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