使用bluez 4.95 想要在设备inquiry 过程中,获取到查询到设备的rssi 信息,该怎么做,蓝牙求指点
目前的实现如下
if ((dd = hci_open_dev(dev_id)) < 0) {
printf("Fail to open hci dev\n");
goto error;
}
if (ioctl(dd, HCIDEVUP, 0) < 0) {
if (EALREADY == errno) {
printf("ate already hci dev up\n");
} else {
printf("ate hci dev up fail\n");
goto error;
}
}
/*inquiry device*/
ii = (inquiry_info*)malloc(MAX_BT_RSP * sizeof(inquiry_info));
if(!ii) {
printf("malloc fail!\n");
goto error;
}
for(test_count = 0 ;test_count < MAX_BT_SCAN_TIMES;test_count++){
flag = 0;
memset(ii, 0, MAX_BT_RSP * sizeof(inquiry_info));
num_rsp = hci_inquiry(dev_id, BT_SCAN_TIME, MAX_BT_RSP, NULL, &ii, IREQ_CACHE_FLUSH);
printf("This is the %d test, Query the number of devices is %d\n",test_count,num_rsp);
if (num_rsp <= 0) {
continue ;
}
/*Compare MAC*/
for (temp_i = 0; temp_i < num_rsp; temp_i++) {
memset(tmp_mac_val, 0, TEMP_MAC_ARR_LEN);
ba2str(&(ii + temp_i)->bdaddr, tmp_mac_val);
for (temp_j = 0; temp_j < index; temp_j++) {
printf("%s<--->%s",tmp_mac_val,dst_mac_arr[temp_j]);
if (!strcmp(tmp_mac_val, dst_mac_arr[temp_j])) {
printf(" TRUE\n");
flag++;
}else{
printf("\n");
}
}
}
if(flag == index){
break;
}
}
hci_close_dev(dd);
free(ii);
ii = NULL;
但是发现查询到的设备信息中不含着rssi信息
typedef struct {
bdaddr_t bdaddr;
uint8_t pscan_rep_mode;
uint8_t pscan_period_mode;
uint8_t pscan_mode;
uint8_t dev_class[3];
uint16_t clock_offset;
} __attribute__ ((packed)) inquiry_info;
然后查阅网上资料说蓝牙查询模式不同获取事件信息是不同的
然后在相关源码的地方发现该内容
然后查找到对应事件
static gboolean io_security_event(GIOChannel *chan, GIOCondition cond,
gpointer data)
{
printf("========io_security_event====================\n");
unsigned char buf[HCI_MAX_EVENT_SIZE], *ptr = buf;
int type, index = GPOINTER_TO_INT(data);
struct dev_info *dev = &devs[index];
struct hci_dev_info di;
ssize_t len;
hci_event_hdr *eh;
evt_cmd_status *evt;
int fd;
if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR)) {
stop_hci_dev(index);
return FALSE;
}
fd = g_io_channel_unix_get_fd(chan);
len = read(fd, buf, sizeof(buf));
if (len < 0) {
if (errno == EAGAIN)
return TRUE;
stop_hci_dev(index);
return FALSE;
}
type = *ptr++;
if (type != HCI_EVENT_PKT)
return TRUE;
eh = (hci_event_hdr *) ptr;
ptr += HCI_EVENT_HDR_SIZE;
memset(&di, 0, sizeof(di));
if (hci_devinfo(index, &di) == 0) {
bacpy(&dev->bdaddr, &di.bdaddr);
if (ignore_device(&di))
return TRUE;
}
printf("=====123=============eh->evt: 0x%x\n", eh->evt);
switch (eh->evt) {
case EVT_CMD_STATUS:
cmd_status(index, ptr);
break;
case EVT_CMD_COMPLETE:
cmd_complete(index, ptr);
break;
case EVT_REMOTE_NAME_REQ_COMPLETE:
remote_name_information(index, ptr);
break;
case EVT_READ_REMOTE_VERSION_COMPLETE:
remote_version_information(index, ptr);
break;
case EVT_READ_REMOTE_FEATURES_COMPLETE:
remote_features_information(index, ptr);
break;
case EVT_REMOTE_HOST_FEATURES_NOTIFY:
remote_features_notify(index, ptr);
break;
case EVT_INQUIRY_COMPLETE:
evt = (evt_cmd_status *) ptr;
inquiry_complete_evt(index, evt->status);
break;
case EVT_INQUIRY_RESULT:
inquiry_result(index, eh->plen, ptr);
break;
case EVT_INQUIRY_RESULT_WITH_RSSI:
inquiry_result_with_rssi(index, eh->plen, ptr);
break;
case EVT_EXTENDED_INQUIRY_RESULT:
extended_inquiry_result(index, eh->plen, ptr);
break;
case EVT_CONN_COMPLETE:
conn_complete(index, ptr);
break;
case EVT_DISCONN_COMPLETE:
disconn_complete(index, ptr);
break;
case EVT_AUTH_COMPLETE:
auth_complete(index, ptr);
break;
case EVT_SIMPLE_PAIRING_COMPLETE:
simple_pairing_complete(index, ptr);
break;
case EVT_CONN_REQUEST:
conn_request(index, ptr);
break;
case EVT_LE_META_EVENT:
le_metaevent(index, ptr);
break;
case EVT_PIN_CODE_REQ:
pin_code_request(index, (bdaddr_t *) ptr);
break;
case EVT_LINK_KEY_REQ:
link_key_request(index, (bdaddr_t *) ptr);
break;
case EVT_LINK_KEY_NOTIFY:
link_key_notify(index, ptr);
break;
case EVT_RETURN_LINK_KEYS:
return_link_keys(index, ptr);
break;
case EVT_IO_CAPABILITY_REQUEST:
io_capa_request(index, ptr);
break;
case EVT_IO_CAPABILITY_RESPONSE:
io_capa_response(index, ptr);
break;
case EVT_USER_CONFIRM_REQUEST:
user_confirm_request(index, ptr);
break;
case EVT_USER_PASSKEY_REQUEST:
user_passkey_request(index, ptr);
break;
case EVT_USER_PASSKEY_NOTIFY:
user_passkey_notify(index, ptr);
break;
case EVT_REMOTE_OOB_DATA_REQUEST:
remote_oob_data_request(index, (bdaddr_t *) ptr);
break;
}
return TRUE;
}
但添加打印后,该事件处理的地方并没有走到
但抓包能看到
想请教指点一下,我怎么能在查询设备信息的时候,同时将设备的rssi信号强度也获取到