From: Madan Lanka Date: Fri, 2 Oct 2015 09:13:15 +0000 (-0400) Subject: [Easy-Setup] Arduino Enrollee Doxygen update and api folder change X-Git-Tag: 1.2.0+RC1~952 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=67ecf55a724ba906e12e9986bb8e04f77a4f6a06;p=platform%2Fupstream%2Fiotivity.git [Easy-Setup] Arduino Enrollee Doxygen update and api folder change - Reused OCConnectivityType struct instead of defining new struct - Updated the Enrollee Device doxygen comments - Enrollee EasySetup API folder is changed - License header contribution year is updated Change-Id: I72e095c5c886fb10dd365b72c80944f8864685ee Signed-off-by: Madan Lanka Reviewed-on: https://gerrit.iotivity.org/gerrit/3413 Tested-by: jenkins-iotivity Reviewed-by: Uze Choi --- diff --git a/service/easy-setup/Build_Instructions_Android_Arduino.txt b/service/easy-setup/Build_Instructions_Android_Arduino.txt index 9056422..6fad77e 100755 --- a/service/easy-setup/Build_Instructions_Android_Arduino.txt +++ b/service/easy-setup/Build_Instructions_Android_Arduino.txt @@ -1,3 +1,23 @@ +#****************************************************************** +# +# Copyright 2015 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. +# +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + === Prerequisites === * 1. Scons diff --git a/service/easy-setup/SConscript b/service/easy-setup/SConscript index fef6e1d..4b4446a 100644 --- a/service/easy-setup/SConscript +++ b/service/easy-setup/SConscript @@ -1,6 +1,6 @@ #****************************************************************** # -# Copyright 2014 Samsung Electronics All Rights Reserved. +# Copyright 2015 Samsung Electronics All Rights Reserved. # #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= # @@ -65,8 +65,9 @@ if target_os == 'arduino': '../../resource/csdk/stack/include', '../../extlibs/cjson', 'sdk/enrollee/arduino/wifi', - 'sdk/enrollee/common/src', - 'sdk/enrollee/common/inc']) + 'sdk/enrollee/api', + 'sdk/enrollee/src', + 'sdk/enrollee/inc']) easy_setup_env.AppendUnique(CPPDEFINES = ['TB_LOG', 'ESWIFI']) if target_os in ['android','linux']: easy_setup_env.PrependUnique(CPPPATH = [ @@ -86,8 +87,8 @@ if target_os in ['android','linux']: if target_os == 'arduino': es_sdk_static = easy_setup_env.StaticLibrary('ESSDKLibrary', - ['sdk/enrollee/common/src/easysetup.cpp', - 'sdk/enrollee/common/src/resourceHandler.cpp', + ['sdk/enrollee/src/easysetup.cpp', + 'sdk/enrollee/src/resourceHandler.cpp', 'sdk/enrollee/arduino/wifi/networkHandler.cpp']) easy_setup_env.InstallTarget(es_sdk_static, 'libESSDK') diff --git a/service/easy-setup/sampleapp/SConscript b/service/easy-setup/sampleapp/SConscript index fa70b40..95b780a 100644 --- a/service/easy-setup/sampleapp/SConscript +++ b/service/easy-setup/sampleapp/SConscript @@ -1,6 +1,6 @@ #****************************************************************** # -# Copyright 2014 Samsung Electronics All Rights Reserved. +# Copyright 2015 Samsung Electronics All Rights Reserved. # #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= # diff --git a/service/easy-setup/sampleapp/enrollee/arduino/SConscript b/service/easy-setup/sampleapp/enrollee/arduino/SConscript index f9c5bf0..2fa74cd 100644 --- a/service/easy-setup/sampleapp/enrollee/arduino/SConscript +++ b/service/easy-setup/sampleapp/enrollee/arduino/SConscript @@ -1,6 +1,6 @@ #****************************************************************** # -# Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved. +# Copyright 2015 Samsung Electronics All Rights Reserved. # #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= # @@ -33,8 +33,9 @@ enrollee_env.PrependUnique(CPPPATH = [ '../../../../../extlibs/cjson', '../../../sdk/common', '../../../sdk/enrollee/arduino/wifi', - '../../../sdk/enrollee/common/inc', - '../../../sdk/enrollee/common/src' + '../../../sdk/enrollee/api', + '../../../sdk/enrollee/inc', + '../../../sdk/enrollee/src' ]) enrollee_env.AppendUnique(CPPDEFINES = ['TB_LOG', 'ESWIFI']) diff --git a/service/easy-setup/sampleapp/enrollee/arduino/enrollee_wifi.cpp b/service/easy-setup/sampleapp/enrollee/arduino/enrollee_wifi.cpp index aa3416c..7e7d6f7 100755 --- a/service/easy-setup/sampleapp/enrollee/arduino/enrollee_wifi.cpp +++ b/service/easy-setup/sampleapp/enrollee/arduino/enrollee_wifi.cpp @@ -1,6 +1,6 @@ //****************************************************************** // -// Copyright 2014 Samsung Electronics All Rights Reserved. +// Copyright 2015 Samsung Electronics All Rights Reserved. // //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // @@ -80,13 +80,13 @@ void setup() OC_LOG_INIT(); OC_LOG(DEBUG, TAG, "OCServer is starting..."); - if(InitEasySetup(ES_WIFI, ssid, passwd, EventCallbackInApp) == ES_ERROR) + if(InitEasySetup(CT_ADAPTER_IP, ssid, passwd, EventCallbackInApp) == ES_ERROR) { OC_LOG(ERROR, TAG, "EasySetup Init Failed"); return; } - if(InitProvisioning(EventCallbackInApp)== ES_ERROR) + if(InitProvisioning()== ES_ERROR) { OC_LOG(ERROR, TAG, "Init Provisioning Failed"); return; diff --git a/service/easy-setup/sampleapp/mediator/linux/SConscript b/service/easy-setup/sampleapp/mediator/linux/SConscript index 10d9873..8522aaa 100644 --- a/service/easy-setup/sampleapp/mediator/linux/SConscript +++ b/service/easy-setup/sampleapp/mediator/linux/SConscript @@ -1,6 +1,6 @@ #****************************************************************** # -# Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved. +# Copyright 2015 Samsung Electronics All Rights Reserved. # #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= # diff --git a/service/easy-setup/sdk/common/common.h b/service/easy-setup/sdk/common/common.h index 2cd5073..6a22ac2 100755 --- a/service/easy-setup/sdk/common/common.h +++ b/service/easy-setup/sdk/common/common.h @@ -1,6 +1,6 @@ //****************************************************************** // -// Copyright 2014 Samsung Electronics All Rights Reserved. +// Copyright 2015 Samsung Electronics All Rights Reserved. // //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // diff --git a/service/easy-setup/sdk/enrollee/api/easysetup.h b/service/easy-setup/sdk/enrollee/api/easysetup.h new file mode 100644 index 0000000..9887a2c --- /dev/null +++ b/service/easy-setup/sdk/enrollee/api/easysetup.h @@ -0,0 +1,80 @@ +//****************************************************************** +// +// Copyright 2015 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. +// +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + +/** + * @file + * + * This file contains SDK APIs for device operating in Enrollee Mode of EasySetup + */ + +#ifndef EASYSETUP_ENROLLEE_H__ +#define EASYSETUP_ENROLLEE_H__ + +// Do not remove the include below +#include "Arduino.h" +#include "networkHandler.h" + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +/* + * Callback function for updating the Enrollee OnBoarding and Provisioning status result to the application + * + * @param esResult ESResult provides the current state of the Enrollee Device + */ +typedef void (*EventCallback)(ESResult esResult); + +/** + * This function Initializes the EasySetup. This API must be called prior to invoking any other API + * + * @param networkType NetworkType on which OnBoarding has to be performed. + * @param ssid SSID of the target SoftAP network to which the Enrollee is connecting. + * @param passwd Password of the target SoftAP network to which the Enrollee is connecting + * @param eventCallback EventCallback for for updating the Enrollee OnBoarding and Provisioning status + * result to the application + * @return ::ES_OK on success, some other value upon failure. + */ +ESResult InitEasySetup(OCConnectivityType networkType, const char *ssid, + const char *passwd, + EventCallback eventCallback); + +/** + * This function performs initialization of Provisioning and Network resources needed for EasySetup process. + * + * @return ::ES_OK on success, some other value upon failure. + */ +ESResult InitProvisioning(); + +/** + * This function performs termination of Provisioning and Network resources. + * Also terminates the IoTivity core stack. + * + * @return ::ES_OK on success, some other value upon failure. + */ +ESResult TerminateEasySetup(); + +#ifdef __cplusplus +} +#endif // __cplusplus + + +#endif /* EASYSETUP_ENROLLEE_H__ */ + diff --git a/service/easy-setup/sdk/enrollee/arduino/wifi/networkHandler.cpp b/service/easy-setup/sdk/enrollee/arduino/wifi/networkHandler.cpp index b648a82..b9504fb 100755 --- a/service/easy-setup/sdk/enrollee/arduino/wifi/networkHandler.cpp +++ b/service/easy-setup/sdk/enrollee/arduino/wifi/networkHandler.cpp @@ -1,6 +1,6 @@ //****************************************************************** // -// Copyright 2014 Samsung Electronics All Rights Reserved. +// Copyright 2015 Samsung Electronics All Rights Reserved. // //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // @@ -20,8 +20,29 @@ #include "networkHandler.h" -#define TAG "ES_NH" +// Arduino WiFi Shield includes +#include +#include +#include +#include + +#include "logger.h" + +/** + * @var ES_NH_TAG + * @brief Logging tag for module name. + */ +#define ES_NH_TAG "ES_NH" + +//----------------------------------------------------------------------------- +// Private variables +//----------------------------------------------------------------------------- +static IPAddress myIP; + +//----------------------------------------------------------------------------- +// Private internal function prototypes +//----------------------------------------------------------------------------- int findNetwork(const char *ssid); int ConnectToNetwork(const char *ssid, const char *pass); void printEncryptionType(int thisType); @@ -29,11 +50,8 @@ void printEncryptionType(int thisType); // Arduino WiFi Shield // Note : Arduino WiFi Shield currently does NOT support multicast and therefore // this server will NOT be listening on 224.0.1.187 multicast address. - static const char ARDUINO_WIFI_SHIELD_UDP_FW_VER[] = "1.1.0"; -IPAddress myIP; - ESResult ConnectToWiFiNetwork(const char *ssid, const char *pass, NetworkEventCallback cb) { char *fwVersion; @@ -43,21 +61,21 @@ ESResult ConnectToWiFiNetwork(const char *ssid, const char *pass, NetworkEventCa // check for the presence of the shield: if (WiFi.status() == WL_NO_SHIELD) { - OC_LOG(ERROR, TAG, "WiFi shield not present"); + OC_LOG(ERROR, ES_NH_TAG, "WiFi shield not present"); return ES_ERROR; } // Verify that WiFi Shield is running the firmware with all UDP fixes fwVersion = WiFi.firmwareVersion(); - OC_LOG_V(INFO, TAG, "WiFi Shield Firmware version %s", fwVersion); + OC_LOG_V(INFO, ES_NH_TAG, "WiFi Shield Firmware version %s", fwVersion); if (strncmp(fwVersion, ARDUINO_WIFI_SHIELD_UDP_FW_VER, sizeof(ARDUINO_WIFI_SHIELD_UDP_FW_VER)) != 0) { - OC_LOG(DEBUG, TAG, "!!!!! Upgrade WiFi Shield Firmware version !!!!!!"); + OC_LOG(DEBUG, ES_NH_TAG, "!!!!! Upgrade WiFi Shield Firmware version !!!!!!"); //return ES_ERROR; } - OC_LOG_V(INFO, TAG, "Finding SSID: %s", ssid); + OC_LOG_V(INFO, ES_NH_TAG, "Finding SSID: %s", ssid); while (findNetwork(ssid) == 0) // found { @@ -126,17 +144,17 @@ int ConnectToNetwork(const char *ssid, const char *pass) // attempt to connect to Wifi network: while (status != WL_CONNECTED) { - OC_LOG_V(INFO, TAG, "Attempting to connect to SSID: %s", ssid); + OC_LOG_V(INFO, ES_NH_TAG, "Attempting to connect to SSID: %s", ssid); status = WiFi.begin((char *) ssid, (char *) pass); // wait 10 seconds for connection: delay(10000); } - OC_LOG(DEBUG, TAG, "Connected to wifi"); + OC_LOG(DEBUG, ES_NH_TAG, "Connected to wifi"); myIP = WiFi.localIP(); - OC_LOG_V(INFO, TAG, "IP Address: %d.%d.%d.%d", myIP[0], myIP[1], myIP[2], myIP[3]); + OC_LOG_V(INFO, ES_NH_TAG, "IP Address: %d.%d.%d.%d", myIP[0], myIP[1], myIP[2], myIP[3]); char buf[50]; sprintf(buf, "IP Address: %d.%d.%d.%d", myIP[0], myIP[1], myIP[2], myIP[3]); @@ -145,20 +163,24 @@ int ConnectToNetwork(const char *ssid, const char *pass) return 0; } -int getCurrentNetworkInfo(NetworkType targetType, NetworkInfo *info) +ESResult getCurrentNetworkInfo(OCConnectivityType targetType, NetworkInfo *info) { - if (targetType == ES_WIFI && WiFi.status() == WL_CONNECTED) + if (targetType == CT_ADAPTER_IP && WiFi.status() == WL_CONNECTED) { - info->type = ES_WIFI; + info->type = CT_ADAPTER_IP; info->ipaddr = WiFi.localIP(); if(strlen(WiFi.SSID())<=MAXSSIDLEN) - strcpy(info->ssid, WiFi.SSID()); - else return -1; - - return 0; + { + strcpy(info->ssid, WiFi.SSID()); + return ES_OK; + } + else + { + return ES_ERROR; + } } - return -1; + return ES_ERROR; } void printEncryptionType(int thisType) diff --git a/service/easy-setup/sdk/enrollee/arduino/wifi/networkHandler.h b/service/easy-setup/sdk/enrollee/arduino/wifi/networkHandler.h index 5da8cbb..8758674 100755 --- a/service/easy-setup/sdk/enrollee/arduino/wifi/networkHandler.h +++ b/service/easy-setup/sdk/enrollee/arduino/wifi/networkHandler.h @@ -1,6 +1,6 @@ //****************************************************************** // -// Copyright 2014 Samsung Electronics All Rights Reserved. +// Copyright 2015 Samsung Electronics All Rights Reserved. // //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // @@ -18,48 +18,50 @@ // //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +/** + * @file + * + * This file contains IP network handling functionality for Enrollee device + */ + +#ifndef ES_NETWORK_HANDLER_H_ +#define ES_NETWORK_HANDLER_H_ + // Do not remove the include below #include "Arduino.h" -#include "logger.h" -#include "ocstack.h" -#include - -// Arduino WiFi Shield +// Arduino WiFi Shield includes #include #include #include +#include +#include "logger.h" #include "common.h" -#ifndef ES_NETWORK_HANDLER_H_ -#define ES_NETWORK_HANDLER_H_ - #define MAXSSIDLEN 33 #define MAXNETCREDLEN 20 #define MAXNUMTYPE 5 #define MAXADDRLEN 15 -typedef void (*NetworkEventCallback)(ESResult); +/* + * Callback function for updating the Network status to the subscribers + * + * @param esResult ESResult provides the current state of the network connection status + */ +typedef void (*NetworkEventCallback)(ESResult esResult); -enum NetworkType +typedef struct { - ES_WIFI = 1, ES_BT = 2, ES_BLE = 3, ES_ZIGBEE = 4, ES_ETH = 5 -}; - -typedef struct NETWORKINFO -{ - NetworkType type; - + OCConnectivityType type; // for WiFI IPAddress ipaddr; char ssid[MAXSSIDLEN]; - // for BT, BLE byte mac[6]; } NetworkInfo; ESResult ConnectToWiFiNetwork(const char *ssid, const char *pass, NetworkEventCallback); -int getCurrentNetworkInfo(NetworkType targetType, NetworkInfo *info); +ESResult getCurrentNetworkInfo(OCConnectivityType targetType, NetworkInfo *info); #endif diff --git a/service/easy-setup/sdk/enrollee/common/inc/easysetup.h b/service/easy-setup/sdk/enrollee/common/inc/easysetup.h deleted file mode 100755 index 116c930..0000000 --- a/service/easy-setup/sdk/enrollee/common/inc/easysetup.h +++ /dev/null @@ -1,40 +0,0 @@ -//****************************************************************** -// -// Copyright 2014 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. -// -//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - -// Do not remove the include below -#include "Arduino.h" - -#include -#include "ocstack.h" -#include "networkHandler.h" - -typedef void (*EventCallback)(ESResult); - -#ifdef ESWIFI -ESResult InitEasySetup(NetworkType networkType, const char *ssid, const char *passwd,EventCallback cb); -#endif - -#ifdef ESBLE -ESResult InitEasySetup(NetworkType networkType,EventCallback cb); -#endif - -ESResult InitProvisioning(EventCallback cb); -ESResult TerminateEasySetup(); - diff --git a/service/easy-setup/sdk/enrollee/common/inc/resourceHandler.h b/service/easy-setup/sdk/enrollee/inc/resourceHandler.h old mode 100755 new mode 100644 similarity index 97% rename from service/easy-setup/sdk/enrollee/common/inc/resourceHandler.h rename to service/easy-setup/sdk/enrollee/inc/resourceHandler.h index e64c2f5..765f916 --- a/service/easy-setup/sdk/enrollee/common/inc/resourceHandler.h +++ b/service/easy-setup/sdk/enrollee/inc/resourceHandler.h @@ -1,6 +1,6 @@ //****************************************************************** // -// Copyright 2014 Samsung Electronics All Rights Reserved. +// Copyright 2015 Samsung Electronics All Rights Reserved. // //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // @@ -21,10 +21,9 @@ // Do not remove the include below #include "Arduino.h" +#include #include "logger.h" #include "ocstack.h" -#include - #include "common.h" #include "networkHandler.h" #include "octypes.h" diff --git a/service/easy-setup/sdk/enrollee/common/src/easysetup.cpp b/service/easy-setup/sdk/enrollee/src/easysetup.cpp old mode 100755 new mode 100644 similarity index 57% rename from service/easy-setup/sdk/enrollee/common/src/easysetup.cpp rename to service/easy-setup/sdk/enrollee/src/easysetup.cpp index 7560993..5fa44fc --- a/service/easy-setup/sdk/enrollee/common/src/easysetup.cpp +++ b/service/easy-setup/sdk/enrollee/src/easysetup.cpp @@ -1,6 +1,6 @@ //****************************************************************** // -// Copyright 2014 Samsung Electronics All Rights Reserved. +// Copyright 2015 Samsung Electronics All Rights Reserved. // //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // @@ -18,20 +18,48 @@ // //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +/** + * @file + * + * This file contains the implementation for EasySetup Enrollee device + */ + #include "easysetup.h" #include "logger.h" #include "resourceHandler.h" -#define TAG "ES" - -int g_eventflag = 0; -int g_cnt = 0; -char *targetSsid; -char *targetPass; - -EventCallback g_cbForProvisioning = NULL; -EventCallback g_cbForOnboarding = NULL; +/** + * @var ES_ENROLLEE_TAG + * @brief Logging tag for module name. + */ +#define ES_ENROLLEE_TAG "ES" + +//----------------------------------------------------------------------------- +// Private variables +//----------------------------------------------------------------------------- + +/** + * @var targetSsid + * @brief Target SSID of the Soft Access point to which the device has to connect + */ +static char *targetSsid; + +/** + * @var targetPass + * @brief Password of the target access point to which the device has to connect + */ +static char *targetPass; + +/** + * @var g_cbForEnrolleeStatus + * @brief Fucntion pointer holding the callback for intimation of EasySetup Enrollee status callback + */ +static EventCallback g_cbForEnrolleeStatus = NULL; + +//----------------------------------------------------------------------------- +// Private internal function prototypes +//----------------------------------------------------------------------------- void EventCallbackInOnboarding(ESResult event); void EventCallbackInProvisioning(ESResult event); @@ -41,9 +69,9 @@ void EventCallbackInOnboarding(ESResult event) { if (event == ES_NETWORKFOUND || event == ES_NETWORKCONNECTED) { - if (g_cbForOnboarding != NULL) + if (g_cbForEnrolleeStatus != NULL) { - g_cbForOnboarding(event); + g_cbForEnrolleeStatus(event); } } } @@ -59,7 +87,7 @@ void EventCallbackInProvisioning(ESResult event) if(TerminateEasySetup() != OC_STACK_OK) { - OC_LOG(ERROR, TAG, "Terminating stack failed"); + OC_LOG(ERROR, ES_ENROLLEE_TAG, "Terminating stack failed"); return; } @@ -67,9 +95,9 @@ void EventCallbackInProvisioning(ESResult event) res = ConnectToWiFiNetwork(targetSsid, targetPass, EventCallbackAfterProvisioning); - if (g_cbForProvisioning != NULL) + if (g_cbForEnrolleeStatus != NULL) { - g_cbForProvisioning(res); + g_cbForEnrolleeStatus(res); } } } @@ -78,14 +106,14 @@ void EventCallbackAfterProvisioning(ESResult event) { if (event == ES_NETWORKFOUND || event == ES_NETWORKCONNECTED) { - if (g_cbForProvisioning != NULL) + if (g_cbForEnrolleeStatus != NULL) { - g_cbForProvisioning(event); + g_cbForEnrolleeStatus(event); } } } -ESResult FindNetworkForOnboarding(NetworkType networkType, +ESResult FindNetworkForOnboarding(OCConnectivityType networkType, const char *ssid, const char *passwd, EventCallback cb) @@ -95,20 +123,22 @@ ESResult FindNetworkForOnboarding(NetworkType networkType, return ES_ERROR; } - if (networkType == ES_WIFI) + if (networkType == CT_ADAPTER_IP) { - if (g_cbForOnboarding == NULL) + if (g_cbForEnrolleeStatus == NULL) { - g_cbForOnboarding = cb; + g_cbForEnrolleeStatus = cb; } if(ConnectToWiFiNetwork(ssid, passwd, EventCallbackInOnboarding) != ES_NETWORKCONNECTED) { - OC_LOG(ERROR, TAG, "ConnectToWiFiNetwork Failed"); + OC_LOG(ERROR, ES_ENROLLEE_TAG, "ConnectToWiFiNetwork Failed"); + cb(ES_NETWORKNOTCONNECTED); return ES_ERROR; } else{ - OC_LOG(INFO, TAG, "ConnectToWiFiNetwork Success"); + OC_LOG(INFO, ES_ENROLLEE_TAG, "ConnectToWiFiNetwork Success"); + cb(ES_NETWORKCONNECTED); return ES_OK; } } @@ -116,24 +146,24 @@ ESResult FindNetworkForOnboarding(NetworkType networkType, } -ESResult InitEasySetup(NetworkType networkType, const char *ssid, const char *passwd, +ESResult InitEasySetup(OCConnectivityType networkType, const char *ssid, const char *passwd, EventCallback cb) { if(FindNetworkForOnboarding(networkType, ssid, passwd, cb) != ES_OK) { - OC_LOG(ERROR, TAG, "OnBoarding Failed"); + OC_LOG(ERROR, ES_ENROLLEE_TAG, "OnBoarding Failed"); return ES_ERROR; } // Initialize the OC Stack in Server mode if (OCInit(NULL, 0, OC_SERVER) != OC_STACK_OK) { - OC_LOG(ERROR, TAG, "OCStack init error"); + OC_LOG(ERROR, ES_ENROLLEE_TAG, "OCStack init error"); return ES_ERROR; } else { - OC_LOG(DEBUG, TAG, "OCStack init success"); + OC_LOG(DEBUG, ES_ENROLLEE_TAG, "OCStack init success"); return ES_OK; } } @@ -142,27 +172,18 @@ ESResult TerminateEasySetup() { if(OCStop() != OC_STACK_OK) { - OC_LOG(ERROR, TAG, "OCStack stop failed"); + OC_LOG(ERROR, ES_ENROLLEE_TAG, "OCStack stop failed"); return ES_ERROR; } else { - OC_LOG(ERROR, TAG, "OCStack stop success"); + OC_LOG(ERROR, ES_ENROLLEE_TAG, "OCStack stop success"); return ES_OK; } } -ESResult InitProvisioning(EventCallback cb) +ESResult InitProvisioning() { - if (cb == NULL) - { - return ES_ERROR; - } - else - { - g_cbForProvisioning = cb; - } - if (CreateProvisioningResource() != OC_STACK_OK) { return ES_ERROR; diff --git a/service/easy-setup/sdk/enrollee/common/src/resourceHandler.cpp b/service/easy-setup/sdk/enrollee/src/resourceHandler.cpp old mode 100755 new mode 100644 similarity index 77% rename from service/easy-setup/sdk/enrollee/common/src/resourceHandler.cpp rename to service/easy-setup/sdk/enrollee/src/resourceHandler.cpp index f62b4bd..aacdbee --- a/service/easy-setup/sdk/enrollee/common/src/resourceHandler.cpp +++ b/service/easy-setup/sdk/enrollee/src/resourceHandler.cpp @@ -1,6 +1,6 @@ //****************************************************************** // -// Copyright 2014 Samsung Electronics All Rights Reserved. +// Copyright 2015 Samsung Electronics All Rights Reserved. // //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // @@ -21,18 +21,41 @@ #include "resourceHandler.h" #include "ocpayload.h" -#define TAG "ES_RH" - -ProvResource g_prov; -NetResource g_net; - +/** + * @var ES_RH_TAG + * @brief Logging tag for module name. + */ +#define ES_RH_TAG "ES_RH" + +//----------------------------------------------------------------------------- +// Private variables +//----------------------------------------------------------------------------- + +/** + * @var g_prov + * @brief Structure for holding the Provisioning status and target information required to connect to the target network + */ +static ProvResource g_prov; + +/** + * @var g_net + * @brief Structure forr holding the Provisioning status of network information + */ +static NetResource g_net; + +//----------------------------------------------------------------------------- +// Private internal function prototypes +//----------------------------------------------------------------------------- OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag, OCEntityHandlerRequest *ehRequest, void *callback); const char *getResult(OCStackResult result); -OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload); -OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload); -OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload); +OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest, + OCRepPayload** payload); +OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest *ehRequest, + OCRepPayload** payload); +OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, + OCRepPayload** payload); OCRepPayload* constructResponse(OCEntityHandlerRequest *ehRequest); int g_flag = 0; @@ -56,14 +79,14 @@ void GetTargetNetworkInfoFromProvResource(char *name, char *pass) OCStackResult CreateProvisioningResource() { g_prov.ps = 1; // need to provisioning - g_prov.tnt = ES_WIFI; + g_prov.tnt = CT_ADAPTER_IP; sprintf(g_prov.tnn, "Unknown"); sprintf(g_prov.cd, "Unknown"); OCStackResult res = OCCreateResource(&g_prov.handle, "oic.r.prov", OC_RSRVD_INTERFACE_DEFAULT, OC_RSRVD_ES_URI_PROV, OCEntityHandlerCb, NULL, OC_DISCOVERABLE | OC_OBSERVABLE); - OC_LOG_V(INFO, TAG, "Created Prov resource with result: %s", getResult(res)); + OC_LOG_V(INFO, ES_RH_TAG, "Created Prov resource with result: %s", getResult(res)); return res; } @@ -72,50 +95,51 @@ OCStackResult CreateNetworkResource() { NetworkInfo netInfo; - if (getCurrentNetworkInfo(ES_WIFI, &netInfo) != 0) + if (getCurrentNetworkInfo(CT_ADAPTER_IP, &netInfo) != ES_OK) { return OC_STACK_ERROR; } - if (netInfo.type != ES_WIFI) + if (netInfo.type != CT_ADAPTER_IP) { return OC_STACK_ERROR; } g_net.cnt = (int) netInfo.type; - g_net.ant[0] = (int) ES_WIFI; + g_net.ant[0] = (int) CT_ADAPTER_IP; sprintf(g_net.ipaddr, "%d.%d.%d.%d", netInfo.ipaddr[0], netInfo.ipaddr[1], netInfo.ipaddr[2], netInfo.ipaddr[3]); sprintf(g_net.cnn, "%s", netInfo.ssid); - OC_LOG_V(INFO, TAG, "SSID: %s", g_net.cnn); - OC_LOG_V(INFO, TAG, "IP Address: %s", g_net.ipaddr); + OC_LOG_V(INFO, ES_RH_TAG, "SSID: %s", g_net.cnn); + OC_LOG_V(INFO, ES_RH_TAG, "IP Address: %s", g_net.ipaddr); OCStackResult res = OCCreateResource(&g_net.handle, "oic.r.net", OC_RSRVD_INTERFACE_DEFAULT, OC_RSRVD_ES_URI_NET, OCEntityHandlerCb,NULL, OC_DISCOVERABLE | OC_OBSERVABLE); - OC_LOG_V(INFO, TAG, "Created Net resource with result: %s", getResult(res)); + OC_LOG_V(INFO, ES_RH_TAG, "Created Net resource with result: %s", getResult(res)); return res; } #endif -OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload **payload) +OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest, + OCRepPayload **payload) { OCEntityHandlerResult ehResult = OC_EH_ERROR; if (!ehRequest) { - OC_LOG(ERROR, TAG, "Request is Null"); + OC_LOG(ERROR, ES_RH_TAG, "Request is Null"); return ehResult; } if (ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION) { - OC_LOG(ERROR, TAG, "Incoming payload not a representation"); + OC_LOG(ERROR, ES_RH_TAG, "Incoming payload not a representation"); return ehResult; } OCRepPayload *getResp = constructResponse(ehRequest); if (!getResp) { - OC_LOG(ERROR, TAG, "constructResponse failed"); + OC_LOG(ERROR, ES_RH_TAG, "constructResponse failed"); return OC_EH_ERROR; } @@ -125,20 +149,21 @@ OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest, OCRep return ehResult; } -OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload) +OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest *ehRequest, + OCRepPayload** payload) { OCEntityHandlerResult ehResult = OC_EH_ERROR; if (ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION) { - OC_LOG(ERROR, TAG, "Incoming payload not a representation"); + OC_LOG(ERROR, ES_RH_TAG, "Incoming payload not a representation"); return ehResult; } OCRepPayload* input = (OCRepPayload*) (ehRequest->payload); if (!input) { - OC_LOG(ERROR, TAG, "Failed to parse"); + OC_LOG(ERROR, ES_RH_TAG, "Failed to parse"); return ehResult; } @@ -159,7 +184,7 @@ OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest *ehRequest, OCRep OCRepPayload *getResp = constructResponse(ehRequest); if (!getResp) { - OC_LOG(ERROR, TAG, "constructResponse failed"); + OC_LOG(ERROR, ES_RH_TAG, "constructResponse failed"); return OC_EH_ERROR; } @@ -169,24 +194,25 @@ OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest *ehRequest, OCRep return ehResult; } -OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload) +OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, + OCRepPayload** payload) { OCEntityHandlerResult ehResult = OC_EH_ERROR; if (!ehRequest) { - OC_LOG(ERROR, TAG, "Request is Null"); + OC_LOG(ERROR, ES_RH_TAG, "Request is Null"); return ehResult; } if (ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION) { - OC_LOG(ERROR, TAG, "Incoming payload not a representation"); + OC_LOG(ERROR, ES_RH_TAG, "Incoming payload not a representation"); return ehResult; } OCRepPayload* input = (OCRepPayload*) (ehRequest->payload); if (!input) { - OC_LOG(ERROR, TAG, "Failed to parse"); + OC_LOG(ERROR, ES_RH_TAG, "Failed to parse"); return ehResult; } char* tr; @@ -207,7 +233,7 @@ OCRepPayload* constructResponse(OCEntityHandlerRequest *ehRequest) OCRepPayload* payload = OCRepPayloadCreate(); if (!payload) { - OC_LOG(ERROR, TAG, "Failed to allocate Payload"); + OC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload"); return NULL; } @@ -242,12 +268,12 @@ OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag, { if (OC_REST_GET == entityHandlerRequest->method) { - OC_LOG(INFO, TAG, "Received GET request"); + OC_LOG(INFO, ES_RH_TAG, "Received GET request"); ehRet = ProcessGetRequest(entityHandlerRequest, &payload); } else if (OC_REST_PUT == entityHandlerRequest->method) { - OC_LOG(INFO, TAG, "Received PUT request"); + OC_LOG(INFO, ES_RH_TAG, "Received PUT request"); if (g_prov.handle != NULL && entityHandlerRequest->resource == g_prov.handle) { @@ -261,7 +287,7 @@ OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag, else if (OC_REST_POST == entityHandlerRequest->method) { // TODO: As of now, POST request will be not received. - OC_LOG(INFO, TAG, "Received OC_REST_POST from client"); + OC_LOG(INFO, ES_RH_TAG, "Received OC_REST_POST from client"); //ehRet = ProcessPostRequest (entityHandlerRequest, payload, sizeof(payload) - 1); } @@ -283,7 +309,7 @@ OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag, // Send the response if (OCDoResponse(&response) != OC_STACK_OK) { - OC_LOG(ERROR, TAG, "Error sending response"); + OC_LOG(ERROR, ES_RH_TAG, "Error sending response"); ehRet = OC_EH_ERROR; } }