From: Madan Lanka Date: Tue, 1 Sep 2015 01:48:38 +0000 (-0400) Subject: CBOR changes for EasySetup Enrollee and Mediator X-Git-Tag: 1.0.0-RC1^2~27^2~11 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fcb2de769c5089ff64e8fc9b8ffc15df045e18e9;p=contrib%2Fiotivity.git CBOR changes for EasySetup Enrollee and Mediator 1) Updated Enrollee to handle CBOR payload 2) Updated Mediator to handle CBOR payload Change-Id: I1dc346c360f9415e14f54313e27ef0f89a170733 Signed-off-by: Madan Lanka Reviewed-on: https://gerrit.iotivity.org/gerrit/2327 --- diff --git a/service/easy-setup/sampleapp/android/EasySetup/easySetupCore-debug/build.gradle b/service/easy-setup/sampleapp/android/EasySetup/easySetupCore-debug/build.gradle deleted file mode 100644 index 4213d41..0000000 --- a/service/easy-setup/sampleapp/android/EasySetup/easySetupCore-debug/build.gradle +++ /dev/null @@ -1,2 +0,0 @@ -configurations.create("default") -artifacts.add("default", file('easySetupCore-debug.aar')) \ No newline at end of file diff --git a/service/easy-setup/sampleapp/android/EasySetup/easySetupCore-debug/easySetupCore-debug.iml b/service/easy-setup/sampleapp/android/EasySetup/easySetupCore-debug/easySetupCore-debug.iml deleted file mode 100644 index 995ecfb..0000000 --- a/service/easy-setup/sampleapp/android/EasySetup/easySetupCore-debug/easySetupCore-debug.iml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/service/easy-setup/sampleapp/android/EasySetup/iotivity-armeabi-base-debug/build.gradle b/service/easy-setup/sampleapp/android/EasySetup/iotivity-armeabi-base-debug/build.gradle deleted file mode 100644 index 65c8cbe..0000000 --- a/service/easy-setup/sampleapp/android/EasySetup/iotivity-armeabi-base-debug/build.gradle +++ /dev/null @@ -1,2 +0,0 @@ -configurations.create("default") -artifacts.add("default", file('iotivity-armeabi-base-debug.aar')) \ No newline at end of file diff --git a/service/easy-setup/sampleapp/android/EasySetup/iotivity-armeabi-base-debug/iotivity-armeabi-base-debug.iml b/service/easy-setup/sampleapp/android/EasySetup/iotivity-armeabi-base-debug/iotivity-armeabi-base-debug.iml deleted file mode 100644 index 8f28f8f..0000000 --- a/service/easy-setup/sampleapp/android/EasySetup/iotivity-armeabi-base-debug/iotivity-armeabi-base-debug.iml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/service/easy-setup/sampleapp/arduino/thinserver/thinserver.cpp b/service/easy-setup/sampleapp/arduino/thinserver/thinserver.cpp index ee3617d..8a33941 100644 --- a/service/easy-setup/sampleapp/arduino/thinserver/thinserver.cpp +++ b/service/easy-setup/sampleapp/arduino/thinserver/thinserver.cpp @@ -47,8 +47,8 @@ const char *getResult(OCStackResult result); PROGMEM const char TAG[] = "ThinServer"; -char ssid[] = "EasySetup123"; -char passwd[] = "EasySetup123"; +char ssid[] = "hub2.4G"; +char passwd[] = "11112222"; void EventCallbackInApp(ES_RESULT eventFlag) { diff --git a/service/easy-setup/sdk/common/common.h b/service/easy-setup/sdk/common/common.h index 281754b..d1f469b 100644 --- a/service/easy-setup/sdk/common/common.h +++ b/service/easy-setup/sdk/common/common.h @@ -27,7 +27,7 @@ // Defines #define OIC_STRING_MAX_VALUE 100 #define IPV4_ADDR_SIZE 16 -#define IP_PORT 6298 +#define IP_PORT 55555 #define NET_WIFI_SSID_SIZE 16 #define NET_WIFI_PWD_SIZE 16 @@ -38,7 +38,7 @@ //The following variable determines the interface (wifi, ethernet etc.) //to be used for sending unicast messages. Default set to Ethernet. -static OCConnectivityType OC_CONNTYPE = CT_ADAPTER_IP; +static OCConnectivityType OC_CONNTYPE = CT_IP_USE_V4; static const char * UNICAST_PROVISIONING_QUERY = "coap://%s:%d/oic/res?rt=oic.prov"; static const char * UNICAST_PROV_STATUS_QUERY = "coap://%s:%d%s"; diff --git a/service/easy-setup/sdk/enrollee/common/src/resourceHandler.cpp b/service/easy-setup/sdk/enrollee/common/src/resourceHandler.cpp index 8024fdd..768ecc2 100644 --- a/service/easy-setup/sdk/enrollee/common/src/resourceHandler.cpp +++ b/service/easy-setup/sdk/enrollee/common/src/resourceHandler.cpp @@ -39,298 +39,305 @@ ResourceEventCallback g_cbForResEvent = NULL; void RegisterResourceEventCallBack(ResourceEventCallback cb) { - g_cbForResEvent = cb; + g_cbForResEvent = cb; } void GetTargetNetworkInfoFromProvResource(char *name, char *pass) { - if (name != NULL && pass != NULL) - { - sprintf(name, "%s", g_prov.tnn); - sprintf(pass, "%s", g_prov.cd); - } + if (name != NULL && pass != NULL) + { + sprintf(name, "%s", g_prov.tnn); + sprintf(pass, "%s", g_prov.cd); + } } OCStackResult CreateProvisioningResource() { - g_prov.ps = 1; // need to provisioning - g_prov.tnt = ES_WIFI; - sprintf(g_prov.tnn, "Unknown"); - sprintf(g_prov.cd, "Unknown"); + g_prov.ps = 1; // need to provisioning + g_prov.tnt = ES_WIFI; + sprintf(g_prov.tnn, "Unknown"); + sprintf(g_prov.cd, "Unknown"); - OCStackResult res = OCCreateResource(&g_prov.handle, "oic.prov", OC_RSRVD_INTERFACE_DEFAULT, - OC_RSRVD_ES_URI_PROV, OCEntityHandlerCb,NULL, OC_DISCOVERABLE | OC_OBSERVABLE); + OCStackResult res = OCCreateResource(&g_prov.handle, "oic.prov", OC_RSRVD_INTERFACE_DEFAULT, + OC_RSRVD_ES_URI_PROV, OCEntityHandlerCb,NULL, OC_DISCOVERABLE | OC_OBSERVABLE); - OC_LOG_V(INFO, TAG, "Created Prov resource with result: %s", getResult(res)); + OC_LOG_V(INFO, TAG, "Created Prov resource with result: %s", getResult(res)); - return res; + return res; } OCStackResult CreateNetworkResource() { - NetworkInfo netInfo; + NetworkInfo netInfo; - if (getCurrentNetworkInfo(ES_WIFI, &netInfo) != 0) - { - return OC_STACK_ERROR; - } + if (getCurrentNetworkInfo(ES_WIFI, &netInfo) != 0) + { + return OC_STACK_ERROR; + } - if (netInfo.type != ES_WIFI) - { - return OC_STACK_ERROR; - } + if (netInfo.type != ES_WIFI) + { + return OC_STACK_ERROR; + } - g_net.cnt = (int) netInfo.type; - g_net.ant[0] = (int) ES_WIFI; - sprintf(g_net.ipaddr, "%d.%d.%d.%d", netInfo.ipaddr[0], netInfo.ipaddr[1], netInfo.ipaddr[2], - netInfo.ipaddr[3]); - sprintf(g_net.cnn, "%s", netInfo.ssid); + g_net.cnt = (int) netInfo.type; + g_net.ant[0] = (int) ES_WIFI; + sprintf(g_net.ipaddr, "%d.%d.%d.%d", netInfo.ipaddr[0], netInfo.ipaddr[1], netInfo.ipaddr[2], + netInfo.ipaddr[3]); + sprintf(g_net.cnn, "%s", netInfo.ssid); - OC_LOG_V(INFO, TAG, "SSID: %s", g_net.cnn); - OC_LOG_V(INFO, TAG, "IP Address: %s", g_net.ipaddr); + OC_LOG_V(INFO, TAG, "SSID: %s", g_net.cnn); + OC_LOG_V(INFO, TAG, "IP Address: %s", g_net.ipaddr); - OCStackResult res = OCCreateResource(&g_net.handle, "oic.net", OC_RSRVD_INTERFACE_DEFAULT, - OC_RSRVD_ES_URI_NET, OCEntityHandlerCb,NULL, OC_DISCOVERABLE | OC_OBSERVABLE); - OC_LOG_V(INFO, TAG, "Created Net resource with result: %s", getResult(res)); + OCStackResult res = OCCreateResource(&g_net.handle, "oic.net", OC_RSRVD_INTERFACE_DEFAULT, + OC_RSRVD_ES_URI_NET, OCEntityHandlerCb,NULL, OC_DISCOVERABLE | OC_OBSERVABLE); + OC_LOG_V(INFO, TAG, "Created Net resource with result: %s", getResult(res)); - return res; + return res; } OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload **payload) { - OCEntityHandlerResult ehResult = OC_EH_ERROR; - OCRepPayload *getResp = constructResponse(ehRequest); - if(!getResp) - { - OC_LOG(ERROR, TAG, "constructResponse failed"); - return OC_EH_ERROR; - } - - *payload = getResp; - ehResult = OC_EH_OK; - - return ehResult; + OCEntityHandlerResult ehResult = OC_EH_ERROR; + if(!ehRequest) + { + OC_LOG(ERROR, TAG, PCF("Request is Null")); + return ehResult; + } + if(ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION) + { + OC_LOG(ERROR, TAG, PCF("Incoming payload not a representation")); + return ehResult; + } + + OCRepPayload *getResp = constructResponse(ehRequest); + if(!getResp) + { + OC_LOG(ERROR, TAG, "constructResponse failed"); + return OC_EH_ERROR; + } + + *payload = getResp; + ehResult = OC_EH_OK; + + return ehResult; } OCEntityHandlerResult ProcessPutRequest (OCEntityHandlerRequest *ehRequest, - OCRepPayload** payload) + OCRepPayload** payload) { - OCEntityHandlerResult ehResult=OC_EH_ERROR; - if(ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION) - { - OC_LOG(ERROR, TAG, PCF("Incoming payload not a representation")); - return ehResult; - } + OCEntityHandlerResult ehResult=OC_EH_ERROR; + if(ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION) + { + OC_LOG(ERROR, TAG, PCF("Incoming payload not a representation")); + return ehResult; + } - OCRepPayload* input = (OCRepPayload*)(ehRequest->payload); - if(!input) - { - OC_LOG_V(ERROR, TAG, "Failed to parse"); - return ehResult; - } + OCRepPayload* input = (OCRepPayload*)(ehRequest->payload); + if(!input) + { + OC_LOG_V(ERROR, TAG, "Failed to parse"); + return ehResult; + } - const char* tnn; - if(OCRepPayloadGetPropString(input,OC_RSRVD_ES_TNN, &tnn)) - { - sprintf(g_prov.tnn, "%s", tnn); - } + const char* tnn; + if(OCRepPayloadGetPropString(input,OC_RSRVD_ES_TNN, &tnn)) + { + sprintf(g_prov.tnn, "%s", tnn); + } - const char* cd; - if(OCRepPayloadGetPropString(input, OC_RSRVD_ES_CD, &cd)) - { - sprintf(g_prov.cd, "%s", cd); - } + const char* cd; + if(OCRepPayloadGetPropString(input, OC_RSRVD_ES_CD, &cd)) + { + sprintf(g_prov.cd, "%s", cd); + } - g_flag = 1; + g_flag = 1; - OCRepPayload *getResp = constructResponse(ehRequest); - if(!getResp) - { - OC_LOG(ERROR, TAG, "constructResponse failed"); - return OC_EH_ERROR; - } + OCRepPayload *getResp = constructResponse(ehRequest); + if(!getResp) + { + OC_LOG(ERROR, TAG, "constructResponse failed"); + return OC_EH_ERROR; + } - *payload = getResp; - ehResult = OC_EH_OK; + *payload = getResp; + ehResult = OC_EH_OK; - return ehResult; + return ehResult; } OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload) { - OCEntityHandlerResult ehResult = OC_EH_ERROR; - if(!ehRequest) - { - OC_LOG(ERROR, TAG, PCF("Request is Null")); - return ehResult; - } - if(ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION) - { - OC_LOG(ERROR, TAG, PCF("Incoming payload not a representation")); - return ehResult; - } - - OCRepPayload* input = (OCRepPayload*)(ehRequest->payload); - if(!input) - { - OC_LOG_V(ERROR, TAG, "Failed to parse" ); - return ehResult; - } - const char* tr; - if(OCRepPayloadGetPropString(input, OC_RSRVD_ES_TR, &tr)) - { - - // Triggering - ehResult = OC_EH_OK; - } - - g_flag = 1; - - return ehResult; + OCEntityHandlerResult ehResult = OC_EH_ERROR; + if(!ehRequest) + { + OC_LOG(ERROR, TAG, PCF("Request is Null")); + return ehResult; + } + if(ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION) + { + OC_LOG(ERROR, TAG, PCF("Incoming payload not a representation")); + return ehResult; + } + + OCRepPayload* input = (OCRepPayload*)(ehRequest->payload); + if(!input) + { + OC_LOG_V(ERROR, TAG, "Failed to parse" ); + return ehResult; + } + const char* tr; + if(OCRepPayloadGetPropString(input, OC_RSRVD_ES_TR, &tr)) + { + + // Triggering + ehResult = OC_EH_OK; + } + + g_flag = 1; + + return ehResult; } OCRepPayload* constructResponse(OCEntityHandlerRequest *ehRequest) { - - OCRepPayload* payload = OCRepPayloadCreate(); - if(!payload) - { - OC_LOG(ERROR, TAG, PCF("Failed to allocate Payload")); - return NULL; - } - - if (g_prov.handle != NULL && ehRequest->resource == g_prov.handle) - { - - - OCRepPayloadSetUri(payload,OC_RSRVD_ES_URI_PROV); - - OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_PS,g_prov.ps); - OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_TNT, g_prov.tnt); - OCRepPayloadSetPropString(payload,OC_RSRVD_ES_TNN, g_prov.tnn); - OCRepPayloadSetPropString(payload,OC_RSRVD_ES_CD, g_prov.cd); - } - else if (g_net.handle != NULL && ehRequest->requestHandle == g_net.handle) - { - - OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_NET); - OCRepPayloadSetPropInt(payload, "ant", g_net.ant[0]); - } - return payload; + OCRepPayload* payload = OCRepPayloadCreate(); + if(!payload) + { + OC_LOG(ERROR, TAG, PCF("Failed to allocate Payload")); + return NULL; + } + + if (ehRequest->resource == g_prov.handle) + { + OCRepPayloadSetUri(payload,OC_RSRVD_ES_URI_PROV); + OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_PS,g_prov.ps); + OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_TNT, g_prov.tnt); + OCRepPayloadSetPropString(payload,OC_RSRVD_ES_TNN, g_prov.tnn); + OCRepPayloadSetPropString(payload,OC_RSRVD_ES_CD, g_prov.cd); + } + else if (ehRequest->requestHandle == g_net.handle) + { + + OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_NET); + OCRepPayloadSetPropInt(payload, "ant", g_net.ant[0]); + } + return payload; } // This is the entity handler for the registered resource. // This is invoked by OCStack whenever it recevies a request for this resource. OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag, - OCEntityHandlerRequest* entityHandlerRequest,void *callback) + OCEntityHandlerRequest* entityHandlerRequest,void *callback) { - (void)callback; - OCEntityHandlerResult ehRet = OC_EH_OK; - OCEntityHandlerResponse response = - { 0 }; - OCRepPayload* payload = NULL; - if (entityHandlerRequest && (flag & OC_REQUEST_FLAG)) - { - if (OC_REST_GET == entityHandlerRequest->method) - { - OC_LOG_V(INFO, TAG, "Received GET request"); - ehRet = ProcessGetRequest(entityHandlerRequest, &payload); - } - else if (OC_REST_PUT == entityHandlerRequest->method) - { - OC_LOG_V(INFO, TAG, "Received PUT request"); - - if (g_prov.handle != NULL && entityHandlerRequest->resource == g_prov.handle) - { - ehRet = ProcessPutRequest(entityHandlerRequest, &payload); - } - else - { - ehRet = OC_EH_ERROR; - } - } - else if (OC_REST_POST == entityHandlerRequest->method) - { - // TODO: As of now, POST request will be not received. - OC_LOG(INFO, TAG, "Received OC_REST_POST from client"); - //ehRet = ProcessPostRequest (entityHandlerRequest, payload, sizeof(payload) - 1); - } - - if (ehRet == OC_EH_OK) - { - // Format the response. Note this requires some info about the request - response.requestHandle = entityHandlerRequest->requestHandle; - response.resourceHandle = entityHandlerRequest->resource; - response.ehResult = ehRet; - response.payload = (OCPayload*)(&payload); //response uses OCPaylod while all get,put methodes use OCRepPayload - response.numSendVendorSpecificHeaderOptions = 0; - memset(response.sendVendorSpecificHeaderOptions, 0, - sizeof response.sendVendorSpecificHeaderOptions); - memset(response.resourceUri, 0, sizeof response.resourceUri); - // Indicate that response is NOT in a persistent buffer - response.persistentBufferFlag = 0; - - // Send the response - if (OCDoResponse(&response) != OC_STACK_OK) - { - OC_LOG(ERROR, TAG, "Error sending response"); - ehRet = OC_EH_ERROR; - } - } - } - - if (g_flag == 1) - { - g_cbForResEvent(ES_RECVTRIGGEROFPROVRES); - g_flag = 0; - } - - return ehRet; + (void)callback; + OCEntityHandlerResult ehRet = OC_EH_OK; + OCEntityHandlerResponse response = + { 0 }; + OCRepPayload* payload = NULL; + if (entityHandlerRequest && (flag & OC_REQUEST_FLAG)) + { + if (OC_REST_GET == entityHandlerRequest->method) + { + OC_LOG_V(INFO, TAG, "Received GET request"); + ehRet = ProcessGetRequest(entityHandlerRequest, &payload); + } + else if (OC_REST_PUT == entityHandlerRequest->method) + { + OC_LOG_V(INFO, TAG, "Received PUT request"); + + if (g_prov.handle != NULL && entityHandlerRequest->resource == g_prov.handle) + { + ehRet = ProcessPutRequest(entityHandlerRequest, &payload); + } + else + { + ehRet = OC_EH_ERROR; + } + } + else if (OC_REST_POST == entityHandlerRequest->method) + { + // TODO: As of now, POST request will be not received. + OC_LOG(INFO, TAG, "Received OC_REST_POST from client"); + //ehRet = ProcessPostRequest (entityHandlerRequest, payload, sizeof(payload) - 1); + } + + if (ehRet == OC_EH_OK) + { + // Format the response. Note this requires some info about the request + response.requestHandle = entityHandlerRequest->requestHandle; + response.resourceHandle = entityHandlerRequest->resource; + response.ehResult = ehRet; + response.payload = (OCPayload*)(payload); //response uses OCPaylod while all get,put methodes use OCRepPayload + response.numSendVendorSpecificHeaderOptions = 0; + memset(response.sendVendorSpecificHeaderOptions, 0, + sizeof response.sendVendorSpecificHeaderOptions); + memset(response.resourceUri, 0, sizeof response.resourceUri); + // Indicate that response is NOT in a persistent buffer + response.persistentBufferFlag = 0; + + // Send the response + if (OCDoResponse(&response) != OC_STACK_OK) + { + OC_LOG(ERROR, TAG, "Error sending response"); + ehRet = OC_EH_ERROR; + } + } + } + + if (g_flag == 1) + { + g_cbForResEvent(ES_RECVTRIGGEROFPROVRES); + g_flag = 0; + } + + return ehRet; } const char *getResult(OCStackResult result) { - switch (result) - { - case OC_STACK_OK: - return "OC_STACK_OK"; - case OC_STACK_INVALID_URI: - return "OC_STACK_INVALID_URI"; - case OC_STACK_INVALID_QUERY: - return "OC_STACK_INVALID_QUERY"; - case OC_STACK_INVALID_IP: - return "OC_STACK_INVALID_IP"; - case OC_STACK_INVALID_PORT: - return "OC_STACK_INVALID_PORT"; - case OC_STACK_INVALID_CALLBACK: - return "OC_STACK_INVALID_CALLBACK"; - case OC_STACK_INVALID_METHOD: - return "OC_STACK_INVALID_METHOD"; - case OC_STACK_NO_MEMORY: - return "OC_STACK_NO_MEMORY"; - case OC_STACK_COMM_ERROR: - return "OC_STACK_COMM_ERROR"; - case OC_STACK_INVALID_PARAM: - return "OC_STACK_INVALID_PARAM"; - case OC_STACK_NOTIMPL: - return "OC_STACK_NOTIMPL"; - case OC_STACK_NO_RESOURCE: - return "OC_STACK_NO_RESOURCE"; - case OC_STACK_RESOURCE_ERROR: - return "OC_STACK_RESOURCE_ERROR"; - case OC_STACK_SLOW_RESOURCE: - return "OC_STACK_SLOW_RESOURCE"; - case OC_STACK_NO_OBSERVERS: - return "OC_STACK_NO_OBSERVERS"; - case OC_STACK_ERROR: - return "OC_STACK_ERROR"; - default: - return "UNKNOWN"; - } + switch (result) + { + case OC_STACK_OK: + return "OC_STACK_OK"; + case OC_STACK_INVALID_URI: + return "OC_STACK_INVALID_URI"; + case OC_STACK_INVALID_QUERY: + return "OC_STACK_INVALID_QUERY"; + case OC_STACK_INVALID_IP: + return "OC_STACK_INVALID_IP"; + case OC_STACK_INVALID_PORT: + return "OC_STACK_INVALID_PORT"; + case OC_STACK_INVALID_CALLBACK: + return "OC_STACK_INVALID_CALLBACK"; + case OC_STACK_INVALID_METHOD: + return "OC_STACK_INVALID_METHOD"; + case OC_STACK_NO_MEMORY: + return "OC_STACK_NO_MEMORY"; + case OC_STACK_COMM_ERROR: + return "OC_STACK_COMM_ERROR"; + case OC_STACK_INVALID_PARAM: + return "OC_STACK_INVALID_PARAM"; + case OC_STACK_NOTIMPL: + return "OC_STACK_NOTIMPL"; + case OC_STACK_NO_RESOURCE: + return "OC_STACK_NO_RESOURCE"; + case OC_STACK_RESOURCE_ERROR: + return "OC_STACK_RESOURCE_ERROR"; + case OC_STACK_SLOW_RESOURCE: + return "OC_STACK_SLOW_RESOURCE"; + case OC_STACK_NO_OBSERVERS: + return "OC_STACK_NO_OBSERVERS"; + case OC_STACK_ERROR: + return "OC_STACK_ERROR"; + default: + return "UNKNOWN"; + } } diff --git a/service/easy-setup/sdk/mediator/inc/provisioninghandler.h b/service/easy-setup/sdk/mediator/inc/provisioninghandler.h index f4380e8..b9d801c 100644 --- a/service/easy-setup/sdk/mediator/inc/provisioninghandler.h +++ b/service/easy-setup/sdk/mediator/inc/provisioninghandler.h @@ -54,16 +54,18 @@ void listeningFunc(void*); OCStackApplicationResult ProvisionEnrolleeResponse(void* ctx, OCDoHandle handle, OCClientResponse * clientResponse); -OCStackResult ProvisionEnrollee(OCQualityOfService qos, const char* query, const char* resUri); +OCStackResult ProvisionEnrollee(OCQualityOfService qos, const char* query, const char* resUri, + OCDevAddr *destination); OCStackApplicationResult GetProvisioningStatusResponse(void* ctx, OCDoHandle handle, OCClientResponse * clientResponse); -OCStackResult InvokeOCDoResource(const char* query, OCMethod method, +OCStackResult InvokeOCDoResource(const char* query, OCMethod method, const OCDevAddr *dest, OCQualityOfService qos, OCClientResponseHandler cb,OCRepPayload * request, OCHeaderOption * options, uint8_t numOptions); -OCStackResult GetProvisioningStatus(OCQualityOfService qos, const char* query); +OCStackResult GetProvisioningStatus(OCQualityOfService qos, const char* query, + const OCDevAddr *destination); OCStackResult StartProvisioningProcess(const EnrolleeNWProvInfo_t *netInfo, OCProvisioningStatusCB provisioningStatusCallback); diff --git a/service/easy-setup/sdk/mediator/src/provisioninghandler.cpp b/service/easy-setup/sdk/mediator/src/provisioninghandler.cpp index f242269..f0a7780 100644 --- a/service/easy-setup/sdk/mediator/src/provisioninghandler.cpp +++ b/service/easy-setup/sdk/mediator/src/provisioninghandler.cpp @@ -165,6 +165,7 @@ OCStackApplicationResult ProvisionEnrolleeResponse(void* ctx, OCDoHandle handle, if(ps == 1) { OIC_LOG_V(DEBUG, TAG, "PS is proper"); + input = input->next; continue; } else{ @@ -172,7 +173,7 @@ OCStackApplicationResult ProvisionEnrolleeResponse(void* ctx, OCDoHandle handle, provInfo = PrepareProvisioingStatusCB(clientResponse, DEVICE_NOT_PROVISIONED); cbData(provInfo); - + return OC_STACK_DELETE_TRANSACTION; } } @@ -181,6 +182,7 @@ OCStackApplicationResult ProvisionEnrolleeResponse(void* ctx, OCDoHandle handle, if(!strcmp(tnn, netProvInfo->netAddressInfo.WIFI.ssid)) { OIC_LOG_V(DEBUG, TAG, "SSID is proper"); + input = input->next; continue; } else{ @@ -188,6 +190,7 @@ OCStackApplicationResult ProvisionEnrolleeResponse(void* ctx, OCDoHandle handle, provInfo = PrepareProvisioingStatusCB(clientResponse, DEVICE_NOT_PROVISIONED); cbData(provInfo); + return OC_STACK_DELETE_TRANSACTION; } } const char* cd; @@ -195,6 +198,7 @@ OCStackApplicationResult ProvisionEnrolleeResponse(void* ctx, OCDoHandle handle, if(!strcmp(cd,netProvInfo->netAddressInfo.WIFI.pwd)) { OIC_LOG_V(DEBUG, TAG, "Password is proper"); + input = input->next; continue; } else{ @@ -202,6 +206,7 @@ OCStackApplicationResult ProvisionEnrolleeResponse(void* ctx, OCDoHandle handle, provInfo = PrepareProvisioingStatusCB(clientResponse, DEVICE_NOT_PROVISIONED); cbData(provInfo); + return OC_STACK_DELETE_TRANSACTION; } } @@ -300,7 +305,8 @@ OCStackApplicationResult ProvisionEnrolleeResponse(void* ctx, OCDoHandle handle, -OCStackResult ProvisionEnrollee(OCQualityOfService qos, const char* query, const char* resUri) { +OCStackResult ProvisionEnrollee(OCQualityOfService qos, const char* query, const char* resUri, + OCDevAddr *destination) { OIC_LOG_V(INFO, TAG, "\n\nExecuting ProvisionEnrollee%s", __func__); @@ -312,7 +318,7 @@ OCStackResult ProvisionEnrollee(OCQualityOfService qos, const char* query, const OIC_LOG_V(DEBUG, TAG, "OCPayload ready for ProvisionEnrollee"); - OCStackResult ret = InvokeOCDoResource(query, OC_REST_PUT, OC_HIGH_QOS, + OCStackResult ret = InvokeOCDoResource(query, OC_REST_PUT, destination, OC_HIGH_QOS, ProvisionEnrolleeResponse, payload, NULL, 0); return ret; @@ -355,58 +361,45 @@ OCStackApplicationResult GetProvisioningStatusResponse(void* ctx, char query[OIC_STRING_MAX_VALUE] = { '\0' }; + if(NULL == clientResponse->payload) - if (clientResponse->payload) { - - if(clientResponse->payload && clientResponse->payload->type != PAYLOAD_TYPE_REPRESENTATION) - - { - OIC_LOG_V(DEBUG, TAG, "Incoming payload not a representation"); - return OC_STACK_DELETE_TRANSACTION; - } + { + OIC_LOG_V(DEBUG, TAG, "OCClientResponse is NULL"); - OCRepPayload* input = (OCRepPayload*)(clientResponse->payload); - if(!input) - { - OIC_LOG_V(DEBUG, TAG, "Failed To parse"); - return OC_STACK_DELETE_TRANSACTION; - } - OIC_LOG_V(DEBUG, TAG, "resUri = %s",input->uri); + provInfo = PrepareProvisioingStatusCB(clientResponse, + DEVICE_NOT_PROVISIONED); + cbData(provInfo); - char resURI[MAX_URI_LENGTH]={'\0'}; + return OC_STACK_DELETE_TRANSACTION; + } - strncpy(resURI, input->uri, sizeof(resURI)); + OCRepPayload* repPayload = (OCRepPayload*)clientResponse->payload; - snprintf(query, sizeof(query), UNICAST_PROV_STATUS_QUERY, - clientResponse->addr->addr, - IP_PORT, resURI); + OIC_LOG_V(DEBUG, TAG, "repPayload URI = %s",repPayload->uri); - //OCPayloadLogRep(DEBUG,TAG,input); + snprintf(query, sizeof(query), UNICAST_PROV_STATUS_QUERY, + clientResponse->addr->addr, + IP_PORT, repPayload->uri); - if (ProvisionEnrollee(OC_HIGH_QOS, query, resURI) != OC_STACK_OK) { - OIC_LOG(INFO, TAG, - "GetProvisioningStatusResponse received NULL clientResponse. \ - Invoking Provisioing Status Callback"); - provInfo = PrepareProvisioingStatusCB(clientResponse, - DEVICE_NOT_PROVISIONED); - cbData(provInfo); + //OCPayloadLogRep(DEBUG,TAG,input); - return OC_STACK_DELETE_TRANSACTION; - } - } else { + if (ProvisionEnrollee(OC_HIGH_QOS, query, OC_RSRVD_ES_URI_PROV, + clientResponse->addr) != OC_STACK_OK) { OIC_LOG(INFO, TAG, "GetProvisioningStatusResponse received NULL clientResponse. \ Invoking Provisioing Status Callback"); provInfo = PrepareProvisioingStatusCB(clientResponse, DEVICE_NOT_PROVISIONED); cbData(provInfo); + return OC_STACK_DELETE_TRANSACTION; } + return OC_STACK_DELETE_TRANSACTION; } -OCStackResult InvokeOCDoResource(const char* query, OCMethod method, - OCQualityOfService qos, OCClientResponseHandler cb,OCRepPayload* request, +OCStackResult InvokeOCDoResource(const char* query, OCMethod method, const OCDevAddr *dest, + OCQualityOfService qos, OCClientResponseHandler cb,OCRepPayload* payload, OCHeaderOption * options, uint8_t numOptions) { OCStackResult ret; OCCallbackData cbData; @@ -415,7 +408,7 @@ OCStackResult InvokeOCDoResource(const char* query, OCMethod method, cbData.context = (void*) DEFAULT_CONTEXT_VALUE; cbData.cd = NULL; - ret = OCDoResource(NULL, method, query, 0, &request->base, OC_CONNTYPE, qos, + ret = OCDoResource(NULL, method, query, dest, (OCPayload*)payload, OC_CONNTYPE, qos, &cbData, options, numOptions); if (ret != OC_STACK_OK) { @@ -426,7 +419,9 @@ OCStackResult InvokeOCDoResource(const char* query, OCMethod method, return ret; } -OCStackResult GetProvisioningStatus(OCQualityOfService qos, const char* query) { +OCStackResult GetProvisioningStatus(OCQualityOfService qos, + const char* query, + const OCDevAddr *destination) { OCStackResult ret = OC_STACK_ERROR; OCHeaderOption options[MAX_HEADER_OPTIONS]; @@ -444,8 +439,8 @@ OCStackResult GetProvisioningStatus(OCQualityOfService qos, const char* query) { memcpy(options[1].optionData, option1, sizeof(option1)); options[1].optionLength = 10; - ret = InvokeOCDoResource(query, OC_REST_GET, OC_HIGH_QOS, - GetProvisioningStatusResponse, NULL, options, 2); + ret = InvokeOCDoResource(query, OC_REST_GET, destination, OC_HIGH_QOS, + GetProvisioningStatusResponse, NULL, options, 2); return ret; } @@ -505,13 +500,13 @@ OCStackApplicationResult FindProvisioningResourceResponse(void* ctx, OCDoHandle handle, OCClientResponse * clientResponse) { OIC_LOG(INFO, TAG, PCF("Entering FindProvisioningResourceResponse")); + ProvisioningInfo *provInfo = NULL; OCStackApplicationResult response = OC_STACK_DELETE_TRANSACTION; - ProvisioningInfo *provInfo; - - if (clientResponse->result != OC_STACK_OK) { + if(clientResponse == NULL) + { OIC_LOG(ERROR, TAG, - "OCStack stop error. Calling Provisioing Status Callback"); + "OCClientResponse is NULL"); provInfo = PrepareProvisioingStatusCB(clientResponse, DEVICE_NOT_PROVISIONED); @@ -520,51 +515,38 @@ OCStackApplicationResult FindProvisioningResourceResponse(void* ctx, return response; } - if (clientResponse) { + if (clientResponse->result != OC_STACK_OK || NULL == clientResponse->payload) { + OIC_LOG(ERROR, TAG, + "OCStack stop error. Calling Provisioing Status Callback"); + provInfo = PrepareProvisioingStatusCB(clientResponse, + DEVICE_NOT_PROVISIONED); - if(clientResponse->payload && clientResponse->payload->type != PAYLOAD_TYPE_REPRESENTATION) - { - OIC_LOG_V(DEBUG, TAG, "Incoming payload not a representation"); - return OC_STACK_DELETE_TRANSACTION; - } + cbData(provInfo); + return response; + } - OCRepPayload* discoveryPayload= (OCRepPayload*)(clientResponse->payload); - if(!discoveryPayload) - { - OIC_LOG_V(DEBUG, TAG, "Failed To parse"); - provInfo = PrepareProvisioingStatusCB(clientResponse, - DEVICE_NOT_PROVISIONED); - cbData(provInfo); - return response; - } - OIC_LOG_V(DEBUG, TAG, "resUri = %s",discoveryPayload->uri); - char szQueryUri[64] = { 0 }; + OCDiscoveryPayload* discoveryPayload = (OCDiscoveryPayload*)clientResponse->payload; - snprintf(szQueryUri, sizeof(szQueryUri), UNICAST_PROV_STATUS_QUERY, - clientResponse->devAddr.addr, IP_PORT, discoveryPayload->uri); - OIC_LOG_V(DEBUG, TAG, "query before GetProvisioningStatus call = %s", szQueryUri); + OIC_LOG_V(DEBUG, TAG, "discoveryPayload->resources->uri = %s", + discoveryPayload->resources->uri); + char szQueryUri[64] = { 0 }; - if (GetProvisioningStatus(OC_HIGH_QOS, szQueryUri) != OC_STACK_OK) { - OIC_LOG(INFO, TAG, - "GetProvisioningStatus returned error. \ - Invoking Provisioing Status Callback"); - provInfo = PrepareProvisioingStatusCB(clientResponse, - DEVICE_NOT_PROVISIONED); + snprintf(szQueryUri, sizeof(szQueryUri), UNICAST_PROV_STATUS_QUERY, + clientResponse->devAddr.addr, IP_PORT, discoveryPayload->resources->uri); + OIC_LOG_V(DEBUG, TAG, "query before GetProvisioningStatus call = %s", szQueryUri); - cbData(provInfo); - return OC_STACK_DELETE_TRANSACTION; - } - } else { - // clientResponse is invalid - OIC_LOG(ERROR, TAG, - "Invalid response for Provisioning Discovery request. \ + if (GetProvisioningStatus(OC_HIGH_QOS, szQueryUri, &clientResponse->devAddr) != OC_STACK_OK) { + OIC_LOG(INFO, TAG, + "GetProvisioningStatus returned error. \ Invoking Provisioing Status Callback"); provInfo = PrepareProvisioingStatusCB(clientResponse, DEVICE_NOT_PROVISIONED); + cbData(provInfo); - return response; + return OC_STACK_DELETE_TRANSACTION; } + return OC_STACK_KEEP_TRANSACTION; } @@ -587,7 +569,7 @@ void FindProvisioningResource(void *data) ocCBData.context = (void*) DEFAULT_CONTEXT_VALUE; ocCBData.cd = NULL; - ret = OCDoResource(NULL, OC_REST_GET, szQueryUri, 0, 0, OC_CONNTYPE, + ret = OCDoResource(NULL, OC_REST_DISCOVER, szQueryUri, NULL, NULL, OC_CONNTYPE, OC_LOW_QOS, &ocCBData, NULL, 0); if (ret != OC_STACK_OK) {