当前位置:网站首页>Bluetooth development (3) -- look at the air bag

Bluetooth development (3) -- look at the air bag

2022-06-11 00:08:00 yuanyun_ elber

stay initial At this stage, we saw a lot of hci command and hci event Interaction ,controller stay init After that, the initialization is completed , The state has also become HCI_INIT_DONE.

The next step is to go into a program called GAP Of profile,GAP This profile And others profile The obvious difference is , other profile It's all based on l2cap Of , and gap No .

Let's take a look first gap The definition of :

GAP,Generic Access Profile, The Profile Make sure it's different Bluetooth Products can discover each other and connect with each other

GAP Defines how Bluetooth devices discover and establish security with other devices / Unsafe connection
It handles some general business models ( If asked 、 Name and search ) And some security issues ( Such as guarantee )
At the same time, it also handles some services related to connection ( Such as link establishment 、 Channel and connection establishment )

GAP It stipulates some general operation tasks ; therefore , It is mandatory , And as the basis of all other Bluetooth application specifications

Gap It's called profile, Because it is also an application .

For example , Bluetooth on our mobile phones , You need to enter the Bluetooth settings menu , Open to pair , then Enter a state that can be discovered by other Bluetooth devices . This is the time , It's actually called gap The interface of .

 

This time, we'll grab the bag , That is from initial After completion , This order begins to enter gap Stage .

Basically, there is no room for one screen , because GAP The things involved in the layer include discovery 、 Connect 、 authentication 、 Encryption, etc , There are still a lot to talk about .

As controller Speaking of , This time and initial Compared with the first stage of , The biggest difference , Is to start interacting with the outside world .

We can take a look at the air bag .

As shown in the figure , A large number of LMP package , So-called LMP package , In fact, it is marked by the red line ACL-C package . these LMP The contents of the package are controller act , The upper level is not clear , The participation of the upper level at this stage , Mainly to controller dispatch orders , Give Way controller Enter a state , Pairable 、 Connectable 、 Read remote device information 、 encryption … wait .

And after this stage , other profile When I started working ,host The sense of participation is stronger , You can see the bags under the red box , All are l2cap Layers above the package , These bags are from host Layers pass through hci acl data The interface is distributed to controller, from controller adopt ACL –U Packets are sent to the remote end in this format .

Speaking of ACL-C\ACL-U, This stage , It is necessary for us to talk about the format of Bluetooth packets .

Take a look at the picture below , I remember an interview , An interviewer asked me about the format of Bluetooth packets , Although there are in the protocol specifications , But Bluetooth people , If you can't recite it , Is also to be despised .

First of all access code, Which includes PA,preamble, Basically, wireless communication is indispensable , Including SYNC WORD,SYNC WORD The Bluetooth address is hidden in the middle , We know that today's wireless environment is complex , There are so many bags in the air , How do we know which bags we need , According to the Bluetooth address , A lot of junk information , stay access code You can filter it out .

The picture below is access code The format of :

And then there was Packet header,packet header It mainly includes Lt_addr, This address is used to distinguish slave The equipment , Then the format of the package , Include DM1、2DH3、2EV3 And so on , Coding efficiency of different formats 、 The anti-interference performance is different , The baseband will automatically select the appropriate format to send packets according to the environment

Then flow control ,ARQ( Question and answer mechanism ), Serial number, etc , And finally a HEC Check code

stay packet header There's one in the back guard Sync , Because if it is edr Words , The modulation mode is different before and after , Need to resynchronize .

And then there was payload header, We will only discuss here acl package ,(sco Package does not discuss ) The package format mentioned above is in this LLID Contains , Actually LLID There are no more than two package formats , One is LMP-C, One is LMP-U, It's just that the LMP-U Contents related to subcontracting , We also know that l2cap Tier supports subcontracting , The main implementation is in LLID The middle mark is start Package or continous package . Pay attention to this payload header and header There is a flow control bit , It's easy to confuse , The specific contents are as follows .

And then there is payload body 了 , This is exactly what our upper level agreement issued .

controller When receiving packets , First, at the scheduled reception slot On , Turn on according to the preset FM sequence RF, If you receive access code Words , Determine the Bluetooth address , If it wasn't sent to us , Direct filtration , Then receive packet header, Among them is HEC check , If the check does not pass , And direct filtration , Then adjust RF, receive payload,payload Finally, there is crc Verified , If crc If it doesn't pass , Will be filtered out again , So finally controller to host The data package has been reached through thousands of mountains and rivers , Is reliable .

原网站

版权声明
本文为[yuanyun_ elber]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203020629284555.html