uint32_t ble_uuid_vs_add_req_enc(ble_uuid128_t const * const p_vs_uuid, uint8_t * const p_uuid_type, uint8_t * const p_buf, uint32_t * const p_buf_len) { SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_buf_len); uint32_t err_code; uint32_t index = 0; uint32_t buf_len = *p_buf_len; uint8_t opcode = SD_BLE_UUID_VS_ADD; err_code = uint8_t_enc(&opcode, p_buf, buf_len, &index); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = cond_field_enc((void *)p_vs_uuid, p_buf, buf_len, &index, ble_uuid128_t_enc); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = cond_field_enc((void *)p_uuid_type, p_buf, buf_len, &index, NULL); SER_ASSERT(err_code == NRF_SUCCESS, err_code); *p_buf_len = index; return err_code; }
uint32_t ble_gatts_attr_get_req_enc(uint16_t handle, ble_uuid_t * p_uuid, ble_gatts_attr_md_t * p_md, uint8_t * const p_buf, uint32_t * p_buf_len) { uint32_t index = 0; uint32_t err_code = NRF_SUCCESS; uint32_t total_len = *p_buf_len; SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_buf_len); p_buf[index++] = SD_BLE_GATTS_ATTR_GET; err_code = uint16_t_enc(&handle, p_buf, total_len, &index); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = cond_field_enc(p_uuid, p_buf, total_len, &index, ble_uuid_t_enc); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = cond_field_enc(p_md, p_buf, total_len, &index, NULL); SER_ASSERT(err_code == NRF_SUCCESS, err_code); *p_buf_len = index; return NRF_SUCCESS; }
uint32_t ble_gap_sec_params_reply_req_enc(uint16_t conn_handle, uint8_t sec_status, ble_gap_sec_params_t const * const p_sec_params, ble_gap_sec_keyset_t const * const p_sec_keyset, uint8_t * const p_buf, uint32_t * const p_buf_len) { SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_buf_len); uint8_t op_code = SD_BLE_GAP_SEC_PARAMS_REPLY; uint32_t err_code = NRF_SUCCESS; uint32_t buf_len = *p_buf_len; uint32_t index = 0; err_code = uint8_t_enc(&op_code, p_buf, buf_len, &index); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = uint16_t_enc(&conn_handle, p_buf, buf_len, &index); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = uint8_t_enc(&sec_status, p_buf, buf_len, &index); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = cond_field_enc(p_sec_params, p_buf, buf_len, &index, ble_gap_sec_params_t_enc); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = cond_field_enc(p_sec_keyset, p_buf, buf_len, &index, ble_gap_sec_keyset_t_enc); SER_ASSERT(err_code == NRF_SUCCESS, err_code); *p_buf_len = index; return err_code; }
uint32_t ble_gatts_attr_enc(void const * const p_void_gatts_attr, uint8_t * const p_buf, uint32_t buf_len, uint32_t * const p_index) { uint32_t err_code = NRF_SUCCESS; ble_gatts_attr_t * p_gatts_attr = (ble_gatts_attr_t *)p_void_gatts_attr; err_code = cond_field_enc((void *)p_gatts_attr->p_uuid, p_buf, buf_len, p_index, ble_uuid_t_enc); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = cond_field_enc((void *)p_gatts_attr->p_attr_md, p_buf, buf_len, p_index, ble_gatts_attr_md_enc); SER_ERROR_CHECK(err_code == NRF_SUCCESS, err_code); err_code = uint16_t_enc(&p_gatts_attr->init_offs, p_buf, buf_len, p_index); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = uint16_t_enc(&p_gatts_attr->max_len, p_buf, buf_len, p_index); SER_ASSERT(err_code == NRF_SUCCESS, err_code); SER_ERROR_CHECK(p_gatts_attr->init_len <= BLE_GATTS_VAR_ATTR_LEN_MAX, NRF_ERROR_INVALID_PARAM); //init len move just before p_data to be able to use len16data decoder. err_code = len16data_enc(p_gatts_attr->p_value, p_gatts_attr->init_len, p_buf, buf_len, p_index); SER_ASSERT(err_code == NRF_SUCCESS, err_code); return err_code; }
uint32_t ble_gatts_char_md_enc(void const * const p_void_char_md, uint8_t * const p_buf, uint32_t buf_len, uint32_t * const p_index) { uint32_t err_code = NRF_SUCCESS; ble_gatts_char_md_t * p_char_md = (ble_gatts_char_md_t *)p_void_char_md; uint8_t temp8; temp8 = p_char_md->char_props.broadcast | (p_char_md->char_props.read << 1) | (p_char_md->char_props.write_wo_resp << 2) | (p_char_md->char_props.write << 3) | (p_char_md->char_props.notify << 4) | (p_char_md->char_props.indicate << 5) | (p_char_md->char_props.auth_signed_wr << 6); err_code = uint8_t_enc(&temp8, p_buf, buf_len, p_index); SER_ASSERT(err_code == NRF_SUCCESS, err_code); temp8 = p_char_md->char_ext_props.reliable_wr | (p_char_md->char_ext_props.wr_aux << 1); err_code = uint8_t_enc(&temp8, p_buf, buf_len, p_index); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = uint16_t_enc(&p_char_md->char_user_desc_max_size, p_buf, buf_len, p_index); SER_ASSERT(err_code == NRF_SUCCESS, err_code); SER_ERROR_CHECK(p_char_md->char_user_desc_size <= BLE_GATTS_VAR_ATTR_LEN_MAX, NRF_ERROR_INVALID_PARAM); err_code = len16data_enc(p_char_md->p_char_user_desc, p_char_md->char_user_desc_size, p_buf, buf_len, p_index); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = cond_field_enc(p_char_md->p_char_pf, p_buf, buf_len, p_index, ser_ble_gatts_char_pf_enc); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = cond_field_enc(p_char_md->p_user_desc_md, p_buf, buf_len, p_index, ble_gatts_attr_md_enc); SER_ERROR_CHECK(err_code == NRF_SUCCESS, err_code); err_code = cond_field_enc(p_char_md->p_cccd_md, p_buf, buf_len, p_index, ble_gatts_attr_md_enc); SER_ERROR_CHECK(err_code == NRF_SUCCESS, err_code); err_code = cond_field_enc(p_char_md->p_sccd_md, p_buf, buf_len, p_index, ble_gatts_attr_md_enc); SER_ERROR_CHECK(err_code == NRF_SUCCESS, err_code); return err_code; }
uint32_t ble_uuid_vs_add_rsp_enc(uint32_t return_code, uint8_t * const p_buf, uint32_t * const p_buf_len, uint8_t const * const p_uuid_type) { SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_buf_len); uint32_t total_len = *p_buf_len; uint32_t err_code = ser_ble_cmd_rsp_status_code_enc(SD_BLE_UUID_VS_ADD, return_code, p_buf, p_buf_len); SER_ASSERT(err_code == NRF_SUCCESS, err_code); uint32_t index = *p_buf_len; if (return_code != NRF_SUCCESS) { return NRF_SUCCESS; } err_code = cond_field_enc((void *)p_uuid_type, p_buf, total_len, &index, uint8_t_enc); SER_ASSERT(err_code == NRF_SUCCESS, err_code); *p_buf_len = index; return err_code; }
uint32_t ble_l2cap_tx_req_enc(uint16_t conn_handle, ble_l2cap_header_t const * const p_l2cap_header, uint8_t const * const p_data, uint8_t * const p_buf, uint32_t * const p_buf_len) { uint32_t index = 0; uint32_t err_code = NRF_SUCCESS; SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_buf_len); SER_ASSERT_LENGTH_LEQ(1, *p_buf_len); p_buf[index++] = SD_BLE_L2CAP_TX; err_code = uint16_t_enc(&conn_handle, p_buf, *p_buf_len, &index); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = cond_field_enc(p_l2cap_header, p_buf, *p_buf_len, &index, ble_l2cap_header_t_enc); SER_ASSERT(err_code == NRF_SUCCESS, err_code); if (p_l2cap_header != NULL) { err_code = buf_enc(p_data, p_l2cap_header->len, p_buf, *p_buf_len, &index); } else { err_code = buf_enc(NULL, 0, p_buf, *p_buf_len, &index); } *p_buf_len = index; return err_code; }
uint32_t ble_gap_lesc_dhkey_reply_req_enc(uint16_t conn_handle, ble_gap_lesc_dhkey_t const *p_dhkey, uint8_t * const p_buf, uint32_t * const p_buf_len) { SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_buf_len); uint8_t op_code = SD_BLE_GAP_LESC_DHKEY_REPLY; uint32_t err_code = NRF_SUCCESS; uint32_t buf_len = *p_buf_len; uint32_t index = 0; err_code = uint8_t_enc(&op_code, p_buf, buf_len, &index); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = uint16_t_enc(&conn_handle, p_buf, buf_len, &index); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = cond_field_enc(p_dhkey, p_buf, buf_len, &index, ble_gap_lesc_dhkey_t_enc); SER_ASSERT(err_code == NRF_SUCCESS, err_code); *p_buf_len = index; return err_code; }
uint32_t ble_gatts_rw_authorize_reply_req_enc( uint16_t conn_handle, ble_gatts_rw_authorize_reply_params_t const * const p_reply_params, uint8_t * const p_buf, uint32_t * const p_buf_len) { SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_buf_len); uint32_t index = 0; uint32_t buf_len = *p_buf_len; uint8_t opcode = SD_BLE_GATTS_RW_AUTHORIZE_REPLY; uint32_t err_code = NRF_SUCCESS; err_code = uint8_t_enc(&opcode, p_buf, buf_len, &index); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = uint16_t_enc(&conn_handle, p_buf, buf_len, &index); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = cond_field_enc(p_reply_params, p_buf, buf_len, &index, ble_gatts_rw_authorize_reply_params_t_enc); SER_ASSERT(err_code == NRF_SUCCESS, err_code); *p_buf_len = index; return err_code; }
uint32_t ecb_block_encrypt_rsp_enc(uint32_t return_code, uint8_t * const p_buf, uint32_t * const p_buf_len, nrf_ecb_hal_data_t * const p_ecb_data) { SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_buf_len); uint32_t index = 0; uint32_t err_code = NRF_SUCCESS; uint32_t total_len = *p_buf_len; err_code = ser_ble_cmd_rsp_status_code_enc(SD_ECB_BLOCK_ENCRYPT, return_code, p_buf, p_buf_len); SER_ASSERT(err_code == NRF_SUCCESS, err_code); index += *p_buf_len; if (return_code == NRF_SUCCESS) { err_code = cond_field_enc(p_ecb_data, p_buf, total_len, &index,nrf_ecb_hal_data_t_out_enc); SER_ASSERT(err_code == NRF_SUCCESS, err_code); } *p_buf_len = index; return err_code; }
uint32_t ble_gap_lesc_oob_data_get_rsp_enc(uint32_t return_code, ble_gap_lesc_oob_data_t * p_oobd_own, uint8_t * const p_buf, uint32_t * const p_buf_len) { SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_buf_len); uint32_t buflen = *p_buf_len; uint32_t err_code = ser_ble_cmd_rsp_status_code_enc(SD_BLE_GAP_LESC_OOB_DATA_GET, return_code, p_buf, p_buf_len); SER_ASSERT(err_code == NRF_SUCCESS, err_code); uint32_t index = *p_buf_len; if (return_code != NRF_SUCCESS) { return NRF_SUCCESS; } err_code = cond_field_enc(p_oobd_own, p_buf, buflen, &index, ble_gap_lesc_oob_data_t_enc); SER_ASSERT(err_code == NRF_SUCCESS, err_code); *p_buf_len = index; return err_code; }
uint32_t ble_uuid_decode_req_enc(uint8_t uuid_le_len, uint8_t const * const p_uuid_le, ble_uuid_t * const p_uuid, uint8_t * const p_buf, uint32_t * const p_buf_len) { SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_buf_len); uint32_t err_code; uint32_t index = 0; uint32_t buf_len = *p_buf_len; uint8_t opcode = SD_BLE_UUID_DECODE; err_code = uint8_t_enc((void *)&opcode, p_buf, buf_len, &index); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = len8data_enc(p_uuid_le, uuid_le_len, p_buf, buf_len, &index); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = cond_field_enc((void *)p_uuid, p_buf, buf_len, &index, NULL); SER_ASSERT(err_code == NRF_SUCCESS, err_code); *p_buf_len = index; return err_code; }
uint32_t ble_gap_adv_start_req_enc(ble_gap_adv_params_t const * const p_adv_params, uint8_t * const p_buf, uint32_t * const p_buf_len) { uint32_t index = 0; uint32_t err_code = NRF_SUCCESS; SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_buf_len); uint32_t total_len = *p_buf_len; SER_ASSERT_LENGTH_LEQ(index + 2, total_len); p_buf[index++] = SD_BLE_GAP_ADV_START; p_buf[index++] = (p_adv_params == NULL) ? SER_FIELD_NOT_PRESENT : SER_FIELD_PRESENT; if (p_adv_params != NULL) { err_code = uint8_t_enc(&(p_adv_params->type), p_buf, total_len, &index); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = cond_field_enc(p_adv_params->p_peer_addr, p_buf, total_len, &index, ble_gap_addr_enc); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = uint8_t_enc(&(p_adv_params->fp), p_buf, total_len, &index); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = cond_field_enc(p_adv_params->p_whitelist, p_buf, total_len, &index, ble_gap_whitelist_t_enc); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = uint16_t_enc(&(p_adv_params->interval), p_buf, total_len, &index); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = uint16_t_enc(&(p_adv_params->timeout), p_buf, total_len, &index); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = ble_gap_adv_ch_mask_t_enc(&(p_adv_params->channel_mask), p_buf, total_len, &index); SER_ASSERT(err_code == NRF_SUCCESS, err_code); } *p_buf_len = index; return err_code; }
uint32_t ble_gatts_initial_user_handle_get_req_enc(uint16_t * p_handle, uint8_t * const p_buf, uint32_t * p_buf_len) { uint32_t index = 0; uint32_t err_code = NRF_SUCCESS; uint32_t total_len = *p_buf_len; SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_buf_len); p_buf[index++] = SD_BLE_GATTS_INITIAL_USER_HANDLE_GET; err_code = cond_field_enc(p_handle, p_buf, total_len, &index, NULL); SER_ASSERT(err_code == NRF_SUCCESS, err_code); *p_buf_len = index; return NRF_SUCCESS; }
uint32_t ble_common_enable_params_t_enc(void const * const p_void_common_enable_params, uint8_t * const p_buf, uint32_t buf_len, uint32_t * const p_index) { SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_index); SER_ASSERT_NOT_NULL(p_void_common_enable_params); ble_common_enable_params_t * p_common_enable_params = (ble_common_enable_params_t *)p_void_common_enable_params; uint32_t err_code = NRF_SUCCESS; err_code = uint16_t_enc(&p_common_enable_params->vs_uuid_count, p_buf, buf_len, p_index); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = cond_field_enc(p_common_enable_params->p_conn_bw_counts, p_buf, buf_len, p_index, ble_conn_bw_counts_t_enc); SER_ASSERT(err_code == NRF_SUCCESS, err_code); return err_code; }
uint32_t ble_gatts_value_get_rsp_enc(uint32_t return_code, uint8_t * const p_buf, uint32_t * const p_buf_len, uint8_t * const p_value, uint16_t * const p_value_len) { SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_buf_len); SER_ASSERT_LENGTH_LEQ(SER_CMD_RSP_HEADER_SIZE, *p_buf_len); uint32_t total_len = *p_buf_len; uint32_t err_code = ser_ble_cmd_rsp_status_code_enc(SD_BLE_GATTS_VALUE_GET, return_code, p_buf, p_buf_len); if (err_code != NRF_SUCCESS) { return err_code; } uint32_t index = *p_buf_len; if (return_code == NRF_SUCCESS) /* Add value and it's length. */ { err_code = cond_field_enc(p_value_len, p_buf, total_len, &index, uint16_t_enc); SER_ASSERT(err_code == NRF_SUCCESS, err_code); uint16_t value_len = (p_value_len) ? *p_value_len : 0; err_code = buf_enc(p_value, value_len, p_buf, total_len, &index); SER_ASSERT(err_code == NRF_SUCCESS, err_code); } *p_buf_len = index; return NRF_SUCCESS; }
uint32_t ble_enable_req_enc(ble_enable_params_t * p_ble_enable_params, uint8_t * const p_buf, uint32_t * const p_buf_len) { uint32_t index = 0; uint32_t err_code = NRF_SUCCESS; SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_buf_len); SER_ASSERT_LENGTH_LEQ(index + 2, *p_buf_len); p_buf[index++] = SD_BLE_ENABLE; err_code = cond_field_enc(p_ble_enable_params, p_buf, *p_buf_len, &index, ble_enable_params_t_enc); SER_ASSERT(err_code == NRF_SUCCESS, err_code); *p_buf_len = index; return err_code; }
uint32_t temp_get_req_enc(int32_t const * const p_temp, uint8_t * const p_buf, uint32_t * const p_buf_len) { SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_buf_len); uint32_t index = 0; uint32_t err_code = NRF_SUCCESS; uint32_t total_len = *p_buf_len; SER_ASSERT_LENGTH_LEQ(1, total_len); p_buf[index++] = SD_TEMP_GET; err_code = cond_field_enc(p_temp, p_buf, total_len, &index, NULL); SER_ASSERT(err_code == NRF_SUCCESS, err_code); *p_buf_len = index; return err_code; }
uint32_t ble_tx_buffer_count_get_req_enc(uint8_t const * const p_count, uint8_t * const p_buf, uint32_t * const p_buf_len) { SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_buf_len); uint32_t index = 0; uint8_t opcode = SD_BLE_TX_BUFFER_COUNT_GET; uint32_t err_code; uint32_t total_len = *p_buf_len; err_code = uint8_t_enc(&opcode, p_buf, total_len, &index); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = cond_field_enc(p_count, p_buf, total_len, &index, NULL); SER_ASSERT(err_code == NRF_SUCCESS, err_code); *p_buf_len = index; return err_code; }
uint32_t ecb_block_encrypt_req_enc(nrf_ecb_hal_data_t * p_ecb_data, uint8_t * const p_buf, uint32_t * const p_buf_len) { uint32_t index = 0; uint32_t err_code; uint32_t buf_len = *p_buf_len; SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_buf_len); uint8_t opcode = SD_ECB_BLOCK_ENCRYPT; err_code = uint8_t_enc(&opcode, p_buf, buf_len, &index); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = cond_field_enc(p_ecb_data, p_buf, buf_len, &index,nrf_ecb_hal_data_t_in_enc); SER_ASSERT(err_code == NRF_SUCCESS, err_code); *p_buf_len = index; return NRF_SUCCESS; }
uint32_t ble_user_mem_reply_req_enc(uint16_t conn_handle, ble_user_mem_block_t const * p_block, uint8_t * const p_buf, uint32_t * const p_buf_len) { uint32_t index = 0; uint32_t err_code; SER_ASSERT_NOT_NULL(p_buf); SER_ASSERT_NOT_NULL(p_buf_len); p_buf[index++] = SD_BLE_USER_MEM_REPLY; err_code = uint16_t_enc(&conn_handle, p_buf, *p_buf_len, &index); SER_ASSERT(err_code == NRF_SUCCESS, err_code); if(p_block != NULL) { p_buf[index++] = SER_FIELD_PRESENT; // Encoding order is different than structure elements order because // mem block length should be sent first err_code = uint16_t_enc(&(p_block->len), p_buf, *p_buf_len, &index); SER_ASSERT(err_code == NRF_SUCCESS, err_code); err_code = cond_field_enc(p_block->p_mem, p_buf, *p_buf_len, &index, NULL); SER_ASSERT(err_code == NRF_SUCCESS, err_code); } else { p_buf[index++] = SER_FIELD_NOT_PRESENT; } *p_buf_len = index; return err_code; }