BT[0]-BT&BLE協議棧概覽


Overview

Bluetooth standard offers basic rate (BR) or enhanced data rate (EDR) and Bluetooth Low Energy (LE) support. Devices that can support BR/EDR and Bluetooth LE are referred to as dual-mode devices. Typically, in a Bluetooth system, a mobile phone or laptop computer acts as a dual-mode device.
Devices that only support Bluetooth LE are referred to as single-mode devices where the low power consumption is the primary concern for application development, such as those that run on coin cell batteries.
This article focus on:

  • Detailed description of the BR/EDR profiles.
  • Bluetooth LE profiles.

1.1 Bluetooth protocol stack

The Bluetooth protocol stack consists of two sections, the controller and the host, derived from the original Bluetooth core specification where the two sections were often implemented separately.

1.1.1 BR/EDR protocol stack

The BR/EDR protocol stack architecture is illustrated in Figure 1.

The controller section includes the Physical Layer (PHY), Link Layer (LL) and Host-Controller Interface (HCI).

  • 1) The physical layer (PHY) is the lowest layer of the Bluetooth protocol stack to manage physical channels and links.
  • 2) The link layer (LL) is used to control the radio link between two devices, handling matters such as link establishment, querying device abilities and providing power control.
  • 3)The host control interface (HCI) provides a means of communication between the host and controller using a standardized interface.

The host includes various communication protocols, as described below.

  • 1) The logical link control and adaption protocol (L2CAP) provides data encapsulation services to the upper layers that enable logical end-to-end data communication.
  • 2) The radio frequency communication (RFCOMM) is a set of transport protocols on top of the L2CAP protocol, providing emulated RS-232 serial ports.
  • 3) The generic access profile (GAP) defines the generic procedures related to discovery of Bluetooth devices and link management aspects of connecting to Bluetooth devices.
  • 4) The service discovery protocol (SDP) is used to allow devices to discover the supported services, and parameters to use to connect to them.
  • 5) The hands-free profile (HFP) allows hands-free kits to control the mobile phone of calling functions and provide the voice connection between devices.
  • 6) The object exchange (OBEX) is a communications protocol that facilitates the exchange of binary objects between devices.
  • 7) The phonebook access profile (PBAP) defines the procedures and protocols to exchange phonebook objects between devices.
  • 8) The Advanced Audio Distribution Profile (A2DP) defines how multimedia audio is streamed from one device to another via Bluetooth connection
  • 9) The audio/video distribution transport protocol (AVDTP) is used by the advanced audio distribution profile to stream music to stereo headsets over the L2CAP channel intended for video distribution profile in the Bluetooth transmission.
  • 10) The audio/video control transport protocol (AVCTP) is used to transport the command/response messages exchanged for the control of distant A/V devices over point-to-point connections.
  • 11) The audio/video remote control profile (AVRCP) defines the features and procedures required in order to ensure interoperability between Bluetooth devices with audio/video control functions in the audio/video distribution scenarios.
  • 12) The serial port profile (SPP) emulates a serial cable to provide a simple substitute for existing RS-232.

1.1.2 Bluetooth LE protocol stack

The Bluetooth LE protocol stack architecture is shown in Figure 2.

附錄

RK3308藍牙使用

系統概況:

# uname -a
Linux rockchip 4.4.143 #9 SMP PREEMPT Wed Feb 13 18:38:41 CST 2019 armv7l GNU/Linux
藍牙芯片:AP6212

1、查看電源是否開啟

# cd /sys/class/rfkill
# ls
rfkill0  rfkill1  rfkill2
# rfkill <--- 查看藍牙對應的目錄
ID TYPE      DEVICE             SOFT      HARD
 0 bluetooth bt_default      blocked unblocked
 1 wlan      phy0          unblocked unblocked
 2 wlan      brcmfmac-wifi unblocked unblocked
# cd rfkill0/
# cat state <--- 查看電源狀態
0 <--- power down
# echo 1 > ./state  <--- power up
[  423.917629] [BT_RFKILL]: rfkill_rk_set_power: set bt wake_host pin output high!
[  423.980538] [BT_RFKILL]: rfkill_rk_set_power: set bt wake_host pin input!
[  423.980608] [BT_RFKILL]: ENABLE UART_RTS
[  424.081438] [BT_RFKILL]: DISABLE UART_RTS
[  424.081539] [BT_RFKILL]: bt turn on power

 

2、查看藍牙是否啟動

# hciconfig -a
  <--- 藍牙設備未啟動
# brcm_patchram_plus1 --bd_addr_rand --enable_hci --no2bytes --use_baudrate_for_download  --tosleep  200000 --baudrate 1500000 --patchram  /system/etc/firmware/bcm43438a1.hcd /dev/ttyS4 & <--- 啟動藍牙設備
# hciconfig -a
hci0:	Type: Primary  Bus: UART
	BD Address: 90:1B:07:8D:34:B0  ACL MTU: 1021:8  SCO MTU: 64:1
	DOWN <--- 藍牙Down狀態
	RX bytes:612 acl:0 sco:0 events:30 errors:0
	TX bytes:398 acl:0 sco:0 commands:30 errors:0
	Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
	Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 
	Link policy: RSWITCH SNIFF 
	Link mode: SLAVE ACCEPT 

 

3、激活藍牙

# hciconfig hci0 up
# hciconfig dev
hci0:	Type: Primary  Bus: UART
	BD Address: 90:1B:07:8D:34:B0  ACL MTU: 1021:8  SCO MTU: 64:1
	UP RUNNING 
	RX bytes:1224 acl:0 sco:0 events:60 errors:0
	TX bytes:796 acl:0 sco:0 commands:60 errors:0

# hciconfig -a <--- 查看詳細信息
hci0:	Type: Primary  Bus: UART
	BD Address: 90:1B:07:8D:34:B0  ACL MTU: 1021:8  SCO MTU: 64:1
	UP RUNNING 
	RX bytes:1224 acl:0 sco:0 events:60 errors:0
	TX bytes:796 acl:0 sco:0 commands:60 errors:0
	Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
	Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 
	Link policy: RSWITCH SNIFF 
	Link mode: SLAVE ACCEPT 
	Name: 'BCM43438A1 26MHz AP6212A1_CL1 BT4.0 OTP-BD-0058'
	Class: 0x000000
	Service Classes: Unspecified
	Device Class: Miscellaneous, 
	HCI Version: 4.0 (0x6)  Revision: 0xf9
	LMP Version: 4.0 (0x6)  Subversion: 0x2209
	Manufacturer: Broadcom Corporation (15)

 

4、掃描看下

# hcitool scan
Scanning ...
	00:1A:7D:DA:71:13	CHENTONG1070
	70:BB:E9:C7:1B:1C	小米手機
	94:87:E0:B4:09:82	小米手機8
	50:3C:EA:AF:D7:00	OPPO R11s
	20:47:DA:BE:3B:B3	小米手機6
	28:B2:BD:CA:69:BB	GUOZF668
	20:18:06:25:62:79	HC-05
	34:D7:12:91:DC:C0	堅果 Pro 2 特別版

 

參考資料:

https://github.com/fredldotme/brcm-patchram-plus.git


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM