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;
}
}
}
+
+ 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)
}
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)
}
}
-
-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");