Refactored "NetlinkScan" DBus method. 51/164951/3
authorNiraj Kumar Goit <niraj.g@samsung.com>
Fri, 22 Dec 2017 03:58:40 +0000 (09:28 +0530)
committerNiraj Kumar Goit <niraj.g@samsung.com>
Fri, 22 Dec 2017 04:14:00 +0000 (09:44 +0530)
- Refactored "NetlinkScan" DBus method to perform both normal
and specific AP scan.
- Added vendor specific information in probe request.

Change-Id: I65293873467e05d12f91aaf3a9cb96df85c29ff6
Signed-off-by: Niraj Kumar Goit <niraj.g@samsung.com>
include/wifi-config.h
include/wifi-netlink-scan.h
interfaces/netconfig-iface-wifi.xml
src/wifi-config.c
src/wifi-netlink-scan.c
src/wifi.c

index d84f2f2..32206a7 100755 (executable)
@@ -61,6 +61,9 @@ typedef enum {
 
 gboolean       wifi_config_get_config_id(const gchar *service_profile, gchar **config_id);
 gboolean       wifi_config_remove_configuration(const gchar *config_id);
+int __netconfig_hex_str_to_bin(const char *hex, unsigned char *buf, size_t len);
+int __netconfig_hex_to_byte(const char *hex);
+int __netconfig_hex_char_to_num(char c);
 
 gboolean       handle_get_config_ids(Wifi *wifi, GDBusMethodInvocation *context);
 gboolean       handle_load_configuration(Wifi *wifi, GDBusMethodInvocation *context, const gchar *config_id);
index 1bd0ce5..b3c1d93 100755 (executable)
@@ -29,6 +29,7 @@ extern "C" {
 #define NETCONFIG_SSID_LEN                     32
 #define NETCONFIG_BSSID_LEN                    17
 #define NETCONFIG_MAX_VSIE_LEN                 255
+#define NETCONFIG_VENDOR_SPECIFIC_ID           221
 
 #define NL80211_CMD_SCAN_ABORTED               35
 #define NL80211_CMD_GET_SCAN                   32
@@ -41,6 +42,7 @@ extern "C" {
 #define NL80211_BSS_MAX                                15
 #define NL80211_ATTR_BSS                       47
 #define NL80211_ATTR_IFINDEX                   3
+#define NL80211_ATTR_IE                                42
 #define NL80211_ATTR_SCAN_SSIDS                        45
 #define NL80211_ATTR_MAX                       221
 
@@ -71,8 +73,7 @@ typedef struct {
 } netconfig_nl_global;
 
 void __netconfig_notify_netlink_scan_done(void);
-int handle_netlink_scan(Wifi *wifi, GDBusMethodInvocation *context);
-int handle_netlink_specific_scan(Wifi *wifi, GDBusMethodInvocation *context, gchar *ssid);
+int handle_netlink_scan(Wifi *wifi, GDBusMethodInvocation *context, GVariant *params);
 
 #ifdef __cplusplus
 }
index 8920b03..38f26ea 100755 (executable)
@@ -46,9 +46,7 @@
                <method name="RequestBssidScan">
                </method>
                <method name="NetlinkScan">
-               </method>
-               <method name="NetlinkSpecificScan">
-                       <arg type="s" name="ssid" direction="in"/>
+                       <arg type="a{sv}" name="ssids" direction="in"/>
                </method>
                <method name="RequestWpsCancel">
                </method>
index 0caf71c..95e45d1 100755 (executable)
@@ -595,7 +595,7 @@ gboolean wifi_config_remove_configuration(const gchar *config_id)
        return ret;
 }
 
-static int __netconfig_hex_char_to_num(char c)
+int __netconfig_hex_char_to_num(char c)
 {
        if (c >= '0' && c <= '9')
                return c - '0';
@@ -609,7 +609,7 @@ static int __netconfig_hex_char_to_num(char c)
        return -1;
 }
 
-static int __netconfig_hex_to_byte(const char *hex)
+int __netconfig_hex_to_byte(const char *hex)
 {
        int a, b;
 
@@ -624,7 +624,7 @@ static int __netconfig_hex_to_byte(const char *hex)
        return (a << 4) | b;
 }
 
-static int __netconfig_hex_str_to_bin(const char *hex, unsigned char *buf, size_t len)
+int __netconfig_hex_str_to_bin(const char *hex, unsigned char *buf, size_t len)
 {
        size_t i;
        int a;
index d33ae41..c1eab05 100755 (executable)
@@ -22,6 +22,7 @@
 #include "netsupplicant.h"
 #include "log.h"
 #include "util.h"
+#include "wifi-config.h"
 #include "wifi-netlink-scan.h"
 #include <netlink/genl/genl.h>
 #include <netlink/genl/family.h>
@@ -376,7 +377,8 @@ static int __netconfig_netlink_scan_reply(struct nl_msg *msg, void *user_data)
        return NL_SKIP;
 }
 
-static int __netconfig_request_netlink_scan(struct nl_sock *socket, int if_index, int id, char *ssid)
+static int __netconfig_request_netlink_scan(struct nl_sock *socket,
+               int if_index, int id, GVariant *params)
 {
        struct netconfig_netlink_scan_results results = { .done = 0, .aborted = 0 };
        struct nl_msg *msg = NULL;
@@ -384,6 +386,12 @@ static int __netconfig_request_netlink_scan(struct nl_sock *socket, int if_index
        struct nl_msg *ssids = NULL;
        int err = 0;
        int ret = 0;
+       unsigned char ies[NETCONFIG_MAX_VSIE_LEN+1] = {0x00, };
+       int ies_len = 0;
+       GVariantIter *iter;
+       GVariant *value;
+       gchar *key;
+       gboolean ssid_found = FALSE;
        int mcid = __netconfig_get_multicast_id(socket, "nl80211", "scan");
        nl_socket_add_membership(socket, mcid);
 
@@ -409,13 +417,44 @@ static int __netconfig_request_netlink_scan(struct nl_sock *socket, int if_index
        /** Set nl message and callback functions. */
        genlmsg_put(msg, 0, 0, id, 0, 0, NL80211_CMD_TRIGGER_SCAN, 0);
        nla_put_u32(msg, NL80211_ATTR_IFINDEX, if_index);
-       if (!ssid)
+
+       g_variant_get(params, "a{sv}", &iter);
+       while (g_variant_iter_loop(iter, "{sv}", &key, &value)) {
+               if (g_strcmp0(key, "SSID") == 0) {
+                       if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
+                               char *ssid = g_strdup(g_variant_get_string(value, NULL));
+                               ssid_found = TRUE;
+                               DBG("ssid [%s]", ssid);
+
+                               nla_put(ssids, 1, strlen(ssid), ssid);
+                               g_free(ssid);
+                       }
+               } else if (g_strcmp0(key, "VSIE") == 0) {
+                       if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
+                               char *vsie = g_strdup(g_variant_get_string(value, NULL));
+                               int vsie_len = strlen(vsie);
+                               DBG("vsie: %s vsie_len: %d", vsie, vsie_len);
+
+                               ies_len = (vsie_len % 2) ? ((vsie_len / 2) + 1) : (vsie_len / 2);
+                               __netconfig_hex_str_to_bin(vsie, ies, ies_len);
+                               g_free(vsie);
+                       }
+               }
+       }
+       g_variant_iter_free(iter);
+
+       if (!ssid_found)
                nla_put(ssids, 1, 0, "");
-       else
-               nla_put(ssids, 1, strlen(ssid), ssid);
        nla_put_nested(msg, NL80211_ATTR_SCAN_SSIDS, ssids);
        nlmsg_free(ssids);
 
+       if (ies[0] == NETCONFIG_VENDOR_SPECIFIC_ID && ies[1] >= 4) {
+               DBG("ies_len: %d ies: %02x %02x %02x %02x %02x %02x %02x", ies_len,
+                               ies[0], ies[1], ies[2], ies[3], ies[4], ies[5], ies[6]);
+               nla_put(msg, NL80211_ATTR_IE, ies_len, ies);
+       }
+
+       err = 1;
        nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, __netconfig_netlink_scan_reply, &results);
        nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err);
        nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err);
@@ -423,9 +462,10 @@ static int __netconfig_request_netlink_scan(struct nl_sock *socket, int if_index
        nl_cb_set(cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, no_seq_check, NULL);
 
        /** Send NL80211_CMD_TRIGGER_SCAN to start the scan. */
-       err = 1;
        ret = nl_send_auto_complete(socket, msg);
        DBG("Sent %d bytes to the kernel", ret);
+       ssid_found = FALSE;
+
        while (err > 0)
                ret = nl_recvmsgs(socket, cb);
 
@@ -507,7 +547,7 @@ static int __netconfig_initialize_nl_msg(netconfig_nl_global *global)
        return 0;
 }
 
-int handle_netlink_scan(Wifi *wifi, GDBusMethodInvocation *context)
+int handle_netlink_scan(Wifi *wifi, GDBusMethodInvocation *context, GVariant *params)
 {
        DBG("");
        netconfig_nl_global global = {
@@ -521,12 +561,12 @@ int handle_netlink_scan(Wifi *wifi, GDBusMethodInvocation *context)
        int ret = __netconfig_initialize_nl80211(&global);
        if (ret < 0) {
                DBG("__netconfig_initialize_nl80211() failed, error %d", ret);
-               wifi_complete_netlink_specific_scan(wifi, context);
+               wifi_complete_netlink_scan(wifi, context);
                return ret;
        }
 
        /** Request NL80211_CMD_TRIGGER_SCAN to the kernel. */
-       ret = __netconfig_request_netlink_scan(global.socket, global.if_index, global.id, NULL);
+       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);
                wifi_complete_netlink_scan(wifi, context);
@@ -536,7 +576,7 @@ int handle_netlink_scan(Wifi *wifi, GDBusMethodInvocation *context)
        ret = __netconfig_initialize_nl_msg(&global);
        if (ret < 0) {
                DBG("__netconfig_initialize_nl_msg() failed, error %d", ret);
-               wifi_complete_netlink_specific_scan(wifi, context);
+               wifi_complete_netlink_scan(wifi, context);
                return ret;
        }
 
@@ -555,52 +595,3 @@ int handle_netlink_scan(Wifi *wifi, GDBusMethodInvocation *context)
        wifi_complete_netlink_scan(wifi, context);
        return 1;
 }
-
-int handle_netlink_specific_scan(Wifi *wifi, GDBusMethodInvocation *context, gchar *ssid)
-{
-       DBG("ssid: %s", ssid);
-       netconfig_nl_global global = {
-               .id = -1,
-               .if_index = -1,
-               .socket = NULL,
-               .msg = NULL,
-       };
-
-       /** Initialize netlink socket */
-       int ret = __netconfig_initialize_nl80211(&global);
-       if (ret < 0) {
-               DBG("__netconfig_initialize_nl80211() failed, error %d", ret);
-               wifi_complete_netlink_specific_scan(wifi, context);
-               return ret;
-       }
-
-       /** Request NL80211_CMD_TRIGGER_SCAN to the kernel. */
-       ret = __netconfig_request_netlink_scan(global.socket, global.if_index, global.id, ssid);
-       if (ret != 0) {
-               DBG("__netconfig_request_netlink_scan() failed, error %d", ret);
-               wifi_complete_netlink_specific_scan(wifi, context);
-               return ret;
-       }
-
-       ret = __netconfig_initialize_nl_msg(&global);
-       if (ret < 0) {
-               DBG("__netconfig_initialize_nl_msg() failed, error %d", ret);
-               wifi_complete_netlink_specific_scan(wifi, context);
-               return ret;
-       }
-
-       ret = nl_send_auto_complete(global.socket, global.msg);
-       DBG("NL80211_CMD_GET_SCAN sent %d bytes to the kernel", ret);
-
-       /** Receive the kernel message. */
-       ret = nl_recvmsgs_default(global.socket);
-       nlmsg_free(global.msg);
-       if (ret < 0) {
-               DBG("nl_recvmsgs_default() failed. ret: %d (error: %s)", ret, nl_geterror(-ret));
-               wifi_complete_netlink_specific_scan(wifi, context);
-               return ret;
-       }
-
-       wifi_complete_netlink_specific_scan(wifi, context);
-       return 1;
-}
index 74e19f4..d47a352 100755 (executable)
@@ -170,8 +170,6 @@ void wifi_object_create_and_init(void)
                        G_CALLBACK(handle_get_bssid_list), NULL);
        g_signal_connect(wifi_object, "handle-netlink-scan",
                        G_CALLBACK(handle_netlink_scan), NULL);
-       g_signal_connect(wifi_object, "handle-netlink-specific-scan",
-                       G_CALLBACK(handle_netlink_specific_scan), NULL);
 
        /* WPS Connect */
        g_signal_connect(wifi_object, "handle-request-wps-connect",