1 /* *****************************************************************
3 * Copyright 2015 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 ******************************************************************/
24 * This file contains the APIs for adapters to be implemented.
27 #ifndef CA_ADAPTER_INTERFACE_H_
28 #define CA_ADAPTER_INTERFACE_H_
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).
47 typedef CAResult_t (*CAAdapterStart)();
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).
59 typedef CAResult_t (*CAAdapterStartListeningServer)();
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
67 * @return ::CA_STATUS_OK or ::CA_STATUS_FAILED
68 * ERROR CODES (::CAResult_t error codes in cacommon.h).
70 typedef CAResult_t (*CAAdapterStopListeningServer)();
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).
82 typedef CAResult_t (*CAAdapterStartDiscoveryServer)();
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 * @return The number of bytes sent on the network. Return value equal to -1 indicates error.
93 typedef int32_t (*CAAdapterSendUnicastData)(const CAEndpoint_t *endpoint,
94 const void *data, uint32_t dataLen);
97 * Sends Multicast data to the endpoint using the adapter connectivity.
98 * Note: length must be > 0.
99 * @param[in] endpoint Remote Endpoint information (like ipaddress , port,
100 * @param[in] data Data which required to be sent.
101 * @param[in] dataLen Size of data to be sent.
102 * @return The number of bytes sent on the network. Return value equal to -1 indicates error.
104 typedef int32_t (*CAAdapterSendMulticastData)(const CAEndpoint_t *endpoint,
105 const void *data, uint32_t dataLen);
108 * Get Network Information.
109 * @param[out] info Local connectivity information structures
110 * @param[out] size Number of local connectivity structures.
111 * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h)
113 typedef CAResult_t (*CAAdapterGetNetworkInfo)(CAEndpoint_t **info, uint32_t *size);
116 * Read Synchronous API callback.
117 * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h)
119 typedef CAResult_t (*CAAdapterReadData)();
122 * Stopping the adapters and close socket connections.
123 * Transport Specific Behavior:
124 * WIFI/ETH Stops all listening servers and close sockets.
125 * EDR Stops all RFCOMM servers and close sockets.
126 * LE Stops all GATT servers and close sockets.
127 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
129 typedef CAResult_t (*CAAdapterStop)();
132 * Terminate the connectivity adapter.Configuration information will be deleted from
133 * further use. Freeing Memory of threadpool and mutexs and cleanup will be done.
135 typedef void (*CAAdapterTerminate)();
138 * Connectivity handler information for adapter.
142 /** Start Transport specific functions. */
143 CAAdapterStart startAdapter;
145 /** Listening Server function address. */
146 CAAdapterStartListeningServer startListenServer;
148 /** Stops receiving the multicast traffic. */
149 CAAdapterStopListeningServer stopListenServer;
151 /** Discovery Server function address. **/
152 CAAdapterStartDiscoveryServer startDiscoveryServer;
154 /** Unicast data function address. **/
155 CAAdapterSendUnicastData sendData;
157 /** Multicast data function address. **/
158 CAAdapterSendMulticastData sendDataToAll;
160 /** Get Networking information. **/
161 CAAdapterGetNetworkInfo GetnetInfo;
163 /** Read Data function address. **/
164 CAAdapterReadData readData;
166 /** Stop Transport specific functions. */
167 CAAdapterStop stopAdapter;
169 /** Terminate function address stored in this pointer. **/
170 CAAdapterTerminate terminate;
172 /** Type of transport adapter. **/
173 CATransportAdapter_t cType;
174 } CAConnectivityHandler_t;
177 * This will be used during the registration of adapters call backs to the common logic.
178 * @see ::CAConnectivityHandler_t
180 typedef void (*CARegisterConnectivityCallback)(CAConnectivityHandler_t handler);
183 * This will be used during the receive of network requests and response.
184 * @see SendUnicastData(), SendMulticastData()
186 typedef void (*CANetworkPacketReceivedCallback)(const CASecureEndpoint_t *sep,
187 const void *data, uint32_t dataLen);
190 * This will be used to notify network changes to the connectivity common logic layer.
192 typedef void (*CAAdapterChangeCallback)(CATransportAdapter_t adapter, CANetworkStatus_t status);
195 * This will be used to notify connection changes to the connectivity common logic layer.
197 typedef void (*CAConnectionChangeCallback)(const CAEndpoint_t *info, bool isConnected);
200 * This will be used to notify error result to the connectivity common logic layer.
202 typedef void (*CAErrorHandleCallback)(const CAEndpoint_t *endpoint,
203 const void *data, uint32_t dataLen,
210 #endif /* CA_ADAPTER_INTERFACE_H_ */