[NOT A PROBLEM] : LoRaWan: LoRaMac.c - ValidatePayloadLength( ) fails to catch too large payload if fOptsLen != 0

EDIT NOTE: This may be ok, perhaps my not understanding LoRaWan, the end node is processing a MAC Link ADR REQ. Could be just the response being returned, I need to investigate further.

At this point I believe the code mentioned below is correct. However, I am seeing the user payload delivered even though it violates the max length for DR. I’ll open another thread for that to avoid confusion.

I no longer believe this code is in error

I’m chasing down some anomalies that occur if one tries to transmit a packet that is larger than the currently defined DR maximum. This is one:

cores/asr650x/loramac/mac/LoRaMac.c - ValidatePayloadLength() is not catching payload lengths that exceed the currently defined DR maximum if the fOptsLen parameter is not zero:

The following will demonstrate, this is run on Ubuntu Linux using cc version 9.3.0, although I don’t expect this to matter.

#include <stdio.h>
#include <stdbool.h>

bool checkLen( int userPayloadLen, int fOptsLen, int drLen);

void main() {
  int fOptsLen;
  int drMaxLen;
  int userPackLen;

  //    max user packet for DR_0 is 11, these are successful
   userPackLen = 10;
   fOptsLen = 0;
   drMaxLen = 11;
  checkLen( userPackLen, fOptsLen, drMaxLen);

   fOptsLen = 4;
  checkLen( userPackLen, fOptsLen, drMaxLen);

  //   these exceed drMaxLen and should not pass the check
   userPackLen = 20;
   fOptsLen = 4;
   drMaxLen = 11;
  checkLen( userPackLen, fOptsLen, drMaxLen);

   fOptsLen = 3;
  checkLen( userPackLen, fOptsLen, drMaxLen);
   fOptsLen = 2;
  checkLen( userPackLen, fOptsLen, drMaxLen);

  // this one correctly fails to pass the check
   fOptsLen = 0;
  checkLen( userPackLen, fOptsLen, drMaxLen);


  // Just trying a difference DR, max user packet for DR_3 is 242
   userPackLen = 243;
   fOptsLen = 4;
   drMaxLen = 242;
  checkLen( userPackLen, fOptsLen, drMaxLen);

  // with fOptsLen = 0, catches the packet too large
  fOptsLen = 0;
  checkLen( userPackLen, fOptsLen, drMaxLen);
}

// lenN application payload length
// fOptsLen
bool checkLen( int lenN, int fOptsLen, int lenPerDataRate)
{
   int maxN = lenPerDataRate;    // Data rate dependent max
   int LORAMAC_PHY_MAXPAYLOAD = 255;

   int payloadSize = ( lenN + fOptsLen );

   printf("userPayloadLen: %d, fOptsLen: %d\n", lenN, fOptsLen);

 // this if statement copied directly from the ValidataPayload() function
  if ( ((( payloadSize > maxN ) && (fOptsLen != 0) && (fOptsLen <= maxN)) || ( payloadSize <= maxN )) && ( payloadSize <= LORAMAC_PHY_MAXPAYLOAD ) ) {
        printf("\tcheck true, size ok\n\n");
        return true;
    }
    printf("\tcheck false, packet too large\n\n");
    return false;
}


Interesting original semtech code, around for a while …

This may be ok, perhaps my not understanding LoRaWan, the end node is processing a MAC Link ADR REQ. Could be just the response being returned, I need to investigate further.