Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Class B fixes #481

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/lmic/lmic.c
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ static CONST_TABLE(u1_t, macCmdSize)[] = {
static u1_t getMacCmdSize(u1_t macCmd) {
if (macCmd < 2)
return 0;
if (macCmd >= LENOF_TABLE(macCmdSize) - 2)
if ((macCmd - 2) >= LENOF_TABLE(macCmdSize))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh. Sorry about this one.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem, but I'm wondering why 0 is returned in the error case, because in scan_mac_cmds I see no check except for line 887, which doesn't do what the comment says.

https://github.com/sualko/arduino-lmic/blob/cabf6fbcd4390fcc42102a47c0323b7dafc6723a/src/lmic/lmic.c#L887

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's a bug too -- no test cases for bad mac commands, even in certification.

Should be if (cmdlen == 0 || cmdlen >> olen - oidx).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was fixed in 06b53c7, merged in #555 (and possibly before that, but that's the most recent change).

return 0;
return TABLE_GET_U1(macCmdSize, macCmd - 2);
}
Expand Down Expand Up @@ -1889,6 +1889,9 @@ static bit_t buildDataFrame (void) {
LMIC.frame[OFF_DAT_HDR] = HDR_FTYPE_DAUP | HDR_MAJOR_V1;
LMIC.frame[OFF_DAT_FCT] = (LMIC.dnConf | LMIC.adrEnabled
| (sendAdrAckReq() ? FCT_ADRACKReq : 0)
#if !defined(DISABLE_PING)
| ((LMIC.opmode & OP_PINGABLE) ? FCT_CLASSB : 0)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@terrillmoore I think LMIC.opmode & OP_PINGABLE is the wrong check, because this is true after LMIC_setPingable is called, but this doesn't mean that the periodic read has started (e.g. the device has no beacon received yet). Is OP_TRACK the right mask?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess. The spec is not clear about this at all. Here's the relevant text (starting at line 1147, page 43, spec 1.0.3

The end-device application requests the LoRaWAN layer 1147 to switch to Class B mode. The LoRaWAN layer in the end-device searches for a beacon and returns either a BEACON_LOCKED service primitive to the application if a network beacon was found and locked or a BEACON_NOT_FOUND service primitive. To accelerate the beacon discovery the LoRaWAN layer MAY use the “DeviceTimeReq” MAC command.

Once in Class B mode, the MAC layer sets to 1 the Class B bit of the FCTRL field of every uplink frame transmitted.

From context, it does appear possible that they mean the device has to be locked to the beacon. So I think it makes sense to change to OP_TRACK, as that bit is set exactly when EV_BEACON_FOUND is reported.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixing as part of #208 major update.

#endif // ndef DISABLE_PING
| (end-OFF_DAT_OPTS));
os_wlsbf4(LMIC.frame+OFF_DAT_ADDR, LMIC.devaddr);

Expand Down