Merge branch 'master' into simulator
[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  * Start discovery servers for receiving multicast advertisements.
73  * Transport Specific Behavior:
74  * IP Starts multicast server on a particular interface and prefixed port
75  * number as per OIC Specification.
76  * @return  ::CA_STATUS_OK or Appropriate error code.
77  */
78 CAResult_t CAStartIPDiscoveryServer();
79
80 /**
81  * Sends data to the endpoint using the adapter connectivity.
82  * @param[in]   endpoint       Remote Endpoint information (like ipaddress,
83  *                              port, reference uri and transport type) to
84  *                              which the unicast data has to be sent.
85  * @param[in]   data           Data which is required to be sent.
86  * @param[in]   dataLen        Size of data to be sent.
87  * @note  dataLen must be > 0.
88  * @return  The number of bytes sent on the network, or -1 upon error.
89  */
90 int32_t CASendIPUnicastData(const CAEndpoint_t *endpoint, const void *data,
91                             uint32_t dataLen);
92
93 /**
94  * Send Multicast data to the endpoint using the IP connectivity.
95  * @param[in]   endpoint       Remote Endpoint information (like ipaddress,
96  *                              port)
97  * @param[in]   data           Data which is required to be sent.
98  * @param[in]   dataLen        Size of data to be sent.
99  * @note  dataLen must be > 0.
100  * @return  The number of bytes sent on the network, or -1 upon error.
101  */
102 int32_t CASendIPMulticastData(const CAEndpoint_t *endpoint, const void *data, uint32_t dataLen);
103
104 /**
105  * Get IP Connectivity network information.
106  * @param[out]   info        Local connectivity information structures.
107  * @note info is allocated in this API and should be freed by the caller.
108  * @param[out]   size        Number of local connectivity structures.
109  * @return  ::CA_STATUS_OK or Appropriate error code.
110  */
111 CAResult_t CAGetIPInterfaceInformation(CAEndpoint_t **info, uint32_t *size);
112
113 /**
114  * Read Synchronous API callback.
115  * @return  ::CA_STATUS_OK or Appropriate error code.
116  */
117 CAResult_t CAReadIPData();
118
119 /**
120  * Stops Unicast, Multicast servers and close the sockets.
121  * @return  ::CA_STATUS_OK or Appropriate error code.
122  */
123 CAResult_t CAStopIP();
124
125 /**
126  * Terminate the IP connectivity adapter.
127  * Configuration information will be deleted from further use.
128  */
129 void CATerminateIP();
130
131 #ifdef __cplusplus
132 } /* extern "C" */
133 #endif
134
135 #endif  // CA_IP_ADAPTER_H_