藍芽 HID 剖析(一)

於忠軍-無線通訊發表於2016-06-13
1.概述
    The Human Interface Device (HID)定義了藍芽在人機介面裝置中的協議、特徵和使用規程。典型的應用包括藍芽滑鼠、藍芽鍵盤、藍芽遊戲手柄等。該協議改編自USB HID Protocol。
    
2.一些概念
(1)HID Reports:Bluetooth HID devices支援三種Report:Input, Output, and Feature。
(2)HID建立Control Channel和Interrupt Channel兩個通道,report可以在這兩條channel上傳輸,在Control channel上傳輸的report稱為synchronous reports ;在Interrupt channel上傳輸的report稱為asynchronous reports。
(3)Feature reports are always transferred synchronously using GET_REPORT or SET_REPORT requests。
(4)Report Protocol Mode和Boot Protocol Mode。Bluetooth HID Hosts至少支援一種,Bluetooth HID Device則需要支援Report Protocol Mode,並且Report Protocol Mode是Bluetooth HID Device的預設Mode。 

3.Bluetooth HID Protocol Messages
這些message不能超過L2CAP的MTU,大小超過MTU的message將被忽略。
Message Header的格式如下:
藍芽HID協議筆記
藍芽HID協議筆記
藍芽HID協議筆記
(1)HANDSHAKE
該Message用來acknowledgeSET_REPORT, SET_IDLE and SET_PROTOCOL等request。只在Control Channel上傳輸,只由Bluetooth HID device。
Parameter部分定義如下:
藍芽HID協議筆記

(2)HID_CONTROL
控制Bluetooth HID device改變狀態。
Parameter部分定義如下:
藍芽HID協議筆記

(3)GET_REPORT
Bluetooth HID Host用來請求Bluetooth HID device的傳輸。
定義如下:
藍芽HID協議筆記

(4)SET_REPORT
Bluetooth HID Host用來向Bluetooth HID device發起傳輸。
格式如下:
藍芽HID協議筆記

(5)GET_PROTOCOL
用來獲取Bluetooth HID device的Protocol Mode,然後Bluetooth HID device response一個DATA payload說明當前的Protocol Mode。
格式如下:
藍芽HID協議筆記
GET_PROTOCOL Data Definition格式如下:
藍芽HID協議筆記

(6)SET_PROTOCOL
用來設定Bluetooth HID device的Bluetooth HID device。格式如下:
藍芽HID協議筆記

(7)DATA
代表一個a HID payload。格式如下:
藍芽HID協議筆記

4.Transfers
以HID Protocol messages的形式傳輸。
(1)Control Channel Transfers
分為Acknowledged和Unacknowledged兩種,格式如下:
藍芽HID協議筆記
(2)Interrupt Channel Transfers
Interrupt IN和Interrupt OUT兩種,可以在任意時刻傳送。【中斷嘛】

5.其餘各層對於HID的要求
HID與L2CAP的互動如下:
藍芽HID協議筆記


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

相關文章