本文作者的博客地址:http://blog.sina.com.cn/samzhen1977 作者:Sam (甄峰) sam_code@hotmail.com Linux下写Bluetooth程序,首先接触到的就是使用HCI Command来设置Bluetooth Modules(USB Bluetooth dongle)。那这些HCI command在blueZ中是如何实现的呢?举例说明。 if ((ctl = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI)) 来源:(http://blog.sina.com.cn/s/blog_602f87700100dpzc.html) - Linux下Bluetooth HCI Command的实现_samzhen_新浪博客 在此之前,因为hci_sock.c已经被built-in.所以hci_sock_init()已经被执行。 另外,因为hci usb driver也已经insmod。所以hci_usb_init()被执行,这个driver指出,当USB Bluetooth Dongle插入时,调用hci_usb_probe()。这时,就会指出open为hci_usb_open() hci_usb_open()中则设置hci_dev->flag=HCI_RUNNING. 并向USB Core提交一个中断URB。当有中断URB被USB Core出来完毕后,调用hci_usb_rx_complete()。它则调用__recv_frame()。它处理所有USB Dongle通过中断URB送来的数据。 利用hci_init_req()发送request. hci_init_req()调用hci_send_cmd()发送命令。 hci_send_cmd() 则调用skb_queue_tail()将命令skb添加到发送队列。再调用hci_sched_cmd()去调用发送命令去发送。发送命令为:hci_cmd_task() hci_cmd_task()-〉hci_send_frame()-〉hci_send_frame()-〉 hdev->send(skb);=hci_usb_send_frame();发送命令给USB bluetooth dongle. HCI就是通过这个途径发送Command到Dongle的。所以HCI Socket其实就是PC和Dongle之间的一个通道。注意,不是PC和远端bluetooth 设备的通道,而是本地Dongle。
Linux下 Bluetooth HCI Command的实现
最新推荐文章于 2023-07-03 20:42:31 发布