nrf_gzp.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. /* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
  2. *
  3. * The information contained herein is property of Nordic Semiconductor ASA.
  4. * Terms and conditions of usage are described in detail in NORDIC
  5. * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
  6. *
  7. * Licensees are granted free, non-transferable use of the information. NO
  8. * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
  9. * the file.
  10. *
  11. * $LastChangedRevision: 25678 $
  12. */
  13. /**
  14. * @file
  15. * @brief Gazell Pairing API
  16. */
  17. #ifndef __GZP_H
  18. #define __GZP_H
  19. #include "nrf.h"
  20. #include "nrf_gzp_config.h"
  21. #include <stdbool.h>
  22. /**
  23. * @defgroup gzp_02_api Application Programming Interface (API)
  24. * @{
  25. * @ingroup modules_02_gzp
  26. * @brief Gazell Pairing API.
  27. */
  28. /******************************************************************************/
  29. /** @name Pairing configuration defines
  30. * @{ */
  31. /******************************************************************************/
  32. #define GZP_PAIRING_PIPE 0 ///< Pipe reserved for initial pairing communication.
  33. #define GZP_DATA_PIPE 1 ///< Pipe reserved for GZP encrypted data communication (one pipe only).
  34. #define GZP_TX_RX_TRANS_DELAY 10 ///< Time to wait between request and fetch packets in RX_PERIODS (2 timeslot periods)
  35. #define GZP_SYSTEM_ADDRESS_WIDTH 4 ///< Must equal Gazell base address length.
  36. #define GZP_VALIDATION_ID {0x32, 0x53, 0x66} ///< Validation ID. Required to be shared by Host and Device. Not a secret.
  37. #define GZP_VALIDATION_ID_LENGTH 3 ///< Validation ID length in bytes.
  38. #define GZP_HOST_ID_LENGTH 5 ///< Host ID length in bytes.
  39. #define GZP_SESSION_TOKEN_LENGTH GZP_HOST_ID_LENGTH ///< Session token length in bytes.
  40. #define GZP_DYN_KEY_LENGTH (16 - GZP_VALIDATION_ID_LENGTH) ///< Dynamic key length in bytes.
  41. #define GZP_HOST_RX_POWER_THRESHOLD -64 ///< RSSI threshold for when signal strength in RX packet power is high enough.
  42. /** @} */
  43. /******************************************************************************/
  44. /** @name Device -> Host packet definitions
  45. * @{ */
  46. /******************************************************************************/
  47. #define GZP_CMD_HOST_ADDRESS_REQ_PAYLOAD_LENGTH 1 ///< "Host address request" packet, payload length
  48. #define GZP_CMD_HOST_ADDRESS_FETCH_PAYLOAD_LENGTH 1 ///< "Host address fetch" packet, payload length
  49. #define GZP_CMD_HOST_ID_REQ_SESSION_TOKEN 1 ///< "Host ID request" packet, session token position
  50. #define GZP_CMD_HOST_ID_REQ_PAYLOAD_LENGTH (GZP_CMD_HOST_ID_REQ_SESSION_TOKEN + GZP_SESSION_TOKEN_LENGTH) ///< "Host ID request" payload length
  51. #if (GZP_CMD_HOST_ID_REQ_PAYLOAD_LENGTH > 17)
  52. #error GZP_SESSION_TOKEN_LENGTH too long.
  53. #endif
  54. #define GZP_CMD_HOST_ID_FETCH_VALIDATION_ID 1 ///< "Host ID fetch" packet
  55. #define GZP_CMD_HOST_ID_FETCH_PAYLOAD_LENGTH (GZP_CMD_HOST_ID_FETCH_VALIDATION_ID + GZP_VALIDATION_ID_LENGTH) ///< "Host ID fetch" payload length
  56. #if (GZP_CMD_HOST_ID_FETCH_PAYLOAD_LENGTH > 17)
  57. #error GZP_VALIDATION_ID_LENGTH set too long.
  58. #endif
  59. #define GZP_CMD_KEY_UPDATE_PREPARE_PAYLOAD_LENGTH 1 ///< "Key update prepare" payload length
  60. #define GZP_CMD_KEY_UPDATE_VALIDATION_ID 1 ///< "Key update" packet, validation ID position
  61. #define GZP_CMD_KEY_UPDATE_NEW_KEY (GZP_CMD_KEY_UPDATE_VALIDATION_ID + GZP_VALIDATION_ID_LENGTH) ///< "Key update" packet, new key position
  62. #define GZP_CMD_KEY_UPDATE_PAYLOAD_LENGTH (GZP_CMD_KEY_UPDATE_NEW_KEY + GZP_DYN_KEY_LENGTH) ///< "Key update" packet, payload length
  63. #if (GZP_CMD_KEY_UPDATE_PAYLOAD_LENGTH > 17)
  64. #error Sum (GZP_VALIDATION_ID_LENGTH + GZP_DYN_KEY_LENGTH) too high.
  65. #endif
  66. #define GZP_CMD_ENCRYPTED_USER_DATA_VALIDATION_ID 1 ///< "Encrypted user data" packet, validation ID position
  67. #define GZP_CMD_ENCRYPTED_USER_DATA_PAYLOAD ((GZP_CMD_ENCRYPTED_USER_DATA_VALIDATION_ID + GZP_VALIDATION_ID_LENGTH)) ///< "Encrypted user data" packet, user data position
  68. #define GZP_ENCRYPTED_USER_DATA_PACKET_OVERHEAD ( GZP_CMD_ENCRYPTED_USER_DATA_VALIDATION_ID + GZP_VALIDATION_ID_LENGTH) ///< "Encrypted user data" packet, packet overhead length
  69. #define GZP_ENCRYPTED_USER_DATA_MAX_LENGTH (17 - GZP_ENCRYPTED_USER_DATA_PACKET_OVERHEAD) ///< "Encrypted user data" packet, max payload length
  70. #if(GZP_MAX_FW_PAYLOAD_LENGTH < 17)
  71. #error GZP_MAX_FW_PAYLOAD_LENGTH must be greater or equal to 17.
  72. #endif
  73. #define GZP_CMD_FETCH_RESP_PAYLOAD_LENGTH 1 ///< General "fetch response" packet, payload_length
  74. /** @} */
  75. /******************************************************************************/
  76. /** @name Host -> Device packet definitions
  77. * @{ */
  78. /******************************************************************************/
  79. #define GZP_CMD_HOST_ADDRESS_RESP_ADDRESS 1 ///< "Host address fetch" response packet, address position
  80. #define GZP_CMD_HOST_ADDRESS_RESP_PAYLOAD_LENGTH (GZP_CMD_HOST_ADDRESS_RESP_ADDRESS + GZP_SYSTEM_ADDRESS_WIDTH) ///< ///< "Host address fetch" response packet, payload length
  81. #if(GZP_MAX_ACK_PAYLOAD_LENGTH < GZP_CMD_HOST_ADDRESS_RESP_PAYLOAD_LENGTH)
  82. #error GZP_MAX_ACK_PAYLOAD_LENGTH must be greater or equal to GZP_CMD_HOST_ADDRESS_RESP_PAYLOAD_LENGTH.
  83. #endif
  84. #define GZP_CMD_HOST_ID_FETCH_RESP_VALIDATION_ID 1 ///< "Host ID fetch" response packet, validation ID position
  85. #define GZP_CMD_HOST_ID_FETCH_RESP_STATUS (GZP_CMD_HOST_ID_FETCH_RESP_VALIDATION_ID + GZP_VALIDATION_ID_LENGTH) ///< "Host ID fetch" response packet, status position
  86. #define GZP_CMD_HOST_ID_FETCH_RESP_HOST_ID (GZP_CMD_HOST_ID_FETCH_RESP_STATUS + 1) ///< "Host ID fetch" response packet, Host ID position
  87. #define GZP_CMD_HOST_ID_FETCH_RESP_PAYLOAD_LENGTH (GZP_CMD_HOST_ID_FETCH_RESP_HOST_ID + GZP_HOST_ID_LENGTH) ///< "Host ID fetch" response packet, payload length
  88. #if(GZP_MAX_ACK_PAYLOAD_LENGTH < GZP_CMD_HOST_ID_FETCH_RESP_PAYLOAD_LENGTH)
  89. #error GZP_MAX_ACK_PAYLOAD_LENGTH must be greater or equal to GZP_CMD_HOST_ID_FETCH_RESP_PAYLOAD_LENGTH.
  90. #endif
  91. #define GZP_CMD_KEY_UPDATE_PREPARE_RESP_SESSION_TOKEN 1 ///< "Key update prepare" response packet, session token position
  92. #define GZP_CMD_KEY_UPDATE_PREPARE_RESP_PAYLOAD_LENGTH (GZP_CMD_KEY_UPDATE_PREPARE_RESP_SESSION_TOKEN + GZP_SESSION_TOKEN_LENGTH) ///< "Key update prepare" response packet, payload length position
  93. #if(GZP_MAX_ACK_PAYLOAD_LENGTH < GZP_CMD_KEY_UPDATE_PREPARE_RESP_PAYLOAD_LENGTH)
  94. #error GZP_MAX_ACK_PAYLOAD_LENGTH must be greater or equal to GZP_CMD_KEY_UPDATE_PREPARE_RESP_PAYLOAD_LENGTH.
  95. #endif
  96. #define GZP_CMD_ENCRYPTED_USER_DATA_RESP_SESSION_TOKEN 1 ///< "Encrypted user data" response packet, session token position
  97. #define GZP_CMD_ENCRYPTED_USER_DATA_RESP_VALIDATION_ID (GZP_CMD_ENCRYPTED_USER_DATA_RESP_SESSION_TOKEN + GZP_SESSION_TOKEN_LENGTH) ///< "Encrypted user data" response packet, validation ID position
  98. #define GZP_CMD_ENCRYPTED_USER_DATA_RESP_PAYLOAD_LENGTH (GZP_CMD_ENCRYPTED_USER_DATA_RESP_VALIDATION_ID + GZP_VALIDATION_ID_LENGTH) ///< "Encrypted user data" response packet, payload length position
  99. #if(GZP_MAX_ACK_PAYLOAD_LENGTH < GZP_CMD_ENCRYPTED_USER_DATA_RESP_PAYLOAD_LENGTH)
  100. #error GZP_MAX_ACK_PAYLOAD_LENGTH must be greater or equal to GZP_CMD_ENCRYPTED_USER_DATA_RESP_PAYLOAD_LENGTH.
  101. #endif
  102. #if(GZP_VALIDATION_ID_LENGTH > GZP_HOST_ID_LENGTH)
  103. #error GZP_HOST_ID_LENGTH should be greater or equal to GZP_VALIDATION_ID_LENGTH.
  104. #endif
  105. #if(GZP_SESSION_TOKEN_LENGTH != GZP_HOST_ID_LENGTH)
  106. #error GZP_SESSION_TOKEN_LENGTH must equal GZP_HOST_ID_LENGTH.
  107. #endif
  108. #ifdef GZLL_CRYPT_ENABLE
  109. #error Gazell encryption can not be enabled when using the Gazell pairing library. \
  110. GZLL_CRYPT_ENABLE must be undefined.
  111. #endif
  112. /** @} */
  113. /******************************************************************************/
  114. /** @name Typedefs
  115. * @{ */
  116. /******************************************************************************/
  117. /**
  118. * @enum gzp_key_select_t
  119. * @brief Enumerator used for selecting the key to be used for encryption.
  120. */
  121. typedef enum
  122. {
  123. GZP_ID_EXCHANGE, ///< "Secret key" only
  124. GZP_KEY_EXCHANGE, ///< "Secret key" and "Host ID"
  125. GZP_DATA_EXCHANGE ///< "Dynamic key" and "Host ID"
  126. } gzp_key_select_t;
  127. /**
  128. * @enum gzp_cmd_t
  129. * @brief Enumerator used in the first payload byte of each packet to
  130. * indicate the packet type.
  131. */
  132. typedef enum
  133. {
  134. GZP_CMD_HOST_ADDRESS_REQ = 0, ///< Host address request
  135. GZP_CMD_HOST_ADDRESS_FETCH, ///< Host address fetch
  136. GZP_CMD_HOST_ID_REQ, ///< Host ID request
  137. GZP_CMD_HOST_ID_FETCH, ///< Host ID fetch request
  138. GZP_CMD_KEY_UPDATE_PREPARE, ///< Key update prepare
  139. GZP_CMD_KEY_UPDATE, ///< Key update
  140. GZP_CMD_ENCRYPTED_USER_DATA, ///< Encrypted user data
  141. GZP_CMD_FETCH_RESP, ///< Fetch response
  142. GZP_CMD_HOST_ADDRESS_RESP, ///< Host address response
  143. GZP_CMD_HOST_ID_FETCH_RESP, ///< Host ID fetch response
  144. GZP_CMD_KEY_UPDATE_PREPARE_RESP, ///< Key update prepare
  145. GZP_CMD_ENCRYPTED_USER_DATA_RESP, ///< Encrypted user data response
  146. } gzp_cmd_t;
  147. /**
  148. * @enum gzp_id_req_res_t
  149. * @brief Enumerator used to identify the state of the current
  150. * Host ID request.
  151. */
  152. typedef enum
  153. {
  154. GZP_ID_RESP_PENDING, ///< ID response pending
  155. GZP_ID_RESP_GRANTED, ///< ID response granted
  156. GZP_ID_RESP_REJECTED, ///< ID response rejected
  157. GZP_ID_RESP_FAILED, ///< ID response failed
  158. GZP_ID_RESP_NO_REQUEST ///< Default value. No ID request has yet been received.
  159. } gzp_id_req_res_t;
  160. /** @} */
  161. /******************************************************************************/
  162. /** @name Misc. function prototypes
  163. * @{ */
  164. /******************************************************************************/
  165. /**
  166. * Set the session token.
  167. *
  168. * @param token Pointer to the session token to set.
  169. */
  170. void gzp_crypt_set_session_token(const uint8_t *token);
  171. /**
  172. * Get the session token.
  173. *
  174. * @param dst_token Pointer to write the session token.
  175. */
  176. void gzp_crypt_get_session_token(uint8_t *dst_token);
  177. /**
  178. * Set the dynamic key.
  179. *
  180. * @param dyn_key Pointer to the dynamic key to set.
  181. */
  182. void gzp_crypt_set_dyn_key(const uint8_t* dyn_key);
  183. /**
  184. * Get the dynamic key.
  185. *
  186. * @param dst_key Pointer to write the dynamic key too.
  187. */
  188. void gzp_crypt_get_dyn_key(uint8_t *dst_key);
  189. /**
  190. * Set the Host ID.
  191. *
  192. * @param src Pointer to the Host ID to set.
  193. */
  194. static void gzp_set_host_id(const uint8_t* src);
  195. /**
  196. * Get the Host ID.
  197. *
  198. * @param dst Pointer to write the Host ID to.
  199. */
  200. void gzp_get_host_id(uint8_t *dst);
  201. /**
  202. * Selecting what key-set that should be used when encrypting data
  203. * using gzp_crypt().
  204. *
  205. * @param key_select Key-set to use.
  206. */
  207. void gzp_crypt_select_key(gzp_key_select_t key_select);
  208. /**
  209. * Encypt / decrypt data.
  210. *
  211. * The current "session token" will be used as initialization vector (IV).
  212. * The AES key to be used is selected by gzp_crypt_select_key().
  213. * AES is a symmetric encryption scheme, this function can be used
  214. * to perform both encryption and decryption.
  215. *
  216. * @param dst Destination to write encrypted data to. Should be 16 bytes long.
  217. * @param src Source data to encrypt.
  218. * @param length Length in bytes of src.
  219. */
  220. void gzp_crypt(uint8_t* dst, const uint8_t* src, uint8_t length);
  221. /**
  222. * Compare the *src_id with a pre-defined validation ID.
  223. *
  224. * @param src_id Pointer to the source validation ID to compare to.
  225. *
  226. * @retval true If *src_id equals the pre-defined ID.
  227. * @retval false If *src_id does not equal the pre-defined ID.
  228. */
  229. bool gzp_validate_id(const uint8_t *src_id);
  230. /**
  231. * Add the pre-defined validation ID to dst_id.
  232. * GZP_VALIDATION_ID_LENGTH bytes will be added.
  233. *
  234. * @param dst_id Pointer to add the GZP validation ID to.
  235. */
  236. void gzp_add_validation_id(uint8_t *dst_id);
  237. /**
  238. * Generate random bytes.
  239. *
  240. * @param dst Destination to write the random bytes to.
  241. * @param n Number of bytes to generate.
  242. */
  243. void gzp_random_numbers_generate(uint8_t *dst, uint8_t n);
  244. /**
  245. * Update the channel table and the system address.
  246. *
  247. * The channel table is updated to pseudo-random set generated using the
  248. * system address. The channel table still includes GZP_CHANNEL_MAX and
  249. * GZP_CHANNEL_MIN.
  250. * The system address is applied to base address 1 and therefore applies
  251. * to pipes 1-7.
  252. *
  253. * @param system_address Pointer to the system_address to set.
  254. *
  255. * @retval true If theradio parameters were updated successfully.
  256. * @retval false If there was an error updated the radio parameters.
  257. */
  258. bool gzp_update_radio_params(const uint8_t *system_address);
  259. /**
  260. * Generate a set of channels from a 4 byte address.
  261. *
  262. * @param ch_dst Destination to write the channel set to. The channel set
  263. * includes GZP_CHANNEL_MAX and GZP_CHANNEL_MIN.
  264. * @param address Four byte address to generate the channel set from.
  265. * @param channel_set_size Size of the channel set to generate.
  266. */
  267. void gzp_generate_channels(uint8_t *ch_dst, const uint8_t * address, uint8_t channel_set_size);
  268. /**
  269. * Perform an XOR on two byte strings.
  270. *
  271. * @param dst Destination to write the result to. Should be of size length.
  272. * @param src
  273. * @param pad
  274. * @param length Number of bytes to perform the XOR operation on.
  275. */
  276. void gzp_xor_cipher(uint8_t* dst, const uint8_t* src, const uint8_t* pad, uint8_t length);
  277. /******************************************************************************/
  278. /** @name Common Device and Host functions
  279. * @{ */
  280. /******************************************************************************/
  281. /**
  282. * Initialization function. This function initializes the Gazell Pairing Library.
  283. * This function must be called before any of the other Gazell Pairing Library functions are
  284. * used and must be called @b after gzll_init() is called.
  285. *
  286. */
  287. void gzp_init(void);
  288. /**
  289. * Function for erasing all pairing data.
  290. */
  291. void gzp_erase_pairing_data(void);
  292. /**
  293. * Disable Gazell and sleep while waiting for nrf_gzll_disabled callback.
  294. */
  295. void nrf_gzp_disable_gzll(void);
  296. /**
  297. Function for cancelling an ongoing (pending) "Host ID request".
  298. After calling this function the "Host ID request" status will go to
  299. "ID request Idle".
  300. */
  301. void gzp_id_req_cancel(void);
  302. /**
  303. * Flush the GZLL RX FIFO for a specific pipe while GZLL is disabled.
  304. *
  305. * @param pipe Pipe.
  306. */
  307. void nrf_gzp_flush_rx_fifo(uint32_t pipe);
  308. /**
  309. @name Device functions
  310. */
  311. /**
  312. * Check whether current GZP packet transaction has completed.
  313. *
  314. * @retval true
  315. * @retval false
  316. */
  317. bool nrf_gzp_tx_complete(void);
  318. /**
  319. * Check whether previous GZP packet transaction was successful.
  320. *
  321. * @retval true
  322. * @retval false
  323. */
  324. bool nrf_gzp_tx_success(void);
  325. /**
  326. * Reset tx_complete status.
  327. */
  328. void nrf_gzp_reset_tx_complete(void);
  329. /**
  330. * Reset tx_success status.
  331. */
  332. void nrf_gzp_reset_tx_success(void);
  333. /**
  334. * Function to check whether a Device has existing pairing data, implying that it is
  335. * paired to a Host.
  336. *
  337. * @retval -2 The pairing database is empty.
  338. * @retval -1 The device has a system address but no Host ID.
  339. * @retval >=0 The device has a system address and HostID at this index value in the database.
  340. */
  341. int8_t gzp_get_pairing_status(void);
  342. /**
  343. Function for sending a "system address" request to a Host.
  344. When calling this function the Device will attempt acquiring the "system address" from
  345. any Host within close proximity.
  346. If a host is located within close proximity and pairing is enabled in the Host,
  347. a "system address" will be sent in return to the Device.
  348. The new "system address" will apply immediately in the Device, and the new "system address"
  349. will be stored in non volatile (NV) memory.
  350. Note. Using OTP devices limits the number of times a new "system address" can
  351. be stored in NV memory.
  352. @return
  353. @retval true if new "system address" was received from a Host.
  354. @retval false if no "system address" was received from a Host.
  355. */
  356. bool gzp_address_req_send(void);
  357. /**
  358. Function for sending a "Host ID request" to a Host.
  359. The "Host ID" is needed to be able to send encrypted data using
  360. gzp_crypt_data_send().
  361. The request will be sent using the "system address" previously received using
  362. gzp_address_req_send().
  363. It is not required that the Host is within close proximity in order to acquire the
  364. "Host ID".
  365. The new "Host ID" will apply immediately for the Device, and the new "Host ID"
  366. will be stored in non volatile (NV) memory.
  367. Note. Using OTP devices limits the number of times a new "Host ID" can
  368. be stored in NV memory.
  369. @return
  370. @retval GZP_ID_RESP_PENDING if a "Host ID request" has been sent to the Host, but the Host application has
  371. not yet decided whether to Grant or Reject the "ID request".
  372. @retval GZP_ID_RESP_GRANTED if the "Host ID" has been received from the Host. The received "Host ID" will be stored
  373. in non volatile memory.
  374. @retval GZP_ID_RESP_REJECTED if the Host application has rejected the "Host ID request".
  375. @retval GZP_ID_RESP_FAILED if failing to send a request or receive a response from the Host.
  376. */
  377. gzp_id_req_res_t gzp_id_req_send(void);
  378. /**
  379. Function for sending encrypted user data to the Host.
  380. Before any data can be sent the Device must acquire both the Host's
  381. "system address" by using gzp_address_req_send() and the "Host ID" by using
  382. gzp_id_req_send().
  383. @param *src is a pointer to the data packet to be sent.
  384. @param length is the length of the data packet to be sent.
  385. @return
  386. @retval true if the data was successfully transmitted and decrypted by the Host.
  387. @retval false if data transmission failed or Host failed to decryption data correctly.
  388. */
  389. bool gzp_crypt_data_send(const uint8_t *src, uint8_t length);
  390. /**
  391. @name Host functions
  392. */
  393. /**
  394. Function for enabling/disabling pairing in a host. When pairing is enabled the host will
  395. be monitoring for "system address" and "Host ID" requests from Devices.
  396. A "system address request" received from a Device will always be granted.
  397. When a "host ID request" has been received, the Host application have to grant,
  398. reject or cancel this by using one of the following functions:
  399. - gzp_id_req_grant()
  400. - gzp_id_req_reject()
  401. - gzp_id_req_cancel()
  402. @param enable
  403. @arg true enables pairing.
  404. @arg false disables pairing.
  405. */
  406. void gzp_pairing_enable(bool enable);
  407. /**
  408. * Execute the Gazell Pairing Library Host operation.
  409. *
  410. * This function must be called regularly by the Host application.
  411. */
  412. void gzp_host_execute(void);
  413. /**
  414. * Address exchanged check.
  415. *
  416. * @retval true If a "system address" was delivered to a requesting Device during the
  417. * previous call to gzp_host_execute();
  418. * @retval false Otherwise.
  419. */
  420. bool gzp_address_exchanged(void);
  421. /**
  422. Function for checking if a "Host ID request" has been received from a Device.
  423. If a request has been received, the Pairing library will enter "ID request pending"
  424. state.
  425. The application is responsible for responding to this request by calling
  426. one of the following functions:
  427. - gzp_id_req_grant()
  428. - gzp_id_req_reject()
  429. - gzp_id_req_cancel()
  430. @retval true if a "Host ID request" has been received (internal state is "ID request pending")
  431. @retval false if no "Host ID request" has been received (internal state is "ID request idle")
  432. */
  433. bool gzp_id_req_received(void);
  434. /**
  435. Function for rejecting the previously received "Host ID request". This function should be called
  436. only when a "Host ID request" has been received (internal state is "ID request pending").
  437. The internal state of the Pairing library will remain "ID request pending" until the a "reject" message
  438. has been successfully transmitted to the requesting Device. After this the internal state will
  439. change to "ID request idle".
  440. */
  441. void gzp_id_req_reject(void);
  442. /**
  443. * Function for granting the previously received "Host ID request". This function should be called
  444. only when a "Host ID request" has been received (internal state is "ID request pending").
  445. The internal state of the Pairing library will remain "ID request pending" until the "Host ID" has
  446. been successfully transmitted to the requesting Device. After this the internal state will
  447. change to "ID request idle".
  448. */
  449. void gzp_id_req_grant(void);
  450. /**
  451. * Check if user data has been received.
  452. *
  453. * @retval true If encrypted user data has been received.
  454. * @retval false Otherwise.
  455. */
  456. bool gzp_crypt_user_data_received(void);
  457. /**
  458. Function for reading encrypted user data.
  459. Note that the read user data will be automatically decrypted. Only data
  460. that was decrypted correctly will be presented.
  461. @param dst* is a pointer to where the received data will be written.
  462. @param length* is a pointer for returning the number of bytes received. Only 1 byte will
  463. be writtem to length*.
  464. @return
  465. @retval true if data has been received and is written to dst*
  466. @retval false if no data has been received.
  467. */
  468. bool gzp_crypt_user_data_read(uint8_t* dst, uint8_t* length);
  469. /**
  470. Function emulating behavior of gzll_rx_start() in legeacy nRF24xx Gaell
  471. linbrary.
  472. This functions sets Gazell in Host mode and starts reception (enable).
  473. */
  474. void gzll_rx_start(void);
  475. /** @} */
  476. /** @} */
  477. /** @} */
  478. #endif