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