From ec962ebce853356c4a513b86081befb830c8b3f3 Mon Sep 17 00:00:00 2001 From: Seonah Moon Date: Tue, 30 Jan 2018 20:27:54 +0900 Subject: [PATCH] Add unittest code Change-Id: I866158b0fa8d9403223834dcd7d520af11a4c414 --- include/mobileap_network.h | 1 - include/mobileap_notification.h | 1 - include/mobileap_softap.h | 1 - packaging/mobileap-agent.spec | 5 + src/gdbus/mobileap_dbus.c | 4 +- src/mobileap.c | 62 +++-- src/mobileap_bluetooth.c | 84 ++++-- src/mobileap_common.c | 87 +++--- src/mobileap_handler.c | 20 +- src/mobileap_iptables.c | 78 +++--- src/mobileap_network.c | 400 ++++++++------------------- src/mobileap_notification.c | 120 ++++---- src/mobileap_p2p.c | 91 +++--- src/mobileap_softap.c | 307 ++++++++++----------- src/mobileap_usb.c | 60 ++-- src/mobileap_wfd.c | 25 +- src/mobileap_wifi.c | 196 ++++++++----- unittest/CMakeLists.txt | 2 +- unittest/resource/dnsmasq.leases | 2 + unittest/unittest.cpp | 581 ++++++++++++++++++++++++++++++++++++++- unittest/unittest.h | 19 ++ unittest/unittest_common.cpp | 54 ++++ 22 files changed, 1399 insertions(+), 801 deletions(-) create mode 100644 unittest/resource/dnsmasq.leases create mode 100644 unittest/unittest_common.cpp diff --git a/include/mobileap_network.h b/include/mobileap_network.h index 062f4f8..d9e9f37 100644 --- a/include/mobileap_network.h +++ b/include/mobileap_network.h @@ -46,7 +46,6 @@ int _enable_ipv6(const char *if_name); #endif gboolean _add_route(const char *if_name, char *ip, mobile_ap_address_type_e address_type, int prefix); -gboolean _remove_route(const char *if_name, char *ip, mobile_ap_address_type_e address_type, int prefix); gboolean _add_address(const char *if_name, char *ip); gboolean _remove_address(const char *if_name, char *ip); diff --git a/include/mobileap_notification.h b/include/mobileap_notification.h index ea74e5a..f817281 100644 --- a/include/mobileap_notification.h +++ b/include/mobileap_notification.h @@ -54,6 +54,5 @@ int _create_connected_noti(mobile_ap_type_e type, int count); int _update_connected_noti(mobile_ap_type_e type, int count); int _delete_connected_noti(void); void _create_tethering_active_noti(void); -void _create_bt_tethering_active_noti(void); void _create_security_restriction_noti(mobile_ap_type_e type); #endif diff --git a/include/mobileap_softap.h b/include/mobileap_softap.h index 417478a..aa17b25 100755 --- a/include/mobileap_softap.h +++ b/include/mobileap_softap.h @@ -303,7 +303,6 @@ typedef struct { /* ssid : 32 key : 64 */ int _mh_core_enable_softap(const mobile_ap_type_e type, softap_settings_t *settings); int _mh_core_disable_softap(void); -int _mh_core_get_device_info(softap_device_info_t *di); int _mh_core_execute_dhcp_server(gchar *softap_rangestart, gchar *softap_rangestop); int _mh_core_terminate_dhcp_server(void); int _mh_core_enable_masquerade(const char *ext_if); diff --git a/packaging/mobileap-agent.spec b/packaging/mobileap-agent.spec index 70c9015..bb30ef7 100644 --- a/packaging/mobileap-agent.spec +++ b/packaging/mobileap-agent.spec @@ -163,6 +163,9 @@ mkdir -p %{buildroot}%{_datadir}/dbus-1/system-services/ cp %{SOURCE2} %{buildroot}%{_datadir}/dbus-1/system-services/org.tizen.MobileapAgent.service %if 0%{?gtests:1} cp %{_builddir}/%{name}-%{version}/unittest/gtest-mobileap-agent %{buildroot}%{_bindir} + +mkdir -p %{buildroot}/var/lib/misc +cp unittest/resource/dnsmasq.leases %{buildroot}/var/lib/misc %endif %post @@ -211,4 +214,6 @@ rm %{_bindir}/mobileap-agent %if 0%{?gtests:1} %files unittest %{_bindir}/gtest-mobileap-agent +%attr(755,nework_fw,nework_fw) +/var/lib/misc/dnsmasq.leases %endif diff --git a/src/gdbus/mobileap_dbus.c b/src/gdbus/mobileap_dbus.c index de23fc9..d80c6c8 100644 --- a/src/gdbus/mobileap_dbus.c +++ b/src/gdbus/mobileap_dbus.c @@ -86,6 +86,7 @@ static struct { } }; +//LCOV_EXCL_START static void network_technology_signal_handler(GDBusConnection *connection, const gchar *sender, const gchar *object_path, @@ -142,7 +143,7 @@ static void network_property_changed_signal_handler(GDBusConnection *connection, if (g_strcmp0(property, "ready") == 0) { if (network_cb) network_cb->connected(object_path); - }else if (g_strcmp0(property, "online") == 0) { + } else if (g_strcmp0(property, "online") == 0) { if (network_cb) network_cb->online(); } else if (g_strcmp0(property, "failure") == 0 || @@ -485,3 +486,4 @@ void mobileap_dbus_deinit(void) mobileap_dbus.connection = NULL; DBG("mobileap dbus deinit done"); } +//LCOV_EXCL_STOP diff --git a/src/mobileap.c b/src/mobileap.c index 3dd1b1b..c89faef 100755 --- a/src/mobileap.c +++ b/src/mobileap.c @@ -66,6 +66,7 @@ guint Added_sig_id = 0; guint Updated_sig_id = 0; guint deleted_sig_id = 0; +//LCOV_EXCL_START Tethering *_get_tethering_obj(void) { return tethering_obj; @@ -75,6 +76,7 @@ Softap *_get_softap_obj(void) { return softap_obj; } +//LCOV_EXCL_STOP gboolean _mobileap_set_state(int state) { @@ -84,7 +86,7 @@ gboolean _mobileap_set_state(int state) vconf_ret = vconf_set_int(VCONFKEY_MOBILE_HOTSPOT_MODE, mobileap_state); if (vconf_ret != 0) { - ERR("vconf_set_int is failed : %d\n", vconf_ret); + ERR("vconf_set_int is failed : %d\n", vconf_ret); //LCOV_EXCL_LINE return FALSE; } @@ -130,7 +132,7 @@ gboolean _mobileap_is_enabled_by_type(mobile_ap_type_e type) break; default: - ERR("Unknow type : %d\n", type); + ERR("Unknow type : %d\n", type); //LCOV_EXCL_LINE break; } @@ -145,7 +147,7 @@ gboolean _mobileap_clear_state(int state) vconf_ret = vconf_set_int(VCONFKEY_MOBILE_HOTSPOT_MODE, mobileap_state); if (vconf_ret != 0) { - ERR("vconf_set_int is failed : %d\n", vconf_ret); + ERR("vconf_set_int is failed : %d\n", vconf_ret); //LCOV_EXCL_LINE return FALSE; } @@ -158,35 +160,35 @@ gboolean _terminate_mobileap_agent(gpointer user_data) return FALSE; if (!_mobileap_is_disabled()) { - DBG("Tethering is enabled\n"); + DBG("Tethering is enabled\n"); //LCOV_EXCL_LINE return FALSE; } if (_is_trying_network_operation()) { - DBG("Network operation is going on\n"); + DBG("Network operation is going on\n"); //LCOV_EXCL_LINE return FALSE; } if (_is_trying_wifi_operation()) { - DBG("Wi-Fi operation is going on\n"); + DBG("Wi-Fi operation is going on\n"); //LCOV_EXCL_LINE return FALSE; } #ifndef TIZEN_FEATURE_HEADLESS if (_is_trying_bt_operation()) { - DBG("BT operation is going on\n"); + DBG("BT operation is going on\n"); //LCOV_EXCL_LINE return FALSE; } if (_is_trying_usb_operation()) { - DBG("USB operation is going on\n"); + DBG("USB operation is going on\n"); //LCOV_EXCL_LINE return FALSE; } #endif #ifdef TIZZEN_FEATURE_WIFI_DIRECT if (_is_trying_p2p_operation()) { - DBG("P2P operation is going on\n"); + DBG("P2P operation is going on\n"); //LCOV_EXCL_LINE return FALSE; } #endif @@ -207,9 +209,9 @@ void _block_device_sleep(void) ret = display_lock_state(LCD_OFF, STAY_CUR_STATE, 0); if (ret < 0) - ERR("PM control [ERROR] result = %d\n", ret); + ERR("PM control [ERROR] result = %d\n", ret); //LCOV_EXCL_LINE else - DBG("PM control [SUCCESS]\n"); + DBG("PM control [SUCCESS]\n"); //LCOV_EXCL_LINE #endif } @@ -222,9 +224,9 @@ void _unblock_device_sleep(void) ret = display_unlock_state(LCD_OFF, PM_SLEEP_MARGIN); if (ret < 0) - ERR("PM control [ERROR] result = %d\n", ret); + ERR("PM control [ERROR] result = %d\n", ret); //LCOV_EXCL_LINE else - DBG("PM control [SUCCESS]\n"); + DBG("PM control [SUCCESS]\n"); //LCOV_EXCL_LINE #endif } @@ -263,7 +265,7 @@ int _init_tethering(mobile_ap_address_type_e address_type) #endif } else { ret = MOBILE_AP_ERROR_INVALID_PARAM; - ERR("Invalid address type"); + ERR("Invalid address type"); //LCOV_EXCL_LINE } if (ret == MOBILE_AP_ERROR_NONE) @@ -282,7 +284,7 @@ gboolean _deinit_tethering(mobile_ap_address_type_e address_type) init_count--; return TRUE; } else if (init_count <= 0) { - ERR("Already deinitialized\n"); + ERR("Already deinitialized\n"); //LCOV_EXCL_LINE init_count = 0; return TRUE; } @@ -303,16 +305,16 @@ gboolean _deinit_tethering(mobile_ap_address_type_e address_type) } _close_ipv6_network(); #else - ERR("Not supported address type"); + ERR("Not supported address type"); //LCOV_EXCL_LINE #endif } else { - ERR("Invalid address type"); + ERR("Invalid address type"); //LCOV_EXCL_LINE } } idle_id = g_idle_add(_terminate_mobileap_agent, NULL); if (idle_id == 0) - ERR("g_idle_add is failed\n"); + ERR("g_idle_add is failed\n"); //LCOV_EXCL_LINE return TRUE; } @@ -335,7 +337,7 @@ static void __handle_dnsmasq_dhcp_status_changed_cb(GDBusConnection *connection, time_t tm; if (signal_name == NULL) { - ERR("singal name is NULL\n"); + ERR("singal name is NULL\n"); //LCOV_EXCL_LINE return; } g_variant_get(parameters, "(sss)", &ip_addr, &mac, &name); @@ -357,7 +359,7 @@ static void __handle_dnsmasq_dhcp_status_changed_cb(GDBusConnection *connection, info = (mobile_ap_station_info_t *)g_malloc(sizeof(mobile_ap_station_info_t)); if (info == NULL) { - ERR("malloc failed\n"); + ERR("malloc failed\n"); //LCOV_EXCL_LINE goto EXIT; } @@ -383,7 +385,7 @@ static void __handle_dnsmasq_dhcp_status_changed_cb(GDBusConnection *connection, time(&tm); info->tm = tm; if (_add_station_info(info) != MOBILE_AP_ERROR_NONE) { - ERR("_add_station_info is failed\n"); + ERR("_add_station_info is failed\n"); //LCOV_EXCL_LINE if (info) { g_free(info->hostname); g_free(info); @@ -400,10 +402,10 @@ static void __handle_dnsmasq_dhcp_status_changed_cb(GDBusConnection *connection, _send_dbus_station_info("DhcpConnected", info); } else if (!g_strcmp0(signal_name, "DhcpLeaseDeleted")) { - SDBG("DhcpLeaseDeleted signal : %s %s %s\n", ip_addr, mac, name); + SDBG("DhcpLeaseDeleted signal : %s %s %s\n", ip_addr, mac, name); //LCOV_EXCL_LINE _remove_station_info(ip_addr, _slist_find_station_by_ip_addr); } else { - SDBG("UNKNOWN member signal\n"); + SDBG("UNKNOWN member signal\n"); //LCOV_EXCL_LINE } EXIT: g_free(ip_addr); @@ -422,25 +424,25 @@ static void on_bus_acquired_cb(GDBusConnection *connection, const gchar *name, manager_server = g_dbus_object_manager_server_new(TETHERING_SERVICE_OBJECT_PATH); if (manager_server == NULL) { - DBG("Manager server not created."); + DBG("Manager server not created."); //LCOV_EXCL_LINE return; } tethering_obj = tethering_skeleton_new(); intf = G_DBUS_INTERFACE_SKELETON(tethering_obj); if (!g_dbus_interface_skeleton_export(intf, connection, TETHERING_SERVICE_OBJECT_PATH, NULL)) { - ERR("Export with path failed"); + ERR("Export with path failed"); //LCOV_EXCL_LINE } else { - DBG("Export sucessss"); + DBG("Export sucessss"); //LCOV_EXCL_LINE } softap_obj = softap_skeleton_new(); softap_intf = G_DBUS_INTERFACE_SKELETON(softap_obj); if (!g_dbus_interface_skeleton_export(softap_intf, connection, TETHERING_SERVICE_OBJECT_PATH, NULL)) { - ERR("Export with path failed"); + ERR("Export with path failed"); //LCOV_EXCL_LINE } else { - DBG("Export sucessss"); + DBG("Export sucessss"); //LCOV_EXCL_LINE } #ifndef TIZEN_FEATURE_HEADLESS g_signal_connect(tethering_obj, "handle-enable-wifi-tethering", @@ -590,8 +592,10 @@ static int __tethering_setup_gdbus(void) return 0; } +//LCOV_EXCL_START int mobileap_main(void) { +#ifndef TIZEN_FEATURE_UNITTEST int ret = 0; DBG("+\n"); @@ -667,8 +671,10 @@ int mobileap_main(void) g_bus_unown_name(owner_id); g_object_unref(manager_server); DBG("-\n"); +#endif return 0; } +//LCOV_EXCL_STOP gboolean _mobileap_get_ipv6_state(int state) { diff --git a/src/mobileap_bluetooth.c b/src/mobileap_bluetooth.c index 8b4742e..dd855bf 100755 --- a/src/mobileap_bluetooth.c +++ b/src/mobileap_bluetooth.c @@ -81,13 +81,14 @@ static __bt_remote_device_s *__find_bt_remote(const char *mac) } if (i == MOBILE_AP_MAX_BT_STA) { - SERR("Not found : %s\n", mac); + SERR("Not found : %s\n", mac); //LCOV_EXCL_LINE return NULL; } return &__bt_remote_devices[i]; } +//LCOV_EXCL_START static __bt_remote_device_s *__add_bt_remote(bt_device_info_s *info, const char *intf_name) { int i; @@ -129,7 +130,7 @@ static gboolean __del_bt_remote(const char *mac) } if (i == MOBILE_AP_MAX_BT_STA) { - SERR("Not found : %s\n", mac); + SERR("Not found : %s\n", mac); //LCOV_EXCL_LINE return FALSE; } @@ -144,6 +145,7 @@ static gboolean __del_bt_remote(const char *mac) return TRUE; } +//LCOV_EXCL_STOP static void __del_bt_remote_all(void) { @@ -173,7 +175,7 @@ static mobile_ap_error_code_e __init_bt(Tethering *obj, mobile_ap_address_type_e ret = bt_initialize(); if (ret != BT_ERROR_NONE) { - ERR("bt_initialize is failed : %d\n", ret); + ERR("bt_initialize is failed : %d\n", ret); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_RESOURCE; } @@ -185,7 +187,7 @@ static mobile_ap_error_code_e __init_bt(Tethering *obj, mobile_ap_address_type_e #endif if (ret != BT_ERROR_NONE) { - ERR("Failed to set callback for bt adapter: %d\n", ret); + ERR("Failed to set callback for bt adapter: %d\n", ret); //LCOV_EXCL_LINE bt_deinitialize(); return MOBILE_AP_ERROR_RESOURCE; } @@ -199,11 +201,11 @@ static void __deinit_bt(void) ret = bt_adapter_unset_state_changed_cb(); if (ret != BT_ERROR_NONE) - ERR("bt_adapter_unset_state_changed_cb is failed : %d\n", ret); + ERR("bt_adapter_unset_state_changed_cb is failed : %d\n", ret); //LCOV_EXCL_LINE ret = bt_deinitialize(); if (ret != BT_ERROR_NONE) - ERR("bt_deinitialize is failed : %d\n", ret); + ERR("bt_deinitialize is failed : %d\n", ret); //LCOV_EXCL_LINE return; } @@ -215,7 +217,7 @@ static gboolean __is_bt_adapter_on(void) ret = bt_adapter_get_state(&adapter_state); if (ret != BT_ERROR_NONE) { - ERR("bt_adapter_get_state is failed : %d\n", ret); + ERR("bt_adapter_get_state is failed : %d\n", ret); //LCOV_EXCL_LINE return FALSE; } @@ -225,6 +227,7 @@ static gboolean __is_bt_adapter_on(void) return FALSE; } +//LCOV_EXCL_START gboolean __bt_adapter_timeout_cb(gpointer data) { DBG("+\n"); @@ -243,7 +246,9 @@ gboolean __bt_adapter_timeout_cb(gpointer data) ERR("_enable_bt_tethering() is failed because of bt_adapter_eanbled() failed:n"); _mobileap_clear_state(MOBILE_AP_STATE_BT); __deinit_bt(); +#ifndef TIZEN_FEATURE_UNITTEST tethering_complete_enable_bt_tethering(obj, g_context, MOBILE_AP_ERROR_INTERNAL); +#endif g_context = NULL; _unblock_device_sleep(); DBG("-\n"); @@ -272,7 +277,7 @@ static mobile_ap_error_code_e __turn_on_bt_adapter(gpointer data) } if (ret != BT_ERROR_NONE && ret != BT_ERROR_ALREADY_DONE) { - ERR("bt_adapter_enable is failed : %d\n", ret); + ERR("bt_adapter_enable is failed : %d\n", ret); //LCOV_EXCL_LINE if (ret == BT_ERROR_PERMISSION_DENIED) return MOBILE_AP_ERROR_PERMISSION_DENIED; else @@ -281,6 +286,7 @@ static mobile_ap_error_code_e __turn_on_bt_adapter(gpointer data) return MOBILE_AP_ERROR_NONE; } +//LCOV_EXCL_STOP static mobile_ap_error_code_e __turn_on_bt_nap(Tethering *obj, mobile_ap_address_type_e address_type) { @@ -294,14 +300,14 @@ static mobile_ap_error_code_e __turn_on_bt_nap(Tethering *obj, mobile_ap_address bt_ret = bt_nap_set_connection_state_changed_cb(__bt_nap_connection_changed, (void *)obj); if (bt_ret != BT_ERROR_NONE) { - ERR("Failed to set callback function for bt nap state: %d\n", bt_ret); + ERR("Failed to set callback function for bt nap state: %d\n", bt_ret); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_RESOURCE; } bt_ret = bt_nap_activate(); if (bt_ret != BT_ERROR_NONE && bt_ret != BT_ERROR_ALREADY_DONE) { bt_nap_unset_connection_state_changed_cb(); - ERR("bt_nap_activate is failed : %d\n", bt_ret); + ERR("bt_nap_activate is failed : %d\n", bt_ret); //LCOV_EXCL_LINE if (bt_ret == BT_ERROR_PERMISSION_DENIED) return MOBILE_AP_ERROR_PERMISSION_DENIED; else @@ -317,13 +323,13 @@ static void __turn_off_bt_nap(void) bt_ret = bt_nap_deactivate(); if (bt_ret != BT_ERROR_NONE) - ERR("bt_nap_deactivate is failed : %d\n", bt_ret); + ERR("bt_nap_deactivate is failed : %d\n", bt_ret); //LCOV_EXCL_LINE else - DBG("bt_nap_deactivate is called\n"); + DBG("bt_nap_deactivate is called\n"); //LCOV_EXCL_LINE bt_ret = bt_nap_unset_connection_state_changed_cb(); if (bt_ret != BT_ERROR_NONE) - ERR("bt_nap_unset_connection_state_changed_cb is failed : %d\n", bt_ret); + ERR("bt_nap_unset_connection_state_changed_cb is failed : %d\n", bt_ret); //LCOV_EXCL_LINE return; } @@ -339,7 +345,7 @@ mobile_ap_error_code_e _enable_bt_tethering(Tethering *obj, mobile_ap_address_ty } if (_mobileap_is_enabled(MOBILE_AP_STATE_WIFI_AP)) { - ERR("Wi-Fi AP is enabled\n"); + ERR("Wi-Fi AP is enabled\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_RESOURCE; } @@ -364,12 +370,12 @@ mobile_ap_error_code_e _disable_bt_tethering(Tethering *obj, mobile_ap_address_t { int ret = BT_ERROR_NONE; if (!_mobileap_is_enabled(MOBILE_AP_STATE_BT)) { - ERR("BT tethering has not been enabled\n"); + ERR("BT tethering has not been enabled\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_NOT_ENABLED; } ret = bt_adapter_unset_visibility_mode_changed_cb(); if (ret != BT_ERROR_NONE) - ERR("bt_adapter_unset_visibility_mode_changed_cb is failed : %d\n", ret); + ERR("bt_adapter_unset_visibility_mode_changed_cb is failed : %d\n", ret); //LCOV_EXCL_LINE _block_device_sleep(); if (__is_bt_adapter_on()) { @@ -398,6 +404,7 @@ mobile_ap_error_code_e _disable_bt_tethering(Tethering *obj, mobile_ap_address_t return MOBILE_AP_ERROR_NONE; } +//LCOV_EXCL_START static void __bt_nap_connection_changed(bool connected, const char *remote_address, const char *interface_name, void *user_data) { if (remote_address == NULL || interface_name == NULL || user_data == NULL) { @@ -481,7 +488,9 @@ static void __bt_adapter_state_changed(int result, bt_adapter_state_e adapter_st tethering_emit_bluetooth_on(obj); _create_tethering_active_noti(); +#ifndef TIZEN_FEATURE_UNITTEST tethering_complete_enable_bt_tethering(obj, g_context, ret); +#endif __handle_bt_adapter_visibility(); g_context = NULL; _unblock_device_sleep(); @@ -490,18 +499,21 @@ static void __bt_adapter_state_changed(int result, bt_adapter_state_e adapter_st } FAIL: +#ifndef TIZEN_FEATURE_UNITTEST tethering_complete_enable_bt_tethering(obj, g_context, ret); +#endif g_context = NULL; _mobileap_clear_state(MOBILE_AP_STATE_BT); _unblock_device_sleep(); return; } +//LCOV_EXCL_STOP void _bt_get_remote_device_name(const char *mac, char **name) { if (mac == NULL || name == NULL) { - ERR("Invalid param\n"); + ERR("Invalid param\n"); //LCOV_EXCL_LINE return; } @@ -513,7 +525,7 @@ void _bt_get_remote_device_name(const char *mac, char **name) *name = g_strdup(remote->info->remote_name); if (*name == NULL) { - ERR("Memory allocation failed\n"); + ERR("Memory allocation failed\n"); //LCOV_EXCL_LINE return; } @@ -531,10 +543,10 @@ static void __bt_adapter_visibility_changed_cb(int result, ret = bt_adapter_get_visibility(&mode, &duration); if (ret != BT_ERROR_NONE) - ERR("bt_adapter_get_visibility is failed 0x[%X]\n", ret); + ERR("bt_adapter_get_visibility is failed 0x[%X]\n", ret); //LCOV_EXCL_LINE if (mode == BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE) - ERR("_launch_toast_popup() is failed\n"); + ERR("_launch_toast_popup() is failed\n"); //LCOV_EXCL_LINE DBG("-\n"); } @@ -549,12 +561,12 @@ static void __handle_bt_adapter_visibility() ret = bt_adapter_get_visibility(&mode, &duration); if (ret != BT_ERROR_NONE) - ERR("bt_adapter_get_visibility is failed 0x[%X]\n", ret); + ERR("bt_adapter_get_visibility is failed 0x[%X]\n", ret); //LCOV_EXCL_LINE if (mode == BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE) { ret = bt_adapter_set_visibility(BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE, 120); if (ret != BT_ERROR_NONE) - ERR("bt_adapter_set_visibility is failed 0x[%X]\n", ret); + ERR("bt_adapter_set_visibility is failed 0x[%X]\n", ret); //LCOV_EXCL_LINE } bt_adapter_set_visibility_mode_changed_cb(__bt_adapter_visibility_changed_cb, NULL); DBG("-\n"); @@ -573,9 +585,11 @@ gboolean tethering_enable_bt_tethering(Tethering *obj, g_assert(context != NULL); #endif if (g_context) { - DBG("It is turnning on\n"); + DBG("It is turnning on\n"); //LCOV_EXCL_LINE +#ifndef TIZEN_FEATURE_UNITTEST tethering_complete_enable_bt_tethering(obj, context, MOBILE_AP_ERROR_IN_PROGRESS); +#endif return FALSE; } @@ -583,7 +597,7 @@ gboolean tethering_enable_bt_tethering(Tethering *obj, /* DPM Policy */ if (!_is_allowed(MOBILE_AP_TYPE_BT)) { - DBG("DPM policy restricts BT tethering\n"); + DBG("DPM policy restricts BT tethering\n"); //LCOV_EXCL_LINE ret = MOBILE_AP_ERROR_NOT_PERMITTED; _create_security_restriction_noti(MOBILE_AP_TYPE_BT); goto DONE; @@ -619,9 +633,9 @@ gboolean tethering_enable_bt_tethering(Tethering *obj, #endif if (__is_bt_adapter_on() == FALSE) { - DBG("Bluetooth is deactivated\n"); + DBG("Bluetooth is deactivated\n"); //LCOV_EXCL_LINE if (__turn_on_bt_adapter((gpointer)obj) != MOBILE_AP_ERROR_NONE) { - ERR("__turn_on_bt_adapter is failed\n"); + ERR("__turn_on_bt_adapter is failed\n"); //LCOV_EXCL_LINE ret = MOBILE_AP_ERROR_INTERNAL; _mobileap_clear_state(MOBILE_AP_STATE_BT); #ifdef TIZEN_FEATURE_ENABLE_IPV6 @@ -637,7 +651,7 @@ gboolean tethering_enable_bt_tethering(Tethering *obj, ret = _enable_bt_tethering(obj, address_type); if (ret != MOBILE_AP_ERROR_NONE) { - ERR("_enable_bt_tethering() is failed : %d\n", ret); + ERR("_enable_bt_tethering() is failed : %d\n", ret); //LCOV_EXCL_LINE _mobileap_clear_state(MOBILE_AP_STATE_BT); #ifdef TIZEN_FEATURE_ENABLE_IPV6 if (address_type == MOBILE_AP_ADDRESS_TYPE_IPV6) @@ -652,7 +666,9 @@ gboolean tethering_enable_bt_tethering(Tethering *obj, } DONE: +#ifndef TIZEN_FEATURE_UNITTEST tethering_complete_enable_bt_tethering(obj, g_context, ret); +#endif g_context = NULL; _unblock_device_sleep(); @@ -673,14 +689,18 @@ gboolean tethering_disable_bt_tethering(Tethering *obj, #endif ret = _disable_bt_tethering(obj, address_type); if (ret != MOBILE_AP_ERROR_NONE) { +#ifndef TIZEN_FEATURE_UNITTEST tethering_complete_disable_bt_tethering(obj, context, MOBILE_AP_DISABLE_BT_TETHERING_CFM, ret); +#endif return FALSE; } - tethering_emit_bluetooth_off(obj, NULL); + tethering_emit_bluetooth_off(obj, ""); +#ifndef TIZEN_FEATURE_UNITTEST tethering_complete_disable_bt_tethering(obj, context, MOBILE_AP_DISABLE_BT_TETHERING_CFM, ret); +#endif return TRUE; } @@ -690,6 +710,7 @@ gboolean _is_trying_bt_operation(void) } #ifdef TIZEN_FEATURE_ENABLE_IPV6 +//LCOV_EXCL_START static gboolean __del_ipv6_bt_remote(const char *mac) { int i; @@ -719,6 +740,7 @@ static gboolean __del_ipv6_bt_remote(const char *mac) return TRUE; } +//LCOV_EXCL_STOP static void __del_ipv6_bt_remote_all(void) { @@ -743,6 +765,7 @@ static void __del_ipv6_bt_remote_all(void) return; } +//LCOV_EXCL_START static void __bt_ipv6_adapter_state_changed(int result, bt_adapter_state_e adapter_state, void *user_data) { if (user_data == NULL) { @@ -779,7 +802,9 @@ static void __bt_ipv6_adapter_state_changed(int result, bt_adapter_state_e adapt tethering_emit_bluetooth_on(obj); _create_tethering_active_noti(); +#ifndef TIZEN_FEATURE_UNITTEST tethering_complete_enable_bt_tethering(obj, g_context, ret); +#endif __handle_bt_adapter_visibility(); g_context = NULL; _unblock_device_sleep(); @@ -788,7 +813,9 @@ static void __bt_ipv6_adapter_state_changed(int result, bt_adapter_state_e adapt } FAIL: +#ifndef TIZEN_FEATURE_UNITTEST tethering_complete_enable_bt_tethering(obj, g_context, ret); +#endif g_context = NULL; _mobileap_clear_state(MOBILE_AP_STATE_BT); _mobileap_clear_ipv6_state(MOBILE_AP_STATE_BT); @@ -947,4 +974,5 @@ static void __bt_nap_ipv6_connection_changed(bool connected, const char *remote_ DBG("-"); return; } +//LCOV_EXCL_STOP #endif /* TIZEN_FEATURE_ENABLE_IPV6 */ diff --git a/src/mobileap_common.c b/src/mobileap_common.c index 69aaf6c..392e933 100755 --- a/src/mobileap_common.c +++ b/src/mobileap_common.c @@ -203,12 +203,12 @@ int _add_station_info(mobile_ap_station_info_t *info) int _remove_station_info(gconstpointer data, GCompareFunc func) { if (func == NULL) { - ERR("Invalid param\n"); + ERR("Invalid param\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INVALID_PARAM; } if (station_list == NULL) { - ERR("There is no station\n"); + ERR("There is no station\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } @@ -218,12 +218,12 @@ int _remove_station_info(gconstpointer data, GCompareFunc func) l = g_slist_find_custom(station_list, data, func); if (!l) { - ERR("Not found\n"); + ERR("Not found\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } si = (mobile_ap_station_info_t *)l->data; - SDBG("Remove station MAC : %s\n", si->mac); + SDBG("Remove station MAC : %s\n", si->mac); //LCOV_EXCL_LINE _send_dbus_station_info("DhcpLeaseDeleted", si); g_free(si->hostname); g_free(si); @@ -254,7 +254,7 @@ int _remove_station_info_all(mobile_ap_type_e type) continue; } - SDBG("Remove station MAC : %s\n", si->mac); + SDBG("Remove station MAC : %s\n", si->mac); //LCOV_EXCL_LINE _send_dbus_station_info("DhcpLeaseDeleted", si); g_free(si->hostname); g_free(si); @@ -274,12 +274,12 @@ int _get_station_info(gconstpointer data, GCompareFunc func, mobile_ap_station_info_t **si) { if (func == NULL || si == NULL) { - ERR("Invalid param\n"); + ERR("Invalid param\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INVALID_PARAM; } if (station_list == NULL) { - ERR("There is no station\n"); + ERR("There is no station\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } @@ -288,12 +288,12 @@ int _get_station_info(gconstpointer data, GCompareFunc func, l = g_slist_find_custom(station_list, data, func); if (!l) { - ERR("Not found\n"); + ERR("Not found\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } node = l->data; - SDBG("Found station : %s\n", node->mac); + SDBG("Found station : %s\n", node->mac); //LCOV_EXCL_LINE *si = node; return MOBILE_AP_ERROR_NONE; @@ -302,7 +302,7 @@ int _get_station_info(gconstpointer data, GCompareFunc func, int _get_station_count(gconstpointer data, GCompareFunc func, int *count) { if (count == NULL) { - ERR("Invalid param\n"); + ERR("Invalid param\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INVALID_PARAM; } @@ -354,9 +354,9 @@ GVariant * _station_info_foreach() params = g_variant_new("(@a(a{sv}))", g_variant_builder_end(outer_builder)); if (params == NULL) - ERR("params IS NULL\n"); + ERR("params IS NULL\n"); //LCOV_EXCL_LINE else - SDBG("outer builder print %s", g_variant_print(params, TRUE)); + SDBG("outer builder print %s", g_variant_print(params, TRUE)); //LCOV_EXCL_LINE g_variant_builder_unref(outer_builder); return params; @@ -366,7 +366,7 @@ GVariant * _station_info_foreach() int _add_multicast_routing(const char *interface) { if (interface == NULL || interface[0] == '\0') { - ERR("Invalid parameter\n"); + ERR("Invalid parameter\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INVALID_PARAM; } @@ -374,7 +374,7 @@ int _add_multicast_routing(const char *interface) snprintf(cmd, sizeof(cmd), "%s "ROUTE_ADD, ROUTE_CMD, MULTICAST_ADDR, MULTICAST_NETMASK, interface); if (_execute_command(cmd)) { - ERR("cmd failed : %s\n", cmd); + ERR("cmd failed : %s\n", cmd); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } @@ -384,7 +384,7 @@ int _add_multicast_routing(const char *interface) int _del_multicast_routing(const char *interface) { if (interface == NULL || interface[0] == '\0') { - ERR("Invalid parameter\n"); + ERR("Invalid parameter\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INVALID_PARAM; } @@ -392,7 +392,7 @@ int _del_multicast_routing(const char *interface) snprintf(cmd, sizeof(cmd), "%s "ROUTE_DEL, ROUTE_CMD, MULTICAST_ADDR, MULTICAST_NETMASK, interface); if (_execute_command(cmd)) { - ERR("cmd failed : %s\n", cmd); + ERR("cmd failed : %s\n", cmd); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } @@ -403,7 +403,7 @@ int _del_multicast_routing(const char *interface) int _add_interface_routing(const char *interface, const in_addr_t gateway) { if (interface == NULL || interface[0] == '\0') { - ERR("Invalid parameter\n"); + ERR("Invalid parameter\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INVALID_PARAM; } @@ -421,7 +421,7 @@ int _add_interface_routing(const char *interface, const in_addr_t gateway) snprintf(cmd, sizeof(cmd), "%s route add "INTERFACE_ROUTING, IP_CMD, interface_gw, TETHERING_ROUTING_TABLE, interface); if (_execute_command(cmd)) { - ERR("cmd failed : %s\n", cmd); + ERR("cmd failed : %s\n", cmd); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } @@ -431,7 +431,7 @@ int _add_interface_routing(const char *interface, const in_addr_t gateway) int _del_interface_routing(const char *interface, const in_addr_t gateway) { if (interface == NULL || interface[0] == '\0') { - ERR("Invalid parameter\n"); + ERR("Invalid parameter\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INVALID_PARAM; } @@ -449,7 +449,7 @@ int _del_interface_routing(const char *interface, const in_addr_t gateway) snprintf(cmd, sizeof(cmd), "%s route del "INTERFACE_ROUTING, IP_CMD, interface_gw, TETHERING_ROUTING_TABLE, interface); if (_execute_command(cmd)) { - ERR("cmd failed : %s\n", cmd); + ERR("cmd failed : %s\n", cmd); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } @@ -459,7 +459,7 @@ int _del_interface_routing(const char *interface, const in_addr_t gateway) int _add_routing_rule(const char *interface) { if (interface == NULL || interface[0] == '\0') { - ERR("Invalid parameter\n"); + ERR("Invalid parameter\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INVALID_PARAM; } @@ -468,7 +468,7 @@ int _add_routing_rule(const char *interface) snprintf(cmd, sizeof(cmd), "%s rule add "SRC_ROUTING_RULE, IP_CMD, interface, TETHERING_ROUTING_TABLE); if (_execute_command(cmd)) { - ERR("cmd failed : %s\n", cmd); + ERR("cmd failed : %s\n", cmd); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } @@ -478,7 +478,7 @@ int _add_routing_rule(const char *interface) int _del_routing_rule(const char *interface) { if (interface == NULL || interface[0] == '\0') { - ERR("Invalid parameter\n"); + ERR("Invalid parameter\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INVALID_PARAM; } @@ -487,7 +487,7 @@ int _del_routing_rule(const char *interface) snprintf(cmd, sizeof(cmd), "%s rule del "SRC_ROUTING_RULE, IP_CMD, interface, TETHERING_ROUTING_TABLE); if (_execute_command(cmd)) { - ERR("cmd failed : %s\n", cmd); + ERR("cmd failed : %s\n", cmd); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } @@ -497,7 +497,7 @@ int _del_routing_rule(const char *interface) int _flush_ip_address(const char *interface) { if (interface == NULL || interface[0] == '\0') { - ERR("Invalid parameter\n"); + ERR("Invalid parameter\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INVALID_PARAM; } @@ -506,7 +506,7 @@ int _flush_ip_address(const char *interface) snprintf(cmd, sizeof(cmd), "%s addr flush dev %s", IP_CMD, interface); if (_execute_command(cmd)) { - ERR("cmd failed : %s\n", cmd); + ERR("cmd failed : %s\n", cmd); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } @@ -516,7 +516,7 @@ int _flush_ip_address(const char *interface) int _execute_command(const char *cmd) { if (cmd == NULL) { - ERR("Invalid param\n"); + ERR("Invalid param\n"); //LCOV_EXCL_LINE return EXIT_FAILURE; } @@ -529,21 +529,21 @@ int _execute_command(const char *cmd) args = g_strsplit_set(cmd, " ", -1); if (!args) { - ERR("g_strsplit_set failed\n"); + ERR("g_strsplit_set failed\n"); //LCOV_EXCL_LINE return EXIT_FAILURE; } if ((pid = fork()) < 0) { - ERR("fork failed\n"); + ERR("fork failed\n"); //LCOV_EXCL_LINE g_strfreev(args); return EXIT_FAILURE; } if (!pid) { if (execv(args[0], args)) - ERR("execl failed\n"); + ERR("execl failed\n"); //LCOV_EXCL_LINE - ERR("Should never get here!\n"); + ERR("Should never get here!\n"); //LCOV_EXCL_LINE g_strfreev(args); return EXIT_FAILURE; } else { @@ -554,12 +554,12 @@ int _execute_command(const char *cmd) if (WIFEXITED(status)) { exit_status = WEXITSTATUS(status); if (exit_status) { - ERR("child return : %d\n", exit_status); + ERR("child return : %d\n", exit_status); //LCOV_EXCL_LINE return EXIT_FAILURE; } return EXIT_SUCCESS; } else { - ERR("child is terminated without exit\n"); + ERR("child is terminated without exit\n"); //LCOV_EXCL_LINE return EXIT_FAILURE; } } @@ -568,7 +568,7 @@ int _execute_command(const char *cmd) int _get_tethering_type_from_ip(const char *ip, mobile_ap_type_e *type) { if (ip == NULL || type == NULL) { - ERR("Invalid param\n"); + ERR("Invalid param\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INVALID_PARAM; } @@ -582,7 +582,7 @@ int _get_tethering_type_from_ip(const char *ip, mobile_ap_type_e *type) in_addr_t subnet; if (inet_aton(ip, &addr) == 0) { - SERR("Address : %s is invalid\n", ip); + SERR("Address : %s is invalid\n", ip); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INVALID_PARAM; } subnet = inet_netof(addr); @@ -622,6 +622,7 @@ int _get_tethering_type_from_ip(const char *ip, mobile_ap_type_e *type) } #ifndef TIZEN_FEATURE_HEADLESS +//LCOV_EXCL_START static void __policy_chnaged_cb(const char *name, const char *value, void *data) { Tethering *obj = _get_tethering_obj(); @@ -662,6 +663,7 @@ static void __policy_chnaged_cb(const char *name, const char *value, void *data) allow_bt_tethering = allowed; } } +//LCOV_EXCL_STOP int _is_allowed(mobile_ap_type_e type) { @@ -697,17 +699,17 @@ int _init_dpm(void) ret = dpm_add_policy_changed_cb(dpm, DPM_POLICY_WIFI_TETHERING, __policy_chnaged_cb, NULL, &wifi_tethering_id); if (ret < 0) - ERR("Failed to register policy callback!!"); + ERR("Failed to register policy callback!!"); //LCOV_EXCL_LINE ret = dpm_add_policy_changed_cb(dpm, DPM_POLICY_BT_TETHERING, __policy_chnaged_cb, NULL, &bt_tethering_id); if (ret < 0) - ERR("Failed to register policy callback!!"); + ERR("Failed to register policy callback!!"); //LCOV_EXCL_LINE ret = dpm_add_policy_changed_cb(dpm, DPM_POLICY_USB_TETHERING, __policy_chnaged_cb, NULL, &usb_tethering_id); if (ret < 0) - ERR("Failed to register policy callback!!"); + ERR("Failed to register policy callback!!"); //LCOV_EXCL_LINE /* Initialize DPM state */ if (dpm_restriction_get_wifi_hotspot_state(dpm, &is_allow) == DPM_ERROR_NONE) @@ -744,7 +746,9 @@ gboolean tethering_disable(Tethering *obj, GDBusMethodInvocation *context) if (_mobileap_is_disabled()) { ERR("Mobile hotspot has not been enabled\n"); ret = MOBILE_AP_ERROR_NOT_ENABLED; +#ifndef TIZEN_FEATURE_UNITTEST tethering_complete_disable(obj, context, MOBILE_AP_DISABLE_CFM, ret); +#endif return FALSE; } @@ -762,7 +766,9 @@ gboolean tethering_disable(Tethering *obj, GDBusMethodInvocation *context) _disable_usb_tethering(obj); #endif +#ifndef TIZEN_FEATURE_UNITTEST tethering_complete_disable(obj, context, MOBILE_AP_DISABLE_CFM, ret); +#endif return TRUE; } @@ -801,9 +807,11 @@ gboolean tethering_get_data_packet_usage(Tethering *obj, unsigned long long rx_bytes = 0; if (_get_network_interface_name(&if_name) == FALSE) { +#ifndef TIZEN_FEATURE_UNITTEST tethering_complete_get_data_packet_usage(obj, context, MOBILE_AP_GET_DATA_PACKET_USAGE_CFM, 0ULL, 0ULL); +#endif return FALSE; } @@ -822,9 +830,10 @@ gboolean tethering_get_data_packet_usage(Tethering *obj, tx_bytes = wifi_tx_bytes + bt_tx_bytes + usb_tx_bytes; rx_bytes = wifi_rx_bytes + bt_rx_bytes + usb_rx_bytes; - +#ifndef TIZEN_FEATURE_UNITTEST tethering_complete_get_data_packet_usage(obj, context, MOBILE_AP_GET_DATA_PACKET_USAGE_CFM, tx_bytes, rx_bytes); +#endif return TRUE; } diff --git a/src/mobileap_handler.c b/src/mobileap_handler.c index 495598e..de6679d 100644 --- a/src/mobileap_handler.c +++ b/src/mobileap_handler.c @@ -45,6 +45,7 @@ static sp_timeout_handler_t sp_timeout_handler[MOBILE_AP_TYPE_MAX] = { {0, 0, __bt_timeout_cb, NULL}, {0, 0, NULL, NULL} }; +//LCOV_EXCL_START static void __handle_network_cellular_state_changed_cb(keynode_t *key, void *data) { if (key == NULL) { @@ -137,11 +138,12 @@ static void __handle_language_changed_cb(keynode_t *key, void *data) return; } +//LCOV_EXCL_STOP void _register_vconf_cb(void *user_data) { if (user_data == NULL) { - ERR("Invalid param\n"); + ERR("Invalid param\n"); //LCOV_EXCL_LINE return; } @@ -164,13 +166,13 @@ void _register_vconf_cb(void *user_data) ret = vconf_notify_key_changed(vconf_reg[i].key, vconf_reg[i].cb, user_data); if (ret != 0) - ERR("vconf_notify_key_changed is failed : %d\n", ret); + ERR("vconf_notify_key_changed is failed : %d\n", ret); //LCOV_EXCL_LINE if (vconf_reg[i].value) { ret = vconf_get_int(vconf_reg[i].key, vconf_reg[i].value); if (ret != 0) - ERR("vconf_get_int is failed : %d\n", ret); + ERR("vconf_get_int is failed : %d\n", ret); //LCOV_EXCL_LINE } i++; @@ -200,7 +202,7 @@ void _unregister_vconf_cb(void) ret = vconf_ignore_key_changed(vconf_reg[i].key, vconf_reg[i].cb); if (ret != 0) - ERR("vconf_notify_key_changed is failed : %d\n", ret); + ERR("vconf_notify_key_changed is failed : %d\n", ret); //LCOV_EXCL_LINE i++; } @@ -208,6 +210,7 @@ void _unregister_vconf_cb(void) return; } +//LCOV_EXCL_START static gboolean __wifi_timeout_cb(gpointer data) { DBG("+\n"); @@ -262,6 +265,7 @@ static gboolean __bt_timeout_cb(gpointer data) DBG("-\n"); return FALSE; } +//LCOV_EXCL_STOP static sp_timeout_handler_t *__find_next_timeout(void) { @@ -280,6 +284,7 @@ static sp_timeout_handler_t *__find_next_timeout(void) return next_timeout; } +//LCOV_EXCL_START static void __expire_timeout(sp_timeout_handler_t *sp) { if (sp->alarm_id > 0) { @@ -292,6 +297,7 @@ static void __expire_timeout(sp_timeout_handler_t *sp) if (sp->func) sp->func(sp->user_data); } +//LCOV_EXCL_STOP static void __reset_timeout(sp_timeout_handler_t *sp) { @@ -303,6 +309,7 @@ static void __reset_timeout(sp_timeout_handler_t *sp) sp->end_time = 0; } +//LCOV_EXCL_START int _sp_timeout_handler(alarm_id_t alarm_id, void *user_param) { DBG("+\n"); @@ -347,6 +354,7 @@ int _sp_timeout_handler(alarm_id_t alarm_id, void *user_param) DBG("-\n"); return 0; } +//LCOV_EXCL_STOP void _init_timeout_cb(mobile_ap_type_e type, void *user_data) { @@ -402,7 +410,7 @@ void _start_timeout_cb(mobile_ap_type_e type, time_t end_time) &next_timeout->alarm_id); if (ret != ALARMMGR_RESULT_SUCCESS) { ERR("alarmmgr_add_alarm is failed. type : %d, end_time : %d\n", - type, end_time); + type, end_time); //LCOV_EXCL_LINE return; } @@ -452,7 +460,7 @@ void _stop_timeout_cb(mobile_ap_type_e type) &next_timeout->alarm_id); if (ret != ALARMMGR_RESULT_SUCCESS) { ERR("alarmmgr_add_alarm is failed. type : %d, end_time : %d\n", - type, next_timeout->end_time); + type, next_timeout->end_time); //LCOV_EXCL_LINE } DBG("-\n"); diff --git a/src/mobileap_iptables.c b/src/mobileap_iptables.c index 0247ecd..927d279 100755 --- a/src/mobileap_iptables.c +++ b/src/mobileap_iptables.c @@ -58,9 +58,9 @@ int _iptables_create_chain(const char *table_name, const char *chain_name) snprintf(cmd, sizeof(cmd), "%s "CREATE_CHAIN_STR, IPTABLES, table_name, chain_name); - SDBG("command [%s]\n", cmd); + SDBG("command [%s]\n", cmd); //LCOV_EXCL_LINE if (_execute_command(cmd)) { - SERR("command [%s] failed\n", cmd); + SERR("command [%s] failed\n", cmd); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } @@ -73,9 +73,9 @@ int _iptables_flush_rules(const char *table_name, const char *chain_name) snprintf(cmd, sizeof(cmd), "%s "FLUSH_CMD_STR, IPTABLES, table_name, chain_name); - SDBG("command [%s]\n", cmd); + SDBG("command [%s]\n", cmd); //LCOV_EXCL_LINE if (_execute_command(cmd)) { - SERR("command [%s] failed\n", cmd); + SERR("command [%s] failed\n", cmd); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } @@ -88,9 +88,9 @@ int _iptables_delete_chain(const char *table_name, const char *chain_name) snprintf(cmd, sizeof(cmd), "%s "DELETE_CHAIN_STR, IPTABLES, table_name, chain_name); - SDBG("command [%s]\n", cmd); + SDBG("command [%s]\n", cmd); //LCOV_EXCL_LINE if (_execute_command(cmd)) { - SERR("command [%s] failed\n", cmd); + SERR("command [%s] failed\n", cmd); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } @@ -100,7 +100,7 @@ int _iptables_delete_chain(const char *table_name, const char *chain_name) int _iptables_add_rule(iptables_rule_e rule_type, const char *table, const char *chain, ...) { if (table == NULL || chain == NULL) { - ERR("invalid parameters\n"); + ERR("invalid parameters\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INVALID_PARAM; } @@ -114,7 +114,7 @@ int _iptables_add_rule(iptables_rule_e rule_type, const char *table, const char dst_chain = va_arg(ap, char *); if (dst_chain == NULL) { - ERR("invalid parameters\n"); + ERR("invalid parameters\n"); //LCOV_EXCL_LINE goto ERROR_EXIT; } @@ -133,7 +133,7 @@ int _iptables_add_rule(iptables_rule_e rule_type, const char *table, const char action = va_arg(ap, char *); if (in_iface == NULL || out_iface == NULL || action == NULL) { - ERR("invalid parameters\n"); + ERR("invalid parameters\n"); //LCOV_EXCL_LINE goto ERROR_EXIT; } @@ -155,7 +155,7 @@ int _iptables_add_rule(iptables_rule_e rule_type, const char *table, const char if (in_iface == NULL || out_iface == NULL || action == NULL || state == NULL) { - ERR("invalid parameters\n"); + ERR("invalid parameters\n"); //LCOV_EXCL_LINE goto ERROR_EXIT; } @@ -182,7 +182,7 @@ int _iptables_add_rule(iptables_rule_e rule_type, const char *table, const char if (ip_iface == NULL || proto == NULL || org_ip == NULL || final_ip == NULL) { - ERR("invalid parameters\n"); + ERR("invalid parameters\n"); //LCOV_EXCL_LINE goto ERROR_EXIT; } @@ -198,7 +198,7 @@ int _iptables_add_rule(iptables_rule_e rule_type, const char *table, const char ext_iface = va_arg(ap, char *); if (ext_iface == NULL) { - ERR("invalid parameters\n"); + ERR("invalid parameters\n"); //LCOV_EXCL_LINE goto ERROR_EXIT; } @@ -219,7 +219,7 @@ int _iptables_add_rule(iptables_rule_e rule_type, const char *table, const char action = va_arg(ap, char *); if (action == NULL) { - ERR("invalid parameters\n"); + ERR("invalid parameters\n"); //LCOV_EXCL_LINE goto ERROR_EXIT; } @@ -241,7 +241,7 @@ int _iptables_add_rule(iptables_rule_e rule_type, const char *table, const char action = va_arg(ap, char *); if (chain == NULL || proto == NULL || action == NULL) { - ERR("invalid parameters\n"); + ERR("invalid parameters\n"); //LCOV_EXCL_LINE goto ERROR_EXIT; } @@ -266,7 +266,7 @@ int _iptables_add_rule(iptables_rule_e rule_type, const char *table, const char if (table == NULL || chain == NULL || out_iface == NULL || src_addr == NULL) { - ERR("Invalid parameter"); + ERR("Invalid parameter"); //LCOV_EXCL_LINE goto ERROR_EXIT; } @@ -276,12 +276,12 @@ int _iptables_add_rule(iptables_rule_e rule_type, const char *table, const char } #endif default: - ERR("case not supported\n"); + ERR("case not supported\n"); //LCOV_EXCL_LINE goto ERROR_EXIT; } if (_execute_command(cmd)) { - SERR("command [%s] failed\n", cmd); + SERR("command [%s] failed\n", cmd); //LCOV_EXCL_LINE goto ERROR_EXIT; } @@ -322,7 +322,7 @@ int _iptables_delete_rule(iptables_rule_e rule_type, const char *table, const ch if (in_iface == NULL || out_iface == NULL || action == NULL || state == NULL) { - ERR("invalid parameters\n"); + ERR("invalid parameters\n"); //LCOV_EXCL_LINE goto ERROR_EXIT; } @@ -342,7 +342,7 @@ int _iptables_delete_rule(iptables_rule_e rule_type, const char *table, const ch action = va_arg(ap, char *); if (in_iface == NULL || out_iface == NULL || action == NULL) { - ERR("invalid parameters\n"); + ERR("invalid parameters\n"); //LCOV_EXCL_LINE goto ERROR_EXIT; } @@ -357,7 +357,7 @@ int _iptables_delete_rule(iptables_rule_e rule_type, const char *table, const ch ext_iface = va_arg(ap, char *); if (ext_iface == NULL) { - ERR("invalid parameters\n"); + ERR("invalid parameters\n"); //LCOV_EXCL_LINE goto ERROR_EXIT; } @@ -376,7 +376,7 @@ int _iptables_delete_rule(iptables_rule_e rule_type, const char *table, const ch if (table == NULL || chain == NULL || out_iface == NULL || src_addr == NULL) { - ERR("Invalid parameter"); + ERR("Invalid parameter"); //LCOV_EXCL_LINE goto ERROR_EXIT; } @@ -386,12 +386,12 @@ int _iptables_delete_rule(iptables_rule_e rule_type, const char *table, const ch } #endif default: - ERR("case not supported\n"); + ERR("case not supported\n"); //LCOV_EXCL_LINE goto ERROR_EXIT; } if (_execute_command(cmd)) { - SERR("command [%s] failed\n", cmd); + SERR("command [%s] failed\n", cmd); //LCOV_EXCL_LINE va_end(ap); return MOBILE_AP_ERROR_INTERNAL; } @@ -408,7 +408,7 @@ int _get_data_usage(const char *src, const char *dest, unsigned long long *tx, { if (src == NULL || src[0] == '\0' || dest == NULL || dest[0] == '\0' || tx == NULL || rx == NULL) { - ERR("Invalid parameter\n"); + ERR("Invalid parameter\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INVALID_PARAM; } @@ -420,15 +420,15 @@ int _get_data_usage(const char *src, const char *dest, unsigned long long *tx, /* Tx : Src. -> Dest. */ snprintf(cmd, sizeof(cmd), "%s %s %s %s", MOBILEAP_AGENT_CMD, GET_TX, src, dest); if (_execute_command(cmd) != EXIT_SUCCESS) - ERR("Failed to execute command: %s", cmd); + ERR("Failed to execute command: %s", cmd); //LCOV_EXCL_LINE *tx = 0; fp = fopen(DATA_USAGE_FILE, "r"); if (fp == NULL) { - ERR("%s open failed\n", DATA_USAGE_FILE); + ERR("%s open failed\n", DATA_USAGE_FILE); //LCOV_EXCL_LINE strerror_r(errno, err_buf, sizeof(err_buf)); - ERR("%s\n", err_buf); + ERR("%s\n", err_buf); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } @@ -441,15 +441,15 @@ int _get_data_usage(const char *src, const char *dest, unsigned long long *tx, /* Rx : Dest. -> Src. */ snprintf(cmd, sizeof(cmd), "%s %s %s %s", MOBILEAP_AGENT_CMD, GET_RX, src, dest); if (_execute_command(cmd) != EXIT_SUCCESS) - ERR("Failed to execute command: %s", cmd); + ERR("Failed to execute command: %s", cmd); //LCOV_EXCL_LINE *rx = 0; fp = fopen(DATA_USAGE_FILE, "r"); if (fp == NULL) { - ERR("%s open failed\n", DATA_USAGE_FILE); + ERR("%s open failed\n", DATA_USAGE_FILE); //LCOV_EXCL_LINE strerror_r(errno, err_buf, sizeof(err_buf)); - ERR("%s\n", err_buf); + ERR("%s\n", err_buf); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } @@ -476,37 +476,37 @@ int _iptables_set_vpn_passthrough_rule(iptables_vpn_passthorugh_e vpn_type, int UDP(17) 4500/high port IKE, ESPinUDP encapsulation */ snprintf(cmd, sizeof(cmd), "%s -A FORWARD -p udp --dport 500 --sport 500 -j %s", IPTABLES, (enable ? "ACCEPT" : "REJECT")); if (_execute_command(cmd)) { - SERR("command [%s] failed\n", cmd); + SERR("command [%s] failed\n", cmd); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } memset(cmd, '0', sizeof(cmd)); snprintf(cmd, sizeof(cmd), "%s -A FORWARD -p udp --dport 10000 --sport 10000 -j %s", IPTABLES, (enable ? "ACCEPT" : "REJECT")); if (_execute_command(cmd)) { - SERR("command [%s] failed\n", cmd); + SERR("command [%s] failed\n", cmd); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } memset(cmd, '0', sizeof(cmd)); snprintf(cmd, sizeof(cmd), "%s -A FORWARD -p tcp --dport 10000 --sport 10000 -j %s", IPTABLES, (enable ? "ACCEPT" : "REJECT")); if (_execute_command(cmd)) { - SERR("command [%s] failed\n", cmd); + SERR("command [%s] failed\n", cmd); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } memset(cmd, '0', sizeof(cmd)); snprintf(cmd, sizeof(cmd), "%s -A FORWARD -p udp --dport 4500 --sport 4500 -j %s", IPTABLES, (enable ? "ACCEPT" : "REJECT")); if (_execute_command(cmd)) { - SERR("command [%s] failed\n", cmd); + SERR("command [%s] failed\n", cmd); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } memset(cmd, '0', sizeof(cmd)); snprintf(cmd, sizeof(cmd), "%s -A FORWARD -p 50 -j %s", IPTABLES, (enable ? "ACCEPT" : "REJECT")); if (_execute_command(cmd)) { - SERR("command [%s] failed\n", cmd); + SERR("command [%s] failed\n", cmd); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } memset(cmd, '0', sizeof(cmd)); snprintf(cmd, sizeof(cmd), "%s -A FORWARD -p 51 -j %s", IPTABLES, (enable ? "ACCEPT" : "REJECT")); if (_execute_command(cmd)) { - SERR("command [%s] failed\n", cmd); + SERR("command [%s] failed\n", cmd); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } break; @@ -517,7 +517,7 @@ int _iptables_set_vpn_passthrough_rule(iptables_vpn_passthorugh_e vpn_type, int UDP(17) 1723 -- */ snprintf(cmd, sizeof(cmd), "%s -A FORWARD -p tcp --dport 1723 --sport 1723 -j %s", IPTABLES, (enable ? "ACCEPT" : "REJECT")); if (_execute_command(cmd)) { - SERR("command [%s] failed\n", cmd); + SERR("command [%s] failed\n", cmd); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } break; @@ -528,13 +528,13 @@ int _iptables_set_vpn_passthrough_rule(iptables_vpn_passthorugh_e vpn_type, int UDP(17) 1701 -- */ snprintf(cmd, sizeof(cmd), "%s -A FORWARD -p udp --dport 1701 --sport 1701 -j %s", IPTABLES, (enable ? "ACCEPT" : "REJECT")); if (_execute_command(cmd)) { - SERR("command [%s] failed\n", cmd); + SERR("command [%s] failed\n", cmd); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } break; default: - ERR("case not supported\n"); + ERR("case not supported\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } diff --git a/src/mobileap_network.c b/src/mobileap_network.c index 101a180..c63337e 100644 --- a/src/mobileap_network.c +++ b/src/mobileap_network.c @@ -63,7 +63,6 @@ gboolean _set_ipv6_masquerade(void); gboolean _unset_ipv6_masquerade(void); #endif -#define MH_PORT_FORWARD_CONF_FILEPATH "/tmp/mobileap_agent_port_forward_info" #define MH_MAX_PORT_FORWARD_RULE_LEN 64 /* interface(10) protocol(10) ip(15):port(5) ip(15):port(5) */ #define MH_MAX_NO_OF_PORT_FORWARD_RULE 64 @@ -85,6 +84,7 @@ static GSList *port_forward_info = NULL; static gboolean __try_to_open_tethering_profile(gpointer user_data); +//LCOV_EXCL_START static mobile_ap_error_code_e __get_conn_error(int conn_error) { mobile_ap_error_code_e err = MOBILE_AP_ERROR_NONE; @@ -127,13 +127,14 @@ static mobile_ap_error_code_e __get_conn_error(int conn_error) break; _default_: default: - ERR("Not defined error : %d\n", conn_error); + ERR("Not defined error : %d\n", conn_error); //LCOV_EXCL_LINE err = MOBILE_AP_ERROR_INTERNAL; break; } return err; } +//LCOV_EXCL_STOP static gboolean __is_valid_ipv4_addr(const char *ip) { @@ -204,125 +205,6 @@ static void __clear_port_forward_info(void) return; } -static gboolean __read_port_forward_info(const char *conf_file) -{ - if (conf_file == NULL) { - ERR("Invalid parameter\n"); - return FALSE; - } - - DBG("+\n"); - - FILE *fp; - char buf[MH_MAX_PORT_FORWARD_RULE_LEN]; - char err_buf[MAX_BUF_SIZE] = {0, }; - port_forward_info_s *pf; - int no_of_rule = 0; - - __clear_port_forward_info(); - - fp = fopen(conf_file, "r"); - if (fp == NULL) { - strerror_r(errno, err_buf, sizeof(err_buf)); - ERR("fopen is failed : %s\n", err_buf); - return FALSE; - } - - while (fgets(buf, sizeof(buf), fp)) { - int i; - char *token; - char *saveptr1 = NULL; - char *saveptr2 = NULL; - - char *input_interface; - char *proto; - char *dest_ip[2]; - char *dest_port[2]; - - if (no_of_rule++ >= MH_MAX_NO_OF_PORT_FORWARD_RULE) { - DBG("There are too many rules\n"); - break; - } - - /* "Input interface" "Protocol" "Original destination IP:Port" "New destination IP:Port" */ - /* pdp0 udp 10.90.50.38:23 192.168.43.10:23 */ - - input_interface = strtok_r(buf, " ", &saveptr1); - if (input_interface == NULL) { - SERR("Invalid rule : %s\n", buf); - continue; - } - - proto = strtok_r(NULL, " ", &saveptr1); - if (proto == NULL) { - SERR("Invalid rule : %s\n", buf); - continue; - } - - for (i = 0; i < sizeof(dest_ip) / sizeof(char *); i++) { - token = strtok_r(NULL, " ", &saveptr1); - if (token == NULL) { - SERR("Invalid rule : %s\n", buf); - break; - } - - dest_ip[i] = strtok_r(token, ":", &saveptr2); - if (dest_ip[i] == NULL || - !__is_valid_ipv4_addr(dest_ip[i])) { - SERR("Invalid rule : %s\n", buf); - break; - } - - dest_port[i] = strtok_r(NULL, ":", &saveptr2); - if (dest_port[i] == NULL) { - SERR("Invalid rule : %s\n", buf); - break; - } - } - - if (i < sizeof(dest_ip) / sizeof(char *)) - continue; - - pf = (port_forward_info_s *)malloc(sizeof(port_forward_info_s)); - if (pf == NULL) - break; - - pf->input_interface = g_strdup(input_interface); - pf->proto = g_strdup(proto); - pf->org_dest_ip = g_strdup(dest_ip[0]); - pf->org_dest_port = (unsigned short)atoi(dest_port[0]); - pf->new_dest_ip = g_strdup(dest_ip[1]); - if (dest_port[1]) - pf->new_dest_port = (unsigned short)atoi(dest_port[1]); - port_forward_info = g_slist_append(port_forward_info, pf); - - SDBG("Port forward rule #%d : %s %s %s:%d %s:%d\n", no_of_rule, - pf->input_interface, pf->proto, - pf->org_dest_ip, pf->org_dest_port, - pf->new_dest_ip, pf->new_dest_port); - } - - fclose(fp); - - return TRUE; -} - -static gboolean __is_valid_port_forward_info(port_forward_info_s *pf) -{ - if (pf == NULL) - return FALSE; - - if (!pf->input_interface || !pf->proto || - !pf->org_dest_ip || !pf->new_dest_ip) - return FALSE; - - if (!strlen(pf->input_interface) || !strlen(pf->proto) || - !strlen(pf->org_dest_ip) || !strlen(pf->new_dest_ip)) - return FALSE; - - return TRUE; -} - static void __print_cellular_profile(void) { int ret = 0; @@ -336,15 +218,15 @@ static void __print_cellular_profile(void) ret = connection_profile_get_cellular_service_type(c_prof.handle, &service_type); if (ret != CONNECTION_ERROR_NONE) - ERR("connection API fail: 0x%X\n", ret); + ERR("connection API fail: 0x%X\n", ret); //LCOV_EXCL_LINE else - SDBG("Service type: %d\n", service_type); + SDBG("Service type: %d\n", service_type); //LCOV_EXCL_LINE ret = connection_profile_get_cellular_apn(c_prof.handle, &apn); if (ret != CONNECTION_ERROR_NONE) - ERR("connection API fail: 0x%X\n", ret); + ERR("connection API fail: 0x%X\n", ret); //LCOV_EXCL_LINE else { - SDBG("APN: %s\n", apn); + SDBG("APN: %s\n", apn); //LCOV_EXCL_LINE g_free(apn); } @@ -352,17 +234,18 @@ static void __print_cellular_profile(void) if (ret != CONNECTION_ERROR_NONE) ERR("connection API fail: 0x%X\n", ret); else { - SDBG("Home url: %s\n", home_url); + SDBG("Home url: %s\n", home_url); //LCOV_EXCL_LINE g_free(home_url); } ret = connection_profile_is_cellular_roaming(c_prof.handle, &roaming); if (ret != CONNECTION_ERROR_NONE) - ERR("connection API fail: 0x%X\n", ret); + ERR("connection API fail: 0x%X\n", ret); //LCOV_EXCL_LINE else - SDBG("Roaming: %d\n", roaming); + SDBG("Roaming: %d\n", roaming); //LCOV_EXCL_LINE } +//LCOV_EXCL_START static void __handle_open_network_error(void) { int ret = MOBILE_AP_ERROR_NONE; @@ -388,6 +271,7 @@ static void __handle_open_network_error(void) #endif tethering_emit_net_closed(obj); } +//LCOV_EXCL_END static gboolean __is_equal_profile(connection_profile_h a, connection_profile_h b) { @@ -397,7 +281,7 @@ static gboolean __is_equal_profile(connection_profile_h a, connection_profile_h ret = connection_profile_get_id(a, &a_id); if (ret != CONNECTION_ERROR_NONE || a_id == NULL) { - ERR("connection_profile_get_id is failed [0x%X]\n", ret); + ERR("connection_profile_get_id is failed [0x%X]\n", ret); //LCOV_EXCL_LINE if (a_id) g_free(a_id); return FALSE; @@ -405,7 +289,7 @@ static gboolean __is_equal_profile(connection_profile_h a, connection_profile_h ret = connection_profile_get_id(b, &b_id); if (ret != CONNECTION_ERROR_NONE || b_id == NULL) { - ERR("connection_profile_get_id is failed [0x%X]\n", ret); + ERR("connection_profile_get_id is failed [0x%X]\n", ret); //LCOV_EXCL_LINE g_free(a_id); if (b_id) g_free(b_id); @@ -431,7 +315,7 @@ static gboolean __is_connected_profile(connection_profile_h profile) ret = connection_profile_get_state(profile, &pstat); if (ret != CONNECTION_ERROR_NONE) { - ERR("connection_profile_get_state is failed: 0x%X\n", ret); + ERR("connection_profile_get_state is failed: 0x%X\n", ret); //LCOV_EXCL_LINE return FALSE; } @@ -442,6 +326,7 @@ static gboolean __is_connected_profile(connection_profile_h profile) return TRUE; } +//LCOV_EXCL_START static void __connection_type_changed_cb(connection_type_e type, void *user_data) { DBG("Changed connection type is [%s]\n", @@ -452,12 +337,12 @@ static void __connection_type_changed_cb(connection_type_e type, void *user_data "Unknown"); if (_mobileap_is_disabled()) { - DBG("Tethering is disabled\n"); + DBG("Tethering is disabled\n"); //LCOV_EXCL_LINE return; } if (_open_network() != MOBILE_AP_ERROR_NONE) { - ERR("_open_network() is failed\n"); + ERR("_open_network() is failed\n"); //LCOV_EXCL_LINE __handle_open_network_error(); } @@ -472,7 +357,7 @@ void __cellular_state_changed_cb(keynode_t *node, void *user_data) } if (vconf_keynode_get_type(node) != VCONF_TYPE_INT) { - ERR("Invalid vconf key type\n"); + ERR("Invalid vconf key type\n"); //LCOV_EXCL_LINE return; } @@ -492,7 +377,7 @@ void __cellular_state_changed_cb(keynode_t *node, void *user_data) ret = connection_get_type(connection, &net_type); if (ret != CONNECTION_ERROR_NONE) { - ERR("connection_get_type is failed [0x%X]\n", ret); + ERR("connection_get_type is failed [0x%X]\n", ret); //LCOV_EXCL_LINE return; } @@ -505,12 +390,13 @@ void __cellular_state_changed_cb(keynode_t *node, void *user_data) DBG("VCONFKEY_NETWORK_CELLULAR_ON\n"); if (_open_network() != MOBILE_AP_ERROR_NONE) { - ERR("_open_network() is failed\n"); + ERR("_open_network() is failed\n"); //LCOV_EXCL_LINE __handle_open_network_error(); } return; } +//LCOV_EXCL_STOP static void __profile_state_changed_cb(connection_profile_state_e state, void *user_data) { @@ -551,10 +437,10 @@ static void __profile_state_changed_cb(connection_profile_state_e state, void *u ret = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &cellular_state); if (ret < 0) { - ERR("vconf_get_int is failed : %d\n", ret); + ERR("vconf_get_int is failed : %d\n", ret); //LCOV_EXCL_LINE if (vconf_ignore_key_changed(VCONFKEY_NETWORK_CELLULAR_STATE, __cellular_state_changed_cb) < 0) { - ERR("vconf_ignore_key_changed is failed\n"); + ERR("vconf_ignore_key_changed is failed\n"); //LCOV_EXCL_LINE } return; } @@ -563,7 +449,7 @@ static void __profile_state_changed_cb(connection_profile_state_e state, void *u return; if (_open_network() != MOBILE_AP_ERROR_NONE) { - ERR("_open_network() is failed\n"); + ERR("_open_network() is failed\n"); //LCOV_EXCL_LINE __handle_open_network_error(); } @@ -583,7 +469,7 @@ static void __update_tethering_cellular_profile(void) svc_type = __TETHERING_ONLY; goto DONE; } - DBG("There is no tethering profile\n"); + DBG("There is no tethering profile\n"); //LCOV_EXCL_LINE ret = connection_get_default_cellular_service_profile(connection, CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET, &profile); @@ -591,7 +477,7 @@ static void __update_tethering_cellular_profile(void) svc_type = __INTERNET; goto DONE; } - ERR("Getting default connection for internet is failed\n"); + ERR("Getting default connection for internet is failed\n"); //LCOV_EXCL_LINE /* To-Do : Need to consider prepaid internet profile */ if (c_prof.handle) { @@ -606,7 +492,7 @@ DONE: if (c_prof.handle == NULL || !__is_equal_profile(c_prof.handle, profile)) { if (c_prof.handle) { - DBG("Tethering cellular profile is updated\n"); + DBG("Tethering cellular profile is updated\n"); //LCOV_EXCL_LINE connection_profile_unset_state_changed_cb(c_prof.handle); connection_profile_destroy(c_prof.handle); } @@ -628,9 +514,9 @@ static void __profile_closed_cb(connection_error_e result, void *user_data) connection_profile_refresh(c_prof.handle); if (result != CONNECTION_ERROR_NONE) - ERR("Unable to close profile [0x%X]", result); + ERR("Unable to close profile [0x%X]", result); //LCOV_EXCL_LINE else - DBG("Tethering profile is closed"); + DBG("Tethering profile is closed"); //LCOV_EXCL_LINE return; } @@ -638,7 +524,7 @@ static void __profile_closed_cb(connection_error_e result, void *user_data) static gboolean __close_tethering_profile(void) { if (c_prof.handle == NULL || c_prof.svc_type == __NO_SERVICE) { - ERR("There is no proper cellular profile\n"); + ERR("There is no proper cellular profile\n"); //LCOV_EXCL_LINE return FALSE; } @@ -659,19 +545,19 @@ static gboolean __close_tethering_profile(void) ret = connection_profile_get_state(c_prof.handle, &state); if (ret != CONNECTION_ERROR_NONE) { - ERR("connection_profile_get_state is failed [0x%X]\n", ret); + ERR("connection_profile_get_state is failed [0x%X]\n", ret); //LCOV_EXCL_LINE return FALSE; } if (state == CONNECTION_PROFILE_STATE_DISCONNECTED) { - DBG("Already disconnected profile\n"); + DBG("Already disconnected profile\n"); //LCOV_EXCL_LINE return TRUE; } ret = connection_close_profile(connection, c_prof.handle, __profile_closed_cb, NULL); if (ret != CONNECTION_ERROR_NONE) { - ERR("Connection close Failed!!\n"); + ERR("Connection close Failed!!\n"); //LCOV_EXCL_LINE return FALSE; } @@ -699,14 +585,14 @@ static void __profile_opened_cb(connection_error_e result, void *user_data) } if (result == CONNECTION_ERROR_OPERATION_ABORTED) { - DBG("connection_open_profile is cancelled\n"); + DBG("connection_open_profile is cancelled\n"); //LCOV_EXCL_LINE return; } /* Check opened and retry context */ ret = connection_get_type(connection, &net_type); if (ret != CONNECTION_ERROR_NONE) { - ERR("connection_get_type is failed\n"); + ERR("connection_get_type is failed\n"); //LCOV_EXCL_LINE __close_tethering_profile(); return; } @@ -726,7 +612,7 @@ static void __profile_opened_cb(connection_error_e result, void *user_data) if (result != CONNECTION_ERROR_ALREADY_EXISTS && result != CONNECTION_ERROR_NONE) { - DBG("Retry to open profile [0x%X]\n", result); + DBG("Retry to open profile [0x%X]\n", result); //LCOV_EXCL_LINE if (net_timeout_id) { g_source_remove(net_timeout_id); net_timeout_id = 0; @@ -750,7 +636,6 @@ static void __profile_opened_cb(connection_error_e result, void *user_data) #endif _set_masquerade(); _add_default_router(); - _add_port_forward_rule(); #ifdef TIZEN_FEATURE_ENABLE_IPV6 } #endif @@ -763,7 +648,7 @@ static void __profile_opened_cb(connection_error_e result, void *user_data) static gboolean __open_tethering_profile(void) { if (c_prof.handle == NULL || c_prof.svc_type == __NO_SERVICE) { - ERR("There is no proper cellular profile\n"); + ERR("There is no proper cellular profile\n"); //LCOV_EXCL_LINE return FALSE; } @@ -775,14 +660,14 @@ static gboolean __open_tethering_profile(void) return TRUE; if (__is_connected_profile(c_prof.handle)) { - DBG("Already connected profile\n"); + DBG("Already connected profile\n"); //LCOV_EXCL_LINE return TRUE; } ret = connection_open_profile(connection, c_prof.handle, __profile_opened_cb, NULL); if (ret != CONNECTION_ERROR_NONE) { - ERR("Unable to open profile [0x%X]", ret); + ERR("Unable to open profile [0x%X]", ret); //LCOV_EXCL_LINE return FALSE; } @@ -795,7 +680,7 @@ static gboolean __try_to_open_tethering_profile(gpointer user_data) DBG("+\n"); if (_mobileap_is_disabled()) { - DBG("Tethering is disabled\n"); + DBG("Tethering is disabled\n"); //LCOV_EXCL_LINE net_timeout_id = 0; return FALSE; } @@ -818,25 +703,31 @@ gboolean _is_trying_network_operation(void) gboolean _get_network_interface_name(char **if_name) { if (if_name == NULL) { - ERR("if_name is NULL\n"); + ERR("if_name is NULL\n"); //LCOV_EXCL_LINE return FALSE; } - if (tethered_prof == NULL) + if (tethered_prof == NULL) { + ERR("tethered_prof is NULL"); //LCOV_EXCL_LINE return FALSE; + } int ret = 0; - connection_profile_refresh(tethered_prof); + ret = connection_profile_refresh(tethered_prof); + if (ret != CONNECTION_ERROR_NONE) { + ERR("connection_profile_refresh is failed : 0x%X\n", ret); //LCOV_EXCL_LINE + return FALSE; + } ret = connection_profile_get_network_interface_name(tethered_prof, if_name); if (ret != CONNECTION_ERROR_NONE) { - ERR("connection_profile_get_network_interface_name is failed : 0x%X\n", ret); + ERR("connection_profile_get_network_interface_name is failed : 0x%X\n", ret); //LCOV_EXCL_LINE return FALSE; } if (strlen(*if_name) == 0) { - ERR("if_name is zero length\n"); + ERR("if_name is zero length\n"); //LCOV_EXCL_LINE free(*if_name); return FALSE; } @@ -847,7 +738,7 @@ gboolean _get_network_interface_name(char **if_name) gboolean _get_network_gateway_address(mobile_ap_address_type_e address_type, char **ip) { if (ip == NULL) { - ERR("ip is NULL\n"); + ERR("ip is NULL\n"); //LCOV_EXCL_LINE return FALSE; } @@ -860,7 +751,7 @@ gboolean _get_network_gateway_address(mobile_ap_address_type_e address_type, cha ret = connection_profile_get_gateway_address(tethered_prof, address_type, ip); if (ret != CONNECTION_ERROR_NONE) { - ERR("connection_profile_get_ip_address is failed : 0x%X\n", ret); + ERR("connection_profile_get_ip_address is failed : 0x%X\n", ret); //LCOV_EXCL_LINE return FALSE; } @@ -872,7 +763,7 @@ gboolean _set_masquerade(void) char *if_name = NULL; if (_get_network_interface_name(&if_name) == FALSE) { - ERR("_get_network_interface_name is failed\n"); + ERR("_get_network_interface_name is failed\n"); //LCOV_EXCL_LINE return FALSE; } SDBG("Network interface : %s\n", if_name); @@ -886,14 +777,14 @@ gboolean _set_masquerade(void) gboolean _unset_masquerade(void) { if (tethered_prof == NULL) { - DBG("There is nothing to unset masquerading\n"); + DBG("There is nothing to unset masquerading\n"); //LCOV_EXCL_LINE return TRUE; } char *if_name = NULL; if (_get_network_interface_name(&if_name) == FALSE) { - ERR("_get_network_interface_name is failed\n"); + ERR("_get_network_interface_name is failed\n"); //LCOV_EXCL_LINE return FALSE; } SDBG("Network interface : %s\n", if_name); @@ -907,7 +798,7 @@ gboolean _unset_masquerade(void) gboolean _add_default_router(void) { if (tethered_prof == NULL) { - DBG("There is no network\n"); + DBG("There is no network\n"); //LCOV_EXCL_LINE return TRUE; } @@ -929,7 +820,7 @@ gboolean _add_default_router(void) free(ip); if (_execute_command(cmd)) { - ERR("%s is failed\n", cmd); + ERR("%s is failed\n", cmd); //LCOV_EXCL_LINE return FALSE; } @@ -939,7 +830,7 @@ gboolean _add_default_router(void) gboolean _del_default_router(void) { if (tethered_prof == NULL) { - DBG("There is no network\n"); + DBG("There is no network\n"); //LCOV_EXCL_LINE return TRUE; } @@ -961,46 +852,13 @@ gboolean _del_default_router(void) free(ip); if (_execute_command(cmd)) { - ERR("%s is failed\n", cmd); + ERR("%s is failed\n", cmd); //LCOV_EXCL_LINE return FALSE; } return TRUE; } -void _add_port_forward_rule(void) -{ - DBG("+\n"); - - GSList *l; - port_forward_info_s *pf; - - if (access(MH_PORT_FORWARD_CONF_FILEPATH, F_OK) < 0) - return; - - if (__read_port_forward_info(MH_PORT_FORWARD_CONF_FILEPATH) == FALSE) { - ERR("__read_port_forward_info() is failed\n"); - return; - } - - _iptables_create_chain(TABLE_NAT, TETH_NAT_PRE); - _iptables_add_rule(PKT_REDIRECTION_RULE, TABLE_NAT, CHAIN_PRE, - TETH_NAT_PRE); - - for (l = port_forward_info; l; l = g_slist_next(l)) { - pf = (port_forward_info_s *)l->data; - - if (__is_valid_port_forward_info(pf) == FALSE) - continue; - - _iptables_add_rule(PORT_FW_RULE, TABLE_NAT, TETH_NAT_PRE, - pf->input_interface, pf->proto, pf->org_dest_ip, - pf->new_dest_ip, (int)pf->org_dest_port, (int)pf->new_dest_port); - } - - return; -} - void _del_port_forward_rule(void) { GSList *l; @@ -1010,7 +868,7 @@ void _del_port_forward_rule(void) DBG("+\n"); if (port_forward_info == NULL) { - DBG("port forwarding rules were not applied, no need to deleted\n"); + DBG("port forwarding rules were not applied, no need to deleted\n"); //LCOV_EXCL_LINE return; } @@ -1047,13 +905,13 @@ static int __create_tethering_profile(void) ret = connection_get_type(connection, &net_type); if (ret != CONNECTION_ERROR_NONE) { - ERR("connection_get_type is failed\n"); + ERR("connection_get_type is failed\n"); //LCOV_EXCL_LINE con_ret = __get_conn_error(ret); return con_ret; } if (vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &cellular_state) < 0) { - ERR("vconf_get_int is failed\n"); + ERR("vconf_get_int is failed\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } @@ -1064,7 +922,7 @@ static int __create_tethering_profile(void) if (net_type == CONNECTION_TYPE_CELLULAR) { __update_tethering_cellular_profile(); if (__is_equal_profile(tethered_prof, c_prof.handle)) { - DBG("Cellular profile is already configured\n"); + DBG("Cellular profile is already configured\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_NONE; } } @@ -1075,7 +933,7 @@ static int __create_tethering_profile(void) if (net_type == CONNECTION_TYPE_DISCONNECTED && cellular_state != VCONFKEY_NETWORK_CELLULAR_ON) { - DBG("There is no network\n"); + DBG("There is no network\n"); //LCOV_EXCL_LINE /* Callback will handle this once Network type is changed */ return MOBILE_AP_ERROR_NONE; } @@ -1085,7 +943,7 @@ static int __create_tethering_profile(void) case CONNECTION_TYPE_CELLULAR: __update_tethering_cellular_profile(); if (c_prof.handle == NULL || c_prof.svc_type == __NO_SERVICE) { - DBG("There is no proper cellular profile for tethering\n"); + DBG("There is no proper cellular profile for tethering\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_NONE; } __print_cellular_profile(); @@ -1111,14 +969,14 @@ static int __create_tethering_profile(void) case CONNECTION_TYPE_BT: ret = connection_get_current_profile(connection, &tethered_prof); if (ret != CONNECTION_ERROR_NONE) { - ERR("connection_get_current_profile is failed [0x%X]\n", ret); + ERR("connection_get_current_profile is failed [0x%X]\n", ret); //LCOV_EXCL_LINE con_ret = __get_conn_error(ret); return con_ret; } break; default: - ERR("Unknown connection type : %d\n", net_type); + ERR("Unknown connection type : %d\n", net_type); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } return MOBILE_AP_ERROR_NONE; @@ -1130,13 +988,12 @@ int _open_network(void) int ret = __create_tethering_profile(); if (ret != MOBILE_AP_ERROR_NONE) { - ERR("Failed to create tethering profile!!"); + ERR("Failed to create tethering profile!!"); //LCOV_EXCL_LINE return ret; } _set_masquerade(); _add_default_router(); - _add_port_forward_rule(); DBG("-\n"); @@ -1146,7 +1003,7 @@ int _open_network(void) void _close_network(void) { if (tethered_prof == NULL) { - DBG("There is no tethered profile\n"); + DBG("There is no tethered profile\n"); //LCOV_EXCL_LINE return; } @@ -1167,7 +1024,7 @@ void _close_network(void) gboolean _init_network(void *user_data) { if (user_data == NULL) { - ERR("Invalid parameter\n"); + ERR("Invalid parameter\n"); //LCOV_EXCL_LINE return FALSE; } @@ -1177,21 +1034,21 @@ gboolean _init_network(void *user_data) ret = connection_create(&connection); if (ret != CONNECTION_ERROR_NONE) { - ERR("connection_create is failed : 0x%X\n", ret); + ERR("connection_create is failed : 0x%X\n", ret); //LCOV_EXCL_LINE goto FAIL; } ret = connection_set_type_changed_cb(connection, __connection_type_changed_cb, user_data); if (ret != CONNECTION_ERROR_NONE) { - ERR("connection_set_type_changed cb is failed : 0x%X\n", ret); + ERR("connection_set_type_changed cb is failed : 0x%X\n", ret); //LCOV_EXCL_LINE goto FAIL; } ret = vconf_notify_key_changed(VCONFKEY_NETWORK_CELLULAR_STATE, __cellular_state_changed_cb, NULL); if (ret < 0) { - ERR("vconf_notify_key_changed is failed : %d\n", ret); + ERR("vconf_notify_key_changed is failed : %d\n", ret); //LCOV_EXCL_LINE connection_unset_type_changed_cb(connection); goto FAIL; } @@ -1214,7 +1071,7 @@ gboolean _deinit_network(void) int ret; if (connection == NULL) { - ERR("Connection handle is not initialized\n"); + ERR("Connection handle is not initialized\n"); //LCOV_EXCL_LINE return TRUE; } @@ -1229,7 +1086,7 @@ gboolean _deinit_network(void) ret = connection_unset_type_changed_cb(connection); if (ret != CONNECTION_ERROR_NONE) - ERR("connection_unset_type_changed_cb is failed : %d\n", ret); + ERR("connection_unset_type_changed_cb is failed : %d\n", ret); //LCOV_EXCL_LINE connection_destroy(connection); connection = NULL; @@ -1245,21 +1102,21 @@ int _enable_ipv6(const char *if_name) char path[1024] = ""; if (if_name == NULL || strlen(if_name) == 0) { - ERR("Invalid interface name"); + ERR("Invalid interface name"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INVALID_PARAM; } snprintf(path, 1024, DISABLE_IPV6, if_name); - DBG("Enable IPv6 operation [%s]", path); + DBG("Enable IPv6 operation [%s]", path); //LCOV_EXCL_LINE fd = open(path, O_WRONLY); if (fd < 0) { - ERR("open failed\n"); + ERR("open failed\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_RESOURCE; } if (write(fd, "0", 1) != 1) { - ERR("write failed\n"); + ERR("write failed\n"); //LCOV_EXCL_LINE close(fd); return MOBILE_AP_ERROR_INTERNAL; } @@ -1274,14 +1131,14 @@ static int __update_ipv6_network_info(void) char *global_address = NULL; if (_get_network_interface_name(&if_name) == FALSE) { - ERR("Fail to get interface name!!"); + ERR("Fail to get interface name!!"); //LCOV_EXCL_LINE g_free(if_name); if_name = NULL; } if (if_name) { if (_get_ipv6_interface_address(if_name, MOBILE_AP_IPV6_SCOPE_GLOBAL, &global_address) == FALSE) { - ERR("Current network doesn't support IPv6"); + ERR("Current network doesn't support IPv6"); //LCOV_EXCL_LINE g_free(if_name); if_name = NULL; g_free(global_address); @@ -1311,12 +1168,12 @@ static int __enable_ipv4_forwarding(void) fd = open(IPV4_FORWARDING, O_WRONLY); if (fd < 0) { - ERR("open failed\n"); + ERR("open failed\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_RESOURCE; } if (write(fd, "1", 1) != 1) { - ERR("write failed\n"); + ERR("write failed\n"); //LCOV_EXCL_LINE close(fd); return MOBILE_AP_ERROR_INTERNAL; } @@ -1331,12 +1188,12 @@ static int __disable_ipv4_forwarding(void) fd = open(IPV4_FORWARDING, O_WRONLY); if (fd < 0) { - ERR("open failed\n"); + ERR("open failed\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_RESOURCE; } if (write(fd, "0", 1) != 1) { - ERR("write failed\n"); + ERR("write failed\n"); //LCOV_EXCL_LINE close(fd); return MOBILE_AP_ERROR_INTERNAL; } @@ -1351,12 +1208,12 @@ static int __enable_ipv6_forwarding(void) fd = open(IPV6_FORWARDING, O_WRONLY); if (fd < 0) { - ERR("open failed\n"); + ERR("open failed\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_RESOURCE; } if (write(fd, "1", 1) != 1) { - ERR("write failed\n"); + ERR("write failed\n"); //LCOV_EXCL_LINE close(fd); return MOBILE_AP_ERROR_INTERNAL; } @@ -1371,12 +1228,12 @@ static int __disable_ipv6_forwarding(void) fd = open(IPV6_FORWARDING, O_WRONLY); if (fd < 0) { - ERR("open failed\n"); + ERR("open failed\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_RESOURCE; } if (write(fd, "0", 1) != 1) { - ERR("write failed\n"); + ERR("write failed\n"); //LCOV_EXCL_LINE close(fd); return MOBILE_AP_ERROR_INTERNAL; } @@ -1391,12 +1248,12 @@ static int __enable_ipv6_proxy_ndp(void) fd = open(IPV6_PROXY_NDP, O_WRONLY); if (fd < 0) { - ERR("open failed\n"); + ERR("open failed\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_RESOURCE; } if (write(fd, "1", 1) != 1) { - ERR("write failed\n"); + ERR("write failed\n"); //LCOV_EXCL_LINE close(fd); return MOBILE_AP_ERROR_INTERNAL; } @@ -1411,12 +1268,12 @@ static int __disable_ipv6_proxy_ndp(void) fd = open(IPV6_PROXY_NDP, O_WRONLY); if (fd < 0) { - ERR("open failed\n"); + ERR("open failed\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_RESOURCE; } if (write(fd, "0", 1) != 1) { - ERR("write failed\n"); + ERR("write failed\n"); //LCOV_EXCL_LINE close(fd); return MOBILE_AP_ERROR_INTERNAL; } @@ -1445,11 +1302,11 @@ gboolean _set_ipv6_masquerade(void) char *if_name = NULL; if (_get_network_interface_name(&if_name) == FALSE) { - ERR("_get_network_interface_name is failed\n"); + ERR("_get_network_interface_name is failed\n"); //LCOV_EXCL_LINE return FALSE; } - SDBG("Network interface : %s\n", if_name); + SDBG("Network interface : %s\n", if_name); //LCOV_EXCL_LINE _mh_core_enable_ipv6_masquerade(if_name); free(if_name); @@ -1462,11 +1319,11 @@ gboolean _unset_ipv6_masquerade(void) char *if_name = NULL; if (_get_network_interface_name(&if_name) == FALSE) { - ERR("_get_network_interface_name is failed\n"); + ERR("_get_network_interface_name is failed\n"); //LCOV_EXCL_LINE return FALSE; } - SDBG("Network interface : %s\n", if_name); + SDBG("Network interface : %s\n", if_name); //LCOV_EXCL_LINE _mh_core_disable_ipv6_masquerade(if_name); free(if_name); @@ -1480,7 +1337,7 @@ int _open_ipv6_network(void) int ret = __create_tethering_profile(); if (ret != MOBILE_AP_ERROR_NONE) { - ERR("Failed to create tethering profile"); + ERR("Failed to create tethering profile"); //LCOV_EXCL_LINE return ret; } @@ -1488,13 +1345,13 @@ int _open_ipv6_network(void) ret = __enable_ipv6_forwarding(); if (ret != MOBILE_AP_ERROR_NONE) { - ERR("Failed to enable ipv6 forwarding"); + ERR("Failed to enable ipv6 forwarding"); //LCOV_EXCL_LINE return ret; } ret = __enable_ipv6_proxy_ndp(); if (ret != MOBILE_AP_ERROR_NONE) { - ERR("Failed to enable proxy_ndp"); + ERR("Failed to enable proxy_ndp"); //LCOV_EXCL_LINE return ret; } @@ -1510,7 +1367,7 @@ int _open_ipv6_network(void) void _close_ipv6_network(void) { if (tethered_prof == NULL) { - DBG("There is no tethered profile\n"); + DBG("There is no tethered profile\n"); //LCOV_EXCL_LINE return; } @@ -1543,7 +1400,7 @@ gboolean _get_ipv6_interface_address(const char *if_name, mobile_ap_ipv6_scope_e fd = fopen(MH_IF_INET6_PATH, "r"); if (fd == NULL) { - ERR("Failed to open file!!"); + ERR("Failed to open file!!"); //LCOV_EXCL_LINE return FALSE; } @@ -1567,7 +1424,7 @@ gboolean _get_ipv6_interface_address(const char *if_name, mobile_ap_ipv6_scope_e *ip = g_strdup(copied); - DBG("ipv6 address(%s)", *ip); + DBG("ipv6 address(%s)", *ip); //LCOV_EXCL_LINE break; } @@ -1595,26 +1452,7 @@ gboolean _add_route(const char *if_name, char *ip, mobile_ap_address_type_e addr return FALSE; if (_execute_command(cmd)) { - ERR("%s is failed\n", cmd); - return FALSE; - } - - return TRUE; -} - -gboolean _remove_route(const char *if_name, char *ip, mobile_ap_address_type_e address_type, int prefix) -{ - char cmd[MAX_BUF_SIZE] = {0, }; - - if (address_type == MOBILE_AP_ADDRESS_TYPE_IPV4) - snprintf(cmd, sizeof(cmd), "%s route del %s/%d dev %s", IP_CMD, ip, prefix, if_name); - else if (address_type == MOBILE_AP_ADDRESS_TYPE_IPV6) - snprintf(cmd, sizeof(cmd), "%s -6 route del %s/%d dev %s", IP_CMD, ip, prefix, if_name); - else - return FALSE; - - if (_execute_command(cmd)) { - ERR("%s is failed\n", cmd); + ERR("%s is failed\n", cmd); //LCOV_EXCL_LINE return FALSE; } @@ -1628,7 +1466,7 @@ gboolean _add_address(const char *if_name, char *ip) snprintf(cmd, sizeof(cmd), "%s addr add %s dev %s", IP_CMD, ip, if_name); if (_execute_command(cmd)) { - ERR("%s is failed\n", cmd); + ERR("%s is failed\n", cmd); //LCOV_EXCL_LINE return FALSE; } @@ -1642,7 +1480,7 @@ gboolean _remove_address(const char *if_name, char *ip) snprintf(cmd, sizeof(cmd), "%s addr del %s dev %s", IP_CMD, ip, if_name); if (_execute_command(cmd)) { - ERR("%s is failed\n", cmd); + ERR("%s is failed\n", cmd); //LCOV_EXCL_LINE return FALSE; } @@ -1652,7 +1490,7 @@ gboolean _remove_address(const char *if_name, char *ip) gboolean _add_ipv6_neigh_proxy(const char *if_name, const char *ip) { if (tethered_prof == NULL) { - DBG("There is no network\n"); + DBG("There is no network\n"); //LCOV_EXCL_LINE return TRUE; } @@ -1662,7 +1500,7 @@ gboolean _add_ipv6_neigh_proxy(const char *if_name, const char *ip) IP_CMD, ip, if_name); if (_execute_command(cmd)) { - ERR("%s is failed\n", cmd); + ERR("%s is failed\n", cmd); //LCOV_EXCL_LINE return FALSE; } @@ -1672,7 +1510,7 @@ gboolean _add_ipv6_neigh_proxy(const char *if_name, const char *ip) gboolean _remove_ipv6_neigh_proxy(const char *if_name, const char *ip) { if (tethered_prof == NULL) { - DBG("There is no network\n"); + DBG("There is no network\n"); //LCOV_EXCL_LINE return TRUE; } @@ -1682,7 +1520,7 @@ gboolean _remove_ipv6_neigh_proxy(const char *if_name, const char *ip) IP_CMD, ip, if_name); if (_execute_command(cmd)) { - ERR("%s is failed\n", cmd); + ERR("%s is failed\n", cmd); //LCOV_EXCL_LINE return FALSE; } @@ -1694,14 +1532,14 @@ gboolean _create_nat64_interface(void) char cmd[MAX_BUF_SIZE] = {0, }; snprintf(cmd, sizeof(cmd), "%s --mktun --config %s", NAT64_BIN, NAT64_CONF_FILE); - SDBG("commnad [%s]", cmd); + SDBG("commnad [%s]", cmd); //LCOV_EXCL_LINE if (_execute_command(cmd)) - ERR("%s is failed\n", cmd); + ERR("%s is failed\n", cmd); //LCOV_EXCL_LINE snprintf(cmd, sizeof(cmd), "%s -6 link set %s up", IP_CMD, NAT64_DEV); - SDBG("commnad [%s]", cmd); + SDBG("commnad [%s]", cmd); //LCOV_EXCL_LINE if (_execute_command(cmd)) { - ERR("%s is failed\n", cmd); + ERR("%s is failed\n", cmd); //LCOV_EXCL_LINE return FALSE; } @@ -1713,12 +1551,12 @@ gboolean _remove_nat64_interface(void) char cmd[MAX_BUF_SIZE] = {0, }; if (_flush_ip_address(NAT64_DEV) != MOBILE_AP_ERROR_NONE) - ERR("Failed to flush IP address of %s", NAT64_DEV); + ERR("Failed to flush IP address of %s", NAT64_DEV); //LCOV_EXCL_LINE snprintf(cmd, sizeof(cmd), "%s link set %s down", IP_CMD, NAT64_DEV); - SDBG("commnad [%s]", cmd); + SDBG("commnad [%s]", cmd); //LCOV_EXCL_LINE if (_execute_command(cmd)) { - ERR("%s is failed\n", cmd); + ERR("%s is failed\n", cmd); //LCOV_EXCL_LINE return FALSE; } diff --git a/src/mobileap_notification.c b/src/mobileap_notification.c index 49f4a35..981da26 100644 --- a/src/mobileap_notification.c +++ b/src/mobileap_notification.c @@ -76,7 +76,7 @@ static int __create_status_noti(const char *content) ret = notification_status_message_post(content); if (ret != NOTIFICATION_ERROR_NONE) { - ERR("notification_status_message_post() is failed : %d\n", ret); + ERR("notification_status_message_post() is failed : %d\n", ret); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } @@ -94,14 +94,14 @@ int _create_timeout_noti(mobile_ap_type_e type) char *icon_path = __get_icon_path(type); if (icon_path == NULL) { - ERR("icon_path is NULL\n"); + ERR("icon_path is NULL\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } if (timeout_noti_id) { noti = notification_load(MH_NOTI_CALLER_PKGNAME, timeout_noti_id); if (noti == NULL) { - DBG("Notification can be deleted already\n"); + DBG("Notification can be deleted already\n"); //LCOV_EXCL_LINE } else { ret = notification_get_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, &old_icon_path); @@ -112,11 +112,11 @@ int _create_timeout_noti(mobile_ap_type_e type) ret = notification_delete(noti); if (ret != NOTIFICATION_ERROR_NONE) { - ERR("Fail to notification_delete [%d]\n", ret); + ERR("Fail to notification_delete [%d]\n", ret); //LCOV_EXCL_LINE ret = notification_free(noti); if (ret != NOTIFICATION_ERROR_NONE) - ERR("Fail to notification_free [%d]\n", ret); + ERR("Fail to notification_free [%d]\n", ret); //LCOV_EXCL_LINE if (general_icon_path) free(general_icon_path); @@ -127,7 +127,7 @@ int _create_timeout_noti(mobile_ap_type_e type) ret = notification_free(noti); if (ret != NOTIFICATION_ERROR_NONE) - ERR("Fail to notification_free [%d]\n", ret); + ERR("Fail to notification_free [%d]\n", ret); //LCOV_EXCL_LINE } timeout_noti_id = 0; @@ -135,7 +135,7 @@ int _create_timeout_noti(mobile_ap_type_e type) noti = notification_create(NOTIFICATION_TYPE_NOTI); if (!noti) { - ERR("Fail to notification_create\n"); + ERR("Fail to notification_create\n"); //LCOV_EXCL_LINE if (general_icon_path) free(general_icon_path); @@ -145,20 +145,20 @@ int _create_timeout_noti(mobile_ap_type_e type) ret = notification_set_pkgname(noti, MH_NOTI_CALLER_PKGNAME); if (ret != NOTIFICATION_ERROR_NONE) { - ERR("Fail to notification_set_pkgname [%d]\n", ret); + ERR("Fail to notification_set_pkgname [%d]\n", ret); //LCOV_EXCL_LINE goto FAIL; } ret = notification_set_property(noti, NOTIFICATION_PROP_VOLATILE_DISPLAY); if (ret != NOTIFICATION_ERROR_NONE) { - ERR("Fail to notification_set_property [%d]\n", ret); + ERR("Fail to notification_set_property [%d]\n", ret); //LCOV_EXCL_LINE goto FAIL; } ret = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_SINGLE); if (ret != NOTIFICATION_ERROR_NONE) { - ERR("Fail to notification_set_layout [%d]\n", ret); + ERR("Fail to notification_set_layout [%d]\n", ret); //LCOV_EXCL_LINE goto FAIL; } @@ -166,7 +166,7 @@ int _create_timeout_noti(mobile_ap_type_e type) NOTIFICATION_IMAGE_TYPE_ICON, general_icon_path ? general_icon_path : icon_path); if (ret != NOTIFICATION_ERROR_NONE) { - ERR("Fail to notification_set_image [%d]\n", ret); + ERR("Fail to notification_set_image [%d]\n", ret); //LCOV_EXCL_LINE goto FAIL; } @@ -175,7 +175,7 @@ int _create_timeout_noti(mobile_ap_type_e type) MH_STR_CONNECTION_TIMEOUT, NOTIFICATION_VARIABLE_TYPE_NONE); if (ret != NOTIFICATION_ERROR_NONE) { - ERR("Fail to notification_set_text [%d]\n", ret); + ERR("Fail to notification_set_text [%d]\n", ret); //LCOV_EXCL_LINE goto FAIL; } @@ -184,31 +184,31 @@ int _create_timeout_noti(mobile_ap_type_e type) MH_STR_CONFIGURE_TETHERING, NOTIFICATION_VARIABLE_TYPE_NONE); if (ret != NOTIFICATION_ERROR_NONE) { - ERR("Fail to notification_set_text [%d]\n", ret); + ERR("Fail to notification_set_text [%d]\n", ret); //LCOV_EXCL_LINE goto FAIL; } ret = notification_set_text_domain(noti, MH_LOCALE_DOMAIN, MH_LOCALE_DIR); if (ret != NOTIFICATION_ERROR_NONE) { - ERR("Fail to notification_set_text_domain [%d]\n", ret); + ERR("Fail to notification_set_text_domain [%d]\n", ret); //LCOV_EXCL_LINE goto FAIL; } ret = notification_set_application(noti, MH_NOTI_LAUNCH_PKGNAME); if (ret != NOTIFICATION_ERROR_NONE) { - ERR("Fail to notification_set_application [%d]\n", ret); + ERR("Fail to notification_set_application [%d]\n", ret); //LCOV_EXCL_LINE goto FAIL; } ret = notification_insert(noti, &timeout_noti_id); if (ret != NOTIFICATION_ERROR_NONE) { - ERR("Fail to notification_insert [%d]\n", ret); + ERR("Fail to notification_insert [%d]\n", ret); //LCOV_EXCL_LINE goto FAIL; } ret = notification_free(noti); if (ret != NOTIFICATION_ERROR_NONE) { - ERR("Fail to notification_free [%d]\n", ret); + ERR("Fail to notification_free [%d]\n", ret); //LCOV_EXCL_LINE if (general_icon_path) free(general_icon_path); free(icon_path); @@ -225,7 +225,7 @@ int _create_timeout_noti(mobile_ap_type_e type) FAIL: ret = notification_free(noti); if (ret != NOTIFICATION_ERROR_NONE) - ERR("Fail to notification_free [%d]\n", ret); + ERR("Fail to notification_free [%d]\n", ret); //LCOV_EXCL_LINE if (general_icon_path) free(general_icon_path); @@ -250,7 +250,7 @@ int _delete_timeout_noti(void) -1, ¬i_list); if (ret != NOTIFICATION_ERROR_NONE) { - ERR("Fail to notification_get_detail_list\n"); + ERR("Fail to notification_get_detail_list\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } @@ -265,7 +265,7 @@ int _delete_timeout_noti(void) ret = notification_get_layout(noti, &layout); if (ret == NOTIFICATION_ERROR_NONE && layout == NOTIFICATION_LY_NOTI_EVENT_SINGLE) { - DBG("Found timeout noti\n"); + DBG("Found timeout noti\n"); //LCOV_EXCL_LINE notification_delete(noti); } } @@ -286,20 +286,20 @@ int _create_connected_noti(mobile_ap_type_e type, int count) char *icon_path = __get_icon_path(type); if (icon_path == NULL) { - ERR("icon_path is NULL\n"); + ERR("icon_path is NULL\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } noti = notification_create(NOTIFICATION_TYPE_ONGOING); if (!noti) { - ERR("Fail to notification_create\n"); + ERR("Fail to notification_create\n"); //LCOV_EXCL_LINE free(icon_path); return MOBILE_AP_ERROR_INTERNAL; } ret = notification_set_pkgname(noti, MH_NOTI_CALLER_PKGNAME); if (ret != NOTIFICATION_ERROR_NONE) { - ERR("Fail to notification_set_pkgname [%d]\n", ret); + ERR("Fail to notification_set_pkgname [%d]\n", ret); //LCOV_EXCL_LINE goto FAIL; } @@ -307,7 +307,7 @@ int _create_connected_noti(mobile_ap_type_e type, int count) NOTIFICATION_PROP_DISABLE_AUTO_DELETE | NOTIFICATION_PROP_VOLATILE_DISPLAY); if (ret != NOTIFICATION_ERROR_NONE) { - ERR("Fail to notification_set_property [%d]\n", ret); + ERR("Fail to notification_set_property [%d]\n", ret); //LCOV_EXCL_LINE goto FAIL; } @@ -320,7 +320,7 @@ int _create_connected_noti(mobile_ap_type_e type, int count) ret = notification_set_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, "Launch", NULL, b); if (ret != NOTIFICATION_ERROR_NONE) { - ERR("Failed to notification_set_execute_option"); + ERR("Failed to notification_set_execute_option"); //LCOV_EXCL_LINE goto FAIL; } @@ -328,13 +328,13 @@ int _create_connected_noti(mobile_ap_type_e type, int count) ret = notification_set_layout(noti, NOTIFICATION_LY_ONGOING_EVENT); if (ret != NOTIFICATION_ERROR_NONE) { - ERR("Fail to notification_set_image [%d]\n", ret); + ERR("Fail to notification_set_image [%d]\n", ret); //LCOV_EXCL_LINE goto FAIL; } ret = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, icon_path); if (ret != NOTIFICATION_ERROR_NONE) { - ERR("Fail to notification_set_image [%d]\n", ret); + ERR("Fail to notification_set_image [%d]\n", ret); //LCOV_EXCL_LINE goto FAIL; } @@ -343,7 +343,7 @@ int _create_connected_noti(mobile_ap_type_e type, int count) MH_STR_TETHERING, NOTIFICATION_VARIABLE_TYPE_NONE); if (ret != NOTIFICATION_ERROR_NONE) { - ERR("Fail to notification_set_text [%d]\n", ret); + ERR("Fail to notification_set_text [%d]\n", ret); //LCOV_EXCL_LINE goto FAIL; } @@ -353,38 +353,38 @@ int _create_connected_noti(mobile_ap_type_e type, int count) NOTIFICATION_VARIABLE_TYPE_INT, count, NOTIFICATION_VARIABLE_TYPE_NONE); if (ret != NOTIFICATION_ERROR_NONE) { - ERR("Fail to notification_set_text [%d]\n", ret); + ERR("Fail to notification_set_text [%d]\n", ret); //LCOV_EXCL_LINE goto FAIL; } ret = notification_set_text_domain(noti, MH_LOCALE_DOMAIN, MH_LOCALE_DIR); if (ret != NOTIFICATION_ERROR_NONE) { - ERR("Fail to notification_set_text_domain [%d]\n", ret); + ERR("Fail to notification_set_text_domain [%d]\n", ret); //LCOV_EXCL_LINE goto FAIL; } ret = notification_set_application(noti, MH_NOTI_LAUNCH_PKGNAME); if (ret != NOTIFICATION_ERROR_NONE) { - ERR("Fail to notification_set_application [%d]\n", ret); + ERR("Fail to notification_set_application [%d]\n", ret); //LCOV_EXCL_LINE goto FAIL; } ret = notification_set_display_applist(noti, NOTIFICATION_DISPLAY_APP_ALL ^ NOTIFICATION_DISPLAY_APP_INDICATOR); if (ret != NOTIFICATION_ERROR_NONE) { - ERR("Fail to notification_set_display_applist [%d]\n", ret); + ERR("Fail to notification_set_display_applist [%d]\n", ret); //LCOV_EXCL_LINE goto FAIL; } ret = notification_insert(noti, &connected_noti_id); if (ret != NOTIFICATION_ERROR_NONE) { - ERR("Fail to notification_insert [%d]\n", ret); + ERR("Fail to notification_insert [%d]\n", ret); //LCOV_EXCL_LINE goto FAIL; } ret = notification_free(noti); if (ret != NOTIFICATION_ERROR_NONE) { - ERR("Fail to notification_free [%d]\n", ret); + ERR("Fail to notification_free [%d]\n", ret); //LCOV_EXCL_LINE if (b != NULL) bundle_free(b); free(icon_path); @@ -402,7 +402,7 @@ FAIL: bundle_free(b); ret = notification_free(noti); if (ret != NOTIFICATION_ERROR_NONE) - ERR("Fail to notification_free [%d]\n", ret); + ERR("Fail to notification_free [%d]\n", ret); //LCOV_EXCL_LINE free(icon_path); return MOBILE_AP_ERROR_INTERNAL; } @@ -416,13 +416,13 @@ int _update_connected_noti(mobile_ap_type_e type, int count) char *icon_path = __get_icon_path(type); if (icon_path == NULL) { - ERR("icon_path is NULL\n"); + ERR("icon_path is NULL\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } noti = notification_load(MH_NOTI_CALLER_PKGNAME, connected_noti_id); if (noti == NULL) { - ERR("notification_load is failed\n"); + ERR("notification_load is failed\n"); //LCOV_EXCL_LINE free(icon_path); return MOBILE_AP_ERROR_INTERNAL; } @@ -430,7 +430,7 @@ int _update_connected_noti(mobile_ap_type_e type, int count) ret = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, icon_path); if (ret != NOTIFICATION_ERROR_NONE) { - ERR("Fail to notification_set_image [%d]\n", ret); + ERR("Fail to notification_set_image [%d]\n", ret); //LCOV_EXCL_LINE goto FAIL; } @@ -440,19 +440,19 @@ int _update_connected_noti(mobile_ap_type_e type, int count) NOTIFICATION_VARIABLE_TYPE_INT, count, NOTIFICATION_VARIABLE_TYPE_NONE); if (ret != NOTIFICATION_ERROR_NONE) { - ERR("Fail to notification_set_text [%d]\n", ret); + ERR("Fail to notification_set_text [%d]\n", ret); //LCOV_EXCL_LINE goto FAIL; } ret = notification_update(noti); if (ret != NOTIFICATION_ERROR_NONE) { - ERR("Fail to notification_update [%d]\n", ret); + ERR("Fail to notification_update [%d]\n", ret); //LCOV_EXCL_LINE goto FAIL; } ret = notification_free(noti); if (ret != NOTIFICATION_ERROR_NONE) { - ERR("Fail to notification_free [%d]\n", ret); + ERR("Fail to notification_free [%d]\n", ret); //LCOV_EXCL_LINE free(icon_path); return MOBILE_AP_ERROR_INTERNAL; } @@ -464,7 +464,7 @@ int _update_connected_noti(mobile_ap_type_e type, int count) FAIL: ret = notification_free(noti); if (ret != NOTIFICATION_ERROR_NONE) - ERR("Fail to notification_free [%d]\n", ret); + ERR("Fail to notification_free [%d]\n", ret); //LCOV_EXCL_LINE free(icon_path); return MOBILE_AP_ERROR_INTERNAL; @@ -478,7 +478,7 @@ int _delete_connected_noti(void) noti = notification_load(MH_NOTI_CALLER_PKGNAME, connected_noti_id); if (noti == NULL) { - ERR("notification_load is failed\n"); + ERR("notification_load is failed\n"); //LCOV_EXCL_LINE connected_noti_id = 0; return MOBILE_AP_ERROR_INTERNAL; } @@ -486,17 +486,17 @@ int _delete_connected_noti(void) ret = notification_delete(noti); if (ret != NOTIFICATION_ERROR_NONE) { - ERR("Fail to notification_delete [%d]\n", ret); + ERR("Fail to notification_delete [%d]\n", ret); //LCOV_EXCL_LINE ret = notification_free(noti); if (ret != NOTIFICATION_ERROR_NONE) - ERR("Fail to notification_free [%d]\n", ret); + ERR("Fail to notification_free [%d]\n", ret); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } ret = notification_free(noti); if (ret != NOTIFICATION_ERROR_NONE) { - ERR("Fail to notification_free [%d]\n", ret); + ERR("Fail to notification_free [%d]\n", ret); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } @@ -523,32 +523,6 @@ void _create_tethering_active_noti(void) return; } -void _create_bt_tethering_active_noti(void) -{ - int ret; - bt_adapter_visibility_mode_e mode = BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE; - int duration; - char *str1 = NULL; - char *str2 = NULL; - - if (!_mobileap_is_enabled(MOBILE_AP_STATE_WIFI) && - !_mobileap_is_enabled(MOBILE_AP_STATE_USB)) { - str1 = MH_STR_TETHERING_ACTIVE; - __create_status_noti(str1); - } - - ret = bt_adapter_get_visibility(&mode, &duration); - if (ret != BT_ERROR_NONE) - ERR("bt_adapter_get_visibility is failed 0x[%X]\n", ret); - - if (mode == BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE) { - str2 = MH_STR_BT_VISIBILITY; - __create_status_noti(str2); - } - - return; -} - void _create_security_restriction_noti(mobile_ap_type_e type) { bundle *b = NULL; @@ -579,7 +553,7 @@ void _create_security_restriction_noti(mobile_ap_type_e type) DBG("Launch security restriction alert network popup"); ret = syspopup_launch(NETPOPUP, b); if (ret < 0) - ERR("Fail to launch syspopup"); + ERR("Fail to launch syspopup"); //LCOV_EXCL_LINE bundle_free(b); diff --git a/src/mobileap_p2p.c b/src/mobileap_p2p.c index 3a3d044..95c5d46 100644 --- a/src/mobileap_p2p.c +++ b/src/mobileap_p2p.c @@ -69,6 +69,7 @@ static gboolean __p2p_tethering_error_timeout_cb(gpointer data) __disable_p2p_tethering(); wfd_client_deactivate(NULL); wfd_client_deregister_callback(); + p2p_tethering_error_timeout_id = 0; return FALSE; } @@ -100,7 +101,7 @@ static int __get_wifi_direct_state(void) ret = vconf_get_int(VCONFKEY_WIFI_DIRECT_STATE, &wfd_state); if (ret < 0) { - ERR("vconf_get_int() is failed : %d\n", ret); + ERR("vconf_get_int() is failed : %d\n", ret); //LCOV_EXCL_LINE return wfd_state; } @@ -114,7 +115,7 @@ static gboolean __is_wifi_direct_activated(void) ret = vconf_get_int(VCONFKEY_WIFI_DIRECT_STATE, &wfd_state); if (ret < 0) { - ERR("vconf_get_int() is failed : %d\n", ret); + ERR("vconf_get_int() is failed : %d\n", ret); //LCOV_EXCL_LINE return FALSE; } @@ -131,7 +132,7 @@ static gboolean __is_wifi_direct_deactivated(void) ret = vconf_get_int(VCONFKEY_WIFI_DIRECT_STATE, &wfd_state); if (ret < 0) { - ERR("vconf_get_int() is failed : %d\n", ret); + ERR("vconf_get_int() is failed : %d\n", ret); //LCOV_EXCL_LINE return FALSE; } @@ -148,7 +149,7 @@ int __enable_p2p_tethering(void) DBG("+"); /* Update global state */ if (!_mobileap_set_state(MOBILE_AP_STATE_P2P)) { - ERR("Failed to set the state"); + ERR("Failed to set the state"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_RESOURCE; } @@ -156,7 +157,7 @@ int __enable_p2p_tethering(void) _block_device_sleep(); ret = _init_tethering(MOBILE_AP_ADDRESS_TYPE_IPV4); if (ret != MOBILE_AP_ERROR_NONE) { - ERR("Failed to init tethering"); + ERR("Failed to init tethering"); //LCOV_EXCL_LINE _mobileap_clear_state(MOBILE_AP_STATE_P2P); return ret; } @@ -184,15 +185,15 @@ static int __create_p2p_tethering_group(request_data_t *request_data) if (request_data->request_type == P2P_TETHERING_ENABLE_RQ) { if (wfd_client_set_auto_group_removal(false) < 0) { - ERR("Failed to set auto group removal"); + ERR("Failed to set auto group removal"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } if (wfd_client_set_passphrase(p2p_settings.key) < 0) { - ERR("Failed to set passphrase"); + ERR("Failed to set passphrase"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } if (wfd_client_create_group(p2p_settings.ssid, request_data) < 0) { - ERR("Failed to create group"); + ERR("Failed to create group"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } } @@ -207,13 +208,15 @@ static void p2p_activated(int error, void *user_data) request_data_t *request_data = user_data; if (request_data && request_data->request_type == P2P_TETHERING_ENABLE_RQ) { - DBG("Activated by mobileap-agent"); + DBG("Activated by mobileap-agent"); //LCOV_EXCL_LINE ret = __create_p2p_tethering_group(request_data); if (ret != MOBILE_AP_ERROR_NONE) { +#ifndef TIZEN_FEATURE_UNITTEST tethering_complete_enable_p2p_tethering(request_data->object, g_context, ret); g_context = NULL; request_data->object = NULL; g_free(request_data); +#endif __handle_p2p_tethering_error(); return; } @@ -226,7 +229,7 @@ static void p2p_deactivated(int error, void *user_data) request_data_t *request_data = user_data; if (request_data && request_data->request_type == P2P_TETHERING_ENABLE_RQ) { - DBG("Deactivated by mobileap-agent to enable p2p tethering"); + DBG("Deactivated by mobileap-agent to enable p2p tethering"); //LCOV_EXCL_LINE } else if (request_data && request_data->request_type == P2P_TETHERING_DISABLE_RQ) { wfd_client_deregister_callback(); g_free(request_data); @@ -240,17 +243,20 @@ static void p2p_group_created(int error, void *user_data) request_data_t *request_data = user_data; if (request_data && request_data->request_type == P2P_TETHERING_ENABLE_RQ) { - DBG("Group created by mobileap-agent"); + DBG("Group created by mobileap-agent"); //LCOV_EXCL_LINE ret = __enable_p2p_tethering(); if (ret != MOBILE_AP_ERROR_NONE) { +#ifndef TIZEN_FEATURE_UNITTEST tethering_complete_enable_p2p_tethering(request_data->object, g_context, ret); +#endif g_context = NULL; g_free(request_data); __handle_p2p_tethering_error(); return; } - +#ifndef TIZEN_FEATURE_UNITTEST tethering_complete_enable_p2p_tethering(request_data->object, g_context, ret); +#endif g_context = NULL; g_free(request_data); DBG("P2P Tethering enabled successfully"); @@ -259,7 +265,7 @@ static void p2p_group_created(int error, void *user_data) static void p2p_group_destoyed(int error, void *user_data) { - DBG("Group Destroyed"); + DBG("Group Destroyed"); //LCOV_EXCL_LINE _remove_station_info_all(MOBILE_AP_TYPE_P2P); } @@ -270,7 +276,7 @@ static void p2p_disconnection(GVariant *parameters, void *user_data) wifi_direct_connection_state_e state; const gchar *peer_mac; - DBG("Disconnection"); + DBG("Disconnection"); //LCOV_EXCL_LINE request_data_t *request_data = user_data; if (p2p_tethering_error_timeout_id > 0) { @@ -282,11 +288,13 @@ static void p2p_disconnection(GVariant *parameters, void *user_data) } if (request_data && request_data->request_type == P2P_TETHERING_ENABLE_RQ) { - DBG("Disconnection by mobileap-agent"); + DBG("Disconnection by mobileap-agent"); //LCOV_EXCL_LINE if (__is_wifi_direct_activated() == TRUE) { ret = __create_p2p_tethering_group(request_data); if (ret != MOBILE_AP_ERROR_NONE) { +#ifndef TIZEN_FEATURE_UNITTEST tethering_complete_enable_p2p_tethering(request_data->object, g_context, ret); +#endif g_context = NULL; request_data->object = NULL; g_free(request_data); @@ -302,14 +310,15 @@ static void p2p_disconnection(GVariant *parameters, void *user_data) g_variant_get(parameters, "(ii&s)", &error, &state, &peer_mac); if (state == WIFI_DIRECT_DISCONNECTION_IND) { - DBG("client disconnected: [%s]", peer_mac); + DBG("client disconnected: [%s]", peer_mac); //LCOV_EXCL_LINE _remove_station_info(peer_mac, _slist_find_station_by_mac); } else if (state == WIFI_DIRECT_DISCONNECTION_RSP) { - DBG("remove all clients info !!"); + DBG("remove all clients info !!"); //LCOV_EXCL_LINE _remove_station_info_all(MOBILE_AP_TYPE_P2P); } } +//LCOV_EXCL_START static void p2p_connection(GVariant *parameters, void *user_data) { int error; @@ -330,14 +339,14 @@ static void p2p_connection(GVariant *parameters, void *user_data) return; if (peer_mac == NULL) { - ERR("Client mac is NULL !!!"); + ERR("Client mac is NULL !!!"); //LCOV_EXCL_LINE return; } - DBG("client connected: [%s]", peer_mac); + DBG("client connected: [%s]", peer_mac); //LCOV_EXCL_LINE info = (mobile_ap_station_info_t *)g_malloc(sizeof(mobile_ap_station_info_t)); if (info == NULL) { - ERR("malloc failed\n"); + ERR("malloc failed\n"); //LCOV_EXCL_LINE return; } @@ -351,7 +360,7 @@ static void p2p_connection(GVariant *parameters, void *user_data) /* Add the client station here, since station is now associated to the p2p group */ if (_add_station_info(info) != MOBILE_AP_ERROR_NONE) { - ERR("_add_station_info is failed\n"); + ERR("_add_station_info is failed\n"); //LCOV_EXCL_LINE if (info) { g_free(info->hostname); g_free(info); @@ -373,14 +382,15 @@ static void p2p_ip_assigned(GVariant *parameters, void *user_data) if (_get_station_info(peer_mac, _slist_find_station_by_mac, &info) != MOBILE_AP_ERROR_NONE) { - ERR("client not found with mac [%s]", peer_mac); + ERR("client not found with mac [%s]", peer_mac); //LCOV_EXCL_LINE return; } g_strlcpy(info->ip, ip_assigned, sizeof(info->ip)); - DBG("client ip assigned: mac [%s] ip [%s]", peer_mac, ip_assigned); + DBG("client ip assigned: mac [%s] ip [%s]", peer_mac, ip_assigned); //LCOV_EXCL_LINE _send_dbus_station_info("DhcpConnected", info); } +//LCOV_EXCL_STOP static int activate_wifi_direct(request_data_t *request_data) { @@ -390,20 +400,20 @@ static int activate_wifi_direct(request_data_t *request_data) switch (wfd_state) { case VCONFKEY_WIFI_DIRECT_DEACTIVATED: - DBG("activate wifi direct"); + DBG("activate wifi direct"); //LCOV_EXCL_LINE if (wfd_client_activate(request_data) < 0) { - ERR("Failed to activate wifi direct"); + ERR("Failed to activate wifi direct"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } break; case VCONFKEY_WIFI_DIRECT_ACTIVATED: - DBG("wifi direct already activated"); + DBG("wifi direct already activated"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_ALREADY_ENABLED; case VCONFKEY_WIFI_DIRECT_CONNECTED: case VCONFKEY_WIFI_DIRECT_GROUP_OWNER: - DBG("disconnect all"); + DBG("disconnect all"); //LCOV_EXCL_LINE if (wfd_client_disconnect_all(request_data) < 0) { - ERR("Failed to disconnect all"); + ERR("Failed to disconnect all"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } break; @@ -412,10 +422,10 @@ static int activate_wifi_direct(request_data_t *request_data) case VCONFKEY_WIFI_DIRECT_ACTIVATING: case VCONFKEY_WIFI_DIRECT_CONNECTING: case VCONFKEY_WIFI_DIRECT_DISCONNECTING: - DBG("wifi direct operation not permitted"); + DBG("wifi direct operation not permitted"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_PERMISSION_DENIED; default: - DBG("wifi direct unknown state found"); + DBG("wifi direct unknown state found"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } @@ -454,7 +464,7 @@ gboolean tethering_p2p_enable(Tethering *obj, DBG("+\n"); request_data_t *request_data = g_try_malloc0(sizeof(request_data_t)); if (request_data == NULL) { - ERR("Error: malloc failed!!"); + ERR("Error: malloc failed!!"); //LCOV_EXCL_LINE error_code = MOBILE_AP_ERROR_INTERNAL; goto done; } @@ -468,16 +478,18 @@ gboolean tethering_p2p_enable(Tethering *obj, #endif if (_mobileap_is_enabled(MOBILE_AP_STATE_P2P)) { - DBG("Tethering is already enabled"); + DBG("Tethering is already enabled"); //LCOV_EXCL_LINE +#ifndef TIZEN_FEATURE_UNITTEST tethering_complete_enable_p2p_tethering(obj, context, MOBILE_AP_ERROR_ALREADY_ENABLED); +#endif request_data->object = NULL; g_free(request_data); return TRUE; } if (g_context) { - ERR("P2P Tethering turning on\n"); + ERR("P2P Tethering turning on\n"); //LCOV_EXCL_LINE error_code = MOBILE_AP_ERROR_IN_PROGRESS; request_data->object = NULL; g_free(request_data); @@ -489,7 +501,7 @@ gboolean tethering_p2p_enable(Tethering *obj, init_p2p_events(); if (!set_p2p_settings(ssid, key, channel)) { - ERR("Invalid p2p settings\n"); + ERR("Invalid p2p settings\n"); //LCOV_EXCL_LINE error_code = MOBILE_AP_ERROR_INTERNAL; request_data->object = NULL; g_free(request_data); @@ -499,7 +511,7 @@ gboolean tethering_p2p_enable(Tethering *obj, /* Activate wifi direct if not */ if (__is_wifi_direct_activated() == FALSE) { if (activate_wifi_direct(request_data) != MOBILE_AP_ERROR_NONE) { - ERR("permission denied !!"); + ERR("permission denied !!"); //LCOV_EXCL_LINE error_code = MOBILE_AP_ERROR_PERMISSION_DENIED; request_data->object = NULL; g_free(request_data); @@ -518,7 +530,9 @@ gboolean tethering_p2p_enable(Tethering *obj, rv = TRUE; done: +#ifndef TIZEN_FEATURE_UNITTEST tethering_complete_enable_p2p_tethering(obj, context, error_code); +#endif g_context = NULL; DBG("-\n"); return rv; @@ -532,9 +546,11 @@ gboolean tethering_p2p_disable(Tethering *obj, if (_mobileap_is_disabled()) { ERR("Tethering is not enabled"); +#ifndef TIZEN_FEATURE_UNITTEST tethering_complete_disable_p2p_tethering(obj, context, MOBILE_AP_DISABLE_P2P_TETHERING_CFM, MOBILE_AP_ERROR_NOT_ENABLED); +#endif return TRUE; } @@ -542,18 +558,21 @@ gboolean tethering_p2p_disable(Tethering *obj, if (__is_wifi_direct_deactivated() == TRUE) { ERR("wifi direct already deactivated"); +#ifndef TIZEN_FEATURE_UNITTEST tethering_complete_disable_p2p_tethering(obj, context, MOBILE_AP_DISABLE_P2P_TETHERING_CFM, MOBILE_AP_ERROR_NONE); +#endif __disable_p2p_tethering(); return TRUE; } g_context = context; +#ifndef TIZEN_FEATURE_UNITTEST tethering_complete_disable_p2p_tethering(obj, context, MOBILE_AP_DISABLE_P2P_TETHERING_CFM, MOBILE_AP_ERROR_NONE); - +#endif __handle_p2p_tethering_error(); g_context = NULL; diff --git a/src/mobileap_softap.c b/src/mobileap_softap.c index 844722e..741dd5f 100755 --- a/src/mobileap_softap.c +++ b/src/mobileap_softap.c @@ -80,7 +80,7 @@ static gboolean __hostapd_connect_timer_cb(gpointer user_data); static char *__find_first_caps_char(char *str) { if (str == NULL) { - ERR("NULL string passes\n"); + ERR("NULL string passes\n"); //LCOV_EXCL_LINE return NULL; } @@ -110,7 +110,7 @@ static int __issue_ioctl(int sock_fd, char *if_name, char *cmd, char *buf) /* Issue ioctl */ if ((ioctl(sock_fd, SIOCSIWPRIV, &iwr)) < 0) { - ERR("ioctl failed...!!!\n"); + ERR("ioctl failed...!!!\n"); //LCOV_EXCL_LINE ret_val = MOBILE_AP_ERROR_INTERNAL; } @@ -134,7 +134,7 @@ static int __get_psk_hexascii(const char *pass, const unsigned char *salt, if (!PKCS5_PBKDF2_HMAC_SHA1(pass, strlen(pass), salt, strlen((const char *)salt), PSK_ITERATION_COUNT, sizeof(buf), buf)) { - ERR("Getting psk is failed\n"); + ERR("Getting psk is failed\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_RESOURCE; } @@ -155,7 +155,7 @@ static int __make_hostapd_dir(void) if (mkdir(HOSTAPD_NETWORK_DIR, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0) { if (errno != EEXIST) { - ERR("Failed to create network directory"); + ERR("Failed to create network directory"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_RESOURCE; } } @@ -163,7 +163,7 @@ static int __make_hostapd_dir(void) if (mkdir(HOSTAPD_DEBUG_DIR, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0) { if (errno != EEXIST) - ERR("Failed to create debug directory"); + ERR("Failed to create debug directory"); //LCOV_EXCL_LINE /* Although debug directory is not created, hostapd will be launched. */ } @@ -230,7 +230,7 @@ static int __execute_hostapd(const mobile_ap_type_e type, softap_settings_t *set key, sizeof(key)); if (ret != MOBILE_AP_ERROR_NONE) { g_free(conf); - ERR("hex conversion failed\n"); + ERR("hex conversion failed\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_RESOURCE; } snprintf(buf, sizeof(buf), @@ -243,7 +243,7 @@ static int __execute_hostapd(const mobile_ap_type_e type, softap_settings_t *set fp = fopen(HOSTAPD_CONF_FILE, "w"); if (NULL == fp) { - ERR("Could not create the file.\n"); + ERR("Could not create the file.\n"); //LCOV_EXCL_LINE g_free(conf); return MOBILE_AP_ERROR_RESOURCE; } @@ -256,7 +256,7 @@ static int __execute_hostapd(const mobile_ap_type_e type, softap_settings_t *set pid = fork(); if (pid < 0) { - ERR("fork failed\n"); + ERR("fork failed\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_RESOURCE; } @@ -265,10 +265,10 @@ static int __execute_hostapd(const mobile_ap_type_e type, softap_settings_t *set HOSTAPD_CONF_FILE, "-f", HOSTAPD_DEBUG_FILE, "-ddd", (char *)NULL)) { - ERR("execl failed\n"); + ERR("execl failed\n"); //LCOV_EXCL_LINE } - ERR("Should not get here!"); + ERR("Should not get here!"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_RESOURCE; } @@ -278,6 +278,7 @@ static int __execute_hostapd(const mobile_ap_type_e type, softap_settings_t *set } #ifdef TIZEN_FEATURE_WLAN_BOARD_SPRD +//LCOV_EXCL_START static int __execute_hostapd_wps(const mobile_ap_type_e type, softap_settings_t *settings) { DBG("+\n"); @@ -297,7 +298,7 @@ static int __execute_hostapd_wps(const mobile_ap_type_e type, softap_settings_t (const unsigned char *)settings->ssid, key, sizeof(key)); if (ret != MOBILE_AP_ERROR_NONE) { - ERR("hex conversion failed\n"); + ERR("hex conversion failed\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_RESOURCE; } /* Default conf. */ @@ -327,7 +328,7 @@ static int __execute_hostapd_wps(const mobile_ap_type_e type, softap_settings_t fp = fopen(HOSTAPD_CONF_FILE, "w"); if (NULL == fp) { - ERR("Could not create the file.\n"); + ERR("Could not create the file.\n"); //LCOV_EXCL_LINE g_free(conf); return MOBILE_AP_ERROR_RESOURCE; } @@ -340,7 +341,7 @@ static int __execute_hostapd_wps(const mobile_ap_type_e type, softap_settings_t pid = fork(); if (pid < 0) { - ERR("fork failed\n"); + ERR("fork failed\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_RESOURCE; } @@ -349,9 +350,9 @@ static int __execute_hostapd_wps(const mobile_ap_type_e type, softap_settings_t HOSTAPD_CONF_FILE, "-f", HOSTAPD_DEBUG_FILE, "-ddd", (char *)NULL)) - ERR("execl failed\n"); + ERR("execl failed\n"); //LCOV_EXCL_LINE - ERR("Should not get here!"); + ERR("Should not get here!"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_RESOURCE; } @@ -359,6 +360,7 @@ static int __execute_hostapd_wps(const mobile_ap_type_e type, softap_settings_t return MOBILE_AP_ERROR_NONE; } +//LCOV_EXCL_STOP #endif static int __terminate_hostapd() @@ -369,7 +371,7 @@ static int __terminate_hostapd() char buf[MAX_BUF_SIZE] = {0, }; if (hostapd_pid == 0) { - ERR("There is no hostapd\n"); + ERR("There is no hostapd\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_NONE; } @@ -380,7 +382,7 @@ static int __terminate_hostapd() ret = unlink(HOSTAPD_CONF_FILE); if (ret < 0) { strerror_r(errno, buf, sizeof(buf)); - ERR("unlink is failed : %s\n", buf); + ERR("unlink is failed : %s\n", buf); //LCOV_EXCL_LINE } return MOBILE_AP_ERROR_NONE; @@ -411,7 +413,7 @@ static int __send_hostapd_req(int fd, const char *req, const int req_len, ret = send(fd, req, req_len, 0); if (ret < 0) { strerror_r(errno, err_buf, sizeof(err_buf)); - ERR("send is failed : %s\n", err_buf); + ERR("send is failed : %s\n", err_buf); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } @@ -422,10 +424,10 @@ static int __send_hostapd_req(int fd, const char *req, const int req_len, if (ret < 0) { return MOBILE_AP_ERROR_INTERNAL; } else if (ret == 0) { - ERR("There is no response from hostapd\n"); + ERR("There is no response from hostapd\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } else if (!FD_ISSET(fd, &fds)) { - ERR("Unknown case\n"); + ERR("Unknown case\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } @@ -436,14 +438,14 @@ static int __send_hostapd_req(int fd, const char *req, const int req_len, } if (buf[0] == '<') { - ERR("Unsolicited message\n"); + ERR("Unsolicited message\n"); //LCOV_EXCL_LINE continue; } *buf_len = ret; buf[ret] = '\0'; if (ret == 0) - ERR("socket is closed\n"); + ERR("socket is closed\n"); //LCOV_EXCL_LINE break; } @@ -468,7 +470,7 @@ static int __open_hostapd_intf(int *fd, const char *intf) *fd = socket(PF_UNIX, SOCK_DGRAM, 0); if (*fd < 0) { - ERR("socket is failed\n"); + ERR("socket is failed\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } @@ -479,7 +481,7 @@ static int __open_hostapd_intf(int *fd, const char *intf) unlink(src.sun_path); if (bind(*fd, (struct sockaddr *)&src, sizeof(src)) < 0) { - ERR("bind is failed\n"); + ERR("bind is failed\n"); //LCOV_EXCL_LINE close(*fd); *fd = -1; unlink(src.sun_path); @@ -500,7 +502,7 @@ static int __open_hostapd_intf(int *fd, const char *intf) return MOBILE_AP_ERROR_NONE; FAIL: - ERR("Cannot make connection to hostapd\n"); + ERR("Cannot make connection to hostapd\n"); //LCOV_EXCL_LINE close(*fd); *fd = -1; unlink(src.sun_path); @@ -513,7 +515,7 @@ static int __close_hostapd_intf(int *fd) DBG("+\n"); if (fd == NULL) { - ERR("fd is NULL\n"); + ERR("fd is NULL\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INVALID_PARAM; } @@ -524,6 +526,7 @@ static int __close_hostapd_intf(int *fd) return MOBILE_AP_ERROR_NONE; } +//LCOV_EXCL_START static gboolean __hostapd_monitor_cb(GIOChannel *source) { DBG("+\n"); @@ -546,7 +549,7 @@ static gboolean __hostapd_monitor_cb(GIOChannel *source) ret = g_io_channel_read(hostapd_io_channel, buf, HOSTAPD_REQ_MAX_LEN, &read); if (ret != G_IO_ERROR_NONE) { - ERR("g_io_channel_read is failed\n"); + ERR("g_io_channel_read is failed\n"); //LCOV_EXCL_LINE return FALSE; } #else @@ -556,11 +559,11 @@ static gboolean __hostapd_monitor_cb(GIOChannel *source) ios = g_io_channel_read_chars(hostapd_io_channel, buf, HOSTAPD_REQ_MAX_LEN, &read, &err); if (err != NULL) { - ERR("g_io_channel_read_chars is failed : %s\n", err->message); + ERR("g_io_channel_read_chars is failed : %s\n", err->message); //LCOV_EXCL_LINE g_error_free(err); return FALSE; } else if (ios != G_IO_STATUS_NORMAL) { - ERR("g_io_channel_read_chars is failed : %d\n", ios); + ERR("g_io_channel_read_chars is failed : %d\n", ios); //LCOV_EXCL_LINE return FALSE; } #endif @@ -581,7 +584,7 @@ static gboolean __hostapd_monitor_cb(GIOChannel *source) if (!strncmp(pbuf, HOSTAPD_STA_CONN, HOSTAPD_STA_CONN_LEN)) { pbuf = pbuf + HOSTAPD_STA_CONN_LEN; if (!pbuf || !*pbuf) { - ERR("No mac address\n"); + ERR("No mac address\n"); //LCOV_EXCL_LINE return TRUE; } @@ -643,7 +646,7 @@ static gboolean __hostapd_monitor_cb(GIOChannel *source) } if (mac == NULL) { - ERR("strdup failed\n"); + ERR("strdup failed\n"); //LCOV_EXCL_LINE return TRUE; } @@ -690,11 +693,12 @@ static gboolean __hostapd_monitor_cb(GIOChannel *source) DONE: return TRUE; } +//LCOV_EXCL_STOP static int __open_hostapd_monitor(int *fd) { if (fd == NULL) { - ERR("fd is NULL\n"); + ERR("fd is NULL\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INVALID_PARAM; } @@ -704,13 +708,13 @@ static int __open_hostapd_monitor(int *fd) int buf_len = 0; if (__open_hostapd_intf(fd, MH_MONITOR_INTF) != MOBILE_AP_ERROR_NONE) { - ERR("__open_hostapd_intf() is failed\n"); + ERR("__open_hostapd_intf() is failed\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } hostapd_io_channel = g_io_channel_unix_new(*fd); if (hostapd_io_channel == NULL) { - ERR("g_io_channel_unix_new is failed\n"); + ERR("g_io_channel_unix_new is failed\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } @@ -813,7 +817,7 @@ static int __mh_core_softap_firmware_start(void) message = dbus_message_new_method_call(NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH, NETCONFIG_WIFI_INTERFACE ".Firmware", "Start"); if (message == NULL) { - ERR("Failed DBus method call"); + ERR("Failed DBus method call"); //LCOV_EXCL_LINE dbus_connection_unref(connection); return -EIO; } @@ -830,7 +834,7 @@ static int __mh_core_softap_firmware_start(void) /* softap already enabled */ } else { ERR("dbus_connection_send_with_reply_and_block() failed. " - "DBus error [%s: %s]", error.name, error.message); + "DBus error [%s: %s]", error.name, error.message); //LCOV_EXCL_LINE err = -EIO; @@ -862,14 +866,14 @@ static int __mh_core_softap_firmware_stop(void) connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL); if (connection == NULL) { - ERR("Failed to get system bus"); + ERR("Failed to get system bus"); //LCOV_EXCL_LINE return -EIO; } message = dbus_message_new_method_call(NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH, NETCONFIG_WIFI_INTERFACE ".Firmware", "Stop"); if (message == NULL) { - ERR("Failed DBus method call"); + ERR("Failed DBus method call"); //LCOV_EXCL_LINE dbus_connection_unref(connection); return -EIO; } @@ -886,7 +890,7 @@ static int __mh_core_softap_firmware_stop(void) /* softap already disabled */ } else { ERR("dbus_connection_send_with_reply_and_block() failed. " - "DBus error [%s: %s]", error.name, error.message); + "DBus error [%s: %s]", error.name, error.message); //LCOV_EXCL_LINE err = -EIO; @@ -931,9 +935,10 @@ int _mh_core_enable_softap(const mobile_ap_type_e type, softap_settings_t *setti drv_interface = __get_drv_interface(); switch (drv_interface) { +#ifndef TIZEN_FEATURE_UNITTEST case MOBILE_AP_WEXT: if ((sock_fd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) { - ERR("Failed to open socket...!!!\n"); + ERR("Failed to open socket...!!!\n"); //LCOV_EXCL_LINE ret_status = MOBILE_AP_ERROR_RESOURCE; break; } @@ -956,7 +961,7 @@ int _mh_core_enable_softap(const mobile_ap_type_e type, softap_settings_t *setti MOBILE_AP_MAX_WIFI_STA, settings->hide_mode); ret_status = __issue_ioctl(sock_fd, if_name, cmd, buf); if (ret_status != MOBILE_AP_ERROR_NONE) { - ERR("__issue_ioctl failed...!!!\n"); + ERR("__issue_ioctl failed...!!!\n"); //LCOV_EXCL_LINE close(sock_fd); break; } @@ -965,7 +970,7 @@ int _mh_core_enable_softap(const mobile_ap_type_e type, softap_settings_t *setti snprintf(cmd, MAX_BUF_SIZE, "ASCII_CMD=AP_BSS_START"); ret_status = __issue_ioctl(sock_fd, if_name, cmd, buf); if (ret_status != MOBILE_AP_ERROR_NONE) { - ERR("__issue_ioctl failed...!!!\n"); + ERR("__issue_ioctl failed...!!!\n"); //LCOV_EXCL_LINE close(sock_fd); break; } @@ -975,25 +980,25 @@ int _mh_core_enable_softap(const mobile_ap_type_e type, softap_settings_t *setti ret_status = _mh_core_set_ip_address(SOFTAP_IF, IP_ADDRESS_SOFTAP); if (ret_status != MOBILE_AP_ERROR_NONE) { - ERR("_mh_core_set_ip_address of SOFTAP_IF is failed\n"); + ERR("_mh_core_set_ip_address of SOFTAP_IF is failed\n"); //LCOV_EXCL_LINE break; } ret_status = _mh_core_set_ip_address(WIFI_IF, IP_ADDRESS_WIFI); if (ret_status != MOBILE_AP_ERROR_NONE) { - ERR("_mh_core_set_ip_address of WIFI_IF is failed\n"); + ERR("_mh_core_set_ip_address of WIFI_IF is failed\n"); //LCOV_EXCL_LINE break; } break; - +#endif case MOBILE_AP_NL80211: #ifdef TIZEN_FEATURE_ENABLE_IPV6 if (settings->address_type == MOBILE_AP_ADDRESS_TYPE_IPV6) { /* Setup IPv6 address for wlan0 */ ret_status = _get_hw_address(WIFI_IF, &wlan_hw_addr); if (ret_status != MOBILE_AP_ERROR_NONE || wlan_hw_addr == NULL) { - ERR("Failed to get network hw address"); + ERR("Failed to get network hw address"); //LCOV_EXCL_LINE break; } @@ -1005,7 +1010,7 @@ int _mh_core_enable_softap(const mobile_ap_type_e type, softap_settings_t *setti break; ret_status = _mh_core_set_ipv6_address(WIFI_IF, wlan_ipv6_address); if (ret_status != MOBILE_AP_ERROR_NONE) { - ERR("Failed to set ip address"); + ERR("Failed to set ip address"); //LCOV_EXCL_LINE break; } } @@ -1019,7 +1024,7 @@ int _mh_core_enable_softap(const mobile_ap_type_e type, softap_settings_t *setti ret_status = _mh_core_set_ip_address(WIFI_IF, IP_ADDRESS_SOFTAP); if (ret_status != MOBILE_AP_ERROR_NONE) { - ERR("_mh_core_set_ip_address is failed\n"); + ERR("_mh_core_set_ip_address is failed\n"); //LCOV_EXCL_LINE break; } #ifdef TIZEN_FEATURE_ENABLE_IPV6 @@ -1028,7 +1033,7 @@ int _mh_core_enable_softap(const mobile_ap_type_e type, softap_settings_t *setti if (!g_strcmp0(settings->security_type, "wps")) { #ifdef TIZEN_FEATURE_WLAN_BOARD_SPRD - ret_status = __execute_hostapd_wps(type, settings); + ret_status = __execute_hostapd_wps(type, settings); //LCOV_EXCL_LINE #else ret_status = MOBILE_AP_ERROR_NOT_PERMITTED; #endif @@ -1037,20 +1042,20 @@ int _mh_core_enable_softap(const mobile_ap_type_e type, softap_settings_t *setti } if (ret_status != MOBILE_AP_ERROR_NONE) { - ERR("__execute_hostapd is failed\n"); + ERR("__execute_hostapd is failed\n"); //LCOV_EXCL_LINE break; } ret_status = __open_hostapd_intf(&hostapd_ctrl_fd, MH_CTRL_INTF); if (ret_status != MOBILE_AP_ERROR_NONE) { - ERR("__open_hostapd_intf is failed\n"); + ERR("__open_hostapd_intf is failed\n"); //LCOV_EXCL_LINE __terminate_hostapd(); break; } ret_status = __open_hostapd_monitor(&hostapd_monitor_fd); if (ret_status != MOBILE_AP_ERROR_NONE) { - ERR("__open_hostapd_monitor is failed\n"); + ERR("__open_hostapd_monitor is failed\n"); //LCOV_EXCL_LINE __close_hostapd_intf(&hostapd_ctrl_fd); __terminate_hostapd(); break; @@ -1059,7 +1064,7 @@ int _mh_core_enable_softap(const mobile_ap_type_e type, softap_settings_t *setti break; default: - ERR("Unknown driver interface : %d\n", drv_interface); + ERR("Unknown driver interface : %d\n", drv_interface); //LCOV_EXCL_LINE break; } @@ -1085,9 +1090,10 @@ int _mh_core_disable_softap(void) drv_interface = __get_drv_interface(); switch (drv_interface) { +#ifndef TIZEN_FEATURE_UNITTEST case MOBILE_AP_WEXT: if ((sock_fd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) { - ERR("Failed to open socket...!!!\n"); + ERR("Failed to open socket...!!!\n"); //LCOV_EXCL_LINE ret_status = MOBILE_AP_ERROR_RESOURCE; break; } @@ -1096,30 +1102,30 @@ int _mh_core_disable_softap(void) snprintf(cmd, MAX_BUF_SIZE, "ASCII_CMD=AP_BSS_STOP"); ret_status = __issue_ioctl(sock_fd, if_name, cmd, buf); if (ret_status != MOBILE_AP_ERROR_NONE) { - ERR("__issue_ioctl failed...!!!\n"); + ERR("__issue_ioctl failed...!!!\n"); //LCOV_EXCL_LINE close(sock_fd); break; } close(sock_fd); break; - +#endif case MOBILE_AP_NL80211: ret_status = __close_hostapd_intf(&hostapd_ctrl_fd); if (ret_status != MOBILE_AP_ERROR_NONE) - ERR("hostapd termination is failed\n"); + ERR("hostapd termination is failed\n"); //LCOV_EXCL_LINE ret_status = __close_hostapd_monitor(&hostapd_monitor_fd); if (ret_status != MOBILE_AP_ERROR_NONE) - ERR("hostapd termination is failed\n"); + ERR("hostapd termination is failed\n"); //LCOV_EXCL_LINE ret_status = __terminate_hostapd(); if (ret_status != MOBILE_AP_ERROR_NONE) - ERR("hostapd termination is failed\n"); + ERR("hostapd termination is failed\n"); //LCOV_EXCL_LINE break; default: - ERR("Unknown driver interface : %d\n", drv_interface); + ERR("Unknown driver interface : %d\n", drv_interface); //LCOV_EXCL_LINE break; } @@ -1143,7 +1149,7 @@ int _mh_core_set_wps_pin(const char *wps_pin) ret = __send_hostapd_req(hostapd_ctrl_fd, req, strlen(req), buf, &buf_len); if (ret != MOBILE_AP_ERROR_NONE) { - ERR("__send_to_hostapd is failed : %d\n", ret); + ERR("__send_to_hostapd is failed : %d\n", ret); //LCOV_EXCL_LINE return ret; } @@ -1163,7 +1169,7 @@ int _mh_core_push_wps_button(void) ret = __send_hostapd_req(hostapd_ctrl_fd, req, strlen(req), buf, &buf_len); if (ret != MOBILE_AP_ERROR_NONE) { - ERR("__send_to_hostapd is failed : %d\n", ret); + ERR("__send_to_hostapd is failed : %d\n", ret); //LCOV_EXCL_LINE return ret; } @@ -1171,6 +1177,7 @@ int _mh_core_push_wps_button(void) } #endif +#ifndef TIZEN_FEATURE_UNITTEST static int __get_device_info_by_wext(softap_device_info_t *di) { int sock_fd = 0; @@ -1221,6 +1228,7 @@ static int __get_device_info_by_wext(softap_device_info_t *di) return ret; } +#endif static int __get_device_info_by_nl80211(softap_device_info_t *di) { @@ -1235,13 +1243,13 @@ static int __get_device_info_by_nl80211(softap_device_info_t *di) ret = __send_hostapd_req(hostapd_ctrl_fd, req, strlen(req), buf, &buf_len); if (ret != MOBILE_AP_ERROR_NONE) { - ERR("__send_hostapd_req is failed : %d\n", ret); + ERR("__send_hostapd_req is failed : %d\n", ret); //LCOV_EXCL_LINE return ret; } DBG("The number of station : %s\n", buf); if (atoi(buf) == 0) { - DBG("There is no station\n"); + DBG("There is no station\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_NONE; } @@ -1285,12 +1293,12 @@ static int __enable_port_forwarding(void) fd = open(IP_FORWARD, O_WRONLY); if (fd < 0) { - ERR("open failed\n"); + ERR("open failed\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_RESOURCE; } if (write(fd, "1", 1) != 1) { - ERR("write failed\n"); + ERR("write failed\n"); //LCOV_EXCL_LINE close(fd); return MOBILE_AP_ERROR_INTERNAL; } @@ -1305,12 +1313,12 @@ static int __disable_port_forwarding(void) fd = open(IP_FORWARD, O_WRONLY); if (fd < 0) { - ERR("open failed\n"); + ERR("open failed\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_RESOURCE; } if (write(fd, "0", 1) != 1) { - ERR("write failed\n"); + ERR("write failed\n"); //LCOV_EXCL_LINE close(fd); return MOBILE_AP_ERROR_INTERNAL; } @@ -1319,32 +1327,6 @@ static int __disable_port_forwarding(void) return MOBILE_AP_ERROR_NONE; } -int _mh_core_get_device_info(softap_device_info_t *di) -{ - if (di == NULL) { - ERR("Invalid param\n"); - return MOBILE_AP_ERROR_INVALID_PARAM; - } - - int ret = MOBILE_AP_ERROR_NONE; - - switch (__get_drv_interface()) { - case MOBILE_AP_WEXT: - ret = __get_device_info_by_wext(di); - break; - - case MOBILE_AP_NL80211: - ret = __get_device_info_by_nl80211(di); - break; - - default: - ERR("Unknown interface\n"); - break; - } - - return ret; -} - int _mh_core_execute_dhcp_server(gchar *softap_rangestart, gchar *softap_rangestop) { char buf[DNSMASQ_CONF_LEN] = ""; @@ -1352,12 +1334,12 @@ int _mh_core_execute_dhcp_server(gchar *softap_rangestart, gchar *softap_rangest pid_t pid; if (remove(DNSMASQ_LEASES_FILE) < 0) - ERR("Failed to remove %s", DNSMASQ_LEASES_FILE); + ERR("Failed to remove %s", DNSMASQ_LEASES_FILE); //LCOV_EXCL_LINE if (dnsmasq_pid == 0) { fp = fopen(DNSMASQ_CONF_FILE, "w"); if (NULL == fp) { - ERR("Could not create the file.\n"); + ERR("Could not create the file.\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_RESOURCE; } @@ -1373,7 +1355,7 @@ int _mh_core_execute_dhcp_server(gchar *softap_rangestart, gchar *softap_rangest pid = fork(); if (pid < 0) { - ERR("fork failed\n"); + ERR("fork failed\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_RESOURCE; } @@ -1385,17 +1367,17 @@ int _mh_core_execute_dhcp_server(gchar *softap_rangestart, gchar *softap_rangest if (execl("/usr/bin/dnsmasq", "/usr/bin/dnsmasq", "-d", "-p", "0", "-C", DNSMASQ_CONF_FILE, (char *)NULL)) { - ERR("execl failed\n"); + ERR("execl failed\n"); //LCOV_EXCL_LINE } - ERR("Should not get here!"); + ERR("Should not get here!"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_RESOURCE; } dnsmasq_pid = pid; - DBG("dnsmasq[%d] is enabled", dnsmasq_pid); + DBG("dnsmasq[%d] is enabled", dnsmasq_pid); //LCOV_EXCL_LINE } else { - DBG("DNS-SERVER is already running.\n"); + DBG("DNS-SERVER is already running.\n"); //LCOV_EXCL_LINE } return MOBILE_AP_ERROR_NONE; @@ -1407,7 +1389,7 @@ int _mh_core_terminate_dhcp_server(void) char buf[MAX_BUF_SIZE] = {0, }; if (dnsmasq_pid == 0) { - ERR("There is no dnsmasq\n"); + ERR("There is no dnsmasq\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_NONE; } @@ -1418,7 +1400,7 @@ int _mh_core_terminate_dhcp_server(void) ret = unlink(DNSMASQ_CONF_FILE); if (ret < 0) { strerror_r(errno, buf, sizeof(buf)); - ERR("unlink is failed : %s\n", buf); + ERR("unlink is failed : %s\n", buf); //LCOV_EXCL_LINE } DBG("dnsmasq is disabled"); @@ -1437,13 +1419,13 @@ static int _mh_core_enable_p2p_masquerade(const char *ext_if) int ret; if (ext_if == NULL || strlen(ext_if) == 0) { - ERR("ext_if[%s] is invalid\n", ext_if); + ERR("ext_if[%s] is invalid\n", ext_if); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INVALID_PARAM; } ret = __enable_port_forwarding(); if (ret != MOBILE_AP_ERROR_NONE) { - ERR("Error: Failed to enable port forwarding!!!"); + ERR("Error: Failed to enable port forwarding!!!"); //LCOV_EXCL_LINE return ret; } @@ -1498,12 +1480,12 @@ int _mh_core_enable_masquerade(const char *ext_if) int ret; if (ext_if == NULL || strlen(ext_if) == 0) { - ERR("ext_if[%s] is invalid\n", ext_if); + ERR("ext_if[%s] is invalid\n", ext_if); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INVALID_PARAM; } if (_mobileap_is_enabled_by_type(MOBILE_AP_TYPE_P2P) == TRUE) { - DBG("enable p2p tethering masquerade for interface %s", ext_if); + DBG("enable p2p tethering masquerade for interface %s", ext_if); //LCOV_EXCL_LINE ret = _mh_core_enable_p2p_masquerade(ext_if); return ret; } @@ -1512,12 +1494,12 @@ int _mh_core_enable_masquerade(const char *ext_if) fd = open(IP_FORWARD, O_WRONLY); if (fd < 0) { - ERR("open failed\n"); + ERR("open failed\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_RESOURCE; } if (write(fd, "1", 1) != 1) { - ERR("write failed\n"); + ERR("write failed\n"); //LCOV_EXCL_LINE close(fd); return MOBILE_AP_ERROR_INTERNAL; } @@ -1572,7 +1554,7 @@ int _mh_core_enable_masquerade(const char *ext_if) int _mh_core_disable_masquerade(const char *ext_if) { if (ext_if == NULL || strlen(ext_if) == 0) { - ERR("ext_if[%s] is invalid\n", ext_if); + ERR("ext_if[%s] is invalid\n", ext_if); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INVALID_PARAM; } @@ -1580,12 +1562,12 @@ int _mh_core_disable_masquerade(const char *ext_if) fd = open(IP_FORWARD, O_WRONLY); if (fd < 0) { - ERR("open failed\n"); + ERR("open failed\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_RESOURCE; } if (write(fd, "0", 1) != 1) { - ERR("write failed\n"); + ERR("write failed\n"); //LCOV_EXCL_LINE close(fd); return MOBILE_AP_ERROR_INTERNAL; } @@ -1613,7 +1595,7 @@ int _mh_core_set_ip_address(const char *if_name, const in_addr_t ip) SDBG("if_name : %s ip address : 0x%X\n", if_name, ip); if ((sock_fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { - ERR("socket open failed!!!\n"); + ERR("socket open failed!!!\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_RESOURCE; } @@ -1626,20 +1608,20 @@ int _mh_core_set_ip_address(const char *if_name, const in_addr_t ip) memcpy(&ifr.ifr_addr, &addr, sizeof(struct sockaddr)); if (ioctl(sock_fd, SIOCSIFADDR, &ifr) < 0) { - ERR("ioctl failed...!!!\n"); + ERR("ioctl failed...!!!\n"); //LCOV_EXCL_LINE close(sock_fd); return MOBILE_AP_ERROR_INTERNAL; } if (ioctl(sock_fd, SIOCGIFFLAGS, &ifr) < 0) { - ERR("ioctl failed...!!!\n"); + ERR("ioctl failed...!!!\n"); //LCOV_EXCL_LINE close(sock_fd); return MOBILE_AP_ERROR_INTERNAL; } ifr.ifr_flags |= IFF_UP | IFF_RUNNING; if (ioctl(sock_fd, SIOCSIFFLAGS, &ifr) < 0) { - ERR("ioctl failed...!!!\n"); + ERR("ioctl failed...!!!\n"); //LCOV_EXCL_LINE close(sock_fd); return MOBILE_AP_ERROR_INTERNAL; } @@ -1656,7 +1638,7 @@ int _mh_core_set_mtu(int mtu) sock = socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0); if (sock < 0) { - ERR("socket creation failed\n"); + ERR("socket creation failed\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } @@ -1666,7 +1648,7 @@ int _mh_core_set_mtu(int mtu) ifr.ifr_mtu = mtu; if (ioctl(sock, SIOCSIFMTU, &ifr, sizeof(ifr)) != 0) { - ERR("Failed to set mtu errno:%d\n", errno); + ERR("Failed to set mtu errno:%d\n", errno); //LCOV_EXCL_LINE close(sock); return MOBILE_AP_ERROR_INTERNAL; } @@ -1694,7 +1676,7 @@ int _mh_core_change_mac(const char *mac) fd = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0); if (fd < 0) { - ERR("socket creation failed\n"); + ERR("socket creation failed\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } @@ -1702,7 +1684,7 @@ int _mh_core_change_mac(const char *mac) ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; if (ioctl(fd, SIOCSIFHWADDR, &ifr) == -1) { - ERR("Failed to change MAC address\n"); + ERR("Failed to change MAC address\n"); //LCOV_EXCL_LINE close(fd); return MOBILE_AP_ERROR_INTERNAL; } @@ -1720,7 +1702,7 @@ int _mh_core_enable_port_forwarding(int enable) if (enable) { ret = __enable_port_forwarding(); if (ret != MOBILE_AP_ERROR_NONE) { - ERR("__enable_port_forwarding is failed\n"); + ERR("__enable_port_forwarding is failed\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } @@ -1731,7 +1713,7 @@ int _mh_core_enable_port_forwarding(int enable) } else { ret = __disable_port_forwarding(); if (ret != MOBILE_AP_ERROR_NONE) { - ERR("__enable_port_forwarding is failed\n"); + ERR("__enable_port_forwarding is failed\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } @@ -1776,7 +1758,7 @@ int _mh_core_enable_port_filtering(int enable) int _mh_core_add_port_filtering_rule(int port, const char *protocol, int allow) { if (protocol == NULL) { - ERR("protocol is invalid\n"); + ERR("protocol is invalid\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INVALID_PARAM; } @@ -1791,7 +1773,7 @@ int _mh_core_add_port_filtering_rule(int port, const char *protocol, int allow) int _mh_core_add_custom_port_filtering_rule(int port1, int port2, const char *protocol, int allow) { if (protocol == NULL) { - ERR("protocol is invalid\n"); + ERR("protocol is invalid\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INVALID_PARAM; } @@ -1810,6 +1792,7 @@ int _mh_core_set_vpn_passthrough_rule(int vpn_type, int enable) return MOBILE_AP_ERROR_NONE; } +//LCOV_EXCL_START static gboolean __send_station_event_cb(gpointer data) { int sig = GPOINTER_TO_INT(data); @@ -1859,8 +1842,9 @@ static void __handle_station_signal(int sig) int idle_id = 0; idle_id = g_idle_add(__send_station_event_cb, GINT_TO_POINTER(sig)); if (idle_id == 0) - ERR("g_idle_add is failed\n"); + ERR("g_idle_add is failed\n"); //LCOV_EXCL_LINE } +//LCOV_EXCL_STOP void _register_wifi_station_handler(void) { @@ -1892,6 +1876,7 @@ void _unregister_wifi_station_handler(void) return; } +//LCOV_EXCL_START static gboolean __hostapd_connect_timer_cb(gpointer user_data) { char *mac = (char *)user_data; @@ -1921,7 +1906,7 @@ static gboolean __hostapd_connect_timer_cb(gpointer user_data) info = (mobile_ap_station_info_t *)g_malloc(sizeof(mobile_ap_station_info_t)); if (info == NULL) { - ERR("g_malloc failed\n"); + ERR("g_malloc failed\n"); //LCOV_EXCL_LINE g_free(ptr->mac_addr); g_free(ptr); temp = l; @@ -1969,6 +1954,7 @@ SUCCESS: return FALSE; } +//LCOV_EXCL_STOP void _flush_dhcp_ack_timer(void) { @@ -2002,7 +1988,7 @@ void _destroy_dhcp_ack_timer(char *mac_addr) { DBG("+\n"); if (mac_addr == NULL) { - ERR("mac address passed NULL\n"); + ERR("mac address passed NULL\n"); //LCOV_EXCL_LINE return; } @@ -2035,6 +2021,7 @@ void _destroy_dhcp_ack_timer(char *mac_addr) DBG("-\n"); return; } + int _set_hostapd_tx_power(unsigned int txpower) { int ret = 0; @@ -2045,7 +2032,7 @@ int _set_hostapd_tx_power(unsigned int txpower) snprintf(req, sizeof(req), "%s%u", "SET txpower ", txpower); ret = __send_hostapd_req(hostapd_ctrl_fd, req, strlen(req), buf, &buf_len); if (ret != MOBILE_AP_ERROR_NONE) { - ERR("__send_to_hostapd is failed : %d\n", ret); + ERR("__send_to_hostapd is failed : %d\n", ret); //LCOV_EXCL_LINE return ret; } return MOBILE_AP_ERROR_NONE; @@ -2062,14 +2049,14 @@ unsigned int _get_hostapd_tx_power(void) ret = __send_hostapd_req(hostapd_ctrl_fd, req, strlen(req), buf, &buf_len); if (ret != MOBILE_AP_ERROR_NONE) { - ERR("__send_hostapd_req is failed : %d\n", ret); + ERR("__send_hostapd_req is failed : %d\n", ret); //LCOV_EXCL_LINE return ret; } if (!strncmp(buf, "FAIL", 4)) - ERR("FAIL is returned\n"); + ERR("FAIL is returned\n"); //LCOV_EXCL_LINE if (buf[0] == '\0') - ERR("NULL string\n"); + ERR("NULL string\n"); //LCOV_EXCL_LINE return (atoi(buf)); } @@ -2082,7 +2069,7 @@ int _get_hw_address(const char *if_name, char **hw_addr) fd = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0); if (fd < 0) { - ERR("Failed to create sockeet"); + ERR("Failed to create sockeet"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } @@ -2090,7 +2077,7 @@ int _get_hw_address(const char *if_name, char **hw_addr) strncpy(ifr.ifr_name, if_name, IFNAMSIZ); if (ioctl(fd, SIOCGIFHWADDR, &ifr) == -1) { - ERR("Failed to get MAC address\n"); + ERR("Failed to get MAC address\n"); //LCOV_EXCL_LINE close(fd); return MOBILE_AP_ERROR_INTERNAL; } @@ -2154,13 +2141,13 @@ int _mh_core_create_ipv6_address(int idx, const char *hw_address, char **ipv6_ad __generate_eui64_address(idx, hw_address, &eui64_addr); if (eui64_addr == NULL) { - ERR("Failed to generate EUI-64 ID!!"); + ERR("Failed to generate EUI-64 ID!!"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } network_addr = _get_ipv6_network_address(); if (network_addr == NULL) { - ERR("Failed to get network address!!"); + ERR("Failed to get network address!!"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } @@ -2188,7 +2175,7 @@ int _mh_core_set_ipv6_address(const char *if_name, const char *ipv6_addr) DBG("Setup IPv6 address (%s/%s)", if_name, ipv6_addr); sock_fd = socket(AF_INET6, SOCK_DGRAM, IPPROTO_IP); if (sock_fd == -1) { - ERR("Failed to open socket for ipv6!!"); + ERR("Failed to open socket for ipv6!!"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_RESOURCE; } @@ -2199,7 +2186,7 @@ int _mh_core_set_ipv6_address(const char *if_name, const char *ipv6_addr) addr.sin6_port = 0; if (inet_pton(AF_INET6, ipv6_addr, (void *)&addr.sin6_addr) <= 0) { - ERR("Bad address!!"); + ERR("Bad address!!"); //LCOV_EXCL_LINE close(sock_fd); return MOBILE_AP_ERROR_INTERNAL; } @@ -2207,7 +2194,7 @@ int _mh_core_set_ipv6_address(const char *if_name, const char *ipv6_addr) memcpy((char *)&ifr6.ifr6_addr, (char *)&addr.sin6_addr, sizeof(struct in6_addr)); if (ioctl(sock_fd, SIOGIFINDEX, &ifr) < 0) { - ERR("Failed to get IFINDEX: %s", strerror_r(errno, buf, sizeof(buf))); + ERR("Failed to get IFINDEX: %s", strerror_r(errno, buf, sizeof(buf))); //LCOV_EXCL_LINE close(sock_fd); return MOBILE_AP_ERROR_INTERNAL; } @@ -2216,7 +2203,7 @@ int _mh_core_set_ipv6_address(const char *if_name, const char *ipv6_addr) ifr6.ifr6_prefixlen = 64; if (ioctl(sock_fd, SIOCSIFADDR, &ifr6) < 0) { - ERR("Failed to set address: %s", strerror_r(errno, buf, sizeof(buf))); + ERR("Failed to set address: %s", strerror_r(errno, buf, sizeof(buf))); //LCOV_EXCL_LINE close(sock_fd); return MOBILE_AP_ERROR_INTERNAL; } @@ -2224,7 +2211,7 @@ int _mh_core_set_ipv6_address(const char *if_name, const char *ipv6_addr) ifr.ifr_flags |= IFF_UP | IFF_RUNNING; if (ioctl(sock_fd, SIOCSIFFLAGS, &ifr) < 0) { - ERR("ioctl failed...!!!\n"); + ERR("ioctl failed...!!!\n"); //LCOV_EXCL_LINE close(sock_fd); return MOBILE_AP_ERROR_INTERNAL; } @@ -2238,7 +2225,7 @@ int _mh_core_set_ipv6_address(const char *if_name, const char *ipv6_addr) int _mh_core_enable_ipv6_masquerade(const char *network_intf) { if (network_intf == NULL || strlen(network_intf) == 0) { - ERR("Invalid interface[%s]", network_intf); + ERR("Invalid interface[%s]", network_intf); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INVALID_PARAM; } @@ -2255,7 +2242,7 @@ int _mh_core_enable_ipv6_masquerade(const char *network_intf) int _mh_core_disable_ipv6_masquerade(const char *network_intf) { if (network_intf == NULL || strlen(network_intf) == 0) { - ERR("Invalid interface[%s]", network_intf); + ERR("Invalid interface[%s]", network_intf); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INVALID_PARAM; } @@ -2281,18 +2268,18 @@ int _mh_core_execute_dhcp6_server(void) char *prefix = NULL; if (remove(DNSMASQ_LEASES_FILE) < 0) - ERR("Failed to remove %s", DNSMASQ_LEASES_FILE); + ERR("Failed to remove %s", DNSMASQ_LEASES_FILE); //LCOV_EXCL_LINE if (dnsmasq_pid == 0) { fp = fopen(DNSMASQ_CONF_FILE, "w"); if (NULL == fp) { - ERR("Could not create the file.\n"); + ERR("Could not create the file.\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_RESOURCE; } network_addr = _get_ipv6_network_address(); if (network_addr == NULL) { - ERR("Failed to get global IP"); + ERR("Failed to get global IP"); //LCOV_EXCL_LINE fclose(fp); return MOBILE_AP_ERROR_INTERNAL; } @@ -2312,7 +2299,7 @@ int _mh_core_execute_dhcp6_server(void) pid = fork(); if (pid < 0) { - ERR("fork failed\n"); + ERR("fork failed\n"); //LCOV_EXCL_LINE g_free(prefix); prefix = NULL; return MOBILE_AP_ERROR_RESOURCE; @@ -2331,13 +2318,13 @@ int _mh_core_execute_dhcp6_server(void) g_free(prefix); prefix = NULL; - ERR("Should not get here!"); + ERR("Should not get here!"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_RESOURCE; } dnsmasq_pid = pid; } else { - DBG("DNS-SERVER is already running.\n"); + DBG("DNS-SERVER is already running.\n"); //LCOV_EXCL_LINE } g_free(prefix); @@ -2380,7 +2367,7 @@ int _mh_core_active_nat64_interface(void) return MOBILE_AP_ERROR_NONE; FAIL: - ERR("Failed to setup NAT64"); + ERR("Failed to setup NAT64"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } @@ -2390,7 +2377,7 @@ int _mh_core_deactive_nat64_interface(void) ret = _remove_nat64_interface(); if (!ret) { - ERR("Failed to remove NAT64"); + ERR("Failed to remove NAT64"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INTERNAL; } @@ -2404,22 +2391,22 @@ int _mh_core_execute_nat64(void) if (nat64_pid == 0) { pid = fork(); if (pid < 0) { - ERR("fork failed\n"); + ERR("fork failed\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_RESOURCE; } if (pid == 0) { if (execl(NAT64_BIN, NAT64_BIN, "--config", NAT64_CONF_FILE, (char *)NULL)) { - ERR("execl failed\n"); + ERR("execl failed\n"); //LCOV_EXCL_LINE } - ERR("Should not get here!"); + ERR("Should not get here!"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_RESOURCE; } nat64_pid = pid; } else { - DBG("NAT64 is already running.\n"); + DBG("NAT64 is already running.\n"); //LCOV_EXCL_LINE } return MOBILE_AP_ERROR_NONE; @@ -2428,7 +2415,7 @@ int _mh_core_execute_nat64(void) int _mh_core_terminate_nat64(void) { if (nat64_pid == 0) { - ERR("There is no NAT64"); + ERR("There is no NAT64"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_NONE; } @@ -2446,21 +2433,21 @@ int _mh_core_execute_dns64(void) if (dns64_pid == 0) { pid = fork(); if (pid < 0) { - ERR("fork failed\n"); + ERR("fork failed\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_RESOURCE; } if (pid == 0) { if (execl(DNS64_BIN, DNS64_BIN, "-u", "network_fw", "-t", DNS64_CHROOTDIR, (char *)NULL)) { - ERR("execl failed\n"); + ERR("execl failed\n"); //LCOV_EXCL_LINE } - ERR("Should not get here!"); + ERR("Should not get here!"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_RESOURCE; } dns64_pid = pid; } else { - DBG("DNS64 is already running.\n"); + DBG("DNS64 is already running.\n"); //LCOV_EXCL_LINE } return MOBILE_AP_ERROR_NONE; @@ -2469,7 +2456,7 @@ int _mh_core_execute_dns64(void) int _mh_core_terminate_dns64(void) { if (dns64_pid == 0) { - ERR("There is no DNS64"); + ERR("There is no DNS64"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_NONE; } diff --git a/src/mobileap_usb.c b/src/mobileap_usb.c index 4f5304a..8bba0e2 100755 --- a/src/mobileap_usb.c +++ b/src/mobileap_usb.c @@ -47,6 +47,7 @@ enum usbclient_state { }; /* GDbus Signal Handler for USB Device State Changes */ +//LCOV_EXCL_START static void __usb_device_state_change_cb(GDBusConnection *connection, const gchar *sender_name, const gchar *object_path, const gchar *interface_name, const gchar *signal_name, @@ -84,6 +85,7 @@ static void __usb_device_state_change_cb(GDBusConnection *connection, usb_client_state = value; } +//LCOV_EXCL_STOP int _dbus_register_usb_state_change_signal(void *data) { @@ -96,13 +98,13 @@ int _dbus_register_usb_state_change_signal(void *data) conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); if (error) { - ERR("Error occurred (%s)", error->message); + ERR("Error occurred (%s)", error->message); //LCOV_EXCL_LINE g_error_free(error); ret = MOBILE_AP_ERROR_RESOURCE; goto FAIL; } if (!conn) { - ERR("Failed to get gdbus connection"); + ERR("Failed to get gdbus connection"); //LCOV_EXCL_LINE ret = MOBILE_AP_ERROR_RESOURCE; goto FAIL; } @@ -114,7 +116,7 @@ int _dbus_register_usb_state_change_signal(void *data) data, NULL); if (subscription_id == 0) { - ERR("Failed to subscribe signal (%d)", USB_STATE_CHANGE_SIGNAL); + ERR("Failed to subscribe signal (%d)", USB_STATE_CHANGE_SIGNAL); //LCOV_EXCL_LINE ret = MOBILE_AP_ERROR_RESOURCE; goto FAIL; } @@ -129,6 +131,7 @@ FAIL: return ret; } +//LCOV_EXCL_START void __handle_usb_disconnect_cb(keynode_t *key, void *data) { if (key == NULL || data == NULL) { @@ -253,6 +256,7 @@ static void __handle_usb_mode_change(keynode_t *key, void *data) ERR("g_idle_add is failed\n"); } } +//LCOV_EXCL_STOP mobile_ap_error_code_e _enable_usb_tethering(Tethering *obj) { @@ -261,39 +265,41 @@ mobile_ap_error_code_e _enable_usb_tethering(Tethering *obj) int usb_mode = SET_USB_NONE; if (_mobileap_is_enabled(MOBILE_AP_STATE_USB)) { - ERR("USB tethering is already enabled\n"); + ERR("USB tethering is already enabled\n"); //LCOV_EXCL_LINE ret = MOBILE_AP_ERROR_ALREADY_ENABLED; return ret; } if (_mobileap_is_enabled(MOBILE_AP_STATE_WIFI_AP)) { - ERR("Wi-Fi AP is enabled\n"); + ERR("Wi-Fi AP is enabled\n"); //LCOV_EXCL_LINE ret = MOBILE_AP_ERROR_RESOURCE; return ret; } /* Register DBus Signal Handler for USB Client State */ if (_dbus_register_usb_state_change_signal(obj) != MOBILE_AP_ERROR_NONE) { - ERR("Failed to register dbus signal(%d)", ret); + ERR("Failed to register dbus signal(%d)", ret); //LCOV_EXCL_LINE ret = MOBILE_AP_ERROR_RESOURCE; goto FAIL; } +#ifndef TIZEN_FEATURE_UNITTEST if (!_mobileap_set_state(MOBILE_AP_STATE_USB)) { ret = MOBILE_AP_ERROR_RESOURCE; goto FAIL; } - +#endif ret = _init_tethering(MOBILE_AP_ADDRESS_TYPE_IPV4); if (ret != MOBILE_AP_ERROR_NONE) goto FAIL; +#ifndef TIZEN_FEATURE_UNITTEST vconf_notify_key_changed(VCONFKEY_USB_CUR_MODE, __handle_usb_mode_change, (void *)obj); vconf_ret = vconf_get_int(VCONFKEY_USB_CUR_MODE, &usb_mode); if (vconf_ret != 0) { - ERR("Error getting vconf\n"); + ERR("Error getting vconf\n"); //LCOV_EXCL_LINE vconf_ignore_key_changed(VCONFKEY_USB_CUR_MODE, __handle_usb_mode_change); _deinit_tethering(MOBILE_AP_ADDRESS_TYPE_IPV4); @@ -307,7 +313,7 @@ mobile_ap_error_code_e _enable_usb_tethering(Tethering *obj) _add_interface_routing(USB_IF, IP_ADDRESS_USB); _add_routing_rule(USB_IF); } - +#endif DBG("-\n"); return MOBILE_AP_ERROR_NONE; @@ -330,16 +336,18 @@ mobile_ap_error_code_e _disable_usb_tethering(Tethering *obj) { mobile_ap_error_code_e ret = MOBILE_AP_ERROR_NONE; +#ifndef TIZEN_FEATURE_UNITTEST if (!_mobileap_is_enabled(MOBILE_AP_STATE_USB)) { - ERR("USB tethering has not been enabled\n"); + ERR("USB tethering has not been enabled\n"); //LCOV_EXCL_LINE ret = MOBILE_AP_ERROR_NOT_ENABLED; return ret; } +#endif _deinit_tethering(MOBILE_AP_ADDRESS_TYPE_IPV4); if (_remove_station_info_all(MOBILE_AP_TYPE_USB) != MOBILE_AP_ERROR_NONE) - ERR("_remove_station_info_all is failed. Ignore it\n"); + ERR("_remove_station_info_all is failed. Ignore it\n"); //LCOV_EXCL_LINE /* Clear DBus Signal Handler for USB Client State */ if (conn) { @@ -368,18 +376,21 @@ gboolean tethering_enable_usb_tethering(Tethering *obj, GDBusMethodInvocation *c DBG("+\n"); g_assert(obj != NULL); +#ifndef TIZEN_FEATURE_UNITTEST g_assert(context != NULL); - +#endif if (g_context) { - DBG("It is turnning on\n"); + DBG("It is turnning on\n"); //LCOV_EXCL_LINE +#ifndef TIZEN_FEATURE_UNITTEST tethering_complete_enable_usb_tethering(obj, g_context, MOBILE_AP_ERROR_IN_PROGRESS); +#endif return FALSE; } g_context = context; if (!_is_allowed(MOBILE_AP_TYPE_USB)) { - DBG("DPM policy restricts USB tethering\n"); + DBG("DPM policy restricts USB tethering\n"); //LCOV_EXCL_LINE ret = MOBILE_AP_ERROR_NOT_PERMITTED; _create_security_restriction_noti(MOBILE_AP_TYPE_USB); goto DONE; @@ -387,17 +398,19 @@ gboolean tethering_enable_usb_tethering(Tethering *obj, GDBusMethodInvocation *c ret = _enable_usb_tethering(obj); if (ret != MOBILE_AP_ERROR_NONE) { - ERR("_enable_usb_tethering() is failed : %d\n", ret); + ERR("_enable_usb_tethering() is failed : %d\n", ret); //LCOV_EXCL_LINE goto DONE; } else { - DBG("Don't need to wait for usb-setting\n"); + DBG("Don't need to wait for usb-setting\n"); //LCOV_EXCL_LINE tethering_emit_usb_on(obj); _create_tethering_active_noti(); ret_val = TRUE; } DONE: +#ifndef TIZEN_FEATURE_UNITTEST tethering_complete_enable_usb_tethering(obj, g_context, ret); +#endif g_context = NULL; @@ -414,13 +427,17 @@ gboolean tethering_disable_usb_tethering(Tethering *obj, DBG("+\n"); g_assert(obj != NULL); +#ifndef TIZEN_FEATURE_UNITTEST g_assert(context != NULL); +#endif if (g_context) { - DBG("It is turnning on\n"); + DBG("It is turnning on\n"); //LCOV_EXCL_LINE +#ifndef TIZEN_FEATURE_UNITTEST tethering_complete_disable_usb_tethering(obj, context, MOBILE_AP_DISABLE_USB_TETHERING_CFM, MOBILE_AP_ERROR_IN_PROGRESS); +#endif return FALSE; } @@ -428,26 +445,29 @@ gboolean tethering_disable_usb_tethering(Tethering *obj, ret = _disable_usb_tethering(obj); if (ret != MOBILE_AP_ERROR_NONE) { +#ifndef TIZEN_FEATURE_UNITTEST tethering_complete_disable_usb_tethering(obj, g_context, MOBILE_AP_DISABLE_USB_TETHERING_CFM, ret); +#endif g_context = NULL; return FALSE; } +#ifndef TIZEN_FEATURE_UNITTEST vconf_notify_key_changed(VCONFKEY_USB_CUR_MODE, __handle_usb_mode_change, (void *)obj); vconf_ret = vconf_get_int(VCONFKEY_USB_CUR_MODE, &usb_mode); if (vconf_ret != 0) { - ERR("Error getting vconf : %d. This error is ignored\n", vconf_ret); + ERR("Error getting vconf : %d. This error is ignored\n", vconf_ret); //LCOV_EXCL_LINE goto DONE; } if (usb_mode != SET_USB_RNDIS) { - DBG("Don't need to wait for usb-setting\n"); + DBG("Don't need to wait for usb-setting\n"); //LCOV_EXCL_LINE goto DONE; } - in_progress = TRUE; +#endif DBG("-\n"); return TRUE; diff --git a/src/mobileap_wfd.c b/src/mobileap_wfd.c index 8d9c650..58da204 100644 --- a/src/mobileap_wfd.c +++ b/src/mobileap_wfd.c @@ -28,10 +28,10 @@ static wfd_callback_t *wfd_callback = NULL; - +//LCOV_EXCL_START static char *get_state_str(int state) { - switch(state) { + switch (state) { case WIFI_DIRECT_STATE_DEACTIVATED: return "deactivated"; case WIFI_DIRECT_STATE_DEACTIVATING: @@ -54,6 +54,7 @@ static char *get_state_str(int state) return "unknown state"; } } +//LCOV_EXCL_STOP static void wfd_client_event_handler(const gchar *signal, GVariant *parameters, void *user_data) { @@ -99,7 +100,7 @@ static void wfd_client_event_handler(const gchar *signal, GVariant *parameters, if (wfd_callback->ip_assigned_cb) wfd_callback->ip_assigned_cb(parameters, NULL); } else - DBG("Unknown event"); + DBG("Unknown event"); //LCOV_EXCL_LINE DBG("-"); } @@ -116,7 +117,7 @@ int wfd_client_activate(void *user_data) reply = wfd_client_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE, "Activate", NULL, &error); if (error) { - ERR("error [%d: %s]", error->code, error->message); + ERR("error [%d: %s]", error->code, error->message); //LCOV_EXCL_LINE g_error_free(error); return -1; } @@ -138,7 +139,7 @@ int wfd_client_deactivate(void *user_data) reply = wfd_client_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE, "Deactivate", NULL, &error); if (error) { - ERR("error [%d: %s]", error->code, error->message); + ERR("error [%d: %s]", error->code, error->message); //LCOV_EXCL_LINE g_error_free(error); return -1; } @@ -157,7 +158,7 @@ int wfd_client_get_state(int *state) reply = wfd_client_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE, "GetState", NULL, &error); if (error) { - ERR("error [%d: %s]", error->code, error->message); + ERR("error [%d: %s]", error->code, error->message); //LCOV_EXCL_LINE g_error_free(error); *state = ret; return -1; @@ -165,7 +166,7 @@ int wfd_client_get_state(int *state) g_variant_get(reply, "(i)", &ret); *state = ret; - DBG("state = [%s]", get_state_str(*state)); + DBG("state = [%s]", get_state_str(*state)); //LCOV_EXCL_LINE g_variant_unref(reply); return 0; } @@ -185,7 +186,7 @@ int wfd_client_set_passphrase(gchar *passphrase) reply = wfd_client_dbus_method_call_sync(WFD_MANAGER_GROUP_INTERFACE, "SetPassphrase", params, &error); if (error) { - ERR("error [%d: %s]", error->code, error->message); + ERR("error [%d: %s]", error->code, error->message); //LCOV_EXCL_LINE g_error_free(error); return -1; } @@ -210,7 +211,7 @@ int wfd_client_set_ssid(gchar *ssid) reply = wfd_client_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE, "SetDeviceName", params, &error); if (error) { - ERR("error [%d: %s]", error->code, error->message); + ERR("error [%d: %s]", error->code, error->message); //LCOV_EXCL_LINE g_error_free(error); return -1; } @@ -239,7 +240,7 @@ int wfd_client_create_group(gchar *ssid, void *user_data) reply = wfd_client_dbus_method_call_sync(WFD_MANAGER_GROUP_INTERFACE, "CreateGroup", params, &error); if (error) { - ERR("error [%d: %s]", error->code, error->message); + ERR("error [%d: %s]", error->code, error->message); //LCOV_EXCL_LINE g_error_free(error); return -1; } @@ -261,7 +262,7 @@ int wfd_client_destroy_group(void *user_data) reply = wfd_client_dbus_method_call_sync(WFD_MANAGER_GROUP_INTERFACE, "DestroyGroup", NULL, &error); if (error) { - ERR("error [%d: %s]", error->code, error->message); + ERR("error [%d: %s]", error->code, error->message); //LCOV_EXCL_LINE g_error_free(error); return -1; } @@ -282,7 +283,7 @@ int wfd_client_set_auto_group_removal(bool enable) reply = wfd_client_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE, "SetAutoGroupRemoval", params, &error); if (error) { - ERR("error [%d: %s]", error->code, error->message); + ERR("error [%d: %s]", error->code, error->message); //LCOV_EXCL_LINE g_error_free(error); return -1; } diff --git a/src/mobileap_wifi.c b/src/mobileap_wifi.c index df711d3..6799c80 100755 --- a/src/mobileap_wifi.c +++ b/src/mobileap_wifi.c @@ -158,6 +158,7 @@ static int _extract_softap_settings(GVariant *values, softap_settings_t *setting } #ifdef TIZEN_FEATURE_ENABLE_WIFI_DIRECT +//LCOV_EXCL_START static void _wifi_direct_state_cb(int error_code, wifi_direct_device_state_e state, void *user_data) { bool wifi_state = false; @@ -211,20 +212,24 @@ static void _wifi_direct_state_cb(int error_code, wifi_direct_device_state_e sta } DONE: +#ifndef TIZEN_FEATURE_UNITTEST if (!is_softap) { tethering_complete_enable_wifi_tethering((Tethering *)obj, g_context, ret); } else { softap_complete_enable((Softap *)obj, g_context, ret); is_softap = FALSE; } +#endif g_context = NULL; memset(&wifi_settings, 0, sizeof(wifi_settings)); DBG("-\n"); return; } +//LCOV_EXCL_STOP #endif +//LCOV_EXCL_START static void __wifi_manager_activated_cb(wifi_manager_error_e result, void *user_data) { DBG("Wi-Fi on is done\n"); @@ -266,12 +271,14 @@ static void __wifi_manager_deactivated_cb(wifi_manager_error_e result, void *use } DONE: +#ifndef TIZEN_FEATURE_UNITTEST if (!is_softap) { tethering_complete_enable_wifi_tethering((Tethering *)obj, g_context, ret); } else { softap_complete_enable((Softap *)obj, g_context, ret); is_softap = FALSE; } +#endif g_context = NULL; memset(&wifi_settings, 0, sizeof(wifi_settings)); @@ -326,6 +333,7 @@ static int __turn_on_wifi(void) return MOBILE_AP_ERROR_NONE; } +//LCOV_EXCL_STOP #ifdef TIZEN_FEATURE_ENABLE_WIFI_DIRECT static gboolean __is_wifi_direct_on(void) @@ -342,6 +350,7 @@ static gboolean __is_wifi_direct_on(void) return wifi_direct_state != 0 ? TRUE : FALSE; } +//LCOV_EXCL_START static int __turn_off_wifi_direct(void *obj) { int ret; @@ -372,12 +381,13 @@ static int __turn_off_wifi_direct(void *obj) return MOBILE_AP_ERROR_NONE; } +//LCOV_EXCL_STOP #endif static mobile_ap_error_code_e __update_softap_settings(softap_settings_t *dst, softap_settings_t *src) { if (dst == NULL) { - ERR("Invalid param\n"); + ERR("Invalid param\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INVALID_PARAM; } @@ -467,7 +477,7 @@ mobile_ap_error_code_e _reload_softap_settings(Tethering *obj, softap_settings_t softap_settings_t new_settings; if (obj == NULL || settings == NULL || !strlen(settings->ssid)) { - ERR("invalid parameters\n"); + ERR("invalid parameters\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INVALID_PARAM; } @@ -476,12 +486,12 @@ mobile_ap_error_code_e _reload_softap_settings(Tethering *obj, softap_settings_t ret = __update_softap_settings(&new_settings, settings); if (ret != MOBILE_AP_ERROR_NONE) { - ERR("__update_softap_settings is failed\n"); + ERR("__update_softap_settings is failed\n"); //LCOV_EXCL_LINE return ret; } if (__is_equal_softap_settings(&new_settings, old_settings) == TRUE) { - DBG("No need to reload settings\n"); + DBG("No need to reload settings\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_NONE; } @@ -490,13 +500,13 @@ mobile_ap_error_code_e _reload_softap_settings(Tethering *obj, softap_settings_t prev_wifi_on = backup_prev_wifi_on; if (ret != MOBILE_AP_ERROR_NONE) { - ERR("_disable_wifi_tethering is failed : %d\n", ret); + ERR("_disable_wifi_tethering is failed : %d\n", ret); //LCOV_EXCL_LINE return ret; } ret = _enable_wifi_tethering(obj, &new_settings); if (ret != MOBILE_AP_ERROR_NONE) { - ERR("_enable_wifi_tethering is failed : %d\n", ret); + ERR("_enable_wifi_tethering is failed : %d\n", ret); //LCOV_EXCL_LINE return ret; } tethering_emit_wifi_on(obj); @@ -550,24 +560,24 @@ mobile_ap_error_code_e _enable_wifi_tethering(Tethering *obj, softap_settings_t DBG("+"); if (obj == NULL || !strlen(settings->ssid)) { - ERR("invalid parameters\n"); + ERR("invalid parameters\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INVALID_PARAM; } if (!g_strcmp0(settings->security_type, SOFTAP_SECURITY_TYPE_WPA2_PSK_STR) && !strlen(settings->key)) { - ERR("passphrase is null\n"); + ERR("passphrase is null\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INVALID_PARAM; } if (_mobileap_is_enabled(MOBILE_AP_STATE_WIFI_AP)) { - ERR("Wi-Fi AP is already enabled\n"); + ERR("Wi-Fi AP is already enabled\n"); //LCOV_EXCL_LINE ret = MOBILE_AP_ERROR_RESOURCE; return ret; } if (_mobileap_is_enabled(MOBILE_AP_STATE_WIFI)) { - ERR("Wi-Fi tethering is already enabled\n"); + ERR("Wi-Fi tethering is already enabled\n"); //LCOV_EXCL_LINE ret = MOBILE_AP_ERROR_ALREADY_ENABLED; return ret; } @@ -592,7 +602,7 @@ mobile_ap_error_code_e _enable_wifi_tethering(Tethering *obj, softap_settings_t if (vconf_set_str(VCONFKEY_MOBILE_HOTSPOT_SSID, obj_softap_settings.ssid) < 0) { - ERR("vconf_set_str is failed\n"); + ERR("vconf_set_str is failed\n"); //LCOV_EXCL_LINE } /* Initialize tethering */ @@ -639,7 +649,7 @@ mobile_ap_error_code_e _disable_wifi_tethering(Tethering *obj, mobile_ap_address state = MOBILE_AP_STATE_WIFI; if (!_mobileap_is_enabled(state)) { - ERR("Wi-Fi tethering ap has not been activated\n"); + ERR("Wi-Fi tethering ap has not been activated\n"); //LCOV_EXCL_LINE ret = MOBILE_AP_ERROR_NOT_ENABLED; return ret; } @@ -659,11 +669,11 @@ mobile_ap_error_code_e _disable_wifi_tethering(Tethering *obj, mobile_ap_address #endif if (_remove_station_info_all(type) != MOBILE_AP_ERROR_NONE) - ERR("_remove_station_info_all is failed. Ignore it.\n"); + ERR("_remove_station_info_all is failed. Ignore it.\n"); //LCOV_EXCL_LINE ret = _mh_core_disable_softap(); if (ret != MOBILE_AP_ERROR_NONE) { - ERR("_mh_core_disable_softap is failed : %d\n", ret); + ERR("_mh_core_disable_softap is failed : %d\n", ret); //LCOV_EXCL_LINE goto DONE; } @@ -675,9 +685,9 @@ mobile_ap_error_code_e _disable_wifi_tethering(Tethering *obj, mobile_ap_address #endif if (prev_wifi_on == TRUE) { - DBG("Previous Wi-Fi was turned on. Recover it\n"); + DBG("Previous Wi-Fi was turned on. Recover it\n"); //LCOV_EXCL_LINE if (__turn_on_wifi() != MOBILE_AP_ERROR_NONE) - ERR("__turn_on_wifi() is failed\n"); + ERR("__turn_on_wifi() is failed\n"); //LCOV_EXCL_LINE prev_wifi_on = FALSE; } DBG("_disable_wifi_tethering is done\n"); @@ -693,25 +703,25 @@ mobile_ap_error_code_e _enable_soft_ap(Softap *obj, softap_settings_t *settings) int mode; if (obj == NULL || !strlen(settings->ssid)) { - ERR("invalid parameters\n"); + ERR("invalid parameters\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INVALID_PARAM; } if (!g_strcmp0(settings->security_type, SOFTAP_SECURITY_TYPE_WPA2_PSK_STR) && strlen(settings->key) >= MOBILE_AP_WIFI_KEY_MAX_LEN) { - ERR("hex key length is not correct\n"); + ERR("hex key length is not correct\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INVALID_PARAM; } if (_mobileap_is_enabled(MOBILE_AP_STATE_WIFI | MOBILE_AP_STATE_BT | MOBILE_AP_STATE_USB)) { - ERR("Tethering is already enabled\n"); + ERR("Tethering is already enabled\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_RESOURCE; } if (_mobileap_is_enabled(MOBILE_AP_STATE_WIFI_AP)) { - ERR("SoftAP is already enabled\n"); + ERR("SoftAP is already enabled\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_ALREADY_ENABLED; } @@ -725,22 +735,22 @@ mobile_ap_error_code_e _enable_soft_ap(Softap *obj, softap_settings_t *settings) } if (vconf_set_str(VCONFKEY_SOFTAP_SSID, obj_softap_settings.ssid) < 0) - ERR("vconf_set_str is failed"); + ERR("vconf_set_str is failed"); //LCOV_EXCL_LINE if (vconf_set_str(VCONFKEY_SOFTAP_KEY, obj_softap_settings.key) < 0) - ERR("vconf_set_str is failed"); + ERR("vconf_set_str is failed"); //LCOV_EXCL_LINE if (vconf_set_int(VCONFKEY_SOFTAP_CHANNEL, obj_softap_settings.channel) < 0) - ERR("vconf_set_str is failed"); + ERR("vconf_set_str is failed"); //LCOV_EXCL_LINE mode = __convert_mode_str_to_int(obj_softap_settings.mode); if (mode != -1) { if (vconf_set_int(VCONFKEY_SOFTAP_MODE, mode) < 0) - ERR("vconf_set_str is failed"); + ERR("vconf_set_str is failed"); //LCOV_EXCL_LINE } if (vconf_set_str(VCONFKEY_SOFTAP_VSIE, obj_softap_settings.vendor_elements) < 0) - ERR("vconf_set_str is failed"); + ERR("vconf_set_str is failed"); //LCOV_EXCL_LINE _block_device_sleep(); @@ -787,7 +797,7 @@ mobile_ap_error_code_e _disable_soft_ap(Softap *obj) state = MOBILE_AP_STATE_WIFI_AP; if (!_mobileap_is_enabled(state)) { - ERR("Wi-Fi ap tethering has not been activated\n"); + ERR("Wi-Fi ap tethering has not been activated\n"); //LCOV_EXCL_LINE ret = MOBILE_AP_ERROR_NOT_ENABLED; return ret; } @@ -803,11 +813,11 @@ mobile_ap_error_code_e _disable_soft_ap(Softap *obj) _deinit_timeout_cb(type); #endif if (_remove_station_info_all(type) != MOBILE_AP_ERROR_NONE) - ERR("_remove_station_info_all is failed. Ignore it.\n"); + ERR("_remove_station_info_all is failed. Ignore it.\n"); //LCOV_EXCL_LINE ret = _mh_core_disable_softap(); if (ret != MOBILE_AP_ERROR_NONE) { - ERR("_mh_core_disable_softap is failed : %d\n", ret); + ERR("_mh_core_disable_softap is failed : %d\n", ret); //LCOV_EXCL_LINE goto DONE; } @@ -831,7 +841,7 @@ mobile_ap_error_code_e _reload_softap_settings_for_softap(Softap *obj, softap_se DBG("+"); if (obj == NULL || !strlen(settings->ssid)) { - ERR("invalid parameters\n"); + ERR("invalid parameters\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INVALID_PARAM; } @@ -840,12 +850,12 @@ mobile_ap_error_code_e _reload_softap_settings_for_softap(Softap *obj, softap_se ret = __update_softap_settings(&new_settings, settings); if (ret != MOBILE_AP_ERROR_NONE) { - ERR("__update_softap_settings is failed\n"); + ERR("__update_softap_settings is failed\n"); //LCOV_EXCL_LINE return ret; } if (__is_equal_softap_settings(&new_settings, old_settings) == TRUE) { - DBG("No need to reload settings\n"); + DBG("No need to reload settings\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_NONE; } @@ -854,13 +864,13 @@ mobile_ap_error_code_e _reload_softap_settings_for_softap(Softap *obj, softap_se prev_wifi_on = backup_prev_wifi_on; if (ret != MOBILE_AP_ERROR_NONE) { - ERR("_disable_softap is failed : %d\n", ret); + ERR("_disable_softap is failed : %d\n", ret); //LCOV_EXCL_LINE return ret; } ret = _enable_soft_ap(obj, &new_settings); if (ret != MOBILE_AP_ERROR_NONE) { - ERR("_enable_softap is failed : %d\n", ret); + ERR("_enable_softap is failed : %d\n", ret); //LCOV_EXCL_LINE return ret; } softap_emit_soft_ap_on(obj); @@ -883,7 +893,7 @@ gboolean tethering_enable_wifi_tethering(Tethering *obj, #endif if (g_context) { - DBG("It is turnning on\n"); + DBG("It is turnning on\n"); //LCOV_EXCL_LINE tethering_complete_enable_wifi_tethering(obj, g_context, MOBILE_AP_ERROR_IN_PROGRESS); return FALSE; @@ -892,7 +902,7 @@ gboolean tethering_enable_wifi_tethering(Tethering *obj, #ifndef TIZEN_FEATURE_HEADLESS if (!_is_allowed(MOBILE_AP_TYPE_WIFI)) { - DBG("DPM policy restricts Wi-Fi tethering\n"); + DBG("DPM policy restricts Wi-Fi tethering\n"); //LCOV_EXCL_LINE ret = MOBILE_AP_ERROR_NOT_PERMITTED; _create_security_restriction_noti(MOBILE_AP_TYPE_WIFI); goto DONE; @@ -931,7 +941,7 @@ gboolean tethering_enable_wifi_tethering(Tethering *obj, wifi_settings.address_type = address_type; if (wifi_recovery_timeout_id) { - DBG("Wi-Fi recovery is cancelled\n"); + DBG("Wi-Fi recovery is cancelled\n"); //LCOV_EXCL_LINE g_source_remove(wifi_recovery_timeout_id); wifi_recovery_timeout_id = 0; prev_wifi_on = TRUE; @@ -941,7 +951,7 @@ gboolean tethering_enable_wifi_tethering(Tethering *obj, if (__is_wifi_direct_on() == TRUE) { DBG("Wi-Fi and Wi-Fi direct are turned on\n"); if (__turn_off_wifi_direct(obj) != MOBILE_AP_ERROR_NONE) { - ERR("_turn_off_wifi_direct is failed\n"); + ERR("_turn_off_wifi_direct is failed\n"); //LCOV_EXCL_LINE ret = MOBILE_AP_ERROR_INTERNAL; goto DONE; } @@ -952,9 +962,9 @@ gboolean tethering_enable_wifi_tethering(Tethering *obj, wifi_manager_is_activated(wifi_manager, &wifi_state); if (wifi_state == true) { - DBG("Wi-Fi is turned on\n"); + DBG("Wi-Fi is turned on\n"); //LCOV_EXCL_LINE if (__turn_off_wifi(obj) != MOBILE_AP_ERROR_NONE) { - ERR("_turn_off_wifi is failed\n"); + ERR("_turn_off_wifi is failed\n"); //LCOV_EXCL_LINE ret = MOBILE_AP_ERROR_INTERNAL; goto DONE; } @@ -964,7 +974,7 @@ gboolean tethering_enable_wifi_tethering(Tethering *obj, ret = _enable_wifi_tethering(obj, &wifi_settings); if (ret != MOBILE_AP_ERROR_NONE) { - ERR("_enable_wifi_tethering is failed\n"); + ERR("_enable_wifi_tethering is failed\n"); //LCOV_EXCL_LINE } else { tethering_emit_wifi_on(obj); #ifndef TIZEN_FEATURE_HEADLESS @@ -974,7 +984,9 @@ gboolean tethering_enable_wifi_tethering(Tethering *obj, } DONE: +#ifndef TIZEN_FEATURE_UNITTEST tethering_complete_enable_wifi_tethering(obj, g_context, ret); +#endif g_context = NULL; memset(&wifi_settings, 0, sizeof(wifi_settings)); @@ -994,9 +1006,11 @@ gboolean tethering_disable_wifi_tethering(Tethering *obj, ret = _disable_wifi_tethering(obj, address_type); - tethering_emit_wifi_off(obj, NULL); + tethering_emit_wifi_off(obj, ""); +#ifndef TIZEN_FEATURE_UNITTEST tethering_complete_disable_wifi_tethering(obj, context, MOBILE_AP_DISABLE_WIFI_TETHERING_CFM, ret); +#endif return (ret == MOBILE_AP_ERROR_NONE ? TRUE : FALSE); } @@ -1044,11 +1058,13 @@ gboolean tethering_reload_wifi_settings(Tethering *obj, ret = _reload_softap_settings(obj, &settings); if (ret != MOBILE_AP_ERROR_NONE) { - ERR("_reload_softap_settings is failed\n"); + ERR("_reload_softap_settings is failed\n"); //LCOV_EXCL_LINE ret_val = FALSE; } +#ifndef TIZEN_FEATURE_UNITTEST tethering_complete_reload_wifi_settings(obj, context, ret); +#endif return ret_val; } @@ -1059,7 +1075,9 @@ gboolean tethering_set_mtu(Tethering *obj, mobile_ap_error_code_e ret = MOBILE_AP_ERROR_NONE; ret = _mh_core_set_mtu(mtu); +#ifndef TIZEN_FEATURE_UNITTEST tethering_complete_set_mtu(obj, context, ret); +#endif return (ret == MOBILE_AP_ERROR_NONE ? TRUE : FALSE); } @@ -1070,7 +1088,9 @@ gboolean tethering_change_mac(Tethering *obj, mobile_ap_error_code_e ret = MOBILE_AP_ERROR_NONE; ret = _mh_core_change_mac(mac); +#ifndef TIZEN_FEATURE_UNITTEST tethering_complete_change_mac(obj, context, ret); +#endif return (ret == MOBILE_AP_ERROR_NONE ? TRUE : FALSE); } @@ -1081,7 +1101,9 @@ gboolean tethering_enable_port_forwarding(Tethering *obj, mobile_ap_error_code_e ret = MOBILE_AP_ERROR_NONE; ret = _mh_core_enable_port_forwarding(enable); +#ifndef TIZEN_FEATURE_UNITTEST tethering_complete_enable_port_forwarding(obj, context, ret); +#endif return (ret == MOBILE_AP_ERROR_NONE ? TRUE : FALSE); } @@ -1092,7 +1114,9 @@ gboolean tethering_add_port_forwarding_rule(Tethering *obj, GDBusMethodInvocatio mobile_ap_error_code_e ret = MOBILE_AP_ERROR_NONE; ret = _mh_core_add_port_forwarding_rule(ifname, protocol, org_ip, org_port, final_ip, final_port); +#ifndef TIZEN_FEATURE_UNITTEST tethering_complete_add_port_forwarding_rule(obj, context, ret); +#endif return (ret == MOBILE_AP_ERROR_NONE ? TRUE : FALSE); } @@ -1103,8 +1127,9 @@ gboolean tethering_reset_port_forwarding_rule(Tethering *obj, mobile_ap_error_code_e ret = MOBILE_AP_ERROR_NONE; ret = _mh_core_reset_port_forwarding_rule(); +#ifndef TIZEN_FEATURE_UNITTEST tethering_complete_reset_port_forwarding_rule(obj, context, ret); - +#endif return (ret == MOBILE_AP_ERROR_NONE ? TRUE : FALSE); } @@ -1114,8 +1139,9 @@ gboolean tethering_enable_port_filtering(Tethering *obj, mobile_ap_error_code_e ret = MOBILE_AP_ERROR_NONE; ret = _mh_core_enable_port_filtering(enable); +#ifndef TIZEN_FEATURE_UNITTEST tethering_complete_enable_port_filtering(obj, context, ret); - +#endif return (ret == MOBILE_AP_ERROR_NONE ? TRUE : FALSE); } @@ -1125,8 +1151,9 @@ gboolean tethering_add_port_filtering_rule(Tethering *obj, mobile_ap_error_code_e ret = MOBILE_AP_ERROR_NONE; ret = _mh_core_add_port_filtering_rule(port, protocol, allow); +#ifndef TIZEN_FEATURE_UNITTEST tethering_complete_add_port_filtering_rule(obj, context, ret); - +#endif return (ret == MOBILE_AP_ERROR_NONE ? TRUE : FALSE); } @@ -1136,8 +1163,9 @@ gboolean tethering_add_custom_port_filtering_rule(Tethering *obj, mobile_ap_error_code_e ret = MOBILE_AP_ERROR_NONE; ret = _mh_core_add_custom_port_filtering_rule(port1, port2, protocol, allow); +#ifndef TIZEN_FEATURE_UNITTEST tethering_complete_add_custom_port_filtering_rule(obj, context, ret); - +#endif return (ret == MOBILE_AP_ERROR_NONE ? TRUE : FALSE); } @@ -1147,8 +1175,9 @@ gboolean tethering_set_vpn_passthrough_rule(Tethering *obj, mobile_ap_error_code_e ret = MOBILE_AP_ERROR_NONE; ret = _mh_core_set_vpn_passthrough_rule(vpn_type, enable); +#ifndef TIZEN_FEATURE_UNITTEST tethering_complete_set_vpn_passthrough_rule(obj, context, ret); - +#endif return (ret == MOBILE_AP_ERROR_NONE ? TRUE : FALSE); } @@ -1165,7 +1194,9 @@ gboolean tethering_set_wps_pin(Tethering *obj, ret = MOBILE_AP_ERROR_NOT_PERMITTED; #endif +#ifndef TIZEN_FEATURE_UNITTEST tethering_complete_set_wps_pin(obj, context, ret); +#endif #ifdef TIZEN_FEATURE_WLAN_BOARD_SPRD return (ret == MOBILE_AP_ERROR_NONE ? TRUE : FALSE); @@ -1187,8 +1218,9 @@ gboolean tethering_push_wps_button(Tethering *obj, ret = MOBILE_AP_ERROR_NOT_PERMITTED; #endif +#ifndef TIZEN_FEATURE_UNITTEST tethering_complete_push_wps_button(obj, context, ret); - +#endif #ifdef TIZEN_FEATURE_WLAN_BOARD_SPRD return (ret == MOBILE_AP_ERROR_NONE ? TRUE : FALSE); #else @@ -1208,7 +1240,7 @@ static char *__get_key_manager_alias(const char* name) ret = ckmc_alias_new(ckmc_owner_id_system, name, &ckmc_alias); if (ret != CKMC_ERROR_NONE) { - ERR("Fail to create ckmc_alias!"); + ERR("Fail to create ckmc_alias!"); //LCOV_EXCL_LINE return NULL; } @@ -1235,7 +1267,7 @@ static mobile_ap_error_code_e __set_passphrase(const char *passphrase, const uns ret = ckmc_remove_alias(alias); if (ret != CKMC_ERROR_NONE && ret != CKMC_ERROR_DB_ALIAS_UNKNOWN) { - ERR("Fail to remove old data : %d", ret); + ERR("Fail to remove old data : %d", ret); //LCOV_EXCL_LINE if (alias) free(alias); @@ -1244,7 +1276,7 @@ static mobile_ap_error_code_e __set_passphrase(const char *passphrase, const uns ret = ckmc_save_data(alias, ckmc_buf, ckmc_policy); if (ret != CKMC_ERROR_NONE) { - ERR("Fail to save the passphrase : %d", ret); + ERR("Fail to save the passphrase : %d", ret); //LCOV_EXCL_LINE if (alias) free(alias); @@ -1278,7 +1310,7 @@ static mobile_ap_error_code_e __get_passphrase(char *passphrase, unsigned int passphrase_size, unsigned int *passphrase_len) { if (passphrase == NULL || passphrase_size == 0) { - ERR("Invalid parameter\n"); + ERR("Invalid parameter\n"); //LCOV_EXCL_LINE return MOBILE_AP_ERROR_INVALID_PARAM; } @@ -1295,7 +1327,7 @@ static mobile_ap_error_code_e __get_passphrase(char *passphrase, ret = __generate_initial_passphrase(tmp, sizeof(tmp)); if (ret == 0) { - ERR("generate_initial_passphrase failed : %d\n", *passphrase_len); + ERR("generate_initial_passphrase failed : %d\n", *passphrase_len); //LCOV_EXCL_LINE if (alias) free(alias); @@ -1305,7 +1337,7 @@ static mobile_ap_error_code_e __get_passphrase(char *passphrase, g_strlcpy(passphrase, tmp, (*passphrase_len)+1); if (__set_passphrase(passphrase, *passphrase_len) != MOBILE_AP_ERROR_NONE) { - DBG("set_passphrase is failed : %s, %d", passphrase, *passphrase_len); + DBG("set_passphrase is failed : %s, %d", passphrase, *passphrase_len); //LCOV_EXCL_LINE if (alias) free(alias); @@ -1333,7 +1365,9 @@ gboolean tethering_enable_dhcp(Tethering *obj, else ret = _mh_core_terminate_dhcp_server(); +#ifndef TIZEN_FEATURE_UNITTEST tethering_complete_enable_dhcp(obj, context, ret); +#endif return (ret == MOBILE_AP_ERROR_NONE ? TRUE : FALSE); } @@ -1344,7 +1378,9 @@ gboolean tethering_dhcp_range(Tethering *obj, mobile_ap_error_code_e ret = MOBILE_AP_ERROR_NONE; ret = _mh_core_execute_dhcp_server(rangestart, rangestop); +#ifndef TIZEN_FEATURE_UNITTEST tethering_complete_dhcp_range(obj, context, ret); +#endif return (ret == MOBILE_AP_ERROR_NONE ? TRUE : FALSE); } @@ -1358,12 +1394,14 @@ gboolean tethering_get_wifi_tethering_passphrase(Tethering *obj, ret = __get_passphrase(passphrase_buf, sizeof(passphrase_buf), &len); if (ret != MOBILE_AP_ERROR_NONE) { - ERR("__get_passphrase is failed"); + ERR("__get_passphrase is failed"); //LCOV_EXCL_LINE len = 0; } +#ifndef TIZEN_FEATURE_UNITTEST tethering_complete_get_wifi_tethering_passphrase(obj, context, (len > 0 ? passphrase_buf : NULL), len, ret); +#endif return (ret == MOBILE_AP_ERROR_NONE ? TRUE : FALSE); } @@ -1385,7 +1423,9 @@ gboolean tethering_set_wifi_tethering_passphrase(Tethering *obj, ret = __set_passphrase(passphrase, passphrase_len); DONE: +#ifndef TIZEN_FEATURE_UNITTEST tethering_complete_set_wifi_tethering_passphrase(obj, context, ret); +#endif return (ret == MOBILE_AP_ERROR_NONE ? TRUE : FALSE); } @@ -1404,7 +1444,9 @@ gboolean tethering_set_hostapd_tx_power(Tethering *obj, result = _set_hostapd_tx_power(txpower); var = g_variant_new("(u)", result); +#ifndef TIZEN_FEATURE_UNITTEST g_dbus_method_invocation_return_value(context, var); +#endif g_variant_unref(var); DBG("-"); @@ -1425,7 +1467,9 @@ gboolean tethering_get_hostapd_tx_power(Tethering *obj, #endif txpower = _get_hostapd_tx_power(); var = g_variant_new("(u)", txpower); +#ifndef TIZEN_FEATURE_UNITTEST g_dbus_method_invocation_return_value(context, var); +#endif g_variant_unref(var); DBG("-"); @@ -1447,8 +1491,10 @@ gboolean softap_enable(Softap *obj, GDBusMethodInvocation *context, GVariant *se g_assert(settings != NULL); if (g_context) { - DBG("It is turnning on\n"); + DBG("It is turnning on\n"); //LCOV_EXCL_LINE +#ifndef TIZEN_FEATURE_UNITTEST softap_complete_enable(obj, g_context, MOBILE_AP_ERROR_IN_PROGRESS); +#endif return FALSE; } g_context = context; @@ -1456,13 +1502,13 @@ gboolean softap_enable(Softap *obj, GDBusMethodInvocation *context, GVariant *se ret = _extract_softap_settings(settings, &wifi_ap_settings); if (ret != MOBILE_AP_ERROR_NONE) { - ERR("Failed to get SoftAP settings"); + ERR("Failed to get SoftAP settings"); //LCOV_EXCL_LINE return FALSE; } #ifdef TIZEN_FEATURE_ENABLE_WIFI_DIRECT if (__is_wifi_direct_on() == TRUE) { - DBG("Wi-Fi direct are turned on\n"); + DBG("Wi-Fi direct are turned on\n"); //LCOV_EXCL_LINE ret = MOBILE_AP_ERROR_NOT_PERMITTED; goto DONE; } @@ -1470,20 +1516,22 @@ gboolean softap_enable(Softap *obj, GDBusMethodInvocation *context, GVariant *se wifi_manager_is_activated(wifi_manager, &wifi_state); if (wifi_state == true) { - DBG("Wi-Fi is turned on\n"); + DBG("Wi-Fi is turned on\n"); //LCOV_EXCL_LINE ret = MOBILE_AP_ERROR_NOT_PERMITTED; goto DONE; } ret = _enable_soft_ap(obj, &wifi_ap_settings); if (ret != MOBILE_AP_ERROR_NONE) { - ERR("_enable_soft_ap is failed\n"); + ERR("_enable_soft_ap is failed\n"); //LCOV_EXCL_LINE } else { softap_emit_soft_ap_on(obj); ret_val = TRUE; } DONE: +#ifndef TIZEN_FEATURE_UNITTEST softap_complete_enable(obj, g_context, ret); +#endif is_softap = FALSE; g_context = NULL; memset(&wifi_ap_settings, 0, sizeof(wifi_ap_settings)); @@ -1503,8 +1551,10 @@ gboolean softap_disable(Softap *obj, #endif ret = _disable_soft_ap(obj); - softap_emit_soft_ap_off(obj, NULL); + softap_emit_soft_ap_off(obj, ""); +#ifndef TIZEN_FEATURE_UNITTEST softap_complete_disable(obj, context, ret); +#endif return (ret == MOBILE_AP_ERROR_NONE ? TRUE : FALSE); } @@ -1525,17 +1575,19 @@ gboolean softap_reload_settings(Softap *obj, ret = _extract_softap_settings(settings, &reload_settings); if (ret != MOBILE_AP_ERROR_NONE) { - ERR("Failed to get SoftAP settings"); + ERR("Failed to get SoftAP settings"); //LCOV_EXCL_LINE goto DONE; } ret = _reload_softap_settings_for_softap(obj, &reload_settings); if (ret != MOBILE_AP_ERROR_NONE) - ERR("_reload_softap_settings is failed\n"); + ERR("_reload_softap_settings is failed\n"); //LCOV_EXCL_LINE DONE: +#ifndef TIZEN_FEATURE_UNITTEST softap_complete_reload_settings(obj, context, ret); +#endif return (ret == MOBILE_AP_ERROR_NONE ? TRUE : FALSE); } @@ -1550,7 +1602,9 @@ gboolean softap_set_wps_pin(Softap *obj, ret = MOBILE_AP_ERROR_NOT_PERMITTED; #endif +#ifndef TIZEN_FEATURE_UNITTEST softap_complete_set_wps_pin(obj, context, ret); +#endif #ifdef TIZEN_FEATURE_WLAN_BOARD_SPRD return (ret == MOBILE_AP_ERROR_NONE ? TRUE : FALSE); @@ -1568,7 +1622,10 @@ gboolean softap_push_wps_button(Softap *obj, GDBusMethodInvocation *context) #else ret = MOBILE_AP_ERROR_NOT_PERMITTED; #endif + +#ifndef TIZEN_FEATURE_UNITTEST softap_complete_push_wps_button(obj, context, ret); +#endif #ifdef TIZEN_FEATURE_WLAN_BOARD_SPRD return (ret == MOBILE_AP_ERROR_NONE ? TRUE : FALSE); @@ -1583,7 +1640,9 @@ gboolean softap_enable_dhcp(Softap *obj, mobile_ap_error_code_e ret = MOBILE_AP_ERROR_NONE; ret = _mh_core_execute_dhcp_server(NULL, NULL); +#ifndef TIZEN_FEATURE_UNITTEST softap_complete_enable_dhcp(obj, context, ret); +#endif return (ret == MOBILE_AP_ERROR_NONE ? TRUE : FALSE); } @@ -1594,8 +1653,9 @@ gboolean softap_disable_dhcp(Softap *obj, mobile_ap_error_code_e ret = MOBILE_AP_ERROR_NONE; ret = _mh_core_terminate_dhcp_server(); +#ifndef TIZEN_FEATURE_UNITTEST softap_complete_disable_dhcp(obj, context, ret); - +#endif return (ret == MOBILE_AP_ERROR_NONE ? TRUE : FALSE); } @@ -1605,8 +1665,9 @@ gboolean softap_enable_dhcp_with_range(Softap *obj, mobile_ap_error_code_e ret = MOBILE_AP_ERROR_NONE; ret = _mh_core_execute_dhcp_server(rangestart, rangestop); +#ifndef TIZEN_FEATURE_UNITTEST softap_complete_enable_dhcp_with_range(obj, context, ret); - +#endif return (ret == MOBILE_AP_ERROR_NONE ? TRUE : FALSE); } @@ -1614,8 +1675,9 @@ gboolean softap_enable_dhcp_with_range(Softap *obj, gboolean softap_get_dhcp_state(Softap *obj, GDBusMethodInvocation *context) { int state = _mh_core_get_dhcp_state(); +#ifndef TIZEN_FEATURE_UNITTEST softap_complete_get_dhcp_state(obj, context, state); - +#endif return TRUE; } @@ -1631,7 +1693,9 @@ gboolean softap_get_station_info(Softap *obj, var = _station_info_foreach(); +#ifndef TIZEN_FEATURE_UNITTEST g_dbus_method_invocation_return_value(context, var); +#endif g_variant_unref(var); return (var != NULL ? TRUE : FALSE); diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt index 14993a5..2c27902 100644 --- a/unittest/CMakeLists.txt +++ b/unittest/CMakeLists.txt @@ -19,7 +19,7 @@ ADD_CUSTOM_COMMAND( FILE(GLOB GTEST_TEST_SRCS *.cpp ${CMAKE_SOURCE_DIR}/src/*.c ${CMAKE_SOURCE_DIR}/src/gdbus/*.c) LIST(REMOVE_ITEM GTEST_TEST_SRCS ${CMAKE_SOURCE_DIR}/src/mobileap_main.c) -SET(GTEST_TEST_SRCS ${GTEST_TEST_SRCS} unittest.cpp) +SET(GTEST_TEST_SRCS ${GTEST_TEST_SRCS} unittest.cpp unittest_common.cpp) PKG_CHECK_MODULES(gtest_pkgs REQUIRED glib-2.0 gmock) INCLUDE_DIRECTORIES(${gtest_pkgs_INCLUDE_DIRS}) diff --git a/unittest/resource/dnsmasq.leases b/unittest/resource/dnsmasq.leases new file mode 100644 index 0000000..6d0449a --- /dev/null +++ b/unittest/resource/dnsmasq.leases @@ -0,0 +1,2 @@ +1516676503 11:22:33:44:55:66 192.168.43.64 Tethering-Client 11:22:33:44:55:66:77 + diff --git a/unittest/unittest.cpp b/unittest/unittest.cpp index 8a53b4a..302ffc8 100644 --- a/unittest/unittest.cpp +++ b/unittest/unittest.cpp @@ -13,12 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/** - * @file unittest.cpp - * @author abc - * @version 1.0 - * @brief Unit-tests setup - */ #include #include @@ -39,17 +33,588 @@ using ::testing::UnitTest; class MobileAP:public::testing::Test { protected: + Tethering *obj; + Softap *sobj; virtual void SetUp() { + obj = tethering_skeleton_new(); + sobj = softap_skeleton_new(); + mobileap_dbus_init(); + _register_wifi_station_handler(); + _init_wifi_manager(); + _init_network((void *)obj); + _init_dpm(); + _register_vconf_cb((void *)obj); + } virtual void TearDown() { + _deinit_dpm(); + _deinit_wifi_manager(); + _unregister_wifi_station_handler(); + _deinit_network(); + _unregister_vconf_cb(); + mobileap_dbus_deinit(); + g_object_unref(obj); + g_object_unref(sobj); } }; -TEST_F(MobileAP, mobileap_agent_test_example_p) { - int ret = 0; +TEST_F(MobileAP, mobileap_agent_test_get_tizen_profile_p) { + int ret = _get_tizen_profile(); + EXPECT_TRUE(ret != 0); +} + +TEST_F(MobileAP, mobileap_agent_test_get_name_from_lease_info_p) { + char *dev_name = NULL; + int ret = _get_wifi_name_from_lease_info("11:22:33:44:55:66", &dev_name); + + if (dev_name) + g_free(dev_name); + + EXPECT_EQ(ret, MOBILE_AP_ERROR_NONE); +} + +/* Soft AP */ +TEST_F(MobileAP, mobileap_agent_test_softap_enable_reload_disable_p) { + GVariant *settings = get_softap_settings("test", "qwer1234", 1, 1, 6, 1, "192.168.43.5", "DD050016328000"); + int ret = softap_enable(sobj, NULL, settings); + EXPECT_EQ(ret, TRUE); + + settings = get_softap_settings("test", "qwer1234", 1, 1, 6, 1, "192.168.43.1", "DD050016328000"); + ret = softap_reload_settings(sobj, NULL, settings); + EXPECT_EQ(ret, TRUE); + + ret = softap_disable(sobj, NULL); + EXPECT_EQ(ret, TRUE); +} + +TEST_F(MobileAP, mobileap_agent_test_softap_get_station_info_p) { + GVariant *settings = get_softap_settings("test", "qwer1234", 1, 1, 6, 1, "192.168.43.5", "DD050016328000"); + int ret = softap_enable(sobj, NULL, settings); + EXPECT_EQ(ret, TRUE); + + ret = softap_get_station_info(sobj, NULL); + EXPECT_EQ(ret, TRUE); + + ret = softap_disable(sobj, NULL); + EXPECT_EQ(ret, TRUE); +} + +TEST_F(MobileAP, mobileap_agent_test_softap_wps_p) { + GVariant *settings = get_softap_settings("test", "qwer1234", 1, 1, 6, 1, "192.168.43.5", "DD050016328000"); + int ret = softap_enable(sobj, NULL, settings); + EXPECT_EQ(ret, TRUE); + + ret = softap_set_wps_pin(sobj, NULL, "1234567890"); + EXPECT_EQ(ret, TRUE); + + ret = softap_push_wps_button(sobj, NULL); + EXPECT_EQ(ret, TRUE); + + ret = softap_disable(sobj, NULL); + EXPECT_EQ(ret, TRUE); +} + +TEST_F(MobileAP, mobileap_agent_test_softap_enable_disable_dhcp_p) { + int ret = softap_enable_dhcp(sobj, NULL); + EXPECT_EQ(ret, TRUE); + + ret = softap_disable_dhcp(sobj, NULL); + EXPECT_EQ(ret, TRUE); +} + +TEST_F(MobileAP, mobileap_agent_test_softap_enable_dhcp_with_range_p) { + int ret = softap_enable_dhcp_with_range(sobj, NULL, "192.168.100.1", "192.168.100.200"); + EXPECT_EQ(ret, TRUE); + + ret = softap_disable_dhcp(sobj, NULL); + EXPECT_EQ(ret, TRUE); +} + +TEST_F(MobileAP, mobileap_agent_test_softap_get_dhcp_state_p) { + int ret = softap_get_dhcp_state(sobj, NULL); + EXPECT_EQ(ret, TRUE); +} + +/* P2P Tethering */ +TEST_F(MobileAP, mobileap_agent_test_p2p_enable_disable_p) { + int ret = tethering_p2p_enable(obj, NULL, "test", "qwer1234", 11); + run_gmain_loop(6000); + EXPECT_EQ(ret, TRUE); + + ret = tethering_p2p_disable(obj, NULL); + run_gmain_loop(2000); + EXPECT_EQ(ret, TRUE); +} + +TEST_F(MobileAP, mobileap_agent_test_p2p_enable_disable_n) { + int ret = tethering_p2p_enable(obj, NULL, NULL, "qwer1234", 6); + EXPECT_EQ(ret, FALSE); + + ret = tethering_p2p_disable(obj, NULL); + EXPECT_EQ(ret, TRUE); +} + +TEST_F(MobileAP, mobileap_agent_test_p2p_client_get_state_p) { + int state = 0; + int ret = tethering_p2p_enable(obj, NULL, "test", "qwer1234", 6); + run_gmain_loop(2000); + EXPECT_EQ(ret, TRUE); + + ret = wfd_client_get_state(&state); + EXPECT_EQ(ret, 0); + + ret = tethering_p2p_disable(obj, NULL); + run_gmain_loop(2000); + EXPECT_EQ(ret, TRUE); +} + +TEST_F(MobileAP, mobileap_agent_test_p2p_destroy_group_p) { + int ret = tethering_p2p_enable(obj, NULL, "test", "qwer1234", 6); + run_gmain_loop(3000); + EXPECT_EQ(ret, TRUE); + + ret = wfd_client_destroy_group(NULL); + EXPECT_EQ(ret, 0); + + ret = tethering_p2p_disable(obj, NULL); + run_gmain_loop(3000); + EXPECT_EQ(ret, TRUE); +} + +TEST_F(MobileAP, mobileap_agent_test_p2p_set_passphrase_n) { + int ret = wfd_client_set_passphrase(NULL); + EXPECT_EQ(ret, -1); +} + +TEST_F(MobileAP, mobileap_agent_test_p2p_set_passphrase_p) { + int ret = wfd_client_set_passphrase("qwer1234"); + EXPECT_EQ(ret, 0); +} + +TEST_F(MobileAP, mobileap_agent_test_p2p_set_ssid_n) { + int ret = wfd_client_set_ssid(NULL); + EXPECT_EQ(ret, -1); +} + +TEST_F(MobileAP, mobileap_agent_test_p2p_set_ssid_p) { + int ret = wfd_client_set_ssid("test"); EXPECT_EQ(ret, 0); } +TEST_F(MobileAP, mobileap_agent_test_usb_tethering_enable_disable_p) { + int ret = tethering_enable_usb_tethering(obj, NULL); + EXPECT_EQ(ret, TRUE); + + ret = tethering_disable_usb_tethering(obj, NULL); + EXPECT_EQ(ret, TRUE); +} + +TEST_F(MobileAP, mobileap_agent_test_enable_disable_wifi_tethering_n) { + int ret = 0; + + /* SSID Length: 0 */ + ret = tethering_enable_wifi_tethering(obj, NULL, "", "password", "g", 6, 1, 0, 10, 1, 0); + EXPECT_EQ(ret, FALSE); + + /* Security Type: WPA2_PSK, Password Length: 0 */ + ret = tethering_enable_wifi_tethering(obj, NULL, "test", "", "g", 6, 1, 0, 10, 1, 0); + EXPECT_EQ(ret, FALSE); + + /* Invalid address type */ + ret = tethering_enable_wifi_tethering(obj, NULL, "test", "password", "g", 6, 1, 0, 10, 1, 3); + EXPECT_EQ(ret, FALSE); + + ret = tethering_disable_wifi_tethering(obj, NULL, MOBILE_AP_ADDRESS_TYPE_IPV4); + EXPECT_EQ(ret, FALSE); +} + +TEST_F(MobileAP, mobileap_agent_test_enable_reload_disable_wifi_tethering_p) { + int ret = tethering_enable_wifi_tethering(obj, NULL, "test", "password", "g", 6, 1, 0, 10, 1, 0); + run_gmain_loop(2000); + EXPECT_EQ(ret, TRUE); + + ret = tethering_reload_wifi_settings(obj, NULL, "test", "password", "g", 11, 1, 0, 10, 1); + run_gmain_loop(3000); + EXPECT_EQ(ret, TRUE); + + ret = tethering_disable_wifi_tethering(obj, NULL, MOBILE_AP_ADDRESS_TYPE_IPV4); + run_gmain_loop(2000); + EXPECT_EQ(ret, TRUE); +} + +TEST_F(MobileAP, mobileap_agent_test_get_data_packet_usage_p) { + int ret = tethering_enable_wifi_tethering(obj, NULL, "test", "password", "g", 6, 1, 0, 10, 1, 0); + run_gmain_loop(2000); + EXPECT_EQ(ret, TRUE); + + ret = tethering_get_data_packet_usage(obj, NULL); + EXPECT_EQ(ret, TRUE); + + ret = tethering_disable_wifi_tethering(obj, NULL, MOBILE_AP_ADDRESS_TYPE_IPV4); + run_gmain_loop(2000); + EXPECT_EQ(ret, TRUE); +} + +TEST_F(MobileAP, mobileap_agent_test_set_wifi_tethering_passphrase_n) { + int ret = tethering_set_wifi_tethering_passphrase(obj, NULL, ""); + EXPECT_EQ(ret, FALSE); +} + +TEST_F(MobileAP, mobileap_agent_test_set_get_wifi_tethering_passphrase_p) { + int ret = tethering_set_wifi_tethering_passphrase(obj, NULL, "password2"); + EXPECT_EQ(ret, TRUE); + + ret = tethering_get_wifi_tethering_passphrase(obj, NULL); + EXPECT_EQ(ret, TRUE); +} + +TEST_F(MobileAP, mobileap_agent_test_set_mtu_p) { + int ret = tethering_enable_wifi_tethering(obj, NULL, "test", "password", "g", 6, 1, 0, 10, 1, 0); + run_gmain_loop(2000); + EXPECT_EQ(ret, TRUE); + + ret = tethering_set_mtu(obj, NULL, 1500); + EXPECT_EQ(ret, TRUE); + + ret = tethering_get_data_packet_usage(obj, NULL); + EXPECT_EQ(ret, TRUE); + + ret = tethering_disable_wifi_tethering(obj, NULL, MOBILE_AP_ADDRESS_TYPE_IPV4); + run_gmain_loop(2000); + EXPECT_EQ(ret, TRUE); +} + +TEST_F(MobileAP, mobileap_agent_test_enable_port_forwarding_p) { + int ret = tethering_enable_port_forwarding(obj, NULL, TRUE); + EXPECT_EQ(ret, TRUE); + + ret = tethering_enable_port_forwarding(obj, NULL, FALSE); + EXPECT_EQ(ret, TRUE); +} + +TEST_F(MobileAP, mobileap_agent_test_enable_port_filtering_p) { + int ret = tethering_enable_port_filtering(obj, NULL, TRUE); + EXPECT_EQ(ret, TRUE); + + ret = tethering_enable_port_filtering(obj, NULL, FALSE); + EXPECT_EQ(ret, TRUE); +} + +TEST_F(MobileAP, mobileap_agent_test_wps_p) { + int ret = tethering_enable_wifi_tethering(obj, NULL, "test", "password", "g", 6, 1, 0, 10, 1, 0); + run_gmain_loop(2000); + EXPECT_EQ(ret, TRUE); + + ret = tethering_set_wps_pin(obj, NULL, "1234567890"); + EXPECT_EQ(ret, TRUE); + + ret = tethering_push_wps_button(obj, NULL); + EXPECT_EQ(ret, TRUE); + + ret = tethering_disable_wifi_tethering(obj, NULL, MOBILE_AP_ADDRESS_TYPE_IPV4); + run_gmain_loop(2000); + EXPECT_EQ(ret, TRUE); +} + +TEST_F(MobileAP, mobileap_agent_test_enable_disable_wifi_ipv6_tethering_p) { + int ret = tethering_enable_wifi_tethering(obj, NULL, "test", "password", "g", 6, 1, 0, 10, 1, 1); + run_gmain_loop(2000); + EXPECT_EQ(ret, TRUE); + + ret = tethering_disable_wifi_tethering(obj, NULL, MOBILE_AP_ADDRESS_TYPE_IPV6); + run_gmain_loop(2000); + EXPECT_EQ(ret, TRUE); +} + +/* Precondition: Tethering has to be disabled */ +TEST_F(MobileAP, mobileap_agent_test_set_wps_pin_n) { + int ret = tethering_set_wps_pin(obj, NULL, "1234567890"); + EXPECT_EQ(ret, FALSE); +} + +TEST_F(MobileAP, mobileap_agent_test_set_mtu_n) { + int ret = tethering_set_mtu(obj, NULL, 1500); + EXPECT_EQ(ret, FALSE); +} + +TEST_F(MobileAP, mobileap_agent_test_get_data_packet_usage_n) { + int ret = tethering_get_data_packet_usage(obj, NULL); + EXPECT_EQ(ret, FALSE); +} + +TEST_F(MobileAP, mobileap_agent_test_enable_disable_bt_tethering_p) { + int ret = tethering_enable_bt_tethering(obj, NULL, MOBILE_AP_ADDRESS_TYPE_IPV4); + run_gmain_loop(2000); + EXPECT_EQ(ret, TRUE); + + ret = tethering_disable_bt_tethering(obj, NULL, MOBILE_AP_ADDRESS_TYPE_IPV4); + run_gmain_loop(2000); + EXPECT_EQ(ret, TRUE); +} + +TEST_F(MobileAP, mobileap_agent_test_enable_disable_bt_ipv6_tethering_p) { + int ret = tethering_enable_bt_tethering(obj, NULL, MOBILE_AP_ADDRESS_TYPE_IPV6); + run_gmain_loop(2000); + EXPECT_EQ(ret, TRUE); + + ret = tethering_disable_bt_tethering(obj, NULL, MOBILE_AP_ADDRESS_TYPE_IPV6); + run_gmain_loop(2000); + EXPECT_EQ(ret, TRUE); +} + +TEST_F(MobileAP, mobileap_agent_test_bt_get_remote_device_name_n) { + char *name = NULL; + _bt_get_remote_device_name(NULL, NULL); + EXPECT_TRUE(name == NULL); + + _bt_get_remote_device_name("11:22:33:44:55:66", &name); + EXPECT_TRUE(name == NULL); +} + +TEST_F(MobileAP, mobileap_agent_test_disable_bt_tethering_n) { + int ret = tethering_disable_bt_tethering(obj, NULL, MOBILE_AP_ADDRESS_TYPE_IPV6); + EXPECT_EQ(ret, FALSE); +} + +TEST_F(MobileAP, mobileap_agent_test_enable_disable_dhcp_p) { + int ret = tethering_enable_dhcp(obj, NULL, TRUE); + EXPECT_EQ(ret, TRUE); + + ret = tethering_enable_dhcp(obj, NULL, FALSE); + EXPECT_EQ(ret, TRUE); +} + +TEST_F(MobileAP, mobileap_agent_test_enable_disable_dhcp_with_range_p) { + int ret = tethering_dhcp_range(obj, NULL, "192.168.100.1", "192.168.100.200"); + EXPECT_EQ(ret, TRUE); + + ret = tethering_enable_dhcp(obj, NULL, FALSE); + EXPECT_EQ(ret, TRUE); +} + +TEST_F(MobileAP, mobileap_agent_test_add_port_forwarding_rule_p) { + int ret = tethering_add_port_forwarding_rule(obj, NULL, "wlan0", "tcp", "192.168.0.10", 80, "192.168.0.1", 80); + EXPECT_EQ(ret, TRUE); +} + +TEST_F(MobileAP, mobileap_agent_test_reset_port_forwarding_rule_p) { + int ret = tethering_reset_port_forwarding_rule(obj, NULL); + EXPECT_EQ(ret, TRUE); +} + +TEST_F(MobileAP, mobileap_agent_test_add_port_filtering_rule_p) { + int ret = tethering_add_port_filtering_rule(obj, NULL, 80, "tcp", TRUE); + EXPECT_EQ(ret, TRUE); + + ret = tethering_add_port_filtering_rule(obj, NULL, 80, "tcp", FALSE); + EXPECT_EQ(ret, TRUE); +} + +TEST_F(MobileAP, mobileap_agent_test_add_custom_port_filtering_rule_p) { + int ret = tethering_add_custom_port_filtering_rule(obj, NULL, 43, 100, "tcp", TRUE); + EXPECT_EQ(ret, TRUE); + + ret = tethering_add_custom_port_filtering_rule(obj, NULL, 43, 100, "tcp", FALSE); + EXPECT_EQ(ret, TRUE); +} + +TEST_F(MobileAP, mobileap_agent_test_set_vpn_passthrough_rule_p) { + int ret = tethering_set_vpn_passthrough_rule(obj, NULL, 0, TRUE); + EXPECT_EQ(ret, TRUE); + + ret = tethering_set_vpn_passthrough_rule(obj, NULL, 1, TRUE); + EXPECT_EQ(ret, TRUE); + + ret = tethering_set_vpn_passthrough_rule(obj, NULL, 2, TRUE); + EXPECT_EQ(ret, TRUE); +} + +TEST_F(MobileAP, mobileap_agent_test_set_hostapd_tx_power_p) { + int ret = tethering_set_hostapd_tx_power(obj, NULL, 200); + EXPECT_EQ(ret, TRUE); +} + +TEST_F(MobileAP, mobileap_agent_test_get_hostapd_tx_power_p) { + int ret = tethering_get_hostapd_tx_power(obj, NULL); + EXPECT_EQ(ret, TRUE); +} + +TEST_F(MobileAP, mobileap_agent_test_change_mac_p) { + int ret = tethering_change_mac(obj, NULL, "11:22:33:44:55:66"); + EXPECT_EQ(ret, FALSE); +} + +/* Notification */ +TEST_F(MobileAP, mobileap_agent_test_create_timeout_noti_p) { + int ret = _create_timeout_noti(MOBILE_AP_TYPE_WIFI); + EXPECT_EQ(ret, MOBILE_AP_ERROR_NONE); + + ret = _create_timeout_noti(MOBILE_AP_TYPE_BT); + EXPECT_EQ(ret, MOBILE_AP_ERROR_NONE); + + ret = _create_timeout_noti(MOBILE_AP_TYPE_USB); + EXPECT_EQ(ret, MOBILE_AP_ERROR_NONE); + + ret = _create_timeout_noti(MOBILE_AP_TYPE_P2P); + EXPECT_EQ(ret, MOBILE_AP_ERROR_NONE); + +} + +TEST_F(MobileAP, mobileap_agent_test_create_connected_noti_p) { + int ret = _create_connected_noti(MOBILE_AP_TYPE_WIFI, 1); + EXPECT_EQ(ret, MOBILE_AP_ERROR_NONE); +} + +TEST_F(MobileAP, mobileap_agent_test_update_connected_noti_p) { + int ret = _update_connected_noti(MOBILE_AP_TYPE_WIFI, 3); + EXPECT_EQ(ret, MOBILE_AP_ERROR_NONE); +} + +TEST_F(MobileAP, mobileap_agent_test_delete_connected_noti_p) { + int ret = _delete_connected_noti(); + EXPECT_EQ(ret, MOBILE_AP_ERROR_NONE); +} + +TEST_F(MobileAP, mobileap_agent_test_create_security_restriction_noti_p) { + _create_security_restriction_noti(MOBILE_AP_TYPE_WIFI); +} + +TEST_F(MobileAP, mobileap_agent_test_is_enabled_by_type_p) { + gboolean ret = _mobileap_is_enabled_by_type(MOBILE_AP_TYPE_WIFI); + EXPECT_EQ(ret, FALSE); + + ret = _mobileap_is_enabled_by_type(MOBILE_AP_TYPE_BT); + EXPECT_EQ(ret, FALSE); + + ret = _mobileap_is_enabled_by_type(MOBILE_AP_TYPE_USB); + EXPECT_EQ(ret, FALSE); + + ret = _mobileap_is_enabled_by_type(MOBILE_AP_TYPE_WIFI_AP); + EXPECT_EQ(ret, FALSE); +} + +TEST_F(MobileAP, mobileap_agent_test_remove_dhcp_ack_timer_p) { + _flush_dhcp_ack_timer(); + _destroy_dhcp_ack_timer("11:22:33:44:55:66"); +} + +TEST_F(MobileAP, mobileap_agent_test_start_stop_timeout_cb_p) { + _start_timeout_cb(MOBILE_AP_TYPE_WIFI, TETHERING_CONN_TIMEOUT); + _stop_timeout_cb(MOBILE_AP_TYPE_WIFI); + + _start_timeout_cb(MOBILE_AP_TYPE_BT, TETHERING_CONN_TIMEOUT); + _stop_timeout_cb(MOBILE_AP_TYPE_BT); + + _start_timeout_cb(MOBILE_AP_TYPE_USB, TETHERING_CONN_TIMEOUT); + _stop_timeout_cb(MOBILE_AP_TYPE_USB); + + _start_timeout_cb(MOBILE_AP_TYPE_P2P, TETHERING_CONN_TIMEOUT); + _stop_timeout_cb(MOBILE_AP_TYPE_P2P); +} + +TEST_F(MobileAP, mobileap_agent_test_get_tethering_type_from_ip_n) { + mobile_ap_type_e type = MOBILE_AP_TYPE_MAX; + int ret = _get_tethering_type_from_ip("192.168.43.23", &type); + EXPECT_EQ(ret, MOBILE_AP_ERROR_INVALID_PARAM); +} + +TEST_F(MobileAP, mobileap_agent_test_get_station_info_p) { + int ret = tethering_get_station_info(obj, NULL); + EXPECT_EQ(ret, TRUE); +} + +TEST_F(MobileAP, mobileap_agent_test_disable_all_tethering_p) { + int ret = tethering_enable_bt_tethering(obj, NULL, MOBILE_AP_ADDRESS_TYPE_IPV4); + run_gmain_loop(2000); + EXPECT_EQ(ret, TRUE); + + ret = tethering_enable_wifi_tethering(obj, NULL, "test", "password", "g", 6, 1, 0, 10, 1, 1); + run_gmain_loop(4000); + EXPECT_EQ(ret, TRUE); + + ret = tethering_disable(obj, NULL); + run_gmain_loop(2000); + EXPECT_EQ(ret, TRUE); +} + +TEST_F(MobileAP, mobileap_agent_test_add_remove_station_info_p) { + int ret; + mobile_ap_station_info_t *info = (mobile_ap_station_info_t *)g_malloc(sizeof(mobile_ap_station_info_t)); + time_t tm; + + time(&tm); + info->tm = tm; + info->interface = MOBILE_AP_TYPE_WIFI; + g_strlcpy(info->ip, "192.168.43.123", sizeof(info->ip)); + g_strlcpy(info->mac, "11:22:33:44:55:66", sizeof(info->mac)); + info->hostname = g_strdup(MOBILE_AP_NAME_UNKNOWN); + + ret = _add_station_info(info); + EXPECT_EQ(ret, MOBILE_AP_ERROR_NONE); + + ret = _remove_station_info("11:22:33:44:55:66", _slist_find_station_by_mac); + EXPECT_EQ(ret, MOBILE_AP_ERROR_NONE); +} + +TEST_F(MobileAP, mobileap_agent_test_add_remove_multiple_station_info_p) { + int ret; + mobile_ap_station_info_t *info1 = (mobile_ap_station_info_t *)g_malloc(sizeof(mobile_ap_station_info_t)); + mobile_ap_station_info_t *info2 = (mobile_ap_station_info_t *)g_malloc(sizeof(mobile_ap_station_info_t)); + + time_t tm; + + time(&tm); + info1->tm = tm; + info1->interface = MOBILE_AP_TYPE_WIFI; + g_strlcpy(info1->ip, "192.168.43.123", sizeof(info1->ip)); + g_strlcpy(info1->mac, "11:22:33:44:55:66", sizeof(info1->mac)); + info1->hostname = g_strdup(MOBILE_AP_NAME_UNKNOWN); + + ret = _add_station_info(info1); + EXPECT_EQ(ret, MOBILE_AP_ERROR_NONE); + + info2->tm = tm; + info2->interface = MOBILE_AP_TYPE_WIFI; + g_strlcpy(info2->ip, "192.168.43.223", sizeof(info2->ip)); + g_strlcpy(info2->mac, "22:33:44:55:66:77", sizeof(info2->mac)); + info2->hostname = g_strdup(MOBILE_AP_NAME_UNKNOWN); + + ret = _remove_station_info_all(MOBILE_AP_TYPE_WIFI); + EXPECT_EQ(ret, MOBILE_AP_ERROR_NONE); +} + +TEST_F(MobileAP, mobileap_agent_test_update_station_count_p) { + _update_station_count(3); +} + +TEST_F(MobileAP, mobileap_agent_test_get_ipv6_interface_address_n) { + char *ip = NULL; + _get_ipv6_interface_address("wlan0", MOBILE_AP_IPV6_SCOPE_GLOBAL, &ip); + EXPECT_TRUE(ip == NULL); +} + +TEST_F(MobileAP, mobileap_agent_test_add_remve_ipv6_neigh_proxy_p) { + int ret = _add_ipv6_neigh_proxy("wlan0", "fd23::23"); + EXPECT_EQ(ret, TRUE); + + ret = _remove_ipv6_neigh_proxy("wlan0", "fd23::23"); + EXPECT_EQ(ret, TRUE); +} + +TEST_F(MobileAP, mobileap_agent_test_is_trying_operation_p) { + int ret = _is_trying_bt_operation(); + EXPECT_EQ(ret, FALSE); + + ret = _is_trying_p2p_operation(); + EXPECT_EQ(ret, FALSE); + + ret = _is_trying_usb_operation(); + EXPECT_EQ(ret, FALSE); + + ret = _is_trying_wifi_operation(); + EXPECT_EQ(ret, FALSE); +} + int main(int argc, char **argv) { InitGoogleTest(&argc, argv); diff --git a/unittest/unittest.h b/unittest/unittest.h index da74c95..ee4c7fc 100644 --- a/unittest/unittest.h +++ b/unittest/unittest.h @@ -20,6 +20,25 @@ extern "C" { #endif +#include +#include "mobileap_bluetooth.h" +#include "mobileap_common.h" +#include "mobileap_dbus.h" +#include "mobileap_handler.h" +#include "mobileap_network.h" +#include "mobileap_notification.h" +#include "mobileap_softap.h" +#include "mobileap_usb.h" +#include "mobileap_wfd.h" +#include "mobileap_wifi.h" +#include "mobileap_p2p.h" + +GVariant *get_softap_settings(const char *ssid, const char *passphrase, int sec_type, + int visibility, int channel, int mode, + const char *ip_address, const char *vendor); + +void run_gmain_loop(int interval); + #ifdef __cplusplus } #endif diff --git a/unittest/unittest_common.cpp b/unittest/unittest_common.cpp new file mode 100644 index 0000000..cd649aa --- /dev/null +++ b/unittest/unittest_common.cpp @@ -0,0 +1,54 @@ +#include "unittest.h" + +GMainLoop *main_loop = NULL; +guint timeout_id; + +GVariant *get_softap_settings(const char *ssid, const char *passphrase, int sec_type, + int visibility, int channel, int mode, + const char *ip_address, const char *vendor) +{ + GVariantBuilder *builder = NULL; + GVariant *params = NULL; + + builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); + if (builder == NULL) { + ERR("Failed to create builder"); + return NULL; + } + + g_variant_builder_add(builder, "{sv}", "ssid", g_variant_new_string(ssid)); + g_variant_builder_add(builder, "{sv}", "sec_type", g_variant_new_int32(sec_type)); + g_variant_builder_add(builder, "{sv}", "visibility", g_variant_new_boolean(visibility)); + g_variant_builder_add(builder, "{sv}", "channel", g_variant_new_int32(channel)); + g_variant_builder_add(builder, "{sv}", "mode", g_variant_new_int32(mode)); + + if (sec_type != 0) + g_variant_builder_add(builder, "{sv}", "passphrase", g_variant_new_string(passphrase)); + + if (strlen(ip_address)) + g_variant_builder_add(builder, "{sv}", "ip_address", g_variant_new_string(ip_address)); + + if (strlen(vendor)) + g_variant_builder_add(builder, "{sv}", "vendor", g_variant_new_string(vendor)); + + params = g_variant_builder_end(builder); + + return params; +} + +static gboolean timeout_cb(gpointer data) +{ + if (main_loop) { + g_main_loop_quit(main_loop); + main_loop = NULL; + } +} + +void run_gmain_loop(int interval) +{ + main_loop = g_main_loop_new(NULL, false); + timeout_id = g_timeout_add(interval, timeout_cb, main_loop); + g_main_loop_run(main_loop); + g_source_remove(timeout_id); + main_loop = NULL; +} -- 2.7.4