Skip to content

Commit 863259e

Browse files
author
Cruz Monrreal
authored
Merge pull request #6960 from hasnainvirk/msg_flags
LoRaWAN: Message flags correction
2 parents 99df848 + 71348f7 commit 863259e

File tree

3 files changed

+35
-44
lines changed

3 files changed

+35
-44
lines changed

features/lorawan/LoRaWANStack.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ using namespace events;
5858
#endif
5959
#endif
6060

61+
/**
62+
* Bit mask for message flags
63+
*/
64+
65+
#define MSG_FLAG_MASK 0x0F
66+
6167
/*****************************************************************************
6268
* Constructor *
6369
****************************************************************************/
@@ -286,10 +292,17 @@ int16_t LoRaWANStack::handle_tx(const uint8_t port, const uint8_t* data,
286292
return status;
287293
}
288294

289-
if (flags == 0 ||
290-
(flags & MSG_FLAG_MASK) == (MSG_CONFIRMED_FLAG|MSG_UNCONFIRMED_FLAG)) {
291-
tr_error("CONFIRMED and UNCONFIRMED are mutually exclusive for send()");
292-
return LORAWAN_STATUS_PARAMETER_INVALID;
295+
// All the flags mutually exclusive. In addition to that MSG_MULTICAST_FLAG cannot be
296+
// used for uplink.
297+
switch (flags & MSG_FLAG_MASK) {
298+
case MSG_UNCONFIRMED_FLAG:
299+
case MSG_CONFIRMED_FLAG:
300+
case MSG_PROPRIETARY_FLAG:
301+
break;
302+
303+
default:
304+
tr_error("Invalid send flags");
305+
return LORAWAN_STATUS_PARAMETER_INVALID;
293306
}
294307

295308
int16_t len = _loramac.prepare_ongoing_tx(port, data, length, flags, _num_retry);
@@ -527,8 +540,8 @@ void LoRaWANStack::process_reception(const uint8_t* const payload, uint16_t size
527540
state_controller(DEVICE_STATE_STATUS_CHECK);
528541
}
529542
} else {
530-
// handle UNCONFIRMED case here, RX slots were turned off due to
531-
// valid packet reception
543+
// handle UNCONFIRMED, PROPRIETARY case here, RX slots were turned off due to
544+
// valid packet reception, so we generate a TX_DONE event
532545
_loramac.post_process_mcps_req();
533546
_ctrl_flags |= TX_DONE_FLAG;
534547
state_controller(DEVICE_STATE_STATUS_CHECK);

features/lorawan/lorastack/mac/LoRaMac.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ void LoRaMac::post_process_mcps_req()
172172
}
173173

174174
} else {
175-
//UNCONFIRMED
175+
//UNCONFIRMED or PROPRIETARY
176176
if (_params.is_ul_frame_counter_fixed == false) {
177177
_params.ul_frame_counter++;
178178
}
@@ -1210,26 +1210,27 @@ int16_t LoRaMac::prepare_ongoing_tx(const uint8_t port,
12101210
}
12111211
}
12121212

1213-
// Handles all unconfirmed messages, including proprietary and multicast
1214-
if ((flags & MSG_FLAG_MASK) == MSG_UNCONFIRMED_FLAG
1215-
|| (flags & MSG_FLAG_MASK) == MSG_UNCONFIRMED_MULTICAST
1216-
|| (flags & MSG_FLAG_MASK) == MSG_UNCONFIRMED_PROPRIETARY) {
1217-
1213+
// Handles unconfirmed messages
1214+
if (flags & MSG_UNCONFIRMED_FLAG) {
12181215
_ongoing_tx_msg.type = MCPS_UNCONFIRMED;
12191216
_ongoing_tx_msg.fport = port;
12201217
_ongoing_tx_msg.nb_trials = 1;
12211218
}
12221219

1223-
// Handles all confirmed messages, including proprietary and multicast
1224-
if ((flags & MSG_FLAG_MASK) == MSG_CONFIRMED_FLAG
1225-
|| (flags & MSG_FLAG_MASK) == MSG_CONFIRMED_MULTICAST
1226-
|| (flags & MSG_FLAG_MASK) == MSG_CONFIRMED_PROPRIETARY) {
1227-
1220+
// Handles confirmed messages
1221+
if (flags & MSG_CONFIRMED_FLAG) {
12281222
_ongoing_tx_msg.type = MCPS_CONFIRMED;
12291223
_ongoing_tx_msg.fport = port;
12301224
_ongoing_tx_msg.nb_trials = num_retries;
12311225
}
12321226

1227+
// Handles proprietary messages
1228+
if (flags & MSG_PROPRIETARY_FLAG) {
1229+
_ongoing_tx_msg.type = MCPS_PROPRIETARY;
1230+
_ongoing_tx_msg.fport = port;
1231+
_ongoing_tx_msg.nb_trials = 1;
1232+
}
1233+
12331234
tr_info("RTS = %u bytes, PEND = %u, Port: %u",
12341235
_ongoing_tx_msg.f_buffer_size, _ongoing_tx_msg.pending_size,
12351236
_ongoing_tx_msg.fport);
@@ -1262,7 +1263,6 @@ lorawan_status_t LoRaMac::send_ongoing_tx()
12621263
machdr.bits.mtype = FRAME_TYPE_DATA_CONFIRMED_UP;
12631264
_params.max_ack_timeout_retries = _ongoing_tx_msg.nb_trials;
12641265
} else if (_ongoing_tx_msg.type == MCPS_PROPRIETARY) {
1265-
//TODO: Is this dead code currently??? Nobody sets this type
12661266
machdr.bits.mtype = FRAME_TYPE_PROPRIETARY;
12671267
} else {
12681268
return LORAWAN_STATUS_SERVICE_UNKNOWN;

features/lorawan/lorawan_types.h

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -36,38 +36,16 @@
3636

3737
/**
3838
* Option Flags for send(), receive() APIs
39+
*
40+
* Special Notes for UPLINK:
41+
* i) All of the flags are mutually exclusive.
42+
* ii) MSG_MULTICAST_FLAG cannot be used.
3943
*/
4044
#define MSG_UNCONFIRMED_FLAG 0x01
4145
#define MSG_CONFIRMED_FLAG 0x02
4246
#define MSG_MULTICAST_FLAG 0x04
4347
#define MSG_PROPRIETARY_FLAG 0x08
4448

45-
/**
46-
* Bit mask for message flags
47-
*/
48-
49-
#define MSG_FLAG_MASK 0x0F
50-
51-
/**
52-
* Mask for unconfirmed multicast message
53-
*/
54-
#define MSG_UNCONFIRMED_MULTICAST 0x05
55-
56-
/**
57-
* Mask for confirmed multicast message
58-
*/
59-
#define MSG_CONFIRMED_MULTICAST 0x06
60-
61-
/**
62-
* Mask for unconfirmed message proprietary message
63-
*/
64-
#define MSG_UNCONFIRMED_PROPRIETARY 0x09
65-
66-
/**
67-
* Mask for confirmed proprietary message
68-
*/
69-
#define MSG_CONFIRMED_PROPRIETARY 0x0A
70-
7149
/**
7250
* LoRaWAN device classes definition.
7351
*

0 commit comments

Comments
 (0)