-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathavctp.c
2446 lines (1967 loc) · 55.6 KB
/
avctp.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
*
* BlueZ - Bluetooth protocol stack for Linux
*
* Copyright (C) 2011-2014 Intel Corporation
* Copyright (C) 2002-2010 Marcel Holtmann <marcel@holtmann.org>
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <inttypes.h>
#include "lib/bluetooth.h"
#include "src/shared/util.h"
#include "bt.h"
#include "packet.h"
#include "display.h"
#include "l2cap.h"
#include "uuid.h"
#include "keys.h"
#include "sdp.h"
#include "avctp.h"
/* ctype entries */
#define AVC_CTYPE_CONTROL 0x0
#define AVC_CTYPE_STATUS 0x1
#define AVC_CTYPE_SPECIFIC_INQUIRY 0x2
#define AVC_CTYPE_NOTIFY 0x3
#define AVC_CTYPE_GENERAL_INQUIRY 0x4
#define AVC_CTYPE_NOT_IMPLEMENTED 0x8
#define AVC_CTYPE_ACCEPTED 0x9
#define AVC_CTYPE_REJECTED 0xA
#define AVC_CTYPE_IN_TRANSITION 0xB
#define AVC_CTYPE_STABLE 0xC
#define AVC_CTYPE_CHANGED 0xD
#define AVC_CTYPE_INTERIM 0xF
/* subunit type */
#define AVC_SUBUNIT_MONITOR 0x00
#define AVC_SUBUNIT_AUDIO 0x01
#define AVC_SUBUNIT_PRINTER 0x02
#define AVC_SUBUNIT_DISC 0x03
#define AVC_SUBUNIT_TAPE 0x04
#define AVC_SUBUNIT_TURNER 0x05
#define AVC_SUBUNIT_CA 0x06
#define AVC_SUBUNIT_CAMERA 0x07
#define AVC_SUBUNIT_PANEL 0x09
#define AVC_SUBUNIT_BULLETIN_BOARD 0x0a
#define AVC_SUBUNIT_CAMERA_STORAGE 0x0b
#define AVC_SUBUNIT_VENDOR_UNIQUE 0x0c
#define AVC_SUBUNIT_EXTENDED 0x1e
#define AVC_SUBUNIT_UNIT 0x1f
/* opcodes */
#define AVC_OP_VENDORDEP 0x00
#define AVC_OP_UNITINFO 0x30
#define AVC_OP_SUBUNITINFO 0x31
#define AVC_OP_PASSTHROUGH 0x7c
/* notification events */
#define AVRCP_EVENT_PLAYBACK_STATUS_CHANGED 0x01
#define AVRCP_EVENT_TRACK_CHANGED 0x02
#define AVRCP_EVENT_TRACK_REACHED_END 0x03
#define AVRCP_EVENT_TRACK_REACHED_START 0x04
#define AVRCP_EVENT_PLAYBACK_POS_CHANGED 0x05
#define AVRCP_EVENT_BATT_STATUS_CHANGED 0x06
#define AVRCP_EVENT_SYSTEM_STATUS_CHANGED 0x07
#define AVRCP_EVENT_PLAYER_APPLICATION_SETTING_CHANGED 0x08
#define AVRCP_EVENT_NOW_PLAYING_CONTENT_CHANGED 0x09
#define AVRCP_EVENT_AVAILABLE_PLAYERS_CHANGED 0x0a
#define AVRCP_EVENT_ADDRESSED_PLAYER_CHANGED 0x0b
#define AVRCP_EVENT_UIDS_CHANGED 0x0c
#define AVRCP_EVENT_VOLUME_CHANGED 0x0d
/* error statuses */
#define AVRCP_STATUS_INVALID_COMMAND 0x00
#define AVRCP_STATUS_INVALID_PARAMETER 0x01
#define AVRCP_STATUS_NOT_FOUND 0x02
#define AVRCP_STATUS_INTERNAL_ERROR 0x03
#define AVRCP_STATUS_SUCCESS 0x04
#define AVRCP_STATUS_UID_CHANGED 0x05
#define AVRCP_STATUS_INVALID_DIRECTION 0x07
#define AVRCP_STATUS_NOT_DIRECTORY 0x08
#define AVRCP_STATUS_DOES_NOT_EXIST 0x09
#define AVRCP_STATUS_INVALID_SCOPE 0x0a
#define AVRCP_STATUS_OUT_OF_BOUNDS 0x0b
#define AVRCP_STATUS_IS_DIRECTORY 0x0c
#define AVRCP_STATUS_MEDIA_IN_USE 0x0d
#define AVRCP_STATUS_NOW_PLAYING_LIST_FULL 0x0e
#define AVRCP_STATUS_SEARCH_NOT_SUPPORTED 0x0f
#define AVRCP_STATUS_SEARCH_IN_PROGRESS 0x10
#define AVRCP_STATUS_INVALID_PLAYER_ID 0x11
#define AVRCP_STATUS_PLAYER_NOT_BROWSABLE 0x12
#define AVRCP_STATUS_PLAYER_NOT_ADDRESSED 0x13
#define AVRCP_STATUS_NO_VALID_SEARCH_RESULTS 0x14
#define AVRCP_STATUS_NO_AVAILABLE_PLAYERS 0x15
#define AVRCP_STATUS_ADDRESSED_PLAYER_CHANGED 0x16
/* pdu ids */
#define AVRCP_GET_CAPABILITIES 0x10
#define AVRCP_LIST_PLAYER_ATTRIBUTES 0x11
#define AVRCP_LIST_PLAYER_VALUES 0x12
#define AVRCP_GET_CURRENT_PLAYER_VALUE 0x13
#define AVRCP_SET_PLAYER_VALUE 0x14
#define AVRCP_GET_PLAYER_ATTRIBUTE_TEXT 0x15
#define AVRCP_GET_PLAYER_VALUE_TEXT 0x16
#define AVRCP_DISPLAYABLE_CHARSET 0x17
#define AVRCP_CT_BATTERY_STATUS 0x18
#define AVRCP_GET_ELEMENT_ATTRIBUTES 0x20
#define AVRCP_GET_PLAY_STATUS 0x30
#define AVRCP_REGISTER_NOTIFICATION 0x31
#define AVRCP_REQUEST_CONTINUING 0x40
#define AVRCP_ABORT_CONTINUING 0x41
#define AVRCP_SET_ABSOLUTE_VOLUME 0x50
#define AVRCP_SET_ADDRESSED_PLAYER 0x60
#define AVRCP_SET_BROWSED_PLAYER 0x70
#define AVRCP_GET_FOLDER_ITEMS 0x71
#define AVRCP_CHANGE_PATH 0x72
#define AVRCP_GET_ITEM_ATTRIBUTES 0x73
#define AVRCP_PLAY_ITEM 0x74
#define AVRCP_SEARCH 0x80
#define AVRCP_ADD_TO_NOW_PLAYING 0x90
#define AVRCP_GENERAL_REJECT 0xA0
/* Packet types */
#define AVRCP_PACKET_TYPE_SINGLE 0x00
#define AVRCP_PACKET_TYPE_START 0x01
#define AVRCP_PACKET_TYPE_CONTINUING 0x02
#define AVRCP_PACKET_TYPE_END 0x03
/* player attributes */
#define AVRCP_ATTRIBUTE_ILEGAL 0x00
#define AVRCP_ATTRIBUTE_EQUALIZER 0x01
#define AVRCP_ATTRIBUTE_REPEAT_MODE 0x02
#define AVRCP_ATTRIBUTE_SHUFFLE 0x03
#define AVRCP_ATTRIBUTE_SCAN 0x04
/* media attributes */
#define AVRCP_MEDIA_ATTRIBUTE_ILLEGAL 0x00
#define AVRCP_MEDIA_ATTRIBUTE_TITLE 0x01
#define AVRCP_MEDIA_ATTRIBUTE_ARTIST 0x02
#define AVRCP_MEDIA_ATTRIBUTE_ALBUM 0x03
#define AVRCP_MEDIA_ATTRIBUTE_TRACK 0x04
#define AVRCP_MEDIA_ATTRIBUTE_TOTAL 0x05
#define AVRCP_MEDIA_ATTRIBUTE_GENRE 0x06
#define AVRCP_MEDIA_ATTRIBUTE_DURATION 0x07
/* play status */
#define AVRCP_PLAY_STATUS_STOPPED 0x00
#define AVRCP_PLAY_STATUS_PLAYING 0x01
#define AVRCP_PLAY_STATUS_PAUSED 0x02
#define AVRCP_PLAY_STATUS_FWD_SEEK 0x03
#define AVRCP_PLAY_STATUS_REV_SEEK 0x04
#define AVRCP_PLAY_STATUS_ERROR 0xFF
/* media scope */
#define AVRCP_MEDIA_PLAYER_LIST 0x00
#define AVRCP_MEDIA_PLAYER_VFS 0x01
#define AVRCP_MEDIA_SEARCH 0x02
#define AVRCP_MEDIA_NOW_PLAYING 0x03
/* Media Item Type */
#define AVRCP_MEDIA_PLAYER_ITEM_TYPE 0x01
#define AVRCP_FOLDER_ITEM_TYPE 0x02
#define AVRCP_MEDIA_ELEMENT_ITEM_TYPE 0x03
/* operands in passthrough commands */
#define AVC_PANEL_VOLUME_UP 0x41
#define AVC_PANEL_VOLUME_DOWN 0x42
#define AVC_PANEL_MUTE 0x43
#define AVC_PANEL_PLAY 0x44
#define AVC_PANEL_STOP 0x45
#define AVC_PANEL_PAUSE 0x46
#define AVC_PANEL_RECORD 0x47
#define AVC_PANEL_REWIND 0x48
#define AVC_PANEL_FAST_FORWARD 0x49
#define AVC_PANEL_EJECT 0x4a
#define AVC_PANEL_FORWARD 0x4b
#define AVC_PANEL_BACKWARD 0x4c
struct avctp_frame {
uint8_t hdr;
uint8_t pt;
uint16_t pid;
struct l2cap_frame l2cap_frame;
};
static struct avrcp_continuing {
uint16_t num;
uint16_t size;
} avrcp_continuing;
static const char *ctype2str(uint8_t ctype)
{
switch (ctype & 0x0f) {
case AVC_CTYPE_CONTROL:
return "Control";
case AVC_CTYPE_STATUS:
return "Status";
case AVC_CTYPE_SPECIFIC_INQUIRY:
return "Specific Inquiry";
case AVC_CTYPE_NOTIFY:
return "Notify";
case AVC_CTYPE_GENERAL_INQUIRY:
return "General Inquiry";
case AVC_CTYPE_NOT_IMPLEMENTED:
return "Not Implemented";
case AVC_CTYPE_ACCEPTED:
return "Accepted";
case AVC_CTYPE_REJECTED:
return "Rejected";
case AVC_CTYPE_IN_TRANSITION:
return "In Transition";
case AVC_CTYPE_STABLE:
return "Stable";
case AVC_CTYPE_CHANGED:
return "Changed";
case AVC_CTYPE_INTERIM:
return "Interim";
default:
return "Unknown";
}
}
static const char *subunit2str(uint8_t subunit)
{
switch (subunit) {
case AVC_SUBUNIT_MONITOR:
return "Monitor";
case AVC_SUBUNIT_AUDIO:
return "Audio";
case AVC_SUBUNIT_PRINTER:
return "Printer";
case AVC_SUBUNIT_DISC:
return "Disc";
case AVC_SUBUNIT_TAPE:
return "Tape";
case AVC_SUBUNIT_TURNER:
return "Turner";
case AVC_SUBUNIT_CA:
return "CA";
case AVC_SUBUNIT_CAMERA:
return "Camera";
case AVC_SUBUNIT_PANEL:
return "Panel";
case AVC_SUBUNIT_BULLETIN_BOARD:
return "Bulleting Board";
case AVC_SUBUNIT_CAMERA_STORAGE:
return "Camera Storage";
case AVC_SUBUNIT_VENDOR_UNIQUE:
return "Vendor Unique";
case AVC_SUBUNIT_EXTENDED:
return "Extended to next byte";
case AVC_SUBUNIT_UNIT:
return "Unit";
default:
return "Reserved";
}
}
static const char *opcode2str(uint8_t opcode)
{
switch (opcode) {
case AVC_OP_VENDORDEP:
return "Vendor Dependent";
case AVC_OP_UNITINFO:
return "Unit Info";
case AVC_OP_SUBUNITINFO:
return "Subunit Info";
case AVC_OP_PASSTHROUGH:
return "Passthrough";
default:
return "Unknown";
}
}
static char *cap2str(uint8_t cap)
{
switch (cap) {
case 0x2:
return "CompanyID";
case 0x3:
return "EventsID";
default:
return "Unknown";
}
}
static char *event2str(uint8_t event)
{
switch (event) {
case AVRCP_EVENT_PLAYBACK_STATUS_CHANGED:
return "EVENT_PLAYBACK_STATUS_CHANGED";
case AVRCP_EVENT_TRACK_CHANGED:
return "EVENT_TRACK_CHANGED";
case AVRCP_EVENT_TRACK_REACHED_END:
return "EVENT_TRACK_REACHED_END";
case AVRCP_EVENT_TRACK_REACHED_START:
return "EVENT_TRACK_REACHED_START";
case AVRCP_EVENT_PLAYBACK_POS_CHANGED:
return "EVENT_PLAYBACK_POS_CHANGED";
case AVRCP_EVENT_BATT_STATUS_CHANGED:
return "EVENT_BATT_STATUS_CHANGED";
case AVRCP_EVENT_SYSTEM_STATUS_CHANGED:
return "EVENT_SYSTEM_STATUS_CHANGED";
case AVRCP_EVENT_PLAYER_APPLICATION_SETTING_CHANGED:
return "EVENT_PLAYER_APPLICATION_SETTING_CHANGED";
case AVRCP_EVENT_NOW_PLAYING_CONTENT_CHANGED:
return "EVENT_NOW_PLAYING_CONTENT_CHANGED";
case AVRCP_EVENT_AVAILABLE_PLAYERS_CHANGED:
return "EVENT_AVAILABLE_PLAYERS_CHANGED";
case AVRCP_EVENT_ADDRESSED_PLAYER_CHANGED:
return "EVENT_ADDRESSED_PLAYER_CHANGED";
case AVRCP_EVENT_UIDS_CHANGED:
return "EVENT_UIDS_CHANGED";
case AVRCP_EVENT_VOLUME_CHANGED:
return "EVENT_VOLUME_CHANGED";
default:
return "Reserved";
}
}
static const char *error2str(uint8_t status)
{
switch (status) {
case AVRCP_STATUS_INVALID_COMMAND:
return "Invalid Command";
case AVRCP_STATUS_INVALID_PARAMETER:
return "Invalid Parameter";
case AVRCP_STATUS_NOT_FOUND:
return "Not Found";
case AVRCP_STATUS_INTERNAL_ERROR:
return "Internal Error";
case AVRCP_STATUS_SUCCESS:
return "Success";
case AVRCP_STATUS_UID_CHANGED:
return "UID Changed";
case AVRCP_STATUS_INVALID_DIRECTION:
return "Invalid Direction";
case AVRCP_STATUS_NOT_DIRECTORY:
return "Not a Directory";
case AVRCP_STATUS_DOES_NOT_EXIST:
return "Does Not Exist";
case AVRCP_STATUS_INVALID_SCOPE:
return "Invalid Scope";
case AVRCP_STATUS_OUT_OF_BOUNDS:
return "Range Out of Bonds";
case AVRCP_STATUS_MEDIA_IN_USE:
return "Media in Use";
case AVRCP_STATUS_IS_DIRECTORY:
return "UID is a Directory";
case AVRCP_STATUS_NOW_PLAYING_LIST_FULL:
return "Now Playing List Full";
case AVRCP_STATUS_SEARCH_NOT_SUPPORTED:
return "Seach Not Supported";
case AVRCP_STATUS_SEARCH_IN_PROGRESS:
return "Search in Progress";
case AVRCP_STATUS_INVALID_PLAYER_ID:
return "Invalid Player ID";
case AVRCP_STATUS_PLAYER_NOT_BROWSABLE:
return "Player Not Browsable";
case AVRCP_STATUS_PLAYER_NOT_ADDRESSED:
return "Player Not Addressed";
case AVRCP_STATUS_NO_VALID_SEARCH_RESULTS:
return "No Valid Search Result";
case AVRCP_STATUS_NO_AVAILABLE_PLAYERS:
return "No Available Players";
case AVRCP_STATUS_ADDRESSED_PLAYER_CHANGED:
return "Addressed Player Changed";
default:
return "Unknown";
}
}
static const char *pdu2str(uint8_t pduid)
{
switch (pduid) {
case AVRCP_GET_CAPABILITIES:
return "GetCapabilities";
case AVRCP_LIST_PLAYER_ATTRIBUTES:
return "ListPlayerApplicationSettingAttributes";
case AVRCP_LIST_PLAYER_VALUES:
return "ListPlayerApplicationSettingValues";
case AVRCP_GET_CURRENT_PLAYER_VALUE:
return "GetCurrentPlayerApplicationSettingValue";
case AVRCP_SET_PLAYER_VALUE:
return "SetPlayerApplicationSettingValue";
case AVRCP_GET_PLAYER_ATTRIBUTE_TEXT:
return "GetPlayerApplicationSettingAttributeText";
case AVRCP_GET_PLAYER_VALUE_TEXT:
return "GetPlayerApplicationSettingValueText";
case AVRCP_DISPLAYABLE_CHARSET:
return "InformDisplayableCharacterSet";
case AVRCP_CT_BATTERY_STATUS:
return "InformBatteryStatusOfCT";
case AVRCP_GET_ELEMENT_ATTRIBUTES:
return "GetElementAttributes";
case AVRCP_GET_PLAY_STATUS:
return "GetPlayStatus";
case AVRCP_REGISTER_NOTIFICATION:
return "RegisterNotification";
case AVRCP_REQUEST_CONTINUING:
return "RequestContinuingResponse";
case AVRCP_ABORT_CONTINUING:
return "AbortContinuingResponse";
case AVRCP_SET_ABSOLUTE_VOLUME:
return "SetAbsoluteVolume";
case AVRCP_SET_ADDRESSED_PLAYER:
return "SetAddressedPlayer";
case AVRCP_SET_BROWSED_PLAYER:
return "SetBrowsedPlayer";
case AVRCP_GET_FOLDER_ITEMS:
return "GetFolderItems";
case AVRCP_CHANGE_PATH:
return "ChangePath";
case AVRCP_GET_ITEM_ATTRIBUTES:
return "GetItemAttributes";
case AVRCP_PLAY_ITEM:
return "PlayItem";
case AVRCP_SEARCH:
return "Search";
case AVRCP_ADD_TO_NOW_PLAYING:
return "AddToNowPlaying";
case AVRCP_GENERAL_REJECT:
return "GeneralReject";
default:
return "Unknown";
}
}
static const char *pt2str(uint8_t pt)
{
switch (pt) {
case AVRCP_PACKET_TYPE_SINGLE:
return "Single";
case AVRCP_PACKET_TYPE_START:
return "Start";
case AVRCP_PACKET_TYPE_CONTINUING:
return "Continuing";
case AVRCP_PACKET_TYPE_END:
return "End";
default:
return "Unknown";
}
}
static const char *attr2str(uint8_t attr)
{
switch (attr) {
case AVRCP_ATTRIBUTE_ILEGAL:
return "Illegal";
case AVRCP_ATTRIBUTE_EQUALIZER:
return "Equalizer ON/OFF Status";
case AVRCP_ATTRIBUTE_REPEAT_MODE:
return "Repeat Mode Status";
case AVRCP_ATTRIBUTE_SHUFFLE:
return "Shuffle ON/OFF Status";
case AVRCP_ATTRIBUTE_SCAN:
return "Scan ON/OFF Status";
default:
return "Unknown";
}
}
static const char *value2str(uint8_t attr, uint8_t value)
{
switch (attr) {
case AVRCP_ATTRIBUTE_ILEGAL:
return "Illegal";
case AVRCP_ATTRIBUTE_EQUALIZER:
switch (value) {
case 0x01:
return "OFF";
case 0x02:
return "ON";
default:
return "Reserved";
}
case AVRCP_ATTRIBUTE_REPEAT_MODE:
switch (value) {
case 0x01:
return "OFF";
case 0x02:
return "Single Track Repeat";
case 0x03:
return "All Track Repeat";
case 0x04:
return "Group Repeat";
default:
return "Reserved";
}
case AVRCP_ATTRIBUTE_SHUFFLE:
switch (value) {
case 0x01:
return "OFF";
case 0x02:
return "All Track Suffle";
case 0x03:
return "Group Suffle";
default:
return "Reserved";
}
case AVRCP_ATTRIBUTE_SCAN:
switch (value) {
case 0x01:
return "OFF";
case 0x02:
return "All Track Scan";
case 0x03:
return "Group Scan";
default:
return "Reserved";
}
default:
return "Unknown";
}
}
static const char *charset2str(uint16_t charset)
{
switch (charset) {
case 1:
case 2:
return "Reserved";
case 3:
return "ASCII";
case 4:
return "ISO_8859-1";
case 5:
return "ISO_8859-2";
case 6:
return "ISO_8859-3";
case 7:
return "ISO_8859-4";
case 8:
return "ISO_8859-5";
case 9:
return "ISO_8859-6";
case 10:
return "ISO_8859-7";
case 11:
return "ISO_8859-8";
case 12:
return "ISO_8859-9";
case 106:
return "UTF-8";
default:
return "Unknown";
}
}
static const char *mediattr2str(uint32_t attr)
{
switch (attr) {
case AVRCP_MEDIA_ATTRIBUTE_ILLEGAL:
return "Illegal";
case AVRCP_MEDIA_ATTRIBUTE_TITLE:
return "Title";
case AVRCP_MEDIA_ATTRIBUTE_ARTIST:
return "Artist";
case AVRCP_MEDIA_ATTRIBUTE_ALBUM:
return "Album";
case AVRCP_MEDIA_ATTRIBUTE_TRACK:
return "Track";
case AVRCP_MEDIA_ATTRIBUTE_TOTAL:
return "Track Total";
case AVRCP_MEDIA_ATTRIBUTE_GENRE:
return "Genre";
case AVRCP_MEDIA_ATTRIBUTE_DURATION:
return "Track duration";
default:
return "Reserved";
}
}
static const char *playstatus2str(uint8_t status)
{
switch (status) {
case AVRCP_PLAY_STATUS_STOPPED:
return "STOPPED";
case AVRCP_PLAY_STATUS_PLAYING:
return "PLAYING";
case AVRCP_PLAY_STATUS_PAUSED:
return "PAUSED";
case AVRCP_PLAY_STATUS_FWD_SEEK:
return "FWD_SEEK";
case AVRCP_PLAY_STATUS_REV_SEEK:
return "REV_SEEK";
case AVRCP_PLAY_STATUS_ERROR:
return "ERROR";
default:
return "Unknown";
}
}
static const char *status2str(uint8_t status)
{
switch (status) {
case 0x0:
return "NORMAL";
case 0x1:
return "WARNING";
case 0x2:
return "CRITICAL";
case 0x3:
return "EXTERNAL";
case 0x4:
return "FULL_CHARGE";
default:
return "Reserved";
}
}
static const char *scope2str(uint8_t scope)
{
switch (scope) {
case AVRCP_MEDIA_PLAYER_LIST:
return "Media Player List";
case AVRCP_MEDIA_PLAYER_VFS:
return "Media Player Virtual Filesystem";
case AVRCP_MEDIA_SEARCH:
return "Search";
case AVRCP_MEDIA_NOW_PLAYING:
return "Now Playing";
default:
return "Unknown";
}
}
static char *op2str(uint8_t op)
{
switch (op & 0x7f) {
case AVC_PANEL_VOLUME_UP:
return "VOLUME UP";
case AVC_PANEL_VOLUME_DOWN:
return "VOLUME DOWN";
case AVC_PANEL_MUTE:
return "MUTE";
case AVC_PANEL_PLAY:
return "PLAY";
case AVC_PANEL_STOP:
return "STOP";
case AVC_PANEL_PAUSE:
return "PAUSE";
case AVC_PANEL_RECORD:
return "RECORD";
case AVC_PANEL_REWIND:
return "REWIND";
case AVC_PANEL_FAST_FORWARD:
return "FAST FORWARD";
case AVC_PANEL_EJECT:
return "EJECT";
case AVC_PANEL_FORWARD:
return "FORWARD";
case AVC_PANEL_BACKWARD:
return "BACKWARD";
default:
return "UNKNOWN";
}
}
static const char *type2str(uint8_t type)
{
switch (type) {
case AVRCP_MEDIA_PLAYER_ITEM_TYPE:
return "Media Player";
case AVRCP_FOLDER_ITEM_TYPE:
return "Folder";
case AVRCP_MEDIA_ELEMENT_ITEM_TYPE:
return "Media Element";
default:
return "Unknown";
}
}
static const char *playertype2str(uint8_t type)
{
switch (type & 0x0F) {
case 0x01:
return "Audio";
case 0x02:
return "Video";
case 0x03:
return "Audio, Video";
case 0x04:
return "Audio Broadcasting";
case 0x05:
return "Audio, Audio Broadcasting";
case 0x06:
return "Video, Audio Broadcasting";
case 0x07:
return "Audio, Video, Audio Broadcasting";
case 0x08:
return "Video Broadcasting";
case 0x09:
return "Audio, Video Broadcasting";
case 0x0A:
return "Video, Video Broadcasting";
case 0x0B:
return "Audio, Video, Video Broadcasting";
case 0x0C:
return "Audio Broadcasting, Video Broadcasting";
case 0x0D:
return "Audio, Audio Broadcasting, Video Broadcasting";
case 0x0E:
return "Video, Audio Broadcasting, Video Broadcasting";
case 0x0F:
return "Audio, Video, Audio Broadcasting, Video Broadcasting";
}
return "None";
}
static const char *playersubtype2str(uint32_t subtype)
{
switch (subtype & 0x03) {
case 0x01:
return "Audio Book";
case 0x02:
return "Podcast";
case 0x03:
return "Audio Book, Podcast";
}
return "None";
}
static const char *foldertype2str(uint8_t type)
{
switch (type) {
case 0x00:
return "Mixed";
case 0x01:
return "Titles";
case 0x02:
return "Albuns";
case 0x03:
return "Artists";
case 0x04:
return "Genres";
case 0x05:
return "Playlists";
case 0x06:
return "Years";
}
return "Reserved";
}
static const char *elementtype2str(uint8_t type)
{
switch (type) {
case 0x00:
return "Audio";
case 0x01:
return "Video";
}
return "Reserved";
}
static bool avrcp_passthrough_packet(struct avctp_frame *avctp_frame,
uint8_t indent)
{
struct l2cap_frame *frame = &avctp_frame->l2cap_frame;
uint8_t op, len;
if (!l2cap_frame_get_u8(frame, &op))
return false;
print_field("%*cOperation: 0x%02x (%s %s)", (indent - 8), ' ', op,
op2str(op), op & 0x80 ? "Released" : "Pressed");
if (!l2cap_frame_get_u8(frame, &len))
return false;
print_field("%*cLength: 0x%02x", (indent - 8), ' ', len);
packet_hexdump(frame->data, frame->size);
return true;
}
static bool avrcp_get_capabilities(struct avctp_frame *avctp_frame,
uint8_t ctype, uint8_t len,
uint8_t indent)
{
struct l2cap_frame *frame = &avctp_frame->l2cap_frame;
uint8_t cap, count;
int i;
if (!l2cap_frame_get_u8(frame, &cap))
return false;
print_field("%*cCapabilityID: 0x%02x (%s)", (indent - 8), ' ', cap,
cap2str(cap));
if (len == 1)
return true;
if (!l2cap_frame_get_u8(frame, &count))
return false;
print_field("%*cCapabilityCount: 0x%02x", (indent - 8), ' ', count);
switch (cap) {
case 0x2:
for (; count > 0; count--) {
uint8_t company[3];
if (!l2cap_frame_get_u8(frame, &company[0]) ||
!l2cap_frame_get_u8(frame, &company[1]) ||
!l2cap_frame_get_u8(frame, &company[2]))
return false;
print_field("%*c%s: 0x%02x%02x%02x", (indent - 8), ' ',
cap2str(cap), company[0], company[1],
company[2]);
}
break;
case 0x3:
for (i = 0; count > 0; count--, i++) {
uint8_t event;
if (!l2cap_frame_get_u8(frame, &event))
return false;
print_field("%*c%s: 0x%02x (%s)", (indent - 8), ' ',
cap2str(cap), event, event2str(event));
}
break;
default:
packet_hexdump(frame->data, frame->size);
}
return true;
}
static bool avrcp_list_player_attributes(struct avctp_frame *avctp_frame,
uint8_t ctype, uint8_t len,
uint8_t indent)
{
struct l2cap_frame *frame = &avctp_frame->l2cap_frame;
uint8_t num;
int i;
if (len == 0)
return true;
if (!l2cap_frame_get_u8(frame, &num))
return false;
print_field("%*cAttributeCount: 0x%02x", (indent - 8), ' ', num);
for (i = 0; num > 0; num--, i++) {
uint8_t attr;
if (!l2cap_frame_get_u8(frame, &attr))
return false;
print_field("%*cAttributeID: 0x%02x (%s)", (indent - 8), ' ',
attr, attr2str(attr));
}
return true;
}
static bool avrcp_list_player_values(struct avctp_frame *avctp_frame,
uint8_t ctype, uint8_t len,
uint8_t indent)
{
struct l2cap_frame *frame = &avctp_frame->l2cap_frame;
static uint8_t attr = 0;
uint8_t num;
if (ctype > AVC_CTYPE_GENERAL_INQUIRY)
goto response;
if (!l2cap_frame_get_u8(frame, &attr))
return false;
print_field("%*cAttributeID: 0x%02x (%s)", (indent - 8), ' ',
attr, attr2str(attr));
return true;
response:
if (!l2cap_frame_get_u8(frame, &num))
return false;
print_field("%*cValueCount: 0x%02x", (indent - 8), ' ', num);
for (; num > 0; num--) {
uint8_t value;
if (!l2cap_frame_get_u8(frame, &value))
return false;
print_field("%*cValueID: 0x%02x (%s)", (indent - 8),
' ', value, value2str(attr, value));
}
return true;
}
static bool avrcp_get_current_player_value(struct avctp_frame *avctp_frame,
uint8_t ctype, uint8_t len,
uint8_t indent)
{
struct l2cap_frame *frame = &avctp_frame->l2cap_frame;
uint8_t num;
if (!l2cap_frame_get_u8(frame, &num))
return false;
if (ctype > AVC_CTYPE_GENERAL_INQUIRY)
goto response;
print_field("%*cAttributeCount: 0x%02x", (indent - 8), ' ', num);
for (; num > 0; num--) {
uint8_t attr;
if (!l2cap_frame_get_u8(frame, &attr))
return false;
print_field("%*cAttributeID: 0x%02x (%s)", (indent - 8),
' ', attr, attr2str(attr));
}
return true;
response:
print_field("%*cValueCount: 0x%02x", (indent - 8), ' ', num);
for (; num > 0; num--) {
uint8_t attr, value;
if (!l2cap_frame_get_u8(frame, &attr))
return false;
print_field("%*cAttributeID: 0x%02x (%s)", (indent - 8),
' ', attr, attr2str(attr));
if (!l2cap_frame_get_u8(frame, &value))
return false;
print_field("%*cValueID: 0x%02x (%s)", (indent - 8),
' ', value, value2str(attr, value));
}
return true;
}
static bool avrcp_set_player_value(struct avctp_frame *avctp_frame,
uint8_t ctype, uint8_t len,
uint8_t indent)
{
struct l2cap_frame *frame = &avctp_frame->l2cap_frame;
uint8_t num;
if (ctype > AVC_CTYPE_GENERAL_INQUIRY)
return true;
if (!l2cap_frame_get_u8(frame, &num))
return false;
print_field("%*cAttributeCount: 0x%02x", (indent - 8), ' ', num);
for (; num > 0; num--) {
uint8_t attr, value;
if (!l2cap_frame_get_u8(frame, &attr))
return false;
print_field("%*cAttributeID: 0x%02x (%s)", (indent - 8), ' ',
attr, attr2str(attr));