From d5b1d6cdde9f61c8ae091eabee69e5dd9bb30699 Mon Sep 17 00:00:00 2001 From: "sy01.youn" Date: Fri, 19 Aug 2016 08:12:22 +0900 Subject: [PATCH] Tizen Enrollee Sample App. and its script files are updated. EasySetup logic and Wifi Connection implementation (targeted mobile tizen) are newly updated. It works fine when tested on tizen mobile Z3. Change-Id: Iff140fc33bb22ec83fd9c4ee26e6ba5fb05ab91c Signed-off-by: sy01.youn Reviewed-on: https://gerrit.iotivity.org/gerrit/10531 Tested-by: jenkins-iotivity Reviewed-by: Jihun Ha Reviewed-by: Madan Lanka --- gbsbuild.sh | 33 ++ service/easy-setup/enrollee/SConscript | 1 - .../EnrolleeSample/build/tizen/gbsbuild.sh | 103 ------ .../EnrolleeSample/com.oic.es.sample.manifest | 6 +- .../tizen-sdb/EnrolleeSample/easysetup_wifi_conn.c | 294 ++++++++++++++++ .../tizen-sdb/EnrolleeSample/easysetup_wifi_conn.h | 58 ++++ .../tizen-sdb/EnrolleeSample/enrolleewifi.cpp | 378 ++++++++++++++------- .../packaging/com.oic.es.sample.spec | 18 + .../tizen-sdb/EnrolleeSample/scons/SConscript | 13 +- .../sampleapp/enrollee/tizen-sdb/README.txt | 6 +- tools/tizen/iotivity.spec | 1 + 11 files changed, 682 insertions(+), 229 deletions(-) delete mode 100644 service/easy-setup/sampleapp/enrollee/tizen-sdb/EnrolleeSample/build/tizen/gbsbuild.sh create mode 100644 service/easy-setup/sampleapp/enrollee/tizen-sdb/EnrolleeSample/easysetup_wifi_conn.c create mode 100644 service/easy-setup/sampleapp/enrollee/tizen-sdb/EnrolleeSample/easysetup_wifi_conn.h diff --git a/gbsbuild.sh b/gbsbuild.sh index 84fe3ac..aedbd1e 100755 --- a/gbsbuild.sh +++ b/gbsbuild.sh @@ -10,6 +10,9 @@ name=iotivity rm -rf $name-$version +echo $1 +export ES_SAMPLE=$1 + builddir=`pwd` sourcedir=`pwd` @@ -46,6 +49,8 @@ cp ./LICENSE.md ./tmp # copy dependency RPMs and conf files for tizen build cp ./tools/tizen/*.rpm ./tmp cp ./tools/tizen/.gbs.conf ./tmp +cp ./tools/tizen/*.rpm $sourcedir/tmp/service/easy-setup/sampleapp/enrollee/tizen-sdb/EnrolleeSample +cp ./tools/tizen/.gbs.conf ./tmp/service/easy-setup/sampleapp/enrollee/tizen-sdb/EnrolleeSample cp -R $sourcedir/iotivity.pc.in $sourcedir/tmp @@ -73,6 +78,34 @@ else exit 1 fi +# Build EasySetup App. if ES_ON is entered on command prompt +if echo $ES_SAMPLE|grep -qi '^ES_ON$'; then + cd service/easy-setup/sampleapp/enrollee/tizen-sdb/EnrolleeSample + echo `pwd` + echo "EasySetup Sample Build is enabled" + + # Initialize Git repository for EnrolleeSample + if [ ! -d .git ]; then + git init ./ + git config user.email "you@example.com" + git config user.name "Your Name" + git add ./ + git commit -m "Initial commit" + fi + echo "Calling EasySetup Sample gbs build command" + gbscommand="gbs build -A armv7l -B ~/GBS-ROOT-OIC --include-all --repository ./" + echo $gbscommand + if eval $gbscommand; then + echo "EasySetup Sample build is successful" + else + echo "EasySetup Sample build is failed." + exit 1 + fi +else + echo "EasySetup Sample Build is not enabled" +fi + +rm -rf tmp cd $sourcedir rm -rf $sourcedir/tmp diff --git a/service/easy-setup/enrollee/SConscript b/service/easy-setup/enrollee/SConscript index b353aa8..5c2b99f 100644 --- a/service/easy-setup/enrollee/SConscript +++ b/service/easy-setup/enrollee/SConscript @@ -85,7 +85,6 @@ if target_os == 'tizen': enrollee_env.AppendUnique(RPATH = [enrollee_env.get('BUILD_DIR')]) enrollee_env.AppendUnique(CXXFLAGS = ['-pthread']) enrollee_env.PrependUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'pthread', 'connectivity_abstraction']) - enrollee_env.AppendUnique(CPPPATH = [enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/tizen/wifi']) ###################################################################### # Arduino Enrollee diff --git a/service/easy-setup/sampleapp/enrollee/tizen-sdb/EnrolleeSample/build/tizen/gbsbuild.sh b/service/easy-setup/sampleapp/enrollee/tizen-sdb/EnrolleeSample/build/tizen/gbsbuild.sh deleted file mode 100644 index 5479bcc..0000000 --- a/service/easy-setup/sampleapp/enrollee/tizen-sdb/EnrolleeSample/build/tizen/gbsbuild.sh +++ /dev/null @@ -1,103 +0,0 @@ -#!/bin/sh - -cur_dir="./service/easy-setup" - -spec=`ls ./service/easy-setup/sampleapp/enrollee/tizen-sdb/EnrolleeSample/packaging/*.spec` -version=`rpm --query --queryformat '%{version}\n' --specfile $spec` - -name=`echo $name|cut -d" " -f 1` -version=`echo $version|cut -d" " -f 1` - -name=iotivity - -rm -rf $name-$version - -builddir=`pwd` -sourcedir=`pwd` - -echo `pwd` - -rm -rf ./tmp - -# Create directory structure for GBS Build -mkdir ./tmp -mkdir ./tmp/con/ -mkdir ./tmp/extlibs/ -mkdir ./tmp/packaging -cp -R ./build_common $sourcedir/tmp -cp -R ./examples $sourcedir/tmp - -# tinycbor is available as soft-link, so copying with 'dereference' option. -cp -LR ./extlibs/tinycbor $sourcedir/tmp/extlibs -rm -rf $sourcedir/tmp/extlibs/tinycbor/tinycbor/.git - -cp -R ./extlibs/cjson $sourcedir/tmp/extlibs -cp -R ./extlibs/tinydtls $sourcedir/tmp/extlibs -cp -R ./extlibs/sqlite3 $sourcedir/tmp/extlibs -cp -R ./extlibs/timer $sourcedir/tmp/extlibs -cp -R ./extlibs/rapidxml $sourcedir/tmp/extlibs -cp -R ./resource $sourcedir/tmp -cp -R ./service $sourcedir/tmp -cp ./extra_options.scons $sourcedir/tmp -cp ./tools/tizen/*.spec ./tmp/packaging -cp ./tools/tizen/*.manifest ./tmp/packaging -cp ./SConstruct ./tmp -cp ./LICENSE.md ./tmp - -# copy dependency RPMs and conf files for tizen build -cp ./tools/tizen/*.rpm ./tmp -cp ./tools/tizen/.gbs.conf ./tmp -cp ./tools/tizen/*.rpm $sourcedir/tmp/service/easy-setup/sampleapp/enrollee/tizen-sdb/EnrolleeSample -cp ./tools/tizen/.gbs.conf ./tmp/service/easy-setup/sampleapp/enrollee/tizen-sdb/EnrolleeSample -cp -R $sourcedir/iotivity.pc.in $sourcedir/tmp - -cd $sourcedir/tmp - -echo `pwd` - -whoami -# Initialize Git repository -if [ ! -d .git ]; then - git init ./ - git config user.email "you@example.com" - git config user.name "Your Name" - git add ./ - git commit -m "Initial commit" -fi - -echo "Calling core gbs build command" -gbscommand="gbs build -A armv7l --include-all --repository ./ --define 'TARGET_TRANSPORT $1' --define 'SECURED $2' --define 'RELEASE $5' --define 'LOGGING $6' --define 'ES_ROLE $7' --define 'ES_TARGET_ENROLLEE $8' --define 'ES_SOFTAP_MODE $9'" -echo $gbscommand -if eval $gbscommand; then - echo "Core build is successful" -else - echo "Core build failed." - cd $sourcedir - rm -rf $sourcedir/tmp - exit 1 -fi - -cd service/easy-setup/sampleapp/enrollee/tizen-sdb/EnrolleeSample -echo `pwd` -# Initialize Git repository -if [ ! -d .git ]; then - git init ./ - git config user.email "you@example.com" - git config user.name "Your Name" - git add ./ - git commit -m "Initial commit" -fi -echo "Calling sample gbs build command" -gbscommand="gbs build -A armv7l -B ~/GBS-ROOT --include-all --repository ./ --define 'TARGET_TRANSPORT $1' --define 'SECURED $2' --define 'ROUTING $4' --define 'RELEASE $5' --define 'LOGGING $6' --define 'ES_ROLE $7' --define 'ES_TARGET_ENROLLEE $8' --define 'ES_SOFTAP_MODE $9'" -echo $gbscommand -if eval $gbscommand; then - echo "Sample build is successful" -else - echo "Sample build is failed." - exit 1 -fi -rm -rf tmp -cd $sourcedir -rm -rf $sourcedir/tmp - -exit 0 diff --git a/service/easy-setup/sampleapp/enrollee/tizen-sdb/EnrolleeSample/com.oic.es.sample.manifest b/service/easy-setup/sampleapp/enrollee/tizen-sdb/EnrolleeSample/com.oic.es.sample.manifest index b37c690..16c3594 100644 --- a/service/easy-setup/sampleapp/enrollee/tizen-sdb/EnrolleeSample/com.oic.es.sample.manifest +++ b/service/easy-setup/sampleapp/enrollee/tizen-sdb/EnrolleeSample/com.oic.es.sample.manifest @@ -6,8 +6,12 @@ + + + + + - diff --git a/service/easy-setup/sampleapp/enrollee/tizen-sdb/EnrolleeSample/easysetup_wifi_conn.c b/service/easy-setup/sampleapp/enrollee/tizen-sdb/EnrolleeSample/easysetup_wifi_conn.c new file mode 100644 index 0000000..d8ff9fd --- /dev/null +++ b/service/easy-setup/sampleapp/enrollee/tizen-sdb/EnrolleeSample/easysetup_wifi_conn.c @@ -0,0 +1,294 @@ +//****************************************************************** +// +// Copyright 2016 Samsung Electronics 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 "easysetup_wifi_conn.h" +#include "string.h" +#include "logger.h" +#include "escommon.h" + +#include +#include +#include +#include + +/** + * @var ES_WIFICONN_TAG + * @brief Logging tag for module name. + */ +#define ES_WIFICONN_TAG "ESWIFICONN" + +typedef struct{ + char wifiName[OIC_STRING_MAX_VALUE]; + char wifiPasswd[OIC_STRING_MAX_VALUE]; +} TargetWifiInfo; + +static bool gWiFiConnFlag; + +char* PrintWifiErr(wifi_error_e errType) +{ + switch (errType) { + case WIFI_ERROR_NONE: + return "NONE"; + case WIFI_ERROR_INVALID_PARAMETER: + return "INVALID_PARAMETER"; + case WIFI_ERROR_OUT_OF_MEMORY: + return "OUT_OF_MEMORY"; + case WIFI_ERROR_INVALID_OPERATION: + return "INVALID_OPERATION"; + case WIFI_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED: + return "ADDRESS_FAMILY_NOT_SUPPORTED"; + case WIFI_ERROR_OPERATION_FAILED: + return "OPERATION_FAILED"; + case WIFI_ERROR_NO_CONNECTION: + return "NO_CONNECTION"; + case WIFI_ERROR_NOW_IN_PROGRESS: + return "NOW_IN_PROGRESS"; + case WIFI_ERROR_ALREADY_EXISTS: + return "ALREADY_EXISTS"; + case WIFI_ERROR_OPERATION_ABORTED: + return "OPERATION_ABORTED"; + case WIFI_ERROR_DHCP_FAILED: + return "DHCP_FAILED"; + case WIFI_ERROR_INVALID_KEY: + return "INVALID_KEY"; + case WIFI_ERROR_NO_REPLY: + return "NO_REPLY"; + case WIFI_ERROR_SECURITY_RESTRICTED: + return "SECURITY_RESTRICTED"; + case WIFI_ERROR_PERMISSION_DENIED: + return "PERMISSION_DENIED"; + case WIFI_ERROR_NOT_SUPPORTED: + return "NOT_SUPPORTED"; + } + + return "UNKNOWN"; +} + +static void WiFiScanCallback(wifi_error_e err, void* data) +{ + if(data != NULL) { + OIC_LOG_V(INFO, ES_WIFICONN_TAG, "UserData : %s", (char *) data); + } + + OIC_LOG_V(INFO, ES_WIFICONN_TAG, "Scan Callback Res : %s", PrintWifiErr(err)); +} + +static void WiFiActivateCallback(wifi_error_e result, void* user_data) +{ + OIC_LOG(DEBUG, ES_WIFICONN_TAG, "__test_activated_callback IN"); + + int ret = wifi_scan(WiFiScanCallback, NULL); + if (ret != WIFI_ERROR_NONE) { + OIC_LOG(ERROR, ES_WIFICONN_TAG, "WiFi Scan Error"); + OIC_LOG_V(INFO, ES_WIFICONN_TAG, "Scan Fail Status : %s", PrintWifiErr((wifi_error_e) ret)); + } + + OIC_LOG(DEBUG, ES_WIFICONN_TAG, "__test_activated_callback OUT"); + +} + +static void ConnectedCallback(wifi_error_e err, void* data) +{ + if(err == WIFI_ERROR_NONE) { + OIC_LOG(DEBUG, ES_WIFICONN_TAG, "Success to Connect AP"); + } + else { + OIC_LOG(ERROR, ES_WIFICONN_TAG, "Fail to Connect AP"); + } +} + +static bool WiFiFoundCallback(wifi_ap_h ap, void *data) +{ + TargetWifiInfo* targetInfo = (TargetWifiInfo *) data; + + char *foundAP = NULL; + + int ret = wifi_ap_get_essid(ap, &foundAP); + + if(ret != WIFI_ERROR_NONE) { + OIC_LOG(ERROR, ES_WIFICONN_TAG, "Fail to get AP"); + OIC_LOG_V(INFO, ES_WIFICONN_TAG, "Fail Status : %s", PrintWifiErr((wifi_error_e) ret)); + return false; + } + + OIC_LOG_V(DEBUG, ES_WIFICONN_TAG, "Found AP name : %s", foundAP); + + if(strstr(foundAP, targetInfo->wifiName) != NULL) { + + bool needPasswd = false; + + if (wifi_ap_is_passphrase_required(ap, &needPasswd) == WIFI_ERROR_NONE) { + + OIC_LOG(DEBUG, ES_WIFICONN_TAG, "Passsword required"); + + ret = wifi_ap_set_passphrase(ap, targetInfo->wifiPasswd); + if (ret != WIFI_ERROR_NONE) { + OIC_LOG(ERROR, ES_WIFICONN_TAG, "Fail to Set Password"); + OIC_LOG_V(INFO, ES_WIFICONN_TAG, "Fail Status : %s", PrintWifiErr((wifi_error_e) ret)); + g_free(foundAP); + return false; + } + + ret = wifi_connect(ap, ConnectedCallback, targetInfo); + if (ret != WIFI_ERROR_NONE) { + OIC_LOG(ERROR, ES_WIFICONN_TAG, "Fail to connect wifi"); + OIC_LOG_V(INFO, ES_WIFICONN_TAG, "Connect Fail Status : %s", PrintWifiErr((wifi_error_e) ret)); + g_free(foundAP); + return false; + } + else { + OIC_LOG_V(INFO, ES_WIFICONN_TAG, "Success to connect wifi : %s", PrintWifiErr((wifi_error_e) ret)); + gWiFiConnFlag = true; + g_free(foundAP); + return false; + } + + + } + else { + OIC_LOG(ERROR, ES_WIFICONN_TAG, "Fail to get Passphrase Required"); + OIC_LOG_V(INFO, ES_WIFICONN_TAG, "Fail Status : %s", PrintWifiErr((wifi_error_e) ret)); + return false; + } + + } + else { + OIC_LOG(DEBUG, ES_WIFICONN_TAG, "This AP is not the one wanted to be connected"); + OIC_LOG_V(INFO, ES_WIFICONN_TAG, "Searching : %s / Searched : %s", targetInfo->wifiName, foundAP); + } + + g_free(foundAP); + + return true; +} + +WiFiConnErrCode TizenWiFiDeinit() +{ + OIC_LOG(DEBUG, ES_WIFICONN_TAG, "TizenWiFiDeinit IN"); + + int ret = wifi_deinitialize(); + if(ret != WIFI_ERROR_NONE) { + OIC_LOG(ERROR, ES_WIFICONN_TAG, "wifi deinit error"); + OIC_LOG_V(INFO, ES_WIFICONN_TAG, "Fail Status : %s", PrintWifiErr((wifi_error_e) ret)); + return WIFI_DEINIT_ERROR; + } + + OIC_LOG(DEBUG, ES_WIFICONN_TAG, "TizenWiFiDeinit OUT"); + return WIFI_NO_ERROR; +} + +WiFiConnErrCode TizenWiFiInit() +{ + OIC_LOG(DEBUG, ES_WIFICONN_TAG, "TizenWiFiInit IN"); + + gWiFiConnFlag = false; + int ret = wifi_initialize(); + if (ret != WIFI_ERROR_NONE) { + OIC_LOG(ERROR, ES_WIFICONN_TAG, "WiFi Init Error"); + OIC_LOG_V(INFO, ES_WIFICONN_TAG, "Init Fail Status : %s", PrintWifiErr((wifi_error_e) ret)); + return WIFI_INIT_ERROR; + } + + OIC_LOG(DEBUG, ES_WIFICONN_TAG, "TizenWiFiInit OUT"); + + return WIFI_NO_ERROR; +} + +WiFiConnErrCode TizenWiFiScanStart() +{ + OIC_LOG(DEBUG, ES_WIFICONN_TAG, "TizenWiFiScanStart IN"); + int ret; + + bool wifiState = false; + wifi_is_activated(&wifiState); + + // if wifi is not activated, actviate & scan + if (wifiState == false) { + OIC_LOG(ERROR, ES_WIFICONN_TAG, "WiFi Not Activated...Activate it!"); + ret = wifi_activate(WiFiActivateCallback, NULL); + + if(ret != WIFI_ERROR_NONE) { + OIC_LOG(ERROR, ES_WIFICONN_TAG, "wifi activate error"); + return WIFI_ACTIVATE_ERROR; + } + } + else{ + ret = wifi_scan(WiFiScanCallback, NULL); + if (ret != WIFI_ERROR_NONE) { + OIC_LOG(ERROR, ES_WIFICONN_TAG, "WiFi Scan Error"); + OIC_LOG_V(INFO, ES_WIFICONN_TAG, "Scan Fail Status : %s", PrintWifiErr((wifi_error_e) ret)); + return WIFI_SCAN_ERROR; + } + } + + OIC_LOG(DEBUG, ES_WIFICONN_TAG, "TizenWiFiScanStart OUT"); + + return WIFI_NO_ERROR; +} + + +WiFiConnErrCode TizenWiFiConn(char *ssid, char* passwd) +{ + TargetWifiInfo targetInfo; + + memset(targetInfo.wifiName, 0, OIC_STRING_MAX_VALUE); + memset(targetInfo.wifiPasswd, 0, OIC_STRING_MAX_VALUE); + if(ssid != NULL) + { + strncpy(targetInfo.wifiName, ssid, strlen(ssid)); + } + + if(passwd != NULL) + { + strncpy(targetInfo.wifiPasswd, passwd, strlen(passwd)); + } + + int ret = wifi_foreach_found_aps(WiFiFoundCallback, &targetInfo); + if(ret != WIFI_ERROR_NONE) { + OIC_LOG(ERROR, ES_WIFICONN_TAG, "wifi_foreach_found_aps Error"); + OIC_LOG_V(INFO, ES_WIFICONN_TAG, "Fail Status : %s", PrintWifiErr((wifi_error_e) ret)); + memset(targetInfo.wifiName, 0, OIC_STRING_MAX_VALUE); + memset(targetInfo.wifiPasswd, 0, OIC_STRING_MAX_VALUE); + + return WIFI_CONN_ERROR; + } + + // try to find target AP during 10[sec] + int times = 1; + while(!gWiFiConnFlag) { + sleep(1); + + if(times >= 10){ + OIC_LOG(ERROR, ES_WIFICONN_TAG, "Connection Error... try 10[sec]"); + memset(targetInfo.wifiName, 0, OIC_STRING_MAX_VALUE); + memset(targetInfo.wifiPasswd, 0, OIC_STRING_MAX_VALUE); + + return WIFI_CONN_ERROR; + } + + times ++; + } + + gWiFiConnFlag = false; + + return WIFI_NO_ERROR; +} + diff --git a/service/easy-setup/sampleapp/enrollee/tizen-sdb/EnrolleeSample/easysetup_wifi_conn.h b/service/easy-setup/sampleapp/enrollee/tizen-sdb/EnrolleeSample/easysetup_wifi_conn.h new file mode 100644 index 0000000..15f8b06 --- /dev/null +++ b/service/easy-setup/sampleapp/enrollee/tizen-sdb/EnrolleeSample/easysetup_wifi_conn.h @@ -0,0 +1,58 @@ +//****************************************************************** +// +// Copyright 2016 Samsung Electronics 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. +// +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + +#ifndef EASYSETUP_WIFI_CONN_H__ +#define EASYSETUP_WIFI_CONN_H__ +#ifdef __cplusplus + +extern "C" +{ +#endif + +typedef enum +{ + /** No error.*/ + WIFI_NO_ERROR = 0, + /** Tizen WiFi Init Error.*/ + WIFI_INIT_ERROR, + /** Tizen WiFi Deinit Error.*/ + WIFI_DEINIT_ERROR, + /** Tizen WiFi Activate Error.*/ + WIFI_ACTIVATE_ERROR, + /** Tizen WiFi Scan Error.*/ + WIFI_SCAN_ERROR, + /** Tizen WiFi Connection Error.*/ + WIFI_CONN_ERROR, + /** Tizen WiFi Not Found SSID Error.*/ + WIFI_NOTFOUND_SSID_ERROR, + /** Tizen WiFi Wrong Password Error.*/ + WIFI_WRONG_PWD_ERROR, +} WiFiConnErrCode; + +WiFiConnErrCode TizenWiFiInit(void); +WiFiConnErrCode TizenWiFiDeinit(void); +WiFiConnErrCode TizenWiFiScanStart(void); +WiFiConnErrCode TizenWiFiConn(char *ssid, char* passwd); + +#ifdef __cplusplus +} +#endif + +#endif /* EASYSETUP_WIFI_CONN_H__ */ diff --git a/service/easy-setup/sampleapp/enrollee/tizen-sdb/EnrolleeSample/enrolleewifi.cpp b/service/easy-setup/sampleapp/enrollee/tizen-sdb/EnrolleeSample/enrolleewifi.cpp index 79943b1..94a51cd 100755 --- a/service/easy-setup/sampleapp/enrollee/tizen-sdb/EnrolleeSample/enrolleewifi.cpp +++ b/service/easy-setup/sampleapp/enrollee/tizen-sdb/EnrolleeSample/enrolleewifi.cpp @@ -1,6 +1,6 @@ //****************************************************************** // -// Copyright 2015 Samsung Electronics All Rights Reserved. +// Copyright 2016 Samsung Electronics All Rights Reserved. // //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // @@ -20,29 +20,25 @@ #include "easysetup.h" +#include "easysetup_wifi_conn.h" #include #include #include #include - -#define TAG "TS" +#include +#include +#include +#define TAG "TIZEN_ES" using namespace std; -void *listeningFunc(void*); +gboolean mainThread(GIOChannel *source, GIOCondition condition, gpointer data); +void *listeningFunc(void *); -/** - * @var ssid - * @brief Target SSID of the Soft Access point to which the device has to connect - */ -static char ssid[] = "EasySetup123"; +GMainLoop *gMainloop; +static pthread_t gThreadHandle = 0; -/** - * @var passwd - * @brief Password of the Soft Access point to which the device has to connect - */ -static char passwd[] = "EasySetup123"; /** * Secure Virtual Resource database for Iotivity Server @@ -51,55 +47,100 @@ static char passwd[] = "EasySetup123"; */ static char CRED_FILE[] = "oic_svr_db_server.dat"; -OCPersistentStorage ps ; - +OCPersistentStorage ps; /** * @var gIsSecured * @brief Variable to check if secure mode is enabled or not. */ static bool gIsSecured = false; +static bool gWiFiCBflag = false; +static char gSSID[OIC_STRING_MAX_VALUE]; +static char gPasswd[OIC_STRING_MAX_VALUE]; -void PrintMenu() +void WiFiProvCbInApp(ESWiFiProvData *eventData) { - cout<<"============"<ssid << endl; + cout << "Password : " << eventData->pwd << endl; + cout << "AuthType : " << eventData->authtype << endl; + cout << "EncType : " << eventData->enctype << endl; + + memset(gSSID, 0, OIC_STRING_MAX_VALUE); + memset(gPasswd, 0, OIC_STRING_MAX_VALUE); + if(eventData->ssid != NULL) + { + strncpy(gSSID, eventData->ssid, strlen(eventData->ssid)); + } + + if(eventData->pwd != NULL) + { + strncpy(gPasswd, eventData->pwd, strlen(eventData->pwd)); + } + + cout << "WiFiProvCbInApp OUT" << endl; } -void EventCallbackInApp(ESResult esResult, ESEnrolleeState enrolleeState) +void DevConfProvCbInApp(ESDevConfProvData *eventData) { - cout<<"Easy setup event callback"<language << endl; + cout << "Country : " << eventData->country << endl; + + cout << "DevConfProvCbInApp OUT" << endl; +} + +void CloudDataProvCbInApp(ESCloudProvData *eventData) +{ + cout << "CloudDataProvCbInApp IN" << endl; + + if(eventData == NULL) { - cout<<"Easy stup is failed at Enrollee state = "<authCode << endl; + cout << "AuthProvider : " << eventData->authProvider << endl; + cout << "CI Server : " << eventData->ciServer << endl; + + cout << "CloudDataProvCbInApp OUT" << endl; + +} + +ESProvisioningCallbacks gCallbacks = { + .WiFiProvCb = &WiFiProvCbInApp, + .DevConfProvCb = &DevConfProvCbInApp, + .CloudDataProvCb = &CloudDataProvCbInApp +}; + +void PrintMenu() +{ + cout << "========================" << endl; + cout << "A: Enabled Security" << endl; + cout << "B: Init & Start EasySetup" << endl; + cout << "C: Set DeviceInfo" << endl; + cout << "D: Connect to TargetAP" << endl; + cout << "Q: Terminate" << endl; + cout << "ENTER : Show Menu......." << endl; + cout << "========================" << endl; } FILE* server_fopen(const char *path, const char *mode) @@ -110,121 +151,224 @@ FILE* server_fopen(const char *path, const char *mode) void EnableSecurity() { - cout << "Inside EnableSecurity API.." << endl; + printf("Inside EnableSecurity API..\n"); gIsSecured = true; // Initialize Persistent Storage for SVR database - ps = { server_fopen, fread, fwrite, fclose, unlink }; + ps = (OCPersistentStorage){ server_fopen, fread, fwrite, fclose, unlink }; OCRegisterPersistentStorageHandler(&ps); } void StartEasySetup() { - cout<<"StartEasySetup and onboarding started.."<> entered; + cin.ignore(numeric_limits::max(), '\n'); + + switch (entered) { + case 'Q': // quit + case 'q': + StopEasySetup(); + break; + + case 'A': // Enable Security + case 'a': + //EnableSecurity(); + PrintMenu(); + break; + + case 'B': // Init EasySetup + case 'b': + StartEasySetup(); + PrintMenu(); + break; + + case 'C': // Set Device Info + case 'c': + SetDeviceInfo(); + PrintMenu(); + break; + + case 'D': // Start to connect target AP + case 'd': + ConnectToTargetAP(); + PrintMenu(); + break; + + default: + cout << "Wrong option" << endl; + PrintMenu(); + break; + } + + if(entered == 'q' || entered == 'Q'){ + g_main_loop_quit(gMainloop); + } + + return TRUE; } int main() { - cout<<"#########################"<>option; - switch (option) - { - case 'H': // help - case 'h': - PrintMenu(); - break; - - case 'Q': // quit - case 'q': - cout<<"quit"; - break; - - case 'S': // Enable Security - case 's': - EnableSecurity(); - break; - - case 'I': // Init EasySetup - case 'i': - StartEasySetup(); - break; - - case 'P': // start provisioning - case 'p': - ESInitResources(); - break; - - case 'T': // stop easy setup - case 't': - StopEasySetup(); - break; - - default: - cout<<"wrong option"<