1 /******************************************************************
3 * Copyright 2014 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 ******************************************************************/
22 * @file caipinterface.h
23 * This file provides APIs IP client/server/network monitor modules.
26 #ifndef CA_IP_INTERFACE_H_
27 #define CA_IP_INTERFACE_H_
32 #include "cathreadpool.h"
33 #include "uarraylist.h"
41 * Enum for defining different server types.
45 CA_UNICAST_SERVER = 0, /**< Unicast Server */
46 CA_MULTICAST_SERVER, /**< Multicast Server */
47 CA_SECURED_UNICAST_SERVER /**< Secured Unicast Server */
48 } CAAdapterServerType_t;
51 * Callback to be notified on reception of any data from remote OIC devices.
53 * @param[in] sep network endpoint description.
54 * @param[in] data Data received from remote OIC device.
55 * @param[in] dataLength Length of data in bytes.
56 * @pre Callback must be registered using CAIPSetPacketReceiveCallback().
58 typedef void (*CAIPPacketReceivedCallback)(const CASecureEndpoint_t *sep,
63 * Callback to notify error in the IP adapter.
65 * @param[in] endpoint network endpoint description.
66 * @param[in] data Data sent/received.
67 * @param[in] dataLength Length of data in bytes.
68 * @param[in] result result of request from R.I.
69 * @pre Callback must be registered using CAIPSetPacketReceiveCallback().
71 typedef void (*CAIPErrorHandleCallback)(const CAEndpoint_t *endpoint, const void *data,
72 uint32_t dataLength, CAResult_t result);
75 * Callback to be notified when exception occures on multicast/unicast server.
76 * @param type Type of server(#CAAdapterServerType_t).
77 * @pre Callback must be registered using CAIPSetExceptionCallback().
79 typedef void (*CAIPExceptionCallback)(CAAdapterServerType_t type);
84 * @param threadPool Thread pool for managing Unicast/Multicast server threads.
85 * @return ::CA_STATUS_OK or Appropriate error code.
86 * @retval ::CA_STATUS_OK Successful.
87 * @retval ::CA_STATUS_INVALID_PARAM Invalid input data.
88 * @retval ::CA_STATUS_FAILED Initialization failed.
91 CAResult_t CAIPStartServer();
93 CAResult_t CAIPStartServer(const ca_thread_pool_t threadPool);
99 void CADeInitializeIPGlobals();
104 void CAIPStopServer();
107 * Starts receiving the multicast traffic.
109 * This will be used in case sleepy device wants to start back receiving the multicast
112 CAResult_t CAIPStartListenServer();
115 * Stops the multicast traffic.
117 * This is to be used by the sleeping device to stop receiving multicast traffic.
118 * Once this is set no multicast traffic will be received. Device can still receive
119 * the unicast traffic.
121 CAResult_t CAIPStopListenServer();
124 * Set this callback for receiving data packets from peer devices.
126 * @param[in] callback Callback to be notified on reception of unicast/multicast data packets.
128 void CAIPSetPacketReceiveCallback(CAIPPacketReceivedCallback callback);
131 * Set this callback for receiving exception notifications.
133 * @param[in] callback Callback to be notified on exception on running servers.
135 void CAIPSetExceptionCallback(CAIPExceptionCallback callback);
138 * Set socket description for sending unicast UDP data.
139 * Once the Unicast server is started,
140 * the same socket descriptor is used for sending the Unicast UDP data.
142 * @param[in] socketFD Socket descriptor used for sending UDP data.
144 void CAIPSetUnicastSocket(int socketFD);
147 * Set the port number for sending unicast UDP data.
148 * @param[in] port Port number used for sending UDP data.
150 void CAIPSetUnicastPort(uint16_t port);
153 * API to send unicast UDP data.
155 * @param[in] endpoint complete network address to send to.
156 * @param[in] data Data to be send.
157 * @param[in] dataLength Length of data in bytes.
158 * @param[in] isMulticast Whether data needs to be sent to multicast ip.
160 void CAIPSendData(CAEndpoint_t *endpoint,
166 * Get IP adapter connection state.
168 * @return True if IP adapter is connected, otherwise false.
170 bool CAIPIsConnected();
173 * Pull the Received Data.
178 #define CA_SECURE_COAP 5684
179 #define INTERFACE_NAME_MAX 16
183 char name[INTERFACE_NAME_MAX];
187 uint32_t ipv4addr; /**< used for IPv4 only. */
192 * Callback to be notified when IP adapter connection state changes.
194 * @param[in] adapter Transport adapter.
195 * @param[in] status Connection status either ::CA_INTERFACE_UP or ::CA_INTERFACE_DOWN.
196 * @see CAIPSetConnectionStateChangeCallback() for registration.
198 typedef void (*CAIPConnectionStateChangeCallback)(CATransportAdapter_t adapter, CANetworkStatus_t status);
201 * Set callback for receiving local IP adapter connection status.
203 * @param[in] adapter Callback to be notified when IP adapter connection state changes.
205 void CAIPSetConnectionStateChangeCallback(CAIPConnectionStateChangeCallback callback);
208 * Set callback for receiving local IP adapter connection status.
210 * @param[in] callback Callback to be notified when IP adapter connection state changes.
212 void CAIPSetNetworkMonitorCallback(CAIPConnectionStateChangeCallback callback);
215 * Get a list of CAInterface_t items.
217 * @return List of CAInterface_t items.
219 u_arraylist_t *CAIPGetInterfaceInformation(int desiredIndex);
222 * Find a new network interface.
224 * @return Description of interface (or NULL if no change)
226 CAInterface_t *CAFindInterfaceChange();
229 * Let the network monitor update the polling interval.
230 * @param [in] current polling interval
232 * @return desired polling interval
234 int CAGetPollingInterval(int interval);
237 * Tell the IP server an interface has been added.
239 void CAWakeUpForChange();
242 * Start network monitor.
244 * @return ::CA_STATUS_OK or Appropriate error code.
246 CAResult_t CAIPStartNetworkMonitor();
249 * Stops network monitor.
251 * @return ::CA_STATUS_OK or Appropriate error code.
253 CAResult_t CAIPStopNetworkMonitor();
256 * Set callback for error handling.
258 * @param[in] ipErrorCallback callback to notify error to the ipadapter.
260 void CAIPSetErrorHandleCallback(CAIPErrorHandleCallback ipErrorCallback);
266 #endif /* CA_IP_INTERFACE_H_ */