Linux下Bluetooth HCI Command的實現

Linux下寫Bluetooth程序,首先接觸到的就是使用HCI Command來設置Bluetooth Modules(USB Bluetooth dongle)。那這些HCI command在blueZ中是如何實現的呢?舉例說明。


if ((ctl = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI))

 

在此之前,因爲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。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章