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.