Add configuration file for Tizen Wi-Fi Direct features 17/139217/4
authorJiung Yu <jiung.yu@samsung.com>
Tue, 18 Jul 2017 02:28:28 +0000 (11:28 +0900)
committerJiung Yu <jiung.yu@samsung.com>
Tue, 18 Jul 2017 09:10:42 +0000 (18:10 +0900)
Description: We replace build config flags with the configuration file.
These features are not included in model config. So we can't get
availability of the feature at run time. I expect that managing
configuraions with a file can make porting process easy.

Change-Id: Ie2073decd0f4ec4b924c458704ea90479723d119
Signed-off-by: Yu jiung <jiung.yu@samsung.com>
CMakeLists.txt
files/wifi-direct-manager.conf.in [new file with mode: 0644]
include/wifi-direct-manager.h
include/wifi-direct-util.h
packaging/wifi-direct-manager.spec
src/wifi-direct-iface.c
src/wifi-direct-manager.c
src/wifi-direct-session.c
src/wifi-direct-util.c

index 0215d8f..dc185c6 100644 (file)
@@ -95,6 +95,7 @@ TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} -ldl)
 
 CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/files/dhcpd-notify.sh.in ${CMAKE_SOURCE_DIR}/files/dhcpd-notify.sh @ONLY)
 CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/files/dhcpd.conf.in ${CMAKE_SOURCE_DIR}/files/dhcpd.conf @ONLY)
+CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/files/wifi-direct-manager.conf.in ${CMAKE_SOURCE_DIR}/files/wifi-direct-manager.conf @ONLY)
 CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/files/p2p_supp.conf.in ${CMAKE_SOURCE_DIR}/files/p2p_supp.conf @ONLY)
 CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/files/p2p_supp.sh.in ${CMAKE_SOURCE_DIR}/files/p2p_supp.sh @ONLY)
 CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/files/udhcp_script.non-autoip.in ${CMAKE_SOURCE_DIR}/files/udhcp_script.non-autoip @ONLY)
@@ -110,6 +111,7 @@ INSTALL(FILES ${CMAKE_SOURCE_DIR}/files/dhcpd-notify.sh DESTINATION ${BIN_DIR})
 INSTALL(FILES ${CMAKE_SOURCE_DIR}/files/p2p_supp.conf DESTINATION ${TZ_SYS_RO_ETC}/wifi-direct)
 INSTALL(FILES ${CMAKE_SOURCE_DIR}/files/p2p_supp.conf DESTINATION ${TZ_SYS_ETC})
 INSTALL(FILES ${CMAKE_SOURCE_DIR}/files/dhcpd.conf DESTINATION ${TZ_SYS_RO_ETC}/wifi-direct)
+INSTALL(FILES ${CMAKE_SOURCE_DIR}/files/wifi-direct-manager.conf DESTINATION ${TZ_SYS_RO_ETC}/wifi-direct)
 INSTALL(FILES ${CMAKE_SOURCE_DIR}/files/wifi-direct-dhcp.sh DESTINATION ${BIN_DIR})
 
 IF("${ARCH}" MATCHES "^arm.*|.*86.*")
diff --git a/files/wifi-direct-manager.conf.in b/files/wifi-direct-manager.conf.in
new file mode 100644 (file)
index 0000000..dfb13dd
--- /dev/null
@@ -0,0 +1,4 @@
+[wfd-manager]
+on_demand=yes
+connection_agent=yes
+ip_over_eapol=yes
index 6530ccf..a08e745 100644 (file)
@@ -207,6 +207,9 @@ typedef struct {
        gboolean is_tethering_wifi_supported;
        gboolean is_tethering_wifi_direct_supported;
        gboolean is_asp_supported;
+       gboolean is_on_demand;
+       gboolean is_connection_agent;
+       gboolean is_ip_over_eapol;
 } wfd_manager_s;
 
 wfd_manager_s *wfd_get_manager();
index 4014f8b..c4645b7 100644 (file)
@@ -56,7 +56,8 @@ void wfd_util_set_dev_name_notification();
 void wfd_util_unset_dev_name_notification();
 int wfd_util_set_country();
 
-void wfd_util_check_features();
+void wfd_util_check_features(wfd_manager_s *manager);
+void wfd_util_load_wfd_conf(wfd_manager_s *manager);
 int wfd_util_check_wifi_state();
 int wfd_util_check_p2p_hotspot_state();
 int wfd_util_check_mobile_ap_state();
index c65ba59..62d08bd 100644 (file)
@@ -8,7 +8,7 @@
 
 Name:          wifi-direct-manager
 Summary:       Wi-Fi Direct manger
-Version:       1.2.232
+Version:       1.2.233
 Release:       1
 Group:      Network & Connectivity/Wireless
 License:    Apache-2.0
@@ -410,6 +410,7 @@ cp -f 500.wifi-direct-manager_upgrade.sh %{buildroot}%{upgrade_script_path}
 
 %post
 chmod 644 %{TZ_SYS_RO_ETC}/wifi-direct/dhcpd.conf
+chmod 644 %{TZ_SYS_RO_ETC}/wifi-direct/wifi-direct-manager.conf
 chmod 755 %{_bindir}/dhcpd-notify.sh
 chmod 755 %{TZ_SYS_RO_ETC}/wifi-direct/udhcp_script.non-autoip
 chmod 755 %{_bindir}/wifi-direct-server.sh
@@ -593,6 +594,7 @@ esac
 %defattr(-,network_fw,network_fw,-)
 %config %{TZ_SYS_RO_ETC}/wifi-direct/ccode.conf
 %config %{TZ_SYS_RO_ETC}/wifi-direct/dhcpd.conf
+%config %{TZ_SYS_RO_ETC}/wifi-direct/wifi-direct-manager.conf
 %config %{TZ_SYS_RO_ETC}/wifi-direct/p2p_supp.conf
 %config %{_sysconfdir}/dbus-1/system.d/wfd-manager.conf
 %attr(644,-,-) %{TZ_SYS_ETC}/p2p_supp.conf
index a5bbfe9..a84beaa 100644 (file)
@@ -2631,7 +2631,7 @@ static void __get_asp_connect_params(GVariantIter *iter, wfd_oem_asp_prov_s *pro
                if (!g_strcmp0(key, "service_mac")) {
                        g_variant_get(var, "&s", &mac_str);
                        if (mac_str == NULL)
-                               memset(prov_params->session_mac, 0, sizeof(prov_params->service_mac));
+                               memset(prov_params->service_mac, 0, sizeof(prov_params->service_mac));
                        else
                                macaddr_atoe(mac_str, prov_params->service_mac);
                } else if (!g_strcmp0(key, "adv_id")) {
@@ -2673,7 +2673,7 @@ static void __get_asp_confirm_params(GVariantIter *iter, wfd_oem_asp_prov_s *pro
                if (!g_strcmp0(key, "service_mac")) {
                        g_variant_get(var, "&s", &mac_str);
                        if (mac_str == NULL)
-                               memset(prov_params->session_mac, 0, sizeof(prov_params->service_mac));
+                               memset(prov_params->service_mac, 0, sizeof(prov_params->service_mac));
                        else
                                macaddr_atoe(mac_str, prov_params->service_mac);
                } else if (!g_strcmp0(key, "adv_id")) {
index 69c2039..dde59e5 100644 (file)
@@ -1711,7 +1711,9 @@ static wfd_manager_s *wfd_manager_init()
        manager->max_station = 8;
        manager->session_timer = 120;
        manager->auto_group_remove_enable = TRUE;
-       wfd_util_check_features();
+       wfd_util_check_features(manager);
+       wfd_util_load_wfd_conf(manager);
+
        res = _wfd_local_init_device(manager);
        if (res < 0) {
                WDS_LOGE("Failed to initialize local device");
index 1fd492b..b4d59c5 100644 (file)
@@ -1160,9 +1160,6 @@ int wfd_session_process_event(wfd_manager_s *manager, wfd_oem_event_s *event)
                }
        }
                break;
-       if (res < 0)
-               _wfd_notify_session_failed(manager, event->dev_addr);
-       break;
        default:
                break;
        }
index bcd20bd..f60d109 100644 (file)
 #endif
 
 #define COUNTRY_CODE_FILE tzplatform_mkpath(TZ_SYS_RO_ETC, "wifi-direct/ccode.conf")
+#define WFD_MANGER_CONF_FILE tzplatform_mkpath(TZ_SYS_RO_ETC, "wifi-direct/wifi-direct-manager.conf")
+#define WFD_CONF_GROUP_NAME "wfd-manager"
+
+enum wfd_util_conf_key {
+       WFD_CONF_ON_DEMAND,
+       WFD_CONF_CONNECTION_AGENT,
+       WFD_CONF_IP_OVER_EAPOL,
+       WFD_CONF_MAX,
+};
+
+struct key_value {
+       int num;
+       const char *key;
+       char *value;
+};
+
+static GKeyFile *__load_key_file()
+{
+       __WDS_LOG_FUNC_ENTER__;
+       GKeyFile *key_file = NULL;
+       GError *error = NULL;
+
+       key_file = g_key_file_new();
+       if (!g_key_file_load_from_file(key_file, WFD_MANGER_CONF_FILE, 0, &error)) {
+               WDS_LOGE("Unable to load %s: %s", WFD_MANGER_CONF_FILE, error->message);
+               g_clear_error(&error);
+               g_key_file_free(key_file);
+               key_file = NULL;
+       }
+
+       __WDS_LOG_FUNC_EXIT__;
+       return key_file;
+}
+
+
+static void __load_wfd_config(GKeyFile *key_file, struct key_value *conf_key_val)
+{
+       __WDS_LOG_FUNC_ENTER__;
+       GError *error = NULL;
+       int i = 0;
+       if (!conf_key_val) {
+               __WDS_LOG_FUNC_EXIT__;
+               return;
+       }
+
+       key_file = __load_key_file();
+       if (!key_file) {
+               __WDS_LOG_FUNC_EXIT__;
+               return;
+       }
+
+       for (i = 0; i < WFD_CONF_MAX; i++) {
+               conf_key_val[i].value = g_key_file_get_string(key_file,
+                               WFD_CONF_GROUP_NAME, conf_key_val[i].key, &error);
+               if (!conf_key_val[i].value) {
+                       WDS_LOGE("Unable to load %s : %s", conf_key_val[i].key, error->message);
+                       g_clear_error(&error);
+
+               } else {
+                       WDS_LOGD("key [%s] value [%s]\n",
+                                       conf_key_val[i].key, conf_key_val[i].value);
+               }
+               if (conf_key_val[i].value && strlen(conf_key_val[i].value) == 0) {
+                       g_free(conf_key_val[i].value);
+                       conf_key_val[i].value = NULL;
+               }
+       }
+
+       __WDS_LOG_FUNC_EXIT__;
+       return;
+}
+
+static void __unload_wfd_config(GKeyFile *key_file, struct key_value *conf_key_val)
+{
+       __WDS_LOG_FUNC_ENTER__;
+       int i = 0;
+       if (!key_file || !conf_key_val) {
+               __WDS_LOG_FUNC_EXIT__;
+               return;
+       }
+
+       for (i = 0; i < WFD_CONF_MAX; i++) {
+               g_free(conf_key_val[i].value);
+       }
+
+       g_key_file_free(key_file);
+       __WDS_LOG_FUNC_EXIT__;
+       return;
+}
+
+void wfd_util_load_wfd_conf(wfd_manager_s * manager)
+{
+       __WDS_LOG_FUNC_ENTER__;
+
+       GKeyFile *key_file = NULL;
+       struct key_value wfd_conf[] = {
+                       {WFD_CONF_ON_DEMAND, "on_demand", NULL},
+                       {WFD_CONF_CONNECTION_AGENT, "connection_agent", NULL},
+                       {WFD_CONF_IP_OVER_EAPOL, "ip_over_eapol", NULL},
+                       {WFD_CONF_MAX, NULL, NULL},
+       };
+
+       if (!manager) {
+               __WDS_LOG_FUNC_EXIT__;
+               return;
+       }
+
+       __load_wfd_config(key_file, wfd_conf);
+
+       if (wfd_conf[WFD_CONF_ON_DEMAND].value &&
+                       g_strcmp0(wfd_conf[WFD_CONF_ON_DEMAND].value, "yes") == 0)
+               manager->is_on_demand = true;
+       else
+               manager->is_on_demand = false;
+
+       if (wfd_conf[WFD_CONF_CONNECTION_AGENT].value &&
+                       g_strcmp0(wfd_conf[WFD_CONF_CONNECTION_AGENT].value, "yes") == 0)
+               manager->is_connection_agent = true;
+       else
+               manager->is_connection_agent = false;
+
+       if (wfd_conf[WFD_CONF_IP_OVER_EAPOL].value &&
+                       g_strcmp0(wfd_conf[WFD_CONF_IP_OVER_EAPOL].value, "yes") == 0)
+               manager->is_ip_over_eapol = true;
+       else
+               manager->is_ip_over_eapol = false;
+
+       __unload_wfd_config(key_file, wfd_conf);
+
+       __WDS_LOG_FUNC_EXIT__;
+       return;
+}
 
 static int _txt_to_mac(char *txt, unsigned char *mac)
 {
@@ -492,57 +624,67 @@ static void __check_feature_supported(const char *key,
 
 static bool __is_wifi_direct_display_feature_supported()
 {
+       __WDS_LOG_FUNC_ENTER__;
        bool supported;
 
        __check_feature_supported(WIFI_DIRECT_DISPLAY_FEATURE, &supported);
 
+       __WDS_LOG_FUNC_EXIT__;
        return supported;
 }
 
 static bool __is_wifi_direct_service_discovery_feature_supported()
 {
+       __WDS_LOG_FUNC_ENTER__;
        bool supported;
 
        __check_feature_supported(WIFI_DIRECT_SERVICE_DISCOVERY_FEATURE, &supported);
 
+       __WDS_LOG_FUNC_EXIT__;
        return supported;
 }
 
 static bool __is_asp_feature_supported()
 {
+       __WDS_LOG_FUNC_ENTER__;
        bool supported;
 
        __check_feature_supported(ASP_FEATURE, &supported);
 
+       __WDS_LOG_FUNC_EXIT__;
        return supported;
 }
 
 static bool __is_tethering_wifi_feature_supported()
 {
+       __WDS_LOG_FUNC_ENTER__;
        bool supported;
 
        __check_feature_supported(TETHERING_WIFI_FEATURE, &supported);
 
+       __WDS_LOG_FUNC_EXIT__;
        return supported;
 }
 
 static bool __is_tethering_wifi_direct_feature_supported()
 {
+       __WDS_LOG_FUNC_ENTER__;
        bool supported;
 
        __check_feature_supported(TETHERING_WIFI_DIRECT_FEATURE, &supported);
 
+       __WDS_LOG_FUNC_EXIT__;
        return supported;
 }
 
-void wfd_util_check_features()
+void wfd_util_check_features(wfd_manager_s * manager)
 {
        __WDS_LOG_FUNC_ENTER__;
-       wfd_manager_s * manager = NULL;
 
-       manager = wfd_get_manager();
-       if (!manager)
+       if (!manager) {
+               __WDS_LOG_FUNC_EXIT__;
                return;
+       }
 
        manager->is_on_demand_supported = TRUE;
 
@@ -571,6 +713,7 @@ void wfd_util_check_features()
        else
                manager->is_tethering_wifi_direct_supported = FALSE;
 
+       __WDS_LOG_FUNC_EXIT__;
        return;
 
 }