Implementation of Filtered Scan for BLE android client
[platform/upstream/iotivity.git] / resource / csdk / connectivity / src / bt_le_adapter / android / caleutils.h
1 /* ****************************************************************
2  *
3  * Copyright 2014 Samsung Electronics All Rights Reserved.
4  *
5  *
6  *
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  ******************************************************************/
20
21 /**
22  * @file
23  * This file contains the APIs for BT LE communications.
24  */
25 #ifndef CA_LE_UTILS_H_
26 #define CA_LE_UTILS_H_
27
28 #include "cacommon.h"
29 #include "cathreadpool.h"
30 #include "cagattservice.h"
31 #include "uarraylist.h"
32 #include "jni.h"
33
34 #ifdef __cplusplus
35 extern "C"
36 {
37 #endif
38
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
43
44 /* Service UUID */
45 static const char OIC_GATT_SERVICE_UUID[] = CA_GATT_SERVICE_UUID;
46 static const char OIC_GATT_CUSTOM_UUID[] = CA_GATT_CUSTOM_UUID;
47 static const char OIC_GATT_CUSTOM_UUID2[] = CA_GATT_CUSTOM_UUID2;
48 static const char OIC_GATT_CUSTOM_UUID3[] = CA_GATT_CUSTOM_UUID3;
49 static const char OIC_GATT_CHARACTERISTIC_REQUEST_UUID[] = CA_GATT_REQUEST_CHRC_UUID;
50 static const char OIC_GATT_CHARACTERISTIC_RESPONSE_UUID[] = CA_GATT_RESPONSE_CHRC_UUID;
51 static const char OIC_GATT_CHARACTERISTIC_CONFIG_UUID[] = "00002902-0000-1000-8000-00805f9b34fb";
52
53 static const char CLASSPATH_BT_PROFILE[] = "android/bluetooth/BluetoothProfile";
54 static const char CLASSPATH_BT_GATT[] = "android/bluetooth/BluetoothGatt";
55 static const char CLASSPATH_BT_ADAPTER[] = "android/bluetooth/BluetoothAdapter";
56 static const char CLASSPATH_BT_DEVICE[] = "android/bluetooth/BluetoothDevice";
57 static const char CLASSPATH_BT_UUID[] = "java/util/UUID";
58 static const char CLASSPATH_LE_SCANNER[] = "android/bluetooth/le/BluetoothLeScanner";
59 static const char CLASSPATH_LE_SCANSETTINGS[] = "android/bluetooth/le/ScanSettings";
60
61 static const char METHODID_OBJECTNONPARAM[] = "()Landroid/bluetooth/BluetoothAdapter;";
62 static const char METHODID_BT_DEVICE[] = "()Landroid/bluetooth/BluetoothDevice;";
63 static const char METHODID_BT_REMOTE_DEVICE[] = "(Ljava/lang/String;)Landroid/bluetooth/BluetoothDevice;";
64
65 static const jint GATT_PROFILE = 7;
66 static const jint GATT_SUCCESS = 0;
67
68 static const jint BOND_BONDED = 12;
69 static const jint BOND_BONDING = 11;
70 static const jint BOND_NONE = 10;
71
72 static const uint16_t STATE_CONNECTED = 3;
73 static const uint16_t STATE_SERVICE_CONNECTED = 2;
74 static const uint16_t STATE_DISCONNECTED = 1;
75
76 static const uint16_t GATT_ERROR = 133;
77
78 static const uint16_t STATE_SEND_NONE = 1;
79 static const uint16_t STATE_SEND_SUCCESS = 2;
80 static const uint16_t STATE_SEND_FAIL = 3;
81 static const uint16_t STATE_SENDING = 4;
82 static const uint16_t STATE_SEND_PREPARING = 5;
83 static const uint16_t STATE_SEND_MTU_NEGO_SUCCESS = 6;
84
85 /**
86  * get uuid(jni object) from uuid(character).
87  * @param[in]   env              JNI interface pointer.
88  * @param[in]   uuid             uuid(character).
89  * @return  uuid(jni object).
90  */
91 jobject CALEGetUuidFromString(JNIEnv *env, const char* uuid);
92
93 /**
94  * get parcel uuid object.
95  * @param[in]   env              JNI interface pointer.
96  * @param[in]   uuid             uuid (jni object).
97  * @return  parcel uuid object.
98  */
99 jobject CALEGetParcelUuid(JNIEnv *env, jobject uuid);
100
101 /**
102  * get parcel uuid object from uuid string value.
103  * @param[in]   env              JNI interface pointer.
104  * @param[in]   uuid             uuid (const char*).
105  * @return  parcel uuid object.
106  */
107 jobject CALEGetParcelUuidFromString(JNIEnv *env, const char* uuid);
108
109 /**
110  * get manufactererData jbyteArray from uuid string value.
111  * @param[in]   env              JNI interface pointer.
112  * @param[in]   uuid             uuid (const char*).
113  * @return  manufactererData jbyteArray.
114  */
115 jbyteArray CALEGetManufacturerData(JNIEnv *env, const char* uuid);
116
117 /**
118  * get address from a local device.
119  * @param[in]   env              JNI interface pointer.
120  * @return  local address.
121  */
122 jstring CALEGetLocalDeviceAddress(JNIEnv *env);
123
124 /**
125  * get bonded list.
126  * @param[in]   env              JNI interface pointer.
127  * @return  bonded list.
128  */
129 jobjectArray CALEGetBondedDevices(JNIEnv *env);
130
131 /**
132  * get constants information of bluetooth state-on.
133  * @param[in]   env              JNI interface pointer.
134  * @return  constants information of bluetooth state-on.
135  */
136 jint CALEGetBTStateOnInfo(JNIEnv *env);
137
138 /**
139  * check this device can be supported as BLE client or server.
140  * @param[in]   env              JNI interface pointer.
141  * @param[in]   level            Android API Level to support.
142  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
143  */
144 CAResult_t CALECheckPlatformVersion(JNIEnv *env, uint16_t level);
145
146 /**
147  * get constants information of android.os.Build.VERSION.SDK_INT.
148  * @param[in]   env              JNI interface pointer.
149  * @return  constants information of android.os.Build.VERSION.SDK_INT.
150  */
151 jint CALEGetBuildVersion(JNIEnv *env);
152
153 /**
154  * get constants information of android.os.Build.VERSION_CODES.[VersionName].
155  * @param[in]   env              JNI interface pointer.
156  * @param[in]   versionName      version name (.., KITKAT, LOLLIPOP, ..).
157  * @return  constants information of android.os.Build.VERSION_CODES.[VersionName].
158  */
159 jint CALEGetBuildVersionCodeForName(JNIEnv *env, const char* versionName);
160
161 /**
162  * get bluetooth adapter state information.
163  * @param[in]   env              JNI interface pointer.
164  * @return  JNI_TRUE if the local adapter is turned on.
165  */
166 jboolean CALEIsEnableBTAdapter(JNIEnv *env);
167
168 /**
169  * get address from remote device.
170  * @param[in]   env              JNI interface pointer.
171  * @param[in]   bluetoothDevice  bluetooth device object.
172  * @return  remote address.
173  */
174 jstring CALEGetAddressFromBTDevice(JNIEnv *env, jobject bluetoothDevice);
175
176 /**
177  * get value from selected constants.
178  * @param[in]   env              JNI interface pointer.
179  * @param[in]   classType        class type
180  * @param[in]   name             constants name to get.
181  * @return  remote address.
182  */
183 jint CALEGetConstantsValue(JNIEnv *env, const char* classType, const char* name);
184
185 /**
186  * get bluetooth device object from bluetooth adapter.
187  * @param[in]   env                   JNI interface pointer.
188  * @param[in]   address               bluetooth address.
189  * @return  bluetooth device object.
190  */
191 jobject CALEGetRemoteDevice(JNIEnv *env, jstring address);
192
193 /**
194  * get address from gatt profile object.
195  * @param[in]   env                   JNI interface pointer.
196  * @param[in]   gatt                  gatt profile object.
197  * @return  LE address.
198  */
199 jstring CALEGetAddressFromGatt(JNIEnv *env, jobject gatt);
200
201 #ifdef __cplusplus
202 } /* extern "C" */
203 #endif
204
205 #endif /* CA_LE_UTILS_H_ */