Get WiFi activation status

This short function will do all that is needed to check if WiFi service is activated. 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

// function returns 0 on success, -1 on error. 
// is_activated is set to true when the WiFi is turned on, false otherwise.

int check_wifi_status(bool *is_activated)
{
    int error = -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 activated!");
                *is_activated = true;
                error = 0; //success, WiFi status: activated
            }
            else
            {
                LOGI("WIFI not activated!");
                *is_activated = false;
                error = 0; //success, WiFi status: not activated
            }
        }
        else
        {
            LOGE("Could not check WiFi status!");
            error = -1; //failure
        }
        if (wifi_deinitialize() != WIFI_ERROR_NONE)
        {
            LOGE("WiFi deinitialization failed!");
            error = -1; //failure
        }
    }
    else
    {
        LOGE("WiFi initialization error!");
        error = -1; //failure
    }
    return error;
}

Responses

0 Replies