-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
commit_info_2019-07-11.txt
-commit_id: 6b31a4840ddceaeb699293dff833353d39901675
+commit_id: 6b31a4840ddceaeb699293dff833353d39901675
---------------------------------------------------------------------------------------------------------------------------------
http://suprem.sec.samsung.net/jira/browse/CONPRO-1456
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.
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;
#define CA_MAX_TOKEN_LEN (8)
/**
+* Max interface name length.
+*/
+#define CA_MAX_INTERFACE_NAME_LEN (16)
+
+/**
* Max URI length.
*/
#ifdef ARDUINO
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;
#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
* @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.
* @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
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.
// 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
// 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
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;
// 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;
if (CA_STATUS_OK != result)
{
OIC_LOG(ERROR, CALEADAPTER_TAG, "CAInitBleServerSenderQueue failed");
-
+
return CA_STATUS_FAILED;
}
oc_mutex_lock(g_senderInfoMutex);
senderInfo->refCount--;
- if(senderInfo->refCount <= 0)
+ if(senderInfo->refCount == 0)
{
OICFree(senderInfo->defragData);
OICFree(senderInfo->remoteEndpoint);
CAStopLEGattClient();
CAResult_t result = CAQueueingThreadStop(g_bleClientSendQueueHandle);
-
+
return result;
#else
CAStopLEGattClient();
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;
//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;
// 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));
CAResult_t res = CAQueueingThreadAddData(g_bleServerSendQueueHandle,
bleData,
- sizeof(CALEData_t));
+ sizeof(CALEData_t), true);
if (CA_STATUS_OK != res)
{
CALEDataDestroyer(bleData, sizeof(CALEData_t));
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
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
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);
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;
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;
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))
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;
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;
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;
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;
CATerminateLEGattServer();
return CA_STATUS_FAILED;
}
-
+
if(g_leServerAutoAdvertisement)
{
ret = CALEStartAdvertise();
{
OIC_LOG(WARNING, TAG, "Auto advertisement is DISABLED. Advertising is not started.");
}
-
+
g_isLEGattServerStarted = true;
oc_mutex_unlock(g_leServerStateMutex);
{
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);
VERIFY_NON_NULL_VOID(blockID, TAG, "blockID");
OICFree(blockID->id);
OICFree(blockID);
- blockID = NULL;
}
bool CABlockidMatches(const CABlockData_t *currData, 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);
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)
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)
#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)
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)
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;
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
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
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)
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)
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)
{
// 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);
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
{
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);
// 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)
{
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;
}
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;
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)
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;
}
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
#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>
#include <fcntl.h>
#include <arpa/inet.h>
#include <netinet/in.h>
+#include <netinet/tcp.h>
#include <net/if.h>
#include <errno.h>
*/
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();
#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)
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
{
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!");
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)
{
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;
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;
}
}
#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;
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)
{
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
);
#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;
}
{
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;
+}
#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
OCRepPayloadGetPropInt(payload, GATEWAY, &tempGateway);
*gatewayId = tempGateway;
- if (NULL == gatewayId || 0 == *gatewayId)
+ if (0 == *gatewayId)
{
return OC_STACK_COMM_ERROR;
}
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);
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;
*/
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.
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
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
}
/**
+ * 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.
InvokeOtmEventHandler(ehRequest->devAddr.addr, ehRequest->devAddr.port,
NULL, OIC_OTM_ERROR);
#endif
- RestoreDoxmToInitState();
- RestorePstatToInitState();
+ ResetSecureResourceInPS();
OIC_LOG(WARNING, TAG, "DOXM will be reverted.");
}
}
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
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;
// 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;
}
}
if(NULL == context)
{
+ OIC_LOG_V(ERROR, TAG, "%s: context is NULL", __func__);
return retVal;
}
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;
}
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);
// 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;
}
exit:
+ OIC_LOG_V(INFO, TAG, "context->retVal - %d", retVal);
+ OIC_LOG_V(INFO, TAG, "Out %s", __func__);
return retVal;
}
// 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.
*/
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;
}
#include "oic_malloc.h"
#include "oic_string.h"
#include "base64.h"
+#include "psinterface.h"
#include "doxmresource.h"
#include "credresource.h"
#include "pstatresource.h"
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);
}
}
*/
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.
*
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
}
#endif // WITH_PRESENCE
OICFree(cbNode);
- cbNode = NULL;
}
OIC_TRACE_END();
}
return OC_STACK_NO_RESOURCE;
}
- if (resourcePtr && resourcePtr->rsrcChildResourcesHead != NULL)
+ if (resourcePtr->rsrcChildResourcesHead != NULL)
{
// Collection resource
if (resourcePtr->entityHandler != defaultResourceEHandler)
OICFree(serverRequest->requestToken);
OICFree(serverRequest->rcvdVendorSpecificHeaderOptions);
OICFree(serverRequest);
- serverRequest = NULL;
OIC_LOG(INFO, TAG, "Server Request Removed!!");
}
}
#include "camessagehandler.h"
#include "oicgroup.h"
#include "pstatresource.h"
+#include "srmutility.h"
#if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
#include "routingutility.h"
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);
}
}
}
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;
}
else
{
- if ((key != NULL) && (value != NULL))
+ if (value != NULL)
{
OIC_LOG(INFO, TAG, "Build OCCapability Instance.");
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));
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;
}
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)
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;
}
// 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};
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);
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;
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;
}
}
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
(obj->consumerId)[0] = '\0';
OICFree(obj);
- obj = NULL;
return NS_OK;
}
address = schema + 2;
}
size_t prefixLen = schema - inputaddress;
- if (prefixLen <= 0)
+ if (prefixLen == 0)
{
NS_LOG(ERROR, "Invalid Input address.");
return NULL;
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,