d51c41f24574b7e163a83b29ae12efa0cfdb973c
[platform/upstream/iotivity.git] / resource / csdk / connectivity / inc / caadapterinterface.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
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  * @brief 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  * @brief 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  * @brief for starting discovery servers for receiving multicast advertisements
63  * Transport Specific Behavior:
64  * WIFI/ETH Starts multicast server on all available IPs and defined port
65  * number as per OIC Specification.
66  * EDR Starts RFCOMM Server with prefixed UUID as per OIC Specification.
67  * LE Starts GATT Server with prefixed UUID and Characteristics as per OIC Specification.
68  * @return CA_STATUS_OK or CA_STATUS_FAILED
69  * ERROR CODES (CAResult_t error codes in cacommon.h)
70  */
71 typedef CAResult_t (*CAAdapterStartDiscoveryServer)();
72
73 /**
74  * @brief Sends data to the endpoint using the adapter connectivity.
75  * Note: length must be > 0.
76  * @param   endpoint    [IN]    Remote Endpoint information (like ipaddress , port,
77  * reference uri and connectivity type) to which the unicast data has to be sent.
78  * @param   data        [IN]    Data which required to be sent.
79  * @param   dataLen     [IN]    Size of data to be sent.
80  * @return The number of bytes sent on the network. Return value equal to -1 indicates error.
81  */
82 typedef int32_t (*CAAdapterSendUnitcastData)(const CARemoteEndpoint_t *endpoint,
83         const void *data, uint32_t dataLen);
84
85 /**
86  * @brief Sends Multicast data to the endpoint using the adapter connectivity.
87  * Note: length must be > 0.
88  * @param   data        [IN]    Data which required to be sent.
89  * @param   dataLen     [IN]    Size of data to be sent.
90  * @return The number of bytes sent on the network. Return value equal to -1 indicates error.
91  */
92 typedef int32_t (*CAAdapterSendMulticastData)(const void *data, uint32_t dataLen);
93
94 /**
95  * @brief Get Network Information
96  * @param   info        [OUT]   Local connectivity information structures
97  * @param   size        [OUT]   Number of local connectivity structures.
98  * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
99  */
100 typedef CAResult_t (*CAAdapterGetNetworkInfo)(CALocalConnectivity_t **info, uint32_t *size);
101
102 /**
103  * @brief Read Synchronous API callback.
104  * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
105  */
106 typedef CAResult_t (*CAAdapterReadData)();
107
108 /**
109  * @brief Stopping the adapters and close socket connections
110  * Transport Specific Behavior:
111  * WIFI/ETH Stops all listening servers and close sockets.
112  * EDR Stops all RFCOMM servers and close sockets.
113  * LE Stops all GATT servers and close sockets.
114  * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
115  */
116 typedef CAResult_t (*CAAdapterStop)();
117
118 /**
119  * @brief Terminate the connectivity adapter.Configuration information will be deleted from
120  * further use. Freeing Memory of threadpool and mutexs and cleanup will be done.
121  */
122 typedef void (*CAAdapterTerminate)();
123
124 /**
125  * @brief Connectivity handler information for adapter
126  */
127 typedef struct
128 {
129     /** Start Transport specific functions*/
130     CAAdapterStart startAdapter;
131
132     /** Listening Server function address*/
133     CAAdapterStartListeningServer startListenServer;
134
135     /** Discovery Server function address **/
136     CAAdapterStartDiscoveryServer startDiscoveryServer;
137
138     /** Unicast data function address**/
139     CAAdapterSendUnitcastData sendData;
140
141     /** Multicast data function address**/
142     CAAdapterSendMulticastData sendDataToAll;
143
144     /** Get Networking information  **/
145     CAAdapterGetNetworkInfo GetnetInfo;
146
147     /** Read Data function address**/
148     CAAdapterReadData readData;
149
150     /** Stop Transport specific functions*/
151     CAAdapterStop stopAdapter;
152
153     /** Terminate function address stored in this pointer**/
154     CAAdapterTerminate terminate;
155
156 } CAConnectivityHandler_t;
157
158 /**
159  * @brief This will be used during the registration of adapters call backs to the common logic
160  * @see CAConnectivityHandler_t , CATransportType_t
161  */
162 typedef void (*CARegisterConnectivityCallback)(CAConnectivityHandler_t handler,
163         CATransportType_t cType);
164
165 /**
166  * @brief This will be used during the recive of network requests and response.
167  * @see SendUnitcastData(), SendMulticastData()
168  */
169 typedef void (*CANetworkPacketReceivedCallback)(CARemoteEndpoint_t *endPoint, void *data,
170         uint32_t dataLen);
171
172 /**
173  * @brief This will be used to notify network changes to the connectivity common logic layer
174  * @see SendUnitcastData(), SendMulticastData()
175  */
176 typedef void (*CANetworkChangeCallback)(CALocalConnectivity_t *info, CANetworkStatus_t status);
177
178 #ifdef __cplusplus
179 } /* extern "C" */
180 #endif
181
182 #endif  // CA_ADAPTER_INTERFACE_H_
183