forked from bearxiong99/wireshark-dlms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdlms.c
2140 lines (1971 loc) · 83.3 KB
/
dlms.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
/*
* dlms.c - Device Language Message Specification dissector plugin for Wireshark
*
* Copyright (C) 2018 Andre B. Oliveira
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#define WS_BUILD_DLL
#define NEW_PROTO_TREE_API
#include <config.h>
#include <epan/exceptions.h>
#include <epan/expert.h>
#include <epan/packet.h>
#include <epan/reassemble.h>
#include <ws_symbol_export.h>
#include "obis.h"
/* Choice values for the currently supported ACSE and xDLMS APDUs */
#define DLMS_DATA_NOTIFICATION 15
#define DLMS_AARQ 96
#define DLMS_AARE 97
#define DLMS_RLRQ 98
#define DLMS_RLRE 99
#define DLMS_GET_REQUEST 192
#define DLMS_SET_REQUEST 193
#define DLMS_EVENT_NOTIFICATION_REQUEST 194
#define DLMS_ACTION_REQUEST 195
#define DLMS_GET_RESPONSE 196
#define DLMS_SET_RESPONSE 197
#define DLMS_ACTION_RESPONSE 199
#define DLMS_EXCEPTION_RESPONSE 216
#define DLMS_ACCESS_REQUEST 217
#define DLMS_ACCESS_RESPONSE 218
static const value_string dlms_apdu_names[] = {
{ DLMS_DATA_NOTIFICATION, "data-notification" },
{ DLMS_AARQ, "aarq" },
{ DLMS_AARE, "aare" },
{ DLMS_RLRQ, "rlrq" },
{ DLMS_RLRE, "rlre" },
{ DLMS_GET_REQUEST, "get-request" },
{ DLMS_SET_REQUEST, "set-request" },
{ DLMS_EVENT_NOTIFICATION_REQUEST, "event-notification-request" },
{ DLMS_ACTION_REQUEST, "action-request" },
{ DLMS_GET_RESPONSE, "get-response" },
{ DLMS_SET_RESPONSE, "set-response" },
{ DLMS_ACTION_RESPONSE, "action-response" },
{ DLMS_EXCEPTION_RESPONSE, "exception-response" },
{ DLMS_ACCESS_REQUEST, "access-request" },
{ DLMS_ACCESS_RESPONSE, "access-response" },
{ 0, 0 }
};
/* Choice values for a Get-Request */
#define DLMS_GET_REQUEST_NORMAL 1
#define DLMS_GET_REQUEST_NEXT 2
#define DLMS_GET_REQUEST_WITH_LIST 3
static const value_string dlms_get_request_names[] = {
{ DLMS_GET_REQUEST_NORMAL, "get-request-normal" },
{ DLMS_GET_REQUEST_NEXT, "get-request-next" },
{ DLMS_GET_REQUEST_WITH_LIST, "get-request-with-list" },
{ 0, 0 }
};
/* Choice values for a Get-Response */
#define DLMS_GET_RESPONSE_NORMAL 1
#define DLMS_GET_RESPONSE_WITH_DATABLOCK 2
#define DLMS_GET_RESPONSE_WITH_LIST 3
static const value_string dlms_get_response_names[] = {
{ DLMS_GET_RESPONSE_NORMAL, "get-response-normal" },
{ DLMS_GET_RESPONSE_WITH_DATABLOCK, "get-response-with-datablock" },
{ DLMS_GET_RESPONSE_WITH_LIST, "get-response-with-list" },
{ 0, 0 }
};
/* Choice values for a Set-Request */
#define DLMS_SET_REQUEST_NORMAL 1
#define DLMS_SET_REQUEST_WITH_FIRST_DATABLOCK 2
#define DLMS_SET_REQUEST_WITH_DATABLOCK 3
#define DLMS_SET_REQUEST_WITH_LIST 4
#define DLMS_SET_REQUEST_WITH_LIST_AND_FIRST_DATABLOCK 5
static const value_string dlms_set_request_names[] = {
{ DLMS_SET_REQUEST_NORMAL, "set-request-normal" },
{ DLMS_SET_REQUEST_WITH_FIRST_DATABLOCK, "set-request-with-first-datablock" },
{ DLMS_SET_REQUEST_WITH_DATABLOCK, "set-request-with-datablock" },
{ DLMS_SET_REQUEST_WITH_LIST, "set-request-with-list" },
{ DLMS_SET_REQUEST_WITH_LIST_AND_FIRST_DATABLOCK, "set-request-with-list-and-first-datablock" },
{ 0, 0 }
};
/* Choice values for a Set-Response */
#define DLMS_SET_RESPONSE_NORMAL 1
#define DLMS_SET_RESPONSE_DATABLOCK 2
#define DLMS_SET_RESPONSE_LAST_DATABLOCK 3
#define DLMS_SET_RESPONSE_LAST_DATABLOCK_WITH_LIST 4
#define DLMS_SET_RESPONSE_WITH_LIST 5
static const value_string dlms_set_response_names[] = {
{ DLMS_SET_RESPONSE_NORMAL, "set-response-normal" },
{ DLMS_SET_RESPONSE_DATABLOCK, "set-response-datablock" },
{ DLMS_SET_RESPONSE_LAST_DATABLOCK, "set-response-last-datablock" },
{ DLMS_SET_RESPONSE_LAST_DATABLOCK_WITH_LIST, "set-response-last-datablock-with-list" },
{ DLMS_SET_RESPONSE_WITH_LIST, "set-response-with-list" },
{ 0, 0 }
};
/* Choice values for an Action-Request */
#define DLMS_ACTION_REQUEST_NORMAL 1
#define DLMS_ACTION_REQUEST_NEXT_PBLOCK 2
#define DLMS_ACTION_REQUEST_WITH_LIST 3
#define DLMS_ACTION_REQUEST_WITH_FIRST_PBLOCK 4
#define DLMS_ACTION_REQUEST_WITH_LIST_AND_FIRST_PBLOCK 5
#define DLMS_ACTION_REQUEST_WITH_PBLOCK 6
static const value_string dlms_action_request_names[] = {
{ DLMS_ACTION_REQUEST_NORMAL, "action-request-normal" },
{ DLMS_ACTION_REQUEST_NEXT_PBLOCK, "action-request-next-pblock" },
{ DLMS_ACTION_REQUEST_WITH_LIST, "action-request-with-list" },
{ DLMS_ACTION_REQUEST_WITH_FIRST_PBLOCK, "action-request-with-first-pblock" },
{ DLMS_ACTION_REQUEST_WITH_LIST_AND_FIRST_PBLOCK, "action-request-with-list-and-first-pblock" },
{ DLMS_ACTION_REQUEST_WITH_PBLOCK, "action-request-with-pblock" },
{ 0, 0 }
};
/* Choice values for an Action-Response */
#define DLMS_ACTION_RESPONSE_NORMAL 1
#define DLMS_ACTION_RESPONSE_WITH_PBLOCK 2
#define DLMS_ACTION_RESPONSE_WITH_LIST 3
#define DLMS_ACTION_RESPONSE_NEXT_PBLOCK 4
static const value_string dlms_action_response_names[] = {
{ DLMS_ACTION_RESPONSE_NORMAL, "action-response-normal" },
{ DLMS_ACTION_RESPONSE_WITH_PBLOCK, "action-response-with-pblock" },
{ DLMS_ACTION_RESPONSE_WITH_LIST, "action-response-with-list" },
{ DLMS_ACTION_RESPONSE_NEXT_PBLOCK, "action-response-next-pblock" },
{ 0, 0 },
};
/* Choice values for an Access-Request-Specification */
#define DLMS_ACCESS_REQUEST_GET 1
#define DLMS_ACCESS_REQUEST_SET 2
#define DLMS_ACCESS_REQUEST_ACTION 3
#define DLMS_ACCESS_REQUEST_GET_WITH_SELECTION 4
#define DLMS_ACCESS_REQUEST_SET_WITH_SELECTION 5
static const value_string dlms_access_request_names[] = {
{ DLMS_ACCESS_REQUEST_GET, "access-request-get" },
{ DLMS_ACCESS_REQUEST_SET, "access-request-set" },
{ DLMS_ACCESS_REQUEST_ACTION, "access-request-action" },
{ DLMS_ACCESS_REQUEST_GET_WITH_SELECTION, "access-request-get-with-selection" },
{ DLMS_ACCESS_REQUEST_SET_WITH_SELECTION, "access-request-set-with-selection" },
{ 0, 0 },
};
/* Choice values for an Access-Response-Specification */
static const value_string dlms_access_response_names[] = {
{ 1, "access-response-get" },
{ 2, "access-response-set" },
{ 3, "access-response-action" },
{ 0, 0 },
};
/* Enumerated values for a Data-Access-Result */
static const value_string dlms_data_access_result_names[] = {
{ 0, "success" },
{ 1, "hardware-fault" },
{ 2, "temporary-failure" },
{ 3, "read-write-denied" },
{ 4, "object-undefined" },
{ 9, "object-class-inconsistent" },
{ 11, "object-unvailable" },
{ 12, "type-unmatched" },
{ 13, "scope-of-access-violated" },
{ 14, "data-block-unavailable" },
{ 15, "long-get-aborted" },
{ 16, "no-long-get-in-progress" },
{ 17, "long-set-aborted" },
{ 18, "no-long-set-in-progress" },
{ 19, "data-block-number-invalid" },
{ 250, "other-reason" },
{ 0, 0 }
};
/* Enumerated values for an Action-Result */
static const value_string dlms_action_result_names[] = {
{ 0, "success" },
{ 1, "hardware-fault" },
{ 2, "temporary-failure" },
{ 3, "read-write-denied" },
{ 4, "object-undefined" },
{ 9, "object-class-inconsistent" },
{ 11, "object-unavailable" },
{ 12, "type-unmatched" },
{ 13, "scope-of-access-violated" },
{ 14, "data-block-unavailable" },
{ 15, "long-action-aborted" },
{ 16, "no-long-action-in-progress" },
{ 250, "other-reason" },
{ 0, 0 }
};
/* Enumerated values for a state-error in an Exception-Response */
static const value_string dlms_state_error_names[] = {
{ 1, "service-not-allowed" },
{ 2, "service-unknown" },
{ 0, 0 }
};
/* Enumerated values for a service-error in an Exception-Response */
static const value_string dlms_service_error_names[] = {
{ 1, "operation-not-possible" },
{ 2, "service-not-supported" },
{ 3, "other-reason" },
{ 0, 0 }
};
/* Names of the values of the service-class bit in the Invoke-Id-And-Priority */
static const value_string dlms_service_class_names[] = {
{ 0, "unconfirmed" },
{ 1, "confirmed" },
{ 0, 0 }
};
/* Names of the values of the priority bit in the Invoke-Id-And-Priority */
static const value_string dlms_priority_names[] = {
{ 0, "normal" },
{ 1, "high" },
{ 0, 0 }
};
/* Names of the values of the self-descriptive bit in the Long-Invoke-Id-And-Priority */
static const value_string dlms_self_descriptive_names[] = {
{ 0, "not-self-descriptive" },
{ 1, "self-descriptive" },
{ 0, 0 }
};
/* Names of the values of the processing-option bit in the Long-Invoke-Id-And-Priority */
static const value_string dlms_processing_option_names[] = {
{ 0, "continue-on-error" },
{ 1, "break-on-error" },
{ 0, 0 }
};
/* HDLC frame names for the control field values (with the RRR, P/F, and SSS bits masked off) */
static const value_string dlms_hdlc_frame_names[] = {
{ 0x00, "I (Information)" },
{ 0x01, "RR (Receive Ready)" },
{ 0x03, "UI (Unnumbered Information)" },
{ 0x05, "RNR (Receive Not Ready)" },
{ 0x0f, "DM (Disconnected Mode)" },
{ 0x43, "DISC (Disconnect)" },
{ 0x63, "UA (Unnumbered Acknowledge)" },
{ 0x83, "SNRM (Set Normal Response Mode)" },
{ 0x87, "FRMR (Frame Reject)" },
{ 0, 0 }
};
/* Structure with the names of a DLMS/COSEM class */
struct dlms_cosem_class {
const char *name;
const char *attributes[18]; /* index 0 is attribute 2 (attribute 1 is always "logical_name") */
const char *methods[11]; /* index 0 is method 1 */
};
typedef struct dlms_cosem_class dlms_cosem_class;
/* Get the DLMS/COSEM class with the specified class_id */
static const dlms_cosem_class *
dlms_get_class(int class_id) {
const short ids[] = {
1, /* data */
3, /* register */
4, /* extended register */
5, /* demand register */
7, /* profile generic */
8, /* clock */
9, /* script table */
10, /* schedule */
11, /* special days table */
15, /* association ln */
17, /* sap assignment */
18, /* image transfer */
20, /* activity calendar */
21, /* register monitor */
22, /* single action schedule */
23, /* iec hdlc setup */
30, /* data protection */
70, /* disconnect control */
71, /* limiter */
104, /* zigbee network control */
111, /* account */
112, /* credit */
113, /* charge */
115, /* token gateway */
9000, /* extended data */
};
static const struct dlms_cosem_class classes[] = {
{
"data",
{
"value"
}
},{
"register",
{
"value",
"scaler_unit"
},{
"reset"
}
},{
"extended_register",
{
"value",
"scaler_unit",
"status",
"capture_time"
},{
"reset"
}
},{
"demand_register",
{
"current_average_value",
"last_average_value",
"scaler_unit",
"status",
"capture_time",
"start_time_current",
"period",
"number_of_periods"
},{
"reset",
"next_period"
}
},{
"profile_generic",
{
"buffer",
"capture_objects",
"capture_period",
"sort_method",
"sort_object",
"entries_in_use",
"profile_entries"
},{
"reset",
"capture",
"get_buffer_by_range",
"get_buffer_by_index"
}
},{
"clock",
{
"time",
"time_zone",
"status",
"daylight_savings_begin",
"daylight_savings_end",
"daylight_savings_deviation",
"daylight_savings_enabled",
"clock_base"
},{
"adjust_to_quarter",
"adjust_to_measuring_period",
"adjust_to_minute",
"adjust_to_preset_time",
"preset_adjusting_time",
"shift_time"
}
},{
"script_table",
{
"scripts"
},{
"execute"
}
},{
"schedule",
{
"entries"
},{
"enable_disable",
"insert",
"delete"
}
},{
"special_days_table",
{
"entries"
},{
"insert",
"delete"
}
},{
"association_ln",
{
"object_list",
"associated_partners_id",
"application_context_name",
"xdlms_context_info",
"authentication_mechanism_name",
"secret",
"association_status",
"security_setup_reference",
"user_list",
"current_user"
},{
"reply_to_hls_authentication",
"change_hls_secret",
"add_object",
"remove_object",
"add_user",
"remove_user"
}
},{
"sap_assignment",
{
"sap_assignment_list"
},{
"connect_logical_devices"
}
},{
"image_transfer",
{
"image_block_size",
"image_transferred_blocks_status",
"image_first_not_transferred_block_number",
"image_transfer_enabled",
"image_transfer_status",
"image_to_activate_info"
},{
"image_transfer_initiate",
"image_block_transfer",
"image_verify",
"image_activate"
}
},{
"activity_calendar",
{
"calendar_name_active",
"season_profile_active",
"week_profile_table_active",
"day_profile_table_active",
"calendar_name_passive",
"season_profile_passive",
"week_profile_table_passive",
"day_profile_table_passive",
"active_passive_calendar_time"
},{
"active_passive_calendar"
}
},{
"register_monitor",
{
"thresholds",
"monitored_value",
"actions"
}
},{
"single_action_schedule",
{
"executed_script",
"type",
"execution_time"
}
},{
"iec_hdlc_setup",
{
"comm_speed",
"window_size_transmit",
"window_size_receive",
"max_info_field_length_transmit",
"max_info_field_length_receive",
"inter_octet_time_out",
"inactivity_time_out",
"device_address"
}
},{
"data_protection",
{
"protection_buffer",
"protection_object_list",
"protection_parameters_get",
"protection_parameters_set",
"required_protection"
},{
"get_protected_attributes",
"set_protected_attributes",
"invoke_protected_method"
}
},{
"disconnect_control",
{
"output_state",
"control_state",
"control_mode"
},{
"remote_disconnect",
"remote_reconnect"
}
},{
"limiter",
{
"monitored_value",
"threshold_active",
"threshold_normal",
"threshold_emergency",
"min_over_threshold_duration",
"min_under_threshold_duration",
"emergency_profile",
"emergency_profile_group_id_list",
"emergency_profile_active",
"actions"
}
},{
"zigbee_network_control",
{
"enable_disable_joining",
"join_timeout",
"active_devices"
},{
"register_device",
"unregister_device",
"unregister_all_devices",
"backup_pan",
"restore_pan",
"identify_device",
"remove_mirror",
"update_network_key",
"update_link_key",
"create_pan",
"remove_pan"
}
},{
"account",
{
"account_mode_and_status",
"current_credit_in_use",
"current_credit_status",
"available_credit",
"amount_to_clear",
"clearance_threshold",
"aggregated_debt",
"credit_reference_list",
"charge_reference_list",
"credit_charge_configuration",
"token_gateway_configuration",
"account_activation_time",
"account_closure_time",
"currency",
"low_credit_threshold",
"next_credit_available_threshold",
"max_provision",
"max_provision_period"
},{
"activate_account",
"close_account",
"reset_account"
}
},{
"credit",
{
"current_credit_amount",
"credit_type",
"priority",
"warning_threshold",
"limit",
"credit_configuration",
"credit_status",
"preset_credit_amount",
"credit_available_threshold",
"period"
},{
"update_amount",
"set_amount_to_value",
"invoke_credit"
}
},{
"charge",
{
"total_amount_paid",
"charge_type",
"priority",
"unit_charge_active",
"unit_charge_passive",
"unit_charge_activation_time",
"period",
"charge_configuration",
"last_collection_time",
"last_collection_amount",
"total_amount_remaining",
"proportion"
},{
"update_unit_charge",
"activate_passive_unit_charge",
"collect",
"update_total_amount_remaining",
"set_total_amount_remaining"
}
},{
"token_gateway",
{
"token",
"token_time",
"token_description",
"token_delivery_method",
"token_status"
},{
"enter"
}
},{
"extended_data",
{
"value_active",
"scaler_unit_active",
"value_passive",
"scaler_unit_passive",
"activate_passive_value_time"
},{
"reset",
"activate_passive_value"
}
}
};
unsigned i;
for (i = 0; i < array_length(ids); i++) {
if (ids[i] == class_id) {
return &classes[i];
}
}
return 0;
}
static const char *
dlms_get_attribute_name(const dlms_cosem_class *c, int attribute_id) {
if (attribute_id > 1 && attribute_id < array_length(c->attributes) + 2) {
return c->attributes[attribute_id - 2];
} else if (attribute_id == 1) {
return "logical_name";
}
return 0;
}
static const char *
dlms_get_method_name(const dlms_cosem_class *c, int method_id) {
if (method_id > 0 && method_id < array_length(c->methods) + 1) {
return c->methods[method_id - 1];
}
return 0;
}
/* The DLMS protocol handle */
static int dlms_proto;
/* The DLMS header_field_info (hfi) structures */
static struct {
/* HDLC */
header_field_info hdlc_flag; /* opening/closing flag */
header_field_info hdlc_type; /* frame format type */
header_field_info hdlc_segmentation; /* frame format segmentation bit */
header_field_info hdlc_length; /* frame format length sub-field */
header_field_info hdlc_address; /* destination/source address */
header_field_info hdlc_frame_i; /* control field & 0x01 (I) */
header_field_info hdlc_frame_rr_rnr; /* control field & 0x0f (RR or RNR) */
header_field_info hdlc_frame_other; /* control field & 0xef (all other) */
header_field_info hdlc_pf; /* poll/final bit */
header_field_info hdlc_rsn; /* receive sequence number N(R) */
header_field_info hdlc_ssn; /* send sequence number N(S) */
header_field_info hdlc_hcs; /* header check sequence */
header_field_info hdlc_fcs; /* frame check sequence */
header_field_info hdlc_parameter; /* information field parameter */
header_field_info hdlc_llc; /* LLC header */
/* IEC 4-32 LLC */
header_field_info iec432llc;
/* Wrapper Protocol Data Unit (WPDU) */
header_field_info wrapper_header;
/* APDU */
header_field_info apdu;
header_field_info client_max_receive_pdu_size;
header_field_info server_max_receive_pdu_size;
header_field_info get_request;
header_field_info set_request;
header_field_info action_request;
header_field_info get_response;
header_field_info set_response;
header_field_info action_response;
header_field_info access_request;
header_field_info access_response;
header_field_info class_id;
header_field_info instance_id;
header_field_info attribute_id;
header_field_info method_id;
header_field_info access_selector;
header_field_info data_access_result;
header_field_info action_result;
header_field_info block_number;
header_field_info last_block;
header_field_info type_description;
header_field_info data;
header_field_info date_time;
header_field_info length;
header_field_info state_error;
header_field_info service_error;
/* Invoke-Id-And-Priority */
header_field_info invoke_id;
header_field_info service_class;
header_field_info priority;
/* Long-Invoke-Id-And-Priority */
header_field_info long_invoke_id;
header_field_info long_self_descriptive;
header_field_info long_processing_option;
header_field_info long_service_class;
header_field_info long_priority;
/* Conformance bits */
header_field_info conformance_general_protection;
header_field_info conformance_general_block_transfer;
header_field_info conformance_read;
header_field_info conformance_write;
header_field_info conformance_unconfirmed_write;
header_field_info conformance_attribute0_supported_with_set;
header_field_info conformance_priority_mgmt_supported;
header_field_info conformance_attribute0_supported_with_get;
header_field_info conformance_block_transfer_with_get_or_read;
header_field_info conformance_block_transfer_with_set_or_write;
header_field_info conformance_block_transfer_with_action;
header_field_info conformance_multiple_references;
header_field_info conformance_information_report;
header_field_info conformance_data_notification;
header_field_info conformance_access;
header_field_info conformance_parameterized_access;
header_field_info conformance_get;
header_field_info conformance_set;
header_field_info conformance_selective_access;
header_field_info conformance_event_notification;
header_field_info conformance_action;
/* fragment_items */
header_field_info fragments;
header_field_info fragment;
header_field_info fragment_overlap;
header_field_info fragment_overlap_conflict;
header_field_info fragment_multiple_tails;
header_field_info fragment_too_long_fragment;
header_field_info fragment_error;
header_field_info fragment_count;
header_field_info reassembled_in;
header_field_info reassembled_length;
header_field_info reassembled_data;
} dlms_hfi HFI_INIT(dlms_proto) = {
/* HDLC */
{ "Flag", "dlms.hdlc.flag", FT_NONE, BASE_NONE, 0, 0, 0, HFILL },
{ "Type", "dlms.hdlc.type", FT_UINT16, BASE_DEC, 0, 0xf000, 0, HFILL },
{ "Segmentation", "dlms.hdlc.segmentation", FT_UINT16, BASE_DEC, 0, 0x0800, 0, HFILL },
{ "Length", "dlms.hdlc.length", FT_UINT16, BASE_DEC, 0, 0x07ff, 0, HFILL },
{ "Upper HDLC Address", "dlms.hdlc.address", FT_UINT8, BASE_DEC, 0, 0xfe, 0, HFILL },
{ "Frame", "dlms.hdlc.frame", FT_UINT8, BASE_DEC, dlms_hdlc_frame_names, 0x01, 0, HFILL },
{ "Frame", "dlms.hdlc.frame", FT_UINT8, BASE_DEC, dlms_hdlc_frame_names, 0x0f, 0, HFILL },
{ "Frame", "dlms.hdlc.frame", FT_UINT8, BASE_DEC, dlms_hdlc_frame_names, 0xef, 0, HFILL },
{ "Poll/Final", "dlms.hdlc.pf", FT_UINT8, BASE_DEC, 0, 0x10, 0, HFILL },
{ "Receive Sequence Number", "dlms.hdlc.rsn", FT_UINT8, BASE_DEC, 0, 0xe0, 0, HFILL },
{ "Send Sequence Number", "dlms.hdlc.ssn", FT_UINT8, BASE_DEC, 0, 0x0e, 0, HFILL },
{ "Header Check Sequence", "dlms.hdlc.hcs", FT_NONE, BASE_NONE, 0, 0, 0, HFILL },
{ "Frame Check Sequence", "dlms.hdlc.fcs", FT_NONE, BASE_NONE, 0, 0, 0, HFILL },
{ "Parameter", "dlms.hdlc.parameter", FT_NONE, BASE_NONE, 0, 0, 0, HFILL },
{ "LLC Header", "dlms.hdlc.llc", FT_NONE, BASE_NONE, 0, 0, 0, HFILL },
/* IEC 4-32 LLC */
{ "IEC 4-32 LLC Header", "dlms.iec432llc", FT_NONE, BASE_NONE, 0, 0, 0, HFILL },
/* Wrapper Protocol Data Unit (WPDU) */
{ "Wrapper Header", "dlms.wrapper", FT_NONE, BASE_NONE, 0, 0, 0, HFILL },
/* APDU */
{ "APDU", "dlms.apdu", FT_UINT8, BASE_DEC, dlms_apdu_names, 0, 0, HFILL },
{ "Client Max Receive PDU Size", "dlms.client_max_receive_pdu_size", FT_UINT16, BASE_DEC, 0, 0, 0, HFILL },
{ "Server Max Receive PDU Size", "dlms.server_max_receive_pdu_size", FT_UINT16, BASE_DEC, 0, 0, 0, HFILL },
{ "Get Request", "dlms.get_request", FT_UINT8, BASE_DEC, dlms_get_request_names, 0, 0, HFILL },
{ "Set Request", "dlms.set_request", FT_UINT8, BASE_DEC, dlms_set_request_names, 0, 0, HFILL },
{ "Action Request", "dlms.action_request", FT_UINT8, BASE_DEC, dlms_action_request_names, 0, 0, HFILL },
{ "Get Response", "dlms.get_response", FT_UINT8, BASE_DEC, dlms_get_response_names, 0, 0, HFILL },
{ "Set Response", "dlms.set_response", FT_UINT8, BASE_DEC, dlms_set_response_names, 0, 0, HFILL },
{ "Action Response", "dlms.action_response", FT_UINT8, BASE_DEC, dlms_action_response_names, 0, 0, HFILL },
{ "Access Request", "dlms.action_request", FT_UINT8, BASE_DEC, dlms_access_request_names, 0, 0, HFILL },
{ "Access Response", "dlms.action_response", FT_UINT8, BASE_DEC, dlms_access_response_names, 0, 0, HFILL },
{ "Class Id", "dlms.class_id", FT_NONE, BASE_NONE, 0, 0, 0, HFILL },
{ "Instance Id", "dlms.instance_id", FT_NONE, BASE_NONE, 0, 0, 0, HFILL },
{ "Attribute Id", "dlms.attribute_id", FT_NONE, BASE_NONE, 0, 0, 0, HFILL },
{ "Method Id", "dlms.method_id", FT_UINT8, BASE_DEC, 0, 0, 0, HFILL },
{ "Access Selector", "dlms.access_selector", FT_UINT8, BASE_DEC, 0, 0, 0, HFILL },
{ "Data Access Result", "dlms.data_access_result", FT_UINT8, BASE_DEC, dlms_data_access_result_names, 0, 0, HFILL },
{ "Action Result", "dlms.action_result", FT_UINT8, BASE_DEC, dlms_action_result_names, 0, 0, HFILL },
{ "Block Number", "dlms.block_number", FT_UINT32, BASE_DEC, 0, 0, 0, HFILL },
{ "Last Block", "dlms.last_block", FT_BOOLEAN, BASE_DEC, 0, 0, 0, HFILL },
{ "Type Description", "dlms.type_description", FT_NONE, BASE_NONE, 0, 0, 0, HFILL },
{ "Data", "dlms.data", FT_NONE, BASE_NONE, 0, 0, 0, HFILL },
{ "Date-Time", "dlms.date_time", FT_NONE, BASE_NONE, 0, 0, 0, HFILL },
{ "Length", "dlms.length", FT_NONE, BASE_NONE, 0, 0, 0, HFILL },
{ "State Error", "dlms.state_error", FT_UINT8, BASE_DEC, dlms_state_error_names, 0, 0, HFILL },
{ "Service Error", "dlms.service_error", FT_UINT8, BASE_DEC, dlms_service_error_names, 0, 0, HFILL },
/* Invoke-Id-And-Priority */
{ "Invoke Id", "dlms.invoke_id", FT_UINT8, BASE_DEC, 0, 0x0f, 0, HFILL },
{ "Service Class", "dlms.service_class", FT_UINT8, BASE_DEC, dlms_service_class_names, 0x40, 0, HFILL },
{ "Priority", "dlms.priority", FT_UINT8, BASE_DEC, dlms_priority_names, 0x80, 0, HFILL },
/* Long-Invoke-Id-And-Priority */
{ "Long Invoke Id", "dlms.long_invoke_id", FT_UINT32, BASE_DEC, 0, 0xffffff, 0, HFILL },
{ "Self Descriptive", "dlms.self_descriptive", FT_UINT32, BASE_DEC, dlms_self_descriptive_names, 0x10000000, 0, HFILL },
{ "Processing Option", "dlms.processing_option", FT_UINT32, BASE_DEC, dlms_processing_option_names, 0x20000000, 0, HFILL },
{ "Service Class", "dlms.service_class", FT_UINT32, BASE_DEC, dlms_service_class_names, 0x40000000, 0, HFILL },
{ "Priority", "dlms.priority", FT_UINT32, BASE_DEC, dlms_priority_names, 0x80000000, 0, HFILL },
/* proposed-conformance and negotiated-conformance bits */
{ "general-protection", "dlms.conformance.general_protection", FT_UINT24, BASE_DEC, 0, 0x400000, 0, HFILL },
{ "general-block-transfer", "dlms.conformance.general_block_transfer", FT_UINT24, BASE_DEC, 0, 0x200000, 0, HFILL },
{ "read", "dlms.conformance.read", FT_UINT24, BASE_DEC, 0, 0x100000, 0, HFILL },
{ "write", "dlms.conformance.write", FT_UINT24, BASE_DEC, 0, 0x080000, 0, HFILL },
{ "unconfirmed-write", "dlms.conformance.unconfirmed_write", FT_UINT24, BASE_DEC, 0, 0x040000, 0, HFILL },
{ "attribute0-supported-with-set", "dlms.conformance.attribute0_supported_with_set", FT_UINT24, BASE_DEC, 0, 0x008000, 0, HFILL },
{ "priority-mgmt-supported", "dlms.conformance.priority_mgmt_supported", FT_UINT24, BASE_DEC, 0, 0x004000, 0, HFILL },
{ "attribute0-supported-with-get", "dlms.conformance.attribute0_supported_with_get", FT_UINT24, BASE_DEC, 0, 0x002000, 0, HFILL },
{ "block-transfer-with-get-or-read", "dlms.conformance.block_transfer_with_get_or_read", FT_UINT24, BASE_DEC, 0, 0x001000, 0, HFILL },
{ "block-transfer-with-set-or-write", "dlms.conformance.block_transfer_with_set_or_write", FT_UINT24, BASE_DEC, 0, 0x000800, 0, HFILL },
{ "block-transfer-with-action", "dlms.conformance.block_transfer_with_action", FT_UINT24, BASE_DEC, 0, 0x000400, 0, HFILL },
{ "multiple-references", "dlms.conformance.multiple_references", FT_UINT24, BASE_DEC, 0, 0x000200, 0, HFILL },
{ "information-report", "dlms.conformance.information_report", FT_UINT24, BASE_DEC, 0, 0x000100, 0, HFILL },
{ "data-notification", "dlms.conformance.data_notification", FT_UINT24, BASE_DEC, 0, 0x000080, 0, HFILL },
{ "access", "dlms.conformance.access", FT_UINT24, BASE_DEC, 0, 0x000040, 0, HFILL },
{ "parameterized-access", "dlms.conformance.parameterized_access", FT_UINT24, BASE_DEC, 0, 0x000020, 0, HFILL },
{ "get", "dlms.conformance.get", FT_UINT24, BASE_DEC, 0, 0x000010, 0, HFILL },
{ "set", "dlms.conformance.set", FT_UINT24, BASE_DEC, 0, 0x000008, 0, HFILL },
{ "selective-access", "dlms.conformance.selective_access", FT_UINT24, BASE_DEC, 0, 0x000004, 0, HFILL },
{ "event-notification", "dlms.conformance.event_notification", FT_UINT24, BASE_DEC, 0, 0x000002, 0, HFILL },
{ "action", "dlms.conformance.action", FT_UINT24, BASE_DEC, 0, 0x000001, 0, HFILL },
/* fragment_items */
{ "Fragments", "dlms.fragments", FT_NONE, BASE_NONE, 0, 0, 0, HFILL },
{ "Fragment", "dlms.fragment", FT_FRAMENUM, BASE_NONE, 0, 0, 0, HFILL },
{ "Fragment Overlap", "dlms.fragment.overlap", FT_BOOLEAN, 0, 0, 0, 0, HFILL },
{ "Fragment Conflict", "dlms.fragment.conflict", FT_BOOLEAN, 0, 0, 0, 0, HFILL },
{ "Fragment Multiple", "dlms.fragment.multiple", FT_BOOLEAN, 0, 0, 0, 0, HFILL },
{ "Fragment Too Long", "dlms.fragment.too_long", FT_BOOLEAN, 0, 0, 0, 0, HFILL },
{ "Fragment Error", "dlms.fragment.error", FT_FRAMENUM, BASE_NONE, 0, 0, 0, HFILL },
{ "Fragment Count", "dlms.fragment.count", FT_UINT32, BASE_DEC, 0, 0, 0, HFILL },
{ "Reassembled In", "dlms.reassembled_in", FT_FRAMENUM, BASE_NONE, 0, 0, 0, HFILL },
{ "Reassembled Length", "dlms.reassembled_length", FT_UINT32, BASE_DEC, 0, 0, 0, HFILL },
{ "Reassembled Data", "dlms.reassembled_data", FT_BYTES, SEP_SPACE, 0, 0, 0, HFILL },
};
/* Protocol subtree (ett) indices */
static struct {
gint dlms;
gint hdlc;
gint hdlc_format;
gint hdlc_address;
gint hdlc_control;
gint hdlc_information;
gint invoke_id_and_priority;
gint access_request_specification;
gint access_request;
gint access_response_specification;
gint access_response;
gint cosem_attribute_or_method_descriptor;
gint selective_access_descriptor;
gint composite_data;
gint user_information; /* AARQ and AARE user-information field */
gint conformance; /* InitiateRequest proposed-conformance and InitiateResponse negotiated-confirmance */
gint datablock;
gint data;
/* fragment_items */
gint fragment;
gint fragments;
} dlms_ett;
/* Expert information (ei) fields */
static struct {
expert_field no_success;
expert_field not_implemented;
expert_field check_sequence; /* bad HDLC check sequence (HCS or FCS) value */
} dlms_ei;
/*
* The reassembly table is used for reassembling both
* HDLC I frame segments and DLMS APDU datablocks.
* The reassembly id is used as hash key to distinguish between the two.
*/
static reassembly_table dlms_reassembly_table;
enum {
/* Do not use 0 as id because that would return a NULL key */
DLMS_REASSEMBLY_ID_HDLC = 1,
DLMS_REASSEMBLY_ID_DATABLOCK,
};
static guint
dlms_reassembly_hash_func(gconstpointer key)
{
return (gsize)key;
}
static gint
dlms_reassembly_equal_func(gconstpointer key1, gconstpointer key2)
{
return key1 == key2;
}
static gpointer
dlms_reassembly_key_func(const packet_info *pinfo, guint32 id, const void *data)
{
return (gpointer)(gsize)id;
}
static void
dlms_reassembly_free_key_func(gpointer ptr)
{
}
static const fragment_items dlms_fragment_items = {
&dlms_ett.fragment,
&dlms_ett.fragments,
&dlms_hfi.fragments.id,
&dlms_hfi.fragment.id,
&dlms_hfi.fragment_overlap.id,
&dlms_hfi.fragment_overlap_conflict.id,
&dlms_hfi.fragment_multiple_tails.id,
&dlms_hfi.fragment_too_long_fragment.id,
&dlms_hfi.fragment_error.id,
&dlms_hfi.fragment_count.id,
&dlms_hfi.reassembled_in.id,
&dlms_hfi.reassembled_length.id,
&dlms_hfi.reassembled_data.id,
"Fragments"
};
static void
dlms_dissect_invoke_id_and_priority(proto_tree *tree, tvbuff_t *tvb, gint *offset)
{
proto_tree *subtree;
subtree = proto_tree_add_subtree(tree, tvb, *offset, 1, dlms_ett.invoke_id_and_priority, 0, "Invoke Id And Priority");
proto_tree_add_item(subtree, &dlms_hfi.invoke_id, tvb, *offset, 1, ENC_NA);
proto_tree_add_item(subtree, &dlms_hfi.service_class, tvb, *offset, 1, ENC_NA);
proto_tree_add_item(subtree, &dlms_hfi.priority, tvb, *offset, 1, ENC_NA);
*offset += 1;
}
static void
dlms_dissect_long_invoke_id_and_priority(proto_tree *tree, tvbuff_t *tvb, gint *offset)
{
proto_tree *subtree;
subtree = proto_tree_add_subtree(tree, tvb, *offset, 4, dlms_ett.invoke_id_and_priority, 0, "Long Invoke Id And Priority");
proto_tree_add_item(subtree, &dlms_hfi.long_invoke_id, tvb, *offset, 4, ENC_BIG_ENDIAN);
proto_tree_add_item(subtree, &dlms_hfi.long_self_descriptive, tvb, *offset, 4, ENC_BIG_ENDIAN);
proto_tree_add_item(subtree, &dlms_hfi.long_processing_option, tvb, *offset, 4, ENC_BIG_ENDIAN);
proto_tree_add_item(subtree, &dlms_hfi.long_service_class, tvb, *offset, 4, ENC_BIG_ENDIAN);
proto_tree_add_item(subtree, &dlms_hfi.long_priority, tvb, *offset, 4, ENC_BIG_ENDIAN);
*offset += 4;
}
static void
dlms_dissect_cosem_attribute_or_method_descriptor(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint *offset, int is_attribute)
{
unsigned class_id, attribute_method_id;
const dlms_cosem_class *cosem_class;
const char *attribute_method_name;
const gchar *instance_name;
proto_tree *subtree;
proto_item *item;
class_id = tvb_get_ntohs(tvb, *offset);
attribute_method_id = tvb_get_guint8(tvb, *offset + 8);
cosem_class = dlms_get_class(class_id);
if (cosem_class) {
col_append_fstr(pinfo->cinfo, COL_INFO, " %s", cosem_class->name);
if (is_attribute) {
attribute_method_name = dlms_get_attribute_name(cosem_class, attribute_method_id);
} else {
attribute_method_name = dlms_get_method_name(cosem_class, attribute_method_id);
}
} else {
col_append_fstr(pinfo->cinfo, COL_INFO, " %u", class_id);
attribute_method_name = 0;
}
if (attribute_method_name) {
col_append_fstr(pinfo->cinfo, COL_INFO, ".%s", attribute_method_name);
} else {
col_append_fstr(pinfo->cinfo, COL_INFO, ".%u", attribute_method_id);
}
instance_name = try_val64_to_str(tvb_get_ntoh48(tvb, *offset + 2), obis_code_names);
if (instance_name) {
col_append_fstr(pinfo->cinfo, COL_INFO, " %s", instance_name);
}
else {