From: Pyun DoHyun Date: Thu, 4 Jul 2019 23:19:49 +0000 (+0000) Subject: Merge "Remove unused openssl-devel dependency" into tizen X-Git-Tag: accepted/tizen/unified/20190816.112424~19 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=03ae7cd73e2e10a8de75da40a0e476cc955b46b2;hp=0afa8c3f7cf361f56b47702ddea0dc5303f546f9;p=platform%2Fupstream%2Fiotivity.git Merge "Remove unused openssl-devel dependency" into tizen --- diff --git a/extlibs/gtest/SConscript b/extlibs/gtest/SConscript index d127ccf..df306f4 100644 --- a/extlibs/gtest/SConscript +++ b/extlibs/gtest/SConscript @@ -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): diff --git a/packaging/iotivity.spec b/packaging/iotivity.spec index 1d21d2d..947b4f5 100644 --- a/packaging/iotivity.spec +++ b/packaging/iotivity.spec @@ -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} \ diff --git a/packaging/snapshot_history.txt b/packaging/snapshot_history.txt index 030f478..fbb81fd 100755 --- a/packaging/snapshot_history.txt +++ b/packaging/snapshot_history.txt @@ -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 diff --git a/resource/c_common/ocrandom/include/ocrandom.h b/resource/c_common/ocrandom/include/ocrandom.h index d4af634..a531c70 100644 --- a/resource/c_common/ocrandom/include/ocrandom.h +++ b/resource/c_common/ocrandom/include/ocrandom.h @@ -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 diff --git a/resource/c_common/ocrandom/src/ocrandom.c b/resource/c_common/ocrandom/src/ocrandom.c index 631906c..1c43edb 100644 --- a/resource/c_common/ocrandom/src/ocrandom.c +++ b/resource/c_common/ocrandom/src/ocrandom.c @@ -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; diff --git a/resource/csdk/connectivity/api/casecurityinterface.h b/resource/csdk/connectivity/api/casecurityinterface.h index 5e628d4..264bac8 100644 --- a/resource/csdk/connectivity/api/casecurityinterface.h +++ b/resource/csdk/connectivity/api/casecurityinterface.h @@ -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 /** diff --git a/resource/csdk/connectivity/inc/ca_adapter_net_ssl.h b/resource/csdk/connectivity/inc/ca_adapter_net_ssl.h index 1bfdecc..a7e31bd 100644 --- a/resource/csdk/connectivity/inc/ca_adapter_net_ssl.h +++ b/resource/csdk/connectivity/inc/ca_adapter_net_ssl.h @@ -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 diff --git a/resource/csdk/connectivity/src/adapter_util/ca_adapter_net_ssl.c b/resource/csdk/connectivity/src/adapter_util/ca_adapter_net_ssl.c index 47e2199..355b0aa 100644 --- a/resource/csdk/connectivity/src/adapter_util/ca_adapter_net_ssl.c +++ b/resource/csdk/connectivity/src/adapter_util/ca_adapter_net_ssl.c @@ -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. * diff --git a/resource/csdk/connectivity/src/cablockwisetransfer.c b/resource/csdk/connectivity/src/cablockwisetransfer.c index 10efa2e..0326f19 100755 --- a/resource/csdk/connectivity/src/cablockwisetransfer.c +++ b/resource/csdk/connectivity/src/cablockwisetransfer.c @@ -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; diff --git a/resource/csdk/connectivity/src/caconnectivitymanager.c b/resource/csdk/connectivity/src/caconnectivitymanager.c index bd5df0e..a3e8f41 100755 --- a/resource/csdk/connectivity/src/caconnectivitymanager.c +++ b/resource/csdk/connectivity/src/caconnectivitymanager.c @@ -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"); diff --git a/resource/csdk/connectivity/src/caprotocolmessage.c b/resource/csdk/connectivity/src/caprotocolmessage.c index ff29b33..0ab1ae7 100755 --- a/resource/csdk/connectivity/src/caprotocolmessage.c +++ b/resource/csdk/connectivity/src/caprotocolmessage.c @@ -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; } diff --git a/resource/csdk/connectivity/src/caqueueingthread.c b/resource/csdk/connectivity/src/caqueueingthread.c old mode 100644 new mode 100755 index 0afeed9..05baf0f --- a/resource/csdk/connectivity/src/caqueueingthread.c +++ b/resource/csdk/connectivity/src/caqueueingthread.c @@ -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 diff --git a/resource/csdk/connectivity/src/tcp_adapter/catcpadapter.c b/resource/csdk/connectivity/src/tcp_adapter/catcpadapter.c index 0e33b46..ea55c74 100644 --- a/resource/csdk/connectivity/src/tcp_adapter/catcpadapter.c +++ b/resource/csdk/connectivity/src/tcp_adapter/catcpadapter.c @@ -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. diff --git a/resource/csdk/connectivity/test/ca_api_unittest.cpp b/resource/csdk/connectivity/test/ca_api_unittest.cpp index 100beac..b2657fb 100644 --- a/resource/csdk/connectivity/test/ca_api_unittest.cpp +++ b/resource/csdk/connectivity/test/ca_api_unittest.cpp @@ -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) { diff --git a/resource/csdk/security/SConscript b/resource/csdk/security/SConscript index 964cdd1..613faa4 100644 --- a/resource/csdk/security/SConscript +++ b/resource/csdk/security/SConscript @@ -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']: diff --git a/resource/csdk/security/include/srmutility.h b/resource/csdk/security/include/srmutility.h index 3608bbc..22936b7 100644 --- a/resource/csdk/security/include/srmutility.h +++ b/resource/csdk/security/include/srmutility.h @@ -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 } diff --git a/resource/csdk/security/provisioning/sample/SConscript b/resource/csdk/security/provisioning/sample/SConscript index bfdfba7..cfde979 100644 --- a/resource/csdk/security/provisioning/sample/SConscript +++ b/resource/csdk/security/provisioning/sample/SConscript @@ -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']) diff --git a/resource/csdk/security/provisioning/sample/cloud/cloudCommon.c b/resource/csdk/security/provisioning/sample/cloud/cloudCommon.c index d4913b5..1aca476 100644 --- a/resource/csdk/security/provisioning/sample/cloud/cloudCommon.c +++ b/resource/csdk/security/provisioning/sample/cloud/cloudCommon.c @@ -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" diff --git a/resource/csdk/security/src/aclresource.c b/resource/csdk/security/src/aclresource.c index f557a09..dc4b874 100644 --- a/resource/csdk/security/src/aclresource.c +++ b/resource/csdk/security/src/aclresource.c @@ -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."); diff --git a/resource/csdk/security/src/pstatresource.c b/resource/csdk/security/src/pstatresource.c index 4a4c107..92e7579 100644 --- a/resource/csdk/security/src/pstatresource.c +++ b/resource/csdk/security/src/pstatresource.c @@ -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 diff --git a/resource/csdk/security/src/srmutility.c b/resource/csdk/security/src/srmutility.c index e54095d..80b836f 100644 --- a/resource/csdk/security/src/srmutility.c +++ b/resource/csdk/security/src/srmutility.c @@ -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 diff --git a/resource/csdk/stack/include/internal/ocobserve.h b/resource/csdk/stack/include/internal/ocobserve.h index f5fc6c1..018ee7c 100644 --- a/resource/csdk/stack/include/internal/ocobserve.h +++ b/resource/csdk/stack/include/internal/ocobserve.h @@ -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); diff --git a/resource/csdk/stack/include/ocpayload.h b/resource/csdk/stack/include/ocpayload.h index fc11afa..763a107 100644 --- a/resource/csdk/stack/include/ocpayload.h +++ b/resource/csdk/stack/include/ocpayload.h @@ -32,10 +32,6 @@ #include #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 diff --git a/resource/csdk/stack/include/octypes.h b/resource/csdk/stack/include/octypes.h index a7e6dbf..8187b88 100644 --- a/resource/csdk/stack/include/octypes.h +++ b/resource/csdk/stack/include/octypes.h @@ -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, diff --git a/resource/csdk/stack/src/ocobserve.c b/resource/csdk/stack/src/ocobserve.c index 18de8c6..7495f2b 100644 --- a/resource/csdk/stack/src/ocobserve.c +++ b/resource/csdk/stack/src/ocobserve.c @@ -43,9 +43,13 @@ #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); diff --git a/resource/csdk/stack/src/ocpayload.c b/resource/csdk/stack/src/ocpayload.c index 95b9440..e31454f 100755 --- a/resource/csdk/stack/src/ocpayload.c +++ b/resource/csdk/stack/src/ocpayload.c @@ -32,6 +32,10 @@ #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 ',' diff --git a/resource/csdk/stack/src/ocserverrequest.c b/resource/csdk/stack/src/ocserverrequest.c index 3dde884..aa5930b 100644 --- a/resource/csdk/stack/src/ocserverrequest.c +++ b/resource/csdk/stack/src/ocserverrequest.c @@ -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); diff --git a/resource/csdk/stack/src/ocstack.c b/resource/csdk/stack/src/ocstack.c index 63eef55..240920f 100644 --- a/resource/csdk/stack/src/ocstack.c +++ b/resource/csdk/stack/src/ocstack.c @@ -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) diff --git a/resource/csdk/stack/src/oickeepalive.c b/resource/csdk/stack/src/oickeepalive.c index 451d9dc..bd01d08 100755 --- a/resource/csdk/stack/src/oickeepalive.c +++ b/resource/csdk/stack/src/oickeepalive.c @@ -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); } diff --git a/resource/include/OCUtilities.h b/resource/include/OCUtilities.h index 85039d0..2339be2 100644 --- a/resource/include/OCUtilities.h +++ b/resource/include/OCUtilities.h @@ -21,6 +21,7 @@ #ifndef OC_UTILITIES_H_ #define OC_UTILITIES_H_ +#include #include #include #include diff --git a/resource/src/InProcClientWrapper.cpp b/resource/src/InProcClientWrapper.cpp index 0dfc3b6..132d082 100755 --- a/resource/src/InProcClientWrapper.cpp +++ b/resource/src/InProcClientWrapper.cpp @@ -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) diff --git a/service/notification/src/provider/NSProviderNotification.c b/service/notification/src/provider/NSProviderNotification.c index 0119116..74708df 100644 --- a/service/notification/src/provider/NSProviderNotification.c +++ b/service/notification/src/provider/NSProviderNotification.c @@ -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; diff --git a/service/notification/src/provider/NSProviderTopic.c b/service/notification/src/provider/NSProviderTopic.c index f6aa8e9..9a6dee9 100644 --- a/service/notification/src/provider/NSProviderTopic.c +++ b/service/notification/src/provider/NSProviderTopic.c @@ -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;