summaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-ptpip.c
blob: 6e5f7e523b9f368805c80ad0d7bb6a74c998b4d9 (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
/* packet-ptpip.c
 * Routines for PTP/IP (Picture Transfer Protocol) packet dissection
 * 0xBismarck 2013
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

/**
 * References:
 * [1] CIPA DC-X005-2005 - PTP-IP
 * [2] BS ISO 15740:2008 - Photography Electronic still picture imaging - Picture transfer protocol (PTP)
 * for digital still photography devices
 * [3] gPhoto's Reversed Engineered PTP/IP documentation - http://gphoto.sourceforge.net/doc/ptpip.php
 * [4] gPhoto's ptp2 header file  https://gphoto.svn.sourceforge.net/svnroot/gphoto/trunk/libgphoto2/camlibs/ptp2/ptp.h
 *
 * @todo: This is being written as 1 dissector when in reality there is PTP/IP and PTP.
 *        Future work should include splitting this into 2 so that the PTP layer may be used again for PTP/USB.
 */
#include "config.h"
#include <epan/packet.h>
#include <epan/prefs.h>
#include "packet-ptpip.h"

/* Define */
#define PTPIP_PORT            15740  /* [1] Section 2.2.3.1 */
#define PTPIP_GUID_SIZE          16  /* [1] Section 2.3.1 */
#define PTPIP_MAX_PARAM_COUNT     5  /* [1] Section 2.3.6 */

/* trees */
static gint ett_ptpIP =  -1;
static gint ett_ptpIP_hdr = -1;

/* PTP/IP Fields */
static int proto_ptpIP = -1;
static int hf_ptpIP_len = -1; /* [1] Section 2.3 */
static int hf_ptpIP_pktType = -1; /* [1] Section 2.3 */
static int hf_ptpIP_guid = -1;
static int hf_ptpIP_name = -1;
static int hf_ptpIP_version = -1;
static int hf_ptpIP_connectionNumber = -1;
static int hf_ptpIP_dataPhaseInfo = -1;

/* note: separating the fields to make it easier to divide this code later. */

/* PTP Fields */
/* picking hf_ptp for now. Might need to change later for namespace issues with Precision Time Protocol. */
static int hf_ptp_opCode = -1;
static int hf_ptp_vendor_opCode = -1;
static int hf_ptp_respCode = -1;
static int hf_ptp_eventCode = -1;
static int hf_ptp_transactionID = -1;
static int hf_ptp_totalDataLength = -1;
static int hf_ptp_opCode_param_sessionID = -1;

/* function declarations */
static int dissect_ptpIP (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_);
static void dissect_ptpIP_init_command_request (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint16 *offset);
static void dissect_ptpIP_init_command_ack     (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint16 *offset);
static void dissect_ptpIP_init_event_request   (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint16 *offset);
static void dissect_ptpIP_init_event_ack       (               packet_info *pinfo);
static void dissect_ptpIP_operation_request    (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint16 *offset);
static void dissect_ptpIP_operation_response   (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint16 *offset);
static void dissect_ptpIP_start_data           (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint16 *offset);
static void dissect_ptpIP_data                 (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint16 *offset);
static void dissect_ptpIP_end_data             (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint16 *offset);
static void dissect_ptpIP_event                (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint16 *offset);
static void dissect_ptpIP_unicode_name         (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint16 *offset);
static void dissect_ptpIP_protocol_version     (tvbuff_t *tvb,                     proto_tree *tree, guint16 *offset);
static void dissect_ptpIP_guid                 (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint16 *offset);

void proto_register_ptpip( void );
void proto_reg_handoff_ptpIP( void );

static dissector_handle_t ptpIP_handle;

typedef enum {
    PTP_VENDOR_UNKNOWN = 0,
    PTP_VENDOR_EASTMAN_KODAK = 1,
    PTP_VENDOR_CANON = 2,
    PTP_VENDOR_NIKON = 3,
    PTP_VENDOR_CASIO = 4,
    PTP_VENDOR_MTP = 5,
    PTP_VENDOR_OLYMPUS = 6
} ptp_vendors;

static const enum_val_t pref_hsp_role[] = {
    { "Unknown",        "Unknown vendor",   PTP_VENDOR_UNKNOWN },
    { "Eastman Kodak",  "Eastman Kodak",    PTP_VENDOR_EASTMAN_KODAK},
    { "Canon",          "Canon",            PTP_VENDOR_CANON },
    { "Nikon",          "Nikon",            PTP_VENDOR_NIKON },
    { "Casio",          "Casio EX-F1",      PTP_VENDOR_CASIO },
    { "Microsoft / MTP","Microsoft / MTP",  PTP_VENDOR_MTP },
    { "Olympus",        "Olympus E series", PTP_VENDOR_OLYMPUS },
    { NULL, NULL, 0 }
};

/* Vendor preference for deciphering opcodes */
static int pref_vendor = 0;


static const value_string ptp_opcode_names[] = {
    { PTP_OC_GetDeviceInfo,                             "GetDeviceInfo" },
    { PTP_OC_OpenSession,                               "OpenSession" },
    { PTP_OC_CloseSession,                              "CloseSession" },
    { PTP_OC_GetStorageIDs,                             "GetStorageIDs" },
    { PTP_OC_GetStorageInfo,                            "GetStorageInfo" },
    { PTP_OC_GetNumObjects,                             "GetNumObjects" },
    { PTP_OC_GetObjectHandles,                          "GetObjectHandles" },
    { PTP_OC_GetObjectInfo,                             "GetObjectInfo" },
    { PTP_OC_GetObject,                                 "GetObject" },
    { PTP_OC_DeleteObject,                              "DeleteObject" },
    { PTP_OC_SendObjectInfo,                            "SendObjectInfo" },
    { PTP_OC_SendObject,                                "SendObject" },
    { PTP_OC_InitiateCapture,                           "InitiateCapture" },
    { PTP_OC_FormatStore,                               "FormatStore" },
    { PTP_OC_ResetDevice,                               "ResetDevice" },
    { PTP_OC_SelfTest,                                  "SelfTest" },
    { PTP_OC_SetObjectProtection,                       "SetObjectProtection" },
    { PTP_OC_PowerDown,                                 "PowerDown" },
    { PTP_OC_GetDevicePropDesc,                         "GetDevicePropDesc" },
    { PTP_OC_GetDevicePropValue,                        "GetDevicePropValue" },
    { PTP_OC_SetDevicePropValue,                        "SetDevicePropValue" },
    { PTP_OC_ResetDevicePropValue,                      "ResetDevicePropValue" },
    { PTP_OC_TerminateOpenCapture,                      "TerminateOpenCapture" },
    { PTP_OC_MoveObject,                                "MoveObject" },
    { PTP_OC_CopyObject,                                "CopyObject" },
    { PTP_OC_GetPartialObject,                          "GetPartialObject" },
    { PTP_OC_InitiateOpenCapture,                       "InitiateOpenCapture" },
    { PTP_OC_StartEnumHandles,                          "StartEnumHandles" },
    { PTP_OC_EnumHandles,                               "EnumHandles" },
    { PTP_OC_StopEnumHandles,                           "StopEnumHandles" },
    { PTP_OC_GetVendorExtensionMaps,                    "GetVendorExtensionMaps" },
    { PTP_OC_GetVendorDeviceInfo,                       "GetVendorDeviceInfo" },
    { PTP_OC_GetResizedImageObject,                     "GetResizedImageObject" },
    { PTP_OC_GetFilesystemManifest,                     "GetFilesystemManifest" },
    { PTP_OC_GetStreamInfo,                             "GetStreamInfo" },
    { PTP_OC_GetStream,                                 "GetStream" },
    { 0,                                                 NULL }
};
static value_string_ext ptp_opcode_names_ext = VALUE_STRING_EXT_INIT(ptp_opcode_names);

static const value_string ptp_opcode_ek_names[] = {
    { PTP_OC_EK_GetSerial,                              "EK_GetSerial" },
    { PTP_OC_EK_SetSerial,                              "EK_SetSerial" },
    { PTP_OC_EK_SendFileObjectInfo,                     "EK_SendFileObjectInfo" },
    { PTP_OC_EK_SendFileObject,                         "EK_SendFileObject" },
    { PTP_OC_EK_SetText,                                "EK_SetText" },
    { 0,                                                 NULL }
};
static value_string_ext ptp_opcode_ek_names_ext = VALUE_STRING_EXT_INIT(ptp_opcode_ek_names);

static const value_string ptp_opcode_canon_names[] = {
    { PTP_OC_CANON_GetPartialObjectInfo,                "CANON_GetPartialObjectInfo" },
    { PTP_OC_CANON_SetObjectArchive,                    "CANON_SetObjectArchive" },
    { PTP_OC_CANON_KeepDeviceOn,                        "CANON_KeepDeviceOn" },
    { PTP_OC_CANON_LockDeviceUI,                        "CANON_LockDeviceUI" },
    { PTP_OC_CANON_UnlockDeviceUI,                      "CANON_UnlockDeviceUI" },
    { PTP_OC_CANON_GetObjectHandleByName,               "CANON_GetObjectHandleByName" },
    { PTP_OC_CANON_InitiateReleaseControl,              "CANON_InitiateReleaseControl" },
    { PTP_OC_CANON_TerminateReleaseControl,             "CANON_TerminateReleaseControl" },
    { PTP_OC_CANON_TerminatePlaybackMode,               "CANON_TerminatePlaybackMode" },
    { PTP_OC_CANON_ViewfinderOn,                        "CANON_ViewfinderOn" },
    { PTP_OC_CANON_ViewfinderOff,                       "CANON_ViewfinderOff" },
    { PTP_OC_CANON_DoAeAfAwb,                           "CANON_DoAeAfAwb" },
    { PTP_OC_CANON_GetCustomizeSpec,                    "CANON_GetCustomizeSpec" },
    { PTP_OC_CANON_GetCustomizeItemInfo,                "CANON_GetCustomizeItemInfo" },
    { PTP_OC_CANON_GetCustomizeData,                    "CANON_GetCustomizeData" },
    { PTP_OC_CANON_SetCustomizeData,                    "CANON_SetCustomizeData" },
    { PTP_OC_CANON_GetCaptureStatus,                    "CANON_GetCaptureStatus" },
    { PTP_OC_CANON_CheckEvent,                          "CANON_CheckEvent" },
    { PTP_OC_CANON_FocusLock,                           "CANON_FocusLock" },
    { PTP_OC_CANON_FocusUnlock,                         "CANON_FocusUnlock" },
    { PTP_OC_CANON_GetLocalReleaseParam,                "CANON_GetLocalReleaseParam" },
    { PTP_OC_CANON_SetLocalReleaseParam,                "CANON_SetLocalReleaseParam" },
    { PTP_OC_CANON_AskAboutPcEvf,                       "CANON_AskAboutPcEvf" },
    { PTP_OC_CANON_SendPartialObject,                   "CANON_SendPartialObject" },
    { PTP_OC_CANON_InitiateCaptureInMemory,             "CANON_InitiateCaptureInMemory" },
    { PTP_OC_CANON_GetPartialObjectEx,                  "CANON_GetPartialObjectEx" },
    { PTP_OC_CANON_SetObjectTime,                       "CANON_SetObjectTime" },
    { PTP_OC_CANON_GetViewfinderImage,                  "CANON_GetViewfinderImage" },
    { PTP_OC_CANON_GetObjectAttributes,                 "CANON_GetObjectAttributes" },
    { PTP_OC_CANON_ChangeUSBProtocol,                   "CANON_ChangeUSBProtocol" },
    { PTP_OC_CANON_GetChanges,                          "CANON_GetChanges" },
    { PTP_OC_CANON_GetObjectInfoEx,                     "CANON_GetObjectInfoEx" },
    { PTP_OC_CANON_InitiateDirectTransfer,              "CANON_InitiateDirectTransfer" },
    { PTP_OC_CANON_TerminateDirectTransfer,             "CANON_TerminateDirectTransfer" },
    { PTP_OC_CANON_SendObjectInfoByPath,                "CANON_SendObjectInfoByPath" },
    { PTP_OC_CANON_SendObjectByPath,                    "CANON_SendObjectByPath" },
    { PTP_OC_CANON_InitiateDirectTransferEx,            "CANON_InitiateDirectTransferEx" },
    { PTP_OC_CANON_GetAncillaryObjectHandles,           "CANON_GetAncillaryObjectHandles" },
    { PTP_OC_CANON_GetTreeInfo,                         "CANON_GetTreeInfo" },
    { PTP_OC_CANON_GetTreeSize,                         "CANON_GetTreeSize" },
    { PTP_OC_CANON_NotifyProgress,                      "CANON_NotifyProgress" },
    { PTP_OC_CANON_NotifyCancelAccepted,                "CANON_NotifyCancelAccepted" },
    { PTP_OC_CANON_902C,                                "CANON_902C" },
    { PTP_OC_CANON_SetPairingInfo,                      "CANON_SetPairingInfo" },
    { PTP_OC_CANON_GetPairingInfo,                      "CANON_GetPairingInfo" },
    { PTP_OC_CANON_DeletePairingInfo,                   "CANON_DeletePairingInfo" },
    { PTP_OC_CANON_GetMACAddress,                       "CANON_GetMACAddress" },
    { PTP_OC_CANON_SetDisplayMonitor,                   "CANON_SetDisplayMonitor" },
    { PTP_OC_CANON_PairingComplete,                     "CANON_PairingComplete" },
    { PTP_OC_CANON_GetWirelessMAXChannel,               "CANON_GetWirelessMAXChannel" },
    { PTP_OC_CANON_EOS_GetStorageIDs,                   "CANON_EOS_GetStorageIDs" },
    { PTP_OC_CANON_EOS_GetStorageInfo,                  "CANON_EOS_GetStorageInfo" },
    { PTP_OC_CANON_EOS_GetObjectInfo,                   "CANON_EOS_GetObjectInfo" },
    { PTP_OC_CANON_EOS_GetObject,                       "CANON_EOS_GetObject" },
    { PTP_OC_CANON_EOS_DeleteObject,                    "CANON_EOS_DeleteObject" },
    { PTP_OC_CANON_EOS_FormatStore,                     "CANON_EOS_FormatStore" },
    { PTP_OC_CANON_EOS_GetPartialObject,                "CANON_EOS_GetPartialObject" },
    { PTP_OC_CANON_EOS_GetDeviceInfoEx,                 "CANON_EOS_GetDeviceInfoEx" },
    { PTP_OC_CANON_EOS_GetObjectInfoEx,                 "CANON_EOS_GetObjectInfoEx" },
    { PTP_OC_CANON_EOS_GetThumbEx,                      "CANON_EOS_GetThumbEx" },
    { PTP_OC_CANON_EOS_SendPartialObject,               "CANON_EOS_SendPartialObject" },
    { PTP_OC_CANON_EOS_SetObjectAttributes,             "CANON_EOS_SetObjectAttributes" },
    { PTP_OC_CANON_EOS_GetObjectTime,                   "CANON_EOS_GetObjectTime" },
    { PTP_OC_CANON_EOS_SetObjectTime,                   "CANON_EOS_SetObjectTime" },
    { PTP_OC_CANON_EOS_RemoteRelease,                   "CANON_EOS_RemoteRelease" },
    { PTP_OC_CANON_EOS_SetDevicePropValueEx,            "CANON_EOS_SetDevicePropValueEx" },
    { PTP_OC_CANON_EOS_GetRemoteMode,                   "CANON_EOS_GetRemoteMode" },
    { PTP_OC_CANON_EOS_SetRemoteMode,                   "CANON_EOS_SetRemoteMode" },
    { PTP_OC_CANON_EOS_SetEventMode,                    "CANON_EOS_SetEventMode" },
    { PTP_OC_CANON_EOS_GetEvent,                        "CANON_EOS_GetEvent" },
    { PTP_OC_CANON_EOS_TransferComplete,                "CANON_EOS_TransferComplete" },
    { PTP_OC_CANON_EOS_CancelTransfer,                  "CANON_EOS_CancelTransfer" },
    { PTP_OC_CANON_EOS_ResetTransfer,                   "CANON_EOS_ResetTransfer" },
    { PTP_OC_CANON_EOS_PCHDDCapacity,                   "CANON_EOS_PCHDDCapacity" },
    { PTP_OC_CANON_EOS_SetUILock,                       "CANON_EOS_SetUILock" },
    { PTP_OC_CANON_EOS_ResetUILock,                     "CANON_EOS_ResetUILock" },
    { PTP_OC_CANON_EOS_KeepDeviceOn,                    "CANON_EOS_KeepDeviceOn" },
    { PTP_OC_CANON_EOS_SetNullPacketMode,               "CANON_EOS_SetNullPacketMode" },
    { PTP_OC_CANON_EOS_UpdateFirmware,                  "CANON_EOS_UpdateFirmware" },
    { PTP_OC_CANON_EOS_TransferCompleteDT,              "CANON_EOS_TransferCompleteDT" },
    { PTP_OC_CANON_EOS_CancelTransferDT,                "CANON_EOS_CancelTransferDT" },
    { PTP_OC_CANON_EOS_SetWftProfile,                   "CANON_EOS_SetWftProfile" },
    { PTP_OC_CANON_EOS_GetWftProfile,                   "CANON_EOS_GetWftProfile" },
    { PTP_OC_CANON_EOS_SetProfileToWft,                 "CANON_EOS_SetProfileToWft" },
    { PTP_OC_CANON_EOS_BulbStart,                       "CANON_EOS_BulbStart" },
    { PTP_OC_CANON_EOS_BulbEnd,                         "CANON_EOS_BulbEnd" },
    { PTP_OC_CANON_EOS_RequestDevicePropValue,          "CANON_EOS_RequestDevicePropValue" },
    { PTP_OC_CANON_EOS_RemoteReleaseOn,                 "CANON_EOS_RemoteReleaseOn" },
    { PTP_OC_CANON_EOS_RemoteReleaseOff,                "CANON_EOS_RemoteReleaseOff" },
    { PTP_OC_CANON_EOS_InitiateViewfinder,              "CANON_EOS_InitiateViewfinder" },
    { PTP_OC_CANON_EOS_TerminateViewfinder,             "CANON_EOS_TerminateViewfinder" },
    { PTP_OC_CANON_EOS_GetViewFinderData,               "CANON_EOS_GetViewFinderData" },
    { PTP_OC_CANON_EOS_DoAf,                            "CANON_EOS_DoAf" },
    { PTP_OC_CANON_EOS_DriveLens,                       "CANON_EOS_DriveLens" },
    { PTP_OC_CANON_EOS_DepthOfFieldPreview,             "CANON_EOS_DepthOfFieldPreview" },
    { PTP_OC_CANON_EOS_ClickWB,                         "CANON_EOS_ClickWB" },
    { PTP_OC_CANON_EOS_Zoom,                            "CANON_EOS_Zoom" },
    { PTP_OC_CANON_EOS_ZoomPosition,                    "CANON_EOS_ZoomPosition" },
    { PTP_OC_CANON_EOS_SetLiveAfFrame,                  "CANON_EOS_SetLiveAfFrame" },
    { PTP_OC_CANON_EOS_AfCancel,                        "CANON_EOS_AfCancel" },
    { PTP_OC_CANON_EOS_FAPIMessageTX,                   "CANON_EOS_FAPIMessageTX" },
    { PTP_OC_CANON_EOS_FAPIMessageRX,                   "CANON_EOS_FAPIMessageRX" },
    { 0,                                                 NULL }
};
static value_string_ext ptp_opcode_canon_names_ext = VALUE_STRING_EXT_INIT(ptp_opcode_canon_names);

static const value_string ptp_opcode_nikon_names[] = {
    { PTP_OC_NIKON_GetProfileAllData,                   "NIKON_GetProfileAllData" },
    { PTP_OC_NIKON_SendProfileData,                     "NIKON_SendProfileData" },
    { PTP_OC_NIKON_SendProfileData,                     "NIKON_SendProfileData" },
    { PTP_OC_NIKON_DeleteProfile,                       "NIKON_DeleteProfile" },
    { PTP_OC_NIKON_SetProfileData,                      "NIKON_SetProfileData" },
    { PTP_OC_NIKON_AdvancedTransfer,                    "NIKON_AdvancedTransfer" },
    { PTP_OC_NIKON_GetFileInfoInBlock,                  "NIKON_GetFileInfoInBlock" },
    { PTP_OC_NIKON_Capture,                             "NIKON_Capture" },
    { PTP_OC_NIKON_AfDrive,                             "NIKON_AfDrive" },
    { PTP_OC_NIKON_SetControlMode,                      "NIKON_SetControlMode" },
    { PTP_OC_NIKON_DelImageSDRAM,                       "NIKON_DelImageSDRAM" },
    { PTP_OC_NIKON_GetLargeThumb,                       "NIKON_GetLargeThumb" },
    { PTP_OC_NIKON_CurveDownload,                       "NIKON_CurveDownload" },
    { PTP_OC_NIKON_CurveUpload,                         "NIKON_CurveUpload" },
    { PTP_OC_NIKON_CheckEvent,                          "NIKON_CheckEvent" },
    { PTP_OC_NIKON_DeviceReady,                         "NIKON_DeviceReady" },
    { PTP_OC_NIKON_SetPreWBData,                        "NIKON_SetPreWBData" },
    { PTP_OC_NIKON_GetVendorPropCodes,                  "NIKON_GetVendorPropCodes" },
    { PTP_OC_NIKON_AfCaptureSDRAM,                      "NIKON_AfCaptureSDRAM" },
    { PTP_OC_NIKON_GetPictCtrlData,                     "NIKON_GetPictCtrlData" },
    { PTP_OC_NIKON_SetPictCtrlData,                     "NIKON_SetPictCtrlData" },
    { PTP_OC_NIKON_DelCstPicCtrl,                       "NIKON_DelCstPicCtrl" },
    { PTP_OC_NIKON_GetPicCtrlCapability,                "NIKON_GetPicCtrlCapability" },
    { PTP_OC_NIKON_GetPreviewImg,                       "NIKON_GetPreviewImg" },
    { PTP_OC_NIKON_StartLiveView,                       "NIKON_StartLiveView" },
    { PTP_OC_NIKON_EndLiveView,                         "NIKON_EndLiveView" },
    { PTP_OC_NIKON_GetLiveViewImg,                      "NIKON_GetLiveViewImg" },
    { PTP_OC_NIKON_MfDrive,                             "NIKON_MfDrive" },
    { PTP_OC_NIKON_ChangeAfArea,                        "NIKON_ChangeAfArea" },
    { PTP_OC_NIKON_AfDriveCancel,                       "NIKON_AfDriveCancel" },
    { PTP_OC_NIKON_GetDevicePTPIPInfo,                  "NIKON_GetDevicePTPIPInfo" },
    { 0,                                                 NULL }
};
static value_string_ext ptp_opcode_nikon_names_ext = VALUE_STRING_EXT_INIT(ptp_opcode_nikon_names);

static const value_string ptp_opcode_casio_names[] = {
    { PTP_OC_CASIO_STILL_START,                         "CASIO_STILL_START" },
    { PTP_OC_CASIO_STILL_STOP,                          "CASIO_STILL_STOP" },
    { PTP_OC_CASIO_FOCUS,                               "CASIO_FOCUS" },
    { PTP_OC_CASIO_CF_PRESS,                            "CASIO_CF_PRESS" },
    { PTP_OC_CASIO_CF_RELEASE,                          "CASIO_CF_RELEASE" },
    { PTP_OC_CASIO_GET_OBJECT_INFO,                     "CASIO_GET_OBJECT_INFO" },
    { PTP_OC_CASIO_SHUTTER,                             "CASIO_SHUTTER" },
    { PTP_OC_CASIO_GET_STILL_HANDLES,                   "CASIO_GET_STILL_HANDLES" },
    { PTP_OC_CASIO_STILL_RESET,                         "CASIO_STILL_RESET" },
    { PTP_OC_CASIO_HALF_PRESS,                          "CASIO_HALF_PRESS" },
    { PTP_OC_CASIO_HALF_RELEASE,                        "CASIO_HALF_RELEASE" },
    { PTP_OC_CASIO_CS_PRESS,                            "CASIO_CS_PRESS" },
    { PTP_OC_CASIO_CS_RELEASE,                          "CASIO_CS_RELEASE" },
    { PTP_OC_CASIO_ZOOM,                                "CASIO_ZOOM" },
    { PTP_OC_CASIO_CZ_PRESS,                            "CASIO_CZ_PRESS" },
    { PTP_OC_CASIO_CZ_RELEASE,                          "CASIO_CZ_RELEASE" },
    { PTP_OC_CASIO_MOVIE_START,                         "CASIO_MOVIE_START" },
    { PTP_OC_CASIO_MOVIE_STOP,                          "CASIO_MOVIE_STOP" },
    { PTP_OC_CASIO_MOVIE_PRESS,                         "CASIO_MOVIE_PRESS" },
    { PTP_OC_CASIO_MOVIE_RELEASE,                       "CASIO_MOVIE_RELEASE" },
    { PTP_OC_CASIO_GET_MOVIE_HANDLES,                   "CASIO_GET_MOVIE_HANDLES" },
    { PTP_OC_CASIO_MOVIE_RESET,                         "CASIO_MOVIE_RESET" },
    { PTP_OC_CASIO_GET_OBJECT,                          "CASIO_GET_OBJECT" },
    { PTP_OC_CASIO_GET_THUMBNAIL,                       "CASIO_GET_THUMBNAIL" },
    { 0,                                                 NULL }
};
static value_string_ext ptp_opcode_casio_names_ext = VALUE_STRING_EXT_INIT(ptp_opcode_casio_names);

static const value_string ptp_opcode_mtp_names[] = {
    { PTP_OC_MTP_GetObjectPropsSupported,               "MTP_GetObjectPropsSupported" },
    { PTP_OC_MTP_GetObjectPropDesc,                     "MTP_GetObjectPropDesc" },
    { PTP_OC_MTP_GetObjectPropValue,                    "MTP_GetObjectPropValue" },
    { PTP_OC_MTP_SetObjectPropValue,                    "MTP_SetObjectPropValue" },
    { PTP_OC_MTP_GetObjPropList,                        "MTP_GetObjPropList" },
    { PTP_OC_MTP_SetObjPropList,                        "MTP_SetObjPropList" },
    { PTP_OC_MTP_GetInterdependendPropdesc,             "MTP_GetInterdependendPropdesc" },
    { PTP_OC_MTP_SendObjectPropList,                    "MTP_SendObjectPropList" },
    { PTP_OC_MTP_GetObjectReferences,                   "MTP_GetObjectReferences" },
    { PTP_OC_MTP_SetObjectReferences,                   "MTP_SetObjectReferences" },
    { PTP_OC_MTP_UpdateDeviceFirmware,                  "MTP_UpdateDeviceFirmware" },
    { PTP_OC_MTP_Skip,                                  "MTP_Skip" },
    { PTP_OC_MTP_WMDRMPD_GetSecureTimeChallenge,        "MTP_WMDRMPD_GetSecureTimeChallenge" },
    { PTP_OC_MTP_WMDRMPD_GetSecureTimeResponse,         "MTP_WMDRMPD_GetSecureTimeResponse" },
    { PTP_OC_MTP_WMDRMPD_SetLicenseResponse,            "MTP_WMDRMPD_SetLicenseResponse" },
    { PTP_OC_MTP_WMDRMPD_GetSyncList,                   "MTP_WMDRMPD_GetSyncList" },
    { PTP_OC_MTP_WMDRMPD_SendMeterChallengeQuery,       "MTP_WMDRMPD_SendMeterChallengeQuery" },
    { PTP_OC_MTP_WMDRMPD_GetMeterChallenge,             "MTP_WMDRMPD_GetMeterChallenge" },
    { PTP_OC_MTP_WMDRMPD_SetMeterResponse,              "MTP_WMDRMPD_SetMeterResponse" },
    { PTP_OC_MTP_WMDRMPD_CleanDataStore,                "MTP_WMDRMPD_CleanDataStore" },
    { PTP_OC_MTP_WMDRMPD_GetLicenseState,               "MTP_WMDRMPD_GetLicenseState" },
    { PTP_OC_MTP_WMDRMPD_SendWMDRMPDCommand,            "MTP_WMDRMPD_SendWMDRMPDCommand" },
    { PTP_OC_MTP_WMDRMPD_SendWMDRMPDRequest,            "MTP_WMDRMPD_SendWMDRMPDRequest" },
    { PTP_OC_MTP_WMDRMPD_SendWMDRMPDAppRequest,         "MTP_WMDRMPD_SendWMDRMPDAppRequest" },
    { PTP_OC_MTP_WMDRMPD_GetWMDRMPDAppResponse,         "MTP_WMDRMPD_GetWMDRMPDAppResponse" },
    { PTP_OC_MTP_WMDRMPD_EnableTrustedFilesOperations,  "MTP_WMDRMPD_EnableTrustedFilesOperations" },
    { PTP_OC_MTP_WMDRMPD_DisableTrustedFilesOperations, "MTP_WMDRMPD_DisableTrustedFilesOperations" },
    { PTP_OC_MTP_WMDRMPD_EndTrustedAppSession,          "MTP_WMDRMPD_EndTrustedAppSession" },
    { PTP_OC_MTP_AAVT_OpenMediaSession,                 "MTP_AAVT_OpenMediaSession" },
    { PTP_OC_MTP_AAVT_CloseMediaSession,                "MTP_AAVT_CloseMediaSession" },
    { PTP_OC_MTP_AAVT_GetNextDataBlock,                 "MTP_AAVT_GetNextDataBlock" },
    { PTP_OC_MTP_AAVT_SetCurrentTimePosition,           "MTP_AAVT_SetCurrentTimePosition" },
    { PTP_OC_MTP_WMDRMND_SendRegistrationRequest,       "MTP_WMDRMND_SendRegistrationRequest" },
    { PTP_OC_MTP_WMDRMND_GetRegistrationResponse,       "MTP_WMDRMND_GetRegistrationResponse" },
    { PTP_OC_MTP_WMDRMND_GetProximityChallenge,         "MTP_WMDRMND_GetProximityChallenge" },
    { PTP_OC_MTP_WMDRMND_SendProximityResponse,         "MTP_WMDRMND_SendProximityResponse" },
    { PTP_OC_MTP_WMDRMND_SendWMDRMNDLicenseRequest,     "MTP_WMDRMND_SendWMDRMNDLicenseRequest" },
    { PTP_OC_MTP_WMDRMND_GetWMDRMNDLicenseResponse,     "MTP_WMDRMND_GetWMDRMNDLicenseResponse" },
    { PTP_OC_MTP_WMPPD_ReportAddedDeletedItems,         "MTP_WMPPD_ReportAddedDeletedItems" },
    { PTP_OC_MTP_WMPPD_ReportAcquiredItems,             "MTP_WMPPD_ReportAcquiredItems" },
    { PTP_OC_MTP_WMPPD_PlaylistObjectPref,              "MTP_WMPPD_PlaylistObjectPref" },
    { PTP_OC_MTP_ZUNE_GETUNDEFINED001,                  "MTP_ZUNE_GETUNDEFINED001" },
    { PTP_OC_MTP_WPDWCN_ProcessWFCObject,               "MTP_WPDWCN_ProcessWFCObject" },
    { 0,                                                 NULL }
};
static value_string_ext ptp_opcode_mtp_names_ext = VALUE_STRING_EXT_INIT(ptp_opcode_mtp_names);

static const value_string ptp_opcode_olympus_names[] = {
    { PTP_OC_OLYMPUS_Capture,                           "OLYMPUS_Capture" },
    { PTP_OC_OLYMPUS_SelfCleaning,                      "OLYMPUS_SelfCleaning" },
    { PTP_OC_OLYMPUS_SetRGBGain,                        "OLYMPUS_SetRGBGain" },
    { PTP_OC_OLYMPUS_SetPresetMode,                     "OLYMPUS_SetPresetMode" },
    { PTP_OC_OLYMPUS_SetWBBiasAll,                      "OLYMPUS_SetWBBiasAll" },
    { PTP_OC_OLYMPUS_GetCameraControlMode,              "OLYMPUS_GetCameraControlMode" },
    { PTP_OC_OLYMPUS_SetCameraControlMode,              "OLYMPUS_SetCameraControlMode" },
    { PTP_OC_OLYMPUS_SetWBRGBGain,                      "OLYMPUS_SetWBRGBGain" },
    { PTP_OC_OLYMPUS_GetDeviceInfo,                     "OLYMPUS_GetDeviceInfo" },
    { PTP_OC_OLYMPUS_Init1,                             "OLYMPUS_Init1" },
    { PTP_OC_OLYMPUS_SetDateTime,                       "OLYMPUS_SetDateTime" },
    { PTP_OC_OLYMPUS_GetDateTime,                       "OLYMPUS_GetDateTim" },
    { PTP_OC_OLYMPUS_SetCameraID,                       "OLYMPUS_SetCameraID" },
    { PTP_OC_OLYMPUS_GetCameraID,                       "OLYMPUS_GetCameraID" },
    { 0,                                                 NULL }
};
static value_string_ext ptp_opcode_olympus_names_ext = VALUE_STRING_EXT_INIT(ptp_opcode_olympus_names);

static const value_string ptp_respcode_names[] = {
    { PTP_RC_OK,                                     "OK" },
    { PTP_RC_GeneralError,                           "GeneralError" },
    { PTP_RC_SessionNotOpen,                         "SessionNotOpen" },
    { PTP_RC_InvalidTransactionID,                   "InvalidTransactionID" },
    { PTP_RC_OperationNotSupported,                  "OperationNotSupported" },
    { PTP_RC_ParameterNotSupported,                  "ParameterNotSupported" },
    { PTP_RC_IncompleteTransfer,                     "IncompleteTransfer" },
    { PTP_RC_InvalidStorageId,                       "InvalidStorageId" },
    { PTP_RC_InvalidObjectHandle,                    "InvalidObjectHandle" },
    { PTP_RC_DevicePropNotSupported,                 "DevicePropNotSupported" },
    { PTP_RC_InvalidObjectFormatCode,                "InvalidObjectFormatCode" },
    { PTP_RC_StoreFull,                              "StoreFull" },
    { PTP_RC_StoreReadOnly,                          "StoreReadOnly" },
    { PTP_RC_AccessDenied,                           "AccessDenied" },
    { PTP_RC_NoThumbnailPresent,                     "NoThumbnailPresent" },
    { PTP_RC_SelfTestFailed,                         "SelfTestFailed" },
    { PTP_RC_PartialDeletion,                        "PartialDeletion" },
    { PTP_RC_StoreNotAvailable,                      "StoreNotAvailable" },
    { PTP_RC_SpecificationByFormatUnsupported,       "SpecificationByFormatUnsupported" },
    { PTP_RC_NoValidObjectInfo,                      "NoValidObjectInfo" },
    { PTP_RC_InvalidCodeFormat,                      "InvalidCodeFormat" },
    { PTP_RC_UnknownVendorCode,                      "UnknownVendorCode" },
    { PTP_RC_CaptureAlreadyTerminated,               "CaptureAlreadyTerminated" },
    { PTP_RC_DeviceBusy,                             "DeviceBusy" },
    { PTP_RC_InvalidParentObject,                    "InvalidParentObject" },
    { PTP_RC_InvalidDevicePropFormat,                "InvalidDevicePropFormat" },
    { PTP_RC_InvalidDevicePropValue,                 "InvalidDevicePropValue" },
    { PTP_RC_InvalidParameter,                       "InvalidParameter" },
    { PTP_RC_SessionAlreadyOpened,                   "SessionAlreadyOpened" },
    { PTP_RC_TransactionCanceled,                    "TransactionCanceled" },
    { PTP_RC_SpecificationOfDestinationUnsupported,  "SpecificationOfDestinationUnsupported" },
    { PTP_RC_InvalidEnumHandle,                      "InvalidEnumHandle" },
    { PTP_RC_NoStreamEnabled,                        "NoStreamEnabled" },
    { PTP_RC_InvalidDataSet,                         "InvalidDataSet" },
    { 0,                                                 NULL }
};
/* static value_string_ext ptp_respcode_names_ext = VALUE_STRING_EXT_INIT(ptp_respcode_names); */

static const value_string ptp_respcode_ek_names[] = {
    { PTP_RC_EK_FilenameRequired,                    "EK_FilenameRequired" },
    { PTP_RC_EK_FilenameConflicts,                   "EK_FilenameConflicts" },
    { PTP_RC_EK_FilenameInvalid,                     "EK_FilenameInvalid" },
    { 0,                                                 NULL }
};

static const value_string ptp_respcode_nikon_names[] = {
    { PTP_RC_NIKON_HardwareError,                    "NIKON_HardwareError" },
    { PTP_RC_NIKON_OutOfFocus,                       "NIKON_OutOfFocus" },
    { PTP_RC_NIKON_ChangeCameraModeFailed,           "NIKON_ChangeCameraModeFailed" },
    { PTP_RC_NIKON_InvalidStatus,                    "NIKON_InvalidStatus" },
    { PTP_RC_NIKON_SetPropertyNotSupported,          "NIKON_SetPropertyNotSupported" },
    { PTP_RC_NIKON_WbResetError,                     "NIKON_WbResetError" },
    { PTP_RC_NIKON_DustReferenceError,               "NIKON_DustReferenceError" },
    { PTP_RC_NIKON_ShutterSpeedBulb,                 "NIKON_ShutterSpeedBulb" },
    { PTP_RC_NIKON_MirrorUpSequence,                 "NIKON_MirrorUpSequence" },
    { PTP_RC_NIKON_CameraModeNotAdjustFNumber,       "NIKON_CameraModeNotAdjustFNumber" },
    { PTP_RC_NIKON_NotLiveView,                      "NIKON_NotLiveView" },
    { PTP_RC_NIKON_MfDriveStepEnd,                   "NIKON_MfDriveStepEnd" },
    { PTP_RC_NIKON_MfDriveStepInsufficiency,         "NIKON_MfDriveStepInsufficiency" },
    { PTP_RC_NIKON_AdvancedTransferCancel,           "NIKON_AdvancedTransferCancel" },
    { 0,                                                 NULL }
};

static const value_string ptp_respcode_canon_names[] = {
    { PTP_RC_CANON_UNKNOWN_COMMAND,                  "CANON_UNKNOWN_COMMAND" },
    { PTP_RC_CANON_OPERATION_REFUSED,                "CANON_OPERATION_REFUSED" },
    { PTP_RC_CANON_LENS_COVER,                       "CANON_LENS_COVER" },
    { PTP_RC_CANON_BATTERY_LOW,                      "CANON_BATTERY_LOW" },
    { PTP_RC_CANON_NOT_READY,                        "CANON_NOT_READY" },
    { PTP_RC_CANON_A009,                             "CANON_A009" },
    { 0,                                                 NULL }
};

static const value_string ptp_respcode_mtp_names[] = {
    { PTP_RC_MTP_Undefined,                          "MTP_Undefined" },
    { PTP_RC_MTP_Invalid_ObjectPropCode,             "MTP_Invalid_ObjectPropCode" },
    { PTP_RC_MTP_Invalid_ObjectProp_Format,          "MTP_Invalid_ObjectProp_Format" },
    { PTP_RC_MTP_Invalid_ObjectProp_Value,           "MTP_Invalid_ObjectProp_Value" },
    { PTP_RC_MTP_Invalid_ObjectReference,            "MTP_Invalid_ObjectReference" },
    { PTP_RC_MTP_Invalid_Dataset,                    "MTP_Invalid_Dataset" },
    { PTP_RC_MTP_Specification_By_Group_Unsupported, "MTP_Specification_By_Group_Unsupported" },
    { PTP_RC_MTP_Specification_By_Depth_Unsupported, "MTP_Specification_By_Depth_Unsupported" },
    { PTP_RC_MTP_Object_Too_Large,                   "MTP_Object_Too_Large" },
    { PTP_RC_MTP_ObjectProp_Not_Supported,           "MTP_ObjectProp_Not_Supported" },
    { PTP_RC_MTP_Invalid_Media_Session_ID,           "MTP_Invalid_Media_Session_ID" },
    { PTP_RC_MTP_Media_Session_Limit_Reached,        "MTP_Media_Session_Limit_Reached" },
    { PTP_RC_MTP_No_More_Data,                       "MTP_No_More_Data" },
    { PTP_RC_MTP_Invalid_WFC_Syntax,                 "MTP_Invalid_WFC_Syntax" },
    { PTP_RC_MTP_WFC_Version_Not_Supported,          "MTP_WFC_Version_Not_Supported" },
    { 0,                                                 NULL }
};

/* String Names of packet types [3] & [4] */
/* PTP/IP definitions */
 /* enums reformatted from [4] */
typedef enum {
    PTPIP_INVALID                = 0,
    PTPIP_INIT_COMMAND_REQUEST   = 1,
    PTPIP_INIT_COMMAND_ACK       = 2,
    PTPIP_INIT_EVENT_REQUEST     = 3,
    PTPIP_INIT_EVENT_ACK         = 4,
    PTPIP_INIT_FAIL              = 5,
    PTPIP_CMD_REQUEST            = 6,  /* possibly Operation request in [1] 2.3.6 agrees with [3]   */
    PTPIP_CMD_RESPONSE           = 7,  /* possibly Operation response in [1] 2.3.7  agrees with [3] */
    PTPIP_EVENT                  = 8,
    PTPIP_START_DATA_PACKET      = 9,
    PTPIP_DATA_PACKET            = 10,
    PTPIP_CANCEL_TRANSACTION     = 11,
    PTPIP_END_DATA_PACKET        = 12,
    PTPIP_PING                   = 13, /* possibly Probe Request in [1] 2.3.13  */
    PTPIP_PONG                   = 14  /* possibly Probe Response in [1] 2.3.14 */
} ptpip_pktType;

/* Unless otherwise stated, names are based on info in [3] */
static const value_string ptpip_pktType_names[] = {
    { PTPIP_INVALID,                 "Invalid" },
    { PTPIP_INIT_COMMAND_REQUEST,    "Init Command Request Packet" },
    { PTPIP_INIT_COMMAND_ACK,        "Init Command ACK Packet" },
    { PTPIP_INIT_EVENT_REQUEST,      "Init Event Request Packet" },
    { PTPIP_INIT_EVENT_ACK,          "Init Event Ack Packet"},
    { PTPIP_INIT_FAIL,               "Init Fail Packet"},
    { PTPIP_CMD_REQUEST,             "Operation Request Packet"},  /* string based on [1]  */
    { PTPIP_CMD_RESPONSE,            "Operation Response Packet"}, /* string based on [1] */
    { PTPIP_EVENT,                   "Event Packet"},
    { PTPIP_START_DATA_PACKET,       "Start Data Packet"},
    { PTPIP_DATA_PACKET,             "Data Packet"},
    { PTPIP_CANCEL_TRANSACTION,      "Cancel Packet"},
    { PTPIP_END_DATA_PACKET,         "End Data Packet"},
    { PTPIP_PING,                    "Probe Request Packet"},      /* string based on [1]  */
    { PTPIP_PONG,                    "Probe Response Packet"},     /* string based on [1] */
    { 0,                             NULL }
};
static value_string_ext ptpip_pktType_names_ext = VALUE_STRING_EXT_INIT(ptpip_pktType_names);


/**
 * Primary method to dissect a PTP/IP packet. When a subtype is encounter,
 * the method will call a subdissector.
 */
static
int dissect_ptpIP (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
{
    proto_item *item_ptr;
    proto_tree *ptp_tree;
    guint16     offset = 0;

    guint32 pktType;

    /* Check that there's enough data */
    if ( tvb_captured_length_remaining(tvb, offset) < 8 )    /* ptp-photo smallest packet size is 8 */
        return (0);

    col_set_str(pinfo->cinfo,COL_PROTOCOL, "PTP/IP");

    col_set_str(
        pinfo->cinfo,
        COL_INFO,
        "Picture Transfer Protocol");

    item_ptr = proto_tree_add_protocol_format(tree, proto_ptpIP, tvb, offset,
         -1, "Picture Transfer Protocol");

    /* creating the tree */
    ptp_tree = proto_item_add_subtree(item_ptr, ett_ptpIP);
    /* [1] Defines first 2 fields as length and packet type. (Section 2.3)
     * Also note: the standard lists all multibyte values in PTP-IP as little-endian
     */

    /* note: len field size included in total len */
    proto_tree_add_item(ptp_tree, hf_ptpIP_len, tvb, offset, 4, ENC_LITTLE_ENDIAN);
    offset += 4;
    /* @todo:maybe add some length verification checks to see if len advertised matches actual len */

    pktType = tvb_get_letohl(tvb, offset);
    proto_tree_add_item(ptp_tree, hf_ptpIP_pktType, tvb, offset, 4, ENC_LITTLE_ENDIAN);
    offset += 4;
    switch (pktType) {
        case PTPIP_INIT_COMMAND_REQUEST:
            dissect_ptpIP_init_command_request(tvb, pinfo, ptp_tree, &offset);
            break;
        case PTPIP_INIT_COMMAND_ACK:
            dissect_ptpIP_init_command_ack(tvb, pinfo, ptp_tree, &offset);
            break;
        case PTPIP_INIT_EVENT_REQUEST:
            dissect_ptpIP_init_event_request(tvb, pinfo, ptp_tree, &offset);
            break;
        case PTPIP_INIT_EVENT_ACK:
            dissect_ptpIP_init_event_ack(pinfo);
            break;
        case PTPIP_CMD_REQUEST:
            dissect_ptpIP_operation_request(tvb, pinfo, ptp_tree, &offset);
            break;
        case PTPIP_CMD_RESPONSE:
            dissect_ptpIP_operation_response(tvb, pinfo, ptp_tree, &offset);
            break;
        case PTPIP_EVENT:
            dissect_ptpIP_event(tvb, pinfo, ptp_tree, &offset);
            break;
        case PTPIP_START_DATA_PACKET:
            dissect_ptpIP_start_data(tvb, pinfo, ptp_tree, &offset);
            break;
        case PTPIP_DATA_PACKET:
            dissect_ptpIP_data(tvb, pinfo, ptp_tree, &offset);
            break;
        case PTPIP_END_DATA_PACKET:
            dissect_ptpIP_end_data(tvb, pinfo, ptp_tree, &offset);
            break;
        default:
            break;
    }

    return (offset);
}

/**
 * Method to dissect the Init Command Request sent by the Initiator
 * in the connection. This packet is defined by [1] Section 2.3.1
 */
static void dissect_ptpIP_init_command_request(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint16 *offset)
{
    *offset += 0;

    col_set_str(
        pinfo->cinfo,
        COL_INFO,
        "Init Command Request");

    dissect_ptpIP_guid(tvb, pinfo, tree, offset);

    /* grabbing the name */
    dissect_ptpIP_unicode_name(tvb, pinfo, tree, offset);

    /* grabbing protocol version
     * Note: [3] does not list this in the packet field. . [1] 2.3.1 states it's the last 4
     * bytes of the packet.
    */
    dissect_ptpIP_protocol_version(tvb, tree, offset);
    return;
}

/**
 * Method to dissect the Init Command Ack sent by the Responder
 * in the connection. This packet is defined by [1] Section 2.3.2
 */
static void dissect_ptpIP_init_command_ack(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint16 *offset)
{
    guint32 connectionNumber;

    col_set_str(
        pinfo->cinfo,
        COL_INFO,
        "Init Command Ack");

    /* Grabbing the Connection Number */
    connectionNumber = tvb_get_letohl(tvb, *offset);
    proto_tree_add_item(tree, hf_ptpIP_connectionNumber, tvb, *offset, 4,ENC_LITTLE_ENDIAN);
    col_append_fstr(
        pinfo->cinfo,
        COL_INFO,
        " Connection #:%u",
        connectionNumber);
    *offset += 4;

    dissect_ptpIP_guid(tvb, pinfo, tree, offset);

    /* grabbing name */
    dissect_ptpIP_unicode_name(tvb,pinfo, tree, offset);

    /* grabbing protocol version. Note: like in the Init Command Request, [3] doesn't mention
     * this field, but [1] Section 2.3.2 does.
     */


    dissect_ptpIP_protocol_version(tvb, tree, offset);
}

/**
 * Dissects the Init Event Request packet specified in [1] Section 2.3.3.
 * Standard states that the packet only has 1 field.
 */
static void dissect_ptpIP_init_event_request(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint16 *offset)
{
    guint32 connectionNumber;

    col_set_str(
        pinfo->cinfo,
        COL_INFO,
        "Init Event Request");

    /* Grabbing the Connection Number */
    connectionNumber = tvb_get_letohl(tvb, *offset);
    proto_tree_add_item(tree, hf_ptpIP_connectionNumber, tvb, *offset, 4,ENC_LITTLE_ENDIAN);
    col_append_fstr(
        pinfo->cinfo,
        COL_INFO,
        " Connection #:%u",
        connectionNumber);
    *offset += 4;
}

/**
 * Dissects the Init Event Ack packet specified in [1] Section 2.3.4
 */
static void dissect_ptpIP_init_event_ack(packet_info *pinfo)
{
    col_set_str(
        pinfo->cinfo,
        COL_INFO,
        "Init Event Ack");

    /* packet has no payload. */
}

/**
 * Dissects the Operation Request Packet specified in [1] Section 2.3.6
 * Note: many of the fields in this packet move from PTP/IP to PTP layer
 * of the stack.  Work will need to be done in future iterations to make this
 * compatible with PTP/USB.
 */
static void dissect_ptpIP_operation_request(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint16 *offset)
{
    guint16 opcode;
    guint16 transactionID_offset = *offset; /* need to save this to output transaction id in pinfo */

    col_set_str(
        pinfo->cinfo,
        COL_INFO,
        "Operation Request Packet ");

    proto_tree_add_item(tree,hf_ptpIP_dataPhaseInfo, tvb, *offset, 4, ENC_LITTLE_ENDIAN);
    *offset += 4;

    opcode = tvb_get_letohs(tvb, *offset);
    if (opcode & PTP_OC_EXTENSION_MASK)
    {
        if (pref_vendor == PTP_VENDOR_UNKNOWN)
        {
            proto_tree_add_item(tree, hf_ptp_vendor_opCode, tvb, *offset, 2, ENC_LITTLE_ENDIAN);
        }
        else
        {
            value_string_ext* vendor_values = NULL;

            switch(pref_vendor)
            {
            case PTP_VENDOR_EASTMAN_KODAK:
                vendor_values = &ptp_opcode_ek_names_ext;
                break;
            case PTP_VENDOR_CANON:
                vendor_values = &ptp_opcode_canon_names_ext;
                break;
            case PTP_VENDOR_NIKON:
                vendor_values = &ptp_opcode_nikon_names_ext;
                break;
            case PTP_VENDOR_CASIO:
                vendor_values = &ptp_opcode_casio_names_ext;
                break;
            case PTP_VENDOR_MTP:
                vendor_values = &ptp_opcode_mtp_names_ext;
                break;
            case PTP_VENDOR_OLYMPUS:
                vendor_values = &ptp_opcode_olympus_names_ext;
                break;
            default:
                DISSECTOR_ASSERT(FALSE);
                break;
            }

            proto_tree_add_uint_format_value(tree, hf_ptp_vendor_opCode, tvb, *offset, 2, opcode, "%s (0x%04x)",
                        val_to_str_ext_const(opcode, vendor_values, "Unknown"), opcode);
        }
    }
    else
    {
        proto_tree_add_item(tree, hf_ptp_opCode, tvb, *offset, 2, ENC_LITTLE_ENDIAN);
    }
    *offset += 2;

    transactionID_offset = *offset; /* we'll dissect the transactionID later because
                                       opcode handling erases the column */
    *offset += 4;

    /* carving out the parameters. [1] 2.3.6 states there can be at most 5. Params are defined in [2] 10.1 & 10.4 */
    switch (opcode)
    {
        case PTP_OC_GetDeviceInfo:
            /* [1] 10.5.1 */
            col_set_str(
                pinfo->cinfo,
                COL_INFO,
                "GetDeviceInfo");
            /* No parameters */
            break;
        case PTP_OC_OpenSession:
            dissect_ptp_opCode_openSession(tvb, pinfo, tree, offset);
            break;
        case PTP_OC_CloseSession:
            /* [1] 10.5.3 */
            col_set_str(
                pinfo->cinfo,
                COL_INFO,
                "CloseSession");
            /* No parameters */
            break;
        case PTP_OC_GetStorageIDs:
            /* [2]  10.5.4 */
            col_set_str(
                pinfo->cinfo,
                COL_INFO,
                "GetStorageIDs");
            /* states data is a storage array. Needs eventual investigation. */
            break;
        default:
            break;
    }
    dissect_ptp_transactionID(tvb, pinfo, tree, &transactionID_offset);
}

/**
 * Dissects the Operation Response Packet specified in [1] Section 2.3.7
 * Note: many of the fields in this packet move from PTP/IP to PTP layer
 * of the stack.  Work will need to be done in future iterations to make this
 * compatible with PTP/USB.
 */
static void dissect_ptpIP_operation_response(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint16 *offset)
{
    guint16 resp;

    col_set_str(
        pinfo->cinfo,
        COL_INFO,
        "Operation Response Packet ");

    resp = tvb_get_letohs(tvb, *offset);
    if (resp & PTP_OC_EXTENSION_MASK)
    {
        const value_string* vendor_values = NULL;
        switch(pref_vendor)
        {
        case PTP_VENDOR_EASTMAN_KODAK:
            vendor_values = ptp_respcode_ek_names;
            break;
        case PTP_VENDOR_CANON:
            vendor_values = ptp_respcode_canon_names;
            break;
        case PTP_VENDOR_NIKON:
            vendor_values = ptp_respcode_nikon_names;
            break;
        case PTP_VENDOR_MTP:
            vendor_values = ptp_respcode_mtp_names;
            break;
        case PTP_VENDOR_UNKNOWN:
        case PTP_VENDOR_CASIO:
        case PTP_VENDOR_OLYMPUS:
        default:
            vendor_values = ptp_respcode_names;
            break;
        }

        proto_tree_add_uint_format_value(tree, hf_ptp_vendor_opCode, tvb, *offset, 2, resp, "%s (0x%04x)",
                        val_to_str_const(resp, vendor_values, "Unknown"), resp);
    }
    else
    {
        proto_tree_add_item(tree, hf_ptp_respCode, tvb, *offset, 2, ENC_LITTLE_ENDIAN);
    }
    *offset += 2;

    dissect_ptp_transactionID(tvb, pinfo, tree, offset);

}

/**
 * Dissects the Event Packet specified in [1] Section 2.3.8
 * Note: many of the fields in this packet move from PTP/IP to PTP layer
 * of the stack.  Work will need to be done in future iterations to make this
 * compatible with PTP/USB.
 */
static void dissect_ptpIP_event(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint16 *offset)
{
    col_set_str(
        pinfo->cinfo,
        COL_INFO,
        "Event Packet ");

    proto_tree_add_item(tree, hf_ptp_eventCode, tvb, *offset, 2, ENC_LITTLE_ENDIAN);
    *offset += 2;

    dissect_ptp_transactionID(tvb, pinfo, tree, offset);
}

/**
 * Dissects the Event Packet specified in [1] Section 2.3.9
 * Note: many of the fields in this packet move from PTP/IP to PTP layer
 * of the stack.  Work will need to be done in future iterations to make this
 * compatible with PTP/USB.
 */
static void dissect_ptpIP_start_data(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint16 *offset)
{
    guint64 dataLen;

    col_set_str(
        pinfo->cinfo,
        COL_INFO,
        "Start Data Packet ");

    dissect_ptp_transactionID(tvb, pinfo, tree, offset);


    dataLen = tvb_get_letoh64(tvb, *offset);
    proto_tree_add_item(tree, hf_ptp_totalDataLength, tvb, *offset, 8, ENC_LITTLE_ENDIAN);
    *offset += 8;
    if (dataLen == G_GUINT64_CONSTANT(0xFFFFFFFFFFFFFFFF)) /* [1] specifies in 2.3.9 if total data len
                                                              is this value then len is unknown */
    {
        col_append_str(
            pinfo->cinfo,
            COL_INFO,
            " Data Length Unknown");
    }
}

static void dissect_ptpIP_data(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint16 *offset)
{

    col_set_str(
        pinfo->cinfo,
        COL_INFO,
        "Data Packet ");

    dissect_ptp_transactionID(tvb, pinfo, tree, offset);

}

/**
 * Dissects the End Data specified in [1] Section 2.3.11
 * Note: many of the fields in this packet move from PTP/IP to PTP layer
 * of the stack.  Work will need to be done in future iterations to make this
 * compatible with PTP/USB.
 */
static void dissect_ptpIP_end_data(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint16 *offset)
{

    col_set_str(
        pinfo->cinfo,
        COL_INFO,
        "End Data Packet ");

    dissect_ptp_transactionID(tvb, pinfo, tree, offset);
}

/**
 * Dissects the Opcode Open Session as defined by [2] 10.5.2
 */
void dissect_ptp_opCode_openSession(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint16 *offset)
{
    col_set_str(
        pinfo->cinfo,
        COL_INFO,
        "OpenSession");

    proto_tree_add_item(tree, hf_ptp_opCode_param_sessionID, tvb, *offset, 4 , ENC_LITTLE_ENDIAN);
    *offset += 4;
}

/**
 * The transaction ID is defined  in [2]  9.3.1
 * and used in multiple message types. This method handles
 * parsing the field and adding the value to the info
 * column.
 *
 */
void dissect_ptp_transactionID(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint16 *offset)
{
    guint32 transactionID;

    transactionID = tvb_get_letohl(tvb, *offset);
    proto_tree_add_item(tree, hf_ptp_transactionID, tvb, *offset, 4, ENC_LITTLE_ENDIAN);
    *offset += 4;
    col_append_fstr(
        pinfo->cinfo,
        COL_INFO,
        " Transaction ID: %d",
        transactionID);
}

/**
 * This method handles dissecting the Unicode name that is
 * specificed in multiple packets.
 */
static void dissect_ptpIP_unicode_name(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint16 *offset)
{
    const guint8 *name;
    gint          nameLen;

    nameLen = tvb_unicode_strsize(tvb, *offset);
    proto_tree_add_item_ret_string(tree, hf_ptpIP_name, tvb, *offset, nameLen, ENC_UTF_16|ENC_LITTLE_ENDIAN, pinfo->pool, &name);
    *offset += nameLen;
    col_append_fstr(pinfo->cinfo, COL_INFO, " Name: %s", name);
}

/** Method dissects the protocol version from the packets.
 * Additional note, section 3 of [1] defines the Binary Protocol version
 * as 0x00010000 == 1.0 where the Most significant bits are the major version and the least
 * significant bits are the minor version.
 */
static void dissect_ptpIP_protocol_version(tvbuff_t *tvb, proto_tree *tree, guint16 *offset)
{

    guint8  version[30];
    guint32 protoVersion;
    guint16 majorVersion, minorVersion;

    protoVersion = tvb_get_letohl(tvb, *offset);
    /* logic to format version */
    minorVersion = protoVersion & 0xFFFF;
    majorVersion = (protoVersion & 0xFFFF0000) >>16;
    snprintf(version, sizeof(version), "%u.%u", majorVersion, minorVersion);
    proto_tree_add_string(tree, hf_ptpIP_version, tvb, *offset, 4, version);
    *offset += 4;
}

/* Grabbing the GUID */
static void dissect_ptpIP_guid(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint16 *offset)
{
    guint8 *guid;

    guid = tvb_bytes_to_str(pinfo->pool, tvb, *offset, PTPIP_GUID_SIZE);
    proto_tree_add_item(tree, hf_ptpIP_guid, tvb, *offset, PTPIP_GUID_SIZE, ENC_NA);
    *offset += PTPIP_GUID_SIZE;
    col_append_fstr(
        pinfo->cinfo,
        COL_INFO,
        " GUID: %s",
        guid);
}

void proto_register_ptpip( void )
{
    static hf_register_info hf[] = {
        /* PTP/IP layer */
        { &hf_ptpIP_len, {
            "Length", "ptpip.len", FT_UINT32, BASE_DEC,
            NULL, 0, NULL, HFILL }},
        { &hf_ptpIP_pktType, {
            "Packet Type", "ptpip.pktType", FT_UINT32, BASE_HEX | BASE_EXT_STRING,
            &ptpip_pktType_names_ext, 0, NULL, HFILL }},
        { &hf_ptpIP_guid, {
            "GUID", "ptpip.guid", FT_BYTES, BASE_NONE,
            NULL, 0, NULL, HFILL }},
        { &hf_ptpIP_name, {
            "Host Name", "ptpip.name", FT_STRINGZ, BASE_NONE,
            NULL, 0, NULL, HFILL }},
        { &hf_ptpIP_version, {
            "Version", "ptpip.version", FT_STRING, BASE_NONE,
            NULL, 0, NULL, HFILL }},
        { &hf_ptpIP_connectionNumber, {
            "Connection Number", "ptpip.connection", FT_UINT32, BASE_DEC,
            NULL, 0, NULL, HFILL }},
        { &hf_ptpIP_dataPhaseInfo, {
            "Data Phase Info", "ptpip.phaseinfo", FT_UINT32, BASE_HEX,
            NULL, 0, NULL, HFILL }},
        /* PTP layer */
             /* leaving names with "ptpip" to try and prevent namespace issues. probably changing later. */
        { &hf_ptp_opCode, {
            "Operation Code", "ptpip.opcode", FT_UINT16, BASE_HEX|BASE_EXT_STRING,
            &ptp_opcode_names_ext, 0, NULL, HFILL }},
        { &hf_ptp_vendor_opCode, {
            "Operation Code", "ptpip.opcode", FT_UINT16, BASE_HEX,
            NULL, 0, NULL, HFILL }},
        { &hf_ptp_respCode, {
            "Response Code", "ptpip.respcode", FT_UINT16, BASE_HEX,
            VALS(ptp_respcode_names), 0, NULL, HFILL }},
        { &hf_ptp_eventCode, {
            "Event Code", "ptpip.eventcode", FT_UINT16, BASE_HEX,
            NULL, 0, NULL, HFILL }},
        { &hf_ptp_transactionID, {
            "Transaction ID", "ptpip.transactionID", FT_UINT32, BASE_HEX,
            NULL, 0, NULL, HFILL }},
        { &hf_ptp_totalDataLength, {
            "Total Data Length", "ptpip.datalen", FT_UINT64, BASE_DEC_HEX,
            NULL, 0, NULL, HFILL }},
        { &hf_ptp_opCode_param_sessionID, {
            "Session ID", "ptpip.opcode.param.sessionid", FT_UINT32, BASE_HEX,
            NULL, 0, NULL, HFILL }},

    };
    static gint *ett[] = {
        &ett_ptpIP,
        &ett_ptpIP_hdr
    };

    module_t *ptpIP_module;

    proto_ptpIP = proto_register_protocol("Picture Transfer Protocol Over IP", "PTP/IP", "ptpip");

    proto_register_field_array(proto_ptpIP, hf, array_length(hf));
    proto_register_subtree_array(ett, array_length(ett));

    /*  Use register_dissector() to indicate that dissect_ptpIP()
    *  returns the number of bytes it dissected (or 0 if it thinks the packet
    *  does not belong to PROTONAME).
    */
    ptpIP_handle = register_dissector("ptpip", dissect_ptpIP, proto_ptpIP);

    ptpIP_module = prefs_register_protocol(proto_ptpIP, NULL);

    prefs_register_enum_preference(ptpIP_module, "vendor",
            "Camera vendor",
            "Properly translates vendor specific opcodes",
            &pref_vendor, pref_hsp_role, FALSE);

}

void proto_reg_handoff_ptpIP( void ) {
    dissector_add_uint_with_preference("tcp.port", PTPIP_PORT, ptpIP_handle);
}

/*
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
 *
 * Local variables:
 * c-basic-offset: 4
 * tab-width: 8
 * indent-tabs-mode: nil
 * End:
 *
 * vi: set shiftwidth=4 tabstop=8 expandtab:
 * :indentSize=4:tabSize=8:noTabs=true:
 */