1 /* 2 * bluetooth.h 3 */ 4 5 /*- 6 * Copyright (c) 2001-2002 Maksim Yevmenkin <m_evmenkin@yahoo.com> 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 * 30 * $Id: ng_bluetooth.h,v 1.4 2003/04/26 22:32:34 max Exp $ 31 * $FreeBSD$ 32 */ 33 34 #ifndef _NETGRAPH_BLUETOOTH_H_ 35 #define _NETGRAPH_BLUETOOTH_H_ 36 37 /* 38 * Version of the stack 39 */ 40 41 #define NG_BLUETOOTH_VERSION 1 42 43 /* 44 * Declare the base of the Bluetooth sysctl hierarchy, 45 * but only if this file cares about sysctl's 46 */ 47 48 #ifdef SYSCTL_DECL 49 SYSCTL_DECL(_net_bluetooth); 50 SYSCTL_DECL(_net_bluetooth_hci); 51 SYSCTL_DECL(_net_bluetooth_l2cap); 52 SYSCTL_DECL(_net_bluetooth_rfcomm); 53 #endif /* SYSCTL_DECL */ 54 55 /* 56 * Mbuf qeueue and useful mbufq macros. We do not use ifqueue because we 57 * do not need mutex and other locking stuff 58 */ 59 60 struct mbuf; 61 62 struct ng_bt_mbufq { 63 struct mbuf *head; /* first item in the queue */ 64 struct mbuf *tail; /* last item in the queue */ 65 u_int32_t len; /* number of items in the queue */ 66 u_int32_t maxlen; /* maximal number of items in the queue */ 67 u_int32_t drops; /* number if dropped items */ 68 }; 69 typedef struct ng_bt_mbufq ng_bt_mbufq_t; 70 typedef struct ng_bt_mbufq * ng_bt_mbufq_p; 71 72 #define NG_BT_MBUFQ_INIT(q, _maxlen) \ 73 do { \ 74 (q)->head = NULL; \ 75 (q)->tail = NULL; \ 76 (q)->len = 0; \ 77 (q)->maxlen = (_maxlen); \ 78 (q)->drops = 0; \ 79 } while (0) 80 81 #define NG_BT_MBUFQ_DESTROY(q) \ 82 do { \ 83 NG_BT_MBUFQ_DRAIN((q)); \ 84 } while (0) 85 86 #define NG_BT_MBUFQ_FIRST(q) (q)->head 87 88 #define NG_BT_MBUFQ_LEN(q) (q)->len 89 90 #define NG_BT_MBUFQ_FULL(q) ((q)->len >= (q)->maxlen) 91 92 #define NG_BT_MBUFQ_DROP(q) (q)->drops ++ 93 94 #define NG_BT_MBUFQ_ENQUEUE(q, i) \ 95 do { \ 96 (i)->m_nextpkt = NULL; \ 97 \ 98 if ((q)->tail == NULL) \ 99 (q)->head = (i); \ 100 else \ 101 (q)->tail->m_nextpkt = (i); \ 102 \ 103 (q)->tail = (i); \ 104 (q)->len ++; \ 105 } while (0) 106 107 #define NG_BT_MBUFQ_DEQUEUE(q, i) \ 108 do { \ 109 (i) = (q)->head; \ 110 if ((i) != NULL) { \ 111 (q)->head = (q)->head->m_nextpkt; \ 112 if ((q)->head == NULL) \ 113 (q)->tail = NULL; \ 114 \ 115 (q)->len --; \ 116 (i)->m_nextpkt = NULL; \ 117 } \ 118 } while (0) 119 120 #define NG_BT_MBUFQ_PREPEND(q, i) \ 121 do { \ 122 (i)->m_nextpkt = (q)->head; \ 123 if ((q)->tail == NULL) \ 124 (q)->tail = (i); \ 125 \ 126 (q)->head = (i); \ 127 (q)->len ++; \ 128 } while (0) 129 130 #define NG_BT_MBUFQ_DRAIN(q) \ 131 do { \ 132 struct mbuf *m = NULL; \ 133 \ 134 for (;;) { \ 135 NG_BT_MBUFQ_DEQUEUE((q), m); \ 136 if (m == NULL) \ 137 break; \ 138 \ 139 NG_FREE_M(m); \ 140 } \ 141 } while (0) 142 143 /* 144 * Netgraph item queue and useful itemq macros 145 */ 146 147 struct ng_item; 148 149 struct ng_bt_itemq { 150 struct ng_item *head; /* first item in the queue */ 151 struct ng_item *tail; /* last item in the queue */ 152 u_int32_t len; /* number of items in the queue */ 153 u_int32_t maxlen; /* maximal number of items in the queue */ 154 u_int32_t drops; /* number if dropped items */ 155 }; 156 typedef struct ng_bt_itemq ng_bt_itemq_t; 157 typedef struct ng_bt_itemq * ng_bt_itemq_p; 158 159 #define NG_BT_ITEMQ_INIT(q, _maxlen) NG_BT_MBUFQ_INIT((q), (_maxlen)) 160 161 #define NG_BT_ITEMQ_DESTROY(q) \ 162 do { \ 163 NG_BT_ITEMQ_DRAIN((q)); \ 164 } while (0) 165 166 #define NG_BT_ITEMQ_FIRST(q) NG_BT_MBUFQ_FIRST((q)) 167 168 #define NG_BT_ITEMQ_LEN(q) NG_BT_MBUFQ_LEN((q)) 169 170 #define NG_BT_ITEMQ_FULL(q) NG_BT_MBUFQ_FULL((q)) 171 172 #define NG_BT_ITEMQ_DROP(q) NG_BT_MBUFQ_DROP((q)) 173 174 #define NG_BT_ITEMQ_ENQUEUE(q, i) \ 175 do { \ 176 (i)->el_next = NULL; \ 177 \ 178 if ((q)->tail == NULL) \ 179 (q)->head = (i); \ 180 else \ 181 (q)->tail->el_next = (i); \ 182 \ 183 (q)->tail = (i); \ 184 (q)->len ++; \ 185 } while (0) 186 187 #define NG_BT_ITEMQ_DEQUEUE(q, i) \ 188 do { \ 189 (i) = (q)->head; \ 190 if ((i) != NULL) { \ 191 (q)->head = (q)->head->el_next; \ 192 if ((q)->head == NULL) \ 193 (q)->tail = NULL; \ 194 \ 195 (q)->len --; \ 196 (i)->el_next = NULL; \ 197 } \ 198 } while (0) 199 200 #define NG_BT_ITEMQ_PREPEND(q, i) \ 201 do { \ 202 (i)->el_next = (q)->head; \ 203 if ((q)->tail == NULL) \ 204 (q)->tail = (i); \ 205 \ 206 (q)->head = (i); \ 207 (q)->len ++; \ 208 } while (0) 209 210 #define NG_BT_ITEMQ_DRAIN(q) \ 211 do { \ 212 struct ng_item *i = NULL; \ 213 \ 214 for (;;) { \ 215 NG_BT_ITEMQ_DEQUEUE((q), i); \ 216 if (i == NULL) \ 217 break; \ 218 \ 219 NG_FREE_ITEM(i); \ 220 } \ 221 } while (0) 222 223 /* 224 * Get Bluetooth stack sysctl globals 225 */ 226 227 u_int32_t bluetooth_hci_command_timeout (void); 228 u_int32_t bluetooth_hci_connect_timeout (void); 229 u_int32_t bluetooth_hci_max_neighbor_age (void); 230 u_int32_t bluetooth_l2cap_rtx_timeout (void); 231 u_int32_t bluetooth_l2cap_ertx_timeout (void); 232 233 #endif /* _NETGRAPH_BLUETOOTH_H_ */ 234 235