Merge branch 'tizen' into tizen_5.5 52/218152/1 submit/tizen_5.5/20191120.044409
authorSudipto Bal <sudipto.bal@samsung.com>
Wed, 20 Nov 2019 04:34:53 +0000 (13:34 +0900)
committerSudipto Bal <sudipto.bal@samsung.com>
Wed, 20 Nov 2019 04:35:23 +0000 (13:35 +0900)
Change-Id: I4b938307646c13c4011edeed494fbe930d1ce3a1

49 files changed:
packaging/snapshot_history.txt
resource/c_common/octhread/include/octhread.h
resource/c_common/octhread/src/noop/octhread.c
resource/csdk/connectivity/api/cacommon.h
resource/csdk/connectivity/api/cautilinterface.h [changed mode: 0644->0755]
resource/csdk/connectivity/inc/caqueueingthread.h
resource/csdk/connectivity/inc/catcpadapter.h
resource/csdk/connectivity/inc/catcpinterface.h
resource/csdk/connectivity/src/bt_edr_adapter/caedradapter.c
resource/csdk/connectivity/src/bt_edr_adapter/tizen/caedrclient.c
resource/csdk/connectivity/src/bt_le_adapter/caleadapter.c
resource/csdk/connectivity/src/bt_le_adapter/tizen/caleclient.c
resource/csdk/connectivity/src/bt_le_adapter/tizen/caleclient_vd.c
resource/csdk/connectivity/src/bt_le_adapter/tizen/caleserver_mcd.c
resource/csdk/connectivity/src/cablockwisetransfer.c
resource/csdk/connectivity/src/camessagehandler.c
resource/csdk/connectivity/src/caqueueingthread.c
resource/csdk/connectivity/src/ip_adapter/caipadapter.c
resource/csdk/connectivity/src/ip_adapter/caipserver.c
resource/csdk/connectivity/src/ip_adapter/linux/caipnwmonitor.c
resource/csdk/connectivity/src/nfc_adapter/canfcadapter.c
resource/csdk/connectivity/src/tcp_adapter/catcpadapter.c [changed mode: 0644->0755]
resource/csdk/connectivity/src/tcp_adapter/catcpserver.c [changed mode: 0644->0755]
resource/csdk/connectivity/util/src/cautilinterface.c
resource/csdk/routing/src/routingmessageparser.c
resource/csdk/routing/src/routingtablemanager.c
resource/csdk/routing/src/routingutility.c
resource/csdk/security/include/internal/doxmresource.h
resource/csdk/security/include/internal/psinterface.h
resource/csdk/security/provisioning/include/ocprovisioningmanager.h
resource/csdk/security/provisioning/src/ocprovisioningmanager.c
resource/csdk/security/src/credresource.c
resource/csdk/security/src/doxmresource.c
resource/csdk/security/src/policyengine.c
resource/csdk/security/src/psinterface.c
resource/csdk/security/src/srmutility.c
resource/csdk/stack/include/ocstack.h
resource/csdk/stack/include/octypes.h
resource/csdk/stack/src/occlientcb.c
resource/csdk/stack/src/ocresource.c
resource/csdk/stack/src/ocserverrequest.c
resource/csdk/stack/src/ocstack.c
resource/csdk/stack/src/oicgroup.c
resource/src/InProcClientWrapper.cpp
service/easy-setup/enrollee/src/resourcehandler.c
service/notification/cpp-wrapper/consumer/src/NSConsumerService.cpp
service/notification/cpp-wrapper/consumer/src/NSProvider.cpp
service/notification/src/common/NSUtil.c
service/notification/src/provider/NSProviderNotification.c

index 698f66e..5eae353 100755 (executable)
@@ -1,4 +1,16 @@
-http://suprem.sec.samsung.net/jira/browse/CONPRO-1503 
+http://suprem.sec.samsung.net/jira/browse/CONPRO-1528
+
+commit_info_2019-11-14.txt
+
+commit_id: Ib52585b767e92e3f263a653a108e0b734e348eb1
+---------------------------------------------------------------------------------------------------------------------------------
+http://suprem.sec.samsung.net/jira/browse/CONPRO-1520
+
+commit_info_2019-10-25.txt
+
+commit_id: 992729fd6eab4f1b57280f6502ce09d460ace39c
+---------------------------------------------------------------------------------------------------------------------------------
+http://suprem.sec.samsung.net/jira/browse/CONPRO-1503
 
 commit_info_2019-09-26.txt
 
@@ -44,7 +56,7 @@ http://suprem.sec.samsung.net/jira/browse/CONPRO-1461
 
 commit_info_2019-07-11.txt
 
-commit_id: 6b31a4840ddceaeb699293dff833353d39901675 
+commit_id: 6b31a4840ddceaeb699293dff833353d39901675
 ---------------------------------------------------------------------------------------------------------------------------------
 http://suprem.sec.samsung.net/jira/browse/CONPRO-1456
 
index 3caffa0..54ba69d 100755 (executable)
@@ -142,6 +142,16 @@ OCThreadResult_t oc_thread_cancel(oc_thread t);
 oc_mutex oc_mutex_new(void);
 
 /**
+ * Creates new mutex that supports recursion. Use oc_mutex_free to free the created mutex.
+ *
+ * @note The use of recursive mutex in IoTivity is discouraged. Please use it sporadically.
+ *
+ * @return  Reference to newly created mutex, otherwise NULL.
+ *
+ */
+oc_mutex oc_mutex_new_recursive(void);
+
+/**
  * Lock the mutex.
  *
  * @param  mutex  The mutex to be locked.
index 39cfff9..c8aafbe 100755 (executable)
@@ -79,6 +79,11 @@ oc_mutex oc_mutex_new(void)
     return (oc_mutex)&g_mutexInfo;
 }
 
+oc_mutex oc_mutex_new_recursive(void)
+{
+    return oc_mutex_new();
+}
+
 bool oc_mutex_free(oc_mutex mutex)
 {
     return true;
index c0593e0..002794c 100755 (executable)
@@ -98,6 +98,11 @@ extern "C"
 #define CA_MAX_TOKEN_LEN (8)
 
 /**
+* Max interface name length.
+*/
+#define CA_MAX_INTERFACE_NAME_LEN (16)
+
+/**
  * Max URI length.
  */
 #ifdef ARDUINO
@@ -651,6 +656,7 @@ typedef struct
         int connectionFds[2];   /**< connection pipe */
         bool started;           /**< the TCP adapter has started */
         bool terminate;         /**< the TCP adapter needs to stop */
+        bool bindenabled;       /**< binding of TCP socket enabled */
         bool ipv4tcpenabled;    /**< IPv4 TCP enabled by OCInit flags */
         bool ipv6tcpenabled;    /**< IPv6 TCP enabled by OCInit flags */
     } tcp;
old mode 100644 (file)
new mode 100755 (executable)
index 563c781..59e0315
@@ -451,6 +451,49 @@ CAResult_t CAUtilStopGattServer();
 
 #if defined(__TIZEN__)
 CAResult_t CAGetTCPIPHeader(CATransportAdapter_t adapter, int flag, TCPHeaderInfo* info);
+
+/**
+ * Enables keep-alive on the given endpoint & configures it with user defined values.
+ *
+ * @param[in]  endpoint    Endpoint on keep-alive needs to be enabled.
+ * @param[in]  time    The number of seconds a connection needs to be idle
+ *                                  before TCP begins sending out keep-alive probes.
+ * @param[in]  cnt    The maximum number of TCP keep-alive probes to send before
+ *                                giving up and killing the connection if no response is obtained from the other end
+ * @param[in]  intvl    The number of seconds between TCP keep-alive probes.
+ *
+ * @return  ::CA_STATUS_OK or Appropriate error code.
+ */
+CAResult_t CASetTCPKeepAlive(const CAEndpoint_t *endpoint, int time, int cnt, int intvl);
+
+/**
+ * Disables keep-alive on the given endpoint.
+ *
+ * @param[in]  endpoint    Endpoint on which keep-alive needs to be disabled.
+ *
+ * @return  ::CA_STATUS_OK or Appropriate error code.
+ */
+CAResult_t CAUnSetTCPKeepAlive(const CAEndpoint_t *endpoint);
+
+/**
+ * Get the last error code (errno) to identify the reason
+ * when disconnection happens during keep-alive.
+ *
+ * @return             - Direct 'errno' value from kernel
+ */
+int CAGetTCPLastErrorCode();
+
+/**
+ * Set the interface to be used for outgoing TCP packets.
+ * Tcp client sockets (before establishing connection) will be bound to the IP address of the given WiFi interface.
+ * Internally, Iotivity reads the IP address assigned to the given interace
+ * and binds it with the TCP client socket before connect().
+ *
+ * @param[in]   ifname     WiFi interface name.
+ *
+ * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
+ */
+CAResult_t CASetTCPServerSocketBindIP(const char* ifname);
 #endif
 
 #ifdef __cplusplus
index 91deeda..cfa017c 100644 (file)
@@ -91,9 +91,11 @@ CAResult_t CAQueueingThreadStart(CAQueueingThread_t *thread, const char *thread_
  * @param[in]   thread       thread data for new thread control.
  * @param[in]   data         data that needs to be given for each thread.
  * @param[in]   size         length of the data.
+ * @param[in]   chkThread         Option to ensure whether thread is running or not before adding data.
  * @return  CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h).
  */
-CAResult_t CAQueueingThreadAddData(CAQueueingThread_t *thread, void *data, uint32_t size);
+CAResult_t CAQueueingThreadAddData(CAQueueingThread_t *thread, void *data,
+                                            uint32_t size, bool chkThread);
 
 /**
  * Clears queue thread data.
index 2c9bb43..252e80b 100644 (file)
@@ -214,6 +214,38 @@ void CATerminateTCP();
  * @return  ::CA_STATUS_OK or Appropriate error code.
  */
 CAResult_t CAGetTCPIPHeaderInfo(CATransportFlags_t flag, TCPHeaderInfo* tcpHeaderInfo);
+
+/**
+ * Enables keep-alive on the given endpoint & configures it with user defined values.
+ *
+ * @param[in]  endpoint    Endpoint on keep-alive needs to be enabled.
+ * @param[in]  time    The number of seconds a connection needs to be idle
+ *                                  before TCP begins sending out keep-alive probes.
+ * @param[in]  cnt    The maximum number of TCP keep-alive probes to send before
+ *                                giving up and killing the connection if no response is obtained from the other end
+ * @param[in]  intvl    The number of seconds between TCP keep-alive probes.
+ *
+ * @return  ::CA_STATUS_OK or Appropriate error code.
+ */
+CAResult_t CATCPSetKeepAlive(const CAEndpoint_t *endpoint, int time, int cnt, int intvl);
+
+/**
+ * Disables keep-alive on the given endpoint.
+ *
+ * @param[in]  endpoint    Endpoint on which keep-alive needs to be disabled.
+ *
+ * @return  ::CA_STATUS_OK or Appropriate error code.
+ */
+CAResult_t CATCPUnSetKeepAlive(const CAEndpoint_t *endpoint);
+
+/**
+ * Get the last error code (errno) to identify the reason
+ * when disconnection happens during keep-alive.
+ *
+ * @return             - Direct 'errno' value from kernel
+ */
+int CATCPGetLastErrorCode();
+
 #endif
 
 #ifdef TCP_ADAPTER
index d617365..24d69d5 100644 (file)
@@ -271,6 +271,37 @@ CAResult_t CAConstructCoAP(CATCPSessionInfo_t *svritem, unsigned char **data,
 void CACleanData(CATCPSessionInfo_t *svritem);
 
 /**
+ * Enables keep-alive on the given endpoint & configures it with user defined values.
+ *
+ * @param[in]  endpoint    Endpoint on keep-alive needs to be enabled.
+ * @param[in]  time    The number of seconds a connection needs to be idle
+ *                                  before TCP begins sending out keep-alive probes.
+ * @param[in]  cnt    The maximum number of TCP keep-alive probes to send before
+ *                                giving up and killing the connection if no response is obtained from the other end
+ * @param[in]  intvl    The number of seconds between TCP keep-alive probes.
+ *
+ * @return  ::CA_STATUS_OK or Appropriate error code.
+ */
+CAResult_t CASetKeepAlive(const CAEndpoint_t *endpoint, int time, int cnt, int intvl);
+
+/**
+ * Disables keep-alive on the given endpoint.
+ *
+ * @param[in]  endpoint    Endpoint on which keep-alive needs to be disabled.
+ *
+ * @return  ::CA_STATUS_OK or Appropriate error code.
+ */
+CAResult_t CAUnSetKeepAlive(const CAEndpoint_t *endpoint);
+
+/**
+ * Get the last error code (errno) to identify the reason
+ * when disconnection happens during keep-alive.
+ *
+ * @return             - Direct 'errno' value from kernel
+ */
+int CAGetLastErrorCode();
+
+/**
  * Create a mutex object.
  *
  * @return  ::CA_STATUS_OK or Appropriate error code.
index 4481499..f5cf685 100644 (file)
@@ -660,7 +660,15 @@ CAResult_t CAAdapterRecvData(const char *remoteAddress, const uint8_t *data,
 
     // Add message to data queue
     CAEDRData *edrData =  CACreateEDRData(remoteEndpoint, data, dataLength);
-    CAQueueingThreadAddData(g_recvQueueHandle, edrData, sizeof(CAEDRData));
+    CAResult_t result = CAQueueingThreadAddData(g_recvQueueHandle, edrData, sizeof(CAEDRData), true);
+    if (result != CA_STATUS_OK)
+    {
+        OIC_LOG(ERROR, TAG, "Failed to add message to data queue!");
+        CAFreeEDRData(edrData);
+        CAFreeEndpoint(remoteEndpoint);
+        return result;
+    }
+
     *sentLength = dataLength;
 
     // Free remote endpoint
@@ -718,7 +726,15 @@ CAResult_t CAAdapterSendData(const char *remoteAddress, const char *serviceUUID,
 
     // Add message to data queue
     CAEDRData *edrData =  CACreateEDRData(remoteEndpoint, data, dataLength);
-    CAQueueingThreadAddData(g_sendQueueHandle, edrData, sizeof (CAEDRData));
+    CAResult_t result = CAQueueingThreadAddData(g_sendQueueHandle, edrData, sizeof (CAEDRData), true);
+    if (result != CA_STATUS_OK)
+    {
+        OIC_LOG(ERROR, TAG, "Failed to add message to data queue!");
+        CAFreeEDRData(edrData);
+        CAFreeEndpoint(remoteEndpoint);
+        return result;
+    }
+
     *sentLength = dataLength;
 
     // Free remote endpoint
index 49384b4..5fb9d3b 100644 (file)
@@ -676,7 +676,7 @@ CAResult_t CAEDRClientSendUnicastData(const char *remoteAddress,
     VERIFY_NON_NULL(remoteAddress, EDR_ADAPTER_TAG, "Remote address is null");
     VERIFY_NON_NULL(data, EDR_ADAPTER_TAG, "Data is null");
 
-    if (0 >= dataLength)
+    if (0 == dataLength)
     {
         OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Invalid input: Negative data length!");
         return CA_STATUS_INVALID_PARAM;
@@ -771,7 +771,7 @@ CAResult_t CAEDRClientSendMulticastData(const uint8_t *data,
     // Input validation
     VERIFY_NON_NULL(data, EDR_ADAPTER_TAG, "Data is null");
 
-    if (0 >= dataLength)
+    if (0 == dataLength)
     {
         OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Invalid input: Negative data length!");
         return CA_STATUS_INVALID_PARAM;
index 003cc92..225e1be 100644 (file)
@@ -585,7 +585,7 @@ static CAResult_t CAInitLEServerQueues()
     if (CA_STATUS_OK != result)
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "CAInitBleServerSenderQueue failed");
+
         return CA_STATUS_FAILED;
     }
 
@@ -929,7 +929,7 @@ static CAResult_t CALEFreeSenderInfo(CABLESenderInfo_t *senderInfo)
 
     oc_mutex_lock(g_senderInfoMutex);
     senderInfo->refCount--;
-    if(senderInfo->refCount <= 0)
+    if(senderInfo->refCount == 0)
     {
         OICFree(senderInfo->defragData);
         OICFree(senderInfo->remoteEndpoint);
@@ -2564,7 +2564,7 @@ static CAResult_t CALEAdapterGattClientStop()
     CAStopLEGattClient();
 
     CAResult_t result = CAQueueingThreadStop(g_bleClientSendQueueHandle);
+
     return result;
 #else
     CAStopLEGattClient();
@@ -2639,7 +2639,7 @@ CAResult_t CALESecureReceiveDataCB(const CASecureEndpoint_t *sep, const void *da
     OIC_LOG_V(DEBUG, CALEADAPTER_TAG,
               "Secure Data Receive - decrypted datalen = %zd", dataLen);
 
-    if (dataLen <= 0)
+    if (dataLen == 0)
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "incorrect dataLen, derecypt fail !");
         return CA_STATUS_INVALID_PARAM;
@@ -3067,7 +3067,7 @@ static int32_t CASendLEMulticastData(const CAEndpoint_t *endpoint,
     //Input validation
     VERIFY_NON_NULL_RET(data, CALEADAPTER_TAG, "Data is null", -1);
 
-    if (0 >= dataLen)
+    if (0 == dataLen)
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "Invalid Parameter");
         return -1;
@@ -3417,7 +3417,7 @@ static CAResult_t CALEAdapterClientSendData(const CAEndpoint_t *remoteEndpoint,
     // Add message to send queue
 
     CAResult_t res = CAQueueingThreadAddData(g_bleClientSendQueueHandle, bleData,
-                                             sizeof(CALEData_t));
+                                             sizeof(CALEData_t), true);
     if (CA_STATUS_OK != res)
     {
         CALEDataDestroyer(bleData, sizeof(CALEData_t));
@@ -3467,7 +3467,7 @@ static CAResult_t CALEAdapterServerSendData(const CAEndpoint_t *remoteEndpoint,
 
     CAResult_t res = CAQueueingThreadAddData(g_bleServerSendQueueHandle,
                                            bleData,
-                                           sizeof(CALEData_t));
+                                           sizeof(CALEData_t), true);
     if (CA_STATUS_OK != res)
     {
         CALEDataDestroyer(bleData, sizeof(CALEData_t));
@@ -3546,7 +3546,13 @@ static CAResult_t CALEAdapterServerReceivedData(const char *remoteAddress,
 
     CAFreeEndpoint(remoteEndpoint);
     // Add message to receiver queue
-    CAQueueingThreadAddData(g_bleServerReceiverQueue, bleData, sizeof(CALEData_t));
+    CAResult_t result = CAQueueingThreadAddData(g_bleServerReceiverQueue, bleData, sizeof(CALEData_t), true);
+    if (result != CA_STATUS_OK)
+    {
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "Failed to add message to data queue!");
+        CAFreeLEData(bleData);
+        return result;
+    }
 
     *sentLength = dataLength;
 #endif
@@ -3595,7 +3601,13 @@ static CAResult_t CALEAdapterClientReceivedData(const char *remoteAddress,
 
     CAFreeEndpoint(remoteEndpoint);
     // Add message to receiver queue
-    CAQueueingThreadAddData(g_bleClientReceiverQueue, bleData, sizeof(CALEData_t));
+    CAResult_t result = CAQueueingThreadAddData(g_bleClientReceiverQueue, bleData, sizeof(CALEData_t), true);
+    if (result != CA_STATUS_OK)
+    {
+        OIC_LOG(ERROR, CALEADAPTER_TAG, "Failed to add message to data queue!");
+        CAFreeLEData(bleData);
+        return result;
+    }
 
     *sentLength = dataLength;
 #endif
index a5851cb..fb5a920 100644 (file)
@@ -428,7 +428,7 @@ static bool CALEIsHaveServiceImpl(bt_adapter_le_device_scan_result_info_s *scanI
         int man_id;
         result = bt_adapter_le_get_scan_result_manufacturer_data(scanInfo,
                               pkt_type, &man_id, &man_data, &man_data_len);
-        
+
         if (result == BT_ERROR_NONE && NULL != man_data)
         {
             char *compare_man_data = OICMalloc((man_data_len*2)+1);
@@ -1446,7 +1446,7 @@ CAResult_t CAUpdateCharacteristicsToGattServer(const char *remoteAddress,
 
     VERIFY_NON_NULL(data, TAG, "data is NULL");
 
-    if (0 >= dataLen)
+    if (0 == dataLen)
     {
         OIC_LOG(ERROR, TAG, "dataLen is less than or equal zero. Invalid input!");
         return CA_STATUS_INVALID_PARAM;
@@ -1589,7 +1589,7 @@ CAResult_t CAUpdateCharacteristicsToAllGattServers(const uint8_t *data, uint32_t
 
     VERIFY_NON_NULL(data, TAG, "data is NULL");
 
-    if (0 >= dataLen)
+    if (0 == dataLen)
     {
         OIC_LOG(ERROR, TAG, "dataLen is less than or equal zero. Invalid input !");
         return CA_STATUS_INVALID_PARAM;
index 68c2455..9b9bcce 100644 (file)
@@ -421,10 +421,17 @@ static bool CALEIsHaveServiceImpl(bt_adapter_le_device_scan_result_info_s *scanI
 
         if (result == BT_ERROR_NONE && NULL != man_data)
         {
-            char *compare_man_data = OICCalloc(1, (man_data_len*2)+1);
             int pos =0;
+            char *compare_man_data = OICCalloc(1, (man_data_len*2)+1);
+            if (!compare_man_data)
+            {
+                OIC_LOG(ERROR, TAG, "Memory allocation failed for compare_man_data");
+                OICFree(man_data);
+                return false;
+            }
+
             for(int i=0;i<man_data_len;i++){
-                pos += sprintf(compare_man_data+pos, "%.2x", man_data[i]);
+                pos += snprintf(compare_man_data+pos, 2, "%.2x", man_data[i]);
             }
 
             if (man_id == samsung_code && 0 == strncasecmp(compare_man_data, service_uuid, CUSTOM_UUID_LEN))
@@ -1401,7 +1408,7 @@ CAResult_t CAUpdateCharacteristicsToGattServer(const char *remoteAddress,
 
     VERIFY_NON_NULL(data, TAG, "data is NULL");
 
-    if (0 >= dataLen)
+    if (0 == dataLen)
     {
         OIC_LOG(ERROR, TAG, "dataLen is less than or equal zero. Invalid input!");
         return CA_STATUS_INVALID_PARAM;
@@ -1542,7 +1549,7 @@ CAResult_t CAUpdateCharacteristicsToAllGattServers(const uint8_t *data, uint32_t
 
     VERIFY_NON_NULL(data, TAG, "data is NULL");
 
-    if (0 >= dataLen)
+    if (0 == dataLen)
     {
         OIC_LOG(ERROR, TAG, "dataLen is less than or equal zero. Invalid input !");
         return CA_STATUS_INVALID_PARAM;
index 0f9aaab..e9e3d00 100644 (file)
@@ -159,7 +159,7 @@ CAResult_t CAsetServerAdvertisementData(const char *data, int length)
 
     OIC_LOG(DEBUG, TAG, "IN");
 
-    if(!data || strlen(data) <= 0 || length <=0 )
+    if(!data || strlen(data) == 0 || length <=0 )
     {
         OIC_LOG(ERROR, TAG, "Invalid param is passed");
         return CA_STATUS_INVALID_PARAM;
@@ -211,7 +211,7 @@ CAResult_t CAsetServerScanResponseData(const char *data, int length)
 
     OIC_LOG(DEBUG, TAG, "IN");
 
-    if(!data || strlen(data) <= 0 || length <=0 )
+    if(!data || strlen(data) == 0 || length <=0 )
     {
         OIC_LOG(ERROR, TAG, "Invalid param is passed");
         return CA_STATUS_INVALID_PARAM;
@@ -358,7 +358,7 @@ CAResult_t CAStartLEGattServer()
         CATerminateLEGattServer();
         return CA_STATUS_FAILED;
     }
-    
+
     if(g_leServerAutoAdvertisement)
     {
         ret = CALEStartAdvertise();
@@ -374,7 +374,7 @@ CAResult_t CAStartLEGattServer()
     {
         OIC_LOG(WARNING, TAG, "Auto advertisement is DISABLED. Advertising is not started.");
     }
-    
+
     g_isLEGattServerStarted = true;
 
     oc_mutex_unlock(g_leServerStateMutex);
@@ -426,7 +426,7 @@ CAResult_t CALEStartAdvertise()
     {
         OIC_LOG_V(ERROR, TAG, "CALEStartAdvertiseImpl failed[%d]", res);
     }
-    
+
     //This array is freed here because it's used in CALEStartAdvertiseImpl() method (freeing earlier causes bluetooth to crash)
     if(data)
         free(data);
index 0326f19..868b6e8 100755 (executable)
@@ -2722,7 +2722,6 @@ void CADestroyBlockID(CABlockDataID_t *blockID)
     VERIFY_NON_NULL_VOID(blockID, TAG, "blockID");
     OICFree(blockID->id);
     OICFree(blockID);
-    blockID = NULL;
 }
 
 bool CABlockidMatches(const CABlockData_t *currData, const CABlockDataID_t *blockID)
@@ -2784,7 +2783,7 @@ void CAResetBlockDataTTL(const CABlockDataID_t *blockID)
     for (size_t i = 0; i < len; i++)
     {
         CABlockData_t *blockData = (CABlockData_t *) u_arraylist_get(g_context.dataList, i);
-        if (CABlockidMatches(blockData, blockID))
+        if (blockData && CABlockidMatches(blockData, blockID))
         {
             uint64_t now = OICGetCurrentTime(TIME_IN_US);
             blockData->ttl = now + (BLOCK_DATA_TIMEOUT_SECONDS * USECS_PER_SEC);
index c91f820..ef3e3e7 100644 (file)
@@ -116,7 +116,12 @@ void CAAddDataToSendThread(CAData_t *data)
     VERIFY_NON_NULL_VOID(data, TAG, "data");
 
     // add thread
-    CAQueueingThreadAddData(&g_sendThread, data, sizeof(CAData_t));
+    CAResult_t result = CAQueueingThreadAddData(&g_sendThread, data, sizeof(CAData_t), true);
+    if (result != CA_STATUS_OK)
+    {
+        OIC_LOG(ERROR, TAG, "Failed to add message to data queue!");
+        CADestroyData(data, sizeof(CAData_t));
+    }
 }
 
 void CAAddDataToReceiveThread(CAData_t *data)
@@ -124,7 +129,13 @@ void CAAddDataToReceiveThread(CAData_t *data)
     VERIFY_NON_NULL_VOID(data, TAG, "data");
 
     // add thread
-    CAQueueingThreadAddData(&g_receiveThread, data, sizeof(CAData_t));
+    CAResult_t result = CAQueueingThreadAddData(&g_receiveThread, data, sizeof(CAData_t), false);
+    if (result != CA_STATUS_OK)
+    {
+        OIC_LOG(ERROR, TAG, "Failed to add message to data queue!");
+        CADestroyData(data, sizeof(CAData_t));
+        return;
+    }
 
 #ifdef WITH_PROCESS_EVENT
     if (g_processEvent)
@@ -346,7 +357,13 @@ static void CATimeoutCallback(const CAEndpoint_t *endpoint, const void *pdu, uin
 #ifdef SINGLE_THREAD
     CAProcessReceivedData(cadata);
 #else
-    CAQueueingThreadAddData(&g_receiveThread, cadata, sizeof(CAData_t));
+    CAResult_t result = CAQueueingThreadAddData(&g_receiveThread, cadata, sizeof(CAData_t), false);
+    if (result != CA_STATUS_OK)
+    {
+        OIC_LOG(ERROR, TAG, "Failed to add message to data queue!");
+        CADestroyData(cadata, sizeof(CAData_t));
+        return;
+    }
 
 #ifdef WITH_PROCESS_EVENT
     if (g_processEvent)
@@ -894,7 +911,14 @@ static CAResult_t CAReceivedPacketCallback(const CASecureEndpoint_t *sep,
     else
 #endif
     {
-        CAQueueingThreadAddData(&g_receiveThread, cadata, sizeof(CAData_t));
+        CAResult_t result = CAQueueingThreadAddData(&g_receiveThread, cadata, sizeof(CAData_t), false);
+        if (result != CA_STATUS_OK)
+        {
+            OIC_LOG(ERROR, TAG, "Failed to add message to data queue!");
+            CADestroyData(cadata, sizeof(CAData_t));
+            coap_delete_pdu(pdu);
+            goto exit;
+        }
 
 #ifdef WITH_PROCESS_EVENT
         if (g_processEvent)
@@ -1127,7 +1151,13 @@ CAResult_t CADetachSendNetworkReqMessage(const CAEndpoint_t *endpoint,
     cadata->eventInfo = event;
     cadata->dataType = dataType;
 
-    CAQueueingThreadAddData(&g_sendThread, cadata, sizeof(CAData_t));
+    CAResult_t result = CAQueueingThreadAddData(&g_sendThread, cadata, sizeof(CAData_t), true);
+    if (result != CA_STATUS_OK)
+    {
+        OIC_LOG(ERROR, TAG, "Failed to add message to data queue!");
+        CADestroyData(cadata, sizeof(CAData_t));
+        return result;
+    }
 #endif
 
     return CA_STATUS_OK;
@@ -1183,7 +1213,13 @@ CAResult_t CADetachSendMessage(const CAEndpoint_t *endpoint, const void *sendMsg
         if (CA_NOT_SUPPORTED == res)
         {
             OIC_LOG(DEBUG, TAG, "normal msg will be sent");
-            CAQueueingThreadAddData(&g_sendThread, data, sizeof(CAData_t));
+            CAResult_t result = CAQueueingThreadAddData(&g_sendThread, data, sizeof(CAData_t), true);
+            if (result != CA_STATUS_OK)
+            {
+                OIC_LOG(ERROR, TAG, "Failed to add message to data queue!");
+                CADestroyData(data, sizeof(CAData_t));
+                return result;
+            }
             return CA_STATUS_OK;
         }
         else
@@ -1196,7 +1232,13 @@ CAResult_t CADetachSendMessage(const CAEndpoint_t *endpoint, const void *sendMsg
     else
 #endif // WITH_BWT
     {
-        CAQueueingThreadAddData(&g_sendThread, data, sizeof(CAData_t));
+        CAResult_t result = CAQueueingThreadAddData(&g_sendThread, data, sizeof(CAData_t), true);
+        if (result != CA_STATUS_OK)
+        {
+            OIC_LOG(ERROR, TAG, "Failed to add message to data queue!");
+            CADestroyData(data, sizeof(CAData_t));
+            return result;
+        }
     }
 #endif // SINGLE_THREAD
 
@@ -1501,7 +1543,14 @@ void CAErrorHandler(const CAEndpoint_t *endpoint,
 
     cadata->errorInfo->result = result;
 
-    CAQueueingThreadAddData(&g_receiveThread, cadata, sizeof(CAData_t));
+    CAResult_t res = CAQueueingThreadAddData(&g_receiveThread, cadata, sizeof(CAData_t), false);
+    if (res != CA_STATUS_OK)
+    {
+        OIC_LOG(ERROR, TAG, "Failed to add message to data queue!");
+        CADestroyData(cadata, sizeof(CAData_t));
+        coap_delete_pdu(pdu);
+        return;
+    }
 
 #ifdef WITH_PROCESS_EVENT
     if (g_processEvent)
@@ -1561,7 +1610,13 @@ static void CASendErrorInfo(const CAEndpoint_t *endpoint, const CAInfo_t *info,
     cadata->errorInfo = errorInfo;
     cadata->dataType = CA_ERROR_DATA;
 
-    CAQueueingThreadAddData(&g_receiveThread, cadata, sizeof(CAData_t));
+    res = CAQueueingThreadAddData(&g_receiveThread, cadata, sizeof(CAData_t), false);
+    if (res != CA_STATUS_OK)
+    {
+        OIC_LOG(ERROR, TAG, "Failed to add message to data queue!");
+        CADestroyData(cadata, sizeof(CAData_t));
+        return;
+    }
 
 #ifdef WITH_PROCESS_EVENT
     if (g_processEvent)
index 05baf0f..018e53b 100755 (executable)
@@ -214,7 +214,8 @@ CAResult_t CAQueueingThreadStart(CAQueueingThread_t *thread, const char *thread_
     return res;
 }
 
-CAResult_t CAQueueingThreadAddData(CAQueueingThread_t *thread, void *data, uint32_t size)
+CAResult_t CAQueueingThreadAddData(CAQueueingThread_t *thread, void *data,
+                                   uint32_t size, bool chkThread)
 {
     if (NULL == thread)
     {
@@ -243,6 +244,17 @@ CAResult_t CAQueueingThreadAddData(CAQueueingThread_t *thread, void *data, uint3
     // mutex lock
     oc_mutex_lock(thread->threadMutex);
 
+    // thread stop
+    if (chkThread && thread->isStop)
+    {
+        // mutex unlock
+        oc_mutex_unlock(thread->threadMutex);
+
+        OIC_LOG(ERROR, TAG, "thread is stopped..");
+        OICFree(message);
+        return CA_STATUS_FAILED;
+    }
+
     // add thread data into list
     u_queue_add_element(thread->dataQueue, message);
 
index 313584c..5b50636 100644 (file)
@@ -405,7 +405,13 @@ static int32_t CAQueueIPData(bool isMulticast, const CAEndpoint_t *endpoint,
         return -1;
     }
     // Add message to send queue
-    CAQueueingThreadAddData(g_sendQueueHandle, ipData, sizeof(CAIPData_t));
+    CAResult_t result = CAQueueingThreadAddData(g_sendQueueHandle, ipData, sizeof(CAIPData_t), true);
+    if (result != CA_STATUS_OK)
+    {
+        OIC_LOG(ERROR, TAG, "Failed to add message to data queue!");
+        CAFreeIPData(ipData);
+        return -1;
+    }
 
 #endif // SINGLE_THREAD
 
index 085f060..04a3495 100644 (file)
@@ -362,6 +362,13 @@ static void CAFindReadyMessage()
     {
         CAPollReturned(readFds, ret);
     }
+    else if (ret == 0)
+    {
+        usleep(1000); /* Incase of failure of FastShutdownMechanism timeout will be set to 1.
+                         some of the fields are not set by kernel on repeatedly calling
+                         poll.Applying a sleep will solve this by providing a delay
+                         between each subsequent poll system call */
+    }
     else if (ret < 0)
     {
         OIC_LOG_V(FATAL, TAG, "poll error %s", CAIPS_GET_ERROR);
@@ -398,10 +405,10 @@ static void CAPollReturned(struct pollfd *readFds, int ret)
             // Write end of the pipe is closed. Indicates the termination of UDP server.
             return;
         }
-
-        counter++;
     }
 
+   counter++;
+
     if (!caglobals.ip.terminate &&
            (caglobals.ip.netlinkFd != OC_INVALID_SOCKET) && readFds[counter].revents != 0)
     {
index 802e41a..1dcd851 100644 (file)
@@ -328,9 +328,9 @@ u_arraylist_t *CAFindInterfaceChange()
 
     ssize_t len = recvmsg(caglobals.ip.netlinkFd, &msg, 0);
 
-    for (nh = (struct nlmsghdr *)buf; NLMSG_OK(nh, len); nh = NLMSG_NEXT(nh, len))
+    for (nh = (struct nlmsghdr *)buf; nh != NULL && NLMSG_OK(nh, len); nh = NLMSG_NEXT(nh, len))
     {
-        if (nh != NULL && (nh->nlmsg_type != RTM_DELADDR && nh->nlmsg_type != RTM_NEWADDR))
+        if (nh->nlmsg_type != RTM_DELADDR && nh->nlmsg_type != RTM_NEWADDR)
         {
             continue;
         }
index 7f77e69..32f2e70 100644 (file)
@@ -296,7 +296,13 @@ static int32_t CAQueueNFCData(const CAEndpoint_t *endpoint, const void *data,
         return -1;
     }
     // Add message to send queue
-    CAQueueingThreadAddData(g_sendQueueHandle, nfcData, sizeof(CANFCData));
+    CAResult_t result = CAQueueingThreadAddData(g_sendQueueHandle, nfcData, sizeof(CANFCData), true);
+    if (result != CA_STATUS_OK)
+    {
+        OIC_LOG(ERROR, TAG, "Failed to add message to data queue!");
+        CAFreeNFCData(nfcData);
+        return -1;
+    }
 
     OIC_LOG(DEBUG, TAG, "OUT");
     return dataLength;
old mode 100644 (file)
new mode 100755 (executable)
index 3dd9a7a..19bea61
@@ -360,6 +360,7 @@ static void CAInitializeTCPGlobals()
     caglobals.tcp.selectTimeout = CA_TCP_SELECT_TIMEOUT;
     caglobals.tcp.listenBacklog = CA_TCP_LISTEN_BACKLOG;
     caglobals.tcp.svrlist = NULL;
+    caglobals.tcp.bindenabled = false;
 
     CATransportFlags_t flags = 0;
     if (caglobals.client)
@@ -628,7 +629,13 @@ static size_t CAQueueTCPData(bool isMulticast, const CAEndpoint_t *endpoint,
         return -1;
     }
     // Add message to send queue
-    CAQueueingThreadAddData(g_sendQueueHandle, tcpData, sizeof(CATCPData));
+    CAResult_t result = CAQueueingThreadAddData(g_sendQueueHandle, tcpData, sizeof(CATCPData), true);
+    if (result != CA_STATUS_OK)
+    {
+        OIC_LOG(ERROR, TAG, "Failed to add message to data queue!");
+        CAFreeTCPData(tcpData);
+        return -1;
+    }
 
     return dataLength;
 }
@@ -975,6 +982,22 @@ CAResult_t CAGetTCPIPHeaderInfo(CATransportFlags_t flag, TCPHeaderInfo* tcpHeade
 
     return res;
 }
+
+CAResult_t CATCPSetKeepAlive(const CAEndpoint_t *endpoint, int time, int cnt, int intvl)
+{
+    return CASetKeepAlive(endpoint, time, cnt, intvl);
+}
+
+CAResult_t CATCPUnSetKeepAlive(const CAEndpoint_t *endpoint)
+{
+    return CAUnSetKeepAlive(endpoint);
+}
+
+int CATCPGetLastErrorCode()
+{
+    return CAGetLastErrorCode();
+}
+
 #endif
 
 #ifdef SINGLE_THREAD
old mode 100644 (file)
new mode 100755 (executable)
index 081775e..f0ca652
@@ -21,6 +21,9 @@
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/ioctl.h>
+#if defined(__TIZEN__)
+#include <ifaddrs.h>
+#endif
 #ifdef __TIZENRT__
 #include <tinyara/config.h>
 #include <poll.h>
@@ -32,6 +35,7 @@
 #include <fcntl.h>
 #include <arpa/inet.h>
 #include <netinet/in.h>
+#include <netinet/tcp.h>
 #include <net/if.h>
 #include <errno.h>
 
@@ -124,6 +128,13 @@ static CATCPErrorHandleCallback g_tcpErrorHandler = NULL;
  */
 static CATCPConnectionHandleCallback g_connectionCallback = NULL;
 
+/**
+ * Error code to hold the errno(Timeout, Destination unreachable, etc) when send/recv fails.
+ * Main purpose is to hold the reason for connection drop when keep-alive is in use.
+ * To indicate normal disconnection, 0 will be assigned.
+ */
+static int g_lastErrorCode;
+
 static CASocketFd_t CACreateAcceptSocket(int family, CASocket_t *sock);
 static void CAAcceptConnection(CATransportFlags_t flag, CASocket_t *sock);
 static void CAFindReadyMessage();
@@ -137,6 +148,8 @@ static CATCPSessionInfo_t *CAGetSessionInfoFromFDAsOwner(int fd, size_t *index);
 #if defined(__TIZEN__)
 static char g_cloudproxyUri[CA_MAX_URI_LENGTH];
 
+static char g_interfaceName[CA_MAX_INTERFACE_NAME_LEN];
+
 CAResult_t CASetCloudAddressForProxy(const char *uri)
 {
     if (uri == NULL)
@@ -152,6 +165,22 @@ const char *CAGetCloudAddressForProxy()
         return NULL;
     return g_cloudproxyUri;
 }
+
+CAResult_t CASetTCPServerSocketBindIP(const char* ifname)
+{
+    CAResult_t res = CA_STATUS_OK;
+#ifdef TCP_ADAPTER
+    VERIFY_NON_NULL_RET(ifname, TAG, "Interface name is NULL", CA_STATUS_INVALID_PARAM);
+
+    OIC_LOG(DEBUG, TAG, "Setting Socket Bind");
+    caglobals.tcp.bindenabled = true;
+    OICStrcpy(g_interfaceName, sizeof (g_interfaceName), ifname);
+#else
+    OIC_LOG(DEBUG, TAG, "Not supported!");
+    res = CA_NOT_SUPPORTED;
+#endif
+    return res;
+}
 #endif
 
 #define MAX_TCP_SOCK_COUNT 4
@@ -180,7 +209,7 @@ CAResult_t CATCPCreateMutex()
 {
     if (!g_mutexObjectList)
     {
-        g_mutexObjectList = oc_mutex_new();
+        g_mutexObjectList = oc_mutex_new_recursive();
         if (!g_mutexObjectList)
         {
             OIC_LOG(ERROR, TAG, "Failed to create mutex!");
@@ -349,7 +378,8 @@ static void CAFindReadyMessage()
     else if (ret == 0)
     {
         usleep(1000); /* some of the fields are not set by kernel on repeatedly calling
-                         poll.Applying a timeout will solve this*/
+                         poll.Applying a sleep will solve this by providing a delay between
+                         each subsequent poll system call */
     }
     else if (ret < 0)
     {
@@ -719,11 +749,15 @@ static void CAReceiveMessage(int fd)
         len = recv(fd, svritem->tlsdata + svritem->tlsLen, nbRead, 0);
         if (len < 0)
         {
-            OIC_LOG_V(ERROR, TAG, "recv failed %s", strerror(errno));
+            g_lastErrorCode = errno;
+            OIC_LOG_V(DEBUG, TAG, "Set g_lastErrorCode to %s", strerror(g_lastErrorCode));
+            OIC_LOG_V(ERROR, TAG, "recv failed %s", strerror(g_lastErrorCode));
             res = CA_RECEIVE_FAILED;
         }
         else if (0 == len)
         {
+            g_lastErrorCode = 0;
+            OIC_LOG(DEBUG, TAG, "Set g_lastErrorCode to 0");
             OIC_LOG(INFO, TAG, "Received disconnect from peer. Close connection");
             svritem->state = DISCONNECTED;
             res = CA_DESTINATION_DISCONNECTED;
@@ -771,11 +805,15 @@ static void CAReceiveMessage(int fd)
         len = recv(fd, svritem->tlsdata, TLS_DATA_MAX_SIZE, 0);
         if (len < 0)
         {
-            OIC_LOG_V(ERROR, TAG, "recv failed %s", strerror(errno));
+            g_lastErrorCode = errno;
+            OIC_LOG_V(DEBUG, TAG, "Set g_lastErrorCode to %s", strerror(g_lastErrorCode));
+            OIC_LOG_V(ERROR, TAG, "recv failed %s", strerror(g_lastErrorCode));
             res = CA_RECEIVE_FAILED;
         }
         else if (0 == len)
         {
+            g_lastErrorCode = 0;
+            OIC_LOG_V(DEBUG, TAG, "Set g_lastErrorCode to 0");
             OIC_LOG(INFO, TAG, "Received disconnect from peer. Close connection");
             res = CA_DESTINATION_DISCONNECTED;
         }
@@ -877,6 +915,54 @@ static CAResult_t CATCPConvertNameToAddr(int family, const char *host, uint16_t
 }
 
 #if defined(__TIZEN__)
+static char * CATCPGetInterfaceAddr()
+{
+    struct ifaddrs *ifaddr, *ifa;
+    int family, s, n;
+    char *host = (uint8_t *)OICMalloc(NI_MAXHOST);
+
+    if (getifaddrs(&ifaddr) == -1)
+    {
+        OIC_LOG_V(ERROR, TAG, "getifaddrs failed: errno %s", strerror(errno));
+        OICFree(host);
+        return NULL;
+    }
+
+    for (ifa = ifaddr, n = 0; ifa != NULL; ifa = ifa->ifa_next, n++)
+    {
+        if (ifa->ifa_addr == NULL)
+            continue;
+
+        family = ifa->ifa_addr->sa_family;
+        OIC_LOG_V(DEBUG, TAG,"Interface name: %s",ifa->ifa_name);
+
+        if ((strncmp(g_interfaceName,ifa->ifa_name,strlen(ifa->ifa_name))==0)
+            && (family == AF_INET || family == AF_INET6))
+        {
+            s = getnameinfo(ifa->ifa_addr, (family == AF_INET) ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6),
+                                        host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
+            if (s != 0)
+            {
+                OIC_LOG_V(ERROR, TAG, "getnameinfo failed: errno %s", strerror(errno));
+                freeifaddrs(ifaddr);
+                OICFree(host);
+                return NULL;
+            }
+
+            OIC_LOG_V(DEBUG, TAG, "Interface address: %s", host);
+            freeifaddrs(ifaddr);
+            return host;
+        }
+    }
+
+    freeifaddrs(ifaddr);
+    OICFree(host);
+    OIC_LOG(ERROR, TAG, "Interface address not found");
+    return NULL;
+}
+#endif
+
+#if defined(__TIZEN__)
 static int CAGetHTTPStatusCode(char * response) {
     char *resp, *code_plus, *ptrSave;
     int ret = -1;
@@ -933,6 +1019,43 @@ static CAResult_t CATCPCreateSocket(int family, CATCPSessionInfo_t *svritem)
         socklen = sizeof(struct sockaddr_in);
     }
 
+#if defined(__TIZEN__)
+    if (caglobals.tcp.bindenabled)
+    {
+        char *host_address = CATCPGetInterfaceAddr();
+        if (host_address)
+        {
+            if (sa.ss_family == AF_INET)
+            {
+                struct sockaddr_in client;
+                memset(&client, 0x00, sizeof(client));
+                client.sin_family = AF_INET;
+                inet_pton(AF_INET, host_address, &(client.sin_addr.s_addr));
+                if (-1 == bind(fd, (struct sockaddr *)&client, socklen))
+                {
+                    OIC_LOG_V(ERROR, TAG, "bind socket failed: %s", strerror(errno));
+                    OICFree(host_address);
+                    return CA_SOCKET_OPERATION_FAILED;
+                }
+            }
+            else
+            {
+                struct sockaddr_in6 client6;
+                memset(&client6, 0x00, sizeof(client6));
+                client6.sin6_family = AF_INET6;
+                inet_pton(AF_INET6, host_address, &client6.sin6_addr.s6_addr);
+                if (-1 == bind(fd, (struct sockaddr *)&client6, socklen))
+                {
+                    OIC_LOG_V(ERROR, TAG, "bind socket failed: %s", strerror(errno));
+                    OICFree(host_address);
+                    return CA_SOCKET_OPERATION_FAILED;
+                }
+            }
+            OICFree(host_address);
+        }
+    }
+#endif
+
     // #4. connect to remote server device.
     if (connect(fd, (struct sockaddr *)&sa, socklen) < 0)
     {
@@ -960,7 +1083,7 @@ static CAResult_t CATCPCreateSocket(int family, CATCPSessionInfo_t *svritem)
     if(cloud_address && *cloud_address)
     {
         char message[4096];
-        int len = sprintf(message,
+        int len = snprintf(message, 4096,
                 "CONNECT %s HTTP/1.1\r\n"
                 "Host: %s\r\n\r\n", cloud_address, cloud_address
         );
@@ -1391,11 +1514,13 @@ static ssize_t sendData(const CAEndpoint_t *endpoint, const void *data,
 #endif
         if (-1 == len)
         {
-            if (EWOULDBLOCK != errno && EAGAIN != errno)
+            g_lastErrorCode = errno;
+            OIC_LOG_V(DEBUG, TAG, "Set g_lastErrorCode to %s", strerror(g_lastErrorCode));
+            if (EWOULDBLOCK != g_lastErrorCode && EAGAIN != g_lastErrorCode)
             {
-                OIC_LOG_V(ERROR, TAG, "unicast ipv4tcp sendTo failed: %s", strerror(errno));
+                OIC_LOG_V(ERROR, TAG, "unicast ipv4tcp sendTo failed: %s", strerror(g_lastErrorCode));
                 CALogSendStateInfo(endpoint->adapter, endpoint->addr, endpoint->port,
-                                   len, false, strerror(errno));
+                                   len, false, strerror(g_lastErrorCode));
                 return len;
             }
 
@@ -1775,3 +1900,120 @@ void CATCPSetErrorHandler(CATCPErrorHandleCallback errorHandleCallback)
 {
     g_tcpErrorHandler = errorHandleCallback;
 }
+
+CAResult_t CASetKeepAlive(const CAEndpoint_t *endpoint, int time, int cnt, int intvl)
+{
+    OIC_LOG(INFO, TAG, "IN - CATCPSetKeepAlive");
+
+    VERIFY_NON_NULL(endpoint, TAG, "endpoint is NULL");
+
+    size_t index = 0;
+    bool revertKeepAliveSetting = false;
+    CAResult_t result = CA_STATUS_OK;
+    oc_mutex_lock(g_mutexObjectList);
+    CATCPSessionInfo_t *svritem = CAGetTCPSessionInfoFromEndpoint(endpoint, &index);
+    if (!svritem)
+    {
+        // There is no connection with the given endpoint, so the parameter is considered to be invalid.
+        result = CA_STATUS_INVALID_PARAM;
+        goto exit;
+    }
+
+    if (svritem->fd < 0 || svritem->state != CONNECTED)
+    {
+        result = CA_DESTINATION_DISCONNECTED;
+        goto exit;
+    }
+
+    int option = 1;
+    if (-1 == setsockopt(svritem->fd, SOL_SOCKET, SO_KEEPALIVE, &option, sizeof(option)))
+    {
+        OIC_LOG_V(ERROR, TAG, "setsockopt SO_KEEPALIVE failed on socket(%d): %s",
+            svritem->fd, strerror(errno));
+        result = CA_SOCKET_OPERATION_FAILED;
+        goto exit;
+    }
+
+    if (-1 == setsockopt(svritem->fd, SOL_TCP, TCP_KEEPIDLE, &time, sizeof(time)))
+    {
+        OIC_LOG_V(ERROR, TAG, "setsockopt TCP_KEEPIDLE failed on socket(%d): %s",
+            svritem->fd, strerror(errno));
+        revertKeepAliveSetting = true;
+        result = CA_SOCKET_OPERATION_FAILED;
+        goto exit;
+    }
+
+    if (-1 == setsockopt(svritem->fd, SOL_TCP, TCP_KEEPCNT, &cnt, sizeof(cnt)))
+    {
+        OIC_LOG_V(ERROR, TAG, "setsockopt TCP_KEEPCNT failed on socket(%d): %s",
+            svritem->fd, strerror(errno));
+        revertKeepAliveSetting = true;
+        result = CA_SOCKET_OPERATION_FAILED;
+        goto exit;
+    }
+
+    if (-1 == setsockopt(svritem->fd, SOL_TCP, TCP_KEEPINTVL, &intvl, sizeof(intvl)))
+    {
+        OIC_LOG_V(ERROR, TAG, "setsockopt TCP_KEEPINTVL failed on socket(%d): %s",
+            svritem->fd, strerror(errno));
+        revertKeepAliveSetting = true;
+        result = CA_SOCKET_OPERATION_FAILED;
+    }
+
+exit:
+    if (revertKeepAliveSetting)
+    {
+        // Unset SO_KEEPALIVE
+        option = 0;
+        if (-1 == setsockopt(svritem->fd, SOL_SOCKET, SO_KEEPALIVE, &option, sizeof(option)))
+        {
+            OIC_LOG_V(ERROR, TAG, "unset SO_KEEPALIVE failed on socket(%d): %s",
+                svritem->fd, strerror(errno));
+        }
+    }
+    oc_mutex_unlock(g_mutexObjectList);
+    OIC_LOG(INFO, TAG, "OUT - CATCPSetKeepAlive");
+    return result;
+}
+
+CAResult_t CAUnSetKeepAlive(const CAEndpoint_t *endpoint)
+{
+    OIC_LOG(INFO, TAG, "IN - CATCPUnSetKeepAlive");
+
+    VERIFY_NON_NULL(endpoint, TAG, "endpoint is NULL");
+
+    size_t index = 0;
+    CAResult_t result = CA_STATUS_OK;
+    oc_mutex_lock(g_mutexObjectList);
+    CATCPSessionInfo_t *svritem = CAGetTCPSessionInfoFromEndpoint(endpoint, &index);
+    if (!svritem)
+    {
+        // There is no connection with the given endpoint, so the parameter is considered to be invalid.
+        result = CA_STATUS_INVALID_PARAM;
+        goto exit;
+    }
+
+    if (svritem->fd < 0 || svritem->state != CONNECTED)
+    {
+        result = CA_DESTINATION_DISCONNECTED;
+        goto exit;
+    }
+
+    int option = 0;
+    if (-1 == setsockopt(svritem->fd, SOL_SOCKET, SO_KEEPALIVE, &option, sizeof(option)))
+    {
+        OIC_LOG_V(ERROR, TAG, "setsockopt SO_KEEPALIVE failed on socket(%d): %s",
+            svritem->fd, strerror(errno));
+        result = CA_SOCKET_OPERATION_FAILED;
+    }
+
+exit:
+    oc_mutex_unlock(g_mutexObjectList);
+    OIC_LOG(INFO, TAG, "OUT - CATCPUnSetKeepAlive");
+    return result;
+}
+
+int CAGetLastErrorCode()
+{
+    return g_lastErrorCode;
+}
index 0a03b11..c8a11bb 100644 (file)
@@ -550,4 +550,23 @@ CAResult_t CAGetTCPIPHeader(CATransportAdapter_t adapter, int flag, TCPHeaderInf
 #endif
     return res;
 }
+
+CAResult_t CASetTCPKeepAlive(const CAEndpoint_t *endpoint, int time, int cnt, int intvl)
+{
+    OIC_LOG(DEBUG, TAG, "CASetTCPKeepAlive");
+    return CATCPSetKeepAlive(endpoint, time, cnt, intvl);
+}
+
+CAResult_t CAUnSetTCPKeepAlive(const CAEndpoint_t *endpoint)
+{
+    OIC_LOG(DEBUG, TAG, "CAUnSetTCPKeepAlive");
+    return CATCPUnSetKeepAlive(endpoint);
+}
+
+int CAGetTCPLastErrorCode()
+{
+    OIC_LOG(DEBUG, TAG, "CAGetTCPLastErrorCode");
+    return CATCPGetLastErrorCode();
+}
+
 #endif
index 81f460a..3eac404 100644 (file)
@@ -245,7 +245,7 @@ OCStackResult RMPParseResponsePayload(const OCRepPayload *payload, uint32_t *gat
     OCRepPayloadGetPropInt(payload, GATEWAY, &tempGateway);
     *gatewayId = tempGateway;
 
-    if (NULL == gatewayId || 0 == *gatewayId)
+    if (0 == *gatewayId)
     {
         return OC_STACK_COMM_ERROR;
     }
index 4eb8501..f949c62 100644 (file)
@@ -1210,7 +1210,7 @@ OCStackResult RTMRemoveInvalidGateways(u_linklist_t **invalidTable, u_linklist_t
             for (uint32_t i = 0; i < u_arraylist_length(entry->destination->destIntfAddr); i++)
             {
                 RTMDestIntfInfo_t *destCheck = u_arraylist_get(entry->destination->destIntfAddr, i);
-                if (!destCheck && !destCheck->isValid)
+                if (destCheck && !destCheck->isValid)
                 {
                     void *data = u_arraylist_remove(entry->destination->destIntfAddr, i);
                     OICFree(data);
index de7781a..4757e1f 100644 (file)
@@ -224,7 +224,7 @@ OCStackResult RMUpdateInfo(CAHeaderOption_t **options, uint8_t *numOptions,
     RM_NULL_CHECK_WITH_RET(numOptions, TAG, "numOptions");
     RM_NULL_CHECK_WITH_RET(endpoint, TAG, "endpoint");
 
-    if (0 >= *numOptions)
+    if (0 == *numOptions)
     {
         OIC_LOG(ERROR, TAG, "Invalid arguement: numOptions");
         return OC_STACK_ERROR;
index 1000f86..f0d8022 100644 (file)
@@ -108,6 +108,12 @@ OCStackResult GetDoxmDeviceID(OicUuid_t *deviceID);
  */
 OCStackResult SetDoxmDeviceID(const OicUuid_t *deviceID);
 
+/**
+ * This method sets the device ID for reset profile in PS.
+ * This workaround api related to issue with 0x0 starting Uuid details in [CONPRO-1516].
+ * @return ::OC_STACK_OK for Success, otherwise some error value.
+ */
+OCStackResult SetDoxmDeviceIDResetPF(const OicUuid_t *deviceID);
 
 /**
  * Gets the OicUuid_t value for the owner of this device.
index ae228bf..73bc90e 100644 (file)
@@ -152,4 +152,10 @@ void DeinitPersistentStorageInterface(void);
 OCStackResult setSecurePSI(const unsigned char *key, const OCPersistentStorage *psPlain,
         const OCPersistentStorage *psEnc, const OCPersistentStorage *psRescue);
 
+/**
+ *
+ * @return pointer on resetSVRDB structure for manipulating with callback
+ */
+resetSVRDBCB_t* const GetResetSVRDBCB(void);
+
 #endif //IOTVT_SRM_PSI_H
index 483afa2..b27d8ec 100644 (file)
@@ -449,6 +449,19 @@ OCStackResult OCResetDevice(void *ctx, unsigned short waitTimeForOwnedDeviceDisc
 OCStackResult OCResetSVRDB(void);\r
 \r
 /**\r
+ * The function registers callback, for getting notification if SVR DB was reseted.\r
+ *\r
+ * @param[in] ResetSVRDBCB notifier callback function.\r
+ * @return OC_STACK_OK in case of success and other value otherwise.\r
+ */\r
+OCStackResult OCRegisterResetSVRDBNotifier(ResetSVRDBCB callback);\r
+\r
+/**\r
+ * The function unregisters ResetSVRDBCB notification callback.\r
+ */\r
+void OCUnregisterResetSVRDBNotifier(void);\r
+\r
+/**\r
  * This function configures SVR DB as self-ownership.\r
  *\r
  *@return OC_STACK_OK in case of successful configue and other value otherwise.\r
index a46843f..7453a82 100644 (file)
@@ -934,6 +934,44 @@ OCStackResult OCResetSVRDB(void)
 }
 
 /**
+ * This function to register callback, for getting notification if SVR DB was reseted.
+ * @param[in] ResetSVRDBCB notifier callback function.
+ * @return OC_STACK_OK in case of successful reset and other value otherwise.
+ */
+
+OCStackResult OCRegisterResetSVRDBNotifier(ResetSVRDBCB callback)
+{
+    OIC_LOG_V(INFO, TAG, "IN %s", __func__);
+
+    if(NULL != GetResetSVRDBCB()->callback)
+    {
+        OIC_LOG_V(ERROR, TAG,"%s Can't register notifier callback, unregister previous one!" ,__func__);
+        return OC_STACK_ERROR;
+    }
+
+    GetResetSVRDBCB()->callback = callback;
+
+    OIC_LOG_V(INFO, TAG, "Out %s", __func__);
+    return OC_STACK_OK;
+}
+
+
+/**
+ * This function to unregister ResetSVRDBCB notification callback.
+ */
+void OCUnregisterResetSVRDBNotifier(void)
+{
+    OIC_LOG_V(INFO, TAG, "IN %s", __func__);
+
+    if(NULL != GetResetSVRDBCB()->callback)
+    {
+        GetResetSVRDBCB()->callback = NULL;
+    }
+
+    OIC_LOG_V(INFO, TAG, "Out %s", __func__);
+}
+
+/**
  * This function configures SVR DB as self-ownership.
  *
  *@return OC_STACK_OK in case of successful configue and other value otherwise.
index 40aab22..e455f13 100644 (file)
@@ -2035,8 +2035,7 @@ static OCEntityHandlerResult HandlePostRequest(OCEntityHandlerRequest * ehReques
                             InvokeOtmEventHandler(ehRequest->devAddr.addr, ehRequest->devAddr.port,
                                                   NULL, OIC_OTM_ERROR);
 #endif
-                            RestoreDoxmToInitState();
-                            RestorePstatToInitState();
+                            ResetSecureResourceInPS();
                             OIC_LOG(WARNING, TAG, "DOXM will be reverted.");
                         }
                     }
index d8b4506..c7362fb 100644 (file)
@@ -736,6 +736,156 @@ static bool UpdatePersistentStorage(OicSecDoxm_t * doxm)
     return bRet;
 }
 
+OCStackResult SetDoxmDeviceIDResetPF(const OicUuid_t *deviceID)
+{
+    OIC_LOG_V(DEBUG, TAG, "In %s", __func__);
+
+    OCStackResult res = OC_STACK_ERROR;
+    size_t dbSize = 0;
+    uint8_t *dbData = NULL;
+    uint8_t *aclCbor = NULL;
+    uint8_t *credCbor = NULL;
+    uint8_t *pstatCbor = NULL;
+    uint8_t *doxmCbor = NULL;
+    uint8_t *resetPfCbor = NULL;
+    int64_t cborEncoderResult = CborNoError;
+
+    if (NULL == deviceID)
+    {
+        OIC_LOG_V(ERROR, TAG, "%s - deviceID is NULL!", __func__);
+        return res;
+    }
+
+    res = GetSecureVirtualDatabaseFromPS(NULL, &dbData, &dbSize);
+    if (OC_STACK_OK != res)
+    {
+        OIC_LOG_V(ERROR, TAG, "GetSecureVirtualDatabaseFromPS() is failed(%d)", res);
+        return res;
+    }
+    if (dbData && dbSize)
+    {
+        size_t aclCborLen = 0;
+        size_t credCborLen = 0;
+        size_t pstatCborLen = 0;
+        size_t doxmCborLen = 0;
+        size_t resetPfCborLen = 0;
+        OicSecDoxm_t *tmpDoxm = NULL;
+
+        {
+            CborParser parser;
+            CborValue cbor;
+            cbor_parser_init(dbData, dbSize, 0, &parser, &cbor);
+            CborValue curVal = {0};
+            CborError cborFindResult = CborNoError;
+
+            // abort if reset profile doesn't exist
+            cborFindResult = cbor_value_map_find_value(&cbor, OIC_JSON_RESET_PF_NAME, &curVal);
+            if (CborNoError != cborFindResult || !cbor_value_is_byte_string(&curVal))
+            {
+                OIC_LOG(DEBUG, TAG, "Reset Profile doesn't exist!");
+                res=OC_STACK_ERROR;
+                goto exit;
+            }
+            cborFindResult = cbor_value_map_find_value(&cbor, OIC_JSON_ACL_NAME, &curVal);
+            if (CborNoError == cborFindResult && cbor_value_is_byte_string(&curVal))
+            {
+                cborFindResult = cbor_value_dup_byte_string(&curVal, &aclCbor, &aclCborLen, NULL);
+                VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding ACL Name Value.");
+            }
+            cborFindResult = cbor_value_map_find_value(&cbor, OIC_JSON_CRED_NAME, &curVal);
+            if (CborNoError == cborFindResult && cbor_value_is_byte_string(&curVal))
+            {
+                cborFindResult = cbor_value_dup_byte_string(&curVal, &credCbor, &credCborLen, NULL);
+                VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding CRED Name Value.");
+            }
+            cborFindResult = cbor_value_map_find_value(&cbor, OIC_JSON_PSTAT_NAME, &curVal);
+            if (CborNoError == cborFindResult && cbor_value_is_byte_string(&curVal))
+            {
+                cborFindResult = cbor_value_dup_byte_string(&curVal, &pstatCbor, &pstatCborLen, NULL);
+                VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding PSTAT Name Value.");
+            }
+            cborFindResult = cbor_value_map_find_value(&cbor, OIC_JSON_DOXM_NAME, &curVal);
+            if (CborNoError == cborFindResult && cbor_value_is_byte_string(&curVal))
+            {
+                cborFindResult = cbor_value_dup_byte_string(&curVal, &doxmCbor, &doxmCborLen, NULL);
+                VERIFY_CBOR_SUCCESS(TAG, cborFindResult,  "Failed Finding DOXM Name Value.");
+
+                res = CBORPayloadToDoxm(doxmCbor, doxmCborLen, &tmpDoxm);
+                if (OC_STACK_OK != res)
+                {
+                    OIC_LOG_V(ERROR, TAG, "%s - CBORPayloadToDoxm error : %d", __func__, res);
+                    goto exit;
+                }
+                VERIFY_NON_NULL(TAG, tmpDoxm, ERROR);
+                memcpy(tmpDoxm->deviceID.id, deviceID->id, sizeof(deviceID->id));
+                OICFree(doxmCbor);
+                doxmCbor = NULL;
+                doxmCborLen = 0;
+                res = DoxmToCBORPayload(tmpDoxm, &doxmCbor, &doxmCborLen, false);
+                if (OC_STACK_OK != res || 0 == doxmCborLen || NULL == doxmCbor)
+                {
+                    OIC_LOG_V(ERROR, TAG,"%s - DoxmToCBORPayload error : %d", __func__, res);
+                    goto exit;
+                }
+            }
+        }
+
+        {
+            size_t size = aclCborLen + credCborLen + pstatCborLen + doxmCborLen + 255;
+            resetPfCbor = (uint8_t *) OICCalloc(1, size);
+            VERIFY_NON_NULL(TAG, resetPfCbor, ERROR);
+            CborEncoder encoder;  // will be initialized in |cbor_parser_init|
+            cbor_encoder_init(&encoder, resetPfCbor, size, 0);
+            CborEncoder secRsrc;  // will be initialized in |cbor_encoder_create_map|
+            cborEncoderResult |= cbor_encoder_create_map(&encoder, &secRsrc, CborIndefiniteLength);
+
+            cborEncoderResult |= cbor_encode_text_string(&secRsrc, OIC_JSON_ACL_NAME, strlen(OIC_JSON_ACL_NAME));
+            VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding ACL Name.");
+            cborEncoderResult |= cbor_encode_byte_string(&secRsrc, aclCbor, aclCborLen);
+            VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding ACL Value.");
+
+            if (credCborLen)
+            {
+                cborEncoderResult |= cbor_encode_text_string(&secRsrc, OIC_JSON_CRED_NAME, strlen(OIC_JSON_CRED_NAME));
+                VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding CRED Name.");
+                cborEncoderResult |= cbor_encode_byte_string(&secRsrc, credCbor, credCborLen);
+                VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding CRED Value.");
+            }
+
+            cborEncoderResult |= cbor_encode_text_string(&secRsrc, OIC_JSON_PSTAT_NAME, strlen(OIC_JSON_PSTAT_NAME));
+            VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding PSTAT Name.");
+            cborEncoderResult |= cbor_encode_byte_string(&secRsrc, pstatCbor, pstatCborLen);
+            VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding PSTAT Value.");
+
+            cborEncoderResult |= cbor_encode_text_string(&secRsrc, OIC_JSON_DOXM_NAME, strlen(OIC_JSON_DOXM_NAME));
+            VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding Doxm Name.");
+            cborEncoderResult |= cbor_encode_byte_string(&secRsrc, doxmCbor, doxmCborLen);
+            VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding Doxm Value.");
+
+            cborEncoderResult |= cbor_encoder_close_container(&encoder, &secRsrc);
+            VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Closing Array.");
+            resetPfCborLen = cbor_encoder_get_buffer_size(&encoder, resetPfCbor);
+        }
+
+        res = UpdateSecureResourceInPS(OIC_JSON_RESET_PF_NAME, resetPfCbor, resetPfCborLen);
+        if (OC_STACK_OK != res)
+        {
+            OIC_LOG_V(ERROR, TAG, "%s - Error in UpdateSecureResourceInPS", __func__);
+        }
+    }
+    OIC_LOG_V(DEBUG, TAG, "Out %s", __func__);
+
+exit:
+    OICFree(dbData);
+    OICFree(aclCbor);
+    OICFree(credCbor);
+    OICFree(pstatCbor);
+    OICFree(doxmCbor);
+    OICFree(resetPfCbor);
+
+    return res;
+}
+
 static bool ValidateQuery(const char * query)
 {
     // Send doxm resource data if the state of doxm resource
@@ -2226,9 +2376,12 @@ OCStackResult GetDoxmDeviceID(OicUuid_t *deviceID)
 
 OCStackResult GetDoxmIsOwned(bool *isOwned)
 {
+    OIC_LOG_V(INFO, TAG, "In %s", __func__);
     if (isOwned && gDoxm)
     {
-       *isOwned = gDoxm->owned;
+        *isOwned = gDoxm->owned;
+        OIC_LOG_V(INFO, TAG, "isOwned - %s", *isOwned ? "true" : "false");
+        OIC_LOG_V(INFO, TAG, "Out %s", __func__);
         return OC_STACK_OK;
     }
     return OC_STACK_ERROR;
index e38fc38..649ba6e 100644 (file)
@@ -76,17 +76,15 @@ static bool UuidCmp(OicUuid_t *firstId, OicUuid_t *secondId)
     // TODO use VERIFY macros to check for null when they are merged.
     if(NULL == firstId || NULL == secondId)
     {
+        OIC_LOG_V(ERROR, TAG, "%s - %s is NULL",__func__, firstId ? "secondId" : "firstId");
         return false;
     }
-    // Check empty uuid string
-    if('\0' == firstId->id[0] || '\0' == secondId->id[0])
-    {
-        return false;
-    }
+
     for(int i = 0; i < UUID_LENGTH; i++)
     {
         if(firstId->id[i] != secondId->id[i])
         {
+            OIC_LOG_V(ERROR, TAG, "%s - Uuids are not equal " ,__func__);
             return false;
         }
     }
@@ -132,6 +130,7 @@ static bool IsRequestFromDevOwner(PEContext_t *context)
 
     if(NULL == context)
     {
+        OIC_LOG_V(ERROR, TAG, "%s: context is NULL", __func__);
         return retVal;
     }
 
@@ -147,7 +146,21 @@ static bool IsRequestFromDevOwner(PEContext_t *context)
     if (doxm)
     {
         retVal = UuidCmp(&doxm->owner, &context->subject);
+        char *strUuid = NULL;
+        ConvertUuidToStr(&doxm->owner, &strUuid);
+        OIC_LOG_V(ERROR, TAG, "%s: Owner UUID: %s", __func__, strUuid ? strUuid : "NULL");
+        OICFree(strUuid);
+
+        strUuid = NULL;
+        ConvertUuidToStr(&context->subject, &strUuid);
+        OIC_LOG_V(ERROR, TAG, "%s: Context subject: %s", __func__, strUuid ? strUuid : "NULL");
+        OICFree(strUuid);
     }
+    else
+    {
+        OIC_LOG_V(ERROR, TAG, "%s: doxm is NULL", __func__);
+    }
+    OIC_LOG_V(INFO, TAG, "%s: return val: %s", __func__, retVal ? "True" : "False");
     return retVal;
 }
 
@@ -554,6 +567,8 @@ SRMAccessResponse_t CheckPermission(PEContext_t     *context,
                                     const char      *resource,
                                     const uint16_t  requestedPermission)
 {
+    OIC_LOG_V(INFO, TAG, "In %s", __func__);
+
     SRMAccessResponse_t retVal = ACCESS_DENIED_POLICY_ENGINE_ERROR;
 
     VERIFY_NON_NULL(TAG, context, ERROR);
@@ -577,6 +592,9 @@ SRMAccessResponse_t CheckPermission(PEContext_t     *context,
         // AND c) the request is for a SVR resource.
         // If all 3 conditions are met, grant request.
         bool isDeviceOwned = true; // default to value that will not grant access
+        OIC_LOG_V(INFO, TAG, "IsRequestFromDevOwner - %s", IsRequestFromDevOwner(context) ? "true" : "false");
+        OIC_LOG_V(INFO, TAG, "Pstat IsOp - %s", GetPstatIsop() ? "true" : "false");
+
         if (OC_STACK_OK != GetDoxmIsOwned(&isDeviceOwned)) // if runtime error, don't grant
         {
             context->retVal = ACCESS_DENIED_POLICY_ENGINE_ERROR;
@@ -667,6 +685,8 @@ SRMAccessResponse_t CheckPermission(PEContext_t     *context,
     }
 
 exit:
+    OIC_LOG_V(INFO, TAG, "context->retVal - %d", retVal);
+    OIC_LOG_V(INFO, TAG, "Out %s", __func__);
     return retVal;
 }
 
index baba287..d6474ab 100644 (file)
@@ -59,6 +59,12 @@ static oc_mutex g_mutexDb = NULL;
 // Persistent Storage status
 static PSStatus_t g_psStatus = PS_NO_EXTERNAL_DB_SET;
 
+static resetSVRDBCB_t g_resetSVRDBCB = {0};
+
+resetSVRDBCB_t* const GetResetSVRDBCB(void)
+{
+    return &g_resetSVRDBCB;
+}
 /**
  * Update the Persistent Storage Database size.
  */
@@ -1058,6 +1064,16 @@ exit:
     OICFree(pstatCbor);
     OICFree(doxmCbor);
     OICFree(resetPfCbor);
+
+    if (NULL != g_resetSVRDBCB.callback)
+    {
+        g_resetSVRDBCB.callback(ret);
+    }
+    else
+    {
+        OIC_LOG_V(DEBUG, TAG, "%s - Notifier resetSVRDB callback isn't registered.", __func__);
+    }
+
     return ret;
 }
 
index 1b8cd21..686cb2c 100644 (file)
@@ -26,6 +26,7 @@
 #include "oic_malloc.h"
 #include "oic_string.h"
 #include "base64.h"
+#include "psinterface.h"
 #include "doxmresource.h"
 #include "credresource.h"
 #include "pstatresource.h"
@@ -320,9 +321,8 @@ static void DTLSHandshakeServerCB(const CAEndpoint_t *endpoint, const CAErrorInf
             if (CA_STATUS_OK != info->result)
             {
                 OIC_LOG(ERROR, TAG, "Failed to establish a secure session with owner device.");
-                OIC_LOG(ERROR, TAG, "Doxm/Pstat resource will be reverted to init state.");
-                RestoreDoxmToInitState();
-                RestorePstatToInitState();
+                ResetSecureResourceInPS();
+                OIC_LOG(INFO, TAG, "Secure Resources reverted.");
                 InvokeOtmEventHandler(endpoint->addr, endpoint->port, NULL, OIC_OTM_ERROR);
             }
         }
index a1f5cd2..0ebe590 100755 (executable)
@@ -764,6 +764,14 @@ OCStackResult OCGetDeviceId(OCUUIdentity *deviceId);
  */
 OCStackResult OCSetDeviceId(const OCUUIdentity *deviceId);
 
+/**
+ * sets the Doxm deviceId for ResetPF in PS
+ *
+ * @param deviceId pointer.
+ * @return Returns ::OC_STACK_OK if success.
+ */
+OCStackResult OCSetDeviceIdResetPF(const OCUUIdentity *deviceId);
+
  /**
  * Gets the bool state of "isOwned" property on the doxm resource.
  *
index 8187b88..128470c 100644 (file)
@@ -1772,6 +1772,21 @@ typedef enum
 typedef void (*OCOtmEventHandler)(void *ctx, const char *addr, uint16_t port,
         const char *ownerId, OCOtmEvent_t event);
 
+/**
+ * Callback function for notification SVR DB was reseted.
+ *
+ * @param[in] result of OCResetSVRDB API call
+ */
+typedef void (*ResetSVRDBCB)(OCStackResult result);
+
+/**
+ * resetSVRDBCB structure.
+ */
+typedef struct resetSVRDBCB
+{
+    ResetSVRDBCB callback;
+} resetSVRDBCB_t;
+
 #ifdef __cplusplus
 }
 #endif // __cplusplus
index 82f46ce..b616f41 100755 (executable)
@@ -200,7 +200,6 @@ void DeleteClientCB(ClientCB * cbNode)
         }
 #endif // WITH_PRESENCE
         OICFree(cbNode);
-        cbNode = NULL;
     }
     OIC_TRACE_END();
 }
index bba4dd1..bf82aa2 100644 (file)
@@ -618,7 +618,7 @@ OCStackResult DetermineResourceHandling (const OCServerRequest *request,
             return OC_STACK_NO_RESOURCE;
         }
 
-        if (resourcePtr && resourcePtr->rsrcChildResourcesHead != NULL)
+        if (resourcePtr->rsrcChildResourcesHead != NULL)
         {
             // Collection resource
             if (resourcePtr->entityHandler != defaultResourceEHandler)
index aa5930b..3ebd62b 100644 (file)
@@ -105,7 +105,6 @@ static void DeleteServerRequest(OCServerRequest * serverRequest)
         OICFree(serverRequest->requestToken);
         OICFree(serverRequest->rcvdVendorSpecificHeaderOptions);
         OICFree(serverRequest);
-        serverRequest = NULL;
         OIC_LOG(INFO, TAG, "Server Request Removed!!");
     }
 }
index 5f94a12..c5b6fd3 100644 (file)
@@ -64,6 +64,7 @@
 #include "camessagehandler.h"
 #include "oicgroup.h"
 #include "pstatresource.h"
+#include "srmutility.h"
 
 #if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
 #include "routingutility.h"
@@ -5369,42 +5370,39 @@ OCStackResult OCUpdateResourceInsWithResponse(const char *requestUri,
         if (strcmp(rdPubUri, targetUri) == 0)
         {
             // Update resource unique id in stack.
-            if (response)
+            if (response->payload)
             {
-                if (response->payload)
+                OCRepPayload *rdPayload = (OCRepPayload *) response->payload;
+                OCRepPayload **links = NULL;
+                size_t dimensions[MAX_REP_ARRAY_DEPTH] = { 0 };
+                if (OCRepPayloadGetPropObjectArray(rdPayload, OC_RSRVD_LINKS,
+                                                   &links, dimensions))
                 {
-                    OCRepPayload *rdPayload = (OCRepPayload *) response->payload;
-                    OCRepPayload **links = NULL;
-                    size_t dimensions[MAX_REP_ARRAY_DEPTH] = { 0 };
-                    if (OCRepPayloadGetPropObjectArray(rdPayload, OC_RSRVD_LINKS,
-                                                       &links, dimensions))
+                    size_t i = 0;
+                    for (; i < dimensions[0]; i++)
                     {
-                        size_t i = 0;
-                        for (; i < dimensions[0]; i++)
+                        char *uri = NULL;
+                        if (OCRepPayloadGetPropString(links[i], OC_RSRVD_HREF, &uri))
                         {
-                            char *uri = NULL;
-                            if (OCRepPayloadGetPropString(links[i], OC_RSRVD_HREF, &uri))
+                            OCResourceHandle handle = OCGetResourceHandleAtUri(uri);
+                            int64_t ins = 0;
+                            if (OCRepPayloadGetPropInt(links[i], OC_RSRVD_INS, &ins))
                             {
-                                OCResourceHandle handle = OCGetResourceHandleAtUri(uri);
-                                int64_t ins = 0;
-                                if (OCRepPayloadGetPropInt(links[i], OC_RSRVD_INS, &ins))
-                                {
-                                    OCBindResourceInsToResource(handle, ins);
-                                }
-
-                                OICFree(uri);
-                                uri = NULL;
+                                OCBindResourceInsToResource(handle, ins);
                             }
-                        }
 
-                        // Free links
-                        size_t count = calcDimTotal(dimensions);
-                        for (size_t k = 0; k < count; k++)
-                        {
-                            OCRepPayloadDestroy(links[k]);
+                            OICFree(uri);
+                            uri = NULL;
                         }
-                        OICFree(links);
                     }
+
+                    // Free links
+                    size_t count = calcDimTotal(dimensions);
+                    for (size_t k = 0; k < count; k++)
+                    {
+                        OCRepPayloadDestroy(links[k]);
+                    }
+                    OICFree(links);
                 }
             }
         }
@@ -5643,6 +5641,26 @@ OCStackResult OCSetDeviceId(const OCUUIdentity *deviceId)
     return ret;
 }
 
+OCStackResult OCSetDeviceIdResetPF(const OCUUIdentity *deviceId)
+{
+    OicUuid_t oicUuid;
+    OCStackResult ret = OC_STACK_ERROR;
+
+    memcpy(&oicUuid, deviceId, UUID_LENGTH);
+    char *strUuid = NULL;
+    if (OC_STACK_OK == ConvertUuidToStr(&oicUuid, &strUuid))
+    {
+        OIC_LOG_V(INFO, TAG, "%s: deviceId : %s" ,__func__, strUuid);
+        OICFree(strUuid);
+    }
+    else
+    {
+        OIC_LOG(DEBUG, TAG, "Can't convert  deviceId to string");
+    }
+    ret = SetDoxmDeviceIDResetPF(&oicUuid);
+    return ret;
+}
+
 OCStackResult OCGetDeviceOwnedState(bool *isOwned)
 {
     bool isDeviceOwned = true;
index 61c0eaa..c75220c 100644 (file)
@@ -736,7 +736,7 @@ OCStackResult BuildActionSetFromString(OCActionSet **set, char* actiondesc)
             }
             else
             {
-                if ((key != NULL) && (value != NULL))
+                if (value != NULL)
                 {
                     OIC_LOG(INFO, TAG, "Build OCCapability Instance.");
 
@@ -822,7 +822,7 @@ OCStackResult BuildStringFromActionSet(OCActionSet* actionset, char** desc)
     actionTypeStr = (char *)OICMalloc(1024);
     if(actionTypeStr != NULL)
     {
-        sprintf(actionTypeStr, "%ld %u", actionset->timesteps, actionset->type);
+        snprintf(actionTypeStr, 1024, "%ld %u", actionset->timesteps, actionset->type);
         if(remaining >= strlen(actionTypeStr) + strlen(ACTION_DELIMITER) + 1)
         {
             strncat(temp, actionTypeStr, strlen(actionTypeStr));
@@ -852,11 +852,11 @@ OCStackResult BuildStringFromActionSet(OCActionSet* actionset, char** desc)
             goto exit;
         }
 
-        strcat(temp, "uri=");
+        strncat(temp, "uri=", 4);
         remaining -= strlen("uri=");
-        strcat(temp, action->resourceUri);
+        strncat(temp, action->resourceUri, strlen(action->resourceUri));
         remaining -= strlen(action->resourceUri);
-        strcat(temp, "|");
+        strncat(temp, "|", 1);
         remaining--;
 
         OCCapability *capas = action->head;
@@ -987,6 +987,12 @@ OCStackResult BuildActionJSON(OCAction* action, unsigned char* bufferPtr,
     }
 
     jsonStr = cJSON_PrintUnformatted(json);
+    if (jsonStr == NULL)
+    {
+        OIC_LOG(ERROR, TAG, "cJSON_PrintUnformatted failed");
+        cJSON_Delete(json);
+        return OC_STACK_ERROR;
+    }
 
     jsonLen = strlen(jsonStr);
     if (jsonLen < *remaining)
index 132d082..433d840 100755 (executable)
@@ -962,15 +962,21 @@ namespace OC
         try
         {
             rep = parseGetSetCallback(clientResponse);
+            OIC_LOG_V(DEBUG, TAG, "%s: call response callback", __func__);
+            std::thread exec(context->callback, serverHeaderOptions, rep, result);
+            exec.detach();
         }
         catch(OC::OCException& e)
         {
-            result = e.code();
+            oclog() << "Exception in parseGetSetCallback, ignoring callback: "
+                << e.what() << std::flush;
+        }
+        catch(const std::exception& e)
+        {
+            oclog() << "Exception in thread execution, ignoring callback: "
+                << e.what() << std::flush;
         }
 
-        OIC_LOG_V(DEBUG, TAG, "%s: call response callback", __func__);
-        std::thread exec(context->callback, serverHeaderOptions, rep, result);
-        exec.detach();
         return OC_STACK_DELETE_TRANSACTION;
     }
 
index 1156390..779354e 100755 (executable)
@@ -826,10 +826,9 @@ OCRepPayload* constructResponseOfEasySetup(OCEntityHandlerRequest *ehRequest)
 
     // Requested interface is Link list interface
     //if(ehRequest->query && CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_LL))
-    if(!ehRequest->query ||
-        (ehRequest->query && !strcmp(ehRequest->query, "")) ||
-        (ehRequest->query && CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_LL)) ||
-        (ehRequest->query && CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT)))
+    if (!ehRequest->query || !strcmp(ehRequest->query, "") ||
+        CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_LL) ||
+        CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
     {
         const OCRepPayload *arrayPayload[3] = {NULL};
 
@@ -999,9 +998,8 @@ OCRepPayload* constructResponseOfEasySetup(OCEntityHandlerRequest *ehRequest)
 
         size_t dimensions[MAX_REP_ARRAY_DEPTH] = {childResCnt, 0, 0};
 
-        if(!ehRequest->query ||
-            (ehRequest->query && !strcmp(ehRequest->query, "")) ||
-            (ehRequest->query && CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT)))
+        if(!ehRequest->query || !strcmp(ehRequest->query, "") ||
+            CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
         {
             OIC_LOG(DEBUG, ES_RH_TAG, "constructResponse EasySetup res");
             OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_EASYSETUP);
@@ -1654,10 +1652,8 @@ OCStackResult SetEnrolleeErrCode(ESErrorCode esErrCode)
 
 OCEntityHandlerResult CheckEhRequestPayload(OCEntityHandlerRequest *ehRequest)
 {
-    if( !(ehRequest->query) ||
-                (ehRequest->query &&
-                (strcmp(ehRequest->query, "") && !CompareResourceInterface(ehRequest->query,
-                                                                        OC_RSRVD_INTERFACE_DEFAULT))))
+    if( !ehRequest->query || (strcmp(ehRequest->query, "") &&
+                !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT)))
     {
         OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
         return OC_EH_BAD_REQ;
index d242919..2457c6d 100755 (executable)
@@ -134,12 +134,9 @@ namespace OIC
                         while (iter)
                         {
                             following = iter->next;
-                            if (iter)
-                            {
-                                NSOICFree(iter->topicName);
-                                iter->next = NULL;
-                                NSOICFree(iter);
-                            }
+                            NSOICFree(iter->topicName);
+                            iter->next = NULL;
+                            NSOICFree(iter);
                             iter = following;
                         }
                     }
index 9272cf3..b615608 100755 (executable)
@@ -179,12 +179,9 @@ namespace OIC
                 while (iter)\r
                 {\r
                     following = iter->next;\r
-                    if (iter)\r
-                    {\r
-                        NSOICFree(iter->topicName);\r
-                        iter->next = NULL;\r
-                        NSOICFree(iter);\r
-                    }\r
+                    NSOICFree(iter->topicName);\r
+                    iter->next = NULL;\r
+                    NSOICFree(iter);\r
                     iter = following;\r
                 }\r
             }\r
index 53c62c4..cf2d6ac 100644 (file)
@@ -205,7 +205,6 @@ NSResult NSFreeConsumer(NSConsumer * obj)
     (obj->consumerId)[0] = '\0';
 
     OICFree(obj);
-    obj = NULL;
 
     return NS_OK;
 }
@@ -492,7 +491,7 @@ OCDevAddr * NSChangeAddress(const char * inputaddress)
         address = schema + 2;
     }
     size_t prefixLen = schema - inputaddress;
-    if (prefixLen <= 0)
+    if (prefixLen == 0)
     {
         NS_LOG(ERROR, "Invalid Input address.");
         return NULL;
index 74708df..6c14b61 100644 (file)
@@ -92,10 +92,12 @@ OCStackResult NSProviderPublishTopic(OCRepPayload * payload, OCClientResponseHan
 
     if (!serverInfo)
     {
-        NS_LOG(DEBUG, "serverInfo is not NULL");
-        NS_LOG_V(DEBUG, "serverInfo->serverUri = %s", serverInfo->serverUri);
+        NS_LOG(ERROR, "serverInfo is NULL");
+        return OC_STACK_ERROR;
     }
 
+    NS_LOG_V(DEBUG, "serverInfo->serverUri = %s", serverInfo->serverUri);
+
     NS_LOG(DEBUG, "NSProviderPublishTopic - OUT");
 
     return OCDoResource(NULL, OC_REST_POST, serverInfo->serverUri, serverInfo->devAddr,