/**
* @file caipinterface.h
- * @brief This file provides APIs IP client/server/network monitor modules
+ * This file provides APIs IP client/server/network monitor modules.
*/
#ifndef CA_IP_INTERFACE_H_
#endif
/**
- * @enum CAAdapterServerType_t
- * @brief Enum for defining different server types.
+ * 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 */
+ 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.
+ * 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.
- * @param isSecured [IN] Indicates the data is secure or not.
- *
- * @return NONE
- * @pre Callback must be registered using CAIPSetPacketReceiveCallback()
- */
-typedef void (*CAIPPacketReceivedCallback)(const char *ipAddress, uint16_t port,
- const void *data, uint32_t dataLength,
- bool isSecured);
-
-/**
- * @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
- *
- * @param threadPool [IN] Thread pool for managing Unicast/Multicast server threads.
- *
- * @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(const ca_thread_pool_t threadPool);
-
-/**
- * @brief Terminate IP server
- * @return NONE
+ * @param[in] sep network endpoint description.
+ * @param[in] data Data received from remote OIC device.
+ * @param[in] dataLength Length of data in bytes.
+ * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
+ * @pre Callback must be registered using CAIPSetPacketReceiveCallback().
*/
-void CAIPTerminateServer();
+typedef CAResult_t (*CAIPPacketReceivedCallback)(const CASecureEndpoint_t *sep,
+ const void *data,
+ uint32_t dataLength);
/**
- * @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.
- *
- * @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);
-
-/**
- * @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 secured [IN] True if the secure server to be started, otherwise false.
- *
- * @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,
- bool secured);
-
-/**
- * @brief Stop servers that are running in particular interface address.
- *
- * @param interfaceAddress [IN] interface address in which servers are running.
- *
- * @return #CA_STATUS_OK or Appropriate error code
- * @retval #CA_STATUS_OK Successful
- * @retval #CA_STATUS_FAILED Operation failed
+ * Callback to notify error in the IP adapter.
+ *
+ * @param[in] endpoint network endpoint description.
+ * @param[in] data Data sent/received.
+ * @param[in] dataLength Length of data in bytes.
+ * @param[in] result result of request from R.I.
+ * @pre Callback must be registered using CAIPSetPacketReceiveCallback().
*/
-CAResult_t CAIPStopServer(const char *interfaceAddress);
+typedef void (*CAIPErrorHandleCallback)(const CAEndpoint_t *endpoint, const void *data,
+ uint32_t dataLength, CAResult_t result);
/**
- * @brief Used to stop all unicast and multicast servers.
+ * Start IP server.
*
- * @return #CA_STATUS_OK or Appropriate error code
- * @retval #CA_STATUS_OK Successful
- * @retval #CA_STATUS_FAILED Operation failed
+ * @param threadPool Thread pool for managing Unicast/Multicast server threads.
+ * @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 CAIPStopAllServers();
+#ifdef SINGLE_THREAD
+CAResult_t CAIPStartServer();
+#else
+CAResult_t CAIPStartServer(const ca_thread_pool_t threadPool);
+#endif
/**
- * @brief Used to get the socket fd based on index value of server info list.
- *
- * @param index [IN] Index where we need socket fd value.
- * @param isSecured [IN] For secured unicast server or normal server.
- *
- * @return positive value on success and -1 on error.
+ * Close IP socket.
*/
-int CAGetSocketFdFromUnicastIPServerbyIndex(int16_t index, bool isSecured);
+void CADeInitializeIPGlobals();
/**
- * @brief Used to get the number of unicast server currently running.
- *
- * @param isSecured [IN] To identify whether its secured unicast server or normal server.
- *
- * @return positive value on success and -1 on error.
+ * Stop IP server.
*/
-int16_t CAGetNumberOfUnicastIPServers(bool isSecured);
+void CAIPStopServer();
/**
- * @brief Used to get the stored socket fd for corresponding ipAddress.
- *
- * @param ipAddress [IN] IpAddress of server.
- * @param isSecured [IN] Used to check the server is secured or not.
- * @param isMulticast [IN] To identify whether its for multicast or unicast.
+ * Starts receiving the multicast traffic.
*
- * @return socket fd on success and -1 on error.
+ * This will be used in case sleepy device wants to start back receiving the multicast
+ * traffic.
*/
-int CAGetSocketFdFromUnicastIPServer(const char *ipAddress, bool isSecured, bool isMulticast);
+CAResult_t CAIPStartListenServer();
/**
- * @brief Used to get the port number to the corresponding ip for giving interface info.
+ * Stops the multicast traffic.
*
- * @param ipAddress [IN] IpAddress of server.
- * @param isSecured [IN] Used to check the server is secured or not.
- *
- * @return port number on success and -1 on error.
+ * This is to be used by the sleeping device to stop receiving multicast traffic.
+ * Once this is set no multicast traffic will be received. Device can still receive
+ * the unicast traffic.
*/
-uint16_t CAGetServerPortNum(const char *ipAddress, bool isSecured);
+CAResult_t CAIPStopListenServer();
/**
- * @brief Used to get the port number for corresponding ipAddress.
- *
- * @param serverInfoList [OUT] ServerInfoList holds unicast and multicast server informations.
+ * Set this callback for receiving data packets from peer devices.
*
- * @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 CAGetIPServerInfoList(u_arraylist_t **serverInfoList);
-
-/**
- * @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
+ * @param[in] callback Callback to be notified on reception of unicast/multicast data packets.
*/
void CAIPSetPacketReceiveCallback(CAIPPacketReceivedCallback callback);
/**
- * @brief Set this callback for receiving exception notifications.
- *
- * @param callback [IN] Callback to be notified on occurance of exception on running servers.
+ * 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.
*
- * @return NONE
+ * @param[in] socketFD Socket descriptor used for sending UDP data.
*/
-void CAIPSetExceptionCallback(CAIPExceptionCallback callback);
+void CAIPSetUnicastSocket(int socketFD);
/**
- * @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 data [IN] Data to be send.
- * @param dataLength [IN] Length of data in bytes
- * @param isMulticast [IN] Whether data needs to be sent to multicast ip
- * @param isSecured [IN] Whether data to be sent on secured channel.
- *
- * @return The number of bytes sent on the network. Returns 0 on error.
- * @remarks isSecure will be ignored when isMulticast is true.
+ * Set the port number for sending unicast UDP data.
+ * @param[in] port Port number used for sending UDP data.
*/
-uint32_t CAIPSendData(const char *remoteAddress, uint16_t port, const void *data,
- uint32_t dataLength, bool isMulticast, bool isSecure);
+void CAIPSetUnicastPort(uint16_t port);
/**
- * @brief Callback to be notified when IP adapter connection state changes.
+ * API to send unicast UDP data.
*
- * @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()
+ * @param[in] endpoint complete network address to send to.
+ * @param[in] data Data to be send.
+ * @param[in] dataLength Length of data in bytes.
+ * @param[in] isMulticast Whether data needs to be sent to multicast ip.
*/
-typedef void (*CAIPConnectionStateChangeCallback)(const char *ipAddress,
- CANetworkStatus_t status);
+void CAIPSendData(CAEndpoint_t *endpoint,
+ const void *data,
+ uint32_t dataLength,
+ bool isMulticast);
/**
- * @brief Initialize IP network monitor
- *
- * @param threadPool [IN] Thread pool for managing network monitor thread.
+ * Get IP adapter connection state.
*
- * @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
+ * @return True if IP adapter is connected, otherwise false.
*/
-CAResult_t CAIPInitializeNetworkMonitor(const ca_thread_pool_t threadPool);
+bool CAIPIsConnected();
/**
- * @brief Terminate IP network monitor by removing interface list.
- * @return NONE
+ * Pull the Received Data.
*/
-void CAIPTerminateNetworkMonitor();
+void CAIPPullData();
+
+#define CA_COAP 5683
+#define CA_SECURE_COAP 5684
/**
- * @brief Start network monitoring process. It will start the monitor thread.
+ * Let the network monitor update the polling interval.
+ * @param [in] current polling interval
*
- * @return #CA_STATUS_OK or Appropriate error code
- * @retval #CA_STATUS_OK Successful
- * @retval #CA_STATUS_FAILED Operation failed
+ * @return desired polling interval
*/
-CAResult_t CAIPStartNetworkMonitor();
+int CAGetPollingInterval(int interval);
/**
- * @brief Stop network monitoring process. It will stop the monitor thread.
+ * Set callback for error handling.
*
- * @return #CA_STATUS_OK or Appropriate error code
- * @retval #CA_STATUS_OK Successful
- * @retval #CA_STATUS_FAILED Operation failed
+ * @param[in] errorHandleCallback callback to notify error to the ipadapter.
*/
-CAResult_t CAIPStopNetworkMonitor();
+void CAIPSetErrorHandler(CAIPErrorHandleCallback errorHandleCallback);
/**
- * @brief Get local adapter network information.
+ * Set udp multicast time to live value to control the scope of the multicasts.
+ * @param[in] ttl To be set to any value from 0 to 255.
*
- * @param netInterfaceList [OUT] network interface information list
- *
- * @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().
+ * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
*/
-CAResult_t CAIPGetInterfaceInfo(u_arraylist_t **netInterfaceList);
+CAResult_t CAIPSetMulticastTTL(size_t ttl);
/**
- * @brief Get local adapter network subnet mask.
- *
- * @param ipAddress [IN] IpAddress which is used for getting subnet mask.
- * @param subnetMask [OUT] Local adapter interface subnet mask
+ * Get udp multicast time to live value.
+ * @param[out] ttl TTL pointer to get the stored multicast time to live.
*
- * @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 subnetMask must be freed using free().
+ * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
*/
-CAResult_t CAIPGetInterfaceSubnetMask(const char *ipAddress, char **subnetMask);
+CAResult_t CAIPGetMulticastTTL(size_t *ttl);
/**
- * @brief Get IP adapter connection state.
- *
- * @return True if IP adapter is connected, otherwise false
+ * Create multicast socket to receive multicast message from remote device.
*/
- bool CAIPIsConnected();
+void CreateMulticastSocket();
/**
- * @brief Set callback for receiving local IP adapter connection status.
- *
- * @param callback [IN] Callback to be notified when IP adapter connection state changes.
- * @return NONE
+ * Close multicast socket to stop receiving multicast message.
*/
-void CAIPSetConnectionStateChangeCallback(CAIPConnectionStateChangeCallback callback);
-
+void CloseMulticastSocket();
#ifdef __cplusplus
}
#endif