uint32_t ble_common_opt_pa_lna_t_dec(uint8_t const * const p_buf, uint32_t buf_len, uint32_t * const p_index, void * const p_void_opt) { SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_index); SER_ASSERT_NOT_NULL(p_void_opt); ble_common_opt_pa_lna_t * p_opt = (ble_common_opt_pa_lna_t *)p_void_opt; uint32_t err_code = NRF_SUCCESS; err_code = ble_pa_lna_cfg_t_dec(p_buf, buf_len, p_index, &p_opt->pa_cfg); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = ble_pa_lna_cfg_t_dec(p_buf, buf_len, p_index, &p_opt->lna_cfg); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = uint8_t_dec(p_buf, buf_len, p_index, &p_opt->ppi_ch_id_set); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = uint8_t_dec(p_buf, buf_len, p_index, &p_opt->ppi_ch_id_clr); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = uint8_t_dec(p_buf, buf_len, p_index, &p_opt->gpiote_ch_id); SER_ASSERT(err_code == NRF_SUCCESS, err_code); return err_code; }
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_ENABLE_dec(uint8_t const * const p_buf, uint32_t buf_len, uint32_t * const p_index, void * const p_void_enable_params) { SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_index); SER_ASSERT_NOT_NULL(p_void_enable_params); ANT_ENABLE * p_enable_params = (ANT_ENABLE *)p_void_enable_params; uint32_t err_code = NRF_SUCCESS; err_code = uint8_t_dec(p_buf, buf_len, p_index, &p_enable_params->ucTotalNumberOfChannels); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = uint8_t_dec(p_buf, buf_len, p_index, &p_enable_params->ucNumberOfEncryptedChannels); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = uint16_t_dec(p_buf, buf_len, p_index, &p_enable_params->usNumberOfEvents); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = uint32_t_dec(p_buf, buf_len, p_index, &p_enable_params->pucMemoryBlockStartLocation); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = uint16_t_dec(p_buf, buf_len, p_index, &p_enable_params->usMemoryBlockByteSize); SER_ASSERT(err_code == NRF_SUCCESS, err_code); 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_gattc_write_params_t_dec(uint8_t const * const p_buf, uint32_t buf_len, uint32_t * const p_index, void * const p_void_write) { SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_index); SER_ASSERT_NOT_NULL(p_void_write); uint32_t err_code = NRF_SUCCESS; ble_gattc_write_params_t * p_write = (ble_gattc_write_params_t *)p_void_write; err_code = uint8_t_dec(p_buf, buf_len, p_index, &(p_write->write_op)); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = uint8_t_dec(p_buf, buf_len, p_index, &(p_write->flags)); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = uint16_t_dec(p_buf, buf_len, p_index, &(p_write->handle)); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = uint16_t_dec(p_buf, buf_len, p_index, &(p_write->offset)); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = len16data_dec(p_buf, buf_len, p_index, &(p_write->p_value), &(p_write->len)); SER_ASSERT(err_code == NRF_SUCCESS, err_code); return err_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_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_gap_evt_adv_report_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; uint32_t err_code = NRF_SUCCESS; uint8_t byte; SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_event_len); SER_ASSERT_LENGTH_LEQ(SER_EVT_CONN_HANDLE_SIZE+7+1+1, packet_len); // assumed size(data) = 0 uint32_t event_len = (uint16_t) (offsetof(ble_evt_t, evt.gap_evt.params.adv_report)) + sizeof (ble_gap_evt_adv_report_t) - sizeof (ble_evt_hdr_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_GAP_EVT_ADV_REPORT; p_event->header.evt_len = event_len; err_code = uint16_t_dec(p_buf, packet_len, &index, &(p_event->evt.gap_evt.conn_handle)); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = ble_gap_addr_dec(p_buf, packet_len, &index, &(p_event->evt.gap_evt.params.adv_report.peer_addr)); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = uint8_t_dec(p_buf, packet_len, &index, &(p_event->evt.gap_evt.params.adv_report.rssi)); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = uint8_t_dec(p_buf, packet_len, &index, &byte); SER_ASSERT(err_code == NRF_SUCCESS, err_code); p_event->evt.gap_evt.params.adv_report.scan_rsp = byte & 0x01; p_event->evt.gap_evt.params.adv_report.type = (byte >> 1) & 0x03; p_event->evt.gap_evt.params.adv_report.dlen = (byte >> 3) & 0x1F; err_code = uint8_vector_dec(p_buf, packet_len, &index, p_event->evt.gap_evt.params.adv_report.data, (uint16_t)(p_event->evt.gap_evt.params.adv_report.dlen)); 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 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 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_gatts_service_add_req_dec(uint8_t const * const p_buf, uint32_t buf_len, uint8_t * const p_type, ble_uuid_t * * const pp_uuid, uint16_t * * const pp_handle) { SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_type); SER_ASSERT_NOT_NULL(pp_uuid); SER_ASSERT_NOT_NULL(*pp_uuid); SER_ASSERT_NOT_NULL(pp_handle); SER_ASSERT_NOT_NULL(*pp_handle); uint32_t index = SER_CMD_DATA_POS; uint32_t err_code; SER_ASSERT_LENGTH_LEQ(3, buf_len - index); err_code = uint8_t_dec(p_buf, buf_len, &index, p_type); SER_ASSERT(err_code == NRF_SUCCESS, err_code); 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, NULL); SER_ASSERT(err_code == NRF_SUCCESS, err_code); SER_ASSERT(index == buf_len, NRF_ERROR_INVALID_LENGTH); return err_code; }
uint32_t ble_gatts_evt_write_t_dec(uint8_t const * const p_buf, uint32_t buf_len, uint32_t * const p_index, uint32_t * const p_struct_len, void * const p_void_write) { SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_index); SER_ASSERT_NOT_NULL(p_struct_len); uint32_t err_code = NRF_SUCCESS; uint32_t in_struct_len = *p_struct_len; *p_struct_len = offsetof(ble_gatts_evt_write_t, data); uint16_t handle; err_code = uint16_t_dec(p_buf, buf_len, p_index, &handle); SER_ASSERT(err_code == NRF_SUCCESS, err_code); uint8_t op; err_code = uint8_t_dec(p_buf, buf_len, p_index, &op); SER_ASSERT(err_code == NRF_SUCCESS, err_code); ble_gatts_attr_context_t context; err_code = ble_gatts_attr_context_t_dec(p_buf, buf_len, p_index, &context); SER_ASSERT(err_code == NRF_SUCCESS, err_code); uint16_t offset; err_code = uint16_t_dec(p_buf, buf_len, p_index, &offset); SER_ASSERT(err_code == NRF_SUCCESS, err_code); uint16_t len; err_code = uint16_t_dec(p_buf, buf_len, p_index, &len); SER_ASSERT(err_code == NRF_SUCCESS, err_code); *p_struct_len += len; if (p_void_write != NULL) { ble_gatts_evt_write_t * p_write = (ble_gatts_evt_write_t *)p_void_write; SER_ASSERT_LENGTH_LEQ(*p_struct_len, in_struct_len); p_write->handle = handle; p_write->op = op; memcpy(&(p_write->context), &context, sizeof (ble_gatts_attr_context_t)); p_write->offset = offset; p_write->len = len; SER_ASSERT_LENGTH_LEQ(p_write->len, buf_len - *p_index); memcpy(p_write->data, &p_buf[*p_index], p_write->len); } *p_index += 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_conn_bw_t_dec(uint8_t const * const p_buf, uint32_t buf_len, uint32_t * const p_index, void * const p_void_conn_bw) { SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_index); SER_ASSERT_NOT_NULL(p_void_conn_bw); ble_conn_bw_t * p_conn_bw = (ble_conn_bw_t *)p_void_conn_bw; uint32_t err_code = NRF_SUCCESS; err_code = uint8_t_dec(p_buf, buf_len, p_index, &p_conn_bw->conn_bw_rx); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = uint8_t_dec(p_buf, buf_len, p_index, &p_conn_bw->conn_bw_tx); SER_ASSERT(err_code == NRF_SUCCESS, err_code); return err_code; }
uint32_t ant_channel_low_priority_rx_search_timeout_set_req_dec(uint8_t const * const p_buf, uint32_t packet_len, uint8_t * const p_channel, uint8_t * const p_timeout) { 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_timeout); 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_timeout); SER_ASSERT(err_code == NRF_SUCCESS, err_code); SER_ASSERT_LENGTH_EQ(index, packet_len); return err_code; }
uint32_t ble_gap_evt_lesc_dhkey_request_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; uint32_t err_code = NRF_SUCCESS; uint32_t conn_index; SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_event_len); // [minimal packet is: 'conn_handle' + 'p_pk_peer' SER_FIELD_NOT_PRESENT + // 'oobd_req'] SER_ASSERT_LENGTH_LEQ(sizeof(uint16_t) + sizeof(uint8_t) + sizeof(uint8_t), packet_len); uint32_t event_len = offsetof (ble_gap_evt_t, params) + sizeof(uint8_t) + sizeof(uint8_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_len = event_len; err_code = uint16_t_dec(p_buf, packet_len, &index, &p_event->evt.gap_evt.conn_handle); SER_ASSERT(err_code == NRF_SUCCESS, err_code); // keyset is an extension of standard event data - used to synchronize keys at application err_code = app_ble_gap_sec_context_find(p_event->evt.gap_evt.conn_handle, &conn_index); SER_ASSERT(err_code == NRF_SUCCESS, err_code); p_event->evt.gap_evt.params.lesc_dhkey_request.p_pk_peer = m_app_keys_table[conn_index].keyset.keys_peer.p_pk; err_code = cond_field_dec(p_buf, packet_len, &index, (void **)&p_event->evt.gap_evt.params.lesc_dhkey_request.p_pk_peer, ble_gap_lesc_p256_pk_t_dec); SER_ASSERT(err_code == NRF_SUCCESS, err_code); uint8_t data; err_code = uint8_t_dec(p_buf, packet_len, &index, &data); SER_ASSERT(err_code == NRF_SUCCESS, err_code); p_event->evt.gap_evt.params.lesc_dhkey_request.oobd_req = data & 0x01; SER_ASSERT_LENGTH_EQ(index, packet_len); *p_event_len = event_len; return err_code; }
uint32_t ble_conn_bw_count_t_dec(uint8_t const * const p_buf, uint32_t buf_len, uint32_t * const p_index, void * const p_void_conn_bw_count) { SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_index); SER_ASSERT_NOT_NULL(p_void_conn_bw_count); ble_conn_bw_count_t * p_conn_bw_count = (ble_conn_bw_count_t *)p_void_conn_bw_count; uint32_t err_code = NRF_SUCCESS; err_code = uint8_t_dec(p_buf, buf_len, p_index, &p_conn_bw_count->high_count); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = uint8_t_dec(p_buf, buf_len, p_index, &p_conn_bw_count->mid_count); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = uint8_t_dec(p_buf, buf_len, p_index, &p_conn_bw_count->low_count); SER_ASSERT(err_code == NRF_SUCCESS, err_code); return err_code; }
uint32_t ant_evt_t_dec(uint8_t const * const p_buf, uint32_t buf_len, uint32_t * const p_index, void * const p_void_ant_evt) { SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_index); SER_ASSERT_NOT_NULL(p_void_ant_evt); ant_evt_t * p_ant_evt = (ant_evt_t *)p_void_ant_evt; uint32_t err_code = NRF_SUCCESS; memcpy(p_ant_evt->msg.evt_buffer, &p_buf[*p_index], ANT_STACK_EVT_MSG_BUF_SIZE); // Size + sizeof(size) & sizeof(msg id) *p_index += ANT_STACK_EVT_MSG_BUF_SIZE; err_code = uint8_t_dec(p_buf, buf_len, p_index, &p_ant_evt->event); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = uint8_t_dec(p_buf, buf_len, p_index, &p_ant_evt->channel); SER_ASSERT(err_code == NRF_SUCCESS, err_code); return err_code; }
uint32_t len8data_dec(uint8_t const * const p_buf, uint32_t buf_len, uint32_t * const p_index, uint8_t * * const pp_data, uint8_t * const p_len) { uint32_t err_code = NRF_SUCCESS; uint16_t out_buf_len = *p_len; err_code = uint8_t_dec(p_buf, buf_len, p_index, p_len); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = buf_dec(p_buf, buf_len, p_index, pp_data, out_buf_len, *p_len); SER_ASSERT(err_code == NRF_SUCCESS, err_code); return err_code; }
uint32_t ant_coex_config_get_req_dec(uint8_t const * const p_buf, uint16_t packet_len, uint8_t * const p_channel) { uint32_t index = SER_CMD_DATA_POS; uint32_t err_code; SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_channel); err_code = uint8_t_dec(p_buf, packet_len, &index, p_channel); SER_ASSERT(err_code == NRF_SUCCESS, err_code); SER_ASSERT_LENGTH_EQ(index, packet_len); return err_code; }
uint32_t ble_gap_tx_power_set_req_dec(uint8_t const * const p_buf, uint32_t packet_len, int8_t * p_tx_power) { SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_tx_power); uint32_t err_code = NRF_SUCCESS; uint32_t index = SER_CMD_DATA_POS; err_code = uint8_t_dec(p_buf, packet_len, &index, p_tx_power); SER_ASSERT(err_code == NRF_SUCCESS, err_code); SER_ASSERT_LENGTH_EQ(index, packet_len); return NRF_SUCCESS; }
uint32_t ble_gatts_enable_params_t_dec(uint8_t const * const p_buf, uint32_t buf_len, uint32_t * const p_index, void * const p_void_struct) { ble_gatts_enable_params_t * p_enable_params = (ble_gatts_enable_params_t *)p_void_struct; uint32_t err_code = NRF_SUCCESS; uint8_t temp8 = 0; err_code = uint8_t_dec(p_buf, buf_len, p_index, (void *) &temp8); SER_ASSERT(err_code == NRF_SUCCESS, err_code); p_enable_params->service_changed = temp8 & 0x01; err_code = uint32_t_dec(p_buf, buf_len, p_index, (void *) &(p_enable_params->attr_tab_size)); SER_ASSERT(err_code == NRF_SUCCESS, err_code); return err_code; }
uint32_t ble_common_opt_radio_cpu_mutex_t_dec(uint8_t const * const p_buf, uint32_t buf_len, uint32_t * const p_index, void * const p_void_opt_mutex) { SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_index); SER_ASSERT_NOT_NULL(p_void_opt_mutex); ble_common_opt_radio_cpu_mutex_t * p_radio_cpu_mutex = (ble_common_opt_radio_cpu_mutex_t *)p_void_opt_mutex; uint32_t err_code = NRF_SUCCESS; uint8_t byte; err_code = uint8_t_dec(p_buf, buf_len, p_index, &byte); SER_ASSERT(err_code == NRF_SUCCESS, err_code); p_radio_cpu_mutex->enable = byte & 0x01; return err_code; }
uint32_t ble_gap_evt_scan_req_report_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; uint32_t err_code = NRF_SUCCESS; SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_event_len); uint32_t event_len = (uint16_t) (offsetof(ble_evt_t, evt.gap_evt.params.scan_req_report)) + sizeof (ble_gap_evt_scan_req_report_t) - sizeof (ble_evt_hdr_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_GAP_EVT_SCAN_REQ_REPORT; p_event->header.evt_len = event_len; err_code = uint16_t_dec(p_buf, packet_len, &index, &(p_event->evt.gap_evt.conn_handle)); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = ble_gap_addr_dec(p_buf, packet_len, &index, &(p_event->evt.gap_evt.params.scan_req_report.peer_addr)); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = uint8_t_dec(p_buf, packet_len, &index, &(p_event->evt.gap_evt.params.scan_req_report.rssi)); 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_gap_keypress_notify_req_dec(uint8_t const * const p_buf, uint32_t packet_len, uint16_t * p_conn_handle, uint8_t * p_kp_not) { 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(p_kp_not); 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_kp_not); SER_ASSERT(err_code == NRF_SUCCESS, err_code); SER_ASSERT_LENGTH_EQ(index, packet_len); return err_code; }
uint32_t ble_pa_lna_cfg_t_dec(uint8_t const * const p_buf, uint32_t buf_len, uint32_t * const p_index, void * const p_void_cfg) { SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_index); SER_ASSERT_NOT_NULL(p_void_cfg); ble_pa_lna_cfg_t * p_cfg = (ble_pa_lna_cfg_t *)p_void_cfg; uint32_t err_code = NRF_SUCCESS; uint8_t data; err_code = uint8_t_dec(p_buf, buf_len, p_index, &data); SER_ASSERT(err_code == NRF_SUCCESS, err_code); p_cfg->enable = data & 0x01; p_cfg->active_high = (data >> 1) & 0x01; p_cfg->gpio_pin = (data >> 2); return err_code; }
uint32_t ble_gap_adv_start_req_dec(uint8_t const * const p_buf, uint32_t packet_len, ble_gap_adv_params_t * * const pp_adv_params) { uint32_t index = 0, i = 0; uint32_t err_code = NRF_SUCCESS; SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(pp_adv_params); SER_ASSERT_NOT_NULL(*pp_adv_params); SER_ASSERT_NOT_NULL((*pp_adv_params)->p_peer_addr); SER_ASSERT_NOT_NULL((*pp_adv_params)->p_whitelist); SER_ASSERT_NOT_NULL((*pp_adv_params)->p_whitelist->pp_addrs); SER_ASSERT_NOT_NULL((*pp_adv_params)->p_whitelist->pp_irks); for (i = 0; i < BLE_GAP_WHITELIST_ADDR_MAX_COUNT; i++) { SER_ASSERT_NOT_NULL((*pp_adv_params)->p_whitelist->pp_addrs[i]); } for (i = 0; i < BLE_GAP_WHITELIST_IRK_MAX_COUNT; i++) { SER_ASSERT_NOT_NULL((*pp_adv_params)->p_whitelist->pp_irks[i]); } /* Packet with variable length. */ /* For now check: opcode + indicator showing if ble_gap_adv_params_t struct is present. */ SER_ASSERT_LENGTH_LEQ(SER_CMD_HEADER_SIZE + 1, packet_len); SER_ASSERT(p_buf[index] == SD_BLE_GAP_ADV_START, NRF_ERROR_INVALID_PARAM); index++; if (p_buf[index++] == SER_FIELD_PRESENT) { err_code = uint8_t_dec(p_buf, packet_len, &index, &((*pp_adv_params)->type)); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = cond_field_dec(p_buf, packet_len, &index, (void **) &((*pp_adv_params)->p_peer_addr), ble_gap_addr_dec); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = uint8_t_dec(p_buf, packet_len, &index, &((*pp_adv_params)->fp)); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = cond_field_dec(p_buf, packet_len, &index, (void **) &((*pp_adv_params)->p_whitelist), ble_gap_whitelist_t_dec); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = uint16_t_dec(p_buf, packet_len, &index, &((*pp_adv_params)->interval)); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = uint16_t_dec(p_buf, packet_len, &index, &((*pp_adv_params)->timeout)); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = ble_gap_adv_ch_mask_t_dec(p_buf, packet_len, &index, &((*pp_adv_params)->channel_mask)); SER_ASSERT(err_code == NRF_SUCCESS, err_code); } else { *pp_adv_params = NULL; } SER_ASSERT_LENGTH_EQ(index, packet_len); return NRF_SUCCESS; }
uint32_t ble_gatts_evt_rw_authorize_request_t_dec(uint8_t const * const p_buf, uint32_t buf_len, uint32_t * const p_index, uint32_t * const p_struct_len, void * const p_void_authorize_request) { SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_struct_len); SER_ASSERT_NOT_NULL(p_index); uint32_t err_code = NRF_SUCCESS; uint8_t type; err_code = uint8_t_dec(p_buf, buf_len, p_index, &type); SER_ASSERT(err_code == NRF_SUCCESS, err_code); uint32_t in_struct_len = *p_struct_len; *p_struct_len = offsetof(ble_gatts_evt_rw_authorize_request_t, request); ble_gatts_evt_rw_authorize_request_t * p_authorize_request = (ble_gatts_evt_rw_authorize_request_t *)p_void_authorize_request; void * p_void_request = NULL; if (p_void_authorize_request != NULL) { p_authorize_request->type = type; SER_ASSERT_LENGTH_LEQ(*p_struct_len, in_struct_len); switch (type) { case BLE_GATTS_AUTHORIZE_TYPE_READ: p_void_request = &(p_authorize_request->request.read); break; case BLE_GATTS_AUTHORIZE_TYPE_WRITE: p_void_request = &(p_authorize_request->request.write); break; default: case BLE_GATTS_AUTHORIZE_TYPE_INVALID: return NRF_ERROR_INVALID_DATA; } } switch (type) { case BLE_GATTS_AUTHORIZE_TYPE_READ: err_code = ble_gatts_evt_read_t_dec(p_buf, buf_len, p_index, &in_struct_len, p_void_request); SER_ASSERT(err_code == NRF_SUCCESS, err_code); break; case BLE_GATTS_AUTHORIZE_TYPE_WRITE: err_code = ble_gatts_evt_write_t_dec(p_buf, buf_len, p_index, &in_struct_len, p_void_request); SER_ASSERT(err_code == NRF_SUCCESS, err_code); break; default: case BLE_GATTS_AUTHORIZE_TYPE_INVALID: return NRF_ERROR_INVALID_DATA; } *p_struct_len += in_struct_len; return err_code; }