Gazell pairing library header file. More...
#include "gzll.h"
#include "gzp_params.h"
#include <stdint.h>
#include <stdbool.h>
Go to the source code of this file.
Gazell pairing library header file.
Definition in file gzp.h.
#define GZP_CMD_HOST_ID_REQ_PAYLOAD_LENGTH (GZP_CMD_HOST_ID_REQ_SESSION_TOKEN + GZP_SESSION_TOKEN_LENGTH) |
#define GZP_CMD_HOST_ID_FETCH_PAYLOAD_LENGTH (GZP_CMD_HOST_ID_FETCH_VALIDATION_ID + GZP_VALIDATION_ID_LENGTH) |
#define GZP_CMD_KEY_UPDATE_NEW_KEY (GZP_CMD_KEY_UPDATE_VALIDATION_ID + GZP_VALIDATION_ID_LENGTH) |
#define GZP_CMD_KEY_UPDATE_PAYLOAD_LENGTH (GZP_CMD_KEY_UPDATE_NEW_KEY + GZP_DYN_KEY_LENGTH) |
#define GZP_CMD_ENCRYPTED_USER_DATA_PAYLOAD ((GZP_CMD_ENCRYPTED_USER_DATA_VALIDATION_ID + GZP_VALIDATION_ID_LENGTH)) |
#define GZP_USER_DATA_PACKET_OVERHEAD ( GZP_CMD_ENCRYPTED_USER_DATA_VALIDATION_ID + GZP_VALIDATION_ID_LENGTH) |
#define GZP_ENCRYPTED_USER_DATA_MAX_LENGTH (17 - GZP_USER_DATA_PACKET_OVERHEAD) |
#define GZP_CMD_HOST_ADDRESS_RESP_PAYLOAD_LENGTH (GZP_CMD_HOST_ADDRESS_RESP_ADDRESS + GZP_SYSTEM_ADDRESS_WIDTH) |
#define GZP_CMD_HOST_ID_FETCH_RESP_STATUS (GZP_CMD_HOST_ID_FETCH_RESP_VALIDATION_ID + GZP_VALIDATION_ID_LENGTH) |
#define GZP_CMD_HOST_ID_FETCH_RESP_HOST_ID (GZP_CMD_HOST_ID_FETCH_RESP_STATUS + 1) |
#define GZP_CMD_HOST_ID_FETCH_RESP_PAYLOAD_LENGTH (GZP_CMD_HOST_ID_FETCH_RESP_HOST_ID + GZP_HOST_ID_LENGTH) |
#define GZP_CMD_KEY_UPDATE_PREPARE_RESP_PAYLOAD_LENGTH (GZP_CMD_KEY_UPDATE_PREPARE_RESP_SESSION_TOKEN + GZP_SESSION_TOKEN_LENGTH) |
#define GZP_CMD_ENCRYPTED_USER_DATA_RESP_VALIDATION_ID (GZP_CMD_ENCRYPTED_USER_DATA_RESP_SESSION_TOKEN + GZP_SESSION_TOKEN_LENGTH) |
#define GZP_CMD_ENCRYPTED_USER_DATA_RESP_PAYLOAD_LENGTH (GZP_CMD_ENCRYPTED_USER_DATA_RESP_VALIDATION_ID + GZP_VALIDATION_ID_LENGTH) |
enum gzp_key_select_t |
Definition at line 147 of file gzp.h.
{ GZP_ID_EXCHANGE, // "Secret key" only GZP_KEY_EXCHANGE, // "Secret key" and "Host ID" GZP_DATA_EXCHANGE // "Dynamic key" and "Host ID" } gzp_key_select_t;
enum gzp_cmd_t |
Definition at line 154 of file gzp.h.
{ GZP_CMD_HOST_ADDRESS_REQ = 0, GZP_CMD_HOST_ADDRESS_FETCH, GZP_CMD_HOST_ID_REQ, GZP_CMD_HOST_ID_FETCH, GZP_CMD_KEY_UPDATE_PREPARE, GZP_CMD_KEY_UPDATE, GZP_CMD_ENCRYPTED_USER_DATA, GZP_CMD_FETCH_RESP, GZP_CMD_HOST_ADDRESS_RESP, GZP_CMD_HOST_ID_FETCH_RESP, GZP_CMD_KEY_UPDATE_PREPARE_RESP, GZP_CMD_ENCRYPTED_USER_DATA_RESP, } gzp_cmd_t;
enum gzp_id_req_res_t |
void gzp_crypt_set_session_token | ( | const uint8_t * | token ) |
Function for writing global variable gzp_session_token.
Definition at line 138 of file gzp.c.
{ memcpy(gzp_session_token, (void const*)token, GZP_SESSION_TOKEN_LENGTH); }
void gzp_crypt_set_dyn_key | ( | const uint8_t * | src_key ) |
Function for writing global variable gzp_dyn_key.
Definition at line 143 of file gzp.c.
{ memcpy(gzp_dyn_key, (void const*)key, GZP_DYN_KEY_LENGTH); }
void gzp_crypt_get_session_token | ( | uint8_t * | dst_token ) |
Function for reading global variable gzp_session_token.
Definition at line 148 of file gzp.c.
{ memcpy(dst_token, (void const*)gzp_session_token, GZP_SESSION_TOKEN_LENGTH); }
void gzp_crypt_get_dyn_key | ( | uint8_t * | dst_key ) |
Function for reading global variable gzp_dyn_key.
Definition at line 153 of file gzp.c.
{ memcpy(dst_key, (void const*)gzp_dyn_key, GZP_DYN_KEY_LENGTH); }
_Bool gzp_get_host_id | ( | uint8_t * | dst ) |
Function reading current "Host ID". On Host, returns false if host ID not yet generated.
Definition at line 550 of file gzp_device.c.
{ memcpy(dst_id, gzp_host_id, GZP_HOST_ID_LENGTH); return true; }
void gzp_crypt_select_key | ( | gzp_key_select_t | key_select ) |
Function selecting what key-set that should be used when encrypting data using gzp_crypt().
Definition at line 158 of file gzp.c.
{ gzp_key_select = key_select; }
void gzp_crypt | ( | uint8_t * | dst, |
const uint8_t * | src, | ||
uint8_t | length | ||
) |
Function for encypting / decrypting data.
The current "session token" will be used as initialization vector (IV). The AES key to be used is selected by gzp_crypt_select_key().
Definition at line 163 of file gzp.c.
{ uint8_t i; uint8_t key[16]; uint8_t iv[16]; // Build AES key based on "gzp_key_select" switch(gzp_key_select) { case GZP_ID_EXCHANGE: memcpy(key, (void const*)gzp_secret_key, 16); break; case GZP_KEY_EXCHANGE: memcpy(key, (void const*)gzp_secret_key, 16); gzp_get_host_id(key); break; case GZP_DATA_EXCHANGE: memcpy(key, (void const*)gzp_secret_key, 16); memcpy(key, (void const*)gzp_dyn_key, GZP_DYN_KEY_LENGTH); break; default: break; } // Build init vector from "gzp_session_token" for(i = 0; i < 16; i++) { if(i < GZP_SESSION_TOKEN_LENGTH) { iv[i] = gzp_session_token[i]; } else { iv[i] = 0; } } // Set up hal_aes using new key and init vector hal_aes_setup(false, ECB, key, NULL); // Note, here we skip the IV as we use ECB mode // Encrypt IV using ECB mode hal_aes_crypt(iv, iv); // Encrypt data by XOR'ing with AES output gzp_xor_cipher(dst, src, iv, length); }
_Bool gzp_validate_id | ( | const uint8_t * | src_id ) |
Function for comparing *src_id with a pre-defined validation ID.
Returns true if *src_id equals the pre-defined ID.
Definition at line 128 of file gzp.c.
{ return (memcmp(id, (void*)gzp_validation_id, GZP_VALIDATION_ID_LENGTH) == 0); }
void gzp_add_validation_id | ( | uint8_t * | dst_id ) |
Function for adding the pre-defined validation ID to dst_id. GZP_VALIDATION_ID_LENGTH bytes will be added.
Definition at line 133 of file gzp.c.
{ memcpy(dst, (void const*)gzp_validation_id, GZP_VALIDATION_ID_LENGTH); }
void gzp_random_numbers_generate | ( | uint8_t * | dst, |
uint8_t | n | ||
) |
Function generating and returning n random numbers to dst.
Definition at line 30 of file gzp_device_le1.c.
{ uint8_t i; hal_rng_power_up(true); for(i = 0; i < n; i++) { while(!hal_rng_data_ready()) ; *(dst++) = hal_rng_read(); } hal_rng_power_up(false); }
void gzp_update_radio_params | ( | const uint8_t * | system_address ) |
Function updating channel subset and all pipe addresses from a single 5 byte address.
Definition at line 59 of file gzp.c.
{ uint8_t i; uint8_t channels[GZLL_MAX_CHANNEL_TAB_SIZE]; uint8_t temp_address[GZLL_ADDRESS_WIDTH]; // Configure "global" pairing address gzll_set_address(HAL_NRF_PIPE0, (uint8_t const*)pairing_address); if(system_address != NULL) { for(i = 0; i < GZP_SYSTEM_ADDRESS_WIDTH; i++) { temp_address[i + 1] = *(system_address + i); } // Configure address for pipe 1 - 5. Address byte set to equal pipe number. for(i = 1; i < 6; i++) { temp_address[0] = i; gzll_set_address((hal_nrf_address_t)i, temp_address); } } gzp_generate_channels(&channels[0], &temp_address[1], gzll_get_channel_tab_size()); // Write generated channel subset to Gazell Link Layer gzll_set_channels(&channels[0], gzll_get_channel_tab_size()); }
void gzp_generate_channels | ( | uint8_t * | ch_dst, |
const uint8_t * | system_address, | ||
uint8_t | channel_tab_size | ||
) |
Function generating channel subset from a single 5 byte address.
Definition at line 89 of file gzp.c.
{ uint8_t binsize, spacing, i; binsize = (GZP_CHANNEL_MAX - GZP_CHANNEL_MIN) / channel_tab_size; ch_dst[0] = GZP_CHANNEL_LOW; ch_dst[channel_tab_size - 1] = GZP_CHANNEL_HIGH; for(i = 1; i < (channel_tab_size - 1); i++) { ch_dst[i] = (binsize * i) + (system_address[i % 4] % binsize); } for(i = 1; i < channel_tab_size; i++) { spacing = (ch_dst[i] - ch_dst[i - 1]); if(spacing < GZP_CHANNEL_SPACING_MIN) { ch_dst[i] += (GZP_CHANNEL_SPACING_MIN - spacing); } } }