Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/bluetooth/hccontrol/node.c
Show First 20 Lines • Show All 202 Lines • ▼ Show 20 Lines | |||||
hci_flush_neighbor_cache(int s, int argc, char **argv) | hci_flush_neighbor_cache(int s, int argc, char **argv) | ||||
{ | { | ||||
if (ioctl(s, SIOC_HCI_RAW_NODE_FLUSH_NEIGHBOR_CACHE) < 0) | if (ioctl(s, SIOC_HCI_RAW_NODE_FLUSH_NEIGHBOR_CACHE) < 0) | ||||
return (ERROR); | return (ERROR); | ||||
return (OK); | return (OK); | ||||
} /* hci_flush_neighbor_cache */ | } /* hci_flush_neighbor_cache */ | ||||
static int hci_dump_adv(uint8_t *data, int length) | |||||
{ | |||||
int cur = 0; | |||||
int elemlen; | |||||
int type; | |||||
int i; | |||||
while(cur < length){ | |||||
elemlen = data[cur]; | |||||
cur++; | |||||
type = data[cur]; | |||||
switch(type){ | |||||
case 0x1: | |||||
printf("NDflag:%x\n", data[cur+1]); | |||||
break; | |||||
case 0x9: | |||||
printf("LocalName:"); | |||||
for(i = 0; i < elemlen - 2; i++){ | |||||
putchar(data[cur+1+i]); | |||||
} | |||||
printf("\n"); | |||||
break; | |||||
default: | |||||
printf("Type%d:", type); | |||||
for(i=0; i < elemlen - 2; i++){ | |||||
emax: do we need to check elemlen here as well? basically what if elemlen is longer than supplied… | |||||
printf("%02x ",data[cur+i+1]); | |||||
} | |||||
printf("\n"); | |||||
break; | |||||
} | |||||
cur += elemlen; | |||||
} | |||||
return 0; | |||||
} | |||||
/* Send Read_Neighbor_Cache command to the node */ | /* Send Read_Neighbor_Cache command to the node */ | ||||
static int | static int | ||||
hci_read_neighbor_cache(int s, int argc, char **argv) | hci_read_neighbor_cache(int s, int argc, char **argv) | ||||
{ | { | ||||
struct ng_btsocket_hci_raw_node_neighbor_cache r; | struct ng_btsocket_hci_raw_node_neighbor_cache r; | ||||
int n, error = OK; | int n, error = OK; | ||||
const char *addrtype2str[] = {"B","P", "R", "E"}; | |||||
memset(&r, 0, sizeof(r)); | memset(&r, 0, sizeof(r)); | ||||
r.num_entries = NG_HCI_MAX_NEIGHBOR_NUM; | r.num_entries = NG_HCI_MAX_NEIGHBOR_NUM; | ||||
r.entries = calloc(NG_HCI_MAX_NEIGHBOR_NUM, | r.entries = calloc(NG_HCI_MAX_NEIGHBOR_NUM, | ||||
sizeof(ng_hci_node_neighbor_cache_entry_ep)); | sizeof(ng_hci_node_neighbor_cache_entry_ep)); | ||||
if (r.entries == NULL) { | if (r.entries == NULL) { | ||||
errno = ENOMEM; | errno = ENOMEM; | ||||
return (ERROR); | return (ERROR); | ||||
} | } | ||||
if (ioctl(s, SIOC_HCI_RAW_NODE_GET_NEIGHBOR_CACHE, &r, | if (ioctl(s, SIOC_HCI_RAW_NODE_GET_NEIGHBOR_CACHE, &r, | ||||
sizeof(r)) < 0) { | sizeof(r)) < 0) { | ||||
error = ERROR; | error = ERROR; | ||||
goto out; | goto out; | ||||
} | } | ||||
fprintf(stdout, | fprintf(stdout, | ||||
"T " \ | |||||
"BD_ADDR " \ | "BD_ADDR " \ | ||||
"Features " \ | "Features " \ | ||||
"Clock offset " \ | "Clock offset " \ | ||||
"Page scan " \ | "Page scan " \ | ||||
"Rep. scan\n"); | "Rep. scan\n"); | ||||
for (n = 0; n < r.num_entries; 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]); | |||||
emaxUnsubmitted Not Done Inline Actionsi think this is off by one, i.e. sizeof() will return 4, but last index is 3. what do you think? emax: i think this is off by one, i.e. sizeof() will return 4, but last index is 3. what do you think? | |||||
fprintf(stdout, | fprintf(stdout, | ||||
"%-17.17s " \ | "%1s %-17.17s " \ | ||||
"%02x %02x %02x %02x %02x %02x %02x %02x " \ | "%02x %02x %02x %02x %02x %02x %02x %02x " \ | ||||
"%#12x " \ | "%#12x " \ | ||||
"%#9x " \ | "%#9x " \ | ||||
"%#9x\n", | "%#9x\n", | ||||
addrtype2str[addrtype], | |||||
hci_bdaddr2str(&r.entries[n].bdaddr), | hci_bdaddr2str(&r.entries[n].bdaddr), | ||||
r.entries[n].features[0], r.entries[n].features[1], | r.entries[n].features[0], r.entries[n].features[1], | ||||
r.entries[n].features[2], r.entries[n].features[3], | r.entries[n].features[2], r.entries[n].features[3], | ||||
r.entries[n].features[4], r.entries[n].features[5], | r.entries[n].features[4], r.entries[n].features[5], | ||||
r.entries[n].features[6], r.entries[n].features[7], | r.entries[n].features[6], r.entries[n].features[7], | ||||
r.entries[n].clock_offset, r.entries[n].page_scan_mode, | r.entries[n].clock_offset, r.entries[n].page_scan_mode, | ||||
r.entries[n].page_scan_rep_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: | out: | ||||
free(r.entries); | free(r.entries); | ||||
return (error); | return (error); | ||||
} /* hci_read_neightbor_cache */ | } /* hci_read_neightbor_cache */ | ||||
/* Send Read_Connection_List command to the node */ | /* Send Read_Connection_List command to the node */ | ||||
▲ Show 20 Lines • Show All 347 Lines • Show Last 20 Lines |
do we need to check elemlen here as well? basically what if elemlen is longer than supplied length?