bsal_int.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. * Copyright (c) 2006-2020, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2020-05-28 Supperthomas the first version
  9. */
  10. #ifndef __BSAL_INT_H__
  11. #define __BSAL_INT_H__
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. #include <stdint.h>
  16. #include <stdbool.h>
  17. #include "bsal.h"
  18. struct bsal_uuid
  19. {
  20. uint8_t type;
  21. uint8_t data[16];
  22. uint16_t propertiy;
  23. uint16_t permision;
  24. uint32_t *handle;
  25. };
  26. typedef struct bsal_uuid bsal_uuid_t;
  27. struct bsal_gatt_value_entry
  28. {
  29. uint32_t u_handle;
  30. uint8_t *value;
  31. uint16_t value_length;
  32. uint32_t alloc_size;
  33. bool append;///for future
  34. struct bsal_gatt_value_entry *next_entry;
  35. };
  36. typedef struct bsal_gatt_value_entry bsal_gatt_value_entry_t;
  37. struct bsal_stack_ops
  38. {
  39. BSAL_STATUS(*le_set_stack_param)(uint32_t value_length, uint8_t *value); //set param param_type firstbit 1:br/edr param 0: ble
  40. BSAL_STATUS(*le_get_stack_param)(uint32_t value_length, uint8_t *value); //get param param_type firstbit 1:br/edr param 0: ble
  41. void (*get_mac_address)(uint8_t addr_type, uint8_t *bd_addr); //get mac addr
  42. void (*init)(uint8_t stack_type); //stack init //set the default param stack_type: bit 0 :BR/EDR. bit 1: BLE, bit2:mesh
  43. void (*startup)(void); //stack init
  44. //GAP OPERATE
  45. //bond
  46. void (*set_bond_param)(bsal_bond_param_t *value); //set adv param
  47. void (*get_bond_param)(bsal_bond_param_t *value);
  48. //ADV PARAM
  49. void (*le_set_adv_param)(bsal_adv_param_t *adv_param); //set adv param
  50. void (*le_get_adv_param)(bsal_adv_param_t *adv_param);
  51. BSAL_STATUS(*le_adv_enable)(bool enable); // set adv param
  52. void (*set_gaps_param)(bsal_gaps_param_t *gaps_param); //set device name
  53. //service profile
  54. uint32_t (*cov_handle_to_u_handle)(uint16_t service_id, uint16_t offset_handle); // bsal_hanlde_to_stack_handle
  55. BSAL_STATUS(*le_srv_reg_begin)(bool is_continue, uint8_t service_num, void *p_func);
  56. BSAL_STATUS(*le_srv_reg_fun)(struct bsal_gatt_app_srv_def *p_srv, void *p_func); //tobe define
  57. BSAL_STATUS(*le_srv_reg_end)(void);
  58. BSAL_STATUS(*le_srv_send_data)(uint16_t conn_handle, uint16_t service_id, uint16_t offse_handle, uint16_t value_len, const uint8_t *value, uint8_t send_type);
  59. BSAL_STATUS(*send_notify_complete)(uint32_t credits); /*TODO*/
  60. //client profile
  61. // TO BE CALLED BY BSAL_RTK.C
  62. };
  63. typedef struct bsal_stack_ops bsal_stack_ops_t;
  64. //load the static info
  65. struct bsal_stack_info
  66. {
  67. uint8_t public_bd_addr[6];
  68. uint8_t device_name[BSAL_MAX_NAME_LENGTH];
  69. uint16_t le_mtu_size;
  70. uint16_t le_srv_tx_credits;
  71. bsal_adv_param_t adv_param;
  72. bsal_bond_param_t bond_param;
  73. };
  74. typedef struct bsal_stack_info bsal_stack_info_t;
  75. typedef BSAL_STATUS(*P_BSAL_PROFILE_CB)(void *p_para);
  76. struct bsal_srv_callback
  77. {
  78. P_BSAL_PROFILE_CB bsal_srv_fn_cb;
  79. uint16_t start_handle;
  80. bsal_uuid_any_t srv_uuid;
  81. };
  82. typedef struct bsal_srv_callback bsal_srv_callback_t;
  83. struct bsal_stack_obj
  84. {
  85. bool stack_ready_flag;
  86. bsal_stack_ops_t bsal_ops;
  87. //att
  88. bsal_gatt_value_entry_t *db;
  89. //service
  90. bsal_srv_callback_t *bsal_srv_objs;
  91. //static info:
  92. bsal_stack_info_t bsal_info;
  93. uint16_t g_att_index;
  94. uint8_t srv_num;
  95. //register
  96. void (*app_all_callbak)(void *stack_ptr, uint8_t cb_layer, uint16_t cb_sub_event, uint8_t value_length , void *value);
  97. };
  98. typedef struct bsal_stack_obj bsal_stack_obj_t;
  99. /**
  100. * BSAL create the att first init
  101. *
  102. * @param stack_ptr the point of the stack object
  103. * @param u_handle the unique handle of the att
  104. * @param value_length the length of the value
  105. * @param value the buffer of the value
  106. * @Note create the attribute with the unique handle
  107. */
  108. int bsal_att_create_entry(void *stack_ptr, uint32_t u_handle, uint16_t value_length);
  109. /**
  110. * BSAL read the attribute with u_handle
  111. *
  112. * @param stack_ptr the point of the stack object
  113. * @param u_handle the unique handle of the att
  114. * @param value_length the length of the value
  115. * @param save the value the buffer of the value
  116. * @Note create the attribute with the unique handle
  117. */
  118. int bsal_att_read_entry(void *stack_ptr, uint32_t u_handle, uint16_t *value_length, uint8_t **value);
  119. /**
  120. * BSAL write the attribute with u_handle
  121. *
  122. * @param stack_ptr the point of the stack object
  123. * @param u_handle the unique handle of the att
  124. * @param value_length the length of the value
  125. * @param value the buffer of the value
  126. * @Note create the attribute with the unique handle
  127. */
  128. int bsal_att_write_entry(void *stack_ptr, uint32_t u_handle, uint16_t value_length, uint8_t *value);
  129. /**
  130. * BSAL change the attribute size with u_handle
  131. *
  132. * @param stack_ptr the point of the stack object
  133. * @param u_handle the unique handle of the att
  134. * @param value_length the length of the value
  135. * @param append the flag of append the value
  136. * @Note change the size of value the attribute with the unique handle
  137. */
  138. int bsal_att_resize_entry(void *stack_ptr, uint32_t u_handle, uint16_t value_length, bool append);
  139. //send data
  140. typedef enum
  141. {
  142. BSAL_SEND_DATA_TYPE_ANY = 0x00, /**< Any PDU type. */
  143. BSAL_SEND_DATA_TYPE_NOTIFICATION = 0x01, /**< Notification PDU type. */
  144. BSAL_SEND_DATA_TYPE_INDICATION = 0x02 /**< Indication PDU type. */
  145. } T_BSAL_SEND_DATA_TYPE;
  146. /**
  147. * BSAL find the start handle by the uuid
  148. *
  149. * @param stack_ptr the point of the stack object
  150. * @param uuid the 16 bit of the uuid
  151. * @Note get the profile start handle by the uuid
  152. */
  153. uint16_t bsal_profile_get_start_handle_by_16_uuid(void *stack_ptr, uint16_t uuid);
  154. /**
  155. * BSAL find the start handle by the uuid
  156. *
  157. * @param stack_ptr the point of the stack object
  158. * @param uuid the 32 bit of the uuid
  159. * @Note get the profile start handle by the uuid
  160. */
  161. uint16_t bsal_profile_get_start_handle_by_32_uuid(void *stack_ptr, uint32_t uuid);
  162. /**
  163. * BSAL find the start handle by the uuid
  164. *
  165. * @param stack_ptr the point of the stack object
  166. * @param uuid the point of the 128 bit of the uuid
  167. * @Note get the profile start handle by the uuid
  168. */
  169. uint16_t bsal_profile_get_start_handle_by_128_uuid(void *stack_ptr, uint8_t *uuid);
  170. /**
  171. * BSAL get the profile entry by the start handle
  172. *
  173. * @param stack_ptr the point of the stack object
  174. * @param the start handle
  175. * @Note get the profile entry by the start_handle
  176. */
  177. bsal_srv_callback_t *bsal_profile_get(void *stack_ptr, uint16_t start_handle);
  178. #ifdef __cplusplus
  179. }
  180. #endif
  181. #endif