ble_msg.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #if 0
  17. #define BLUETOOTH_INTERFACE_ADVERTISMENT_DATA_LENGTH 31
  18. /* ble_device_info */
  19. typedef struct ble_device_info {
  20. /* address type */
  21. uint8_t address_type;
  22. /* MAC of Device */
  23. uint8_t mac[6];
  24. /* security level */
  25. uint8_t security_level;
  26. /* signal strength */
  27. int8_t rssi;
  28. /* uuid_16_type */
  29. int8_t uuid_16_type;
  30. /* uuid_32_type */
  31. int8_t uuid_32_type;
  32. /* uuid_128_type */
  33. int8_t uuid_128_type;
  34. /* error code */
  35. uint8_t error_code;
  36. /* scan response length*/
  37. uint16_t adv_data_len;
  38. /* advertisement data */
  39. uint8_t *adv_data;
  40. /* scan response length*/
  41. uint16_t scan_response_len;
  42. /* scan response */
  43. uint8_t *scan_response;
  44. /* next device */
  45. struct ble_device_info *next;
  46. /* private data length */
  47. int private_data_length;
  48. /* private data */
  49. uint8_t *private_data;
  50. /* value handle*/
  51. uint16_t value_handle;
  52. /* ccc handle*/
  53. uint16_t ccc_handle;
  54. }ble_device_info;
  55. /* BLE message sub type */
  56. typedef enum BLE_SUB_EVENT_TYPE {
  57. BLE_SUB_EVENT_DISCOVERY,
  58. BLE_SUB_EVENT_CONNECTED,
  59. BLE_SUB_EVENT_DISCONNECTED,
  60. BLE_SUB_EVENT_NOTIFICATION,
  61. BLE_SUB_EVENT_INDICATION,
  62. BLE_SUB_EVENT_PASSKEYENTRY,
  63. BLE_SUB_EVENT_SECURITY_LEVEL_CHANGE
  64. }BLE_SUB_EVENT_TYPE;
  65. /* Queue message, for BLE Event */
  66. typedef struct bh_queue_ble_sub_msg_t {
  67. /* message type, should be one of QUEUE_MSG_TYPE */
  68. BLE_SUB_EVENT_TYPE type;
  69. /* payload size */
  70. /*uint32_t payload_size;*/
  71. char payload[1];
  72. }bh_queue_ble_sub_msg_t;
  73. static void
  74. app_instance_free_ble_msg(char *msg)
  75. {
  76. bh_queue_ble_sub_msg_t *ble_msg = (bh_queue_ble_sub_msg_t *)msg;
  77. ble_device_info *dev_info;
  78. dev_info = (ble_device_info *) ble_msg->payload;
  79. if (dev_info->scan_response != NULL)
  80. bh_free(dev_info->scan_response);
  81. if (dev_info->private_data != NULL)
  82. bh_free(dev_info->private_data);
  83. if (dev_info->adv_data != NULL)
  84. bh_free(dev_info->adv_data);
  85. if (dev_info != NULL)
  86. bh_free(dev_info);
  87. }
  88. static void
  89. app_instance_queue_free_callback(bh_message_t queue_msg)
  90. {
  91. char * payload = (char *)bh_message_payload(queue_msg);
  92. if(payload == NULL)
  93. return;
  94. switch (bh_message_type(queue_msg))
  95. {
  96. /*
  97. case SENSOR_EVENT: {
  98. bh_sensor_event_t *sensor_event = (bh_sensor_event_t *) payload;
  99. attr_container_t *event = sensor_event->event;
  100. attr_container_destroy(event);
  101. }
  102. break;
  103. */
  104. case BLE_EVENT: {
  105. app_instance_free_ble_msg(payload);
  106. break;
  107. }
  108. }
  109. }
  110. #endif