1 /* 2 * Copyright (c) 2021 Chipsea Technologies (Shenzhen) Corp., Ltd. All rights reserved. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef _HID_OVER_GATT_TASK_H 17 #define _HID_OVER_GATT_TASK_H 18 19 #include <stdint.h> 20 #include "ble_ip_task.h" // Task definitions 21 22 /// Maximal number of HIDS that can be added in the DB 23 #define HOGPD_NB_HIDS_INST_MAX (2) 24 /// Maximal number of Report Char. that can be added in the DB for one HIDS - Up to 11 25 #define HOGPD_NB_REPORT_INST_MAX (5) 26 /// Number of HIDS that added in the DB 27 #define HOGPDF_NB_HIDS_INST (1) 28 29 /// Messages for HID Over GATT Profile Device Role 30 enum hogpd_msg_id 31 { 32 /// Restore bond data the HID Over GATT Profile Device Role Task 33 HOGPD_ENABLE_REQ = TASK_FIRST_MSG(TASK_ID_HOGPD), 34 /// Response of enabled request 35 HOGPD_ENABLE_RSP, 36 37 /// Request sending of a report to the host - notification 38 HOGPD_REPORT_UPD_REQ, 39 /// Response sending of a report to the host 40 HOGPD_REPORT_UPD_RSP, 41 42 43 /// Request from peer device to Read or update a report value 44 HOGPD_REPORT_REQ_IND, 45 /// Confirmation for peer device for Reading or Updating a report value 46 HOGPD_REPORT_CFM, 47 48 /// Inform Device APP that Protocol Mode Characteristic Value has been written on Device 49 HOGPD_PROTO_MODE_REQ_IND, 50 /// Confirm if the new protocol mode value 51 HOGPD_PROTO_MODE_CFM, 52 53 /// Inform Device APP that a Client Characteristic Configuration has been modified 54 HOGPD_NTF_CFG_IND, 55 /// Inform APP that HID Control Point Characteristic Value has been written on Device 56 HOGPD_CTNL_PT_IND, 57 }; 58 59 /// Report Char. Configuration Flag Values 60 enum hogpd_report_cfg 61 { 62 /// Input Report 63 HOGPD_CFG_REPORT_IN = 0x01, 64 /// Output Report 65 HOGPD_CFG_REPORT_OUT = 0x02, 66 //HOGPD_CFG_REPORT_FEAT can be used as a mask to check Report type 67 /// Feature Report 68 HOGPD_CFG_REPORT_FEAT = 0x03, 69 /// Input report with Write capabilities 70 HOGPD_CFG_REPORT_WR = 0x10, 71 }; 72 73 /// Features Flag Values 74 enum hogpd_cfg 75 { 76 /// Keyboard Device 77 HOGPD_CFG_KEYBOARD = 0x01, 78 /// Mouse Device 79 HOGPD_CFG_MOUSE = 0x02, 80 /// Protocol Mode present 81 HOGPD_CFG_PROTO_MODE = 0x04, 82 /// Extended Reference Present 83 HOGPD_CFG_MAP_EXT_REF = 0x08, 84 /// Boot Keyboard Report write capability 85 HOGPD_CFG_BOOT_KB_WR = 0x10, 86 /// Boot Mouse Report write capability 87 HOGPD_CFG_BOOT_MOUSE_WR = 0x20, 88 89 /// Valid Feature mask 90 HOGPD_CFG_MASK = 0x3F, 91 92 /// Report Notification Enabled (to be shift for each report index) 93 HOGPD_CFG_REPORT_NTF_EN = 0x40, 94 }; 95 96 /// Type of reports 97 enum hogpd_report_type 98 { 99 /// The Report characteristic is used to exchange data between a HID Device and a HID Host. 100 HOGPD_REPORT, 101 /// The Report Map characteristic 102 HOGPD_REPORT_MAP, 103 /// Boot Keyboard Input Report 104 HOGPD_BOOT_KEYBOARD_INPUT_REPORT, 105 /// Boot Keyboard Output Report 106 HOGPD_BOOT_KEYBOARD_OUTPUT_REPORT, 107 /// Boot Mouse Input Report 108 HOGPD_BOOT_MOUSE_INPUT_REPORT, 109 }; 110 111 /// type of operation requested by peer device 112 enum hogpd_op 113 { 114 /// No operation 115 HOGPD_OP_NO, 116 /// Read report value 117 HOGPD_OP_REPORT_READ, 118 /// Modify/Set report value 119 HOGPD_OP_REPORT_WRITE, 120 /// Modify Protocol mode 121 HOGPD_OP_PROT_UPDATE, 122 }; 123 124 /* 125 * APIs Structures 126 **************************************************************************************** 127 */ 128 /// External Report Reference 129 struct hogpd_ext_ref 130 { 131 /// External Report Reference - Included Service 132 uint16_t inc_svc_hdl; 133 /// External Report Reference - Characteristic UUID 134 uint16_t rep_ref_uuid; 135 }; 136 137 /// Database Creation Service Instance Configuration structure 138 struct hogpd_hids_cfg 139 { 140 /// Service Features (@see enum hogpd_cfg) 141 uint8_t svc_features; 142 /// Number of Report Char. instances to add in the database 143 uint8_t report_nb; 144 /// Report Char. Configuration (@see enum hogpd_report_cfg) 145 uint8_t report_char_cfg[HOGPD_NB_REPORT_INST_MAX]; 146 /// Report id number 147 uint8_t report_id[HOGPD_NB_REPORT_INST_MAX]; 148 /// HID Information Char. Values 149 struct hids_hid_info hid_info; 150 /// External Report Reference 151 struct hogpd_ext_ref ext_ref; 152 153 }; 154 155 /// Parameters of the @ref HOGPD_CREATE_DB_REQ message 156 struct hogpd_db_cfg 157 { 158 /// Number of HIDS to add 159 uint8_t hids_nb; 160 /// Initial configuration for each HIDS instance 161 struct hogpd_hids_cfg cfg[HOGPD_NB_HIDS_INST_MAX]; 162 }; 163 164 /// Parameters of the @ref HOGPD_ENABLE_REQ message 165 struct hogpd_enable_req 166 { 167 ///Connection index 168 uint8_t conidx; 169 /// Notification Configurations 170 uint16_t ntf_cfg[HOGPD_NB_HIDS_INST_MAX]; 171 }; 172 173 /// Parameters of the @ref HOGPD_ENABLE_RSP message 174 struct hogpd_enable_rsp 175 { 176 ///Connection index 177 uint8_t conidx; 178 /// status of the request 179 uint8_t status; 180 }; 181 182 ///Parameters of the @ref HOGPD_NTF_CFG_IND message 183 struct hogpd_ntf_cfg_ind 184 { 185 /// Connection Index 186 uint8_t conidx; 187 /// Service Instance Index 188 uint8_t svcidx; 189 /// Notification Configurations 190 uint16_t ntf_cfg[HOGPD_NB_HIDS_INST_MAX]; 191 }; 192 193 194 /// Inform Device APP that Protocol Mode Characteristic Value has been written on Device 195 struct hogpd_proto_mode_req_ind 196 { 197 /// Connection Index 198 uint8_t conidx; 199 /// Operation requested (update protocol mode @see hogpd_op) 200 uint8_t operation; 201 /// HIDS Instance 202 uint8_t hid_idx; 203 /// New Protocol Mode Characteristic Value 204 uint8_t proto_mode; 205 }; 206 207 /// Confirm if the new protocol mode value 208 struct hogpd_proto_mode_cfm 209 { 210 /// Connection Index 211 uint8_t conidx; 212 /// Status of the request 213 uint8_t status; 214 /// HIDS Instance 215 uint8_t hid_idx; 216 /// New Protocol Mode Characteristic Value 217 uint8_t proto_mode; 218 }; 219 220 /// HID Report Info 221 struct hogpd_report_info 222 { 223 /// HIDS Instance 224 uint8_t hid_idx; 225 /// type of report (@see enum hogpd_report_type) 226 uint8_t type; 227 /// Report Length (uint8_t) 228 uint16_t length; 229 /// Report Instance - 0 for boot reports and report map 230 uint8_t idx; 231 /// Report data 232 uint8_t value[__ARRAY_EMPTY]; 233 }; 234 235 236 /// Request sending of a report to the host - notification 237 struct hogpd_report_upd_req 238 { 239 /// Connection Index 240 uint8_t conidx; 241 /// Report Info 242 struct hogpd_report_info report; 243 }; 244 245 /// Response sending of a report to the host 246 struct hogpd_report_upd_rsp 247 { 248 /// Connection Index 249 uint8_t conidx; 250 /// Status of the request 251 uint8_t status; 252 }; 253 254 /// Request from peer device to Read or update a report value 255 struct hogpd_report_req_ind 256 { 257 /// Connection Index 258 uint8_t conidx; 259 /// Operation requested (read/write @see hogpd_op) 260 uint8_t operation; 261 /// Report Info 262 struct hogpd_report_info report; 263 }; 264 265 /// Confirmation for peer device for Reading or Updating a report value 266 struct hogpd_report_cfm 267 { 268 /// Connection Index 269 uint8_t conidx; 270 /// Operation requested (read/write @see enum hogpd_op) 271 uint8_t operation; 272 /// Status of the request 273 uint8_t status; 274 /// Report Info 275 struct hogpd_report_info report; 276 }; 277 278 279 ///Parameters of the @ref HOGPD_CTNL_PT_IND message 280 struct hogpd_ctnl_pt_ind 281 { 282 /// Connection Index 283 uint8_t conidx; 284 /// HIDS Instance 285 uint8_t hid_idx; 286 /// New HID Control Point Characteristic Value 287 uint8_t hid_ctnl_pt; 288 }; 289 290 #endif // _HID_OVER_GATT_TASK_H 291