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