gap.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /**
  2. * @file
  3. * @author chipsea
  4. * @brief
  5. * @version 0.1
  6. * @date 2020-11-30
  7. * @copyright Copyright (c) 2020, CHIPSEA Co., Ltd.
  8. * @note
  9. */
  10. /*************************************************************************************************
  11. Filename: gap.c
  12. Revised:
  13. Revision:
  14. Description: This file contains the GAP Configuration API.
  15. **************************************************************************************************/
  16. #include "sdk_config.h"
  17. #include "bcomdef.h"
  18. #include "gap.h"
  19. #include "sm.h"
  20. #include "log.h"
  21. /*********************************************************************
  22. * MACROS
  23. */
  24. /*********************************************************************
  25. * CONSTANTS
  26. */
  27. /*********************************************************************
  28. * GLOBAL VARIABLES
  29. */
  30. /*********************************************************************
  31. * EXTERNAL VARIABLES
  32. */
  33. /*********************************************************************
  34. * EXTERNAL FUNCTIONS
  35. */
  36. /*********************************************************************
  37. * LOCAL VARIABLES
  38. */
  39. /*********************************************************************
  40. * LOCAL FUNCTION PROTOTYPES
  41. */
  42. /*********************************************************************
  43. * API FUNCTIONS
  44. */
  45. /*********************************************************************
  46. * Called to setup the device. Call just once.
  47. *
  48. * Public function defined in gap.h.
  49. */
  50. bStatus_t GAP_DeviceInit( uint8 taskID,
  51. uint8 profileRole,
  52. uint8 maxScanResponses,
  53. uint8 *pIRK,
  54. uint8 *pSRK,
  55. uint32 *pSignCounter )
  56. {
  57. bStatus_t stat = INVALIDPARAMETER; // Return status
  58. // Valid profile roles and supported combinations
  59. switch ( profileRole )
  60. {
  61. case GAP_PROFILE_BROADCASTER:
  62. #if ( HOST_CONFIG & ( BROADCASTER_CFG | PERIPHERAL_CFG ) )
  63. {
  64. stat = SUCCESS;
  65. }
  66. #endif
  67. break;
  68. case GAP_PROFILE_OBSERVER:
  69. #if ( HOST_CONFIG & ( OBSERVER_CFG | CENTRAL_CFG ) )
  70. {
  71. stat = SUCCESS;
  72. }
  73. #endif
  74. break;
  75. case GAP_PROFILE_PERIPHERAL:
  76. #if ( HOST_CONFIG & PERIPHERAL_CFG )
  77. {
  78. stat = SUCCESS;
  79. }
  80. #endif
  81. break;
  82. case GAP_PROFILE_CENTRAL:
  83. #if ( HOST_CONFIG & CENTRAL_CFG )
  84. {
  85. stat = SUCCESS;
  86. }
  87. #endif
  88. break;
  89. case (GAP_PROFILE_BROADCASTER | GAP_PROFILE_OBSERVER):
  90. #if ( ( HOST_CONFIG & ( BROADCASTER_CFG | PERIPHERAL_CFG ) ) && \
  91. ( HOST_CONFIG & ( OBSERVER_CFG | CENTRAL_CFG ) ) )
  92. {
  93. stat = SUCCESS;
  94. }
  95. #endif
  96. break;
  97. case (GAP_PROFILE_PERIPHERAL | GAP_PROFILE_OBSERVER):
  98. #if ( ( HOST_CONFIG & PERIPHERAL_CFG ) && \
  99. ( HOST_CONFIG & ( OBSERVER_CFG | CENTRAL_CFG ) ) )
  100. {
  101. stat = SUCCESS;
  102. }
  103. #endif
  104. break;
  105. case (GAP_PROFILE_CENTRAL | GAP_PROFILE_BROADCASTER):
  106. #if ( ( HOST_CONFIG & CENTRAL_CFG ) && \
  107. ( HOST_CONFIG & ( BROADCASTER_CFG | PERIPHERAL_CFG ) ) )
  108. {
  109. stat = SUCCESS;
  110. }
  111. #endif
  112. break;
  113. case (GAP_PROFILE_CENTRAL | GAP_PROFILE_PERIPHERAL):
  114. {
  115. LOG_DEBUG("GAP_DeviceInit: GAP_PROFILE_CENTRAL | GAP_PROFILE_PERIPHERAL \n");
  116. stat = SUCCESS;
  117. }
  118. break;
  119. // Invalid profile roles
  120. default:
  121. stat = INVALIDPARAMETER;
  122. break;
  123. }
  124. if ( stat == SUCCESS )
  125. {
  126. // Setup the device configuration parameters
  127. stat = GAP_ParamsInit( taskID, profileRole );
  128. if ( stat == SUCCESS )
  129. {
  130. #if ( HOST_CONFIG & ( CENTRAL_CFG | PERIPHERAL_CFG ) )
  131. {
  132. GAP_SecParamsInit( pIRK, pSRK, pSignCounter );
  133. }
  134. #endif
  135. #if ( HOST_CONFIG & ( CENTRAL_CFG | OBSERVER_CFG ) )
  136. {
  137. // if ( (profileRole == GAP_PROFILE_BROADCASTER) ||
  138. // (profileRole == GAP_PROFILE_PERIPHERAL) )
  139. // {
  140. // maxScanResponses = 0; // Can't scan, so no need for responses. Force 0.
  141. // }
  142. // Initialize GAP Central Device Manager
  143. VOID GAP_CentDevMgrInit( maxScanResponses );
  144. #if ( HOST_CONFIG & CENTRAL_CFG )
  145. {
  146. // Register GAP Central Connection processing functions
  147. GAP_CentConnRegister();
  148. // Initialize SM Initiator
  149. VOID SM_InitiatorInit();
  150. }
  151. #endif
  152. }
  153. #endif
  154. #if ( HOST_CONFIG & ( PERIPHERAL_CFG | BROADCASTER_CFG ) )
  155. {
  156. // Initialize GAP Peripheral Device Manager
  157. VOID GAP_PeriDevMgrInit();
  158. #if ( HOST_CONFIG & PERIPHERAL_CFG )
  159. {
  160. // Initialize SM Responder
  161. VOID SM_ResponderInit();
  162. }
  163. #endif
  164. }
  165. #endif
  166. }
  167. }
  168. return ( stat );
  169. }
  170. /*********************************************************************
  171. *********************************************************************/