たれぱんのびぼーろく

わたしの備忘録、生物学とプログラミングが多いかも

BLEの仕組み

接続とデータ交換

  • GAP: 接続に重点
  • GATT: データ交換に重点
  • GATT based profiles: データのフォーマット(?)

yegang.hatenablog.com

バイスの発見、接続確立、セキュリティ、認証、association model, サービスの発見

It also describes the behaviors and methods **for device discovery, connection establishment, security, authentication, association models and service discovery.
v4.2 vol1 partA, p98

HIDとHOGP

HID OVER GATT PROFILE SPECIFICATION

採択済み Bluetooth のプロファイル、サービス、プロトコル、トランスポート

HOGP
HID over GATT Profile
​​> 1.0
有効
2011年12月27日
link

(筆者訳) このプロファイルはUSB HID specificationに適合しています。その目的は、BLEワイヤレスリンク上でUSB HID 仕様を運用することです。 This profile is an adaptation of the USB HID specification [2] to operate over a Bluetooth low energy wireless link.

USB HID specification
USB HID: USBでHIDを使うためのプトロコル. USBデバイスはいくつかのdevice classに分けられる. そのうちの1つが(USB) HID class.

These devices are broken into various device classes.
This document describes the Human Interface Device (HID) class for use with Universal Serial Bus (USB).

Viewer | Bluetooth Technology Website

HIDそのものの仕組み

USB.org - HID Tools

(なんかこの文献、USB HID仕様書とずれてないか?)

HID (Human Interface Device) クラスでは、レポートと呼ばれる単位でデータを転送します。例えばマウスの場合、各ボタンが押されているかどうか、水平方向の移動量、垂直方向の移動量、ホイールの移動量といった情報をまとめたレポートを定期的に転送します。
レポートの中にどのような情報がどのように並んでいるかは、レポートディスクリプタによって定義されます。
HID (Human Interface Device) クラスについて | インターフェイス株式会社

データの構造情報とdataそのものがまとめて送られる.
Report - item(s) - “size”+“type”+“tag”+“data”
itemの構造は
* short items: 1byte"size" + 1byte"type" + 1byte"tag" + 0/½/4byte"data"
* long items: 1byte"size" + 1byte"type" + 1byte"tag" + 1byte"datasize" + 1byte"longitemtag" + Xbyte"data"
送られたデータは、Hostのparserによって構造化データになる.

Report descriptors are composed of pieces of information. Each piece of information is called an Item.
All items have a one-byte prefix that contains the item tag, item type, and item size. http://www.usb.org/developers/hidpage/HID1_11.pdf

item typesは3種類
* Main * Global * Local

There are three item types: Main, Global, and Local.
There are five Main item tags currently defined:

Main typeは5種類のtagを持ちうる * Input * Output * Feature * Collection: A meaningful grouping of Input, Output, and Feature items—for example, mouse, keyboard, joystick, and pointer. * End Collection

HOGPで定義されるrole

HOGPを利用するデバイスは、以下の役割を担う.

  • HID Device: GATT server
  • HID Host: GATT client
    • Boot Host: HID parserが不要、つまりReport Mapが要らない(事前に決められた形式)
    • Report Host: HID parserを実装.

This profile defines three roles: HID Device, Boot Host, and Report Host.
 The HID Device shall be a GATT server.
 The Boot Host shall be a GATT client.
 The Report Host shall be a GATT client.
Use of the term HID Host refers to both host roles: Boot Host, and Report Host. A Report Host is required to support a HID Parser and be able to handle arbitrary formats for data transfers (known as Reports) whereas a Boot Host is not required to support a HID Parser as all data transfers (Reports) for Boot Protocol Mode are of predefined length and format.
https://www.bluetooth.org/docman/handlers/downloaddoc.ashx?doc_id=245141&_ga=1.20487995.2039220976.1491127446#page10

HID Deviceへの要求

ほぼ、USB HID に従えとのこと(つまり、USB HID規格を理解せよと)

HID Hostへの要求

なんかめっちゃある.

USB HIDとHOGP間にあるフォーマットの差

USB HIDはReportに全情報が入ってる.
HOGPはServiceに全情報が入ってる. Reportにはdataのみが入り、Report Mapに構造情報が別で入ってる.

By looking at a Report descriptor alone, an application knows how to handle incoming data, as well as what the data could be used for.
http://www.usb.org/developers/hidpage/HID1_11.pdf

All of the structure formats described in HID are used in HID-over-GATT.
The nomenclature is not ideal, though:

  • Report Map: what the USB HID calls Report Descriptor.
  • Report Reference Characteristic Descriptor is the BLE way of setting a report characteristic’s metadata. It contains the type (Input/Output/Feature) and ID of a report.

USB HIDとHOGPのデータ構造

たぶんこう

USB HID

  • Report (Descriptor)
    • item
      • size
      • type
      • tag
      • data

HOGP

  • HID Service
    • Report Characteristic

      - data Value

      (どっかのdiscriptor) type, ID of a report

The HID Service defines the following characteristics:

  • Protocol Mode: the default is Report mode, but you can change that to Boot mode.
  • Report Map: the HID Report descriptor, defining the possible format for Input/Output/Feature reports.
  • Report: a characteristic used as a vehicle for HID reports. Unlike USB, where the ID is sent as a prefix when there is more than one report per type, the ID is stored in a characteristic descriptor. This means that there will be one characteristic per report described in the Report Map.
  • Boot Keyboard Input Report: when the device is a keyboard, it must define boot reports.
  • Boot Keyboard Output Report.
  • Boot Mouse Input Report.
  • HID Information: HID version, localization and some capability flags.
  • HID Control Point: inform the device that the host is entering or leaving suspend state.

HID-over-GATT

Reportに操作情報
Report MapにReportの構造情報
Boot …BIOSでも使える用のもの

Boot…について

しかし、キーボードおよびマウスはBIOSがサポートするデバイス(ブートデバイス)として、シンプルな実装が求められた。そこで、ブートデバイスとして用いられるUSB HID クラスデバイス(キーボードあるいはマウス)は、ブートプロトコルに対応することを示すためにサブクラスを使用する
USB HID クラス ‐ 通信用語の基礎知識

Reportのvalue

Report Mapのvalue

HOGPのReport MapはUSB HID specificationで定義されたReport Descriptorを返す.
つまり、USB HID Report Discriptorの値をそのまま入れれば良い.

4.7 ReportMapBehavior
The Report Map characteristic shall return the HID Report Descriptor when read. The HID Report Descriptor is defined in the USB HID specification [2].
https://www.bluetooth.org/docman/handlers/downloaddoc.ashx?doc_id=245141&_ga=1.20487995.2039220976.1491127446#page21