WiFi-HAL: Map kernel returned error code to wifihal error

Framework expects error codes of type wifi_error from wifihal.
Map the error codes returned by kernel to wifi_error value and
return the same to framework

Bug: 63971485
Test: Ran VTS tests on marlin.
Change-Id: Ifbb8cdb9c1177da0c6715ee2a63d4299b71f74e3
diff --git a/qcwcn/wifi_hal/common.cpp b/qcwcn/wifi_hal/common.cpp
index 2dd8395..2541b65 100644
--- a/qcwcn/wifi_hal/common.cpp
+++ b/qcwcn/wifi_hal/common.cpp
@@ -23,6 +23,7 @@
 
 #include "wifi_hal.h"
 #include "common.h"
+#include <errno.h>
 
 interface_info *getIfaceInfo(wifi_interface_handle handle)
 {
@@ -447,3 +448,26 @@
     return LowiWifiHalApi;
 }
 
+wifi_error mapErrorKernelToWifiHAL(int error)
+{
+    if (error >= 0)
+        return WIFI_ERROR_NONE;
+
+    switch (error) {
+        case -EOPNOTSUPP:
+            return WIFI_ERROR_NOT_SUPPORTED;
+        case -EAGAIN:
+            return WIFI_ERROR_NOT_AVAILABLE;
+        case -EINVAL:
+            return WIFI_ERROR_INVALID_ARGS;
+        case -ETIMEDOUT:
+            return WIFI_ERROR_TIMED_OUT;
+        case -ENOMEM:
+            return WIFI_ERROR_OUT_OF_MEMORY;
+        case -EBUSY:
+            return WIFI_ERROR_BUSY;
+        default:
+            return WIFI_ERROR_UNKNOWN;
+    }
+    return WIFI_ERROR_UNKNOWN;
+}
diff --git a/qcwcn/wifi_hal/common.h b/qcwcn/wifi_hal/common.h
index 649bf6a..c3ac14e 100644
--- a/qcwcn/wifi_hal/common.h
+++ b/qcwcn/wifi_hal/common.h
@@ -182,6 +182,7 @@
 wifi_error wifi_start_rssi_monitoring(wifi_request_id id, wifi_interface_handle
         iface, s8 max_rssi, s8 min_rssi, wifi_rssi_event_handler eh);
 wifi_error wifi_stop_rssi_monitoring(wifi_request_id id, wifi_interface_handle iface);
+wifi_error mapErrorKernelToWifiHAL(int error);
 // some common macros
 
 #define min(x, y)       ((x) < (y) ? (x) : (y))
diff --git a/qcwcn/wifi_hal/cpp_bindings.cpp b/qcwcn/wifi_hal/cpp_bindings.cpp
index f67b411..36befed 100644
--- a/qcwcn/wifi_hal/cpp_bindings.cpp
+++ b/qcwcn/wifi_hal/cpp_bindings.cpp
@@ -1003,5 +1003,5 @@
 
 cleanup:
     delete *vCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
diff --git a/qcwcn/wifi_hal/gscan.cpp b/qcwcn/wifi_hal/gscan.cpp
index 7894b26..db5f140 100644
--- a/qcwcn/wifi_hal/gscan.cpp
+++ b/qcwcn/wifi_hal/gscan.cpp
@@ -161,7 +161,7 @@
 
 cleanup:
     delete gScanCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 wifi_error wifi_get_gscan_capabilities(wifi_interface_handle handle,
@@ -174,7 +174,7 @@
     if (!(info->supported_feature_set & WIFI_FEATURE_GSCAN)) {
         ALOGE("%s: GSCAN is not supported by driver", __FUNCTION__);
         return WIFI_ERROR_NOT_SUPPORTED;
-     }
+    }
 
     if (capabilities == NULL) {
         ALOGE("%s: NULL capabilities pointer provided. Exit.", __FUNCTION__);
@@ -183,7 +183,7 @@
 
     memcpy(capabilities, &info->capa.gscan_capa, sizeof(wifi_gscan_capabilities));
 
-    return ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 wifi_error wifi_start_gscan(wifi_request_id id,
@@ -396,7 +396,7 @@
             __FUNCTION__, ret);
         gScanStartCmdEventHandler->disableEventHandling();
     }
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 
 }
 
@@ -474,7 +474,7 @@
 
 cleanup:
     delete gScanCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 /* Set the GSCAN BSSID Hotlist. */
@@ -637,7 +637,7 @@
             __FUNCTION__, ret);
         gScanSetBssidHotlistCmdEventHandler->disableEventHandling();
     }
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 wifi_error wifi_reset_bssid_hotlist(wifi_request_id id,
@@ -715,7 +715,7 @@
 
 cleanup:
     delete gScanCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 /* Set the GSCAN Significant AP Change list. */
@@ -889,7 +889,7 @@
         gScanSetSignificantChangeCmdEventHandler->disableEventHandling();
     }
     delete gScanCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 /* Clear the GSCAN Significant AP change list. */
@@ -970,7 +970,7 @@
 
 cleanup:
     delete gScanCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 /* Get the GSCAN cached scan results. */
@@ -1094,7 +1094,7 @@
 cleanup:
     gScanCommand->freeRspParams(eGScanGetCachedResultsRspParams);
     delete gScanCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 /* Random MAC OUI for PNO */
@@ -1149,7 +1149,7 @@
 
 cleanup:
     delete vCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 
@@ -1833,7 +1833,7 @@
             __FUNCTION__, ret);
         gScanSetPnoListCmdEventHandler->disableEventHandling();
     }
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 /* Reset the ePNO list - no ePNO networks should be matched after this */
@@ -1903,7 +1903,7 @@
 
 cleanup:
     delete gScanCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 /* Set the ePNO Passpoint List. */
@@ -2072,7 +2072,7 @@
             __FUNCTION__, ret);
         gScanPnoSetPasspointListCmdEventHandler->disableEventHandling();
     }
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 wifi_error wifi_reset_passpoint_list(wifi_request_id id,
@@ -2160,7 +2160,7 @@
 
 cleanup:
     delete gScanCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 int GScanCommand::allocCachedResultsTemp(int max,
diff --git a/qcwcn/wifi_hal/ifaceeventhandler.cpp b/qcwcn/wifi_hal/ifaceeventhandler.cpp
index fd959ac..9e11ce1 100644
--- a/qcwcn/wifi_hal/ifaceeventhandler.cpp
+++ b/qcwcn/wifi_hal/ifaceeventhandler.cpp
@@ -72,7 +72,7 @@
     }
     mwifiEventHandler->setCallbackHandler(eh);
 
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 /* Reset monitoring for the NL event*/
@@ -96,7 +96,7 @@
         ALOGV("Object mwifiEventHandler for id = %d already Deleted", id);
     }
 
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 /* This function will be the main handler for the registered incoming
diff --git a/qcwcn/wifi_hal/llstats.cpp b/qcwcn/wifi_hal/llstats.cpp
index 88bf79f..9a0365e 100644
--- a/qcwcn/wifi_hal/llstats.cpp
+++ b/qcwcn/wifi_hal/llstats.cpp
@@ -1293,7 +1293,7 @@
     }
 
 cleanup:
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 //Implementation of the functions exposed in LLStats.h
@@ -1356,7 +1356,7 @@
     }
 
 cleanup:
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 
@@ -1413,5 +1413,5 @@
 
 cleanup:
     delete LLCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
diff --git a/qcwcn/wifi_hal/nan.cpp b/qcwcn/wifi_hal/nan.cpp
index f2017fe..894873a 100644
--- a/qcwcn/wifi_hal/nan.cpp
+++ b/qcwcn/wifi_hal/nan.cpp
@@ -54,7 +54,7 @@
     }
 
     ret = nanCommand->setCallbackHandler(handlers);
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 wifi_error nan_get_version(wifi_handle handle,
@@ -103,7 +103,7 @@
     }
 cleanup:
     delete nanCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 /*  Function to send disable request to the wifi driver.*/
@@ -144,7 +144,7 @@
     }
 cleanup:
     delete nanCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 /*  Function to send publish request to the wifi driver.*/
@@ -186,7 +186,7 @@
     }
 cleanup:
     delete nanCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 /*  Function to send publish cancel to the wifi driver.*/
@@ -228,7 +228,7 @@
     }
 cleanup:
     delete nanCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 /*  Function to send Subscribe request to the wifi driver.*/
@@ -270,7 +270,7 @@
     }
 cleanup:
     delete nanCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 /*  Function to cancel subscribe to the wifi driver.*/
@@ -312,7 +312,7 @@
     }
 cleanup:
     delete nanCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 /*  Function to send NAN follow up request to the wifi driver.*/
@@ -354,7 +354,7 @@
     }
 cleanup:
     delete nanCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 /*  Function to send NAN statistics request to the wifi driver.*/
@@ -396,7 +396,7 @@
     }
 cleanup:
     delete nanCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 /*  Function to send NAN configuration request to the wifi driver.*/
@@ -438,7 +438,7 @@
     }
 cleanup:
     delete nanCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 /*  Function to send NAN request to the wifi driver.*/
@@ -480,7 +480,7 @@
     }
 cleanup:
     delete nanCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 /*  Function to send NAN Beacon sdf payload to the wifi driver.
@@ -526,7 +526,7 @@
 
 cleanup:
     delete nanCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 wifi_error nan_get_sta_parameter(transaction_id id,
@@ -550,7 +550,7 @@
     }
 
 cleanup:
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 /*  Function to get NAN capabilities */
@@ -591,7 +591,7 @@
     }
 cleanup:
     delete nanCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 /*  Function to get NAN capabilities */
@@ -677,7 +677,7 @@
     return WIFI_SUCCESS;
 cleanup:
     delete *nanCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 wifi_error nan_data_interface_create(transaction_id id,
@@ -698,7 +698,7 @@
                                     &nanCommand);
     if (ret != WIFI_SUCCESS) {
         ALOGE("%s: Initialization failed", __FUNCTION__);
-        return (wifi_error)ret;
+        return mapErrorKernelToWifiHAL(ret);
     }
 
     /* Add the vendor specific attributes for the NL command. */
@@ -725,7 +725,7 @@
     }
 cleanup:
     delete nanCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 wifi_error nan_data_interface_delete(transaction_id id,
@@ -745,7 +745,7 @@
                                     &nanCommand);
     if (ret != WIFI_SUCCESS) {
         ALOGE("%s: Initialization failed", __FUNCTION__);
-        return (wifi_error)ret;
+        return mapErrorKernelToWifiHAL(ret);
     }
 
     /* Add the vendor specific attributes for the NL command. */
@@ -773,7 +773,7 @@
     }
 cleanup:
     delete nanCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 wifi_error nan_data_request_initiator(transaction_id id,
@@ -792,7 +792,7 @@
                                     &nanCommand);
     if (ret != WIFI_SUCCESS) {
         ALOGE("%s: Initialization failed", __FUNCTION__);
-        return (wifi_error)ret;
+        return mapErrorKernelToWifiHAL(ret);
     }
 
     if ((msg->cipher_type != NAN_CIPHER_SUITE_SHARED_KEY_NONE) &&
@@ -908,7 +908,7 @@
     }
 cleanup:
     delete nanCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 wifi_error nan_data_indication_response(transaction_id id,
@@ -927,7 +927,7 @@
                                     &nanCommand);
     if (ret != WIFI_SUCCESS) {
         ALOGE("%s: Initialization failed", __FUNCTION__);
-        return (wifi_error)ret;
+        return mapErrorKernelToWifiHAL(ret);
     }
 
     if ((msg->cipher_type != NAN_CIPHER_SUITE_SHARED_KEY_NONE) &&
@@ -1025,7 +1025,7 @@
     }
 cleanup:
     delete nanCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 wifi_error nan_data_end(transaction_id id,
@@ -1044,7 +1044,7 @@
                                     &nanCommand);
     if (ret != WIFI_SUCCESS) {
         ALOGE("%s: Initialization failed", __FUNCTION__);
-        return (wifi_error)ret;
+        return mapErrorKernelToWifiHAL(ret);
     }
 
     /* Add the vendor specific attributes for the NL command. */
@@ -1072,7 +1072,7 @@
     }
 cleanup:
     delete nanCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 // Implementation related to nan class common functions
diff --git a/qcwcn/wifi_hal/rssi_monitor.cpp b/qcwcn/wifi_hal/rssi_monitor.cpp
index 8cffe98..b4df331 100644
--- a/qcwcn/wifi_hal/rssi_monitor.cpp
+++ b/qcwcn/wifi_hal/rssi_monitor.cpp
@@ -264,7 +264,7 @@
                                 &vCommand);
     if (ret != WIFI_SUCCESS) {
         ALOGE("%s: Initialization failed", __FUNCTION__);
-        return (wifi_error)ret;
+        return mapErrorKernelToWifiHAL(ret);
     }
 
     ALOGV("%s: Max RSSI:%d Min RSSI:%d", __FUNCTION__,
@@ -308,7 +308,7 @@
 
 cleanup:
     delete vCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 wifi_error wifi_stop_rssi_monitoring(wifi_request_id id,
@@ -337,7 +337,7 @@
                                 &vCommand);
     if (ret != WIFI_SUCCESS) {
         ALOGE("%s: Initialization failed", __FUNCTION__);
-        return (wifi_error)ret;
+        return mapErrorKernelToWifiHAL(ret);
     }
 
     /* Add the vendor specific attributes for the NL command. */
@@ -366,5 +366,5 @@
 
 cleanup:
     delete vCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
diff --git a/qcwcn/wifi_hal/rtt.cpp b/qcwcn/wifi_hal/rtt.cpp
index f3ca8e4..c3d9e69 100644
--- a/qcwcn/wifi_hal/rtt.cpp
+++ b/qcwcn/wifi_hal/rtt.cpp
@@ -80,7 +80,7 @@
     }
 
 cleanup:
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 /* API to request RTT measurement */
@@ -143,7 +143,7 @@
     }
 
 cleanup:
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 /* API to cancel RTT measurements */
@@ -195,7 +195,7 @@
     }
 
 cleanup:
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 // API to configure the LCI. Used in RTT Responder mode only
@@ -239,7 +239,7 @@
     }
 
 cleanup:
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 // API to configure the LCR. Used in RTT Responder mode only.
@@ -283,7 +283,7 @@
     }
 
 cleanup:
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 /*
@@ -320,7 +320,7 @@
     }
 
 cleanup:
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 /**
@@ -366,7 +366,7 @@
     }
 
 cleanup:
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 
@@ -404,5 +404,5 @@
     }
 
 cleanup:
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
diff --git a/qcwcn/wifi_hal/tdls.cpp b/qcwcn/wifi_hal/tdls.cpp
index a1b0936..64d5a63 100644
--- a/qcwcn/wifi_hal/tdls.cpp
+++ b/qcwcn/wifi_hal/tdls.cpp
@@ -415,7 +415,7 @@
     }
 
 cleanup:
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 /* wifi_disable_tdls - disables TDLS-auto mode for a specific route
@@ -469,7 +469,7 @@
 
 cleanup:
     delete pTdlsCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 /* wifi_get_tdls_status - allows getting the status of TDLS for a specific
@@ -518,7 +518,7 @@
     pTdlsCommand->getStatusRspParams(status);
 
 cleanup:
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 /* return the current HW + Firmware combination's TDLS capabilities */
@@ -563,5 +563,5 @@
     if (ret < 0)
         memset(capabilities, 0, sizeof(wifi_tdls_capabilities));
     delete pTdlsCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
diff --git a/qcwcn/wifi_hal/wifi_hal.cpp b/qcwcn/wifi_hal/wifi_hal.cpp
index 229a971..7391e93 100644
--- a/qcwcn/wifi_hal/wifi_hal.cpp
+++ b/qcwcn/wifi_hal/wifi_hal.cpp
@@ -181,7 +181,7 @@
     supportedFeatures.getResponseparams(set);
 
 cleanup:
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 static wifi_error wifi_get_capabilities(wifi_interface_handle handle)
@@ -247,7 +247,7 @@
     info->firmware_bus_max_size = busSizeSupported.getBusSize();
 
 cleanup:
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 static wifi_error wifi_init_user_sock(hal_info *info)
@@ -1202,7 +1202,7 @@
     if (ret) {
         *set_size = 0;
     }
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 
@@ -1248,7 +1248,7 @@
 
 cleanup:
     delete vCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 wifi_error wifi_start_sending_offloaded_packet(wifi_request_id id,
@@ -1268,7 +1268,7 @@
                                 &vCommand);
     if (ret != WIFI_SUCCESS) {
         ALOGE("%s: Initialization failed", __func__);
-        return (wifi_error)ret;
+        return mapErrorKernelToWifiHAL(ret);
     }
 
     ALOGV("ip packet length : %u\nIP Packet:", ip_packet_len);
@@ -1312,7 +1312,7 @@
 
 cleanup:
     delete vCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 wifi_error wifi_stop_sending_offloaded_packet(wifi_request_id id,
@@ -1327,7 +1327,7 @@
                                 &vCommand);
     if (ret != WIFI_SUCCESS) {
         ALOGE("%s: Initialization failed", __func__);
-        return (wifi_error)ret;
+        return mapErrorKernelToWifiHAL(ret);
     }
 
     /* Add the vendor specific attributes for the NL command. */
@@ -1354,7 +1354,7 @@
 
 cleanup:
     delete vCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 static wifi_error wifi_set_packet_filter(wifi_interface_handle iface,
@@ -1380,7 +1380,7 @@
                                     &vCommand);
         if (ret != WIFI_SUCCESS) {
             ALOGE("%s: Initialization failed", __FUNCTION__);
-            return (wifi_error)ret;
+            return mapErrorKernelToWifiHAL(ret);
         }
 
         /* Add the vendor specific attributes for the NL command. */
@@ -1432,7 +1432,7 @@
 cleanup:
     if (vCommand)
         delete vCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 static wifi_error wifi_get_packet_filter_capabilities(
@@ -1499,7 +1499,7 @@
     *max_len = vCommand->getFilterLength();
 cleanup:
     delete vCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 
@@ -1515,7 +1515,7 @@
                                 &vCommand);
     if (ret != WIFI_SUCCESS) {
         ALOGE("%s: Initialization failed", __func__);
-        return (wifi_error)ret;
+        return mapErrorKernelToWifiHAL(ret);
     }
 
     ALOGV("ND offload : %s", enable?"Enable":"Disable");
@@ -1538,5 +1538,5 @@
 
 cleanup:
     delete vCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
diff --git a/qcwcn/wifi_hal/wificonfig.cpp b/qcwcn/wifi_hal/wificonfig.cpp
index b0c1397..d125186 100644
--- a/qcwcn/wifi_hal/wificonfig.cpp
+++ b/qcwcn/wifi_hal/wificonfig.cpp
@@ -100,7 +100,7 @@
 
 cleanup:
     delete wifiConfigCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 /* Set the country code to driver. */
@@ -151,7 +151,7 @@
 
 cleanup:
     delete wifiConfigCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 wifi_error wifi_set_beacon_wifi_iface_stats_averaging_factor(
@@ -219,7 +219,7 @@
 
 cleanup:
     delete wifiConfigCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 wifi_error wifi_set_guard_time(wifi_request_id id,
@@ -283,7 +283,7 @@
 
 cleanup:
     delete wifiConfigCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 wifi_error wifi_set_tx_power_limit(wifi_interface_handle handle,
@@ -360,14 +360,12 @@
     ret = wifiConfigCommand->requestEvent();
     if (ret != 0) {
         ALOGE("wifi_set_tx_power_limit(): requestEvent Error:%d", ret);
-        if (ret == -EOPNOTSUPP)
-            ret = WIFI_ERROR_NOT_SUPPORTED;
         goto cleanup;
     }
 
 cleanup:
     delete wifiConfigCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 wifi_error wifi_reset_tx_power_limit(wifi_interface_handle handle)
@@ -420,14 +418,12 @@
     ret = wifiConfigCommand->requestEvent();
     if (ret != 0) {
         ALOGE("wifi_set_tx_power_limit(): requestEvent Error:%d", ret);
-        if (ret == -EOPNOTSUPP)
-            ret = WIFI_ERROR_NOT_SUPPORTED;
         goto cleanup;
     }
 
 cleanup:
     delete wifiConfigCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 WiFiConfigCommand::WiFiConfigCommand(wifi_handle handle,
diff --git a/qcwcn/wifi_hal/wifilogger.cpp b/qcwcn/wifi_hal/wifilogger.cpp
index 6c77650..a8423cf 100644
--- a/qcwcn/wifi_hal/wifilogger.cpp
+++ b/qcwcn/wifi_hal/wifilogger.cpp
@@ -153,7 +153,7 @@
 cleanup:
     if (wifiLoggerCommand)
         delete wifiLoggerCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 
 }
 
@@ -183,7 +183,7 @@
         get_rb_status(rb_info, rbs);
     }
     *num_buffers = NUM_RING_BUFS;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 void push_out_all_ring_buffers(hal_info *info)
@@ -273,7 +273,7 @@
 
 cleanup:
     delete wifiLoggerCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 /*  Function to get the data in each ring for the given ring ID.*/
@@ -339,7 +339,7 @@
 
 cleanup:
     delete wifiLoggerCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 void WifiLoggerCommand::setVersionInfo(char *buffer, int buffer_size) {
@@ -405,7 +405,7 @@
     }
 cleanup:
     delete wifiLoggerCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 
 }
 
@@ -468,7 +468,7 @@
     }
 cleanup:
     delete wifiLoggerCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 
@@ -534,7 +534,7 @@
 
 cleanup:
     delete wifiLoggerCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 wifi_error wifi_set_log_handler(wifi_request_id id,
@@ -1501,7 +1501,7 @@
 
 cleanup:
     delete wifiLoggerCommand;
-    return (wifi_error)ret;
+    return mapErrorKernelToWifiHAL(ret);
 }
 
 void WifiLoggerCommand::getWakeStatsRspParams(