Make the first wireless interface up and start wpa_supplicant if the wireless interfa...
authorsaerome.kim <saerome.kim@samsung.com>
Mon, 3 Jul 2017 06:06:42 +0000 (15:06 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 17 Jul 2017 02:35:37 +0000 (11:35 +0900)
Signed-off-by: saerome.kim <saerome.kim@samsung.com>
CMakeLists.txt
packaging/meshd.spec
src/mesh-service-interface.c

index a5d32a9..5cd0e85 100644 (file)
@@ -15,7 +15,8 @@ SET(PKG_MODULES
                libnl-genl-3.0
                dbus-1
                libcrypto
-               libtzplatform-config)
+               libtzplatform-config
+               capi-network-wifi-manager)
 pkg_check_modules(daemon_pkgs REQUIRED ${PKG_MODULES})
 
 MESSAGE(" - Adding external C flags")
index 801908b..7596874 100644 (file)
@@ -18,6 +18,7 @@ BuildRequires: pkgconfig(libnl-3.0)
 BuildRequires: pkgconfig(dbus-1)
 BuildRequires: pkgconfig(libcrypto)
 BuildRequires: pkgconfig(libtzplatform-config)
+BuildRequires: pkgconfig(capi-network-wifi-manager)
 BuildRequires: cmake
 # if meshd do dhcp instead of connman
 Requires: net-tools
index b7aadcd..cb4bacc 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <glib.h>
 #include <gio/gio.h>
+#include <wifi-manager.h>
 
 #include "mesh.h"
 #include "mesh-log.h"
@@ -45,6 +46,34 @@ typedef struct _meshd_dbus_client_s {
        gchar *bus_name;
 } meshd_dbus_client_s;
 
+#define CASE_TO_STR(x) case x: return #x;
+
+static const char* wifi_error_to_string(wifi_manager_error_e err)
+{
+       switch (err) {
+       /* CHECK: List all enum values here */
+       CASE_TO_STR(WIFI_MANAGER_ERROR_NONE)
+       CASE_TO_STR(WIFI_MANAGER_ERROR_INVALID_PARAMETER)
+       CASE_TO_STR(WIFI_MANAGER_ERROR_OUT_OF_MEMORY)
+       CASE_TO_STR(WIFI_MANAGER_ERROR_INVALID_OPERATION)
+       CASE_TO_STR(WIFI_MANAGER_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED)
+       CASE_TO_STR(WIFI_MANAGER_ERROR_OPERATION_FAILED)
+       CASE_TO_STR(WIFI_MANAGER_ERROR_NO_CONNECTION)
+       CASE_TO_STR(WIFI_MANAGER_ERROR_NOW_IN_PROGRESS)
+       CASE_TO_STR(WIFI_MANAGER_ERROR_ALREADY_EXISTS)
+       CASE_TO_STR(WIFI_MANAGER_ERROR_OPERATION_ABORTED)
+       CASE_TO_STR(WIFI_MANAGER_ERROR_DHCP_FAILED)
+       CASE_TO_STR(WIFI_MANAGER_ERROR_INVALID_KEY)
+       CASE_TO_STR(WIFI_MANAGER_ERROR_NO_REPLY)
+       CASE_TO_STR(WIFI_MANAGER_ERROR_SECURITY_RESTRICTED)
+       CASE_TO_STR(WIFI_MANAGER_ERROR_ALREADY_INITIALIZED)
+       CASE_TO_STR(WIFI_MANAGER_ERROR_PERMISSION_DENIED)
+       CASE_TO_STR(WIFI_MANAGER_ERROR_NOT_SUPPORTED)
+       default :
+               return "WIFI_MANAGER_ERROR_UNKNOWN";
+       }
+}
+
 NetMesh* meshd_dbus_get_object()
 {
        return meshd_dbus_object;
@@ -154,6 +183,24 @@ static gboolean _meshd_dbus_handle_enable(Manager *object,
        mesh_service *service = (mesh_service *)user_data;
        mesh_interface_s *info = service->interface_info;
 
+       wifi_manager_h wifi_handle = NULL;
+       bool wifi_activated = false;
+
+       /* Initialize Wi-Fi driver */
+       ret = wifi_manager_initialize(&wifi_handle);
+       if (WIFI_MANAGER_ERROR_NONE != ret)
+               MESH_LOGE("Failed to get wifi manager handle ! [%s(%X)]",
+                       wifi_error_to_string(ret), ret);
+
+       wifi_manager_is_activated(wifi_handle, &wifi_activated);
+       if (false == wifi_activated) {
+               ret = wifi_manager_activate(wifi_handle, NULL, NULL);
+               if (WIFI_MANAGER_ERROR_NONE != ret) {
+                       MESH_LOGE("Failed to activate wifi ! [%s(%X)]", wifi_error_to_string(ret), ret);
+               }
+       }
+       wifi_manager_deinitialize(wifi_handle);
+
        if (service->mesh_activated) {
                /* Already activated */
                manager_complete_enable(object, invocation, MESHD_ERROR_NONE);