hidkbdservice.c 48 KB

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