Index: head/lib/libbluetooth/bluetooth.h =================================================================== --- head/lib/libbluetooth/bluetooth.h (revision 317505) +++ head/lib/libbluetooth/bluetooth.h (revision 317506) @@ -1,218 +1,219 @@ /* * bluetooth.h */ /*- * Copyright (c) 2001-2009 Maksim Yevmenkin * 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.5 2003/09/14 23:28:42 max Exp $ * $FreeBSD$ */ #ifndef _BLUETOOTH_H_ #define _BLUETOOTH_H_ #include #include #include #include #include #include #include #include #include #include +#include #include #include #include #include __BEGIN_DECLS /* * Linux BlueZ compatibility */ #define bacmp(ba1, ba2) memcmp((ba1), (ba2), sizeof(bdaddr_t)) #define bacpy(dst, src) memcpy((dst), (src), sizeof(bdaddr_t)) #define ba2str(ba, str) bt_ntoa((ba), (str)) #define str2ba(str, ba) (bt_aton((str), (ba)) == 1? 0 : -1) #define htobs(d) htole16(d) #define htobl(d) htole32(d) #define btohs(d) le16toh(d) #define btohl(d) le32toh(d) /* * Interface to the outside world */ struct hostent * bt_gethostbyname (char const *name); struct hostent * bt_gethostbyaddr (char const *addr, int len, int type); struct hostent * bt_gethostent (void); void bt_sethostent (int stayopen); void bt_endhostent (void); struct protoent * bt_getprotobyname (char const *name); struct protoent * bt_getprotobynumber (int proto); struct protoent * bt_getprotoent (void); void bt_setprotoent (int stayopen); void bt_endprotoent (void); char const * bt_ntoa (bdaddr_t const *ba, char *str); int bt_aton (char const *str, bdaddr_t *ba); /* bt_devXXXX() functions (inspired by NetBSD) */ int bt_devaddr (char const *devname, bdaddr_t *addr); int bt_devname (char *devname, bdaddr_t const *addr); /* * Bluetooth HCI functions */ #define HCI_DEVMAX 32 /* arbitrary */ #define HCI_DEVNAME_SIZE NG_NODESIZ #define HCI_DEVFEATURES_SIZE NG_HCI_FEATURES_SIZE struct bt_devinfo { char devname[HCI_DEVNAME_SIZE]; uint32_t state; /* device/implementation specific */ bdaddr_t bdaddr; uint16_t _reserved0; uint8_t features[HCI_DEVFEATURES_SIZE]; /* buffer info */ uint16_t _reserved1; uint16_t cmd_free; uint16_t sco_size; uint16_t sco_pkts; uint16_t sco_free; uint16_t acl_size; uint16_t acl_pkts; uint16_t acl_free; /* stats */ uint32_t cmd_sent; uint32_t evnt_recv; uint32_t acl_recv; uint32_t acl_sent; uint32_t sco_recv; uint32_t sco_sent; uint32_t bytes_recv; uint32_t bytes_sent; /* misc/specific */ uint16_t link_policy_info; uint16_t packet_type_info; uint16_t role_switch_info; uint16_t debug; uint8_t _padding[20]; /* leave space for future additions */ }; struct bt_devreq { uint16_t opcode; uint8_t event; void *cparam; size_t clen; void *rparam; size_t rlen; }; struct bt_devfilter { bitstr_t bit_decl(packet_mask, 8); bitstr_t bit_decl(event_mask, 256); }; struct bt_devinquiry { bdaddr_t bdaddr; uint8_t pscan_rep_mode; uint8_t pscan_period_mode; uint8_t dev_class[3]; uint16_t clock_offset; int8_t rssi; uint8_t data[240]; }; typedef int (bt_devenum_cb_t)(int, struct bt_devinfo const *, void *); int bt_devopen (char const *devname); int bt_devclose(int s); int bt_devsend (int s, uint16_t opcode, void *param, size_t plen); ssize_t bt_devrecv (int s, void *buf, size_t size, time_t to); int bt_devreq (int s, struct bt_devreq *r, time_t to); int bt_devfilter(int s, struct bt_devfilter const *newp, struct bt_devfilter *oldp); void bt_devfilter_pkt_set(struct bt_devfilter *filter, uint8_t type); void bt_devfilter_pkt_clr(struct bt_devfilter *filter, uint8_t type); int bt_devfilter_pkt_tst(struct bt_devfilter const *filter, uint8_t type); void bt_devfilter_evt_set(struct bt_devfilter *filter, uint8_t event); void bt_devfilter_evt_clr(struct bt_devfilter *filter, uint8_t event); int bt_devfilter_evt_tst(struct bt_devfilter const *filter, uint8_t event); int bt_devinquiry(char const *devname, time_t length, int num_rsp, struct bt_devinquiry **ii); int bt_devinfo (struct bt_devinfo *di); int bt_devenum (bt_devenum_cb_t cb, void *arg); /* * bdaddr utility functions (from NetBSD) */ static __inline int bdaddr_same(const bdaddr_t *a, const bdaddr_t *b) { return (a->b[0] == b->b[0] && a->b[1] == b->b[1] && a->b[2] == b->b[2] && a->b[3] == b->b[3] && a->b[4] == b->b[4] && a->b[5] == b->b[5]); } static __inline int bdaddr_any(const bdaddr_t *a) { return (a->b[0] == 0 && a->b[1] == 0 && a->b[2] == 0 && a->b[3] == 0 && a->b[4] == 0 && a->b[5] == 0); } static __inline void bdaddr_copy(bdaddr_t *d, const bdaddr_t *s) { d->b[0] = s->b[0]; d->b[1] = s->b[1]; d->b[2] = s->b[2]; d->b[3] = s->b[3]; d->b[4] = s->b[4]; d->b[5] = s->b[5]; } __END_DECLS #endif /* ndef _BLUETOOTH_H_ */ Index: head/sys/netgraph/bluetooth/hci/ng_hci_evnt.c =================================================================== --- head/sys/netgraph/bluetooth/hci/ng_hci_evnt.c (revision 317505) +++ head/sys/netgraph/bluetooth/hci/ng_hci_evnt.c (revision 317506) @@ -1,1376 +1,1390 @@ /* * ng_hci_evnt.c */ /*- * Copyright (c) Maksim Yevmenkin * 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: ng_hci_evnt.c,v 1.6 2003/09/08 18:57:51 max Exp $ * $FreeBSD$ */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /****************************************************************************** ****************************************************************************** ** HCI event processing module ****************************************************************************** ******************************************************************************/ /* * Event processing routines */ static int inquiry_result (ng_hci_unit_p, struct mbuf *); static int con_compl (ng_hci_unit_p, struct mbuf *); static int con_req (ng_hci_unit_p, struct mbuf *); static int discon_compl (ng_hci_unit_p, struct mbuf *); static int encryption_change (ng_hci_unit_p, struct mbuf *); static int read_remote_features_compl (ng_hci_unit_p, struct mbuf *); static int qos_setup_compl (ng_hci_unit_p, struct mbuf *); static int hardware_error (ng_hci_unit_p, struct mbuf *); static int role_change (ng_hci_unit_p, struct mbuf *); static int num_compl_pkts (ng_hci_unit_p, struct mbuf *); static int mode_change (ng_hci_unit_p, struct mbuf *); static int data_buffer_overflow (ng_hci_unit_p, struct mbuf *); static int read_clock_offset_compl (ng_hci_unit_p, struct mbuf *); static int qos_violation (ng_hci_unit_p, struct mbuf *); static int page_scan_mode_change (ng_hci_unit_p, struct mbuf *); static int page_scan_rep_mode_change (ng_hci_unit_p, struct mbuf *); static int sync_con_queue (ng_hci_unit_p, ng_hci_unit_con_p, int); static int send_data_packets (ng_hci_unit_p, int, int); static int le_event (ng_hci_unit_p, struct mbuf *); /* * Process HCI event packet */ int ng_hci_process_event(ng_hci_unit_p unit, struct mbuf *event) { ng_hci_event_pkt_t *hdr = NULL; int error = 0; /* Get event packet header */ NG_HCI_M_PULLUP(event, sizeof(*hdr)); if (event == NULL) return (ENOBUFS); hdr = mtod(event, ng_hci_event_pkt_t *); NG_HCI_INFO( "%s: %s - got HCI event=%#x, length=%d\n", __func__, NG_NODE_NAME(unit->node), hdr->event, hdr->length); /* Get rid of event header and process event */ m_adj(event, sizeof(*hdr)); switch (hdr->event) { case NG_HCI_EVENT_INQUIRY_COMPL: case NG_HCI_EVENT_RETURN_LINK_KEYS: case NG_HCI_EVENT_PIN_CODE_REQ: case NG_HCI_EVENT_LINK_KEY_REQ: case NG_HCI_EVENT_LINK_KEY_NOTIFICATION: case NG_HCI_EVENT_LOOPBACK_COMMAND: case NG_HCI_EVENT_AUTH_COMPL: case NG_HCI_EVENT_CHANGE_CON_LINK_KEY_COMPL: case NG_HCI_EVENT_MASTER_LINK_KEY_COMPL: case NG_HCI_EVENT_FLUSH_OCCUR: /* XXX Do we have to handle it? */ case NG_HCI_EVENT_MAX_SLOT_CHANGE: case NG_HCI_EVENT_CON_PKT_TYPE_CHANGED: case NG_HCI_EVENT_BT_LOGO: case NG_HCI_EVENT_VENDOR: case NG_HCI_EVENT_REMOTE_NAME_REQ_COMPL: case NG_HCI_EVENT_READ_REMOTE_VER_INFO_COMPL: /* These do not need post processing */ NG_FREE_M(event); break; case NG_HCI_EVENT_LE: error = le_event(unit, event); break; case NG_HCI_EVENT_INQUIRY_RESULT: error = inquiry_result(unit, event); break; case NG_HCI_EVENT_CON_COMPL: error = con_compl(unit, event); break; case NG_HCI_EVENT_CON_REQ: error = con_req(unit, event); break; case NG_HCI_EVENT_DISCON_COMPL: error = discon_compl(unit, event); break; case NG_HCI_EVENT_ENCRYPTION_CHANGE: error = encryption_change(unit, event); break; case NG_HCI_EVENT_READ_REMOTE_FEATURES_COMPL: error = read_remote_features_compl(unit, event); break; case NG_HCI_EVENT_QOS_SETUP_COMPL: error = qos_setup_compl(unit, event); break; case NG_HCI_EVENT_COMMAND_COMPL: error = ng_hci_process_command_complete(unit, event); break; case NG_HCI_EVENT_COMMAND_STATUS: error = ng_hci_process_command_status(unit, event); break; case NG_HCI_EVENT_HARDWARE_ERROR: error = hardware_error(unit, event); break; case NG_HCI_EVENT_ROLE_CHANGE: error = role_change(unit, event); break; case NG_HCI_EVENT_NUM_COMPL_PKTS: error = num_compl_pkts(unit, event); break; case NG_HCI_EVENT_MODE_CHANGE: error = mode_change(unit, event); break; case NG_HCI_EVENT_DATA_BUFFER_OVERFLOW: error = data_buffer_overflow(unit, event); break; case NG_HCI_EVENT_READ_CLOCK_OFFSET_COMPL: error = read_clock_offset_compl(unit, event); break; case NG_HCI_EVENT_QOS_VIOLATION: error = qos_violation(unit, event); break; case NG_HCI_EVENT_PAGE_SCAN_MODE_CHANGE: error = page_scan_mode_change(unit, event); break; case NG_HCI_EVENT_PAGE_SCAN_REP_MODE_CHANGE: error = page_scan_rep_mode_change(unit, event); break; default: NG_FREE_M(event); error = EINVAL; break; } return (error); } /* ng_hci_process_event */ /* * Send ACL and/or SCO data to the unit driver */ void ng_hci_send_data(ng_hci_unit_p unit) { int count; /* Send ACL data */ NG_HCI_BUFF_ACL_AVAIL(unit->buffer, count); NG_HCI_INFO( "%s: %s - sending ACL data packets, count=%d\n", __func__, NG_NODE_NAME(unit->node), count); if (count > 0) { count = send_data_packets(unit, NG_HCI_LINK_ACL, count); NG_HCI_STAT_ACL_SENT(unit->stat, count); NG_HCI_BUFF_ACL_USE(unit->buffer, count); } /* Send SCO data */ NG_HCI_BUFF_SCO_AVAIL(unit->buffer, count); NG_HCI_INFO( "%s: %s - sending SCO data packets, count=%d\n", __func__, NG_NODE_NAME(unit->node), count); if (count > 0) { count = send_data_packets(unit, NG_HCI_LINK_SCO, count); NG_HCI_STAT_SCO_SENT(unit->stat, count); NG_HCI_BUFF_SCO_USE(unit->buffer, count); } } /* ng_hci_send_data */ /* * Send data packets to the lower layer. */ static int send_data_packets(ng_hci_unit_p unit, int link_type, int limit) { ng_hci_unit_con_p con = NULL, winner = NULL; int reallink_type; item_p item = NULL; int min_pending, total_sent, sent, error, v; for (total_sent = 0; limit > 0; ) { min_pending = 0x0fffffff; winner = NULL; /* * Find the connection that has has data to send * and the smallest number of pending packets */ LIST_FOREACH(con, &unit->con_list, next) { reallink_type = (con->link_type == NG_HCI_LINK_SCO)? NG_HCI_LINK_SCO: NG_HCI_LINK_ACL; if (reallink_type != link_type){ continue; } if (NG_BT_ITEMQ_LEN(&con->conq) == 0) continue; if (con->pending < min_pending) { winner = con; min_pending = con->pending; } } if (winner == NULL) break; /* * OK, we have a winner now send as much packets as we can * Count the number of packets we have sent and then sync * winner connection queue. */ for (sent = 0; limit > 0; limit --, total_sent ++, sent ++) { NG_BT_ITEMQ_DEQUEUE(&winner->conq, item); if (item == NULL) break; NG_HCI_INFO( "%s: %s - sending data packet, handle=%d, len=%d\n", __func__, NG_NODE_NAME(unit->node), winner->con_handle, NGI_M(item)->m_pkthdr.len); /* Check if driver hook still there */ v = (unit->drv != NULL && NG_HOOK_IS_VALID(unit->drv)); if (!v || (unit->state & NG_HCI_UNIT_READY) != NG_HCI_UNIT_READY) { NG_HCI_ERR( "%s: %s - could not send data. Hook \"%s\" is %svalid, state=%#x\n", __func__, NG_NODE_NAME(unit->node), NG_HCI_HOOK_DRV, ((v)? "" : "not "), unit->state); NG_FREE_ITEM(item); error = ENOTCONN; } else { v = NGI_M(item)->m_pkthdr.len; /* Give packet to raw hook */ ng_hci_mtap(unit, NGI_M(item)); /* ... and forward item to the driver */ NG_FWD_ITEM_HOOK(error, item, unit->drv); } if (error != 0) { NG_HCI_ERR( "%s: %s - could not send data packet, handle=%d, error=%d\n", __func__, NG_NODE_NAME(unit->node), winner->con_handle, error); break; } winner->pending ++; NG_HCI_STAT_BYTES_SENT(unit->stat, v); } /* * Sync connection queue for the winner */ sync_con_queue(unit, winner, sent); } return (total_sent); } /* send_data_packets */ /* * Send flow control messages to the upper layer */ static int sync_con_queue(ng_hci_unit_p unit, ng_hci_unit_con_p con, int completed) { hook_p hook = NULL; struct ng_mesg *msg = NULL; ng_hci_sync_con_queue_ep *state = NULL; int error; hook = (con->link_type != NG_HCI_LINK_SCO)? unit->acl : unit->sco; if (hook == NULL || NG_HOOK_NOT_VALID(hook)) return (ENOTCONN); NG_MKMESSAGE(msg, NGM_HCI_COOKIE, NGM_HCI_SYNC_CON_QUEUE, sizeof(*state), M_NOWAIT); if (msg == NULL) return (ENOMEM); state = (ng_hci_sync_con_queue_ep *)(msg->data); state->con_handle = con->con_handle; state->completed = completed; NG_SEND_MSG_HOOK(error, unit->node, msg, hook, 0); return (error); } /* sync_con_queue */ /* le meta event */ /* Inquiry result event */ static int le_advertizing_report(ng_hci_unit_p unit, struct mbuf *event) { ng_hci_le_advertising_report_ep *ep = NULL; ng_hci_neighbor_p n = NULL; bdaddr_t bdaddr; int error = 0; u_int8_t event_type; u_int8_t addr_type; NG_HCI_M_PULLUP(event, sizeof(*ep)); if (event == NULL) return (ENOBUFS); ep = mtod(event, ng_hci_le_advertising_report_ep *); m_adj(event, sizeof(*ep)); for (; ep->num_reports > 0; ep->num_reports --) { /* Get remote unit address */ NG_HCI_M_PULLUP(event, sizeof(u_int8_t)); event_type = *mtod(event, u_int8_t *); m_adj(event, sizeof(u_int8_t)); NG_HCI_M_PULLUP(event, sizeof(u_int8_t)); addr_type = *mtod(event, u_int8_t *); m_adj(event, sizeof(u_int8_t)); m_copydata(event, 0, sizeof(bdaddr), (caddr_t) &bdaddr); m_adj(event, sizeof(bdaddr)); /* Lookup entry in the cache */ n = ng_hci_get_neighbor(unit, &bdaddr, (addr_type) ? NG_HCI_LINK_LE_RANDOM:NG_HCI_LINK_LE_PUBLIC); if (n == NULL) { /* Create new entry */ n = ng_hci_new_neighbor(unit); if (n == NULL) { error = ENOMEM; break; } bcopy(&bdaddr, &n->bdaddr, sizeof(n->bdaddr)); n->addrtype = (addr_type)? NG_HCI_LINK_LE_RANDOM : NG_HCI_LINK_LE_PUBLIC; } else getmicrotime(&n->updated); -#if 0 { /* * TODO: Make these information * Available from userland. */ u_int8_t length_data; - char *rssi; - - NG_HCI_M_PULLUP(event, sizeof(u_int8_t)); + event = m_pullup(event, sizeof(u_int8_t)); + if(event == NULL){ + NG_HCI_WARN("%s: Event datasize Pullup Failed\n", __func__); + goto out; + } length_data = *mtod(event, u_int8_t *); m_adj(event, sizeof(u_int8_t)); + n->extinq_size = (length_data < NG_HCI_EXTINQ_MAX)? + length_data : NG_HCI_EXTINQ_MAX; + /*Advertizement data*/ - NG_HCI_M_PULLUP(event, length_data); - m_adj(event, length_data); - NG_HCI_M_PULLUP(event, sizeof(char )); + event = m_pullup(event, n->extinq_size); + if(event == NULL){ + NG_HCI_WARN("%s: Event data pullup Failed\n", __func__); + goto out; + } + m_copydata(event, 0, n->extinq_size, n->extinq_data); + m_adj(event, n->extinq_size); + event = m_pullup(event, sizeof(char )); /*Get RSSI*/ - rssi = mtod(event, char *); + if(event == NULL){ + NG_HCI_WARN("%s: Event rssi pull up Failed\n", __func__); + + goto out; + } + n->page_scan_mode = *mtod(event, char *); m_adj(event, sizeof(u_int8_t)); } -#endif } + out: NG_FREE_M(event); return (error); } /* inquiry_result */ static int le_connection_complete(ng_hci_unit_p unit, struct mbuf *event) { int error = 0; ng_hci_le_connection_complete_ep *ep = NULL; ng_hci_unit_con_p con = NULL; int link_type; uint8_t uclass[3] = {0,0,0};//dummy uclass NG_HCI_M_PULLUP(event, sizeof(*ep)); if (event == NULL) return (ENOBUFS); ep = mtod(event, ng_hci_le_connection_complete_ep *); link_type = (ep->address_type)? NG_HCI_LINK_LE_RANDOM : NG_HCI_LINK_LE_PUBLIC; /* * Find the first connection descriptor that matches the following: * * 1) con->link_type == link_type * 2) con->state == NG_HCI_CON_W4_CONN_COMPLETE * 3) con->bdaddr == ep->address */ LIST_FOREACH(con, &unit->con_list, next) if (con->link_type == link_type && con->state == NG_HCI_CON_W4_CONN_COMPLETE && bcmp(&con->bdaddr, &ep->address, sizeof(bdaddr_t)) == 0) break; /* * Two possible cases: * * 1) We have found connection descriptor. That means upper layer has * requested this connection via LP_CON_REQ message. In this case * connection must have timeout set. If ng_hci_con_untimeout() fails * then timeout message already went into node's queue. In this case * ignore Connection_Complete event and let timeout deal with it. * * 2) We do not have connection descriptor. That means upper layer * nas not requested this connection , (less likely) we gave up * on this connection (timeout) or as node act as slave role. * The most likely scenario is that * we have received LE_Create_Connection command * from the RAW hook */ if (con == NULL) { if (ep->status != 0) goto out; con = ng_hci_new_con(unit, link_type); if (con == NULL) { error = ENOMEM; goto out; } con->state = NG_HCI_CON_W4_LP_CON_RSP; ng_hci_con_timeout(con); bcopy(&ep->address, &con->bdaddr, sizeof(con->bdaddr)); error = ng_hci_lp_con_ind(con, uclass); if (error != 0) { ng_hci_con_untimeout(con); ng_hci_free_con(con); } } else if ((error = ng_hci_con_untimeout(con)) != 0) goto out; /* * Update connection descriptor and send notification * to the upper layers. */ con->con_handle = NG_HCI_CON_HANDLE(le16toh(ep->handle)); con->encryption_mode = NG_HCI_ENCRYPTION_MODE_NONE; ng_hci_lp_con_cfm(con, ep->status); /* Adjust connection state */ if (ep->status != 0) ng_hci_free_con(con); else { con->state = NG_HCI_CON_OPEN; /* * Change link policy for the ACL connections. Enable all * supported link modes. Enable Role switch as well if * device supports it. */ } out: NG_FREE_M(event); return (error); } static int le_connection_update(ng_hci_unit_p unit, struct mbuf *event) { int error = 0; /*TBD*/ NG_FREE_M(event); return error; } static int le_event(ng_hci_unit_p unit, struct mbuf *event) { int error = 0; ng_hci_le_ep *lep; NG_HCI_M_PULLUP(event, sizeof(*lep)); if(event ==NULL){ return ENOBUFS; } lep = mtod(event, ng_hci_le_ep *); m_adj(event, sizeof(*lep)); switch(lep->subevent_code){ case NG_HCI_LEEV_CON_COMPL: le_connection_complete(unit, event); break; case NG_HCI_LEEV_ADVREP: le_advertizing_report(unit, event); break; case NG_HCI_LEEV_CON_UPDATE_COMPL: le_connection_update(unit, event); break; case NG_HCI_LEEV_READ_REMOTE_FEATURES_COMPL: //TBD /*FALLTHROUGH*/ case NG_HCI_LEEV_LONG_TERM_KEY_REQUEST: //TBD /*FALLTHROUGH*/ default: NG_FREE_M(event); } return error; } /* Inquiry result event */ static int inquiry_result(ng_hci_unit_p unit, struct mbuf *event) { ng_hci_inquiry_result_ep *ep = NULL; ng_hci_neighbor_p n = NULL; bdaddr_t bdaddr; int error = 0; NG_HCI_M_PULLUP(event, sizeof(*ep)); if (event == NULL) return (ENOBUFS); ep = mtod(event, ng_hci_inquiry_result_ep *); m_adj(event, sizeof(*ep)); for (; ep->num_responses > 0; ep->num_responses --) { /* Get remote unit address */ m_copydata(event, 0, sizeof(bdaddr), (caddr_t) &bdaddr); m_adj(event, sizeof(bdaddr)); /* Lookup entry in the cache */ n = ng_hci_get_neighbor(unit, &bdaddr, NG_HCI_LINK_ACL); if (n == NULL) { /* Create new entry */ n = ng_hci_new_neighbor(unit); if (n == NULL) { error = ENOMEM; break; } } else getmicrotime(&n->updated); bcopy(&bdaddr, &n->bdaddr, sizeof(n->bdaddr)); n->addrtype = NG_HCI_LINK_ACL; /* XXX call m_pullup here? */ n->page_scan_rep_mode = *mtod(event, u_int8_t *); m_adj(event, sizeof(u_int8_t)); /* page_scan_period_mode */ m_adj(event, sizeof(u_int8_t)); n->page_scan_mode = *mtod(event, u_int8_t *); m_adj(event, sizeof(u_int8_t)); /* class */ m_adj(event, NG_HCI_CLASS_SIZE); /* clock offset */ m_copydata(event, 0, sizeof(n->clock_offset), (caddr_t) &n->clock_offset); n->clock_offset = le16toh(n->clock_offset); } NG_FREE_M(event); return (error); } /* inquiry_result */ /* Connection complete event */ static int con_compl(ng_hci_unit_p unit, struct mbuf *event) { ng_hci_con_compl_ep *ep = NULL; ng_hci_unit_con_p con = NULL; int error = 0; NG_HCI_M_PULLUP(event, sizeof(*ep)); if (event == NULL) return (ENOBUFS); ep = mtod(event, ng_hci_con_compl_ep *); /* * Find the first connection descriptor that matches the following: * * 1) con->link_type == ep->link_type * 2) con->state == NG_HCI_CON_W4_CONN_COMPLETE * 3) con->bdaddr == ep->bdaddr */ LIST_FOREACH(con, &unit->con_list, next) if (con->link_type == ep->link_type && con->state == NG_HCI_CON_W4_CONN_COMPLETE && bcmp(&con->bdaddr, &ep->bdaddr, sizeof(bdaddr_t)) == 0) break; /* * Two possible cases: * * 1) We have found connection descriptor. That means upper layer has * requested this connection via LP_CON_REQ message. In this case * connection must have timeout set. If ng_hci_con_untimeout() fails * then timeout message already went into node's queue. In this case * ignore Connection_Complete event and let timeout deal with it. * * 2) We do not have connection descriptor. That means upper layer * nas not requested this connection or (less likely) we gave up * on this connection (timeout). The most likely scenario is that * we have received Create_Connection/Add_SCO_Connection command * from the RAW hook */ if (con == NULL) { if (ep->status != 0) goto out; con = ng_hci_new_con(unit, ep->link_type); if (con == NULL) { error = ENOMEM; goto out; } bcopy(&ep->bdaddr, &con->bdaddr, sizeof(con->bdaddr)); } else if ((error = ng_hci_con_untimeout(con)) != 0) goto out; /* * Update connection descriptor and send notification * to the upper layers. */ con->con_handle = NG_HCI_CON_HANDLE(le16toh(ep->con_handle)); con->encryption_mode = ep->encryption_mode; ng_hci_lp_con_cfm(con, ep->status); /* Adjust connection state */ if (ep->status != 0) ng_hci_free_con(con); else { con->state = NG_HCI_CON_OPEN; /* * Change link policy for the ACL connections. Enable all * supported link modes. Enable Role switch as well if * device supports it. */ if (ep->link_type == NG_HCI_LINK_ACL) { struct __link_policy { ng_hci_cmd_pkt_t hdr; ng_hci_write_link_policy_settings_cp cp; } __attribute__ ((packed)) *lp; struct mbuf *m; MGETHDR(m, M_NOWAIT, MT_DATA); if (m != NULL) { m->m_pkthdr.len = m->m_len = sizeof(*lp); lp = mtod(m, struct __link_policy *); lp->hdr.type = NG_HCI_CMD_PKT; lp->hdr.opcode = htole16(NG_HCI_OPCODE( NG_HCI_OGF_LINK_POLICY, NG_HCI_OCF_WRITE_LINK_POLICY_SETTINGS)); lp->hdr.length = sizeof(lp->cp); lp->cp.con_handle = ep->con_handle; lp->cp.settings = 0; if ((unit->features[0] & NG_HCI_LMP_SWITCH) && unit->role_switch) lp->cp.settings |= 0x1; if (unit->features[0] & NG_HCI_LMP_HOLD_MODE) lp->cp.settings |= 0x2; if (unit->features[0] & NG_HCI_LMP_SNIFF_MODE) lp->cp.settings |= 0x4; if (unit->features[1] & NG_HCI_LMP_PARK_MODE) lp->cp.settings |= 0x8; lp->cp.settings &= unit->link_policy_mask; lp->cp.settings = htole16(lp->cp.settings); NG_BT_MBUFQ_ENQUEUE(&unit->cmdq, m); if (!(unit->state & NG_HCI_UNIT_COMMAND_PENDING)) ng_hci_send_command(unit); } } } out: NG_FREE_M(event); return (error); } /* con_compl */ /* Connection request event */ static int con_req(ng_hci_unit_p unit, struct mbuf *event) { ng_hci_con_req_ep *ep = NULL; ng_hci_unit_con_p con = NULL; int error = 0; NG_HCI_M_PULLUP(event, sizeof(*ep)); if (event == NULL) return (ENOBUFS); ep = mtod(event, ng_hci_con_req_ep *); /* * Find the first connection descriptor that matches the following: * * 1) con->link_type == ep->link_type * * 2) con->state == NG_HCI_CON_W4_LP_CON_RSP || * con->state == NG_HCI_CON_W4_CONN_COMPL * * 3) con->bdaddr == ep->bdaddr * * Possible cases: * * 1) We do not have connection descriptor. This is simple. Create * new fresh connection descriptor and send notification to the * appropriate upstream hook (based on link_type). * * 2) We found connection handle. This is more complicated. * * 2.1) ACL links * * Since only one ACL link can exist between each pair of * units then we have a race. Our upper layer has requested * an ACL connection to the remote unit, but we did not send * command yet. At the same time the remote unit has requested * an ACL connection from us. In this case we will ignore * Connection_Request event. This probably will cause connect * failure on both units. * * 2.2) SCO links * * The spec on page 45 says : * * "The master can support up to three SCO links to the same * slave or to different slaves. A slave can support up to * three SCO links from the same master, or two SCO links if * the links originate from different masters." * * The only problem is how to handle multiple SCO links between * matster and slave. For now we will assume that multiple SCO * links MUST be opened one after another. */ LIST_FOREACH(con, &unit->con_list, next) if (con->link_type == ep->link_type && (con->state == NG_HCI_CON_W4_LP_CON_RSP || con->state == NG_HCI_CON_W4_CONN_COMPLETE) && bcmp(&con->bdaddr, &ep->bdaddr, sizeof(bdaddr_t)) == 0) break; if (con == NULL) { con = ng_hci_new_con(unit, ep->link_type); if (con != NULL) { bcopy(&ep->bdaddr, &con->bdaddr, sizeof(con->bdaddr)); con->state = NG_HCI_CON_W4_LP_CON_RSP; ng_hci_con_timeout(con); error = ng_hci_lp_con_ind(con, ep->uclass); if (error != 0) { ng_hci_con_untimeout(con); ng_hci_free_con(con); } } else error = ENOMEM; } NG_FREE_M(event); return (error); } /* con_req */ /* Disconnect complete event */ static int discon_compl(ng_hci_unit_p unit, struct mbuf *event) { ng_hci_discon_compl_ep *ep = NULL; ng_hci_unit_con_p con = NULL; int error = 0; u_int16_t h; NG_HCI_M_PULLUP(event, sizeof(*ep)); if (event == NULL) return (ENOBUFS); ep = mtod(event, ng_hci_discon_compl_ep *); /* * XXX * Do we have to send notification if ep->status != 0? * For now we will send notification for both ACL and SCO connections * ONLY if ep->status == 0. */ if (ep->status == 0) { h = NG_HCI_CON_HANDLE(le16toh(ep->con_handle)); con = ng_hci_con_by_handle(unit, h); if (con != NULL) { error = ng_hci_lp_discon_ind(con, ep->reason); /* Remove all timeouts (if any) */ if (con->flags & NG_HCI_CON_TIMEOUT_PENDING) ng_hci_con_untimeout(con); ng_hci_free_con(con); } else { NG_HCI_ALERT( "%s: %s - invalid connection handle=%d\n", __func__, NG_NODE_NAME(unit->node), h); error = ENOENT; } } NG_FREE_M(event); return (error); } /* discon_compl */ /* Encryption change event */ static int encryption_change(ng_hci_unit_p unit, struct mbuf *event) { ng_hci_encryption_change_ep *ep = NULL; ng_hci_unit_con_p con = NULL; int error = 0; u_int16_t h; NG_HCI_M_PULLUP(event, sizeof(*ep)); if (event == NULL) return (ENOBUFS); ep = mtod(event, ng_hci_encryption_change_ep *); h = NG_HCI_CON_HANDLE(le16toh(ep->con_handle)); con = ng_hci_con_by_handle(unit, h); if (ep->status == 0) { if (con == NULL) { NG_HCI_ALERT( "%s: %s - invalid connection handle=%d\n", __func__, NG_NODE_NAME(unit->node), h); error = ENOENT; } else if (con->link_type == NG_HCI_LINK_SCO) { NG_HCI_ALERT( "%s: %s - invalid link type=%d\n", __func__, NG_NODE_NAME(unit->node), con->link_type); error = EINVAL; } else if (ep->encryption_enable) /* XXX is that true? */ con->encryption_mode = NG_HCI_ENCRYPTION_MODE_P2P; else con->encryption_mode = NG_HCI_ENCRYPTION_MODE_NONE; } else NG_HCI_ERR( "%s: %s - failed to change encryption mode, status=%d\n", __func__, NG_NODE_NAME(unit->node), ep->status); /*Anyway, propagete encryption status to upper layer*/ ng_hci_lp_enc_change(con, con->encryption_mode); NG_FREE_M(event); return (error); } /* encryption_change */ /* Read remote feature complete event */ static int read_remote_features_compl(ng_hci_unit_p unit, struct mbuf *event) { ng_hci_read_remote_features_compl_ep *ep = NULL; ng_hci_unit_con_p con = NULL; ng_hci_neighbor_p n = NULL; u_int16_t h; int error = 0; NG_HCI_M_PULLUP(event, sizeof(*ep)); if (event == NULL) return (ENOBUFS); ep = mtod(event, ng_hci_read_remote_features_compl_ep *); if (ep->status == 0) { /* Check if we have this connection handle */ h = NG_HCI_CON_HANDLE(le16toh(ep->con_handle)); con = ng_hci_con_by_handle(unit, h); if (con == NULL) { NG_HCI_ALERT( "%s: %s - invalid connection handle=%d\n", __func__, NG_NODE_NAME(unit->node), h); error = ENOENT; goto out; } /* Update cache entry */ n = ng_hci_get_neighbor(unit, &con->bdaddr, NG_HCI_LINK_ACL); if (n == NULL) { n = ng_hci_new_neighbor(unit); if (n == NULL) { error = ENOMEM; goto out; } bcopy(&con->bdaddr, &n->bdaddr, sizeof(n->bdaddr)); n->addrtype = NG_HCI_LINK_ACL; } else getmicrotime(&n->updated); bcopy(ep->features, n->features, sizeof(n->features)); } else NG_HCI_ERR( "%s: %s - failed to read remote unit features, status=%d\n", __func__, NG_NODE_NAME(unit->node), ep->status); out: NG_FREE_M(event); return (error); } /* read_remote_features_compl */ /* QoS setup complete event */ static int qos_setup_compl(ng_hci_unit_p unit, struct mbuf *event) { ng_hci_qos_setup_compl_ep *ep = NULL; ng_hci_unit_con_p con = NULL; u_int16_t h; int error = 0; NG_HCI_M_PULLUP(event, sizeof(*ep)); if (event == NULL) return (ENOBUFS); ep = mtod(event, ng_hci_qos_setup_compl_ep *); /* Check if we have this connection handle */ h = NG_HCI_CON_HANDLE(le16toh(ep->con_handle)); con = ng_hci_con_by_handle(unit, h); if (con == NULL) { NG_HCI_ALERT( "%s: %s - invalid connection handle=%d\n", __func__, NG_NODE_NAME(unit->node), h); error = ENOENT; } else if (con->link_type != NG_HCI_LINK_ACL) { NG_HCI_ALERT( "%s: %s - invalid link type=%d, handle=%d\n", __func__, NG_NODE_NAME(unit->node), con->link_type, h); error = EINVAL; } else if (con->state != NG_HCI_CON_OPEN) { NG_HCI_ALERT( "%s: %s - invalid connection state=%d, handle=%d\n", __func__, NG_NODE_NAME(unit->node), con->state, h); error = EINVAL; } else /* Notify upper layer */ error = ng_hci_lp_qos_cfm(con, ep->status); NG_FREE_M(event); return (error); } /* qos_setup_compl */ /* Hardware error event */ static int hardware_error(ng_hci_unit_p unit, struct mbuf *event) { NG_HCI_ALERT( "%s: %s - hardware error %#x\n", __func__, NG_NODE_NAME(unit->node), *mtod(event, u_int8_t *)); NG_FREE_M(event); return (0); } /* hardware_error */ /* Role change event */ static int role_change(ng_hci_unit_p unit, struct mbuf *event) { ng_hci_role_change_ep *ep = NULL; ng_hci_unit_con_p con = NULL; NG_HCI_M_PULLUP(event, sizeof(*ep)); if (event == NULL) return (ENOBUFS); ep = mtod(event, ng_hci_role_change_ep *); if (ep->status == 0) { /* XXX shoud we also change "role" for SCO connections? */ con = ng_hci_con_by_bdaddr(unit, &ep->bdaddr, NG_HCI_LINK_ACL); if (con != NULL) con->role = ep->role; else NG_HCI_ALERT( "%s: %s - ACL connection does not exist, bdaddr=%x:%x:%x:%x:%x:%x\n", __func__, NG_NODE_NAME(unit->node), ep->bdaddr.b[5], ep->bdaddr.b[4], ep->bdaddr.b[3], ep->bdaddr.b[2], ep->bdaddr.b[1], ep->bdaddr.b[0]); } else NG_HCI_ERR( "%s: %s - failed to change role, status=%d, bdaddr=%x:%x:%x:%x:%x:%x\n", __func__, NG_NODE_NAME(unit->node), ep->status, ep->bdaddr.b[5], ep->bdaddr.b[4], ep->bdaddr.b[3], ep->bdaddr.b[2], ep->bdaddr.b[1], ep->bdaddr.b[0]); NG_FREE_M(event); return (0); } /* role_change */ /* Number of completed packets event */ static int num_compl_pkts(ng_hci_unit_p unit, struct mbuf *event) { ng_hci_num_compl_pkts_ep *ep = NULL; ng_hci_unit_con_p con = NULL; u_int16_t h, p; NG_HCI_M_PULLUP(event, sizeof(*ep)); if (event == NULL) return (ENOBUFS); ep = mtod(event, ng_hci_num_compl_pkts_ep *); m_adj(event, sizeof(*ep)); for (; ep->num_con_handles > 0; ep->num_con_handles --) { /* Get connection handle */ m_copydata(event, 0, sizeof(h), (caddr_t) &h); m_adj(event, sizeof(h)); h = NG_HCI_CON_HANDLE(le16toh(h)); /* Get number of completed packets */ m_copydata(event, 0, sizeof(p), (caddr_t) &p); m_adj(event, sizeof(p)); p = le16toh(p); /* Check if we have this connection handle */ con = ng_hci_con_by_handle(unit, h); if (con != NULL) { con->pending -= p; if (con->pending < 0) { NG_HCI_WARN( "%s: %s - pending packet counter is out of sync! " \ "handle=%d, pending=%d, ncp=%d\n", __func__, NG_NODE_NAME(unit->node), con->con_handle, con->pending, p); con->pending = 0; } /* Update buffer descriptor */ if (con->link_type != NG_HCI_LINK_SCO) NG_HCI_BUFF_ACL_FREE(unit->buffer, p); else NG_HCI_BUFF_SCO_FREE(unit->buffer, p); } else NG_HCI_ALERT( "%s: %s - invalid connection handle=%d\n", __func__, NG_NODE_NAME(unit->node), h); } NG_FREE_M(event); /* Send more data */ ng_hci_send_data(unit); return (0); } /* num_compl_pkts */ /* Mode change event */ static int mode_change(ng_hci_unit_p unit, struct mbuf *event) { ng_hci_mode_change_ep *ep = NULL; ng_hci_unit_con_p con = NULL; int error = 0; NG_HCI_M_PULLUP(event, sizeof(*ep)); if (event == NULL) return (ENOBUFS); ep = mtod(event, ng_hci_mode_change_ep *); if (ep->status == 0) { u_int16_t h = NG_HCI_CON_HANDLE(le16toh(ep->con_handle)); con = ng_hci_con_by_handle(unit, h); if (con == NULL) { NG_HCI_ALERT( "%s: %s - invalid connection handle=%d\n", __func__, NG_NODE_NAME(unit->node), h); error = ENOENT; } else if (con->link_type != NG_HCI_LINK_ACL) { NG_HCI_ALERT( "%s: %s - invalid link type=%d\n", __func__, NG_NODE_NAME(unit->node), con->link_type); error = EINVAL; } else con->mode = ep->unit_mode; } else NG_HCI_ERR( "%s: %s - failed to change mode, status=%d\n", __func__, NG_NODE_NAME(unit->node), ep->status); NG_FREE_M(event); return (error); } /* mode_change */ /* Data buffer overflow event */ static int data_buffer_overflow(ng_hci_unit_p unit, struct mbuf *event) { NG_HCI_ALERT( "%s: %s - %s data buffer overflow\n", __func__, NG_NODE_NAME(unit->node), (*mtod(event, u_int8_t *) == NG_HCI_LINK_ACL)? "ACL" : "SCO"); NG_FREE_M(event); return (0); } /* data_buffer_overflow */ /* Read clock offset complete event */ static int read_clock_offset_compl(ng_hci_unit_p unit, struct mbuf *event) { ng_hci_read_clock_offset_compl_ep *ep = NULL; ng_hci_unit_con_p con = NULL; ng_hci_neighbor_p n = NULL; int error = 0; NG_HCI_M_PULLUP(event, sizeof(*ep)); if (event == NULL) return (ENOBUFS); ep = mtod(event, ng_hci_read_clock_offset_compl_ep *); if (ep->status == 0) { u_int16_t h = NG_HCI_CON_HANDLE(le16toh(ep->con_handle)); con = ng_hci_con_by_handle(unit, h); if (con == NULL) { NG_HCI_ALERT( "%s: %s - invalid connection handle=%d\n", __func__, NG_NODE_NAME(unit->node), h); error = ENOENT; goto out; } /* Update cache entry */ n = ng_hci_get_neighbor(unit, &con->bdaddr, NG_HCI_LINK_ACL); if (n == NULL) { n = ng_hci_new_neighbor(unit); if (n == NULL) { error = ENOMEM; goto out; } bcopy(&con->bdaddr, &n->bdaddr, sizeof(n->bdaddr)); n->addrtype = NG_HCI_LINK_ACL; } else getmicrotime(&n->updated); n->clock_offset = le16toh(ep->clock_offset); } else NG_HCI_ERR( "%s: %s - failed to Read Remote Clock Offset, status=%d\n", __func__, NG_NODE_NAME(unit->node), ep->status); out: NG_FREE_M(event); return (error); } /* read_clock_offset_compl */ /* QoS violation event */ static int qos_violation(ng_hci_unit_p unit, struct mbuf *event) { ng_hci_qos_violation_ep *ep = NULL; ng_hci_unit_con_p con = NULL; u_int16_t h; int error = 0; NG_HCI_M_PULLUP(event, sizeof(*ep)); if (event == NULL) return (ENOBUFS); ep = mtod(event, ng_hci_qos_violation_ep *); /* Check if we have this connection handle */ h = NG_HCI_CON_HANDLE(le16toh(ep->con_handle)); con = ng_hci_con_by_handle(unit, h); if (con == NULL) { NG_HCI_ALERT( "%s: %s - invalid connection handle=%d\n", __func__, NG_NODE_NAME(unit->node), h); error = ENOENT; } else if (con->link_type != NG_HCI_LINK_ACL) { NG_HCI_ALERT( "%s: %s - invalid link type=%d\n", __func__, NG_NODE_NAME(unit->node), con->link_type); error = EINVAL; } else if (con->state != NG_HCI_CON_OPEN) { NG_HCI_ALERT( "%s: %s - invalid connection state=%d, handle=%d\n", __func__, NG_NODE_NAME(unit->node), con->state, h); error = EINVAL; } else /* Notify upper layer */ error = ng_hci_lp_qos_ind(con); NG_FREE_M(event); return (error); } /* qos_violation */ /* Page scan mode change event */ static int page_scan_mode_change(ng_hci_unit_p unit, struct mbuf *event) { ng_hci_page_scan_mode_change_ep *ep = NULL; ng_hci_neighbor_p n = NULL; int error = 0; NG_HCI_M_PULLUP(event, sizeof(*ep)); if (event == NULL) return (ENOBUFS); ep = mtod(event, ng_hci_page_scan_mode_change_ep *); /* Update cache entry */ n = ng_hci_get_neighbor(unit, &ep->bdaddr, NG_HCI_LINK_ACL); if (n == NULL) { n = ng_hci_new_neighbor(unit); if (n == NULL) { error = ENOMEM; goto out; } bcopy(&ep->bdaddr, &n->bdaddr, sizeof(n->bdaddr)); n->addrtype = NG_HCI_LINK_ACL; } else getmicrotime(&n->updated); n->page_scan_mode = ep->page_scan_mode; out: NG_FREE_M(event); return (error); } /* page_scan_mode_change */ /* Page scan repetition mode change event */ static int page_scan_rep_mode_change(ng_hci_unit_p unit, struct mbuf *event) { ng_hci_page_scan_rep_mode_change_ep *ep = NULL; ng_hci_neighbor_p n = NULL; int error = 0; NG_HCI_M_PULLUP(event, sizeof(*ep)); if (event == NULL) return (ENOBUFS); ep = mtod(event, ng_hci_page_scan_rep_mode_change_ep *); /* Update cache entry */ n = ng_hci_get_neighbor(unit, &ep->bdaddr, NG_HCI_LINK_ACL); if (n == NULL) { n = ng_hci_new_neighbor(unit); if (n == NULL) { error = ENOMEM; goto out; } bcopy(&ep->bdaddr, &n->bdaddr, sizeof(n->bdaddr)); n->addrtype = NG_HCI_LINK_ACL; } else getmicrotime(&n->updated); n->page_scan_rep_mode = ep->page_scan_rep_mode; out: NG_FREE_M(event); return (error); } /* page_scan_rep_mode_change */ Index: head/sys/netgraph/bluetooth/hci/ng_hci_main.c =================================================================== --- head/sys/netgraph/bluetooth/hci/ng_hci_main.c (revision 317505) +++ head/sys/netgraph/bluetooth/hci/ng_hci_main.c (revision 317506) @@ -1,1083 +1,1102 @@ /* * ng_hci_main.c */ /*- * Copyright (c) Maksim Yevmenkin * 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: ng_hci_main.c,v 1.2 2003/03/18 00:09:36 max Exp $ * $FreeBSD$ */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /****************************************************************************** ****************************************************************************** ** This node implements Bluetooth Host Controller Interface (HCI) ****************************************************************************** ******************************************************************************/ /* MALLOC define */ #ifdef NG_SEPARATE_MALLOC MALLOC_DEFINE(M_NETGRAPH_HCI, "netgraph_hci", "Netgraph Bluetooth HCI node"); #else #define M_NETGRAPH_HCI M_NETGRAPH #endif /* NG_SEPARATE_MALLOC */ /* Netgraph node methods */ static ng_constructor_t ng_hci_constructor; static ng_shutdown_t ng_hci_shutdown; static ng_newhook_t ng_hci_newhook; static ng_connect_t ng_hci_connect; static ng_disconnect_t ng_hci_disconnect; static ng_rcvmsg_t ng_hci_default_rcvmsg; static ng_rcvmsg_t ng_hci_upper_rcvmsg; static ng_rcvdata_t ng_hci_drv_rcvdata; static ng_rcvdata_t ng_hci_acl_rcvdata; static ng_rcvdata_t ng_hci_sco_rcvdata; static ng_rcvdata_t ng_hci_raw_rcvdata; /* Netgraph node type descriptor */ static struct ng_type typestruct = { .version = NG_ABI_VERSION, .name = NG_HCI_NODE_TYPE, .constructor = ng_hci_constructor, .rcvmsg = ng_hci_default_rcvmsg, .shutdown = ng_hci_shutdown, .newhook = ng_hci_newhook, .connect = ng_hci_connect, .rcvdata = ng_hci_drv_rcvdata, .disconnect = ng_hci_disconnect, .cmdlist = ng_hci_cmdlist, }; NETGRAPH_INIT(hci, &typestruct); MODULE_VERSION(ng_hci, NG_BLUETOOTH_VERSION); MODULE_DEPEND(ng_hci, ng_bluetooth, NG_BLUETOOTH_VERSION, NG_BLUETOOTH_VERSION, NG_BLUETOOTH_VERSION); +static int ng_hci_linktype_to_addrtype(int linktype); +static int ng_hci_linktype_to_addrtype(int linktype) +{ + switch(linktype){ + case NG_HCI_LINK_LE_PUBLIC: + return BDADDR_LE_PUBLIC; + case NG_HCI_LINK_LE_RANDOM: + return BDADDR_LE_RANDOM; + case NG_HCI_LINK_ACL: + /*FALLTHROUGH*/ + default: + return BDADDR_BREDR; + } + return BDADDR_BREDR; +} /***************************************************************************** ***************************************************************************** ** Netgraph methods implementation ***************************************************************************** *****************************************************************************/ /* * Create new instance of HCI node (new unit) */ static int ng_hci_constructor(node_p node) { ng_hci_unit_p unit = NULL; unit = malloc(sizeof(*unit), M_NETGRAPH_HCI, M_WAITOK | M_ZERO); unit->node = node; unit->debug = NG_HCI_WARN_LEVEL; unit->link_policy_mask = 0xffff; /* Enable all supported modes */ unit->packet_mask = 0xffff; /* Enable all packet types */ unit->role_switch = 1; /* Enable role switch (if device supports it) */ /* * Set default buffer info * * One HCI command * One ACL packet with max. size of 17 bytes (1 DM1 packet) * One SCO packet with max. size of 10 bytes (1 HV1 packet) */ NG_HCI_BUFF_CMD_SET(unit->buffer, 1); NG_HCI_BUFF_ACL_SET(unit->buffer, 1, 17, 1); NG_HCI_BUFF_SCO_SET(unit->buffer, 1, 10, 1); /* Init command queue & command timeout handler */ ng_callout_init(&unit->cmd_timo); NG_BT_MBUFQ_INIT(&unit->cmdq, NG_HCI_CMD_QUEUE_LEN); /* Init lists */ LIST_INIT(&unit->con_list); LIST_INIT(&unit->neighbors); /* * This node has to be a WRITER because both data and messages * can change node state. */ NG_NODE_FORCE_WRITER(node); NG_NODE_SET_PRIVATE(node, unit); return (0); } /* ng_hci_constructor */ /* * Destroy the node */ static int ng_hci_shutdown(node_p node) { ng_hci_unit_p unit = (ng_hci_unit_p) NG_NODE_PRIVATE(node); NG_NODE_SET_PRIVATE(node, NULL); NG_NODE_UNREF(node); unit->node = NULL; ng_hci_unit_clean(unit, 0x16 /* Connection terminated by local host */); NG_BT_MBUFQ_DESTROY(&unit->cmdq); bzero(unit, sizeof(*unit)); free(unit, M_NETGRAPH_HCI); return (0); } /* ng_hci_shutdown */ /* * Give our OK for a hook to be added. Unit driver is connected to the driver * (NG_HCI_HOOK_DRV) hook. Upper layer protocols are connected to appropriate * (NG_HCI_HOOK_ACL or NG_HCI_HOOK_SCO) hooks. */ static int ng_hci_newhook(node_p node, hook_p hook, char const *name) { ng_hci_unit_p unit = (ng_hci_unit_p) NG_NODE_PRIVATE(node); hook_p *h = NULL; if (strcmp(name, NG_HCI_HOOK_DRV) == 0) h = &unit->drv; else if (strcmp(name, NG_HCI_HOOK_ACL) == 0) h = &unit->acl; else if (strcmp(name, NG_HCI_HOOK_SCO) == 0) h = &unit->sco; else if (strcmp(name, NG_HCI_HOOK_RAW) == 0) h = &unit->raw; else return (EINVAL); if (*h != NULL) return (EISCONN); *h = hook; return (0); } /* ng_hci_newhook */ /* * Give our final OK to connect hook */ static int ng_hci_connect(hook_p hook) { ng_hci_unit_p unit = (ng_hci_unit_p) NG_NODE_PRIVATE(NG_HOOK_NODE(hook)); if (hook != unit->drv) { if (hook == unit->acl) { NG_HOOK_SET_RCVMSG(hook, ng_hci_upper_rcvmsg); NG_HOOK_SET_RCVDATA(hook, ng_hci_acl_rcvdata); } else if (hook == unit->sco) { NG_HOOK_SET_RCVMSG(hook, ng_hci_upper_rcvmsg); NG_HOOK_SET_RCVDATA(hook, ng_hci_sco_rcvdata); } else NG_HOOK_SET_RCVDATA(hook, ng_hci_raw_rcvdata); /* Send delayed notification to the upper layers */ if (hook != unit->raw) ng_send_fn(unit->node, hook, ng_hci_node_is_up, NULL,0); } else unit->state |= NG_HCI_UNIT_CONNECTED; return (0); } /* ng_hci_connect */ /* * Disconnect the hook */ static int ng_hci_disconnect(hook_p hook) { ng_hci_unit_p unit = (ng_hci_unit_p) NG_NODE_PRIVATE(NG_HOOK_NODE(hook)); if (hook == unit->acl) unit->acl = NULL; else if (hook == unit->sco) unit->sco = NULL; else if (hook == unit->raw) unit->raw = NULL; else if (hook == unit->drv) { unit->drv = NULL; /* Connection terminated by local host */ ng_hci_unit_clean(unit, 0x16); unit->state &= ~(NG_HCI_UNIT_CONNECTED|NG_HCI_UNIT_INITED); } else return (EINVAL); /* Shutdown when all hooks are disconnected */ if ((NG_NODE_NUMHOOKS(NG_HOOK_NODE(hook)) == 0) && (NG_NODE_IS_VALID(NG_HOOK_NODE(hook)))) ng_rmnode_self(NG_HOOK_NODE(hook)); return (0); } /* ng_hci_disconnect */ /* * Default control message processing routine. Control message could be: * * 1) GENERIC Netgraph messages * * 2) Control message directed to the node itself. */ static int ng_hci_default_rcvmsg(node_p node, item_p item, hook_p lasthook) { ng_hci_unit_p unit = (ng_hci_unit_p) NG_NODE_PRIVATE(node); struct ng_mesg *msg = NULL, *rsp = NULL; int error = 0; NGI_GET_MSG(item, msg); switch (msg->header.typecookie) { case NGM_GENERIC_COOKIE: switch (msg->header.cmd) { case NGM_TEXT_STATUS: { int cmd_avail, acl_total, acl_avail, acl_size, sco_total, sco_avail, sco_size; NG_MKRESPONSE(rsp, msg, NG_TEXTRESPONSE, M_NOWAIT); if (rsp == NULL) { error = ENOMEM; break; } NG_HCI_BUFF_CMD_GET(unit->buffer, cmd_avail); NG_HCI_BUFF_ACL_AVAIL(unit->buffer, acl_avail); NG_HCI_BUFF_ACL_TOTAL(unit->buffer, acl_total); NG_HCI_BUFF_ACL_SIZE(unit->buffer, acl_size); NG_HCI_BUFF_SCO_AVAIL(unit->buffer, sco_avail); NG_HCI_BUFF_SCO_TOTAL(unit->buffer, sco_total); NG_HCI_BUFF_SCO_SIZE(unit->buffer, sco_size); snprintf(rsp->data, NG_TEXTRESPONSE, "bdaddr %x:%x:%x:%x:%x:%x\n" \ "Hooks %s %s %s %s\n" \ "State %#x\n" \ "Queue cmd:%d\n" \ "Buffer cmd:%d,acl:%d,%d,%d,sco:%d,%d,%d", unit->bdaddr.b[5], unit->bdaddr.b[4], unit->bdaddr.b[3], unit->bdaddr.b[2], unit->bdaddr.b[1], unit->bdaddr.b[0], (unit->drv != NULL)? NG_HCI_HOOK_DRV : "", (unit->acl != NULL)? NG_HCI_HOOK_ACL : "", (unit->sco != NULL)? NG_HCI_HOOK_SCO : "", (unit->raw != NULL)? NG_HCI_HOOK_RAW : "", unit->state, NG_BT_MBUFQ_LEN(&unit->cmdq), cmd_avail, acl_avail, acl_total, acl_size, sco_avail, sco_total, sco_size); } break; default: error = EINVAL; break; } break; case NGM_HCI_COOKIE: switch (msg->header.cmd) { /* Get current node state */ case NGM_HCI_NODE_GET_STATE: NG_MKRESPONSE(rsp, msg, sizeof(unit->state), M_NOWAIT); if (rsp == NULL) { error = ENOMEM; break; } *((ng_hci_node_state_ep *)(rsp->data)) = unit->state; break; /* Turn INITED bit - node initialized */ case NGM_HCI_NODE_INIT: if (bcmp(&unit->bdaddr, NG_HCI_BDADDR_ANY, sizeof(bdaddr_t)) == 0) { error = ENXIO; break; } unit->state |= NG_HCI_UNIT_INITED; ng_hci_node_is_up(unit->node, unit->acl, NULL, 0); ng_hci_node_is_up(unit->node, unit->sco, NULL, 0); break; /* Get node debug level */ case NGM_HCI_NODE_GET_DEBUG: NG_MKRESPONSE(rsp, msg, sizeof(unit->debug), M_NOWAIT); if (rsp == NULL) { error = ENOMEM; break; } *((ng_hci_node_debug_ep *)(rsp->data)) = unit->debug; break; /* Set node debug level */ case NGM_HCI_NODE_SET_DEBUG: if (msg->header.arglen != sizeof(ng_hci_node_debug_ep)){ error = EMSGSIZE; break; } unit->debug = *((ng_hci_node_debug_ep *)(msg->data)); break; /* Get buffer info */ case NGM_HCI_NODE_GET_BUFFER: { ng_hci_node_buffer_ep *ep = NULL; NG_MKRESPONSE(rsp, msg, sizeof(ng_hci_node_buffer_ep), M_NOWAIT); if (rsp == NULL) { error = ENOMEM; break; } ep = (ng_hci_node_buffer_ep *)(rsp->data); NG_HCI_BUFF_CMD_GET(unit->buffer, ep->cmd_free); NG_HCI_BUFF_ACL_AVAIL(unit->buffer, ep->acl_free); NG_HCI_BUFF_ACL_TOTAL(unit->buffer, ep->acl_pkts); NG_HCI_BUFF_ACL_SIZE(unit->buffer, ep->acl_size); NG_HCI_BUFF_SCO_AVAIL(unit->buffer, ep->sco_free); NG_HCI_BUFF_SCO_TOTAL(unit->buffer, ep->sco_pkts); NG_HCI_BUFF_SCO_SIZE(unit->buffer, ep->sco_size); } break; /* Get BDADDR */ case NGM_HCI_NODE_GET_BDADDR: NG_MKRESPONSE(rsp, msg, sizeof(bdaddr_t), M_NOWAIT); if (rsp == NULL) { error = ENOMEM; break; } bcopy(&unit->bdaddr, rsp->data, sizeof(bdaddr_t)); break; /* Get features */ case NGM_HCI_NODE_GET_FEATURES: NG_MKRESPONSE(rsp,msg,sizeof(unit->features),M_NOWAIT); if (rsp == NULL) { error = ENOMEM; break; } bcopy(&unit->features,rsp->data,sizeof(unit->features)); break; /* Get stat */ case NGM_HCI_NODE_GET_STAT: NG_MKRESPONSE(rsp, msg, sizeof(unit->stat), M_NOWAIT); if (rsp == NULL) { error = ENOMEM; break; } bcopy(&unit->stat, rsp->data, sizeof(unit->stat)); break; /* Reset stat */ case NGM_HCI_NODE_RESET_STAT: NG_HCI_STAT_RESET(unit->stat); break; /* Clean up neighbors list */ case NGM_HCI_NODE_FLUSH_NEIGHBOR_CACHE: ng_hci_flush_neighbor_cache(unit); break; /* Get neighbor cache entries */ case NGM_HCI_NODE_GET_NEIGHBOR_CACHE: { ng_hci_neighbor_p n = NULL; ng_hci_node_get_neighbor_cache_ep *e1 = NULL; ng_hci_node_neighbor_cache_entry_ep *e2 = NULL; int s = 0; /* Look for the fresh entries in the cache */ for (n = LIST_FIRST(&unit->neighbors); n != NULL; ) { ng_hci_neighbor_p nn = LIST_NEXT(n, next); if (ng_hci_neighbor_stale(n)) ng_hci_free_neighbor(n); else s ++; n = nn; } if (s > NG_HCI_MAX_NEIGHBOR_NUM) s = NG_HCI_MAX_NEIGHBOR_NUM; /* Prepare response */ NG_MKRESPONSE(rsp, msg, sizeof(*e1) + s * sizeof(*e2), M_NOWAIT); if (rsp == NULL) { error = ENOMEM; break; } e1 = (ng_hci_node_get_neighbor_cache_ep *)(rsp->data); e2 = (ng_hci_node_neighbor_cache_entry_ep *)(e1 + 1); e1->num_entries = s; LIST_FOREACH(n, &unit->neighbors, next) { e2->page_scan_rep_mode = n->page_scan_rep_mode; e2->page_scan_mode = n->page_scan_mode; e2->clock_offset = n->clock_offset; + e2->addrtype = + ng_hci_linktype_to_addrtype(n->addrtype); + e2->extinq_size = n->extinq_size; bcopy(&n->bdaddr, &e2->bdaddr, sizeof(e2->bdaddr)); bcopy(&n->features, &e2->features, sizeof(e2->features)); - + bcopy(&n->extinq_data, &e2->extinq_data, + n->extinq_size); e2 ++; if (--s <= 0) break; } } break; /* Get connection list */ case NGM_HCI_NODE_GET_CON_LIST: { ng_hci_unit_con_p c = NULL; ng_hci_node_con_list_ep *e1 = NULL; ng_hci_node_con_ep *e2 = NULL; int s = 0; /* Count number of connections in the list */ LIST_FOREACH(c, &unit->con_list, next) s ++; if (s > NG_HCI_MAX_CON_NUM) s = NG_HCI_MAX_CON_NUM; /* Prepare response */ NG_MKRESPONSE(rsp, msg, sizeof(*e1) + s * sizeof(*e2), M_NOWAIT); if (rsp == NULL) { error = ENOMEM; break; } e1 = (ng_hci_node_con_list_ep *)(rsp->data); e2 = (ng_hci_node_con_ep *)(e1 + 1); e1->num_connections = s; LIST_FOREACH(c, &unit->con_list, next) { e2->link_type = c->link_type; e2->encryption_mode= c->encryption_mode; e2->mode = c->mode; e2->role = c->role; e2->state = c->state; e2->pending = c->pending; e2->queue_len = NG_BT_ITEMQ_LEN(&c->conq); e2->con_handle = c->con_handle; bcopy(&c->bdaddr, &e2->bdaddr, sizeof(e2->bdaddr)); e2 ++; if (--s <= 0) break; } } break; /* Get link policy settings mask */ case NGM_HCI_NODE_GET_LINK_POLICY_SETTINGS_MASK: NG_MKRESPONSE(rsp, msg, sizeof(unit->link_policy_mask), M_NOWAIT); if (rsp == NULL) { error = ENOMEM; break; } *((ng_hci_node_link_policy_mask_ep *)(rsp->data)) = unit->link_policy_mask; break; /* Set link policy settings mask */ case NGM_HCI_NODE_SET_LINK_POLICY_SETTINGS_MASK: if (msg->header.arglen != sizeof(ng_hci_node_link_policy_mask_ep)) { error = EMSGSIZE; break; } unit->link_policy_mask = *((ng_hci_node_link_policy_mask_ep *) (msg->data)); break; /* Get packet mask */ case NGM_HCI_NODE_GET_PACKET_MASK: NG_MKRESPONSE(rsp, msg, sizeof(unit->packet_mask), M_NOWAIT); if (rsp == NULL) { error = ENOMEM; break; } *((ng_hci_node_packet_mask_ep *)(rsp->data)) = unit->packet_mask; break; /* Set packet mask */ case NGM_HCI_NODE_SET_PACKET_MASK: if (msg->header.arglen != sizeof(ng_hci_node_packet_mask_ep)) { error = EMSGSIZE; break; } unit->packet_mask = *((ng_hci_node_packet_mask_ep *)(msg->data)); break; /* Get role switch */ case NGM_HCI_NODE_GET_ROLE_SWITCH: NG_MKRESPONSE(rsp, msg, sizeof(unit->role_switch), M_NOWAIT); if (rsp == NULL) { error = ENOMEM; break; } *((ng_hci_node_role_switch_ep *)(rsp->data)) = unit->role_switch; break; /* Set role switch */ case NGM_HCI_NODE_SET_ROLE_SWITCH: if (msg->header.arglen != sizeof(ng_hci_node_role_switch_ep)) { error = EMSGSIZE; break; } unit->role_switch = *((ng_hci_node_role_switch_ep *)(msg->data)); break; default: error = EINVAL; break; } break; default: error = EINVAL; break; } /* NG_RESPOND_MSG should take care of "item" and "rsp" */ NG_RESPOND_MSG(error, node, item, rsp); NG_FREE_MSG(msg); return (error); } /* ng_hci_default_rcvmsg */ /* * Process control message from upstream hooks (ACL and SCO). * Handle LP_xxx messages here, give everything else to default routine. */ static int ng_hci_upper_rcvmsg(node_p node, item_p item, hook_p lasthook) { ng_hci_unit_p unit = (ng_hci_unit_p) NG_NODE_PRIVATE(node); int error = 0; switch (NGI_MSG(item)->header.typecookie) { case NGM_HCI_COOKIE: switch (NGI_MSG(item)->header.cmd) { case NGM_HCI_LP_CON_REQ: error = ng_hci_lp_con_req(unit, item, lasthook); break; case NGM_HCI_LP_DISCON_REQ: /* XXX not defined by specs */ error = ng_hci_lp_discon_req(unit, item, lasthook); break; case NGM_HCI_LP_CON_RSP: error = ng_hci_lp_con_rsp(unit, item, lasthook); break; case NGM_HCI_LP_QOS_REQ: error = ng_hci_lp_qos_req(unit, item, lasthook); break; default: error = ng_hci_default_rcvmsg(node, item, lasthook); break; } break; default: error = ng_hci_default_rcvmsg(node, item, lasthook); break; } return (error); } /* ng_hci_upper_rcvmsg */ /* * Process data packet from the driver hook. * We expect HCI events, ACL or SCO data packets. */ static int ng_hci_drv_rcvdata(hook_p hook, item_p item) { ng_hci_unit_p unit = (ng_hci_unit_p) NG_NODE_PRIVATE(NG_HOOK_NODE(hook)); struct mbuf *m = NULL; int error = 0; /* Process packet */ m = NGI_M(item); /* item still has mbuf, just peeking */ m->m_flags |= M_PROTO1; /* mark as incoming packet */ NG_HCI_STAT_BYTES_RECV(unit->stat, m->m_pkthdr.len); /* Give copy packet to RAW hook */ ng_hci_mtap(unit, m); /* * XXX XXX XXX * Lower layer drivers MUST NOT send mbuf chain with empty mbuf at * the beginning of the chain. HCI layer WILL NOT call m_pullup() here. */ switch (*mtod(m, u_int8_t *)) { case NG_HCI_ACL_DATA_PKT: NG_HCI_STAT_ACL_RECV(unit->stat); if ((unit->state & NG_HCI_UNIT_READY) != NG_HCI_UNIT_READY || unit->acl == NULL || NG_HOOK_NOT_VALID(unit->acl)) { NG_HCI_WARN( "%s: %s - could not forward HCI ACL data packet, state=%#x, hook=%p\n", __func__, NG_NODE_NAME(unit->node), unit->state, unit->acl); NG_FREE_ITEM(item); } else NG_FWD_ITEM_HOOK(error, item, unit->acl); break; case NG_HCI_SCO_DATA_PKT: NG_HCI_STAT_SCO_RECV(unit->stat); if ((unit->state & NG_HCI_UNIT_READY) != NG_HCI_UNIT_READY || unit->sco == NULL || NG_HOOK_NOT_VALID(unit->sco)) { NG_HCI_INFO( "%s: %s - could not forward HCI SCO data packet, state=%#x, hook=%p\n", __func__, NG_NODE_NAME(unit->node), unit->state, unit->sco); NG_FREE_ITEM(item); } else NG_FWD_ITEM_HOOK(error, item, unit->sco); break; case NG_HCI_EVENT_PKT: NG_HCI_STAT_EVNT_RECV(unit->stat); /* Detach mbuf, discard item and process event */ NGI_GET_M(item, m); NG_FREE_ITEM(item); error = ng_hci_process_event(unit, m); break; default: NG_HCI_ALERT( "%s: %s - got unknown HCI packet type=%#x\n", __func__, NG_NODE_NAME(unit->node), *mtod(m, u_int8_t *)); NG_FREE_ITEM(item); error = EINVAL; break; } return (error); } /* ng_hci_drv_rcvdata */ /* * Process data packet from ACL upstream hook. * We expect valid HCI ACL data packets. */ static int ng_hci_acl_rcvdata(hook_p hook, item_p item) { ng_hci_unit_p unit = (ng_hci_unit_p) NG_NODE_PRIVATE(NG_HOOK_NODE(hook)); struct mbuf *m = NULL; ng_hci_unit_con_p con = NULL; u_int16_t con_handle; int size, error = 0; NG_HCI_BUFF_ACL_SIZE(unit->buffer, size); /* Check packet */ NGI_GET_M(item, m); if (*mtod(m, u_int8_t *) != NG_HCI_ACL_DATA_PKT) { NG_HCI_ALERT( "%s: %s - invalid HCI data packet type=%#x\n", __func__, NG_NODE_NAME(unit->node), *mtod(m, u_int8_t *)); error = EINVAL; goto drop; } if (m->m_pkthdr.len < sizeof(ng_hci_acldata_pkt_t) || m->m_pkthdr.len > sizeof(ng_hci_acldata_pkt_t) + size) { NG_HCI_ALERT( "%s: %s - invalid HCI ACL data packet, len=%d, mtu=%d\n", __func__, NG_NODE_NAME(unit->node), m->m_pkthdr.len, size); error = EMSGSIZE; goto drop; } NG_HCI_M_PULLUP(m, sizeof(ng_hci_acldata_pkt_t)); if (m == NULL) { error = ENOBUFS; goto drop; } con_handle = NG_HCI_CON_HANDLE(le16toh( mtod(m, ng_hci_acldata_pkt_t *)->con_handle)); size = le16toh(mtod(m, ng_hci_acldata_pkt_t *)->length); if (m->m_pkthdr.len != sizeof(ng_hci_acldata_pkt_t) + size) { NG_HCI_ALERT( "%s: %s - invalid HCI ACL data packet size, len=%d, length=%d\n", __func__, NG_NODE_NAME(unit->node), m->m_pkthdr.len, size); error = EMSGSIZE; goto drop; } /* Queue packet */ con = ng_hci_con_by_handle(unit, con_handle); if (con == NULL) { NG_HCI_ERR( "%s: %s - unexpected HCI ACL data packet. Connection does not exists, " \ "con_handle=%d\n", __func__, NG_NODE_NAME(unit->node), con_handle); error = ENOENT; goto drop; } if (con->link_type == NG_HCI_LINK_SCO) { NG_HCI_ERR( "%s: %s - unexpected HCI ACL data packet. Not ACL link, con_handle=%d, " \ "link_type=%d\n", __func__, NG_NODE_NAME(unit->node), con_handle, con->link_type); error = EINVAL; goto drop; } if (con->state != NG_HCI_CON_OPEN) { NG_HCI_ERR( "%s: %s - unexpected HCI ACL data packet. Invalid connection state=%d, " \ "con_handle=%d\n", __func__, NG_NODE_NAME(unit->node), con->state, con_handle); error = EHOSTDOWN; goto drop; } if (NG_BT_ITEMQ_FULL(&con->conq)) { NG_HCI_ALERT( "%s: %s - dropping HCI ACL data packet, con_handle=%d, len=%d, queue_len=%d\n", __func__, NG_NODE_NAME(unit->node), con_handle, m->m_pkthdr.len, NG_BT_ITEMQ_LEN(&con->conq)); NG_BT_ITEMQ_DROP(&con->conq); error = ENOBUFS; goto drop; } /* Queue item and schedule data transfer */ NGI_M(item) = m; NG_BT_ITEMQ_ENQUEUE(&con->conq, item); item = NULL; m = NULL; ng_hci_send_data(unit); drop: if (item != NULL) NG_FREE_ITEM(item); NG_FREE_M(m); /* NG_FREE_M() checks for m != NULL */ return (error); } /* ng_hci_acl_rcvdata */ /* * Process data packet from SCO upstream hook. * We expect valid HCI SCO data packets */ static int ng_hci_sco_rcvdata(hook_p hook, item_p item) { ng_hci_unit_p unit = (ng_hci_unit_p) NG_NODE_PRIVATE(NG_HOOK_NODE(hook)); struct mbuf *m = NULL; ng_hci_unit_con_p con = NULL; u_int16_t con_handle; int size, error = 0; NG_HCI_BUFF_SCO_SIZE(unit->buffer, size); /* Check packet */ NGI_GET_M(item, m); if (*mtod(m, u_int8_t *) != NG_HCI_SCO_DATA_PKT) { NG_HCI_ALERT( "%s: %s - invalid HCI data packet type=%#x\n", __func__, NG_NODE_NAME(unit->node), *mtod(m, u_int8_t *)); error = EINVAL; goto drop; } if (m->m_pkthdr.len < sizeof(ng_hci_scodata_pkt_t) || m->m_pkthdr.len > sizeof(ng_hci_scodata_pkt_t) + size) { NG_HCI_ALERT( "%s: %s - invalid HCI SCO data packet, len=%d, mtu=%d\n", __func__, NG_NODE_NAME(unit->node), m->m_pkthdr.len, size); error = EMSGSIZE; goto drop; } NG_HCI_M_PULLUP(m, sizeof(ng_hci_scodata_pkt_t)); if (m == NULL) { error = ENOBUFS; goto drop; } con_handle = NG_HCI_CON_HANDLE(le16toh( mtod(m, ng_hci_scodata_pkt_t *)->con_handle)); size = mtod(m, ng_hci_scodata_pkt_t *)->length; if (m->m_pkthdr.len != sizeof(ng_hci_scodata_pkt_t) + size) { NG_HCI_ALERT( "%s: %s - invalid HCI SCO data packet size, len=%d, length=%d\n", __func__, NG_NODE_NAME(unit->node), m->m_pkthdr.len, size); error = EMSGSIZE; goto drop; } /* Queue packet */ con = ng_hci_con_by_handle(unit, con_handle); if (con == NULL) { NG_HCI_ERR( "%s: %s - unexpected HCI SCO data packet. Connection does not exists, " \ "con_handle=%d\n", __func__, NG_NODE_NAME(unit->node), con_handle); error = ENOENT; goto drop; } if (con->link_type != NG_HCI_LINK_SCO) { NG_HCI_ERR( "%s: %s - unexpected HCI SCO data packet. Not SCO link, con_handle=%d, " \ "link_type=%d\n", __func__, NG_NODE_NAME(unit->node), con_handle, con->link_type); error = EINVAL; goto drop; } if (con->state != NG_HCI_CON_OPEN) { NG_HCI_ERR( "%s: %s - unexpected HCI SCO data packet. Invalid connection state=%d, " \ "con_handle=%d\n", __func__, NG_NODE_NAME(unit->node), con->state, con_handle); error = EHOSTDOWN; goto drop; } if (NG_BT_ITEMQ_FULL(&con->conq)) { NG_HCI_ALERT( "%s: %s - dropping HCI SCO data packet, con_handle=%d, len=%d, queue_len=%d\n", __func__, NG_NODE_NAME(unit->node), con_handle, m->m_pkthdr.len, NG_BT_ITEMQ_LEN(&con->conq)); NG_BT_ITEMQ_DROP(&con->conq); error = ENOBUFS; goto drop; } /* Queue item and schedule data transfer */ NGI_M(item) = m; NG_BT_ITEMQ_ENQUEUE(&con->conq, item); item = NULL; m = NULL; ng_hci_send_data(unit); drop: if (item != NULL) NG_FREE_ITEM(item); NG_FREE_M(m); /* NG_FREE_M() checks for m != NULL */ return (error); } /* ng_hci_sco_rcvdata */ /* * Process data packet from uptream RAW hook. * We expect valid HCI command packets. */ static int ng_hci_raw_rcvdata(hook_p hook, item_p item) { ng_hci_unit_p unit = (ng_hci_unit_p) NG_NODE_PRIVATE(NG_HOOK_NODE(hook)); struct mbuf *m = NULL; int error = 0; NGI_GET_M(item, m); NG_FREE_ITEM(item); /* Check packet */ if (*mtod(m, u_int8_t *) != NG_HCI_CMD_PKT) { NG_HCI_ALERT( "%s: %s - invalid HCI command packet type=%#x\n", __func__, NG_NODE_NAME(unit->node), *mtod(m, u_int8_t *)); error = EINVAL; goto drop; } if (m->m_pkthdr.len < sizeof(ng_hci_cmd_pkt_t)) { NG_HCI_ALERT( "%s: %s - invalid HCI command packet len=%d\n", __func__, NG_NODE_NAME(unit->node), m->m_pkthdr.len); error = EMSGSIZE; goto drop; } NG_HCI_M_PULLUP(m, sizeof(ng_hci_cmd_pkt_t)); if (m == NULL) { error = ENOBUFS; goto drop; } if (m->m_pkthdr.len != mtod(m, ng_hci_cmd_pkt_t *)->length + sizeof(ng_hci_cmd_pkt_t)) { NG_HCI_ALERT( "%s: %s - invalid HCI command packet size, len=%d, length=%d\n", __func__, NG_NODE_NAME(unit->node), m->m_pkthdr.len, mtod(m, ng_hci_cmd_pkt_t *)->length); error = EMSGSIZE; goto drop; } if (mtod(m, ng_hci_cmd_pkt_t *)->opcode == 0) { NG_HCI_ALERT( "%s: %s - invalid HCI command opcode\n", __func__, NG_NODE_NAME(unit->node)); error = EINVAL; goto drop; } if (NG_BT_MBUFQ_FULL(&unit->cmdq)) { NG_HCI_ALERT( "%s: %s - dropping HCI command packet, len=%d, queue_len=%d\n", __func__, NG_NODE_NAME(unit->node), m->m_pkthdr.len, NG_BT_MBUFQ_LEN(&unit->cmdq)); NG_BT_MBUFQ_DROP(&unit->cmdq); error = ENOBUFS; goto drop; } /* Queue and send command */ NG_BT_MBUFQ_ENQUEUE(&unit->cmdq, m); m = NULL; if (!(unit->state & NG_HCI_UNIT_COMMAND_PENDING)) error = ng_hci_send_command(unit); drop: NG_FREE_M(m); /* NG_FREE_M() checks for m != NULL */ return (error); } /* ng_hci_raw_rcvdata */ Index: head/sys/netgraph/bluetooth/hci/ng_hci_var.h =================================================================== --- head/sys/netgraph/bluetooth/hci/ng_hci_var.h (revision 317505) +++ head/sys/netgraph/bluetooth/hci/ng_hci_var.h (revision 317506) @@ -1,219 +1,220 @@ /* * ng_hci_var.h */ /*- * Copyright (c) 2001 Maksim Yevmenkin * 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: ng_hci_var.h,v 1.3 2003/04/26 22:35:21 max Exp $ * $FreeBSD$ */ #ifndef _NETGRAPH_HCI_VAR_H_ #define _NETGRAPH_HCI_VAR_H_ /* MALLOC decalation */ #ifdef NG_SEPARATE_MALLOC MALLOC_DECLARE(M_NETGRAPH_HCI); #else #define M_NETGRAPH_HCI M_NETGRAPH #endif /* NG_SEPARATE_MALLOC */ /* Debug */ #define NG_HCI_ALERT if (unit->debug >= NG_HCI_ALERT_LEVEL) printf #define NG_HCI_ERR if (unit->debug >= NG_HCI_ERR_LEVEL) printf #define NG_HCI_WARN if (unit->debug >= NG_HCI_WARN_LEVEL) printf #define NG_HCI_INFO if (unit->debug >= NG_HCI_INFO_LEVEL) printf /* Wrapper around m_pullup */ #define NG_HCI_M_PULLUP(m, s) \ do { \ if ((m)->m_len < (s)) \ (m) = m_pullup((m), (s)); \ if ((m) == NULL) \ NG_HCI_ALERT("%s: %s - m_pullup(%zd) failed\n", \ __func__, NG_NODE_NAME(unit->node), (s)); \ } while (0) /* * Unit hardware buffer descriptor */ typedef struct ng_hci_unit_buff { u_int8_t cmd_free; /* space available (cmds) */ u_int8_t sco_size; /* max. size of one packet */ u_int16_t sco_pkts; /* size of buffer (packets) */ u_int16_t sco_free; /* space available (packets)*/ u_int16_t acl_size; /* max. size of one packet */ u_int16_t acl_pkts; /* size of buffer (packets) */ u_int16_t acl_free; /* space available (packets)*/ } ng_hci_unit_buff_t; /* * These macro's must be used everywhere in the code. So if extra locking * is required later, it can be added without much troubles. */ #define NG_HCI_BUFF_CMD_SET(b, v) (b).cmd_free = (v) #define NG_HCI_BUFF_CMD_GET(b, v) (v) = (b).cmd_free #define NG_HCI_BUFF_CMD_USE(b, v) (b).cmd_free -= (v) #define NG_HCI_BUFF_ACL_USE(b, v) (b).acl_free -= (v) #define NG_HCI_BUFF_ACL_FREE(b, v) \ do { \ (b).acl_free += (v); \ if ((b).acl_free > (b).acl_pkts) \ (b).acl_free = (b).acl_pkts; \ } while (0) #define NG_HCI_BUFF_ACL_AVAIL(b, v) (v) = (b).acl_free #define NG_HCI_BUFF_ACL_TOTAL(b, v) (v) = (b).acl_pkts #define NG_HCI_BUFF_ACL_SIZE(b, v) (v) = (b).acl_size #define NG_HCI_BUFF_ACL_SET(b, n, s, f) \ do { \ (b).acl_free = (f); \ (b).acl_size = (s); \ (b).acl_pkts = (n); \ } while (0) #define NG_HCI_BUFF_SCO_USE(b, v) (b).sco_free -= (v) #define NG_HCI_BUFF_SCO_FREE(b, v) \ do { \ (b).sco_free += (v); \ if ((b).sco_free > (b).sco_pkts) \ (b).sco_free = (b).sco_pkts; \ } while (0) #define NG_HCI_BUFF_SCO_AVAIL(b, v) (v) = (b).sco_free #define NG_HCI_BUFF_SCO_TOTAL(b, v) (v) = (b).sco_pkts #define NG_HCI_BUFF_SCO_SIZE(b, v) (v) = (b).sco_size #define NG_HCI_BUFF_SCO_SET(b, n, s, f) \ do { \ (b).sco_free = (f); \ (b).sco_size = (s); \ (b).sco_pkts = (n); \ } while (0) /* * Unit (Node private) */ struct ng_hci_unit_con; struct ng_hci_neighbor; typedef struct ng_hci_unit { node_p node; /* node ptr */ ng_hci_node_debug_ep debug; /* debug level */ ng_hci_node_state_ep state; /* unit state */ bdaddr_t bdaddr; /* unit address */ u_int8_t features[NG_HCI_FEATURES_SIZE]; /* LMP features */ ng_hci_node_link_policy_mask_ep link_policy_mask; /* link policy mask */ ng_hci_node_packet_mask_ep packet_mask; /* packet mask */ ng_hci_node_role_switch_ep role_switch; /* role switch */ ng_hci_node_stat_ep stat; /* statistic */ #define NG_HCI_STAT_CMD_SENT(s) (s).cmd_sent ++ #define NG_HCI_STAT_EVNT_RECV(s) (s).evnt_recv ++ #define NG_HCI_STAT_ACL_SENT(s, n) (s).acl_sent += (n) #define NG_HCI_STAT_ACL_RECV(s) (s).acl_recv ++ #define NG_HCI_STAT_SCO_SENT(s, n) (s).sco_sent += (n) #define NG_HCI_STAT_SCO_RECV(s) (s).sco_recv ++ #define NG_HCI_STAT_BYTES_SENT(s, b) (s).bytes_sent += (b) #define NG_HCI_STAT_BYTES_RECV(s, b) (s).bytes_recv += (b) #define NG_HCI_STAT_RESET(s) bzero(&(s), sizeof((s))) ng_hci_unit_buff_t buffer; /* buffer info */ struct callout cmd_timo; /* command timeout */ ng_bt_mbufq_t cmdq; /* command queue */ #define NG_HCI_CMD_QUEUE_LEN 12 /* max. size of cmd q */ hook_p drv; /* driver hook */ hook_p acl; /* upstream hook */ hook_p sco; /* upstream hook */ hook_p raw; /* upstream hook */ LIST_HEAD(, ng_hci_unit_con) con_list; /* connections */ LIST_HEAD(, ng_hci_neighbor) neighbors; /* unit neighbors */ } ng_hci_unit_t; typedef ng_hci_unit_t * ng_hci_unit_p; /* * Unit connection descriptor */ typedef struct ng_hci_unit_con { ng_hci_unit_p unit; /* pointer back */ u_int16_t state; /* con. state */ u_int16_t flags; /* con. flags */ #define NG_HCI_CON_TIMEOUT_PENDING (1 << 0) #define NG_HCI_CON_NOTIFY_ACL (1 << 1) #define NG_HCI_CON_NOTIFY_SCO (1 << 2) bdaddr_t bdaddr; /* remote address */ u_int16_t con_handle; /* con. handle */ 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 */ struct callout con_timo; /* con. timeout */ int pending; /* # of data pkts */ ng_bt_itemq_t conq; /* con. queue */ LIST_ENTRY(ng_hci_unit_con) next; /* next */ } ng_hci_unit_con_t; typedef ng_hci_unit_con_t * ng_hci_unit_con_p; /* * Unit's neighbor descriptor. * Neighbor is a remote unit that responded to our inquiry. */ typedef struct ng_hci_neighbor { struct timeval updated; /* entry was updated */ bdaddr_t bdaddr; /* address */ u_int8_t features[NG_HCI_FEATURES_SIZE]; /* LMP features */ u_int8_t addrtype; /*Address Type*/ u_int8_t page_scan_rep_mode; /* PS rep. mode */ u_int8_t page_scan_mode; /* page scan mode */ u_int16_t clock_offset; /* clock offset */ - + uint8_t extinq_size; + uint8_t extinq_data[NG_HCI_EXTINQ_MAX]; LIST_ENTRY(ng_hci_neighbor) next; } ng_hci_neighbor_t; typedef ng_hci_neighbor_t * ng_hci_neighbor_p; #endif /* ndef _NETGRAPH_HCI_VAR_H_ */ Index: head/sys/netgraph/bluetooth/include/ng_bluetooth.h =================================================================== --- head/sys/netgraph/bluetooth/include/ng_bluetooth.h (revision 317505) +++ head/sys/netgraph/bluetooth/include/ng_bluetooth.h (revision 317506) @@ -1,228 +1,232 @@ /* * bluetooth.h */ /*- * Copyright (c) 2001-2002 Maksim Yevmenkin * 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: ng_bluetooth.h,v 1.4 2003/04/26 22:32:34 max Exp $ * $FreeBSD$ */ #ifndef _NETGRAPH_BLUETOOTH_H_ #define _NETGRAPH_BLUETOOTH_H_ #include /* * 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); SYSCTL_DECL(_net_bluetooth_sco); #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 { STAILQ_HEAD(, ng_item) queue; /* actually items 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) \ do { \ STAILQ_INIT(&(q)->queue); \ (q)->len = 0; \ (q)->maxlen = (_maxlen); \ (q)->drops = 0; \ } while (0) #define NG_BT_ITEMQ_DESTROY(q) \ do { \ NG_BT_ITEMQ_DRAIN((q)); \ } while (0) #define NG_BT_ITEMQ_FIRST(q) STAILQ_FIRST(&(q)->queue) #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 { \ STAILQ_INSERT_TAIL(&(q)->queue, (i), el_next); \ (q)->len ++; \ } while (0) #define NG_BT_ITEMQ_DEQUEUE(q, i) \ do { \ (i) = STAILQ_FIRST(&(q)->queue); \ if ((i) != NULL) { \ STAILQ_REMOVE_HEAD(&(q)->queue, el_next); \ (q)->len --; \ } \ } while (0) #define NG_BT_ITEMQ_PREPEND(q, i) \ do { \ STAILQ_INSERT_HEAD(&(q)->queue, (i), el_next); \ (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); u_int32_t bluetooth_sco_rtx_timeout (void); +#define BDADDR_BREDR 0 +#define BDADDR_LE_PUBLIC 1 +#define BDADDR_LE_RANDOM 2 + #endif /* _NETGRAPH_BLUETOOTH_H_ */ Index: head/sys/netgraph/bluetooth/include/ng_btsocket.h =================================================================== --- head/sys/netgraph/bluetooth/include/ng_btsocket.h (revision 317505) +++ head/sys/netgraph/bluetooth/include/ng_btsocket.h (revision 317506) @@ -1,380 +1,376 @@ /* * ng_btsocket.h */ /*- * Copyright (c) 2001-2002 Maksim Yevmenkin * 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: ng_btsocket.h,v 1.8 2003/04/26 22:32:10 max Exp $ * $FreeBSD$ */ #ifndef _NETGRAPH_BTSOCKET_H_ #define _NETGRAPH_BTSOCKET_H_ /* * 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 */ #define BLUETOOTH_PROTO_SCO 137 /* SCO 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) /* Get list of HCI node names */ struct ng_btsocket_hci_raw_node_list_names { u_int32_t num_names; struct nodeinfo *names; }; #define SIOC_HCI_RAW_NODE_LIST_NAMES \ _IOWR('b', NGM_HCI_NODE_LIST_NAMES, \ struct ng_btsocket_hci_raw_node_list_names) /* * XXX FIXME: probably does not belong here * Bluetooth version of struct sockaddr for SCO sockets (SEQPACKET) */ struct sockaddr_sco { u_char sco_len; /* total length */ u_char sco_family; /* address family */ bdaddr_t sco_bdaddr; /* address */ }; /* SCO socket options */ #define SOL_SCO 0x0209 /* socket options level */ #define SO_SCO_MTU 1 /* get sockets mtu */ #define SO_SCO_CONNINFO 2 /* get HCI connection handle */ /* * XXX FIXME: probably does not belong here * Bluetooth version of struct sockaddr for L2CAP sockets (RAW and SEQPACKET) */ struct sockaddr_l2cap_compat { 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 */ }; -#define BDADDR_BREDR 0 -#define BDADDR_LE_PUBLIC 1 -#define BDADDR_LE_RANDOM 2 - 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 */ u_int16_t l2cap_cid; /*cid*/ u_int8_t l2cap_bdaddr_type; /*address type*/ }; #if !defined(L2CAP_SOCKET_CHECKED) && !defined(_KERNEL) #warning "Make sure new member of socket address initialized" #endif /* 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 */ #define SO_L2CAP_ENCRYPTED 6 /* get/set whether wait for encryptin on connect */ /* * 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" #define NG_BTSOCKET_SCO_NODE_TYPE "btsock_sco" /* * 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_ */ Index: head/sys/netgraph/bluetooth/include/ng_hci.h =================================================================== --- head/sys/netgraph/bluetooth/include/ng_hci.h (revision 317505) +++ head/sys/netgraph/bluetooth/include/ng_hci.h (revision 317506) @@ -1,1989 +1,1993 @@ /* * ng_hci.h */ /*- * Copyright (c) 2001 Maksim Yevmenkin * 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: ng_hci.h,v 1.2 2003/03/18 00:09:37 max Exp $ * $FreeBSD$ */ /* * 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_LE_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 */ #define NG_HCI_COMMANDS_SIZE 64 /*Command list BMP size*/ +#define NG_HCI_EXTINQ_MAX 240 /**/ /* 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 */ #define NG_HCI_LINK_LE_PUBLIC 0x02 /* LE Public*/ #define NG_HCI_LINK_LE_RANDOM 0x03 /* LE Random*/ /* 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; /*Encryption Change event*/ #define NGM_HCI_LP_ENC_CHG 10 /* HCI->Upper*/ typedef struct { uint16_t con_handle; uint8_t status; uint8_t link_type; }ng_hci_lp_enc_change_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 */ + uint8_t addrtype; + uint8_t extinq_size; /* MAX 240*/ + uint8_t extinq_data[NG_HCI_EXTINQ_MAX]; } 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; #define NGM_HCI_NODE_LIST_NAMES 200 /* HCI -> User */ /************************************************************************** ************************************************************************** ** 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_EVENT_MASK_DEFAULT 0x1fffffffffff #define NG_HCI_EVENT_MASK_LE 0x2000000000000000 #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; /*0x003b-0x003e commands are depricated v2.0 or later*/ #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; #define NG_HCI_OCF_READ_LE_HOST_SUPPORTED 0x6c typedef struct { u_int8_t status; /* 0x00 - success */ u_int8_t le_supported_host ;/* LE host supported?*/ u_int8_t simultaneous_le_host; /* BR/LE simulateneous? */ } __attribute__ ((packed)) ng_hci_read_le_host_supported_rp; #define NG_HCI_OCF_WRITE_LE_HOST_SUPPORTED 0x6d typedef struct { u_int8_t le_supported_host; /* LE host supported?*/ u_int8_t simultaneous_le_host; /* LE host supported?*/ } __attribute__ ((packed)) ng_hci_write_le_host_supported_cp; typedef ng_hci_status_rp ng_hci_write_le_host_supported_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_COMMANDS 0x0002 typedef struct { u_int8_t status; /* 0x00 - success */ u_int8_t features[NG_HCI_COMMANDS_SIZE]; /* command bitmsk*/ } __attribute__ ((packed)) ng_hci_read_local_commands_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; /************************************************************************** ************************************************************************** ** LE OpCode group field ************************************************************************** **************************************************************************/ #define NG_HCI_OGF_LE 0x08 /* OpCode Group Field */ #define NG_HCI_OCF_LE_SET_EVENT_MASK 0x0001 typedef struct { u_int8_t event_mask[NG_HCI_LE_EVENT_MASK_SIZE]; /* event_mask*/ } __attribute__ ((packed)) ng_hci_le_set_event_mask_cp; typedef ng_hci_status_rp ng_hci_le_set_event_mask_rp; #define NG_HCI_LE_EVENT_MASK_ALL 0x1f #define NG_HCI_OCF_LE_READ_BUFFER_SIZE 0x0002 /*No command parameter */ typedef struct { u_int8_t status; /*status*/ u_int16_t hc_le_data_packet_length; u_int8_t hc_total_num_le_data_packets; } __attribute__ ((packed)) ng_hci_le_read_buffer_size_rp; #define NG_HCI_OCF_LE_READ_LOCAL_SUPPORTED_FEATURES 0x0003 /*No command parameter */ typedef struct { u_int8_t status; /*status*/ u_int64_t le_features; } __attribute__ ((packed)) ng_hci_le_read_local_supported_features_rp; #define NG_HCI_OCF_LE_SET_RANDOM_ADDRESS 0x0005 typedef struct { bdaddr_t random_address; } __attribute__ ((packed)) ng_hci_le_set_random_address_cp_; typedef ng_hci_status_rp ng_hci_le_set_random_address_rp; #define NG_HCI_OCF_LE_SET_ADVERTISING_PARAMETERS 0x0006 typedef struct { u_int16_t advertising_interval_min; u_int16_t advertising_interval_max; u_int8_t advertising_type; u_int8_t own_address_type; u_int8_t direct_address_type; bdaddr_t direct_address; u_int8_t advertising_channel_map; u_int8_t advertising_filter_policy; } __attribute__ ((packed)) ng_hci_le_set_advertising_parameters_cp; typedef ng_hci_status_rp ng_hci_le_set_advertising_parameters_rp; #define NG_HCI_OCF_LE_READ_ADVERTISING_CHANNEL_TX_POWER 0x0007 /*No command parameter*/ typedef struct { u_int8_t status; u_int8_t transmit_power_level; } __attribute__ ((packed)) ng_hci_le_read_advertising_channel_tx_power_rp; #define NG_HCI_OCF_LE_SET_ADVERTISING_DATA 0x0008 #define NG_HCI_ADVERTISING_DATA_SIZE 31 typedef struct { u_int8_t advertising_data_length; char advertising_data[NG_HCI_ADVERTISING_DATA_SIZE]; } __attribute__ ((packed)) ng_hci_le_set_advertising_data_cp; typedef ng_hci_status_rp ng_hci_le_set_advertising_data_rp; #define NG_HCI_OCF_LE_SET_SCAN_RESPONSE_DATA 0x0009 typedef struct { u_int8_t scan_response_data_length; char scan_response_data[NG_HCI_ADVERTISING_DATA_SIZE]; } __attribute__ ((packed)) ng_hci_le_set_scan_response_data_cp; typedef ng_hci_status_rp ng_hci_le_set_scan_response_data_rp; #define NG_HCI_OCF_LE_SET_ADVERTISE_ENABLE 0x000a typedef struct { u_int8_t advertising_enable; }__attribute__ ((packed)) ng_hci_le_set_advertise_enable_cp; typedef ng_hci_status_rp ng_hci_le_set_advertise_enable_rp; #define NG_HCI_OCF_LE_SET_SCAN_PARAMETERS 0x000b typedef struct { u_int8_t le_scan_type; u_int16_t le_scan_interval; u_int16_t le_scan_window; u_int8_t own_address_type; u_int8_t scanning_filter_policy; }__attribute__ ((packed)) ng_hci_le_set_scan_parameters_cp; typedef ng_hci_status_rp ng_hci_le_set_scan_parameters_rp; #define NG_HCI_OCF_LE_SET_SCAN_ENABLE 0x000c typedef struct { u_int8_t le_scan_enable; u_int8_t filter_duplicates; }__attribute__ ((packed)) ng_hci_le_set_scan_enable_cp; typedef ng_hci_status_rp ng_hci_le_set_scan_enable_rp; #define NG_HCI_OCF_LE_CREATE_CONNECTION 0x000d typedef struct { u_int16_t scan_interval; u_int16_t scan_window; u_int8_t filter_policy; u_int8_t peer_addr_type; bdaddr_t peer_addr; u_int8_t own_address_type; u_int16_t conn_interval_min; u_int16_t conn_interval_max; u_int16_t conn_latency; u_int16_t supervision_timeout; u_int16_t min_ce_length; u_int16_t max_ce_length; }__attribute__((packed)) ng_hci_le_create_connection_cp; /* No return parameters. */ #define NG_HCI_OCF_LE_CREATE_CONNECTION_CANCEL 0x000e /*No command parameter*/ typedef ng_hci_status_rp ng_hci_le_create_connection_cancel_rp; #define NG_HCI_OCF_LE_READ_WHITE_LIST_SIZE 0x000f /*No command parameter*/ typedef struct { u_int8_t status; u_int8_t white_list_size; } __attribute__ ((packed)) ng_hci_le_read_white_list_size_rp; #define NG_HCI_OCF_LE_CLEAR_WHITE_LIST 0x0010 /* No command parameters. */ typedef ng_hci_status_rp ng_hci_le_clear_white_list_rp; #define NG_HCI_OCF_LE_ADD_DEVICE_TO_WHITE_LIST 0x0011 typedef struct { u_int8_t address_type; bdaddr_t address; } __attribute__ ((packed)) ng_hci_le_add_device_to_white_list_cp; typedef ng_hci_status_rp ng_hci_le_add_device_to_white_list_rp; #define NG_HCI_OCF_LE_REMOVE_DEVICE_FROM_WHITE_LIST 0x0012 typedef struct { u_int8_t address_type; bdaddr_t address; } __attribute__ ((packed)) ng_hci_le_remove_device_from_white_list_cp; typedef ng_hci_status_rp ng_hci_le_remove_device_from_white_list_rp; #define NG_HCI_OCF_LE_CONNECTION_UPDATE 0x0013 typedef struct { u_int16_t connection_handle; u_int16_t conn_interval_min; u_int16_t conn_interval_max; u_int16_t conn_latency; u_int16_t supervision_timeout; u_int16_t minimum_ce_length; u_int16_t maximum_ce_length; }__attribute__ ((packed)) ng_hci_le_connection_update_cp; /*no return parameter*/ #define NG_HCI_OCF_LE_SET_HOST_CHANNEL_CLASSIFICATION 0x0014 typedef struct{ u_int8_t le_channel_map[5]; }__attribute__ ((packed)) ng_hci_le_set_host_channel_classification_cp; typedef ng_hci_status_rp ng_hci_le_set_host_channel_classification_rp; #define NG_HCI_OCF_LE_READ_CHANNEL_MAP 0x0015 typedef struct { u_int16_t connection_handle; }__attribute__ ((packed)) ng_hci_le_read_channel_map_cp; typedef struct { u_int8_t status; u_int16_t connection_handle; u_int8_t le_channel_map[5]; } __attribute__ ((packed)) ng_hci_le_read_channel_map_rp; #define NG_HCI_OCF_LE_READ_REMOTE_USED_FEATURES 0x0016 typedef struct { u_int16_t connection_handle; }__attribute__ ((packed)) ng_hci_le_read_remote_used_features_cp; /*No return parameter*/ #define NG_HCI_128BIT 16 #define NG_HCI_OCF_LE_ENCRYPT 0x0017 typedef struct { u_int8_t key[NG_HCI_128BIT]; u_int8_t plaintext_data[NG_HCI_128BIT]; }__attribute__ ((packed)) ng_hci_le_encrypt_cp; typedef struct { u_int8_t status; u_int8_t plaintext_data[NG_HCI_128BIT]; }__attribute__ ((packed)) ng_hci_le_encrypt_rp; #define NG_HCI_OCF_LE_RAND 0x0018 /*No command parameter*/ typedef struct { u_int8_t status; u_int64_t random_number; }__attribute__ ((packed)) ng_hci_le_rand_rp; #define NG_HCI_OCF_LE_START_ENCRYPTION 0x0019 typedef struct { u_int16_t connection_handle; u_int64_t random_number; u_int16_t encrypted_diversifier; u_int8_t long_term_key[NG_HCI_128BIT]; }__attribute__ ((packed)) ng_hci_le_start_encryption_cp; /*No return parameter*/ #define NG_HCI_OCF_LE_LONG_TERM_KEY_REQUEST_REPLY 0x001a typedef struct { u_int16_t connection_handle; u_int8_t long_term_key[NG_HCI_128BIT]; }__attribute__ ((packed)) ng_hci_le_long_term_key_request_reply_cp; typedef struct { u_int8_t status; u_int16_t connection_handle; }__attribute__ ((packed)) ng_hci_le_long_term_key_request_reply_rp; #define NG_HCI_OCF_LE_LONG_TERM_KEY_REQUEST_NEGATIVE_REPLY 0x001b typedef struct{ u_int16_t connection_handle; }ng_hci_le_long_term_key_request_negative_reply_cp; typedef struct { u_int8_t status; u_int16_t connection_handle; }__attribute__ ((packed)) ng_hci_le_long_term_key_request_negative_reply_rp; #define NG_HCI_OCF_LE_READ_SUPPORTED_STATUS 0x001c /*No command parameter*/ typedef struct { u_int8_t status; u_int64_t le_status; }__attribute__ ((packed)) ng_hci_le_read_supported_status_rp; #define NG_HCI_OCF_LE_RECEIVER_TEST 0x001d typedef struct{ u_int8_t rx_frequency; } __attribute__((packed)) ng_le_receiver_test_cp; typedef ng_hci_status_rp ng_hci_le_receiver_test_rp; #define NG_HCI_OCF_LE_TRANSMITTER_TEST 0x001e typedef struct{ u_int8_t tx_frequency; u_int8_t length_of_test_data; u_int8_t packet_payload; } __attribute__((packed)) ng_le_transmitter_test_cp; typedef ng_hci_status_rp ng_hci_le_transmitter_test_rp; #define NG_HCI_OCF_LE_TEST_END 0x001f /* No command parameter. */ typedef struct { u_int8_t status; u_int16_t number_of_packets; }__attribute__ ((packed)) ng_hci_le_test_end_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 uclass[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_LE 0x3e typedef struct { u_int8_t subevent_code; }__attribute__ ((packed)) ng_hci_le_ep; #define NG_HCI_LEEV_CON_COMPL 0x01 typedef struct { u_int8_t status; u_int16_t handle; u_int8_t role; u_int8_t address_type; bdaddr_t address; u_int16_t interval; u_int8_t latency; u_int16_t supervision_timeout; u_int8_t master_clock_accracy; } __attribute__ ((packed)) ng_hci_le_connection_complete_ep; #define NG_HCI_LEEV_ADVREP 0x02 typedef struct { u_int8_t num_reports; }__attribute__ ((packed)) ng_hci_le_advertising_report_ep; #define NG_HCI_SCAN_RESPONSE_DATA_MAX 0x1f typedef struct { u_int8_t event_type; u_int8_t addr_type; bdaddr_t bdaddr; u_int8_t length_data; u_int8_t data[NG_HCI_SCAN_RESPONSE_DATA_MAX]; }__attribute__((packed)) ng_hci_le_advreport; #define NG_HCI_LEEV_CON_UPDATE_COMPL 0x03 typedef struct { u_int8_t status; u_int16_t connection_handle; u_int16_t conn_interval; u_int16_t conn_latency; u_int16_t supervision_timeout; }__attribute__((packed)) ng_hci_connection_update_complete_ep; #define NG_HCI_LEEV_READ_REMOTE_FEATURES_COMPL 0x04 //TBD #define NG_HCI_LEEV_LONG_TERM_KEY_REQUEST 0x05 //TBD #define NG_HCI_EVENT_BT_LOGO 0xfe #define NG_HCI_EVENT_VENDOR 0xff #endif /* ndef _NETGRAPH_HCI_H_ */ Index: head/usr.sbin/bluetooth/hccontrol/node.c =================================================================== --- head/usr.sbin/bluetooth/hccontrol/node.c (revision 317505) +++ head/usr.sbin/bluetooth/hccontrol/node.c (revision 317506) @@ -1,608 +1,663 @@ /* * node.c * * Copyright (c) 2001-2002 Maksim Yevmenkin * 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: node.c,v 1.6 2003/07/22 21:14:02 max Exp $ * $FreeBSD$ */ #include #define L2CAP_SOCKET_CHECKED #include #include #include #include #include #include #include #include "hccontrol.h" /* Send Read_Node_State command to the node */ static int hci_read_node_state(int s, int argc, char **argv) { struct ng_btsocket_hci_raw_node_state r; memset(&r, 0, sizeof(r)); if (ioctl(s, SIOC_HCI_RAW_NODE_GET_STATE, &r, sizeof(r)) < 0) return (ERROR); fprintf(stdout, "State: %#x\n", r.state); return (OK); } /* hci_read_node_state */ /* Send Intitialize command to the node */ static int hci_node_initialize(int s, int argc, char **argv) { if (ioctl(s, SIOC_HCI_RAW_NODE_INIT) < 0) return (ERROR); return (OK); } /* hci_node_initialize */ /* Send Read_Debug_Level command to the node */ static int hci_read_debug_level(int s, int argc, char **argv) { struct ng_btsocket_hci_raw_node_debug r; memset(&r, 0, sizeof(r)); if (ioctl(s, SIOC_HCI_RAW_NODE_GET_DEBUG, &r, sizeof(r)) < 0) return (ERROR); fprintf(stdout, "Debug level: %d\n", r.debug); return (OK); } /* hci_read_debug_level */ /* Send Write_Debug_Level command to the node */ static int hci_write_debug_level(int s, int argc, char **argv) { struct ng_btsocket_hci_raw_node_debug r; memset(&r, 0, sizeof(r)); switch (argc) { case 1: r.debug = atoi(argv[0]); break; default: return (USAGE); } if (ioctl(s, SIOC_HCI_RAW_NODE_SET_DEBUG, &r, sizeof(r)) < 0) return (ERROR); return (OK); } /* hci_write_debug_level */ /* Send Read_Node_Buffer_Size command to the node */ static int hci_read_node_buffer_size(int s, int argc, char **argv) { struct ng_btsocket_hci_raw_node_buffer r; memset(&r, 0, sizeof(r)); if (ioctl(s, SIOC_HCI_RAW_NODE_GET_BUFFER, &r, sizeof(r)) < 0) return (ERROR); fprintf(stdout, "Number of free command buffers: %d\n", r.buffer.cmd_free); fprintf(stdout, "Max. ACL packet size: %d\n", r.buffer.acl_size); fprintf(stdout, "Numbef of free ACL buffers: %d\n", r.buffer.acl_free); fprintf(stdout, "Total number of ACL buffers: %d\n", r.buffer.acl_pkts); fprintf(stdout, "Max. SCO packet size: %d\n", r.buffer.sco_size); fprintf(stdout, "Numbef of free SCO buffers: %d\n", r.buffer.sco_free); fprintf(stdout, "Total number of SCO buffers: %d\n", r.buffer.sco_pkts); return (OK); } /* hci_read_node_buffer_size */ /* Send Read_Node_BD_ADDR command to the node */ static int hci_read_node_bd_addr(int s, int argc, char **argv) { struct ng_btsocket_hci_raw_node_bdaddr r; memset(&r, 0, sizeof(r)); if (ioctl(s, SIOC_HCI_RAW_NODE_GET_BDADDR, &r, sizeof(r)) < 0) return (ERROR); fprintf(stdout, "BD_ADDR: %s\n", bt_ntoa(&r.bdaddr, NULL)); return (OK); } /* hci_read_node_bd_addr */ /* Send Read_Node_Features command to the node */ static int hci_read_node_features(int s, int argc, char **argv) { struct ng_btsocket_hci_raw_node_features r; int n; char buffer[1024]; memset(&r, 0, sizeof(r)); if (ioctl(s, SIOC_HCI_RAW_NODE_GET_FEATURES, &r, sizeof(r)) < 0) return (ERROR); fprintf(stdout, "Features: "); for (n = 0; n < sizeof(r.features)/sizeof(r.features[0]); n++) fprintf(stdout, "%#02x ", r.features[n]); fprintf(stdout, "\n%s\n", hci_features2str(r.features, buffer, sizeof(buffer))); return (OK); } /* hci_read_node_features */ /* Send Read_Node_Stat command to the node */ static int hci_read_node_stat(int s, int argc, char **argv) { struct ng_btsocket_hci_raw_node_stat r; memset(&r, 0, sizeof(r)); if (ioctl(s, SIOC_HCI_RAW_NODE_GET_STAT, &r, sizeof(r)) < 0) return (ERROR); fprintf(stdout, "Commands sent: %d\n", r.stat.cmd_sent); fprintf(stdout, "Events received: %d\n", r.stat.evnt_recv); fprintf(stdout, "ACL packets received: %d\n", r.stat.acl_recv); fprintf(stdout, "ACL packets sent: %d\n", r.stat.acl_sent); fprintf(stdout, "SCO packets received: %d\n", r.stat.sco_recv); fprintf(stdout, "SCO packets sent: %d\n", r.stat.sco_sent); fprintf(stdout, "Bytes received: %d\n", r.stat.bytes_recv); fprintf(stdout, "Bytes sent: %d\n", r.stat.bytes_sent); return (OK); } /* hci_read_node_stat */ /* Send Reset_Node_Stat command to the node */ static int hci_reset_node_stat(int s, int argc, char **argv) { if (ioctl(s, SIOC_HCI_RAW_NODE_RESET_STAT) < 0) return (ERROR); return (OK); } /* hci_reset_node_stat */ /* Send Flush_Neighbor_Cache command to the node */ static int hci_flush_neighbor_cache(int s, int argc, char **argv) { if (ioctl(s, SIOC_HCI_RAW_NODE_FLUSH_NEIGHBOR_CACHE) < 0) return (ERROR); return (OK); } /* hci_flush_neighbor_cache */ +#define MIN(a,b) (((a)>(b)) ? (b) :(a) ) + +static int hci_dump_adv(uint8_t *data, int length) +{ + int elemlen; + int type; + int i; + + while(length>0){ + elemlen = *data; + data++; + length --; + elemlen--; + if(length<=0) + break; + type = *data; + data++; + length --; + elemlen--; + if(length<=0) + break; + switch(type){ + case 0x1: + printf("NDflag:%x\n", *data); + break; + case 0x9: + printf("LocalName:"); + for(i = 0; i < MIN(length,elemlen); i++){ + putchar(data[i]); + } + printf("\n"); + break; + default: + printf("Type%d:", type); + for(i=0; i < MIN(length,elemlen); i++){ + printf("%02x ",data[i]); + } + printf("\n"); + break; + } + data += elemlen; + length -= elemlen; + } + return 0; +} +#undef MIN /* Send Read_Neighbor_Cache command to the node */ static int hci_read_neighbor_cache(int s, int argc, char **argv) { struct ng_btsocket_hci_raw_node_neighbor_cache r; int n, error = OK; + const char *addrtype2str[] = {"B", "P", "R", "E"}; memset(&r, 0, sizeof(r)); r.num_entries = NG_HCI_MAX_NEIGHBOR_NUM; r.entries = calloc(NG_HCI_MAX_NEIGHBOR_NUM, sizeof(ng_hci_node_neighbor_cache_entry_ep)); if (r.entries == NULL) { errno = ENOMEM; return (ERROR); } if (ioctl(s, SIOC_HCI_RAW_NODE_GET_NEIGHBOR_CACHE, &r, sizeof(r)) < 0) { error = ERROR; goto out; } fprintf(stdout, +"T " \ "BD_ADDR " \ "Features " \ "Clock offset " \ "Page scan " \ "Rep. scan\n"); for (n = 0; n < r.num_entries; n++) { + uint8_t addrtype = r.entries[n].addrtype; + if(addrtype >= sizeof(addrtype2str)/sizeof(addrtype2str[0])) + addrtype = sizeof(addrtype2str)/sizeof(addrtype2str[0]) - 1; fprintf(stdout, -"%-17.17s " \ +"%1s %-17.17s " \ "%02x %02x %02x %02x %02x %02x %02x %02x " \ "%#12x " \ "%#9x " \ "%#9x\n", + addrtype2str[addrtype], hci_bdaddr2str(&r.entries[n].bdaddr), r.entries[n].features[0], r.entries[n].features[1], r.entries[n].features[2], r.entries[n].features[3], r.entries[n].features[4], r.entries[n].features[5], r.entries[n].features[6], r.entries[n].features[7], r.entries[n].clock_offset, r.entries[n].page_scan_mode, r.entries[n].page_scan_rep_mode); + hci_dump_adv(r.entries[n].extinq_data, + r.entries[n].extinq_size); + fprintf(stdout,"\n"); } out: free(r.entries); return (error); } /* hci_read_neightbor_cache */ /* Send Read_Connection_List command to the node */ static int hci_read_connection_list(int s, int argc, char **argv) { struct ng_btsocket_hci_raw_con_list r; int n, error = OK; memset(&r, 0, sizeof(r)); r.num_connections = NG_HCI_MAX_CON_NUM; r.connections = calloc(NG_HCI_MAX_CON_NUM, sizeof(ng_hci_node_con_ep)); if (r.connections == NULL) { errno = ENOMEM; return (ERROR); } if (ioctl(s, SIOC_HCI_RAW_NODE_GET_CON_LIST, &r, sizeof(r)) < 0) { error = ERROR; goto out; } fprintf(stdout, "Remote BD_ADDR " \ "Handle " \ "Type " \ "Mode " \ "Role " \ "Encrypt " \ "Pending " \ "Queue " \ "State\n"); for (n = 0; n < r.num_connections; n++) { fprintf(stdout, "%-17.17s " \ "%6d " \ "%4.4s " \ "%4d " \ "%4.4s " \ "%7.7s " \ "%7d " \ "%5d " \ "%s\n", hci_bdaddr2str(&r.connections[n].bdaddr), r.connections[n].con_handle, (r.connections[n].link_type == NG_HCI_LINK_ACL)? "ACL" : "SCO", r.connections[n].mode, (r.connections[n].role == NG_HCI_ROLE_MASTER)? "MAST" : "SLAV", hci_encrypt2str(r.connections[n].encryption_mode, 1), r.connections[n].pending, r.connections[n].queue_len, hci_con_state2str(r.connections[n].state)); } out: free(r.connections); return (error); } /* hci_read_connection_list */ /* Send Read_Node_Link_Policy_Settings_Mask command to the node */ int hci_read_node_link_policy_settings_mask(int s, int argc, char **argv) { struct ng_btsocket_hci_raw_node_link_policy_mask r; memset(&r, 0, sizeof(r)); if (ioctl(s, SIOC_HCI_RAW_NODE_GET_LINK_POLICY_MASK, &r, sizeof(r)) < 0) return (ERROR); fprintf(stdout, "Link Policy Settings mask: %#04x\n", r.policy_mask); return (OK); } /* hci_read_node_link_policy_settings_mask */ /* Send Write_Node_Link_Policy_Settings_Mask command to the node */ int hci_write_node_link_policy_settings_mask(int s, int argc, char **argv) { struct ng_btsocket_hci_raw_node_link_policy_mask r; int m; memset(&r, 0, sizeof(r)); switch (argc) { case 1: if (sscanf(argv[0], "%x", &m) != 1) return (USAGE); r.policy_mask = (m & 0xffff); break; default: return (USAGE); } if (ioctl(s, SIOC_HCI_RAW_NODE_SET_LINK_POLICY_MASK, &r, sizeof(r)) < 0) return (ERROR); return (OK); } /* hci_write_node_link_policy_settings_mask */ /* Send Read_Node_Packet_Mask command to the node */ int hci_read_node_packet_mask(int s, int argc, char **argv) { struct ng_btsocket_hci_raw_node_packet_mask r; memset(&r, 0, sizeof(r)); if (ioctl(s, SIOC_HCI_RAW_NODE_GET_PACKET_MASK, &r, sizeof(r)) < 0) return (ERROR); fprintf(stdout, "Packet mask: %#04x\n", r.packet_mask); return (OK); } /* hci_read_node_packet_mask */ /* Send Write_Node_Packet_Mask command to the node */ int hci_write_node_packet_mask(int s, int argc, char **argv) { struct ng_btsocket_hci_raw_node_packet_mask r; int m; memset(&r, 0, sizeof(r)); switch (argc) { case 1: if (sscanf(argv[0], "%x", &m) != 1) return (USAGE); r.packet_mask = (m & 0xffff); break; default: return (USAGE); } if (ioctl(s, SIOC_HCI_RAW_NODE_SET_PACKET_MASK, &r, sizeof(r)) < 0) return (ERROR); return (OK); } /* hci_write_node_packet_mask */ /* Send Read_Node_Role_Switch command to the node */ int hci_read_node_role_switch(int s, int argc, char **argv) { struct ng_btsocket_hci_raw_node_role_switch r; memset(&r, 0, sizeof(r)); if (ioctl(s, SIOC_HCI_RAW_NODE_GET_ROLE_SWITCH, &r, sizeof(r)) < 0) return (ERROR); fprintf(stdout, "Role switch: %d\n", r.role_switch); return (OK); } /* hci_read_node_role_switch */ /* Send Write_Node_Role_Switch command to the node */ int hci_write_node_role_switch(int s, int argc, char **argv) { struct ng_btsocket_hci_raw_node_role_switch r; int m; memset(&r, 0, sizeof(r)); switch (argc) { case 1: if (sscanf(argv[0], "%d", &m) != 1) return (USAGE); r.role_switch = m? 1 : 0; break; default: return (USAGE); } if (ioctl(s, SIOC_HCI_RAW_NODE_SET_ROLE_SWITCH, &r, sizeof(r)) < 0) return (ERROR); return (OK); } /* hci_write_node_role_switch */ /* Send Read_Node_List command to the node */ int hci_read_node_list(int s, int argc, char **argv) { struct ng_btsocket_hci_raw_node_list_names r; int i; r.num_names = MAX_NODE_NUM; r.names = (struct nodeinfo*)calloc(MAX_NODE_NUM, sizeof(struct nodeinfo)); if (r.names == NULL) return (ERROR); if (ioctl(s, SIOC_HCI_RAW_NODE_LIST_NAMES, &r, sizeof(r)) < 0) { free(r.names); return (ERROR); } fprintf(stdout, "Name ID Num hooks\n"); for (i = 0; i < r.num_names; ++i) fprintf(stdout, "%-15s %08x %9d\n", r.names[i].name, r.names[i].id, r.names[i].hooks); free(r.names); return (OK); } /* hci_read_node_list */ struct hci_command node_commands[] = { { "read_node_state", "Get the HCI node state", &hci_read_node_state }, { "initialize", "Initialize the HCI node", &hci_node_initialize }, { "read_debug_level", "Read the HCI node debug level", &hci_read_debug_level }, { "write_debug_level ", "Write the HCI node debug level", &hci_write_debug_level }, { "read_node_buffer_size", "Read the HCI node buffer information. This will return current state of the\n"\ "HCI buffer for the HCI node", &hci_read_node_buffer_size }, { "read_node_bd_addr", "Read the HCI node BD_ADDR. Returns device BD_ADDR as cached by the HCI node", &hci_read_node_bd_addr }, { "read_node_features", "Read the HCI node features. This will return list of supported features as\n" \ "cached by the HCI node", &hci_read_node_features }, { "read_node_stat", "Read packets and bytes counters for the HCI node", &hci_read_node_stat }, { "reset_node_stat", "Reset packets and bytes counters for the HCI node", &hci_reset_node_stat }, { "flush_neighbor_cache", "Flush content of the HCI node neighbor cache", &hci_flush_neighbor_cache }, { "read_neighbor_cache", "Read content of the HCI node neighbor cache", &hci_read_neighbor_cache }, { "read_connection_list", "Read the baseband connection descriptors list for the HCI node", &hci_read_connection_list }, { "read_node_link_policy_settings_mask", "Read the value of the Link Policy Settinngs mask for the HCI node", &hci_read_node_link_policy_settings_mask }, { "write_node_link_policy_settings_mask ", "Write the value of the Link Policy Settings mask for the HCI node. By default\n" \ "all supported Link Policy modes (as reported by the local device features) are\n"\ "enabled. The particular Link Policy mode is enabled if local device supports\n"\ "it and correspinding bit in the mask was set\n\n" \ "\t - xxxx; Link Policy mask\n" \ "\t\t0x0000 - Disable All LM Modes\n" \ "\t\t0x0001 - Enable Master Slave Switch\n" \ "\t\t0x0002 - Enable Hold Mode\n" \ "\t\t0x0004 - Enable Sniff Mode\n" \ "\t\t0x0008 - Enable Park Mode\n", &hci_write_node_link_policy_settings_mask }, { "read_node_packet_mask", "Read the value of the Packet mask for the HCI node", &hci_read_node_packet_mask }, { "write_node_packet_mask ", "Write the value of the Packet mask for the HCI node. By default all supported\n" \ "packet types (as reported by the local device features) are enabled. The\n" \ "particular packet type is enabled if local device supports it and corresponding\n" \ "bit in the mask was set\n\n" \ "\t - xxxx; packet type mask\n" \ "" \ "\t\tACL packets\n" \ "\t\t-----------\n" \ "\t\t0x0008 DM1\n" \ "\t\t0x0010 DH1\n" \ "\t\t0x0400 DM3\n" \ "\t\t0x0800 DH3\n" \ "\t\t0x4000 DM5\n" \ "\t\t0x8000 DH5\n" \ "\n" \ "\t\tSCO packets\n" \ "\t\t-----------\n" \ "\t\t0x0020 HV1\n" \ "\t\t0x0040 HV2\n" \ "\t\t0x0080 HV3\n", &hci_write_node_packet_mask }, { "read_node_role_switch", "Read the value of the Role Switch parameter for the HCI node", &hci_read_node_role_switch }, { "write_node_role_switch {0|1}", "Write the value of the Role Switch parameter for the HCI node. By default,\n" \ "if Role Switch is supported, local device will try to perform Role Switch\n" \ "and become Master on incoming connection. Some devices do not support Role\n" \ "Switch and thus incoming connections from such devices will fail. Setting\n" \ "this parameter to zero will prevent Role Switch and thus accepting device\n" \ "will remain Slave", &hci_write_node_role_switch }, { "read_node_list", "Get a list of HCI nodes, their Netgraph IDs and connected hooks.", &hci_read_node_list }, { NULL, }};