gap.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /**************************************************************************************************
  2. Phyplus Microelectronics Limited confidential and proprietary.
  3. All rights reserved.
  4. IMPORTANT: All rights of this software belong to Phyplus Microelectronics
  5. Limited ("Phyplus"). Your use of this Software is limited to those
  6. specific rights granted under the terms of the business contract, the
  7. confidential agreement, the non-disclosure agreement and any other forms
  8. of agreements as a customer or a partner of Phyplus. You may not use this
  9. Software unless you agree to abide by the terms of these agreements.
  10. You acknowledge that the Software may not be modified, copied,
  11. distributed or disclosed unless embedded on a Phyplus Bluetooth Low Energy
  12. (BLE) integrated circuit, either as a product or is integrated into your
  13. products. Other than for the aforementioned purposes, you may not use,
  14. reproduce, copy, prepare derivative works of, modify, distribute, perform,
  15. display or sell this Software and/or its documentation for any purposes.
  16. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
  17. PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  18. INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
  19. NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
  20. PHYPLUS OR ITS SUBSIDIARIES BE LIABLE OR OBLIGATED UNDER CONTRACT,
  21. NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
  22. LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
  23. INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
  24. OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
  25. OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
  26. (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
  27. **************************************************************************************************/
  28. /*************************************************************************************************
  29. Filename: gap.c
  30. Revised:
  31. Revision:
  32. Description: This file contains the GAP Configuration API.
  33. **************************************************************************************************/
  34. #include "bcomdef.h"
  35. #include "gap.h"
  36. #include "sm.h"
  37. /*********************************************************************
  38. * MACROS
  39. */
  40. /*********************************************************************
  41. * CONSTANTS
  42. */
  43. /*********************************************************************
  44. * GLOBAL VARIABLES
  45. */
  46. /*********************************************************************
  47. * EXTERNAL VARIABLES
  48. */
  49. /*********************************************************************
  50. * EXTERNAL FUNCTIONS
  51. */
  52. /*********************************************************************
  53. * LOCAL VARIABLES
  54. */
  55. /*********************************************************************
  56. * LOCAL FUNCTION PROTOTYPES
  57. */
  58. /*********************************************************************
  59. * API FUNCTIONS
  60. */
  61. /*********************************************************************
  62. * Called to setup the device. Call just once.
  63. *
  64. * Public function defined in gap.h.
  65. */
  66. bStatus_t GAP_DeviceInit( uint8 taskID,
  67. uint8 profileRole,
  68. uint8 maxScanResponses,
  69. uint8 *pIRK,
  70. uint8 *pSRK,
  71. uint32 *pSignCounter )
  72. {
  73. bStatus_t stat = INVALIDPARAMETER; // Return status
  74. // Valid profile roles and supported combinations
  75. switch ( profileRole )
  76. {
  77. case GAP_PROFILE_BROADCASTER:
  78. #if ( HOST_CONFIG & ( BROADCASTER_CFG | PERIPHERAL_CFG ) )
  79. {
  80. stat = SUCCESS;
  81. }
  82. #endif
  83. break;
  84. case GAP_PROFILE_OBSERVER:
  85. #if ( HOST_CONFIG & ( OBSERVER_CFG | CENTRAL_CFG ) )
  86. {
  87. stat = SUCCESS;
  88. }
  89. #endif
  90. break;
  91. case GAP_PROFILE_PERIPHERAL:
  92. #if ( HOST_CONFIG & PERIPHERAL_CFG )
  93. {
  94. stat = SUCCESS;
  95. }
  96. #endif
  97. break;
  98. case GAP_PROFILE_CENTRAL:
  99. #if ( HOST_CONFIG & CENTRAL_CFG )
  100. {
  101. stat = SUCCESS;
  102. }
  103. #endif
  104. break;
  105. case (GAP_PROFILE_BROADCASTER | GAP_PROFILE_OBSERVER):
  106. #if ( ( HOST_CONFIG & ( BROADCASTER_CFG | PERIPHERAL_CFG ) ) && \
  107. ( HOST_CONFIG & ( OBSERVER_CFG | CENTRAL_CFG ) ) )
  108. {
  109. stat = SUCCESS;
  110. }
  111. #endif
  112. break;
  113. case (GAP_PROFILE_PERIPHERAL | GAP_PROFILE_OBSERVER):
  114. #if ( ( HOST_CONFIG & PERIPHERAL_CFG ) && \
  115. ( HOST_CONFIG & ( OBSERVER_CFG | CENTRAL_CFG ) ) )
  116. {
  117. stat = SUCCESS;
  118. }
  119. #endif
  120. break;
  121. case (GAP_PROFILE_CENTRAL | GAP_PROFILE_BROADCASTER):
  122. #if ( ( HOST_CONFIG & CENTRAL_CFG ) && \
  123. ( HOST_CONFIG & ( BROADCASTER_CFG | PERIPHERAL_CFG ) ) )
  124. {
  125. stat = SUCCESS;
  126. }
  127. #endif
  128. break;
  129. // Invalid profile roles
  130. default:
  131. stat = INVALIDPARAMETER;
  132. break;
  133. }
  134. if ( stat == SUCCESS )
  135. {
  136. // Setup the device configuration parameters
  137. stat = GAP_ParamsInit( taskID, profileRole );
  138. if ( stat == SUCCESS )
  139. {
  140. #if ( HOST_CONFIG & ( CENTRAL_CFG | PERIPHERAL_CFG ) )
  141. {
  142. GAP_SecParamsInit( pIRK, pSRK, pSignCounter );
  143. }
  144. #endif
  145. #if ( HOST_CONFIG & ( CENTRAL_CFG | OBSERVER_CFG ) )
  146. {
  147. // if ( (profileRole == GAP_PROFILE_BROADCASTER) ||
  148. // (profileRole == GAP_PROFILE_PERIPHERAL) )
  149. // {
  150. // maxScanResponses = 0; // Can't scan, so no need for responses. Force 0.
  151. // }
  152. // Initialize GAP Central Device Manager
  153. VOID GAP_CentDevMgrInit( maxScanResponses );
  154. #if ( HOST_CONFIG & CENTRAL_CFG )
  155. {
  156. // Register GAP Central Connection processing functions
  157. GAP_CentConnRegister();
  158. // Initialize SM Initiator
  159. VOID SM_InitiatorInit();
  160. }
  161. #endif
  162. }
  163. #endif
  164. #if ( HOST_CONFIG & ( PERIPHERAL_CFG | BROADCASTER_CFG ) )
  165. {
  166. // Initialize GAP Peripheral Device Manager
  167. VOID GAP_PeriDevMgrInit();
  168. #if ( HOST_CONFIG & PERIPHERAL_CFG )
  169. {
  170. // Initialize SM Responder
  171. VOID SM_ResponderInit();
  172. }
  173. #endif
  174. }
  175. #endif
  176. }
  177. }
  178. return ( stat );
  179. }
  180. /*********************************************************************
  181. *********************************************************************/