nrf_gzp.h 22 KB

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