hcitool 使用与分析

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工具也差不多。



  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值