Processing of Bluetooth HCI event

Source: Internet
Author: User

The author's blog address: http://blog.sina.com.cn/samzhen1977
By Sam (zhufeng)
Sam_code@hotmail.com

 

 

1. When Bluetooth USB
When the USB interface is inserted into the dongle, the probe program in Driver/Bluetooth/hci_usb.c is called. PROBE will call
Hci_register_dev () --> tasklet_init (& hdev-> rx_task,
Hci_rx_task, (unsigned long) hdev );
Connect hci_rx_task () to rx_task-> func.

 

2. When Bluetooth USB dongle is inserted, hdev-> open =
Hci_usb_open; When USB
This function is called when the dongle is up. It calls hci_usb_intr_rx_submit () and registers urb to complete the processing process.
Hci_usb_rx_complete.

When urb appears, hci_usb_rx_complete->__ recv_frame ()
-> Hci_recv_frame ()-> hci_sched_rx (hdev);-> hci_sched_rx ()
-> Tasklet_schedule (& hdev-> rx_task)

Tasklet_schedule ():
Put this tasklet in
The head of the tasklet_vec linked list and wake up the background thread ksoftirqd. When the backend thread ksoftirqd runs the call _ do_softirq, the execution is interrupted.
Tasklet_action function corresponding to tasklet_softirq in softirq_vec vector table, and traverse tasklet_action
The tasklet_vec linked list calls each tasklet function to complete the Soft Interrupt operation.
That is, call hci_rx_task ()

That is, when urb exists, hci_rx_task () is finally called ()

When the package type is HCI event, call hci_event_packet ()
In hci_event_packet (), the system determines the event and processes it.

The following uses hci_ev_disconn_complete as an example to see how the event is processed. This event indicates that the connection is disconnected. Reason indicates the reason for disconnection.

Hci_ev_disconn_complete
Event is handled by the handler hci_disconn_complete_evt. The following describes in detail:

1. hci_dev_lock (): Use the spin lock to get the resource.

2. hci_conn_hash_lookup_handle (): Find the corresponding connection from the connection queue. Note: When an ACL or SOC connection exists, the connection will be added to the connection chain.
Table.

3. Change the connection state to bt_closed.

4. hci_proto_disconn_ind ():
Call disconn_ind () in the global variable hci_proto ().

Note: In L2CAP protocol
Hci_register_proto () is called during insmod. The global variable hci_proto is assigned a value.
Disconn_ind = l2cap_disconn_ind;

Therefore, when the HCI Layer gets disconnect, it will notify the L2CAP layer to delete the channel.

Because the state is changed to bt_closed
When the layer calls poll (and finally calls bt_sock_poll), it will find that pollhup is set.

In this way, The L2CAP application can know that the connection has been disconnected.

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.