From: sung.goo.kim Date: Thu, 26 May 2016 02:02:06 +0000 (+0900) Subject: Add a test program for checking wifi state X-Git-Tag: submit/tizen/20160603.003854~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=582ffb8b0dfde73dccffcadd255144fa42e39dba;p=platform%2Fcore%2Fiot%2Fiotcon.git Add a test program for checking wifi state Change-Id: Ieb37453ccb412c803929aa6dca804b95b3418477 --- diff --git a/packaging/iotcon.spec b/packaging/iotcon.spec index e270f45..ece8b21 100644 --- a/packaging/iotcon.spec +++ b/packaging/iotcon.spec @@ -18,6 +18,7 @@ BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(capi-base-common) BuildRequires: pkgconfig(capi-system-info) BuildRequires: pkgconfig(capi-system-system-settings) +BuildRequires: pkgconfig(capi-network-wifi) BuildRequires: pkgconfig(iotivity) BuildRequires: pkgconfig(uuid) BuildRequires: pkgconfig(cynara-client) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3b52635..9b3e65d 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -19,7 +19,10 @@ SET(IOTCON_TEST_ENCAP_SERVER "iotcon-test-encap-server") SET(IOTCON_TEST_ENCAP_CLIENT_SRCS "iotcon-test-encap-client.c") SET(IOTCON_TEST_ENCAP_SERVER_SRCS "iotcon-test-encap-server.c") -pkg_check_modules(test_pkgs REQUIRED dlog glib-2.0) +SET(IOTCON_TEST_WIFI "iotcon-test-wifi") +SET(IOTCON_TEST_WIFI_SRCS "iotcon-test-wifi.c") + +pkg_check_modules(test_pkgs REQUIRED dlog glib-2.0 capi-network-wifi) INCLUDE_DIRECTORIES(${test_pkgs_INCLUDE_DIRS}) LINK_DIRECTORIES(${test_pkgs_LIBRARY_DIRS}) @@ -51,3 +54,6 @@ ADD_EXECUTABLE(${IOTCON_TEST_ENCAP_SERVER} ${IOTCON_TEST_ENCAP_SERVER_SRCS}) TARGET_LINK_LIBRARIES(${IOTCON_TEST_ENCAP_SERVER} ${test_pkgs_LIBRARIES} ${CLIENT}) INSTALL(TARGETS ${IOTCON_TEST_ENCAP_SERVER} DESTINATION ${BIN_INSTALL_DIR}) +ADD_EXECUTABLE(${IOTCON_TEST_WIFI} ${IOTCON_TEST_WIFI_SRCS}) +TARGET_LINK_LIBRARIES(${IOTCON_TEST_WIFI} ${test_pkgs_LIBRARIES} ${CLIENT}) +INSTALL(TARGETS ${IOTCON_TEST_WIFI} DESTINATION ${BIN_INSTALL_DIR}) diff --git a/test/iotcon-test-wifi.c b/test/iotcon-test-wifi.c new file mode 100644 index 0000000..5020e9c --- /dev/null +++ b/test/iotcon-test-wifi.c @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include +#include + +#include "test.h" + +static void _check_wifi_state() +{ + int ret; + wifi_ap_h ap; + wifi_connection_state_e connection_state; + bool activated; + char *essid; + + ret = wifi_initialize(); + if (WIFI_ERROR_NONE != ret) { + ERR("wifi_initialize() Fail(%d)", ret); + printf("wifi_initialize() Fail(%d)\n", ret); + return; + } + + ret = wifi_is_activated(&activated); + if (WIFI_ERROR_NONE != ret) { + ERR("wifi_is_activated() Fail(%d)", ret); + printf("wifi_is_activated() Fail(%d)\n", ret); + wifi_deinitialize(); + return; + } else if (false == activated) { + ERR("wifi is not activated"); + printf("wifi is not activate\n"); + wifi_deinitialize(); + return; + } + + ret = wifi_get_connection_state(&connection_state); + if (WIFI_ERROR_NONE != ret) { + ERR("wifi_get_connection_state() Fail(%d)", ret); + printf("wifi_get_connection_state() Fail(%d)\n", ret); + wifi_deinitialize(); + return; + } + + switch (connection_state) { + case WIFI_CONNECTION_STATE_CONNECTED: + INFO("WIFI_CONNECTION_STATE_CONNECTED"); + printf("WIFI_CONNECTION_STATE_CONNECTED\n"); + ret = wifi_get_connected_ap(&ap); + if (WIFI_ERROR_NONE != ret) { + ERR("wifi_get_connected_ap() Fail(%d)", ret); + printf("wifi_get_connected_ap() Fail(%d)\n", ret); + break; + } + ret = wifi_ap_get_essid(ap, &essid); + if (WIFI_ERROR_NONE != ret) { + ERR("wifi_ap_get_essid() Fail(%d)", ret); + printf("wifi_ap_get_essid() Fail(%d)\n", ret); + wifi_ap_destroy(ap); + break; + } + INFO("ssid: %s", essid); + printf("ssid: %s\n", essid); + free(essid); + wifi_ap_destroy(ap); + break; + case WIFI_CONNECTION_STATE_FAILURE: + ERR("WIFI_CONNECTION_STATE_FAILURE"); + printf("WIFI_CONNECTION_STATE_FAILURE\n"); + break; + case WIFI_CONNECTION_STATE_DISCONNECTED: + ERR("WIFI_CONNECTION_STATE_DISCONNECTED"); + printf("WIFI_CONNECTION_STATE_DISCONNECTED\n"); + break; + case WIFI_CONNECTION_STATE_ASSOCIATION: + ERR("WIFI_CONNECTION_STATE_ASSOCIATION"); + printf("WIFI_CONNECTION_STATE_ASSOCIATION\n"); + break; + case WIFI_CONNECTION_STATE_CONFIGURATION: + ERR("WIFI_CONNECTION_STATE_CONFIGURATION"); + printf("WIFI_CONNECTION_STATE_CONFIGURATION\n"); + break; + default: + ERR("Invalid connection state(%d)", connection_state); + printf("Invalid connection state(%d)", connection_state); + } + + wifi_deinitialize(); +} + +int main(int argc, char **argv) +{ + _check_wifi_state(); + return 0; +}