It works fine when tested on tizen mobile Z3.
Change-Id: Iff140fc33bb22ec83fd9c4ee26e6ba5fb05ab91c
Signed-off-by: sy01.youn <sy01.youn@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/10531
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jihun Ha <jihun.ha@samsung.com>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
rm -rf $name-$version
+echo $1
+export ES_SAMPLE=$1
+
builddir=`pwd`
sourcedir=`pwd`
# 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
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
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
+++ /dev/null
-#!/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
</permit>
<request>
<smack request="system::use_internet" type="rwx"/>
+ <smack request="connman" type="rw"/>
+ <smack request="connman::set" type="rw"/>
+ <smack request="connman::get" type="rw"/>
+ <smack request="connman::profile" type="rw"/>
+ <smack request="net-config" type="rw"/>
<smack request="bt-service" type="rwx"/>
- <smack request="sap" type="rwx"/>
<smack request="bt-service::spp" type="rwx"/>
<smack request="bt-service::gap" type="rwx"/>
<smack request="bt-service::admin" type="rwx"/>
--- /dev/null
+//******************************************************************
+//
+// 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 <wifi.h>
+#include <tizen_error.h>
+#include <glib.h>
+#include <unistd.h>
+
+/**
+ * @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;
+}
+
--- /dev/null
+//******************************************************************
+//
+// 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__ */
//******************************************************************
//
-// Copyright 2015 Samsung Electronics All Rights Reserved.
+// Copyright 2016 Samsung Electronics All Rights Reserved.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
#include "easysetup.h"
+#include "easysetup_wifi_conn.h"
#include <unistd.h>
#include <string.h>
#include <iostream>
#include <pthread.h>
-
-#define TAG "TS"
+#include <glib.h>
+#include <limits>
+#include <unistd.h>
+#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
*/
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<<"============"<<endl;
- cout<<"S: Enabled Security"<<endl;
- cout<<"I: Init easy setup"<<endl;
- cout<<"P: start provisioning resources"<<endl;
- cout<<"T: terminate"<<endl;
- cout<<"Q: quit"<<endl;
- cout<<"============"<<endl;
+ cout << "WiFiProvCbInApp IN" << endl;
+ gWiFiCBflag = true;
+
+ ESSetState(ES_STATE_CONNECTING_TO_ENROLLER);
+
+ if(eventData == NULL)
+ {
+ cout << "ESWiFiProvData is NULL" << endl;
+ return ;
+ }
+
+ cout << "SSID : " << eventData->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"<<endl;
+ cout << "DevConfProvCbInApp IN" << endl;
- if(esResult == ES_OK)
+ if(eventData == NULL)
{
- if(enrolleeState == ES_ON_BOARDED_STATE)
- {
- cout<<"Device is successfully OnBoared on Adhoc network"<<endl;
- }
- else if (enrolleeState == ES_PROVISIONED_STATE)
- {
- cout<<"Device is provisioned with target network's credentials"<<endl;
- }
- else if (enrolleeState == ES_ON_BOARDED_TARGET_NETWORK_STATE)
- {
- cout<<"Device is onboarded/connected with target network"<<endl;
- }
- else
- {
- cout<<"Wrong state !! Easy setup is failed at Enrollee state = "<<enrolleeState<<endl;
- }
+ cout << "ESDevConfProvData is NULL" << endl;
+ return ;
}
- else
+
+ cout << "Language : " << eventData->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 = "<<enrolleeState<<endl;
+ cout << "ESCloudProvData is NULL" << endl;
+ return ;
}
- PrintMenu();
+ cout << "AuthCode : " << eventData->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)
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.."<<endl;
+ cout << "StartEasySetup IN" << endl;
- if(ESInitEnrollee(CT_ADAPTER_IP, ssid, passwd, gIsSecured, EventCallbackInApp) == ES_ERROR)
+ if (OCInit(NULL, 0, OC_SERVER) != OC_STACK_OK)
{
- cout<<"StartEasySetup and onboarding Fail!!"<<endl;
+ cout << "OCStack init error!!" << endl;
return;
}
-}
-void ESInitResources()
-{
- cout<<"Starting Enrollee Provisioning"<<endl;
-
- // Initialize the OC Stack in Server mode
- if (OCInit(NULL, 0, OC_SERVER) != OC_STACK_OK)
+ ESResourceMask resourcemMask = (ESResourceMask) (ES_WIFI_RESOURCE | ES_CLOUD_RESOURCE | ES_DEVCONF_RESOURCE);
+ cout << "resourcemMask : " << resourcemMask << endl;
+ if(ESInitEnrollee(gIsSecured, resourcemMask, gCallbacks) != ES_OK)
{
- cout<<"OCStack init error!!"<<endl;
+ cout << "OCStack init error!!" << endl;
return;
}
- if (ESInitProvisioning() == ES_ERROR)
- {
- cout<<"Init Provisioning Failed!!"<<endl;
- return;
+ cout << "ESInitEnrollee Success" << endl;
+
+ if(gThreadHandle == 0) {
+
+ if (pthread_create(&gThreadHandle, NULL, listeningFunc, NULL)) {
+ cout << "Thread creation failed" << endl;
+ return;
+ }
+
}
- pthread_t thread_handle;
- if (pthread_create(&thread_handle, NULL, listeningFunc, NULL))
+ ESSetState(ES_STATE_INIT);
+ ESSetErrorCode(ES_ERRCODE_NO_ERROR);
+
+ int ret = 0;
+
+ ret = TizenWiFiInit();
+ if(ret != WIFI_NO_ERROR) {
+ cout << "WiFi Init Error" << endl;
+ }
+ else
+ cout << "WiFi Init Success" << endl;
+
+ ret = TizenWiFiScanStart();
+ if(ret != WIFI_NO_ERROR) {
+ cout << "WiFi Scan Error" << endl;
+ }
+ else
+ cout << "WiFi Scan Success" << endl;
+
+ cout << "StartEasySetup OUT" << endl;
+}
+
+void SetDeviceInfo()
+{
+ cout << "SetDeviceInfo IN" << endl;
+
+ ESDeviceProperty deviceProperty = {
+ {{WIFI_11G, WIFI_11N, WIFI_11AC, WiFi_EOF}, WIFI_5G}, {"Tizen Device"}
+ };
+
+ if(ESSetDeviceProperty(&deviceProperty) == ES_ERROR)
{
- cout<<"Thread creation failed"<<endl;
+ cout << "ESSetDeviceProperty Error" << endl;
}
- cout<<"ESInitProvisioning Success"<<endl;
+ // Set user properties if needed
+
+ cout << "SetDeviceInfo OUT" << endl;
}
void StopEasySetup()
{
- cout<<"StopEasySetup IN"<<endl;
-
+ cout << "StopEasySetup IN" << endl;
if (ESTerminateEnrollee() == ES_ERROR)
{
- cout<<"ESTerminateEnrollee Failed!!"<<endl;
+ cout << "ESTerminateEnrollee Failed!!" << endl;
return;
}
- //stop OC Stack
+ // Deinit Tizen Wifi
+ TizenWiFiDeinit();
+
+ // Stop OC Stack
if (OCStop() != OC_STACK_OK)
{
- cout<<"OCStack stop failed!!"<<endl;
+ cout << "OCStack stop failed!!" << endl;
return;
}
- cout<<"StopEasySetup OUT"<<endl;
+ if(gThreadHandle != 0) {
+ pthread_cancel(gThreadHandle);
+ pthread_join(gThreadHandle, NULL);
+ }
+
+ cout << "StopEasySetup OUT" << endl;
+}
+
+void ConnectToTargetAP()
+{
+ if(!gWiFiCBflag){
+ cout << "WiFi Provisioning is needed to be preceded" << endl;
+ return;
+ }
+
+ WiFiConnErrCode ret = WIFI_NO_ERROR;
+ ret = TizenWiFiScanStart();
+ if(ret != WIFI_NO_ERROR){
+ ESSetState(ES_STATE_CONNECTED_FAIL_TO_ENROLLER);
+ ESSetErrorCode(ES_ERRCODE_UNKNOWN);
+ cout << "WiFi Scan Error" << endl;
+ return;
+ }
+ else{
+ cout << "WiFi Scan Succss" << endl;
+ }
+
+ ret = TizenWiFiConn(gSSID, gPasswd);
+ if(ret != WIFI_NO_ERROR) {
+ ESSetState(ES_STATE_CONNECTED_FAIL_TO_ENROLLER);
+
+ if(ret == WIFI_NOTFOUND_SSID_ERROR) {
+ ESSetErrorCode(ES_ERRCODE_SSID_NOT_FOUND);
+ }
+ else if(ret == WIFI_WRONG_PWD_ERROR) {
+ ESSetErrorCode(ES_ERRCODE_PW_WRONG);
+ }
+ else {
+ ESSetErrorCode(ES_ERRCODE_TIMEOUT);
+ }
+ cout << "WiFi Connection Error" << endl;
+ return;
+ }
+ else {
+ cout << "WIFI Connection Success" << endl;
+ ESSetState(ES_STATE_CONNECTED_TO_ENROLLER);
+ ESSetErrorCode(ES_ERRCODE_NO_ERROR);
+ }
+}
+
+gboolean mainThread(GIOChannel *source, GIOCondition condition, gpointer data)
+{
+ char entered;
+ cin >> entered;
+ cin.ignore(numeric_limits<streamsize>::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<<"#########################"<<endl;
- cout<<"EasySetup Enrollee SAMPLE"<<endl;
- cout<<"#########################"<<endl;
+ cout << "#########################" << endl;
+ cout << "EasySetup Enrollee SAMPLE" << endl;
+ cout << "#########################" << endl;
PrintMenu();
- char option;
- while(true)
- {
- cin>>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"<<endl;
- break;
- }
- if (option == 'Q' || option == 'q') break;
+ gMainloop = g_main_loop_new (NULL, FALSE);
+ if(gMainloop == NULL) {
+ cout << "Create Min Loop Error" << endl;
+ return 0;
}
+
+ GIOChannel *channel = g_io_channel_unix_new(0);
+ g_io_add_watch(channel, (GIOCondition)(G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL), mainThread, NULL);
+
+ g_main_loop_run (gMainloop);
+
+ cout << "#########################" << endl;
+ cout << "Terminate Enrollee SAMPLE" << endl;
+ cout << "#########################" << endl;
+
return 0;
}
Group: Applications/OICSample
BuildRequires: pkgconfig(dlog)
BuildRequires: pkgconfig(glib-2.0)
+BuildRequires: pkgconfig(gio-2.0)
+BuildRequires: pkgconfig(gthread-2.0)
BuildRequires: boost-devel
BuildRequires: boost-thread
BuildRequires: boost-system
BuildRequires: iotivity-devel
BuildRequires: iotivity-service
+## If tizen 2.x, RELEASE follows tizen_build_binary_release_type_eng. ##
+## and if tizen 3.0, RELEASE follows tizen_build_devel_mode. ##
+%if 0%{?tizen_build_devel_mode} == 1 || 0%{?tizen_build_binary_release_type_eng} == 1
+%define RELEASE False
+%else
+%define RELEASE True
+%endif
+
+%{!?TARGET_TRANSPORT: %define TARGET_TRANSPORT IP}
+%{!?SECURED: %define SECURED 0}
+%{!?LOGGING: %define LOGGING True}
+%{!?ROUTING: %define ROUTING EP}
+%{!?ES_TARGET_ENROLLEE: %define ES_TARGET_ENROLLEE tizen}
+%{!?ES_ROLE: %define ES_ROLE enrollee}
+%{!?ES_SOFTAP_MODE: %define ES_SOFTAP_MODE MEDIATOR_SOFTAP}
+%{!?VERBOSE: %define VERBOSE 1}
%description
EasySetup Sample application
build_dir = env.get('BUILD_DIR')
sample_dir = build_dir
+env.ParseConfig("pkg-config --cflags --libs capi-network-wifi dlog gobject-2.0 gio-2.0 gthread-2.0 glib-2.0")
env.AppendUnique(CPPFLAGS = ['-std=c++0x', '-fPIC', '-D__TIZEN__','-DWITH_POSIX', '-Wall', '-DSLP_SDK_LOG', '-g','-D_GNU_SOURCE','-DTIZEN_DEBUG_ENABLE', '-DTB_LOG','`pkg-config', '--cflags', '--libs','dlog','capi-network-wifi',
- 'gobject-2.0','glib-2.0`'])
+ 'gobject-2.0', 'gio-2.0', 'gthread-2.0', 'glib-2.0`'])
+
+#env.AppendUnique(CPPFLAGS = ['-std=c++0x', '-fPIC', '-D__TIZEN__','-DWITH_POSIX', '-Wall', '-DSLP_SDK_LOG', '-g','-D_GNU_SOURCE','-DTIZEN_DEBUG_ENABLE', '-DTB_LOG','`pkg-config', '--cflags', '--libs','dlog','capi-network-wifi',
+# 'gobject-2.0','glib-2.0`'])
env.AppendUnique(CPPDEFINES = ['TB_LOG', 'ESWIFI'])
env.AppendUnique(CPPDEFINES = ['ROUTING_GATEWAY'])
elif routing == 'EP':
env.AppendUnique(CPPDEFINES = ['ROUTING_EP'])
-env.Append(LIBS=['octbstack','connectivity_abstraction','coap', 'libESEnrolleeSDK','pthread'])
+
+env.Append(LIBS=['-lgobject-2.0', '-lglib-2.0', '-lgio-2.0', '-lgthread-2.0'])
+env.PrependUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'connectivity_abstraction','coap', 'libESEnrolleeSDK','pthread'])
if secured == '1':
env.PrependUnique(CPPPATH = [root_dir + '/external/inc/'])
env.AppendUnique(CPPDEFINES = ['__WITH_DTLS__'])
-env.Program('enrollee_wifi', [sample_dir + 'enrolleewifi.cpp'])
-
+env.Program('enrollee_wifi', [sample_dir + 'enrolleewifi.cpp', sample_dir + 'easysetup_wifi_conn.c'])
\ No newline at end of file
If needed, same can be modified as per appropriate target.
2) Go to "iotivity/" folder.
-3) Execute following command(s) to start build based on transport selection required :
-scons -f service/easy-setup/sampleapp/enrollee/tizen-sdb/EnrolleeSample/build/tizen/SConscript TARGET_OS=tizen TARGET_TRANSPORT=IP ROUTING=EP RELEASE=0 LOGGING=true
- ES_ROLE=enrollee ES_TARGET_ENROLLEE=android ES_SOFTAP_MODE=ENROLLEE_SOFTAP
+3) Execute following command to build easy setup sample app. :
+
+# sh gbsbuild.sh ES_ON
4) If built for security mode:
After installing sample RPM on device, copy required .dat files and other applications to the same path where enrollee_wifi(executable) is available
%endif
cp resource/c_common/*.h %{buildroot}%{_includedir}
cp resource/csdk/stack/include/*.h %{buildroot}%{_includedir}
+cp resource/csdk/logger/include/*.h %{buildroot}%{_includedir}
cp service/things-manager/sdk/inc/*.h %{buildroot}%{_includedir}
cp service/easy-setup/inc/*.h %{buildroot}%{_includedir}