From: Abhishek Sansanwal Date: Fri, 25 May 2018 11:45:09 +0000 (+0530) Subject: Added initial code for Gtest X-Git-Tag: accepted/tizen/unified/20180612.044202~2^2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fconnectivity%2Fnet-config.git;a=commitdiff_plain;h=1932b35f0cd4fd8fd0436aace16b3fb05bff0de9 Added initial code for Gtest Signed-off-by: Abhishek Sansanwal Change-Id: Ie1b8c8f8c9514074186c9941c2f4437269acadf0 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 6c372e7..e39e645 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -131,3 +131,4 @@ INSTALL(FILES ${CMAKE_SOURCE_DIR}/config/security-network-config.conf DESTINATIO ADD_SUBDIRECTORY(plugin/headed) ADD_SUBDIRECTORY(plugin/telephony) ADD_SUBDIRECTORY(unittest) +ADD_SUBDIRECTORY(gtest) diff --git a/gtest/CMakeLists.txt b/gtest/CMakeLists.txt new file mode 100644 index 0000000..fda5d23 --- /dev/null +++ b/gtest/CMakeLists.txt @@ -0,0 +1,32 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(gtest-net-config C CXX) + +SET(GTEST_TEST "gtest-net-config") +ADD_DEFINITIONS("-DUSE_DLOG") + +SET(REQUIRES_LIST ${REQUIRES_LIST} + glib-2.0 + gio-2.0 + gmock + dlog +) + +INCLUDE(FindPkgConfig) +PKG_CHECK_MODULES(GTEST_TEST_PKG REQUIRED ${REQUIRES_LIST}) + +FOREACH(flag ${GTEST_TEST_PKG_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wall -fPIE") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}") +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie") + +FILE(GLOB GTEST_TEST_SRCS *.cpp) +SET(GTEST_TEST_SRCS ${GTEST_TEST_SRCS}) + +ADD_EXECUTABLE(${GTEST_TEST} ${GTEST_TEST_SRCS}) +TARGET_LINK_LIBRARIES(${GTEST_TEST} ${GTEST_TEST_LDFLAGS} ${GTEST_TEST_PKG_LDFLAGS} -ldl -lgcov) + +INSTALL(TARGETS ${GTEST_TEST} RUNTIME DESTINATION ${BIN_DIR}) diff --git a/gtest/gdbus.cpp b/gtest/gdbus.cpp new file mode 100644 index 0000000..27764d7 --- /dev/null +++ b/gtest/gdbus.cpp @@ -0,0 +1,231 @@ +/* + * Copyright (c) 2017 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 +#include +#include +#include + +#include "gdbus.h" + +GDbus::GDbus() +{ + this->m_pConnection = NULL; + this->m_pCancellable = NULL; +} + +GDbus::~GDbus() +{ + GDBusConnection *conn = this->m_pConnection; + GCancellable *cancel = this->m_pCancellable; + + if (cancel) { + g_cancellable_cancel(cancel); + g_object_unref(cancel); + cancel = NULL; + } + + if (conn) { + g_object_unref(conn); + conn = NULL; + } +} + +error_e GDbus::Create(void) +{ + GError *err = NULL; + +#if !GLIB_CHECK_VERSION(2, 36, 0) + g_type_init(); +#endif + + this->m_pConnection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err); + if (this->m_pConnection == NULL) { + if (err != NULL) { + GLOGD("Failed to connect to the D-BUS daemon [%s]", err->message); + g_error_free(err); + } + + return ERROR_OPERATION_FAILED; + } + + this->m_pCancellable = g_cancellable_new(); + + return ERROR_NONE; +} + +error_e GDbus::Destroy(void) +{ + g_cancellable_cancel(this->m_pCancellable); + g_object_unref(this->m_pCancellable); + this->m_pCancellable = NULL; + + g_object_unref(this->m_pConnection); + this->m_pConnection = NULL; + + return ERROR_NONE; +} + +GDBusConnection *GDbus::GetConnection(void) +{ + return this->m_pConnection; +} + +GCancellable *GDbus::GetCancellable(void) +{ + return this->m_pCancellable; +} + +error_e GDbus::ConvertErrorStringToEnum(const char *error) +{ + if (NULL != strstr(error, "NoReply")) + return ERROR_INVALID_OPERATION; + else if (NULL != strstr(error, "Failed")) + return ERROR_OPERATION_FAILED; + else if (NULL != strstr(error, "UnknownMethod")) + return ERROR_INVALID_OPERATION; + else if (NULL != strstr(error, "InvalidArguments")) + return ERROR_INVALID_PARAMETER; + else if (NULL != strstr(error, "AccessDenied")) + return ERROR_PERMISSION_DENIED; + else if (NULL != strstr(error, "PermissionDenied")) + return ERROR_PERMISSION_DENIED; + else if (NULL != strstr(error, "NotSupported")) + return ERROR_NOT_SUPPORTED; + else if (NULL != strstr(error, "InProgress")) + return ERROR_IN_PROGRESS; + + return ERROR_OPERATION_FAILED; +} + +GVariant *GDbus::InvokeMethod_with_fd(GUnixFDList *fd_list, const char *dest, const char *path, + const char *iface_name, const char *method, GVariant *params, error_e *dbus_error) +{ + GError *error = NULL; + GVariant *reply = NULL; + GDBusConnection *connection = NULL; + *dbus_error = ERROR_NONE; + + connection = GetConnection(); + if (connection == NULL) { + GLOGD("GDBusconnection is NULL"); + *dbus_error = ERROR_NOT_INITIALIZED; + return reply; + } + + reply = g_dbus_connection_call_with_unix_fd_list_sync(connection, + dest, + path, + iface_name, + method, + params, + NULL, + G_DBUS_CALL_FLAGS_NONE, + DBUS_REPLY_TIMEOUT, + fd_list, + NULL, + GetCancellable(), + &error); + + if (reply == NULL) { + if (error != NULL) { + GLOGD("g_dbus_connection_call_with_unix_fd_list_sync() failed " + "error [%d: %s]", error->code, error->message); + *dbus_error = ConvertErrorStringToEnum(error->message); + g_error_free(error); + } else { + GLOGD("g_dbus_connection_call_with_unix_fd_list_sync() failed"); + *dbus_error = ERROR_OPERATION_FAILED; + } + + return NULL; + } + + return reply; +} + +GVariant *GDbus::InvokeMethod(const char *dest, const char *path, + const char *iface_name, const char *method, GVariant *params, error_e *dbus_error) +{ + GError *error = NULL; + GVariant *reply = NULL; + GDBusConnection *connection = NULL; + *dbus_error = ERROR_NONE; + + connection = GetConnection(); + if (connection == NULL) { + GLOGD("GDBusconnection is NULL"); + *dbus_error = ERROR_NOT_INITIALIZED; + return reply; + } + + reply = g_dbus_connection_call_sync(connection, + dest, + path, + iface_name, + method, + params, + NULL, + G_DBUS_CALL_FLAGS_NONE, + DBUS_REPLY_TIMEOUT, + GetCancellable(), + &error); + + if (reply == NULL) { + if (error != NULL) { + GLOGD("g_dbus_connection_call_sync() failed " + "error [%d: %s]", error->code, error->message); + *dbus_error = ConvertErrorStringToEnum(error->message); + g_error_free(error); + } else { + GLOGD("g_dbus_connection_call_sync() failed"); + *dbus_error = ERROR_OPERATION_FAILED; + } + + return NULL; + } + + return reply; +} + +error_e GDbus::InvokeMethodNonblock(const char *dest, const char *path, + const char *iface_name, const char *method, GVariant *params, int timeout, + GAsyncReadyCallback notify_func, void *user_data) +{ + GDBusConnection *connection = NULL; + + connection = GetConnection(); + if (connection == NULL) { + GLOGD("GDBusconnection is NULL"); + return ERROR_NOT_INITIALIZED; + } + + g_dbus_connection_call(connection, + dest, + path, + iface_name, + method, + params, + NULL, + G_DBUS_CALL_FLAGS_NONE, + timeout, + GetCancellable(), + (GAsyncReadyCallback) notify_func, + (gpointer)user_data); + + return ERROR_NONE; +} diff --git a/gtest/gdbus.h b/gtest/gdbus.h new file mode 100644 index 0000000..06e83f7 --- /dev/null +++ b/gtest/gdbus.h @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2017 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 __NET_CONFIG_GDBUS_H__ +#define __NET_CONFIG_GDBUS_H__ + +#include +#include + +#include "netconf.h" + +#define GMAINTIMEOUT 10000 +#define DBUS_REPLY_TIMEOUT (120 * 1000) + +#define NETCONFIG_SERVICE "net.netconfig" + +/* wifi */ +#define NETCONFIG_WIFI_PATH "/net/netconfig/wifi" +#define NETCONFIG_WIFI_INTERFACE "net.netconfig.wifi" + +#define GET_WIFI_STATE "GetWifiState" +#define LOAD_DRIVER "LoadDriver" +#define REMOVE_DRIVER "RemoveDriver" +#define IS_IP_CONFLICT_DETECT_ENABLED "IsIpConflictDetectEnabled" +#define SET_BGSCAN "SetBgscan" +#define GET_AUTOSCAN "GetAutoscan" +#define GET_IP_CONFLICT_STATE "GetIpConflictState" +#define GET_IP_CONFLICT_PERIOD "GetIpConflictPeriod" +#define GET_AUTOSCANMODE "GetAutoscanmode" +#define REQUEST_WPS_CONNECT "RequestWpsConnect" +#define NETLINK_SCAN "NetlinkScan" +#define GET_PASSPOINT "GetPasspoint" +#define SET_PASSPOINT "SetPasspoint" +#define GET_CONFIGIDS "GetConfigIds" +#define SAVE_CONFIGURATION "SaveConfiguration" +#define SAVE_EAP_CONFIGURATION "SaveEapConfiguration" +#define SET_IP_CONFLICT_PERIOD "SetIpConflictPeriod" +#define REMOVE_CONFIGURATION "RemoveConfiguration" +#define LOAD_CONFIGURATION "LoadConfiguration" +#define LOAD_EAP_CONFIGURATION "LoadEapConfiguration" +#define SET_CONFIG_FIELD "SetConfigField" +#define GET_CONFIG_PASSPHRASE "GetConfigPassphrase" +#define CREATE_EAP_CONFIG "CreateEapConfig" +#define DELETE_EAP_CONFIG "DeleteEapConfig" +#define IP_CONFLICT_SET_ENABLE "IpConflictSetEnable" +#define GET_SIM_IMSI "GetSimImsi" +#define REQ_SIM_AUTH "ReqSimAuth" +#define REQ_AKA_AUTH "ReqAkaAuth" +#define GET_SIM_AUTH "GetSimAuth" +#define CHECK_BLACKLIST "CheckBlackList" +#define TDLS_DISCONNECT "TdlsDisconnect" +#define TDLS_CONNECTED_PEER "TdlsConnectedPeer" +#define TDLS_CONNECT "TdlsConnect" +#define TDLS_DISCOVER "TdlsDiscover" +#define TDLS_CHANNEL_SWITCH "TdlsChannelSwitch" +#define TDLS_CANCEL_CHANNEL_SWITCH "TdlsCancelChannelSwitch" +#define ADD_VSIE "AddVsie" +#define GET_VSIE "GetVsie" +#define REMOVE_VSIE "RemoveVsie" +#define ENCRYPT_PASSPHRASE "EncryptPassphrase" +#define DECRYPT_PASSPHRASE "DecryptPassphrase" + +#define NETCONFIG_WIFI_FIRMWARE_INTERFACE "net.netconfig.wifi.Firmware" + +#define WIFI_FIRMWARE_STOP "Stop" +#define WIFI_FIRMWARE_START "Start" + +/* vpn service */ +#define NETCONFIG_VPNSVC_PATH "/net/netconfig/vpnsvc" +#define NETCONFIG_VPNSVC_INTERFACE "net.netconfig.vpnsvc" + +#define VPN_INIT "vpn_init" +#define VPN_DEINIT "vpn_deinit" +#define VPN_PROTECT "vpn_protect" +#define VPN_UP "vpn_up" +#define VPN_DOWN "vpn_down" +#define VPN_BLOCK_NETWORKS "vpn_block_networks" +#define VPN_UNBLOCK_NETWORKS "vpn_unblock_networks" +#define VPN_UPDATE_SETTINGS "vpn_update_settings" +#define VPN_ADD_ROUTE "vpn_add_route" +#define VPN_REMOVE_ROUTE "vpn_remove_route" +#define VPN_ADD_DNS_SERVER "vpn_add_dns_server" +#define VPN_REMOVE_DNS_SERVER "vpn_remove_dns_server" + +/* network state */ +#define NETCONFIG_NETWORK_PATH "/net/netconfig/network" +#define NETCONFIG_NETWORK_INTERFACE "net.netconfig.network" +#define NETCONFIG_TCPDUMP_INTERFACE "net.netconfig.tcpdump" + +#define ADD_ROUTE "AddRoute" +#define REMOVE_ROUTE "RemoveRoute" +#define ETHERNET_CABLE_STATE "EthernetCableState" +#define CHECK_GET_PRIVILEGE "CheckGetPrivilege" +#define CHECK_PROFILE_PRIVILEGE "CheckProfilePrivilege" +#define CHECK_INTERNET_Privilege "CheckInternetPrivilege" +#define LAUNCH_MDNS "LaunchMdns" +#define DEVICE_POLICY_SET_WIFI "DevicePolicySetWifi" +#define DEVICE_POLICY_GET_WIFI "DevicePolicyGetWifi" +#define DEVICE_POLICY_SET_WIFI_PROFILE "DevicePolicySetWifiProfile" +#define DEVICE_POLICY_GET_WIFI_PROFILE "DevicePolicyGetWifiProfile" +#define GET_METERED_INFO "GetMeteredInfo" +#define PREFERRED_IPV6_ADDRESS "PreferredIpv6Address" +#define GET_TCP_DUMPSTATE "GetTCPDumpState" +#define START_TCP_DUMP "StartTCPDump" +#define STOP_TCP_DUMP "StopTCPDump" + +/* mptcp */ +#define NETCONFIG_MPTCP_PATH "/net/netconfig/mptcp" +#define NETCONFIG_MPTCP_INTERFACE "net.netconfig.mptcp" + +#define MPTCP_SUPPORTED "MptcpSupported" +#define MPTCP_SET_ENABLE "MptcpSetEnable" +#define MPTCP_GET_ENABLED "MptcpGetEnabled" +#define MPTCP_SET_PATH_MANAGER "MptcpSetPathManager" +#define MPTCP_GET_PATH_MANAGER "MptcpGetPathManager" +#define MPTCP_SET_SCHEDULER "MptcpSetScheduler" +#define MPTCP_GET_SCHEDULER "MptcpGetScheduler" + +/* network statistics */ +#define NETCONFIG_NETWORK_STATISTICS_PATH "/net/netconfig/network_statistics" +#define NETCONFIG_NETWORK_STATISTICS_INTERFACE "net.netconfig.network_statistics" + +#define GET_WIFI_TOTAL_TX_BYTES "GetWifiTotalTxBytes" +#define GET_WIFI_TOTAL_RX_BYTES "GetWifiTotalRxBytes" +#define GET_WIFI_LAST_TX_BYTES "GetWifiLastTxBytes" +#define GET_WIFI_LAST_RX_BYTES "GetWifiLastRxBytes" +#define RESET_CELLULAR_TOTAL_TX_BYTES "ResetCellularTotalTxBytes" +#define RESET_CELLULAR_TOTAL_RX_BYTES "ResetCellularTotalRxBytes" +#define RESET_CELLULAR_LAST_TX_BYTES "ResetCellularLastTxBytes" +#define RESET_CELLULAR_LAST_RX_BYTES "ResetCellularLastRxBytes" +#define RESET_WIFI_TOTAL_TX_BYTES "ResetWifiTotalTxBytes" +#define RESET_WIFI_TOTAL_RX_BYTES "ResetWifiTotalRxBytes" +#define RESET_WIFI_LAST_TX_BYTES "ResetWifiLastTxBytes" +#define RESET_WIFI_LAST_RX_BYTES "ResetWifiLastRxBytes" + +class GDbus { +private: + GDBusConnection *m_pConnection; + GCancellable *m_pCancellable; +public: + GDbus(); + ~GDbus(); + error_e Create(void); + error_e Destroy(void); + GDBusConnection *GetConnection(void); + GCancellable *GetCancellable(void); + error_e ConvertErrorStringToEnum(const char *error); + GVariant *InvokeMethod(const char *dest, const char *path, + const char *iface_name, const char *method, GVariant *params, error_e *dbus_error); + error_e InvokeMethodNonblock(const char *dest, const char *path, + const char *iface_name, const char *method, GVariant *params, int timeout, + GAsyncReadyCallback notify_func, void *user_data); + GVariant *InvokeMethod_with_fd(GUnixFDList *fd_list, const char *dest, const char *path, + const char *iface_name, const char *method, GVariant *params, error_e *dbus_error); +}; + +#endif /* __NET_CONFIG_GDBUS_H__ */ diff --git a/gtest/mptcp.cpp b/gtest/mptcp.cpp new file mode 100644 index 0000000..8c0ae36 --- /dev/null +++ b/gtest/mptcp.cpp @@ -0,0 +1,193 @@ +/* + * Copyright (c) 2017 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 +#include +#include +#include +#include + +#include "mptcp.h" + +Mptcp::Mptcp() +{ + Create(); +} + +Mptcp::~Mptcp() +{ + Destroy(); +} + +error_e Mptcp::MptcpSupported(bool *supported) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_MPTCP_PATH, + NETCONFIG_MPTCP_INTERFACE, + MPTCP_SUPPORTED, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(b)", supported); + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Mptcp::MptcpSetEnable(int enabled) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_MPTCP_PATH, + NETCONFIG_MPTCP_INTERFACE, + MPTCP_SET_ENABLE, + g_variant_new("(i)", enabled), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Mptcp::MptcpGetEnabled(int *enabled) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_MPTCP_PATH, + NETCONFIG_MPTCP_INTERFACE, + MPTCP_GET_ENABLED, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(i)", enabled); + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Mptcp::MptcpSetPathManager(const char *path) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_MPTCP_PATH, + NETCONFIG_MPTCP_INTERFACE, + MPTCP_SET_PATH_MANAGER, + g_variant_new("(s)", path), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Mptcp::MptcpGetPathManager(char *path) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_MPTCP_PATH, + NETCONFIG_MPTCP_INTERFACE, + MPTCP_GET_PATH_MANAGER, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(s)", path); + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Mptcp::MptcpSetScheduler(const char *sched) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_MPTCP_PATH, + NETCONFIG_MPTCP_INTERFACE, + MPTCP_SET_SCHEDULER, + g_variant_new("(s)", sched), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Mptcp::MptcpGetScheduler(char *sched) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_MPTCP_PATH, + NETCONFIG_MPTCP_INTERFACE, + MPTCP_GET_SCHEDULER, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(s)", sched); + g_variant_unref(message); + + return ERROR_NONE; +} + diff --git a/gtest/mptcp.h b/gtest/mptcp.h new file mode 100644 index 0000000..4d1018f --- /dev/null +++ b/gtest/mptcp.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2017 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 __MPTCP_H__ +#define __MPTCP_H__ + +#include "mptcp.h" +#include "gdbus.h" + +class Mptcp:public GDbus { +public: + Mptcp(); + ~Mptcp(); + error_e MptcpSupported(bool *supported); + error_e MptcpSetEnable(int enabled); + error_e MptcpSetPathManager(char *path); + error_e MptcpGetEnabled(int *enabled); + error_e MptcpGetPathManager(char *path); + error_e MptcpSetPathManager(const char *path); + error_e MptcpSetScheduler(const char *sched); + error_e MptcpGetScheduler(char *sched); +}; + + +#endif /* __MPTCP_H__ */ diff --git a/gtest/netconf.h b/gtest/netconf.h new file mode 100644 index 0000000..52450e3 --- /dev/null +++ b/gtest/netconf.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2017 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 __NETCONF_H__ +#define __NETCONF_H__ + +#include + +#ifdef USE_DLOG +#include +#undef LOG_TAG +#define LOG_TAG "NET_CONFIG_TEST" +#define GLOGD(format, args...) LOGD(format, ##args) +#else +#define GLOGD(format, args...) +#endif + +typedef enum { + ERROR_NONE = 0, + ERROR_NOT_PERMITTED = -1, + ERROR_OUT_OF_MEMORY = -2, + ERROR_PERMISSION_DENIED = -3, + ERROR_RESOURCE_BUSY = -4, + ERROR_INVALID_OPERATION = -5, + ERROR_INVALID_PARAMETER = -6, + ERROR_NOT_SUPPORTED = -7, + ERROR_OPERATION_FAILED = -8, + ERROR_NOT_INITIALIZED = -9, + ERROR_ALREADY_INITIALIZED = -10, + ERROR_IN_PROGRESS = -11, +} error_e; + + +#endif /* __NETCONF_H__ */ diff --git a/gtest/netstat.cpp b/gtest/netstat.cpp new file mode 100644 index 0000000..01af513 --- /dev/null +++ b/gtest/netstat.cpp @@ -0,0 +1,314 @@ +/* + * Copyright (c) 2017 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 +#include +#include +#include +#include + +#include "netstat.h" + +NetStat::NetStat() +{ + Create(); +} + +NetStat::~NetStat() +{ + Destroy(); +} + +error_e NetStat::GetWifiTotalTxBytes(void) +{ + uint64_t tx_bytes = 0; + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_NETWORK_STATISTICS_PATH, + NETCONFIG_NETWORK_STATISTICS_INTERFACE, + GET_WIFI_TOTAL_TX_BYTES, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(t)", &tx_bytes); + g_variant_unref(message); + + GLOGD("Succeeded to get wifi total tx bytes %d", tx_bytes); + + return ERROR_NONE; +} + +error_e NetStat::GetWifiTotalRxBytes(void) +{ + uint64_t rx_bytes = 0; + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_NETWORK_STATISTICS_PATH, + NETCONFIG_NETWORK_STATISTICS_INTERFACE, + GET_WIFI_TOTAL_RX_BYTES, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(t)", &rx_bytes); + g_variant_unref(message); + + GLOGD("Succeeded to get wifi total rx bytes %d", rx_bytes); + + return ERROR_NONE; +} + +error_e NetStat::GetWifiLastTxBytes(void) +{ + uint64_t tx_bytes = 0; + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_NETWORK_STATISTICS_PATH, + NETCONFIG_NETWORK_STATISTICS_INTERFACE, + GET_WIFI_LAST_TX_BYTES, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(t)", &tx_bytes); + g_variant_unref(message); + + GLOGD("Succeeded to get wifi last tx bytes %d", tx_bytes); + + return ERROR_NONE; +} + +error_e NetStat::GetWifiLastRxBytes(void) +{ + uint64_t rx_bytes = 0; + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_NETWORK_STATISTICS_PATH, + NETCONFIG_NETWORK_STATISTICS_INTERFACE, + GET_WIFI_LAST_RX_BYTES, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(t)", &rx_bytes); + g_variant_unref(message); + + GLOGD("Succeeded to get wifi last rx bytes %d", rx_bytes); + + return ERROR_NONE; +} + +error_e NetStat::ResetCellularTotalTxBytes(void) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_NETWORK_STATISTICS_PATH, + NETCONFIG_NETWORK_STATISTICS_INTERFACE, + RESET_CELLULAR_TOTAL_TX_BYTES, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e NetStat::ResetCellularTotalRxBytes(void) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_NETWORK_STATISTICS_PATH, + NETCONFIG_NETWORK_STATISTICS_INTERFACE, + RESET_CELLULAR_TOTAL_RX_BYTES, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e NetStat::ResetCellularLastTxBytes(void) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_NETWORK_STATISTICS_PATH, + NETCONFIG_NETWORK_STATISTICS_INTERFACE, + RESET_CELLULAR_LAST_TX_BYTES, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e NetStat::ResetCellularLastRxBytes(void) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_NETWORK_STATISTICS_PATH, + NETCONFIG_NETWORK_STATISTICS_INTERFACE, + RESET_CELLULAR_LAST_RX_BYTES, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e NetStat::ResetWifiLastTxBytes(void) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_NETWORK_STATISTICS_PATH, + NETCONFIG_NETWORK_STATISTICS_INTERFACE, + RESET_WIFI_LAST_TX_BYTES, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e NetStat::ResetWifiLastRxBytes(void) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_NETWORK_STATISTICS_PATH, + NETCONFIG_NETWORK_STATISTICS_INTERFACE, + RESET_WIFI_LAST_RX_BYTES, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e NetStat::ResetWifiTotalTxBytes(void) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_NETWORK_STATISTICS_PATH, + NETCONFIG_NETWORK_STATISTICS_INTERFACE, + RESET_WIFI_TOTAL_TX_BYTES, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e NetStat::ResetWifiTotalRxBytes(void) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_NETWORK_STATISTICS_PATH, + NETCONFIG_NETWORK_STATISTICS_INTERFACE, + RESET_WIFI_TOTAL_RX_BYTES, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_unref(message); + + return ERROR_NONE; +} diff --git a/gtest/netstat.h b/gtest/netstat.h new file mode 100644 index 0000000..affed40 --- /dev/null +++ b/gtest/netstat.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2017 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 __NETSTAT_H__ +#define __NETSTAT_H__ + +#include "netconf.h" +#include "gdbus.h" + +class NetStat:public GDbus { +public: + NetStat(); + ~NetStat(); + error_e GetWifiTotalTxBytes(void); + error_e GetWifiLastTxBytes(void); + error_e GetWifiLastRxBytes(void); + error_e GetWifiTotalRxBytes(void); + error_e ResetWifiTotalRxBytes(void); + error_e ResetWifiTotalTxBytes(void); + error_e ResetWifiLastRxBytes(void); + error_e ResetWifiLastTxBytes(void); + error_e ResetCellularLastRxBytes(void); + error_e ResetCellularLastTxBytes(void); + error_e ResetCellularTotalRxBytes(void); + error_e ResetCellularTotalTxBytes(void); +}; + + +#endif /* __NETSTAT_H__ */ diff --git a/gtest/network_state.cpp b/gtest/network_state.cpp new file mode 100644 index 0000000..b0e0f11 --- /dev/null +++ b/gtest/network_state.cpp @@ -0,0 +1,322 @@ +/* + * Copyright (c) 2017 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 +#include +#include +#include +#include + +#include "network_state.h" + +NetworkState::NetworkState() +{ + Create(); +} + +NetworkState::~NetworkState() +{ + Destroy(); +} + +error_e NetworkState::AddRoute(const char *ip, const char *mask, const char *interface, +const char *gateway, int family, bool *result) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_NETWORK_PATH, + NETCONFIG_NETWORK_INTERFACE, + ADD_ROUTE, + g_variant_new("(ssssi)", ip, mask, interface, + gateway, family), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(b)", result); + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e NetworkState::RemoveRoute(const char *ip, const char *mask, const char *interface, +const char *gateway, int family, bool *result) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_NETWORK_PATH, + NETCONFIG_NETWORK_INTERFACE, + REMOVE_ROUTE, + g_variant_new("(ssssi)", ip, mask, interface, + gateway, family), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(b)", result); + g_variant_unref(message); + + return ERROR_NONE; +} +error_e NetworkState::EthernetCableState(int *state) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_NETWORK_PATH, + NETCONFIG_NETWORK_INTERFACE, + ETHERNET_CABLE_STATE, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(i)", state); + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e NetworkState::LaunchMdns(const char *name) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_NETWORK_PATH, + NETCONFIG_NETWORK_INTERFACE, + LAUNCH_MDNS, + g_variant_new("(s)", name), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_unref(message); + + return ERROR_NONE; +} +error_e NetworkState::DevicePolicySetWifi(int state) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_NETWORK_PATH, + NETCONFIG_NETWORK_INTERFACE, + DEVICE_POLICY_SET_WIFI, + g_variant_new("(i)", state), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_unref(message); + + return ERROR_NONE; +} +error_e NetworkState::DevicePolicyGetWifi(int *state) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_NETWORK_PATH, + NETCONFIG_NETWORK_INTERFACE, + DEVICE_POLICY_GET_WIFI, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(i)", state); + g_variant_unref(message); + + return ERROR_NONE; +} +error_e NetworkState::DevicePolicySetWifiProfile(int state) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_NETWORK_PATH, + NETCONFIG_NETWORK_INTERFACE, + DEVICE_POLICY_SET_WIFI_PROFILE, + g_variant_new("(i)", state), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_unref(message); + + return ERROR_NONE; +} +error_e NetworkState::DevicePolicyGetWifiProfile(int *state) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_NETWORK_PATH, + NETCONFIG_NETWORK_INTERFACE, + DEVICE_POLICY_GET_WIFI_PROFILE, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(i)", state); + g_variant_unref(message); + + return ERROR_NONE; +} +error_e NetworkState::GetMeteredInfo(bool *state) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_NETWORK_PATH, + NETCONFIG_NETWORK_INTERFACE, + GET_METERED_INFO, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(b)", state); + g_variant_unref(message); + + return ERROR_NONE; +} +error_e NetworkState::PreferredIpv6Address(const char *profile, char *address) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_NETWORK_PATH, + NETCONFIG_NETWORK_INTERFACE, + PREFERRED_IPV6_ADDRESS, + g_variant_new("(s)", profile), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(s)", address); + g_variant_unref(message); + + return ERROR_NONE; +} +error_e NetworkState::GetTCPDumpState(bool *state) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_NETWORK_PATH, + NETCONFIG_TCPDUMP_INTERFACE, + GET_TCP_DUMPSTATE, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(b)", state); + g_variant_unref(message); + + return ERROR_NONE; +} +error_e NetworkState::StartTCPDump() +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_NETWORK_PATH, + NETCONFIG_TCPDUMP_INTERFACE, + START_TCP_DUMP, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_unref(message); + + return ERROR_NONE; +} +error_e NetworkState::StopTCPDump() +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_NETWORK_PATH, + NETCONFIG_TCPDUMP_INTERFACE, + STOP_TCP_DUMP, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_unref(message); + + return ERROR_NONE; +} diff --git a/gtest/network_state.h b/gtest/network_state.h new file mode 100644 index 0000000..8d51d2a --- /dev/null +++ b/gtest/network_state.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2017 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 __NETWORK_STATE_H__ +#define __NETWORK_STATE_H__ + +#include "network_state.h" +#include "gdbus.h" + +class NetworkState:public GDbus { +public: + NetworkState(); + ~NetworkState(); + error_e AddRoute(const char *ip, const char *mask, const char *interface, + const char *gateway, int family, bool *result); + error_e RemoveRoute(const char *ip, const char *mask, const char *interface, + const char *gateway, int family, bool *result); + error_e EthernetCableState(int *state); + error_e LaunchMdns(const char *name); + error_e DevicePolicySetWifi(int state); + error_e DevicePolicyGetWifi(int *state); + error_e DevicePolicySetWifiProfile(int state); + error_e DevicePolicyGetWifiProfile(int *state); + error_e GetMeteredInfo(bool *state); + error_e PreferredIpv6Address(const char *profile, char *address); + error_e GetTCPDumpState(bool *state); + error_e StartTCPDump(); + error_e StopTCPDump(); +}; + + +#endif /* __NETWORK_STATE_H__ */ diff --git a/gtest/unittest.cpp b/gtest/unittest.cpp new file mode 100644 index 0000000..ad4bf14 --- /dev/null +++ b/gtest/unittest.cpp @@ -0,0 +1,1377 @@ +/* + * Copyright (c) 2017 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 +#include +#include +#include +#include +#include +#include +#include + +#include "netconf.h" +#include "netstat.h" +#include "mptcp.h" +#include "network_state.h" +#include "vpn.h" +#include "wifi.h" + +using ::testing::InitGoogleTest; +using ::testing::Test; +using ::testing::TestCase; +using namespace std; + +char *mesh_id = (char *)"gtestnetwork"; + +TEST(NetworkStatistics, GetWifiTotalTxBytes_p) +{ + error_e ret = ERROR_NONE; + NetStat mgr; + + ret = mgr.GetWifiTotalTxBytes(); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(NetworkStatistics, GetWifiTotalRxBytes_p) +{ + error_e ret = ERROR_NONE; + NetStat mgr; + + ret = mgr.GetWifiTotalRxBytes(); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(NetworkStatistics, GetWifiLastTxBytes_p) +{ + error_e ret = ERROR_NONE; + NetStat mgr; + + ret = mgr.GetWifiLastTxBytes(); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(NetworkStatistics, GetWifiLastRxBytes_p) +{ + error_e ret = ERROR_NONE; + NetStat mgr; + + ret = mgr.GetWifiLastRxBytes(); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(NetworkStatistics, ResetCellularTotalTxBytes_p) +{ + error_e ret = ERROR_NONE; + NetStat mgr; + + ret = mgr.ResetCellularTotalTxBytes(); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(NetworkStatistics, ResetCellularTotalRxBytes_p) +{ + error_e ret = ERROR_NONE; + NetStat mgr; + + ret = mgr.ResetCellularTotalRxBytes(); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(NetworkStatistics, ResetCellularLastTxBytes_p) +{ + error_e ret = ERROR_NONE; + NetStat mgr; + + ret = mgr.ResetCellularLastTxBytes(); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(NetworkStatistics, ResetCellularLastRxBytes_p) +{ + error_e ret = ERROR_NONE; + NetStat mgr; + + ret = mgr.ResetCellularLastRxBytes(); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(NetworkStatistics, ResetWifiTotalTxBytes_p) +{ + error_e ret = ERROR_NONE; + NetStat mgr; + + ret = mgr.ResetWifiTotalTxBytes(); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(NetworkStatistics, ResetWifiTotalRxBytes_p) +{ + error_e ret = ERROR_NONE; + NetStat mgr; + + ret = mgr.ResetWifiTotalRxBytes(); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(NetworkStatistics, ResetWifiLastTxBytes_p) +{ + error_e ret = ERROR_NONE; + NetStat mgr; + + ret = mgr.ResetWifiLastTxBytes(); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(NetworkStatistics, ResetWifiLastRxBytes_p) +{ + error_e ret = ERROR_NONE; + NetStat mgr; + + ret = mgr.ResetWifiLastRxBytes(); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(NetworkState, AddRoute_p) +{ + error_e ret = ERROR_NONE; + NetworkState mgr; + const char *ip = "192.168.11.55"; + const char *mask = "255.255.255.0"; + const char *interface = "lo"; + const char *gateway = "192.168.11.1"; + bool result; + + ret = mgr.AddRoute(ip, mask, interface, gateway, + AF_INET, &result); + EXPECT_EQ(ERROR_NONE, ret); + EXPECT_EQ(true, result); +} + +TEST(NetworkState, RemoveRoute_p) +{ + error_e ret = ERROR_NONE; + NetworkState mgr; + const char *ip = "192.168.11.55"; + const char *mask = "255.255.255.0"; + const char *interface = "lo"; + const char *gateway = "192.168.11.1"; + bool result; + + ret = mgr.RemoveRoute(ip, mask, interface, gateway, + AF_INET, &result); + + EXPECT_EQ(ERROR_NONE, ret); + EXPECT_EQ(true, result); +} + +TEST(NetworkState, RemoveRoute_n) +{ + error_e ret = ERROR_NONE; + NetworkState mgr; + bool result; + + ret = mgr.RemoveRoute(NULL, NULL, NULL, NULL, + -1, &result); + + EXPECT_NE(ERROR_NONE, ret); +} + +TEST(NetworkState, LaunchMdns_p) +{ + error_e ret = ERROR_NONE; + NetworkState mgr; + const char *name = "gtest"; + + ret = mgr.LaunchMdns(name); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(NetworkState, LaunchMdns_n) +{ + error_e ret = ERROR_NONE; + NetworkState mgr; + const char *name = "gtest"; + + ret = mgr.LaunchMdns(name); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(NetworkState, DevicePolicySetWifi_p1) +{ + error_e ret = ERROR_NONE; + NetworkState mgr; + int state = 0; + + ret = mgr.DevicePolicySetWifi(state); + EXPECT_EQ(ERROR_NONE, ret); + ret = mgr.DevicePolicyGetWifi(&state); + EXPECT_EQ(ERROR_NONE, ret); + EXPECT_EQ(state, 0); +} + +TEST(NetworkState, DevicePolicySetWifi_p2) +{ + error_e ret = ERROR_NONE; + NetworkState mgr; + int state = 1; + + ret = mgr.DevicePolicySetWifi(state); + EXPECT_EQ(ERROR_NONE, ret); + ret = mgr.DevicePolicyGetWifi(&state); + EXPECT_EQ(ERROR_NONE, ret); + EXPECT_EQ(state, 1); +} + +TEST(NetworkState, DevicePolicyGetWifi_p) +{ + error_e ret = ERROR_NONE; + NetworkState mgr; + int state; + + ret = mgr.DevicePolicyGetWifi(&state); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(NetworkState, DevicePolicyGetWifi_n) +{ + error_e ret = ERROR_NONE; + NetworkState mgr; + + ret = mgr.DevicePolicyGetWifi(NULL); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(NetworkState, DevicePolicySetWifiProfile_p1) +{ + error_e ret = ERROR_NONE; + NetworkState mgr; + int state = 0; + + ret = mgr.DevicePolicySetWifiProfile(state); + EXPECT_EQ(ERROR_NONE, ret); + ret = mgr.DevicePolicyGetWifiProfile(&state); + EXPECT_EQ(ERROR_NONE, ret); + EXPECT_EQ(state, 0); +} + +TEST(NetworkState, DevicePolicySetWifiProfile_p2) +{ + error_e ret = ERROR_NONE; + NetworkState mgr; + int state = 1; + + ret = mgr.DevicePolicySetWifiProfile(state); + EXPECT_EQ(ERROR_NONE, ret); + ret = mgr.DevicePolicyGetWifiProfile(&state); + EXPECT_EQ(ERROR_NONE, ret); + EXPECT_EQ(state, 1); +} + +TEST(NetworkState, DevicePolicySetWifiProfile_n) +{ + error_e ret = ERROR_NONE; + NetworkState mgr; + int state = -1; + + ret = mgr.DevicePolicySetWifiProfile(state); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(NetworkState, DevicePolicyGetWifiProfile_p) +{ + error_e ret = ERROR_NONE; + NetworkState mgr; + int state; + + ret = mgr.DevicePolicyGetWifiProfile(&state); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(NetworkState, GetMeteredInfo_p) +{ + error_e ret = ERROR_NONE; + NetworkState mgr; + bool state; + + ret = mgr.GetMeteredInfo(&state); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(NetworkState, GetMeteredInfo_n) +{ + error_e ret = ERROR_NONE; + NetworkState mgr; + bool state; + + ret = mgr.GetMeteredInfo(&state); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(NetworkState, GetTCPDumpState_p) +{ + error_e ret = ERROR_NONE; + NetworkState mgr; + bool state; + + ret = mgr.GetTCPDumpState(&state); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(NetworkState, GetTCPDumpState_n) +{ + error_e ret = ERROR_NONE; + NetworkState mgr; + + ret = mgr.GetTCPDumpState(NULL); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(NetworkState, StartTCPDump_p) +{ + error_e ret = ERROR_NONE; + NetworkState mgr; + bool state; + + ret = mgr.StartTCPDump(); + EXPECT_EQ(ERROR_NONE, ret); + + sleep(1); + ret = mgr.GetTCPDumpState(&state); + EXPECT_EQ(ERROR_NONE, ret); + EXPECT_EQ(state, true); +} + +TEST(NetworkState, StartTCPDump_n) +{ + error_e ret = ERROR_NONE; + NetworkState mgr; + Wifi wifi_mgr; + bool state; + + ret = mgr.StartTCPDump(); + EXPECT_EQ(ERROR_NONE, ret); + + sleep(1); + ret = mgr.GetTCPDumpState(&state); + EXPECT_EQ(ERROR_NONE, ret); + EXPECT_NE(state, false); + + wifi_mgr.LoadDriver(false); +} + +TEST(NetworkState, StopTCPDump_p) +{ + error_e ret = ERROR_NONE; + NetworkState mgr; + bool state; + + ret = mgr.StopTCPDump(); + EXPECT_EQ(ERROR_NONE, ret); + + sleep(1); + ret = mgr.GetTCPDumpState(&state); + EXPECT_EQ(ERROR_NONE, ret); + EXPECT_EQ(state, false); +} + +TEST(NetworkState, StopTCPDump_n) +{ + error_e ret = ERROR_NONE; + NetworkState mgr; + bool state; + + ret = mgr.StopTCPDump(); + EXPECT_EQ(ERROR_NONE, ret); + + sleep(1); + ret = mgr.GetTCPDumpState(&state); + EXPECT_EQ(ERROR_NONE, ret); + EXPECT_NE(state, true); +} +TEST(NetworkState, PreferredIpv6Address_n) +{ + error_e ret = ERROR_NONE; + NetworkState mgr; + const char *profile = "gtest"; + char address[256]; + + ret = mgr.PreferredIpv6Address(profile, address); + EXPECT_NE(ERROR_NONE, ret); +} + +TEST(VpnTest, vpn_init_p) +{ + error_e ret = ERROR_NONE; + Vpnsvc mgr; + const char *iface_name = "tun0"; + int iface_name_len = 4; + int result; + int h_index; + char h_name[256]; + + ret = mgr.vpn_init(iface_name, iface_name_len, &result, &h_index, h_name); + EXPECT_EQ(ERROR_NONE, ret); + EXPECT_EQ(result, VPNSVC_ERROR_NONE); +} + +TEST(VpnTest, vpn_init_n) +{ + error_e ret = ERROR_NONE; + Vpnsvc mgr; + const char *iface_name = "gtest"; + int iface_name_len = 5; + int result; + int h_index; + char h_name[256]; + + ret = mgr.vpn_init(iface_name, iface_name_len, &result, &h_index, h_name); + EXPECT_EQ(ERROR_NONE, ret); + EXPECT_EQ(result, false); +} + +TEST(VpnTest, vpn_deinit_p) +{ + error_e ret = ERROR_NONE; + Vpnsvc mgr; + const char *dev_name = "tun0"; + int result; + + ret = mgr.vpn_deinit(dev_name, &result); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(VpnTest, vpn_deinit_n) +{ + error_e ret = ERROR_NONE; + Vpnsvc mgr; + const char *dev_name = "gtest"; + int result; + + ret = mgr.vpn_deinit(dev_name, &result); + EXPECT_EQ(ERROR_NONE, ret); + EXPECT_EQ(result, false); +} + +TEST(VpnTest, vpn_protect_p) +{ + error_e ret = ERROR_NONE; + Vpnsvc mgr; + const char *iface_name = "tun0"; + int iface_name_len = 5; + int result; + int h_index; + char h_name[256]; + + ret = mgr.vpn_init(iface_name, iface_name_len, &result, &h_index, h_name); + EXPECT_EQ(ERROR_NONE, ret); + EXPECT_EQ(result, VPNSVC_ERROR_NONE); + + const char *dev_name = "tun0"; + + ret = mgr.vpn_protect(dev_name, &result); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(VpnTest, vpn_protect_n) +{ + error_e ret = ERROR_NONE; + Vpnsvc mgr; + const char *dev_name = "gtest"; + int result; + + ret = mgr.vpn_deinit(dev_name, &result); + EXPECT_EQ(ERROR_NONE, ret); + EXPECT_NE(VPNSVC_ERROR_NONE, result); +} + +TEST(VpnTest, vpn_up_p) +{ + error_e ret = ERROR_NONE; + Vpnsvc mgr; + const char *iface_name = "wlan0"; + int result; + + ret = mgr.vpn_up(iface_name, &result); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(VpnTest, vpn_up_n) +{ + error_e ret = ERROR_NONE; + Vpnsvc mgr; + const char *iface_name = "wlan0"; + int result; + + ret = mgr.vpn_up(iface_name, &result); + EXPECT_EQ(ERROR_NONE, ret); + EXPECT_NE(VPNSVC_ERROR_NONE, result); +} + +TEST(VpnTest, vpn_down_p) +{ + error_e ret = ERROR_NONE; + Vpnsvc mgr; + const char *iface_name = "wlan0"; + int result; + + ret = mgr.vpn_up(iface_name, &result); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(VpnTest, vpn_down_n) +{ + error_e ret = ERROR_NONE; + Vpnsvc mgr; + const char *iface_name = "wlan0"; + int result; + + ret = mgr.vpn_up(iface_name, &result); + EXPECT_EQ(ERROR_NONE, ret); + EXPECT_NE(VPNSVC_ERROR_NONE, result); +} + +TEST(VpnTest, vpn_block_networks_p) +{ + error_e ret = ERROR_NONE; + Vpnsvc mgr; + int result; + GVariantBuilder nets_builder; + GVariant *nets_param_vpn; + GVariant *nets_param_orig; + + g_variant_builder_init(&nets_builder, G_VARIANT_TYPE("a{si}")); + g_variant_builder_add(&nets_builder, "{si}", "1.1.1.1", 24); + nets_param_vpn = g_variant_builder_end(&nets_builder); + + g_variant_builder_init(&nets_builder, G_VARIANT_TYPE("a{si}")); + g_variant_builder_add(&nets_builder, "{si}", "2.2.2.2", 24); + nets_param_orig = g_variant_builder_end(&nets_builder); + + ret = mgr.vpn_block_networks(nets_param_vpn, 1, nets_param_orig, 1, &result); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(VpnTest, vpn_unblock_networks_p) +{ + error_e ret = ERROR_NONE; + Vpnsvc mgr; + int result; + + ret = mgr.vpn_unblock_networks(&result); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(VpnTest, vpn_update_settings_p) +{ + error_e ret = ERROR_NONE; + Vpnsvc mgr; + int iface_index = 1; + const char *local_ip = "192.168.0.2"; + const char *remote_ip = "192.168.0.3"; + int mtu = 10; + int result; + + ret = mgr.vpn_update_settings(iface_index, local_ip, + remote_ip, mtu, &result); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(VpnTest, vpn_update_settings_n) +{ + error_e ret = ERROR_NONE; + Vpnsvc mgr; + int result; + + ret = mgr.vpn_update_settings(0, NULL, NULL, 0, &result); + EXPECT_EQ(ERROR_NONE, ret); + EXPECT_NE(VPNSVC_ERROR_NONE, result); +} + +TEST(VpnTest, vpn_add_route_p) +{ + error_e ret = ERROR_NONE; + Vpnsvc mgr; + const char *iface_name = "wlan0"; + const char *route = "gtest"; + int prefix = 24; + int result; + + ret = mgr.vpn_add_route(iface_name, route, prefix, &result); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(VpnTest, vpn_add_route_n) +{ + error_e ret = ERROR_NONE; + Vpnsvc mgr; + const char *iface_name = "wlan0"; + const char *route = "gtest"; + int prefix = 24; + int result; + + ret = mgr.vpn_add_route(iface_name, route, prefix, &result); + EXPECT_EQ(ERROR_NONE, ret); + EXPECT_NE(VPNSVC_ERROR_NONE, result); +} + +TEST(VpnTest, vpn_remove_route_p) +{ + error_e ret = ERROR_NONE; + Vpnsvc mgr; + const char *iface_name = "wlan0"; + const char *route = "gtest"; + int prefix = 24; + int result; + + ret = mgr.vpn_add_route(iface_name, route, prefix, &result); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(VpnTest, vpn_remove_route_n) +{ + error_e ret = ERROR_NONE; + Vpnsvc mgr; + const char *iface_name = "wlan0"; + const char *route = "gtest"; + int prefix = 24; + int result; + + ret = mgr.vpn_add_route(iface_name, route, prefix, &result); + EXPECT_EQ(ERROR_NONE, ret); + EXPECT_NE(VPNSVC_ERROR_NONE, result); +} + +TEST(VpnTest, vpn_add_dns_server_p) +{ + error_e ret = ERROR_NONE; + Vpnsvc mgr; + const char *iface_name = "wlan0"; + const char *dns_server = "1.1.1.1"; + int result; + + ret = mgr.vpn_add_dns_server(iface_name, dns_server, &result); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(VpnTest, vpn_add_dns_server_n) +{ + error_e ret = ERROR_NONE; + Vpnsvc mgr; + const char *iface_name = "wlan0"; + const char *dns_server = "1.1.1.1"; + int result; + + ret = mgr.vpn_add_dns_server(iface_name, dns_server, &result); + EXPECT_EQ(ERROR_NONE, ret); + EXPECT_NE(VPNSVC_ERROR_NONE, result); +} + +TEST(WifiTest, GetWifiState_p) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + char state[256]; + + ret = mgr.GetWifiState(state); + EXPECT_EQ(ERROR_NONE, ret); + +} + +TEST(WifiTest, IsIpConflictDetectEnabled_p) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + bool state; + + ret = mgr.IsIpConflictDetectEnabled(&state); + EXPECT_EQ(ERROR_NONE, ret); + +} + +TEST(WifiTest, SetBgscan_p) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + int scan_mode = 1; + + ret = mgr.SetBgscan(scan_mode); + EXPECT_EQ(ERROR_NONE, ret); + +} + +TEST(WifiTest, GetAutoscan_p) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + bool state; + + ret = mgr.GetAutoscan(&state); + EXPECT_EQ(ERROR_NONE, ret); + +} + +TEST(WifiTest, GetIpConflictState_p) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + int state; + + ret = mgr.GetIpConflictState(&state); + EXPECT_EQ(ERROR_NONE, ret); + +} + +TEST(WifiTest, GetIpConflictPeriod_p) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + int period; + + ret = mgr.GetIpConflictPeriod(&period); + EXPECT_EQ(ERROR_NONE, ret); + +} + +TEST(WifiTest, GetAutoscanmode_p) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + int autoscanmode; + + ret = mgr.GetAutoscanmode(&autoscanmode); + EXPECT_EQ(ERROR_NONE, ret); + +} + +TEST(WifiTest, NetlinkScan_p) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + const char *ssid = "gtest"; + + ret = mgr.NetlinkScan(ssid); + EXPECT_EQ(ERROR_NONE, ret); + +} + +TEST(WifiTest, RequestWpsConnect_p) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + const char *param = "PBC"; + + ret = mgr.RequestWpsConnect(param); + EXPECT_EQ(ERROR_NONE, ret); + +} + +TEST(WifiTest, GetPasspoint_p) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + int enable; + + ret = mgr.GetPasspoint(&enable); + EXPECT_EQ(ERROR_NONE, ret); + +} + +TEST(WifiTest, SetPasspoint_p) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + int enable = 0; + + ret = mgr.SetPasspoint(enable); + EXPECT_EQ(ERROR_NONE, ret); + +} + +TEST(WifiTest, GetConfigIds_p) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + + ret = mgr.GetConfigIds(); + EXPECT_EQ(ERROR_NONE, ret); + +} + +TEST(WifiTest, SaveConfiguration_p) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + const char *config_id = "gtest"; + const char *name = "gtest"; + const char *ssid = "gtest"; + + ret = mgr.SaveConfiguration(config_id, name, ssid, NULL); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(WifiTest, SaveEapConfiguration_p) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + const char *config_id = "gtest"; + const char *name = "gtest"; + const char *ssid = "gtest"; + + ret = mgr.SaveEapConfiguration(config_id, name, ssid); + EXPECT_EQ(ERROR_NONE, ret); + +} + +TEST(WifiTest, SetIpConflictPeriod_p) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + unsigned int period = 25000; + + ret = mgr.SetIpConflictPeriod(period); + EXPECT_EQ(ERROR_NONE, ret); + +} + +TEST(WifiTest, SetIpConflictPeriod_n) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + unsigned int period = 10; + + ret = mgr.SetIpConflictPeriod(period); + EXPECT_NE(ERROR_NONE, ret); + +} + +TEST(WifiTest, LoadConfiguration_p) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + const char *config_id = "gtest_managed_none"; + const char *name = "gtest"; + const char *ssid = "gtest"; + + ret = mgr.SaveConfiguration(config_id, name, ssid, NULL); + EXPECT_EQ(ERROR_NONE, ret); + + sleep(2); + + ret = mgr.LoadConfiguration(config_id); + EXPECT_EQ(ERROR_NONE, ret); + +} + +TEST(WifiTest, LoadConfiguration_n) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + const char *config_id = "\0"; + + ret = mgr.LoadConfiguration(config_id); + EXPECT_NE(ERROR_NONE, ret); +} + +TEST(WifiTest, LoadEapConfiguration_p) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + const char *config_id = "gtest_managed_ieee8021x"; + const char *name = "gtest"; + const char *ssid = "gtest"; + + ret = mgr.SaveEapConfiguration(config_id, name, ssid); + EXPECT_EQ(ERROR_NONE, ret); + + sleep(2); + + ret = mgr.LoadEapConfiguration(config_id); + EXPECT_EQ(ERROR_NONE, ret); + +} + +TEST(WifiTest, LoadEapConfiguration_n) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + const char *config_id = "\0"; + + ret = mgr.LoadEapConfiguration(config_id); + EXPECT_NE(ERROR_NONE, ret); + +} + +TEST(WifiTest, RemoveConfiguration_p) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + const char *config_id = "gtest"; + + ret = mgr.RemoveConfiguration(config_id); + EXPECT_EQ(ERROR_NONE, ret); + +} + +TEST(WifiTest, RemoveConfiguration_n) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + const char *config_id = "\0"; + + ret = mgr.RemoveConfiguration(config_id); + EXPECT_NE(ERROR_NONE, ret); + +} + +TEST(WifiTest, SetConfigField_p) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + const char *config_id = "gtest"; + const char *key = "Identity"; + const char *value = "gtest"; + + ret = mgr.SetConfigField(config_id, key, value); + EXPECT_EQ(ERROR_NONE, ret); + +} + +TEST(WifiTest, SetConfigField_n) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + const char *config_id = "\0"; + const char *key = "\0"; + const char *value = "\0"; + + ret = mgr.SetConfigField(config_id, key, value); + EXPECT_NE(ERROR_NONE, ret); + +} + +TEST(WifiTest, GetConfigPassphrase_p) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + + const char *config_id = "gtest"; + const char *name = "gtest"; + const char *ssid = "gtest"; + const char *passphrase = "gtest"; + + ret = mgr.SaveConfiguration(config_id, name, ssid, passphrase); + EXPECT_EQ(ERROR_NONE, ret); + + char password[256]; + + ret = mgr.GetConfigPassphrase(config_id, password); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(WifiTest, GetConfigPassphrase_n) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + const char *config_id = "\0"; + char password[256]; + + ret = mgr.GetConfigPassphrase(config_id, password); + EXPECT_NE(ERROR_NONE, ret); + +} + +TEST(WifiTest, CreateEapConfig_p) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + const char *profile_name = + "/net/connman/service/wifi_e45d7553fd5b_gtest_managed_ieee8021x"; + + ret = mgr.CreateEapConfig(profile_name); + EXPECT_EQ(ERROR_NONE, ret); + +} + +TEST(WifiTest, CreateEapConfig_n) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + const char *profile_name = "/gtest"; + + ret = mgr.CreateEapConfig(profile_name); + EXPECT_NE(ERROR_NONE, ret); +} + +TEST(WifiTest, DeleteEapConfig_p) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + const char *profile_name = + "/net/connman/service/wifi_e45d7553fd5b_gtest_managed_ieee8021x"; + + ret = mgr.CreateEapConfig(profile_name); + EXPECT_EQ(ERROR_NONE, ret); + + ret = mgr.DeleteEapConfig(profile_name); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(WifiTest, IpConflictSetEnable_p) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + bool state; + + ret = mgr.IsIpConflictDetectEnabled(&state); + EXPECT_EQ(ERROR_NONE, ret); + + ret = mgr.IpConflictSetEnable(!state); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(WifiTest, ReqSimAuth_p) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + const unsigned char *rand_data = (unsigned char *)"01234567890123456"; + unsigned int length = 16; + bool result; + + ret = mgr.ReqSimAuth(rand_data, length, &result); + EXPECT_EQ(ERROR_NONE, ret); + +} + +TEST(WifiTest, ReqSimAuth_n) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + const unsigned char *rand_data = (unsigned char *)"\0"; + unsigned int length = 5; + bool result; + + ret = mgr.ReqSimAuth(rand_data, length, &result); + EXPECT_NE(ERROR_NONE, ret); + +} + +TEST(WifiTest, ReqAkaAuth_p) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + unsigned char rand[] = {65, 61, 62, 63, 64, 65, 66, 67, + 68, 69, 70, 71, 72, 73, 74, 75}; + unsigned char autn[] = {65, 61, 62, 63, 64, 65, 66, 67, + 68, 69, 70, 71, 72, 73, 74, 75}; + const unsigned char *rand_data = (unsigned char *)rand; + const unsigned char *auth_data = (unsigned char *)autn; + int length = 16; + bool result; + + ret = mgr.ReqAkaAuth(rand_data, length, auth_data, length, &result); + EXPECT_EQ(ERROR_NONE, ret); + +} + +TEST(WifiTest, ReqAkaAuth_n) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + const unsigned char *rand_data = (unsigned char *)"\0"; + const unsigned char *auth_data = (unsigned char *)"\0"; + int length = 5; + bool result; + + ret = mgr.ReqAkaAuth(rand_data, length, auth_data, length, &result); + EXPECT_NE(ERROR_NONE, ret); + +} + +TEST(WifiTest, CheckBlackList_p) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + const char *name = "gtest"; + const char *sec_type = "gtest"; + const char *eap = "gtest"; + bool allowed; + + ret = mgr.CheckBlackList(name, sec_type, eap, &allowed); + EXPECT_EQ(ERROR_NONE, ret); + +} + +TEST(WifiTest, TdlsDisconnect_p) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + int result; + const char *peer_mac_address = "00:00:00:00:00:00"; + + ret = mgr.TdlsDisconnect(peer_mac_address, &result); + EXPECT_EQ(ERROR_NONE, ret); + +} + +TEST(WifiTest, TdlsConnectedPeer_p) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + char peer_mac_address[256]; + + ret = mgr.TdlsConnectedPeer(peer_mac_address); + EXPECT_EQ(ERROR_NONE, ret); + +} + +TEST(WifiTest, TdlsDiscover_n) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + int result; + const char *peer_mac_address = "\0"; + + ret = mgr.TdlsDiscover(peer_mac_address, &result); + EXPECT_NE(ERROR_NONE, ret); + +} + +TEST(WifiTest, TdlsChannelSwitch_p) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + int result; + const char *peer_mac_address = "00:00:00:00:00:00"; + int freq = 2600; + + ret = mgr.TdlsChannelSwitch(peer_mac_address, freq, &result); + EXPECT_EQ(ERROR_NONE, ret); + EXPECT_NE(result, 0); +} + +TEST(WifiTest, TdlsChannelSwitch_n) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + int result; + const char *peer_mac_address = "\0"; + int freq = -1; + + ret = mgr.TdlsChannelSwitch(peer_mac_address, freq, &result); + EXPECT_EQ(ERROR_NONE, ret); + EXPECT_NE(result, 0); +} + +TEST(WifiTest, TdlsCancelChannelSwitch_p) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + int result; + const char *peer_mac_address = "00:00:00:00:00:00"; + + ret = mgr.TdlsCancelChannelSwitch(peer_mac_address, &result); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(WifiTest, TdlsCancelChannelSwitch_n) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + int result; + const char *peer_mac_address = "\0"; + + ret = mgr.TdlsCancelChannelSwitch(peer_mac_address, &result); + EXPECT_EQ(ERROR_NONE, ret); + EXPECT_NE(result, 0); +} + +TEST(WifiTest, AddVsie_p) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + int frame_id = 1; + const char *vsie = "dd050016328000"; + + ret = mgr.AddVsie(frame_id, vsie); + EXPECT_EQ(ERROR_NONE, ret); + +} + +TEST(WifiTest, AddVsie_n) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + int frame_id = -1; + const char *vsie = "\0"; + + ret = mgr.AddVsie(frame_id, vsie); + EXPECT_NE(ERROR_NONE, ret); +} + +TEST(WifiTest, GetVsie_p) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + int frame_id = 1; + char vsie[256]; + + ret = mgr.GetVsie(frame_id, vsie); + EXPECT_EQ(ERROR_NONE, ret); + +} + +TEST(WifiTest, GetVsie_n) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + int frame_id = -1; + char vsie[256]; + + ret = mgr.GetVsie(frame_id, vsie); + EXPECT_NE(ERROR_NONE, ret); + +} + +TEST(WifiTest, RemoveVsie_p) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + int frame_id = 1; + const char *vsie = "dd050016328000"; + + ret = mgr.RemoveVsie(frame_id, vsie); + EXPECT_EQ(ERROR_NONE, ret); + +} + +TEST(WifiTest, RemoveVsie_n) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + int frame_id = -1; + const char *vsie = "\0"; + + ret = mgr.RemoveVsie(frame_id, vsie); + EXPECT_NE(ERROR_NONE, ret); + +} + +TEST(WifiTest, EncryptPassphrase_p) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + const char *passphrase = "gtest"; + char *enc_data = NULL; + + ret = mgr.EncryptPassphrase(&enc_data, passphrase); + free(enc_data); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(WifiTest, EncryptPassphrase_n) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + const char *passphrase = "\0"; + char *enc_data = NULL; + + ret = mgr.EncryptPassphrase(&enc_data, passphrase); + free(enc_data); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(WifiTest, DecryptPassphrase_p) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + + const char *passphrase = "0123456789"; + char *enc_data = NULL; + char *passphrase1 = NULL; + + ret = mgr.EncryptPassphrase(&enc_data, passphrase); + EXPECT_EQ(ERROR_NONE, ret); + ret = mgr.DecryptPassphrase(enc_data, &passphrase1); + std::cerr << "decrypted password = " << passphrase1; + std::cerr << " " << "expected = " << passphrase << endl; + EXPECT_EQ(!strcmp(passphrase1, passphrase), true); + + free(enc_data); + free(passphrase1); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(WifiTest, DecryptPassphrase_n) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + char *passphrase = NULL; + const char enc_data[] = "\0"; + + ret = mgr.DecryptPassphrase(enc_data, &passphrase); + free(passphrase); + EXPECT_NE(ERROR_NONE, ret); +} + +TEST(WifiTest, Stop_n) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + + ret = mgr.RemoveDriver(); + EXPECT_EQ(ERROR_NONE, ret); + + sleep(5); + + ret = mgr.Stop("gtest"); + EXPECT_NE(ERROR_NONE, ret); +} + +TEST(WifiTest, Start_p) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + + ret = mgr.Start("softap"); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(WifiTest, Stop_p) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + + sleep(2); + ret = mgr.Stop("softap"); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(WifiTest, Start_n) +{ + error_e ret = ERROR_NONE; + Wifi mgr; + + ret = mgr.Start("gtest"); + EXPECT_NE(ERROR_NONE, ret); +} + +int main(int argc, char **argv) +{ + InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/gtest/vpn.cpp b/gtest/vpn.cpp new file mode 100644 index 0000000..b0c56a7 --- /dev/null +++ b/gtest/vpn.cpp @@ -0,0 +1,369 @@ +/* + * Copyright (c) 2017 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 +#include +#include +#include +#include +#include +#include +#include + +#include "vpn.h" + +Vpnsvc::Vpnsvc() +{ + Create(); +} + +Vpnsvc::~Vpnsvc() +{ + Destroy(); +} + +error_e Vpnsvc::vpn_init(const char *iface_name, int iface_name_len, int *result, + int *h_index, char *h_name) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + GError *g_error = NULL; + GUnixFDList *fd_list = NULL; + int iface_fd = 0; + + fd_list = g_unix_fd_list_new(); + if (fd_list == NULL) { + GLOGD("g_unix_fd_list_new() failed!"); + return ERROR_OPERATION_FAILED ; + } + + if ((iface_fd = open("/dev/net/tun", O_RDWR)) < 0) { + GLOGD("tun device open fail\n"); + return ERROR_OPERATION_FAILED; + } + + g_unix_fd_list_append(fd_list, iface_fd, &g_error); + if (g_error != NULL) { + close(iface_fd); + return ERROR_OPERATION_FAILED; + } + + message = InvokeMethod_with_fd(fd_list, + NETCONFIG_SERVICE, + NETCONFIG_VPNSVC_PATH, + NETCONFIG_VPNSVC_INTERFACE, + VPN_INIT, + g_variant_new("(su)", iface_name, iface_name_len), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + close(iface_fd); + return error; + } + + g_variant_get(message, "(iis)", result, h_index, h_name); + g_variant_unref(message); + close(iface_fd); + + return ERROR_NONE; +} + +error_e Vpnsvc::vpn_deinit(const char *dev_name, int *result) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_VPNSVC_PATH, + NETCONFIG_VPNSVC_INTERFACE, + VPN_DEINIT, + g_variant_new("(s)", dev_name), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(i)", result); + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Vpnsvc::vpn_protect(const char *dev_name, int *result) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + GError *g_error = NULL; + GUnixFDList *fd_list = NULL; + int iface_fd = 0; + + fd_list = g_unix_fd_list_new(); + if (fd_list == NULL) { + GLOGD("g_unix_fd_list_new() failed!"); + return ERROR_OPERATION_FAILED ; + } + + if ((iface_fd = open("/dev/net/tun", O_RDWR)) < 0) { + GLOGD("tun device open fail\n"); + return ERROR_OPERATION_FAILED; + } + + g_unix_fd_list_append(fd_list, iface_fd, &g_error); + if (g_error != NULL) { + close(iface_fd); + return ERROR_OPERATION_FAILED; + } + + message = InvokeMethod_with_fd(fd_list, + NETCONFIG_SERVICE, + NETCONFIG_VPNSVC_PATH, + NETCONFIG_VPNSVC_INTERFACE, + VPN_PROTECT, + g_variant_new("(s)", dev_name), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + close(iface_fd); + return error; + } + + g_variant_get(message, "(i)", result); + g_variant_unref(message); + close(iface_fd); + + return ERROR_NONE; +} + +error_e Vpnsvc::vpn_up(const char *iface_name, int *result) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_VPNSVC_PATH, + NETCONFIG_VPNSVC_INTERFACE, + VPN_UP, + g_variant_new("(s)", iface_name), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(i)", result); + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Vpnsvc::vpn_down(const char *iface_name, int *result) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_VPNSVC_PATH, + NETCONFIG_VPNSVC_INTERFACE, + VPN_DOWN, + g_variant_new("(s)", iface_name), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(i)", result); + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Vpnsvc::vpn_block_networks(GVariant *nets_vpn, int nr_nets_vpn, + GVariant *nets_orig, int nr_nets_orig, int *result) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_VPNSVC_PATH, + NETCONFIG_VPNSVC_INTERFACE, + VPN_BLOCK_NETWORKS, + g_variant_new("(vuvu)", nets_vpn, nr_nets_vpn, + nets_orig, nr_nets_orig), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(i)", result); + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Vpnsvc::vpn_unblock_networks(int *result) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_VPNSVC_PATH, + NETCONFIG_VPNSVC_INTERFACE, + VPN_UNBLOCK_NETWORKS, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(i)", result); + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Vpnsvc::vpn_update_settings(int iface_index, const char *local_ip, + const char *remote_ip, int mtu, int *result) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_VPNSVC_PATH, + NETCONFIG_VPNSVC_INTERFACE, + VPN_UPDATE_SETTINGS, + g_variant_new("(issu)", iface_index, local_ip, + remote_ip, mtu), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(i)", result); + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Vpnsvc::vpn_add_route(const char *iface_name, const char *route, int prefix, + int *result) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_VPNSVC_PATH, + NETCONFIG_VPNSVC_INTERFACE, + VPN_ADD_ROUTE, + g_variant_new("(ssi)", iface_name, route, prefix), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(i)", result); + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Vpnsvc::vpn_remove_route(const char *iface_name, const char *route, int prefix, + int *result) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_VPNSVC_PATH, + NETCONFIG_VPNSVC_INTERFACE, + VPN_REMOVE_ROUTE, + g_variant_new("(ssi)", iface_name, route, prefix), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(i)", result); + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Vpnsvc::vpn_add_dns_server(const char* iface_name, const char *dns_server, + int *result) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_VPNSVC_PATH, + NETCONFIG_VPNSVC_INTERFACE, + VPN_ADD_DNS_SERVER, + g_variant_new("(ss)", iface_name, dns_server), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(i)", result); + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Vpnsvc::vpn_remove_dns_server(const char* iface_name, const char *dns_server, + int *result) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_VPNSVC_PATH, + NETCONFIG_VPNSVC_INTERFACE, + VPN_REMOVE_DNS_SERVER, + g_variant_new("(ss)", iface_name, dns_server), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(i)", result); + g_variant_unref(message); + + return ERROR_NONE; +} + diff --git a/gtest/vpn.h b/gtest/vpn.h new file mode 100644 index 0000000..a123bf7 --- /dev/null +++ b/gtest/vpn.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2017 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 __VPN_H__ +#define __VPN_H__ + +#include "vpn.h" +#include "gdbus.h" + +class Vpnsvc:public GDbus { +public: + Vpnsvc(); + ~Vpnsvc(); + + error_e vpn_init(const char *iface_name, int iface_name_len, int *result, + int *h_index, char *h_name); + error_e vpn_deinit(const char *dev_name, int *result); + error_e vpn_protect(const char *dev_name, int *result); + error_e vpn_up(const char *iface_name, int *result); + error_e vpn_down(const char *iface_name, int *result); + error_e vpn_block_networks(GVariant *nets_vpn, int nr_nets_vpn, + GVariant *nets_orig, int nr_nets_orig, int *result); + error_e vpn_unblock_networks(int *result); + error_e vpn_update_settings(int iface_index, const char *local_ip, + const char *remote_ip, int mtu, int *result); + error_e vpn_add_route(const char *iface_name, const char *route, int prefix, + int *result); + error_e vpn_remove_route(const char *iface_name, const char *route, int prefix, + int *result); + error_e vpn_add_dns_server(const char* iface_name, const char *dns_server, + int *result); + error_e vpn_remove_dns_server(const char* iface_name, const char *dns_server, + int *result); +}; + + +#endif /* __VPN_H__ */ diff --git a/gtest/wifi.cpp b/gtest/wifi.cpp new file mode 100644 index 0000000..9c2cd11 --- /dev/null +++ b/gtest/wifi.cpp @@ -0,0 +1,1082 @@ +/* + * Copyright (c) 2017 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 +#include +#include +#include +#include +#include + +#include "wifi.h" + +Wifi::Wifi() +{ + Create(); +} + +Wifi::~Wifi() +{ + Destroy(); +} + +error_e Wifi::GetWifiState(char *state) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, + GET_WIFI_STATE, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(s)", state); + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Wifi::IsIpConflictDetectEnabled(bool *state) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, + IS_IP_CONFLICT_DETECT_ENABLED, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(b)", state); + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Wifi::SetBgscan(int scan_mode) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, + SET_BGSCAN, + g_variant_new("(u)", scan_mode), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Wifi::GetAutoscan(bool *state) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, + GET_AUTOSCAN, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(b)", state); + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Wifi::GetIpConflictState(int *state) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, + GET_IP_CONFLICT_STATE, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(u)", state); + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Wifi::GetIpConflictPeriod(int *period) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, + GET_IP_CONFLICT_PERIOD, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(u)", period); + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Wifi::GetAutoscanmode(int *autoscanmode) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, + GET_AUTOSCANMODE, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(u)", autoscanmode); + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Wifi::NetlinkScan(const char *ssid) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + GVariantBuilder *builder; + GVariant *params = NULL; + + builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); + if (ssid[0] != '\0') { + g_variant_builder_add(builder, "{sv}", "SSID", g_variant_new_string(ssid)); + } else { + return ERROR_INVALID_PARAMETER; + } + + params = g_variant_new("(@a{sv})", g_variant_builder_end(builder)); + g_variant_builder_unref(builder); + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, + NETLINK_SCAN, + params, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Wifi::RequestWpsConnect(const char *param) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, + REQUEST_WPS_CONNECT, + g_variant_new("(s)", param), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_unref(message); + + return ERROR_NONE; +} +error_e Wifi::GetPasspoint(int *enable) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, + GET_PASSPOINT, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(i)", enable); + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Wifi::SetPasspoint(int enable) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, + SET_PASSPOINT, + g_variant_new("(i)", enable), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Wifi::GetConfigIds(void) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, + GET_CONFIGIDS, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Wifi::SaveConfiguration(const char *config_id, const char *name, + const char *ssid, const char *passphrase) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + GVariantBuilder *b = NULL; + GVariant *params = NULL; + + b = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); + g_variant_builder_add(b, "{sv}", "Name", g_variant_new_string(name)); + g_variant_builder_add(b, "{sv}", "SSID", g_variant_new_string(ssid)); + if (passphrase != NULL) + g_variant_builder_add(b, "{sv}", "Passphrase", g_variant_new_string(passphrase)); + params = g_variant_new("(s@a{sv})", config_id, g_variant_builder_end(b)); + g_variant_builder_unref(b); + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, + SAVE_CONFIGURATION, + params, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Wifi::SaveEapConfiguration(const char *config_id, const char *name, + const char *ssid) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + GVariantBuilder *b = NULL; + GVariant *params = NULL; + + b = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); + g_variant_builder_add(b, "{sv}", "Name", g_variant_new_string(name)); + g_variant_builder_add(b, "{sv}", "SSID", g_variant_new_string(ssid)); + params = g_variant_new("(s@a{sv})", config_id, g_variant_builder_end(b)); + g_variant_builder_unref(b); + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, + SAVE_EAP_CONFIGURATION, + params, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Wifi::SetIpConflictPeriod(unsigned int time) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, + SET_IP_CONFLICT_PERIOD, + g_variant_new("(u)", time), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Wifi::RemoveConfiguration(const char *config_id) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, + REMOVE_CONFIGURATION, + g_variant_new("(s)", config_id), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Wifi::LoadConfiguration(const char *config_id) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, + LOAD_CONFIGURATION, + g_variant_new("(s)", config_id), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Wifi::LoadEapConfiguration(const char *config_id) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, + LOAD_EAP_CONFIGURATION, + g_variant_new("(s)", config_id), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Wifi::SetConfigField(const char *config_id, const char *key, + const char *value) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, + SET_CONFIG_FIELD, + g_variant_new("(sss)", config_id, key, value), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Wifi::GetConfigPassphrase(const char *config_id, char *password) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, + GET_CONFIG_PASSPHRASE, + g_variant_new("(s)", config_id), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(s)", password); + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Wifi::CreateEapConfig(const char *profile_name) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + GVariant *params = NULL; + GVariantBuilder *builder; + + builder = g_variant_builder_new(G_VARIANT_TYPE("a{ss}")); + g_variant_builder_add(builder, "{ss}", "Type", "wifi"); + g_variant_builder_add(builder, "{ss}", + "Name", "gtest"); + + params = g_variant_new("(o@a{ss})", (gchar *)profile_name, + g_variant_builder_end(builder)); + + g_variant_builder_unref(builder); + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, + CREATE_EAP_CONFIG, + params, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Wifi::DeleteEapConfig(const char *profile_name) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, + DELETE_EAP_CONFIG, + g_variant_new("(s)", profile_name), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Wifi::IpConflictSetEnable(bool detect) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, + IP_CONFLICT_SET_ENABLE, + g_variant_new("(b)", detect), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Wifi::GetSimImsi(char *imsi) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, + GET_SIM_IMSI, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(s)", imsi); + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Wifi::ReqSimAuth(const unsigned char *rand_data, unsigned int length, + bool *result) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + GVariantBuilder *b; + GVariant *v; + b = g_variant_builder_new(G_VARIANT_TYPE("ay")); + for(unsigned int i = 0;i < length;i++) + g_variant_builder_add(b, "y", rand_data[i]); + + v = g_variant_new("(ay)", b); + g_variant_builder_unref(b); + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, + REQ_SIM_AUTH, + v, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(b)", result); + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Wifi::ReqAkaAuth(const unsigned char *rand_data, int rand_length, + const unsigned char *autn_data, int auth_length, bool *result) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + GVariantBuilder *b1, *b2; + GVariant *v; + b1 = g_variant_builder_new(G_VARIANT_TYPE("ay")); + for(int i = 0;i < rand_length;i++) + g_variant_builder_add(b1, "y", rand_data[i]); + + b2 = g_variant_builder_new(G_VARIANT_TYPE("ay")); + for(int i = 0;i < auth_length;i++) + g_variant_builder_add(b2, "y", autn_data[i]); + + v = g_variant_new("(@ay@ay)", g_variant_builder_end(b1), g_variant_builder_end(b2)); + + g_variant_builder_unref(b1); + g_variant_builder_unref(b2); + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, + REQ_AKA_AUTH, + v, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(b)", result); + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Wifi::GetSimAuth(const unsigned char *auth_data, unsigned int length) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + GVariantBuilder *b; + GVariant *v; + b = g_variant_builder_new(G_VARIANT_TYPE("ay")); + for(unsigned int i = 0;i < length;i++) + g_variant_builder_add(b, "y", auth_data[i]); + + v = g_variant_new("(ay)", b); + g_variant_builder_unref(b); + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, + GET_SIM_AUTH, + v, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Wifi::CheckBlackList(const char *name, const char *sec_type, + const char *eap, bool *allowed) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, + CHECK_BLACKLIST, + g_variant_new("(sss)", name, sec_type, eap), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(b)", allowed); + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Wifi::TdlsDisconnect(const char *peer_mac_address, int *result) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, + TDLS_DISCONNECT, + g_variant_new("(s)", peer_mac_address), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(i)", result); + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Wifi::TdlsConnectedPeer(char *peer_mac_address) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, + TDLS_CONNECTED_PEER, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(s)", peer_mac_address); + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Wifi::TdlsConnect(const char *peer_mac_address, int *result) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, + TDLS_CONNECT, + g_variant_new("(s)", peer_mac_address), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(i)", result); + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Wifi::TdlsDiscover(const char *peer_mac_address, int *result) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, + TDLS_DISCOVER, + g_variant_new("(s)", peer_mac_address), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(i)", result); + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Wifi::TdlsChannelSwitch(const char *peer_mac_address, int freq, int *result) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, + TDLS_CHANNEL_SWITCH, + g_variant_new("(si)", peer_mac_address, freq), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(i)", result); + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Wifi::TdlsCancelChannelSwitch(const char *peer_mac_address, int *result) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, + TDLS_CANCEL_CHANNEL_SWITCH, + g_variant_new("(s)", peer_mac_address), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(i)", result); + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Wifi::AddVsie(int frame_id, const char *vsie) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, + ADD_VSIE, + g_variant_new("(is)", frame_id, vsie), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Wifi::GetVsie(int frame_id, char *vsie) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, + GET_VSIE, + g_variant_new("(i)", frame_id), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(s)", vsie); + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Wifi::RemoveVsie(int frame_id, const char *vsie) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, + REMOVE_VSIE, + g_variant_new("(is)", frame_id, vsie), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Wifi::EncryptPassphrase(char **enc_data, const char *passphrase) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, + ENCRYPT_PASSPHRASE, + g_variant_new("(s)", passphrase), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(s)", enc_data); + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Wifi::DecryptPassphrase(const char *enc_data, char **passphrase) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, + DECRYPT_PASSPHRASE, + g_variant_new("(s)", enc_data), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(s)", passphrase); + g_variant_unref(message); + + return ERROR_NONE; +} + + +error_e Wifi::Stop(const char *device) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_FIRMWARE_INTERFACE, + WIFI_FIRMWARE_STOP, + g_variant_new("(s)", device), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Wifi::Start(const char *device) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_FIRMWARE_INTERFACE, + WIFI_FIRMWARE_START, + g_variant_new("(s)", device), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Wifi::LoadDriver(bool device_picker_test) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, + LOAD_DRIVER, + g_variant_new("(b)", device_picker_test), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Wifi::RemoveDriver() +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, + REMOVE_DRIVER, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_unref(message); + + return ERROR_NONE; +} diff --git a/gtest/wifi.h b/gtest/wifi.h new file mode 100644 index 0000000..ef0200c --- /dev/null +++ b/gtest/wifi.h @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2017 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 __WIFI_H__ +#define __WIFI_H__ + +#include "wifi.h" +#include "gdbus.h" + +class Wifi:public GDbus { +public: + Wifi(); + ~Wifi(); + +error_e GetWifiState(char *state); +error_e IsIpConflictDetectEnabled(bool *state); +error_e SetBgscan(int scan_mode); +error_e GetAutoscan(bool *state); +error_e GetIpConflictState(int *state); +error_e GetIpConflictPeriod(int *period); +error_e GetAutoscanmode(int *autoscanmode); +error_e NetlinkScan(const char *ssid); +error_e RequestWpsConnect(const char *param); +error_e GetPasspoint(int *enable); +error_e SetPasspoint(int enable); +error_e GetConfigIds(void); +error_e SaveConfiguration(const char *config_id, const char *name, + const char *ssid, const char *passphrase); +error_e SaveEapConfiguration(const char *config_id, const char *name, + const char *ssid); +error_e SetIpConflictPeriod(unsigned int time); +error_e RemoveConfiguration(const char *config_id); +error_e LoadConfiguration(const char *config_id); +error_e LoadEapConfiguration(const char *config_id); +error_e SetConfigField(const char *config_id, const char *key, + const char *value); +error_e GetConfigPassphrase(const char *config_id, char *password); +error_e CreateEapConfig(const char *profile_name); +error_e DeleteEapConfig(const char *profile_name); +error_e IpConflictSetEnable(bool detect); +error_e GetSimImsi(char *imsi); +error_e ReqSimAuth(const unsigned char *rand_data, unsigned int length, + bool *result); +error_e ReqAkaAuth(const unsigned char *rand_data, int rand_length, + const unsigned char *auth_data, int auth_length, bool *result); +error_e GetSimAuth(const unsigned char *auth_data, unsigned int length); +error_e CheckBlackList(const char *name, const char *sec_type, + const char *eap, bool *allowed); +error_e TdlsDisconnect(const char *peer_mac_address, int *result); +error_e TdlsConnectedPeer(char *peer_mac_address); +error_e TdlsConnect(const char *peer_mac_address, int *result); +error_e TdlsDiscover(const char *peer_mac_address, int *result); +error_e TdlsChannelSwitch(const char *peer_mac_address, int freq, int *result); +error_e TdlsCancelChannelSwitch(const char *peer_mac_address, int *result); +error_e AddVsie(int frame_id, const char *vsie); +error_e GetVsie(int frame_id, char *vsie); +error_e RemoveVsie(int frame_id, const char *vsie); +error_e EncryptPassphrase(char **enc_data, const char *passphrase); +error_e DecryptPassphrase(const char *enc_data, char **passphrase); +error_e Stop(const char *device); +error_e Start(const char *device); +error_e LoadDriver(bool device_picker_test); +error_e RemoveDriver(); +}; + + +#endif /* __WIFI_H__ */ diff --git a/src/ip-conflict-detect.c b/src/ip-conflict-detect.c index adb9124..4120481 100755 --- a/src/ip-conflict-detect.c +++ b/src/ip-conflict-detect.c @@ -485,7 +485,8 @@ gboolean handle_is_ip_conflict_detect_enabled(Wifi *wifi, GDBusMethodInvocation gboolean handle_set_ip_conflict_period(Wifi *wifi, GDBusMethodInvocation *context, guint initial_time) { g_return_val_if_fail(wifi != NULL, TRUE); - if (initial_time < MAX_ARP_SEND_TIME && initial_time > MIN_ARP_SEND_TIME) { + INFO("%d", initial_time); + if (initial_time > MAX_ARP_SEND_TIME || initial_time < MIN_ARP_SEND_TIME) { netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "Failed"); return TRUE;