mirror of
https://git.FreeBSD.org/src.git
synced 2024-11-30 08:19:09 +00:00
Make cached Bluetooth LE host advertise information visible from userland.
Differential Revision: https://reviews.freebsd.org/D10362
This commit is contained in:
parent
791c9d7848
commit
4aa92fe2f3
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=317506
@ -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>
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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_ */
|
||||
|
||||
|
@ -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 */
|
||||
|
@ -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 \
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user