/**
* Callback function to pass the connection information from CA to RI.
* @param[out] object remote device information.
+ * @param[out] isConnected Whether keepalive message needs to be sent.
+ * @param[out] isClient Host Mode of Operation.
*/
-typedef void (*CAKeepAliveConnectionCallback)(const CAEndpoint_t *object, bool isConnected);
+typedef void (*CAKeepAliveConnectionCallback)(const CAEndpoint_t *object, bool isConnected,
+ bool isClient);
/**
* Register connection status changes callback to process KeepAlive.
unsigned char* data; /**< received data from remote device */
size_t len; /**< received data length */
size_t totalLen; /**< total coap data length required to receive */
- unsigned char tlsdata[18437]; /**< tls data(rfc5246: TLSCiphertext max (2^14+2048+5)) */
- size_t tlsLen; /**< received tls data length */
+ unsigned char tlsdata[18437]; /**< tls data(rfc5246: TLSCiphertext max (2^14+2048+5)) */
+ size_t tlsLen; /**< received tls data length */
CAProtocol_t protocol; /**< application-level protocol */
CATCPConnectionState_t state; /**< current tcp session state */
+ bool isClient; /**< Host Mode of Operation. */
} CATCPSessionInfo_t;
/**
*
* @param[in] endpoint network endpoint description.
* @param[in] isConnected Whether keepalive message needs to be sent.
+ * @param[in] isClient Host Mode of Operation.
* @see Callback must be registered using CATCPSetKeepAliveCallback().
*/
-typedef void (*CATCPConnectionHandleCallback)(const CAEndpoint_t *endpoint, bool isConnected);
+typedef void (*CATCPConnectionHandleCallback)(const CAEndpoint_t *endpoint, bool isConnected,
+ bool isClient);
/**
* set error callback to notify error in TCP adapter.
*/
static CAErrorHandleCallback g_errorCallback = NULL;
+/**
+ * KeepAlive Connected or Disconnected Callback to CA adapter.
+ */
+static CAKeepAliveConnectionCallback g_connKeepAliveCallback = NULL;
+
static void CATCPPacketReceivedCB(const CASecureEndpoint_t *sep,
const void *data, uint32_t dataLength);
static void CATCPErrorHandler(const CAEndpoint_t *endpoint, const void *data,
size_t dataLength, CAResult_t result);
-/**
- * KeepAlive Connected or Disconnected Callback to CA adapter.
- */
-static CAKeepAliveConnectionCallback g_connKeepAliveCallback = NULL;
-
static CAResult_t CATCPInitializeQueueHandles();
static void CATCPDeinitializeQueueHandles();
}
}
-static void CATCPConnectionHandler(const CAEndpoint_t *endpoint, bool isConnected)
+static void CATCPConnectionHandler(const CAEndpoint_t *endpoint, bool isConnected, bool isClient)
{
// Pass the changed connection status to RI Layer for keepalive.
if (g_connKeepAliveCallback)
{
- g_connKeepAliveCallback(endpoint, isConnected);
+ g_connKeepAliveCallback(endpoint, isConnected, isClient);
}
// Pass the changed connection status to CAUtil.
svritem->sep.endpoint.flags = flag;
svritem->sep.endpoint.adapter = CA_ADAPTER_TCP;
svritem->state = CONNECTED;
+ svritem->isClient = false;
CAConvertAddrToName((struct sockaddr_storage *)&clientaddr, clientlen,
svritem->sep.endpoint.addr, &svritem->sep.endpoint.port);
// pass the connection information to CA Common Layer.
if (g_connectionCallback)
{
- g_connectionCallback(&(svritem->sep.endpoint), true);
+ g_connectionCallback(&(svritem->sep.endpoint), true, svritem->isClient);
}
}
}
svritem->sep.endpoint.flags = endpoint->flags;
svritem->sep.endpoint.ifindex = endpoint->ifindex;
svritem->state = CONNECTING;
+ svritem->isClient = true;
// #2. add TCP connection info to list
oc_mutex_lock(g_mutexObjectList);
// #4. pass the connection information to CA Common Layer.
if (g_connectionCallback)
{
- g_connectionCallback(&(svritem->sep.endpoint), true);
+ g_connectionCallback(&(svritem->sep.endpoint), true, svritem->isClient);
}
return svritem->fd;
// pass the connection information to CA Common Layer.
if (g_connectionCallback && DISCONNECTED == removedData->state)
{
- g_connectionCallback(&(removedData->sep.endpoint), false);
+ g_connectionCallback(&(removedData->sep.endpoint), false, removedData->isClient);
}
}
OICFree(removedData->data);
/**
* API to handle the connected device for KeepAlive.
- * @return Current Time.
+ * @param[in] endpoint Remote endpoint information.
+ * @param[in] isConnected Whether keepalive message needs to be sent.
+ * @param[in] isClient Host Mode of Operation.
*/
-void HandleKeepAliveConnCB(const CAEndpoint_t *endpoint, bool isConnected);
+void HandleKeepAliveConnCB(const CAEndpoint_t *endpoint, bool isConnected, bool isClient);
#ifdef __cplusplus
} // extern "C"
return OC_STACK_OK;
}
-void HandleKeepAliveConnCB(const CAEndpoint_t *endpoint, bool isConnected)
+void HandleKeepAliveConnCB(const CAEndpoint_t *endpoint, bool isConnected, bool isClient)
{
VERIFY_NON_NULL_NR(endpoint, FATAL);
{
OIC_LOG(DEBUG, TAG, "Received the connected device information from CA");
- // Send discover message to find ping resource
- OCCallbackData pingData = {.context = NULL, .cb = PingRequestCallback };
- OCDevAddr devAddr = { .adapter = OC_ADAPTER_TCP };
- CopyEndpointToDevAddr(endpoint, &devAddr);
-
- OCStackResult result = OCDoResource(NULL, OC_REST_DISCOVER, KEEPALIVE_RESOURCE_URI,
- &devAddr, NULL, CT_ADAPTER_TCP, OC_HIGH_QOS,
- &pingData, NULL, 0);
- if (OC_STACK_OK != result)
+ if (isClient)
{
- OIC_LOG(ERROR, TAG, "OCDoResource has failed");
- return;
+ // Send discover message to find ping resource
+ OCCallbackData pingData = {.context = NULL, .cb = PingRequestCallback };
+ OCDevAddr devAddr = { .adapter = OC_ADAPTER_TCP };
+ CopyEndpointToDevAddr(endpoint, &devAddr);
+
+ OCStackResult result = OCDoResource(NULL, OC_REST_DISCOVER, KEEPALIVE_RESOURCE_URI,
+ &devAddr, NULL, CT_ADAPTER_TCP, OC_HIGH_QOS,
+ &pingData, NULL, 0);
+ if (OC_STACK_OK != result)
+ {
+ OIC_LOG(ERROR, TAG, "OCDoResource has failed");
+ return;
+ }
}
}
else