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