From a7b8bf18e871a2576fc6b2ee872f6f7e7082781b Mon Sep 17 00:00:00 2001 From: "js126.lee" Date: Tue, 7 Jun 2016 20:44:19 +0900 Subject: [PATCH] Changing DOXM resource to be normally discoverable Issue: DOXM is not listed by default in /oic/res response. Resolve : Changeg DOXM to be normally discoverable PT should use secure port of DOXM for OTM and Provision, even if Device has different COAPS ports per resource. Patch 1: Init Patch 2: According to review of Randeep, modified form strcmp to strncmp Change-Id: I7742681b75261694c809e98f639379332c77e3b5 Signed-off-by: js126.lee Reviewed-on: https://gerrit.iotivity.org/gerrit/8527 Tested-by: jenkins-iotivity Reviewed-by: Randeep Singh --- .../csdk/security/provisioning/src/pmutility.c | 30 ++++++++++++++-------- resource/csdk/security/src/doxmresource.c | 2 +- .../samples/linux/secure/occlientbasicops.cpp | 10 ++++++-- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/resource/csdk/security/provisioning/src/pmutility.c b/resource/csdk/security/provisioning/src/pmutility.c index 38d1377..e36c166 100644 --- a/resource/csdk/security/provisioning/src/pmutility.c +++ b/resource/csdk/security/provisioning/src/pmutility.c @@ -584,6 +584,25 @@ static OCStackApplicationResult SecurePortDiscoveryHandler(void *ctx, OCDoHandle uint16_t securePort = 0; OCResourcePayload* resPayload = ((OCDiscoveryPayload*)clientResponse->payload)->resources; + // Use seure port of doxm for OTM and Provision. + while (resPayload) + { + if (0 == strncmp(resPayload->uri, OIC_RSRC_DOXM_URI, sizeof(OIC_RSRC_DOXM_URI))) + { + OIC_LOG_V(INFO,TAG,"resPaylod->uri:%s",resPayload->uri); + OIC_LOG(INFO, TAG, "Found doxm resource."); + break; + } + else + { + resPayload = resPayload->next; + } + } + if (NULL == resPayload) + { + OIC_LOG(ERROR, TAG, "Can not find doxm resource."); + return OC_STACK_DELETE_TRANSACTION; + } if (resPayload && resPayload->secure) { securePort = resPayload->port; @@ -810,21 +829,12 @@ static OCStackResult SecurePortDiscovery(DiscoveryInfo* discoveryInfo, { return OC_STACK_INVALID_PARAM; } - - char rsrc_uri[MAX_URI_LENGTH+1] = {0}; - int wr_len = snprintf(rsrc_uri, sizeof(rsrc_uri), "%s?%s=%s", - OC_RSRVD_WELL_KNOWN_URI, OC_RSRVD_RESOURCE_TYPE, OIC_RSRC_TYPE_SEC_DOXM); - if(wr_len <= 0 || (size_t)wr_len >= sizeof(rsrc_uri)) - { - OIC_LOG(ERROR, TAG, "rsrc_uri_string_print failed"); - return OC_STACK_ERROR; - } //Try to the unicast discovery to getting secure port char query[MAX_URI_LENGTH+MAX_QUERY_LENGTH+1] = {0}; if(!PMGenerateQuery(false, clientResponse->devAddr.addr, clientResponse->devAddr.port, clientResponse->connType, - query, sizeof(query), rsrc_uri)) + query, sizeof(query), OC_RSRVD_WELL_KNOWN_URI)) { OIC_LOG(ERROR, TAG, "SecurePortDiscovery : Failed to generate query"); return OC_STACK_ERROR; diff --git a/resource/csdk/security/src/doxmresource.c b/resource/csdk/security/src/doxmresource.c index 6cfbc4b..ccdfbc8 100644 --- a/resource/csdk/security/src/doxmresource.c +++ b/resource/csdk/security/src/doxmresource.c @@ -868,7 +868,7 @@ OCStackResult CreateDoxmResource() DoxmEntityHandler, NULL, OC_OBSERVABLE | OC_SECURE | - OC_EXPLICIT_DISCOVERABLE); + OC_DISCOVERABLE); if (OC_STACK_OK != ret) { diff --git a/resource/csdk/stack/samples/linux/secure/occlientbasicops.cpp b/resource/csdk/stack/samples/linux/secure/occlientbasicops.cpp index f531773..1e7421d 100644 --- a/resource/csdk/stack/samples/linux/secure/occlientbasicops.cpp +++ b/resource/csdk/stack/samples/linux/secure/occlientbasicops.cpp @@ -52,7 +52,7 @@ static OCConnectivityType ocConnType; //of other devices which the client trusts static char CRED_FILE_DEVOWNER[] = "oic_svr_db_client_devowner.dat"; static char CRED_FILE_NONDEVOWNER[] = "oic_svr_db_client_nondevowner.dat"; - +const char * OIC_RSRC_DOXM_URI = "/oic/sec/doxm"; int gQuitFlag = 0; @@ -417,9 +417,15 @@ int parseClientResponse(OCClientResponse * clientResponse) { coapServerResource.assign(res->uri); OIC_LOG_V(INFO, TAG, "Uri -- %s", coapServerResource.c_str()); - + if (0 == strcmp(coapServerResource.c_str(),OIC_RSRC_DOXM_URI)) + { + OIC_LOG(INFO,TAG,"Skip: doxm is secure virtual resource"); + res = res->next; + continue; + } if (res->secure) { + OIC_LOG_V(INFO,TAG,"SECUREPORT: %d",res->port); endpoint.port = res->port; coapSecureResource = 1; } -- 2.7.4