Integrated IP adapter Singlethread and Multithread files
authorvimala.v <vimala.v@samsung.com>
Wed, 1 Jul 2015 05:28:31 +0000 (10:58 +0530)
committerErich Keane <erich.keane@intel.com>
Fri, 3 Jul 2015 06:08:12 +0000 (06:08 +0000)
Removed all "_singlethread" files related to IP adapter.

Change-Id: I8a096ca6b28f74afaa8d122bf416cb4b0733f185
Signed-off-by: vimala.v <vimala.v@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1010
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Erich Keane <erich.keane@intel.com>
21 files changed:
resource/csdk/connectivity/inc/caipadapter.h
resource/csdk/connectivity/inc/caipadapter_singlethread.h [deleted file]
resource/csdk/connectivity/inc/caipinterface.h
resource/csdk/connectivity/inc/caipinterface_singlethread.h [deleted file]
resource/csdk/connectivity/samples/arduino/casample.cpp
resource/csdk/connectivity/src/cainterfacecontroller_singlethread.c
resource/csdk/connectivity/src/camessagehandler_singlethread.c
resource/csdk/connectivity/src/ip_adapter/SConscript
resource/csdk/connectivity/src/ip_adapter/arduino/SConscript
resource/csdk/connectivity/src/ip_adapter/arduino/caipadapterutils_eth.cpp
resource/csdk/connectivity/src/ip_adapter/arduino/caipadapterutils_eth.h
resource/csdk/connectivity/src/ip_adapter/arduino/caipclient_eth.cpp
resource/csdk/connectivity/src/ip_adapter/arduino/caipclient_wifi.cpp
resource/csdk/connectivity/src/ip_adapter/arduino/caipnwmonitor.cpp [deleted file]
resource/csdk/connectivity/src/ip_adapter/arduino/caipnwmonitor_eth.cpp [new file with mode: 0644]
resource/csdk/connectivity/src/ip_adapter/arduino/caipnwmonitor_wifi.cpp [new file with mode: 0644]
resource/csdk/connectivity/src/ip_adapter/arduino/caipserver_eth.cpp
resource/csdk/connectivity/src/ip_adapter/arduino/caipserver_wifi.cpp
resource/csdk/connectivity/src/ip_adapter/caipadapter.c
resource/csdk/connectivity/src/ip_adapter/caipadapter_singlethread.c [deleted file]
resource/csdk/connectivity/src/ip_adapter/caipserver.c

index dce3cca..b6aa76f 100644 (file)
@@ -39,9 +39,9 @@ extern "C"
  * @param registerCallback      [IN] Callback to register IP interfaces to Connectivity
  *                                   Abstraction Layer
  * @param networkPacketCallback [IN] Callback to notify request and response messages from server(s)
- *                                   started at Connectivity Abstraction Layer
+ *                                   started at Connectivity Abstraction Layer.
  * @param netCallback           [IN] Callback to notify the network additions to Connectivity
- *                                   Abstraction Layer
+ *                                   Abstraction Layer.
  * @param errorCallback         [IN] Callback to notify the network errors to Connectivity
  *                                   Abstraction Layer
  * @param handle                [IN] Threadpool Handle
@@ -70,7 +70,7 @@ CAResult_t CAStartIPListeningServer();
 /**
  * @brief Start discovery servers for receiving multicast advertisements
  * Transport Specific Behavior:
- * IP Starts Start multicast server on a particular interface and prefixed port
+ * IP Starts multicast server on a particular interface and prefixed port
  * number as per OIC Specification
  * @return  #CA_STATUS_OK or Appropriate error code
  */
@@ -78,23 +78,23 @@ CAResult_t CAStartIPDiscoveryServer();
 
 /**
  * @brief Sends data to the endpoint using the adapter connectivity.
- * @param   endpoint    [IN]    Remote Endpoint information (like ipaddress , port,
- * reference uri and transport type) to which the unicast data has to be sent.
+ * @param   endpoint    [IN]    Remote Endpoint information (like ipaddress , port, reference uri
+ *                              and transport type) to which the unicast data has to be sent.
  * @param   data        [IN]    Data which is required to be sent.
  * @param   dataLen     [IN]    Size of data to be sent.
- * @return The number of bytes sent on the network. Return value equal to -1 indicates error.
- * @remarks dataLen must be > 0.
+ * @return  The number of bytes sent on the network. Return value equal to -1 indicates error.
+ * @remark  dataLen must be > 0.
  */
 int32_t CASendIPUnicastData(const CAEndpoint_t *endpoint, const void *data,
-                                   uint32_t dataLen);
+                            uint32_t dataLen);
 
 /**
- * @brief Sends Multicast data to the endpoint using the IP connectivity.
+ * @brief Send Multicast data to the endpoint using the IP connectivity.
  * @param   endpoint    [IN]    Remote Endpoint information (like ipaddress , port)
- * @param   data        [IN]    Data which required to be sent.
+ * @param   data        [IN]    Data which is required to be sent.
  * @param   dataLen     [IN]    Size of data to be sent.
- * @return The number of bytes sent on the network. Return value equal to -1 indicates error.
- * @remarks dataLen must be > 0.
+ * @return  The number of bytes sent on the network. Return value equal to -1 indicates error.
+ * @remark  dataLen must be > 0.
  */
 int32_t CASendIPMulticastData(const CAEndpoint_t *endpoint, const void *data, uint32_t dataLen);
 
diff --git a/resource/csdk/connectivity/inc/caipadapter_singlethread.h b/resource/csdk/connectivity/inc/caipadapter_singlethread.h
deleted file mode 100644 (file)
index f772c88..0000000
+++ /dev/null
@@ -1,128 +0,0 @@
-/******************************************************************
- *
- * Copyright 2014 Samsung Electronics All Rights Reserved.
- *
- *
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************/
-
-/**
- * @file caipadapter_singlethread.h
- * @brief This file contains the APIs for IP Adapter.
- */
-#ifndef CA_IP_ADAPTER_SINGLETHREAD_H_
-#define CA_IP_ADAPTER_SINGLETHREAD_H_
-
-#include "cacommon.h"
-#include "caadapterinterface.h"
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-/**
- * @brief API to initialize IP Interface.
- * @param registerCallback      [IN] Callback to register IP interfaces to Connectivity
- *                                   Abstraction Layer
- * @param networkPacketCallback [IN] Callback to notify request and response messages from server(s)
- *                                   started at Connectivity Abstraction Layer.
- * @param netCallback           [IN] Callback to notify the network additions to Connectivity
- *                                   Abstraction Layer.
- * @return  #CA_STATUS_OK or Appropriate error code
- */
-CAResult_t CAInitializeIP(CARegisterConnectivityCallback registerCallback,
-                                CANetworkPacketReceivedCallback networkPacketCallback,
-                                CANetworkChangeCallback netCallback);
-
-/**
- * @brief Start IP Interface adapter.
- * @return  #CA_STATUS_OK or Appropriate error code
- */
-CAResult_t CAStartIP();
-
-/**
- * @brief Start listening server for receiving multicast search requests
- * Transport Specific Behavior:
- * IP Starts Multicast Server on  all available IPs and prefixed port number and
- * as per OIC Specification.
- * @return  #CA_STATUS_OK or Appropriate error code
- */
-CAResult_t CAStartIPListeningServer();
-
-/**
- * @brief Start discovery servers for receiving multicast advertisements
- * Transport Specific Behavior:
- * IP Starts multicast server on all available IPs and prefixed port
- * number as per OIC Specification
- * @return  #CA_STATUS_OK or Appropriate error code
- */
-CAResult_t CAStartIPDiscoveryServer();
-
-/**
- * @brief Sends data to the endpoint using the adapter connectivity.
- * @param   endpoint    [IN]    Remote Endpoint information (like ipaddress , port,
- * reference uri and connectivity type) to which the unicast data has to be sent.
- * @param   data        [IN]    Data which required to be sent.
- * @param   dataLen     [IN]    Size of data to be sent.
- * @return  The number of bytes sent on the network. Return value equal to -1 indicates error.
- * @remark  dataLen must be > 0.
- */
-int32_t CASendIPUnicastData(const CAEndpoint_t *endpoint, const void *data,
-                                  uint32_t dataLen);
-
-/**
- * @brief Send Multicast data to the endpoint using the IP connectivity.
- * @param   data        [IN]    Data which is required to be sent.
- * @param   dataLen     [IN]    Size of data to be sent.
- * @return  The number of bytes sent on the network. Return value equal to -1 indicates error.
- * @remark  dataLen must be > 0.
- */
-int32_t CASendIPMulticastData(const CAEndpoint_t *endpoint, const void *data, uint32_t dataLen);
-
-/**
- * @brief Get IP Connectivity network information
- * @param   info        [OUT]   Local connectivity information structures
- * @param   size        [OUT]   Number of local connectivity structures.
- * @return  #CA_STATUS_OK or Appropriate error code
- * @remarks info is allocated in this API and should be freed by the caller.
- */
-CAResult_t CAGetIPInterfaceInformation(CAEndpoint_t **info, uint32_t *size);
-
-/**
- * @brief Read Synchronous API callback.
- * @return  #CA_STATUS_OK or Appropriate error code
- */
-CAResult_t CAReadIPData();
-
-/**
- * @brief Stops Unicast, Multicast servers and close the sockets.
- * @return  #CA_STATUS_OK or Appropriate error code
- */
-CAResult_t CAStopIP();
-
-/**
- * @brief Terminate the Ethernet connectivity adapter.
- * Configuration information will be deleted from further use
- * @return NONE
- */
-void CATerminateIP();
-
-#ifdef __cplusplus
-} /* extern "C" */
-#endif
-
-#endif  /* CA_IP_ADAPTER_SINGLETHREAD_H_ */
-
index d55284e..085169f 100644 (file)
@@ -43,9 +43,9 @@ extern "C"
  */
 typedef enum
 {
-    CA_UNICAST_SERVER = 0,    /**< Unicast Server */
-    CA_MULTICAST_SERVER,      /**< Multicast Server */
-    CA_SECURED_UNICAST_SERVER /**< Secured Unicast Server */
+    CA_UNICAST_SERVER = 0,      /**< Unicast Server */
+    CA_MULTICAST_SERVER,        /**< Multicast Server */
+    CA_SECURED_UNICAST_SERVER   /**< Secured Unicast Server */
 } CAAdapterServerType_t;
 
 /**
@@ -225,6 +225,22 @@ void CAIPSetPacketReceiveCallback(CAIPPacketReceivedCallback callback);
 void CAIPSetExceptionCallback(CAIPExceptionCallback callback);
 
 /**
+ * @brief  Set socket description for sending unicast UDP data. Once the Unicast server is started,
+ *         the same socket descriptor is used for sending the Unicast UDP data.
+ *
+ * @param  socketFD [IN]  Socket descriptor used for sending UDP data.
+ * @return  NONE
+ */
+void CAIPSetUnicastSocket(int socketFD);
+
+/**
+ * @brief  Set the port number for sending unicast UDP data
+ * @param  port [IN] Port number used for sending UDP data.
+ * @return NONE
+ */
+void CAIPSetUnicastPort(uint16_t port);
+
+/**
  * @brief  API to send unicast UDP data
  *
  * @param  endpoint         [IN] complete network address to send to
@@ -288,6 +304,12 @@ CAResult_t CAIPStartNetworkMonitor();
 CAResult_t CAIPStopNetworkMonitor();
 
 /**
+ * @brief  Pull the Received Data
+ * @return NONE
+ */
+void CAIPPullData();
+
+/**
  * @brief  Get local adapter network information.
  *
  * @param  netInterfaceList [OUT] network interface information list
diff --git a/resource/csdk/connectivity/inc/caipinterface_singlethread.h b/resource/csdk/connectivity/inc/caipinterface_singlethread.h
deleted file mode 100644 (file)
index 69133c3..0000000
+++ /dev/null
@@ -1,307 +0,0 @@
-/******************************************************************
-*
-* Copyright 2014 Samsung Electronics All Rights Reserved.
-*
-*
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*      http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*
-******************************************************************/
-
-/**
- * @file caipinterface_singlethread.h
- * @brief This file provides APIs IP client/server/network monitor modules
- */
-
-#ifndef CA_IP_INTERFACE_SINGLETHREAD_H_
-#define CA_IP_INTERFACE_SINGLETHREAD_H_
-
-#include <stdbool.h>
-
-#include "cacommon.h"
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-/**
- * @enum CAAdapterServerType_t
- * @brief Enum for defining different server types.
- */
-typedef enum
-{
-    CA_UNICAST_SERVER = 0,      /**< Unicast Server */
-    CA_MULTICAST_SERVER,        /**< Multicast Server */
-    CA_SECURED_UNICAST_SERVER   /**< Secured Unicast Server */
-} CAAdapterServerType_t;
-
-/**
- * @brief Callback to be notified on reception of any data from remote OIC devices.
- * @param  ipAddress    [IN] IP address of remote OIC device.
- * @param  port         [IN] Port number on which data is received.
- * @param  data         [IN] Data received from remote OIC device.
- * @param  dataLength   [IN] Length of data in bytes.
- * @return NONE
- * @pre  Callback must be registered using CAIPSetPacketReceiveCallback()
- */
-typedef void (*CAIPPacketReceivedCallback)(const char *ipAddress, uint16_t port,
-                                                 const void *data, uint32_t dataLength);
-
-/**
- * @brief  Callback to be notified when exception occures on multicast/unicast server.
- * @param  type  [IN] Type of server(#CAAdapterServerType_t)
- * @return NONE
- * @pre  Callback must be registered using CAIPSetExceptionCallback()
- */
-typedef void (*CAIPExceptionCallback)(CAAdapterServerType_t type);
-
-/**
- * @brief  Initialize IP server
- * @return  #CA_STATUS_OK or Appropriate error code
- * @retval  #CA_STATUS_OK  Successful
- * @retval  #CA_STATUS_INVALID_PARAM Invalid input data
- * @retval  #CA_STATUS_FAILED Initialization failed
- */
-CAResult_t CAIPInitializeServer(void);
-
-/**
- * @brief  Terminate IP server
- * @return NONE
- */
-void CAIPTerminateServer(void);
-
-/**
- * @brief  Start multicast server for specified multicast address and port
- *
- * @param   localAddress        [IN]      Local adapter address to which server to be binded.
- * @param   multicastAddress    [IN]      Multicast group address.
- * @param   multicastPort       [IN,OUT]  Port number on which server will be running. If binding
-                                          the port failed, server starts in the next available port.
- * @param   serverFD            [OUT]     Multicast server socket FD.
- *
- * @return  #CA_STATUS_OK or Appropriate error code
- * @retval  #CA_STATUS_OK  Successful
- * @retval  #CA_STATUS_INVALID_PARAM Invalid input data
- * @retval  #CA_SERVER_STARTED_ALREADY Multicast server is already started and running.
- * @retval  #CA_STATUS_FAILED Operation failed
- */
-CAResult_t CAIPStartMulticastServer(const char *localAddress, const char *multicastAddress,
-                                          uint16_t multicastPort, int *serverFD);
-
-/**
- * @brief  Start unicast server for specified local address and port
- *
- * @param  localAddress [IN]      Local adapter address to which server to be binded.
- * @param  port         [IN,OUT]  Port number on which server will be running. If binding
-                                  the port failed, server starts in the next available port.
- * @param  forceStart   [IN]      Indicate whether to start server forcesfully on specified port
- *                                or not.
- * @param  serverFD     [OUT]     Unicast server socket FD.
- *
- * @return  #CA_STATUS_OK or Appropriate error code
- * @retval  #CA_STATUS_OK  Successful
- * @retval  #CA_STATUS_INVALID_PARAM Invalid input data
- * @retval  #CA_SERVER_STARTED_ALREADY Unicast server is already started and running.
- * @retval  #CA_STATUS_FAILED Operation failed
- */
-CAResult_t CAIPStartUnicastServer(const char *localAddress, uint16_t *port,
-                                        bool forceStart, int *serverFD);
-
-/**
- * @brief  Stop multicast server.
- *
- * @return  #CA_STATUS_OK or Appropriate error code
- * @retval  #CA_STATUS_OK  Successful
- * @retval  #CA_STATUS_FAILED Operation failed
- */
-CAResult_t CAIPStopMulticastServer(void);
-
-/**
- * @brief  Stop unicast server.
- *
- * @return  #CA_STATUS_OK or Appropriate error code
- * @retval  #CA_STATUS_OK  Successful
- * @retval  #CA_STATUS_FAILED Operation failed
- */
-CAResult_t CAIPStopUnicastServer();
-
-#ifdef __WITH_DTLS__
-/**
- * @brief  Stop secured unicast server.
- *
- * @return  #CA_STATUS_OK or Appropriate error code
- * @retval  #CA_STATUS_OK  Successful
- * @retval  #CA_STATUS_FAILED Operation failed
- */
-CAResult_t CAIPStopSecureUnicastServer();
-#endif
-
-/**
- * @brief  Get the Unicast Server Information if it is started
- * @param  ipAddress    [OUT] IP address on which server is binded and running.
- * @param  port         [OUT]Port number on which server is running
- * @param  serverFD     [OUT]Server socket fd.
- *
- * @return  #CA_STATUS_OK or Appropriate error code
- * @retval  #CA_STATUS_OK  Successful
- * @retval  #CA_STATUS_INVALID_PARAM Invalid input data
- * @retval  #CA_STATUS_FAILED Operation failed
- * @remarks  ipAddress must be freed using free().
- */
-CAResult_t CAIPGetUnicastServerInfo(char **ipAddress, uint16_t *port, int *serverFD);
-
-/**
- * @brief  Set this callback for receiving data packets from peer devices.
- * @param  callback   [IN] Callback to be notified on reception of unicast/multicast data packets.
- *
- * @return  NONE
- */
-void CAIPSetPacketReceiveCallback(CAIPPacketReceivedCallback callback);
-
-/**
- * @brief  Pull the Received Data
- * @return NONE
- */
-void CAIPPullData();
-
-/**
- * @brief  Set this callback for receiving exception notifications.
- *
- * @param  callback [IN] Callback to be notified on occurance of exception on running servers.
- *
- * @return  NONE
- */
-void CAIPSetExceptionCallback(CAIPExceptionCallback callback);
-
-/**
- * @brief  Set socket description for sending unicast UDP data. Once the Unicast server is started,
- *         the same socket descriptor is used for sending the Unicast UDP data.
- *
- * @param  socketFD [IN]  Socket descriptor used for sending UDP data.
- * @return  NONE
- */
-void CAIPSetUnicastSocket(int socketFD);
-
-/**
- * @brief  Set the port number for sending unicast UDP data
- * @param  port [IN] Port number used for sending UDP data.
- * @return NONE
- */
-void CAIPSetUnicastPort(uint16_t port);
-
-#ifdef __WITH_DTLS__
-/**
- * @brief  Set socket description for sending secured (encrypted) unicast UDP data
- *
- * @param socketFD [IN] Socket descriptor used for sending secured (encrypted) UDP data.
- * @return  NONE
- */
-void CAIPSetSecureUnicastSocket(int socketFD);
-#endif
-
-/**
- * @brief  API to send unicast UDP data
- *
- * @param  remoteAddress    [IN] IP address to which data needs to be sent.
- * @param  port             [IN] Port to which data needs to be send.
- * @param  buf              [IN] Data to be send.
- * @param  bufLen           [IN] Length of data in bytes
- * @param  isMulticast      [IN] Whether data needs to be sent to multicast ip
- *
- * @return  The number of bytes sent on the network. Returns 0 on error.
- */
-uint32_t CAIPSendData(const char *remoteAddress, uint16_t port,
-                            const char *buf, uint32_t bufLen, bool isMulticast);
-
-/**
- * @brief  Callback to be notified when IP adapter connection state changes.
- *
- * @param  ipAddress    [IN] IP address of remote OIC device.
- * @param  status       [IN] Connection status either #CA_INTERFACE_UP or #CA_INTERFACE_DOWN.
- * @return  NONE
- * @pre  Callback must be registered using CAIPSetConnectionStateChangeCallback()
- */
-typedef void (*CAIPConnectionStateChangeCallback)(const char *ipAddress,
-                                                        CANetworkStatus_t status);
-
-/**
- * @brief Initialize IP network monitor
- * @return  #CA_STATUS_OK or Appropriate error code
- * @retval  #CA_STATUS_OK  Successful
- * @retval  #CA_STATUS_INVALID_PARAM Invalid input data
- * @retval  #CA_STATUS_FAILED Initialization failed
- */
-CAResult_t CAIPInitializeNetworkMonitor(void);
-
-/**
- * @brief Terminate IP network monitor
- * @return  NONE
- */
-void CAIPTerminateNetworkMonitor(void);
-
-/**
- * @brief  Start network monitoring process.
- *
- * @return  #CA_STATUS_OK or Appropriate error code
- * @retval  #CA_STATUS_OK  Successful
- * @retval  #CA_STATUS_FAILED Operation failed
- */
-CAResult_t CAIPStartNetworkMonitor(void);
-
-/**
- * @brief  Stop network monitoring process.
- *
- * @return  #CA_STATUS_OK or Appropriate error code
- * @retval  #CA_STATUS_OK  Successful
- * @retval  #CA_STATUS_FAILED Operation failed
- */
-CAResult_t CAIPStopNetworkMonitor(void);
-
-/**
- * @brief  Get local adapter network information.
- *
- * @param  interfaceName [OUT] Local adapter interface name
- * @param  ipAddress     [OUT] IP address
- *
- * @return  #CA_STATUS_OK or Appropriate error code
- * @retval  #CA_STATUS_OK  Successful
- * @retval  #CA_STATUS_INVALID_PARAM Invalid input data
- * @retval  #CA_STATUS_FAILED Operation failed
- * @remarks  interfaceName and ipAddress must be freed using free().
- */
-CAResult_t CAIPGetInterfaceInfo(char **ipAddress, char **interfaceName);
-
-/**
- * @brief  Get Ethernet adapter connection state.
- *
- * @return  True if Ethernet adapter is connected, otherwise false
- */
-bool CAIPIsConnected(void);
-
-/**
- * @brief  Set callback for receiving local ethernet adapter connection status.
- *
- * @param  callback [IN] Callback to be notified when local Ethernet adapter connection state
- *                       changes.
- * @return NONE
- */
-void CAIPSetConnectionStateChangeCallback
-                (CAIPConnectionStateChangeCallback callback);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* CA_IP_INTERFACE_SINGLETHREAD_H_ */
-
index b2e0e74..9d0c879 100644 (file)
@@ -55,6 +55,7 @@ static void SendNotification();
 static void SelectNetwork();
 static void UnselectNetwork();
 static void HandleRequestResponse();
+static void GetNetworkInfo();
 
 static void RequestHandler(const CAEndpoint_t *object, const CARequestInfo_t *requestInfo);
 static void ResponseHandler(const CAEndpoint_t *object, const CAResponseInfo_t *responseInfo);
@@ -207,6 +208,9 @@ void loop()
             case 'B': // send notification
                 SendNotification();
                 break;
+            case 'G': // Get network info
+                GetNetworkInfo();
+                break;
 
             case 'N': // select network
                 SelectNetwork();
@@ -624,6 +628,36 @@ void UnselectNetwork()
     Serial.println("============");
 }
 
+void GetNetworkInfo()
+{
+    CAEndpoint_t *tempInfo = NULL;
+    uint32_t tempSize = 0;
+    CAResult_t res = CAGetNetworkInformation(&tempInfo, &tempSize);
+    if (CA_STATUS_OK != res || NULL == tempInfo || 0 >= tempSize)
+    {
+        Serial.println("Network not connected");
+        free(tempInfo);
+        return;
+    }
+    printf("=========");
+    printf("Network info total size is %d\n\n", tempSize);
+    int index;
+    for (index = 0; index < tempSize; index++)
+    {
+        Serial.println("Type:");
+        Serial.println(tempInfo[index].adapter);
+        if (CA_ADAPTER_IP == tempInfo[index].adapter)
+        {
+            Serial.println("Address:");
+            Serial.println(tempInfo[index].addr);
+            Serial.println("Port:");
+            Serial.println(tempInfo[index].port);
+        }
+    }
+    free(tempInfo);
+    Serial.println("=======");
+}
+
 void PrintMenu()
 {
 
@@ -634,6 +668,7 @@ void PrintMenu()
     Serial.println("r: send request");
     Serial.println("e: send request to all");
     Serial.println("b: send notification");
+    Serial.println("g: get network info");
     Serial.println("n: select network");
     Serial.println("x: unselect network");
     Serial.println("h: handle request response");
index 1818df3..6e4c265 100644 (file)
@@ -25,7 +25,7 @@
 #include <string.h>
 #include <stdint.h>
 
-#include "caipadapter_singlethread.h"
+#include "caipadapter.h"
 #include "caedradapter_singlethread.h"
 #include "caleadapter_singlethread.h"
 #include "caadapterutils.h"
@@ -137,7 +137,8 @@ void CAInitializeAdapters()
 
     // Initialize adapters and register callback.
 #ifdef IP_ADAPTER
-    CAInitializeIP(CARegisterCallback, CAReceivedPacketCallback, CANetworkChangedCallback);
+    CAInitializeIP(CARegisterCallback, CAReceivedPacketCallback, CANetworkChangedCallback,
+                   NULL, NULL);
 #endif /* IP_ADAPTER */
 
 #ifdef EDR_ADAPTER
index 8a5603b..ec72031 100644 (file)
@@ -184,7 +184,7 @@ static void CAReceivedPacketCallback(CAEndpoint_t *endpoint, void *data, uint32_
 
     uint32_t code = CA_NOT_FOUND;
     coap_pdu_t *pdu = (coap_pdu_t *) CAParsePDU((const char *) data, dataLen, &code);
-
+    OICFree(data);
     if (NULL == pdu)
     {
         OIC_LOG(ERROR, TAG, "Parse PDU failed");
index 8e81e15..db06815 100644 (file)
@@ -17,7 +17,7 @@ src_dir = './ip_adapter/'
 common_files = None
 if target_os == 'arduino':
     common_files = [ os.path.join(src_dir,
-                                  'caipadapter_singlethread.c') ]
+                                  'caipadapter.c') ]
 else:
     common_files = [
         os.path.join(src_dir, 'caipadapter.c'),
index a83ee8a..6e33f93 100644 (file)
@@ -7,14 +7,14 @@ import os.path
 
 env.AppendUnique(CPPPATH = [ os.path.join(src_dir, 'arduino') ])
 
-src_files = [ 'caipnwmonitor.cpp' ]
-
 if env.get('SHIELD') == 'WIFI':
-    src_files += [ 'caipclient_wifi.cpp',
-                   'caipserver_wifi.cpp' ]
+    src_files = [ 'caipclient_wifi.cpp',
+                   'caipserver_wifi.cpp',
+                   'caipnwmonitor_wifi.cpp' ]
 else:
-    src_files += [ 'caipadapterutils_eth.cpp',
+    src_files = [ 'caipadapterutils_eth.cpp',
                    'caipclient_eth.cpp',
-                   'caipserver_eth.cpp' ]
+                   'caipserver_eth.cpp',
+                   'caipnwmonitor_eth.cpp' ]
 
 Return('src_files')
index 534d3a4..60317e5 100644 (file)
@@ -29,7 +29,6 @@
 #include "logger.h"
 #include "cacommon.h"
 #include "caadapterinterface.h"
-#include "caipadapter_singlethread.h"
 #include "caadapterutils.h"
 
 #define TAG "IPU"
index c6b8213..668cfca 100644 (file)
@@ -36,7 +36,7 @@
 #include "logger.h"
 #include "cacommon.h"
 #include "caadapterinterface.h"
-#include "caipadapter_singlethread.h"
+#include "caipadapter.h"
 #include "caadapterutils.h"
 
 #ifdef __cplusplus
index 95b9334..3c997ad 100644 (file)
@@ -17,7 +17,7 @@
 * limitations under the License.
 *
 ******************************************************************/
-#include "caipinterface_singlethread.h"
+#include "caipinterface.h"
 
 #include <Arduino.h>
 #include <Ethernet.h>
@@ -29,7 +29,7 @@
 #include "logger.h"
 #include "cacommon.h"
 #include "caadapterinterface.h"
-#include "caipadapter_singlethread.h"
+#include "caipadapter.h"
 #include "caipadapterutils_eth.h"
 #include "caadapterutils.h"
 #include "oic_malloc.h"
@@ -68,8 +68,8 @@ void CAIPSetUnicastPort(uint16_t port)
     return;
 }
 
-uint32_t CAIPSendData(const char *remoteAddress, uint16_t port,
-                      const char *buf, uint32_t bufLen, bool isMulticast)
+uint32_t CAIPSendData(const CAEndpoint_t *endpoint, const void *buf,
+                      uint32_t bufLen, bool isMulticast)
 {
     if (!isMulticast && 0 == g_unicastPort)
     {
@@ -77,14 +77,14 @@ uint32_t CAIPSendData(const char *remoteAddress, uint16_t port,
         return 0;
     }
 
-    VERIFY_NON_NULL(buf, TAG, "buf");
-    VERIFY_NON_NULL(remoteAddress, TAG, "address");
+    VERIFY_NON_NULL(endpoint, TAG, "endpoint");
 
     int socketID = 0;
+    uint16_t port = endpoint->port;
     if (isMulticast)
     {
-        if (CAArduinoInitMulticastUdpSocket(remoteAddress, port, g_unicastPort, &socketID)
-            != CA_STATUS_OK)
+        if (CAArduinoInitMulticastUdpSocket(endpoint->addr, port,
+                                            g_unicastPort, &socketID) != CA_STATUS_OK)
         {
             OIC_LOG(ERROR, TAG, "init mcast err");
             return 0;
@@ -112,7 +112,7 @@ uint32_t CAIPSendData(const char *remoteAddress, uint16_t port,
     uint32_t ret;
     uint8_t ipAddr[4] = { 0 };
     uint16_t parsedPort = 0;
-    if (CAParseIPv4AddressInternal(remoteAddress, ipAddr, sizeof(ipAddr),
+    if (CAParseIPv4AddressInternal(endpoint->addr, ipAddr, sizeof(ipAddr),
                                    &parsedPort) != CA_STATUS_OK)
     {
         OIC_LOG(ERROR, TAG, "parse fail");
index 38acd84..724bcdc 100644 (file)
@@ -17,7 +17,7 @@
 * limitations under the License.
 *
 ******************************************************************/
-#include "caipinterface_singlethread.h"
+#include "caipinterface.h"
 
 #include <Arduino.h>
 #include <WiFi.h>
@@ -30,7 +30,7 @@
 #include "logger.h"
 #include "cacommon.h"
 #include "caadapterinterface.h"
-#include "caipadapter_singlethread.h"
+#include "caipadapter.h"
 #include "caadapterutils.h"
 
 /// This is the max buffer size between Arduino and WiFi Shield
@@ -49,20 +49,20 @@ void CAIPSetUnicastPort(uint16_t port)
 
 }
 
-uint32_t CAIPSendData(const char *remoteAddress, uint16_t port,
-                      const char *data, uint32_t dataLength, bool isMulticast)
+uint32_t CAIPSendData(const CAEndpoint_t *endpoint, const void *data,
+                      uint32_t dataLength, bool isMulticast)
 {
     OIC_LOG(DEBUG, TAG, "IN");
 
     VERIFY_NON_NULL_RET(data, TAG, "data", 0);
-    VERIFY_NON_NULL_RET(remoteAddress, TAG, "address", 0);
+    VERIFY_NON_NULL_RET(endpoint, TAG, "endpoint", 0);
 
-    OIC_LOG_V(DEBUG, TAG, "remoteip: %s", remoteAddress);
-    OIC_LOG_V(DEBUG, TAG, "port: %d", port);
+    OIC_LOG_V(DEBUG, TAG, "remoteip: %s", endpoint->addr);
+    OIC_LOG_V(DEBUG, TAG, "port: %d", endpoint->port);
 
     uint8_t ip[4] = {0};
     uint16_t parsedPort = 0;
-    CAResult_t res = CAParseIPv4AddressInternal(remoteAddress, ip, sizeof(ip),
+    CAResult_t res = CAParseIPv4AddressInternal(endpoint->addr, ip, sizeof(ip),
                                                 &parsedPort);
     if (res != CA_STATUS_OK)
     {
@@ -71,7 +71,7 @@ uint32_t CAIPSendData(const char *remoteAddress, uint16_t port,
     }
 
     IPAddress remoteIp(ip);
-    Udp.beginPacket(remoteIp, (uint16_t)port);
+    Udp.beginPacket(remoteIp, endpoint->port);
 
     uint32_t bytesWritten = 0;
     while(bytesWritten < dataLength)
diff --git a/resource/csdk/connectivity/src/ip_adapter/arduino/caipnwmonitor.cpp b/resource/csdk/connectivity/src/ip_adapter/arduino/caipnwmonitor.cpp
deleted file mode 100644 (file)
index a64142a..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-/******************************************************************
-*
-* Copyright 2014 Samsung Electronics All Rights Reserved.
-*
-*
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*      http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*
-******************************************************************/
-/**
- * @file caipnwmonitor.cpp
- * @brief This file is to keep design in sync with other platforms.  Right now there is no
- *        api for network monitioring in arduino.
- */
-
-#include "caipinterface_singlethread.h"
-
-#define TAG "IPNW"
-
-CAResult_t CAIPInitializeNetworkMonitor(void)
-{
-    return CA_STATUS_OK;
-}
-
-CAResult_t CAIPStartNetworkMonitor(void)
-{
-    return CA_STATUS_OK;
-}
-
-CAResult_t CAIPGetInterfaceInfo(char **ipAddress, char **interfaceName)
-{
-    return CA_STATUS_OK;
-}
-
-bool CAIPIsConnected(void)
-{
-    return true;
-}
-
-void CAIPSetConnectionStateChangeCallback(CAIPConnectionStateChangeCallback callback)
-{
-    return;
-}
-
-CAResult_t CAIPStopNetworkMonitor(void)
-{
-    return CA_STATUS_OK;
-}
-
-void CAIPTerminateNetworkMonitor(void)
-{
-    return;
-}
diff --git a/resource/csdk/connectivity/src/ip_adapter/arduino/caipnwmonitor_eth.cpp b/resource/csdk/connectivity/src/ip_adapter/arduino/caipnwmonitor_eth.cpp
new file mode 100644 (file)
index 0000000..61da510
--- /dev/null
@@ -0,0 +1,141 @@
+/******************************************************************
+*
+* Copyright 2014 Samsung Electronics All Rights Reserved.
+*
+*
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+******************************************************************/
+/**
+ * @file caipnwmonitor.cpp
+ * @brief This file is to keep design in sync with other platforms.  Right now there is no
+ *        api for network monitioring in arduino.
+ */
+
+#include "caipinterface.h"
+
+#include <Arduino.h>
+#include <Ethernet.h>
+#include <socket.h>
+#include <w5100.h>
+#include <EthernetUdp.h>
+#include <IPAddress.h>
+
+#include "logger.h"
+#include "cacommon.h"
+#include "caipadapter.h"
+#include "caadapterutils.h"
+#include "oic_malloc.h"
+
+#define TAG "IPNW"
+
+CAResult_t CAIPInitializeNetworkMonitor(const ca_thread_pool_t threadPool)
+{
+    return CA_STATUS_OK;
+}
+
+CAResult_t CAIPStartNetworkMonitor(void)
+{
+    return CA_STATUS_OK;
+}
+
+void CAIPGetSubnetMask(char *subnetMask, int32_t addrLen)
+{
+    OIC_LOG(DEBUG, TAG, "IN");
+    VERIFY_NON_NULL_VOID(subnetMask, TAG, "subnetMask");
+
+    //TODO : Fix this for scenarios when this API is invoked when device is not connected
+    uint8_t rawIPAddr[4];
+    if (addrLen < CA_IPADDR_SIZE)
+    {
+        OIC_LOG(ERROR, TAG, "Invalid addrLen");
+        return;
+    }
+
+    W5100.getSubnetMask(rawIPAddr);
+    snprintf(subnetMask, addrLen, "%d.%d.%d.%d", rawIPAddr[0], rawIPAddr[1], rawIPAddr[2],
+             rawIPAddr[3]);
+
+    OIC_LOG_V(DEBUG, TAG, "subnetMask:%s", subnetMask);
+    OIC_LOG(DEBUG, TAG, "OUT");
+    return;
+}
+
+/// Retrieves the IP address assigned to Arduino Ethernet shield
+void CAArduinoGetInterfaceAddress(char *address, int32_t addrLen)
+{
+    OIC_LOG(DEBUG, TAG, "IN");
+    VERIFY_NON_NULL_VOID(address, TAG, "address");
+
+    //TODO : Fix this for scenarios when this API is invoked when device is not connected
+    uint8_t rawIPAddr[4];
+    if (addrLen < CA_IPADDR_SIZE)
+    {
+        OIC_LOG(ERROR, TAG, "Invalid addrLen");
+        return;
+    }
+
+    W5100.getIPAddress(rawIPAddr);
+    snprintf(address, addrLen, "%d.%d.%d.%d", rawIPAddr[0], rawIPAddr[1], rawIPAddr[2],
+             rawIPAddr[3]);
+
+    OIC_LOG_V(DEBUG, TAG, "address:%s", address);
+    OIC_LOG(DEBUG, TAG, "OUT");
+    return;
+}
+
+CAResult_t CAIPGetInterfaceInfo(u_arraylist_t **netInterfaceList)
+{
+    CANetInfo_t *netInfo = (CANetInfo_t *)OICCalloc(1, sizeof(CANetInfo_t));
+    if (!netInfo)
+    {
+        OIC_LOG(ERROR, TAG, "Malloc failed");
+        return CA_STATUS_FAILED;
+    }
+
+    CAArduinoGetInterfaceAddress(netInfo->ipAddress, CA_IPADDR_SIZE);
+
+    CAIPGetSubnetMask(netInfo->subnetMask, CA_IPADDR_SIZE);
+
+    // set interface name
+    strncpy(netInfo->interfaceName, "ETH", strlen(netInfo->interfaceName));
+
+    CAResult_t result = u_arraylist_add(*netInterfaceList, (void *)netInfo);
+    if (CA_STATUS_OK != result)
+    {
+        OIC_LOG(ERROR, TAG, "u_arraylist_add failed");
+        return result;
+    }
+    return CA_STATUS_OK;
+}
+
+bool CAIPIsConnected(void)
+{
+    return true;
+}
+
+void CAIPSetConnectionStateChangeCallback(CAIPConnectionStateChangeCallback callback)
+{
+    return;
+}
+
+CAResult_t CAIPStopNetworkMonitor(void)
+{
+    return CA_STATUS_OK;
+}
+
+void CAIPTerminateNetworkMonitor(void)
+{
+    return;
+}
diff --git a/resource/csdk/connectivity/src/ip_adapter/arduino/caipnwmonitor_wifi.cpp b/resource/csdk/connectivity/src/ip_adapter/arduino/caipnwmonitor_wifi.cpp
new file mode 100644 (file)
index 0000000..3268b6c
--- /dev/null
@@ -0,0 +1,146 @@
+/******************************************************************
+*
+* Copyright 2014 Samsung Electronics All Rights Reserved.
+*
+*
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+******************************************************************/
+/**
+ * @file caipnwmonitor.cpp
+ * @brief This file is to keep design in sync with other platforms.  Right now there is no
+ *        api for network monitioring in arduino.
+ */
+
+#include "caipinterface.h"
+
+#include <Arduino.h>
+#include <WiFi.h>
+#include <WiFiUdp.h>
+#include <SPI.h>
+#include <utility/server_drv.h>
+#include <utility/wifi_drv.h>
+#include <IPAddress.h>
+
+#include "logger.h"
+#include "cacommon.h"
+#include "caipadapter.h"
+#include "caadapterutils.h"
+#include "oic_malloc.h"
+
+#define TAG "IPNW"
+
+CAResult_t CAIPInitializeNetworkMonitor(const ca_thread_pool_t threadPool)
+{
+    return CA_STATUS_OK;
+}
+
+CAResult_t CAIPStartNetworkMonitor(void)
+{
+    return CA_STATUS_OK;
+}
+
+void CAIPGetSubnetMask(char *subnetMaskAddr, int32_t addrLen)
+{
+    OIC_LOG(DEBUG, TAG, "IN");
+    if (WiFi.status() != WL_CONNECTED)
+    {
+        OIC_LOG(DEBUG, TAG, "No WIFI");
+        return;
+    }
+
+    VERIFY_NON_NULL_VOID(subnetMaskAddr, TAG, "Invalid Input");
+    if (addrLen < CA_IPADDR_SIZE)
+    {
+        OIC_LOG_V(ERROR, TAG, "AddrLen MUST be atleast %d", CA_IPADDR_SIZE);
+        return;
+    }
+
+    IPAddress ip = WiFi.subnetMask();
+    snprintf((char *)subnetMaskAddr, addrLen, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
+
+    OIC_LOG_V(DEBUG, TAG, "Wifi shield subnet mask is: %s", subnetMaskAddr);
+    OIC_LOG(DEBUG, TAG, "OUT");
+    return;
+}
+
+/// Retrieves the IP address assigned to Arduino WiFi shield
+void CAArduinoGetInterfaceAddress(char *address, int32_t addrLen)
+{
+    OIC_LOG(DEBUG, TAG, "IN");
+    if (WiFi.status() != WL_CONNECTED)
+    {
+        OIC_LOG(DEBUG, TAG, "No WIFI");
+        return;
+    }
+
+    VERIFY_NON_NULL_VOID(address, TAG, "Invalid address");
+    if (addrLen < CA_IPADDR_SIZE)
+    {
+        OIC_LOG_V(ERROR, TAG, "AddrLen MUST be atleast %d", CA_IPADDR_SIZE);
+        return;
+    }
+
+    IPAddress ip = WiFi.localIP();
+    snprintf((char *)address, addrLen, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
+
+    OIC_LOG_V(DEBUG, TAG, "Wifi shield address is: %s", address);
+    OIC_LOG(DEBUG, TAG, "OUT");
+    return;
+}
+
+CAResult_t CAIPGetInterfaceInfo(u_arraylist_t **netInterfaceList)
+{
+    CANetInfo_t *netInfo = (CANetInfo_t *)OICCalloc(1, sizeof(CANetInfo_t));
+    if (!netInfo)
+    {
+        OIC_LOG(ERROR, TAG, "Malloc failed");
+        return CA_STATUS_FAILED;
+    }
+
+    CAArduinoGetInterfaceAddress(netInfo->ipAddress, CA_IPADDR_SIZE);
+
+    CAIPGetSubnetMask(netInfo->subnetMask, CA_IPADDR_SIZE);
+
+    // set interface name
+    strncpy(netInfo->interfaceName, "WIFI", strlen(netInfo->interfaceName));
+
+    CAResult_t result = u_arraylist_add(*netInterfaceList, (void *)netInfo);
+    if (CA_STATUS_OK != result)
+    {
+        OIC_LOG(ERROR, TAG, "u_arraylist_add failed");
+        return result;
+    }
+    return CA_STATUS_OK;
+}
+
+bool CAIPIsConnected(void)
+{
+    return true;
+}
+
+void CAIPSetConnectionStateChangeCallback(CAIPConnectionStateChangeCallback callback)
+{
+    return;
+}
+
+CAResult_t CAIPStopNetworkMonitor(void)
+{
+    return CA_STATUS_OK;
+}
+
+void CAIPTerminateNetworkMonitor(void)
+{
+    return;
+}
index 0b7f3df..a698260 100644 (file)
@@ -18,7 +18,7 @@
 *
 ******************************************************************/
 
-#include "caipinterface_singlethread.h"
+#include "caipinterface.h"
 
 #include <Arduino.h>
 #include <Ethernet.h>
@@ -31,7 +31,7 @@
 #include "cacommon.h"
 #include "cainterface.h"
 #include "caadapterinterface.h"
-#include "caipadapter_singlethread.h"
+#include "caipadapter.h"
 #include "caipadapterutils_eth.h"
 #include "caadapterutils.h"
 #include "oic_malloc.h"
@@ -44,7 +44,6 @@
 CAResult_t CAIPStartUnicastServer(const char *localAddress, uint16_t *port,
                                         const bool forceStart, int32_t *serverFD);
 static CAResult_t CAArduinoRecvData(int32_t sockFd);
-static CAResult_t CAArduinoGetInterfaceAddress(char *address, int32_t addrLen);
 static void CAArduinoCheckData();
 static void CAPacketReceivedCallback(const char *ipAddress, const uint16_t port,
                               const void *data, const uint32_t dataLength);
@@ -54,12 +53,18 @@ static int g_unicastSocket = 0;
 static int g_multicastSocket = 0;
 
 /**
+ * @var g_isMulticastServerStarted
+ * @brief Flag to check if multicast server is started
+ */
+static bool g_isMulticastServerStarted = false;
+
+/**
  * @var g_unicastPort
  * @brief Unicast Port
  */
 static uint16_t g_unicastPort = 0;
 
-CAResult_t CAIPInitializeServer(void)
+CAResult_t CAIPInitializeServer(const ca_thread_pool_t threadPool)
 {
     return CA_STATUS_OK;
 }
@@ -69,14 +74,13 @@ void CAIPTerminateServer(void)
     return;
 }
 
-CAResult_t CAIPGetUnicastServerInfo(char **ipAddress, uint16_t *port,
-                                          int *serverID)
+uint16_t CAGetServerPortNum(const char *ipAddress, bool isSecured)
 {
-    return CA_STATUS_OK;
+    return g_unicastPort;
 }
 
 CAResult_t CAIPStartUnicastServer(const char *localAddress, uint16_t *port,
-                                        const bool forceStart, int *serverFD)
+                                  bool secured)
 {
     OIC_LOG(DEBUG, TAG, "IN");
     VERIFY_NON_NULL(port, TAG, "port");
@@ -86,15 +90,17 @@ CAResult_t CAIPStartUnicastServer(const char *localAddress, uint16_t *port,
     W5100.getIPAddress(rawIPAddr);
     sprintf(address, "%d.%d.%d.%d", rawIPAddr[0], rawIPAddr[1], rawIPAddr[2], rawIPAddr[3]);
     OIC_LOG_V(DEBUG, TAG, "address:%s", address);
-
-    if (CAArduinoInitUdpSocket(port, serverFD) != CA_STATUS_OK)
+    int serverFD = 1;
+    if (CAArduinoInitUdpSocket(port, &serverFD) != CA_STATUS_OK)
     {
         OIC_LOG(DEBUG, TAG, "failed");
         return CA_STATUS_FAILED;
     }
 
     g_unicastPort = *port;
-    g_unicastSocket = *serverFD;
+    g_unicastSocket = serverFD;
+    CAIPSetUnicastSocket(g_unicastSocket);
+    CAIPSetUnicastPort(g_unicastPort);
     OIC_LOG_V(DEBUG, TAG, "g_unicastPort: %d", g_unicastPort);
     OIC_LOG_V(DEBUG, TAG, "g_unicastSocket: %d", g_unicastSocket);
     OIC_LOG(DEBUG, TAG, "OUT");
@@ -102,17 +108,24 @@ CAResult_t CAIPStartUnicastServer(const char *localAddress, uint16_t *port,
 }
 
 CAResult_t CAIPStartMulticastServer(const char *localAddress, const char *multicastAddress,
-                                    uint16_t multicastPort, int *serverFD)
+                                    uint16_t multicastPort)
 {
     OIC_LOG(DEBUG, TAG, "IN");
+    if (g_isMulticastServerStarted == true)
+    {
+        OIC_LOG(ERROR, TAG, "Already Started!");
+        return CA_SERVER_STARTED_ALREADY;
+    }
+    int serverFD = 1;
     if (CAArduinoInitMulticastUdpSocket(multicastAddress, multicastPort, multicastPort,
-                                        serverFD) != CA_STATUS_OK)
+                                        &serverFD) != CA_STATUS_OK)
     {
         OIC_LOG(DEBUG, TAG, "failed");
         return CA_STATUS_FAILED;
     }
 
-    g_multicastSocket = *serverFD;
+    g_multicastSocket = serverFD;
+    g_isMulticastServerStarted = true;
     OIC_LOG_V(DEBUG, TAG, "gMulticastPort: %d", multicastPort);
     OIC_LOG_V(DEBUG, TAG, "g_multicastSocket: %d", g_multicastSocket);
     OIC_LOG(DEBUG, TAG, "OUT");
@@ -137,13 +150,45 @@ CAResult_t CAIPStopMulticastServer()
     return CA_STATUS_OK;
 }
 
+CAResult_t CAIPStopServer(const char *interfaceAddress)
+{
+    /* For arduino, Server will be running in only one interface */
+    return CAIPStopAllServers();
+}
+
+CAResult_t CAIPStopAllServers()
+{
+    OIC_LOG(DEBUG, TAG, "IN");
+    CAResult_t result = CAIPStopUnicastServer();
+    if (CA_STATUS_OK != result)
+    {
+        OIC_LOG_V(ERROR, TAG, "stop ucast srv fail:%d", result);
+        return result;
+    }
+    CAIPSetUnicastSocket(-1);
+    CAIPSetUnicastPort(0);
+
+    result = CAIPStopMulticastServer();
+    if (CA_STATUS_OK != result)
+    {
+        OIC_LOG_V(ERROR, TAG, "stop mcast srv fail:%d", result);
+    }
+    OIC_LOG(DEBUG, TAG, "OUT");
+    return result;
+}
+
 void CAPacketReceivedCallback(const char *ipAddress, const uint16_t port,
                               const void *data, const uint32_t dataLength)
 {
     OIC_LOG(DEBUG, TAG, "IN");
     if (g_packetReceivedCallback)
     {
-        g_packetReceivedCallback(ipAddress, port, data, dataLength);
+        CAEndpoint_t ep;
+        strncpy(ep.addr, ipAddress, MAX_ADDR_STR_SIZE_CA);
+        ep.port = port;
+        ep.flags = CA_IPV4;
+        ep.adapter = CA_ADAPTER_IP;
+        g_packetReceivedCallback(&ep, data, dataLength);
     }
     OIC_LOG(DEBUG, TAG, "OUT");
 }
@@ -235,31 +280,13 @@ void CAIPSetExceptionCallback(CAIPExceptionCallback callback)
     // TODO
 }
 
-void CAIPPullData()
-{
-    CAArduinoCheckData();
-}
-
-/// Retrieves the IP address assigned to Arduino Ethernet shield
-CAResult_t CAArduinoGetInterfaceAddress(char *address, int32_t addrLen)
+void CAIPSetErrorHandleCallback(CAIPErrorHandleCallback ipErrorCallback)
 {
     OIC_LOG(DEBUG, TAG, "IN");
-    VERIFY_NON_NULL(address, TAG, "address");
-
-    //TODO : Fix this for scenarios when this API is invoked when device is not connected
-    uint8_t rawIPAddr[4];
-    if (addrLen < IPNAMESIZE)
-    {
-        OIC_LOG(ERROR, TAG, "Invalid addrLen");
-        return CA_STATUS_FAILED;
-    }
-
-    W5100.getIPAddress(rawIPAddr);
-    snprintf(address, sizeof(address), "%d.%d.%d.%d", rawIPAddr[0], rawIPAddr[1], rawIPAddr[2],
-             rawIPAddr[3]);
-
-    OIC_LOG_V(DEBUG, TAG, "address:%s", address);
     OIC_LOG(DEBUG, TAG, "OUT");
-    return CA_STATUS_OK;
 }
 
+void CAIPPullData()
+{
+    CAArduinoCheckData();
+}
index 97dd582..5c31cf9 100644 (file)
@@ -18,7 +18,7 @@
 *
 ******************************************************************/
 
-#include "caipinterface_singlethread.h"
+#include "caipinterface.h"
 
 #include <Arduino.h>
 #include <WiFi.h>
@@ -32,7 +32,7 @@
 #include "cacommon.h"
 #include "cainterface.h"
 #include "caadapterinterface.h"
-#include "caipadapter_singlethread.h"
+#include "caipadapter.h"
 #include "caadapterutils.h"
 #include "oic_malloc.h"
 
@@ -49,7 +49,6 @@
 #define IP_RECBUF_PORT_SIZE      (IP_RECBUF_PORT_OFFSET - 0)
 #define IP_RECBUF_FOOTER_SIZE    (IP_RECBUF_IPADDR_SIZE + IP_RECBUF_PORT_SIZE)
 
-static CAResult_t CAArduinoGetInterfaceAddress(char *address, int32_t addrLen);
 static void CAArduinoCheckData();
 static void CAPacketReceivedCallback(const char *ipAddress, const uint16_t port,
                                      const void *data, const uint32_t dataLength);
@@ -58,8 +57,13 @@ static CAIPPacketReceivedCallback gPacketReceivedCallback = NULL;
 static int32_t gUnicastSocket = 0;
 static bool gServerRunning = false;
 static WiFiUDP Udp;
+/**
+ * @var g_unicastPort
+ * @brief Unicast Port
+ */
+static uint16_t g_unicastPort = 0;
 
-CAResult_t CAIPInitializeServer(void)
+CAResult_t CAIPInitializeServer(const ca_thread_pool_t threadPool)
 {
     /**
      * This API is to keep design in sync with other platforms.
@@ -76,17 +80,13 @@ void CAIPTerminateServer(void)
      */
 }
 
-CAResult_t CAIPGetUnicastServerInfo(char **ipAddress, uint16_t *port, int *serverID)
+uint16_t CAGetServerPortNum(const char *ipAddress, bool isSecured)
 {
-    /*
-     * This API is to keep design in sync with other platforms.
-     * Will be implemented as and when CA layer wants this info.
-     */
-    return CA_STATUS_OK;
+    return g_unicastPort;
 }
 
 CAResult_t CAIPStartUnicastServer(const char *localAddress, uint16_t *port,
-                                  bool forceStart, int *serverFD)
+                                  bool secured)
 {
     OIC_LOG(DEBUG, TAG, "IN");
     VERIFY_NON_NULL(port, TAG, "port");
@@ -104,21 +104,17 @@ CAResult_t CAIPStartUnicastServer(const char *localAddress, uint16_t *port,
         return CA_STATUS_FAILED;
     }
 
-    char localIpAddress[CA_IPADDR_SIZE];
-    int32_t localIpAddressLen = sizeof(localIpAddress);
-    CAArduinoGetInterfaceAddress(localIpAddress, localIpAddressLen);
-    OIC_LOG_V(DEBUG, TAG, "address: %s", localIpAddress);
     OIC_LOG_V(DEBUG, TAG, "port: %d", *port);
 
     Udp.begin((uint16_t ) *port);
     gServerRunning = true;
-
+    g_unicastPort = *port;
     OIC_LOG(DEBUG, TAG, "OUT");
     return CA_STATUS_OK;
 }
 
 CAResult_t CAIPStartMulticastServer(const char *localAddress, const char *multicastAddress,
-                                      uint16_t multicastPort, int *serverFD)
+                                      uint16_t multicastPort)
 {
     // wifi shield does not support multicast
     OIC_LOG(DEBUG, TAG, "IN");
@@ -141,13 +137,45 @@ CAResult_t CAIPStopMulticastServer()
     return CAIPStopUnicastServer();
 }
 
+CAResult_t CAIPStopServer(const char *interfaceAddress)
+{
+    /* For arduino, Server will be running in only one interface */
+    return CAIPStopAllServers();
+}
+
+CAResult_t CAIPStopAllServers()
+{
+    OIC_LOG(DEBUG, TAG, "IN");
+    CAResult_t result = CAIPStopUnicastServer();
+    if (CA_STATUS_OK != result)
+    {
+        OIC_LOG_V(ERROR, TAG, "stop ucast srv fail:%d", result);
+        return result;
+    }
+    CAIPSetUnicastSocket(-1);
+    CAIPSetUnicastPort(0);
+
+    result = CAIPStopMulticastServer();
+    if (CA_STATUS_OK != result)
+    {
+        OIC_LOG_V(ERROR, TAG, "stop mcast srv fail:%d", result);
+    }
+    OIC_LOG(DEBUG, TAG, "OUT");
+    return result;
+}
+
 void CAPacketReceivedCallback(const char *ipAddress, const uint16_t port,
                               const void *data, const uint32_t dataLength)
 {
     OIC_LOG(DEBUG, TAG, "IN");
     if (gPacketReceivedCallback)
     {
-        gPacketReceivedCallback(ipAddress, port, data, dataLength);
+        CAEndpoint_t ep;
+        strncpy(ep.addr, ipAddress, MAX_ADDR_STR_SIZE_CA);
+        ep.port = port;
+        ep.flags = CA_IPV4;
+        ep.adapter = CA_ADAPTER_IP;
+        gPacketReceivedCallback(&ep, data, dataLength);
         OIC_LOG(DEBUG, TAG, "Notified network packet");
     }
     OIC_LOG(DEBUG, TAG, "OUT");
@@ -196,35 +224,13 @@ void CAIPSetExceptionCallback(CAIPExceptionCallback callback)
     // TODO
 }
 
-void CAIPPullData()
-{
-    CAArduinoCheckData();
-}
-
-/// Retrieves the IP address assigned to Arduino WiFi shield
-CAResult_t CAArduinoGetInterfaceAddress(char *address, int32_t addrLen)
+void CAIPSetErrorHandleCallback(CAIPErrorHandleCallback ipErrorCallback)
 {
     OIC_LOG(DEBUG, TAG, "IN");
-    if (WiFi.status() != WL_CONNECTED)
-    {
-        OIC_LOG(DEBUG, TAG, "No WIFI");
-        return CA_STATUS_FAILED;
-    }
-
-    VERIFY_NON_NULL(address, TAG, "Invalid address");
-    if (addrLen < IPNAMESIZE)
-    {
-        OIC_LOG_V(ERROR, TAG, "AddrLen MUST be atleast %d", IPNAMESIZE);
-        return CA_STATUS_FAILED;
-    }
-
-    IPAddress ip = WiFi.localIP();
-    sprintf((char *)address, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
-
-    OIC_LOG_V(DEBUG, TAG, "Wifi shield address is: %s", address);
     OIC_LOG(DEBUG, TAG, "OUT");
-    return CA_STATUS_OK;
 }
 
-
-
+void CAIPPullData()
+{
+    CAArduinoCheckData();
+}
index c89b8ca..43ca8fa 100644 (file)
  * @def IP_ADAPTER_TAG
  * @brief Logging tag for module name
  */
-#define IP_ADAPTER_TAG "IP_ADAP"
+#define IP_ADAPTER_TAG "IPAD"
 
 /**
  * @def CA_PORT
  * @brief Port to listen for incoming data
  */
+#ifdef ARDUINO
+#define CA_PORT   55555
+#else
 #define CA_PORT   0
+#endif
 
 /**
  * @def CA_SECURE_PORT
@@ -67,6 +71,7 @@
  */
 #define CA_MULTICAST_IP "224.0.1.187"
 
+#ifndef SINGLE_THREAD
 /**
  * @var CAIPData
  * @brief Holds inter thread ip data information.
@@ -80,6 +85,13 @@ typedef struct
 } CAIPData;
 
 /**
+ * @var g_sendQueueHandle
+ * @brief Queue handle for Send Data
+ */
+static CAQueueingThread_t *g_sendQueueHandle = NULL;
+#endif
+
+/**
  * @var g_networkPacketCallback
  * @brief Network Packet Received Callback to CA
  */
@@ -98,21 +110,11 @@ static CANetworkChangeCallback g_networkChangeCallback = NULL;
 static CAErrorHandleCallback g_errorCallback = NULL;
 
 /**
- * @var g_sendQueueHandle
- * @brief Queue handle for Send Data
- */
-static CAQueueingThread_t *g_sendQueueHandle = NULL;
-
-/**
  * @var g_threadPool
  * @brief ThreadPool for storing ca_thread_pool_t handle passed from CA
  */
 static ca_thread_pool_t g_threadPool = NULL;
 
-static CAResult_t CAIPInitializeQueueHandles();
-
-static void CAIPDeinitializeQueueHandles();
-
 static void CAIPNotifyNetworkChange(const char *address, uint16_t port,
                                     CANetworkStatus_t status);
 
@@ -129,6 +131,12 @@ static uint32_t CAIPPacketSendCB(const CAEndpoint_t *endpoint,
 
 static CAResult_t CAIPStopServers();
 
+#ifndef SINGLE_THREAD
+
+static CAResult_t CAIPInitializeQueueHandles();
+
+static void CAIPDeinitializeQueueHandles();
+
 static void CAIPSendDataThread(void *threadData);
 
 static CAIPData *CACreateIPData(const CAEndpoint_t *remoteEndpoint,
@@ -180,6 +188,109 @@ void CAIPDeinitializeQueueHandles()
     OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
 }
 
+void CAIPSendDataThread(void *threadData)
+{
+    OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
+
+    CAIPData *ipData = (CAIPData *) threadData;
+    uint32_t sentData = -1;
+
+    if (!ipData)
+    {
+        OIC_LOG(DEBUG, IP_ADAPTER_TAG, "Invalid ip data!");
+        return;
+    }
+
+    if (ipData->isMulticast)
+    {
+        //Processing for sending multicast
+        OIC_LOG(DEBUG, IP_ADAPTER_TAG, "Send Multicast Data is called");
+        strncpy(ipData->remoteEndpoint->addr, CA_MULTICAST_IP, MAX_ADDR_STR_SIZE_CA);
+        ipData->remoteEndpoint->port = CA_MCAST_PORT;
+        sentData = CAIPSendData(ipData->remoteEndpoint, ipData->data, ipData->dataLen, true);
+    }
+    else
+    {
+        //Processing for sending unicast
+#ifdef __WITH_DTLS__
+        if (ipData->remoteEndpoint->flags & CA_SECURE)
+        {
+            OIC_LOG(DEBUG, IP_ADAPTER_TAG, "CAAdapterNetDtlsEncrypt called!");
+            CAResult_t result = CAAdapterNetDtlsEncrypt(ipData->remoteEndpoint,
+                                               ipData->data, ipData->dataLen);
+            if (CA_STATUS_OK != result)
+            {
+                OIC_LOG(ERROR, IP_ADAPTER_TAG, "CAAdapterNetDtlsEncrypt failed!");
+                sentData = 0;
+            }
+            OIC_LOG_V(DEBUG, IP_ADAPTER_TAG,
+                      "CAAdapterNetDtlsEncrypt returned with result[%d]", result);
+        }
+        else
+        {
+            OIC_LOG(DEBUG, IP_ADAPTER_TAG, "Send Unicast Data is called");
+            sentData = CAIPSendData(ipData->remoteEndpoint, ipData->data, ipData->dataLen, false);
+        }
+#else
+        sentData = CAIPSendData(ipData->remoteEndpoint, ipData->data, ipData->dataLen, false);
+#endif
+    }
+
+    if (0 == sentData)
+    {
+        g_errorCallback(ipData->remoteEndpoint, ipData->data, ipData->dataLen,
+                        CA_SEND_FAILED);
+    }
+
+    OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
+}
+
+CAIPData *CACreateIPData(const CAEndpoint_t *remoteEndpoint, const void *data,
+                         uint32_t dataLength, bool isMulticast)
+{
+    VERIFY_NON_NULL_RET(data, IP_ADAPTER_TAG, "IPData is NULL", NULL);
+
+    CAIPData *ipData = (CAIPData *) OICMalloc(sizeof(CAIPData));
+    if (!ipData)
+    {
+        OIC_LOG(ERROR, IP_ADAPTER_TAG, "Memory allocation failed!");
+        return NULL;
+    }
+
+    ipData->remoteEndpoint = CACloneEndpoint(remoteEndpoint);
+    ipData->data = (void *) OICMalloc(dataLength);
+    if (!ipData->data)
+    {
+        OIC_LOG(ERROR, IP_ADAPTER_TAG, "Memory allocation failed!");
+        CAFreeIPData(ipData);
+        return NULL;
+    }
+
+    memcpy(ipData->data, data, dataLength);
+    ipData->dataLen = dataLength;
+
+    ipData->isMulticast = isMulticast;
+
+    return ipData;
+}
+
+void CAFreeIPData(CAIPData *ipData)
+{
+    VERIFY_NON_NULL_VOID(ipData, IP_ADAPTER_TAG, "ipData is NULL");
+
+    CAFreeEndpoint(ipData->remoteEndpoint);
+    OICFree(ipData->data);
+    OICFree(ipData);
+}
+
+void CADataDestroyer(void *data, uint32_t size)
+{
+    CAIPData *etdata = (CAIPData *) data;
+
+    CAFreeIPData(etdata);
+}
+#endif
+
 void CAIPNotifyNetworkChange(const char *address, uint16_t port, CANetworkStatus_t status)
 {
     OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
@@ -291,7 +402,7 @@ uint32_t CAIPPacketSendCB(const CAEndpoint_t *endpoint, const void *data, uint32
 #endif
 
 void CAIPPacketReceivedCB(const CAEndpoint_t *endpoint, const void *data,
-                                uint32_t dataLength)
+                          uint32_t dataLength)
 {
     OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
 
@@ -316,7 +427,6 @@ void CAIPPacketReceivedCB(const CAEndpoint_t *endpoint, const void *data,
     {
         OICFree(buf);
     }
-
     OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
 }
 
@@ -350,6 +460,45 @@ void CAIPErrorHandler (const CAEndpoint_t *endpoint, const void *data,
     return;
 }
 
+int32_t CAIPSendDataInternal(const CAEndpoint_t *remoteEndpoint, const void *data,
+                             uint32_t dataLength, bool isMulticast)
+{
+    OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
+#ifdef SINGLE_THREAD
+
+    // If remoteEndpoint is NULL, its Multicast, else its Unicast.
+    if(!isMulticast)
+    {
+        CAIPSendData(remoteEndpoint, data, dataLength, false);
+    }
+    else
+    {
+        CAEndpoint_t ep = { 0 };
+        strcpy(ep.addr, CA_MULTICAST_IP);
+        ep.port = CA_MCAST_PORT;
+        CAIPSendData(&ep, data, dataLength, true);
+    }
+#else
+    VERIFY_NON_NULL_RET(g_sendQueueHandle, IP_ADAPTER_TAG, "sendQueueHandle", -1);
+
+    // Create IPData to add to queue
+    CAIPData *ipData = CACreateIPData(remoteEndpoint, data, dataLength, isMulticast);
+
+    if (!ipData)
+    {
+        OIC_LOG(ERROR, IP_ADAPTER_TAG, "Failed to create ipData!");
+        return -1;
+    }
+    else
+    {
+        // Add message to send queue
+        CAQueueingThreadAddData(g_sendQueueHandle, ipData, sizeof(CAIPData));
+    }
+#endif
+    OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
+    return dataLength;
+}
+
 CAResult_t CAInitializeIP(CARegisterConnectivityCallback registerCallback,
                           CANetworkPacketReceivedCallback networkPacketCallback,
                           CANetworkChangeCallback netCallback,
@@ -359,7 +508,9 @@ CAResult_t CAInitializeIP(CARegisterConnectivityCallback registerCallback,
     VERIFY_NON_NULL(registerCallback, IP_ADAPTER_TAG, "registerCallback");
     VERIFY_NON_NULL(networkPacketCallback, IP_ADAPTER_TAG, "networkPacketCallback");
     VERIFY_NON_NULL(netCallback, IP_ADAPTER_TAG, "netCallback");
+#ifndef SINGLE_THREAD
     VERIFY_NON_NULL(handle, IP_ADAPTER_TAG, "thread pool handle");
+#endif
 
     g_threadPool = handle;
     g_networkChangeCallback = netCallback;
@@ -369,7 +520,7 @@ CAResult_t CAInitializeIP(CARegisterConnectivityCallback registerCallback,
     CAResult_t ret = CAIPInitializeNetworkMonitor(g_threadPool);
     if (CA_STATUS_OK != ret)
     {
-        OIC_LOG_V(ERROR, IP_ADAPTER_TAG, "Failed to initialize n/w monitor![%d]", ret);
+        OIC_LOG_V(ERROR, IP_ADAPTER_TAG, "Failed to initialize n/w monitor[%d]", ret);
         return ret;
     }
     CAIPSetConnectionStateChangeCallback(CAIPConnectionStateCB);
@@ -402,14 +553,15 @@ CAResult_t CAInitializeIP(CARegisterConnectivityCallback registerCallback,
     ipHandler.terminate = CATerminateIP;
     registerCallback(ipHandler, CA_ADAPTER_IP);
 
+#ifndef SINGLE_THREAD
     if (CA_STATUS_OK != CAIPInitializeQueueHandles())
     {
         OIC_LOG(ERROR, IP_ADAPTER_TAG, "Failed to Initialize Queue Handle");
         CATerminateIP();
         return CA_STATUS_FAILED;
     }
-
-    OIC_LOG(INFO, IP_ADAPTER_TAG, "OUT IntializeIP is Success");
+#endif
+    OIC_LOG(INFO, IP_ADAPTER_TAG, "OUT");
     return CA_STATUS_OK;
 }
 
@@ -425,12 +577,14 @@ CAResult_t CAStartIP()
         return ret;
     }
 
+#ifndef SINGLE_THREAD
     // Start send queue thread
     if (CA_STATUS_OK != CAQueueingThreadStart(g_sendQueueHandle))
     {
         OIC_LOG(ERROR, IP_ADAPTER_TAG, "Failed to Start Send Data Thread");
         return CA_STATUS_FAILED;
     }
+#endif
 
     bool retVal = CAIPIsConnected();
     if (false == retVal)
@@ -439,6 +593,16 @@ CAResult_t CAStartIP()
         return CA_STATUS_OK;
     }
 
+#ifdef ARDUINO
+    uint16_t unicastPort = CA_PORT;
+    // Address is hardcoded as we are using Single Interface
+    ret = CAIPStartUnicastServer("0.0.0.0", &unicastPort, false);
+    if (CA_STATUS_OK != ret)
+    {
+        OIC_LOG_V(DEBUG, IP_ADAPTER_TAG, "Start unicast serv failed[%d]", ret);
+
+    }
+#else
     u_arraylist_t *netInterfaceList = u_arraylist_create();
 
     VERIFY_NON_NULL(netInterfaceList, IP_ADAPTER_TAG, "netInterfaceList is NULL");
@@ -480,6 +644,7 @@ CAResult_t CAStartIP()
 #endif
     }
     CAClearNetInterfaceInfoList(netInterfaceList);
+#endif
     OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
     return ret;
 }
@@ -488,19 +653,27 @@ CAResult_t CAStartIPListeningServer()
 {
     OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
 
+    CAResult_t ret = CA_STATUS_OK;
     bool retVal = CAIPIsConnected();
     if (false == retVal)
     {
-        OIC_LOG(DEBUG, IP_ADAPTER_TAG,
-                  "IP not Connected. Couldn't start multicast server");
-        return CA_STATUS_OK;
+        OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IP not Connected");
+        return ret;
     }
 
+#ifdef ARDUINO
+    //uint16_t multicastPort = CA_MCAST_PORT;
+    ret = CAIPStartMulticastServer("0.0.0.0", CA_MULTICAST_IP, CA_MCAST_PORT);
+    if (CA_STATUS_OK != ret)
+    {
+        OIC_LOG_V(ERROR, IP_ADAPTER_TAG, "Start multicast failed[%d]", ret);
+    }
+#else
     u_arraylist_t *netInterfaceList = u_arraylist_create();
 
     VERIFY_NON_NULL(netInterfaceList, IP_ADAPTER_TAG, "netInterfaceList is NULL");
 
-    CAResult_t ret = CAIPGetInterfaceInfo(&netInterfaceList);
+    ret = CAIPGetInterfaceInfo(&netInterfaceList);
     if (CA_STATUS_OK != ret)
     {
         OIC_LOG_V(ERROR, IP_ADAPTER_TAG, "Failed to get IP interface info [%d]", ret);
@@ -529,6 +702,7 @@ CAResult_t CAStartIPListeningServer()
     }
 
     CAClearNetInterfaceInfoList(netInterfaceList);
+#endif
     OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
     return ret;
 }
@@ -536,6 +710,8 @@ CAResult_t CAStartIPListeningServer()
 CAResult_t CAStartIPDiscoveryServer()
 {
     OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
+    /* Both listening and discovery server are same */
+    OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
     return CAStartIPListeningServer();
 }
 
@@ -546,29 +722,14 @@ int32_t CASendIPUnicastData(const CAEndpoint_t *remoteEndpoint,
 
     VERIFY_NON_NULL_RET(remoteEndpoint, IP_ADAPTER_TAG, "remoteEndpoint", -1);
     VERIFY_NON_NULL_RET(data, IP_ADAPTER_TAG, "data", -1);
-    VERIFY_NON_NULL_RET(g_sendQueueHandle, IP_ADAPTER_TAG, "sendQueueHandle", -1);
-
     if (0 == dataLength)
     {
         OIC_LOG(ERROR, IP_ADAPTER_TAG, "Invalid Data Length");
         return -1;
     }
 
-    // Create IPData to add to queue
-    CAIPData *ipData = CACreateIPData(remoteEndpoint, data, dataLength, false);
-    if (!ipData)
-    {
-        OIC_LOG(ERROR, IP_ADAPTER_TAG, "Failed to create ipData!");
-        return -1;
-    }
-    else
-    {
-        // Add message to send queue
-        CAQueueingThreadAddData(g_sendQueueHandle, ipData, sizeof(CAIPData));
-
-        OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
-        return dataLength;
-    }
+    OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
+    return CAIPSendDataInternal(remoteEndpoint, data, dataLength, false);
 }
 
 int32_t CASendIPMulticastData(const CAEndpoint_t *endpoint, const void *data, uint32_t dataLength)
@@ -576,29 +737,14 @@ int32_t CASendIPMulticastData(const CAEndpoint_t *endpoint, const void *data, ui
     OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
 
     VERIFY_NON_NULL_RET(data, IP_ADAPTER_TAG, "data", -1);
-    VERIFY_NON_NULL_RET(g_sendQueueHandle, IP_ADAPTER_TAG, "sendQueueHandle", -1);
-
     if (0 == dataLength)
     {
         OIC_LOG(ERROR, IP_ADAPTER_TAG, "Invalid Data Length");
         return -1;
     }
 
-    // Create IPData to add to queue
-    CAIPData *ipData = CACreateIPData(endpoint, data, dataLength, true);
-    if (!ipData)
-    {
-        OIC_LOG(ERROR, IP_ADAPTER_TAG, "Failed to create ipData!");
-        return -1;
-    }
-    else
-    {
-        // Add message to send queue
-        CAQueueingThreadAddData(g_sendQueueHandle, ipData, sizeof(CAIPData));
-
-        OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
-        return dataLength;
-    }
+    OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
+    return CAIPSendDataInternal(endpoint, data, dataLength, true);
 }
 
 CAResult_t CAGetIPInterfaceInformation(CAEndpoint_t **info, uint32_t *size)
@@ -611,8 +757,7 @@ CAResult_t CAGetIPInterfaceInformation(CAEndpoint_t **info, uint32_t *size)
     bool retVal = CAIPIsConnected();
     if (false == retVal)
     {
-        OIC_LOG(ERROR, IP_ADAPTER_TAG,
-                "Failed to get interface address, IP not Connected");
+        OIC_LOG(ERROR, IP_ADAPTER_TAG, "IP not Connected");
         return CA_ADAPTER_NOT_ENABLED;
     }
 
@@ -688,7 +833,7 @@ CAResult_t CAGetIPInterfaceInformation(CAEndpoint_t **info, uint32_t *size)
 CAResult_t CAReadIPData()
 {
     OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
-
+    CAIPPullData();
     OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
     return CA_STATUS_OK;
 }
@@ -718,17 +863,23 @@ CAResult_t CAStopIP()
     // Stop IP network monitor
     CAIPStopNetworkMonitor();
 
+#ifdef MULTI_THREAD
     // Stop send queue thread
     if (g_sendQueueHandle)
     {
         CAQueueingThreadStop(g_sendQueueHandle);
     }
+#endif
 
     // Stop Unicast, Secured unicast and Multicast servers running
-    CAIPStopServers();
+    CAResult_t result = CAIPStopServers();
+    if (CA_STATUS_OK != result)
+    {
+        OIC_LOG_V(ERROR, IP_ADAPTER_TAG, "stop srv fail:%d", result);
+    }
 
     OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
-    return CA_STATUS_OK;
+    return result;
 }
 
 void CATerminateIP()
@@ -751,111 +902,10 @@ void CATerminateIP()
     CAIPSetConnectionStateChangeCallback(NULL);
     CAIPTerminateNetworkMonitor();
 
+#ifndef SINGLE_THREAD
     // Terminate message queue handler
     CAIPDeinitializeQueueHandles();
-
-    OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
-}
-
-void CAIPSendDataThread(void *threadData)
-{
-    OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
-
-    CAIPData *ipData = (CAIPData *) threadData;
-    uint32_t sentData = -1;
-
-    if (!ipData)
-    {
-        OIC_LOG(DEBUG, IP_ADAPTER_TAG, "Invalid ip data!");
-        return;
-    }
-
-    if (ipData->isMulticast)
-    {
-        //Processing for sending multicast
-        OIC_LOG(DEBUG, IP_ADAPTER_TAG, "Send Multicast Data is called");
-        strncpy(ipData->remoteEndpoint->addr, CA_MULTICAST_IP, MAX_ADDR_STR_SIZE_CA);
-        ipData->remoteEndpoint->port = CA_MCAST_PORT;
-        sentData = CAIPSendData(ipData->remoteEndpoint, ipData->data, ipData->dataLen, true);
-    }
-    else
-    {
-        //Processing for sending unicast
-#ifdef __WITH_DTLS__
-        if (ipData->remoteEndpoint->flags & CA_SECURE)
-        {
-            OIC_LOG(DEBUG, IP_ADAPTER_TAG, "CAAdapterNetDtlsEncrypt called!");
-            CAResult_t result = CAAdapterNetDtlsEncrypt(ipData->remoteEndpoint,
-                                               ipData->data, ipData->dataLen);
-            if (CA_STATUS_OK != result)
-            {
-                OIC_LOG(ERROR, IP_ADAPTER_TAG, "CAAdapterNetDtlsEncrypt failed!");
-                sentData = 0;
-            }
-            OIC_LOG_V(DEBUG, IP_ADAPTER_TAG,
-                      "CAAdapterNetDtlsEncrypt returned with result[%d]", result);
-        }
-        else
-        {
-            OIC_LOG(DEBUG, IP_ADAPTER_TAG, "Send Unicast Data is called");
-            sentData = CAIPSendData(ipData->remoteEndpoint, ipData->data, ipData->dataLen, false);
-        }
-#else
-        sentData = CAIPSendData(ipData->remoteEndpoint, ipData->data, ipData->dataLen, false);
 #endif
-    }
-
-    if (0 == sentData)
-    {
-        g_errorCallback(ipData->remoteEndpoint, ipData->data, ipData->dataLen,
-                        CA_SEND_FAILED);
-    }
 
     OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
 }
-
-CAIPData *CACreateIPData(const CAEndpoint_t *remoteEndpoint, const void *data,
-                         uint32_t dataLength, bool isMulticast)
-{
-    VERIFY_NON_NULL_RET(data, IP_ADAPTER_TAG, "IPData is NULL", NULL);
-
-    CAIPData *ipData = (CAIPData *) OICMalloc(sizeof(CAIPData));
-    if (!ipData)
-    {
-        OIC_LOG(ERROR, IP_ADAPTER_TAG, "Memory allocation failed!");
-        return NULL;
-    }
-
-    ipData->remoteEndpoint = CACloneEndpoint(remoteEndpoint);
-    ipData->data = (void *) OICMalloc(dataLength);
-    if (!ipData->data)
-    {
-        OIC_LOG(ERROR, IP_ADAPTER_TAG, "Memory allocation failed!");
-        CAFreeIPData(ipData);
-        return NULL;
-    }
-
-    memcpy(ipData->data, data, dataLength);
-    ipData->dataLen = dataLength;
-
-    ipData->isMulticast = isMulticast;
-
-    return ipData;
-}
-
-void CAFreeIPData(CAIPData *ipData)
-{
-    VERIFY_NON_NULL_VOID(ipData, IP_ADAPTER_TAG, "ipData is NULL");
-
-    CAFreeEndpoint(ipData->remoteEndpoint);
-    OICFree(ipData->data);
-    OICFree(ipData);
-}
-
-void CADataDestroyer(void *data, uint32_t size)
-{
-    CAIPData *etdata = (CAIPData *) data;
-
-    CAFreeIPData(etdata);
-}
-
diff --git a/resource/csdk/connectivity/src/ip_adapter/caipadapter_singlethread.c b/resource/csdk/connectivity/src/ip_adapter/caipadapter_singlethread.c
deleted file mode 100644 (file)
index 7e00998..0000000
+++ /dev/null
@@ -1,489 +0,0 @@
-/******************************************************************
- *
- * Copyright 2014 Samsung Electronics All Rights Reserved.
- *
- *
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************/
-
-#include "caipadapter_singlethread.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdint.h>
-#include "caadapterutils.h"
-#include "logger.h"
-#include "oic_malloc.h"
-#include "caremotehandler.h"
-#include "caipinterface_singlethread.h"
-
-/**
- * @def TAG
- * @brief Logging tag for module name
- */
-#define TAG "IPAD"
-
-/**
- * @def CA_PORT
- * @brief Unicast port number (to listen for incoming data on unicast server).
- * Note :- Actual port number may differ based on result of bind() operation.
- */
- // Assigning fixed number as port number as Arduino eth and wifi libraries dont have proper api to
- // return assigned port number
-#define CA_PORT   55555
-
-/**
- * @def CA_SECURE_PORT
- * @brief Secured (unicast) port number as defined in COAP Specification, RFC-7252.
- */
-#define CA_SECURE_PORT   5684
-
-/**
- * @def CA_MCAST_PORT
- * @brief Multicast port number as defined in COAP Specification, RFC-7252.
- */
-#define CA_MCAST_PORT   5683
-
-/**
- * @def CA_MULTICAST_IP
- * @brief Multicast IP Address
- */
-#define CA_MULTICAST_IP "224.0.1.187"
-
-/* Skip Queue */
-/**
- * @var g_networkPacketCallback
- * @brief Network Packet Received Callback to CA
- */
-static CANetworkPacketReceivedCallback g_networkPacketCallback = NULL;
-
-/**
- * @var g_networkChangeCallback
- * @brief Network Changed Callback to CA
- */
-
-static CANetworkChangeCallback g_networkChangeCallback = NULL;
-
-/**
- * @var g_isMulticastServerStarted
- * @brief Flag to check if multicast server is started
- */
-static bool g_isMulticastServerStarted = false;
-
-/**
- * @var g_startUnicastServerRequested
- * @brief Flag to check if server start requested by CA.
- */
-static bool g_startUnicastServerRequested = false;
-
-/**
- * @var g_unicastServerport
- * @brief port number on which unicast server is running.
- */
-static uint16_t g_unicastServerport = 0;
-
-/**
- * @var g_startMulticastServerRequested
- * @brief Flag to check if server start requested by CA.
- */
-static bool g_startMulticastServerRequested = false;
-
-
-static void CAIPNotifyNetworkChange(const char *address, uint16_t port,
-                                          CANetworkStatus_t status);
-static void CAIPConnectionStateCB(const char *ipAddress,
-                                        CANetworkStatus_t status);
-static void CAIPPacketReceivedCB(const char *ipAddress, uint16_t port,
-                                       const void *data, uint32_t dataLength);
-static CAResult_t CAIPStopServers();
-
-void CAIPNotifyNetworkChange(const char *address, uint16_t port, CANetworkStatus_t status)
-{
-    CAEndpoint_t *localEndpoint = CACreateEndpointObject(CA_DEFAULT_FLAGS, CA_ADAPTER_IP,
-                                                         address, port);
-    if (!localEndpoint)
-    {
-        OIC_LOG(ERROR, TAG, "Out of memory!");
-        return;
-    }
-    localEndpoint->port = port;
-
-    if (NULL != g_networkChangeCallback)
-    {
-        g_networkChangeCallback(localEndpoint, status);
-    }
-
-    CAFreeEndpoint(localEndpoint);
-}
-
-void CAIPConnectionStateCB(const char *ipAddr,
-                                 CANetworkStatus_t status)
-{
-    OIC_LOG(DEBUG, TAG, "IN");
-
-    CAResult_t ret = CA_STATUS_FAILED;
-    /* If IP is connected, then get the latest IP from the IP Interface
-      * and start unicast and multicast servers if requested earlier */
-    if (CA_INTERFACE_UP == status)
-    {
-        uint16_t port = CA_PORT;
-        int32_t serverFd = -1;
-        /* Start Unicast server if requested earlier */
-        if (g_startUnicastServerRequested)
-        {
-            ret = CAIPStartUnicastServer("0.0.0.0", &port, false, &serverFd);
-            if (CA_STATUS_OK == ret)
-            {
-                OIC_LOG_V(DEBUG, TAG, "unicast started:%d", port);
-                CAIPSetUnicastSocket(serverFd);
-                CAIPSetUnicastPort(port);
-                g_unicastServerport = port;
-            }
-            else
-            {
-                OIC_LOG_V(ERROR, TAG, "FAILED:%d", ret);
-            }
-        }
-
-        /* Start Multicast server if requested earlier */
-        if (g_startMulticastServerRequested)
-        {
-            uint16_t multicastPort = CA_MCAST_PORT;
-            ret = CAIPStartMulticastServer("0.0.0.0", CA_MULTICAST_IP, multicastPort, &serverFd);
-            if (CA_STATUS_OK == ret)
-            {
-                OIC_LOG_V(DEBUG, TAG, "multicast started:%d", multicastPort);
-                g_isMulticastServerStarted = true;
-            }
-            else
-            {
-                OIC_LOG_V(ERROR, TAG, "strt mcast srv fail:%d", ret);
-            }
-        }
-
-        char *ipAddress = NULL;
-        char *ifcName = NULL;
-        CAResult_t ret = CAIPGetInterfaceInfo(&ifcName, &ipAddress);
-        if (CA_STATUS_OK != ret)
-        {
-            OIC_LOG_V(ERROR, TAG, "get interface info fail:%d", ret);
-            OICFree(ipAddress);
-            OICFree(ifcName);
-            return;
-        }
-        /* Notify network change to CA */
-        CAIPNotifyNetworkChange(ipAddress, port, status);
-        OICFree(ipAddress);
-        OICFree(ifcName);
-    }
-    else
-    {
-        CAIPNotifyNetworkChange("", 0, status);
-        /* Stop both Unicast and Multicast servers */
-        ret = CAIPStopServers();
-        if (CA_STATUS_OK != ret)
-        {
-            OIC_LOG_V(ERROR, TAG, "stop srv fail:%d", ret);
-            return;
-        }
-    }
-
-    OIC_LOG(DEBUG, TAG, "OUT");
-}
-
-void CAIPPacketReceivedCB(const char *ipAddress, uint16_t port,
-                                const void *data, uint32_t dataLength)
-{
-    OIC_LOG(DEBUG, TAG, "IN");
-    OIC_LOG_V(DEBUG, TAG, "sddress:%s", ipAddress);
-    OIC_LOG_V(DEBUG, TAG, "port:%d", port);
-    OIC_LOG_V(DEBUG, TAG, "data:%s", data);
-
-    /* CA is freeing this memory */
-    CAEndpoint_t *endPoint = CACreateEndpointObject(CA_DEFAULT_FLAGS, CA_ADAPTER_IP,
-                                                    ipAddress, port);
-    if (NULL == endPoint)
-    {
-        OIC_LOG(ERROR, TAG, "Out of memory!");
-        return;
-    }
-
-    if (g_networkPacketCallback)
-    {
-        g_networkPacketCallback(endPoint, data, dataLength);
-    }
-    CAFreeEndpoint(endPoint);
-    OIC_LOG(DEBUG, TAG, "OUT");
-}
-
-CAResult_t CAInitializeIP(CARegisterConnectivityCallback registerCallback,
-                                CANetworkPacketReceivedCallback networkPacketCallback,
-                                CANetworkChangeCallback netCallback)
-{
-    OIC_LOG(DEBUG, TAG, "IN");
-    VERIFY_NON_NULL(registerCallback, TAG, "registerCallback");
-    VERIFY_NON_NULL(networkPacketCallback, TAG, "networkPacketCallback");
-    VERIFY_NON_NULL(netCallback, TAG, "netCallback");
-
-    g_networkChangeCallback = netCallback;
-    g_networkPacketCallback = networkPacketCallback;
-
-    CAResult_t ret = CAIPInitializeNetworkMonitor();
-    if (CA_STATUS_OK != ret)
-    {
-        OIC_LOG_V(ERROR, TAG, "init n/w fail:%d", ret);
-        return ret;
-    }
-    CAIPSetConnectionStateChangeCallback(CAIPConnectionStateCB);
-
-    ret = CAIPInitializeServer();
-    if (CA_STATUS_OK != ret)
-    {
-        OIC_LOG_V(ERROR, TAG, "init fail:%d", ret);
-        CATerminateIP();
-        return ret;
-    }
-    CAIPSetPacketReceiveCallback(CAIPPacketReceivedCB);
-
-    CAConnectivityHandler_t IPHandler;
-    IPHandler.startAdapter = CAStartIP;
-    IPHandler.startListenServer = CAStartIPListeningServer;
-    IPHandler.startDiscoveryServer = CAStartIPDiscoveryServer;
-    IPHandler.sendData = CASendIPUnicastData;
-    IPHandler.sendDataToAll = CASendIPMulticastData;
-    IPHandler.GetnetInfo = CAGetIPInterfaceInformation;
-    IPHandler.readData = CAReadIPData;
-    IPHandler.stopAdapter = CAStopIP;
-    IPHandler.terminate = CATerminateIP;
-    registerCallback(IPHandler, CA_ADAPTER_IP);
-
-    OIC_LOG(INFO, TAG, "success");
-    OIC_LOG(DEBUG, TAG, "OUT");
-    return CA_STATUS_OK;
-}
-
-CAResult_t CAStartIP()
-{
-    OIC_LOG(DEBUG, TAG, "IN");
-
-    /* Start monitoring IP network */
-    CAResult_t ret = CAIPStartNetworkMonitor();
-    if (CA_STATUS_OK != ret)
-    {
-        OIC_LOG(ERROR, TAG, "strt n/w monitor fail");
-    }
-
-    g_startUnicastServerRequested = true;
-    bool retVal = CAIPIsConnected();
-    if (false == retVal)
-    {
-        OIC_LOG(ERROR, TAG, "not connected");
-        return ret;
-    }
-
-    uint16_t unicastPort = CA_PORT;
-    int32_t serverFd = 0;
-    // Address is hardcoded as we are using Single Interface
-    ret = CAIPStartUnicastServer("0.0.0.0", &unicastPort, false, &serverFd);
-    if (CA_STATUS_OK == ret)
-    {
-        OIC_LOG_V(DEBUG, TAG, "unicast started:%d", unicastPort);
-        CAIPSetUnicastSocket(serverFd);
-        CAIPSetUnicastPort(unicastPort);
-        g_unicastServerport = unicastPort;
-    }
-
-    OIC_LOG(DEBUG, TAG, "OUT");
-    return ret;
-}
-
-CAResult_t CAStartIPListeningServer()
-{
-    OIC_LOG(DEBUG, TAG, "IN");
-
-    CAResult_t ret = CA_STATUS_OK;
-    uint16_t multicastPort = CA_MCAST_PORT;
-    int32_t serverFD = 1;
-    if (g_isMulticastServerStarted == true)
-    {
-        OIC_LOG(ERROR, TAG, "Already Started!");
-        return CA_SERVER_STARTED_ALREADY;
-    }
-
-    g_startMulticastServerRequested = true;
-    bool retVal = CAIPIsConnected();
-    if (false == retVal)
-    {
-        OIC_LOG(ERROR, TAG,"Not connected");
-        return CA_ADAPTER_NOT_ENABLED;
-    }
-
-    ret = CAIPStartMulticastServer("0.0.0.0", CA_MULTICAST_IP, multicastPort, &serverFD);
-    if (CA_STATUS_OK == ret)
-    {
-        OIC_LOG(INFO, TAG, "multicast success");
-        g_isMulticastServerStarted = true;
-    }
-
-    OIC_LOG(DEBUG, TAG, "OUT");
-    return ret;
-}
-
-CAResult_t CAStartIPDiscoveryServer()
-{
-    OIC_LOG(DEBUG, TAG, "IN");
-    /* Both listening and discovery server are same */
-    OIC_LOG(DEBUG, TAG, "OUT");
-    return CAStartIPListeningServer();
-}
-
-int32_t CASendIPUnicastData(const CAEndpoint_t *endpoint, const void *data, uint32_t dataLength)
-{
-    OIC_LOG(DEBUG, TAG, "IN");
-
-    VERIFY_NON_NULL_RET(endpoint, TAG, "remoteEndpoint", -1);
-    VERIFY_NON_NULL_RET(data, TAG, "data", -1);
-    if (dataLength == 0)
-    {
-        OIC_LOG(ERROR, TAG, "Invalid length");
-        return -1;
-    }
-
-    CAIPSendData(endpoint->addr, endpoint->port, data, dataLength, false);
-    OIC_LOG(DEBUG, TAG, "OUT");
-    return dataLength;
-}
-
-int32_t CASendIPMulticastData(const CAEndpoint_t *endpoint, const void *data, uint32_t dataLength)
-{
-    OIC_LOG(DEBUG, TAG, "IN");
-
-    VERIFY_NON_NULL_RET(data, TAG, "data", -1);
-    if (dataLength == 0)
-    {
-        OIC_LOG(ERROR, TAG, "Invalid length");
-        return -1;
-    }
-
-    CAIPSendData(CA_MULTICAST_IP, CA_MCAST_PORT, data, dataLength, true);
-    OIC_LOG(DEBUG, TAG, "OUT");
-    return dataLength;
-}
-
-CAResult_t CAGetIPInterfaceInformation(CAEndpoint_t **info, uint32_t *size)
-{
-    OIC_LOG(DEBUG, TAG, "IN");
-    VERIFY_NON_NULL(info, TAG, "info");
-    VERIFY_NON_NULL(size, TAG, "size");
-
-    bool retVal = CAIPIsConnected();
-    if (false == retVal)
-    {
-        OIC_LOG(ERROR, TAG, "Not connected");
-        return CA_ADAPTER_NOT_ENABLED;
-    }
-
-    char *ipAddress = NULL;
-    char *ifcName = NULL;
-    CAResult_t ret = CAIPGetInterfaceInfo(&ipAddress, &ifcName);
-    if (CA_STATUS_OK != ret)
-    {
-        OIC_LOG_V(ERROR, TAG, "get interface info fail:%d", ret);
-        OICFree(ipAddress);
-        OICFree(ifcName);
-        return ret;
-    }
-
-    // Create local endpoint using util function
-    (*info) = CACreateEndpointObject(CA_DEFAULT_FLAGS, CA_ADAPTER_IP, ipAddress,
-                                     g_unicastServerport);
-    if (NULL == (*info))
-    {
-        OIC_LOG(ERROR, TAG, "malloc fail");
-        OICFree(ipAddress);
-        OICFree(ifcName);
-        return CA_MEMORY_ALLOC_FAILED;
-    }
-
-    (*size) = 1;
-
-    OICFree(ipAddress);
-    OICFree(ifcName);
-
-    OIC_LOG(INFO, TAG, "success");
-    OIC_LOG(DEBUG, TAG, "OUT");
-    return CA_STATUS_OK;
-}
-
-CAResult_t CAReadIPData()
-{
-    CAIPPullData();
-    return CA_STATUS_OK;
-}
-
-CAResult_t CAIPStopServers()
-{
-    CAResult_t result = CAIPStopUnicastServer();
-    if (CA_STATUS_OK != result)
-    {
-        OIC_LOG_V(ERROR, TAG, "stop ucast srv fail:%d", result);
-        return result;
-    }
-    CAIPSetUnicastSocket(-1);
-    CAIPSetUnicastPort(0);
-    g_unicastServerport = 0;
-
-    result = CAIPStopMulticastServer();
-    if (CA_STATUS_OK != result)
-    {
-        OIC_LOG_V(ERROR, TAG, "stop mcast srv fail:%d", result);
-        return result;
-    }
-    g_isMulticastServerStarted = false;
-
-    return result;
-}
-
-CAResult_t CAStopIP()
-{
-    OIC_LOG(DEBUG, TAG, "IN");
-
-    g_startUnicastServerRequested = false;
-    g_startMulticastServerRequested = false;
-    CAIPStopNetworkMonitor();
-    CAResult_t result = CAIPStopServers();
-    if (CA_STATUS_OK != result)
-    {
-        OIC_LOG_V(ERROR, TAG, "stop srv fail:%d", result);
-    }
-
-    OIC_LOG(DEBUG, TAG, "OUT");
-    return result;
-}
-
-void CATerminateIP()
-{
-    OIC_LOG(DEBUG, TAG, "IN");
-
-    CAIPSetConnectionStateChangeCallback(NULL);
-    CAIPTerminateNetworkMonitor();
-    CAIPSetPacketReceiveCallback(NULL);
-    OIC_LOG(INFO, TAG, "Terminated Ethernet");
-    OIC_LOG(DEBUG, TAG, "OUT");
-    return;
-}
-
-
index 23a3c69..7c0f9aa 100644 (file)
@@ -897,6 +897,12 @@ CAResult_t CAIPStopAllServers()
     return CA_STATUS_OK;
 }
 
+void CAIPPullData()
+{
+    OIC_LOG(DEBUG, IP_SERVER_TAG, "IN");
+    OIC_LOG(DEBUG, IP_SERVER_TAG, "OUT");
+}
+
 uint16_t CAGetServerPortNum(const char *ipAddress, bool isSecured)
 {
     ca_mutex_lock(g_mutexServerInfoList);