Activate WiFi
This set of functions will do anything that should be done to activate WiFi service. PRIVILEGES NEEDED: http://tizen.org/privilege/network.get http://tizen.org/privilege/network.set
// PRIVILEGES needed to be set in tizen-manifest.xml:
// http://tizen.org/privilege/network.get
// http://tizen.org/privilege/network.set
#include <wifi.h>
#include <dlog.h> // for logging purposes
//callback to be called when WiFi is activated
void on_wifi_activated(wifi_error_e result, void *user_data)
{
if (result == WIFI_ERROR_NONE)
{
LOGI("WiFi activation request successfully finished!");
bool wifi_activated = false;
if (wifi_is_activated(&wifi_activated) == WIFI_ERROR_NONE)
{
if (wifi_activated)
{
LOGI("status: activated!");
}
else
{
LOGE("Error! WiFi not activated!");
}
}
else
{
LOGE("Error! Could not check WiFi status!");
}
}
else
{
LOGE("Error! WiFi activation failed!");
}
}
// This simple function activates WiFi.
// It returns:
// -1 on failure,
// 0 when the WiFi activation request was successful (in that case callback will be executed),
// and 1 when WiFi has been already activated.
int activate_wifi()
{
int result = -1;
if (wifi_initialize() == WIFI_ERROR_NONE)
{
bool wifi_activated = false;
if (wifi_is_activated(&wifi_activated) == WIFI_ERROR_NONE)
{
if (wifi_activated)
{
LOGI("WIFI already activated!");
// As WiFi is already activated,
// you shouldn't call wifi_activate(), because it will return error.
// So you shouldn't also wait for callback.
// You can call the callback function manually here:
// on_wifi_activated(WIFI_ERROR_NONE, NULL);
// or check the function result and act accordingly outside of this function.
result = 1;
}
else
{
LOGI("WIFI not activated!");
if (wifi_activate(on_wifi_activated, NULL)== WIFI_ERROR_NONE)
{
LOGI("WIFI activation requested! Please wait for callback");
result = 0;
}
else
{
LOGE("Failed to request WiFi activation!");
result = -1;
}
}
}
else
{
LOGE("Could not check WiFi status!");
result = -1;
}
}
else
{
LOGE("WiFi initialization error!");
result = -1;
}
return result;
}
// This should be called when the activation callback is executed
// and you don't need WiFi services anymore (e.g. on app shutdown).
void deinitialize()
{
if (wifi_deinitialize() == WIFI_ERROR_NONE)
{
LOGE("WiFi deinitialized!");
}
}