1 /* ****************************************************************
3 * Copyright 2015 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 ******************************************************************/
21 #include "oickeepalive.h"
25 #include "oic_malloc.h"
26 #include "oic_string.h"
29 #include "uarraylist.h"
30 #include "ocstackinternal.h"
31 #include "ocpayloadcbor.h"
32 #include "ocpayload.h"
33 #include "ocresourcehandler.h"
37 * Logging tag for module name.
39 #define TAG "OIC_RI_KEEPALIVE"
41 static const uint64_t USECS_PER_SEC = 1000000;
43 //-----------------------------------------------------------------------------
45 //-----------------------------------------------------------------------------
46 #define VERIFY_SUCCESS(op, successCode) { if ((op) != (successCode)) \
47 {OIC_LOG_V(FATAL, TAG, "%s failed!!", #op); goto exit;} }
49 #define VERIFY_NON_NULL(arg, logLevel, retVal) { if (!(arg)) { OIC_LOG((logLevel), \
50 TAG, #arg " is NULL"); return (retVal); } }
52 #define VERIFY_NON_NULL_NR(arg, logLevel) { if (!(arg)) { OIC_LOG((logLevel), \
53 TAG, #arg " is NULL"); return; } }
55 #define VERIFY_NON_NULL_V(arg) { if (!arg) {OIC_LOG_V(FATAL, TAG, "%s is NULL", #arg);\
59 * The KeepAlive table entries are removed
60 * if it can't receive response message within 60 seconds.
62 #define KEEPALIVE_RESPONSE_TIMEOUT_SEC 60
65 * The Min time interval value. (2 minutes)
66 * start from 2 minutes and increases in multiples of 2 up to a maximum of 64minutes.
68 #define KEEPALIVE_MIN_INTERVAL 2
71 * The Max time interval value. (64 minutes)
73 #define KEEPALIVE_MAX_INTERVAL 64
76 * Default counts of interval value.
78 #define DEFAULT_INTERVAL_COUNT 6
81 * KeepAlive key to parser Payload Table.
83 static const char INTERVAL[] = "in";
86 * KeepAlive key to get interval values from Payload Table.
88 static const char INTERVAL_ARRAY[] = "inarray";
91 * To check if KeepAlive is initialized.
93 static bool g_isKeepAliveInitialized = false;
96 * Pointer to handle of the newly created KeepAlive resource.
98 static OCResourceHandle g_keepAliveHandle = NULL;
101 * KeepAlive table which holds connection interval.
103 static u_arraylist_t *g_keepAliveConnectionTable = NULL;
106 * KeepAlive table entries.
110 OCMode mode; /**< host Mode of Operation. */
111 CAEndpoint_t remoteAddr; /**< destination Address. */
112 uint32_t interval; /**< time interval for KeepAlive. in seconds.*/
113 int32_t currIndex; /**< current interval value index. */
114 size_t intervalSize; /**< total interval counts. */
115 int64_t *intervalInfo; /**< interval values for KeepAlive. */
116 bool sentPingMsg; /**< if oic client already sent ping message. */
117 uint64_t timeStamp; /**< last sent or received ping message. in microseconds. */
121 * Send disconnect message to remove connection.
123 static OCStackResult SendDisconnectMessage(const KeepAliveEntry_t *entry);
126 * Send ping message to remote endpoint.
128 static OCStackResult SendPingMessage(KeepAliveEntry_t *entry);
131 * Increase interval value to send next ping message.
133 static void IncreaseInterval(KeepAliveEntry_t *entry);
136 * Ping Message callback registered with RI for KeepAlive Request.
138 static OCStackApplicationResult PingRequestCallback(void* ctx, OCDoHandle handle,
139 OCClientResponse * clientResponse);
142 * This function creates KeepAlive resource.
143 * @return ::OC_STACK_OK or Appropriate error code.
145 static OCStackResult CreateKeepAliveResource();
148 * This function deletes KeepAlive resource.
149 * @return ::OC_STACK_OK or Appropriate error code.
151 static OCStackResult DeleteKeepAliveResource();
154 * API to handle the GET request received for a KeepAlive resource.
155 * @param[in] request Request Received.
156 * @param[in] resource Resource handle used for sending the response.
157 * @return ::OC_STACK_OK or Appropriate error code.
159 static OCStackResult HandleKeepAliveGETRequest(OCServerRequest *request,
160 const OCResource *resource);
163 * API to handle the PUT request received for a KeepAlive resource.
164 * @param[in] request Request Received.
165 * @param[in] resource Resource handle used for sending the response.
166 * @return ::OC_STACK_OK or Appropriate error code.
168 static OCStackResult HandleKeepAlivePUTRequest(OCServerRequest *request,
169 const OCResource *resource);
172 * API to handle the Response payload.
173 * @param[in] endpoint RemoteEndpoint which sent the packet.
174 * @param[in] responseCode Received reseponse code.
175 * @param[in] respPayload Response payload.
176 * @return ::OC_STACK_OK or Appropriate error code.
178 OCStackResult HandleKeepAliveResponse(const CAEndpoint_t *endPoint,
179 OCStackResult responseCode,
180 const OCRepPayload *respPayload);
182 * Gets keepalive entry.
183 * @param[in] endpoint Remote Endpoint information (like ipaddress,
184 * port, reference uri and transport type) to
185 * which the ping message has to be sent.
186 * @param[out] index index of array list.
187 * @return KeepAlive entry to send ping message.
189 static KeepAliveEntry_t *GetEntryFromEndpoint(const CAEndpoint_t *endpoint, uint32_t *index);
192 * Add keepalive entry.
193 * @param[in] endpoint Remote Endpoint information (like ipaddress,
194 * port, reference uri and transport type).
195 * @param[in] mode Whether it is OIC Server or OIC Client.
196 * @param[in] intervalArray Received interval values from cloud server.
197 * @return The KeepAlive entry added in KeepAlive Table.
199 KeepAliveEntry_t *AddKeepAliveEntry(const CAEndpoint_t *endpoint, OCMode mode,
200 int64_t *intervalArray);
203 * Remove keepalive entry.
204 * @param[in] endpoint Remote Endpoint information (like ipaddress,
205 * port, reference uri and transport type).
206 * @return The KeepAlive entry removed in KeepAlive Table.
208 static OCStackResult RemoveKeepAliveEntry(const CAEndpoint_t *endpoint);
210 OCStackResult InitializeKeepAlive(OCMode mode)
212 OIC_LOG(DEBUG, TAG, "InitializeKeepAlive IN");
213 if (g_isKeepAliveInitialized)
215 OIC_LOG(DEBUG, TAG, "KeepAlive already initialized");
219 if (OC_CLIENT != mode)
221 // Create the KeepAlive Resource[/oic/ping].
222 OCStackResult result = CreateKeepAliveResource();
223 if (OC_STACK_OK != result)
225 OIC_LOG_V(ERROR, TAG, "CreateKeepAliveResource failed[%d]", result);
230 if (!g_keepAliveConnectionTable)
232 g_keepAliveConnectionTable = u_arraylist_create();
233 if (NULL == g_keepAliveConnectionTable)
235 OIC_LOG(ERROR, TAG, "Creating KeepAlive Table failed");
236 TerminateKeepAlive(mode);
237 return OC_STACK_ERROR;
241 g_isKeepAliveInitialized = true;
243 OIC_LOG(DEBUG, TAG, "InitializeKeepAlive OUT");
247 OCStackResult TerminateKeepAlive(OCMode mode)
249 OIC_LOG(DEBUG, TAG, "TerminateKeepAlive IN");
250 if (!g_isKeepAliveInitialized)
252 OIC_LOG(ERROR, TAG, "KeepAlive not initialized");
253 return OC_STACK_ERROR;
256 if (OC_CLIENT != mode)
258 // Delete the KeepAlive Resource[/oic/ping].
259 OCStackResult result = DeleteKeepAliveResource();
260 if (OC_STACK_OK != result)
262 OIC_LOG_V(ERROR, TAG, "DeleteKeepAliveResource failed[%d]", result);
267 if (NULL != g_keepAliveConnectionTable)
269 u_arraylist_destroy(g_keepAliveConnectionTable);
270 g_keepAliveConnectionTable = NULL;
273 g_isKeepAliveInitialized = false;
275 OIC_LOG(DEBUG, TAG, "TerminateKeepAlive OUT");
279 OCStackResult CreateKeepAliveResource()
281 OIC_LOG(DEBUG, TAG, "InitKeepAliveResource IN");
283 // Create a KeepAlive resource
284 OCStackResult result = OCCreateResource(&g_keepAliveHandle,
285 KEEPALIVE_RESOURCE_TYPE_NAME,
286 KEEPALIVE_RESOURCE_INTF_NAME,
287 KEEPALIVE_RESOURCE_URI,
292 if (OC_STACK_OK != result)
294 OIC_LOG_V(ERROR, TAG, "Create resource for KeepAlive failed[%d]", result);
297 OIC_LOG(DEBUG, TAG, "InitKeepAliveResource OUT");
301 OCStackResult DeleteKeepAliveResource()
303 OIC_LOG(DEBUG, TAG, "DeleteKeepAliveResource IN");
305 // Create a KeepAlive resource
306 OCStackResult result = OCDeleteResource(g_keepAliveHandle);
308 if (OC_STACK_OK != result)
310 OIC_LOG_V(ERROR, TAG, "Delete resource for KeepAlive failed[%d]", result);
313 OIC_LOG(DEBUG, TAG, "DeleteKeepAliveResource OUT");
317 OCStackResult HandleKeepAliveRequest(OCServerRequest *request,
318 const OCResource *resource)
320 VERIFY_NON_NULL(request, FATAL, OC_STACK_INVALID_PARAM);
321 VERIFY_NON_NULL(resource, FATAL, OC_STACK_INVALID_PARAM);
323 OIC_LOG(DEBUG, TAG, "HandleKeepAliveRequest IN");
325 OCStackResult result = OC_STACK_ERROR;
326 if (OC_REST_GET == request->method)
328 switch ((OCObserveAction)request->observationOption)
330 case OC_OBSERVE_NO_OPTION:
331 OIC_LOG(DEBUG, TAG, "Received GET request");
332 result = HandleKeepAliveGETRequest(request, resource);
335 OIC_LOG(DEBUG, TAG, "Not Supported by KeepAlive");
336 result = OC_STACK_UNAUTHORIZED_REQ;
339 else if (OC_REST_PUT == request->method)
341 OIC_LOG(DEBUG, TAG, "Received PUT request");
342 result = HandleKeepAlivePUTRequest(request, resource);
346 OIC_LOG(DEBUG, TAG, "Not Supported by KeepAlive");
347 result = OC_STACK_UNAUTHORIZED_REQ;
350 // convert OCStackResult to CAResponseResult_t.
351 CAResponseResult_t caResult = OCToCAStackResult(result, request->method);
352 CAEndpoint_t endpoint = {.adapter = CA_DEFAULT_ADAPTER};
353 CopyDevAddrToEndpoint(&request->devAddr, &endpoint);
355 // Send response message.
356 SendDirectStackResponse(&endpoint, request->coapID, caResult,
357 qualityOfServiceToMessageType(request->qos),
358 request->numRcvdVendorSpecificHeaderOptions,
359 request->rcvdVendorSpecificHeaderOptions,
360 request->requestToken, request->tokenLength,
361 request->resourceUrl, CA_RESPONSE_DATA);
363 OIC_LOG(DEBUG, TAG, "HandleKeepAliveRequest OUT");
367 OCStackResult HandleKeepAliveGETRequest(OCServerRequest *request,
368 const OCResource *resource)
370 VERIFY_NON_NULL(request, FATAL, OC_STACK_INVALID_PARAM);
371 VERIFY_NON_NULL(resource, FATAL, OC_STACK_INVALID_PARAM);
373 OIC_LOG_V(DEBUG, TAG, "Find Ping resource [%s]", request->resourceUrl);
375 CAResponseResult_t result = CA_CONTENT;
376 OCResource *resourcePtr = FindResourceByUri(request->resourceUrl);
379 // Resource URL not specified
380 OIC_LOG_V(DEBUG, TAG, "There is no Ping resource [%s]", request->resourceUrl);
381 return OC_STACK_NO_RESOURCE;
387 OCStackResult HandleKeepAlivePUTRequest(OCServerRequest *request,
388 const OCResource *resource)
390 VERIFY_NON_NULL(request, FATAL, OC_STACK_INVALID_PARAM);
391 VERIFY_NON_NULL(resource, FATAL, OC_STACK_INVALID_PARAM);
393 // Get entry from KeepAlive table.
394 CAEndpoint_t endpoint = { .adapter = CA_DEFAULT_ADAPTER };
395 CopyDevAddrToEndpoint(&request->devAddr, &endpoint);
398 KeepAliveEntry_t *entry = GetEntryFromEndpoint(&endpoint, &index);
401 OIC_LOG(ERROR, TAG, "Received the first keepalive message from client");
402 entry = AddKeepAliveEntry(&endpoint, OC_SERVER, NULL);
405 OIC_LOG(ERROR, TAG, "Failed to add new keepalive entry");
406 return OC_STACK_ERROR;
410 OCPayload *ocPayload = NULL;
411 OCParsePayload(&ocPayload, PAYLOAD_TYPE_REPRESENTATION,
412 request->payload, request->payloadSize);
413 OCRepPayload *repPayload = (OCRepPayload *)ocPayload;
415 int64_t interval = 0;
416 OCRepPayloadGetPropInt(repPayload, INTERVAL, &interval);
417 entry->interval = interval;
418 OIC_LOG_V(DEBUG, TAG, "Received interval is [%d]", entry->interval);
419 entry->timeStamp = OICGetCurrentTime(TIME_IN_US);
421 OCPayloadDestroy(ocPayload);
426 OCStackResult HandleKeepAliveResponse(const CAEndpoint_t *endPoint,
427 OCStackResult responseCode,
428 const OCRepPayload *respPayload)
430 VERIFY_NON_NULL(endPoint, FATAL, OC_STACK_INVALID_PARAM);
432 OIC_LOG(DEBUG, TAG, "HandleKeepAliveResponse IN");
434 // Get entry from KeepAlive table.
436 KeepAliveEntry_t *entry = GetEntryFromEndpoint(endPoint, &index);
439 // Receive response message about find /oic/ping request.
440 OIC_LOG(ERROR, TAG, "There is no connection info in KeepAlive table");
442 if (OC_STACK_NO_RESOURCE == responseCode)
444 OIC_LOG(ERROR, TAG, "Server doesn't have a ping resource");
445 return OC_STACK_ERROR;
447 else if (OC_STACK_OK == responseCode)
449 int64_t *recvInterval = NULL;
450 size_t dimensions[MAX_REP_ARRAY_DEPTH] = { 0 };
451 OCRepPayloadGetIntArray(respPayload, INTERVAL_ARRAY, &recvInterval, dimensions);
452 size_t serverIntervalSize = calcDimTotal(dimensions);
454 entry = AddKeepAliveEntry(endPoint, OC_CLIENT, recvInterval);
457 OIC_LOG(ERROR, TAG, "Failed to add new KeepAlive entry");
458 return OC_STACK_ERROR;
461 if (serverIntervalSize)
463 // update interval size with received size of server.
464 entry->intervalSize = serverIntervalSize;
467 // Send first ping message
468 return SendPingMessage(entry);
473 // Set sentPingMsg values with false.
474 entry->sentPingMsg = false;
477 OIC_LOG(DEBUG, TAG, "HandleKeepAliveResponse OUT");
481 void ProcessKeepAlive()
483 if (!g_isKeepAliveInitialized)
485 OIC_LOG(ERROR, TAG, "KeepAlive not initialized");
489 uint32_t len = u_arraylist_length(g_keepAliveConnectionTable);
491 for (uint32_t i = 0; i < len; i++)
493 KeepAliveEntry_t *entry = (KeepAliveEntry_t *)u_arraylist_get(g_keepAliveConnectionTable,
500 uint64_t currentTime = OICGetCurrentTime(TIME_IN_US);
501 if (OC_CLIENT == entry->mode)
503 if (entry->sentPingMsg)
506 * If an OIC Client does not receive the response within 1 minutes,
507 * terminate the connection.
508 * In this case the timeStamp means last time sent ping message.
510 if ((KEEPALIVE_RESPONSE_TIMEOUT_SEC * USECS_PER_SEC) <= currentTime - entry->timeStamp)
512 OIC_LOG(DEBUG, TAG, "Client does not receive the response within 1 minutes.");
514 // Send message to disconnect session.
515 SendDisconnectMessage(entry);
520 if ((entry->interval * KEEPALIVE_RESPONSE_TIMEOUT_SEC * USECS_PER_SEC)
521 <= currentTime - entry->timeStamp)
523 // Increase interval value.
524 IncreaseInterval(entry);
526 OCStackResult result = SendPingMessage(entry);
527 if (OC_STACK_OK != result)
529 OIC_LOG(ERROR, TAG, "Failed to send ping request");
535 else if (OC_SERVER == entry->mode)
538 * If an OIC Server does not receive a PUT request to ping resource
539 * within the specified interval time, terminate the connection.
540 * In this case the timeStamp means last time received ping message.
542 if ((entry->interval * KEEPALIVE_RESPONSE_TIMEOUT_SEC * USECS_PER_SEC)
543 <= currentTime - entry->timeStamp)
545 OIC_LOG(DEBUG, TAG, "Server does not receive a PUT request.");
546 SendDisconnectMessage(entry);
552 void IncreaseInterval(KeepAliveEntry_t *entry)
554 VERIFY_NON_NULL_NR(entry, FATAL);
556 OIC_LOG_V(DEBUG, TAG, "Total interval counts: %zu", entry->intervalSize);
557 if (entry->intervalSize > (size_t)entry->currIndex + 1)
560 entry->interval = entry->intervalInfo[entry->currIndex];
561 OIC_LOG_V(DEBUG, TAG, "increase interval value [%d]", entry->interval);
565 OCStackResult SendDisconnectMessage(const KeepAliveEntry_t *entry)
567 VERIFY_NON_NULL(entry, FATAL, OC_STACK_INVALID_PARAM);
570 * Send empty message to disconnect a connection.
571 * If CA get the empty message from RI, CA will disconnect a connection.
574 OCStackResult result = RemoveKeepAliveEntry(&entry->remoteAddr);
575 if (result != OC_STACK_OK)
580 CARequestInfo_t requestInfo = { .method = CA_PUT };
581 result = CASendRequest(&entry->remoteAddr, &requestInfo);
582 return CAResultToOCResult(result);
585 OCStackResult SendPingMessage(KeepAliveEntry_t *entry)
587 VERIFY_NON_NULL(entry, FATAL, OC_STACK_INVALID_PARAM);
589 // Send ping message.
590 OCCallbackData pingData = { .context = NULL, .cb = PingRequestCallback };
591 OCDevAddr devAddr = { .adapter = OC_ADAPTER_TCP };
592 CopyEndpointToDevAddr(&(entry->remoteAddr), &devAddr);
594 OCRepPayload *payload = OCRepPayloadCreate();
597 OIC_LOG(ERROR, TAG, "Failed to allocate Payload");
598 return OC_STACK_ERROR;
600 payload->base.type = PAYLOAD_TYPE_REPRESENTATION;
601 OCRepPayloadSetPropInt(payload, INTERVAL, entry->interval);
603 OCStackResult result = OCDoResource(NULL, OC_REST_PUT, KEEPALIVE_RESOURCE_URI, &devAddr,
604 (OCPayload *) payload, CT_ADAPTER_TCP, OC_LOW_QOS,
606 if (OC_STACK_OK != result)
608 OIC_LOG(ERROR, TAG, "OCDoResource has failed");
612 // Update timeStamp with time sent ping message for next ping message.
613 entry->timeStamp = OICGetCurrentTime(TIME_IN_US);
614 entry->sentPingMsg = true;
616 OIC_LOG_V(DEBUG, TAG, "Client sent ping message, interval [%d]", entry->interval);
621 OCStackApplicationResult PingRequestCallback(void* ctx, OCDoHandle handle,
622 OCClientResponse *clientResponse)
624 OIC_LOG(DEBUG, TAG, "PingRequestCallback IN");
627 if (NULL == clientResponse)
629 OIC_LOG(ERROR, TAG, "clientResponse is NULL");
630 return OC_STACK_DELETE_TRANSACTION;
633 CAEndpoint_t endpoint = { .adapter = CA_ADAPTER_TCP };
634 CopyDevAddrToEndpoint(&(clientResponse->devAddr), &endpoint);
636 HandleKeepAliveResponse(&endpoint, clientResponse->result,
637 (OCRepPayload *)clientResponse->payload);
639 OIC_LOG(DEBUG, TAG, "PingRequestCallback OUT");
640 return OC_STACK_DELETE_TRANSACTION;
643 KeepAliveEntry_t *GetEntryFromEndpoint(const CAEndpoint_t *endpoint, uint32_t *index)
645 if (!g_keepAliveConnectionTable)
647 OIC_LOG(ERROR, TAG, "KeepAlive Table was not Created.");
651 uint32_t len = u_arraylist_length(g_keepAliveConnectionTable);
653 for (uint32_t i = 0; i < len; i++)
655 KeepAliveEntry_t *entry = (KeepAliveEntry_t *)u_arraylist_get(g_keepAliveConnectionTable,
662 if (!strncmp(entry->remoteAddr.addr, endpoint->addr, sizeof(entry->remoteAddr.addr))
663 && (entry->remoteAddr.port == endpoint->port))
665 OIC_LOG(DEBUG, TAG, "Connection Info found in KeepAlive table");
674 KeepAliveEntry_t *AddKeepAliveEntry(const CAEndpoint_t *endpoint, OCMode mode,
675 int64_t *intervalInfo)
679 OIC_LOG(ERROR, TAG, "endpoint is NULL");
683 if (!g_keepAliveConnectionTable)
685 OIC_LOG(ERROR, TAG, "KeepAlive Table was not Created.");
689 KeepAliveEntry_t *entry = (KeepAliveEntry_t *) OICCalloc(1, sizeof(KeepAliveEntry_t));
692 OIC_LOG(ERROR, TAG, "Failed to Calloc KeepAlive Entry");
697 entry->timeStamp = OICGetCurrentTime(TIME_IN_US);
698 entry->remoteAddr.adapter = endpoint->adapter;
699 entry->remoteAddr.flags = endpoint->flags;
700 entry->remoteAddr.ifindex = endpoint->ifindex;
701 entry->remoteAddr.port = endpoint->port;
702 strncpy(entry->remoteAddr.addr, endpoint->addr, sizeof(entry->remoteAddr.addr));
704 entry->intervalSize = DEFAULT_INTERVAL_COUNT;
705 entry->intervalInfo = intervalInfo;
706 if (!entry->intervalInfo)
708 entry->intervalInfo = (int64_t*) OICMalloc(entry->intervalSize * sizeof(int64_t));
709 for (size_t i = 0; i < entry->intervalSize; i++)
711 entry->intervalInfo[i] = KEEPALIVE_MIN_INTERVAL << i;
714 entry->interval = entry->intervalInfo[0];
716 bool result = u_arraylist_add(g_keepAliveConnectionTable, (void *)entry);
719 OIC_LOG(ERROR, TAG, "Adding node to head failed");
720 OICFree(entry->intervalInfo);
728 OCStackResult RemoveKeepAliveEntry(const CAEndpoint_t *endpoint)
730 VERIFY_NON_NULL(endpoint, FATAL, OC_STACK_INVALID_PARAM);
733 KeepAliveEntry_t *entry = GetEntryFromEndpoint(endpoint, &index);
736 OIC_LOG(ERROR, TAG, "There is no entry in keepalive table.");
737 return OC_STACK_ERROR;
740 KeepAliveEntry_t *removedEntry = (KeepAliveEntry_t *)
741 u_arraylist_remove(g_keepAliveConnectionTable, index);
742 if (NULL == removedEntry)
744 OIC_LOG(ERROR, TAG, "Removed Entry is NULL");
745 return OC_STACK_ERROR;
748 OIC_LOG_V(DEBUG, TAG, "Remove Connection Info from KeepAlive table, "
749 "remote addr=%s port:%d", removedEntry->remoteAddr.addr,
750 removedEntry->remoteAddr.port);
752 OICFree(entry->intervalInfo);
753 OICFree(removedEntry);
758 void HandleKeepAliveConnCB(const CAEndpoint_t *endpoint, bool isConnected)
760 VERIFY_NON_NULL_NR(endpoint, FATAL);
764 OIC_LOG(DEBUG, TAG, "Received the connected device information from CA");
766 // Send discover message to find ping resource
767 OCCallbackData pingData = {.context = NULL, .cb = PingRequestCallback };
768 OCDevAddr devAddr = { .adapter = OC_ADAPTER_TCP };
769 CopyEndpointToDevAddr(endpoint, &devAddr);
771 OCStackResult result = OCDoResource(NULL, OC_REST_DISCOVER, KEEPALIVE_RESOURCE_URI,
772 &devAddr, NULL, CT_ADAPTER_TCP, OC_HIGH_QOS,
774 if (OC_STACK_OK != result)
776 OIC_LOG(ERROR, TAG, "OCDoResource has failed");
782 OIC_LOG(DEBUG, TAG, "Received the disconnected device information from CA");
784 OCStackResult result = RemoveKeepAliveEntry(endpoint);
785 if(result != OC_STACK_OK)