#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-##
+######################################################################
# easy-setup project build script
-##
-
+######################################################################
import os
-
Import('env')
-transport = env.get('TARGET_TRANSPORT')
-
-env.AppendUnique(CPPDEFINES = ['EASY_SETUP_CA_INIT'])
+######################################################################
+#building Resource client, resourceBroker and resourceCache
+######################################################################
-easy_setup_env = env.Clone()
-#
-target_os = env.get('TARGET_OS')
+if env.get('RELEASE'):
+ env.AppendUnique(CCFLAGS = ['-Os'])
+ env.AppendUnique(CPPDEFINES = ['NDEBUG'])
+else:
+ env.AppendUnique(CCFLAGS = ['-g'])
+if env.get('LOGGING'):
+ env.AppendUnique(CPPDEFINES = ['TB_LOG'])
+
+# Add third party libraries
lib_env = env.Clone()
-if target_os == 'android':
- SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', exports = 'lib_env')
+SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env')
+
+easy_setup_env = lib_env.Clone()
+target_os = env.get('TARGET_OS')
######################################################################
# Build flags
easy_setup_env.AppendUnique(CPPPATH = ['sdk/inc', 'sdk/src', 'sdk/common'])
if target_os not in ['windows', 'winrt']:
- easy_setup_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall'])
- if target_os not in ['android', 'arduino']:
- easy_setup_env.AppendUnique(CXXFLAGS = ['-pthread'])
+ easy_setup_env.AppendUnique(CXXFLAGS = ['-Wall', '-std=c++0x'])
+
+if target_os == 'linux':
+ easy_setup_env.AppendUnique(LIBS = ['pthread'])
-if target_os in ['android', 'linux']:
+if target_os in ['android']:
easy_setup_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
easy_setup_env.AppendUnique(RPATH = [env.get('BUILD_DIR')])
easy_setup_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
- if target_os not in ['linux', 'arduino']:
- easy_setup_env.PrependUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'connectivity_abstraction', 'gnustl_shared'])
- if not env.get('RELEASE'):
- easy_setup_env.AppendUnique(LIBS = ['log'])
- else:
- easy_setup_env.PrependUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'pthread', 'connectivity_abstraction'])
+ easy_setup_env.PrependUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'connectivity_abstraction', 'gnustl_shared'])
+ if not env.get('RELEASE'):
+ easy_setup_env.AppendUnique(LIBS = ['log'])
+
+if target_os == 'linux':
+ easy_setup_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
+ easy_setup_env.AppendUnique(RPATH = [env.get('BUILD_DIR')])
+ easy_setup_env.AppendUnique(CXXFLAGS = ['-pthread'])
+ easy_setup_env.PrependUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'pthread', 'connectivity_abstraction'])
+
if target_os == 'arduino':
easy_setup_env.AppendUnique(CPPPATH = [
'../../resource/oc_logger/include',
'../../resource/csdk/logger/include',
'../../resource/csdk/stack/include',
'../../extlibs/cjson',
- 'sdk/enrollee/arduino/wifi',
- 'sdk/enrollee/api',
- 'sdk/enrollee/src',
+ 'sdk/enrollee/arduino/wifi',
+ 'sdk/enrollee/api',
+ 'sdk/enrollee/src',
'sdk/enrollee/inc'])
- easy_setup_env.AppendUnique(CPPDEFINES = ['TB_LOG', 'ESWIFI'])
+ easy_setup_env.AppendUnique(CPPDEFINES = ['ESWIFI'])
+
if target_os in ['android','linux']:
easy_setup_env.PrependUnique(CPPPATH = [
env.get('SRC_DIR') + '/resource/c_common/oic_malloc/include',
- env.get('SRC_DIR') + '/resource/csdk/connectivity/common/inc',
- env.get('SRC_DIR') + '/resource/csdk/connectivity/api',
- env.get('SRC_DIR') + '/resource/csdk/stack/include',
- env.get('SRC_DIR') + '/resource/csdk/logger/include',
+ env.get('SRC_DIR') + '/resource/include',
+ env.get('SRC_DIR') + '/resource/csdk/logger/include',
+ env.get('SRC_DIR') + '/resource/csdk/stack/include',
+ env.get('SRC_DIR') + '/resource/csdk/logger/include',
env.get('SRC_DIR') + '/resource/csdk/security/include',
env.get('SRC_DIR') + '/extlibs/cjson',
- 'sdk/common',
- 'sdk/mediator/inc'])
+ '/ser/sdk/common',
+ 'sdk/mediator/include',
+ 'sdk/mediator/src'])
######################################################################
# Source files and Targets
es_sdk_shared = easy_setup_env.StaticLibrary('libESSDK',
['sdk/mediator/src/prov_adapter.cpp',
'sdk/mediator/src/wifi_provisioning.cpp',
- 'sdk/mediator/src/provisioning.cpp'])
+ 'sdk/mediator/src/provisioning.cpp'])
easy_setup_env.InstallTarget(es_sdk_shared, 'libESSDK')
if target_os == 'linux':
es_sdk_shared = easy_setup_env.SharedLibrary('ESSDKLibrary',
- ['sdk/mediator/src/prov_adapter.cpp',
+ ['sdk/mediator/src/RemoteEnrollee.cpp',
+ 'sdk/mediator/src/RemoteEnrolleeResource.cpp',
+ 'sdk/mediator/src/EasySetup.cpp',
+ 'sdk/mediator/src/prov_adapter.cpp',
+ 'sdk/mediator/src/ESException.cpp',
'sdk/mediator/src/wifi_provisioning.cpp',
- 'sdk/mediator/src/provisioning.cpp'])
+ 'sdk/mediator/src/provisioning.cpp'])
easy_setup_env.InstallTarget(es_sdk_shared, 'libESSDK')
#Go to build sample apps
# Build flags
######################################################################
mediator_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
-mediator_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
+if env.get('RELEASE'):
+ mediator_env.AppendUnique(CCFLAGS = ['-Os'])
+ mediator_env.AppendUnique(CPPDEFINES = ['NDEBUG'])
+else:
+ mediator_env.AppendUnique(CCFLAGS = ['-g'])
+
+if env.get('LOGGING'):
+ env.AppendUnique(CPPDEFINES = ['TB_LOG'])
+
+
+if target_os not in ['windows', 'winrt']:
+ mediator_env.AppendUnique(CXXFLAGS = ['-Wall', '-std=c++0x'])
+
mediator_env.PrependUnique(CPPPATH = [
+ env.get('SRC_DIR') + '/resource/include',
+ env.get('SRC_DIR') + '/resource/oc_logger/include',
env.get('SRC_DIR') + '/resource/csdk/ocmalloc/include',
- env.get('SRC_DIR') + '/resource/csdk/connectivity/common/inc',
- env.get('SRC_DIR') + '/resource/csdk/connectivity/api',
env.get('SRC_DIR') + '/resource/csdk/stack/include',
env.get('SRC_DIR') + '/resource/csdk/logger/include',
env.get('SRC_DIR') + '/resource/csdk/security/include',
env.get('SRC_DIR') + '/extlibs/cjson',
- env.get('SRC_DIR') + '/service/easy-setup/sdk/mediator/inc',
+ env.get('SRC_DIR') + '/service/easy-setup/sdk/mediator/include',
+ env.get('SRC_DIR') + '/service/easy-setup/sdk/mediator/src',
env.get('SRC_DIR') + '/service/easy-setup/sdk/common'])
mediator_env.PrependUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'pthread', 'connectivity_abstraction', 'coap', 'ESSDKLibrary'])
-mediator = mediator_env.Program('mediator', 'mediator.cpp')
+mediator = mediator_env.Program('mediator', 'mediator_cpp.cpp')
i_mediator = mediator_env.Install(env.get('BUILD_DIR'), mediator)
int main(int argc, char **argv) {
int opt;
- EnrolleeNWProvInfo_t netInfo;
+ EnrolleeNWProvInfo netInfo;
PrintUsage();
InitProvProcess();
--- /dev/null
+//******************************************************************
+//
+// 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 <iostream>
+
+#include "oic_string.h"
+#include "EasySetup.h"
+#include "OCPlatform.h"
+#include "logger.h"
+
+#define ES_SAMPLE_APP_TAG "ES_SAMPLE_APP_TAG"
+#define DECLARE_MENU(FUNC, ...) { #FUNC, FUNC }
+
+using namespace OC;
+using namespace OIC::Service;
+
+static EasySetup *easySetupIntance = nullptr;
+static EnrolleeNWProvInfo netInfo;
+static RemoteEnrollee::shared_ptr remoteEnrollee = nullptr;
+
+struct CloseApp
+{
+};
+
+typedef void (*Runner)();
+
+Runner g_currentRun;
+
+int processUserInput(int min, int max)
+{
+ assert(min <= max);
+
+ int input;
+
+ std::cin >> input;
+
+ if (!std::cin.fail())
+ {
+ if(input == max + 1) throw CloseApp();
+ if(min <= input && input <= max) return input;
+ }
+
+ std::cin.clear();
+ std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
+
+ throw std::runtime_error("Invalid Input, please try again");
+}
+
+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,
+ easySetupStatus->getEasySetupState());
+
+}
+
+void startProvisioning()
+{
+ try
+ {
+ remoteEnrollee->startProvisioning();
+ }
+ catch(OCException &exception)
+ {
+ std::cout << "Exception : " << exception.reason();
+ }
+}
+
+void initEasySetup()
+{
+
+ easySetupIntance = EasySetup::getInstance();
+
+ std::string ipaddress ("192.168.0.100");
+ std::cout << "Enter the target enrollee ipv4 address ";
+
+
+ std::string ssid;
+ std::cout << "Enter the ssid of the target Enrolleer ";
+ std:: cin >> ssid;
+
+ std::string pwd;
+ std::cout << "Enter the pwd of the target Enrolleer ";
+ std::cin >> pwd;
+
+ netInfo.connType = CT_ADAPTER_IP;
+ netInfo.isSecured = 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());
+
+ try
+ {
+ remoteEnrollee = easySetupIntance->createEnrolleeDevice(netInfo);
+ }
+ catch (OCException &e)
+ {
+ std::cout << "Exception during createEnrolleeDevice call" << e.reason();
+ return;
+ }
+
+ remoteEnrollee->registerEasySetupStatusHandler(&easySetupStatusCallback);
+}
+void runEasySetupMenu()
+{
+ constexpr int EASY_SETUP_INIT = 1;
+ constexpr int START_PROVISIONING = 2;
+ constexpr int STOP_PROVISIONING = 3;
+ constexpr int STOP_EASY_SETUP = 4;
+
+ std::cout << "========================================================\n";
+ std::cout << EASY_SETUP_INIT << ". Easy Setup Init \n";
+ std::cout << START_PROVISIONING << ". Start Provisioning \n";
+ std::cout << STOP_PROVISIONING << ". Stop Provisioning \n";
+ std::cout << STOP_EASY_SETUP << ". Stop Easy Setup \n";
+ std::cout << STOP_EASY_SETUP + 1 << ". Quit \n";
+ std::cout << "========================================================\n";
+
+ int selection = processUserInput(EASY_SETUP_INIT, STOP_EASY_SETUP);
+
+ switch (selection)
+ {
+ case EASY_SETUP_INIT:
+ initEasySetup();
+ break;
+ case START_PROVISIONING:
+ startProvisioning();
+ break;
+ case STOP_PROVISIONING:
+ //stopProvisioning();
+ break;
+ case STOP_EASY_SETUP:
+ //stopEasySetup();
+ break;
+ default:
+ break;
+ };
+}
+
+void configurePlatform()
+{
+ PlatformConfig config
+ {
+ OC::ServiceType::InProc, ModeType::Client, "0.0.0.0", 0, OC::QualityOfService::LowQos
+ };
+ OCPlatform::Configure(config);
+}
+
+int main()
+{
+ configurePlatform();
+
+ g_currentRun = runEasySetupMenu;
+
+ while (true)
+ {
+ try
+ {
+ g_currentRun();
+ }
+ catch (const std::exception& e)
+ {
+ std::cout << "Exception caught in main " << e.what() << std::endl;
+ }
+ catch (const CloseApp&)
+ {
+ break;
+ }
+ }
+
+ std::cout << "Stopping the client" << std::endl;
+
+ return 0;
+}
+
#ifndef ES_COMMON_H_
#define ES_COMMON_H_
+#ifndef WITH_ARDUINO
+#include <memory>
+#endif
+
#include "ocstack.h"
#include "octypes.h"
OCDevAddr * addr;
/// Indicates adaptor type on which the response was received
OCConnectivityType connType;
-} ProvDeviceInfo;
+} EasySetupDeviceInfo;
/**
* Provosioning Status
*/
-typedef enum {
- DEVICE_PROVISIONED = 0, DEVICE_NOT_PROVISIONED
-} ProvStatus;
+typedef enum
+{
+ DEVICE_PROVISIONED = 0,
+ DEVICE_NOT_PROVISIONED,
+ DEVICE_OWNED,
+ DEVICE_NOT_OWNED
+} EasySetupState, ProvStatus;
+
+
/**
* Response from queries to remote servers.
*/
typedef struct {
- // Provisioning Status
- ProvStatus provStatus;
- // Provisioning Device Info
- ProvDeviceInfo provDeviceInfo;
-} ProvisioningInfo;
+ // EasySetup Status
+ EasySetupState provStatus;
+ // EasySetup Device Info
+ EasySetupDeviceInfo provDeviceInfo;
+} EasySetupInfo, ProvisioningInfo;
/**
* @brief Network information 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_t;
+} EnrolleeInfo;
/**
*/
typedef struct
{
- EnrolleeInfo_t netAddressInfo; /**< Enroller Network Info**/
+ EnrolleeInfo netAddressInfo; /**< Enroller Network Info**/
OCConnectivityType connType; /**< Connectivity Type**/
bool isSecured; /**< Secure connection**/
-} EnrolleeNWProvInfo_t;
+} EnrolleeNWProvInfo;
/**
* Client applications implement this callback to consume responses received from Servers.
*/
-typedef void (*OCProvisioningStatusCB)(ProvisioningInfo *provInfo);
+typedef void (*OCProvisioningStatusCB)(EasySetupInfo *easySetupInfo);
+
+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;
+
+#ifndef WITH_ARDUINO
+ 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
+
+ }
+}
#endif
sprintf(g_prov.tnn, "%s", tnn);
}
+ OC_LOG_V(INFO, ES_RH_TAG, "g_prov.tnn %s", g_prov.tnn);
+
char* cd;
if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_CD, &cd))
{
sprintf(g_prov.cd, "%s", cd);
}
+ OC_LOG_V(INFO, ES_RH_TAG, "g_prov.cd %s", g_prov.cd);
+
g_flag = 1;
OCRepPayload *getResp = constructResponse(ehRequest);
--- /dev/null
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+/**
+ * @file
+ *
+ * This file contains the declaration of exception classes for easy setup
+ */
+#ifndef EASY_SETUP_EXCEPTION_H
+#define EASY_SETUP_EXCEPTION_H
+
+#include <string>
+#include <octypes.h>
+
+namespace OIC
+{
+ namespace Service
+ {
+
+ /**
+ * The base exception class for resource encapsulation.
+ *
+ */
+ class ESException: public std::exception
+ {
+ public:
+
+ /**
+ * Constructs an exception with an empty description.
+ */
+ ESException();
+
+ /**
+ * Constructs an exception with a description.
+ *
+ * @param what The description for the error.
+ */
+ explicit ESException(const std::string &what);
+
+ /**
+ * @overload
+ */
+ explicit ESException(std::string &&what);
+
+ virtual ~ESException() noexcept;
+
+ /**
+ * Returns the exception description.
+ *
+ */
+ virtual const char *what() const noexcept;
+
+ private:
+ /**
+ * Exception description
+ */
+ const std::string m_what;
+ };
+
+ /**
+ * Thrown when OC layer returns an error.
+ *
+ */
+ class ESPlatformException: public ESException
+ {
+ public:
+ explicit ESPlatformException(OCStackResult reason);
+
+ /**
+ * Returns the reason.
+ *
+ */
+ OCStackResult getReasonCode() const;
+
+ /**
+ * Returns the reason description.
+ *
+ */
+ std::string getReason() const;
+
+ private:
+ OCStackResult m_reason;
+ };
+
+ /**
+ * Thrown when a request is not acceptable.
+ *
+ */
+ class ESBadRequestException: public ESException
+ {
+ public:
+ explicit ESBadRequestException(const std::string& what);
+ explicit ESBadRequestException(std::string&& what);
+ };
+
+ /**
+ * Thrown when a parameter is not valid.
+ *
+ */
+ class ESInvalidParameterException: public ESException
+ {
+ public:
+ explicit ESInvalidParameterException(const std::string& what);
+ explicit ESInvalidParameterException(std::string&& what);
+ };
+
+ /**
+ * Thrown when getting value with wrong template parameter.
+ */
+ class ESBadGetException: public ESException
+ {
+ public:
+ explicit ESBadGetException(const std::string& what);
+ explicit ESBadGetException(std::string&& what);
+ };
+
+ /**
+ * Thrown when a key is invalid.
+ *
+ */
+ class ESInvalidKeyException: public ESException
+ {
+ public:
+ explicit ESInvalidKeyException(const std::string& what);
+ explicit ESInvalidKeyException(std::string&& what);
+ };
+ }
+}
+
+#endif // EASY_SETUP_EXCEPTION_H
--- /dev/null
+//******************************************************************\r
+//\r
+// Copyright 2015 Samsung Electronics All Rights Reserved.\r
+//\r
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the "License");\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+// http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+//\r
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+\r
+#ifndef EASYSETUP_H_\r
+#define EASYSETUP_H_\r
+\r
+#include <memory>\r
+#include <vector>\r
+\r
+#include "escommon.h"\r
+#include "RemoteEnrollee.h"\r
+\r
+namespace OIC\r
+{\r
+ namespace Service\r
+ {\r
+ class RemoteEnrollee;\r
+\r
+ /**\r
+ * This provides methods for Mediator devices to perform EasySetup of Enrollee devices.\r
+ * EasySetup involves\r
+ * 1) Ownership transfer for enabling secured communication between Mediator and Enrollee\r
+ * devices.\r
+ * 2) Provisioning of Enrollee devices using the credentails of target Enroller devices.\r
+ */\r
+ class EasySetup\r
+ {\r
+ public:\r
+ /**\r
+ * API for getting the instance of EasySetup singleton class.\r
+ * @return EasySetup instance.\r
+ */\r
+ static EasySetup* getInstance();\r
+\r
+ /**\r
+ * This API is used for creating a remote Enrollee device instance.\r
+ * @param enrolleeNWProvIndo Provisioning information for configuring the Enrollee.\r
+ *\r
+ * @throws ESBadRequestException If createEnrolleeDevice is invoked with the same\r
+ * provisioning information.\r
+ *\r
+ * @return Pointer to RemoteEnrollee instance.\r
+ */\r
+ std::shared_ptr<RemoteEnrollee> createEnrolleeDevice (\r
+ const EnrolleeNWProvInfo& enrolleeNWProvInfo);\r
+ private:\r
+ EasySetup();\r
+ ~EasySetup();\r
+\r
+ RemoteEnrollee::shared_ptr findDeviceInProvisioningList(\r
+ const EnrolleeNWProvInfo& enrolleeNWProvInfo);\r
+ bool addDeviceToProvisioningList(const RemoteEnrollee::shared_ptr remoteEnrollee);\r
+ bool deleteDeviceFromProvisioningList (const EnrolleeNWProvInfo& enrolleeNWProvInfo);\r
+\r
+ std::vector< RemoteEnrollee::shared_ptr > m_activeEnrolleeList;\r
+ static EasySetup *s_instance;\r
+ };\r
+ }\r
+}\r
+\r
+#endif /* EASYSETUP_H_ */\r
--- /dev/null
+//******************************************************************\r
+//\r
+// Copyright 2015 Samsung Electronics All Rights Reserved.\r
+//\r
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the "License");\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+// http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+//\r
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+\r
+#ifndef REMOTE_ENROLLEE_H_\r
+#define REMOTE_ENROLLEE_H_\r
+\r
+#include "escommon.h"\r
+\r
+namespace OIC\r
+{\r
+ namespace Service\r
+ {\r
+ class RemoteEnrolleeResource;\r
+\r
+ /**\r
+ * This class represents Remote Enrollee device instance.\r
+ * It will provide APIs for Mediator to perform operations to enable the Enrollee device\r
+ * to connect to the Enroller.\r
+ */\r
+ class RemoteEnrollee\r
+ {\r
+ public:\r
+ /**\r
+ * RemoteEnrollee constructor\r
+ *\r
+ * @param enrolleeNWProvInfo Provisioning information for the Enrollee\r
+ *\r
+ * @throw ESBadRequestException is thrown if the parameters are invalid\r
+ */\r
+ RemoteEnrollee(const EnrolleeNWProvInfo& enrolleeNWProvInfo) ;\r
+\r
+ ~RemoteEnrollee() = default;\r
+\r
+ typedef std::shared_ptr< RemoteEnrollee > shared_ptr;\r
+\r
+ /**\r
+ * Callback definition to be invoked when EasySetup status is changed.\r
+ * The same callback will be invoked when there is an error in the\r
+ * EasySetup process.\r
+ *\r
+ * @see registerResourceHandler\r
+ * @see ResourceState\r
+ */\r
+ typedef std::function< void(std::shared_ptr< EasySetupStatus >) >\r
+ EasySetupStatusCB;\r
+\r
+ /**\r
+ * Register EasySetup status handler.\r
+ *\r
+ * @param callback Callback to get EasySetup status.\r
+ *\r
+ * @throws InvalidParameterException If callback is an empty function or null.\r
+ * @throws ESBadRequestException If registration is already completed.\r
+ *\r
+ * @see EasySetupStatus\r
+ */\r
+ void registerEasySetupStatusHandler(EasySetupStatusCB callback);\r
+\r
+ /**\r
+ * Start provisioning of target Enrollers information to the Enrollee.\r
+ *\r
+ * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call.\r
+ *\r
+ * @see RemoteEnrollee\r
+ */\r
+ virtual void startProvisioning();\r
+\r
+ /**\r
+ * Stop provisioning process that is currently in progress.\r
+ *\r
+ * @throws BadRequestException If provisioning is not in progress.\r
+ */\r
+ virtual void stopProvisioning();\r
+\r
+ /**\r
+ * Check if the Enrollee device provisioned.\r
+ */\r
+ virtual bool isEnrolleeProvisioned();\r
+\r
+ /**\r
+ * Get the Provisioning information provided for the current Enrollee.\r
+ *\r
+ * @return EnrolleeNWProvInfo Provisioning information provided for the current Enrollee.\r
+ */\r
+ virtual EnrolleeNWProvInfo& getEnrolleeProvisioningInfo ();\r
+\r
+ private:\r
+ std::shared_ptr< RemoteEnrolleeResource > m_remoteResource;\r
+ EasySetupStatusCB m_easySetupStatusCb;\r
+ EnrolleeNWProvInfo m_enrolleeNWProvInfo;\r
+ CurrentESState m_currentESState;\r
+\r
+ void provisioningStatusHandler (std::shared_ptr< ProvisioningStatus > provStatus);\r
+ };\r
+ }\r
+}\r
+\r
+#endif //REMOTE_ENROLLEE_H_\r
--- /dev/null
+//******************************************************************
+//
+// 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 "ESException.h"
+
+#include "OCException.h"
+
+namespace OIC
+{
+ namespace Service
+ {
+
+ ESException::ESException()
+ {
+ }
+
+ ESException::ESException(const std::string& what) :
+ m_what{ what }
+ {
+ }
+
+ ESException::ESException(std::string&& what) :
+ m_what{ std::move(what) }
+ {
+ }
+
+ ESException::~ESException() noexcept
+ {
+ }
+
+ const char* ESException::what() const noexcept
+ {
+ return m_what.c_str();
+ }
+
+
+ ESPlatformException::ESPlatformException(OCStackResult reason) :
+ ESException{ "Failed : " + OC::OCException::reason(reason) },
+ m_reason { reason }
+ {
+ }
+
+ OCStackResult ESPlatformException::getReasonCode() const
+ {
+ return m_reason;
+ }
+
+ std::string ESPlatformException::getReason() const
+ {
+ return OC::OCException::reason(m_reason);
+ }
+
+
+ ESBadRequestException::ESBadRequestException(const std::string& what) :
+ ESException{ what }
+ {
+ }
+
+ ESBadRequestException::ESBadRequestException(std::string&& what) :
+ ESException{ std::move(what) }
+ {
+ }
+
+
+ ESInvalidParameterException::ESInvalidParameterException(const std::string& what) :
+ ESException{ what }
+ {
+ }
+
+ ESInvalidParameterException::ESInvalidParameterException(std::string&& what) :
+ ESException{ std::move(what) }
+ {
+ }
+
+
+ ESBadGetException::ESBadGetException(const std::string& what) :
+ ESException{ what }
+ {
+ }
+
+ ESBadGetException::ESBadGetException(std::string&& what) :
+ ESException{ std::move(what) }
+ {
+ }
+
+
+ ESInvalidKeyException::ESInvalidKeyException(const std::string& what) :
+ ESException{ what }
+ {
+ }
+
+ ESInvalidKeyException::ESInvalidKeyException(std::string&& what) :
+ ESException{ std::move(what) }
+ {
+ }
+ }
+}
--- /dev/null
+//******************************************************************\r
+//\r
+// Copyright 2015 Samsung Electronics All Rights Reserved.\r
+//\r
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the "License");\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+// http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+//\r
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+\r
+#include "EasySetup.h"\r
+\r
+#include "logger.h"\r
+#include "ESException.h"\r
+#include "RemoteEnrollee.h"\r
+\r
+namespace OIC\r
+{\r
+ namespace Service\r
+ {\r
+ #define EASYSETUP_TAG "EASY_SETUP"\r
+\r
+ EasySetup * EasySetup::s_instance = nullptr;\r
+\r
+ EasySetup::EasySetup()\r
+ {\r
+\r
+ }\r
+\r
+ EasySetup* EasySetup::getInstance ()\r
+ {\r
+ if (s_instance == nullptr)\r
+ {\r
+ s_instance = new EasySetup ();\r
+ }\r
+ return s_instance;\r
+ }\r
+\r
+ RemoteEnrollee::shared_ptr EasySetup::findDeviceInProvisioningList (\r
+ const EnrolleeNWProvInfo& enrolleeNWProvInfo)\r
+ {\r
+ OC_LOG(DEBUG,EASYSETUP_TAG,"Entered findDeviceInProvisioningList ()");\r
+\r
+ std::vector< std::shared_ptr< RemoteEnrollee > >::iterator it;\r
+\r
+ std::shared_ptr< RemoteEnrollee > remoteEnrollee = nullptr;\r
+ for(auto it : m_activeEnrolleeList)\r
+ {\r
+ OC_LOG_V(DEBUG,EASYSETUP_TAG,"entered the iterator");\r
+\r
+ if (0 == memcmp(&it->getEnrolleeProvisioningInfo().netAddressInfo,\r
+ &enrolleeNWProvInfo.netAddressInfo, sizeof(EnrolleeNWProvInfo)))\r
+ {\r
+ remoteEnrollee = it;\r
+ return remoteEnrollee;\r
+ }\r
+ }\r
+\r
+ OC_LOG_V(DEBUG,EASYSETUP_TAG,"Return nullptr for findDeviceInProvisioningList call");\r
+ return remoteEnrollee;\r
+ }\r
+\r
+ bool EasySetup::addDeviceToProvisioningList(const RemoteEnrollee::shared_ptr remoteEnrollee)\r
+ {\r
+ for (auto it : m_activeEnrolleeList)\r
+ {\r
+ if (0 == memcmp(&it->getEnrolleeProvisioningInfo().netAddressInfo,\r
+ &remoteEnrollee->getEnrolleeProvisioningInfo().netAddressInfo,\r
+ sizeof(EnrolleeNWProvInfo)))\r
+ {\r
+ return false;\r
+ }\r
+ }\r
+\r
+ OC_LOG_V(DEBUG,EASYSETUP_TAG,"Adding new device RemoteEnrollee list");\r
+ m_activeEnrolleeList.push_back(remoteEnrollee);\r
+ return true;\r
+ }\r
+\r
+ std::shared_ptr<RemoteEnrollee> EasySetup::createEnrolleeDevice (\r
+ const EnrolleeNWProvInfo& enrolleeNWProvInfo)\r
+ {\r
+ if (findDeviceInProvisioningList(enrolleeNWProvInfo) != nullptr)\r
+ {\r
+ throw ESBadRequestException { "Device already created exception" };\r
+ }\r
+\r
+ RemoteEnrollee::shared_ptr remoteEnrollee;\r
+\r
+ remoteEnrollee = std::make_shared< RemoteEnrollee > (enrolleeNWProvInfo);\r
+\r
+\r
+ if (!addDeviceToProvisioningList (remoteEnrollee))\r
+ {\r
+ return nullptr;\r
+ }\r
+\r
+ return remoteEnrollee;\r
+ }\r
+\r
+\r
+ }\r
+}\r
+\r
--- /dev/null
+//******************************************************************\r
+//\r
+// Copyright 2015 Samsung Electronics All Rights Reserved.\r
+//\r
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the "License");\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+// http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+//\r
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+\r
+#include "RemoteEnrollee.h"\r
+#include "RemoteEnrolleeResource.h"\r
+#include "ESException.h"\r
+#include "logger.h"\r
+\r
+namespace OIC\r
+{\r
+ #define ES_REMOTE_ENROLLEE_TAG "ES_REMOTE_ENROLLEE"\r
+\r
+ namespace Service\r
+ {\r
+ RemoteEnrollee::RemoteEnrollee(const EnrolleeNWProvInfo& enrolleeNWProvInfo) :\r
+ m_enrolleeNWProvInfo(enrolleeNWProvInfo)\r
+ {\r
+ m_currentESState = CurrentESState::ES_UNKNOWN;\r
+\r
+ OC_LOG ( DEBUG, ES_REMOTE_ENROLLEE_TAG, "Inside RemoteEnrollee constr");\r
+ if (m_easySetupStatusCb)\r
+ {\r
+ throw ESBadRequestException("Callback handler already registered");\r
+ }\r
+ }\r
+\r
+ void RemoteEnrollee::registerEasySetupStatusHandler(EasySetupStatusCB callback)\r
+ {\r
+ OC_LOG ( DEBUG, ES_REMOTE_ENROLLEE_TAG, "Entered registerStatusHandler");\r
+ if(!callback)\r
+ {\r
+ throw ESInvalidParameterException("Callback is empty");\r
+ }\r
+\r
+ if (m_easySetupStatusCb)\r
+ {\r
+ throw ESBadRequestException("Callback handler already registered");\r
+ }\r
+ else\r
+ {\r
+ m_easySetupStatusCb = callback;\r
+\r
+ m_remoteResource = std::make_shared< RemoteEnrolleeResource >(\r
+ m_enrolleeNWProvInfo.netAddressInfo.WIFI.ipAddress,\r
+ m_enrolleeNWProvInfo.connType);\r
+\r
+ m_remoteResource->constructResourceObject();\r
+ }\r
+ }\r
+\r
+ void RemoteEnrollee::provisioningStatusHandler(\r
+ std::shared_ptr< ProvisioningStatus > provStatus)\r
+ {\r
+ OC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Entering ProvisioningStatusHandler");\r
+\r
+ OC_LOG_V(DEBUG,ES_REMOTE_ENROLLEE_TAG,"ProvStatus = %d", provStatus->getESResult());\r
+\r
+ std::shared_ptr< EasySetupStatus > easySetupStatus = nullptr;\r
+\r
+ if (m_enrolleeNWProvInfo.isSecured)\r
+ {\r
+ if (m_currentESState > CurrentESState::ES_OWNED)\r
+ {\r
+ goto CALLBACK_CHECK;\r
+ }\r
+ else\r
+ {\r
+ goto FAILURE;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ goto CALLBACK_CHECK;\r
+ }\r
+\r
+ CALLBACK_CHECK:\r
+\r
+ if (provStatus->getESResult() == ES_OK)\r
+ {\r
+ if (provStatus->getESState() >= ESState::ES_PROVISIONED_ALREADY)\r
+ {\r
+ easySetupStatus = std::make_shared< EasySetupStatus >(DEVICE_PROVISIONED,\r
+ m_enrolleeNWProvInfo);\r
+ }\r
+ else\r
+ {\r
+ easySetupStatus = std::make_shared< EasySetupStatus >(DEVICE_NOT_PROVISIONED,\r
+ m_enrolleeNWProvInfo);\r
+ }\r
+ }\r
+ else\r
+ {\r
+ easySetupStatus = std::make_shared< EasySetupStatus >(DEVICE_NOT_PROVISIONED,\r
+ m_enrolleeNWProvInfo);\r
+ }\r
+\r
+ if (m_easySetupStatusCb)\r
+ {\r
+ if (easySetupStatus)\r
+ {\r
+ m_easySetupStatusCb(easySetupStatus);\r
+ }\r
+ else\r
+ {\r
+ m_easySetupStatusCb(nullptr);\r
+ }\r
+ }\r
+\r
+ return;\r
+\r
+ FAILURE:\r
+\r
+ easySetupStatus = std::make_shared< EasySetupStatus >(DEVICE_NOT_PROVISIONED,\r
+ m_enrolleeNWProvInfo);\r
+\r
+ if (easySetupStatus)\r
+ {\r
+ m_easySetupStatusCb(easySetupStatus);\r
+ }\r
+ else\r
+ {\r
+ m_easySetupStatusCb(nullptr);\r
+ }\r
+ return;\r
+ }\r
+\r
+\r
+ void RemoteEnrollee::startProvisioning()\r
+ {\r
+ OC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Entering startProvisioning");\r
+ if (m_remoteResource == nullptr)\r
+ {\r
+ throw ESBadRequestException ("Device not created");\r
+ }\r
+ else\r
+ {\r
+ m_currentESState = CurrentESState::ES_ONBOARDED;\r
+\r
+ OC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Before ProvisionEnrollee");\r
+\r
+ RemoteEnrolleeResource::ProvStatusCb provStatusCb = std::bind(\r
+ &RemoteEnrollee::provisioningStatusHandler, this, std::placeholders::_1);\r
+\r
+ m_remoteResource->registerProvStatusCallback(provStatusCb);\r
+ m_remoteResource->provisionEnrollee(m_enrolleeNWProvInfo);\r
+ }\r
+ }\r
+\r
+ void RemoteEnrollee::stopProvisioning()\r
+ {\r
+ m_currentESState = CurrentESState::ES_UNKNOWN;\r
+\r
+ m_remoteResource->unprovisionEnrollee();\r
+ }\r
+\r
+ bool RemoteEnrollee::isEnrolleeProvisioned()\r
+ {\r
+ if(m_currentESState >= CurrentESState::ES_PROVISIONED)\r
+ {\r
+ return true;\r
+ }\r
+ else\r
+ {\r
+ return false;\r
+ }\r
+ }\r
+\r
+ EnrolleeNWProvInfo& RemoteEnrollee::getEnrolleeProvisioningInfo ()\r
+ {\r
+ return m_enrolleeNWProvInfo;\r
+ }\r
+ }\r
+}\r
--- /dev/null
+//******************************************************************\r
+//\r
+// Copyright 2015 Samsung Electronics All Rights Reserved.\r
+//\r
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the "License");\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+// http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+//\r
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+\r
+#include <functional>\r
+\r
+#include "RemoteEnrolleeResource.h"\r
+\r
+#include "OCPlatform.h"\r
+#include "ESException.h"\r
+#include "OCResource.h"\r
+#include "logger.h"\r
+\r
+namespace OIC\r
+{\r
+ namespace Service\r
+ {\r
+ #define ES_REMOTE_ENROLLEE_TAG "ES_REMOTE_ENROLLEE"\r
+ static const char ES_RES_URI[] = "/oic/prov";\r
+ static const char ES_RES_TYPE[] = "oic.r.prov";\r
+\r
+ RemoteEnrolleeResource::RemoteEnrolleeResource(const std::string& host,\r
+ OCConnectivityType connectivityType) :\r
+ m_host(host), m_connectivityType(connectivityType)\r
+ {\r
+\r
+ }\r
+\r
+ void RemoteEnrolleeResource::onProvPostResource(const HeaderOptions& /*headerOptions*/,\r
+ const OCRepresentation& rep, const int eCode)\r
+ {\r
+ OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "onProvPostResource : %s, eCode = %d",\r
+ rep.getUri().c_str(),\r
+ eCode);\r
+\r
+ if(eCode != 0)\r
+ {\r
+ OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG,\r
+ "onProvPostResource : Provisioning is failed ");\r
+ std::shared_ptr< ProvisioningStatus > provStatus = std::make_shared<\r
+ ProvisioningStatus >(ESResult::ES_ERROR, ESState::ES_PROVISIONING_ERROR);\r
+ m_provStatusCb(provStatus);\r
+ return;\r
+ }\r
+\r
+ int ps = -1;\r
+ std::string tnn = "";\r
+ std::string cd = "";\r
+\r
+ rep.getValue(OC_RSRVD_ES_PS, ps);\r
+ rep.getValue(OC_RSRVD_ES_TNN, tnn);\r
+ rep.getValue(OC_RSRVD_ES_CD, cd);\r
+\r
+ OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "onProvPostResource : ps - %d",\r
+ ps);OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "onProvResource : tnn - %s",\r
+ tnn.c_str());OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "onProvResource : cd - %s",\r
+ cd.c_str());\r
+\r
+ //Provisioning status check\r
+ if (ps == 0)\r
+ {\r
+ OC::QueryParamsMap query;\r
+ OC::OCRepresentation rep;\r
+\r
+ OCStackResult result = m_ocResource->get(m_ocResource->getResourceTypes().at(0),\r
+ m_ocResource->getResourceInterfaces().at(0), query,\r
+ std::function<\r
+ void(const HeaderOptions& headerOptions,\r
+ const OCRepresentation& rep, const int eCode) >(\r
+ std::bind(&RemoteEnrolleeResource::onProvResource, this,\r
+ std::placeholders::_1, std::placeholders::_2,\r
+ std::placeholders::_3)));\r
+\r
+ if(result != OCStackResult::OC_STACK_OK)\r
+ {\r
+ std::shared_ptr< ProvisioningStatus > provStatus = std::make_shared<\r
+ ProvisioningStatus >(ESResult::ES_ERROR,\r
+ ESState::ES_PROVISIONING_ERROR);\r
+ m_provStatusCb(provStatus);\r
+ return;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG,\r
+ "onProvResource : Provisioning is failed ");\r
+ std::shared_ptr< ProvisioningStatus > provStatus = std::make_shared<\r
+ ProvisioningStatus >(ESResult::ES_ERROR, ESState::ES_PROVISIONING_ERROR);\r
+ m_provStatusCb(provStatus);\r
+ return;\r
+ }\r
+ }\r
+\r
+ void RemoteEnrolleeResource::onProvResource(const HeaderOptions& /*headerOptions*/,\r
+ const OCRepresentation& rep,\r
+ const int eCode)\r
+ {\r
+ OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "onProvResource : %s, eCode = %d",\r
+ rep.getUri().c_str(),\r
+ eCode);\r
+\r
+ if (eCode != 0)\r
+ {\r
+ OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG,\r
+ "onProvResource : Provisioning is failed ");\r
+ std::shared_ptr< ProvisioningStatus > provStatus = std::make_shared<\r
+ ProvisioningStatus >(ESResult::ES_ERROR, ESState::ES_PROVISIONING_ERROR);\r
+ m_provStatusCb(provStatus);\r
+ return;\r
+ }\r
+\r
+ int ps = -1;\r
+ std::string tnn = "";\r
+ std::string cd = "";\r
+\r
+ rep.getValue(OC_RSRVD_ES_PS, ps);\r
+ rep.getValue(OC_RSRVD_ES_TNN, tnn);\r
+ rep.getValue(OC_RSRVD_ES_CD, cd);\r
+\r
+ OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "onProvResource : ps - %d",\r
+ ps);\r
+ OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "onProvResource : tnn - %s",\r
+ tnn.c_str());\r
+ OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "onProvResource : cd - %s",\r
+ cd.c_str());\r
+\r
+ if (ps == 1) //ps == 1 indicates the need for provisioning\r
+ {\r
+ OCRepresentation provisioningRepresentation;\r
+\r
+ provisioningRepresentation.setValue(OC_RSRVD_ES_TNN,\r
+ m_enrolleeNWProvInfo.netAddressInfo.WIFI.ssid);\r
+ provisioningRepresentation.setValue(OC_RSRVD_ES_CD,\r
+ m_enrolleeNWProvInfo.netAddressInfo.WIFI.pwd);\r
+\r
+ OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "onProvResource : ssid - %s",\r
+ m_enrolleeNWProvInfo.netAddressInfo.WIFI.ssid);\r
+ OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "onProvResource : pwd - %s",\r
+ m_enrolleeNWProvInfo.netAddressInfo.WIFI.pwd);\r
+\r
+ m_ocResource->put(provisioningRepresentation, QueryParamsMap(),\r
+ std::function<\r
+ void(const HeaderOptions& headerOptions,\r
+ const OCRepresentation& rep, const int eCode) >(\r
+ std::bind(&RemoteEnrolleeResource::onProvPostResource, this,\r
+ std::placeholders::_1, std::placeholders::_2,\r
+ std::placeholders::_3)));\r
+ }\r
+ else if(ps == 0) //ps == 1 indicates that provisioning is completed\r
+ {\r
+ OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG,\r
+ "onProvResource : Provisioning is successful");\r
+ std::shared_ptr< ProvisioningStatus > provStatus = std::make_shared<\r
+ ProvisioningStatus >(ESResult::ES_OK, ESState::ES_PROVISIONED_ALREADY);\r
+ m_provStatusCb(provStatus);\r
+ }\r
+ }\r
+\r
+ void RemoteEnrolleeResource::registerProvStatusCallback (ProvStatusCb provStatusCb)\r
+ {\r
+ m_provStatusCb = provStatusCb;\r
+ }\r
+\r
+ void RemoteEnrolleeResource::constructResourceObject()\r
+ {\r
+ if (m_ocResource != nullptr)\r
+ {\r
+ throw ESBadRequestException("Remote resource is already created");\r
+ }\r
+\r
+ try\r
+ {\r
+
+ std::vector< std::string > m_if = { DEFAULT_INTERFACE };\r
+ std::vector< std::string > m_resTypes = {ES_RES_TYPE};\r
+\r
+\r
+ OC_LOG(DEBUG, ES_REMOTE_ENROLLEE_TAG, "Before OCPlatform::constructResourceObject");\r
+\r
+ OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "m_host = %s", m_host.c_str());\r
+ OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "ES_RES_URI = %s", ES_RES_URI);\r
+ OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "m_connectivityType = %d",\r
+ m_connectivityType);\r
+ OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "m_resTypes = %s",\r
+ m_resTypes.at(0).c_str());\r
+ OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "m_if = %s", m_if.at(0).c_str());\r
+\r
+ std::string host;\r
+ if(m_enrolleeNWProvInfo.isSecured)\r
+ {\r
+ host.append("coaps://");\r
+ }\r
+ else\r
+ {\r
+ host.append("coap://");\r
+ }\r
+\r
+ if(m_connectivityType == CT_ADAPTER_IP)\r
+ {\r
+ host.append(m_host);\r
+ //TODO : If the target Enrollee is not a Arduino Wi-Fi device, then m_ocResource\r
+ // will be discovered using findResource API of OCPlatform instead of using\r
+ // constructResourceObject API. The port number thus will be found during\r
+ // resource discovery instead of using 55555\r
+ host.append(":55555");\r
+ }\r
+\r
+ OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "HOST = %s", host.c_str());\r
+\r
+ m_ocResource = OC::OCPlatform::constructResourceObject(host,\r
+ ES_RES_URI,\r
+ m_connectivityType,\r
+ true,\r
+ m_resTypes,\r
+ m_if);\r
+ OC_LOG_V(DEBUG, ES_REMOTE_ENROLLEE_TAG,\r
+ "created OCResource : %s", m_ocResource->uri().c_str());\r
+ }\r
+ catch (OCException & e)\r
+ {\r
+ OC_LOG_V(ERROR, ES_REMOTE_ENROLLEE_TAG,\r
+ "Exception for constructResourceObject : %s", e.reason().c_str());\r
+ }\r
+ }\r
+\r
+ void RemoteEnrolleeResource::provisionEnrollee(const EnrolleeNWProvInfo& enrolleeNWProvInfo)\r
+\r
+ {\r
+ if(m_ocResource == nullptr)\r
+ {\r
+ throw ESBadRequestException ("Resource is not initialized");\r
+ }\r
+\r
+ m_enrolleeNWProvInfo = enrolleeNWProvInfo;\r
+ OC::QueryParamsMap query;\r
+ OC::OCRepresentation rep;\r
+\r
+ OCStackResult result = m_ocResource->get(m_ocResource->getResourceTypes().at(0),\r
+ m_ocResource->getResourceInterfaces().at(0), query,\r
+ std::function<\r
+ void(const HeaderOptions& headerOptions, const OCRepresentation& rep,\r
+ const int eCode) >(\r
+ std::bind(&RemoteEnrolleeResource::onProvResource, this,\r
+ std::placeholders::_1, std::placeholders::_2,\r
+ std::placeholders::_3)));\r
+\r
+ if (result != OCStackResult::OC_STACK_OK)\r
+ {\r
+ std::shared_ptr< ProvisioningStatus > provStatus = std::make_shared<\r
+ ProvisioningStatus >(ESResult::ES_ERROR, ESState::ES_PROVISIONING_ERROR);\r
+ m_provStatusCb(provStatus);\r
+ return;\r
+ }\r
+ }\r
+\r
+ void RemoteEnrolleeResource::unprovisionEnrollee()\r
+ {\r
+ if (m_ocResource == nullptr)\r
+ {\r
+ throw ESBadRequestException("Resource is not initialized");\r
+ }\r
+\r
+ OCRepresentation provisioningRepresentation;\r
+\r
+ provisioningRepresentation.setValue(OC_RSRVD_ES_TNN, "");\r
+ provisioningRepresentation.setValue(OC_RSRVD_ES_CD, "");\r
+\r
+ m_ocResource->post(provisioningRepresentation, QueryParamsMap(),\r
+ std::function<\r
+ void(const HeaderOptions& headerOptions, const OCRepresentation& rep,\r
+ const int eCode) >(\r
+ std::bind(&RemoteEnrolleeResource::onProvPostResource, this,\r
+ std::placeholders::_1, std::placeholders::_2,\r
+ std::placeholders::_3)));\r
+ }\r
+ }\r
+}\r
--- /dev/null
+//******************************************************************\r
+//\r
+// Copyright 2015 Samsung Electronics All Rights Reserved.\r
+//\r
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the "License");\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+// http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+//\r
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+\r
+#ifndef REMOTE_ENROLLEE_RESOURCE_H_\r
+#define REMOTE_ENROLLEE_RESOURCE_H_\r
+\r
+#include <mutex>\r
+#include <memory>\r
+\r
+#include "escommon.h"\r
+\r
+#include "OCApi.h"\r
+\r
+using namespace OC;\r
+\r
+namespace OIC\r
+{\r
+ namespace Service\r
+ {\r
+ class OCResource;\r
+\r
+ /**\r
+ * This class contains the resource discovery methods.\r
+ *\r
+ * @see RemoteEnrolleeResource\r
+ */\r
+ class RemoteEnrolleeResource\r
+ {\r
+ public:\r
+ typedef std::shared_ptr< RemoteEnrolleeResource > Ptr;\r
+\r
+ typedef std::function< void(std::shared_ptr< ProvisioningStatus > provStatus) > ProvStatusCb;\r
+\r
+ /**\r
+ * RemoteEnrolleeResource constructor\r
+ *\r
+ * @param host Host information of the Enrollee device obtained from OnBoarding process.\r
+ * @param connectivityType Connectivity type on which OnBoarding is performed\r
+ *\r
+ * @throw ESBadRequestException is thrown if the parameters are invalid\r
+ */\r
+ RemoteEnrolleeResource(const std::string& host, OCConnectivityType connectivityType);\r
+\r
+ ~RemoteEnrolleeResource() = default;\r
+\r
+ /**\r
+ * Register provisioning status handler.\r
+ *\r
+ * @param callback Callback to get Provisioning status.\r
+ *\r
+ * @throws InvalidParameterException If callback is an empty function or null.\r
+ * @throws ESBadRequestException If registration is already completed.\r
+ *\r
+ * @see ProvisioningStatus\r
+ */\r
+ void registerProvStatusCallback (ProvStatusCb provStatusCb);\r
+\r
+ /**\r
+ * Construct Remote OIC resource using the enrollee host and connectivity information\r
+ * provided in the constructor of RemoteEnrolleeResource.\r
+ *\r
+ * @throws InvalidParameterException If the provided information is invalid.\r
+ * @throws ESBadRequestException If resource is already constructed.\r
+ *\r
+ * @see ProvisioningStatus\r
+ */\r
+ void constructResourceObject();\r
+\r
+ /**\r
+ * Function for provisioning of Remote Enrollee resource using the information provided.\r
+ *\r
+ * @param enrolleeNWProvInfo Provisioning information for the Enrollee\r
+ *\r
+ * @throws InvalidParameterException If cb is empty.\r
+ */\r
+ virtual void provisionEnrollee(const EnrolleeNWProvInfo& enrolleeNWProvInfo);\r
+\r
+ /**\r
+ * Function for unprovisioning of Remote Enrollee and bring to unprovisioned state\r
+ *\r
+ * @throws ESBadRequestException If device is not provisioned already.\r
+ */\r
+ virtual void unprovisionEnrollee();\r
+\r
+\r
+\r
+ private:\r
+ std::shared_ptr< OC::OCResource > m_ocResource;\r
+ std::mutex m_mutex;\r
+ std::string m_host;\r
+ OCConnectivityType m_connectivityType;\r
+ ProvStatusCb m_provStatusCb;\r
+ EnrolleeNWProvInfo m_enrolleeNWProvInfo;\r
+\r
+ void onProvResource(const HeaderOptions& headerOptions, const OCRepresentation& rep,\r
+ const int eCode);\r
+\r
+ void onProvPostResource(const HeaderOptions& headerOptions, const OCRepresentation& rep,\r
+ const int eCode);\r
+ };\r
+ }\r
+}\r
+#endif\r
if (InitProvisioningHandler() == OC_STACK_OK) {
result = OC_STACK_OK;
- OIC_LOG(DEBUG, ES_PROV_ADAP_TAG, "InitProvisioningHandler returned Success");
+ OC_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",
+ OC_LOG_V(ERROR, ES_PROV_ADAP_TAG, "InitProvisioningHandler returned error = %d",
result);
}
}
else {
result = OC_STACK_ERROR;
- OIC_LOG(ERROR, ES_PROV_ADAP_TAG, "provisioningStatusCallback is NULL");
+ OC_LOG(ERROR, ES_PROV_ADAP_TAG, "provisioningStatusCallback is NULL");
}
return result;
}
}
-OCStackResult StartProvisioning(const EnrolleeNWProvInfo_t *netInfo) {
+OCStackResult StartProvisioning(const EnrolleeNWProvInfo *netInfo) {
char findQuery[64] = {0};
snprintf(findQuery, sizeof(findQuery) - 1, UNICAST_PROVISIONING_QUERY,
void UnRegisterCallback();
-OCStackResult StartProvisioning(const EnrolleeNWProvInfo_t *netInfo);
+OCStackResult StartProvisioning(const EnrolleeNWProvInfo *netInfo);
OCStackResult StopProvisioning(OCConnectivityType connectivityType);
bool g_provisioningCondFlag = false;
-static EnrolleeNWProvInfo_t *netProvInfo;
+static EnrolleeNWProvInfo *netProvInfo;
char szFindResourceQueryUri[64] = {0};
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");
+ OC_LOG(ERROR, ES_PROV_TAG, "OCStack init error");
return ret;
}
pthread_t thread_handle;
if (pthread_create(&thread_handle, NULL, listeningFunc, NULL)) {
- OIC_LOG(DEBUG, ES_PROV_TAG, "Thread creation failed");
+ OC_LOG(DEBUG, ES_PROV_TAG, "Thread creation failed");
return OC_STACK_ERROR;
}
OCStackResult TerminateProvisioningHandler() {
OCStackResult ret = OC_STACK_ERROR;
if (OCStop() != OC_STACK_OK) {
- OIC_LOG(ERROR, ES_PROV_TAG, "OCStack stop error");
+ OC_LOG(ERROR, ES_PROV_TAG, "OCStack stop error");
}
g_provisioningCondFlag = true;
result = OCProcess();
if (result != OC_STACK_OK) {
- OIC_LOG(ERROR, ES_PROV_TAG, "OCStack stop error");
+ OC_LOG(ERROR, ES_PROV_TAG, "OCStack stop error");
}
// To minimize CPU utilization we may wish to do this with sleep
OCStackApplicationResult ProvisionEnrolleeResponse(void* /*ctx*/, OCDoHandle /*handle*/,
OCClientResponse *clientResponse) {
- OIC_LOG_V(DEBUG, ES_PROV_TAG, "INSIDE ProvisionEnrolleeResponse");
+ OC_LOG_V(DEBUG, ES_PROV_TAG, "INSIDE ProvisionEnrolleeResponse");
// If user stopped the process then return from this function;
if (IsSetupStopped()) {
continue;
}
else {
- OIC_LOG_V(DEBUG, ES_PROV_TAG, "PS is NOT proper");
+ OC_LOG_V(DEBUG, ES_PROV_TAG, "PS is NOT proper");
goto Error;
}
if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_TNN, &tnn)) {
if (!strcmp(tnn, netProvInfo->netAddressInfo.WIFI.ssid)) {
- OIC_LOG_V(DEBUG, ES_PROV_TAG, "SSID is proper");
+ OC_LOG_V(DEBUG, ES_PROV_TAG, "SSID is proper");
input = input->next;
continue;
}
else {
- OIC_LOG_V(DEBUG, ES_PROV_TAG, "SSID is NOT proper");
+ OC_LOG_V(DEBUG, ES_PROV_TAG, "SSID is NOT proper");
goto Error;
}
}
if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_CD, &cd)) {
if (!strcmp(cd, netProvInfo->netAddressInfo.WIFI.pwd)) {
- OIC_LOG_V(DEBUG, ES_PROV_TAG, "Password is proper");
+ OC_LOG_V(DEBUG, ES_PROV_TAG, "Password is proper");
input = input->next;
continue;
}
else {
- OIC_LOG_V(DEBUG, ES_PROV_TAG, "Password is NOT proper");
+ OC_LOG_V(DEBUG, ES_PROV_TAG, "Password is NOT proper");
goto Error;
}
}
}
-OCStackResult StartProvisioningProcess(const EnrolleeNWProvInfo_t *netInfo,
+OCStackResult StartProvisioningProcess(const EnrolleeNWProvInfo *netInfo,
OCProvisioningStatusCB provisioningStatusCallback,
char *findResQuery) {
}
else
{
- OIC_LOG(ERROR, ES_PROV_TAG, PCF("Find resource query is NULL"));
+ OC_LOG(ERROR, ES_PROV_TAG, PCF("Find resource query is NULL"));
goto Error;
}
if (!SetProgress(provisioningStatusCallback)) {
// Device provisioning session is running already.
- OIC_LOG(INFO, ES_PROV_TAG, PCF("Device provisioning session is running already"));
+ OC_LOG(INFO, ES_PROV_TAG, PCF("Device provisioning session is running already"));
goto Error;
}
bool ClearMemory() {
- OIC_LOG(DEBUG, ES_PROV_TAG, "thread_pool_add_task of FindProvisioningResource failed");
+ OC_LOG(DEBUG, ES_PROV_TAG, "thread_pool_add_task of FindProvisioningResource failed");
OICFree(netProvInfo);
return true;
}
-bool ConfigEnrolleeObject(const EnrolleeNWProvInfo_t *netInfo) {
+bool ConfigEnrolleeObject(const EnrolleeNWProvInfo *netInfo) {
//Copy Network Provisioning Information
- netProvInfo = (EnrolleeNWProvInfo_t *) OICCalloc(1, sizeof(EnrolleeNWProvInfo_t));
+ netProvInfo = (EnrolleeNWProvInfo *) OICCalloc(1, sizeof(EnrolleeNWProvInfo));
if (netProvInfo == NULL) {
- OIC_LOG(ERROR, ES_PROV_TAG, "Invalid input..");
+ OC_LOG(ERROR, ES_PROV_TAG, "Invalid input..");
return false;
}
- memcpy(netProvInfo, netInfo, sizeof(EnrolleeNWProvInfo_t));
+ memcpy(netProvInfo, netInfo, sizeof(EnrolleeNWProvInfo));
- OIC_LOG_V(DEBUG, ES_PROV_TAG, "Network Provisioning Info. SSID = %s",
+ OC_LOG_V(DEBUG, ES_PROV_TAG, "Network Provisioning Info. SSID = %s",
netProvInfo->netAddressInfo.WIFI.ssid);
- OIC_LOG_V(DEBUG, ES_PROV_TAG, "Network Provisioning Info. PWD = %s",
+ OC_LOG_V(DEBUG, ES_PROV_TAG, "Network Provisioning Info. PWD = %s",
netProvInfo->netAddressInfo.WIFI.pwd);
return true;
switch (val->type) {
case OCREP_PROP_NULL:
- OIC_LOG_V(DEBUG, ES_PROV_TAG, "\t\t%s: NULL", val->name);
+ OC_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):%ld", val->name, val->i);
+ OC_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);
+ OC_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");
+ OC_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);
+ OC_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);
+ OC_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",
+ OC_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",
+ OC_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",
+ OC_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",
+ OC_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",
+ OC_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]);
OCStackResult FindNetworkResource() {
OCStackResult ret = OC_STACK_ERROR;
if (OCStop() != OC_STACK_OK) {
- OIC_LOG(ERROR, ES_PROV_TAG, "OCStack stop error");
+ OC_LOG(ERROR, ES_PROV_TAG, "OCStack stop error");
}
return ret;
ProvisioningInfo *provInfo = (ProvisioningInfo *) OICCalloc(1, sizeof(ProvisioningInfo));
if (provInfo == NULL) {
- OIC_LOG_V(ERROR, ES_PROV_TAG, "Failed to allocate memory");
+ OC_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");
+ OC_LOG_V(ERROR, ES_PROV_TAG, "Failed to allocate memory");
OICFree(provInfo);
return NULL;
}
// 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");
+ OC_LOG(ERROR, ES_PROV_TAG, "Easy setup session is already in progress");
return true;
}
ProvisioningInfo *provInfo = (ProvisioningInfo *) OICCalloc(1, sizeof(ProvisioningInfo));
if (provInfo == NULL) {
- OIC_LOG_V(ERROR, ES_PROV_TAG, "Failed to allocate memory");
+ OC_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");
+ OC_LOG_V(ERROR, ES_PROV_TAG, "Failed to allocate memory");
OICFree(provInfo);
return NULL;
}
if (!(clientResponse) || !(clientResponse->payload)) {
- OIC_LOG_V(INFO, ES_PROV_TAG, "ProvisionEnrolleeResponse received Null clientResponse");
+ OC_LOG_V(INFO, ES_PROV_TAG, "ProvisionEnrolleeResponse received Null clientResponse");
return false;
if (!(clientResponse) || !(clientResponse->payload)) {
- OIC_LOG_V(INFO, ES_PROV_TAG, "ProvisionEnrolleeResponse received Null clientResponse");
+ OC_LOG_V(INFO, ES_PROV_TAG, "ProvisionEnrolleeResponse received Null clientResponse");
return false;
if (clientResponse->payload->type != PAYLOAD_TYPE_REPRESENTATION) {
- OIC_LOG_V(DEBUG, ES_PROV_TAG, "Incoming payload not a representation");
+ OC_LOG_V(DEBUG, ES_PROV_TAG, "Incoming payload not a representation");
return false;
}
OCStackResult ret = OC_STACK_ERROR;
- OIC_LOG_V(DEBUG, ES_PROV_TAG, "szFindResourceQueryUri = %s", szFindResourceQueryUri);
+ OC_LOG_V(DEBUG, ES_PROV_TAG, "szFindResourceQueryUri = %s", szFindResourceQueryUri);
OCCallbackData ocCBData;
&cbData, options, numOptions);
if (ret != OC_STACK_OK) {
- OIC_LOG_V(ERROR, ES_PROV_TAG, "OCDoResource returns error %d with method %d", ret, method);
+ OC_LOG_V(ERROR, ES_PROV_TAG, "OCDoResource returns error %d with method %d", ret, method);
}
return ret;
// 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);
+ OC_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__);
+ OC_LOG_V(INFO, ES_PROV_TAG, "\n\nExecuting ProvisionEnrollee%s", __func__);
OCRepPayload *payload = OCRepPayloadCreate();
OCRepPayloadSetPropString(payload, OC_RSRVD_ES_TNN, netProvInfo->netAddressInfo.WIFI.ssid);
OCRepPayloadSetPropString(payload, OC_RSRVD_ES_CD, netProvInfo->netAddressInfo.WIFI.pwd);
- OIC_LOG_V(DEBUG, ES_PROV_TAG, "OCPayload ready for ProvisionEnrollee");
+ OC_LOG_V(DEBUG, ES_PROV_TAG, "OCPayload ready for ProvisionEnrollee");
OCStackResult ret = InvokeOCDoResource(query, OC_REST_PUT, destination, qos,
ProvisionEnrolleeResponse, payload, NULL, 0);
OCStackResult GetProvisioningStatus(OCQualityOfService qos, const char *query,
const OCDevAddr *destination);
-OCStackResult StartProvisioningProcess(const EnrolleeNWProvInfo_t *netInfo,
+OCStackResult StartProvisioningProcess(const EnrolleeNWProvInfo *netInfo,
OCProvisioningStatusCB provisioningStatusCallback,
char *findResQuery);
void LogProvisioningResponse(OCRepPayloadValue * val);
-bool ConfigEnrolleeObject(const EnrolleeNWProvInfo_t *netInfo);
+bool ConfigEnrolleeObject(const EnrolleeNWProvInfo *netInfo);
bool ClearMemory();
bool InProgress();
-bool ValidateEasySetupParams(const EnrolleeNWProvInfo_t *netInfo,
+bool ValidateEasySetupParams(const EnrolleeNWProvInfo *netInfo,
OCProvisioningStatusCB provisioningStatusCallback);
bool IsSetupStopped();
char resURI[MAX_URI_LENGTH] =
{'\0'};
- OIC_LOG_V(DEBUG, ES_WIFI_PROV_TAG, "resUri = %s", input->uri);
+ OC_LOG_V(DEBUG, ES_WIFI_PROV_TAG, "resUri = %s", input->uri);
strncpy(resURI, input->uri, sizeof(resURI) - 1);
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");
+ OC_LOG(INFO, ES_WIFI_PROV_TAG, "GetProvisioningStatusResponse received NULL clientResponse");
ErrorCallback(DEVICE_NOT_PROVISIONED);
ClearMemory();
OCStackResult ret = OC_STACK_ERROR;
OCHeaderOption options[MAX_HEADER_OPTIONS];
- OIC_LOG_V(INFO, ES_WIFI_PROV_TAG, "\n\nExecuting %s", __func__);
+ OC_LOG_V(INFO, ES_WIFI_PROV_TAG, "\n\nExecuting %s", __func__);
uint8_t option0[] =
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
OCDoHandle /*handle*/,
OCClientResponse *clientResponse) {
- OIC_LOG(INFO, ES_WIFI_PROV_TAG, PCF("Entering FindProvisioningResourceResponse"));
+ OC_LOG(INFO, ES_WIFI_PROV_TAG, PCF("Entering FindProvisioningResourceResponse"));
// If user stopped the process then return from this function;
if (IsSetupStopped()) {
OCDiscoveryPayload *discoveryPayload = (OCDiscoveryPayload * )(clientResponse->payload);
- OIC_LOG_V(DEBUG, ES_WIFI_PROV_TAG, "resUri = %s", discoveryPayload->resources->uri);
+ OC_LOG_V(DEBUG, ES_WIFI_PROV_TAG, "resUri = %s", discoveryPayload->resources->uri);
snprintf(szQueryUri, sizeof(szQueryUri), UNICAST_PROV_STATUS_QUERY,
clientResponse->devAddr.addr, IP_PORT, discoveryPayload->resources->uri);
- OIC_LOG_V(DEBUG, ES_WIFI_PROV_TAG, "query before GetProvisioningStatus call = %s", szQueryUri);
+ OC_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);
}
-bool ValidateEasySetupParams(const EnrolleeNWProvInfo_t *netInfo,
+bool ValidateEasySetupParams(const EnrolleeNWProvInfo *netInfo,
OCProvisioningStatusCB provisioningStatusCallback) {
if (netInfo == NULL || strlen(netInfo->netAddressInfo.WIFI.ipAddress) == 0) {
- OIC_LOG(ERROR, ES_WIFI_PROV_TAG, "Request URI is NULL");
+ OC_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");
+ OC_LOG(ERROR, ES_WIFI_PROV_TAG, "ProvisioningStatusCallback is NULL");
return false;
}