藍牙的SDP協議總結

本文轉自:http://blog.sina.com.cn/s/blog_69b5d2a50101egbb.html

1.概念
    SDP協議讓客戶機的應用程序發現存在的服務器應用程序提供的服務以及這些服務的屬性。SDP只提供發現服務的機制,不提供使用這些服務的方法。每個藍牙設備都需要一個SDP Service,只做Client的藍牙設備除外。

2.ServiceRecord
    每一個Service利用ServiceRecord來表示(具有唯一的32bit的Handle),每一個ServiceRecord由若干ServiceAttribute組成,由下圖表示:
藍牙的SDP協議總結

每一個ServiceAttribute的結構由下圖所示:
    藍牙的SDP協議總結
Attribute ID是由Assigned Value定義好的,例如Record Handle Attribute的ID爲0x0000。
正因爲SDP Record由許多Attribute組成,所以,可以把Record看成AtributeList,這在後面的SDP resposne中會常用到。
設備通過SDP request來訪問這些record的相關信息。這裏有個很好的SDP實例,如下:
藍牙的SDP協議總結
Service Class ID List描述了Service的類型,如0x00000000代表SDP service
Protocol Descriptior List 列出了可能使用這種Service的protocol

3.Data Element
Data Element是在SDP中定義的一種數據結構,用來表示ServiceAttribute的Value域。每一個data element由Type+Size兩部分組成。
Type的定義如下圖:
藍牙的SDP協議總結
Size的定義如下圖:
藍牙的SDP協議總結

幾個Data Element的例子:
藍牙的SDP協議總結

4.Service Class
    每一個Service都是ServiceClass的一個實例,一個Service Record就是一個Service Class的實例,Service Class可以表示一個Record裏的所有Attribute。每一個Service Class有一個ID,包含在ServiceClassIDList這個Attribute的value裏,稱之爲UUID。

5.UUID
   一個全局惟一的標識符,128bit。爲了節省存儲和傳輸開銷,UUID的一些位已經固定,出現了16bit和32bit的兩種UUID。這些不同bit的UUID可以相互轉化,如下式:
藍牙的SDP協議總結

6.SDP的數據單元格式(SDU)
    傳輸時都是以Big-Endian的形式,數據格式如下:
藍牙的SDP協議總結
PUD ID有如下幾種定義:
藍牙的SDP協議總結
Transaction ID和Length定義如下:
藍牙的SDP協議總結
7.SDP中的PDU
(1)Error PDU
藍牙的SDP協議總結

(2)SDP_ServiceSearchRequest PDU
藍牙的SDP協議總結
 ServiceSearchPattern由UUID組成,每個UUID由data lement組成。MaximumServiceRecordCount用來指定返回的Service Records Handles的最大個數,由於該參數爲2字節,所以其取值區間就是0x0001~0xffff。由於一個ServiceSearchPattern相匹配的Service Records Handles可能有多個,所以指定該參數非常的有必要。

(3)SDP_ServiceSearchResponse PDU
藍牙的SDP協議總結

TotalServiceRecordCount用來表示匹配的Service Record個數,最大爲65535(而且不能夠大於MaximumServiceRecordCount),如果沒有配置的Service Record,則其值爲0。

CurrentServiceRecordCount用來表示當前PDU中返回的Service Record Handle的個數。

ServiceRecordHandleList包含了當前PDU中返回的所有Service Record 的Handles,每一個Handle用一個32bit的數據來表示,所以該參數的長度就是4×CurrentServiceRecordCount字節。

(4)SDP_ServiceAttributeRequest PDU
藍牙的SDP協議總結

ServiceREcordHandle是通過SDP_ServiceSearchResponse獲取到的特定的Service的Service Record Handle。

參數MaximumAttributeByCount用來指定返回Attribute Value的最大總長度,以字節爲單位。

第三個參數AttributeIDList用來指定一組AttributeIDList,可以是幾個AttributeID,以可以是一個ID Range,如果是前者,則長度爲16位,如果爲後者,則長度爲32位。


(5) SDP_ServiceAttributeResponse PDU

藍牙的SDP協議總結

AttributeListByteCount用來表示Package中包含的數據的總長度,該值應該是小於SDP_ServiceSearchRequest中的MaxmumAttributeByteCount的一個值。

 

第二個參數AttributeLists是Service Record Attribute 的列表項,每一項包含了Attribute ID和Attribute Value兩部分。

(6)SDP_ServiceSearchAttributeRequest PDU
藍牙的SDP協議總結

ServiceSearchPattern和SDP_ServiceSearchRequest中完全一樣。

第二個參數MaxmumAttributeByteCount用來指定返回Attribute Value的最大總長度,以字節爲單位。

第三個參數AttributeIDList用來指定一組AttributeIDList,可以是幾個AttributeID,以可以是一個ID Range,如果是前者,則長度爲16位,如果爲後者,則長度爲32位。


(7)SDP_ServiceSearchAttributeResponse PDU

藍牙的SDP協議總結

AttributeListByteCount用來表示Package中包含的數據的總長度,該值應該是小於SDP_ServiceSearchRequest中的MaxmumAttributeByteCount的一個值。

 

第二個參數AttributeLists是Service Record Attribute 的列表項,每一項包含了Attribute ID和Attribute Value兩部分。


8.一些Attributes

兩種attribute每個service record都有:1.ServiceRecordHandle (attribute ID 0x00002).ServiceClassIDList (attribute ID 0x00001)

(1)ServiceRecordHandle Attribute

藍牙的SDP協議總結

(2)ServiceClassIDList Attribute

藍牙的SDP協議總結

(3)ServiceRecordState Attribute

藍牙的SDP協議總結

(4)ServiceID Attribute

藍牙的SDP協議總結
其餘很多Attribute參考SPEC。



本文轉自:http://blog.sina.com.cn/s/blog_69b5d2a50101egbb.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章