]> rtime.felk.cvut.cz Git - arc.git/commitdiff
Fixed CanTP bug when consecutive frame where received with not validation that we...
authorUlrikHagstrom <ulrik.hagstrom@movimento.se>
Thu, 29 Apr 2010 11:37:00 +0000 (13:37 +0200)
committerUlrikHagstrom <ulrik.hagstrom@movimento.se>
Thu, 29 Apr 2010 11:37:00 +0000 (13:37 +0200)
communication/CanTp/CanTp.c
diagnostic/Dcm/Dcm_Dsl.c

index 5c6eb8a58c7ada984d3579dd4658deb9497a17bb..36e494252b2d7745d604668dd450aedb6f72fec2 100644 (file)
@@ -590,81 +590,83 @@ static INLINE void handleConsecutiveFrame(const CanTp_RxNSduType *rxConfig,
        PduLengthType bytesCopiedToPdurRxBuffer = 0;\r
        BufReq_ReturnType ret = BUFREQ_NOT_OK;\r
 \r
-       if (rxConfig->CanTpAddressingFormant == CANTP_EXTENDED) {\r
-               extendedAddress = rxPduData->SduDataPtr[indexCount++];\r
-               // TODO: Should we validate the extended address ?\r
-       }\r
-       segmentNumber = rxPduData->SduDataPtr[indexCount++] & SEGMENT_NUMBER_MASK;\r
-       if (segmentNumber != (rxRuntime->iso15765.framesHandledCount\r
-                       & SEGMENT_NUMBER_MASK)) {\r
-               DEBUG(DEBUG_MEDIUM,"Segmentation number error detected - is the sending"\r
-                               "unit too fast? Increase STmin (cofig) to slow it down!\n");\r
-               PduR_CanTpRxIndication(rxConfig->PduR_PduId, NTFRSLT_E_WRONG_SN); /** @req CANTP084 */\r
-               rxRuntime->iso15765.state = IDLE;\r
-               rxRuntime->mode = CANTP_RX_WAIT;\r
-       } else {\r
-               currentSegmentMaxSize = CANIF_PDU_MAX_LENGTH - indexCount;\r
-               bytesLeftToCopy = rxRuntime->transferTotal\r
-                               - rxRuntime->transferCount;\r
-               if (bytesLeftToCopy < currentSegmentMaxSize) {\r
-                       currentSegmentSize = bytesLeftToCopy; // 1-5.\r
-               } else {\r
-                       currentSegmentSize = currentSegmentMaxSize; // 6 or 7, depends on addressing format used.\r
+\r
+       if (rxRuntime->iso15765.state == RX_WAIT_CONSECUTIVE_FRAME) {\r
+               if (rxConfig->CanTpAddressingFormant == CANTP_EXTENDED) {\r
+                       extendedAddress = rxPduData->SduDataPtr[indexCount++];\r
                }\r
-               // Copy received data to buffer provided by SDUR.\r
-               ret = copySegmentToPduRRxBuffer(rxConfig, rxRuntime,\r
-                               &rxPduData->SduDataPtr[indexCount],\r
-                               currentSegmentSize,\r
-                               &bytesCopiedToPdurRxBuffer);\r
-               if (ret == BUFREQ_NOT_OK) {\r
-                       PduR_CanTpRxIndication(rxConfig->PduR_PduId, NTFRSLT_E_NO_BUFFER); /** @req CANTP084 */\r
+               segmentNumber = rxPduData->SduDataPtr[indexCount++] & SEGMENT_NUMBER_MASK;\r
+               if (segmentNumber != (rxRuntime->iso15765.framesHandledCount\r
+                               & SEGMENT_NUMBER_MASK)) {\r
+                       DEBUG(DEBUG_MEDIUM,"Segmentation number error detected - is the sending"\r
+                                       "unit too fast? Increase STmin (cofig) to slow it down!\n");\r
+                       PduR_CanTpRxIndication(rxConfig->PduR_PduId, NTFRSLT_E_WRONG_SN); /** @req CANTP084 */\r
                        rxRuntime->iso15765.state = IDLE;\r
                        rxRuntime->mode = CANTP_RX_WAIT;\r
-               } else if (ret == BUFREQ_BUSY) {\r
-                       boolean dataCopyFailure = FALSE;\r
-                       PduLengthType bytesNotCopiedToPdurRxBuffer =\r
-                                       currentSegmentSize - bytesCopiedToPdurRxBuffer;\r
-                       if (rxConfig->CanTpAddressingFormant == CANTP_STANDARD) {\r
-                               if ( copySegmentToLocalRxBuffer(rxRuntime,      /** @req CANTP067 */\r
-                                               &rxPduData->SduDataPtr[1 + bytesCopiedToPdurRxBuffer],\r
-                                               bytesNotCopiedToPdurRxBuffer ) != TRUE ) {\r
-                                       rxRuntime->iso15765.state = IDLE;\r
-                                       rxRuntime->mode = CANTP_RX_WAIT;\r
-                                       dataCopyFailure = TRUE;\r
-                                       DEBUG( DEBUG_MEDIUM, "Unexpected error, could not copy 'unaligned leftover' "\r
-                                                       "data to local buffer!\n");\r
-                               }\r
+               } else {\r
+                       currentSegmentMaxSize = CANIF_PDU_MAX_LENGTH - indexCount;\r
+                       bytesLeftToCopy = rxRuntime->transferTotal\r
+                                       - rxRuntime->transferCount;\r
+                       if (bytesLeftToCopy < currentSegmentMaxSize) {\r
+                               currentSegmentSize = bytesLeftToCopy; // 1-5.\r
                        } else {\r
-                               if ( copySegmentToLocalRxBuffer(rxRuntime,  /** @req CANTP067 */\r
-                                               &rxPduData->SduDataPtr[2 + bytesCopiedToPdurRxBuffer],\r
-                                               bytesNotCopiedToPdurRxBuffer) != TRUE ) {\r
-                                       rxRuntime->iso15765.state = IDLE;\r
-                                       rxRuntime->mode = CANTP_RX_WAIT;\r
-                                       dataCopyFailure = TRUE;\r
-                                       DEBUG( DEBUG_MEDIUM, "Unexpected error, could not copy 'unaligned leftover' "\r
-                                                       "data to local buffer!\n");\r
-                               }\r
-                       }\r
-                       if ( dataCopyFailure == FALSE ) {\r
-                               rxRuntime->iso15765.framesHandledCount++;\r
-                               rxRuntime->iso15765.stateTimeoutCount = CANTP_CONVERT_MS_TO_MAIN_CYCLES(rxConfig->CanTpNbr);\r
-                               rxRuntime->iso15765.state = RX_WAIT_SDU_BUFFER;\r
-                               rxRuntime->mode = CANTP_RX_PROCESSING;\r
-                               sendFlowControlFrame(rxConfig, rxRuntime, ret);  /** @req CANTP082 */\r
+                               currentSegmentSize = currentSegmentMaxSize; // 6 or 7, depends on addressing format used.\r
                        }\r
-               } else if (ret == BUFREQ_OK) {\r
-                       bytesLeftToTransfer = rxRuntime->transferTotal - rxRuntime->transferCount;\r
-                       if (bytesLeftToTransfer > 0) {\r
-                               rxRuntime->iso15765.framesHandledCount++;\r
-                               COUNT_DECREMENT(rxRuntime->iso15765.nextFlowControlCount);\r
-                               if (rxRuntime->iso15765.nextFlowControlCount == 0) {\r
-                                       sendFlowControlFrame(rxConfig, rxRuntime, BUFREQ_OK);\r
-                               }\r
-                       } else {\r
-                               DEBUG( DEBUG_MEDIUM,"ISO15765-Rx session finished, going back to IDLE!\n");\r
+                       // Copy received data to buffer provided by SDUR.\r
+                       ret = copySegmentToPduRRxBuffer(rxConfig, rxRuntime,\r
+                                       &rxPduData->SduDataPtr[indexCount],\r
+                                       currentSegmentSize,\r
+                                       &bytesCopiedToPdurRxBuffer);\r
+                       if (ret == BUFREQ_NOT_OK) {\r
+                               PduR_CanTpRxIndication(rxConfig->PduR_PduId, NTFRSLT_E_NO_BUFFER); /** @req CANTP084 */\r
                                rxRuntime->iso15765.state = IDLE;\r
                                rxRuntime->mode = CANTP_RX_WAIT;\r
-                               PduR_CanTpRxIndication(rxConfig->PduR_PduId, NTFRSLT_OK); /** @req CANTP084 */\r
+                       } else if (ret == BUFREQ_BUSY) {\r
+                               boolean dataCopyFailure = FALSE;\r
+                               PduLengthType bytesNotCopiedToPdurRxBuffer =\r
+                                               currentSegmentSize - bytesCopiedToPdurRxBuffer;\r
+                               if (rxConfig->CanTpAddressingFormant == CANTP_STANDARD) {\r
+                                       if ( copySegmentToLocalRxBuffer(rxRuntime,      /** @req CANTP067 */\r
+                                                       &rxPduData->SduDataPtr[1 + bytesCopiedToPdurRxBuffer],\r
+                                                       bytesNotCopiedToPdurRxBuffer ) != TRUE ) {\r
+                                               rxRuntime->iso15765.state = IDLE;\r
+                                               rxRuntime->mode = CANTP_RX_WAIT;\r
+                                               dataCopyFailure = TRUE;\r
+                                               DEBUG( DEBUG_MEDIUM, "Unexpected error, could not copy 'unaligned leftover' "\r
+                                                               "data to local buffer!\n");\r
+                                       }\r
+                               } else {\r
+                                       if ( copySegmentToLocalRxBuffer(rxRuntime,  /** @req CANTP067 */\r
+                                                       &rxPduData->SduDataPtr[2 + bytesCopiedToPdurRxBuffer],\r
+                                                       bytesNotCopiedToPdurRxBuffer) != TRUE ) {\r
+                                               rxRuntime->iso15765.state = IDLE;\r
+                                               rxRuntime->mode = CANTP_RX_WAIT;\r
+                                               dataCopyFailure = TRUE;\r
+                                               DEBUG( DEBUG_MEDIUM, "Unexpected error, could not copy 'unaligned leftover' "\r
+                                                               "data to local buffer!\n");\r
+                                       }\r
+                               }\r
+                               if ( dataCopyFailure == FALSE ) {\r
+                                       rxRuntime->iso15765.framesHandledCount++;\r
+                                       rxRuntime->iso15765.stateTimeoutCount = CANTP_CONVERT_MS_TO_MAIN_CYCLES(rxConfig->CanTpNbr);\r
+                                       rxRuntime->iso15765.state = RX_WAIT_SDU_BUFFER;\r
+                                       rxRuntime->mode = CANTP_RX_PROCESSING;\r
+                                       sendFlowControlFrame(rxConfig, rxRuntime, ret);  /** @req CANTP082 */\r
+                               }\r
+                       } else if (ret == BUFREQ_OK) {\r
+                               bytesLeftToTransfer = rxRuntime->transferTotal - rxRuntime->transferCount;\r
+                               if (bytesLeftToTransfer > 0) {\r
+                                       rxRuntime->iso15765.framesHandledCount++;\r
+                                       COUNT_DECREMENT(rxRuntime->iso15765.nextFlowControlCount);\r
+                                       if (rxRuntime->iso15765.nextFlowControlCount == 0) {\r
+                                               sendFlowControlFrame(rxConfig, rxRuntime, BUFREQ_OK);\r
+                                       }\r
+                               } else {\r
+                                       DEBUG( DEBUG_MEDIUM,"ISO15765-Rx session finished, going back to IDLE!\n");\r
+                                       rxRuntime->iso15765.state = IDLE;\r
+                                       rxRuntime->mode = CANTP_RX_WAIT;\r
+                                       PduR_CanTpRxIndication(rxConfig->PduR_PduId, NTFRSLT_OK); /** @req CANTP084 */\r
+                               }\r
                        }\r
                }\r
        }\r
@@ -785,34 +787,39 @@ static INLINE void handleFlowControlFrame(const CanTp_TxNSduType *txConfig,
        uint8 extendedAddress = 0;\r
        Std_ReturnType ret;\r
 \r
-       if (txConfig->CanTpAddressingMode == CANTP_EXTENDED) { /** @req CANTP094 *//** @req CANTP095 */\r
-               extendedAddress = txPduData->SduDataPtr[indexCount++];\r
-       }\r
-       switch (txPduData->SduDataPtr[indexCount++] & ISO15765_TPCI_FS_MASK) {\r
-       case ISO15765_FLOW_CONTROL_STATUS_CTS:\r
-               txRuntime->iso15765.BS = txPduData->SduDataPtr[indexCount++];\r
-               txRuntime->iso15765.nextFlowControlCount = txRuntime->iso15765.BS;\r
-               txRuntime->iso15765.STmin = txPduData->SduDataPtr[indexCount++];\r
-               DEBUG( DEBUG_MEDIUM, "txRuntime->iso15765.STmin = %d\n", txRuntime->iso15765.STmin);\r
-               ret = sendConsecutiveFrame(txConfig, txRuntime);\r
-               if (ret == E_OK) {\r
-                       handleConsecutiveFrameSent(txConfig, txRuntime);\r
-               } else {\r
-                       PduR_CanTpRxIndication(txConfig->PduR_PduId, NTFRSLT_E_NOT_OK);  /** @req CANTP177 */ /** @req CANTP084 */\r
+\r
+       if ( txRuntime->iso15765.state == TX_WAIT_FLOW_CONTROL ) {\r
+               if (txConfig->CanTpAddressingMode == CANTP_EXTENDED) { /** @req CANTP094 *//** @req CANTP095 */\r
+                       extendedAddress = txPduData->SduDataPtr[indexCount++];\r
+               }\r
+               switch (txPduData->SduDataPtr[indexCount++] & ISO15765_TPCI_FS_MASK) {\r
+               case ISO15765_FLOW_CONTROL_STATUS_CTS:\r
+                       txRuntime->iso15765.BS = txPduData->SduDataPtr[indexCount++];\r
+                       txRuntime->iso15765.nextFlowControlCount = txRuntime->iso15765.BS;\r
+                       txRuntime->iso15765.STmin = txPduData->SduDataPtr[indexCount++];\r
+                       DEBUG( DEBUG_MEDIUM, "txRuntime->iso15765.STmin = %d\n", txRuntime->iso15765.STmin);\r
+                       ret = sendConsecutiveFrame(txConfig, txRuntime);\r
+                       if (ret == E_OK) {\r
+                               handleConsecutiveFrameSent(txConfig, txRuntime);\r
+                       } else {\r
+                               PduR_CanTpRxIndication(txConfig->PduR_PduId, NTFRSLT_E_NOT_OK);  /** @req CANTP177 */ /** @req CANTP084 */\r
+                               txRuntime->iso15765.state = IDLE;\r
+                               txRuntime->mode = CANTP_TX_WAIT;\r
+                       }\r
+                       break;\r
+               case ISO15765_FLOW_CONTROL_STATUS_WAIT:\r
+                       txRuntime->iso15765.stateTimeoutCount =\r
+                                       CANTP_CONVERT_MS_TO_MAIN_CYCLES(txConfig->CanTpNbs);  /*CanTp: 264*/\r
+                       txRuntime->iso15765.state = TX_WAIT_FLOW_CONTROL;\r
+                       break;\r
+               case ISO15765_FLOW_CONTROL_STATUS_OVFLW:\r
+                       PduR_CanTpRxIndication(txConfig->PduR_PduId, NTFRSLT_E_NOT_OK);\r
                        txRuntime->iso15765.state = IDLE;\r
                        txRuntime->mode = CANTP_TX_WAIT;\r
+                       break;\r
                }\r
-               break;\r
-       case ISO15765_FLOW_CONTROL_STATUS_WAIT:\r
-               txRuntime->iso15765.stateTimeoutCount =\r
-                               CANTP_CONVERT_MS_TO_MAIN_CYCLES(txConfig->CanTpNbs);  /*CanTp: 264*/\r
-               txRuntime->iso15765.state = TX_WAIT_FLOW_CONTROL;\r
-               break;\r
-       case ISO15765_FLOW_CONTROL_STATUS_OVFLW:\r
-               PduR_CanTpRxIndication(txConfig->PduR_PduId, NTFRSLT_E_NOT_OK);\r
-               txRuntime->iso15765.state = IDLE;\r
-               txRuntime->mode = CANTP_TX_WAIT;\r
-               break;\r
+       } else {\r
+               DEBUG( DEBUG_MEDIUM, "Ignoring flow control, we do not expect it!");\r
        }\r
 }\r
 \r
@@ -1085,7 +1092,7 @@ static INLINE BufReq_ReturnType canTpTransmitHelper(const CanTp_TxNSduType *txCo
                                if ( txRuntime->iso15765.stateTimeoutCount == 0 ) {\r
                                        DEBUG( DEBUG_MEDIUM, "WARNING! Too low CanTpNbs timeout!\n" );\r
                                }\r
-                               txRuntime->iso15765.state = TX_WAIT_FLOW_CONTROL;\r
+                               txRuntime->iso15765.state = TX_WAIT_FLOW_CONTROL; // We will always expect a flow control at this stage.\r
                                res = sendFirstFrame(txConfig, txRuntime); /** @req CANTP231 */\r
                                if (res == E_OK) {\r
                                        txRuntime->mode = CANTP_TX_PROCESSING;\r
@@ -1137,7 +1144,7 @@ Std_ReturnType CanTp_Transmit(PduIdType CanTpTxSduId,
        txConfig = (CanTp_TxNSduType*)&CanTpConfig.CanTpNSduList[CanTpTxSduId].configData;\r
 \r
        txRuntime = &CanTpRunTimeData.runtimeDataList[txConfig->CanTpTxChannel]; // Runtime data.\r
-       if (txRuntime->mode != CANTP_TX_PROCESSING) {\r
+       if (txRuntime->iso15765.state == IDLE) {\r
                txRuntime->pdurBufferCount = 0;\r
                txRuntime->pdurBufferCount = 0;\r
                txRuntime->transferCount = 0;\r
@@ -1163,6 +1170,7 @@ Std_ReturnType CanTp_Transmit(PduIdType CanTpTxSduId,
                        break;\r
                }\r
        } else {\r
+               DEBUG( DEBUG_MEDIUM, "CanTp can't transmit, it is already occupied!\n", CanTpTxSduId);\r
                ret = E_NOT_OK;  /** @req CANTP123 *//** @req CANTP206 */\r
        }\r
        return ret; // CAN level error code.\r
@@ -1271,7 +1279,7 @@ void CanTp_RxIndication_Main(PduIdType CanTpRxPduId,
                        handleSingleFrame(rxConfigParams, runtimeParams, CanTpRxPduPtr);\r
                }\r
                else\r
-                       DEBUG( DEBUG_MEDIUM, "Single frame received on ISO15765-Tx flow control - is ignored!\n");\r
+                       DEBUG( DEBUG_MEDIUM, "Single frame received on ISO15765-Tx - is ignored!\n");\r
                break;\r
        }\r
        case FIRST_FRAME: {\r
@@ -1279,7 +1287,7 @@ void CanTp_RxIndication_Main(PduIdType CanTpRxPduId,
                        DEBUG( DEBUG_MEDIUM, "calling handleFirstFrame!\n");\r
                        handleFirstFrame(rxConfigParams, runtimeParams, CanTpRxPduPtr);\r
                } else\r
-                       DEBUG( DEBUG_MEDIUM, "First frame received on ISO15765-Tx flow control - is ignored!\n");\r
+                       DEBUG( DEBUG_MEDIUM, "First frame received on ISO15765-Tx - is ignored!\n");\r
                break;\r
        }\r
        case CONSECUTIVE_FRAME: {\r
@@ -1287,7 +1295,7 @@ void CanTp_RxIndication_Main(PduIdType CanTpRxPduId,
                        DEBUG( DEBUG_MEDIUM, "calling handleConsecutiveFrame!\n");\r
                        handleConsecutiveFrame(rxConfigParams, runtimeParams, CanTpRxPduPtr);\r
                } else\r
-                       DEBUG( DEBUG_MEDIUM, "Consecutive frame received on ISO15765-Tx flow control - is ignored!\n");\r
+                       DEBUG( DEBUG_MEDIUM, "Consecutive frame received on ISO15765-Tx - is ignored!\n");\r
                break;\r
        }\r
        case FLOW_CONTROL_CTS_FRAME: {\r
@@ -1295,11 +1303,11 @@ void CanTp_RxIndication_Main(PduIdType CanTpRxPduId,
                        DEBUG( DEBUG_MEDIUM, "calling handleFlowControlFrame!\n");\r
                        handleFlowControlFrame(txConfigParams, runtimeParams, CanTpRxPduPtr);\r
                } else\r
-                       DEBUG( DEBUG_MEDIUM, "Flow control frame received on ISO15765-RX flow control - is ignored!\n");\r
+                       DEBUG( DEBUG_MEDIUM, "Flow control frame received on ISO15765-Rx - is ignored!\n");\r
                break;\r
        }\r
        case INVALID_FRAME: {\r
-               DEBUG( DEBUG_MEDIUM, "INVALID_FRAME recived, doing nothing!!\n");\r
+               DEBUG( DEBUG_MEDIUM, "INVALID_FRAME received - is ignored!\n!\n");\r
                break;\r
        }\r
        default:\r
@@ -1433,10 +1441,10 @@ void CanTp_MainFunction() /** @req CANTP213 */
                                                handleConsecutiveFrameSent(txConfigListItem, txRuntimeListItem);\r
                                        } else {\r
                                                DEBUG( DEBUG_MEDIUM, "ERROR: Consecutive frame could not be sent!\n");\r
-                                               PduR_CanTpTxConfirmation(txConfigListItem->PduR_PduId,\r
-                                                                NTFRSLT_E_NOT_OK); /** @req CANTP204 */\r
                                                txRuntimeListItem->iso15765.state = IDLE;\r
                                                txRuntimeListItem->mode = CANTP_TX_WAIT;\r
+                                               PduR_CanTpTxConfirmation(txConfigListItem->PduR_PduId,\r
+                                                                NTFRSLT_E_NOT_OK); /** @req CANTP204 */\r
                                        }\r
                                } else {\r
                                        DEBUG( DEBUG_MEDIUM, "Waiting for STmin timer to expire!\n");\r
@@ -1447,9 +1455,10 @@ void CanTp_MainFunction() /** @req CANTP213 */
                                //DEBUG( DEBUG_MEDIUM, "Waiting for flow control!\n");\r
                                if (txRuntimeListItem->iso15765.stateTimeoutCount == 0) {\r
                                        DEBUG( DEBUG_MEDIUM, "State TX_WAIT_FLOW_CONTROL timed out!\n");\r
+                                       txRuntimeListItem->iso15765.state = IDLE;\r
+                                       txRuntimeListItem->mode = CANTP_TX_WAIT;\r
                                        PduR_CanTpTxConfirmation(txConfigListItem->PduR_PduId,\r
                                                        NTFRSLT_E_NOT_OK); /** @req CANTP204 */ /** @req CANTP185 */\r
-                                       txRuntimeListItem->iso15765.state = IDLE;\r
                                }\r
                                break;\r
                        default:\r
@@ -1478,7 +1487,7 @@ void CanTp_MainFunction() /** @req CANTP213 */
                                 * to send a flow-control clear to send (CTS).\r
                                 */\r
                                if (rxRuntimeListItem->iso15765.stateTimeoutCount == 0) { /** @req CANTP223 */\r
-                                       PduR_CanTpTxConfirmation(rxConfigListItem->PduR_PduId,\r
+                                       PduR_CanTpRxIndication(rxConfigListItem->PduR_PduId,\r
                                                        NTFRSLT_E_NOT_OK); /** @req CANTP204 */\r
                                        rxRuntimeListItem->iso15765.state = IDLE;\r
                                        rxRuntimeListItem->mode = CANTP_RX_WAIT;\r
@@ -1505,7 +1514,7 @@ void CanTp_MainFunction() /** @req CANTP213 */
                                        } else if (ret == BUFREQ_NOT_OK ) {\r
                                                rxRuntimeListItem->iso15765.state = IDLE;\r
                                                rxRuntimeListItem->mode = CANTP_RX_WAIT;\r
-                                               PduR_CanTpTxConfirmation(rxConfigListItem->PduR_PduId,\r
+                                               PduR_CanTpRxIndication(rxConfigListItem->PduR_PduId,\r
                                                                NTFRSLT_E_NOT_OK); /** @req CANTP205 */\r
                                        } else if ( ret == BUFREQ_BUSY ) {\r
                                                DEBUG( DEBUG_MEDIUM, "Still busy!\n");\r
index 291ac820fdef3b0fa290828d9a0ed2df3960d281..08de80a7a096a04764ffe256a1159feab7569bf0 100644 (file)
@@ -22,7 +22,7 @@
 #include "ComM_Dcm.h"\r
 #include "PduR_Dcm.h"\r
 #include "ComStack_Types.h"\r
-//#define USE_DEBUG_PRINTF\r
+#define USE_DEBUG_PRINTF\r
 #include "debug.h"\r
 \r
 #define DECREMENT(timer) { if (timer > 0) timer--; }\r
@@ -43,14 +43,17 @@ typedef struct {
 \r
 typedef struct {\r
        boolean initRun;\r
+       //boolean diagnosticRequestPending; // This is a "semaphore" because DSD and DCM can handle multiple/parallel request at the moment.\r
        const Dcm_DslProtocolRowType *preemptedProtocol; // Points to the currently active protocol.\r
        const Dcm_DslProtocolRowType *activeProtocol; // Points to the currently active protocol.\r
        Dcm_DslRunTimeProtocolParametersType\r
                        protocolList[MAX_PARALLEL_PROTOCOLS_ALLOWED];\r
 } DcmDsl_RunTimeDataType;\r
 \r
-DcmDsl_RunTimeDataType DcmDslRunTimeData = { .initRun = FALSE,\r
-               .preemptedProtocol = NULL, .activeProtocol = NULL };\r
+DcmDsl_RunTimeDataType DcmDslRunTimeData = {\r
+               .initRun = FALSE,\r
+               .preemptedProtocol = NULL,\r
+               .activeProtocol = NULL };\r
 \r
 // ################# DUMMIES START #################\r
 \r
@@ -322,6 +325,7 @@ void DslDsdProcessingDone(PduIdType rxPduIdRef,
                        runtime->externalTxBufferStatus = DSD_PENDING_RESPONSE_SIGNALED; /** @req DCM114 **/\r
                        break;\r
                case DSD_TX_RESPONSE_SUPPRESSED:\r
+                       DEBUG( DEBUG_MEDIUM, "DslDsdProcessingDone called with DSD_TX_RESPONSE_SUPPRESSED.\n");\r
                        releaseExternalRxTxBuffersHelper(rxPduIdRef);\r
                        break;\r
                default:\r
@@ -418,6 +422,7 @@ void DslInit(void) { /** @req DCM037 - for DSL submodule. **/
                                = BUFFER_AVAILABLE;\r
                listEntry++;\r
        };\r
+       //DcmDslRunTimeData.diagnosticRequestPending = FALSE;\r
        DcmDslRunTimeData.initRun = TRUE;\r
 }\r
 \r
@@ -538,8 +543,7 @@ BufReq_ReturnType DslProvideRxBufferToPdur(PduIdType dcmRxPduId, /** @req DCM094
                                protocolRow->DslProtocolRxBufferID;\r
                if (externalRxBuffer->pduInfo.SduLength >= tpSduLength) { /** @req DCM443 **/\r
                        if ((runtime->externalRxBufferStatus == NOT_IN_USE)\r
-                                       && (externalRxBuffer->externalBufferRuntimeData->status\r
-                                                       == BUFFER_AVAILABLE)) {\r
+                               && (externalRxBuffer->externalBufferRuntimeData->status == BUFFER_AVAILABLE)) {\r
                                DEBUG( DEBUG_MEDIUM, "External buffer available!\n");\r
                                // ### EXTERNAL BUFFER IS AVAILABLE; GRAB IT AND REMEBER THAT WE OWN IT! ###\r
                                externalRxBuffer->externalBufferRuntimeData->status\r
@@ -547,7 +551,6 @@ BufReq_ReturnType DslProvideRxBufferToPdur(PduIdType dcmRxPduId, /** @req DCM094
                                runtime->diagnosticRequestFromTester.SduDataPtr\r
                                                = externalRxBuffer->pduInfo.SduDataPtr;\r
                                runtime->diagnosticRequestFromTester.SduLength = tpSduLength;\r
-                               //*pduInfoPtr = &(externalRxBuffer->pduInfo);\r
                                *pduInfoPtr = &(runtime->diagnosticRequestFromTester);\r
                                runtime->externalRxBufferStatus = PROVIDED_TO_PDUR; /** @req DCM342 **/\r
                                ret = BUFREQ_OK;\r
@@ -564,6 +567,8 @@ BufReq_ReturnType DslProvideRxBufferToPdur(PduIdType dcmRxPduId, /** @req DCM094
                                                                        = tpSduLength;\r
                                                        *pduInfoPtr = &(runtime->localRxBuffer.PduInfo);\r
                                                        ret = BUFREQ_OK;\r
+                                               } else {\r
+                                                       ret = BUFREQ_BUSY;\r
                                                }\r
                                        }\r
                                } else {\r
@@ -631,13 +636,16 @@ void DslRxIndicationFromPduR(PduIdType dcmRxPduId, NotifResultType result) {  /*
                                                        ComM_DCM_ActivateDiagnostic(); /* @DCM163 */\r
                                                        runtime->diagnosticActiveComM = TRUE;\r
                                                }\r
+                                               timeParams = protocolRow->DslProtocolTimeLimit;\r
                                                runtime->stateTimeoutCount = DCM_CONVERT_MS_TO_MAIN_CYCLES(\r
                                                                timeParams->TimStrP2ServerMax); /* See 9.2.2. */\r
                                                runtime->externalRxBufferStatus = PROVIDED_TO_DSD; /** @req DCM241 **/\r
+                                               if (runtime->externalTxBufferStatus == NOT_IN_USE) {\r
+                                                       DEBUG( DEBUG_MEDIUM, "External Tx buffer available, we can pass it to DSD.\n");\r
+                                               } else {\r
+                                                       DEBUG( DEBUG_MEDIUM, "External buffer not available, a response is being transmitted?\n");\r
+                                               }\r
                                                runtime->externalTxBufferStatus = PROVIDED_TO_DSD; /** @req DCM241 **/\r
-                                               timeParams = protocolRow->DslProtocolTimeLimit;\r
-                                               //runtime->stateTimeoutCount = DCM_CONVERT_MS_TO_MAIN_CYCLES(\r
-                                               //              timeParams->TimStrP2ServerMax); /* Reinitiate timer, see 9.2.2. */\r
                                                runtime->responsePendingCount = DCM_Config.Dsl->DslDiagResp->DslDiagRespMaxNumRespPend;\r
                                                runtime->diagnosticResponseFromDsd.SduDataPtr\r
                                                                = protocolRow->DslProtocolTxBufferID->pduInfo.SduDataPtr;\r
@@ -646,7 +654,7 @@ void DslRxIndicationFromPduR(PduIdType dcmRxPduId, NotifResultType result) {  /*
                                                DEBUG( DEBUG_MEDIUM, "DsdDslDataIndication(DcmDslProtocolTxPduId=%d, dcmRxPduId=%d)\n",\r
                                                                mainConnection->DslProtocolTx->DcmDslProtocolTxPduId, dcmRxPduId);\r
                                                runtime->diagReqestRxPduId = dcmRxPduId;\r
-                                               DsdDslDataIndication(  // qqq: We are inside a critical section, how much time will this consume?\r
+                                               DsdDslDataIndication(  // qqq: We are inside a critical section.\r
                                                                &(runtime->diagnosticRequestFromTester),\r
                                                                protocolRow->DslProtocolSIDTable,\r
                                                                protocolRx->DslProtocolAddrType,\r
@@ -696,7 +704,7 @@ BufReq_ReturnType DslProvideTxBuffer(PduIdType dcmTxPduId,  /** @req DCM092 **/
        const Dcm_DslProtocolRowType *protocolRow = NULL;\r
        Dcm_DslRunTimeProtocolParametersType *runtime = NULL;\r
 \r
-       DEBUG( DEBUG_MEDIUM, "DslProvideTxBuffer (dcmTxPduId=%d)\n", dcmTxPduId);\r
+       DEBUG( DEBUG_MEDIUM, "DslProvideTxBuffer=%d\n", dcmTxPduId);\r
        if (findTxPduIdParentConfigurationLeafs(dcmTxPduId, &protocolTx, &mainConnection,\r
                        &connection, &protocolRow, &runtime)) {\r
                switch (runtime->externalTxBufferStatus) { // ### EXTERNAL TX BUFFER ###\r
@@ -749,7 +757,7 @@ void DslTxConfirmation(PduIdType dcmTxPduId, NotifResultType result) {
        Dcm_DslRunTimeProtocolParametersType *runtime = NULL;\r
        imask_t state;\r
 \r
-       DEBUG( DEBUG_MEDIUM, "DslTxConfirmation=%d\n", dcmTxPduId);\r
+       DEBUG( DEBUG_MEDIUM, "DslTxConfirmation=%d, result=%d\n", dcmTxPduId, result);\r
        if (findTxPduIdParentConfigurationLeafs(dcmTxPduId, &protocolTx, &mainConnection,\r
                        &connection, &protocolRow, &runtime)) {\r
                boolean externalBufferReleased = FALSE;\r