void main(void) { bool send_crypt_data = false; bool tx_success = false; gzp_id_req_res_t id_req_status; uint8_t payload[GZLL_MAX_PAYLOAD_LENGTH]; mcu_init(); // Initialize Gazell Link Layer gzll_init(); // Initialize Gazell Pairing Library gzp_init(); EA = 1; while(true) { payload[0] = ~P0; // Send every other packet as encrypted data if(send_crypt_data) { // Send encrypted packet using the Gazell pairing library tx_success = gzp_crypt_data_send(payload, GZP_ENCRYPTED_USER_DATA_MAX_LENGTH); } else { // Send packet as plaintext on pipe 2 gzll_tx_data(payload, GZLL_MAX_FW_PAYLOAD_LENGTH, 2); while(gzll_get_state() != GZLL_IDLE) ; tx_success = gzll_tx_success(); } send_crypt_data = !send_crypt_data; // If data transfer failed if(!tx_success) { // Send "system address request". Needed for sending any user data to Host. gzp_address_req_send(); // Send "Host ID request". Needed for sending encrypted user data to host. id_req_status = gzp_id_req_send(); } // If waiting for Host to grant or reject ID request if(id_req_status == GZP_ID_RESP_PENDING) { // Send new ID request for fetching response id_req_status = gzp_id_req_send(); } } }
static gzp_id_req_res_t send_host_id_req(void) { gzp_id_req_res_t id_resp; // Try sending "Host ID" request id_resp = gzp_id_req_send(); switch(id_resp) { case GZP_ID_RESP_REJECTED: case GZP_ID_RESP_FAILED: //nrfr_keyboard_led_blink_on(false, 0); // Turn LED off nrf_gpio_pin_write(PAIRING_FAILED_LED,1); nrf_gpio_pin_write(PAIRING_SUCCESS_LED,0); // Reset variables so that pairing restarts from the beginning. host_id_received = false; system_addr_received = false; break; case GZP_ID_RESP_GRANTED: // Blink LED if new Host ID received from dongle (pairing success) //nrfr_keyboard_led_blink_on(true, 2000); // Blink LED for 2 seconds nrf_gpio_pin_write(PAIRING_FAILED_LED ,0); nrf_gpio_pin_write(PAIRING_SUCCESS_LED,1); // Reset variables so that pairing restarts from the beginning. host_id_received = true; system_addr_received = true; break; case GZP_ID_RESP_PENDING: default: break; } return id_resp; }
static gzp_id_req_res_t send_host_id_req(void) { gzp_id_req_res_t id_resp; // Try sending "Host ID" request id_resp = gzp_id_req_send(); switch(id_resp) { case GZP_ID_RESP_REJECTED: case GZP_ID_RESP_FAILED: host_id_received = false; system_addr_received = false; break; case GZP_ID_RESP_GRANTED: host_id_received = true; system_addr_received = true; break; case GZP_ID_RESP_PENDING: default: break; } return id_resp; }