Added CASelectCipherSuite for android
[platform/upstream/iotivity.git] / resource / csdk / connectivity / src / caconnectivitymanager.c
1 /******************************************************************
2  *
3  * Copyright 2014 Samsung Electronics All Rights Reserved.
4  *
5  *
6  *
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  ******************************************************************/
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <stdint.h>
24 #include <stdbool.h>
25
26 #include "ocrandom.h"
27 #include "cainterface.h"
28 #include "caremotehandler.h"
29 #include "camessagehandler.h"
30 #include "caprotocolmessage.h"
31 #include "canetworkconfigurator.h"
32 #include "cainterfacecontroller.h"
33 #include "logger.h"
34 #ifdef __WITH_DTLS__
35 #include "caadapternetdtls.h"
36 #endif
37
38 #ifdef TCP_ADAPTER
39 #include "catcpadapter.h"
40 #ifdef __WITH_TLS__
41 #include "ca_adapter_net_tls.h"
42 #endif
43 #endif
44
45 CAGlobals_t caglobals = { .clientFlags = 0,
46                           .serverFlags = 0, };
47
48 #define TAG "OIC_CA_CONN_MGR"
49
50 static bool g_isInitialized = false;
51
52 #ifdef __WITH_DTLS__
53 // CAAdapterNetDTLS will register the callback.
54 // Taking callback all the way through adapters not the right approach, hence calling here.
55 extern void CADTLSSetCredentialsCallback(CAGetDTLSPskCredentialsHandler credCallback);
56 #endif
57
58 #ifdef __WITH_X509__
59 // CAAdapterNetDTLS will register the callback.
60 // Taking callback all the way through adapters not the right approach, hence calling here.
61 extern void CADTLSSetX509CredentialsCallback(CAGetDTLSX509CredentialsHandler credCallback);
62 extern void CADTLSSetCrlCallback(CAGetDTLSCrlHandler crlCallback);
63 #endif
64
65 #ifdef __WITH_TLS__
66 extern void CAsetPkixInfoCallback(CAgetPkixInfoHandler infCallback);
67 extern void CAsetTlsCredentialsCallback(CAGetDTLSPskCredentialsHandler credCallback);
68 extern void CAsetCredentialTypesCallback(CAgetCredentialTypesHandler credCallback);
69 #endif
70
71
72 CAResult_t CAInitialize()
73 {
74     OIC_LOG_V(DEBUG, TAG, "IoTivity version is v%s", IOTIVITY_VERSION);
75     OIC_LOG(DEBUG, TAG, "CAInitialize");
76
77     if (!g_isInitialized)
78     {
79         if (0 != OCSeedRandom())
80         {
81             OIC_LOG(ERROR, TAG, "Seed Random Failed");
82         }
83
84         CAResult_t res = CAInitializeMessageHandler();
85         if (res != CA_STATUS_OK)
86         {
87             OIC_LOG(ERROR, TAG, "CAInitialize has failed");
88             return res;
89         }
90         g_isInitialized = true;
91     }
92
93     return CA_STATUS_OK;
94 }
95
96 void CATerminate()
97 {
98     OIC_LOG(DEBUG, TAG, "CATerminate");
99
100     if (g_isInitialized)
101     {
102         CATerminateMessageHandler();
103         CATerminateNetworkType();
104
105         g_isInitialized = false;
106     }
107 }
108
109 CAResult_t CAStartListeningServer()
110 {
111     OIC_LOG(DEBUG, TAG, "CAStartListeningServer");
112
113     if (!g_isInitialized)
114     {
115         return CA_STATUS_NOT_INITIALIZED;
116     }
117
118     return CAStartListeningServerAdapters();
119 }
120
121 CAResult_t CAStopListeningServer()
122 {
123     OIC_LOG(DEBUG, TAG, "CAStopListeningServer");
124
125     if (!g_isInitialized)
126     {
127         return CA_STATUS_NOT_INITIALIZED;
128     }
129
130     return CAStopListeningServerAdapters();
131 }
132
133 CAResult_t CAStartDiscoveryServer()
134 {
135     OIC_LOG(DEBUG, TAG, "CAStartDiscoveryServer");
136
137     if (!g_isInitialized)
138     {
139         return CA_STATUS_NOT_INITIALIZED;
140     }
141
142     return CAStartDiscoveryServerAdapters();
143 }
144
145 void CARegisterHandler(CARequestCallback ReqHandler, CAResponseCallback RespHandler,
146                        CAErrorCallback ErrorHandler)
147 {
148     OIC_LOG(DEBUG, TAG, "CARegisterHandler");
149
150     if (!g_isInitialized)
151     {
152         OIC_LOG(DEBUG, TAG, "CA is not initialized");
153         return;
154     }
155
156     CASetInterfaceCallbacks(ReqHandler, RespHandler, ErrorHandler);
157 }
158
159 #ifdef __WITH_DTLS__
160 CAResult_t CARegisterDTLSHandshakeCallback(CAErrorCallback dtlsHandshakeCallback)
161 {
162     OIC_LOG(DEBUG, TAG, "CARegisterDTLSHandshakeCallback");
163
164     if (!g_isInitialized)
165     {
166         return CA_STATUS_NOT_INITIALIZED;
167     }
168
169     CADTLSSetHandshakeCallback(dtlsHandshakeCallback);
170
171     return CA_STATUS_OK;
172 }
173
174 CAResult_t CARegisterDTLSCredentialsHandler(CAGetDTLSPskCredentialsHandler GetDTLSCredentialsHandler)
175 {
176     OIC_LOG(DEBUG, TAG, "CARegisterDTLSCredentialsHandler");
177
178     if (!g_isInitialized)
179     {
180         return CA_STATUS_NOT_INITIALIZED;
181     }
182
183     CADTLSSetCredentialsCallback(GetDTLSCredentialsHandler);
184     return CA_STATUS_OK;
185 }
186 #endif //__WITH_DTLS__
187 #ifdef __WITH_TLS__
188 CAResult_t CAregisterTlsHandshakeCallback(CAErrorCallback tlsHandshakeCallback)
189 {
190     OIC_LOG(DEBUG, TAG, "CARegisterTlsHandshakeCallback");
191
192     if(!g_isInitialized)
193     {
194         return CA_STATUS_NOT_INITIALIZED;
195     }
196
197     CAsetTlsHandshakeCallback(tlsHandshakeCallback);
198     return CA_STATUS_OK;
199 }
200
201 CAResult_t CAregisterTlsCredentialsHandler(CAGetDTLSPskCredentialsHandler getTlsCredentialsHandler)
202 {
203     OIC_LOG_V(DEBUG, TAG, "In %s", __func__);
204
205     if (!g_isInitialized)
206     {
207         return CA_STATUS_NOT_INITIALIZED;
208     }
209     CAsetTlsCredentialsCallback(getTlsCredentialsHandler);
210     OIC_LOG_V(DEBUG, TAG, "Out %s", __func__);
211     return CA_STATUS_OK;
212 }
213
214 CAResult_t CAregisterPkixInfoHandler(CAgetPkixInfoHandler getPkixInfoHandler)
215 {
216     OIC_LOG_V(DEBUG, TAG, "In %s", __func__);
217
218     if (!g_isInitialized)
219     {
220         return CA_STATUS_NOT_INITIALIZED;
221     }
222     CAsetPkixInfoCallback(getPkixInfoHandler);
223     OIC_LOG_V(DEBUG, TAG, "Out %s", __func__);
224     return CA_STATUS_OK;
225 }
226
227 CAResult_t CAregisterGetCredentialTypesHandler(CAgetCredentialTypesHandler getCredTypesHandler)
228 {
229     OIC_LOG_V(DEBUG, TAG, "In %s", __func__);
230
231     if (!g_isInitialized)
232     {
233         return CA_STATUS_NOT_INITIALIZED;
234     }
235     CAsetCredentialTypesCallback(getCredTypesHandler);
236     OIC_LOG_V(DEBUG, TAG, "Out %s", __func__);
237     return CA_STATUS_OK;
238 }
239 #endif
240
241 #ifdef __WITH_X509__
242 CAResult_t CARegisterDTLSX509CredentialsHandler(CAGetDTLSX509CredentialsHandler GetDTLSX509CredentialsHandler)
243 {
244     OIC_LOG(DEBUG, TAG, "CARegisterDTLSX509CredentialsHandler");
245
246     if (!g_isInitialized)
247     {
248         return CA_STATUS_NOT_INITIALIZED;
249     }
250
251     CADTLSSetX509CredentialsCallback(GetDTLSX509CredentialsHandler);
252     return CA_STATUS_OK;
253 }
254
255 CAResult_t CARegisterDTLSCrlHandler(CAGetDTLSCrlHandler GetDTLSCrlHandler)
256 {
257     OIC_LOG(DEBUG, TAG, "CARegisterDTLSCrlHandler");
258
259     if (!g_isInitialized)
260     {
261         return CA_STATUS_NOT_INITIALIZED;
262     }
263
264     CADTLSSetCrlCallback(GetDTLSCrlHandler);
265     return CA_STATUS_OK;
266 }
267 #endif //__WITH_X509__
268
269 CAResult_t CACreateEndpoint(CATransportFlags_t flags,
270                             CATransportAdapter_t adapter,
271                             const char *addr,
272                             uint16_t port,
273                             CAEndpoint_t **object)
274 {
275     if (!object)
276     {
277         OIC_LOG(ERROR, TAG, "Invalid Parameter");
278         return CA_STATUS_INVALID_PARAM;
279     }
280
281     CAEndpoint_t *endpoint = CACreateEndpointObject(flags, adapter, addr, port);
282     if (!endpoint)
283     {
284         return CA_STATUS_FAILED;
285     }
286     *object = endpoint;
287     return CA_STATUS_OK;
288 }
289
290 void CADestroyEndpoint(CAEndpoint_t *rep)
291 {
292     OIC_LOG(DEBUG, TAG, "CADestroyEndpoint");
293
294     CAFreeEndpoint(rep);
295 }
296
297 CAResult_t CAGenerateToken(CAToken_t *token, uint8_t tokenLength)
298 {
299     OIC_LOG(DEBUG, TAG, "CAGenerateToken");
300
301     return CAGenerateTokenInternal(token, tokenLength);
302 }
303
304 void CADestroyToken(CAToken_t token)
305 {
306     OIC_LOG(DEBUG, TAG, "CADestroyToken");
307
308     CADestroyTokenInternal(token);
309
310     OIC_LOG(DEBUG, TAG, "OUT");
311 }
312
313 CAResult_t CAGetNetworkInformation(CAEndpoint_t **info, uint32_t *size)
314 {
315     OIC_LOG(DEBUG, TAG, "CAGetNetworkInformation");
316
317     if (!g_isInitialized)
318     {
319         return CA_STATUS_NOT_INITIALIZED;
320     }
321
322     return CAGetNetworkInformationInternal(info, size);
323 }
324
325 static CAResult_t CASendMessageMultiAdapter(const CAEndpoint_t *object, const void *sendMsg,
326                                             CADataType_t dataType)
327 {
328     OIC_LOG(DEBUG, TAG, "CASendMessageMultipleAdapter");
329
330     CATransportAdapter_t connTypes[] = {
331             CA_ADAPTER_IP
332 #ifdef LE_ADAPTER
333             ,CA_ADAPTER_GATT_BTLE
334 #endif
335 #ifdef EDR_ADAPTER
336             ,CA_ADAPTER_RFCOMM_BTEDR
337 #endif
338 #ifdef NFC_ADAPTER
339             ,CA_ADAPTER_NFC
340 #endif
341 #ifdef RA_ADAPTER
342             ,CA_ADAPTER_REMOTE_ACCESS
343 #endif
344 #ifdef TCP_ADAPTER
345             ,CA_ADAPTER_TCP
346 #endif
347         };
348
349     CAEndpoint_t *cloneEp = CACloneEndpoint(object);
350     if (!cloneEp)
351     {
352         OIC_LOG(ERROR, TAG, "Failed to clone CAEndpoint");
353         return CA_MEMORY_ALLOC_FAILED;
354     }
355
356     CAResult_t ret = CA_STATUS_OK;
357     size_t numConnTypes = sizeof(connTypes) / sizeof(connTypes[0]);
358
359     for (size_t i = 0; i < numConnTypes && ret == CA_STATUS_OK; i++)
360     {
361         cloneEp->adapter = connTypes[i];
362         ret = CADetachSendMessage(cloneEp, sendMsg, dataType);
363     }
364     CAFreeEndpoint(cloneEp);
365     return ret;
366 }
367
368 CAResult_t CASendRequest(const CAEndpoint_t *object, const CARequestInfo_t *requestInfo)
369 {
370     OIC_LOG(DEBUG, TAG, "CASendRequest");
371
372     if (!g_isInitialized)
373     {
374         return CA_STATUS_NOT_INITIALIZED;
375     }
376
377     if (requestInfo && requestInfo->isMulticast &&
378             (object->adapter == CA_DEFAULT_ADAPTER || object->adapter == CA_ALL_ADAPTERS))
379     {
380         return CASendMessageMultiAdapter(object, requestInfo, CA_REQUEST_DATA);
381     }
382     else
383     {
384         return CADetachSendMessage(object, requestInfo, CA_REQUEST_DATA);
385     }
386 }
387
388 CAResult_t CASendResponse(const CAEndpoint_t *object, const CAResponseInfo_t *responseInfo)
389 {
390     OIC_LOG(DEBUG, TAG, "CASendResponse");
391
392     if (!g_isInitialized)
393     {
394         return CA_STATUS_NOT_INITIALIZED;
395     }
396
397     if (!responseInfo || !object)
398     {
399         return CA_STATUS_INVALID_PARAM;
400     }
401
402     if (responseInfo->isMulticast &&
403             (object->adapter == CA_DEFAULT_ADAPTER || object->adapter == CA_ALL_ADAPTERS))
404     {
405         return CASendMessageMultiAdapter(object, responseInfo, responseInfo->info.dataType);
406     }
407     else
408     {
409         return CADetachSendMessage(object, responseInfo, responseInfo->info.dataType);
410     }
411 }
412
413 CAResult_t CASelectNetwork(CATransportAdapter_t interestedNetwork)
414 {
415     OIC_LOG_V(DEBUG, TAG, "Selected network : %d", interestedNetwork);
416
417     if (!g_isInitialized)
418     {
419         return CA_STATUS_NOT_INITIALIZED;
420     }
421
422     CAResult_t res = CA_STATUS_OK;
423
424     if (interestedNetwork & CA_ADAPTER_IP)
425     {
426         res = CAAddNetworkType(CA_ADAPTER_IP);
427         OIC_LOG_V(DEBUG, TAG, "CAAddNetworkType(CA_IP_ADAPTER) function returns result: %d", res);
428     }
429     else if (interestedNetwork & CA_ADAPTER_RFCOMM_BTEDR)
430     {
431         res = CAAddNetworkType(CA_ADAPTER_RFCOMM_BTEDR);
432         OIC_LOG_V(DEBUG, TAG, "CAAddNetworkType(CA_RFCOMM_ADAPTER) function returns result : %d", res);
433     }
434     else if (interestedNetwork & CA_ADAPTER_GATT_BTLE)
435     {
436         res = CAAddNetworkType(CA_ADAPTER_GATT_BTLE);
437         OIC_LOG_V(DEBUG, TAG, "CAAddNetworkType(CA_GATT_ADAPTER) function returns result : %d", res);
438     }
439
440 #ifdef RA_ADAPTER
441     else if (interestedNetwork & CA_ADAPTER_REMOTE_ACCESS)
442     {
443         res = CAAddNetworkType(CA_ADAPTER_REMOTE_ACCESS);
444         OIC_LOG_V(DEBUG, TAG,
445                   "CAAddNetworkType(CA_ADAPTER_REMOTE_ACCESS) function returns result : %d", res);
446     }
447 #endif
448
449 #ifdef TCP_ADAPTER
450     else if (interestedNetwork & CA_ADAPTER_TCP)
451     {
452         res = CAAddNetworkType(CA_ADAPTER_TCP);
453         OIC_LOG_V(DEBUG, TAG,
454                   "CAAddNetworkType(CA_ADAPTER_TCP) function returns result : %d", res);
455     }
456 #endif
457     else if (interestedNetwork & CA_ADAPTER_NFC)
458     {
459         res = CAAddNetworkType(CA_ADAPTER_NFC);
460         OIC_LOG_V(DEBUG, TAG, "CAAddNetworkType(CA_ADAPTER_NFC) function returns result : %d", res);
461     }
462     else
463     {
464         res = CA_NOT_SUPPORTED;
465     }
466     return res;
467 }
468
469 CAResult_t CAUnSelectNetwork(CATransportAdapter_t nonInterestedNetwork)
470 {
471     OIC_LOG_V(DEBUG, TAG, "unselected network : %d", nonInterestedNetwork);
472
473     if (!g_isInitialized)
474     {
475         return CA_STATUS_NOT_INITIALIZED;
476     }
477
478     CAResult_t res = CA_STATUS_OK;
479
480     if (nonInterestedNetwork & CA_ADAPTER_IP)
481     {
482         res = CARemoveNetworkType(CA_ADAPTER_IP);
483         OIC_LOG_V(DEBUG, TAG, "CARemoveNetworkType(CA_IP_ADAPTER) function returns result : %d", res);
484     }
485     else if (nonInterestedNetwork & CA_ADAPTER_RFCOMM_BTEDR)
486     {
487         res = CARemoveNetworkType(CA_ADAPTER_RFCOMM_BTEDR);
488         OIC_LOG_V(DEBUG, TAG, "CARemoveNetworkType(CA_RFCOMM_ADAPTER) function returns result : %d", res);
489     }
490     else if (nonInterestedNetwork & CA_ADAPTER_GATT_BTLE)
491     {
492         res = CARemoveNetworkType(CA_ADAPTER_GATT_BTLE);
493         OIC_LOG_V(DEBUG, TAG, "CARemoveNetworkType(CA_GATT_ADAPTER) function returns result : %d", res);
494     }
495 #ifdef RA_ADAPTER
496     else if (nonInterestedNetwork & CA_ADAPTER_REMOTE_ACCESS)
497     {
498         res = CARemoveNetworkType(CA_ADAPTER_REMOTE_ACCESS);
499         OIC_LOG_V(DEBUG, TAG, "CARemoveNetworkType(CA_ADAPTER_REMOTE_ACCESS) function returns result : %d",
500                   res);
501     }
502 #endif
503
504
505 #ifdef TCP_ADAPTER
506     else if (nonInterestedNetwork & CA_ADAPTER_TCP)
507     {
508         res = CARemoveNetworkType(CA_ADAPTER_TCP);
509         OIC_LOG_V(DEBUG, TAG, "CARemoveNetworkType(CA_ADAPTER_TCP) function returns result : %d",
510                   res);
511     }
512 #endif
513
514     else
515     {
516         res = CA_STATUS_FAILED;
517     }
518     return res;
519 }
520
521 CAResult_t CAHandleRequestResponse()
522 {
523     if (!g_isInitialized)
524     {
525         OIC_LOG(ERROR, TAG, "not initialized");
526         return CA_STATUS_NOT_INITIALIZED;
527     }
528
529     CAHandleRequestResponseCallbacks();
530
531     return CA_STATUS_OK;
532 }
533
534 #if defined (__WITH_DTLS__) || defined(__WITH_TLS__)
535 CAResult_t CASelectCipherSuite(const uint16_t cipher, CATransportAdapter_t adapter)
536 {
537     OIC_LOG_V(DEBUG, TAG, "IN CASelectCipherSuite");
538     OIC_LOG_V(DEBUG, TAG, "cipher : %d , CATransportAdapter : %d",cipher, adapter);
539     if(CA_ADAPTER_IP == adapter)
540     {
541         if (CA_STATUS_OK != CADtlsSelectCipherSuite(cipher))
542         {
543             OIC_LOG_V(DEBUG, TAG, "CADtlsSelectCipherSuite failed");
544             return CA_STATUS_FAILED;
545         }
546     }
547 #ifdef __WITH_TLS__
548     else if(CA_ADAPTER_TCP == adapter)
549     {
550         if (CA_STATUS_OK != CAsetTlsCipherSuite(cipher))
551         {
552             OIC_LOG_V(DEBUG, TAG, "CAsetTlsCipherSuite failed");
553             return CA_STATUS_FAILED;
554         }
555     }
556 #endif
557     OIC_LOG_V(DEBUG, TAG, "CASelectCipherSuite OK");
558     return CA_STATUS_OK;
559 }
560
561 CAResult_t CAEnableAnonECDHCipherSuite(const bool enable)
562 {
563     OIC_LOG_V(DEBUG, TAG, "CAEnableAnonECDHCipherSuite");
564
565 #ifdef __WITH_DTLS__
566     if (CA_STATUS_OK != CADtlsEnableAnonECDHCipherSuite(enable))
567     {
568         return CA_STATUS_FAILED;
569     }
570 #endif
571 #ifdef __WITH_TLS__
572     // TLS_ECDH_ANON_WITH_AES_128_CBC_SHA256    0xFF00 replaces 0xC018
573     // TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256    0xC037
574     if (CA_STATUS_OK != CAsetTlsCipherSuite(enable ? 0xFF00 : 0xC037))
575     {
576         return CA_STATUS_FAILED;
577     }
578 #endif
579     return CA_STATUS_OK;
580 }
581
582 CAResult_t CAGenerateOwnerPSK(const CAEndpoint_t* endpoint,
583                     const uint8_t* label, const size_t labelLen,
584                     const uint8_t* rsrcServerDeviceID, const size_t rsrcServerDeviceIDLen,
585                     const uint8_t* provServerDeviceID, const size_t provServerDeviceIDLen,
586                     uint8_t* ownerPSK, const size_t ownerPSKSize)
587 {
588     OIC_LOG_V(DEBUG, TAG, "IN : CAGenerateOwnerPSK");
589
590     CAResult_t res = CA_STATUS_OK;
591
592     //newOwnerLabel and prevOwnerLabe can be NULL
593     if (!endpoint || !label || 0 == labelLen || !ownerPSK || 0 == ownerPSKSize)
594     {
595         return CA_STATUS_INVALID_PARAM;
596     }
597
598     if(CA_ADAPTER_IP == endpoint->adapter)
599     {
600         res = CADtlsGenerateOwnerPSK(endpoint, label, labelLen,
601                                       rsrcServerDeviceID, rsrcServerDeviceIDLen,
602                                       provServerDeviceID, provServerDeviceIDLen,
603                                       ownerPSK, ownerPSKSize);
604     }
605 #ifdef __WITH_TLS__
606     else
607     {
608         res = CAtlsGenerateOwnerPSK(endpoint, ownerPSK, ownerPSKSize,
609                 rsrcServerDeviceID, rsrcServerDeviceIDLen);
610     }
611 #endif
612     if (CA_STATUS_OK != res)
613     {
614         OIC_LOG_V(ERROR, TAG, "Failed to CAGenerateOwnerPSK : %d", res);
615     }
616
617     OIC_LOG_V(DEBUG, TAG, "OUT : CAGenerateOwnerPSK");
618
619     return res;
620 }
621
622 CAResult_t CAInitiateHandshake(const CAEndpoint_t *endpoint)
623 {
624     OIC_LOG_V(DEBUG, TAG, "IN : CAInitiateHandshake");
625     CAResult_t res = CA_STATUS_OK;
626
627     if (!endpoint)
628     {
629         return CA_STATUS_INVALID_PARAM;
630     }
631
632     res = CADtlsInitiateHandshake(endpoint);
633     if (CA_STATUS_OK != res)
634     {
635         OIC_LOG_V(ERROR, TAG, "Failed to CADtlsInitiateHandshake : %d", res);
636     }
637
638     OIC_LOG_V(DEBUG, TAG, "OUT : CAInitiateHandshake");
639
640     return res;
641 }
642
643 CAResult_t CACloseDtlsSession(const CAEndpoint_t *endpoint)
644 {
645     OIC_LOG_V(DEBUG, TAG, "IN : CACloseDtlsSession");
646     CAResult_t res = CA_STATUS_OK;
647
648     if (!endpoint)
649     {
650         return CA_STATUS_INVALID_PARAM;
651     }
652
653     res = CADtlsClose(endpoint);
654     if (CA_STATUS_OK != res)
655     {
656         OIC_LOG_V(ERROR, TAG, "Failed to CADtlsClose : %d", res);
657     }
658
659     OIC_LOG_V(DEBUG, TAG, "OUT : CACloseDtlsSession");
660
661     return res;
662 }
663
664 #endif /* __WITH_DTLS__ */
665
666 #ifdef TCP_ADAPTER
667 void CARegisterKeepAliveHandler(CAKeepAliveConnectionCallback ConnHandler)
668 {
669     CATCPSetKeepAliveCallbacks(ConnHandler);
670 }
671 #endif