wlan: Send done indication for invalid buffer length

Currently the host driver does not process when it receives invalid
length and it causes firmware to stay active as it is waiting for done
indication from host. Made changes to sent done indication for invalid
length also.

Change-Id: Ie28fe5b00890b63556164f481d0ea351b29004c8
CRs-Fixed: 914090
diff --git a/CORE/WDI/CP/src/wlan_qct_wdi.c b/CORE/WDI/CP/src/wlan_qct_wdi.c
index d8d523e..cbb1784 100644
--- a/CORE/WDI/CP/src/wlan_qct_wdi.c
+++ b/CORE/WDI/CP/src/wlan_qct_wdi.c
@@ -35191,7 +35191,7 @@
                  &pLoggingSession->logBuffAddress, MAX_NUM_OF_BUFFER *
                  sizeof(FWLoggingDxeDoneIndParams->logBuffAddress[0]));
 
-  FWLoggingDxeDoneIndParams->status = eHAL_STATUS_SUCCESS;
+  FWLoggingDxeDoneIndParams->status = pLoggingSession->status;
   FWLoggingDxeDoneIndParams->doneIndicationForSource = (wpt_uint16)*pLogType;
 
   wpalMemoryCopy(&FWLoggingDxeDoneIndParams->logBuffLength,
diff --git a/CORE/WDI/DP/inc/wlan_qct_wdi_ds.h b/CORE/WDI/DP/inc/wlan_qct_wdi_ds.h
index ba95c76..a7c7a02 100644
--- a/CORE/WDI/DP/inc/wlan_qct_wdi_ds.h
+++ b/CORE/WDI/DP/inc/wlan_qct_wdi_ds.h
@@ -186,6 +186,7 @@
 
 typedef struct
 {
+   wpt_uint16 status;
    wpt_boolean active;
    wpt_uint64 logBuffAddress[MAX_NUM_OF_BUFFER];
    wpt_uint32 logBuffLength[MAX_NUM_OF_BUFFER];
diff --git a/CORE/WDI/TRP/DTS/inc/wlan_qct_wdi_dts.h b/CORE/WDI/TRP/DTS/inc/wlan_qct_wdi_dts.h
index 2eccf5c..b20b7d6 100644
--- a/CORE/WDI/TRP/DTS/inc/wlan_qct_wdi_dts.h
+++ b/CORE/WDI/TRP/DTS/inc/wlan_qct_wdi_dts.h
@@ -93,6 +93,11 @@
    WDTS_POWER_STATE_MAX
 } WDTS_PowerStateType;
 
+typedef enum
+{
+   WDTS_LOGGING_STATUS_SUCCESS,
+   WDTS_LOGGING_STATUS_ERROR
+} WDTS_LoggingSessionStatus;
 
 typedef wpt_status (*WDTS_TxCompleteCbType)(void *pContext, wpt_packet *pFrame, wpt_status status);
 typedef wpt_status (*WDTS_RxFrameReadyCbType) (void *pContext, wpt_packet *pFrame, WDTS_ChannelType channel);
diff --git a/CORE/WDI/TRP/DTS/src/wlan_qct_wdi_dts.c b/CORE/WDI/TRP/DTS/src/wlan_qct_wdi_dts.c
index 1832804..13b2d59 100644
--- a/CORE/WDI/TRP/DTS/src/wlan_qct_wdi_dts.c
+++ b/CORE/WDI/TRP/DTS/src/wlan_qct_wdi_dts.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012-2013 The Linux Foundation. All rights reserved.
+ * Copyright (c) 2011-2015 The Linux Foundation. All rights reserved.
  *
  * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
  *
@@ -875,55 +875,6 @@
 
 }
 
-void WDTS_MbReceiveMsg(void *pContext)
-{
-  tpLoggingMailBox pLoggingMb;
-  WDI_DS_LoggingSessionType *pLoggingSession;
-  wpt_int8 i, noMem = 0;
-  wpt_uint32 totalLen = 0;
-
-  pLoggingMb = (tpLoggingMailBox)WDI_DS_GetLoggingMbAddr(pContext);
-  pLoggingSession = (WDI_DS_LoggingSessionType *)
-                       WDI_DS_GetLoggingSession(pContext);
-
-  for(i = 0; i < MAX_NUM_OF_BUFFER; i++)
-  {
-     pLoggingSession->logBuffAddress[i] = pLoggingMb->logBuffAddress[i];
-     if (!noMem && (pLoggingMb->logBuffLength[i] <= MAX_LOG_BUFFER_LENGTH))
-     {
-        pLoggingSession->logBuffLength[i] = gTransportDriver.setupLogTransfer(
-                                               pLoggingMb->logBuffAddress[i],
-                                               pLoggingMb->logBuffLength[i]);
-     }
-     else
-     {
-        pLoggingSession->logBuffLength[i] = 0;
-        continue;
-     }
-
-     totalLen += pLoggingSession->logBuffLength[i];
-
-     if (pLoggingSession->logBuffLength[i] < pLoggingMb->logBuffLength[i])
-     {
-        noMem = 1;
-     }
-  }
-
-  pLoggingSession->done = pLoggingMb->done;
-  pLoggingSession->logType = pLoggingMb->logType;
-  pLoggingSession->reasonCode = pLoggingMb->reasonCode;
-  // Done using Mailbox, zero out the memory.
-  wpalMemoryZero(pLoggingMb, sizeof(tLoggingMailBox));
-
-  if (totalLen)
-  {
-     if (gTransportDriver.startLogTransfer() == eWLAN_PAL_STATUS_SUCCESS)
-        return;
-  }
-
-  // Send Done event to upper layers, since we wont be getting any from DXE
-}
-
 void WDTS_LogRxDone(void *pContext)
 {
   WDI_DS_LoggingSessionType *pLoggingSession;
@@ -953,6 +904,76 @@
   return;
 }
 
+void WDTS_MbReceiveMsg(void *pContext)
+{
+  tpLoggingMailBox pLoggingMb;
+  WDI_DS_LoggingSessionType *pLoggingSession;
+  wpt_int8 i, noMem = 0;
+  wpt_uint32 totalLen = 0;
+
+  pLoggingMb = (tpLoggingMailBox)WDI_DS_GetLoggingMbAddr(pContext);
+  pLoggingSession = (WDI_DS_LoggingSessionType *)
+                       WDI_DS_GetLoggingSession(pContext);
+
+  for(i = 0; i < MAX_NUM_OF_BUFFER; i++)
+  {
+      totalLen += pLoggingMb->logBuffLength[i];
+      // Send done indication when the logbuffer size exceeds 128KB.
+      if (totalLen > MAX_LOG_BUFFER_LENGTH || pLoggingMb->logBuffLength[i] > MAX_LOG_BUFFER_LENGTH)
+      {
+         DTI_TRACE( DTI_TRACE_LEVEL_ERROR, " %d received invalid log buffer length",
+                                              totalLen);
+         // Done using Mailbox, zero out the memory.
+         wpalMemoryZero(pLoggingMb, sizeof(tLoggingMailBox));
+         wpalMemoryZero(pLoggingSession, sizeof(WDI_DS_LoggingSessionType));
+         //Set Status as Failure
+         pLoggingSession->status = WDTS_LOGGING_STATUS_ERROR;
+         WDTS_LogRxDone(pContext);
+
+         return;
+      }
+  }
+
+  totalLen = 0;
+  for(i = 0; i < MAX_NUM_OF_BUFFER; i++)
+  {
+     pLoggingSession->logBuffAddress[i] = pLoggingMb->logBuffAddress[i];
+     if (!noMem)
+     {
+        pLoggingSession->logBuffLength[i] = gTransportDriver.setupLogTransfer(
+                                               pLoggingMb->logBuffAddress[i],
+                                               pLoggingMb->logBuffLength[i]);
+     }
+     else
+     {
+        pLoggingSession->logBuffLength[i] = 0;
+        continue;
+     }
+
+     totalLen += pLoggingSession->logBuffLength[i];
+
+     if (pLoggingSession->logBuffLength[i] < pLoggingMb->logBuffLength[i])
+     {
+        noMem = 1;
+     }
+  }
+
+  pLoggingSession->done = pLoggingMb->done;
+  pLoggingSession->logType = pLoggingMb->logType;
+  pLoggingSession->reasonCode = pLoggingMb->reasonCode;
+  pLoggingSession->status = WDTS_LOGGING_STATUS_SUCCESS;
+  // Done using Mailbox, zero out the memory.
+  wpalMemoryZero(pLoggingMb, sizeof(tLoggingMailBox));
+
+  if (totalLen)
+  {
+     if (gTransportDriver.startLogTransfer() == eWLAN_PAL_STATUS_SUCCESS)
+        return;
+  }
+
+  // Send Done event to upper layers, since we wont be getting any from DXE
+}
+
 /* DTS open  function. 
  * On open the transport device should initialize itself.
  * Parameters: