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 * @brief 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 CAAdapterServerType_t
42 * @brief Enum for defining different server types.
46 CA_UNICAST_SERVER = 0, /**< Unicast Server */
47 CA_MULTICAST_SERVER, /**< Multicast Server */
48 CA_SECURED_UNICAST_SERVER /**< Secured Unicast Server */
49 } CAAdapterServerType_t;
52 * @brief Callback to be notified on reception of any data from remote OIC devices.
54 * @param endpoint [IN] network endpoint description
55 * @param data [IN] Data received from remote OIC device.
56 * @param dataLength [IN] Length of data in bytes.
59 * @pre Callback must be registered using CAIPSetPacketReceiveCallback()
61 typedef void (*CAIPPacketReceivedCallback)(const CAEndpoint_t *endpoint,
66 * @brief Callback to notify error in the IP adapter
68 * @param endpoint [IN] [IN] network endpoint description
69 * @param data [IN] Data sent/received
70 * @param dataLength [IN] Length of data in bytes.
71 * @param result [IN] result of request from R.I
73 * @pre Callback must be registered using CAIPSetPacketReceiveCallback()
75 typedef void (*CAIPErrorHandleCallback)(const CAEndpoint_t *endpoint, const void *data,
76 uint32_t dataLength, CAResult_t result);
79 * @brief Callback to be notified when exception occures on multicast/unicast server.
80 * @param type [IN] Type of server(#CAAdapterServerType_t)
82 * @pre Callback must be registered using CAIPSetExceptionCallback()
84 typedef void (*CAIPExceptionCallback)(CAAdapterServerType_t type);
87 * @brief Start IP server
89 * @param threadPool [IN] Thread pool for managing Unicast/Multicast server threads.
91 * @return #CA_STATUS_OK or Appropriate error code
92 * @retval #CA_STATUS_OK Successful
93 * @retval #CA_STATUS_INVALID_PARAM Invalid input data
94 * @retval #CA_STATUS_FAILED Initialization failed
97 CAResult_t CAIPStartServer();
99 CAResult_t CAIPStartServer(const ca_thread_pool_t threadPool);
103 * @brief Stop IP server
106 void CAIPStopServer();
109 * @brief Set this callback for receiving data packets from peer devices.
111 * @param callback [IN] Callback to be notified on reception of unicast/multicast data packets.
115 void CAIPSetPacketReceiveCallback(CAIPPacketReceivedCallback callback);
118 * @brief Set this callback for receiving exception notifications.
120 * @param callback [IN] Callback to be notified on occurance of exception on running servers.
124 void CAIPSetExceptionCallback(CAIPExceptionCallback callback);
127 * @brief Set socket description for sending unicast UDP data. Once the Unicast server is started,
128 * the same socket descriptor is used for sending the Unicast UDP data.
130 * @param socketFD [IN] Socket descriptor used for sending UDP data.
133 void CAIPSetUnicastSocket(int socketFD);
136 * @brief Set the port number for sending unicast UDP data
137 * @param port [IN] Port number used for sending UDP data.
140 void CAIPSetUnicastPort(uint16_t port);
143 * @brief API to send unicast UDP data
145 * @param endpoint [IN] complete network address to send to
146 * @param data [IN] Data to be send.
147 * @param dataLength [IN] Length of data in bytes
148 * @param isMulticast [IN] Whether data needs to be sent to multicast ip
150 void CAIPSendData(CAEndpoint_t *endpoint,
156 * @brief Get IP adapter connection state.
158 * @return True if IP adapter is connected, otherwise false
160 bool CAIPIsConnected();
163 * @brief Pull the Received Data
169 #define CA_SECURE_COAP 5684
170 #define INTERFACE_NAME_MAX 16
174 char name[INTERFACE_NAME_MAX];
178 uint32_t ipv4addr; // used for IPv4 only
182 * @brief Get a list of CAInterface_t items
184 * @return List of CAInterface_t items
186 u_arraylist_t *CAIPGetInterfaceInformation(int desiredIndex);
189 * @brief Set callback for error handling
191 * @param ipErrorCallback [IN] callback to notify error to the ipadapter
194 void CAIPSetErrorHandleCallback(CAIPErrorHandleCallback ipErrorCallback);
200 #endif /* CA_IP_INTERFACE_H_ */