基于Android P版本分析
通话过程协议分析
接听电话 - AG
从AG端接听Incoming call的流程比较简单,其中包括了几个动作:来电、响铃和接听,AG只是会通过+CIEV、RING和AT+CLCC等指令进行交互,其中通过+CIEV指令更新callsetup和call状态;

来电
+CIEV
yaml
Bluetooth HFP Profile
[Role: AG - Audio Gate (1)]
AT Stream: \r\n+CIEV: 2,1\r\n
Command 0: +CIEV
Command: +CIEV (Indicator Events Reporting)
Type: Response (0x003a)
Parameters
Indicator Index: 2
Indicator 2: 1
- Indicator Index = 2:对应了AT+CIND指令的Indicator,index = 2对应的是callsetup;
- Indicator 2 = 1:对应了callsetup的1,意为正在呼叫中,但是不区分是outgoing还是incoming;
+AT+CLCC
yaml
Bluetooth HFP Profile
[Role: HS - Headset (2)]
AT Stream: AT+CLCC\r
Command 0: +CLCC
Command Line Prefix: AT
Command: +CLCC (Current Calls)
Type: Action Command (0x000d)
Parameters: No
yaml
Bluetooth HFP Profile
[Role: AG - Audio Gate (1)]
AT Stream: \r\n+CLCC: 1,1,4,0,0,"18717895345",129\r\n
Command 0: +CLCC
Command: +CLCC (Current Calls)
Type: Response (0x003a)
Parameters
ID: 1
Direction: Mobile Terminated (1)
State: Incoming (4)
Mode: Voice (0)
Mpty: Call is not one of multiparty (conference) call parties (0)
Number: "18717895345"
Type: The phone number format may be a national or international format, and may contain prefix and/or escape digits. No changes on the number presentation are required. (129)
- ID = 1:当前电话是第几路,从 1 开始计数;
- Direction:电话方向,0代表往外拨打的电话outgoing;1代表来电incoming;
- State:电话状态,当前状态为4,意为incoming;
- Mode:电话模式,当前模式为0,意为voice;
- Mpty:是否为多方通话的电话,0代表当前为非多方通话状态;
- Number:来电号码
- Type:可选项,电话类型,129代表了国内号码;
选择编解码器
选择编解码器逻辑基本上和拨号逻辑类同;
+BCS & AT+BCS
yaml
Bluetooth HFP Profile
[Role: AG - Audio Gate (1)]
AT Stream: \r\n+BCS: 2\r\n
Command 0: +BCS
Command: +BCS (Bluetooth Codec Selection)
Type: Response (0x003a)
Parameters
Codec: mSBC (2)
当前选用的编解码器为mSBC,AT+BAC指令用于获取蓝牙可用编解码器,而对应的AT+BCS指令用于指定使用哪种编解码器;
yaml
Bluetooth HFP Profile
[Role: HS - Headset (2)]
AT Stream: AT+BCS=2\r
Command 0: +BCS
Command Line Prefix: AT
Command: +BCS (Bluetooth Codec Selection)
Type: Action Command (0x003d)
Parameters
Codec: mSBC (2)
然后返回对应的OK Response;
同步连接请求
响铃
RING
yaml
Frame 501: 21 bytes on wire (168 bits), 21 bytes captured (168 bits)
Bluetooth
[Source: HuaweiDe_42:c7:dd (30:aa:e4:42:c7:dd)]
[Destination: BarrotTe_50:67:20 (04:7f:0e:50:67:20)]
Bluetooth HCI H4
Bluetooth HCI ACL Packet
Bluetooth L2CAP Protocol
Bluetooth RFCOMM Protocol
Bluetooth HFP Profile
[Role: AG - Audio Gate (1)]
AT Stream: \r\nRING\r\n
Command 0: RING
Command: RING (Incoming Call Indication)
Type: Response (0x0d0a)
Parameters: No
AT+CLIP & +CLIP
一般情况下,AT+CLIP指令和+CLIP指令不会出现,即AT+CLIP指令的Response不是+CLIP;
AT+CLIP指令,标准呼叫线路识别通知激活AT命令,它启用/禁用呼叫线路识别通知主动结果代码 +CLIP;
该指令的执行时间一般是在ProfileService启动阶段就设置好了;
yaml
..............................
Bluetooth HFP Profile
[Role: HS - Headset (2)]
AT Stream: AT+CLIP=1\r
Command 0: +CLIP
Command Line Prefix: AT
Command: +CLIP (Calling Line Identification Notification)
Type: Action Command (0x003d)
Parameters
Mode: Enabled (1)
- Mode:Enabled (1),启用呼叫线路识别通知激活,0代表禁用;
对应的Response为OK;
呼叫线路识别通知激活之后,就可以等待incoming;
yaml
Bluetooth HFP Profile
[Role: AG - Audio Gate (1)]
AT Stream: \r\n+CLIP: "18717895345",129\r\n
Command 0: +CLIP
Command: +CLIP (Calling Line Identification Notification)
Type: Response (0x003a)
Parameters
Number: "1871789xxxx"
Type: The phone number format may be a national or international format, and may contain prefix and/or escape digits. No changes on the number presentation are required. (129)
- Number:来电号码;
- Type = 129:国内号码;
AT+CLCC & +CLCC
yaml
Bluetooth HFP Profile
[Role: HS - Headset (2)]
AT Stream: AT+CLCC\r
Command 0: +CLCC
Command Line Prefix: AT
Command: +CLCC (Current Calls)
Type: Action Command (0x000d)
Parameters: No
yaml
Bluetooth HFP Profile
[Role: AG - Audio Gate (1)]
AT Stream: \r\n+CLCC: 1,1,4,0,0,"18717895345",129\r\n
Command 0: +CLCC
Command: +CLCC (Current Calls)
Type: Response (0x003a)
Parameters
ID: 1
Direction: Mobile Terminated (1)
State: Incoming (4)
Mode: Voice (0)
Mpty: Call is not one of multiparty (conference) call parties (0)
Number: "1871789xxxx"
Type: The phone number format may be a national or international format, and may contain prefix and/or escape digits. No changes on the number presentation are required. (129)
- ID = 1:路线1;
- Direction = 1:来电;
- State = 4:来电状态;
- Mode = 0:voice;
- Mpty = 0:非多方通话;
- Number = 1871789xxxx:来电号码;
- Type = 129:国内号码;
然后 AT+CLCC & +CLCC指令组合会一直响应,在响铃阶段和通话阶段都会响应,只是响应的状态值不一样;
然后返回对应的Response为OK;
接听
+CIEV: 1,1
yaml
Bluetooth HFP Profile
[Role: AG - Audio Gate (1)]
AT Stream: \r\n+CIEV: 1,1\r\n
Command 0: +CIEV
Command: +CIEV (Indicator Events Reporting)
Type: Response (0x003a)
Parameters
Indicator Index: 1
Indicator 1: 1
- call = 1:代表了至少有一个电话在进行中,call 状态从 0 -> 1,代表了从未接通状态到接通状态的变化;
+CIEV: 2,0
yaml
Bluetooth HFP Profile
[Role: AG - Audio Gate (1)]
AT Stream: \r\n+CIEV: 2,0\r\n
Command 0: +CIEV
Command: +CIEV (Indicator Events Reporting)
Type: Response (0x003a)
Parameters
Indicator Index: 2
Indicator 2: 0
- callsetup = 0:代表了当前没在呼叫中,callsetup 状态从 1 -> 0,代表了从呼叫状态到结束呼叫状态的变化;
通话中
AT+CLCC & +CLCC
HF侧向AG侧发送 Action Command 类型的 AT+CLCC 指令,请求列出当前的呼叫状态信息;
yaml
Bluetooth HFP Profile
[Role: AG - Audio Gate (1)]
AT Stream: \r\n+CLCC: 1,1,0,0,0,"18717895345",129\r\n
Command 0: +CLCC
Command: +CLCC (Current Calls)
Type: Response (0x003a)
Parameters
ID: 1
Direction: Mobile Terminated (1)
State: Active (0)
Mode: Voice (0)
Mpty: Call is not one of multiparty (conference) call parties (0)
Number: "1871789xxxx"
Type: The phone number format may be a national or international format, and may contain prefix and/or escape digits. No changes on the number presentation are required. (129)
- ID = 1:路线1;
- Direction = 1:来电;
- State = 0:活跃状态,即通话中;
- Mode = 0:voice;
- Mpty = 0:非多方通话;
- Number = 1871789xxxx:来电号码;
- Type = 129:国内号码;
而该指令的响应直到通话结束之后,才会停止响应;
接听电话 - HF
和拨打阶段类似,在HF响应操作的时候,对应ATD多了一个ATA的指令操作,该指令为标准呼叫应答命令,用于HF侧告知AG侧接电话;

接听
ATA
yaml
Bluetooth HFP Profile
[Role: HS - Headset (2)]
AT Stream: ATA\r
Command 0: A
Command Line Prefix: AT
Command: A (Call Answer)
Type: Action Command (0x000d)
Parameters: No
- Command:A,CAll Answer,电话应答指令;
然后返回对应的OK Response;