You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/01/04 20:47:50 UTC

[GitHub] wes3 closed pull request #714: net/lora: Remove MLME and MAC primitives from code

wes3 closed pull request #714: net/lora: Remove MLME and MAC primitives from code
URL: https://github.com/apache/mynewt-core/pull/714
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/net/lora/node/include/node/lora.h b/net/lora/node/include/node/lora.h
index cb004fcbf..4ca0d3a42 100644
--- a/net/lora/node/include/node/lora.h
+++ b/net/lora/node/include/node/lora.h
@@ -125,7 +125,28 @@ struct lora_txd_info
     int8_t txpower;
 
     /*!
-     * Provides the number of retransmissions
+     * Initially, 'retries' for confirmed frames is the number of trials
+     * (described below). In the confirmation, this field is set to the
+     * actual # of retries (0 retries if successful on first attempt).
+     *
+     * Number of trials to transmit the frame, if the LoRaMAC layer did not
+     * receive an acknowledgment. The MAC performs a datarate adaptation,
+     * according to the LoRaWAN Specification V1.0.1, chapter 19.4, according
+     * to the following table:
+     *
+     * Transmission nb | Data Rate
+     * ----------------|-----------
+     * 1 (first)       | DR
+     * 2               | DR
+     * 3               | max(DR-1,0)
+     * 4               | max(DR-1,0)
+     * 5               | max(DR-2,0)
+     * 6               | max(DR-2,0)
+     * 7               | max(DR-3,0)
+     * 8               | max(DR-3,0)
+     *
+     * Note, that if NbTrials is set to 1 or 2, the MAC will not decrease
+     * the datarate, in case the LoRaMAC layer did not receive an acknowledgment
      */
     uint8_t retries;
 
@@ -157,7 +178,7 @@ struct lora_txd_info
 struct lora_pkt_info
 {
     uint8_t port;
-    Mcps_t pkt_type;
+    uint8_t pkt_type;
     LoRaMacEventInfoStatus_t status;
 
     union {
diff --git a/net/lora/node/include/node/lora_priv.h b/net/lora/node/include/node/lora_priv.h
index 4dc083b01..9238ed544 100644
--- a/net/lora/node/include/node/lora_priv.h
+++ b/net/lora/node/include/node/lora_priv.h
@@ -21,6 +21,55 @@
 #define H_LORA_PRIV_
 
 #include "node/mac/LoRaMac.h"
+#include "os/os.h"
+#include "node/lora.h"
+
+/*
+ * Lora MAC data object
+ */
+struct lora_mac_obj
+{
+    /* Task event queue */
+    struct os_eventq lm_evq;
+
+    /* Transmit queue */
+    struct os_mqueue lm_txq;
+
+    /* Join event */
+    struct os_event lm_join_ev;
+
+    /* Link check event */
+    struct os_event lm_link_chk_ev;
+
+    /* TODO: this is temporary until we figure out a better way to deal */
+    /* Transmit queue timer */
+    struct os_callout lm_txq_timer;
+
+    /*
+     * Pointer to the lora packet information of the packet being currently
+     * transmitted.
+     */
+    struct lora_pkt_info *curtx;
+
+    /*
+     * Global lora tx packet info structure. Used when transmitting but no mbuf
+     * was available for transmission.
+     */
+    struct lora_pkt_info txpkt;
+
+    /* Pointer to current transmit mbuf. Can be NULL and still txing */
+    struct os_mbuf *cur_tx_mbuf;
+
+    /*
+     * Global lora rx packet info structure. Used when receiving and prior to
+     * obtaining a mbuf.
+     */
+    uint16_t rxbufsize;
+    uint8_t *rxbuf;
+    struct lora_pkt_info rxpkt;
+};
+
+extern struct lora_mac_obj g_lora_mac_data;
 
 void lora_cli_init(void);
 void lora_app_init(void);
@@ -32,6 +81,7 @@ void lora_app_join_confirm(LoRaMacEventInfoStatus_t status, uint8_t attempts);
 void lora_app_link_chk_confirm(LoRaMacEventInfoStatus_t status, uint8_t num_gw,
                                uint8_t demod_margin);
 void lora_node_mcps_request(struct os_mbuf *om);
+void lora_node_mac_mcps_indicate(void);
 int lora_node_join(uint8_t *dev_eui, uint8_t *app_eui, uint8_t *app_key,
                    uint8_t trials);
 int lora_node_link_check(void);
diff --git a/net/lora/node/include/node/mac/LoRaMac.h b/net/lora/node/include/node/mac/LoRaMac.h
index d7bd714b7..a44780876 100644
--- a/net/lora/node/include/node/mac/LoRaMac.h
+++ b/net/lora/node/include/node/mac/LoRaMac.h
@@ -53,6 +53,8 @@
 #include "node/utilities.h"
 #include "os/os.h"
 
+struct lora_pkt_info;
+
 /*!
  * Beacon interval in ms
  */
@@ -683,242 +685,31 @@ typedef union eLoRaMacFlags_t
  *
  * Primitive        | Function
  * ---------------- | :---------------------:
- * MCPS-Request     | \ref LoRaMacMlmeRequest
- * MCPS-Confirm     | MacMcpsConfirm in \ref LoRaMacPrimitives_t
- * MCPS-Indication  | MacMcpsIndication in \ref LoRaMacPrimitives_t
+ * MCPS-Request     | \ref lora_node_mcps_request
+ * MLME-Confirm    | \ref lora_node_mac_mlme_confirm
+ * MCPS-Confirm     | \ref lora_node_mac_mcps_confirm
+ * MCPS-Indication  |  \ref lora_node_mac_mcps_indicate
  */
 typedef enum eMcps
 {
     /*!
      * Unconfirmed LoRaMAC frame
      */
-    MCPS_UNCONFIRMED,
+    MCPS_UNCONFIRMED = 0,
     /*!
      * Confirmed LoRaMAC frame
      */
-    MCPS_CONFIRMED,
+    MCPS_CONFIRMED = 1,
     /*!
      * Multicast LoRaMAC frame
      */
-    MCPS_MULTICAST,
+    MCPS_MULTICAST = 2,
     /*!
      * Proprietary frame
      */
-    MCPS_PROPRIETARY,
+    MCPS_PROPRIETARY = 3,
 }Mcps_t;
 
-/*!
- * LoRaMAC MCPS-Request for an unconfirmed frame
- */
-typedef struct sMcpsReqUnconfirmed
-{
-    /*!
-     * Frame port field. Must be set if the payload is not empty. Use the
-     * application specific frame port values: [1...223]
-     *
-     * LoRaWAN Specification V1.0.1, chapter 4.3.2
-     */
-    uint8_t fPort;
-    /*!
-     * Uplink datarate, if ADR is off
-     */
-    int8_t Datarate;
-}McpsReqUnconfirmed_t;
-
-/*!
- * LoRaMAC MCPS-Request for a confirmed frame
- */
-typedef struct sMcpsReqConfirmed
-{
-    /*!
-     * Frame port field. Must be set if the payload is not empty. Use the
-     * application specific frame port values: [1...223]
-     *
-     * LoRaWAN Specification V1.0.1, chapter 4.3.2
-     */
-    uint8_t fPort;
-    /*!
-     * Uplink datarate, if ADR is off
-     */
-    int8_t Datarate;
-    /*!
-     * Number of trials to transmit the frame, if the LoRaMAC layer did not
-     * receive an acknowledgment. The MAC performs a datarate adaptation,
-     * according to the LoRaWAN Specification V1.0.1, chapter 19.4, according
-     * to the following table:
-     *
-     * Transmission nb | Data Rate
-     * ----------------|-----------
-     * 1 (first)       | DR
-     * 2               | DR
-     * 3               | max(DR-1,0)
-     * 4               | max(DR-1,0)
-     * 5               | max(DR-2,0)
-     * 6               | max(DR-2,0)
-     * 7               | max(DR-3,0)
-     * 8               | max(DR-3,0)
-     *
-     * Note, that if NbTrials is set to 1 or 2, the MAC will not decrease
-     * the datarate, in case the LoRaMAC layer did not receive an acknowledgment
-     */
-    uint8_t NbTrials;
-}McpsReqConfirmed_t;
-
-/*!
- * LoRaMAC MCPS-Request for a proprietary frame
- */
-typedef struct sMcpsReqProprietary
-{
-    /*!
-     * Uplink datarate, if ADR is off
-     */
-    int8_t Datarate;
-}McpsReqProprietary_t;
-
-/*!
- * LoRaMAC MCPS-Request structure
- */
-typedef struct sMcpsReq
-{
-    /*!
-     * MCPS-Request type
-     */
-    Mcps_t Type;
-
-    /* Pointer to mbuf */
-    struct os_mbuf *om;
-
-    /*!
-     * MCPS-Request parameters
-     */
-    union uMcpsParam
-    {
-        /*!
-         * MCPS-Request parameters for an unconfirmed frame
-         */
-        McpsReqUnconfirmed_t Unconfirmed;
-        /*!
-         * MCPS-Request parameters for a confirmed frame
-         */
-        McpsReqConfirmed_t Confirmed;
-        /*!
-         * MCPS-Request parameters for a proprietary frame
-         */
-        McpsReqProprietary_t Proprietary;
-    }Req;
-}McpsReq_t;
-
-/*!
- * LoRaMAC MCPS-Confirm
- */
-typedef struct sMcpsConfirm
-{
-    /* Pointer to packet buffer */
-    struct os_mbuf *om;
-
-    /*!
-     * Holds the previously performed MCPS-Request Type
-     */
-    Mcps_t McpsRequest;
-    /*!
-     * Status of the operation
-     */
-    LoRaMacEventInfoStatus_t Status;
-    /*!
-     * Uplink datarate
-     */
-    uint8_t Datarate;
-    /*!
-     * Transmission power
-     */
-    int8_t TxPower;
-    /*!
-     * Set if an acknowledgement was received
-     */
-    bool AckReceived;
-    /*!
-     * Provides the number of retransmissions
-     */
-    uint8_t NbRetries;
-    /*!
-     * The transmission time on air of the frame
-     */
-    uint32_t TxTimeOnAir;
-    /*!
-     * The uplink counter value related to the frame
-     */
-    uint32_t UpLinkCounter;
-    /*!
-     * The uplink frequency related to the frame
-     */
-    uint32_t UpLinkFrequency;
-}McpsConfirm_t;
-
-/*!
- * LoRaMAC MCPS-Indication primitive
- */
-typedef struct sMcpsIndication
-{
-    /*!
-     * MCPS-Indication type
-     */
-    Mcps_t McpsIndication;
-    /*!
-     * Status of the operation
-     */
-    LoRaMacEventInfoStatus_t Status;
-    /*!
-     * Multicast
-     */
-    uint8_t Multicast;
-    /*!
-     * Application port
-     */
-    uint8_t Port;
-    /*!
-     * Downlink datarate
-     */
-    uint8_t RxDatarate;
-    /*!
-     * Frame pending status
-     */
-    uint8_t FramePending;
-    /*!
-     * Pointer to the received data stream
-     */
-    uint8_t *Buffer;
-    /*!
-     * Size of the received data stream
-     */
-    uint16_t BufferSize;
-    /*!
-     * Indicates, if data is available
-     */
-    bool RxData;
-    /*!
-     * Rssi of the received packet
-     */
-    int16_t Rssi;
-    /*!
-     * Snr of the received packet
-     */
-    uint8_t Snr;
-    /*!
-     * Receive window
-     *
-     * [0: Rx window 1, 1: Rx window 2]
-     */
-    uint8_t RxSlot;
-    /*!
-     * Set if an acknowledgement was received
-     */
-    bool AckReceived;
-    /*!
-     * The downlink counter value for the received frame
-     */
-    uint32_t DownLinkCounter;
-}McpsIndication_t;
-
 /*!
  * \brief LoRaMAC management services
  *
@@ -946,25 +737,25 @@ typedef enum eMlme
      *
      * LoRaWAN Specification V1.0.1, chapter 6.2
      */
-    MLME_JOIN,
+    MLME_JOIN = 0,
     /*!
      * LinkCheckReq - Connectivity validation
      *
      * LoRaWAN Specification V1.0.1, chapter 5, table 4
      */
-    MLME_LINK_CHECK,
+    MLME_LINK_CHECK = 1,
     /*!
      * Sets Tx continuous wave mode
      *
      * LoRaWAN end-device certification
      */
-    MLME_TXCW,
+    MLME_TXCW = 2,
     /*!
      * Sets Tx continuous wave mode (new LoRa-Alliance CC definition)
      *
      * LoRaWAN end-device certification
      */
-    MLME_TXCW_1,
+    MLME_TXCW_1 = 3,
 }Mlme_t;
 
 /*!
@@ -1041,38 +832,6 @@ typedef struct sMlmeReq
     }Req;
 }MlmeReq_t;
 
-/*!
- * LoRaMAC MLME-Confirm primitive
- */
-typedef struct sMlmeConfirm
-{
-    /*!
-     * Holds the previously performed MLME-Request
-     */
-    Mlme_t MlmeRequest;
-    /*!
-     * Status of the operation
-     */
-    LoRaMacEventInfoStatus_t Status;
-    /*!
-     * The transmission time on air of the frame
-     */
-    uint32_t TxTimeOnAir;
-    /*!
-     * Demodulation margin. Contains the link margin [dB] of the last
-     * successfully received LinkCheckReq
-     */
-    uint8_t DemodMargin;
-    /*!
-     * Number of gateways which received the last LinkCheckReq
-     */
-    uint8_t NbGateways;
-    /*!
-     * Provides the number of retransmissions
-     */
-    uint8_t NbRetries;
-}MlmeConfirm_t;
-
 /*!
  * LoRa Mac Information Base (MIB)
  *
@@ -1589,32 +1348,6 @@ typedef enum eLoRaMacStatus
     LORAMAC_STATUS_DEVICE_OFF,
 }LoRaMacStatus_t;
 
-/*!
- * LoRaMAC events structure
- * Used to notify upper layers of MAC events
- */
-typedef struct sLoRaMacPrimitives
-{
-    /*!
-     * \brief   MCPS-Confirm primitive
-     *
-     * \param   [OUT] MCPS-Confirm parameters
-     */
-    void ( *MacMcpsConfirm )( McpsConfirm_t *McpsConfirm );
-    /*!
-     * \brief   MCPS-Indication primitive
-     *
-     * \param   [OUT] MCPS-Indication parameters
-     */
-    void ( *MacMcpsIndication )( McpsIndication_t *McpsIndication );
-    /*!
-     * \brief   MLME-Confirm primitive
-     *
-     * \param   [OUT] MLME-Confirm parameters
-     */
-    void ( *MacMlmeConfirm )( MlmeConfirm_t *MlmeConfirm );
-}LoRaMacPrimitives_t;
-
 typedef struct sLoRaMacCallback
 {
     /*!
@@ -1633,11 +1366,7 @@ typedef struct sLoRaMacCallback
  *
  * \details In addition to the initialization of the LoRaMAC layer, this
  *          function initializes the callback primitives of the MCPS and
- *          MLME services. Every data field of \ref LoRaMacPrimitives_t must be
- *          set to a valid callback function.
- *
- * \param   [IN] events - Pointer to a structure defining the LoRaMAC
- *                        event functions. Refer to \ref LoRaMacPrimitives_t.
+ *          MLME services.
  *
  * \param   [IN] events - Pointer to a structure defining the LoRaMAC
  *                        callback functions. Refer to \ref LoRaMacCallback_t.
@@ -1647,7 +1376,7 @@ typedef struct sLoRaMacCallback
  *          \ref LORAMAC_STATUS_OK,
  *          \ref LORAMAC_STATUS_PARAMETER_INVALID.
  */
-LoRaMacStatus_t LoRaMacInitialization( LoRaMacPrimitives_t *primitives, LoRaMacCallback_t *callbacks );
+LoRaMacStatus_t LoRaMacInitialization( LoRaMacCallback_t *callbacks );
 
 /*!
  * \brief   Queries the LoRaMAC if it is possible to send the next frame with
@@ -1849,22 +1578,8 @@ LoRaMacStatus_t LoRaMacMlmeRequest( MlmeReq_t *mlmeRequest );
  *          code-snippet shows how to use the API to send an unconfirmed
  *          LoRaMAC frame.
  *
- * \code
- * uint8_t myBuffer[] = { 1, 2, 3 };
- *
- * McpsReq_t mcpsReq;
- * mcpsReq.Type = MCPS_UNCONFIRMED;
- * mcpsReq.Req.Unconfirmed.fPort = 1;
- * mcpsReq.Req.Unconfirmed.fBuffer = myBuffer;
- * mcpsReq.Req.Unconfirmed.fBufferSize = sizeof( myBuffer );
- *
- * if( LoRaMacMcpsRequest( &mcpsReq ) == LORAMAC_STATUS_OK )
- * {
- *   // Service started successfully. Waiting for the MCPS-Confirm event
- * }
- * \endcode
- *
- * \param   [IN] mcpsRequest - MCPS-Request to perform. Refer to \ref McpsReq_t.
+ * \param   [om] Pointer to mbuf to transmit.
+ * \param   [txi] Pointer to lora_pkt_info structure of current transmission.
  *
  * \retval  LoRaMacStatus_t Status of the operation. Possible returns are:
  *          \ref LORAMAC_STATUS_OK,
@@ -1875,7 +1590,8 @@ LoRaMacStatus_t LoRaMacMlmeRequest( MlmeReq_t *mlmeRequest );
  *          \ref LORAMAC_STATUS_LENGTH_ERROR,
  *          \ref LORAMAC_STATUS_DEVICE_OFF.
  */
-LoRaMacStatus_t LoRaMacMcpsRequest( McpsReq_t *mcpsRequest );
+LoRaMacStatus_t
+LoRaMacMcpsRequest(struct os_mbuf *om, struct lora_pkt_info *txi);
 
 /*!
  * \brief   lora_mac_tx_state
diff --git a/net/lora/node/src/lora_node.c b/net/lora/node/src/lora_node.c
index 564b8ea6d..55742f497 100644
--- a/net/lora/node/src/lora_node.c
+++ b/net/lora/node/src/lora_node.c
@@ -19,10 +19,7 @@
 #include <string.h>
 #include "sysinit/sysinit.h"
 #include "syscfg/syscfg.h"
-#include "os/os.h"
-#include "node/lora.h"
 #include "node/lora_priv.h"
-#include "node/mac/LoRaMac.h"
 
 STATS_SECT_DECL(lora_mac_stats) lora_mac_stats;
 STATS_NAME_START(lora_mac_stats)
@@ -65,10 +62,6 @@ uint8_t g_lora_app_key[LORA_KEY_LEN];
 /* Flag to denote if we last sent a mac command */
 uint8_t g_lora_node_last_tx_mac_cmd;
 
-#if !MYNEWT_VAL(LORA_NODE_CLI)
-LoRaMacPrimitives_t g_lora_primitives;
-#endif
-
 /* MAC task */
 #define LORA_MAC_STACK_SIZE   (256)
 struct os_task g_lora_mac_task;
@@ -77,25 +70,6 @@ os_stack_t g_lora_mac_stack[LORA_MAC_STACK_SIZE];
 /*
  * Lora MAC data object
  */
-struct lora_mac_obj
-{
-    /* Task event queue */
-    struct os_eventq lm_evq;
-
-    /* Transmit queue */
-    struct os_mqueue lm_txq;
-
-    /* Join event */
-    struct os_event lm_join_ev;
-
-    /* Link check event */
-    struct os_event lm_link_chk_ev;
-
-    /* TODO: this is temporary until we figure out a better way to deal */
-    /* Transmit queue timer */
-    struct os_callout lm_txq_timer;
-};
-
 struct lora_mac_obj g_lora_mac_data;
 
 /* The join event argument */
@@ -221,39 +195,13 @@ lora_node_txq_empty(void)
     return rc;
 }
 
-/* MAC MCPS-Confirm primitive */
-static void
-lora_node_mac_mcps_confirm(McpsConfirm_t *confirm)
-{
-    struct os_mbuf *om;
-    struct lora_pkt_info *lpkt;
-
-    /*
-     * XXX: note that datarate and retries were set when the
-     * request was made. They could have changed. Do we need
-     * to preserve original values?
-     */
-
-    /* Copy confirmation info into lora packet info */
-    om = confirm->om;
-    if (om == NULL) {
-        return;
-    }
-    lpkt = LORA_PKT_INFO_PTR(om);
-    lpkt->status = confirm->Status;
-    lpkt->txdinfo.datarate = confirm->Datarate;
-    lpkt->txdinfo.txpower = confirm->TxPower;
-    lpkt->txdinfo.ack_rxd = confirm->AckReceived;
-    lpkt->txdinfo.retries = confirm->NbRetries;
-    lpkt->txdinfo.tx_time_on_air = confirm->TxTimeOnAir;
-    lpkt->txdinfo.uplink_cntr = confirm->UpLinkCounter;
-    lpkt->txdinfo.uplink_freq = confirm->UpLinkFrequency;
-    lora_app_mcps_confirm(om);
-}
-
-/* MAC MCPS-Indicate primitive  */
-static void
-lora_node_mac_mcps_indicate(McpsIndication_t *ind)
+/**
+ * lora node mac mcps indicate
+ *
+ * MAC indication handler
+ */
+void
+lora_node_mac_mcps_indicate(void)
 {
     int rc;
     struct os_mbuf *om;
@@ -263,7 +211,7 @@ lora_node_mac_mcps_indicate(McpsIndication_t *ind)
      * Not sure if this is possible, but port 0 is not a valid application port.
      * If the port is 0 do not send indicate
      */
-    if (ind->Port == 0) {
+    if (g_lora_mac_data.rxpkt.port == 0) {
         /* XXX: count a statistic? */
         return;
     }
@@ -271,7 +219,8 @@ lora_node_mac_mcps_indicate(McpsIndication_t *ind)
     om = lora_pkt_alloc();
     if (om) {
         /* Copy data into mbuf */
-        rc = os_mbuf_copyinto(om, 0, ind->Buffer, ind->BufferSize);
+        rc = os_mbuf_copyinto(om, 0, g_lora_mac_data.rxbuf,
+                              g_lora_mac_data.rxbufsize);
         if (rc) {
             os_mbuf_free_chain(om);
             return;
@@ -279,47 +228,13 @@ lora_node_mac_mcps_indicate(McpsIndication_t *ind)
 
         /* Set lora packet info */
         lpkt = LORA_PKT_INFO_PTR(om);
-        lpkt->status = ind->Status;
-        lpkt->pkt_type = ind->McpsIndication;
-        lpkt->port = ind->Port;
-        lpkt->rxdinfo.rxdatarate = ind->RxDatarate;
-        lpkt->rxdinfo.rxdata = ind->RxData;
-        lpkt->rxdinfo.snr = ind->Snr;
-        lpkt->rxdinfo.rssi = ind->Rssi;
-        lpkt->rxdinfo.frame_pending = ind->FramePending == 0 ? 0 : 1;
-        lpkt->rxdinfo.ack_rxd = ind->AckReceived;
-        lpkt->rxdinfo.downlink_cntr = ind->DownLinkCounter;
-        lpkt->rxdinfo.rxslot = ind->RxSlot;
+        memcpy(lpkt, &g_lora_mac_data.rxpkt, sizeof(struct lora_pkt_info));
         lora_app_mcps_indicate(om);
     } else {
         /* XXX: cant do anything until the lower stack gets modified */
     }
 }
 
-/**
- * This is the LoRaMac stack Confirm primitive. It is called by the LoRaMac
- * stack upon completion of a MLME service.
- *
- * @param confirm
- */
-static void
-lora_node_mac_mlme_confirm(MlmeConfirm_t *confirm)
-{
-    /* XXX: do we need the time on air for MLME packets? */
-    switch (confirm->MlmeRequest) {
-    case MLME_JOIN:
-        lora_app_join_confirm(confirm->Status, confirm->NbRetries);
-        break;
-    case MLME_LINK_CHECK:
-        lora_app_link_chk_confirm(confirm->Status, confirm->NbGateways,
-                                  confirm->DemodMargin);
-        break;
-    default:
-        /* Nothing to do here */
-        break;
-    }
-}
-
 static uint8_t
 lora_node_get_batt_status(void)
 {
@@ -336,7 +251,6 @@ lora_node_get_batt_status(void)
 static void
 lora_mac_proc_tx_q_event(struct os_event *ev)
 {
-    McpsReq_t req;
     LoRaMacStatus_t rc;
     LoRaMacEventInfoStatus_t evstatus;
     LoRaMacTxInfo_t txinfo;
@@ -396,21 +310,23 @@ lora_mac_proc_tx_q_event(struct os_event *ev)
             STATS_INC(lora_mac_stats, tx_mac_flush);
             /* NOTE: no need to get a mbuf. */
 send_empty_msg:
-            lpkt = NULL;
+            lpkt = &g_lora_mac_data.txpkt;
+            g_lora_mac_data.curtx = lpkt;
             om = NULL;
-            memset(&req, 0, sizeof(McpsReq_t));
-            req.Type = MCPS_UNCONFIRMED;
+            memset(lpkt, 0, sizeof(struct lora_pkt_info));
+            lpkt->pkt_type = MCPS_UNCONFIRMED;
             rc = LORAMAC_STATUS_OK;
         } else {
 send_from_txq:
             om = os_mqueue_get(&g_lora_mac_data.lm_txq);
             assert(om != NULL);
             lpkt = LORA_PKT_INFO_PTR(om);
-            req.om = om;
-            req.Type = lpkt->pkt_type;
+            g_lora_mac_data.curtx = lpkt;
             g_lora_node_last_tx_mac_cmd = 0;
         }
 
+        g_lora_mac_data.cur_tx_mbuf = om;
+
         if (rc != LORAMAC_STATUS_OK) {
             /* Check if length error or mac command error */
             if (rc == LORAMAC_STATUS_LENGTH_ERROR) {
@@ -422,16 +338,11 @@ lora_mac_proc_tx_q_event(struct os_event *ev)
         }
 
         /* Form MCPS request */
-        switch (req.Type) {
+        switch (lpkt->pkt_type) {
         case MCPS_UNCONFIRMED:
-            if (lpkt) {
-                req.Req.Unconfirmed.fPort = lpkt->port;
-            }
             evstatus = LORAMAC_EVENT_INFO_STATUS_OK;
             break;
         case MCPS_CONFIRMED:
-            req.Req.Confirmed.fPort = lpkt->port;
-            req.Req.Confirmed.NbTrials = lpkt->txdinfo.retries;
             evstatus = LORAMAC_EVENT_INFO_STATUS_OK;
             break;
         case MCPS_PROPRIETARY:
@@ -445,7 +356,7 @@ lora_mac_proc_tx_q_event(struct os_event *ev)
         }
 
         if (evstatus == LORAMAC_EVENT_INFO_STATUS_OK) {
-            rc = LoRaMacMcpsRequest(&req);
+            rc = LoRaMacMcpsRequest(om, lpkt);
             switch (rc) {
             case LORAMAC_STATUS_OK:
                 /* Transmission started. */
@@ -474,10 +385,8 @@ lora_mac_proc_tx_q_event(struct os_event *ev)
          * continue processing transmit queue.
          */
 proc_txq_om_done:
-        if (lpkt) {
-            lpkt->status = evstatus;
-            lora_app_mcps_confirm(om);
-        }
+        lpkt->status = evstatus;
+        lora_app_mcps_confirm(om);
     }
 }
 
@@ -713,12 +622,9 @@ lora_node_init(void)
                     &g_lora_mac_data.lm_evq, lora_mac_txq_timer_cb, NULL);
 
     /* Initialize the LoRa mac */
-    g_lora_primitives.MacMcpsConfirm = lora_node_mac_mcps_confirm;
-    g_lora_primitives.MacMcpsIndication = lora_node_mac_mcps_indicate;
-    g_lora_primitives.MacMlmeConfirm = lora_node_mac_mlme_confirm;
     lora_cb.GetBatteryLevel = lora_node_get_batt_status;
 
-    lms = LoRaMacInitialization(&g_lora_primitives, &lora_cb);
+    lms = LoRaMacInitialization(&lora_cb);
     assert(lms == LORAMAC_STATUS_OK);
 #endif
 }
diff --git a/net/lora/node/src/mac/LoRaMac.c b/net/lora/node/src/mac/LoRaMac.c
index af623d5ad..69431ad4b 100644
--- a/net/lora/node/src/mac/LoRaMac.c
+++ b/net/lora/node/src/mac/LoRaMac.c
@@ -535,11 +535,6 @@ enum eLoRaMacState
  */
 uint32_t LoRaMacState;
 
-/*!
- * LoRaMac upper layer event functions
- */
-static LoRaMacPrimitives_t *LoRaMacPrimitives;
-
 /*!
  * LoRaMac upper layer callback functions
  */
@@ -599,21 +594,6 @@ static uint8_t JoinRequestTrials;
  */
 static uint8_t MaxJoinRequestTrials;
 
-/*!
- * Structure to hold an MCPS indication data.
- */
-static McpsIndication_t McpsIndication;
-
-/*!
- * Structure to hold MCPS confirm data.
- */
-static McpsConfirm_t McpsConfirm;
-
-/*!
- * Structure to hold MLME confirm data.
- */
-static MlmeConfirm_t MlmeConfirm;
-
 /*!
  * Holds the current rx window slot
  */
@@ -664,15 +644,15 @@ OnRadioRxDone(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr)
     os_eventq_put(lora_node_mac_evq_get(), &g_lora_mac_radio_rx_event);
 
     /*
-      * XXX: for class C devices we may need to handle this differently as
+      * TODO: for class C devices we may need to handle this differently as
       * the device is continuously listening I believe and it may be possible
       * to get a receive done event before the previous one has been handled.
       */
     /* The ISR fills out the payload pointer, size, rssi and snr of rx pdu */
-    McpsIndication.Rssi = rssi;
-    McpsIndication.Snr = snr;
-    McpsIndication.Buffer = payload;
-    McpsIndication.BufferSize = size;
+    g_lora_mac_data.rxpkt.rxdinfo.rssi = rssi;
+    g_lora_mac_data.rxpkt.rxdinfo.snr = snr;
+    g_lora_mac_data.rxbuf = payload;
+    g_lora_mac_data.rxbufsize = size;
 }
 
 /**
@@ -1024,32 +1004,31 @@ lora_mac_send_mcps_confirm(LoRaMacEventInfoStatus_t status)
 {
     /* We are no longer running a tx service */
     LoRaMacState &= ~LORAMAC_TX_RUNNING;
+    /* TODO: deal w/this bit. What exactly does McpsReq mean? Can om be NULL? */
     if (LoRaMacFlags.Bits.McpsReq == 1) {
-        McpsConfirm.Status = status;
-        LoRaMacPrimitives->MacMcpsConfirm( &McpsConfirm );
+        assert(g_lora_mac_data.curtx != NULL);
+        g_lora_mac_data.curtx->status = status;
+        if (g_lora_mac_data.cur_tx_mbuf) {
+            lora_app_mcps_confirm(g_lora_mac_data.cur_tx_mbuf);
+        }
         LoRaMacFlags.Bits.McpsReq = 0;
     }
     lora_node_chk_txq();
 }
 
 /**
- * Called to send MLME confirmations
+ * Called to send join confirmations
  */
 static void
-lora_mac_send_mlme_confirm(LoRaMacEventInfoStatus_t status)
+lora_mac_send_join_confirm(LoRaMacEventInfoStatus_t status, uint8_t attempts)
 {
-    /* We are no longer running a tx service */
-    if (MlmeConfirm.MlmeRequest == MLME_JOIN) {
-        LoRaMacState &= ~LORAMAC_TX_RUNNING;
-    }
-
-    MlmeConfirm.Status = status;
-    LoRaMacPrimitives->MacMlmeConfirm( &MlmeConfirm );
+    LoRaMacState &= ~LORAMAC_TX_RUNNING;
+    lora_app_join_confirm(status, attempts);
     LoRaMacFlags.Bits.MlmeReq = 0;
 }
 
 static void
-lora_mac_confirmed_tx_fail(void)
+lora_mac_confirmed_tx_fail(struct lora_pkt_info *txi)
 {
     STATS_INC(lora_mac_stats, confirmed_tx_fail);
 
@@ -1070,8 +1049,8 @@ lora_mac_confirmed_tx_fail(void)
         } else {
             // The DR is not applicable for the payload size
             NodeAckRequested = false;
-            McpsConfirm.NbRetries = AckTimeoutRetriesCounter;
-            McpsConfirm.Datarate = LoRaMacParams.ChannelsDatarate;
+            txi->txdinfo.retries = AckTimeoutRetriesCounter;
+            txi->txdinfo.datarate = LoRaMacParams.ChannelsDatarate;
             UpLinkCounter++;
             lora_mac_send_mcps_confirm(LORAMAC_EVENT_INFO_STATUS_TX_DR_PAYLOAD_SIZE_ERROR);
         }
@@ -1093,13 +1072,13 @@ lora_mac_confirmed_tx_fail(void)
 #endif
         UpLinkCounter++;
         NodeAckRequested = false;
-        McpsConfirm.NbRetries = AckTimeoutRetriesCounter;
+        txi->txdinfo.retries = AckTimeoutRetriesCounter;
         lora_mac_send_mcps_confirm(LORAMAC_EVENT_INFO_STATUS_TX_RETRIES_EXCEEDED);
     }
 }
 
 static void
-lora_mac_confirmed_tx_success(void)
+lora_mac_confirmed_tx_success(struct lora_pkt_info *txi)
 {
     /* XXX: should this be done on success? */
 #if defined( USE_BAND_433 ) || defined( USE_BAND_780 ) || defined( USE_BAND_868 )
@@ -1121,8 +1100,8 @@ lora_mac_confirmed_tx_success(void)
     STATS_INC(lora_mac_stats, confirmed_tx_good);
     UpLinkCounter++;
     NodeAckRequested = false;
-    McpsConfirm.AckReceived = true;
-    McpsConfirm.NbRetries = AckTimeoutRetriesCounter;
+    txi->txdinfo.ack_rxd = true;
+    txi->txdinfo.retries = AckTimeoutRetriesCounter;
     lora_mac_send_mcps_confirm(LORAMAC_EVENT_INFO_STATUS_OK);
 }
 
@@ -1133,8 +1112,8 @@ lora_mac_join_req_tx_fail(void)
     if (JoinRequestTrials >= MaxJoinRequestTrials) {
         /* Join was a failure */
         STATS_INC(lora_mac_stats, join_failures);
-        MlmeConfirm.NbRetries = JoinRequestTrials;
-        lora_mac_send_mlme_confirm(LORAMAC_EVENT_INFO_STATUS_JOIN_FAIL);
+        lora_mac_send_join_confirm(LORAMAC_EVENT_INFO_STATUS_JOIN_FAIL,
+                                   JoinRequestTrials);
 
         /*
          * The reason we do this if failed to join is to flush the transmit
@@ -1150,13 +1129,13 @@ lora_mac_join_req_tx_fail(void)
 }
 
 static void
-lora_mac_unconfirmed_tx_done(void)
+lora_mac_unconfirmed_tx_done(struct lora_pkt_info *txi)
 {
     STATS_INC(lora_mac_stats, unconfirmed_tx);
 
     /* Unconfirmed frames get repeated N times. */
     if (ChannelsNbRepCounter >= LoRaMacParams.ChannelsNbRep) {
-        McpsConfirm.NbRetries = ChannelsNbRepCounter;
+        txi->txdinfo.retries = ChannelsNbRepCounter;
         ChannelsNbRepCounter = 0;
         AdrAckCounter++;
         UpLinkCounter++;
@@ -1177,6 +1156,8 @@ lora_mac_unconfirmed_tx_done(void)
 static void
 lora_mac_tx_service_done(int rxd_confirmation)
 {
+    struct lora_pkt_info *txi;
+
     /* If no MLME or MCPS request in progress we just return. */
     if ((LoRaMacFlags.Bits.MlmeReq == 0) && (LoRaMacFlags.Bits.McpsReq == 0)) {
         assert((LoRaMacState & LORAMAC_TX_RUNNING) == 0);
@@ -1184,18 +1165,21 @@ lora_mac_tx_service_done(int rxd_confirmation)
         return;
     }
 
-    if (LoRaMacFlags.Bits.MlmeReq && (MlmeConfirm.MlmeRequest == MLME_JOIN)) {
+    if (LoRaMacFlags.Bits.MlmeReq &&
+        (g_lora_mac_data.txpkt.pkt_type == MLME_JOIN)) {
         lora_mac_join_req_tx_fail();
     } else {
         if (LoRaMacFlags.Bits.McpsReq == 1) {
+            txi = g_lora_mac_data.curtx;
+            assert(txi != NULL);
             if (NodeAckRequested) {
                 if (rxd_confirmation) {
-                    lora_mac_confirmed_tx_success();
+                    lora_mac_confirmed_tx_success(txi);
                 } else {
-                    lora_mac_confirmed_tx_fail();
+                    lora_mac_confirmed_tx_fail(txi);
                 }
             } else {
-                lora_mac_unconfirmed_tx_done();
+                lora_mac_unconfirmed_tx_done(txi);
             }
         }
     }
@@ -1253,9 +1237,10 @@ lora_mac_process_radio_tx(struct os_event *ev)
         ChannelsNbRepCounter++;
     }
 
+    /* TODO: move this somewhere else? */
     /* We increment join request transmissions here */
     if ((LoRaMacFlags.Bits.MlmeReq == 1) &&
-        (MlmeConfirm.MlmeRequest == MLME_JOIN)) {
+        (g_lora_mac_data.txpkt.pkt_type == MLME_JOIN)) {
         STATS_INC(lora_mac_stats, join_req_tx);
     }
 }
@@ -1273,6 +1258,7 @@ lora_mac_process_radio_rx(struct os_event *ev)
     LoRaMacHeader_t macHdr;
     LoRaMacFrameCtrl_t fCtrl;
     uint8_t entry_rx_slot;
+    struct lora_pkt_info *rxi;
     bool skipIndication = false;
     bool send_indicate = false;
     int tx_service_over = 0;
@@ -1310,19 +1296,21 @@ lora_mac_process_radio_rx(struct os_event *ev)
     STATS_INC(lora_mac_stats, rx_frames);
 
     /* Payload, size and snr are filled in by radio rx ISR */
-    payload = McpsIndication.Buffer;
-    size = McpsIndication.BufferSize;
-    snr = McpsIndication.Snr;
+    payload = g_lora_mac_data.rxbuf;
+    size = g_lora_mac_data.rxbufsize;
+
+    rxi = &g_lora_mac_data.rxpkt;
+    snr = rxi->rxdinfo.snr;
 
     /* Reset rest of global indication element */
+    rxi->port = 0;
     entry_rx_slot = RxSlot;
-    McpsIndication.RxSlot = entry_rx_slot;
-    McpsIndication.Port = 0;
-    McpsIndication.Multicast = 0;
-    McpsIndication.FramePending = 0;
-    McpsIndication.RxData = false;
-    McpsIndication.AckReceived = false;
-    McpsIndication.DownLinkCounter = 0;
+    rxi->rxdinfo.rxslot = entry_rx_slot;
+    rxi->rxdinfo.multicast = 0;
+    rxi->rxdinfo.frame_pending = 0;
+    rxi->rxdinfo.rxdata = false;
+    rxi->rxdinfo.ack_rxd = false;
+    rxi->rxdinfo.downlink_cntr = 0;
 
     lora_node_log(LORA_NODE_LOG_RX_DONE, Channel, size, entry_rx_slot);
 
@@ -1344,7 +1332,7 @@ lora_mac_process_radio_rx(struct os_event *ev)
              * do. Guess we will just ignore this packet.
              */
             if ((LoRaMacFlags.Bits.MlmeReq == 0) ||
-                (MlmeConfirm.MlmeRequest != MLME_JOIN)) {
+                (g_lora_mac_data.txpkt.pkt_type != MLME_JOIN)) {
                 goto process_rx_done;
             }
 
@@ -1407,8 +1395,8 @@ lora_mac_process_radio_rx(struct os_event *ev)
                 UpLinkCounter = 0;
                 ChannelsNbRepCounter = 0;
                 LoRaMacParams.ChannelsDatarate = LoRaMacParamsDefaults.ChannelsDatarate;
-                MlmeConfirm.NbRetries = JoinRequestTrials;
-                lora_mac_send_mlme_confirm(LORAMAC_EVENT_INFO_STATUS_OK);
+                lora_mac_send_join_confirm(LORAMAC_EVENT_INFO_STATUS_OK,
+                                           JoinRequestTrials);
             }
             break;
         case FRAME_TYPE_DATA_CONFIRMED_DOWN:
@@ -1469,10 +1457,10 @@ lora_mac_process_radio_rx(struct os_event *ev)
             if (micRx == mic) {
                 isMicOk = true;
                 /* XXX: inc mic good stat */
-                McpsIndication.Status = LORAMAC_EVENT_INFO_STATUS_OK;
-                McpsIndication.Multicast = multicast;
-                McpsIndication.FramePending = fCtrl.Bits.FPending;
-                McpsIndication.DownLinkCounter = downLinkCounter;
+                rxi->status = LORAMAC_EVENT_INFO_STATUS_OK;
+                rxi->rxdinfo.multicast = multicast;
+                rxi->rxdinfo.frame_pending = fCtrl.Bits.FPending;
+                rxi->rxdinfo.downlink_cntr = downLinkCounter;
             } else {
                 STATS_INC(lora_mac_stats, rx_mic_failures);
             }
@@ -1489,7 +1477,7 @@ lora_mac_process_radio_rx(struct os_event *ev)
                  * re-transmitted here.
                  */
                 if (isMicOk) {
-                    McpsIndication.Status = LORAMAC_EVENT_INFO_STATUS_DOWNLINK_TOO_MANY_FRAMES_LOSS;
+                    rxi->status = LORAMAC_EVENT_INFO_STATUS_DOWNLINK_TOO_MANY_FRAMES_LOSS;
                     send_indicate = true;
                 }
                 goto process_rx_done;
@@ -1501,7 +1489,7 @@ lora_mac_process_radio_rx(struct os_event *ev)
 
                 // Update 32 bits downlink counter
                 if (multicast == 1) {
-                    McpsIndication.McpsIndication = MCPS_MULTICAST;
+                    rxi->pkt_type = MCPS_MULTICAST;
 
                     if((curMulticastParams->DownLinkCounter == downLinkCounter ) &&
                         (curMulticastParams->DownLinkCounter != 0)) {
@@ -1510,7 +1498,7 @@ lora_mac_process_radio_rx(struct os_event *ev)
                            transmissions? */
 
                         /* XXX: count stat */
-                        McpsIndication.Status = LORAMAC_EVENT_INFO_STATUS_DOWNLINK_REPEATED;
+                        rxi->status = LORAMAC_EVENT_INFO_STATUS_DOWNLINK_REPEATED;
                         send_indicate = true;
                         goto process_rx_done;
                     }
@@ -1518,7 +1506,7 @@ lora_mac_process_radio_rx(struct os_event *ev)
                 } else {
                     if (macHdr.Bits.MType == FRAME_TYPE_DATA_CONFIRMED_DOWN) {
                         SrvAckRequested = true;
-                        McpsIndication.McpsIndication = MCPS_CONFIRMED;
+                        rxi->pkt_type = MCPS_CONFIRMED;
 
                         if ((DownLinkCounter == downLinkCounter) &&
                             (DownLinkCounter != 0) ) {
@@ -1527,13 +1515,13 @@ lora_mac_process_radio_rx(struct os_event *ev)
                         }
                     } else {
                         SrvAckRequested = false;
-                        McpsIndication.McpsIndication = MCPS_UNCONFIRMED;
+                        rxi->pkt_type = MCPS_UNCONFIRMED;
 
                         /* XXX: this should never happen. What should we do?
                            Count stat */
                         if ((DownLinkCounter == downLinkCounter ) &&
                             (DownLinkCounter != 0)) {
-                            McpsIndication.Status = LORAMAC_EVENT_INFO_STATUS_DOWNLINK_REPEATED;
+                            rxi->status = LORAMAC_EVENT_INFO_STATUS_DOWNLINK_REPEATED;
                             send_indicate = true;
                             goto process_rx_done;
                         }
@@ -1545,7 +1533,8 @@ lora_mac_process_radio_rx(struct os_event *ev)
                 // This must be done before parsing the payload and the MAC commands.
                 // We need to reset the MacCommandsBufferIndex here, since we need
                 // to take retransmissions and repititions into account.
-                if (McpsConfirm.McpsRequest == MCPS_CONFIRMED) {
+                if ((g_lora_mac_data.curtx != NULL) &&
+                    (g_lora_mac_data.curtx->pkt_type == MCPS_CONFIRMED)) {
                     if (fCtrl.Bits.Ack == 1) {
                         // Reset MacCommandsBufferIndex when we have received an ACK.
                         MacCommandsBufferIndex = 0;
@@ -1559,7 +1548,7 @@ lora_mac_process_radio_rx(struct os_event *ev)
                     port = payload[appPayloadStartIndex++];
                     frameLen = (size - 4) - appPayloadStartIndex;
 
-                    McpsIndication.Port = port;
+                    rxi->port = port;
 
                     lora_node_log(LORA_NODE_LOG_RX_PORT, port, frameLen, 0);
 
@@ -1598,9 +1587,9 @@ lora_mac_process_radio_rx(struct os_event *ev)
                                                LoRaMacRxPayload );
 
                         if (skipIndication == false ) {
-                            McpsIndication.Buffer = LoRaMacRxPayload;
-                            McpsIndication.BufferSize = frameLen;
-                            McpsIndication.RxData = true;
+                            g_lora_mac_data.rxbuf = LoRaMacRxPayload;
+                            g_lora_mac_data.rxbufsize = frameLen;
+                            rxi->rxdinfo.rxdata = true;
                             send_indicate = true;
                         }
                     }
@@ -1616,7 +1605,7 @@ lora_mac_process_radio_rx(struct os_event *ev)
                     if (skipIndication == false) {
                         // Check if the frame is an acknowledgement
                         if (fCtrl.Bits.Ack == 1) {
-                            McpsIndication.AckReceived = true;
+                            rxi->rxdinfo.ack_rxd = true;
                             hal_timer_stop(&AckTimeoutTimer);
                             hal_timer_stop(&RxWindowTimer2);
                             lora_mac_tx_service_done(1);
@@ -1684,7 +1673,7 @@ lora_mac_process_radio_rx(struct os_event *ev)
 
     /* Send MCPS indication if flag set */
     if (send_indicate) {
-        LoRaMacPrimitives->MacMcpsIndication(&McpsIndication);
+        lora_node_mac_mcps_indicate();
     }
 }
 
@@ -1781,7 +1770,8 @@ lora_mac_process_tx_delay_timeout(struct os_event *ev)
         return;
     }
 
-    if ((LoRaMacFlags.Bits.MlmeReq == 1) && (MlmeConfirm.MlmeRequest == MLME_JOIN)) {
+    if ((LoRaMacFlags.Bits.MlmeReq == 1) &&
+        (g_lora_mac_data.txpkt.pkt_type == MLME_JOIN)) {
         ResetMacParameters( );
 
         // Add a +1, since we start to count from 0
@@ -2187,7 +2177,7 @@ RxWindowSetup( uint32_t freq, int8_t datarate, uint32_t bandwidth, uint16_t time
     Radio.SetChannel( freq );
 
     // Store downlink datarate
-    McpsIndication.RxDatarate = ( uint8_t ) datarate;
+    g_lora_mac_data.rxpkt.rxdinfo.rxdatarate = ( uint8_t ) datarate;
 
 #if defined( USE_BAND_433 ) || defined( USE_BAND_780 ) || defined( USE_BAND_868 )
     if( datarate == DR_7 ) {
@@ -2607,6 +2597,8 @@ static void
 ProcessMacCommands(uint8_t *payload, uint8_t macIndex, uint8_t commandsSize, uint8_t snr)
 {
     uint8_t i;
+    uint8_t demod_margin;
+    uint8_t gateways;
     uint8_t status = 0x07;
     uint16_t chMask;
     int8_t txPower = 0;
@@ -2624,13 +2616,11 @@ ProcessMacCommands(uint8_t *payload, uint8_t macIndex, uint8_t commandsSize, uin
         switch( payload[macIndex++] )
         {
             case SRV_MAC_LINK_CHECK_ANS:
-                MlmeConfirm.DemodMargin = payload[macIndex++];
-                MlmeConfirm.NbGateways = payload[macIndex++];
-                if ((LoRaMacFlags.Bits.MlmeReq == 1) &&
-                    (MlmeConfirm.MlmeRequest == MLME_LINK_CHECK)) {
-                    STATS_INC(lora_mac_stats, link_chk_ans_rxd);
-                    lora_mac_send_mlme_confirm(LORAMAC_EVENT_INFO_STATUS_OK);
-                }
+                demod_margin = payload[macIndex++];
+                gateways = payload[macIndex++];
+                STATS_INC(lora_mac_stats, link_chk_ans_rxd);
+                lora_app_link_chk_confirm(LORAMAC_EVENT_INFO_STATUS_OK,
+                                          gateways, demod_margin);
                 break;
             case SRV_MAC_LINK_ADR_REQ:
                 // Initialize local copy of the channels mask array
@@ -3407,6 +3397,7 @@ PrepareFrame(LoRaMacHeader_t *macHdr, LoRaMacFrameCtrl_t *fCtrl, uint8_t fPort,
 LoRaMacStatus_t
 SendFrameOnChannel( ChannelParams_t channel )
 {
+    struct lora_pkt_info *txi;
     int8_t datarate = Datarates[LoRaMacParams.ChannelsDatarate];
     int8_t txPowerIndex = 0;
     int8_t txPower = 0;
@@ -3415,9 +3406,10 @@ SendFrameOnChannel( ChannelParams_t channel )
     txPower = TxPowers[txPowerIndex];
 
     /* Set MCPS confirm information */
-    McpsConfirm.Datarate = LoRaMacParams.ChannelsDatarate;
-    McpsConfirm.TxPower = txPower;
-    McpsConfirm.UpLinkFrequency = channel.Frequency;
+    txi = g_lora_mac_data.curtx;
+    txi->txdinfo.datarate = LoRaMacParams.ChannelsDatarate;
+    txi->txdinfo.txpower = txPower;
+    txi->txdinfo.uplink_freq = channel.Frequency;
 
     Radio.SetChannel( channel.Frequency );
 
@@ -3462,8 +3454,7 @@ SendFrameOnChannel( ChannelParams_t channel )
 #endif
 
     // Store the time on air
-    McpsConfirm.TxTimeOnAir = TxTimeOnAir;
-    MlmeConfirm.TxTimeOnAir = TxTimeOnAir;
+    txi->txdinfo.tx_time_on_air = TxTimeOnAir;
 
     if (IsLoRaMacNetworkJoined == false) {
         JoinRequestTrials++;
@@ -3493,15 +3484,8 @@ LoRaMacStatus_t SetTxContinuousWave( uint16_t timeout )
 }
 
 LoRaMacStatus_t
-LoRaMacInitialization( LoRaMacPrimitives_t *primitives, LoRaMacCallback_t *callbacks )
+LoRaMacInitialization(LoRaMacCallback_t *callbacks )
 {
-    assert(primitives != NULL);
-
-    assert((primitives->MacMcpsConfirm != NULL) &&
-               (primitives->MacMcpsIndication != NULL)  &&
-               (primitives->MacMlmeConfirm != NULL));
-
-    LoRaMacPrimitives = primitives;
     LoRaMacCallbacks = callbacks;
 
     LoRaMacFlags.Value = 0;
@@ -4301,9 +4285,9 @@ LoRaMacMlmeRequest(MlmeReq_t *mlmeRequest)
         return LORAMAC_STATUS_BUSY;
     }
 
-    memset( ( uint8_t* ) &MlmeConfirm, 0, sizeof( MlmeConfirm ) );
-    MlmeConfirm.Status = LORAMAC_EVENT_INFO_STATUS_ERROR;
-    MlmeConfirm.MlmeRequest = mlmeRequest->Type;
+    g_lora_mac_data.txpkt.port = 0;
+    g_lora_mac_data.txpkt.status = LORAMAC_EVENT_INFO_STATUS_ERROR;
+    g_lora_mac_data.txpkt.pkt_type = mlmeRequest->Type;
 
     switch( mlmeRequest->Type )
     {
@@ -4354,8 +4338,7 @@ LoRaMacMlmeRequest(MlmeReq_t *mlmeRequest)
             status = Send(&macHdr, 0, NULL);
             break;
         case MLME_LINK_CHECK:
-            LoRaMacFlags.Bits.MlmeReq = 1;
-            // LoRaMac will send this command piggy-pack
+            // LoRaMac will send this command piggy-back.
             status = AddMacCommand(MOTE_MAC_LINK_CHECK_REQ, 0, 0);
             if (status == LORAMAC_STATUS_OK) {
                 STATS_INC(lora_mac_stats, link_chk_tx);
@@ -4366,6 +4349,7 @@ LoRaMacMlmeRequest(MlmeReq_t *mlmeRequest)
             status = SetTxContinuousWave( mlmeRequest->Req.TxCw.Timeout );
             break;
         default:
+            status = LORAMAC_STATUS_SERVICE_UNKNOWN;
             break;
     }
 
@@ -4377,13 +4361,12 @@ LoRaMacMlmeRequest(MlmeReq_t *mlmeRequest)
 }
 
 LoRaMacStatus_t
-LoRaMacMcpsRequest(McpsReq_t *mcpsRequest)
+LoRaMacMcpsRequest(struct os_mbuf *om, struct lora_pkt_info *txi)
 {
     LoRaMacStatus_t status = LORAMAC_STATUS_SERVICE_UNKNOWN;
     LoRaMacHeader_t macHdr;
-    uint8_t fPort = 0;
 
-    assert(mcpsRequest != NULL);
+    assert(txi != NULL);
 
     if (((LoRaMacState & LORAMAC_TX_RUNNING) == LORAMAC_TX_RUNNING) ||
         ((LoRaMacState & LORAMAC_TX_DELAYED) == LORAMAC_TX_DELAYED)) {
@@ -4392,30 +4375,20 @@ LoRaMacMcpsRequest(McpsReq_t *mcpsRequest)
 
     macHdr.Value = 0;
 
-    /* Reset confirm parameters */
-    memset(&McpsConfirm, 0, sizeof(McpsConfirm));
-    McpsConfirm.Status = LORAMAC_EVENT_INFO_STATUS_ERROR;
-    McpsConfirm.om = mcpsRequest->om;
-    McpsConfirm.NbRetries = 0;
-    McpsConfirm.AckReceived = false;
-    McpsConfirm.UpLinkCounter = UpLinkCounter;
-    McpsConfirm.McpsRequest = mcpsRequest->Type;
-
-    switch (mcpsRequest->Type) {
+    switch (txi->pkt_type) {
         case MCPS_UNCONFIRMED:
             AckTimeoutRetries = 1;
             macHdr.Bits.MType = FRAME_TYPE_DATA_UNCONFIRMED_UP;
-            fPort = mcpsRequest->Req.Unconfirmed.fPort;
             break;
         case MCPS_CONFIRMED:
             AckTimeoutRetriesCounter = 1;
-            AckTimeoutRetries = mcpsRequest->Req.Confirmed.NbTrials;
+            /* The retries field is seeded with trials, then cleared */
+            AckTimeoutRetries = txi->txdinfo.retries;
             if (AckTimeoutRetries > MAX_ACK_RETRIES) {
                 AckTimeoutRetries = MAX_ACK_RETRIES;
             }
 
             macHdr.Bits.MType = FRAME_TYPE_DATA_CONFIRMED_UP;
-            fPort = mcpsRequest->Req.Confirmed.fPort;
             break;
 
         case MCPS_PROPRIETARY:
@@ -4427,7 +4400,14 @@ LoRaMacMcpsRequest(McpsReq_t *mcpsRequest)
             break;
     }
 
-    status = Send(&macHdr, fPort, mcpsRequest->om);
+    /* Default packet status to error; will get set if ok later */
+    txi->status = LORAMAC_EVENT_INFO_STATUS_ERROR;
+
+    /* Clear out all transmitted information. */
+    memset(&txi->txdinfo, 0, sizeof(struct lora_txd_info));
+    txi->txdinfo.uplink_cntr = UpLinkCounter;
+
+    status = Send(&macHdr, txi->port, om);
     if (status == LORAMAC_STATUS_OK) {
         LoRaMacFlags.Bits.McpsReq = 1;
     } else {


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services