Merge "Remove unused openssl-devel dependency" into tizen
authorPyun DoHyun <dh79.pyun@samsung.com>
Thu, 4 Jul 2019 23:19:49 +0000 (23:19 +0000)
committerGerrit Code Review <gerrit@review.ap-northeast-2.compute.internal>
Thu, 4 Jul 2019 23:19:49 +0000 (23:19 +0000)
33 files changed:
extlibs/gtest/SConscript
packaging/iotivity.spec
packaging/snapshot_history.txt
resource/c_common/ocrandom/include/ocrandom.h
resource/c_common/ocrandom/src/ocrandom.c
resource/csdk/connectivity/api/casecurityinterface.h
resource/csdk/connectivity/inc/ca_adapter_net_ssl.h
resource/csdk/connectivity/src/adapter_util/ca_adapter_net_ssl.c
resource/csdk/connectivity/src/cablockwisetransfer.c
resource/csdk/connectivity/src/caconnectivitymanager.c
resource/csdk/connectivity/src/caprotocolmessage.c
resource/csdk/connectivity/src/caqueueingthread.c [changed mode: 0644->0755]
resource/csdk/connectivity/src/tcp_adapter/catcpadapter.c
resource/csdk/connectivity/test/ca_api_unittest.cpp
resource/csdk/security/SConscript
resource/csdk/security/include/srmutility.h
resource/csdk/security/provisioning/sample/SConscript
resource/csdk/security/provisioning/sample/cloud/cloudCommon.c
resource/csdk/security/src/aclresource.c
resource/csdk/security/src/pstatresource.c
resource/csdk/security/src/srmutility.c
resource/csdk/stack/include/internal/ocobserve.h
resource/csdk/stack/include/ocpayload.h
resource/csdk/stack/include/octypes.h
resource/csdk/stack/src/ocobserve.c
resource/csdk/stack/src/ocpayload.c
resource/csdk/stack/src/ocserverrequest.c
resource/csdk/stack/src/ocstack.c
resource/csdk/stack/src/oickeepalive.c
resource/include/OCUtilities.h
resource/src/InProcClientWrapper.cpp
service/notification/src/provider/NSProviderNotification.c
service/notification/src/provider/NSProviderTopic.c

index d127ccf..df306f4 100644 (file)
@@ -6,6 +6,7 @@
 ##
 
 import os
+import shutil
 
 Import('env')
 
@@ -22,7 +23,26 @@ gtest_url = 'http://pkgs.fedoraproject.org/repo/pkgs/gtest/gtest-1.7.0.zip/2d6ec
 
 if target_os in targets_need_gtest:
        print '*** Checking for installation of google unit test 1.7.0 ***'
-       if not os.path.exists(os.path.join(gtest_dir, 'configure')):
+       env_lib_path = env.get('LIBPATH')
+       if gtest_lib_dir in env_lib_path:
+               print '*** Found google unit test, set environments ***'
+               gtest_env.AppendUnique(LIBPATH = [gtest_dotlib_dir])
+               gtest_env.PrependUnique(CPPPATH = [os.path.join(gtest_dir, 'include')])
+               gtest_env.AppendENVPath('LD_LIBRARY_PATH', gtest_dotlib_dir)
+               if 'g++' in gtest_env.get('CXX'):
+                       gtest_env.AppendUnique(CXXFLAGS = ['-std=c++0x'])
+                       gtest_env.AppendUnique(CXXFLAGS = ['-Wall'])
+                       if target_os not in ['android']:
+                               gtest_env.AppendUnique(CXXFLAGS = ['-pthread'])
+                               gtest_env.PrependUnique(LIBS = ['pthread'])
+               gtest_env.PrependUnique(LIBS = ['gtest', 'gtest_main'])
+               if target_os in ['windows']:
+                       gtest_env.AppendUnique(LINKFLAGS = ['/subsystem:CONSOLE'])
+               Return('gtest_env')
+       else:
+               print '*** Prepare to build google unit test 1.7.0 ***'
+               if os.path.exists(gtest_dir):
+                       shutil.rmtree(gtest_dir)
                # If the gtest zip file is not already present, download it
                if not os.path.exists(gtest_zip_file):
                        gtest_zip = gtest_env.Download(gtest_zip_file, gtest_url)
@@ -74,6 +94,7 @@ elif target_os in ['linux']:
                        # Run make on gtest
                        print 'Making google unit test'
                        gtest_env.Configure(gtest_dir, 'make')
+               env.AppendUnique(LIBPATH = [gtest_lib_dir])
 
 elif target_os == 'msys_nt':
        if os.path.exists(gtest_dir):
index 1d21d2d..947b4f5 100644 (file)
@@ -88,7 +88,7 @@ Source1002: %{name}-test.manifest
 %{!?BLE_DIVISION: %define BLE_DIVISION VD}
 %{!?DISABLE_BLE_SERVER: %define DISABLE_BLE_SERVER 0}
 %{!?MULTIPLE_OWNER: %define MULTIPLE_OWNER 1}
-%{!?BLE_TIZEN_40: %define BLE_TIZEN_40 True}
+%{!?BLE_TIZEN_30: %define BLE_TIZEN_30 True}
 
 BuildRequires:  expat-devel
 BuildRequires:  python, libcurl-devel
@@ -183,7 +183,7 @@ scons %{JOB} --prefix=%{_prefix} \
     RD_MODE=%{RD_MODE} \
     BLE_CUSTOM_ADV=%{BLE_CUSTOM_ADV} \
     BLE_DIVISION=%{BLE_DIVISION} \
-    BLE_TIZEN_40=%{BLE_TIZEN_40} \
+    BLE_TIZEN_30=%{BLE_TIZEN_30} \
     DISABLE_BLE_SERVER=%{DISABLE_BLE_SERVER} \
     MULTIPLE_OWNER=%{MULTIPLE_OWNER} \
     LOG_LEVEL=%{log_level} \
index 030f478..fbb81fd 100755 (executable)
@@ -1,3 +1,9 @@
+http://suprem.sec.samsung.net/jira/browse/CONPRO-1456
+
+commit_info_2019-06-27.txt
+
+commit_id: ead7a6d1d2220a5ccbed468dc71c212fc784151e
+---------------------------------------------------------------------------------------------------------------------------------
 http://suprem.sec.samsung.net/jira/browse/CONPRO-1431
 
 commit_info_2019-04-17.txt
index d4af634..a531c70 100644 (file)
@@ -67,6 +67,12 @@ uint32_t OCGetRandom();
 uint8_t OCGetRandomByte(void);
 
 /**
+ * Generate a uniformly [0,2^16] distributed random number
+ * @retval On Success, it returns the random value, otherwise -1 for error.
+ */
+uint16_t OCGetRandomTwoByte(void);
+
+/**
  * Generate a uniformly distributed 8-bit (byte) array random numbers
  * @param[out] location
  *              memory location to start filling with random bytes
index 631906c..1c43edb 100644 (file)
@@ -191,9 +191,23 @@ void OCFillRandomMem(uint8_t * location, uint16_t len)
     {
         return;
     }
-    for (; len--;)
+    uint16_t i, rand_idx;
+    uint8_t *loc;
+    i = len;
+    loc = location;
+    for (; i--;)
     {
-        *location++ = OCGetRandomByte();
+        *loc++ = OCGetRandomByte();
+    }
+    uint8_t temp;
+    i = len;
+    while(i > 1)
+    {
+        rand_idx = lrand48() % i;
+        temp = location[i - 1];
+        location[i - 1] = location[rand_idx];
+        location[rand_idx] = temp;
+        i--;
     }
 }
 
@@ -213,6 +227,16 @@ uint8_t OCGetRandomByte(void)
 #endif
 }
 
+uint16_t OCGetRandomTwoByte(void)
+{
+#ifdef HAVE_SRANDOM
+    return random() & 0x00FFFF;
+#else
+    return rand() & 0x00FFFF;
+#endif
+}
+
+
 uint32_t OCGetRandomRange(uint32_t firstBound, uint32_t secondBound)
 {
     uint32_t base;
index 5e628d4..264bac8 100644 (file)
@@ -119,6 +119,16 @@ typedef int (*CAgetPskCredentialsHandler)(CADtlsPskCredType_t type,
  */
 const CASecureEndpoint_t *CAGetSecureEndpointData(const CAEndpoint_t *peer);
 #endif //MULTIPLE_OWNER
+
+/**
+ * API to set a secure endpoint identity with uuid
+ *
+ * @param[in] peer peer information includs IP address and port
+ * @param[in] uuid UUID of target device
+ *
+ * @return  ::CA_STATUS_OK or appropriate error code
+ */
+CAResult_t CASetSecureEndpointUuid(const CAEndpoint_t *peer, const char *uuid);
 #endif
 
 /**
index 1bfdecc..a7e31bd 100644 (file)
@@ -203,6 +203,16 @@ CAResult_t CAsslGenerateOwnerPsk(const CAEndpoint_t *endpoint,
 const CASecureEndpoint_t *GetCASecureEndpointData(const CAEndpoint_t* peer);
 #endif
 
+/**
+ * Sets CA secure endpoint identity with uuid.
+ *
+ * @param[in]  peer    remote address
+ * @param[in]  uuid    UUID data to set
+ *
+ * @retval  ::CA_STATUS_OK for success, otherwise some error value
+ */
+CAResult_t SetCASecureEndpointUuid(const CAEndpoint_t *peer, const char *uuid);
+
 bool CAIsExistSslPeer(const CAEndpoint_t *peer);
 
 #ifdef __cplusplus
index 47e2199..355b0aa 100644 (file)
@@ -1360,6 +1360,35 @@ const CASecureEndpoint_t *GetCASecureEndpointData(const CAEndpoint_t* peer)
 }
 #endif
 
+CAResult_t SetCASecureEndpointUuid(const CAEndpoint_t *peer, const char *uuid)
+{
+    OIC_LOG_V(DEBUG, NET_SSL_TAG, "In %s", __func__);
+    VERIFY_NON_NULL(peer, NET_SSL_TAG, "peer");
+    VERIFY_NON_NULL(peer, NET_SSL_TAG, "uuid");
+
+    oc_mutex_lock(g_sslContextMutex);
+    SslEndPoint_t *sslPeer = GetSslPeer(peer);
+    if (NULL == sslPeer)
+    {
+        OIC_LOG(ERROR, NET_SSL_TAG, "Peer not found");
+        oc_mutex_unlock(g_sslContextMutex);
+        return CA_STATUS_FAILED;
+    }
+
+    OCRandomUuidResult ret = OCConvertStringToUuid(uuid, sslPeer->sep.identity.id);
+    oc_mutex_unlock(g_sslContextMutex);
+
+    if (RAND_UUID_OK != ret)
+    {
+        OIC_LOG(ERROR, NET_SSL_TAG, "Failed to convert uuid");
+        return CA_STATUS_FAILED;
+    }
+
+    OIC_LOG_V(DEBUG, NET_SSL_TAG, "Out %s", __func__);
+
+    return CA_STATUS_OK;
+}
+
 /**
  * Deletes cached message.
  *
index 10efa2e..0326f19 100755 (executable)
@@ -1120,10 +1120,14 @@ CAResult_t CASetNextBlockOption2(coap_pdu_t *pdu, const CAEndpoint_t *endpoint,
                 OIC_LOG(DEBUG, TAG, "M bit is 0");
                 blockWiseStatus = CA_OPTION2_LAST_BLOCK;
             }
+            else if(CA_BLOCK_RECEIVED_ALREADY == blockWiseStatus)// If already received no need to update block option items.
+            {
+                    OIC_LOG(DEBUG, TAG, "Already Received : M bit is 1");
+                    blockWiseStatus = CA_OPTION2_RESPONSE;
+            }
             else
             {
-                if (CA_BLOCK_UNKNOWN == blockWiseStatus ||
-                        CA_BLOCK_RECEIVED_ALREADY == blockWiseStatus)
+                if (CA_BLOCK_UNKNOWN == blockWiseStatus)
                 {
                     OIC_LOG(DEBUG, TAG, "M bit is 1");
                     blockWiseStatus = CA_OPTION2_RESPONSE;
index bd5df0e..a3e8f41 100755 (executable)
@@ -161,6 +161,20 @@ const CASecureEndpoint_t *CAGetSecureEndpointData(const CAEndpoint_t *peer)
 }
 #endif //MULTIPLE_OWNER
 
+CAResult_t CASetSecureEndpointUuid(const CAEndpoint_t *peer, const char *uuid)
+{
+    OIC_LOG(DEBUG, TAG, "IN CASetSecureEndpointUuid");
+
+    if (!g_isInitialized)
+    {
+        OIC_LOG(DEBUG, TAG, "CA is not initialized");
+        return CA_STATUS_NOT_INITIALIZED;
+    }
+
+    OIC_LOG(DEBUG, TAG, "OUT CASetSecureEndpointUuid");
+    return SetCASecureEndpointUuid(peer, uuid);
+}
+
 CAResult_t CAregisterSslHandshakeCallback(CAErrorCallback tlsHandshakeCallback)
 {
     OIC_LOG(DEBUG, TAG, "CAregisterSslHandshakeCallback");
index ff29b33..0ab1ae7 100755 (executable)
@@ -1058,7 +1058,6 @@ CAResult_t CAGenerateTokenInternal(CAToken_t *token, uint8_t tokenLength)
 
     OIC_LOG_V(DEBUG, TAG, "token len:%d, token:", tokenLength);
     OIC_LOG_BUFFER(DEBUG, TAG, (const uint8_t *)(*token), tokenLength);
-
     return CA_STATUS_OK;
 }
 
old mode 100644 (file)
new mode 100755 (executable)
index 0afeed9..05baf0f
@@ -52,6 +52,12 @@ static void CAQueueingThreadBaseRoutine(void *threadValue)
         return;
     }
 
+    if (NULL == thread->threadMutex || NULL == thread->threadCond || NULL == thread->dataQueue)
+    {
+        OIC_LOG(ERROR, TAG, "thread data was already destroyed");
+        return;
+    }
+
     while (!thread->isStop)
     {
         // mutex lock
index 0e33b46..ea55c74 100644 (file)
@@ -111,7 +111,7 @@ static void CATCPErrorHandler(const CAEndpoint_t *endpoint, const void *data,
 
 static CAResult_t CATCPInitializeQueueHandles();
 
-static void CATCPDeinitializeQueueHandles();
+static void CATCPDeinitializeQueueHandles(CAQueueingThread_t *queueHandle);
 
 static void CATCPSendDataThread(void *threadData);
 
@@ -152,11 +152,10 @@ CAResult_t CATCPInitializeQueueHandles()
     return CA_STATUS_OK;
 }
 
-void CATCPDeinitializeQueueHandles()
+void CATCPDeinitializeQueueHandles(CAQueueingThread_t *queueHandle)
 {
-    CAQueueingThreadDestroy(g_sendQueueHandle);
-    OICFree(g_sendQueueHandle);
-    g_sendQueueHandle = NULL;
+    CAQueueingThreadDestroy(queueHandle);
+    OICFree(queueHandle);
 }
 
 void CATCPConnectionStateCB(const char *ipAddress, CANetworkStatus_t status)
@@ -665,11 +664,18 @@ CAResult_t CAStopTCP()
 
 #ifndef SINGLE_THREAD
     // Stop send queue thread.
-    if (g_sendQueueHandle && g_sendQueueHandle->threadMutex)
+    if (g_sendQueueHandle != NULL)
     {
-        CAQueueingThreadStop(g_sendQueueHandle);
+        // g_sendQueueHandle is set to NULL to prevent new requests from being enqueued.
+        CAQueueingThread_t *queueHandle = g_sendQueueHandle;
+        g_sendQueueHandle = NULL;
+
+        if (queueHandle->threadMutex)
+        {
+            CAQueueingThreadStop(queueHandle);
+        }
+        CATCPDeinitializeQueueHandles(queueHandle);
     }
-    CATCPDeinitializeQueueHandles();
 #endif
 
     // Close TCP servers and established connections.
index 100beac..b2657fb 100644 (file)
@@ -530,6 +530,13 @@ TEST_F(CATests, RegisterDTLSCredentialsHandlerTest)
 #endif
 }
 
+TEST_F(CATests, SetSecureEndpointUuidTestWithNullPeer)
+{
+#ifdef __WITH_DTLS__
+    EXPECT_EQ(CA_STATUS_INVALID_PARAM, CASetSecureEndpointUuid(NULL, NULL));
+#endif
+}
+
 // CARegisterNetworkMonitorHandler TC
 TEST_F(CATests, RegisterNetworkMonitorHandler)
 {
index 964cdd1..613faa4 100644 (file)
@@ -60,7 +60,8 @@ libocsrm_env.PrependUnique(CPPPATH = [
                '../connectivity/api',
                '../security/include',
                '../security/include/internal',
-               '../security/provisioning/include'
+               '../security/provisioning/include',
+               '#resource/csdk/security/provisioning/include/internal'
                ])
 
 if target_os not in ['arduino', 'windows']:
index 3608bbc..22936b7 100644 (file)
@@ -188,6 +188,12 @@ void SetOtmEventHandler(OicSecOtmEventHandler_t otmEventHandler);
 void InvokeOtmEventHandler(const char* addr, uint16_t port,
                            const OicUuid_t* uuid, OicSecOtmEvent_t event);
 #endif
+/**
+ * OicUuid_t to Nil UUID {.id={0000000000000000}}
+ *
+ * @return true if the OicUuid_t is the Nil UUID
+ */
+bool IsNilUuid(const OicUuid_t *uuid);
 
 #ifdef __cplusplus
 }
index bfdfba7..cfde979 100644 (file)
@@ -65,7 +65,7 @@ provisioning_env.AppendUnique(RPATH = [env.get('BUILD_DIR')])
 provisioning_env.AppendUnique(CPPDEFINES = ['__WITH_DTLS__'])
 
 if target_os not in ['windows']:
-       provisioning_env.AppendUnique(CFLAGS = ['-std=c99'])
+       provisioning_env.AppendUnique(CFLAGS = ['-std=gnu99'])
        provisioning_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-pthread', '-fpermissive'])
        provisioning_env.AppendUnique(LIBS = ['pthread'])
 
index d4913b5..1aca476 100644 (file)
@@ -27,6 +27,7 @@
 #include "octhread.h"
 #include "cathreadpool.h"
 #include "ocpayload.h"
+#include "securevirtualresourcetypes.h"
 #include "payload_logging.h"
 #include "aclresource.h"
 #include "crlresource.h"
index f557a09..dc4b874 100644 (file)
@@ -190,6 +190,7 @@ OicSecAce_t* DuplicateACE(const OicSecAce_t* ace)
                 newRsrc->rel = (char*)OICMalloc(sizeof(char) * allocateSize);
                 VERIFY_NON_NULL(TAG, newRsrc->rel, ERROR);
                 OICStrcpy(newRsrc->rel, allocateSize, rsrc->rel);
+                newRsrc->rel[allocateSize - 1] = '\0';
             }
 
             if(rsrc->types && 0 < rsrc->typeLen)
@@ -1128,12 +1129,31 @@ OicSecAcl_t* CBORPayloadToAcl(const uint8_t *cborPayload, const size_t size)
                                                     {
                                                         cbor_value_get_array_length(&rMap, &rsrc->typeLen);
                                                         VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding RT array length.");
+
+                                                        CborValue resourceTypes;
+
+                                                        if (rsrc->typeLen == 0)
+                                                        {
+                                                            cborFindResult = cbor_value_enter_container(&rMap, &resourceTypes);
+                                                            VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Entering RT Array.");
+
+                                                            while (!cbor_value_at_end(&resourceTypes))
+                                                            {
+                                                                rsrc->typeLen++;
+                                                                cborFindResult = cbor_value_advance(&resourceTypes);
+                                                                if (cborFindResult != CborNoError)
+                                                                {
+                                                                    break;
+                                                                }
+                                                            }
+                                                            VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding RT array length.");
+                                                        }
+
                                                         VERIFY_SUCCESS(TAG, (0 != rsrc->typeLen), ERROR);
 
                                                         rsrc->types = (char**)OICCalloc(rsrc->typeLen, sizeof(char*));
                                                         VERIFY_NON_NULL(TAG, rsrc->types, ERROR);
 
-                                                        CborValue resourceTypes;
                                                         cborFindResult = cbor_value_enter_container(&rMap, &resourceTypes);
                                                         VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Entering RT Array.");
 
@@ -1151,12 +1171,31 @@ OicSecAcl_t* CBORPayloadToAcl(const uint8_t *cborPayload, const size_t size)
                                                     {
                                                         cbor_value_get_array_length(&rMap, &rsrc->interfaceLen);
                                                         VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding IF array length.");
+
+                                                        CborValue interfaces;
+
+                                                        if (rsrc->interfaceLen == 0)
+                                                        {
+                                                            cborFindResult = cbor_value_enter_container(&rMap, &interfaces);
+                                                            VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Entering IF Array.");
+
+                                                            while (!cbor_value_at_end(&interfaces))
+                                                            {
+                                                                rsrc->interfaceLen++;
+                                                                cborFindResult = cbor_value_advance(&interfaces);
+                                                                if (cborFindResult != CborNoError)
+                                                                {
+                                                                    break;
+                                                                }
+                                                            }
+                                                            VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding IF array length.");
+                                                        }
+
                                                         VERIFY_SUCCESS(TAG, (0 != rsrc->interfaceLen), ERROR);
 
                                                         rsrc->interfaces = (char**)OICCalloc(rsrc->interfaceLen, sizeof(char*));
                                                         VERIFY_NON_NULL(TAG, rsrc->interfaces, ERROR);
 
-                                                        CborValue interfaces;
                                                         cborFindResult = cbor_value_enter_container(&rMap, &interfaces);
                                                         VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Entering IF Array.");
 
index 4a4c107..92e7579 100644 (file)
@@ -32,6 +32,9 @@
 #include "psinterface.h"
 #include "srmresourcestrings.h"
 #include "srmutility.h"
+#include "aclresource.h"
+#include "credresource.h"
+#include "ocprovisioningmanager.h"
 
 #define TAG  "OIC_SRM_PSTAT"
 
@@ -533,6 +536,86 @@ static OCEntityHandlerResult HandlePstatGetRequest (const OCEntityHandlerRequest
 }
 
 /**
+ * Checks if device can change state to Ready for Normal Operation.
+ */
+static OCEntityHandlerResult ValidateReadyForNOP(const OicSecPstat_t *pstat)
+{
+    OIC_LOG_V(DEBUG, TAG, "%s: IN", __func__);
+
+    const OicSecDoxm_t *doxm = GetDoxmResourceData();
+    OicUuid_t rowneruuid;
+
+    if (!doxm)
+    {
+        OIC_LOG(WARNING, TAG, "DOXM is NULL");
+        return OC_EH_NOT_ACCEPTABLE;
+    }
+
+    if (!doxm->owned)
+    {
+        OIC_LOG(WARNING, TAG, "Can't change state to Ready for Normal Operation: the device is unowned");
+        return OC_EH_NOT_ACCEPTABLE;
+    }
+
+    if (IsNilUuid(&doxm->owner))
+    {
+        OIC_LOG(WARNING, TAG, "Can't change state to Ready for Normal Operation: the device owner is NIL");
+        return OC_EH_INTERNAL_SERVER_ERROR;
+    }
+
+    if (IsNilUuid(&doxm->deviceID))
+    {
+        OIC_LOG(WARNING, TAG,
+                "Can't change state to Ready for Normal Operation: the device owner ID is NIL");
+        return OC_EH_INTERNAL_SERVER_ERROR;
+    }
+
+    if (IsNilUuid(&doxm->rownerID))
+    {
+        OIC_LOG(WARNING, TAG, "Can't change state to Ready for Normal Operation: the doxm rowner is NIL");
+        return OC_EH_INTERNAL_SERVER_ERROR;
+    }
+
+
+    if (IsNilUuid(&pstat->rownerID))
+    {
+        OIC_LOG(WARNING, TAG, "Can't change state to Ready for Normal Operation: the pstat rowner is NIL");
+        return OC_EH_INTERNAL_SERVER_ERROR;
+    }
+
+    memset(&rowneruuid, 0, sizeof(OicUuid_t));
+    if (OC_STACK_OK != GetAclRownerId(&rowneruuid))
+    {
+        OIC_LOG(WARNING, TAG, "Can't change state to Ready for Normal Operation: can't get acl");
+        return OC_EH_INTERNAL_SERVER_ERROR;
+    }
+
+    if (IsNilUuid(&rowneruuid))
+    {
+        OIC_LOG(WARNING, TAG, "Can't change state to Ready for Normal Operation: the acl rowner is NIL");
+        return OC_EH_INTERNAL_SERVER_ERROR;
+    }
+
+    memset(&rowneruuid, 0, sizeof(OicUuid_t));
+    if (OC_STACK_OK != GetCredRownerId(&rowneruuid))
+    {
+        OIC_LOG(WARNING, TAG, "Can't change state to Ready for Normal Operation: can't get cred");
+        return OC_EH_INTERNAL_SERVER_ERROR;
+    }
+
+    if (IsNilUuid(&rowneruuid))
+    {
+        OIC_LOG(WARNING, TAG, "Can't change state to Ready for Normal Operation: the cred rowner is NIL");
+        return OC_EH_INTERNAL_SERVER_ERROR;
+    }
+
+    OIC_LOG_V(DEBUG, TAG, "%s: OUT", __func__);
+
+    return OC_EH_OK;
+
+}
+
+/**
  * The entity handler determines how to process a POST request.
  * Per the REST paradigm, POST can also be used to update representation of existing
  * resource or create a new resource.
@@ -615,6 +698,11 @@ static OCEntityHandlerResult HandlePstatPostRequest(OCEntityHandlerRequest *ehRe
                 }
                 else if (false == (pstat->cm & TAKE_OWNER) && true == pstat->isOp)
                 {
+                    ehRet = ValidateReadyForNOP(pstat);
+                    if(OC_EH_OK != ehRet)
+                    {
+                        goto exit;
+                    }
                     validReq = true;
                     OIC_LOG (INFO, TAG, "State changed to Ready for Normal Operation");
                 }
@@ -674,27 +762,25 @@ static OCEntityHandlerResult HandlePstatPostRequest(OCEntityHandlerRequest *ehRe
            * ownership transfer related resource should be revert back to initial status.
            */
          const OicSecDoxm_t* doxm = GetDoxmResourceData();
-         if(doxm)
+         if(doxm && !doxm->owned)
          {
-             if(!doxm->owned)
-             {
-                OIC_LOG(WARNING, TAG, "The operation failed during handle DOXM request");
+            OIC_LOG(WARNING, TAG, "The operation failed during handle DOXM request");
 
-                if (!isDuplicatedMsg)
-                {
+            if (!isDuplicatedMsg)
+            {
 #if defined (__WITH_TLS__) || defined(__WITH_DTLS__)
-                    InvokeOtmEventHandler(ehRequest->devAddr.addr, ehRequest->devAddr.port,
+                InvokeOtmEventHandler(ehRequest->devAddr.addr, ehRequest->devAddr.port,
                                           NULL, OIC_OTM_ERROR);
 #endif
-                    RestoreDoxmToInitState();
-                    RestorePstatToInitState();
-                    OIC_LOG(WARNING, TAG, "DOXM will be reverted.");
-                }
-             }
+                RestoreDoxmToInitState();
+                RestorePstatToInitState();
+                OIC_LOG(WARNING, TAG, "DOXM will be reverted.");
+            }
          }
          else
          {
              OIC_LOG(ERROR, TAG, "Invalid DOXM resource.");
+             ResetSecureResourceInPS();
          }
      }
      else
index e54095d..80b836f 100644 (file)
@@ -378,4 +378,47 @@ exit:
     }
     OIC_LOG_V(DEBUG, TAG, "Out %s", __func__);
 }
+
+const OicUuid_t THE_NIL_UUID = {.id={0000000000000000}};
+
+/**
+ * Compares two OicUuid_t structs.
+ *
+ * @return true if the two OicUuid_t structs are equal, else false.
+ */
+bool UuidCmp(const OicUuid_t *firstId, const OicUuid_t *secondId)
+{
+    bool ret = false;
+    VERIFY_NON_NULL(TAG, firstId, ERROR);
+    VERIFY_NON_NULL(TAG, secondId, ERROR);
+
+    if (0 == memcmp(firstId, secondId, sizeof(OicUuid_t)))
+    {
+        ret = true;
+    }
+
+exit:
+    OIC_LOG_V(DEBUG, TAG, "%s: returning %s.", __func__, ret?"true":"false");
+    return ret;
+}
+
+/**
+ * Compares OicUuid_t to Nil UUID {.id={0000000000000000}}
+ *
+ * @return true if the OicUuid_t is the Nil UUID.
+ */
+bool IsNilUuid(const OicUuid_t *uuid)
+{
+#if !defined(NDEBUG)
+    char *strUuid = NULL;
+    ConvertUuidToStr(uuid, &strUuid);
+    if (strUuid)
+    {
+        OIC_LOG_V(DEBUG, TAG, "%s: uuid: %s.", __func__, strUuid);
+        OICFree(strUuid);
+    }
+#endif
+    return UuidCmp(uuid, &THE_NIL_UUID);
+}
+
 #endif
index f5fc6c1..018ee7c 100644 (file)
@@ -150,7 +150,7 @@ OCStackResult SendAllObserverNotification (OCMethod method, OCResource *resPtr,
  * @return ::OC_STACK_OK on success, some other value upon failure.
  */
 OCStackResult SendListObserverNotification (OCResource * resource,
-        OCObservationId  *obsIdList, uint8_t numberOfIds,
+        OCObservationId  *obsIdList, uint16_t numberOfIds,
         const OCRepPayload *payload, uint32_t maxAge,
         OCQualityOfService qos);
 
index fc11afa..763a107 100644 (file)
 #include <inttypes.h>
 #include "octypes.h"
 
-#if defined(__WITH_TLS__) || defined(__WITH_DTLS__)
-#include "securevirtualresourcetypes.h"
-#endif
-
 #ifdef __cplusplus
 extern "C"
 {
@@ -65,6 +61,10 @@ extern "C"
 
 typedef struct OCResource OCResource;
 
+#if defined(__WITH_TLS__) || defined(__WITH_DTLS__)
+typedef struct OicSecKey OicSecKey_t;
+#endif
+
 void OCPayloadDestroy(OCPayload* payload);
 
 // Representation Payload
index a7e6dbf..8187b88 100644 (file)
@@ -1063,9 +1063,9 @@ typedef uint32_t OCRequestHandle;
  * Unique identifier for each observation request. Used when observations are
  * registered or de-registered. Used by entity handler to signal specific
  * observers to be notified of resource changes.
- * There can be maximum of 256 observations per server.
+ * There can be maximum of 3840 observations per server.
  */
-typedef uint8_t OCObservationId;
+typedef uint16_t OCObservationId;
 
 /**
  * Sequence number is a 24 bit field,
index 18de8c6..7495f2b 100644 (file)
 
 #define VERIFY_NON_NULL(arg) { if (!arg) {OIC_LOG(FATAL, TAG, #arg " is NULL"); goto exit;} }
 
+#define MAX_OBSERVERS 3840
+
 static struct ResourceObserver * g_serverObsList = NULL;
 static oc_mutex g_serverObsListMutex = NULL;
 
+static int observer_count = 0;
+
 static ResourceObserver* GetObserverUsingIdAsOwner (const OCObservationId observeId);
 
 static ResourceObserver* CloneObserverNode (ResourceObserver* observer)
@@ -255,7 +259,7 @@ OCStackResult SendAllObserverNotification (OCMethod method, OCResource *resPtr,
 
     OCStackResult result = OC_STACK_ERROR;
     ResourceObserver * resourceObserver = NULL;
-    uint8_t numObs = 0;
+    uint16_t numObs = 0;
     OCServerRequest * request = NULL;
     bool observeErrorFlag = false;
 
@@ -347,7 +351,7 @@ OCStackResult SendAllObserverNotification (OCMethod method, OCResource *resPtr,
 }
 
 OCStackResult SendListObserverNotification (OCResource * resource,
-        OCObservationId  *obsIdList, uint8_t numberOfIds,
+        OCObservationId  *obsIdList, uint16_t numberOfIds,
         const OCRepPayload *payload,
         uint32_t maxAge,
         OCQualityOfService qos)
@@ -358,9 +362,9 @@ OCStackResult SendListObserverNotification (OCResource * resource,
         return OC_STACK_INVALID_PARAM;
     }
 
-    uint8_t numIds = numberOfIds;
+    uint16_t numIds = numberOfIds;
     ResourceObserver *observer = NULL;
-    uint8_t numSentNotification = 0;
+    uint16_t numSentNotification = 0;
     OCServerRequest * request = NULL;
     OCStackResult result = OC_STACK_ERROR;
     bool observeErrorFlag = false;
@@ -464,19 +468,32 @@ OCStackResult GenerateObserverId (OCObservationId *observationId)
     OIC_LOG(INFO, TAG, "Entering GenerateObserverId");
     VERIFY_NON_NULL (observationId);
 
-    do
+    oc_mutex_lock(g_serverObsListMutex);
+
+    if (observer_count < MAX_OBSERVERS)
     {
+        oc_mutex_unlock(g_serverObsListMutex);
         do
         {
-            *observationId = OCGetRandomByte();
-        } while (0 == *observationId); //Make sure *observationId is not 0
-        // Check if observation Id already exists
-        found = IsObserverAvailable (*observationId);
-    } while (found);
-
+            do
+            {
+                *observationId = OCGetRandomTwoByte();
+            } while (0 == *observationId); //Make sure *observationId is not 0
+            // Check if observation Id already exists
+            found = IsObserverAvailable (*observationId);
+        } while (found);
     OIC_LOG_V(INFO, TAG, "GeneratedObservation ID is %u", *observationId);
+    //oc_mutex_unlock(g_serverObsListMutex);
 
     return OC_STACK_OK;
+    }
+    else
+    {
+        OIC_LOG_V(ERROR, TAG, "No more observers can be added");
+        oc_mutex_unlock(g_serverObsListMutex);
+
+        return OC_STACK_ERROR;
+    }
 exit:
     return OC_STACK_ERROR;
 }
@@ -547,6 +564,7 @@ OCStackResult AddObserver (const char         *resUri,
 
         oc_mutex_lock(g_serverObsListMutex);
         LL_APPEND (g_serverObsList, obsNode);
+        observer_count++;
         oc_mutex_unlock(g_serverObsListMutex);
 
         return OC_STACK_OK;
@@ -728,6 +746,7 @@ OCStackResult DeleteObserverUsingToken (CAToken_t token, uint8_t tokenLength)
         OIC_LOG_BUFFER(INFO, TAG, (const uint8_t *)obsNode->token, tokenLength);
 
         LL_DELETE (g_serverObsList, obsNode);
+        observer_count--;
         FreeObserver(obsNode);
     }
     oc_mutex_unlock(g_serverObsListMutex);
index 95b9440..e31454f 100755 (executable)
 #include "ocresource.h"
 #include "logger.h"
 
+#if defined(__WITH_TLS__) || defined(__WITH_DTLS__)
+#include "securevirtualresourcetypes.h"
+#endif
+
 #define TAG "OIC_RI_PAYLOAD"
 #define CSV_SEPARATOR ','
 
index 3dde884..aa5930b 100644 (file)
@@ -100,6 +100,7 @@ static void DeleteServerRequest(OCServerRequest * serverRequest)
 {
     if(serverRequest)
     {
+        OIC_LOG_V(WARNING, TAG, "Server request ID = [%u]", serverRequest->requestId);
         LL_DELETE(serverRequestList, serverRequest);
         OICFree(serverRequest->requestToken);
         OICFree(serverRequest->rcvdVendorSpecificHeaderOptions);
@@ -300,6 +301,12 @@ OCStackResult AddServerRequest (OCServerRequest ** request, uint16_t coapID,
     serverRequest->numResponses = 1;
     serverRequest->requestId = OCGetRandom();
 
+    // checking same id exist
+    while(serverRequest->requestId == 0 || GetServerRequestUsingHandle(serverRequest->requestId) != NULL)
+    {
+        serverRequest->requestId = OCGetRandom();
+    }
+
     if(query)
     {
         OICStrcpy(serverRequest->query, sizeof(serverRequest->query), query);
index 63eef55..240920f 100644 (file)
@@ -61,6 +61,7 @@
 #include "ocpayload.h"
 #include "ocpayloadcbor.h"
 #include "cautilinterface.h"
+#include "camessagehandler.h"
 #include "oicgroup.h"
 
 #if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
@@ -2014,10 +2015,13 @@ OCStackResult HandleStackRequests(OCServerProtocolRequest * protocolRequest)
         {
             request->requestComplete = 1;
         }
+
+        OIC_LOG_V(WARNING, TAG, "Server request ID = [%u]", request->requestId);
     }
     else
     {
         OIC_LOG(INFO, TAG, "This is either a repeated or blocked Server Request");
+        return OC_STACK_DUPLICATE_REQUEST;
     }
 
     if(request->requestComplete)
index 451d9dc..bd01d08 100755 (executable)
@@ -644,8 +644,13 @@ void OCProcessKeepAlive()
                     {
                         OIC_LOG(DEBUG, TAG, "Client does not receive the response within 1 minutes.");
 
-                        // Send message to disconnect session.
-                        OCSendDisconnectMessage(entry);
+                        /* TCPDisconnectSession should be invoked depending on the result from client callback */
+                        if (OCSendDisconnectMessage(entry) == OC_STACK_CONTINUE)
+                        {
+                            // Set sentPingMsg values with false.
+                            entry->sentPingMsg = false;
+                            entry->handle = NULL;
+                        }
                     }
 #ifdef WITH_PROCESS_EVENT
                     else
@@ -714,7 +719,12 @@ OCStackResult OCSendDisconnectMessage(const KeepAliveEntry_t *entry)
         response.resourceUri = cbNode->requestUri;
         response.result = OC_STACK_TIMEOUT;
 
-        cbNode->callBack(cbNode->context, cbNode->handle, &response);
+        /* TCPDisconnectSession should be invoked depending on the result from client callback */
+        if (cbNode->callBack(cbNode->context, cbNode->handle, &response) == OC_STACK_KEEP_TRANSACTION)
+        {
+            return OC_STACK_CONTINUE;
+        }
+
         FindAndDeleteClientCB(cbNode);
     }
 
index 85039d0..2339be2 100644 (file)
@@ -21,6 +21,7 @@
 #ifndef OC_UTILITIES_H_
 #define OC_UTILITIES_H_
 
+#include <functional>
 #include <map>
 #include <vector>
 #include <memory>
index 0dfc3b6..132d082 100755 (executable)
@@ -98,30 +98,29 @@ namespace OC
     {
         OIC_LOG(INFO, TAG, "stop ocplatform");
 
-        if (m_threadRun && m_listeningThread.joinable())
+        // only stop if we are the ones who actually called 'start'.  We are counting
+        // on the server to do the stop.
+        if (m_cfg.mode == ModeType::Client)
         {
-            m_threadRun = false;
-#ifdef WITH_PROCESS_EVENT
-            if (m_processEvent)
+            if (m_threadRun && m_listeningThread.joinable())
             {
-                oc_event_signal(m_processEvent);
-            }
+                m_threadRun = false;
+#ifdef WITH_PROCESS_EVENT
+                if (m_processEvent)
+                {
+                    oc_event_signal(m_processEvent);
+                }
 #endif
-            m_listeningThread.join();
-        }
+                m_listeningThread.join();
+            }
 
 #ifdef WITH_PROCESS_EVENT
-        if (m_processEvent)
-        {
-            oc_event_free(m_processEvent);
-            m_processEvent = NULL;
-        }
+            if (m_processEvent)
+            {
+                oc_event_free(m_processEvent);
+                m_processEvent = NULL;
+            }
 #endif
-
-        // only stop if we are the ones who actually called 'start'.  We are counting
-        // on the server to do the stop.
-        if (m_cfg.mode == ModeType::Client)
-        {
             OCStackResult result = OCStop();
 
             if (OC_STACK_OK != result)
index 0119116..74708df 100644 (file)
@@ -108,7 +108,7 @@ NSResult NSSendNotification(NSMessage *msg)
     NS_LOG(DEBUG, "NSSendMessage - IN");
 
     OCResourceHandle rHandle;
-    OCObservationId obArray[255] = { 0, };
+    OCObservationId obArray[3839] = { 0, };
     int obCount = 0, i;
 
     if (NSPutMessageResource(msg, &rHandle) != NS_OK)
@@ -232,7 +232,7 @@ NSResult NSSendSync(NSSyncInfo *sync)
 {
     NS_LOG(DEBUG, "NSSendSync - IN");
 
-    OCObservationId obArray[255] = { 0, };
+    OCObservationId obArray[3839] = { 0, };
     int obCount = 0;
     int i;
 
index f6aa8e9..9a6dee9 100644 (file)
@@ -143,7 +143,7 @@ NSResult NSSendTopicUpdation()
     OCRepPayloadSetPropInt(payload, NS_ATTRIBUTE_MESSAGE_ID, NS_TOPIC);
     OCRepPayloadSetPropString(payload, NS_ATTRIBUTE_PROVIDER_ID, NSGetProviderInfo()->providerId);
 
-    OCObservationId obArray[255] =
+    OCObservationId obArray[3839] =
     { 0, };
     int obCount = 0;