btif_hid.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright (c) 2016 Actions Semi Co., Inc.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file
  8. * @brief bt hid interface
  9. */
  10. #define SYS_LOG_DOMAIN "btif_hid"
  11. #include "btsrv_os_common.h"
  12. #include "btsrv_inner.h"
  13. int btif_hid_register_processer(void)
  14. {
  15. return btsrv_register_msg_processer(MSG_BTSRV_HID, &btsrv_hid_process);
  16. }
  17. int btif_hid_register_sdp(struct bt_sdp_attribute *hid_attrs, uint8_t attrs_size)
  18. {
  19. return btsrv_event_notify_ext(MSG_BTSRV_HID, MSG_BTSRV_HID_REGISTER, hid_attrs, attrs_size);
  20. }
  21. int btif_did_register_sdp(uint8_t *data, uint32_t len)
  22. {
  23. return btsrv_function_call_malloc(MSG_BTSRV_HID, MSG_BTSRV_DID_REGISTER, data,len,0);
  24. }
  25. static int btif_hid_send_data(uint8_t cmd, uint16_t hdl, uint8_t report_type, uint8_t *data, uint32_t len)
  26. {
  27. struct bt_hid_report report;
  28. if (len > BT_HID_REPORT_DATA_LEN) {
  29. SYS_LOG_ERR("Need extern len %d", len);
  30. return -ENOMEM;
  31. }
  32. report.hdl = hdl;
  33. report.report_type = report_type;
  34. report.has_size = 0;
  35. memcpy(report.data, data, len);
  36. report.len = len;
  37. return btsrv_function_call_malloc(MSG_BTSRV_HID, cmd, (uint8_t *)&report, sizeof(report), 0);
  38. }
  39. int btif_hid_send_ctrl_data(uint16_t hdl, uint8_t report_type, uint8_t *data, uint32_t len)
  40. {
  41. return btif_hid_send_data(MSG_BTSRV_HID_SEND_CTRL_DATA, hdl, report_type, data, len);
  42. }
  43. int btif_hid_send_intr_data(uint16_t hdl, uint8_t report_type,uint8_t *data, uint32_t len)
  44. {
  45. return btif_hid_send_data(MSG_BTSRV_HID_SEND_INTR_DATA, hdl, report_type, data, len);
  46. }
  47. int btif_hid_send_rsp(uint16_t hdl, uint8_t status)
  48. {
  49. return btsrv_event_notify_ext(MSG_BTSRV_HID, MSG_BTSRV_HID_SEND_RSP, (void *)(uint32_t)hdl, status);
  50. }
  51. int btif_hid_connect(uint16_t hdl)
  52. {
  53. return btsrv_function_call(MSG_BTSRV_HID, MSG_BTSRV_HID_CONNECT, (void *)(uint32_t)hdl);
  54. }
  55. int btif_hid_disconnect(uint16_t hdl)
  56. {
  57. return btsrv_function_call(MSG_BTSRV_HID, MSG_BTSRV_HID_DISCONNECT, (void *)(uint32_t)hdl);
  58. }
  59. int btif_hid_start(btsrv_hid_callback cb)
  60. {
  61. return btsrv_function_call(MSG_BTSRV_HID, MSG_BTSRV_HID_START, cb);
  62. }
  63. int btif_hid_stop(void)
  64. {
  65. return btsrv_function_call(MSG_BTSRV_HID, MSG_BTSRV_HID_STOP, NULL);
  66. }