• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef _HID_OVER_GATT_DEVICE_H
16 #define _HID_OVER_GATT_DEVICE_H
17 
18 #include "ble_ip_config.h"
19 
20 #if (BLE_HID_DEVICE)
21 #include "hid_over_gatt_task.h"
22 
23 #include "hal_profile.h"
24 #include "hal_prf_types.h"
25 
26 ///Maximum number of HID Over GATT Device task instances
27 #define HOGPD_IDX_MAX                   (0x01)
28 
29 /// Maximal length of Report Char. Value
30 #define HOGPD_REPORT_MAX_LEN                (45)
31 /// Maximal length of Report Map Char. Value
32 #define HOGPD_REPORT_MAP_MAX_LEN            (512)
33 
34 /// Length of Boot Report Char. Value Maximal Length
35 #define HOGPD_BOOT_REPORT_MAX_LEN           (8)
36 
37 /// Boot KB Input Report Notification Configuration Bit Mask
38 #define HOGPD_BOOT_KB_IN_NTF_CFG_MASK       (0x40)
39 /// Boot KB Input Report Notification Configuration Bit Mask
40 #define HOGPD_BOOT_MOUSE_IN_NTF_CFG_MASK    (0x80)
41 /// Boot Report Notification Configuration Bit Mask
42 #define HOGPD_REPORT_NTF_CFG_MASK           (0x20)
43 
44 /*
45  * ENUMERATIONS
46  ****************************************************************************************
47  */
48 
49 /// Possible states of the HOGPD task
50 enum hogpd_state
51 {
52     /// Idle state
53     HOGPD_IDLE,
54     /// Request from application on-going
55     HOGPD_REQ_BUSY  = (1 << 0),
56     /// OPeration requested by peer device on-going
57     HOGPD_OP_BUSY   = (1 << 1),
58     /// Number of defined states.
59     HOGPD_STATE_MAX
60 };
61 
62 /// HID Service Attributes Indexes
63 enum
64 {
65     HOGPD_IDX_SVC,
66 
67     // Included Service
68     HOGPD_IDX_INCL_SVC,
69 
70     // HID Information
71     HOGPD_IDX_HID_INFO_CHAR,
72     HOGPD_IDX_HID_INFO_VAL,
73 
74     // HID Control Point
75     HOGPD_IDX_HID_CTNL_PT_CHAR,
76     HOGPD_IDX_HID_CTNL_PT_VAL,
77 
78     // Report Map
79     HOGPD_IDX_REPORT_MAP_CHAR,
80     HOGPD_IDX_REPORT_MAP_VAL,
81     HOGPD_IDX_REPORT_MAP_EXT_REP_REF,
82 
83     // Protocol Mode
84     HOGPD_IDX_PROTO_MODE_CHAR,
85     HOGPD_IDX_PROTO_MODE_VAL,
86 
87     // Boot Keyboard Input Report
88     HOGPD_IDX_BOOT_KB_IN_REPORT_CHAR,
89     HOGPD_IDX_BOOT_KB_IN_REPORT_VAL,
90     HOGPD_IDX_BOOT_KB_IN_REPORT_NTF_CFG,
91 
92     // Boot Keyboard Output Report
93     HOGPD_IDX_BOOT_KB_OUT_REPORT_CHAR,
94     HOGPD_IDX_BOOT_KB_OUT_REPORT_VAL,
95 
96     // Boot Mouse Input Report
97     HOGPD_IDX_BOOT_MOUSE_IN_REPORT_CHAR,
98     HOGPD_IDX_BOOT_MOUSE_IN_REPORT_VAL,
99     HOGPD_IDX_BOOT_MOUSE_IN_REPORT_NTF_CFG,
100 
101     /// number of attributes that are uniq in the service
102     HOGPD_ATT_UNIQ_NB,
103 
104     // Report
105     HOGPD_IDX_REPORT_CHAR = HOGPD_ATT_UNIQ_NB,
106     HOGPD_IDX_REPORT_VAL,
107     HOGPD_IDX_REPORT_REP_REF,
108     HOGPD_IDX_REPORT_NTF_CFG,
109 
110     HOGPD_IDX_NB,
111 
112     // maximum number of attribute that can be present in the HID service
113     HOGPD_ATT_MAX = HOGPD_ATT_UNIQ_NB + (4* (HOGPD_NB_REPORT_INST_MAX)),
114 };
115 
116 
117 
118 /*
119  * TYPE DEFINITIONS
120  ****************************************************************************************
121  */
122 
123 /// HIDS service cfg
124 struct hogpd_svc_cfg
125 {
126     /// Service Features (@see enum hogpd_cfg)
127     uint16_t features;
128     /// Notification configuration
129     uint16_t ntf_cfg[BLE_CONNECTION_MAX];
130     /// Number of attribute present in service
131     uint8_t  nb_att;
132     /// Number of Report Char. instances to add in the database
133     uint8_t  nb_report;
134     /// Handle offset where report are available - to enhance handle search
135     uint8_t  report_hdl_offset;
136     /// Current Protocol Mode
137     uint8_t  proto_mode;
138 };
139 
140 /// HIDS on-going operation
141 struct hogpd_operation
142 {
143     /// Connection index impacted
144     uint8_t  conidx;
145     /// Operation type (@see enum hogpd_op)
146     uint8_t  operation;
147     /// Handle impacted by operation
148     uint16_t handle;
149 };
150 
151 /// HID Over GATT Profile HID Device Role Environment variable
152 struct hogpd_env_tag
153 {
154     /// profile environment
155     prf_env_t prf_env;
156     /// Supported Features
157     struct hogpd_svc_cfg svcs[HOGPD_NB_HIDS_INST_MAX];
158     /// HIDS Start Handles
159     uint16_t start_hdl;
160     /// On-going operation (requested by peer device)
161     struct hogpd_operation op;
162     /// HID Over GATT task state
163     ke_state_t state[HOGPD_IDX_MAX];
164     /// Number of HIDS added in the database
165     uint8_t hids_nb;
166 };
167 
168 /*
169  * GLOBAL VARIABLE DECLARATIONS
170  ****************************************************************************************
171  */
172 
173 
174 /*
175  * FUNCTION DECLARATIONS
176  ****************************************************************************************
177  */
178 
179 /**
180  ****************************************************************************************
181  * @brief Retrieve HID service profile interface
182  *
183  * @return HID service profile interface
184  ****************************************************************************************
185  */
186 const struct prf_task_cbs* hogpd_prf_itf_get(void);
187 
188 /**
189  ****************************************************************************************
190  * @brief Retrieve Attribute handle from service and attribute index
191  *
192  * @param[in] hogpd_env  HID Service environment
193  * @param[in] svc_idx    HID Service index
194  * @param[in] att_idx    Attribute index
195  * @param[in] report_idx Report index
196  *
197  * @return HID attribute handle or INVALID HANDLE if nothing found
198  ****************************************************************************************
199  */
200 uint16_t hogpd_get_att_handle(struct hogpd_env_tag* hogpd_env, uint8_t svc_idx, uint8_t att_idx, uint8_t report_idx);
201 
202 
203 /**
204  ****************************************************************************************
205  * @brief Retrieve Service and attribute index form attribute handle
206  *
207  * @param[out] handle     Attribute handle
208  * @param[out] svc_idx    HID Service index
209  * @param[out] att_idx    Attribute index
210  * @param[out] report_idx Report Index
211  *
212  * @return Success if attribute and service index found, else Application error
213  ****************************************************************************************
214  */
215 uint8_t hogpd_get_att_idx(struct hogpd_env_tag* hogpd_env, uint16_t handle, uint8_t *svc_idx, uint8_t *att_idx, uint8_t *report_idx);
216 
217 
218 /**
219  ****************************************************************************************
220  * @brief Check if a report value can be notified to the peer central.
221  *
222  * @param[in] conidx Connection Index
223  * @param[in] report Report information to notify
224  *
225  * @return Status Code to know if request succeed or not.
226  ****************************************************************************************
227  */
228 uint8_t hogpd_ntf_send(uint8_t conidx, const struct hogpd_report_info* report);
229 
230 /**
231  ****************************************************************************************
232  * @brief Send a HOGPD_NTF_CFG_IND message to the application
233  *
234  * @param[in] conidx Connection Index
235  * @param[in] svc_idx    HID Service index
236  * @param[in] att_idx    Attribute index
237  * @param[in] report_idx Report Index
238  * @param[in] ntf_cfg       Client Characteristic Configuration Descriptor value
239  *
240  * @return Status Code to know if notification update succeed or not
241  ****************************************************************************************
242  */
243 uint8_t hogpd_ntf_cfg_ind_send(uint8_t conidx, uint8_t svc_idx, uint8_t att_idx, uint8_t report_idx, uint16_t ntf_cfg);
244 
245 
246 /*
247  * TASK DESCRIPTOR DECLARATIONS
248  ****************************************************************************************
249  */
250 
251 /**
252  ****************************************************************************************
253  * Initialize task handler
254  *
255  * @param task_desc Task descriptor to fill
256  ****************************************************************************************
257  */
258 void hogpd_task_init(struct ke_task_desc *task_desc);
259 
260 #endif /* #if (BLE_HID_DEVICE) */
261 
262 #endif // _HID_OVER_GATT_DEVICE_H
263