Linux下 Bluetooth HCI Command的實現

來源:互聯網
上載者:User
本文作者的部落格地址: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。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.