From aac57d44315d38b1f449b1ee79f6ce55a78d6f16 Mon Sep 17 00:00:00 2001 From: Jiung Yu Date: Thu, 6 Jul 2017 15:00:06 +0900 Subject: [PATCH] Stop supporting wpasupplicant socket plugin Description : We have supported the DBus interface for IPC between the WPAsupplicant and the wfd-manager daemon since Tizen 2.3. At that time, some features are not supported comparing with a socket interface. But most of them are now provided by a DBus interface. So, we will no longer support a socket interface to reduce the maintaining resource Change-Id: Icb4b82f4a8d2f0151d36bd542a2709bf9d29454e Signed-off-by: Yu jiung --- CMakeLists.txt | 15 +- packaging/wifi-direct-manager.spec | 15 +- .../wpasupplicant/ctrl_iface_sock/CMakeLists.txt | 28 - .../ctrl_iface_sock/include/wfd-plugin-log.h | 67 - .../include/wfd-plugin-wpasupplicant.h | 597 --- .../ctrl_iface_sock/wfd-plugin-wpasupplicant.c | 5062 -------------------- .../wpasupplicant/ctrl_iface_sock/CMakeLists.txt | 28 - .../ctrl_iface_sock/include/wfd-prd-plugin-log.h | 59 - .../include/wfd-prd-plugin-wpasupplicant.h | 48 - .../ctrl_iface_sock/wfd-prd-plugin-wpasupplicant.c | 90 - src/wifi-direct-event.c | 75 - 11 files changed, 10 insertions(+), 6074 deletions(-) delete mode 100644 plugin/wpasupplicant/ctrl_iface_sock/CMakeLists.txt delete mode 100644 plugin/wpasupplicant/ctrl_iface_sock/include/wfd-plugin-log.h delete mode 100644 plugin/wpasupplicant/ctrl_iface_sock/include/wfd-plugin-wpasupplicant.h delete mode 100644 plugin/wpasupplicant/ctrl_iface_sock/wfd-plugin-wpasupplicant.c delete mode 100644 prd/plugin/wpasupplicant/ctrl_iface_sock/CMakeLists.txt delete mode 100644 prd/plugin/wpasupplicant/ctrl_iface_sock/include/wfd-prd-plugin-log.h delete mode 100644 prd/plugin/wpasupplicant/ctrl_iface_sock/include/wfd-prd-plugin-wpasupplicant.h delete mode 100644 prd/plugin/wpasupplicant/ctrl_iface_sock/wfd-prd-plugin-wpasupplicant.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 5193b1a..d3c3610 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,9 +73,6 @@ IF(TIZEN_WIFI_MODULE_BUNDLE) ADD_DEFINITIONS(-DTIZEN_WIFI_MODULE_BUNDLE) ENDIF(TIZEN_WIFI_MODULE_BUNDLE) -IF(CTRL_IFACE_DBUS) - ADD_DEFINITIONS(-DCTRL_IFACE_DBUS) -ENDIF(CTRL_IFACE_DBUS) IF(TIZEN_DEBUG_DBUS_VALUE) ADD_DEFINITIONS(-DTIZEN_DEBUG_DBUS_VALUE) ENDIF(TIZEN_DEBUG_DBUS_VALUE) @@ -139,21 +136,13 @@ INSTALL(FILES ${CMAKE_SOURCE_DIR}/files/dhcpd.conf DESTINATION ${TZ_SYS_RO_ETC}/ INSTALL(FILES ${CMAKE_SOURCE_DIR}/files/wifi-direct-dhcp.sh DESTINATION ${BIN_DIR}) IF("${ARCH}" MATCHES "^arm.*|.*86.*") - IF(CTRL_IFACE_DBUS) - ADD_SUBDIRECTORY(plugin/wpasupplicant/ctrl_iface_dbus) - ELSE(CTRL_IFACE_DBUS) - ADD_SUBDIRECTORY(plugin/wpasupplicant/ctrl_iface_sock) - ENDIF(CTRL_IFACE_DBUS) + ADD_SUBDIRECTORY(plugin/wpasupplicant/ctrl_iface_dbus) ELSE() ADD_SUBDIRECTORY(plugin/wpasupplicant/emul) ENDIF() IF(TIZEN_ENABLE_PRD) IF("${ARCH}" MATCHES "^arm.*|.*86.*") - IF(CTRL_IFACE_DBUS) - ADD_SUBDIRECTORY(prd/plugin/wpasupplicant/ctrl_iface_dbus) - ELSE(CTRL_IFACE_DBUS) - ADD_SUBDIRECTORY(prd/plugin/wpasupplicant/ctrl_iface_sock) - ENDIF(CTRL_IFACE_DBUS) + ADD_SUBDIRECTORY(prd/plugin/wpasupplicant/ctrl_iface_dbus) ENDIF() ENDIF(TIZEN_ENABLE_PRD) diff --git a/packaging/wifi-direct-manager.spec b/packaging/wifi-direct-manager.spec index a180f08..c2f279e 100644 --- a/packaging/wifi-direct-manager.spec +++ b/packaging/wifi-direct-manager.spec @@ -8,7 +8,7 @@ Name: wifi-direct-manager Summary: Wi-Fi Direct manger -Version: 1.2.226 +Version: 1.2.227 Release: 1 Group: Network & Connectivity/Wireless License: Apache-2.0 @@ -222,7 +222,6 @@ cmake .. -DCMAKE_INSTALL_PREFIX=%{_prefix} -DARCHITECTURE=$ARCH \ -DTIZEN_FEATURE_WIFI_DISPLAY=1 \ -DTIZEN_FEATURE_DEFAULT_CONNECTION_AGENT=1 \ -DTIZEN_FEATURE_IP_OVER_EAPOL=1 \ - -DCTRL_IFACE_DBUS=1 \ -DTIZEN_DEBUG_DBUS_VALUE=1 \ -DTIZEN_PROFILE_MOBILE=1 \ -DTIZEN_FEATURE_ASP=1 \ @@ -258,7 +257,6 @@ cmake .. -DCMAKE_INSTALL_PREFIX=%{_prefix} -DARCHITECTURE=$ARCH \ -DTIZEN_FEATURE_WIFI_DISPLAY=1 \ -DTIZEN_FEATURE_DEFAULT_CONNECTION_AGENT=1 \ -DTIZEN_FEATURE_IP_OVER_EAPOL=1 \ - -DCTRL_IFACE_DBUS=1 \ -DTIZEN_DEBUG_DBUS_VALUE=1 \ -DTIZEN_PROFILE_MOBILE=1 \ -DTIZEN_FEATURE_ASP=1 \ @@ -291,8 +289,13 @@ cmake .. -DCMAKE_INSTALL_PREFIX=%{_prefix} -DARCHITECTURE=$ARCH \ %if ! 0%{?model_build_feature_network_tethering_disable} -DTIZEN_TETHERING_ENABLE=0 \ %endif - -DTIZEN_FEATURE_SERVICE_DISCOVERY=0 \ - -DTIZEN_FEATURE_WIFI_DISPLAY=0 \ + -DTIZEN_FEATURE_WIFI_DIRECT_ON_DEMAND=1 \ + -DTIZEN_FEATURE_SERVICE_DISCOVERY=1 \ + -DTIZEN_WLAN_CONCURRENT_ENABLE=1 \ + -DTIZEN_FEATURE_WIFI_DISPLAY=1 \ + -DTIZEN_FEATURE_IP_OVER_EAPOL=1 \ + -DTIZEN_DEBUG_DBUS_VALUE=1 \ + -DTIZEN_PROFILE_COMMON=1 \ %if "%{?_lib}" == "lib64" -DTIZEN_ARCH_64=1 \ %endif @@ -326,7 +329,6 @@ cmake .. -DCMAKE_INSTALL_PREFIX=%{_prefix} -DARCHITECTURE=$ARCH \ -DTIZEN_WLAN_CONCURRENT_ENABLE=0 \ -DTIZEN_FEATURE_WIFI_DISPLAY=1 \ -DTIZEN_FEATURE_IP_OVER_EAPOL=1 \ - -DCTRL_IFACE_DBUS=1 \ -DTIZEN_DEBUG_DBUS_VALUE=1 \ -DTIZEN_WIFI_MODULE_BUNDLE=0 \ -DTIZEN_PROFILE_TV=1 \ @@ -362,7 +364,6 @@ cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DARCHITECTURE=$ARCH \ -DTIZEN_WLAN_CONCURRENT_ENABLE=1 \ -DTIZEN_FEATURE_WIFI_DISPLAY=1 \ -DTIZEN_FEATURE_IP_OVER_EAPOL=1 \ - -DCTRL_IFACE_DBUS=1 \ -DTIZEN_DEBUG_DBUS_VALUE=1 \ -DTIZEN_PROFILE_COMMON=1 \ %if "%{?_lib}" == "lib64" diff --git a/plugin/wpasupplicant/ctrl_iface_sock/CMakeLists.txt b/plugin/wpasupplicant/ctrl_iface_sock/CMakeLists.txt deleted file mode 100644 index f97e2cb..0000000 --- a/plugin/wpasupplicant/ctrl_iface_sock/CMakeLists.txt +++ /dev/null @@ -1,28 +0,0 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -PROJECT(wifi-direct-plugin-wpasupplicant C) - -# Set required packages -INCLUDE(FindPkgConfig) -pkg_check_modules(pkgs REQUIRED capi-network-wifi-direct glib-2.0 gio-2.0 dlog) -FOREACH(flag ${pkgs_CFLAGS}) - SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") -ENDFOREACH(flag) - -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/oem) -INCLUDE_DIRECTORIES(SRCS include) - -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -g -Werror") -SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") -SET(CMAKE_C_FLAGS_RELEASE "-O2") -SET(SRCS - wfd-plugin-wpasupplicant.c - ) - -# library build -ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS}) -#SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION 0.1.0) -SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "" OUTPUT_NAME ${PROJECT_NAME}) - -# install -INSTALL(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${LIB_DIR}) diff --git a/plugin/wpasupplicant/ctrl_iface_sock/include/wfd-plugin-log.h b/plugin/wpasupplicant/ctrl_iface_sock/include/wfd-plugin-log.h deleted file mode 100644 index a515aa5..0000000 --- a/plugin/wpasupplicant/ctrl_iface_sock/include/wfd-plugin-log.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Network Configuration Module - * - * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -/** - * This file declares wifi direct wpasupplicant plugin functions and structures. - * - * @file wfd-plugin-log.h - * @author Gibyoung Kim (lastkgb.kim@samsung.com) - * @version 0.7 - */ - -#ifndef __WFD_PLUGIN_LOG_H_ -#define __WFD_PLUGIN_LOG_H_ - -#ifdef USE_DLOG -#include - -#undef LOG_TAG -#define LOG_TAG "WIFI_DIRECT_PLUGIN" - -#define WDP_LOGV(format, args...) LOGV(format, ##args) -#define WDP_LOGD(format, args...) LOGD(format, ##args) -#define WDP_LOGI(format, args...) LOGI(format, ##args) -#define WDP_LOGW(format, args...) LOGW(format, ##args) -#define WDP_LOGE(format, args...) LOGE(format, ##args) -#define WDP_LOGF(format, args...) LOGF(format, ##args) - -#define __WDP_LOG_FUNC_ENTER__ LOGD("Enter") -#define __WDP_LOG_FUNC_EXIT__ LOGD("Quit") - -#define WDP_SECLOGI(format, args...) SECURE_LOG(LOG_INFO, LOG_TAG, format, ##args) -#define WDP_SECLOGD(format, args...) SECURE_LOG(LOG_DEBUG, LOG_TAG, format, ##args) - -#else /* USE_DLOG */ - -#define WDP_LOGV(format, args...) -#define WDP_LOGD(format, args...) -#define WDP_LOGI(format, args...) -#define WDP_LOGW(format, args...) -#define WDP_LOGE(format, args...) -#define WDP_LOGF(format, args...) - -#define __WDP_LOG_FUNC_ENTER__ -#define __WDP_LOG_FUNC_EXIT__ - -#define WDP_SECLOGI(format, args...) -#define WDP_SECLOGD(format, args...) - -#endif /* USE_DLOG */ - -#endif /* __WFD_PLUGIN_LOG_H_ */ diff --git a/plugin/wpasupplicant/ctrl_iface_sock/include/wfd-plugin-wpasupplicant.h b/plugin/wpasupplicant/ctrl_iface_sock/include/wfd-plugin-wpasupplicant.h deleted file mode 100644 index f3aaef1..0000000 --- a/plugin/wpasupplicant/ctrl_iface_sock/include/wfd-plugin-wpasupplicant.h +++ /dev/null @@ -1,597 +0,0 @@ -/* - * Network Configuration Module - * - * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -/** - * This file declares wifi direct wpasupplicant plugin functions and structures. - * - * @file wfd-plugin-wpasupplicant.h - * @author Gibyoung Kim (lastkgb.kim@samsung.com) - * @version 0.7 - */ - -#ifndef __WFD_PLUGIN_WPASUPPLICANT_H__ -#define __WFD_PLUGIN_WPASUPPLICANT_H__ - - -#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5] -#define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x" -#define IP2STR(a) (a)[0], (a)[1], (a)[2], (a)[3] -#define IPSTR "%d.%d.%d.%d" -#define MAC2SECSTR(a) (a)[0], (a)[4], (a)[5] -#define MACSECSTR "%02x:%02x:%02x" -#define ISZEROMACADDR(a) !(a[0] | a[1] | a[2] | a[3] | a[4] | a[5]) -#define IP2SECSTR(a) (a)[0], (a)[3] -#define IPSECSTR "%d..%d" - -#define SOCK_FD_MIN 3 -#define GLOBAL_INTF_PATH "/tmp/wpa_ctrl_global" - -#if defined TIZEN_PROFILE_MOBILE -#define COMMON_IFACE_NAME "wlan0" -#define GROUP_IFACE_NAME "p2p-wlan0-0" -#define GROUP_IFACE_PREFIX "p2p-wlan0-" -#endif - -#if defined TIZEN_WIFI_MODULE_BUNDLE -#define COMMON_IFACE_NAME "wlan0" -#define GROUP_IFACE_NAME "wlan0" -#define GROUP_IFACE_PREFIX "wlan" -#endif - -#ifndef COMMON_IFACE_NAME -#define COMMON_IFACE_NAME "p2p0" -#endif - -#ifndef GROUP_IFACE_NAME -#define GROUP_IFACE_NAME "p2p0" -#endif - -#ifndef GROUP_IFACE_PREFIX -#define GROUP_IFACE_PREFIX "p2p" -#endif - -#ifdef TIZEN_FEATURE_IP_OVER_EAPOL -#define DEFAULT_IP_GO "192.168.49.1" -#define DEFAULT_IP_MASK "255.255.255.0" -#define DEFAULT_IP_START "192.168.49.51" -#define DEFAULT_IP_END "192.168.49.100" -#endif /* TIZEN_FEATURE_IP_OVER_EAPOL */ - -#define WS_POLL_TIMEOUT 5000 -#define WS_CONN_RETRY_COUNT 10 -#define WS_PINSTR_LEN 8 -#define WS_DEVTYPESTR_LEN 14 -#define WS_REPLY_LEN 1024 -#define WS_SSID_LEN 32 -#define WS_MACSTR_LEN 18 -#define WS_MACADDR_LEN 6 -#define WS_NETFLAG_LEN 32 -#define WS_MAX_PERSISTENT_COUNT 20 -#define WS_SCAN_RETRY_COUNT 10 -#define WS_IP_LEN 4 - -#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY - -#define SERV_DISC_REQ_ALL "02000001" -#define SERV_DISC_REQ_BONJOUR "02000101" -#define SERV_DISC_REQ_UPNP "02000201" - -#define SAMSUNG_SERVICE_ALL "0c" - -#define SERVICE_TYPE_LEN 8 -#define SERV_BROADCAST_ADDRESS "00:00:00:00:00:00" -#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */ - -/* Config Method bitmap */ -#define WS_CONFIG_METHOD_DISPLAY 0x0008 -#define WS_CONFIG_METHOD_PUSHBUTTON 0x0080 -#define WS_CONFIG_METHOD_KEYPAD 0x0100 - -/* wpa_supplicant command */ -#define WS_CMD_INTERFACES "INTERFACES" -#define WS_CMD_INTERFACE_ADD "INTERFACE_ADD " -#define WS_CMD_INTERFACE_REMOVE "INTERFACE_REMOVE" -#define WS_CMD_ATTACH "ATTACH" -#define WS_CMD_DETACH "DETACH" -#define WS_CMD_P2P_FIND "P2P_FIND" -#define WS_CMD_P2P_LISTEN "P2P_LISTEN" -#define WS_CMD_P2P_STOP_FIND "P2P_STOP_FIND" -#define WS_CMD_P2P_FLUSH "P2P_FLUSH" -#define WS_CMD_P2P_CANCEL "P2P_CANCEL" -#define WS_CMD_P2P_PEER "P2P_PEER " -#define WS_CMD_P2P_PEER_FIRST "P2P_PEER FIRST" -#define WS_CMD_P2P_PEER_NEXT "P2P_PEER NEXT-" -#define WS_CMD_P2P_PROV_DISC "P2P_PROV_DISC " -#define WS_CMD_P2P_INVITE "P2P_INVITE " -#define WS_CMD_P2P_GROUP_ADD "P2P_GROUP_ADD" -#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 " -#define WS_CMD_WPS_CANCEL "WPS_CANCEL" -#define WS_CMD_SET "SET " -#define WS_CMD_GET "GET " -#define WS_CMD_P2P_SET "P2P_SET " -#define WS_CMD_STATUS "STATUS" -#define WS_CMD_STATUS_P2P "STATUS P2P" -#define WS_CMD_LOG_LEVEL "LOG_LEVEL" -#define WS_CMD_QUIT "QUIT" -#define WS_CMD_TERMINATE "TERMINATE" -#define WS_CMD_LIST_NETWORKS "LIST_NETWORKS" -#define WS_CMD_REMOVE_NETWORK "REMOVE_NETWORK" - -#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY -#define WS_CMD_SERVICE_ADD "P2P_SERVICE_ADD" -#define WS_CMD_SERVICE_DEL "P2P_SERVICE_DEL" -#define WS_CMD_SERV_DISC_REQ "P2P_SERV_DISC_REQ" -#define WS_CMD_SERV_DISC_CANCEL "P2P_SERV_DISC_CANCEL_REQ" -#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */ - -#define WS_CMD_SUBELEM_SET "WFD_SUBELEM_SET " - -#define WS_STR_PBC " pbc" -#define WS_STR_DISPLAY " display" -#define WS_STR_KEYPAD " keypad" -#define WS_STR_JOIN " join" -#define WS_STR_AUTH " auth" -#define WS_STR_PERSISTENT " persistent" -#define WS_STR_PASSPHRASE " passphrase=" -#define WS_STR_FREQ " freq=" -#define WS_STR_FREQ_2G " freq=2" - -#define WS_STR_ATTR_LISTEN_CLASS "p2p_listen_reg_class" -#define WS_STR_ATTR_OPER_CLASS "p2p_oper_reg_class" - -#ifdef TIZEN_FEATURE_WIFI_DISPLAY -#define WS_WFD_INFO_PRIMARY_SINK 0x01 -#define WS_WFD_INFO_SECONDARY_SINK 0x02 -#define WS_WFD_INFO_AVAILABILITY 0x10 -#define WS_WFD_INFO_WSD_SUPPORT 0x40 -#define WS_WFD_INFO_TDLS_SUPPORT 0x80 -#define WS_WFD_INFO_HDCP_SUPPORT 0x100 -#define WS_WFD_INFO_SYNC_SUPPORT 0x200 -#endif /* TIZEN_FEATURE_WIFI_DISPLAY */ - -typedef enum { - WS_IFTYPE_NONE, - WS_IFTYPE_STATION, - WS_IFTYPE_GROUP, -} ws_iftype_e; - -typedef enum { - WS_PRI_DEV_TYPE_NONE, - WS_PRI_DEV_TYPE_COMPUTER = 1, - WS_PRI_DEV_TYPE_INPUT_DEVICE = 2, - WS_PRI_DEV_TYPE_PRINTER = 3, - WS_PRI_DEV_TYPE_CAMERA = 4, - WS_PRI_DEV_TYPE_STORAGE = 5, - WS_PRI_DEV_TYPE_NETWORK_INFRA = 6, - WS_PRI_DEV_TYPE_DISPLAY = 7, - WS_PRI_DEV_TYPE_MULTIMEDIA_DEVICE = 8, - WS_PRI_DEV_TYPE_GAME_DEVICE = 9, - WS_PRI_DEV_TYPE_TELEPHONE = 10, - WS_PRI_DEV_TYPE_AUDIO = 11, - WS_PRI_DEV_TYPE_OTHER = 255, -} ws_device_type_e; - -typedef enum { - WS_EVENT_NONE = -1, - - WS_EVENT_DEVICE_FOUND, - WS_EVENT_DEVICE_LOST, - WS_EVENT_FIND_STOPED, - WS_EVENT_PROV_DISC_PBC_REQ, - WS_EVENT_PROV_DISC_SHOW_PIN, - WS_EVENT_PROV_DISC_ENTER_PIN, /* 5 */ - WS_EVENT_PROV_DISC_PBC_RESP, - WS_EVENT_PROV_DISC_FAILURE, - - WS_EVENT_GO_NEG_REQUEST, - WS_EVENT_GO_NEG_FAILURE, - WS_EVENT_GO_NEG_SUCCESS, /* 10*/ - - WS_EVENT_WPS_FAIL, - WS_EVENT_GROUP_FORMATION_FAILURE, - WS_EVENT_WPS_SUCCESS, - WS_EVENT_WPS_REG_SUCCESS, - WS_EVENT_GROUP_FORMATION_SUCCESS, /* 15*/ - - WS_EVENT_STA_CONNECTED, - - WS_EVENT_INVITATION_RECEIVED, - WS_EVENT_INVITATION_RESULT, - - WS_EVENT_STA_DISCONNECTED, - - WS_EVENT_GROUP_STARTED, /* 20 */ - WS_EVENT_GROUP_REMOVED, - - WS_EVENT_TERMINATING, - -#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY - WS_EVENT_SERV_DISC_RESP, -#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */ - - WS_EVENT_LIMIT, -} ws_event_id_e; - -typedef enum { - WS_DEV_INFO_NONE = -1, - - WS_DEV_INFO_P2P_DEV_ADDR, /* p2p_dev_addr= */ - WS_DEV_INFO_DEV_NAME, /* name= */ - WS_DEV_INFO_DEV_TYPE, /* pri_dev_type= */ - WS_DEV_INFO_CONFIG_METHODS, /* config_methods= */ - WS_DEV_INFO_DEV_CAP, /* dev_capab= */ - WS_DEV_INFO_GROUP_CAP, /* group_capab= */ - WS_DEV_INFO_P2P_GO_ADDR, /* p2p_go_addr= */ -#ifdef TIZEN_FEATURE_WIFI_DISPLAY - WS_DEV_INFO_WFD_DEV_INFO, /* wfd_dev_info= */ -#endif - WS_DEV_INFO_LIMIT, -} ws_dev_info_id_e; - -typedef enum { - WS_CONN_INFO_NONE = -1, - - WS_CONN_INFO_DEV_PWD_ID, /* dev_passwd_id= */ - WS_CONN_INFO_STATUS, /* status= */ - WS_CONN_INFO_ERROR, /* config_error= */ - - WS_CONN_INFO_LIMIT, -} ws_conn_info_id_e; - -typedef enum { - WS_INVITE_INFO_NONE = -1, - - WS_INVITE_INFO_SRC_ADDR, /* sa= */ - WS_INVITE_INFO_GO_DEV_ADDR, /* go_dev_addr= */ - WS_INVITE_INFO_BSSID, /* bssid= */ - WS_INVITE_INFO_LISTEN, /* listen= */ - WS_INVITE_INFO_FREQ, /* op_freq= */ - WS_INVITE_INFO_PERSISTENT_ID, /* persistent_id= */ - WS_INVITE_INFO_STATUS, /* status= */ - - WS_INVITE_INFO_LIMIT, -} ws_invite_info_id_e; - -typedef enum { - WS_GROUP_INFO_NONE = -1, - - WS_GROUP_INFO_SSID, /* ssid= */ - WS_GROUP_INFO_FREQ, /* freq= */ - WS_GROUP_INFO_PASS, /* passphrase= */ - WS_GROUP_INFO_GO_DEV_ADDR, /* go_dev_addr= */ - WS_GROUP_INFO_STATUS, /* status= */ - WS_GROUP_INFO_PERSISTENT, /* [PERSISTENT] */ -#ifdef TIZEN_FEATURE_IP_OVER_EAPOL - WS_GROUP_INFO_IP_ADDR, /* ip_addr= */ - WS_GROUP_INFO_IP_MASK, /* ip_mask= */ - WS_GROUP_INFO_GO_IP_ADDR, /* go_ip_addr= */ -#endif /* TIZEN_FEATURE_IP_OVER_EAPOL */ - WS_GROUP_INFO_LIMIT, -} ws_group_info_id_e; - -enum { - WS_PEER_INFO_NONE = -1, - - WS_PEER_INFO_AGE, - WS_PEER_INFO_LISTEN_FREQ, - WS_PEER_INFO_LEVEL, - WS_PEER_INFO_WPS_METHOD, - WS_PEER_INFO_INTERFACE_ADDR, - WS_PEER_INFO_MEMBER_IN_GO_DEV, - WS_PEER_INFO_MEMBER_IN_GO_IFACE, - WS_PEER_INFO_PRI_DEV_TYPE, - WS_PEER_INFO_DEVICE_NAME, - WS_PEER_INFO_MANUFACTURER, - WS_PEER_INFO_MODEL_NAME, - WS_PEER_INFO_MODEL_NUMBER, - WS_PEER_INFO_SERIAL_NUMBER, - WS_PEER_INFO_CONFIG_METHODS, - WS_PEER_INFO_DEV_CAPAB, - WS_PEER_INFO_GROUP_CAPAB, - WS_PEER_INFO_GO_NEG_REQ_SENT, - WS_PEER_INFO_GO_STATE, - WS_PEER_INFO_DIALOG_TOKEN, - WS_PEER_INFO_INTENDED_ADDR, - WS_PEER_INFO_COUNTRY, - WS_PEER_INFO_OPER_FREQ, - WS_PEER_INFO_REQ_CONFIG_METHODS, - WS_PEER_INFO_FLAGS, - WS_PEER_INFO_STATUS, - WS_PEER_INFO_WAIT_COUNT, - WS_PEER_INFO_INVITATION_REQS, -#ifdef TIZEN_FEATURE_WIFI_DISPLAY - WS_PEER_INFO_WFD_SUBELEMS, -#endif /* TIZEN_FEATURE_WIFI_DISPLAY */ - - WS_PEER_INFO_LIMIT, -} ws_peer_info_id_e; - -typedef enum { - /* The Service Discovery field shall be set to 1 - * if the P2P Device supports Service Discovery, - * and is set to 0 otherwise. */ - WS_DEVICE_CAP_SERVICE_DISCOVERY = 0x01, - - /* Within a P2P Group Info attribute and a (Re)association - * request frame the P2P Client Discoverability field shall be set to 1 - * when the P2P Device supports P2P Client Discoverability, - * and is set to 0 otherwise. - * This field shall be reserved and set to 0 in all other frames or uses. */ - WS_DEVICE_CAP_CLIENT_DISCOVERABILITY = 0x02, - - /* The Concurrent Operation field shall be set to 1 - * when the P2P Device supports Concurrent Operation with WLAN, - * and is set to 0 otherwise. */ - WS_DEVICE_CAP_CONCURRENT_OPERATION = 0x04, - - /* The P2P Infrastructure Managed field shall be set to 1 - * when the P2P interface of the P2P Device is capable of being - * managed by the WLAN (infrastructure network) based on - * P2P Coexistence Parameters, and set to 0 otherwise. */ - WS_DEVICE_CAP_INFRASTRUCTURE_MANAGED = 0x08, - - /* The P2P Device Limit field shall be set to 1 - * when the P2P Device is unable to participate in additional P2P Groups, - * and set to 0 otherwise. */ - WS_DEVICE_CAP_DEVICE_LIMIT = 0x10, - - /* The P2P Invitation Procedure field shall be set to 1 - * if the P2P Device is capable of processing P2P Invitation Procedure - * signaling, and set to 0 otherwise. */ - WS_DEVICE_CAP_INVITATION_PROCEDURE = 0x20, -} ws_device_cap_flag_e; - -typedef enum { - /* The P2P Group Owner field shall be set to 1 - * when the P2P Device is operating as a Group Owner, - * and set to 0 otherwise. */ - WS_GROUP_CAP_GROUP_OWNER = 0x01, - - /* The Persistent P2P Group field shall be set to 1 - * when the P2P Device is hosting, or intends to host, - * a persistent P2P Group, and set to 0 otherwise. */ - WS_GROUP_CAP_PERSISTENT_GROUP = 0x02, - - /* The P2P Group Limit field shall be set to 1 - * when the P2P Group Owner is unable to add additional Clients - * to its P2P Group, and set to 0 otherwise. */ - WS_GROUP_CAP_GROUP_LIMIT = 0x04, - - /* The Intra-BSS Distribution field shall be set to 1 - * if the P2P Device is hosting, or intends to host, - * a P2P Group that provides a data distribution service - * between Clients in the P2P Group. - * The Intra-BSS Distribution field shall be set to 0, - * if the P2P Device is not a P2P Group Owner, - * or is not providing such a data distribution service. */ - WS_GROUP_CAP_INTRA_BSS_DISTRIB = 0x08, - - /* The Cross Connection field shall be set to 1 - * if the P2P Device is hosting, or intends to host, - * a P2P Group that provides cross connection - * between the P2P Group and a WLAN. - * The Cross Connection field shall be set to 0 - * if the P2P Device is not a P2P Group Owner, - * or is not providing a cross connection service. */ - WS_GROUP_CAP_CROSS_CONNECTION = 0x10, - - /* The Persistent Reconnect field shall be set to 1 - * when the P2P Device is hosting, or intends to host, - * a persistent P2P Group that allows reconnection - * without user intervention, and set to 0 otherwise. */ - WS_GROUP_CAP_PERSISTENT_RECONN = 0x20, - - /* The Group Formation field shall be set to 1 - * when the P2P Device is operating as a Group Owner - * in the Provisioning phase of Group Formation, - * and set to 0 otherwise. */ - WS_GROUP_CAP_GROUP_FORMATION = 0x40, -} ws_group_cap_flag_e; - -typedef enum { - /* If the Device Password ID is Default, the Enrollee should use - * its PIN password (from the label or display). This password may - * correspond to the label, display, or a user-defined password - * that has been configured to replace the original device password. */ - WS_DEV_PASSWD_ID_DEFAULT = 0x0000, - - /* User-specified indicates that the user has overridden the password - * with a manually selected value. */ - WS_DEV_PASSWD_ID_USER_SPECIFIED = 0x0001, - - /* Machine-specified indicates that the original PIN password has been - * overridden by a strong, machine-generated device password value. */ - WS_DEV_PASSWD_ID_MACHINE_SPECIFIED = 0x0002, - - /* The Rekey value indicates that the device's 256-bit rekeying - * password will be used. */ - WS_DEV_PASSWD_ID_REKEY = 0x0003, - - /* The PushButton value indicates that the PIN is the all-zero value - * reserved for the Push Button Configuration method. */ - WS_DEV_PASSWD_ID_PUSH_BUTTON = 0x0004, - - /* The Registrar-specified value indicates a PIN that has been - * obtained from the Registrar (via a display or other out-of-band - * method). This value may be further augmented with the optional - * "Identity" attribute in M1. */ - WS_DEV_PASSWD_ID_REGISTRAR_SPECIFIED = 0x0005, /* ENTER-PIN */ -} ws_dev_passwd_id_e; - -typedef enum { - WPS_ERROR_NONE, - - WPS_ERROR_OOBINFO_READ_FAIL, - WPS_ERROR_DECRYPTION_FAIL, - WPS_ERROR_2G_NOT_SUPPORTED, - WPS_ERROR_5G_NOT_SUPPORTED, - WPS_ERROR_WEAK_SIGNAL, - WPS_ERROR_NET_AUTH_FAIL, - WPS_ERROR_NET_ASSOC_FAIL, - WPS_ERROR_NO_DHCP_RESPONSE, - WPS_ERROR_DHCP_CONFIG_FAIL, - WPS_ERROR_IP_CONFLICT, - - WPS_ERROR_REGISTRAT_CONN_FAIL, - WPS_ERROR_PBC_SESSION_OVERLAP, - WPS_ERROR_ROGUE_ACTIVITY, - WPS_ERROR_DEVICE_BUSY, - WPS_ERROR_SETUP_LOCKED, - WPS_ERROR_MESSAGE_TIMEOUT, - WPS_ERROR_SESSION_TIMEOUT, - WPS_ERROR_PASSWORD_MISMATCH, -} ws_wps_error_e; - -#ifdef TIZEN_FEATURE_WIFI_DISPLAY -typedef enum { - WFD_SUBELM_ID_DEV_INFO, - WFD_SUBELM_ID_ASSOC_BSSID, - WFD_SUBELM_ID_AUDIO_FORMAT, - WFD_SUBELM_ID_VIDEO_FORMAT, - WFD_SUBELM_ID_3D_FORMAT, - WFD_SUBELM_ID_CONTENT_PROTECTION, - - WFD_SUBELM_ID_CUPLED_SYNC_INFO, - WFD_SUBELM_ID_EXT_CAPAB, - WFD_SUBELM_ID_LOCAL_IP, - WFD_SUBELM_ID_SESSION_INFO, - WFD_SUBELM_ID_ALT_MAC, -} ws_wfd_subelm_id_e; -#define WFD_SUBELEM_LEN_DEV_INFO 6 -#define WFD_SUBELM_LEN_ASSOC_BSSID 6 -#define WFD_SUBELM_LEN_CUPLED_SYNC_INFO 7 -#endif /* TIZEN_FEATURE_WIFI_DISPLAY */ - -typedef struct { - char *string; - int index; -} ws_string_s; - -typedef enum { - WFD_OEM_NETFLAG_CURRENT, - WFD_OEM_NETFLAG_DISABLED, - WFD_OEM_NETFLAG_TEMP_DISABLED, - WFD_OEM_NETFLAG_P2P_PERSISTENT, -} ws_netowrk_flag_e; - -typedef struct { - int network_id; - char ssid[OEM_DEV_NAME_LEN+1]; - unsigned char bssid[OEM_MACADDR_LEN]; - int flags; -} ws_network_info_s; - -typedef struct { - int iftype; - int ctrl_sock; - int mon_sock; - char *ifname; - int error_count; - int gsource; -} ws_sock_data_s; - -typedef struct { - int initialized; /* check whether plugin is initialized or not. block init function if initialized */ - int activated; - int concurrent; - int global_sock; - ws_sock_data_s *common; - ws_sock_data_s *group; - unsigned char local_dev_addr[WS_MACADDR_LEN]; - wfd_oem_event_cbs_s *callback; -} ws_plugin_data_s; - -int ws_init(wfd_oem_event_cbs_s *event_cbs); -int ws_deinit(); -int ws_activate(int concurrent); -int ws_deactivate(int concurrent); -int ws_start_scan(wfd_oem_scan_param_s *param); -int ws_restart_scan(int freq); -int ws_stop_scan(); -int ws_get_visibility(int *visibility); -int ws_set_visibility(int visibility); -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 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); -int ws_get_pin(char *pin); -int ws_set_pin(char *pin); -int ws_generate_pin(char **pin); -int ws_get_supported_wps_mode(); -int ws_create_group(wfd_oem_group_param_s *param); -int ws_destroy_group(const char *ifname); -int ws_invite(unsigned char *peer_addr, wfd_oem_invite_param_s *param); -int ws_wps_start(unsigned char *peer_addr, int wps_mode, const char *pin); -int ws_enrollee_start(unsigned char *peer_addr, int wps_mode, const char *pin); -int ws_wps_cancel(); -int ws_get_dev_name(char *dev_name); -int ws_set_dev_name(char *dev_name); -int ws_get_dev_mac(char *dev_mac); -int ws_get_dev_type(int *pri_dev_type, int *sec_dev_type); -int ws_set_dev_type(int pri_dev_type, int sec_dev_type); -int ws_get_go_intent(int *go_intent); -int ws_set_go_intent(int go_intent); -int ws_set_country(char *ccode); - -int ws_get_persistent_groups(wfd_oem_persistent_group_s **groups, int *group_count); -int ws_remove_persistent_group(char *ssid, unsigned char *bssid); -int ws_set_persistent_reconnect(unsigned char *bssid, int reconnect); - -#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY -int ws_start_service_discovery(unsigned char *mac_addr, int service_type); -int ws_cancel_service_discovery(unsigned char *mac_addr, int service_type); - -int ws_serv_add(wfd_oem_new_service_s *service); -int ws_serv_del(wfd_oem_new_service_s *service); -#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */ - -#ifdef TIZEN_FEATURE_WIFI_DISPLAY -int ws_miracast_init(int enable); -int ws_set_display(wfd_oem_display_s *wifi_display); -#endif /* TIZEN_FEATURE_WIFI_DISPLAY */ - -int ws_refresh(); -int ws_save_config(void); -int ws_set_operating_channel(int channel); -int ws_remove_all_network(void); -int ws_get_wpa_status(int *wpa_status); - -#if defined(TIZEN_FEATURE_ASP) -int ws_advertise_service(wfd_oem_asp_service_s *service, int replace); -int ws_cancel_advertise_service(wfd_oem_asp_service_s *service); -int ws_seek_service(wfd_oem_asp_service_s *service); -int ws_cancel_seek_service(wfd_oem_asp_service_s *service); -int ws_asp_prov_disc_req(wfd_oem_asp_prov_s *asp_params); -#endif /* TIZEN_FEATURE_ASP */ - -int ws_add_vsie(wfd_oem_vsie_frames_e frame_id, const char* vsie); -int ws_get_vsie(wfd_oem_vsie_frames_e frame_id, char **vsie); -int ws_remove_vsie(wfd_oem_vsie_frames_e frame_id, const char *vsie); - -#endif /* __WFD_PLUGIN_WPASUPPLICANT_H__ */ diff --git a/plugin/wpasupplicant/ctrl_iface_sock/wfd-plugin-wpasupplicant.c b/plugin/wpasupplicant/ctrl_iface_sock/wfd-plugin-wpasupplicant.c deleted file mode 100644 index bbc70f8..0000000 --- a/plugin/wpasupplicant/ctrl_iface_sock/wfd-plugin-wpasupplicant.c +++ /dev/null @@ -1,5062 +0,0 @@ -/* - * Network Configuration Module - * - * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -/** - * This file implements wifi direct wpasupplicant plugin functions. - * - * @file wfd_plugin_wpasupplicant.c - * @author Gibyoung Kim (lastkgb.kim@samsung.com) - * @version 0.7 - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define _GNU_SOURCE -#include -#include -#include -#include -#include - -#include -#include - -#include - -#include "wifi-direct-oem.h" -#include "wfd-plugin-log.h" -#include "wfd-plugin-wpasupplicant.h" - -#define NETCONFIG_SERVICE "net.netconfig" -#define NETCONFIG_WIFI_INTERFACE "net.netconfig.wifi" -#define NETCONFIG_WIFI_PATH "/net/netconfig/wifi" - -#define NETCONFIG_DBUS_REPLY_TIMEOUT (10 * 1000) - -#define SUPPL_GLOBAL_INTF_PATH tzplatform_mkpath(TZ_SYS_RUN, "wpa_global/") -#define SUPPL_IFACE_PATH tzplatform_mkpath(TZ_SYS_RUN, "wpa_supplicant/") -#define SUPPL_GROUP_IFACE_PATH tzplatform_mkpath(TZ_SYS_RUN, "wpa_supplicant/") - -#if defined TIZEN_PROFILE_MOBILE -#define DEFAULT_MAC_FILE_PATH tzplatform_mkpath(TZ_SYS_ETC, ".mac.info") -#endif - -#if defined TIZEN_WIFI_MODULE_BUNDLE -#define DEFAULT_MAC_FILE_PATH "/sys/class/net/wlan0/address" -#endif - -#ifndef DEFAULT_MAC_FILE_PATH -#define DEFAULT_MAC_FILE_PATH "/sys/class/net/p2p0/address" -#endif - -ws_string_s ws_event_strs[] = { - /* discovery */ - {"P2P-DEVICE-FOUND", WS_EVENT_DEVICE_FOUND}, - {"P2P-DEVICE-LOST", WS_EVENT_DEVICE_LOST}, - {"P2P-FIND-STOPPED", WS_EVENT_FIND_STOPED}, - - /* provision discovery */ - {"P2P-PROV-DISC-PBC-REQ", WS_EVENT_PROV_DISC_PBC_REQ}, - {"P2P-PROV-DISC-SHOW-PIN", WS_EVENT_PROV_DISC_SHOW_PIN}, - {"P2P-PROV-DISC-ENTER-PIN", WS_EVENT_PROV_DISC_ENTER_PIN}, - {"P2P-PROV-DISC-PBC-RESP", WS_EVENT_PROV_DISC_PBC_RESP}, - {"P2P-PROV-DISC-FAILURE", WS_EVENT_PROV_DISC_FAILURE}, - - /* connection */ - {"P2P-GO-NEG-REQUEST", WS_EVENT_GO_NEG_REQUEST}, - {"P2P: Received GO Negotiation Request from", WS_EVENT_GO_NEG_REQUEST}, - {"P2P-GO-NEG-FAILURE", WS_EVENT_GO_NEG_FAILURE}, - {"P2P-GO-NEG-SUCCESS", WS_EVENT_GO_NEG_SUCCESS}, - {"WPS-FAIL", WS_EVENT_WPS_FAIL}, - {"P2P-GROUP-FORMATION-FAILURE", WS_EVENT_GROUP_FORMATION_FAILURE}, - {"WPS-SUCCESS", WS_EVENT_WPS_SUCCESS}, - {"WPS-REG-SUCCESS", WS_EVENT_WPS_REG_SUCCESS}, - {"P2P-GROUP-FORMATION-SUCCESS", WS_EVENT_GROUP_FORMATION_SUCCESS}, - - {"AP-STA-CONNECTED", WS_EVENT_STA_CONNECTED}, - - /* invite */ - {"P2P-INVITATION-RECEIVED", WS_EVENT_INVITATION_RECEIVED}, - {"P2P-INVITATION-RESULT", WS_EVENT_INVITATION_RESULT}, - - {"AP-STA-DISCONNECTED", WS_EVENT_STA_DISCONNECTED}, - - /* group */ - {"P2P-GROUP-STARTED", WS_EVENT_GROUP_STARTED}, - {"P2P-GROUP-REMOVED", WS_EVENT_GROUP_REMOVED}, - -#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY - {"P2P-SERV-DISC-RESP", WS_EVENT_SERV_DISC_RESP}, -#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */ - - {"CTRL-EVENT-TERMINATING", WS_EVENT_TERMINATING}, - - {"", WS_EVENT_LIMIT}, - }; - -ws_string_s ws_dev_info_strs[] = { - {"p2p_dev_addr", WS_DEV_INFO_P2P_DEV_ADDR}, - {"name", WS_DEV_INFO_DEV_NAME}, - {"pri_dev_type", WS_DEV_INFO_DEV_TYPE}, - {"config_methods", WS_DEV_INFO_CONFIG_METHODS}, - {"dev_capab", WS_DEV_INFO_DEV_CAP}, - {"group_capab", WS_DEV_INFO_GROUP_CAP}, - {"p2p_go_addr", WS_DEV_INFO_P2P_GO_ADDR}, -#ifdef TIZEN_FEATURE_WIFI_DISPLAY - {"wfd_dev_info", WS_DEV_INFO_WFD_DEV_INFO}, -#endif /* TIZEN_FEATURE_WIFI_DISPLAY */ - {"", WS_DEV_INFO_LIMIT}, - }; - -ws_string_s ws_conn_info_strs[] = { - {"dev_passwd_id", WS_CONN_INFO_DEV_PWD_ID}, - {"status", WS_CONN_INFO_STATUS}, - {"config_error", WS_CONN_INFO_ERROR}, - {"", WS_CONN_INFO_LIMIT}, - }; - -ws_string_s ws_invite_info_strs[] = { - {"sa", WS_INVITE_INFO_SRC_ADDR}, - {"go_dev_addr", WS_INVITE_INFO_GO_DEV_ADDR}, - {"bssid", WS_INVITE_INFO_BSSID}, - {"listen", WS_INVITE_INFO_LISTEN}, - {"op_freq", WS_INVITE_INFO_FREQ}, - {"persistent_id", WS_INVITE_INFO_PERSISTENT_ID}, - {"status", WS_INVITE_INFO_STATUS}, - {"", WS_INVITE_INFO_LIMIT}, - }; - -ws_string_s ws_group_info_strs[] = { - {"ssid", WS_GROUP_INFO_SSID}, - {"freq", WS_GROUP_INFO_FREQ}, - {"passphrase", WS_GROUP_INFO_PASS}, - {"go_dev_addr", WS_GROUP_INFO_GO_DEV_ADDR}, - {"status", WS_GROUP_INFO_STATUS}, - {"[PERSISTENT]", WS_GROUP_INFO_PERSISTENT}, -#ifdef TIZEN_FEATURE_IP_OVER_EAPOL - {"ip_addr", WS_GROUP_INFO_IP_ADDR}, - {"ip_mask", WS_GROUP_INFO_IP_MASK}, - {"go_ip_addr", WS_GROUP_INFO_GO_IP_ADDR}, -#endif /* TIZEN_FEATURE_IP_OVER_EAPOL */ - {"", WS_GROUP_INFO_LIMIT}, - - }; - -ws_string_s ws_peer_info_strs[] = { - {"age", WS_PEER_INFO_AGE}, - {"listen_freq", WS_PEER_INFO_LISTEN_FREQ}, - {"level", WS_PEER_INFO_LEVEL}, - {"wps_method", WS_PEER_INFO_WPS_METHOD}, - {"interface_addr", WS_PEER_INFO_INTERFACE_ADDR}, - {"member_in_go_dev", WS_PEER_INFO_MEMBER_IN_GO_DEV}, - {"member_in_go_iface", WS_PEER_INFO_MEMBER_IN_GO_IFACE}, - {"pri_dev_type", WS_PEER_INFO_PRI_DEV_TYPE}, - {"device_name", WS_PEER_INFO_DEVICE_NAME}, - {"manufacturer", WS_PEER_INFO_MANUFACTURER}, - {"model_name", WS_PEER_INFO_MODEL_NAME}, - {"model_number", WS_PEER_INFO_MODEL_NUMBER}, - {"serial_number", WS_PEER_INFO_SERIAL_NUMBER}, - {"config_methods", WS_PEER_INFO_CONFIG_METHODS}, - {"dev_capab", WS_PEER_INFO_DEV_CAPAB}, - {"group_capab", WS_PEER_INFO_GROUP_CAPAB}, - {"go_neg_req_sent", WS_PEER_INFO_GO_NEG_REQ_SENT}, - {"go_state", WS_PEER_INFO_GO_STATE}, - {"dialog_token", WS_PEER_INFO_DIALOG_TOKEN}, - {"intended_addr", WS_PEER_INFO_INTENDED_ADDR}, - {"country", WS_PEER_INFO_COUNTRY}, - {"oper_freq", WS_PEER_INFO_OPER_FREQ}, - {"req_config_methods", WS_PEER_INFO_REQ_CONFIG_METHODS}, - {"flags", WS_PEER_INFO_FLAGS}, - {"status", WS_PEER_INFO_STATUS}, - {"wait_count", WS_PEER_INFO_WAIT_COUNT}, - {"invitation_reqs", WS_PEER_INFO_INVITATION_REQS}, -#ifdef TIZEN_FEATURE_WIFI_DISPLAY - {"wfd_subelems", WS_PEER_INFO_WFD_SUBELEMS}, -#endif /* TIZEN_FEATURE_WIFI_DISPLAY */ - }; - -ws_string_s ws_conf_attr_strs[] = { - {"device_name", WFD_OEM_CONFIG_ATTR_STR_DEVICE_NAME}, - {"p2p_ssid_postfix", WFD_OEM_CONFIG_ATTR_STR_SSID_POSTFIX}, - {"country", WFD_OEM_CONFIG_ATTR_STR_COUNTRY}, - {"p2p_go_intent", WFD_OEM_CONFIG_ATTR_NUM_GO_INTENT}, - {"p2p_listen_channel", WFD_OEM_CONFIG_ATTR_NUM_LISTEN_FREQ}, - {"p2p_oper_channel", WFD_OEM_CONFIG_ATTR_NUM_OPER_FREQ}, - {"p2p_pref_chan", WFD_OEM_CONFIG_ATTR_NUM_PREF_FREQ}, - {"persistent_reconnect", WFD_OEM_CONFIG_ATTR_NUM_PERSIST_RECONN}, - {"wifi_display", WFD_OEM_CONFIG_ATTR_NUM_WIFI_DISPLAY}, - {"p2p_disabled", WFD_OEM_CONFIG_ATTR_NUM_P2P_DISABLED}, - {"max_num_sta", WFD_OEM_CONFIG_ATTR_NUM_MAX_STA}, - }; - -static wfd_oem_ops_s supplicant_ops = { - .init = ws_init, - .deinit = ws_deinit, - .activate = ws_activate, - .deactivate = ws_deactivate, - - .start_scan = ws_start_scan, - .stop_scan = ws_stop_scan, - .get_visibility = ws_get_visibility, - .set_visibility = ws_set_visibility, - .get_scan_result = ws_get_scan_result, - .get_peer_info = ws_get_peer_info, - - .prov_disc_req = ws_prov_disc_req, - - .connect = ws_connect, - .disconnect = ws_disconnect, - .reject_connection = ws_reject_connection, - .cancel_connection = ws_cancel_connection, - - .get_connected_peers = ws_get_connected_peers, - .get_pin = ws_get_pin, - .set_pin = ws_set_pin, - .generate_pin = ws_generate_pin, - .get_supported_wps_mode = ws_get_supported_wps_mode, - - .create_group = ws_create_group, - .destroy_group = ws_destroy_group, - .invite = ws_invite, - .wps_start = ws_wps_start, - .enrollee_start = ws_enrollee_start, - .wps_cancel = ws_wps_cancel, - - .get_dev_name = ws_get_dev_name, - .set_dev_name = ws_set_dev_name, - .get_dev_mac = ws_get_dev_mac, - .get_dev_type = ws_get_dev_type, - .set_dev_type = ws_set_dev_type, - .get_go_intent = ws_get_go_intent, - .set_go_intent = ws_set_go_intent, - .set_country = ws_set_country, - .get_persistent_groups = ws_get_persistent_groups, - .remove_persistent_group = ws_remove_persistent_group, - .set_persistent_reconnect = ws_set_persistent_reconnect, - -#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY - .start_service_discovery = ws_start_service_discovery, - .cancel_service_discovery = ws_cancel_service_discovery, - - .serv_add = ws_serv_add, - .serv_del = ws_serv_del, -#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */ - -#ifdef TIZEN_FEATURE_WIFI_DISPLAY - .miracast_init = ws_miracast_init, - .set_display = ws_set_display, -#endif /* TIZEN_FEATURE_WIFI_DISPLAY */ - - .refresh = ws_refresh, - .save_config = ws_save_config, - .set_operating_channel = ws_set_operating_channel, - .remove_all_network = ws_remove_all_network, - .get_wpa_status = ws_get_wpa_status, - -#if defined(TIZEN_FEATURE_ASP) - .advertise_service = ws_advertise_service, - .cancel_advertise_service = ws_cancel_advertise_service, - .seek_service = ws_seek_service, - .cancel_seek_service = ws_cancel_seek_service, - .asp_prov_disc_req = ws_asp_prov_disc_req, -#endif /* TIZEN_FEATURE_ASP */ - - .add_vsie = ws_add_vsie, - .get_vsie = ws_get_vsie, - .remove_vsie = ws_remove_vsie, - - }; - -static ws_plugin_data_s *g_pd; -static unsigned char g_pd_out[OEM_MACADDR_LEN]; -static unsigned char null_mac[OEM_MACADDR_LEN] = {0, 0, 0, 0, 0, 0}; - -#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY -static GList *service_list; -#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */ - -static gboolean ws_event_handler(GIOChannel *source, - GIOCondition condition, - gpointer data); - -int wfd_plugin_load(wfd_oem_ops_s **ops) -{ - if (!ops) { - WDP_LOGE("Invalid parameter"); - return -1; - } - - *ops = &supplicant_ops; - - return 0; -} - -#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY -static int _change_str_order(char *src, int length, int unit, char *dest) -{ - int i = 0; - - if (!src || length < 0 || length < unit || !dest) { - WDP_LOGE("Invalid parameter"); - return -1; - } - - for (i = 0; i < (length / unit); i++) - memcpy(dest + length - (i + 1) * unit, src + (i * unit), unit); - - return 0; -} - - -static int _ws_hex_to_num(char *src, int len) -{ - char *temp = NULL; - int num = 0; - - if (!src || len < 0) { - WDP_LOGE("Invalid parameter"); - return -1; - } - - temp = (char*) g_try_malloc0(len + 1); - if (!temp) { - WDP_LOGE("Failed to allocate memory"); - return -1; - } - - memcpy(temp, src, len); - num = strtoul(temp, NULL, 16); - free(temp); - - return num; -} -#if 0 -static int _ws_hex_to_txt(char *src, int length, char *dest) -{ - char *temp = NULL; - char *ptr = NULL; - int len = 0; - int i = 0; - - if (!src || length < 0 || !dest) { - WDP_LOGE("Invalid parameter"); - return -1; - } - - ptr = src; - temp = dest; - - if (!length) - len = strlen(src); - else - len = length; - - for (i = 0; i < (len / 2) && *ptr != 0; i++) { - temp[i] = (char) _ws_hex_to_num(ptr, 2); - if (temp[i] < 0) { - WDP_LOGE("Failed to convert hexa string to num"); - return -1; - } - ptr += 2; - } - - return 0; -} -#endif -#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */ - -static int _ws_txt_to_devtype(char *txt, int *pri, int *sec) -{ - if (!txt || !pri || !sec) { - WDP_LOGE("Invalid parameter"); - return -1; - } - - if (strlen(txt) > WS_DEVTYPESTR_LEN) { - WDP_LOGE("Device type string is invalid [%s]", txt); - return -1; - } - - *pri = (int) strtoul(txt, &txt, 0); - txt = strrchr(txt, '-'); - *sec = (int) strtoul(txt+1, &txt, 16); - - return 0; -} - -static int _ws_txt_to_mac(char *txt, unsigned char *mac) -{ - int i = 0; - - if (!txt || !mac) { - WDP_LOGE("Invalid parameter"); - return -1; - } - - for (;;) { - mac[i++] = (char) strtoul(txt, &txt, 16); - if (!*txt++ || i == 6) - break; - } - - if (i != OEM_MACADDR_LEN) - return -1; - - return 0; -} - -static char *_ws_wps_to_txt(int wps_mode) -{ - switch (wps_mode) { - case WFD_OEM_WPS_MODE_PBC: - return WS_STR_PBC; - break; - case WFD_OEM_WPS_MODE_DISPLAY: - return WS_STR_DISPLAY; - break; - case WFD_OEM_WPS_MODE_KEYPAD: - return WS_STR_KEYPAD; - break; - default: - return ""; - break; - } -} - -static int _ws_freq_to_channel(int freq) -{ - if (freq < 2412 || freq > 5825 || - (freq > 2484 && freq < 5180)) { - WDP_LOGE("Invalid parameter"); - return -1; - } - - if (freq >= 5180) - return 36 + (freq - 5180)/5; - else if (freq <= 2472) - return 1 + (freq - 2412)/5; - else if (freq == 2484) - return 14; - else - return -1; -} - -gboolean _ws_util_execute_file(const char *file_path, - char *const args[], char *const envs[]) -{ - pid_t pid = 0; - int rv = 0; - errno = 0; - register unsigned int index = 0; - - while (args[index] != NULL) { - WDP_LOGD("[%s]", args[index]); - index++; - } - - if (!(pid = fork())) { - WDP_LOGD("pid(%d), ppid(%d)", getpid(), getppid()); - WDP_LOGD("Inside child, exec (%s) command", file_path); - - errno = 0; - if (execve(file_path, args, envs) == -1) { - WDP_LOGE("Fail to execute command (%s)", strerror(errno)); - exit(1); - } - } else if (pid > 0) { - if (waitpid(pid, &rv, 0) == -1) - WDP_LOGD("wait pid (%u) rv (%d)", pid, rv); - if (WIFEXITED(rv)) - WDP_LOGD("exited, rv=%d", WEXITSTATUS(rv)); - else if (WIFSIGNALED(rv)) - WDP_LOGD("killed by signal %d", WTERMSIG(rv)); - else if (WIFSTOPPED(rv)) - WDP_LOGD("stopped by signal %d", WSTOPSIG(rv)); - else if (WIFCONTINUED(rv)) - WDP_LOGD("continued"); - - return TRUE; - } - - WDP_LOGE("failed to fork (%s)", strerror(errno)); - return FALSE; -} - -static int _ws_check_socket(int sock) -{ - struct pollfd p_fd; - int res = 0; - - p_fd.fd = sock; - p_fd.events = POLLIN | POLLOUT | POLLERR | POLLHUP | POLLNVAL; - res = poll((struct pollfd *) &p_fd, 1, 1); - - if (res < 0) { - WDP_LOGE("Polling error from socket[%d]. [%s]", sock, strerror(errno)); - return -1; - } else if (res == 0) { - WDP_LOGD("poll timeout. socket is busy\n"); - return 1; - } else { - - if (p_fd.revents & POLLERR) { - WDP_LOGE("Error! POLLERR from socket[%d]", sock); - return -1; - } else if (p_fd.revents & POLLHUP) { - WDP_LOGE("Error! POLLHUP from socket[%d]", sock); - return -1; - } else if (p_fd.revents & POLLNVAL) { - WDP_LOGE("Error! POLLNVAL from socket[%d]", sock); - return -1; - } else if (p_fd.revents & POLLIN) { - WDP_LOGD("POLLIN from socket [%d]", sock); - return 0; - } else if (p_fd.revents & POLLOUT) { - WDP_LOGD("POLLOUT from socket [%d]", sock); - return 0; - } - } - - WDP_LOGD("Unknown poll event [%d]", p_fd.revents); - return -1; -} - -static int _ws_read_sock(int sock, char *data, int data_len) -{ - __WDP_LOG_FUNC_ENTER__; - struct pollfd p_fd; - int p_ret = 0; - int rbytes = 0; - - if (sock < SOCK_FD_MIN || !data || data_len <= 0) { - WDP_LOGE("Invalid parameter"); - return -1; - } - - p_fd.fd = sock; - p_fd.events = POLLIN | POLLERR | POLLHUP; - p_ret = poll(&p_fd, 1, WS_POLL_TIMEOUT); - - errno = 0; - if (p_ret > 0) { - if (p_fd.revents & POLLIN) { - WDP_LOGD("POLLIN from socket [%d]", sock); - errno = 0; - rbytes = read(sock, data, data_len); - if (rbytes < 0) { - WDP_LOGE("Failed to read data from socket[%d]. [%s]", sock, strerror(errno)); - return -1; - } - data[data_len-1] = '\0'; - __WDP_LOG_FUNC_EXIT__; - return rbytes; - } else if (p_fd.revents & POLLERR) { - WDP_LOGE("Error! POLLERR from socket[%d]", sock); - return -1; - } else if (p_fd.revents & POLLHUP) { - WDP_LOGE("Error! POLLHUP from socket[%d]", sock); - return -1; - } - } else if (p_ret == 0) { - WDP_LOGE("Polling timeout from socket[%d]", sock); - } else { - WDP_LOGE("Polling error from socket[%d]. [%s]", sock, strerror(errno)); - } - - __WDP_LOG_FUNC_EXIT__; - return -1; -} - -static int _ws_send_cmd(int sock, char *cmd, char *reply, int reply_len) -{ - __WDP_LOG_FUNC_ENTER__; - int wbytes = 0; - int res = 0; - - if (sock < SOCK_FD_MIN || !cmd || !reply || reply_len < 0) { - WDP_LOGE("Invalid parameter"); - return -1; - } - WDP_SECLOGD("Sending command [%s]", cmd); - - res = _ws_check_socket(sock); - if (res < 0) { - WDP_LOGE("Socket error"); - return -1; - } else if (res > 0) { - WDP_LOGE("Socket is busy"); - return -2; - } - - errno = 0; - wbytes = write(sock, cmd, strlen(cmd)); - if (wbytes < 0) { - WDP_LOGE("Failed to write into socket[%d]. [%s]", sock, strerror(errno)); - return -1; - } - - res = _ws_read_sock(sock, reply, reply_len); - if (res < 0) { - WDP_LOGE("Failed to read return for command"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -static int _ws_flush() -{ - __WDP_LOG_FUNC_ENTER__; - ws_sock_data_s *sock = g_pd->common; - char reply[1024] = {0,}; - int res = 0; - - if (!sock) { - WDP_LOGE("Socket is NULL"); - return -1; - } - - res = _ws_send_cmd(sock->ctrl_sock, WS_CMD_P2P_FLUSH, reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - if (strstr(reply, "FAIL")) { - WDP_LOGE("Failed to flush"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - WDP_LOGD("Succeeded to flush"); - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -static int _ws_cancel() -{ - __WDP_LOG_FUNC_ENTER__; - ws_sock_data_s *sock = g_pd->common; - char reply[1024] = {0,}; - int res = 0; - - if (!sock) { - WDP_LOGE("Socket is NULL"); - return -1; - } - - res = _ws_send_cmd(sock->ctrl_sock, WS_CMD_P2P_CANCEL, reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - if (strstr(reply, "FAIL")) { - WDP_LOGE("Failed to cancel"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - WDP_LOGD("Succeeded to cancel"); - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -static int _create_ctrl_intf(char *ctrl_intf_path, char *supp_path) -{ - __WDP_LOG_FUNC_ENTER__; - struct sockaddr_un srv_addr; - struct sockaddr_un local_addr; - int sock = 0; - int res = 0; - - if (!ctrl_intf_path || !supp_path) { - WDP_LOGE("Invalid parameter"); - return -1; - } - unlink(ctrl_intf_path); - - errno = 0; - sock = socket(AF_UNIX, SOCK_DGRAM, 0); - if (sock < SOCK_FD_MIN) { - WDP_LOGE("Failed to create socket. [%s]", strerror(errno)); - if (sock >= 0) - close(sock); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - WDP_LOGI("Succeeded to create socket [%d]\n", sock); - - memset(&srv_addr, 0, sizeof(srv_addr)); - srv_addr.sun_family = AF_UNIX; - snprintf(srv_addr.sun_path, sizeof(srv_addr.sun_path), "%s", supp_path); - - memset(&local_addr, 0, sizeof(local_addr)); - local_addr.sun_family = AF_UNIX; - snprintf(local_addr.sun_path, sizeof(local_addr.sun_path), "%s", ctrl_intf_path); - - res = bind(sock, (struct sockaddr*) &local_addr, sizeof(local_addr)); - if (res < 0) { - WDP_LOGE("Failed to bind local socket [%s]. Try again...", strerror(errno)); - unlink(ctrl_intf_path); - - close(sock); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - errno = 0; - res = connect(sock, (struct sockaddr*) &srv_addr, sizeof(srv_addr)); - if (res < 0) { - WDP_LOGE("Failed to connect to server socket [%s]", strerror(errno)); - close(sock); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - WDP_LOGI("Succeeded to connect to server socket [%d]", sock); - - __WDP_LOG_FUNC_EXIT__; - return sock; -} - -static int _attach_mon_intf(int sock) -{ - __WDP_LOG_FUNC_ENTER__; - char cmd[8] = {0}; - char reply[8] = {0,}; - int res = 0; - - if (sock < SOCK_FD_MIN) { - WDP_LOGE("Invalid parameter"); - return -1; - } - - snprintf(cmd, sizeof(cmd), WS_CMD_ATTACH); - res = _ws_send_cmd(sock, cmd, reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - if (strstr(reply, "FAIL")) { - WDP_LOGE("Failed to operate command(wpa_supplicant)"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -static int _connect_to_supplicant(char *ifname, ws_sock_data_s **sock_data) -{ - __WDP_LOG_FUNC_ENTER__; - ws_sock_data_s *sock = NULL; - int ctrl_sock = -1; - int mon_sock = -1; - char ctrl_path[32] = {0, }; - char mon_path[32] = {0, }; - char suppl_path[40] = {0, }; - int res = 0; - int i = 0; - - const char *supp_iface_path = SUPPL_IFACE_PATH; - const char *supp_group_iface_path = SUPPL_GROUP_IFACE_PATH; - - if (!ifname || !sock_data) { - WDP_LOGE("Invalie parameter"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - errno = 0; - sock = (ws_sock_data_s*) g_try_malloc0(sizeof(ws_sock_data_s)); - if (!sock) { - WDP_LOGE("Failed to allocate memory for socket data", strerror(errno)); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - snprintf(ctrl_path, sizeof(ctrl_path), "/tmp/%s_control", ifname); - snprintf(mon_path, sizeof(mon_path), "/tmp/%s_monitor", ifname); - if (strncmp(ifname, GROUP_IFACE_NAME, 11)) - g_snprintf(suppl_path, sizeof(suppl_path), "%s%s", supp_iface_path, ifname); - else - g_snprintf(suppl_path, sizeof(suppl_path), "%s%s", supp_group_iface_path, ifname); - - - for (i = 0; i < WS_CONN_RETRY_COUNT; i++) { - ctrl_sock = _create_ctrl_intf(ctrl_path, suppl_path); - if (ctrl_sock < SOCK_FD_MIN) { - WDP_LOGE("Failed to create control interface socket for %s", ifname); - continue; - } - WDP_LOGD("Succeeded to create control interface socket[%d] for %s", ctrl_sock, ifname); - - mon_sock = _create_ctrl_intf(mon_path, suppl_path); - if (mon_sock < SOCK_FD_MIN) { - WDP_LOGE("Failed to create monitor interface socket for %s", ifname); - close(ctrl_sock); - ctrl_sock = -1; - continue; - } - WDP_LOGD("Succeeded to create monitor interface socket[%d] for %s", mon_sock, ifname); - - res = _attach_mon_intf(mon_sock); - if (res < 0) { - WDP_LOGE("Failed to attach monitor interface for event"); - close(ctrl_sock); - ctrl_sock = -1; - close(mon_sock); - mon_sock = -1; - continue; - } - WDP_LOGD("Succeeded to attach monitor interface for event"); - break; - } - - if (i == WS_CONN_RETRY_COUNT) { - if (ctrl_sock >= 0) - close(ctrl_sock); - if (mon_sock >= 0) - close(mon_sock); - - free(sock); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - sock->ctrl_sock = ctrl_sock; - sock->mon_sock = mon_sock; - sock->ifname = strdup(ifname); - - GIOChannel *gio; - int gsource = 0; - gio = g_io_channel_unix_new(mon_sock); - gsource = g_io_add_watch(gio, G_IO_IN | G_IO_ERR | G_IO_HUP, - (GIOFunc) ws_event_handler, sock); - g_io_channel_unref(gio); - - sock->gsource = gsource; - - *sock_data = sock; - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -static gboolean _remove_event_source(gpointer data) -{ - __WDP_LOG_FUNC_ENTER__; - ws_sock_data_s *sock_data = NULL; - int res = 0; - - sock_data = (ws_sock_data_s *) data; - if (sock_data == NULL) { - WDP_LOGE("Invalid sock_data"); - return FALSE; - } - - if (sock_data->gsource < 0) { - WDP_LOGE("Invalid source ID [%d]", sock_data->gsource); - return FALSE; - } - - res = g_source_remove(sock_data->gsource); - if (!res) { - WDP_LOGE("Failed to remove GSource(%d)", sock_data->gsource); - return FALSE; - } - WDP_LOGD("Succeeded to remove GSource"); - - __WDP_LOG_FUNC_EXIT__; - return FALSE; -} - -static int _disconnect_from_supplicant(char *ifname, ws_sock_data_s *sock_data) -{ - __WDP_LOG_FUNC_ENTER__; - int res = 0; - char ctrl_path[32] = {0, }; - char mon_path[32] = {0, }; - char cmd[8] = {0, }; - char reply[1024] = {0, }; - - if (!ifname || !sock_data) { - WDP_LOGE("Invalie parameter"); - return -1; - } - - /* detach monitor interface */ - g_snprintf(cmd, sizeof(cmd), WS_CMD_DETACH); - res = _ws_send_cmd(sock_data->mon_sock, cmd, reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant. Keep going to close socket."); - } else { - if (!strncmp(reply, "FAIL", 4)) { - WDP_LOGE("Failed to detach monitor sock [%d]", sock_data->mon_sock); - /* TODO: I think there is no need to exit */ - __WDP_LOG_FUNC_EXIT__; - return -1; - } - WDP_LOGD("Succeeded to detach monitor sock for %s", ifname ? ifname : "NULL"); - } - - if (sock_data->gsource > 0) - g_idle_add(_remove_event_source, (gpointer) sock_data); - sock_data->gsource = 0; - - /* close control interface */ - g_snprintf(ctrl_path, sizeof(ctrl_path), "/tmp/%s_control", ifname); - snprintf(mon_path, sizeof(mon_path), "/tmp/%s_monitor", ifname); - - if (sock_data->ctrl_sock >= SOCK_FD_MIN) - close(sock_data->ctrl_sock); - sock_data->ctrl_sock = -1; - unlink(ctrl_path); - - if (sock_data->mon_sock >= SOCK_FD_MIN) - close(sock_data->mon_sock); - sock_data->mon_sock = -1; - unlink(mon_path); - - if (sock_data->ifname) - free(sock_data->ifname); - - free(sock_data); - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY -int _check_service_query_exists(wfd_oem_service_s *service) -{ - int count = 0; - wfd_oem_service_s *data = NULL; - - for (count = 0; count < g_list_length(service_list); count++) { - data = (wfd_oem_service_s*) g_list_nth_data(service_list, count); - if (strncmp(service->query_id, data->query_id, OEM_QUERY_ID_LEN) == 0) { - WDP_LOGD("Query already exists"); - return 1; - } - } - return 0; -} - -static wfd_oem_service_s* _remove_service_query(char * s_type, char *mac_str, char *query_id) -{ - if (NULL == s_type || NULL == mac_str || NULL == query_id) - return NULL; - - int count = 0; - wfd_oem_service_s *data = NULL; - - for (count = 0; count < g_list_length(service_list); count++) { - data = (wfd_oem_service_s*) g_list_nth_data(service_list, count); - if (data && !strncmp(data->service_type, s_type, SERVICE_TYPE_LEN) && - memcmp(data->dev_addr, mac_str, OEM_MACSTR_LEN - 1) == 0) { - strncpy(query_id, data->query_id, OEM_QUERY_ID_LEN); - break; - } - } - if (strlen(query_id) <= 0) { - WDP_LOGD("!! Query ID not found !!"); - return NULL; - } - - WDP_LOGD("query id :[0x%s]", query_id); - - return data; - -} -#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */ - -static int _extract_word(const char *data, char **value) -{ - int i = 0; - - if (!data || !value) { - WDP_LOGE("Invalid parameter"); - return -1; - } - - for (i = 0; data[i]; i++) - if (data[i] == '\n' || data[i] == '\r' || data[i] == ' ' || data[i] == '\t') - break; - - if (i > 0) { - *value = (char*) g_try_malloc0(i + 1); - if (!(*value)) { - WDP_LOGE("Failed to allocate memory for value"); - return -1; - } - strncpy(*value, data, i); - (*value)[i] = '\0'; - WDP_LOGV("Extracted word: %s", *value); - } - - return i; -} - -static int _extract_value_str(const char *data, const char *key, char **value) -{ - char *tmp_str = NULL; - int i = 0; - - if (!data || !key || !value) { - WDP_LOGE("Invalid parameter"); - return -1; - } - - tmp_str = strstr(data, key); - if (!tmp_str) { - WDP_LOGE("Key[%s] is not found", key); - return -1; - } - tmp_str = tmp_str + strlen(key) + 1; - - if (tmp_str[0] == '\'' || tmp_str[0] == '\"') { - tmp_str += 1; - for (i = 0; tmp_str[i]; i++) { - if (tmp_str[i] == '\'' || tmp_str[i] == '\"') - break; - } - } else { - for (i = 0; tmp_str[i]; i++) { - if (tmp_str[i] == '\n' || tmp_str[i] == '\r' || tmp_str[i] == ' ') - break; - } - } - - if (i > 0) { - *value = (char*) g_try_malloc0(i + 1); - if (!(*value)) { - WDP_LOGE("Failed to allocate memory for value"); - return -1; - } - strncpy(*value, tmp_str, i); - (*value)[i] = '\0'; - WDP_LOGV("Extracted string: %s", *value); - return i; - } - - return 0; -} - -static int _extract_peer_value_str(const char *data, const char *key, char **value) -{ - char *tmp_str = NULL; - int i = 0; - - if (!data || !key || !value) { - WDP_LOGE("Invalid parameter"); - return -1; - } - - tmp_str = strstr(data, key); - if (!tmp_str) { - WDP_LOGE("Key[%s] is not found", key); - return -1; - } - tmp_str = tmp_str + strlen(key) + 1; - - for (i = 0; tmp_str[i]; i++) { - if (tmp_str[i] == '\n' || tmp_str[i] == '\r') - break; - } - - if (i > 0) { - *value = (char*) g_try_malloc0(i + 1); - if (!(*value)) { - WDP_LOGE("Failed to allocate memory for value"); - return -1; - } - strncpy(*value, tmp_str, i); - (*value)[i] = '\0'; - WDP_LOGV("Extracted string: %s", *value); - return i; - } - - return 0; -} - -#if 0 -static int _check_dev_type(unsigned char *dev_addr, int *pri_dev_type, int *sec_dev_type) -{ - ws_sock_data_s *sock = g_pd->common; - char cmd[32] = {0, }; - char reply[1024] = {0,}; - char *manufacturer = NULL; - char *model_name = NULL; - char *model_number = NULL; - int res = 0; - - if (!dev_addr || !pri_dev_type || !sec_dev_type) { - WDP_LOGE("Invalid parameter"); - return -1; - } - - if (!sock) { - WDP_LOGE("Socket is NULL"); - return -1; - } - - snprintf(cmd, sizeof(cmd), WS_CMD_P2P_PEER MACSTR, MAC2STR(dev_addr)); - res = _ws_send_cmd(sock->ctrl_sock, cmd, reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - if (strstr(reply, "FAIL")) { - WDP_SECLOGD("Failed to get peer info [" MACSTR "]", MAC2STR(dev_addr)); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - WDP_SECLOGD("Succeeded to get peer info [" MACSTR "]", MAC2STR(dev_addr)); - - res = _extract_peer_value_str(reply, "model_number", &model_number); - if (res > 0 && !strncmp(model_number, "EAD-T10", 7)) { - *pri_dev_type = 8; - *sec_dev_type = 5; - free(model_number); - WDP_LOGD("peer device type set as Dongle"); - return 0; - } - if (model_number) - free(model_number); - - _extract_peer_value_str(reply, "manufacturer", &manufacturer); - _extract_peer_value_str(reply, "model_name", &model_name); - if (!manufacturer || !model_name) { - WDP_LOGE("parsing error"); - if (manufacturer) - free(manufacturer); - if (model_name) - free(model_name); - return -1; - } - - if (!strncmp(manufacturer, "SAMSUNG_ELECTRONICS", 19) && - !strncmp(model_name, "SAMSUNG_MOBILE", 14)) { - *pri_dev_type = 8; - *sec_dev_type = 4; - WDP_LOGD("peer device type set as Homesync"); - free(manufacturer); - free(model_name); - return 0; - } - if (manufacturer) - free(manufacturer); - if (model_name) - free(model_name); - - return -1; -} -#endif - -#ifdef TIZEN_FEATURE_WIFI_DISPLAY -static int _parsing_wfd_info(char *msg, wfd_oem_display_s *display) -{ - __WDP_LOG_FUNC_ENTER__; - - char wfd_info_msg[5] = {0, }; - char ctrl_port_msg[5] = {0, }; - char max_tput_msg[5] = {0, }; - int wfd_info = 0; - if (!msg || strlen(msg) < 12) { - WDP_LOGE("Invalid parameter"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - /*wfd_info_msg:0013 1c44 000a */ - WDP_LOGE("Message to parse: %s", msg); - - strncpy(wfd_info_msg, msg, 4); - wfd_info = strtoul(wfd_info_msg, NULL, 16); - - if (wfd_info & WS_WFD_INFO_PRIMARY_SINK) - display->type |= WS_WFD_INFO_PRIMARY_SINK; - if (wfd_info & WS_WFD_INFO_SECONDARY_SINK) - display->type |= WS_WFD_INFO_SECONDARY_SINK; - - display->availability = (wfd_info & WS_WFD_INFO_AVAILABILITY) >> 4; - display->hdcp_support = (wfd_info & WS_WFD_INFO_HDCP_SUPPORT) >> 8; - - strncpy(ctrl_port_msg, msg+4, 4); - display->port = strtoul(ctrl_port_msg, NULL, 16); - strncpy(max_tput_msg, msg+8, 4); - display->max_tput = strtoul(max_tput_msg, NULL, 16); - - WDP_LOGE("type [%d],availability [%d],hdcp_support [%d],ctrl_port [%d] max_tput[%d]", - display->type, display->availability, display->hdcp_support, - display->port, display->max_tput); - - __WDP_LOG_FUNC_EXIT__; - return 0; -} -#endif /* TIZEN_FEATURE_WIFI_DISPLAY */ - -static int _parsing_peer_info(char *msg, wfd_oem_device_s *peer) -{ - __WDP_LOG_FUNC_ENTER__; - int i, info_cnt = 0; - ws_string_s infos[WS_PEER_INFO_LIMIT]; - int config_methods = 0x00; - int group_capab = 0x00; - int res = 0; - - if (!msg || !peer) { - WDP_LOGE("Invalid parameter"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - _ws_txt_to_mac(msg, peer->dev_addr); - msg += OEM_MACSTR_LEN; - - memset(infos, 0x0, (WS_PEER_INFO_LIMIT) * sizeof(ws_string_s)); - for (i = 0; i < WS_PEER_INFO_LIMIT; i++) { - res = _extract_peer_value_str(msg, ws_peer_info_strs[i].string, &infos[info_cnt].string); - if (res > 0) { - infos[info_cnt].index = ws_peer_info_strs[i].index; - info_cnt++; - } - } - if (info_cnt == 0) { - WDP_LOGD("Device info ids have no valid information"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - for (i = 0; i < info_cnt; i++) { - switch (infos[i].index) { - case WS_PEER_INFO_AGE: - peer->age = (int) strtoul(infos[i].string, NULL, 10); - break; - case WS_PEER_INFO_LISTEN_FREQ: - { - int freq = 0; - freq = (int) strtoul(infos[i].string, NULL, 10); - peer->channel = _ws_freq_to_channel(freq); - } - break; - case WS_PEER_INFO_LEVEL: - break; - case WS_PEER_INFO_WPS_METHOD: - break; - case WS_PEER_INFO_INTERFACE_ADDR: - break; - case WS_PEER_INFO_MEMBER_IN_GO_DEV: - { - res = _ws_txt_to_mac(infos[i].string, peer->go_dev_addr); - if (res < 0) - memset(peer->go_dev_addr, 0x00, OEM_MACADDR_LEN); - - if (memcmp(peer->go_dev_addr, null_mac, OEM_MACADDR_LEN)) - peer->dev_role = WFD_OEM_DEV_ROLE_GC; - } - break; - case WS_PEER_INFO_MEMBER_IN_GO_IFACE: - break; - case WS_PEER_INFO_PRI_DEV_TYPE: - res = _ws_txt_to_devtype(infos[i].string, &peer->pri_dev_type, &peer->sec_dev_type); - if (res < 0) { - peer->pri_dev_type = 0; - peer->sec_dev_type = 0; - } - break; - case WS_PEER_INFO_DEVICE_NAME: - strncpy(peer->dev_name, infos[i].string, OEM_DEV_NAME_LEN); - peer->dev_name[OEM_DEV_NAME_LEN] = '\0'; - break; - case WS_PEER_INFO_MANUFACTURER: - break; - case WS_PEER_INFO_MODEL_NAME: - break; - case WS_PEER_INFO_MODEL_NUMBER: - break; - case WS_PEER_INFO_SERIAL_NUMBER: - break; - case WS_PEER_INFO_CONFIG_METHODS: - config_methods = (int) strtoul(infos[i].string, NULL, 16); - if (config_methods & WS_CONFIG_METHOD_DISPLAY) - peer->config_methods |= WFD_OEM_WPS_MODE_DISPLAY; - if (config_methods & WS_CONFIG_METHOD_PUSHBUTTON) - peer->config_methods |= WFD_OEM_WPS_MODE_PBC; - if (config_methods & WS_CONFIG_METHOD_KEYPAD) - peer->config_methods |= WFD_OEM_WPS_MODE_KEYPAD; - break; - case WS_PEER_INFO_DEV_CAPAB: - peer->dev_flags = (int) strtoul(infos[i].string, NULL, 16); - break; - case WS_PEER_INFO_GROUP_CAPAB: - group_capab = (int) strtoul(infos[i].string, NULL, 16); - if (group_capab & WS_GROUP_CAP_GROUP_OWNER) { - peer->group_flags = WFD_OEM_GROUP_FLAG_GROUP_OWNER; - peer->dev_role = WFD_OEM_DEV_ROLE_GO; - } - if (group_capab & WS_GROUP_CAP_PERSISTENT_GROUP) - peer->group_flags = WFD_OEM_GROUP_FLAG_PERSISTENT_GROUP; - break; - case WS_PEER_INFO_GO_NEG_REQ_SENT: - break; - case WS_PEER_INFO_GO_STATE: - break; - case WS_PEER_INFO_DIALOG_TOKEN: - break; - case WS_PEER_INFO_INTENDED_ADDR: - res = _ws_txt_to_mac(infos[i].string, peer->intf_addr); - if (res < 0) - memset(peer->intf_addr, 0x00, OEM_MACADDR_LEN); - break; - case WS_PEER_INFO_COUNTRY: - break; - case WS_PEER_INFO_OPER_FREQ: - break; - case WS_PEER_INFO_REQ_CONFIG_METHODS: - break; - case WS_PEER_INFO_FLAGS: - break; - case WS_PEER_INFO_STATUS: - break; - case WS_PEER_INFO_WAIT_COUNT: - break; - case WS_PEER_INFO_INVITATION_REQS: - break; -#ifdef TIZEN_FEATURE_WIFI_DISPLAY - case WS_PEER_INFO_WFD_SUBELEMS: - res = _parsing_wfd_info(infos[i].string+6, &peer->display); - if (res < 0) - memset(&peer->display, 0x00, sizeof(wfd_oem_display_s)); - break; -#endif /* TIZEN_FEATURE_WIFI_DISPLAY */ - default: - break; - } - } - - for (i = 0; i < info_cnt; i++) { - if (infos[i].string) - free(infos[i].string); - } - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -static wfd_oem_dev_data_s *_convert_msg_to_dev_info(char *msg) -{ - __WDP_LOG_FUNC_ENTER__; - int i; - int info_cnt = 0; - ws_string_s infos[WS_DEV_INFO_LIMIT]; - wfd_oem_dev_data_s *edata = NULL; - int config_methods = 0x00; - int group_capab = 0x00; - int res = 0; - - if (!msg) { - WDP_LOGE("Invalid parameter"); - return NULL; - } - WDP_SECLOGD("msg to be converted [%s]", msg); - - memset(infos, 0x0, (WS_DEV_INFO_LIMIT) * sizeof(ws_string_s)); - for (i = 0; ws_dev_info_strs[i].index < WS_DEV_INFO_LIMIT; i++) { - res = _extract_value_str(msg, ws_dev_info_strs[i].string, &infos[info_cnt].string); - if (res > 0) { - infos[info_cnt].index = ws_dev_info_strs[i].index; - if (infos[info_cnt].index == WS_DEV_INFO_P2P_DEV_ADDR) - WDP_SECLOGD("%dth info [%d:%s]", i, infos[info_cnt].index, infos[info_cnt].string); - else - WDP_LOGD("%dth info [%d:%s]", i, infos[info_cnt].index, infos[info_cnt].string); - info_cnt++; - } - } - - if (!info_cnt) { - WDP_LOGE("There is no item converted"); - return NULL; - } - - errno = 0; - edata = (wfd_oem_dev_data_s*) g_try_malloc0(sizeof(wfd_oem_dev_data_s)); - if (!edata) { - WDP_LOGE("Failed to allocate memory for device information [%s]", strerror(errno)); - return NULL; - } - - for (i = 0; i < info_cnt; i++) { - switch (infos[i].index) { - case WS_DEV_INFO_P2P_DEV_ADDR: - res = _ws_txt_to_mac(infos[i].string, edata->p2p_dev_addr); - if (res < 0) - memset(edata->p2p_dev_addr, 0x00, OEM_MACADDR_LEN); - break; - case WS_DEV_INFO_DEV_NAME: - strncpy(edata->name, infos[i].string, OEM_DEV_NAME_LEN); - edata->name[OEM_DEV_NAME_LEN] = '\0'; - break; - case WS_DEV_INFO_DEV_TYPE: - res = _ws_txt_to_devtype(infos[i].string, &edata->pri_dev_type, &edata->sec_dev_type); - if (res < 0) { - edata->pri_dev_type = 0; - edata->sec_dev_type = 0; - } - break; - case WS_DEV_INFO_CONFIG_METHODS: - config_methods = (int) strtoul(infos[i].string, NULL, 16); - if (config_methods & WS_CONFIG_METHOD_DISPLAY) - edata->config_methods |= WFD_OEM_WPS_MODE_DISPLAY; - if (config_methods & WS_CONFIG_METHOD_PUSHBUTTON) - edata->config_methods |= WFD_OEM_WPS_MODE_PBC; - if (config_methods & WS_CONFIG_METHOD_KEYPAD) - edata->config_methods |= WFD_OEM_WPS_MODE_KEYPAD; - break; - case WS_DEV_INFO_DEV_CAP: - edata->dev_flags = (int) strtoul(infos[i].string, NULL, 16); - break; - case WS_DEV_INFO_GROUP_CAP: - group_capab = (int) strtoul(infos[i].string, NULL, 16); - if (group_capab & WS_GROUP_CAP_GROUP_OWNER) { - edata->group_flags = WFD_OEM_GROUP_FLAG_GROUP_OWNER; - edata->dev_role = WFD_OEM_DEV_ROLE_GO; - } - if (group_capab & WS_GROUP_CAP_PERSISTENT_GROUP) - edata->group_flags = WFD_OEM_GROUP_FLAG_PERSISTENT_GROUP; - break; - case WS_DEV_INFO_P2P_GO_ADDR: - res = _ws_txt_to_mac(infos[i].string, edata->p2p_go_addr); - if (res < 0) - memset(edata->p2p_go_addr, 0x00, OEM_MACADDR_LEN); - if (memcmp(edata->p2p_go_addr, null_mac, OEM_MACADDR_LEN)) - edata->dev_role = WFD_OEM_DEV_ROLE_GC; - break; -#ifdef TIZEN_FEATURE_WIFI_DISPLAY - case WS_DEV_INFO_WFD_DEV_INFO: - /* wfd_dev_info=0x00 0006 015d 022a0032 */ - res = _parsing_wfd_info(infos[i].string+2, &edata->display); - if (res < 0) - memset(&edata->display, 0x00, sizeof(wfd_oem_display_s)); - break; -#endif /* TIZEN_FEATURE_WIFI_DISPLAY */ - - default: - WDP_LOGE("Unknown parameter [%d:%s]", infos[i].index, infos[i].string); - break; - } - if (infos[i].string) - free(infos[i].string); - } - - __WDP_LOG_FUNC_EXIT__; - return edata; -} - -static wfd_oem_conn_data_s *_convert_msg_to_conn_info(char *msg) -{ - __WDP_LOG_FUNC_ENTER__; - int i; - int info_cnt = 0; - ws_string_s infos[WS_CONN_INFO_LIMIT]; - wfd_oem_conn_data_s *edata = NULL; - int dev_pwd_id; - int res = 0; - - if (!msg) { - WDP_LOGE("Invalid parameter"); - return NULL; - } - WDP_LOGD("msg to convert [%s]", msg); - - memset(infos, 0x0, (WS_CONN_INFO_LIMIT) * sizeof(ws_string_s)); - for (i = 0; ws_conn_info_strs[i].index < WS_CONN_INFO_LIMIT; i++) { - res = _extract_value_str(msg, ws_conn_info_strs[i].string, &infos[info_cnt].string); - if (res > 0) { - infos[info_cnt].index = ws_conn_info_strs[i].index; - info_cnt++; - } - } - - if (!info_cnt) { - WDP_LOGE("There is no item converted"); - return NULL; - } - - errno = 0; - edata = (wfd_oem_conn_data_s*) g_try_malloc0(sizeof(wfd_oem_conn_data_s)); - if (!edata) { - WDP_LOGE("Failed to allocate memory for connection information [%s]", strerror(errno)); - return NULL; - } - - for (i = 0; i < info_cnt; i++) { - switch (infos[i].index) { - case WS_CONN_INFO_DEV_PWD_ID: - dev_pwd_id = atoi(infos[i].string); - if (dev_pwd_id == WS_DEV_PASSWD_ID_PUSH_BUTTON) - edata->wps_mode = WFD_OEM_WPS_MODE_PBC; - else if (dev_pwd_id == WS_DEV_PASSWD_ID_REGISTRAR_SPECIFIED) - edata->wps_mode = WFD_OEM_WPS_MODE_DISPLAY; - else if (dev_pwd_id == WS_DEV_PASSWD_ID_USER_SPECIFIED) - edata->wps_mode = WFD_OEM_WPS_MODE_KEYPAD; - else - edata->wps_mode = WFD_OEM_WPS_MODE_NONE; - break; - case WS_CONN_INFO_STATUS: - edata->status = atoi(infos[i].string); - break; - case WS_CONN_INFO_ERROR: - edata->error = atoi(infos[i].string); - break; - default: - WDP_LOGE("Unknown information [%d:%s]", infos[i].index, infos[i].string); - break; - } - if (infos[i].string) - free(infos[i].string); - } - - __WDP_LOG_FUNC_EXIT__; - return edata; -} - -static wfd_oem_invite_data_s *_convert_msg_to_invite_info(char *msg) -{ - __WDP_LOG_FUNC_ENTER__; - int i; - int info_cnt = 0; - ws_string_s infos[WS_INVITE_INFO_LIMIT]; - wfd_oem_invite_data_s *edata = NULL; - int res = 0; - - if (!msg) { - WDP_LOGE("Invalid parameter"); - return NULL; - } - WDP_LOGD("msg to convert [%s]", msg); - - memset(infos, 0x0, (WS_INVITE_INFO_LIMIT) * sizeof(ws_string_s)); - for (i = 0; ws_invite_info_strs[i].index < WS_INVITE_INFO_LIMIT; i++) { - res = _extract_value_str(msg, ws_invite_info_strs[i].string, &infos[info_cnt].string); - if (res > 0) { - infos[info_cnt].index = ws_invite_info_strs[i].index; - info_cnt++; - } - } - - if (!info_cnt) { - WDP_LOGE("There is no item converted"); - return NULL; - } - - errno = 0; - edata = (wfd_oem_invite_data_s*) g_try_malloc0(sizeof(wfd_oem_invite_data_s)); - if (!edata) { - WDP_LOGE("Failed to allocate memory for invite information [%s]", strerror(errno)); - return NULL; - } - - for (i = 0; i < info_cnt; i++) { - switch (infos[i].index) { - case WS_INVITE_INFO_GO_DEV_ADDR: - res = _ws_txt_to_mac(infos[i].string, edata->go_dev_addr); - if (res < 0) - memset(edata->go_dev_addr, 0x00, OEM_MACADDR_LEN); - break; - case WS_INVITE_INFO_BSSID: - res = _ws_txt_to_mac(infos[i].string, edata->bssid); - if (res < 0) - memset(edata->bssid, 0x00, OEM_MACADDR_LEN); - break; - case WS_INVITE_INFO_LISTEN: - edata->listen = atoi(infos[i].string); - break; - case WS_INVITE_INFO_STATUS: - edata->status = atoi(infos[i].string); - break; - default: - WDP_LOGE("Unknown parameter [%d:%s]", infos[i].index, infos[i].string); - break; - } - if (infos[i].string) - free(infos[i].string); - } - - __WDP_LOG_FUNC_EXIT__; - return edata; -} - -static wfd_oem_group_data_s *_convert_msg_to_group_info(char *msg) -{ - __WDP_LOG_FUNC_ENTER__; - int i; - int info_cnt = 0; - ws_string_s infos[WS_GROUP_INFO_LIMIT]; - wfd_oem_group_data_s *edata = NULL; - -#ifdef TIZEN_FEATURE_IP_OVER_EAPOL - unsigned int addr = 0; -#endif /* TIZEN_FEATURE_IP_OVER_EAPOL */ - int res = 0; - if (!msg) { - WDP_LOGE("Invalid parameter"); - return NULL; - } - WDP_LOGD("msg to convert [%s]", msg); - - memset(infos, 0x0, WS_GROUP_INFO_LIMIT * sizeof(ws_string_s)); - for (i = 0; ws_group_info_strs[i].index < WS_GROUP_INFO_LIMIT; i++) { - res = _extract_value_str(msg, ws_group_info_strs[i].string, &infos[info_cnt].string); - if (res > 0) { - infos[info_cnt].index = ws_group_info_strs[i].index; - info_cnt++; - } - } - - if (!info_cnt) { - WDP_LOGE("There is no item converted"); - return NULL; - } - - errno = 0; - edata = (wfd_oem_group_data_s*) g_try_malloc0(sizeof(wfd_oem_group_data_s)); - if (!edata) { - WDP_LOGE("Failed to allocate memory for group information [%s]", strerror(errno)); - return NULL; - } - - for (i = 0; i < info_cnt; i++) { - switch (infos[i].index) { - case WS_GROUP_INFO_SSID: - g_strlcpy(edata->ssid, infos[i].string, OEM_DEV_NAME_LEN + 1); - WDP_LOGD("ssid [%s]", edata->ssid); - break; - case WS_GROUP_INFO_FREQ: - edata->freq = atoi(infos[i].string); - break; - case WS_GROUP_INFO_PASS: - g_strlcpy(edata->pass, infos[i].string, OEM_PASS_PHRASE_LEN + 1); - WDP_LOGD("passphrase [%s]", edata->pass); - break; - case WS_GROUP_INFO_GO_DEV_ADDR: - res = _ws_txt_to_mac(infos[i].string, edata->go_dev_addr); - if (res < 0) - memset(edata->go_dev_addr, 0x00, OEM_MACADDR_LEN); - break; - case WS_GROUP_INFO_PERSISTENT: - edata->is_persistent = TRUE; - WDP_LOGD("Is Persistent : [%s]", edata->is_persistent ? "YES" : "NO"); - break; -#ifdef TIZEN_FEATURE_IP_OVER_EAPOL - case WS_GROUP_INFO_IP_ADDR: - WDP_LOGD("Extracted peer ip = %s", infos[i].string); - res = inet_aton(infos[i].string, (struct in_addr *)&addr); - if (res == 1) - memcpy(&(edata->ip_addr), &addr, sizeof(edata->ip_addr)); - break; - case WS_GROUP_INFO_IP_MASK: - WDP_LOGD("Extracted ip mask= %s", infos[i].string); - res = inet_aton(infos[i].string, (struct in_addr *)&addr); - if (res == 1) - memcpy(&(edata->ip_addr_mask), &addr, sizeof(edata->ip_addr_mask)); - break; - case WS_GROUP_INFO_GO_IP_ADDR: - WDP_LOGD("Extracted peer go ip = %s", infos[i].string); - res = inet_aton(infos[i].string, (struct in_addr *)&addr); - if (res == 1) - memcpy(&(edata->ip_addr_go), &addr, sizeof(edata->ip_addr_go)); - break; -#endif /* TIZEN_FEATURE_IP_OVER_EAPOL */ - default: - WDP_LOGE("Unknown parameter [%d:%s]", infos[i].index, infos[i].string); - break; - } - g_free(infos[i].string); - } - - __WDP_LOG_FUNC_EXIT__; - return edata; -} - -#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY -static int _ws_segment_to_service(char *segment, wfd_oem_new_service_s **service) -{ - wfd_oem_new_service_s *serv_tmp = NULL; - char *ptr = NULL; - char *temp = NULL; - int len = 0; - int i = 0; - - if (!segment || !service) { - WDP_LOGE("Invalid parameter"); - return -1; - } - - ptr = segment; - WDP_LOGD("Segment: %s", segment); - - serv_tmp = (wfd_oem_new_service_s*) g_try_malloc0(sizeof(wfd_oem_new_service_s)); - if (!serv_tmp) { - WDP_LOGE("Failed to allocate memory for service"); - return -1; - } - - serv_tmp->protocol = _ws_hex_to_num(ptr, 2); - serv_tmp->trans_id = _ws_hex_to_num(ptr+2, 2); - serv_tmp->status = _ws_hex_to_num(ptr+4, 2); - ptr += 6; - WDP_LOGD("Protocol[%d], Transaction ID[%d], Status[%d]", serv_tmp->protocol, serv_tmp->trans_id, serv_tmp->status); - - if (serv_tmp->status != 0) { - WDP_LOGE("Service status is not success"); - g_free(serv_tmp); - return -1; - } - - if (serv_tmp->protocol == WFD_OEM_SERVICE_TYPE_BONJOUR) { - WDP_LOGD("===== Bonjour service ====="); - char compr[5] = {0, }; - char query[256] = {0, }; - char rdata[256] = {0, }; - int dns_type = 0; - - while (*ptr != 0 && strncmp(ptr, "c0", 2)) { - len = _ws_hex_to_num(ptr, 2); - ptr += 2; - if (len) { - temp = (char*) g_try_malloc0(len + 2); - if (!temp) { - WDP_LOGE("Failed to allocate memory for temp"); - g_free(serv_tmp); - return -1; - } - temp[0] = '.'; - for (i = 0; i < len; i++) { - temp[i+1] = (char) _ws_hex_to_num(ptr, 2); - ptr += 2; - } - strncat(query, temp, len+1); - g_free(temp); - temp = NULL; - } - } - - if (!strncmp(ptr, "c0", 2)) { - memcpy(compr, ptr, 4); - ptr += 2; - - if (!strncmp(ptr, "27", 2)) { - WDP_LOGD("Segment ended"); - ptr += 2; - } else { - ptr += 2; - dns_type = _ws_hex_to_num(ptr, 4); - ptr += 6; - if (dns_type == 12) { - if (!strncmp(compr, "c011", 4)) - strncat(query, ".local.", 7); - else if (!strncmp(compr, "c00c", 4)) - strncat(query, "._tcp.local.", 12); - else if (!strncmp(compr, "c01c", 4)) - strncat(query, "._udp.local.", 12); - } - } - } - serv_tmp->data.bonjour.query = strdup(query + 1); - while (*ptr != 0 && strncmp(ptr, "c0", 2)) { - len = _ws_hex_to_num(ptr, 2); - ptr += 2; - if (len) { - temp = (char*) g_try_malloc0(len + 2); - if (!temp) { - WDP_LOGE("Failed to allocate memory for temp"); - g_free(serv_tmp); - return -1; - } - temp[0] = '.'; - for (i = 0; i < len; i++) { - temp[i + 1] = (char) _ws_hex_to_num(ptr, 2); - ptr += 2; - } - strncat(rdata, temp, len+1); - g_free(temp); - temp = NULL; - } - } - serv_tmp->data.bonjour.rdata = strdup(rdata + 1); - - WDP_LOGD("Query: %s", serv_tmp->data.bonjour.query); - WDP_LOGD("RData: %s", serv_tmp->data.bonjour.rdata); - } else if (serv_tmp->protocol == WFD_OEM_SERVICE_TYPE_VENDOR) { - WDP_LOGD("===== Vendor specific service ====="); - } else { - WDP_LOGE("Not supported yet. Only bonjour service supproted [%d]", - serv_tmp->protocol); - g_free(serv_tmp); - return -1; - } - - *service = serv_tmp; - - return 0; -} -#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */ - -static int _parsing_event_info(char *ifname, char *msg, wfd_oem_event_s *data) -{ - __WDP_LOG_FUNC_ENTER__; - int i; - int res = 0; - char *info_str = NULL; - - if (!msg || !data) { - WDP_LOGE("Invalid parameter"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - WDP_SECLOGD("Event message [%s]", msg); - - /* parsing event string */ - for (i = 0; ws_event_strs[i].index < WS_EVENT_LIMIT; i++) { - if (!strncmp(ws_event_strs[i].string, msg, - strlen(ws_event_strs[i].string))) - break; - } - - if (i == sizeof(ws_event_strs)) { - WDP_LOGE("Unknown event [%d]", WS_EVENT_LIMIT); - data->event_id = WS_EVENT_LIMIT; - return 1; - } - data->event_id = ws_event_strs[i].index; - WDP_LOGD("Event ID [%d]", data->event_id); - - /* parsing event info */ - info_str = msg + strlen(ws_event_strs[i].string) + 1; - if (!strlen(info_str)) { - WDP_LOGD("Nothing to parse anymore"); - data->edata_type = WFD_OEM_EDATA_TYPE_NONE; - __WDP_LOG_FUNC_EXIT__; - return 0; - } - - switch (data->event_id) { - case WS_EVENT_DEVICE_FOUND: - { - _ws_txt_to_mac(info_str, data->dev_addr); - info_str += OEM_MACSTR_LEN; - - wfd_oem_dev_data_s *edata = NULL; - edata = _convert_msg_to_dev_info(info_str); - if (!edata) { - WDP_LOGE("Failed to convert information string to device data"); - data->edata_type = WFD_OEM_EDATA_TYPE_NONE; - break; - } - - if (edata->dev_role == WFD_OEM_DEV_ROLE_GO) { - memcpy(edata->p2p_intf_addr, data->dev_addr, OEM_MACADDR_LEN); - memcpy(data->dev_addr, edata->p2p_dev_addr, OEM_MACADDR_LEN); - } - data->edata_type = WFD_OEM_EDATA_TYPE_DEVICE; - data->edata = (void*) edata; - - } - break; - case WS_EVENT_PROV_DISC_PBC_REQ: - case WS_EVENT_PROV_DISC_SHOW_PIN: - case WS_EVENT_PROV_DISC_ENTER_PIN: - case WS_EVENT_PROV_DISC_PBC_RESP: - { - _ws_txt_to_mac(info_str, data->dev_addr); - info_str += OEM_MACSTR_LEN; - - if (data->event_id == WS_EVENT_PROV_DISC_PBC_REQ || - data->event_id == WS_EVENT_PROV_DISC_PBC_RESP) { - data->wps_mode = WFD_OEM_WPS_MODE_PBC; - } else if (data->event_id == WS_EVENT_PROV_DISC_ENTER_PIN) { - data->wps_mode = WFD_OEM_WPS_MODE_KEYPAD; - } else if (data->event_id == WS_EVENT_PROV_DISC_SHOW_PIN) { - data->wps_mode = WFD_OEM_WPS_MODE_DISPLAY; - strncpy(data->wps_pin, info_str, OEM_PINSTR_LEN); - data->wps_pin[OEM_PINSTR_LEN] = '\0'; - info_str += OEM_PINSTR_LEN +1; - } - - WDP_LOGD("info string left [%s]", info_str ? info_str : "NULL"); - - data->edata_type = WFD_OEM_EDATA_TYPE_NONE; - - } - break; - case WS_EVENT_DEVICE_LOST: - { - char *temp_mac = NULL; - res = _extract_value_str(info_str, "p2p_dev_addr", &temp_mac); - if (res < 0) { - WDP_LOGE("Failed to extract device address"); - break; - } - _ws_txt_to_mac(temp_mac, data->dev_addr); - if (temp_mac) - g_free(temp_mac); - data->edata_type = WFD_OEM_EDATA_TYPE_NONE; - } - break; - case WS_EVENT_FIND_STOPED: - break; - case WS_EVENT_GO_NEG_REQUEST: - { - _ws_txt_to_mac(info_str, data->dev_addr); - info_str += OEM_MACSTR_LEN; - - if (!strlen(info_str)) { - WDP_LOGD("Nothing to parse anymore"); - data->edata_type = WFD_OEM_EDATA_TYPE_NONE; - break; - } - - wfd_oem_conn_data_s *edata = NULL; - edata = _convert_msg_to_conn_info(info_str); - if (!edata) { - WDP_LOGE("Failed to convert information string to connection data"); - data->edata_type = WFD_OEM_EDATA_TYPE_NONE; - break; - } - data->edata_type = WFD_OEM_EDATA_TYPE_CONN; - data->edata = (void*) edata; - } - break; - case WS_EVENT_PROV_DISC_FAILURE: - case WS_EVENT_WPS_FAIL: /* M_id(msg), error(config_error) */ - break; - case WS_EVENT_GO_NEG_FAILURE: - { - wfd_oem_conn_data_s *edata = NULL; - edata = _convert_msg_to_conn_info(info_str); - if (!edata) { - WDP_LOGE("Failed to convert information string to connection data"); - data->edata_type = WFD_OEM_EDATA_TYPE_NONE; - break; - } - data->edata_type = WFD_OEM_EDATA_TYPE_CONN; - data->edata = (void*) edata; - } - break; - case WS_EVENT_GROUP_FORMATION_FAILURE: /* No incofmation sring */ - case WS_EVENT_GO_NEG_SUCCESS: - case WS_EVENT_WPS_SUCCESS: - case WS_EVENT_GROUP_FORMATION_SUCCESS: - /* No information string */ - data->edata_type = WFD_OEM_EDATA_TYPE_NONE; - break; - case WS_EVENT_WPS_REG_SUCCESS: /* "intf_addr" */ - /* Interface address of peer will come up */ - break; - case WS_EVENT_STA_CONNECTED: /* "intf_addr", dev_addr(dev_addr) */ - case WS_EVENT_STA_DISCONNECTED: - { - /* Interface address of connected peer will come up */ - _ws_txt_to_mac(info_str, data->intf_addr); - - char *temp = NULL; - res = _extract_value_str(info_str, "p2p_dev_addr", &temp); - if (res < 0) { - WDP_LOGE("Failed to extract interface address"); - break; - } - _ws_txt_to_mac(temp, data->dev_addr); - if (temp) - free(temp); -#ifdef TIZEN_FEATURE_IP_OVER_EAPOL - res = _extract_value_str(info_str, "ip_addr", &temp); - if (res > 0 && temp) { - unsigned int addr = 0; - WDP_LOGD("Extracted peer ip = %s", temp); - res = inet_aton(temp, (struct in_addr *)&addr); - if (res == 1) - memcpy(&(data->ip_addr_peer), &addr, sizeof(data->ip_addr_peer)); - } -#endif /* TIZEN_FEATURE_IP_OVER_EAPOL */ - data->edata_type = WFD_OEM_EDATA_TYPE_NONE; - } - break; - case WS_EVENT_INVITATION_RECEIVED: - case WS_EVENT_INVITATION_RESULT: - { - char *peer_addr_str = NULL; - res = _extract_value_str(info_str, "sa", &peer_addr_str); - if (res == 17/*(OEM_MACSTR_LEN-1)*/) { - _ws_txt_to_mac(peer_addr_str, data->dev_addr); - if (peer_addr_str) - g_free(peer_addr_str); - } else if (res < 0) { - WDP_LOGE("Failed to extract source address"); - } else { - WDP_LOGE("Wrong source address"); - g_free(peer_addr_str); - } - - if (!strlen(info_str)) { - WDP_LOGD("Nothing to parse anymore"); - data->edata_type = WFD_OEM_EDATA_TYPE_NONE; - break; - } - - wfd_oem_invite_data_s* edata = NULL; - edata = _convert_msg_to_invite_info(info_str); - if (!edata) { - WDP_LOGE("Failed to convert information string to invite data"); - data->edata_type = WFD_OEM_EDATA_TYPE_NONE; - break; - } - - data->edata_type = WFD_OEM_EDATA_TYPE_INVITE; - data->edata = (void*) edata; - - } - break; - case WS_EVENT_GROUP_STARTED: - case WS_EVENT_GROUP_REMOVED: - { - char *ifname_str = NULL; - res = _extract_word(info_str, &ifname_str); - if (res < 0) { - WDP_LOGE("Failed to extract event param string"); - } else if (res == 0) { - WDP_LOGE("Nothing extracted"); - g_free(ifname_str); - } else { - if (!ifname_str) { - WDP_LOGE("Parsing error(interface name)"); - return -1; - } - strncpy(data->ifname, ifname_str, OEM_IFACE_NAME_LEN); - data->ifname[OEM_IFACE_NAME_LEN] = '\0'; - - info_str += strlen(ifname_str) + 1; - g_free(ifname_str); - } - - char *dev_role_str = NULL; - res = _extract_word(info_str, &dev_role_str); - if (res < 0) { - WDP_LOGE("Failed to extract event param string"); - } else if (res == 0) { - WDP_LOGE("Nothing extracted"); - g_free(dev_role_str); - } else { - if (!dev_role_str) { - WDP_LOGE("Parsing error(device role)"); - return -1; - } - if (!strncmp(dev_role_str, "GO", 2)) - data->dev_role = WFD_OEM_DEV_ROLE_GO; - else if (!strncmp(dev_role_str, "client", 6)) - data->dev_role = WFD_OEM_DEV_ROLE_GC; - else - WDP_LOGE("Unknown device role [%s]", dev_role_str); - - info_str += strlen(dev_role_str) + 1; - g_free(dev_role_str); - } - - if (!strlen(info_str)) { - WDP_LOGD("Nothing to parse anymore"); - data->edata_type = WFD_OEM_EDATA_TYPE_NONE; - break; - } - - wfd_oem_group_data_s* edata = NULL; - edata = _convert_msg_to_group_info(info_str); - if (!edata) { - WDP_LOGE("Failed to convert information string to group data"); - data->edata_type = WFD_OEM_EDATA_TYPE_NONE; - break; - } - - data->edata_type = WFD_OEM_EDATA_TYPE_GROUP; - data->edata = (void*) edata; - - } - break; -#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY - case WS_EVENT_SERV_DISC_RESP: - { - char mac_addr[OEM_MACSTR_LEN] = {0, }; - char *up_indic = NULL; - int len = 0; - int ret = 0; - - _ws_txt_to_mac(info_str, data->dev_addr); - info_str += OEM_MACSTR_LEN; - g_snprintf(mac_addr, OEM_MACSTR_LEN, MACSTR, MAC2STR(data->dev_addr)); - - ret = _extract_word(info_str, &up_indic); - if (ret < 0) - WDP_LOGE("_extract_word is failed"); - - if (up_indic) { - WDP_LOGD("Update indicator: %s", up_indic); - info_str += strlen(up_indic) + 1; - g_free(up_indic); - } - WDP_LOGD("Info string [%s]", info_str); - - char seglen_str[5] = {0, }; - char *segment = NULL; - char *ptr = info_str; - GList *services = NULL; - wfd_oem_new_service_s *new_service = NULL; - int count = 0; - - while (*ptr != '\0') { - _change_str_order(ptr, 4, 2, seglen_str); - len = strtoul(seglen_str, NULL, 16); - if (len == 0) - break; - segment = (char*) g_try_malloc0(len * 2 + 1); - if (!segment) { - WDP_LOGE("Failed to allocate memory for segment"); - return -1; - } - memcpy(segment, ptr+4, len*2); - ptr = ptr + 4 + len*2; - res = _ws_segment_to_service(segment, &new_service); - if (res < 0) { - WDP_LOGE("Failed to convert segment as service instance"); - g_free(segment); - segment = NULL; - continue; - } - services = g_list_append(services, new_service); - count++; - g_free(segment); - segment = NULL; - } - data->edata_type = WFD_OEM_EDATA_TYPE_NEW_SERVICE; - data->dev_role = count; - data->edata = (void*) services; - } - break; -#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */ - - default: - WDP_LOGE("Unknown event"); - break; - } - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -static gboolean ws_event_handler(GIOChannel *source, - GIOCondition condition, - gpointer data) -{ - __WDP_LOG_FUNC_ENTER__; - ws_sock_data_s * sd = (ws_sock_data_s*) data; - char msg[1024] = {0, }; - char *pos = NULL; - char *param = NULL; - wfd_oem_event_s event; - int res = 0; - - if (!g_pd) { - WDP_LOGE("event cannot be handled"); - return FALSE; - } - - if (!sd) { - WDP_LOGE("Invalid parameter"); - /* TODO: if error count is more than 10, disconnect this interface and reset sock data */ - return FALSE; - } - - res = _ws_read_sock(sd->mon_sock, msg, sizeof(msg)); - if (res < 0) { - WDP_LOGE("Failed to read socket. [%d]", sd->mon_sock); - return FALSE; - } - - errno = 0; - memset(&event, 0, sizeof(wfd_oem_event_s)); - - if (!strncmp(msg, "IFNAME", 6)) { - pos = strchr(msg, ' '); - param = pos+4; - } else { - param = &msg[3]; - } - - res = _parsing_event_info(sd->ifname, param, &event); - if (res < 0) { - WDP_LOGE("Failed to parse event string"); - return FALSE; - } - - if (res == 1) - WDP_LOGD("This means event->event_data is NULL"); - - /* Converting WS event to OEM event */ - switch (event.event_id) { - case WS_EVENT_DEVICE_FOUND: - event.event_id = WFD_OEM_EVENT_PEER_FOUND; - if (g_pd->callback && g_pd->callback->peer_found_cb) - g_pd->callback->peer_found_cb(&event); - break; - case WS_EVENT_DEVICE_LOST: - event.event_id = WFD_OEM_EVENT_PEER_DISAPPEARED; - if (g_pd->callback && g_pd->callback->peer_disappeared_cb) - g_pd->callback->peer_disappeared_cb(&event); - break; - case WS_EVENT_FIND_STOPED: - event.event_id = WFD_OEM_EVENT_DISCOVERY_FINISHED; - if (g_pd->callback && g_pd->callback->discovery_finished_cb) - g_pd->callback->discovery_finished_cb(&event); - break; - case WS_EVENT_PROV_DISC_PBC_REQ: - event.event_id = WFD_OEM_EVENT_PROV_DISC_REQ; - if (g_pd->callback && g_pd->callback->prov_disc_req_cb) - g_pd->callback->prov_disc_req_cb(&event); - break; - case WS_EVENT_PROV_DISC_PBC_RESP: - if (!memcmp(event.dev_addr, g_pd_out, OEM_MACADDR_LEN)) { - event.event_id = WFD_OEM_EVENT_PROV_DISC_RESP; - memset(g_pd_out, 0x0, OEM_MACADDR_LEN); - } else { - WDP_LOGE("Invalid peer mac address[" MACSTR "]", MAC2STR(event.dev_addr)); - goto done; - } - if (g_pd->callback && g_pd->callback->prov_disc_resp_cb) - g_pd->callback->prov_disc_resp_cb(&event); - break; - case WS_EVENT_PROV_DISC_SHOW_PIN: - case WS_EVENT_PROV_DISC_ENTER_PIN: - if (!memcmp(event.dev_addr, g_pd_out, OEM_MACADDR_LEN)) { - event.event_id = WFD_OEM_EVENT_PROV_DISC_RESP; - memset(g_pd_out, 0x0, OEM_MACADDR_LEN); - WDP_LOGD("Peer mac address verified"); - if (g_pd->callback && g_pd->callback->prov_disc_resp_cb) - g_pd->callback->prov_disc_resp_cb(&event); - } else if (!memcmp(g_pd_out, null_mac, OEM_MACADDR_LEN)) { - event.event_id = WFD_OEM_EVENT_PROV_DISC_REQ; - WDP_LOGD(" PD request from peer[" MACSTR "]", MAC2STR(event.dev_addr)); - if (g_pd->callback && g_pd->callback->prov_disc_req_cb) - g_pd->callback->prov_disc_req_cb(&event); - } else { - WDP_LOGE("Invalid peer mac address[" MACSTR "]", MAC2STR(event.dev_addr)); - goto done; - } - - break; - case WS_EVENT_PROV_DISC_FAILURE: - event.event_id = WFD_OEM_EVENT_PROV_DISC_FAIL; - if (!memcmp(event.dev_addr, g_pd_out, OEM_MACADDR_LEN)) { - memset(g_pd_out, 0x0, OEM_MACADDR_LEN); - WDP_LOGD("Peer mac address verified, but PD failed"); - } - if (g_pd->callback && g_pd->callback->prov_disc_fail_cb) - g_pd->callback->prov_disc_fail_cb(&event); - break; - case WS_EVENT_GO_NEG_REQUEST: - event.event_id = WFD_OEM_EVENT_GO_NEG_REQ; - if (g_pd->callback && g_pd->callback->go_neg_req_cb) - g_pd->callback->go_neg_req_cb(&event); - break; - case WS_EVENT_GO_NEG_FAILURE: - event.event_id = WFD_OEM_EVENT_GO_NEG_FAIL; - if (g_pd->callback && g_pd->callback->go_neg_fail_cb) - g_pd->callback->go_neg_fail_cb(&event); - break; - case WS_EVENT_GO_NEG_SUCCESS: - event.event_id = WFD_OEM_EVENT_GO_NEG_DONE; - if (g_pd->callback && g_pd->callback->go_neg_done_cb) - g_pd->callback->go_neg_done_cb(&event); - break; - case WS_EVENT_WPS_FAIL: - event.event_id = WFD_OEM_EVENT_WPS_FAIL; - if (g_pd->callback && g_pd->callback->wps_fail_cb) - g_pd->callback->wps_fail_cb(&event); - break; - case WS_EVENT_GROUP_FORMATION_FAILURE: - event.event_id = WFD_OEM_EVENT_WPS_FAIL; - if (g_pd->callback && g_pd->callback->group_formation_failure_cb) - g_pd->callback->group_formation_failure_cb(&event); - break; - case WS_EVENT_WPS_SUCCESS: - case WS_EVENT_WPS_REG_SUCCESS: - case WS_EVENT_GROUP_FORMATION_SUCCESS: - event.event_id = WFD_OEM_EVENT_WPS_DONE; - /* TODO: connect to supplicant via group interface */ - if (g_pd->callback && g_pd->callback->wps_done_cb) - g_pd->callback->wps_done_cb(&event); - break; - case WS_EVENT_STA_CONNECTED: - event.event_id = WFD_OEM_EVENT_STA_CONNECTED; - if (g_pd->callback && g_pd->callback->sta_connected_cb) - g_pd->callback->sta_connected_cb(&event); - break; - case WS_EVENT_GROUP_STARTED: - event.event_id = WFD_OEM_EVENT_GROUP_CREATED; - if (!g_strcmp0(GROUP_IFACE_NAME, COMMON_IFACE_NAME)) { - g_pd->group = g_pd->common; - } else { - res = _connect_to_supplicant(GROUP_IFACE_NAME, - &g_pd->group); - if (res < 0) { - WDP_LOGE("Failed to connect to group interface of supplicant"); - /* goto done; */ - } - } - if (g_pd->callback && g_pd->callback->group_created_cb) - g_pd->callback->group_created_cb(&event); - break; - case WS_EVENT_GROUP_REMOVED: - event.event_id = WFD_OEM_EVENT_GROUP_DESTROYED; - if (!g_strcmp0(GROUP_IFACE_NAME, COMMON_IFACE_NAME)) { - g_pd->group = NULL; - _ws_flush(); - } else { - if (g_pd->group) { - res = _disconnect_from_supplicant(GROUP_IFACE_NAME, - g_pd->group); - if (res < 0) { - WDP_LOGE("Failed to disconnect from group interface of supplicant"); - /* goto done; */ - } - g_pd->group = NULL; - _ws_flush(); - } - } - if (g_pd->callback && g_pd->callback->group_destroyed_cb) - g_pd->callback->group_destroyed_cb(&event); - break; - case WS_EVENT_INVITATION_RECEIVED: - event.event_id = WFD_OEM_EVENT_INVITATION_REQ; - if (g_pd->callback && g_pd->callback->invitation_req_cb) - g_pd->callback->invitation_req_cb(&event); - break; - case WS_EVENT_INVITATION_RESULT: - event.event_id = WFD_OEM_EVENT_INVITATION_RES; - if (g_pd->callback && g_pd->callback->invitation_resp_cb) - g_pd->callback->invitation_resp_cb(&event); - break; - case WS_EVENT_STA_DISCONNECTED: - event.event_id = WFD_OEM_EVENT_STA_DISCONNECTED; - if (g_pd->callback && g_pd->callback->sta_disconnected_cb) - g_pd->callback->sta_disconnected_cb(&event); - break; - case WS_EVENT_TERMINATING: - event.event_id = WFD_OEM_EVENT_DEACTIVATED; - if (g_pd->callback && g_pd->callback->deactivated_cb) - g_pd->callback->deactivated_cb(&event); - break; -#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY - case WS_EVENT_SERV_DISC_RESP: - event.event_id = WFD_OEM_EVENT_SERV_DISC_RESP; - if (g_pd->callback && g_pd->callback->serv_disc_resp_cb) - g_pd->callback->serv_disc_resp_cb(&event); - break; -#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */ - default: - WDP_LOGD("Unknown event [%d]", event.event_id); - goto done; - break; - } - -done: - if (event.edata) { -#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY - if (event.edata_type == WFD_OEM_EDATA_TYPE_NEW_SERVICE) - g_list_free((GList*) event.edata); - else -#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */ - g_free(event.edata); - } - - __WDP_LOG_FUNC_EXIT__; - return TRUE; -} - -static int _ws_reset_plugin(ws_plugin_data_s *pd) -{ - __WDP_LOG_FUNC_ENTER__; - - if (!pd) { - WDP_LOGE("Invalid parameter"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - if (pd->activated) - ws_deactivate(g_pd->concurrent); - - g_free(pd); - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - - -static int __ws_check_net_interface(char* if_name) -{ - struct ifreq ifr; - int fd; - - if (if_name == NULL) { - WDP_LOGE("Invalid param"); - return -1; - } - - fd = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0); - if (fd < 0) { - WDP_LOGE("socket create error: %d", fd); - return -2; - } - - memset(&ifr, 0, sizeof(ifr)); - g_strlcpy(ifr.ifr_name, if_name, sizeof(ifr.ifr_name) + 1); - - if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) { - close(fd); - WDP_LOGE("ioctl error: SIOCGIFFLAGS: %s", strerror(errno)); /* interface is not found.. */ - return -3; - } - - close(fd); - - if (ifr.ifr_flags & IFF_UP) { - WDP_LOGD("%s interface is up", if_name); - return 1; - } else if (!(ifr.ifr_flags & IFF_UP)) { - WDP_LOGD("%s interface is down", if_name); - return 0; - } - return 0; -} - -int ws_init(wfd_oem_event_cbs_s *event_cbs) -{ - __WDP_LOG_FUNC_ENTER__; - - if (g_pd) - _ws_reset_plugin(g_pd); - - errno = 0; - g_pd = (ws_plugin_data_s*) g_try_malloc0(sizeof(ws_plugin_data_s)); - if (!g_pd) { - WDP_LOGE("Failed to allocate memory for plugin data. [%s]", strerror(errno)); - return -1; - } - - g_pd->callback = event_cbs; - g_pd->initialized = TRUE; - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -int ws_deinit(void) -{ - __WDP_LOG_FUNC_ENTER__; - - if (g_pd) { - _ws_reset_plugin(g_pd); - g_pd = NULL; - } - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -gboolean _ws_util_interface_up(const char *ifname) -{ - int fd; - struct ifreq ifr; - - fd = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0); - if (fd < 0) - return FALSE; - - memset(&ifr, 0, sizeof(ifr)); - g_strlcpy((char *)ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); - - if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) { - close(fd); - return FALSE; - } - - ifr.ifr_flags |= (IFF_UP | IFF_DYNAMIC); - if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) { - close(fd); - return FALSE; - } - - close(fd); - - WDP_LOGI("Successfully activated [%s] interface", ifname); - return TRUE; -} - -gboolean _ws_util_interface_down(const char *ifname) -{ - int fd; - struct ifreq ifr; - - fd = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0); - if (fd < 0) - return FALSE; - - memset(&ifr, 0, sizeof(ifr)); - g_strlcpy((char *)ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); - - if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) { - close(fd); - return FALSE; - } - - ifr.ifr_flags = (ifr.ifr_flags & ~IFF_UP) | IFF_DYNAMIC; - if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) { - close(fd); - return FALSE; - } - - close(fd); - - WDP_LOGI("Successfully de-activated [%s] interface", ifname); - return TRUE; -} - -static int __ws_p2p_firmware_start(void) -{ - gboolean rv = FALSE; - const char *path = "/usr/bin/wlan.sh"; - char *const args[] = { "/usr/bin/wlan.sh", "p2p", NULL }; - char *const envs[] = { NULL }; - - rv = _ws_util_execute_file(path, args, envs); - if (rv != TRUE) - return -1; - - rv = _ws_util_interface_up(COMMON_IFACE_NAME); - if (rv != TRUE) - return -1; - - WDP_LOGI("Successfully loaded p2p device driver"); - return 0; -} - -static int __ws_p2p_firmware_stop(void) -{ - gboolean rv = FALSE; - const char *path = "/usr/bin/wlan.sh"; - char *const args[] = { "/usr/bin/wlan.sh", "stop", NULL }; - char *const envs[] = { NULL }; - - rv = _ws_util_interface_down(COMMON_IFACE_NAME); - if (rv != TRUE) - return -1; - - rv = _ws_util_execute_file(path, args, envs); - if (rv < 0) - return -1; - - WDP_LOGI("Successfully removed p2p device driver"); - return 0; -} - -static int __ws_p2p_supplicant_start(void) -{ - gboolean rv = FALSE; - const char *path = "/usr/sbin/p2p_supp.sh"; - char *const args[] = { "/usr/sbin/p2p_supp.sh", "start", NULL }; - char *const envs[] = { NULL }; - - rv = _ws_util_execute_file(path, args, envs); - - if (rv != TRUE) { - WDP_LOGE("Failed to start p2p_supp.sh"); - return -1; - } - - WDP_LOGI("Successfully started p2p_supp.sh"); - return 0; -} - -static int __ws_p2p_supplicant_stop(void) -{ - gboolean rv = FALSE; - const char *path = "/usr/sbin/p2p_supp.sh"; - char *const args[] = { "/usr/sbin/p2p_supp.sh", "stop", NULL }; - char *const envs[] = { NULL }; - - rv = _ws_util_execute_file(path, args, envs); - - if (rv != TRUE) { - WDP_LOGE("Failed to stop p2p_supp.sh"); - return -1; - } - - WDP_LOGI("Successfully stopped p2p_supp.sh"); - return 0; -} - -#if 0 -static int __ws_p2p_on(void) -{ - DBusError error; - DBusMessage *reply = NULL; - DBusMessage *message = NULL; - DBusConnection *connection = NULL; - - connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL); - if (connection == NULL) { - WDP_LOGE("Failed to get system bus"); - return -EIO; - } - - message = dbus_message_new_method_call(NETCONFIG_SERVICE, - NETCONFIG_WIFI_PATH, NETCONFIG_WIFI_INTERFACE, "LoadP2pDriver"); - if (message == NULL) { - WDP_LOGE("Failed DBus method call"); - dbus_connection_unref(connection); - return -EIO; - } - - dbus_error_init(&error); - - reply = dbus_connection_send_with_reply_and_block(connection, message, - NETCONFIG_DBUS_REPLY_TIMEOUT, &error); - if (dbus_error_is_set(&error) == TRUE) { - if (NULL != strstr(error.message, ".AlreadyExists")) { - /* p2p already enabled */ - } else { - WDP_LOGE("dbus_connection_send_with_reply_and_block() failed. " - "DBus error [%s: %s]", error.name, error.message); - - dbus_error_free(&error); - } - - dbus_error_free(&error); - } - - if (reply != NULL) - dbus_message_unref(reply); - - dbus_message_unref(message); - dbus_connection_unref(connection); - - return 0; -} - -static int __ws_p2p_off(void) -{ - DBusError error; - DBusMessage *reply = NULL; - DBusMessage *message = NULL; - DBusConnection *connection = NULL; - - connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL); - if (connection == NULL) { - WDP_LOGE("Failed to get system bus"); - return -EIO; - } - - message = dbus_message_new_method_call(NETCONFIG_SERVICE, - NETCONFIG_WIFI_PATH, NETCONFIG_WIFI_INTERFACE, "RemoveP2pDriver"); - if (message == NULL) { - WDP_LOGE("Failed DBus method call"); - dbus_connection_unref(connection); - return -EIO; - } - - dbus_error_init(&error); - - reply = dbus_connection_send_with_reply_and_block(connection, message, - NETCONFIG_DBUS_REPLY_TIMEOUT, &error); - if (dbus_error_is_set(&error) == TRUE) { - if (NULL != strstr(error.message, ".AlreadyExists")) { - /* p2p already disabled */ - } else { - WDP_LOGE("dbus_connection_send_with_reply_and_block() failed. " - "DBus error [%s: %s]", error.name, error.message); - - dbus_error_free(&error); - } - - dbus_error_free(&error); - } - - if (reply != NULL) - dbus_message_unref(reply); - - dbus_message_unref(message); - dbus_connection_unref(connection); - - return 0; -} -#endif -static int _ws_update_local_dev_addr_from_file() -{ - __WDP_LOG_FUNC_ENTER__; - FILE *fd = NULL; - const char *file_path = DEFAULT_MAC_FILE_PATH; - char local_mac[OEM_MACSTR_LEN] = {0, }; - char *ptr = NULL; - int res = 0; - - errno = 0; - fd = fopen(file_path, "r"); - if (!fd) { - WDP_LOGE("Failed to open MAC info file [%s] (%s)", file_path, strerror(errno)); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - errno = 0; - ptr = fgets(local_mac, OEM_MACSTR_LEN, fd); - if (!ptr) { - WDP_LOGE("Failed to read file or no data read(%s)", strerror(errno)); - fclose(fd); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - WDP_SECLOGD("Local MAC address [%s]", ptr); - - res = _ws_txt_to_mac(local_mac, g_pd->local_dev_addr); - if (res < 0) { - WDP_LOGE("Failed to convert text to MAC address"); - fclose(fd); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - g_pd->local_dev_addr[0] |= 0x2; - WDP_LOGD("Local Device MAC address [" MACSECSTR "]", MAC2SECSTR(g_pd->local_dev_addr)); - - fclose(fd); - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -static int _ws_update_local_dev_addr() -{ - int res = 0; - char reply[96] = {0, }; - char *mac_str = NULL; - - res = _ws_send_cmd(g_pd->common->ctrl_sock, "status", reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant"); - goto failed; - } - - res = _extract_value_str(reply, "p2p_device_address", &mac_str); - if (res < 0) { - WDP_LOGE("Failed to parsing p2p_device_address"); - goto failed; - } - - res = _ws_txt_to_mac(mac_str, g_pd->local_dev_addr); - if (res < 0) { - WDP_LOGE("Failed to convert MAC string to address"); - free(mac_str); - goto failed; - } - - g_free(mac_str); - - return 0; - -failed: - res = _ws_update_local_dev_addr_from_file(); - if (res < 0) { - WDP_LOGE("Failed to update local device address from file"); - return -1; - } - - return 1; -} - -#ifdef TIZEN_FEATURE_IP_OVER_EAPOL -int _ws_set_default_eapol_over_ip() -{ - __WDP_LOG_FUNC_ENTER__; - - ws_sock_data_s *sock = g_pd->common; - char cmd[80] = {0, }; - char reply[1024] = {0,}; - int res; - - if (!sock) { - WDP_LOGE("Socket is NULL"); - return -1; - } - - g_snprintf(cmd, sizeof(cmd), WS_CMD_SET "ip_addr_go %s", - DEFAULT_IP_GO); - - res = _ws_send_cmd(sock->ctrl_sock, cmd, (char*) reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - if (strstr(reply, "FAIL")) { - WDP_LOGE("Failed to set go intent"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - g_snprintf(cmd, sizeof(cmd), WS_CMD_SET "ip_addr_mask %s", - DEFAULT_IP_MASK); - - res = _ws_send_cmd(sock->ctrl_sock, cmd, (char*) reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - if (strstr(reply, "FAIL")) { - WDP_LOGE("Failed to set go intent"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - g_snprintf(cmd, sizeof(cmd), WS_CMD_SET "ip_addr_start %s", - DEFAULT_IP_START); - - res = _ws_send_cmd(sock->ctrl_sock, cmd, (char*) reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - if (strstr(reply, "FAIL")) { - WDP_LOGE("Failed to set go intent"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - g_snprintf(cmd, sizeof(cmd), WS_CMD_SET "ip_addr_end %s", - DEFAULT_IP_END); - - res = _ws_send_cmd(sock->ctrl_sock, cmd, (char*) reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - if (strstr(reply, "FAIL")) { - WDP_LOGE("Failed to set go intent"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - WDP_LOGD("Succeeded to set default EAPol over IP"); - - __WDP_LOG_FUNC_EXIT__; - return 0; -} -#endif /* TIZEN_FEATURE_IP_OVER_EAPOL */ - -int ws_activate(int concurrent) -{ - __WDP_LOG_FUNC_ENTER__; - int res = 0; - int retry_count = 0; - - while (retry_count < 10) { - /* load wlan driver */ - res = __ws_p2p_firmware_start(); - if (res < 0) { - WDP_LOGE("Failed to load driver [ret=%d]", res); - return -1; - } - WDP_LOGI("P2P firmware started with error %d", res); - - if (__ws_check_net_interface(COMMON_IFACE_NAME) < 0) { - usleep(150000); /* wait for 150ms */ - retry_count++; - WDP_LOGE("interface is not up: retry, %d", retry_count); - } else { - break; - } - } - - if (retry_count >= 10) { - WDP_LOGE("Driver loading is failed", res); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - if (retry_count > 0) { - /* Give driver marginal time to config net */ - WDP_LOGE("Driver loading is done. Wait marginal time for driver"); - sleep(1); /* 1s */ - } - - g_pd->concurrent = concurrent; - - - /* load wpa_supplicant */ - res = __ws_p2p_supplicant_start(); - if (res == -1) { - WDP_LOGE("Failed to start p2p_supplicant [%d: %s]", res, strerror(errno)); - res = __ws_p2p_firmware_stop(); - WDP_LOGI("P2P firmware stopped with error %d", res); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - res = _connect_to_supplicant(COMMON_IFACE_NAME, &g_pd->common); - if (res < 0) { - res = __ws_p2p_supplicant_stop(); - WDP_LOGI("[/usr/sbin/p2p_supp.sh stop] returns %d", res); - res = __ws_p2p_firmware_stop(); - WDP_LOGI("P2P firmware stopped with error %d", res); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - g_pd->activated = TRUE; - - _ws_update_local_dev_addr(); -#ifdef TIZEN_FEATURE_IP_OVER_EAPOL - _ws_set_default_eapol_over_ip(); -#endif /* TIZEN_FEATURE_IP_OVER_EAPOL */ - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -int ws_deactivate(int concurrent) -{ - __WDP_LOG_FUNC_ENTER__; - char cmd[32] = {0, }; - char reply[1024] = {0,}; - int res = 0; - - if (!g_pd->activated) { - WDP_LOGE("Wi-Fi Direct is not activated"); - return -1; - } - - ws_stop_scan(); - - g_pd->concurrent = concurrent; - - if (g_strcmp0(GROUP_IFACE_NAME, COMMON_IFACE_NAME)) { - if (g_pd->group) { - _disconnect_from_supplicant(GROUP_IFACE_NAME, - g_pd->group); - g_pd->group = NULL; - } - } - - /* terminate wpasupplicant */ - snprintf(cmd, sizeof(cmd), WS_CMD_TERMINATE); - res = _ws_send_cmd(g_pd->common->ctrl_sock, cmd, reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant"); - res = __ws_p2p_supplicant_stop(); - WDP_LOGI("[/usr/sbin/p2p_supp.sh stop] returns %d", res); - goto done; - } - - if (!strncmp(reply, "FAIL", 4)) { - WDP_LOGE("Failed to terminate wpa_supplicant"); - res = __ws_p2p_supplicant_stop(); - WDP_LOGI("[/usr/sbin/p2p_supp.sh stop] returns %d", res); - goto done; - } - - res = _disconnect_from_supplicant(COMMON_IFACE_NAME, g_pd->common); - if (res < 0) { - WDP_LOGE("Failed to disconnect common interface(%s) from supplicant. ", - COMMON_IFACE_NAME); - } - - res = __ws_p2p_supplicant_stop(); - WDP_LOGI("[/usr/sbin/p2p_supp.sh stop] returns %d", res); - -done: - res = __ws_p2p_firmware_stop(); - WDP_LOGI("P2P firmware stopped with error %d", res); - g_pd->activated = FALSE; - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -static gboolean _retry_start_scan(gpointer data) -{ - ws_sock_data_s *sock = g_pd->common; - char reply[1024] = {0, }; - static int retry_cnt = 0; - int res = 0; - char *cmd = (char *)data; - - if (NULL == sock || NULL == cmd) { - WDP_LOGE("Data is NULL, Retry Scan Failed !!!"); - goto done; - } - - if (WS_SCAN_RETRY_COUNT == retry_cnt) { - WDP_LOGE("Maximum Retry Reached. Aborting Scan."); - goto done; - } - - res = _ws_send_cmd(sock->ctrl_sock, cmd, reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant"); - goto done; - } - - if (strstr(reply, "FAIL")) { - WDP_LOGE("Retry Scan Failed, Retry after 100ms..."); - retry_cnt++; - return TRUE; - } - - WDP_LOGD("Retry Scan Succeeded."); - -done: - retry_cnt = 0; - if (NULL != cmd) { - free(cmd); - cmd = NULL; - } - return FALSE; -} - -int ws_start_scan(wfd_oem_scan_param_s *param) -{ - __WDP_LOG_FUNC_ENTER__; - ws_sock_data_s *sock = g_pd->common; - char cmd[40] = {0, }; - char reply[1024] = {0, }; - char time_str[4] = {0, }; - char type_str[20] = {0, }; - int res = 0; - char *retry_cmd = NULL; - - if (!param) { - WDP_LOGE("Invalid parameter"); - return -1; - } - - if (!sock) { - WDP_LOGE("Socket is NULL"); - return -1; - } - - if (param->refresh) - _ws_flush(); - - if (param->scan_time) - g_snprintf(time_str, 4, " %d", param->scan_time); - - if (param->scan_type == WFD_OEM_SCAN_TYPE_SOCIAL) - g_snprintf(type_str, 20, " type=social"); - else if (param->scan_type == WFD_OEM_SCAN_TYPE_SPECIFIC && - param->freq > 0) - g_snprintf(type_str, 20, " freq=%d", param->freq); - else if (param->scan_type == WFD_OEM_SCAN_TYPE_CHANNEL1) - g_snprintf(type_str, 20, " type=specific1"); - else if (param->scan_type == WFD_OEM_SCAN_TYPE_CHANNEL6) - g_snprintf(type_str, 20, " type=specific6"); - else if (param->scan_type == WFD_OEM_SCAN_TYPE_CHANNEL11) - g_snprintf(type_str, 20, " type=specific11"); - else if (param->scan_type == WFD_OEM_SCAN_TYPE_GO_FREQ) - g_snprintf(type_str, 20, " type=frequency"); - - if (param->scan_mode == WFD_OEM_SCAN_MODE_ACTIVE) - g_snprintf(cmd, sizeof(cmd), WS_CMD_P2P_FIND "%s%s", - (param->scan_time > 0) ? time_str : "", - (param->scan_type) ? type_str : ""); - else - g_snprintf(cmd, sizeof(cmd), WS_CMD_P2P_LISTEN); - - res = _ws_send_cmd(sock->ctrl_sock, cmd, reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - if (strstr(reply, "FAIL")) { - WDP_LOGE("Failed to start scan, Retry"); - retry_cmd = strdup(cmd); - /* Add Timeout of 100ms for retry SCAN */ - g_timeout_add(100, _retry_start_scan, (gpointer) retry_cmd); - __WDP_LOG_FUNC_EXIT__; - return 0; - } - WDP_LOGD("Succeeded to start scan"); - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -int ws_stop_scan() -{ - __WDP_LOG_FUNC_ENTER__; - ws_sock_data_s *sock = g_pd->common; - char reply[1024] = {0, }; - int res = 0; - - if (!sock) { - WDP_LOGE("Socket is NULL"); - return -1; - } - - res = _ws_send_cmd(sock->ctrl_sock, WS_CMD_P2P_STOP_FIND, reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - if (strstr(reply, "FAIL")) { - WDP_LOGE("Failed to stop scan"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - WDP_LOGD("Succeeded to stop scan"); - - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -int ws_get_visibility(int *visibility) -{ - __WDP_LOG_FUNC_ENTER__; - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -int ws_set_visibility(int visibility) -{ - __WDP_LOG_FUNC_ENTER__; - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -int ws_get_scan_result(GList **peers, int *peer_count) -{ - __WDP_LOG_FUNC_ENTER__; - ws_sock_data_s *sock = g_pd->common; - char cmd[32] = {0, }; - char reply[1024] = {0,}; - wfd_oem_device_s *peer = NULL; - int res = 0; - - if (!peers || !peer_count) { - WDP_LOGE("Invalid parameter"); - return -1; - } - - if (!sock) { - WDP_LOGE("Socket is NULL"); - return -1; - } - - g_snprintf(cmd, sizeof(cmd), WS_CMD_P2P_PEER_FIRST); - res = _ws_send_cmd(sock->ctrl_sock, cmd, reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - if (strstr(reply, "FAIL")) { - WDP_LOGE("Failed to get first peer info"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - WDP_LOGD("Succeeded to get first peer info"); - - peer = (wfd_oem_device_s *) g_try_malloc0(sizeof(wfd_oem_device_s)); - if (!peer) { - WDP_LOGF("Failed to allocate memory for peer."); - return -1; - } - - res = _parsing_peer_info(reply, peer); - if (res < 0) { - WDP_LOGE("Failed to parsing peer info"); - g_free(peer); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - *peers = g_list_prepend(*peers, peer); - - do { - g_snprintf(cmd, sizeof(cmd), WS_CMD_P2P_PEER_NEXT MACSTR, MAC2STR(peer->dev_addr)); - res = _ws_send_cmd(sock->ctrl_sock, cmd, reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant"); - break; - } - - if (strstr(reply, "FAIL")) { - WDP_LOGE("Failed to get first peer info"); - break; - } - WDP_LOGD("Succeeded to get first peer info"); - - peer = (wfd_oem_device_s *) g_try_malloc0(sizeof(wfd_oem_device_s)); - if (!peer) { - WDP_LOGF("Failed to allocate memory for peer"); - break; - } - - res = _parsing_peer_info(reply, peer); - if (res < 0) { - WDP_LOGE("Failed to parsing peer info"); - g_free(peer); - break; - } - - *peers = g_list_prepend(*peers, peer); - } while (1); - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -int ws_get_peer_info(unsigned char *peer_addr, wfd_oem_device_s **peer) -{ - __WDP_LOG_FUNC_ENTER__; - ws_sock_data_s *sock = g_pd->common; - char cmd[32] = {0, }; - char reply[1024] = {0,}; - wfd_oem_device_s *ws_dev = NULL; - int res = 0; - - if (!peer_addr || !peer) { - WDP_LOGE("Invalid parameter"); - return -1; - } - - if (!sock) { - WDP_LOGE("Socket is NULL"); - return -1; - } - - g_snprintf(cmd, sizeof(cmd), WS_CMD_P2P_PEER MACSTR, MAC2STR(peer_addr)); - res = _ws_send_cmd(sock->ctrl_sock, cmd, reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - if (strstr(reply, "FAIL")) { - WDP_LOGD("Failed to get peer info [" MACSECSTR "]", MAC2SECSTR(peer_addr)); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - WDP_LOGD("Succeeded to get peer info [" MACSECSTR "]", MAC2SECSTR(peer_addr)); - - ws_dev = (wfd_oem_device_s*) g_try_malloc0(sizeof(wfd_oem_device_s)); - if (!ws_dev) { - WDP_LOGF("Failed to allocate memory for device"); - return -1; - } - - res = _parsing_peer_info(reply, ws_dev); - if (res < 0) { - WDP_LOGE("Failed to parsing peer info"); - g_free(ws_dev); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - *peer = ws_dev; - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -int ws_prov_disc_req(unsigned char *peer_addr, wfd_oem_wps_mode_e wps_mode, int join) -{ - __WDP_LOG_FUNC_ENTER__; - ws_sock_data_s *sock = g_pd->common; - char cmd[64] = {0, }; - char reply[1024] = {0,}; - int res; - - if (!sock) { - WDP_LOGE("Socket is NULL"); - return -1; - } - - g_snprintf(cmd, sizeof(cmd), WS_CMD_P2P_PROV_DISC MACSTR "%s", - MAC2STR(peer_addr), _ws_wps_to_txt(wps_mode)); - - if (join) - strncat(cmd, WS_STR_JOIN, 5); - - res = _ws_send_cmd(sock->ctrl_sock, cmd, reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - if (strstr(reply, "FAIL")) { - WDP_LOGD("Failed to send provision discovery to peer[" MACSECSTR "]", - MAC2SECSTR(peer_addr)); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - WDP_LOGD("Succeeded to send provision discovery to peer[" MACSECSTR "]", - MAC2SECSTR(peer_addr)); - memcpy(g_pd_out, peer_addr, OEM_MACADDR_LEN); - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -int ws_connect(unsigned char *peer_addr, wfd_oem_conn_param_s *param) -{ - __WDP_LOG_FUNC_ENTER__; - ws_sock_data_s *sock = g_pd->common; - char cmd[64] = {0, }; - char freq_str[11] = {0, }; - char reply[1024] = {0, }; - int res = 0; - - if (!peer_addr) { - WDP_LOGE("Invalid parameter"); - return -1; - } - - if (!sock) { - WDP_LOGE("Socket is NULL"); - return -1; - } - - if (param->wps_pin[0] != '\0') - g_snprintf(cmd, sizeof(cmd), WS_CMD_P2P_CONNECT MACSTR " %s%s" , - MAC2STR(peer_addr), param->wps_pin, - _ws_wps_to_txt(param->wps_mode)); - else - g_snprintf(cmd, sizeof(cmd), WS_CMD_P2P_CONNECT MACSTR "%s", - MAC2STR(peer_addr), - _ws_wps_to_txt(param->wps_mode)); - - if (param->conn_flags & WFD_OEM_CONN_TYPE_JOIN) - strncat(cmd, WS_STR_JOIN, 5); - else if (param->conn_flags & WFD_OEM_CONN_TYPE_AUTH) - strncat(cmd, WS_STR_AUTH, 5); - - if (param->conn_flags & WFD_OEM_CONN_TYPE_PERSISTENT) - strncat(cmd, WS_STR_PERSISTENT, 11); - - if (param->freq > 0) { - g_snprintf(freq_str, sizeof(freq_str), WS_STR_FREQ "%d", param->freq); - strncat(cmd, freq_str, sizeof(freq_str)); - } - - WDP_LOGI("Connection command [%s]", cmd); - - res = _ws_send_cmd(sock->ctrl_sock, cmd, reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - if (strstr(reply, "FAIL")) { - WDP_LOGD("Failed to connect with peer[" MACSECSTR "]", MAC2SECSTR(peer_addr)); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - WDP_LOGD("Succeeded to send connection command to peer[" MACSECSTR "]", MAC2SECSTR(peer_addr)); - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -int ws_disconnect(unsigned char *peer_addr, int is_iface_addr) -{ - __WDP_LOG_FUNC_ENTER__; - ws_sock_data_s *sock = g_pd->common; - char cmd[48] = {0, }; - char reply[1024] = {0,}; - int res; - - if (!peer_addr) { - WDP_LOGE("Invalid parameter"); - return -1; - } - - if (!sock) { - WDP_LOGE("Socket is NULL"); - return -1; - } - - 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)); - - res = _ws_send_cmd(sock->ctrl_sock, cmd, reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - if (strstr(reply, "FAIL")) { - 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_LOG_FUNC_EXIT__; - return 0; -} - -int ws_reject_connection(unsigned char *peer_addr) -{ - __WDP_LOG_FUNC_ENTER__; - ws_sock_data_s *sock = g_pd->common; - char cmd[64] = {0, }; - char reply[1024] = {0,}; - int res; - - if (!sock) { - WDP_LOGE("Socket is NULL"); - return -1; - } - - g_snprintf(cmd, sizeof(cmd), WS_CMD_P2P_CONNECT MACSTR "%s userReject", MAC2STR(peer_addr), WS_STR_PBC); - res = _ws_send_cmd(sock->ctrl_sock, cmd, reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - if (strstr(reply, "FAIL")) { - WDP_LOGD("Failed to reject connection with peer[" MACSECSTR "]", MAC2SECSTR(peer_addr)); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - WDP_LOGD("Succeeded to send reject connection command to peer[" MACSECSTR "]", MAC2SECSTR(peer_addr)); - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -int ws_cancel_connection(unsigned char *peer_addr) -{ - __WDP_LOG_FUNC_ENTER__; - - _ws_cancel(); - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -int ws_get_connected_peers(GList **peers, int *peer_count) -{ - __WDP_LOG_FUNC_ENTER__; - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -int ws_get_pin(char *pin) -{ - __WDP_LOG_FUNC_ENTER__; - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -int ws_set_pin(char *pin) -{ - __WDP_LOG_FUNC_ENTER__; - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -int ws_generate_pin(char **pin) -{ - __WDP_LOG_FUNC_ENTER__; - ws_sock_data_s *sock = g_pd->common; - char cmd[32] = {0, }; - char reply[1024] = {0,}; - int res = 0; - if (!pin) { - WDP_LOGE("Invalid parameter"); - return -1; - } - - if (!sock) { - WDP_LOGE("Socket is NULL"); - return -1; - } - - snprintf(cmd, sizeof(cmd), WS_CMD_WPS_PIN "get"); - res = _ws_send_cmd(sock->ctrl_sock, cmd, reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - if (strstr(reply, "FAIL")) { - WDP_LOGE("Failed to generate the pin"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - WDP_LOGE("Succeeded to generate the pin [ %s ]", reply); - - *pin = strndup(reply, OEM_PINSTR_LEN); - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -int ws_get_supported_wps_mode() -{ - __WDP_LOG_FUNC_ENTER__; - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -int ws_create_group(wfd_oem_group_param_s *param) -{ - __WDP_LOG_FUNC_ENTER__; - ws_sock_data_s *sock = g_pd->common; - char cmd[44] = {0, }; - char freq_str[11] = {0, }; - char passphrase[21] = {0, }; - char reply[1024] = {0,}; - int res = 0; - - if (!sock) { - WDP_LOGE("Socket is NULL"); - return -1; - } - - g_snprintf(cmd, sizeof(cmd), WS_CMD_P2P_GROUP_ADD); - - if (param->persistent) { - if (param->persistent == 2) - g_snprintf(cmd, sizeof(cmd), WS_STR_PERSISTENT "=%d", - param->persistent_group_id); - else - g_snprintf(cmd, sizeof(cmd), WS_STR_PERSISTENT); - } - - if (param->freq > 0) { - g_snprintf(freq_str, sizeof(freq_str), WS_STR_FREQ "%d", param->freq); - strncat(cmd, freq_str, sizeof(freq_str)); - } else { -#ifndef TIZEN_WLAN_BOARD_SPRD - strncat(cmd, WS_STR_FREQ_2G, 8); -#endif /* TIZEN_WLAN_BOARD_SPRD */ - } - - if (param->passphrase[0] != '\0') { - g_snprintf(passphrase, sizeof(passphrase), WS_STR_PASSPHRASE "%s", param->passphrase); - strncat(cmd, passphrase, sizeof(passphrase)); - } - - res = _ws_send_cmd(sock->ctrl_sock, cmd, reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - if (strstr(reply, "FAIL")) { - WDP_LOGE("Failed to add group"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - WDP_LOGD("Succeeded to add group"); - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -int ws_destroy_group(const char *ifname) -{ - __WDP_LOG_FUNC_ENTER__; - ws_sock_data_s *sock = g_pd->common; - char cmd[32] = {0, }; - char reply[1024] = {0,}; - int res = 0; - - if (!ifname) { - WDP_LOGE("Invalid parameter"); - return -1; - } - - if (!sock) { - WDP_LOGE("Socket is NULL"); - return -1; - } - - snprintf(cmd, sizeof(cmd), WS_CMD_P2P_GROUP_REMOVE "%s", ifname); - - res = _ws_send_cmd(sock->ctrl_sock, cmd, reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - if (strstr(reply, "FAIL")) { - WDP_LOGE("Failed to remove group"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - WDP_LOGD("Succeeded to remove group"); - - _ws_flush(); - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -int ws_invite(unsigned char *peer_addr, wfd_oem_invite_param_s *param) -{ - __WDP_LOG_FUNC_ENTER__; - ws_sock_data_s *sock = g_pd->common; - char cmd[128] = {0, }; - char reply[1024] = {0,}; - int res = 0; - - if (!peer_addr || !param) { - WDP_LOGE("Invalid parameter"); - return -1; - } - - if (!sock) { - WDP_LOGE("Group interface not connected"); - return -1; - } - - WDP_LOGD("Invite: Peer[" MACSECSTR "], GO Addr[" MACSECSTR "]", - MAC2SECSTR(peer_addr), MAC2SECSTR(param->go_dev_addr)); - - if (param->net_id) - g_snprintf(cmd, sizeof(cmd), WS_CMD_P2P_INVITE "persistent=%d peer=" MACSTR " go_dev_addr=" MACSTR, - param->net_id, MAC2STR(peer_addr), - MAC2STR(param->go_dev_addr)); - else - g_snprintf(cmd, sizeof(cmd), WS_CMD_P2P_INVITE "group=%s peer=" MACSTR " go_dev_addr=" MACSTR, - param->ifname, MAC2STR(peer_addr), - MAC2STR(param->go_dev_addr)); - - res = _ws_send_cmd(sock->ctrl_sock, cmd, reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - if (strstr(reply, "FAIL")) { - WDP_LOGE("Failed to invite peer"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - WDP_LOGD("Succeeded to invite peer"); - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -/* Only group owner can use this command */ -int ws_wps_start(unsigned char *peer_addr, int wps_mode, const char *pin) -{ - __WDP_LOG_FUNC_ENTER__; - ws_sock_data_s *sock = g_pd->group; - char cmd[40] = {0, }; - char reply[1024] = {0,}; - int res; - - if (!peer_addr || !pin) { - WDP_LOGE("Invalid parameter"); - return -1; - } - - if (!sock) { - WDP_LOGE("Group interface not connected"); - return -1; - } - - if (wps_mode == WFD_OEM_WPS_MODE_PBC) - g_snprintf(cmd, sizeof(cmd), WS_CMD_WPS_PBC "p2p_dev_addr=" MACSTR, MAC2STR(peer_addr)); - else - g_snprintf(cmd, sizeof(cmd), WS_CMD_WPS_PIN MACSTR " %s", MAC2STR(peer_addr), pin); - - res = _ws_send_cmd(sock->ctrl_sock, cmd, reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - if (strstr(reply, "FAIL")) { - WDP_LOGE("Failed to start WPS"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - WDP_LOGD("Succeeded to start WPS"); - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -int ws_enrollee_start(unsigned char *peer_addr, int wps_mode, const char *pin) -{ - __WDP_LOG_FUNC_ENTER__; - ws_sock_data_s *sock = g_pd->group; - char cmd[64] = {0, }; - char reply[1024] = {0,}; - int res; - - if (!peer_addr || !pin) { - WDP_LOGE("Invalid parameter"); - return -1; - } - - if (!sock) { - WDP_LOGE("Socket is NULL"); - return -1; - } - - if (wps_mode == WFD_OEM_WPS_MODE_PBC) - g_snprintf(cmd, sizeof(cmd), WS_CMD_WPS_ENROLLEE MACSTR "%s", - MAC2STR(peer_addr), _ws_wps_to_txt(wps_mode)); - else - g_snprintf(cmd, sizeof(cmd), WS_CMD_WPS_ENROLLEE MACSTR " %s%s", - MAC2STR(peer_addr), pin, _ws_wps_to_txt(wps_mode)); - - res = _ws_send_cmd(sock->ctrl_sock, cmd, reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - if (strstr(reply, "FAIL")) { - WDP_LOGE("Failed to start WPS"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - WDP_LOGD("Succeeded to start WPS"); - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -int ws_wps_cancel() -{ - __WDP_LOG_FUNC_ENTER__; - ws_sock_data_s *sock = g_pd->group; - char reply[1024] = {0,}; - int res; - - if (!sock) { - WDP_LOGE("Socket is NULL"); - return -1; - } - - res = _ws_send_cmd(sock->ctrl_sock, WS_CMD_WPS_CANCEL, reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - if (strstr(reply, "FAIL")) { - WDP_LOGE("Failed to cancel WPS"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - WDP_LOGD("Succeeded to cancel WPS"); - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -int ws_get_dev_name(char *dev_name) -{ - __WDP_LOG_FUNC_ENTER__; - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -int ws_set_dev_name(char *dev_name) -{ - __WDP_LOG_FUNC_ENTER__; - ws_sock_data_s *sock = g_pd->common; - char cmd[128] = {0, }; - char reply[1024] = {0,}; - int res; - - if (!dev_name || !strlen(dev_name)) { - WDP_LOGE("Invalid parameter"); - __WDP_LOG_FUNC_EXIT__; - return 1; - } - - if (!sock) { - WDP_LOGE("Socket is NULL"); - return -1; - } - - g_snprintf(cmd, sizeof(cmd), WS_CMD_SET "device_name %s", dev_name); - res = _ws_send_cmd(sock->ctrl_sock, cmd, (char*) reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - if (strstr(reply, "FAIL")) { - WDP_LOGE("Failed to set device name"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - WDP_LOGD("Succeeded to set device name"); - - memset(cmd, 0x0, 128); - memset(reply, 0x0, 1024); - - snprintf(cmd, sizeof(cmd), WS_CMD_SET "p2p_ssid_postfix %s", dev_name); - res = _ws_send_cmd(sock->ctrl_sock, cmd, (char*) reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - if (strstr(reply, "FAIL")) { - WDP_LOGE("Failed to set SSID postfix"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - WDP_LOGD("Succeeded to set SSID postfix"); - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -int ws_get_dev_mac(char *dev_mac) -{ - __WDP_LOG_FUNC_ENTER__; - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -int ws_get_dev_type(int *pri_dev_type, int *sec_dev_type) -{ - __WDP_LOG_FUNC_ENTER__; - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -int ws_set_dev_type(int pri_dev_type, int sec_dev_type) -{ - __WDP_LOG_FUNC_ENTER__; - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -int ws_get_go_intent(int *go_intent) -{ - __WDP_LOG_FUNC_ENTER__; - - ws_sock_data_s *sock = g_pd->common; - char cmd[80] = {0, }; - char reply[1024] = {0,}; - int res; - - if (!sock) { - WDP_LOGE("Socket is NULL"); - return -1; - } - - if (go_intent == NULL) { - WDP_LOGE("p2p_go_intent is NULL"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - g_snprintf(cmd, sizeof(cmd), WS_CMD_GET "p2p_go_intent"); - res = _ws_send_cmd(sock->ctrl_sock, cmd, (char*) reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - if (strstr(reply, "FAIL")) { - WDP_LOGE("Failed to set go intent"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - *go_intent = atoi(reply); - WDP_LOGD("Succeeded to get go intent(%d)", *go_intent); - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -int ws_set_go_intent(int go_intent) -{ - __WDP_LOG_FUNC_ENTER__; - - ws_sock_data_s *sock = g_pd->common; - char cmd[80] = {0, }; - char reply[1024] = {0,}; - int res; - - if (!sock) { - WDP_LOGE("Socket is NULL"); - return -1; - } - - g_snprintf(cmd, sizeof(cmd), WS_CMD_SET "p2p_go_intent %d", go_intent); - - res = _ws_send_cmd(sock->ctrl_sock, cmd, (char*) reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - if (strstr(reply, "FAIL")) { - WDP_LOGE("Failed to set go intent"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - WDP_LOGD("Succeeded to set go intent(%d)", go_intent); - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -int ws_set_country(char *ccode) -{ - __WDP_LOG_FUNC_ENTER__; - ws_sock_data_s *sock = g_pd->common; - char cmd[80] = {0, }; - char reply[1024] = {0,}; - int res; - - if (!sock) { - WDP_LOGE("Socket is NULL"); - return -1; - } - - g_snprintf(cmd, sizeof(cmd), WS_CMD_SET "country %s", ccode); - - res = _ws_send_cmd(sock->ctrl_sock, cmd, (char*) reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - if (strstr(reply, "FAIL")) { - WDP_LOGE("Failed to set country"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - WDP_LOGD("Succeeded to set country(%s)", ccode); - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -int _parsing_networks(char* buf, ws_network_info_s networks[], int *network_cnt) -{ - __WDP_LOG_FUNC_ENTER__; - char *ptr = buf; - int count = 0; - char *tmp_str = NULL; - int res = 0; - - /* Passing first line : "network id / ssid / bssid / flags" */ - while (*ptr != '\n') - ptr++; - - ptr++; - - count = 0; - while (*ptr != '\0') { - res = _extract_word(ptr, &tmp_str); - if (res > 0) { - networks[count].network_id = atoi(tmp_str); - g_free(tmp_str); - tmp_str = NULL; - ptr += res; - } - ptr++; - - res = _extract_word(ptr, &tmp_str); - if (res > 0) { - snprintf(networks[count].ssid, WS_SSID_LEN, "%s", tmp_str); - free(tmp_str); - tmp_str = NULL; - ptr += res; - } - ptr++; - - res = _extract_word(ptr, &tmp_str); - if (res > 0) { - _ws_txt_to_mac(tmp_str, networks[count].bssid); - g_free(tmp_str); - tmp_str = NULL; - ptr += res; - } - ptr++; - - res = _extract_word(ptr, &tmp_str); - if (res > 0) { - if (strstr(tmp_str, "CURRENT")) - networks[count].flags |= WFD_OEM_NETFLAG_CURRENT; - if (strstr(tmp_str, "DISABLED")) - networks[count].flags |= WFD_OEM_NETFLAG_DISABLED; - if (strstr(tmp_str, "TEMP-DISABLED")) - networks[count].flags |= WFD_OEM_NETFLAG_TEMP_DISABLED; - if (strstr(tmp_str, "P2P-PERSISTENT")) - networks[count].flags |= WFD_OEM_NETFLAG_P2P_PERSISTENT; - g_free(tmp_str); - tmp_str = NULL; - ptr += res; - } - ptr++; - - count++; - } - - *network_cnt = count; - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -int ws_get_persistent_groups(wfd_oem_persistent_group_s **groups, int *group_count) -{ - __WDP_LOG_FUNC_ENTER__; - ws_sock_data_s *sock = g_pd->common; - char cmd[80] = {0, }; - char reply[1024] = {0,}; - ws_network_info_s networks[WS_MAX_PERSISTENT_COUNT]; - wfd_oem_persistent_group_s *wfd_persistent_groups = NULL; - int res; - int i, cnt; - - if (!groups || !group_count) { - WDP_LOGE("Invalid parameter"); - return -1; - } - - if (!sock) { - WDP_LOGE("Socket is NULL"); - return -1; - } - - memset(networks, 0, (sizeof(ws_network_info_s) * WS_MAX_PERSISTENT_COUNT)); - - /* Reading lists the configured networks, including stored information for persistent groups. - The identifier in this is used with p2p_group_add and p2p_invite to indicate witch persistent - group is to be reinvoked. */ - snprintf(cmd, sizeof(cmd), WS_CMD_LIST_NETWORKS); - res = _ws_send_cmd(sock->ctrl_sock, cmd, (char*) reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - if (strstr(reply, "FAIL")) { - WDP_LOGE("Failed to get list of networks"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - WDP_LOGD("Succeeded to get list of networks"); - - _parsing_networks(reply, networks, &cnt); - WDP_LOGD("Persistent Group Count=%d", cnt); - if (cnt > WS_MAX_PERSISTENT_COUNT) { - WDP_LOGE("Persistent group count exceeded or parsing error"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - if (cnt == 0) { - *group_count = cnt; - *groups = wfd_persistent_groups; - - __WDP_LOG_FUNC_EXIT__; - return 0; - } - - wfd_persistent_groups = (wfd_oem_persistent_group_s*) g_try_malloc0(cnt * sizeof(wfd_oem_persistent_group_s)); - if (wfd_persistent_groups == NULL) { - WDP_LOGE("Failed to allocate memory for wfd_persistent_groups "); - return -1; - } - - for (i = 0; i < cnt; i++) { - WDP_LOGD("----persistent group [%d]----", i); - WDP_LOGD("network_id=%d", networks[i].network_id); - WDP_LOGD("ssid=%s", networks[i].ssid); - WDP_LOGD("bssid=" MACSECSTR, MAC2SECSTR(networks[i].bssid)); - WDP_LOGD("flags=%x", networks[i].flags); - - wfd_persistent_groups[i].network_id = networks[i].network_id; - g_strlcpy(wfd_persistent_groups[i].ssid, networks[i].ssid, OEM_DEV_NAME_LEN + 1); - wfd_persistent_groups[i].ssid[WS_SSID_LEN] = '\0'; - memcpy(wfd_persistent_groups[i].go_mac_address, networks[i].bssid, WS_MACADDR_LEN); - } - - *group_count = cnt; - *groups = wfd_persistent_groups; - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -int ws_remove_persistent_group(char *ssid, unsigned char *bssid) -{ - __WDP_LOG_FUNC_ENTER__; - ws_sock_data_s *sock = g_pd->common; - char cmd[80] = {0, }; - char reply[1024] = {0,}; - int res; - int i; - ws_network_info_s networks[WS_MAX_PERSISTENT_COUNT]; - int network_count; - - if (!ssid || !bssid) { - WDP_LOGE("Invalid parameter"); - return -1; - } - - if (!sock) { - WDP_LOGE("Socket is NULL"); - return -1; - } - - memset(networks, 0, (sizeof(ws_network_info_s) * WS_MAX_PERSISTENT_COUNT)); - - strncpy(cmd, WS_CMD_LIST_NETWORKS, sizeof(cmd)); - res = _ws_send_cmd(sock->ctrl_sock, cmd, (char*) reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - if (strstr(reply, "FAIL")) { - WDP_LOGE("Failed to get list of networks"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - WDP_LOGD("Succeeded to get list of networks"); - - _parsing_networks(reply, networks, &network_count); - - for (i = 0; i < network_count; i++) { - WDP_LOGD("----persistent group [%d]----", i); - WDP_LOGD("network_id=%d", networks[i].network_id); - WDP_LOGD("ssid=%s", networks[i].ssid); - WDP_LOGD("bssid=" MACSECSTR, MAC2SECSTR(networks[i].bssid)); - WDP_LOGD("flags=%x", networks[i].flags); - - if (!memcmp(bssid, networks[i].bssid, OEM_MACADDR_LEN) && !strcmp(ssid, networks[i].ssid)) { - - WDP_LOGD("Persistent group found [%d: %s]", networks[i].network_id, ssid); - - memset(cmd, 0x0, sizeof(cmd)); - memset(reply, 0x0, sizeof(reply)); - - g_snprintf(cmd, sizeof(cmd), WS_CMD_REMOVE_NETWORK " %d", networks[i].network_id); - res = _ws_send_cmd(sock->ctrl_sock, cmd, (char*) reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - if (strstr(reply, "FAIL")) { - WDP_LOGE("Failed to remove persistent group"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - WDP_LOGD("Succeeded to remove persistent group"); - - break; - } - } - - if (i == network_count) { - WDP_LOGE("Persistent group not found [%s]", ssid); - return -1; - } - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -int ws_set_persistent_reconnect(unsigned char *bssid, int reconnect) -{ - __WDP_LOG_FUNC_ENTER__; - ws_sock_data_s *sock = g_pd->common; - char cmd[80] = {0, }; - char reply[1024] = {0,}; - int res; - - if (!sock) { - WDP_LOGE("Socket is NULL"); - return -1; - } - - g_snprintf(cmd, sizeof(cmd), WS_CMD_SET "persistent_reconnect %d", reconnect); - res = _ws_send_cmd(sock->ctrl_sock, cmd, (char*) reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - if (strstr(reply, "FAIL")) { - WDP_LOGE("Failed to register WFDS service"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - WDP_LOGD("Succeeded to register WFDS service"); - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY -int ws_start_service_discovery(unsigned char *mac_addr, int service_type) -{ - __WDP_LOG_FUNC_ENTER__; - ws_sock_data_s *sock = g_pd->common; - char cmd[80] = {0, }; - char reply[1024] = {0,}; - int res; - char query[30] = {'0', '2', '0', '0', 'F', 'F', '0', '1'}; - char mac_str[18] = {0, }; - wfd_oem_service_s *service = NULL; - - if (!sock) { - WDP_LOGE("Socket is NULL"); - return -1; - } - - memset(cmd, 0x00, 80); - memset(reply, 0x00, WS_REPLY_LEN); - - query[1] += OEM_SERVICE_TYPE_LEN /2; - service = (wfd_oem_service_s*) g_try_malloc0(sizeof(wfd_oem_service_s)); - if (!service) { - WDP_LOGE("Failed to allocate memory for service"); - return -1; - } - - if (mac_addr[0] == 0 && mac_addr[1] == 0 && mac_addr[2] == 0 && - mac_addr[3] == 0 && mac_addr[4] == 0 && mac_addr[5] == 0) { - g_snprintf(mac_str, OEM_MACSTR_LEN , "%s", SERV_BROADCAST_ADDRESS); - } else { - g_snprintf(mac_str, OEM_MACSTR_LEN, MACSTR, MAC2STR(mac_addr)); - } - - switch (service_type) { - case WFD_OEM_SERVICE_TYPE_ALL: - { - g_snprintf(cmd, sizeof(cmd), WS_CMD_SERV_DISC_REQ " %s %s", mac_str, SERV_DISC_REQ_ALL); - g_strlcpy(service->service_type, SERV_DISC_REQ_ALL, OEM_SERVICE_TYPE_LEN + 1); - } - break; - case WFD_OEM_SERVICE_TYPE_BONJOUR: - { - g_snprintf(cmd, sizeof(cmd), WS_CMD_SERV_DISC_REQ " %s %s", mac_str, SERV_DISC_REQ_BONJOUR); - g_strlcpy(service->service_type, SERV_DISC_REQ_BONJOUR, OEM_SERVICE_TYPE_LEN + 1); - } - break; - case WFD_OEM_SERVICE_TYPE_UPNP: - { - g_snprintf(cmd, sizeof(cmd), WS_CMD_SERV_DISC_REQ " %s %s", mac_str, SERV_DISC_REQ_UPNP); - g_strlcpy(service->service_type, SERV_DISC_REQ_UPNP, OEM_SERVICE_TYPE_LEN + 1); - } - break; - default: - WDP_LOGE("Invalid Service type"); - __WDP_LOG_FUNC_EXIT__; - g_free(service); - return -1; - } - - res = _ws_send_cmd(sock->ctrl_sock, cmd, (char*) reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant"); - __WDP_LOG_FUNC_EXIT__; - g_free(service); - return -1; - } - - if (strstr(reply, "FAIL")) { - WDP_LOGE("Failed to start service discovery"); - __WDP_LOG_FUNC_EXIT__; - g_free(service); - return -1; - } - WDP_LOGD("Succeeded to start service discovery"); - - g_strlcpy(service->dev_addr, mac_str, OEM_MACSTR_LEN); - WDP_LOGD("query id :[0x%s]", reply); - g_strlcpy(service->query_id, reply, OEM_QUERY_ID_LEN + 1); - - res = _check_service_query_exists(service); - if (res) - g_free(service); - else - service_list = g_list_append(service_list, service); - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -int ws_cancel_service_discovery(unsigned char *mac_addr, int service_type) -{ - __WDP_LOG_FUNC_ENTER__; - ws_sock_data_s *sock = g_pd->common; - char cmd[80] = {0, }; - char reply[1024] = {0,}; - int res; - char query_id[OEM_QUERY_ID_LEN + 1] = {0, }; - char mac_str[18] = {0, }; - wfd_oem_service_s *data = NULL; - char s_type[OEM_SERVICE_TYPE_LEN + 1] = {0, }; - - if (!sock) { - WDP_LOGE("Socket is NULL"); - return -1; - } - - memset(cmd, 0x00, 80); - memset(reply, 0x00, WS_REPLY_LEN); - - if (mac_addr[0] == 0 && mac_addr[1] == 0 && mac_addr[2] == 0 && - mac_addr[3] == 0 && mac_addr[4] == 0 && mac_addr[5] == 0) { - g_snprintf(mac_str, OEM_MACSTR_LEN , "%s", SERV_BROADCAST_ADDRESS); - } else { - g_snprintf(mac_str, OEM_MACSTR_LEN, MACSTR, MAC2STR(mac_addr)); - } - - switch (service_type) { - case WFD_OEM_SERVICE_TYPE_ALL: - g_strlcpy(s_type, SERV_DISC_REQ_ALL, OEM_SERVICE_TYPE_LEN + 1); - break; - case WFD_OEM_SERVICE_TYPE_BONJOUR: - g_strlcpy(s_type, SERV_DISC_REQ_BONJOUR, OEM_SERVICE_TYPE_LEN + 1); - break; - case WFD_OEM_SERVICE_TYPE_UPNP: - g_strlcpy(s_type, SERV_DISC_REQ_UPNP, OEM_SERVICE_TYPE_LEN + 1); - break; - default: - __WDP_LOG_FUNC_EXIT__; - WDP_LOGE("Invalid Service type"); - return -1; - } - - WDP_LOGD("Cancel service discovery service_type [%d]", service_type); - WDP_LOGD("Cancel service discovery s_type [%s]", s_type); - - data = _remove_service_query(s_type, mac_str, query_id); - if (NULL == data) - return -1; - - g_snprintf(cmd, sizeof(cmd), WS_CMD_SERV_DISC_CANCEL " %s", query_id); - res = _ws_send_cmd(sock->ctrl_sock, cmd, (char*) reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - if (strstr(reply, "FAIL")) { - WDP_LOGE("Failed to cancel service discovery"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - WDP_LOGD("Succeeded to cancel service discovery"); - - service_list = g_list_remove(service_list, data); - g_free(data); - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -int _convert_bonjour_query_to_hex(char *query, char **hex) -{ - char hex_key[256] = {0, };; - char *token = NULL; - char *temp = NULL; - int len = 0; - int tot_len = 0; - int i = 0; - char temp_str[256] = {0, }; - char *result_str = NULL; - char *str_query = NULL; - - if (!query || !hex) { - WDP_LOGE("Invalid parameter"); - return -1; - } - - str_query = strdup(query); - if (!str_query) { - WDP_LOGE("Memory allocation failed"); - return -1; - } - - token = strtok_r(str_query, ".", &temp); - while (token) { - if (!strcmp(token, "local") || !strcmp(token, "_tcp") || !strcmp(token, "_udp")) { - WDP_LOGD("Query conversion done"); - break; - } - WDP_LOGD("Token: %s", token); - len = strlen(token); - sprintf(temp_str, "%02x", len); - for (i = 0; i < len; i++) - sprintf(temp_str + i * 2 + 2, "%02x", token[i]); - - strncat(hex_key, temp_str, 2+2*len); - WDP_LOGD("Converting: %s", hex_key); - memset(temp_str, 0x0, 256); - - token = strtok_r(NULL, ".", &temp); - } - - if (token && strstr(token, "_tcp")) { - token = strtok_r(NULL, ".", &temp); - if (token && strstr(token, "local")) { - strncat(hex_key, "c00c", 4); - strncat(hex_key, "000c", 4); - strncat(hex_key, "01", 2); - goto next; - } - } else if (token && strstr(token, "_udp")) { - token = strtok_r(NULL, ".", &temp); - if (token && strstr(token, "local")) { - strncat(hex_key, "c01c", 4); - strncat(hex_key, "000c", 4); - strncat(hex_key, "01", 2); - goto next; - } - } else if (token && strstr(token, "local")) { - strncat(hex_key, "c011", 4); - strncat(hex_key, "000c", 4); - strncat(hex_key, "01", 2); - goto next; - } - - strncat(hex_key, "c00c", 4); - strncat(hex_key, "0010", 4); - strncat(hex_key, "01", 2); - -next: - g_free(str_query); - - tot_len = strlen(hex_key); - result_str = (char*) calloc(1, tot_len+1); - if (!result_str) { - WDP_LOGE("Failed to allocate memory for result string"); - return -1; - } - sprintf(result_str, "%s", hex_key); - - *hex = result_str; - - return 0; -} - - -int _convert_bonjour_to_hex(char *query, char *rdata, - wfd_oem_bonjour_rdata_type_e rdata_type, char **hex) -{ - char *hex_key = NULL; - char hex_value[256] = {0, }; - char *token = NULL; - char *temp = NULL; - int len = 0; - int tot_len = 0; - int i = 0; - char temp_str[256] = {0, }; - char *result_str = NULL; - char *str_rdata = NULL; - - if (!query || !hex) { - WDP_LOGE("Invalid parameter"); - return -1; - } - - if (_convert_bonjour_query_to_hex(query, &hex_key) < 0 || !hex_key) { - WDP_LOGE("_convert_bonjour_query_to_hex failed"); - return -1; - } - - if (!rdata || !strlen(rdata)) { - WDP_LOGD("RDATA is NULL"); - strncat(hex_value, "00", 2); - } else { - str_rdata = strdup(rdata); - if (!str_rdata) { - WDP_LOGE("Memory allocation failed"); - g_free(hex_key); - return -1; - } - token = strtok_r(str_rdata, ".", &temp); - while (token) { - WDP_LOGD("Token: %s", token); - len = strlen(token); - sprintf(temp_str, "%02x", len); - for (i = 0; i < len; i++) - sprintf(temp_str + i * 2 + 2, "%02x", token[i]); - - strncat(hex_value, temp_str, 2+2*len); - WDP_LOGD("Converting: %s", hex_value); - memset(temp_str, 0x0, 256); - - token = strtok_r(NULL, ".", &temp); - } - g_free(str_rdata); - } - - if (rdata_type == WFD_OEM_BONJOUR_RDATA_PTR) - strncat(hex_value, "c027", 4); - - tot_len = strlen(hex_key) + strlen(hex_value); - result_str = (char*) g_try_malloc0(tot_len+2); - if (!result_str) { - WDP_LOGE("Failed to allocate memory for result string"); - g_free(hex_key); - return -1; - } - g_snprintf(result_str, tot_len+2, "%s %s", hex_key, hex_value); - - *hex = result_str; - - g_free(hex_key); - - return 0; -} - -int ws_serv_add(wfd_oem_new_service_s *service) -{ - __WDP_LOG_FUNC_ENTER__; - ws_sock_data_s *sock = g_pd->common; - char cmd[256] = {0, }; - char reply[1024] = {0,}; - int res; - - if (!sock) { - WDP_LOGE("Socket is NULL"); - return -1; - } - - switch (service->protocol) { - case WFD_OEM_SERVICE_TYPE_BONJOUR: - { - WDP_LOGD("Service type: WFD_OEM_SERVICE_TYPE_BONJOUR"); - WDP_LOGD("Query: %s", service->data.bonjour.query); - WDP_LOGD("RData: %s", service->data.bonjour.rdata); - char *hex = NULL; - - res = _convert_bonjour_to_hex(service->data.bonjour.query, - service->data.bonjour.rdata, - service->data.bonjour.rdata_type, - &hex); - - if (res < 0) { - WDP_LOGE("Failed to convert Key string as hex string"); - return -1; - } - - WDP_LOGD("Converted Hexadecimal string [%s]", hex); - g_snprintf(cmd, sizeof(cmd), WS_CMD_SERVICE_ADD " bonjour %s", hex); - g_free(hex); - - } - break; - case WFD_OEM_SERVICE_TYPE_UPNP: - { - WDP_LOGD("Service type: WFD_OEM_SERVICE_TYPE_UPNP"); - - g_snprintf(cmd, sizeof(cmd), WS_CMD_SERVICE_ADD " upnp %s %s", - service->data.upnp.version, service->data.upnp.service); - } - break; - default: - WDP_LOGE("This service type is not supported [%d]", service->protocol); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - res = _ws_send_cmd(sock->ctrl_sock, cmd, (char*) reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - if (strstr(reply, "FAIL")) { - WDP_LOGE("Failed to add service"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - WDP_LOGD("Succeeded to add service"); - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -int ws_serv_del(wfd_oem_new_service_s *service) -{ - __WDP_LOG_FUNC_ENTER__; - ws_sock_data_s *sock = g_pd->common; - char cmd[256] = {0, }; - char reply[1024] = {0,}; - int res; - - if (!sock) { - WDP_LOGE("Socket is NULL"); - return -1; - } - - switch (service->protocol) { - case WFD_OEM_SERVICE_TYPE_BONJOUR: - { - WDP_LOGD("Service type: WFD_OEM_SERVICE_TYPE_BONJOUR, Data: %s", service); - char *hex_key = NULL; - - res = _convert_bonjour_query_to_hex(service->data.bonjour.query, &hex_key); - if (res != 0) { - WDP_LOGE("Failed to convert Key string as hex string"); - return -1; - } - - WDP_LOGD("Converted Hexadecimal string [%s]", hex_key); - g_snprintf(cmd, sizeof(cmd), WS_CMD_SERVICE_DEL " bonjour %s", hex_key); - g_free(hex_key); - } - break; - case WFD_OEM_SERVICE_TYPE_UPNP: - { - WDP_LOGD("Service type: WFD_OEM_SERVICE_TYPE_UPNP"); - - g_snprintf(cmd, sizeof(cmd), WS_CMD_SERVICE_DEL " upnp %s %s", - service->data.upnp.version, service->data.upnp.service); - } - break; - default: - WDP_LOGE("This service type is not supported"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - res = _ws_send_cmd(sock->ctrl_sock, cmd, (char*) reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - if (strstr(reply, "FAIL")) { - WDP_LOGE("Failed to delete service"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - WDP_LOGD("Succeeded to del service"); - - __WDP_LOG_FUNC_EXIT__; - return 0; -} -#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */ - -#ifdef TIZEN_FEATURE_WIFI_DISPLAY -int ws_miracast_init(int enable) -{ - __WDP_LOG_FUNC_ENTER__; - ws_sock_data_s *sock = g_pd->common; - char cmd[80] = {0, }; - char reply[1024] = {0,}; - int res; - - unsigned int length = 0x0006; - unsigned int dev_info = 0x0110; - unsigned int ctrl_port = 0x07E6; - unsigned int max_tput = 0x0028; - /* unsigned int bssid = 0x00; */ - unsigned int cpled_sink_status = 0x00; - /* param : enable or disable*/ - - if (!sock) { - WDP_LOGE("Socket is NULL"); - return -1; - } - - g_snprintf(cmd, sizeof(cmd), WS_CMD_SET "wifi_display %d", enable); - - res = _ws_send_cmd(sock->ctrl_sock, cmd, (char*) reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - if (strstr(reply, "FAIL")) { - WDP_LOGE("Failed to initialize miracast"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - WDP_LOGD("Succeeded to initialize miracast"); - - if (enable) { - /* param : dev_info */ - memset(cmd, 0x0, 80); - memset(reply, 0x0, WS_REPLY_LEN); - - g_snprintf(cmd, sizeof(cmd), WS_CMD_SUBELEM_SET "%d %04x%04x%04x%04x", - WFD_SUBELM_ID_DEV_INFO, length, dev_info, ctrl_port, max_tput); - res = _ws_send_cmd(sock->ctrl_sock, cmd, (char*) reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - if (strstr(reply, "FAIL")) { - WDP_LOGE("Failed to set miracast parameter(device info)"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - WDP_LOGD("Succeeded to set miracast parameter(device info)"); - - /* param : Associated BSSID Subelement */ - memset(cmd, 0x0, 80); - memset(reply, 0x0, WS_REPLY_LEN); - - snprintf(cmd, sizeof(cmd), WS_CMD_SUBELEM_SET "%d %04x%s", - WFD_SUBELM_ID_ASSOC_BSSID, WFD_SUBELM_LEN_ASSOC_BSSID, "000000000000"); - res = _ws_send_cmd(sock->ctrl_sock, cmd, (char*) reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - if (strstr(reply, "FAIL")) { - WDP_LOGE("Failed to set miracast parameter(BSSID subelement)"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - WDP_LOGD("Succeeded to set miracast parameter(BSSID subelement)"); - - /* param : cpled_sink_status */ - memset(cmd, 0x0, 80); - memset(reply, 0x0, WS_REPLY_LEN); - - g_snprintf(cmd, sizeof(cmd), WS_CMD_SUBELEM_SET "%d %04x%02x", - WFD_SUBELM_ID_CUPLED_SYNC_INFO, 0x01, cpled_sink_status); - res = _ws_send_cmd(sock->ctrl_sock, cmd, (char*) reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - if (strstr(reply, "FAIL")) { - WDP_LOGE("Failed to set miracast parameter(Cuppled sink status)"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - WDP_LOGD("Succeeded to set miracast parameter(Cuppled sink status)"); - - - /* param : WFD Extended Capability */ - memset(cmd, 0x0, 80); - memset(reply, 0x0, WS_REPLY_LEN); - - g_snprintf(cmd, sizeof(cmd), WS_CMD_SUBELEM_SET "%d %04x%04x", - WFD_SUBELM_ID_EXT_CAPAB, 0x02, 0x00); - res = _ws_send_cmd(sock->ctrl_sock, cmd, (char*) reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - if (strstr(reply, "FAIL")) { - WDP_LOGE("Failed to set miracast parameter(Extended Capability)"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - WDP_LOGD("Succeeded to set miracast parameter(Extended Capability)"); - - } - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -int ws_set_display(wfd_oem_display_s *wifi_display) -{ - __WDP_LOG_FUNC_ENTER__; - ws_sock_data_s *sock = g_pd->common; - char cmd[80] = {0, }; - char reply[1024] = {0,}; - int res; - unsigned int device_info = 0; - - if (!sock) { - WDP_LOGE("Socket is NULL"); - return -1; - } - - WDP_LOGD("Wi-Fi Display type: [%d]", wifi_display->type); - WDP_LOGD("Wi-Fi Display avai: [%d]", wifi_display->availability); - WDP_LOGD("Wi-Fi Display hdcp: [%d]", wifi_display->hdcp_support); - WDP_LOGD("Wi-Fi Display hdcp: [%d]", wifi_display->port); - WDP_LOGD("Wi-Fi Display sync: [%d]", wifi_display->max_tput); - - device_info = wifi_display->type; - device_info += (wifi_display->hdcp_support) << 8; - device_info += (wifi_display->availability) << 4; /* for availability bit */ - - g_snprintf(cmd, sizeof(cmd), WS_CMD_SUBELEM_SET "%d %04x%04x%04x%04x", - WFD_SUBELM_ID_DEV_INFO, WFD_SUBELEM_LEN_DEV_INFO, - device_info, wifi_display->port, wifi_display->max_tput); - - WDP_LOGD("Wi-Fi Display set command: [%s]", cmd); - res = _ws_send_cmd(sock->ctrl_sock, cmd, (char*) reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - if (strstr(reply, "FAIL")) { - WDP_LOGE("Failed to set wifi display"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - WDP_LOGD("Succeeded to set wifi display"); - - __WDP_LOG_FUNC_EXIT__; - return 0; -} -#endif /* TIZEN_FEATURE_WIFI_DISPLAY */ - -int ws_refresh() -{ - __WDP_LOG_FUNC_ENTER__; - - _ws_cancel(); - _ws_flush(); - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -int ws_save_config() -{ - __WDP_LOG_FUNC_ENTER__; - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -int ws_set_operating_channel(int channel) -{ - __WDP_LOG_FUNC_ENTER__; - - char cmd[80] = {0, }; - char reply[WS_REPLY_LEN] = {0, }; - int res = 0; - ws_sock_data_s *sock = g_pd->common; - - if (!sock) { - WDP_LOGE("Socket is NULL"); - return -1; - } - - snprintf(cmd, sizeof(cmd), WS_CMD_SET "p2p_oper_channel %d", channel); - - res = _ws_send_cmd(sock->ctrl_sock, cmd, reply, sizeof(reply)); - if (res < 0) { - WDP_LOGE("Failed to send command to wpa_supplicant"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - if (strstr(reply, "FAIL")) { - WDP_LOGE("Failed to set Operating channel"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - WDP_LOGD("Succeeded to set P2P Operating Channel"); - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -int ws_remove_all_network() -{ - __WDP_LOG_FUNC_ENTER__; - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -int ws_get_wpa_status(int *wpa_status) -{ - __WDP_LOG_FUNC_ENTER__; - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -#if defined(TIZEN_FEATURE_ASP) -int ws_advertise_service(wfd_oem_asp_service_s *service, int replace) -{ - __WDP_LOG_FUNC_ENTER__; - - __WDP_LOG_FUNC_EXIT__; - return -1; -} - -int ws_cancel_advertise_service(wfd_oem_asp_service_s *service) -{ - __WDP_LOG_FUNC_ENTER__; - - __WDP_LOG_FUNC_EXIT__; - return -1; -} - -int ws_seek_service(wfd_oem_asp_service_s *service) -{ - __WDP_LOG_FUNC_ENTER__; - - __WDP_LOG_FUNC_EXIT__; - return -1; -} - -int ws_cancel_seek_service(wfd_oem_asp_service_s *service) -{ - __WDP_LOG_FUNC_ENTER__; - - __WDP_LOG_FUNC_EXIT__; - return -1; -} - -int ws_asp_prov_disc_req(wfd_oem_asp_prov_s *asp_params) -{ - __WDP_LOG_FUNC_ENTER__; - - __WDP_LOG_FUNC_EXIT__; - return -1; -} -#endif /* TIZEN_FEATURE_ASP */ - -int ws_add_vsie(wfd_oem_vsie_frames_e frame_id, const char* vsie) -{ - __WDP_LOG_FUNC_ENTER__; - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -int ws_get_vsie(wfd_oem_vsie_frames_e frame_id, char **vsie) -{ - __WDP_LOG_FUNC_ENTER__; - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -int ws_remove_vsie(wfd_oem_vsie_frames_e frame_id, const char *vsie) -{ - __WDP_LOG_FUNC_ENTER__; - - __WDP_LOG_FUNC_EXIT__; - return 0; -} diff --git a/prd/plugin/wpasupplicant/ctrl_iface_sock/CMakeLists.txt b/prd/plugin/wpasupplicant/ctrl_iface_sock/CMakeLists.txt deleted file mode 100644 index 9bc3c43..0000000 --- a/prd/plugin/wpasupplicant/ctrl_iface_sock/CMakeLists.txt +++ /dev/null @@ -1,28 +0,0 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -PROJECT(wifi-direct-prd-plugin-wpasupplicant C) - -# Set required packages -INCLUDE(FindPkgConfig) -pkg_check_modules(pkgs REQUIRED capi-network-wifi-direct glib-2.0 gio-2.0 dlog) -FOREACH(flag ${pkgs_CFLAGS}) - SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") -ENDFOREACH(flag) - -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/oem) -INCLUDE_DIRECTORIES(SRCS include) - -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -g -Werror") -SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") -SET(CMAKE_C_FLAGS_RELEASE "-O2") -SET(SRCS - wfd-prd-plugin-wpasupplicant.c - ) - -# library build -ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS}) -#SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION 0.1.0) -SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "" OUTPUT_NAME ${PROJECT_NAME}) - -# install -INSTALL(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${LIB_DIR}) diff --git a/prd/plugin/wpasupplicant/ctrl_iface_sock/include/wfd-prd-plugin-log.h b/prd/plugin/wpasupplicant/ctrl_iface_sock/include/wfd-prd-plugin-log.h deleted file mode 100644 index e11b6af..0000000 --- a/prd/plugin/wpasupplicant/ctrl_iface_sock/include/wfd-prd-plugin-log.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Network Configuration Module - * - * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef __WFD_PRD_PLUGIN_LOG_H_ -#define __WFD_PRD_PLUGIN_LOG_H_ - -#ifdef USE_DLOG -#include - -#undef LOG_TAG -#define LOG_TAG "WIFI_DIRECT_PRD_PLUGIN" - -#define WDP_LOGV(format, args...) LOGV(format, ##args) -#define WDP_LOGD(format, args...) LOGD(format, ##args) -#define WDP_LOGI(format, args...) LOGI(format, ##args) -#define WDP_LOGW(format, args...) LOGW(format, ##args) -#define WDP_LOGE(format, args...) LOGE(format, ##args) -#define WDP_LOGF(format, args...) LOGF(format, ##args) - -#define __WDP_LOG_FUNC_ENTER__ LOGD("Enter") -#define __WDP_LOG_FUNC_EXIT__ LOGD("Quit") - -#define WDP_SECLOGI(format, args...) SECURE_LOG(LOG_INFO, LOG_TAG, format, ##args) -#define WDP_SECLOGD(format, args...) SECURE_LOG(LOG_DEBUG, LOG_TAG, format, ##args) - -#else /* USE_DLOG */ - -#define WDP_LOGV(format, args...) -#define WDP_LOGD(format, args...) -#define WDP_LOGI(format, args...) -#define WDP_LOGW(format, args...) -#define WDP_LOGE(format, args...) -#define WDP_LOGF(format, args...) - -#define __WDP_LOG_FUNC_ENTER__ -#define __WDP_LOG_FUNC_EXIT__ - -#define WDP_SECLOGI(format, args...) -#define WDP_SECLOGD(format, args...) - -#endif /* USE_DLOG */ - -#endif /* __WFD_PRD_PLUGIN_LOG_H_ */ diff --git a/prd/plugin/wpasupplicant/ctrl_iface_sock/include/wfd-prd-plugin-wpasupplicant.h b/prd/plugin/wpasupplicant/ctrl_iface_sock/include/wfd-prd-plugin-wpasupplicant.h deleted file mode 100644 index 2619e76..0000000 --- a/prd/plugin/wpasupplicant/ctrl_iface_sock/include/wfd-prd-plugin-wpasupplicant.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Network Configuration Module - * - * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef __WFD_PRD_PLUGIN_WPASUPPLICANT_H__ -#define __WFD_PRD_PLUGIN_WPASUPPLICANT_H__ - -#define WS_MACADDR_LEN 6 - -typedef struct { - int iftype; - int ctrl_sock; - int mon_sock; - char *ifname; - int error_count; - int gsource; -} ws_sock_data_s; - -typedef struct { - int initialized; /* check whether plugin is initialized or not. block init function if initialized */ - int activated; - int concurrent; - int global_sock; - ws_sock_data_s *common; - ws_sock_data_s *group; - unsigned char local_dev_addr[WS_MACADDR_LEN]; - wfd_oem_event_cbs_s *callback; -} ws_sock_plugin_data_s; - -int ws_prd_init(wfd_oem_event_cbs_s *event_cb); -int wfd_prd_plugin_load(wfd_oem_ops_s **ops); - -#endif /* __WFD_PRD_PLUGIN_WPASUPPLICANT_H__ */ diff --git a/prd/plugin/wpasupplicant/ctrl_iface_sock/wfd-prd-plugin-wpasupplicant.c b/prd/plugin/wpasupplicant/ctrl_iface_sock/wfd-prd-plugin-wpasupplicant.c deleted file mode 100644 index 7c770d9..0000000 --- a/prd/plugin/wpasupplicant/ctrl_iface_sock/wfd-prd-plugin-wpasupplicant.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Network Configuration Module - * - * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include "wifi-direct-oem.h" -#include "wfd-prd-plugin-log.h" -#include "wfd-prd-plugin-wpasupplicant.h" - -static ws_sock_plugin_data_s *g_pd; - -static int _ws_reset_plugin(ws_sock_plugin_data_s *pd) -{ - __WDP_LOG_FUNC_ENTER__; - - if (!pd) { - WDP_LOGE("Invalid parameter"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - g_free(pd); - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -int ws_prd_init(wfd_oem_event_cbs_s *event_cbs) -{ - __WDP_LOG_FUNC_ENTER__; - - if (event_cbs == NULL) { - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - if (g_pd) - _ws_reset_plugin(g_pd); - - errno = 0; - g_pd = (ws_sock_plugin_data_s*) g_try_malloc0(sizeof(ws_sock_plugin_data_s)); - if (!g_pd) { - WDP_LOGE("Failed to allocate memory for plugin data. [%s]", - strerror(errno)); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - g_pd->callback = event_cbs; - g_pd->initialized = TRUE; - - __WDP_LOG_FUNC_EXIT__; - return 0; -} - -wfd_oem_prd_ops_s prd_ops = { - .prd_init = ws_prd_init, -}; - -int wfd_prd_plugin_load(wfd_oem_ops_s **ops) -{ - __WDP_LOG_FUNC_ENTER__; - - if (!ops) { - WDP_LOGE("Invalid parameter"); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - - (*ops)->extra_data = &prd_ops; - - __WDP_LOG_FUNC_EXIT__; - return 0; -} diff --git a/src/wifi-direct-event.c b/src/wifi-direct-event.c index c5c7bf4..56e2f15 100644 --- a/src/wifi-direct-event.c +++ b/src/wifi-direct-event.c @@ -79,9 +79,6 @@ static int _wfd_event_update_peer(wfd_manager_s *manager, wfd_oem_dev_data_s *da MAC2SECSTR(peer->dev_addr), peer->dev_name); } } -#ifndef CTRL_IFACE_DBUS - memcpy(peer->intf_addr, data->p2p_intf_addr, MACADDR_LEN); -#endif /* CTRL_IFACE_DBUS */ peer->pri_dev_type = data->pri_dev_type; peer->sec_dev_type = data->sec_dev_type; peer->config_methods = data->config_methods; @@ -339,7 +336,6 @@ void wfd_event_prov_disc_req(wfd_oem_event_s *event) return; } -#ifdef CTRL_IFACE_DBUS wfd_oem_dev_data_s *edata = NULL; edata = (wfd_oem_dev_data_s*) event->edata; @@ -351,20 +347,6 @@ void wfd_event_prov_disc_req(wfd_oem_event_s *event) res = _wfd_event_update_peer(manager, edata); peer = wfd_peer_find_by_dev_addr(manager, event->dev_addr); -#else /* CTRL_IFACE_DBUS */ - peer = wfd_peer_find_by_dev_addr(manager, event->dev_addr); - if (!peer) { - WDS_LOGD("Prov_disc from unknown peer. Add new peer"); - peer = wfd_add_peer(manager, event->dev_addr, "DIRECT-"); - if (!peer) { - WDS_LOGE("Failed to add peer for invitation"); - __WDS_LOG_FUNC_EXIT__; - return; - } - wfd_update_peer(manager, peer); - } - wfd_update_peer_time(manager, event->dev_addr); -#endif /* CTRL_IFACE_DBUS */ if (WFD_DEV_ROLE_GO != manager->local->dev_role) { WDS_LOGI("TV is not GO, updated peer data only."); @@ -396,7 +378,6 @@ void wfd_event_prov_disc_resp(wfd_oem_event_s *event) wfd_device_s *peer = NULL; int res = 0; -#ifdef CTRL_IFACE_DBUS wfd_oem_dev_data_s *edata = NULL; edata = (wfd_oem_dev_data_s*) event->edata; @@ -410,21 +391,6 @@ void wfd_event_prov_disc_resp(wfd_oem_event_s *event) peer = wfd_peer_find_by_dev_addr(manager, event->dev_addr); if (peer) peer->state = WFD_PEER_STATE_CONNECTING; -#else /* CTRL_IFACE_DBUS */ - peer = wfd_peer_find_by_dev_addr(manager, event->dev_addr); - if (!peer) { - WDS_LOGD("Prov_disc from unknown peer. Add new peer"); - peer = wfd_add_peer(manager, event->dev_addr, "DIRECT-"); - if (!peer) { - WDS_LOGE("Failed to add peer for invitation"); - __WDS_LOG_FUNC_EXIT__; - return; - } - peer->state = WFD_PEER_STATE_CONNECTING; - wfd_update_peer(manager, peer); - } - wfd_update_peer_time(manager, event->dev_addr); -#endif /* CTRL_IFACE_DBUS */ res = wfd_session_process_event(manager, event); if (res < 0) @@ -541,7 +507,6 @@ void wfd_event_go_neg_req(wfd_oem_event_s *event) return; } -#ifdef CTRL_IFACE_DBUS wfd_oem_dev_data_s *edata = NULL; int res = 0; @@ -558,33 +523,6 @@ void wfd_event_go_neg_req(wfd_oem_event_s *event) __WDS_LOG_FUNC_EXIT__; return; } -#else /* CTRL_IFACE_DBUS */ - wfd_oem_conn_data_s *edata = NULL; - wfd_device_s *peer = NULL; - - edata = (wfd_oem_conn_data_s*) event->edata; - if (!edata || event->edata_type != WFD_OEM_EDATA_TYPE_CONN) { - WDS_LOGE("Invalid connection event data"); - __WDS_LOG_FUNC_EXIT__; - return; - } - - peer = wfd_peer_find_by_dev_addr(manager, event->dev_addr); - if (!peer) { - WDS_LOGD("Invitation from unknown peer. Add new peer"); - peer = wfd_add_peer(manager, event->dev_addr, "DIRECT-"); - if (!peer) { - WDS_LOGE("Failed to add peer for invitation"); - __WDS_LOG_FUNC_EXIT__; - return; - } - } - - if (edata->wps_mode == 0) - edata->wps_mode = 1; - - event->wps_mode = edata->wps_mode; -#endif /* CTRL_IFACE_DBUS */ wfd_session_process_event(manager, event); __WDS_LOG_FUNC_EXIT__; @@ -663,7 +601,6 @@ void wfd_event_go_neg_done(wfd_oem_event_s *event) { __WDS_LOG_FUNC_ENTER__; -#ifdef CTRL_IFACE_DBUS wfd_manager_s *manager = wfd_get_manager(); wfd_session_s *session = NULL; wfd_oem_conn_data_s *edata = NULL; @@ -683,7 +620,6 @@ void wfd_event_go_neg_done(wfd_oem_event_s *event) } wfd_session_process_event(manager, event); -#endif /* CTRL_IFACE_DBUS */ __WDS_LOG_FUNC_EXIT__; return; } @@ -1175,9 +1111,6 @@ void wfd_event_sta_connected(wfd_oem_event_s *event) wfd_group_add_member(group, peer->dev_addr); session->state = SESSION_STATE_COMPLETED; -#ifndef CTRL_IFACE_DBUS - memcpy(peer->intf_addr, event->intf_addr, MACADDR_LEN); -#endif /* CTRL_IFACE_DBUS */ peer->state = WFD_PEER_STATE_CONNECTED; wfd_state_set(manager, WIFI_DIRECT_STATE_GROUP_OWNER); @@ -1190,9 +1123,7 @@ void wfd_event_sta_connected(wfd_oem_event_s *event) WFD_EVENT_CONNECTION_RSP, peer_mac_address)); -#ifdef CTRL_IFACE_DBUS wfd_update_peer(manager, peer); -#endif /* CTRL_IFACE_DBUS */ #ifdef TIZEN_FEATURE_IP_OVER_EAPOL if (event->ip_addr_peer[3]) { peer->ip_type = WFD_IP_TYPE_OVER_EAPOL; @@ -1272,11 +1203,7 @@ void wfd_event_sta_disconnected(wfd_oem_event_s *event) return; } -#ifdef CTRL_IFACE_DBUS peer = wfd_group_find_member_by_addr(group, event->dev_addr); -#else /* CTRL_IFACE_DBUS */ - peer = wfd_group_find_member_by_addr(group, event->intf_addr); -#endif /* DBUS_IFACE */ if (!peer) { WDS_LOGE("Failed to find connected peer"); peer = wfd_session_get_peer(manager->session); @@ -1286,7 +1213,6 @@ void wfd_event_sta_disconnected(wfd_oem_event_s *event) return; } -#ifdef CTRL_IFACE_DBUS /** * If no peer connected and * disconnected event is not for connecting peer @@ -1299,7 +1225,6 @@ void wfd_event_sta_disconnected(wfd_oem_event_s *event) __WDS_LOG_FUNC_EXIT__; return; } -#endif /* CTRL_DBUS_IFACE */ } memcpy(peer_addr, peer->dev_addr, MACADDR_LEN); -- 2.7.4