Yesterday, I looked at the introduction of Bluetooth protocol documents, today simply looked at the code in kernel (BlueZ), here to note, or inherited the old habits,
Only focus on the overall process and ignore the details, first understand the approximate, and so on when the real need to carefully analyze.
Net/hci_core.c
The main driver of HCI is to provide a unified interface for the upper layer, so that the upper layer protocol does not depend on the implementation of the specific hardware. The firmware of the HCI in the hardware
There are many ways to communicate with HCI on the host side, such as UART, USB and PC Card, and so on. The hci_core.c is equivalent to a frame used to
A variety of specific means of communication are glued together and provide some common function implementations.
Hci_cmd_task is responsible for the task of sending CMD, it takes cmd from the hdev->cmd_q queue, and then calls Hci_send_frame to send cmd out,
The Hci_send_frame also invokes the actual HCI-driven send function for sending the data.
Hci_rx_task is the task that receives data, takes data from the Hdev->rx_q queue, and then calls the top-level function processing based on the type of data. Data
There are three types of packages:
1. HCI_EVENT_PKT: For handling Some communication events, such as connection establishment, connection disconnection, authentication and encryption, and other events, these events control protocol
Change of state.
2. HCI_ACLDATA_PKT: Asynchronous disconnected packets, Hci_acldata_packet submitted to the upper layer of the L2CAP protocol processing
(Hci_proto[hci_proto_l2cap]).
3. HCI_SCODATA_PKT: Synchronous connection-oriented packets, provided by Hci_scodata_packet to the upper level SCO protocol processing
(Hci_proto[hci_proto_sco]).
Hci_tx_task is the task responsible for sending data, sending ACL and SCO data from all connection, and packets in hdev->raw_q.
The interfaces that HCI provides to the upper layers are:
1. Hci_send_sco: Send SCO packets, send the packets into the connection send queue, and then dispatch the task to send.
2. HCI_SEND_ACL: Send ACL packets, put the packets to be sent into the connection send queue, and then dispatch the task to send.
3. Hci_send_cmd: Send the command data, put the packets to be sent into the hdev->cmd_q queue, and then dispatch the command to send the task to send.
4. Hci_register_proto/hci_unregister_proto: Registration/cancellation of upper layer protocol, HCI will receive the data forwarded to these upper layer protocol.
5. Hci_register_dev/hci_unregister_dev: Registration/Cancellation device, HCI will send the data sent through these devices.
6. Some other common functions.
Net/hci_conn.c
Provides a number of functions for connection management, justification, and encryption.
Net/hci_event.c
Event handlers, which are responsible for the maintenance of state machines, which typically cause the connection to transition from one state to another.
1. Hci_si_event: for sending events.
2. Hci_event_packet: Used to handle the low-level escalation of the event, from the Hci_rx_task call over.
Net/hci_sock.c
Provides a socket interface to the upper layer, and the application can access the HCI by means of a socket.
1. Hci_sock_init: BTPROTO_HCI type family is registered.
2. Hci_sock_create: Creates the sock function, its sock ops points to hci_sock_ops.
3. Hci_sock_setsockopt/hci_sock_getsockopt: Set/Get some options for sock.
4. Hci_sock_sendmsg: Sends a message and places the message in the appropriate queue based on the type of message.
5. Hci_sock_recvmsg: Receives the message, takes the message from the receive queue.
6. Hci_sock_recvmsg:ioctl function.
Net/hci_sysfs.c
Provides some SYSFS file system interfaces. Net/l2cap.c
L2cap is a protocol above HCI that provides functionality such as QoS, grouping, multiplexing, staging, and assembly.
Provides a sock interface for the upper layer through Bt_sock_register:
1. L2cap_sock_create: Creates the sock function, its sock ops points to l2cap_sock_ops.
2. L2cap_sock_setsockopt/l2cap_sock_getsockopt set/Get some options for sock.
3. L2cap_sock_sendmsg: Sends the message, through HCI provides the HCI_SEND_ACL function to pass the message to the lower level device.
4. BT_SOCK_RECVMSG: Receives the message, takes the message from the receive queue.
Through the Hci_register_proto to the HCI registration agreement:
1. L2cap_connect_ind: Processing connection requests.
2. L2CAP_CONNECT_CFM: Confirm the connection.
3. L2cap_disconn: Process the disconnect request.
4. L2CAP_AUTH_CFM: Certification confirmation.
5. L2CAP_ENCRYPT_CFM: Encryption confirmation.
6. L2cap_recv_acldata: Process data from HCI.
Net/sco.c
SCO is also a protocol running on HCI, which is a reliable connection-oriented transmission, primarily for sound data transmission.
Provides a sock interface for the upper layer through Bt_sock_register:
1. Sco_sock_create: Creates the sock function, its sock ops points to sco_sock_ops.
2. Sco_sock_setsockopt/sco_sock_getsockopt set/Get some options for sock.
3. Sco_sock_sendmsg: Sends the message, through HCI provides the Sco_send_frame function to pass the message to the lower level device.
4. BT_SOCK_RECVMSG: Receives the message, takes the message from the receive queue.
Through the Hci_register_proto to the HCI registration agreement:
1. Sco_connect_ind: Processing connection requests.
2. SCO_CONNECT_CFM: Confirm the connection.
3. Sco_disconn_ind: Process the disconnect request.
4. Sco_recv_scodata: Processing from HCI data.
rfcomm/*
Rfcomm is a protocol based on L2cap, which encapsulates the traditional RS232 serial port on top of the Bluetooth protocol.
Drivers/bluetooth
We have previously described both HCI and its upper layer protocols, and the implementation of the HCI layer is the HCI driver, which is used to communicate with the Bluetooth hardware,
The way of communication is common to have usb,uart and PC card and so on several. Here we look at the USB way:
Drivers/bluetooth/hci_usb.c
1. Hci_usb_probe: Invoke Hci_register_dev to register the HCI device with the Hci_core described above.
2. Hci_usb_send_frame: Used to provide to HCI to send packets. It puts packets into the transport queue __transmit_q (HUSB,
BT_CB (SKB)->pkt_type), and then call hci_usb_tx_process to transmit the data.
3. Hci_usb_tx_process: According to the type of data to call Hci_usb_send_ctrl/hci_usb_send_isoc/hci_usb_send_bulk
Data is sent to the hardware via USB.