Merge "Added support to add ipv6 route using netlink." into tizen
authortaesub kim <taesub.kim@samsung.com>
Mon, 11 Jun 2018 23:56:43 +0000 (23:56 +0000)
committerGerrit Code Review <gerrit@review.ap-northeast-2.compute.internal>
Mon, 11 Jun 2018 23:56:43 +0000 (23:56 +0000)
src/wifi-firmware.c
src/wifi-netlink-scan.c

index 2195913..60a7abe 100755 (executable)
@@ -20,6 +20,8 @@
 #include <errno.h>
 #include <vconf.h>
 #include <vconf-keys.h>
+#include <stdio.h>
+#include <fcntl.h>
 
 #include "log.h"
 #include "util.h"
@@ -36,6 +38,9 @@
 #define WLAN_P2P_IFACE_NAME_TV                 "p2p0"
 #define WLAN_P2P_IFACE_NAME_COMMON                     "wlan0"
 #define WLAN_P2P_IFACE_NAME ((TIZEN_TV) ? (WLAN_P2P_IFACE_NAME_TV) : (WLAN_P2P_IFACE_NAME_COMMON))
+#define QUAD_CPUS_COUNT                        4
+#define TEMP_BUFFER_LEN                        100
+#define WIFI_MAC_ADD_PATH              "/sys/class/net/wlan0/address"
 
 static int __netconfig_sta_firmware_start(void)
 {
@@ -205,6 +210,69 @@ static int __netconfig_wifi_firmware_stop(enum netconfig_wifi_firmware type)
        return -ENXIO;
 }
 
+static int __netconfig_set_rps_cpus(void)
+{
+       int fd, i;
+       ssize_t count;
+       char t_buf[TEMP_BUFFER_LEN];
+       char r_buf[TEMP_BUFFER_LEN];
+
+       if (access(WIFI_MAC_ADD_PATH, F_OK) != 0) {
+               DBG("WiFi driver is not loaded... ");
+               return -1;
+       } else {
+               DBG("WiFi driver loaded... ");
+       }
+
+       for (i = 0; i < QUAD_CPUS_COUNT; i++) {
+               snprintf(t_buf, TEMP_BUFFER_LEN, "/sys/class/net/wlan0/queues/rx-%d/rps_cpus", i);
+               DBG("Command : [%s]", t_buf);
+               fd = open(t_buf, O_RDWR | O_CLOEXEC);
+
+               if (fd < 0) {
+                       DBG("failed to open rps file");
+                       return -1;
+               } else {
+                       count = read(fd, r_buf, 1);
+
+                       if (count < 0) {
+                               DBG("read failed");
+                               close(fd);
+                               return -1;
+                       } else {
+                               DBG("read size = %d", count);
+                       }
+
+                       if (r_buf[0] == 'e') {
+                               close(fd);
+                               continue;
+                       } else {
+                               DBG("e is already written");
+                       }
+
+                       if (lseek(fd, 0, SEEK_SET) < 0) {
+                               DBG("lseek failed");
+                               close(fd);
+                               return -1;
+                       }
+
+                       count = write(fd, "e", 1);
+
+                       if (count < 0) {
+                               DBG("write failed");
+                               close(fd);
+                               return -1;
+                       } else {
+                               DBG("write size = %d", count);
+                       }
+
+                       close(fd);
+               }
+       }
+
+       return 0;
+}
+
 int netconfig_wifi_firmware(enum netconfig_wifi_firmware type, gboolean enable)
 {
        int err;
@@ -244,6 +312,9 @@ int netconfig_wifi_firmware(enum netconfig_wifi_firmware type, gboolean enable)
        else
                current_driver = alias;
 
+       if (__netconfig_set_rps_cpus() < 0)
+               DBG("Failed to set rps_cpus");
+
        return err;
 }
 
index 5fb87f7..38098f1 100755 (executable)
@@ -111,6 +111,7 @@ static int ack_handler(struct nl_msg *msg, void *user_data)
 {
        int *err = user_data;
        *err = 0;
+       DBG("");
        return NL_STOP;
 }
 
@@ -680,9 +681,12 @@ static int __netconfig_request_netlink_scan(struct nl_sock *socket,
        nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err);
        nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err);
        nl_cb_set(cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, no_seq_check, NULL);
+       ret = nl_socket_set_nonblocking(socket);
+       DBG("Set the non-blocking mode [%d]", ret);
 
        /** Send NL80211_CMD_TRIGGER_SCAN to start the scan. */
        ret = nl_send_auto_complete(socket, msg);
+
        if (ret < 0) {
                DBG("nl_send_auto_complete() error: (%s)", nl_geterror(-ret));
                goto out;
@@ -691,19 +695,26 @@ static int __netconfig_request_netlink_scan(struct nl_sock *socket,
        DBG("Sent %d bytes to the kernel", ret);
        ssid_found = FALSE;
 
-       while (err > 0)
+       while (err > 0) {
                ret = nl_recvmsgs(socket, cb);
-
-       if (ret < 0) {
-               DBG("nl_recvmsgs() ret: %d (%s)", ret, nl_geterror(-ret));
-               goto out;
+               if (ret < 0) {
+                       DBG("nl_recvmsgs() ret: %d (%s)", ret, nl_geterror(-ret));
+                       goto out;
+               }
        }
 
-       while (!results.done)
-               nl_recvmsgs(socket, cb);
+       while (!results.done) {
+               ret = nl_recvmsgs(socket, cb);
+               if (ret < 0 || err < 0) {
+                       DBG("scan failed");
+                       ret = -1;
+                       goto out;
+               }
+       }
 
        if (results.aborted) {
                DBG("scan aborted");
+               ret = -1;
                goto out;
        }
 
@@ -799,6 +810,7 @@ int handle_netlink_scan(Wifi *wifi, GDBusMethodInvocation *context, GVariant *pa
        int ret = __netconfig_initialize_nl80211(&global);
        if (ret < 0) {
                DBG("__netconfig_initialize_nl80211() failed, error %d", ret);
+               netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "AccessDenied");
                wifi_complete_netlink_scan(wifi, context);
                return TRUE;
        }
@@ -807,6 +819,7 @@ int handle_netlink_scan(Wifi *wifi, GDBusMethodInvocation *context, GVariant *pa
        ret = __netconfig_request_netlink_scan(global.socket, global.if_index, global.id, params);
        if (ret < 0) {
                DBG("__netconfig_request_netlink_scan() failed, error %d", ret);
+               netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "AccessDenied");
                wifi_complete_netlink_scan(wifi, context);
                return TRUE;
        }
@@ -814,6 +827,7 @@ int handle_netlink_scan(Wifi *wifi, GDBusMethodInvocation *context, GVariant *pa
        ret = __netconfig_initialize_nl_msg(&global);
        if (ret < 0) {
                DBG("__netconfig_initialize_nl_msg() failed, error %d", ret);
+               netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "AccessDenied");
                wifi_complete_netlink_scan(wifi, context);
                return TRUE;
        }
@@ -826,6 +840,7 @@ int handle_netlink_scan(Wifi *wifi, GDBusMethodInvocation *context, GVariant *pa
        nlmsg_free(global.msg);
        if (ret < 0) {
                DBG("nl_recvmsgs_default() failed. ret: %d (error: %s)", ret, nl_geterror(-ret));
+               netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "AccessDenied");
                wifi_complete_netlink_scan(wifi, context);
                return TRUE;
        }