diff --git a/include/zephyr/lorawan/lorawan.h b/include/zephyr/lorawan/lorawan.h index 058c4cbabc7..61f05997504 100644 --- a/include/zephyr/lorawan/lorawan.h +++ b/include/zephyr/lorawan/lorawan.h @@ -103,6 +103,13 @@ enum lorawan_message_type { LORAWAN_MSG_CONFIRMED, /**< Confirmed message */ }; +/** + * @brief LoRaWAN downlink flags. + */ +enum lorawan_dl_flags { + LORAWAN_DATA_PENDING = BIT(0), +}; + /** * @brief LoRaWAN join parameters for over-the-Air activation (OTAA) * @@ -181,15 +188,14 @@ struct lorawan_downlink_cb { * and should therefore be as short as possible. * * @param port Port message was sent on - * @param data_pending Network server has more downlink packets pending + * @param flags Downlink data flags (see @ref lorawan_dl_flags) * @param rssi Received signal strength in dBm * @param snr Signal to Noise ratio in dBm * @param len Length of data received, will be 0 for ACKs * @param data Data received, will be NULL for ACKs */ - void (*cb)(uint8_t port, bool data_pending, - int16_t rssi, int8_t snr, - uint8_t len, const uint8_t *data); + void (*cb)(uint8_t port, uint8_t flags, int16_t rssi, int8_t snr, uint8_t len, + const uint8_t *data); /** Node for callback list */ sys_snode_t node; }; diff --git a/samples/subsys/lorawan/class_a/src/main.c b/samples/subsys/lorawan/class_a/src/main.c index 1e31baf36e4..e09d6945907 100644 --- a/samples/subsys/lorawan/class_a/src/main.c +++ b/samples/subsys/lorawan/class_a/src/main.c @@ -27,11 +27,12 @@ LOG_MODULE_REGISTER(lorawan_class_a); char data[] = {'h', 'e', 'l', 'l', 'o', 'w', 'o', 'r', 'l', 'd'}; -static void dl_callback(uint8_t port, bool data_pending, +static void dl_callback(uint8_t port, uint8_t flags, int16_t rssi, int8_t snr, uint8_t len, const uint8_t *hex_data) { - LOG_INF("Port %d, Pending %d, RSSI %ddB, SNR %ddBm", port, data_pending, rssi, snr); + LOG_INF("Port %d, Pending %d, RSSI %ddB, SNR %ddBm", + port, flags & LORAWAN_DATA_PENDING, rssi, snr); if (hex_data) { LOG_HEXDUMP_INF(hex_data, len, "Payload: "); } diff --git a/subsys/lorawan/lorawan.c b/subsys/lorawan/lorawan.c index 8a4830a37e2..1e33f95d2d7 100644 --- a/subsys/lorawan/lorawan.c +++ b/subsys/lorawan/lorawan.c @@ -148,6 +148,7 @@ static void mcps_confirm_handler(McpsConfirm_t *mcps_confirm) static void mcps_indication_handler(McpsIndication_t *mcps_indication) { struct lorawan_downlink_cb *cb; + uint8_t flags = 0; LOG_DBG("Received McpsIndication %d", mcps_indication->McpsIndication); @@ -162,15 +163,15 @@ static void mcps_indication_handler(McpsIndication_t *mcps_indication) datarate_observe(false); } + /* IsUplinkTxPending also indicates pending downlinks */ + flags |= (mcps_indication->IsUplinkTxPending == 1 ? LORAWAN_DATA_PENDING : 0); + /* Iterate over all registered downlink callbacks */ SYS_SLIST_FOR_EACH_CONTAINER(&dl_callbacks, cb, node) { if ((cb->port == LW_RECV_PORT_ANY) || (cb->port == mcps_indication->Port)) { - cb->cb(mcps_indication->Port, - /* IsUplinkTxPending also indicates pending downlinks */ - mcps_indication->IsUplinkTxPending == 1, - mcps_indication->Rssi, mcps_indication->Snr, - mcps_indication->BufferSize, + cb->cb(mcps_indication->Port, flags, mcps_indication->Rssi, + mcps_indication->Snr, mcps_indication->BufferSize, mcps_indication->Buffer); } } diff --git a/subsys/lorawan/services/clock_sync.c b/subsys/lorawan/services/clock_sync.c index 5249f43b881..bac4b466cda 100644 --- a/subsys/lorawan/services/clock_sync.c +++ b/subsys/lorawan/services/clock_sync.c @@ -91,7 +91,7 @@ static inline k_timeout_t clock_sync_calc_periodicity(void) return K_SECONDS(ctx.periodicity - 30 + sys_rand32_get() % 61); } -static void clock_sync_package_callback(uint8_t port, bool data_pending, int16_t rssi, int8_t snr, +static void clock_sync_package_callback(uint8_t port, uint8_t flags, int16_t rssi, int8_t snr, uint8_t len, const uint8_t *rx_buf) { uint8_t tx_buf[3 * MAX_CLOCK_SYNC_ANS_LEN]; diff --git a/subsys/lorawan/services/frag_transport.c b/subsys/lorawan/services/frag_transport.c index 24541e30de0..5bb180bb161 100644 --- a/subsys/lorawan/services/frag_transport.c +++ b/subsys/lorawan/services/frag_transport.c @@ -101,8 +101,8 @@ static struct frag_transport_context ctx; /* Callback for notification of finished firmware transfer */ static void (*finished_cb)(void); -static void frag_transport_package_callback(uint8_t port, bool data_pending, int16_t rssi, - int8_t snr, uint8_t len, const uint8_t *rx_buf) +static void frag_transport_package_callback(uint8_t port, uint8_t flags, int16_t rssi, int8_t snr, + uint8_t len, const uint8_t *rx_buf) { uint8_t tx_buf[FRAG_TRANSPORT_MAX_CMDS_PER_PACKAGE * FRAG_TRANSPORT_MAX_ANS_LEN]; uint8_t tx_pos = 0; diff --git a/subsys/lorawan/services/multicast.c b/subsys/lorawan/services/multicast.c index c6af76eca1e..72f2de0497e 100644 --- a/subsys/lorawan/services/multicast.c +++ b/subsys/lorawan/services/multicast.c @@ -107,7 +107,7 @@ static int32_t multicast_schedule_class_c_session(uint8_t id, uint32_t session_t return time_to_start; } -static void multicast_package_callback(uint8_t port, bool data_pending, int16_t rssi, int8_t snr, +static void multicast_package_callback(uint8_t port, uint8_t flags, int16_t rssi, int8_t snr, uint8_t len, const uint8_t *rx_buf) { uint8_t tx_buf[MAX_MULTICAST_CMDS_PER_PACKAGE * MAX_MULTICAST_ANS_LEN];