Change default vaule of acceptVersion and acceptFormat.
authorZiran Sun <ziran.sun@samsung.com>
Tue, 28 Mar 2017 14:48:07 +0000 (15:48 +0100)
committerZiran Sun <ziran.sun@samsung.com>
Fri, 31 Mar 2017 14:44:59 +0000 (14:44 +0000)
Change the value that was for OIC 1.1 to OCF 1.0.0.

Bug: https://jira.iotivity.org/browse/IOT-1959
Change-Id: Iac714ab5bc410c09f5ca4e20071b9749ce405340
Signed-off-by: Ziran Sun <ziran.sun@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/18263
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
resource/csdk/connectivity/src/camessagehandler.c
resource/csdk/stack/samples/linux/SimpleClientServer/SConscript
resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp
resource/csdk/stack/src/ocstack.c

index daef640..04aac41 100755 (executable)
@@ -1454,6 +1454,10 @@ static void CALogPDUInfo(const CAData_t *data, const coap_pdu_t *pdu)
         {
             OIC_LOG(DEBUG, ANALYZER_TAG, "Payload Format = [CA_FORMAT_APPLICATION_CBOR]");
         }
+        else if (CA_FORMAT_APPLICATION_VND_OCF_CBOR == info->payloadFormat)
+        {
+            OIC_LOG(DEBUG, ANALYZER_TAG, "Payload Format = [CA_FORMAT_APPLICATION_VND_OCF_CBOR]");
+        }
         else
         {
             OIC_LOG_V(DEBUG, ANALYZER_TAG, "Payload Format = [%d]", info->payloadFormat);
index 4b9bfdf..db1119c 100644 (file)
@@ -44,6 +44,7 @@ samples_env.PrependUnique(CPPPATH=[
     '../../../../include',
     '../../../../stack/include',
     '../../../../connectivity/api',
+    '../../../../connectivity/lib/libcoap-4.1.1/include/coap',
     '../../../../security/include',
     '../../../../../../extlibs/boost/boost',
     '../../../../../oc_logger/include',
index 1b39e28..72857f5 100755 (executable)
@@ -34,6 +34,7 @@
 #include <sstream>
 #include <getopt.h>
 #include "ocstack.h"
+#include "pdu.h"
 #include "logger.h"
 #include "occlient.h"
 #include "ocpayload.h"
@@ -402,14 +403,6 @@ OCStackApplicationResult discoveryReqCB(void* ctx, OCDoHandle /*handle*/,
     {
         OIC_LOG_V(INFO, TAG, "StackResult: %s", getResult(clientResponse->result));
 
-        if (OC_STACK_NOT_ACCEPTABLE == clientResponse->result)
-        {
-            // Re-initiate discovery with OIC format. This is applicable for the case that
-            // a OCF 1.x client speaks to a OIC 1.1 server.
-            InitDiscovery(OC_LOW_QOS, 0);
-            return OC_STACK_KEEP_TRANSACTION;
-        }
-
         std::string connectionType = getConnectivityType (clientResponse->connType);
         OIC_LOG_V(INFO, TAG, "Discovered on %s", connectionType.c_str());
         OIC_LOG_V(INFO, TAG,
@@ -880,15 +873,10 @@ int InitDiscovery(OCQualityOfService qos, uint8_t withVendorSpecificHeaderOption
         memset(options, 0, sizeof(OCHeaderOption) * MAX_HEADER_OPTIONS);
         size_t numOptions = 0;
 
-        uint16_t format = COAP_MEDIATYPE_APPLICATION_VND_OCF_CBOR;
+        uint8_t format = COAP_MEDIATYPE_APPLICATION_CBOR;
         uint16_t optionID = CA_OPTION_ACCEPT;
         OCSetHeaderOption(options, &numOptions, optionID, &format, sizeof(format));
 
-        uint16_t version = 2048;
-        optionID = CA_OPTION_ACCEPT_VERSION;
-        numOptions = 1;
-        OCSetHeaderOption(options, &numOptions, optionID, &version, sizeof(version));
-
         ret = OCDoRequest(NULL, OC_REST_DISCOVER, szQueryUri, NULL, 0, CT_DEFAULT,
                               (qos == OC_HIGH_QOS) ? OC_HIGH_QOS : OC_LOW_QOS,
                               &cbData, options, 2);
@@ -1107,7 +1095,7 @@ int main(int argc, char* argv[])
     }
     else
     {
-        InitDiscovery(OC_LOW_QOS, 1);
+        InitDiscovery(OC_LOW_QOS, 0);
     }
 
     // Break from loop with Ctrl+C
index 2b4e55d..c597ce5 100755 (executable)
@@ -612,8 +612,8 @@ static OCStackResult OCSendRequest(const CAEndpoint_t *object, CARequestInfo_t *
     }
 #endif
 
-    uint16_t acceptVersion = 0;
-    CAPayloadFormat_t acceptFormat = CA_FORMAT_APPLICATION_CBOR;
+    uint16_t acceptVersion = OC_SPEC_VERSION_VALUE;
+    CAPayloadFormat_t acceptFormat = CA_FORMAT_APPLICATION_VND_OCF_CBOR;
     // Check settings of version option and content format.
     if (requestInfo->info.numOptions > 0 && requestInfo->info.options)
     {
@@ -645,17 +645,11 @@ static OCStackResult OCSendRequest(const CAEndpoint_t *object, CARequestInfo_t *
     }
 
     requestInfo->info.acceptFormat = acceptFormat;
-    if (CA_FORMAT_APPLICATION_VND_OCF_CBOR == acceptFormat)
+    if (CA_FORMAT_APPLICATION_CBOR == acceptFormat && acceptVersion)
     {
-        if (!acceptVersion)
-        {
-            requestInfo->info.acceptVersion = OC_SPEC_VERSION_VALUE;
-        }
-        else
-        {
-            requestInfo->info.acceptVersion = acceptVersion;
-        }
+        acceptVersion = 0;
     }
+    requestInfo->info.acceptVersion = acceptVersion;
 
     CAResult_t result = CASendRequest(object, requestInfo);
     if (CA_STATUS_OK != result)
@@ -2331,6 +2325,7 @@ void OCHandleRequests(const CAEndpoint_t* endPoint, const CARequestInfo_t* reque
     {
         serverRequest.acceptVersion = requestInfo->info.acceptVersion;
     }
+
     if (requestInfo->info.type == CA_MSG_CONFIRM)
     {
         serverRequest.qos = OC_HIGH_QOS;
@@ -3256,8 +3251,8 @@ OCStackResult OCDoRequest(OCDoHandle *handle,
 
     if (payload)
     {
-        uint16_t payloadVersion = 0;
-        CAPayloadFormat_t payloadFormat = CA_FORMAT_APPLICATION_CBOR;
+        uint16_t payloadVersion = OC_SPEC_VERSION_VALUE;
+        CAPayloadFormat_t payloadFormat = CA_FORMAT_APPLICATION_VND_OCF_CBOR;
         // Check version option settings
         if (numOptions > 0 && options)
         {
@@ -3287,17 +3282,12 @@ OCStackResult OCDoRequest(OCDoHandle *handle,
         }
 
         requestInfo.info.payloadFormat = payloadFormat;
-        if (CA_FORMAT_APPLICATION_VND_OCF_CBOR == payloadFormat)
+        if (CA_FORMAT_APPLICATION_CBOR == payloadFormat && payloadVersion)
         {
-            if (!payloadVersion)
-            {
-                requestInfo.info.payloadVersion = OC_SPEC_VERSION_VALUE;
-            }
-            else
-            {
-                requestInfo.info.payloadVersion = payloadVersion;
-            }
+            payloadVersion = 0;
         }
+        requestInfo.info.payloadVersion = payloadVersion;
+
         if ((result =
             OCConvertPayload(payload, CAToOCPayloadFormat(requestInfo.info.payloadFormat),
                             &requestInfo.info.payload, &requestInfo.info.payloadSize))