1 /******************************************************************
3 * Copyright 2014 Samsung Electronics All Rights Reserved.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 ******************************************************************/
25 #include "cainterface.h"
26 #include "caremotehandler.h"
27 #include "camessagehandler.h"
28 #include "caprotocolmessage.h"
29 #include "canetworkconfigurator.h"
30 #include "cainterfacecontroller.h"
36 // CAAdapterNetDTLS will register the callback.
37 // Taking callback all the way through adapters not the right approach, hence calling here.
38 extern void CADTLSSetCredentialsCallback(CAGetDTLSCredentialsHandler credCallback);
41 CAResult_t CAInitialize()
43 OIC_LOG_V(DEBUG, TAG, "CAInitialize");
45 CAResult_t res = CAInitializeMessageHandler();
47 if (res != CA_STATUS_OK)
57 OIC_LOG_V(DEBUG, TAG, "CATerminate");
59 CATerminateMessageHandler();
61 CATerminateNetworkType();
64 CAResult_t CAStartListeningServer()
66 OIC_LOG_V(DEBUG, TAG, "CAStartListeningServer");
68 return CAStartListeningServerAdapters();
71 CAResult_t CAStartDiscoveryServer()
73 OIC_LOG_V(DEBUG, TAG, "CAStartDiscoveryServer");
75 return CAStartDiscoveryServerAdapters();
78 void CARegisterHandler(CARequestCallback ReqHandler, CAResponseCallback RespHandler)
80 OIC_LOG_V(DEBUG, TAG, "CARegisterHandler");
82 CASetRequestResponseCallbacks(ReqHandler, RespHandler);
86 CAResult_t CARegisterDTLSCredentialsHandler(
87 CAGetDTLSCredentialsHandler GetDTLSCredentialsHandler)
89 OIC_LOG(DEBUG, TAG, "CARegisterDTLSCredentialsHandler");
90 CADTLSSetCredentialsCallback(GetDTLSCredentialsHandler);
93 #endif //__WITH_DTLS__
95 CAResult_t CACreateRemoteEndpoint(const CAURI_t uri,
96 const CAConnectivityType_t connectivityType,CARemoteEndpoint_t **remoteEndpoint)
98 OIC_LOG_V(DEBUG, TAG, "CACreateRemoteEndpoint");
100 CARemoteEndpoint_t *remote = CACreateRemoteEndpointUriInternal(uri, connectivityType);
102 *remoteEndpoint = remote;
105 return CA_STATUS_FAILED;
110 void CADestroyRemoteEndpoint(CARemoteEndpoint_t *rep)
112 OIC_LOG_V(DEBUG, TAG, "CADestroyRemoteEndpoint");
114 CADestroyRemoteEndpointInternal(rep);
117 CAResult_t CAGenerateToken(CAToken_t *token)
119 OIC_LOG_V(DEBUG, TAG, "CAGenerateToken");
121 return CAGenerateTokenInternal(token);
124 void CADestroyToken(CAToken_t token)
126 OIC_LOG_V(DEBUG, TAG, "CADestroyToken");
128 CADestroyTokenInternal(token);
131 CAResult_t CAGetNetworkInformation(CALocalConnectivity_t **info, uint32_t *size)
133 OIC_LOG_V(DEBUG, TAG, "CAGetNetworkInformation");
135 return CAGetNetworkInformationInternal(info, size);
138 CAResult_t CAFindResource(const CAURI_t resourceUri, const CAToken_t token)
140 OIC_LOG_V(DEBUG, TAG, "CAFindResource");
142 return CADetachMessageResourceUri(resourceUri, token, NULL, 0);
146 CAResult_t CASendRequest(const CARemoteEndpoint_t *object, CARequestInfo_t *requestInfo)
148 OIC_LOG_V(DEBUG, TAG, "CASendGetRequest");
150 return CADetachRequestMessage(object, requestInfo);
153 CAResult_t CASendRequestToAll(const CAGroupEndpoint_t *object,
154 const CARequestInfo_t *requestInfo)
156 OIC_LOG_V(DEBUG, TAG, "CASendRequestToAll");
158 return CADetachRequestToAllMessage(object, requestInfo);
161 CAResult_t CASendNotification(const CARemoteEndpoint_t *object, CAResponseInfo_t *responseInfo)
163 OIC_LOG_V(DEBUG, TAG, "CASendNotification");
165 return CADetachResponseMessage(object, responseInfo);
169 CAResult_t CASendResponse(const CARemoteEndpoint_t *object, CAResponseInfo_t *responseInfo)
171 OIC_LOG_V(DEBUG, TAG, "CASendResponse");
173 return CADetachResponseMessage(object, responseInfo);
177 CAResult_t CAAdvertiseResource(const CAURI_t resourceUri, CAToken_t token,
178 CAHeaderOption_t *options, uint8_t numOptions)
180 OIC_LOG_V(DEBUG, TAG, "CAAdvertiseResource");
182 return CADetachMessageResourceUri(resourceUri, token, options, numOptions);
186 CAResult_t CASelectNetwork(const uint32_t interestedNetwork)
188 OIC_LOG_V(DEBUG, TAG, "Selected network : %d", interestedNetwork);
190 if (!(interestedNetwork & 0xf))
192 return CA_NOT_SUPPORTED;
196 if (interestedNetwork & CA_ETHERNET)
198 res = CAAddNetworkType(CA_ETHERNET);
199 if (res != CA_STATUS_OK)
205 if (interestedNetwork & CA_WIFI)
207 res = CAAddNetworkType(CA_WIFI);
208 if (res != CA_STATUS_OK)
214 if (interestedNetwork & CA_EDR)
216 res = CAAddNetworkType(CA_EDR);
217 if (res != CA_STATUS_OK)
223 if (interestedNetwork & CA_LE)
225 res = CAAddNetworkType(CA_LE);
226 if (res != CA_STATUS_OK)
235 CAResult_t CAUnSelectNetwork(const uint32_t nonInterestedNetwork)
237 OIC_LOG_V(DEBUG, TAG, "unselected network : %d", nonInterestedNetwork);
239 if (!(nonInterestedNetwork & 0xf))
241 return CA_NOT_SUPPORTED;
246 if (nonInterestedNetwork & CA_ETHERNET)
248 res = CARemoveNetworkType(CA_ETHERNET);
249 if (res != CA_STATUS_OK)
255 if (nonInterestedNetwork & CA_WIFI)
257 res = CARemoveNetworkType(CA_WIFI);
258 if (res != CA_STATUS_OK)
264 if (nonInterestedNetwork & CA_EDR)
266 res = CARemoveNetworkType(CA_EDR);
267 if (res != CA_STATUS_OK)
273 if (nonInterestedNetwork & CA_LE)
275 res = CARemoveNetworkType(CA_LE);
276 if (res != CA_STATUS_OK)
285 CAResult_t CAHandleRequestResponse()
287 OIC_LOG_V(DEBUG, TAG, "CAHandleRequestResponse");
289 CAHandleRequestResponseCallbacks();