ble_msg.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #if 0
  6. #define BLUETOOTH_INTERFACE_ADVERTISMENT_DATA_LENGTH 31
  7. /* ble_device_info */
  8. typedef struct ble_device_info {
  9. /* address type */
  10. uint8_t address_type;
  11. /* MAC of Device */
  12. uint8_t mac[6];
  13. /* security level */
  14. uint8_t security_level;
  15. /* signal strength */
  16. int8_t rssi;
  17. /* uuid_16_type */
  18. int8_t uuid_16_type;
  19. /* uuid_32_type */
  20. int8_t uuid_32_type;
  21. /* uuid_128_type */
  22. int8_t uuid_128_type;
  23. /* error code */
  24. uint8_t error_code;
  25. /* scan response length*/
  26. uint16_t adv_data_len;
  27. /* advertisement data */
  28. uint8_t *adv_data;
  29. /* scan response length*/
  30. uint16_t scan_response_len;
  31. /* scan response */
  32. uint8_t *scan_response;
  33. /* next device */
  34. struct ble_device_info *next;
  35. /* private data length */
  36. int private_data_length;
  37. /* private data */
  38. uint8_t *private_data;
  39. /* value handle*/
  40. uint16_t value_handle;
  41. /* ccc handle*/
  42. uint16_t ccc_handle;
  43. }ble_device_info;
  44. /* BLE message sub type */
  45. typedef enum BLE_SUB_EVENT_TYPE {
  46. BLE_SUB_EVENT_DISCOVERY,
  47. BLE_SUB_EVENT_CONNECTED,
  48. BLE_SUB_EVENT_DISCONNECTED,
  49. BLE_SUB_EVENT_NOTIFICATION,
  50. BLE_SUB_EVENT_INDICATION,
  51. BLE_SUB_EVENT_PASSKEYENTRY,
  52. BLE_SUB_EVENT_SECURITY_LEVEL_CHANGE
  53. }BLE_SUB_EVENT_TYPE;
  54. /* Queue message, for BLE Event */
  55. typedef struct bh_queue_ble_sub_msg_t {
  56. /* message type, should be one of QUEUE_MSG_TYPE */
  57. BLE_SUB_EVENT_TYPE type;
  58. /* payload size */
  59. /*uint32_t payload_size;*/
  60. char payload[1];
  61. }bh_queue_ble_sub_msg_t;
  62. static void
  63. app_instance_free_ble_msg(char *msg)
  64. {
  65. bh_queue_ble_sub_msg_t *ble_msg = (bh_queue_ble_sub_msg_t *)msg;
  66. ble_device_info *dev_info;
  67. dev_info = (ble_device_info *) ble_msg->payload;
  68. if (dev_info->scan_response != NULL)
  69. APP_MGR_FREE(dev_info->scan_response);
  70. if (dev_info->private_data != NULL)
  71. APP_MGR_FREE(dev_info->private_data);
  72. if (dev_info->adv_data != NULL)
  73. APP_MGR_FREE(dev_info->adv_data);
  74. if (dev_info != NULL)
  75. APP_MGR_FREE(dev_info);
  76. }
  77. static void
  78. app_instance_queue_free_callback(bh_message_t queue_msg)
  79. {
  80. char * payload = (char *)bh_message_payload(queue_msg);
  81. if(payload == NULL)
  82. return;
  83. switch (bh_message_type(queue_msg))
  84. {
  85. /*
  86. case SENSOR_EVENT: {
  87. bh_sensor_event_t *sensor_event = (bh_sensor_event_t *) payload;
  88. attr_container_t *event = sensor_event->event;
  89. attr_container_destroy(event);
  90. }
  91. break;
  92. */
  93. case BLE_EVENT: {
  94. app_instance_free_ble_msg(payload);
  95. break;
  96. }
  97. }
  98. }
  99. #endif