This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

openthread uri-path extraction

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 the Uri-Path from the header when the message is received by the packet sniffer?

If there is not would it be possible to extract any other information stored in by the message to determine what the message is and where it is from?

Thanks,

Richard

Parents
  • Hello richardjallen!

    First of all thanks for using our Thread solution!

    There are two functions in OpenThread API that allow to extract Uri-Path:

    const otCoapOption *otCoapHeaderGetFirstOption(otCoapHeader *aHeader);
    

    and

    const otCoapOption *otCoapHeaderGetNextOption(otCoapHeader *aHeader);
    

    Basically if the first option is not Uri-Path you will need to check all other options using the second function.

    Both functions return pointer to otCoapOption structure. If pointer is different than NULL, you need to check the mNumber field and compare against OT_COAP_OPTION_URI_PATH. Then you can use mValue and mLength fields to retrieve the option content.

    There is a nice example of how to do it already in core coap implementation: github.com/.../coap.cpp

    What you need is to replace CPP calls with C API that i have listed you above.

    Just for your knowledge, if you need to create generic sniffer (to sniff all frames in the air) you can use pyspinel project. Please refer to: github.com/.../SNIFFER.md 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.

    Give me know if you need any more details.

  • Hi Lukasz,

    reading through your answer both functions are the same, am I safe to assume the first one was supposed to be:

    const otCoapOption* otCoapHeaderGetFirstOption	(	otCoapHeader * 	aHeader	)
    

    Thanks,

    Richard

Reply Children
No Data
Related