Imported Upstream version 0.9.2
[platform/upstream/iotivity.git] / resource / csdk / connectivity / inc / caipinterface.h
1 /******************************************************************
2  *
3  * Copyright 2014 Samsung Electronics All Rights Reserved.
4  *
5  *
6  *
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  ******************************************************************/
20
21 /**
22  * @file caipinterface.h
23  * @brief This file provides APIs IP client/server/network monitor modules
24  */
25
26 #ifndef CA_IP_INTERFACE_H_
27 #define CA_IP_INTERFACE_H_
28
29 #include <stdbool.h>
30
31 #include "cacommon.h"
32 #include "cathreadpool.h"
33 #include "uarraylist.h"
34
35 #ifdef __cplusplus
36 extern "C"
37 {
38 #endif
39
40 /**
41  * @enum CAAdapterServerType_t
42  * @brief Enum for defining different server types.
43  */
44 typedef enum
45 {
46     CA_UNICAST_SERVER = 0,      /**< Unicast Server */
47     CA_MULTICAST_SERVER,        /**< Multicast Server */
48     CA_SECURED_UNICAST_SERVER   /**< Secured Unicast Server */
49 } CAAdapterServerType_t;
50
51 /**
52  * @brief Callback to be notified on reception of any data from remote OIC devices.
53  *
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.
57  *
58  * @return NONE
59  * @pre  Callback must be registered using CAIPSetPacketReceiveCallback()
60  */
61 typedef void (*CAIPPacketReceivedCallback)(const CAEndpoint_t *endpoint,
62                                            const void *data,
63                                            uint32_t dataLength);
64
65 /**
66   * @brief Callback to notify error in the IP adapter
67   *
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
72   * @return NONE
73   * @pre  Callback must be registered using CAIPSetPacketReceiveCallback()
74  */
75 typedef void (*CAIPErrorHandleCallback)(const CAEndpoint_t *endpoint, const void *data,
76                                         uint32_t dataLength, CAResult_t result);
77
78 /**
79  * @brief  Callback to be notified when exception occures on multicast/unicast server.
80  * @param  type  [IN] Type of server(#CAAdapterServerType_t)
81  * @return NONE
82  * @pre  Callback must be registered using CAIPSetExceptionCallback()
83  */
84 typedef void (*CAIPExceptionCallback)(CAAdapterServerType_t type);
85
86 /**
87  * @brief  Start IP server
88  *
89  * @param   threadPool  [IN] Thread pool for managing Unicast/Multicast server threads.
90  *
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
95  */
96 #ifdef SINGLE_THREAD
97 CAResult_t CAIPStartServer();
98 #else
99 CAResult_t CAIPStartServer(const ca_thread_pool_t threadPool);
100 #endif
101
102 /**
103  * @brief  Stop IP server
104  * @return NONE
105  */
106 void CAIPStopServer();
107
108 /**
109  * @brief  Set this callback for receiving data packets from peer devices.
110  *
111  * @param  callback   [IN] Callback to be notified on reception of unicast/multicast data packets.
112  *
113  * @return  NONE
114  */
115 void CAIPSetPacketReceiveCallback(CAIPPacketReceivedCallback callback);
116
117 /**
118  * @brief  Set this callback for receiving exception notifications.
119  *
120  * @param  callback [IN] Callback to be notified on occurance of exception on running servers.
121  *
122  * @return  NONE
123  */
124 void CAIPSetExceptionCallback(CAIPExceptionCallback callback);
125
126 /**
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.
129  *
130  * @param  socketFD [IN]  Socket descriptor used for sending UDP data.
131  * @return  NONE
132  */
133 void CAIPSetUnicastSocket(int socketFD);
134
135 /**
136  * @brief  Set the port number for sending unicast UDP data
137  * @param  port [IN] Port number used for sending UDP data.
138  * @return NONE
139  */
140 void CAIPSetUnicastPort(uint16_t port);
141
142 /**
143  * @brief  API to send unicast UDP data
144  *
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
149  */
150 void CAIPSendData(CAEndpoint_t *endpoint,
151                   const void *data,
152                   uint32_t dataLength,
153                   bool isMulticast);
154
155 /**
156  * @brief  Get IP adapter connection state.
157  *
158  * @return  True if IP adapter is connected, otherwise false
159  */
160 bool CAIPIsConnected();
161
162 /**
163  * @brief  Pull the Received Data
164  * @return NONE
165  */
166 void CAIPPullData();
167
168 #define CA_COAP        5683
169 #define CA_SECURE_COAP 5684
170 #define INTERFACE_NAME_MAX 16
171
172 typedef struct
173 {
174     char name[INTERFACE_NAME_MAX];
175     uint32_t index;
176     uint32_t flags;
177     uint16_t family;
178     uint32_t ipv4addr;        // used for IPv4 only
179 } CAInterface_t;
180
181 /**
182  * @brief  Get a list of CAInterface_t items
183  *
184  * @return  List of CAInterface_t items
185  */
186 u_arraylist_t *CAIPGetInterfaceInformation(int desiredIndex);
187
188 /**
189  * @brief  Set callback for error handling
190  *
191  * @param  ipErrorCallback [IN] callback to notify error to the ipadapter
192  * @return NONE
193  */
194 void CAIPSetErrorHandleCallback(CAIPErrorHandleCallback ipErrorCallback);
195
196 #ifdef __cplusplus
197 }
198 #endif
199
200 #endif /* CA_IP_INTERFACE_H_ */