[7885][7872] wlbt : Enhanced logGing support
authorHimani Gupta <himani.g2@samsung.com>
Fri, 2 Feb 2018 07:03:39 +0000 (12:33 +0530)
committerTarun Karela <t.karela@samsung.com>
Mon, 4 Jun 2018 09:40:47 +0000 (10:40 +0100)
HAL changes to support enhanced logGing.
SCSC-Bug-Id:SSB-25788

Change-Id: I9573e7f7ccda8f5c22ce857e2dd8ba2fd90cab08
Signed-off-by: Himani Gupta <himani.g2@samsung.com>
Android.mk
common.h
wifi_hal.cpp
wifi_logger.cpp [new file with mode: 0755]

index bb391cef2cae2f1c34077a19faaa0c5c4266ff23..739ff680f226819ca20e1ba1ce429b05ee817817 100755 (executable)
@@ -27,7 +27,8 @@ LOCAL_SRC_FILES := \
        gscan.cpp \
        link_layer_stats.cpp \
        wifi_offload.cpp \
-       roam.cpp
+       roam.cpp \
+       wifi_logger.cpp
 
 LOCAL_MODULE := libwifi-hal-slsi
 
index 164db798069bc81e2a1adf6f41a4b8fe2e232456..48800ac0768401ff22dc6987b26095a3f04656f0 100755 (executable)
--- a/common.h
+++ b/common.h
@@ -123,6 +123,10 @@ typedef enum {
     ANDROID_NL80211_SUBCMD_LSTATS_RANGE_START = 0x1200,
     ANDROID_NL80211_SUBCMD_LSTATS_RANGE_END   = 0x12FF,
 
+    /* define all Logger related commands between 0x1400 and 0x14FF */
+    ANDROID_NL80211_SUBCMD_DEBUG_RANGE_START = 0x1400,
+    ANDROID_NL80211_SUBCMD_DEBUG_RANGE_END   = 0x14FF,
+
     /* define all wifi offload related commands between 0x1400 and 0x14FF */
     ANDROID_NL80211_SUBCMD_WIFI_OFFLOAD_RANGE_START = 0x1400,
     ANDROID_NL80211_SUBCMD_WIFI_OFFLOAD_RANGE_END   = 0x14FF,
@@ -172,7 +176,9 @@ typedef enum {
     WIFI_HANGED_EVENT,
     WIFI_EPNO_EVENT,
     WIFI_HOTSPOT_MATCH,
-    WIFI_RSSI_REPORT_EVENT
+    WIFI_RSSI_REPORT_EVENT,
+    ENHANCE_LOGGER_RING_EVENT,
+    ENHANCE_LOGGER_MEM_DUMP_EVENT
 
 } WIFI_EVENT;
 
@@ -254,5 +260,13 @@ wifi_interface_handle getIfaceHandle(interface_info *info);
 #define min(x, y)       ((x) < (y) ? (x) : (y))
 #define max(x, y)       ((x) > (y) ? (x) : (y))
 
+#define NULL_CHECK_RETURN(ptr, str, ret) \
+    do { \
+        if (!(ptr)) { \
+            ALOGE("%s(): null pointer - #ptr (%s)\n", __FUNCTION__, str); \
+            return ret; \
+        } \
+    } while (0)
+
 #endif
 
index 1c3564a47e482763ba537235696d045f8af0f1c0..951bac577e4447c14424d503878890cc68303c23 100755 (executable)
@@ -62,6 +62,8 @@ enum wifi_rssi_monitor_attr {
 static 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);
 static wifi_error wifi_stop_rssi_monitoring(wifi_request_id id, wifi_interface_handle iface);
+wifi_error (*wifi_get_wake_reason_stats)(wifi_interface_handle iface,
+                        WLAN_DRIVER_WAKE_REASON_CNT *wifi_wake_reason_cnt);
 
 /* Initialize/Cleanup */
 
@@ -132,6 +134,20 @@ wifi_error init_wifi_vendor_hal_func_table(wifi_hal_fn *fn)
     fn->wifi_configure_roaming = wifi_configure_roaming;
     fn->wifi_configure_nd_offload = wifi_configure_nd_offload;
     fn->wifi_get_packet_filter_capabilities = wifi_get_packet_filter_capabilities;
+    fn->wifi_start_pkt_fate_monitoring = wifi_start_pkt_fate_monitoring;
+    fn->wifi_get_tx_pkt_fates = wifi_get_tx_pkt_fates;
+    fn->wifi_get_rx_pkt_fates = wifi_get_rx_pkt_fates;
+    fn->wifi_start_logging = wifi_start_logging;
+    fn->wifi_set_log_handler = wifi_set_log_handler;
+    fn->wifi_set_alert_handler= wifi_set_alert_handler;
+    fn->wifi_get_ring_buffers_status = wifi_get_ring_buffers_status;
+    fn->wifi_get_logger_supported_feature_set = wifi_get_logger_supported_feature_set;
+    fn->wifi_get_ring_data = wifi_get_ring_data;
+    fn->wifi_get_driver_version = wifi_get_driver_version;
+    fn->wifi_get_firmware_version = wifi_get_firmware_version;
+    fn->wifi_get_firmware_memory_dump = wifi_get_firmware_memory_dump;
+    fn->wifi_get_driver_memory_dump = wifi_get_driver_memory_dump;
+    fn->wifi_get_wake_reason_stats = wifi_get_wake_reason_stats;
 
     return WIFI_SUCCESS;
 }
diff --git a/wifi_logger.cpp b/wifi_logger.cpp
new file mode 100755 (executable)
index 0000000..9ca3e13
--- /dev/null
@@ -0,0 +1,1428 @@
+#include <stdint.h>\r
+#include <fcntl.h>\r
+#include <sys/socket.h>\r
+#include <netlink/genl/genl.h>\r
+#include <netlink/genl/family.h>\r
+#include <netlink/genl/ctrl.h>\r
+#include <linux/rtnetlink.h>\r
+#include <netpacket/packet.h>\r
+#include <linux/filter.h>\r
+#include <linux/errqueue.h>\r
+\r
+#include <linux/pkt_sched.h>\r
+#include <netlink/object-api.h>\r
+#include <netlink/netlink.h>\r
+#include <netlink/socket.h>\r
+#include <netlink-private/object-api.h>\r
+#include <netlink-private/types.h>\r
+\r
+#include "nl80211_copy.h"\r
+#include "sync.h"\r
+\r
+#define LOG_TAG  "WifiHAL"\r
+\r
+#include <utils/Log.h>\r
+\r
+#include "wifi_hal.h"\r
+#include "common.h"\r
+#include "cpp_bindings.h"\r
+\r
+using namespace android;\r
+\r
+typedef enum {\r
+    ENHANCE_LOGGER_START_LOGGING = ANDROID_NL80211_SUBCMD_DEBUG_RANGE_START,\r
+    ENHANCE_LOGGER_TRIGGER_FW_MEM_DUMP,\r
+    ENHANCE_LOGGER_GET_FW_MEM_DUMP,\r
+    ENHANCE_LOGGER_GET_VER,\r
+    ENHANCE_LOGGER_GET_RING_STATUS,\r
+    ENHANCE_LOGGER_GET_RING_DATA,\r
+    ENHANCE_LOGGER_GET_FEATURE,\r
+    ENHANCE_LOGGER_RESET_LOGGING,\r
+    ENHANCE_LOGGER_TRIGGER_DRIVER_MEM_DUMP,\r
+    ENHANCE_LOGGER_GET_DRIVER_MEM_DUMP,\r
+    ENHANCE_LOGGER_START_PKT_FATE_MONITORING,\r
+    ENHANCE_LOGGER_GET_TX_PKT_FATES,\r
+    ENHANCE_LOGGER_GET_RX_PKT_FATES,\r
+    ENHANCE_LOGGER_GET_WAKE_REASON_STATS,\r
+} DEBUG_SUB_COMMAND;\r
+\r
+typedef enum {\r
+    ENHANCE_LOGGER_ATTRIBUTE_DRIVER_VER,\r
+    ENHANCE_LOGGER_ATTRIBUTE_FW_VER,\r
+    ENHANCE_LOGGER_ATTRIBUTE_RING_ID,\r
+    ENHANCE_LOGGER_ATTRIBUTE_RING_NAME,\r
+    ENHANCE_LOGGER_ATTRIBUTE_RING_FLAGS,\r
+    ENHANCE_LOGGER_ATTRIBUTE_LOG_LEVEL,\r
+    ENHANCE_LOGGER_ATTRIBUTE_LOG_TIME_INTVAL,\r
+    ENHANCE_LOGGER_ATTRIBUTE_LOG_MIN_DATA_SIZE,\r
+    ENHANCE_LOGGER_ATTRIBUTE_FW_DUMP_LEN,\r
+    ENHANCE_LOGGER_ATTRIBUTE_FW_DUMP_DATA,\r
+    // LOGGER_ATTRIBUTE_FW_ERR_CODE,\r
+    ENHANCE_LOGGER_ATTRIBUTE_RING_DATA,\r
+    ENHANCE_LOGGER_ATTRIBUTE_RING_STATUS,\r
+    ENHANCE_LOGGER_ATTRIBUTE_RING_NUM,\r
+    ENHANCE_LOGGER_ATTRIBUTE_DRIVER_DUMP_LEN,\r
+    ENHANCE_LOGGER_ATTRIBUTE_DRIVER_DUMP_DATA,\r
+    ENHANCE_LOGGER_ATTRIBUTE_PKT_FATE_NUM,\r
+    ENHANCE_LOGGER_ATTRIBUTE_PKT_FATE_DATA,\r
+    //Attributes for data used by wake stats subcmd.\r
+    ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_INVALID = 0,\r
+    ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_TOTAL_CMD_EVENT_WAKE,\r
+    ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_CMD_EVENT_WAKE_CNT_PTR,\r
+    ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_CMD_EVENT_WAKE_CNT_SZ,\r
+    ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_TOTAL_DRIVER_FW_LOCAL_WAKE,\r
+    ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_DRIVER_FW_LOCAL_WAKE_CNT_PTR,\r
+    ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_DRIVER_FW_LOCAL_WAKE_CNT_SZ,\r
+    ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_TOTAL_RX_DATA_WAKE,\r
+    ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_RX_UNICAST_CNT,\r
+    ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_RX_MULTICAST_CNT,\r
+    ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_RX_BROADCAST_CNT,\r
+    ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_ICMP_PKT,\r
+    ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_ICMP6_PKT,\r
+    ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_ICMP6_RA,\r
+    ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_ICMP6_NA,\r
+    ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_ICMP6_NS,\r
+    ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_ICMP4_RX_MULTICAST_CNT,\r
+    ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_ICMP6_RX_MULTICAST_CNT,\r
+    ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_OTHER_RX_MULTICAST_CNT,\r
+} ENHANCE_LOGGER_ATTRIBUTE;\r
+\r
+typedef enum {\r
+    DEBUG_OFF = 0,\r
+    DEBUG_NORMAL,\r
+    DEBUG_VERBOSE,\r
+    DEBUG_VERY,\r
+    DEBUG_VERY_VERY,\r
+} ENHANCE_LOGGER_LEVEL;\r
+\r
+typedef enum {\r
+    GET_FW_VER,\r
+    GET_DRV_VER,\r
+    GET_RING_DATA,\r
+    GET_RING_STATUS,\r
+    GET_FEATURE,\r
+    START_RING_LOG,\r
+    GET_FW_DUMP,\r
+    GET_DRIVER_DUMP,\r
+} GetCmdType;\r
+\r
+typedef enum {\r
+    PACKET_MONITOR_START,\r
+    TX_PACKET_FATE,\r
+    RX_PACKET_FATE,\r
+} PktFateReqType;\r
+\r
+class DebugCommand : public WifiCommand\r
+{\r
+    char *mBuff;\r
+    int *mBuffSize;\r
+    u32 *mNumRings;\r
+    wifi_ring_buffer_status *mStatus;\r
+    unsigned int *mSupport;\r
+    u32 mVerboseLevel;\r
+    u32 mFlags;\r
+    u32 mMaxIntervalSec;\r
+    u32 mMinDataSize;\r
+    char *mRingName;\r
+    GetCmdType mType;\r
+\r
+public:\r
+\r
+    // constructor for get version\r
+    DebugCommand(wifi_interface_handle iface, char *buffer, int *buffer_size,\r
+            GetCmdType cmdType)\r
+        : WifiCommand(iface, 0), mBuff(buffer), mBuffSize(buffer_size), mType\r
+        (cmdType)\r
+    {\r
+        memset(mBuff, 0, *mBuffSize);\r
+    }\r
+\r
+    // constructor for ring data\r
+    DebugCommand(wifi_interface_handle iface, char *ring_name, GetCmdType cmdType)\r
+        : WifiCommand(iface, 0), mRingName(ring_name), mType(cmdType)\r
+    { }\r
+\r
+    // constructor for ring status\r
+    DebugCommand(wifi_interface_handle iface, u32 *num_rings,\r
+            wifi_ring_buffer_status *status, GetCmdType cmdType)\r
+        : WifiCommand(iface, 0), mNumRings(num_rings), mStatus(status), mType(cmdType)\r
+    {\r
+        memset(mStatus, 0, sizeof(wifi_ring_buffer_status) * (*mNumRings));\r
+    }\r
+\r
+    // constructor for feature set\r
+    DebugCommand(wifi_interface_handle iface, unsigned int *support, GetCmdType cmdType)\r
+        : WifiCommand(iface, 0), mSupport(support), mType(cmdType)\r
+    { }\r
+\r
+    // constructor for ring params\r
+    DebugCommand(wifi_interface_handle iface, u32 verbose_level, u32 flags,\r
+            u32 max_interval_sec, u32 min_data_size, char *ring_name, GetCmdType cmdType)\r
+        : WifiCommand(iface, 0), mVerboseLevel(verbose_level), mFlags(flags),\r
+        mMaxIntervalSec(max_interval_sec), mMinDataSize(min_data_size),\r
+        mRingName(ring_name), mType(cmdType)\r
+    { }\r
+\r
+    int createRingRequest(WifiRequest& request) {\r
+        int result = request.create(GOOGLE_OUI, ENHANCE_LOGGER_START_LOGGING);\r
+        if (result != WIFI_SUCCESS) {\r
+            ALOGE("Failed to create start ring logger request; result = %d", result);\r
+            return result;\r
+        }\r
+\r
+        nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA);\r
+\r
+        result = request.put_u32(ENHANCE_LOGGER_ATTRIBUTE_LOG_LEVEL, mVerboseLevel);\r
+        if (result != WIFI_SUCCESS) {\r
+            ALOGE("Failed to put log level; result = %d", result);\r
+            return result;\r
+        }\r
+        result = request.put_u32(ENHANCE_LOGGER_ATTRIBUTE_RING_FLAGS, mFlags);\r
+        if (result != WIFI_SUCCESS) {\r
+            ALOGE("Failed to put ring flags; result = %d", result);\r
+            return result;\r
+        }\r
+        result = request.put_u32(ENHANCE_LOGGER_ATTRIBUTE_LOG_TIME_INTVAL, mMaxIntervalSec);\r
+        if (result != WIFI_SUCCESS) {\r
+            ALOGE("Failed to put log time interval; result = %d", result);\r
+            return result;\r
+        }\r
+        result = request.put_u32(ENHANCE_LOGGER_ATTRIBUTE_LOG_MIN_DATA_SIZE, mMinDataSize);\r
+        if (result != WIFI_SUCCESS) {\r
+            ALOGE("Failed to put min data size; result = %d", result);\r
+            return result;\r
+        }\r
+        result = request.put_string(ENHANCE_LOGGER_ATTRIBUTE_RING_NAME, mRingName);\r
+        if (result != WIFI_SUCCESS) {\r
+            ALOGE("Failed to put ringbuffer name; result = %d", result);\r
+            return result;\r
+        }\r
+        request.attr_end(data);\r
+\r
+        return WIFI_SUCCESS;\r
+    }\r
+\r
+    int createRequest(WifiRequest &request) {\r
+        int result;\r
+\r
+        switch (mType) {\r
+            case GET_FW_VER:\r
+            {\r
+                result = request.create(GOOGLE_OUI, ENHANCE_LOGGER_GET_VER);\r
+                if (result != WIFI_SUCCESS) {\r
+                    ALOGE("Failed to create get fw version request; result = %d", result);\r
+                    return result;\r
+                }\r
+\r
+                nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA);\r
+\r
+                // Driver expecting only attribute type, passing mbuff as data with\r
+                // length 0 to avoid undefined state\r
+                result = request.put(ENHANCE_LOGGER_ATTRIBUTE_FW_VER, mBuff, 0);\r
+                if (result != WIFI_SUCCESS) {\r
+                    ALOGE("Failed to put get fw version request; result = %d", result);\r
+                    return result;\r
+                }\r
+                request.attr_end(data);\r
+                break;\r
+            }\r
+\r
+            case GET_DRV_VER:\r
+            {\r
+                result = request.create(GOOGLE_OUI, ENHANCE_LOGGER_GET_VER);\r
+                if (result != WIFI_SUCCESS) {\r
+                    ALOGE("Failed to create get drv version request; result = %d", result);\r
+                    return result;\r
+                }\r
+\r
+                nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA);\r
+\r
+                // Driver expecting only attribute type, passing mbuff as data with\r
+                // length 0 to avoid undefined state\r
+                result = request.put(ENHANCE_LOGGER_ATTRIBUTE_DRIVER_VER, mBuff, 0);\r
+\r
+                if (result != WIFI_SUCCESS) {\r
+                    ALOGE("Failed to put get drv version request; result = %d", result);\r
+                    return result;\r
+                }\r
+                request.attr_end(data);\r
+                break;\r
+            }\r
+\r
+            case GET_RING_DATA:\r
+            {\r
+                result = request.create(GOOGLE_OUI, ENHANCE_LOGGER_GET_RING_DATA);\r
+                if (result != WIFI_SUCCESS) {\r
+                    ALOGE("Failed to create get ring data request; result = %d", result);\r
+                    return result;\r
+                }\r
+\r
+                nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA);\r
+                result = request.put_string(ENHANCE_LOGGER_ATTRIBUTE_RING_NAME, mRingName);\r
+                if (result != WIFI_SUCCESS) {\r
+                    ALOGE("Failed to put ring data request; result = %d", result);\r
+                    return result;\r
+                }\r
+                request.attr_end(data);\r
+                break;\r
+            }\r
+\r
+            case GET_RING_STATUS:\r
+            {\r
+                result = request.create(GOOGLE_OUI, ENHANCE_LOGGER_GET_RING_STATUS);\r
+                if (result != WIFI_SUCCESS) {\r
+                    ALOGE("Failed to create get ring status request; result = %d", result);\r
+                    return result;\r
+                }\r
+                break;\r
+            }\r
+\r
+            case GET_FEATURE:\r
+            {\r
+                result = request.create(GOOGLE_OUI, ENHANCE_LOGGER_GET_FEATURE);\r
+                if (result != WIFI_SUCCESS) {\r
+                    ALOGE("Failed to create get feature request; result = %d", result);\r
+                    return result;\r
+                }\r
+                break;\r
+            }\r
+\r
+            case START_RING_LOG:\r
+                result = createRingRequest(request);\r
+                break;\r
+\r
+            default:\r
+                ALOGE("Unknown Debug command");\r
+                result = WIFI_ERROR_UNKNOWN;\r
+        }\r
+        return result;\r
+    }\r
+\r
+    int start() {\r
+        // ALOGD("Start debug command");\r
+        WifiRequest request(familyId(), ifaceId());\r
+        int result = createRequest(request);\r
+        if (result != WIFI_SUCCESS) {\r
+            ALOGE("Failed to create debug request; result = %d", result);\r
+            return result;\r
+        }\r
+\r
+        result = requestResponse(request);\r
+        if (result != WIFI_SUCCESS) {\r
+            ALOGE("Failed to register debug response; result = %d", result);\r
+        }\r
+        return result;\r
+    }\r
+\r
+    virtual int handleResponse(WifiEvent& reply) {\r
+        ALOGD("In DebugCommand::handleResponse");\r
+\r
+        if (reply.get_cmd() != NL80211_CMD_VENDOR) {\r
+            ALOGD("Ignoring reply with cmd = %d", reply.get_cmd());\r
+            return NL_SKIP;\r
+        }\r
+\r
+        switch (mType) {\r
+            case GET_DRV_VER:\r
+            case GET_FW_VER:\r
+            {\r
+                void *data = reply.get_vendor_data();\r
+                int len = reply.get_vendor_data_len();\r
+\r
+                ALOGD("len = %d, expected len = %d", len, *mBuffSize);\r
+                memcpy(mBuff, data, min(len, *mBuffSize));\r
+                if (*mBuffSize < len)\r
+                    return NL_SKIP;\r
+                *mBuffSize = len;\r
+                break;\r
+            }\r
+\r
+            case START_RING_LOG:\r
+            case GET_RING_DATA:\r
+                break;\r
+\r
+            case GET_RING_STATUS:\r
+            {\r
+                nlattr *vendor_data = reply.get_attribute(NL80211_ATTR_VENDOR_DATA);\r
+                int len = reply.get_vendor_data_len();\r
+                wifi_ring_buffer_status *status(mStatus);\r
+\r
+                if (vendor_data == NULL || len == 0) {\r
+                    ALOGE("No Debug data found");\r
+                    return NL_SKIP;\r
+                }\r
+\r
+                nl_iterator it(vendor_data);\r
+                if (it.get_type() == ENHANCE_LOGGER_ATTRIBUTE_RING_NUM) {\r
+                    unsigned int num_rings = it.get_u32();\r
+                    if (*mNumRings < num_rings) {\r
+                        ALOGE("Not enough status buffers provided, available: %d required: %d",\r
+                                *mNumRings, num_rings);\r
+                    } else {\r
+                        *mNumRings = num_rings;\r
+                    }\r
+                } else {\r
+                    ALOGE("Unknown attribute: %d expecting %d",\r
+                            it.get_type(), ENHANCE_LOGGER_ATTRIBUTE_RING_NUM);\r
+                    return NL_SKIP;\r
+                }\r
+\r
+                it.next();\r
+                if (it.get_type() == ENHANCE_LOGGER_ATTRIBUTE_RING_STATUS) {\r
+                    memcpy(status, it.get_data(), sizeof(wifi_ring_buffer_status) * (*mNumRings));\r
+                } else {\r
+                    ALOGW("Ignoring invalid attribute type = %d, size = %d",\r
+                                it.get_type(), it.get_len());\r
+                }\r
+                break;\r
+            }\r
+\r
+            case GET_FEATURE:\r
+            {\r
+                void *data = reply.get_vendor_data();\r
+                int len = reply.get_vendor_data_len();\r
+\r
+                ALOGD("len = %d, expected len = %d", len, sizeof(unsigned int));\r
+                memcpy(mSupport, data, sizeof(unsigned int));\r
+                break;\r
+            }\r
+\r
+            default:\r
+                ALOGW("Unknown Debug command");\r
+        }\r
+        return NL_OK;\r
+    }\r
+\r
+    virtual int handleEvent(WifiEvent& event) {\r
+        /* NO events! */\r
+        return NL_SKIP;\r
+    }\r
+};\r
+\r
+/* API to get supportable feature */\r
+wifi_error wifi_get_logger_supported_feature_set(wifi_interface_handle iface,\r
+        unsigned int *support)\r
+{\r
+    if (support) {\r
+        DebugCommand *cmd = new DebugCommand(iface, support, GET_FEATURE);\r
+        NULL_CHECK_RETURN(cmd, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY);\r
+        wifi_error result = (wifi_error)cmd->start();\r
+        cmd->releaseRef();\r
+        return result;\r
+    } else {\r
+        ALOGE("Get support buffer NULL");\r
+        return  WIFI_ERROR_INVALID_ARGS;\r
+    }\r
+}\r
+\r
+/* API to get the status of all ring buffers supported by driver */\r
+wifi_error wifi_get_ring_buffers_status(wifi_interface_handle iface,\r
+        u32 *num_rings, wifi_ring_buffer_status *status)\r
+{\r
+    if (status && num_rings) {\r
+        DebugCommand *cmd = new DebugCommand(iface, num_rings, status, GET_RING_STATUS);\r
+        NULL_CHECK_RETURN(cmd, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY);\r
+        wifi_error result = (wifi_error)cmd->start();\r
+        cmd->releaseRef();\r
+        return result;\r
+    } else {\r
+        ALOGE("Ring status buffer NULL");\r
+        return  WIFI_ERROR_INVALID_ARGS;\r
+    }\r
+}\r
+\r
+/* API to collect driver records */\r
+wifi_error wifi_get_ring_data(wifi_interface_handle iface, char *ring_name)\r
+{\r
+    DebugCommand *cmd = new DebugCommand(iface, ring_name, GET_RING_DATA);\r
+    NULL_CHECK_RETURN(cmd, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY);\r
+    wifi_error result = (wifi_error)cmd->start();\r
+    cmd->releaseRef();\r
+    return result;\r
+}\r
+\r
+wifi_error wifi_start_logging(wifi_interface_handle iface, u32 verbose_level,\r
+        u32 flags, u32 max_interval_sec, u32 min_data_size, char *ring_name)\r
+{\r
+    if (ring_name) {\r
+        DebugCommand *cmd = new DebugCommand(iface, verbose_level, flags, max_interval_sec,\r
+                    min_data_size, ring_name, START_RING_LOG);\r
+        NULL_CHECK_RETURN(cmd, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY);\r
+        wifi_error result = (wifi_error)cmd->start();\r
+        cmd->releaseRef();\r
+        return result;\r
+    } else {\r
+        ALOGE("Ring name NULL");\r
+        return  WIFI_ERROR_INVALID_ARGS;\r
+    }\r
+}\r
+\r
+/* API to collect a firmware version string */\r
+wifi_error wifi_get_firmware_version(wifi_interface_handle iface, char *buffer,\r
+        int buffer_size)\r
+{\r
+    if (buffer && (buffer_size > 0)) {\r
+        DebugCommand *cmd = new DebugCommand(iface, buffer, &buffer_size, GET_FW_VER);\r
+        NULL_CHECK_RETURN(cmd, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY);\r
+        wifi_error result = (wifi_error)cmd->start();\r
+        cmd->releaseRef();\r
+        return result;\r
+    } else {\r
+        ALOGE("FW version buffer NULL");\r
+        return  WIFI_ERROR_INVALID_ARGS;\r
+    }\r
+}\r
+\r
+/* API to collect a driver version string */\r
+wifi_error wifi_get_driver_version(wifi_interface_handle iface, char *buffer, int buffer_size)\r
+{\r
+    if (buffer && (buffer_size > 0)) {\r
+        DebugCommand *cmd = new DebugCommand(iface, buffer, &buffer_size, GET_DRV_VER);\r
+        NULL_CHECK_RETURN(cmd, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY);\r
+        wifi_error result = (wifi_error)cmd->start();\r
+        cmd->releaseRef();\r
+        return result;\r
+    } else {\r
+        ALOGE("Driver version buffer NULL");\r
+        return  WIFI_ERROR_INVALID_ARGS;\r
+    }\r
+}\r
+\r
+\r
+///////////////////////////////////////////////////////////////////////////////\r
+class SetLogHandler : public WifiCommand\r
+{\r
+    wifi_ring_buffer_data_handler mHandler;\r
+\r
+public:\r
+    SetLogHandler(wifi_interface_handle iface, int id, wifi_ring_buffer_data_handler handler)\r
+        : WifiCommand(iface, id), mHandler(handler)\r
+    { }\r
+\r
+    int start() {\r
+        ALOGV("Register loghandler");\r
+        registerVendorHandler(GOOGLE_OUI, ENHANCE_LOGGER_RING_EVENT);\r
+        return WIFI_SUCCESS;\r
+    }\r
+\r
+    virtual int cancel() {\r
+        /* Send a command to driver to stop generating logging events */\r
+        ALOGV("Clear loghandler");\r
+\r
+        /* unregister event handler */\r
+        unregisterVendorHandler(GOOGLE_OUI, ENHANCE_LOGGER_RING_EVENT);\r
+\r
+        WifiRequest request(familyId(), ifaceId());\r
+        int result = request.create(GOOGLE_OUI, ENHANCE_LOGGER_RESET_LOGGING);\r
+        if (result != WIFI_SUCCESS) {\r
+            ALOGE("failed to create reset request; result = %d", result);\r
+            return result;\r
+        }\r
+\r
+        result = requestResponse(request);\r
+        if (result != WIFI_SUCCESS) {\r
+            ALOGE("failed to request reset; result = %d", result);\r
+            return result;\r
+        }\r
+\r
+        ALOGD("Success to clear loghandler");\r
+        return WIFI_SUCCESS;\r
+    }\r
+\r
+    virtual int handleEvent(WifiEvent& event) {\r
+        char *buffer = NULL;\r
+        int buffer_size = 0;\r
+\r
+        // ALOGD("In SetLogHandler::handleEvent");\r
+        nlattr *vendor_data = event.get_attribute(NL80211_ATTR_VENDOR_DATA);\r
+        int len = event.get_vendor_data_len();\r
+        int event_id = event.get_vendor_subcmd();\r
+        // ALOGI("Got Logger event: %d", event_id);\r
+\r
+        if (vendor_data == NULL || len == 0) {\r
+            ALOGE("No Debug data found");\r
+            return NL_SKIP;\r
+        }\r
+\r
+        if(event_id == ENHANCE_LOGGER_RING_EVENT) {\r
+            wifi_ring_buffer_status status;\r
+            memset(&status, 0, sizeof(status));\r
+\r
+            for (nl_iterator it(vendor_data); it.has_next(); it.next()) {\r
+                if (it.get_type() == ENHANCE_LOGGER_ATTRIBUTE_RING_STATUS) {\r
+                    memcpy(&status, it.get_data(), sizeof(status));\r
+                } else if (it.get_type() == ENHANCE_LOGGER_ATTRIBUTE_RING_DATA) {\r
+                    buffer_size = it.get_len();\r
+                    buffer = (char *)it.get_data();\r
+                } else {\r
+                    ALOGW("Ignoring invalid attribute type = %d, size = %d",\r
+                            it.get_type(), it.get_len());\r
+                }\r
+            }\r
+\r
+            // ALOGI("Retrieved Debug data");\r
+            if (mHandler.on_ring_buffer_data) {\r
+                (*mHandler.on_ring_buffer_data)((char *)status.name, buffer, buffer_size,\r
+                        &status);\r
+            }\r
+        } else {\r
+            ALOGE("Unknown Event");\r
+            return NL_SKIP;\r
+        }\r
+        return NL_OK;\r
+    }\r
+};\r
+\r
+wifi_error wifi_set_log_handler(wifi_request_id id, wifi_interface_handle iface,\r
+        wifi_ring_buffer_data_handler handler)\r
+{\r
+    wifi_handle handle = getWifiHandle(iface);\r
+    ALOGV("Loghandler start, handle = %p", handle);\r
+\r
+    SetLogHandler *cmd = new SetLogHandler(iface, id, handler);\r
+    NULL_CHECK_RETURN(cmd, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY);\r
+    wifi_error result = wifi_register_cmd(handle, id, cmd);\r
+    if (result != WIFI_SUCCESS) {\r
+        cmd->releaseRef();\r
+        return result;\r
+    }\r
+    result = (wifi_error)cmd->start();\r
+    if (result != WIFI_SUCCESS) {\r
+        wifi_unregister_cmd(handle, id);\r
+        cmd->releaseRef();\r
+        return result;\r
+    }\r
+    return result;\r
+}\r
+\r
+wifi_error wifi_reset_log_handler(wifi_request_id id, wifi_interface_handle iface)\r
+{\r
+    wifi_handle handle = getWifiHandle(iface);\r
+    ALOGV("Loghandler reset, wifi_request_id = %d, handle = %p", id, handle);\r
+\r
+    if (id == -1) {\r
+        wifi_ring_buffer_data_handler handler;\r
+        memset(&handler, 0, sizeof(handler));\r
+\r
+        SetLogHandler *cmd = new SetLogHandler(iface, id, handler);\r
+        NULL_CHECK_RETURN(cmd, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY);\r
+        cmd->cancel();\r
+        cmd->releaseRef();\r
+        return WIFI_SUCCESS;\r
+    }\r
+\r
+    return wifi_cancel_cmd(id, iface);\r
+}\r
+\r
+///////////////////////////////////////////////////////////////////////////////\r
+class SetAlertHandler : public WifiCommand\r
+{\r
+    wifi_alert_handler mHandler;\r
+    int mBuffSize;\r
+    char *mBuff;\r
+    int mErrCode;\r
+\r
+public:\r
+    SetAlertHandler(wifi_interface_handle iface, int id, wifi_alert_handler handler)\r
+        : WifiCommand(iface, id), mHandler(handler), mBuffSize(0), mBuff(NULL),\r
+            mErrCode(0)\r
+    { }\r
+\r
+    int start() {\r
+        ALOGV("Start Alerting");\r
+        registerVendorHandler(GOOGLE_OUI, ENHANCE_LOGGER_MEM_DUMP_EVENT);\r
+        return WIFI_SUCCESS;\r
+    }\r
+\r
+    virtual int cancel() {\r
+        ALOGV("Clear alerthandler");\r
+\r
+        /* unregister alert handler */\r
+        unregisterVendorHandler(GOOGLE_OUI, ENHANCE_LOGGER_MEM_DUMP_EVENT);\r
+        wifi_unregister_cmd(wifiHandle(), id());\r
+        ALOGD("Success to clear alerthandler");\r
+        return WIFI_SUCCESS;\r
+    }\r
+\r
+    virtual int handleResponse(WifiEvent& reply) {\r
+        ALOGD("In SetAlertHandler::handleResponse");\r
+\r
+        if (reply.get_cmd() != NL80211_CMD_VENDOR) {\r
+            ALOGD("Ignoring reply with cmd = %d", reply.get_cmd());\r
+            return NL_SKIP;\r
+        }\r
+\r
+        nlattr *vendor_data = reply.get_attribute(NL80211_ATTR_VENDOR_DATA);\r
+        int len = reply.get_vendor_data_len();\r
+\r
+        ALOGD("len = %d", len);\r
+        if (vendor_data == NULL || len == 0) {\r
+            ALOGE("no vendor data in memory dump response; ignoring it");\r
+            return NL_SKIP;\r
+        }\r
+\r
+        for (nl_iterator it(vendor_data); it.has_next(); it.next()) {\r
+            if (it.get_type() == ENHANCE_LOGGER_ATTRIBUTE_FW_DUMP_DATA) {\r
+                ALOGI("Initiating alert callback");\r
+                if (mHandler.on_alert) {\r
+                    (*mHandler.on_alert)(id(), mBuff, mBuffSize, mErrCode);\r
+                }\r
+                if (mBuff) {\r
+                    free(mBuff);\r
+                    mBuff = NULL;\r
+                }\r
+            }\r
+        }\r
+        return NL_OK;\r
+    }\r
+\r
+    virtual int handleEvent(WifiEvent& event) {\r
+        wifi_ring_buffer_id ring_id;\r
+        char *buffer = NULL;\r
+        int buffer_size = 0;\r
+\r
+\r
+        nlattr *vendor_data = event.get_attribute(NL80211_ATTR_VENDOR_DATA);\r
+        int len = event.get_vendor_data_len();\r
+        int event_id = event.get_vendor_subcmd();\r
+        ALOGI("Got event: %d", event_id);\r
+\r
+        if (vendor_data == NULL || len == 0) {\r
+            ALOGE("No Debug data found");\r
+            return NL_SKIP;\r
+        }\r
+\r
+        if (event_id == ENHANCE_LOGGER_MEM_DUMP_EVENT) {\r
+            for (nl_iterator it(vendor_data); it.has_next(); it.next()) {\r
+                if (it.get_type() == ENHANCE_LOGGER_ATTRIBUTE_FW_DUMP_LEN) {\r
+                    mBuffSize = it.get_u32();\r
+                } else if (it.get_type() == ENHANCE_LOGGER_ATTRIBUTE_RING_DATA) {\r
+                    buffer_size = it.get_len();\r
+                    buffer = (char *)it.get_data();\r
+            /*\r
+                } else if (it.get_type() == ENHANCE_LOGGER_ATTRIBUTE_FW_ERR_CODE) {\r
+                    mErrCode = it.get_u32();\r
+            */\r
+                } else {\r
+                    ALOGW("Ignoring invalid attribute type = %d, size = %d",\r
+                            it.get_type(), it.get_len());\r
+                }\r
+            }\r
+            if (mBuffSize) {\r
+                ALOGD("dump size: %d meta data size: %d", mBuffSize, buffer_size);\r
+                if (mBuff) free(mBuff);\r
+                mBuff = (char *)malloc(mBuffSize + buffer_size);\r
+                if (!mBuff) {\r
+                    ALOGE("Buffer allocation failed");\r
+                    return NL_SKIP;\r
+                }\r
+                memcpy(mBuff, buffer, buffer_size);\r
+\r
+                WifiRequest request(familyId(), ifaceId());\r
+                int result = request.create(GOOGLE_OUI, ENHANCE_LOGGER_MEM_DUMP_EVENT);\r
+                if (result != WIFI_SUCCESS) {\r
+                    ALOGE("Failed to create get memory dump request; result = %d", result);\r
+                    free(mBuff);\r
+                    return NL_SKIP;\r
+                }\r
+                nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA);\r
+                result = request.put_u32(ENHANCE_LOGGER_ATTRIBUTE_FW_DUMP_LEN, mBuffSize);\r
+                if (result != WIFI_SUCCESS) {\r
+                    ALOGE("Failed to put get memory dump request; result = %d", result);\r
+                    return result;\r
+                }\r
+\r
+                result = request.put_u64(ENHANCE_LOGGER_ATTRIBUTE_FW_DUMP_DATA,\r
+                         (uint64_t)(mBuff+buffer_size));\r
+                if (result != WIFI_SUCCESS) {\r
+                    ALOGE("Failed to put get memory dump request; result = %d", result);\r
+                    return result;\r
+                }\r
+\r
+                request.attr_end(data);\r
+                mBuffSize += buffer_size;\r
+\r
+                result = requestResponse(request);\r
+\r
+                if (result != WIFI_SUCCESS) {\r
+                    ALOGE("Failed to register get momory dump response; result = %d", result);\r
+                }\r
+            } else {\r
+                ALOGE("dump event missing dump length attribute");\r
+                return NL_SKIP;\r
+            }\r
+        }\r
+        return NL_OK;\r
+    }\r
+};\r
+\r
+wifi_error wifi_set_alert_handler(wifi_request_id id, wifi_interface_handle iface,\r
+        wifi_alert_handler handler)\r
+{\r
+    wifi_handle handle = getWifiHandle(iface);\r
+    ALOGV("Alerthandler start, handle = %p", handle);\r
+\r
+    SetAlertHandler *cmd = new SetAlertHandler(iface, id, handler);\r
+    NULL_CHECK_RETURN(cmd, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY);\r
+    wifi_error result = wifi_register_cmd(handle, id, cmd);\r
+    if (result != WIFI_SUCCESS) {\r
+        cmd->releaseRef();\r
+        return result;\r
+    }\r
+    result = (wifi_error)cmd->start();\r
+    if (result != WIFI_SUCCESS) {\r
+        wifi_unregister_cmd(handle, id);\r
+        cmd->releaseRef();\r
+        return result;\r
+    }\r
+    return result;\r
+}\r
+\r
+wifi_error wifi_reset_alert_handler(wifi_request_id id, wifi_interface_handle iface)\r
+{\r
+    wifi_handle handle = getWifiHandle(iface);\r
+    ALOGV("Alerthandler reset, wifi_request_id = %d, handle = %p", id, handle);\r
+\r
+    if (id == -1) {\r
+        wifi_alert_handler handler;\r
+        memset(&handler, 0, sizeof(handler));\r
+\r
+        SetAlertHandler *cmd = new SetAlertHandler(iface, id, handler);\r
+        NULL_CHECK_RETURN(cmd, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY);\r
+        cmd->cancel();\r
+        cmd->releaseRef();\r
+        return WIFI_SUCCESS;\r
+    }\r
+\r
+    return wifi_cancel_cmd(id, iface);\r
+}\r
+\r
+\r
+class PacketFateCommand: public WifiCommand\r
+{\r
+    void *mReportBufs;\r
+    size_t mNoReqFates;\r
+    size_t *mNoProvidedFates;\r
+    PktFateReqType mReqType;\r
+\r
+public:\r
+    PacketFateCommand(wifi_interface_handle handle)\r
+        : WifiCommand(handle, 0), mReqType(PACKET_MONITOR_START)\r
+    { }\r
+\r
+    PacketFateCommand(wifi_interface_handle handle, wifi_tx_report *tx_report_bufs,\r
+            size_t n_requested_fates, size_t *n_provided_fates)\r
+        : WifiCommand(handle, 0), mReportBufs(tx_report_bufs),\r
+                  mNoReqFates(n_requested_fates), mNoProvidedFates(n_provided_fates),\r
+                  mReqType(TX_PACKET_FATE)\r
+    { }\r
+\r
+    PacketFateCommand(wifi_interface_handle handle, wifi_rx_report *rx_report_bufs,\r
+            size_t n_requested_fates, size_t *n_provided_fates)\r
+        : WifiCommand(handle, 0), mReportBufs(rx_report_bufs),\r
+                  mNoReqFates(n_requested_fates), mNoProvidedFates(n_provided_fates),\r
+                  mReqType(RX_PACKET_FATE)\r
+    { }\r
+\r
+    int createRequest(WifiRequest& request) {\r
+        if (mReqType == TX_PACKET_FATE) {\r
+            ALOGD("%s Get Tx packet fate request\n", __FUNCTION__);\r
+            return createTxPktFateRequest(request);\r
+        } else if (mReqType == RX_PACKET_FATE) {\r
+            ALOGD("%s Get Rx packet fate request\n", __FUNCTION__);\r
+            return createRxPktFateRequest(request);\r
+        } else if (mReqType == PACKET_MONITOR_START) {\r
+            ALOGD("%s Monitor packet fate request\n", __FUNCTION__);\r
+            return createMonitorPktFateRequest(request);\r
+        } else {\r
+            ALOGE("%s Unknown packet fate request\n", __FUNCTION__);\r
+            return WIFI_ERROR_NOT_SUPPORTED;\r
+        }\r
+        return WIFI_SUCCESS;\r
+    }\r
+\r
+    int createMonitorPktFateRequest(WifiRequest& request) {\r
+        int result = request.create(GOOGLE_OUI, ENHANCE_LOGGER_START_PKT_FATE_MONITORING);\r
+        if (result < 0) {\r
+            return result;\r
+        }\r
+\r
+        nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA);\r
+        request.attr_end(data);\r
+        return result;\r
+    }\r
+\r
+    int createTxPktFateRequest(WifiRequest& request) {\r
+        int result = request.create(GOOGLE_OUI, ENHANCE_LOGGER_GET_TX_PKT_FATES);\r
+        if (result < 0) {\r
+            return result;\r
+        }\r
+\r
+        memset(mReportBufs, 0, (mNoReqFates * sizeof(wifi_tx_report)));\r
+        nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA);\r
+        result = request.put_u32(ENHANCE_LOGGER_ATTRIBUTE_PKT_FATE_NUM, mNoReqFates);\r
+        if (result < 0) {\r
+            return result;\r
+        }\r
+        result = request.put_u64(ENHANCE_LOGGER_ATTRIBUTE_PKT_FATE_DATA, (uint64_t)mReportBufs);\r
+        if (result < 0) {\r
+            return result;\r
+        }\r
+        request.attr_end(data);\r
+        return result;\r
+    }\r
+\r
+    int createRxPktFateRequest(WifiRequest& request) {\r
+        int result = request.create(GOOGLE_OUI, ENHANCE_LOGGER_GET_RX_PKT_FATES);\r
+        if (result < 0) {\r
+            return result;\r
+        }\r
+\r
+        memset(mReportBufs, 0, (mNoReqFates * sizeof(wifi_rx_report)));\r
+        nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA);\r
+        result = request.put_u32(ENHANCE_LOGGER_ATTRIBUTE_PKT_FATE_NUM, mNoReqFates);\r
+        if (result < 0) {\r
+            return result;\r
+        }\r
+        result = request.put_u64(ENHANCE_LOGGER_ATTRIBUTE_PKT_FATE_DATA, (uint64_t)mReportBufs);\r
+        if (result < 0) {\r
+            return result;\r
+        }\r
+        request.attr_end(data);\r
+        return result;\r
+    }\r
+\r
+    int start() {\r
+        ALOGD("Start get packet fate command\n");\r
+        WifiRequest request(familyId(), ifaceId());\r
+\r
+        int result = createRequest(request);\r
+        if (result < 0) {\r
+            ALOGE("Failed to create get pkt fate request; result = %d\n", result);\r
+            return result;\r
+        }\r
+\r
+        result = requestResponse(request);\r
+        if (result != WIFI_SUCCESS) {\r
+            ALOGE("Failed to register get pkt fate response; result = %d\n", result);\r
+        }\r
+        return result;\r
+    }\r
+\r
+    int handleResponse(WifiEvent& reply) {\r
+        ALOGD("In GetPktFateCommand::handleResponse\n");\r
+\r
+        if (reply.get_cmd() != NL80211_CMD_VENDOR) {\r
+            ALOGI("Ignoring reply with cmd = %d", reply.get_cmd());\r
+            return NL_SKIP;\r
+        }\r
+\r
+        int id = reply.get_vendor_id();\r
+        int subcmd = reply.get_vendor_subcmd();\r
+        nlattr *vendor_data = reply.get_attribute(NL80211_ATTR_VENDOR_DATA);\r
+        int len = reply.get_vendor_data_len();\r
+\r
+        ALOGI("Id = %0x, subcmd = %d, len = %d", id, subcmd, len);\r
+\r
+        if (mReqType == TX_PACKET_FATE) {\r
+            ALOGI("Response recieved for get TX pkt fate command\n");\r
+        } else if (mReqType == RX_PACKET_FATE) {\r
+            ALOGI("Response recieved for get RX pkt fate command\n");\r
+        } else if (mReqType == PACKET_MONITOR_START) {\r
+            ALOGI("Response recieved for monitor pkt fate command\n");\r
+            return NL_OK;\r
+        } else {\r
+            ALOGE("Response recieved for unknown pkt fate command\n");\r
+            return NL_SKIP;\r
+        }\r
+\r
+        if (vendor_data == NULL || len == 0) {\r
+            ALOGE("no vendor data in GetPktFateCommand response; ignoring it\n");\r
+            return NL_SKIP;\r
+        }\r
+\r
+        for (nl_iterator it(vendor_data); it.has_next(); it.next()) {\r
+            if (it.get_type() == ENHANCE_LOGGER_ATTRIBUTE_PKT_FATE_NUM) {\r
+                *mNoProvidedFates = it.get_u32();\r
+                ALOGI("No: of pkt fates provided is %d\n", *mNoProvidedFates);\r
+            } else {\r
+                ALOGE("Ignoring invalid attribute type = %d, size = %d\n",\r
+                        it.get_type(), it.get_len());\r
+            }\r
+        }\r
+\r
+        return NL_OK;\r
+    }\r
+\r
+    int handleEvent(WifiEvent& event) {\r
+        /* NO events to handle here! */\r
+        return NL_SKIP;\r
+    }\r
+};\r
+\r
+wifi_error wifi_start_pkt_fate_monitoring(wifi_interface_handle handle)\r
+{\r
+    PacketFateCommand *cmd = new PacketFateCommand(handle);\r
+    NULL_CHECK_RETURN(cmd, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY);\r
+    wifi_error result = (wifi_error)cmd->start();\r
+    cmd->releaseRef();\r
+    return result;\r
+}\r
+\r
+wifi_error wifi_get_tx_pkt_fates(wifi_interface_handle handle,\r
+        wifi_tx_report *tx_report_bufs, size_t n_requested_fates,\r
+        size_t *n_provided_fates)\r
+{\r
+    PacketFateCommand *cmd = new PacketFateCommand(handle, tx_report_bufs,\r
+                n_requested_fates, n_provided_fates);\r
+    NULL_CHECK_RETURN(cmd, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY);\r
+    wifi_error result = (wifi_error)cmd->start();\r
+    cmd->releaseRef();\r
+    return result;\r
+}\r
+\r
+wifi_error wifi_get_rx_pkt_fates(wifi_interface_handle handle,\r
+        wifi_rx_report *rx_report_bufs, size_t n_requested_fates,\r
+        size_t *n_provided_fates)\r
+{\r
+    PacketFateCommand *cmd = new PacketFateCommand(handle, rx_report_bufs,\r
+                n_requested_fates, n_provided_fates);\r
+    NULL_CHECK_RETURN(cmd, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY);\r
+    wifi_error result = (wifi_error)cmd->start();\r
+    cmd->releaseRef();\r
+    return result;\r
+}\r
+\r
+class MemoryDumpCommand: public WifiCommand\r
+{\r
+    wifi_firmware_memory_dump_handler mHandler;\r
+    wifi_driver_memory_dump_callbacks mcallback;\r
+    int mBuffSize;\r
+    char *mBuff;\r
+    GetCmdType mType;\r
+\r
+public:\r
+    MemoryDumpCommand(wifi_interface_handle iface, wifi_firmware_memory_dump_handler handler, GetCmdType cmdtype )\r
+        : WifiCommand(iface, 0), mHandler(handler), mBuffSize(0), mBuff(NULL), mType(cmdtype)\r
+    { }\r
+\r
+    MemoryDumpCommand(wifi_interface_handle iface, wifi_driver_memory_dump_callbacks callback, GetCmdType cmdtype)\r
+        : WifiCommand(iface, 0), mcallback(callback), mBuffSize(0), mBuff(NULL), mType(cmdtype)\r
+    { }\r
+\r
+     int createRequest(WifiRequest &request) {\r
+        int result;\r
+\r
+        switch (mType) {\r
+                case GET_FW_DUMP:\r
+                    {\r
+                        result = request.create(GOOGLE_OUI, ENHANCE_LOGGER_TRIGGER_FW_MEM_DUMP);\r
+                        if (result != WIFI_SUCCESS) {\r
+                                 ALOGE("Failed to create trigger fw memory dump request; result = %d", result);\r
+                                 return result;\r
+                        }\r
+                        break;\r
+                    }\r
+                case GET_DRIVER_DUMP :\r
+                    {\r
+                        result = request.create(GOOGLE_OUI, ENHANCE_LOGGER_TRIGGER_DRIVER_MEM_DUMP);\r
+                        if (result != WIFI_SUCCESS) {\r
+                                ALOGE("Failed to create trigger driver memory dump request; result = %d", result);\r
+                                return result;\r
+                         }\r
+                        break;\r
+                      }\r
+                 default:\r
+                         ALOGE("Unknown Debug command");\r
+                         result = WIFI_ERROR_UNKNOWN;\r
+                     }\r
+        return result;\r
+     }\r
+    int start() {\r
+        ALOGD("Start memory dump command");\r
+        WifiRequest request(familyId(), ifaceId());\r
+\r
+        int result = createRequest(request);\r
+        if (result != WIFI_SUCCESS) {\r
+            ALOGE("Failed to create trigger memory dump request; result = %d", result);\r
+            return result;\r
+        }\r
+\r
+        result = requestResponse(request);\r
+        if (result != WIFI_SUCCESS) {\r
+            ALOGE("Failed to register trigger memory dump response; result = %d", result);\r
+        }\r
+        return result;\r
+    }\r
+\r
+    virtual int handleResponse(WifiEvent& reply) {\r
+        ALOGD("In MemoryDumpCommand::handleResponse");\r
+\r
+        if (reply.get_cmd() != NL80211_CMD_VENDOR) {\r
+            ALOGD("Ignoring reply with cmd = %d", reply.get_cmd());\r
+            return NL_SKIP;\r
+        }\r
+\r
+        nlattr *vendor_data = reply.get_attribute(NL80211_ATTR_VENDOR_DATA);\r
+        int len = reply.get_vendor_data_len();\r
+\r
+        ALOGD("len = %d", len);\r
+        if (vendor_data == NULL || len == 0) {\r
+            ALOGE("no vendor data in memory dump response; ignoring it");\r
+            return NL_SKIP;\r
+        }\r
+        switch(mType) {\r
+            case GET_FW_DUMP:\r
+                 for (nl_iterator it(vendor_data); it.has_next(); it.next()) {\r
+                     if (it.get_type() == ENHANCE_LOGGER_ATTRIBUTE_FW_DUMP_LEN) {\r
+                         mBuffSize = it.get_u32();\r
+                         if (mBuff)\r
+                             free(mBuff);\r
+                         mBuff = (char *)malloc(mBuffSize);\r
+                         if (!mBuff) {\r
+                             ALOGE("Buffer allocation failed");\r
+                             return NL_SKIP;\r
+                         }\r
+                         WifiRequest request(familyId(), ifaceId());\r
+                         int result = request.create(GOOGLE_OUI, ENHANCE_LOGGER_GET_FW_MEM_DUMP);\r
+                         if (result != WIFI_SUCCESS) {\r
+                             ALOGE("Failed to create get fw memory dump request; result = %d", result);\r
+                             free(mBuff);\r
+                             return NL_SKIP;\r
+                          }\r
+                          nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA);\r
+                          result = request.put_u32(ENHANCE_LOGGER_ATTRIBUTE_FW_DUMP_LEN, mBuffSize);\r
+                          if (result != WIFI_SUCCESS) {\r
+                              ALOGE("Failed to put get fw memory dump request; result = %d", result);\r
+                              return result;\r
+                          }\r
+                          result = request.put_u64(ENHANCE_LOGGER_ATTRIBUTE_FW_DUMP_DATA, (uint64_t)mBuff);\r
+                          if (result != WIFI_SUCCESS) {\r
+                              ALOGE("Failed to put get fw memory dump request; result = %d", result);\r
+                              return result;\r
+                          }\r
+                          request.attr_end(data);\r
+                          result = requestResponse(request);\r
+                          if (result != WIFI_SUCCESS) {\r
+                              ALOGE("Failed to register get fw momory dump response; result = %d", result);\r
+                          }\r
+                     } else if (it.get_type() == ENHANCE_LOGGER_ATTRIBUTE_FW_DUMP_DATA) {\r
+                          ALOGI("Initiating memory dump callback");\r
+                          if (mHandler.on_firmware_memory_dump) {\r
+                              (*mHandler.on_firmware_memory_dump)(mBuff, mBuffSize);\r
+                          }\r
+                          if (mBuff) {\r
+                              free(mBuff);\r
+                              mBuff = NULL;\r
+                          }\r
+                    } else {\r
+                           ALOGW("Ignoring invalid attribute type = %d, size = %d",\r
+                           it.get_type(), it.get_len());\r
+                     }\r
+                 }\r
+            case GET_DRIVER_DUMP :\r
+                 for (nl_iterator it(vendor_data); it.has_next(); it.next()) {\r
+                     if (it.get_type() == ENHANCE_LOGGER_ATTRIBUTE_DRIVER_DUMP_LEN) {\r
+                         mBuffSize = it.get_u32();\r
+                         if (mBuff)\r
+                             free(mBuff);\r
+                         mBuff = (char *)malloc(mBuffSize);\r
+                         if (!mBuff) {\r
+                             ALOGE("Buffer allocation failed");\r
+                             return NL_SKIP;\r
+                         }\r
+                         WifiRequest request(familyId(), ifaceId());\r
+                         int result = request.create(GOOGLE_OUI, ENHANCE_LOGGER_GET_DRIVER_MEM_DUMP);\r
+                         if (result != WIFI_SUCCESS) {\r
+                             ALOGE("Failed to create get driver memory dump request; result = %d", result);\r
+                             free(mBuff);\r
+                             return NL_SKIP;\r
+                          }\r
+                          nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA);\r
+                          result = request.put_u32(ENHANCE_LOGGER_ATTRIBUTE_DRIVER_DUMP_LEN, mBuffSize);\r
+                          if (result != WIFI_SUCCESS) {\r
+                              ALOGE("Failed to put get driver memory dump request; result = %d", result);\r
+                              return result;\r
+                          }\r
+                          result = request.put_u64(ENHANCE_LOGGER_ATTRIBUTE_DRIVER_DUMP_DATA, (uint64_t)mBuff);\r
+                          if (result != WIFI_SUCCESS) {\r
+                              ALOGE("Failed to put get driver memory dump request; result = %d", result);\r
+                              return result;\r
+                          }\r
+                          request.attr_end(data);\r
+                          result = requestResponse(request);\r
+                          if (result != WIFI_SUCCESS) {\r
+                              ALOGE("Failed to register get driver momory dump response; result = %d", result);\r
+                          }\r
+                     } else if (it.get_type() == ENHANCE_LOGGER_ATTRIBUTE_DRIVER_DUMP_DATA) {\r
+                          ALOGI("Initiating memory dump callback");\r
+                          if (mcallback.on_driver_memory_dump) {\r
+                              (*mcallback.on_driver_memory_dump)(mBuff, mBuffSize);\r
+                          }\r
+                          if (mBuff) {\r
+                              free(mBuff);\r
+                              mBuff = NULL;\r
+                          }\r
+                    } else {\r
+                           ALOGW("Ignoring invalid attribute type = %d, size = %d",\r
+                           it.get_type(), it.get_len());\r
+                     }\r
+                 }\r
+            }\r
+        return NL_OK;\r
+    }\r
+\r
+    virtual int handleEvent(WifiEvent& event) {\r
+        /* NO events! */\r
+        return NL_SKIP;\r
+    }\r
+};\r
+\r
+/* API to collect a firmware memory dump for a given iface */\r
+wifi_error wifi_get_firmware_memory_dump( wifi_interface_handle iface,\r
+        wifi_firmware_memory_dump_handler handler)\r
+{\r
+    MemoryDumpCommand *cmd = new MemoryDumpCommand(iface, handler, GET_FW_DUMP);\r
+    NULL_CHECK_RETURN(cmd, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY);\r
+    wifi_error result = (wifi_error)cmd->start();\r
+    cmd->releaseRef();\r
+    return result;\r
+}\r
+\r
+wifi_error wifi_get_driver_memory_dump(wifi_interface_handle iface,\r
+                                wifi_driver_memory_dump_callbacks callbacks)\r
+{\r
+    MemoryDumpCommand *cmd = new MemoryDumpCommand(iface, callbacks, GET_DRIVER_DUMP);\r
+    NULL_CHECK_RETURN(cmd, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY);\r
+    wifi_error result = (wifi_error)cmd->start();\r
+    cmd->releaseRef();\r
+    return result;\r
+}\r
+class WifiLoggerCommand: public WifiCommand\r
+{\r
+     WLAN_DRIVER_WAKE_REASON_CNT *mGetWakeStats;\r
+\r
+public:\r
+    WifiLoggerCommand(wifi_interface_handle handle, WLAN_DRIVER_WAKE_REASON_CNT *wifi_wake_reason_cnt)\r
+        : WifiCommand(handle, 0), mGetWakeStats(wifi_wake_reason_cnt)\r
+    { }\r
+\r
+    int createRequest(WifiRequest& request) {\r
+        int result = request.create(GOOGLE_OUI, ENHANCE_LOGGER_GET_WAKE_REASON_STATS);\r
+        if (result < 0) {\r
+            return result;\r
+        }\r
+\r
+        nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA);\r
+\r
+        result = request.put_u32(ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_CMD_EVENT_WAKE_CNT_SZ, mGetWakeStats->cmd_event_wake_cnt_sz);\r
+        if (result != WIFI_SUCCESS) {\r
+            ALOGE("Failed to put wake_cnt_sz; result = %d", result);\r
+            return result;\r
+        }\r
+        result = request.put_u32(ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_DRIVER_FW_LOCAL_WAKE_CNT_SZ, mGetWakeStats->driver_fw_local_wake_cnt_sz);\r
+        if (result != WIFI_SUCCESS) {\r
+            ALOGE("Failed to put driver_fw_local_wake_cnt; result = %d", result);\r
+            return result;\r
+        }\r
+        request.attr_end(data);\r
+        return result;\r
+    }\r
+\r
+    int start() {\r
+        ALOGD("Start get wake reason stats command\n");\r
+        WifiRequest request(familyId(), ifaceId());\r
+        int result = createRequest(request);\r
+        if (result < 0) {\r
+                 ALOGE("Failed to create get wake reason stats request; result = %d\n", result);\r
+                 return result;\r
+        }\r
+        result = requestResponse(request);\r
+        if (result != WIFI_SUCCESS) {\r
+                ALOGE("Failed to register get wake reason stats response; result = %d\n", result);\r
+        }\r
+        return result;\r
+    }\r
+\r
+    int handleResponse(WifiEvent& reply) {\r
+         int len = 0;\r
+         ALOGD("In WifiLoggerCommand::handleResponse\n");\r
+\r
+         if (reply.get_cmd() != NL80211_CMD_VENDOR) {\r
+             ALOGI("Ignoring reply with cmd = %d", reply.get_cmd());\r
+             return NL_SKIP;\r
+        }\r
+        nlattr *vendor_data = reply.get_attribute(NL80211_ATTR_VENDOR_DATA);\r
+        len = reply.get_vendor_data_len();\r
+        if (vendor_data == NULL || len == 0) {\r
+            ALOGE("No Debug data found");\r
+            return NL_SKIP;\r
+       }\r
+       nl_iterator it(vendor_data);\r
+\r
+       if (it.get_type() != ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_TOTAL_CMD_EVENT_WAKE) {\r
+            ALOGE("TOTAL_CMD_EVENT_WAKE not found %d", it.get_type());\r
+            return NL_SKIP;\r
+       }\r
+\r
+       mGetWakeStats->total_cmd_event_wake = it.get_u32();\r
+       it.next();\r
+\r
+       if(mGetWakeStats->total_cmd_event_wake && mGetWakeStats->cmd_event_wake_cnt) {\r
+            if (it.get_type() != ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_CMD_EVENT_WAKE_CNT_PTR) {\r
+                 ALOGE("CMD_EVENT_WAKE_CNT_PTR not found %d", it.get_type());\r
+                 return NL_SKIP;\r
+            }\r
+\r
+            len = it.get_len();\r
+            mGetWakeStats->cmd_event_wake_cnt_used = (len < mGetWakeStats->cmd_event_wake_cnt_sz) ? len : mGetWakeStats->cmd_event_wake_cnt_sz;\r
+            memcpy(mGetWakeStats->cmd_event_wake_cnt, it.get_data(), mGetWakeStats->cmd_event_wake_cnt_used * sizeof(int));\r
+       } else {\r
+            mGetWakeStats->cmd_event_wake_cnt_used = 0;\r
+       }\r
+\r
+       it.next();\r
+\r
+       if (it.get_type() != ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_TOTAL_DRIVER_FW_LOCAL_WAKE) {\r
+            ALOGE("TOTAL_DRIVER_FW_LOCAL_WAKE not found %d", it.get_type());\r
+            return NL_SKIP;\r
+       }\r
+\r
+       mGetWakeStats->total_driver_fw_local_wake = it.get_u32();\r
+       it.next();\r
+\r
+       if(mGetWakeStats->total_driver_fw_local_wake && mGetWakeStats->driver_fw_local_wake_cnt) {\r
+            if (it.get_type() != ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_DRIVER_FW_LOCAL_WAKE_CNT_PTR) {\r
+                 ALOGE("DRIVER_FW_LOCAL_WAKE_CNT_PTR not found %d", it.get_type());\r
+                 return NL_SKIP;\r
+            }\r
+\r
+            len = it.get_len();\r
+            mGetWakeStats->driver_fw_local_wake_cnt_used= (len < mGetWakeStats->driver_fw_local_wake_cnt_sz) ? len : mGetWakeStats->driver_fw_local_wake_cnt_sz;\r
+            memcpy(mGetWakeStats->driver_fw_local_wake_cnt, it.get_data(), mGetWakeStats->driver_fw_local_wake_cnt_used * sizeof(int));\r
+       } else {\r
+            mGetWakeStats->driver_fw_local_wake_cnt_used= 0;\r
+       }\r
+\r
+       it.next();\r
+\r
+       if (it.get_type() != ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_TOTAL_RX_DATA_WAKE) {\r
+            ALOGE("TOTAL_RX_DATA_WAKE not found %d", it.get_type());\r
+            return NL_SKIP;\r
+       }\r
+\r
+       mGetWakeStats->total_rx_data_wake = it.get_u32();\r
+       it.next();\r
+\r
+       if (it.get_type() != ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_RX_UNICAST_CNT) {\r
+            ALOGE("RX_UNICAST_CNT not found %d", it.get_type());\r
+            return NL_SKIP;\r
+       }\r
+\r
+       mGetWakeStats->rx_wake_details.rx_unicast_cnt = it.get_u32();\r
+       it.next();\r
+\r
+       if (it.get_type() != ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_RX_MULTICAST_CNT) {\r
+            ALOGE("RX_MULTICAST_CNT not found %d", it.get_type());\r
+            return NL_SKIP;\r
+       }\r
+\r
+       mGetWakeStats->rx_wake_details.rx_multicast_cnt = it.get_u32();\r
+       it.next();\r
+\r
+       if (it.get_type() != ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_RX_BROADCAST_CNT) {\r
+            ALOGE("RX_BROADCAST_CNT not found %d", it.get_type());\r
+            return NL_SKIP;\r
+       }\r
+\r
+       mGetWakeStats->rx_wake_details.rx_broadcast_cnt = it.get_u32();\r
+       it.next();\r
+\r
+       if (it.get_type() != ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_ICMP_PKT) {\r
+            ALOGE("ICMP_PKT not found %d", it.get_type());\r
+            return NL_SKIP;\r
+       }\r
+\r
+       mGetWakeStats->rx_wake_pkt_classification_info .icmp_pkt = it.get_u32();\r
+       it.next();\r
+\r
+       if (it.get_type() != ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_ICMP6_PKT) {\r
+            ALOGE("ICMP6_PKT not found %d", it.get_type());\r
+            return NL_SKIP;\r
+       }\r
+\r
+       mGetWakeStats->rx_wake_pkt_classification_info .icmp6_pkt = it.get_u32();\r
+       it.next();\r
+\r
+       if (it.get_type() != ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_ICMP6_RA) {\r
+            ALOGE("ICMP6_RA not found %d", it.get_type());\r
+            return NL_SKIP;\r
+       }\r
+\r
+       mGetWakeStats->rx_wake_pkt_classification_info .icmp6_ra = it.get_u32();\r
+       it.next();\r
+\r
+       if (it.get_type() != ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_ICMP6_NA) {\r
+            ALOGE("ICMP6_NA not found %d", it.get_type());\r
+            return NL_SKIP;\r
+       }\r
+\r
+       mGetWakeStats->rx_wake_pkt_classification_info .icmp6_na = it.get_u32();\r
+       it.next();\r
+\r
+       if (it.get_type() != ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_ICMP6_NS) {\r
+            ALOGE("ICMP6_NS not found %d", it.get_type());\r
+            return NL_SKIP;\r
+       }\r
+\r
+       mGetWakeStats->rx_wake_pkt_classification_info .icmp6_ns = it.get_u32();\r
+       it.next();\r
+\r
+       if (it.get_type() != ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_ICMP4_RX_MULTICAST_CNT) {\r
+            ALOGE("ICMP4_RX_MULTICAST_CNT not found %d", it.get_type());\r
+            return NL_SKIP;\r
+       }\r
+\r
+       mGetWakeStats->rx_multicast_wake_pkt_info.ipv4_rx_multicast_addr_cnt = it.get_u32();\r
+       it.next();\r
+\r
+       if (it.get_type() != ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_ICMP6_RX_MULTICAST_CNT) {\r
+            ALOGE("ICMP6_RX_MULTICAST_CNT not found %d", it.get_type());\r
+            return NL_SKIP;\r
+       }\r
+\r
+       mGetWakeStats->rx_multicast_wake_pkt_info.ipv6_rx_multicast_addr_cnt = it.get_u32();\r
+       it.next();\r
+\r
+       if (it.get_type() != ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_OTHER_RX_MULTICAST_CNT) {\r
+            ALOGE("OTHER_RX_MULTICAST_CNT not found %d", it.get_type());\r
+            return NL_SKIP;\r
+       }\r
+\r
+       mGetWakeStats->rx_multicast_wake_pkt_info.other_rx_multicast_addr_cnt = it.get_u32();\r
+\r
+       return NL_OK;\r
+    }\r
+\r
+    int handleEvent(WifiEvent& event) {\r
+        /* NO events to handle here! */\r
+        return NL_SKIP;\r
+    }\r
+};\r
+\r
+ /* Function to get wake lock stats */\r
+wifi_error wifi_get_wake_reason_stats(wifi_interface_handle iface,\r
+                             WLAN_DRIVER_WAKE_REASON_CNT *wifi_wake_reason_cnt)\r
+{\r
+    if(wifi_wake_reason_cnt) {\r
+        WifiLoggerCommand *cmd =  new WifiLoggerCommand(iface,wifi_wake_reason_cnt);\r
+        NULL_CHECK_RETURN(cmd, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY);\r
+        wifi_error result = (wifi_error)cmd->start();\r
+        cmd->releaseRef();\r
+        return result;\r
+    } else {\r
+        ALOGE("Reason cnt NULL");\r
+        return  WIFI_ERROR_INVALID_ARGS;\r
+    }\r
+}\r
+\r