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 CASetRequestResponseCallbacks(NULL, NULL);
47 CATerminateMessageHandler();
49 CATerminateNetworkType();
50 OIC_LOG(DEBUG, TAG, "OUT");
53 CAResult_t CAStartListeningServer()
55 return CAStartListeningServerAdapters();
58 CAResult_t CAStartDiscoveryServer()
60 return CAStartDiscoveryServerAdapters();
63 void CARegisterHandler(CARequestCallback ReqHandler, CAResponseCallback RespHandler)
65 OIC_LOG(DEBUG, TAG, "IN");
66 CASetRequestResponseCallbacks(ReqHandler, RespHandler);
67 OIC_LOG(DEBUG, TAG, "OUT");
70 CAResult_t CACreateRemoteEndpoint(const CAURI_t uri, const CATransportType_t transportType,
71 CARemoteEndpoint_t **remoteEndpoint)
73 OIC_LOG(DEBUG, TAG, "IN");
75 CARemoteEndpoint_t *remote = CACreateRemoteEndpointUriInternal(uri, transportType);
79 OIC_LOG(ERROR, TAG, "remote endpoint is NULL");
80 return CA_STATUS_FAILED;
83 *remoteEndpoint = remote;
85 OIC_LOG(DEBUG, TAG, "OUT");
89 void CADestroyRemoteEndpoint(CARemoteEndpoint_t *rep)
91 CADestroyRemoteEndpointInternal(rep);
94 CAResult_t CAGenerateToken(CAToken_t *token, uint8_t tokenLength)
96 return CAGenerateTokenInternal(token, tokenLength);
99 void CADestroyToken(CAToken_t token)
101 OIC_LOG(DEBUG, TAG, "IN");
102 CADestroyTokenInternal(token);
103 OIC_LOG(DEBUG, TAG, "OUT");
106 CAResult_t CAGetNetworkInformation(CALocalConnectivity_t **info, uint32_t *size)
108 return CAGetNetworkInformationInternal(info, size);
111 CAResult_t CAFindResource(const CAURI_t resourceUri, const CAToken_t token, uint8_t tokenLength)
113 OIC_LOG(DEBUG, TAG, "IN");
115 return CADetachMessageResourceUri(resourceUri, token, tokenLength, NULL, 0);
118 CAResult_t CASendRequest(const CARemoteEndpoint_t *object,const CARequestInfo_t *requestInfo)
120 return CADetachRequestMessage(object, requestInfo);
123 CAResult_t CASendRequestToAll(const CAGroupEndpoint_t *object,
124 const CARequestInfo_t *requestInfo)
126 OIC_LOG(DEBUG, TAG, "CASendRequestToAll");
128 return CADetachRequestToAllMessage(object, requestInfo);
131 CAResult_t CASendNotification(const CARemoteEndpoint_t *object,
132 const CAResponseInfo_t *responseInfo)
134 return CADetachResponseMessage(object, responseInfo);
137 CAResult_t CASendResponse(const CARemoteEndpoint_t *object,
138 const CAResponseInfo_t *responseInfo)
140 return CADetachResponseMessage(object, responseInfo);
143 CAResult_t CAAdvertiseResource(const CAURI_t resourceUri,const CAToken_t token,
144 uint8_t tokenLength, const CAHeaderOption_t *options,
145 const uint8_t numOptions)
147 return CADetachMessageResourceUri(resourceUri, token, tokenLength, options, numOptions);
150 CAResult_t CASelectNetwork(const uint32_t interestedNetwork)
152 OIC_LOG_V(DEBUG, TAG, "Selected n/W=%d", interestedNetwork);
154 if (!(interestedNetwork & 0xf))
156 OIC_LOG(ERROR, TAG, "not supported");
157 return CA_NOT_SUPPORTED;
159 CAResult_t res = CA_STATUS_OK;
161 if (interestedNetwork & CA_IPV4)
163 res = CAAddNetworkType(CA_IPV4);
164 if (res != CA_STATUS_OK)
166 OIC_LOG(ERROR, TAG, "Failed to Add n/w type");
171 if (interestedNetwork & CA_EDR)
173 res = CAAddNetworkType(CA_EDR);
174 if (res != CA_STATUS_OK)
176 OIC_LOG(ERROR, TAG, "Failed to Add n/w type");
181 if (interestedNetwork & CA_LE)
183 res = CAAddNetworkType(CA_LE);
184 if (res != CA_STATUS_OK)
186 OIC_LOG(ERROR, TAG, "Failed to Add n/w type");
190 OIC_LOG(DEBUG, TAG, "OUT");
194 CAResult_t CAUnSelectNetwork(const uint32_t nonInterestedNetwork)
196 OIC_LOG_V(DEBUG, TAG, "unselected n/w=%d", nonInterestedNetwork);
198 if (!(nonInterestedNetwork & 0xf))
200 OIC_LOG(ERROR, TAG, "not supported");
201 return CA_NOT_SUPPORTED;
204 CAResult_t res = CA_STATUS_OK;
206 if (nonInterestedNetwork & CA_IPV4)
208 res = CARemoveNetworkType(CA_IPV4);
209 if (res != CA_STATUS_OK)
211 OIC_LOG(ERROR, TAG, "Failed to remove n/w type");
216 if (nonInterestedNetwork & CA_EDR)
218 res = CARemoveNetworkType(CA_EDR);
219 if (res != CA_STATUS_OK)
221 OIC_LOG(ERROR, TAG, "Failed to remove n/w type");
226 if (nonInterestedNetwork & CA_LE)
228 res = CARemoveNetworkType(CA_LE);
229 if (res != CA_STATUS_OK)
231 OIC_LOG(ERROR, TAG, "Failed to remove n/w type");
235 OIC_LOG(DEBUG, TAG, "OUT");
239 CAResult_t CAHandleRequestResponse()
241 CAHandleRequestResponseCallbacks();