Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00019 #ifndef __GZP_H
00020 #define __GZP_H
00021
00022 #include "gzll.h"
00023 #include "gzp_params.h"
00024 #include <stdint.h>
00025 #include <stdbool.h>
00026
00027
00028
00029
00030 #define GZP_PAIRING_PIPE 0
00031 #define GZP_DATA_PIPE 1
00032 #define GZP_TX_RX_TRANS_DELAY 10
00033 #define GZP_SYSTEM_ADDRESS_WIDTH 4 // Must equal Gazell address width - 1
00034 #define GZP_VALIDATION_ID {0x32, 0x53, 0x66}
00035 #define GZP_VALIDATION_ID_LENGTH 3
00036 #define GZP_HOST_ID_LENGTH 5
00037 #define GZP_SESSION_TOKEN_LENGTH GZP_HOST_ID_LENGTH
00038 #define GZP_DYN_KEY_LENGTH (16 - GZP_VALIDATION_ID_LENGTH)
00039
00040
00041
00042
00043
00044
00045 #define GZP_CMD_HOST_ADDRESS_REQ_PAYLOAD_LENGTH 1
00046
00047
00048 #define GZP_CMD_HOST_ADDRESS_FETCH_PAYLOAD_LENGTH 1
00049
00050
00051 #define GZP_CMD_HOST_ID_REQ_SESSION_TOKEN 1
00052 #define GZP_CMD_HOST_ID_REQ_PAYLOAD_LENGTH (GZP_CMD_HOST_ID_REQ_SESSION_TOKEN + GZP_SESSION_TOKEN_LENGTH)
00053
00054 #if (GZP_CMD_HOST_ID_REQ_PAYLOAD_LENGTH > 17)
00055 #error GZP_SESSION_TOKEN_LENGTH too long.
00056 #endif
00057
00058
00059 #define GZP_CMD_HOST_ID_FETCH_VALIDATION_ID 1
00060 #define GZP_CMD_HOST_ID_FETCH_PAYLOAD_LENGTH (GZP_CMD_HOST_ID_FETCH_VALIDATION_ID + GZP_VALIDATION_ID_LENGTH)
00061
00062 #if (GZP_CMD_HOST_ID_FETCH_PAYLOAD_LENGTH > 17)
00063 #error GZP_VALIDATION_ID_LENGTH set too long.
00064 #endif
00065
00066
00067 #define GZP_CMD_KEY_UPDATE_PREPARE_PAYLOAD_LENGTH 1
00068
00069
00070 #define GZP_CMD_KEY_UPDATE_VALIDATION_ID 1
00071 #define GZP_CMD_KEY_UPDATE_NEW_KEY (GZP_CMD_KEY_UPDATE_VALIDATION_ID + GZP_VALIDATION_ID_LENGTH)
00072 #define GZP_CMD_KEY_UPDATE_PAYLOAD_LENGTH (GZP_CMD_KEY_UPDATE_NEW_KEY + GZP_DYN_KEY_LENGTH)
00073
00074 #if (GZP_CMD_KEY_UPDATE_PAYLOAD_LENGTH > 17)
00075 #error Sum (GZP_VALIDATION_ID_LENGTH + GZP_DYN_KEY_LENGTH) too high.
00076 #endif
00077
00078
00079 #define GZP_CMD_ENCRYPTED_USER_DATA_VALIDATION_ID 1
00080 #define GZP_CMD_ENCRYPTED_USER_DATA_PAYLOAD ((GZP_CMD_ENCRYPTED_USER_DATA_VALIDATION_ID + GZP_VALIDATION_ID_LENGTH))
00081 #define GZP_USER_DATA_PACKET_OVERHEAD ( GZP_CMD_ENCRYPTED_USER_DATA_VALIDATION_ID + GZP_VALIDATION_ID_LENGTH)
00082
00083 #define GZP_ENCRYPTED_USER_DATA_MAX_LENGTH (17 - GZP_USER_DATA_PACKET_OVERHEAD)
00084
00085 #if(GZLL_MAX_FW_PAYLOAD_LENGTH < 17)
00086 #error GZLL_MAX_FW_PAYLOAD_LENGTH must be greater or equal to 17.
00087 #endif
00088
00089
00090 #define GZPAR_CMD_FETCH_RESP_PAYLOAD_LENGTH 1
00091
00092
00093
00094
00095
00096
00097 #define GZP_CMD_HOST_ADDRESS_RESP_ADDRESS 1
00098 #define GZP_CMD_HOST_ADDRESS_RESP_PAYLOAD_LENGTH (GZP_CMD_HOST_ADDRESS_RESP_ADDRESS + GZP_SYSTEM_ADDRESS_WIDTH)
00099
00100 #if(GZLL_MAX_ACK_PAYLOAD_LENGTH < GZP_CMD_HOST_ADDRESS_RESP_PAYLOAD_LENGTH)
00101 #error GZLL_MAX_ACK_PAYLOAD_LENGTH must be greater or equal to GZP_CMD_HOST_ADDRESS_RESP_PAYLOAD_LENGTH.
00102 #endif
00103
00104
00105 #define GZP_CMD_HOST_ID_FETCH_RESP_VALIDATION_ID 1
00106 #define GZP_CMD_HOST_ID_FETCH_RESP_STATUS (GZP_CMD_HOST_ID_FETCH_RESP_VALIDATION_ID + GZP_VALIDATION_ID_LENGTH)
00107 #define GZP_CMD_HOST_ID_FETCH_RESP_HOST_ID (GZP_CMD_HOST_ID_FETCH_RESP_STATUS + 1)
00108 #define GZP_CMD_HOST_ID_FETCH_RESP_PAYLOAD_LENGTH (GZP_CMD_HOST_ID_FETCH_RESP_HOST_ID + GZP_HOST_ID_LENGTH)
00109
00110 #if(GZLL_MAX_ACK_PAYLOAD_LENGTH < GZP_CMD_HOST_ID_FETCH_RESP_PAYLOAD_LENGTH)
00111 #error GZLL_MAX_ACK_PAYLOAD_LENGTH must be greater or equal to GZP_CMD_HOST_ID_FETCH_RESP_PAYLOAD_LENGTH.
00112 #endif
00113
00114
00115 #define GZP_CMD_KEY_UPDATE_PREPARE_RESP_SESSION_TOKEN 1
00116 #define GZP_CMD_KEY_UPDATE_PREPARE_RESP_PAYLOAD_LENGTH (GZP_CMD_KEY_UPDATE_PREPARE_RESP_SESSION_TOKEN + GZP_SESSION_TOKEN_LENGTH)
00117
00118 #if(GZLL_MAX_ACK_PAYLOAD_LENGTH < GZP_CMD_KEY_UPDATE_PREPARE_RESP_PAYLOAD_LENGTH)
00119 #error GZLL_MAX_ACK_PAYLOAD_LENGTH must be greater or equal to GZP_CMD_KEY_UPDATE_PREPARE_RESP_PAYLOAD_LENGTH.
00120 #endif
00121
00122
00123 #define GZP_CMD_ENCRYPTED_USER_DATA_RESP_SESSION_TOKEN 1
00124 #define GZP_CMD_ENCRYPTED_USER_DATA_RESP_VALIDATION_ID (GZP_CMD_ENCRYPTED_USER_DATA_RESP_SESSION_TOKEN + GZP_SESSION_TOKEN_LENGTH)
00125 #define GZP_CMD_ENCRYPTED_USER_DATA_RESP_PAYLOAD_LENGTH (GZP_CMD_ENCRYPTED_USER_DATA_RESP_VALIDATION_ID + GZP_VALIDATION_ID_LENGTH)
00126
00127 #if(GZLL_MAX_ACK_PAYLOAD_LENGTH < GZP_CMD_ENCRYPTED_USER_DATA_RESP_PAYLOAD_LENGTH)
00128 #error GZLL_MAX_ACK_PAYLOAD_LENGTH must be greater or equal to GZP_CMD_ENCRYPTED_USER_DATA_RESP_PAYLOAD_LENGTH.
00129 #endif
00130
00131 #if(GZP_VALIDATION_ID_LENGTH > GZP_HOST_ID_LENGTH)
00132 #error GZP_HOST_ID_LENGTH should be greater or equal to GZP_VALIDATION_ID_LENGTH.
00133 #endif
00134
00135 #if(GZP_SESSION_TOKEN_LENGTH != GZP_HOST_ID_LENGTH)
00136 #error GZP_SESSION_TOKEN_LENGTH must equal GZP_HOST_ID_LENGTH.
00137 #endif
00138
00139 #ifdef GZLL_CRYPT_ENABLE
00140 #error Gazell encryption can not be enabled when using the Gazell pairing library. \
00141 GZLL_CRYPT_ENABLE must be undefined.
00142 #endif
00143
00144
00145
00146
00147 typedef enum
00148 {
00149 GZP_ID_EXCHANGE,
00150 GZP_KEY_EXCHANGE,
00151 GZP_DATA_EXCHANGE
00152 } gzp_key_select_t;
00153
00154 typedef enum
00155 {
00156 GZP_CMD_HOST_ADDRESS_REQ = 0,
00157 GZP_CMD_HOST_ADDRESS_FETCH,
00158 GZP_CMD_HOST_ID_REQ,
00159 GZP_CMD_HOST_ID_FETCH,
00160 GZP_CMD_KEY_UPDATE_PREPARE,
00161 GZP_CMD_KEY_UPDATE,
00162 GZP_CMD_ENCRYPTED_USER_DATA,
00163 GZP_CMD_FETCH_RESP,
00164 GZP_CMD_HOST_ADDRESS_RESP,
00165 GZP_CMD_HOST_ID_FETCH_RESP,
00166 GZP_CMD_KEY_UPDATE_PREPARE_RESP,
00167 GZP_CMD_ENCRYPTED_USER_DATA_RESP,
00168 } gzp_cmd_t;
00169
00170 typedef enum
00171 {
00172 GZP_ID_RESP_PENDING,
00173 GZP_ID_RESP_GRANTED,
00174 GZP_ID_RESP_REJECTED,
00175 GZP_ID_RESP_FAILED
00176 } gzp_id_req_res_t;
00177
00178
00179
00180
00181
00185 void gzp_crypt_set_session_token(const uint8_t *token);
00186
00190 void gzp_crypt_set_dyn_key(const uint8_t* src_key);
00191
00195 void gzp_crypt_get_session_token(uint8_t *dst_token);
00196
00200 void gzp_crypt_get_dyn_key(uint8_t *dst_key);
00201
00206 static bool gzp_set_host_id(const uint8_t* src);
00207
00212 bool gzp_get_host_id(uint8_t *dst);
00213
00218 void gzp_crypt_select_key(gzp_key_select_t key_select);
00219
00226 void gzp_crypt(uint8_t* dst, const uint8_t* src, uint8_t length);
00227
00233 bool gzp_validate_id(const uint8_t *src_id);
00234
00239 void gzp_add_validation_id(uint8_t *dst_id);
00240
00244 void gzp_random_numbers_generate(uint8_t *dst, uint8_t n);
00245
00250 void gzp_update_radio_params(const uint8_t *system_address);
00251
00256 void gzp_generate_channels(uint8_t *ch_dst, const uint8_t *system_address, uint8_t channel_tab_size);
00257
00261 void gzp_xor_cipher(uint8_t* dst, const uint8_t* src, const uint8_t* pad, uint8_t length);
00262
00278 void gzp_init(void);
00279
00286 void gzp_id_req_cancel(void);
00287
00312 bool gzp_address_req_send(void);
00313
00341 gzp_id_req_res_t gzp_id_req_send(void);
00342
00358 bool gzp_crypt_data_send(const uint8_t *src, uint8_t length);
00359
00380 void gzp_pairing_enable(bool enable);
00381
00387 void gzp_host_execute(void);
00388
00393 bool gzp_address_exchanged(void);
00394
00412 bool gzp_id_req_received(void);
00413
00422 void gzp_id_req_reject(void);
00423
00432 void gzp_id_req_grant(void);
00433
00437 bool gzp_crypt_user_data_received(void);
00438
00453 bool gzp_crypt_user_data_read(uint8_t* dst, uint8_t* length);
00454
00459 #endif