*/
#include "easysetup.h"
-//#include "softap.h"
-//#include "onboarding.h"
#include "logger.h"
#include "resourcehandler.h"
#include "easysetupcallbacks.h"
//-----------------------------------------------------------------------------
// Private variables
//-----------------------------------------------------------------------------
+static bool gIsSecured = false;
-/**
- * @var gTargetSsid
- * @brief Target SSID of the Soft Access point to which the device has to connect
- */
-static char gTargetSsid[MAXSSIDLEN];
+static ESProvisioningCallbacks gESProvisioningCb;
-/**
- * @var gTargetPass
- * @brief Password of the target access point to which the device has to connect
- */
-static char gTargetPass[MAXNETCREDLEN];
-
-/**
- * @var gEnrolleeStatusCb
- * @brief Fucntion pointer holding the callback for intimation of EasySetup Enrollee status callback
- */
-static ESEnrolleeEventCallback gEnrolleeStatusCb = NULL;
+void ESWiFiRsrcCallback(ESResult esResult, ESWiFiProvData *eventData)
+{
+ OIC_LOG_V(DEBUG, ES_ENROLLEE_TAG, "ESWiFiRsrcCallback IN");
-/**
- * @var gIsSecured
- * @brief Variable to check if secure mode is enabled or not.
- */
-static bool gIsSecured = false;
+ if(esResult != ES_OK)
+ {
+ OIC_LOG_V(ERROR, ES_ENROLLEE_TAG, "ESWiFiRsrcCallback Error Occured");
+ return;
+ }
-void ESOnboardingCallback(ESResult esResult)
-{
- OIC_LOG_V(DEBUG, ES_ENROLLEE_TAG, "ESOnboardingCallback with result = %d", esResult);
- if(esResult == ES_OK)
- {
- gEnrolleeStatusCb(esResult, ES_ON_BOARDED_STATE);
- }
- else
- {
- OIC_LOG_V(DEBUG, ES_ENROLLEE_TAG,
- "Onboarding is failed callback result is = %d", esResult);
- gEnrolleeStatusCb(esResult, ES_INIT_STATE);
- }
+ // deliver data to ESProvisioningCallbacks
+ if(gESProvisioningCb.WiFiProvCb != NULL)
+ {
+ gESProvisioningCb.WiFiProvCb(eventData);
+ }
+ else
+ {
+ OIC_LOG_V(ERROR, ES_ENROLLEE_TAG, "WiFiProvCb is NULL");
+ return;
+ }
}
-void ESProvisioningCallback(ESResult esResult)
+void ESCloudRsrcCallback(ESResult esResult, ESCloudProvData *eventData)
{
- OIC_LOG_V(DEBUG, ES_ENROLLEE_TAG, "ESProvisioningCallback with result = %d", esResult);
+ OIC_LOG_V(DEBUG, ES_ENROLLEE_TAG, "ESCloudRsrcCallback IN");
- if (esResult == ES_RECVTRIGGEROFPROVRES)
+ if(esResult != ES_OK)
{
- GetTargetNetworkInfoFromProvResource(gTargetSsid, gTargetPass);
- gEnrolleeStatusCb(ES_OK, ES_PROVISIONED_STATE);
- OIC_LOG(DEBUG, ES_ENROLLEE_TAG, "Connecting with target network");
+ OIC_LOG_V(ERROR, ES_ENROLLEE_TAG, "ESCloudRsrcCallback Error Occured");
+ return;
+ }
- // Connecting/onboarding to target network
- //ConnectToWiFiNetwork(gTargetSsid, gTargetPass, ESOnboardingCallbackTargetNet);
+ if(gESProvisioningCb.CloudDataProvCb != NULL)
+ {
+ gESProvisioningCb.CloudDataProvCb(eventData);
}
else
{
- OIC_LOG_V(DEBUG, ES_ENROLLEE_TAG, "Provisioning is failed callback result is = %d", esResult);
- // Resetting Enrollee to ONBOARDED_STATE as Enrollee is alreday onboarded in previous step
- gEnrolleeStatusCb(ES_OK, ES_ON_BOARDED_STATE);
+ OIC_LOG_V(ERROR, ES_ENROLLEE_TAG, "CloudDataProvCb is NULL");
+ return;
}
}
-void ESOnboardingCallbackTargetNet(ESResult esResult)
+void ESDevconfRsrcallback(ESResult esResult, ESDevConfProvData *eventData)
{
- OIC_LOG_V(DEBUG, ES_ENROLLEE_TAG, "ESOnboardingCallback on target network with result = %d",
- esResult);
- if(esResult == ES_OK)
+ OIC_LOG_V(DEBUG, ES_ENROLLEE_TAG, "ESDevconfRsrcallback IN");
+
+ if(esResult != ES_OK)
+ {
+ OIC_LOG_V(ERROR, ES_ENROLLEE_TAG, "ESDevconfRsrcallback Error Occured");
+ return;
+ }
+
+ if(gESProvisioningCb.DevConfProvCb != NULL)
{
- gEnrolleeStatusCb(esResult, ES_ON_BOARDED_TARGET_NETWORK_STATE);
+ gESProvisioningCb.DevConfProvCb(eventData);
}
else
{
- OIC_LOG_V(DEBUG, ES_ENROLLEE_TAG,
- "Onboarding is failed on target network and callback result is = %d", esResult);
- // Resetting Enrollee state to the ES_PROVISIONED_STATE
- // as device is already being provisioned with target network creds.
- gEnrolleeStatusCb(esResult, ES_PROVISIONED_STATE);
+ OIC_LOG_V(ERROR, ES_ENROLLEE_TAG, "DevConfProvCb is NULL");
+ return;
}
}
-ESResult ESInitEnrollee(OCConnectivityType networkType, const char *ssid, const char *passwd,
- bool isSecured,
- ESEnrolleeEventCallback cb)
+ESResult ESInitEnrollee(bool isSecured, ESResourceMask resourceMask, ESProvisioningCallbacks callbacks)
{
OIC_LOG(INFO, ES_ENROLLEE_TAG, "ESInitEnrollee IN");
- if(!ESEnrolleeValidateParam(networkType,ssid,passwd,cb))
- {
- OIC_LOG(ERROR, ES_ENROLLEE_TAG,
- "ESInitEnrollee::Stopping Easy setup due to invalid parameters");
- return ES_ERROR;
- }
-
- //Init callback
- gEnrolleeStatusCb = cb;
gIsSecured = isSecured;
- // TODO : This onboarding state has to be set by lower layer, as they better
- // knows when actually on-boarding started.
- cb(ES_ERROR,ES_ON_BOARDING_STATE);
-
- /*
- OIC_LOG(INFO, ES_ENROLLEE_TAG, "received callback");
- OIC_LOG(INFO, ES_ENROLLEE_TAG, "onboarding now..");
+ if((resourceMask & ES_WIFI_RESOURCE) == ES_WIFI_RESOURCE)
+ {
+ if(callbacks.WiFiProvCb != NULL)
+ {
+ gESProvisioningCb.WiFiProvCb = callbacks.WiFiProvCb;
+ RegisterWifiRsrcEventCallBack(ESWiFiRsrcCallback);
+ }
+ else
+ {
+ OIC_LOG(ERROR, ES_ENROLLEE_TAG, "WiFiProvCb NULL");
+ return ES_ERROR;
+ }
+ }
+ if((resourceMask & ES_DEVCONF_RESOURCE) == ES_DEVCONF_RESOURCE)
+ {
+ if(callbacks.DevConfProvCb != NULL)
+ {
+ gESProvisioningCb.DevConfProvCb = callbacks.DevConfProvCb;
+ RegisterDevConfRsrcEventCallBack(ESDevconfRsrcallback);
+ }
+ else
+ {
+ OIC_LOG(ERROR, ES_ENROLLEE_TAG, "DevConfProvCb NULL");
+ return ES_ERROR;
+ }
+ }
+ if((resourceMask & ES_CLOUD_RESOURCE) == ES_CLOUD_RESOURCE)
+ {
+ if(callbacks.DevConfProvCb != NULL)
+ {
+ gESProvisioningCb.CloudDataProvCb = callbacks.CloudDataProvCb;
+ RegisterCloudRsrcEventCallBack(ESCloudRsrcCallback);
+ }
+ else
+ {
+ OIC_LOG(ERROR, ES_ENROLLEE_TAG, "CloudDataProvCb NULL");
+ return ES_ERROR;
+ }
+ }
- if(!ESOnboard(ssid, passwd, ESOnboardingCallback))
+ if(CreateEasySetupResources(gIsSecured, resourceMask) != OC_STACK_OK)
{
- OIC_LOG(ERROR, ES_ENROLLEE_TAG, "ESInitEnrollee::On-boarding failed");
- cb(ES_ERROR, ES_INIT_STATE);
+ // TODO : Error Handling
return ES_ERROR;
}
- */
+
OIC_LOG(INFO, ES_ENROLLEE_TAG, "ESInitEnrollee OUT");
return ES_OK;
return ES_OK;
}
-ESResult ESInitProvisioning()
-{
- OIC_LOG(INFO, ES_ENROLLEE_TAG, "ESInitProvisioning <<IN>>");
-
- if (CreateEasySetupResources(gIsSecured) != OC_STACK_OK)
- {
- OIC_LOG(ERROR, ES_ENROLLEE_TAG, "CreateProvisioningResource error");
- return ES_ERROR;
- }
-
- RegisterResourceEventCallBack(ESProvisioningCallback);
-
- OIC_LOG(INFO, ES_ENROLLEE_TAG, "ESInitProvisioning <<OUT>>");
- return ES_RESOURCECREATED;
-}
-
static bool ESEnrolleeValidateParam(OCConnectivityType networkType, const char *ssid,
const char *passwd, ESEnrolleeEventCallback cb)
{
static CloudResource gCloudResource;
static DevConfResource gDevConfResource;
+/**
+ * @var gWiFiData
+ * @brief Structure for holding the target information required to
+ * connect to the target network
+ */
+ static ESWiFiProvData gWiFiData;
+
+/**
+ * @var gDevConfData
+ * @brief Structure for holding the device information
+ */
+ static ESDevConfProvData gDevConfData;
+
+/**
+ * @var gCloudData
+ * @brief Structure for holding the cloud information required to
+ * connect to CI Server
+ */
+ static ESCloudProvData gCloudData;
+
+
+
//-----------------------------------------------------------------------------
// Private internal function prototypes
//-----------------------------------------------------------------------------
OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload);
OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload);
void updateProvResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input);
-void updateWiFiResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input);
-void updateCloudResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input);
-void updateDevConfResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input);
+void updateWiFiResource(OCRepPayload* input);
+void updateCloudResource(OCRepPayload* input);
+void updateDevConfResource(OCRepPayload* input);
-ESEnrolleeResourceEventCallback gNetworkInfoProvEventCb = NULL;
+ESWiFiCB gWifiRsrcEvtCb = NULL;
+ESCloudCB gCloudRsrcEvtCb = NULL;
+ESDevConfCB gDevConfRsrcEvtCb = NULL;
-void RegisterResourceEventCallBack(ESEnrolleeResourceEventCallback cb)
+void RegisterWifiRsrcEventCallBack(ESWiFiCB cb)
{
- gNetworkInfoProvEventCb = cb;
+ gWifiRsrcEvtCb = cb;
+}
+
+void RegisterCloudRsrcEventCallBack(ESCloudCB cb)
+{
+ gCloudRsrcEvtCb = cb;
+}
+
+void RegisterDevConfRsrcEventCallBack(ESDevConfCB cb)
+{
+ gDevConfRsrcEvtCb = cb;
}
void UnRegisterResourceEventCallBack()
{
- if (gNetworkInfoProvEventCb)
+ if (gWifiRsrcEvtCb)
{
- gNetworkInfoProvEventCb = NULL;
+ gWifiRsrcEvtCb = NULL;
+ }
+ if (gCloudRsrcEvtCb)
+ {
+ gCloudRsrcEvtCb = NULL;
+ }
+ if (gDevConfRsrcEvtCb)
+ {
+ gDevConfRsrcEvtCb = NULL;
}
}
}
-void updateProvResource(OCEntityHandlerRequest *ehRequest, OCRepPayload* input)
+void updateProvResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input)
{
OIC_LOG_V(INFO, ES_RH_TAG, "gProvResource.status %lld", gProvResource.status);
- bool trigger;
- if (OCRepPayloadGetPropBool(input, OC_RSRVD_ES_TRIGGER, &trigger))
- {
- // Triggering
- gProvResource.trigger = trigger;
- }
if(ehRequest->query)
{
if(strstr(ehRequest->query, OC_RSRVD_INTERFACE_BATCH))
- {// When Provisioning resource has a POST with BatchInterface
- updateCloudResource(ehRequest, input);
- updateWiFiResource(ehRequest, input);
- updateDevConfResource(ehRequest, input);
+ {
+ // When Provisioning resource has a POST with BatchInterface
+ updateCloudResource(input);
+ updateWiFiResource(input);
+ updateDevConfResource(input);
}
}
}
-void updateWiFiResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input)
+void updateWiFiResource(OCRepPayload* input)
{
- (void) ehRequest;
- char* ssid;
+ char* ssid = NULL;
if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_SSID, &ssid))
{
OICStrcpy(gWiFiResource.ssid, sizeof(gWiFiResource.ssid), ssid);
- OIC_LOG(INFO, ES_RH_TAG, "got ssid");
+ OICStrcpy(gWiFiData.ssid, sizeof(gWiFiData.ssid), ssid);
+ OIC_LOG_V(INFO, ES_RH_TAG, "gWiFiResource.ssid : %s", gWiFiResource.ssid);
}
- char* cred;
+ char* cred = NULL;
if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_CRED, &cred))
{
OICStrcpy(gWiFiResource.cred, sizeof(gWiFiResource.cred), cred);
+ OICStrcpy(gWiFiData.pwd, sizeof(gWiFiData.pwd), cred);
OIC_LOG_V(INFO, ES_RH_TAG, "gWiFiResource.cred %s", gWiFiResource.cred);
}
- int64_t authType;
+ int64_t authType = -1;
if (OCRepPayloadGetPropInt(input, OC_RSRVD_ES_AUTHTYPE, &authType))
{
gWiFiResource.authType = authType;
+ gWiFiData.authtype = gWiFiResource.authType;
OIC_LOG_V(INFO, ES_RH_TAG, "gWiFiResource.authType %u", gWiFiResource.authType);
}
- int64_t encType;
+ int64_t encType = -1;
if (OCRepPayloadGetPropInt(input, OC_RSRVD_ES_ENCTYPE, &encType))
{
gWiFiResource.encType = encType;
+ gWiFiData.enctype = gWiFiResource.encType;
OIC_LOG_V(INFO, ES_RH_TAG, "gWiFiResource.encType %u", gWiFiResource.encType);
}
+
+ if(ssid || cred || authType!= -1 || encType != -1)
+ {
+ OIC_LOG(INFO, ES_RH_TAG, "Send WiFiRsrc Callback To ES");
+
+ // TODO : Need to check appropriateness of gWiFiData
+ if(gWifiRsrcEvtCb != NULL)
+ {
+ gWifiRsrcEvtCb(ES_OK, &gWiFiData);
+ }
+ else
+ {
+ OIC_LOG(ERROR, ES_RH_TAG, "gWifiRsrcEvtCb is NULL");
+ }
+ }
+
}
-void updateCloudResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input)
+
+void updateCloudResource(OCRepPayload* input)
{
- (void) ehRequest;
- char *authCode;
+ char *authCode = NULL;
if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_AUTHCODE, &authCode))
{
OICStrcpy(gCloudResource.authCode, sizeof(gCloudResource.authCode), authCode);
+ OICStrcpy(gCloudData.authCode, sizeof(gCloudData.authCode), authCode);
OIC_LOG_V(INFO, ES_RH_TAG, "gCloudResource.authCode %s", gCloudResource.authCode);
}
- char *authProvider;
+ char *authProvider = NULL;
if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_AUTHPROVIDER, &authProvider))
{
OICStrcpy(gCloudResource.authProvider, sizeof(gCloudResource.authProvider), authProvider);
+ OICStrcpy(gCloudData.authProvider, sizeof(gCloudData.authProvider), authProvider);
OIC_LOG_V(INFO, ES_RH_TAG, "gCloudResource.authServerUrl %s", gCloudResource.authProvider);
}
- char *ciServer;
+ char *ciServer = NULL;
if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_CISERVER, &ciServer))
{
OICStrcpy(gCloudResource.ciServer, sizeof(gCloudResource.ciServer), ciServer);
+ OICStrcpy(gCloudData.ciServer, sizeof(gCloudData.ciServer), ciServer);
OIC_LOG_V(INFO, ES_RH_TAG, "gCloudResource.ciServer %s", gCloudResource.ciServer);
}
+
+ if(authCode || authProvider || ciServer)
+ {
+ OIC_LOG(INFO, ES_RH_TAG, "Send CloudRsrc Callback To ES");
+
+ // TODO : Need to check appropriateness of gCloudData
+ if(gCloudRsrcEvtCb != NULL)
+ {
+ gCloudRsrcEvtCb(ES_OK, &gCloudData);
+ }
+ else
+ {
+ OIC_LOG(ERROR, ES_RH_TAG, "gCloudRsrcEvtCb is NULL");
+ }
+ }
}
-void updateDevConfResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input)
+void updateDevConfResource(OCRepPayload* input)
{
- (void) ehRequest;
- char *country;
+ char *country = NULL;
if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_AUTHCODE, &country))
{
OICStrcpy(gDevConfResource.country, sizeof(gDevConfResource.country), country);
+ OICStrcpy(gDevConfData.country, sizeof(gDevConfData.country), country);
OIC_LOG_V(INFO, ES_RH_TAG, "gDevConfResource.country %s", gDevConfResource.country);
}
- char *language;
+ char *language = NULL;
if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_AUTHPROVIDER, &language))
{
OICStrcpy(gDevConfResource.language, sizeof(gDevConfResource.language), language);
+ OICStrcpy(gDevConfData.language, sizeof(gDevConfData.language), language);
OIC_LOG_V(INFO, ES_RH_TAG, "gDevConfResource.language %s", gDevConfResource.language);
}
+
+ if(country || language)
+ {
+ OIC_LOG(INFO, ES_RH_TAG, "Send DevConfRsrc Callback To ES");
+
+ // TODO : Need to check appropriateness of gDevConfData
+ if(gDevConfRsrcEvtCb != NULL)
+ {
+ gDevConfRsrcEvtCb(ES_OK, &gDevConfData);
+ }
+ else
+ {
+ OIC_LOG(ERROR, ES_RH_TAG, "gDevConfRsrcEvtCb is NULL");
+ }
+ }
}
-OCRepPayload* constructResponseOfWiFi(OCEntityHandlerRequest *ehRequest)
+OCRepPayload* constructResponseOfWiFi()
{
- (void) ehRequest;
OCRepPayload* payload = OCRepPayloadCreate();
if (!payload)
{
OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_WIFI);
size_t dimensions[MAX_REP_ARRAY_DEPTH] = {gWiFiResource.numMode, 0, 0};
- OCRepPayloadSetIntArray(payload, OC_RSRVD_ES_SUPPORTEDWIFIMODE, gWiFiResource.supportedMode, dimensions);
+ OCRepPayloadSetIntArray(payload, OC_RSRVD_ES_SUPPORTEDWIFIMODE, (int64_t *)gWiFiResource.supportedMode, dimensions);
OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_SUPPORTEDWIFIFREQ, gWiFiResource.supportedFreq);
OCRepPayloadSetPropString(payload, OC_RSRVD_ES_SSID, gWiFiResource.ssid);
OCRepPayloadSetPropString(payload, OC_RSRVD_ES_CRED, gWiFiResource.cred);
- OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_AUTHTYPE, gWiFiResource.authType);
- OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_ENCTYPE, gWiFiResource.encType);
+ OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_AUTHTYPE, (int) gWiFiResource.authType);
+ OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_ENCTYPE, (int) gWiFiResource.encType);
printf("%s\n", gWiFiResource.ssid);
return payload;
}
-OCRepPayload* constructResponseOfCloud(OCEntityHandlerRequest *ehRequest)
+OCRepPayload* constructResponseOfCloud()
{
- (void) ehRequest;
OCRepPayload* payload = OCRepPayloadCreate();
if (!payload)
{
return payload;
}
-OCRepPayload* constructResponseOfDevConf(OCEntityHandlerRequest *ehRequest)
+OCRepPayload* constructResponseOfDevConf()
{
- (void) ehRequest;
OCRepPayload* payload = OCRepPayloadCreate();
if (!payload)
{
{
if(strstr(ehRequest->query, OC_RSRVD_INTERFACE_BATCH))
{// When Provisioning resource has a GET with BatchInterface
- payload->next = constructResponseOfWiFi(ehRequest);
+ payload->next = constructResponseOfWiFi();
if(payload->next)
- payload->next->next = constructResponseOfCloud(ehRequest);
+ payload->next->next = constructResponseOfCloud();
else
return payload;
if(payload->next->next)
- payload->next->next->next = constructResponseOfDevConf(ehRequest);
+ payload->next->next->next = constructResponseOfDevConf();
else
return payload;
}
}
-OCStackResult CreateEasySetupResources(bool isSecured)
+OCStackResult CreateEasySetupResources(bool isSecured, ESResourceMask resourceMask)
{
OCStackResult res = OC_STACK_ERROR;
+ bool maskFlag = false;
res = initProvResource(isSecured);
- if(res)
+ if(res != OC_STACK_OK)
{
// TODO: destroy logic will be added
+ OIC_LOG_V(ERROR, ES_RH_TAG, "initProvResource result: %s", getResult(res));
+
return res;
}
- res = initWiFiResource(isSecured);
- if(res)
+ if((resourceMask & ES_WIFI_RESOURCE) == ES_WIFI_RESOURCE)
{
- // TODO: destroy logic will be added
- return res;
+ maskFlag = true;
+ res = initWiFiResource(isSecured);
+ if(res != OC_STACK_OK)
+ {
+ // TODO: destroy logic will be added
+ OIC_LOG_V(ERROR, ES_RH_TAG, "initWiFiResource result: %s", getResult(res));
+
+ return res;
+ }
+
+ res = OCBindResource(gProvResource.handle, gWiFiResource.handle);
+ if(res != OC_STACK_OK)
+ {
+ // TODO : Error Handling
+ OIC_LOG_V(ERROR, ES_RH_TAG, "Bind WiFiResource result: %s", getResult(res));
+
+ return res;
+ }
+
}
- res = initCloudServerResource(isSecured);
- if(res)
+ if((resourceMask & ES_CLOUD_RESOURCE) == ES_CLOUD_RESOURCE)
{
- // TODO: destroy logic will be added
- return res;
+ maskFlag = true;
+ res = initCloudServerResource(isSecured);
+ if(res != OC_STACK_OK)
+ {
+ // TODO: destroy logic will be added
+ OIC_LOG_V(ERROR, ES_RH_TAG, "initCloudResource result: %s", getResult(res));
+
+ return res;
+ }
+
+ res = OCBindResource(gProvResource.handle, gCloudResource.handle);
+ if(res != OC_STACK_OK)
+ {
+ // TODO : Error Handling
+ OIC_LOG_V(ERROR, ES_RH_TAG, "Bind CloudResource result: %s", getResult(res));
+
+ return res;
+ }
}
- res = initDevConfResource(isSecured);
- if(res)
+ if((resourceMask & ES_DEVCONF_RESOURCE) == ES_DEVCONF_RESOURCE)
{
- // TODO: destroy logic will be added
- return res;
+ maskFlag = true;
+ res = initDevConfResource(isSecured);
+ if(res != OC_STACK_OK)
+ {
+ // TODO: destroy logic will be added
+ OIC_LOG_V(ERROR, ES_RH_TAG, "initDevConf result: %s", getResult(res));
+
+ return res;
+ }
+
+ res = OCBindResource(gProvResource.handle, gDevConfResource.handle);
+ if(res != OC_STACK_OK)
+ {
+ // TODO : Error Handling
+ OIC_LOG_V(ERROR, ES_RH_TAG, "Bind DevConfResource result: %s", getResult(res));
+
+ return res;
+ }
}
- OCBindResource(gProvResource.handle, gWiFiResource.handle);
- OCBindResource(gProvResource.handle, gCloudResource.handle);
- OCBindResource(gProvResource.handle, gDevConfResource.handle);
+ if(maskFlag == false)
+ {
+ // TODO: destroy logic will be added
+ OIC_LOG_V(ERROR, ES_RH_TAG, "Invalid ResourceMask");
+ return OC_STACK_ERROR;
+
+ }
OIC_LOG_V(INFO, ES_RH_TAG, "Created all resources with result: %s", getResult(res));
return res;
}
if(ehRequest->resource == gProvResource.handle)
getResp = constructResponseOfProv(ehRequest);
else if(ehRequest->resource == gWiFiResource.handle)
- getResp = constructResponseOfWiFi(ehRequest);
+ getResp = constructResponseOfWiFi();
else if(ehRequest->resource == gCloudResource.handle)
- getResp = constructResponseOfCloud(ehRequest);
+ getResp = constructResponseOfCloud();
else if(ehRequest->resource == gDevConfResource.handle)
- getResp = constructResponseOfDevConf(ehRequest);
+ getResp = constructResponseOfDevConf();
if (!getResp)
{
if(ehRequest->resource == gProvResource.handle)
updateProvResource(ehRequest, input);
else if(ehRequest->resource == gWiFiResource.handle)
- updateWiFiResource(ehRequest, input);
+ updateWiFiResource(input);
else if(ehRequest->resource == gCloudResource.handle)
- updateCloudResource(ehRequest, input);
+ updateCloudResource(input);
else if(ehRequest->resource == gDevConfResource.handle)
- updateDevConfResource(ehRequest, input);
+ updateDevConfResource(input);
+ // TBD : Discuss about triggering flag (to be existed or not)
// ES_PS_PROVISIONING_COMPLETED state indicates that already provisioning is completed.
// A new request for provisioning means overriding existing network provisioning information.
- if (gProvResource.trigger)
- {
- OIC_LOG(DEBUG, ES_RH_TAG, "Provisioning already completed."
- "Tiggering the network connection");
-
- if (gNetworkInfoProvEventCb)
- {
- gNetworkInfoProvEventCb(ES_RECVTRIGGEROFPROVRES);
- ehResult = OC_EH_OK;
- }
- else
- {
- OIC_LOG(ERROR, ES_RH_TAG, "gNetworkInfoProvEventCb is NULL."
- "Network handler not registered. Failed to connect to the network");
- ehResult = OC_EH_ERROR;
- return ehResult;
- }
- }
- else
- {
- OIC_LOG(DEBUG, ES_RH_TAG, "Provisioning the network information to the Enrollee.");
- }
+ // if (gProvResource.trigger)
+ // {
+ // OIC_LOG(DEBUG, ES_RH_TAG, "Provisioning already completed."
+ // "Tiggering the network connection");
+
+ // if (gNetworkInfoProvEventCb)
+ // {
+ // gNetworkInfoProvEventCb(ES_RECVTRIGGEROFPROVRES);
+ // ehResult = OC_EH_OK;
+ // }
+ // else
+ // {
+ // OIC_LOG(ERROR, ES_RH_TAG, "gNetworkInfoProvEventCb is NULL."
+ // "Network handler not registered. Failed to connect to the network");
+ // ehResult = OC_EH_ERROR;
+ // return ehResult;
+ // }
+ // }
+ // else
+ // {
+ // OIC_LOG(DEBUG, ES_RH_TAG, "Provisioning the network information to the Enrollee.");
+ // }
OCRepPayload *getResp = NULL;
if(ehRequest->resource == gProvResource.handle)
getResp = constructResponseOfProv(ehRequest);
else if(ehRequest->resource == gWiFiResource.handle)
- getResp = constructResponseOfWiFi(ehRequest);
+ getResp = constructResponseOfWiFi();
else if(ehRequest->resource == gCloudResource.handle)
- getResp = constructResponseOfCloud(ehRequest);
+ getResp = constructResponseOfCloud();
else if(ehRequest->resource == gDevConfResource.handle)
- getResp = constructResponseOfDevConf(ehRequest);
+ getResp = constructResponseOfDevConf();
if (gProvResource.trigger)// Trigger false should be restored after executed
gProvResource.trigger = false;
#include <stdio.h>
#include <pthread.h>
-#define TAG "TS"
+#define TAG "ENROLLEE_SAMPLE"
void *listeningFunc(void *);
-/**
- * @var ssid
- * @brief Target SSID of the Soft Access point to which the device has to connect
- */
-static char ssid[] = "EasySetup123";
-
-/**
- * @var passwd
- * @brief Password of the Soft Access point to which the device has to connect
- */
-static char passwd[] = "EasySetup123";
/**
* Secure Virtual Resource database for Iotivity Server
{
printf("============\n");
printf("S: Enabled Security\n");
- printf("I: Init easy setup\n");
- printf("P: start provisioning resources\n");
- printf("T: terminate\n");
- printf("Q: quit\n");
+ printf("I: Init & Start EasySetup\n");
+ printf("D: Set DeviceInfo\n");
+ printf("T: Terminate\n");
+ printf("Q: Quit\n");
printf("============\n");
}
-void EventCallbackInApp(ESResult esResult, ESEnrolleeState enrolleeState)
+void WiFiProvCbInApp(ESWiFiProvData *eventData)
{
- printf("Easy setup event callback\n");
+ printf("WiFiProvCbInApp IN\n");
- if(esResult == ES_OK)
+ if(eventData->ssid != NULL)
{
- if(enrolleeState == ES_ON_BOARDED_STATE)
- {
- printf("Device is successfully OnBoared on Adhoc network\n");
- }
- else if (enrolleeState == ES_PROVISIONED_STATE)
- {
- printf("Device is provisioned with target network's credentials\n");
- }
- else if (enrolleeState == ES_ON_BOARDED_TARGET_NETWORK_STATE)
- {
- printf("Device is onboarded/connected with target network\n");
- }
- else
- {
- printf("Wrong state !! Easy setup is failed at Enrollee state = %d\n",enrolleeState);
- }
+ 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;
+ }
+
+ 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("WiFiProvCbInApp OUT\n");
+
+ PrintMenu();
+}
+
+void DevConfProvCbInApp(ESDevConfProvData *eventData)
+{
+ printf("DevConfProvCbInApp IN\n");
+
+ if(eventData->language != NULL)
+ {
+ printf("Language : %s\n", eventData->language);
+ }
+ else
+ {
+ printf("ERROR! Language IS NULL\n");
+ return;
+ }
+
+ if(eventData->country != NULL)
+ {
+ printf("Country : %s\n", eventData->country);
+ }
+ else
+ {
+ printf("ERROR! Country IS NULL\n");
+ return;
+ }
+
+ printf("DevConfProvCbInApp OUT\n");
+
+ PrintMenu();
+}
+
+void CloudDataProvCbInApp(ESCloudProvData *eventData)
+{
+ 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
+ {
+ printf("ERROR! AuthProvider IS NULL\n");
+ return;
+ }
+
+ if(eventData->ciServer != NULL)
+ {
+ printf("CI Server : %s\n", eventData->ciServer);
}
else
{
- printf("Easy stup is failed at Enrollee state = %d\n",enrolleeState);;
+ printf("ERROR! CI Server IS NULL\n");
+ return;
}
+ printf("CloudDataProvCbInApp OUT\n");
+
PrintMenu();
}
+ESProvisioningCallbacks gCallbacks = {
+ .WiFiProvCb = &WiFiProvCbInApp,
+ .DevConfProvCb = &DevConfProvCbInApp,
+ .CloudDataProvCb = &CloudDataProvCbInApp
+};
+
FILE* server_fopen(const char *path, const char *mode)
{
(void) path;
void StartEasySetup()
{
- printf("StartEasySetup and onboarding started..\n");
+ printf("StartEasySetup IN\n");
- if(ESInitEnrollee(CT_ADAPTER_IP, ssid, passwd, gIsSecured, EventCallbackInApp) == ES_ERROR)
- {
- printf("StartEasySetup and onboarding Fail!!\n");
- return;
- }
-}
-
-void ESInitResources()
-{
- printf("Starting Enrollee Provisioning\n");
-
- // Initialize the OC Stack in Server mode
if (OCInit(NULL, 0, OC_SERVER) != OC_STACK_OK)
{
printf("OCStack init error!!\n");
return;
}
- if (ESInitProvisioning() == ES_ERROR)
+ ESResourceMask resourcemMask = ES_WIFI_RESOURCE | ES_CLOUD_RESOURCE | ES_DEVCONF_RESOURCE;
+ if(ESInitEnrollee(gIsSecured, resourcemMask, gCallbacks) != ES_OK)
{
- printf("Init Provisioning Failed!!\n");
+ printf("OCStack init error!!\n");
return;
}
+ printf("ESInitEnrollee Success\n");
pthread_t thread_handle;
if (pthread_create(&thread_handle, NULL, listeningFunc, NULL))
printf("Thread creation failed\n");
}
- printf("ESInitProvisioning Success\n");
+ printf("StartEasySetup OUT\n");
}
void StopEasySetup()
while(true)
{
- scanf("%c",&option);
+ if(scanf("%c", &option) != 1)
+ {
+ printf("Failed to read input data\n");
+ continue;
+ }
- if(option!= '\n')
- {
+ if(option!= '\n')
+ {
switch (option)
{
case 'H': // help
StartEasySetup();
break;
- case 'P': // start provisioning
- case 'p':
- ESInitResources();
- break;
+ case 'D': // Set Device Info
+ case 'd':
+ // TODO
case 'T': // stop easy setup
case 't':
return 0;
}
-void *listeningFunc(void * a)
+void *listeningFunc(void * data)
{
OCStackResult result;