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(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_addr_t * pp_addr_tab[BLE_GAP_WHITELIST_ADDR_MAX_COUNT]; ble_gap_irk_t * pp_irk_tab[BLE_GAP_WHITELIST_IRK_MAX_COUNT]; ble_gap_addr_t addr_tab[BLE_GAP_WHITELIST_ADDR_MAX_COUNT]; ble_gap_irk_t irk_tab[BLE_GAP_WHITELIST_IRK_MAX_COUNT]; for (uint8_t i = 0; i < BLE_GAP_WHITELIST_ADDR_MAX_COUNT; ++i) { pp_addr_tab[i] = &addr_tab[i]; } for (uint8_t i = 0; i < BLE_GAP_WHITELIST_IRK_MAX_COUNT; ++i) { pp_irk_tab[i] = &irk_tab[i]; } ble_gap_whitelist_t whitelist; whitelist.addr_count = BLE_GAP_WHITELIST_ADDR_MAX_COUNT; whitelist.pp_addrs = pp_addr_tab; whitelist.irk_count = BLE_GAP_WHITELIST_IRK_MAX_COUNT; whitelist.pp_irks = pp_irk_tab; ble_gap_scan_params_t scan_params; scan_params.p_whitelist = &whitelist; 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; 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); 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; }