From 5282da891091be413bb28c52896f39727f59c5b5 Mon Sep 17 00:00:00 2001 From: Hyojung Jo Date: Mon, 12 Oct 2015 15:55:00 +0900 Subject: [PATCH] Data: Added the wifi AP connect function Change-Id: I65049536ca43283f81fa04e296af5e4d5ebb220c Signed-off-by: Hyojung Jo --- src/data/data_wireless.c | 111 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 104 insertions(+), 7 deletions(-) diff --git a/src/data/data_wireless.c b/src/data/data_wireless.c index fe2d543..bd8a5cf 100644 --- a/src/data/data_wireless.c +++ b/src/data/data_wireless.c @@ -60,6 +60,7 @@ static void _free_wifi_list(Eina_List *list) if (!ap_info) continue; + wifi_ap_destroy(ap_info->ap); free(ap_info->essid); free(ap_info); @@ -111,34 +112,40 @@ static bool _wifi_found_ap_cb(wifi_ap_h ap, void *data) r = wifi_is_activated(&activated); if (r != WIFI_ERROR_NONE) { _ERR("wifi_is_activated failed."); - return EINA_FALSE; + return EINA_TRUE; } r = wifi_ap_get_essid(ap, &essid); if (r != WIFI_ERROR_NONE) { _ERR("wifi_ap_get_essid failed."); - return EINA_FALSE; + return EINA_TRUE; } r = wifi_ap_get_connection_state(ap, &connection_state); if (r != WIFI_ERROR_NONE) { _ERR("wifi_ap_get_connection_state failed."); - return EINA_FALSE; + return EINA_TRUE; } r = wifi_ap_get_security_type(ap, &secure_type); if (r != WIFI_ERROR_NONE) { _ERR("wifi_ap_get_security_type failed."); - return EINA_FALSE; + return EINA_TRUE; } ap_info = calloc(1, sizeof(*ap_info)); if (!ap_info) { _ERR("Calloc failed."); - return EINA_FALSE; + return EINA_TRUE; + } + + r = wifi_ap_clone(&ap_info->ap, ap); + if (r != WIFI_ERROR_NONE) { + _ERR("wifi_ap_clone failed."); + free(ap_info); + return EINA_TRUE; } - ap_info->ap = ap; ap_info->essid = strdup(essid); ap_info->connection_state = connection_state; ap_info->secure_type = secure_type; @@ -227,9 +234,99 @@ static bool _update(void *dclass_data) return true; } +bool _wifi_forget_last_ap(void) +{ + wifi_ap_h ap; + int r; + + r = wifi_get_connected_ap(&ap); + if (r == WIFI_ERROR_NO_CONNECTION) { + return true; + } else if (r != WIFI_ERROR_NONE) { + _ERR("Get connected ap failed."); + return false; + } + + r = wifi_forget_ap(ap); + if (r != WIFI_ERROR_NONE) { + _ERR("Forget ap failed."); + wifi_ap_destroy(ap); + return false; + } + + return true; +} + +bool _wifi_set_passcode(wifi_ap_h ap, char *passcode) +{ + int r; + + if (!ap || !passcode) + return false; + + r = wifi_ap_set_passphrase(ap, passcode); + if (r != WIFI_ERROR_NONE) { + _ERR("Set passcode failed."); + return false; + } + + return true; +} + +static void _wifi_connected_cb(wifi_error_e err, void *user_data) +{ + struct _priv *priv; + + if (!user_data) { + _ERR("Invalid argument."); + return; + } + + priv = user_data; + + if (err != WIFI_ERROR_NONE) { + _ERR("Connect ap failed."); + return; + } + + if (priv->event_cb) + priv->event_cb(EVENT_DATA_SELECT_DONE, priv->cb_data); +} + bool _select(void *dclass_data, Elm_Object_Item *it, void *data) { - /* It should be implemented later */ + struct _priv *priv; + struct wifi_ap_info *ap_info; + int r; + + if (!dclass_data || !it) { + _ERR("Invalid argument."); + return false; + } + + priv = dclass_data; + + ap_info = elm_object_item_data_get(it); + if (!ap_info || !ap_info->ap) + return false; + + if (!_wifi_forget_last_ap()) { + _ERR("Forget last ap failed."); + return false; + } + + if (data) { + if (!_wifi_set_passcode(ap_info->ap, (char *)data)) { + _ERR("Set passcode failed."); + return false; + } + } + + r = wifi_connect(ap_info->ap, _wifi_connected_cb, priv); + if (r != WIFI_ERROR_NONE) { + _ERR("Wifi connect failed."); + return false; + } return true; } -- 2.7.4