1 /* ****************************************************************
3 * Copyright 2016 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 ******************************************************************/
21 #include "camanagerleinterface.h"
22 #include "cabtpairinginterface.h"
23 #include "cautilinterface.h"
24 #include "cainterfacecontroller.h"
28 #define TAG "OIC_CA_COMMON_UTILS"
30 CAResult_t CARegisterNetworkMonitorHandler(CAAdapterStateChangedCB adapterStateCB,
31 CAConnectionStateChangedCB connStateCB)
33 OIC_LOG(DEBUG, TAG, "CARegisterNetworkMonitorHandler");
35 CASetNetworkMonitorCallbacks(adapterStateCB, connStateCB);
39 CAResult_t CASetAutoConnectionDeviceInfo(const char *address)
41 OIC_LOG(DEBUG, TAG, "CASetAutoConnectionDeviceInfo");
43 #if defined(__ANDROID__) && defined(LE_ADAPTER)
44 return CASetLEClientAutoConnectionDeviceInfo(address);
47 return CA_NOT_SUPPORTED;
51 CAResult_t CAUnsetAutoConnectionDeviceInfo(const char *address)
53 OIC_LOG(DEBUG, TAG, "CAUnsetAutoConnectionDeviceInfo");
55 #if defined(__ANDROID__) && defined(LE_ADAPTER)
56 return CAUnsetLEClientAutoConnectionDeviceInfo(address);
59 return CA_NOT_SUPPORTED;
63 CAResult_t CASetPortNumberToAssign(CATransportAdapter_t adapter,
64 CATransportFlags_t flag, uint16_t port)
66 uint16_t *targetPort = 0;
68 if (CA_ADAPTER_IP & adapter)
74 targetPort = &caglobals.ports.udp.u6s;
76 else if (CA_IPV4 & flag)
78 targetPort = &caglobals.ports.udp.u4s;
85 targetPort = &caglobals.ports.udp.u6;
87 else if (CA_IPV4 & flag)
89 targetPort = &caglobals.ports.udp.u4;
94 if (CA_ADAPTER_TCP & adapter)
98 targetPort = &caglobals.ports.tcp.u6;
100 else if (CA_IPV4 & flag)
102 targetPort = &caglobals.ports.tcp.u4;
113 return CA_NOT_SUPPORTED;
116 uint16_t CAGetAssignedPortNumber(CATransportAdapter_t adapter, CATransportFlags_t flag)
118 OIC_LOG(DEBUG, TAG, "CAGetAssignedPortNumber");
120 if (CA_ADAPTER_IP & adapter)
122 if (CA_SECURE & flag)
126 return caglobals.ip.u6s.port;
128 else if (CA_IPV4 & flag)
130 return caglobals.ip.u4s.port;
137 return caglobals.ip.u6.port;
139 else if (CA_IPV4 & flag)
141 return caglobals.ip.u4.port;
146 if (CA_ADAPTER_TCP & adapter)
150 return caglobals.tcp.ipv6.port;
152 else if (CA_IPV4 & flag)
154 return caglobals.tcp.ipv4.port;
163 * initialize client connection manager
164 * @param[in] env JNI interface pointer.
165 * @param[in] jvm invocation inferface for JAVA virtual machine.
166 * @param[in] context application context.
168 CAResult_t CAUtilClientInitialize(JNIEnv *env, JavaVM *jvm, jobject context)
170 OIC_LOG(DEBUG, TAG, "CAUtilClientInitialize");
172 CAResult_t res = CA_STATUS_OK;
174 if (CA_STATUS_OK != CAManagerLEClientInitialize(env, jvm, context))
176 OIC_LOG(ERROR, TAG, "CAManagerLEClientInitialize has failed");
177 res = CA_STATUS_FAILED;
182 if (CA_STATUS_OK != CABTPairingInitialize(env, jvm, context))
184 OIC_LOG(ERROR, TAG, "CABTPairingInitialize has failed");
185 res = CA_STATUS_FAILED;
189 #if !defined(LE_ADAPTER) && !defined(EDR_ADAPTER)
198 * terminate client connection manager
199 * @param[in] env JNI interface pointer.
201 CAResult_t CAUtilClientTerminate(JNIEnv *env)
203 OIC_LOG(DEBUG, TAG, "CAUtilClientTerminate");
205 return CAManagerLEClientTerminate(env);
207 OIC_LOG(DEBUG, TAG, "it is not supported");
209 return CA_NOT_SUPPORTED;
214 CAResult_t CAUtilStartScan(JNIEnv *env)
217 return CABTPairingStartScan(env);
219 OIC_LOG(DEBUG, TAG, "it is not supported");
221 return CA_NOT_SUPPORTED;
225 CAResult_t CAUtilStopScan(JNIEnv *env)
228 return CABTPairingStopScan(env);
230 OIC_LOG(DEBUG, TAG, "it is not supported");
232 return CA_NOT_SUPPORTED;
236 CAResult_t CAUtilCreateBond(JNIEnv *env, jobject device)
239 return CABTPairingCreateBond(env, device);
241 OIC_LOG(DEBUG, TAG, "it is not supported");
244 return CA_NOT_SUPPORTED;
248 void CAUtilSetFoundDeviceListener(jobject listener)
251 CABTPairingSetFoundDeviceListener(listener);
257 CAResult_t CAUtilSetLEScanInterval(jint intervalTime, jint workingCount)
259 OIC_LOG(DEBUG, TAG, "CAUtilSetLEScanInterval");
261 CAManagerLESetScanInterval(intervalTime, workingCount);
266 OIC_LOG(DEBUG, TAG, "it is not supported");
267 return CA_NOT_SUPPORTED;