hidkbdservice.c 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617
  1. /**
  2. * @file
  3. * @author chipsea
  4. * @brief
  5. * @version 0.1
  6. * @date 2020-11-30
  7. * @copyright Copyright (c) 2020, CHIPSEA Co., Ltd.
  8. * @note
  9. */
  10. /******************************************************************************
  11. *****************************************************************************/
  12. /*********************************************************************
  13. * INCLUDES
  14. */
  15. #include "bcomdef.h"
  16. #include "OSAL.h"
  17. #include "att.h"
  18. #include "gatt.h"
  19. #include "gatt_uuid.h"
  20. #include "gatt_profile_uuid.h"
  21. #include "linkdb.h"
  22. #include "gattservapp.h"
  23. #include "hidkbdservice.h"
  24. #include "peripheral.h"
  25. #include "hiddev.h"
  26. #include "battservice.h"
  27. /*********************************************************************
  28. * MACROS
  29. */
  30. /*********************************************************************
  31. * CONSTANTS
  32. */
  33. /*********************************************************************
  34. * TYPEDEFS
  35. */
  36. /*********************************************************************
  37. * GLOBAL VARIABLES
  38. */
  39. // HID service
  40. CONST uint8 hidServUUID[ATT_BT_UUID_SIZE] =
  41. {
  42. LO_UINT16(HID_SERV_UUID), HI_UINT16(HID_SERV_UUID)
  43. };
  44. // HID Boot Keyboard Input Report characteristic
  45. CONST uint8 hidBootKeyInputUUID[ATT_BT_UUID_SIZE] =
  46. {
  47. LO_UINT16(BOOT_KEY_INPUT_UUID), HI_UINT16(BOOT_KEY_INPUT_UUID)
  48. };
  49. // HID Boot Mouse Input Report characteristic
  50. CONST uint8 hidBootMouseInputUUID[ATT_BT_UUID_SIZE] =
  51. {
  52. LO_UINT16(BOOT_MOUSE_INPUT_UUID), HI_UINT16(BOOT_MOUSE_INPUT_UUID)
  53. };
  54. // HID Boot Keyboard Output Report characteristic
  55. CONST uint8 hidBootKeyOutputUUID[ATT_BT_UUID_SIZE] =
  56. {
  57. LO_UINT16(BOOT_KEY_OUTPUT_UUID), HI_UINT16(BOOT_KEY_OUTPUT_UUID)
  58. };
  59. // HID Information characteristic
  60. CONST uint8 hidInfoUUID[ATT_BT_UUID_SIZE] =
  61. {
  62. LO_UINT16(HID_INFORMATION_UUID), HI_UINT16(HID_INFORMATION_UUID)
  63. };
  64. // HID Report Map characteristic
  65. CONST uint8 hidReportMapUUID[ATT_BT_UUID_SIZE] =
  66. {
  67. LO_UINT16(REPORT_MAP_UUID), HI_UINT16(REPORT_MAP_UUID)
  68. };
  69. // HID Control Point characteristic
  70. CONST uint8 hidControlPointUUID[ATT_BT_UUID_SIZE] =
  71. {
  72. LO_UINT16(HID_CTRL_PT_UUID), HI_UINT16(HID_CTRL_PT_UUID)
  73. };
  74. // HID Report characteristic
  75. CONST uint8 hidReportUUID[ATT_BT_UUID_SIZE] =
  76. {
  77. LO_UINT16(REPORT_UUID), HI_UINT16(REPORT_UUID)
  78. };
  79. // HID Protocol Mode characteristic
  80. CONST uint8 hidProtocolModeUUID[ATT_BT_UUID_SIZE] =
  81. {
  82. LO_UINT16(PROTOCOL_MODE_UUID), HI_UINT16(PROTOCOL_MODE_UUID)
  83. };
  84. /*********************************************************************
  85. * EXTERNAL VARIABLES
  86. */
  87. /*********************************************************************
  88. * EXTERNAL FUNCTIONS
  89. */
  90. /*********************************************************************
  91. * LOCAL VARIABLES
  92. */
  93. // HID Information characteristic value
  94. static CONST uint8 hidInfo[HID_INFORMATION_LEN] =
  95. {
  96. LO_UINT16(0x0111), HI_UINT16(0x0111), // bcdHID (USB HID version)
  97. 0x00, // bCountryCode
  98. HID_KBD_FLAGS // Flags
  99. };
  100. // HID Report Map characteristic value
  101. // Keyboard report descriptor (using format for Boot interface descriptor)
  102. #if FOLLOW_TI_MAP
  103. static CONST uint8 hidReportMap[] =
  104. {
  105. 0x05, 0x01, // USAGE_PAGE (Generic Desktop)
  106. 0x09, 0x06, // USAGE (Keyboard)
  107. 0xA1, 0x01, // COLLECTION (Application)
  108. 0x85, HID_RPT_ID_KEY_IN, // REPORT_ID (1)
  109. //
  110. 0x05, 0x07, // USAGE_PAGE (Key Codes)
  111. 0x19, 0xE0, // USAGE_MIN (224)
  112. 0x29, 0xE7, // USAGE_MAX (231)
  113. 0x15, 0x00, // LOGICAL_MINIMUM (0)
  114. 0x25, 0x01, // LOGICAL_MAXIMUM (1)
  115. //
  116. // Modifier byte
  117. 0x95, 0x08, // REPORT_COUNT (8)
  118. 0x75, 0x01, // REPORT_SIZE (1)
  119. 0x81, 0x02, // INPUT (Data, Variable, Absolute)
  120. //
  121. // Reserved byte
  122. 0x95, 0x01, // REPORT_COUNT (1)
  123. 0x75, 0x08, // REPORT_SIZE (8)
  124. 0x81, 0x01, // INPUT (Constant)
  125. //
  126. // LED report
  127. 0x95, 0x05, // REPORT_COUNT (5)
  128. 0x75, 0x01, // REPORT_SIZE (1)
  129. 0x05, 0x08, // USAGE_PAGE (LEDs)
  130. 0x19, 0x01, // USAGE_MIN (1)
  131. 0x29, 0x05, // USAGE_MAX (5)
  132. 0x91, 0x02, // OUTPUT (Data, Variable, Absolute)
  133. //
  134. // LED report padding
  135. 0x95, 0x01, // REPORT_COUNT (1)
  136. 0x75, 0x03, // REPORT_SIZE (3)
  137. 0x91, 0x01, // OUTPUT (Constant)
  138. //
  139. // Key arrays (6 bytes)
  140. 0x95, 0x06, // REPORT_COUNT (6)
  141. 0x75, 0x08, // REPORT_SIZE (8)
  142. 0x15, 0x00, // LOGICAL_MINIMUM (0)
  143. 0x25, 0x65, // LOGICAL_MAXIMUM (101)
  144. 0x05, 0x07, // USAGE_PAGE (Key Codes)
  145. 0x19, 0x00, // USAGE_MIN (0)
  146. 0x29, 0x65, // USAGE_MAX (101)
  147. 0x81, 0x00, // INPUT (Data, Array)
  148. //
  149. 0xC0, // END_COLLECTION
  150. //
  151. 0x05, 0x0c, // USAGE_PAGE (Consumer Devices)
  152. 0x09, 0x01, // USAGE (Consumer Control)
  153. 0xa1, 0x01, // COLLECTION (Application)
  154. 0x85, HID_RPT_ID_CC_IN, // REPORT_ID (2)
  155. //
  156. 0x09, 0x30, // USAGE (Power)
  157. 0x09, 0xCD, // USAGE (Play/Pause)
  158. 0x09, 0xB7, // USAGE (Stop)
  159. 0x09, 0xB5, // USAGE (Skip track)
  160. 0x09, 0xB6, // USAGE (Previous track)
  161. 0x09, 0xB3, // USAGE (Fast forward)
  162. 0x09, 0xB4, // USAGE (Rewind)
  163. 0x09, 0xB2, // USAGE (Record)
  164. 0x09, 0xE9, // USAGE (Volume up)
  165. 0x09, 0xEA, // USAGE (Volume down)
  166. 0x09, 0xE2, // USAGE (Mute)
  167. 0x15, 0x01, // LOGICAL_MINIMUM (1)
  168. 0x25, 0x0B, // LOGICAL_MAXIMUM (11)
  169. 0x95, 0x01, // REPORT_COUNT (1)
  170. 0x75, 0x08, // REPORT_SIZE (8)
  171. 0x81, 0x00, // INPUT (Data,Ary,Abs)
  172. //
  173. 0xC0, // END_COLLECTION
  174. //Voice collection
  175. 0x05, 0x0C, // Usage Page (Consumer Devices)
  176. 0x09, 0x01, // Usage (Consumer Control)
  177. 0xA1, 0x01, // Collection (Application)
  178. 0x85, HID_RPT_ID_VOICE_START_IN, // Report ID (10)
  179. 0x15, 0x00, // Logical Minimum (0)
  180. 0x26, 0xFF, 0x00, // Logical Maximum (255)
  181. 0x75, 0x08, // Report Size (8)
  182. 0x95, 0x05, // Report Count (5)
  183. 0x09, 0x01, // Usage (Consumer Control)
  184. 0x81, 0x00, // Input (Data,Array,Abs,No Wrap,Linear,Preferred State,No Null Position)
  185. 0x85, HID_RPT_ID_VOICE_DATA_IN, // Report ID (11)
  186. 0x15, 0x00, // Logical Minimum (0)
  187. 0x26, 0xFF, 0x00, // Logical Maximum (255)
  188. 0x75, 0x08, // Report Size (8)
  189. 0x95, 0x14, // Report Count (20)
  190. 0x09, 0x01, // Usage (Consumer Control)
  191. 0x81, 0x00, // Input (Data,Array,Abs,No Wrap,Linear,Preferred State,No Null Position)
  192. 0xC0 // END_COLLECTION
  193. };
  194. #else
  195. static CONST uint8 hidReportMap[] =
  196. {
  197. 0x05, 0x01, // Usage Page (Generic Desktop)
  198. 0x09, 0x02, // Usage (Mouse)
  199. 0xA1, 0x01, // Collection (Application)
  200. 0x85, HID_RPT_ID_MOUSE_IN, // Report Id (1) 0X01
  201. 0x09, 0x01, // Usage (Pointer)
  202. 0xA1, 0x00, // Collection (Physical)
  203. 0x05, 0x09, // Usage Page (Buttons)
  204. 0x19, 0x01, // Usage Minimum (01) - Button 1
  205. 0x29, 0x03, // Usage Maximum (03) - Button 3
  206. 0x15, 0x00, // Logical Minimum (0)
  207. 0x25, 0x01, // Logical Maximum (1)
  208. 0x75, 0x01, // Report Size (1)
  209. 0x95, 0x03, // Report Count (3)
  210. 0x81, 0x02, // Input (Data, Variable, Absolute) - Button states
  211. 0x75, 0x05, // Report Size (5)
  212. 0x95, 0x01, // Report Count (1)
  213. 0x81, 0x01, // Input (Constant) - Padding or Reserved bits
  214. 0x05, 0x01, // Usage Page (Generic Desktop)
  215. 0x09, 0x30, // Usage (X)
  216. 0x09, 0x31, // Usage (Y)
  217. 0x09, 0x38, // Usage (Wheel)
  218. 0x15, 0x81, // Logical Minimum (-127)
  219. 0x25, 0x7F, // Logical Maximum (127)
  220. 0x75, 0x08, // Report Size (8)
  221. 0x95, 0x03, // Report Count (3)
  222. 0x81, 0x06, // Input (Data, Variable, Relative) - X & Y coordinate
  223. 0xC0, // End Collection
  224. 0xC0, // End Collection
  225. 0x05, 0x01, // Usage Pg (Generic Desktop)
  226. 0x09, 0x06, // Usage (Keyboard)
  227. 0xA1, 0x01, // Collection: (Application)
  228. 0x85, HID_RPT_ID_KEY_IN, // Report Id (2)
  229. //
  230. 0x05, 0x07, // Usage Pg (Key Codes)
  231. 0x19, 0xE0, // Usage Min (224)
  232. 0x29, 0xE7, // Usage Max (231)
  233. 0x15, 0x00, // Log Min (0)
  234. 0x25, 0x01, // Log Max (1)
  235. //
  236. // Modifier byte
  237. 0x75, 0x01, // Report Size (1)
  238. 0x95, 0x08, // Report Count (8)
  239. 0x81, 0x02, // Input: (Data, Variable, Absolute)
  240. //
  241. // Reserved byte
  242. 0x95, 0x01, // Report Count (1)
  243. 0x75, 0x08, // Report Size (8)
  244. 0x81, 0x01, // Input: (Constant)
  245. //
  246. // LED report
  247. 0x95, 0x05, // Report Count (5)
  248. 0x75, 0x01, // Report Size (1)
  249. 0x05, 0x08, // Usage Pg (LEDs)
  250. 0x19, 0x01, // Usage Min (1)
  251. 0x29, 0x05, // Usage Max (5)
  252. 0x91, 0x02, // Output: (Data, Variable, Absolute)
  253. //
  254. // LED report padding
  255. 0x95, 0x01, // Report Count (1)
  256. 0x75, 0x03, // Report Size (3)
  257. 0x91, 0x01, // Output: (Constant)
  258. //
  259. // Key arrays (6 bytes)
  260. 0x95, 0x06, // Report Count (6)
  261. 0x75, 0x08, // Report Size (8)
  262. 0x15, 0x00, // Log Min (0)
  263. 0x25, 0x65, // Log Max (101)
  264. 0x05, 0x07, // Usage Pg (Key Codes)
  265. 0x19, 0x00, // Usage Min (0)
  266. 0x29, 0x65, // Usage Max (101)
  267. 0x81, 0x00, // Input: (Data, Array)
  268. //
  269. 0xC0, // End Collection
  270. #if EN_CONSUMER_MODE
  271. 0x05, 0x0C, // Usage Pg (Consumer Devices)
  272. 0x09, 0x01, // Usage (Consumer Control)
  273. 0xA1, 0x01, // Collection (Application)
  274. 0x85, HID_RPT_ID_CC_IN, // Report Id (3)
  275. 0x09, 0x02, // Usage (Numeric Key Pad)
  276. 0xA1, 0x02, // Collection (Logical)
  277. 0x05, 0x09, // Usage Pg (Button)
  278. 0x19, 0x01, // Usage Min (Button 1)
  279. 0x29, 0x0A, // Usage Max (Button 10)
  280. 0x15, 0x01, // Logical Min (1)
  281. 0x25, 0x0A, // Logical Max (10)
  282. 0x75, 0x04, // Report Size (4)
  283. 0x95, 0x01, // Report Count (1)
  284. 0x81, 0x00, // Input (Data, Ary, Abs)
  285. 0xC0, // End Collection
  286. 0x05, 0x0C, // Usage Pg (Consumer Devices)
  287. 0x09, 0x86, // Usage (Channel)
  288. 0x15, 0xFF, // Logical Min (-1)
  289. 0x25, 0x01, // Logical Max (1)
  290. 0x75, 0x02, // Report Size (2)
  291. 0x95, 0x01, // Report Count (1)
  292. 0x81, 0x46, // Input (Data, Var, Rel, Null)
  293. 0x09, 0xE9, // Usage (Volume Up)
  294. 0x09, 0xEA, // Usage (Volume Down)
  295. 0x15, 0x00, // Logical Min (0)
  296. 0x75, 0x01, // Report Size (1)
  297. 0x95, 0x02, // Report Count (2)
  298. 0x81, 0x02, // Input (Data, Var, Abs)
  299. 0x09, 0xE2, // Usage (Mute)
  300. 0x09, 0x30, // Usage (Power)
  301. 0x09, 0x83, // Usage (Recall Last)
  302. 0x09, 0x81, // Usage (Assign Selection)
  303. 0x09, 0xB0, // Usage (Play)
  304. 0x09, 0xB1, // Usage (Pause)
  305. 0x09, 0xB2, // Usage (Record)
  306. 0x09, 0xB3, // Usage (Fast Forward)
  307. 0x09, 0xB4, // Usage (Rewind)
  308. 0x09, 0xB5, // Usage (Scan Next)
  309. 0x09, 0xB6, // Usage (Scan Prev)
  310. 0x09, 0xB7, // Usage (Stop)
  311. 0x15, 0x01, // Logical Min (1)
  312. 0x25, 0x0C, // Logical Max (12)
  313. 0x75, 0x04, // Report Size (4)
  314. 0x95, 0x01, // Report Count (1)
  315. 0x81, 0x00, // Input (Data, Ary, Abs)
  316. 0x09, 0x80, // Usage (Selection)
  317. 0xA1, 0x02, // Collection (Logical)
  318. 0x05, 0x09, // Usage Pg (Button)
  319. 0x19, 0x01, // Usage Min (Button 1)
  320. 0x29, 0x03, // Usage Max (Button 3)
  321. 0x15, 0x01, // Logical Min (1)
  322. 0x25, 0x03, // Logical Max (3)
  323. 0x75, 0x02, // Report Size (2)
  324. 0x81, 0x00, // Input (Data, Ary, Abs)
  325. 0xC0, // End Collection
  326. 0x81, 0x03, // Input (Const, Var, Abs)
  327. 0xC0, // End Collection
  328. #endif
  329. #if EN_VOICE_MODE
  330. //Voice collection
  331. 0x05, 0x0C, // Usage Page (Consumer Devices)
  332. 0x09, 0x01, // Usage (Consumer Control)
  333. 0xA1, 0x01, // Collection (Application)
  334. 0x85, HID_RPT_ID_VOICE_START_IN, // Report ID (10)
  335. 0x15, 0x00, // Logical Minimum (0)
  336. 0x26, 0xFF, 0x00, // Logical Maximum (255)
  337. 0x75, 0x08, // Report Size (8)
  338. 0x95, 0x05, // Report Count (5)
  339. 0x09, 0x01, // Usage (Consumer Control)
  340. 0x81, 0x00, // Input (Data,Array,Abs,No Wrap,Linear,Preferred State,No Null Position)
  341. 0x85, HID_RPT_ID_VOICE_DATA_IN, // Report ID (11)
  342. 0x15, 0x00, // Logical Minimum (0)
  343. 0x26, 0xFF, 0x00, // Logical Maximum (255)
  344. 0x75, 0x08, // Report Size (8)
  345. 0x95, 0x14, // Report Count (20)
  346. 0x09, 0x01, // Usage (Consumer Control)
  347. 0x81, 0x00, // Input (Data,Array,Abs,No Wrap,Linear,Preferred State,No Null Position)
  348. 0xC0 // END_COLLECTION
  349. #endif
  350. };
  351. #endif
  352. // HID report map length
  353. uint16 hidReportMapLen = sizeof(hidReportMap);
  354. // HID report mapping table
  355. hidRptMap_t hidRptMap[HID_NUM_REPORTS];
  356. /*********************************************************************
  357. * Profile Attributes - variables
  358. */
  359. #if FOLLOW_TI_MAP
  360. // HID Service attribute
  361. static CONST gattAttrType_t hidService = { ATT_BT_UUID_SIZE, hidServUUID };
  362. // Include attribute (Battery service)
  363. static uint16 include = GATT_INVALID_HANDLE;
  364. // HID Information characteristic
  365. static uint8 hidInfoProps = GATT_PROP_READ;
  366. // HID Control Point characteristic
  367. static uint8 hidControlPointProps = GATT_PROP_WRITE_NO_RSP;
  368. static uint8 hidControlPoint;
  369. // HID Protocol Mode characteristic
  370. static uint8 hidProtocolModeProps = GATT_PROP_READ | GATT_PROP_WRITE_NO_RSP;
  371. uint8 hidProtocolMode = HID_PROTOCOL_MODE_REPORT;
  372. // HID Report Map characteristic
  373. static uint8 hidReportMapProps = GATT_PROP_READ;
  374. // HID External Report Reference Descriptor
  375. static uint8 hidExtReportRefDesc[ATT_BT_UUID_SIZE] =
  376. { LO_UINT16(BATT_LEVEL_UUID), HI_UINT16(BATT_LEVEL_UUID) };
  377. // HID Report characteristic, key input
  378. static uint8 hidReportKeyInProps = GATT_PROP_READ | GATT_PROP_NOTIFY;
  379. static uint8 hidReportKeyIn;
  380. static gattCharCfg_t hidReportKeyInClientCharCfg[GATT_MAX_NUM_CONN];
  381. // HID Report Reference characteristic descriptor, key input
  382. static uint8 hidReportRefKeyIn[HID_REPORT_REF_LEN] =
  383. { HID_RPT_ID_KEY_IN, HID_REPORT_TYPE_INPUT };
  384. // HID Report characteristic, LED output
  385. static uint8 hidReportLedOutProps = GATT_PROP_READ |
  386. GATT_PROP_WRITE |
  387. GATT_PROP_WRITE_NO_RSP;
  388. static uint8 hidReportLedOut;
  389. // HID Report Reference characteristic descriptor, LED output
  390. static uint8 hidReportRefLedOut[HID_REPORT_REF_LEN] =
  391. { HID_RPT_ID_LED_OUT, HID_REPORT_TYPE_OUTPUT };
  392. // HID Boot Keyboard Input Report
  393. static uint8 hidReportBootKeyInProps = GATT_PROP_READ | GATT_PROP_NOTIFY;
  394. static uint8 hidReportBootKeyIn;
  395. static gattCharCfg_t hidReportBootKeyInClientCharCfg[GATT_MAX_NUM_CONN];
  396. // HID Boot Keyboard Output Report
  397. static uint8 hidReportBootKeyOutProps = GATT_PROP_READ |
  398. GATT_PROP_WRITE |
  399. GATT_PROP_WRITE_NO_RSP;
  400. static uint8 hidReportBootKeyOut;
  401. // HID Report characteristic, consumer control input
  402. static uint8 hidReportCCInProps = GATT_PROP_READ | GATT_PROP_NOTIFY;
  403. static uint8 hidReportCCIn;
  404. static gattCharCfg_t hidReportCCInClientCharCfg[GATT_MAX_NUM_CONN];
  405. // HID Report Reference characteristic descriptor, consumer control input
  406. static uint8 hidReportRefCCIn[HID_REPORT_REF_LEN] =
  407. { HID_RPT_ID_CC_IN, HID_REPORT_TYPE_INPUT };
  408. #if 0
  409. // HID Report characteristic, Voice Start
  410. static uint8 hidReportVoiceStartProps = GATT_PROP_READ | GATT_PROP_NOTIFY;
  411. static uint8 hidReportVoiceStart;
  412. static gattCharCfg_t hidReportVoiceStartInClientCharCfg[GATT_MAX_NUM_CONN];
  413. static uint8 hidReportRefVoiceStart[HID_REPORT_REF_LEN] =
  414. { HID_RPT_ID_VOICE_START_IN, HID_REPORT_TYPE_INPUT };
  415. // HID Report characteristic, Voice Data
  416. static uint8 hidReportVoiceDataProps = GATT_PROP_READ | GATT_PROP_NOTIFY;
  417. static uint8 hidReportVoiceData;
  418. static gattCharCfg_t hidReportVoiceDataInClientCharCfg[GATT_MAX_NUM_CONN];
  419. static uint8 hidReportRefVoiceData[HID_REPORT_REF_LEN] =
  420. { HID_RPT_ID_VOICE_DATA_IN, HID_REPORT_TYPE_INPUT };
  421. #endif
  422. #else
  423. // HID Service attribute
  424. static CONST gattAttrType_t hidService = { ATT_BT_UUID_SIZE, hidServUUID };
  425. // Include attribute (Battery service)
  426. static uint16 include = GATT_INVALID_HANDLE;
  427. // HID Information characteristic
  428. static uint8 hidInfoProps = GATT_PROP_READ;
  429. // HID Report Map characteristic
  430. static uint8 hidReportMapProps = GATT_PROP_READ;
  431. // HID External Report Reference Descriptor
  432. static uint8 hidExtReportRefDesc[ATT_BT_UUID_SIZE] =
  433. { LO_UINT16(BATT_LEVEL_UUID), HI_UINT16(BATT_LEVEL_UUID) };
  434. // HID Control Point characteristic
  435. static uint8 hidControlPointProps = GATT_PROP_WRITE_NO_RSP;
  436. static uint8 hidControlPoint;
  437. // HID Protocol Mode characteristic
  438. static uint8 hidProtocolModeProps = GATT_PROP_READ | GATT_PROP_WRITE_NO_RSP;
  439. uint8 hidProtocolMode = HID_PROTOCOL_MODE_REPORT;
  440. // HID Report characteristic, key input
  441. static uint8 hidReportKeyInProps = GATT_PROP_READ | GATT_PROP_NOTIFY;
  442. static uint8 hidReportKeyIn;
  443. static gattCharCfg_t hidReportKeyInClientCharCfg[GATT_MAX_NUM_CONN];
  444. // HID Report Reference characteristic descriptor, key input
  445. static uint8 hidReportRefKeyIn[HID_REPORT_REF_LEN] =
  446. { HID_RPT_ID_KEY_IN, HID_REPORT_TYPE_INPUT };
  447. // HID Report characteristic, LED output
  448. static uint8 hidReportLedOutProps = GATT_PROP_READ | GATT_PROP_WRITE | GATT_PROP_WRITE_NO_RSP;
  449. static uint8 hidReportLedOut;
  450. // HID Report Reference characteristic descriptor, LED output
  451. static uint8 hidReportRefLedOut[HID_REPORT_REF_LEN] =
  452. { HID_RPT_ID_LED_OUT, HID_REPORT_TYPE_OUTPUT };
  453. // HID Boot Keyboard Input Report
  454. static uint8 hidReportBootKeyInProps = GATT_PROP_READ | GATT_PROP_NOTIFY;
  455. static uint8 hidReportBootKeyIn;
  456. static gattCharCfg_t hidReportBootKeyInClientCharCfg[GATT_MAX_NUM_CONN];
  457. // HID Boot Keyboard Output Report
  458. static uint8 hidReportBootKeyOutProps = GATT_PROP_READ | GATT_PROP_WRITE | GATT_PROP_WRITE_NO_RSP;
  459. static uint8 hidReportBootKeyOut;
  460. // HID Boot Mouse Input Report
  461. static uint8 hidReportBootMouseInProps = GATT_PROP_READ | GATT_PROP_NOTIFY;
  462. static uint8 hidReportBootMouseIn;
  463. static gattCharCfg_t hidReportBootMouseInClientCharCfg[GATT_MAX_NUM_CONN];
  464. // Feature Report
  465. static uint8 hidReportFeatureProps = GATT_PROP_READ | GATT_PROP_WRITE;
  466. static uint8 hidReportFeature;
  467. // HID Report Reference characteristic descriptor, Feature
  468. static uint8 hidReportRefFeature[HID_REPORT_REF_LEN] =
  469. { HID_RPT_ID_FEATURE, HID_REPORT_TYPE_FEATURE };
  470. #if EN_VOICE_MODE
  471. // HID Report characteristic, Voice Start
  472. static uint8 hidReportVoiceStartProps = GATT_PROP_READ | GATT_PROP_NOTIFY;
  473. static uint8 hidReportVoiceStart;
  474. static gattCharCfg_t *hidReportVoiceStartInClientCharCfg;
  475. static uint8 hidReportRefVoiceStart[HID_REPORT_REF_LEN] =
  476. { HID_RPT_ID_VOICE_START_IN, HID_REPORT_TYPE_INPUT };
  477. // HID Report characteristic, Voice Data
  478. static uint8 hidReportVoiceDataProps = GATT_PROP_READ | GATT_PROP_NOTIFY;
  479. static uint8 hidReportVoiceData;
  480. static gattCharCfg_t *hidReportVoiceDataInClientCharCfg;
  481. static uint8 hidReportRefVoiceData[HID_REPORT_REF_LEN] =
  482. { HID_RPT_ID_VOICE_DATA_IN, HID_REPORT_TYPE_INPUT };
  483. #endif
  484. #if EN_MOUSE_REPORT
  485. // HID Report Reference characteristic descriptor, mouse input
  486. static uint8 hidReportRefMouseIn[HID_REPORT_REF_LEN] =
  487. { HID_RPT_ID_MOUSE_IN, HID_REPORT_TYPE_INPUT };
  488. static uint8 hidReportMouseInProps = GATT_PROP_READ | GATT_PROP_NOTIFY;
  489. static uint8 hidReportMouseIn;
  490. static gattCharCfg_t hidReportMouseInClientCharCfg[GATT_MAX_NUM_CONN];
  491. #endif
  492. #if EN_CONSUMER_MODE
  493. // HID Report Reference characteristic descriptor, consumer control input
  494. static uint8 hidReportRefCCIn[HID_REPORT_REF_LEN] =
  495. { HID_RPT_ID_CC_IN, HID_REPORT_TYPE_INPUT };
  496. // HID Report characteristic, consumer control input
  497. static uint8 hidReportCCInProps = GATT_PROP_READ | GATT_PROP_NOTIFY;
  498. static uint8 hidReportCCIn;
  499. static gattCharCfg_t hidReportCCInClientCharCfg[GATT_MAX_NUM_CONN];
  500. #endif
  501. #endif
  502. /*********************************************************************
  503. * Profile Attributes - Table
  504. */
  505. #if FOLLOW_TI_MAP
  506. static gattAttribute_t hidAttrTbl[] =
  507. {
  508. // HID Service
  509. {
  510. { ATT_BT_UUID_SIZE, primaryServiceUUID }, /* type */
  511. GATT_PERMIT_READ, /* permissions */
  512. 0, /* handle */
  513. (uint8 *) &hidService /* pValue */
  514. },
  515. // Included service (battery)
  516. {
  517. { ATT_BT_UUID_SIZE, includeUUID },
  518. GATT_PERMIT_READ,
  519. 0,
  520. (uint8 *)&include
  521. },
  522. // HID Information characteristic declaration
  523. {
  524. { ATT_BT_UUID_SIZE, characterUUID },
  525. GATT_PERMIT_READ,
  526. 0,
  527. &hidInfoProps
  528. },
  529. // HID Information characteristic
  530. {
  531. { ATT_BT_UUID_SIZE, hidInfoUUID },
  532. GATT_PERMIT_ENCRYPT_READ,
  533. 0,
  534. (uint8 *) hidInfo
  535. },
  536. // HID Control Point characteristic declaration
  537. {
  538. { ATT_BT_UUID_SIZE, characterUUID },
  539. GATT_PERMIT_READ,
  540. 0,
  541. &hidControlPointProps
  542. },
  543. // HID Control Point characteristic
  544. {
  545. { ATT_BT_UUID_SIZE, hidControlPointUUID },
  546. GATT_PERMIT_ENCRYPT_WRITE,
  547. 0,
  548. &hidControlPoint
  549. },
  550. // HID Protocol Mode characteristic declaration
  551. {
  552. { ATT_BT_UUID_SIZE, characterUUID },
  553. GATT_PERMIT_READ,
  554. 0,
  555. &hidProtocolModeProps
  556. },
  557. // HID Protocol Mode characteristic
  558. {
  559. { ATT_BT_UUID_SIZE, hidProtocolModeUUID },
  560. GATT_PERMIT_ENCRYPT_READ | GATT_PERMIT_ENCRYPT_WRITE,
  561. 0,
  562. &hidProtocolMode
  563. },
  564. // HID Report Map characteristic declaration
  565. {
  566. { ATT_BT_UUID_SIZE, characterUUID },
  567. GATT_PERMIT_READ,
  568. 0,
  569. &hidReportMapProps
  570. },
  571. // HID Report Map characteristic
  572. {
  573. { ATT_BT_UUID_SIZE, hidReportMapUUID },
  574. GATT_PERMIT_ENCRYPT_READ,
  575. 0,
  576. (uint8 *) hidReportMap
  577. },
  578. // HID External Report Reference Descriptor
  579. {
  580. { ATT_BT_UUID_SIZE, extReportRefUUID },
  581. GATT_PERMIT_READ,
  582. 0,
  583. hidExtReportRefDesc
  584. },
  585. // HID Report characteristic declaration, key input
  586. {
  587. { ATT_BT_UUID_SIZE, characterUUID },
  588. GATT_PERMIT_READ,
  589. 0,
  590. &hidReportKeyInProps
  591. },
  592. // HID Report characteristic, key input
  593. {
  594. { ATT_BT_UUID_SIZE, hidReportUUID },
  595. GATT_PERMIT_ENCRYPT_READ,
  596. 0,
  597. &hidReportKeyIn
  598. },
  599. // HID Report characteristic client characteristic configuration, key input
  600. {
  601. { ATT_BT_UUID_SIZE, clientCharCfgUUID },
  602. GATT_PERMIT_READ | GATT_PERMIT_ENCRYPT_WRITE,
  603. 0,
  604. (uint8 *) &hidReportKeyInClientCharCfg
  605. },
  606. // HID Report Reference characteristic descriptor, key input
  607. {
  608. { ATT_BT_UUID_SIZE, reportRefUUID },
  609. GATT_PERMIT_READ,
  610. 0,
  611. hidReportRefKeyIn
  612. },
  613. // HID Report characteristic, LED output declaration
  614. {
  615. { ATT_BT_UUID_SIZE, characterUUID },
  616. GATT_PERMIT_READ,
  617. 0,
  618. &hidReportLedOutProps
  619. },
  620. // HID Report characteristic, LED output
  621. {
  622. { ATT_BT_UUID_SIZE, hidReportUUID },
  623. GATT_PERMIT_ENCRYPT_READ | GATT_PERMIT_ENCRYPT_WRITE,
  624. 0,
  625. &hidReportLedOut
  626. },
  627. // HID Report Reference characteristic descriptor, LED output
  628. {
  629. { ATT_BT_UUID_SIZE, reportRefUUID },
  630. GATT_PERMIT_READ,
  631. 0,
  632. hidReportRefLedOut
  633. },
  634. // HID Boot Keyboard Input Report declaration
  635. {
  636. { ATT_BT_UUID_SIZE, characterUUID },
  637. GATT_PERMIT_READ,
  638. 0,
  639. &hidReportBootKeyInProps
  640. },
  641. // HID Boot Keyboard Input Report
  642. {
  643. { ATT_BT_UUID_SIZE, hidBootKeyInputUUID },
  644. GATT_PERMIT_ENCRYPT_READ,
  645. 0,
  646. &hidReportBootKeyIn
  647. },
  648. // HID Boot Keyboard Input Report characteristic client characteristic configuration
  649. {
  650. { ATT_BT_UUID_SIZE, clientCharCfgUUID },
  651. GATT_PERMIT_READ | GATT_PERMIT_ENCRYPT_WRITE,
  652. 0,
  653. (uint8 *) &hidReportBootKeyInClientCharCfg
  654. },
  655. // HID Boot Keyboard Output Report declaration
  656. {
  657. { ATT_BT_UUID_SIZE, characterUUID },
  658. GATT_PERMIT_READ,
  659. 0,
  660. &hidReportBootKeyOutProps
  661. },
  662. // HID Boot Keyboard Output Report
  663. {
  664. { ATT_BT_UUID_SIZE, hidBootKeyOutputUUID },
  665. GATT_PERMIT_ENCRYPT_READ | GATT_PERMIT_ENCRYPT_WRITE,
  666. 0,
  667. &hidReportBootKeyOut
  668. },
  669. // HID Report characteristic declaration, consumer control
  670. {
  671. { ATT_BT_UUID_SIZE, characterUUID },
  672. GATT_PERMIT_READ,
  673. 0,
  674. &hidReportCCInProps
  675. },
  676. // HID Report characteristic, consumer control
  677. {
  678. { ATT_BT_UUID_SIZE, hidReportUUID },
  679. GATT_PERMIT_ENCRYPT_READ,
  680. 0,
  681. &hidReportCCIn
  682. },
  683. // HID Report characteristic client characteristic configuration, consumer control
  684. {
  685. { ATT_BT_UUID_SIZE, clientCharCfgUUID },
  686. GATT_PERMIT_READ | GATT_PERMIT_ENCRYPT_WRITE,
  687. 0,
  688. (uint8 *) &hidReportCCInClientCharCfg
  689. },
  690. // HID Report Reference characteristic descriptor, consumer control
  691. {
  692. { ATT_BT_UUID_SIZE, reportRefUUID },
  693. GATT_PERMIT_READ,
  694. 0,
  695. hidReportRefCCIn
  696. },
  697. #if 0
  698. // HID Voice Start Input Report declaration
  699. {
  700. { ATT_BT_UUID_SIZE, characterUUID },
  701. GATT_PERMIT_READ,
  702. 0,
  703. &hidReportVoiceStartProps
  704. },
  705. // HID Voice Start Input Report
  706. {
  707. { ATT_BT_UUID_SIZE, hidReportUUID },
  708. GATT_PERMIT_ENCRYPT_READ,
  709. 0,
  710. &hidReportVoiceStart
  711. },
  712. // HID Voice Start Input Report characteristic client characteristic configuration
  713. {
  714. { ATT_BT_UUID_SIZE, clientCharCfgUUID },
  715. GATT_PERMIT_READ | GATT_PERMIT_ENCRYPT_WRITE,
  716. 0,
  717. (uint8 *) &hidReportVoiceStartInClientCharCfg
  718. },
  719. // HID Report Reference characteristic descriptor, Voice Start
  720. {
  721. { ATT_BT_UUID_SIZE, reportRefUUID },
  722. GATT_PERMIT_READ,
  723. 0,
  724. hidReportRefVoiceStart
  725. },
  726. // HID Voice Data Input Report declaration
  727. {
  728. { ATT_BT_UUID_SIZE, characterUUID },
  729. GATT_PERMIT_READ,
  730. 0,
  731. &hidReportVoiceDataProps
  732. },
  733. // HID Voice Data Input Report
  734. {
  735. { ATT_BT_UUID_SIZE, hidReportUUID },
  736. GATT_PERMIT_ENCRYPT_READ,
  737. 0,
  738. &hidReportVoiceData
  739. },
  740. // HID Voice Data Input Report characteristic client characteristic configuration
  741. {
  742. { ATT_BT_UUID_SIZE, clientCharCfgUUID },
  743. GATT_PERMIT_READ | GATT_PERMIT_ENCRYPT_WRITE,
  744. 0,
  745. (uint8 *) &hidReportVoiceDataInClientCharCfg
  746. },
  747. // HID Report Reference characteristic descriptor, Voice Data
  748. {
  749. { ATT_BT_UUID_SIZE, reportRefUUID },
  750. GATT_PERMIT_READ,
  751. 0,
  752. hidReportRefVoiceData
  753. },
  754. #endif
  755. };
  756. #else
  757. static gattAttribute_t hidAttrTbl[] =
  758. {
  759. // HID Service
  760. {
  761. { ATT_BT_UUID_SIZE, primaryServiceUUID }, /* type */
  762. GATT_PERMIT_READ, /* permissions */
  763. 0, /* handle */
  764. (uint8 *) &hidService /* pValue */
  765. },
  766. // Included service (battery)
  767. {
  768. { ATT_BT_UUID_SIZE, includeUUID },
  769. GATT_PERMIT_READ,
  770. 0,
  771. (uint8 *)&include
  772. },
  773. // HID Information characteristic declaration
  774. {
  775. { ATT_BT_UUID_SIZE, characterUUID },
  776. GATT_PERMIT_READ,
  777. 0,
  778. &hidInfoProps
  779. },
  780. // HID Information characteristic
  781. {
  782. { ATT_BT_UUID_SIZE, hidInfoUUID },
  783. GATT_PERMIT_ENCRYPT_READ,
  784. 0,
  785. (uint8 *) hidInfo
  786. },
  787. // HID Control Point characteristic declaration
  788. {
  789. { ATT_BT_UUID_SIZE, characterUUID },
  790. GATT_PERMIT_READ,
  791. 0,
  792. &hidControlPointProps
  793. },
  794. // HID Control Point characteristic
  795. {
  796. { ATT_BT_UUID_SIZE, hidControlPointUUID },
  797. GATT_PERMIT_ENCRYPT_WRITE,
  798. 0,
  799. &hidControlPoint
  800. },
  801. // HID Protocol Mode characteristic declaration
  802. {
  803. { ATT_BT_UUID_SIZE, characterUUID },
  804. GATT_PERMIT_READ,
  805. 0,
  806. &hidProtocolModeProps
  807. },
  808. // HID Protocol Mode characteristic
  809. {
  810. { ATT_BT_UUID_SIZE, hidProtocolModeUUID },
  811. GATT_PERMIT_ENCRYPT_READ | GATT_PERMIT_ENCRYPT_WRITE,
  812. 0,
  813. &hidProtocolMode
  814. },
  815. // HID Report Map characteristic declaration
  816. {
  817. { ATT_BT_UUID_SIZE, characterUUID },
  818. GATT_PERMIT_READ,
  819. 0,
  820. &hidReportMapProps
  821. },
  822. // HID Report Map characteristic
  823. {
  824. { ATT_BT_UUID_SIZE, hidReportMapUUID },
  825. GATT_PERMIT_ENCRYPT_READ,
  826. 0,
  827. (uint8 *) hidReportMap
  828. },
  829. // HID External Report Reference Descriptor
  830. {
  831. { ATT_BT_UUID_SIZE, extReportRefUUID },
  832. GATT_PERMIT_READ,
  833. 0,
  834. hidExtReportRefDesc
  835. },
  836. #if EN_MOUSE_REPORT
  837. // HID Report characteristic, mouse input declaration
  838. {
  839. { ATT_BT_UUID_SIZE, characterUUID },
  840. GATT_PERMIT_READ,
  841. 0,
  842. &hidReportMouseInProps
  843. },
  844. // HID Report characteristic, mouse input
  845. {
  846. { ATT_BT_UUID_SIZE, hidReportUUID },
  847. GATT_PERMIT_ENCRYPT_READ,
  848. 0,
  849. &hidReportMouseIn
  850. },
  851. // HID Report characteristic client characteristic configuration
  852. {
  853. { ATT_BT_UUID_SIZE, clientCharCfgUUID },
  854. GATT_PERMIT_READ | GATT_PERMIT_ENCRYPT_WRITE,
  855. 0,
  856. (uint8 *) &hidReportMouseInClientCharCfg
  857. },
  858. // HID Report Reference characteristic descriptor, mouse input
  859. {
  860. { ATT_BT_UUID_SIZE, reportRefUUID },
  861. GATT_PERMIT_READ,
  862. 0,
  863. hidReportRefMouseIn
  864. },
  865. #endif
  866. // HID Report characteristic, key input declaration
  867. {
  868. { ATT_BT_UUID_SIZE, characterUUID },
  869. GATT_PERMIT_READ,
  870. 0,
  871. &hidReportKeyInProps
  872. },
  873. // HID Report characteristic, key input
  874. {
  875. { ATT_BT_UUID_SIZE, hidReportUUID },
  876. GATT_PERMIT_ENCRYPT_READ,
  877. 0,
  878. &hidReportKeyIn
  879. },
  880. // HID Report characteristic client characteristic configuration
  881. {
  882. { ATT_BT_UUID_SIZE, clientCharCfgUUID },
  883. GATT_PERMIT_READ | GATT_PERMIT_ENCRYPT_WRITE,
  884. 0,
  885. (uint8 *) &hidReportKeyInClientCharCfg
  886. },
  887. // HID Report Reference characteristic descriptor, key input
  888. {
  889. { ATT_BT_UUID_SIZE, reportRefUUID },
  890. GATT_PERMIT_READ,
  891. 0,
  892. hidReportRefKeyIn
  893. },
  894. // HID Report characteristic, LED output declaration
  895. {
  896. { ATT_BT_UUID_SIZE, characterUUID },
  897. GATT_PERMIT_READ,
  898. 0,
  899. &hidReportLedOutProps
  900. },
  901. // HID Report characteristic, LED output
  902. {
  903. { ATT_BT_UUID_SIZE, hidReportUUID },
  904. GATT_PERMIT_ENCRYPT_READ | GATT_PERMIT_ENCRYPT_WRITE,
  905. 0,
  906. &hidReportLedOut
  907. },
  908. // HID Report Reference characteristic descriptor, LED output
  909. {
  910. { ATT_BT_UUID_SIZE, reportRefUUID },
  911. GATT_PERMIT_READ,
  912. 0,
  913. hidReportRefLedOut
  914. },
  915. // HID Boot Keyboard Input Report declaration
  916. {
  917. { ATT_BT_UUID_SIZE, characterUUID },
  918. GATT_PERMIT_READ,
  919. 0,
  920. &hidReportBootKeyInProps
  921. },
  922. // HID Boot Keyboard Input Report
  923. {
  924. { ATT_BT_UUID_SIZE, hidBootKeyInputUUID },
  925. GATT_PERMIT_ENCRYPT_READ,
  926. 0,
  927. &hidReportBootKeyIn
  928. },
  929. // HID Boot Keyboard Input Report characteristic client characteristic configuration
  930. {
  931. { ATT_BT_UUID_SIZE, clientCharCfgUUID },
  932. GATT_PERMIT_READ | GATT_PERMIT_ENCRYPT_WRITE,
  933. 0,
  934. (uint8 *) &hidReportBootKeyInClientCharCfg
  935. },
  936. // HID Boot Keyboard Output Report declaration
  937. {
  938. { ATT_BT_UUID_SIZE, characterUUID },
  939. GATT_PERMIT_READ,
  940. 0,
  941. &hidReportBootKeyOutProps
  942. },
  943. // HID Boot Keyboard Output Report
  944. {
  945. { ATT_BT_UUID_SIZE, hidBootKeyOutputUUID },
  946. GATT_PERMIT_ENCRYPT_READ | GATT_PERMIT_ENCRYPT_WRITE,
  947. 0,
  948. &hidReportBootKeyOut
  949. },
  950. #if EN_CONSUMER_MODE
  951. // HID Report characteristic declaration, consumer control
  952. {
  953. { ATT_BT_UUID_SIZE, characterUUID },
  954. GATT_PERMIT_READ,
  955. 0,
  956. &hidReportCCInProps
  957. },
  958. // HID Report characteristic, consumer control
  959. {
  960. { ATT_BT_UUID_SIZE, hidReportUUID },
  961. GATT_PERMIT_ENCRYPT_READ,
  962. 0,
  963. &hidReportCCIn
  964. },
  965. // HID Report characteristic client characteristic configuration, consumer control
  966. {
  967. { ATT_BT_UUID_SIZE, clientCharCfgUUID },
  968. GATT_PERMIT_READ | GATT_PERMIT_ENCRYPT_WRITE,
  969. 0,
  970. (uint8 *) &hidReportCCInClientCharCfg
  971. },
  972. // HID Report Reference characteristic descriptor, consumer control
  973. {
  974. { ATT_BT_UUID_SIZE, reportRefUUID },
  975. GATT_PERMIT_READ,
  976. 0,
  977. hidReportRefCCIn
  978. },
  979. #endif
  980. // HID Boot Mouse Input Report declaration
  981. {
  982. { ATT_BT_UUID_SIZE, characterUUID },
  983. GATT_PERMIT_READ,
  984. 0,
  985. &hidReportBootMouseInProps
  986. },
  987. // HID Boot Mouse Input Report
  988. {
  989. { ATT_BT_UUID_SIZE, hidBootMouseInputUUID },
  990. GATT_PERMIT_ENCRYPT_READ,
  991. 0,
  992. &hidReportBootMouseIn
  993. },
  994. // HID Boot Mouse Input Report characteristic client characteristic configuration
  995. {
  996. { ATT_BT_UUID_SIZE, clientCharCfgUUID },
  997. GATT_PERMIT_READ | GATT_PERMIT_ENCRYPT_WRITE,
  998. 0,
  999. (uint8 *) &hidReportBootMouseInClientCharCfg
  1000. },
  1001. // Feature Report declaration
  1002. {
  1003. { ATT_BT_UUID_SIZE, characterUUID },
  1004. GATT_PERMIT_READ,
  1005. 0,
  1006. &hidReportFeatureProps
  1007. },
  1008. // Feature Report
  1009. {
  1010. { ATT_BT_UUID_SIZE, hidReportUUID},
  1011. GATT_PERMIT_ENCRYPT_READ | GATT_PERMIT_ENCRYPT_WRITE,
  1012. 0,
  1013. &hidReportFeature
  1014. },
  1015. // HID Report Reference characteristic descriptor, feature
  1016. {
  1017. { ATT_BT_UUID_SIZE, reportRefUUID },
  1018. GATT_PERMIT_READ,
  1019. 0,
  1020. hidReportRefFeature
  1021. },
  1022. #if EN_VOICE_MODE
  1023. // HID Voice Start Input Report declaration
  1024. {
  1025. { ATT_BT_UUID_SIZE, characterUUID },
  1026. GATT_PERMIT_READ,
  1027. 0,
  1028. &hidReportVoiceStartProps
  1029. },
  1030. // HID Voice Start Input Report
  1031. {
  1032. { ATT_BT_UUID_SIZE, hidReportUUID },
  1033. GATT_PERMIT_ENCRYPT_READ,
  1034. 0,
  1035. &hidReportVoiceStart
  1036. },
  1037. // HID Voice Start Input Report characteristic client characteristic configuration
  1038. {
  1039. { ATT_BT_UUID_SIZE, clientCharCfgUUID },
  1040. GATT_PERMIT_READ | GATT_PERMIT_ENCRYPT_WRITE,
  1041. 0,
  1042. (uint8 *) &hidReportVoiceStartInClientCharCfg
  1043. },
  1044. // HID Report Reference characteristic descriptor, Voice Start
  1045. {
  1046. { ATT_BT_UUID_SIZE, reportRefUUID },
  1047. GATT_PERMIT_READ,
  1048. 0,
  1049. hidReportRefVoiceStart
  1050. },
  1051. // HID Voice Data Input Report declaration
  1052. {
  1053. { ATT_BT_UUID_SIZE, characterUUID },
  1054. GATT_PERMIT_READ,
  1055. 0,
  1056. &hidReportVoiceDataProps
  1057. },
  1058. // HID Voice Data Input Report
  1059. {
  1060. { ATT_BT_UUID_SIZE, hidReportUUID },
  1061. GATT_PERMIT_ENCRYPT_READ,
  1062. 0,
  1063. &hidReportVoiceData
  1064. },
  1065. // HID Voice Data Input Report characteristic client characteristic configuration
  1066. {
  1067. { ATT_BT_UUID_SIZE, clientCharCfgUUID },
  1068. GATT_PERMIT_READ | GATT_PERMIT_ENCRYPT_WRITE,
  1069. 0,
  1070. (uint8 *) &hidReportVoiceDataInClientCharCfg
  1071. },
  1072. // HID Report Reference characteristic descriptor, Voice Data
  1073. {
  1074. { ATT_BT_UUID_SIZE, reportRefUUID },
  1075. GATT_PERMIT_READ,
  1076. 0,
  1077. hidReportRefVoiceData
  1078. },
  1079. #endif
  1080. };
  1081. #endif
  1082. /*********************************************************************
  1083. * LOCAL FUNCTIONS
  1084. */
  1085. /*********************************************************************
  1086. * PROFILE CALLBACKS
  1087. */
  1088. // Service Callbacks
  1089. CONST gattServiceCBs_t hidKbdCBs =
  1090. {
  1091. HidDev_ReadAttrCB, // Read callback function pointer
  1092. HidDev_WriteAttrCB, // Write callback function pointer
  1093. NULL // Authorization callback function pointer
  1094. };
  1095. /*********************************************************************
  1096. * PUBLIC FUNCTIONS
  1097. */
  1098. /*********************************************************************
  1099. * @fn HidKbd_AddService
  1100. *
  1101. * @brief Initializes the HID Service by registering
  1102. * GATT attributes with the GATT server.
  1103. *
  1104. * @return Success or Failure
  1105. */
  1106. #if FOLLOW_TI_MAP
  1107. bStatus_t HidKbd_AddService( void )
  1108. {
  1109. uint8 status = SUCCESS;
  1110. // Initialize Client Characteristic Configuration attributes
  1111. GATTServApp_InitCharCfg( INVALID_CONNHANDLE, hidReportKeyInClientCharCfg );
  1112. GATTServApp_InitCharCfg( INVALID_CONNHANDLE, hidReportBootKeyInClientCharCfg );
  1113. GATTServApp_InitCharCfg(INVALID_CONNHANDLE, hidReportCCInClientCharCfg);
  1114. #if 0
  1115. GATTServApp_InitCharCfg(INVALID_CONNHANDLE, hidReportVoiceStartInClientCharCfg);
  1116. GATTServApp_InitCharCfg(INVALID_CONNHANDLE, hidReportVoiceDataInClientCharCfg);
  1117. #endif
  1118. // Register GATT attribute list and CBs with GATT Server App
  1119. status = GATTServApp_RegisterService( hidAttrTbl, GATT_NUM_ATTRS( hidAttrTbl ), &hidKbdCBs );
  1120. // Set up included service
  1121. Batt_GetParameter( BATT_PARAM_SERVICE_HANDLE,
  1122. &GATT_INCLUDED_HANDLE( hidAttrTbl, HID_INCLUDED_SERVICE_IDX ) );
  1123. // Construct map of reports to characteristic handles
  1124. // Each report is uniquely identified via its ID and type
  1125. // Key input report
  1126. hidRptMap[0].id = hidReportRefKeyIn[0];
  1127. hidRptMap[0].type = hidReportRefKeyIn[1];
  1128. hidRptMap[0].handle = hidAttrTbl[HID_REPORT_KEY_IN_IDX].handle;
  1129. hidRptMap[0].cccdHandle = hidAttrTbl[HID_REPORT_KEY_IN_CCCD_IDX].handle;
  1130. hidRptMap[0].mode = HID_PROTOCOL_MODE_REPORT;
  1131. // LED output report
  1132. hidRptMap[1].id = hidReportRefLedOut[0];
  1133. hidRptMap[1].type = hidReportRefLedOut[1];
  1134. hidRptMap[1].handle = hidAttrTbl[HID_REPORT_LED_OUT_IDX].handle;
  1135. hidRptMap[1].cccdHandle = 0;
  1136. hidRptMap[1].mode = HID_PROTOCOL_MODE_REPORT;
  1137. // Boot keyboard input report
  1138. // Use same ID and type as key input report
  1139. hidRptMap[2].id = hidReportRefKeyIn[0];
  1140. hidRptMap[2].type = hidReportRefKeyIn[1];
  1141. hidRptMap[2].handle = hidAttrTbl[HID_BOOT_KEY_IN_IDX].handle;
  1142. hidRptMap[2].cccdHandle = hidAttrTbl[HID_BOOT_KEY_IN_CCCD_IDX].handle;
  1143. hidRptMap[2].mode = HID_PROTOCOL_MODE_BOOT;
  1144. // Boot keyboard output report
  1145. // Use same ID and type as LED output report
  1146. hidRptMap[3].id = hidReportRefLedOut[0];
  1147. hidRptMap[3].type = hidReportRefLedOut[1];
  1148. hidRptMap[3].handle = hidAttrTbl[HID_BOOT_KEY_OUT_IDX].handle;
  1149. hidRptMap[3].cccdHandle = 0;
  1150. hidRptMap[3].mode = HID_PROTOCOL_MODE_BOOT;
  1151. // Consumer Control input report
  1152. hidRptMap[4].id = hidReportRefCCIn[0];
  1153. hidRptMap[4].type = hidReportRefCCIn[1];
  1154. hidRptMap[4].handle = hidAttrTbl[HID_REPORT_CC_IN_IDX].handle;
  1155. hidRptMap[4].cccdHandle = hidAttrTbl[HID_REPORT_CC_IN_CCCD_IDX].handle;
  1156. hidRptMap[4].mode = HID_PROTOCOL_MODE_REPORT;
  1157. #if 0
  1158. // Voice Start input report
  1159. hidRptMap[5].id = hidReportRefVoiceStart[0];
  1160. hidRptMap[5].type = hidReportRefVoiceStart[1];
  1161. hidRptMap[5].handle = hidAttrTbl[HID_VOICE_START_IN_IDX].handle;
  1162. hidRptMap[5].cccdHandle = hidAttrTbl[HID_VOICE_START_IN_CCCD_IDX].handle;
  1163. hidRptMap[5].mode = HID_PROTOCOL_MODE_REPORT;
  1164. // Voice Data input report
  1165. hidRptMap[6].id = hidReportRefVoiceData[0];
  1166. hidRptMap[6].type = hidReportRefVoiceData[1];
  1167. hidRptMap[6].handle = hidAttrTbl[HID_VOICE_DATA_IN_IDX].handle;
  1168. hidRptMap[6].cccdHandle = hidAttrTbl[HID_VOICE_DATA_IN_CCCD_IDX].handle;
  1169. hidRptMap[6].mode = HID_PROTOCOL_MODE_REPORT;
  1170. #endif
  1171. // Battery level input report
  1172. VOID Batt_GetParameter( BATT_PARAM_BATT_LEVEL_IN_REPORT, &(hidRptMap[2]) );
  1173. // Setup report ID map
  1174. HidDev_RegisterReports( HID_NUM_REPORTS, hidRptMap );
  1175. return ( status );
  1176. }
  1177. #else
  1178. bStatus_t HidKbd_AddService( void )
  1179. {
  1180. uint8 status = SUCCESS;
  1181. // Initialize Client Characteristic Configuration attributes
  1182. GATTServApp_InitCharCfg( INVALID_CONNHANDLE, hidReportKeyInClientCharCfg );
  1183. GATTServApp_InitCharCfg( INVALID_CONNHANDLE, hidReportBootKeyInClientCharCfg );
  1184. GATTServApp_InitCharCfg( INVALID_CONNHANDLE, hidReportBootMouseInClientCharCfg );
  1185. // Register GATT attribute list and CBs with GATT Server App
  1186. status = GATTServApp_RegisterService( hidAttrTbl, GATT_NUM_ATTRS( hidAttrTbl ), &hidKbdCBs );
  1187. // Set up included service
  1188. Batt_GetParameter( BATT_PARAM_SERVICE_HANDLE,
  1189. &GATT_INCLUDED_HANDLE( hidAttrTbl, HID_INCLUDED_SERVICE_IDX ) );
  1190. // Construct map of reports to characteristic handles
  1191. // Each report is uniquely identified via its ID and type
  1192. // Key input report
  1193. hidRptMap[0].id = hidReportRefKeyIn[0];
  1194. hidRptMap[0].type = hidReportRefKeyIn[1];
  1195. hidRptMap[0].handle = hidAttrTbl[HID_REPORT_KEY_IN_IDX].handle;
  1196. hidRptMap[0].cccdHandle = hidAttrTbl[HID_REPORT_KEY_IN_CCCD_IDX].handle;
  1197. hidRptMap[0].mode = HID_PROTOCOL_MODE_REPORT;
  1198. // LED output report
  1199. hidRptMap[1].id = hidReportRefLedOut[0];
  1200. hidRptMap[1].type = hidReportRefLedOut[1];
  1201. hidRptMap[1].handle = hidAttrTbl[HID_REPORT_LED_OUT_IDX].handle;
  1202. hidRptMap[1].cccdHandle = 0;
  1203. hidRptMap[1].mode = HID_PROTOCOL_MODE_REPORT;
  1204. // Boot keyboard input report
  1205. // Use same ID and type as key input report
  1206. hidRptMap[2].id = hidReportRefKeyIn[0];
  1207. hidRptMap[2].type = hidReportRefKeyIn[1];
  1208. hidRptMap[2].handle = hidAttrTbl[HID_BOOT_KEY_IN_IDX].handle;
  1209. hidRptMap[2].cccdHandle = hidAttrTbl[HID_BOOT_KEY_IN_CCCD_IDX].handle;
  1210. hidRptMap[2].mode = HID_PROTOCOL_MODE_BOOT;
  1211. // Boot keyboard output report
  1212. // Use same ID and type as LED output report
  1213. hidRptMap[3].id = hidReportRefLedOut[0];
  1214. hidRptMap[3].type = hidReportRefLedOut[1];
  1215. hidRptMap[3].handle = hidAttrTbl[HID_BOOT_KEY_OUT_IDX].handle;
  1216. hidRptMap[3].cccdHandle = 0;
  1217. hidRptMap[3].mode = HID_PROTOCOL_MODE_BOOT;
  1218. // Boot mouse input report
  1219. hidRptMap[4].id = HID_RPT_ID_MOUSE_IN;
  1220. hidRptMap[4].type = HID_REPORT_TYPE_INPUT;
  1221. hidRptMap[4].handle = hidAttrTbl[HID_BOOT_MOUSE_IN_IDX].handle;
  1222. hidRptMap[4].cccdHandle = hidAttrTbl[HID_BOOT_MOUSE_IN_CCCD_IDX].handle;
  1223. hidRptMap[4].mode = HID_PROTOCOL_MODE_BOOT;
  1224. // Feature report
  1225. hidRptMap[5].id = hidReportRefFeature[0];
  1226. hidRptMap[5].type = hidReportRefFeature[1];
  1227. hidRptMap[5].handle = hidAttrTbl[HID_FEATURE_IDX].handle;
  1228. hidRptMap[5].cccdHandle = 0;
  1229. hidRptMap[5].mode = HID_PROTOCOL_MODE_REPORT;
  1230. // Battery level input report
  1231. VOID Batt_GetParameter( BATT_PARAM_BATT_LEVEL_IN_REPORT, &(hidRptMap[6]) );
  1232. #if EN_VOICE_MODE
  1233. // Voice Start input report
  1234. hidRptMap[7].id = hidReportRefVoiceStart[0];
  1235. hidRptMap[7].type = hidReportRefVoiceStart[1];
  1236. hidRptMap[7].handle = hidAttrTbl[HID_VOICE_START_IN_IDX].handle;
  1237. hidRptMap[7].cccdHandle = hidAttrTbl[HID_VOICE_START_IN_CCCD_IDX].handle;
  1238. hidRptMap[7].mode = HID_PROTOCOL_MODE_REPORT;
  1239. // Voice Data input report
  1240. hidRptMap[8].id = hidReportRefVoiceData[0];
  1241. hidRptMap[8].type = hidReportRefVoiceData[1];
  1242. hidRptMap[8].handle = hidAttrTbl[HID_VOICE_DATA_IN_IDX].handle;
  1243. hidRptMap[8].cccdHandle = hidAttrTbl[HID_VOICE_DATA_IN_CCCD_IDX].handle;
  1244. hidRptMap[8].mode = HID_PROTOCOL_MODE_REPORT;
  1245. #endif
  1246. #if EN_MOUSE_REPORT
  1247. // Mouse input report
  1248. hidRptMap[9].id = hidReportRefMouseIn[0];
  1249. hidRptMap[9].type = hidReportRefMouseIn[1];
  1250. hidRptMap[9].handle = hidAttrTbl[HID_REPORT_MOUSE_IN_IDX].handle;
  1251. hidRptMap[9].cccdHandle = hidAttrTbl[HID_REPORT_MOUSE_IN_CCCD_IDX].handle;
  1252. hidRptMap[9].mode = HID_PROTOCOL_MODE_REPORT;
  1253. #endif
  1254. #if EN_CONSUMER_MODE
  1255. // Consumer Control input report
  1256. hidRptMap[10].id = hidReportRefCCIn[0];
  1257. hidRptMap[10].type = hidReportRefCCIn[1];
  1258. hidRptMap[10].handle = hidAttrTbl[HID_REPORT_CC_IN_IDX].handle;
  1259. hidRptMap[10].cccdHandle = hidAttrTbl[HID_REPORT_CC_IN_CCCD_IDX].handle;
  1260. hidRptMap[10].mode = HID_PROTOCOL_MODE_REPORT;
  1261. #endif
  1262. // Setup report ID map
  1263. HidDev_RegisterReports( HID_NUM_REPORTS, hidRptMap );
  1264. return ( status );
  1265. }
  1266. #endif
  1267. /*********************************************************************
  1268. * @fn HidKbd_SetParameter
  1269. *
  1270. * @brief Set a HID Kbd parameter.
  1271. *
  1272. * @param id - HID report ID.
  1273. * @param type - HID report type.
  1274. * @param uuid - attribute uuid.
  1275. * @param len - length of data to right.
  1276. * @param pValue - pointer to data to write. This is dependent on
  1277. * the input parameters and WILL be cast to the appropriate
  1278. * data type (example: data type of uint16 will be cast to
  1279. * uint16 pointer).
  1280. *
  1281. * @return GATT status code.
  1282. */
  1283. uint8 HidKbd_SetParameter( uint8 id, uint8 type, uint16 uuid, uint16 len, void *pValue )
  1284. {
  1285. bStatus_t ret = SUCCESS;
  1286. switch ( uuid )
  1287. {
  1288. case REPORT_UUID:
  1289. if ( type == HID_REPORT_TYPE_OUTPUT )
  1290. {
  1291. if ( len == 1 )
  1292. {
  1293. hidReportLedOut = *((uint8 *)pValue);
  1294. }
  1295. else
  1296. {
  1297. ret = ATT_ERR_INVALID_VALUE_SIZE;
  1298. }
  1299. }
  1300. else if ( type == HID_REPORT_TYPE_FEATURE )
  1301. {
  1302. if ( len == 1 )
  1303. {
  1304. // hidReportFeature = *((uint8 *)pValue);
  1305. }
  1306. else
  1307. {
  1308. ret = ATT_ERR_INVALID_VALUE_SIZE;
  1309. }
  1310. }
  1311. else
  1312. {
  1313. ret = ATT_ERR_ATTR_NOT_FOUND;
  1314. }
  1315. break;
  1316. case BOOT_KEY_OUTPUT_UUID:
  1317. if ( len == 1 )
  1318. {
  1319. hidReportBootKeyOut = *((uint8 *)pValue);
  1320. }
  1321. else
  1322. {
  1323. ret = ATT_ERR_INVALID_VALUE_SIZE;
  1324. }
  1325. break;
  1326. default:
  1327. // ignore the request
  1328. break;
  1329. }
  1330. return ( ret );
  1331. }
  1332. /*********************************************************************
  1333. * @fn HidKbd_GetParameter
  1334. *
  1335. * @brief Get a HID Kbd parameter.
  1336. *
  1337. * @param id - HID report ID.
  1338. * @param type - HID report type.
  1339. * @param uuid - attribute uuid.
  1340. * @param pLen - length of data to be read
  1341. * @param pValue - pointer to data to get. This is dependent on
  1342. * the input parameters and WILL be cast to the appropriate
  1343. * data type (example: data type of uint16 will be cast to
  1344. * uint16 pointer).
  1345. *
  1346. * @return GATT status code.
  1347. */
  1348. uint8 HidKbd_GetParameter( uint8 id, uint8 type, uint16 uuid, uint16 *pLen, void *pValue )
  1349. {
  1350. switch ( uuid )
  1351. {
  1352. case REPORT_UUID:
  1353. if ( type == HID_REPORT_TYPE_OUTPUT )
  1354. {
  1355. *((uint8 *)pValue) = hidReportLedOut;
  1356. *pLen = 1;
  1357. }
  1358. else if ( type == HID_REPORT_TYPE_FEATURE )
  1359. {
  1360. // *((uint8 *)pValue) = hidReportFeature;
  1361. // *pLen = 1;
  1362. }
  1363. else
  1364. {
  1365. *pLen = 0;
  1366. }
  1367. break;
  1368. case BOOT_KEY_OUTPUT_UUID:
  1369. *((uint8 *)pValue) = hidReportBootKeyOut;
  1370. *pLen = 1;
  1371. break;
  1372. default:
  1373. *pLen = 0;
  1374. break;
  1375. }
  1376. return ( SUCCESS );
  1377. }
  1378. /*********************************************************************
  1379. *********************************************************************/