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>
* @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
/**
* @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
*/
/**
* @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);
+++ /dev/null
-/******************************************************************
- *
- * 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_ */
-
*/
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;
/**
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
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
+++ /dev/null
-/******************************************************************
-*
-* 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_ */
-
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);
case 'B': // send notification
SendNotification();
break;
+ case 'G': // Get network info
+ GetNetworkInfo();
+ break;
case 'N': // select network
SelectNetwork();
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()
{
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");
#include <string.h>
#include <stdint.h>
-#include "caipadapter_singlethread.h"
+#include "caipadapter.h"
#include "caedradapter_singlethread.h"
#include "caleadapter_singlethread.h"
#include "caadapterutils.h"
// Initialize adapters and register callback.
#ifdef IP_ADAPTER
- CAInitializeIP(CARegisterCallback, CAReceivedPacketCallback, CANetworkChangedCallback);
+ CAInitializeIP(CARegisterCallback, CAReceivedPacketCallback, CANetworkChangedCallback,
+ NULL, NULL);
#endif /* IP_ADAPTER */
#ifdef EDR_ADAPTER
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");
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'),
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')
#include "logger.h"
#include "cacommon.h"
#include "caadapterinterface.h"
-#include "caipadapter_singlethread.h"
#include "caadapterutils.h"
#define TAG "IPU"
#include "logger.h"
#include "cacommon.h"
#include "caadapterinterface.h"
-#include "caipadapter_singlethread.h"
+#include "caipadapter.h"
#include "caadapterutils.h"
#ifdef __cplusplus
* limitations under the License.
*
******************************************************************/
-#include "caipinterface_singlethread.h"
+#include "caipinterface.h"
#include <Arduino.h>
#include <Ethernet.h>
#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"
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)
{
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;
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");
* limitations under the License.
*
******************************************************************/
-#include "caipinterface_singlethread.h"
+#include "caipinterface.h"
#include <Arduino.h>
#include <WiFi.h>
#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
}
-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)
{
}
IPAddress remoteIp(ip);
- Udp.beginPacket(remoteIp, (uint16_t)port);
+ Udp.beginPacket(remoteIp, endpoint->port);
uint32_t bytesWritten = 0;
while(bytesWritten < dataLength)
+++ /dev/null
-/******************************************************************
-*
-* 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;
-}
--- /dev/null
+/******************************************************************
+*
+* 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;
+}
--- /dev/null
+/******************************************************************
+*
+* 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;
+}
*
******************************************************************/
-#include "caipinterface_singlethread.h"
+#include "caipinterface.h"
#include <Arduino.h>
#include <Ethernet.h>
#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"
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);
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;
}
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");
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");
}
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");
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");
}
// 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();
+}
*
******************************************************************/
-#include "caipinterface_singlethread.h"
+#include "caipinterface.h"
#include <Arduino.h>
#include <WiFi.h>
#include "cacommon.h"
#include "cainterface.h"
#include "caadapterinterface.h"
-#include "caipadapter_singlethread.h"
+#include "caipadapter.h"
#include "caadapterutils.h"
#include "oic_malloc.h"
#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);
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.
*/
}
-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");
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");
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");
// 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();
+}
* @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
*/
#define CA_MULTICAST_IP "224.0.1.187"
+#ifndef SINGLE_THREAD
/**
* @var CAIPData
* @brief Holds inter thread ip data information.
} 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
*/
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);
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,
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");
#endif
void CAIPPacketReceivedCB(const CAEndpoint_t *endpoint, const void *data,
- uint32_t dataLength)
+ uint32_t dataLength)
{
OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
{
OICFree(buf);
}
-
OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
}
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,
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;
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);
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;
}
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)
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");
#endif
}
CAClearNetInterfaceInfoList(netInterfaceList);
+#endif
OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
return ret;
}
{
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);
}
CAClearNetInterfaceInfoList(netInterfaceList);
+#endif
OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
return ret;
}
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();
}
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)
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)
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;
}
CAResult_t CAReadIPData()
{
OIC_LOG(DEBUG, IP_ADAPTER_TAG, "IN");
-
+ CAIPPullData();
OIC_LOG(DEBUG, IP_ADAPTER_TAG, "OUT");
return CA_STATUS_OK;
}
// 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()
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);
-}
-
+++ /dev/null
-/******************************************************************
- *
- * 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;
-}
-
-
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);