Obtain RSSI with hcidump

2019-01-29 06:24发布

In order to read the raw RSSI values, we use a utility called Hcidump, which monitors the Bluetooth HCI data. Using hcidump commands, we can read the raw RSSI values when an inquiry response message is received. To obtain RSSI values for every response packet we first set the inquiry mode to Inquiry With RSSI.In order to read raw RSSI values we run the hcidump tool and then use the appropriate HCI functions to start periodic inquiry.

I don't know how to use hcidump to obatain only RSSI raw data or maybe how to start a periodic inquiry. I see all the opcions but I am not able.

I make hcidump --raw to obtain raw data, and try to parse this data to obtain the rssi, but I dont know wich hex is the rssi info.

This is what I obtain

  04 2F FF 01 AC A2 65 92 88 EC 01 00 0C 02 5A 2D 1F D2 08 09 
  4E 65 78 75 73 20 36 17 03 05 11 0A 11 0C 11 0E 11 12 11 15 
  11 16 11 1F 11 2F 11 00 12 32 11 01 05 01 07 00 00 00 00 00 
  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 

Now I need to know which is the RSSI value.

2条回答
forever°为你锁心
2楼-- · 2019-01-29 06:34

We can figure this out by inspecting the source code behind the hcidump tool. It is a part of BlueZ, the official Linux Bluetooth stack. You can download the BlueZ source code here, to follow along. If you open up the source code and step into lib/ folder, you can find hci.h, which has the struct definitons for BlueZ's HCI functions. Otherwise, you can look in your Linux system's header files. The path should be something like: /usr/include/bluetooth/hci.h. In this header file, you will find all the struct definitions for BlueZ's HCI functionality. Specifically, you can find the struct defintion for inquiry_info_with_rssi. The header file is a few thousand lines long so you would be better served searching the header file instead of trying to look through it. From looking at this struct and the #define below, you can see the struct size is 14 bytes. The rssi value is the last member of the struct and only 1 byte, so it should be the 14th byte you count.

typedef struct {
bdaddr_t    bdaddr;
uint8_t     pscan_rep_mode;
uint8_t     pscan_period_mode;
uint8_t     dev_class[3];
uint16_t    clock_offset;
int8_t      rssi;
} __attribute__ ((packed)) inquiry_info_with_rssi;
#define INQUIRY_INFO_WITH_RSSI_SIZE 14

An interesting note is that __attribute__ ((packed)) is a compiler preprocessor directing it not to pad the structure, so the size of 14 bytes is guranteed.

查看更多
Explosion°爆炸
3楼-- · 2019-01-29 06:41

you can try using sudo hcidump [-a] this will get you the name and RSSI value of all the nearby bluetooth devices.you can check out what you can do with hcidump here.

查看更多
登录 后发表回答