Data: Added code for getting wifi information 82/49082/1
authorHyojung Jo <hj903.jo@samsung.com>
Tue, 6 Oct 2015 08:11:05 +0000 (17:11 +0900)
committerHyojung Jo <hj903.jo@samsung.com>
Tue, 6 Oct 2015 08:11:05 +0000 (17:11 +0900)
Change-Id: Ife03a3fbf73ee1e6cbd4dec2da9f0b8a3a5aa0e8
Signed-off-by: Hyojung Jo <hj903.jo@samsung.com>
CMakeLists.txt
include/data/data_wireless.h [new file with mode: 0644]
packaging/org.tizen.settings.spec
src/data/data_wireless.c [new file with mode: 0644]

index 8f0c9ed..dcf84de 100644 (file)
@@ -25,6 +25,7 @@ pkg_check_modules(PKGS REQUIRED
                capi-system-device
                capi-system-system-settings
                capi-base-utils-i18n
+               capi-network-wifi
                app-utils
                tv-service
                )
@@ -69,6 +70,7 @@ SET(SRCS
        src/layout/layout_support.c
        src/layout/layout_info.c
        src/layout/layout_voice.c
+       src/data/data_wireless.c
    )
 
 SET(TARGET_EDJ "${PROJECT_NAME}.edj")
diff --git a/include/data/data_wireless.h b/include/data/data_wireless.h
new file mode 100644 (file)
index 0000000..7f8986f
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __AIR_SETTINGS_DATA_WIRELESS_H__
+#define __AIR_SETTINGS_DATA_WIRELESS_H__
+
+#include <wifi.h>
+
+struct wifi_ap_info {
+       wifi_ap_h ap;
+       char *essid;
+       wifi_security_type_e secure_type;
+       wifi_connection_state_e connection_state;
+};
+
+struct data_class *get_wireless_data_class(void);
+
+#endif /* __AIR_SETTINGS_DATA_WIRELESS_H__ */
index e2f8bf8..1709ed9 100644 (file)
@@ -14,6 +14,7 @@ BuildRequires: pkgconfig(capi-system-info)
 BuildRequires: pkgconfig(capi-system-device)
 BuildRequires: pkgconfig(capi-system-system-settings)
 BuildRequires: pkgconfig(capi-base-utils-i18n)
+BuildRequires: pkgconfig(capi-network-wifi)
 BuildRequires: pkgconfig(app-utils)
 BuildRequires: pkgconfig(tv-service)
 
diff --git a/src/data/data_wireless.c b/src/data/data_wireless.c
new file mode 100644 (file)
index 0000000..41c01b3
--- /dev/null
@@ -0,0 +1,200 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <Elementary.h>
+#include <app_debug.h>
+
+#include "data/data_wireless.h"
+#include "datamgr.h"
+
+static bool _create(struct datamgr *dmgr)
+{
+       if (wifi_initialize() != WIFI_ERROR_NONE) {
+               _ERR("wifi_initialize failed.");
+               return false;
+       }
+
+       return true;
+}
+
+static bool _destroy(struct datamgr *dmgr)
+{
+       struct wifi_ap_info *ap_info;
+
+       if (!dmgr) {
+               _ERR("Invalid argument.");
+               return false;
+       }
+
+       EINA_LIST_FREE(dmgr->list, ap_info) {
+               if (!ap_info)
+                       continue;
+
+               free(ap_info->essid);
+               free(ap_info);
+
+               ap_info = NULL;
+       }
+
+       if (wifi_deinitialize() != WIFI_ERROR_NONE) {
+               _ERR("wifi_deinitialize failed.");
+               return false;
+       }
+
+       return true;
+}
+
+static bool _wifi_found_ap_cb(wifi_ap_h ap, void *data)
+{
+       struct wifi_ap_info *ap_info;
+       Eina_List **list;
+       wifi_connection_state_e connection_state;
+       wifi_security_type_e secure_type;
+       bool activated;
+       char *essid;
+       int r;
+
+       if (!data) {
+               _ERR("Invalid argument.");
+               return EINA_FALSE;
+       }
+
+       list = data;
+
+       r = wifi_is_activated(&activated);
+       if (r != WIFI_ERROR_NONE) {
+               _ERR("wifi_is_activated failed.");
+               return EINA_FALSE;
+       }
+
+       r = wifi_ap_get_essid(ap, &essid);
+       if (r != WIFI_ERROR_NONE) {
+               _ERR("wifi_ap_get_essid failed.");
+               return EINA_FALSE;
+       }
+
+       r = wifi_ap_get_connection_state(ap, &connection_state);
+       if (r != WIFI_ERROR_NONE) {
+               _ERR("wifi_ap_get_connection_state failed.");
+               return EINA_FALSE;
+       }
+
+       r = wifi_ap_get_security_type(ap, &secure_type);
+       if (r != WIFI_ERROR_NONE) {
+               _ERR("wifi_ap_get_security_type failed.");
+               return EINA_FALSE;
+       }
+
+       ap_info = calloc(1, sizeof(*ap_info));
+       if (!ap_info) {
+               _ERR("Calloc failed.");
+               return EINA_FALSE;
+       }
+
+       ap_info->ap = ap;
+       ap_info->essid = strdup(essid);
+       ap_info->connection_state = connection_state;
+       ap_info->secure_type = secure_type;
+
+       *list = eina_list_append(*list, ap_info);
+
+       return EINA_TRUE;
+}
+
+static void _wifi_scan_finished_cb(wifi_error_e err, void *data)
+{
+       struct datamgr *dmgr;
+       int r;
+
+       if (!data) {
+               _ERR("Invalid argument.");
+               return;
+       }
+       dmgr = data;
+
+       r = wifi_foreach_found_aps(_wifi_found_ap_cb, &dmgr->list);
+       if (r != WIFI_ERROR_NONE) {
+               _ERR("wifi_foreach_found_aps failed.");
+               return;
+       }
+
+       dmgr->update_done_cb(dmgr->user_data);
+}
+
+static void _wifi_activated_cb(wifi_error_e err, void *data)
+{
+       int r;
+
+       if (!data) {
+               _ERR("Invalid argument.");
+               return;
+       }
+
+       if (err != WIFI_ERROR_NONE) {
+               _ERR("wifi activation failed.");
+               return;
+       }
+
+       r = wifi_scan(_wifi_scan_finished_cb, data);
+       if (r != WIFI_ERROR_NONE) {
+               _ERR("wifi_scan failed.");
+               return;
+       }
+}
+
+static bool _update(struct datamgr *dmgr)
+{
+       bool activated;
+       int r;
+
+       if (!dmgr) {
+               _ERR("Invalid argument.");
+               return false;
+       }
+
+       r = wifi_is_activated(&activated);
+       if (r != WIFI_ERROR_NONE) {
+               _ERR("wifi_is_activated failed.");
+               return false;
+       }
+
+       if (activated) {
+               r = wifi_scan(_wifi_scan_finished_cb, dmgr);
+               if (r != WIFI_ERROR_NONE) {
+                       _ERR("wifi_scan failed.");
+                       return false;
+               }
+       } else {
+               r = wifi_activate(_wifi_activated_cb, dmgr);
+               if (r != WIFI_ERROR_NONE) {
+                       _ERR("wifi_activated failed.");
+                       return false;
+               }
+       }
+
+       return true;
+}
+
+static struct data_class _dclass = {
+       .create = _create,
+       .destroy = _destroy,
+       .update = _update,
+};
+
+struct data_class *get_wireless_data_class(void)
+{
+       return &_dclass;
+}