传统蓝牙服务问询协议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

蓝牙学习目录http://www.noobyard.com/article/p-wkbgqcxj-nt.html

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

二. 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 Name UUID
BASE_UUID 00000000-0000-1000-8000-00805F9B34FB
Protocol Name UUID Protocol Specification
SDP 0x0001 Bluetooth Core Specification
UDP 0x0002 [NO USE BY PROFILES]
RFCOMM 0x0003 RFCOMM with TS 07.10
TCP 0x0004 [NO USE BY PROFILES]
TCS-BIN 0x0005 Telephony Control Specification / TCS Binary [DEPRECATED]
TCS-AT 0x0006 [NO USE BY PROFILES]
ATT 0x0007 Attribute Protocol
OBEX 0x0008 IrDA Interoperability
IP 0x0009 [NO USE BY PROFILES]
FTP 0x000A [NO USE BY PROFILES]
HTTP 0x000C [NO USE BY PROFILES]
WSP 0x000E [NO USE BY PROFILES]
BNEP 0x000F Bluetooth Network Encapsulation Protocol (BNEP)
UPNP 0x0010 Extended Service Discovery Profile (ESDP) [DEPRECATED]
HIDP 0x0011 Human Interface Device Profile (HID)
HardcopyControlChannel 0x0012 Hardcopy Cable Replacement Profile (HCRP)
HardcopyDataChannel 0x0014 See Hardcopy Cable Replacement Profile (HCRP)
HardcopyNotification 0x0016 Hardcopy Cable Replacement Profile (HCRP)
AVCTP 0x0017 Audio/Video Control Transport Protocol (AVCTP)
AVDTP 0x0019 Audio/Video Distribution Transport Protocol (AVDTP)
CMTP 0x001B Common ISDN Access Profile (CIP) [DEPRECATED]
MCAPControlChannel 0x001E Multi-Channel Adaptation Protocol (MCAP)
MCAPDataChannel 0x001F Multi-Channel Adaptation Protocol (MCAP)
L2CAP 0x0100 Bluetooth Core Specification

4. 服务类 

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

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

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

有以下服务类,如excel

Service Class Name UUID Specification Allowed Usage
ServiceDiscoveryServerServiceClassID 0x1000 Bluetooth Core Specification Service Class
BrowseGroupDescriptorServiceClassID 0x1001 Bluetooth Core Specification Service Class
SerialPort 0x1101 Serial 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
LANAccessUsingPPP 0x1102 LAN Access Profile
[DEPRECATED]
NOTE: Used as both Service Class Identifier and Profile Identifier.
Service Class/ Profile
DialupNetworking 0x1103 Dial-up Networking Profile (DUN)
NOTE: Used as both Service Class Identifier and Profile Identifier.
Service Class/ Profile
IrMCSync 0x1104 Synchronization Profile (SYNC)
NOTE: Used as both Service Class Identifier and Profile Identifier.
Service Class/ Profile
OBEXObjectPush 0x1105 Object Push Profile (OPP)
NOTE: Used as both Service Class Identifier and Profile.
Service Class/ Profile
OBEXFileTransfer 0x1106 File Transfer Profile (FTP)
NOTE: Used as both Service Class Identifier and Profile Identifier.
Service Class/ Profile
IrMCSyncCommand 0x1107 Synchronization Profile (SYNC)  
Headset 0x1108 Headset Profile (HSP)
NOTE: Used as both Service Class Identifier and Profile Identifier.
Service Class/ Profile
CordlessTelephony 0x1109 Cordless Telephony Profile (CTP)
NOTE: Used as both Service Class Identifier and Profile Identifier.
[DEPRECATED]
Service Class/ Profile
AudioSource 0x110A Advanced Audio Distribution Profile (A2DP) Service Class
AudioSink 0x110B Advanced Audio Distribution Profile (A2DP) Service Class
A/V_RemoteControlTarget 0x110C Audio/Video Remote Control Profile (AVRCP) Service Class
AdvancedAudioDistribution 0x110D Advanced Audio Distribution Profile (A2DP) Profile
A/V_RemoteControl 0x110E Audio/Video Remote Control Profile (AVRCP)
NOTE: Used as both Service Class Identifier and Profile Identifier.
Service Class/ Profile
A/V_RemoteControlController 0x110F Audio/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
Intercom 0x1110 Intercom Profile (ICP)
NOTE: Used as both Service Class Identifier and Profile Identifier.
[DEPRECATED]
Service Class
Fax 0x1111 Fax Profile (FAX)
NOTE: Used as both Service Class Identifier and Profile Identifier.
[DEPRECATED]
Service Class
Headset – Audio Gateway (AG) 0x1112 Headset Profile (HSP) Service Class
WAP 0x1113 Interoperability Requirements for Bluetooth technology as a WAP, Bluetooth SIG [DEPRECATED] Service Class
WAP_CLIENT 0x1114 Interoperability Requirements for Bluetooth technology as a WAP, Bluetooth SIG [DEPRECATED] Service Class
PANU 0x1115 Personal Area Networking Profile (PAN)
NOTE: Used as both Service Class Identifier and Profile Identifier for PANU role.
Service Class / Profile
NAP 0x1116 Personal Area Networking Profile (PAN)
NOTE: Used as both Service Class Identifier and Profile Identifier for NAP role.
Service Class / Profile
GN 0x1117 Personal Area Networking Profile (PAN)
NOTE: Used as both Service Class Identifier and Profile Identifier for GN role.
Service Class / Profile
DirectPrinting 0x1118 Basic Printing Profile (BPP) Service Class
ReferencePrinting 0x1119 See Basic Printing Profile (BPP) Service Class
Basic Imaging Profile 0x111A Basic Imaging Profile (BIP) Profile
ImagingResponder 0x111B Basic Imaging Profile (BIP) Service Class
ImagingAutomaticArchive 0x111C Basic Imaging Profile (BIP) Service Class
ImagingReferencedObjects 0x111D Basic Imaging Profile (BIP) Service Class
Handsfree 0x111E Hands-Free Profile (HFP)
NOTE: Used as both Service Class Identifier and Profile Identifier.
Service Class / Profile
HandsfreeAudioGateway 0x111F Hands-free Profile (HFP) Service Class
DirectPrintingReferenceObjectsService 0x1120 Basic Printing Profile (BPP) Service Class
ReflectedUI 0x1121 Basic Printing Profile (BPP) Service Class
BasicPrinting 0x1122 Basic Printing Profile (BPP) Profile
PrintingStatus 0x1123 Basic Printing Profile (BPP) Service Class
HumanInterfaceDeviceService 0x1124 Human Interface Device (HID)
NOTE: Used as both Service Class Identifier and Profile Identifier.
Service Class / Profile
HardcopyCableReplacement 0x1125 Hardcopy Cable Replacement Profile (HCRP) Profile
HCR_Print 0x1126 Hardcopy Cable Replacement Profile (HCRP) Service Class
HCR_Scan 0x1127 Hardcopy Cable Replacement Profile (HCRP) Service Class
Common_ISDN_Access 0x1128 Common ISDN Access Profile (CIP)
NOTE: Used as both Service Class Identifier and Profile Identifier.
[DEPRECATED]
Service Class / Profile
SIM_Access 0x112D SIM Access Profile (SAP)
NOTE: Used as both Service Class Identifier and Profile Identifier.
Service Class / Profile
Phonebook Access – PCE 0x112E Phonebook Access Profile (PBAP) Service Class
Phonebook Access – PSE 0x112F Phonebook Access Profile (PBAP) Service Class
Phonebook Access 0x1130 Phonebook Access Profile (PBAP) Profile
Headset – HS 0x1131 Headset 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 Server 0x1132 Message Access Profile (MAP) Service Class
Message Notification Server 0x1133 Message Access Profile (MAP) Service Class
Message Access Profile 0x1134 Message Access Profile (MAP) Profile
GNSS 0x1135 Global Navigation Satellite System Profile (GNSS) Profile
GNSS_Server 0x1136 Global Navigation Satellite System Profile (GNSS) Service Class
​3D Display 0x1137​ ​3D Synchronization Profile (3DSP) Service Class​
​3D Glasses ​0x1138 ​3D Synchronization Profile (3DSP) ​Service Class
​3D Synchronization 0x1139​ ​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
PnPInformation 0x1200 Device Identification (DID)
NOTE: Used as both Service Class Identifier and Profile Identifier.
Service Class / Profile
GenericNetworking 0x1201 N/A Service Class
GenericFileTransfer 0x1202 N/A Service Class
GenericAudio 0x1203 N/A Service Class
GenericTelephony 0x1204 N/A Service Class
UPNP_Service 0x1205 Enhanced Service Discovery Profile (ESDP) [DEPRECATED] Service Class
UPNP_IP_Service 0x1206 Enhanced Service Discovery Profile (ESDP) [DEPRECATED] Service Class
ESDP_UPNP_IP_PAN 0x1300 Enhanced Service Discovery Profile (ESDP) [DEPRECATED] Service Class
ESDP_UPNP_IP_LAP 0x1301 Enhanced Service Discovery Profile (ESDP)[DEPRECATED] Service Class
ESDP_UPNP_L2CAP 0x1302 Enhanced Service Discovery Profile (ESDP)[DEPRECATED] Service Class
VideoSource 0x1303 Video Distribution Profile (VDP) Service Class
VideoSink 0x1304 Video Distribution Profile (VDP) Service Class
VideoDistribution 0x1305 Video Distribution Profile (VDP) Profile
HDP 0x1400 Health Device Profile Profile
HDP Source 0x1401 Health Device Profile (HDP) Service Class
HDP Sink 0x1402 Health Device Profile (HDP) Service Class
  (Max value 0xFFFF)  

 五.特定类属性 

具体参照,如图:

我们以截图的方式给出: