From owner-svn-src-head@freebsd.org Thu Apr 27 15:03:26 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id BA002D53AE1; Thu, 27 Apr 2017 15:03:26 +0000 (UTC) (envelope-from takawata@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 720051B22; Thu, 27 Apr 2017 15:03:26 +0000 (UTC) (envelope-from takawata@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v3RF3PqV018525; Thu, 27 Apr 2017 15:03:25 GMT (envelope-from takawata@FreeBSD.org) Received: (from takawata@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v3RF3Ovn018517; Thu, 27 Apr 2017 15:03:24 GMT (envelope-from takawata@FreeBSD.org) Message-Id: <201704271503.v3RF3Ovn018517@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: takawata set sender to takawata@FreeBSD.org using -f From: Takanori Watanabe Date: Thu, 27 Apr 2017 15:03:24 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r317506 - in head: lib/libbluetooth sys/netgraph/bluetooth/hci sys/netgraph/bluetooth/include usr.sbin/bluetooth/hccontrol X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 Apr 2017 15:03:26 -0000 Author: takawata Date: Thu Apr 27 15:03:24 2017 New Revision: 317506 URL: https://svnweb.freebsd.org/changeset/base/317506 Log: Make cached Bluetooth LE host advertise information visible from userland. Differential Revision: https://reviews.freebsd.org/D10362 Modified: head/lib/libbluetooth/bluetooth.h head/sys/netgraph/bluetooth/hci/ng_hci_evnt.c head/sys/netgraph/bluetooth/hci/ng_hci_main.c head/sys/netgraph/bluetooth/hci/ng_hci_var.h head/sys/netgraph/bluetooth/include/ng_bluetooth.h head/sys/netgraph/bluetooth/include/ng_btsocket.h head/sys/netgraph/bluetooth/include/ng_hci.h head/usr.sbin/bluetooth/hccontrol/node.c Modified: head/lib/libbluetooth/bluetooth.h ============================================================================== --- head/lib/libbluetooth/bluetooth.h Thu Apr 27 14:39:52 2017 (r317505) +++ head/lib/libbluetooth/bluetooth.h Thu Apr 27 15:03:24 2017 (r317506) @@ -46,6 +46,7 @@ #include #include +#include #include #include #include Modified: head/sys/netgraph/bluetooth/hci/ng_hci_evnt.c ============================================================================== --- head/sys/netgraph/bluetooth/hci/ng_hci_evnt.c Thu Apr 27 14:39:52 2017 (r317505) +++ head/sys/netgraph/bluetooth/hci/ng_hci_evnt.c Thu Apr 27 15:03:24 2017 (r317506) @@ -417,7 +417,6 @@ le_advertizing_report(ng_hci_unit_p unit } else getmicrotime(&n->updated); -#if 0 { /* * TODO: Make these information @@ -425,21 +424,36 @@ le_advertizing_report(ng_hci_unit_p unit */ 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); Modified: head/sys/netgraph/bluetooth/hci/ng_hci_main.c ============================================================================== --- head/sys/netgraph/bluetooth/hci/ng_hci_main.c Thu Apr 27 14:39:52 2017 (r317505) +++ head/sys/netgraph/bluetooth/hci/ng_hci_main.c Thu Apr 27 15:03:24 2017 (r317506) @@ -93,7 +93,22 @@ 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 @@ -481,11 +496,15 @@ ng_hci_default_rcvmsg(node_p node, item_ 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; Modified: head/sys/netgraph/bluetooth/hci/ng_hci_var.h ============================================================================== --- head/sys/netgraph/bluetooth/hci/ng_hci_var.h Thu Apr 27 14:39:52 2017 (r317505) +++ head/sys/netgraph/bluetooth/hci/ng_hci_var.h Thu Apr 27 15:03:24 2017 (r317506) @@ -210,7 +210,8 @@ typedef struct ng_hci_neighbor { 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; Modified: head/sys/netgraph/bluetooth/include/ng_bluetooth.h ============================================================================== --- head/sys/netgraph/bluetooth/include/ng_bluetooth.h Thu Apr 27 14:39:52 2017 (r317505) +++ head/sys/netgraph/bluetooth/include/ng_bluetooth.h Thu Apr 27 15:03:24 2017 (r317506) @@ -224,5 +224,9 @@ u_int32_t bluetooth_l2cap_rtx_timeout (v 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_ */ Modified: head/sys/netgraph/bluetooth/include/ng_btsocket.h ============================================================================== --- head/sys/netgraph/bluetooth/include/ng_btsocket.h Thu Apr 27 14:39:52 2017 (r317505) +++ head/sys/netgraph/bluetooth/include/ng_btsocket.h Thu Apr 27 15:03:24 2017 (r317506) @@ -228,10 +228,6 @@ struct sockaddr_l2cap_compat { 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 */ Modified: head/sys/netgraph/bluetooth/include/ng_hci.h ============================================================================== --- head/sys/netgraph/bluetooth/include/ng_hci.h Thu Apr 27 14:39:52 2017 (r317505) +++ head/sys/netgraph/bluetooth/include/ng_hci.h Thu Apr 27 15:03:24 2017 (r317506) @@ -80,6 +80,7 @@ #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 */ @@ -561,6 +562,9 @@ typedef struct { 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 \ Modified: head/usr.sbin/bluetooth/hccontrol/node.c ============================================================================== --- head/usr.sbin/bluetooth/hccontrol/node.c Thu Apr 27 14:39:52 2017 (r317505) +++ head/usr.sbin/bluetooth/hccontrol/node.c Thu Apr 27 15:03:24 2017 (r317506) @@ -208,12 +208,59 @@ hci_flush_neighbor_cache(int s, int argc 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; @@ -231,6 +278,7 @@ hci_read_neighbor_cache(int s, int argc, } fprintf(stdout, +"T " \ "BD_ADDR " \ "Features " \ "Clock offset " \ @@ -238,12 +286,16 @@ hci_read_neighbor_cache(int s, int argc, "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], @@ -251,6 +303,9 @@ hci_read_neighbor_cache(int s, int argc, 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);