central.h 10 KB

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