[Support Legacy Connection] Identify legacy peer connection. 61/71761/2
authorNishant Chaprana <n.chaprana@samsung.com>
Fri, 27 May 2016 04:49:23 +0000 (10:19 +0530)
committerNishant Chaprana <n.chaprana@samsung.com>
Thu, 2 Jun 2016 07:18:15 +0000 (12:48 +0530)
1. This patch identifies whether a legacy peer connection/disconnection
2. This patch also allows legacy peer to connect to Tizen device.

Change-Id: I9b7148dd60bc96796b3a27373020fbffd0d06d0e
Signed-off-by: Nishant Chaprana <n.chaprana@samsung.com>
include/wifi-direct-util.h
packaging/wifi-direct-manager.spec
plugin/wpasupplicant/ctrl_iface_dbus/wfd-plugin-wpasupplicant.c
src/wifi-direct-event.c

index d5a6069..ffcafa4 100755 (executable)
@@ -34,6 +34,7 @@
 #define IPSTR "%d.%d.%d.%d"
 #define ZEROIP "0.0.0.0"
 #define ISZEROIP(a) !(a[0] | a[1] | a[2] | a[3])
+#define ISZEROMACADDR(a) !(a[0] | a[1] | a[2] | a[3] | a[4] | a[5])
 #define MAC2SECSTR(a) (a)[0], (a)[4], (a)[5]
 #define MACSECSTR "%02x:%02x:%02x"
 #define IP2SECSTR(a) (a)[0], (a)[3]
index cdbfc21..11bfa94 100755 (executable)
@@ -1,6 +1,6 @@
 Name:          wifi-direct-manager
 Summary:       Wi-Fi Direct manger
-Version:       1.2.161
+Version:       1.2.162
 Release:       1
 Group:      Network & Connectivity/Wireless
 License:    Apache-2.0
index a31cf99..a9a5567 100755 (executable)
@@ -154,6 +154,9 @@ static wfd_oem_ops_s supplicant_ops = {
 
 static ws_dbus_plugin_data_s *g_pd;
 
+static int is_peer_joined_notified = 0;
+static int is_peer_disconnected_notified = 0;
+
 #ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
 static GList *service_list;
 #endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
@@ -172,6 +175,10 @@ static void _group_signal_cb(GDBusConnection *connection,
                const gchar *sender, const gchar *object_path, const gchar *interface,
                const gchar *signal, GVariant *parameters, gpointer user_data);
 
+static void _interface_signal_cb(GDBusConnection *connection,
+               const gchar *sender, const gchar *object_path, const gchar *interface,
+               const gchar *signal, GVariant *parameters, gpointer user_data);
+
 static int __ws_txt_to_mac(unsigned char *txt, unsigned char *mac)
 {
        int i = 0;
@@ -2681,6 +2688,100 @@ static void _p2pdevice_signal_cb(GDBusConnection *connection,
 }
 
 
+static void _ws_process_sta_authorized(GDBusConnection *connection,
+               const gchar *object_path, GVariant *parameters)
+{
+       __WDP_LOG_FUNC_ENTER__;
+       wfd_oem_event_s event;
+       const gchar* mac_str = NULL;
+
+       if (is_peer_joined_notified) {
+               is_peer_joined_notified = 0;
+               __WDP_LOG_FUNC_EXIT__;
+               return;
+       }
+
+       memset(&event, 0x0, sizeof(wfd_oem_event_s));
+       g_variant_get(parameters, "(&s)", &mac_str);
+       __ws_txt_to_mac((unsigned char *)mac_str, event.intf_addr);
+
+       event.event_id = WFD_OEM_EVENT_STA_CONNECTED;
+       event.edata_type = WFD_OEM_EDATA_TYPE_NONE;
+
+       g_pd->callback(g_pd->user_data, &event);
+       __WDP_LOG_FUNC_EXIT__;
+}
+
+static void _ws_process_sta_deauthorized(GDBusConnection *connection,
+               const gchar *object_path, GVariant *parameters)
+{
+       __WDP_LOG_FUNC_ENTER__;
+       wfd_oem_event_s event;
+       const gchar* mac_str = NULL;
+
+       if (is_peer_disconnected_notified) {
+               is_peer_disconnected_notified = 0;
+               __WDP_LOG_FUNC_EXIT__;
+               return;
+       }
+
+       memset(&event, 0x0, sizeof(wfd_oem_event_s));
+       g_variant_get(parameters, "(&s)", &mac_str);
+       __ws_txt_to_mac((unsigned char *)mac_str, event.intf_addr);
+
+       event.event_id = WFD_OEM_EVENT_STA_DISCONNECTED;
+       event.edata_type = WFD_OEM_EDATA_TYPE_NONE;
+
+       g_pd->callback(g_pd->user_data, &event);
+       __WDP_LOG_FUNC_EXIT__;
+}
+
+static struct {
+       const char *interface;
+       const char *member;
+       void (*function) (GDBusConnection *connection,const gchar *object_path,
+                       GVariant *parameters);
+} ws_interface_signal_map[] = {
+       {
+               SUPPLICANT_INTERFACE,
+               "StaAuthorized",
+               _ws_process_sta_authorized
+       },
+       {
+               SUPPLICANT_INTERFACE,
+               "StaDeauthorized",
+               _ws_process_sta_deauthorized
+       },
+       {
+               NULL,
+               NULL,
+               NULL
+       }
+};
+
+static void _interface_signal_cb(GDBusConnection *connection,
+               const gchar *sender, const gchar *object_path, const gchar *interface,
+               const gchar *signal, GVariant *parameters, gpointer user_data)
+{
+       int i = 0;
+#if defined (TIZEN_DEBUG_DBUS_VALUE)
+       DEBUG_SIGNAL(sender, object_path, interface, signal, parameters);
+#endif /* TIZEN_DEBUG_DBUS_VALUE */
+
+       if (!g_pd) {
+               WDP_LOGE("ws_dbus_plugin_data_s is not created yet");
+               __WDP_LOG_FUNC_EXIT__;
+               return;
+       }
+
+       for (i = 0; ws_interface_signal_map[i].member != NULL; i++) {
+               if (!g_strcmp0(signal, ws_interface_signal_map[i].member) &&
+                               ws_interface_signal_map[i].function != NULL)
+                       ws_interface_signal_map[i].function(connection, object_path, parameters);
+       }
+}
+
+
 static void __ws_parse_peer_joined(char *peer_path,
                unsigned char *dev_addr, unsigned char *ip_addr, GVariant *parameter)
 {
@@ -2755,6 +2856,8 @@ static void _group_signal_cb(GDBusConnection *connection,
                                __ws_peer_property, event.edata);
 
                g_pd->callback(g_pd->user_data, &event);
+               is_peer_joined_notified = 1;
+
                g_free(edata);
 
        } else if (!g_strcmp0(signal,"PeerDisconnected")) {
@@ -2771,6 +2874,7 @@ static void _group_signal_cb(GDBusConnection *connection,
                __ws_path_to_addr(peer_path, event.dev_addr, parameters);
 
                g_pd->callback(g_pd->user_data, &event);
+               is_peer_disconnected_notified = 1;
        }
 }
 
@@ -2793,7 +2897,21 @@ static void __register_p2pdevice_signal(GVariant *value, void *user_data)
        g_strlcpy(pd_data->iface_path, path, DBUS_OBJECT_PATH_MAX);
 
        WDP_LOGD("interface object path [%s]", interface_path);
-       /* subscribe interface p2p signal */
+
+       /* subscribe Interface iface signal */
+       WDP_LOGD("Register Interface iface signal");
+       pd_data->p2pdevice_sub_id = g_dbus_connection_signal_subscribe(
+               pd_data->g_dbus,
+               SUPPLICANT_SERVICE, /* bus name */
+               SUPPLICANT_IFACE, /* interface */
+               NULL, /* member */
+               NULL, /* object path */
+               NULL, /* arg0 */
+               G_DBUS_SIGNAL_FLAGS_NONE,
+               _interface_signal_cb,
+               NULL, NULL);
+
+       /* subscribe P2PDevice iface signal */
        WDP_LOGD("register P2PDevice iface signal");
        pd_data->p2pdevice_sub_id = g_dbus_connection_signal_subscribe(
                pd_data->g_dbus,
index ea88d4b..937dc6b 100755 (executable)
@@ -979,9 +979,9 @@ static void __wfd_process_sta_connected(wfd_manager_s *manager, wfd_oem_event_s
 {
        __WDS_LOG_FUNC_ENTER__;
 
-       wfd_session_s *session = NULL;
+       wfd_session_s *session = (wfd_session_s*) manager->session;
+       wfd_group_s *group = (wfd_group_s*) manager->group;
        wfd_device_s *peer = NULL;
-       wfd_group_s *group = NULL;
        char peer_mac_address[MACSTR_LEN+1] = {0, };
 
        // FIXME: Move this code to plugin
@@ -991,6 +991,12 @@ static void __wfd_process_sta_connected(wfd_manager_s *manager, wfd_oem_event_s
                return;
        }
 
+       if (ISZEROMACADDR(event->dev_addr)) {
+               WDS_LOGD("Legacy Peer Connected [Peer: " MACSTR "]", MAC2STR(event->intf_addr));
+               __WDS_LOG_FUNC_EXIT__;
+               return;
+       }
+
        session = (wfd_session_s*) manager->session;
        if (!session) {
                WDS_LOGD("Unexpected event. Session is NULL [peer: " MACSECSTR "]",
@@ -1086,6 +1092,12 @@ static void __wfd_process_sta_disconnected(wfd_manager_s *manager, wfd_oem_event
                return;
        }
 
+       if (ISZEROMACADDR(event->dev_addr)) {
+               WDS_LOGD("Legacy Peer Disconnected [Peer: " MACSTR "]", MAC2STR(event->intf_addr));
+               __WDS_LOG_FUNC_EXIT__;
+               return;
+       }
+
 #ifdef CTRL_IFACE_DBUS
        peer = wfd_group_find_member_by_addr(group, event->dev_addr);
 #else /* CTRL_IFACE_DBUS */
@@ -1117,9 +1129,10 @@ static void __wfd_process_sta_disconnected(wfd_manager_s *manager, wfd_oem_event
        }
        memcpy(peer_addr, peer->dev_addr, MACADDR_LEN);
 
-       /* If state is not DISCONNECTING, connection is finished by peer.
-       *  Required the check also, when Device is Group Owner and state is DISCOVERING.
-       */
+       /**
+        * If state is not DISCONNECTING, connection is finished by peer.
+        *  Required the check also, when Device is Group Owner and state is DISCOVERING.
+        */
        if (manager->state >= WIFI_DIRECT_STATE_CONNECTED ||
                                (manager->state == WIFI_DIRECT_STATE_DISCOVERING &&
                                 manager->local->dev_role == WFD_DEV_ROLE_GO)) {