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(DEBUG, TAG, "CAInitialize");
45 return CAInitializeMessageHandler();;
50 OIC_LOG(DEBUG, TAG, "CATerminate");
52 CATerminateMessageHandler();
54 CATerminateNetworkType();
57 CAResult_t CAStartListeningServer()
59 OIC_LOG(DEBUG, TAG, "CAStartListeningServer");
61 return CAStartListeningServerAdapters();
64 CAResult_t CAStartDiscoveryServer()
66 OIC_LOG(DEBUG, TAG, "CAStartDiscoveryServer");
68 return CAStartDiscoveryServerAdapters();
71 void CARegisterHandler(CARequestCallback ReqHandler, CAResponseCallback RespHandler)
73 OIC_LOG(DEBUG, TAG, "CARegisterHandler");
75 CASetRequestResponseCallbacks(ReqHandler, RespHandler);
79 CAResult_t CARegisterDTLSCredentialsHandler(
80 CAGetDTLSCredentialsHandler GetDTLSCredentialsHandler)
82 OIC_LOG(DEBUG, TAG, "CARegisterDTLSCredentialsHandler");
83 CADTLSSetCredentialsCallback(GetDTLSCredentialsHandler);
86 #endif //__WITH_DTLS__
88 CAResult_t CACreateRemoteEndpoint(const CAURI_t uri, const CATransportType_t transportType,
89 CARemoteEndpoint_t **remoteEndpoint)
91 OIC_LOG(DEBUG, TAG, "CACreateRemoteEndpoint");
93 CARemoteEndpoint_t *remote = CACreateRemoteEndpointUriInternal(uri, transportType);
97 OIC_LOG(DEBUG, TAG, "remote is NULL!");
98 return CA_STATUS_FAILED;
101 *remoteEndpoint = remote;
106 void CADestroyRemoteEndpoint(CARemoteEndpoint_t *rep)
108 OIC_LOG(DEBUG, TAG, "CADestroyRemoteEndpoint");
110 CADestroyRemoteEndpointInternal(rep);
113 CAResult_t CAGenerateToken(CAToken_t *token, uint8_t tokenLength)
115 OIC_LOG(DEBUG, TAG, "CAGenerateToken");
117 return CAGenerateTokenInternal(token, tokenLength);
120 void CADestroyToken(CAToken_t token)
122 OIC_LOG(DEBUG, TAG, "CADestroyToken");
124 CADestroyTokenInternal(token);
127 CAResult_t CAGetNetworkInformation(CALocalConnectivity_t **info, uint32_t *size)
129 OIC_LOG(DEBUG, TAG, "CAGetNetworkInformation");
131 return CAGetNetworkInformationInternal(info, size);
134 CAResult_t CAFindResource(const CAURI_t resourceUri, const CAToken_t token, uint8_t tokenLength)
136 OIC_LOG(DEBUG, TAG, "CAFindResource");
138 return CADetachMessageResourceUri(resourceUri, token, tokenLength, NULL, 0);
142 CAResult_t CASendRequest(const CARemoteEndpoint_t *object,const CARequestInfo_t *requestInfo)
144 OIC_LOG(DEBUG, TAG, "CASendGetRequest");
146 return CADetachRequestMessage(object, requestInfo);
149 CAResult_t CASendRequestToAll(const CAGroupEndpoint_t *object,
150 const CARequestInfo_t *requestInfo)
152 OIC_LOG(DEBUG, TAG, "CASendRequestToAll");
154 return CADetachRequestToAllMessage(object, requestInfo);
157 CAResult_t CASendNotification(const CARemoteEndpoint_t *object,
158 const CAResponseInfo_t *responseInfo)
160 OIC_LOG(DEBUG, TAG, "CASendNotification");
162 return CADetachResponseMessage(object, responseInfo);
166 CAResult_t CASendResponse(const CARemoteEndpoint_t *object,
167 const CAResponseInfo_t *responseInfo)
169 OIC_LOG(DEBUG, TAG, "CASendResponse");
171 return CADetachResponseMessage(object, responseInfo);
175 CAResult_t CAAdvertiseResource(const CAURI_t resourceUri,const CAToken_t token,
176 uint8_t tokenLength, const CAHeaderOption_t *options,
177 const uint8_t numOptions)
179 OIC_LOG(DEBUG, TAG, "CAAdvertiseResource");
181 return CADetachMessageResourceUri(resourceUri, token, tokenLength, options, numOptions);
185 CAResult_t CASelectNetwork(const uint32_t interestedNetwork)
187 OIC_LOG_V(DEBUG, TAG, "Selected network : %d", interestedNetwork);
189 if (!(interestedNetwork & 0xf))
191 return CA_NOT_SUPPORTED;
194 CAResult_t res = CA_STATUS_OK;
196 if (interestedNetwork & CA_IPV4)
198 res = CAAddNetworkType(CA_IPV4);
199 OIC_LOG_V(ERROR, TAG, "CAAddNetworkType(CA_IPV4) function returns error : %d", res);
202 if (interestedNetwork & CA_EDR)
204 res = CAAddNetworkType(CA_EDR);
205 OIC_LOG_V(ERROR, TAG, "CAAddNetworkType(CA_EDR) function returns error : %d", res);
208 if (interestedNetwork & CA_LE)
210 res = CAAddNetworkType(CA_LE);
211 OIC_LOG_V(ERROR, TAG, "CAAddNetworkType(CA_LE) function returns error : %d", res);
217 CAResult_t CAUnSelectNetwork(const uint32_t nonInterestedNetwork)
219 OIC_LOG_V(DEBUG, TAG, "unselected network : %d", nonInterestedNetwork);
221 if (!(nonInterestedNetwork & 0xf))
223 return CA_NOT_SUPPORTED;
226 CAResult_t res = CA_STATUS_OK;
228 if (nonInterestedNetwork & CA_IPV4)
230 res = CARemoveNetworkType(CA_IPV4);
231 OIC_LOG_V(ERROR, TAG, "CARemoveNetworkType(CA_IPV4) function returns error : %d", res);
234 if (nonInterestedNetwork & CA_EDR)
236 res = CARemoveNetworkType(CA_EDR);
237 OIC_LOG_V(ERROR, TAG, "CARemoveNetworkType(CA_EDR) function returns error : %d", res);
240 if (nonInterestedNetwork & CA_LE)
242 res = CARemoveNetworkType(CA_LE);
243 OIC_LOG_V(ERROR, TAG, "CARemoveNetworkType(CA_LE) function returns error : %d", res);
249 CAResult_t CAHandleRequestResponse()
251 OIC_LOG(DEBUG, TAG, "CAHandleRequestResponse");
253 CAHandleRequestResponseCallbacks();