void updateWiFiResource(OCRepPayload* input)
{
ESWiFiProvData* wiFiData = (ESWiFiProvData*)OICMalloc(sizeof(ESWiFiProvData));
+
if(wiFiData == NULL)
{
OIC_LOG(DEBUG, ES_RH_TAG, "OICMalloc is failed");
+ return ;
}
+
+ memset(wiFiData->ssid, 0, MAX_SSIDLEN);
+ memset(wiFiData->pwd, 0, MAX_CREDLEN);
+ wiFiData->authtype = NONE_AUTH;
+ wiFiData->enctype = NONE_AUTH;
wiFiData->userdata = NULL;
char* ssid = NULL;
void updateCloudResource(OCRepPayload* input)
{
ESCloudProvData* cloudData = (ESCloudProvData*)OICMalloc(sizeof(ESCloudProvData));
+
if(cloudData == NULL)
{
OIC_LOG(DEBUG, ES_RH_TAG, "OICMalloc is failed");
+ return;
}
+
+ memset(cloudData->authCode, 0, OIC_STRING_MAX_VALUE);
+ memset(cloudData->authProvider, 0, OIC_STRING_MAX_VALUE);
+ memset(cloudData->ciServer, 0, OIC_STRING_MAX_VALUE);
cloudData->userdata = NULL;
char *authCode = NULL;
void updateDevConfResource(OCRepPayload* input)
{
ESDevConfProvData* devConfData = (ESDevConfProvData*)OICMalloc(sizeof(ESDevConfProvData));
+
if(devConfData == NULL)
{
OIC_LOG(DEBUG, ES_RH_TAG, "OICMalloc is failed");
+ return;
}
+ memset(devConfData->language, 0, OIC_STRING_MAX_VALUE);
+ memset(devConfData->country, 0, OIC_STRING_MAX_VALUE);
devConfData->userdata = NULL;
char *country = NULL;
size_t dimensions[MAX_REP_ARRAY_DEPTH] = {gWiFiResource.numMode, 0, 0};
int64_t *modes_64 = (int64_t *)OICMalloc(gWiFiResource.numMode * sizeof(int64_t));
for(int i = 0 ; i < gWiFiResource.numMode ; ++i)
+ {
modes_64[i] = gWiFiResource.supportedMode[i];
+ }
OCRepPayloadSetIntArray(payload, OC_RSRVD_ES_SUPPORTEDWIFIMODE, (int64_t *)modes_64, dimensions);
OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_SUPPORTEDWIFIFREQ, gWiFiResource.supportedFreq);
payload->next = constructResponseOfWiFi();
if(payload->next)
+ {
payload->next->next = constructResponseOfCloud();
+ }
else
+ {
return payload;
+ }
if(payload->next->next)
+ {
payload->next->next->next = constructResponseOfDevConf();
+ }
else
+ {
return payload;
+ }
}
}
MockRepository mocks;
protected:
- virtual ~TestWithMock() noexcept(noexcept(std::declval<Test>().~Test())) {}
+ virtual ~TestWithMock() noexcept(noexcept(std::declval<Test>().~Test()))
+ {
+ }
- virtual void TearDown() {
+ virtual void TearDown()
+ {
try
{
mocks.VerifyAll();
{
EnrolleeStatus enrolleeStatus = status->getEnrolleeStatus();
+
if(enrolleeStatus.getProvStatus() == ES_STATE_CONNECTED_TO_ENROLLER &&
enrolleeStatus.getLastErrCode() == ES_ERRCODE_NO_INTERNETCONNECTION)
+ {
isWellConstructed = true;
+ }
}
});
ESResult ret = startEnrollee();
!strcmp(data->pwd, "Iotivity_PWD") &&
data->authtype == WPA2_PSK &&
data->enctype == TKIP_AES)
+ {
cntForReceivedCallbackWithSuccess++;
+ }
});
mocks.OnCallFunc(DevConfProvCbInApp).Do(
[& cntForReceivedCallbackWithSuccess](ESDevConfProvData *data)
{
if(!strcmp(data->language, "korean") &&
!strcmp(data->country, "Korea"))
+ {
cntForReceivedCallbackWithSuccess++;
+ }
});
startEnrollee();
{
// Will called twice
if(status->getESResult() == ES_OK)
+ {
cntForReceivedCallbackWithSuccess++;
+ }
});
mocks.OnCallFunc(CloudDataCbInApp).Do(
if(!strcmp(data->authCode, "authCode") &&
!strcmp(data->authProvider, "authProvider") &&
!strcmp(data->ciServer, "ciServer"))
+ {
cntForReceivedCallbackWithSuccess++;
+ }
});
startEnrollee();
public:
ESMediatorSimulator()
: m_remoteEnrollee(), m_discoveryCb(), m_getConfigurationCb(), m_getStatusCb(),
- m_DevicePropProvisioningCb(), m_CloudPropProvisioningCb() { };
+ m_DevicePropProvisioningCb(), m_CloudPropProvisioningCb()
+ {
+ };
~ESMediatorSimulator() = default;
-
+
ESMediatorSimulator(const ESMediatorSimulator &) = delete;
ESMediatorSimulator & operator = (const ESMediatorSimulator &) = delete;
OCConnectivityType::CT_DEFAULT,
std::bind(&ESMediatorSimulator::discoverRemoteEnrolleeCb,
this, std::placeholders::_1));
-
+
}
void getConfiguration(std::function<void(std::shared_ptr< GetConfigurationStatus >)> cb)
OC::OCPlatform::findResource("", uri,
OCConnectivityType::CT_DEFAULT,
std::bind(&ESMediatorSimulator::discoverRemoteEnrolleeCbToGetConfiguration,
- this, std::placeholders::_1));
+ this, std::placeholders::_1));
}
void getStatus(std::function<void(std::shared_ptr< GetEnrolleeStatus >)> cb)
OC::OCPlatform::findResource("", uri,
OCConnectivityType::CT_DEFAULT,
std::bind(&ESMediatorSimulator::discoverRemoteEnrolleeCbToGetStatus,
- this, std::placeholders::_1));
+ this, std::placeholders::_1));
}
void provisionDeviceProperties(std::function<void(std::shared_ptr< DevicePropProvisioningStatus >)> cb)
OC::OCPlatform::findResource("", uri,
OCConnectivityType::CT_DEFAULT,
std::bind(&ESMediatorSimulator::discoverRemoteEnrolleeCbToProvisionDeviceProperties,
- this, std::placeholders::_1));
+ this, std::placeholders::_1));
}
void provisionCloudProperties(std::function<void(std::shared_ptr< CloudPropProvisioningStatus >)> cb)
OC::OCPlatform::findResource("", uri,
OCConnectivityType::CT_DEFAULT,
std::bind(&ESMediatorSimulator::discoverRemoteEnrolleeCbToProvisionCloudProperties,
- this, std::placeholders::_1));
+ this, std::placeholders::_1));
}
private:
m_discoveryCb(resource);
m_discoveryCb = NULL;
}
- }
+ }
void getConfigurationCallback(std::shared_ptr< GetConfigurationStatus > getConfigurationStatus)
{
if(m_getConfigurationCb != NULL)
{
m_getConfigurationCb(getConfigurationStatus);
- m_getConfigurationCb = NULL;
+ m_getConfigurationCb = NULL;
}
}
void discoverRemoteEnrolleeCbToGetConfiguration(std::shared_ptr<OC::OCResource> resource)
- {
+ {
if(!resource->getResourceTypes().at(0).compare(PROV_RESOURCE_TYPE) && m_getConfigurationCb
&& !m_remoteEnrollee)
{
if(m_remoteEnrollee != NULL)
{
m_remoteEnrollee->getConfiguration(std::bind(
- &ESMediatorSimulator::getConfigurationCallback, this, std::placeholders::_1));
+ &ESMediatorSimulator::getConfigurationCallback, this, std::placeholders::_1));
}
}
}
if(m_remoteEnrollee != NULL)
{
m_remoteEnrollee->getStatus(std::bind(
- &ESMediatorSimulator::getStatusCallback, this, std::placeholders::_1));
+ &ESMediatorSimulator::getStatusCallback, this, std::placeholders::_1));
}
}
}
DeviceProp devProp;
devProp.setWiFiProp("Iotivity_SSID", "Iotivity_PWD", WPA2_PSK, TKIP_AES);
devProp.setDevConfProp("korean", "Korea");
-
- m_remoteEnrollee->provisionDeviceProperties(devProp,
- std::bind(&ESMediatorSimulator::deviceProvisioningStatusCallback,
+
+ m_remoteEnrollee->provisionDeviceProperties(devProp,
+ std::bind(&ESMediatorSimulator::deviceProvisioningStatusCallback,
this, std::placeholders::_1));
}
}
void cloudProvisioningStatusCallback(std::shared_ptr< CloudPropProvisioningStatus >
cloudPropProvisioningStatus)
- {
+ {
if(m_CloudPropProvisioningCb != NULL)
{
m_CloudPropProvisioningCb(cloudPropProvisioningStatus);
- if(cloudPropProvisioningStatus->getESCloudState() == ES_CLOUD_PROVISIONING_SUCCESS)
+ if(cloudPropProvisioningStatus->getESCloudState() == ES_CLOUD_PROVISIONING_SUCCESS)
+ {
m_CloudPropProvisioningCb = NULL;
+ }
}
}
void discoverRemoteEnrolleeCbToProvisionCloudProperties(std::shared_ptr<OC::OCResource> resource)
- {
+ {
if(!resource->getResourceTypes().at(0).compare(PROV_RESOURCE_TYPE) &&
m_CloudPropProvisioningCb && !m_remoteEnrollee)
{
m_remoteEnrollee = EasySetup::getInstance()->createRemoteEnrollee(resource);
if(m_remoteEnrollee != NULL)
- {
+ {
CloudProp cloudProp;
cloudProp.setCloudProp("authCode", "authProvider", "ciServer");
- m_remoteEnrollee->provisionCloudProperties(cloudProp,
- std::bind(&ESMediatorSimulator::cloudProvisioningStatusCallback,
+ m_remoteEnrollee->provisionCloudProperties(cloudProp,
+ std::bind(&ESMediatorSimulator::cloudProvisioningStatusCallback,
this, std::placeholders::_1));
}
}
/**
* Constructor
*/
- EnrolleeStatus(const OCRepresentation& rep) { m_rep = rep; }
+ EnrolleeStatus(const OCRepresentation& rep)
+ {
+ m_rep = rep;
+ }
EnrolleeStatus(const EnrolleeStatus& enrolleeStatus) :
m_rep(enrolleeStatus.getRepresentation())
ProvStatus getProvStatus()
{
if(m_rep.hasAttribute(OC_RSRVD_ES_PROVSTATUS))
+ {
return static_cast<ProvStatus>(
m_rep.getValue<int>(OC_RSRVD_ES_PROVSTATUS));
+ }
return ES_STATE_INIT;
}
ESErrorCode getLastErrCode()
{
if(m_rep.hasAttribute(OC_RSRVD_ES_LAST_ERRORCODE))
+ {
return static_cast<ESErrorCode>(
m_rep.getValue<int>(OC_RSRVD_ES_LAST_ERRORCODE));
+ }
return ES_ERRCODE_NO_ERROR;
}
/**
* Constructor
*/
- CloudProp() {};
+ CloudProp()
+ {
+ };
/**
* Constructor with OCRepresentation object. This is used for JNI communication.
std::string getAuthCode()
{
if(m_rep.hasAttribute(OC_RSRVD_ES_AUTHCODE))
+ {
return m_rep.getValue<std::string>(OC_RSRVD_ES_AUTHCODE);
+ }
return std::string("");
}
std::string getAuthProvider()
{
if(m_rep.hasAttribute(OC_RSRVD_ES_AUTHPROVIDER))
+ {
return m_rep.getValue<std::string>(OC_RSRVD_ES_AUTHPROVIDER);
+ }
return std::string("");
}
std::string getCiServer()
{
if(m_rep.hasAttribute(OC_RSRVD_ES_CISERVER))
+ {
return m_rep.getValue<std::string>(OC_RSRVD_ES_CISERVER);
+ }
return std::string("");
}
/**
* Constructor with OCRepresentation object. This is used for JNI communication.
*/
- DeviceProp(const OCRepresentation &rep) { m_rep = rep; }
+ DeviceProp(const OCRepresentation &rep)
+ {
+ m_rep = rep;
+ }
/**
* Set WiFi resource properties to be delivered to Enrollee
std::string getSsid()
{
if(m_rep.hasAttribute(OC_RSRVD_ES_SSID))
+ {
return m_rep.getValue<std::string>(OC_RSRVD_ES_SSID);
+ }
return std::string("");
}
std::string getPassword()
{
if(m_rep.hasAttribute(OC_RSRVD_ES_CRED))
+ {
return m_rep.getValue<std::string>(OC_RSRVD_ES_CRED);
+ }
return std::string("");
}
WIFI_AUTHTYPE getAuthType()
{
if(m_rep.hasAttribute(OC_RSRVD_ES_AUTHTYPE))
+ {
return static_cast<WIFI_AUTHTYPE>(m_rep.getValue<int>(OC_RSRVD_ES_AUTHTYPE));
+ }
return NONE_AUTH;
}
WIFI_ENCTYPE getEncType()
{
if(m_rep.hasAttribute(OC_RSRVD_ES_ENCTYPE))
+ {
return static_cast<WIFI_ENCTYPE>(m_rep.getValue<int>(OC_RSRVD_ES_ENCTYPE));
+ }
return NONE_ENC;
}
std::string getLanguage()
{
if(m_rep.hasAttribute(OC_RSRVD_ES_LANGUAGE))
+ {
return m_rep.getValue<std::string>(OC_RSRVD_ES_LANGUAGE);
+ }
return std::string("");
}
std::string getCountry()
{
if(m_rep.hasAttribute(OC_RSRVD_ES_COUNTRY))
+ {
return m_rep.getValue<std::string>(OC_RSRVD_ES_COUNTRY);
+ }
return std::string("");
}
OC::OCRepresentation rep;
std::function< OCStackResult(void) > getStatus = [&]
- { return m_ocResource->get(m_ocResource->getResourceTypes().at(0),
+ {
+ return m_ocResource->get(m_ocResource->getResourceTypes().at(0),
DEFAULT_INTERFACE, query, std::function<void(const HeaderOptions& headerOptions,
const OCRepresentation& rep, const int eCode) >(
std::bind(&EnrolleeResource::onGetStatusResponse, this,
OC::OCRepresentation rep;
std::function< OCStackResult(void) > getConfigurationStatus = [&]
- { return m_ocResource->get(m_ocResource->getResourceTypes().at(0),
+ {
+ return m_ocResource->get(m_ocResource->getResourceTypes().at(0),
BATCH_INTERFACE, query, std::function<void(const HeaderOptions& headerOptions,
const OCRepresentation& rep, const int eCode) >(
std::bind(&EnrolleeResource::onGetConfigurationResponse, this,
{
size_t outBufSize = B64DECODE_OUT_SAFESIZE((uuidString.length() + 1));
uint8_t* outKey = (uint8_t*)OICCalloc(1, outBufSize);
- uint32_t outKeySize;
+ uint32_t outKeySize = 0;
if(NULL == outKey)
{
OIC_LOG (ERROR, ENROLEE_SECURITY_TAG, "Failed to memoray allocation.");
pOwnedDevList.clear();
pUnownedDevList.clear();
- OCStackResult result;
+ OCStackResult result = OC_STACK_ERROR;
result = OCSecure::discoverOwnedDevices(ES_SEC_DISCOVERY_TIMEOUT,
pOwnedDevList);
char href[] = "*";
size_t len = strlen(href)+1; // '1' for null termination
rsrc->href = (char*) OICCalloc(len, sizeof(char));
- if(!rsrc)
+ if(!rsrc->href)
{
OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG, "createAcl: OICCalloc error return");
OCDeleteACLList(acl);
}
OICStrcpy(rsrc->href, len, href);
- int arrLen = 1;
+ size_t arrLen = 1;
rsrc->typeLen = arrLen;
rsrc->types = (char**)OICCalloc(arrLen, sizeof(char*));
rsrc->interfaces = (char**)OICCalloc(arrLen, sizeof(char*));
if (OCRepPayloadGetPropInt(payload, USERPROPERTY_KEY_INT, &value))
{
if(*userdata != NULL)
+ {
*userdata = (void*)OICMalloc(sizeof(UserProperties));
+ }
OIC_LOG_V(INFO, ESX_ENROLLEE_TAG, "[User specific property] %s : %ld",
USERPROPERTY_KEY_INT, value);
((UserProperties*)(*userdata))->userValue_int = value;
{
printf("WiFiProvCbInApp IN\n");
- if(eventData->ssid != NULL)
+ if(eventData == NULL)
{
- printf("SSID : %s\n", eventData->ssid);
- }
- else
- {
- printf("ERROR! SSID IS NULL\n");
- return;
- }
-
- if(eventData->pwd != NULL)
- {
- printf("Password : %s\n", eventData->pwd);
- }
- else
- {
- printf("ERROR! Password IS NULL\n");
- return;
- }
-
- if(eventData->authtype == NONE_AUTH || eventData->authtype == WEP || \
- eventData->authtype == WPA_PSK || eventData->authtype == WPA2_PSK)
- {
- printf("AuthType : %d\n", eventData->authtype);
- }
- else
- {
- printf("ERROR! AuthType IS NULL\n");
- return;
+ printf("ESWiFiProvData is NULL\n");
+ return ;
}
- if(eventData->enctype == NONE_ENC || eventData->enctype == WEP_64 || \
- eventData->enctype == WEP_128 || eventData->enctype == TKIP || \
- eventData->enctype == AES || eventData->enctype == TKIP_AES)
- {
- printf("EncType : %d\n", eventData->enctype);
- }
- else
- {
- printf("ERROR! EncType IS NULL\n");
- return;
- }
+ printf("SSID : %s\n", eventData->ssid);
+ printf("Password : %s\n", eventData->pwd);
+ printf("AuthType : %d\n", eventData->authtype);
+ printf("EncType : %d\n", eventData->enctype);
if(eventData->userdata != NULL)
{
{
printf("DevConfProvCbInApp IN\n");
- if(eventData->language != NULL)
- {
- printf("Language : %s\n", eventData->language);
- }
- else
+ if(eventData == NULL)
{
- printf("ERROR! Language IS NULL\n");
- return;
+ printf("ESDevConfProvData is NULL\n");
+ return ;
}
- if(eventData->country != NULL)
- {
- printf("Country : %s\n", eventData->country);
- }
- else
- {
- printf("ERROR! Country IS NULL\n");
- return;
- }
+ printf("Language : %s\n", eventData->language);
+ printf("Country : %s\n", eventData->country);
printf("DevConfProvCbInApp OUT\n");
}
{
printf("CloudDataProvCbInApp IN\n");
- if(eventData->authCode != NULL)
- {
- printf("AuthCode : %s\n", eventData->authCode);
- }
- else
- {
- printf("ERROR! AuthCode IS NULL\n");
- return;
- }
-
- if(eventData->authProvider != NULL)
- {
- printf("AuthProvider : %s\n", eventData->authProvider);
- }
- else
+ if(eventData == NULL)
{
- printf("ERROR! AuthProvider IS NULL\n");
- return;
+ printf("ESCloudProvData is NULL\n");
+ return ;
}
- if(eventData->ciServer != NULL)
- {
- printf("CI Server : %s\n", eventData->ciServer);
- }
- else
- {
- printf("ERROR! CI Server IS NULL\n");
- return;
- }
+ printf("AuthCode : %s\n", eventData->authCode);
+ printf("AuthProvider : %s\n", eventData->authProvider);
+ printf("CI Server : %s\n", eventData->ciServer);
printf("CloudDataProvCbInApp OUT\n");
}
}
printf("ESInitEnrollee Success\n");
- pthread_t thread_handle;
+ pthread_t thread_handle = NULL;
if (pthread_create(&thread_handle, NULL, listeningFunc, NULL))
{
printf("Thread creation failed\n");
SetUserProperties(&g_userProperties);
if(ESSetDeviceProperty(&deviceProperty) == ES_ERROR)
+ {
printf("ESSetDeviceProperty Error\n");
+ }
printf("SetDeviceInfo OUT\n");
}
PrintMenu();
break;
}
- if (option == 'Q' || option == 'q') break;
+ if (option == 'Q' || option == 'q') { break; }
}
}
return 0;
void *listeningFunc(void * data)
{
(void)data;
- OCStackResult result;
+ OCStackResult result = OC_STACK_ERROR;
while (true)
{
void getStatus()
{
if(!remoteEnrollee)
+ {
return;
+ }
try
{
void getConfiguration()
{
if(!remoteEnrollee)
+ {
return;
+ }
try
{
void provisionDeviceProperty()
{
if(!remoteEnrollee)
+ {
return;
+ }
DeviceProp devProp;
devProp.setWiFiProp("Iotivity_SSID", "Iotivity_PWD", WPA2_PSK, TKIP_AES);
void provisionCloudProperty()
{
if(!remoteEnrollee)
+ {
return;
+ }
CloudProp cloudProp;
cloudProp.setCloudProp("authCode", "authProvider", "ciServer");
OCPlatform::Configure(config);
+ try
+ {
#ifdef __WITH_DTLS__
- //Initializing the provisioning client stack using the db path provided by the application.
- OCStackResult result = OCSecure::provisionInit("");
+ //Initializing the provisioning client stack using the db path provided by the application.
+ OCStackResult result = OCSecure::provisionInit("");
- if (result != OC_STACK_OK)
- {
- return -1;
- }
+ if (result != OC_STACK_OK)
+ {
+ return -1;
+ }
#endif
-
- try
- {
requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=" << PROV_RESOURCE_TYPE;
OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource);
}catch(OCException& e)
{
- oclog() << "Exception in main: "<<e.what();
+ std::cout << "Exception in main: "<<e.what();
}
while (true)