uint32_t ble_uuid_decode_rsp_dec(uint8_t const * const p_buf, uint32_t buf_len, ble_uuid_t * * const pp_uuid, uint32_t * const p_result_code) { SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_result_code); uint32_t err_code; uint32_t index = 0; uint32_t decode_result = ser_ble_cmd_rsp_result_code_dec(p_buf, &index, buf_len, SD_BLE_UUID_DECODE, p_result_code); if (decode_result != NRF_SUCCESS) { return decode_result; } if (*p_result_code != NRF_SUCCESS) { SER_ASSERT_LENGTH_EQ(index, buf_len); return NRF_SUCCESS; } err_code = cond_field_dec(p_buf, buf_len, &index, (void * *)pp_uuid, ble_uuid_t_dec); SER_ASSERT(err_code == NRF_SUCCESS, err_code); SER_ASSERT_LENGTH_EQ(index, buf_len); return err_code; }
uint32_t ble_gatts_initial_user_handle_get_rsp_dec(uint8_t const * const p_buf, uint32_t packet_len, uint16_t ** pp_handle, uint32_t * const p_result_code) { SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_result_code); uint32_t err_code; uint32_t index = 0; uint32_t decode_result = ser_ble_cmd_rsp_result_code_dec(p_buf, &index, packet_len, SD_BLE_GATTS_INITIAL_USER_HANDLE_GET, p_result_code); if (decode_result != NRF_SUCCESS) { return decode_result; } if (*p_result_code != NRF_SUCCESS) { SER_ASSERT_LENGTH_EQ(index, packet_len); return NRF_SUCCESS; } err_code = cond_field_dec(p_buf, packet_len, &index, (void * *)pp_handle, uint16_t_dec); SER_ASSERT(err_code == NRF_SUCCESS, err_code); SER_ASSERT_LENGTH_EQ(index, packet_len); return NRF_SUCCESS; }
uint32_t ble_opt_set_rsp_dec(uint8_t const * const p_buf, uint32_t packet_len, uint32_t * const p_result_code) { uint32_t index = 0; uint32_t error_code; error_code = ser_ble_cmd_rsp_result_code_dec(p_buf, &index, packet_len, SD_BLE_OPT_SET, p_result_code); if (error_code != NRF_SUCCESS) { return error_code; } if (*p_result_code != NRF_SUCCESS) { SER_ASSERT_LENGTH_EQ(index, packet_len); return NRF_SUCCESS; } SER_ASSERT_LENGTH_EQ(index, packet_len); return NRF_SUCCESS; }
uint32_t ble_tx_buffer_count_get_rsp_dec(uint8_t const * const p_buf, uint32_t packet_len, uint8_t * * const pp_count, uint32_t * const p_result_code) { SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_result_code); uint32_t index = 0; uint32_t err_code = ser_ble_cmd_rsp_result_code_dec(p_buf, &index, packet_len, SD_BLE_TX_BUFFER_COUNT_GET, p_result_code); SER_ASSERT(err_code == NRF_SUCCESS, err_code); if (*p_result_code != NRF_SUCCESS) { SER_ASSERT_LENGTH_EQ(index, packet_len); return NRF_SUCCESS; } err_code = cond_field_dec(p_buf, packet_len, &index, (void * *)pp_count, uint8_t_dec); SER_ASSERT(err_code == NRF_SUCCESS, err_code); SER_ASSERT_LENGTH_EQ(index, packet_len); return NRF_SUCCESS; }
uint32_t ble_opt_get_req_dec(uint8_t const * const p_buf, uint16_t packet_len, uint32_t * const p_opt_id, ble_opt_t **const pp_opt ) { uint32_t index = 0; uint32_t err_code; SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_opt_id); SER_ASSERT_NOT_NULL(pp_opt); SER_ASSERT_NOT_NULL(*pp_opt); SER_ASSERT_LENGTH_EQ(SER_CMD_HEADER_SIZE + 4 + 1, packet_len); SER_ASSERT(p_buf[index] == SD_BLE_OPT_GET, NRF_ERROR_INVALID_PARAM); index++; err_code = uint32_t_dec(p_buf, packet_len, &index, p_opt_id); SER_ASSERT(err_code == NRF_SUCCESS, err_code); SER_ASSERT(((*p_opt_id == BLE_GAP_OPT_LOCAL_CONN_LATENCY) || (*p_opt_id == BLE_GAP_OPT_PASSKEY) || (*p_opt_id == BLE_GAP_OPT_PRIVACY)), NRF_ERROR_INVALID_PARAM); if (p_buf[index++] == SER_FIELD_NOT_PRESENT) { *pp_opt = NULL; } SER_ASSERT_LENGTH_EQ(index, packet_len); return NRF_SUCCESS; }
uint32_t ble_gatts_service_add_rsp_dec(uint8_t const * const p_buf, uint32_t packet_len, uint16_t * const p_conn_handle, uint32_t * const p_result_code) { uint32_t index = 0; uint32_t decode_result = ser_ble_cmd_rsp_result_code_dec(p_buf, &index, packet_len, SD_BLE_GATTS_SERVICE_ADD, p_result_code); if (decode_result != NRF_SUCCESS) { return decode_result; } if (*p_result_code != NRF_SUCCESS) { SER_ASSERT_LENGTH_EQ(index, packet_len); return NRF_SUCCESS; } SER_ASSERT_NOT_NULL(p_conn_handle); SER_ASSERT_LENGTH_LEQ(index + 2, packet_len); uint16_dec(p_buf, packet_len, &index, p_conn_handle); SER_ASSERT_LENGTH_EQ(index, packet_len); return decode_result; }
uint32_t ble_version_get_rsp_dec(uint8_t const * const p_buf, uint32_t packet_len, ble_version_t * p_version, uint32_t * const p_result_code) { uint32_t index = 0; SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_result_code); uint32_t status_code = ser_ble_cmd_rsp_result_code_dec(p_buf, &index, packet_len, SD_BLE_VERSION_GET, p_result_code); if (status_code != NRF_SUCCESS) { return status_code; } if (*p_result_code != NRF_SUCCESS) { SER_ASSERT_LENGTH_EQ(index, packet_len); return NRF_SUCCESS; } uint8_dec(p_buf, packet_len, &index, &(p_version->version_number)); uint16_dec(p_buf, packet_len, &index, &(p_version->company_id)); uint16_dec(p_buf, packet_len, &index, &p_version->subversion_number); SER_ASSERT_LENGTH_EQ(index, packet_len); return status_code; }
uint32_t ant_channel_id_get_rsp_dec(uint8_t const * const p_buf, uint32_t packet_len, void * const p_device_number, void * const p_device_type, void * const p_transmit_type, uint32_t * const p_result_code) { SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_result_code); uint32_t index = 0; uint32_t err_code = ser_ble_cmd_rsp_result_code_dec(p_buf, &index, packet_len, SVC_ANT_CHANNEL_ID_GET, p_result_code); SER_ASSERT(err_code == NRF_SUCCESS, err_code); if (*p_result_code != NRF_SUCCESS) { SER_ASSERT_LENGTH_EQ(index, packet_len); return NRF_SUCCESS; } err_code = uint16_t_dec(p_buf, packet_len, &index, p_device_number); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = uint8_t_dec(p_buf, packet_len, &index, p_device_type); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = uint8_t_dec(p_buf, packet_len, &index, p_transmit_type); SER_ASSERT(err_code == NRF_SUCCESS, err_code); SER_ASSERT_LENGTH_EQ(index, packet_len); return NRF_SUCCESS; }
uint32_t ant_channel_radio_freq_get_rsp_dec(uint8_t const * const p_buf, uint32_t packet_len, void * const p_r_freq, uint32_t * const p_result_code) { SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_result_code); uint32_t index = 0; uint32_t err_code = ser_ble_cmd_rsp_result_code_dec(p_buf, &index, packet_len, SVC_ANT_CHANNEL_RADIO_FREQ_GET, p_result_code); SER_ASSERT(err_code == NRF_SUCCESS, err_code); if (*p_result_code != NRF_SUCCESS) { SER_ASSERT_LENGTH_EQ(index, packet_len); return NRF_SUCCESS; } err_code = uint8_t_dec(p_buf, packet_len, &index, p_r_freq); SER_ASSERT(err_code == NRF_SUCCESS, err_code); SER_ASSERT_LENGTH_EQ(index, packet_len); return NRF_SUCCESS; }
uint32_t ble_gap_sec_params_reply_rsp_dec(uint8_t const * const p_buf, uint32_t packet_len, ble_gap_sec_keyset_t const * const p_sec_keyset, uint32_t * const p_result_code) { SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_result_code); uint32_t err_code = NRF_SUCCESS; uint32_t index = 0; err_code = ser_ble_cmd_rsp_result_code_dec(p_buf, &index, packet_len, SD_BLE_GAP_SEC_PARAMS_REPLY, p_result_code); if (err_code != NRF_SUCCESS) { return err_code; } if (*p_result_code != NRF_SUCCESS) { SER_ASSERT_LENGTH_EQ(index, packet_len); return NRF_SUCCESS; } //SER_ASSERT_NOT_NULL(p_sec_keyset); // Removed after input from KC 2016-03-11 err_code = cond_field_dec(p_buf, packet_len, &index, (void **)&p_sec_keyset, ble_gap_sec_keyset_t_dec); SER_ASSERT(err_code == NRF_SUCCESS, err_code); SER_ASSERT_LENGTH_EQ(index, packet_len); return err_code; }
uint32_t ecb_block_encrypt_rsp_dec(uint8_t const * const p_buf, uint32_t packet_len, nrf_ecb_hal_data_t * p_ecb_data, uint32_t * const p_result_code) { SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_result_code); uint32_t index = 0; uint32_t decode_result = ser_ble_cmd_rsp_result_code_dec(p_buf, &index, packet_len, SD_ECB_BLOCK_ENCRYPT, p_result_code); if (decode_result != NRF_SUCCESS) { return decode_result; } if (*p_result_code != NRF_SUCCESS) { SER_ASSERT_LENGTH_EQ(index, packet_len); return NRF_SUCCESS; } uint32_t err_code = cond_field_dec(p_buf, packet_len, &index, (void **)&p_ecb_data, nrf_ecb_hal_data_t_out_dec); SER_ASSERT(err_code == NRF_SUCCESS, err_code); SER_ASSERT_LENGTH_EQ(index, packet_len); return NRF_SUCCESS; }
uint32_t ble_gatts_hvx_rsp_dec(uint8_t const * const p_buf, uint32_t packet_len, uint32_t * const p_result_code, uint16_t * * const pp_bytes_written) { SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_result_code); uint32_t err_code; uint32_t index = 0; uint32_t decode_result = ser_ble_cmd_rsp_result_code_dec(p_buf, &index, packet_len, SD_BLE_GATTS_HVX, p_result_code); if (decode_result != NRF_SUCCESS) { return decode_result; } if (*p_result_code != NRF_SUCCESS) { SER_ASSERT_LENGTH_EQ(index, packet_len); return NRF_SUCCESS; } err_code = cond_field_dec(p_buf, packet_len, &index, (void * *)pp_bytes_written, uint16_t_dec); SER_ASSERT(err_code == NRF_SUCCESS, err_code); SER_ASSERT_LENGTH_EQ(index, packet_len); return NRF_SUCCESS; }
uint32_t ble_opt_get_rsp_dec(uint8_t const * const p_buf, uint32_t packet_len, uint32_t * const p_opt_id, ble_opt_t * const p_opt, uint32_t * const p_result_code) { uint32_t index = 0; SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_opt_id); SER_ASSERT_NOT_NULL(p_opt); SER_ASSERT_NOT_NULL(p_result_code); uint32_t err_code = ser_ble_cmd_rsp_result_code_dec(p_buf, &index, packet_len, SD_BLE_OPT_GET, p_result_code); if (err_code != NRF_SUCCESS) { return err_code; } if (*p_result_code != NRF_SUCCESS) { SER_ASSERT_LENGTH_EQ(index, packet_len); return NRF_SUCCESS; } (void) uint32_t_dec(p_buf, packet_len, &index, p_opt_id); SER_ASSERT(((*p_opt_id == BLE_GAP_OPT_LOCAL_CONN_LATENCY) || (*p_opt_id == BLE_GAP_OPT_PASSKEY) || (*p_opt_id == BLE_GAP_OPT_PRIVACY)), NRF_ERROR_INVALID_PARAM); switch (*p_opt_id) { case BLE_GAP_OPT_LOCAL_CONN_LATENCY: err_code = ble_gap_opt_local_conn_latency_t_dec( p_buf, packet_len, &index, (void *)&(p_opt->gap.local_conn_latency)); break; case BLE_GAP_OPT_PASSKEY: err_code = ble_gap_opt_passkey_t_dec( p_buf, packet_len, &index, (void *)&(p_opt->gap.passkey) ); break; case BLE_GAP_OPT_PRIVACY: err_code = ble_gap_opt_privacy_t_dec( p_buf, packet_len, &index, (void *)&(p_opt->gap.privacy) ); break; } if (err_code != NRF_SUCCESS) { return err_code; } SER_ASSERT_LENGTH_EQ(index, packet_len); return err_code; }
uint32_t ble_uuid_decode_req_dec(uint8_t const * const p_buf, uint32_t const buf_len, uint8_t * p_uuid_le_len, uint8_t * * const pp_uuid_le, ble_uuid_t * * const pp_uuid) { SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_uuid_le_len); uint32_t err_code; uint32_t index = 0; uint8_t opcode = SD_BLE_UUID_DECODE; SER_ASSERT_LENGTH_LEQ(1, ((int32_t)buf_len - index)); uint8_dec(p_buf, buf_len, &index, &opcode); SER_ASSERT(opcode == SD_BLE_UUID_DECODE, NRF_ERROR_INVALID_DATA); err_code = len8data_dec(p_buf, buf_len, &index, pp_uuid_le, p_uuid_le_len); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = cond_field_dec(p_buf, buf_len, &index, (void * *)pp_uuid, NULL); SER_ASSERT(err_code == NRF_SUCCESS, err_code); SER_ASSERT_LENGTH_EQ(index, buf_len); return err_code; }
uint32_t ble_gap_lesc_oob_data_get_req_dec(uint8_t const * const p_buf, uint32_t packet_len, uint16_t * p_conn_handle, ble_gap_lesc_p256_pk_t * * pp_pk_own, ble_gap_lesc_oob_data_t * * pp_oobd_own) { uint32_t index = SER_CMD_HEADER_SIZE; uint32_t err_code = NRF_SUCCESS; SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_conn_handle); SER_ASSERT_NOT_NULL(pp_oobd_own); SER_ASSERT_NOT_NULL(pp_pk_own); err_code = uint16_t_dec(p_buf, packet_len, &index, p_conn_handle); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = cond_field_dec(p_buf, packet_len, &index, (void **)pp_pk_own, ble_gap_lesc_p256_pk_t_dec); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = cond_field_dec(p_buf, packet_len, &index, (void **)pp_oobd_own, NULL); SER_ASSERT(err_code == NRF_SUCCESS, err_code); SER_ASSERT_LENGTH_EQ(index, packet_len); return err_code; }
uint32_t ble_gattc_char_values_read_req_dec(uint8_t const * const p_buf, uint16_t packet_len, uint16_t * const p_conn_handle, uint16_t * * const pp_handles, uint16_t * const p_handle_count) { SER_ASSERT_NOT_NULL(p_buf); //check if *p_buf is allocated SER_ASSERT_NOT_NULL(p_conn_handle); //check if *p_conn_handle exist SER_ASSERT_NOT_NULL(pp_handles); //check if *p_handles exist SER_ASSERT_NOT_NULL(*pp_handles); //check if p_handles exist SER_ASSERT_NOT_NULL(p_handle_count); //check if *p_handle_count exist uint32_t index = SER_CMD_DATA_POS; uint32_t status_code; SER_ASSERT_LENGTH_LEQ(5, packet_len - index); //make sure that payload length is at least 5 bytes uint16_dec(p_buf, packet_len, &index, p_conn_handle); //decode handle table count with optional handle table status_code = count16_cond_data16_dec(p_buf, packet_len, &index, pp_handles, p_handle_count); SER_ASSERT(status_code == NRF_SUCCESS, status_code); SER_ASSERT_LENGTH_EQ(index, packet_len); return status_code; }
uint32_t ble_uuid_vs_add_req_dec(uint8_t const * const p_buf, uint16_t buf_len, ble_uuid128_t * * const pp_uuid, uint8_t * * const pp_uuid_type) { uint32_t index = SER_CMD_HEADER_SIZE; SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(pp_uuid); SER_ASSERT_NOT_NULL(pp_uuid_type); SER_ASSERT_NOT_NULL(*pp_uuid); SER_ASSERT_NOT_NULL(*pp_uuid_type); uint32_t err_code; err_code = cond_field_dec(p_buf, buf_len, &index, (void * *)pp_uuid, ble_uuid128_t_dec); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = cond_field_dec(p_buf, buf_len, &index, (void * *)pp_uuid_type, NULL); SER_ASSERT(err_code == NRF_SUCCESS, err_code); SER_ASSERT_LENGTH_EQ(index, buf_len); return err_code; }
uint32_t ble_gap_device_name_set_req_dec(uint8_t const * const p_buf, uint32_t packet_len, ble_gap_conn_sec_mode_t * * const pp_write_perm, uint8_t * * const pp_dev_name, uint16_t * const p_dev_name_len) { SER_ASSERT_NOT_NULL(p_buf); //check if *p_buf is allocated SER_ASSERT_NOT_NULL(pp_write_perm); //check if *pp_write_perm exist SER_ASSERT_NOT_NULL(pp_dev_name); //check if *pp_dev_name exist SER_ASSERT_NOT_NULL(p_dev_name_len); //check if *p_dev_name_len exist uint32_t index = SER_CMD_DATA_POS; uint32_t status_code; SER_ASSERT_LENGTH_LEQ(4, packet_len - index); //make sure that payload is at least 4 bytes //decode optional write permissions field status_code = cond_field_dec(p_buf, packet_len, &index, (void * *)pp_write_perm, ble_gap_conn_sec_mode_dec); SER_ASSERT(status_code == NRF_SUCCESS, status_code); //decode optional device name field status_code = len16data_dec(p_buf, packet_len, &index, pp_dev_name, p_dev_name_len); SER_ASSERT(status_code == NRF_SUCCESS, status_code); SER_ASSERT_LENGTH_EQ(index, packet_len); return status_code; }
uint32_t temp_get_rsp_dec(uint8_t const * const p_buf, uint32_t packet_len, uint32_t * const p_result_code, int32_t * const p_temp) { SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_result_code); SER_ASSERT_NOT_NULL(p_temp); uint32_t index = 0; uint32_t err_code = NRF_SUCCESS; err_code = ser_ble_cmd_rsp_result_code_dec(p_buf, &index, packet_len, SD_TEMP_GET, p_result_code); SER_ASSERT(err_code == NRF_SUCCESS, err_code); if (*p_result_code != NRF_SUCCESS) { return NRF_SUCCESS; } err_code = uint32_t_dec(p_buf, packet_len, &index, p_temp); SER_ASSERT(err_code == NRF_SUCCESS, err_code); SER_ASSERT_LENGTH_EQ(index, packet_len); return err_code; }
uint32_t ble_evt_tx_complete_dec(uint8_t const * const p_buf, uint32_t packet_len, ble_evt_t * const p_event, uint32_t * const p_event_len) { uint32_t index = 0; SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_event_len); SER_ASSERT_LENGTH_LEQ(SER_EVT_CONN_HANDLE_SIZE + 1, packet_len); uint32_t event_len = SER_EVT_CONN_HANDLE_SIZE + sizeof (ble_evt_tx_complete_t); if (p_event == NULL) { *p_event_len = event_len; return NRF_SUCCESS; } SER_ASSERT(event_len <= *p_event_len, NRF_ERROR_DATA_SIZE); p_event->header.evt_id = BLE_EVT_TX_COMPLETE; p_event->header.evt_len = event_len; uint16_dec(p_buf, packet_len, &index, &p_event->evt.common_evt.conn_handle); uint8_dec(p_buf, packet_len, &index, &p_event->evt.common_evt.params.tx_complete.count); SER_ASSERT_LENGTH_EQ(index, packet_len); *p_event_len = event_len; return NRF_SUCCESS; }
uint32_t ant_broadcast_message_tx_req_dec(uint8_t const * const p_buf, uint32_t packet_len, uint8_t * const p_channel, uint8_t * const p_size, uint8_t * * const pp_mesg) { uint32_t index = SER_CMD_DATA_POS; uint32_t err_code; SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_channel); SER_ASSERT_NOT_NULL(p_size); SER_ASSERT_NOT_NULL(*pp_mesg); err_code = uint8_t_dec(p_buf, packet_len, &index, p_channel); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = uint8_t_dec(p_buf, packet_len, &index, p_size); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = uint8_vector_dec(p_buf, packet_len, &index, *pp_mesg, *p_size); SER_ASSERT(err_code == NRF_SUCCESS, err_code); SER_ASSERT_LENGTH_EQ(index, packet_len); return err_code; }
uint32_t ant_crypto_channel_enable_req_dec(uint8_t const * const p_buf, uint32_t packet_len, uint8_t * const p_channel, uint8_t * const p_enable, uint8_t * const p_key_num, uint8_t * const p_decimation_rate) { uint32_t index = SER_CMD_DATA_POS; uint32_t err_code; SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_channel); SER_ASSERT_NOT_NULL(p_enable); SER_ASSERT_NOT_NULL(p_key_num); SER_ASSERT_NOT_NULL(p_decimation_rate); err_code = uint8_t_dec(p_buf, packet_len, &index, p_channel); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = uint8_t_dec(p_buf, packet_len, &index, p_enable); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = uint8_t_dec(p_buf, packet_len, &index, p_key_num); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = uint8_t_dec(p_buf, packet_len, &index, p_decimation_rate); SER_ASSERT(err_code == NRF_SUCCESS, err_code); SER_ASSERT_LENGTH_EQ(index, packet_len); return err_code; }
uint32_t ble_gatts_evt_hvc_dec(uint8_t const * const p_buf, uint32_t packet_len, ble_evt_t * const p_event, uint32_t * const p_event_len) { uint32_t index = 0; SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_event_len); SER_ASSERT_LENGTH_LEQ(SER_EVT_CONN_HANDLE_SIZE + 1, packet_len); uint32_t event_len = SER_EVT_CONN_HANDLE_SIZE + sizeof (ble_gatts_evt_hvc_t); if (p_event == NULL) { *p_event_len = event_len; return NRF_SUCCESS; } SER_ASSERT(event_len <= *p_event_len, NRF_ERROR_DATA_SIZE); p_event->header.evt_id = BLE_GATTS_EVT_HVC; p_event->header.evt_len = event_len; uint16_dec(p_buf, packet_len, &index, &p_event->evt.gatts_evt.conn_handle); uint16_dec(p_buf, packet_len, &index, &p_event->evt.gatts_evt.params.hvc.handle); SER_ASSERT_LENGTH_EQ(index, packet_len); *p_event_len = event_len; return NRF_SUCCESS; }
uint32_t ble_gap_authenticate_req_dec(uint8_t const * const p_buf, uint32_t packet_len, uint16_t * const p_conn_handle, ble_gap_sec_params_t * * const pp_sec_params) { uint32_t index = SER_CMD_DATA_POS; SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_conn_handle); SER_ASSERT_NOT_NULL(pp_sec_params); SER_ASSERT_NOT_NULL(*pp_sec_params); uint32_t err_code = NRF_SUCCESS; err_code = uint16_t_dec(p_buf, packet_len, &index, p_conn_handle); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = cond_field_dec(p_buf, packet_len, &index, (void * *)pp_sec_params, ble_gap_sec_params_t_dec); SER_ASSERT(err_code == NRF_SUCCESS, err_code); SER_ASSERT_LENGTH_EQ(index, packet_len); return err_code; }
uint32_t ant_crypto_info_set_req_dec(uint8_t const * const p_buf, uint32_t packet_len, uint8_t * const p_type, uint8_t * * const pp_info) { uint32_t index = SER_CMD_DATA_POS; uint32_t err_code; SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_type); SER_ASSERT_NOT_NULL(*pp_info); err_code = uint8_t_dec(p_buf, packet_len, &index, p_type); SER_ASSERT(err_code == NRF_SUCCESS, err_code); uint8_t crypto_info_size = (MESG_CONFIG_ENCRYPT_REQ_CONFIG_USER_DATA_SIZE - MESG_CHANNEL_NUM_SIZE) + (MESG_CONFIG_ENCRYPT_REQ_CONFIG_ID_SIZE - MESG_CHANNEL_NUM_SIZE); err_code = uint8_vector_dec(p_buf, packet_len, &index, *pp_info, crypto_info_size); SER_ASSERT(err_code == NRF_SUCCESS, err_code); SER_ASSERT_LENGTH_EQ(index, packet_len); return err_code; }
uint32_t ble_gattc_char_value_by_uuid_read_req_dec( uint8_t const * const p_buf, uint16_t buf_len, uint16_t * const p_conn_handle, ble_uuid_t * * const pp_uuid, ble_gattc_handle_range_t * * const pp_handle_range) { SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_conn_handle); SER_ASSERT_NOT_NULL(pp_uuid); SER_ASSERT_NOT_NULL(*pp_uuid); SER_ASSERT_NOT_NULL(pp_handle_range); SER_ASSERT_NOT_NULL(*pp_handle_range); uint32_t index = 0; uint32_t err_code; SER_ASSERT_LENGTH_LEQ(SER_CMD_HEADER_SIZE + 2, buf_len); SER_ASSERT(p_buf[index] == SD_BLE_GATTC_CHAR_VALUE_BY_UUID_READ, NRF_ERROR_INVALID_DATA); index++; uint16_dec(p_buf, buf_len, &index, p_conn_handle); err_code = cond_field_dec(p_buf, buf_len, &index, (void * *)pp_uuid, ble_uuid_t_dec); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = cond_field_dec(p_buf, buf_len, &index, (void * *)pp_handle_range, ble_gattc_handle_range_t_dec); SER_ASSERT(err_code == NRF_SUCCESS, err_code); SER_ASSERT_LENGTH_EQ(index, buf_len); return err_code; }
uint32_t ble_gap_disconnect_req_dec(uint8_t const * const p_buf, uint32_t packet_len, uint16_t * const p_conn_handle, uint8_t * const p_hci_status) { SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_conn_handle); SER_ASSERT_NOT_NULL(p_hci_status); uint8_t opcode; uint32_t index = 0; uint32_t err_code = NRF_SUCCESS; err_code = uint8_t_dec(p_buf, packet_len, &index, &opcode); SER_ASSERT(err_code == NRF_SUCCESS, err_code); SER_ASSERT(opcode == SD_BLE_GAP_DISCONNECT, NRF_ERROR_INVALID_PARAM); err_code = uint16_t_dec(p_buf, packet_len, &index, p_conn_handle); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = uint8_t_dec(p_buf, packet_len, &index, p_hci_status); SER_ASSERT(err_code == NRF_SUCCESS, err_code); SER_ASSERT_LENGTH_EQ(index, packet_len); return err_code; }
uint32_t ble_gatts_evt_rw_authorize_request_dec(uint8_t const * const p_buf, uint32_t packet_len, ble_evt_t * const p_event, uint32_t * const p_event_len) { SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_event_len); uint32_t index = 0; uint32_t err_code = NRF_SUCCESS; uint32_t in_event_len = *p_event_len; *p_event_len = offsetof(ble_evt_t, evt.gatts_evt.params) - sizeof (ble_evt_hdr_t); uint16_t conn_handle; err_code = uint16_t_dec(p_buf, packet_len, &index, &conn_handle); SER_ASSERT(err_code == NRF_SUCCESS, err_code); void * p_void_authorize_request = NULL; if (p_event != NULL) { SER_ASSERT_LENGTH_LEQ(*p_event_len, in_event_len); p_event->header.evt_id = BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST; p_event->evt.gatts_evt.conn_handle = conn_handle; p_void_authorize_request = &(p_event->evt.gatts_evt.params.authorize_request); } uint32_t tmp_event_len = in_event_len - *p_event_len; err_code = ble_gatts_evt_rw_authorize_request_t_dec(p_buf, packet_len, &index, &tmp_event_len, p_void_authorize_request); SER_ASSERT(err_code == NRF_SUCCESS, err_code); *p_event_len += tmp_event_len; if(p_event != NULL) { if((p_event->evt.gatts_evt.params.authorize_request.type == BLE_GATTS_AUTHORIZE_TYPE_WRITE) && (p_event->evt.gatts_evt.params.authorize_request.request.write.op == BLE_GATTS_OP_EXEC_WRITE_REQ_NOW)) { uint32_t conn_index; if(app_ble_user_mem_context_find(p_event->evt.gatts_evt.conn_handle, &conn_index) != NRF_ERROR_NOT_FOUND) { err_code = len16data_dec(p_buf, packet_len, &index, &m_app_user_mem_table[conn_index].mem_block.p_mem, &m_app_user_mem_table[conn_index].mem_block.len); SER_ASSERT(err_code == NRF_SUCCESS, err_code); } } } SER_ASSERT_LENGTH_EQ(index, packet_len); return err_code; }
uint32_t ble_evt_user_mem_release_dec(uint8_t const * const p_buf, uint32_t packet_len, ble_evt_t * const p_event, uint32_t * const p_event_len) { SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_event); SER_ASSERT_NOT_NULL(p_event_len); uint32_t index = 0; uint32_t err_code = NRF_SUCCESS; uint32_t event_len = (uint16_t) (offsetof(ble_evt_t, evt.common_evt.params.user_mem_release)) + sizeof (ble_evt_user_mem_release_t) - sizeof (ble_evt_hdr_t); if (p_event == NULL) { *p_event_len = event_len; return NRF_SUCCESS; } p_event->header.evt_id = BLE_EVT_USER_MEM_RELEASE; p_event->header.evt_len = event_len; ble_evt_user_mem_release_t * p_user_mem_rel = &(p_event->evt.common_evt.params.user_mem_release); err_code = uint16_t_dec(p_buf, packet_len, &index, &(p_event->evt.common_evt.conn_handle)); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = uint8_t_dec(p_buf, packet_len, &index, &(p_user_mem_rel->type)); SER_ASSERT(err_code == NRF_SUCCESS, err_code); // Decoding order of mem block is different than structure elements order - length is decoded first err_code = uint16_t_dec(p_buf, packet_len, &index, &(p_user_mem_rel->mem_block.len)); SER_ASSERT(err_code == NRF_SUCCESS, err_code); if (p_buf[index++] == SER_FIELD_PRESENT) { // Using connection handle find which mem block to release in Application Processor uint32_t user_mem_table_index; err_code = app_ble_user_mem_context_find(p_event->evt.common_evt.conn_handle, &user_mem_table_index); SER_ASSERT(err_code == NRF_SUCCESS, err_code); p_user_mem_rel->mem_block.p_mem = m_app_user_mem_table[user_mem_table_index].mem_block.p_mem; } else { p_user_mem_rel->mem_block.p_mem = NULL; } // Now user memory context can be released err_code = app_ble_user_mem_context_destroy(p_event->evt.common_evt.conn_handle); SER_ASSERT(err_code == NRF_SUCCESS, err_code); SER_ASSERT_LENGTH_EQ(index, packet_len); *p_event_len = event_len; return err_code; }
uint32_t ble_gattc_evt_desc_disc_rsp_dec(uint8_t const * const p_buf, uint32_t packet_len, ble_evt_t * const p_event, uint32_t * const p_event_len) { uint32_t index = 0; SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_event_len); SER_ASSERT_LENGTH_LEQ(SER_EVT_CONN_HANDLE_SIZE + 6, packet_len); uint16_t tmp_conn_handle; uint16_t tmp_gatt_status; uint16_t tmp_error_handle; uint16_t tmp_service_count; uint16_dec(p_buf, packet_len, &index, &tmp_conn_handle); uint16_dec(p_buf, packet_len, &index, &tmp_gatt_status); uint16_dec(p_buf, packet_len, &index, &tmp_error_handle); uint16_dec(p_buf, packet_len, &index, &tmp_service_count); uint32_t event_len = offsetof(ble_evt_t, evt.gattc_evt.params.desc_disc_rsp) + sizeof (uint16_t) + tmp_service_count * sizeof (ble_gattc_desc_t); if (p_event == NULL) { *p_event_len = event_len; return NRF_SUCCESS; } SER_ASSERT(event_len <= *p_event_len, NRF_ERROR_DATA_SIZE); p_event->header.evt_id = BLE_GATTC_EVT_DESC_DISC_RSP; p_event->header.evt_len = event_len; p_event->evt.gattc_evt.conn_handle = tmp_conn_handle; p_event->evt.gattc_evt.gatt_status = tmp_gatt_status; p_event->evt.gattc_evt.error_handle = tmp_error_handle; p_event->evt.gattc_evt.params.desc_disc_rsp.count = tmp_service_count; SER_ASSERT_LENGTH_LEQ(index + (tmp_service_count * 5), packet_len); for (uint16_t i = 0; i < tmp_service_count; i++) { uint16_dec(p_buf, packet_len, &index, &p_event->evt.gattc_evt.params.desc_disc_rsp.descs[i].handle); uint16_dec(p_buf, packet_len, &index, &p_event->evt.gattc_evt.params.desc_disc_rsp.descs[i].uuid.uuid); uint8_dec(p_buf, packet_len, &index, &p_event->evt.gattc_evt.params.desc_disc_rsp.descs[i].uuid.type); } SER_ASSERT_LENGTH_EQ(index, packet_len); *p_event_len = event_len; return NRF_SUCCESS; }