diff options
-rw-r--r-- | sys/conf/files | 6 | ||||
-rw-r--r-- | sys/kern/uipc_domain.c | 6 | ||||
-rw-r--r-- | sys/net/if.c | 6 | ||||
-rw-r--r-- | sys/net/if_types.h | 3 | ||||
-rw-r--r-- | sys/net/netisr.h | 4 | ||||
-rw-r--r-- | sys/net/netisr_dispatch.h | 6 | ||||
-rw-r--r-- | sys/netbt/bluetooth.h | 264 | ||||
-rw-r--r-- | sys/netbt/bt.h | 344 | ||||
-rw-r--r-- | sys/netbt/bt_input.c | 58 | ||||
-rw-r--r-- | sys/netbt/bt_proto.c | 72 | ||||
-rw-r--r-- | sys/netbt/bt_var.h | 25 | ||||
-rw-r--r-- | sys/netbt/h4.h | 112 | ||||
-rw-r--r-- | sys/netbt/hci.h | 1660 | ||||
-rw-r--r-- | sys/netbt/hci_raw.c | 1748 | ||||
-rw-r--r-- | sys/netbt/hci_var.h | 97 | ||||
-rw-r--r-- | sys/netbt/l2cap.h | 663 | ||||
-rw-r--r-- | sys/netbt/l2cap_var.h | 216 | ||||
-rw-r--r-- | sys/netbt/rfcomm_var.h | 338 | ||||
-rw-r--r-- | sys/sys/malloc.h | 7 | ||||
-rw-r--r-- | sys/sys/socket.h | 7 |
20 files changed, 5632 insertions, 10 deletions
diff --git a/sys/conf/files b/sys/conf/files index 982bcb7a6cc..f0cb08809f4 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -1,4 +1,4 @@ -# $OpenBSD: files,v 1.324 2005/01/14 01:08:11 pvalchev Exp $ +# $OpenBSD: files,v 1.325 2005/01/14 12:04:02 grange Exp $ # $NetBSD: files,v 1.87 1996/05/19 17:17:50 jonathan Exp $ # @(#)files.newconf 7.5 (Berkeley) 5/10/93 @@ -60,6 +60,7 @@ define ieee1394 define sppp define token define wlan +define bluetooth # "Chipset" attributes. These are the machine-independent portions # of device drivers. @@ -815,6 +816,9 @@ file netatalk/at_proto.c netatalk file netatalk/ddp_input.c netatalk file netatalk/ddp_output.c netatalk file netatalk/ddp_usrreq.c netatalk +file netbt/bt_input.c bluetooth needs-flag +file netbt/bt_proto.c bluetooth +file netbt/hci_raw.c bluetooth file netnatm/natm_pcb.c natm file netnatm/natm_proto.c natm file netnatm/natm.c natm diff --git a/sys/kern/uipc_domain.c b/sys/kern/uipc_domain.c index 5c6c6797787..f9abca937ff 100644 --- a/sys/kern/uipc_domain.c +++ b/sys/kern/uipc_domain.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_domain.c,v 1.20 2004/11/27 14:50:55 pat Exp $ */ +/* $OpenBSD: uipc_domain.c,v 1.21 2005/01/14 12:04:02 grange Exp $ */ /* $NetBSD: uipc_domain.c,v 1.14 1996/02/09 19:00:44 christos Exp $ */ /* @@ -45,6 +45,7 @@ #include <sys/sysctl.h> #include <sys/timeout.h> +#include "bluetooth.h" #include "bpfilter.h" struct domain *domains; @@ -113,6 +114,9 @@ domaininit(void) ADDDOMAIN(key); #endif #endif +#if NBLUETOOTH > 0 + ADDDOMAIN(bt); +#endif ADDDOMAIN(route); #endif diff --git a/sys/net/if.c b/sys/net/if.c index 2cd508e8d0a..92e4462b9b6 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if.c,v 1.101 2005/01/14 11:49:01 henning Exp $ */ +/* $OpenBSD: if.c,v 1.102 2005/01/14 12:04:02 grange Exp $ */ /* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */ /* @@ -61,6 +61,7 @@ * @(#)if.c 8.3 (Berkeley) 1/4/94 */ +#include "bluetooth.h" #include "bpfilter.h" #include "bridge.h" #include "carp.h" @@ -582,6 +583,9 @@ do { \ #ifdef DECNET IF_DETACH_QUEUES(decnetintrq); #endif +#if NBLUETOOTH > 0 + IF_DETACH_QUEUES(btintrq); +#endif #undef IF_DETACH_QUEUES /* diff --git a/sys/net/if_types.h b/sys/net/if_types.h index 7cf4217d928..bac91ccfc73 100644 --- a/sys/net/if_types.h +++ b/sys/net/if_types.h @@ -1,4 +1,4 @@ -/* $OpenBSD: if_types.h,v 1.17 2004/11/18 16:49:57 mpf Exp $ */ +/* $OpenBSD: if_types.h,v 1.18 2005/01/14 12:04:02 grange Exp $ */ /* $NetBSD: if_types.h,v 1.17 2000/10/26 06:51:31 onoe Exp $ */ /* @@ -266,5 +266,6 @@ #define IFT_PFLOG 0xf5 /* Packet filter logging */ #define IFT_PFSYNC 0xf6 /* Packet filter state syncing */ #define IFT_CARP 0xf7 /* Common Address Redundancy Protocol */ +#define IFT_BLUETOOTH 0xf8 /* Bluetooth */ #endif /* _NET_IF_TYPES_H_ */ diff --git a/sys/net/netisr.h b/sys/net/netisr.h index dd73562477d..a98bc6661c2 100644 --- a/sys/net/netisr.h +++ b/sys/net/netisr.h @@ -1,4 +1,4 @@ -/* $OpenBSD: netisr.h,v 1.20 2004/11/28 23:39:45 canacar Exp $ */ +/* $OpenBSD: netisr.h,v 1.21 2005/01/14 12:04:02 grange Exp $ */ /* $NetBSD: netisr.h,v 1.12 1995/08/12 23:59:24 mycroft Exp $ */ /* @@ -66,6 +66,7 @@ #define NETISR_PPP 28 /* for PPP processing */ #define NETISR_BRIDGE 29 /* for bridge processing */ #define NETISR_PPPOE 30 /* for pppoe processing */ +#define NETISR_BT 31 /* same as AF_BLUETOOTH */ #ifndef _LOCORE #ifdef _KERNEL @@ -83,6 +84,7 @@ void pppintr(void); void ccittintr(void); void bridgeintr(void); void pppoeintr(void); +void btintr(void); #include <dev/rndvar.h> #define schednetisr(anisr) \ diff --git a/sys/net/netisr_dispatch.h b/sys/net/netisr_dispatch.h index 3be10f991fe..f5e5ae31b5d 100644 --- a/sys/net/netisr_dispatch.h +++ b/sys/net/netisr_dispatch.h @@ -1,4 +1,4 @@ -/* $OpenBSD: netisr_dispatch.h,v 1.7 2004/11/28 23:39:45 canacar Exp $ */ +/* $OpenBSD: netisr_dispatch.h,v 1.8 2005/01/14 12:04:02 grange Exp $ */ /* $NetBSD: netisr_dispatch.h,v 1.2 2000/07/02 04:40:47 cgd Exp $ */ /* @@ -22,6 +22,7 @@ #ifndef _NET_NETISR_DISPATCH_H_ #define _NET_NETISR_DISPATCH_H_ +#include "bluetooth.h" #include "ether.h" #include "ppp.h" #include "bridge.h" @@ -69,3 +70,6 @@ #if NPPPOE > 0 DONETISR(NETISR_PPPOE,pppoeintr); #endif +#if NBLUETOOTH > 0 + DONETISR(NETISR_BT,btintr); +#endif diff --git a/sys/netbt/bluetooth.h b/sys/netbt/bluetooth.h new file mode 100644 index 00000000000..c5e1d261b4f --- /dev/null +++ b/sys/netbt/bluetooth.h @@ -0,0 +1,264 @@ +/* $OpenBSD: bluetooth.h,v 1.1 2005/01/14 12:04:02 grange Exp $ */ + +/* + * bluetooth.h + * + * Copyright (c) 2001-2002 Maksim Yevmenkin <m_evmenkin@yahoo.com> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: bluetooth.h,v 1.1 2005/01/14 12:04:02 grange Exp $ + * $FreeBSD: src/sys/netgraph/bluetooth/include/ng_bluetooth.h,v 1.3 2003/11/14 03:45:29 emax Exp $ + */ + +#ifndef _NETGRAPH_BLUETOOTH_H_ +#define _NETGRAPH_BLUETOOTH_H_ + +/* + * XXX: This file only contains redundant mbuf wrapppers and must be + * removed later. + */ + +/* + * XXX: dirty temporary hacks. + */ +#undef KASSERT +#define KASSERT(a, b) +#undef mtx_init +#undef mtx_lock +#undef mtx_unlock +#undef mtx_assert +#undef mtx_destroy +#define mtx_init(a, b, c, d) +#define mtx_lock(a) +#define mtx_unlock(a) +#define mtx_assert(a, b) +#define mtx_destroy(a) +#define ACCEPT_LOCK() +#define SOCK_LOCK(a) + +#define NG_FREE_M(m) \ + do { \ + if ((m)) { \ + m_freem((m)); \ + (m) = NULL; \ + } \ + } while (0) + +/* + * Version of the stack + */ + +#define NG_BLUETOOTH_VERSION 1 + +/* + * Declare the base of the Bluetooth sysctl hierarchy, + * but only if this file cares about sysctl's + */ + +#ifdef SYSCTL_DECL +SYSCTL_DECL(_net_bluetooth); +SYSCTL_DECL(_net_bluetooth_hci); +SYSCTL_DECL(_net_bluetooth_l2cap); +SYSCTL_DECL(_net_bluetooth_rfcomm); +#endif /* SYSCTL_DECL */ + +/* + * Mbuf qeueue and useful mbufq macros. We do not use ifqueue because we + * do not need mutex and other locking stuff + */ + +struct mbuf; + +struct ng_bt_mbufq { + struct mbuf *head; /* first item in the queue */ + struct mbuf *tail; /* last item in the queue */ + u_int32_t len; /* number of items in the queue */ + u_int32_t maxlen; /* maximal number of items in the queue */ + u_int32_t drops; /* number if dropped items */ +}; +typedef struct ng_bt_mbufq ng_bt_mbufq_t; +typedef struct ng_bt_mbufq * ng_bt_mbufq_p; + +#define NG_BT_MBUFQ_INIT(q, _maxlen) \ + do { \ + (q)->head = NULL; \ + (q)->tail = NULL; \ + (q)->len = 0; \ + (q)->maxlen = (_maxlen); \ + (q)->drops = 0; \ + } while (0) + +#define NG_BT_MBUFQ_DESTROY(q) \ + do { \ + NG_BT_MBUFQ_DRAIN((q)); \ + } while (0) + +#define NG_BT_MBUFQ_FIRST(q) (q)->head + +#define NG_BT_MBUFQ_LEN(q) (q)->len + +#define NG_BT_MBUFQ_FULL(q) ((q)->len >= (q)->maxlen) + +#define NG_BT_MBUFQ_DROP(q) (q)->drops ++ + +#define NG_BT_MBUFQ_ENQUEUE(q, i) \ + do { \ + (i)->m_nextpkt = NULL; \ + \ + if ((q)->tail == NULL) \ + (q)->head = (i); \ + else \ + (q)->tail->m_nextpkt = (i); \ + \ + (q)->tail = (i); \ + (q)->len ++; \ + } while (0) + +#define NG_BT_MBUFQ_DEQUEUE(q, i) \ + do { \ + (i) = (q)->head; \ + if ((i) != NULL) { \ + (q)->head = (q)->head->m_nextpkt; \ + if ((q)->head == NULL) \ + (q)->tail = NULL; \ + \ + (q)->len --; \ + (i)->m_nextpkt = NULL; \ + } \ + } while (0) + +#define NG_BT_MBUFQ_PREPEND(q, i) \ + do { \ + (i)->m_nextpkt = (q)->head; \ + if ((q)->tail == NULL) \ + (q)->tail = (i); \ + \ + (q)->head = (i); \ + (q)->len ++; \ + } while (0) + +#define NG_BT_MBUFQ_DRAIN(q) \ + do { \ + struct mbuf *m = NULL; \ + \ + for (;;) { \ + NG_BT_MBUFQ_DEQUEUE((q), m); \ + if (m == NULL) \ + break; \ + \ + NG_FREE_M(m); \ + } \ + } while (0) + +/* + * Netgraph item queue and useful itemq macros + */ + +struct ng_item; + +struct ng_bt_itemq { + struct ng_item *head; /* first item in the queue */ + struct ng_item *tail; /* last item in the queue */ + u_int32_t len; /* number of items in the queue */ + u_int32_t maxlen; /* maximal number of items in the queue */ + u_int32_t drops; /* number if dropped items */ +}; +typedef struct ng_bt_itemq ng_bt_itemq_t; +typedef struct ng_bt_itemq * ng_bt_itemq_p; + +#define NG_BT_ITEMQ_INIT(q, _maxlen) NG_BT_MBUFQ_INIT((q), (_maxlen)) + +#define NG_BT_ITEMQ_DESTROY(q) \ + do { \ + NG_BT_ITEMQ_DRAIN((q)); \ + } while (0) + +#define NG_BT_ITEMQ_FIRST(q) NG_BT_MBUFQ_FIRST((q)) + +#define NG_BT_ITEMQ_LEN(q) NG_BT_MBUFQ_LEN((q)) + +#define NG_BT_ITEMQ_FULL(q) NG_BT_MBUFQ_FULL((q)) + +#define NG_BT_ITEMQ_DROP(q) NG_BT_MBUFQ_DROP((q)) + +#define NG_BT_ITEMQ_ENQUEUE(q, i) \ + do { \ + (i)->el_next = NULL; \ + \ + if ((q)->tail == NULL) \ + (q)->head = (i); \ + else \ + (q)->tail->el_next = (i); \ + \ + (q)->tail = (i); \ + (q)->len ++; \ + } while (0) + +#define NG_BT_ITEMQ_DEQUEUE(q, i) \ + do { \ + (i) = (q)->head; \ + if ((i) != NULL) { \ + (q)->head = (q)->head->el_next; \ + if ((q)->head == NULL) \ + (q)->tail = NULL; \ + \ + (q)->len --; \ + (i)->el_next = NULL; \ + } \ + } while (0) + +#define NG_BT_ITEMQ_PREPEND(q, i) \ + do { \ + (i)->el_next = (q)->head; \ + if ((q)->tail == NULL) \ + (q)->tail = (i); \ + \ + (q)->head = (i); \ + (q)->len ++; \ + } while (0) + +#define NG_BT_ITEMQ_DRAIN(q) \ + do { \ + struct ng_item *i = NULL; \ + \ + for (;;) { \ + NG_BT_ITEMQ_DEQUEUE((q), i); \ + if (i == NULL) \ + break; \ + \ + NG_FREE_ITEM(i); \ + } \ + } while (0) + +/* + * Get Bluetooth stack sysctl globals + */ + +u_int32_t bluetooth_hci_command_timeout (void); +u_int32_t bluetooth_hci_connect_timeout (void); +u_int32_t bluetooth_hci_max_neighbor_age (void); +u_int32_t bluetooth_l2cap_rtx_timeout (void); +u_int32_t bluetooth_l2cap_ertx_timeout (void); + +#endif /* _NETGRAPH_BLUETOOTH_H_ */ diff --git a/sys/netbt/bt.h b/sys/netbt/bt.h new file mode 100644 index 00000000000..8ad3aacd9c1 --- /dev/null +++ b/sys/netbt/bt.h @@ -0,0 +1,344 @@ +/* $OpenBSD: bt.h,v 1.1 2005/01/14 12:04:02 grange Exp $ */ + +/* + * ng_btsocket.h + * + * Copyright (c) 2001-2002 Maksim Yevmenkin <m_evmenkin@yahoo.com> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: bt.h,v 1.1 2005/01/14 12:04:02 grange Exp $ + * $FreeBSD: src/sys/netgraph/bluetooth/include/ng_btsocket.h,v 1.6 2004/08/20 01:24:23 julian Exp $ + */ + +#ifndef _NETGRAPH_BTSOCKET_H_ +#define _NETGRAPH_BTSOCKET_H_ + +/* + * XXX: bitstring operations, must be removed later. + */ +typedef unsigned char bitstr_t; +#define bitstr_size(nbits) (((nbits) + 7) >> 3) +#define bit_decl(name, nbits) ((name)[bitstr_size(nbits)]) +#define _bit_byte(bit) ((bit) >> 3) +#define _bit_mask(bit) (1 << ((bit)&0x7)) +#define bit_test(name, bit) ((name)[_bit_byte(bit)] & _bit_mask(bit)) +#define bit_set(name, bit) ((name)[_bit_byte(bit)] |= _bit_mask(bit)) +#define bit_clear(name, bit) ((name)[_bit_byte(bit)] &= ~_bit_mask(bit)) + +/* + * Bluetooth protocols + */ + +#define BLUETOOTH_PROTO_HCI 134 /* HCI protocol number */ +#define BLUETOOTH_PROTO_L2CAP 135 /* L2CAP protocol number */ +#define BLUETOOTH_PROTO_RFCOMM 136 /* RFCOMM protocol number */ + +/* + * Bluetooth version of struct sockaddr for raw HCI sockets + */ + +struct sockaddr_hci { + u_char hci_len; /* total length */ + u_char hci_family; /* address family */ + char hci_node[32]; /* address (size == NG_NODESIZ ) */ +}; + +/* Raw HCI socket options */ +#define SOL_HCI_RAW 0x0802 /* socket options level */ + +#define SO_HCI_RAW_FILTER 1 /* get/set filter on socket */ +#define SO_HCI_RAW_DIRECTION 2 /* turn on/off direction info */ +#define SCM_HCI_RAW_DIRECTION SO_HCI_RAW_DIRECTION /* cmsg_type */ + +/* + * Raw HCI socket filter. + * + * For packet mask use (1 << (HCI packet indicator - 1)) + * For event mask use (1 << (Event - 1)) + */ + +struct ng_btsocket_hci_raw_filter { + bitstr_t bit_decl(packet_mask, 32); + bitstr_t bit_decl(event_mask, (NG_HCI_EVENT_MASK_SIZE * 8)); +}; + +/* + * Raw HCI sockets ioctl's + */ + +/* Get state */ +struct ng_btsocket_hci_raw_node_state { + ng_hci_node_state_ep state; +}; +#define SIOC_HCI_RAW_NODE_GET_STATE \ + _IOWR('b', NGM_HCI_NODE_GET_STATE, \ + struct ng_btsocket_hci_raw_node_state) + +/* Initialize */ +#define SIOC_HCI_RAW_NODE_INIT \ + _IO('b', NGM_HCI_NODE_INIT) + +/* Get/Set debug level */ +struct ng_btsocket_hci_raw_node_debug { + ng_hci_node_debug_ep debug; +}; +#define SIOC_HCI_RAW_NODE_GET_DEBUG \ + _IOWR('b', NGM_HCI_NODE_GET_DEBUG, \ + struct ng_btsocket_hci_raw_node_debug) +#define SIOC_HCI_RAW_NODE_SET_DEBUG \ + _IOWR('b', NGM_HCI_NODE_SET_DEBUG, \ + struct ng_btsocket_hci_raw_node_debug) + +/* Get buffer info */ +struct ng_btsocket_hci_raw_node_buffer { + ng_hci_node_buffer_ep buffer; +}; +#define SIOC_HCI_RAW_NODE_GET_BUFFER \ + _IOWR('b', NGM_HCI_NODE_GET_BUFFER, \ + struct ng_btsocket_hci_raw_node_buffer) + +/* Get BD_ADDR */ +struct ng_btsocket_hci_raw_node_bdaddr { + bdaddr_t bdaddr; +}; +#define SIOC_HCI_RAW_NODE_GET_BDADDR \ + _IOWR('b', NGM_HCI_NODE_GET_BDADDR, \ + struct ng_btsocket_hci_raw_node_bdaddr) + +/* Get features */ +struct ng_btsocket_hci_raw_node_features { + u_int8_t features[NG_HCI_FEATURES_SIZE]; +}; +#define SIOC_HCI_RAW_NODE_GET_FEATURES \ + _IOWR('b', NGM_HCI_NODE_GET_FEATURES, \ + struct ng_btsocket_hci_raw_node_features) + +/* Get stat */ +struct ng_btsocket_hci_raw_node_stat { + ng_hci_node_stat_ep stat; +}; +#define SIOC_HCI_RAW_NODE_GET_STAT \ + _IOWR('b', NGM_HCI_NODE_GET_STAT, \ + struct ng_btsocket_hci_raw_node_stat) + +/* Reset stat */ +#define SIOC_HCI_RAW_NODE_RESET_STAT \ + _IO('b', NGM_HCI_NODE_RESET_STAT) + +/* Flush neighbor cache */ +#define SIOC_HCI_RAW_NODE_FLUSH_NEIGHBOR_CACHE \ + _IO('b', NGM_HCI_NODE_FLUSH_NEIGHBOR_CACHE) + +/* Get neighbor cache */ +struct ng_btsocket_hci_raw_node_neighbor_cache { + u_int32_t num_entries; + ng_hci_node_neighbor_cache_entry_ep *entries; +}; +#define SIOC_HCI_RAW_NODE_GET_NEIGHBOR_CACHE \ + _IOWR('b', NGM_HCI_NODE_GET_NEIGHBOR_CACHE, \ + struct ng_btsocket_hci_raw_node_neighbor_cache) + +/* Get connection list */ +struct ng_btsocket_hci_raw_con_list { + u_int32_t num_connections; + ng_hci_node_con_ep *connections; +}; +#define SIOC_HCI_RAW_NODE_GET_CON_LIST \ + _IOWR('b', NGM_HCI_NODE_GET_CON_LIST, \ + struct ng_btsocket_hci_raw_con_list) + +/* Get/Set link policy settings mask */ +struct ng_btsocket_hci_raw_node_link_policy_mask { + ng_hci_node_link_policy_mask_ep policy_mask; +}; +#define SIOC_HCI_RAW_NODE_GET_LINK_POLICY_MASK \ + _IOWR('b', NGM_HCI_NODE_GET_LINK_POLICY_SETTINGS_MASK, \ + struct ng_btsocket_hci_raw_node_link_policy_mask) +#define SIOC_HCI_RAW_NODE_SET_LINK_POLICY_MASK \ + _IOWR('b', NGM_HCI_NODE_SET_LINK_POLICY_SETTINGS_MASK, \ + struct ng_btsocket_hci_raw_node_link_policy_mask) + +/* Get/Set packet mask */ +struct ng_btsocket_hci_raw_node_packet_mask { + ng_hci_node_packet_mask_ep packet_mask; +}; +#define SIOC_HCI_RAW_NODE_GET_PACKET_MASK \ + _IOWR('b', NGM_HCI_NODE_GET_PACKET_MASK, \ + struct ng_btsocket_hci_raw_node_packet_mask) +#define SIOC_HCI_RAW_NODE_SET_PACKET_MASK \ + _IOWR('b', NGM_HCI_NODE_SET_PACKET_MASK, \ + struct ng_btsocket_hci_raw_node_packet_mask) + +/* Get/Set role switch */ +struct ng_btsocket_hci_raw_node_role_switch { + ng_hci_node_role_switch_ep role_switch; +}; +#define SIOC_HCI_RAW_NODE_GET_ROLE_SWITCH \ + _IOWR('b', NGM_HCI_NODE_GET_ROLE_SWITCH, \ + struct ng_btsocket_hci_raw_node_role_switch) +#define SIOC_HCI_RAW_NODE_SET_ROLE_SWITCH \ + _IOWR('b', NGM_HCI_NODE_SET_ROLE_SWITCH, \ + struct ng_btsocket_hci_raw_node_role_switch) + +/* + * XXX FIXME: probably does not belong here + * Bluetooth version of struct sockaddr for L2CAP sockets (RAW and SEQPACKET) + */ + +struct sockaddr_l2cap { + u_char l2cap_len; /* total length */ + u_char l2cap_family; /* address family */ + u_int16_t l2cap_psm; /* PSM (Protocol/Service Multiplexor) */ + bdaddr_t l2cap_bdaddr; /* address */ +}; + +/* L2CAP socket options */ +#define SOL_L2CAP 0x1609 /* socket option level */ + +#define SO_L2CAP_IMTU 1 /* get/set incoming MTU */ +#define SO_L2CAP_OMTU 2 /* get outgoing (peer incoming) MTU */ +#define SO_L2CAP_IFLOW 3 /* get incoming flow spec. */ +#define SO_L2CAP_OFLOW 4 /* get/set outgoing flow spec. */ +#define SO_L2CAP_FLUSH 5 /* get/set flush timeout */ + +/* + * Raw L2CAP sockets ioctl's + */ + +/* Ping */ +struct ng_btsocket_l2cap_raw_ping { + u_int32_t result; + u_int32_t echo_size; + u_int8_t *echo_data; +}; +#define SIOC_L2CAP_L2CA_PING \ + _IOWR('b', NGM_L2CAP_L2CA_PING, \ + struct ng_btsocket_l2cap_raw_ping) + +/* Get info */ +struct ng_btsocket_l2cap_raw_get_info { + u_int32_t result; + u_int32_t info_type; + u_int32_t info_size; + u_int8_t *info_data; +}; +#define SIOC_L2CAP_L2CA_GET_INFO \ + _IOWR('b', NGM_L2CAP_L2CA_GET_INFO, \ + struct ng_btsocket_l2cap_raw_get_info) + +/* Get flags */ +struct ng_btsocket_l2cap_raw_node_flags { + ng_l2cap_node_flags_ep flags; +}; +#define SIOC_L2CAP_NODE_GET_FLAGS \ + _IOWR('b', NGM_L2CAP_NODE_GET_FLAGS, \ + struct ng_btsocket_l2cap_raw_node_flags) + +/* Get/Set debug level */ +struct ng_btsocket_l2cap_raw_node_debug { + ng_l2cap_node_debug_ep debug; +}; +#define SIOC_L2CAP_NODE_GET_DEBUG \ + _IOWR('b', NGM_L2CAP_NODE_GET_DEBUG, \ + struct ng_btsocket_l2cap_raw_node_debug) +#define SIOC_L2CAP_NODE_SET_DEBUG \ + _IOWR('b', NGM_L2CAP_NODE_SET_DEBUG, \ + struct ng_btsocket_l2cap_raw_node_debug) + +/* Get connection list */ +struct ng_btsocket_l2cap_raw_con_list { + u_int32_t num_connections; + ng_l2cap_node_con_ep *connections; +}; +#define SIOC_L2CAP_NODE_GET_CON_LIST \ + _IOWR('b', NGM_L2CAP_NODE_GET_CON_LIST, \ + struct ng_btsocket_l2cap_raw_con_list) + +/* Get channel list */ +struct ng_btsocket_l2cap_raw_chan_list { + u_int32_t num_channels; + ng_l2cap_node_chan_ep *channels; +}; +#define SIOC_L2CAP_NODE_GET_CHAN_LIST \ + _IOWR('b', NGM_L2CAP_NODE_GET_CHAN_LIST, \ + struct ng_btsocket_l2cap_raw_chan_list) + +/* Get/Set auto disconnect timeout */ +struct ng_btsocket_l2cap_raw_auto_discon_timo +{ + ng_l2cap_node_auto_discon_ep timeout; +}; +#define SIOC_L2CAP_NODE_GET_AUTO_DISCON_TIMO \ + _IOWR('b', NGM_L2CAP_NODE_GET_AUTO_DISCON_TIMO, \ + struct ng_btsocket_l2cap_raw_auto_discon_timo) +#define SIOC_L2CAP_NODE_SET_AUTO_DISCON_TIMO \ + _IOWR('b', NGM_L2CAP_NODE_SET_AUTO_DISCON_TIMO, \ + struct ng_btsocket_l2cap_raw_auto_discon_timo) + +/* + * XXX FIXME: probably does not belong here + * Bluetooth version of struct sockaddr for RFCOMM sockets (STREAM) + */ + +struct sockaddr_rfcomm { + u_char rfcomm_len; /* total length */ + u_char rfcomm_family; /* address family */ + bdaddr_t rfcomm_bdaddr; /* address */ + u_int8_t rfcomm_channel; /* channel */ +}; + +/* Flow control information */ +struct ng_btsocket_rfcomm_fc_info { + u_int8_t lmodem; /* modem signals (local) */ + u_int8_t rmodem; /* modem signals (remote) */ + u_int8_t tx_cred; /* TX credits */ + u_int8_t rx_cred; /* RX credits */ + u_int8_t cfc; /* credit flow control */ + u_int8_t reserved; +}; + +/* STREAM RFCOMM socket options */ +#define SOL_RFCOMM 0x0816 /* socket options level */ + +#define SO_RFCOMM_MTU 1 /* get channel MTU */ +#define SO_RFCOMM_FC_INFO 2 /* get flow control information */ + +/* + * Netgraph node type name and cookie + */ + +#define NG_BTSOCKET_HCI_RAW_NODE_TYPE "btsock_hci_raw" +#define NG_BTSOCKET_L2CAP_RAW_NODE_TYPE "btsock_l2c_raw" +#define NG_BTSOCKET_L2CAP_NODE_TYPE "btsock_l2c" + +/* + * Debug levels + */ + +#define NG_BTSOCKET_ALERT_LEVEL 1 +#define NG_BTSOCKET_ERR_LEVEL 2 +#define NG_BTSOCKET_WARN_LEVEL 3 +#define NG_BTSOCKET_INFO_LEVEL 4 + +#endif /* _NETGRAPH_BTSOCKET_H_ */ diff --git a/sys/netbt/bt_input.c b/sys/netbt/bt_input.c new file mode 100644 index 00000000000..a6622342d40 --- /dev/null +++ b/sys/netbt/bt_input.c @@ -0,0 +1,58 @@ +/* $OpenBSD: bt_input.c,v 1.1 2005/01/14 12:04:02 grange Exp $ */ +/* + * Copyright (c) 2004 Alexander Yurchenko <grange@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/param.h> +#include <sys/mbuf.h> +#include <sys/systm.h> +#include <sys/socket.h> + +#include <net/if.h> +#include <net/if_types.h> +#include <net/netisr.h> + +#include <netbt/bluetooth.h> +#include <netbt/hci.h> +#include <netbt/l2cap.h> +#include <netbt/bt.h> +#include <netbt/bt_var.h> +#include <netbt/hci_var.h> + +struct ifqueue btintrq; + +void +bt_init(void) +{ + btintrq.ifq_maxlen = IFQ_MAXLEN; +} + +void +btintr(void) +{ + struct mbuf *m; + int s; + + for (;;) { + s = splimp(); + IF_DEQUEUE(&btintrq, m); + splx(s); + + if (m == NULL) + break; + + ng_btsocket_hci_raw_data_input(m); + } +} diff --git a/sys/netbt/bt_proto.c b/sys/netbt/bt_proto.c new file mode 100644 index 00000000000..43d74b790f2 --- /dev/null +++ b/sys/netbt/bt_proto.c @@ -0,0 +1,72 @@ +/* $OpenBSD: bt_proto.c,v 1.1 2005/01/14 12:04:02 grange Exp $ */ +/* + * Copyright (c) 2004 Alexander Yurchenko <grange@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/param.h> +#include <sys/domain.h> +#include <sys/protosw.h> +#include <sys/socket.h> + +#include <netbt/bluetooth.h> +#include <netbt/hci.h> +#include <netbt/l2cap.h> +#include <netbt/bt.h> +#include <netbt/bt_var.h> +#include <netbt/hci_var.h> +#include <netbt/l2cap_var.h> + +struct domain btdomain; + +struct protosw btsw[] = { + { SOCK_RAW, &btdomain, BLUETOOTH_PROTO_HCI, + PR_ATOMIC | PR_ADDR, + NULL/*input*/, NULL/*output*/, NULL/*ctlinput*/, + hci_raw_ctloutput, hci_raw_usrreq, hci_raw_init, + NULL/*fasttimo*/, NULL/*slowtimo*/, NULL/*drain*/, + NULL/*sysctl*/ + }, +#if 0 + { SOCK_RAW, &btdomain, BLUETOOTH_PROTO_L2CAP, + PR_ATOMIC | PR_ADDR, + NULL/*input*/, NULL/*output*/, NULL/*ctlinput*/, + NULL/*ctloutput*/, l2cap_raw_usrreq, l2cap_raw_init, + NULL/*fasttimo*/, NULL/*slowtimo*/, NULL/*drain*/, + NULL/*sysctl*/ + }, + { SOCK_SEQPACKET, &btdomain, BLUETOOTH_PROTO_L2CAP, + PR_ATOMIC | PR_CONNREQUIRED, + NULL/*input*/, NULL/*output*/, NULL/*ctlinput*/, + l2cap_ctloutput, l2cap_usrreq, l2cap_init, + NULL/*fasttimo*/, NULL/*slowtimo*/, NULL/*drain*/, + NULL/*sysctl*/ + }, + { SOCK_STREAM, &btdomain, BLUETOOTH_PROTO_RFCOMM, + PR_ATOMIC | PR_CONNREQUIRED, + NULL/*input*/, NULL/*output*/, NULL/*ctlinput*/, + rfcomm_ctloutput, rfcomm_usrreq, rfcomm_init, + NULL/*fasttimo*/, NULL/*slowtimo*/, NULL/*drain*/, + NULL/*sysctl*/ + } +#endif +}; + +struct domain btdomain = { + AF_BLUETOOTH, "bluetooth", + bt_init, NULL/*externalize*/, NULL/*dispose*/, + btsw, &btsw[sizeof(btsw) / sizeof(btsw[0])], NULL, + NULL/*rtattach*/, 32, sizeof(struct sockaddr_hci), + NULL/*ifattach*/, NULL/*ifdetach*/ +}; diff --git a/sys/netbt/bt_var.h b/sys/netbt/bt_var.h new file mode 100644 index 00000000000..d677f12d338 --- /dev/null +++ b/sys/netbt/bt_var.h @@ -0,0 +1,25 @@ +/* $OpenBSD: bt_var.h,v 1.1 2005/01/14 12:04:02 grange Exp $ */ +/* + * Copyright (c) 2004 Alexander Yurchenko <grange@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _NETBT_BT_VAR_H_ +#define _NETBT_BT_VAR_H_ + +extern struct ifqueue btintrq; + +void bt_init(void); + +#endif /* !_NETBT_BT_VAR_H_ */ diff --git a/sys/netbt/h4.h b/sys/netbt/h4.h new file mode 100644 index 00000000000..387f3226a5f --- /dev/null +++ b/sys/netbt/h4.h @@ -0,0 +1,112 @@ +/* $OpenBSD: h4.h,v 1.1 2005/01/14 12:04:02 grange Exp $ */ + +/* + * ng_h4.h + * + * Copyright (c) 2001-2002 Maksim Yevmenkin <m_evmenkin@yahoo.com> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: h4.h,v 1.1 2005/01/14 12:04:02 grange Exp $ + * $FreeBSD: src/sys/netgraph/bluetooth/include/ng_h4.h,v 1.4 2004/05/10 02:24:55 emax Exp $ + * + * Based on: + * --------- + * + * FreeBSD: src/sys/netgraph/ng_tty.h + * Author: Archie Cobbs <archie@freebsd.org> + */ + +/* + * This file contains everything that application needs to know about + * Bluetooth HCI UART transport layer as per chapter H4 of the Bluetooth + * Specification Book v1.1. + * + * This file can be included by both kernel and userland applications. + */ + +#ifndef _NETGRAPH_H4_H_ +#define _NETGRAPH_H4_H_ + +/************************************************************************** + ************************************************************************** + ** Netgraph node hook name, type name and type cookie and commands + ************************************************************************** + **************************************************************************/ + +/* Hook name */ +#define NG_H4_HOOK "hook" + +/* Node type name and magic cookie */ +#define NG_H4_NODE_TYPE "h4" +#define NGM_H4_COOKIE 1013899512 + +/* Node states */ +#define NG_H4_W4_PKT_IND 1 /* Waiting for packet indicator */ +#define NG_H4_W4_PKT_HDR 2 /* Waiting for packet header */ +#define NG_H4_W4_PKT_DATA 3 /* Waiting for packet data */ + +/* Debug levels */ +#define NG_H4_ALERT_LEVEL 1 +#define NG_H4_ERR_LEVEL 2 +#define NG_H4_WARN_LEVEL 3 +#define NG_H4_INFO_LEVEL 4 + +/************************************************************************** + ************************************************************************** + ** H4 node command/event parameters + ************************************************************************** + **************************************************************************/ + +/* Reset node */ +#define NGM_H4_NODE_RESET 1 + +/* Get node state (see states above) */ +#define NGM_H4_NODE_GET_STATE 2 +typedef u_int16_t ng_h4_node_state_ep; + +/* Get/Set node debug level (see levels above) */ +#define NGM_H4_NODE_GET_DEBUG 3 +#define NGM_H4_NODE_SET_DEBUG 4 +typedef u_int16_t ng_h4_node_debug_ep; + +/* Get/Set max queue length for the node */ +#define NGM_H4_NODE_GET_QLEN 5 +#define NGM_H4_NODE_SET_QLEN 6 +typedef int32_t ng_h4_node_qlen_ep; + +/* Get node statistic */ +#define NGM_H4_NODE_GET_STAT 7 +typedef struct { + u_int32_t pckts_recv; /* # of packets received */ + u_int32_t bytes_recv; /* # of bytes received */ + u_int32_t pckts_sent; /* # of packets sent */ + u_int32_t bytes_sent; /* # of bytes sent */ + u_int32_t oerrors; /* # of output errors */ + u_int32_t ierrors; /* # of input errors */ +} ng_h4_node_stat_ep; + +/* Reset node statistic */ +#define NGM_H4_NODE_RESET_STAT 8 + +#endif /* _NETGRAPH_H4_H_ */ diff --git a/sys/netbt/hci.h b/sys/netbt/hci.h new file mode 100644 index 00000000000..13239579cb1 --- /dev/null +++ b/sys/netbt/hci.h @@ -0,0 +1,1660 @@ +/* $OpenBSD: hci.h,v 1.1 2005/01/14 12:04:02 grange Exp $ */ + +/* + * ng_hci.h + * + * Copyright (c) 2001 Maksim Yevmenkin <m_evmenkin@yahoo.com> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: hci.h,v 1.1 2005/01/14 12:04:02 grange Exp $ + * $FreeBSD: src/sys/netgraph/bluetooth/include/ng_hci.h,v 1.4 2004/08/10 00:38:50 emax Exp $ + */ + +/* + * This file contains everything that application needs to know about + * Host Controller Interface (HCI). All information was obtained from + * Bluetooth Specification Book v1.1. + * + * This file can be included by both kernel and userland applications. + * + * NOTE: Here and after Bluetooth device is called a "unit". Bluetooth + * specification refers to both devices and units. They are the + * same thing (i think), so to be consistent word "unit" will be + * used. + */ + +#ifndef _NETGRAPH_HCI_H_ +#define _NETGRAPH_HCI_H_ + +/************************************************************************** + ************************************************************************** + ** Netgraph node hook name, type name and type cookie and commands + ************************************************************************** + **************************************************************************/ + +/* Node type name and type cookie */ +#define NG_HCI_NODE_TYPE "hci" +#define NGM_HCI_COOKIE 1000774184 + +/* Netgraph node hook names */ +#define NG_HCI_HOOK_DRV "drv" /* Driver <-> HCI */ +#define NG_HCI_HOOK_ACL "acl" /* HCI <-> Upper */ +#define NG_HCI_HOOK_SCO "sco" /* HCI <-> Upper */ +#define NG_HCI_HOOK_RAW "raw" /* HCI <-> Upper */ + +/************************************************************************** + ************************************************************************** + ** Common defines and types (HCI) + ************************************************************************** + **************************************************************************/ + +/* All sizes are in bytes */ +#define NG_HCI_BDADDR_SIZE 6 /* unit address */ +#define NG_HCI_LAP_SIZE 3 /* unit LAP */ +#define NG_HCI_KEY_SIZE 16 /* link key */ +#define NG_HCI_PIN_SIZE 16 /* link PIN */ +#define NG_HCI_EVENT_MASK_SIZE 8 /* event mask */ +#define NG_HCI_CLASS_SIZE 3 /* unit class */ +#define NG_HCI_FEATURES_SIZE 8 /* LMP features */ +#define NG_HCI_UNIT_NAME_SIZE 248 /* unit name size */ + +/* HCI specification */ +#define NG_HCI_SPEC_V10 0x00 /* v1.0 */ +#define NG_HCI_SPEC_V11 0x01 /* v1.1 */ +/* 0x02 - 0xFF - reserved for future use */ + +/* LMP features */ +/* ------------------- byte 0 --------------------*/ +#define NG_HCI_LMP_3SLOT 0x01 +#define NG_HCI_LMP_5SLOT 0x02 +#define NG_HCI_LMP_ENCRYPTION 0x04 +#define NG_HCI_LMP_SLOT_OFFSET 0x08 +#define NG_HCI_LMP_TIMING_ACCURACY 0x10 +#define NG_HCI_LMP_SWITCH 0x20 +#define NG_HCI_LMP_HOLD_MODE 0x40 +#define NG_HCI_LMP_SNIFF_MODE 0x80 +/* ------------------- byte 1 --------------------*/ +#define NG_HCI_LMP_PARK_MODE 0x01 +#define NG_HCI_LMP_RSSI 0x02 +#define NG_HCI_LMP_CHANNEL_QUALITY 0x04 +#define NG_HCI_LMP_SCO_LINK 0x08 +#define NG_HCI_LMP_HV2_PKT 0x10 +#define NG_HCI_LMP_HV3_PKT 0x20 +#define NG_HCI_LMP_ULAW_LOG 0x40 +#define NG_HCI_LMP_ALAW_LOG 0x80 +/* ------------------- byte 2 --------------------*/ +#define NG_HCI_LMP_CVSD 0x01 +#define NG_HCI_LMP_PAGING_SCHEME 0x02 +#define NG_HCI_LMP_POWER_CONTROL 0x04 +#define NG_HCI_LMP_TRANSPARENT_SCO 0x08 +#define NG_HCI_LMP_FLOW_CONTROL_LAG0 0x10 +#define NG_HCI_LMP_FLOW_CONTROL_LAG1 0x20 +#define NG_HCI_LMP_FLOW_CONTROL_LAG2 0x40 + +/* Link types */ +#define NG_HCI_LINK_SCO 0x00 /* Voice */ +#define NG_HCI_LINK_ACL 0x01 /* Data */ +/* 0x02 - 0xFF - reserved for future use */ + +/* Packet types */ + /* 0x0001 - 0x0004 - reserved for future use */ +#define NG_HCI_PKT_DM1 0x0008 /* ACL link */ +#define NG_HCI_PKT_DH1 0x0010 /* ACL link */ +#define NG_HCI_PKT_HV1 0x0020 /* SCO link */ +#define NG_HCI_PKT_HV2 0x0040 /* SCO link */ +#define NG_HCI_PKT_HV3 0x0080 /* SCO link */ + /* 0x0100 - 0x0200 - reserved for future use */ +#define NG_HCI_PKT_DM3 0x0400 /* ACL link */ +#define NG_HCI_PKT_DH3 0x0800 /* ACL link */ + /* 0x1000 - 0x2000 - reserved for future use */ +#define NG_HCI_PKT_DM5 0x4000 /* ACL link */ +#define NG_HCI_PKT_DH5 0x8000 /* ACL link */ + +/* + * Connection modes/Unit modes + * + * This is confusing. It means that one of the units change its mode + * for the specific connection. For example one connection was put on + * hold (but i could be wrong :) + */ + +#define NG_HCI_UNIT_MODE_ACTIVE 0x00 +#define NG_HCI_UNIT_MODE_HOLD 0x01 +#define NG_HCI_UNIT_MODE_SNIFF 0x02 +#define NG_HCI_UNIT_MODE_PARK 0x03 +/* 0x04 - 0xFF - reserved for future use */ + +/* Page scan modes */ +#define NG_HCI_MANDATORY_PAGE_SCAN_MODE 0x00 +#define NG_HCI_OPTIONAL_PAGE_SCAN_MODE1 0x01 +#define NG_HCI_OPTIONAL_PAGE_SCAN_MODE2 0x02 +#define NG_HCI_OPTIONAL_PAGE_SCAN_MODE3 0x03 +/* 0x04 - 0xFF - reserved for future use */ + +/* Page scan repetition modes */ +#define NG_HCI_SCAN_REP_MODE0 0x00 +#define NG_HCI_SCAN_REP_MODE1 0x01 +#define NG_HCI_SCAN_REP_MODE2 0x02 +/* 0x03 - 0xFF - reserved for future use */ + +/* Page scan period modes */ +#define NG_HCI_PAGE_SCAN_PERIOD_MODE0 0x00 +#define NG_HCI_PAGE_SCAN_PERIOD_MODE1 0x01 +#define NG_HCI_PAGE_SCAN_PERIOD_MODE2 0x02 +/* 0x03 - 0xFF - reserved for future use */ + +/* Scan enable */ +#define NG_HCI_NO_SCAN_ENABLE 0x00 +#define NG_HCI_INQUIRY_ENABLE_PAGE_DISABLE 0x01 +#define NG_HCI_INQUIRY_DISABLE_PAGE_ENABLE 0x02 +#define NG_HCI_INQUIRY_ENABLE_PAGE_ENABLE 0x03 +/* 0x04 - 0xFF - reserved for future use */ + +/* Hold mode activities */ +#define NG_HCI_HOLD_MODE_NO_CHANGE 0x00 +#define NG_HCI_HOLD_MODE_SUSPEND_PAGE_SCAN 0x01 +#define NG_HCI_HOLD_MODE_SUSPEND_INQUIRY_SCAN 0x02 +#define NG_HCI_HOLD_MODE_SUSPEND_PERIOD_INQUIRY 0x04 +/* 0x08 - 0x80 - reserved for future use */ + +/* Connection roles */ +#define NG_HCI_ROLE_MASTER 0x00 +#define NG_HCI_ROLE_SLAVE 0x01 +/* 0x02 - 0xFF - reserved for future use */ + +/* Key flags */ +#define NG_HCI_USE_SEMI_PERMANENT_LINK_KEYS 0x00 +#define NG_HCI_USE_TEMPORARY_LINK_KEY 0x01 +/* 0x02 - 0xFF - reserved for future use */ + +/* Pin types */ +#define NG_HCI_PIN_TYPE_VARIABLE 0x00 +#define NG_HCI_PIN_TYPE_FIXED 0x01 + +/* Link key types */ +#define NG_HCI_LINK_KEY_TYPE_COMBINATION_KEY 0x00 +#define NG_HCI_LINK_KEY_TYPE_LOCAL_UNIT_KEY 0x01 +#define NG_HCI_LINK_KEY_TYPE_REMOTE_UNIT_KEY 0x02 +/* 0x03 - 0xFF - reserved for future use */ + +/* Encryption modes */ +#define NG_HCI_ENCRYPTION_MODE_NONE 0x00 +#define NG_HCI_ENCRYPTION_MODE_P2P 0x01 +#define NG_HCI_ENCRYPTION_MODE_ALL 0x02 +/* 0x03 - 0xFF - reserved for future use */ + +/* Quality of service types */ +#define NG_HCI_SERVICE_TYPE_NO_TRAFFIC 0x00 +#define NG_HCI_SERVICE_TYPE_BEST_EFFORT 0x01 +#define NG_HCI_SERVICE_TYPE_GUARANTEED 0x02 +/* 0x03 - 0xFF - reserved for future use */ + +/* Link policy settings */ +#define NG_HCI_LINK_POLICY_DISABLE_ALL_LM_MODES 0x0000 +#define NG_HCI_LINK_POLICY_ENABLE_ROLE_SWITCH 0x0001 /* Master/Slave switch */ +#define NG_HCI_LINK_POLICY_ENABLE_HOLD_MODE 0x0002 +#define NG_HCI_LINK_POLICY_ENABLE_SNIFF_MODE 0x0004 +#define NG_HCI_LINK_POLICY_ENABLE_PARK_MODE 0x0008 +/* 0x0010 - 0x8000 - reserved for future use */ + +/* Event masks */ +#define NG_HCI_EVMSK_ALL 0x00000000ffffffff +#define NG_HCI_EVMSK_NONE 0x0000000000000000 +#define NG_HCI_EVMSK_INQUIRY_COMPL 0x0000000000000001 +#define NG_HCI_EVMSK_INQUIRY_RESULT 0x0000000000000002 +#define NG_HCI_EVMSK_CON_COMPL 0x0000000000000004 +#define NG_HCI_EVMSK_CON_REQ 0x0000000000000008 +#define NG_HCI_EVMSK_DISCON_COMPL 0x0000000000000010 +#define NG_HCI_EVMSK_AUTH_COMPL 0x0000000000000020 +#define NG_HCI_EVMSK_REMOTE_NAME_REQ_COMPL 0x0000000000000040 +#define NG_HCI_EVMSK_ENCRYPTION_CHANGE 0x0000000000000080 +#define NG_HCI_EVMSK_CHANGE_CON_LINK_KEY_COMPL 0x0000000000000100 +#define NG_HCI_EVMSK_MASTER_LINK_KEY_COMPL 0x0000000000000200 +#define NG_HCI_EVMSK_READ_REMOTE_FEATURES_COMPL 0x0000000000000400 +#define NG_HCI_EVMSK_READ_REMOTE_VER_INFO_COMPL 0x0000000000000800 +#define NG_HCI_EVMSK_QOS_SETUP_COMPL 0x0000000000001000 +#define NG_HCI_EVMSK_COMMAND_COMPL 0x0000000000002000 +#define NG_HCI_EVMSK_COMMAND_STATUS 0x0000000000004000 +#define NG_HCI_EVMSK_HARDWARE_ERROR 0x0000000000008000 +#define NG_HCI_EVMSK_FLUSH_OCCUR 0x0000000000010000 +#define NG_HCI_EVMSK_ROLE_CHANGE 0x0000000000020000 +#define NG_HCI_EVMSK_NUM_COMPL_PKTS 0x0000000000040000 +#define NG_HCI_EVMSK_MODE_CHANGE 0x0000000000080000 +#define NG_HCI_EVMSK_RETURN_LINK_KEYS 0x0000000000100000 +#define NG_HCI_EVMSK_PIN_CODE_REQ 0x0000000000200000 +#define NG_HCI_EVMSK_LINK_KEY_REQ 0x0000000000400000 +#define NG_HCI_EVMSK_LINK_KEY_NOTIFICATION 0x0000000000800000 +#define NG_HCI_EVMSK_LOOPBACK_COMMAND 0x0000000001000000 +#define NG_HCI_EVMSK_DATA_BUFFER_OVERFLOW 0x0000000002000000 +#define NG_HCI_EVMSK_MAX_SLOT_CHANGE 0x0000000004000000 +#define NG_HCI_EVMSK_READ_CLOCK_OFFSET_COMLETE 0x0000000008000000 +#define NG_HCI_EVMSK_CON_PKT_TYPE_CHANGED 0x0000000010000000 +#define NG_HCI_EVMSK_QOS_VIOLATION 0x0000000020000000 +#define NG_HCI_EVMSK_PAGE_SCAN_MODE_CHANGE 0x0000000040000000 +#define NG_HCI_EVMSK_PAGE_SCAN_REP_MODE_CHANGE 0x0000000080000000 +/* 0x0000000100000000 - 0x8000000000000000 - reserved for future use */ + +/* Filter types */ +#define NG_HCI_FILTER_TYPE_NONE 0x00 +#define NG_HCI_FILTER_TYPE_INQUIRY_RESULT 0x01 +#define NG_HCI_FILTER_TYPE_CON_SETUP 0x02 +/* 0x03 - 0xFF - reserved for future use */ + +/* Filter condition types for NG_HCI_FILTER_TYPE_INQUIRY_RESULT */ +#define NG_HCI_FILTER_COND_INQUIRY_NEW_UNIT 0x00 +#define NG_HCI_FILTER_COND_INQUIRY_UNIT_CLASS 0x01 +#define NG_HCI_FILTER_COND_INQUIRY_BDADDR 0x02 +/* 0x03 - 0xFF - reserved for future use */ + +/* Filter condition types for NG_HCI_FILTER_TYPE_CON_SETUP */ +#define NG_HCI_FILTER_COND_CON_ANY_UNIT 0x00 +#define NG_HCI_FILTER_COND_CON_UNIT_CLASS 0x01 +#define NG_HCI_FILTER_COND_CON_BDADDR 0x02 +/* 0x03 - 0xFF - reserved for future use */ + +/* Xmit level types */ +#define NG_HCI_XMIT_LEVEL_CURRENT 0x00 +#define NG_HCI_XMIT_LEVEL_MAXIMUM 0x01 +/* 0x02 - 0xFF - reserved for future use */ + +/* Host to Host Controller flow control */ +#define NG_HCI_H2HC_FLOW_CONTROL_NONE 0x00 +#define NG_HCI_H2HC_FLOW_CONTROL_ACL 0x01 +#define NG_HCI_H2HC_FLOW_CONTROL_SCO 0x02 +#define NG_HCI_H2HC_FLOW_CONTROL_BOTH 0x03 /* ACL and SCO */ +/* 0x04 - 0xFF - reserved future use */ + +/* Country codes */ +#define NG_HCI_COUNTRY_CODE_NAM_EUR_JP 0x00 +#define NG_HCI_COUNTRY_CODE_FRANCE 0x01 +/* 0x02 - 0xFF - reserved future use */ + +/* Loopback modes */ +#define NG_HCI_LOOPBACK_NONE 0x00 +#define NG_HCI_LOOPBACK_LOCAL 0x01 +#define NG_HCI_LOOPBACK_REMOTE 0x02 +/* 0x03 - 0xFF - reserved future use */ + +/************************************************************************** + ************************************************************************** + ** Link level defines, headers and types + ************************************************************************** + **************************************************************************/ + +/* + * Macro(s) to combine OpCode and extract OGF (OpCode Group Field) + * and OCF (OpCode Command Field) from OpCode. + */ + +#define NG_HCI_OPCODE(gf,cf) ((((gf) & 0x3f) << 10) | ((cf) & 0x3ff)) +#define NG_HCI_OCF(op) ((op) & 0x3ff) +#define NG_HCI_OGF(op) (((op) >> 10) & 0x3f) + +/* + * Marco(s) to extract/combine connection handle, BC (Broadcast) and + * PB (Packet boundary) flags. + */ + +#define NG_HCI_CON_HANDLE(h) ((h) & 0x0fff) +#define NG_HCI_PB_FLAG(h) (((h) & 0x3000) >> 12) +#define NG_HCI_BC_FLAG(h) (((h) & 0xc000) >> 14) +#define NG_HCI_MK_CON_HANDLE(h, pb, bc) \ + (((h) & 0x0fff) | (((pb) & 3) << 12) | (((bc) & 3) << 14)) + +/* PB flag values */ + /* 00 - reserved for future use */ +#define NG_HCI_PACKET_FRAGMENT 0x1 +#define NG_HCI_PACKET_START 0x2 + /* 11 - reserved for future use */ + +/* BC flag values */ +#define NG_HCI_POINT2POINT 0x0 /* only Host controller to Host */ +#define NG_HCI_BROADCAST_ACTIVE 0x1 /* both directions */ +#define NG_HCI_BROADCAST_PICONET 0x2 /* both directions */ + /* 11 - reserved for future use */ + +/* HCI command packet header */ +#define NG_HCI_CMD_PKT 0x01 +#define NG_HCI_CMD_PKT_SIZE 0xff /* without header */ +typedef struct { + u_int8_t type; /* MUST be 0x1 */ + u_int16_t opcode; /* OpCode */ + u_int8_t length; /* parameter(s) length in bytes */ +} __attribute__ ((packed)) ng_hci_cmd_pkt_t; + +/* ACL data packet header */ +#define NG_HCI_ACL_DATA_PKT 0x02 +#define NG_HCI_ACL_PKT_SIZE 0xffff /* without header */ +typedef struct { + u_int8_t type; /* MUST be 0x2 */ + u_int16_t con_handle; /* connection handle + PB + BC flags */ + u_int16_t length; /* payload length in bytes */ +} __attribute__ ((packed)) ng_hci_acldata_pkt_t; + +/* SCO data packet header */ +#define NG_HCI_SCO_DATA_PKT 0x03 +#define NG_HCI_SCO_PKT_SIZE 0xff /* without header */ +typedef struct { + u_int8_t type; /* MUST be 0x3 */ + u_int16_t con_handle; /* connection handle + reserved bits */ + u_int8_t length; /* payload length in bytes */ +} __attribute__ ((packed)) ng_hci_scodata_pkt_t; + +/* HCI event packet header */ +#define NG_HCI_EVENT_PKT 0x04 +#define NG_HCI_EVENT_PKT_SIZE 0xff /* without header */ +typedef struct { + u_int8_t type; /* MUST be 0x4 */ + u_int8_t event; /* event */ + u_int8_t length; /* parameter(s) length in bytes */ +} __attribute__ ((packed)) ng_hci_event_pkt_t; + +/* Bluetooth unit address */ +typedef struct { + u_int8_t b[NG_HCI_BDADDR_SIZE]; +} __attribute__ ((packed)) bdaddr_t; +typedef bdaddr_t * bdaddr_p; + +/* Any BD_ADDR. Note: This is actually 7 bytes (count '\0' terminator) */ +#define NG_HCI_BDADDR_ANY ((bdaddr_p) "\000\000\000\000\000\000") + +/* HCI status return parameter */ +typedef struct { + u_int8_t status; /* 0x00 - success */ +} __attribute__ ((packed)) ng_hci_status_rp; + +/************************************************************************** + ************************************************************************** + ** Upper layer protocol interface. LP_xxx event parameters + ************************************************************************** + **************************************************************************/ + +/* Connection Request Event */ +#define NGM_HCI_LP_CON_REQ 1 /* Upper -> HCI */ +typedef struct { + u_int16_t link_type; /* type of connection */ + bdaddr_t bdaddr; /* remote unit address */ +} ng_hci_lp_con_req_ep; + +/* + * XXX XXX XXX + * + * NOTE: This request is not defined by Bluetooth specification, + * but i find it useful :) + */ +#define NGM_HCI_LP_DISCON_REQ 2 /* Upper -> HCI */ +typedef struct { + u_int16_t con_handle; /* connection handle */ + u_int16_t reason; /* reason to disconnect (only low byte) */ +} ng_hci_lp_discon_req_ep; + +/* Connection Confirmation Event */ +#define NGM_HCI_LP_CON_CFM 3 /* HCI -> Upper */ +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int8_t link_type; /* link type */ + u_int16_t con_handle; /* con_handle */ + bdaddr_t bdaddr; /* remote unit address */ +} ng_hci_lp_con_cfm_ep; + +/* Connection Indication Event */ +#define NGM_HCI_LP_CON_IND 4 /* HCI -> Upper */ +typedef struct { + u_int8_t link_type; /* link type */ + u_int8_t uclass[NG_HCI_CLASS_SIZE]; /* unit class */ + bdaddr_t bdaddr; /* remote unit address */ +} ng_hci_lp_con_ind_ep; + +/* Connection Response Event */ +#define NGM_HCI_LP_CON_RSP 5 /* Upper -> HCI */ +typedef struct { + u_int8_t status; /* 0x00 - accept connection */ + u_int8_t link_type; /* link type */ + bdaddr_t bdaddr; /* remote unit address */ +} ng_hci_lp_con_rsp_ep; + +/* Disconnection Indication Event */ +#define NGM_HCI_LP_DISCON_IND 6 /* HCI -> Upper */ +typedef struct { + u_int8_t reason; /* reason to disconnect (only low byte) */ + u_int8_t link_type; /* link type */ + u_int16_t con_handle; /* connection handle */ +} ng_hci_lp_discon_ind_ep; + +/* QoS Setup Request Event */ +#define NGM_HCI_LP_QOS_REQ 7 /* Upper -> HCI */ +typedef struct { + u_int16_t con_handle; /* connection handle */ + u_int8_t flags; /* reserved */ + u_int8_t service_type; /* service type */ + u_int32_t token_rate; /* bytes/sec */ + u_int32_t peak_bandwidth; /* bytes/sec */ + u_int32_t latency; /* msec */ + u_int32_t delay_variation; /* msec */ +} ng_hci_lp_qos_req_ep; + +/* QoS Conformition Event */ +#define NGM_HCI_LP_QOS_CFM 8 /* HCI -> Upper */ +typedef struct { + u_int16_t status; /* 0x00 - success (only low byte) */ + u_int16_t con_handle; /* connection handle */ +} ng_hci_lp_qos_cfm_ep; + +/* QoS Violation Indication Event */ +#define NGM_HCI_LP_QOS_IND 9 /* HCI -> Upper */ +typedef struct { + u_int16_t con_handle; /* connection handle */ +} ng_hci_lp_qos_ind_ep; + +/************************************************************************** + ************************************************************************** + ** HCI node command/event parameters + ************************************************************************** + **************************************************************************/ + +/* Debug levels */ +#define NG_HCI_ALERT_LEVEL 1 +#define NG_HCI_ERR_LEVEL 2 +#define NG_HCI_WARN_LEVEL 3 +#define NG_HCI_INFO_LEVEL 4 + +/* Unit states */ +#define NG_HCI_UNIT_CONNECTED (1 << 0) +#define NG_HCI_UNIT_INITED (1 << 1) +#define NG_HCI_UNIT_READY (NG_HCI_UNIT_CONNECTED|NG_HCI_UNIT_INITED) +#define NG_HCI_UNIT_COMMAND_PENDING (1 << 2) + +/* Connection state */ +#define NG_HCI_CON_CLOSED 0 /* connection closed */ +#define NG_HCI_CON_W4_LP_CON_RSP 1 /* wait for LP_ConnectRsp */ +#define NG_HCI_CON_W4_CONN_COMPLETE 2 /* wait for Connection_Complete evt */ +#define NG_HCI_CON_OPEN 3 /* connection open */ + +/* Get HCI node (unit) state (see states above) */ +#define NGM_HCI_NODE_GET_STATE 100 /* HCI -> User */ +typedef u_int16_t ng_hci_node_state_ep; + +/* Turn on "inited" bit */ +#define NGM_HCI_NODE_INIT 101 /* User -> HCI */ +/* No parameters */ + +/* Get/Set node debug level (see debug levels above) */ +#define NGM_HCI_NODE_GET_DEBUG 102 /* HCI -> User */ +#define NGM_HCI_NODE_SET_DEBUG 103 /* User -> HCI */ +typedef u_int16_t ng_hci_node_debug_ep; + +/* Get node buffer info */ +#define NGM_HCI_NODE_GET_BUFFER 104 /* HCI -> User */ +typedef struct { + u_int8_t cmd_free; /* number of free command packets */ + u_int8_t sco_size; /* max. size of SCO packet */ + u_int16_t sco_pkts; /* number of SCO packets */ + u_int16_t sco_free; /* number of free SCO packets */ + u_int16_t acl_size; /* max. size of ACL packet */ + u_int16_t acl_pkts; /* number of ACL packets */ + u_int16_t acl_free; /* number of free ACL packets */ +} ng_hci_node_buffer_ep; + +/* Get BDADDR */ +#define NGM_HCI_NODE_GET_BDADDR 105 /* HCI -> User */ +/* bdaddr_t -- BDADDR */ + +/* Get features */ +#define NGM_HCI_NODE_GET_FEATURES 106 /* HCI -> User */ +/* features[NG_HCI_FEATURES_SIZE] -- features */ + +#define NGM_HCI_NODE_GET_STAT 107 /* HCI -> User */ +typedef struct { + u_int32_t cmd_sent; /* number of HCI commands sent */ + u_int32_t evnt_recv; /* number of HCI events received */ + u_int32_t acl_recv; /* number of ACL packets received */ + u_int32_t acl_sent; /* number of ACL packets sent */ + u_int32_t sco_recv; /* number of SCO packets received */ + u_int32_t sco_sent; /* number of SCO packets sent */ + u_int32_t bytes_recv; /* total number of bytes received */ + u_int32_t bytes_sent; /* total number of bytes sent */ +} ng_hci_node_stat_ep; + +#define NGM_HCI_NODE_RESET_STAT 108 /* User -> HCI */ +/* No parameters */ + +#define NGM_HCI_NODE_FLUSH_NEIGHBOR_CACHE 109 /* User -> HCI */ + +#define NGM_HCI_NODE_GET_NEIGHBOR_CACHE 110 /* HCI -> User */ +typedef struct { + u_int32_t num_entries; /* number of entries */ +} ng_hci_node_get_neighbor_cache_ep; + +typedef struct { + u_int16_t page_scan_rep_mode; /* page rep scan mode */ + u_int16_t page_scan_mode; /* page scan mode */ + u_int16_t clock_offset; /* clock offset */ + bdaddr_t bdaddr; /* bdaddr */ + u_int8_t features[NG_HCI_FEATURES_SIZE]; /* features */ +} ng_hci_node_neighbor_cache_entry_ep; + +#define NG_HCI_MAX_NEIGHBOR_NUM \ + ((0xffff - sizeof(ng_hci_node_get_neighbor_cache_ep))/sizeof(ng_hci_node_neighbor_cache_entry_ep)) + +#define NGM_HCI_NODE_GET_CON_LIST 111 /* HCI -> User */ +typedef struct { + u_int32_t num_connections; /* number of connections */ +} ng_hci_node_con_list_ep; + +typedef struct { + u_int8_t link_type; /* ACL or SCO */ + u_int8_t encryption_mode; /* none, p2p, ... */ + u_int8_t mode; /* ACTIVE, HOLD ... */ + u_int8_t role; /* MASTER/SLAVE */ + u_int16_t state; /* connection state */ + u_int16_t reserved; /* place holder */ + u_int16_t pending; /* number of pending packets */ + u_int16_t queue_len; /* number of packets in queue */ + u_int16_t con_handle; /* connection handle */ + bdaddr_t bdaddr; /* remote bdaddr */ +} ng_hci_node_con_ep; + +#define NG_HCI_MAX_CON_NUM \ + ((0xffff - sizeof(ng_hci_node_con_list_ep))/sizeof(ng_hci_node_con_ep)) + +#define NGM_HCI_NODE_UP 112 /* HCI -> Upper */ +typedef struct { + u_int16_t pkt_size; /* max. ACL/SCO packet size (w/out header) */ + u_int16_t num_pkts; /* ACL/SCO packet queue size */ + u_int16_t reserved; /* place holder */ + bdaddr_t bdaddr; /* bdaddr */ +} ng_hci_node_up_ep; + +#define NGM_HCI_SYNC_CON_QUEUE 113 /* HCI -> Upper */ +typedef struct { + u_int16_t con_handle; /* connection handle */ + u_int16_t completed; /* number of completed packets */ +} ng_hci_sync_con_queue_ep; + +#define NGM_HCI_NODE_GET_LINK_POLICY_SETTINGS_MASK 114 /* HCI -> User */ +#define NGM_HCI_NODE_SET_LINK_POLICY_SETTINGS_MASK 115 /* User -> HCI */ +typedef u_int16_t ng_hci_node_link_policy_mask_ep; + +#define NGM_HCI_NODE_GET_PACKET_MASK 116 /* HCI -> User */ +#define NGM_HCI_NODE_SET_PACKET_MASK 117 /* User -> HCI */ +typedef u_int16_t ng_hci_node_packet_mask_ep; + +#define NGM_HCI_NODE_GET_ROLE_SWITCH 118 /* HCI -> User */ +#define NGM_HCI_NODE_SET_ROLE_SWITCH 119 /* User -> HCI */ +typedef u_int16_t ng_hci_node_role_switch_ep; + +/************************************************************************** + ************************************************************************** + ** Link control commands and return parameters + ************************************************************************** + **************************************************************************/ + +#define NG_HCI_OGF_LINK_CONTROL 0x01 /* OpCode Group Field */ + +#define NG_HCI_OCF_INQUIRY 0x0001 +typedef struct { + u_int8_t lap[NG_HCI_LAP_SIZE]; /* LAP */ + u_int8_t inquiry_length; /* (N x 1.28) sec */ + u_int8_t num_responses; /* Max. # of responses before halted */ +} __attribute__ ((packed)) ng_hci_inquiry_cp; +/* No return parameter(s) */ + +#define NG_HCI_OCF_INQUIRY_CANCEL 0x0002 +/* No command parameter(s) */ +typedef ng_hci_status_rp ng_hci_inquiry_cancel_rp; + +#define NG_HCI_OCF_PERIODIC_INQUIRY 0x0003 +typedef struct { + u_int16_t max_period_length; /* Max. and min. amount of time */ + u_int16_t min_period_length; /* between consecutive inquiries */ + u_int8_t lap[NG_HCI_LAP_SIZE]; /* LAP */ + u_int8_t inquiry_length; /* (inquiry_length * 1.28) sec */ + u_int8_t num_responses; /* Max. # of responses */ +} __attribute__ ((packed)) ng_hci_periodic_inquiry_cp; + +typedef ng_hci_status_rp ng_hci_periodic_inquiry_rp; + +#define NG_HCI_OCF_EXIT_PERIODIC_INQUIRY 0x0004 +/* No command parameter(s) */ +typedef ng_hci_status_rp ng_hci_exit_periodic_inquiry_rp; + +#define NG_HCI_OCF_CREATE_CON 0x0005 +typedef struct { + bdaddr_t bdaddr; /* destination address */ + u_int16_t pkt_type; /* packet type */ + u_int8_t page_scan_rep_mode; /* page scan repetition mode */ + u_int8_t page_scan_mode; /* page scan mode */ + u_int16_t clock_offset; /* clock offset */ + u_int8_t accept_role_switch; /* accept role switch? 0x00 - no */ +} __attribute__ ((packed)) ng_hci_create_con_cp; +/* No return parameter(s) */ + +#define NG_HCI_OCF_DISCON 0x0006 +typedef struct { + u_int16_t con_handle; /* connection handle */ + u_int8_t reason; /* reason to disconnect */ +} __attribute__ ((packed)) ng_hci_discon_cp; +/* No return parameter(s) */ + +#define NG_HCI_OCF_ADD_SCO_CON 0x0007 +typedef struct { + u_int16_t con_handle; /* connection handle */ + u_int16_t pkt_type; /* packet type */ +} __attribute__ ((packed)) ng_hci_add_sco_con_cp; +/* No return parameter(s) */ + +#define NG_HCI_OCF_ACCEPT_CON 0x0009 +typedef struct { + bdaddr_t bdaddr; /* address of unit to be connected */ + u_int8_t role; /* connection role */ +} __attribute__ ((packed)) ng_hci_accept_con_cp; +/* No return parameter(s) */ + +#define NG_HCI_OCF_REJECT_CON 0x000a +typedef struct { + bdaddr_t bdaddr; /* remote address */ + u_int8_t reason; /* reason to reject */ +} __attribute__ ((packed)) ng_hci_reject_con_cp; +/* No return parameter(s) */ + +#define NG_HCI_OCF_LINK_KEY_REP 0x000b +typedef struct { + bdaddr_t bdaddr; /* remote address */ + u_int8_t key[NG_HCI_KEY_SIZE]; /* key */ +} __attribute__ ((packed)) ng_hci_link_key_rep_cp; + +typedef struct { + u_int8_t status; /* 0x00 - success */ + bdaddr_t bdaddr; /* unit address */ +} __attribute__ ((packed)) ng_hci_link_key_rep_rp; + +#define NG_HCI_OCF_LINK_KEY_NEG_REP 0x000c +typedef struct { + bdaddr_t bdaddr; /* remote address */ +} __attribute__ ((packed)) ng_hci_link_key_neg_rep_cp; + +typedef struct { + u_int8_t status; /* 0x00 - success */ + bdaddr_t bdaddr; /* unit address */ +} __attribute__ ((packed)) ng_hci_link_key_neg_rep_rp; + +#define NG_HCI_OCF_PIN_CODE_REP 0x000d +typedef struct { + bdaddr_t bdaddr; /* remote address */ + u_int8_t pin_size; /* pin code length (in bytes) */ + u_int8_t pin[NG_HCI_PIN_SIZE]; /* pin code */ +} __attribute__ ((packed)) ng_hci_pin_code_rep_cp; + +typedef struct { + u_int8_t status; /* 0x00 - success */ + bdaddr_t bdaddr; /* unit address */ +} __attribute__ ((packed)) ng_hci_pin_code_rep_rp; + +#define NG_HCI_OCF_PIN_CODE_NEG_REP 0x000e +typedef struct { + bdaddr_t bdaddr; /* remote address */ +} __attribute__ ((packed)) ng_hci_pin_code_neg_rep_cp; + +typedef struct { + u_int8_t status; /* 0x00 - success */ + bdaddr_t bdaddr; /* unit address */ +} __attribute__ ((packed)) ng_hci_pin_code_neg_rep_rp; + +#define NG_HCI_OCF_CHANGE_CON_PKT_TYPE 0x000f +typedef struct { + u_int16_t con_handle; /* connection handle */ + u_int16_t pkt_type; /* packet type */ +} __attribute__ ((packed)) ng_hci_change_con_pkt_type_cp; +/* No return parameter(s) */ + +#define NG_HCI_OCF_AUTH_REQ 0x0011 +typedef struct { + u_int16_t con_handle; /* connection handle */ +} __attribute__ ((packed)) ng_hci_auth_req_cp; +/* No return parameter(s) */ + +#define NG_HCI_OCF_SET_CON_ENCRYPTION 0x0013 +typedef struct { + u_int16_t con_handle; /* connection handle */ + u_int8_t encryption_enable; /* 0x00 - disable, 0x01 - enable */ +} __attribute__ ((packed)) ng_hci_set_con_encryption_cp; +/* No return parameter(s) */ + +#define NG_HCI_OCF_CHANGE_CON_LINK_KEY 0x0015 +typedef struct { + u_int16_t con_handle; /* connection handle */ +} __attribute__ ((packed)) ng_hci_change_con_link_key_cp; +/* No return parameter(s) */ + +#define NG_HCI_OCF_MASTER_LINK_KEY 0x0017 +typedef struct { + u_int8_t key_flag; /* key flag */ +} __attribute__ ((packed)) ng_hci_master_link_key_cp; +/* No return parameter(s) */ + +#define NG_HCI_OCF_REMOTE_NAME_REQ 0x0019 +typedef struct { + bdaddr_t bdaddr; /* remote address */ + u_int8_t page_scan_rep_mode; /* page scan repetition mode */ + u_int8_t page_scan_mode; /* page scan mode */ + u_int16_t clock_offset; /* clock offset */ +} __attribute__ ((packed)) ng_hci_remote_name_req_cp; +/* No return parameter(s) */ + +#define NG_HCI_OCF_READ_REMOTE_FEATURES 0x001b +typedef struct { + u_int16_t con_handle; /* connection handle */ +} __attribute__ ((packed)) ng_hci_read_remote_features_cp; +/* No return parameter(s) */ + +#define NG_HCI_OCF_READ_REMOTE_VER_INFO 0x001d +typedef struct { + u_int16_t con_handle; /* connection handle */ +} __attribute__ ((packed)) ng_hci_read_remote_ver_info_cp; +/* No return parameter(s) */ + +#define NG_HCI_OCF_READ_CLOCK_OFFSET 0x001f +typedef struct { + u_int16_t con_handle; /* connection handle */ +} __attribute__ ((packed)) ng_hci_read_clock_offset_cp; +/* No return parameter(s) */ + +/************************************************************************** + ************************************************************************** + ** Link policy commands and return parameters + ************************************************************************** + **************************************************************************/ + +#define NG_HCI_OGF_LINK_POLICY 0x02 /* OpCode Group Field */ + +#define NG_HCI_OCF_HOLD_MODE 0x0001 +typedef struct { + u_int16_t con_handle; /* connection handle */ + u_int16_t max_interval; /* (max_interval * 0.625) msec */ + u_int16_t min_interval; /* (max_interval * 0.625) msec */ +} __attribute__ ((packed)) ng_hci_hold_mode_cp; +/* No return parameter(s) */ + +#define NG_HCI_OCF_SNIFF_MODE 0x0003 +typedef struct { + u_int16_t con_handle; /* connection handle */ + u_int16_t max_interval; /* (max_interval * 0.625) msec */ + u_int16_t min_interval; /* (max_interval * 0.625) msec */ + u_int16_t attempt; /* (2 * attempt - 1) * 0.625 msec */ + u_int16_t timeout; /* (2 * attempt - 1) * 0.625 msec */ +} __attribute__ ((packed)) ng_hci_sniff_mode_cp; +/* No return parameter(s) */ + +#define NG_HCI_OCF_EXIT_SNIFF_MODE 0x0004 +typedef struct { + u_int16_t con_handle; /* connection handle */ +} __attribute__ ((packed)) ng_hci_exit_sniff_mode_cp; +/* No return parameter(s) */ + +#define NG_HCI_OCF_PARK_MODE 0x0005 +typedef struct { + u_int16_t con_handle; /* connection handle */ + u_int16_t max_interval; /* (max_interval * 0.625) msec */ + u_int16_t min_interval; /* (max_interval * 0.625) msec */ +} __attribute__ ((packed)) ng_hci_park_mode_cp; +/* No return parameter(s) */ + +#define NG_HCI_OCF_EXIT_PARK_MODE 0x0006 +typedef struct { + u_int16_t con_handle; /* connection handle */ +} __attribute__ ((packed)) ng_hci_exit_park_mode_cp; +/* No return parameter(s) */ + +#define NG_HCI_OCF_QOS_SETUP 0x0007 +typedef struct { + u_int16_t con_handle; /* connection handle */ + u_int8_t flags; /* reserved for future use */ + u_int8_t service_type; /* service type */ + u_int32_t token_rate; /* bytes per second */ + u_int32_t peak_bandwidth; /* bytes per second */ + u_int32_t latency; /* microseconds */ + u_int32_t delay_variation; /* microseconds */ +} __attribute__ ((packed)) ng_hci_qos_setup_cp; +/* No return parameter(s) */ + +#define NG_HCI_OCF_ROLE_DISCOVERY 0x0009 +typedef struct { + u_int16_t con_handle; /* connection handle */ +} __attribute__ ((packed)) ng_hci_role_discovery_cp; + +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int16_t con_handle; /* connection handle */ + u_int8_t role; /* role for the connection handle */ +} __attribute__ ((packed)) ng_hci_role_discovery_rp; + +#define NG_HCI_OCF_SWITCH_ROLE 0x000b +typedef struct { + bdaddr_t bdaddr; /* remote address */ + u_int8_t role; /* new local role */ +} __attribute__ ((packed)) ng_hci_switch_role_cp; +/* No return parameter(s) */ + +#define NG_HCI_OCF_READ_LINK_POLICY_SETTINGS 0x000c +typedef struct { + u_int16_t con_handle; /* connection handle */ +} __attribute__ ((packed)) ng_hci_read_link_policy_settings_cp; + +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int16_t con_handle; /* connection handle */ + u_int16_t settings; /* link policy settings */ +} __attribute__ ((packed)) ng_hci_read_link_policy_settings_rp; + +#define NG_HCI_OCF_WRITE_LINK_POLICY_SETTINGS 0x000d +typedef struct { + u_int16_t con_handle; /* connection handle */ + u_int16_t settings; /* link policy settings */ +} __attribute__ ((packed)) ng_hci_write_link_policy_settings_cp; + +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int16_t con_handle; /* connection handle */ +} __attribute__ ((packed)) ng_hci_write_link_policy_settings_rp; + +/************************************************************************** + ************************************************************************** + ** Host controller and baseband commands and return parameters + ************************************************************************** + **************************************************************************/ + +#define NG_HCI_OGF_HC_BASEBAND 0x03 /* OpCode Group Field */ + +#define NG_HCI_OCF_SET_EVENT_MASK 0x0001 +typedef struct { + u_int8_t event_mask[NG_HCI_EVENT_MASK_SIZE]; /* event_mask */ +} __attribute__ ((packed)) ng_hci_set_event_mask_cp; + +typedef ng_hci_status_rp ng_hci_set_event_mask_rp; + +#define NG_HCI_OCF_RESET 0x0003 +/* No command parameter(s) */ +typedef ng_hci_status_rp ng_hci_reset_rp; + +#define NG_HCI_OCF_SET_EVENT_FILTER 0x0005 +typedef struct { + u_int8_t filter_type; /* filter type */ + u_int8_t filter_condition_type; /* filter condition type */ + u_int8_t condition[0]; /* conditions - variable size */ +} __attribute__ ((packed)) ng_hci_set_event_filter_cp; + +typedef ng_hci_status_rp ng_hci_set_event_filter_rp; + +#define NG_HCI_OCF_FLUSH 0x0008 +typedef struct { + u_int16_t con_handle; /* connection handle */ +} __attribute__ ((packed)) ng_hci_flush_cp; + +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int16_t con_handle; /* connection handle */ +} __attribute__ ((packed)) ng_hci_flush_rp; + +#define NG_HCI_OCF_READ_PIN_TYPE 0x0009 +/* No command parameter(s) */ +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int8_t pin_type; /* PIN type */ +} __attribute__ ((packed)) ng_hci_read_pin_type_rp; + +#define NG_HCI_OCF_WRITE_PIN_TYPE 0x000a +typedef struct { + u_int8_t pin_type; /* PIN type */ +} __attribute__ ((packed)) ng_hci_write_pin_type_cp; + +typedef ng_hci_status_rp ng_hci_write_pin_type_rp; + +#define NG_HCI_OCF_CREATE_NEW_UNIT_KEY 0x000b +/* No command parameter(s) */ +typedef ng_hci_status_rp ng_hci_create_new_unit_key_rp; + +#define NG_HCI_OCF_READ_STORED_LINK_KEY 0x000d +typedef struct { + bdaddr_t bdaddr; /* address */ + u_int8_t read_all; /* read all keys? 0x01 - yes */ +} __attribute__ ((packed)) ng_hci_read_stored_link_key_cp; + +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int16_t max_num_keys; /* Max. number of keys */ + u_int16_t num_keys_read; /* Number of stored keys */ +} __attribute__ ((packed)) ng_hci_read_stored_link_key_rp; + +#define NG_HCI_OCF_WRITE_STORED_LINK_KEY 0x0011 +typedef struct { + u_int8_t num_keys_write; /* # of keys to write */ +/* these are repeated "num_keys_write" times + bdaddr_t bdaddr; --- remote address(es) + u_int8_t key[NG_HCI_KEY_SIZE]; --- key(s) */ +} __attribute__ ((packed)) ng_hci_write_stored_link_key_cp; + +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int8_t num_keys_written; /* # of keys successfully written */ +} __attribute__ ((packed)) ng_hci_write_stored_link_key_rp; + +#define NG_HCI_OCF_DELETE_STORED_LINK_KEY 0x0012 +typedef struct { + bdaddr_t bdaddr; /* address */ + u_int8_t delete_all; /* delete all keys? 0x01 - yes */ +} __attribute__ ((packed)) ng_hci_delete_stored_link_key_cp; + +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int16_t num_keys_deleted; /* Number of keys deleted */ +} __attribute__ ((packed)) ng_hci_delete_stored_link_key_rp; + +#define NG_HCI_OCF_CHANGE_LOCAL_NAME 0x0013 +typedef struct { + char name[NG_HCI_UNIT_NAME_SIZE]; /* new unit name */ +} __attribute__ ((packed)) ng_hci_change_local_name_cp; + +typedef ng_hci_status_rp ng_hci_change_local_name_rp; + +#define NG_HCI_OCF_READ_LOCAL_NAME 0x0014 +/* No command parameter(s) */ +typedef struct { + u_int8_t status; /* 0x00 - success */ + char name[NG_HCI_UNIT_NAME_SIZE]; /* unit name */ +} __attribute__ ((packed)) ng_hci_read_local_name_rp; + +#define NG_HCI_OCF_READ_CON_ACCEPT_TIMO 0x0015 +/* No command parameter(s) */ +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int16_t timeout; /* (timeout * 0.625) msec */ +} __attribute__ ((packed)) ng_hci_read_con_accept_timo_rp; + +#define NG_HCI_OCF_WRITE_CON_ACCEPT_TIMO 0x0016 +typedef struct { + u_int16_t timeout; /* (timeout * 0.625) msec */ +} __attribute__ ((packed)) ng_hci_write_con_accept_timo_cp; + +typedef ng_hci_status_rp ng_hci_write_con_accept_timo_rp; + +#define NG_HCI_OCF_READ_PAGE_TIMO 0x0017 +/* No command parameter(s) */ +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int16_t timeout; /* (timeout * 0.625) msec */ +} __attribute__ ((packed)) ng_hci_read_page_timo_rp; + +#define NG_HCI_OCF_WRITE_PAGE_TIMO 0x0018 +typedef struct { + u_int16_t timeout; /* (timeout * 0.625) msec */ +} __attribute__ ((packed)) ng_hci_write_page_timo_cp; + +typedef ng_hci_status_rp ng_hci_write_page_timo_rp; + +#define NG_HCI_OCF_READ_SCAN_ENABLE 0x0019 +/* No command parameter(s) */ +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int8_t scan_enable; /* Scan enable */ +} __attribute__ ((packed)) ng_hci_read_scan_enable_rp; + +#define NG_HCI_OCF_WRITE_SCAN_ENABLE 0x001a +typedef struct { + u_int8_t scan_enable; /* Scan enable */ +} __attribute__ ((packed)) ng_hci_write_scan_enable_cp; + +typedef ng_hci_status_rp ng_hci_write_scan_enable_rp; + +#define NG_HCI_OCF_READ_PAGE_SCAN_ACTIVITY 0x001b +/* No command parameter(s) */ +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int16_t page_scan_interval; /* interval * 0.625 msec */ + u_int16_t page_scan_window; /* window * 0.625 msec */ +} __attribute__ ((packed)) ng_hci_read_page_scan_activity_rp; + +#define NG_HCI_OCF_WRITE_PAGE_SCAN_ACTIVITY 0x001c +typedef struct { + u_int16_t page_scan_interval; /* interval * 0.625 msec */ + u_int16_t page_scan_window; /* window * 0.625 msec */ +} __attribute__ ((packed)) ng_hci_write_page_scan_activity_cp; + +typedef ng_hci_status_rp ng_hci_write_page_scan_activity_rp; + +#define NG_HCI_OCF_READ_INQUIRY_SCAN_ACTIVITY 0x001d +/* No command parameter(s) */ +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int16_t inquiry_scan_interval; /* interval * 0.625 msec */ + u_int16_t inquiry_scan_window; /* window * 0.625 msec */ +} __attribute__ ((packed)) ng_hci_read_inquiry_scan_activity_rp; + +#define NG_HCI_OCF_WRITE_INQUIRY_SCAN_ACTIVITY 0x001e +typedef struct { + u_int16_t inquiry_scan_interval; /* interval * 0.625 msec */ + u_int16_t inquiry_scan_window; /* window * 0.625 msec */ +} __attribute__ ((packed)) ng_hci_write_inquiry_scan_activity_cp; + +typedef ng_hci_status_rp ng_hci_write_inquiry_scan_activity_rp; + +#define NG_HCI_OCF_READ_AUTH_ENABLE 0x001f +/* No command parameter(s) */ +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int8_t auth_enable; /* 0x01 - enabled */ +} __attribute__ ((packed)) ng_hci_read_auth_enable_rp; + +#define NG_HCI_OCF_WRITE_AUTH_ENABLE 0x0020 +typedef struct { + u_int8_t auth_enable; /* 0x01 - enabled */ +} __attribute__ ((packed)) ng_hci_write_auth_enable_cp; + +typedef ng_hci_status_rp ng_hci_write_auth_enable_rp; + +#define NG_HCI_OCF_READ_ENCRYPTION_MODE 0x0021 +/* No command parameter(s) */ +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int8_t encryption_mode; /* encryption mode */ +} __attribute__ ((packed)) ng_hci_read_encryption_mode_rp; + +#define NG_HCI_OCF_WRITE_ENCRYPTION_MODE 0x0022 +typedef struct { + u_int8_t encryption_mode; /* encryption mode */ +} __attribute__ ((packed)) ng_hci_write_encryption_mode_cp; + +typedef ng_hci_status_rp ng_hci_write_encryption_mode_rp; + +#define NG_HCI_OCF_READ_UNIT_CLASS 0x0023 +/* No command parameter(s) */ +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int8_t uclass[NG_HCI_CLASS_SIZE]; /* unit class */ +} __attribute__ ((packed)) ng_hci_read_unit_class_rp; + +#define NG_HCI_OCF_WRITE_UNIT_CLASS 0x0024 +typedef struct { + u_int8_t uclass[NG_HCI_CLASS_SIZE]; /* unit class */ +} __attribute__ ((packed)) ng_hci_write_unit_class_cp; + +typedef ng_hci_status_rp ng_hci_write_unit_class_rp; + +#define NG_HCI_OCF_READ_VOICE_SETTINGS 0x0025 +/* No command parameter(s) */ +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int16_t settings; /* voice settings */ +} __attribute__ ((packed)) ng_hci_read_voice_settings_rp; + +#define NG_HCI_OCF_WRITE_VOICE_SETTINGS 0x0026 +typedef struct { + u_int16_t settings; /* voice settings */ +} __attribute__ ((packed)) ng_hci_write_voice_settings_cp; + +typedef ng_hci_status_rp ng_hci_write_voice_settings_rp; + +#define NG_HCI_OCF_READ_AUTO_FLUSH_TIMO 0x0027 +typedef struct { + u_int16_t con_handle; /* connection handle */ +} __attribute__ ((packed)) ng_hci_read_auto_flush_timo_cp; + +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int16_t con_handle; /* connection handle */ + u_int16_t timeout; /* 0x00 - no flush, timeout * 0.625 msec */ +} __attribute__ ((packed)) ng_hci_read_auto_flush_timo_rp; + +#define NG_HCI_OCF_WRITE_AUTO_FLUSH_TIMO 0x0028 +typedef struct { + u_int16_t con_handle; /* connection handle */ + u_int16_t timeout; /* 0x00 - no flush, timeout * 0.625 msec */ +} __attribute__ ((packed)) ng_hci_write_auto_flush_timo_cp; + +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int16_t con_handle; /* connection handle */ +} __attribute__ ((packed)) ng_hci_write_auto_flush_timo_rp; + +#define NG_HCI_OCF_READ_NUM_BROADCAST_RETRANS 0x0029 +/* No command parameter(s) */ +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int8_t counter; /* number of broadcast retransmissions */ +} __attribute__ ((packed)) ng_hci_read_num_broadcast_retrans_rp; + +#define NG_HCI_OCF_WRITE_NUM_BROADCAST_RETRANS 0x002a +typedef struct { + u_int8_t counter; /* number of broadcast retransmissions */ +} __attribute__ ((packed)) ng_hci_write_num_broadcast_retrans_cp; + +typedef ng_hci_status_rp ng_hci_write_num_broadcast_retrans_rp; + +#define NG_HCI_OCF_READ_HOLD_MODE_ACTIVITY 0x002b +/* No command parameter(s) */ +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int8_t hold_mode_activity; /* Hold mode activities */ +} __attribute__ ((packed)) ng_hci_read_hold_mode_activity_rp; + +#define NG_HCI_OCF_WRITE_HOLD_MODE_ACTIVITY 0x002c +typedef struct { + u_int8_t hold_mode_activity; /* Hold mode activities */ +} __attribute__ ((packed)) ng_hci_write_hold_mode_activity_cp; + +typedef ng_hci_status_rp ng_hci_write_hold_mode_activity_rp; + +#define NG_HCI_OCF_READ_XMIT_LEVEL 0x002d +typedef struct { + u_int16_t con_handle; /* connection handle */ + u_int8_t type; /* Xmit level type */ +} __attribute__ ((packed)) ng_hci_read_xmit_level_cp; + +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int16_t con_handle; /* connection handle */ + char level; /* -30 <= level <= 30 dBm */ +} __attribute__ ((packed)) ng_hci_read_xmit_level_rp; + +#define NG_HCI_OCF_READ_SCO_FLOW_CONTROL 0x002e +/* No command parameter(s) */ +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int8_t flow_control; /* 0x00 - disabled */ +} __attribute__ ((packed)) ng_hci_read_sco_flow_control_rp; + +#define NG_HCI_OCF_WRITE_SCO_FLOW_CONTROL 0x002f +typedef struct { + u_int8_t flow_control; /* 0x00 - disabled */ +} __attribute__ ((packed)) ng_hci_write_sco_flow_control_cp; + +typedef ng_hci_status_rp ng_hci_write_sco_flow_control_rp; + +#define NG_HCI_OCF_H2HC_FLOW_CONTROL 0x0031 +typedef struct { + u_int8_t h2hc_flow; /* Host to Host controller flow control */ +} __attribute__ ((packed)) ng_hci_h2hc_flow_control_cp; + +typedef ng_hci_status_rp ng_hci_h2hc_flow_control_rp; + +#define NG_HCI_OCF_HOST_BUFFER_SIZE 0x0033 +typedef struct { + u_int16_t max_acl_size; /* Max. size of ACL packet (bytes) */ + u_int8_t max_sco_size; /* Max. size of SCO packet (bytes) */ + u_int16_t num_acl_pkt; /* Max. number of ACL packets */ + u_int16_t num_sco_pkt; /* Max. number of SCO packets */ +} __attribute__ ((packed)) ng_hci_host_buffer_size_cp; + +typedef ng_hci_status_rp ng_hci_host_buffer_size_rp; + +#define NG_HCI_OCF_HOST_NUM_COMPL_PKTS 0x0035 +typedef struct { + u_int8_t num_con_handles; /* # of connection handles */ +/* these are repeated "num_con_handles" times + u_int16_t con_handle; --- connection handle(s) + u_int16_t compl_pkt; --- # of completed packets */ +} __attribute__ ((packed)) ng_hci_host_num_compl_pkts_cp; +/* No return parameter(s) */ + +#define NG_HCI_OCF_READ_LINK_SUPERVISION_TIMO 0x0036 +typedef struct { + u_int16_t con_handle; /* connection handle */ +} __attribute__ ((packed)) ng_hci_read_link_supervision_timo_cp; + +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int16_t con_handle; /* connection handle */ + u_int16_t timeout; /* Link supervision timeout * 0.625 msec */ +} __attribute__ ((packed)) ng_hci_read_link_supervision_timo_rp; + +#define NG_HCI_OCF_WRITE_LINK_SUPERVISION_TIMO 0x0037 +typedef struct { + u_int16_t con_handle; /* connection handle */ + u_int16_t timeout; /* Link supervision timeout * 0.625 msec */ +} __attribute__ ((packed)) ng_hci_write_link_supervision_timo_cp; + +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int16_t con_handle; /* connection handle */ +} __attribute__ ((packed)) ng_hci_write_link_supervision_timo_rp; + +#define NG_HCI_OCF_READ_SUPPORTED_IAC_NUM 0x0038 +/* No command parameter(s) */ +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int8_t num_iac; /* # of supported IAC during scan */ +} __attribute__ ((packed)) ng_hci_read_supported_iac_num_rp; + +#define NG_HCI_OCF_READ_IAC_LAP 0x0039 +/* No command parameter(s) */ +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int8_t num_iac; /* # of IAC */ +/* these are repeated "num_iac" times + u_int8_t laps[NG_HCI_LAP_SIZE]; --- LAPs */ +} __attribute__ ((packed)) ng_hci_read_iac_lap_rp; + +#define NG_HCI_OCF_WRITE_IAC_LAP 0x003a +typedef struct { + u_int8_t num_iac; /* # of IAC */ +/* these are repeated "num_iac" times + u_int8_t laps[NG_HCI_LAP_SIZE]; --- LAPs */ +} __attribute__ ((packed)) ng_hci_write_iac_lap_cp; + +typedef ng_hci_status_rp ng_hci_write_iac_lap_rp; + +#define NG_HCI_OCF_READ_PAGE_SCAN_PERIOD 0x003b +/* No command parameter(s) */ +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int8_t page_scan_period_mode; /* Page scan period mode */ +} __attribute__ ((packed)) ng_hci_read_page_scan_period_rp; + +#define NG_HCI_OCF_WRITE_PAGE_SCAN_PERIOD 0x003c +typedef struct { + u_int8_t page_scan_period_mode; /* Page scan period mode */ +} __attribute__ ((packed)) ng_hci_write_page_scan_period_cp; + +typedef ng_hci_status_rp ng_hci_write_page_scan_period_rp; + +#define NG_HCI_OCF_READ_PAGE_SCAN 0x003d +/* No command parameter(s) */ +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int8_t page_scan_mode; /* Page scan mode */ +} __attribute__ ((packed)) ng_hci_read_page_scan_rp; + +#define NG_HCI_OCF_WRITE_PAGE_SCAN 0x003e +typedef struct { + u_int8_t page_scan_mode; /* Page scan mode */ +} __attribute__ ((packed)) ng_hci_write_page_scan_cp; + +typedef ng_hci_status_rp ng_hci_write_page_scan_rp; + +/************************************************************************** + ************************************************************************** + ** Informational commands and return parameters + ** All commands in this category do not accept any parameters + ************************************************************************** + **************************************************************************/ + +#define NG_HCI_OGF_INFO 0x04 /* OpCode Group Field */ + +#define NG_HCI_OCF_READ_LOCAL_VER 0x0001 +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int8_t hci_version; /* HCI version */ + u_int16_t hci_revision; /* HCI revision */ + u_int8_t lmp_version; /* LMP version */ + u_int16_t manufacturer; /* Hardware manufacturer name */ + u_int16_t lmp_subversion; /* LMP sub-version */ +} __attribute__ ((packed)) ng_hci_read_local_ver_rp; + +#define NG_HCI_OCF_READ_LOCAL_FEATURES 0x0003 +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int8_t features[NG_HCI_FEATURES_SIZE]; /* LMP features bitmsk*/ +} __attribute__ ((packed)) ng_hci_read_local_features_rp; + +#define NG_HCI_OCF_READ_BUFFER_SIZE 0x0005 +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int16_t max_acl_size; /* Max. size of ACL packet (bytes) */ + u_int8_t max_sco_size; /* Max. size of SCO packet (bytes) */ + u_int16_t num_acl_pkt; /* Max. number of ACL packets */ + u_int16_t num_sco_pkt; /* Max. number of SCO packets */ +} __attribute__ ((packed)) ng_hci_read_buffer_size_rp; + +#define NG_HCI_OCF_READ_COUNTRY_CODE 0x0007 +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int8_t country_code; /* 0x00 - NAM, EUR, JP; 0x01 - France */ +} __attribute__ ((packed)) ng_hci_read_country_code_rp; + +#define NG_HCI_OCF_READ_BDADDR 0x0009 +typedef struct { + u_int8_t status; /* 0x00 - success */ + bdaddr_t bdaddr; /* unit address */ +} __attribute__ ((packed)) ng_hci_read_bdaddr_rp; + +/************************************************************************** + ************************************************************************** + ** Status commands and return parameters + ************************************************************************** + **************************************************************************/ + +#define NG_HCI_OGF_STATUS 0x05 /* OpCode Group Field */ + +#define NG_HCI_OCF_READ_FAILED_CONTACT_CNTR 0x0001 +typedef struct { + u_int16_t con_handle; /* connection handle */ +} __attribute__ ((packed)) ng_hci_read_failed_contact_cntr_cp; + +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int16_t con_handle; /* connection handle */ + u_int16_t counter; /* number of consecutive failed contacts */ +} __attribute__ ((packed)) ng_hci_read_failed_contact_cntr_rp; + +#define NG_HCI_OCF_RESET_FAILED_CONTACT_CNTR 0x0002 +typedef struct { + u_int16_t con_handle; /* connection handle */ +} __attribute__ ((packed)) ng_hci_reset_failed_contact_cntr_cp; + +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int16_t con_handle; /* connection handle */ +} __attribute__ ((packed)) ng_hci_reset_failed_contact_cntr_rp; + +#define NG_HCI_OCF_GET_LINK_QUALITY 0x0003 +typedef struct { + u_int16_t con_handle; /* connection handle */ +} __attribute__ ((packed)) ng_hci_get_link_quality_cp; + +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int16_t con_handle; /* connection handle */ + u_int8_t quality; /* higher value means better quality */ +} __attribute__ ((packed)) ng_hci_get_link_quality_rp; + +#define NG_HCI_OCF_READ_RSSI 0x0005 +typedef struct { + u_int16_t con_handle; /* connection handle */ +} __attribute__ ((packed)) ng_hci_read_rssi_cp; + +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int16_t con_handle; /* connection handle */ + char rssi; /* -127 <= rssi <= 127 dB */ +} __attribute__ ((packed)) ng_hci_read_rssi_rp; + +/************************************************************************** + ************************************************************************** + ** Testing commands and return parameters + ************************************************************************** + **************************************************************************/ + +#define NG_HCI_OGF_TESTING 0x06 /* OpCode Group Field */ + +#define NG_HCI_OCF_READ_LOOPBACK_MODE 0x0001 +/* No command parameter(s) */ +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int8_t lbmode; /* loopback mode */ +} __attribute__ ((packed)) ng_hci_read_loopback_mode_rp; + +#define NG_HCI_OCF_WRITE_LOOPBACK_MODE 0x0002 +typedef struct { + u_int8_t lbmode; /* loopback mode */ +} __attribute__ ((packed)) ng_hci_write_loopback_mode_cp; + +typedef ng_hci_status_rp ng_hci_write_loopback_mode_rp; + +#define NG_HCI_OCF_ENABLE_UNIT_UNDER_TEST 0x0003 +/* No command parameter(s) */ +typedef ng_hci_status_rp ng_hci_enable_unit_under_test_rp; + +/************************************************************************** + ************************************************************************** + ** Special HCI OpCode group field values + ************************************************************************** + **************************************************************************/ + +#define NG_HCI_OGF_BT_LOGO 0x3e + +#define NG_HCI_OGF_VENDOR 0x3f + +/************************************************************************** + ************************************************************************** + ** Events and event parameters + ************************************************************************** + **************************************************************************/ + +#define NG_HCI_EVENT_INQUIRY_COMPL 0x01 +typedef struct { + u_int8_t status; /* 0x00 - success */ +} __attribute__ ((packed)) ng_hci_inquiry_compl_ep; + +#define NG_HCI_EVENT_INQUIRY_RESULT 0x02 +typedef struct { + u_int8_t num_responses; /* number of responses */ +/* ng_hci_inquiry_response[num_responses] -- see below */ +} __attribute__ ((packed)) ng_hci_inquiry_result_ep; + +typedef struct { + bdaddr_t bdaddr; /* unit address */ + u_int8_t page_scan_rep_mode; /* page scan rep. mode */ + u_int8_t page_scan_period_mode; /* page scan period mode */ + u_int8_t page_scan_mode; /* page scan mode */ + u_int8_t class[NG_HCI_CLASS_SIZE]; /* unit class */ + u_int16_t clock_offset; /* clock offset */ +} __attribute__ ((packed)) ng_hci_inquiry_response; + +#define NG_HCI_EVENT_CON_COMPL 0x03 +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int16_t con_handle; /* Connection handle */ + bdaddr_t bdaddr; /* remote unit address */ + u_int8_t link_type; /* Link type */ + u_int8_t encryption_mode; /* Encryption mode */ +} __attribute__ ((packed)) ng_hci_con_compl_ep; + +#define NG_HCI_EVENT_CON_REQ 0x04 +typedef struct { + bdaddr_t bdaddr; /* remote unit address */ + u_int8_t uclass[NG_HCI_CLASS_SIZE]; /* remote unit class */ + u_int8_t link_type; /* link type */ +} __attribute__ ((packed)) ng_hci_con_req_ep; + +#define NG_HCI_EVENT_DISCON_COMPL 0x05 +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int16_t con_handle; /* connection handle */ + u_int8_t reason; /* reason to disconnect */ +} __attribute__ ((packed)) ng_hci_discon_compl_ep; + +#define NG_HCI_EVENT_AUTH_COMPL 0x06 +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int16_t con_handle; /* connection handle */ +} __attribute__ ((packed)) ng_hci_auth_compl_ep; + +#define NG_HCI_EVENT_REMOTE_NAME_REQ_COMPL 0x7 +typedef struct { + u_int8_t status; /* 0x00 - success */ + bdaddr_t bdaddr; /* remote unit address */ + char name[NG_HCI_UNIT_NAME_SIZE]; /* remote unit name */ +} __attribute__ ((packed)) ng_hci_remote_name_req_compl_ep; + +#define NG_HCI_EVENT_ENCRYPTION_CHANGE 0x08 +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int16_t con_handle; /* Connection handle */ + u_int8_t encryption_enable; /* 0x00 - disable */ +} __attribute__ ((packed)) ng_hci_encryption_change_ep; + +#define NG_HCI_EVENT_CHANGE_CON_LINK_KEY_COMPL 0x09 +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int16_t con_handle; /* Connection handle */ +} __attribute__ ((packed)) ng_hci_change_con_link_key_compl_ep; + +#define NG_HCI_EVENT_MASTER_LINK_KEY_COMPL 0x0a +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int16_t con_handle; /* Connection handle */ + u_int8_t key_flag; /* Key flag */ +} __attribute__ ((packed)) ng_hci_master_link_key_compl_ep; + +#define NG_HCI_EVENT_READ_REMOTE_FEATURES_COMPL 0x0b +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int16_t con_handle; /* Connection handle */ + u_int8_t features[NG_HCI_FEATURES_SIZE]; /* LMP features bitmsk*/ +} __attribute__ ((packed)) ng_hci_read_remote_features_compl_ep; + +#define NG_HCI_EVENT_READ_REMOTE_VER_INFO_COMPL 0x0c +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int16_t con_handle; /* Connection handle */ + u_int8_t lmp_version; /* LMP version */ + u_int16_t manufacturer; /* Hardware manufacturer name */ + u_int16_t lmp_subversion; /* LMP sub-version */ +} __attribute__ ((packed)) ng_hci_read_remote_ver_info_compl_ep; + +#define NG_HCI_EVENT_QOS_SETUP_COMPL 0x0d +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int16_t con_handle; /* connection handle */ + u_int8_t flags; /* reserved for future use */ + u_int8_t service_type; /* service type */ + u_int32_t token_rate; /* bytes per second */ + u_int32_t peak_bandwidth; /* bytes per second */ + u_int32_t latency; /* microseconds */ + u_int32_t delay_variation; /* microseconds */ +} __attribute__ ((packed)) ng_hci_qos_setup_compl_ep; + +#define NG_HCI_EVENT_COMMAND_COMPL 0x0e +typedef struct { + u_int8_t num_cmd_pkts; /* # of HCI command packets */ + u_int16_t opcode; /* command OpCode */ + /* command return parameters (if any) */ +} __attribute__ ((packed)) ng_hci_command_compl_ep; + +#define NG_HCI_EVENT_COMMAND_STATUS 0x0f +typedef struct { + u_int8_t status; /* 0x00 - pending */ + u_int8_t num_cmd_pkts; /* # of HCI command packets */ + u_int16_t opcode; /* command OpCode */ +} __attribute__ ((packed)) ng_hci_command_status_ep; + +#define NG_HCI_EVENT_HARDWARE_ERROR 0x10 +typedef struct { + u_int8_t hardware_code; /* hardware error code */ +} __attribute__ ((packed)) ng_hci_hardware_error_ep; + +#define NG_HCI_EVENT_FLUSH_OCCUR 0x11 +typedef struct { + u_int16_t con_handle; /* connection handle */ +} __attribute__ ((packed)) ng_hci_flush_occur_ep; + +#define NG_HCI_EVENT_ROLE_CHANGE 0x12 +typedef struct { + u_int8_t status; /* 0x00 - success */ + bdaddr_t bdaddr; /* address of remote unit */ + u_int8_t role; /* new connection role */ +} __attribute__ ((packed)) ng_hci_role_change_ep; + +#define NG_HCI_EVENT_NUM_COMPL_PKTS 0x13 +typedef struct { + u_int8_t num_con_handles; /* # of connection handles */ +/* these are repeated "num_con_handles" times + u_int16_t con_handle; --- connection handle(s) + u_int16_t compl_pkt; --- # of completed packets */ +} __attribute__ ((packed)) ng_hci_num_compl_pkts_ep; + +#define NG_HCI_EVENT_MODE_CHANGE 0x14 +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int16_t con_handle; /* connection handle */ + u_int8_t unit_mode; /* remote unit mode */ + u_int16_t interval; /* interval * 0.625 msec */ +} __attribute__ ((packed)) ng_hci_mode_change_ep; + +#define NG_HCI_EVENT_RETURN_LINK_KEYS 0x15 +typedef struct { + u_int8_t num_keys; /* # of keys */ +/* these are repeated "num_keys" times + bdaddr_t bdaddr; --- remote address(es) + u_int8_t key[NG_HCI_KEY_SIZE]; --- key(s) */ +} __attribute__ ((packed)) ng_hci_return_link_keys_ep; + +#define NG_HCI_EVENT_PIN_CODE_REQ 0x16 +typedef struct { + bdaddr_t bdaddr; /* remote unit address */ +} __attribute__ ((packed)) ng_hci_pin_code_req_ep; + +#define NG_HCI_EVENT_LINK_KEY_REQ 0x17 +typedef struct { + bdaddr_t bdaddr; /* remote unit address */ +} __attribute__ ((packed)) ng_hci_link_key_req_ep; + +#define NG_HCI_EVENT_LINK_KEY_NOTIFICATION 0x18 +typedef struct { + bdaddr_t bdaddr; /* remote unit address */ + u_int8_t key[NG_HCI_KEY_SIZE]; /* link key */ + u_int8_t key_type; /* type of the key */ +} __attribute__ ((packed)) ng_hci_link_key_notification_ep; + +#define NG_HCI_EVENT_LOOPBACK_COMMAND 0x19 +typedef struct { + u_int8_t command[0]; /* Command packet */ +} __attribute__ ((packed)) ng_hci_loopback_command_ep; + +#define NG_HCI_EVENT_DATA_BUFFER_OVERFLOW 0x1a +typedef struct { + u_int8_t link_type; /* Link type */ +} __attribute__ ((packed)) ng_hci_data_buffer_overflow_ep; + +#define NG_HCI_EVENT_MAX_SLOT_CHANGE 0x1b +typedef struct { + u_int16_t con_handle; /* connection handle */ + u_int8_t lmp_max_slots; /* Max. # of slots allowed */ +} __attribute__ ((packed)) ng_hci_max_slot_change_ep; + +#define NG_HCI_EVENT_READ_CLOCK_OFFSET_COMPL 0x1c +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int16_t con_handle; /* Connection handle */ + u_int16_t clock_offset; /* Clock offset */ +} __attribute__ ((packed)) ng_hci_read_clock_offset_compl_ep; + +#define NG_HCI_EVENT_CON_PKT_TYPE_CHANGED 0x1d +typedef struct { + u_int8_t status; /* 0x00 - success */ + u_int16_t con_handle; /* connection handle */ + u_int16_t pkt_type; /* packet type */ +} __attribute__ ((packed)) ng_hci_con_pkt_type_changed_ep; + +#define NG_HCI_EVENT_QOS_VIOLATION 0x1e +typedef struct { + u_int16_t con_handle; /* connection handle */ +} __attribute__ ((packed)) ng_hci_qos_violation_ep; + +#define NG_HCI_EVENT_PAGE_SCAN_MODE_CHANGE 0x1f +typedef struct { + bdaddr_t bdaddr; /* destination address */ + u_int8_t page_scan_mode; /* page scan mode */ +} __attribute__ ((packed)) ng_hci_page_scan_mode_change_ep; + +#define NG_HCI_EVENT_PAGE_SCAN_REP_MODE_CHANGE 0x20 +typedef struct { + bdaddr_t bdaddr; /* destination address */ + u_int8_t page_scan_rep_mode; /* page scan repetition mode */ +} __attribute__ ((packed)) ng_hci_page_scan_rep_mode_change_ep; + +#define NG_HCI_EVENT_BT_LOGO 0xfe + +#define NG_HCI_EVENT_VENDOR 0xff + +#endif /* ndef _NETGRAPH_HCI_H_ */ diff --git a/sys/netbt/hci_raw.c b/sys/netbt/hci_raw.c new file mode 100644 index 00000000000..930606f5e69 --- /dev/null +++ b/sys/netbt/hci_raw.c @@ -0,0 +1,1748 @@ +/* $OpenBSD: hci_raw.c,v 1.1 2005/01/14 12:04:02 grange Exp $ */ + +/* + * ng_btsocket_hci_raw.c + * + * Copyright (c) 2001-2002 Maksim Yevmenkin <m_evmenkin@yahoo.com> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: hci_raw.c,v 1.1 2005/01/14 12:04:02 grange Exp $ + * $FreeBSD: src/sys/netgraph/bluetooth/socket/ng_btsocket_hci_raw.c,v 1.16 2004/10/18 22:19:42 rwatson Exp $ + */ + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/domain.h> +#include <sys/endian.h> +#include <sys/errno.h> +#include <sys/filedesc.h> +#include <sys/ioccom.h> +#include <sys/kernel.h> +#include <sys/lock.h> +#include <sys/malloc.h> +#include <sys/mbuf.h> +#include <sys/mutex.h> +#include <sys/protosw.h> +#include <sys/queue.h> +#include <sys/socket.h> +#include <sys/socketvar.h> +#include <sys/sysctl.h> + +#include <net/if.h> +#include <net/if_types.h> +#include <net/netisr.h> + +#include <netbt/bluetooth.h> +#include <netbt/hci.h> +#include <netbt/l2cap.h> +#include <netbt/bt.h> +#include <netbt/hci_var.h> + +#if 0 +/* Netgraph node methods */ +static ng_constructor_t ng_btsocket_hci_raw_node_constructor; +static ng_rcvmsg_t ng_btsocket_hci_raw_node_rcvmsg; +static ng_shutdown_t ng_btsocket_hci_raw_node_shutdown; +static ng_newhook_t ng_btsocket_hci_raw_node_newhook; +static ng_connect_t ng_btsocket_hci_raw_node_connect; +static ng_rcvdata_t ng_btsocket_hci_raw_node_rcvdata; +static ng_disconnect_t ng_btsocket_hci_raw_node_disconnect; +#endif + +void ng_btsocket_hci_raw_output(void *, int); +void ng_btsocket_hci_raw_savctl(ng_btsocket_hci_raw_pcb_p, + struct mbuf **, + struct mbuf *); +int ng_btsocket_hci_raw_filter(ng_btsocket_hci_raw_pcb_p, + struct mbuf *, int); + +int ng_btsocket_hci_raw_send_ngmsg(char *, int, void *, int); +int ng_btsocket_hci_raw_send_sync_ngmsg(ng_btsocket_hci_raw_pcb_p, char *, + int, void *, int); + +#define ng_btsocket_hci_raw_wakeup_input_task() \ + taskqueue_enqueue(taskqueue_swi_giant, &ng_btsocket_hci_raw_task) + +/* Security filter */ +struct ng_btsocket_hci_raw_sec_filter { + bitstr_t bit_decl(events, 0xff); + bitstr_t bit_decl(commands[0x3f], 0x3ff); +}; + +#if 0 +/* Netgraph type descriptor */ +static struct ng_type typestruct = { + .version = NG_ABI_VERSION, + .name = NG_BTSOCKET_HCI_RAW_NODE_TYPE, + .constructor = ng_btsocket_hci_raw_node_constructor, + .rcvmsg = ng_btsocket_hci_raw_node_rcvmsg, + .shutdown = ng_btsocket_hci_raw_node_shutdown, + .newhook = ng_btsocket_hci_raw_node_newhook, + .connect = ng_btsocket_hci_raw_node_connect, + .rcvdata = ng_btsocket_hci_raw_node_rcvdata, + .disconnect = ng_btsocket_hci_raw_node_disconnect, +}; +#endif + +/* Globals */ +extern int ifqmaxlen; +static u_int32_t ng_btsocket_hci_raw_debug_level; +static u_int32_t ng_btsocket_hci_raw_ioctl_timeout; +#if 0 +static node_p ng_btsocket_hci_raw_node; +#endif +static struct ng_bt_itemq ng_btsocket_hci_raw_queue; +#if 0 +static struct mtx ng_btsocket_hci_raw_queue_mtx; +static struct task ng_btsocket_hci_raw_task; +#endif +static LIST_HEAD(, ng_btsocket_hci_raw_pcb) ng_btsocket_hci_raw_sockets; +#if 0 +static struct mtx ng_btsocket_hci_raw_sockets_mtx; +#endif +static u_int32_t ng_btsocket_hci_raw_token; +#if 0 +static struct mtx ng_btsocket_hci_raw_token_mtx; +#endif +static struct ng_btsocket_hci_raw_sec_filter *ng_btsocket_hci_raw_sec_filter; + +extern struct ifqueue btintrq; + +/* Debug */ +#define NG_BTSOCKET_HCI_RAW_INFO \ + if (ng_btsocket_hci_raw_debug_level >= NG_BTSOCKET_INFO_LEVEL) \ + printf + +#define NG_BTSOCKET_HCI_RAW_WARN \ + if (ng_btsocket_hci_raw_debug_level >= NG_BTSOCKET_WARN_LEVEL) \ + printf + +#define NG_BTSOCKET_HCI_RAW_ERR \ + if (ng_btsocket_hci_raw_debug_level >= NG_BTSOCKET_ERR_LEVEL) \ + printf + +#define NG_BTSOCKET_HCI_RAW_ALERT \ + if (ng_btsocket_hci_raw_debug_level >= NG_BTSOCKET_ALERT_LEVEL) \ + printf + +#if 0 +/**************************************************************************** + **************************************************************************** + ** Netgraph specific + **************************************************************************** + ****************************************************************************/ + +/* + * Netgraph node constructor. Do not allow to create node of this type. + */ + +int +ng_btsocket_hci_raw_node_constructor(node_p node) +{ + return (EINVAL); +} /* ng_btsocket_hci_raw_node_constructor */ + +/* + * Netgraph node destructor. Just let old node go and create new fresh one. + */ + +int +ng_btsocket_hci_raw_node_shutdown(node_p node) +{ + int error = 0; + + NG_NODE_UNREF(node); + + error = ng_make_node_common(&typestruct, &ng_btsocket_hci_raw_node); + if (error != 0) { + NG_BTSOCKET_HCI_RAW_ALERT( +"%s: Could not create Netgraph node, error=%d\n", __func__, error); + + ng_btsocket_hci_raw_node = NULL; + + return (ENOMEM); + } + + error = ng_name_node(ng_btsocket_hci_raw_node, + NG_BTSOCKET_HCI_RAW_NODE_TYPE); + if (error != 0) { + NG_BTSOCKET_HCI_RAW_ALERT( +"%s: Could not name Netgraph node, error=%d\n", __func__, error); + + NG_NODE_UNREF(ng_btsocket_hci_raw_node); + ng_btsocket_hci_raw_node = NULL; + + return (EINVAL); + } + + return (0); +} /* ng_btsocket_hci_raw_node_shutdown */ + +/* + * Create new hook. Just say "yes" + */ + +int +ng_btsocket_hci_raw_node_newhook(node_p node, hook_p hook, char const *name) +{ + return (0); +} /* ng_btsocket_hci_raw_node_newhook */ + +/* + * Connect hook. Just say "yes" + */ + +int +ng_btsocket_hci_raw_node_connect(hook_p hook) +{ + return (0); +} /* ng_btsocket_hci_raw_node_connect */ + +/* + * Disconnect hook + */ + +int +ng_btsocket_hci_raw_node_disconnect(hook_p hook) +{ + return (0); +} /* ng_btsocket_hci_raw_node_disconnect */ + +/* + * Receive control message. + * Make sure it is a message from HCI node and it is a response. + * Enqueue item and schedule input task. + */ + +int +ng_btsocket_hci_raw_node_rcvmsg(node_p node, item_p item, hook_p lasthook) +{ + struct ng_mesg *msg = NGI_MSG(item); /* item still has message */ + int empty, error = 0; + + mtx_lock(&ng_btsocket_hci_raw_sockets_mtx); + empty = LIST_EMPTY(&ng_btsocket_hci_raw_sockets); + mtx_unlock(&ng_btsocket_hci_raw_sockets_mtx); + + if (empty) { + NG_FREE_ITEM(item); + return (0); + } + + if (msg != NULL && + msg->header.typecookie == NGM_HCI_COOKIE && + msg->header.flags & NGF_RESP) { + if (msg->header.token == 0) { + NG_FREE_ITEM(item); + return (0); + } + + mtx_lock(&ng_btsocket_hci_raw_queue_mtx); + if (NG_BT_ITEMQ_FULL(&ng_btsocket_hci_raw_queue)) { + NG_BTSOCKET_HCI_RAW_ERR( +"%s: Input queue is full\n", __func__); + + NG_BT_ITEMQ_DROP(&ng_btsocket_hci_raw_queue); + NG_FREE_ITEM(item); + error = ENOBUFS; + } else { + NG_BT_ITEMQ_ENQUEUE(&ng_btsocket_hci_raw_queue, item); + error = ng_btsocket_hci_raw_wakeup_input_task(); + } + mtx_unlock(&ng_btsocket_hci_raw_queue_mtx); + } else { + NG_FREE_ITEM(item); + error = EINVAL; + } + + return (error); +} /* ng_btsocket_hci_raw_node_rcvmsg */ +#endif + +/* + * Receive packet from the one of our hook. + * Prepend every packet with sockaddr_hci and record sender's node name. + * Enqueue item and schedule input task. + */ + +int +ng_btsocket_hci_raw_node_rcvdata(struct ifnet *ifp, struct mbuf *m) +{ + struct mbuf *nam = NULL; + int empty, error; + int s; + + mtx_lock(&ng_btsocket_hci_raw_sockets_mtx); + empty = LIST_EMPTY(&ng_btsocket_hci_raw_sockets); + mtx_unlock(&ng_btsocket_hci_raw_sockets_mtx); + + if (empty) { +#if 0 + NG_FREE_ITEM(item); +#endif + return (0); + } + + MGET(nam, M_DONTWAIT, MT_SONAME); + if (nam != NULL) { + struct sockaddr_hci *sa = mtod(nam, struct sockaddr_hci *); + + nam->m_len = sizeof(struct sockaddr_hci); + + sa->hci_len = sizeof(*sa); + sa->hci_family = AF_BLUETOOTH; +#if 0 + strlcpy(sa->hci_node, NG_PEER_NODE_NAME(hook), + sizeof(sa->hci_node)); +#endif + strlcpy(sa->hci_node, ifp->if_xname, sizeof(sa->hci_node)); + +#if 0 + NGI_GET_M(item, nam->m_next); + NGI_M(item) = nam; +#endif + nam->m_next = m; + + mtx_lock(&ng_btsocket_hci_raw_queue_mtx); + if (NG_BT_ITEMQ_FULL(&ng_btsocket_hci_raw_queue)) { + NG_BTSOCKET_HCI_RAW_ERR( +"%s: Input queue is full\n", __func__); + + NG_BT_ITEMQ_DROP(&ng_btsocket_hci_raw_queue); +#if 0 + NG_FREE_ITEM(item); +#endif + error = ENOBUFS; + } else { +#if 0 + NG_BT_ITEMQ_ENQUEUE(&ng_btsocket_hci_raw_queue, item); + error = ng_btsocket_hci_raw_wakeup_input_task(); +#endif + s = splimp(); + IF_INPUT_ENQUEUE(&btintrq, nam); + splx(s); + schednetisr(NETISR_BT); + } + mtx_unlock(&ng_btsocket_hci_raw_queue_mtx); + } else { + NG_BTSOCKET_HCI_RAW_ERR( +"%s: Failed to allocate address mbuf\n", __func__); + +#if 0 + NG_FREE_ITEM(item); +#endif + error = ENOBUFS; + } + + return (error); +} /* ng_btsocket_hci_raw_node_rcvdata */ + +/**************************************************************************** + **************************************************************************** + ** Sockets specific + **************************************************************************** + ****************************************************************************/ + +/* + * Get next token. We need token to avoid theoretical race where process + * submits ioctl() message then interrupts ioctl() and re-submits another + * ioctl() on the same socket *before* first ioctl() complete. + */ + +#if 0 +void +ng_btsocket_hci_raw_get_token(u_int32_t *token) +{ + mtx_lock(&ng_btsocket_hci_raw_token_mtx); + + if (++ ng_btsocket_hci_raw_token == 0) + ng_btsocket_hci_raw_token = 1; + + *token = ng_btsocket_hci_raw_token; + + mtx_unlock(&ng_btsocket_hci_raw_token_mtx); +} /* ng_btsocket_hci_raw_get_token */ +#endif + +/* + * Send Netgraph message to the node - do not expect reply + */ + +int +ng_btsocket_hci_raw_send_ngmsg(char *path, int cmd, void *arg, int arglen) +{ +#if 0 + struct ng_mesg *msg = NULL; + int error = 0; + + NG_MKMESSAGE(msg, NGM_HCI_COOKIE, cmd, arglen, M_NOWAIT); + if (msg == NULL) + return (ENOMEM); + + if (arg != NULL && arglen > 0) + bcopy(arg, msg->data, arglen); + + NG_SEND_MSG_PATH(error, ng_btsocket_hci_raw_node, msg, path, 0); + + return (error); +#endif + return (0); +} /* ng_btsocket_hci_raw_send_ngmsg */ + +/* + * Send Netgraph message to the node (no data) and wait for reply + */ + +int +ng_btsocket_hci_raw_send_sync_ngmsg(ng_btsocket_hci_raw_pcb_p pcb, char *path, + int cmd, void *rsp, int rsplen) +{ +#if 0 + struct ng_mesg *msg = NULL; + int error = 0; + + mtx_assert(&pcb->pcb_mtx, MA_OWNED); + + NG_MKMESSAGE(msg, NGM_HCI_COOKIE, cmd, 0, M_NOWAIT); + if (msg == NULL) + return (ENOMEM); + + ng_btsocket_hci_raw_get_token(&msg->header.token); + pcb->token = msg->header.token; + pcb->msg = NULL; + + NG_SEND_MSG_PATH(error, ng_btsocket_hci_raw_node, msg, path, 0); + if (error != 0) { + pcb->token = 0; + return (error); + } + + error = msleep(&pcb->msg, &pcb->pcb_mtx, PZERO|PCATCH, "hcictl", + ng_btsocket_hci_raw_ioctl_timeout * hz); + pcb->token = 0; + + if (error != 0) + return (error); + + if (pcb->msg != NULL && pcb->msg->header.cmd == cmd) + bcopy(pcb->msg->data, rsp, rsplen); + else + error = EINVAL; + + NG_FREE_MSG(pcb->msg); /* checks for != NULL */ +#endif + + return (0); +} /* ng_btsocket_hci_raw_send_sync_ngmsg */ + +/* + * Create control information for the packet + */ + +void +ng_btsocket_hci_raw_savctl(ng_btsocket_hci_raw_pcb_p pcb, struct mbuf **ctl, + struct mbuf *m) +{ + int dir; +#if 0 + struct timeval tv; +#endif + + mtx_assert(&pcb->pcb_mtx, MA_OWNED); + + if (pcb->flags & NG_BTSOCKET_HCI_RAW_DIRECTION) { + dir = (m->m_flags & M_PROTO1)? 1 : 0; + *ctl = sbcreatecontrol((caddr_t) &dir, sizeof(dir), + SCM_HCI_RAW_DIRECTION, SOL_HCI_RAW); + if (*ctl != NULL) + ctl = &((*ctl)->m_next); + } + +#if 0 + if (pcb->so->so_options & SO_TIMESTAMP) { + microtime(&tv); + *ctl = sbcreatecontrol((caddr_t) &tv, sizeof(tv), + SCM_TIMESTAMP, SOL_SOCKET); + if (*ctl != NULL) + ctl = &((*ctl)->m_next); + } +#endif +} /* ng_btsocket_hci_raw_savctl */ + +/* + * Raw HCI sockets data input routine + */ + +void +ng_btsocket_hci_raw_data_input(struct mbuf *nam) +{ + ng_btsocket_hci_raw_pcb_p pcb = NULL; + struct mbuf *m0 = NULL, *m = NULL; + struct sockaddr_hci *sa = NULL; + + m0 = nam->m_next; + nam->m_next = NULL; + + KASSERT((nam->m_type == MT_SONAME), + ("%s: m_type=%d\n", __func__, nam->m_type)); + KASSERT((m0->m_flags & M_PKTHDR), + ("%s: m_flags=%#x\n", __func__, m0->m_flags)); + + sa = mtod(nam, struct sockaddr_hci *); + + mtx_lock(&ng_btsocket_hci_raw_sockets_mtx); + + LIST_FOREACH(pcb, &ng_btsocket_hci_raw_sockets, next) { + + mtx_lock(&pcb->pcb_mtx); + + /* + * If socket was bound then check address and + * make sure it matches. + */ + + if (pcb->addr.hci_node[0] != 0 && + strcmp(sa->hci_node, pcb->addr.hci_node) != 0) + goto next; + + /* + * Check packet against filters + * XXX do we have to call m_pullup() here? + */ + +#if 0 + if (ng_btsocket_hci_raw_filter(pcb, m0, 1) != 0) + goto next; +#endif + + /* + * Make a copy of the packet, append to the socket's + * receive queue and wakeup socket. sbappendaddr() + * will check if socket has enough buffer space. + */ + +#if 0 + m = m_dup(m0, M_DONTWAIT); +#endif + m = m_copym2(m0, 0, M_COPYALL, M_DONTWAIT); + if (m != NULL) { + struct mbuf *ctl = NULL; + + ng_btsocket_hci_raw_savctl(pcb, &ctl, m); + + if (sbappendaddr(&pcb->so->so_rcv, + (struct sockaddr *) sa, m, ctl)) { + sorwakeup(pcb->so); + } else { + NG_BTSOCKET_HCI_RAW_INFO( +"%s: sbappendaddr() failed\n", __func__); + + NG_FREE_M(m); + NG_FREE_M(ctl); + } + } +next: + mtx_unlock(&pcb->pcb_mtx); + } + + mtx_unlock(&ng_btsocket_hci_raw_sockets_mtx); + + NG_FREE_M(nam); + NG_FREE_M(m0); +} /* ng_btsocket_hci_raw_data_input */ + +#if 0 +/* + * Raw HCI sockets message input routine + */ + +void +ng_btsocket_hci_raw_msg_input(struct ng_mesg *msg) +{ + ng_btsocket_hci_raw_pcb_p pcb = NULL; + + mtx_lock(&ng_btsocket_hci_raw_sockets_mtx); + + LIST_FOREACH(pcb, &ng_btsocket_hci_raw_sockets, next) { + mtx_lock(&pcb->pcb_mtx); + + if (msg->header.token == pcb->token) { + pcb->msg = msg; + wakeup(&pcb->msg); + + mtx_unlock(&pcb->pcb_mtx); + mtx_unlock(&ng_btsocket_hci_raw_sockets_mtx); + + return; + } + + mtx_unlock(&pcb->pcb_mtx); + } + + mtx_unlock(&ng_btsocket_hci_raw_sockets_mtx); + +#if 0 + NG_FREE_MSG(msg); /* checks for != NULL */ +#endif +} /* ng_btsocket_hci_raw_msg_input */ +#endif + +#if 0 +/* + * Raw HCI sockets input routines + */ + +void +ng_btsocket_hci_raw_input(void *context, int pending) +{ + item_p item = NULL; + + for (;;) { + mtx_lock(&ng_btsocket_hci_raw_queue_mtx); + NG_BT_ITEMQ_DEQUEUE(&ng_btsocket_hci_raw_queue, item); + mtx_unlock(&ng_btsocket_hci_raw_queue_mtx); + + if (item == NULL) + break; + + switch(item->el_flags & NGQF_TYPE) { + case NGQF_DATA: { + struct mbuf *m = NULL; + + NGI_GET_M(item, m); + ng_btsocket_hci_raw_data_input(m); + } break; + + case NGQF_MESG: { + struct ng_mesg *msg = NULL; + + NGI_GET_MSG(item, msg); + ng_btsocket_hci_raw_msg_input(msg); + } break; + + default: + KASSERT(0, +("%s: invalid item type=%ld\n", __func__, (item->el_flags & NGQF_TYPE))); + break; + } + + NG_FREE_ITEM(item); + } +} /* ng_btsocket_hci_raw_input */ +#endif + +/* + * Raw HCI sockets output routine + */ + +void +ng_btsocket_hci_raw_output(void *arg1, int arg2) +{ + struct mbuf *nam = (struct mbuf *) arg1, *m = NULL; + struct sockaddr_hci *sa = NULL; + struct ifnet *ifp; + int error; + int s; + + m = nam->m_next; + nam->m_next = NULL; + + KASSERT((nam->m_type == MT_SONAME), + ("%s: m_type=%d\n", __func__, nam->m_type)); + KASSERT((m->m_flags & M_PKTHDR), + ("%s: m_flags=%#x\n", __func__, m->m_flags)); + + sa = mtod(nam, struct sockaddr_hci *); + + /* + * Find downstream hook + * XXX For now access node hook list directly. Should be safe because + * we used ng_send_fn() and we should have exclusive lock on the node. + */ + +#if 0 + LIST_FOREACH(hook, &node->nd_hooks, hk_hooks) { + if (hook == NULL || NG_HOOK_NOT_VALID(hook) || + NG_NODE_NOT_VALID(NG_PEER_NODE(hook))) + continue; + + if (strcmp(sa->hci_node, NG_PEER_NODE_NAME(hook)) == 0) { + NG_SEND_DATA_ONLY(error, hook, m); /* sets m to NULL */ + break; + } + } +#endif + TAILQ_FOREACH(ifp, &ifnet, if_list) { + if (ifp->if_type != IFT_BLUETOOTH) + continue; + + if (strcmp(sa->hci_node, ifp->if_xname) == 0) { + s = splimp(); + IFQ_ENQUEUE(&ifp->if_snd, m, NULL, error); + if (error) { + splx(s); + return; + } + if ((ifp->if_flags & IFF_OACTIVE) == 0) + (*ifp->if_start)(ifp); + splx(s); + break; + } + } + + NG_FREE_M(nam); /* check for != NULL */ +#if 0 + NG_FREE_M(m); +#endif +} /* ng_btsocket_hci_raw_output */ + +/* + * Check frame against security and socket filters. + * d (direction bit) == 1 means incoming frame. + */ + +int +ng_btsocket_hci_raw_filter(ng_btsocket_hci_raw_pcb_p pcb, struct mbuf *m, int d) +{ + int type, event, opcode; + + mtx_assert(&pcb->pcb_mtx, MA_OWNED); + + switch ((type = *mtod(m, u_int8_t *))) { + case NG_HCI_CMD_PKT: + if (!(pcb->flags & NG_BTSOCKET_HCI_RAW_PRIVILEGED)) { + opcode = letoh16(mtod(m, ng_hci_cmd_pkt_t *)->opcode); + + if (!bit_test( +ng_btsocket_hci_raw_sec_filter->commands[NG_HCI_OGF(opcode) - 1], +NG_HCI_OCF(opcode) - 1)) + return (EPERM); + } + + if (d && !bit_test(pcb->filter.packet_mask, NG_HCI_CMD_PKT - 1)) + return (EPERM); + break; + + case NG_HCI_ACL_DATA_PKT: + case NG_HCI_SCO_DATA_PKT: + if (!(pcb->flags & NG_BTSOCKET_HCI_RAW_PRIVILEGED) || + !bit_test(pcb->filter.packet_mask, type - 1) || + !d) + return (EPERM); + break; + + case NG_HCI_EVENT_PKT: + if (!d) + return (EINVAL); + + event = mtod(m, ng_hci_event_pkt_t *)->event - 1; + + if (!(pcb->flags & NG_BTSOCKET_HCI_RAW_PRIVILEGED)) + if (!bit_test(ng_btsocket_hci_raw_sec_filter->events, event)) + return (EPERM); + + if (!bit_test(pcb->filter.event_mask, event)) + return (EPERM); + break; + + default: + return (EINVAL); + } + + return (0); +} /* ng_btsocket_hci_raw_filter */ + +/* + * Initialize everything + */ + +void +hci_raw_init(void) +{ + bitstr_t *f = NULL; +#if 0 + int error = 0; +#endif + +#if 0 + ng_btsocket_hci_raw_node = NULL; +#endif + ng_btsocket_hci_raw_debug_level = NG_BTSOCKET_WARN_LEVEL; + ng_btsocket_hci_raw_ioctl_timeout = 5; + +#if 0 + /* Register Netgraph node type */ + error = ng_newtype(&typestruct); + if (error != 0) { + NG_BTSOCKET_HCI_RAW_ALERT( +"%s: Could not register Netgraph node type, error=%d\n", __func__, error); + + return; + } + + /* Create Netgrapg node */ + error = ng_make_node_common(&typestruct, &ng_btsocket_hci_raw_node); + if (error != 0) { + NG_BTSOCKET_HCI_RAW_ALERT( +"%s: Could not create Netgraph node, error=%d\n", __func__, error); + + ng_btsocket_hci_raw_node = NULL; + + return; + } + + error = ng_name_node(ng_btsocket_hci_raw_node, + NG_BTSOCKET_HCI_RAW_NODE_TYPE); + if (error != 0) { + NG_BTSOCKET_HCI_RAW_ALERT( +"%s: Could not name Netgraph node, error=%d\n", __func__, error); + + NG_NODE_UNREF(ng_btsocket_hci_raw_node); + ng_btsocket_hci_raw_node = NULL; + + return; + } +#endif + + /* Create input queue */ + NG_BT_ITEMQ_INIT(&ng_btsocket_hci_raw_queue, ifqmaxlen); + mtx_init(&ng_btsocket_hci_raw_queue_mtx, + "btsocks_hci_raw_queue_mtx", NULL, MTX_DEF); +#if 0 + TASK_INIT(&ng_btsocket_hci_raw_task, 0, + ng_btsocket_hci_raw_input, NULL); +#endif + + /* Create list of sockets */ + LIST_INIT(&ng_btsocket_hci_raw_sockets); + mtx_init(&ng_btsocket_hci_raw_sockets_mtx, + "btsocks_hci_raw_sockets_mtx", NULL, MTX_DEF); + + /* Tokens */ + ng_btsocket_hci_raw_token = 0; + mtx_init(&ng_btsocket_hci_raw_token_mtx, + "btsocks_hci_raw_token_mtx", NULL, MTX_DEF); + + /* + * Security filter + * XXX never FREE()ed + */ + + ng_btsocket_hci_raw_sec_filter = NULL; + + MALLOC(ng_btsocket_hci_raw_sec_filter, + struct ng_btsocket_hci_raw_sec_filter *, + sizeof(struct ng_btsocket_hci_raw_sec_filter), + M_BLUETOOTH, M_NOWAIT); + if (ng_btsocket_hci_raw_sec_filter == NULL) { + printf("%s: Could not allocate security filter!\n", __func__); + return; + } + bzero(ng_btsocket_hci_raw_sec_filter, + sizeof(struct ng_btsocket_hci_raw_sec_filter)); + + /* + * XXX How paranoid can we get? + * + * Initialize security filter. If bit is set in the mask then + * unprivileged socket is allowed to send (receive) this command + * (event). + */ + + /* Enable all events */ + memset(&ng_btsocket_hci_raw_sec_filter->events, 0xff, + sizeof(ng_btsocket_hci_raw_sec_filter->events)/ + sizeof(ng_btsocket_hci_raw_sec_filter->events[0])); + + /* Disable some critical events */ + f = ng_btsocket_hci_raw_sec_filter->events; + bit_clear(f, NG_HCI_EVENT_RETURN_LINK_KEYS - 1); + bit_clear(f, NG_HCI_EVENT_LINK_KEY_NOTIFICATION - 1); + bit_clear(f, NG_HCI_EVENT_VENDOR - 1); + + /* Commands - Link control */ + f = ng_btsocket_hci_raw_sec_filter->commands[NG_HCI_OGF_LINK_CONTROL-1]; + bit_set(f, NG_HCI_OCF_INQUIRY - 1); + bit_set(f, NG_HCI_OCF_INQUIRY_CANCEL - 1); + bit_set(f, NG_HCI_OCF_PERIODIC_INQUIRY - 1); + bit_set(f, NG_HCI_OCF_EXIT_PERIODIC_INQUIRY - 1); + bit_set(f, NG_HCI_OCF_REMOTE_NAME_REQ - 1); + bit_set(f, NG_HCI_OCF_READ_REMOTE_FEATURES - 1); + bit_set(f, NG_HCI_OCF_READ_REMOTE_VER_INFO - 1); + bit_set(f, NG_HCI_OCF_READ_CLOCK_OFFSET - 1); + + /* Commands - Link policy */ + f = ng_btsocket_hci_raw_sec_filter->commands[NG_HCI_OGF_LINK_POLICY-1]; + bit_set(f, NG_HCI_OCF_ROLE_DISCOVERY - 1); + bit_set(f, NG_HCI_OCF_READ_LINK_POLICY_SETTINGS - 1); + + /* Commands - Host controller and baseband */ + f = ng_btsocket_hci_raw_sec_filter->commands[NG_HCI_OGF_HC_BASEBAND-1]; + bit_set(f, NG_HCI_OCF_READ_PIN_TYPE - 1); + bit_set(f, NG_HCI_OCF_READ_LOCAL_NAME - 1); + bit_set(f, NG_HCI_OCF_READ_CON_ACCEPT_TIMO - 1); + bit_set(f, NG_HCI_OCF_READ_PAGE_TIMO - 1); + bit_set(f, NG_HCI_OCF_READ_SCAN_ENABLE - 1); + bit_set(f, NG_HCI_OCF_READ_PAGE_SCAN_ACTIVITY - 1); + bit_set(f, NG_HCI_OCF_READ_INQUIRY_SCAN_ACTIVITY - 1); + bit_set(f, NG_HCI_OCF_READ_AUTH_ENABLE - 1); + bit_set(f, NG_HCI_OCF_READ_ENCRYPTION_MODE - 1); + bit_set(f, NG_HCI_OCF_READ_UNIT_CLASS - 1); + bit_set(f, NG_HCI_OCF_READ_VOICE_SETTINGS - 1); + bit_set(f, NG_HCI_OCF_READ_AUTO_FLUSH_TIMO - 1); + bit_set(f, NG_HCI_OCF_READ_NUM_BROADCAST_RETRANS - 1); + bit_set(f, NG_HCI_OCF_READ_HOLD_MODE_ACTIVITY - 1); + bit_set(f, NG_HCI_OCF_READ_XMIT_LEVEL - 1); + bit_set(f, NG_HCI_OCF_READ_SCO_FLOW_CONTROL - 1); + bit_set(f, NG_HCI_OCF_READ_LINK_SUPERVISION_TIMO - 1); + bit_set(f, NG_HCI_OCF_READ_SUPPORTED_IAC_NUM - 1); + bit_set(f, NG_HCI_OCF_READ_IAC_LAP - 1); + bit_set(f, NG_HCI_OCF_READ_PAGE_SCAN_PERIOD - 1); + bit_set(f, NG_HCI_OCF_READ_PAGE_SCAN - 1); + + /* Commands - Informational */ + f = ng_btsocket_hci_raw_sec_filter->commands[NG_HCI_OGF_INFO - 1]; + bit_set(f, NG_HCI_OCF_READ_LOCAL_VER - 1); + bit_set(f, NG_HCI_OCF_READ_LOCAL_FEATURES - 1); + bit_set(f, NG_HCI_OCF_READ_BUFFER_SIZE - 1); + bit_set(f, NG_HCI_OCF_READ_COUNTRY_CODE - 1); + bit_set(f, NG_HCI_OCF_READ_BDADDR - 1); + + /* Commands - Status */ + f = ng_btsocket_hci_raw_sec_filter->commands[NG_HCI_OGF_STATUS - 1]; + bit_set(f, NG_HCI_OCF_READ_FAILED_CONTACT_CNTR - 1); + bit_set(f, NG_HCI_OCF_GET_LINK_QUALITY - 1); + bit_set(f, NG_HCI_OCF_READ_RSSI - 1); + + /* Commands - Testing */ + f = ng_btsocket_hci_raw_sec_filter->commands[NG_HCI_OGF_TESTING - 1]; + bit_set(f, NG_HCI_OCF_READ_LOOPBACK_MODE - 1); +} /* ng_btsocket_hci_raw_init */ + +/* + * Abort connection on socket + */ + +int +ng_btsocket_hci_raw_abort(struct socket *so) +{ + return (ng_btsocket_hci_raw_detach(so)); +} /* ng_btsocket_hci_raw_abort */ + +/* + * Create new raw HCI socket + */ + +int +ng_btsocket_hci_raw_attach(struct socket *so, int proto, struct proc *p) +{ + ng_btsocket_hci_raw_pcb_p pcb = so2hci_raw_pcb(so); + int error = 0; + + if (pcb != NULL) + return (EISCONN); + +#if 0 + if (ng_btsocket_hci_raw_node == NULL) + return (EPROTONOSUPPORT); +#endif + if (proto != BLUETOOTH_PROTO_HCI) + return (EPROTONOSUPPORT); + if (so->so_type != SOCK_RAW) + return (ESOCKTNOSUPPORT); + + error = soreserve(so, NG_BTSOCKET_HCI_RAW_SENDSPACE, + NG_BTSOCKET_HCI_RAW_RECVSPACE); + if (error != 0) + return (error); + + MALLOC(pcb, ng_btsocket_hci_raw_pcb_p, sizeof(*pcb), + M_BLUETOOTH, M_NOWAIT); + if (pcb == NULL) + return (ENOMEM); + bzero(pcb, sizeof(*pcb)); + + so->so_pcb = (caddr_t) pcb; + pcb->so = so; + + if (suser(p, 0) == 0) + pcb->flags |= NG_BTSOCKET_HCI_RAW_PRIVILEGED; + + /* + * Set default socket filter. By default socket only accepts HCI + * Command_Complete and Command_Status event packets. + */ + + bit_set(pcb->filter.event_mask, NG_HCI_EVENT_COMMAND_COMPL - 1); + bit_set(pcb->filter.event_mask, NG_HCI_EVENT_COMMAND_STATUS - 1); + + mtx_init(&pcb->pcb_mtx, "btsocks_hci_raw_pcb_mtx", NULL, MTX_DEF); + + mtx_lock(&ng_btsocket_hci_raw_sockets_mtx); + LIST_INSERT_HEAD(&ng_btsocket_hci_raw_sockets, pcb, next); + mtx_unlock(&ng_btsocket_hci_raw_sockets_mtx); + + return (0); +} /* ng_btsocket_hci_raw_attach */ + +/* + * Bind raw HCI socket + */ + +int +ng_btsocket_hci_raw_bind(struct socket *so, struct sockaddr *nam, + struct proc *p) +{ + ng_btsocket_hci_raw_pcb_p pcb = so2hci_raw_pcb(so); + struct sockaddr_hci *sa = (struct sockaddr_hci *) nam; + + if (pcb == NULL) + return (EINVAL); +#if 0 + if (ng_btsocket_hci_raw_node == NULL) + return (EINVAL); +#endif + + if (sa == NULL) + return (EINVAL); + if (sa->hci_family != AF_BLUETOOTH) + return (EAFNOSUPPORT); + if (sa->hci_len != sizeof(*sa)) + return (EINVAL); + if (sa->hci_node[0] == 0) + return (EINVAL); + + bcopy(sa, &pcb->addr, sizeof(pcb->addr)); + + return (0); +} /* ng_btsocket_hci_raw_bind */ + +/* + * Connect raw HCI socket + */ + +int +ng_btsocket_hci_raw_connect(struct socket *so, struct sockaddr *nam, + struct proc *p) +{ + ng_btsocket_hci_raw_pcb_p pcb = so2hci_raw_pcb(so); + struct sockaddr_hci *sa = (struct sockaddr_hci *) nam; + + if (pcb == NULL) + return (EINVAL); +#if 0 + if (ng_btsocket_hci_raw_node == NULL) + return (EINVAL); +#endif + + if (sa == NULL) + return (EINVAL); + if (sa->hci_family != AF_BLUETOOTH) + return (EAFNOSUPPORT); + if (sa->hci_len != sizeof(*sa)) + return (EINVAL); + if (sa->hci_node[0] == 0) + return (EDESTADDRREQ); + if (bcmp(sa, &pcb->addr, sizeof(pcb->addr)) != 0) + return (EADDRNOTAVAIL); + + soisconnected(so); + + return (0); +} /* ng_btsocket_hci_raw_connect */ + +/* + * Process ioctl on socket + */ + +int +ng_btsocket_hci_raw_control(struct socket *so, u_long cmd, caddr_t data, + struct ifnet *ifp, struct proc *p) +{ + ng_btsocket_hci_raw_pcb_p pcb = so2hci_raw_pcb(so); + char path[256]; +#if 0 + struct ng_mesg *msg = NULL; +#endif + int error = 0; + + if (pcb == NULL) + return (EINVAL); +#if 0 + if (ng_btsocket_hci_raw_node == NULL) + return (EINVAL); +#endif + + mtx_lock(&pcb->pcb_mtx); + + /* Check if we have device name */ + if (pcb->addr.hci_node[0] == 0) { + mtx_unlock(&pcb->pcb_mtx); + return (EHOSTUNREACH); + } + + /* Check if we have pending ioctl() */ + if (pcb->token != 0) { + mtx_unlock(&pcb->pcb_mtx); + return (EBUSY); + } + + snprintf(path, sizeof(path), "%s:", pcb->addr.hci_node); + + switch (cmd) { + case SIOC_HCI_RAW_NODE_GET_STATE: { + struct ng_btsocket_hci_raw_node_state *p = + (struct ng_btsocket_hci_raw_node_state *) data; + + error = ng_btsocket_hci_raw_send_sync_ngmsg(pcb, path, + NGM_HCI_NODE_GET_STATE, + &p->state, sizeof(p->state)); + } break; + + case SIOC_HCI_RAW_NODE_INIT: + if (pcb->flags & NG_BTSOCKET_HCI_RAW_PRIVILEGED) + error = ng_btsocket_hci_raw_send_ngmsg(path, + NGM_HCI_NODE_INIT, NULL, 0); + else + error = EPERM; + break; + + case SIOC_HCI_RAW_NODE_GET_DEBUG: { + struct ng_btsocket_hci_raw_node_debug *p = + (struct ng_btsocket_hci_raw_node_debug *) data; + + error = ng_btsocket_hci_raw_send_sync_ngmsg(pcb, path, + NGM_HCI_NODE_GET_DEBUG, + &p->debug, sizeof(p->debug)); + } break; + + case SIOC_HCI_RAW_NODE_SET_DEBUG: { + struct ng_btsocket_hci_raw_node_debug *p = + (struct ng_btsocket_hci_raw_node_debug *) data; + + if (pcb->flags & NG_BTSOCKET_HCI_RAW_PRIVILEGED) + error = ng_btsocket_hci_raw_send_ngmsg(path, + NGM_HCI_NODE_SET_DEBUG, &p->debug, + sizeof(p->debug)); + else + error = EPERM; + } break; + + case SIOC_HCI_RAW_NODE_GET_BUFFER: { + struct ng_btsocket_hci_raw_node_buffer *p = + (struct ng_btsocket_hci_raw_node_buffer *) data; + + error = ng_btsocket_hci_raw_send_sync_ngmsg(pcb, path, + NGM_HCI_NODE_GET_BUFFER, + &p->buffer, sizeof(p->buffer)); + } break; + + case SIOC_HCI_RAW_NODE_GET_BDADDR: { + struct ng_btsocket_hci_raw_node_bdaddr *p = + (struct ng_btsocket_hci_raw_node_bdaddr *) data; + + error = ng_btsocket_hci_raw_send_sync_ngmsg(pcb, path, + NGM_HCI_NODE_GET_BDADDR, + &p->bdaddr, sizeof(p->bdaddr)); + } break; + + case SIOC_HCI_RAW_NODE_GET_FEATURES: { + struct ng_btsocket_hci_raw_node_features *p = + (struct ng_btsocket_hci_raw_node_features *) data; + + error = ng_btsocket_hci_raw_send_sync_ngmsg(pcb, path, + NGM_HCI_NODE_GET_FEATURES, + &p->features, sizeof(p->features)); + } break; + + case SIOC_HCI_RAW_NODE_GET_STAT: { + struct ng_btsocket_hci_raw_node_stat *p = + (struct ng_btsocket_hci_raw_node_stat *) data; + + error = ng_btsocket_hci_raw_send_sync_ngmsg(pcb, path, + NGM_HCI_NODE_GET_STAT, + &p->stat, sizeof(p->stat)); + } break; + + case SIOC_HCI_RAW_NODE_RESET_STAT: + if (pcb->flags & NG_BTSOCKET_HCI_RAW_PRIVILEGED) + error = ng_btsocket_hci_raw_send_ngmsg(path, + NGM_HCI_NODE_RESET_STAT, NULL, 0); + else + error = EPERM; + break; + + case SIOC_HCI_RAW_NODE_FLUSH_NEIGHBOR_CACHE: + if (pcb->flags & NG_BTSOCKET_HCI_RAW_PRIVILEGED) + error = ng_btsocket_hci_raw_send_ngmsg(path, + NGM_HCI_NODE_FLUSH_NEIGHBOR_CACHE, + NULL, 0); + else + error = EPERM; + break; + + case SIOC_HCI_RAW_NODE_GET_NEIGHBOR_CACHE: { + struct ng_btsocket_hci_raw_node_neighbor_cache *p = + (struct ng_btsocket_hci_raw_node_neighbor_cache *) data; +#if 0 + ng_hci_node_get_neighbor_cache_ep *p1 = NULL; + ng_hci_node_neighbor_cache_entry_ep *p2 = NULL; +#endif + + if (p->num_entries <= 0 || + p->num_entries > NG_HCI_MAX_NEIGHBOR_NUM || + p->entries == NULL) { + error = EINVAL; + break; + } + +#if 0 + NG_MKMESSAGE(msg, NGM_HCI_COOKIE, + NGM_HCI_NODE_GET_NEIGHBOR_CACHE, 0, M_NOWAIT); + if (msg == NULL) { + error = ENOMEM; + break; + } + ng_btsocket_hci_raw_get_token(&msg->header.token); + pcb->token = msg->header.token; + pcb->msg = NULL; + + NG_SEND_MSG_PATH(error, ng_btsocket_hci_raw_node, msg, path, 0); + if (error != 0) { + pcb->token = 0; + break; + } +#endif + + error = tsleep(&pcb->msg, + PZERO|PCATCH, "hcictl", + ng_btsocket_hci_raw_ioctl_timeout * hz); + pcb->token = 0; + + if (error != 0) + break; + +#if 0 + if (pcb->msg != NULL && + pcb->msg->header.cmd == NGM_HCI_NODE_GET_NEIGHBOR_CACHE) { + /* Return data back to user space */ + p1 = (ng_hci_node_get_neighbor_cache_ep *) + (pcb->msg->data); + p2 = (ng_hci_node_neighbor_cache_entry_ep *) + (p1 + 1); + + p->num_entries = min(p->num_entries, p1->num_entries); + if (p->num_entries > 0) + error = copyout((caddr_t) p2, + (caddr_t) p->entries, + p->num_entries * sizeof(*p2)); + } else + error = EINVAL; +#endif + +#if 0 + NG_FREE_MSG(pcb->msg); /* checks for != NULL */ +#endif + }break; + + case SIOC_HCI_RAW_NODE_GET_CON_LIST: { + struct ng_btsocket_hci_raw_con_list *p = + (struct ng_btsocket_hci_raw_con_list *) data; +#if 0 + ng_hci_node_con_list_ep *p1 = NULL; + ng_hci_node_con_ep *p2 = NULL; +#endif + + if (p->num_connections == 0 || + p->num_connections > NG_HCI_MAX_CON_NUM || + p->connections == NULL) { + error = EINVAL; + break; + } + +#if 0 + NG_MKMESSAGE(msg, NGM_HCI_COOKIE, NGM_HCI_NODE_GET_CON_LIST, + 0, M_NOWAIT); + if (msg == NULL) { + error = ENOMEM; + break; + } + ng_btsocket_hci_raw_get_token(&msg->header.token); + pcb->token = msg->header.token; + pcb->msg = NULL; + + NG_SEND_MSG_PATH(error, ng_btsocket_hci_raw_node, msg, path, 0); + if (error != 0) { + pcb->token = 0; + break; + } +#endif + + error = tsleep(&pcb->msg, + PZERO|PCATCH, "hcictl", + ng_btsocket_hci_raw_ioctl_timeout * hz); + pcb->token = 0; + + if (error != 0) + break; + +#if 0 + if (pcb->msg != NULL && + pcb->msg->header.cmd == NGM_HCI_NODE_GET_CON_LIST) { + /* Return data back to user space */ + p1 = (ng_hci_node_con_list_ep *)(pcb->msg->data); + p2 = (ng_hci_node_con_ep *)(p1 + 1); + + p->num_connections = min(p->num_connections, + p1->num_connections); + if (p->num_connections > 0) + error = copyout((caddr_t) p2, + (caddr_t) p->connections, + p->num_connections * sizeof(*p2)); + } else + error = EINVAL; +#endif + +#if 0 + NG_FREE_MSG(pcb->msg); /* checks for != NULL */ +#endif + } break; + + case SIOC_HCI_RAW_NODE_GET_LINK_POLICY_MASK: { + struct ng_btsocket_hci_raw_node_link_policy_mask *p = + (struct ng_btsocket_hci_raw_node_link_policy_mask *) + data; + + error = ng_btsocket_hci_raw_send_sync_ngmsg(pcb, path, + NGM_HCI_NODE_GET_LINK_POLICY_SETTINGS_MASK, + &p->policy_mask, sizeof(p->policy_mask)); + } break; + + case SIOC_HCI_RAW_NODE_SET_LINK_POLICY_MASK: { + struct ng_btsocket_hci_raw_node_link_policy_mask *p = + (struct ng_btsocket_hci_raw_node_link_policy_mask *) + data; + + if (pcb->flags & NG_BTSOCKET_HCI_RAW_PRIVILEGED) + error = ng_btsocket_hci_raw_send_ngmsg(path, + NGM_HCI_NODE_SET_LINK_POLICY_SETTINGS_MASK, + &p->policy_mask, + sizeof(p->policy_mask)); + else + error = EPERM; + } break; + + case SIOC_HCI_RAW_NODE_GET_PACKET_MASK: { + struct ng_btsocket_hci_raw_node_packet_mask *p = + (struct ng_btsocket_hci_raw_node_packet_mask *) data; + + error = ng_btsocket_hci_raw_send_sync_ngmsg(pcb, path, + NGM_HCI_NODE_GET_PACKET_MASK, + &p->packet_mask, sizeof(p->packet_mask)); + } break; + + case SIOC_HCI_RAW_NODE_SET_PACKET_MASK: { + struct ng_btsocket_hci_raw_node_packet_mask *p = + (struct ng_btsocket_hci_raw_node_packet_mask *) data; + + if (pcb->flags & NG_BTSOCKET_HCI_RAW_PRIVILEGED) + error = ng_btsocket_hci_raw_send_ngmsg(path, + NGM_HCI_NODE_SET_PACKET_MASK, + &p->packet_mask, + sizeof(p->packet_mask)); + else + error = EPERM; + } break; + + case SIOC_HCI_RAW_NODE_GET_ROLE_SWITCH: { + struct ng_btsocket_hci_raw_node_role_switch *p = + (struct ng_btsocket_hci_raw_node_role_switch *) data; + + error = ng_btsocket_hci_raw_send_sync_ngmsg(pcb, path, + NGM_HCI_NODE_GET_ROLE_SWITCH, + &p->role_switch, sizeof(p->role_switch)); + } break; + + case SIOC_HCI_RAW_NODE_SET_ROLE_SWITCH: { + struct ng_btsocket_hci_raw_node_role_switch *p = + (struct ng_btsocket_hci_raw_node_role_switch *) data; + + if (pcb->flags & NG_BTSOCKET_HCI_RAW_PRIVILEGED) + error = ng_btsocket_hci_raw_send_ngmsg(path, + NGM_HCI_NODE_SET_ROLE_SWITCH, + &p->role_switch, + sizeof(p->role_switch)); + else + error = EPERM; + } break; + + default: + error = EINVAL; + break; + } + + mtx_unlock(&pcb->pcb_mtx); + + return (error); +} /* ng_btsocket_hci_raw_control */ + +/* + * Process getsockopt/setsockopt system calls + */ + +int +hci_raw_ctloutput(int op, struct socket *so, int level, + int optname, struct mbuf **m) +{ + ng_btsocket_hci_raw_pcb_p pcb = so2hci_raw_pcb(so); + struct ng_btsocket_hci_raw_filter filter; + int error = 0, dir; + size_t len; + + if (pcb == NULL) + return (EINVAL); +#if 0 + if (ng_btsocket_hci_raw_node == NULL) + return (EINVAL); +#endif + + if (level != SOL_HCI_RAW) + return (0); + + mtx_lock(&pcb->pcb_mtx); + + switch (op) { + case PRCO_GETOPT: + switch (optname) { + case SO_HCI_RAW_FILTER: + len = min((*m)->m_len, sizeof(pcb->filter)); + bcopy(&pcb->filter, mtod(*m, void *), len); + break; + + case SO_HCI_RAW_DIRECTION: + len = min((*m)->m_len, sizeof(dir)); + dir = (pcb->flags & NG_BTSOCKET_HCI_RAW_DIRECTION)?1:0; + bcopy(&dir, mtod(*m, void *), len); + break; + + default: + error = EINVAL; + break; + } + break; + + case PRCO_SETOPT: + switch (optname) { + case SO_HCI_RAW_FILTER: + len = min((*m)->m_len, sizeof(pcb->filter)); + bcopy(&filter, &pcb->filter, len); + break; + + case SO_HCI_RAW_DIRECTION: + len = min((*m)->m_len, sizeof(dir)); + bcopy(mtod(*m, void *), &dir, len); + + if (dir) + pcb->flags |= NG_BTSOCKET_HCI_RAW_DIRECTION; + else + pcb->flags &= ~NG_BTSOCKET_HCI_RAW_DIRECTION; + break; + + default: + error = EINVAL; + break; + } + break; + + default: + error = EINVAL; + break; + } + + mtx_unlock(&pcb->pcb_mtx); + + return (error); +} /* ng_btsocket_hci_raw_ctloutput */ + +/* + * Detach raw HCI socket + */ + +int +ng_btsocket_hci_raw_detach(struct socket *so) +{ + ng_btsocket_hci_raw_pcb_p pcb = so2hci_raw_pcb(so); + + if (pcb == NULL) + return (EINVAL); +#if 0 + if (ng_btsocket_hci_raw_node == NULL) + return (EINVAL); +#endif + + mtx_lock(&ng_btsocket_hci_raw_sockets_mtx); + mtx_lock(&pcb->pcb_mtx); + + LIST_REMOVE(pcb, next); + + mtx_unlock(&pcb->pcb_mtx); + mtx_unlock(&ng_btsocket_hci_raw_sockets_mtx); + + mtx_destroy(&pcb->pcb_mtx); + + bzero(pcb, sizeof(*pcb)); + FREE(pcb, M_BLUETOOTH); + + ACCEPT_LOCK(); + SOCK_LOCK(so); + so->so_pcb = NULL; + sofree(so); + + return (0); +} /* ng_btsocket_hci_raw_detach */ + +/* + * Disconnect raw HCI socket + */ + +int +ng_btsocket_hci_raw_disconnect(struct socket *so) +{ + ng_btsocket_hci_raw_pcb_p pcb = so2hci_raw_pcb(so); + + if (pcb == NULL) + return (EINVAL); +#if 0 + if (ng_btsocket_hci_raw_node == NULL) + return (EINVAL); +#endif + + soisdisconnected(so); + + return (0); +} /* ng_btsocket_hci_raw_disconnect */ + +/* + * Get socket peer's address + */ + +int +ng_btsocket_hci_raw_peeraddr(struct socket *so, struct sockaddr **nam) +{ + return (ng_btsocket_hci_raw_sockaddr(so, nam)); +} /* ng_btsocket_hci_raw_peeraddr */ + +/* + * Send data + */ + +int +ng_btsocket_hci_raw_send(struct socket *so, int flags, struct mbuf *m, + struct sockaddr *sa, struct mbuf *control, struct proc *p) +{ + ng_btsocket_hci_raw_pcb_p pcb = so2hci_raw_pcb(so); + struct mbuf *nam = NULL; + int error = 0; + +#if 0 + if (ng_btsocket_hci_raw_node == NULL) { + error = ENETDOWN; + goto drop; + } +#endif + if (pcb == NULL) { + error = EINVAL; + goto drop; + } + if (control != NULL) { + error = EINVAL; + goto drop; + } + + if (m->m_pkthdr.len < sizeof(ng_hci_cmd_pkt_t) || + m->m_pkthdr.len > sizeof(ng_hci_cmd_pkt_t) + NG_HCI_CMD_PKT_SIZE) { + error = EMSGSIZE; + goto drop; + } + + if (m->m_len < sizeof(ng_hci_cmd_pkt_t)) { + if ((m = m_pullup(m, sizeof(ng_hci_cmd_pkt_t))) == NULL) { + error = ENOBUFS; + goto drop; + } + } + if (*mtod(m, u_int8_t *) != NG_HCI_CMD_PKT) { + error = EOPNOTSUPP; + goto drop; + } + + mtx_lock(&pcb->pcb_mtx); + + error = ng_btsocket_hci_raw_filter(pcb, m, 0); + if (error != 0) { + mtx_unlock(&pcb->pcb_mtx); + goto drop; + } + + if (sa == NULL) { + if (pcb->addr.hci_node[0] == 0) { + mtx_unlock(&pcb->pcb_mtx); + error = EDESTADDRREQ; + goto drop; + } + + sa = (struct sockaddr *) &pcb->addr; + } + + MGET(nam, M_DONTWAIT, MT_SONAME); + if (nam == NULL) { + mtx_unlock(&pcb->pcb_mtx); + error = ENOBUFS; + goto drop; + } + + nam->m_len = sizeof(struct sockaddr_hci); + bcopy(sa,mtod(nam, struct sockaddr_hci *),sizeof(struct sockaddr_hci)); + + nam->m_next = m; + m = NULL; + + mtx_unlock(&pcb->pcb_mtx); + +#if 0 + return (ng_send_fn(ng_btsocket_hci_raw_node, NULL, + ng_btsocket_hci_raw_output, nam, 0)); +#endif + ng_btsocket_hci_raw_output(nam, 0); + return (0); + +drop: + NG_FREE_M(control); /* NG_FREE_M checks for != NULL */ + NG_FREE_M(nam); + NG_FREE_M(m); + + return (error); +} /* ng_btsocket_hci_raw_send */ + +/* + * Get socket address + */ + +int +ng_btsocket_hci_raw_sockaddr(struct socket *so, struct sockaddr **nam) +{ + ng_btsocket_hci_raw_pcb_p pcb = so2hci_raw_pcb(so); + struct sockaddr_hci sa; + + if (pcb == NULL) + return (EINVAL); +#if 0 + if (ng_btsocket_hci_raw_node == NULL) + return (EINVAL); +#endif + + bzero(&sa, sizeof(sa)); + sa.hci_len = sizeof(sa); + sa.hci_family = AF_BLUETOOTH; + strlcpy(sa.hci_node, pcb->addr.hci_node, sizeof(sa.hci_node)); + +#if 0 + *nam = sodupsockaddr((struct sockaddr *) &sa, M_NOWAIT); +#endif + + return ((*nam == NULL)? ENOMEM : 0); +} /* ng_btsocket_hci_raw_sockaddr */ + +int +hci_raw_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, + struct mbuf *control) +{ + ng_btsocket_hci_raw_pcb_p pcb = so2hci_raw_pcb(so); + struct sockaddr *sa; + int error = 0; + + if (req == PRU_CONTROL) + return (ng_btsocket_hci_raw_control(so, (u_long)m, + (caddr_t)nam, (struct ifnet *)control, curproc)); + + if (pcb == NULL && req != PRU_ATTACH) { + error = EINVAL; + goto release; + } + + switch (req) { + case PRU_ATTACH: + return (ng_btsocket_hci_raw_attach(so, + so->so_proto->pr_protocol, curproc)); + case PRU_DISCONNECT: + if ((so->so_state & SS_ISCONNECTED) == 0) { + error = ENOTCONN; + break; + } + /* FALLTHROUGH */ + case PRU_ABORT: + soisdisconnected(so); + /* FALLTHROUGH */ + case PRU_DETACH: + return (ng_btsocket_hci_raw_detach(so)); + case PRU_BIND: + sa = mtod(nam, struct sockaddr *); + return (ng_btsocket_hci_raw_bind(so, sa, curproc)); + case PRU_CONNECT: + sa = mtod(nam, struct sockaddr *); + return (ng_btsocket_hci_raw_connect(so, sa, curproc)); + case PRU_CONNECT2: + error = EOPNOTSUPP; + break; + case PRU_SHUTDOWN: + socantsendmore(so); + break; + case PRU_SEND: + sa = nam != NULL ? mtod(nam, struct sockaddr *) : NULL; + return (ng_btsocket_hci_raw_send(so, 0, m, sa, control, + curproc)); + case PRU_SENSE: + return (0); + case PRU_RCVOOB: + case PRU_RCVD: + case PRU_LISTEN: + case PRU_ACCEPT: + case PRU_SENDOOB: + error = EOPNOTSUPP; + break; + case PRU_SOCKADDR: + sa = mtod(nam, struct sockaddr *); + return (ng_btsocket_hci_raw_sockaddr(so, &sa)); + case PRU_PEERADDR: + sa = mtod(nam, struct sockaddr *); + return (ng_btsocket_hci_raw_peeraddr(so, &sa)); + default: + panic("hci_raw_usrreq: unexpected request %d", req); + } + +release: + if (m != NULL) + m_freem(m); + return (error); +} diff --git a/sys/netbt/hci_var.h b/sys/netbt/hci_var.h new file mode 100644 index 00000000000..bf5c6f494ab --- /dev/null +++ b/sys/netbt/hci_var.h @@ -0,0 +1,97 @@ +/* $OpenBSD: hci_var.h,v 1.1 2005/01/14 12:04:02 grange Exp $ */ + +/* + * ng_btsocket_hci_raw.h + * + * Copyright (c) 2001-2002 Maksim Yevmenkin <m_evmenkin@yahoo.com> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: hci_var.h,v 1.1 2005/01/14 12:04:02 grange Exp $ + * $FreeBSD: src/sys/netgraph/bluetooth/include/ng_btsocket_hci_raw.h,v 1.3 2003/11/14 03:45:29 emax Exp $ + */ + +#ifndef _NETGRAPH_BTSOCKET_HCI_RAW_H_ +#define _NETGRAPH_BTSOCKET_HCI_RAW_H_ + +#define NG_BTSOCKET_HCI_RAW_SENDSPACE (4 * 1024) +#define NG_BTSOCKET_HCI_RAW_RECVSPACE (4 * 1024) + +/* + * Bluetooth raw HCI socket PCB + */ + +struct ng_btsocket_hci_raw_pcb { + struct socket *so; /* socket */ + u_int32_t flags; /* flags */ +#define NG_BTSOCKET_HCI_RAW_DIRECTION (1 << 0) +#define NG_BTSOCKET_HCI_RAW_PRIVILEGED (1 << 1) + struct sockaddr_hci addr; /* local address */ + struct ng_btsocket_hci_raw_filter filter; /* filter */ + u_int32_t token; /* message token */ + struct ng_mesg *msg; /* message */ + LIST_ENTRY(ng_btsocket_hci_raw_pcb) next; /* link to next */ +#if 0 + struct mtx pcb_mtx; /* pcb mutex */ +#endif +}; +typedef struct ng_btsocket_hci_raw_pcb ng_btsocket_hci_raw_pcb_t; +typedef struct ng_btsocket_hci_raw_pcb * ng_btsocket_hci_raw_pcb_p; + +#define so2hci_raw_pcb(so) \ + ((struct ng_btsocket_hci_raw_pcb *)((so)->so_pcb)) + +/* + * Bluetooth raw HCI socket methods + */ + +#ifdef _KERNEL + +void hci_raw_init(void); + +int ng_btsocket_hci_raw_abort (struct socket *); +int ng_btsocket_hci_raw_attach (struct socket *, int, struct proc *); +int ng_btsocket_hci_raw_bind (struct socket *, struct sockaddr *, + struct proc *); +int ng_btsocket_hci_raw_connect (struct socket *, struct sockaddr *, + struct proc *); +int ng_btsocket_hci_raw_control (struct socket *, u_long, caddr_t, + struct ifnet *, struct proc *); +int hci_raw_ctloutput(int, struct socket *, int, int, struct mbuf **); +int ng_btsocket_hci_raw_detach (struct socket *); +int ng_btsocket_hci_raw_disconnect (struct socket *); +int ng_btsocket_hci_raw_peeraddr (struct socket *, struct sockaddr **); +int ng_btsocket_hci_raw_send (struct socket *, int, struct mbuf *, + struct sockaddr *, struct mbuf *, + struct proc *); +int ng_btsocket_hci_raw_sockaddr (struct socket *, struct sockaddr **); + +int hci_raw_usrreq(struct socket *, int, struct mbuf *, struct mbuf *, + struct mbuf *); + +void ng_btsocket_hci_raw_data_input(struct mbuf *); +int ng_btsocket_hci_raw_node_rcvdata(struct ifnet *, struct mbuf *); + +#endif /* _KERNEL */ + +#endif /* ndef _NETGRAPH_BTSOCKET_HCI_RAW_H_ */ diff --git a/sys/netbt/l2cap.h b/sys/netbt/l2cap.h new file mode 100644 index 00000000000..e860f358db7 --- /dev/null +++ b/sys/netbt/l2cap.h @@ -0,0 +1,663 @@ +/* $OpenBSD: l2cap.h,v 1.1 2005/01/14 12:04:02 grange Exp $ */ + +/* + * ng_l2cap.h + * + * Copyright (c) Maksim Yevmenkin <m_evmenkin@yahoo.com> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: l2cap.h,v 1.1 2005/01/14 12:04:02 grange Exp $ + * $FreeBSD: src/sys/netgraph/bluetooth/include/ng_l2cap.h,v 1.2 2003/05/10 21:44:41 julian Exp $ + */ + +/* + * This file contains everything that application needs to know about + * Link Layer Control and Adaptation Protocol (L2CAP). All information + * was obtained from Bluetooth Specification Book v1.1. + * + * This file can be included by both kernel and userland applications. + */ + +#ifndef _NETGRAPH_L2CAP_H_ +#define _NETGRAPH_L2CAP_H_ + +/************************************************************************** + ************************************************************************** + ** Netgraph node hook name, type name and type cookie and commands + ************************************************************************** + **************************************************************************/ + +/* Netgraph node hook names */ +#define NG_L2CAP_HOOK_HCI "hci" /* HCI <-> L2CAP */ +#define NG_L2CAP_HOOK_L2C "l2c" /* L2CAP <-> Upper */ +#define NG_L2CAP_HOOK_CTL "ctl" /* L2CAP <-> User */ + +/* Node type name and type cookie */ +#define NG_L2CAP_NODE_TYPE "l2cap" +#define NGM_L2CAP_COOKIE 1000774185 + +/************************************************************************** + ************************************************************************** + ** Common defines and types (L2CAP) + ************************************************************************** + **************************************************************************/ + +/* + * Channel IDs are assigned relative to the instance of L2CAP node, i.e. + * relative to the unit. So the total number of channels that unit can have + * open at the same time is 0xffff - 0x0040 = 0xffbf (65471). This number + * does not depend on number of connections. + */ + +#define NG_L2CAP_NULL_CID 0x0000 /* DO NOT USE THIS CID */ +#define NG_L2CAP_SIGNAL_CID 0x0001 /* signaling channel ID */ +#define NG_L2CAP_CLT_CID 0x0002 /* connectionless channel ID */ + /* 0x0003 - 0x003f Reserved */ +#define NG_L2CAP_FIRST_CID 0x0040 /* dynamically alloc. (start) */ +#define NG_L2CAP_LAST_CID 0xffff /* dynamically alloc. (end) */ + +/* L2CAP MTU */ +#define NG_L2CAP_MTU_MINIMUM 48 +#define NG_L2CAP_MTU_DEFAULT 672 +#define NG_L2CAP_MTU_MAXIMUM 0xffff + +/* L2CAP flush and link timeouts */ +#define NG_L2CAP_FLUSH_TIMO_DEFAULT 0xffff /* always retransmit */ +#define NG_L2CAP_LINK_TIMO_DEFAULT 0xffff + +/* L2CAP Command Reject reasons */ +#define NG_L2CAP_REJ_NOT_UNDERSTOOD 0x0000 +#define NG_L2CAP_REJ_MTU_EXCEEDED 0x0001 +#define NG_L2CAP_REJ_INVALID_CID 0x0002 +/* 0x0003 - 0xffff - reserved for future use */ + +/* Protocol/Service Multioplexor (PSM) values */ +#define NG_L2CAP_PSM_ANY 0x0000 /* Any/Invalid PSM */ +#define NG_L2CAP_PSM_SDP 0x0001 /* Service Discovery Protocol */ +#define NG_L2CAP_PSM_RFCOMM 0x0003 /* RFCOMM protocol */ +#define NG_L2CAP_PSM_TCP 0x0005 /* Telephony Control Protocol */ +/* 0x0006 - 0x1000 - reserved for future use */ + +/* L2CAP Connection response command result codes */ +#define NG_L2CAP_SUCCESS 0x0000 +#define NG_L2CAP_PENDING 0x0001 +#define NG_L2CAP_PSM_NOT_SUPPORTED 0x0002 +#define NG_L2CAP_SEQUIRY_BLOCK 0x0003 +#define NG_L2CAP_NO_RESOURCES 0x0004 +#define NG_L2CAP_TIMEOUT 0xeeee +#define NG_L2CAP_UNKNOWN 0xffff +/* 0x0005 - 0xffff - reserved for future use */ + +/* L2CAP Connection response status codes */ +#define NG_L2CAP_NO_INFO 0x0000 +#define NG_L2CAP_AUTH_PENDING 0x0001 +#define NG_L2CAP_AUTZ_PENDING 0x0002 +/* 0x0003 - 0xffff - reserved for future use */ + +/* L2CAP Configuration response result codes */ +#define NG_L2CAP_UNACCEPTABLE_PARAMS 0x0001 +#define NG_L2CAP_REJECT 0x0002 +#define NG_L2CAP_UNKNOWN_OPTION 0x0003 +/* 0x0003 - 0xffff - reserved for future use */ + +/* L2CAP Configuration options */ +#define NG_L2CAP_OPT_CFLAG_BIT 0x0001 +#define NG_L2CAP_OPT_CFLAG(flags) ((flags) & NG_L2CAP_OPT_CFLAG_BIT) +#define NG_L2CAP_OPT_HINT_BIT 0x80 +#define NG_L2CAP_OPT_HINT(type) ((type) & NG_L2CAP_OPT_HINT_BIT) +#define NG_L2CAP_OPT_HINT_MASK 0x7f +#define NG_L2CAP_OPT_MTU 0x01 +#define NG_L2CAP_OPT_MTU_SIZE sizeof(u_int16_t) +#define NG_L2CAP_OPT_FLUSH_TIMO 0x02 +#define NG_L2CAP_OPT_FLUSH_TIMO_SIZE sizeof(u_int16_t) +#define NG_L2CAP_OPT_QOS 0x03 +#define NG_L2CAP_OPT_QOS_SIZE sizeof(ng_l2cap_flow_t) +/* 0x4 - 0xff - reserved for future use */ + +/* L2CAP Information request type codes */ +#define NG_L2CAP_CONNLESS_MTU 0x0001 +/* 0x0002 - 0xffff - reserved for future use */ + +/* L2CAP Information response codes */ +#define NG_L2CAP_NOT_SUPPORTED 0x0001 +/* 0x0002 - 0xffff - reserved for future use */ + +/* L2CAP flow control */ +typedef struct { + u_int8_t flags; /* reserved for future use */ + u_int8_t service_type; /* service type */ + u_int32_t token_rate; /* bytes per second */ + u_int32_t token_bucket_size; /* bytes */ + u_int32_t peak_bandwidth; /* bytes per second */ + u_int32_t latency; /* microseconds */ + u_int32_t delay_variation; /* microseconds */ +} __attribute__ ((packed)) ng_l2cap_flow_t; +typedef ng_l2cap_flow_t * ng_l2cap_flow_p; + +/************************************************************************** + ************************************************************************** + ** Link level defines, headers and types + ************************************************************************** + **************************************************************************/ + +/* L2CAP header */ +typedef struct { + u_int16_t length; /* payload size */ + u_int16_t dcid; /* destination channel ID */ +} __attribute__ ((packed)) ng_l2cap_hdr_t; + +/* L2CAP ConnectionLess Traffic (CLT) (if destination cid == 0x2) */ +typedef struct { + u_int16_t psm; /* Protocol/Service Multiplexor */ +} __attribute__ ((packed)) ng_l2cap_clt_hdr_t; + +#define NG_L2CAP_CLT_MTU_MAXIMUM \ + (NG_L2CAP_MTU_MAXIMUM - sizeof(ng_l2cap_clt_hdr_t)) + +/* L2CAP command header */ +typedef struct { + u_int8_t code; /* command OpCode */ + u_int8_t ident; /* identifier to match request and response */ + u_int16_t length; /* command parameters length */ +} __attribute__ ((packed)) ng_l2cap_cmd_hdr_t; + +/* L2CAP Command Reject */ +#define NG_L2CAP_CMD_REJ 0x01 +typedef struct { + u_int16_t reason; /* reason to reject command */ +/* u_int8_t data[]; -- optional data (depends on reason) */ +} __attribute__ ((packed)) ng_l2cap_cmd_rej_cp; + +/* CommandReject data */ +typedef union { + /* NG_L2CAP_REJ_MTU_EXCEEDED */ + struct { + u_int16_t mtu; /* actual signaling MTU */ + } __attribute__ ((packed)) mtu; + /* NG_L2CAP_REJ_INVALID_CID */ + struct { + u_int16_t scid; /* local CID */ + u_int16_t dcid; /* remote CID */ + } __attribute__ ((packed)) cid; +} ng_l2cap_cmd_rej_data_t; +typedef ng_l2cap_cmd_rej_data_t * ng_l2cap_cmd_rej_data_p; + +/* L2CAP Connection Request */ +#define NG_L2CAP_CON_REQ 0x02 +typedef struct { + u_int16_t psm; /* Protocol/Service Multiplexor (PSM) */ + u_int16_t scid; /* source channel ID */ +} __attribute__ ((packed)) ng_l2cap_con_req_cp; + +/* L2CAP Connection Response */ +#define NG_L2CAP_CON_RSP 0x03 +typedef struct { + u_int16_t dcid; /* destination channel ID */ + u_int16_t scid; /* source channel ID */ + u_int16_t result; /* 0x00 - success */ + u_int16_t status; /* more info if result != 0x00 */ +} __attribute__ ((packed)) ng_l2cap_con_rsp_cp; + +/* L2CAP Configuration Request */ +#define NG_L2CAP_CFG_REQ 0x04 +typedef struct { + u_int16_t dcid; /* destination channel ID */ + u_int16_t flags; /* flags */ +/* u_int8_t options[] -- options */ +} __attribute__ ((packed)) ng_l2cap_cfg_req_cp; + +/* L2CAP Configuration Response */ +#define NG_L2CAP_CFG_RSP 0x05 +typedef struct { + u_int16_t scid; /* source channel ID */ + u_int16_t flags; /* flags */ + u_int16_t result; /* 0x00 - success */ +/* u_int8_t options[] -- options */ +} __attribute__ ((packed)) ng_l2cap_cfg_rsp_cp; + +/* L2CAP configuration option */ +typedef struct { + u_int8_t type; + u_int8_t length; +/* u_int8_t value[] -- option value (depends on type) */ +} __attribute__ ((packed)) ng_l2cap_cfg_opt_t; +typedef ng_l2cap_cfg_opt_t * ng_l2cap_cfg_opt_p; + +/* L2CAP configuration option value */ +typedef union { + u_int16_t mtu; /* NG_L2CAP_OPT_MTU */ + u_int16_t flush_timo; /* NG_L2CAP_OPT_FLUSH_TIMO */ + ng_l2cap_flow_t flow; /* NG_L2CAP_OPT_QOS */ +} ng_l2cap_cfg_opt_val_t; +typedef ng_l2cap_cfg_opt_val_t * ng_l2cap_cfg_opt_val_p; + +/* L2CAP Disconnect Request */ +#define NG_L2CAP_DISCON_REQ 0x06 +typedef struct { + u_int16_t dcid; /* destination channel ID */ + u_int16_t scid; /* source channel ID */ +} __attribute__ ((packed)) ng_l2cap_discon_req_cp; + +/* L2CAP Disconnect Response */ +#define NG_L2CAP_DISCON_RSP 0x07 +typedef ng_l2cap_discon_req_cp ng_l2cap_discon_rsp_cp; + +/* L2CAP Echo Request */ +#define NG_L2CAP_ECHO_REQ 0x08 +/* No command parameters, only optional data */ + +/* L2CAP Echo Response */ +#define NG_L2CAP_ECHO_RSP 0x09 +#define NG_L2CAP_MAX_ECHO_SIZE \ + (NG_L2CAP_MTU_MAXIMUM - sizeof(ng_l2cap_cmd_hdr_t)) +/* No command parameters, only optional data */ + +/* L2CAP Information Request */ +#define NG_L2CAP_INFO_REQ 0x0a +typedef struct { + u_int16_t type; /* requested information type */ +} __attribute__ ((packed)) ng_l2cap_info_req_cp; + +/* L2CAP Information Response */ +#define NG_L2CAP_INFO_RSP 0x0b +typedef struct { + u_int16_t type; /* requested information type */ + u_int16_t result; /* 0x00 - success */ +/* u_int8_t info[] -- info data (depends on type) + * + * NG_L2CAP_CONNLESS_MTU - 2 bytes connectionless MTU + */ +} __attribute__ ((packed)) ng_l2cap_info_rsp_cp; + +typedef union { + /* NG_L2CAP_CONNLESS_MTU */ + struct { + u_int16_t mtu; + } __attribute__ ((packed)) mtu; +} ng_l2cap_info_rsp_data_t; +typedef ng_l2cap_info_rsp_data_t * ng_l2cap_info_rsp_data_p; + +/************************************************************************** + ************************************************************************** + ** Upper layer protocol interface. L2CA_xxx messages + ************************************************************************** + **************************************************************************/ + +/* + * NOTE! NOTE! NOTE! + * + * Bluetooth specification says that L2CA_xxx request must block until + * response is ready. We are not allowed to block in Netgraph, so we + * need to queue request and save some information that can be used + * later and help match request and response. + * + * The idea is to use "token" field from Netgraph message header. The + * upper layer protocol _MUST_ populate "token". L2CAP will queue request + * (using L2CAP command descriptor) and start processing. Later, when + * response is ready or timeout has occur L2CAP layer will create new + * Netgraph message, set "token" and RESP flag and send the message to + * the upper layer protocol. + * + * L2CA_xxx_Ind messages _WILL_NOT_ populate "token" and _WILL_NOT_ + * set RESP flag. There is no reason for this, because they are just + * notifications and do not require acknowlegment. + * + * NOTE: This is _NOT_ what NG_MKRESPONSE and NG_RESPOND_MSG do, however + * it is somewhat similar. + */ + +/* L2CA data packet header */ +typedef struct { + u_int32_t token; /* token to use in L2CAP_L2CA_WRITE */ + u_int16_t length; /* length of the data */ + u_int16_t lcid; /* local channel ID */ +} __attribute__ ((packed)) ng_l2cap_l2ca_hdr_t; + +/* L2CA_Connect */ +#define NGM_L2CAP_L2CA_CON 0x80 +/* Upper -> L2CAP */ +typedef struct { + u_int16_t psm; /* Protocol/Service Multiplexor */ + bdaddr_t bdaddr; /* remote unit address */ +} ng_l2cap_l2ca_con_ip; + +/* L2CAP -> Upper */ +typedef struct { + u_int16_t lcid; /* local channel ID */ + u_int16_t result; /* 0x00 - success */ + u_int16_t status; /* if result != 0x00 */ +} ng_l2cap_l2ca_con_op; + +/* L2CA_ConnectInd */ +#define NGM_L2CAP_L2CA_CON_IND 0x81 +/* L2CAP -> Upper */ +typedef struct { + bdaddr_t bdaddr; /* remote unit address */ + u_int16_t lcid; /* local channel ID */ + u_int16_t psm; /* Procotol/Service Multiplexor */ + u_int8_t ident; /* indentifier */ + u_int8_t unused; /* place holder */ +} ng_l2cap_l2ca_con_ind_ip; +/* No output parameters */ + +/* L2CA_ConnectRsp */ +#define NGM_L2CAP_L2CA_CON_RSP 0x82 +/* Upper -> L2CAP */ +typedef struct { + bdaddr_t bdaddr; /* remote unit address */ + u_int8_t ident; /* "ident" from L2CAP_ConnectInd event */ + u_int8_t unused; /* place holder */ + u_int16_t lcid; /* local channel ID */ + u_int16_t result; /* 0x00 - success */ + u_int16_t status; /* if response != 0x00 */ +} ng_l2cap_l2ca_con_rsp_ip; + +/* L2CAP -> Upper */ +typedef struct { + u_int16_t result; /* 0x00 - success */ +} ng_l2cap_l2ca_con_rsp_op; + +/* L2CA_Config */ +#define NGM_L2CAP_L2CA_CFG 0x83 +/* Upper -> L2CAP */ +typedef struct { + u_int16_t lcid; /* local channel ID */ + u_int16_t imtu; /* receiving MTU for the local channel */ + ng_l2cap_flow_t oflow; /* out flow */ + u_int16_t flush_timo; /* flush timeout (msec) */ + u_int16_t link_timo; /* link timeout (msec) */ +} ng_l2cap_l2ca_cfg_ip; + +/* L2CAP -> Upper */ +typedef struct { + u_int16_t result; /* 0x00 - success */ + u_int16_t imtu; /* sending MTU for the remote channel */ + ng_l2cap_flow_t oflow; /* out flow */ + u_int16_t flush_timo; /* flush timeout (msec) */ +} ng_l2cap_l2ca_cfg_op; + +/* L2CA_ConfigRsp */ +#define NGM_L2CAP_L2CA_CFG_RSP 0x84 +/* Upper -> L2CAP */ +typedef struct { + u_int16_t lcid; /* local channel ID */ + u_int16_t omtu; /* sending MTU for the local channel */ + ng_l2cap_flow_t iflow; /* in FLOW */ +} ng_l2cap_l2ca_cfg_rsp_ip; + +/* L2CAP -> Upper */ +typedef struct { + u_int16_t result; /* 0x00 - sucsess */ +} ng_l2cap_l2ca_cfg_rsp_op; + +/* L2CA_ConfigInd */ +#define NGM_L2CAP_L2CA_CFG_IND 0x85 +/* L2CAP -> Upper */ +typedef struct { + u_int16_t lcid; /* local channel ID */ + u_int16_t omtu; /* outgoing MTU for the local channel */ + ng_l2cap_flow_t iflow; /* in flow */ + u_int16_t flush_timo; /* flush timeout (msec) */ +} ng_l2cap_l2ca_cfg_ind_ip; +/* No output parameters */ + +/* L2CA_QoSViolationInd */ +#define NGM_L2CAP_L2CA_QOS_IND 0x86 +/* L2CAP -> Upper */ +typedef struct { + bdaddr_t bdaddr; /* remote unit address */ +} ng_l2cap_l2ca_qos_ind_ip; +/* No output parameters */ + +/* L2CA_Disconnect */ +#define NGM_L2CAP_L2CA_DISCON 0x87 +/* Upper -> L2CAP */ +typedef struct { + u_int16_t lcid; /* local channel ID */ +} ng_l2cap_l2ca_discon_ip; + +/* L2CAP -> Upper */ +typedef struct { + u_int16_t result; /* 0x00 - sucsess */ +} ng_l2cap_l2ca_discon_op; + +/* L2CA_DisconnectInd */ +#define NGM_L2CAP_L2CA_DISCON_IND 0x88 +/* L2CAP -> Upper */ +typedef ng_l2cap_l2ca_discon_ip ng_l2cap_l2ca_discon_ind_ip; +/* No output parameters */ + +/* L2CA_Write response */ +#define NGM_L2CAP_L2CA_WRITE 0x89 +/* No input parameters */ + +/* L2CAP -> Upper */ +typedef struct { + int result; /* result (0x00 - success) */ + u_int16_t length; /* amount of data written */ + u_int16_t lcid; /* local channel ID */ +} ng_l2cap_l2ca_write_op; + +/* L2CA_GroupCreate */ +#define NGM_L2CAP_L2CA_GRP_CREATE 0x8a +/* Upper -> L2CAP */ +typedef struct { + u_int16_t psm; /* Protocol/Service Multiplexor */ +} ng_l2cap_l2ca_grp_create_ip; + +/* L2CAP -> Upper */ +typedef struct { + u_int16_t lcid; /* local group channel ID */ +} ng_l2cap_l2ca_grp_create_op; + +/* L2CA_GroupClose */ +#define NGM_L2CAP_L2CA_GRP_CLOSE 0x8b +/* Upper -> L2CAP */ +typedef struct { + u_int16_t lcid; /* local group channel ID */ +} ng_l2cap_l2ca_grp_close_ip; + +#if 0 +/* L2CAP -> Upper */ + * typedef struct { + * u_int16_t result; /* 0x00 - success */ + * } ng_l2cap_l2ca_grp_close_op; +#endif + +/* L2CA_GroupAddMember */ +#define NGM_L2CAP_L2CA_GRP_ADD_MEMBER 0x8c +/* Upper -> L2CAP */ +typedef struct { + u_int16_t lcid; /* local group channel ID */ + bdaddr_t bdaddr; /* remote unit address */ +} ng_l2cap_l2ca_grp_add_member_ip; + +/* L2CAP -> Upper */ +typedef struct { + u_int16_t result; /* 0x00 - success */ +} ng_l2cap_l2ca_grp_add_member_op; + +/* L2CA_GroupRemoveMember */ +#define NGM_L2CAP_L2CA_GRP_REM_MEMBER 0x8d +/* Upper -> L2CAP */ +typedef ng_l2cap_l2ca_grp_add_member_ip ng_l2cap_l2ca_grp_rem_member_ip; + +/* L2CAP -> Upper */ +#if 0 + * typedef ng_l2cap_l2ca_grp_add_member_op ng_l2cap_l2ca_grp_rem_member_op; +#endif + +/* L2CA_GroupMembeship */ +#define NGM_L2CAP_L2CA_GRP_MEMBERSHIP 0x8e +/* Upper -> L2CAP */ +typedef struct { + u_int16_t lcid; /* local group channel ID */ +} ng_l2cap_l2ca_grp_get_members_ip; + +/* L2CAP -> Upper */ +typedef struct { + u_int16_t result; /* 0x00 - success */ + u_int16_t nmembers; /* number of group members */ +/* bdaddr_t members[] -- group memebers */ +} ng_l2cap_l2ca_grp_get_members_op; + +/* L2CA_Ping */ +#define NGM_L2CAP_L2CA_PING 0x8f +/* Upper -> L2CAP */ +typedef struct { + bdaddr_t bdaddr; /* remote unit address */ + u_int16_t echo_size; /* size of echo data in bytes */ +/* u_int8_t echo_data[] -- echo data */ +} ng_l2cap_l2ca_ping_ip; + +/* L2CAP -> Upper */ +typedef struct { + u_int16_t result; /* 0x00 - success */ + bdaddr_t bdaddr; /* remote unit address */ + u_int16_t echo_size; /* size of echo data in bytes */ +/* u_int8_t echo_data[] -- echo data */ +} ng_l2cap_l2ca_ping_op; + +/* L2CA_GetInfo */ +#define NGM_L2CAP_L2CA_GET_INFO 0x90 +/* Upper -> L2CAP */ +typedef struct { + bdaddr_t bdaddr; /* remote unit address */ + u_int16_t info_type; /* info type */ +} ng_l2cap_l2ca_get_info_ip; + +/* L2CAP -> Upper */ +typedef struct { + u_int16_t result; /* 0x00 - success */ + u_int16_t info_size; /* size of info data in bytes */ +/* u_int8_t info_data[] -- info data */ +} ng_l2cap_l2ca_get_info_op; + +/* L2CA_EnableCLT/L2CA_DisableCLT */ +#define NGM_L2CAP_L2CA_ENABLE_CLT 0x91 +/* Upper -> L2CAP */ +typedef struct { + u_int16_t psm; /* Protocol/Service Multiplexor */ + u_int16_t enable; /* 0x00 - disable */ +} ng_l2cap_l2ca_enable_clt_ip; + +#if 0 +/* L2CAP -> Upper */ + * typedef struct { + * u_int16_t result; /* 0x00 - success */ + * } ng_l2cap_l2ca_enable_clt_op; +#endif + +/************************************************************************** + ************************************************************************** + ** L2CAP node messages + ************************************************************************** + **************************************************************************/ + +/* L2CAP connection states */ +#define NG_L2CAP_CON_CLOSED 0 /* connection closed */ +#define NG_L2CAP_W4_LP_CON_CFM 1 /* waiting... */ +#define NG_L2CAP_CON_OPEN 2 /* connection open */ + +/* L2CAP channel states */ +#define NG_L2CAP_CLOSED 0 /* channel closed */ +#define NG_L2CAP_W4_L2CAP_CON_RSP 1 /* wait for L2CAP resp. */ +#define NG_L2CAP_W4_L2CA_CON_RSP 2 /* wait for upper resp. */ +#define NG_L2CAP_CONFIG 3 /* L2CAP configuration */ +#define NG_L2CAP_OPEN 4 /* channel open */ +#define NG_L2CAP_W4_L2CAP_DISCON_RSP 5 /* wait for L2CAP discon. */ +#define NG_L2CAP_W4_L2CA_DISCON_RSP 6 /* wait for upper discon. */ + +/* Node flags */ +#define NG_L2CAP_CLT_SDP_DISABLED (1 << 0) /* disable SDP CLT */ +#define NG_L2CAP_CLT_RFCOMM_DISABLED (1 << 1) /* disable RFCOMM CLT */ +#define NG_L2CAP_CLT_TCP_DISABLED (1 << 2) /* disable TCP CLT */ + +/* Debug levels */ +#define NG_L2CAP_ALERT_LEVEL 1 +#define NG_L2CAP_ERR_LEVEL 2 +#define NG_L2CAP_WARN_LEVEL 3 +#define NG_L2CAP_INFO_LEVEL 4 + +/* Get node flags (see flags above) */ +#define NGM_L2CAP_NODE_GET_FLAGS 0x400 /* L2CAP -> User */ +typedef u_int16_t ng_l2cap_node_flags_ep; + +/* Get/Set debug level (see levels above) */ +#define NGM_L2CAP_NODE_GET_DEBUG 0x401 /* L2CAP -> User */ +#define NGM_L2CAP_NODE_SET_DEBUG 0x402 /* User -> L2CAP */ +typedef u_int16_t ng_l2cap_node_debug_ep; + +#define NGM_L2CAP_NODE_HOOK_INFO 0x409 /* L2CAP -> Upper */ +/* bdaddr_t bdaddr; -- local (source BDADDR) */ + +#define NGM_L2CAP_NODE_GET_CON_LIST 0x40a /* L2CAP -> User */ +typedef struct { + u_int32_t num_connections; /* number of connections */ +} ng_l2cap_node_con_list_ep; + +/* Connection flags */ +#define NG_L2CAP_CON_TX (1 << 0) /* sending data */ +#define NG_L2CAP_CON_RX (1 << 1) /* receiving data */ +#define NG_L2CAP_CON_OUTGOING (1 << 2) /* outgoing connection */ +#define NG_L2CAP_CON_LP_TIMO (1 << 3) /* LP timeout */ +#define NG_L2CAP_CON_AUTO_DISCON_TIMO (1 << 4) /* auto discon. timeout */ + +typedef struct { + u_int8_t state; /* connection state */ + u_int8_t flags; /* flags */ + int16_t pending; /* num. pending packets */ + u_int16_t con_handle; /* connection handle */ + bdaddr_t remote; /* remote bdaddr */ +} ng_l2cap_node_con_ep; + +#define NG_L2CAP_MAX_CON_NUM \ + ((0xffff - sizeof(ng_l2cap_node_con_list_ep))/sizeof(ng_l2cap_node_con_ep)) + +#define NGM_L2CAP_NODE_GET_CHAN_LIST 0x40b /* L2CAP -> User */ +typedef struct { + u_int32_t num_channels; /* number of channels */ +} ng_l2cap_node_chan_list_ep; + +typedef struct { + u_int32_t state; /* channel state */ + + u_int16_t scid; /* source (local) channel ID */ + u_int16_t dcid; /* destination (remote) channel ID */ + + u_int16_t imtu; /* incomming MTU */ + u_int16_t omtu; /* outgoing MTU */ + + u_int16_t psm; /* PSM */ + bdaddr_t remote; /* remote bdaddr */ +} ng_l2cap_node_chan_ep; + +#define NG_L2CAP_MAX_CHAN_NUM \ + ((0xffff - sizeof(ng_l2cap_node_chan_list_ep))/sizeof(ng_l2cap_node_chan_ep)) + +#define NGM_L2CAP_NODE_GET_AUTO_DISCON_TIMO 0x40c /* L2CAP -> User */ +#define NGM_L2CAP_NODE_SET_AUTO_DISCON_TIMO 0x40d /* User -> L2CAP */ +typedef u_int16_t ng_l2cap_node_auto_discon_ep; + +#endif /* ndef _NETGRAPH_L2CAP_H_ */ diff --git a/sys/netbt/l2cap_var.h b/sys/netbt/l2cap_var.h new file mode 100644 index 00000000000..51ee4d1f75e --- /dev/null +++ b/sys/netbt/l2cap_var.h @@ -0,0 +1,216 @@ +/* $OpenBSD: l2cap_var.h,v 1.1 2005/01/14 12:04:02 grange Exp $ */ + +/* + * ng_btsocket_l2cap.h + * + * Copyright (c) 2001-2002 Maksim Yevmenkin <m_evmenkin@yahoo.com> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: l2cap_var.h,v 1.1 2005/01/14 12:04:02 grange Exp $ + * $FreeBSD: src/sys/netgraph/bluetooth/include/ng_btsocket_l2cap.h,v 1.3 2003/11/14 03:45:29 emax Exp $ + */ + +#ifndef _NETGRAPH_BTSOCKET_L2CAP_H_ +#define _NETGRAPH_BTSOCKET_L2CAP_H_ + +#include <sys/timeout.h> + +/* + * L2CAP routing entry + */ + +struct ng_hook; +struct ng_message; + +struct ng_btsocket_l2cap_rtentry { + bdaddr_t src; /* source BD_ADDR */ + struct ng_hook *hook; /* downstream hook */ + LIST_ENTRY(ng_btsocket_l2cap_rtentry) next; /* link to next */ +}; +typedef struct ng_btsocket_l2cap_rtentry ng_btsocket_l2cap_rtentry_t; +typedef struct ng_btsocket_l2cap_rtentry * ng_btsocket_l2cap_rtentry_p; + +/***************************************************************************** + ***************************************************************************** + ** SOCK_RAW L2CAP sockets ** + ***************************************************************************** + *****************************************************************************/ + +#define NG_BTSOCKET_L2CAP_RAW_SENDSPACE NG_L2CAP_MTU_DEFAULT +#define NG_BTSOCKET_L2CAP_RAW_RECVSPACE NG_L2CAP_MTU_DEFAULT + +/* + * Bluetooth raw L2CAP socket PCB + */ + +struct ng_btsocket_l2cap_raw_pcb { + struct socket *so; /* socket */ + + u_int32_t flags; /* flags */ +#define NG_BTSOCKET_L2CAP_RAW_PRIVILEGED (1 << 0) + + bdaddr_t src; /* source address */ + bdaddr_t dst; /* dest address */ + ng_btsocket_l2cap_rtentry_p rt; /* routing info */ + + u_int32_t token; /* message token */ + struct ng_mesg *msg; /* message */ + +#if 0 + struct mtx pcb_mtx; /* pcb mutex */ +#endif + + LIST_ENTRY(ng_btsocket_l2cap_raw_pcb) next; /* link to next PCB */ +}; +typedef struct ng_btsocket_l2cap_raw_pcb ng_btsocket_l2cap_raw_pcb_t; +typedef struct ng_btsocket_l2cap_raw_pcb * ng_btsocket_l2cap_raw_pcb_p; + +#define so2l2cap_raw_pcb(so) \ + ((struct ng_btsocket_l2cap_raw_pcb *)((so)->so_pcb)) + +/* + * Bluetooth raw L2CAP socket methods + */ + +#ifdef _KERNEL + +void l2cap_raw_init(void); +int ng_btsocket_l2cap_raw_abort (struct socket *); +int ng_btsocket_l2cap_raw_attach (struct socket *, int, struct proc *); +int ng_btsocket_l2cap_raw_bind (struct socket *, struct sockaddr *, + struct proc *); +int ng_btsocket_l2cap_raw_connect (struct socket *, struct sockaddr *, + struct proc *); +int ng_btsocket_l2cap_raw_control (struct socket *, u_long, caddr_t, + struct ifnet *, struct proc *); +int ng_btsocket_l2cap_raw_detach (struct socket *); +int ng_btsocket_l2cap_raw_disconnect (struct socket *); +int ng_btsocket_l2cap_raw_peeraddr (struct socket *, struct sockaddr **); +int ng_btsocket_l2cap_raw_send (struct socket *, int, struct mbuf *, + struct sockaddr *, struct mbuf *, + struct proc *); +int ng_btsocket_l2cap_raw_sockaddr (struct socket *, struct sockaddr **); + +#endif /* _KERNEL */ + +/***************************************************************************** + ***************************************************************************** + ** SOCK_SEQPACKET L2CAP sockets ** + ***************************************************************************** + *****************************************************************************/ + +#define NG_BTSOCKET_L2CAP_SENDSPACE NG_L2CAP_MTU_DEFAULT /* (64 * 1024) */ +#define NG_BTSOCKET_L2CAP_RECVSPACE (64 * 1024) + +/* + * Bluetooth L2CAP socket PCB + */ + +struct ng_btsocket_l2cap_pcb { + struct socket *so; /* Pointer to socket */ + + bdaddr_t src; /* Source address */ + bdaddr_t dst; /* Destination address */ + + u_int16_t psm; /* PSM */ + u_int16_t cid; /* Local channel ID */ + + u_int16_t flags; /* socket flags */ +#define NG_BTSOCKET_L2CAP_CLIENT (1 << 0) /* socket is client */ +#define NG_BTSOCKET_L2CAP_TIMO (1 << 1) /* timeout pending */ + + u_int8_t state; /* socket state */ +#define NG_BTSOCKET_L2CAP_CLOSED 0 /* socket closed */ +#define NG_BTSOCKET_L2CAP_CONNECTING 1 /* wait for connect */ +#define NG_BTSOCKET_L2CAP_CONFIGURING 2 /* wait for config */ +#define NG_BTSOCKET_L2CAP_OPEN 3 /* socket open */ +#define NG_BTSOCKET_L2CAP_DISCONNECTING 4 /* wait for disconnect */ + + u_int8_t cfg_state; /* config state */ +#define NG_BTSOCKET_L2CAP_CFG_IN (1 << 0) /* incoming path done */ +#define NG_BTSOCKET_L2CAP_CFG_OUT (1 << 1) /* outgoing path done */ +#define NG_BTSOCKET_L2CAP_CFG_BOTH \ + (NG_BTSOCKET_L2CAP_CFG_IN | NG_BTSOCKET_L2CAP_CFG_OUT) + +#define NG_BTSOCKET_L2CAP_CFG_IN_SENT (1 << 2) /* L2CAP ConfigReq sent */ +#define NG_BTSOCKET_L2CAP_CFG_OUT_SENT (1 << 3) /* ---/--- */ + + u_int16_t imtu; /* Incoming MTU */ + ng_l2cap_flow_t iflow; /* Input flow spec */ + + u_int16_t omtu; /* Outgoing MTU */ + ng_l2cap_flow_t oflow; /* Outgoing flow spec */ + + u_int16_t flush_timo; /* flush timeout */ + u_int16_t link_timo; /* link timeout */ + + struct timeout timo; /* timeout */ + + u_int32_t token; /* message token */ + ng_btsocket_l2cap_rtentry_p rt; /* routing info */ + +#if 0 + struct mtx pcb_mtx; /* pcb mutex */ +#endif + + LIST_ENTRY(ng_btsocket_l2cap_pcb) next; /* link to next PCB */ +}; +typedef struct ng_btsocket_l2cap_pcb ng_btsocket_l2cap_pcb_t; +typedef struct ng_btsocket_l2cap_pcb * ng_btsocket_l2cap_pcb_p; + +#define so2l2cap_pcb(so) \ + ((struct ng_btsocket_l2cap_pcb *)((so)->so_pcb)) + +/* + * Bluetooth L2CAP socket methods + */ + +#ifdef _KERNEL + +void l2cap_init(void); +int ng_btsocket_l2cap_abort (struct socket *); +int ng_btsocket_l2cap_accept (struct socket *, struct sockaddr **); +int ng_btsocket_l2cap_attach (struct socket *, int, struct proc *); +int ng_btsocket_l2cap_bind (struct socket *, struct sockaddr *, + struct proc *); +int ng_btsocket_l2cap_connect (struct socket *, struct sockaddr *, + struct proc *); +int ng_btsocket_l2cap_control (struct socket *, u_long, caddr_t, + struct ifnet *, struct proc *); +int l2cap_raw_ctloutput(int, struct socket *, int, int, struct mbuf **); +int ng_btsocket_l2cap_detach (struct socket *); +int ng_btsocket_l2cap_disconnect (struct socket *); +int ng_btsocket_l2cap_listen (struct socket *, struct proc *); +int ng_btsocket_l2cap_peeraddr (struct socket *, struct sockaddr **); +int ng_btsocket_l2cap_send (struct socket *, int, struct mbuf *, + struct sockaddr *, struct mbuf *, + struct proc *); +int ng_btsocket_l2cap_sockaddr (struct socket *, struct sockaddr **); + +int l2cap_raw_usrreq(struct socket *, int, struct mbuf *, struct mbuf *, + struct mbuf *); + +#endif /* _KERNEL */ + +#endif /* _NETGRAPH_BTSOCKET_L2CAP_H_ */ diff --git a/sys/netbt/rfcomm_var.h b/sys/netbt/rfcomm_var.h new file mode 100644 index 00000000000..1fe7f720d24 --- /dev/null +++ b/sys/netbt/rfcomm_var.h @@ -0,0 +1,338 @@ +/* $OpenBSD: rfcomm_var.h,v 1.1 2005/01/14 12:04:02 grange Exp $ */ + +/* + * ng_btsocket_rfcomm.h + * + * Copyright (c) 2001-2003 Maksim Yevmenkin <m_evmenkin@yahoo.com> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: rfcomm_var.h,v 1.1 2005/01/14 12:04:02 grange Exp $ + * $FreeBSD: src/sys/netgraph/bluetooth/include/ng_btsocket_rfcomm.h,v 1.2 2003/11/14 03:45:29 emax Exp $ + */ + +#ifndef _NETGRAPH_BTSOCKET_RFCOMM_H_ +#define _NETGRAPH_BTSOCKET_RFCOMM_H_ + +/***************************************************************************** + ***************************************************************************** + ** RFCOMM ** + ***************************************************************************** + *****************************************************************************/ + +/* XXX FIXME this does not belong here */ + +#define RFCOMM_DEFAULT_MTU 127 +#define RFCOMM_MAX_MTU 1024 + +#define RFCOMM_DEFAULT_CREDITS 7 +#define RFCOMM_MAX_CREDITS 40 + +/* RFCOMM frame types */ +#define RFCOMM_FRAME_SABM 0x2f +#define RFCOMM_FRAME_DISC 0x43 +#define RFCOMM_FRAME_UA 0x63 +#define RFCOMM_FRAME_DM 0x0f +#define RFCOMM_FRAME_UIH 0xef + +/* RFCOMM MCC commands */ +#define RFCOMM_MCC_TEST 0x08 /* Test */ +#define RFCOMM_MCC_FCON 0x28 /* Flow Control on */ +#define RFCOMM_MCC_FCOFF 0x18 /* Flow Control off */ +#define RFCOMM_MCC_MSC 0x38 /* Modem Status Command */ +#define RFCOMM_MCC_RPN 0x24 /* Remote Port Negotiation */ +#define RFCOMM_MCC_RLS 0x14 /* Remote Line Status */ +#define RFCOMM_MCC_PN 0x20 /* Port Negotiation */ +#define RFCOMM_MCC_NSC 0x04 /* Non Supported Command */ + +/* RFCOMM modem signals */ +#define RFCOMM_MODEM_FC 0x02 /* Flow Control asserted */ +#define RFCOMM_MODEM_RTC 0x04 /* Ready To Communicate */ +#define RFCOMM_MODEM_RTR 0x08 /* Ready To Receive */ +#define RFCOMM_MODEM_IC 0x40 /* Incomming Call */ +#define RFCOMM_MODEM_DV 0x80 /* Data Valid */ + +/* RPN parameters - baud rate */ +#define RFCOMM_RPN_BR_2400 0x0 +#define RFCOMM_RPN_BR_4800 0x1 +#define RFCOMM_RPN_BR_7200 0x2 +#define RFCOMM_RPN_BR_9600 0x3 +#define RFCOMM_RPN_BR_19200 0x4 +#define RFCOMM_RPN_BR_38400 0x5 +#define RFCOMM_RPN_BR_57600 0x6 +#define RFCOMM_RPN_BR_115200 0x7 +#define RFCOMM_RPN_BR_230400 0x8 + +/* RPN parameters - data bits */ +#define RFCOMM_RPN_DATA_5 0x0 +#define RFCOMM_RPN_DATA_6 0x1 +#define RFCOMM_RPN_DATA_7 0x2 +#define RFCOMM_RPN_DATA_8 0x3 + +/* RPN parameters - stop bit */ +#define RFCOMM_RPN_STOP_1 0 +#define RFCOMM_RPN_STOP_15 1 + +/* RPN parameters - parity */ +#define RFCOMM_RPN_PARITY_NONE 0x0 +#define RFCOMM_RPN_PARITY_ODD 0x4 +#define RFCOMM_RPN_PARITY_EVEN 0x5 +#define RFCOMM_RPN_PARITY_MARK 0x6 +#define RFCOMM_RPN_PARITY_SPACE 0x7 + +/* RPN parameters - flow control */ +#define RFCOMM_RPN_FLOW_NONE 0x00 +#define RFCOMM_RPN_XON_CHAR 0x11 +#define RFCOMM_RPN_XOFF_CHAR 0x13 + +/* RPN parameters - mask */ +#define RFCOMM_RPN_PM_BITRATE 0x0001 +#define RFCOMM_RPN_PM_DATA 0x0002 +#define RFCOMM_RPN_PM_STOP 0x0004 +#define RFCOMM_RPN_PM_PARITY 0x0008 +#define RFCOMM_RPN_PM_PARITY_TYPE 0x0010 +#define RFCOMM_RPN_PM_XON 0x0020 +#define RFCOMM_RPN_PM_XOFF 0x0040 +#define RFCOMM_RPN_PM_FLOW 0x3F00 +#define RFCOMM_RPN_PM_ALL 0x3F7F + +/* RFCOMM frame header */ +struct rfcomm_frame_hdr +{ + u_int8_t address; + u_int8_t control; + u_int8_t length; /* Actual size could be 2 bytes */ +} __attribute__ ((packed)); + +/* RFCOMM command frame header */ +struct rfcomm_cmd_hdr +{ + u_int8_t address; + u_int8_t control; + u_int8_t length; + u_int8_t fcs; +} __attribute__ ((packed)); + +/* RFCOMM MCC command header */ +struct rfcomm_mcc_hdr +{ + u_int8_t type; + u_int8_t length; /* XXX FIXME Can actual size be 2 bytes?? */ +} __attribute__ ((packed)); + +/* RFCOMM MSC command */ +struct rfcomm_mcc_msc +{ + u_int8_t address; + u_int8_t modem; +} __attribute__ ((packed)); + +/* RFCOMM RPN command */ +struct rfcomm_mcc_rpn +{ + u_int8_t dlci; + u_int8_t bit_rate; + u_int8_t line_settings; + u_int8_t flow_control; + u_int8_t xon_char; + u_int8_t xoff_char; + u_int16_t param_mask; +} __attribute__ ((packed)); + +/* RFCOMM RLS command */ +struct rfcomm_mcc_rls +{ + u_int8_t address; + u_int8_t status; +} __attribute__ ((packed)); + +/* RFCOMM PN command */ +struct rfcomm_mcc_pn +{ + u_int8_t dlci; + u_int8_t flow_control; + u_int8_t priority; + u_int8_t ack_timer; + u_int16_t mtu; + u_int8_t max_retrans; + u_int8_t credits; +} __attribute__ ((packed)); + +/* RFCOMM frame parsing macros */ +#define RFCOMM_DLCI(b) (((b) & 0xfc) >> 2) +#define RFCOMM_CHANNEL(b) (((b) & 0xf8) >> 3) +#define RFCOMM_DIRECTION(b) (((b) & 0x04) >> 2) +#define RFCOMM_TYPE(b) (((b) & 0xef)) + +#define RFCOMM_EA(b) (((b) & 0x01)) +#define RFCOMM_CR(b) (((b) & 0x02) >> 1) +#define RFCOMM_PF(b) (((b) & 0x10) >> 4) + +#define RFCOMM_SRVCHANNEL(dlci) ((dlci) >> 1) + +#define RFCOMM_MKADDRESS(cr, dlci) \ + ((((dlci) & 0x3f) << 2) | ((cr) << 1) | 0x01) + +#define RFCOMM_MKCONTROL(type, pf) ((((type) & 0xef) | ((pf) << 4))) +#define RFCOMM_MKDLCI(dir, channel) ((((channel) & 0x1f) << 1) | (dir)) + +#define RFCOMM_MKLEN8(len) (((len) << 1) | 1) +#define RFCOMM_MKLEN16(len) ((len) << 1) + +/* RFCOMM MCC macros */ +#define RFCOMM_MCC_TYPE(b) (((b) & 0xfc) >> 2) +#define RFCOMM_MCC_LENGTH(b) (((b) & 0xfe) >> 1) +#define RFCOMM_MKMCC_TYPE(cr, type) ((((type) << 2) | ((cr) << 1) | 0x01)) + +/* RPN macros */ +#define RFCOMM_RPN_DATA_BITS(line) ((line) & 0x3) +#define RFCOMM_RPN_STOP_BITS(line) (((line) >> 2) & 0x1) +#define RFCOMM_RPN_PARITY(line) (((line) >> 3) & 0x3) +#define RFCOMM_MKRPN_LINE_SETTINGS(data, stop, parity) \ + (((data) & 0x3) | (((stop) & 0x1) << 2) | (((parity) & 0x3) << 3)) + +/***************************************************************************** + ***************************************************************************** + ** SOCK_STREAM RFCOMM sockets ** + ***************************************************************************** + *****************************************************************************/ + +#define NG_BTSOCKET_RFCOMM_SENDSPACE \ + (RFCOMM_MAX_CREDITS * RFCOMM_DEFAULT_MTU * 10) +#define NG_BTSOCKET_RFCOMM_RECVSPACE \ + (RFCOMM_MAX_CREDITS * RFCOMM_DEFAULT_MTU * 10) + +/* + * Bluetooth RFCOMM session. One L2CAP connection == one RFCOMM session + */ + +struct ng_btsocket_rfcomm_pcb; +struct ng_btsocket_rfcomm_session; + +struct ng_btsocket_rfcomm_session { + struct socket *l2so; /* L2CAP socket */ + + u_int16_t state; /* session state */ +#define NG_BTSOCKET_RFCOMM_SESSION_CLOSED 0 +#define NG_BTSOCKET_RFCOMM_SESSION_LISTENING 1 +#define NG_BTSOCKET_RFCOMM_SESSION_CONNECTING 2 +#define NG_BTSOCKET_RFCOMM_SESSION_CONNECTED 3 +#define NG_BTSOCKET_RFCOMM_SESSION_OPEN 4 +#define NG_BTSOCKET_RFCOMM_SESSION_DISCONNECTING 5 + + u_int16_t flags; /* session flags */ +#define NG_BTSOCKET_RFCOMM_SESSION_INITIATOR (1 << 0) /* initiator */ +#define NG_BTSOCKET_RFCOMM_SESSION_LFC (1 << 1) /* local flow */ +#define NG_BTSOCKET_RFCOMM_SESSION_RFC (1 << 2) /* remote flow */ + +#define INITIATOR(s) \ + (((s)->flags & NG_BTSOCKET_RFCOMM_SESSION_INITIATOR)? 1 : 0) + + u_int16_t mtu; /* default MTU */ + struct ng_bt_mbufq outq; /* outgoing queue */ + + struct mtx session_mtx; /* session lock */ + LIST_HEAD(, ng_btsocket_rfcomm_pcb) dlcs; /* active DLC */ + + LIST_ENTRY(ng_btsocket_rfcomm_session) next; /* link to next */ +}; +typedef struct ng_btsocket_rfcomm_session ng_btsocket_rfcomm_session_t; +typedef struct ng_btsocket_rfcomm_session * ng_btsocket_rfcomm_session_p; + +/* + * Bluetooth RFCOMM socket PCB (DLC) + */ + +struct ng_btsocket_rfcomm_pcb { + struct socket *so; /* RFCOMM socket */ + struct ng_btsocket_rfcomm_session *session; /* RFCOMM session */ + + u_int16_t flags; /* DLC flags */ +#define NG_BTSOCKET_RFCOMM_DLC_TIMO (1 << 0) /* timeout pending */ +#define NG_BTSOCKET_RFCOMM_DLC_CFC (1 << 1) /* credit flow ctrl */ +#define NG_BTSOCKET_RFCOMM_DLC_TIMEDOUT (1 << 2) /* timeout happend */ +#define NG_BTSOCKET_RFCOMM_DLC_DETACHED (1 << 3) /* DLC detached */ +#define NG_BTSOCKET_RFCOMM_DLC_SENDING (1 << 4) /* send pending */ + + u_int16_t state; /* DLC state */ +#define NG_BTSOCKET_RFCOMM_DLC_CLOSED 0 +#define NG_BTSOCKET_RFCOMM_DLC_W4_CONNECT 1 +#define NG_BTSOCKET_RFCOMM_DLC_CONFIGURING 2 +#define NG_BTSOCKET_RFCOMM_DLC_CONNECTING 3 +#define NG_BTSOCKET_RFCOMM_DLC_CONNECTED 4 +#define NG_BTSOCKET_RFCOMM_DLC_DISCONNECTING 5 + + bdaddr_t src; /* source address */ + bdaddr_t dst; /* dest. address */ + + u_int8_t channel; /* RFCOMM channel */ + u_int8_t dlci; /* RFCOMM DLCI */ + + u_int8_t lmodem; /* local mdm signls */ + u_int8_t rmodem; /* remote -/- */ + + u_int16_t mtu; /* MTU */ + int16_t rx_cred; /* RX credits */ + int16_t tx_cred; /* TX credits */ + + struct mtx pcb_mtx; /* PCB lock */ + struct callout_handle timo; /* timeout */ + + LIST_ENTRY(ng_btsocket_rfcomm_pcb) session_next;/* link to next */ + LIST_ENTRY(ng_btsocket_rfcomm_pcb) next; /* link to next */ +}; +typedef struct ng_btsocket_rfcomm_pcb ng_btsocket_rfcomm_pcb_t; +typedef struct ng_btsocket_rfcomm_pcb * ng_btsocket_rfcomm_pcb_p; + +#define so2rfcomm_pcb(so) \ + ((struct ng_btsocket_rfcomm_pcb *)((so)->so_pcb)) + +/* + * Bluetooth RFCOMM socket methods + */ + +#ifdef _KERNEL + +void ng_btsocket_rfcomm_init (void); +int ng_btsocket_rfcomm_abort (struct socket *); +int ng_btsocket_rfcomm_accept (struct socket *, struct sockaddr **); +int ng_btsocket_rfcomm_attach (struct socket *, int, struct thread *); +int ng_btsocket_rfcomm_bind (struct socket *, struct sockaddr *, + struct thread *); +int ng_btsocket_rfcomm_connect (struct socket *, struct sockaddr *, + struct thread *); +int ng_btsocket_rfcomm_control (struct socket *, u_long, caddr_t, + struct ifnet *, struct thread *); +int ng_btsocket_rfcomm_ctloutput (struct socket *, struct sockopt *); +int ng_btsocket_rfcomm_detach (struct socket *); +int ng_btsocket_rfcomm_disconnect (struct socket *); +int ng_btsocket_rfcomm_listen (struct socket *, struct thread *); +int ng_btsocket_rfcomm_peeraddr (struct socket *, struct sockaddr **); +int ng_btsocket_rfcomm_send (struct socket *, int, struct mbuf *, + struct sockaddr *, struct mbuf *, + struct thread *); +int ng_btsocket_rfcomm_sockaddr (struct socket *, struct sockaddr **); + +#endif /* _KERNEL */ + +#endif /* _NETGRAPH_BTSOCKET_RFCOMM_H_ */ diff --git a/sys/sys/malloc.h b/sys/sys/malloc.h index 81f7e64c65f..916be3e70a4 100644 --- a/sys/sys/malloc.h +++ b/sys/sys/malloc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: malloc.h,v 1.74 2004/12/30 08:28:39 niklas Exp $ */ +/* $OpenBSD: malloc.h,v 1.75 2005/01/14 12:04:02 grange Exp $ */ /* $NetBSD: malloc.h,v 1.39 1998/07/12 19:52:01 augustss Exp $ */ /* @@ -176,7 +176,9 @@ #define M_KEVENT 137 /* kqueue related */ -#define M_LAST 138 /* Must be last type + 1 */ +#define M_BLUETOOTH 138 /* Bluetooth */ + +#define M_LAST 139 /* Must be last type + 1 */ #define INITKMEMNAMES { \ @@ -303,6 +305,7 @@ "NTFS decomp", /* 135 M_NTFSDECOMP */ \ "NTFS vrun", /* 136 M_NTFSRUN */ \ "kqueue", /* 137 M_KEVENT */ \ + "bluetooth", /* 138 M_BLUETOOTH */ \ } struct kmemstats { diff --git a/sys/sys/socket.h b/sys/sys/socket.h index 8c8371389eb..5175aa09587 100644 --- a/sys/sys/socket.h +++ b/sys/sys/socket.h @@ -1,4 +1,4 @@ -/* $OpenBSD: socket.h,v 1.48 2004/11/26 13:07:52 markus Exp $ */ +/* $OpenBSD: socket.h,v 1.49 2005/01/14 12:04:02 grange Exp $ */ /* $NetBSD: socket.h,v 1.14 1996/02/09 18:25:36 christos Exp $ */ /* @@ -132,7 +132,9 @@ struct linger { #define AF_KEY 30 #define pseudo_AF_HDRCMPLT 31 /* Used by BPF to not rewrite headers in interface output routine */ -#define AF_MAX 32 +#define AF_BLUETOOTH 32 /* Bluetooth */ + +#define AF_MAX 33 /* * Structure used by kernel to store most @@ -210,6 +212,7 @@ struct sockproto { #define PF_SIP AF_SIP #define PF_KEY AF_KEY #define PF_BPF pseudo_AF_HDRCMPLT +#define PF_BLUETOOTH AF_BLUETOOTH #define PF_MAX AF_MAX /* |