传统蓝牙服务问询协议SDP概念

零.概述

本文主要介绍传统蓝牙SDP的概念,SDP在整个协议栈中的架构,SDP的UUID,服务类,以及服务类属性介绍。

服务发现协议(SDP)为应用程序提供了一种方法来发现哪些服务可用,并确定这些可用服务的特征。比如主动问询对方支持哪些蓝牙协议,或者单独问询对方蓝牙电话HFP

一. 声明

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

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

第二篇: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

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

二. SDP概念

服务发现协议(SDP)为应用程序提供了一种方法来发现哪些服务可用,并确定这些可用服务的特征。比如主动问询对方支持哪些蓝牙协议,或者单独问询对方蓝牙电话HFP,在整个蓝牙中的架构如红框内:

整个SDP是基于C/S架构,主要是client发起request,server回送response,如下图:

三. SDP常用术语

1. 服务记录

服务是任何一个能够提供信息、执行动作、或代表另一实体控制资源的实体 。服务可以以软件、硬件、或硬软件混合的形式来实现。由 SDP 服务器所维护服务的所有信息都包含于一条服务记录中。该服务记录全部由一张服务属性表组成。如下图所示:

其中服务记录包括服务句柄+服务属性服务句柄是一个32位无符号整形的数字,整个sdp server中必须唯一服务属性如下小节。

2. 服务属性

服务属性用于描述某一服务的一个特征。服务属性的实例如下:

其中服务属性的格式如下:

其中属性ID是1个16位无符号整形的数字,属性值要看ID,来决定是什么格式,属性在后面介绍

总结起来,整个服务器应该包含如下结构(0条或者多条记录):

3.UUID

UUID 是经授权可在所有时空中保持唯一的通用定位符。UUID 可以分布的方式独立创建,而且不需要指定 UUID 的中心注册机构。UUID 值长度为 128 位。

为了减少存储压力,并便于 128 位 UUID 值的转换,UUID 值域已经为了常用和注册的目的进行预先分配。在该已分配域的第一个 UUID 作为蓝牙基 UUID,具有来自蓝牙号码分配文件的值 00000000-0000-1000-7007- 00805F9B34FB。在该已分配域的 UUID 值都具有 16 位或 32 位的别名。这些别名常被称为 16 位或 32位 UUID。但每一别名实际上都代表一个 128 位 UUID 。可以通过一个简单的数学运算计算 16 位或 32 位 UUID 的全部 128 位值。

128 位值 = 16 位值 × 2^96+ 蓝牙基 UUID

128 位值 = 32 位值 × 2^96+ 蓝牙基 UUID

通过对 16 位值进行零扩展,将 16 位 UUID 转换成为 32 位 UUID 格式。另外

一个转换方法是将 16 位值加到所有位都为零的 32 位 UUID 。

注 :可以直接对两个 16 位 UUID 或 32 位 UUID 或 128 位 UUID 进行比较,如果要对不同大小的 UUID 进行比较,短 UUID 必须在比较前转换成为长 UUID 格式。

具体协议的UUID如下,参考:https://www.bluetooth.com/specifications/assigned-numbers/service-discovery/

Base Universally Unique Identifier (UUID)

The Base UUID is used for calculating 128-bit UUIDs from “short UUIDs” (uuid16 and uuid32) as described in the SDP Specification. See Service Discovery Protocol (SDP) in the Bluetooth Core Specification.

NOTE: Currently all assigned short UUIDs are uuid16 types.

UUID NameUUID
BASE_UUID00000000-0000-1000-8000-00805F9B34FB
Protocol NameUUIDProtocol Specification
SDP0x0001Bluetooth Core Specification
UDP0x0002[NO USE BY PROFILES]
RFCOMM0x0003RFCOMM with TS 07.10
TCP0x0004[NO USE BY PROFILES]
TCS-BIN0x0005Telephony Control Specification / TCS Binary [DEPRECATED]
TCS-AT0x0006[NO USE BY PROFILES]
ATT0x0007Attribute Protocol
OBEX0x0008IrDA Interoperability
IP0x0009[NO USE BY PROFILES]
FTP0x000A[NO USE BY PROFILES]
HTTP0x000C[NO USE BY PROFILES]
WSP0x000E[NO USE BY PROFILES]
BNEP0x000FBluetooth Network Encapsulation Protocol (BNEP)
UPNP0x0010Extended Service Discovery Profile (ESDP) [DEPRECATED]
HIDP0x0011Human Interface Device Profile (HID)
HardcopyControlChannel0x0012Hardcopy Cable Replacement Profile (HCRP)
HardcopyDataChannel0x0014See Hardcopy Cable Replacement Profile (HCRP)
HardcopyNotification0x0016Hardcopy Cable Replacement Profile (HCRP)
AVCTP0x0017Audio/Video Control Transport Protocol (AVCTP)
AVDTP0x0019Audio/Video Distribution Transport Protocol (AVDTP)
CMTP0x001BCommon ISDN Access Profile (CIP) [DEPRECATED]
MCAPControlChannel0x001EMulti-Channel Adaptation Protocol (MCAP)
MCAPDataChannel0x001FMulti-Channel Adaptation Protocol (MCAP)
L2CAP0x0100Bluetooth Core Specification

4. 服务类 

每一服务都是服务类的一个实例。服务类定义提供对所有包含于服务记录中属性的定义,而这些服务记录就代表一个类实例。每一属性定义将给出该属性 ID的数字值、该属性值的用法及其格式。服务记录包含服务类的专用属性,以及用于所有服务的通用属性。

每一服务类将指定一个唯一标识符 。 该服务类标识符包含于ServiceClassIDList 属性的属性值,并表示为 UUID。由于服务记录中的某些属性的格式和含义依赖于服务记录的服务类,因此 ServiceClassIDList 属性非常重要。在使用任一类指定属性之前,应检查或验证它们的值。由于服务记录的所有属性必须遵循所有的服务类,包含于 ServiceClassIDList 属性中的服务类标识符也与此有关。特别要说明的是,每一服务类都是另外一类的子类,该父类的标识符包含在 ServiceClassIDList 列表中。服务子类定义与其父类不同,子类中包含该其它子类特定的属性定义。ServiceClassIDList 属性中的服务类标识符,按照从底层类到高层类的顺序一一列出。

在定义本身是另一服务类子类的新服务类时,该新类将保留父类定义的所有属性。同时,也将定义专用于新服务类的其它属性。换句话说, 向已有服务类的某些实例添加新属性的机制将创建一个新的服务类,该服务类是已有服务类的子类。

有以下服务类,如excel

Service Class NameUUIDSpecificationAllowed Usage
ServiceDiscoveryServerServiceClassID0x1000Bluetooth Core SpecificationService Class
BrowseGroupDescriptorServiceClassID0x1001Bluetooth Core SpecificationService Class
SerialPort0x1101Serial Port Profile (SPP)
NOTE: The example SDP record in SPP v1.0 does not include a BluetoothProfileDescriptorList attribute, but some implementations may also use this UUID for the Profile Identifier.
Service Class/ Profile
LANAccessUsingPPP0x1102LAN Access Profile
[DEPRECATED]
NOTE: Used as both Service Class Identifier and Profile Identifier.
Service Class/ Profile
DialupNetworking0x1103Dial-up Networking Profile (DUN)
NOTE: Used as both Service Class Identifier and Profile Identifier.
Service Class/ Profile
IrMCSync0x1104Synchronization Profile (SYNC)
NOTE: Used as both Service Class Identifier and Profile Identifier.
Service Class/ Profile
OBEXObjectPush0x1105Object Push Profile (OPP)
NOTE: Used as both Service Class Identifier and Profile.
Service Class/ Profile
OBEXFileTransfer0x1106File Transfer Profile (FTP)
NOTE: Used as both Service Class Identifier and Profile Identifier.
Service Class/ Profile
IrMCSyncCommand0x1107Synchronization Profile (SYNC) 
Headset0x1108Headset Profile (HSP)
NOTE: Used as both Service Class Identifier and Profile Identifier.
Service Class/ Profile
CordlessTelephony0x1109Cordless Telephony Profile (CTP)
NOTE: Used as both Service Class Identifier and Profile Identifier.
[DEPRECATED]
Service Class/ Profile
AudioSource0x110AAdvanced Audio Distribution Profile (A2DP)Service Class
AudioSink0x110BAdvanced Audio Distribution Profile (A2DP)Service Class
A/V_RemoteControlTarget0x110CAudio/Video Remote Control Profile (AVRCP)Service Class
AdvancedAudioDistribution0x110DAdvanced Audio Distribution Profile (A2DP)Profile
A/V_RemoteControl0x110EAudio/Video Remote Control Profile (AVRCP)
NOTE: Used as both Service Class Identifier and Profile Identifier.
Service Class/ Profile
A/V_RemoteControlController0x110FAudio/Video Remote Control Profile (AVRCP)
NOTE: The AVRCP specification v1.3 and later require that 0x110E also be included in the ServiceClassIDList before 0x110F for backwards compatibility.
Service Class
Intercom0x1110Intercom Profile (ICP)
NOTE: Used as both Service Class Identifier and Profile Identifier.
[DEPRECATED]
Service Class
Fax0x1111Fax Profile (FAX)
NOTE: Used as both Service Class Identifier and Profile Identifier.
[DEPRECATED]
Service Class
Headset – Audio Gateway (AG)0x1112Headset Profile (HSP)Service Class
WAP0x1113Interoperability Requirements for Bluetooth technology as a WAP, Bluetooth SIG [DEPRECATED]Service Class
WAP_CLIENT0x1114Interoperability Requirements for Bluetooth technology as a WAP, Bluetooth SIG [DEPRECATED]Service Class
PANU0x1115Personal Area Networking Profile (PAN)
NOTE: Used as both Service Class Identifier and Profile Identifier for PANU role.
Service Class / Profile
NAP0x1116Personal Area Networking Profile (PAN)
NOTE: Used as both Service Class Identifier and Profile Identifier for NAP role.
Service Class / Profile
GN0x1117Personal Area Networking Profile (PAN)
NOTE: Used as both Service Class Identifier and Profile Identifier for GN role.
Service Class / Profile
DirectPrinting0x1118Basic Printing Profile (BPP)Service Class
ReferencePrinting0x1119See Basic Printing Profile (BPP)Service Class
Basic Imaging Profile0x111ABasic Imaging Profile (BIP)Profile
ImagingResponder0x111BBasic Imaging Profile (BIP)Service Class
ImagingAutomaticArchive0x111CBasic Imaging Profile (BIP)Service Class
ImagingReferencedObjects0x111DBasic Imaging Profile (BIP)Service Class
Handsfree0x111EHands-Free Profile (HFP)
NOTE: Used as both Service Class Identifier and Profile Identifier.
Service Class / Profile
HandsfreeAudioGateway0x111FHands-free Profile (HFP)Service Class
DirectPrintingReferenceObjectsService0x1120Basic Printing Profile (BPP)Service Class
ReflectedUI0x1121Basic Printing Profile (BPP)Service Class
BasicPrinting0x1122Basic Printing Profile (BPP)Profile
PrintingStatus0x1123Basic Printing Profile (BPP)Service Class
HumanInterfaceDeviceService0x1124Human Interface Device (HID)
NOTE: Used as both Service Class Identifier and Profile Identifier.
Service Class / Profile
HardcopyCableReplacement0x1125Hardcopy Cable Replacement Profile (HCRP)Profile
HCR_Print0x1126Hardcopy Cable Replacement Profile (HCRP)Service Class
HCR_Scan0x1127Hardcopy Cable Replacement Profile (HCRP)Service Class
Common_ISDN_Access0x1128Common ISDN Access Profile (CIP)
NOTE: Used as both Service Class Identifier and Profile Identifier.
[DEPRECATED]
Service Class / Profile
SIM_Access0x112DSIM Access Profile (SAP)
NOTE: Used as both Service Class Identifier and Profile Identifier.
Service Class / Profile
Phonebook Access – PCE0x112EPhonebook Access Profile (PBAP)Service Class
Phonebook Access – PSE0x112FPhonebook Access Profile (PBAP)Service Class
Phonebook Access0x1130Phonebook Access Profile (PBAP)Profile
Headset – HS0x1131Headset Profile (HSP)
NOTE: See erratum #3507.
0x1108 and 0x1203 should also be included in the ServiceClassIDList before 0x1131 for backwards compatibility.
Service Class
Message Access Server0x1132Message Access Profile (MAP)Service Class
Message Notification Server0x1133Message Access Profile (MAP)Service Class
Message Access Profile0x1134Message Access Profile (MAP)Profile
GNSS0x1135Global Navigation Satellite System Profile (GNSS)Profile
GNSS_Server0x1136Global Navigation Satellite System Profile (GNSS)Service Class
​3D Display0x1137​​3D Synchronization Profile (3DSP)Service Class​
​3D Glasses​0x1138​3D Synchronization Profile (3DSP)​Service Class
​3D Synchronization0x1139​​3D Synchronization Profile (3DSP)​Profile
​MPS Profile UUID​0x113A​Multi-Profile Specification (MPS)​Profile
​MPS SC UUID​0x113B​Multi-Profile Specification (MPS)​Service Class
​CTN Access Service​​0x113C​​Calendar, Task, and Notes (CTN) Profile​Service Class
​CTN Notification Service​​0x113D​​Calendar Tasks and Notes (CTN) Profile​Service Class
​CTN Profile​0x113E​​Calendar Tasks and Notes (CTN) Profile​Profile
PnPInformation0x1200Device Identification (DID)
NOTE: Used as both Service Class Identifier and Profile Identifier.
Service Class / Profile
GenericNetworking0x1201N/AService Class
GenericFileTransfer0x1202N/AService Class
GenericAudio0x1203N/AService Class
GenericTelephony0x1204N/AService Class
UPNP_Service0x1205Enhanced Service Discovery Profile (ESDP) [DEPRECATED]Service Class
UPNP_IP_Service0x1206Enhanced Service Discovery Profile (ESDP) [DEPRECATED]Service Class
ESDP_UPNP_IP_PAN0x1300Enhanced Service Discovery Profile (ESDP) [DEPRECATED]Service Class
ESDP_UPNP_IP_LAP0x1301Enhanced Service Discovery Profile (ESDP)[DEPRECATED]Service Class
ESDP_UPNP_L2CAP0x1302Enhanced Service Discovery Profile (ESDP)[DEPRECATED]Service Class
VideoSource0x1303Video Distribution Profile (VDP)Service Class
VideoSink0x1304Video Distribution Profile (VDP)Service Class
VideoDistribution0x1305Video Distribution Profile (VDP)Profile
HDP0x1400Health Device ProfileProfile
HDP Source0x1401Health Device Profile (HDP)Service Class
HDP Sink0x1402Health Device Profile (HDP)Service Class
 (Max value 0xFFFF) 

 五.特定类属性 

具体参照,如图:

我们以截图的方式给出:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Wireless_Link

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值