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 "caprotocolmessage.h"
28 #include "canetworkconfigurator.h"
31 #include "cainterfacecontroller_singlethread.h"
32 #include "camessagehandler_singlethread.h"
36 CAResult_t CAInitialize()
38 OIC_LOG(DEBUG, TAG, "IN");
40 return CAInitializeMessageHandler();
45 OIC_LOG(DEBUG, TAG, "IN");
46 CATerminateMessageHandler();
48 CATerminateNetworkType();
49 OIC_LOG(DEBUG, TAG, "OUT");
52 CAResult_t CAStartListeningServer()
54 return CAStartListeningServerAdapters();
57 CAResult_t CAStartDiscoveryServer()
59 return CAStartDiscoveryServerAdapters();
62 void CARegisterHandler(CARequestCallback ReqHandler, CAResponseCallback RespHandler)
64 OIC_LOG(DEBUG, TAG, "IN");
65 CASetRequestResponseCallbacks(ReqHandler, RespHandler);
66 OIC_LOG(DEBUG, TAG, "OUT");
69 CAResult_t CACreateRemoteEndpoint(const CAURI_t uri,
70 const CAConnectivityType_t connectivityType,CARemoteEndpoint_t **remoteEndpoint)
72 OIC_LOG(DEBUG, TAG, "IN");
74 CARemoteEndpoint_t *remote = CACreateRemoteEndpointUriInternal(uri,connectivityType);
78 OIC_LOG(ERROR, TAG, "remote endpoint is NULL");
79 return CA_STATUS_FAILED;
82 *remoteEndpoint = remote;
84 OIC_LOG(DEBUG, TAG, "OUT");
88 void CADestroyRemoteEndpoint(CARemoteEndpoint_t *rep)
90 CADestroyRemoteEndpointInternal(rep);
93 CAResult_t CAGenerateToken(CAToken_t *token, uint8_t tokenLength)
95 return CAGenerateTokenInternal(token, tokenLength);
98 void CADestroyToken(CAToken_t token)
100 OIC_LOG(DEBUG, TAG, "IN");
101 CADestroyTokenInternal(token);
102 OIC_LOG(DEBUG, TAG, "OUT");
105 CAResult_t CAGetNetworkInformation(CALocalConnectivity_t **info, uint32_t *size)
107 return CAGetNetworkInformationInternal(info, size);
110 CAResult_t CAFindResource(const CAURI_t resourceUri, const CAToken_t token, uint8_t tokenLength)
112 OIC_LOG(DEBUG, TAG, "IN");
114 return CADetachMessageResourceUri(resourceUri, token, tokenLength, NULL, 0);
117 CAResult_t CASendRequest(const CARemoteEndpoint_t *object,const CARequestInfo_t *requestInfo)
119 return CADetachRequestMessage(object, requestInfo);
122 CAResult_t CASendRequestToAll(const CAGroupEndpoint_t *object,
123 const CARequestInfo_t *requestInfo)
125 OIC_LOG(DEBUG, TAG, "CASendRequestToAll");
127 return CADetachRequestToAllMessage(object, requestInfo);
130 CAResult_t CASendNotification(const CARemoteEndpoint_t *object,
131 const CAResponseInfo_t *responseInfo)
133 return CADetachResponseMessage(object, responseInfo);
136 CAResult_t CASendResponse(const CARemoteEndpoint_t *object,
137 const CAResponseInfo_t *responseInfo)
139 return CADetachResponseMessage(object, responseInfo);
142 CAResult_t CAAdvertiseResource(const CAURI_t resourceUri,const CAToken_t token,
143 uint8_t tokenLength, const CAHeaderOption_t *options,
144 const uint8_t numOptions)
146 return CADetachMessageResourceUri(resourceUri, token, tokenLength, options, numOptions);
149 CAResult_t CASelectNetwork(const uint32_t interestedNetwork)
151 OIC_LOG_V(DEBUG, TAG, "Selected n/W=%d", interestedNetwork);
153 if (!(interestedNetwork & 0xf))
155 OIC_LOG(ERROR, TAG, "not supported");
156 return CA_NOT_SUPPORTED;
158 CAResult_t res = CA_STATUS_OK;
160 if (interestedNetwork & CA_ETHERNET)
162 res = CAAddNetworkType(CA_ETHERNET);
163 if (res != CA_STATUS_OK)
165 OIC_LOG(ERROR, TAG, "Failed to Add n/w type");
170 if (interestedNetwork & CA_WIFI)
172 res = CAAddNetworkType(CA_WIFI);
173 if (res != CA_STATUS_OK)
175 OIC_LOG(ERROR, TAG, "Failed to Add n/w type");
180 if (interestedNetwork & CA_EDR)
182 res = CAAddNetworkType(CA_EDR);
183 if (res != CA_STATUS_OK)
185 OIC_LOG(ERROR, TAG, "Failed to Add n/w type");
190 if (interestedNetwork & CA_LE)
192 res = CAAddNetworkType(CA_LE);
193 if (res != CA_STATUS_OK)
195 OIC_LOG(ERROR, TAG, "Failed to Add n/w type");
199 OIC_LOG(DEBUG, TAG, "OUT");
203 CAResult_t CAUnSelectNetwork(const uint32_t nonInterestedNetwork)
205 OIC_LOG_V(DEBUG, TAG, "unselected n/w=%d", nonInterestedNetwork);
207 if (!(nonInterestedNetwork & 0xf))
209 OIC_LOG(ERROR, TAG, "not supported");
210 return CA_NOT_SUPPORTED;
213 CAResult_t res = CA_STATUS_OK;
215 if (nonInterestedNetwork & CA_ETHERNET)
217 res = CARemoveNetworkType(CA_ETHERNET);
218 if (res != CA_STATUS_OK)
220 OIC_LOG(ERROR, TAG, "Failed to remove n/w type");
225 if (nonInterestedNetwork & CA_WIFI)
227 res = CARemoveNetworkType(CA_WIFI);
228 if (res != CA_STATUS_OK)
230 OIC_LOG(ERROR, TAG, "Failed to remove n/w type");
235 if (nonInterestedNetwork & CA_EDR)
237 res = CARemoveNetworkType(CA_EDR);
238 if (res != CA_STATUS_OK)
240 OIC_LOG(ERROR, TAG, "Failed to remove n/w type");
245 if (nonInterestedNetwork & CA_LE)
247 res = CARemoveNetworkType(CA_LE);
248 if (res != CA_STATUS_OK)
250 OIC_LOG(ERROR, TAG, "Failed to remove n/w type");
254 OIC_LOG(DEBUG, TAG, "OUT");
258 CAResult_t CAHandleRequestResponse()
260 CAHandleRequestResponseCallbacks();