central.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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. #ifndef CENTRAL_H
  11. #define CENTRAL_H
  12. #ifdef __cplusplus
  13. extern "C"
  14. {
  15. #endif
  16. /*********************************************************************
  17. * INCLUDES
  18. */
  19. #include "bcomdef.h"
  20. #include "OSAL.h"
  21. #include "gap.h"
  22. /*********************************************************************
  23. * CONSTANTS
  24. */
  25. /** @defgroup GAPCENTRALROLE_PROFILE_PARAMETERS GAP Central Role Parameters
  26. * @{
  27. */
  28. #define GAPCENTRALROLE_IRK 0x400 //!< Identity Resolving Key. Read/Write. Size is uint8[KEYLEN]. Default is all 0, which means that the IRK will be randomly generated.
  29. #define GAPCENTRALROLE_SRK 0x401 //!< Signature Resolving Key. Read/Write. Size is uint8[KEYLEN]. Default is all 0, which means that the SRK will be randomly generated.
  30. #define GAPCENTRALROLE_SIGNCOUNTER 0x402 //!< Sign Counter. Read/Write. Size is uint32. Default is 0.
  31. #define GAPCENTRALROLE_BD_ADDR 0x403 //!< Device's Address. Read Only. Size is uint8[B_ADDR_LEN]. This item is read from the controller.
  32. #define GAPCENTRALROLE_MAX_SCAN_RES 0x404 //!< Maximum number of discover scan results to receive. Default is 0 = unlimited.
  33. /** @} End GAPCENTRALROLE_PROFILE_PARAMETERS */
  34. /**
  35. * Number of simultaneous links with periodic RSSI reads
  36. */
  37. #ifndef GAPCENTRALROLE_NUM_RSSI_LINKS
  38. #define GAPCENTRALROLE_NUM_RSSI_LINKS 4
  39. #endif
  40. /*********************************************************************
  41. * VARIABLES
  42. */
  43. /*********************************************************************
  44. * MACROS
  45. */
  46. /*********************************************************************
  47. * TYPEDEFS
  48. */
  49. /**
  50. * Central Event Structure
  51. */
  52. typedef union
  53. {
  54. gapEventHdr_t gap; //!< GAP_MSG_EVENT and status.
  55. gapDeviceInitDoneEvent_t initDone; //!< GAP initialization done.
  56. gapDeviceInfoEvent_t deviceInfo; //!< Discovery device information event structure.
  57. gapDevDiscEvent_t discCmpl; //!< Discovery complete event structure.
  58. gapEstLinkReqEvent_t linkCmpl; //!< Link complete event structure.
  59. gapLinkUpdateEvent_t linkUpdate; //!< Link update event structure.
  60. gapTerminateLinkEvent_t linkTerminate; //!< Link terminated event structure.
  61. } gapCentralRoleEvent_t;
  62. /**
  63. * RSSI Read Callback Function
  64. */
  65. typedef void (*pfnGapCentralRoleRssiCB_t)
  66. (
  67. uint16 connHandle, //!< Connection handle.
  68. int8 rssi //!< New RSSI value.
  69. );
  70. /**
  71. * Central Event Callback Function
  72. */
  73. typedef void (*pfnGapCentralRoleEventCB_t)
  74. (
  75. gapCentralRoleEvent_t *pEvent //!< Pointer to event structure.
  76. );
  77. /**
  78. * Central Callback Structure
  79. */
  80. typedef struct
  81. {
  82. pfnGapCentralRoleRssiCB_t rssiCB; //!< RSSI callback.
  83. pfnGapCentralRoleEventCB_t eventCB; //!< Event callback.
  84. } gapCentralRoleCB_t;
  85. /*********************************************************************
  86. * VARIABLES
  87. */
  88. /*********************************************************************
  89. * API FUNCTIONS
  90. */
  91. /*-------------------------------------------------------------------
  92. * Central Profile Public APIs
  93. */
  94. /**
  95. * @defgroup CENTRAL_PROFILE_API Central Profile API Functions
  96. *
  97. * @{
  98. */
  99. /**
  100. * @brief Start the device in Central role. This function is typically
  101. * called once during system startup.
  102. *
  103. * @param pAppCallbacks - pointer to application callbacks
  104. *
  105. * @return SUCCESS: Operation successful.<BR>
  106. * bleAlreadyInRequestedMode: Device already started.<BR>
  107. */
  108. extern bStatus_t GAPCentralRole_StartDevice( gapCentralRoleCB_t *pAppCallbacks );
  109. /**
  110. * @brief Set a parameter in the Central Profile.
  111. *
  112. * @param param - profile parameter ID: @ref GAPCENTRALROLE_PROFILE_PARAMETERS
  113. * @param len - length of data to write
  114. * @param pValue - pointer to data to write. This is dependent on
  115. * the parameter ID and WILL be cast to the appropriate
  116. * data type.
  117. *
  118. * @return SUCCESS: Operation successful.<BR>
  119. * INVALIDPARAMETER: Invalid parameter ID.<BR>
  120. */
  121. extern bStatus_t GAPCentralRole_SetParameter( uint16 param, uint8 len, void *pValue );
  122. /**
  123. * @brief Get a parameter in the Central Profile.
  124. *
  125. * @param param - profile parameter ID: @ref GAPCENTRALROLE_PROFILE_PARAMETERS
  126. * @param pValue - pointer to buffer to contain the read data
  127. *
  128. * @return SUCCESS: Operation successful.<BR>
  129. * INVALIDPARAMETER: Invalid parameter ID.<BR>
  130. */
  131. extern bStatus_t GAPCentralRole_GetParameter( uint16 param, void *pValue );
  132. /**
  133. * @brief Terminate a link.
  134. *
  135. * @param connHandle - connection handle of link to terminate
  136. * or @ref GAP_CONN_HANDLE_DEFINES
  137. *
  138. * @return SUCCESS: Terminate started.<BR>
  139. * bleIncorrectMode: No link to terminate.<BR>
  140. */
  141. extern bStatus_t GAPCentralRole_TerminateLink( uint16 connHandle );
  142. /**
  143. * @brief Establish a link to a peer device.
  144. *
  145. * @param highDutyCycle - TRUE to high duty cycle scan, FALSE if not
  146. * @param whiteList - determines use of the white list: @ref GAP_WHITELIST_DEFINES
  147. * @param addrTypePeer - address type of the peer device: @ref GAP_ADDR_TYPE_DEFINES
  148. * @param peerAddr - peer device address
  149. *
  150. * @return SUCCESS: started establish link process.<BR>
  151. * bleIncorrectMode: invalid profile role.<BR>
  152. * bleNotReady: a scan is in progress.<BR>
  153. * bleAlreadyInRequestedMode: can?t process now.<BR>
  154. * bleNoResources: too many links.<BR>
  155. */
  156. extern bStatus_t GAPCentralRole_EstablishLink( uint8 highDutyCycle, uint8 whiteList,
  157. uint8 addrTypePeer, uint8 *peerAddr );
  158. /**
  159. * @brief Update the link connection parameters.
  160. *
  161. * @param connHandle - connection handle
  162. * @param connIntervalMin - minimum connection interval in 1.25ms units
  163. * @param connIntervalMax - maximum connection interval in 1.25ms units
  164. * @param connLatency - number of LL latency connection events
  165. * @param connTimeout - connection timeout in 10ms units
  166. *
  167. * @return SUCCESS: Connection update started started.<BR>
  168. * bleIncorrectMode: No connection to update.<BR>
  169. */
  170. extern bStatus_t GAPCentralRole_UpdateLink( uint16 connHandle, uint16 connIntervalMin,
  171. uint16 connIntervalMax, uint16 connLatency,
  172. uint16 connTimeout );
  173. /**
  174. * @brief Start a device discovery scan.
  175. *
  176. * @param mode - discovery mode: @ref GAP_DEVDISC_MODE_DEFINES
  177. * @param activeScan - TRUE to perform active scan
  178. * @param whiteList - TRUE to only scan for devices in the white list
  179. *
  180. * @return SUCCESS: Discovery scan started.<BR>
  181. * bleIncorrectMode: Invalid profile role.<BR>
  182. * bleAlreadyInRequestedMode: Not available.<BR>
  183. */
  184. extern bStatus_t GAPCentralRole_StartDiscovery( uint8 mode, uint8 activeScan, uint8 whiteList );
  185. /**
  186. * @brief Cancel a device discovery scan.
  187. *
  188. * @return SUCCESS: Cancel started.<BR>
  189. * bleInvalidTaskID: Not the task that started discovery.<BR>
  190. * bleIncorrectMode: Not in discovery mode.<BR>
  191. */
  192. extern bStatus_t GAPCentralRole_CancelDiscovery( void );
  193. /**
  194. * @brief Start periodic RSSI reads on a link.
  195. *
  196. * @param connHandle - connection handle of link
  197. * @param period - RSSI read period in ms
  198. *
  199. * @return SUCCESS: Terminate started.<BR>
  200. * bleIncorrectMode: No link.<BR>
  201. * bleNoResources: No resources.<BR>
  202. */
  203. extern bStatus_t GAPCentralRole_StartRssi( uint16 connHandle, uint16 period );
  204. /**
  205. * @brief Cancel periodic RSSI reads on a link.
  206. *
  207. * @param connHandle - connection handle of link
  208. *
  209. * @return SUCCESS: Operation successful.<BR>
  210. * bleIncorrectMode: No link.<BR>
  211. */
  212. extern bStatus_t GAPCentralRole_CancelRssi(uint16 connHandle );
  213. /**
  214. * @}
  215. */
  216. /*-------------------------------------------------------------------
  217. * TASK API - These functions must only be called by OSAL.
  218. */
  219. /**
  220. * @internal
  221. *
  222. * @brief Central Profile Task initialization function.
  223. *
  224. * @param taskId - Task ID.
  225. *
  226. * @return void
  227. */
  228. extern void GAPCentralRole_Init( uint8 taskId );
  229. /**
  230. * @internal
  231. *
  232. * @brief Central Profile Task event processing function.
  233. *
  234. * @param taskId - Task ID
  235. * @param events - Events.
  236. *
  237. * @return events not processed
  238. */
  239. extern uint16 GAPCentralRole_ProcessEvent( uint8 taskId, uint16 events );
  240. /*********************************************************************
  241. *********************************************************************/
  242. #ifdef __cplusplus
  243. }
  244. #endif
  245. #endif /* CENTRAL_H */