[APR-2987]wlbt: NAN transaction Id
[GitHub/LineageOS/android_hardware_samsung_slsi_scsc_wifibt_wifi_hal.git] / link_layer_stats.cpp
index 64218e96c7c2773b5922591945eed8e40020c60c..bfdeac8c86621610ed05564c8acd2698d94a3f30 100755 (executable)
@@ -17,8 +17,6 @@
 
 #include "sync.h"
 
-#define LOG_TAG  "WifiHAL"
-
 #include <utils/Log.h>
 
 #include "wifi_hal.h"
@@ -46,13 +44,21 @@ class LinkLayerStatsCommand : public WifiCommand
 public:
     LinkLayerStatsCommand(wifi_interface_handle handle, wifi_link_layer_params params)
         : WifiCommand(handle, 0), mParams(params)
-    { }
+    {
+        mStatsClearReqMask = 0;
+        mStatsClearRspMask = 0;
+        mStopReq = 0 ;
+        mStopRsp = NULL;
+
+    }
 
     LinkLayerStatsCommand(wifi_interface_handle handle,
         u32 stats_clear_req_mask, u32 *stats_clear_rsp_mask, u8 stop_req, u8 *stop_rsp)
         : WifiCommand(handle, 0), mStatsClearReqMask(stats_clear_req_mask), mStatsClearRspMask(stats_clear_rsp_mask),
         mStopReq(stop_req), mStopRsp(stop_rsp)
-    { }
+    {
+        memset(&mParams,0,sizeof(wifi_link_layer_params));
+    }
 
     int createSetRequest(WifiRequest& request) {
         int result = request.create(GOOGLE_OUI, SLSI_NL80211_VENDOR_SUBCMD_LLS_SET_INFO);
@@ -110,7 +116,6 @@ public:
             return result;
         }
 
-        ALOGD("Successfully set Link Layer Statistics measurement");
         return result;
     }
 
@@ -129,7 +134,6 @@ public:
             return result;
         }
 
-        ALOGD("Successfully clear Link Layer Statistics measurement");
         return result;
     }
 
@@ -145,7 +149,7 @@ wifi_error wifi_set_link_stats(wifi_interface_handle iface, wifi_link_layer_para
     LinkLayerStatsCommand *command = new LinkLayerStatsCommand(iface, params);
     wifi_error result = (wifi_error)command->start();
     if (result != WIFI_SUCCESS) {
-        ALOGE("failed to Set link layer stats", result);
+        ALOGE("failed to Set link layer stats (result:%d)", result);
     }
     return result;
 }
@@ -156,7 +160,7 @@ wifi_error wifi_clear_link_stats(wifi_interface_handle iface,
     LinkLayerStatsCommand *command = new LinkLayerStatsCommand(iface, stats_clear_req_mask, stats_clear_rsp_mask, stop_req, stop_rsp);
     wifi_error result = (wifi_error)command->clear();
     if (result != WIFI_SUCCESS) {
-        ALOGE("failed to Clear link layer stats", result);
+        ALOGE("failed to Clear link layer stats (result:%d)", result);
         *stats_clear_rsp_mask = 0;
         *stop_rsp = 0;
     } else {
@@ -179,8 +183,6 @@ public:
     }
 
     virtual int create() {
-        ALOGI("Creating message to get link statistics");
-
         int ret = mMsg.create(GOOGLE_OUI, SLSI_NL80211_VENDOR_SUBCMD_LLS_GET_INFO);
         if (ret < 0) {
             ALOGE("Failed to create %x - %d", SLSI_NL80211_VENDOR_SUBCMD_LLS_GET_INFO, ret);
@@ -192,29 +194,30 @@ public:
 
 protected:
     virtual int handleResponse(WifiEvent& reply) {
-
-        ALOGI("In GetLinkStatsCommand::handleResponse");
-
         if (reply.get_cmd() != NL80211_CMD_VENDOR) {
             ALOGD("Ignoring reply with cmd = %d", reply.get_cmd());
             return NL_SKIP;
         }
-
         int id = reply.get_vendor_id();
-        int subcmd = reply.get_vendor_subcmd();
-
-        ALOGI("Id = %0x, subcmd = %d", id, subcmd);
-
         u8 *data = (u8 *)reply.get_vendor_data();
-        int len = reply.get_vendor_data_len();
+        int num_radios = 0, i = 0;
+        num_radios = data[0];
+        data += sizeof(data[0]);
 
         // assuming max peers is 16
         wifi_iface_stat *iface_stat = (wifi_iface_stat *) malloc(sizeof(wifi_iface_stat) + sizeof(wifi_peer_info) * 16);
-        // max channel is 38 (14 2.4GHz and 24 5GHz)
-        wifi_radio_stat *radio_stat = (wifi_radio_stat *) malloc(sizeof(wifi_radio_stat) + sizeof(wifi_channel_stat) * 38);
+        if (!iface_stat) {
+            ALOGE("Memory alloc failed for iface_stat in response handler!!!");
+            return NL_SKIP;
+        }
 
-        if (!iface_stat || !radio_stat) {
-            ALOGE("Memory alloc failed in response handler!!!");
+        // max channel is 39 (14 2.4GHz and 25 5GHz)
+        wifi_radio_stat *radio_stat = (wifi_radio_stat *) malloc((num_radios * sizeof(wifi_radio_stat)) + sizeof(wifi_channel_stat) * 39);
+        wifi_radio_stat *radio_stat2;
+        radio_stat2 = radio_stat;
+        if (!radio_stat) {
+            ALOGE("Memory alloc failed for radio_stat in response handler!!!");
+            free(iface_stat);
             return NL_SKIP;
         }
 
@@ -241,15 +244,20 @@ protected:
             memcpy(iface_stat->peer_info, data, sizeof(wifi_peer_info) * iface_stat->num_peers);
             data += sizeof(wifi_peer_info) * iface_stat->num_peers;
         }
-        memcpy(radio_stat, data, radio_data_len1);
-        data += radio_data_len1;
-        memcpy(&radio_stat->rx_time, data, radio_data_len2);
-        data += radio_data_len2;
-        memcpy(radio_stat->channels, data, sizeof(wifi_channel_stat)* radio_stat->num_channels);
-        radio_stat->num_tx_levels = 0;
-        radio_stat->tx_time_per_levels = NULL;
+        for (i = 0; i < num_radios; i++) {
+            memcpy(radio_stat2, data, radio_data_len1);
+            data += radio_data_len1;
+            memcpy(&radio_stat2->rx_time, data, radio_data_len2);
+            data += radio_data_len2;
+            memcpy(radio_stat2->channels, data, sizeof(wifi_channel_stat)* radio_stat2->num_channels);
+            radio_stat2->num_tx_levels = 0;
+            radio_stat2->tx_time_per_levels = NULL;
+            data += sizeof(wifi_channel_stat)* radio_stat2->num_channels;
+            radio_stat2=(wifi_radio_stat *) ((u8 *)radio_stat2+ sizeof(wifi_radio_stat) +
+                        (sizeof(wifi_channel_stat) * radio_stat2->num_channels ));
+        }
         iface_stat->iface = iface;
-        (*mHandler.on_link_stats_results)(id, iface_stat, 1, radio_stat);
+        (*mHandler.on_link_stats_results)(id, iface_stat, num_radios, radio_stat);
         free(iface_stat);
         free(radio_stat);
         return NL_OK;