蓝牙协议HFP(Hands-Free Profile)电话免提协议 Connection management 连接管理HFP SLC 的建立跟释放

article/2025/6/19 15:40:23

零. 概述

本文章主要讲下电话免提协议HFP(Hands-Free Profile)Connection management。包括connection establishment     跟connection realease,那connection establishment又会涉及到HFP SLC的建立过程。

本节讲解的内容就是一下HFP feature中的NO.1

一. 声明

本专栏文章我们会以连载的方式持续更新,本专栏计划更新内容如下:

第一篇:蓝牙综合介绍 ,主要介绍蓝牙的一些概念,产生背景,发展轨迹,市面蓝牙介绍,以及蓝牙开发板介绍。

第二篇:Transport层介绍,主要介绍蓝牙协议栈跟蓝牙芯片之前的硬件传输协议,比如基于UART的H4,H5,BCSP,基于USB的H2等

第三篇:传统蓝牙controller介绍,主要介绍传统蓝牙芯片的介绍,包括射频层(RF),基带层(baseband),链路管理层(LMP)等

第四篇:传统蓝牙host介绍,主要介绍传统蓝牙的协议栈,比如HCI,L2CAP,SDP,RFCOMM,HFP,SPP,HID,AVDTP,AVCTP,A2DP,AVRCP,OBEX,PBAP,MAP等等一系列的协议吧。

第五篇:低功耗蓝牙controller介绍,主要介绍低功耗蓝牙芯片,包括物理层(PHY),链路层(LL)

第六篇:低功耗蓝牙host介绍,低功耗蓝牙协议栈的介绍,包括HCI,L2CAP,ATT,GATT,SM等

第七篇:蓝牙芯片介绍,主要介绍一些蓝牙芯片的初始化流程,基于HCI vendor command的扩展

第八篇:附录,主要介绍以上常用名词的介绍以及一些特殊流程的介绍等。

另外,开发板如下所示,对于想学习蓝牙协议栈的最好人手一套。以便更好的学习蓝牙协议栈,相信我,学完这一套视频你将拥有修改任何协议栈的能力(比如Linux下的bluez,Android下的bluedroid)。

-------------------------------------------------------------------------------------------------------------------------

CSDN学院链接(进入选择你想要学习的课程):https://edu.csdn.net/lecturer/5352?spm=1002.2001.3001.4144

蓝牙交流扣扣群:970324688

Github代码:https://github.com/sj15712795029/bluetooth_stack

入手开发板:https://item.taobao.com/item.htm?spm=a1z10.1-c-s.w4004-22329603896.18.5aeb41f973iStr&id=622836061708

蓝牙学习目录:https://blog.csdn.net/XiaoXiaoPengBo/article/details/107727900

--------------------------------------------------------------------------------------------------------------------------

二. HFP Connection management 介绍

HFP connection Management分为两个小节:1)connection establishment     2)connection realease

下面我们就来分别介绍下两个小节

2.1 connection establishment

Upon a user action or an internal event, either the HF or the AG may initiate a Service Level Connection establishment procedure.

A Service Level Connection establishment requires the existence of a RFCOMM connection, that is, a RFCOMM data link channel between the HF and the AG.

Both the HF and the AG may initiate the RFCOMM connection establishment. If there is no RFCOMM session between the AG and the HF, the initiating device shall first initialize RFCOMM.

When an RFCOMM connection has been established, the Service Level Connection Initialization procedure shall be executed.

其中以上的意思大概就是:在建立HFP SLC之必须要有一个RFCOMM通道,也就是HFP的Server channel必须存在

你可能会问HFP的SLC是什么,拿SLC(Service Level Connection)就是一堆HFP HF角色跟AG角色的一些AT command的交互,这些AT command交互完毕才叫HFP SLC建立,SLC建立的流程如下:

下面我们就来分别介绍下小步骤(注意哈,虚线部分是可选步骤,在SLC建立的时候可以不做)

2.1.1 Supported features exchange

First, in the initialization procedure, the HF shall send the AT+BRSF=<HF supported features> command to the AG to both notify the AG of the supported features in the HF, as well as to retrieve the supported features in the AG using the +BRSF result code.

这个过程很简单充当HF角色首先要发送AT+BRSF=<HF supported features>,AG会回复+BRSF=<AG supported features>

BRSF (Bluetooth Retrieve Supported Features),此命令就是用于HF和AG互相告知对方支持的特性,HF&AG的support feature都是一个32bit的数,HF的support feature的bit map为

其中bit7为V1.6才添加,bit 7,8,9是V1.7才添加,AG的support feature的bit map为:

其中bit9为V1.6才添加,bit10,11是V1.7才添加

2.1.2 Codec Negotiation(HFP V1.6增加的特性)

Secondly, in the initialization procedure, if the HF supports the Codec Negotiation feature, it shall check if the AT+BRSF command response from the AG has indicated that it supports the Codec Negotiation feature. If both the HF and AG do support the Codec Negotiation feature then the HF shall send the AT+BAC=<HF available codecs> command to the AG to notify the AG of the available codecs in the HF.

如果HF和AG都支持BRSF中的Codec negotiation,那么HF发送:

AT+BAC=<HF available codecs>

BAC(Bluetooth Available Codecs)

Description:

This command informs the remote device (AG) about what codecs (see Table 3.3) the HF

supports.The Codec ID for the mandatory narrow band codec (CVSD) shall always be included. If wide band speech is supported, then the mandatory codec (mSBC) shall be included unless it is temporarily unavailable.

Any other optional wide band speech codecs may also be included in this list as long as the

mandatory codec is included first.

这个命令是HF告知AG,自己支持的codec,CVSD就是NBS(窄带通话,8KHz)的编解码方式,mSBC就是WBS(宽带电话,16KHz)的编解码方式,ID如下表所示

2.1.3 AG Indicators

After having retrieved the supported features in the AG, the HF shall determine which indicators are supported by the AG, as well as the ordering of the supported indicators. This is because, according to the 3GPP 27.007 specification [2], the AG may support additional indicators not provided for by the Hands-Free Profile, and because the ordering of the indicators is implementation specific. The HF uses the AT+CIND=? Test command to retrieve information about the supported indicators and their ordering. Once the HF has the necessary supported indicator and ordering information, it shall retrieve the current status of the indicators in the AG using the AT+CIND? Read command. After having retrieved the status of the indicators in the AG, the HF shall then enable the "Indicators status update" function in the AG by issuing the AT+CMER command, to which the AG shall respond with

OK. As a result, the AG shall send the +CIEV unsolicited result code with the corresponding indicator value whenever a change in service, call, or call setup status occurs. When an update is required for both the call and call setup indicators, the AG shall send the +CIEV unsolicited result code for the call indicator before sending the +CIEV unsolicited result code for the call setup indicator. The HF shall use the information provided by the +CIEV code to update its own internal and/or external indications.

Once the "Indicators status update" function has been enabled, the AG shall keep the function enabled until either the AT+CMER command is issued to disable it, or the current Service Level Connection between the AG and the HF is dropped for any reason.

After the HF has enabled the “Indicators status update” function in the AG, and if the “Call waiting and 3-way calling” bit was set in the supported features bitmap by both the HF and the AG, the HF shall issue the AT+CHLD=? test command to retrieve the information about how the call hold and multiparty services are supported in the AG. The HF shall not issue the AT+CHLD=? test command in case either the HF or the AG does not support the "Three-way calling" feature.

这部分有几个重点:

① 发送AT+CIND=?问询支持的indicators(包括service/call/callsetup/callheld/signal/ roam/ battchg)的index

AT+CIND=?是问询AG有多少indicators,并且自己解析每个indicators的index

如图所示:service的index是1,call的index是2,callsetup的index是3,battchg的index是4,signal的index是5,roam的index是6,callheld的index是7,后续AG更新过来+CIEV是通过这个index来决定他是跟的什么值

② 发送AT+CIND?问询各个indicators的status,此命令就是统一问下各个indicator的值,接着上图问询AT+CIND?

如图,service的值为1,call的值为0,callsetup的值为0, battchg的值为2, signal的值为3, roam的值为0, callheld的值为0,那么你一定会好奇各个value的值代表什么意思,下面我们就一一贴出

2.1.4 AT+CMER

发送AT+CMER enable各个indicators,发送这个后,如果某一个indicator有变化,那么AG就可以发送+CIEV来告知

AT+CMER 是Standard event reporting activation/deactivation AT command.说白了就是使能/失能 indicator,一共有两种格式

AT+CMER=3,0,0,1 activates “indicator events reporting”.

AT+CMER=3,0,0,0 deactivates “indicator events reporting”.

使能之后,AG可以发送+CIEV命令来汇报各个indicator的变化

先来看下+CIEV AT command

+CIEV:Standard “indicator events reporting” unsolicited result code.

格式为:+CIEV: <ind>,<value>,举例来说(此部分要根据CIND的index来角色,每个AG可能index不同,所以代码重要有解析index的动作,我这个index是根据2.1.3小节的index来讲解)

如果后续AG发送过来 +CIEV:1,x那么就是service有变化,值为x,

如果AG发送过来+CIEV:5,x那么就是signal有变化,值为x

再来个具体的例子,如图

这个就说明signal的值有变化,变成了4

2.1.5 AT+CHLD=? 三方通话功能

以上三个发送完毕后,如果HF&AG都支持三方通话,那么发送AT+CHLD=?

此部分是问询手机三方通话的支持的特性都有哪些,一共有以下几个特性

比如如图就是支持0,1,1x,2,2x,3,下面我们就来说下每个值得功能,这个功能是以后三方功能HF主动给AG下AT command用的

0 = Releases all held calls or sets User Determined User Busy (UDUB) for a waiting call.

->相当于此时正在通话中,又有一通电话来,拒接来电

1 = Releases all active calls (if any exist) and accepts the other (held or waiting) call.

->挂断所有在通话中的电话,接听来电

1<idx> = Releases specified active call only (<idx>).

->挂断idx的通话中的电话

2 =Places all active calls (if any exist) on hold and accepts the other (held or waiting) call.

->把所有通话中的电话设置为hold状态,然后接听电话

2<idx> = Request private consultation mode with specified call (<idx>). (Place all calls on hold EXCEPT the call indicated by <idx>.)

->请求接受<idx>标识电话,让其它电话保持。

3 = Adds a held call to the conversation.

->增加一个保持电话到对话中

4 = Connects the two calls and disconnects the subscriber from both calls (Explicit Call Transfer). Support for this value and its associated functionality is optional for the HF.

->连接两个电话并且断开两个电话的订阅。HF侧可选。

注意此部分,虽然手机都显示支持,但是部分cmd手机还是会返回error,尤其带有idx的cmd

2.1.6 HF Indicators(HFP V1.7增加的特性)

If the HF supports the HF indicator feature, it shall check the +BRSF response to see if the AG also supports the HF Indicator feature. If both the HF and AG support the HF Indicator feature, then the HF shall send the AT+BIND=<HF supported HF indicators> command to the AG to notify the AG of the supported indicators’ assigned numbers in the HF. The AG shall respond with OK. After having provided the AG with the HF indicators it supports, the HF shall send the AT+BIND=? to request HF indicators supported by the AG. The AG shall reply with the +BIND response listing all HF indicators that it supports followed by an OK.

Once the HF receives the supported HF indicators list from the AG, the HF shall send the AT+BIND? command to determine which HF indicators are enabled. The AG shall respond with one or more +BIND responses. The AG shall terminate the list with OK. From this point onwards, the HF may send the AT+BIEV command with the corresponding HF indicator value whenever a change in value occurs of an enabled HF indicator. The AG may enable or disable the notification of any HF indicator at any time by using the +BIND

unsolicited response.

这部分有几个重点:

① 如果HF & AG都支持HF Indicators的feature,那么HF发送AT+BIND=<HF supported HF indicators>来告知AG支持那些indicator

② 发送AT+BIND=?问询AG支持哪些indicator

③ 发送AT+BIND?问询AG哪些indicator是enable的

④ 发送AT+BIEV来使能某一个indicator

HFP的indicator一共有两个:

下面我们来看下我们抓取的btsnoop(在资料中STM32_UBUNTU_BLUETOOTH\2-蓝牙资料\蓝牙协议分析\hfp_slc连接.log)

整个流程如下:

我们生成一个流程图

这些图放在这里当作你们的参考

2.2 Service Level Connection Release

断开连接比较简单,就是断开RFCOMM link就OK了

好了,本节内容到此结束


http://chatgpt.dhexx.cn/article/RwQj70Yu.shtml

相关文章

蓝牙A2DP和HFP编解码

一、A2DP A2DP全名是&#xff08;Advanced Audio Distribution Profile&#xff09; 蓝牙音频传输模型协定&#xff0c;提供通过蓝牙连接传输音频流的能力&#xff0c;比如手机播放音乐&#xff0c;蓝牙耳机通过蓝牙连接听歌。 mp3和flac音频编码都是在PCM音频编码基础上二次编…

Rockchip安卓11.0 16k wbs msbc HFP PCM语音通话支持

Rockchip安卓11.0 16k wbs/msbc HFP PCM语音通话支持 调试平台: 安卓11.0, rk3328, 博通ap6212芯片, HFP 8K已经调通的情况下. SDK修改支持16k wbs/msbc HFP PCM语音注意点如下: 1. bluedroid(system/bt) 博通方案中, ESCO_DATA_PATH_PCM 为1代表蓝牙芯片作为pcm master, 6…

蓝牙电话之HFP-电话音频

蓝牙电话之HFP协议中的电话音频 蓝牙技术通信的内容多种多样&#xff0c;其中音频部分包含媒体音频和电话音频。 媒体音频&#xff1a;播放蓝牙音乐的数据&#xff0c;这种音频对质量要求高&#xff0c;数据发送有重传机制&#xff0c;从而以l2cap的数据形式走ACL链路。编码方…

VSCode 按下tab键自动补全功能失效

问题描述&#xff1a;标签自动补全插件已经安装&#xff0c;某天按下tab键自动补全标签的功能突然失效了。解决方法&#xff1a; 1、找到路径 file > Preferences >settings 2、搜索tabs&#xff0c;选择Extensions里面的Emmet&#xff0c;将复选框的√打上就ok啦!

javascript 按下回车键触发input表单的切换(enter键代替tab键功能)

本来是想用js代码去模拟键盘按下来实现该功能&#xff0c;但是没有实现到。后来想到一种比较笨的方法。局限性是只能这些表单元素只能在同个层面下才能切换。 <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><m…

sublime text3 tab键功能失效

选择首选项 -> 快捷键设置 出现下面编辑页 在右边添加下面一些设置&#xff08;记得要用逗号与前面内容分开&#xff09;&#xff1a; { "keys": ["tab"], "command": "reindent", "context":[{ "key": "…

计算机键盘上的2个定位键,电脑键盘上Tab 键的神奇之处!(用途详解)

下面通过实例来详细解释下&#xff1a; 假设“D:\cfan”路径下&#xff0c;有文件夹&#xff1a; a、 ab &#xff0c;有文件&#xff1a; abc.txt &#xff0c; ac.txt 。依次点击“开始→运行”输入“cmd”&#xff0c;按下回车打开命令提示符。先输入“D:”&#xff0c;回车…

微型计算机上的tab作用,TAB键有什么用处

Tab键对大家来说都是比较熟悉吧。比如写文章时开头要空两格就可用这个键。但是它还有什么特殊功能呢&#xff0c;不一定是大家都知道的。下面小编来详细的介绍下几种tab键的常见功能 tab键作用一&#xff1a;改变焦点 聚焦到下一个按钮&#xff0c;输入框或者链接等。例如&…

计算机键盘上的tab键是什么键,电脑Tab键有什么用处

电脑Tab键有什么用处 Tab键对大家来说都是比较熟悉吧。比如写文章时开头要空两格就可用这个键。但是它还有什么特殊功能呢&#xff0c;不一定是大家都知道的。下面小编来详细的介绍下几种tab键的常见用处&#xff1a; tab键作用一&#xff1a;改变焦点 聚焦到下一个按钮&#x…

电脑Tab键有什么功能?6个实用功能总结!

我最近对电脑的键盘很有兴趣&#xff0c;想了解一下各个键有什么特殊的用法。今天正好看到Tab键&#xff0c;想问下大家知道电脑的Tab键有什么比较好用的功能吗&#xff1f; 在电脑键盘上&#xff0c;Tab键是一个常见的键&#xff0c;它具有多种功能和用途。无论是在文本处理、…

tab键功能

tab 键可以实现命令及路径等补全&#xff0c;提高输入效率&#xff0c;避免出错 tab键可以命令补全&#xff0c;还有路径、文件名补全。 命令补全&#xff1a; 在Linux命令行下&#xff0c;输入字符后&#xff0c;按两次Tab键&#xff0c;shell就会列出以这些字符打头的所有…

计算机键盘上的tab键是什么键,键盘Tab键有什么作用?

Tab键——跳格键&#xff0c;大家都比较熟悉了吧&#xff0c;但是到底它有什么特殊的使用功能&#xff0c;却未必是大家都知道的哦。今天就将Tab键的几种使用功能进行了整理&#xff0c;大家可以参考学习学习。 1、跳格。当我们在网页输入表单的时候&#xff0c;在一个输入控件…

电脑Tab键有什么用

Tab键对大家来说都是比较熟悉吧。比如写文章时开头要空两格就可用这个键。但是它还有什么特殊功能呢&#xff0c;不一定是大家都知道的。下面我来详细的介绍下几种tab键的常见用处&#xff1a; tab键作用一&#xff1a;改变焦点 聚焦到下一个按钮&#xff0c;输入框或者链接等…

电脑Tab键有什么功能?分享Tab键的6个妙用

Tab键tabulator key 的缩写&#xff0c;意思是跳格键。基本用法是可以用来绘制无边框的表格&#xff0c;还可以在单词间留下间隔&#xff0c;一般等于八个空格的长度。但是您知道电脑Tab键有什么功能吗&#xff1f;以下一些关于Tab键的使用和功能的介绍&#xff0c;希望这些可以…

matlab EOF程序

% eof第一模态图用变量eof的第一列&#xff0c;以此类推&#xff1b;相应的时间系数用pc第一行 clear clcx [2 6 1 5 2;9 4 0 5 4;12 2 55 9 10;4 55 78 2 13]; %原始数据&#xff0c;列为站点或格点&#xff0c;行为时间序列上的值 x(1,:) x(1,:) - mean(x(1,:)); x(…

C语言——EOF的用法——while(scanf(“%d“,num)!=EOF)

简介&#xff1a; EOF是一个计算机术语&#xff0c;为End Of File的缩写&#xff0c;在操作系统中表示资料源无更多的资料可读取。资料源通常称为档案或串流。通常在文本的最后存在此字符表示资料结束。、 概念&#xff1a; 在C语言中&#xff0c;或更精确地说成C标准函数库中…

cat << EOF 什么意思?

cat <<EOF 什么意思&#xff1f; cat命令表示查看&#xff0c;而cat <<EOF命令表示将进行输入&#xff0c;直到以EOF终止符来结束输入&#xff08;最后的新行&#xff09;。EOF必须写在一行的头部&#xff0c;前面不能有制表符或者空格。如果结束符EOF前面有制表符…

【C语言中的EOF】零基础看懂EOF如何使用while(scanf(“%d %d”,a,b)感叹号=EOF)

&#x1f31f;前言 ✨如今我们努力奔跑&#xff0c;不过是为了追上那个曾经被寄予厚望的自己&#xff01; 【&#x1f47b;&#x1f47b;&#x1f47b;大家好&#xff0c;我是姜姜爱柚子&#xff0c;将在这里分享所学所得&#xff0c;如果有不正确的地方&#xff0c;希望大家多…

c语言中eof的作用,eof在c语言中表示什么

eof在c语言中表示文件结束符。在while循环中以EOF作为文件结束标志&#xff0c;这种以EOF作为文件结束标志的文件&#xff0c;必须是文本文件。在文本文件中&#xff0c;数据都是以字符的ASCII码值的形式存放的。 在C语言中&#xff0c;或更精确地说成C标准函数库中表示文件结束…