I tried to port the example "ble_app_ipsp_initiator" to pc-ble-driver and run on Linux. The peer device is another PCA10056 device running ble_app_ipsp_acceptor. The problem is that sd_ble_l2cap_ch_setup() always returns "NRF_ERROR_RESOURCES".
However, it works fine if I just take and run ble_app_ipsp_initiator example standalone without pc-ble-driver. As far as my know, pc-ble-driver will apply some patches and build a special firmware (softdevice?) in the hex folder.
Do I need to include additional patches related to L2CAP to make it work?
I followed the instructions of pc-ble-driver and built the s140 softdevice (connectivity_1.0.0_1m_with_s140_6.1.1.hex). In addition, I added a file "ble_l2cap_impl.cpp" for l2cap serialization as below.
uint32_t sd_ble_l2cap_ch_setup(adapter_t *adapter, uint16_t conn_handle, uint16_t *p_local_cid, ble_l2cap_ch_setup_params_t const *p_params) { auto adapterLayer = static_cast<AdapterInternal *>(adapter->internal); RequestReplyCodecContext context(adapterLayer->transport); encode_function_t encode_function = [&](uint8_t *buffer, uint32_t *length) -> uint32_t { return ble_l2cap_ch_setup_req_enc(conn_handle, p_local_cid, p_params, buffer, length); }; decode_function_t decode_function = [&](uint8_t *buffer, uint32_t length, uint32_t *result) -> uint32_t { return ble_l2cap_ch_setup_rsp_dec(buffer, length, p_local_cid, result); }; return encode_decode(adapter, encode_function, decode_function); }
Here is the parameter when calling sd_ble_l2cap_ch_setup(). It applies the settings as same as ble_ipsp.c.
BLE_IPSP_TRC("Requesting sd_ble_l2cap_ch_setup"); ble_l2cap_ch_setup_params_t param = { { // rx_params BLE_IPSP_MTU, //rx_mtu BLE_IPSP_RX_MPS, //rx_mps { //sdu_buf nullptr, // p_data 0 // len } }, BLE_IPSP_PSM, // le_psm 0 // status }; err_code = sd_ble_l2cap_ch_setup(m_adapter, p_handle->conn_handle, &m_channel[ch_id].cid, ¶m);
From the document, NRF_ERROR_RESOURCES may be caused by the value of ch_count. Therefor, I also attached the setting as well.
ble_cfg.conn_cfg.conn_cfg_tag = APP_IPSP_TAG; ble_cfg.conn_cfg.params.l2cap_conn_cfg.rx_mps = BLE_IPSP_RX_MPS; ble_cfg.conn_cfg.params.l2cap_conn_cfg.rx_queue_size = BLE_IPSP_RX_BUFFER_COUNT; ble_cfg.conn_cfg.params.l2cap_conn_cfg.tx_mps = BLE_IPSP_TX_MPS; ble_cfg.conn_cfg.params.l2cap_conn_cfg.tx_queue_size = 1; ble_cfg.conn_cfg.params.l2cap_conn_cfg.ch_count = 1; // One L2CAP channel per link. err_code = sd_ble_cfg_set(m_adapter, BLE_CONN_CFG_L2CAP, &ble_cfg, ram_start);
Results:
Here are the raw logs captured in ble_common.cpp. When running the code, everything is fine except for the return status of sd_ble_l2cap_ch_setup().
// sd_ble_cfg_set(m_adapter, BLE_GAP_CFG_ROLE_COUNT, &ble_cfg, ram_start); send [69,40,0,0,0,1,0,1,0,0,0,] receive [69,0,0,0,0,] // err_code = sd_ble_cfg_set(m_adapter, BLE_CONN_CFG_GAP, &ble_cfg, ram_start); send [69,20,0,0,0,1,23,1,3,0,] receive [69,0,0,0,0,] // err_code = sd_ble_cfg_set(m_adapter, BLE_COMMON_CFG_VS_UUID, &ble_cfg, ram_start); send [69,1,0,0,0,1,0,] receive [69,0,0,0,0,] // err_code = sd_ble_cfg_set(m_adapter, BLE_CONN_CFG_L2CAP, &ble_cfg, ram_start); send [69,24,0,0,0,1,32,0,d4,0,4,1,1,] receive [69,0,0,0,0,] // err_code = sd_ble_cfg_set(m_adapter, BLE_GATTS_CFG_ATTR_TAB_SIZE, &ble_cfg, ram_start); send [69,a1,0,0,0,1,0,1,0,0,] receive [69,0,0,0,0,] // err_code = sd_ble_enable(m_adapter, &ram_start); send [60,] receive [60,0,0,0,0,] // err_code = sd_ble_gatts_service_add(m_adapter, BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, &handle); send [a8,1,1,20,18,1,1,] receive [a8,0,0,0,0,1,e,0,] // err_code = sd_ble_gap_addr_set(m_adapter, &m_my_addr); send [6c,1,0,55,44,33,22,11,0,] receive [6c,0,0,0,0,] // err_code = sd_ble_gap_connect(m_adapter, &m_peer_addr, &m_scan_param, &m_connection_param, APP_IPSP_TAG); send [8c,1,0,aa,bb,cc,dd,ee,0,1,0,0,1,0,0,0,0,0,a0,0,50,0,0,0,1,18,0,30,0,0,0,90,1,23,] receive [8c,0,0,0,0,] // err_code = sd_ble_l2cap_ch_setup(m_adapter, p_handle->conn_handle, &m_channel[ch_id].cid, ¶m); send [b8,0,0,1,0,0,1,0,5,32,0,0,0,0,0,0,0,23,0,0,0,] receive [b8,13,0,0,0,] (*** 0x13 equals to 19 in decimal ***)
Thanks