Imported Upstream version 1.0.0
[platform/upstream/iotivity.git] / resource / csdk / connectivity / inc / caipadapter.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  * This file contains the APIs for IP Adapter.
24  */
25 #ifndef CA_IP_ADAPTER_H_
26 #define CA_IP_ADAPTER_H_
27
28 #include "cacommon.h"
29 #include "caadapterinterface.h"
30 #include "cathreadpool.h"
31
32 #ifdef __cplusplus
33 extern "C"
34 {
35 #endif
36
37 /**
38  * API to initialize IP Interface.
39  * @param[in] registerCallback      Callback to register IP interfaces to
40  *                                   Connectivity Abstraction Layer.
41  * @param[in] networkPacketCallback Callback to notify request and
42  *                                   response messages from server(s)
43  *                                   started at Connectivity Abstraction Layer.
44  * @param[in] netCallback           Callback to notify the network additions
45  *                                   to Connectivity Abstraction Layer.
46  * @param[in] errorCallback         Callback to notify the network errors to
47  *                                   Connectivity Abstraction Layer.
48  * @param[in] handle                Threadpool Handle.
49  * @return  ::CA_STATUS_OK or Appropriate error code
50  */
51 CAResult_t CAInitializeIP(CARegisterConnectivityCallback registerCallback,
52                           CANetworkPacketReceivedCallback networkPacketCallback,
53                           CANetworkChangeCallback netCallback,
54                           CAErrorHandleCallback errorCallback, ca_thread_pool_t handle);
55
56 /**
57  * Start IP Interface adapter.
58  * @return  ::CA_STATUS_OK or Appropriate error code.
59  */
60 CAResult_t CAStartIP();
61
62 /**
63  * Start listening server for receiving multicast search requests.
64  * Transport Specific Behavior:
65  * IP Starts Multicast Server on a particular interface and prefixed port
66  * number and as per OIC Specification.
67  * @return  ::CA_STATUS_OK or Appropriate error code.
68  */
69 CAResult_t CAStartIPListeningServer();
70
71 /**
72  * Stop listening server from receiving multicast search requests.
73  * Transport Specific Behavior:
74  * IP closes open multicast socket for a particular interface.
75  * @return  ::CA_STATUS_OK or Appropriate error code.
76  */
77 CAResult_t CAStopIPListeningServer();
78
79 /**
80  * Start discovery servers for receiving multicast advertisements.
81  * Transport Specific Behavior:
82  * IP Starts multicast server on a particular interface and prefixed port
83  * number as per OIC Specification.
84  * @return  ::CA_STATUS_OK or Appropriate error code.
85  */
86 CAResult_t CAStartIPDiscoveryServer();
87
88 /**
89  * Sends data to the endpoint using the adapter connectivity.
90  * @param[in]   endpoint       Remote Endpoint information (like ipaddress,
91  *                              port, reference uri and transport type) to
92  *                              which the unicast data has to be sent.
93  * @param[in]   data           Data which is required to be sent.
94  * @param[in]   dataLen        Size of data to be sent.
95  * @note  dataLen must be > 0.
96  * @return  The number of bytes sent on the network, or -1 upon error.
97  */
98 int32_t CASendIPUnicastData(const CAEndpoint_t *endpoint, const void *data,
99                             uint32_t dataLen);
100
101 /**
102  * Send Multicast data to the endpoint using the IP connectivity.
103  * @param[in]   endpoint       Remote Endpoint information (like ipaddress,
104  *                              port)
105  * @param[in]   data           Data which is required to be sent.
106  * @param[in]   dataLen        Size of data to be sent.
107  * @note  dataLen must be > 0.
108  * @return  The number of bytes sent on the network, or -1 upon error.
109  */
110 int32_t CASendIPMulticastData(const CAEndpoint_t *endpoint, const void *data, uint32_t dataLen);
111
112 /**
113  * Get IP Connectivity network information.
114  * @param[out]   info        Local connectivity information structures.
115  * @note info is allocated in this API and should be freed by the caller.
116  * @param[out]   size        Number of local connectivity structures.
117  * @return  ::CA_STATUS_OK or Appropriate error code.
118  */
119 CAResult_t CAGetIPInterfaceInformation(CAEndpoint_t **info, uint32_t *size);
120
121 /**
122  * Read Synchronous API callback.
123  * @return  ::CA_STATUS_OK or Appropriate error code.
124  */
125 CAResult_t CAReadIPData();
126
127 /**
128  * Stops Unicast, Multicast servers and close the sockets.
129  * @return  ::CA_STATUS_OK or Appropriate error code.
130  */
131 CAResult_t CAStopIP();
132
133 /**
134  * Terminate the IP connectivity adapter.
135  * Configuration information will be deleted from further use.
136  */
137 void CATerminateIP();
138
139 #ifdef __cplusplus
140 } /* extern "C" */
141 #endif
142
143 #endif  // CA_IP_ADAPTER_H_