[9610][7872][7570][7885] wlbt: Reduce gscan logGing
[GitHub/LineageOS/android_hardware_samsung_slsi_scsc_wifibt_wifi_hal.git] / wifi_hal.cpp
index 0371481fd462ddf0f76ceb76788b884624b8ef61..937a6e0f1ce2d6630c362a72b281aa9ddad6948e 100755 (executable)
@@ -1,5 +1,6 @@
 #include <errno.h>
 #include <stdint.h>
+#include <string.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netlink/genl/genl.h>
@@ -37,6 +38,7 @@
 #define FEATURE_SET                  0
 #define FEATURE_SET_MATRIX           1
 #define ATTR_NODFS_VALUE             3
+#define ATTR_COUNTRY_CODE            4
 
 static void internal_event_handler(wifi_handle handle, int events);
 static int internal_no_seq_check(nl_msg *msg, void *arg);
@@ -71,7 +73,6 @@ void wifi_socket_set_local_port(struct nl_sock *sock, uint32_t port)
 
 static nl_sock * wifi_create_nl_socket(int port)
 {
-     ALOGI("Creating socket");
     struct nl_sock *sock = nl_socket_alloc();
     if (sock == NULL) {
         ALOGE("Could not create handle");
@@ -80,7 +81,6 @@ static nl_sock * wifi_create_nl_socket(int port)
 
     wifi_socket_set_local_port(sock, port);
 
-    ALOGI("Connecting socket");
     if (nl_connect(sock, NETLINK_GENERIC)) {
         ALOGE("Could not connect handle");
         nl_socket_free(sock);
@@ -120,14 +120,16 @@ wifi_error init_wifi_vendor_hal_func_table(wifi_hal_fn *fn)
     fn->wifi_start_sending_offloaded_packet = wifi_start_sending_offloaded_packet;
     fn->wifi_stop_sending_offloaded_packet = wifi_stop_sending_offloaded_packet;
     fn->wifi_set_epno_list = wifi_set_epno_list;
+    fn->wifi_reset_epno_list = wifi_reset_epno_list;
     fn->wifi_set_passpoint_list = wifi_set_passpoint_list;
     fn->wifi_reset_passpoint_list = wifi_reset_passpoint_list;
-    fn->wifi_set_bssid_blacklist = wifi_set_bssid_blacklist;
+//    fn->wifi_set_bssid_blacklist = wifi_set_bssid_blacklist;  // TODO: (IP) make it build
     fn->wifi_start_rssi_monitoring = wifi_start_rssi_monitoring;
     fn->wifi_stop_rssi_monitoring = wifi_stop_rssi_monitoring;
     fn->wifi_set_link_stats = wifi_set_link_stats;
     fn->wifi_get_link_stats = wifi_get_link_stats;
     fn->wifi_clear_link_stats = wifi_clear_link_stats;
+    fn->wifi_set_country_code = wifi_set_country_code;
 
     return WIFI_SUCCESS;
 }
@@ -145,7 +147,6 @@ wifi_error wifi_initialize(wifi_handle *handle)
 
     memset(info, 0, sizeof(*info));
 
-    ALOGI("Creating socket");
     if (socketpair(AF_UNIX, SOCK_STREAM, 0, info->cleanup_socks) == -1) {
         ALOGE("Could not create cleanup sockets");
         free(info);
@@ -206,20 +207,25 @@ wifi_error wifi_initialize(wifi_handle *handle)
     pthread_mutex_init(&info->cb_lock, NULL);
 
     *handle = (wifi_handle) info;
-           ALOGD("wifi_initialize, handle = %p\n", handle);
-           ALOGD("wifi_initialize, *handle = %p\n", *handle);
-               ALOGD("wifi_initialize, info = %p\n", info);
-               ALOGD("wifi_initialize, *info = %pn", *info);
+
     wifi_add_membership(*handle, "scan");
     wifi_add_membership(*handle, "mlme");
     wifi_add_membership(*handle, "regulatory");
     wifi_add_membership(*handle, "vendor");
 
     wifi_init_interfaces(*handle);
-     ALOGD("Found %d interfaces", info->num_interfaces);
+    char intf_name_buff[10 * 10 + 4]; /* Randomly choosen max interface 10. each interface name max 9 + 1(for space) */
+    char *pos = intf_name_buff;
+    for (int i = 0; i < (info->num_interfaces < 10 ? info->num_interfaces : 10); i++) {
+        strncpy(pos, info->interfaces[i]->name, sizeof(intf_name_buff) - (pos - intf_name_buff));
+        pos += strlen(pos);
+    }
+    if (info->num_interfaces > 10) {
+        strncpy(pos, "...", 3);
+    }
 
+    ALOGD("Found %d interfaces[%s]. Initialized Wifi HAL Successfully", info->num_interfaces, intf_name_buff);
 
-    ALOGI("Initialized Wifi HAL Successfully; vendor cmd = %d", NL80211_CMD_VENDOR);
     return WIFI_SUCCESS;
 }
 
@@ -237,8 +243,6 @@ static int wifi_add_membership(wifi_handle handle, const char *group)
     if (ret < 0) {
         ALOGE("Could not add membership to group %s", group);
     }
-
-     ALOGI("Successfully added membership for group %s", group);
     return ret;
 }
 
@@ -259,8 +263,6 @@ static void internal_cleaned_up_handler(wifi_handle handle)
     (*cleaned_up_handler)(handle);
     pthread_mutex_destroy(&info->cb_lock);
     free(info);
-
-    ALOGI("Internal cleanup completed");
 }
 
 void wifi_cleanup(wifi_handle handle, wifi_cleaned_up_handler handler)
@@ -280,9 +282,7 @@ void wifi_cleanup(wifi_handle handle, wifi_cleaned_up_handler handler)
         memset(buf, 0, sizeof(buf));
         int result = read(info->cleanup_socks[0], buf, sizeof(buf));
         ALOGE("%s: Read after POLL returned %d, error no = %d", __FUNCTION__, result, errno);
-        if (strncmp(buf, "Done", 4) == 0) {
-            ALOGE("Event processing terminated");
-        } else {
+        if (strncmp(buf, "Done", 4) != 0) {
             ALOGD("Rx'ed %s", buf);
         }
     }
@@ -319,10 +319,8 @@ void wifi_cleanup(wifi_handle handle, wifi_cleaned_up_handler handler)
 static int internal_pollin_handler(wifi_handle handle)
 {
     hal_info *info = getHalInfo(handle);
-               ALOGI("even_loop info = %p", info);
     struct nl_cb *cb = nl_socket_get_cb(info->event_sock);
     int res = nl_recvmsgs(info->event_sock, cb);
-     ALOGD("nl_recvmsgs returned %d", res);
     nl_cb_put(cb);
     return res;
 }
@@ -331,8 +329,6 @@ static int internal_pollin_handler(wifi_handle handle)
 void wifi_event_loop(wifi_handle handle)
 {
     hal_info *info = getHalInfo(handle);
-       ALOGI("even_loop info = %p", info);
-       ALOGI("even_loop info = %p", handle);
     if (info->in_event_loop) {
         return;
     } else {
@@ -356,9 +352,9 @@ void wifi_event_loop(wifi_handle handle)
         int result = poll(pfd, 2, timeout);
         if (result < 0) {
         } else if (pfd[0].revents & POLLERR) {
-            ALOGE("POLL Error; error no = %d", errno);
+            int prev_err = (int)errno;
             int result2 = read(pfd[0].fd, buf, sizeof(buf));
-            ALOGE("Read after POLL returned %d, error no = %d", result2, errno);
+            ALOGE("Poll err:%d | Read after POLL returned %d, error no = %d", prev_err, result2, errno);
         } else if (pfd[0].revents & POLLHUP) {
             ALOGE("Remote side hung up");
             break;
@@ -381,7 +377,6 @@ void wifi_event_loop(wifi_handle handle)
             ALOGE("Unknown event - %0x, %0x", pfd[0].revents, pfd[1].revents);
         }
     } while (!info->clean_up);
-    ALOGI("Exit %s", __FUNCTION__);
 }
 
 ///////////////////////////////////////////////////////////////////////////////////////
@@ -395,8 +390,6 @@ static int internal_valid_message_handler(nl_msg *msg, void *arg)
 {
     wifi_handle handle = (wifi_handle)arg;
     hal_info *info = getHalInfo(handle);
-   ALOGI("even_loop info = %p", handle);
-   ALOGD("internal_valid_message_handler, info = %p", info);
 
     WifiEvent event(msg);
     int res = event.parse();
@@ -412,10 +405,9 @@ static int internal_valid_message_handler(nl_msg *msg, void *arg)
     if (cmd == NL80211_CMD_VENDOR) {
         vendor_id = event.get_u32(NL80211_ATTR_VENDOR_ID);
         subcmd = event.get_u32(NL80211_ATTR_VENDOR_SUBCMD);
+        /*
         ALOGI("event received %s, vendor_id = 0x%0x, subcmd = 0x%0x",
-                event.get_cmdString(), vendor_id, subcmd);
-    } else {
-         ALOGI("event received %s", event.get_cmdString());
+                event.get_cmdString(), vendor_id, subcmd);*/
     }
 
      //ALOGI("event received %s, vendor_id = 0x%0x", event.get_cmdString(), vendor_id);
@@ -423,8 +415,6 @@ static int internal_valid_message_handler(nl_msg *msg, void *arg)
 
     pthread_mutex_lock(&info->cb_lock);
 
-    ALOGI("Number of events %d", info->num_event_cb);
-
     for (int i = 0; i < info->num_event_cb; i++) {
         if (cmd == info->event_cb[i].nl_cmd) {
             if (cmd == NL80211_CMD_VENDOR
@@ -481,7 +471,6 @@ public:
 
     virtual int create() {
         int nlctrlFamily = genl_ctrl_resolve(mInfo->cmd_sock, "nlctrl");
-        ALOGI("ctrl family = %d", nlctrlFamily);
         int ret = mMsg.create(nlctrlFamily, CTRL_CMD_GETFAMILY, 0, 0);
         if (ret < 0) {
             return ret;
@@ -491,9 +480,6 @@ public:
     }
 
     virtual int handleResponse(WifiEvent& reply) {
-
-         ALOGE("handling reponse in %s", __func__);
-
         struct nlattr **tb = reply.attributes();
         struct nlattr *mcgrp = NULL;
         int i;
@@ -501,13 +487,10 @@ public:
         if (!tb[CTRL_ATTR_MCAST_GROUPS]) {
             ALOGE("No multicast groups found");
             return NL_SKIP;
-        } else {
-             ALOGE("Multicast groups attr size = %d", nla_len(tb[CTRL_ATTR_MCAST_GROUPS]));
         }
 
         for_each_attr(mcgrp, tb[CTRL_ATTR_MCAST_GROUPS], i) {
 
-             ALOGE("Processing group");
             struct nlattr *tb2[CTRL_ATTR_MCAST_GRP_MAX + 1];
             nla_parse(tb2, CTRL_ATTR_MCAST_GRP_MAX, (nlattr *)nla_data(mcgrp),
                 nla_len(mcgrp), NULL);
@@ -518,8 +501,6 @@ public:
             char *grpName = (char *)nla_data(tb2[CTRL_ATTR_MCAST_GRP_NAME]);
             int grpNameLen = nla_len(tb2[CTRL_ATTR_MCAST_GRP_NAME]);
 
-             ALOGE("Found group name %s", grpName);
-
             if (strncmp(grpName, mGroup, grpNameLen) != 0)
                 continue;
 
@@ -565,7 +546,6 @@ public:
     }
 
     int start() {
-        ALOGD("Sending mac address OUI");
         WifiRequest request(familyId(), ifaceId());
         int result = createRequest(request, SLSI_NL80211_VENDOR_SUBCMD_SET_GSCAN_OUI, mOui);
         if (result != WIFI_SUCCESS) {
@@ -582,7 +562,6 @@ public:
     }
 protected:
     virtual int handleResponse(WifiEvent& reply) {
-         ALOGD("Request complete!");
         /* Nothing to do on response! */
         return NL_SKIP;
     }
@@ -640,7 +619,7 @@ public:
         if (result < 0) {
             return result;
         }
-        ALOGD("create request");
+
         result = request.put_u8(RSSI_MONITOR_ATTRIBUTE_MIN_RSSI, (enable? mMin_rssi: 0));
         if (result < 0) {
             return result;
@@ -667,12 +646,6 @@ public:
         ALOGI("Successfully set RSSI monitoring");
         registerVendorHandler(GOOGLE_OUI, WIFI_RSSI_REPORT_EVENT);
 
-
-        if (result < 0) {
-            unregisterVendorHandler(GOOGLE_OUI, WIFI_RSSI_REPORT_EVENT);
-            return result;
-        }
-        ALOGI("Done!");
         return result;
     }
 
@@ -698,7 +671,6 @@ public:
     }
 
    virtual int handleEvent(WifiEvent& event) {
-        ALOGI("Got a RSSI monitor event");
 
         nlattr *vendor_data = event.get_attribute(NL80211_ATTR_VENDOR_DATA);
         int len = event.get_vendor_data_len();
@@ -726,13 +698,41 @@ public:
 
 };
 
+class SetCountryCodeCommand : public WifiCommand {
+private:
+    const char *mCountryCode;
+public:
+    SetCountryCodeCommand(wifi_interface_handle handle, const char *country_code)
+        : WifiCommand(handle, 0) {
+        mCountryCode = country_code;
+        }
+    virtual int create() {
+        int ret;
+
+        ret = mMsg.create(GOOGLE_OUI, SLSI_NL80211_VENDOR_SUBCMD_SET_COUNTRY_CODE);
+        if (ret < 0) {
+             ALOGE("Can't create message to send to driver - %d", ret);
+             return ret;
+        }
+
+        nlattr *data = mMsg.attr_start(NL80211_ATTR_VENDOR_DATA);
+        ret = mMsg.put_string(ATTR_COUNTRY_CODE, mCountryCode);
+        if (ret < 0) {
+            return ret;
+        }
+
+        mMsg.attr_end(data);
+        return WIFI_SUCCESS;
+
+    }
+};
+
 class GetFeatureSetCommand : public WifiCommand {
 
 private:
-    int feature_type;
+
     feature_set *fset;
-    int *fm_size;
-    int set_size_max;
+
 public:
     GetFeatureSetCommand(wifi_interface_handle handle, feature_set *set)
         : WifiCommand(handle, 0)
@@ -807,15 +807,12 @@ static int get_interface(const char *name, interface_info *info)
 {
     strcpy(info->name, name);
     info->id = if_nametoindex(name);
-     ALOGI("found an interface : %s, id = %d", name, info->id);
     return WIFI_SUCCESS;
 }
 
 wifi_error wifi_init_interfaces(wifi_handle handle)
 {
     hal_info *info = (hal_info *)handle;
-       ALOGD("wifi_init_interfaces, info = %p", info);
-
     struct dirent *de;
 
     DIR *d = opendir("/sys/class/net");
@@ -936,4 +933,10 @@ wifi_error wifi_get_supported_feature_set(wifi_interface_handle handle, feature_
     return (wifi_error) command.requestResponse();
 }
 
+wifi_error wifi_set_country_code(wifi_interface_handle handle, const char *country_code)
+{
+    SetCountryCodeCommand command(handle, country_code);
+    return (wifi_error) command.requestResponse();
+}
+
 /////////////////////////////////////////////////////////////////////////////