Skip to content

Commit 71348f7

Browse files
author
Hasnain Virk
committed
Message flags correction
Uplink multicast is not allowed. Proprietary messages cannot be of type unconfirmed and unconfirmed.
1 parent 79640c6 commit 71348f7

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
@@ -64,6 +64,12 @@ using namespace events;
6464
#endif
6565
#endif
6666

67+
/**
68+
* Bit mask for message flags
69+
*/
70+
71+
#define MSG_FLAG_MASK 0x0F
72+
6773
/*****************************************************************************
6874
* Constructor *
6975
****************************************************************************/
@@ -292,10 +298,17 @@ int16_t LoRaWANStack::handle_tx(const uint8_t port, const uint8_t* data,
292298
return status;
293299
}
294300

295-
if (flags == 0 ||
296-
(flags & MSG_FLAG_MASK) == (MSG_CONFIRMED_FLAG|MSG_UNCONFIRMED_FLAG)) {
297-
tr_error("CONFIRMED and UNCONFIRMED are mutually exclusive for send()");
298-
return LORAWAN_STATUS_PARAMETER_INVALID;
301+
// All the flags mutually exclusive. In addition to that MSG_MULTICAST_FLAG cannot be
302+
// used for uplink.
303+
switch (flags & MSG_FLAG_MASK) {
304+
case MSG_UNCONFIRMED_FLAG:
305+
case MSG_CONFIRMED_FLAG:
306+
case MSG_PROPRIETARY_FLAG:
307+
break;
308+
309+
default:
310+
tr_error("Invalid send flags");
311+
return LORAWAN_STATUS_PARAMETER_INVALID;
299312
}
300313

301314
int16_t len = _loramac.prepare_ongoing_tx(port, data, length, flags, _num_retry);
@@ -533,8 +546,8 @@ void LoRaWANStack::process_reception(const uint8_t* const payload, uint16_t size
533546
state_controller(DEVICE_STATE_STATUS_CHECK);
534547
}
535548
} else {
536-
// handle UNCONFIRMED case here, RX slots were turned off due to
537-
// valid packet reception
549+
// handle UNCONFIRMED, PROPRIETARY case here, RX slots were turned off due to
550+
// valid packet reception, so we generate a TX_DONE event
538551
_loramac.post_process_mcps_req();
539552
_ctrl_flags |= TX_DONE_FLAG;
540553
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
@@ -179,7 +179,7 @@ void LoRaMac::post_process_mcps_req()
179179
}
180180

181181
} else {
182-
//UNCONFIRMED
182+
//UNCONFIRMED or PROPRIETARY
183183
if (_params.is_ul_frame_counter_fixed == false) {
184184
_params.ul_frame_counter++;
185185
}
@@ -1217,26 +1217,27 @@ int16_t LoRaMac::prepare_ongoing_tx(const uint8_t port,
12171217
}
12181218
}
12191219

1220-
// Handles all unconfirmed messages, including proprietary and multicast
1221-
if ((flags & MSG_FLAG_MASK) == MSG_UNCONFIRMED_FLAG
1222-
|| (flags & MSG_FLAG_MASK) == MSG_UNCONFIRMED_MULTICAST
1223-
|| (flags & MSG_FLAG_MASK) == MSG_UNCONFIRMED_PROPRIETARY) {
1224-
1220+
// Handles unconfirmed messages
1221+
if (flags & MSG_UNCONFIRMED_FLAG) {
12251222
_ongoing_tx_msg.type = MCPS_UNCONFIRMED;
12261223
_ongoing_tx_msg.fport = port;
12271224
_ongoing_tx_msg.nb_trials = 1;
12281225
}
12291226

1230-
// Handles all confirmed messages, including proprietary and multicast
1231-
if ((flags & MSG_FLAG_MASK) == MSG_CONFIRMED_FLAG
1232-
|| (flags & MSG_FLAG_MASK) == MSG_CONFIRMED_MULTICAST
1233-
|| (flags & MSG_FLAG_MASK) == MSG_CONFIRMED_PROPRIETARY) {
1234-
1227+
// Handles confirmed messages
1228+
if (flags & MSG_CONFIRMED_FLAG) {
12351229
_ongoing_tx_msg.type = MCPS_CONFIRMED;
12361230
_ongoing_tx_msg.fport = port;
12371231
_ongoing_tx_msg.nb_trials = num_retries;
12381232
}
12391233

1234+
// Handles proprietary messages
1235+
if (flags & MSG_PROPRIETARY_FLAG) {
1236+
_ongoing_tx_msg.type = MCPS_PROPRIETARY;
1237+
_ongoing_tx_msg.fport = port;
1238+
_ongoing_tx_msg.nb_trials = 1;
1239+
}
1240+
12401241
tr_info("RTS = %u bytes, PEND = %u, Port: %u",
12411242
_ongoing_tx_msg.f_buffer_size, _ongoing_tx_msg.pending_size,
12421243
_ongoing_tx_msg.fport);
@@ -1269,7 +1270,6 @@ lorawan_status_t LoRaMac::send_ongoing_tx()
12691270
machdr.bits.mtype = FRAME_TYPE_DATA_CONFIRMED_UP;
12701271
_params.max_ack_timeout_retries = _ongoing_tx_msg.nb_trials;
12711272
} else if (_ongoing_tx_msg.type == MCPS_PROPRIETARY) {
1272-
//TODO: Is this dead code currently??? Nobody sets this type
12731273
machdr.bits.mtype = FRAME_TYPE_PROPRIETARY;
12741274
} else {
12751275
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)