Handle tdls status from the driver as response in the same context

Currently, it's being handled as an asynchronous event from the
driver. The new approach would be to receive the response from the
driver as an nl reply within the same nl message and in the same
context.

Change-Id: I32550f3e7aea71d60d286b022513278488258e2b
CRs-Fixed: 715277
diff --git a/qcwcn/wifi_hal/tdls.cpp b/qcwcn/wifi_hal/tdls.cpp
index a535a88..0f1da68 100644
--- a/qcwcn/wifi_hal/tdls.cpp
+++ b/qcwcn/wifi_hal/tdls.cpp
@@ -124,7 +124,7 @@
 //Call the appropriate callback handler after parsing the vendor data.
 int TdlsCommand::handleEvent(WifiEvent &event)
 {
-    ALOGI("Got a LLStats message from Driver");
+    ALOGI("Got a TDLS message from Driver");
     unsigned i=0;
     u32 status;
     int ret = WIFI_SUCCESS;
@@ -152,7 +152,7 @@
                 memcpy(mTDLSStateChange.addr,
                      (u8 *)nla_data(tb_vendor[QCA_WLAN_VENDOR_ATTR_TDLS_STATE_MAC_ADDR]),
                            nla_len(tb_vendor[QCA_WLAN_VENDOR_ATTR_TDLS_STATE_MAC_ADDR]));
-                ALOGI("TDLS: State : %u ", mTDLSStateChange.state);
+                ALOGI("TDLS: State Old : %u ", mTDLSStateChange.state);
 
                 if (!tb_vendor[QCA_WLAN_VENDOR_ATTR_TDLS_STATE])
                 {
@@ -160,8 +160,8 @@
                     return WIFI_ERROR_INVALID_ARGS;
                 }
                 mTDLSStateChange.state =
-                     nla_get_u32(tb_vendor[QCA_WLAN_VENDOR_ATTR_TDLS_STATE]);
-                ALOGI("TDLS: State : %u ", mTDLSStateChange.state);
+                     (wifi_tdls_state)get_s32(tb_vendor[QCA_WLAN_VENDOR_ATTR_TDLS_STATE]);
+                ALOGI("TDLS: State New : %u ", mTDLSStateChange.state);
 
                 if (!tb_vendor[QCA_WLAN_VENDOR_ATTR_TDLS_STATUS])
                 {
@@ -169,11 +169,28 @@
                     return WIFI_ERROR_INVALID_ARGS;
                 }
                 mTDLSStateChange.reason =
-                    nla_get_u32(tb_vendor[QCA_WLAN_VENDOR_ATTR_TDLS_STATUS]);
+                    (wifi_tdls_reason)get_s32(tb_vendor[QCA_WLAN_VENDOR_ATTR_TDLS_STATUS]);
                 ALOGI("TDLS: Reason : %u ", mTDLSStateChange.reason);
             }
             break;
 
+        default:
+            //error case should not happen print log
+            ALOGE("%s: Wrong TDLS subcmd received %d", __func__, mSubcmd);
+    }
+
+    return NL_SKIP;
+}
+
+int TdlsCommand::handleResponse(WifiEvent &reply)
+{
+    ALOGI("Received a TDLS response message from Driver");
+    u32 status;
+    int i = 0;
+    WifiVendorCommand::handleResponse(reply);
+
+    switch(mSubcmd)
+    {
         case QCA_NL80211_VENDOR_SUBCMD_TDLS_GET_STATUS:
             {
                 wifi_request_id id;
@@ -190,7 +207,7 @@
                     return WIFI_ERROR_INVALID_ARGS;
                 }
                 mTDLSgetStatusRspParams.state =
-                     nla_get_u8(tb_vendor[QCA_WLAN_VENDOR_ATTR_TDLS_GET_STATUS_STATE]);
+                     (wifi_tdls_state)get_s32(tb_vendor[QCA_WLAN_VENDOR_ATTR_TDLS_GET_STATUS_STATE]);
                 ALOGI("TDLS: State : %u ", mTDLSgetStatusRspParams.state);
 
                 if (!tb_vendor[QCA_WLAN_VENDOR_ATTR_TDLS_GET_STATUS_REASON])
@@ -199,19 +216,18 @@
                     return WIFI_ERROR_INVALID_ARGS;
                 }
                 mTDLSgetStatusRspParams.reason =
-                    nla_get_u8(tb_vendor[QCA_WLAN_VENDOR_ATTR_TDLS_GET_STATUS_REASON]);
+                    (wifi_tdls_reason)get_s32(tb_vendor[QCA_WLAN_VENDOR_ATTR_TDLS_GET_STATUS_REASON]);
                 ALOGI("TDLS: Reason : %u ", mTDLSgetStatusRspParams.reason);
             }
             break;
-
-        default:
-            //error case should not happen print log
-            ALOGE("%s: Wrong LLStats subcmd received %d", __func__, mSubcmd);
+        default :
+            ALOGE("%s: Wrong TDLS subcmd response received %d",
+                __func__, mSubcmd);
     }
-
     return NL_SKIP;
 }
 
+
 int TdlsCommand::setCallbackHandler(wifi_tdls_handler nHandler, u32 event)
 {
     int res = 0;
@@ -233,8 +249,8 @@
 void TdlsCommand::getStatusRspParams( wifi_tdls_state *state,
                                       wifi_tdls_reason *reason)
 {
-    *state = (wifi_tdls_state)mTDLSgetStatusRspParams.state;
-    *reason = (wifi_tdls_reason)mTDLSgetStatusRspParams.reason;
+    *state = mTDLSgetStatusRspParams.state;
+    *reason = mTDLSgetStatusRspParams.reason;
 }
 
 int TdlsCommand::requestResponse()
diff --git a/qcwcn/wifi_hal/tdlsCommand.h b/qcwcn/wifi_hal/tdlsCommand.h
index 5483ad3..c391368 100644
--- a/qcwcn/wifi_hal/tdlsCommand.h
+++ b/qcwcn/wifi_hal/tdlsCommand.h
@@ -68,14 +68,14 @@
 #endif /* __cplusplus */
 
 typedef struct{
-    u8 state;
-    u8 reason;
+    wifi_tdls_state state;
+    wifi_tdls_reason reason;
 } TDLSgetStatusRspParams;
 
 typedef struct{
     mac_addr addr;
-    u8 state;
-    u8 reason;
+    wifi_tdls_state state;
+    wifi_tdls_reason reason;
 } TDLSStateChange;
 
 /* Response and Event Callbacks */
@@ -107,6 +107,8 @@
 
     virtual int handleEvent(WifiEvent &event);
 
+    virtual int handleResponse(WifiEvent &reply);
+
     virtual int setCallbackHandler(wifi_tdls_handler nHandler, u32 event);
 
     virtual void unregisterHandler(u32 subCmd);