Upgrade bluez5_37 :Merge the code from private
[platform/upstream/bluez.git] / android / tester-hdp.c
1 /*
2  * Copyright (C) 2014 Intel Corporation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <stdlib.h>
19 #include <stdbool.h>
20
21 #include "emulator/bthost.h"
22 #include "lib/bluetooth.h"
23 #include "android/utils.h"
24 #include "src/shared/tester.h"
25 #include "src/shared/queue.h"
26 #include "tester-main.h"
27
28 typedef enum {
29         HDP_APP_SINK_RELIABLE,
30         HDP_APP_SINK_STREAM,
31         HDP_APP_SOURCE_RELIABLE,
32         HDP_APP_SOURCE_STREAM,
33 } hdp_app_reg_type;
34
35 #define hdp_rsp_pdu     0x07, \
36                         0x00, 0x00, \
37                         0x01, 0xc8, \
38                         0x01, 0xc5, \
39                         0x36, 0x01, 0xc2, 0x36, 0x01, 0xbf, 0x09, 0x00, 0x00, \
40                         0x0a, 0x00, 0x01, 0x00, 0x00, 0x09, 0x00, 0x01, 0x35, \
41                         0x03, 0x19, 0x14, 0x01, 0x09, 0x00, 0x04, 0x35, 0x10, \
42                         0x35, 0x06, 0x19, 0x01, 0x00, 0x09, 0x10, 0x01, 0x35, \
43                         0x06, 0x19, 0x00, 0x1e, 0x09, 0x01, 0x00, 0x09, 0x00, \
44                         0x09, 0x35, 0x08, 0x35, 0x06, 0x19, 0x14, 0x00, 0x09, \
45                         0x01, 0x01, 0x09, 0x00, 0x0d, 0x35, 0x0f, 0x35, 0x0d, \
46                         0x35, 0x06, 0x19, 0x01, 0x00, 0x09, 0x10, 0x03, 0x35, \
47                         0x03, 0x19, 0x00, 0x1f, 0x09, 0x01, 0x00, 0x25, 0x03, \
48                         0x48, 0x44, 0x50, 0x09, 0x01, 0x01, 0x25, 0x28, 0x43, \
49                         0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x2c, 0x20, 0x64, \
50                         0x69, 0x73, 0x70, 0x6c, 0x61, 0x79, 0x2c, 0x20, 0x61, \
51                         0x6e, 0x64, 0x20, 0x72, 0x65, 0x8b, 0x6c, 0x61, 0x79, \
52                         0x20, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x20, 0x64, \
53                         0x61, 0x74, 0x61, 0x09, 0x01, 0x02, 0x25, 0x0d, 0x42, \
54                         0x4c, 0x55, 0x45, 0x54, 0x4f, 0x4f, 0x54, 0x48, 0x20, \
55                         0x53, 0x49, 0x47, 0x09, 0x02, 0x00, 0x36, 0x01, 0x22, \
56                         0x35, 0x18, 0x08, 0x01, 0x09, 0x10, 0x04, 0x08, 0x00, \
57                         0x25, 0x0f, 0x50, 0x75, 0x6c, 0x73, 0x65, 0x20, 0x4f, \
58                         0x78, 0x69, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x0d, 0x35, \
59                         0x20, 0x08, 0x02, 0x09, 0x10, 0x07, 0x08, 0x00, 0x25, \
60                         0x17, 0x42, 0x6c, 0x6f, 0x6f, 0x64, 0x20, 0x50, 0x72, \
61                         0x65, 0x73, 0x73, 0x75, 0x72, 0x65, 0x20, 0x4d, 0x6f, \
62                         0x6e, 0x69, 0x74, 0x6f, 0x72, 0x0d, 0x35, 0x1a, 0x08, \
63                         0x03, 0x09, 0x10, 0x08, 0x08, 0x00, 0x25, 0x11, 0x42, \
64                         0x6f, 0x64, 0x79, 0x20, 0x54, 0x68, 0x65, 0x72, 0x6d, \
65                         0x6f, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x0d, 0x35, 0x1e, \
66                         0x08, 0x04, 0x09, 0x10, 0x0f, 0x08, 0x00, 0x25, 0x15, \
67                         0x42, 0x6f, 0x64, 0x79, 0x20, 0x57, 0x65, 0x69, 0x67, \
68                         0x68, 0x74, 0x20, 0x53, 0x63, 0x61, 0x6c, 0x65, 0x09, \
69                         0x09, 0x09, 0x0d, 0x35, 0x17, 0x08, 0x05, 0x09, 0x10, \
70                         0x11, 0x08, 0x00, 0x25, 0x0e, 0x47, 0x6c, 0x75, 0x63, \
71                         0x6f, 0x73, 0x65, 0x20, 0x4d, 0x65, 0x74, 0x65, 0x72, \
72                         0x0d, 0x35, 0x18, 0x08, 0x06, 0x09, 0x10, 0x04, 0x08, \
73                         0x01, 0x25, 0x0f, 0x50, 0x75, 0x6c, 0x73, 0x65, 0x20, \
74                         0x4f, 0x78, 0x69, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x0d, \
75                         0x35, 0x20, 0x08, 0x07, 0x09, 0x10, 0x07, 0x08, 0x01, \
76                         0x25, 0x17, 0x42, 0x6c, 0x6f, 0x6f, 0x64, 0x20, 0x50, \
77                         0x72, 0x65, 0x73, 0x73, 0x75, 0x72, 0x65, 0x20, 0x4d, \
78                         0x6f, 0x6e, 0x69, 0x74, 0x6f, 0x72, 0x0d, 0x35, 0x1a, \
79                         0x08, 0x08, 0x09, 0x10, 0x08, 0x08, 0x01, 0x25, 0x11, \
80                         0x42, 0x6f, 0x64, 0x79, 0x20, 0x54, 0x68, 0x65, 0x72, \
81                         0x6d, 0x6f, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x0d, 0x35, \
82                         0x1e, 0x08, 0x09, 0x09, 0x10, 0x0f, 0x08, 0x01, 0x25, \
83                         0x15, 0x42, 0x6f, 0x64, 0x79, 0x20, 0x57, 0x65, 0x69, \
84                         0x67, 0x68, 0x74, 0x20, 0x53, 0x63, 0x61, 0x6c, 0x65, \
85                         0x09, 0x09, 0x09, 0x0d, 0x35, 0x17, 0x08, 0x0a, 0x09, \
86                         0x10, 0x11, 0x08, 0x01, 0x25, 0x0e, 0x47, 0x6c, 0x75, \
87                         0x63, 0x6f, 0x73, 0x65, 0x20, 0x4d, 0x65, 0x74, 0x65, \
88                         0x72, 0x0d, 0x09, 0x03, 0x01, 0x08, 0x01, 0x09, 0x03, \
89                         0x02, 0x08, 0x00, \
90                         0x00
91
92 static const struct pdu_set sdp_pdus[] = {
93         { end_pdu, raw_pdu(hdp_rsp_pdu) },
94         { end_pdu, end_pdu },
95 };
96
97 static struct emu_l2cap_cid_data sdp_cid_data = {
98         .pdu = sdp_pdus,
99         .is_sdp = TRUE,
100 };
101
102 static struct emu_l2cap_cid_data ctrl_cid_data;
103 static struct emu_l2cap_cid_data data_cid_data;
104
105 static struct queue *list; /* List of hdp test cases */
106
107 static bthl_reg_param_t *create_app(hdp_app_reg_type type)
108 {
109         bthl_reg_param_t *reg;
110         bthl_mdep_cfg_t mdep1, mdep2;
111
112         reg = malloc(sizeof(bthl_reg_param_t));
113         reg->application_name = "bluez-android";
114         reg->provider_name = "Bluez";
115         reg->srv_name = "bluez-hdp";
116         reg->srv_desp = "health-device-profile";
117
118         mdep1.data_type = 4100;
119         mdep1.mdep_description = "pulse-oximeter";
120
121         mdep2.data_type = 4100;
122         mdep2.mdep_description = "pulse-oximeter";
123
124         switch (type) {
125         case HDP_APP_SINK_RELIABLE:
126                 reg->number_of_mdeps = 1;
127                 mdep1.mdep_role = BTHL_MDEP_ROLE_SINK;
128                 mdep1.channel_type = BTHL_CHANNEL_TYPE_RELIABLE;
129                 reg->mdep_cfg = malloc(reg->number_of_mdeps *
130                                                 sizeof(bthl_mdep_cfg_t));
131                 reg->mdep_cfg[0] = mdep1;
132                 break;
133
134         case HDP_APP_SINK_STREAM:
135                 reg->number_of_mdeps = 2;
136
137                 mdep1.mdep_role = BTHL_MDEP_ROLE_SINK;
138                 mdep1.channel_type = BTHL_CHANNEL_TYPE_RELIABLE;
139
140                 mdep2.mdep_role = BTHL_MDEP_ROLE_SINK;
141                 mdep2.channel_type = BTHL_CHANNEL_TYPE_STREAMING;
142
143                 reg->mdep_cfg = malloc(reg->number_of_mdeps *
144                                                 sizeof(bthl_mdep_cfg_t));
145                 reg->mdep_cfg[0] = mdep1;
146                 reg->mdep_cfg[1] = mdep2;
147                 break;
148
149         case HDP_APP_SOURCE_RELIABLE:
150                 reg->number_of_mdeps = 1;
151
152                 mdep1.mdep_role = BTHL_MDEP_ROLE_SOURCE;
153                 mdep1.channel_type = BTHL_CHANNEL_TYPE_RELIABLE;
154
155                 reg->mdep_cfg = malloc(reg->number_of_mdeps *
156                                                 sizeof(bthl_mdep_cfg_t));
157                 reg->mdep_cfg[0] = mdep1;
158                 break;
159
160         case HDP_APP_SOURCE_STREAM:
161                 reg->number_of_mdeps = 2;
162
163                 mdep1.mdep_role = BTHL_MDEP_ROLE_SOURCE;
164                 mdep1.channel_type = BTHL_CHANNEL_TYPE_RELIABLE;
165
166                 mdep2.mdep_role = BTHL_MDEP_ROLE_SOURCE;
167                 mdep2.channel_type = BTHL_CHANNEL_TYPE_STREAMING;
168
169                 reg->mdep_cfg = malloc(reg->number_of_mdeps *
170                                                 sizeof(bthl_mdep_cfg_t));
171                 reg->mdep_cfg[0] = mdep1;
172                 reg->mdep_cfg[1] = mdep2;
173                 break;
174         }
175
176
177         return reg;
178 }
179
180 static void hdp_register_sink_reliable_app_action(void)
181 {
182         struct test_data *data = tester_get_data();
183         struct step *step = g_new0(struct step, 1);
184         int app_id = 0;
185         bthl_reg_param_t *reg;
186
187         reg = create_app(HDP_APP_SINK_RELIABLE);
188         step->action_status = data->if_hdp->register_application(reg, &app_id);
189
190         schedule_action_verification(step);
191         free(reg->mdep_cfg);
192         free(reg);
193 }
194
195 static void hdp_register_sink_stream_app_action(void)
196 {
197         struct test_data *data = tester_get_data();
198         struct step *step = g_new0(struct step, 1);
199         int app_id = 0;
200         bthl_reg_param_t *reg;
201
202         reg = create_app(HDP_APP_SINK_STREAM);
203         step->action_status = data->if_hdp->register_application(reg, &app_id);
204
205         schedule_action_verification(step);
206         free(reg->mdep_cfg);
207         free(reg);
208 }
209
210 static void hdp_register_source_reliable_app_action(void)
211 {
212         struct test_data *data = tester_get_data();
213         struct step *step = g_new0(struct step, 1);
214         int app_id = 0;
215         bthl_reg_param_t *reg;
216
217         reg = create_app(HDP_APP_SOURCE_RELIABLE);
218         step->action_status = data->if_hdp->register_application(reg, &app_id);
219
220         schedule_action_verification(step);
221         free(reg->mdep_cfg);
222         free(reg);
223 }
224
225 static void hdp_register_source_stream_app_action(void)
226 {
227         struct test_data *data = tester_get_data();
228         struct step *step = g_new0(struct step, 1);
229         int app_id = 0;
230         bthl_reg_param_t *reg;
231
232         reg = create_app(HDP_APP_SOURCE_STREAM);
233         step->action_status = data->if_hdp->register_application(reg, &app_id);
234
235         schedule_action_verification(step);
236         free(reg->mdep_cfg);
237         free(reg);
238 }
239
240 static void hdp_unregister_app_action(void)
241 {
242         struct test_data *data = tester_get_data();
243         struct step *step = g_new0(struct step, 1);
244
245         step->action_status = data->if_hdp->unregister_application(1);
246
247         schedule_action_verification(step);
248 }
249
250 static void mcap_ctrl_cid_hook_cb(const void *data, uint16_t len,
251                                                         void *user_data)
252 {
253         struct test_data *t_data = tester_get_data();
254         struct bthost *bthost = hciemu_client_get_host(t_data->hciemu);
255         struct emu_l2cap_cid_data *cid_data = user_data;
256         uint8_t crt_rsp[5], del_rsp[4], config;
257         uint8_t opcode = ((uint8_t *) data)[0];
258         static bool reliable = false;
259
260         switch (opcode) {
261         case 0x01: /* MD_CREATE_MDL_REQ */
262                 crt_rsp[0] = 0x02; /* MD_CREATE_MDL_RSP */
263                 crt_rsp[1] = 0x00; /* Response code - Success */
264                 crt_rsp[2] = ((uint8_t *) data)[1]; /* mdlid */
265                 crt_rsp[3] = ((uint8_t *) data)[2];
266                 config = ((uint8_t *) data)[4];
267
268                 if (config == 0x00) {
269                         if (!reliable) {
270                                 crt_rsp[4] = 0x01;
271                                 reliable = true;
272                         } else {
273                                 crt_rsp[4] = 0x02;
274                                 reliable = false;
275                         }
276                 } else {
277                         crt_rsp[4] = config;
278                 }
279
280                 bthost_send_cid(bthost, cid_data->handle,
281                                         cid_data->cid,
282                                         crt_rsp, sizeof(crt_rsp));
283                 break;
284         case 0x03: /* MD_RECONNECT_MDL_REQ */
285         case 0x05: /* MD_ABORT_MDL_REQ */
286                 break;
287         case 0x07: /* MD_DELETE_MDL_REQ */
288                 del_rsp[0] = 0x08; /* MD_DELETE_MDL_RSP */
289                 del_rsp[1] = 0x00; /* Response code - Success */
290                 del_rsp[2] = ((uint8_t *) data)[1]; /* mdlid */
291                 del_rsp[3] = ((uint8_t *) data)[2];
292                 bthost_send_cid(bthost, cid_data->handle,
293                                         cid_data->cid,
294                                         del_rsp, sizeof(del_rsp));
295                 break;
296         }
297 }
298
299 static void mcap_ctrl_connect_cb(uint16_t handle, uint16_t cid, void *user_data)
300 {
301         struct test_data *data = tester_get_data();
302         struct bthost *bthost = hciemu_client_get_host(data->hciemu);
303         struct emu_l2cap_cid_data *cid_data = user_data;
304
305         cid_data->handle = handle;
306         cid_data->cid = cid;
307
308         bthost_add_cid_hook(bthost, handle, cid, mcap_ctrl_cid_hook_cb,
309                                                                 cid_data);
310 }
311
312 /* Emulate SDP (PSM = 1) */
313 static struct emu_set_l2cap_data l2cap_setup_sdp_data = {
314         .psm = 1,
315         .func = tester_generic_connect_cb,
316         .user_data = &sdp_cid_data,
317 };
318
319 /* Emulate Control Channel (PSM = 0x1001) */
320 static struct emu_set_l2cap_data l2cap_setup_cc_data = {
321         .psm = 0x1001,
322         .func = mcap_ctrl_connect_cb,
323         .user_data = &ctrl_cid_data,
324 };
325
326 /* Emulate Data Channel (PSM = 0x1003) */
327 static struct emu_set_l2cap_data l2cap_setup_dc_data = {
328         .psm = 0x1003,
329         .func = tester_generic_connect_cb,
330         .user_data = &data_cid_data,
331 };
332
333 static void hdp_connect_source_reliable_action(void)
334 {
335         struct test_data *data = tester_get_data();
336         const uint8_t *hid_addr = hciemu_get_client_bdaddr(data->hciemu);
337         struct step *step = g_new0(struct step, 1);
338         bt_bdaddr_t bdaddr;
339         int app_id, channel_id, mdep_cfg_index;
340
341         bdaddr2android((const bdaddr_t *) hid_addr, &bdaddr);
342         app_id = 1;
343         mdep_cfg_index = 0;
344         channel_id = 0;
345         step->action_status = data->if_hdp->connect_channel(app_id, &bdaddr,
346                                                 mdep_cfg_index, &channel_id);
347
348         schedule_action_verification(step);
349 }
350
351 static void hdp_destroy_source_reliable_action(void)
352 {
353         struct test_data *data = tester_get_data();
354         struct step *step = g_new0(struct step, 1);
355
356         step->action_status = data->if_hdp->destroy_channel(1);
357         schedule_action_verification(step);
358 }
359
360 static void hdp_connect_sink_reliable_action(void)
361 {
362         struct test_data *data = tester_get_data();
363         const uint8_t *hid_addr = hciemu_get_client_bdaddr(data->hciemu);
364         struct step *step = g_new0(struct step, 1);
365         bt_bdaddr_t bdaddr;
366         int app_id, channel_id, mdep_cfg_index;
367
368         bdaddr2android((const bdaddr_t *) hid_addr, &bdaddr);
369         app_id = 1;
370         mdep_cfg_index = 0;
371         channel_id = 0;
372         step->action_status = data->if_hdp->connect_channel(app_id, &bdaddr,
373                                                 mdep_cfg_index, &channel_id);
374
375         schedule_action_verification(step);
376 }
377
378 static void hdp_connect_sink_stream_action(void)
379 {
380         struct test_data *data = tester_get_data();
381         const uint8_t *hid_addr = hciemu_get_client_bdaddr(data->hciemu);
382         struct step *step = g_new0(struct step, 1);
383         bt_bdaddr_t bdaddr;
384         int app_id, channel_id, mdep_cfg_index;
385
386         bdaddr2android((const bdaddr_t *) hid_addr, &bdaddr);
387         app_id = 1;
388         mdep_cfg_index = 1;
389         channel_id = 0;
390         step->action_status = data->if_hdp->connect_channel(app_id, &bdaddr,
391                                                 mdep_cfg_index, &channel_id);
392
393         schedule_action_verification(step);
394 }
395
396 static void hdp_destroy_sink_reliable_action(void)
397 {
398         struct test_data *data = tester_get_data();
399         struct step *step = g_new0(struct step, 1);
400
401         step->action_status = data->if_hdp->destroy_channel(1);
402         schedule_action_verification(step);
403 }
404
405 static void hdp_destroy_sink_stream_action(void)
406 {
407         struct test_data *data = tester_get_data();
408         struct step *step = g_new0(struct step, 1);
409
410         step->action_status = data->if_hdp->destroy_channel(2);
411         schedule_action_verification(step);
412 }
413
414 static struct test_case test_cases[] = {
415         TEST_CASE_BREDRLE("HDP Init",
416                 ACTION_SUCCESS(dummy_action, NULL),
417         ),
418         TEST_CASE_BREDRLE("HDP Register Sink Reliable Application",
419                 ACTION_SUCCESS(hdp_register_sink_reliable_app_action, NULL),
420                 CALLBACK_HDP_APP_REG_STATE(CB_HDP_APP_REG_STATE, 1,
421                                         BTHL_APP_REG_STATE_REG_SUCCESS),
422         ),
423         TEST_CASE_BREDRLE("HDP Register Sink Stream Application",
424                 ACTION_SUCCESS(hdp_register_sink_stream_app_action, NULL),
425                 CALLBACK_HDP_APP_REG_STATE(CB_HDP_APP_REG_STATE, 1,
426                                         BTHL_APP_REG_STATE_REG_SUCCESS),
427         ),
428         TEST_CASE_BREDRLE("HDP Register Source Reliable Application",
429                 ACTION_SUCCESS(hdp_register_source_reliable_app_action, NULL),
430                 CALLBACK_HDP_APP_REG_STATE(CB_HDP_APP_REG_STATE, 1,
431                                         BTHL_APP_REG_STATE_REG_SUCCESS),
432         ),
433         TEST_CASE_BREDRLE("HDP Register Source Stream Application",
434                 ACTION_SUCCESS(hdp_register_source_stream_app_action, NULL),
435                 CALLBACK_HDP_APP_REG_STATE(CB_HDP_APP_REG_STATE, 1,
436                                         BTHL_APP_REG_STATE_REG_SUCCESS),
437         ),
438         TEST_CASE_BREDRLE("HDP Unegister Application",
439                 ACTION_SUCCESS(hdp_register_source_stream_app_action, NULL),
440                 CALLBACK_HDP_APP_REG_STATE(CB_HDP_APP_REG_STATE, 1,
441                                         BTHL_APP_REG_STATE_REG_SUCCESS),
442                 ACTION_SUCCESS(hdp_unregister_app_action, NULL),
443                 CALLBACK_HDP_APP_REG_STATE(CB_HDP_APP_REG_STATE, 1,
444                                         BTHL_APP_REG_STATE_DEREG_SUCCESS),
445         ),
446         TEST_CASE_BREDRLE("HDP Connect Source Reliable Channel",
447                 ACTION_SUCCESS(set_default_ssp_request_handler, NULL),
448                 ACTION_SUCCESS(bluetooth_enable_action, NULL),
449                 CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
450                 ACTION_SUCCESS(emu_setup_powered_remote_action, NULL),
451                 ACTION_SUCCESS(emu_set_ssp_mode_action, NULL),
452                 ACTION_SUCCESS(emu_add_l2cap_server_action,
453                                                         &l2cap_setup_sdp_data),
454                 ACTION_SUCCESS(emu_add_l2cap_server_action,
455                                                         &l2cap_setup_cc_data),
456                 ACTION_SUCCESS(emu_add_l2cap_server_action,
457                                                         &l2cap_setup_dc_data),
458                 ACTION_SUCCESS(hdp_register_source_reliable_app_action, NULL),
459                 CALLBACK_HDP_APP_REG_STATE(CB_HDP_APP_REG_STATE, 1,
460                                         BTHL_APP_REG_STATE_REG_SUCCESS),
461                 ACTION_SUCCESS(hdp_connect_source_reliable_action, NULL),
462                 CALLBACK_HDP_CHANNEL_STATE(CB_HDP_CHANNEL_STATE, 1, 1, 0,
463                                                 BTHL_CONN_STATE_CONNECTING),
464                 CALLBACK_HDP_CHANNEL_STATE(CB_HDP_CHANNEL_STATE, 1, 1, 0,
465                                                 BTHL_CONN_STATE_CONNECTED),
466         ),
467         TEST_CASE_BREDRLE("HDP Destroy Source Reliable Channel",
468                 ACTION_SUCCESS(set_default_ssp_request_handler, NULL),
469                 ACTION_SUCCESS(bluetooth_enable_action, NULL),
470                 CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
471                 ACTION_SUCCESS(emu_setup_powered_remote_action, NULL),
472                 ACTION_SUCCESS(emu_set_ssp_mode_action, NULL),
473                 ACTION_SUCCESS(emu_add_l2cap_server_action,
474                                                         &l2cap_setup_sdp_data),
475                 ACTION_SUCCESS(emu_add_l2cap_server_action,
476                                                         &l2cap_setup_cc_data),
477                 ACTION_SUCCESS(emu_add_l2cap_server_action,
478                                                         &l2cap_setup_dc_data),
479                 ACTION_SUCCESS(hdp_register_source_reliable_app_action, NULL),
480                 CALLBACK_HDP_APP_REG_STATE(CB_HDP_APP_REG_STATE, 1,
481                                         BTHL_APP_REG_STATE_REG_SUCCESS),
482                 ACTION_SUCCESS(hdp_connect_source_reliable_action, NULL),
483                 CALLBACK_HDP_CHANNEL_STATE(CB_HDP_CHANNEL_STATE, 1, 1, 0,
484                                                 BTHL_CONN_STATE_CONNECTING),
485                 CALLBACK_HDP_CHANNEL_STATE(CB_HDP_CHANNEL_STATE, 1, 1, 0,
486                                                 BTHL_CONN_STATE_CONNECTED),
487                 ACTION_SUCCESS(hdp_destroy_source_reliable_action, NULL),
488                 CALLBACK_HDP_CHANNEL_STATE(CB_HDP_CHANNEL_STATE, 1, 1, 0,
489                                                 BTHL_CONN_STATE_DESTROYED),
490         ),
491         TEST_CASE_BREDRLE("HDP Connect Sink Streaming Channel",
492                 ACTION_SUCCESS(set_default_ssp_request_handler, NULL),
493                 ACTION_SUCCESS(bluetooth_enable_action, NULL),
494                 CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
495                 ACTION_SUCCESS(emu_setup_powered_remote_action, NULL),
496                 ACTION_SUCCESS(emu_set_ssp_mode_action, NULL),
497                 ACTION_SUCCESS(emu_add_l2cap_server_action,
498                                                         &l2cap_setup_sdp_data),
499                 ACTION_SUCCESS(emu_add_l2cap_server_action,
500                                                         &l2cap_setup_cc_data),
501                 ACTION_SUCCESS(emu_add_l2cap_server_action,
502                                                         &l2cap_setup_dc_data),
503                 ACTION_SUCCESS(hdp_register_sink_stream_app_action, NULL),
504                 CALLBACK_HDP_APP_REG_STATE(CB_HDP_APP_REG_STATE, 1,
505                                         BTHL_APP_REG_STATE_REG_SUCCESS),
506                 ACTION_SUCCESS(hdp_connect_sink_reliable_action, NULL),
507                 CALLBACK_HDP_CHANNEL_STATE(CB_HDP_CHANNEL_STATE, 1, 1, 0,
508                                                 BTHL_CONN_STATE_CONNECTING),
509                 CALLBACK_HDP_CHANNEL_STATE(CB_HDP_CHANNEL_STATE, 1, 1, 0,
510                                                 BTHL_CONN_STATE_CONNECTED),
511                 ACTION_SUCCESS(hdp_connect_sink_stream_action, NULL),
512                 CALLBACK_HDP_CHANNEL_STATE(CB_HDP_CHANNEL_STATE, 1, 2, 1,
513                                                 BTHL_CONN_STATE_CONNECTED),
514         ),
515         TEST_CASE_BREDRLE("HDP Destroy Sink Streaming Channel",
516                 ACTION_SUCCESS(set_default_ssp_request_handler, NULL),
517                 ACTION_SUCCESS(bluetooth_enable_action, NULL),
518                 CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
519                 ACTION_SUCCESS(emu_setup_powered_remote_action, NULL),
520                 ACTION_SUCCESS(emu_set_ssp_mode_action, NULL),
521                 ACTION_SUCCESS(emu_add_l2cap_server_action,
522                                                         &l2cap_setup_sdp_data),
523                 ACTION_SUCCESS(emu_add_l2cap_server_action,
524                                                         &l2cap_setup_cc_data),
525                 ACTION_SUCCESS(emu_add_l2cap_server_action,
526                                                         &l2cap_setup_dc_data),
527                 ACTION_SUCCESS(hdp_register_sink_stream_app_action, NULL),
528                 CALLBACK_HDP_APP_REG_STATE(CB_HDP_APP_REG_STATE, 1,
529                                         BTHL_APP_REG_STATE_REG_SUCCESS),
530                 ACTION_SUCCESS(hdp_connect_sink_reliable_action, NULL),
531                 CALLBACK_HDP_CHANNEL_STATE(CB_HDP_CHANNEL_STATE, 1, 1, 0,
532                                                 BTHL_CONN_STATE_CONNECTING),
533                 CALLBACK_HDP_CHANNEL_STATE(CB_HDP_CHANNEL_STATE, 1, 1, 0,
534                                                 BTHL_CONN_STATE_CONNECTED),
535                 ACTION_SUCCESS(hdp_connect_sink_stream_action, NULL),
536                 CALLBACK_HDP_CHANNEL_STATE(CB_HDP_CHANNEL_STATE, 1, 2, 1,
537                                                 BTHL_CONN_STATE_CONNECTED),
538                 ACTION_SUCCESS(hdp_destroy_sink_reliable_action, NULL),
539                 CALLBACK_HDP_CHANNEL_STATE(CB_HDP_CHANNEL_STATE, 1, 1, 0,
540                                                 BTHL_CONN_STATE_DESTROYED),
541                 ACTION_SUCCESS(hdp_destroy_sink_stream_action, NULL),
542                 CALLBACK_HDP_CHANNEL_STATE(CB_HDP_CHANNEL_STATE, 1, 2, 1,
543                                                 BTHL_CONN_STATE_DESTROYED),
544         ),
545 };
546
547 struct queue *get_hdp_tests(void)
548 {
549         uint16_t i = 0;
550
551         list = queue_new();
552
553         for (; i < sizeof(test_cases) / sizeof(test_cases[0]); ++i)
554                 queue_push_tail(list, &test_cases[i]);
555
556         return list;
557 }
558
559 void remove_hdp_tests(void)
560 {
561         queue_destroy(list, NULL);
562 }