Browse Source

suspending shellmatta transport optional mode when ymodem is running
this shall prevent the transport layer from processing control characters of ymodem
when the transport layer is active the ymodem data can be passed through the tranport layer stream - switching between transport layer and without is not possible!

stefan 9 tháng trước cách đây
mục cha
commit
5127069c73
4 tập tin đã thay đổi với 45 bổ sung34 xóa
  1. 1 1
      api/shellmatta.h
  2. 24 32
      src/shellmatta.c
  3. 3 1
      src/shellmatta_transport.c
  4. 17 0
      src/shellmatta_ymodem.c

+ 1 - 1
api/shellmatta.h

@@ -316,6 +316,7 @@ typedef struct
     bool                            active;             /**< is transport layer communication active        */
     bool                            disableAutoFlush;   /**< enforce manual flushing                        */
     bool                            mandatory;          /**< is the transport layer enforced                */
+    bool                            suspendOptional;    /**< forces the transport layer to not run optional */
     uint8_t                         sequenceH2S;        /**< sequence counter host to shellmatta            */
     uint8_t                         sequenceS2H;        /**< sequenc counter shellmatta to host             */
     uint32_t                        headerIndex;        /**< read index of the header                       */
@@ -384,7 +385,6 @@ typedef struct
     shellmatta_auth_log_t           logFct;             /**< auth log function                      */
 #endif
 #ifdef SHELLMATTA_TRANSPORT
-    bool                            transportEnabled;   /**< if true the transport layer is enabled */
     uint32_t                        transportBusyMark;  /**< transport processing position during
                                                              busy cmd execution                     */
     shellmatta_transport_layer_t    transportLayer;     /**< transport layer instance               */

+ 24 - 32
src/shellmatta.c

@@ -78,7 +78,7 @@ static shellmatta_retCode_t shellmatta_processDataInt(shellmatta_handle_t     ha
             utils_terminateInput(inst);
         }
     }
-    /** -# poll shellmatta ymomde to send out the request to the sender */
+    /** -# poll shellmatta ymomdem to send out the request to the sender */
     if(SHELLMATTA_YMODEM_WAIT_FOR_START == inst->ymodem.state)
     {
         (void)shellmatta_ymodem_poll(handle);
@@ -501,7 +501,6 @@ shellmatta_retCode_t shellmatta_doInit(
 
 #ifdef SHELLMATTA_TRANSPORT
         /* init transport layer */
-        inst->transportEnabled  = true;
         inst->transportBusyMark = 0u;
         shellmatta_transport_init(&inst->transportLayer, inst->write);
 #endif
@@ -796,51 +795,44 @@ shellmatta_retCode_t shellmatta_processData(shellmatta_handle_t     handle,
         &&  (SHELLMATTA_MAGIC   == inst->magic))
     {
 #ifdef SHELLMATTA_TRANSPORT
-        if (inst->transportEnabled)
+        for (i = inst->transportBusyMark; i < size; i ++)
         {
-            for (i = inst->transportBusyMark; i < size; i ++)
+            ret = shellmatta_transport_process(&inst->transportLayer, data[i], &tmpData, &tmpSize);
+            if (SHELLMATTA_OK == ret)
             {
-                ret = shellmatta_transport_process(&inst->transportLayer, data[i], &tmpData, &tmpSize);
-                if (SHELLMATTA_OK == ret)
-                {
-                    ret = shellmatta_processDataInt(handle, tmpData, tmpSize);
-                    processingDone = true;
+                ret = shellmatta_processDataInt(handle, tmpData, tmpSize);
+                processingDone = true;
 
-                    if (SHELLMATTA_BUSY == ret)
-                    {
-                        inst->transportBusyMark = i;
-                        break;
-                    }
-                    else
-                    {
-                        inst->transportBusyMark = 0u;
-                    }
-                }
-                else if (SHELLMATTA_ERROR == ret)
+                if (SHELLMATTA_BUSY == ret)
                 {
-                    utils_writeEcho(inst, "crc error\r\n", 11);
-                    utils_terminateInput(inst);
+                    inst->transportBusyMark = i;
+                    break;
                 }
                 else
                 {
-                    /* nothing to do - transport layer busy */
+                    inst->transportBusyMark = 0u;
                 }
             }
-
-            /*! -# call the internal processing at least once - for continued and busy commands */
-            if (true != processingDone)
+            else if (SHELLMATTA_ERROR == ret)
             {
-                ret = shellmatta_processDataInt(handle, tmpData, 0);
+                utils_writeEcho(inst, "crc error\r\n", 11);
+                utils_terminateInput(inst);
             }
-
-            if (false == inst->transportLayer.disableAutoFlush)
+            else
             {
-                (void)shellmatta_transport_flush(handle);
+                /* nothing to do - transport layer busy */
             }
         }
-        else
+
+        /*! -# call the internal processing at least once - for continued and busy commands */
+        if (true != processingDone)
+        {
+            ret = shellmatta_processDataInt(handle, tmpData, 0);
+        }
+
+        if (false == inst->transportLayer.disableAutoFlush)
         {
-            ret = shellmatta_processDataInt(handle, data, size);
+            (void)shellmatta_transport_flush(handle);
         }
 #else
         ret = shellmatta_processDataInt(handle, data, size);

+ 3 - 1
src/shellmatta_transport.c

@@ -173,7 +173,9 @@ shellmatta_retCode_t shellmatta_transport_process(shellmatta_transport_layer_t
     /** -# look for start of header */
     case SHELLMATTA_TRANSPORT_STATE_WAIT:
         /** -# if start of header is found, continue transport layer fsm */
-        if (SHELLMATTA_TRANSPORT_START_OF_HEADER == byte)
+        /** -# respect suspendedOptional when there is no active session */
+        if ((SHELLMATTA_TRANSPORT_START_OF_HEADER == byte) &&
+            !((false == transportLayer->active) && (true == transportLayer->suspendOptional)))
         {
             memset(&transportLayer->inPacket, 0, sizeof(transportLayer->inPacket));
             transportLayer->headerIndex = 1u;

+ 17 - 0
src/shellmatta_ymodem.c

@@ -73,6 +73,12 @@ static void shellmatta_ymodem_reset(shellmatta_handle_t handle, bool doCancel)
     inst->ymodem.fileName = NULL;
     inst->ymodem.fileSize = 0u;
     inst->ymodem.pauseRequested = false;
+
+#ifdef SHELLMATTA_TRANSPORT
+    /** .-# reenable transport layer optional mode */
+    inst->transportLayer.suspendOptional = false;
+#endif
+
     (void)memset((void *)&inst->ymodem.packet, 0, sizeof(shellmatta_ymodem_packet_t));
 }
 
@@ -148,6 +154,12 @@ static shellmatta_retCode_t ymodem_stateMachine(shellmatta_handle_t handle, uint
                     /** -# ACK the successful file reception */
                     shellmatta_ymodem_control(handle, YMODEM_ACK);
                     shellmatta_ymodem_control(handle, YMODEM_CRC);
+
+#ifdef SHELLMATTA_TRANSPORT
+                    /** .-# reenable transport layer optional mode */
+                    inst->transportLayer.suspendOptional = false;
+#endif
+
                     inst->ymodem.state = SHELLMATTA_YMODEM_INACTIVE;
                     (void)utils_terminateInput(inst);
                     break;
@@ -336,6 +348,11 @@ shellmatta_retCode_t shellmatta_ymodem_init(shellmatta_handle_t             hand
 
         inst->ymodem.state = SHELLMATTA_YMODEM_WAIT_FOR_START;
 
+#ifdef SHELLMATTA_TRANSPORT
+        /** -# suspend the transport layer being optional while ymodem is running */
+        inst->transportLayer.suspendOptional = true;
+#endif
+
         /** -# send initial ymodem symbol to start transmission */
         shellmatta_ymodem_control(handle, YMODEM_CRC);
     }