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 ******************************************************************/
23 * This file contains the APIs for BT LE communications.
25 #ifndef CA_LE_UTILS_H_
26 #define CA_LE_UTILS_H_
29 #include "cathreadpool.h"
30 #include "cagattservice.h"
31 #include "uarraylist.h"
39 #define CA_LE_AUTO_CONNECT_FLAG 1
40 #define CA_LE_CONNECTION_STATE 2
41 #define CA_LE_SEND_STATE 3
42 #define CA_LE_DESCRIPTOR_FOUND 4
45 static const char OIC_GATT_SERVICE_UUID[] = CA_GATT_SERVICE_UUID;
46 static const char OIC_GATT_CHARACTERISTIC_REQUEST_UUID[] = CA_GATT_REQUEST_CHRC_UUID;
47 static const char OIC_GATT_CHARACTERISTIC_RESPONSE_UUID[] = CA_GATT_RESPONSE_CHRC_UUID;
48 static const char OIC_GATT_CHARACTERISTIC_CONFIG_UUID[] = "00002902-0000-1000-8000-00805f9b34fb";
50 static const char CLASSPATH_BT_PROFILE[] = "android/bluetooth/BluetoothProfile";
51 static const char CLASSPATH_BT_GATT[] = "android/bluetooth/BluetoothGatt";
52 static const char CLASSPATH_BT_ADAPTER[] = "android/bluetooth/BluetoothAdapter";
53 static const char CLASSPATH_BT_DEVICE[] = "android/bluetooth/BluetoothDevice";
54 static const char CLASSPATH_BT_UUID[] = "java/util/UUID";
57 static const char METHODID_OBJECTNONPARAM[] = "()Landroid/bluetooth/BluetoothAdapter;";
58 static const char METHODID_BT_DEVICE[] = "()Landroid/bluetooth/BluetoothDevice;";
59 static const char METHODID_BT_REMOTE_DEVICE[] = "(Ljava/lang/String;)Landroid/bluetooth/BluetoothDevice;";
61 static const jint GATT_PROFILE = 7;
62 static const jint GATT_SUCCESS = 0;
64 static const jint BOND_BONDED = 12;
65 static const jint BOND_BONDING = 11;
66 static const jint BOND_NONE = 10;
68 static const uint16_t STATE_CONNECTED = 3;
69 static const uint16_t STATE_SERVICE_CONNECTED = 2;
70 static const uint16_t STATE_DISCONNECTED = 1;
72 static const uint16_t GATT_ERROR = 133;
74 static const uint16_t STATE_SEND_NONE = 1;
75 static const uint16_t STATE_SEND_SUCCESS = 2;
76 static const uint16_t STATE_SEND_FAIL = 3;
77 static const uint16_t STATE_SENDING = 4;
78 static const uint16_t STATE_SEND_PREPARING = 5;
79 static const uint16_t STATE_SEND_MTU_NEGO_SUCCESS = 6;
82 * get uuid(jni object) from uuid(character).
83 * @param[in] env JNI interface pointer.
84 * @param[in] uuid uuid(character).
85 * @return uuid(jni object).
87 jobject CALEGetUuidFromString(JNIEnv *env, const char* uuid);
90 * get parcel uuid object.
91 * @param[in] env JNI interface pointer.
92 * @param[in] uuid uuid (jni object).
93 * @return parcel uuid object.
95 jobject CALEGetParcelUuid(JNIEnv *env, jobject uuid);
98 * get address from a local device.
99 * @param[in] env JNI interface pointer.
100 * @return local address.
102 jstring CALEGetLocalDeviceAddress(JNIEnv *env);
106 * @param[in] env JNI interface pointer.
107 * @return bonded list.
109 jobjectArray CALEGetBondedDevices(JNIEnv *env);
112 * get constants information of bluetooth state-on.
113 * @param[in] env JNI interface pointer.
114 * @return constants information of bluetooth state-on.
116 jint CALEGetBTStateOnInfo(JNIEnv *env);
119 * check this device can be supported as BLE client or server.
120 * @param[in] env JNI interface pointer.
121 * @param[in] level Android API Level to support.
122 * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
124 CAResult_t CALECheckPlatformVersion(JNIEnv *env, uint16_t level);
127 * get constants information of android.os.Build.VERSION.SDK_INT.
128 * @param[in] env JNI interface pointer.
129 * @return constants information of android.os.Build.VERSION.SDK_INT.
131 jint CALEGetBuildVersion(JNIEnv *env);
134 * get constants information of android.os.Build.VERSION_CODES.[VersionName].
135 * @param[in] env JNI interface pointer.
136 * @param[in] versionName version name (.., KITKAT, LOLLIPOP, ..).
137 * @return constants information of android.os.Build.VERSION_CODES.[VersionName].
139 jint CALEGetBuildVersionCodeForName(JNIEnv *env, const char* versionName);
142 * get bluetooth adapter state information.
143 * @param[in] env JNI interface pointer.
144 * @return JNI_TRUE if the local adapter is turned on.
146 jboolean CALEIsEnableBTAdapter(JNIEnv *env);
149 * get address from remote device.
150 * @param[in] env JNI interface pointer.
151 * @param[in] bluetoothDevice bluetooth device object.
152 * @return remote address.
154 jstring CALEGetAddressFromBTDevice(JNIEnv *env, jobject bluetoothDevice);
157 * get value from selected constants.
158 * @param[in] env JNI interface pointer.
159 * @param[in] classType class type
160 * @param[in] name constants name to get.
161 * @return remote address.
163 jint CALEGetConstantsValue(JNIEnv *env, const char* classType, const char* name);
166 * get bluetooth device object from bluetooth adapter.
167 * @param[in] env JNI interface pointer.
168 * @param[in] address bluetooth address.
169 * @return bluetooth device object.
171 jobject CALEGetRemoteDevice(JNIEnv *env, jstring address);
174 * get address from gatt profile object.
175 * @param[in] env JNI interface pointer.
176 * @param[in] gatt gatt profile object.
177 * @return LE address.
179 jstring CALEGetAddressFromGatt(JNIEnv *env, jobject gatt);
185 #endif /* CA_LE_UTILS_H_ */