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 ******************************************************************/
25 #include "cawifiadapter.h"
30 #include "cawificore.h"
36 // received packet callback
37 static CANetworkPacketReceivedCallback gWifiReceivedCallback = NULL;
39 static void CAWiFiPacketReceiveCallback(const char* address, const char* data)
42 "CAWiFiPacketReceiveCallback, from: %s, data: %s", address, data);
45 if (gWifiReceivedCallback != NULL)
47 CARemoteEndpoint_t* endpoint = NULL;
48 endpoint = (CARemoteEndpoint_t*) OICMalloc(sizeof(CARemoteEndpoint_t));
51 memset((void*) endpoint->addressInfo.IP.ipAddress, 0, CA_IPADDR_SIZE);
52 if (CA_IPADDR_SIZE > strlen(address))
53 strcpy((char*) endpoint->addressInfo.IP.ipAddress, address);
55 // set connectivity type
56 endpoint->connectivityType = CA_WIFI;
58 gWifiReceivedCallback(endpoint, data, strlen(data));
62 CAResult_t CAInitializeWifi(CARegisterConnectivityCallback registerCallback,
63 CANetworkPacketReceivedCallback reqRespCallback, CANetworkChangeCallback netCallback)
65 OIC_LOG(DEBUG, TAG, "IntializeWifi");
67 gWifiReceivedCallback = reqRespCallback;
70 CAConnectivityHandler_t handler;
71 memset(&handler, 0, sizeof(CAConnectivityHandler_t));
73 handler.startAdapter = CAStartWIFI;
74 handler.startListenServer = CAStartWIFIListeningServer;
75 handler.startDiscoverServer = CAStartWIFIDiscoveryServer;
76 handler.sendData = CASendWIFIUnicastData;
77 handler.sendDataToAll = CASendWIFIMulticastData;
78 handler.startNotifyServer = CAStartWIFINotifyRecvServers;
79 handler.sendNotification = CASendWIFINotification;
80 handler.GetnetInfo = CAGetWIFIInterfaceInformation;
81 handler.readData = CAReadWIFIData;
82 handler.stopAdapter = CAStopWIFI;
83 handler.terminate = CATerminateWIfI;
85 registerCallback(handler, CA_WIFI);
87 CAWiFiSetCallback(CAWiFiPacketReceiveCallback);
92 void CATerminateWIfI()
94 OIC_LOG(DEBUG, TAG, "TerminateWifi");
99 CAResult_t CAStartWIFI()
101 OIC_LOG(DEBUG, TAG, "CAStartWIFI");
104 OIC_LOG(DEBUG, TAG, "CAWiFiStartUnicastServer");
105 CAWiFiStartUnicastServer("0.0.0.0", atoi("5283"));
110 CAResult_t CAStopWIFI()
112 OIC_LOG(DEBUG, TAG, "CAStopWIFI");
119 CAResult_t CAStartWIFIListeningServer()
121 OIC_LOG(DEBUG, TAG, "StartWIFIListeningServer");
123 CAWiFiStartMulticastServer("0.0.0.0", atoi("5283"));
128 CAResult_t CAStartWIFIDiscoveryServer()
130 OIC_LOG(DEBUG, TAG, "StartWIFIDiscoveryServer");
132 CAWiFiStartMulticastServer("0.0.0.0", atoi("5283"));
137 uint32_t CASendWIFIUnicastData(const CARemoteEndpoint_t* endpoint, void* data, uint32_t dataLen)
139 OIC_LOG(DEBUG, TAG, "SendWIFIUnicastData");
141 CAWiFiSendUnicastMessage(endpoint->addressInfo.IP.ipAddress, data, dataLen);
146 uint32_t CASendWIFIMulticastData(void* data, uint32_t dataLen)
148 OIC_LOG(DEBUG, TAG, "CASendWIFIMulticastData");
150 CAWiFiSendMulticastMessage("0.0.0.0", (char*) data);
155 CAResult_t CAStartWIFINotifyRecvServers()
157 OIC_LOG(DEBUG, TAG, "StartWIFINotifyRecvServers");
164 uint32_t CASendWIFINotification(const CARemoteEndpoint_t* endpoint, void* data, uint32_t dataLen)
166 OIC_LOG(DEBUG, TAG, "SendWIFINotification");
173 CAResult_t CAGetWIFIInterfaceInformation(CALocalConnectivityt_t** info, uint32_t* size)
175 OIC_LOG(DEBUG, TAG, "GetWIFIInterfaceInformation");
182 CAResult_t CAReadWIFIData()
184 OIC_LOG(DEBUG, TAG, "Read WIFI Data");