Bluetooth programming in Linux

Source: Internet
Author: User

1.
HCI
Layer Protocol Overview:

HCIProvides a unified method to access the underlying layer of Bluetooth. :

 

 

 

As shown in the figure,Host Controller Interface (HCI)Is used to communicate with the host and module. The host is usually a PC, and the module is connected to Bluetooth on the PC in various physical connection forms (USB, serial, PC-card, etc.).
Dongle.

At the host end, protocols such as application, SDP, and L2CAP are all proposed in the form of software (bluez uses the kernel layer program ). At the module end, protocols such as link manager and BB are provided by firmware in hardware.

WhileHCISome of them are implemented in software to provide access interfaces for upper-layer protocols and programs (in bluez,HCI. C
HCI_ USB. C,HCI_ Sock. c). The other part is also implemented in firmware, which is used to transmit the commands of the software part to the underlying layer in a way that the underlying protocol understands.

 

Between the upper-Layer Program and protocol in the PC and the lower-layer protocol in the modulesHCICommunication, there are four different forms of transmission:Commands,
Event, ACL data, SCO/ESCO data.

 

1.1.
HCI
Command:

HCI commandHost sends commands to modules.HCI commandThe packet structure is as follows:

Opcode is used to uniquely identifyHCI commandIt consists of two parts, 10 bit opcode
Command. 6-bit opcode group.

1.1.1: opcode group:

Linux Kernel (bluez ,~ /Include/NET/Bluetooth/HCIOpcode group is defined in. h.

# Define ogf_link_ctl 0x01

# Define ogf_link_policy 0x02

# Define ogf_host_ctl 0x03

# Define ogf_info_param 0x04

# Define ogf_status_param 0x05

They represent differentCommandGROUP:

 

Ogf_link_ctl:Link Control, thisCommandIn groupCommandAllow Host Control and other Bluetooth
Device connection.

Ogf_link_policy: Link policy. ThisCommandIn groupCommandAllow link adjustment
Manager Control.

Ogf_host_ctl:Control and baseband.

 

1.1.2: opcode
Command:
 

Used for unique identification within the same groupCommand.~ /Include/NET/Bluetooth/HCI. H.

 

 

1.2:
HCI event
:

Modules sends some information to the host.HCI event.EventThe packet structure is as follows:

HCI eventThere are three types:CommandComplete
Event,
Command
States
Event
,CommandSubsequently completend.

CommandComplete
Event
:
If the host sendsCommandThis class is sent if a result is available immediately.Event. That is to say, ifCommandIt is only related to local modules and does not deal with remote devices.Command
CompleteEvent. For example:HCI_ Read_buffer_size.

CommandStates
Event:
If the host sendsCommandIf you do not know the result immediately, send this classEvent. The host sendsCommandThe execution must deal with the remote device, so the result cannot be immediately known, so it will sendCommand
StatesEvent. Example:

HCIConnect.

CommandSubsequently completend: CommandDelayed completionEvent. For example, the connection has been established.

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.