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 2017/11/10 22:08:21 UTC

[GitHub] wes3 closed pull request #656: net/lora: Fix link check command failing

wes3 closed pull request #656: net/lora: Fix link check command failing
URL: https://github.com/apache/mynewt-core/pull/656
 
 
   

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_priv.h b/net/lora/node/include/node/lora_priv.h
index 422ae678b..4dc083b01 100644
--- a/net/lora/node/include/node/lora_priv.h
+++ b/net/lora/node/include/node/lora_priv.h
@@ -40,6 +40,7 @@ struct os_eventq *lora_node_mac_evq_get(void);
 void lora_node_chk_txq(void);
 bool lora_node_txq_empty(void);
 bool lora_mac_srv_ack_requested(void);
+uint8_t lora_mac_cmd_buffer_len(void);
 
 /* Lora debug log */
 #define LORA_NODE_DEBUG_LOG
@@ -60,6 +61,8 @@ void lora_node_log(uint8_t logid, uint8_t p8, uint16_t p16, uint32_t p32);
 #define LORA_NODE_LOG_RX_WIN_SETUP_FAIL (27)
 #define LORA_NODE_LOG_APP_TX            (40)
 #define LORA_NODE_LOG_RX_ADR_REQ        (80)
+#define LORA_NODE_LOG_PROC_MAC_CMD      (85)
+#define LORA_NODE_LOG_LINK_CHK          (90)
 
 #else
 #define lora_node_log(a,b,c,d)
diff --git a/net/lora/node/src/lora_node.c b/net/lora/node/src/lora_node.c
index 0d274018c..564b8ea6d 100644
--- a/net/lora/node/src/lora_node.c
+++ b/net/lora/node/src/lora_node.c
@@ -154,23 +154,6 @@ lora_pkt_alloc(void)
     return p;
 }
 
-#if !MYNEWT_VAL(LORA_NODE_CLI)
-static struct os_mbuf *
-lora_node_alloc_empty_pkt(void)
-{
-    struct os_mbuf *om;
-    struct lora_pkt_info *lpkt;
-
-    om = lora_pkt_alloc();
-    if (om) {
-        lpkt = LORA_PKT_INFO_PTR(om);
-        lpkt->port = 0;
-        lpkt->pkt_type = MCPS_UNCONFIRMED;
-    }
-    return om;
-}
-#endif
-
 /**
  * This is the application to mac layer transmit interface.
  *
@@ -372,14 +355,6 @@ lora_mac_proc_tx_q_event(struct os_event *ev)
     }
 
     /*
-     * WWW: what I need to determine is what happens in the following case:
-     * a Mac command gets added to the buffer but we have nothing on the
-     * transmit queue. What do we do? I do not think we currently
-     * send the response until another frame is enqueued. Need to
-     * look at this. I think I should just send the response back
-     */
-
-    /*
      * Check if possible to send frame. If a MAC command length error we
      * need to send an empty, unconfirmed frame to flush mac commands.
      */
@@ -387,9 +362,16 @@ lora_mac_proc_tx_q_event(struct os_event *ev)
     while (1) {
         mp = STAILQ_FIRST(&g_lora_mac_data.lm_txq.mq_head);
         if (mp == NULL) {
+            /* If an ack has been requested, send one */
             if (lora_mac_srv_ack_requested()) {
                 g_lora_node_last_tx_mac_cmd = 0;
-                goto send_empty_ack;
+                goto send_empty_msg;
+            } else {
+                /* Check for any mac commands */
+                if (lora_mac_cmd_buffer_len() != 0) {
+                    g_lora_node_last_tx_mac_cmd = 1;
+                    goto send_empty_msg;
+                }
             }
             break;
         }
@@ -413,7 +395,7 @@ lora_mac_proc_tx_q_event(struct os_event *ev)
             /* Need to flush MAC commands. Send empty unconfirmed frame */
             STATS_INC(lora_mac_stats, tx_mac_flush);
             /* NOTE: no need to get a mbuf. */
-send_empty_ack:
+send_empty_msg:
             lpkt = NULL;
             om = NULL;
             memset(&req, 0, sizeof(McpsReq_t));
@@ -626,14 +608,21 @@ lora_mac_join_event(struct os_event *ev)
     }
 }
 
+/**
+ * lora mac link chk event
+ *
+ * Called from the Lora MAC task when a link check event has been posted
+ * to it. This event gets posted when link check API gets called.
+ *
+ *
+ * @param ev
+ */
 static void
 lora_mac_link_chk_event(struct os_event *ev)
 {
-    int err;
     MlmeReq_t mlmeReq;
     LoRaMacStatus_t rc;
     LoRaMacEventInfoStatus_t status;
-    struct os_mbuf *om;
 
     mlmeReq.Type = MLME_LINK_CHECK;
     rc = LoRaMacMlmeRequest(&mlmeReq);
@@ -647,6 +636,8 @@ lora_mac_link_chk_event(struct os_event *ev)
         break;
     }
 
+    lora_node_log(LORA_NODE_LOG_LINK_CHK, 0, 0, status);
+
     /* If status is OK */
     if (status != LORAMAC_EVENT_INFO_STATUS_OK) {
         if (lora_link_chk_cb_func) {
@@ -654,17 +645,11 @@ lora_mac_link_chk_event(struct os_event *ev)
         }
     } else {
         /*
-         * If nothing on transmit queue this will sit around until the
-         * application decides to send its next packet. In this case, we
-         * create a dummy frame to send the command.
+         * If nothing on transmit queue, we need to send event so that link
+         * check gets sent.
          */
         if (lora_node_txq_empty()) {
-            om = lora_node_alloc_empty_pkt();
-            if (om) {
-                err = os_mqueue_put(&g_lora_mac_data.lm_txq,
-                                 &g_lora_mac_data.lm_evq, om);
-                assert(err == 0);
-            }
+            lora_node_chk_txq();
         }
     }
 }
diff --git a/net/lora/node/src/mac/LoRaMac.c b/net/lora/node/src/mac/LoRaMac.c
index 16dc7ba07..fc1147094 100644
--- a/net/lora/node/src/mac/LoRaMac.c
+++ b/net/lora/node/src/mac/LoRaMac.c
@@ -2615,6 +2615,8 @@ ProcessMacCommands(uint8_t *payload, uint8_t macIndex, uint8_t commandsSize, uin
     uint16_t channelsMask[6];
     uint32_t freq;
 
+    lora_node_log(LORA_NODE_LOG_PROC_MAC_CMD, macIndex, snr, commandsSize);
+
     while (macIndex < commandsSize) {
         // Decode Frame MAC commands
         switch( payload[macIndex++] )
@@ -3221,7 +3223,6 @@ PrepareFrame(LoRaMacHeader_t *macHdr, LoRaMacFrameCtrl_t *fCtrl, uint8_t fPort,
     uint16_t bufsize;
     uint32_t mic = 0;
     uint8_t port = fPort;
-    uint8_t *payload;
     const uint8_t *key;
     uint8_t maxbytes;
     uint8_t max_cmd_bytes;
@@ -3231,10 +3232,8 @@ PrepareFrame(LoRaMacHeader_t *macHdr, LoRaMacFrameCtrl_t *fCtrl, uint8_t fPort,
 
     /* Get the mac payload size from the mbuf. A NULL mbuf is valid */
     if (om == NULL) {
-        payload = NULL;
         bufsize = 0;
     } else {
-        payload = om->om_data;
         bufsize = OS_MBUF_PKTLEN(om);
         assert(bufsize > 0);
     }
@@ -3316,7 +3315,7 @@ PrepareFrame(LoRaMacHeader_t *macHdr, LoRaMacFrameCtrl_t *fCtrl, uint8_t fPort,
             MacCommandsBufferIndex += MacCommandsBufferToRepeatIndex;
 
             cmd_bytes_txd = 0;
-            if (payload != NULL) {
+            if (om != NULL) {
                 if ((MacCommandsBufferIndex != 0) && (max_cmd_bytes != 0)) {
                     /* fopts cannot exceed 15 bytes */
                     if (max_cmd_bytes > LORA_MAC_COMMAND_MAX_LENGTH) {
@@ -3326,12 +3325,17 @@ PrepareFrame(LoRaMacHeader_t *macHdr, LoRaMacFrameCtrl_t *fCtrl, uint8_t fPort,
                     cmd_bytes_txd = lora_mac_extract_mac_cmds(max_cmd_bytes,
                                                               &LoRaMacBuffer[hdrlen]);
                     if (cmd_bytes_txd) {
-                        // Update FCtrl field with new value of OptionsLength
+                        /* Update FCtrl field with new value of OptionsLength */
                         fCtrl->Bits.FOptsLen += cmd_bytes_txd;
                         LoRaMacBuffer[0x05] = fCtrl->Value;
                         hdrlen += cmd_bytes_txd;
                     }
                 }
+
+                /* Set the port and copy in the application payload */
+                LoRaMacBuffer[hdrlen++] = port;
+                os_mbuf_copydata(om, 0, LoRaMacTxPayloadLen,
+                                 LoRaMacBuffer + hdrlen);
             } else {
                 if (MacCommandsBufferIndex > 0) {
                     port = 0;
@@ -3341,7 +3345,6 @@ PrepareFrame(LoRaMacHeader_t *macHdr, LoRaMacFrameCtrl_t *fCtrl, uint8_t fPort,
 
                     LoRaMacTxPayloadLen = cmd_bytes_txd;
                     assert(cmd_bytes_txd != 0);
-                    payload = MacCommandsBuffer;
                 }
             }
 
@@ -3365,12 +3368,6 @@ PrepareFrame(LoRaMacHeader_t *macHdr, LoRaMacFrameCtrl_t *fCtrl, uint8_t fPort,
             }
 
             if (LoRaMacTxPayloadLen > 0) {
-                /* If application data, set port and copy in payload */
-                if (payload) {
-                    LoRaMacBuffer[hdrlen++] = port;
-                    os_mbuf_copydata(om, 0, LoRaMacTxPayloadLen, LoRaMacBuffer + hdrlen);
-                }
-
                 /* Encrypt the MAC payload using appropriate key */
                 if (port == 0) {
                     key = LoRaMacNwkSKey;
@@ -4482,3 +4479,15 @@ lora_mac_srv_ack_requested(void)
 {
     return SrvAckRequested;
 }
+
+/**
+ * Returns the number of bytes of MAC commands to send.
+ *
+ * @return uint8_t Number of bytes of MAC commands that need to be sent
+ */
+uint8_t
+lora_mac_cmd_buffer_len(void)
+{
+    return MacCommandsBufferIndex + MacCommandsBufferToRepeatIndex;
+}
+


 

----------------------------------------------------------------
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