nRF Connect SDK API 0.1.0
Loading...
Searching...
No Matches
gzp.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5 */
6
12#ifndef __GZP_H
13#define __GZP_H
14
15#include <stdint.h>
16#include <stdbool.h>
17#include <nrf_gzll.h>
18#if defined(CONFIG_GAZELL_PAIRING_USER_CONFIG_ENABLE)
19#include CONFIG_GAZELL_PAIRING_USER_CONFIG_FILE
20#else
21#include "gzp_config.h"
22#endif /* CONFIG_GAZELL_PAIRING_USER_CONFIG_ENABLE */
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28
35/******************************************************************************/
39/******************************************************************************/
40
42#define GZP_PAIRING_PIPE 0
44#define GZP_DATA_PIPE 1
46#define GZP_TX_RX_TRANS_DELAY 10
48#define GZP_SYSTEM_ADDRESS_WIDTH 4
49
50
52#define GZP_VALIDATION_ID {0x32, 0x53, 0x66}
54#define GZP_VALIDATION_ID_LENGTH 3
56#define GZP_HOST_ID_LENGTH 5
58#define GZP_SESSION_TOKEN_LENGTH GZP_HOST_ID_LENGTH
60#define GZP_DYN_KEY_LENGTH (16 - GZP_VALIDATION_ID_LENGTH)
61
63#define GZP_HOST_RX_POWER_THRESHOLD -64
64
68/******************************************************************************/
72/******************************************************************************/
73
75#define GZP_CMD_HOST_ADDRESS_REQ_PAYLOAD_LENGTH 1
76
78#define GZP_CMD_HOST_ADDRESS_FETCH_PAYLOAD_LENGTH 1
79
81#define GZP_CMD_HOST_ID_REQ_SESSION_TOKEN 1
82/* "Host ID request" payload length */
83#define GZP_CMD_HOST_ID_REQ_PAYLOAD_LENGTH (GZP_CMD_HOST_ID_REQ_SESSION_TOKEN + \
84 GZP_SESSION_TOKEN_LENGTH)
85
86#if (GZP_CMD_HOST_ID_REQ_PAYLOAD_LENGTH > 17)
87#error GZP_SESSION_TOKEN_LENGTH too long.
88#endif
89
91#define GZP_CMD_HOST_ID_FETCH_VALIDATION_ID 1
93#define GZP_CMD_HOST_ID_FETCH_PAYLOAD_LENGTH (GZP_CMD_HOST_ID_FETCH_VALIDATION_ID + \
94 GZP_VALIDATION_ID_LENGTH)
95
96#if (GZP_CMD_HOST_ID_FETCH_PAYLOAD_LENGTH > 17)
97#error GZP_VALIDATION_ID_LENGTH set too long.
98#endif
99
101#define GZP_CMD_KEY_UPDATE_PREPARE_PAYLOAD_LENGTH 1
102
104#define GZP_CMD_KEY_UPDATE_VALIDATION_ID 1
106#define GZP_CMD_KEY_UPDATE_NEW_KEY (GZP_CMD_KEY_UPDATE_VALIDATION_ID + GZP_VALIDATION_ID_LENGTH)
108#define GZP_CMD_KEY_UPDATE_PAYLOAD_LENGTH (GZP_CMD_KEY_UPDATE_NEW_KEY + GZP_DYN_KEY_LENGTH)
109
110#if (GZP_CMD_KEY_UPDATE_PAYLOAD_LENGTH > 17)
111#error Sum (GZP_VALIDATION_ID_LENGTH + GZP_DYN_KEY_LENGTH) too high.
112#endif
113
114
116#define GZP_CMD_ENCRYPTED_USER_DATA_VALIDATION_ID 1
118#define GZP_CMD_ENCRYPTED_USER_DATA_PAYLOAD (GZP_CMD_ENCRYPTED_USER_DATA_VALIDATION_ID + \
119 GZP_VALIDATION_ID_LENGTH)
121#define GZP_ENCRYPTED_USER_DATA_PACKET_OVERHEAD (GZP_CMD_ENCRYPTED_USER_DATA_VALIDATION_ID + \
122 GZP_VALIDATION_ID_LENGTH)
124#define GZP_ENCRYPTED_USER_DATA_MAX_LENGTH (17 - GZP_ENCRYPTED_USER_DATA_PACKET_OVERHEAD)
125
126#if (GZP_MAX_FW_PAYLOAD_LENGTH < 17)
127#error GZP_MAX_FW_PAYLOAD_LENGTH must be greater or equal to 17.
128#endif
129
131#define GZP_CMD_FETCH_RESP_PAYLOAD_LENGTH 1
132
136/******************************************************************************/
140/******************************************************************************/
141
143#define GZP_CMD_HOST_ADDRESS_RESP_ADDRESS 1
145#define GZP_CMD_HOST_ADDRESS_RESP_PAYLOAD_LENGTH (GZP_CMD_HOST_ADDRESS_RESP_ADDRESS + \
146 GZP_SYSTEM_ADDRESS_WIDTH)
147
148#if (GZP_MAX_ACK_PAYLOAD_LENGTH < GZP_CMD_HOST_ADDRESS_RESP_PAYLOAD_LENGTH)
149#error GZP_MAX_ACK_PAYLOAD_LENGTH must be greater or equal to \
150 GZP_CMD_HOST_ADDRESS_RESP_PAYLOAD_LENGTH.
151#endif
152
153
155#define GZP_CMD_HOST_ID_FETCH_RESP_VALIDATION_ID 1
157#define GZP_CMD_HOST_ID_FETCH_RESP_STATUS (GZP_CMD_HOST_ID_FETCH_RESP_VALIDATION_ID + \
158 GZP_VALIDATION_ID_LENGTH)
160#define GZP_CMD_HOST_ID_FETCH_RESP_HOST_ID (GZP_CMD_HOST_ID_FETCH_RESP_STATUS + 1)
162#define GZP_CMD_HOST_ID_FETCH_RESP_PAYLOAD_LENGTH (GZP_CMD_HOST_ID_FETCH_RESP_HOST_ID + \
163 GZP_HOST_ID_LENGTH)
164
165#if (GZP_MAX_ACK_PAYLOAD_LENGTH < GZP_CMD_HOST_ID_FETCH_RESP_PAYLOAD_LENGTH)
166#error GZP_MAX_ACK_PAYLOAD_LENGTH must be greater or equal to \
167 GZP_CMD_HOST_ID_FETCH_RESP_PAYLOAD_LENGTH.
168#endif
169
170
172#define GZP_CMD_KEY_UPDATE_PREPARE_RESP_SESSION_TOKEN 1
174#define GZP_CMD_KEY_UPDATE_PREPARE_RESP_PAYLOAD_LENGTH \
175 (GZP_CMD_KEY_UPDATE_PREPARE_RESP_SESSION_TOKEN + \
176 GZP_SESSION_TOKEN_LENGTH)
177
178#if (GZP_MAX_ACK_PAYLOAD_LENGTH < GZP_CMD_KEY_UPDATE_PREPARE_RESP_PAYLOAD_LENGTH)
179#error GZP_MAX_ACK_PAYLOAD_LENGTH must be greater or equal to \
180 GZP_CMD_KEY_UPDATE_PREPARE_RESP_PAYLOAD_LENGTH.
181#endif
182
183
185#define GZP_CMD_ENCRYPTED_USER_DATA_RESP_SESSION_TOKEN 1
187#define GZP_CMD_ENCRYPTED_USER_DATA_RESP_VALIDATION_ID \
188 (GZP_CMD_ENCRYPTED_USER_DATA_RESP_SESSION_TOKEN + \
189 GZP_SESSION_TOKEN_LENGTH)
191#define GZP_CMD_ENCRYPTED_USER_DATA_RESP_PAYLOAD_LENGTH \
192 (GZP_CMD_ENCRYPTED_USER_DATA_RESP_VALIDATION_ID + \
193 GZP_VALIDATION_ID_LENGTH)
194
195#if (GZP_MAX_ACK_PAYLOAD_LENGTH < GZP_CMD_ENCRYPTED_USER_DATA_RESP_PAYLOAD_LENGTH)
196#error GZP_MAX_ACK_PAYLOAD_LENGTH must be greater or equal to \
197 GZP_CMD_ENCRYPTED_USER_DATA_RESP_PAYLOAD_LENGTH.
198#endif
199
200#if (GZP_VALIDATION_ID_LENGTH > GZP_HOST_ID_LENGTH)
201#error GZP_HOST_ID_LENGTH should be greater or equal to \
202 GZP_VALIDATION_ID_LENGTH.
203#endif
204
205#if (GZP_SESSION_TOKEN_LENGTH != GZP_HOST_ID_LENGTH)
206#error GZP_SESSION_TOKEN_LENGTH must equal GZP_HOST_ID_LENGTH.
207#endif
208
212/******************************************************************************/
216/******************************************************************************/
217
218
231
232
263};
264
265
283
284
292typedef void (*gzp_tx_result_callback)(bool success,
293 uint32_t pipe,
294 const nrf_gzll_device_tx_info_t *tx_info);
295
296
303typedef void (*gzp_address_req_callback)(bool result, void *context);
304
305
312typedef void (*gzp_id_req_callback)(enum gzp_id_req_res result, void *context);
313
314
321typedef void (*gzp_crypt_data_send_callback)(bool result, void *context);
322
323
327/******************************************************************************/
331/******************************************************************************/
332
338void gzp_crypt_set_session_token(const uint8_t *token);
339
340
346void gzp_crypt_get_session_token(uint8_t *dst_token);
347
348
354void gzp_crypt_set_dyn_key(const uint8_t *dyn_key);
355
356
362void gzp_crypt_get_dyn_key(uint8_t *dst_key);
363
364
370void gzp_set_host_id(const uint8_t *src);
371
372
378void gzp_get_host_id(uint8_t *dst);
379
380
388
389
402void gzp_crypt(uint8_t *dst, const uint8_t *src, uint8_t length);
403
404
413bool gzp_validate_id(const uint8_t *src_id);
414
415
422void gzp_add_validation_id(uint8_t *dst_id);
423
424
431void gzp_random_numbers_generate(uint8_t *dst, uint8_t n);
432
433
448bool gzp_update_radio_params(const uint8_t *system_address);
449
450
459void gzp_generate_channels(uint8_t *ch_dst, const uint8_t *address, uint8_t channel_set_size);
460
461
470void gzp_xor_cipher(uint8_t *dst, const uint8_t *src, const uint8_t *pad, uint8_t length);
471
472
473/******************************************************************************/
477/******************************************************************************/
478
479
486void gzp_init(void);
487
492
497
505
511void nrf_gzp_flush_rx_fifo(uint32_t pipe);
512
523
533
550
558
583
590void gzp_id_req_send_async(gzp_id_req_callback callback, void *context);
591
605bool gzp_crypt_data_send(const uint8_t *src, uint8_t length);
606
615void gzp_crypt_data_send_async(const uint8_t *src,
616 uint8_t length,
618 void *context);
619
620
641void gzp_pairing_enable(bool enable);
642
649
658
676
686
696
697
705
719bool gzp_crypt_user_data_read(uint8_t *dst, uint8_t *length);
720
721
728void gzll_rx_start(void);
729
730
735#ifdef __cplusplus
736}
737#endif
738
739#endif /* __GZP_H */
void gzp_erase_pairing_data(void)
void gzp_id_req_send_async(gzp_id_req_callback callback, void *context)
void(* gzp_tx_result_callback)(bool success, uint32_t pipe, const nrf_gzll_device_tx_info_t *tx_info)
Definition: gzp.h:292
bool gzp_address_exchanged(void)
void gzll_rx_start(void)
gzp_key_select
Enumerator used for selecting the key to be used for encryption.
Definition: gzp.h:223
@ GZP_DATA_EXCHANGE
Definition: gzp.h:229
@ GZP_ID_EXCHANGE
Definition: gzp.h:225
@ GZP_KEY_EXCHANGE
Definition: gzp.h:227
void gzp_crypt_get_dyn_key(uint8_t *dst_key)
bool gzp_validate_id(const uint8_t *src_id)
void gzp_xor_cipher(uint8_t *dst, const uint8_t *src, const uint8_t *pad, uint8_t length)
void gzp_tx_result_callback_register(gzp_tx_result_callback callback)
enum gzp_id_req_res gzp_id_req_send(void)
void gzp_generate_channels(uint8_t *ch_dst, const uint8_t *address, uint8_t channel_set_size)
bool gzp_crypt_data_send(const uint8_t *src, uint8_t length)
void gzp_address_req_send_async(gzp_address_req_callback callback, void *context)
void gzp_set_host_id(const uint8_t *src)
void gzp_id_req_grant(void)
void gzp_get_host_id(uint8_t *dst)
bool gzp_id_req_received(void)
bool gzp_update_radio_params(const uint8_t *system_address)
bool gzp_crypt_user_data_read(uint8_t *dst, uint8_t *length)
void gzp_random_numbers_generate(uint8_t *dst, uint8_t n)
void nrf_gzp_flush_rx_fifo(uint32_t pipe)
gzp_id_req_res
Enumerator used to identify the state of the current Host ID request.
Definition: gzp.h:271
@ GZP_ID_RESP_REJECTED
Definition: gzp.h:277
@ GZP_ID_RESP_GRANTED
Definition: gzp.h:275
@ GZP_ID_RESP_FAILED
Definition: gzp.h:279
@ GZP_ID_RESP_NO_REQUEST
Definition: gzp.h:281
@ GZP_ID_RESP_PENDING
Definition: gzp.h:273
void nrf_gzp_disable_gzll(void)
void gzp_crypt_select_key(enum gzp_key_select key_select)
void gzp_id_req_reject(void)
void(* gzp_crypt_data_send_callback)(bool result, void *context)
Definition: gzp.h:321
void gzp_id_req_cancel(void)
void gzp_pairing_enable(bool enable)
gzp_cmd
Enumerator used in the first payload byte of each packet to indicate the packet type.
Definition: gzp.h:238
@ GZP_CMD_HOST_ADDRESS_RESP
Definition: gzp.h:256
@ GZP_CMD_ENCRYPTED_USER_DATA
Definition: gzp.h:252
@ GZP_CMD_KEY_UPDATE_PREPARE_RESP
Definition: gzp.h:260
@ GZP_CMD_KEY_UPDATE
Definition: gzp.h:250
@ GZP_CMD_HOST_ID_FETCH_RESP
Definition: gzp.h:258
@ GZP_CMD_HOST_ID_REQ
Definition: gzp.h:244
@ GZP_CMD_HOST_ID_FETCH
Definition: gzp.h:246
@ GZP_CMD_FETCH_RESP
Definition: gzp.h:254
@ GZP_CMD_HOST_ADDRESS_REQ
Definition: gzp.h:240
@ GZP_CMD_KEY_UPDATE_PREPARE
Definition: gzp.h:248
@ GZP_CMD_HOST_ADDRESS_FETCH
Definition: gzp.h:242
@ GZP_CMD_ENCRYPTED_USER_DATA_RESP
Definition: gzp.h:262
void gzp_crypt(uint8_t *dst, const uint8_t *src, uint8_t length)
void(* gzp_id_req_callback)(enum gzp_id_req_res result, void *context)
Definition: gzp.h:312
void gzp_crypt_set_dyn_key(const uint8_t *dyn_key)
bool gzp_crypt_user_data_received(void)
void(* gzp_address_req_callback)(bool result, void *context)
Definition: gzp.h:303
void gzp_crypt_get_session_token(uint8_t *dst_token)
void gzp_crypt_data_send_async(const uint8_t *src, uint8_t length, gzp_crypt_data_send_callback callback, void *context)
int8_t gzp_get_pairing_status(void)
void gzp_crypt_set_session_token(const uint8_t *token)
void gzp_init(void)
void gzp_host_execute(void)
bool gzp_address_req_send(void)
void gzp_add_validation_id(uint8_t *dst_id)