OSDN Git Service

Add RTL8723BS Bluetooth tool
[android-x86/external-bluetooth-bluez.git] / unit / test-avdtp.c
1 /*
2  *
3  *  BlueZ - Bluetooth protocol stack for Linux
4  *
5  *  Copyright (C) 2012  Intel Corporation. All rights reserved.
6  *
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program 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
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21  *
22  */
23
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27
28 #include <unistd.h>
29 #include <stdlib.h>
30 #include <stdbool.h>
31 #include <inttypes.h>
32 #include <string.h>
33 #include <fcntl.h>
34 #include <sys/socket.h>
35
36 #include <glib.h>
37
38 #include "src/shared/util.h"
39 #include "src/shared/queue.h"
40 #include "src/shared/tester.h"
41 #include "src/log.h"
42
43 #include "android/avdtp.h"
44
45 #define MAX_SEID 0x3E
46
47 struct test_pdu {
48         bool valid;
49         bool fragmented;
50         const uint8_t *data;
51         size_t size;
52 };
53
54 struct test_data {
55         char *test_name;
56         struct test_pdu *pdu_list;
57 };
58
59 #define data(args...) ((const unsigned char[]) { args })
60
61 #define raw_pdu(args...) \
62         {                                                       \
63                 .valid = true,                                  \
64                 .data = data(args),                             \
65                 .size = sizeof(data(args)),                     \
66         }
67
68 #define frg_pdu(args...) \
69         {                                                       \
70                 .valid = true,                                  \
71                 .fragmented = true,                             \
72                 .data = data(args),                             \
73                 .size = sizeof(data(args)),                     \
74         }
75
76 #define define_test(name, function, args...) \
77         do {                                                            \
78                 const struct test_pdu pdus[] = {                        \
79                         args, { }                                       \
80                 };                                                      \
81                 static struct test_data data;                           \
82                 data.test_name = g_strdup(name);                        \
83                 data.pdu_list = g_memdup(pdus, sizeof(pdus));           \
84                 tester_add(name, &data, NULL, function, NULL);          \
85         } while (0)
86
87 struct context {
88         struct avdtp *session;
89         struct avdtp_local_sep *sep;
90         struct avdtp_stream *stream;
91         struct queue *lseps;
92         guint source;
93         guint process;
94         int fd;
95         int mtu;
96         gboolean pending_open;
97         gboolean pending_suspend;
98         unsigned int pdu_offset;
99         const struct test_data *data;
100 };
101
102 static void test_debug(const char *str, void *user_data)
103 {
104         const char *prefix = user_data;
105
106         tester_debug("%s%s", prefix, str);
107 }
108
109 static void test_free(gconstpointer user_data)
110 {
111         const struct test_data *data = user_data;
112
113         g_free(data->test_name);
114         g_free(data->pdu_list);
115 }
116
117 static void unregister_sep(void *data)
118 {
119         struct avdtp_local_sep *sep = data;
120
121         /* Removed from the queue by caller */
122         avdtp_unregister_sep(NULL, sep);
123 }
124
125 static void destroy_context(struct context *context)
126 {
127         if (context->source > 0)
128                 g_source_remove(context->source);
129         avdtp_unref(context->session);
130
131         test_free(context->data);
132         queue_destroy(context->lseps, unregister_sep);
133
134         g_free(context);
135 }
136
137 static gboolean context_quit(gpointer user_data)
138 {
139         struct context *context = user_data;
140
141         if (context->process > 0)
142                 g_source_remove(context->process);
143
144         destroy_context(context);
145
146         tester_test_passed();
147
148         return FALSE;
149 }
150
151 static gboolean send_pdu(gpointer user_data)
152 {
153         struct context *context = user_data;
154         const struct test_pdu *pdu;
155         ssize_t len;
156
157         pdu = &context->data->pdu_list[context->pdu_offset++];
158
159         len = write(context->fd, pdu->data, pdu->size);
160
161         util_hexdump('<', pdu->data, len, test_debug, "AVDTP: ");
162
163         g_assert_cmpint(len, ==, pdu->size);
164
165         if (g_str_equal(context->data->test_name, "/TP/SIG/SMG/BI-02-C"))
166                 g_timeout_add_seconds(1, context_quit, context);
167
168         if (pdu->fragmented)
169                 return send_pdu(user_data);
170
171         context->process = 0;
172         return FALSE;
173 }
174
175 static void context_process(struct context *context)
176 {
177         if (!context->data->pdu_list[context->pdu_offset].valid) {
178                 context_quit(context);
179                 return;
180         }
181
182         context->process = g_idle_add(send_pdu, context);
183 }
184
185 static gboolean transport_open(struct avdtp_stream *stream)
186 {
187         int fd;
188
189         fd = open("/dev/null", O_RDWR, 0);
190         if (fd < 0)
191                 g_assert_not_reached();
192
193         return avdtp_stream_set_transport(stream, fd, 672, 672);
194 }
195
196 static gboolean test_handler(GIOChannel *channel, GIOCondition cond,
197                                                         gpointer user_data)
198 {
199         struct context *context = user_data;
200         const struct test_pdu *pdu;
201         unsigned char buf[512];
202         ssize_t len;
203         int fd;
204
205         pdu = &context->data->pdu_list[context->pdu_offset++];
206
207         if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) {
208                 context->source = 0;
209                 return FALSE;
210         }
211
212         fd = g_io_channel_unix_get_fd(channel);
213
214         len = read(fd, buf, sizeof(buf));
215
216         g_assert(len > 0);
217
218         util_hexdump('>', buf, len, test_debug, "AVDTP: ");
219
220         g_assert_cmpint(len, ==, pdu->size);
221
222         g_assert(memcmp(buf, pdu->data, pdu->size) == 0);
223
224         if (context->pending_open) {
225                 context->pending_open = FALSE;
226                 g_assert(transport_open(context->stream));
227         }
228
229         if (context->pending_suspend) {
230                 int ret;
231
232                 context->pending_suspend = FALSE;
233                 ret = avdtp_suspend(context->session, context->stream);
234                 g_assert_cmpint(ret, ==, 0);
235         }
236
237         if (!pdu->fragmented)
238                 context_process(context);
239
240         return TRUE;
241 }
242
243 static struct context *context_new(uint16_t version, uint16_t imtu,
244                                         uint16_t omtu, gconstpointer data)
245 {
246         struct context *context = g_new0(struct context, 1);
247         GIOChannel *channel;
248         int err, sv[2];
249
250         err = socketpair(AF_UNIX, SOCK_SEQPACKET | SOCK_CLOEXEC, 0, sv);
251         g_assert(err == 0);
252
253         context->lseps = queue_new();
254         g_assert(context->lseps);
255
256         context->session = avdtp_new(sv[0], imtu, omtu, version,
257                                                                 context->lseps);
258         g_assert(context->session != NULL);
259
260         channel = g_io_channel_unix_new(sv[1]);
261
262         g_io_channel_set_close_on_unref(channel, TRUE);
263         g_io_channel_set_encoding(channel, NULL, NULL);
264         g_io_channel_set_buffered(channel, FALSE);
265
266         context->source = g_io_add_watch(channel,
267                                 G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
268                                 test_handler, context);
269         g_assert(context->source > 0);
270
271         g_io_channel_unref(channel);
272
273         context->fd = sv[1];
274         context->data = data;
275
276         return context;
277 }
278
279 static struct context *create_context(uint16_t version, gconstpointer data)
280 {
281         return context_new(version, 672, 672, data);
282 }
283
284 static gboolean sep_getcap_ind(struct avdtp *session,
285                                         struct avdtp_local_sep *sep,
286                                         GSList **caps, uint8_t *err,
287                                         void *user_data)
288 {
289         struct avdtp_service_capability *media_transport, *media_codec;
290         struct avdtp_media_codec_capability *codec_caps;
291         uint8_t cap[4] = { 0xff, 0xff, 2, 64 };
292
293         *caps = NULL;
294
295         media_transport = avdtp_service_cap_new(AVDTP_MEDIA_TRANSPORT,
296                                                 NULL, 0);
297
298         *caps = g_slist_append(*caps, media_transport);
299
300         codec_caps = g_malloc0(sizeof(*codec_caps) + sizeof(cap));
301         codec_caps->media_type = AVDTP_MEDIA_TYPE_AUDIO;
302         codec_caps->media_codec_type = 0x00;
303         memcpy(codec_caps->data, cap, sizeof(cap));
304
305         media_codec = avdtp_service_cap_new(AVDTP_MEDIA_CODEC, codec_caps,
306                                         sizeof(*codec_caps) + sizeof(cap));
307
308         *caps = g_slist_append(*caps, media_codec);
309         g_free(codec_caps);
310
311         return TRUE;
312 }
313
314 static gboolean sep_open_ind(struct avdtp *session, struct avdtp_local_sep *sep,
315                                 struct avdtp_stream *stream, uint8_t *err,
316                                 void *user_data)
317 {
318         struct context *context = user_data;
319
320         if (g_str_equal(context->data->test_name, "/TP/SIG/SMG/BI-18-C")) {
321                 *err = 0xc0;
322                 return FALSE;
323         }
324
325         context->pending_open = TRUE;
326         context->stream = stream;
327
328         return TRUE;
329 }
330
331 static gboolean sep_setconf_ind(struct avdtp *session,
332                                                 struct avdtp_local_sep *sep,
333                                                 struct avdtp_stream *stream,
334                                                 GSList *caps,
335                                                 avdtp_set_configuration_cb cb,
336                                                 void *user_data)
337 {
338         struct context *context = user_data;
339
340         if (g_str_equal(context->data->test_name, "/TP/SIG/SMG/BI-09-C"))
341                 return FALSE;
342
343         cb(session, stream, NULL);
344
345         return TRUE;
346 }
347
348 static gboolean sep_start_ind(struct avdtp *session,
349                                                 struct avdtp_local_sep *sep,
350                                                 struct avdtp_stream *stream,
351                                                 uint8_t *err,
352                                                 void *user_data)
353 {
354         struct context *context = user_data;
355
356         if (g_str_equal(context->data->test_name, "/TP/SIG/SMG/BI-21-C")) {
357                 *err = 0xc0;
358                 return FALSE;
359         }
360
361         if (g_str_equal(context->data->test_name, "/TP/SIG/SMG/BI-25-C"))
362                 context->pending_suspend = TRUE;
363
364         return TRUE;
365 }
366
367 static gboolean sep_close_ind(struct avdtp *session,
368                                                 struct avdtp_local_sep *sep,
369                                                 struct avdtp_stream *stream,
370                                                 uint8_t *err,
371                                                 void *user_data)
372 {
373         struct context *context = user_data;
374
375         if (g_str_equal(context->data->test_name, "/TP/SIG/SMG/BI-24-C")) {
376                 *err = 0xc0;
377                 return FALSE;
378         }
379
380         return TRUE;
381 }
382
383 static gboolean sep_suspend_ind(struct avdtp *session,
384                                                 struct avdtp_local_sep *sep,
385                                                 struct avdtp_stream *stream,
386                                                 uint8_t *err,
387                                                 void *user_data)
388 {
389         struct context *context = user_data;
390
391         if (g_str_equal(context->data->test_name, "/TP/SIG/SMG/BI-27-C")) {
392                 *err = 0xc0;
393                 return FALSE;
394         }
395
396         return TRUE;
397 }
398
399 static struct avdtp_sep_ind sep_ind = {
400         .get_capability         = sep_getcap_ind,
401         .set_configuration      = sep_setconf_ind,
402         .open                   = sep_open_ind,
403         .close                  = sep_close_ind,
404         .start                  = sep_start_ind,
405         .suspend                = sep_suspend_ind,
406 };
407
408 static void sep_setconf_cfm(struct avdtp *session, struct avdtp_local_sep *sep,
409                                 struct avdtp_stream *stream,
410                                 struct avdtp_error *err, void *user_data)
411 {
412         struct context *context = user_data;
413         int ret;
414
415         if (g_str_equal(context->data->test_name, "/TP/SIG/SMG/BV-09-C")) {
416                 context_quit(context);
417                 return;
418         }
419
420         if (g_str_equal(context->data->test_name, "/TP/SIG/SMG/BI-07-C")) {
421                 g_assert(err != NULL);
422                 g_assert_cmpint(avdtp_error_error_code(err), ==, 0x13);
423                 context_quit(context);
424                 return;
425         }
426
427         g_assert(err == NULL);
428
429         if (g_str_equal(context->data->test_name, "/TP/SIG/SMG/BV-11-C") ||
430                 g_str_equal(context->data->test_name, "/TP/SIG/SMG/BI-10-C"))
431                 ret = avdtp_get_configuration(session, stream);
432         else if (g_str_equal(context->data->test_name, "/TP/SIG/SMG/BV-23-C"))
433                 ret = avdtp_abort(session, stream);
434         else
435                 ret = avdtp_open(session, stream);
436
437         g_assert_cmpint(ret, ==, 0);
438 }
439
440 static void sep_getconf_cfm(struct avdtp *session, struct avdtp_local_sep *sep,
441                                 struct avdtp_stream *stream,
442                                 struct avdtp_error *err, void *user_data)
443 {
444         struct context *context = user_data;
445
446         if (g_str_equal(context->data->test_name, "/TP/SIG/SMG/BI-10-C")) {
447                 g_assert(err != NULL);
448                 g_assert_cmpint(avdtp_error_error_code(err), ==, 0x12);
449         } else
450                 g_assert(err == NULL);
451
452         context_quit(context);
453 }
454
455 static void sep_open_cfm(struct avdtp *session, struct avdtp_local_sep *sep,
456                         struct avdtp_stream *stream, struct avdtp_error *err,
457                         void *user_data)
458 {
459         int ret;
460
461         g_assert(err == NULL);
462
463         g_assert(transport_open(stream));
464
465         ret = avdtp_start(session, stream);
466         g_assert_cmpint(ret, ==, 0);
467 }
468
469 static void sep_start_cfm(struct avdtp *session, struct avdtp_local_sep *sep,
470                         struct avdtp_stream *stream, struct avdtp_error *err,
471                         void *user_data)
472 {
473         struct context *context = user_data;
474         int ret;
475
476         if (g_str_equal(context->data->test_name, "/TP/SIG/SMG/BI-19-C") ||
477                 g_str_equal(context->data->test_name, "/TP/SIG/SMG/BI-22-C")) {
478                 g_assert(err != NULL);
479                 g_assert_cmpint(avdtp_error_error_code(err), ==, 0x31);
480                 context_quit(context);
481                 return;
482         }
483
484         g_assert(err == NULL);
485
486         if (g_str_equal(context->data->test_name, "/TP/SIG/SMG/BV-19-C"))
487                 ret = avdtp_close(session, stream, FALSE);
488         else
489                 ret = avdtp_suspend(session, stream);
490
491         g_assert_cmpint(ret, ==, 0);
492 }
493
494 static void sep_suspend_cfm(struct avdtp *session, struct avdtp_local_sep *sep,
495                         struct avdtp_stream *stream, struct avdtp_error *err,
496                         void *user_data)
497 {
498         struct context *context = user_data;
499
500         if (g_str_equal(context->data->test_name, "/TP/SIG/SMG/BI-25-C")) {
501                 g_assert(err != NULL);
502                 g_assert_cmpint(avdtp_error_error_code(err), ==, 0x31);
503                 context_quit(context);
504         }
505 }
506
507 static struct avdtp_sep_cfm sep_cfm = {
508         .set_configuration      = sep_setconf_cfm,
509         .get_configuration      = sep_getconf_cfm,
510         .open                   = sep_open_cfm,
511         .start                  = sep_start_cfm,
512         .suspend                = sep_suspend_cfm,
513 };
514
515 static void test_server(gconstpointer data)
516 {
517         struct context *context = create_context(0x0100, data);
518         struct avdtp_local_sep *sep;
519
520         sep = avdtp_register_sep(context->lseps, AVDTP_SEP_TYPE_SOURCE,
521                                         AVDTP_MEDIA_TYPE_AUDIO,
522                                         0x00, FALSE, &sep_ind, &sep_cfm,
523                                         context);
524         g_assert(sep);
525
526         g_idle_add(send_pdu, context);
527 }
528
529 static void test_server_1_3(gconstpointer data)
530 {
531         struct context *context = create_context(0x0103, data);
532         struct avdtp_local_sep *sep;
533
534         sep = avdtp_register_sep(context->lseps, AVDTP_SEP_TYPE_SOURCE,
535                                         AVDTP_MEDIA_TYPE_AUDIO,
536                                         0x00, TRUE, &sep_ind, NULL, context);
537         g_assert(sep);
538
539         g_idle_add(send_pdu, context);
540 }
541
542 static void test_server_1_3_sink(gconstpointer data)
543 {
544         struct context *context = create_context(0x0103, data);
545         struct avdtp_local_sep *sep;
546
547         sep = avdtp_register_sep(context->lseps, AVDTP_SEP_TYPE_SINK,
548                                         AVDTP_MEDIA_TYPE_AUDIO,
549                                         0x00, TRUE, &sep_ind, NULL, context);
550         g_assert(sep);
551
552         g_idle_add(send_pdu, context);
553 }
554
555 static void test_server_0_sep(gconstpointer data)
556 {
557         struct context *context = create_context(0x0100, data);
558
559         g_idle_add(send_pdu, context);
560 }
561
562 static void test_server_seid(gconstpointer data)
563 {
564         struct context *context = create_context(0x0103, data);
565         struct avdtp_local_sep *sep;
566         unsigned int i;
567
568         for (i = 0; i < sizeof(int) * 8; i++) {
569                 sep = avdtp_register_sep(context->lseps, AVDTP_SEP_TYPE_SINK,
570                                                 AVDTP_MEDIA_TYPE_AUDIO,
571                                                 0x00, TRUE, &sep_ind, NULL,
572                                                 context);
573                 g_assert(sep);
574         }
575
576         /* Now add (MAX_SEID + 1) SEP -> it shall fail */
577         sep = avdtp_register_sep(context->lseps, AVDTP_SEP_TYPE_SINK,
578                                                 AVDTP_MEDIA_TYPE_AUDIO,
579                                                 0x00, TRUE, &sep_ind, NULL,
580                                                 context);
581         g_assert(!sep);
582
583         context_quit(context);
584 }
585
586 static void test_server_seid_duplicate(gconstpointer data)
587 {
588         struct context *context = create_context(0x0103, data);
589         struct avdtp_local_sep *sep;
590         int i;
591
592         for (i = 0; i < 2; i++) {
593                 sep = avdtp_register_sep(context->lseps, AVDTP_SEP_TYPE_SINK,
594                                                 AVDTP_MEDIA_TYPE_AUDIO,
595                                                 0x00, TRUE, &sep_ind, NULL,
596                                                 context);
597                 g_assert(sep);
598         }
599
600         /* Remove 1st element */
601         sep = queue_peek_head(context->lseps);
602         g_assert(sep);
603
604         avdtp_unregister_sep(context->lseps, sep);
605
606         /* Now register new element */
607         sep = avdtp_register_sep(context->lseps, AVDTP_SEP_TYPE_SINK,
608                                                 AVDTP_MEDIA_TYPE_AUDIO,
609                                                 0x00, TRUE, &sep_ind, NULL,
610                                                 context);
611         g_assert(sep);
612
613         /* Check SEID ids with DISCOVER */
614
615         g_idle_add(send_pdu, context);
616 }
617
618 static gboolean sep_getcap_ind_frg(struct avdtp *session,
619                                         struct avdtp_local_sep *sep,
620                                         GSList **caps, uint8_t *err,
621                                         void *user_data)
622 {
623         struct avdtp_service_capability *media_transport, *media_codec;
624         struct avdtp_service_capability *content_protection;
625         struct avdtp_media_codec_capability *codec_caps;
626         uint8_t cap[4] = { 0xff, 0xff, 2, 64 };
627         uint8_t frg_cap[96] = {};
628
629         *caps = NULL;
630
631         media_transport = avdtp_service_cap_new(AVDTP_MEDIA_TRANSPORT,
632                                                 NULL, 0);
633
634         *caps = g_slist_append(*caps, media_transport);
635
636         codec_caps = g_malloc0(sizeof(*codec_caps) + sizeof(cap));
637         codec_caps->media_type = AVDTP_MEDIA_TYPE_AUDIO;
638         codec_caps->media_codec_type = 0x00;
639         memcpy(codec_caps->data, cap, sizeof(cap));
640
641         media_codec = avdtp_service_cap_new(AVDTP_MEDIA_CODEC, codec_caps,
642                                         sizeof(*codec_caps) + sizeof(cap));
643
644         *caps = g_slist_append(*caps, media_codec);
645         g_free(codec_caps);
646
647         content_protection = avdtp_service_cap_new(AVDTP_CONTENT_PROTECTION,
648                                                 frg_cap, sizeof(frg_cap));
649         *caps = g_slist_append(*caps, content_protection);
650
651         return TRUE;
652 }
653
654 static struct avdtp_sep_ind sep_ind_frg = {
655         .get_capability         = sep_getcap_ind_frg,
656 };
657
658 static void test_server_frg(gconstpointer data)
659 {
660         struct context *context = context_new(0x0100, 48, 48, data);
661         struct avdtp_local_sep *sep;
662
663         sep = avdtp_register_sep(context->lseps, AVDTP_SEP_TYPE_SOURCE,
664                                                 AVDTP_MEDIA_TYPE_AUDIO,
665                                                 0x00, TRUE, &sep_ind_frg,
666                                                 NULL, context);
667         g_assert(sep);
668
669         g_idle_add(send_pdu, context);
670 }
671
672 static void discover_cb(struct avdtp *session, GSList *seps,
673                                 struct avdtp_error *err, void *user_data)
674 {
675         struct context *context = user_data;
676         struct avdtp_stream *stream;
677         struct avdtp_remote_sep *rsep;
678         struct avdtp_service_capability *media_transport, *media_codec;
679         struct avdtp_media_codec_capability *cap;
680         GSList *caps;
681         uint8_t data[4] = { 0x21, 0x02, 2, 32 };
682         int ret;
683
684         if (g_str_equal(context->data->test_name, "/TP/SIG/SMG/BV-05-C") ||
685                 g_str_equal(context->data->test_name, "/TP/SIG/SMG/BV-07-C") ||
686                 g_str_equal(context->data->test_name, "/TP/SIG/SMG/BV-25-C"))
687                 return;
688
689         if (g_str_equal(context->data->test_name, "/TP/SIG/SMG/BI-01-C")) {
690                 g_assert(err != NULL);
691                 g_assert_cmpint(avdtp_error_error_code(err), ==, 0x01);
692                 context_quit(context);
693                 return;
694         }
695
696         if (g_str_equal(context->data->test_name, "/TP/SIG/SMG/BI-04-C") ||
697                 g_str_equal(context->data->test_name, "/TP/SIG/SMG/BI-32-C")) {
698                 g_assert(err != NULL);
699                 g_assert_cmpint(avdtp_error_error_code(err), ==, 0x11);
700                 context_quit(context);
701                 return;
702         }
703
704         g_assert(err == NULL);
705         g_assert_cmpint(g_slist_length(seps), !=, 0);
706
707         if (g_str_equal(context->data->test_name, "/TP/SIG/FRA/BV-02-C")) {
708                 g_assert(err == NULL);
709                 context_quit(context);
710                 return;
711         }
712
713         rsep = avdtp_find_remote_sep(session, context->sep);
714         g_assert(rsep != NULL);
715
716         media_transport = avdtp_service_cap_new(AVDTP_MEDIA_TRANSPORT,
717                                                 NULL, 0);
718
719         caps = g_slist_append(NULL, media_transport);
720
721         cap = g_malloc0(sizeof(*cap) + sizeof(data));
722         cap->media_type = AVDTP_MEDIA_TYPE_AUDIO;
723         cap->media_codec_type = 0x00;
724         memcpy(cap->data, data, sizeof(data));
725
726         media_codec = avdtp_service_cap_new(AVDTP_MEDIA_CODEC, cap,
727                                                 sizeof(*cap) + sizeof(data));
728
729         caps = g_slist_append(caps, media_codec);
730         g_free(cap);
731
732         ret = avdtp_set_configuration(session, rsep, context->sep, caps,
733                                                                 &stream);
734         g_assert_cmpint(ret, ==, 0);
735
736         g_slist_free_full(caps, g_free);
737 }
738
739 static void test_client(gconstpointer data)
740 {
741         struct context *context = create_context(0x0100, data);
742         struct avdtp_local_sep *sep;
743
744         sep = avdtp_register_sep(context->lseps, AVDTP_SEP_TYPE_SINK,
745                                         AVDTP_MEDIA_TYPE_AUDIO,
746                                         0x00, FALSE, NULL, &sep_cfm, context);
747
748         context->sep = sep;
749
750         avdtp_discover(context->session, discover_cb, context);
751 }
752
753 static void test_client_1_3(gconstpointer data)
754 {
755         struct context *context = create_context(0x0103, data);
756         struct avdtp_local_sep *sep;
757
758         sep = avdtp_register_sep(context->lseps, AVDTP_SEP_TYPE_SINK,
759                                         AVDTP_MEDIA_TYPE_AUDIO,
760                                         0x00, TRUE, NULL, &sep_cfm, context);
761
762         context->sep = sep;
763
764         avdtp_discover(context->session, discover_cb, context);
765 }
766
767 static void test_client_frg(gconstpointer data)
768 {
769         struct context *context = context_new(0x0100, 48, 48, data);
770         struct avdtp_local_sep *sep;
771
772         sep = avdtp_register_sep(context->lseps, AVDTP_SEP_TYPE_SINK,
773                                         AVDTP_MEDIA_TYPE_AUDIO,
774                                         0x00, TRUE, NULL, &sep_cfm, context);
775
776         context->sep = sep;
777
778         avdtp_discover(context->session, discover_cb, context);
779 }
780
781 int main(int argc, char *argv[])
782 {
783         tester_init(&argc, &argv);
784
785         __btd_log_init("*", 0);
786
787         /*
788          * Stream Management Service
789          *
790          * To verify that the following procedures are implemented according to
791          * their specification in AVDTP.
792          */
793         define_test("/TP/SIG/SMG/BV-06-C-SEID-1", test_server_seid,
794                         raw_pdu(0x00));
795         define_test("/TP/SIG/SMG/BV-06-C-SEID-2", test_server_seid_duplicate,
796                         raw_pdu(0x00, 0x01),
797                         raw_pdu(0x02, 0x01, 0x08, 0x08, 0x04, 0x08));
798         define_test("/TP/SIG/SMG/BV-05-C", test_client,
799                         raw_pdu(0x00, 0x01));
800         define_test("/TP/SIG/SMG/BV-06-C", test_server,
801                         raw_pdu(0x00, 0x01),
802                         raw_pdu(0x02, 0x01, 0x04, 0x00));
803         define_test("/TP/SIG/SMG/BV-07-C", test_client,
804                         raw_pdu(0x10, 0x01),
805                         raw_pdu(0x12, 0x01, 0x04, 0x00),
806                         raw_pdu(0x20, 0x02, 0x04));
807         define_test("/TP/SIG/SMG/BV-08-C", test_server,
808                         raw_pdu(0x00, 0x01),
809                         raw_pdu(0x02, 0x01, 0x04, 0x00),
810                         raw_pdu(0x10, 0x02, 0x04),
811                         raw_pdu(0x12, 0x02, 0x01, 0x00, 0x07, 0x06, 0x00, 0x00,
812                                 0xff, 0xff, 0x02, 0x40));
813         define_test("/TP/SIG/SMG/BV-09-C", test_client,
814                         raw_pdu(0x30, 0x01),
815                         raw_pdu(0x32, 0x01, 0x04, 0x00),
816                         raw_pdu(0x40, 0x02, 0x04),
817                         raw_pdu(0x42, 0x02, 0x01, 0x00, 0x07, 0x06, 0x00, 0x00,
818                                 0xff, 0xff, 0x02, 0x40),
819                         raw_pdu(0x50, 0x03, 0x04, 0x04, 0x01, 0x00, 0x07, 0x06,
820                                 0x00, 0x00, 0x21, 0x02, 0x02, 0x20),
821                         raw_pdu(0x52, 0x03));
822         define_test("/TP/SIG/SMG/BV-10-C", test_server,
823                         raw_pdu(0x00, 0x01),
824                         raw_pdu(0x02, 0x01, 0x04, 0x00),
825                         raw_pdu(0x10, 0x02, 0x04),
826                         raw_pdu(0x12, 0x02, 0x01, 0x00, 0x07, 0x06, 0x00, 0x00,
827                                 0xff, 0xff, 0x02, 0x40),
828                         raw_pdu(0x20, 0x03, 0x04, 0x04, 0x01, 0x00, 0x07, 0x06,
829                                 0x00, 0x00, 0x21, 0x02, 0x02, 0x20),
830                         raw_pdu(0x22, 0x03));
831         define_test("/TP/SIG/SMG/BV-11-C", test_client,
832                         raw_pdu(0x60, 0x01),
833                         raw_pdu(0x62, 0x01, 0x04, 0x00),
834                         raw_pdu(0x70, 0x02, 0x04),
835                         raw_pdu(0x72, 0x02, 0x01, 0x00, 0x07, 0x06, 0x00, 0x00,
836                                 0xff, 0xff, 0x02, 0x40),
837                         raw_pdu(0x80, 0x03, 0x04, 0x04, 0x01, 0x00, 0x07, 0x06,
838                                 0x00, 0x00, 0x21, 0x02, 0x02, 0x20),
839                         raw_pdu(0x82, 0x03),
840                         raw_pdu(0x90, 0x04, 0x04));
841         define_test("/TP/SIG/SMG/BV-12-C", test_server,
842                         raw_pdu(0x00, 0x01),
843                         raw_pdu(0x02, 0x01, 0x04, 0x00),
844                         raw_pdu(0x10, 0x02, 0x04),
845                         raw_pdu(0x12, 0x02, 0x01, 0x00, 0x07, 0x06, 0x00, 0x00,
846                                 0xff, 0xff, 0x02, 0x40),
847                         raw_pdu(0x20, 0x03, 0x04, 0x04, 0x01, 0x00, 0x07, 0x06,
848                                 0x00, 0x00, 0x21, 0x02, 0x02, 0x20),
849                         raw_pdu(0x22, 0x03),
850                         raw_pdu(0x30, 0x04, 0x04),
851                         raw_pdu(0x32, 0x04, 0x01, 0x00, 0x07, 0x06, 0x00, 0x00,
852                                 0x21, 0x02, 0x02, 0x20));
853         define_test("/TP/SIG/SMG/BV-15-C", test_client,
854                         raw_pdu(0xa0, 0x01),
855                         raw_pdu(0xa2, 0x01, 0x04, 0x00),
856                         raw_pdu(0xb0, 0x02, 0x04),
857                         raw_pdu(0xb2, 0x02, 0x01, 0x00, 0x07, 0x06, 0x00, 0x00,
858                                 0xff, 0xff, 0x02, 0x40),
859                         raw_pdu(0xc0, 0x03, 0x04, 0x04, 0x01, 0x00, 0x07, 0x06,
860                                 0x00, 0x00, 0x21, 0x02, 0x02, 0x20),
861                         raw_pdu(0xc2, 0x03),
862                         raw_pdu(0xd0, 0x06, 0x04));
863         define_test("/TP/SIG/SMG/BV-16-C", test_server,
864                         raw_pdu(0x00, 0x01),
865                         raw_pdu(0x02, 0x01, 0x04, 0x00),
866                         raw_pdu(0x10, 0x02, 0x04),
867                         raw_pdu(0x12, 0x02, 0x01, 0x00, 0x07, 0x06, 0x00, 0x00,
868                                 0xff, 0xff, 0x02, 0x40),
869                         raw_pdu(0x20, 0x03, 0x04, 0x04, 0x01, 0x00, 0x07, 0x06,
870                                 0x00, 0x00, 0x21, 0x02, 0x02, 0x20),
871                         raw_pdu(0x22, 0x03),
872                         raw_pdu(0x30, 0x06, 0x04),
873                         raw_pdu(0x32, 0x06));
874         define_test("/TP/SIG/SMG/BV-17-C", test_client,
875                         raw_pdu(0xe0, 0x01),
876                         raw_pdu(0xe2, 0x01, 0x04, 0x00),
877                         raw_pdu(0xf0, 0x02, 0x04),
878                         raw_pdu(0xf2, 0x02, 0x01, 0x00, 0x07, 0x06, 0x00, 0x00,
879                                 0xff, 0xff, 0x02, 0x40),
880                         raw_pdu(0x00, 0x03, 0x04, 0x04, 0x01, 0x00, 0x07, 0x06,
881                                 0x00, 0x00, 0x21, 0x02, 0x02, 0x20),
882                         raw_pdu(0x02, 0x03),
883                         raw_pdu(0x10, 0x06, 0x04),
884                         raw_pdu(0x12, 0x06),
885                         raw_pdu(0x20, 0x07, 0x04));
886         define_test("/TP/SIG/SMG/BV-18-C", test_server,
887                         raw_pdu(0x00, 0x01),
888                         raw_pdu(0x02, 0x01, 0x04, 0x00),
889                         raw_pdu(0x10, 0x02, 0x04),
890                         raw_pdu(0x12, 0x02, 0x01, 0x00, 0x07, 0x06, 0x00, 0x00,
891                                 0xff, 0xff, 0x02, 0x40),
892                         raw_pdu(0x20, 0x03, 0x04, 0x04, 0x01, 0x00, 0x07, 0x06,
893                                 0x00, 0x00, 0x21, 0x02, 0x02, 0x20),
894                         raw_pdu(0x22, 0x03),
895                         raw_pdu(0x30, 0x06, 0x04),
896                         raw_pdu(0x32, 0x06),
897                         raw_pdu(0x40, 0x07, 0x04),
898                         raw_pdu(0x42, 0x07));
899         define_test("/TP/SIG/SMG/BV-19-C", test_client,
900                         raw_pdu(0x30, 0x01),
901                         raw_pdu(0x32, 0x01, 0x04, 0x00),
902                         raw_pdu(0x40, 0x02, 0x04),
903                         raw_pdu(0x42, 0x02, 0x01, 0x00, 0x07, 0x06, 0x00, 0x00,
904                                 0xff, 0xff, 0x02, 0x40),
905                         raw_pdu(0x50, 0x03, 0x04, 0x04, 0x01, 0x00, 0x07, 0x06,
906                                 0x00, 0x00, 0x21, 0x02, 0x02, 0x20),
907                         raw_pdu(0x52, 0x03),
908                         raw_pdu(0x60, 0x06, 0x04),
909                         raw_pdu(0x62, 0x06),
910                         raw_pdu(0x70, 0x07, 0x04),
911                         raw_pdu(0x72, 0x07),
912                         raw_pdu(0x80, 0x08, 0x04));
913         define_test("/TP/SIG/SMG/BV-20-C", test_server,
914                         raw_pdu(0x00, 0x01),
915                         raw_pdu(0x02, 0x01, 0x04, 0x00),
916                         raw_pdu(0x10, 0x02, 0x04),
917                         raw_pdu(0x12, 0x02, 0x01, 0x00, 0x07, 0x06, 0x00, 0x00,
918                                 0xff, 0xff, 0x02, 0x40),
919                         raw_pdu(0x20, 0x03, 0x04, 0x04, 0x01, 0x00, 0x07, 0x06,
920                                 0x00, 0x00, 0x21, 0x02, 0x02, 0x20),
921                         raw_pdu(0x22, 0x03),
922                         raw_pdu(0x30, 0x06, 0x04),
923                         raw_pdu(0x32, 0x06),
924                         raw_pdu(0x40, 0x07, 0x04),
925                         raw_pdu(0x42, 0x07),
926                         raw_pdu(0x50, 0x08, 0x04),
927                         raw_pdu(0x52, 0x08));
928         define_test("/TP/SIG/SMG/BV-21-C", test_client,
929                         raw_pdu(0x90, 0x01),
930                         raw_pdu(0x92, 0x01, 0x04, 0x00),
931                         raw_pdu(0xa0, 0x02, 0x04),
932                         raw_pdu(0xa2, 0x02, 0x01, 0x00, 0x07, 0x06, 0x00, 0x00,
933                                 0xff, 0xff, 0x02, 0x40),
934                         raw_pdu(0xb0, 0x03, 0x04, 0x04, 0x01, 0x00, 0x07, 0x06,
935                                 0x00, 0x00, 0x21, 0x02, 0x02, 0x20),
936                         raw_pdu(0xb2, 0x03),
937                         raw_pdu(0xc0, 0x06, 0x04),
938                         raw_pdu(0xc2, 0x06),
939                         raw_pdu(0xd0, 0x07, 0x04),
940                         raw_pdu(0xd2, 0x07),
941                         raw_pdu(0xe0, 0x09, 0x04));
942         define_test("/TP/SIG/SMG/BV-22-C", test_server,
943                         raw_pdu(0x00, 0x01),
944                         raw_pdu(0x02, 0x01, 0x04, 0x00),
945                         raw_pdu(0x10, 0x02, 0x04),
946                         raw_pdu(0x12, 0x02, 0x01, 0x00, 0x07, 0x06, 0x00, 0x00,
947                                 0xff, 0xff, 0x02, 0x40),
948                         raw_pdu(0x20, 0x03, 0x04, 0x04, 0x01, 0x00, 0x07, 0x06,
949                                 0x00, 0x00, 0x21, 0x02, 0x02, 0x20),
950                         raw_pdu(0x22, 0x03),
951                         raw_pdu(0x30, 0x06, 0x04),
952                         raw_pdu(0x32, 0x06),
953                         raw_pdu(0x40, 0x07, 0x04),
954                         raw_pdu(0x42, 0x07),
955                         raw_pdu(0x50, 0x09, 0x04),
956                         raw_pdu(0x52, 0x09));
957         define_test("/TP/SIG/SMG/BV-23-C", test_client,
958                         raw_pdu(0xf0, 0x01),
959                         raw_pdu(0xf2, 0x01, 0x04, 0x00),
960                         raw_pdu(0x00, 0x02, 0x04),
961                         raw_pdu(0x02, 0x02, 0x01, 0x00, 0x07, 0x06, 0x00, 0x00,
962                                 0xff, 0xff, 0x02, 0x40),
963                         raw_pdu(0x10, 0x03, 0x04, 0x04, 0x01, 0x00, 0x07, 0x06,
964                                 0x00, 0x00, 0x21, 0x02, 0x02, 0x20),
965                         raw_pdu(0x12, 0x03),
966                         raw_pdu(0x20, 0x0a, 0x04));
967         define_test("/TP/SIG/SMG/BV-24-C", test_server,
968                         raw_pdu(0x00, 0x01),
969                         raw_pdu(0x02, 0x01, 0x04, 0x00),
970                         raw_pdu(0x10, 0x02, 0x04),
971                         raw_pdu(0x12, 0x02, 0x01, 0x00, 0x07, 0x06, 0x00, 0x00,
972                                 0xff, 0xff, 0x02, 0x40),
973                         raw_pdu(0x20, 0x03, 0x04, 0x04, 0x01, 0x00, 0x07, 0x06,
974                                 0x00, 0x00, 0x21, 0x02, 0x02, 0x20),
975                         raw_pdu(0x22, 0x03),
976                         raw_pdu(0x30, 0x0a, 0x04),
977                         raw_pdu(0x32, 0x0a));
978         define_test("/TP/SIG/SMG/BV-25-C", test_client_1_3,
979                         raw_pdu(0x30, 0x01),
980                         raw_pdu(0x32, 0x01, 0x04, 0x00),
981                         raw_pdu(0x40, 0x0c, 0x04));
982         define_test("/TP/SIG/SMG/BV-26-C", test_server_1_3,
983                         raw_pdu(0x00, 0x01),
984                         raw_pdu(0x02, 0x01, 0x04, 0x00),
985                         raw_pdu(0x10, 0x0c, 0x04),
986                         raw_pdu(0x12, 0x0c, 0x01, 0x00, 0x07, 0x06, 0x00, 0x00,
987                                 0xff, 0xff, 0x02, 0x40, 0x08, 0x00));
988         define_test("/TP/SIG/SMG/BV-27-C", test_server_1_3,
989                         raw_pdu(0x00, 0x01),
990                         raw_pdu(0x02, 0x01, 0x04, 0x00),
991                         raw_pdu(0x10, 0x02, 0x04),
992                         raw_pdu(0x12, 0x02, 0x01, 0x00, 0x07, 0x06, 0x00, 0x00,
993                                 0xff, 0xff, 0x02, 0x40));
994         define_test("/TP/SIG/SMG/BV-28-C", test_client_1_3,
995                         raw_pdu(0x50, 0x01),
996                         raw_pdu(0x52, 0x01, 0x04, 0x00),
997                         raw_pdu(0x60, 0x0c, 0x04),
998                         raw_pdu(0x62, 0x0c, 0x01, 0x00, 0x07, 0x06, 0x00, 0x00,
999                                 0xff, 0xff, 0x02, 0x40, 0x0f, 0x00),
1000                         raw_pdu(0x70, 0x03, 0x04, 0x04, 0x01, 0x00, 0x07, 0x06,
1001                                 0x00, 0x00, 0x21, 0x02, 0x02, 0x20));
1002         define_test("/TP/SIG/SMG/BV-31-C", test_client_1_3,
1003                         raw_pdu(0x80, 0x01),
1004                         raw_pdu(0x82, 0x01, 0x04, 0x00),
1005                         raw_pdu(0x90, 0x0c, 0x04),
1006                         raw_pdu(0x92, 0x0c, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00,
1007                                 0x04, 0x00, 0x05, 0x00, 0x06, 0x00, 0x07, 0x06,
1008                                 0x00, 0x00, 0xff, 0xff, 0x02, 0x40, 0x08, 0x00),
1009                         raw_pdu(0xa0, 0x03, 0x04, 0x04, 0x01, 0x00, 0x07, 0x06,
1010                                 0x00, 0x00, 0x21, 0x02, 0x02, 0x20, 0x08,
1011                                 0x00));
1012         define_test("/TP/SIG/SMG/BI-01-C", test_client,
1013                         raw_pdu(0xb0, 0x01),
1014                         raw_pdu(0xb3, 0x01, 0x01));
1015         define_test("/TP/SIG/SMG/BI-02-C", test_server,
1016                         raw_pdu(0x01, 0x01));
1017         define_test("/TP/SIG/SMG/BI-03-C", test_server_0_sep,
1018                         raw_pdu(0x00, 0x01),
1019                         raw_pdu(0x03, 0x01, 0x19));
1020         define_test("/TP/SIG/SMG/BI-04-C", test_client,
1021                         raw_pdu(0xc0, 0x01),
1022                         raw_pdu(0xc2, 0x01, 0x04, 0x00),
1023                         raw_pdu(0xd0, 0x02, 0x04),
1024                         raw_pdu(0xd3, 0x02, 0x11));
1025         define_test("/TP/SIG/SMG/BI-05-C", test_server,
1026                         raw_pdu(0x00, 0x01),
1027                         raw_pdu(0x02, 0x01, 0x04, 0x00),
1028                         raw_pdu(0x10, 0x02),
1029                         raw_pdu(0x13, 0x02, 0x11));
1030         define_test("/TP/SIG/SMG/BI-06-C", test_server,
1031                         raw_pdu(0x00, 0x01),
1032                         raw_pdu(0x02, 0x01, 0x04, 0x00),
1033                         raw_pdu(0x10, 0x02, 0x00),
1034                         raw_pdu(0x13, 0x02, 0x12));
1035         define_test("/TP/SIG/SMG/BI-07-C", test_client,
1036                         raw_pdu(0xe0, 0x01),
1037                         raw_pdu(0xe2, 0x01, 0x04, 0x00),
1038                         raw_pdu(0xf0, 0x02, 0x04),
1039                         raw_pdu(0xf2, 0x02, 0x01, 0x00, 0x07, 0x06, 0x00, 0x00,
1040                                 0xff, 0xff, 0x02, 0x40),
1041                         raw_pdu(0x00, 0x03, 0x04, 0x04, 0x01, 0x00, 0x07, 0x06,
1042                                 0x00, 0x00, 0x21, 0x02, 0x02, 0x20),
1043                         raw_pdu(0x03, 0x03, 0x00, 0x13));
1044         define_test("/TP/SIG/SMG/BI-08-C", test_server,
1045                         raw_pdu(0x00, 0x01),
1046                         raw_pdu(0x02, 0x01, 0x04, 0x00),
1047                         raw_pdu(0x10, 0x02, 0x04),
1048                         raw_pdu(0x12, 0x02, 0x01, 0x00, 0x07, 0x06, 0x00, 0x00,
1049                                 0xff, 0xff, 0x02, 0x40),
1050                         raw_pdu(0x20, 0x03, 0x04, 0x04, 0x01, 0x00, 0x07, 0x06,
1051                                 0x00, 0x00, 0x21, 0x02, 0x02, 0x20),
1052                         raw_pdu(0x22, 0x03),
1053                         raw_pdu(0x30, 0x03, 0x04, 0x04, 0x01, 0x00, 0x07, 0x06,
1054                                 0x00, 0x00, 0x21, 0x02, 0x02, 0x20),
1055                         raw_pdu(0x33, 0x03, 0x00, 0x13));
1056         define_test("/TP/SIG/SMG/BI-09-C", test_server,
1057                         raw_pdu(0x00, 0x01),
1058                         raw_pdu(0x02, 0x01, 0x04, 0x00),
1059                         raw_pdu(0x10, 0x02, 0x04),
1060                         raw_pdu(0x12, 0x02, 0x01, 0x00, 0x07, 0x06, 0x00, 0x00,
1061                                 0xff, 0xff, 0x02, 0x40),
1062                         raw_pdu(0x20, 0x03, 0x04, 0x04, 0x01, 0x00, 0x07, 0x06,
1063                                 0x00, 0x00, 0x21, 0x02, 0x02, 0x20),
1064                         raw_pdu(0x23, 0x03, 0x00, 0x29));
1065         define_test("/TP/SIG/SMG/BI-10-C", test_client,
1066                         raw_pdu(0x10, 0x01),
1067                         raw_pdu(0x12, 0x01, 0x04, 0x00),
1068                         raw_pdu(0x20, 0x02, 0x04),
1069                         raw_pdu(0x22, 0x02, 0x01, 0x00, 0x07, 0x06, 0x00, 0x00,
1070                                 0xff, 0xff, 0x02, 0x40),
1071                         raw_pdu(0x30, 0x03, 0x04, 0x04, 0x01, 0x00, 0x07, 0x06,
1072                                 0x00, 0x00, 0x21, 0x02, 0x02, 0x20),
1073                         raw_pdu(0x32, 0x03),
1074                         raw_pdu(0x40, 0x04, 0x04),
1075                         raw_pdu(0x43, 0x04, 0x12));
1076         define_test("/TP/SIG/SMG/BI-11-C", test_server,
1077                         raw_pdu(0x00, 0x01),
1078                         raw_pdu(0x02, 0x01, 0x04, 0x00),
1079                         raw_pdu(0x10, 0x02, 0x04),
1080                         raw_pdu(0x12, 0x02, 0x01, 0x00, 0x07, 0x06, 0x00, 0x00,
1081                                 0xff, 0xff, 0x02, 0x40),
1082                         raw_pdu(0x20, 0x03, 0x04, 0x04, 0x01, 0x00, 0x07, 0x06,
1083                                 0x00, 0x00, 0x21, 0x02, 0x02, 0x20),
1084                         raw_pdu(0x22, 0x03),
1085                         raw_pdu(0x30, 0x04, 0x00),
1086                         raw_pdu(0x33, 0x04, 0x12));
1087         define_test("/TP/SIG/SMG/BI-17-C", test_server,
1088                         raw_pdu(0x00, 0x01),
1089                         raw_pdu(0x02, 0x01, 0x04, 0x00),
1090                         raw_pdu(0x10, 0x02, 0x04),
1091                         raw_pdu(0x12, 0x02, 0x01, 0x00, 0x07, 0x06, 0x00, 0x00,
1092                                 0xff, 0xff, 0x02, 0x40),
1093                         raw_pdu(0x30, 0x06, 0x04),
1094                         raw_pdu(0x33, 0x06, 0x31));
1095         define_test("/TP/SIG/SMG/BI-18-C", test_server,
1096                         raw_pdu(0x00, 0x01),
1097                         raw_pdu(0x02, 0x01, 0x04, 0x00),
1098                         raw_pdu(0x10, 0x02, 0x04),
1099                         raw_pdu(0x12, 0x02, 0x01, 0x00, 0x07, 0x06, 0x00, 0x00,
1100                                 0xff, 0xff, 0x02, 0x40),
1101                         raw_pdu(0x20, 0x03, 0x04, 0x04, 0x01, 0x00, 0x07, 0x06,
1102                                 0x00, 0x00, 0x21, 0x02, 0x02, 0x20),
1103                         raw_pdu(0x22, 0x03),
1104                         raw_pdu(0x30, 0x06, 0x04),
1105                         raw_pdu(0x33, 0x06, 0xc0));
1106         define_test("/TP/SIG/SMG/BI-19-C", test_client,
1107                         raw_pdu(0x50, 0x01),
1108                         raw_pdu(0x52, 0x01, 0x04, 0x00),
1109                         raw_pdu(0x60, 0x02, 0x04),
1110                         raw_pdu(0x62, 0x02, 0x01, 0x00, 0x07, 0x06, 0x00, 0x00,
1111                                 0xff, 0xff, 0x02, 0x40),
1112                         raw_pdu(0x70, 0x03, 0x04, 0x04, 0x01, 0x00, 0x07, 0x06,
1113                                 0x00, 0x00, 0x21, 0x02, 0x02, 0x20),
1114                         raw_pdu(0x72, 0x03),
1115                         raw_pdu(0x80, 0x06, 0x04),
1116                         raw_pdu(0x82, 0x06),
1117                         raw_pdu(0x90, 0x07, 0x04),
1118                         raw_pdu(0x93, 0x07, 0x04, 0x31));
1119         define_test("/TP/SIG/SMG/BI-20-C", test_server,
1120                         raw_pdu(0x00, 0x01),
1121                         raw_pdu(0x02, 0x01, 0x04, 0x00),
1122                         raw_pdu(0x10, 0x02, 0x04),
1123                         raw_pdu(0x12, 0x02, 0x01, 0x00, 0x07, 0x06, 0x00, 0x00,
1124                                 0xff, 0xff, 0x02, 0x40),
1125                         raw_pdu(0x20, 0x03, 0x04, 0x04, 0x01, 0x00, 0x07, 0x06,
1126                                 0x00, 0x00, 0x21, 0x02, 0x02, 0x20),
1127                         raw_pdu(0x22, 0x03),
1128                         raw_pdu(0x30, 0x07, 0x04),
1129                         raw_pdu(0x33, 0x07, 0x04, 0x31));
1130         define_test("/TP/SIG/SMG/BI-21-C", test_server,
1131                         raw_pdu(0x00, 0x01),
1132                         raw_pdu(0x02, 0x01, 0x04, 0x00),
1133                         raw_pdu(0x10, 0x02, 0x04),
1134                         raw_pdu(0x12, 0x02, 0x01, 0x00, 0x07, 0x06, 0x00, 0x00,
1135                                 0xff, 0xff, 0x02, 0x40),
1136                         raw_pdu(0x20, 0x03, 0x04, 0x04, 0x01, 0x00, 0x07, 0x06,
1137                                 0x00, 0x00, 0x21, 0x02, 0x02, 0x20),
1138                         raw_pdu(0x22, 0x03),
1139                         raw_pdu(0x30, 0x06, 0x04),
1140                         raw_pdu(0x32, 0x06),
1141                         raw_pdu(0x40, 0x07, 0x04),
1142                         raw_pdu(0x43, 0x07, 0x04, 0xc0));
1143         define_test("/TP/SIG/SMG/BI-22-C", test_client,
1144                         raw_pdu(0xa0, 0x01),
1145                         raw_pdu(0xa2, 0x01, 0x04, 0x00),
1146                         raw_pdu(0xb0, 0x02, 0x04),
1147                         raw_pdu(0xb2, 0x02, 0x01, 0x00, 0x07, 0x06, 0x00, 0x00,
1148                                 0xff, 0xff, 0x02, 0x40),
1149                         raw_pdu(0xc0, 0x03, 0x04, 0x04, 0x01, 0x00, 0x07, 0x06,
1150                                 0x00, 0x00, 0x21, 0x02, 0x02, 0x20),
1151                         raw_pdu(0xc2, 0x03),
1152                         raw_pdu(0xd0, 0x06, 0x04),
1153                         raw_pdu(0xd2, 0x06),
1154                         raw_pdu(0xe0, 0x07, 0x04),
1155                         raw_pdu(0xe3, 0x07, 0x04, 0x31));
1156         define_test("/TP/SIG/SMG/BI-23-C", test_server,
1157                         raw_pdu(0x00, 0x01),
1158                         raw_pdu(0x02, 0x01, 0x04, 0x00),
1159                         raw_pdu(0x10, 0x02, 0x04),
1160                         raw_pdu(0x12, 0x02, 0x01, 0x00, 0x07, 0x06, 0x00, 0x00,
1161                                 0xff, 0xff, 0x02, 0x40),
1162                         raw_pdu(0x20, 0x03, 0x04, 0x04, 0x01, 0x00, 0x07, 0x06,
1163                                 0x00, 0x00, 0x21, 0x02, 0x02, 0x20),
1164                         raw_pdu(0x22, 0x03),
1165                         raw_pdu(0x30, 0x06, 0x04),
1166                         raw_pdu(0x32, 0x06),
1167                         raw_pdu(0x40, 0x08, 0x00),
1168                         raw_pdu(0x43, 0x08, 0x12));
1169         define_test("/TP/SIG/SMG/BI-24-C", test_server,
1170                         raw_pdu(0x00, 0x01),
1171                         raw_pdu(0x02, 0x01, 0x04, 0x00),
1172                         raw_pdu(0x10, 0x02, 0x04),
1173                         raw_pdu(0x12, 0x02, 0x01, 0x00, 0x07, 0x06, 0x00, 0x00,
1174                                 0xff, 0xff, 0x02, 0x40),
1175                         raw_pdu(0x20, 0x03, 0x04, 0x04, 0x01, 0x00, 0x07, 0x06,
1176                                 0x00, 0x00, 0x21, 0x02, 0x02, 0x20),
1177                         raw_pdu(0x22, 0x03),
1178                         raw_pdu(0x30, 0x06, 0x04),
1179                         raw_pdu(0x32, 0x06),
1180                         raw_pdu(0x40, 0x08, 0x04),
1181                         raw_pdu(0x43, 0x08, 0xc0));
1182         define_test("/TP/SIG/SMG/BI-25-C", test_server,
1183                         raw_pdu(0x00, 0x01),
1184                         raw_pdu(0x02, 0x01, 0x04, 0x00),
1185                         raw_pdu(0x10, 0x02, 0x04),
1186                         raw_pdu(0x12, 0x02, 0x01, 0x00, 0x07, 0x06, 0x00, 0x00,
1187                                 0xff, 0xff, 0x02, 0x40),
1188                         raw_pdu(0x20, 0x03, 0x04, 0x04, 0x01, 0x00, 0x07, 0x06,
1189                                 0x00, 0x00, 0x21, 0x02, 0x02, 0x20),
1190                         raw_pdu(0x22, 0x03),
1191                         raw_pdu(0x30, 0x06, 0x04),
1192                         raw_pdu(0x32, 0x06),
1193                         raw_pdu(0x40, 0x07, 0x04),
1194                         raw_pdu(0x42, 0x07),
1195                         raw_pdu(0xf0, 0x09, 0x04),
1196                         raw_pdu(0xf3, 0x09, 0x04, 0x31));
1197         define_test("/TP/SIG/SMG/BI-26-C", test_server,
1198                         raw_pdu(0x00, 0x01),
1199                         raw_pdu(0x02, 0x01, 0x04, 0x00),
1200                         raw_pdu(0x10, 0x02, 0x04),
1201                         raw_pdu(0x12, 0x02, 0x01, 0x00, 0x07, 0x06, 0x00, 0x00,
1202                                 0xff, 0xff, 0x02, 0x40),
1203                         raw_pdu(0x20, 0x03, 0x04, 0x04, 0x01, 0x00, 0x07, 0x06,
1204                                 0x00, 0x00, 0x21, 0x02, 0x02, 0x20),
1205                         raw_pdu(0x22, 0x03),
1206                         raw_pdu(0x30, 0x06, 0x04),
1207                         raw_pdu(0x32, 0x06),
1208                         raw_pdu(0x40, 0x09, 0x04),
1209                         raw_pdu(0x43, 0x09, 0x04, 0x31));
1210         define_test("/TP/SIG/SMG/BI-27-C", test_server,
1211                         raw_pdu(0x00, 0x01),
1212                         raw_pdu(0x02, 0x01, 0x04, 0x00),
1213                         raw_pdu(0x10, 0x02, 0x04),
1214                         raw_pdu(0x12, 0x02, 0x01, 0x00, 0x07, 0x06, 0x00, 0x00,
1215                                 0xff, 0xff, 0x02, 0x40),
1216                         raw_pdu(0x20, 0x03, 0x04, 0x04, 0x01, 0x00, 0x07, 0x06,
1217                                 0x00, 0x00, 0x21, 0x02, 0x02, 0x20),
1218                         raw_pdu(0x22, 0x03),
1219                         raw_pdu(0x30, 0x06, 0x04),
1220                         raw_pdu(0x32, 0x06),
1221                         raw_pdu(0x40, 0x07, 0x04),
1222                         raw_pdu(0x42, 0x07),
1223                         raw_pdu(0x50, 0x09, 0x04),
1224                         raw_pdu(0x53, 0x09, 0x04, 0xc0));
1225         define_test("/TP/SIG/SMG/BI-28-C", test_server,
1226                         raw_pdu(0x00, 0xff),
1227                         raw_pdu(0x01, 0x3f));
1228         define_test("/TP/SIG/SMG/BI-30-C", test_client,
1229                         raw_pdu(0x00, 0x01),
1230                         raw_pdu(0x02, 0x01, 0x04, 0x00),
1231                         raw_pdu(0x10, 0x02, 0x04),
1232                         raw_pdu(0x12, 0x02, 0xee, 0x01, 0x00, 0x01, 0x00, 0x07,
1233                                 0x06, 0x00, 0x00, 0xff, 0xff, 0x02, 0x40),
1234                         raw_pdu(0x20, 0x03, 0x04, 0x04, 0x01, 0x00, 0x07, 0x06,
1235                                 0x00, 0x00, 0x21, 0x02, 0x02, 0x20));
1236         define_test("/TP/SIG/SMG/ESR04/BI-28-C", test_server,
1237                         raw_pdu(0x00, 0x3f),
1238                         raw_pdu(0x01, 0x3f));
1239         define_test("/TP/SIG/SMG/BI-32-C", test_client_1_3,
1240                         raw_pdu(0x30, 0x01),
1241                         raw_pdu(0x32, 0x01, 0x04, 0x00),
1242                         raw_pdu(0x40, 0x0c, 0x04),
1243                         raw_pdu(0x43, 0x0c, 0x11));
1244         define_test("/TP/SIG/SMG/BI-33-C", test_server_1_3,
1245                         raw_pdu(0x00, 0x01),
1246                         raw_pdu(0x02, 0x01, 0x04, 0x00),
1247                         raw_pdu(0x10, 0x0c),
1248                         raw_pdu(0x13, 0x0c, 0x11));
1249         define_test("/TP/SIG/SMG/BI-35-C", test_client_1_3,
1250                         raw_pdu(0x50, 0x01),
1251                         raw_pdu(0x52, 0x01, 0x04, 0x00),
1252                         raw_pdu(0x60, 0x0c, 0x04),
1253                         raw_pdu(0x62, 0x0c, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00,
1254                                 0x04, 0x00, 0x05, 0x00, 0x06, 0x00, 0x07, 0x06,
1255                                 0x00, 0x00, 0xff, 0xff, 0x02, 0x40, 0x08, 0x00),
1256                         raw_pdu(0x70, 0x03, 0x04, 0x04, 0x01, 0x00, 0x07, 0x06,
1257                                 0x00, 0x00, 0x21, 0x02, 0x02, 0x20, 0x08,
1258                                 0x00));
1259         define_test("/TP/SIG/SMG/BI-36-C", test_client_1_3,
1260                         raw_pdu(0x80, 0x01),
1261                         raw_pdu(0x82, 0x01, 0x04, 0x00),
1262                         raw_pdu(0x90, 0x0c, 0x04),
1263                         raw_pdu(0x92, 0x0c, 0xee, 0x01, 0x00, 0x01, 0x00, 0x07,
1264                                 0x06, 0x00, 0x00, 0xff, 0xff, 0x02, 0x40),
1265                         raw_pdu(0xa0, 0x03, 0x04, 0x04, 0x01, 0x00, 0x07, 0x06,
1266                                 0x00, 0x00, 0x21, 0x02, 0x02, 0x20));
1267
1268         /*
1269          * Signaling Message Fragmentation Service
1270          *
1271          * verify that the IUT (INT and ACP) fragments the signaling messages
1272          * that cannot fit in a single L2CAP packet.
1273          */
1274         define_test("/TP/SIG/FRA/BV-01-C", test_server_frg,
1275                         raw_pdu(0x00, 0x01),
1276                         raw_pdu(0x02, 0x01, 0x04, 0x00),
1277                         raw_pdu(0x10, 0x02, 0x04),
1278                         frg_pdu(0x16, 0x03, 0x02, 0x01, 0x00, 0x07, 0x06, 0x00,
1279                                 0x00, 0xff, 0xff, 0x02, 0x40, 0x04, 0x60, 0x00,
1280                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1281                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1282                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1283                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1284                                 0x00),
1285                         frg_pdu(0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1286                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1287                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1288                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1289                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1290                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1291                                 0x00),
1292                         raw_pdu(0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1293                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1294                                 0x00));
1295         define_test("/TP/SIG/FRA/BV-02-C", test_client_frg,
1296                         raw_pdu(0xb0, 0x01),
1297                         raw_pdu(0xb2, 0x01, 0x04, 0x00),
1298                         raw_pdu(0xc0, 0x02, 0x04),
1299                         frg_pdu(0xc6, 0x03, 0x02, 0x01, 0x00, 0x07, 0x06, 0x00,
1300                                 0x00, 0xff, 0xff, 0x02, 0x40, 0x04, 0x60, 0x00,
1301                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1302                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1303                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1304                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1305                                 0x00),
1306                         frg_pdu(0xca, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1307                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1308                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1309                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1310                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1311                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1312                                 0x00),
1313                         raw_pdu(0xce, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1314                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1315                                 0x00));
1316
1317         /*
1318          * Delay Reporting
1319          *
1320          * Verify that the stream management signaling procedure of delay
1321          * reporting is implemented according to its specification in AVDTP.
1322          */
1323         define_test("/TP/SIG/SYN/BV-01-C", test_server_1_3_sink,
1324                         raw_pdu(0x00, 0x01),
1325                         raw_pdu(0x02, 0x01, 0x04, 0x08),
1326                         raw_pdu(0x10, 0x0c, 0x04),
1327                         raw_pdu(0x12, 0x0c, 0x01, 0x00, 0x07, 0x06, 0x00, 0x00,
1328                                 0xff, 0xff, 0x02, 0x40, 0x08, 0x00));
1329         define_test("/TP/SIG/SYN/BV-02-C", test_client_1_3,
1330                         raw_pdu(0xd0, 0x01),
1331                         raw_pdu(0xd2, 0x01, 0x04, 0x00),
1332                         raw_pdu(0xe0, 0x0c, 0x04),
1333                         raw_pdu(0xe2, 0x0c, 0x01, 0x00, 0x07, 0x06, 0x00, 0x00,
1334                                 0xff, 0xff, 0x02, 0x40, 0x0f, 0x00, 0x08, 0x00),
1335                         raw_pdu(0xf0, 0x03, 0x04, 0x04, 0x01, 0x00, 0x07, 0x06,
1336                                 0x00, 0x00, 0x21, 0x02, 0x02, 0x20, 0x08,
1337                                 0x00));
1338         define_test("/TP/SIG/SYN/BV-03-C", test_server_1_3_sink,
1339                         raw_pdu(0x00, 0x01),
1340                         raw_pdu(0x02, 0x01, 0x04, 0x08),
1341                         raw_pdu(0x10, 0x0c, 0x04),
1342                         raw_pdu(0x12, 0x0c, 0x01, 0x00, 0x07, 0x06, 0x00, 0x00,
1343                                 0xff, 0xff, 0x02, 0x40, 0x08, 0x00),
1344                         raw_pdu(0x20, 0x03, 0x04, 0x04, 0x01, 0x00, 0x07, 0x06,
1345                                 0x00, 0x00, 0x21, 0x02, 0x02, 0x20, 0x08,
1346                                 0x00),
1347                         raw_pdu(0x22, 0x03),
1348                         raw_pdu(0x00, 0x0d, 0x04, 0x00, 0x00));
1349         define_test("/TP/SIG/SYN/BV-04-C", test_client_1_3,
1350                         raw_pdu(0x10, 0x01),
1351                         raw_pdu(0x12, 0x01, 0x04, 0x00),
1352                         raw_pdu(0x20, 0x0c, 0x04),
1353                         raw_pdu(0x22, 0x0c, 0x01, 0x00, 0x07, 0x06, 0x00, 0x00,
1354                                 0xff, 0xff, 0x02, 0x40, 0x0f, 0x00, 0x08, 0x00),
1355                         raw_pdu(0x30, 0x03, 0x04, 0x04, 0x01, 0x00, 0x07, 0x06,
1356                                 0x00, 0x00, 0x21, 0x02, 0x02, 0x20, 0x08,
1357                                 0x00),
1358                         raw_pdu(0x32, 0x03),
1359                         raw_pdu(0x40, 0x0d, 0x04, 0x00, 0x00));
1360         define_test("/TP/SIG/SYN/BV-05-C", test_server_1_3,
1361                         raw_pdu(0x00, 0x01),
1362                         raw_pdu(0x02, 0x01, 0x04, 0x00),
1363                         raw_pdu(0x10, 0x0c, 0x04),
1364                         raw_pdu(0x12, 0x0c, 0x01, 0x00, 0x07, 0x06, 0x00, 0x00,
1365                                 0xff, 0xff, 0x02, 0x40, 0x08, 0x00),
1366                         raw_pdu(0x20, 0x03, 0x04, 0x04, 0x01, 0x00, 0x07, 0x06,
1367                                 0x00, 0x00, 0x21, 0x02, 0x02, 0x20, 0x08,
1368                                 0x00),
1369                         raw_pdu(0x22, 0x03),
1370                         raw_pdu(0x30, 0x06, 0x04),
1371                         raw_pdu(0x32, 0x06),
1372                         raw_pdu(0x40, 0x0d, 0x04, 0x00, 0x00),
1373                         raw_pdu(0x42, 0x0d));
1374         define_test("/TP/SIG/SYN/BV-06-C", test_server_1_3,
1375                         raw_pdu(0x00, 0x01),
1376                         raw_pdu(0x02, 0x01, 0x04, 0x00),
1377                         raw_pdu(0x10, 0x0c, 0x04),
1378                         raw_pdu(0x12, 0x0c, 0x01, 0x00, 0x07, 0x06, 0x00, 0x00,
1379                                 0xff, 0xff, 0x02, 0x40, 0x08, 0x00),
1380                         raw_pdu(0x20, 0x03, 0x04, 0x04, 0x01, 0x00, 0x07, 0x06,
1381                                 0x00, 0x00, 0x21, 0x02, 0x02, 0x20, 0x08,
1382                                 0x00),
1383                         raw_pdu(0x22, 0x03),
1384                         raw_pdu(0x30, 0x06, 0x04),
1385                         raw_pdu(0x32, 0x06),
1386                         raw_pdu(0x40, 0x07, 0x04),
1387                         raw_pdu(0x42, 0x07),
1388                         raw_pdu(0x50, 0x0d, 0x04, 0x00, 0x00),
1389                         raw_pdu(0x52, 0x0d));
1390
1391         return tester_run();
1392 }