replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / resource / csdk / connectivity / src / bt_le_adapter / ios / caleserver.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_LESERVER_H_
26 #define CA_LESERVER_H_
27
28 #include "cacommon.h"
29 #include "cathreadpool.h"
30 #include "uarraylist.h"
31
32 #include "caleutils.h"
33
34 #ifdef __cplusplus
35 extern "C"
36 {
37 #endif
38
39 /**
40  * Callback to be notified on reception of any data from remote devices.
41  * @param[in]  address           MAC address of remote device.
42  * @param[in]  data              Data received from remote device.
43  * @pre  Callback must be registered using CALEServerSetCallback(CAPacketReceiveCallback callback).
44  */
45 typedef void (*CAPacketReceiveCallback)(const char *address, const uint8_t *data);
46
47 /**
48  * initialize server for BLE.
49  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
50  */
51 CAResult_t CALEServerInitialize();
52
53 /**
54  * terminate client for BLE.
55  */
56 void CALEServerTerminate();
57
58 /**
59  * send data for unicast (interface).
60  * @param[in]   address          remote address.
61  * @param[in]   data             data for transmission.
62  * @param[in]   dataLen          data length.
63  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
64  */
65 CAResult_t CALEServerSendUnicastMessage(const char *address,
66                                         const uint8_t *data,
67                                         uint32_t dataLen);
68
69 /**
70  * send data for multicast (interface).
71  * @param[in]   data             data for transmission.
72  * @param[in]   dataLen          data length.
73  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
74  */
75 CAResult_t CALEServerSendMulticastMessage(const uint8_t *data, uint32_t dataLen);
76
77 /**
78  * start multicast server (start advertise).
79  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
80  */
81 CAResult_t CALEServerStartMulticastServer();
82
83 /**
84  * stop multicast server (stop discovery).
85  * @return  None
86  */
87 CAResult_t CALEServerStopMulticastServer();
88
89 /**
90  * set this callback for receiving data packets from peer devices.
91  * @param[in]   callback         callback to be notified on reception of
92  *                               unicast/multicast data packets.
93  */
94 void CALEServerSetCallback(CAPacketReceiveCallback callback);
95
96 /**
97  * send data for unicast (implement).
98  * @param[in]   env              JNI interface pointer.
99  * @param[in]   address          remote address.
100  * @param[in]   data             data for transmission.
101  * @param[in]   dataLen          data length.
102  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
103  */
104 CAResult_t CALEServerSendUnicastMessageImpl(const char *address,
105                                             const uint8_t *data,
106                                             uint32_t dataLen);
107
108 /**
109  * send data for multicast (implement)
110  * @param[in]   env              JNI interface pointer
111  * @param[in]   data             data for transmission
112  * @param[in]   dataLen          data length
113  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
114  */
115 CAResult_t CALEServerSendMulticastMessageImpl(const uint8_t *data,
116                                               uint32_t dataLen);
117
118 /**
119  * start advertise in gatt server.
120  */
121 CAResult_t CALEStartAdvertise();
122
123 /**
124  * start advertise in gatt server.
125  * @param[in]   env                JNI interface pointer.
126  * @param[in]   advertiseCallback  callback to be notified on reception of
127  *                                 advertisement result.
128  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
129  */
130 CAResult_t CALEServerStartAdvertise();
131
132 /**
133  * stop advertise in gatt server.
134  * @param[in]   env                JNI interface pointer.
135  * @param[in]   advertiseCallback  callback to be notified on reception of
136  *                                 advertisement result.
137  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
138  */
139 CAResult_t CALEServerStopAdvertise();
140
141 /**
142  * start gatt server.
143  * @param[in]   env                  JNI interface pointer.
144  * @param[in]   gattServerCallback   callback to be notified on reception of
145  *                                   state change of gatt server.
146  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
147  */
148 CAResult_t CALEServerStartGattServer();
149
150 /**
151  * close gatt server.
152  * @param[in]   env                  JNI interface pointer.
153  * @param[in]   bluetoothGattServer  Gatt Server object.
154  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
155  */
156 //CAResult_t CALEServerGattClose();
157 /**
158  * send data.
159  * @param[in]   env                  JNI interface pointer.
160  * @param[in]   bluetoothDevice      bluetooth device object.
161  * @param[in]   data                 data which send.
162  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
163  */
164 CAResult_t CALEServerSend(CBCentral *central, const uint8_t *data, const uint32_t dataLen);
165
166 /**
167  * disconnect LE for all devices.
168  * @param[in]   env                  JNI interface pointer.
169  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
170  */
171 //CAResult_t CALEServerDisconnectAllDevices();
172
173 /**
174  * create connected device list.
175  */
176 void CALEServerCreateCachedDeviceList();
177
178 /**
179  * check whether the device exist in the list or not.
180  * @param[in]   env                   JNI interface pointer.
181  * @param[in]   remoteAddress         remote address.
182  * @return  true or false.
183  */
184 bool CALEServerIsDeviceInList(const char* remoteAddress);//, const char* serviceUUID);
185
186 /**
187  * add device object to the list (connected device list).
188  * @param[in]   env                   JNI interface pointer.
189  * @param[in]   device                bluetooth device object.
190  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
191  */
192 CAResult_t CALEServerAddDeviceToList(CBCentral *central);
193
194 /**
195  * remove all devices objects in the list (connected device list).
196  * @param[in]   env                   JNI interface pointer.
197  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
198  */
199 CAResult_t CALEServerRemoveAllDevices();
200
201 /**
202  * remove target device in the list (connected device list).
203  * @param[in]   env                   JNI interface pointer.
204  * @param[in]   address               target address to remove.
205  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
206  */
207 CAResult_t CALEServerRemoveDevice(const char *remoteAddr);
208
209 /**
210  * initialize mutex.
211  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
212  */
213 CAResult_t CALEServerInitMutexVaraibles();
214
215 /**
216  * terminate mutex.
217  */
218 void CALEServerTerminateMutexVaraibles();
219
220 /**
221  * initialize condition.
222  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
223  */
224 CAResult_t CALEServerInitConditionVaraibles();
225
226 /**
227  * terminate condition.
228  */
229 void CALEServerTerminateConditionVaraibles();
230
231 NSString *CALEServerGetAddressFromGattObj(CBCentral *central);
232
233 bool CALEServerIsEnableBTAdapter();
234 void CALEServerSetFlagBTAdapter(bool state);
235
236 #ifdef __cplusplus
237 } /* extern "C" */
238 #endif
239
240 #endif /* CA_LESERVER_H_ */