1 /******************************************************************
3 * Copyright 2014 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 ******************************************************************/
20 #include "cawifiadapter.h"
27 #include "cawifiinterface.h"
28 #include "caqueueingthread.h"
29 #include "caadapterutils.h"
31 #include "caadapternetdtls.h"
35 #include "oic_malloc.h"
38 * @def WIFI_ADAPTER_TAG
39 * @brief Logging tag for module name
41 #define WIFI_ADAPTER_TAG "WIFI_ADAP"
45 * @brief Unicast port number (to listen for incoming data on unicast server).
46 * Note :- Actual port number may differ based on result of bind() operation.
52 * @brief Secured (unicast) port number as defined in COAP Specification, RFC-7252.
54 #define CA_SECURE_PORT 5684
58 * @brief Multicast port number as defined in COAP Specification, RFC-7252.
60 #define CA_MCAST_PORT 5683
63 * @def CA_MULTICAST_IP
64 * @brief Multicast IP Address as defined in COAP Specification, RFC-7252.
66 #define CA_MULTICAST_IP "224.0.1.187"
70 CARemoteEndpoint_t *remoteEndpoint;
76 * @var g_networkPacketCallback
77 * @brief Network Packet Received Callback to CA
79 static CANetworkPacketReceivedCallback g_networkPacketCallback = NULL;
82 * @var gNetworkChangeCb
83 * @brief Network Changed Callback to CA
85 static CANetworkChangeCallback g_networkChangeCallback = NULL;
88 * @var g_isMulticastServerStarted
89 * @brief Flag to check if multicast server is started
91 static bool g_isMulticastServerStarted = false;
94 * @var gIsStartServerCalled
95 * @brief Flag to check if server start requested by CA.
97 static bool g_startUnicastServerRequested = false;
100 * @var g_unicastServerport
101 * @brief port number on which unicast server is running.
103 static int16_t g_unicastServerport = 0;
107 * @var g_secureUnicastServerport
108 * @brief port number on which secure unicast server is running.
110 static int16_t g_secureUnicastServerport = 0;
114 * @var gIsStartServerCalled
115 * @brief Flag to check if server start requested by CA.
117 static bool g_startMulticastServerRequested = false;
120 * @var g_sendQueueHandle
121 * @brief Queue handle for Send Data
123 static CAQueueingThread_t *g_sendQueueHandle = NULL;
127 * @brief ThreadPool for storing u_thread_pool_t handle passed from CA
129 static u_thread_pool_t g_threadPool = NULL;
131 static CAResult_t CAWiFiInitializeQueueHandles();
132 static void CAWiFiDeinitializeQueueHandles();
133 static void CAWiFiNotifyNetworkChange(const char *address, uint16_t port,
134 CANetworkStatus_t status);
135 static void CAWiFiConnectionStateCB(const char *ipAddress,
136 CANetworkStatus_t status);
137 static void CAWiFiPacketReceivedCB(const char *ipAddress, uint16_t port,
138 const void *data, uint32_t dataLength,
142 static uint32_t CAWiFiPacketSendCB(const char *ipAddress, uint16_t port,
143 const void *data, uint32_t dataLength);
145 static CAResult_t CAWiFiStopServers();
146 static void CAWiFiSendDataThread(void *threadData);
147 static CAWiFiData *CACreateWiFiData(const CARemoteEndpoint_t *remoteEndpoint, const void *data,
148 uint32_t dataLength);
149 void CAFreeWiFiData(CAWiFiData *wifiData);
151 static void CADataDestroyer(void *data, uint32_t size);
153 CAResult_t CAWiFiInitializeQueueHandles()
155 OIC_LOG(DEBUG, WIFI_ADAPTER_TAG, "IN");
157 // Check if the message queue is already initialized
158 if (g_sendQueueHandle)
160 OIC_LOG(DEBUG, WIFI_ADAPTER_TAG, "send queue handle is already initialized!");
164 // Create send message queue
165 g_sendQueueHandle = OICMalloc(sizeof(CAQueueingThread_t));
166 if (!g_sendQueueHandle)
168 OIC_LOG(ERROR, WIFI_ADAPTER_TAG, "Memory allocation failed!");
169 return CA_MEMORY_ALLOC_FAILED;
172 if (CA_STATUS_OK != CAQueueingThreadInitialize(g_sendQueueHandle, g_threadPool,
173 CAWiFiSendDataThread, CADataDestroyer))
175 OIC_LOG(ERROR, WIFI_ADAPTER_TAG, "Failed to Initialize send queue thread");
176 OICFree(g_sendQueueHandle);
177 g_sendQueueHandle = NULL;
178 return CA_STATUS_FAILED;
181 OIC_LOG(DEBUG, WIFI_ADAPTER_TAG, "OUT");
185 void CAWiFiDeinitializeQueueHandles()
187 OIC_LOG(DEBUG, WIFI_ADAPTER_TAG, "IN");
189 CAQueueingThreadDestroy(g_sendQueueHandle);
190 OICFree(g_sendQueueHandle);
191 g_sendQueueHandle = NULL;
193 OIC_LOG(DEBUG, WIFI_ADAPTER_TAG, "OUT");
196 void CAWiFiNotifyNetworkChange(const char *address, uint16_t port,
197 CANetworkStatus_t status)
199 OIC_LOG(DEBUG, WIFI_ADAPTER_TAG, "IN");
201 CALocalConnectivity_t *localEndpoint = CAAdapterCreateLocalEndpoint(CA_WIFI, address);
204 OIC_LOG_V(ERROR, WIFI_ADAPTER_TAG, "Out of memory");
208 localEndpoint->addressInfo.IP.port = port;
209 if (NULL != g_networkChangeCallback)
211 g_networkChangeCallback(localEndpoint, status);
214 CAAdapterFreeLocalEndpoint(localEndpoint);
217 void CAWiFiConnectionStateCB(const char *ipAddress,
218 CANetworkStatus_t status)
220 OIC_LOG(DEBUG, WIFI_ADAPTER_TAG, "IN");
222 CAResult_t ret = CA_STATUS_FAILED;
225 * If Wifi is connected, then get the latest IP from the WIFI Interface
226 * and start unicast and multicast servers if requested earlier
228 if (CA_INTERFACE_UP == status)
230 uint16_t port = CA_PORT;
231 int32_t serverFd = -1;
233 // Start Unicast server if requested earlier
234 if (g_startUnicastServerRequested)
236 ret = CAWiFiStartUnicastServer("0.0.0.0", &port, false, false, &serverFd);
237 if (CA_STATUS_OK == ret)
239 OIC_LOG_V(DEBUG, WIFI_ADAPTER_TAG, "Unicast server started on %d port", port);
240 CAWiFiSetUnicastSocket(serverFd);
241 g_unicastServerport = port;
245 OIC_LOG_V(ERROR, WIFI_ADAPTER_TAG, "Failed to start Unicast server [%d]", ret);
249 port = CA_SECURE_PORT;
250 ret = CAWiFiStartUnicastServer("0.0.0.0", &port, false, true, &serverFd);
251 if (CA_STATUS_OK == ret)
253 OIC_LOG_V(DEBUG, WIFI_ADAPTER_TAG, "Secure Unicast server started on %d", port);
254 CAWiFiSetSecureUnicastSocket(serverFd);
255 g_secureUnicastServerport = port;
259 OIC_LOG_V(ERROR, WIFI_ADAPTER_TAG, "Failed to start secure Unicast server [%d]",
265 // Start Multicast server if requested earlier
266 if (g_startMulticastServerRequested)
268 uint16_t multicastPort = CA_MCAST_PORT;
269 int32_t multicastFd = 0;
270 ret = CAWiFiStartMulticastServer("0.0.0.0", CA_MULTICAST_IP, multicastPort,
272 if (CA_STATUS_OK == ret)
274 OIC_LOG_V(DEBUG, WIFI_ADAPTER_TAG, "Multicast server started on %d port",
276 g_isMulticastServerStarted = true;
280 OIC_LOG_V(ERROR, WIFI_ADAPTER_TAG, "Failed to start Multicast server [%d]", ret);
284 char *address = NULL;
285 char *ifcName = NULL;
286 ret = CAWiFiGetInterfaceInfo(&ifcName, &address);
287 if (CA_STATUS_OK != ret || NULL == address)
289 OIC_LOG_V(ERROR, WIFI_ADAPTER_TAG, "Failed to get interface info [%d]", ret);
301 // Notify network change to CA
302 CAWiFiNotifyNetworkChange(address, port, status);
314 CAWiFiNotifyNetworkChange("", 0, status);
316 // Stop Unicast, Secured unicast and Multicast servers
320 OIC_LOG(DEBUG, WIFI_ADAPTER_TAG, "OUT");
324 uint32_t CAWiFiPacketSendCB(const char *ipAddress, uint16_t port,
325 const void *data, uint32_t dataLength)
327 OIC_LOG(DEBUG, WIFI_ADAPTER_TAG, "IN");
329 uint32_t sentLength = CAWiFiSendData(ipAddress, port, data, dataLength, false, true);
331 OIC_LOG_V(DEBUG, WIFI_ADAPTER_TAG, "Successfully sent %d of encrypted data!", sentLength);
337 void CAWiFiPacketReceivedCB(const char *ipAddress, uint16_t port,
338 const void *data, uint32_t dataLength, bool isSecured)
340 OIC_LOG(DEBUG, WIFI_ADAPTER_TAG, "IN");
341 OIC_LOG_V(DEBUG, WIFI_ADAPTER_TAG, "Address: %s, port:%d, data:%s", ipAddress, port, data);
343 // CA is freeing this memory
344 CARemoteEndpoint_t *endPoint = CAAdapterCreateRemoteEndpoint(CA_WIFI, ipAddress, NULL);
345 if (NULL == endPoint)
347 OIC_LOG(ERROR, WIFI_ADAPTER_TAG, "Out of memory");
350 endPoint->addressInfo.IP.port = port;
351 endPoint->isSecured = isSecured;
353 void *buf = OICMalloc(dataLength);
356 OIC_LOG(ERROR, WIFI_ADAPTER_TAG, "Out of memory");
357 CAAdapterFreeRemoteEndpoint(endPoint);
361 memcpy(buf, data, dataLength);
363 if (g_networkPacketCallback)
365 g_networkPacketCallback(endPoint, buf, dataLength);
370 CAAdapterFreeRemoteEndpoint(endPoint);
372 OIC_LOG(DEBUG, WIFI_ADAPTER_TAG, "OUT");
375 CAResult_t CAInitializeWIFI(CARegisterConnectivityCallback registerCallback,
376 CANetworkPacketReceivedCallback networkPacketCallback,
377 CANetworkChangeCallback netCallback, u_thread_pool_t handle)
379 OIC_LOG(DEBUG, WIFI_ADAPTER_TAG, "IN");
380 VERIFY_NON_NULL(registerCallback, WIFI_ADAPTER_TAG, "registerCallback");
381 VERIFY_NON_NULL(networkPacketCallback, WIFI_ADAPTER_TAG, "networkPacketCallback");
382 VERIFY_NON_NULL(netCallback, WIFI_ADAPTER_TAG, "netCallback");
383 VERIFY_NON_NULL(handle, WIFI_ADAPTER_TAG, "thread pool handle");
385 g_threadPool = handle;
386 g_networkChangeCallback = netCallback;
387 g_networkPacketCallback = networkPacketCallback;
389 CAResult_t ret = CAWiFiInitializeNetworkMonitor(g_threadPool);
390 if (CA_STATUS_OK != ret)
392 OIC_LOG_V(ERROR, WIFI_ADAPTER_TAG, "Failed to initialize n/w monitor![%d]", ret);
395 CAWiFiSetConnectionStateChangeCallback(CAWiFiConnectionStateCB);
397 ret = CAWiFiInitializeServer(g_threadPool);
398 if (CA_STATUS_OK != ret)
400 OIC_LOG_V(ERROR, WIFI_ADAPTER_TAG, "Failed to initialize server![%d]", ret);
405 CAWiFiSetPacketReceiveCallback(CAWiFiPacketReceivedCB);
407 CAAdapterNetDtlsInit();
408 CADTLSSetAdapterCallbacks(CAWiFiPacketReceivedCB, CAWiFiPacketSendCB, DTLS_WIFI);
411 CAConnectivityHandler_t wifiHandler;
412 wifiHandler.startAdapter = CAStartWIFI;
413 wifiHandler.startListenServer = CAStartWIFIListeningServer;
414 wifiHandler.startDiscoveryServer = CAStartWIFIDiscoveryServer;
415 wifiHandler.sendData = CASendWIFIUnicastData;
416 wifiHandler.sendDataToAll = CASendWIFIMulticastData;
417 wifiHandler.GetnetInfo = CAGetWIFIInterfaceInformation;
418 wifiHandler.readData = CAReadWIFIData;
419 wifiHandler.stopAdapter = CAStopWIFI;
420 wifiHandler.terminate = CATerminateWIFI;
421 registerCallback(wifiHandler, CA_WIFI);
423 if (CA_STATUS_OK != CAWiFiInitializeQueueHandles())
425 OIC_LOG(ERROR, WIFI_ADAPTER_TAG, "Failed to Initialize Queue Handle");
427 return CA_STATUS_FAILED;
430 OIC_LOG(INFO, WIFI_ADAPTER_TAG, "Intialize WIFI is Success");
434 CAResult_t CAStartWIFI()
436 OIC_LOG(DEBUG, WIFI_ADAPTER_TAG, "IN");
438 // Start monitoring wifi network
439 CAResult_t ret = CAWiFiStartNetworkMonitor();
440 if (CA_STATUS_OK != ret)
442 OIC_LOG(ERROR, WIFI_ADAPTER_TAG, "Failed to Start n/w monitor");
446 // Start send queue thread
447 if (CA_STATUS_OK != CAQueueingThreadStart(g_sendQueueHandle))
449 OIC_LOG(ERROR, WIFI_ADAPTER_TAG, "Failed to Start Send Data Thread");
451 return CA_STATUS_FAILED;
454 g_startUnicastServerRequested = true;
455 bool retVal = CAWiFiIsConnected();
458 OIC_LOG(ERROR, WIFI_ADAPTER_TAG, "WIFI is not Connected");
462 char *ifcName = NULL;
463 char *ifcAdrs = NULL;
464 ret = CAWiFiGetInterfaceInfo(&ifcName, &ifcAdrs);
465 if (CA_STATUS_OK != ret)
467 OIC_LOG_V(DEBUG, WIFI_ADAPTER_TAG, "Failed to get wifi interface info [%d]", ret);
471 uint16_t unicastPort = CA_PORT;
472 int32_t serverFd = 0;
473 // Address is hardcoded as we are using Single Interface
474 ret = CAWiFiStartUnicastServer(ifcAdrs, &unicastPort, false, false, &serverFd);
475 if (CA_STATUS_OK == ret)
477 OIC_LOG_V(DEBUG, WIFI_ADAPTER_TAG, "Unicast server started on %d port", unicastPort);
478 CAWiFiSetUnicastSocket(serverFd);
479 g_unicastServerport = unicastPort;
483 // Address is hardcoded as we are using Single Interface
484 unicastPort = CA_SECURE_PORT;
485 ret = CAWiFiStartUnicastServer(ifcAdrs, &unicastPort, false, true, &serverFd);
486 if (CA_STATUS_OK == ret)
488 OIC_LOG_V(DEBUG, WIFI_ADAPTER_TAG, "Secure Unicast server started on %d port", unicastPort);
489 CAWiFiSetSecureUnicastSocket(serverFd);
490 g_secureUnicastServerport = unicastPort;
497 OIC_LOG(DEBUG, WIFI_ADAPTER_TAG, "OUT");
501 CAResult_t CAStartWIFIListeningServer()
503 OIC_LOG(DEBUG, WIFI_ADAPTER_TAG, "IN");
505 CAResult_t ret = CA_STATUS_OK;
506 int16_t multicastPort = CA_MCAST_PORT;
508 if (g_isMulticastServerStarted == true)
510 OIC_LOG_V(ERROR, WIFI_ADAPTER_TAG,
511 "Failed to Start Multicast Server, Already Started!");
512 return CA_SERVER_STARTED_ALREADY;
515 g_startMulticastServerRequested = true;
516 bool retVal = CAWiFiIsConnected();
519 OIC_LOG_V(ERROR, WIFI_ADAPTER_TAG,
520 "Failed to Start Multicast Server, WIFI not Connected");
524 char *ifcName = NULL;
525 char *ifcAdrs = NULL;
526 ret = CAWiFiGetInterfaceInfo(&ifcName, &ifcAdrs);
527 if (CA_STATUS_OK != ret)
529 OIC_LOG_V(DEBUG, WIFI_ADAPTER_TAG, "Failed to get wifi interface info [%d]", ret);
533 int32_t multicastFd = 0;
534 ret = CAWiFiStartMulticastServer(ifcAdrs, CA_MULTICAST_IP, multicastPort, &multicastFd);
535 if (CA_STATUS_OK == ret)
537 OIC_LOG(INFO, WIFI_ADAPTER_TAG, "Multicast Server is Started Successfully");
538 g_isMulticastServerStarted = true;
544 OIC_LOG(DEBUG, WIFI_ADAPTER_TAG, "OUT");
548 CAResult_t CAStartWIFIDiscoveryServer()
550 OIC_LOG(DEBUG, WIFI_ADAPTER_TAG, "IN");
551 return CAStartWIFIListeningServer();
552 OIC_LOG(DEBUG, WIFI_ADAPTER_TAG, "OUT");
555 int32_t CASendWIFIData(const CARemoteEndpoint_t *remoteEndpoint, const void *data, uint32_t dataLength)
557 OIC_LOG(DEBUG, WIFI_ADAPTER_TAG, "IN");
559 int32_t dataSize = -1;
560 VERIFY_NON_NULL_RET(data, WIFI_ADAPTER_TAG, "data", dataSize);
561 VERIFY_NON_NULL_RET(g_sendQueueHandle, WIFI_ADAPTER_TAG, "sendQueueHandle", dataSize);
565 OIC_LOG_V(ERROR, WIFI_ADAPTER_TAG, "Invalid Data Length");
569 // Create WifiData to add to queue
570 CAWiFiData *wifiData = CACreateWiFiData(remoteEndpoint, data, dataLength);
573 OIC_LOG_V(ERROR, WIFI_ADAPTER_TAG, "Failed to create wifidata!");
577 // Add message to send queue
578 CAQueueingThreadAddData(g_sendQueueHandle, wifiData, sizeof(CAWiFiData));
580 OIC_LOG(DEBUG, WIFI_ADAPTER_TAG, "OUT");
584 int32_t CASendWIFIUnicastData(const CARemoteEndpoint_t *remoteEndpoint, const void *data,
587 OIC_LOG(DEBUG, WIFI_ADAPTER_TAG, "IN");
589 int32_t dataSize = -1;
590 VERIFY_NON_NULL_RET(remoteEndpoint, WIFI_ADAPTER_TAG, "remoteEndpoint", dataSize);
592 dataSize = CASendWIFIData(remoteEndpoint, data, dataLength);
594 OIC_LOG(DEBUG, WIFI_ADAPTER_TAG, "OUT");
598 int32_t CASendWIFIMulticastData(const void *data, uint32_t dataLength)
600 OIC_LOG(DEBUG, WIFI_ADAPTER_TAG, "IN");
602 int32_t dataSize = CASendWIFIData(NULL, data, dataLength);
604 OIC_LOG(DEBUG, WIFI_ADAPTER_TAG, "OUT");
608 CAResult_t CAGetWIFIInterfaceInformation(CALocalConnectivity_t **info, uint32_t *size)
610 OIC_LOG(DEBUG, WIFI_ADAPTER_TAG, "IN");
611 VERIFY_NON_NULL(info, WIFI_ADAPTER_TAG, "info");
612 VERIFY_NON_NULL(size, WIFI_ADAPTER_TAG, "size");
614 CALocalConnectivity_t *netInfo = NULL;
615 bool retVal = CAWiFiIsConnected();
618 OIC_LOG_V(ERROR, WIFI_ADAPTER_TAG,
619 "Failed to get interface address, WIFI not Connected", CA_ADAPTER_NOT_ENABLED);
620 return CA_ADAPTER_NOT_ENABLED;
623 int32_t netInfoSize = 1;
625 if (g_secureUnicastServerport)
630 netInfo = (CALocalConnectivity_t *) OICCalloc(netInfoSize, sizeof(CALocalConnectivity_t));
632 VERIFY_NON_NULL_RET(netInfo, WIFI_ADAPTER_TAG, "malloc failed", CA_MEMORY_ALLOC_FAILED);
634 char *ipAddress = NULL;
635 char *ifcName = NULL;
637 CAResult_t ret = CAWiFiGetInterfaceInfo(&ifcName, &ipAddress);
638 if (CA_STATUS_OK != ret || NULL == ipAddress)
640 OIC_LOG_V(ERROR, WIFI_ADAPTER_TAG, "Failed to get interface info [%d]", ret);
649 // Create local endpoint using util function
650 CALocalConnectivity_t *endpoint = CAAdapterCreateLocalEndpoint(CA_WIFI, ipAddress);
651 if (NULL == endpoint)
653 OIC_LOG_V(ERROR, WIFI_ADAPTER_TAG, "Failed to create Local Endpoint!",
654 CA_MEMORY_ALLOC_FAILED);
659 return CA_MEMORY_ALLOC_FAILED;
662 // copy unicast server information
663 endpoint->isSecured = false;
664 endpoint->addressInfo.IP.port = g_unicastServerport;
665 memcpy(&netInfo[0], endpoint, sizeof(CALocalConnectivity_t));
668 // copy secure unicast server information
669 if (g_secureUnicastServerport)
671 endpoint->isSecured = true;
672 endpoint->addressInfo.IP.port = g_secureUnicastServerport;
673 memcpy(&netInfo[1], endpoint, sizeof(CALocalConnectivity_t));
682 CAAdapterFreeLocalEndpoint(endpoint);
684 OIC_LOG(INFO, WIFI_ADAPTER_TAG, "GetWIFIInterfaceInformation success");
685 OIC_LOG(DEBUG, WIFI_ADAPTER_TAG, "OUT");
689 CAResult_t CAReadWIFIData()
691 OIC_LOG(DEBUG, WIFI_ADAPTER_TAG, "IN");
692 OIC_LOG(DEBUG, WIFI_ADAPTER_TAG, "OUT");
696 CAResult_t CAWiFiStopServers()
698 OIC_LOG(DEBUG, WIFI_ADAPTER_TAG, "IN");
700 // Stop unicast server and set client socket accordingly
701 if (CA_STATUS_OK == CAWiFiStopUnicastServer())
703 CAWiFiSetUnicastSocket(-1);
704 g_unicastServerport = -1;
707 // Stop secure unicast server and set client socket accordingly
708 if (CA_STATUS_OK == CAWiFiStopSecureUnicastServer())
710 CAWiFiSetSecureUnicastSocket(-1);
711 g_secureUnicastServerport = -1;
715 //Stop multicast server and set the state accordingly
716 if (CA_STATUS_OK != CAWiFiStopMulticastServer())
718 g_isMulticastServerStarted = false;
721 OIC_LOG(DEBUG, WIFI_ADAPTER_TAG, "OUT");
725 CAResult_t CAStopWIFI()
727 OIC_LOG(DEBUG, WIFI_ADAPTER_TAG, "IN");
729 g_startUnicastServerRequested = false;
730 g_startMulticastServerRequested = false;
732 // Stop wifi network monitor
733 CAWiFiStopNetworkMonitor();
735 // Stop send queue thread
736 if (g_sendQueueHandle && false == g_sendQueueHandle->isStop)
738 CAQueueingThreadStop(g_sendQueueHandle);
741 // Stop Unicast, Secured unicast and Multicast servers running
744 OIC_LOG(DEBUG, WIFI_ADAPTER_TAG, "OUT");
748 void CATerminateWIFI()
750 OIC_LOG(DEBUG, WIFI_ADAPTER_TAG, "IN");
753 CADTLSSetAdapterCallbacks(NULL, NULL, DTLS_WIFI);
754 CAAdapterNetDtlsDeInit();
760 // Terminate wifi server
761 CAWiFiTerminateServer();
763 // Terminate network monitor
764 CAWiFiSetConnectionStateChangeCallback(NULL);
765 CAWiFiTerminateNetworkMonitor();
767 // Terminate message queue handler
768 CAWiFiDeinitializeQueueHandles();
770 CAWiFiSetPacketReceiveCallback(NULL);
772 OIC_LOG(DEBUG, WIFI_ADAPTER_TAG, "OUT");
776 void CAWiFiSendDataThread(void *threadData)
778 OIC_LOG(DEBUG, WIFI_ADAPTER_TAG, "IN");
780 CAWiFiData *wifiData = (CAWiFiData *) threadData;
783 OIC_LOG(DEBUG, WIFI_ADAPTER_TAG, "Invalid wifidata!");
787 if (NULL != wifiData->remoteEndpoint)
789 char *address = wifiData->remoteEndpoint->addressInfo.IP.ipAddress;
790 uint16_t port = wifiData->remoteEndpoint->addressInfo.IP.port;
793 if (!wifiData->remoteEndpoint->isSecured)
795 CAWiFiSendData(address, port, wifiData->data, wifiData->dataLen, false,
796 wifiData->remoteEndpoint->isSecured);
800 OIC_LOG(DEBUG, WIFI_ADAPTER_TAG, "CAAdapterNetDtlsEncrypt called!");
801 uint8_t cacheFalg = 0;
802 CAResult_t result = CAAdapterNetDtlsEncrypt(address, port, wifiData->data,
803 wifiData->dataLen, &cacheFalg, DTLS_WIFI);
805 if (CA_STATUS_OK != result)
807 OIC_LOG(ERROR, WIFI_ADAPTER_TAG, "CAAdapterNetDtlsEncrypt failed!");
810 OIC_LOG_V(DEBUG, WIFI_ADAPTER_TAG, "CAAdapterNetDtlsEncrypt returned with cache[%d]",
814 CAWiFiSendData(address, port, wifiData->data, wifiData->dataLen, false,
815 wifiData->remoteEndpoint->isSecured);
820 OIC_LOG(DEBUG, WIFI_ADAPTER_TAG, "Send Multicast Data is called");
821 CAWiFiSendData(CA_MULTICAST_IP, CA_MCAST_PORT, wifiData->data,
822 wifiData->dataLen, true, false);
825 OIC_LOG(DEBUG, WIFI_ADAPTER_TAG, "OUT");
829 CAWiFiData *CACreateWiFiData(const CARemoteEndpoint_t *remoteEndpoint, const void *data,
832 CAWiFiData *wifiData = (CAWiFiData *) OICMalloc(sizeof(CAWiFiData));
835 OIC_LOG(ERROR, WIFI_ADAPTER_TAG, "Memory allocation failed!");
839 wifiData->remoteEndpoint = CAAdapterCopyRemoteEndpoint(remoteEndpoint);
840 wifiData->data = OICMalloc(dataLength);
841 if (NULL == wifiData->data)
843 OIC_LOG(ERROR, WIFI_ADAPTER_TAG, "Memory allocation failed!");
844 CAAdapterFreeRemoteEndpoint(wifiData->remoteEndpoint);
845 CAFreeWiFiData(wifiData);
848 memcpy(wifiData->data, data, dataLength);
849 wifiData->dataLen = dataLength;
854 void CAFreeWiFiData(CAWiFiData *wifiData)
861 CAAdapterFreeRemoteEndpoint(wifiData->remoteEndpoint);
862 OICFree(wifiData->data);
866 void CADataDestroyer(void *data, uint32_t size)
868 CAWiFiData *wfdata = (CAWiFiData *) data;
870 CAFreeWiFiData(wfdata);