profile.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. #include "include.h"
  2. #include "api.h"
  3. extern const uint8_t sdp_spp_service_record[];
  4. extern const uint8_t sdp_hfp_service_record[];
  5. extern const uint8_t sdp_hsp_service_record[];
  6. extern const uint8_t sdp_avdtp_service_record[]; //a2dp1.3
  7. extern const uint8_t sdp_avctp_controller_service_record[];
  8. extern const uint8_t sdp_avctp_target_category1_service_record[];
  9. extern const uint8_t sdp_avctp_target_category2_service_record[];
  10. extern const uint8_t sdp_hid_keyboard_service_record[];
  11. extern const uint8_t sdp_hid_consumer_service_record[];
  12. extern const uint8_t sdp_hid_tscreen_service_record[];
  13. extern const uint8_t sdp_hid_tscreen_ext_service_record[];
  14. extern const uint8_t sdp_devic_id_service_record[];
  15. extern const uint8_t sdp_gfps_spp_service_record[];
  16. extern const uint8_t sdp_gatt_service_record[];
  17. extern const uint8_t sdp_hid_ios_service_record[];
  18. extern const uint8_t sdp_pnp_ios_service_record[];
  19. extern const uint8_t sdp_spp_dueros_dma_service_record[];
  20. typedef struct {
  21. void *item;
  22. uint32_t service_record_handle;
  23. uint8_t *service_record;
  24. } service_record_item_t;
  25. #if BT_SPP_EN
  26. service_record_item_t spp_sdp_record_item = {
  27. .service_record_handle = 0x00010001,
  28. .service_record = (uint8_t *)sdp_spp_service_record,
  29. };
  30. #endif
  31. #if GFPS_EN
  32. service_record_item_t spp_gfps_sdp_record_item = {
  33. .service_record_handle = 0x50010001,
  34. .service_record = (uint8_t *)sdp_gfps_spp_service_record,
  35. };
  36. #endif
  37. #if LE_DUEROS_DMA_EN
  38. service_record_item_t spp_dueros_dma_sdp_record_item = {
  39. .service_record_handle = 0x50010003,
  40. .service_record = (uint8_t *)sdp_spp_dueros_dma_service_record,
  41. };
  42. #endif
  43. #ifdef AB_MATE_SPP_UUID
  44. extern const uint8_t sdp_ab_mate_spp_service_record[];
  45. service_record_item_t spp_ab_mate_sdp_record_item = {
  46. .service_record_handle = 0x50010003,
  47. .service_record = (uint8_t *)sdp_ab_mate_spp_service_record,
  48. };
  49. #endif
  50. #if BT_HFP_EN
  51. service_record_item_t hfp_sdp_record_item = {
  52. .service_record_handle = 0x00010002,
  53. .service_record = (uint8_t *)sdp_hfp_service_record,
  54. };
  55. #endif
  56. #if BT_HSP_EN
  57. service_record_item_t hsp_sdp_record_item = {
  58. .service_record_handle = 0x00010008,
  59. .service_record = (uint8_t *)sdp_hsp_service_record,
  60. };
  61. #endif
  62. #if BT_A2DP_EN
  63. service_record_item_t avdtp_sdp_record_item = {
  64. .service_record_handle = 0x00010003,
  65. .service_record = (uint8_t *)sdp_avdtp_service_record,
  66. };
  67. service_record_item_t avctp_ct_sdp_record_item = {
  68. .service_record_handle = 0x00010004,
  69. .service_record = (uint8_t *)sdp_avctp_controller_service_record,
  70. };
  71. service_record_item_t avctp_tg_sdp_record_item = {
  72. .service_record_handle = 0x00010005,
  73. .service_record = (uint8_t *)sdp_avctp_target_category2_service_record,
  74. };
  75. #endif // BT_A2DP_EN
  76. #if BT_HID_EN
  77. service_record_item_t hid_sdp_record_item = {
  78. .service_record_handle = 0x00010006,
  79. #if (BT_HID_TYPE == 0)
  80. .service_record = (uint8_t *)sdp_hid_consumer_service_record,
  81. #elif (BT_HID_TYPE == 1)
  82. .service_record = (uint8_t *)sdp_hid_keyboard_service_record,
  83. #elif (BT_HID_TYPE == 2)
  84. .service_record = (uint8_t *)sdp_hid_tscreen_service_record,
  85. #elif (BT_HID_TYPE == 3)
  86. .service_record = (uint8_t *)sdp_hid_ios_service_record,
  87. #else
  88. .service_record = ...
  89. #endif
  90. };
  91. service_record_item_t device_id_sdp_record_item = {
  92. .service_record_handle = 0x00010007,
  93. #if (BT_HID_TYPE == 3)
  94. .service_record = (uint8_t *)sdp_pnp_ios_service_record,
  95. #else
  96. .service_record = (uint8_t *)sdp_devic_id_service_record,
  97. #endif
  98. };
  99. #endif // BT_HID_EN
  100. #if BT_ATT_EN
  101. service_record_item_t gatt_service_record_item = {
  102. .service_record_handle = 0x00010008,
  103. .service_record = (uint8_t *)sdp_gatt_service_record,
  104. };
  105. #endif
  106. void bt_init_lib(void)
  107. {
  108. uint32_t profile = cfg_bt_support_profile;
  109. #if BT_SPP_EN
  110. if (profile & PROF_SPP) {
  111. #if GFPS_EN || LE_DUEROS_DMA_EN
  112. spp_support_mul_server(1);
  113. #endif
  114. #ifdef AB_MATE_SPP_UUID
  115. spp_support_mul_server(1);
  116. #endif
  117. spp_init();
  118. #if GFPS_EN
  119. if (gfps_is_enable()) {
  120. sdp_add_service(&spp_gfps_sdp_record_item);
  121. gfps_bt_init();
  122. }
  123. #endif
  124. #if LE_DUEROS_DMA_EN
  125. sdp_add_service(&spp_dueros_dma_sdp_record_item);
  126. #endif
  127. #ifdef AB_MATE_SPP_UUID
  128. sdp_add_service(&spp_ab_mate_sdp_record_item);
  129. #endif
  130. sdp_add_service(&spp_sdp_record_item);
  131. }
  132. #endif
  133. #if BT_HFP_EN
  134. if (profile & PROF_HFP) {
  135. hfp_hf_init();
  136. sdp_add_service(&hfp_sdp_record_item);
  137. }
  138. #endif
  139. hsp_hs_init_var();
  140. #if BT_HSP_EN
  141. if (profile & PROF_HSP) {
  142. hsp_hs_init();
  143. sdp_add_service(&hsp_sdp_record_item);
  144. }
  145. #endif
  146. #if BT_A2DP_EN
  147. if (profile & PROF_A2DP) {
  148. a2dp_init();
  149. avctp_tg_sdp_record_item.service_record = (uint8_t *)sdp_avctp_target_category2_service_record;
  150. sdp_add_service(&avdtp_sdp_record_item);
  151. sdp_add_service(&avctp_ct_sdp_record_item);
  152. sdp_add_service(&avctp_tg_sdp_record_item);
  153. }
  154. #endif
  155. #if BT_HID_EN
  156. if (profile & PROF_HID) {
  157. hid_device_init();
  158. sdp_add_service(&hid_sdp_record_item);
  159. sdp_add_service(&device_id_sdp_record_item);
  160. }
  161. #endif
  162. #if BT_PBAP_EN
  163. // init PBAP
  164. if (profile & PROF_PBAP) {
  165. // init PBAP Client
  166. goep_client_init();
  167. pbap_client_init();
  168. }
  169. #endif
  170. #if BT_MAP_EN
  171. if (profile & PROF_MAP) {
  172. // init MAP Client
  173. goep_client_init();
  174. map_client_init();
  175. }
  176. #endif
  177. #if BT_ATT_EN
  178. if(profile & PROF_GATT) {
  179. sdp_add_service(&gatt_service_record_item);
  180. }
  181. #endif
  182. }