API change , Retransmission Callback on expiry , remove glib source for dynamic linking
[platform/upstream/iotivity.git] / resource / csdk / connectivity / src / caconnectivitymanager.c
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 #include <stdio.h>
22 #include <stdlib.h>
23 #include <stdint.h>
24
25 #include "cainterface.h"
26 #include "caremotehandler.h"
27 #include "camessagehandler.h"
28 #include "caprotocolmessage.h"
29 #include "canetworkconfigurator.h"
30 #include "cainterfacecontroller.h"
31 #include "logger.h"
32
33 #define TAG PCF("CA")
34
35 CAResult_t CAInitialize()
36 {
37     OIC_LOG_V(DEBUG, TAG, "CAInitialize");
38
39     CAResult_t res = CAInitializeMessageHandler();
40
41     if (res != CA_STATUS_OK)
42     {
43         return res;
44     }
45
46     return CA_STATUS_OK;
47 }
48
49 void CATerminate()
50 {
51     OIC_LOG_V(DEBUG, TAG, "CATerminate");
52
53     CATerminateMessageHandler();
54 }
55
56 CAResult_t CAStartListeningServer()
57 {
58     OIC_LOG_V(DEBUG, TAG, "CAStartListeningServer");
59
60     return CAStartListeningServerAdapters();
61 }
62
63 CAResult_t CAStartDiscoveryServer()
64 {
65     OIC_LOG_V(DEBUG, TAG, "CAStartDiscoveryServer");
66
67     return CAStartDiscoveryServerAdapters();
68 }
69
70 CAResult_t CARegisterHandler(CARequestCallback ReqHandler, CAResponseCallback RespHandler)
71 {
72     OIC_LOG_V(DEBUG, TAG, "CARegisterHandler");
73
74     CASetRequestResponseCallbacks(ReqHandler, RespHandler);
75
76     return CA_STATUS_OK;
77 }
78
79 CAResult_t CACreateRemoteEndpoint(const CAURI_t uri, 
80     const CAConnectivityType_t connectivityType,CARemoteEndpoint_t **remoteEndpoint)
81 {
82     OIC_LOG_V(DEBUG, TAG, "CACreateRemoteEndpoint");
83
84     CARemoteEndpoint_t *remote = CACreateRemoteEndpointUriInternal(uri, connectivityType);
85
86     *remoteEndpoint = remote;
87
88     if (remote == NULL)
89         return CA_STATUS_FAILED;
90
91     return CA_STATUS_OK;
92 }
93
94 void CADestroyRemoteEndpoint(CARemoteEndpoint_t *rep)
95 {
96     OIC_LOG_V(DEBUG, TAG, "CADestroyRemoteEndpoint");
97
98     CADestroyRemoteEndpointInternal(rep);
99 }
100
101 CAResult_t CAGenerateToken(CAToken_t *token)
102 {
103     OIC_LOG_V(DEBUG, TAG, "CAGenerateToken");
104
105     return CAGenerateTokenInternal(token);
106 }
107
108 void CADestroyToken(CAToken_t token)
109 {
110     OIC_LOG_V(DEBUG, TAG, "CADestroyToken");
111
112     CADestroyTokenInternal(token);
113 }
114
115 CAResult_t CAGetNetworkInformation(CALocalConnectivity_t **info, uint32_t *size)
116 {
117     OIC_LOG_V(DEBUG, TAG, "CAGetNetworkInformation");
118
119     return CAGetNetworkInformationInternal(info, size);
120 }
121
122 CAResult_t CAFindResource(const CAURI_t resourceUri, const CAToken_t token)
123 {
124     OIC_LOG_V(DEBUG, TAG, "CAFindResource");
125
126     return CADetachMessageResourceUri(resourceUri, token, NULL, 0);
127
128 }
129
130 CAResult_t CASendRequest(const CARemoteEndpoint_t *object, CARequestInfo_t *requestInfo)
131 {
132     OIC_LOG_V(DEBUG, TAG, "CASendGetRequest");
133
134     return CADetachRequestMessage(object, requestInfo);
135 }
136
137 CAResult_t CASendRequestToAll(const CAGroupEndpoint_t *object,
138                               const CARequestInfo_t *requestInfo)
139 {
140     OIC_LOG_V(DEBUG, TAG, "CASendRequestToAll");
141
142     return CADetachRequestToAllMessage(object, requestInfo);
143 }
144
145 CAResult_t CASendNotification(const CARemoteEndpoint_t *object, CAResponseInfo_t *responseInfo)
146 {
147     OIC_LOG_V(DEBUG, TAG, "CASendNotification");
148
149     return CADetachResponseMessage(object, responseInfo);
150
151 }
152
153 CAResult_t CASendResponse(const CARemoteEndpoint_t *object, CAResponseInfo_t *responseInfo)
154 {
155     OIC_LOG_V(DEBUG, TAG, "CASendResponse");
156
157     return CADetachResponseMessage(object, responseInfo);
158
159 }
160
161 CAResult_t CAAdvertiseResource(const CAURI_t resourceUri, CAToken_t token,
162                                CAHeaderOption_t *options, uint8_t numOptions)
163 {
164     OIC_LOG_V(DEBUG, TAG, "CAAdvertiseResource");
165
166     return CADetachMessageResourceUri(resourceUri, token, options, numOptions);
167
168 }
169
170 CAResult_t CASelectNetwork(const uint32_t interestedNetwork)
171 {
172     OIC_LOG_V(DEBUG, TAG, "Selected network : %d", interestedNetwork);
173
174     if (!(interestedNetwork & 0xf))
175     {
176         return CA_NOT_SUPPORTED;
177     }
178     CAResult_t res;
179
180     if (interestedNetwork & CA_ETHERNET)
181     {
182         res = CAAddNetworkType(CA_ETHERNET);
183         if (res != CA_STATUS_OK)
184         {
185             return res;
186         }
187     }
188
189     if (interestedNetwork & CA_WIFI)
190     {
191         res = CAAddNetworkType(CA_WIFI);
192         if (res != CA_STATUS_OK)
193         {
194             return res;
195         }
196     }
197
198     if (interestedNetwork & CA_EDR)
199     {
200         res = CAAddNetworkType(CA_EDR);
201         if (res != CA_STATUS_OK)
202         {
203             return res;
204         }
205     }
206
207     if (interestedNetwork & CA_LE)
208     {
209         res = CAAddNetworkType(CA_LE);
210         if (res != CA_STATUS_OK)
211         {
212             return res;
213         }
214     }
215
216     return CA_STATUS_OK;
217 }
218
219 CAResult_t CAUnSelectNetwork(const uint32_t nonInterestedNetwork)
220 {
221     OIC_LOG_V(DEBUG, TAG, "unselected network : %d", nonInterestedNetwork);
222
223     if (!(nonInterestedNetwork & 0xf))
224     {
225         return CA_NOT_SUPPORTED;
226     }
227
228     CAResult_t res;
229
230     if (nonInterestedNetwork & CA_ETHERNET)
231     {
232         res = CARemoveNetworkType(CA_ETHERNET);
233         if (res != CA_STATUS_OK)
234         {
235             return res;
236         }
237     }
238
239     if (nonInterestedNetwork & CA_WIFI)
240     {
241         res = CARemoveNetworkType(CA_WIFI);
242         if (res != CA_STATUS_OK)
243         {
244             return res;
245         }
246     }
247
248     if (nonInterestedNetwork & CA_EDR)
249     {
250         res = CARemoveNetworkType(CA_EDR);
251         if (res != CA_STATUS_OK)
252         {
253             return res;
254         }
255     }
256
257     if (nonInterestedNetwork & CA_LE)
258     {
259         res = CARemoveNetworkType(CA_LE);
260         if (res != CA_STATUS_OK)
261         {
262             return res;
263         }
264     }
265
266     return CA_STATUS_OK;
267 }
268
269 CAResult_t CAHandleRequestResponse()
270 {
271     OIC_LOG_V(DEBUG, TAG, "CAHandleRequestResponse");
272
273     CAHandleRequestResponseCallbacks();
274
275     return CA_STATUS_OK;
276 }
277