1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318 |
- /**
- * Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
- *
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form, except as embedded into a Nordic
- * Semiconductor ASA integrated circuit in a product or a software update for
- * such product, must reproduce the above copyright notice, this list of
- * conditions and the following disclaimer in the documentation and/or other
- * materials provided with the distribution.
- *
- * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
- * contributors may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * 4. This software, with or without modification, must only be used with a
- * Nordic Semiconductor ASA integrated circuit.
- *
- * 5. Any software provided in binary form under this license must not be reverse
- * engineered, decompiled, modified and/or disassembled.
- *
- * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
- * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
- * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
- #include "ble_gap_conn.h"
- #include "ser_config.h"
- #include "conn_mw_ble_gap.h"
- #include "ble_serialization.h"
- #include "conn_ble_gap_sec_keys.h"
- #include <stddef.h>
- extern ser_ble_gap_conn_keyset_t m_conn_keys_table[SER_MAX_CONNECTIONS];
- #if NRF_SD_BLE_API_VERSION > 5 && !defined(S112)
- static uint8_t * mp_scan_data;
- #endif
- /* Id used to identify buffer allocated for scan reports. */
- #define SCAN_BUFFER_ID 1
- #ifndef S112
- uint32_t conn_mw_ble_gap_connect(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- ble_gap_addr_t addr;
- ble_gap_addr_t * p_addr = &addr;
- ble_gap_scan_params_t scan_params;
- ble_gap_scan_params_t * p_scan_params = &scan_params;
- ble_gap_conn_params_t conn_params;
- ble_gap_conn_params_t * p_conn_params = &conn_params;
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- #if NRF_SD_BLE_API_VERSION >= 4
- uint8_t conn_cfg_tag;
- err_code = ble_gap_connect_req_dec(p_rx_buf, rx_buf_len, &p_addr,
- &p_scan_params, &p_conn_params, &conn_cfg_tag);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gap_connect(p_addr, p_scan_params, p_conn_params, conn_cfg_tag);
- #else
- err_code = ble_gap_connect_req_dec(p_rx_buf, rx_buf_len, &p_addr,
- &p_scan_params, &p_conn_params);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gap_connect(p_addr, p_scan_params, p_conn_params);
- #endif
- err_code = ble_gap_connect_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- uint32_t conn_mw_ble_gap_connect_cancel(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- sd_err_code = sd_ble_gap_connect_cancel();
- err_code = ble_gap_connect_cancel_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- uint32_t conn_mw_ble_gap_scan_start(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- ble_gap_scan_params_t scan_params;
- ble_gap_scan_params_t * p_scan_params = &scan_params;
- #if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 5
- ble_data_t adv_report_buffer;
- ble_data_t * p_adv_report_buffer = &adv_report_buffer;
- mp_scan_data = conn_ble_gap_ble_data_buf_alloc(SCAN_BUFFER_ID);
- adv_report_buffer.p_data = mp_scan_data;
- adv_report_buffer.len = SER_MAX_ADV_DATA;
- err_code = ble_gap_scan_start_req_dec(p_rx_buf, rx_buf_len, &p_scan_params, &p_adv_report_buffer);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- if (p_adv_report_buffer)
- {
- conn_ble_gap_scan_data_set(p_adv_report_buffer->p_data);
- }
- sd_err_code = sd_ble_gap_scan_start(p_scan_params, p_adv_report_buffer);
- if (sd_err_code != NRF_SUCCESS)
- {
- conn_ble_gap_scan_data_unset(true);
- }
- err_code = ble_gap_scan_start_rsp_enc(sd_err_code, p_adv_report_buffer, p_tx_buf, p_tx_buf_len);
- #else
- err_code = ble_gap_scan_start_req_dec(p_rx_buf, rx_buf_len, &p_scan_params);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gap_scan_start(p_scan_params);
- err_code = ble_gap_scan_start_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
- #endif
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- uint32_t conn_mw_ble_gap_scan_stop(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
-
- #if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 5
- conn_ble_gap_scan_data_unset(true);
- #endif
- sd_err_code = sd_ble_gap_scan_stop();
- err_code = ble_gap_scan_stop_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- uint32_t conn_mw_ble_gap_encrypt(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- uint16_t conn_handle;
- ble_gap_master_id_t master_id;
- ble_gap_master_id_t *p_master_id = &master_id;
- ble_gap_enc_info_t enc_info;
- ble_gap_enc_info_t *p_enc_info = &enc_info;
- err_code = ble_gap_encrypt_req_dec(p_rx_buf, rx_buf_len, &conn_handle, &p_master_id, &p_enc_info);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gap_encrypt(conn_handle, p_master_id, p_enc_info);
- err_code = ble_gap_encrypt_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- #endif //!S112
- #if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 6
- uint32_t conn_mw_ble_gap_adv_data_set(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- uint8_t data[BLE_GAP_ADV_MAX_SIZE];
- uint8_t * p_data = data;
- uint8_t dlen = sizeof (data);
- uint8_t sr_data[BLE_GAP_ADV_MAX_SIZE];
- uint8_t * p_sr_data = sr_data;
- uint8_t srdlen = sizeof (sr_data);
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- err_code = ble_gap_adv_data_set_req_dec(p_rx_buf,
- rx_buf_len,
- &p_data,
- &dlen,
- &p_sr_data,
- &srdlen);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gap_adv_data_set(p_data, dlen, p_sr_data, srdlen);
- err_code = ble_gap_adv_data_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- #endif
- uint32_t conn_mw_ble_gap_adv_start(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- #if NRF_SD_BLE_API_VERSION > 5
- uint8_t conn_cfg_tag;
- uint8_t adv_handle;
- err_code = ble_gap_adv_start_req_dec(p_rx_buf, rx_buf_len, &adv_handle, &conn_cfg_tag);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gap_adv_start(adv_handle, conn_cfg_tag);
- #else
- ble_gap_addr_t peer_addr;
- ble_gap_adv_params_t adv_params;
- ble_gap_adv_params_t * p_adv_params;
- adv_params.p_peer_addr = &peer_addr;
- p_adv_params = &adv_params;
- #if NRF_SD_BLE_API_VERSION >= 4
- uint8_t conn_cfg_tag;
- err_code = ble_gap_adv_start_req_dec(p_rx_buf, rx_buf_len, &p_adv_params, &conn_cfg_tag);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gap_adv_start(p_adv_params, conn_cfg_tag);
- #else
- err_code = ble_gap_adv_start_req_dec(p_rx_buf, rx_buf_len, &p_adv_params);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gap_adv_start(p_adv_params);
- #endif
- #endif
- err_code = ble_gap_adv_start_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- uint32_t conn_mw_ble_gap_adv_stop(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- #if NRF_SD_BLE_API_VERSION > 5
- uint8_t adv_handle;
- err_code = ble_gap_adv_stop_req_dec(p_rx_buf, rx_buf_len, &adv_handle);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gap_adv_stop(adv_handle);
- #else
- sd_err_code = sd_ble_gap_adv_stop();
- #endif
- err_code = ble_gap_adv_stop_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- uint32_t conn_mw_ble_gap_conn_param_update(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- uint16_t conn_handle;
- ble_gap_conn_params_t conn_params;
- ble_gap_conn_params_t * p_conn_params = &conn_params;
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- err_code = ble_gap_conn_param_update_req_dec(p_rx_buf, rx_buf_len, &conn_handle, &p_conn_params);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gap_conn_param_update(conn_handle, p_conn_params);
- err_code = ble_gap_conn_param_update_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- uint32_t conn_mw_ble_gap_disconnect(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- uint16_t conn_handle;
- uint8_t hci_status_code;
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- err_code = ble_gap_disconnect_req_dec(p_rx_buf, rx_buf_len, &conn_handle, &hci_status_code);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gap_disconnect(conn_handle, hci_status_code);
- err_code = ble_gap_disconnect_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- uint32_t conn_mw_ble_gap_tx_power_set(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- int8_t tx_power;
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- #if NRF_SD_BLE_API_VERSION > 5
- uint8_t role;
- uint16_t handle;
- err_code = ble_gap_tx_power_set_req_dec(p_rx_buf, rx_buf_len, &role, &handle, &tx_power);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gap_tx_power_set(role, handle, tx_power);
- #else
- err_code = ble_gap_tx_power_set_req_dec(p_rx_buf, rx_buf_len, &tx_power);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gap_tx_power_set(tx_power);
- #endif
- err_code = ble_gap_tx_power_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- uint32_t conn_mw_ble_gap_appearance_set(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- uint16_t appearance;
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- err_code = ble_gap_appearance_set_req_dec(p_rx_buf, rx_buf_len, &appearance);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gap_appearance_set(appearance);
- err_code = ble_gap_appearance_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- uint32_t conn_mw_ble_gap_appearance_get(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- uint16_t appearance;
- uint16_t * p_appearance = &appearance;
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- err_code = ble_gap_appearance_get_req_dec(p_rx_buf, rx_buf_len, &p_appearance);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gap_appearance_get(p_appearance);
- err_code = ble_gap_appearance_get_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_appearance);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- uint32_t conn_mw_ble_gap_ppcp_set(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- ble_gap_conn_params_t conn_params;
- ble_gap_conn_params_t * p_conn_params = &conn_params;
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- err_code = ble_gap_ppcp_set_req_dec(p_rx_buf, rx_buf_len, &p_conn_params);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gap_ppcp_set(p_conn_params);
- err_code = ble_gap_ppcp_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- uint32_t conn_mw_ble_gap_ppcp_get(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- ble_gap_conn_params_t conn_params;
- ble_gap_conn_params_t * p_conn_params = &conn_params;
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- err_code = ble_gap_ppcp_get_req_dec(p_rx_buf, rx_buf_len, &p_conn_params);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gap_ppcp_get(p_conn_params);
- err_code = ble_gap_ppcp_get_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_conn_params);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- uint32_t conn_mw_ble_gap_device_name_get(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- uint8_t dev_name[BLE_GAP_DEVNAME_MAX_LEN];
- uint8_t * p_dev_name = dev_name;
- uint16_t len;
- uint16_t * p_len = &len;
- uint16_t buf_len = 0;
- err_code = ble_gap_device_name_get_req_dec(p_rx_buf, rx_buf_len, &p_dev_name, &p_len);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- if (p_len)
- {
- buf_len = *p_len;
- }
- sd_err_code = sd_ble_gap_device_name_get(p_dev_name, p_len);
- if (p_len)
- {
- buf_len = MIN(buf_len, *p_len);
- }
- err_code = ble_gap_device_name_get_rsp_enc(sd_err_code, p_dev_name, p_len, buf_len,
- p_tx_buf, p_tx_buf_len);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- uint32_t conn_mw_ble_gap_device_name_set(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- ble_gap_conn_sec_mode_t write_perm;
- ble_gap_conn_sec_mode_t * p_write_perm = &write_perm;
- uint8_t dev_name[BLE_GAP_DEVNAME_MAX_LEN];
- uint8_t * p_dev_name = dev_name;
- uint16_t len = BLE_GAP_DEVNAME_MAX_LEN;
- err_code = ble_gap_device_name_set_req_dec(p_rx_buf,
- rx_buf_len,
- &p_write_perm,
- &p_dev_name,
- &len);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gap_device_name_set(p_write_perm, p_dev_name, len);
- err_code = ble_gap_device_name_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- uint32_t conn_mw_ble_gap_authenticate(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- uint16_t conn_handle;
- ble_gap_sec_params_t sec_params;
- ble_gap_sec_params_t * p_sec_params = &sec_params;
- err_code = ble_gap_authenticate_req_dec(p_rx_buf, rx_buf_len, &conn_handle, &p_sec_params);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gap_authenticate(conn_handle, p_sec_params);
- err_code = ble_gap_authenticate_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- uint32_t conn_mw_ble_gap_sec_params_reply(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- uint32_t sec_tab_index = 0;
- uint16_t * p_conn_handle;
- uint8_t sec_status;
- ble_gap_sec_params_t sec_params;
- ble_gap_sec_params_t * p_sec_params = &sec_params;
- // Allocate global security context for soft device
- err_code = conn_ble_gap_sec_context_create(&sec_tab_index);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- p_conn_handle = &(m_conn_keys_table[sec_tab_index].conn_handle);
- // Set up global structure for command decoder
- ble_gap_sec_keyset_t * p_sec_keyset = &(m_conn_keys_table[sec_tab_index].keyset);
- p_sec_keyset->keys_own.p_enc_key = &(m_conn_keys_table[sec_tab_index].enc_key_own);
- p_sec_keyset->keys_own.p_id_key = &(m_conn_keys_table[sec_tab_index].id_key_own);
- p_sec_keyset->keys_own.p_sign_key = &(m_conn_keys_table[sec_tab_index].sign_key_own);
- p_sec_keyset->keys_own.p_pk = &(m_conn_keys_table[sec_tab_index].pk_own);
- p_sec_keyset->keys_peer.p_enc_key = &(m_conn_keys_table[sec_tab_index].enc_key_peer);
- p_sec_keyset->keys_peer.p_id_key = &(m_conn_keys_table[sec_tab_index].id_key_peer);
- p_sec_keyset->keys_peer.p_sign_key = &(m_conn_keys_table[sec_tab_index].sign_key_peer);
- p_sec_keyset->keys_peer.p_pk = &(m_conn_keys_table[sec_tab_index].pk_peer);
- err_code = ble_gap_sec_params_reply_req_dec(p_rx_buf,
- rx_buf_len,
- p_conn_handle,
- &sec_status,
- &p_sec_params,
- &p_sec_keyset);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- if (p_sec_keyset == NULL)
- {
- //If no keyset was sent destroy the context.
- err_code = conn_ble_gap_sec_context_destroy(*p_conn_handle);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- }
- sd_err_code = sd_ble_gap_sec_params_reply(*p_conn_handle, sec_status, p_sec_params, p_sec_keyset);
- err_code = ble_gap_sec_params_reply_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_sec_keyset);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- uint32_t conn_mw_ble_gap_auth_key_reply(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- uint16_t conn_handle;
- uint8_t key_type;
- uint8_t key[BLE_GAP_SEC_KEY_LEN];
- uint8_t * p_key = key;
- err_code = ble_gap_auth_key_reply_req_dec(p_rx_buf, rx_buf_len, &conn_handle, &key_type, &p_key);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gap_auth_key_reply(conn_handle, key_type, p_key);
- err_code = ble_gap_auth_key_reply_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- uint32_t conn_mw_ble_gap_sec_info_reply(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- uint16_t conn_handle;
- ble_gap_enc_info_t enc_info;
- ble_gap_enc_info_t * p_enc_info = &enc_info;
- ble_gap_irk_t id_info;
- ble_gap_irk_t * p_id_info = &id_info;
- ble_gap_sign_info_t sign_info;
- ble_gap_sign_info_t * p_sign_info = &sign_info;
- err_code = ble_gap_sec_info_reply_req_dec(p_rx_buf,
- rx_buf_len,
- &conn_handle,
- &p_enc_info,
- &p_id_info,
- &p_sign_info);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gap_sec_info_reply(conn_handle, p_enc_info, p_id_info, p_sign_info);
- err_code = ble_gap_sec_info_reply_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- uint32_t conn_mw_ble_gap_conn_sec_get(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- uint16_t conn_handle;
- ble_gap_conn_sec_t conn_sec;
- ble_gap_conn_sec_t * p_conn_sec = &conn_sec;
- err_code = ble_gap_conn_sec_get_req_dec(p_rx_buf, rx_buf_len, &conn_handle, &p_conn_sec);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gap_conn_sec_get(conn_handle, p_conn_sec);
- err_code = ble_gap_conn_sec_get_rsp_enc(sd_err_code, p_conn_sec, p_tx_buf, p_tx_buf_len);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- uint32_t conn_mw_ble_gap_rssi_start(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- uint16_t conn_handle;
- uint8_t threshold_dbm;
- uint8_t skip_count;
- err_code = ble_gap_rssi_start_req_dec(p_rx_buf, rx_buf_len, &conn_handle, &threshold_dbm, &skip_count);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gap_rssi_start(conn_handle, threshold_dbm, skip_count);
- err_code = ble_gap_rssi_start_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- uint32_t conn_mw_ble_gap_rssi_stop(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- uint16_t conn_handle;
- err_code = ble_gap_rssi_stop_req_dec(p_rx_buf, rx_buf_len, &conn_handle);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gap_rssi_stop(conn_handle);
- err_code = ble_gap_rssi_stop_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- uint32_t conn_mw_ble_gap_rssi_get(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- uint16_t conn_handle;
- int8_t rssi;
- int8_t * p_rssi = &rssi;
- #if NRF_SD_BLE_API_VERSION > 5
- uint8_t ch_index;
- uint8_t * p_ch_index = &ch_index;
- err_code = ble_gap_rssi_get_req_dec(p_rx_buf, rx_buf_len, &conn_handle, &p_rssi, &p_ch_index);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gap_rssi_get(conn_handle, p_rssi, p_ch_index);
- err_code = ble_gap_rssi_get_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_rssi, p_ch_index);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- #else
- err_code = ble_gap_rssi_get_req_dec(p_rx_buf, rx_buf_len, &conn_handle, &p_rssi);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gap_rssi_get(conn_handle, p_rssi);
- err_code = ble_gap_rssi_get_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_rssi);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- #endif
- return err_code;
- }
- uint32_t conn_mw_ble_gap_keypress_notify(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- uint16_t conn_handle;
- uint8_t kp_not;
- err_code = ble_gap_keypress_notify_req_dec(p_rx_buf, rx_buf_len, &conn_handle, &kp_not);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gap_keypress_notify(conn_handle, kp_not);
- err_code = ble_gap_keypress_notify_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- uint32_t conn_mw_ble_gap_lesc_dhkey_reply(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- uint16_t conn_handle;
- ble_gap_lesc_dhkey_t dhkey;
- ble_gap_lesc_dhkey_t * p_dhkey = &dhkey;
- err_code = ble_gap_lesc_dhkey_reply_req_dec(p_rx_buf, rx_buf_len, &conn_handle, &p_dhkey);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gap_lesc_dhkey_reply(conn_handle, p_dhkey);
- err_code = ble_gap_lesc_dhkey_reply_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- uint32_t conn_mw_ble_gap_lesc_oob_data_set(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- uint16_t conn_handle;
- ble_gap_lesc_oob_data_t own;
- ble_gap_lesc_oob_data_t peer;
- ble_gap_lesc_oob_data_t * p_own = &own;
- ble_gap_lesc_oob_data_t * p_peer = &peer;
- err_code = ble_gap_lesc_oob_data_set_req_dec(p_rx_buf, rx_buf_len, &conn_handle, &p_own, &p_peer);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gap_lesc_oob_data_set(conn_handle, p_own, p_peer);
- err_code = ble_gap_lesc_oob_data_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- uint32_t conn_mw_ble_gap_lesc_oob_data_get(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- uint16_t conn_handle;
- ble_gap_lesc_oob_data_t own;
- ble_gap_lesc_oob_data_t * p_own = &own;
- ble_gap_lesc_p256_pk_t pk;
- ble_gap_lesc_p256_pk_t * p_pk = &pk;
- err_code = ble_gap_lesc_oob_data_get_req_dec(p_rx_buf, rx_buf_len, &conn_handle, &p_pk, &p_own);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gap_lesc_oob_data_get(conn_handle, p_pk, p_own);
- err_code = ble_gap_lesc_oob_data_get_rsp_enc(sd_err_code, p_own, p_tx_buf, p_tx_buf_len);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- uint32_t conn_mw_ble_gap_addr_set(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- ble_gap_addr_t addr;
- ble_gap_addr_t * p_addr = &addr;
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- err_code = ble_gap_addr_set_req_dec(p_rx_buf, rx_buf_len, &p_addr);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gap_addr_set(p_addr);
- err_code = ble_gap_addr_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- uint32_t conn_mw_ble_gap_addr_get(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- ble_gap_addr_t addr;
- ble_gap_addr_t * p_addr = &addr;
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- err_code = ble_gap_addr_get_req_dec(p_rx_buf, rx_buf_len, &p_addr);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gap_addr_get(p_addr);
- err_code = ble_gap_addr_get_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_addr);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- uint32_t conn_mw_ble_gap_privacy_set(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- ble_gap_privacy_params_t privacy_params;
- ble_gap_privacy_params_t * p_privacy_params = &privacy_params;
- ble_gap_irk_t irk;
- privacy_params.p_device_irk = &irk;
- err_code = ble_gap_privacy_set_req_dec(p_rx_buf, rx_buf_len, &p_privacy_params);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gap_privacy_set(p_privacy_params);
- err_code = ble_gap_privacy_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- uint32_t conn_mw_ble_gap_privacy_get(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- ble_gap_privacy_params_t privacy_params;
- ble_gap_privacy_params_t * p_privacy_params = &privacy_params;
- ble_gap_irk_t irk;
- privacy_params.p_device_irk = &irk;
- err_code = ble_gap_privacy_get_req_dec(p_rx_buf, rx_buf_len, &p_privacy_params);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gap_privacy_get(p_privacy_params);
- err_code = ble_gap_privacy_get_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_privacy_params);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- uint32_t conn_mw_ble_gap_whitelist_set(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- uint8_t length;
- ble_gap_addr_t wl_addr_array[BLE_GAP_WHITELIST_ADDR_MAX_COUNT];
- ble_gap_addr_t * p_wl_addrs_array[BLE_GAP_WHITELIST_ADDR_MAX_COUNT];
- for (uint8_t i = 0; i < BLE_GAP_WHITELIST_ADDR_MAX_COUNT; ++i)
- {
- p_wl_addrs_array[i] = &wl_addr_array[i];
- }
- ble_gap_addr_t * * pp_wl_addrs = p_wl_addrs_array;
- err_code = ble_gap_whitelist_set_req_dec(p_rx_buf, rx_buf_len, &pp_wl_addrs, &length);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gap_whitelist_set((ble_gap_addr_t const * *)pp_wl_addrs, length);
- err_code = ble_gap_whitelist_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- uint32_t conn_mw_ble_gap_device_identities_set(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- uint8_t length;
- ble_gap_id_key_t id_key_array[BLE_GAP_DEVICE_IDENTITIES_MAX_COUNT];
- ble_gap_id_key_t * p_id_key_array[BLE_GAP_DEVICE_IDENTITIES_MAX_COUNT];
- ble_gap_irk_t irk_array[BLE_GAP_DEVICE_IDENTITIES_MAX_COUNT];
- ble_gap_irk_t * p_irk_array[BLE_GAP_DEVICE_IDENTITIES_MAX_COUNT];
- for (uint8_t i = 0; i < BLE_GAP_DEVICE_IDENTITIES_MAX_COUNT; ++i)
- {
- p_id_key_array[i] = &id_key_array[i];
- p_irk_array[i] = &irk_array[i];
- }
- ble_gap_id_key_t * * pp_id_keys = p_id_key_array;
- ble_gap_irk_t * * pp_local_irks = p_irk_array;
- err_code = ble_gap_device_identities_set_req_dec(p_rx_buf, rx_buf_len,
- &pp_id_keys,
- &pp_local_irks,
- &length);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gap_device_identities_set((ble_gap_id_key_t const * *) pp_id_keys,
- (ble_gap_irk_t const * *) pp_local_irks,
- length);
- err_code = ble_gap_device_identities_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- #if NRF_SD_BLE_API_VERSION >= 5
- uint32_t conn_mw_ble_gap_phy_update(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- uint16_t conn_handle;
- ble_gap_phys_t gap_phys;
- ble_gap_phys_t * p_gap_phys = &gap_phys;
- err_code = ble_gap_phy_update_req_dec(p_rx_buf, rx_buf_len, &conn_handle, &p_gap_phys);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gap_phy_update(conn_handle, p_gap_phys);
- err_code = ble_gap_phy_update_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- #endif
- #if NRF_SD_BLE_API_VERSION >= 4 && !defined(S112)
- uint32_t conn_mw_ble_gap_data_length_update(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- uint16_t conn_handle;
- ble_gap_data_length_params_t dl_params;
- ble_gap_data_length_params_t * p_dl_params = &dl_params;
- ble_gap_data_length_limitation_t dl_limitation;
- ble_gap_data_length_limitation_t * p_dl_limitation = &dl_limitation;
- err_code = ble_gap_data_length_update_req_dec(p_rx_buf, rx_buf_len, &conn_handle, &p_dl_params, &p_dl_limitation);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gap_data_length_update(conn_handle, p_dl_params,p_dl_limitation );
- err_code = ble_gap_data_length_update_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_dl_limitation);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- #endif //NRF_SD_BLE_API_VERSION >= 4 && !defined(S112)
- #if NRF_SD_BLE_API_VERSION > 5
- uint32_t conn_mw_ble_gap_adv_set_configure(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- uint8_t adv_handle;
- uint8_t * p_adv_handle = &adv_handle;
- ble_gap_adv_data_t adv_data;
- ble_gap_adv_data_t * p_adv_data = &adv_data;
- adv_data.adv_data.len = SER_MAX_ADV_DATA;
- adv_data.adv_data.p_data = NULL;
- adv_data.scan_rsp_data.len = SER_MAX_ADV_DATA;
- adv_data.scan_rsp_data.p_data = NULL;
- ble_gap_addr_t addr;
- ble_gap_adv_params_t adv_params;
- adv_params.p_peer_addr = &addr;
- ble_gap_adv_params_t * p_adv_params = &adv_params;
- err_code = ble_gap_adv_set_configure_req_dec(p_rx_buf, rx_buf_len, &p_adv_handle, &p_adv_data, &p_adv_params);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gap_adv_set_configure(p_adv_handle, p_adv_data, p_adv_params);
- if ((sd_err_code != NRF_SUCCESS) && p_adv_data)
- {
- (void)conn_ble_gap_ble_data_buf_free(p_adv_data->adv_data.p_data);
- (void)conn_ble_gap_ble_data_buf_free(p_adv_data->scan_rsp_data.p_data);
- }
- err_code = ble_gap_adv_set_configure_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_adv_data, p_adv_handle);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- #ifndef S112
- uint32_t conn_mw_ble_gap_qos_channel_survey_start(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- uint32_t interval_us;
- err_code = ble_gap_qos_channel_survey_start_req_dec(p_rx_buf, rx_buf_len, &interval_us);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gap_qos_channel_survey_start(interval_us);
- err_code = ble_gap_qos_channel_survey_start_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- uint32_t conn_mw_ble_gap_qos_channel_survey_stop(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- err_code = ble_gap_qos_channel_survey_stop_req_dec(p_rx_buf, rx_buf_len);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gap_qos_channel_survey_stop();
- err_code = ble_gap_qos_channel_survey_stop_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- #endif //!S112
- #endif
|