char profile_name[MAX_NAME_SIZE];
- wifi_ap_h ap;
+ CWifiAp *ap;
char *ap_name;
char *ap_pwd;
}
if (priv->ap) {
- priv->pWifiMgr->DestroyAP(priv->ap);
+ delete priv->ap;
priv->ap = NULL;
}
- priv->pWifiMgr->CloneAP(&priv->ap, ap_info->ap);
+ priv->ap = new CWifiAp(ap_info->ap->Handle());
if (!priv->ap) {
_ERR("ap clone failed.");
return;
}
-bool CNetworkMainView::sm_CbWifiFoundAP(wifi_ap_h ap, void *data)
+bool CNetworkMainView::sm_CbWifiFoundAP(CWifiAp *ap, void *data)
{
- _DBG();
- CNetworkMainView *instance = NULL;
+ CNetworkMainView *root = (CNetworkMainView*)data;
+ bool ret = false;
- if (!data) {
- _ERR("data is NULL.");
- return true;
- }
+ if (root)
+ ret = root->m_OnWifiFoundAP(ap);
- instance = (CNetworkMainView *) data;
- instance->m_OnWifiFoundAP(ap);
- return true;
+ return ret;
}
-void CNetworkMainView::m_OnWifiFoundAP(wifi_ap_h ap)
+bool CNetworkMainView::m_OnWifiFoundAP(CWifiAp *ap)
{
- _DBG();
bool ret;
bool state;
struct wifi_ap_info *ap_info;
ret = m->pWifiMgr->IsActivated(&state);
if (ret != true || state == 0) {
_ERR("failt to wifi_is_activated");
- return ;
+ return false;
}
- ap_info = (struct wifi_ap_info *) calloc(1, sizeof(*ap_info));
+ ap_info = new wifi_ap_info;
if (!ap_info) {
_ERR("calloc failed");
- return ;
+ return false;
}
- ret = m->pWifiMgr->GetESSID(ap, ap_info->essid);
- if(ret != true) {
+ if (!ap->GetEssid(ap_info->essid, sizeof(ap_info->essid))) {
_ERR("Fail to get info");
- return ;
+ return false;
}
- ret = m->pWifiMgr->GetConnectionState(ap, &ap_info->state);
- if(ret != true) {
+ if (!ap->GetConnectionState(&ap_info->state)) {
_ERR("Fail to get info");
- return ;
+ return false;
}
- ret = m->pWifiMgr->GetSecurityType(ap, &ap_info->secure_type);
- if(ret != true) {
+ if (!ap->GetSecurityType(&ap_info->secure_type)) {
_ERR("Fail to get info");
- return ;
+ return false;
}
- ap_info->ap = ap;
+ ap_info->ap = new CWifiAp(ap->Handle());
ap_info->user_data = m;
m->ap_list = eina_list_append(m->ap_list, ap_info);
item = elm_genlist_item_append(m->genlist, m->lock_ic, ap_info, NULL, ELM_GENLIST_ITEM_NONE, sm_CbGenlistItemSelected, m);
if (!item) {
_ERR("genlist append item failed.");
- return ;
+ return false;
}
if (ap_info->state == WIFI_CONNECTION_STATE_CONNECTED) {
m->last_item = item;
if (m->ap) {
- ret = m->pWifiMgr->DestroyAP(m->ap);
- if(ret != true) {
- _ERR("Fail to destroy AP");
- }
+ delete m->ap;
m->ap = NULL;
}
- ret = m->pWifiMgr->CloneAP(&m->ap, ap);
- if(ret != true) {
+ m->ap = new CWifiAp(ap->Handle());
+ if (!m->ap) {
_ERR("Fail to clone AP");
}
m->timer = ecore_timer_add(TIMER_INTERNAL, sm_CbSelectConnected, m);
if (!m->timer) {
_ERR("add timer failed.");
- return ;
+ return false;
}
}
+
+ return false;
}
void CNetworkMainView::sm_CbWifiScanRequest(wifi_error_e err, void *data)
{
- _DBG();
- CNetworkMainView *instance = NULL;
- instance = (CNetworkMainView *) data;
- instance->m_OnWifiScanRequest(err, data);
+ CNetworkMainView *root = (CNetworkMainView*)data;
+ if (root)
+ root->m_OnWifiScanRequest(err);
}
-void CNetworkMainView::m_OnWifiScanRequest(wifi_error_e err, void *data)
+void CNetworkMainView::m_OnWifiScanRequest(wifi_error_e err)
{
_DBG();
bool ret = false;
- ret = m->pWifiMgr->RegisterFoundAPCallback( sm_CbWifiFoundAP, data);
+ ret = m->pWifiMgr->FoundAps(sm_CbWifiFoundAP, this);
if (ret != true) {
_ERR("wifi_mgr_foreach_found_aps() failed.");
}
bool ret;
if (err != WIFI_ERROR_NONE) {
- _ERR("Wi-Fi Activation Failed! error == %s", m->pWifiMgr->GetErrorMsg(err));
+ _ERR("Wi-Fi Activation Failed! error == %s", CWifiMgr::ErrorMsg(err));
return;
}
- ret = m->pWifiMgr->RegisterScanCallback(sm_CbWifiScanRequest, this);
+ ret = m->pWifiMgr->Scan(sm_CbWifiScanRequest, this);
if (ret != true) {
_ERR("wifi_mgr_scan_request() failed.");
m_FillContentPart(m->wireless_discon_ly);
if (activated) {
if (m->ap) {
- ret = m->pWifiMgr->DestroyAP(m->ap);
- if(ret != true) {
- _ERR("Fail to destroy AP");
- }
+ delete m->ap;
m->ap = NULL;
}
- ret = m->pWifiMgr->RegisterScanCallback(sm_CbWifiScanRequest, this);
+ ret = m->pWifiMgr->Scan(sm_CbWifiScanRequest, this);
if (ret != true) {
_ERR("wifi_mgr_scan_request() failed.");
goto _wireless_finish;
void CNetworkMainView::sm_CbWifiConnected(wifi_error_e err, void *data)
{
- _DBG();
- CNetworkMainView *instance;
-
- if (!data) {
- _ERR("Parameter error!");
- return;
- }
-
- instance = (CNetworkMainView *) data;
- instance->m_OnWifiConnected(err);
+ CNetworkMainView *root = (CNetworkMainView*)data;
+ if (root)
+ root->m_OnWifiConnected(err);
}
return true;
}
- ret = m->pWifiMgr->ForgetAP();
+ ret = CWifiAp::ForgetAP();
if (ret != true) {
_ERR("forget last ap failed.");
return false;
}
if (m->ap_pwd) {
- ret = m->pWifiMgr->SetPassPhrase(m->ap, m->ap_pwd);
+ m->ap->SetPassPhrase(m->ap_pwd);
if (ret != true) {
_ERR("wifi_mgr_set_passphrase() failed.");
return false;
}
}
- ret = m->pWifiMgr->Connect(m->ap, sm_CbWifiConnected, this);
+ ret = m->ap->Connect(sm_CbWifiConnected, this);
if (ret != true) {
_ERR("Fail to connection request.");
return false;
}
if (m->timer)
ecore_timer_del(m->timer);
- if (m->ap)
- m->pWifiMgr->DestroyAP(m->ap);
+
+ delete m->ap;
free(m->ap_name);
free(m->ap_pwd);
+#include <stdlib.h>
#include <dbg.h>
#include <wifi.h>
#include "WifiMgr.h"
+#include <AppCommon.h>
+
#define IP_STRING_MAX_SIZE 20
#define MAX_NAME_SIZE 256
#define CONTENT_TXT_SIZE 500
#define ZERO_IP "0.0.0.0"
-CWifiMgr *CWifiMgr::instance = NULL;
-
-struct SWifiMgr {
- wifi_ap_h ap;
-};
-
-bool CWifiMgr::Initialize(void)
+bool CWifiAp::m_CheckErr(const char *func, int ret)
{
- ASSERT(!instance);
-
- instance = new CWifiMgr;
- if(!instance)
- return false;
-
- int ret;
-
- instance->m = new SWifiMgr;
- if(instance->m == NULL) return false;
-
- ret = wifi_initialize();
if (ret != WIFI_ERROR_NONE) {
- _ERR("Fail to wifi_initialize. error : %s", instance->GetErrorMsg((wifi_error_e) ret));
- return false;
+ _ERR("Fail to wifi_get_connected_ap %s", CWifiMgr::ErrorMsg((wifi_error_e)ret));
}
- instance->m->ap = NULL;
-
- return true;
+ return ret == WIFI_ERROR_NONE ? true : false;
}
-void CWifiMgr::Finalize(void)
+void CWifiAp::t_SetHandle(wifi_ap_h handle)
{
- if(!instance)
- return;
- ASSERT(instance->m);
+ m_handle = handle;
+}
- if (wifi_deinitialize() != WIFI_ERROR_NONE) {
- _ERR("Fail to wifi_deinitialize.");
- }
- delete instance->m;
- delete instance;
- instance = NULL;
+CWifiAp::CWifiAp(wifi_ap_h handle)
+{
+ m_handle = handle;
+
+ int ret = wifi_ap_clone(&m_handle, handle);
+ m_CheckErr(__FUNCTION__, ret);
}
-CWifiMgr *CWifiMgr::GetInstance(void)
+CWifiAp::~CWifiAp()
{
- return instance;
+ wifi_ap_destroy(m_handle);
+ m_handle = NULL;
}
-bool CWifiMgr::Activate(void(*ActivatedCb)(wifi_error_e err, void *data), void *data)
+#define WIFI_CHECK_RET(EXP) return m_CheckErr(__FUNCTION__, EXP);
+#define WIFI_CHECK(EXP) m_CheckErr(__FUNCTION__, EXP);
+
+
+wifi_ap_h CWifiAp::Handle(void)
{
- int ret;
+ return m_handle;
+}
- if (!ActivatedCb) {
- _ERR("Parameter is invalid");
- return false;
- }
- ret = wifi_activate(ActivatedCb, data);
- if (ret != WIFI_ERROR_NONE) {
- _ERR("Fail to wifi_activate %s", GetErrorMsg((wifi_error_e) ret));
- return false;
- }
+bool CWifiAp::AllocConnectedAp(void)
+{
+ ASSERT(m_handle == NULL);
- return true;
+ WIFI_CHECK_RET(wifi_get_connected_ap(&m_handle));
}
-bool CWifiMgr::IsActivated(bool *activated)
+void CWifiAp::Destroy(void)
{
- int ret;
-
- ret = wifi_is_activated(activated);
- if (ret != WIFI_ERROR_NONE) {
- _ERR("Fail to wifi_is_activated %s",GetErrorMsg((wifi_error_e) ret));
- return false;
- }
+ if (m_handle == NULL)
+ return;
- return true;
+ WIFI_CHECK(wifi_ap_destroy(m_handle));
+ m_handle = NULL;
}
-bool CWifiMgr::GetConnectedAP(wifi_ap_h *ap)
+bool CWifiAp::GetEssid(char *essid, int size)
{
- int ret;
+ ASSERT(m_handle);
- if (!ap) {
- _ERR("the param is invalid.");
- return false;
+ char *str = NULL;
+ int ret = wifi_ap_get_essid(m_handle, &str);
+ if (ret == WIFI_ERROR_NONE) {
+ strncpy(essid, str, size);
+ _DBG("str : %s , ESSID : %s", str, essid);
+ free(str);
}
-
- ret = wifi_get_connected_ap(ap);
- if (ret != WIFI_ERROR_NONE) {
- _ERR("Fail to wifi_get_connected_ap %s",GetErrorMsg((wifi_error_e) ret));
- return false;
+ else {
+ _ERR("Fail to get ESSID");
}
- return true;
+ return ret == WIFI_ERROR_NONE ? true : false;
}
-bool CWifiMgr::DestroyAP(wifi_ap_h ap)
-{
- int ret;
- if (!ap) {
- _ERR("the ap is already NULL.");
- return true;
- }
-
- ret = wifi_ap_destroy(ap);
- if (ret != WIFI_ERROR_NONE) {
- _ERR("Fail to wifi_ap_destroy %s",GetErrorMsg((wifi_error_e) ret));
- return false;
- }
+bool CWifiAp::GetConnectionState(wifi_connection_state_e *state)
+{
+ ASSERT(m_handle);
- return true;
+ WIFI_CHECK_RET(wifi_ap_get_connection_state(m_handle, state));
}
-bool CWifiMgr::CloneAP(wifi_ap_h *cloned_ap, wifi_ap_h origin)
+bool CWifiAp::GetSecurityType(wifi_security_type_e *type)
{
- int ret;
+ ASSERT(m_handle);
- if (!cloned_ap || !origin) {
- _ERR("the param is invalid.");
- return false;
- }
+ WIFI_CHECK_RET(wifi_ap_get_security_type(m_handle, type));
+}
- ret = wifi_ap_clone(cloned_ap, origin);
- if (ret != WIFI_ERROR_NONE) {
- _ERR("Fail to wifi_ap_clone %s",GetErrorMsg((wifi_error_e) ret));
- return false;
- }
- return true;
+bool CWifiAp::SetPassPhrase(const char *passcode)
+{
+ ASSERT(m_handle);
+ ASSERT(passcode);
+
+ WIFI_CHECK_RET(wifi_ap_set_passphrase(m_handle, passcode));
}
-bool CWifiMgr::RegisterScanCallback(void(*ScanFinishedCb)(wifi_error_e err, void* data), void *data)
+bool CWifiAp::Connect(void(*wifi_connected_cb)(wifi_error_e err, void *data), void *data)
{
- int ret;
+ ASSERT(m_handle);
+ ASSERT(wifi_connected_cb);
- if (!ScanFinishedCb) {
- _ERR("Parameter is invalid");
- return false;
- }
+ WIFI_CHECK_RET(wifi_connect(m_handle, wifi_connected_cb, data));
+}
- ret = wifi_scan(ScanFinishedCb, data);
- if (ret != WIFI_ERROR_NONE) {
- _ERR("Scan request failed [%s]", GetErrorMsg((wifi_error_e) ret));
- return false;
- }
- return true;
+bool CWifiAp::SetIpType(wifi_ip_config_type_e type)
+{
+ ASSERT(m_handle);
+
+ WIFI_CHECK_RET(wifi_ap_set_ip_config_type(m_handle, WIFI_ADDRESS_FAMILY_IPV4, type));
}
-bool CWifiMgr::RegisterFoundAPCallback(bool(*FoundCb)(wifi_ap_h ap, void *data), void *data)
+bool CWifiAp::GetIp(char *ip, int size)
{
- int ret;
+ ASSERT(m_handle);
- if (!FoundCb) {
- _ERR("Parameter is invalid");
- return false;
+ char *str_value = NULL;
+ int ret = wifi_ap_get_ip_address(m_handle, WIFI_ADDRESS_FAMILY_IPV4, &str_value);
+ if (ret == WIFI_ERROR_NONE) {
+ strncpy(ip, str_value, IP_STRING_MAX_SIZE < size);
+ free(str_value);
}
-
- ret = wifi_foreach_found_aps(FoundCb, data);
- if (ret != WIFI_ERROR_NONE) {
- _ERR("Fail to get AP list %s.", GetErrorMsg((wifi_error_e) ret));
- return false;
+ else {
+ strncpy(ip, ZERO_IP, IP_STRING_MAX_SIZE);
+ _ERR("Fail to get Gateway");
}
-
- return true;
+ return ret == WIFI_ERROR_NONE ? true : false;
}
-bool CWifiMgr::SetProxyType(EProxyMethod pm)
+bool CWifiAp::GetSubnetMask(char *submask)
{
- ASSERT(m);
-
- wifi_proxy_type_e type;
- wifi_ap_h ap;
-
- if (wifi_get_connected_ap(&ap) != WIFI_ERROR_NONE) {
- _ERR("wifi_get_connected_ap() failed.");
- return false;
- }
+ ASSERT(m_handle);
- switch (pm) {
- case PROXY_METHOD_NONE:
- type = WIFI_PROXY_TYPE_DIRECT;
- break;
- case PROXY_METHOD_MANUAL:
- type = WIFI_PROXY_TYPE_MANUAL;
- break;
- case PROXY_METHOD_AUTO:
- type = WIFI_PROXY_TYPE_AUTO;
- break;
- default:
- return false;
+ char *str_value = NULL;
+ int ret = wifi_ap_get_subnet_mask(m_handle, WIFI_ADDRESS_FAMILY_IPV4, &str_value);
+ if (ret == WIFI_ERROR_NONE) {
+ strncpy(submask, str_value, IP_STRING_MAX_SIZE);
+ free(str_value);
}
-
- if (wifi_ap_set_proxy_type(ap, type) != WIFI_ERROR_NONE) {
- _ERR("wifi_ap_set_proxy_type() failed.");
- return false;
+ else {
+ strncpy(submask, ZERO_IP, IP_STRING_MAX_SIZE);
+ _ERR("Fail to get Gateway");
}
-
- return true;
+ return ret == WIFI_ERROR_NONE ? true : false;
}
-bool CWifiMgr::GetProxyType(EProxyMethod *pm)
+bool CWifiAp::GetGateway(char *gateway)
{
- ASSERT(m);
-
- wifi_proxy_type_e type;
- wifi_ap_h ap;
-
- if (!pm) {
- _ERR("parameter is invalid.");
- return false;
- }
+ ASSERT(m_handle);
- if (wifi_get_connected_ap(&ap) != WIFI_ERROR_NONE) {
- _ERR("wifi_get_connected_ap() failed.");
- return false;
- }
+ char *str_value;
- if (wifi_ap_get_proxy_type(ap, &type) != WIFI_ERROR_NONE) {
- _ERR("wifi_ap_get_proxy_type() failed.");
- return false;
+ str_value = NULL;
+ if (wifi_ap_get_gateway_address(m_handle, WIFI_ADDRESS_FAMILY_IPV4, &str_value) == WIFI_ERROR_NONE) {
+ strncpy(gateway, str_value, IP_STRING_MAX_SIZE);
+ free(str_value);
+ return true;
}
-
- switch (type) {
- case WIFI_PROXY_TYPE_DIRECT:
- *pm = PROXY_METHOD_NONE;
- break;
- case WIFI_PROXY_TYPE_MANUAL:
- *pm = PROXY_METHOD_MANUAL;
- break;
- case WIFI_PROXY_TYPE_AUTO:
- *pm = PROXY_METHOD_AUTO;
- break;
- default:
+ else {
+ strncpy(gateway, ZERO_IP, IP_STRING_MAX_SIZE);
+ _ERR("Fail to get Gateway");
return false;
}
-
- return true;
}
-bool CWifiMgr::SetProxyAddr(const char *ip)
+bool CWifiAp::GetDNS(char *dns)
{
- ASSERT(m);
+ ASSERT(m_handle);
- wifi_ap_h ap;
+ char *str_value;
- if (wifi_get_connected_ap(&ap) != WIFI_ERROR_NONE) {
- _ERR("wifi_get_connected_ap() failed.");
- return false;
+ str_value = NULL;
+ if (wifi_ap_get_dns_address(m_handle, 1, WIFI_ADDRESS_FAMILY_IPV4, &str_value) == WIFI_ERROR_NONE) {
+ strncpy(dns, str_value, IP_STRING_MAX_SIZE);
+ free(str_value);
+ return true;
}
-
- if (wifi_ap_set_proxy_address(ap, WIFI_ADDRESS_FAMILY_IPV4, ip) != WIFI_ERROR_NONE) {
- _ERR("wifi_ap_set_proxy_address() failed.");
+ else {
+ strncpy(dns, ZERO_IP, IP_STRING_MAX_SIZE);
+ _ERR("Fail to get DNS1");
return false;
}
-
- return true;
}
-bool CWifiMgr::GetProxyAddr(char **ip)
+bool CWifiAp::SetIp(char *ip)
{
- ASSERT(m);
- wifi_ap_h ap;
+ ASSERT(m_handle);
- if (!ip || !*ip) {
- _ERR("parameter is invalid.");
- return false;
- }
+ WIFI_CHECK_RET(wifi_ap_set_ip_address(m_handle, WIFI_ADDRESS_FAMILY_IPV4, ip));
+}
- if (wifi_get_connected_ap(&ap) != WIFI_ERROR_NONE) {
- _ERR("wifi_get_connected_ap() failed.");
- return false;
- }
- if (wifi_ap_get_proxy_address(ap, WIFI_ADDRESS_FAMILY_IPV4, ip) != WIFI_ERROR_NONE) {
- _ERR("wifi_ap_get_proxy_address() failed.");
- return false;
- }
+bool CWifiAp::SetSubnetMask(char *submask)
+{
+ ASSERT(m_handle);
- return true;
+ WIFI_CHECK_RET(wifi_ap_set_subnet_mask(m_handle, WIFI_ADDRESS_FAMILY_IPV4, submask));
}
-bool CWifiMgr::GetESSID(wifi_ap_h ap, char *essid)
+bool CWifiAp::SetGateway(char *gateway)
{
- ASSERT(m);
- ASSERT(ap);
-
- char *str;
- str = NULL;
- if (wifi_ap_get_essid(ap, &str) == WIFI_ERROR_NONE) {
- strncpy(essid, str, 255);
- _DBG("str : %s , ESSID : %s", str, essid);
- delete (str);
- str = NULL;
- } else {
- _ERR("Fail to get ESSID");
- return false;
- }
+ ASSERT(m_handle);
- return true;
+ WIFI_CHECK_RET(wifi_ap_set_gateway_address(m_handle, WIFI_ADDRESS_FAMILY_IPV4, gateway));
}
-bool CWifiMgr::GetConnectionState(wifi_ap_h ap, wifi_connection_state_e *state)
+bool CWifiAp::SetDNS(char *dns)
{
- ASSERT(m);
- ASSERT(ap);
+ ASSERT(m_handle);
- if (wifi_ap_get_connection_state(ap, state) != WIFI_ERROR_NONE) {
- _ERR("Fail to get Connection State");
- return false;
- }
-
- return true;
+ WIFI_CHECK_RET(wifi_ap_set_dns_address(m_handle, 1, WIFI_ADDRESS_FAMILY_IPV4, dns));
}
-bool CWifiMgr::GetSecurityType(wifi_ap_h ap, wifi_security_type_e *type)
+bool CWifiAp::CloneAP(wifi_ap_h *cloned_ap, wifi_ap_h origin)
{
- ASSERT(m);
- ASSERT(ap);
+ int ret;
- if (wifi_ap_get_security_type(ap, type) != WIFI_ERROR_NONE) {
- _ERR("Fail to get Security type");
+ if (!cloned_ap || !origin) {
+ _ERR("the param is invalid.");
+ return false;
+ }
+
+ ret = wifi_ap_clone(cloned_ap, origin);
+ if (ret != WIFI_ERROR_NONE) {
+ _ERR("Fail to wifi_ap_clone %s", CWifiMgr::ErrorMsg((wifi_error_e)ret));
return false;
}
}
-bool CWifiMgr::ForgetAP(void)
+bool CWifiAp::ForgetAP(void)
{
int ret;
- wifi_ap_h ap;
+ wifi_ap_h handle;
char *name;
- ret = wifi_get_connected_ap(&ap);
+ ret = wifi_get_connected_ap(&handle);
if (ret == WIFI_ERROR_NO_CONNECTION) {
return true;
- } else if (ret != WIFI_ERROR_NONE) {
- _ERR("Fail to get connected AP [%s]", GetErrorMsg((wifi_error_e) ret));
+ }
+ else if (ret != WIFI_ERROR_NONE) {
+ _ERR("Fail to get connected AP [%s]", CWifiMgr::ErrorMsg((wifi_error_e)ret));
return false;
}
- ret = wifi_ap_get_essid(ap, &name);
+ ret = wifi_ap_get_essid(handle, &name);
if (ret != WIFI_ERROR_NONE) {
- _ERR("Fail to wifi_ap_get_essid AP [%s]", GetErrorMsg((wifi_error_e) ret));
- wifi_ap_destroy(ap);
+ _ERR("Fail to wifi_ap_get_essid AP [%s]", CWifiMgr::ErrorMsg((wifi_error_e)ret));
+ wifi_ap_destroy(handle);
return false;
}
- ret = wifi_forget_ap(ap);
+ ret = wifi_forget_ap(handle);
if (ret != WIFI_ERROR_NONE) {
- _ERR("Fail to forget [%s],[%s].", name, GetErrorMsg((wifi_error_e) ret));
- wifi_ap_destroy(ap);
- delete (name);
- return false;
+ _ERR("Fail to forget [%s],[%s].", name, CWifiMgr::ErrorMsg((wifi_error_e)ret));
}
- delete (name);
+ wifi_ap_destroy(handle);
+ free(name);
- return true;
+ return ret == WIFI_ERROR_NONE ? true : false;
}
-bool CWifiMgr::SetPassPhrase(wifi_ap_h ap, const char *passcode)
+bool CWifiAp::SetProxyType(EProxyMethod pm)
{
- int ret;
+ ASSERT(m_handle);
- if (!ap || !passcode) {
- _ERR("the param is invalid.");
- return false;
- }
+ wifi_proxy_type_e type;
- ret = wifi_ap_set_passphrase(ap, passcode);
- if (ret != WIFI_ERROR_NONE) {
- _ERR("failed to set passcode. ret: %s.", GetErrorMsg((wifi_error_e) ret));
+ switch (pm) {
+ case PROXY_METHOD_NONE:
+ type = WIFI_PROXY_TYPE_DIRECT;
+ break;
+
+ case PROXY_METHOD_MANUAL:
+ type = WIFI_PROXY_TYPE_MANUAL;
+ break;
+
+ case PROXY_METHOD_AUTO:
+ type = WIFI_PROXY_TYPE_AUTO;
+ break;
+
+ default:
return false;
}
- return true;
+ int ret = wifi_ap_set_proxy_type(m_handle, type);
+ return ret = WIFI_ERROR_NONE ? true : false;
}
-bool CWifiMgr::Connect(wifi_ap_h ap, void(*wifi_connected_cb)(wifi_error_e err, void *data), void *data)
+bool CWifiAp::GetProxyType(EProxyMethod *pm)
{
- int ret;
+ ASSERT(m_handle);
- if (!wifi_connected_cb || !ap) {
- _ERR("the param is invalid.");
- return false;
- }
-
- ret = wifi_connect(ap, wifi_connected_cb, data);
+ wifi_proxy_type_e type;
+
+ int ret = wifi_ap_get_proxy_type(m_handle, &type);
if (ret != WIFI_ERROR_NONE) {
- _ERR("failed to connect ap. ret: %s.", GetErrorMsg((wifi_error_e) ret));
+ _ERR("wifi_ap_get_proxy_type() failed.");
return false;
}
- return true;
-}
-
+ switch (type) {
+ case WIFI_PROXY_TYPE_DIRECT:
+ *pm = PROXY_METHOD_NONE;
+ break;
-bool CWifiMgr::SetIpType(wifi_ap_h ap, wifi_ip_config_type_e type)
-{
- int ret;
+ case WIFI_PROXY_TYPE_MANUAL:
+ *pm = PROXY_METHOD_MANUAL;
+ break;
- if (!ap) {
- _ERR("the param is invalid.");
- return false;
- }
+ case WIFI_PROXY_TYPE_AUTO:
+ *pm = PROXY_METHOD_AUTO;
+ break;
- ret = wifi_ap_set_ip_config_type(ap, WIFI_ADDRESS_FAMILY_IPV4, type);
- if (ret != WIFI_ERROR_NONE) {
- _ERR("failed to connect ap. ret: %s.", GetErrorMsg((wifi_error_e) ret));
+ default:
return false;
}
- return true;
+ return ret;
}
-bool CWifiMgr::GetIp(wifi_ap_h ap, char *ip)
+bool CWifiAp::SetProxyAddr(const char *addr)
{
- ASSERT(ap);
+ ASSERT(m_handle);
- char *str_value;
-
- str_value = NULL;
- if (wifi_ap_get_ip_address(ap, WIFI_ADDRESS_FAMILY_IPV4, &str_value) == WIFI_ERROR_NONE) {
- strncpy(ip, str_value, IP_STRING_MAX_SIZE);
- delete (str_value);
- return true;
- } else {
- strncpy(ip, ZERO_IP, IP_STRING_MAX_SIZE);
- _ERR("Fail to get Gateway");
- return false;
- }
+ WIFI_CHECK_RET(wifi_ap_set_proxy_address(m_handle, WIFI_ADDRESS_FAMILY_IPV4, addr));
}
-bool CWifiMgr::GetSubnetMask(wifi_ap_h ap, char *submask)
+bool CWifiAp::GetProxyAddr(char **addr)
{
- ASSERT(ap);
+ ASSERT(m_handle);
+ ASSERT(addr);
- char *str_value;
-
- str_value = NULL;
- if (wifi_ap_get_subnet_mask(ap, WIFI_ADDRESS_FAMILY_IPV4, &str_value) == WIFI_ERROR_NONE) {
- strncpy(submask, str_value, IP_STRING_MAX_SIZE);
- delete (str_value);
- return true;
- } else {
- strncpy(submask, ZERO_IP, IP_STRING_MAX_SIZE);
- _ERR("Fail to get Gateway");
- return false;
- }
+ WIFI_CHECK_RET(wifi_ap_get_proxy_address(m_handle, WIFI_ADDRESS_FAMILY_IPV4, addr));
}
-bool CWifiMgr::GetGateway(wifi_ap_h ap, char *gateway)
+CWifiMgr *CWifiMgr::instance = NULL;
+
+
+struct SWifiMgr {
+ int a;
+};
+
+
+bool CWifiMgr::Initialize(void)
{
- ASSERT(ap);
+ ASSERT(!instance);
- char *str_value;
+ _CREATE_BEGIN{
+ _CHECK(instance = new CWifiMgr);
+ _CHECK(instance->m = new SWifiMgr);
+ _CHECK(wifi_initialize() == WIFI_ERROR_NONE);
- str_value = NULL;
- if (wifi_ap_get_gateway_address(ap, WIFI_ADDRESS_FAMILY_IPV4, &str_value) == WIFI_ERROR_NONE) {
- strncpy(gateway, str_value, IP_STRING_MAX_SIZE);
- delete (str_value);
- return true;
- } else {
- strncpy(gateway, ZERO_IP, IP_STRING_MAX_SIZE);
- _ERR("Fail to get Gateway");
- return false;
- }
+ _CHECK_FAIL{ wifi_deinitialize(); }
+ _CHECK_FAIL{ delete instance->m; }
+ _CHECK_FAIL{ delete instance; instance = NULL; }
+ } _CREATE_END_AND_CATCH { return false; }
+
+ return true;
}
-bool CWifiMgr::GetDNS(wifi_ap_h ap, char *dns)
+void CWifiMgr::Finalize(void)
{
- ASSERT(ap);
+ ASSERT(instance);
+ ASSERT(instance->m);
- char *str_value;
+ wifi_deinitialize();
- str_value = NULL;
- if (wifi_ap_get_dns_address(ap, 1, WIFI_ADDRESS_FAMILY_IPV4, &str_value) == WIFI_ERROR_NONE) {
- strncpy(dns, str_value, IP_STRING_MAX_SIZE);
- delete (str_value);
- return true;
- } else {
- strncpy(dns, ZERO_IP, IP_STRING_MAX_SIZE);
- _ERR("Fail to get DNS1");
- return false;
- }
+ delete instance->m;
+ delete instance;
+ instance = NULL;
}
-bool CWifiMgr::SetIp(wifi_ap_h ap, char *ip)
+
+CWifiMgr *CWifiMgr::GetInstance(void)
{
- ASSERT(ap);
+ return instance;
+}
- int ret;
- ret = wifi_ap_set_ip_address(ap, WIFI_ADDRESS_FAMILY_IPV4, ip);
+bool CWifiMgr::Activate(void (*cbActivated)(wifi_error_e err, void *data), void *data)
+{
+ ASSERT(cbActivated);
+
+ int ret = wifi_activate(cbActivated, data);
if (ret != WIFI_ERROR_NONE) {
- _ERR("Fail to set ip address[%s]", GetErrorMsg((wifi_error_e) ret));
+ _ERR("Fail to wifi_activate %s", CWifiMgr::ErrorMsg((wifi_error_e) ret));
return false;
}
}
-bool CWifiMgr::SetSubnetMask(wifi_ap_h ap, char *submask)
+bool CWifiMgr::IsActivated(bool *activated)
{
- ASSERT(ap);
-
int ret;
- ret = wifi_ap_set_subnet_mask(ap, WIFI_ADDRESS_FAMILY_IPV4, submask);
+ ret = wifi_is_activated(activated);
if (ret != WIFI_ERROR_NONE) {
- _ERR("Fail to set subnet mask[%s]", GetErrorMsg((wifi_error_e) ret));
+ _ERR("Fail to wifi_is_activated %s",CWifiMgr::ErrorMsg((wifi_error_e) ret));
return false;
}
}
-bool CWifiMgr::SetGateway(wifi_ap_h ap, char *gateway)
+bool CWifiMgr::Scan(void(*cbFinish)(wifi_error_e err, void* data), void *data)
{
- ASSERT(ap);
+ ASSERT(cbFinish);
- int ret;
-
- ret = wifi_ap_set_gateway_address(ap, WIFI_ADDRESS_FAMILY_IPV4, gateway);
+ int ret = wifi_scan(cbFinish, data);
if (ret != WIFI_ERROR_NONE) {
- _ERR("Fail to set gateway address[%s]", GetErrorMsg((wifi_error_e) ret));
+ _ERR("Scan request failed [%s]", CWifiMgr::ErrorMsg((wifi_error_e) ret));
return false;
}
}
-bool CWifiMgr::SetDNS(wifi_ap_h ap, char *dns)
+struct SUserData
{
- ASSERT(ap);
+ bool(*cb)(CWifiAp *ap, void *data);
+ void *data;
+ SUserData(bool(*c)(CWifiAp *ap, void *data), void *d) {
+ cb = c;
+ data = data;
+ }
+};
- int ret;
- ret = wifi_ap_set_dns_address(ap, 1, WIFI_ADDRESS_FAMILY_IPV4, dns);
+static bool g_CbFound(wifi_ap_h ap, void *data)
+{
+ SUserData *ud = (SUserData*)data;
+ CWifiAp ins(ap);
+ ud->cb(&ins, ud->data);
+ delete ud;
+
+ return false;
+}
+
+
+bool CWifiMgr::FoundAps(bool(*cbFound)(CWifiAp *ap, void *data), void *data)
+{
+ ASSERT(cbFound);
+
+ SUserData *ud = new SUserData(cbFound, data);
+ int ret = wifi_foreach_found_aps(g_CbFound, ud);
if (ret != WIFI_ERROR_NONE) {
- _ERR("Fail to set dns address[%s]", GetErrorMsg((wifi_error_e) ret));
+ _ERR("Fail to get AP list %s.", CWifiMgr::ErrorMsg((wifi_error_e) ret));
return false;
}
}
-const char * CWifiMgr::GetErrorMsg(wifi_error_e err_type)
+const char * CWifiMgr::ErrorMsg(wifi_error_e err_type)
{
switch (err_type) {
case WIFI_ERROR_NONE: