From db420230e956243b9a14ee471a3432d0e4d16b67 Mon Sep 17 00:00:00 2001 From: Jihun Ha Date: Wed, 13 Jul 2016 17:12:30 +0900 Subject: [PATCH] Fix an faulty logic in resource handler and clean up useless codes 1. In resourcehandler, a logic of encoding array type's property is fixed. 2. Remove a useless logic to send a GET request before a POST request for update of WiFi and devConf properties in EnroleeResource 3. Change country property's key --> ctry 4. Clean up old structure and enum variable not used anymore. 5. Remove a csdk for mediator which is not used anymore Change-Id: I7502e6b33860db1bcc91a67829ac9411ff9cae6d Signed-off-by: Jihun Ha Reviewed-on: https://gerrit.iotivity.org/gerrit/9241 Tested-by: jenkins-iotivity Reviewed-by: Madan Lanka --- service/easy-setup/enrollee/src/easysetup.c | 15 +- service/easy-setup/enrollee/src/resourcehandler.c | 53 +- service/easy-setup/enrollee/src/resourcehandler.h | 1 - service/easy-setup/inc/escommon.h | 164 +----- service/easy-setup/mediator/SConscript | 3 - .../easy-setup/mediator/csdk/inc/provisioning.h | 119 ----- .../easy-setup/mediator/csdk/inc/provisioningapi.h | 56 -- .../easy-setup/mediator/csdk/src/provisioning.cpp | 577 --------------------- .../mediator/csdk/src/provisioningapi.cpp | 127 ----- .../mediator/csdk/src/wifiprovisioning.cpp | 274 ---------- .../mediator/csdk/unittests/MediatorCSDKTest.cpp | 124 ----- .../mediator/csdk/unittests/UnitTestHelper.h | 48 -- .../easy-setup/mediator/richsdk/inc/ESRichCommon.h | 73 ++- .../mediator/richsdk/inc/EnrolleeResource.h | 2 - .../mediator/richsdk/src/CloudResource.cpp | 8 +- .../mediator/richsdk/src/EnrolleeResource.cpp | 136 ++--- .../mediator/richsdk/src/RemoteEnrollee.cpp | 6 +- .../mediator/linux/richsdk_sample/mediator_cpp.cpp | 1 - 18 files changed, 112 insertions(+), 1675 deletions(-) delete mode 100755 service/easy-setup/mediator/csdk/inc/provisioning.h delete mode 100755 service/easy-setup/mediator/csdk/inc/provisioningapi.h delete mode 100755 service/easy-setup/mediator/csdk/src/provisioning.cpp delete mode 100755 service/easy-setup/mediator/csdk/src/provisioningapi.cpp delete mode 100755 service/easy-setup/mediator/csdk/src/wifiprovisioning.cpp delete mode 100644 service/easy-setup/mediator/csdk/unittests/MediatorCSDKTest.cpp delete mode 100644 service/easy-setup/mediator/csdk/unittests/UnitTestHelper.h diff --git a/service/easy-setup/enrollee/src/easysetup.c b/service/easy-setup/enrollee/src/easysetup.c index 2e9d9d3..466f470 100755 --- a/service/easy-setup/enrollee/src/easysetup.c +++ b/service/easy-setup/enrollee/src/easysetup.c @@ -224,7 +224,7 @@ ESResult ESSetState(ESEnrolleeState esState) { OIC_LOG(INFO, ES_ENROLLEE_TAG, "ESSetState IN"); - if(esState <= 0 || esState >= 6) + if(esState < ES_STATE_INIT || esState > ES_STATE_REGISTRRED_FAIL_TO_CLOUD) { OIC_LOG_V(ERROR, ES_ENROLLEE_TAG, "Invalid ESEnrolleeState : %d", esState); return ES_ERROR; @@ -232,10 +232,11 @@ ESResult ESSetState(ESEnrolleeState esState) if(SetEnrolleeState(esState) != OC_STACK_OK) { - OIC_LOG(ERROR, ES_ENROLLEE_TAG, "ESSetState Error"); + OIC_LOG(ERROR, ES_ENROLLEE_TAG, "ESSetState ES_ERROR"); return ES_ERROR; } + OIC_LOG_V(INFO, ES_ENROLLEE_TAG, "Set ESState succesfully : %d", esState); OIC_LOG(INFO, ES_ENROLLEE_TAG, "ESSetState OUT"); return ES_OK; } @@ -244,21 +245,19 @@ ESResult ESSetErrorCode(ESErrorCode esErrCode) { OIC_LOG(INFO, ES_ENROLLEE_TAG, "ESSetErrorCode IN"); - if(esErrCode <= 0 || esErrCode >= 7) + if(esErrCode < ES_ERRCODE_NO_ERROR || esErrCode > ES_ERRCODE_UNKNOWN) { - if(esErrCode != 999) - { - OIC_LOG_V(ERROR, ES_ENROLLEE_TAG, "Invalid ESErrorCode : %d", esErrCode); + OIC_LOG_V(ERROR, ES_ENROLLEE_TAG, "Invalid ESSetErrorCode : %d", esErrCode); return ES_ERROR; - } } if(SetEnrolleeErrCode(esErrCode) != OC_STACK_OK) { - OIC_LOG(ERROR, ES_ENROLLEE_TAG, "ESSetErrorCode Error"); + OIC_LOG(ERROR, ES_ENROLLEE_TAG, "ESSetErrorCode ES_ERROR"); return ES_ERROR; } + OIC_LOG_V(DEBUG, ES_ENROLLEE_TAG, "Set ESErrorCode succesfully : %d", esErrCode); OIC_LOG(INFO, ES_ENROLLEE_TAG, "ESSetErrorCode OUT"); return ES_OK; } diff --git a/service/easy-setup/enrollee/src/resourcehandler.c b/service/easy-setup/enrollee/src/resourcehandler.c index 2917799..302f6bd 100755 --- a/service/easy-setup/enrollee/src/resourcehandler.c +++ b/service/easy-setup/enrollee/src/resourcehandler.c @@ -126,9 +126,8 @@ void GetTargetNetworkInfoFromProvResource(char *name, char *pass) OCStackResult initProvResource(bool isSecured) { - gProvResource.status = NO_PROVISION; - gProvResource.trigger = false; - gProvResource.lastErrCode = ES_ERRCODE_NONE; + gProvResource.status = ES_STATE_INIT; + gProvResource.lastErrCode = ES_ERRCODE_NO_ERROR; OICStrcpy(gProvResource.errorMessage, MAX_ERRMSGLEN, ""); OICStrcpy(gProvResource.ocfWebLinks, MAX_WEBLINKLEN, ""); @@ -369,7 +368,7 @@ void updateCloudResource(OCRepPayload* input) void updateDevConfResource(OCRepPayload* input) { char *country = NULL; - if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_AUTHCODE, &country)) + if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_COUNTRY, &country)) { OICStrcpy(gDevConfResource.country, sizeof(gDevConfResource.country), country); OICStrcpy(gDevConfData.country, sizeof(gDevConfData.country), country); @@ -377,7 +376,7 @@ void updateDevConfResource(OCRepPayload* input) } char *language = NULL; - if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_AUTHPROVIDER, &language)) + if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_LANGUAGE, &language)) { OICStrcpy(gDevConfResource.language, sizeof(gDevConfResource.language), language); OICStrcpy(gDevConfData.language, sizeof(gDevConfData.language), language); @@ -413,7 +412,10 @@ OCRepPayload* constructResponseOfWiFi() OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_WIFI); size_t dimensions[MAX_REP_ARRAY_DEPTH] = {gWiFiResource.numMode, 0, 0}; - OCRepPayloadSetIntArray(payload, OC_RSRVD_ES_SUPPORTEDWIFIMODE, (int64_t *)gWiFiResource.supportedMode, dimensions); + int64_t *modes_64 = (int64_t *)malloc(gWiFiResource.numMode * sizeof(int64_t)); + for(int i = 0 ; i < gWiFiResource.numMode ; ++i) + modes_64[i] = gWiFiResource.supportedMode[i]; + OCRepPayloadSetIntArray(payload, OC_RSRVD_ES_SUPPORTEDWIFIMODE, (int64_t *)modes_64, dimensions); OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_SUPPORTEDWIFIFREQ, gWiFiResource.supportedFreq); OCRepPayloadSetPropString(payload, OC_RSRVD_ES_SSID, gWiFiResource.ssid); @@ -421,8 +423,6 @@ OCRepPayload* constructResponseOfWiFi() OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_AUTHTYPE, (int) gWiFiResource.authType); OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_ENCTYPE, (int) gWiFiResource.encType); - printf("%s\n", gWiFiResource.ssid); - return payload; } @@ -474,9 +474,7 @@ OCRepPayload* constructResponseOfProv(OCEntityHandlerRequest *ehRequest) OIC_LOG(INFO, ES_RH_TAG, "constructResponse prov res"); OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_PROV); OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_PROVSTATUS, gProvResource.status); - OCRepPayloadSetPropBool(payload, OC_RSRVD_ES_TRIGGER, gProvResource.trigger); OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_LAST_ERRORCODE, gProvResource.lastErrCode); - OCRepPayloadSetPropString(payload, OC_RSRVD_ES_ERRORMESSAGE, gProvResource.errorMessage); OCRepPayloadSetPropString(payload, OC_RSRVD_ES_LINKS, gProvResource.ocfWebLinks); if(ehRequest->query) @@ -675,6 +673,10 @@ OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRe return ehResult; } + // TBD : Discuss about triggering flag (to be existed or not) + // ES_PS_PROVISIONING_COMPLETED state indicates that already provisioning is completed. + // A new request for provisioning means overriding existing network provisioning information. + if(ehRequest->resource == gProvResource.handle) updateProvResource(ehRequest, input); else if(ehRequest->resource == gWiFiResource.handle) @@ -682,33 +684,7 @@ OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRe else if(ehRequest->resource == gCloudResource.handle) updateCloudResource(input); else if(ehRequest->resource == gDevConfResource.handle) - updateDevConfResource(input); - - // TBD : Discuss about triggering flag (to be existed or not) - // ES_PS_PROVISIONING_COMPLETED state indicates that already provisioning is completed. - // A new request for provisioning means overriding existing network provisioning information. - // if (gProvResource.trigger) - // { - // OIC_LOG(DEBUG, ES_RH_TAG, "Provisioning already completed." - // "Tiggering the network connection"); - - // if (gNetworkInfoProvEventCb) - // { - // gNetworkInfoProvEventCb(ES_RECVTRIGGEROFPROVRES); - // ehResult = OC_EH_OK; - // } - // else - // { - // OIC_LOG(ERROR, ES_RH_TAG, "gNetworkInfoProvEventCb is NULL." - // "Network handler not registered. Failed to connect to the network"); - // ehResult = OC_EH_ERROR; - // return ehResult; - // } - // } - // else - // { - // OIC_LOG(DEBUG, ES_RH_TAG, "Provisioning the network information to the Enrollee."); - // } + updateDevConfResource(input); OCRepPayload *getResp = NULL; if(ehRequest->resource == gProvResource.handle) @@ -720,9 +696,6 @@ OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRe else if(ehRequest->resource == gDevConfResource.handle) getResp = constructResponseOfDevConf(); - if (gProvResource.trigger)// Trigger false should be restored after executed - gProvResource.trigger = false; - if (!getResp) { OIC_LOG(ERROR, ES_RH_TAG, "constructResponse failed"); diff --git a/service/easy-setup/enrollee/src/resourcehandler.h b/service/easy-setup/enrollee/src/resourcehandler.h index cca35ed..7fb3686 100755 --- a/service/easy-setup/enrollee/src/resourcehandler.h +++ b/service/easy-setup/enrollee/src/resourcehandler.h @@ -42,7 +42,6 @@ typedef struct PROVRESOURCE { OCResourceHandle handle; ProvStatus status; // provisiong status - bool trigger; // Trigger network connection, 0 : Init value, 1 : Connected to the target network. ESErrorCode lastErrCode; char errorMessage[MAX_ERRMSGLEN]; char ocfWebLinks[MAX_WEBLINKLEN]; diff --git a/service/easy-setup/inc/escommon.h b/service/easy-setup/inc/escommon.h index 3dbd58e..a6b7656 100755 --- a/service/easy-setup/inc/escommon.h +++ b/service/easy-setup/inc/escommon.h @@ -24,6 +24,11 @@ #include "ocstack.h" #include "octypes.h" +#ifdef __cplusplus +extern "C" +{ +#endif + // Defines #define OIC_STRING_MAX_VALUE 100 #define IPV4_ADDR_SIZE 16 @@ -39,9 +44,7 @@ */ #define OC_RSRVD_ES_PROVSTATUS "ps" #define OC_RSRVD_ES_LAST_ERRORCODE "lec" -#define OC_RSRVD_ES_ERRORMESSAGE "em" #define OC_RSRVD_ES_LINKS "links" -#define OC_RSRVD_ES_TRIGGER "tr" #define OC_RSRVD_ES_SUPPORTEDWIFIMODE "swmt" #define OC_RSRVD_ES_SUPPORTEDWIFIFREQ "swf" #define OC_RSRVD_ES_SSID "tnn" @@ -53,7 +56,7 @@ #define OC_RSRVD_ES_CISERVER "cisurl" #define OC_RSRVD_ES_DEVNAME "dn" #define OC_RSRVD_ES_LANGUAGE "lang" -#define OC_RSRVD_ES_COUNTRY "cont" +#define OC_RSRVD_ES_COUNTRY "ctry" /** * Easysetup defined resoruce types and uris. @@ -68,19 +71,12 @@ #define OC_RSRVD_ES_URI_DEVCONF "/.well-known/ocf/prov/devconf" #define NUM_WIFIMODE 10 -#define MAX_SSIDLEN 33 -#define MAX_CREDLEN 20 +#define MAX_SSIDLEN 33 +#define MAX_CREDLEN 20 -#define MAX_DEVICELEN 100 -#define MAX_ERRMSGLEN 100 -#define MAX_WEBLINKLEN 100 - -typedef enum -{ - NO_PROVISION = 0, - CONNECTED_ENROLLER, - FAILED_CONNECTION -} PROV_STATUS; +#define MAX_DEVICELEN 100 +#define MAX_ERRMSGLEN 100 +#define MAX_WEBLINKLEN 100 typedef enum { @@ -117,25 +113,6 @@ typedef enum TKIP_AES } WIFI_ENCTYPE; -/** -* Device Roles defined for each device type used in easy setup -*/ -typedef enum -{ - ENROLLEE, - MEDIATOR, - ENROLLER, -} DeviceRole; - -/** -* On-boarding connection to create Adhoc network. -*/ -typedef enum -{ - SOFTAP, - BLE, -} OBConnection; - typedef enum { ES_ERROR = -1, @@ -197,7 +174,7 @@ typedef enum /** * Default state of the device */ - ES_STATE_INIT = 1, + ES_STATE_INIT = 0, /** * Status indicating successful cnnection to target network @@ -218,14 +195,19 @@ typedef enum * Status indicating failure registeration to cloud */ ES_STATE_REGISTRRED_FAIL_TO_CLOUD -} ESEnrolleeState; +} ESEnrolleeState, ProvStatus; typedef enum { /** + * Init Error Code + */ + ES_ERRCODE_NO_ERROR = 0, + + /** * Error Code that given WiFi's SSID is not found */ - ES_ERRCODE_SSID_NOT_FOUND = 1, + ES_ERRCODE_SSID_NOT_FOUND, /** * Error Code that given WiFi's Password is wrong @@ -250,111 +232,11 @@ typedef enum /** * Error Code that Unknown error occured */ - ES_ERRCODE_UNKNOWN, - - /** - * No Error Occured - */ - ES_ERRCODE_NONE = 999 + ES_ERRCODE_UNKNOWN } ESErrorCode; -typedef struct -{ - // Address of remote server - OCDevAddr * addr; - // Indicates adaptor type on which the response was received - OCConnectivityType connType; -} EasySetupDeviceInfo; - -/** - * Provosioning Status - */ -typedef enum -{ - ES_NEED_PROVISION = 1, - ES_CONNECTED_TO_ENROLLER, - ES_CONNECTED_FAIL_TO_ENROLLER, - ES_REGISTERED_TO_CLOUD, - ES_REGISTERED_FAIL_TO_CLOUD -} EasySetupState, ProvStatus; - -/** - * Response from queries to remote servers. - */ -typedef struct -{ - // EasySetup Status - EasySetupState provStatus; - // EasySetup Device Info - EasySetupDeviceInfo provDeviceInfo; -} EasySetupInfo, ProvisioningInfo; - -/** - * @brief Network information of the Enroller - */ -typedef union -{ - /** - * @brief BT Mac Information - */ - struct - { - char btMacAddress[NET_MACADDR_SIZE]; /**< BT mac address **/ - } BT; - - /** - * @brief LE MAC Information - */ - struct - { - char leMacAddress[NET_MACADDR_SIZE]; /**< BLE mac address **/ - } LE; - - /** - * @brief IP Information - */ - struct - { - char ssid[MAX_SSIDLEN]; /**< ssid of the Enroller**/ - char pwd[MAX_CREDLEN]; /**< pwd of the Enroller**/ - } WIFI; -} ProvData; - -/** - * @brief Network Information - */ -typedef struct -{ - ProvData provData; /**< Enroller Network Info**/ - OCConnectivityType connType; /**< Connectivity Type**/ -} ProvConfig; - -/** - * Client applications implement this callback to consume responses received from Servers. - */ -typedef void (*OCProvisioningStatusCB)(EasySetupInfo *easySetupInfo); - -/** - * @brief This structure represent configuration information to create wifi onboarding SoftAP or connection. -*/ - - -// Note : Below structure is not currently used but added for future purpose. -typedef struct { - char ssid[MAX_SSIDLEN]; /**< ssid of the onboarding Adhoc Wifi network**/ - char pwd[MAX_CREDLEN]; /**< pwd of the onboarding Adhoc wifi network**/ - bool isSecured; /**< Secure connection**/ -}WiFiOnboardingConfig; - -/** - * @brief This structure represent onboarding connection instance. -*/ -typedef struct { - /*Actual use of ipAddress is for unicast discovery, but also used to identify the Enrollee device as of now, - device identification should be based on DeviceID in next release.*/ - char ipAddress[IPV4_ADDR_SIZE]; /**< IP Address of the Enrollee **/ - bool isSecured; /**< Secure connection**/ -}WiFiOnboadingConnection; - +#ifdef __cplusplus +} +#endif #endif //ES_COMMON_H_ diff --git a/service/easy-setup/mediator/SConscript b/service/easy-setup/mediator/SConscript index 57de9b6..060afac 100644 --- a/service/easy-setup/mediator/SConscript +++ b/service/easy-setup/mediator/SConscript @@ -25,9 +25,6 @@ Import('env') target_os = env.get('TARGET_OS') -# Build easy-setup Mediator C SDK -#SConscript('csdk/SConscript') - # Build easy-setup Mediator Rich [C++] SDK SConscript('richsdk/SConscript') diff --git a/service/easy-setup/mediator/csdk/inc/provisioning.h b/service/easy-setup/mediator/csdk/inc/provisioning.h deleted file mode 100755 index f9a6d61..0000000 --- a/service/easy-setup/mediator/csdk/inc/provisioning.h +++ /dev/null @@ -1,119 +0,0 @@ -//****************************************************************** -// -// 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. -// -//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - -#ifndef __ES_PROVISIONING_HANDLER_H_ -#define __ES_PROVISIONING_HANDLER_H_ - -#include "octypes.h" - -#include "logger.h" -#include "ocstack.h" -#include "escommon.h" - -//----------------------------------------------------------------------------- -// Defines -//----------------------------------------------------------------------------- -#define EASY_SETUP_DEFAULT_CONTEXT_VALUE 0x99 - -/** - * List of methods that can be inititated from the client - */ -OCStackResult InitProvisioningHandler(); - -OCStackResult TerminateProvisioningHandler(); - -OCStackResult GetProvisioningStatus(OCQualityOfService qos, const char *query, - const OCDevAddr *destination); - -OCStackResult StartProvisioningProcess(const ProvConfig *netInfo, - WiFiOnboadingConnection *onboardConn, OCProvisioningStatusCB provisioningStatusCallback, - char *findResQuery); - -void StopProvisioningProcess(); - -/** - * Internal worker functions. - */ -OCStackResult TriggerNetworkConnection(OCQualityOfService qos, const char *query, - const char *resUri, OCDevAddr *destination, int /*pauseBeforeStart*/); - -OCStackApplicationResult TriggerNetworkConnectionResponse(void *ctx, OCDoHandle handle, - OCClientResponse *clientResponse); - -OCStackApplicationResult ProvisionEnrolleeResponse(void *ctx, OCDoHandle handle, - OCClientResponse *clientResponse); - -OCStackResult ProvisionEnrollee(OCQualityOfService qos, const char *query, const char *resUri, - OCDevAddr *destination, int pauseBeforeStart); - -OCStackApplicationResult GetProvisioningStatusResponse(void *ctx, OCDoHandle handle, - OCClientResponse *clientResponse); - -OCStackResult InvokeOCDoResource(const char *query, OCMethod method, const OCDevAddr *dest, - OCQualityOfService qos, OCClientResponseHandler cb, OCRepPayload *payload, - OCHeaderOption *options, uint8_t numOptions); - -OCStackApplicationResult FindProvisioningResourceResponse(void *ctx, OCDoHandle handle, - OCClientResponse *clientResponse); - -void *FindProvisioningResource(void *data); - -ProvisioningInfo *PrepareProvisioingStatusCB(OCClientResponse *clientResponse, - ProvStatus provStatus); - -/** - * Internal Util functions. - */ -void LogProvisioningResponse(OCRepPayloadValue * val); - -bool ConfigEnrolleeObject(const ProvConfig *netInfo, WiFiOnboadingConnection *onboardConn); - -bool ClearMemory(); - -void SuccessCallback(OCClientResponse * clientResponse); - -void ErrorCallback(ProvStatus status); - -bool ValidateEnrolleeResponse(OCClientResponse * clientResponse); - -bool ValidateFindResourceResponse(OCClientResponse * clientResponse); - -bool ValidateEnrolleeBasicResponse(OCClientResponse * clientResponse); - -ProvisioningInfo *GetCallbackObjectOnSuccess(OCClientResponse *clientResponse, - ProvStatus provStatus); - -ProvisioningInfo *GetCallbackObjectOnError(ProvStatus status); - -ProvisioningInfo *CreateCallBackObject(); - -bool ResetProgress(); - -bool SetProgress(OCProvisioningStatusCB provisioningStatusCallback); - -bool InProgress(); - -bool ValidateEasySetupParams(const ProvConfig *netInfo, WiFiOnboadingConnection *onboardConn, - OCProvisioningStatusCB provisioningStatusCallback); - -bool IsSetupStopped(); - -#endif //__ES_PROVISIONING_HANDLER_H_ - diff --git a/service/easy-setup/mediator/csdk/inc/provisioningapi.h b/service/easy-setup/mediator/csdk/inc/provisioningapi.h deleted file mode 100755 index 5fa60fa..0000000 --- a/service/easy-setup/mediator/csdk/inc/provisioningapi.h +++ /dev/null @@ -1,56 +0,0 @@ -//****************************************************************** -// -// 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. -// -//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= -#ifndef __EASYSETUP_MGR_H_ -#define __EASYSETUP_MGR_H_ - -#include - -#include "logger.h" -#include "ocstack.h" -#include "octypes.h" -#include "escommon.h" - -#include "provisioning.h" - -//----------------------------------------------------------------------------- -// Defines -//----------------------------------------------------------------------------- - -#ifdef __cplusplus -extern "C" -{ -#endif - OCStackResult InitProvProcess(); - - OCStackResult ResetProvProcess(); - - OCStackResult RegisterCallback(OCProvisioningStatusCB provisioningStatusCallback); - - void UnRegisterCallback(); - - OCStackResult StartProvisioning(const ProvConfig *netInfo, - WiFiOnboadingConnection *onboardConn); - - OCStackResult StopProvisioning(OCConnectivityType connectivityType); -#ifdef __cplusplus -} -#endif - -#endif diff --git a/service/easy-setup/mediator/csdk/src/provisioning.cpp b/service/easy-setup/mediator/csdk/src/provisioning.cpp deleted file mode 100755 index ac6ac5b..0000000 --- a/service/easy-setup/mediator/csdk/src/provisioning.cpp +++ /dev/null @@ -1,577 +0,0 @@ -//****************************************************************** -// -// 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. -// -//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - -#include "provisioning.h" - -//Standard includes -#include -#include -#include -#include -#include -#include - -//EasySetup include files -#include "ocpayload.h" -#include "escommon.h" - -// External includes -#include "logger.h" -#include "oic_malloc.h" -#include "oic_string.h" - -#define ES_PROV_TAG "EASY_SETUP_PROVISIONING" - -bool gProvisioningCondFlag = false; - -static ProvConfig *gProvConfig; -static WiFiOnboadingConnection *gOnboardConn; -static char gSzFindResourceQueryUri[64] = -{ 0 }; - -/** - * @var cbData - * @brief Callback for providing provisioning status callback to application - */ -static OCProvisioningStatusCB cbData = NULL; - -/** - * Utility function for error callback. - */ -void ErrorCallback(ProvStatus status) -{ - ProvisioningInfo *provInfo = GetCallbackObjectOnError(status); - if(cbData != NULL) - { - cbData(provInfo); - } -} - -/** - * Functions implementing the exposed APIs. - */ -OCStackResult InitProvisioningHandler() -{ - OCStackResult ret = OC_STACK_ERROR; - /* Initialize OCStack*/ - if (OCInit(NULL, 0, OC_CLIENT) != OC_STACK_OK) - { - OIC_LOG(ERROR, ES_PROV_TAG, "OCStack init error"); - return ret; - } - - return OC_STACK_OK; -} - -OCStackResult StartProvisioningProcess(const ProvConfig *netInfo, - WiFiOnboadingConnection *onboardConn, OCProvisioningStatusCB provisioningStatusCallback, - char *findResQuery) -{ - - if (findResQuery != NULL) - { - OICStrcpy(gSzFindResourceQueryUri, sizeof(gSzFindResourceQueryUri) - 1, findResQuery); - } - else - { - OIC_LOG(ERROR, ES_PROV_TAG, PCF("Find resource query is NULL")); - goto Error; - } - - pthread_t thread_handle; - - if (!ValidateEasySetupParams(netInfo, onboardConn, provisioningStatusCallback)) - { - goto Error; - } - - if (!SetProgress(provisioningStatusCallback)) - { - // Device provisioning session is running already. - OIC_LOG(INFO, ES_PROV_TAG, PCF("Device provisioning session is running already")); - goto Error; - } - - if (!ConfigEnrolleeObject(netInfo, onboardConn)) - { - goto Error; - } - - if (pthread_create(&thread_handle, NULL, FindProvisioningResource, NULL)) - { - goto Error; - - } - - pthread_join(thread_handle, NULL); - - return OC_STACK_OK; - - Error: - { - ErrorCallback(DEVICE_NOT_PROVISIONED); - ClearMemory(); - return OC_STACK_ERROR; - } - -} - -void StopProvisioningProcess() -{ - ResetProgress(); -} - -OCStackResult TerminateProvisioningHandler() -{ - OCStackResult ret = OC_STACK_ERROR; - if (OCStop() != OC_STACK_OK) - { - OIC_LOG(ERROR, ES_PROV_TAG, "OCStack stop error"); - } - - gProvisioningCondFlag = true; - ResetProgress(); - - ret = OC_STACK_OK; - return ret; -} - -OCStackApplicationResult TriggerNetworkConnectionResponse(void* /*ctx*/, OCDoHandle /*handle*/, - OCClientResponse *clientResponse) -{ - OIC_LOG_V(DEBUG, ES_PROV_TAG, "INSIDE TriggerNetworkConnectionResponse"); - - // If user stopped the process then return from this function; - if (IsSetupStopped()) - { - ErrorCallback(DEVICE_NOT_PROVISIONED); - ClearMemory(); - return OC_STACK_DELETE_TRANSACTION; - } - - if (!ValidateEnrolleeBasicResponse(clientResponse)) - { - ErrorCallback(DEVICE_NOT_PROVISIONED); - return OC_STACK_DELETE_TRANSACTION; - } - - SuccessCallback(clientResponse); - return OC_STACK_KEEP_TRANSACTION; -} - -OCStackResult TriggerNetworkConnection(OCQualityOfService qos, const char *query, - const char *resUri, OCDevAddr *destination, int /*pauseBeforeStart*/) -{ - OIC_LOG_V(INFO, ES_PROV_TAG, "Inside TriggerNetworkConnection"); - - OCRepPayload *payload = OCRepPayloadCreate(); - - OCRepPayloadSetUri(payload, resUri); - OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_TR, ES_PS_TRIGGER_CONNECTION); - - OIC_LOG_V(DEBUG, ES_PROV_TAG, "Triggering network connection from Mediator"); - - OCStackResult ret = InvokeOCDoResource(query, OC_REST_POST, destination, qos, - TriggerNetworkConnectionResponse, payload, NULL, 0); - - return ret; -} - - - -bool ClearMemory() -{ - - OIC_LOG(DEBUG, ES_PROV_TAG, "thread_pool_add_task of FindProvisioningResource failed"); - OICFree(gProvConfig); - OICFree(gOnboardConn); - - return true; - -} - -bool ConfigEnrolleeObject(const ProvConfig *netInfo, WiFiOnboadingConnection *connection) -{ - - //Copy Network Provisioning Information - gProvConfig = (ProvConfig *) OICCalloc(1, sizeof(ProvConfig)); - gOnboardConn = (WiFiOnboadingConnection *) OICCalloc(1, sizeof(WiFiOnboadingConnection)); - - if (gProvConfig == NULL) - { - OIC_LOG(ERROR, ES_PROV_TAG, "Invalid input.."); - return false; - } - - if (gOnboardConn == NULL) - { - OIC_LOG(ERROR, ES_PROV_TAG, "Invalid input.."); - return false; - } - - memcpy(gProvConfig, netInfo, sizeof(ProvConfig)); - memcpy(gOnboardConn, connection, sizeof(WiFiOnboadingConnection)); - - OIC_LOG_V(DEBUG, ES_PROV_TAG, "Network Provisioning Info. SSID = %s", - gProvConfig->provData.WIFI.ssid); - - OIC_LOG_V(DEBUG, ES_PROV_TAG, "Network Provisioning Info. PWD = %s", - gProvConfig->provData.WIFI.pwd); - - return true; - -} - -void LogProvisioningResponse(OCRepPayloadValue * val) -{ - - switch (val->type) - { - case OCREP_PROP_NULL: - OIC_LOG_V(DEBUG, ES_PROV_TAG, "\t\t%s: NULL", val->name); - break; - case OCREP_PROP_INT: - OIC_LOG_V(DEBUG, ES_PROV_TAG, "\t\t%s(int):%lld", val->name, val->i); - break; - case OCREP_PROP_DOUBLE: - OIC_LOG_V(DEBUG, ES_PROV_TAG, "\t\t%s(double):%f", val->name, val->d); - break; - case OCREP_PROP_BOOL: - OIC_LOG_V(DEBUG, ES_PROV_TAG, "\t\t%s(bool):%s", val->name, val->b ? "true" : "false"); - break; - case OCREP_PROP_STRING: - OIC_LOG_V(DEBUG, ES_PROV_TAG, "\t\t%s(string):%s", val->name, val->str); - break; - case OCREP_PROP_OBJECT: - // Note: Only prints the URI (if available), to print further, you'll - // need to dig into the object better! - OIC_LOG_V(DEBUG, ES_PROV_TAG, "\t\t%s(OCRep):%s", val->name, val->obj->uri); - break; - case OCREP_PROP_ARRAY: - switch (val->arr.type) - { - case OCREP_PROP_INT: - OIC_LOG_V(DEBUG, ES_PROV_TAG, "\t\t%s(int array):%zu x %zu x %zu", - val->name, - val->arr.dimensions[0], val->arr.dimensions[1], - val->arr.dimensions[2]); - break; - case OCREP_PROP_DOUBLE: - OIC_LOG_V(DEBUG, ES_PROV_TAG, "\t\t%s(double array):%zu x %zu x %zu", - val->name, - val->arr.dimensions[0], val->arr.dimensions[1], - val->arr.dimensions[2]); - break; - case OCREP_PROP_BOOL: - OIC_LOG_V(DEBUG, ES_PROV_TAG, "\t\t%s(bool array):%zu x %zu x %zu", - val->name, - val->arr.dimensions[0], val->arr.dimensions[1], - val->arr.dimensions[2]); - break; - case OCREP_PROP_STRING: - OIC_LOG_V(DEBUG, ES_PROV_TAG, "\t\t%s(string array):%zu x %zu x %zu", - val->name, - val->arr.dimensions[0], val->arr.dimensions[1], - val->arr.dimensions[2]); - break; - case OCREP_PROP_OBJECT: - OIC_LOG_V(DEBUG, ES_PROV_TAG, "\t\t%s(OCRep array):%zu x %zu x %zu", - val->name, - val->arr.dimensions[0], val->arr.dimensions[1], - val->arr.dimensions[2]); - break; - default: - break; - } - break; - default: - break; - } -} - -OCStackResult FindNetworkResource() -{ - OCStackResult ret = OC_STACK_ERROR; - if (OCStop() != OC_STACK_OK) - { - OIC_LOG(ERROR, ES_PROV_TAG, "OCStack stop error"); - } - - return ret; -} - -ProvisioningInfo *PrepareProvisioingStatusCB(OCClientResponse *clientResponse, - ProvStatus provStatus) -{ - - ProvisioningInfo *provInfo = (ProvisioningInfo *) OICCalloc(1, sizeof(ProvisioningInfo)); - - if (provInfo == NULL) - { - OIC_LOG_V(ERROR, ES_PROV_TAG, "Failed to allocate memory"); - return NULL; - } - - OCDevAddr *devAddr = (OCDevAddr *) OICCalloc(1, sizeof(OCDevAddr)); - - if (devAddr == NULL) - { - OIC_LOG_V(ERROR, ES_PROV_TAG, "Failed to allocate memory"); - OICFree(provInfo); - return NULL; - } - - OICStrcpy(devAddr->addr, sizeof(devAddr->addr), clientResponse->addr->addr); - - devAddr->port = clientResponse->addr->port; - - provInfo->provDeviceInfo.addr = devAddr; - - provInfo->provStatus = provStatus; - - return provInfo; -} - -bool InProgress() -{ - - // It means already Easy Setup provisioning session is going on. - if (NULL != cbData) - { - OIC_LOG(ERROR, ES_PROV_TAG, "Easy setup session is already in progress"); - return true; - } - - return false; -} - -bool SetProgress(OCProvisioningStatusCB provisioningStatusCallback) -{ - - if (InProgress()) - return false; - - cbData = provisioningStatusCallback; - - return true; -} - -bool ResetProgress() -{ - - cbData = NULL; - return true; -} - -ProvisioningInfo *CreateCallBackObject() -{ - - ProvisioningInfo *provInfo = (ProvisioningInfo *) OICCalloc(1, sizeof(ProvisioningInfo)); - - if (provInfo == NULL) - { - OIC_LOG_V(ERROR, ES_PROV_TAG, "Failed to allocate memory"); - return NULL; - } - - OCDevAddr *devAddr = (OCDevAddr *) OICCalloc(1, sizeof(OCDevAddr)); - - if (devAddr == NULL) - { - OIC_LOG_V(ERROR, ES_PROV_TAG, "Failed to allocate memory"); - OICFree(provInfo); - return NULL; - } - - provInfo->provDeviceInfo.addr = devAddr; - - return provInfo; - -} - -ProvisioningInfo *GetCallbackObjectOnError(ProvStatus status) -{ - - ProvisioningInfo *provInfo = CreateCallBackObject(); - OICStrcpy(provInfo->provDeviceInfo.addr->addr, sizeof(provInfo->provDeviceInfo.addr->addr), - gOnboardConn->ipAddress); - - provInfo->provDeviceInfo.addr->port = IP_PORT; - provInfo->provStatus = status; - return provInfo; -} - -ProvisioningInfo *GetCallbackObjectOnSuccess(OCClientResponse *clientResponse, - ProvStatus provStatus) -{ - ProvisioningInfo *provInfo = CreateCallBackObject(); - OICStrcpy(provInfo->provDeviceInfo.addr->addr, sizeof(provInfo->provDeviceInfo.addr->addr), - clientResponse->addr->addr); - - provInfo->provDeviceInfo.addr->port = clientResponse->addr->port; - provInfo->provStatus = provStatus; - return provInfo; -} - -bool ValidateFindResourceResponse(OCClientResponse * clientResponse) -{ - if (!(clientResponse) || !(clientResponse->payload)) - { - OIC_LOG_V(INFO, ES_PROV_TAG, "Received Null clientResponse"); - return false; - } - - if (clientResponse->payload->type != PAYLOAD_TYPE_DISCOVERY) - { - OIC_LOG_V(DEBUG, ES_PROV_TAG, "Payload is not discovery type"); - return false; - } - - return true; -} - -bool ValidateEnrolleeResponse(OCClientResponse * clientResponse) -{ - if (!(clientResponse) || !(clientResponse->payload)) - { - OIC_LOG_V(INFO, ES_PROV_TAG, "Received Null clientResponse"); - return false; - } - - if (clientResponse->payload->type != PAYLOAD_TYPE_REPRESENTATION) - { - OIC_LOG_V(DEBUG, ES_PROV_TAG, "Incoming payload is not a representation"); - return false; - } - - // If flow reachese here means no error condition hit. - return true; -} - -bool ValidateEnrolleeBasicResponse(OCClientResponse * clientResponse) -{ - if (!clientResponse) - { - OIC_LOG_V(INFO, ES_PROV_TAG, "Received Null clientResponse"); - return false; - } - - if(clientResponse->result != OC_STACK_OK) - { - OIC_LOG_V(INFO, ES_PROV_TAG, "Received error response"); - return false; - } - - // If flow reaches, then there no error condition hit. - return true; -} - - -void SuccessCallback(OCClientResponse * clientResponse) -{ - ProvisioningInfo *provInfo = GetCallbackObjectOnSuccess(clientResponse, DEVICE_PROVISIONED); - if(cbData != NULL) - { - cbData(provInfo); - } -} - -void* FindProvisioningResource(void* /*data*/) -{ - - // If user stopped the process before thread get scheduled then check and return from this function; - if (IsSetupStopped()) - { - ErrorCallback(DEVICE_NOT_PROVISIONED); - ClearMemory(); - return NULL; - } - - OCStackResult ret = OC_STACK_ERROR; - - OIC_LOG_V(DEBUG, ES_PROV_TAG, "szFindResourceQueryUri = %s", gSzFindResourceQueryUri); - - OCCallbackData ocCBData; - - ocCBData.cb = FindProvisioningResourceResponse; - ocCBData.context = (void *) EASY_SETUP_DEFAULT_CONTEXT_VALUE; - ocCBData.cd = NULL; - - ret = OCDoResource(NULL, OC_REST_DISCOVER, gSzFindResourceQueryUri, NULL, NULL, - gProvConfig->connType, OC_LOW_QOS, &ocCBData, NULL, 0); - - if (ret != OC_STACK_OK) - { - ErrorCallback(DEVICE_NOT_PROVISIONED); - ClearMemory(); - } - - return NULL; -} - -OCStackResult InvokeOCDoResource(const char *query, OCMethod method, const OCDevAddr *dest, - OCQualityOfService qos, OCClientResponseHandler cb, OCRepPayload *payload, - OCHeaderOption *options, uint8_t numOptions) -{ - OCStackResult ret; - OCCallbackData cbData; - - cbData.cb = cb; - cbData.context = (void *) EASY_SETUP_DEFAULT_CONTEXT_VALUE; - cbData.cd = NULL; - - ret = OCDoResource(NULL, method, query, dest, (OCPayload *) payload, gProvConfig->connType, qos, - &cbData, options, numOptions); - - if (ret != OC_STACK_OK) - { - OIC_LOG_V(ERROR, ES_PROV_TAG, "OCDoResource returns error %d with method %d", ret, method); - } - - return ret; -} - -OCStackResult ProvisionEnrollee(OCQualityOfService qos, const char *query, const char *resUri, - OCDevAddr *destination, int pauseBeforeStart) -{ - - // This sleep is required in case of BLE provisioning due to packet drop issue. - OIC_LOG_V(INFO, ES_PROV_TAG, "Sleeping for %d seconds", pauseBeforeStart); - sleep(pauseBeforeStart); - OIC_LOG_V(INFO, ES_PROV_TAG, "\n\nExecuting ProvisionEnrollee%s", __func__); - - OCRepPayload *payload = OCRepPayloadCreate(); - - OCRepPayloadSetUri(payload, resUri); - OCRepPayloadSetPropString(payload, OC_RSRVD_ES_TNN, gProvConfig->provData.WIFI.ssid); - OCRepPayloadSetPropString(payload, OC_RSRVD_ES_CD, gProvConfig->provData.WIFI.pwd); - - OIC_LOG_V(DEBUG, ES_PROV_TAG, "OCPayload ready for ProvisionEnrollee"); - - OCStackResult ret = InvokeOCDoResource(query, OC_REST_POST, destination, qos, - ProvisionEnrolleeResponse, payload, NULL, 0); - - return ret; -} - -bool IsSetupStopped() -{ - return (cbData == NULL) ? true : false; -} diff --git a/service/easy-setup/mediator/csdk/src/provisioningapi.cpp b/service/easy-setup/mediator/csdk/src/provisioningapi.cpp deleted file mode 100755 index 988921e..0000000 --- a/service/easy-setup/mediator/csdk/src/provisioningapi.cpp +++ /dev/null @@ -1,127 +0,0 @@ -//****************************************************************** -// -// 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. -// -//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= -#include -#include -#include -#include -#include -#include -#include - -#include "provisioningapi.h" -#include "oic_string.h" - -#define ES_PROV_ADAP_TAG "ES_PROVISIONING_ADAPTER" - -//Use ipv4addr for both InitDiscovery and InitDeviceDiscovery -char ipv4addr[IPV4_ADDR_SIZE] = -{ 0 }; - -#ifdef REMOTE_ARDUINO_ENROLEE -//Arduino Enrollee needs mediator application provide IP and port55555 which is specific -// to Arduino WiFi enrollee -static const char * UNICAST_PROVISIONING_QUERY = "coap://%s:%d/oic/res?rt=oic.r.prov"; -#else -static const char * UNICAST_PROVISIONING_QUERY = "/oic/res?rt=oic.r.prov"; -#endif - -volatile static OCProvisioningStatusCB cbData = NULL; - -OCStackResult InitProvProcess() -{ - - OCStackResult result = OC_STACK_ERROR; - - if (InitProvisioningHandler() == OC_STACK_OK) - { - result = OC_STACK_OK; - OIC_LOG(DEBUG, ES_PROV_ADAP_TAG, "InitProvisioningHandler returned Success"); - } - else - { - result = OC_STACK_ERROR; - OIC_LOG_V(ERROR, ES_PROV_ADAP_TAG, "InitProvisioningHandler returned error = %d", - result); - } - - return result; -} - -OCStackResult ResetProvProcess() -{ - return TerminateProvisioningHandler(); -} - -OCStackResult RegisterCallback(OCProvisioningStatusCB provisioningStatusCallback) -{ - OCStackResult result = OC_STACK_OK; - - if (provisioningStatusCallback != NULL) - { - cbData = provisioningStatusCallback; - } - else - { - result = OC_STACK_ERROR; - OIC_LOG(ERROR, ES_PROV_ADAP_TAG, "provisioningStatusCallback is NULL"); - } - - return result; -} - -void UnRegisterCallback() -{ - if (cbData) - { - cbData = NULL; - } -} - -OCStackResult StartProvisioning(const ProvConfig *provConfig, WiFiOnboadingConnection *onboardConn) -{ - - char findQuery[64] = - { 0 }; - - if (provConfig == NULL || onboardConn == NULL) - { - return OC_STACK_ERROR; - } - -#ifdef REMOTE_ARDUINO_ENROLEE - //Arduino Enrollee needs mediator application provide IP and port55555 which is specific - // to Arduino WiFi enrollee - snprintf(findQuery, sizeof(findQuery) - 1, UNICAST_PROVISIONING_QUERY, - onboardConn->ipAddress, IP_PORT); -#else - OICStrcpy(findQuery, sizeof(findQuery) - 1, UNICAST_PROVISIONING_QUERY); -#endif - - return StartProvisioningProcess(provConfig, onboardConn, cbData, findQuery); -} - -OCStackResult StopProvisioning(OCConnectivityType /*connectivityType*/) -{ - OCStackResult result = OC_STACK_OK; - - StopProvisioningProcess(); - - return result; -} diff --git a/service/easy-setup/mediator/csdk/src/wifiprovisioning.cpp b/service/easy-setup/mediator/csdk/src/wifiprovisioning.cpp deleted file mode 100755 index d8d40fe..0000000 --- a/service/easy-setup/mediator/csdk/src/wifiprovisioning.cpp +++ /dev/null @@ -1,274 +0,0 @@ -//****************************************************************** -// -// 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. -// -//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - -// NOTE : Keeping Wifi provisioning in this file to have adaptability while doing OOPs refactoring - -#include "provisioning.h" - -//Standard includes -#include -#include -#include -#include -#include -#include - -//EasySetup include files -#include "ocpayload.h" -#include "escommon.h" - -// External includes -#include "logger.h" -#include "oic_string.h" - -#define ES_WIFI_PROV_TAG "ES_WIFI_PROVISIONING" - -static const char * UNICAST_PROV_STATUS_QUERY = "coap://%s:%d%s"; - -OCStackApplicationResult ProvisionEnrolleeResponse(void* /*ctx*/, OCDoHandle /*handle*/, - OCClientResponse *clientResponse) -{ - OIC_LOG_V(DEBUG, ES_WIFI_PROV_TAG, "Inside ProvisionEnrolleeResponse"); - - // If user stopped the process then return from this function; - if (IsSetupStopped()) - { - ErrorCallback(DEVICE_NOT_PROVISIONED); - ClearMemory(); - return OC_STACK_DELETE_TRANSACTION; - } - - if (!ValidateEnrolleeResponse(clientResponse)) - { - ErrorCallback(DEVICE_NOT_PROVISIONED); - return OC_STACK_DELETE_TRANSACTION; - } - - char query[OIC_STRING_MAX_VALUE] = - { '\0' }; - char resUri[MAX_URI_LENGTH] = - { '\0' }; - - OIC_LOG_V(DEBUG, ES_WIFI_PROV_TAG, "Resource URI = %s", clientResponse->resourceUri); - - OICStrcpy(resUri, sizeof(resUri), clientResponse->resourceUri); - -#ifdef REMOTE_ARDUINO_ENROLEE - //Arduino Enrollee needs mediator application provide IP and port55555 which is specific - // to Arduino WiFi enrollee - // REMOTE_ARDUINO_ENROLEE has to be defined if Mediator is being tested with Arduino - snprintf(query, sizeof(query), UNICAST_PROV_STATUS_QUERY, clientResponse->addr->addr, IP_PORT, - resUri); -#else - snprintf(query, sizeof(query), UNICAST_PROV_STATUS_QUERY, clientResponse->addr->addr, - clientResponse->addr->port, resUri); -#endif - - if (TriggerNetworkConnection(OC_HIGH_QOS, query, OC_RSRVD_ES_URI_PROV, clientResponse->addr, 0) - != OC_STACK_OK) - { - OIC_LOG(INFO, ES_WIFI_PROV_TAG, "GetProvisioningStatusResponse received NULL clientResponse"); - - ErrorCallback(DEVICE_NOT_PROVISIONED); - ClearMemory(); - } - - return OC_STACK_DELETE_TRANSACTION; -} - -OCStackApplicationResult GetProvisioningStatusResponse(void* /*ctx*/, OCDoHandle /*handle*/, - OCClientResponse *clientResponse) -{ - // If user stopped the process then return from this function; - if (IsSetupStopped()) - { - ErrorCallback(DEVICE_NOT_PROVISIONED); - ClearMemory(); - return OC_STACK_DELETE_TRANSACTION; - } - - if (!ValidateEnrolleeResponse(clientResponse)) - { - ErrorCallback(DEVICE_NOT_PROVISIONED); - ClearMemory(); - return OC_STACK_DELETE_TRANSACTION; - } - - OCRepPayload *input = (OCRepPayload *) (clientResponse->payload); - - char resUri[MAX_URI_LENGTH] = { '\0' }; - - OIC_LOG_V(DEBUG, ES_WIFI_PROV_TAG, "resUri = %s", clientResponse->resourceUri); - - OICStrcpy(resUri, sizeof(resUri), clientResponse->resourceUri); - - while (input) - { - int64_t ps; - if (OCRepPayloadGetPropInt(input, OC_RSRVD_ES_PS, &ps)) - { - - if (ps == ES_PS_NEED_PROVISIONING) - { - input = input->next; - continue; - } - else - { - ErrorCallback(DEVICE_NOT_PROVISIONED); - ClearMemory(); - return OC_STACK_DELETE_TRANSACTION; - } - } - - LogProvisioningResponse(input->values); - input = input->next; - } - - char query[OIC_STRING_MAX_VALUE] = - { '\0' }; - -#ifdef REMOTE_ARDUINO_ENROLEE - //Arduino Enrollee needs mediator application provide IP and port55555 which is specific - // to Arduino WiFi enrollee - // REMOTE_ARDUINO_ENROLEE has to be defined if Mediator is being tested with Arduino - snprintf(query, sizeof(query), UNICAST_PROV_STATUS_QUERY, clientResponse->addr->addr, IP_PORT, - resUri); -#else - snprintf(query, sizeof(query), UNICAST_PROV_STATUS_QUERY, clientResponse->addr->addr, - clientResponse->addr->port, resUri); -#endif - - if (ProvisionEnrollee(OC_HIGH_QOS, query, OC_RSRVD_ES_URI_PROV, clientResponse->addr, 0) - != OC_STACK_OK) - { - OIC_LOG(INFO, ES_WIFI_PROV_TAG, "GetProvisioningStatusResponse received NULL clientResponse"); - - ErrorCallback(DEVICE_NOT_PROVISIONED); - ClearMemory(); - return OC_STACK_DELETE_TRANSACTION; - } - - return OC_STACK_KEEP_TRANSACTION; - -} - -OCStackResult GetProvisioningStatus(OCQualityOfService qos, const char *query, - const OCDevAddr *destination) -{ - OCStackResult ret = OC_STACK_ERROR; - OCHeaderOption options[MAX_HEADER_OPTIONS]; - - OIC_LOG(DEBUG, ES_WIFI_PROV_TAG, "Inside GetProvisioningStatus"); - - uint8_t option0[] = - { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; - uint8_t option1[] = - { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 }; - memset(options, 0, sizeof(OCHeaderOption) * MAX_HEADER_OPTIONS); - options[0].protocolID = OC_COAP_ID; - options[0].optionID = 2048; - memcpy(options[0].optionData, option0, sizeof(option0)); - options[0].optionLength = 10; - options[1].protocolID = OC_COAP_ID; - options[1].optionID = 3000; - memcpy(options[1].optionData, option1, sizeof(option1)); - options[1].optionLength = 10; - - ret = InvokeOCDoResource(query, OC_REST_GET, destination, qos, GetProvisioningStatusResponse, - NULL, options, 2); - return ret; -} - -// This is a function called back when a device is discovered -OCStackApplicationResult FindProvisioningResourceResponse(void* /*ctx*/, OCDoHandle /*handle*/, - OCClientResponse *clientResponse) -{ - - OIC_LOG_V(INFO, ES_WIFI_PROV_TAG, "Entering FindProvisioningResourceResponse %s", - clientResponse->devAddr.addr); - - // If user stopped the process then return from this function; - if (IsSetupStopped()) - { - ErrorCallback(DEVICE_NOT_PROVISIONED); - ClearMemory(); - return OC_STACK_DELETE_TRANSACTION; - } - - if (!ValidateFindResourceResponse(clientResponse)) - { - ErrorCallback(DEVICE_NOT_PROVISIONED); - return OC_STACK_DELETE_TRANSACTION; - } - - char szQueryUri[64] = - { 0 }; - - OCDiscoveryPayload *discoveryPayload = (OCDiscoveryPayload *) (clientResponse->payload); - - OIC_LOG_V(DEBUG, ES_WIFI_PROV_TAG, "resUri = %s", discoveryPayload->resources->uri); - -#ifdef REMOTE_ARDUINO_ENROLEE - //Arduino Enrollee needs mediator application provide IP and port55555 which is specific - // to Arduino WiFi enrollee - // REMOTE_ARDUINO_ENROLEE has to be defined if Mediator is being tested with Arduino - snprintf(szQueryUri, sizeof(szQueryUri), UNICAST_PROV_STATUS_QUERY, - clientResponse->addr->addr, - IP_PORT, - discoveryPayload->resources->uri); -#else - snprintf(szQueryUri, sizeof(szQueryUri), UNICAST_PROV_STATUS_QUERY, - clientResponse->devAddr.addr, clientResponse->devAddr.port, - discoveryPayload->resources->uri); -#endif - - OIC_LOG_V(DEBUG, ES_WIFI_PROV_TAG, "query before GetProvisioningStatus call = %s", szQueryUri); - - if (GetProvisioningStatus(OC_HIGH_QOS, szQueryUri, &clientResponse->devAddr) != OC_STACK_OK) - { - ErrorCallback(DEVICE_NOT_PROVISIONED); - return OC_STACK_DELETE_TRANSACTION; - } - - return OC_STACK_KEEP_TRANSACTION; - -} - -bool ValidateEasySetupParams(const ProvConfig */*netInfo*/, WiFiOnboadingConnection *onboardConn, - OCProvisioningStatusCB provisioningStatusCallback) -{ - - if (onboardConn == NULL || strlen(onboardConn->ipAddress) == 0) - { - OIC_LOG(ERROR, ES_WIFI_PROV_TAG, "Request URI is NULL"); - return false; - } - - if (provisioningStatusCallback == NULL) - { - OIC_LOG(ERROR, ES_WIFI_PROV_TAG, "ProvisioningStatusCallback is NULL"); - return false; - } - - return true; - -} - diff --git a/service/easy-setup/mediator/csdk/unittests/MediatorCSDKTest.cpp b/service/easy-setup/mediator/csdk/unittests/MediatorCSDKTest.cpp deleted file mode 100644 index e0aded4..0000000 --- a/service/easy-setup/mediator/csdk/unittests/MediatorCSDKTest.cpp +++ /dev/null @@ -1,124 +0,0 @@ -//****************************************************************** -// -// 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 "UnitTestHelper.h" - -#include "ocstack.h" -#include "OCPlatform.h" -#include "OCApi.h" -#include "oic_string.h" -#include "logger.h" - -#include "provisioningapi.h" -#include "provisioning.h" -#include "escommon.h" - -#include -#include -#include -#include -#include - -class MediatorCSDKTest: public TestWithMock -{ - - protected: - void SetUp() - { - TestWithMock::SetUp(); - } - - void TearDown() - { - TestWithMock::TearDown(); - } - -}; - -//callbacks -void OCProvisioningStatusCallback(EasySetupInfo *easySetupInfo) -{ - (void) easySetupInfo; -} - -/* Test cases for prov_adapter*/ - -//InitProvProcess -TEST_F(MediatorCSDKTest, testInitProvProcess) -{ - OCStackResult result = InitProvProcess(); - ASSERT_EQ(OC_STACK_OK, result); -} - -//ResetProvProcess -TEST_F(MediatorCSDKTest, testResetProvProcess) -{ - OCStackResult result = ResetProvProcess(); - ASSERT_EQ(OC_STACK_OK, result); -} - -//RegisterCallback [positive] -TEST_F(MediatorCSDKTest, testRegisterCallback) -{ - OCStackResult result = RegisterCallback(&OCProvisioningStatusCallback); - ASSERT_EQ(OC_STACK_OK, result); -} - -//RegisterCallback [Negative] -TEST_F(MediatorCSDKTest, testRegisterCallbackNegative) -{ - OCStackResult result = RegisterCallback(NULL); - ASSERT_EQ(OC_STACK_ERROR, result); -} - -//StartProvisioning [positive] -TEST_F(MediatorCSDKTest, testStartProvisioning) -{ - ProvConfig provConfig; - WiFiOnboadingConnection onboardConn; - - strncpy(onboardConn.ipAddress, "1.1.1.1", IPV4_ADDR_SIZE - 1); - - strncpy(provConfig.provData.WIFI.ssid, "testAP", NET_WIFI_SSID_SIZE - 1); - strncpy(provConfig.provData.WIFI.pwd, "test@123", NET_WIFI_PWD_SIZE - 1); - provConfig.connType = CT_ADAPTER_IP; - - //API Call - OCStackResult result = StartProvisioning(&provConfig, &onboardConn); - - ASSERT_EQ(OC_STACK_OK, result); -} - -//StartProvisioning [Negative] -TEST_F(MediatorCSDKTest, testStartProvisioningNegative) -{ - OCStackResult result = StartProvisioning(NULL, NULL); - ASSERT_EQ(OC_STACK_ERROR, result); -} - -//StopProvisioning -TEST_F(MediatorCSDKTest, testStopProvisioning) -{ - // This API always return success - OCStackResult result = StopProvisioning(CT_ADAPTER_IP); - ASSERT_EQ(OC_STACK_OK, result); -} - - diff --git a/service/easy-setup/mediator/csdk/unittests/UnitTestHelper.h b/service/easy-setup/mediator/csdk/unittests/UnitTestHelper.h deleted file mode 100644 index 2bf7424..0000000 --- a/service/easy-setup/mediator/csdk/unittests/UnitTestHelper.h +++ /dev/null @@ -1,48 +0,0 @@ -//****************************************************************** -// -// 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 COMMON_UTILS_UNITTESTHELPER_H -#define COMMON_UTILS_UNITTESTHELPER_H - -#include -#include - -class TestWithMock: public testing::Test -{ - public: - MockRepository mocks; - - protected: - virtual ~TestWithMock() noexcept(noexcept(std::declval().~Test())) {} - - virtual void TearDown() - { - try - { - mocks.VerifyAll(); - } - catch (...) - { - mocks.reset(); - throw; - } - } -}; -#endif // COMMON_UTILS_UNITTESTHELPER_H diff --git a/service/easy-setup/mediator/richsdk/inc/ESRichCommon.h b/service/easy-setup/mediator/richsdk/inc/ESRichCommon.h index 7acf8b1..27089d4 100755 --- a/service/easy-setup/mediator/richsdk/inc/ESRichCommon.h +++ b/service/easy-setup/mediator/richsdk/inc/ESRichCommon.h @@ -37,44 +37,35 @@ using namespace std; #define IP_PORT 55555 /** - * Attributes used to form a proper easysetup conforming JSON message. + * Attributes used to form a proper easysetup conforming JSON message */ -#define OC_RSRVD_ES_PROVSTATUS "ps" -#define OC_RSRVD_ES_TRIGGER "tr" -#define OC_RSRVD_ES_SSID "tnn" -#define OC_RSRVD_ES_CRED "cd" -#define OC_RSRVD_ES_SUPPORTEDWIFIMODE "swmt" -#define OC_RSRVD_ES_SUPPORTEDWIFIFREQ "swf" -#define OC_RSRVD_ES_AUTHTYPE "wat" -#define OC_RSRVD_ES_ENCTYPE "wet" -#define OC_RSRVD_ES_AUTHCODE "ac" -#define OC_RSRVD_ES_AUTHPROVIDER "apn" -#define OC_RSRVD_ES_CISERVER "cisurl" -#define OC_RSRVD_ES_DEVNAME "dn" -#define OC_RSRVD_ES_LANGUAGE "lang" -#define OC_RSRVD_ES_COUNTRY "cont" -#define OC_RSRVD_ES_TNT "tnt" -#define OC_RSRVD_ES_ANT "ant" +#define OC_RSRVD_ES_PROVSTATUS "ps" +#define OC_RSRVD_ES_LAST_ERRORCODE "lec" +#define OC_RSRVD_ES_LINKS "links" +#define OC_RSRVD_ES_SUPPORTEDWIFIMODE "swmt" +#define OC_RSRVD_ES_SUPPORTEDWIFIFREQ "swf" +#define OC_RSRVD_ES_SSID "tnn" +#define OC_RSRVD_ES_CRED "cd" +#define OC_RSRVD_ES_AUTHTYPE "wat" +#define OC_RSRVD_ES_ENCTYPE "wet" +#define OC_RSRVD_ES_AUTHCODE "ac" +#define OC_RSRVD_ES_AUTHPROVIDER "apn" +#define OC_RSRVD_ES_CISERVER "cisurl" +#define OC_RSRVD_ES_DEVNAME "dn" +#define OC_RSRVD_ES_LANGUAGE "lang" +#define OC_RSRVD_ES_COUNTRY "ctry" /** - * Easysetup defined resoruce types and uris. + * Easysetup defined resoruce types and uris */ -#define OC_RSRVD_ES_PROV_RES_TYPE "ocf.r.prov" -#define OC_RSRVD_ES_URI_PROV "/.well-known/ocf/prov" -#define OC_RSRVD_ES_RES_TYPE_WIFI "ocf.r.wifi" -#define OC_RSRVD_ES_URI_WIFI "/.well-known/ocf/prov/wifi" +#define OC_RSRVD_ES_RES_TYPE_PROV "ocf.r.prov" +#define OC_RSRVD_ES_URI_PROV "/.well-known/ocf/prov" +#define OC_RSRVD_ES_RES_TYPE_WIFI "ocf.r.wifi" +#define OC_RSRVD_ES_URI_WIFI "/.well-known/ocf/prov/wifi" #define OC_RSRVD_ES_RES_TYPE_CLOUDSERVER "ocf.r.cloudserver" -#define OC_RSRVD_ES_URI_CLOUDSERVER "/.well-known/ocf/prov/cloudserver" -#define OC_RSRVD_ES_RES_TYPE_DEVCONF "ocf.r.devconf" -#define OC_RSRVD_ES_URI_DEVCONF "/.well-known/ocf/prov/devconf" - -/** - * @brief Defines for Provisioning status accepted values - */ -#define ES_PS_NEED_PROVISIONING 1 -#define ES_PS_PROVISIONING_COMPLETED 2 -#define ES_PS_TRIGGER_INIT_VALUE 0 -#define ES_PS_TRIGGER_CONNECTION 1 +#define OC_RSRVD_ES_URI_CLOUDSERVER "/.well-known/ocf/prov/cloudserver" +#define OC_RSRVD_ES_RES_TYPE_DEVCONF "ocf.r.devconf" +#define OC_RSRVD_ES_URI_DEVCONF "/.well-known/ocf/prov/devconf" #ifndef WITH_ARDUINO namespace OIC @@ -108,7 +99,7 @@ namespace OIC } WIFI_AUTHTYPE; /** - * @brief WIFI ecnrytion type of the Enroller + * @brief WIFI encryption type of the Enroller */ typedef enum { @@ -245,7 +236,7 @@ namespace OIC return m_netInfo; } - const bool isCloudable() const + bool isCloudable() const { return m_cloudable; } @@ -326,32 +317,32 @@ namespace OIC }; /** - * Callback function definition for providing Enrollee security status . + * Callback function definition for providing Enrollee security status */ typedef function< void(shared_ptr< RequestPropertyDataStatus >) > RequestPropertyDataStatusCb; /** - * Callback function definition for providing Enrollee security status . + * Callback function definition for providing Enrollee security status */ typedef function< void(shared_ptr< DataProvisioningStatus >) > DataProvStatusCb; /** - * Callback function definition for providing Enrollee security status . + * Callback function definition for providing Enrollee security status */ typedef function< void(shared_ptr< CloudProvisioningStatus >) > CloudProvStatusCb; /** - * Callback function definition for providing Enrollee security status . + * Callback function definition for providing Enrollee security status */ typedef function< void(shared_ptr) > SecurityProvStatusCb; /** - * Callback definition to be invoked when the security stack expects a pin from application. + * Callback definition to be invoked when the security stack expects a pin from application */ typedef function< void(string&) > SecurityPinCb; /** - * Callback definition to be invoked when the stack expects a db path. + * Callback definition to be invoked when the stack expects a db path */ typedef function< void(string&) > SecProvisioningDbPathCb; diff --git a/service/easy-setup/mediator/richsdk/inc/EnrolleeResource.h b/service/easy-setup/mediator/richsdk/inc/EnrolleeResource.h index 07dce66..29dec59 100755 --- a/service/easy-setup/mediator/richsdk/inc/EnrolleeResource.h +++ b/service/easy-setup/mediator/richsdk/inc/EnrolleeResource.h @@ -101,8 +101,6 @@ namespace OIC private: void onRequestPropertyDataResponse(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode); - void getProvStatusResponse(const HeaderOptions& headerOptions, const OCRepresentation& rep, - const int eCode); void checkProvInformationCb(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode); PropertyData parsePropertyDataFromRepresentation(const OCRepresentation& rep); diff --git a/service/easy-setup/mediator/richsdk/src/CloudResource.cpp b/service/easy-setup/mediator/richsdk/src/CloudResource.cpp index ac15b59..c51a648 100755 --- a/service/easy-setup/mediator/richsdk/src/CloudResource.cpp +++ b/service/easy-setup/mediator/richsdk/src/CloudResource.cpp @@ -57,7 +57,7 @@ namespace OIC OIC_LOG_V (DEBUG, ES_CLOUD_RES_TAG, "provisionEnrollee : ciServer - %s", (cloudProvInfo.ciServer).c_str()); - m_ocResource->post(OC_RSRVD_ES_PROV_RES_TYPE, BATCH_INTERFACE, + m_ocResource->post(OC_RSRVD_ES_RES_TYPE_PROV, BATCH_INTERFACE, provisioningRepresentation, QueryParamsMap(), std::function< void(const HeaderOptions& headerOptions, @@ -77,7 +77,7 @@ namespace OIC { ESResult result = ESResult::ES_ERROR; - OIC_LOG(DEBUG, ES_CLOUD_RES_TAG,"onCloudProvResponse : onCloudProvResponse is failed "); + OIC_LOG(DEBUG, ES_CLOUD_RES_TAG,"onCloudProvResponse : onCloudProvResponse is failed"); if (eCode == OCStackResult::OC_STACK_UNAUTHORIZED_REQ) { @@ -91,7 +91,7 @@ namespace OIC } else { - OIC_LOG(DEBUG, ES_CLOUD_RES_TAG,"onCloudProvResponse : onCloudProvResponse is success "); + OIC_LOG(DEBUG, ES_CLOUD_RES_TAG,"onCloudProvResponse : onCloudProvResponse is success"); std::shared_ptr< CloudProvisioningStatus > provStatus = std::make_shared< CloudProvisioningStatus >(ESResult::ES_OK, ESCloudProvState::ES_CLOUD_PROVISIONING_SUCCESS); m_cloudProvStatusCb(provStatus); @@ -100,7 +100,7 @@ namespace OIC void CloudResource::registerCloudProvisioningStatusCallback(CloudProvStatusCb callback) { - OIC_LOG_V (DEBUG, ES_CLOUD_RES_TAG, "Enter registerCloudProvisioningStatusCallback."); + OIC_LOG_V (DEBUG, ES_CLOUD_RES_TAG, "Enter registerCloudProvisioningStatusCallback"); m_cloudProvStatusCb = callback; } } diff --git a/service/easy-setup/mediator/richsdk/src/EnrolleeResource.cpp b/service/easy-setup/mediator/richsdk/src/EnrolleeResource.cpp index a79e93f..a06eebb 100755 --- a/service/easy-setup/mediator/richsdk/src/EnrolleeResource.cpp +++ b/service/easy-setup/mediator/richsdk/src/EnrolleeResource.cpp @@ -54,13 +54,9 @@ namespace OIC m_dataProvStatusCb(provStatus); return; } - // int ps = -1; - // rep.getValue(OC_RSRVD_ES_PROVSTATUS, ps); - // OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "checkProvInformationCb : ps - %d", ps); OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, - "checkProvInformationCb : Provisioning is success. " - "Now trigger network connection "); + "checkProvInformationCb : Provisioning is success. "); std::shared_ptr< DataProvisioningStatus > provStatus = std::make_shared< DataProvisioningStatus >(ESResult::ES_OK, ESDataProvState::ES_PROVISIONING_SUCCESS); @@ -91,7 +87,6 @@ namespace OIC RequestPropertyDataStatus >(result, propertyData ); m_RequestPropertyDataStatusCb(requestPropertyDataStatus); } - else { PropertyData propertyData = parsePropertyDataFromRepresentation(rep); @@ -102,83 +97,6 @@ namespace OIC } } - void EnrolleeResource::getProvStatusResponse(const HeaderOptions& /*headerOptions*/, - const OCRepresentation& rep, const int eCode) - { - OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : %s, eCode = %d", - rep.getUri().c_str(), - eCode); - - if (eCode != 0) - { - ESResult result = ESResult::ES_ERROR; - - OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,"getProvStatusResponse : Provisioning is failed "); - - if (eCode == OCStackResult::OC_STACK_UNAUTHORIZED_REQ) - { - OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, - "Mediator is unauthorized from Enrollee."); - result = ESResult::ES_UNAUTHORIZED; - } - std::shared_ptr< DataProvisioningStatus > provStatus = std::make_shared< - DataProvisioningStatus >(result, ESDataProvState::ES_PROVISIONING_ERROR); - m_dataProvStatusCb(provStatus); - - return; - } - - int ps = -1; - - rep.getValue(OC_RSRVD_ES_PROVSTATUS, ps); - - OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : ps - %d", - ps); - - //if (ps == ES_PS_NEED_PROVISIONING) //Indicates the need for provisioning - if (ps == 0) //Indicates the need for provisioning - { - OCRepresentation provisioningRepresentation; - - provisioningRepresentation.setValue(OC_RSRVD_ES_SSID, m_dataProvInfo.WIFI.ssid); - provisioningRepresentation.setValue(OC_RSRVD_ES_CRED, m_dataProvInfo.WIFI.pwd); - provisioningRepresentation.setValue(OC_RSRVD_ES_AUTHTYPE, m_dataProvInfo.WIFI.authtype); - provisioningRepresentation.setValue(OC_RSRVD_ES_ENCTYPE, m_dataProvInfo.WIFI.enctype); - provisioningRepresentation.setValue(OC_RSRVD_ES_LANGUAGE, m_dataProvInfo.Device.language); - provisioningRepresentation.setValue(OC_RSRVD_ES_COUNTRY, m_dataProvInfo.Device.country); - - OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : ssid - %s", - (m_dataProvInfo.WIFI.ssid).c_str()); - OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : pwd - %s", - (m_dataProvInfo.WIFI.pwd).c_str()); - OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : authtype - %d", - m_dataProvInfo.WIFI.authtype); - OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : enctype - %d", - m_dataProvInfo.WIFI.enctype); - OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : language - %s", - (m_dataProvInfo.Device.language).c_str()); - OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : country - %s", - (m_dataProvInfo.Device.country).c_str()); - - m_ocResource->post(OC_RSRVD_ES_PROV_RES_TYPE, BATCH_INTERFACE, - provisioningRepresentation, QueryParamsMap(), - std::function< - void(const HeaderOptions& headerOptions, - const OCRepresentation& rep, const int eCode) >( - std::bind(&EnrolleeResource::checkProvInformationCb, this, - std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3))); - } - else if (ps == ES_PS_PROVISIONING_COMPLETED) //Indicates that provisioning is completed - { - OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, - "getProvStatusResponse : Provisioning is successful"); - std::shared_ptr< DataProvisioningStatus > provStatus = std::make_shared< - DataProvisioningStatus >(ESResult::ES_OK, ESDataProvState::ES_PROVISIONED_ALREADY); - m_dataProvStatusCb(provStatus); - } - } - void EnrolleeResource::registerRequestPropertyDataStatusCallback(RequestPropertyDataStatusCb callback) { m_RequestPropertyDataStatusCb = callback; @@ -231,28 +149,36 @@ namespace OIC m_dataProvInfo = dataProvInfo; OC::QueryParamsMap query; - OC::OCRepresentation rep; - - std::function< OCStackResult(void) > getProvisioingStatus = [&] - { return m_ocResource->get(m_ocResource->getResourceTypes().at(0), - m_ocResource->getResourceInterfaces().at(0), query, - std::function< - void(const HeaderOptions& headerOptions, const OCRepresentation& rep, - const int eCode) >( - std::bind(&EnrolleeResource::getProvStatusResponse, this, - std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3))); - }; - - OCStackResult result = getProvisioingStatus(); - - if (result != OCStackResult::OC_STACK_OK) - { - std::shared_ptr< DataProvisioningStatus > provStatus = std::make_shared< - DataProvisioningStatus >(ESResult::ES_ERROR, ESDataProvState::ES_PROVISIONING_ERROR); - m_dataProvStatusCb(provStatus); - return; - } + OC::OCRepresentation provisioningRepresentation; + + provisioningRepresentation.setValue(OC_RSRVD_ES_SSID, m_dataProvInfo.WIFI.ssid); + provisioningRepresentation.setValue(OC_RSRVD_ES_CRED, m_dataProvInfo.WIFI.pwd); + provisioningRepresentation.setValue(OC_RSRVD_ES_AUTHTYPE, m_dataProvInfo.WIFI.authtype); + provisioningRepresentation.setValue(OC_RSRVD_ES_ENCTYPE, m_dataProvInfo.WIFI.enctype); + provisioningRepresentation.setValue(OC_RSRVD_ES_LANGUAGE, m_dataProvInfo.Device.language); + provisioningRepresentation.setValue(OC_RSRVD_ES_COUNTRY, m_dataProvInfo.Device.country); + + OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : ssid - %s", + (m_dataProvInfo.WIFI.ssid).c_str()); + OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : pwd - %s", + (m_dataProvInfo.WIFI.pwd).c_str()); + OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : authtype - %d", + m_dataProvInfo.WIFI.authtype); + OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : enctype - %d", + m_dataProvInfo.WIFI.enctype); + OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : language - %s", + (m_dataProvInfo.Device.language).c_str()); + OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : country - %s", + (m_dataProvInfo.Device.country).c_str()); + + m_ocResource->post(OC_RSRVD_ES_RES_TYPE_PROV, BATCH_INTERFACE, + provisioningRepresentation, QueryParamsMap(), + std::function< + void(const HeaderOptions& headerOptions, + const OCRepresentation& rep, const int eCode) >( + std::bind(&EnrolleeResource::checkProvInformationCb, this, + std::placeholders::_1, std::placeholders::_2, + std::placeholders::_3))); } void EnrolleeResource::unprovisionEnrollee() diff --git a/service/easy-setup/mediator/richsdk/src/RemoteEnrollee.cpp b/service/easy-setup/mediator/richsdk/src/RemoteEnrollee.cpp index f9481c8..b2da78f 100755 --- a/service/easy-setup/mediator/richsdk/src/RemoteEnrollee.cpp +++ b/service/easy-setup/mediator/richsdk/src/RemoteEnrollee.cpp @@ -248,7 +248,7 @@ namespace OIC std::string query(""); query.append(ES_BASE_RES_URI); query.append("?rt="); - query.append(OC_RSRVD_ES_PROV_RES_TYPE); + query.append(OC_RSRVD_ES_RES_TYPE_PROV); OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "query = %s", query.c_str()); @@ -312,7 +312,6 @@ namespace OIC void RemoteEnrollee::startSecurityProvisioning(SecurityProvStatusCb callback) { #ifdef __WITH_DTLS__ - m_securityProvStatusCb = callback; SecurityProvStatusCb securityProvStatusCb = std::bind( @@ -341,6 +340,7 @@ namespace OIC return ; } #else + (void) callback; OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Mediator is unsecured."); std::shared_ptr< SecProvisioningStatus > securityProvisioningStatus = @@ -440,8 +440,6 @@ namespace OIC { OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Enter startCloudProvisioning"); - ESResult result = ES_ERROR; - if(!callback) { throw ESInvalidParameterException("Callback is empty"); diff --git a/service/easy-setup/sampleapp/mediator/linux/richsdk_sample/mediator_cpp.cpp b/service/easy-setup/sampleapp/mediator/linux/richsdk_sample/mediator_cpp.cpp index 289c07f..810a8ab 100755 --- a/service/easy-setup/sampleapp/mediator/linux/richsdk_sample/mediator_cpp.cpp +++ b/service/easy-setup/sampleapp/mediator/linux/richsdk_sample/mediator_cpp.cpp @@ -69,7 +69,6 @@ void printPropertyData(PropertyData propData) cout << "===========================================" << endl; DeviceConfig devConfig = propData.getDevConf(); NetworkInfo netInfo = propData.getNetInfo(); - bool cloudable = propData.isCloudable(); cout << "\tDeviceConfig.id : " << devConfig.id << endl; cout << "\tDeviceConfig.name : " << devConfig.name << endl; -- 2.7.4