btsrv_pnp.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright (c) 2017 Actions Semi Co., Ltd.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file
  8. * @brief btsrvice
  9. */
  10. #define SYS_LOG_DOMAIN "btsrv_pnp"
  11. #include "btsrv_os_common.h"
  12. #include "btsrv_inner.h"
  13. #include <acts_bluetooth/sdp.h>
  14. struct btsrv_pnp_info_context_info {
  15. btsrv_pnp_info_callback pnp_user_callback;
  16. };
  17. static struct btsrv_pnp_info_context_info pnp_info_context;
  18. static int _btsrv_pnp_info_get_cb(struct bt_conn *conn, uint16_t type, void *param)
  19. {
  20. SYS_LOG_INF("type 0x%x.\n",type);
  21. btsrv_pnp_info_event_e event = BTSRV_PNP_VENDOR_ID;
  22. int param_size = 0;
  23. if (BT_SDP_ATTR_VENDOR_ID == type) {
  24. param_size = sizeof(uint16_t);
  25. event = BTSRV_PNP_VENDOR_ID;
  26. } else if (BT_SDP_ATTR_PRODUCT_ID == type) {
  27. param_size = sizeof(uint16_t);
  28. event = BTSRV_PNP_PRODUCT_ID;
  29. }
  30. if (pnp_info_context.pnp_user_callback) {
  31. pnp_info_context.pnp_user_callback(event, param, param_size);
  32. }
  33. return 0;
  34. }
  35. static const struct bt_pnp_info_cb btsrv_pnp_cb = {
  36. .info_get = _btsrv_pnp_info_get_cb
  37. };
  38. int btsrv_pnp_info_search(struct bt_conn *conn)
  39. {
  40. if (!hostif_bt_pnp_info_search(conn)) {
  41. SYS_LOG_DBG("btsrv_pnp_info_search conn:%p\n", conn);
  42. } else {
  43. SYS_LOG_ERR("btsrv_pnp_info_search failed\n");
  44. }
  45. return 0;
  46. }
  47. int btsrv_pnp_info_search_init(btsrv_pnp_info_callback cb)
  48. {
  49. SYS_LOG_INF("cb %p", cb);
  50. memset(&pnp_info_context, 0, sizeof(struct btsrv_pnp_info_context_info));
  51. hostif_bt_pnp_info_register_cb((struct bt_pnp_info_cb *)&btsrv_pnp_cb);
  52. pnp_info_context.pnp_user_callback = cb;
  53. return 0;
  54. }
  55. int btsrv_pnp_info_search_deinit(void)
  56. {
  57. hostif_bt_pnp_info_register_cb(NULL);
  58. pnp_info_context.pnp_user_callback = NULL;
  59. return 0;
  60. }
  61. int btsrv_pnp_info_process(struct app_msg *msg)
  62. {
  63. if (_btsrv_get_msg_param_type(msg) != MSG_BTSRV_PNP) {
  64. return -ENOTSUP;
  65. }
  66. switch (_btsrv_get_msg_param_cmd(msg)) {
  67. case MSG_BTSRV_PNP_INFO_START:
  68. SYS_LOG_INF("MSG_BTSRV_PNP_INFO_START\n");
  69. btsrv_pnp_info_search_init(msg->ptr);
  70. break;
  71. case MSG_BTSRV_PNP_INFO_STOP:
  72. SYS_LOG_INF("MSG_BTSRV_PNP_INFO_STOP\n");
  73. btsrv_pnp_info_search_deinit();
  74. break;
  75. }
  76. return 0;
  77. }