aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakanori Watanabe <takawata@FreeBSD.org>2017-04-27 15:03:24 +0000
committerTakanori Watanabe <takawata@FreeBSD.org>2017-04-27 15:03:24 +0000
commit4aa92fe2f385fa66a86878dd38e29cde6c28ece7 (patch)
tree118a668c3443572267cfcc3b5b43a326489a5a7b
parent791c9d7848b38e9ef3f8f1b78d0e00a2fbafa542 (diff)
downloadsrc-4aa92fe2f385fa66a86878dd38e29cde6c28ece7.tar.gz
src-4aa92fe2f385fa66a86878dd38e29cde6c28ece7.zip
Notes
-rw-r--r--lib/libbluetooth/bluetooth.h1
-rw-r--r--sys/netgraph/bluetooth/hci/ng_hci_evnt.c32
-rw-r--r--sys/netgraph/bluetooth/hci/ng_hci_main.c21
-rw-r--r--sys/netgraph/bluetooth/hci/ng_hci_var.h3
-rw-r--r--sys/netgraph/bluetooth/include/ng_bluetooth.h4
-rw-r--r--sys/netgraph/bluetooth/include/ng_btsocket.h4
-rw-r--r--sys/netgraph/bluetooth/include/ng_hci.h4
-rw-r--r--usr.sbin/bluetooth/hccontrol/node.c57
8 files changed, 110 insertions, 16 deletions
diff --git a/lib/libbluetooth/bluetooth.h b/lib/libbluetooth/bluetooth.h
index 451606bec414..6e00777291fc 100644
--- a/lib/libbluetooth/bluetooth.h
+++ b/lib/libbluetooth/bluetooth.h
@@ -46,6 +46,7 @@
#include <bitstring.h>
#include <netgraph/ng_message.h>
+#include <netgraph/bluetooth/include/ng_bluetooth.h>
#include <netgraph/bluetooth/include/ng_hci.h>
#include <netgraph/bluetooth/include/ng_l2cap.h>
#include <netgraph/bluetooth/include/ng_btsocket.h>
diff --git a/sys/netgraph/bluetooth/hci/ng_hci_evnt.c b/sys/netgraph/bluetooth/hci/ng_hci_evnt.c
index 1c1aeee3b6b2..647bfccabaa5 100644
--- a/sys/netgraph/bluetooth/hci/ng_hci_evnt.c
+++ b/sys/netgraph/bluetooth/hci/ng_hci_evnt.c
@@ -417,7 +417,6 @@ le_advertizing_report(ng_hci_unit_p unit, struct mbuf *event)
} else
getmicrotime(&n->updated);
-#if 0
{
/*
* TODO: Make these information
@@ -425,21 +424,36 @@ le_advertizing_report(ng_hci_unit_p unit, struct mbuf *event)
*/
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);
diff --git a/sys/netgraph/bluetooth/hci/ng_hci_main.c b/sys/netgraph/bluetooth/hci/ng_hci_main.c
index 9abe595c9774..ae00ea6d18e8 100644
--- a/sys/netgraph/bluetooth/hci/ng_hci_main.c
+++ b/sys/netgraph/bluetooth/hci/ng_hci_main.c
@@ -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_p item, hook_p lasthook)
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;
diff --git a/sys/netgraph/bluetooth/hci/ng_hci_var.h b/sys/netgraph/bluetooth/hci/ng_hci_var.h
index 171c437c13fe..7909ce6299b2 100644
--- a/sys/netgraph/bluetooth/hci/ng_hci_var.h
+++ b/sys/netgraph/bluetooth/hci/ng_hci_var.h
@@ -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;
diff --git a/sys/netgraph/bluetooth/include/ng_bluetooth.h b/sys/netgraph/bluetooth/include/ng_bluetooth.h
index 2b85facad51f..3015b9f1b9bb 100644
--- a/sys/netgraph/bluetooth/include/ng_bluetooth.h
+++ b/sys/netgraph/bluetooth/include/ng_bluetooth.h
@@ -224,5 +224,9 @@ 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_ */
diff --git a/sys/netgraph/bluetooth/include/ng_btsocket.h b/sys/netgraph/bluetooth/include/ng_btsocket.h
index 4815e4373b3d..515770b3cdc0 100644
--- a/sys/netgraph/bluetooth/include/ng_btsocket.h
+++ b/sys/netgraph/bluetooth/include/ng_btsocket.h
@@ -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 */
diff --git a/sys/netgraph/bluetooth/include/ng_hci.h b/sys/netgraph/bluetooth/include/ng_hci.h
index 7fe1dc7a6f0b..34cd1a68f221 100644
--- a/sys/netgraph/bluetooth/include/ng_hci.h
+++ b/sys/netgraph/bluetooth/include/ng_hci.h
@@ -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 \
diff --git a/usr.sbin/bluetooth/hccontrol/node.c b/usr.sbin/bluetooth/hccontrol/node.c
index f1f2694a2285..2a08e0e89cbe 100644
--- a/usr.sbin/bluetooth/hccontrol/node.c
+++ b/usr.sbin/bluetooth/hccontrol/node.c
@@ -208,12 +208,59 @@ hci_flush_neighbor_cache(int s, int argc, char **argv)
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, char **argv)
}
fprintf(stdout,
+"T " \
"BD_ADDR " \
"Features " \
"Clock offset " \
@@ -238,12 +286,16 @@ hci_read_neighbor_cache(int s, int argc, char **argv)
"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, char **argv)
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);