<?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>openthread uri-path extraction</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/27168/openthread-uri-path-extraction</link><description>I am attempting to create a packet sniffer for an openthread application. I intend for it to run by sitting on the network and processing all packets with the coap_deafult_handler function (as set by otCoapSetDefaultHandler). 
 Is there a way to extract</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 11 Oct 2017 16:28:32 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/27168/openthread-uri-path-extraction" /><item><title>RE: openthread uri-path extraction</title><link>https://devzone.nordicsemi.com/thread/107020?ContentTypeID=1</link><pubDate>Wed, 11 Oct 2017 16:28:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:54081a85-9344-4419-97f3-1d5403554ecc</guid><dc:creator>richardjallen</dc:creator><description>&lt;p&gt;Thanks a lot Lukasz, I have now managed to create a packet sniffer following the example shown in core coap implementation:
code shown below:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;otCoapOption* option;
option = otCoapHeaderGetFirstOption(p_header);
while(option != NULL)
{
    switch (option-&amp;gt;mNumber)
    {
        case OT_COAP_OPTION_URI_PATH:
            ;
            const uint8_t* optionValue =  option-&amp;gt;mValue;
            NRF_LOG_INFO(&amp;quot;Uri-Path: %s\r\n&amp;quot;, nrf_log_push((char*) optionValue));
            break;
        default:
            break;
    }
    option = otCoapHeaderGetNextOption(p_header);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Many thanks,&lt;/p&gt;
&lt;p&gt;Richard&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: openthread uri-path extraction</title><link>https://devzone.nordicsemi.com/thread/107019?ContentTypeID=1</link><pubDate>Wed, 11 Oct 2017 16:25:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4ea7bfc9-e3c2-4ab2-8ad7-7277ce3229ad</guid><dc:creator>richardjallen</dc:creator><description>&lt;p&gt;My final solution is posted below.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: openthread uri-path extraction</title><link>https://devzone.nordicsemi.com/thread/107018?ContentTypeID=1</link><pubDate>Wed, 11 Oct 2017 14:19:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5ff8c225-f9c2-4e57-851d-8b6967dc0a67</guid><dc:creator>Lukasz Duda</dc:creator><description>&lt;p&gt;Thanks for poiniting this out. I&amp;#39;ve edited the answer.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: openthread uri-path extraction</title><link>https://devzone.nordicsemi.com/thread/107017?ContentTypeID=1</link><pubDate>Wed, 11 Oct 2017 11:34:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5d600cb4-6a7a-4fd1-8aae-aa49c1dfaf5f</guid><dc:creator>richardjallen</dc:creator><description>&lt;p&gt;Hi Lukasz,&lt;/p&gt;
&lt;p&gt;reading through your answer both functions are the same, am I safe to assume the first one was supposed to be:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;const otCoapOption* otCoapHeaderGetFirstOption	(	otCoapHeader * 	aHeader	)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Richard&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: openthread uri-path extraction</title><link>https://devzone.nordicsemi.com/thread/107016?ContentTypeID=1</link><pubDate>Wed, 11 Oct 2017 11:09:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:41ecbfb0-e143-44fd-b706-923818ae3e74</guid><dc:creator>Lukasz Duda</dc:creator><description>&lt;p&gt;Hello richardjallen!&lt;/p&gt;
&lt;p&gt;First of all thanks for using our Thread solution!&lt;/p&gt;
&lt;p&gt;There are two functions in OpenThread API that allow to extract Uri-Path:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;const otCoapOption *otCoapHeaderGetFirstOption(otCoapHeader *aHeader);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;const otCoapOption *otCoapHeaderGetNextOption(otCoapHeader *aHeader);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Basically if the first option is not Uri-Path you will need to check all other options using the second function.&lt;/p&gt;
&lt;p&gt;Both functions return pointer to otCoapOption structure. If pointer is different than NULL, you need to check the &lt;code&gt;mNumber&lt;/code&gt; field and compare against OT_COAP_OPTION_URI_PATH. Then you can use &lt;code&gt;mValue&lt;/code&gt; and &lt;code&gt;mLength&lt;/code&gt; fields to retrieve the option content.&lt;/p&gt;
&lt;p&gt;There is a nice example of how to do it already in core coap implementation:
&lt;a href="https://github.com/openthread/openthread/blob/master/src/core/coap/coap.cpp#L671"&gt;github.com/.../coap.cpp&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;What you need is to replace CPP calls with C API that i have listed you above.&lt;/p&gt;
&lt;p&gt;Just for your knowledge, if you need to create generic sniffer (to sniff all frames in the air) you can use &lt;code&gt;pyspinel&lt;/code&gt; project. Please refer to: &lt;a href="https://github.com/openthread/pyspinel/blob/master/SNIFFER.md"&gt;github.com/.../SNIFFER.md&lt;/a&gt; for more details. The detailed instruction on how to use it and run under Linux, will be presented in our upcoming release of nRF5 SDK for Thread.&lt;/p&gt;
&lt;p&gt;Give me know if you need any more details.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>