device: Set disconnect timer to zero for fast disconnection
[platform/upstream/bluez.git] / monitor / avdtp.c
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 /*
3  *
4  *  BlueZ - Bluetooth protocol stack for Linux
5  *
6  *  Copyright (C) 2015  Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
7  *
8  *
9  */
10
11 #ifdef HAVE_CONFIG_H
12 #include <config.h>
13 #endif
14
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <string.h>
18
19 #include "lib/bluetooth.h"
20
21 #include "src/shared/util.h"
22 #include "bt.h"
23 #include "packet.h"
24 #include "display.h"
25 #include "l2cap.h"
26 #include "avdtp.h"
27 #include "a2dp.h"
28
29 /* Message Types */
30 #define AVDTP_MSG_TYPE_COMMAND          0x00
31 #define AVDTP_MSG_TYPE_GENERAL_REJECT   0x01
32 #define AVDTP_MSG_TYPE_RESPONSE_ACCEPT  0x02
33 #define AVDTP_MSG_TYPE_RESPONSE_REJECT  0x03
34
35 /* Signal Identifiers */
36 #define AVDTP_DISCOVER                  0x01
37 #define AVDTP_GET_CAPABILITIES          0x02
38 #define AVDTP_SET_CONFIGURATION         0x03
39 #define AVDTP_GET_CONFIGURATION         0x04
40 #define AVDTP_RECONFIGURE               0x05
41 #define AVDTP_OPEN                      0x06
42 #define AVDTP_START                     0x07
43 #define AVDTP_CLOSE                     0x08
44 #define AVDTP_SUSPEND                   0x09
45 #define AVDTP_ABORT                     0x0a
46 #define AVDTP_SECURITY_CONTROL          0x0b
47 #define AVDTP_GET_ALL_CAPABILITIES      0x0c
48 #define AVDTP_DELAYREPORT               0x0d
49
50 /* Service Categories */
51 #define AVDTP_MEDIA_TRANSPORT           0x01
52 #define AVDTP_REPORTING                 0x02
53 #define AVDTP_RECOVERY                  0x03
54 #define AVDTP_CONTENT_PROTECTION        0x04
55 #define AVDTP_HEADER_COMPRESSION        0x05
56 #define AVDTP_MULTIPLEXING              0x06
57 #define AVDTP_MEDIA_CODEC               0x07
58 #define AVDTP_DELAY_REPORTING           0x08
59
60 struct avdtp_frame {
61         uint8_t hdr;
62         uint8_t sig_id;
63         struct l2cap_frame l2cap_frame;
64 };
65
66 static inline bool is_configuration_sig_id(uint8_t sig_id)
67 {
68         return (sig_id == AVDTP_SET_CONFIGURATION) ||
69                         (sig_id == AVDTP_GET_CONFIGURATION) ||
70                         (sig_id == AVDTP_RECONFIGURE);
71 }
72
73 static const char *msgtype2str(uint8_t msgtype)
74 {
75         switch (msgtype) {
76         case 0:
77                 return "Command";
78         case 1:
79                 return "General Reject";
80         case 2:
81                 return "Response Accept";
82         case 3:
83                 return "Response Reject";
84         }
85
86         return "";
87 }
88
89 static const char *sigid2str(uint8_t sigid)
90 {
91         switch (sigid) {
92         case AVDTP_DISCOVER:
93                 return "Discover";
94         case AVDTP_GET_CAPABILITIES:
95                 return "Get Capabilities";
96         case AVDTP_SET_CONFIGURATION:
97                 return "Set Configuration";
98         case AVDTP_GET_CONFIGURATION:
99                 return "Get Configuration";
100         case AVDTP_RECONFIGURE:
101                 return "Reconfigure";
102         case AVDTP_OPEN:
103                 return "Open";
104         case AVDTP_START:
105                 return "Start";
106         case AVDTP_CLOSE:
107                 return "Close";
108         case AVDTP_SUSPEND:
109                 return "Suspend";
110         case AVDTP_ABORT:
111                 return "Abort";
112         case AVDTP_SECURITY_CONTROL:
113                 return "Security Control";
114         case AVDTP_GET_ALL_CAPABILITIES:
115                 return "Get All Capabilities";
116         case AVDTP_DELAYREPORT:
117                 return "Delay Report";
118         default:
119                 return "Reserved";
120         }
121 }
122
123 static const char *error2str(uint8_t error)
124 {
125         switch (error) {
126         case 0x01:
127                 return "BAD_HEADER_FORMAT";
128         case 0x11:
129                 return "BAD_LENGTH";
130         case 0x12:
131                 return "BAD_ACP_SEID";
132         case 0x13:
133                 return "SEP_IN_USE";
134         case 0x14:
135                 return "SEP_NOT_IN_USER";
136         case 0x17:
137                 return "BAD_SERV_CATEGORY";
138         case 0x18:
139                 return "BAD_PAYLOAD_FORMAT";
140         case 0x19:
141                 return "NOT_SUPPORTED_COMMAND";
142         case 0x1a:
143                 return "INVALID_CAPABILITIES";
144         case 0x22:
145                 return "BAD_RECOVERY_TYPE";
146         case 0x23:
147                 return "BAD_MEDIA_TRANSPORT_FORMAT";
148         case 0x25:
149                 return "BAD_RECOVERY_FORMAT";
150         case 0x26:
151                 return "BAD_ROHC_FORMAT";
152         case 0x27:
153                 return "BAD_CP_FORMAT";
154         case 0x28:
155                 return "BAD_MULTIPLEXING_FORMAT";
156         case 0x29:
157                 return "UNSUPPORTED_CONFIGURATION";
158         case 0x31:
159                 return "BAD_STATE";
160         default:
161                 return "Unknown";
162         }
163 }
164
165 static const char *mediatype2str(uint8_t media_type)
166 {
167         switch (media_type) {
168         case 0x00:
169                 return "Audio";
170         case 0x01:
171                 return "Video";
172         case 0x02:
173                 return "Multimedia";
174         default:
175                 return "Reserved";
176         }
177 }
178
179 static const char *mediacodec2str(uint8_t codec)
180 {
181         switch (codec) {
182         case 0x00:
183                 return "SBC";
184         case 0x01:
185                 return "MPEG-1,2 Audio";
186         case 0x02:
187                 return "MPEG-2,4 AAC";
188         case 0x04:
189                 return "ATRAC Family";
190         case 0xff:
191                 return "Non-A2DP";
192         default:
193                 return "Reserved";
194         }
195 }
196
197 static const char *cptype2str(uint8_t cp)
198 {
199         switch (cp) {
200         case 0x0001:
201                 return "DTCP";
202         case 0x0002:
203                 return "SCMS-T";
204         default:
205                 return "Reserved";
206         }
207 }
208
209 static const char *servicecat2str(uint8_t service_cat)
210 {
211         switch (service_cat) {
212         case AVDTP_MEDIA_TRANSPORT:
213                 return "Media Transport";
214         case AVDTP_REPORTING:
215                 return "Reporting";
216         case AVDTP_RECOVERY:
217                 return "Recovery";
218         case AVDTP_CONTENT_PROTECTION:
219                 return "Content Protection";
220         case AVDTP_HEADER_COMPRESSION:
221                 return "Header Compression";
222         case AVDTP_MULTIPLEXING:
223                 return "Multiplexing";
224         case AVDTP_MEDIA_CODEC:
225                 return "Media Codec";
226         case AVDTP_DELAY_REPORTING:
227                 return "Delay Reporting";
228         default:
229                 return "Reserved";
230         }
231 }
232
233 static bool avdtp_reject_common(struct avdtp_frame *avdtp_frame)
234 {
235         struct l2cap_frame *frame = &avdtp_frame->l2cap_frame;
236         uint8_t error;
237
238         if (!l2cap_frame_get_u8(frame, &error))
239                 return false;
240
241         print_field("Error code: %s (0x%02x)", error2str(error), error);
242
243         return true;
244 }
245
246 static bool service_content_protection(struct avdtp_frame *avdtp_frame,
247                                                                 uint8_t losc)
248 {
249         struct l2cap_frame *frame = &avdtp_frame->l2cap_frame;
250         uint16_t type = 0;
251
252         if (losc < 2)
253                 return false;
254
255         if (!l2cap_frame_get_le16(frame, &type))
256                 return false;
257
258         losc -= 2;
259
260         print_field("%*cContent Protection Type: %s (0x%04x)", 2, ' ',
261                                                         cptype2str(type), type);
262
263         /* TODO: decode protection specific information */
264         packet_hexdump(frame->data, losc);
265
266         l2cap_frame_pull(frame, frame, losc);
267
268         return true;
269 }
270
271 static bool service_media_codec(struct avdtp_frame *avdtp_frame, uint8_t losc)
272 {
273         struct l2cap_frame *frame = &avdtp_frame->l2cap_frame;
274         uint8_t type = 0;
275         uint8_t codec = 0;
276
277         if (losc < 2)
278                 return false;
279
280         l2cap_frame_get_u8(frame, &type);
281         l2cap_frame_get_u8(frame, &codec);
282
283         losc -= 2;
284
285         print_field("%*cMedia Type: %s (0x%02x)", 2, ' ',
286                                         mediatype2str(type >> 4), type >> 4);
287
288         print_field("%*cMedia Codec: %s (0x%02x)", 2, ' ',
289                                         mediacodec2str(codec), codec);
290
291         if (is_configuration_sig_id(avdtp_frame->sig_id))
292                 return a2dp_codec_cfg(codec, losc, frame);
293         else
294                 return a2dp_codec_cap(codec, losc, frame);
295 }
296
297 static bool decode_capabilities(struct avdtp_frame *avdtp_frame)
298 {
299         struct l2cap_frame *frame = &avdtp_frame->l2cap_frame;
300         uint8_t service_cat;
301         uint8_t losc;
302
303         while (l2cap_frame_get_u8(frame, &service_cat)) {
304                 print_field("Service Category: %s (0x%02x)",
305                                 servicecat2str(service_cat), service_cat);
306
307                 if (!l2cap_frame_get_u8(frame, &losc))
308                         return false;
309
310                 if (frame->size < losc)
311                         return false;
312
313                 switch (service_cat) {
314                 case AVDTP_CONTENT_PROTECTION:
315                         if (!service_content_protection(avdtp_frame, losc))
316                                 return false;
317                         break;
318                 case AVDTP_MEDIA_CODEC:
319                         if (!service_media_codec(avdtp_frame, losc))
320                                 return false;
321                         break;
322                 case AVDTP_MEDIA_TRANSPORT:
323                 case AVDTP_REPORTING:
324                 case AVDTP_RECOVERY:
325                 case AVDTP_HEADER_COMPRESSION:
326                 case AVDTP_MULTIPLEXING:
327                 case AVDTP_DELAY_REPORTING:
328                 default:
329                         packet_hexdump(frame->data, losc);
330                         l2cap_frame_pull(frame, frame, losc);
331                 }
332
333         }
334
335         return true;
336 }
337
338 static bool avdtp_discover(struct avdtp_frame *avdtp_frame)
339 {
340         struct l2cap_frame *frame = &avdtp_frame->l2cap_frame;
341         uint8_t type = avdtp_frame->hdr & 0x03;
342         uint8_t seid;
343         uint8_t info;
344
345         switch (type) {
346         case AVDTP_MSG_TYPE_COMMAND:
347                 return true;
348         case AVDTP_MSG_TYPE_RESPONSE_ACCEPT:
349                 while (l2cap_frame_get_u8(frame, &seid)) {
350                         print_field("ACP SEID: %d", seid >> 2);
351
352                         if (!l2cap_frame_get_u8(frame, &info))
353                                 return false;
354
355                         print_field("%*cMedia Type: %s (0x%02x)", 2, ' ',
356                                         mediatype2str(info >> 4), info >> 4);
357                         print_field("%*cSEP Type: %s (0x%02x)", 2, ' ',
358                                                 info & 0x08 ? "SNK" : "SRC",
359                                                 (info >> 3) & 0x01);
360                         print_field("%*cIn use: %s", 2, ' ',
361                                                 seid & 0x02 ? "Yes" : "No");
362                 }
363                 return true;
364         case AVDTP_MSG_TYPE_RESPONSE_REJECT:
365                 return avdtp_reject_common(avdtp_frame);
366         }
367
368         return false;
369 }
370
371 static bool avdtp_get_capabilities(struct avdtp_frame *avdtp_frame)
372 {
373         struct l2cap_frame *frame = &avdtp_frame->l2cap_frame;
374         uint8_t type = avdtp_frame->hdr & 0x03;
375         uint8_t seid;
376
377         switch (type) {
378         case AVDTP_MSG_TYPE_COMMAND:
379                 if (!l2cap_frame_get_u8(frame, &seid))
380                         return false;
381
382                 print_field("ACP SEID: %d", seid >> 2);
383
384                 return true;
385         case AVDTP_MSG_TYPE_RESPONSE_ACCEPT:
386                 return decode_capabilities(avdtp_frame);
387         case AVDTP_MSG_TYPE_RESPONSE_REJECT:
388                 return avdtp_reject_common(avdtp_frame);
389         }
390
391         return false;
392 }
393
394 static bool avdtp_set_configuration(struct avdtp_frame *avdtp_frame)
395 {
396         struct l2cap_frame *frame = &avdtp_frame->l2cap_frame;
397         uint8_t type = avdtp_frame->hdr & 0x03;
398         uint8_t acp_seid, int_seid;
399         uint8_t service_cat;
400
401         switch (type) {
402         case AVDTP_MSG_TYPE_COMMAND:
403                 if (!l2cap_frame_get_u8(frame, &acp_seid))
404                         return false;
405
406                 print_field("ACP SEID: %d", acp_seid >> 2);
407
408                 if (!l2cap_frame_get_u8(frame, &int_seid))
409                         return false;
410
411                 print_field("INT SEID: %d", int_seid >> 2);
412
413                 return decode_capabilities(avdtp_frame);
414         case AVDTP_MSG_TYPE_RESPONSE_ACCEPT:
415                 return true;
416         case AVDTP_MSG_TYPE_RESPONSE_REJECT:
417                 if (!l2cap_frame_get_u8(frame, &service_cat))
418                         return false;
419
420                 print_field("Service Category: %s (0x%02x)",
421                                 servicecat2str(service_cat), service_cat);
422
423                 return avdtp_reject_common(avdtp_frame);
424         }
425
426         return false;
427 }
428
429 static bool avdtp_get_configuration(struct avdtp_frame *avdtp_frame)
430 {
431         struct l2cap_frame *frame = &avdtp_frame->l2cap_frame;
432         uint8_t type = avdtp_frame->hdr & 0x03;
433         uint8_t seid;
434
435         switch (type) {
436         case AVDTP_MSG_TYPE_COMMAND:
437                 if (!l2cap_frame_get_u8(frame, &seid))
438                         return false;
439
440                 print_field("ACP SEID: %d", seid >> 2);
441
442                 return true;
443         case AVDTP_MSG_TYPE_RESPONSE_ACCEPT:
444                 return decode_capabilities(avdtp_frame);
445         case AVDTP_MSG_TYPE_RESPONSE_REJECT:
446                 return avdtp_reject_common(avdtp_frame);
447         }
448
449         return false;
450 }
451
452 static bool avdtp_reconfigure(struct avdtp_frame *avdtp_frame)
453 {
454         struct l2cap_frame *frame = &avdtp_frame->l2cap_frame;
455         uint8_t type = avdtp_frame->hdr & 0x03;
456         uint8_t seid;
457         uint8_t service_cat;
458
459         switch (type) {
460         case AVDTP_MSG_TYPE_COMMAND:
461                 if (!l2cap_frame_get_u8(frame, &seid))
462                         return false;
463
464                 print_field("ACP SEID: %d", seid >> 2);
465
466                 return decode_capabilities(avdtp_frame);
467         case AVDTP_MSG_TYPE_RESPONSE_ACCEPT:
468                 return true;
469         case AVDTP_MSG_TYPE_RESPONSE_REJECT:
470                 if (!l2cap_frame_get_u8(frame, &service_cat))
471                         return false;
472
473                 print_field("Service Category: %s (0x%02x)",
474                                 servicecat2str(service_cat), service_cat);
475
476                 return avdtp_reject_common(avdtp_frame);
477         }
478
479         return false;
480 }
481
482 static bool avdtp_open(struct avdtp_frame *avdtp_frame)
483 {
484         struct l2cap_frame *frame = &avdtp_frame->l2cap_frame;
485         uint8_t type = avdtp_frame->hdr & 0x03;
486         uint8_t seid;
487
488         switch (type) {
489         case AVDTP_MSG_TYPE_COMMAND:
490                 if (!l2cap_frame_get_u8(frame, &seid))
491                         return false;
492
493                 print_field("ACP SEID: %d", seid >> 2);
494
495                 return true;
496         case AVDTP_MSG_TYPE_RESPONSE_ACCEPT:
497                 return true;
498         case AVDTP_MSG_TYPE_RESPONSE_REJECT:
499                 return avdtp_reject_common(avdtp_frame);
500         }
501
502         return false;
503 }
504
505 static bool avdtp_start(struct avdtp_frame *avdtp_frame)
506 {
507         struct l2cap_frame *frame = &avdtp_frame->l2cap_frame;
508         uint8_t type = avdtp_frame->hdr & 0x03;
509         uint8_t seid;
510
511         switch (type) {
512         case AVDTP_MSG_TYPE_COMMAND:
513                 if (!l2cap_frame_get_u8(frame, &seid))
514                         return false;
515
516                 print_field("ACP SEID: %d", seid >> 2);
517
518                 while (l2cap_frame_get_u8(frame, &seid))
519                         print_field("ACP SEID: %d", seid >> 2);
520
521                 return true;
522         case AVDTP_MSG_TYPE_RESPONSE_ACCEPT:
523                 return true;
524         case AVDTP_MSG_TYPE_RESPONSE_REJECT:
525                 if (!l2cap_frame_get_u8(frame, &seid))
526                         return false;
527
528                 print_field("ACP SEID: %d", seid >> 2);
529
530                 return avdtp_reject_common(avdtp_frame);
531         }
532
533         return false;
534 }
535
536 static bool avdtp_close(struct avdtp_frame *avdtp_frame)
537 {
538         struct l2cap_frame *frame = &avdtp_frame->l2cap_frame;
539         uint8_t type = avdtp_frame->hdr & 0x03;
540         uint8_t seid;
541
542         switch (type) {
543         case AVDTP_MSG_TYPE_COMMAND:
544                 if (!l2cap_frame_get_u8(frame, &seid))
545                         return false;
546
547                 print_field("ACP SEID: %d", seid >> 2);
548
549                 return true;
550         case AVDTP_MSG_TYPE_RESPONSE_ACCEPT:
551                 return true;
552         case AVDTP_MSG_TYPE_RESPONSE_REJECT:
553                 return avdtp_reject_common(avdtp_frame);
554         }
555
556         return false;
557 }
558
559 static bool avdtp_suspend(struct avdtp_frame *avdtp_frame)
560 {
561         struct l2cap_frame *frame = &avdtp_frame->l2cap_frame;
562         uint8_t type = avdtp_frame->hdr & 0x03;
563         uint8_t seid;
564
565         switch (type) {
566         case AVDTP_MSG_TYPE_COMMAND:
567                 if (!l2cap_frame_get_u8(frame, &seid))
568                         return false;
569
570                 print_field("ACP SEID: %d", seid >> 2);
571
572                 while (l2cap_frame_get_u8(frame, &seid))
573                         print_field("ACP SEID: %d", seid >> 2);
574
575                 return true;
576         case AVDTP_MSG_TYPE_RESPONSE_ACCEPT:
577                 return true;
578         case AVDTP_MSG_TYPE_RESPONSE_REJECT:
579                 if (!l2cap_frame_get_u8(frame, &seid))
580                         return false;
581
582                 print_field("ACP SEID: %d", seid >> 2);
583
584                 return avdtp_reject_common(avdtp_frame);
585         }
586
587         return false;
588 }
589
590 static bool avdtp_abort(struct avdtp_frame *avdtp_frame)
591 {
592         struct l2cap_frame *frame = &avdtp_frame->l2cap_frame;
593         uint8_t type = avdtp_frame->hdr & 0x03;
594         uint8_t seid;
595
596         switch (type) {
597         case AVDTP_MSG_TYPE_COMMAND:
598                 if (!l2cap_frame_get_u8(frame, &seid))
599                         return false;
600
601                 print_field("ACP SEID: %d", seid >> 2);
602
603                 return true;
604         case AVDTP_MSG_TYPE_RESPONSE_ACCEPT:
605                 return true;
606         }
607
608         return false;
609 }
610
611 static bool avdtp_security_control(struct avdtp_frame *avdtp_frame)
612 {
613         struct l2cap_frame *frame = &avdtp_frame->l2cap_frame;
614         uint8_t type = avdtp_frame->hdr & 0x03;
615         uint8_t seid;
616
617         switch (type) {
618         case AVDTP_MSG_TYPE_COMMAND:
619                 if (!l2cap_frame_get_u8(frame, &seid))
620                         return false;
621
622                 print_field("ACP SEID: %d", seid >> 2);
623
624                 /* TODO: decode more information */
625                 packet_hexdump(frame->data, frame->size);
626                 return true;
627         case AVDTP_MSG_TYPE_RESPONSE_ACCEPT:
628                 /* TODO: decode more information */
629                 packet_hexdump(frame->data, frame->size);
630                 return true;
631         case AVDTP_MSG_TYPE_RESPONSE_REJECT:
632                 return avdtp_reject_common(avdtp_frame);
633         }
634
635         return false;
636 }
637
638 static bool avdtp_delayreport(struct avdtp_frame *avdtp_frame)
639 {
640         struct l2cap_frame *frame = &avdtp_frame->l2cap_frame;
641         uint8_t type = avdtp_frame->hdr & 0x03;
642         uint8_t seid;
643         uint16_t delay;
644
645         switch (type) {
646         case AVDTP_MSG_TYPE_COMMAND:
647                 if (!l2cap_frame_get_u8(frame, &seid))
648                         return false;
649
650                 print_field("ACP SEID: %d", seid >> 2);
651
652                 if (!l2cap_frame_get_be16(frame, &delay))
653                         return false;
654
655                 print_field("Delay: %d.%dms", delay / 10, delay % 10);
656
657                 return true;
658         case AVDTP_MSG_TYPE_RESPONSE_ACCEPT:
659                 return true;
660         case AVDTP_MSG_TYPE_RESPONSE_REJECT:
661                 return avdtp_reject_common(avdtp_frame);
662         }
663
664         return false;
665 }
666
667 static bool avdtp_signalling_packet(struct avdtp_frame *avdtp_frame)
668 {
669         struct l2cap_frame *frame = &avdtp_frame->l2cap_frame;
670         const char *pdu_color;
671         uint8_t hdr;
672         uint8_t sig_id;
673         uint8_t nosp = 0;
674
675         if (frame->in)
676                 pdu_color = COLOR_MAGENTA;
677         else
678                 pdu_color = COLOR_BLUE;
679
680         if (!l2cap_frame_get_u8(frame, &hdr))
681                 return false;
682
683         avdtp_frame->hdr = hdr;
684
685         /* Continue Packet || End Packet */
686         if (((hdr & 0x0c) == 0x08) || ((hdr & 0x0c) == 0x0c)) {
687                 /* TODO: handle fragmentation */
688                 packet_hexdump(frame->data, frame->size);
689                 return true;
690         }
691
692         /* Start Packet */
693         if ((hdr & 0x0c) == 0x04) {
694                 if (!l2cap_frame_get_u8(frame, &nosp))
695                         return false;
696         }
697
698         if (!l2cap_frame_get_u8(frame, &sig_id))
699                 return false;
700
701         sig_id &= 0x3f;
702
703         avdtp_frame->sig_id = sig_id;
704
705         print_indent(6, pdu_color, "AVDTP: ", sigid2str(sig_id), COLOR_OFF,
706                         " (0x%02x) %s (0x%02x) type 0x%02x label %d nosp %d",
707                         sig_id, msgtype2str(hdr & 0x03), hdr & 0x03,
708                         hdr & 0x0c, hdr >> 4, nosp);
709
710         /* Start Packet */
711         if ((hdr & 0x0c) == 0x04) {
712                 /* TODO: handle fragmentation */
713                 packet_hexdump(frame->data, frame->size);
714                 return true;
715         }
716
717         switch (sig_id) {
718         case AVDTP_DISCOVER:
719                 return avdtp_discover(avdtp_frame);
720         case AVDTP_GET_CAPABILITIES:
721         case AVDTP_GET_ALL_CAPABILITIES:
722                 return avdtp_get_capabilities(avdtp_frame);
723         case AVDTP_SET_CONFIGURATION:
724                 return avdtp_set_configuration(avdtp_frame);
725         case AVDTP_GET_CONFIGURATION:
726                 return avdtp_get_configuration(avdtp_frame);
727         case AVDTP_RECONFIGURE:
728                 return avdtp_reconfigure(avdtp_frame);
729         case AVDTP_OPEN:
730                 return avdtp_open(avdtp_frame);
731         case AVDTP_START:
732                 return avdtp_start(avdtp_frame);
733         case AVDTP_CLOSE:
734                 return avdtp_close(avdtp_frame);
735         case AVDTP_SUSPEND:
736                 return avdtp_suspend(avdtp_frame);
737         case AVDTP_ABORT:
738                 return avdtp_abort(avdtp_frame);
739         case AVDTP_SECURITY_CONTROL:
740                 return avdtp_security_control(avdtp_frame);
741         case AVDTP_DELAYREPORT:
742                 return avdtp_delayreport(avdtp_frame);
743         }
744
745         packet_hexdump(frame->data, frame->size);
746
747         return true;
748 }
749
750 void avdtp_packet(const struct l2cap_frame *frame)
751 {
752         struct avdtp_frame avdtp_frame;
753         bool ret;
754
755         l2cap_frame_pull(&avdtp_frame.l2cap_frame, frame, 0);
756
757         switch (frame->seq_num) {
758         case 1:
759                 ret = avdtp_signalling_packet(&avdtp_frame);
760                 break;
761         default:
762                 if (packet_has_filter(PACKET_FILTER_SHOW_A2DP_STREAM))
763                         packet_hexdump(frame->data, frame->size);
764                 return;
765         }
766
767         if (!ret) {
768                 print_text(COLOR_ERROR, "PDU malformed");
769                 packet_hexdump(frame->data, frame->size);
770         }
771 }