From 893f66af9e6d8a069f0e4d01448c4649bb1dc97c Mon Sep 17 00:00:00 2001 From: Nishant Chaprana Date: Thu, 9 Jun 2016 10:53:42 +0530 Subject: [PATCH] [Support Legacy Connection] Update peer disconnection logic. This patch adds disconnection logic for legacy peer. This patch also updates peer disconnection logic as per latest release supplicant. 1. Dbus interface : RemoveClient method call is used to disconnect. 2. CTRL interface : P2P_REMOVE_CLIENT call is used to disconnect. Change-Id: I58146bb04e32707a7bf27b78d734ed6375f58f96 Signed-off-by: Nishant Chaprana --- files/wifi-direct-dhcp.sh.in | 7 +++++- include/wifi-direct-manager.h | 1 + oem/wifi-direct-oem.c | 4 +-- oem/wifi-direct-oem.h | 4 +-- packaging/wifi-direct-manager.spec | 2 +- .../include/wfd-plugin-wpasupplicant.h | 2 +- .../ctrl_iface_dbus/wfd-plugin-wpasupplicant.c | 29 ++++++++++++++++------ .../include/wfd-plugin-wpasupplicant.h | 5 ++-- .../ctrl_iface_sock/wfd-plugin-wpasupplicant.c | 21 ++++++++++++---- .../emul/include/wfd-plugin-wpasupplicant.h | 2 +- .../emul/wfd-plugin-wpasupplicant-emul.c | 2 +- src/wifi-direct-event.c | 1 + src/wifi-direct-manager.c | 27 ++++++-------------- src/wifi-direct-peer.c | 1 + 14 files changed, 64 insertions(+), 44 deletions(-) diff --git a/files/wifi-direct-dhcp.sh.in b/files/wifi-direct-dhcp.sh.in index baa98af..90545b3 100644 --- a/files/wifi-direct-dhcp.sh.in +++ b/files/wifi-direct-dhcp.sh.in @@ -78,7 +78,12 @@ stop_dhcp() echo "interface(${INTERFACE_PREFIX}) is not up" return 0 fi - @SBIN_DIR@/ip addr del ${local_ip_net} dev ${interface} + + if [ ! -f @SBIN_DIR@/ip ]; then + @SBIN_DIR@/ifconfig ${interface} "0.0.0.0" + else + @SBIN_DIR@/ip addr del ${local_ip_net} dev ${interface} + fi } is_running() diff --git a/include/wifi-direct-manager.h b/include/wifi-direct-manager.h index e47f8d4..ecaa8ae 100755 --- a/include/wifi-direct-manager.h +++ b/include/wifi-direct-manager.h @@ -147,6 +147,7 @@ typedef struct { int dev_flags; int group_flags; int wps_mode; + int is_legacy; char passphrase[PASSPHRASE_LEN_MAX + 1]; diff --git a/oem/wifi-direct-oem.c b/oem/wifi-direct-oem.c index 9b87b60..2c0d656 100644 --- a/oem/wifi-direct-oem.c +++ b/oem/wifi-direct-oem.c @@ -145,12 +145,12 @@ int wfd_oem_cancel_connection(wfd_oem_ops_s *ops, unsigned char *peer_addr) return ops->cancel_connection(peer_addr); } -int wfd_oem_disconnect(wfd_oem_ops_s *ops, unsigned char *peer_addr) +int wfd_oem_disconnect(wfd_oem_ops_s *ops, unsigned char *peer_addr, int is_iface_addr) { if (!ops || !ops->disconnect) return -1; - return ops->disconnect(peer_addr); + return ops->disconnect(peer_addr, is_iface_addr); } int wfd_oem_get_connected_peers(wfd_oem_ops_s *ops, GList **peers, int *peer_count) diff --git a/oem/wifi-direct-oem.h b/oem/wifi-direct-oem.h index 3bb2f45..95cbecb 100755 --- a/oem/wifi-direct-oem.h +++ b/oem/wifi-direct-oem.h @@ -555,7 +555,7 @@ typedef struct _wfd_oem_ops_s { int (*get_peer_info) (unsigned char *peer_addr, wfd_oem_device_s **peer); int (*prov_disc_req) (unsigned char *peer_addr, wfd_oem_wps_mode_e wps_mode, int join); int (*connect) (unsigned char *peer_addr, wfd_oem_conn_param_s *param); - int (*disconnect) (unsigned char *peer_addr); + int (*disconnect) (unsigned char *peer_addr, int is_iface_addr); int (*reject_connection) (unsigned char *peer_addr); int (*cancel_connection) (unsigned char *peer_addr); int (*get_connected_peers) (GList **peers, int *peer_count); @@ -625,7 +625,7 @@ int wfd_oem_get_scan_result(wfd_oem_ops_s *ops, GList **peers, int *peer_count); int wfd_oem_get_peer_info(wfd_oem_ops_s *ops, unsigned char *peer_addr, wfd_oem_device_s **peer); int wfd_oem_prov_disc_req(wfd_oem_ops_s *ops, unsigned char *peer_addr, wfd_oem_wps_mode_e wps_mode, int join); int wfd_oem_connect(wfd_oem_ops_s *ops, unsigned char *peer_addr, wfd_oem_conn_param_s *param); -int wfd_oem_disconnect(wfd_oem_ops_s *ops, unsigned char *peer_addr); +int wfd_oem_disconnect(wfd_oem_ops_s *ops, unsigned char *peer_addr, int is_iface_addr); int wfd_oem_reject_connection(wfd_oem_ops_s *ops, unsigned char *peer_addr); int wfd_oem_cancel_connection(wfd_oem_ops_s *ops, unsigned char *peer_addr); int wfd_oem_get_connected_peers(wfd_oem_ops_s *ops, GList **peers, int *peer_count); diff --git a/packaging/wifi-direct-manager.spec b/packaging/wifi-direct-manager.spec index fa69d91..4f355cd 100755 --- a/packaging/wifi-direct-manager.spec +++ b/packaging/wifi-direct-manager.spec @@ -1,6 +1,6 @@ Name: wifi-direct-manager Summary: Wi-Fi Direct manger -Version: 1.2.168 +Version: 1.2.169 Release: 1 Group: Network & Connectivity/Wireless License: Apache-2.0 diff --git a/plugin/wpasupplicant/ctrl_iface_dbus/include/wfd-plugin-wpasupplicant.h b/plugin/wpasupplicant/ctrl_iface_dbus/include/wfd-plugin-wpasupplicant.h index fdeedb6..cdba5c7 100755 --- a/plugin/wpasupplicant/ctrl_iface_dbus/include/wfd-plugin-wpasupplicant.h +++ b/plugin/wpasupplicant/ctrl_iface_dbus/include/wfd-plugin-wpasupplicant.h @@ -413,7 +413,7 @@ int ws_get_scan_result(GList **peers, int *peer_count); int ws_get_peer_info(unsigned char *peer_addr, wfd_oem_device_s **peer); int ws_prov_disc_req(unsigned char *peer_addr, wfd_oem_wps_mode_e wps_mode, int join); int ws_connect(unsigned char *peer_addr, wfd_oem_conn_param_s *param); -int ws_disconnect(unsigned char *peer_addr); +int ws_disconnect(unsigned char *peer_addr, int is_iface_addr); int ws_reject_connection(unsigned char *peer_addr); int ws_cancel_connection(unsigned char *peer_addr); int ws_get_connected_peers(GList **peers, int *peer_count); diff --git a/plugin/wpasupplicant/ctrl_iface_dbus/wfd-plugin-wpasupplicant.c b/plugin/wpasupplicant/ctrl_iface_dbus/wfd-plugin-wpasupplicant.c index a996b7b..f08c36e 100755 --- a/plugin/wpasupplicant/ctrl_iface_dbus/wfd-plugin-wpasupplicant.c +++ b/plugin/wpasupplicant/ctrl_iface_dbus/wfd-plugin-wpasupplicant.c @@ -4122,13 +4122,13 @@ int ws_connect(unsigned char *peer_addr, wfd_oem_conn_param_s *param) return res; } -int ws_disconnect(unsigned char *peer_addr) +int ws_disconnect(unsigned char *peer_addr, int is_iface_addr) { __WDP_LOG_FUNC_ENTER__; GDBusConnection *g_dbus = NULL; GVariant *value = NULL; dbus_method_param_s params; - static char peer_path[DBUS_OBJECT_PATH_MAX] = {'\0',}; + GVariantBuilder *builder = NULL; int res = 0; if (!peer_addr) { @@ -4149,12 +4149,26 @@ int ws_disconnect(unsigned char *peer_addr) memset(¶ms, 0x0, sizeof(dbus_method_param_s)); dbus_set_method_param(¶ms, "RemoveClient", g_pd->iface_path, g_dbus); + builder = g_variant_builder_new(G_VARIANT_TYPE ("a{sv}")); - g_snprintf(peer_path, DBUS_OBJECT_PATH_MAX, "%s/Peers/" - COMPACT_MACSTR, g_pd->iface_path, MAC2STR(peer_addr)); - WDP_LOGE("get peer path [%s]", peer_path); + if (is_iface_addr) { + char peer_mac_str[WS_MACSTR_LEN] = {'\0', }; - value = g_variant_new("(oi)", peer_path, 0); + g_snprintf(peer_mac_str, WS_MACSTR_LEN, MACSTR, MAC2STR(peer_addr)); + WDP_LOGI("peer addr [%s]", peer_mac_str); + g_variant_builder_add(builder, "{sv}", "iface", + g_variant_new_string(peer_mac_str)); + } else { + char peer_path[DBUS_OBJECT_PATH_MAX] = {'\0', }; + + g_snprintf(peer_path, DBUS_OBJECT_PATH_MAX, "%s/Peers/" + COMPACT_MACSTR, g_pd->iface_path, MAC2STR(peer_addr)); + g_variant_builder_add (builder, "{sv}", "peer", + g_variant_new_object_path(peer_path)); + } + + value = g_variant_new ("(a{sv})", builder); + g_variant_builder_unref (builder); params.params = value; #if defined(TIZEN_DEBUG_DBUS_VALUE) @@ -4165,7 +4179,8 @@ int ws_disconnect(unsigned char *peer_addr) if (res < 0) WDP_LOGE("Failed to send command to wpa_supplicant"); else - WDP_LOGD("Succeeded to stop scan"); + WDP_LOGD("Succeeded to send disconnection command to peer[" MACSECSTR "]", + MAC2SECSTR(peer_addr)); __WDP_LOG_FUNC_EXIT__; return res; diff --git a/plugin/wpasupplicant/ctrl_iface_sock/include/wfd-plugin-wpasupplicant.h b/plugin/wpasupplicant/ctrl_iface_sock/include/wfd-plugin-wpasupplicant.h index 37387e9..a2f2835 100755 --- a/plugin/wpasupplicant/ctrl_iface_sock/include/wfd-plugin-wpasupplicant.h +++ b/plugin/wpasupplicant/ctrl_iface_sock/include/wfd-plugin-wpasupplicant.h @@ -123,6 +123,7 @@ #define WS_CMD_P2P_GROUP_REMOVE "P2P_GROUP_REMOVE " #define WS_CMD_P2P_CONNECT "P2P_CONNECT " #define WS_CMD_P2P_REJECT "P2P_REJECT_CONNECTION " +#define WS_CMD_P2P_REMOVE_CLIENT "P2P_REMOVE_CLIENT " #define WS_CMD_WPS_PBC "WPS_PBC " #define WS_CMD_WPS_PIN "WPS_PIN " #define WS_CMD_WPS_ENROLLEE "WPS_ENROLLEE " @@ -138,8 +139,6 @@ #define WS_CMD_LIST_NETWORKS "LIST_NETWORKS" #define WS_CMD_REMOVE_NETWORK "REMOVE_NETWORK" -#define WS_CMD_DISCONNECT "P2P_DISCONNECT " - #ifdef TIZEN_FEATURE_SERVICE_DISCOVERY #define WS_CMD_SERVICE_ADD "P2P_SERVICE_ADD" #define WS_CMD_SERVICE_DEL "P2P_SERVICE_DEL" @@ -538,7 +537,7 @@ int ws_get_scan_result(GList **peers, int *peer_count); int ws_get_peer_info(unsigned char *peer_addr, wfd_oem_device_s **peer); int ws_prov_disc_req(unsigned char *peer_addr, wfd_oem_wps_mode_e wps_mode, int join); int ws_connect(unsigned char *peer_addr, wfd_oem_conn_param_s *param); -int ws_disconnect(unsigned char *peer_addr); +int ws_disconnect(unsigned char *peer_addr, int is_iface_addr); int ws_reject_connection(unsigned char *peer_addr); int ws_cancel_connection(unsigned char *peer_addr); int ws_get_connected_peers(GList **peers, int *peer_count); diff --git a/plugin/wpasupplicant/ctrl_iface_sock/wfd-plugin-wpasupplicant.c b/plugin/wpasupplicant/ctrl_iface_sock/wfd-plugin-wpasupplicant.c index 2ad5493..2f03f87 100755 --- a/plugin/wpasupplicant/ctrl_iface_sock/wfd-plugin-wpasupplicant.c +++ b/plugin/wpasupplicant/ctrl_iface_sock/wfd-plugin-wpasupplicant.c @@ -3352,7 +3352,7 @@ int ws_connect(unsigned char *peer_addr, wfd_oem_conn_param_s *param) return 0; } -int ws_disconnect(unsigned char *peer_addr) +int ws_disconnect(unsigned char *peer_addr, int is_iface_addr) { __WDP_LOG_FUNC_ENTER__; ws_sock_data_s *sock = g_pd->common; @@ -3370,9 +3370,18 @@ int ws_disconnect(unsigned char *peer_addr) return -1; } - WDP_LOGD("Peer address is [" MACSECSTR "]. Disconnect selected peer", MAC2SECSTR(peer_addr)); + WDP_LOGD("Peer address is [" MACSECSTR "]. Disconnect selected peer", + MAC2SECSTR(peer_addr)); + + if (is_iface_addr) + g_snprintf(cmd, sizeof(cmd), + WS_CMD_P2P_REMOVE_CLIENT "iface=" MACSTR, + MAC2STR(peer_addr)); + else + g_snprintf(cmd, sizeof(cmd), + WS_CMD_P2P_REMOVE_CLIENT MACSTR, + MAC2STR(peer_addr)); - g_snprintf(cmd, sizeof(cmd), WS_CMD_DISCONNECT MACSTR " %s", MAC2STR(peer_addr), GROUP_IFACE_NAME); res = _ws_send_cmd(sock->ctrl_sock, cmd, reply, sizeof(reply)); if (res < 0) { WDP_LOGE("Failed to send command to wpa_supplicant"); @@ -3381,11 +3390,13 @@ int ws_disconnect(unsigned char *peer_addr) } if (strstr(reply, "FAIL")) { - WDP_LOGD("Failed to disconnect with peer[" MACSECSTR "]", MAC2SECSTR(peer_addr)); + WDP_LOGD("Failed to disconnect with peer[" MACSECSTR "]", + MAC2SECSTR(peer_addr)); __WDP_LOG_FUNC_EXIT__; return -1; } - WDP_LOGD("Succeeded to send disconnection command to peer[" MACSECSTR "]", MAC2SECSTR(peer_addr)); + WDP_LOGD("Succeeded to send disconnection command to peer[" MACSECSTR "]", + MAC2SECSTR(peer_addr)); __WDP_LOG_FUNC_EXIT__; return 0; diff --git a/plugin/wpasupplicant/emul/include/wfd-plugin-wpasupplicant.h b/plugin/wpasupplicant/emul/include/wfd-plugin-wpasupplicant.h index a098069..9bb9325 100755 --- a/plugin/wpasupplicant/emul/include/wfd-plugin-wpasupplicant.h +++ b/plugin/wpasupplicant/emul/include/wfd-plugin-wpasupplicant.h @@ -77,7 +77,7 @@ int ws_get_scan_result(GList **peers, int *peer_count); int ws_get_peer_info(unsigned char *peer_addr, wfd_oem_device_s **peer); int ws_prov_disc_req(unsigned char *peer_addr, wfd_oem_wps_mode_e wps_mode, int join); int ws_connect(unsigned char *peer_addr, wfd_oem_conn_param_s *param); -int ws_disconnect(unsigned char *peer_addr); +int ws_disconnect(unsigned char *peer_addr, int is_iface_addr); int ws_reject_connection(unsigned char *peer_addr); int ws_cancel_connection(unsigned char *peer_addr); int ws_get_connected_peers(GList **peers, int *peer_count); diff --git a/plugin/wpasupplicant/emul/wfd-plugin-wpasupplicant-emul.c b/plugin/wpasupplicant/emul/wfd-plugin-wpasupplicant-emul.c index 6cc2ac0..9a79ad0 100755 --- a/plugin/wpasupplicant/emul/wfd-plugin-wpasupplicant-emul.c +++ b/plugin/wpasupplicant/emul/wfd-plugin-wpasupplicant-emul.c @@ -193,7 +193,7 @@ int ws_connect(unsigned char *peer_addr, wfd_oem_conn_param_s *param) return -1; } -int ws_disconnect(unsigned char *peer_addr) +int ws_disconnect(unsigned char *peer_addr, int is_iface_addr) { __WDP_LOG_FUNC_ENTER__; diff --git a/src/wifi-direct-event.c b/src/wifi-direct-event.c index 613a806..3ef8179 100755 --- a/src/wifi-direct-event.c +++ b/src/wifi-direct-event.c @@ -974,6 +974,7 @@ static void __wfd_process_sta_connected(wfd_manager_s *manager, wfd_oem_event_s memcpy(peer->intf_addr, event->intf_addr, MACADDR_LEN); peer->state = WFD_PEER_STATE_CONNECTED; + peer->is_legacy = TRUE; wfd_group_add_member(group, peer->dev_addr); g_snprintf(peer_mac_address, MACSTR_LEN, MACSTR, MAC2STR(peer->dev_addr)); diff --git a/src/wifi-direct-manager.c b/src/wifi-direct-manager.c index 8352a9f..067e0d6 100755 --- a/src/wifi-direct-manager.c +++ b/src/wifi-direct-manager.c @@ -775,25 +775,13 @@ int wfd_manager_cancel_connection(wfd_manager_s *manager, unsigned char *peer_ad return WIFI_DIRECT_ERROR_OPERATION_FAILED; } - if (manager->local->dev_role != WFD_DEV_ROLE_GO) - wfd_oem_destroy_group(manager->oem_ops, GROUP_IFNAME); - group = (wfd_group_s*) manager->group; - if (group) { + if (group) wfd_group_remove_member(group, peer_addr); - if (!group->member_count) { - if (wfd_util_is_remove_group_allowed()) { - wfd_oem_destroy_group(manager->oem_ops, group->ifname); - wfd_destroy_group(manager, group->ifname); - } - } else { - wfd_oem_disconnect(manager->oem_ops, peer_addr); - } - } if (manager->local->dev_role == WFD_DEV_ROLE_GO) { wfd_state_set(manager, WIFI_DIRECT_STATE_GROUP_OWNER); - if (group && group->member_count > 0) + if (group && group->member_count) wfd_util_set_wifi_direct_state(WIFI_DIRECT_STATE_GROUP_OWNER); } else { wfd_state_set(manager, WIFI_DIRECT_STATE_ACTIVATED); @@ -884,15 +872,14 @@ int wfd_manager_disconnect(wfd_manager_s *manager, unsigned char *peer_addr) wfd_state_set(manager, WIFI_DIRECT_STATE_DISCONNECTING); if (manager->local->dev_role == WFD_DEV_ROLE_GO) { -#ifdef CTRL_IFACE_DBUS - /* dbus using device address to identify the peer */ - res = wfd_oem_disconnect(manager->oem_ops, peer->dev_addr); -#else /* CTRL_IFACE_DBUS */ - res = wfd_oem_disconnect(manager->oem_ops, peer->intf_addr); -#endif /* CTRL_IFACE_DBUS */ + if (peer->is_legacy) + res = wfd_oem_disconnect(manager->oem_ops, peer->intf_addr, 1); + else + res = wfd_oem_disconnect(manager->oem_ops, peer->dev_addr, 0); } else { res = wfd_oem_destroy_group(manager->oem_ops, group->ifname); } + if (res < 0) { WDS_LOGE("Failed to disconnect peer"); res = WIFI_DIRECT_ERROR_OPERATION_FAILED; diff --git a/src/wifi-direct-peer.c b/src/wifi-direct-peer.c index 07cfc91..66000e5 100644 --- a/src/wifi-direct-peer.c +++ b/src/wifi-direct-peer.c @@ -69,6 +69,7 @@ wfd_device_s *wfd_add_peer(void *data, unsigned char *dev_addr, char *dev_name) } memcpy(peer->dev_addr, dev_addr, MACADDR_LEN); g_strlcpy(peer->dev_name, dev_name, DEV_NAME_LEN + 1); + peer->is_legacy = FALSE; manager->peers = g_list_prepend(manager->peers, peer); manager->peer_count++; -- 2.7.4