nRF51 SDK
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Gazell Pairing Device implementation.

Macros

#define SOURCE_FILE   NRF_SOURCE_FILE_GZP_DEVICE
 File identifer for asserts.
 

Functions

void gzp_init ()
 
void gzp_erase_pairing_data (void)
 
bool gzp_address_req_send ()
 
gzp_id_req_res_t gzp_id_req_send ()
 
void gzp_id_req_cancel ()
 
bool gzp_crypt_data_send (const uint8_t *src, uint8_t length)
 

Misc. defines

#define GZP_PARAMS_DB_ELEMENT_SYSTEM_ADDRESS   0
 System address position.
 
#define GZP_PARAMS_DB_ELEMENT_HOST_ID   (GZP_PARAMS_DB_ELEMENT_SYSTEM_ADDRESS + GZP_SYSTEM_ADDRESS_WIDTH)
 Host ID position.
 
#define GZP_PARAMS_DB_ELEMENT_SIZE   (GZP_SYSTEM_ADDRESS_WIDTH + GZP_HOST_ID_LENGTH)
 Total size.
 
#define GZP_PARAMS_DB_MAX_ENTRIES   14
 Maximum allowed entries in the database.
 

Derived parameters

#define GZP_PARAMS_DB_ADR   GZP_PARAMS_STORAGE_ADR
 
#define GZP_PARAMS_DB_SIZE   (GZP_PARAMS_DB_MAX_ENTRIES * GZP_PARAMS_DB_ELEMENT_SIZE)
 
#define GZP_INDEX_DB_ADR   (GZP_PARAMS_STORAGE_ADR + GZP_PARAMS_DB_SIZE)
 
#define GZP_INDEX_DB_SIZE   (GZP_DEVICE_PARAMS_STORAGE_SIZE - GZP_PARAMS_DB_SIZE)
 

Typedefs

enum  gzp_tx_rx_trans_result_t {
  GZP_TX_RX_SUCCESS,
  GZP_TX_RX_FAILED_TO_SEND,
  GZP_TX_RX_NO_RESPONSE
}
 

Internal variables

static uint8_t gzp_system_address [GZP_SYSTEM_ADDRESS_WIDTH]
 
static uint8_t gzp_host_id [GZP_HOST_ID_LENGTH]
 
static uint8_t dyn_key [GZP_DYN_KEY_LENGTH]
 
static bool gzp_id_req_pending = false
 

Internal (static) function prototypes

static bool gzp_tx_packet (const uint8_t *tx_packet, uint8_t length, uint8_t pipe)
 
static gzp_tx_rx_trans_result_t gzp_tx_rx_transaction (const uint8_t *tx_packet, uint8_t tx_length, uint8_t *rx_dst, uint32_t *rx_length, uint8_t pipe)
 
static bool gzp_crypt_tx_transaction (const uint8_t *tx_packet, uint8_t length)
 
static bool gzp_key_update (void)
 
static void gzp_params_db_add (const uint8_t *src_element, uint8_t index)
 
static void gzp_params_db_read (uint8_t *dst_element, uint8_t index)
 
static void gzp_index_db_add (uint8_t index)
 
static uint8_t gzp_index_db_read (void)
 
static bool gzp_index_db_full (void)
 
static bool gzp_index_db_empty (void)
 
static bool gzp_array_is_set (const uint8_t *src, uint8_t length)
 
static bool gzp_params_store (bool store_all)
 
static bool gzp_params_restore (void)
 
void gzp_delay_rx_periods (uint32_t rx_periods)
 
void gzp_tick_sleep_rx_periods (uint32_t rx_periods)
 
void print_string (char *p_expr)
 

Internal (static) variables

static nrf_gzll_device_tx_info_t latest_tx_info
 Information about the last TX attempt, e.g. RSSI of ACK.
 
static bool tx_complete
 Flag to indicate whether a GZLL TX attempt has completed.
 
static bool tx_success
 Flag to indicate whether a GZLL TX attempt was successful.
 
static const uint32_t database [GZP_DEVICE_PARAMS_STORAGE_SIZE/4]
 Database for storing keys. More...
 

Detailed Description

Enumeration Type Documentation

Possible return values for the function gzp_tx_rx_transaction()

Enumerator
GZP_TX_RX_SUCCESS 

ACK received. Transaction successful.

Function Documentation

static bool gzp_tx_packet ( const uint8_t *  tx_packet,
uint8_t  length,
uint8_t  pipe 
)
static

Function for sending an encrypted packet.

The function waits for the transmission to complete.

Parameters
tx_packetPointer to the packet to be sent.
lengthLength of the packet to be sent.
pipePipe on which the packet should be sent.
Return values
trueIf the transmission succeeded.
falseIf the transmission failed (timed out).
static gzp_tx_rx_trans_result_t gzp_tx_rx_transaction ( const uint8_t *  tx_packet,
uint8_t  tx_length,
uint8_t *  rx_dst,
uint32_t *  rx_length,
uint8_t  pipe 
)
static

Function sending the packet *tx_packet and a subsequent packet fetching the response to *tx_packet.

Parameters
tx_packetis a pointer to the packet to be sent.
tx_lengthis the length of the packet to be sent.
rx_dstis a pointer to where the received response packet should be stored.
rx_lengthis a pointer to where the length of the received packet should be stored.
pipeis the pipe on which the packet should be sent.
Returns
result of the transaction.
static bool gzp_crypt_tx_transaction ( const uint8_t *  tx_packet,
uint8_t  length 
)
static

Function for sending an encrypted packet. The function detects whether the correct key was used, and attempts to send a "key update" to the host if the wrong key was being used.

Parameters
tx_packetis a pointer to the packet to be sent.
lengthis the length of the packet to be sent.
Return values
trueif transmission succeeded and packet was decrypted correctly by host.
falseif transmission failed or packet was not decrypted correctly by host.
static bool gzp_key_update ( void  )
static

Function updateing the "dynamic key" and sending a "key update" to the host.

Return values
trueif key update succeeded.
falseif if key update failed.
static void gzp_params_db_add ( const uint8_t *  src_element,
uint8_t  index 
)
static

Function for adding an element to "parameters data base" in non volatile (NV) memory. An element is GZP_PARAMS_ELEMENT_SYSTEM_ADDRESS bytes long, holding the "system address" and "host ID".

The "parameters data base" can store up to GZP_DEVICE_PAIRING_PARAMS_DB_MAX_ENTRIES elements.

Parameters
src_elementis a pointer to the element.
indexis a number between 0 and (GZP_PARAMS_DB_MAX_ENTRIES - 1) selecting the location in which the element will be stored.
static void gzp_params_db_read ( uint8_t *  dst_element,
uint8_t  index 
)
static

Function for reading an element from "parameters data base" in non volatile (NV) memory. An element is GZP_PARAMS_ELEMENT_SYSTEM_ADDRESS bytes long, holding the "system address" and "host ID".

Parameters
dst_elementis a pointer where the read element should be stored.
indexis a number between 0 and (GZP_PARAMS_DB_MAX_ENTRIES - 1). selecting the location that should be read.
static void gzp_index_db_add ( uint8_t  index)
static

Function for writing an index to the "index data base" in non volatile (NV) memory.

Parameters
indexis the index to be written to the data base.
static uint8_t gzp_index_db_read ( void  )
static

Function for reading the index previously written to the "index data base" in NV memory.

Returns
static bool gzp_index_db_full ( void  )
static

Check "index data base" is full.

Return values
true
false
static bool gzp_index_db_empty ( void  )
static

Function returning true if the "index data base" is empty.

Return values
true
false
static bool gzp_array_is_set ( const uint8_t *  src,
uint8_t  length 
)
static

Function returning true if array contains only 1s (0xff).

Parameters
*srcis a pointer to the array to be evaluated.
lengthis the length of the array to be evaluated.
Return values
true
false
static bool gzp_params_store ( bool  store_all)
static

Function for storing the current "system address" and "host ID" in NV memory.

Parameters
store_allselects whether only "system address" or both "system address" and "host ID" should be stored.
  • true selects that both should be stored.
  • false selects that only "system address" should be stored.
Return values
true
false
static bool gzp_params_restore ( void  )
static

Restore the "system address" and "host ID" from NV memory.

Return values
true
false
void gzp_delay_rx_periods ( uint32_t  rx_periods)

Delay function. Will add a delay equal to GZLL_RX_PERIOD * rx_periods [us].

Parameters
rx_periods
void gzp_tick_sleep_rx_periods ( uint32_t  rx_periods)

Delay function. Will add a delay equal to GZLL_RX_PERIOD * rx_periods [us] using the gazell timer and not a delay loop.

Parameters
rx_periods
void gzp_init ( void  )

Initialization function. This function initializes the Gazell Pairing Library.

This function must be called before any of the other Gazell Pairing Library functions are used and must be called after gzll_init() is called.

void gzp_erase_pairing_data ( void  )

Function for erasing all pairing data.

bool gzp_address_req_send ( void  )

Function for sending a "system address" request to a Host.

When calling this function the Device will attempt acquiring the "system address" from any Host within close proximity.

If a host is located within close proximity and pairing is enabled in the Host, a "system address" will be sent in return to the Device.

The new "system address" will apply immediately in the Device, and the new "system address" will be stored in non volatile (NV) memory.

Note. Using OTP devices limits the number of times a new "system address" can be stored in NV memory.

Returns
Return values
trueif new "system address" was received from a Host.
falseif no "system address" was received from a Host.
gzp_id_req_res_t gzp_id_req_send ( void  )

Function for sending a "Host ID request" to a Host.

The "Host ID" is needed to be able to send encrypted data using gzp_crypt_data_send().

The request will be sent using the "system address" previously received using gzp_address_req_send().

It is not required that the Host is within close proximity in order to acquire the "Host ID".

The new "Host ID" will apply immediately for the Device, and the new "Host ID" will be stored in non volatile (NV) memory.

Note. Using OTP devices limits the number of times a new "Host ID" can be stored in NV memory.

Returns
Return values
GZP_ID_RESP_PENDINGif a "Host ID request" has been sent to the Host, but the Host application has not yet decided whether to Grant or Reject the "ID request".
GZP_ID_RESP_GRANTEDif the "Host ID" has been received from the Host. The received "Host ID" will be stored in non volatile memory.
GZP_ID_RESP_REJECTEDif the Host application has rejected the "Host ID request".
GZP_ID_RESP_FAILEDif failing to send a request or receive a response from the Host.
void gzp_id_req_cancel ( void  )

Function for cancelling an ongoing (pending) "Host ID request".

After calling this function the "Host ID request" status will go to "ID request Idle".

bool gzp_crypt_data_send ( const uint8_t *  src,
uint8_t  length 
)

Function for sending encrypted user data to the Host.

Before any data can be sent the Device must acquire both the Host's "system address" by using gzp_address_req_send() and the "Host ID" by using gzp_id_req_send().

Parameters
*srcis a pointer to the data packet to be sent.
lengthis the length of the data packet to be sent.
Returns
Return values
trueif the data was successfully transmitted and decrypted by the Host.
falseif data transmission failed or Host failed to decryption data correctly.

Variable Documentation

const uint32_t database[GZP_DEVICE_PARAMS_STORAGE_SIZE/4]
static
Initial value:
= {
0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFF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