Learn the basics of Bluetooth learning records for Linux with cainiao

Source: Internet
Author: User

 

Bluetooth is an emerging technology. Its main purpose is to establish a short-range wireless communication standard around the world. It uses the 2.4-2.5 GHz ISM (industrion scientifcmedical) band to transmit voice and data. Using mature, practical, and advanced wireless technology to replace cables, it provides low-cost, low-power wireless interfaces that enable all fixed and mobile devices such: computer systems, home theater systems, cordless telephone systems, communication devices, and so on can communicate with each other through the pan and personal area network to share resources.

 

Bluetooth specifications

The standard of Bluetooth is 802.15, which is in the 2.4 GHz band and has a bandwidth of 1 Mb/s. The baseband protocol is a combination of circuit switching and group switching. One frequency hopping sends one synchronous group, each of which occupies one time slot and can be extended to five time slots using the Spread Spectrum Technology. At the same time, Bluetooth technology supports one asynchronous data channel, three concurrent synchronous voice channels, or one channel for simultaneous transmission of asynchronous data and synchronous voice. Each voice channel supports synchronous voice at 64 KB/S. asynchronous channels support asymmetric connections with a maximum rate of 432 KB/s and a reverse response rate of 57. 6 kb/s, or.
6 kb/s symmetric connection.

Depending on the output power, there are three distance levels for Bluetooth transmission: class1 is about M, class2 is about 10 m, and class3 is about 2-3 m. Generally, the normal working range is within a 10 m radius. In this range, multiple devices can be interconnected.

The features of Bluetooth technology include: 1. Using frequency hopping technology, short data packets, strong anti-signal attenuation capability; 2. Using fast frequency hopping and forward correction solutions to ensure link stability, reduce the impact of same-frequency interference and random noise during long-distance transmission; 3. Use the 2.4ghzism band without applying for a license; 4. Support for both data, audio, and video signals; 5. Use FM modulation to reduce the complexity of the device.

 

About Bluetooth devices

Bluetooth Technology divides devices into two types: master device and slave device.

Features of the Bluetooth main device: the main device generally has an input. During Bluetooth matching, you can enter a random password at the input end to match the two devices. Bluetooth mobile phones and PCs with Bluetooth modules are all master devices. (For example, when a Bluetooth mobile phone matches a Bluetooth PC, you can enter a group of numbers on the Bluetooth mobile phone, and then enter the same group of numbers on the Bluetooth PC, to match the two devices .)

Bluetooth slave device features: the slave device generally does not have an input. Therefore, when a device leaves the factory, a four-or six-digit password is fixed in its Bluetooth chip. Bluetooth headsets and ustong UD pens are all from the device. (For example, when the Bluetooth PC matches the UD pen, the user enters the correct Bluetooth password on the UD pen to the Bluetooth PC to complete the matching between the UD pen and the Bluetooth PC .)

 

About Bluetooth connections

When a Bluetooth master device initiates a call, the first step is to find the bluetooth device that is nearby and the slave device must be in the available status.

After the master device finds the slave device and matches it with the slave device, enter the PIN code of the slave device. Generally, the default value of the Bluetooth headset is 1234 or 0000, the default value of the stereo Bluetooth headset is 8888. You do not need to enter a pin for a device.

After pairing, the slave bluetooth device records the trust information of the master device. In this case, the master can initiate a call to the slave device, it may be an ACL Data Link call or an SCO voice link call. During the next call, the paired device no longer needs to be re-paired.

A paired device, as a slave-end Bluetooth headset, can also initiate a leeching request, but the bluetooth module for data communication generally does not initiate a call.

After the link is successfully established,Two-way data or voice communication can be performed between the master and slave ends..

In the communication status,Both the master and slave devices can initiate a disconnection to disconnect the bluetooth link..

 

Architecture of the Bluetooth protocol stack

The Official Bluetooth protocol stack for Linux is the bluez protocol stack, as shown in architecture 1. It consists of three parts: the underlying hardware module, the intermediate protocol layer, and the high-end application layer.

Figure 1: Architecture of the Bluetooth protocol stack

 

1. underlying hardware moduleIt is the core module of Bluetooth technology. All devices embedded with Bluetooth technology must include the underlying module. It consists of LMP link manager protocol, BB base band, and RF rodio frequency. Its functions are as follows:

Wireless connection layer (RF): Data Stream filtering and transmission are achieved through the ISM band that does not need to be applied for at GHz. It mainly defines the requirements that the bluetooth receiver working in this band should meet;

Baseband layer (bb): Provides two different physical links (synchronous for connection link SCO synchronous connectionoriented and asynchronousconnection less), responsible for the transmission of frequency hopping and Bluetooth data and information frames, all types of data packets are provided with FEC frequency errorcorrection or CTC Cyc LIC redundancycheck );

LMP layer:Establishes and removes two or more Device Links and ensures the security and control of the links, such as authentication and encryption, and controlling and coordinating the size of the carrier package, it provides different access portals for upper-layer software modules;

Bluetooth Host Controller Interface HCI (Host Controller Interface): It consists of a baseband controller, a connection manager, a control, and an event register. It is an interface between software and hardware in the Bluetooth protocol. It provides a unified command to call the underlying hardware, such as BB, lm, status, and control register, messages and data transmission between the upper and lower module interfaces must be explained by HCI. The protocol software entity above the HCI Layer runs on the host, while the functions below HCI are completed by the bluetooth device, and the two interact through the transport layer.

 

2. Intermediate protocol layerProtocol L2CAP (Logical Link Control andadaptation Protocol) and Service Discovery Protocol (SDP) serial Port simulation protocol or cable replacement protocol rfcom and binary Telephone Control Protocol TCS (Telephony

Control Protocol spectocol.

Logical Link Control and Adaptation Protocol (L2CAP): It is the core component of the Bluetooth protocol stack and also the basis for implementation of other protocols. It is located on top of the baseband and provides connection-oriented and connectionless data services to the upper layer. It mainly implements data disassembly, service quality control, protocol reuse, grouping segmentation and reorganization (segmentation andreassembly) and group extraction functions. L2CAP allows data groups up to 64 KB.

Service Discovery Protocol (SDP): A protocol based on the Client/Server structure. It works on The L2CAP layer and provides a mechanism for upper-layer applications to discover available services and their attributes, the service attributes include the service type and the mechanism or protocol information required by the Service.

Serial Port simulation protocol or cable replacement protocol RFCOMM: It is a wireless data simulation protocol used to simulate wired links. It complies with the ETSI standard TS 07.10 serial port simulation protocol. It simulates the control and data signal of the RS-232 on the Bluetooth baseband to provide the transmission capability for the upper-layer services that used the serial connection.

Binary Telephone Control Protocol (TCS)It is a bit-oriented protocol based on ITU-TQ.931 recommendations, which defines the Call Control Signalling for establishing voice and data calls between bluetooth devices ), and handles the mobile management process of the bluetooth device group.

 

3. High-end application layerLocated at the top of the Bluetooth protocol stack. A complete Bluetooth protocol stack can be divided into four layers based on its functions: core protocol layer (BB, LMP, lcap, SDP), and cable replacement protocol layer (RFCOMM) telephone control protocol layer (TCS-BIN), select protocol layer (PPP, TCP, TP, UDP, OBEX, irmc, WAP, WAE ).

The high-end application layer is composed of the selected protocol layer.

Select protocol layerPPP (Point-to-Point Protocol) is a point-to-point protocol.It consists of encapsulation, Link Control Protocol, and network control protocol. It defines how the serial point-to-point link should transmit Internet protocol data, it is mainly used for LAN access, dial-up network, fax and other application specifications;TCP/IP (Transport Control Protocol/Network Layer Protocol), UDP (User datasync protocol Object Exchange Protocol)Is three existing protocols, which define the communication between the Internet and the network and between other types of computer devices and peripheral devices. Bluetooth uses or shares these existing protocols to achieve communication with devices connected to the Internet, which improves efficiency, it can also ensure the interoperability between Bluetooth and other communication technologies to a certain extent;

Obex (Object Exchange Protocol) is an object exchange protocol.It supports data exchange between devices and provides the same basic functions as HTTP (Hypertext Transfer Protocol) in the customer/Server mode. As an open standard, this Protocol also defines formats such as e-business cards, personal calendars, messages, and notes that can be exchanged;

WAP (Wireless Application Protocol) is a Wireless Application Protocol.It aims to implement Internet services on digital cellular phones and other small wireless devices. It allows mobile phones to browse Web pages, receive emails, and other Internet-based protocols.

WAE (wireless application environment) is a wireless application environment.It provides various application software required for WAP calls and Personal Digital Assistant PDA (Personal digtital Assistant.

Bluetooth audio (audio)It is implemented by directly transmitting SCO groups on the baseband. Currently, the Bluetooth sig does not provide this part in a standard form. Although it is not strictly a part of the Bluetooth protocol specification, it can also be regarded as a direct application-oriented layer in the Bluetooth protocol system.

 

 

The HCI Layer is located at the intermediate layer and the underlying layer of the Bluetooth protocol, and serves as a communication between the two (Figure 2 describes the position of the HCI Layer in the underlying software ). At the same time, the HCI Layer is also the interface between the Bluetooth Software and the Bluetooth hardware. The Bluetooth Software communicates with the Bluetooth hardware through a series of interfaces provided by the HCI Layer. That is, the Bluetooth Software sets and controls the Bluetooth adapter through the interface functions of the HCI Layer.

HCI can also read and set parameters for remote Bluetooth devices.


Figure 2: HCI Architecture

Three basic functions of HCI.

1. Read and set the parameters of the local Bluetooth device;

2. scans the peripheral devices and reads and sets the basic parameters of the remote Bluetooth device;

3. provides an interface for sending HCI commands. You can directly use the HCI command to control the local Bluetooth adapter.

The HCI Layer of bluez is based on the C/S mode described above. Generally, the bluetooth device that initiates a session will act as the client in C/S mode, and the connected remote device will act as the server. In Linux, after a Bluetooth Application is started, its daemon (daemon, which runs in the background, is used to provide a certain service program for the System) mongothd acts as a server in the C/S model and can respond to remote queries and connection requests.

(1) Implementation of the local device parameter reading module

The get_dev_infor () function is used to read local device parameters. This interface provides the bd_addr, dev_name, dev_id, and other parameters of the local device that contain the hci_dev_info structure. This struct is used to describe the basic parameters of a device. In addition, the local parameter reading module also provides an interface for a specific parameter. For example, get get_localnameo of the local device name and get_local_addr0 of the local bd_addr. The implementation process is similar to reading remote device parameters, except that a socket connection is not required and remote device query is not required. The data processing method and implementation method are the same. Here, we will only describe the reading process of remote devices.

(2) remote device parameter reading module implementation

The function of the remote device parameter reading module is basically the same as that of the previous module. The difference is that you need to query the peripheral devices to obtain the bd_addr of the remote device and fill in the inquiry_info structure. Then, the local device establishes a connection with it, and the parameter is passed. In addition, other parameters of the remote device can be read by calling functions such as hciread_remotename0, hciread_remoteversion0, and hci_read_remote_featureso.

 

 

In the Bluetooth protocol stack, The L2CAP layer is located on the HCI Layer, that is, the Logical Link Control and adaptation layer (Logical Link Control andadaptation protoc01 ).

The location of L2CAP in Bluetooth protocol is 3.9. It is between the underlying and high-level protocols. L2CAP provides link-oriented and Non-Linked Data Services to high-level protocols through protocol multiplexing, segmentation and restructuring operations, and group concepts. L2CAP allows high-level protocols and applications to transmit up to 64 kB L2CAP groups.

 

 

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.