<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Receive L2CAP packets with bluez</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/14907/receive-l2cap-packets-with-bluez</link><description>I&amp;#39;ve been struggling for some time to get L2CAP transfer between an NRF51822 and a Linux machine using bluez. 
 I&amp;#39;ve successfully created a connection between the central (Linux) and peripheral (NRF51822) and created a socket, but I get no data through</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 04 Oct 2016 22:17:55 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/14907/receive-l2cap-packets-with-bluez" /><item><title>RE: Receive L2CAP packets with bluez</title><link>https://devzone.nordicsemi.com/thread/56911?ContentTypeID=1</link><pubDate>Tue, 04 Oct 2016 22:17:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dc1113cf-031e-436c-96e3-bb3414d60d96</guid><dc:creator>Tanasis!</dc:creator><description>&lt;p&gt;Okie dokie! I am doing the same thing basically. I have extracted the necessary files from the BlueZ lib. I was wondering if there is something out there that we missed! Thx again!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Receive L2CAP packets with bluez</title><link>https://devzone.nordicsemi.com/thread/56909?ContentTypeID=1</link><pubDate>Tue, 04 Oct 2016 07:14:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2c441475-4708-4a39-b8bd-8c14646d5ff2</guid><dc:creator>dingari</dc:creator><description>&lt;p&gt;@atasoglou  I&amp;#39;m not using any library, just the bluez driver. You can have a look at the source code for gatttool to get an idea of how to get started.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/pauloborges/bluez/blob/master/attrib/gatttool.c"&gt;github.com/.../gatttool.c&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Receive L2CAP packets with bluez</title><link>https://devzone.nordicsemi.com/thread/56910?ContentTypeID=1</link><pubDate>Mon, 03 Oct 2016 22:52:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6c667110-02e2-42dc-8851-9cdd76796a84</guid><dc:creator>Tanasis!</dc:creator><description>&lt;p&gt;@dingari Are you using Bluez for this (GATT notifications)? If yes are you using any library? Thx!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Receive L2CAP packets with bluez</title><link>https://devzone.nordicsemi.com/thread/56908?ContentTypeID=1</link><pubDate>Fri, 08 Jul 2016 09:31:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a1be519e-a8de-4c86-9c3f-b3e96eda928e</guid><dc:creator>dingari</dc:creator><description>&lt;p&gt;Thanks for the detailed response!&lt;/p&gt;
&lt;p&gt;We&amp;#39;ve already gotten this up and running using GATT notifications. But will keep this in mind if we go the L2CAP route in the future :)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Receive L2CAP packets with bluez</title><link>https://devzone.nordicsemi.com/thread/56907?ContentTypeID=1</link><pubDate>Fri, 08 Jul 2016 09:10:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:180c3ad5-74b3-48c2-a9ff-a269e9b25ad9</guid><dc:creator>Stian R&amp;#248;ed Hafskjold</dc:creator><description>&lt;p&gt;The &lt;code&gt;sd_ble_l2cap_tx&lt;/code&gt; function only sends raw L2CAP packets with CID &amp;gt;= 0x0040 (connection oriented channels). The bluez code you wrote is listening for an L2CAP connection request on CID 0x0005 (signaling channel) in order to establish a connection so it can receive data on the CoC (connection oriented channels). You can read more about this here: &lt;a href="https://community.nxp.com/thread/366041"&gt;community.nxp.com/.../366041&lt;/a&gt;. Or in the Bluetooth spec v4.2, Vol 3, Part A, chapter 10.&lt;/p&gt;
&lt;p&gt;So the above is part of the L2CAP spec, and the L2CAP socket you listen to in bluez code follows this spec. The SD does not support CoC yet, so it is unable to do a connection request/response on the L2CAP signaling channel (even though you can send raw packets on CID &amp;gt;=0x0040). So, as far as I know, in order to receive the raw L2CAP packets you are sending (without the connection procedure), you need to communicate with the BLE dongle on the HCI layer.&lt;/p&gt;
&lt;p&gt;However, the &lt;a href="http://developer.nordicsemi.com/nRF5_IoT_SDK/nRF5_IoT_SDK_v0.9.x/"&gt;IoT SD&lt;/a&gt; has added support for CoC, so you can try to use this SD instead. The API is slightly different so I would recommend you to start with one of the examples in the IoT SDK. In the &lt;code&gt;on_ble_evt()&lt;/code&gt; function you can now receive the L2CAP connection request &lt;code&gt;BLE_L2CAP_EVT_CH_CONN_REQUEST&lt;/code&gt;, and you can reply to it, something like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;case BLE_L2CAP_EVT_CH_CONN_REQUEST:
{
    ble_l2cap_ch_conn_reply_params_t reply_param;
        
    uint16_t    tx_mps = 64;
    uint16_t    rx_mps = 50;
    uint16_t    cid    = 0x0064;

    reply_param.peer_cid = p_ble_evt-&amp;gt;evt.l2cap_evt.params.ch_conn_request.peer_cid;
        
    reply_param.ch_conn_params.pub_mtu    = 64;
    reply_param.ch_conn_params.act_mtu    = 64;
    reply_param.ch_conn_params.rx_mem_len = RX_BUFFER_TOTAL_SIZE;
    reply_param.ch_conn_params.p_rx_mps   = &amp;amp;rx_mps;
    reply_param.ch_conn_params.p_tx_mps   = &amp;amp;tx_mps;
    reply_param.ch_conn_params.p_rx_mem   = &amp;amp;m_rx_buffer[0];
    reply_param.ch_conn_params.rx_creds   = INITIAL_CREDITS;
    

    reply_param.result   = BLE_L2CAP_CH_CONN_REPLY_RESULT_SUCCESS;
    int retval = sd_ble_l2cap_ch_conn_reply(p_ble_evt-&amp;gt;evt.l2cap_evt.conn_handle,
                                            &amp;amp;reply_param,
                                            &amp;amp;cid);
    APP_ERROR_CHECK(retval);

    // When the connection is successful you can transmit some data:
    uint8_t data[5] = &amp;quot;hello&amp;quot;;
    sd_ble_l2cap_ch_tx(p_ble_evt-&amp;gt;evt.l2cap_evt.conn_handle,cid,data,5);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The above requires your bluez code to initiate the L2CAP conneciton, and you need to use &lt;code&gt;connect()&lt;/code&gt; instead of &lt;code&gt;bind()&lt;/code&gt; and &lt;code&gt;listen()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;In linux you should use &lt;strong&gt;btmon&lt;/strong&gt; to monitor the HCI interface and you can see all L2CAP packets. Great for debugging.&lt;/p&gt;
&lt;p&gt;You can also try the &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.iotsdk.v0.9.0/iot_sdk_app_tftp.html?cp=6_1_0_5_8"&gt;TFTP example&lt;/a&gt; in the IoT SDK to transfer large amounts of data. But this requires you to first create an 6LoWPAN connection between the BLE device and your linux box. &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.iotsdk.v0.9.0/iot_sdk_user_guides_linux_commands.html?cp=6_1_0_2_5"&gt;See here&lt;/a&gt;, or &lt;a href="https://devzone.nordicsemi.com/question/82269/iot-sdk-rpi3-using-jessie-with-bluetooth_6lowpan/"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Finally, you can also set up a GATT server on the BLE device using the regular SD and SDK (not IoT), and use notifications to send data. You can check out the &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v11.0.0/ble_sdk_app_nus_eval.html?cp=6_0_0_4_2_2_18"&gt;UART example&lt;/a&gt; and use &lt;strong&gt;gatttool&lt;/strong&gt; in linux to create a connection, write to the CCCD to enable notifications and listen for notifications. The drawback with this approach is that you will get some overhead in each packet transfer because of the ATT header, but this is probably the easiest way to go (depending on your bluez skills).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>