OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload);
OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload);
OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload);
-void updateEasySetupResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input);
+OCEntityHandlerResult updateEasySetupResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input);
void updateEasySetupConnectProperty(OCRepPayload* input);
-void updateWiFiConfResource(OCRepPayload* input);
+OCEntityHandlerResult updateWiFiConfResource(OCRepPayload* input);
void updateCoapCloudConfResource(OCRepPayload* input);
void updateDevConfResource(OCRepPayload* input);
+bool isAuthTypeSupported(WIFI_AUTHTYPE authType);
+bool isEncTypeSupported(WIFI_ENCTYPE encType);
const char *getResult(OCStackResult result);
ESConnectRequestCB gConnectRequestEvtCb = NULL;
}
-void updateEasySetupResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input)
+OCEntityHandlerResult updateEasySetupResource(OCEntityHandlerRequest* ehRequest,
+ OCRepPayload* input)
{
OIC_LOG_V(DEBUG, ES_RH_TAG, "g_ESEasySetupResource.status %d", g_ESEasySetupResource.status);
+ OCEntityHandlerResult ehResult = OC_EH_OK;
if (ehRequest->query)
{
if (CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_BATCH))
{
+ bool hasError = false;
// When Provisioning resource has a POST with BatchInterface
// Parsing POST request on Batch Interface cosidering same format as GET using batch.
OCRepPayload *children = input;
-
while(children)
{
char* uri = children->uri;
}
else if (0 == strcmp(uri, OC_RSRVD_ES_URI_WIFICONF))
{
- updateWiFiConfResource(repPayload);
+ if (updateWiFiConfResource(repPayload) != OC_EH_OK)
+ {
+ // Possibility of failure exist only when updating WiFiConf resource.
+ // So error code is checked only for this function.
+ OIC_LOG(ERROR, ES_RH_TAG, "Failed to update WiFiConf resource.");
+ hasError = true;
+ }
}
else if (0 == strcmp(uri, OC_RSRVD_ES_URI_COAPCLOUDCONF))
{
children = children->next;
OCRepPayloadDestroy(repPayload);
}
+
+ if (hasError)
+ {
+ ehResult = OC_EH_BAD_REQ;
+ }
}
else if (CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
{
OIC_LOG(DEBUG, ES_RH_TAG, "Handling POST request on default interface");
updateEasySetupConnectProperty(input);
}
+ return ehResult;
}
OIC_LOG(DEBUG, ES_RH_TAG, "updateEasySetupResource exit");
}
}
-void updateWiFiConfResource(OCRepPayload* input)
+OCEntityHandlerResult updateWiFiConfResource(OCRepPayload* input)
{
+ OCEntityHandlerResult ehResult = OC_EH_ERROR;
ESWiFiConfData* wiFiData = (ESWiFiConfData*) OICMalloc(sizeof(ESWiFiConfData));
-
if (wiFiData == NULL)
{
OIC_LOG(DEBUG, ES_RH_TAG, "OICMalloc is failed");
- return;
+ return ehResult;
}
+ char* ssid = NULL;
+ char* cred = NULL;
+ char *authType = NULL;
+ char *encType = NULL;
memset(wiFiData->ssid, 0, OIC_STRING_MAX_VALUE);
memset(wiFiData->pwd, 0, OIC_STRING_MAX_VALUE);
wiFiData->authtype = NONE_AUTH;
wiFiData->enctype = NONE_AUTH;
wiFiData->userdata = NULL;
- char* ssid = NULL;
- if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_SSID, &ssid))
- {
- OICStrcpy(g_ESWiFiConfResource.ssid, sizeof(g_ESWiFiConfResource.ssid), ssid);
- OICStrcpy(wiFiData->ssid, sizeof(wiFiData->ssid), ssid);
- OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "g_ESWiFiConfResource.ssid : %s",
- g_ESWiFiConfResource.ssid);
- }
-
- char* cred = NULL;
- if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_CRED, &cred))
- {
- OICStrcpy(g_ESWiFiConfResource.cred, sizeof(g_ESWiFiConfResource.cred), cred);
- OICStrcpy(wiFiData->pwd, sizeof(wiFiData->pwd), cred);
- OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "g_ESWiFiConfResource.cred %s",
- g_ESWiFiConfResource.cred);
- }
-
bool validAuthType = false;
- char *authType = NULL;
if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_AUTHTYPE, &authType))
{
WIFI_AUTHTYPE tmp;
validAuthType = WiFiAuthTypeStringToEnum(authType, &tmp);
- if (validAuthType == true)
+ if (validAuthType && isAuthTypeSupported(tmp))
{
- g_ESWiFiConfResource.authType = tmp;
- wiFiData->authtype = g_ESWiFiConfResource.authType;
+ wiFiData->authtype = tmp;
OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "g_ESWiFiConfResource.authType %u",
- g_ESWiFiConfResource.authType);
+ wiFiData->authtype);
+ }
+ else
+ {
+ OIC_LOG(ERROR, ES_RH_TAG, "AuthType is not supported.");
+ ehResult = OC_EH_BAD_REQ;
+ goto EXIT;
}
}
bool validEncType = false;
- char *encType = NULL;
if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_ENCTYPE, &encType))
{
WIFI_ENCTYPE tmp;
validEncType = WiFiEncTypeStringToEnum(encType, &tmp);
- if (validEncType == true)
+ if (validEncType && isEncTypeSupported(tmp))
{
- g_ESWiFiConfResource.encType = tmp;
- wiFiData->enctype = g_ESWiFiConfResource.encType;
+ wiFiData->enctype = tmp;
OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "g_ESWiFiConfResource.encType %u",
- g_ESWiFiConfResource.encType);
+ wiFiData->enctype);
+ }
+ else
+ {
+ OIC_LOG(ERROR, ES_RH_TAG, "EncType is not supported.");
+ ehResult = OC_EH_BAD_REQ;
+ goto EXIT;
}
}
+ if (validAuthType)
+ {
+ g_ESWiFiConfResource.authType = wiFiData->authtype;
+ }
+
+ if (validEncType)
+ {
+ g_ESWiFiConfResource.encType = wiFiData->enctype;
+ }
+
+ if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_SSID, &ssid))
+ {
+ OICStrcpy(g_ESWiFiConfResource.ssid, sizeof(g_ESWiFiConfResource.ssid), ssid);
+ OICStrcpy(wiFiData->ssid, sizeof(wiFiData->ssid), ssid);
+ OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "g_ESWiFiConfResource.ssid : %s",
+ g_ESWiFiConfResource.ssid);
+ }
+
+ if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_CRED, &cred))
+ {
+ OICStrcpy(g_ESWiFiConfResource.cred, sizeof(g_ESWiFiConfResource.cred), cred);
+ OICStrcpy(wiFiData->pwd, sizeof(wiFiData->pwd), cred);
+ OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "g_ESWiFiConfResource.cred %s",
+ g_ESWiFiConfResource.cred);
+ }
+
if (gReadUserdataCb)
{
gReadUserdataCb(input, OC_RSRVD_ES_RES_TYPE_WIFICONF, &wiFiData->userdata);
OIC_LOG(DEBUG, ES_RH_TAG, "Enrollee doesn't have any observer.");
}
+ ehResult = OC_EH_OK;
+
+EXIT:
OICFree(encType);
OICFree(authType);
OICFree(cred);
OICFree(ssid);
OICFree(wiFiData);
+ return ehResult;
}
void updateCoapCloudConfResource(OCRepPayload* input)
// If a writable property in oic.r.devconf is added later,
// a condition for calling a resistered callback should be implemented also.
- if( devConfData->userdata != NULL )
+ if (devConfData->userdata != NULL)
{
OIC_LOG(DEBUG, ES_RH_TAG, "Send DevConfRsrc Callback To ES");
OIC_LOG(ERROR, ES_RH_TAG, "Incoming payload not a representation");
return ehResult;
}
- if(!isValidESResourceHandle(ehRequest->resource))
+ if (!isValidESResourceHandle(ehRequest->resource))
{
OIC_LOG(ERROR, ES_RH_TAG, "Request does not have a valid Easy Setup Resource handle");
return ehResult;
char *iface_name = NULL;
GetInterfaceNameFromQuery(ehRequest->query, &iface_name);
- if(!iface_name)
+ if (!iface_name)
{
iface_name = OICStrdup(OC_RSRVD_INTERFACE_DEFAULT);
}
}
else
{
- updateEasySetupResource(ehRequest, input);
+ if (updateEasySetupResource(ehRequest, input) != OC_EH_OK)
+ {
+ OIC_LOG(ERROR, ES_RH_TAG, "Failed to update EasySetup resource.");
+ return OC_EH_BAD_REQ;
+ }
}
}
else if (ehRequest->resource == g_ESWiFiConfResource.handle)
}
else
{
- updateWiFiConfResource(input);
+ if (updateWiFiConfResource(input) != OC_EH_OK)
+ {
+ OIC_LOG(ERROR, ES_RH_TAG, "Failed to update WifiConf resource.");
+ return OC_EH_BAD_REQ;
+ }
}
}
else if (ehRequest->resource == g_ESCoapCloudConfResource.handle)
return OC_EH_OK;
}
+bool isAuthTypeSupported(WIFI_AUTHTYPE authType)
+{
+ bool supported = false;
+ for (uint8_t i = 0; i < g_ESWiFiConfResource.numSupportedAuthType; ++i)
+ {
+ if (g_ESWiFiConfResource.supportedAuthType[i] == authType)
+ {
+ supported = true;
+ break;
+ }
+ }
+ return supported;
+}
+
+bool isEncTypeSupported(WIFI_ENCTYPE encType)
+{
+ bool supported = false;
+ for (uint8_t i = 0; i < g_ESWiFiConfResource.numSupportedEncType; ++i)
+ {
+ if (g_ESWiFiConfResource.supportedEncType[i] == encType)
+ {
+ supported = true;
+ break;
+ }
+ }
+ return supported;
+}
+
const char *getResult(OCStackResult result)
{
switch (result)
typedef enum
{
/**
- * Init Error Code
+ * Init Error Code.
*/
ES_ERRCODE_NO_ERROR = 0,
/**
- * Error Code that given WiFi's SSID is not found
+ * WiFi's SSID is not found.
*/
ES_ERRCODE_SSID_NOT_FOUND,
/**
- * Error Code that given WiFi's Password is wrong
+ * WiFi's Password is wrong.
*/
ES_ERRCODE_PW_WRONG,
/**
- * Error Code that IP address is not allocated
+ * IP address is not allocated.
*/
ES_ERRCODE_IP_NOT_ALLOCATED,
/**
- * Error Code that there is no Internet connection
+ * There is no Internet connection.
*/
ES_ERRCODE_NO_INTERNETCONNECTION,
/**
- * Error Code that Timeout occured
+ * Timeout occured.
*/
ES_ERRCODE_TIMEOUT,
/**
- * Error Code that cloud server is not reachable due to wrong URL of cloud server, for example.
+ * Auth type is not supported by the Enrollee.
+ */
+ ES_ERRCODE_AUTH_TYPE_NOT_SUPPORTED,
+
+ /**
+ * Enc type is not supported by the Enrollee.
+ */
+ ES_ERRCODE_ENC_TYPE_NOT_SUPPORTED,
+
+ /**
+ * Auth type is not supported by the Enroller.
+ */
+ ES_ERRCODE_AUTH_TYPE_INVALID,
+
+ /**
+ * Enc type is not supported by the Enroller.
+ */
+ ES_ERRCODE_ENC_TYPE_INVALID,
+
+ /**
+ * Cloud server is not reachable due to wrong URL of cloud server, for example.
*/
ES_ERRCODE_FAILED_TO_ACCESS_CLOUD_SERVER,
/**
- * Error Code that no response is arrived from cloud server
+ * No response from cloud server.
*/
ES_ERRCODE_NO_RESPONSE_FROM_CLOUD_SERVER,
/**
- * Error Code that a delivered authcode is not valid.
+ * Delivered authcode is not valid.
*/
ES_ERRCODE_INVALID_AUTHCODE,
/**
- * Error Code that a given access token is not valid due to its expiration, for example.
+ * Access token is not valid due to its expiration, for example.
*/
ES_ERRCODE_INVALID_ACCESSTOKEN,
/**
- * Error Code that a refresh of expired access token is failed due to some reasons.
+ * Refresh of expired access token is failed due to some reasons.
*/
ES_ERRCODE_FAILED_TO_REFRESH_ACCESSTOKEN,
/**
- * Error Code that a target device is not discovered in cloud server
+ * Target device is not discovered in cloud server.
*/
ES_ERRCODE_FAILED_TO_FIND_REGISTERED_DEVICE_IN_CLOUD,
/**
- * Error Code that a target user does not exist in cloud server.
+ * Target user does not exist in cloud server.
*/
ES_ERRCODE_FAILED_TO_FIND_REGISTERED_USER_IN_CLOUD,
/**
- * Error Code that an enrollee can not connect to a target WiFi AP because the AP resides in
+ * Enrollee can not connect to a target WiFi AP because the AP resides in
* an unsupported WiFi frequency.
*/
ES_ERRCODE_UNSUPPORTED_WIFI_FREQUENCY,
/**
- * Error Code that Unknown error occured
+ * Unknown error occured.
*/
ES_ERRCODE_UNKNOWN = 255
} ESErrorCode;
public enum ESErrorCode {
/**
- * Init Error Code
+ * Init Error Code.
*/
ES_ERRCODE_NO_ERROR(0),
/**
- * Error Code that given WiFi's SSID is not found
+ * WiFi's SSID is not found.
*/
ES_ERRCODE_SSID_NOT_FOUND(1),
/**
- * Error Code that given WiFi's Password is wrong
+ * WiFi's Password is wrong.
*/
ES_ERRCODE_PW_WRONG(2),
/**
- * Error Code that IP address is not allocated
+ * IP address is not allocated.
*/
ES_ERRCODE_IP_NOT_ALLOCATED(3),
/**
- * Error Code that there is no Internet connection
+ * There is no Internet connection.
*/
ES_ERRCODE_NO_INTERNETCONNECTION(4),
/**
- * Error Code that Timeout occured
+ * Timeout occured.
*/
ES_ERRCODE_TIMEOUT(5),
/**
- * Error Code that cloud server is not reachable due to wrong URL of cloud server, for example.
+ * Auth type is not supported by the Enrollee.
*/
- ES_ERRCODE_FAILED_TO_ACCESS_CLOUD_SERVER(6),
+ ES_ERRCODE_AUTH_TYPE_NOT_SUPPORTED(6),
/**
- * Error Code that no response is arrived from cloud server
+ * Enc type is not supported by the Enrollee.
*/
- ES_ERRCODE_NO_RESPONSE_FROM_CLOUD_SERVER(7),
+ ES_ERRCODE_ENC_TYPE_NOT_SUPPORTED(7),
/**
- * Error Code that a delivered authcode is not valid.
+ * Auth type is not supported by the Enroller.
*/
- ES_ERRCODE_INVALID_AUTHCODE(8),
+ ES_ERRCODE_AUTH_TYPE_INVALID(8),
/**
- * Error Code that a given access token is not valid due to its expiration, for example.
+ * Enc type is not supported by the Enroller.
*/
- ES_ERRCODE_INVALID_ACCESSTOKEN(9),
+ ES_ERRCODE_ENC_TYPE_INVALID(9),
/**
- * Error Code that a refresh of expired access token is failed due to some reasons.
+ * Cloud server is not reachable due to wrong URL of cloud server, for example.
*/
- ES_ERRCODE_FAILED_TO_REFRESH_ACCESSTOKEN(10),
+ ES_ERRCODE_FAILED_TO_ACCESS_CLOUD_SERVER(10),
/**
- * Error Code that a target device is not discovered in cloud server
+ * No response from cloud server.
*/
- ES_ERRCODE_FAILED_TO_FIND_REGISTERED_DEVICE_IN_CLOUD(11),
+ ES_ERRCODE_NO_RESPONSE_FROM_CLOUD_SERVER(11),
/**
- * Error Code that a target user does not exist in cloud server.
+ * Delivered authcode is not valid.
*/
- ES_ERRCODE_FAILED_TO_FIND_REGISTERED_USER_IN_CLOUD(12),
+ ES_ERRCODE_INVALID_AUTHCODE(12),
/**
- * Error Code that an enrollee can not connect to a target WiFi AP because the AP resides in
+ * Access token is not valid due to its expiration, for example.
+ */
+ ES_ERRCODE_INVALID_ACCESSTOKEN(13),
+
+ /**
+ * Refresh of expired access token is failed due to some reasons.
+ */
+ ES_ERRCODE_FAILED_TO_REFRESH_ACCESSTOKEN(14),
+
+ /**
+ * Target device is not discovered in cloud server.
+ */
+ ES_ERRCODE_FAILED_TO_FIND_REGISTERED_DEVICE_IN_CLOUD(15),
+
+ /**
+ * Target user does not exist in cloud server.
+ */
+ ES_ERRCODE_FAILED_TO_FIND_REGISTERED_USER_IN_CLOUD(16),
+
+ /**
+ * Enrollee can not connect to a target WiFi AP because the AP resides in
* an unsupported WiFi frequency.
*/
- ES_ERRCODE_UNSUPPORTED_WIFI_FREQUENCY(13),
+ ES_ERRCODE_UNSUPPORTED_WIFI_FREQUENCY(17),
/**
- * Error Code that Unknown error occured
+ * Unknown error occured.
*/
ES_ERRCODE_UNKNOWN(255);