• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright 2016 The Android Open Source Project
4  *  Copyright 2002-2012 Broadcom Corporation
5  *
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at:
9  *
10  *  http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License.
17  *
18  ******************************************************************************/
19 
20 /******************************************************************************
21  *
22  *  This file contains the HID Device API entry points
23  *
24  ******************************************************************************/
25 
26 #include "hidd_api.h"
27 
28 #include <frameworks/proto_logging/stats/enums/bluetooth/enums.pb.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 
33 #include "btm_api.h"
34 #include "hidd_int.h"
35 #include "hiddefs.h"
36 #include "osi/include/allocator.h"
37 #include "stack/btm/btm_sec.h"
38 #include "stack/include/bt_types.h"
39 #include "stack/include/stack_metrics_logging.h"
40 #include "types/bluetooth/uuid.h"
41 #include "types/raw_address.h"
42 
43 tHID_DEV_CTB hd_cb;
44 
45 /*******************************************************************************
46  *
47  * Function         HID_DevInit
48  *
49  * Description      Initializes control block
50  *
51  * Returns          void
52  *
53  ******************************************************************************/
HID_DevInit(void)54 void HID_DevInit(void) {
55   uint8_t log_level = hd_cb.trace_level;
56 
57   HIDD_TRACE_API("%s", __func__);
58 
59   memset(&hd_cb, 0, sizeof(tHID_DEV_CTB));
60   hd_cb.trace_level = log_level;
61 }
62 
63 /*******************************************************************************
64  *
65  * Function         HID_DevSetTraceLevel
66  *
67  * Description      This function sets the trace level for HID Dev. If called
68 *with
69  *                  a value of 0xFF, it simply reads the current trace level.
70  *
71  * Returns          the new (current) trace level
72  *
73  ******************************************************************************/
HID_DevSetTraceLevel(uint8_t new_level)74 uint8_t HID_DevSetTraceLevel(uint8_t new_level) {
75   if (new_level != 0xFF) hd_cb.trace_level = new_level;
76 
77   return (hd_cb.trace_level);
78 }
79 
80 /*******************************************************************************
81  *
82  * Function         HID_DevRegister
83  *
84  * Description      Registers HID device with lower layers
85  *
86  * Returns          tHID_STATUS
87  *
88  ******************************************************************************/
HID_DevRegister(tHID_DEV_HOST_CALLBACK * host_cback)89 tHID_STATUS HID_DevRegister(tHID_DEV_HOST_CALLBACK* host_cback) {
90   tHID_STATUS st;
91 
92   HIDD_TRACE_API("%s", __func__);
93 
94   if (hd_cb.reg_flag) {
95     log_counter_metrics(
96         android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_ALREADY_REGISTERED,
97         1);
98     return HID_ERR_ALREADY_REGISTERED;
99   }
100 
101   if (host_cback == NULL) {
102     log_counter_metrics(
103         android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_HOST_CALLBACK_NULL,
104         1);
105     return HID_ERR_INVALID_PARAM;
106   }
107 
108   /* Register with L2CAP */
109   st = hidd_conn_reg();
110   if (st != HID_SUCCESS) return st;
111 
112   hd_cb.callback = host_cback;
113   hd_cb.reg_flag = TRUE;
114 
115   if (hd_cb.pending_data) {
116     osi_free(hd_cb.pending_data);
117     hd_cb.pending_data = NULL;
118   }
119 
120   return (HID_SUCCESS);
121 }
122 
123 /*******************************************************************************
124  *
125  * Function         HID_DevDeregister
126  *
127  * Description      Deregisters HID device with lower layers
128  *
129  * Returns          tHID_STATUS
130  *
131  ******************************************************************************/
HID_DevDeregister(void)132 tHID_STATUS HID_DevDeregister(void) {
133   HIDD_TRACE_API("%s", __func__);
134 
135   if (!hd_cb.reg_flag) {
136     log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum::
137                             HIDD_ERR_NOT_REGISTERED_AT_DEREGISTER,
138                         1);
139     return (HID_ERR_NOT_REGISTERED);
140   }
141 
142   hidd_conn_dereg();
143 
144   hd_cb.reg_flag = FALSE;
145 
146   return (HID_SUCCESS);
147 }
148 
149 /*******************************************************************************
150  *
151  * Function         HID_DevAddRecord
152  *
153  * Description      Creates SDP record for HID device
154  *
155  * Returns          tHID_STATUS
156  *
157  ******************************************************************************/
HID_DevAddRecord(uint32_t handle,char * p_name,char * p_description,char * p_provider,uint16_t subclass,uint16_t desc_len,uint8_t * p_desc_data)158 tHID_STATUS HID_DevAddRecord(uint32_t handle, char* p_name, char* p_description,
159                              char* p_provider, uint16_t subclass,
160                              uint16_t desc_len, uint8_t* p_desc_data) {
161   bool result = TRUE;
162 
163   HIDD_TRACE_API("%s", __func__);
164 
165   // Service Class ID List
166   if (result) {
167     uint16_t uuid = UUID_SERVCLASS_HUMAN_INTERFACE;
168     result &= SDP_AddServiceClassIdList(handle, 1, &uuid);
169   }
170 
171   // Protocol Descriptor List
172   if (result) {
173     tSDP_PROTOCOL_ELEM proto_list[2];
174 
175     proto_list[0].protocol_uuid = UUID_PROTOCOL_L2CAP;
176     proto_list[0].num_params = 1;
177     proto_list[0].params[0] = BT_PSM_HIDC;
178 
179     proto_list[1].protocol_uuid = UUID_PROTOCOL_HIDP;
180     proto_list[1].num_params = 0;
181 
182     result &= SDP_AddProtocolList(handle, 2, proto_list);
183   }
184 
185   // Language Base Attribute ID List
186   if (result) {
187     result &= SDP_AddLanguageBaseAttrIDList(handle, LANG_ID_CODE_ENGLISH,
188                                             LANG_ID_CHAR_ENCODE_UTF8,
189                                             LANGUAGE_BASE_ID);
190   }
191 
192   // Additional Protocol Descriptor List
193   if (result) {
194     tSDP_PROTO_LIST_ELEM add_proto_list;
195 
196     add_proto_list.num_elems = 2;
197     add_proto_list.list_elem[0].protocol_uuid = UUID_PROTOCOL_L2CAP;
198     add_proto_list.list_elem[0].num_params = 1;
199     add_proto_list.list_elem[0].params[0] = BT_PSM_HIDI;
200     add_proto_list.list_elem[1].protocol_uuid = UUID_PROTOCOL_HIDP;
201     add_proto_list.list_elem[1].num_params = 0;
202 
203     result &= SDP_AddAdditionProtoLists(handle, 1, &add_proto_list);
204   }
205 
206   // Service Name (O)
207   // Service Description (O)
208   // Provider Name (O)
209   if (result) {
210     const char* srv_name = p_name;
211     const char* srv_desc = p_description;
212     const char* provider_name = p_provider;
213 
214     result &= SDP_AddAttribute(handle, ATTR_ID_SERVICE_NAME, TEXT_STR_DESC_TYPE,
215                                strlen(srv_name) + 1, (uint8_t*)srv_name);
216 
217     result &= SDP_AddAttribute(handle, ATTR_ID_SERVICE_DESCRIPTION,
218                                TEXT_STR_DESC_TYPE, strlen(srv_desc) + 1,
219                                (uint8_t*)srv_desc);
220 
221     result &=
222         SDP_AddAttribute(handle, ATTR_ID_PROVIDER_NAME, TEXT_STR_DESC_TYPE,
223                          strlen(provider_name) + 1, (uint8_t*)provider_name);
224   }
225 
226   // Bluetooth Profile Descriptor List
227   if (result) {
228     const uint16_t profile_uuid = UUID_SERVCLASS_HUMAN_INTERFACE;
229     const uint16_t version = 0x0100;
230 
231     result &= SDP_AddProfileDescriptorList(handle, profile_uuid, version);
232   }
233 
234   // HID Parser Version
235   if (result) {
236     uint8_t* p;
237     const uint16_t rel_num = 0x0100;
238     const uint16_t parser_version = 0x0111;
239     const uint16_t prof_ver = 0x0100;
240     const uint8_t dev_subclass = subclass;
241     const uint8_t country_code = 0x21;
242     const uint8_t bool_false = 0x00;
243     const uint8_t bool_true = 0x01;
244     uint16_t temp;
245 
246     p = (uint8_t*)&temp;
247     UINT16_TO_BE_STREAM(p, rel_num);
248     result &= SDP_AddAttribute(handle, ATTR_ID_HID_DEVICE_RELNUM,
249                                UINT_DESC_TYPE, 2, (uint8_t*)&temp);
250 
251     p = (uint8_t*)&temp;
252     UINT16_TO_BE_STREAM(p, parser_version);
253     result &= SDP_AddAttribute(handle, ATTR_ID_HID_PARSER_VERSION,
254                                UINT_DESC_TYPE, 2, (uint8_t*)&temp);
255 
256     result &= SDP_AddAttribute(handle, ATTR_ID_HID_DEVICE_SUBCLASS,
257                                UINT_DESC_TYPE, 1, (uint8_t*)&dev_subclass);
258 
259     result &= SDP_AddAttribute(handle, ATTR_ID_HID_COUNTRY_CODE, UINT_DESC_TYPE,
260                                1, (uint8_t*)&country_code);
261 
262     result &= SDP_AddAttribute(handle, ATTR_ID_HID_VIRTUAL_CABLE,
263                                BOOLEAN_DESC_TYPE, 1, (uint8_t*)&bool_true);
264 
265     result &= SDP_AddAttribute(handle, ATTR_ID_HID_RECONNECT_INITIATE,
266                                BOOLEAN_DESC_TYPE, 1, (uint8_t*)&bool_true);
267 
268     {
269       static uint8_t cdt = 0x22;
270       uint8_t* p_buf;
271       uint8_t seq_len = 4 + desc_len;
272 
273       if (desc_len > HIDD_APP_DESCRIPTOR_LEN) {
274         HIDD_TRACE_ERROR("%s: descriptor length = %d, larger than max %d",
275                          __func__, desc_len, HIDD_APP_DESCRIPTOR_LEN);
276         log_counter_metrics(
277             android::bluetooth::CodePathCounterKeyEnum::
278                 HIDD_ERR_NOT_REGISTERED_DUE_TO_DESCRIPTOR_LENGTH,
279             1);
280         return HID_ERR_NOT_REGISTERED;
281       };
282 
283       p_buf = (uint8_t*)osi_malloc(HIDD_APP_DESCRIPTOR_LEN + 6);
284 
285       if (p_buf == NULL) {
286         HIDD_TRACE_ERROR("%s: Buffer allocation failure for size = 2048 ",
287                          __func__);
288         log_counter_metrics(
289             android::bluetooth::CodePathCounterKeyEnum::
290                 HIDD_ERR_NOT_REGISTERED_DUE_TO_BUFFER_ALLOCATION,
291             1);
292         return HID_ERR_NOT_REGISTERED;
293       }
294 
295       p = p_buf;
296 
297       UINT8_TO_BE_STREAM(p, (DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_BYTE);
298 
299       UINT8_TO_BE_STREAM(p, seq_len);
300 
301       UINT8_TO_BE_STREAM(p, (UINT_DESC_TYPE << 3) | SIZE_ONE_BYTE);
302       UINT8_TO_BE_STREAM(p, cdt);
303 
304       UINT8_TO_BE_STREAM(p, (TEXT_STR_DESC_TYPE << 3) | SIZE_IN_NEXT_BYTE);
305       UINT8_TO_BE_STREAM(p, desc_len);
306       ARRAY_TO_BE_STREAM(p, p_desc_data, (int)desc_len);
307 
308       result &= SDP_AddAttribute(handle, ATTR_ID_HID_DESCRIPTOR_LIST,
309                                  DATA_ELE_SEQ_DESC_TYPE, p - p_buf, p_buf);
310 
311       osi_free(p_buf);
312     }
313 
314     {
315       uint8_t lang_buf[8];
316       p = lang_buf;
317       uint8_t seq_len = 6;
318       uint16_t lang_english = 0x0409;
319       UINT8_TO_BE_STREAM(p, (DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_BYTE);
320       UINT8_TO_BE_STREAM(p, seq_len);
321       UINT8_TO_BE_STREAM(p, (UINT_DESC_TYPE << 3) | SIZE_TWO_BYTES);
322       UINT16_TO_BE_STREAM(p, lang_english);
323       UINT8_TO_BE_STREAM(p, (UINT_DESC_TYPE << 3) | SIZE_TWO_BYTES);
324       UINT16_TO_BE_STREAM(p, LANGUAGE_BASE_ID);
325       result &=
326           SDP_AddAttribute(handle, ATTR_ID_HID_LANGUAGE_ID_BASE,
327                            DATA_ELE_SEQ_DESC_TYPE, p - lang_buf, lang_buf);
328     }
329 
330     result &= SDP_AddAttribute(handle, ATTR_ID_HID_BATTERY_POWER,
331                                BOOLEAN_DESC_TYPE, 1, (uint8_t*)&bool_true);
332 
333     result &= SDP_AddAttribute(handle, ATTR_ID_HID_REMOTE_WAKE,
334                                BOOLEAN_DESC_TYPE, 1, (uint8_t*)&bool_false);
335 
336     result &= SDP_AddAttribute(handle, ATTR_ID_HID_NORMALLY_CONNECTABLE,
337                                BOOLEAN_DESC_TYPE, 1, (uint8_t*)&bool_true);
338 
339     result &= SDP_AddAttribute(handle, ATTR_ID_HID_BOOT_DEVICE,
340                                BOOLEAN_DESC_TYPE, 1, (uint8_t*)&bool_true);
341 
342     p = (uint8_t*)&temp;
343     UINT16_TO_BE_STREAM(p, prof_ver);
344     result &= SDP_AddAttribute(handle, ATTR_ID_HID_PROFILE_VERSION,
345                                UINT_DESC_TYPE, 2, (uint8_t*)&temp);
346   }
347 
348   if (result) {
349     uint16_t browse_group = UUID_SERVCLASS_PUBLIC_BROWSE_GROUP;
350     result &= SDP_AddUuidSequence(handle, ATTR_ID_BROWSE_GROUP_LIST, 1,
351                                   &browse_group);
352   }
353 
354   if (!result) {
355     HIDD_TRACE_ERROR("%s: failed to complete SDP record", __func__);
356     log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum::
357                             HIDD_ERR_NOT_REGISTERED_AT_SDP,
358                         1);
359     return HID_ERR_NOT_REGISTERED;
360   }
361 
362   return HID_SUCCESS;
363 }
364 
365 /*******************************************************************************
366  *
367  * Function         HID_DevSendReport
368  *
369  * Description      Sends report
370  *
371  * Returns          tHID_STATUS
372  *
373  ******************************************************************************/
HID_DevSendReport(uint8_t channel,uint8_t type,uint8_t id,uint16_t len,uint8_t * p_data)374 tHID_STATUS HID_DevSendReport(uint8_t channel, uint8_t type, uint8_t id,
375                               uint16_t len, uint8_t* p_data) {
376   HIDD_TRACE_VERBOSE("%s: channel=%d type=%d id=%d len=%d", __func__, channel,
377                      type, id, len);
378 
379   if (channel == HID_CHANNEL_CTRL) {
380     return hidd_conn_send_data(HID_CHANNEL_CTRL, HID_TRANS_DATA, type, id, len,
381                                p_data);
382   }
383 
384   if (channel == HID_CHANNEL_INTR && type == HID_PAR_REP_TYPE_INPUT) {
385     // on INTR we can only send INPUT
386     return hidd_conn_send_data(HID_CHANNEL_INTR, HID_TRANS_DATA,
387                                HID_PAR_REP_TYPE_INPUT, id, len, p_data);
388   }
389   log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum::
390                           HIDD_ERR_INVALID_PARAM_SEND_REPORT,
391                       1);
392   return HID_ERR_INVALID_PARAM;
393 }
394 
395 /*******************************************************************************
396  *
397  * Function         HID_DevVirtualCableUnplug
398  *
399  * Description      Sends Virtual Cable Unplug
400  *
401  * Returns          tHID_STATUS
402  *
403  ******************************************************************************/
HID_DevVirtualCableUnplug(void)404 tHID_STATUS HID_DevVirtualCableUnplug(void) {
405   HIDD_TRACE_API("%s", __func__);
406 
407   return hidd_conn_send_data(HID_CHANNEL_CTRL, HID_TRANS_CONTROL,
408                              HID_PAR_CONTROL_VIRTUAL_CABLE_UNPLUG, 0, 0, NULL);
409 }
410 
411 /*******************************************************************************
412  *
413  * Function         HID_DevPlugDevice
414  *
415  * Description      Establishes virtual cable to given host
416  *
417  * Returns          tHID_STATUS
418  *
419  ******************************************************************************/
HID_DevPlugDevice(const RawAddress & addr)420 tHID_STATUS HID_DevPlugDevice(const RawAddress& addr) {
421   hd_cb.device.in_use = TRUE;
422   hd_cb.device.addr = addr;
423 
424   return HID_SUCCESS;
425 }
426 
427 /*******************************************************************************
428  *
429  * Function         HID_DevUnplugDevice
430  *
431  * Description      Unplugs virtual cable from given host
432  *
433  * Returns          tHID_STATUS
434  *
435  ******************************************************************************/
HID_DevUnplugDevice(const RawAddress & addr)436 tHID_STATUS HID_DevUnplugDevice(const RawAddress& addr) {
437   if (hd_cb.device.addr == addr) {
438     hd_cb.device.in_use = FALSE;
439     hd_cb.device.conn.conn_state = HID_CONN_STATE_UNUSED;
440     hd_cb.device.conn.ctrl_cid = 0;
441     hd_cb.device.conn.intr_cid = 0;
442   }
443 
444   return HID_SUCCESS;
445 }
446 
447 /*******************************************************************************
448  *
449  * Function         HID_DevConnect
450  *
451  * Description      Connects to device
452  *
453  * Returns          tHID_STATUS
454  *
455  ******************************************************************************/
HID_DevConnect(void)456 tHID_STATUS HID_DevConnect(void) {
457   if (!hd_cb.reg_flag) {
458     log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum::
459                             HIDD_ERR_NOT_REGISTERED_AT_CONNECT,
460                         1);
461     return HID_ERR_NOT_REGISTERED;
462   }
463 
464   if (!hd_cb.device.in_use) {
465     log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum::
466                             HIDD_ERR_DEVICE_NOT_IN_USE_AT_CONNECT,
467                         1);
468     return HID_ERR_INVALID_PARAM;
469   }
470 
471   if (hd_cb.device.state != HIDD_DEV_NO_CONN) {
472     log_counter_metrics(
473         android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_ALREADY_CONN, 1);
474     return HID_ERR_ALREADY_CONN;
475   }
476 
477   return hidd_conn_initiate();
478 }
479 
480 /*******************************************************************************
481  *
482  * Function         HID_DevDisconnect
483  *
484  * Description      Disconnects from device
485  *
486  * Returns          tHID_STATUS
487  *
488  ******************************************************************************/
HID_DevDisconnect(void)489 tHID_STATUS HID_DevDisconnect(void) {
490   if (!hd_cb.reg_flag) {
491     log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum::
492                             HIDD_ERR_NOT_REGISTERED_AT_DISCONNECT,
493                         1);
494     return HID_ERR_NOT_REGISTERED;
495   }
496 
497   if (!hd_cb.device.in_use) {
498     log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum::
499                             HIDD_ERR_DEVICE_NOT_IN_USE_AT_DISCONNECT,
500                         1);
501     return HID_ERR_INVALID_PARAM;
502   }
503 
504   if (hd_cb.device.state == HIDD_DEV_NO_CONN) {
505     /* If we are still trying to connect, just close the connection. */
506     if (hd_cb.device.conn.conn_state != HID_CONN_STATE_UNUSED) {
507       tHID_STATUS ret = hidd_conn_disconnect();
508       hd_cb.device.conn.conn_state = HID_CONN_STATE_UNUSED;
509       hd_cb.callback(hd_cb.device.addr, HID_DHOST_EVT_CLOSE,
510                      HID_ERR_DISCONNECTING, NULL);
511       log_counter_metrics(
512           android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_DISCONNECTING,
513           1);
514       return ret;
515     }
516     log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum::
517                             HIDD_ERR_NO_CONNECTION_AT_DISCONNECT,
518                         1);
519     return HID_ERR_NO_CONNECTION;
520   }
521 
522   return hidd_conn_disconnect();
523 }
524 
525 /*******************************************************************************
526  *
527  * Function         HID_DevSetIncomingPolicy
528  *
529  * Description      Sets policy for incoming connections (allowed/disallowed)
530  *
531  * Returns          tHID_STATUS
532  *
533  ******************************************************************************/
HID_DevSetIncomingPolicy(bool allow)534 tHID_STATUS HID_DevSetIncomingPolicy(bool allow) {
535   hd_cb.allow_incoming = allow;
536 
537   return HID_SUCCESS;
538 }
539 
540 /*******************************************************************************
541  *
542  * Function         HID_DevReportError
543  *
544  * Description      Reports error for Set Report via HANDSHAKE
545  *
546  * Returns          tHID_STATUS
547  *
548  ******************************************************************************/
HID_DevReportError(uint8_t error)549 tHID_STATUS HID_DevReportError(uint8_t error) {
550   uint8_t handshake_param;
551 
552   HIDD_TRACE_API("%s: error = %d", __func__, error);
553 
554   switch (error) {
555     case HID_PAR_HANDSHAKE_RSP_SUCCESS:
556     case HID_PAR_HANDSHAKE_RSP_NOT_READY:
557     case HID_PAR_HANDSHAKE_RSP_ERR_INVALID_REP_ID:
558     case HID_PAR_HANDSHAKE_RSP_ERR_UNSUPPORTED_REQ:
559     case HID_PAR_HANDSHAKE_RSP_ERR_INVALID_PARAM:
560     case HID_PAR_HANDSHAKE_RSP_ERR_UNKNOWN:
561     case HID_PAR_HANDSHAKE_RSP_ERR_FATAL:
562       handshake_param = error;
563       break;
564     default:
565       handshake_param = HID_PAR_HANDSHAKE_RSP_ERR_UNKNOWN;
566       break;
567   }
568 
569   return hidd_conn_send_data(0, HID_TRANS_HANDSHAKE, handshake_param, 0, 0,
570                              NULL);
571 }
572 
573 /*******************************************************************************
574  *
575  * Function         HID_DevGetDevice
576  *
577  * Description      Returns the BD Address of virtually cabled device
578  *
579  * Returns          tHID_STATUS
580  *
581  ******************************************************************************/
HID_DevGetDevice(RawAddress * addr)582 tHID_STATUS HID_DevGetDevice(RawAddress* addr) {
583   HIDD_TRACE_API("%s", __func__);
584 
585   if (hd_cb.device.in_use) {
586     *addr = hd_cb.device.addr;
587   } else {
588     log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum::
589                             HIDD_ERR_NOT_REGISTERED_AT_GET_DEVICE,
590                         1);
591     return HID_ERR_NOT_REGISTERED;
592   }
593 
594   return HID_SUCCESS;
595 }
596 
597 /*******************************************************************************
598  *
599  * Function         HID_DevSetIncomingQos
600  *
601  * Description      Sets Incoming QoS values for Interrupt L2CAP Channel
602  *
603  * Returns          tHID_STATUS
604  *
605  ******************************************************************************/
HID_DevSetIncomingQos(uint8_t service_type,uint32_t token_rate,uint32_t token_bucket_size,uint32_t peak_bandwidth,uint32_t latency,uint32_t delay_variation)606 tHID_STATUS HID_DevSetIncomingQos(uint8_t service_type, uint32_t token_rate,
607                                   uint32_t token_bucket_size,
608                                   uint32_t peak_bandwidth, uint32_t latency,
609                                   uint32_t delay_variation) {
610   HIDD_TRACE_API("%s", __func__);
611 
612   hd_cb.use_in_qos = TRUE;
613 
614   hd_cb.in_qos.service_type = service_type;
615   hd_cb.in_qos.token_rate = token_rate;
616   hd_cb.in_qos.token_bucket_size = token_bucket_size;
617   hd_cb.in_qos.peak_bandwidth = peak_bandwidth;
618   hd_cb.in_qos.latency = latency;
619   hd_cb.in_qos.delay_variation = delay_variation;
620 
621   return HID_SUCCESS;
622 }
623 
624 /*******************************************************************************
625  *
626  * Function         HID_DevSetOutgoingQos
627  *
628  * Description      Sets Outgoing QoS values for Interrupt L2CAP Channel
629  *
630  * Returns          tHID_STATUS
631  *
632  ******************************************************************************/
HID_DevSetOutgoingQos(uint8_t service_type,uint32_t token_rate,uint32_t token_bucket_size,uint32_t peak_bandwidth,uint32_t latency,uint32_t delay_variation)633 tHID_STATUS HID_DevSetOutgoingQos(uint8_t service_type, uint32_t token_rate,
634                                   uint32_t token_bucket_size,
635                                   uint32_t peak_bandwidth, uint32_t latency,
636                                   uint32_t delay_variation) {
637   HIDD_TRACE_API("%s", __func__);
638 
639   hd_cb.l2cap_intr_cfg.qos_present = TRUE;
640 
641   hd_cb.l2cap_intr_cfg.qos.service_type = service_type;
642   hd_cb.l2cap_intr_cfg.qos.token_rate = token_rate;
643   hd_cb.l2cap_intr_cfg.qos.token_bucket_size = token_bucket_size;
644   hd_cb.l2cap_intr_cfg.qos.peak_bandwidth = peak_bandwidth;
645   hd_cb.l2cap_intr_cfg.qos.latency = latency;
646   hd_cb.l2cap_intr_cfg.qos.delay_variation = delay_variation;
647 
648   return HID_SUCCESS;
649 }
650