Upgrade bluez5_37 :Merge the code from private
[platform/upstream/bluez.git] / android / tester-main.h
1 /*
2  *
3  *  BlueZ - Bluetooth protocol stack for Linux
4  *
5  *  Copyright (C) 2014  Intel Corporation. All rights reserved.
6  *
7  *
8  *  This library is free software; you can redistribute it and/or
9  *  modify it under the terms of the GNU Lesser General Public
10  *  License as published by the Free Software Foundation; either
11  *  version 2.1 of the License, or (at your option) any later version.
12  *
13  *  This library is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  *  Lesser General Public License for more details.
17  *
18  *  You should have received a copy of the GNU Lesser General Public
19  *  License along with this library; if not, write to the Free Software
20  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21  *
22  */
23
24 #include <glib.h>
25 #include <hardware/audio.h>
26 #include <hardware/bluetooth.h>
27 #include <hardware/bt_sock.h>
28 #include <hardware/bt_hh.h>
29 #include <hardware/bt_pan.h>
30 #include <hardware/bt_hl.h>
31 #include <hardware/bt_av.h>
32 #include <hardware/bt_rc.h>
33 #include <hardware/bt_gatt.h>
34
35 #include "emulator/hciemu.h"
36 #include <hardware/bt_mce.h>
37
38 struct pdu_set {
39         struct iovec req;
40         struct iovec rsp;
41 };
42
43 #define raw_data(args...) ((unsigned char[]) { args })
44
45 #define raw_pdu(args...)                                        \
46         {                                                       \
47                 .iov_base = raw_data(args),                     \
48                 .iov_len = sizeof(raw_data(args)),              \
49         }
50
51 #define end_pdu { .iov_base = NULL }
52
53 #define TEST_CASE_BREDR(text, ...) { \
54                 HCIEMU_TYPE_BREDR, \
55                 text, \
56                 sizeof((struct step[]) {__VA_ARGS__}) / sizeof(struct step), \
57                 (struct step[]) {__VA_ARGS__}, \
58         }
59
60 #define TEST_CASE_BREDRLE(text, ...) { \
61                 HCIEMU_TYPE_BREDRLE, \
62                 text, \
63                 sizeof((struct step[]) {__VA_ARGS__}) / sizeof(struct step), \
64                 (struct step[]) {__VA_ARGS__}, \
65         }
66
67 #define MODIFY_DATA(status, modif_fun, from, to, len) { \
68                 .action_status = status, \
69                 .action = modif_fun, \
70                 .set_data = from, \
71                 .set_data_2 = to, \
72                 .set_data_len = len, \
73         }
74
75 #define PROCESS_DATA(status, proc_fun, data1, data2, data3) { \
76                 .action_status = status, \
77                 .action = proc_fun, \
78                 .set_data = data1, \
79                 .set_data_2 = data2, \
80                 .set_data_3 = data3, \
81         }
82
83 #define ACTION(status, act_fun, data_set) { \
84                 .action_status = status, \
85                 .action = act_fun, \
86                 .set_data = data_set, \
87         }
88
89 #define ACTION_FAIL(act_fun, data_set) \
90                 ACTION(BT_STATUS_FAIL, act_fun, data_set)
91
92 #define ACTION_SUCCESS(act_fun, data_set) \
93                 ACTION(BT_STATUS_SUCCESS, act_fun, data_set)
94
95 #define CALLBACK(cb) { \
96                 .callback = cb, \
97         }
98
99 #define CALLBACK_STATE(cb, cb_res) { \
100                 .callback = cb, \
101                 .callback_result.state = cb_res, \
102         }
103
104 #define CALLBACK_STATUS(cb, cb_res) { \
105                 .callback = cb, \
106                 .callback_result.status = cb_res, \
107         }
108
109 #define CALLBACK_ERROR(cb, cb_err) { \
110                 .callback = cb, \
111                 .callback_result.error = cb_err, \
112         }
113
114 #define CALLBACK_ADAPTER_PROPS(props, prop_cnt) { \
115                 .callback = CB_BT_ADAPTER_PROPERTIES, \
116                 .callback_result.properties = props, \
117                 .callback_result.num_properties = prop_cnt, \
118         }
119
120 #define CALLBACK_PROPS(cb, props, prop_cnt) { \
121                 .callback = cb, \
122                 .callback_result.properties = props, \
123                 .callback_result.num_properties = prop_cnt, \
124         }
125
126 #define CALLBACK_HH_MODE(cb, cb_res, cb_mode) { \
127                 .callback = cb, \
128                 .callback_result.status = cb_res, \
129                 .callback_result.mode = cb_mode, \
130         }
131
132 #define CALLBACK_HHREPORT(cb, cb_res, cb_rep_size) { \
133                 .callback = cb, \
134                 .callback_result.status = cb_res, \
135                 .callback_result.report_size = cb_rep_size, \
136         }
137
138 #define CLLBACK_GATTC_SCAN_RES(props, prop_cnt, cb_adv_data) {\
139                 .callback = CB_GATTC_SCAN_RESULT, \
140                 .callback_result.properties = props, \
141                 .callback_result.num_properties = prop_cnt, \
142                 .callback_result.adv_data = cb_adv_data, \
143         }
144
145 #define CALLBACK_GATTC_CONNECT(cb_res, cb_prop, cb_conn_id, cb_client_id) { \
146                 .callback = CB_GATTC_OPEN, \
147                 .callback_result.status = cb_res, \
148                 .callback_result.properties = cb_prop, \
149                 .callback_result.num_properties = 1, \
150                 .callback_result.conn_id = cb_conn_id, \
151                 .callback_result.gatt_app_id = cb_client_id, \
152         }
153
154 #define CALLBACK_GATTC_SEARCH_RESULT(cb_conn_id, cb_service) { \
155                 .callback = CB_GATTC_SEARCH_RESULT, \
156                 .callback_result.conn_id = cb_conn_id, \
157                 .callback_result.service = cb_service \
158         }
159
160 #define CALLBACK_GATTC_SEARCH_COMPLETE(cb_res, cb_conn_id) { \
161                 .callback = CB_GATTC_SEARCH_COMPLETE, \
162                 .callback_result.conn_id = cb_conn_id \
163         }
164 #define CALLBACK_GATTC_GET_CHARACTERISTIC_CB(cb_res, cb_conn_id, cb_service, \
165                                                 cb_char, cb_char_prop) { \
166                 .callback = CB_GATTC_GET_CHARACTERISTIC, \
167                 .callback_result.conn_id = cb_conn_id, \
168                 .callback_result.status = cb_res, \
169                 .callback_result.service = cb_service, \
170                 .callback_result.characteristic = cb_char, \
171                 .callback_result.char_prop = cb_char_prop \
172         }
173
174 #define CALLBACK_GATTC_GET_DESCRIPTOR(cb_res, cb_conn_id, cb_service, \
175                                                 cb_char, cb_desc) { \
176                 .callback = CB_GATTC_GET_DESCRIPTOR, \
177                 .callback_result.conn_id = cb_conn_id, \
178                 .callback_result.status = cb_res, \
179                 .callback_result.service = cb_service, \
180                 .callback_result.characteristic = cb_char, \
181                 .callback_result.descriptor = cb_desc \
182         }
183
184 #define CALLBACK_GATTC_GET_INCLUDED(cb_res, cb_conn_id, cb_service, \
185                                                         cb_incl) { \
186                 .callback = CB_GATTC_GET_INCLUDED_SERVICE, \
187                 .callback_result.conn_id = cb_conn_id, \
188                 .callback_result.status = cb_res, \
189                 .callback_result.service = cb_service, \
190                 .callback_result.included = cb_incl, \
191         }
192
193 #define CALLBACK_GATTC_READ_CHARACTERISTIC(cb_res, cb_conn_id, cb_read_data) { \
194                 .callback = CB_GATTC_READ_CHARACTERISTIC, \
195                 .callback_result.conn_id = cb_conn_id, \
196                 .callback_result.status = cb_res, \
197                 .callback_result.read_params = cb_read_data, \
198         }
199
200 #define CALLBACK_GATTC_READ_DESCRIPTOR(cb_res, cb_conn_id, cb_read_data) { \
201                 .callback = CB_GATTC_READ_DESCRIPTOR, \
202                 .callback_result.conn_id = cb_conn_id, \
203                 .callback_result.status = cb_res, \
204                 .callback_result.read_params = cb_read_data, \
205         }
206
207 #define CALLBACK_GATTC_WRITE_DESCRIPTOR(cb_res, cb_conn_id, cb_write_data) { \
208                 .callback = CB_GATTC_WRITE_DESCRIPTOR, \
209                 .callback_result.conn_id = cb_conn_id, \
210                 .callback_result.status = cb_res, \
211                 .callback_result.write_params = cb_write_data, \
212         }
213
214 #define CALLBACK_GATTC_WRITE_CHARACTERISTIC(cb_res, cb_conn_id, \
215                                                         cb_write_data) { \
216                 .callback = CB_GATTC_WRITE_CHARACTERISTIC, \
217                 .callback_result.conn_id = cb_conn_id, \
218                 .callback_result.status = cb_res, \
219                 .callback_result.write_params = cb_write_data, \
220         }
221
222 #define CALLBACK_GATTC_REGISTER_FOR_NOTIF(cb_res, cb_conn_id, cb_char,\
223                                                 cb_service, cb_registered) { \
224                 .callback = CB_GATTC_REGISTER_FOR_NOTIFICATION, \
225                 .callback_result.conn_id = cb_conn_id, \
226                 .callback_result.status = cb_res, \
227                 .callback_result.service = cb_service, \
228                 .callback_result.characteristic = cb_char, \
229                 .callback_result.notification_registered = cb_registered \
230         }
231
232 #define CALLBACK_GATTC_NOTIFY(cb_conn_id, cb_notify) { \
233                 .callback = CB_GATTC_NOTIFY, \
234                 .callback_result.conn_id = cb_conn_id, \
235                 .callback_result.notify_params = cb_notify \
236         }
237
238 #define CALLBACK_GATTC_DISCONNECT(cb_res, cb_prop, cb_conn_id, cb_client_id) { \
239                 .callback = CB_GATTC_CLOSE, \
240                 .callback_result.status = cb_res, \
241                 .callback_result.properties = cb_prop, \
242                 .callback_result.num_properties = 1, \
243                 .callback_result.conn_id = cb_conn_id, \
244                 .callback_result.gatt_app_id = cb_client_id, \
245         }
246
247 #define CALLBACK_GATTS_CONNECTION(cb_res, cb_prop, cb_conn_id, cb_server_id) { \
248                 .callback = CB_GATTS_CONNECTION, \
249                 .callback_result.connected = cb_res, \
250                 .callback_result.properties = cb_prop, \
251                 .callback_result.num_properties = 1, \
252                 .callback_result.conn_id = cb_conn_id, \
253                 .callback_result.gatt_app_id = cb_server_id, \
254         }
255
256 #define CALLBACK_GATTS_NOTIF_CONF(cb_conn_id, cb_status) { \
257                 .callback = CB_GATTS_INDICATION_SEND, \
258                 .callback_result.conn_id = cb_conn_id, \
259                 .callback_result.status = cb_status, \
260         }
261
262 #define CALLBACK_GATTS_SERVICE_ADDED(cb_res, cb_server_id, cb_service, \
263                                                 cb_srvc_handle, \
264                                                 cb_store_srvc_handle) { \
265                 .callback = CB_GATTS_SERVICE_ADDED, \
266                 .callback_result.status = cb_res, \
267                 .callback_result.gatt_app_id = cb_server_id, \
268                 .callback_result.service = cb_service, \
269                 .callback_result.srvc_handle = cb_srvc_handle, \
270                 .store_srvc_handle = cb_store_srvc_handle, \
271         }
272
273 #define CALLBACK_GATTS_INC_SERVICE_ADDED(cb_res, cb_server_id, cb_srvc_handle, \
274                                                         cb_inc_srvc_handle) { \
275                 .callback = CB_GATTS_INCLUDED_SERVICE_ADDED, \
276                 .callback_result.status = cb_res, \
277                 .callback_result.gatt_app_id = cb_server_id, \
278                 .callback_result.srvc_handle = cb_srvc_handle, \
279                 .callback_result.inc_srvc_handle = cb_inc_srvc_handle, \
280         }
281
282 #define CALLBACK_GATTS_CHARACTERISTIC_ADDED(cb_res, cb_server_id, cb_uuid, \
283                                                 cb_srvc_handle, \
284                                                 cb_char_handle, \
285                                                 cb_store_char_handle) { \
286                 .callback = CB_GATTS_CHARACTERISTIC_ADDED, \
287                 .callback_result.status = cb_res, \
288                 .callback_result.gatt_app_id = cb_server_id, \
289                 .callback_result.uuid = cb_uuid, \
290                 .callback_result.srvc_handle = cb_srvc_handle, \
291                 .callback_result.char_handle = cb_char_handle, \
292                 .store_char_handle = cb_store_char_handle, \
293         }
294
295 #define CALLBACK_GATTS_DESCRIPTOR_ADDED(cb_res, cb_server_id, cb_uuid, \
296                                         cb_srvc_handle, cb_desc_handle, \
297                                         cb_store_desc_handle) { \
298                 .callback = CB_GATTS_DESCRIPTOR_ADDED, \
299                 .callback_result.status = cb_res, \
300                 .callback_result.gatt_app_id = cb_server_id, \
301                 .callback_result.uuid = cb_uuid, \
302                 .callback_result.srvc_handle = cb_srvc_handle, \
303                 .callback_result.desc_handle = cb_desc_handle, \
304                 .store_desc_handle = cb_store_desc_handle, \
305         }
306
307 #define CALLBACK_GATTS_SERVICE_STARTED(cb_res, cb_server_id, cb_srvc_handle) { \
308                 .callback = CB_GATTS_SERVICE_STARTED, \
309                 .callback_result.status = cb_res, \
310                 .callback_result.gatt_app_id = cb_server_id, \
311                 .callback_result.srvc_handle = cb_srvc_handle, \
312         }
313
314 #define CALLBACK_GATTS_SERVICE_STOPPED(cb_res, cb_server_id, cb_srvc_handle) { \
315                 .callback = CB_GATTS_SERVICE_STOPPED, \
316                 .callback_result.status = cb_res, \
317                 .callback_result.gatt_app_id = cb_server_id, \
318                 .callback_result.srvc_handle = cb_srvc_handle, \
319         }
320
321 #define CALLBACK_GATTS_SERVICE_DELETED(cb_res, cb_server_id, cb_srvc_handle) { \
322                 .callback = CB_GATTS_SERVICE_DELETED, \
323                 .callback_result.status = cb_res, \
324                 .callback_result.gatt_app_id = cb_server_id, \
325                 .callback_result.srvc_handle = cb_srvc_handle, \
326         }
327
328 #define CALLBACK_GATTS_REQUEST_READ(cb_conn_id, cb_trans_id, cb_prop, \
329                                                 cb_attr_handle, cb_offset, \
330                                                 cb_is_long) { \
331                 .callback = CB_GATTS_REQUEST_READ, \
332                 .callback_result.conn_id = cb_conn_id, \
333                 .callback_result.trans_id = cb_trans_id, \
334                 .callback_result.properties = cb_prop, \
335                 .callback_result.num_properties = 1, \
336                 .callback_result.attr_handle = cb_attr_handle, \
337                 .callback_result.offset = cb_offset, \
338                 .callback_result.is_long = cb_is_long, \
339         }
340
341 #define CALLBACK_GATTS_REQUEST_WRITE(cb_conn_id, cb_trans_id, cb_prop, \
342                                                 cb_attr_handle, cb_offset, \
343                                                 cb_length, cb_need_rsp, \
344                                                 cb_is_prep, cb_value) { \
345                 .callback = CB_GATTS_REQUEST_WRITE, \
346                 .callback_result.conn_id = cb_conn_id, \
347                 .callback_result.trans_id = cb_trans_id, \
348                 .callback_result.properties = cb_prop, \
349                 .callback_result.num_properties = 1, \
350                 .callback_result.attr_handle = cb_attr_handle, \
351                 .callback_result.offset = cb_offset, \
352                 .callback_result.length = cb_length, \
353                 .callback_result.need_rsp = cb_need_rsp, \
354                 .callback_result.is_prep = cb_is_prep, \
355                 .callback_result.value = cb_value, \
356         }
357
358 #define CALLBACK_MAP_CLIENT_REMOTE_MAS_INSTANCE(cb_status, cb_prop, \
359                                                 cb_num_inst, cb_instances) { \
360                 .callback = CB_MAP_CLIENT_REMOTE_MAS_INSTANCES, \
361                 .callback_result.properties = cb_prop, \
362                 .callback_result.num_properties = 1, \
363                 .callback_result.status = cb_status, \
364                 .callback_result.num_mas_instances = cb_num_inst, \
365                 .callback_result.mas_instances = cb_instances, \
366         }
367
368 #define CALLBACK_PAN_CTRL_STATE(cb, cb_res, cb_state, cb_local_role) { \
369                 .callback = cb, \
370                 .callback_result.status = cb_res, \
371                 .callback_result.ctrl_state = cb_state, \
372                 .callback_result.local_role = cb_local_role, \
373         }
374
375 #define CALLBACK_PAN_CONN_STATE(cb, cb_res, cb_state, cb_local_role, \
376                                                         cb_remote_role) { \
377                 .callback = cb, \
378                 .callback_result.status = cb_res, \
379                 .callback_result.conn_state = cb_state, \
380                 .callback_result.local_role = cb_local_role, \
381                 .callback_result.remote_role = cb_remote_role, \
382         }
383
384 #define CALLBACK_HDP_APP_REG_STATE(cb, cb_app_id, cb_state) { \
385                 .callback = cb, \
386                 .callback_result.app_id = cb_app_id, \
387                 .callback_result.app_state = cb_state, \
388         }
389
390 #define CALLBACK_HDP_CHANNEL_STATE(cb, cb_app_id, cb_channel_id, \
391                                         cb_mdep_cfg_index, cb_state) { \
392                 .callback = cb, \
393                 .callback_result.app_id = cb_app_id, \
394                 .callback_result.channel_id = cb_channel_id, \
395                 .callback_result.mdep_cfg_index = cb_mdep_cfg_index, \
396                 .callback_result.channel_state = cb_state, \
397         }
398
399 #define CALLBACK_AV_CONN_STATE(cb, cb_av_conn_state) { \
400                 .callback = cb, \
401                 .callback_result.av_conn_state = cb_av_conn_state, \
402         }
403
404 #define CALLBACK_AV_AUDIO_STATE(cb, cb_av_audio_state) { \
405                 .callback = cb, \
406                 .callback_result.av_audio_state = cb_av_audio_state, \
407         }
408
409 #define CALLBACK_RC_PLAY_STATUS(cb, cb_length, cb_position, cb_status) { \
410                 .callback = cb, \
411                 .callback_result.song_length = cb_length, \
412                 .callback_result.song_position = cb_position, \
413                 .callback_result.play_status = cb_status, \
414         }
415
416 #define CALLBACK_RC_REG_NOTIF_TRACK_CHANGED(cb, cb_index) { \
417                 .callback = cb, \
418                 .callback_result.rc_index = cb_index, \
419         }
420
421 #define CALLBACK_RC_REG_NOTIF_POSITION_CHANGED(cb, cb_position) { \
422                 .callback = cb, \
423                 .callback_result.song_position = cb_position, \
424         }
425
426 #define CALLBACK_RC_REG_NOTIF_STATUS_CHANGED(cb, cb_status) { \
427                 .callback = cb, \
428                 .callback_result.play_status = cb_status, \
429         }
430
431 #define CALLBACK_RC_GET_ELEMENT_ATTRIBUTES(cb, cb_num_of_attrs, cb_attrs) { \
432                 .callback = cb, \
433                 .callback_result.num_of_attrs = cb_num_of_attrs, \
434                 .callback_result.attrs = cb_attrs, \
435         }
436
437 #define CALLBACK_DEVICE_PROPS(props, prop_cnt) \
438         CALLBACK_PROPS(CB_BT_REMOTE_DEVICE_PROPERTIES, props, prop_cnt)
439
440 #define CALLBACK_DEVICE_FOUND(props, prop_cnt) \
441         CALLBACK_PROPS(CB_BT_DEVICE_FOUND, props, prop_cnt)
442
443 #define CALLBACK_BOND_STATE(cb_res, props, prop_cnt) { \
444                 .callback = CB_BT_BOND_STATE_CHANGED, \
445                 .callback_result.state = cb_res, \
446                 .callback_result.properties = props, \
447                 .callback_result.num_properties = prop_cnt, \
448         }
449
450 #define CALLBACK_BOND_STATE_FAILED(cb_res, props, prop_cnt, reason) { \
451                 .callback = CB_BT_BOND_STATE_CHANGED, \
452                 .callback_result.state = cb_res, \
453                 .callback_result.status = reason, \
454                 .callback_result.properties = props, \
455                 .callback_result.num_properties = prop_cnt, \
456         }
457
458 #define CALLBACK_SSP_REQ(pair_var, props, prop_cnt) { \
459                 .callback = CB_BT_SSP_REQUEST, \
460                 .callback_result.pairing_variant = pair_var, \
461                 .callback_result.properties = props, \
462                 .callback_result.num_properties = prop_cnt, \
463         }
464
465 #define DBG_CB(cb) { cb, #cb }
466
467 /*
468  * NOTICE:
469  * Callback enum sections should be
470  * updated while adding new HAL to tester.
471  */
472 typedef enum {
473         CB_BT_NONE,
474         CB_BT_ADAPTER_STATE_CHANGED,
475         CB_BT_ADAPTER_PROPERTIES,
476         CB_BT_REMOTE_DEVICE_PROPERTIES,
477         CB_BT_DEVICE_FOUND,
478         CB_BT_DISCOVERY_STATE_CHANGED,
479         CB_BT_PIN_REQUEST,
480         CB_BT_SSP_REQUEST,
481         CB_BT_BOND_STATE_CHANGED,
482         CB_BT_ACL_STATE_CHANGED,
483         CB_BT_THREAD_EVT,
484         CB_BT_DUT_MODE_RECV,
485         CB_BT_LE_TEST_MODE,
486
487         /* Hidhost cb */
488         CB_HH_CONNECTION_STATE,
489         CB_HH_HID_INFO,
490         CB_HH_PROTOCOL_MODE,
491         CB_HH_IDLE_TIME,
492         CB_HH_GET_REPORT,
493         CB_HH_VIRTUAL_UNPLUG,
494
495         /* PAN cb */
496         CB_PAN_CONTROL_STATE,
497         CB_PAN_CONNECTION_STATE,
498
499         /* HDP cb */
500         CB_HDP_APP_REG_STATE,
501         CB_HDP_CHANNEL_STATE,
502
503         /* A2DP cb */
504         CB_A2DP_CONN_STATE,
505         CB_A2DP_AUDIO_STATE,
506
507         /* AVRCP */
508         CB_AVRCP_PLAY_STATUS_REQ,
509         CB_AVRCP_PLAY_STATUS_RSP,
510         CB_AVRCP_REG_NOTIF_REQ,
511         CB_AVRCP_REG_NOTIF_RSP,
512         CB_AVRCP_GET_ATTR_REQ,
513         CB_AVRCP_GET_ATTR_RSP,
514
515         /* Gatt client */
516         CB_GATTC_REGISTER_CLIENT,
517         CB_GATTC_SCAN_RESULT,
518         CB_GATTC_OPEN,
519         CB_GATTC_CLOSE,
520         CB_GATTC_SEARCH_COMPLETE,
521         CB_GATTC_SEARCH_RESULT,
522         CB_GATTC_GET_CHARACTERISTIC,
523         CB_GATTC_GET_DESCRIPTOR,
524         CB_GATTC_GET_INCLUDED_SERVICE,
525         CB_GATTC_REGISTER_FOR_NOTIFICATION,
526         CB_GATTC_NOTIFY,
527         CB_GATTC_READ_CHARACTERISTIC,
528         CB_GATTC_WRITE_CHARACTERISTIC,
529         CB_GATTC_READ_DESCRIPTOR,
530         CB_GATTC_WRITE_DESCRIPTOR,
531         CB_GATTC_EXECUTE_WRITE,
532         CB_GATTC_READ_REMOTE_RSSI,
533         CB_GATTC_LISTEN,
534
535         /* Gatt server */
536         CB_GATTS_REGISTER_SERVER,
537         CB_GATTS_CONNECTION,
538         CB_GATTS_SERVICE_ADDED,
539         CB_GATTS_INCLUDED_SERVICE_ADDED,
540         CB_GATTS_CHARACTERISTIC_ADDED,
541         CB_GATTS_DESCRIPTOR_ADDED,
542         CB_GATTS_SERVICE_STARTED,
543         CB_GATTS_SERVICE_STOPPED,
544         CB_GATTS_SERVICE_DELETED,
545         CB_GATTS_REQUEST_READ,
546         CB_GATTS_REQUEST_WRITE,
547         CB_GATTS_REQUEST_EXEC_WRITE,
548         CB_GATTS_RESPONSE_CONFIRMATION,
549         CB_GATTS_INDICATION_SEND,
550
551         /* Map client */
552         CB_MAP_CLIENT_REMOTE_MAS_INSTANCES,
553
554         /* Emulator callbacks */
555         CB_EMU_CONFIRM_SEND_DATA,
556         CB_EMU_ENCRYPTION_ENABLED,
557         CB_EMU_ENCRYPTION_DISABLED,
558         CB_EMU_CONNECTION_REJECTED,
559         CB_EMU_VALUE_INDICATION,
560         CB_EMU_VALUE_NOTIFICATION,
561         CB_EMU_READ_RESPONSE,
562         CB_EMU_WRITE_RESPONSE,
563         CB_EMU_ATT_ERROR,
564 } expected_bt_callback_t;
565
566 struct test_data {
567         struct mgmt *mgmt;
568         audio_hw_device_t *audio;
569         struct hw_device_t *device;
570         struct hciemu *hciemu;
571         enum hciemu_type hciemu_type;
572
573         const bt_interface_t *if_bluetooth;
574         const btsock_interface_t *if_sock;
575         const bthh_interface_t *if_hid;
576         const btpan_interface_t *if_pan;
577         const bthl_interface_t *if_hdp;
578         const btav_interface_t *if_a2dp;
579         struct audio_stream_out *if_stream;
580         const btrc_interface_t *if_avrcp;
581         const btgatt_interface_t *if_gatt;
582         const btmce_interface_t *if_map_client;
583
584         const void *test_data;
585         struct queue *steps;
586
587         guint signalfd;
588         uint16_t mgmt_index;
589         pid_t bluetoothd_pid;
590
591         struct queue *pdus;
592 };
593
594 /*
595  * Struct holding bluetooth HAL action parameters
596  */
597 struct bt_action_data {
598         bt_bdaddr_t *addr;
599
600         /* Remote props action arguments */
601         const int prop_type;
602         const bt_property_t *prop;
603
604         /* Bonding requests parameters */
605         bt_pin_code_t *pin;
606         const uint8_t pin_len;
607         const uint8_t ssp_variant;
608         const bool accept;
609         const uint16_t io_cap;
610
611         /* Socket HAL specific params */
612         const btsock_type_t sock_type;
613         const int channel;
614         const uint8_t *service_uuid;
615         const char *service_name;
616         const int flags;
617         int *fd;
618
619         /* HidHost params */
620         const int report_size;
621
622         /*Connection params*/
623         const uint8_t bearer_type;
624         const uint8_t transport_type;
625 };
626
627 /* bthost's l2cap server setup parameters */
628 struct emu_set_l2cap_data {
629         const uint16_t psm;
630         const bthost_l2cap_connect_cb func;
631         void *user_data;
632 };
633
634 struct emu_l2cap_cid_data {
635         const struct pdu_set *pdu;
636
637         uint16_t handle;
638         uint16_t cid;
639         bool is_sdp;
640 };
641
642 struct map_inst_data {
643         int32_t id;
644         int32_t scn;
645         int32_t msg_types;
646         int32_t name_len;
647         uint8_t *name;
648 };
649
650 /*
651  * Callback data structure should be enhanced with data
652  * returned by callbacks. It's used for test case step
653  * matching with expected step data.
654  */
655 struct bt_callback_data {
656         bt_state_t state;
657         bt_status_t status;
658         int num_properties;
659         bt_property_t *properties;
660         bt_uuid_t *uuid;
661
662         bt_ssp_variant_t pairing_variant;
663
664         bthh_protocol_mode_t mode;
665         int report_size;
666
667         bool adv_data;
668
669         int gatt_app_id;
670         int conn_id;
671         int trans_id;
672         int offset;
673         bool is_long;
674         int connected;
675         uint16_t *attr_handle;
676         uint16_t *srvc_handle;
677         uint16_t *inc_srvc_handle;
678         uint16_t *char_handle;
679         uint16_t *desc_handle;
680         btgatt_srvc_id_t *service;
681         btgatt_gatt_id_t *characteristic;
682         btgatt_gatt_id_t *descriptor;
683         btgatt_srvc_id_t *included;
684         btgatt_read_params_t *read_params;
685         btgatt_write_params_t *write_params;
686         btgatt_notify_params_t *notify_params;
687         int notification_registered;
688         int char_prop;
689         int length;
690         uint8_t *value;
691         bool need_rsp;
692         bool is_prep;
693         uint8_t error;
694
695         btpan_control_state_t ctrl_state;
696         btpan_connection_state_t conn_state;
697         int local_role;
698         int remote_role;
699
700         int app_id;
701         int channel_id;
702         int mdep_cfg_index;
703         bthl_app_reg_state_t app_state;
704         bthl_channel_state_t channel_state;
705
706         btav_connection_state_t av_conn_state;
707         btav_audio_state_t av_audio_state;
708         uint32_t song_length;
709         uint32_t song_position;
710         btrc_play_status_t play_status;
711         uint64_t rc_index;
712         uint8_t num_of_attrs;
713         btrc_element_attr_val_t *attrs;
714
715         int num_mas_instances;
716         btmce_mas_instance_t *mas_instances;
717 };
718
719 /*
720  * Step structure contains expected step data and step
721  * action, which should be performed before step check.
722  */
723 struct step {
724         void (*action)(void);
725         int action_status;
726
727         expected_bt_callback_t callback;
728         struct bt_callback_data callback_result;
729
730         void *set_data;
731         void *set_data_2;
732         void *set_data_3;
733         int set_data_len;
734
735         uint16_t *store_srvc_handle;
736         uint16_t *store_char_handle;
737         uint16_t *store_desc_handle;
738 };
739
740 struct test_case {
741         const uint8_t emu_type;
742         const char *title;
743         const uint16_t step_num;
744         const struct step *step;
745 };
746
747 void tester_handle_l2cap_data_exchange(struct emu_l2cap_cid_data *cid_data);
748 void tester_generic_connect_cb(uint16_t handle, uint16_t cid, void *user_data);
749
750 /* Get, remove test cases API */
751 struct queue *get_bluetooth_tests(void);
752 void remove_bluetooth_tests(void);
753 struct queue *get_socket_tests(void);
754 void remove_socket_tests(void);
755 struct queue *get_hidhost_tests(void);
756 void remove_hidhost_tests(void);
757 struct queue *get_pan_tests(void);
758 void remove_pan_tests(void);
759 struct queue *get_hdp_tests(void);
760 void remove_hdp_tests(void);
761 struct queue *get_a2dp_tests(void);
762 void remove_a2dp_tests(void);
763 struct queue *get_avrcp_tests(void);
764 void remove_avrcp_tests(void);
765 struct queue *get_gatt_tests(void);
766 void remove_gatt_tests(void);
767 struct queue *get_map_client_tests(void);
768 void remove_map_client_tests(void);
769
770 /* Generic tester API */
771 void schedule_action_verification(struct step *step);
772 void schedule_callback_verification(struct step *step);
773
774 /* Emulator actions */
775 void emu_setup_powered_remote_action(void);
776 void emu_set_pin_code_action(void);
777 void emu_set_ssp_mode_action(void);
778 void emu_set_connect_cb_action(void);
779 void emu_remote_connect_hci_action(void);
780 void emu_remote_disconnect_hci_action(void);
781 void emu_set_io_cap(void);
782 void emu_add_l2cap_server_action(void);
783 void emu_add_rfcomm_server_action(void);
784
785 /* Actions */
786 void dummy_action(void);
787 void bluetooth_enable_action(void);
788 void bluetooth_disable_action(void);
789 void bt_set_property_action(void);
790 void bt_get_property_action(void);
791 void bt_start_discovery_action(void);
792 void bt_cancel_discovery_action(void);
793 void bt_get_device_props_action(void);
794 void bt_get_device_prop_action(void);
795 void bt_set_device_prop_action(void);
796 void bt_create_bond_action(void);
797 void bt_pin_reply_accept_action(void);
798 void bt_ssp_reply_accept_action(void);
799 void bt_cancel_bond_action(void);
800 void bt_remove_bond_action(void);
801 void set_default_ssp_request_handler(void);