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: src/sys/netgraph/bluetooth/include/ng_bluetooth.h,v 1.5 2008/04/15 21:15:32 mav Exp $ 32 * $DragonFly: src/sys/netgraph7/bluetooth/include/ng_bluetooth.h,v 1.2 2008/06/26 23:05:40 dillon Exp $ 33 */ 34 35 #ifndef _NETGRAPH_BLUETOOTH_H_ 36 #define _NETGRAPH_BLUETOOTH_H_ 37 38 #include <sys/queue.h> 39 40 /* 41 * Version of the stack 42 */ 43 44 #define NG_BLUETOOTH_VERSION 1 45 46 /* 47 * Declare the base of the Bluetooth sysctl hierarchy, 48 * but only if this file cares about sysctl's 49 */ 50 51 #ifdef SYSCTL_DECL 52 SYSCTL_DECL(_net_bluetooth); 53 SYSCTL_DECL(_net_bluetooth_hci); 54 SYSCTL_DECL(_net_bluetooth_l2cap); 55 SYSCTL_DECL(_net_bluetooth_rfcomm); 56 #endif /* SYSCTL_DECL */ 57 58 /* 59 * Mbuf qeueue and useful mbufq macros. We do not use ifqueue because we 60 * do not need mutex and other locking stuff 61 */ 62 63 struct mbuf; 64 65 struct ng_bt_mbufq { 66 struct mbuf *head; /* first item in the queue */ 67 struct mbuf *tail; /* last item in the queue */ 68 u_int32_t len; /* number of items in the queue */ 69 u_int32_t maxlen; /* maximal number of items in the queue */ 70 u_int32_t drops; /* number if dropped items */ 71 }; 72 typedef struct ng_bt_mbufq ng_bt_mbufq_t; 73 typedef struct ng_bt_mbufq * ng_bt_mbufq_p; 74 75 #define NG_BT_MBUFQ_INIT(q, _maxlen) \ 76 do { \ 77 (q)->head = NULL; \ 78 (q)->tail = NULL; \ 79 (q)->len = 0; \ 80 (q)->maxlen = (_maxlen); \ 81 (q)->drops = 0; \ 82 } while (0) 83 84 #define NG_BT_MBUFQ_DESTROY(q) \ 85 do { \ 86 NG_BT_MBUFQ_DRAIN((q)); \ 87 } while (0) 88 89 #define NG_BT_MBUFQ_FIRST(q) (q)->head 90 91 #define NG_BT_MBUFQ_LEN(q) (q)->len 92 93 #define NG_BT_MBUFQ_FULL(q) ((q)->len >= (q)->maxlen) 94 95 #define NG_BT_MBUFQ_DROP(q) (q)->drops ++ 96 97 #define NG_BT_MBUFQ_ENQUEUE(q, i) \ 98 do { \ 99 (i)->m_nextpkt = NULL; \ 100 \ 101 if ((q)->tail == NULL) \ 102 (q)->head = (i); \ 103 else \ 104 (q)->tail->m_nextpkt = (i); \ 105 \ 106 (q)->tail = (i); \ 107 (q)->len ++; \ 108 } while (0) 109 110 #define NG_BT_MBUFQ_DEQUEUE(q, i) \ 111 do { \ 112 (i) = (q)->head; \ 113 if ((i) != NULL) { \ 114 (q)->head = (q)->head->m_nextpkt; \ 115 if ((q)->head == NULL) \ 116 (q)->tail = NULL; \ 117 \ 118 (q)->len --; \ 119 (i)->m_nextpkt = NULL; \ 120 } \ 121 } while (0) 122 123 #define NG_BT_MBUFQ_PREPEND(q, i) \ 124 do { \ 125 (i)->m_nextpkt = (q)->head; \ 126 if ((q)->tail == NULL) \ 127 (q)->tail = (i); \ 128 \ 129 (q)->head = (i); \ 130 (q)->len ++; \ 131 } while (0) 132 133 #define NG_BT_MBUFQ_DRAIN(q) \ 134 do { \ 135 struct mbuf *m = NULL; \ 136 \ 137 for (;;) { \ 138 NG_BT_MBUFQ_DEQUEUE((q), m); \ 139 if (m == NULL) \ 140 break; \ 141 \ 142 NG_FREE_M(m); \ 143 } \ 144 } while (0) 145 146 /* 147 * Netgraph item queue and useful itemq macros 148 */ 149 150 struct ng_item; 151 152 struct ng_bt_itemq { 153 STAILQ_HEAD(, ng_item) queue; /* actually items queue */ 154 u_int32_t len; /* number of items in the queue */ 155 u_int32_t maxlen; /* maximal number of items in the queue */ 156 u_int32_t drops; /* number if dropped items */ 157 }; 158 typedef struct ng_bt_itemq ng_bt_itemq_t; 159 typedef struct ng_bt_itemq * ng_bt_itemq_p; 160 161 #define NG_BT_ITEMQ_INIT(q, _maxlen) \ 162 do { \ 163 STAILQ_INIT(&(q)->queue); \ 164 (q)->len = 0; \ 165 (q)->maxlen = (_maxlen); \ 166 (q)->drops = 0; \ 167 } while (0) 168 169 #define NG_BT_ITEMQ_DESTROY(q) \ 170 do { \ 171 NG_BT_ITEMQ_DRAIN((q)); \ 172 } while (0) 173 174 #define NG_BT_ITEMQ_FIRST(q) STAILQ_FIRST(&(q)->queue) 175 176 #define NG_BT_ITEMQ_LEN(q) NG_BT_MBUFQ_LEN((q)) 177 178 #define NG_BT_ITEMQ_FULL(q) NG_BT_MBUFQ_FULL((q)) 179 180 #define NG_BT_ITEMQ_DROP(q) NG_BT_MBUFQ_DROP((q)) 181 182 #define NG_BT_ITEMQ_ENQUEUE(q, i) \ 183 do { \ 184 STAILQ_INSERT_TAIL(&(q)->queue, (i), el_next); \ 185 (q)->len ++; \ 186 } while (0) 187 188 #define NG_BT_ITEMQ_DEQUEUE(q, i) \ 189 do { \ 190 (i) = STAILQ_FIRST(&(q)->queue); \ 191 if ((i) != NULL) { \ 192 STAILQ_REMOVE_HEAD(&(q)->queue, el_next); \ 193 (q)->len --; \ 194 } \ 195 } while (0) 196 197 #define NG_BT_ITEMQ_PREPEND(q, i) \ 198 do { \ 199 STAILQ_INSERT_HEAD(&(q)->queue, (i), el_next); \ 200 (q)->len ++; \ 201 } while (0) 202 203 #define NG_BT_ITEMQ_DRAIN(q) \ 204 do { \ 205 struct ng_item *i = NULL; \ 206 \ 207 for (;;) { \ 208 NG_BT_ITEMQ_DEQUEUE((q), i); \ 209 if (i == NULL) \ 210 break; \ 211 \ 212 NG_FREE_ITEM(i); \ 213 } \ 214 } while (0) 215 216 /* 217 * Get Bluetooth stack sysctl globals 218 */ 219 220 u_int32_t bluetooth_hci_command_timeout (void); 221 u_int32_t bluetooth_hci_connect_timeout (void); 222 u_int32_t bluetooth_hci_max_neighbor_age (void); 223 u_int32_t bluetooth_l2cap_rtx_timeout (void); 224 u_int32_t bluetooth_l2cap_ertx_timeout (void); 225 226 #endif /* _NETGRAPH_BLUETOOTH_H_ */ 227 228