Implementation of Bluetooth HCI command in Linux

Source: Internet
Author: User
The author's blog address: http://blog.sina.com.cn/samzhen1977
By Sam (zhufeng) sam_code@hotmail.com

Write Bluetooth in LinuxProgramFirst, we can use HCI command to set Bluetooth modules (USB Bluetooth dongle ). How are these HCI commands implemented in bluez? Examples.

If (CTL = socket (af_bluetooth, sock_raw, btproto_hci ))
(Http://blog.sina.com.cn/s/blog_602f87700100dpzc.html)-Implementation of Bluetooth HCI command in Linux _ samzhen _ Sina Blog

Previously, hci_sock_init () has been executed because hci_sock.c has been built-in.

In addition, because hci usb driver is also insmod. Therefore, hci_usb_init () is executed. This driver indicates that hci_usb_probe () is called when the USB Bluetooth dongle is inserted (). At this time, it will be pointed out that open is hci_usb_open ()

In hci_usb_open (), set hci_dev-> flag = hci_running.
And submit an interrupted urb to the USB core. Call hci_usb_rx_complete () after the USB core is used to interrupt urb (). It calls _ recv_frame (). It processes all data sent by USB donggle by interrupting urb.

Use hci_init_req () to send a request.
Hci_init_req () calls hci_send_cmd () to send the command.
Hci_send_cmd () calls skb_queue_tail () to add the command SKB to the sending queue. Then call hci_sched_cmd () to call the sending command to send the message. Sending command: hci_cmd_task ()
Hci_cmd_task ()-> hci_send_frame ()-> hdev-> send (SKB); = hci_usb_send_frame (); send a command to USB Bluetooth dongle.

HCI sends command to dongle in this way. Therefore, HCI socket is actually a channel between PC and dongle. Note that it is not a channel between a PC and a remote Bluetooth device, but a local dongle.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.