replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / resource / csdk / connectivity / inc / caadapterinterface.h
1 /* *****************************************************************
2  *
3  * Copyright 2015 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
23  *
24  * This file contains the APIs for adapters to be implemented.
25  */
26
27 #ifndef CA_ADAPTER_INTERFACE_H_
28 #define CA_ADAPTER_INTERFACE_H_
29
30 #include "cacommon.h"
31
32 #ifdef __cplusplus
33 extern "C"
34 {
35 #endif
36
37 /**
38  * Starting connectivity adapters and each adapter have transport specific behavior.
39  * Transport Specific Behavior:
40  * WIFI/ETH connectivity Starts unicast server on  all available IPs and defined
41  * port number as per specification.
42  * EDR will not start any specific servers.
43  * LE will not start any specific servers.
44  * @return ::CA_STATUS_OK or ::CA_STATUS_FAILED
45  *  ERROR CODES (::CAResult_t error codes in cacommon.h).
46  */
47 typedef CAResult_t (*CAAdapterStart)();
48
49 /**
50  * Starting listening server for receiving multicast search requests
51  * Transport Specific Behavior:
52  * WIFI/ETH Starts multicast server on  all available IPs and defined
53  * port number and as per specification.
54  * EDR  Starts RFCOMM Server with prefixed UUID as per specification.
55  * LE Start GATT Server with prefixed UUID and Characteristics as per OIC Specification.
56  * @return ::CA_STATUS_OK or ::CA_STATUS_FAILED
57  * ERROR CODES (::CAResult_t error codes in cacommon.h).
58  */
59 typedef CAResult_t (*CAAdapterStartListeningServer)();
60
61 /**
62  * Stopping listening server to not receive multicast search requests
63  * Transport Specific Behavior:
64  * WIFI/ETH Stops multicast server on  all available IPs. This is required for the
65  * thin device that call this function once all local resources are pushed to the
66  * resource directory.
67  * @return ::CA_STATUS_OK or ::CA_STATUS_FAILED
68  * ERROR CODES (::CAResult_t error codes in cacommon.h).
69  */
70 typedef CAResult_t (*CAAdapterStopListeningServer)();
71
72 /**
73  * for starting discovery servers for receiving multicast advertisements
74  * Transport Specific Behavior:
75  * WIFI/ETH Starts multicast server on all available IPs and defined port
76  * number as per OIC Specification.
77  * EDR Starts RFCOMM Server with prefixed UUID as per OIC Specification.
78  * LE Starts GATT Server with prefixed UUID and Characteristics as per OIC Specification.
79  * @return ::CA_STATUS_OK or ::CA_STATUS_FAILED
80  * ERROR CODES (::CAResult_t error codes in cacommon.h).
81  */
82 typedef CAResult_t (*CAAdapterStartDiscoveryServer)();
83
84 /**
85  * Sends data to the endpoint using the adapter connectivity.
86  * Note: length must be > 0.
87  * @param[in]   endpoint        Remote Endpoint information (like ipaddress , port,
88  * reference uri and connectivity type) to which the unicast data has to be sent.
89  * @param[in]   data            Data which required to be sent.
90  * @param[in]   dataLen         Size of data to be sent.
91  * @param[in]   dataType        Data type which is REQUEST or RESPONSE.
92  * @return The number of bytes sent on the network. Return value equal to -1 indicates error.
93  */
94 typedef int32_t (*CAAdapterSendUnicastData)(const CAEndpoint_t *endpoint,
95                                             const void *data, uint32_t dataLen,
96                                             CADataType_t dataType);
97
98 /**
99  * Sends Multicast data to the endpoint using the adapter connectivity.
100  * Note: length must be > 0.
101  * @param[in]   endpoint        Remote Endpoint information (like ipaddress , port,
102  * @param[in]   data            Data which required to be sent.
103  * @param[in]   dataLen         Size of data to be sent.
104  * @param[in]   dataType        Data type which is REQUEST or RESPONSE.
105  * @return The number of bytes sent on the network. Return value equal to -1 indicates error.
106  */
107 typedef int32_t (*CAAdapterSendMulticastData)(const CAEndpoint_t *endpoint,
108                                               const void *data, uint32_t dataLen,
109                                               CADataType_t dataType);
110
111 /**
112  * Get Network Information.
113  * @param[out]   info           Local connectivity information structures
114  * @param[out]   size           Number of local connectivity structures.
115  * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
116  */
117 typedef CAResult_t (*CAAdapterGetNetworkInfo)(CAEndpoint_t **info, uint32_t *size);
118
119 /**
120  * Read Synchronous API callback.
121  * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
122  */
123 typedef CAResult_t (*CAAdapterReadData)();
124
125 /**
126  * Stopping the adapters and close socket connections.
127  * Transport Specific Behavior:
128  * WIFI/ETH Stops all listening servers and close sockets.
129  * EDR Stops all RFCOMM servers and close sockets.
130  * LE Stops all GATT servers and close sockets.
131  * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
132  */
133 typedef CAResult_t (*CAAdapterStop)();
134
135 /**
136  * Terminate the connectivity adapter.Configuration information will be deleted from
137  * further use. Freeing Memory of threadpool and mutexs and cleanup will be done.
138  */
139 typedef void (*CAAdapterTerminate)();
140
141 /**
142  * Connectivity handler information for adapter.
143  */
144 typedef struct
145 {
146     /** Start Transport specific functions. */
147     CAAdapterStart startAdapter;
148
149     /** Listening Server function address. */
150     CAAdapterStartListeningServer startListenServer;
151
152     /** Stops receiving the multicast traffic. */
153     CAAdapterStopListeningServer stopListenServer;
154
155     /** Discovery Server function address. **/
156     CAAdapterStartDiscoveryServer startDiscoveryServer;
157
158     /** Unicast data function address. **/
159     CAAdapterSendUnicastData sendData;
160
161     /** Multicast data function address. **/
162     CAAdapterSendMulticastData sendDataToAll;
163
164     /** Get Networking information. **/
165     CAAdapterGetNetworkInfo GetnetInfo;
166
167     /** Read Data function address. **/
168     CAAdapterReadData readData;
169
170     /** Stop Transport specific functions. */
171     CAAdapterStop stopAdapter;
172
173     /** Terminate function address stored in this pointer. **/
174     CAAdapterTerminate terminate;
175
176     /** Type of transport adapter. **/
177     CATransportAdapter_t cType;
178 } CAConnectivityHandler_t;
179
180 /**
181  * This will be used during the registration of adapters call backs to the common logic.
182  * @see ::CAConnectivityHandler_t
183  */
184 typedef void (*CARegisterConnectivityCallback)(CAConnectivityHandler_t handler);
185
186 /**
187  * This will be used during the receive of network requests and response.
188  * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
189  * @see SendUnicastData(), SendMulticastData()
190  */
191 typedef CAResult_t (*CANetworkPacketReceivedCallback)(const CASecureEndpoint_t *sep,
192                                                       const void *data, size_t dataLen);
193
194 /**
195  * This will be used to notify network changes to the connectivity common logic layer.
196  */
197 typedef void (*CAAdapterChangeCallback)(CATransportAdapter_t adapter, CANetworkStatus_t status);
198
199 /**
200  * This will be used to notify connection changes to the connectivity common logic layer.
201  */
202 typedef void (*CAConnectionChangeCallback)(const CAEndpoint_t *info, bool isConnected);
203
204 /**
205  * This will be used to notify error result to the connectivity common logic layer.
206  */
207 typedef void (*CAErrorHandleCallback)(const CAEndpoint_t *endpoint,
208                                       const void *data, size_t dataLen,
209                                       CAResult_t result);
210
211 #ifdef __cplusplus
212 } /* extern "C" */
213 #endif
214
215 #endif  /* CA_ADAPTER_INTERFACE_H_ */
216
217