Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Standalone L2CAP Example, Since Apple Core Bluetooth doesn't support OTS

Hi

We want to open L2CAP channel to stream data between nRF52840 and iOS, We cant use OTS example since there is no OTS support  from Apple core bluetooth framework.

So we thought to open a raw L2CAP channel on PSM (either hard-coded or from GATT Characteristic) and stream data over that channel.

I looked around many threads and pages to get some path to finish the task. Found one Similar thread and did the below steps

    Modified  OTS Server example to open L2CAP Channel after peer connected, But L2CAP Connection is rejected instantly (due to lack of clarity at example).

   Any help on this is highly appreciated since i could not much information on this topic.

   

Parents
  • Hi,

    What are you using for testing? An iPhone? Did you develop your own app which is reading the L2CAP stream, or are you using some sort of testing app?

    If you can send a sniffer log that would be great. Then we can see what is going on.

    What is the reason you want to use a raw L2CAP channel? With connection event length extension and long MTU, you should be able to get almost same throughput using GATT.

  • Hello Stian,

    Test scenario iPAD and nRF52840DK

    1. iPAD has custom developed application which reads the psm over gatt characteristic and tries to connect on using that psm.

    2. nRF52840 should setup L2CAP channel as soon as it receives connected event and update the PSM on gatt characteristic.

    Is there any design conflict in our procedure.

    I am initializing the stack with below snippet but app is crashing, i cannot see the error code, since uart is not available.

     To enable L2CAP do i need to create any instance or enable any macro.

    static void ble_stack_init(void)
    {
        ret_code_t err_code;
    
        err_code = nrf_sdh_enable_request();
        APP_ERROR_CHECK(err_code);
    
        // Configure the BLE stack using the default settings.
        // Fetch the start address of the application RAM.
        uint32_t ram_start = 0;
        err_code = nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &ram_start);
        APP_ERROR_CHECK(err_code);
    
        
        // Overwrite some of the default configurations for the BLE stack.
        ble_cfg_t ble_cfg;
    
        // Configure the number of custom UUIDS.
        memset(&ble_cfg, 0x00, sizeof(ble_cfg));
        ble_cfg.common_cfg.vs_uuid_cfg.vs_uuid_count = 0;
    
    
        // Set l2cap channel configuration
        ble_cfg.conn_cfg.conn_cfg_tag                        = APP_BLE_CONN_CFG_TAG;
        ble_cfg.conn_cfg.params.l2cap_conn_cfg.rx_mps        = BLE_L2CAP_MPS_MIN;
        ble_cfg.conn_cfg.params.l2cap_conn_cfg.rx_queue_size = 1;
        ble_cfg.conn_cfg.params.l2cap_conn_cfg.tx_mps        = BLE_L2CAP_MPS_MIN;
        ble_cfg.conn_cfg.params.l2cap_conn_cfg.tx_queue_size = 1;
        ble_cfg.conn_cfg.params.l2cap_conn_cfg.ch_count      = BLE_L2CAP_CH_COUNT_MAX;
    
        err_code = sd_ble_cfg_set(BLE_CONN_CFG_L2CAP, &ble_cfg, ram_start);
        APP_ERROR_CHECK(err_code);
    
        // Enable BLE stack.
        err_code = nrf_sdh_ble_enable(&ram_start);
        APP_ERROR_CHECK(err_code);
    
        // Register a handler for BLE events.
        NRF_SDH_BLE_OBSERVER(m_ble_observer, APP_BLE_OBSERVER_PRIO, ble_evt_handler, NULL);
    }
    

Reply
  • Hello Stian,

    Test scenario iPAD and nRF52840DK

    1. iPAD has custom developed application which reads the psm over gatt characteristic and tries to connect on using that psm.

    2. nRF52840 should setup L2CAP channel as soon as it receives connected event and update the PSM on gatt characteristic.

    Is there any design conflict in our procedure.

    I am initializing the stack with below snippet but app is crashing, i cannot see the error code, since uart is not available.

     To enable L2CAP do i need to create any instance or enable any macro.

    static void ble_stack_init(void)
    {
        ret_code_t err_code;
    
        err_code = nrf_sdh_enable_request();
        APP_ERROR_CHECK(err_code);
    
        // Configure the BLE stack using the default settings.
        // Fetch the start address of the application RAM.
        uint32_t ram_start = 0;
        err_code = nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &ram_start);
        APP_ERROR_CHECK(err_code);
    
        
        // Overwrite some of the default configurations for the BLE stack.
        ble_cfg_t ble_cfg;
    
        // Configure the number of custom UUIDS.
        memset(&ble_cfg, 0x00, sizeof(ble_cfg));
        ble_cfg.common_cfg.vs_uuid_cfg.vs_uuid_count = 0;
    
    
        // Set l2cap channel configuration
        ble_cfg.conn_cfg.conn_cfg_tag                        = APP_BLE_CONN_CFG_TAG;
        ble_cfg.conn_cfg.params.l2cap_conn_cfg.rx_mps        = BLE_L2CAP_MPS_MIN;
        ble_cfg.conn_cfg.params.l2cap_conn_cfg.rx_queue_size = 1;
        ble_cfg.conn_cfg.params.l2cap_conn_cfg.tx_mps        = BLE_L2CAP_MPS_MIN;
        ble_cfg.conn_cfg.params.l2cap_conn_cfg.tx_queue_size = 1;
        ble_cfg.conn_cfg.params.l2cap_conn_cfg.ch_count      = BLE_L2CAP_CH_COUNT_MAX;
    
        err_code = sd_ble_cfg_set(BLE_CONN_CFG_L2CAP, &ble_cfg, ram_start);
        APP_ERROR_CHECK(err_code);
    
        // Enable BLE stack.
        err_code = nrf_sdh_ble_enable(&ram_start);
        APP_ERROR_CHECK(err_code);
    
        // Register a handler for BLE events.
        NRF_SDH_BLE_OBSERVER(m_ble_observer, APP_BLE_OBSERVER_PRIO, ble_evt_handler, NULL);
    }
    

Children
Related