##
import os
+import shutil
Import('env')
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)
# 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):
%{!?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
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} \
+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
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
{
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--;
}
}
#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;
*/
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
/**
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
}
#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.
*
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;
}
#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");
OIC_LOG_V(DEBUG, TAG, "token len:%d, token:", tokenLength);
OIC_LOG_BUFFER(DEBUG, TAG, (const uint8_t *)(*token), tokenLength);
-
return CA_STATUS_OK;
}
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
static CAResult_t CATCPInitializeQueueHandles();
-static void CATCPDeinitializeQueueHandles();
+static void CATCPDeinitializeQueueHandles(CAQueueingThread_t *queueHandle);
static void CATCPSendDataThread(void *threadData);
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)
#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.
#endif
}
+TEST_F(CATests, SetSecureEndpointUuidTestWithNullPeer)
+{
+#ifdef __WITH_DTLS__
+ EXPECT_EQ(CA_STATUS_INVALID_PARAM, CASetSecureEndpointUuid(NULL, NULL));
+#endif
+}
+
// CARegisterNetworkMonitorHandler TC
TEST_F(CATests, RegisterNetworkMonitorHandler)
{
'../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']:
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
}
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'])
#include "octhread.h"
#include "cathreadpool.h"
#include "ocpayload.h"
+#include "securevirtualresourcetypes.h"
#include "payload_logging.h"
#include "aclresource.h"
#include "crlresource.h"
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)
{
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.");
{
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.");
#include "psinterface.h"
#include "srmresourcestrings.h"
#include "srmutility.h"
+#include "aclresource.h"
+#include "credresource.h"
+#include "ocprovisioningmanager.h"
#define TAG "OIC_SRM_PSTAT"
}
/**
+ * 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.
}
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");
}
* 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
}
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
* @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);
#include <inttypes.h>
#include "octypes.h"
-#if defined(__WITH_TLS__) || defined(__WITH_DTLS__)
-#include "securevirtualresourcetypes.h"
-#endif
-
#ifdef __cplusplus
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
* 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,
#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)
OCStackResult result = OC_STACK_ERROR;
ResourceObserver * resourceObserver = NULL;
- uint8_t numObs = 0;
+ uint16_t numObs = 0;
OCServerRequest * request = NULL;
bool observeErrorFlag = false;
}
OCStackResult SendListObserverNotification (OCResource * resource,
- OCObservationId *obsIdList, uint8_t numberOfIds,
+ OCObservationId *obsIdList, uint16_t numberOfIds,
const OCRepPayload *payload,
uint32_t maxAge,
OCQualityOfService qos)
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;
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;
}
oc_mutex_lock(g_serverObsListMutex);
LL_APPEND (g_serverObsList, obsNode);
+ observer_count++;
oc_mutex_unlock(g_serverObsListMutex);
return OC_STACK_OK;
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);
#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 ','
{
if(serverRequest)
{
+ OIC_LOG_V(WARNING, TAG, "Server request ID = [%u]", serverRequest->requestId);
LL_DELETE(serverRequestList, serverRequest);
OICFree(serverRequest->requestToken);
OICFree(serverRequest->rcvdVendorSpecificHeaderOptions);
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);
#include "ocpayload.h"
#include "ocpayloadcbor.h"
#include "cautilinterface.h"
+#include "camessagehandler.h"
#include "oicgroup.h"
#if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
{
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)
{
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
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);
}
#ifndef OC_UTILITIES_H_
#define OC_UTILITIES_H_
+#include <functional>
#include <map>
#include <vector>
#include <memory>
{
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)
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)
{
NS_LOG(DEBUG, "NSSendSync - IN");
- OCObservationId obArray[255] = { 0, };
+ OCObservationId obArray[3839] = { 0, };
int obCount = 0;
int i;
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;