From: Jay Sharma Date: Fri, 19 Feb 2016 06:56:30 +0000 (+0530) Subject: Refactored structures and APIs for medaitor & Enrollee X-Git-Tag: 1.2.0+RC1~597^2^2~11 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a67aad358e5b2e26c3f20c78042c918964de33e0;p=platform%2Fupstream%2Fiotivity.git Refactored structures and APIs for medaitor & Enrollee - Review Comment fixes Change-Id: I232243863131ecd89c0a84f0a5dd16f05f650008 Signed-off-by: Hemant Mahsky Signed-off-by: Jay Sharma Reviewed-on: https://gerrit.iotivity.org/gerrit/5023 Tested-by: jenkins-iotivity Reviewed-by: Madan Lanka --- diff --git a/service/easy-setup/inc/escommon.h b/service/easy-setup/inc/escommon.h index 1798ade..43191c9 100755 --- a/service/easy-setup/inc/escommon.h +++ b/service/easy-setup/inc/escommon.h @@ -210,30 +210,45 @@ typedef union */ struct { - char ipAddress[IPV4_ADDR_SIZE]; /**< IP Address of the Enroller**/ char ssid[NET_WIFI_SSID_SIZE]; /**< ssid of the Enroller**/ char pwd[NET_WIFI_PWD_SIZE]; /**< pwd of the Enroller**/ } WIFI; -} EnrolleeInfo; - +} ProvData; /** * @brief Network Information */ typedef struct { - EnrolleeInfo netAddressInfo; /**< Enroller Network Info**/ + ProvData provData; /**< Enroller Network Info**/ OCConnectivityType connType; /**< Connectivity Type**/ - bool isSecured; /**< Secure connection**/ - // TODO : Ideally isSecured should be renamed to needSecuredEasysetup. - // To provide backward compatibility to v1.0 release, a new variable is being added. - // If isSecured is not used by other applications, isSecured will be depricated. - bool needSecuredEasysetup; /**< Need of secure ownership transfer during easysetup**/ -} EnrolleeNWProvInfo; +} 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[NET_WIFI_SSID_SIZE]; /**< ssid of the onboarding Adhoc Wifi network**/ + char pwd[NET_WIFI_PWD_SIZE]; /**< 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; + #endif //ES_COMMON_H_ diff --git a/service/easy-setup/mediator/csdk/inc/prov_adapter.h b/service/easy-setup/mediator/csdk/inc/prov_adapter.h index 77923c8..c80e0af 100644 --- a/service/easy-setup/mediator/csdk/inc/prov_adapter.h +++ b/service/easy-setup/mediator/csdk/inc/prov_adapter.h @@ -47,7 +47,7 @@ OCStackResult RegisterCallback( void UnRegisterCallback(); -OCStackResult StartProvisioning(const EnrolleeNWProvInfo *netInfo); +OCStackResult StartProvisioning(const ProvConfig *netInfo, WiFiOnboadingConnection *onboardConn); OCStackResult StopProvisioning(OCConnectivityType connectivityType); diff --git a/service/easy-setup/mediator/csdk/inc/provisioning.h b/service/easy-setup/mediator/csdk/inc/provisioning.h index 9993537..31dd601 100644 --- a/service/easy-setup/mediator/csdk/inc/provisioning.h +++ b/service/easy-setup/mediator/csdk/inc/provisioning.h @@ -64,7 +64,7 @@ OCStackResult InvokeOCDoResource(const char *query, OCMethod method, const OCDev OCStackResult GetProvisioningStatus(OCQualityOfService qos, const char *query, const OCDevAddr *destination); -OCStackResult StartProvisioningProcess(const EnrolleeNWProvInfo *netInfo, +OCStackResult StartProvisioningProcess(const ProvConfig *netInfo,WiFiOnboadingConnection *onboardConn, OCProvisioningStatusCB provisioningStatusCallback, char *findResQuery); @@ -82,7 +82,7 @@ ProvisioningInfo *PrepareProvisioingStatusCB(OCClientResponse *clientResponse, void LogProvisioningResponse(OCRepPayloadValue * val); -bool ConfigEnrolleeObject(const EnrolleeNWProvInfo *netInfo); +bool ConfigEnrolleeObject(const ProvConfig *netInfo, WiFiOnboadingConnection *onboardConn); bool ClearMemory(); @@ -107,7 +107,7 @@ bool SetProgress(OCProvisioningStatusCB provisioningStatusCallback); bool InProgress(); -bool ValidateEasySetupParams(const EnrolleeNWProvInfo *netInfo, +bool ValidateEasySetupParams(const ProvConfig *netInfo,WiFiOnboadingConnection *onboardConn, OCProvisioningStatusCB provisioningStatusCallback); bool IsSetupStopped(); diff --git a/service/easy-setup/mediator/csdk/src/prov_adapter.cpp b/service/easy-setup/mediator/csdk/src/prov_adapter.cpp index 6c94fb9..878e5e9 100644 --- a/service/easy-setup/mediator/csdk/src/prov_adapter.cpp +++ b/service/easy-setup/mediator/csdk/src/prov_adapter.cpp @@ -85,7 +85,7 @@ void UnRegisterCallback() { } } -OCStackResult StartProvisioning(const EnrolleeNWProvInfo *netInfo) { +OCStackResult StartProvisioning(const ProvConfig *provConfig, WiFiOnboadingConnection *onboardConn) { char findQuery[64] = {0}; @@ -93,12 +93,12 @@ OCStackResult StartProvisioning(const EnrolleeNWProvInfo *netInfo) { //Arduino Enrollee needs mediator application provide IP and port55555 which is specific // to Arduino WiFi enrollee snprintf(findQuery, sizeof(findQuery) - 1, UNICAST_PROVISIONING_QUERY, - netInfo->netAddressInfo.WIFI.ipAddress, IP_PORT); + onboardConn->ipAddress, IP_PORT); #else OICStrcpy(findQuery, sizeof(findQuery)-1, UNICAST_PROVISIONING_QUERY); #endif - return StartProvisioningProcess(netInfo, cbData, findQuery); + return StartProvisioningProcess(provConfig, onboardConn, cbData, findQuery); } OCStackResult StopProvisioning(OCConnectivityType /*connectivityType*/) { diff --git a/service/easy-setup/mediator/csdk/src/provisioning.cpp b/service/easy-setup/mediator/csdk/src/provisioning.cpp index 49ecfa6..7b0abff 100644 --- a/service/easy-setup/mediator/csdk/src/provisioning.cpp +++ b/service/easy-setup/mediator/csdk/src/provisioning.cpp @@ -40,11 +40,11 @@ #define ES_PROV_TAG "EASY_SETUP_PROVISIONING" -bool g_provisioningCondFlag = false; +bool gProvisioningCondFlag = false; -static EnrolleeNWProvInfo *netProvInfo; - -char szFindResourceQueryUri[64] = {0}; +static ProvConfig *gProvConfig; +static WiFiOnboadingConnection *gOnboardConn; +static char gSzFindResourceQueryUri[64] = {0}; /** * @var cbData @@ -85,14 +85,14 @@ OCStackResult TerminateProvisioningHandler() { OIC_LOG(ERROR, ES_PROV_TAG, "OCStack stop error"); } - g_provisioningCondFlag = true; + gProvisioningCondFlag = true; ret = OC_STACK_OK; return ret; } void *listeningFunc(void* /*data*/) { - while (!g_provisioningCondFlag) { + while (!gProvisioningCondFlag) { OCStackResult result; result = OCProcess(); @@ -146,7 +146,7 @@ OCStackApplicationResult ProvisionEnrolleeResponse(void* /*ctx*/, OCDoHandle /*h } if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_TNN, &tnn)) { - if (!strcmp(tnn, netProvInfo->netAddressInfo.WIFI.ssid)) { + if (!strcmp(tnn, gProvConfig->provData.WIFI.ssid)) { OIC_LOG_V(DEBUG, ES_PROV_TAG, "SSID is proper"); input = input->next; continue; @@ -158,7 +158,7 @@ OCStackApplicationResult ProvisionEnrolleeResponse(void* /*ctx*/, OCDoHandle /*h } if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_CD, &cd)) { - if (!strcmp(cd, netProvInfo->netAddressInfo.WIFI.pwd)) { + if (!strcmp(cd, gProvConfig->provData.WIFI.pwd)) { OIC_LOG_V(DEBUG, ES_PROV_TAG, "Password is proper"); input = input->next; continue; @@ -193,13 +193,13 @@ OCStackApplicationResult ProvisionEnrolleeResponse(void* /*ctx*/, OCDoHandle /*h } -OCStackResult StartProvisioningProcess(const EnrolleeNWProvInfo *netInfo, +OCStackResult StartProvisioningProcess(const ProvConfig *netInfo,WiFiOnboadingConnection *onboardConn, OCProvisioningStatusCB provisioningStatusCallback, char *findResQuery) { if(findResQuery != NULL) { - OICStrcpy(szFindResourceQueryUri, sizeof(szFindResourceQueryUri) - 1, findResQuery); + OICStrcpy(gSzFindResourceQueryUri, sizeof(gSzFindResourceQueryUri) - 1, findResQuery); } else { @@ -209,7 +209,7 @@ OCStackResult StartProvisioningProcess(const EnrolleeNWProvInfo *netInfo, pthread_t thread_handle; - if (!ValidateEasySetupParams(netInfo, provisioningStatusCallback)) { + if (!ValidateEasySetupParams(netInfo, onboardConn, provisioningStatusCallback)) { goto Error; } @@ -219,7 +219,7 @@ OCStackResult StartProvisioningProcess(const EnrolleeNWProvInfo *netInfo, goto Error; } - if (!ConfigEnrolleeObject(netInfo)) { + if (!ConfigEnrolleeObject(netInfo, onboardConn)) { goto Error; } @@ -250,28 +250,37 @@ void StopProvisioningProcess() { bool ClearMemory() { OIC_LOG(DEBUG, ES_PROV_TAG, "thread_pool_add_task of FindProvisioningResource failed"); - OICFree(netProvInfo); + OICFree(gProvConfig); + OICFree(gOnboardConn); + return true; } -bool ConfigEnrolleeObject(const EnrolleeNWProvInfo *netInfo) { +bool ConfigEnrolleeObject(const ProvConfig *netInfo, WiFiOnboadingConnection *connection) { //Copy Network Provisioning Information - netProvInfo = (EnrolleeNWProvInfo *) OICCalloc(1, sizeof(EnrolleeNWProvInfo)); + 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 (netProvInfo == NULL) { + if (gOnboardConn == NULL) { OIC_LOG(ERROR, ES_PROV_TAG, "Invalid input.."); return false; } - memcpy(netProvInfo, netInfo, sizeof(EnrolleeNWProvInfo)); + memcpy(gProvConfig, netInfo, sizeof(ProvConfig)); + memcpy(gOnboardConn, connection, sizeof(WiFiOnboadingConnection)); OIC_LOG_V(DEBUG, ES_PROV_TAG, "Network Provisioning Info. SSID = %s", - netProvInfo->netAddressInfo.WIFI.ssid); + gProvConfig->provData.WIFI.ssid); OIC_LOG_V(DEBUG, ES_PROV_TAG, "Network Provisioning Info. PWD = %s", - netProvInfo->netAddressInfo.WIFI.pwd); + gProvConfig->provData.WIFI.pwd); return true; @@ -435,7 +444,7 @@ ProvisioningInfo *GetCallbackObjectOnError(ProvStatus status) { ProvisioningInfo *provInfo = CreateCallBackObject(); OICStrcpy(provInfo->provDeviceInfo.addr->addr, sizeof(provInfo->provDeviceInfo.addr->addr), - netProvInfo->netAddressInfo.WIFI.ipAddress); + gOnboardConn->ipAddress); provInfo->provDeviceInfo.addr->port = IP_PORT; provInfo->provStatus = status; @@ -504,7 +513,7 @@ void* FindProvisioningResource(void* /*data*/) { OCStackResult ret = OC_STACK_ERROR; - OIC_LOG_V(DEBUG, ES_PROV_TAG, "szFindResourceQueryUri = %s", szFindResourceQueryUri); + OIC_LOG_V(DEBUG, ES_PROV_TAG, "szFindResourceQueryUri = %s", gSzFindResourceQueryUri); OCCallbackData ocCBData; @@ -513,8 +522,8 @@ void* FindProvisioningResource(void* /*data*/) { ocCBData.cd = NULL; - ret = OCDoResource(NULL, OC_REST_DISCOVER, szFindResourceQueryUri, NULL, NULL, - netProvInfo->connType, OC_LOW_QOS, + ret = OCDoResource(NULL, OC_REST_DISCOVER, gSzFindResourceQueryUri, NULL, NULL, + gProvConfig->connType, OC_LOW_QOS, &ocCBData, NULL, 0); if (ret != OC_STACK_OK) { @@ -536,7 +545,7 @@ OCStackResult InvokeOCDoResource(const char *query, OCMethod method, const OCDev cbData.context = (void *) EASY_SETUP_DEFAULT_CONTEXT_VALUE; cbData.cd = NULL; - ret = OCDoResource(NULL, method, query, dest, (OCPayload *) payload, netProvInfo->connType, qos, + ret = OCDoResource(NULL, method, query, dest, (OCPayload *) payload, gProvConfig->connType, qos, &cbData, options, numOptions); if (ret != OC_STACK_OK) { @@ -558,8 +567,8 @@ OCStackResult ProvisionEnrollee(OCQualityOfService qos, const char *query, const OCRepPayload *payload = OCRepPayloadCreate(); OCRepPayloadSetUri(payload, resUri); - OCRepPayloadSetPropString(payload, OC_RSRVD_ES_TNN, netProvInfo->netAddressInfo.WIFI.ssid); - OCRepPayloadSetPropString(payload, OC_RSRVD_ES_CD, netProvInfo->netAddressInfo.WIFI.pwd); + 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"); diff --git a/service/easy-setup/mediator/csdk/src/wifi_provisioning.cpp b/service/easy-setup/mediator/csdk/src/wifi_provisioning.cpp index 63471dd..5a056ea 100644 --- a/service/easy-setup/mediator/csdk/src/wifi_provisioning.cpp +++ b/service/easy-setup/mediator/csdk/src/wifi_provisioning.cpp @@ -176,10 +176,11 @@ OCStackApplicationResult FindProvisioningResourceResponse(void* /*ctx*/, } -bool ValidateEasySetupParams(const EnrolleeNWProvInfo *netInfo, +bool ValidateEasySetupParams(const ProvConfig *netInfo,WiFiOnboadingConnection *onboardConn, OCProvisioningStatusCB provisioningStatusCallback) { - if (netInfo == NULL || strlen(netInfo->netAddressInfo.WIFI.ipAddress) == 0) { + + if (onboardConn == NULL || strlen(onboardConn->ipAddress) == 0) { OIC_LOG(ERROR, ES_WIFI_PROV_TAG, "Request URI is NULL"); return false; } diff --git a/service/easy-setup/mediator/richsdk/android/jni/JniEasySetup.cpp b/service/easy-setup/mediator/richsdk/android/jni/JniEasySetup.cpp index 33023d0..a237936 100644 --- a/service/easy-setup/mediator/richsdk/android/jni/JniEasySetup.cpp +++ b/service/easy-setup/mediator/richsdk/android/jni/JniEasySetup.cpp @@ -28,14 +28,15 @@ extern "C" { JNIEXPORT jobject JNICALL Java_org_iotivity_service_easysetup_mediator_EasySetupService_nativeCreateEnrolleeDevice (JNIEnv *env, jobject interfaceClass, jstring ip, jstring ssid, jstring password, - jint connectivityType, jboolean needSecuredEasysetup) + jint connectivityType, jboolean isSecured) { LOGI("JniEasySetup::nativeCreateEnrolleeDevice enter"); std::shared_ptr nativeRemoteEnrollee; jobject jRemoteEnrollee; - EnrolleeNWProvInfo netInfo; + ProvConfig netInfo; + WiFiOnboadingConnection onboardConn; const char *cIp = (env)->GetStringUTFChars(ip, NULL); const char *cSssid = (env)->GetStringUTFChars(ssid, NULL); @@ -46,17 +47,16 @@ Java_org_iotivity_service_easysetup_mediator_EasySetupService_nativeCreateEnroll std::string sPassword(cPassword); netInfo.connType = getOCConnectivityTypeFromInt(connectivityType); - netInfo.isSecured = bool( - needSecuredEasysetup); // may be need to remove, if removed from c++ layer - netInfo.needSecuredEasysetup = bool(needSecuredEasysetup); - OICStrcpy(netInfo.netAddressInfo.WIFI.ipAddress, IPV4_ADDR_SIZE - 1, sIp.c_str()); - OICStrcpy(netInfo.netAddressInfo.WIFI.ssid, NET_WIFI_SSID_SIZE - 1, sSssid.c_str()); - OICStrcpy(netInfo.netAddressInfo.WIFI.pwd, NET_WIFI_PWD_SIZE - 1, sPassword.c_str()); + onboardConn.isSecured = bool(isSecured); + + OICStrcpy(onboardConn.ipAddress, IPV4_ADDR_SIZE - 1, sIp.c_str()); + OICStrcpy(netInfo.provData.WIFI.ssid, NET_WIFI_SSID_SIZE - 1, sSssid.c_str()); + OICStrcpy(netInfo.provData.WIFI.pwd, NET_WIFI_PWD_SIZE - 1, sPassword.c_str()); try { - nativeRemoteEnrollee = EasySetup::getInstance()->createEnrolleeDevice(netInfo); + nativeRemoteEnrollee = EasySetup::getInstance()->createEnrolleeDevice(netInfo,onboardConn); //create the java object jRemoteEnrollee = env->NewObject(g_cls_RemoteEnrollee, g_mid_RemoteEnrollee_ctor); if (!jRemoteEnrollee) diff --git a/service/easy-setup/mediator/richsdk/android/jni/JniEsUtils.h b/service/easy-setup/mediator/richsdk/android/jni/JniEsUtils.h index 5807720..ac66e23 100644 --- a/service/easy-setup/mediator/richsdk/android/jni/JniEsUtils.h +++ b/service/easy-setup/mediator/richsdk/android/jni/JniEsUtils.h @@ -30,12 +30,13 @@ #include #include -#include "escommon.h" -#include "Utility.h" +#include "esrichcommon.h" #include "octypes.h" #include "JniJvm.h" +using namespace OIC::Service; + /** * @brief Throw the Exception to the java layer */ diff --git a/service/easy-setup/mediator/richsdk/android/jni/JniProvisioningStatusListener.h b/service/easy-setup/mediator/richsdk/android/jni/JniProvisioningStatusListener.h index 832a514..af185b2 100644 --- a/service/easy-setup/mediator/richsdk/android/jni/JniProvisioningStatusListener.h +++ b/service/easy-setup/mediator/richsdk/android/jni/JniProvisioningStatusListener.h @@ -28,8 +28,7 @@ #include #include "RemoteEnrollee.h" -#include "escommon.h" -#include "Utility.h" +#include "esrichcommon.h" #include "JniJvm.h" diff --git a/service/easy-setup/mediator/richsdk/android/jni/JniRemoteEnrollee.h b/service/easy-setup/mediator/richsdk/android/jni/JniRemoteEnrollee.h index fafb25f..1a07d4c 100644 --- a/service/easy-setup/mediator/richsdk/android/jni/JniRemoteEnrollee.h +++ b/service/easy-setup/mediator/richsdk/android/jni/JniRemoteEnrollee.h @@ -28,8 +28,7 @@ #define __JNI_ES_REMOTEENROLLEE_H #include "RemoteEnrollee.h" -#include "escommon.h" -#include "Utility.h" +#include "esrichcommon.h" #include "ESException.h" #include "JniJvm.h" diff --git a/service/easy-setup/mediator/richsdk/inc/EasySetup.h b/service/easy-setup/mediator/richsdk/inc/EasySetup.h index 435039e..1b5bd89 100644 --- a/service/easy-setup/mediator/richsdk/inc/EasySetup.h +++ b/service/easy-setup/mediator/richsdk/inc/EasySetup.h @@ -24,8 +24,7 @@ #include #include -#include "escommon.h" -#include "Utility.h" +#include "esrichcommon.h" #include "RemoteEnrollee.h" namespace OIC @@ -60,15 +59,15 @@ namespace OIC * @return Pointer to RemoteEnrollee instance. */ std::shared_ptr createEnrolleeDevice ( - const EnrolleeNWProvInfo& enrolleeNWProvInfo); + const ProvConfig& enrolleeNWProvInfo, const WiFiOnboadingConnection& wifiOnboardingconn); private: EasySetup(); ~EasySetup(); RemoteEnrollee::shared_ptr findDeviceInProvisioningList( - const EnrolleeNWProvInfo& enrolleeNWProvInfo); + const ProvConfig& enrolleeNWProvInfo, const WiFiOnboadingConnection& wifiOnboardingconn); bool addDeviceToProvisioningList(const RemoteEnrollee::shared_ptr remoteEnrollee); - bool deleteDeviceFromProvisioningList (const EnrolleeNWProvInfo& enrolleeNWProvInfo); + bool deleteDeviceFromProvisioningList (const ProvConfig& enrolleeNWProvInfo); std::vector< RemoteEnrollee::shared_ptr > m_activeEnrolleeList; static EasySetup *s_instance; diff --git a/service/easy-setup/mediator/richsdk/inc/EnrolleeSecurity.h b/service/easy-setup/mediator/richsdk/inc/EnrolleeSecurity.h index 66acea5..538f664 100644 --- a/service/easy-setup/mediator/richsdk/inc/EnrolleeSecurity.h +++ b/service/easy-setup/mediator/richsdk/inc/EnrolleeSecurity.h @@ -23,8 +23,7 @@ #include -#include "escommon.h" -#include "Utility.h" +#include "esrichcommon.h" #include "OCProvisioningManager.h" namespace OIC diff --git a/service/easy-setup/mediator/richsdk/inc/RemoteEnrollee.h b/service/easy-setup/mediator/richsdk/inc/RemoteEnrollee.h index 478808a..eb462aa 100644 --- a/service/easy-setup/mediator/richsdk/inc/RemoteEnrollee.h +++ b/service/easy-setup/mediator/richsdk/inc/RemoteEnrollee.h @@ -21,8 +21,7 @@ #ifndef REMOTE_ENROLLEE_H_ #define REMOTE_ENROLLEE_H_ -#include "escommon.h" -#include "Utility.h" +#include "esrichcommon.h" namespace OIC { @@ -46,7 +45,7 @@ namespace OIC * * @throw ESBadRequestException is thrown if the parameters are invalid */ - RemoteEnrollee(const EnrolleeNWProvInfo& enrolleeNWProvInfo) ; + RemoteEnrollee(const ProvConfig& enrolleeNWProvInfo, const WiFiOnboadingConnection& connection) ; ~RemoteEnrollee() = default; @@ -118,9 +117,17 @@ namespace OIC /** * Get the Provisioning information provided for the current Enrollee. * - * @return EnrolleeNWProvInfo Provisioning information provided for the current Enrollee. + * @return ProvConfig Provisioning information provided for the current Enrollee. */ - EnrolleeNWProvInfo& getEnrolleeProvisioningInfo (); + ProvConfig getProvConfig (); + + /** + * Get the Onboarding connection information between Mediator and Enrollee. + * + * @return WiFiOnboadingConnection information between Mediator and Enrollee. + */ + + WiFiOnboadingConnection getOnboardConn(); private: std::shared_ptr< RemoteEnrolleeResource > m_remoteResource; @@ -128,10 +135,12 @@ namespace OIC EnrolleeSecStatusCb m_enrolleeSecStatusCb; SecurityPinCb m_securityPinCb; SecProvisioningDbPathCb m_secProvisioningDbPathCb; - EnrolleeNWProvInfo m_enrolleeNWProvInfo; + ProvConfig m_ProvConfig; + WiFiOnboadingConnection m_wifiOnboardingconn; + std::shared_ptr< EnrolleeSecurity > m_enrolleeSecurity; CurrentESState m_currentESState; - bool m_needSecuredEasysetup; + bool m_isSecured; void provisioningStatusHandler (std::shared_ptr< ProvisioningStatus > provStatus); void easySetupSecurityStatusCallback( diff --git a/service/easy-setup/mediator/richsdk/inc/RemoteEnrolleeResource.h b/service/easy-setup/mediator/richsdk/inc/RemoteEnrolleeResource.h index 351ef92..d9014c7 100644 --- a/service/easy-setup/mediator/richsdk/inc/RemoteEnrolleeResource.h +++ b/service/easy-setup/mediator/richsdk/inc/RemoteEnrolleeResource.h @@ -24,8 +24,7 @@ #include #include -#include "escommon.h" -#include "Utility.h" +#include "esrichcommon.h" #include "OCApi.h" @@ -59,7 +58,7 @@ namespace OIC * * @throw ESBadRequestException is thrown if the parameters are invalid */ - RemoteEnrolleeResource(EnrolleeNWProvInfo enrolleeNWProvInfo); + RemoteEnrolleeResource(ProvConfig enrolleeNWProvInfo, WiFiOnboadingConnection onboardingconn); ~RemoteEnrolleeResource() = default; @@ -106,7 +105,8 @@ namespace OIC std::shared_ptr< OC::OCResource > m_ocResource; std::mutex m_mutex; ProvStatusCb m_provStatusCb; - EnrolleeNWProvInfo m_enrolleeNWProvInfo; + ProvConfig m_ProvConfig; + WiFiOnboadingConnection m_wifiOnboardingconn; bool m_discoveryResponse; void getProvStatusResponse(const HeaderOptions& headerOptions, const OCRepresentation& rep, diff --git a/service/easy-setup/mediator/richsdk/inc/Utility.h b/service/easy-setup/mediator/richsdk/inc/Utility.h deleted file mode 100644 index 2293464..0000000 --- a/service/easy-setup/mediator/richsdk/inc/Utility.h +++ /dev/null @@ -1,154 +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 UTILITY_H_ -#define UTILITY_H_ - -#ifndef WITH_ARDUINO -#include -#endif - -#include "ocstack.h" -#include "octypes.h" - -#ifndef WITH_ARDUINO -namespace OIC -{ - namespace Service - { - typedef enum - { - ES_PROVISIONING_ERROR = -1, - ES_NEED_PROVISIONING, - ES_PROVISIONED_ALREADY, - ES_PROVISIONING_SUCCESS - } ESState; - - typedef enum - { - ES_UNKNOWN = 0, - ES_ONBOARDED, - ES_OWNED, - ES_PROVISIONED - } CurrentESState; - - typedef enum - { - ES_SEC_UNKNOWN = 0, - ES_SEC_OWNED, - ES_SEC_ACL_PROVISIONED, - ES_SEC_CREDS_PROVISIONED - } EnrolleeSecState; - - /** - * Security Provisioning Status - */ - class SecProvisioningResult - { - public: - std::shared_ptr< SecProvisioningResult > shared_ptr; - SecProvisioningResult(std::string deviceUUID, ESResult result) : - m_devUUID(deviceUUID), m_result(result) - { - - } - - std::string getDeviceUUID() - { - return m_devUUID; - } - - ESResult getResult() - { - return m_result; - } - private: - std::string m_devUUID; - ESResult m_result; - }; - - /** - * Callback function definition for providing Enrollee security status . - */ - typedef std::function< void(std::shared_ptr) > EnrolleeSecStatusCb; - - /** - * Callback definition to be invoked when the security stack expects a pin from application. - */ - typedef std::function< void(std::string&) > SecurityPinCb; - - /** - * Callback definition to be invoked when the stack expects a db path. - */ - typedef std::function< void(std::string&) > SecProvisioningDbPathCb; - - class ProvisioningStatus - { - public: - std::shared_ptr< ProvisioningStatus > shared_ptr; - ProvisioningStatus(ESResult result, ESState esState) : - m_result(result), m_esState(esState) - { - - } - - ESResult& getESResult() - { - return m_result; - } - - ESState& getESState() - { - return m_esState; - } - private: - ESResult m_result; - ESState m_esState; - }; - - class EasySetupStatus - { - public: - std::shared_ptr< EasySetupStatus > shared_ptr; - EasySetupStatus(const EasySetupState& easySetupState, - const EnrolleeNWProvInfo& enrolleeNWProvInfo) : - m_easySetupState(easySetupState), m_enrolleeNWProvInfo(enrolleeNWProvInfo) - { - - } - - EnrolleeNWProvInfo& getEasySetupNWProvInfo() - { - return m_enrolleeNWProvInfo; - } - - EasySetupState& getEasySetupState() - { - return m_easySetupState; - } - private: - EasySetupState m_easySetupState; - EnrolleeNWProvInfo m_enrolleeNWProvInfo; - }; - } -} -#endif //WITH_ARDUINO - -#endif //UTILITY_H_ \ No newline at end of file diff --git a/service/easy-setup/mediator/richsdk/inc/esrichcommon.h b/service/easy-setup/mediator/richsdk/inc/esrichcommon.h new file mode 100644 index 0000000..08b9821 --- /dev/null +++ b/service/easy-setup/mediator/richsdk/inc/esrichcommon.h @@ -0,0 +1,379 @@ +//****************************************************************** +// +// 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 ES_COMMON_RICH_H_ +#define ES_COMMON_RICH_H_ + +#include +#include +#ifndef WITH_ARDUINO +#include +#endif + +#include "ocstack.h" +#include "octypes.h" + +using namespace std; + +// Defines +#define OIC_STRING_MAX_VALUE 100 +#define IPV4_ADDR_SIZE 16 +#define IP_PORT 55555 +#define NET_WIFI_SSID_SIZE 100 +#define NET_WIFI_PWD_SIZE 100 + +/** + * @brief Mac address length for BT port + */ +#define NET_MACADDR_SIZE 18 + +/** + * Attributes used to form a proper easysetup conforming JSON message. + */ +#define OC_RSRVD_ES_PS "ps" +#define OC_RSRVD_ES_TNN "tnn" +#define OC_RSRVD_ES_CD "cd" +#define OC_RSRVD_ES_TR "tr" +#define OC_RSRVD_ES_TNT "tnt" +#define OC_RSRVD_ES_ANT "ant" + +/** + * Easysetup defined resoruce types and uris. + */ +#define OC_RSRVD_ES_PROV_RES_TYPE "oic.r.prov" +#define OC_RSRVD_ES_URI_PROV "/oic/prov" +#define OC_RSRVD_ES_URI_NET "/oic/net" + +/** + * @brief Defines for Provisioning status accepted values + */ +#define ES_PS_NEED_PROVISIONING 1 +#define ES_PS_PROVISIONING_COMPLETED 2 + +#ifndef WITH_ARDUINO +namespace OIC +{ + namespace Service + { + + /** + * 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, + ES_OK = 0, + ES_NETWORKFOUND = 1, + ES_NETWORKCONNECTED, + ES_NETWORKNOTCONNECTED, + ES_RESOURCECREATED = 11, + ES_RECVREQOFPROVRES = 21, + ES_RECVREQOFNETRES, + ES_RECVUPDATEOFPROVRES, + ES_RECVTRIGGEROFPROVRES, + } ESResult; + + typedef enum + { + /** + * Default state of the device + */ + ES_INIT_STATE, + + /** + * Device will move to this state once the on boarding begins + */ + ES_ON_BOARDING_STATE, + + /** + * Device will move to this state after successful on-boarding of the device + */ + ES_ON_BOARDED_STATE, + + /** + * Device will move to this state once the on boarding is done + */ + ES_PROVISIONING_STATE, + + /** + * Easy setup process is successful. + */ + ES_PROVISIONED_STATE, + + /** + * This state is arbitrary one, any time device can come into this state + * Device will move to this state if the ownership transfer initiated by the Application + */ + ES_OWNERSHIP_TRANSFERRING_STATE, + + /** + * This state is arbitrary one, any time device can come into this state + * Device will move to this state if the ownership transfer is completed + */ + ES_OWNERSHIP_TRANSFERRED_STATE, + + /** + * This state is arbitrary one, any time device can come into this state + * Device will move to this state once the Application factory reset the device + */ + ES_FACTORY_RESET_STATE, + + /** + * Enrollee moves to this state after connecting to target network + */ + ES_ON_BOARDED_TARGET_NETWORK_STATE, + }EnrolleeState; + + /** + * Provisioning Device Status + */ + typedef struct + { + // Address of remote server + OCDevAddr * addr; + // Indicates adaptor type on which the response was received + OCConnectivityType connType; + } EasySetupDeviceInfo; + + /** + * Provosioning Status + */ + typedef enum + { + DEVICE_PROVISIONED = 0, + DEVICE_NOT_PROVISIONED, + DEVICE_OWNED, + DEVICE_NOT_OWNED + } 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[NET_WIFI_SSID_SIZE]; /**< ssid of the Enroller**/ + char pwd[NET_WIFI_PWD_SIZE]; /**< 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[NET_WIFI_SSID_SIZE]; /**< ssid of the onboarding Adhoc Wifi network**/ + char pwd[NET_WIFI_PWD_SIZE]; /**< 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; + + typedef enum + { + ES_PROVISIONING_ERROR = -1, + ES_NEED_PROVISIONING, + ES_PROVISIONED_ALREADY, + ES_PROVISIONING_SUCCESS + } ESState; + + typedef enum + { + ES_UNKNOWN = 0, + ES_ONBOARDED, + ES_OWNED, + ES_PROVISIONED + } CurrentESState; + + typedef enum + { + ES_SEC_UNKNOWN = 0, + ES_SEC_OWNED, + ES_SEC_ACL_PROVISIONED, + ES_SEC_CREDS_PROVISIONED + } EnrolleeSecState; + + /** + * Security Provisioning Status + */ + class SecProvisioningResult + { + public: + std::shared_ptr< SecProvisioningResult > shared_ptr; + SecProvisioningResult(std::string deviceUUID, ESResult result) : + m_devUUID(deviceUUID), m_result(result) + { + + } + + std::string getDeviceUUID() + { + return m_devUUID; + } + + ESResult getResult() + { + return m_result; + } + private: + std::string m_devUUID; + ESResult m_result; + }; + + /** + * Callback function definition for providing Enrollee security status . + */ + typedef std::function< void(std::shared_ptr) > EnrolleeSecStatusCb; + + /** + * Callback definition to be invoked when the security stack expects a pin from application. + */ + typedef std::function< void(std::string&) > SecurityPinCb; + + /** + * Callback definition to be invoked when the stack expects a db path. + */ + typedef std::function< void(std::string&) > SecProvisioningDbPathCb; + + class ProvisioningStatus + { + public: + std::shared_ptr< ProvisioningStatus > shared_ptr; + ProvisioningStatus(ESResult result, ESState esState) : + m_result(result), m_esState(esState) + { + + } + + ESResult& getESResult() + { + return m_result; + } + + ESState& getESState() + { + return m_esState; + } + private: + ESResult m_result; + ESState m_esState; + }; + + class EasySetupStatus + { + public: + std::shared_ptr< EasySetupStatus > shared_ptr; + EasySetupStatus(const EasySetupState& easySetupState, + const ProvConfig& provConfig) : + m_easySetupState(easySetupState), m_ProvConfig(provConfig) + { + + } + + ProvConfig& getProvConfig() + { + return m_ProvConfig; + } + + EasySetupState& getEasySetupState() + { + return m_easySetupState; + } + private: + EasySetupState m_easySetupState; + ProvConfig m_ProvConfig; + }; + } +} +#endif //WITH_ARDUINO + +#endif //ES_COMMON_RICH_H_ diff --git a/service/easy-setup/mediator/richsdk/src/EasySetup.cpp b/service/easy-setup/mediator/richsdk/src/EasySetup.cpp index fae9462..fe4e5bf 100644 --- a/service/easy-setup/mediator/richsdk/src/EasySetup.cpp +++ b/service/easy-setup/mediator/richsdk/src/EasySetup.cpp @@ -47,7 +47,7 @@ namespace OIC } RemoteEnrollee::shared_ptr EasySetup::findDeviceInProvisioningList ( - const EnrolleeNWProvInfo& enrolleeNWProvInfo) + const ProvConfig& provConfig, const WiFiOnboadingConnection& onboardingconn) { OC_LOG(DEBUG,EASYSETUP_TAG,"Entered findDeviceInProvisioningList ()"); @@ -58,8 +58,12 @@ namespace OIC { OC_LOG_V(DEBUG,EASYSETUP_TAG,"entered the iterator"); - if (0 == memcmp(&it->getEnrolleeProvisioningInfo().netAddressInfo, - &enrolleeNWProvInfo.netAddressInfo, sizeof(EnrolleeNWProvInfo))) + ProvConfig activeEnrolleConfig = it->getProvConfig(); + WiFiOnboadingConnection activeEnrolleConn = it->getOnboardConn(); + if ((0 == memcmp(&activeEnrolleConfig.provData, + &provConfig.provData, sizeof(ProvConfig))) && + (0 == memcmp(&activeEnrolleConn.ipAddress, + &onboardingconn.ipAddress, sizeof(onboardingconn.ipAddress)))) { remoteEnrollee = it; return remoteEnrollee; @@ -72,11 +76,20 @@ namespace OIC bool EasySetup::addDeviceToProvisioningList(const RemoteEnrollee::shared_ptr remoteEnrollee) { + ProvConfig remoteEnrolleConfig = remoteEnrollee->getProvConfig(); + WiFiOnboadingConnection remoteEnrolleConn = remoteEnrollee->getOnboardConn(); + for (auto it : m_activeEnrolleeList) { - if (0 == memcmp(&it->getEnrolleeProvisioningInfo().netAddressInfo, - &remoteEnrollee->getEnrolleeProvisioningInfo().netAddressInfo, - sizeof(EnrolleeNWProvInfo))) + ProvConfig activeEnrolleConfig = it->getProvConfig(); + WiFiOnboadingConnection activeEnrolleConn = it->getOnboardConn(); + if ( (0 == memcmp(&activeEnrolleConfig.provData, + &remoteEnrolleConfig.provData, + sizeof(ProvConfig))) && + (0 == memcmp(&activeEnrolleConn.ipAddress, + &remoteEnrolleConn.ipAddress, + sizeof(remoteEnrolleConn.ipAddress))) + ) { return false; } @@ -88,16 +101,16 @@ namespace OIC } std::shared_ptr EasySetup::createEnrolleeDevice ( - const EnrolleeNWProvInfo& enrolleeNWProvInfo) + const ProvConfig& provConfig, const WiFiOnboadingConnection& wifiOnboardingconn) { - if (findDeviceInProvisioningList(enrolleeNWProvInfo) != nullptr) + if (findDeviceInProvisioningList(provConfig,wifiOnboardingconn) != nullptr) { throw ESBadRequestException { "Device already created exception" }; } RemoteEnrollee::shared_ptr remoteEnrollee; - remoteEnrollee = std::make_shared< RemoteEnrollee > (enrolleeNWProvInfo); + remoteEnrollee = std::make_shared< RemoteEnrollee > (provConfig, wifiOnboardingconn); if (!addDeviceToProvisioningList (remoteEnrollee)) diff --git a/service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.cpp b/service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.cpp index 93507fc..b0ff4fe 100644 --- a/service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.cpp +++ b/service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.cpp @@ -178,7 +178,7 @@ namespace OIC std::shared_ptr< OC::OCSecureResource > ownedDevice = findEnrollee( std::string( - m_remoteEnrolleeResource->m_enrolleeNWProvInfo.netAddressInfo.WIFI.ipAddress), + m_remoteEnrolleeResource->m_wifiOnboardingconn.ipAddress), pOwnedDevList); if (ownedDevice) { @@ -208,7 +208,7 @@ namespace OIC m_unownedDevice = findEnrollee( - m_remoteEnrolleeResource->m_enrolleeNWProvInfo.netAddressInfo.WIFI.ipAddress, + m_remoteEnrolleeResource->m_wifiOnboardingconn.ipAddress, pUnownedDevList); if (m_unownedDevice) { diff --git a/service/easy-setup/mediator/richsdk/src/RemoteEnrollee.cpp b/service/easy-setup/mediator/richsdk/src/RemoteEnrollee.cpp index e7aaf82..2a359dd 100644 --- a/service/easy-setup/mediator/richsdk/src/RemoteEnrollee.cpp +++ b/service/easy-setup/mediator/richsdk/src/RemoteEnrollee.cpp @@ -32,11 +32,11 @@ namespace OIC namespace Service { - RemoteEnrollee::RemoteEnrollee(const EnrolleeNWProvInfo& enrolleeNWProvInfo) : - m_enrolleeNWProvInfo(enrolleeNWProvInfo) + RemoteEnrollee::RemoteEnrollee(const ProvConfig& provConfig, const WiFiOnboadingConnection& connection) : + m_ProvConfig(provConfig), m_wifiOnboardingconn(connection) { m_currentESState = CurrentESState::ES_UNKNOWN; - m_needSecuredEasysetup = enrolleeNWProvInfo.needSecuredEasysetup; + m_isSecured = connection.isSecured; //enrolleeNWProvInfo.needSecuredEasysetup; OC_LOG ( DEBUG, ES_REMOTE_ENROLLEE_TAG, "Inside RemoteEnrollee constr"); } @@ -72,7 +72,7 @@ namespace OIC { m_easySetupStatusCb = callback; - m_remoteResource = std::make_shared< RemoteEnrolleeResource >(m_enrolleeNWProvInfo); + m_remoteResource = std::make_shared< RemoteEnrolleeResource >(m_ProvConfig, m_wifiOnboardingconn); } } @@ -103,7 +103,7 @@ namespace OIC OC_LOG(DEBUG, ES_REMOTE_ENROLLEE_TAG, "Ownership and ACL are successful"); std::shared_ptr< EasySetupStatus > easySetupStatus = nullptr; easySetupStatus = std::make_shared< EasySetupStatus >(DEVICE_NOT_PROVISIONED, - m_enrolleeNWProvInfo); + m_ProvConfig); if (m_easySetupStatusCb) { if (easySetupStatus) @@ -127,7 +127,7 @@ namespace OIC std::shared_ptr< EasySetupStatus > easySetupStatus = nullptr; - if (m_enrolleeNWProvInfo.isSecured) + if (m_isSecured) { if (m_currentESState > CurrentESState::ES_OWNED) { @@ -150,18 +150,18 @@ namespace OIC if (provStatus->getESState() >= ESState::ES_PROVISIONED_ALREADY) { easySetupStatus = std::make_shared< EasySetupStatus >(DEVICE_PROVISIONED, - m_enrolleeNWProvInfo); + m_ProvConfig); } else { easySetupStatus = std::make_shared< EasySetupStatus >(DEVICE_NOT_PROVISIONED, - m_enrolleeNWProvInfo); + m_ProvConfig); } } else { easySetupStatus = std::make_shared< EasySetupStatus >(DEVICE_NOT_PROVISIONED, - m_enrolleeNWProvInfo); + m_ProvConfig); } if (m_easySetupStatusCb) @@ -181,7 +181,7 @@ namespace OIC FAILURE: easySetupStatus = std::make_shared< EasySetupStatus >(DEVICE_NOT_PROVISIONED, - m_enrolleeNWProvInfo); + m_ProvConfig); if (easySetupStatus) { @@ -216,7 +216,7 @@ namespace OIC m_currentESState = CurrentESState::ES_ONBOARDED; #ifdef __WITH_DTLS__ - if (m_needSecuredEasysetup && m_currentESState < CurrentESState::ES_OWNED) + if (m_isSecured && m_currentESState < CurrentESState::ES_OWNED) { EnrolleeSecStatusCb securityProvStatusCb = std::bind( &RemoteEnrollee::easySetupSecurityStatusCallback, @@ -290,9 +290,15 @@ namespace OIC } } - EnrolleeNWProvInfo& RemoteEnrollee::getEnrolleeProvisioningInfo () + ProvConfig RemoteEnrollee::getProvConfig () { - return m_enrolleeNWProvInfo; + return m_ProvConfig; } + + WiFiOnboadingConnection RemoteEnrollee::getOnboardConn() + { + return m_wifiOnboardingconn; + } + } } diff --git a/service/easy-setup/mediator/richsdk/src/RemoteEnrolleeResource.cpp b/service/easy-setup/mediator/richsdk/src/RemoteEnrolleeResource.cpp index 0209960..79c63f5 100644 --- a/service/easy-setup/mediator/richsdk/src/RemoteEnrolleeResource.cpp +++ b/service/easy-setup/mediator/richsdk/src/RemoteEnrolleeResource.cpp @@ -39,9 +39,11 @@ namespace OIC static const char ES_PROV_RES_URI[] = "/oic/prov"; static const char ES_PROV_RES_TYPE[] = "oic.r.prov"; - RemoteEnrolleeResource::RemoteEnrolleeResource(EnrolleeNWProvInfo enrolleeNWProvInfo) + RemoteEnrolleeResource::RemoteEnrolleeResource(ProvConfig provConfig, + WiFiOnboadingConnection onboardingconn) { - m_enrolleeNWProvInfo = enrolleeNWProvInfo; + m_ProvConfig = provConfig; + m_wifiOnboardingconn = onboardingconn; m_discoveryResponse = false; } @@ -79,7 +81,7 @@ namespace OIC //Provisioning status check if (ps == ES_PS_PROVISIONING_COMPLETED) { - if (tnn != std::string(m_enrolleeNWProvInfo.netAddressInfo.WIFI.ssid)) + if (tnn != std::string(m_ProvConfig.provData.WIFI.ssid)) { OC_LOG_V (ERROR, ES_REMOTE_ENROLLEE_RES_TAG, "checkProvInformationCb : Network SSID is not the same as the " @@ -91,7 +93,7 @@ namespace OIC return; } - if (cd != std::string(m_enrolleeNWProvInfo.netAddressInfo.WIFI.pwd)) + if (cd != std::string(m_ProvConfig.provData.WIFI.pwd)) { OC_LOG_V (ERROR, ES_REMOTE_ENROLLEE_RES_TAG, "checkProvInformationCb : Network PWD is not the same as the " @@ -158,14 +160,14 @@ namespace OIC OCRepresentation provisioningRepresentation; provisioningRepresentation.setValue(OC_RSRVD_ES_TNN, - std::string(m_enrolleeNWProvInfo.netAddressInfo.WIFI.ssid)); + std::string(m_ProvConfig.provData.WIFI.ssid)); provisioningRepresentation.setValue(OC_RSRVD_ES_CD, - std::string(m_enrolleeNWProvInfo.netAddressInfo.WIFI.pwd)); + std::string(m_ProvConfig.provData.WIFI.pwd)); OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : ssid - %s", - m_enrolleeNWProvInfo.netAddressInfo.WIFI.ssid); + m_ProvConfig.provData.WIFI.ssid); OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : pwd - %s", - m_enrolleeNWProvInfo.netAddressInfo.WIFI.pwd); + m_ProvConfig.provData.WIFI.pwd); m_ocResource->put(provisioningRepresentation, QueryParamsMap(), std::function< @@ -258,7 +260,7 @@ namespace OIC std::size_t foundIP = hostAddress.find( - std::string(m_enrolleeNWProvInfo.netAddressInfo.WIFI.ipAddress)); + std::string(m_wifiOnboardingconn.ipAddress)); if(resourceURI == ES_PROV_RES_URI && foundIP!=std::string::npos) { @@ -310,16 +312,16 @@ namespace OIC OC_LOG(DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "Before OCPlatform::constructResourceObject"); OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "m_host = %s", - m_enrolleeNWProvInfo.netAddressInfo.WIFI.ipAddress); + m_wifiOnboardingconn.ipAddress); OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "ES_PROV_RES_URI = %s", ES_PROV_RES_URI); OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "m_connectivityType = %d", - m_enrolleeNWProvInfo.connType); + m_ProvConfig.connType); OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "resTypes = %s", resTypes.at(0).c_str()); OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "interface = %s", interface.at(0).c_str()); std::string host; - if(m_enrolleeNWProvInfo.needSecuredEasysetup) + if(m_wifiOnboardingconn.isSecured) { host.append("coaps://"); } @@ -328,13 +330,13 @@ namespace OIC host.append("coap://"); } - if(m_enrolleeNWProvInfo.connType == CT_ADAPTER_IP) + if(m_ProvConfig.connType == CT_ADAPTER_IP) { // TODO : RemoteEnrollee is current handling easysetup on IP transport. // WiFiRemoteEnrollee need to extend RemoteEnrollee for providing IP specific // Enrollee easysetup. - host.append(m_enrolleeNWProvInfo.netAddressInfo.WIFI.ipAddress); + host.append(m_wifiOnboardingconn.ipAddress); //TODO : If the target Enrollee is not a Arduino Wi-Fi device, // then the port number will be found during resource discovery instead of // using 55555 @@ -345,7 +347,7 @@ namespace OIC m_ocResource = OC::OCPlatform::constructResourceObject(host, ES_PROV_RES_URI, - m_enrolleeNWProvInfo.connType, + m_ProvConfig.connType, true, resTypes, interface); @@ -364,7 +366,7 @@ namespace OIC std::string host(""); std::string query(""); - if (m_enrolleeNWProvInfo.needSecuredEasysetup) + if (m_wifiOnboardingconn.isSecured) { host.append("coaps://"); } @@ -373,13 +375,13 @@ namespace OIC host.append("coap://"); } - if (m_enrolleeNWProvInfo.connType == CT_ADAPTER_IP) + if (m_ProvConfig.connType == CT_ADAPTER_IP) { // TODO : RemoteEnrollee is current handling easysetup on IP transport. // WiFiRemoteEnrollee need to extend RemoteEnrollee for providing IP specific // Enrollee easysetup. - host.append(m_enrolleeNWProvInfo.netAddressInfo.WIFI.ipAddress); + host.append(m_wifiOnboardingconn.ipAddress); } query.append(ES_BASE_RES_URI); @@ -392,7 +394,7 @@ namespace OIC host.c_str()); OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "query = %s", query.c_str()); OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "m_connectivityType = %d", - m_enrolleeNWProvInfo.connType); + m_ProvConfig.connType); m_discoveryResponse = false; std::function< void (std::shared_ptr) > onDeviceDiscoveredCb = diff --git a/service/easy-setup/sampleapp/mediator/linux/csdk_sample/mediator.cpp b/service/easy-setup/sampleapp/mediator/linux/csdk_sample/mediator.cpp index 3ed1984..4a03d17 100644 --- a/service/easy-setup/sampleapp/mediator/linux/csdk_sample/mediator.cpp +++ b/service/easy-setup/sampleapp/mediator/linux/csdk_sample/mediator.cpp @@ -64,7 +64,11 @@ static void PrintUsage() { int main(int argc, char **argv) { int opt; - EnrolleeNWProvInfo netInfo; + + ProvConfig provConfig; + //WiFiOnboardingConfig onboardConfig; + WiFiOnboadingConnection onboardConn; + PrintUsage(); InitProvProcess(); @@ -74,13 +78,13 @@ int main(int argc, char **argv) { while ((opt = getopt(argc, argv, "d:s:p:")) != -1) { switch (opt) { case 'd': - strncpy(netInfo.netAddressInfo.WIFI.ipAddress, optarg, IPV4_ADDR_SIZE - 1); + strncpy(onboardConn.ipAddress, optarg, IPV4_ADDR_SIZE - 1); break; case 's': - strncpy(netInfo.netAddressInfo.WIFI.ssid, optarg, NET_WIFI_SSID_SIZE - 1); + strncpy(provConfig.provData.WIFI.ssid, optarg, NET_WIFI_SSID_SIZE - 1); break; case 'p': - strncpy(netInfo.netAddressInfo.WIFI.pwd, optarg, NET_WIFI_PWD_SIZE - 1); + strncpy(provConfig.provData.WIFI.pwd, optarg, NET_WIFI_PWD_SIZE - 1); break; default: PrintUsage(); @@ -88,13 +92,13 @@ int main(int argc, char **argv) { } } - netInfo.connType = CT_ADAPTER_IP; + provConfig.connType = CT_ADAPTER_IP; OIC_LOG_V(INFO, ES_MEDIATOR_TAG, "IP Address of the Provisioning device is =%s\n", - netInfo.netAddressInfo.WIFI.ipAddress); - OIC_LOG_V(INFO, ES_MEDIATOR_TAG, "SSID of the Enroller is =%s\n", netInfo.netAddressInfo.WIFI.ssid); - OIC_LOG_V(INFO, ES_MEDIATOR_TAG, "Password of the Enroller is =%s\n", netInfo.netAddressInfo.WIFI.pwd); + onboardConn.ipAddress); + OIC_LOG_V(INFO, ES_MEDIATOR_TAG, "SSID of the Enroller is =%s\n", provConfig.provData.WIFI.ssid); + OIC_LOG_V(INFO, ES_MEDIATOR_TAG, "Password of the Enroller is =%s\n", provConfig.provData.WIFI.pwd); - StartProvisioning(&netInfo); + StartProvisioning(&provConfig, &onboardConn); signal(SIGINT, handleSigInt); while (!quitFlag) { 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 13e7630..675e9c0 100644 --- a/service/easy-setup/sampleapp/mediator/linux/richsdk_sample/mediator_cpp.cpp +++ b/service/easy-setup/sampleapp/mediator/linux/richsdk_sample/mediator_cpp.cpp @@ -35,7 +35,8 @@ using namespace OC; using namespace OIC::Service; static EasySetup *easySetupIntance = nullptr; -static EnrolleeNWProvInfo netInfo; +static ProvConfig netInfo; +static WiFiOnboadingConnection onboardingConn; static RemoteEnrollee::shared_ptr remoteEnrollee = nullptr; static std::string ipaddress, ssid, pwd; @@ -70,8 +71,7 @@ int processUserInput(int min, int max) void easySetupStatusCallback (std::shared_ptr< EasySetupStatus > easySetupStatus) { - OC_LOG_V(DEBUG, ES_SAMPLE_APP_TAG, "easySetupStatusCallback status is, IP = %s, Status = %d", - easySetupStatus->getEasySetupNWProvInfo().netAddressInfo.WIFI.ipAddress, + OC_LOG_V(DEBUG, ES_SAMPLE_APP_TAG, "easySetupStatusCallback status is Status = %d", easySetupStatus->getEasySetupState()); } @@ -93,7 +93,7 @@ void initEasySetup() easySetupIntance = EasySetup::getInstance(); - ipaddress = "10.113.64.106"; + ipaddress = "192.168.1.104"; //std::cout << "Enter the target enrollee ipv4 address "; @@ -106,15 +106,19 @@ void initEasySetup() //std::cin >> pwd; netInfo.connType = CT_ADAPTER_IP; - netInfo.isSecured = false; - netInfo.needSecuredEasysetup = false; - OICStrcpy(netInfo.netAddressInfo.WIFI.ipAddress, IPV4_ADDR_SIZE - 1, ipaddress.c_str()); - OICStrcpy(netInfo.netAddressInfo.WIFI.ssid, NET_WIFI_SSID_SIZE - 1, ssid.c_str()); - OICStrcpy(netInfo.netAddressInfo.WIFI.pwd, NET_WIFI_PWD_SIZE - 1, pwd.c_str()); + //netInfo.isSecured = false; + //netInfo.needSecuredEasysetup = false; + + OICStrcpy(netInfo.provData.WIFI.ssid, NET_WIFI_SSID_SIZE - 1, ssid.c_str()); + OICStrcpy(netInfo.provData.WIFI.pwd, NET_WIFI_PWD_SIZE - 1, pwd.c_str()); + + onboardingConn.isSecured = false; + OICStrcpy(onboardingConn.ipAddress, IPV4_ADDR_SIZE - 1, ipaddress.c_str()); + try { - remoteEnrollee = easySetupIntance->createEnrolleeDevice(netInfo); + remoteEnrollee = easySetupIntance->createEnrolleeDevice(netInfo,onboardingConn); } catch (OCException &e) {