Verify INS functions using connmanctl 10/231110/4 submit/tizen/20200422.012623
authorhyunuk.tak <hyunuk.tak@samsung.com>
Fri, 17 Apr 2020 08:32:01 +0000 (17:32 +0900)
committerhyunuk.tak <hyunuk.tak@samsung.com>
Mon, 20 Apr 2020 00:30:46 +0000 (09:30 +0900)
Change-Id: I498fac295defe24eab8e3d23c6e0864bfda8fd86
Signed-off-by: hyunuk.tak <hyunuk.tak@samsung.com>
Makefile.am
client/commands.c [changed mode: 0644->0755]
client/ins.c [new file with mode: 0755]
client/ins.h [new file with mode: 0755]
configure.ac
gsupplicant/supplicant.c
include/network.h
packaging/connman.spec
src/connman.h
src/manager.c [changed mode: 0644->0755]
src/service.c

index 5511c3f..b765875 100644 (file)
@@ -374,6 +374,10 @@ if TIZEN_EXT_WIFI_MESH
 client_connmanctl_SOURCES += client/mesh.c client/mesh.h
 endif
 
+if TIZEN_EXT_INS
+client_connmanctl_SOURCES += client/ins.c client/ins.h
+endif
+
 client_connmanctl_LDADD = gdbus/libgdbus-internal.la @DBUS_LIBS@ @GLIB_LIBS@ \
                                -lreadline -ldl -lncurses
 endif
old mode 100644 (file)
new mode 100755 (executable)
index 6abe7db..a8f3e9d
@@ -39,6 +39,9 @@
 #include "dbus_helpers.h"
 #include "input.h"
 #include "services.h"
+#if defined TIZEN_EXT_INS
+#include "ins.h"
+#endif
 #include "tethering.h"
 #include "peers.h"
 #include "commands.h"
@@ -310,6 +313,25 @@ static int services_list(DBusMessageIter *iter, const char *error,
        return 0;
 }
 
+#if defined TIZEN_EXT_INS
+static int ins_list(DBusMessageIter *iter, const char *error,
+               void *user_data)
+{
+       char *filter = user_data;
+
+       if (!error) {
+               __connmanctl_ins_list(iter, filter);
+               fprintf(stdout, "\n");
+       } else {
+               fprintf(stderr, "Error: %s\n", error);
+       }
+
+       g_free(filter);
+
+       return 0;
+}
+#endif
+
 static int peers_list(DBusMessageIter *iter,
                                        const char *error, void *user_data)
 {
@@ -405,6 +427,24 @@ static int cmd_services(char *args[], int num, struct connman_option *options)
                        object_properties, path, NULL, NULL);
 }
 
+#if defined TIZEN_EXT_INS
+static int cmd_ins(char *args[], int num, struct connman_option *options)
+{
+       char *filter = NULL;
+
+       if (num > 2)
+               return -E2BIG;
+
+       if (num == 2)
+               filter = g_strdup(args[1]);
+
+       return __connmanctl_dbus_method_call(connection,
+                               CONNMAN_SERVICE, CONNMAN_PATH,
+                               "net.connman.Manager", "GetINS",
+                               ins_list, filter, NULL, NULL);
+}
+#endif
+
 static int cmd_peers(char *args[], int num, struct connman_option *options)
 {
        char *peer_name = NULL;
@@ -2950,6 +2990,15 @@ static struct connman_option service_options[] = {
        { NULL, }
 };
 
+#if defined TIZEN_EXT_INS
+static struct connman_option ins_options[] = {
+       {"all",         'a', ""},
+       {"filter-ssid", 's', "ssid"},
+       {"filter-name", 'n', "[<service_name>]"},
+       { NULL, }
+};
+#endif
+
 static struct connman_option config_options[] = {
        {"nameservers", 'n', "<dns1> [<dns2>] [<dns3>]"},
        {"timeservers", 't', "<ntp1> [<ntp2>] [...]"},
@@ -3400,6 +3449,10 @@ static const struct {
          "Display tethering clients", NULL },
        { "services",     "[<service>]",  service_options, cmd_services,
          "Display services", lookup_service_arg },
+#if defined TIZEN_EXT_INS
+       { "ins",                  NULL,      ins_options, cmd_ins,
+         "Display intelligent network selection", NULL },
+#endif
        { "peers",        "[peer]",       NULL,            cmd_peers,
          "Display peers", lookup_peer_arg },
        { "scan",         "<technology>", NULL,            cmd_scan,
diff --git a/client/ins.c b/client/ins.c
new file mode 100755 (executable)
index 0000000..f62f837
--- /dev/null
@@ -0,0 +1,301 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2020  Intel Corporation. All rights reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include <glib.h>
+
+#include "ins.h"
+
+struct bssid_info_s {
+       char *bssid;
+       unsigned int strength;
+       unsigned int frequency;
+       int score_ins;
+       int score_last_connected;
+       int score_assoc_reject;
+       int score_frequency;
+       int score_strength;
+};
+
+static void print_bssid_info(gpointer value, gpointer user_data)
+{
+       struct bssid_info_s *bssid_info = value;
+       int *bssid_rank = user_data;
+
+       fprintf(stdout, "     %2d) %-20s total[%2d] last_conn[%2d] "
+                       "assoc_reject[%2d] freq[%2d(%4d)] strength[%2d(%2d)]\n",
+                       *bssid_rank, bssid_info->bssid, bssid_info->score_ins,
+                       bssid_info->score_last_connected, bssid_info->score_assoc_reject,
+                       bssid_info->score_frequency, bssid_info->frequency,
+                       bssid_info->score_strength, bssid_info->strength);
+
+       (*bssid_rank)++;
+}
+
+static GSList *get_bssid_list(DBusMessageIter *iter)
+{
+       char *property;
+       DBusMessageIter entry, val;
+       GSList *bssid_list = NULL;
+       struct bssid_info_s *bssid_info = NULL;
+
+       while (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
+               dbus_message_iter_recurse(iter, &entry);
+               dbus_message_iter_get_basic(&entry, &property);
+
+               if (strcmp(property, "BSSID") == 0) {
+                       bssid_info = g_try_new0(struct bssid_info_s, 1);
+                       if (!bssid_info)
+                               continue;
+
+                       dbus_message_iter_next(&entry);
+                       dbus_message_iter_recurse(&entry, &val);
+                       dbus_message_iter_get_basic(&val, &(bssid_info->bssid));
+
+               } else if (strcmp(property, "ScoreINS") == 0) {
+                       dbus_message_iter_next(&entry);
+                       dbus_message_iter_recurse(&entry, &val);
+                       dbus_message_iter_get_basic(&val, &(bssid_info->score_ins));
+
+               } else if (strcmp(property, "ScoreLastConnected") == 0) {
+                       dbus_message_iter_next(&entry);
+                       dbus_message_iter_recurse(&entry, &val);
+                       dbus_message_iter_get_basic(&val, &(bssid_info->score_last_connected));
+
+               } else if (strcmp(property, "ScoreAssocReject") == 0) {
+                       dbus_message_iter_next(&entry);
+                       dbus_message_iter_recurse(&entry, &val);
+                       dbus_message_iter_get_basic(&val, &(bssid_info->score_assoc_reject));
+
+               } else if (strcmp(property, "Frequency") == 0) {
+                       dbus_message_iter_next(&entry);
+                       dbus_message_iter_recurse(&entry, &val);
+                       dbus_message_iter_get_basic(&val, &(bssid_info->frequency));
+
+               } else if (strcmp(property, "ScoreFrequency") == 0) {
+                       dbus_message_iter_next(&entry);
+                       dbus_message_iter_recurse(&entry, &val);
+                       dbus_message_iter_get_basic(&val, &(bssid_info->score_frequency));
+
+               } else if (strcmp(property, "Strength") == 0) {
+                       dbus_message_iter_next(&entry);
+                       dbus_message_iter_recurse(&entry, &val);
+                       dbus_message_iter_get_basic(&val, &(bssid_info->strength));
+
+               } else if (strcmp(property, "ScoreStrength") == 0) {
+                       dbus_message_iter_next(&entry);
+                       dbus_message_iter_recurse(&entry, &val);
+                       dbus_message_iter_get_basic(&val, &(bssid_info->score_strength));
+
+                       bssid_list = g_slist_append(bssid_list, bssid_info);
+               }
+
+               dbus_message_iter_next(iter);
+       }
+
+       return bssid_list;
+}
+
+static void print_ins_info(int *rank, char *path, char *filter, DBusMessageIter *iter)
+{
+       char *name = "";
+       char *security;
+       char *str = NULL;
+       int count = 0;
+       char *property;
+       unsigned char strength;
+       unsigned int frequency;
+       int score_INS;
+       int score_last_user_selection;
+       int score_last_connected;
+       int score_frequency;
+       int score_security_priority;
+       int score_internet_connection;
+       int score_strength;
+       GSList *bssid_list = NULL;
+       DBusMessageIter entry, val, dict;
+
+       while (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
+               dbus_message_iter_recurse(iter, &entry);
+               dbus_message_iter_get_basic(&entry, &property);
+
+               if (strcmp(property, "Name") == 0) {
+                       dbus_message_iter_next(&entry);
+                       dbus_message_iter_recurse(&entry, &val);
+                       dbus_message_iter_get_basic(&val, &name);
+
+               } else if (strcmp(property, "ScoreINS") == 0) {
+                       dbus_message_iter_next(&entry);
+                       dbus_message_iter_recurse(&entry, &val);
+                       dbus_message_iter_get_basic(&val, &score_INS);
+
+               } else if (strcmp(property, "ScoreLastUserSelection") == 0) {
+                       dbus_message_iter_next(&entry);
+                       dbus_message_iter_recurse(&entry, &val);
+                       dbus_message_iter_get_basic(&val, &score_last_user_selection);
+
+               } else if (strcmp(property, "ScoreLastConnected") == 0) {
+                       dbus_message_iter_next(&entry);
+                       dbus_message_iter_recurse(&entry, &val);
+                       dbus_message_iter_get_basic(&val, &score_last_connected);
+
+               } else if (strcmp(property, "Security") == 0) {
+                       dbus_message_iter_next(&entry);
+                       dbus_message_iter_recurse(&entry, &val);
+                       dbus_message_iter_get_basic(&val, &security);
+
+               } else if (strcmp(property, "ScoreSecurityPriority") == 0) {
+                       dbus_message_iter_next(&entry);
+                       dbus_message_iter_recurse(&entry, &val);
+                       dbus_message_iter_get_basic(&val, &score_security_priority);
+
+               } else if (strcmp(property, "Strength") == 0) {
+                       dbus_message_iter_next(&entry);
+                       dbus_message_iter_recurse(&entry, &val);
+                       dbus_message_iter_get_basic(&val, &strength);
+
+               } else if (strcmp(property, "ScoreStrength") == 0) {
+                       dbus_message_iter_next(&entry);
+                       dbus_message_iter_recurse(&entry, &val);
+                       dbus_message_iter_get_basic(&val, &score_strength);
+
+               } else if (strcmp(property, "ScoreInternetConnection") == 0) {
+                       dbus_message_iter_next(&entry);
+                       dbus_message_iter_recurse(&entry, &val);
+                       dbus_message_iter_get_basic(&val, &score_internet_connection);
+
+               } else if (strcmp(property, "Frequency") == 0) {
+                       dbus_message_iter_next(&entry);
+                       dbus_message_iter_recurse(&entry, &val);
+                       dbus_message_iter_get_basic(&val, &frequency);
+
+               } else if (strcmp(property, "ScoreFrequency") == 0) {
+                       dbus_message_iter_next(&entry);
+                       dbus_message_iter_recurse(&entry, &val);
+                       dbus_message_iter_get_basic(&val, &score_frequency);
+
+               } else if (strcmp(property, "BSSID.List") == 0) {
+                       dbus_message_iter_next(&entry);
+                       dbus_message_iter_recurse(&entry, &val);
+                       if (dbus_message_iter_get_arg_type(&val)
+                               == DBUS_TYPE_ARRAY) {
+                               dbus_message_iter_recurse(&val, &dict);
+                               bssid_list = get_bssid_list(&dict);
+                       }
+
+               }
+
+               count++;
+               dbus_message_iter_next(iter);
+       }
+
+       str = strrchr(path, '/');
+       if (str)
+               str++;
+       else
+               str = path;
+
+       if (count > 0) {
+               if (!filter || strcmp(filter, name) == 0 || strcmp(filter, "ssid") == 0) {
+                       fprintf(stdout, "  [%2d] %-20s total[%2d] last_usr[%2d] last_conn[%2d] "
+                               "internet[%2d] sec[%2d(%9s)] freq[%2d(%4d)] strength[%2d(%2d)]\n  %s\n",
+                               *rank, name, score_INS, score_last_user_selection, score_last_connected,
+                               score_internet_connection, score_security_priority, security,
+                               score_frequency, frequency, score_strength, strength, str);
+
+                       if (!filter || strcmp(filter, "ssid") != 0) {
+                               int bssid_rank = 1;
+                               g_slist_foreach(bssid_list, print_bssid_info, &bssid_rank);
+                       }
+
+                       (*rank)++;
+               }
+
+       } else {
+               fprintf(stdout, "%-24s %s", "unchanged\n", str);
+       }
+
+}
+
+static void list_ins_array(DBusMessageIter *iter, char *filter)
+{
+       DBusMessageIter array, dict;
+       char *path = NULL;
+       int rank = 1;
+
+       while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRUCT) {
+
+               dbus_message_iter_recurse(iter, &array);
+               if (dbus_message_iter_get_arg_type(&array)
+                               != DBUS_TYPE_OBJECT_PATH)
+                       return;
+
+               dbus_message_iter_get_basic(&array, &path);
+
+               dbus_message_iter_next(&array);
+               if (dbus_message_iter_get_arg_type(&array)
+                               == DBUS_TYPE_ARRAY) {
+                       dbus_message_iter_recurse(&array, &dict);
+                       print_ins_info(&rank, path, filter, &dict);
+               }
+
+               dbus_message_iter_next(iter);
+       }
+}
+
+void __connmanctl_ins_list(DBusMessageIter *iter, char *filter)
+{
+       DBusMessageIter array;
+       char *path;
+
+       if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
+               return;
+
+       dbus_message_iter_recurse(iter, &array);
+       list_ins_array(&array, filter);
+
+       dbus_message_iter_next(iter);
+       if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
+               return;
+
+       fprintf(stdout, "\n}, {");
+
+       dbus_message_iter_recurse(iter, &array);
+       while (dbus_message_iter_get_arg_type(&array)
+                       == DBUS_TYPE_OBJECT_PATH) {
+               dbus_message_iter_get_basic(&array, &path);
+               fprintf(stdout, "\n%-24s %s", "removed", path);
+
+               dbus_message_iter_next(&array);
+       }
+
+}
diff --git a/client/ins.h b/client/ins.h
new file mode 100755 (executable)
index 0000000..88151af
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2020  Intel Corporation. All rights reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifndef __CONNMANCTL_INS_H
+#define __CONNMANCTL_INS_H
+
+#include <dbus/dbus.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void __connmanctl_ins_list(DBusMessageIter *iter, char *filter);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CONNMANCTL_INS_H */
index a1c34e1..487deb4 100644 (file)
@@ -80,6 +80,11 @@ AC_ARG_ENABLE(tizen-ext,
                        fi])
 AM_CONDITIONAL(TIZEN_EXT, test "${enable-tizen-ext}" != "no")
 
+AC_ARG_ENABLE(tizen-ext-ins,
+       AC_HELP_STRING([--enable-tizen-ext-ins], [enable TIZEN extensions for INS]),
+                       [CFLAGS="$CFLAGS -DTIZEN_EXT_INS"], [enable_tizen_ext_ins="no"])
+AM_CONDITIONAL(TIZEN_EXT_INS, test "${enable_tizen_ext_ins}" != "no")
+
 AC_ARG_ENABLE(tizen-ext-wifi-mesh,
        AC_HELP_STRING([--enable-tizen-ext-wifi-mesh], [enable TIZEN extensions for Wi-Fi Mesh]),
                        [CFLAGS="$CFLAGS -DTIZEN_EXT_WIFI_MESH"], [enable_tizen_ext_wifi_mesh="no"])
index 957312c..d59085d 100755 (executable)
@@ -60,6 +60,9 @@
 #define FREQ_RANGE_24GHZ_CHANNEL_14  2484
 #define FREQ_RANGE_5GHZ_CHANNEL_32   5160
 #define FREQ_RANGE_5GHZ_CHANNEL_165  5825
+
+#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
+#define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
 #endif
 
 #define BSS_UNKNOWN_STRENGTH    -90
@@ -416,6 +419,12 @@ struct g_connman_bssids {
        uint16_t frequency;
        uint16_t assoc_reject_cnt;
        bool is_last_connected;
+#if defined TIZEN_EXT_INS
+       int score_last_connected_bssid;
+       int score_assoc_reject;
+       int score_frequency;
+       int score_strength;
+#endif
        int ins_score;
 };
 
@@ -1962,40 +1971,32 @@ static uint16_t get_assoc_reject_cnt(GHashTable *assoc_reject_table, unsigned ch
        return assoc_count.assoc_count;
 }
 
-static void update_bssid_list(gpointer key, gpointer value, gpointer user_data)
+static int calculate_score_last_connected_bssid(bool is_last_connected)
 {
-       struct g_supplicant_bss *bss = value;
-       struct g_connman_bssids *bssids = NULL;
-       struct update_bssid_data *bssid_data = (struct update_bssid_data *)user_data;
-
-       bssids = (struct g_connman_bssids *)g_try_malloc0(sizeof(struct g_connman_bssids));
-
-       if (bssids) {
-               memcpy(bssids->bssid, bss->bssid, WIFI_BSSID_LEN_MAX);
-
-               bssids->strength = bss->signal;
-               bssids->strength += 120;
+       int score = 0;
 
-               if (bssids->strength > 100)
-                       bssids->strength = 100;
+       if (ins_settings.last_connected_bssid) {
+               if (is_last_connected)
+                       score += ins_settings.last_connected_bssid_score;
+       }
 
-               bssids->frequency = bss->frequency;
+       return score;
+}
 
-               bssids->assoc_reject_cnt = get_assoc_reject_cnt(bssid_data->assoc_reject_table, bssids->bssid);
+static int calculate_score_assoc_reject(uint16_t assoc_reject_cnt)
+{
+       int score = 0;
 
-               bssids->is_last_connected = compare_bssid(bssids->bssid, bssid_data->last_connected_bssid);
+       if (ins_settings.assoc_reject)
+               score -= (assoc_reject_cnt * ins_settings.assoc_reject_score);
 
-               bssid_data->bssid_list = g_slist_append(bssid_data->bssid_list, bssids);
-       } else
-               SUPPLICANT_DBG("Failed to allocate memory");
+       return score;
 }
 
-static int calculate_score(dbus_int16_t strength, dbus_uint16_t frequency,
-               uint16_t assoc_reject_cnt, bool is_last_connected)
+static int calculate_score_frequency(dbus_int16_t strength, dbus_uint16_t frequency)
 {
        int score = 0;
 
-       /* 5GHz & Signal >= RSSI Level 3 */
        switch (ins_settings.preferred_freq_bssid) {
        case G_SUPPLICANT_INS_PREFERRED_FREQ_24GHZ:
                if ((frequency >= FREQ_RANGE_24GHZ_CHANNEL_1 &&
@@ -2015,39 +2016,79 @@ static int calculate_score(dbus_int16_t strength, dbus_uint16_t frequency,
                break;
        }
 
-       /* Last connected BSSID */
-       if (ins_settings.last_connected_bssid) {
-               if (is_last_connected)
-                       score += ins_settings.last_connected_bssid_score;
-       }
+       return score;
+}
 
-       /* Assoc reject */
-       if (ins_settings.assoc_reject)
-               score -= (assoc_reject_cnt * ins_settings.assoc_reject_score);
+static int calculate_score_strength(dbus_int16_t strength)
+{
+       int score = 0;
 
-       /* Signal */
        if (ins_settings.signal_bssid)
                score += (((strength > -60) ? -60 : strength) + 85);
 
        return score;
 }
 
+static int calculate_score(bool is_last_connected, uint16_t assoc_reject_cnt,
+               dbus_int16_t strength, dbus_uint16_t frequency)
+{
+       int score = 0;
+
+       score += calculate_score_last_connected_bssid(is_last_connected);
+       score += calculate_score_assoc_reject(assoc_reject_cnt);
+       score += calculate_score_frequency(strength, frequency);
+       score += calculate_score_strength(strength);
+
+       return score;
+}
+
+static void update_bssid_list(gpointer key, gpointer value, gpointer user_data)
+{
+       struct g_supplicant_bss *bss = value;
+       struct g_connman_bssids *bssids = NULL;
+       struct update_bssid_data *bssid_data = (struct update_bssid_data *)user_data;
+
+       bssids = (struct g_connman_bssids *)g_try_malloc0(sizeof(struct g_connman_bssids));
+
+       if (bssids) {
+               memcpy(bssids->bssid, bss->bssid, WIFI_BSSID_LEN_MAX);
+
+               bssids->strength = bss->signal;
+               bssids->strength += 120;
+
+               if (bssids->strength > 100)
+                       bssids->strength = 100;
+
+               bssids->frequency = bss->frequency;
+
+               bssids->assoc_reject_cnt = get_assoc_reject_cnt(bssid_data->assoc_reject_table, bssids->bssid);
+
+               bssids->is_last_connected = compare_bssid(bssids->bssid, bssid_data->last_connected_bssid);
+
+#if defined TIZEN_EXT_INS
+               bssids->score_last_connected_bssid = calculate_score_last_connected_bssid(bssids->is_last_connected);
+               bssids->score_assoc_reject = calculate_score_assoc_reject(bssids->assoc_reject_cnt);
+               bssids->score_frequency = calculate_score_frequency(bss->signal, bssids->frequency);
+               bssids->score_strength = calculate_score_strength(bssids->strength);
+#endif
+
+               bssids->ins_score = calculate_score(bssids->is_last_connected,
+                       bssids->assoc_reject_cnt, bssids->frequency, bss->signal);
+
+               bssid_data->bssid_list = g_slist_append(bssid_data->bssid_list, bssids);
+       } else
+               SUPPLICANT_DBG("Failed to allocate memory");
+}
+
 static gint cmp_bss(gconstpointer a, gconstpointer b)
 {
        struct g_connman_bssids *entry_a = (struct g_connman_bssids *)a;
        struct g_connman_bssids *entry_b = (struct g_connman_bssids *)b;
-       int score_a = calculate_score(entry_a->strength - 120, entry_a->frequency,
-                       entry_a->assoc_reject_cnt, entry_a->is_last_connected);
-       int score_b = calculate_score(entry_b->strength - 120, entry_b->frequency,
-                       entry_b->assoc_reject_cnt, entry_b->is_last_connected);
-
-       entry_a->ins_score = score_a;
-       entry_b->ins_score = score_b;
 
-       if (score_a > score_b)
+       if (entry_a->ins_score > entry_b->ins_score)
                return -1;
 
-       if (score_a < score_b)
+       if (entry_a->ins_score < entry_b->ins_score)
                return 1;
 
        return 0;
@@ -2058,12 +2099,11 @@ static void print_bssid_sort(gpointer data, gpointer user_data)
 {
        struct g_connman_bssids *bssids = data;
 
-       SUPPLICANT_DBG("bssid[%02x:%02x:%02x:%02x:%02x:%02x] score[%d] "
-                       "strength[%d] freq[%d] assoc_reject[%d] last_conn[%d]",
-                       bssids->bssid[0], bssids->bssid[1], bssids->bssid[2],
-                       bssids->bssid[3], bssids->bssid[4], bssids->bssid[5],
-                       bssids->ins_score, bssids->strength, bssids->frequency,
-                       bssids->assoc_reject_cnt, bssids->is_last_connected);
+       SUPPLICANT_DBG("bssid[" MACSTR "] total[%2d] freq[%2d] "
+                       "last_conn[%2d] assoc_reject[%2d] strength[%2d]",
+                       MAC2STR(bssids->bssid), bssids->ins_score,
+                       bssids->score_frequency, bssids->score_last_connected_bssid,
+                       bssids->score_assoc_reject, bssids->score_strength);
 }
 #endif
 
@@ -2098,8 +2138,7 @@ void g_supplicant_network_set_last_connected_bssid(GSupplicantNetwork *network,
 
        memcpy(network->last_connected_bssid, bssid, WIFI_BSSID_LEN_MAX);
 
-       SUPPLICANT_DBG("last connected bssid [%02x:%02x:%02x:%02x:%02x:%02x]",
-                       bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5]);
+       SUPPLICANT_DBG("last connected bssid [" MACSTR "]", MAC2STR(bssid));
 }
 
 const unsigned char *g_supplicant_network_get_last_connected_bssid(GSupplicantNetwork *network)
@@ -2405,23 +2444,19 @@ static bool update_best_bss(GSupplicantNetwork *network,
        int score_new;
        int score_best;
 
-       score_new = calculate_score(bss->signal, bss->frequency,
+       score_new = calculate_score(
+               compare_bssid(bss->bssid, network->last_connected_bssid),
                get_assoc_reject_cnt(network->assoc_reject_table, bss->bssid),
-               compare_bssid(bss->bssid, network->last_connected_bssid));
-       score_best = calculate_score(network->best_bss->signal, network->best_bss->frequency,
+               bss->frequency, bss->signal);
+       score_best = calculate_score(
+               compare_bssid(network->best_bss->bssid, network->last_connected_bssid),
                get_assoc_reject_cnt(network->assoc_reject_table, network->best_bss->bssid),
-               compare_bssid(network->best_bss->bssid, network->last_connected_bssid));
+               network->best_bss->frequency, network->best_bss->signal);
 
        if (score_new > score_best) {
-               SUPPLICANT_DBG("new[%02x:%02x:%02x:%02x:%02x:%02x][%u] : "
-                       "best[%02x:%02x:%02x:%02x:%02x:%02x][%u]",
-                       bss->bssid[0], bss->bssid[1], bss->bssid[2],
-                       bss->bssid[3], bss->bssid[4], bss->bssid[5],
-                       score_new,
-                       network->best_bss->bssid[0], network->best_bss->bssid[1],
-                       network->best_bss->bssid[2], network->best_bss->bssid[3],
-                       network->best_bss->bssid[4], network->best_bss->bssid[5],
-                       score_best);
+               SUPPLICANT_DBG("new[" MACSTR "][%u] : best[" MACSTR "][%u]",
+                       MAC2STR(bss->bssid), score_new,
+                       MAC2STR(network->best_bss->bssid), score_best);
 
                network->signal = bss->signal;
                network->frequency = bss->frequency;
@@ -3236,10 +3271,8 @@ static void add_timer_for_last_connected(GSupplicantInterface *interface)
                        last_connected_bss_timeout = g_timeout_add_seconds(LAST_CONNECTED_TIMEOUT,
                                last_connected_timeout, interface);
 
-                       SUPPLICANT_DBG("Add timer for last connected bssid "
-                               "[%02x:%02x:%02x:%02x:%02x:%02x]",
-                               best_bss->bssid[0], best_bss->bssid[1], best_bss->bssid[2],
-                               best_bss->bssid[3], best_bss->bssid[4], best_bss->bssid[5]);
+                       SUPPLICANT_DBG("Add timer for last connected bssid [" MACSTR "]",
+                                       MAC2STR(best_bss->bssid));
                }
        }
 }
@@ -6965,21 +6998,14 @@ static void interface_add_network_params(DBusMessageIter *iter, void *user_data)
                }
 
                if (ssid->bssid_for_connect_len) {
-                       snprintf(bssid, 18, "%02x:%02x:%02x:%02x:%02x:%02x",
-                                       ssid->bssid_for_connect[0], ssid->bssid_for_connect[1], ssid->bssid_for_connect[2],
-                                       ssid->bssid_for_connect[3], ssid->bssid_for_connect[4], ssid->bssid_for_connect[5]);
+                       snprintf(bssid, 18, MACSTR, MAC2STR(ssid->bssid_for_connect));
                        memcpy(interface->add_network_bssid, ssid->bssid_for_connect, WIFI_BSSID_LEN_MAX);
                } else {
-                       snprintf(bssid, 18, "%02x:%02x:%02x:%02x:%02x:%02x",
-                                       ssid->bssid[0], ssid->bssid[1], ssid->bssid[2],
-                                       ssid->bssid[3], ssid->bssid[4], ssid->bssid[5]);
+                       snprintf(bssid, 18, MACSTR, MAC2STR(ssid->bssid));
                        memcpy(interface->add_network_bssid, ssid->bssid, WIFI_BSSID_LEN_MAX);
                }
 
-               SUPPLICANT_DBG("bssid [%02x:%02x:%02x:%02x:%02x:%02x]",
-                       interface->add_network_bssid[0], interface->add_network_bssid[1],
-                       interface->add_network_bssid[2], interface->add_network_bssid[3],
-                       interface->add_network_bssid[4], interface->add_network_bssid[5]);
+               SUPPLICANT_DBG("bssid [" MACSTR "]", MAC2STR(interface->add_network_bssid));
 
                supplicant_dbus_dict_append_basic(&dict, "bssid",
                                        DBUS_TYPE_STRING, &bssid);
index 8cefb79..fc68d30 100755 (executable)
@@ -76,6 +76,15 @@ struct connman_bssids {
        unsigned char bssid[WIFI_BSSID_LEN_MAX];
        uint16_t strength;
        uint16_t frequency;
+       uint16_t assoc_reject_cnt;
+       bool is_last_connected;
+#if defined TIZEN_EXT_INS
+       int score_last_connected_bssid;
+       int score_assoc_reject;
+       int score_frequency;
+       int score_strength;
+#endif
+       int ins_score;
 };
 
 /* Backward compatible
index 31ab4ca..879cb47 100644 (file)
@@ -5,7 +5,7 @@
 
 Name:           connman
 Version:        1.37
-Release:        36
+Release:        37
 License:        GPL-2.0+
 Summary:        Connection Manager
 Url:            http://connman.net
@@ -153,6 +153,7 @@ chmod +x bootstrap
            --sysconfdir=/etc \
            --enable-client \
            --enable-tizen-ext \
+           --disable-tizen-ext-ins \
            --enable-pacrunner \
             --enable-wifi=builtin \
 %if %{with connman_openconnect}
index 833e09a..a260839 100755 (executable)
@@ -727,6 +727,9 @@ void __connman_service_cleanup(void);
 int __connman_service_load_modifiable(struct connman_service *service);
 
 void __connman_service_list_struct(DBusMessageIter *iter);
+#if defined TIZEN_EXT_INS
+void __connman_ins_list_struct(DBusMessageIter *iter);
+#endif
 
 #if defined TIZEN_EXT
 int connman_service_get_ipv6_dns_method(struct connman_service *service);
old mode 100644 (file)
new mode 100755 (executable)
index 583b2ad..0b232ec
@@ -216,6 +216,28 @@ static DBusMessage *get_services(DBusConnection *conn,
        return reply;
 }
 
+#if defined TIZEN_EXT_INS
+static void append_ins_structs(DBusMessageIter *iter, void *user_data)
+{
+       __connman_ins_list_struct(iter);
+}
+
+static DBusMessage *get_ins(DBusConnection *conn,
+                                       DBusMessage *msg, void *data)
+{
+       DBusMessage *reply;
+
+       reply = dbus_message_new_method_return(msg);
+       if (!reply)
+               return NULL;
+
+       __connman_dbus_append_objpath_dict_array(reply,
+                       append_ins_structs, NULL);
+
+       return reply;
+}
+#endif
+
 static void append_peer_structs(DBusMessageIter *iter, void *user_data)
 {
        __connman_peer_list_struct(iter);
@@ -666,6 +688,11 @@ static const GDBusMethodTable manager_methods[] = {
        { GDBUS_METHOD("GetServices",
                        NULL, GDBUS_ARGS({ "services", "a(oa{sv})" }),
                        get_services) },
+#if defined TIZEN_EXT_INS
+       { GDBUS_METHOD("GetINS",
+                       NULL, GDBUS_ARGS({ "services", "a(oa{sv})" }),
+                       get_ins) },
+#endif
        { GDBUS_METHOD("GetPeers",
                        NULL, GDBUS_ARGS({ "peers", "a(oa{sv})" }),
                        get_peers) },
index 606ef7d..3f6a003 100755 (executable)
@@ -49,6 +49,9 @@
 #define FREQ_RANGE_24GHZ_CHANNEL_14  2484
 #define FREQ_RANGE_5GHZ_CHANNEL_32   5160
 #define FREQ_RANGE_5GHZ_CHANNEL_165  5825
+
+#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
+#define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
 #endif
 
 static DBusConnection *connection = NULL;
@@ -227,6 +230,14 @@ struct connman_service {
        unsigned char last_connected_bssid[WIFI_BSSID_LEN_MAX];
        bool is_internet_connection;
        int assoc_reject_count;
+#if defined TIZEN_EXT_INS
+       int score_last_user_selection;
+       int score_last_connected;
+       int score_frequency;
+       int score_security_priority;
+       int score_internet_connection;
+       int score_strength;
+#endif
        int ins_score;
 #endif
 };
@@ -751,7 +762,6 @@ static int service_ext_load(struct connman_service *service)
                                continue;
                        }
 
-                       memset(reject_data, 0, sizeof(struct assoc_reject_data));
                        reject_data->bssid = g_strdup(bssid);
                        g_hash_table_insert(reject_table, reject_data->bssid, reject_data);
                }
@@ -3887,9 +3897,7 @@ static void append_wifi_ext_info(DBusMessageIter *dict,
        country_code = connman_network_get_countrycode(network);
        connection_mode = connman_network_get_connection_mode(network);
 
-       snprintf(bssid_str, WIFI_BSSID_STR_LEN, "%02x:%02x:%02x:%02x:%02x:%02x",
-                               bssid[0], bssid[1], bssid[2],
-                               bssid[3], bssid[4], bssid[5]);
+       snprintf(bssid_str, WIFI_BSSID_STR_LEN, MACSTR, MAC2STR(bssid));
 
        snprintf(country_code_str, (WIFI_COUNTRY_CODE_LEN + 1), "%c%c",
                 country_code[0], country_code[1]);
@@ -3965,9 +3973,7 @@ static void append_bssid_info(DBusMessageIter *iter, void *user_data)
                GSList *list;
                for (list = bssid_list; list; list = list->next) {
                        bssids = (struct connman_bssids *)list->data;
-                       g_snprintf(bssid_buf, MAC_ADDRESS_LENGTH, "%02x:%02x:%02x:%02x:%02x:%02x",
-                                       bssids->bssid[0], bssids->bssid[1], bssids->bssid[2],
-                                       bssids->bssid[3], bssids->bssid[4], bssids->bssid[5]);
+                       g_snprintf(bssid_buf, MAC_ADDRESS_LENGTH, MACSTR, MAC2STR(bssids->bssid));
 
                        connman_dbus_dict_append_basic(iter, "BSSID",
                                        DBUS_TYPE_STRING, &bssid_str);
@@ -4168,6 +4174,99 @@ static void append_properties(DBusMessageIter *dict, dbus_bool_t limited,
                connman_network_append_acddbus(dict, service->network);
 }
 
+#if defined TIZEN_EXT_INS
+static void append_ins_bssid_info(DBusMessageIter *iter, void *user_data)
+{
+       GSList *bssid_list = NULL;
+       struct connman_network *network = user_data;
+       struct connman_bssids *bssids;
+       char bssid_buf[MAC_ADDRESS_LENGTH] = {0,};
+       char *bssid_str = bssid_buf;
+
+       bssid_list = (GSList *)connman_network_get_bssid_list(network);
+       if(bssid_list) {
+               GSList *list;
+               for (list = bssid_list; list; list = list->next) {
+                       bssids = (struct connman_bssids *)list->data;
+                       g_snprintf(bssid_buf, MAC_ADDRESS_LENGTH, MACSTR, MAC2STR(bssids->bssid));
+
+                       connman_dbus_dict_append_basic(iter, "BSSID",
+                                       DBUS_TYPE_STRING, &bssid_str);
+
+                       connman_dbus_dict_append_basic(iter, "ScoreINS",
+                                       DBUS_TYPE_INT32, &bssids->ins_score);
+
+                       connman_dbus_dict_append_basic(iter, "ScoreLastConnected",
+                                       DBUS_TYPE_INT32, &bssids->score_last_connected_bssid);
+
+                       connman_dbus_dict_append_basic(iter, "ScoreAssocReject",
+                                       DBUS_TYPE_INT32, &bssids->score_assoc_reject);
+
+                       connman_dbus_dict_append_basic(iter, "Frequency",
+                                       DBUS_TYPE_UINT16, &bssids->frequency);
+
+                       connman_dbus_dict_append_basic(iter, "ScoreFrequency",
+                                       DBUS_TYPE_INT32, &bssids->score_frequency);
+
+                       connman_dbus_dict_append_basic(iter, "Strength",
+                                       DBUS_TYPE_UINT16, &bssids->strength);
+
+                       connman_dbus_dict_append_basic(iter, "ScoreStrength",
+                                       DBUS_TYPE_INT32, &bssids->score_strength);
+               }
+       }
+}
+
+static void append_ins_properties(DBusMessageIter *dict,
+                                       struct connman_service *service)
+{
+       const char *str;
+       unsigned int frequency = 0U;
+
+       if (service->name)
+               connman_dbus_dict_append_basic(dict, "Name",
+                                       DBUS_TYPE_STRING, &service->name);
+
+       connman_dbus_dict_append_basic(dict, "ScoreINS",
+                               DBUS_TYPE_INT32, &service->ins_score);
+
+       connman_dbus_dict_append_basic(dict, "ScoreLastUserSelection",
+                               DBUS_TYPE_INT32, &service->score_last_user_selection);
+
+       connman_dbus_dict_append_basic(dict, "ScoreLastConnected",
+                               DBUS_TYPE_INT32, &service->score_last_connected);
+
+       str = security2string(service->security);
+       if (str)
+               connman_dbus_dict_append_basic(dict, "Security",
+                               DBUS_TYPE_STRING, &str);
+
+       connman_dbus_dict_append_basic(dict, "ScoreSecurityPriority",
+                               DBUS_TYPE_INT32, &service->score_security_priority);
+
+       connman_dbus_dict_append_basic(dict, "Strength",
+                               DBUS_TYPE_BYTE, &service->strength);
+
+       connman_dbus_dict_append_basic(dict, "ScoreStrength",
+                               DBUS_TYPE_INT32, &service->score_strength);
+
+       connman_dbus_dict_append_basic(dict, "ScoreInternetConnection",
+                               DBUS_TYPE_INT32, &service->score_internet_connection);
+
+       if (service->network) {
+               frequency = connman_network_get_frequency(service->network);
+               connman_dbus_dict_append_basic(dict, "Frequency",
+                               DBUS_TYPE_UINT16, &frequency);
+
+               connman_dbus_dict_append_basic(dict, "ScoreFrequency",
+                               DBUS_TYPE_INT32, &service->score_frequency);
+
+               connman_dbus_dict_append_dict(dict, "BSSID.List",
+                               append_ins_bssid_info, service->network);
+       }
+}
+#endif
+
 static void append_struct_service(DBusMessageIter *iter,
                connman_dbus_append_cb_t function,
                struct connman_service *service)
@@ -4210,6 +4309,34 @@ void __connman_service_list_struct(DBusMessageIter *iter)
        g_list_foreach(service_list, append_struct, iter);
 }
 
+#if defined TIZEN_EXT_INS
+static void append_dict_ins_properties(DBusMessageIter *dict, void *user_data)
+{
+       struct connman_service *service = user_data;
+
+       append_ins_properties(dict, service);
+}
+
+static void append_ins_struct(gpointer value, gpointer user_data)
+{
+       struct connman_service *service = value;
+       DBusMessageIter *iter = user_data;
+
+       if (!service->path)
+               return;
+
+       if (service->type != CONNMAN_SERVICE_TYPE_WIFI)
+               return;
+
+       append_struct_service(iter, append_dict_ins_properties, service);
+}
+
+void __connman_ins_list_struct(DBusMessageIter *iter)
+{
+       g_list_foreach(service_list, append_ins_struct, iter);
+}
+#endif
+
 bool __connman_service_is_hidden(struct connman_service *service)
 {
        return service->hidden;
@@ -7238,6 +7365,12 @@ static int calculate_score_strength(struct connman_service *service)
 
 static int calculate_score(struct connman_service *service)
 {
+       int score_last_user_selection;
+       int score_last_connected;
+       int score_frequency;
+       int score_security_priority;
+       int score_internet_connection;
+       int score_strength;
        int score = 0;
 
        if (service->type != CONNMAN_SERVICE_TYPE_WIFI) {
@@ -7246,12 +7379,25 @@ static int calculate_score(struct connman_service *service)
                return score;
        }
 
-       score += calculate_score_last_user_selection(service);
-       score += calculate_score_last_connected(service);
-       score += calculate_score_frequency(service);
-       score += calculate_score_security_priority(service);
-       score += calculate_score_internet_connection(service);
-       score += calculate_score_strength(service);
+       score_last_user_selection = calculate_score_last_user_selection(service);
+       score_last_connected = calculate_score_last_connected(service);
+       score_frequency = calculate_score_frequency(service);
+       score_security_priority = calculate_score_security_priority(service);
+       score_internet_connection = calculate_score_internet_connection(service);
+       score_strength = calculate_score_strength(service);
+
+       score = score_last_user_selection + score_last_connected +
+               score_frequency + score_security_priority +
+               score_internet_connection + score_strength;
+
+#if defined TIZEN_EXT_INS
+       service->score_last_user_selection = score_last_user_selection;
+       service->score_last_connected = score_last_connected;
+       service->score_frequency = score_frequency;
+       service->score_security_priority = score_security_priority;
+       service->score_internet_connection = score_internet_connection;
+       service->score_strength = score_strength;
+#endif
 
        service->ins_score = score;
        return score;
@@ -7376,32 +7522,16 @@ static gint service_compare(gconstpointer a, gconstpointer b)
 static void print_service_sort(gpointer data, gpointer user_data)
 {
        struct connman_service *service = data;
-       struct connman_device *device;
-       const char *last_user_selection_ident;
-       const char *last_connected_ident;
-       unsigned int frequency;
-       time_t ref_time;
-       struct tm* timeinfo;
-       time_t last_user_selection_time;
 
-       device = connman_network_get_device(service->network);
-       last_user_selection_ident = connman_device_get_last_user_selection_ident(device);
-       last_user_selection_time = connman_device_get_last_user_selection_time(device);
-       last_connected_ident = connman_device_get_last_connected_ident(device);
-       frequency = connman_network_get_frequency(service->network);
+       if (service->type != CONNMAN_SERVICE_TYPE_WIFI)
+               return;
 
-       /* Only events that occur within 8 hours are checked. */
-       ref_time = time(NULL);
-       timeinfo = localtime(&ref_time);
-       timeinfo->tm_hour -= 8;
-       ref_time = mktime(timeinfo);
-
-       DBG("name[%s] score[%d] strength[%d] freq[%d] last_usr[%d] last_conn[%d] internet[%d]",
-               service->name, service->ins_score, service->strength, frequency,
-               (g_strcmp0(last_user_selection_ident, service->identifier) == 0 &&
-               last_user_selection_time > ref_time) ? 1 : 0,
-               g_strcmp0(last_connected_ident, service->identifier) == 0 ? 1 : 0,
-               service->is_internet_connection);
+       DBG("name[%-20s] total[%2d] last_usr[%2d] last_conn[%2d] "
+               "freq[%2d] sec[%2d] internet[%2d] strength[%2d]",
+               service->name, service->ins_score, service->score_last_user_selection,
+               service->score_last_connected, service->score_frequency,
+               service->score_security_priority, service->score_internet_connection,
+               service->score_strength);
 }
 #endif