Add Client device info for P2P_Tethering feature. 13/136913/1
authorMilind Ramesh Murhekar <m.murhekar@samsung.com>
Mon, 3 Jul 2017 11:50:44 +0000 (17:20 +0530)
committerMilind Ramesh Murhekar <m.murhekar@samsung.com>
Mon, 3 Jul 2017 11:50:44 +0000 (17:20 +0530)
Description: This patch adds the changes to store/remove
connected client info, when client gets connected to
P2P Tethering.

Change-Id: Ie35db786557f7195b26eaf307b0dd2a1b90014f9
Signed-off-by: Milind Ramesh Murhekar <m.murhekar@samsung.com>
include/mobileap_dbus.h
include/mobileap_wfd.h
packaging/mobileap-agent.spec
src/gdbus/mobileap_dbus.c
src/mobileap_p2p.c
src/mobileap_wfd.c

index dd63ea2..344b0b9 100644 (file)
@@ -81,7 +81,9 @@ typedef struct {
        void (*online)();
 } networkCallbacks;
 
-typedef void (*wfd_client_callback)(const gchar *signal, int error, void *user_data);
+typedef void (*wfd_client_callback)(const gchar *signal,
+                                                                        GVariant *parameters,
+                                                                        void *user_data);
 
 void mobileap_gdbus_pending_call_ref(void);
 void mobileap_gdbus_pending_call_unref(void);
index e51bb7c..439a7c3 100644 (file)
@@ -34,8 +34,12 @@ typedef struct {
        void *group_created_cb_user_data;
        void (*group_destroyed_cb)(int error, void *user_data);
        void *group_destroyed_cb_user_data;
-       void (*disconnection_cb)(int error, void *user_data);
+       void (*disconnection_cb)(GVariant *parameters, void *user_data);
        void *disconnection_cb_user_data;
+       void (*connection_cb)(GVariant *parameters, void *user_data);
+       void *connection_cb_user_data;
+       void (*ip_assigned_cb)(GVariant *parameters, void *user_data);
+       void *ip_assigned_cb_user_data;
 } wfd_callback_t;
 
 void wfd_client_register_callback(wfd_callback_t *cb_data);
index ebad2ae..ef0a127 100644 (file)
@@ -1,6 +1,6 @@
 Name: mobileap-agent
 Summary: Mobile AP daemon for setting tethering environments
-Version: 1.0.100
+Version: 1.0.101
 Release: 1
 Group: System/Network
 License: Apache-2.0
index bd48799..de23fc9 100644 (file)
@@ -169,16 +169,10 @@ static void wfd_dbus_signal_handler(GDBusConnection *connection,
                          GVariant *parameters,
                          gpointer user_data)
 {
-       int error = 0;
-       if (parameters)
-               g_variant_get(parameters, "(i)", &error);
-
        DBG("signal [%s]", signal);
 
-       if (mobileap_dbus.wfd_client) {
-               DBG("+");
-               mobileap_dbus.wfd_client(signal, error, NULL);
-       }
+       if (mobileap_dbus.wfd_client)
+               mobileap_dbus.wfd_client(signal, parameters, NULL);
 }
 
 void mobileap_gdbus_pending_call_ref(void)
index 7916ea3..d647917 100644 (file)
@@ -260,11 +260,16 @@ static void p2p_group_created(int error, void *user_data)
 static void p2p_group_destoyed(int error, void *user_data)
 {
        DBG("Group Destroyed");
+       _remove_station_info_all(MOBILE_AP_TYPE_P2P);
 }
 
-static void p2p_disconnection(int error, void *user_data)
+static void p2p_disconnection(GVariant *parameters, void *user_data)
 {
        int ret;
+       int error;
+       wifi_direct_connection_state_e state;
+       const gchar *peer_mac;
+
        DBG("Disconnection");
        request_data_t *request_data = user_data;
 
@@ -290,6 +295,91 @@ static void p2p_disconnection(int error, void *user_data)
                        }
                }
        }
+
+       if (!parameters)
+               return;
+
+       g_variant_get(parameters, "(ii&s)", &error, &state, &peer_mac);
+
+       if (state == WIFI_DIRECT_DISCONNECTION_IND) {
+               DBG("client disconnected: [%s]", peer_mac);
+               _remove_station_info(peer_mac, _slist_find_station_by_mac);
+       } else if (state == WIFI_DIRECT_DISCONNECTION_RSP) {
+               DBG("remove all clients info !!");
+               _remove_station_info_all(MOBILE_AP_TYPE_P2P);
+       }
+}
+
+static void p2p_connection(GVariant *parameters, void *user_data)
+{
+       int error;
+       const gchar *peer_mac = NULL;
+       wifi_direct_connection_state_e state;
+       mobile_ap_station_info_t *info = NULL;
+       time_t tm;
+
+       if (!parameters)
+               return;
+
+       if (_mobileap_is_enabled_by_type(MOBILE_AP_TYPE_P2P) == FALSE)
+               return;
+
+       g_variant_get(parameters, "(ii&s)", &error, &state, &peer_mac);
+
+       if (state != WIFI_DIRECT_CONNECTION_RSP)
+               return;
+
+       if (peer_mac == NULL) {
+               ERR("Client mac is NULL !!!");
+               return;
+       }
+
+       DBG("client connected: [%s]", peer_mac);
+       info = (mobile_ap_station_info_t *)g_malloc(sizeof(mobile_ap_station_info_t));
+       if (info == NULL) {
+               ERR("malloc failed\n");
+               return;
+       }
+
+       info->interface = MOBILE_AP_TYPE_P2P;
+       g_strlcpy(info->ip, "0.0.0.0", sizeof(info->ip));
+       g_strlcpy(info->mac, peer_mac, sizeof(info->mac));
+       info->hostname = g_strdup(MOBILE_AP_NAME_UNKNOWN);
+       time(&tm);
+       info->tm = tm;
+
+       /* Add the client station here,
+          since station is now associated to the p2p group */
+       if (_add_station_info(info) != MOBILE_AP_ERROR_NONE) {
+               ERR("_add_station_info is failed\n");
+               if (info) {
+                       g_free(info->hostname);
+                       g_free(info);
+               }
+               return;
+       }
+}
+
+static void p2p_ip_assigned(GVariant *parameters, void *user_data)
+{
+       const gchar *peer_mac = NULL;
+       const gchar *ip_assigned = NULL;
+       mobile_ap_station_info_t *info = NULL;
+
+       if (!parameters)
+               return;
+
+       g_variant_get(parameters, "(&s&s)", &peer_mac, &ip_assigned);
+
+       if (_get_station_info(peer_mac, _slist_find_station_by_mac, &info) !=
+                       MOBILE_AP_ERROR_NONE) {
+               ERR("client not found with mac [%s]", peer_mac);
+               return;
+       }
+
+       g_strlcpy(info->ip, ip_assigned, sizeof(info->ip));
+       DBG("client ip assigned: mac [%s] ip [%s]", peer_mac, ip_assigned);
+       _send_dbus_station_info("DhcpConnected", info);
 }
 
 static int activate_wifi_direct(request_data_t *request_data)
@@ -333,16 +423,20 @@ static int activate_wifi_direct(request_data_t *request_data)
 }
 
 static wfd_callback_t callback_data = {
-       .activated_cb = p2p_activated,             /* P2P Activated Callback   */
+       .activated_cb = p2p_activated,             /** P2P Activated Callback */
        .activated_cb_user_data = NULL,
-       .deactivated_cb = p2p_deactivated,         /* P2P Deactivated Callback */
+       .deactivated_cb = p2p_deactivated,         /** P2P Deactivated Callback */
        .deactivated_cb_user_data = NULL,
-       .group_created_cb = p2p_group_created,     /* Group Created Callback   */
+       .group_created_cb = p2p_group_created,     /** Group Created Callback */
        .group_created_cb_user_data = NULL,
-       .group_destroyed_cb = p2p_group_destoyed,  /* Group Destroyed Callback */
+       .group_destroyed_cb = p2p_group_destoyed,  /** Group Destroyed Callback */
        .group_destroyed_cb_user_data = NULL,
-       .disconnection_cb = p2p_disconnection,     /* Disconnection Callback   */
+       .disconnection_cb = p2p_disconnection,     /** Disconnection Callback */
        .disconnection_cb_user_data = NULL,
+       .connection_cb = p2p_connection,           /** Connection Callback */
+       .connection_cb_user_data = NULL,
+       .ip_assigned_cb = p2p_ip_assigned,         /** IP Assigned Callback */
+       .ip_assigned_cb_user_data = NULL,
 };
 
 static void init_p2p_events(void)
index 54f5786..8d9c650 100644 (file)
@@ -55,30 +55,49 @@ static char *get_state_str(int state)
        }
 }
 
-
-static void wfd_client_event_handler(const gchar *signal, int error, void *user_data)
+static void wfd_client_event_handler(const gchar *signal, GVariant *parameters, void *user_data)
 {
        DBG("+");
+
+       int error = 0;
+
        if (wfd_callback == NULL) {
                ERR("callback not registered");
                return;
        }
 
        if (!g_strcmp0("Activation", signal)) {
+               if (parameters)
+                       g_variant_get(parameters, "(i)", &error);
+
                if (wfd_callback->activated_cb)
                        wfd_callback->activated_cb(error, wfd_callback->activated_cb_user_data);
        } else if (!g_strcmp0("Deactivation", signal)) {
+               if (parameters)
+                       g_variant_get(parameters, "(i)", &error);
+
                if (wfd_callback->deactivated_cb)
                        wfd_callback->deactivated_cb(error, wfd_callback->deactivated_cb_user_data);
        } else if (!g_strcmp0("Disconnection", signal)) {
                if (wfd_callback->disconnection_cb)
-                       wfd_callback->disconnection_cb(error, wfd_callback->disconnection_cb_user_data);
+                       wfd_callback->disconnection_cb(parameters, wfd_callback->disconnection_cb_user_data);
        } else if (!g_strcmp0("Created", signal)) {
+                       if (parameters)
+                               g_variant_get(parameters, "(i)", &error);
                if (wfd_callback->group_created_cb)
                        wfd_callback->group_created_cb(error, wfd_callback->group_created_cb_user_data);
        } else if (!g_strcmp0("Destroyed", signal)) {
+               if (parameters)
+                       g_variant_get(parameters, "(i)", &error);
+
                if (wfd_callback->group_destroyed_cb)
                        wfd_callback->group_destroyed_cb(error, wfd_callback->group_destroyed_cb_user_data);
+       } else if (!g_strcmp0("Connection", signal)) {
+               if (wfd_callback->connection_cb)
+                       wfd_callback->connection_cb(parameters, NULL);
+       } else if (!g_strcmp0("PeerIPAssigned", signal)) {
+               if (wfd_callback->ip_assigned_cb)
+                       wfd_callback->ip_assigned_cb(parameters, NULL);
        } else
                DBG("Unknown event");