replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / resource / csdk / connectivity / src / bt_le_adapter / android / caleclient.h
index ad2f8da..e05a0d4 100644 (file)
@@ -25,6 +25,7 @@
 #ifndef CA_LECLIENT_H_
 #define CA_LECLIENT_H_
 
+#include "calestate.h"
 #include "cacommon.h"
 #include "cathreadpool.h"
 #include "uarraylist.h"
@@ -35,27 +36,15 @@ extern "C"
 {
 #endif
 
-static const uint16_t GATT_ERROR = 133;
-
-static const uint16_t STATE_CHARACTER_SET = 2;
-static const uint16_t STATE_CHARACTER_UNSET = 1;
-static const uint16_t STATE_CHARACTER_NO_CHANGE = 0;
-
-static const uint16_t STATE_SEND_NONE = 0;
-static const uint16_t STATE_SEND_SUCCESS = 1;
-static const uint16_t STATE_SEND_FAILED = 2;
-
-static const jint STATE_CONNECTED = 2;
-static const jint STATE_DISCONNECTED = 0;
-
-typedef struct le_state_info
+/**
+ * BLE Scanning State.
+ */
+typedef enum
 {
-    char address[CA_MACADDR_SIZE];
-    jint connectedState;
-    uint16_t notificationState;
-    uint16_t sendState;
-    jboolean autoConnectFlag;
-} CALEState_t;
+    BLE_SCAN_ENABLE = 0, /**< BLE scan is working */
+    BLE_SCAN_DISABLE,    /**< BLE scan is not working */
+    BLE_SCAN_NONE        /**< Initialize State */
+} CALEScanState_t;
 
 /**
  * Callback to be notified on reception of any data from remote devices.
@@ -106,6 +95,13 @@ CAResult_t CALEClientDestroyJniInterface();
 void CALEClientSendFinish(JNIEnv *env, jobject gatt);
 
 /**
+ * send negotiation message after gatt connection is done.
+ * @param[in]   address               remote address.
+ * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
+ */
+CAResult_t CALEClientSendNegotiationMessage(const char* address);
+
+/**
  * send data for unicast (interface).
  * @param[in]   address               remote address.
  * @param[in]   data                  data for transmission.
@@ -183,13 +179,6 @@ CAResult_t CALEClientSendMulticastMessageImpl(JNIEnv *env, const uint8_t *data,
                                               const uint32_t dataLen);
 
 /**
- * check whether it is connected or not with remote address.
- * @param[in]   address               remote address.
- * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
- */
-CAResult_t CALECheckSendState(const char* address);
-
-/**
  * send data to remote device.
  * if it isn't connected yet. connect LE before try to send data.
  * @param[in]   env                   JNI interface pointer.
@@ -237,6 +226,14 @@ CAResult_t CALEClientStartScan();
 CAResult_t CALEClientStartScanImpl(JNIEnv *env, jobject callback);
 
 /**
+ * start to scan whole bluetooth devices for android API level 21 (implement).
+ * @param[in]   env                   JNI interface pointer.
+ * @param[in]   callback              callback to receive device object by scanning.
+ * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
+ */
+CAResult_t CALEClientStartScanImplForV21(JNIEnv *env, jobject callback);
+
+/**
  * start to scan target bluetooth devices for service uuid (implement).
  * @param[in]   env                   JNI interface pointer.
  * @param[in]   uuids                 target UUID.
@@ -247,6 +244,16 @@ CAResult_t CALEClientStartScanWithUUIDImpl(JNIEnv *env, jobjectArray uuids,
                                            jobject callback);
 
 /**
+ * start to scan target bluetooth devices for service uuid for android API level 21 (implement).
+ * @param[in]   env                   JNI interface pointer.
+ * @param[in]   uuids                 target UUID.
+ * @param[in]   callback              callback to receive device object by scanning.
+ * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
+ */
+CAResult_t CALEClientStartScanWithUUIDImplForV21(JNIEnv *env, jobjectArray uuids,
+                                                 jobject callback);
+
+/**
  * get uuid object.
  * @param[in]   env                   JNI interface pointer.
  * @param[in]   uuid                  uuid.
@@ -261,12 +268,6 @@ jobject CALEClientGetUUIDObject(JNIEnv *env, const char *uuid);
 CAResult_t CALEClientStopScan();
 
 /**
- * set ble scanning flag.
- * @param[in]   flag        scan flag.
- */
-void CALEClientSetScanFlag(bool flag);
-
-/**
  * stop scan (implement).
  * @param[in]   env                   JNI interface pointer.
  * @param[in]   callback              callback to receive device object by scanning.
@@ -275,20 +276,12 @@ void CALEClientSetScanFlag(bool flag);
 CAResult_t CALEClientStopScanImpl(JNIEnv *env, jobject callback);
 
 /**
- * set auto connect flag for connectGatt API.
- * @param[in]   env                   JNI interface pointer.
- * @param[in]   jni_address           remote address.
- * @param[in]   flag                  auto connect flag.
- */
-CAResult_t CALEClientSetAutoConnectFlag(JNIEnv *env, jstring jni_address, jboolean flag);
-
-/**
- * get auto connect flag.
+ * stop scan for android API level 21(implement).
  * @param[in]   env                   JNI interface pointer.
- * @param[in]   jni_address           remote address.
- * @return  current auto connect flag;
+ * @param[in]   callback              callback to receive device object by scanning.
+ * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
  */
-jboolean CALEClientGetAutoConnectFlag(JNIEnv *env, jstring jni_address);
+CAResult_t CALEClientStopScanImplForV21(JNIEnv *env, jobject callback);
 
 /**
  * connect to gatt server hosted.
@@ -325,6 +318,14 @@ CAResult_t CALEClientDisconnectAll(JNIEnv *env);
 CAResult_t CALEClientDisconnectforAddress(JNIEnv *env, jstring remoteAddress);
 
 /**
+ * request MTU size negotiation to server.
+ * @param[in]   env                   JNI interface pointer.
+ * @param[in]   bluetoothGatt         gatt object.
+ * @param[in]   size                  MTU size.
+ * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
+ */
+CAResult_t CALEClientRequestMTU(JNIEnv *env, jobject bluetoothGatt, jint size);
+/**
  * start discovery server.
  * @param[in]   env                   JNI interface pointer.
  * @param[in]   bluetoothGatt         Gatt profile object.
@@ -506,35 +507,43 @@ CAResult_t CALEClientRemoveGattObjForAddr(JNIEnv *env, jstring addr);
 jstring CALEClientGetLEAddressFromBTDevice(JNIEnv *env, jobject bluetoothDevice);
 
 /**
- * update new state information.
- * @param[in]   address               remote address.
- * @param[in]   connectedState        connection state.
- * @param[in]   notificationState     whether characteristic notification already set or not.
- * @param[in]   sendState             whether sending was success or not.
+ * update new state information by Bluetooth device object.
+ * @param[in]   env                   JNI interface pointer.
+ * @param[in]   device                Bluetooth device.
+ * @param[in]   state_type            state type.
+ * @param[in]   target_state          state index to update.
  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
  */
-CAResult_t CALEClientUpdateDeviceState(const char* address, uint32_t connectedState,
-                                       uint16_t notificationState, uint16_t sendState);
+CAResult_t CALEClientUpdateDeviceStateWithBtDevice(JNIEnv *env,
+                                                   jobject device,
+                                                   uint16_t state_type,
+                                                   uint16_t target_state);
 
 /**
- * add new state to state list.
- * @param[in]   state                 new state.
- * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
+ * set flag into State List.
+ * @param[in]   env                   JNI interface pointer.
+ * @param[in]   jni_address           remote address.
+ * @param[in]   state_idx             state index.
+ * @param[in]   flag                  auto connect flag.
  */
-CAResult_t CALEClientAddDeviceStateToList(CALEState_t* state);
+CAResult_t CALEClientSetFlagToState(JNIEnv *env, jstring jni_address,
+                                    jint state_idx, jboolean flag);
 
 /**
- * check whether the remote address is existed or not.
- * @param[in]   address               remote address.
- * @return  true or false.
+ * get flag from State List.
+ * @param[in]   env                   JNI interface pointer.
+ * @param[in]   jni_address           remote address.
+ * @param[in]   state_idx             state index.
+ * @return  current flag;
  */
-bool CALEClientIsDeviceInList(const char *remoteAddress);
+jboolean CALEClientGetFlagFromState(JNIEnv *env, jstring jni_address, jint state_idx);
 
 /**
- * remove all device states.
- * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
+ * get MTU size.
+ * @param[in] address      the address of the remote device.
+ * @return  mtu size negotiated from remote device.
  */
-CAResult_t CALEClientRemoveAllDeviceState();
+uint16_t CALEClientGetMtuSize(const char* address);
 
 /**
  * Reset values of device state for all of devices.
@@ -544,34 +553,6 @@ CAResult_t CALEClientRemoveAllDeviceState();
 CAResult_t CALEClientResetDeviceStateForAll();
 
 /**
- * remove the device state for a remote device.
- * @param[in]   remoteAddress         remote address.
- * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
- */
-CAResult_t CALEClientRemoveDeviceState(const char* remoteAddress);
-
-/**
- * get state information for a remote device.
- * @param[in]   remoteAddress         remote address.
- * @return  CALEState_t.
- */
-CALEState_t* CALEClientGetStateInfo(const char* remoteAddress);
-
-/**
- * check whether the remote address is connected or not.
- * @param[in]   remoteAddress         remote address.
- * @return  true or false.
- */
-bool CALEClientIsConnectedDevice(const char* remoteAddress);
-
-/**
- * check whether the remote address set CharacteristicNotification or not.
- * @param[in]   remoteAddress         remote address.
- * @return  true or false.
- */
-bool CALEClientIsSetCharacteristic(const char* remoteAddress);
-
-/**
  * create scan device list.
  */
 void CALEClientCreateDeviceList();
@@ -616,6 +597,51 @@ CAResult_t CALEClientCloseProfileProxy(JNIEnv *env, jobject gatt);
  */
 jobject CALEClientGattConnect(JNIEnv *env, jobject bluetoothDevice, jboolean autoconnect);
 
+/**
+ * connect to GATT Server hosted by this device directly.
+ * @param[in]   env                   JNI interface pointer.
+ * @param[in]   bluetoothDevice       bluetooth device object.
+ * @param[in]   autoconnect           connect as soon as the device becomes avaiable(true).
+ * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
+ */
+CAResult_t CALEClientDirectConnect(JNIEnv *env, jobject bluetoothDevice, jboolean autoconnect);
+
+/**
+ * check connection status.
+ * @param[in] address      the address of the remote device.
+ * @return  true or false.
+ */
+bool CALEClientIsConnected(const char* address);
+
+/**
+ * set new interval time and working count.
+ * @param[in]  intervalTime             interval time(Seconds).
+ * @param[in]  workingCount             working count for selected interval time.
+ * @param[in]  nextScanningStep         set next scanning state.
+ */
+void CALEClientSetScanInterval(int32_t intervalTime, int32_t workingCount,
+                               CALEScanState_t nextScanningStep);
+
+/**
+ * restart scanning with new interval time and working count.
+ * @param[in]  intervalTime             interval time(Seconds).
+ * @param[in]  workingCount             working count for selected interval time.
+ * @param[in]  nextScanningStep         set next scanning state.
+ */
+void CALERestartScanWithInterval(int32_t intervalTime, int32_t workingCount,
+                                 CALEScanState_t nextScanningStep);
+
+/**
+ * start LE scanning logic with interval time and working count.
+ * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
+ */
+CAResult_t CALEClientStartScanWithInterval();
+
+/**
+ * stop LE scanning logic with interval time and cycle.
+ */
+void CALEClientStopScanWithInterval();
+
 #ifdef __cplusplus
 } /* extern "C" */
 #endif