Usage:
hcitool [options] <command> [command parameters]
Options:
--help Display help
-i dev HCI device
Commands:
dev Display local devices
inq Inquire remote devices
scan Scan for remote devices
name Get name from remote device
info Get information from remote device
cmd Submit arbitrary HCI commands
con Display active connections
cc Create connection to remote device
dc Disconnect from remote device
sr Switch master/slave role
cpt Change connection packet type
rssi Display connection RSSI
lq Display link quality
tpl Display transmit power level
afh Display AFH channel map
lst Set/display link supervision timeout
auth Request authentication
enc Set connection encryption
key Change connection link key
clkoff Read clock offset
clock Read local or remote clock
main()函数入口
while ((opt=getopt_long(argc, argv, "+i:h", main_options, NULL)) != -1) 参数解析
比如以hcitool scan 为例,经过解析 cmd_scan函数
static void cmd_scan(int dev_id, int argc, char **argv)
{
……
for_each_opt(opt, scan_options, NULL); //scan的选择参数
……
num_rsp =
hci_inquiry(dev_id, length, num_rsp, lap, &info, flags);
……
}
查看/src/hci.c文件
int hci_inquiry(int dev_id, int len, int nrsp, const uint8_t *lap, inquiry_info **ii, long flags)
{
……
dd = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI); //创建BTPROTO_HCI 类型socket
……
ret = ioctl(dd, HCIINQUIRY, (unsigned long) buf); //获取数据
……
memcpy((void *) *ii, buf + sizeof(*ir), size); //保存信息
……
}
对应内核流程:构造查询命令,放入命令队列,触发tasklet发送命令,命令和数据收集分开处理。
其他bluez工具也差不多。