Scan for WiFi access points
This set of functions will give you anything you need to scan for available WiFi access points. PRIVILEGE NEEDED: http://tizen.org/privilege/network.get
// PRIVILEGE needed to be set in tizen-manifest.xml:
// http://tizen.org/privilege/network.get
#include <wifi.h>
#include <dlog.h> // for logging purposes
//Callback performed on each access point found. It prints an access point ID.
bool access_point_callback(wifi_ap_h access_point, void *user_data)
{
char* ap_id = NULL;
if(wifi_ap_get_essid(access_point, &ap_id) == WIFI_ERROR_NONE)
{
LOGI("Access point ID: %s", ap_id);
}
else
{
LOGE("Error when getting access point ID!");
return false;
}
return true;
}
//Callback called when access point scan is finished.
void scan_finished_callback(wifi_error_e result, void *user_data)
{
if (result == WIFI_ERROR_NONE)
{
LOGI("WiFi access point scan finished!");
if(wifi_foreach_found_aps(access_point_callback, NULL) == WIFI_ERROR_NONE)
{
LOGI("Listing access points successful!");
}
else
{
LOGE("Error when listing access points!");
}
}
else
{
LOGE("Error when scanning for WiFi access points!");
}
}
// This simple function deactivates WiFi.
// It returns false on failure, true on success
bool scan_for_wifi_APs()
{
bool result = false;
if (wifi_initialize() == WIFI_ERROR_NONE)
{
bool wifi_activated = false;
if (wifi_is_activated(&wifi_activated) == WIFI_ERROR_NONE)
{
if (!wifi_activated)
{
LOGE("WIFI is not activated! Please activate WiFi first");
result = false;
}
else
{
LOGI("WIFI is activated!");
if(wifi_scan(scan_finished_callback, NULL) == WIFI_ERROR_NONE)
{
LOGI("WiFi AP scan started!");
result = true;
}
else
{
LOGE("Could not start scanning!");
result = false;
}
}
}
else
{
LOGE("Could not check WiFi status!");
result = false;
}
}
else
{
LOGE("WiFi initialization error!");
result = false;
}
return result;
}
// This should be called when you don't need WiFi services anymore (e.g. on app shutdown).
void deinitialize()
{
if (wifi_deinitialize() == WIFI_ERROR_NONE)
{
LOGI("WiFi deinitialized!");
}
}