Author Topic: Understanding LWMesh Peer2Peer Application and Data Handling  (Read 2784 times)

0 Members and 1 Guest are viewing this topic.

Offline wifiguy11Topic starter

  • Newbie
  • Posts: 7
  • Country: us
Understanding LWMesh Peer2Peer Application and Data Handling
« on: September 06, 2016, 06:02:40 pm »
Hey all! I'm trying to familiarize myself with the LWMesh framework. Right now I've been toying with the peer2peer example application, and am attempting to alter the data sent from one of the nodes to the other. I'm using the Atmel Wireshark Sniffer tool with an atzb-x-212b-USB to trouble shoot things while i'm working on the devices (other atzb-x-212b-USBs), and am noticing my alterations to the data aren't being sent as i would expect.

I've been mainly making changes to the appsendData() function to send specific characters to the other node. Here's my code.

Basically all I want it to do is send the specified data (in this case 0x0607) whenever a keystroke is entered instead of the system keycode for the character. Unfortunately this isn't working, and the 0x0607 is being manipulated into some other hex value was wondering if anyone had any ideas as to why. It seems i must be missing something about how the data is handled in the framework. From what I can tell it gets inserted into the constructed frame in AppDataReq.c but that doesn't seem to be the case.

At this point I feel I understand this function pretty well, except for the memcpy() so I'm not too sure what else to do.

static void appSendData(void)
{
   if (appDataReqBusy || 0 == appUartBufferPtr) {
      return;
   }

   memcpy(appDataReqBuffer, appUartBuffer, appUartBufferPtr);

   appDataReq.dstAddr = 1 - APP_ADDR;
   appDataReq.dstEndpoint = APP_ENDPOINT;
   appDataReq.srcEndpoint = APP_ENDPOINT;
   //appDataReq.options = NWK_OPT_ENABLE_SECURITY; I have this commented out in case it causes the data to be encrypted, to rule it out as an issue.
   appDataReq.data = 0x0607;
   appDataReq.size = 2;
   appDataReq.confirm = appDataConf;
   NWK_DataReq(&appDataReq);

   appUartBufferPtr = 0;
   appDataReqBusy = true;
   LED_Toggle(LED0);
}
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11720
  • Country: us
    • Personal site
Re: Understanding LWMesh Peer2Peer Application and Data Handling
« Reply #1 on: September 06, 2016, 08:58:44 pm »
data is a pointer to the array, you can't just assign a number to it, you will be sending random junk from memory.

If you want to send values 0x06 0x07, then do something like this:

Code: [Select]
static uint8_t array[] = {0x06, 0x07}; // at a global scope
...
appDataReq.data = array;
Alex
 
The following users thanked this post: wifiguy11

Offline wifiguy11Topic starter

  • Newbie
  • Posts: 7
  • Country: us
Re: Understanding LWMesh Peer2Peer Application and Data Handling
« Reply #2 on: September 06, 2016, 09:12:14 pm »
That makes total sense. Thanks!
 

Offline wifiguy11Topic starter

  • Newbie
  • Posts: 7
  • Country: us
Re: Understanding LWMesh Peer2Peer Application and Data Handling
« Reply #3 on: September 12, 2016, 06:10:04 pm »
I guess I do now have a followup question. I can get the device to now send whatever data I want. However, there seems to be a catch. The length of the message seems to be at a fixed length. Any data I send will be preceded by unwanted repeated information, such as the network sequence number, as well as the SrcAddr. I can see that these are already previously listed in the header.

I found where  these extra values are being added, and its in nwkDataReqSendFrame() in nwkDatareqSendFrame.c in the function below next  the arrows.

I currently have them commented out, just to see how the header looks. And it appears that this will remove the excess values, however they are replaced with 0's, and not complete removed from the data portion of wireshark. .

So I guess my question is, where is the data frame length listed from within the framework, or how can i fully rid of these values so that only the data listed in in my array is what is contained within the wireshark  data. I would like to be able to change my data length.

static void nwkDataReqSendFrame(NWK_DataReq_t *req)
{
   NwkFrame_t *frame;

   if (NULL == (frame = nwkFrameAlloc())) {
      req->state = NWK_DATA_REQ_STATE_CONFIRM;
      req->status = NWK_OUT_OF_MEMORY_STATUS;
      return;
   }

   req->frame = frame;
   req->state = NWK_DATA_REQ_STATE_WAIT_CONF;

   frame->tx.confirm = nwkDataReqTxConf;
   frame->tx.control = req->options &
         NWK_OPT_BROADCAST_PAN_ID ?
         NWK_TX_CONTROL_BROADCAST_PAN_ID
         : 0;

   frame->header.nwkFcf.ackRequest = req->options &
         NWK_OPT_ACK_REQUEST ? 1 : 0;
   frame->header.nwkFcf.linkLocal = req->options &
         NWK_OPT_LINK_LOCAL ? 1 : 0;

#ifdef NWK_ENABLE_SECURITY
   frame->header.nwkFcf.security = req->options &
         NWK_OPT_ENABLE_SECURITY ? 1 : 0;
#endif

#ifdef NWK_ENABLE_MULTICAST
   frame->header.nwkFcf.multicast = req->options &
         NWK_OPT_MULTICAST ? 1 : 0;

   if (frame->header.nwkFcf.multicast) {
      NwkFrameMulticastHeader_t *mcHeader
         = (NwkFrameMulticastHeader_t *)frame->payload;

      mcHeader->memberRadius = req->memberRadius;
      mcHeader->maxMemberRadius = req->memberRadius;
      mcHeader->nonMemberRadius = req->nonMemberRadius;
      mcHeader->maxNonMemberRadius = req->nonMemberRadius;

      frame->payload += sizeof(NwkFrameMulticastHeader_t);
      frame->size += sizeof(NwkFrameMulticastHeader_t);
   }
#endif

   //frame->header.nwkSeq = ++nwkIb.nwkSeqNum; <-----**************************************
   //frame->header.nwkSrcAddr = nwkIb.addr; <------------*************************************
   frame->header.nwkDstAddr = req->dstAddr;
   frame->header.nwkSrcEndpoint = req->srcEndpoint;
   frame->header.nwkDstEndpoint = req->dstEndpoint;

   memcpy(frame->payload, req->data, req->size);
   frame->size += req->size;

   nwkTxFrame(frame);
}
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11720
  • Country: us
    • Personal site
Re: Understanding LWMesh Peer2Peer Application and Data Handling
« Reply #4 on: September 12, 2016, 06:13:50 pm »
Any data I send will be preceded by unwanted repeated information, such as the network sequence number, as well as the SrcAddr. I can see that these are already previously listed in the header.
Repeated compared to what? Where is the first instance of this information?

Everything put into the frame is required for normal operation, you can't just comment out things.

So I guess my question is, where is the data frame length listed from within the framework, or how can i fully rid of these values so that only the data listed in in my array is what is contained within the wireshark  data. I would like to be able to change my data length.
You can't eliminate headers added by the stack, because that's the only thing stack really does. If you want to have full control over the raw frame payload, then remove most of the stack and just use PHY_DataReq().
Alex
 

Offline wifiguy11Topic starter

  • Newbie
  • Posts: 7
  • Country: us
Re: Understanding LWMesh Peer2Peer Application and Data Handling
« Reply #5 on: September 12, 2016, 08:57:37 pm »
I see, I was just commenting out that stuff to see the impact it had on the construction of the stack.
I intend to leave the framework as is, but am now curious as to why im seeing this. here is the raw data I'm seeing in wireshark, and relevant information.

APP_ADDR 0xbeef
APP_PANID 0xdead
dstAddr 0xfedd
data {0x45, 58}

61 88 02 ad de | dd fe | ef be | 00 | 02 | ef be | dd fe | 55 45 58 be 87

As you can see APP_ADDR, dstAddr, and the nwkSeqNum are being repeated. Wireshark doesn't seem to know what to do with the repeated values, and just calls it part of the data.

At first i thought this was because the developer guide shows that there is both a network header and a mac header. however there's a slight difference in that there should be two bytes for the frame control field in the network header, but in my case its only one, and says its 00, and not 61 88 in my case. After typing this out i think there just may be some issue with my understanding about the frame control field.
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11720
  • Country: us
    • Personal site
Re: Understanding LWMesh Peer2Peer Application and Data Handling
« Reply #6 on: September 12, 2016, 09:03:35 pm »
As you can see APP_ADDR, dstAddr, and the nwkSeqNum are being repeated. Wireshark doesn't seem to know what to do with the repeated values, and just calls it part of the data.
They are not repeated. Wireshark only shows IEEE 802.15.4 MAC header, but network layer adds its own header. The values have very different meaning and will be different in case if routing is required. Their use is illustrated with pictures in the developers guide.

At first i thought this was because the developer guide shows that there is both a network header and a mac header. however there's a slight difference in that there should be two bytes for the frame control field in the network header, but in my case its only one, and says its 00, and not 61 88 in my case.
You are mixing MAC and NWK FCF. Full format of the mandatory stack data (MAC + NWK headers) is described by the NwkFrameHeader_t structure. You can perfectly match this with your capture. The first 0x61 0x88 is macFcf, the rest follows.

BTW, Wireshark supports LwMesh, you just need to use reasonably recent version of Wireshark and enable it in the settings.

Alex
 

Offline wifiguy11Topic starter

  • Newbie
  • Posts: 7
  • Country: us
Re: Understanding LWMesh Peer2Peer Application and Data Handling
« Reply #7 on: September 13, 2016, 08:18:23 pm »
After looking at it again, everything makes total sense at how i'm seeing the frame in wireshark (I did have lwmesh disabled, so oopsie there).

As an after thought, is there an easy way to remove the network header from the frame completely without altering the framework code? As far as I am aware, the network header is only used for routing, and in the peer2peer application, there are only two devices. I thought disabling routing from the config would work, but that didn't seem to do the trick.

This isn't super critical for my purposes, just curious

 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11720
  • Country: us
    • Personal site
Re: Understanding LWMesh Peer2Peer Application and Data Handling
« Reply #8 on: September 13, 2016, 08:31:59 pm »
As an after thought, is there an easy way to remove the network header from the frame completely without altering the framework code?
There is no easy way to do this. The only way is to edit it out of NwkFrameHeader_t and remove all the code that depends on those fields. But that's going to be 90% of the stack.

As far as I am aware, the network header is only used for routing, and in the peer2peer application, there are only two devices.
No, you can have as many devices as you want in-between two devices that are sending the data to each other.
Alex
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf