peripheralBroadcaster.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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 PERIPHERAL_BROADCASTER_H
  29. #define PERIPHERAL_BROADCASTER_H
  30. #ifdef __cplusplus
  31. extern "C"
  32. {
  33. #endif
  34. /*-------------------------------------------------------------------
  35. * INCLUDES
  36. */
  37. /*-------------------------------------------------------------------
  38. * CONSTANTS
  39. */
  40. /** @defgroup GAPROLE_PROFILE_PARAMETERS GAP Role Parameters
  41. * @{
  42. */
  43. #define GAPROLE_PROFILEROLE 0x300 //!< Reading this parameter will return GAP Role type. Read Only. Size is uint8.
  44. #define GAPROLE_IRK 0x301 //!< Identity Resolving Key. Read/Write. Size is uint8[KEYLEN]. Default is all 0, which means that the IRK will be randomly generated.
  45. #define GAPROLE_SRK 0x302 //!< Signature Resolving Key. Read/Write. Size is uint8[KEYLEN]. Default is all 0, which means that the SRK will be randomly generated.
  46. #define GAPROLE_SIGNCOUNTER 0x303 //!< Sign Counter. Read/Write. Size is uint32. Default is 0.
  47. #define GAPROLE_BD_ADDR 0x304 //!< Device's Address. Read Only. Size is uint8[B_ADDR_LEN]. This item is read from the controller.
  48. #define GAPROLE_ADVERT_ENABLED 0x305 //!< Enable/Disable Advertising. Read/Write. Size is uint8. Default is TRUE=Enabled. During a connection, this will enable and display advertising (non-connectable undirected). Setting this variable during a connection does not change the permanent state of the parameter.
  49. #define GAPROLE_ADVERT_OFF_TIME 0x306 //!< Advertising Off Time for Limited advertisements (in milliseconds). Read/Write. Size is uint16. Default is 30 seconds.
  50. #define GAPROLE_ADVERT_DATA 0x307 //!< Advertisement Data. Read/Write. Max size is uint8[B_MAX_ADV_LEN]. Default is "02:01:01", which means that it is a Limited Discoverable Advertisement.
  51. #define GAPROLE_SCAN_RSP_DATA 0x308 //!< Scan Response Data. Read/Write. Max size is uint8[B_MAX_ADV_LEN]. Defaults to all 0.
  52. #define GAPROLE_ADV_EVENT_TYPE 0x309 //!< Advertisement Type. Read/Write. Size is uint8. Default is GAP_ADTYPE_ADV_IND (defined in GAP.h).
  53. #define GAPROLE_ADV_DIRECT_TYPE 0x30A //!< Direct Advertisement Address Type. Read/Write. Size is uint8. Default is ADDRTYPE_PUBLIC (defined in GAP.h).
  54. #define GAPROLE_ADV_DIRECT_ADDR 0x30B //!< Direct Advertisement Address. Read/Write. Size is uint8[B_ADDR_LEN]. Default is NULL.
  55. #define GAPROLE_ADV_CHANNEL_MAP 0x30C //!< Which channels to advertise on. Read/Write Size is uint8. Default is GAP_ADVCHAN_ALL (defined in GAP.h)
  56. #define GAPROLE_ADV_FILTER_POLICY 0x30D //!< Filter Policy. Ignored when directed advertising is used. Read/Write. Size is uint8. Default is GAP_FILTER_POLICY_ALL (defined in GAP.h).
  57. #define GAPROLE_CONNHANDLE 0x30E //!< Connection Handle. Read Only. Size is uint16.
  58. #define GAPROLE_RSSI_READ_RATE 0x30F //!< How often to read the RSSI during a connection. Read/Write. Size is uint16. The value is in milliseconds. Default is 0 = OFF.
  59. #define GAPROLE_PARAM_UPDATE_ENABLE 0x310 //!< Slave Connection Parameter Update Enable. Read/Write. Size is uint8. If TRUE then automatic connection parameter update request is sent. Default is FALSE.
  60. #define GAPROLE_MIN_CONN_INTERVAL 0x311 //!< Minimum Connection Interval to allow (n * 1.25ms). Range: 7.5 msec to 4 seconds (0x0006 to 0x0C80). Read/Write. Size is uint16. Default is 7.5 milliseconds (0x0006).
  61. #define GAPROLE_MAX_CONN_INTERVAL 0x312 //!< Maximum Connection Interval to allow (n * 1.25ms). Range: 7.5 msec to 4 seconds (0x0006 to 0x0C80). Read/Write. Size is uint16. Default is 4 seconds (0x0C80).
  62. #define GAPROLE_SLAVE_LATENCY 0x313 //!< Update Parameter Slave Latency. Range: 0 - 499. Read/Write. Size is uint16. Default is 0.
  63. #define GAPROLE_TIMEOUT_MULTIPLIER 0x314 //!< Update Parameter Timeout Multiplier (n * 10ms). Range: 100ms to 32 seconds (0x000a - 0x0c80). Read/Write. Size is uint16. Default is 1000.
  64. #define GAPROLE_CONN_BD_ADDR 0x315 //!< Address of connected device. Read only. Size is uint8[B_MAX_ADV_LEN]. Set to all zeros when not connected.
  65. /** @} End GAPROLE_PROFILE_PARAMETERS */
  66. /*-------------------------------------------------------------------
  67. * TYPEDEFS
  68. */
  69. /**
  70. * GAP Peripheral + Broadcaster Role States.
  71. */
  72. typedef enum
  73. {
  74. GAPROLE_INIT = 0, //!< Waiting to be started
  75. GAPROLE_STARTED, //!< Started but not advertising
  76. GAPROLE_ADVERTISING, //!< Currently Advertising
  77. GAPROLE_WAITING, //!< Device is started but not advertising, is in waiting period before advertising again
  78. GAPROLE_WAITING_AFTER_TIMEOUT, //!< Device just timed out from a connection but is not yet advertising, is in waiting period before advertising again
  79. GAPROLE_CONNECTED, //!< In a connection
  80. GAPROLE_CONNECTED_ADV, //!< In a connection and advertising
  81. GAPROLE_ERROR //!< Error occurred - invalid state
  82. } gaprole_States_t;
  83. /*-------------------------------------------------------------------
  84. * MACROS
  85. */
  86. /*-------------------------------------------------------------------
  87. * Profile Callbacks
  88. */
  89. /**
  90. * Callback when the device has been started. Callback event to
  91. * the Notify of a state change.
  92. */
  93. typedef void (*gapRolesStateNotify_t)( gaprole_States_t newState );
  94. /**
  95. * Callback when the device has read an new RSSI value during a connection.
  96. */
  97. typedef void (*gapRolesRssiRead_t)( int8 newRSSI );
  98. /**
  99. * Callback structure - must be setup by the application and used when gapRoles_StartDevice() is called.
  100. */
  101. typedef struct
  102. {
  103. gapRolesStateNotify_t pfnStateChange; //!< Whenever the device changes state
  104. gapRolesRssiRead_t pfnRssiRead; //!< When a valid RSSI is read from controller
  105. } gapRolesCBs_t;
  106. /*-------------------------------------------------------------------
  107. * API FUNCTIONS
  108. */
  109. /**
  110. * @defgroup GAPROLES_PERIPHERAL_BROADCASTER_API GAP Peripheral + Broadcaster Role API Functions
  111. *
  112. * @{
  113. */
  114. /**
  115. * @brief Set a GAP Role parameter.
  116. *
  117. * NOTE: You can call this function with a GAP Parameter ID and it will set the
  118. * GAP Parameter. GAP Parameters are defined in (gap.h). Also,
  119. * the "len" field must be set to the size of a "uint16" and the
  120. * "pValue" field must point to a "uint16".
  121. *
  122. * @param param - Profile parameter ID: @ref GAPROLE_PROFILE_PARAMETERS
  123. * @param len - length of data to write
  124. * @param pValue - pointer to data to write. This is dependent on
  125. * the parameter ID and WILL be cast to the appropriate
  126. * data type (example: data type of uint16 will be cast to
  127. * uint16 pointer).
  128. *
  129. * @return SUCCESS or INVALIDPARAMETER (invalid paramID)
  130. */
  131. extern bStatus_t GAPRole_SetParameter( uint16 param, uint8 len, void *pValue );
  132. /**
  133. * @brief Get a GAP Role parameter.
  134. *
  135. * NOTE: You can call this function with a GAP Parameter ID and it will get a
  136. * GAP Parameter. GAP Parameters are defined in (gap.h). Also, the
  137. * "pValue" field must point to a "uint16".
  138. *
  139. * @param param - Profile parameter ID: @ref GAPROLE_PROFILE_PARAMETERS
  140. * @param pValue - pointer to location to get the value. This is dependent on
  141. * the parameter ID and WILL be cast to the appropriate
  142. * data type (example: data type of uint16 will be cast to
  143. * uint16 pointer).
  144. *
  145. * @return SUCCESS or INVALIDPARAMETER (invalid paramID)
  146. */
  147. extern bStatus_t GAPRole_GetParameter( uint16 param, void *pValue );
  148. /**
  149. * @brief Does the device initialization. Only call this function once.
  150. *
  151. * @param pAppCallbacks - pointer to application callbacks.
  152. *
  153. * @return SUCCESS or bleAlreadyInRequestedMode
  154. */
  155. extern bStatus_t GAPRole_StartDevice( gapRolesCBs_t *pAppCallbacks );
  156. /**
  157. * @brief Terminates the existing connection.
  158. *
  159. * @return SUCCESS or bleIncorrectMode
  160. */
  161. extern bStatus_t GAPRole_TerminateConnection( void );
  162. /**
  163. * @} End GAPROLES_PERIPHERAL_BROADCASTER_API
  164. */
  165. /*-------------------------------------------------------------------
  166. * TASK FUNCTIONS - Don't call these. These are system functions.
  167. */
  168. /**
  169. * @internal
  170. *
  171. * @brief Initialization function for the GAP Role Task.
  172. * This is called during initialization and should contain
  173. * any application specific initialization (ie. hardware
  174. * initialization/setup, table initialization, power up
  175. * notificaiton ... ).
  176. *
  177. * @param the ID assigned by OSAL. This ID should be
  178. * used to send messages and set timers.
  179. *
  180. * @return void
  181. */
  182. extern void GAPRole_Init( uint8 task_id );
  183. /**
  184. * @internal
  185. *
  186. * @brief GAP Role Task event processor.
  187. * This function is called to process all events for the task.
  188. * Events include timers, messages and any other user defined
  189. * events.
  190. *
  191. * @param task_id - The OSAL assigned task ID.
  192. * @param events - events to process. This is a bit map and can
  193. * contain more than one event.
  194. *
  195. * @return events not processed
  196. */
  197. extern uint16 GAPRole_ProcessEvent( uint8 task_id, uint16 events );
  198. /*-------------------------------------------------------------------
  199. -------------------------------------------------------------------*/
  200. #ifdef __cplusplus
  201. }
  202. #endif
  203. #endif /* PERIPHERAL_BROADCASTER_H */