replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / resource / csdk / connectivity / src / bt_le_adapter / android / calestate.h
1 /* ****************************************************************
2  *
3  * Copyright 2017 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_LIST_H_
26 #define CA_LE_LIST_H_
27
28 #include "cacommon.h"
29 #include "cathreadpool.h" /* for thread pool */
30 #include "octhread.h"
31 #include "uarraylist.h"
32 #include "jni.h"
33
34 #ifdef __cplusplus
35 extern "C"
36 {
37 #endif
38
39 typedef struct le_state_info
40 {
41     char address[CA_MACADDR_SIZE];
42     uint16_t connectedState;
43     uint16_t sendState;
44     jboolean autoConnectFlag;
45     jboolean isDescriptorFound;
46     uint16_t mtuSize;
47 } CALEState_t;
48
49 /**
50  * update new state information.
51  * @param[in]   address               remote address.
52  * @param[in]   state_type            state type.
53  * @param[in]   target_state          state index to update.
54  * @param[in]   deviceList            target device list.
55  * @param[in]   deviceListMutex       target device list mutex.
56  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
57  */
58 CAResult_t CALEUpdateDeviceState(const char* address,
59                                  uint16_t state_type,
60                                  uint16_t target_state,
61                                  u_arraylist_t *deviceList,
62                                  oc_mutex deviceListMutex);
63
64 /**
65  * check whether the remote address is existed or not.
66  * @param[in]   address               remote address.
67  * @param[in]   deviceList            target device list.
68  * @return  true or false.
69  */
70 bool CALEIsDeviceInList(const char* remoteAddress,
71                         u_arraylist_t *deviceList);
72
73 /**
74  * remove all device states.
75  * @param[in]   deviceList            target device list.
76  * @param[in]   deviceListMutex       target device list mutex.
77  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
78  */
79 CAResult_t CALERemoveAllDeviceState(u_arraylist_t *deviceList,
80                                     oc_mutex deviceListMutex);
81
82 /**
83  * Reset values of device state for all of devices.
84  * this method has to be invoked when BT adapter is disabled.
85  * @param[in]   deviceList            target device list.
86  * @param[in]   deviceListMutex       target device list mutex.
87  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
88  */
89 CAResult_t CALEResetDeviceStateForAll(u_arraylist_t *deviceList,
90                                       oc_mutex deviceListMutex);
91
92 /**
93  * remove the device state for a remote device.
94  * @param[in]   remoteAddress         remote address.
95  * @param[in]   deviceList            target device list.
96  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
97  */
98 CAResult_t CALERemoveDeviceState(const char* remoteAddress,
99                                  u_arraylist_t *deviceList);
100
101 /**
102  * get state information for a remote device.
103  * @param[in]   remoteAddress         remote address.
104  * @param[in]   deviceList            target device list.
105  * @return  CALEState_t.
106  */
107 CALEState_t* CALEGetStateInfo(const char* remoteAddressm,
108                               u_arraylist_t *deviceList);
109
110 /**
111  * check whether the remote address has same state with target state.
112  * @param[in]   remoteAddress         remote address.
113  * @param[in]   state_type            state_type.
114  * @param[in]   target_state          state index to check.
115  * @param[in]   deviceList            target device list.
116  * @param[in]   deviceListMutex       target device list mutex.
117  * @return  true or false.
118  */
119 bool CALEIsValidState(const char* remoteAddress,
120                       uint16_t state_type,
121                       uint16_t target_state,
122                       u_arraylist_t *deviceList,
123                       oc_mutex deviceListMutex);
124
125
126 /**
127  * set flag into State List.
128  * @param[in]   env                   JNI interface pointer.
129  * @param[in]   jni_address           remote address.
130  * @param[in]   state_idx             state index.
131  * @param[in]   flag                  auto connect flag.
132  * @param[in]   deviceList            target device list.
133  * @param[in]   deviceListMutex       target device list mutex.
134  */
135 CAResult_t CALESetFlagToState(JNIEnv *env, jstring jni_address,
136                               jint state_idx, jboolean flag,
137                               u_arraylist_t *deviceList,
138                               oc_mutex deviceListMutex);
139
140 /**
141  * get flag from State List.
142  * @param[in]   env                   JNI interface pointer.
143  * @param[in]   jni_address           remote address.
144  * @param[in]   state_idx             state index.
145  * @param[in]   deviceList            target device list.
146  * @param[in]   deviceListMutex       target device list mutex.
147  * @return  current flag;
148  */
149 jboolean CALEGetFlagFromState(JNIEnv *env, jstring jni_address, jint state_idx,
150                               u_arraylist_t *deviceList, oc_mutex deviceListMutex);
151
152 /**
153  * This function is used to set MTU size
154  * which negotiated between client and server device.
155  * @param[in]   address               remote address.
156  * @param[in]   mtuSize               MTU size.
157  * @param[in]   deviceList            target device list.
158  * @param[in]   deviceListMutex       target device list mutex.
159  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
160  */
161 CAResult_t CALESetMtuSize(const char* address, uint16_t mtuSize,
162                           u_arraylist_t *deviceList, oc_mutex deviceListMutex);
163
164 /**
165  * get MTU size.
166  * @param[in] address      the address of the remote device.
167  * @param[in]   deviceList            target device list.
168  * @param[in]   deviceListMutex       target device list mutex.
169  * @return  mtu size negotiated from remote device.
170  */
171 uint16_t CALEGetMtuSize(const char* address,
172                         u_arraylist_t *deviceList,
173                         oc_mutex deviceListMutex);
174 #ifdef __cplusplus
175 } /* extern "C" */
176 #endif
177
178 #endif /* CA_LESERVER_H_ */