Coverage Report

Created: 2025-12-27 06:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wireshark/epan/dissectors/packet-docsis.c
Line
Count
Source
1
/* packet-docsis.c
2
 * Routines for docsis dissection
3
 * Copyright 2002, Anand V. Narwani <anand[AT]narwani.org>
4
 *
5
 * Wireshark - Network traffic analyzer
6
 * By Gerald Combs <gerald@wireshark.org>
7
 * Copyright 1998 Gerald Combs
8
 *
9
 * SPDX-License-Identifier: GPL-2.0-or-later
10
 */
11
12
13
/* This code is based on the DOCSIS 1.1 specification available at:
14
 * https://www.cablelabs.com/specifications/radio-frequency-interface-specification
15
 *
16
 * This code was updated to include DOCSIS 3.1 specification details available at:
17
 * https://www.cablelabs.com/specifications/CM-SP-MULPIv3.1
18
 *
19
 * Updates are backward compatible with previous DOCSIS specifications.
20
 *
21
 * DOCSIS Captures can be facilitated using the Cable Monitor Feature
22
 * available on Cisco Cable Modem Termination Systems:
23
 * https://www.cisco.com/c/en/us/td/docs/cable/cmts/config_guide/b_cmts_security_and_cable_monitoring_features/b_cmts_security_and_cable_monitoring_features_chapter_010.html
24
 *
25
 * This dissector depends on the presence of a DOCSIS encapsulation type.
26
 * There is no simple way to distinguish DOCSIS Frames from Ethernet frames,
27
 * since the frames are copied from the RF interface on the CMTS to
28
 * a Fast Ethernet interface; thus a preference was needed to enable
29
 * the DOCSIS encapsulation type.
30
 *
31
 * Libpcap 0.7 and later allow a link-layer header type to be specified for
32
 * some interfaces on some platforms; for Ethernet interfaces, they allow
33
 * DOCSIS to be specified.  If an Ethernet capture is done with a link-layer
34
 * type of DOCSIS, the file will have a link-layer header type of DLT_DOCSIS;
35
 * Wireshark will treat the frames in that capture as DOCSIS frames, even
36
 * if the preference mentioned above isn't enabled.
37
 */
38
39
#include "config.h"
40
41
#include <epan/etypes.h>
42
#include <epan/expert.h>
43
#include <epan/packet.h>
44
#include <epan/prefs.h>
45
#include <epan/reassemble.h>
46
#include <epan/addr_resolv.h>
47
#include <epan/exceptions.h>
48
#include <epan/tfs.h>
49
#include <epan/crc16-tvb.h>
50
#include <epan/crc32-tvb.h>
51
52
void proto_register_docsis(void);
53
void proto_reg_handoff_docsis(void);
54
55
/* Assume all packets have an FCS */
56
static bool docsis_check_fcs = true;
57
static bool docsis_dissect_encrypted_frames;
58
59
906
#define DOCSIS_MIN_HEADER_LEN   6
60
61
1.54k
#define FCTYPE_PACKET   0x00
62
68
#define FCTYPE_SPECIAL  0x01
63
80
#define FCTYPE_ISOLAT   0x02
64
955
#define FCTYPE_MACSPC   0x03
65
66
0
#define FCPARM_TIMING_HDR           0x00
67
3
#define FCPARM_MAC_MGMT_HDR         0x01
68
99
#define FCPARM_RQST_FRM             0x02
69
42
#define FCPARM_FRAG_HDR             0x03
70
956
#define FCPARM_QUEUE_DEPTH_REQ_FRM  0x04
71
2
#define FCPARM_CONCAT_HDR           0x1C
72
73
0
#define EXT_HDR_OFF     0x00
74
1.74k
#define EXT_HDR_ON      0x01
75
76
#define FRAG_FCS_LEN    4
77
#define FRAG_FIRST      0x20
78
#define FRAG_MIDDLE     0x00
79
0
#define FRAG_LAST       0x10
80
81
#define EH_NULL_CONFIG      0
82
54
#define EH_REQUEST          1
83
51
#define EH_ACK_REQ          2
84
200
#define EH_BP_UP            3
85
192
#define EH_BP_DOWN          4
86
81
#define EH_SFLOW_HDR_DOWN   5
87
299
#define EH_SFLOW_HDR_UP     6
88
35
#define EH_BP_UP2           7
89
73
#define EH_DS_SERVICE       8
90
76
#define EH_PATH_VERIFY      9
91
#define EH_RESERVED_10      10
92
#define EH_RESERVED_11      11
93
#define EH_RESERVED_12      12
94
#define EH_RESERVED_13      13
95
#define EH_RESERVED_14      14
96
37
#define EH_EXTENDED         15
97
98
/* Initialize the protocol and registered fields */
99
static int proto_docsis;
100
static int hf_docsis_fctype;
101
static int hf_docsis_machdr_fcparm;
102
static int hf_docsis_fcparm;
103
static int hf_docsis_exthdr;
104
static int hf_docsis_concat_cnt;
105
static int hf_docsis_macparm;
106
static int hf_docsis_ehdrlen;
107
static int hf_docsis_len;
108
static int hf_docsis_eh_type;
109
static int hf_docsis_eh_len;
110
static int hf_docsis_eh_val;
111
static int hf_docsis_ehx_type;
112
static int hf_docsis_ehx_len;
113
static int hf_docsis_frag_rsvd;
114
static int hf_docsis_frag_first;
115
static int hf_docsis_frag_last;
116
static int hf_docsis_frag_seq;
117
static int hf_docsis_sid;
118
static int hf_docsis_mini_slots;
119
static int hf_docsis_requested_size;
120
static int hf_docsis_hcs;
121
static int hf_docsis_hcs_status;
122
static int hf_docsis_bpi_en;
123
static int hf_docsis_toggle_bit;
124
static int hf_docsis_key_seq;
125
static int hf_docsis_ehdr_ver;
126
static int hf_docsis_said;
127
static int hf_docsis_ehdr_phsi;
128
static int hf_docsis_ehdr_qind;
129
static int hf_docsis_ehdr_grants;
130
static int hf_docsis_reserved;
131
static int hf_docsis_ehdr_ds_traffic_pri;
132
static int hf_docsis_ehdr_ds_seq_chg_cnt;
133
static int hf_docsis_ehdr_ds_dsid;
134
static int hf_docsis_ehdr_ds_pkt_seq_num;
135
static int hf_docsis_ehdr_bpup2_bpi_en;
136
static int hf_docsis_ehdr_bpup2_toggle_bit;
137
static int hf_docsis_ehdr_bpup2_key_seq;
138
static int hf_docsis_ehdr_bpup2_ver;
139
static int hf_docsis_ehdr_bpup2_sid;
140
static int hf_docsis_ehdr_pv_st_refpt;
141
static int hf_docsis_ehdr_pv_timestamp;
142
143
static int hf_docsis_fragments;
144
static int hf_docsis_fragment;
145
static int hf_docsis_fragment_overlap;
146
static int hf_docsis_fragment_overlap_conflict;
147
static int hf_docsis_fragment_multiple_tails;
148
static int hf_docsis_fragment_too_long_fragment;
149
static int hf_docsis_fragment_error;
150
static int hf_docsis_fragment_count;
151
static int hf_docsis_reassembled_in;
152
static int hf_docsis_reassembled_length;
153
static int hf_docsis_reassembled_data;
154
static int hf_docsis_frag_fcs;
155
static int hf_docsis_frag_fcs_status;
156
157
static int hf_docsis_dst;
158
static int hf_docsis_dst_resolved;
159
static int hf_docsis_src;
160
static int hf_docsis_src_resolved;
161
static int hf_docsis_lg;
162
static int hf_docsis_ig;
163
static int hf_docsis_encrypted_payload;
164
165
static dissector_handle_t docsis_handle;
166
static dissector_handle_t eth_maybefcs_handle;
167
static dissector_handle_t docsis_mgmt_handle;
168
#if 0
169
static dissector_table_t docsis_dissector_table;
170
#endif
171
172
static expert_field ei_docsis_hcs_bad;
173
static expert_field ei_docsis_len;
174
static expert_field ei_docsis_len_small;
175
static expert_field ei_docsis_frag_fcs_bad;
176
static expert_field ei_docsis_eh_len;
177
178
/* Initialize the subtree pointers */
179
static int ett_docsis;
180
static int ett_ehdr;
181
static int ett_docsis_fragments;
182
static int ett_docsis_fragment;
183
static int ett_addr;
184
185
static const value_string fctype_vals[] = {
186
  {FCTYPE_PACKET,   "Packet PDU"},
187
  {FCTYPE_SPECIAL,  "Special Use"},
188
  {FCTYPE_ISOLAT,   "Isolation PDU"},
189
  {FCTYPE_MACSPC,   "MAC Specific"},
190
  {0, NULL}
191
};
192
193
static const value_string eh_type_vals[] = {
194
  {0,                 "NULL Configuration Parameter"},
195
  {EH_REQUEST,        "Request"},
196
  {EH_ACK_REQ,        "Acknowledgement Requested"},
197
  {EH_BP_UP,          "Upstream Privacy Element"},
198
  {EH_BP_DOWN,        "Downstream  Privacy Element"},
199
  {EH_SFLOW_HDR_UP,   "Service Flow EH; PHS Header Upstream"},
200
  {EH_SFLOW_HDR_DOWN, "Service Flow EH; PHS Header Downstream"},
201
  {EH_BP_UP2,         "Upstream Privacy with Multi Channel"},
202
  {EH_DS_SERVICE,     "Downstream Service"},
203
  {EH_PATH_VERIFY,    "Path Verify"},
204
  {EH_RESERVED_10,    "Reserved"},
205
  {EH_RESERVED_11,    "Reserved"},
206
  {EH_RESERVED_12,    "Reserved"},
207
  {EH_RESERVED_13,    "Reserved"},
208
  {EH_RESERVED_14,    "Reserved"},
209
  {EH_EXTENDED,       "Extended"},
210
  {0, NULL}
211
};
212
213
static const value_string ms_fcparm_vals[] = {
214
  {FCPARM_TIMING_HDR,           "Timing Header"},
215
  {FCPARM_MAC_MGMT_HDR,         "MAC Management Message"},
216
  {FCPARM_RQST_FRM,             "Request Frame"},
217
  {FCPARM_FRAG_HDR,             "Fragmentation Header"},
218
  {FCPARM_QUEUE_DEPTH_REQ_FRM,  "Queue Depth-based Request Frame"},
219
  {FCPARM_CONCAT_HDR,           "Concatenation Header"},
220
  {0, NULL}
221
};
222
223
static const value_string pkt_fcparm_vals[] = {
224
  {0x00,           "PDU MAC"},
225
  {0x01,           "DELAY/DUPLICATE/MULTICAST/BROADCAST"},
226
  {0, NULL}
227
};
228
229
static const true_false_string exthdr_tfs = {
230
  "Extended Header Present",
231
  "Extended Header Absent"
232
};
233
234
static const true_false_string qind_tfs = {
235
  "Rate overrun",
236
  "Rate non-overrun"
237
};
238
239
static const true_false_string odd_even_tfs = {
240
  "Odd Key",
241
  "Even Key",
242
};
243
244
static const value_string unique_no_phs[] = {
245
  { 0, "No PHS on current packet" },
246
  { 0, NULL }
247
};
248
249
/* Fragmentation Flags / Sequence */
250
static uint8_t frag_flags;
251
static uint8_t frag_seq;
252
static uint16_t frag_sid;
253
254
/*
255
 * Defragmentation of DOCSIS
256
 */
257
static reassembly_table docsis_reassembly_table;
258
259
260
static const fragment_items docsis_frag_items = {
261
  &ett_docsis_fragment,
262
  &ett_docsis_fragments,
263
  &hf_docsis_fragments,
264
  &hf_docsis_fragment,
265
  &hf_docsis_fragment_overlap,
266
  &hf_docsis_fragment_overlap_conflict,
267
  &hf_docsis_fragment_multiple_tails,
268
  &hf_docsis_fragment_too_long_fragment,
269
  &hf_docsis_fragment_error,
270
  &hf_docsis_fragment_count,
271
  &hf_docsis_reassembled_in,
272
  &hf_docsis_reassembled_length,
273
  &hf_docsis_reassembled_data,
274
  "DOCSIS fragments"
275
};
276
277
/* Dissection */
278
/* Code to Dissect the extended header; TLV Formatted headers */
279
static void
280
dissect_ehdr (tvbuff_t * tvb, proto_tree * tree, packet_info * pinfo, bool *is_encrypted)
281
121
{
282
121
  proto_tree *ehdr_tree;
283
121
  proto_item *eh_length_item;
284
121
  int ehdrlen;
285
121
  int pos;
286
121
  uint8_t type;
287
121
  uint8_t len;
288
289
121
  ehdrlen = tvb_get_uint8 (tvb, 1);
290
121
  pos = 4;
291
292
121
  ehdr_tree = proto_tree_add_subtree(tree, tvb, pos, ehdrlen, ett_ehdr, NULL, "Extended Header");
293
294
1.95k
  while (pos < ehdrlen + 4)
295
1.90k
  {
296
1.90k
    type = (tvb_get_uint8 (tvb, pos) & 0xF0);
297
1.90k
    len = (tvb_get_uint8 (tvb, pos) & 0x0F);
298
1.90k
    if ((((type >> 4) & 0x0F)== 6) && (len == 2))
299
43
    {
300
43
      proto_tree_add_uint_format_value(ehdr_tree, hf_docsis_eh_type, tvb, pos, 1, 0x60, "Unsolicited Grant Sync EHDR Sub-Element");
301
43
    }
302
1.86k
    else
303
1.86k
    {
304
1.86k
      proto_tree_add_item (ehdr_tree, hf_docsis_eh_type, tvb, pos, 1, ENC_BIG_ENDIAN);
305
1.86k
    }
306
307
1.90k
    eh_length_item = proto_tree_add_item (ehdr_tree, hf_docsis_eh_len, tvb, pos, 1, ENC_BIG_ENDIAN);
308
1.90k
    pos++;
309
310
1.90k
    switch ((type >> 4) & 0x0F)
311
1.90k
    {
312
54
      case EH_REQUEST:
313
        /* Request: Minislots Requested */
314
54
        if (len == 3)
315
47
        {
316
47
          proto_tree_add_item(ehdr_tree, hf_docsis_mini_slots, tvb, pos, 1, ENC_NA);
317
47
          proto_tree_add_item(ehdr_tree, hf_docsis_sid, tvb, pos + 1, 2, ENC_BIG_ENDIAN);
318
47
        }
319
7
        else
320
7
        {
321
7
          expert_add_info(pinfo, eh_length_item, &ei_docsis_eh_len);
322
7
          return;
323
7
        }
324
47
        break;
325
51
      case EH_ACK_REQ:
326
        /* Deprecated in DOCSIS 3.1 */
327
51
        if (len == 2)
328
29
        {
329
29
          proto_tree_add_item(ehdr_tree, hf_docsis_sid, tvb, pos, 2, ENC_BIG_ENDIAN);
330
29
        }
331
22
        else
332
22
        {
333
22
          expert_add_info(pinfo, eh_length_item, &ei_docsis_eh_len);
334
22
          return;
335
22
        }
336
29
        break;
337
200
      case EH_BP_UP:
338
        /* Upstream Privacy EH Element or Upstream Privacy with fragmentation */
339
200
        proto_tree_add_item (ehdr_tree, hf_docsis_key_seq, tvb, pos, 1,
340
200
                             ENC_BIG_ENDIAN);
341
200
        proto_tree_add_item (ehdr_tree, hf_docsis_ehdr_ver, tvb, pos, 1,
342
200
                             ENC_BIG_ENDIAN);
343
200
        proto_tree_add_item_ret_boolean (ehdr_tree, hf_docsis_bpi_en, tvb, pos + 1, 1,
344
200
                             ENC_BIG_ENDIAN, is_encrypted);
345
200
        proto_tree_add_item (ehdr_tree, hf_docsis_toggle_bit, tvb, pos + 1,
346
200
                             1, ENC_BIG_ENDIAN);
347
200
        proto_tree_add_item (ehdr_tree, hf_docsis_sid, tvb, pos + 1, 2,
348
200
                             ENC_BIG_ENDIAN);
349
200
        frag_sid = tvb_get_uint8 (tvb, pos+1) & 0xCFFF;
350
200
        proto_tree_add_item (ehdr_tree, hf_docsis_mini_slots, tvb, pos + 3,
351
200
                             1, ENC_BIG_ENDIAN);
352
200
        if (pinfo->fragmented)
353
8
        {
354
8
          proto_tree_add_item (ehdr_tree, hf_docsis_frag_rsvd, tvb, pos+4,
355
8
                               1, ENC_BIG_ENDIAN);
356
8
          frag_flags = tvb_get_uint8 (tvb, pos+4) & 0x30;
357
8
          proto_tree_add_item (ehdr_tree, hf_docsis_frag_first, tvb, pos+4,
358
8
                               1, ENC_BIG_ENDIAN);
359
8
          proto_tree_add_item (ehdr_tree, hf_docsis_frag_last, tvb, pos+4,
360
8
                               1, ENC_BIG_ENDIAN);
361
8
          frag_seq = tvb_get_uint8 (tvb, pos+4) & 0x0F;
362
8
          proto_tree_add_item (ehdr_tree, hf_docsis_frag_seq, tvb, pos+4,
363
8
                               1, ENC_BIG_ENDIAN);
364
8
        }
365
200
        break;
366
192
      case EH_BP_DOWN:
367
        /* Downstream Privacy EH Element */
368
192
        proto_tree_add_item (ehdr_tree, hf_docsis_key_seq, tvb, pos, 1,
369
192
                             ENC_BIG_ENDIAN);
370
192
        proto_tree_add_item (ehdr_tree, hf_docsis_ehdr_ver, tvb, pos, 1,
371
192
                             ENC_BIG_ENDIAN);
372
192
        proto_tree_add_item_ret_boolean (ehdr_tree, hf_docsis_bpi_en, tvb, pos + 1, 1,
373
192
                             ENC_BIG_ENDIAN, is_encrypted);
374
192
        proto_tree_add_item (ehdr_tree, hf_docsis_toggle_bit, tvb, pos + 1,
375
192
                             1, ENC_BIG_ENDIAN);
376
192
        proto_tree_add_item (ehdr_tree, hf_docsis_said, tvb, pos + 1, 2,
377
192
                             ENC_BIG_ENDIAN);
378
192
        proto_tree_add_item (ehdr_tree, hf_docsis_reserved, tvb, pos + 3, 1,
379
192
                             ENC_BIG_ENDIAN);
380
192
        break;
381
81
      case EH_SFLOW_HDR_DOWN:
382
        /* Deprecated in DOCSIS 3.1, was Downstream Service Flow EH Element in earlier revisions */
383
299
      case EH_SFLOW_HDR_UP:
384
        /* Deprecated in DOCSIS 3.1, was Upstream Service Flow EH Element in earlier revisions */
385
299
        proto_tree_add_item(ehdr_tree, hf_docsis_ehdr_phsi, tvb, pos, 1, ENC_BIG_ENDIAN);
386
387
299
        if (len == 2)
388
53
        {
389
53
          proto_tree_add_item (ehdr_tree, hf_docsis_ehdr_qind, tvb, pos+1, 1, ENC_BIG_ENDIAN);
390
53
          proto_tree_add_item (ehdr_tree, hf_docsis_ehdr_grants, tvb, pos+1, 1, ENC_BIG_ENDIAN);
391
53
        }
392
299
        break;
393
35
      case EH_BP_UP2:
394
        /* Upstream Privacy EH Element, version 2, with no piggyback request */
395
35
        proto_tree_add_item (ehdr_tree, hf_docsis_ehdr_bpup2_key_seq, tvb, pos, 1,
396
35
                             ENC_BIG_ENDIAN);
397
35
        proto_tree_add_item (ehdr_tree, hf_docsis_ehdr_bpup2_ver, tvb, pos, 1,
398
35
                             ENC_BIG_ENDIAN);
399
35
        proto_tree_add_item_ret_boolean (ehdr_tree, hf_docsis_ehdr_bpup2_bpi_en, tvb, pos + 1, 1,
400
35
                             ENC_BIG_ENDIAN, is_encrypted);
401
35
        proto_tree_add_item (ehdr_tree, hf_docsis_ehdr_bpup2_toggle_bit, tvb, pos + 1,
402
35
                             1, ENC_BIG_ENDIAN);
403
35
        proto_tree_add_item (ehdr_tree, hf_docsis_ehdr_bpup2_sid, tvb, pos + 1, 2,
404
35
                             ENC_BIG_ENDIAN);
405
35
        break;
406
73
      case EH_DS_SERVICE:
407
        /* Downstream Service EH Element */
408
73
        proto_tree_add_item(ehdr_tree, hf_docsis_ehdr_ds_traffic_pri, tvb, pos, 1, ENC_BIG_ENDIAN);
409
410
73
        if (len == 3)
411
16
        {
412
16
          proto_tree_add_item (ehdr_tree, hf_docsis_ehdr_ds_dsid, tvb, pos, 3, ENC_BIG_ENDIAN);
413
16
        }
414
415
73
        if (len == 5)
416
3
        {
417
3
          proto_tree_add_item (ehdr_tree, hf_docsis_ehdr_ds_seq_chg_cnt, tvb, pos, 1, ENC_BIG_ENDIAN);
418
3
          proto_tree_add_item (ehdr_tree, hf_docsis_ehdr_ds_dsid, tvb, pos, 3, ENC_BIG_ENDIAN);
419
3
          proto_tree_add_item (ehdr_tree, hf_docsis_ehdr_ds_pkt_seq_num, tvb, pos+3, 2, ENC_BIG_ENDIAN);
420
3
        }
421
73
        break;
422
76
      case EH_PATH_VERIFY:
423
        /* Path Verify EH Element */
424
76
        if (len == 5)
425
23
        {
426
23
          proto_tree_add_item (ehdr_tree, hf_docsis_ehdr_pv_st_refpt, tvb, pos, 1, ENC_BIG_ENDIAN);
427
23
          proto_tree_add_item (ehdr_tree, hf_docsis_ehdr_pv_timestamp, tvb, pos+1, 4, ENC_BIG_ENDIAN);
428
23
        }
429
76
        break;
430
37
      case EH_EXTENDED:
431
        /* Extended EH Element, ignore eh_len */
432
37
        proto_tree_add_item(ehdr_tree, hf_docsis_ehx_type, tvb, pos, 1, ENC_NA);
433
37
        pos++;
434
37
        proto_tree_add_item(ehdr_tree, hf_docsis_ehx_len, tvb, pos, 1, ENC_NA);
435
37
        len = tvb_get_uint8(tvb, pos);
436
37
        pos++;
437
        /* FALLTHROUGH */
438
910
      default:
439
910
        if (len > 0)
440
292
          proto_tree_add_item (ehdr_tree, hf_docsis_eh_val, tvb, pos,
441
292
                               len, ENC_NA);
442
1.90k
    }
443
1.83k
    pos += len;
444
1.83k
  }
445
446
48
  return;
447
121
}
448
449
/* Code to Dissect the Header Check Sequence field */
450
/* Return false in case FCS validation is enabled, but FCS is incorrect */
451
/* Return true in all other cases */
452
static bool
453
dissect_hcs_field (tvbuff_t * tvb, packet_info * pinfo, proto_tree * docsis_tree, int hdrlen)
454
816
{
455
  /* dissect the header check sequence */
456
816
  if(docsis_check_fcs){
457
    /* CRC-CCITT(16+12+5+1) */
458
816
    uint16_t fcs = g_ntohs(crc16_ccitt_tvb(tvb, (hdrlen - 2)));
459
816
    proto_tree_add_checksum(docsis_tree, tvb, (hdrlen - 2), hf_docsis_hcs, hf_docsis_hcs_status, &ei_docsis_hcs_bad, pinfo, fcs, ENC_BIG_ENDIAN, PROTO_CHECKSUM_VERIFY);
460
461
816
    return (tvb_get_ntohs(tvb, (hdrlen - 2)) == fcs) ? true : false;
462
816
  }
463
0
  else
464
0
  {
465
0
    proto_tree_add_checksum(docsis_tree, tvb, (hdrlen - 2), hf_docsis_hcs, hf_docsis_hcs_status, &ei_docsis_hcs_bad, pinfo, 0, ENC_BIG_ENDIAN, PROTO_CHECKSUM_NO_FLAGS);
466
0
  }
467
0
  return true;
468
816
}
469
470
/* Code to Dissect the extended header length / MAC Param field and Length field */
471
/* The length field may contain a SID, but this logic is not handled here */
472
static proto_item*
473
dissect_exthdr_length_field (tvbuff_t * tvb, packet_info * pinfo, proto_tree * docsis_tree,
474
                             uint8_t exthdr, uint16_t mac_parm, uint16_t len_sid, uint16_t *payload_length, bool *is_encrypted)
475
857
{
476
857
  proto_item *length_item;
477
857
  if (exthdr == EXT_HDR_ON)
478
121
  {
479
    /* Add in Extended Header Length */
480
121
    proto_tree_add_item (docsis_tree, hf_docsis_ehdrlen, tvb, 1, 1,  ENC_BIG_ENDIAN);
481
121
    length_item = proto_tree_add_item (docsis_tree, hf_docsis_len, tvb, 2, 2, ENC_BIG_ENDIAN);
482
    /* Validate PDU length */
483
121
    if ((len_sid - mac_parm) > *payload_length)
484
93
    {
485
93
      *payload_length = len_sid;
486
93
      expert_add_info(pinfo, length_item, &ei_docsis_len);
487
93
    }
488
    /* Pass off to the Extended Header dissection */
489
121
    dissect_ehdr (tvb, docsis_tree, pinfo, is_encrypted);
490
121
  }
491
736
  else
492
736
  {
493
    /* Add in MAC Parm field only */
494
736
    proto_tree_add_item (docsis_tree, hf_docsis_macparm, tvb, 1, 1, ENC_BIG_ENDIAN);
495
736
    length_item = proto_tree_add_item (docsis_tree, hf_docsis_len, tvb, 2, 2, ENC_BIG_ENDIAN);
496
    /* Validate PDU length */
497
736
    if (len_sid > *payload_length)
498
25
    {
499
25
      *payload_length = len_sid;
500
25
      expert_add_info(pinfo, length_item, &ei_docsis_len);
501
25
    }
502
736
  }
503
857
  return length_item;
504
857
}
505
506
/* Code to Dissect Encrypted DOCSIS Frames */
507
/* Print DST and SRC MACs and do not dissect the payload */
508
/* Implementation inferred from packet-eth.c */
509
static void
510
dissect_encrypted_frame (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, const uint8_t fctype, const uint8_t fcparm)
511
0
{
512
0
  uint32_t          offset, frame_len;
513
0
  const uint8_t     *src_addr, *dst_addr;
514
0
  const char        *src_addr_name, *dst_addr_name;
515
0
  proto_item        *addr_item;
516
0
  proto_tree        *addr_tree=NULL;
517
//  tvbuff_t          *next_tvb;
518
519
  /* According to CM-SP-SEC-v3.1, PDU regions of the following
520
   * frames must be encrypted when security is enabled:
521
   * - Variable-length PDU MAC Frames;
522
   * - Fragmentation MAC Frames;
523
   * - Registration Request (REG-REQ-MP) MAC Management Message Frames;
524
   * - Isolation PDU MAC Frames.
525
   * There are also other corner cases when MAC Management frames might be encrypted
526
   * (e.g. EH_TYPE=7 as described in CM-SP-MULPIv3.1-I15-180509 Table 17 and Table 20)
527
   */
528
0
  if (fctype == FCTYPE_MACSPC) {
529
0
    if (fcparm == FCPARM_MAC_MGMT_HDR) {
530
0
      col_append_str (pinfo->cinfo, COL_INFO, " (Encrypted MMM)");
531
0
    } else if (fcparm == FCPARM_FRAG_HDR) {
532
0
      col_append_str (pinfo->cinfo, COL_INFO, " (Encrypted Fragmentation MAC Frame)");
533
0
    } else {
534
0
      col_append_str (pinfo->cinfo, COL_INFO, " (Encrypted)");
535
0
    }
536
0
  } else {
537
0
    col_append_str (pinfo->cinfo, COL_INFO, " (Encrypted)");
538
0
  }
539
540
0
  offset = 0;
541
0
  frame_len = tvb_captured_length_remaining (tvb, offset);
542
0
  switch (fctype)
543
0
  {
544
0
    case FCTYPE_PACKET:
545
0
    case FCTYPE_ISOLAT:
546
0
    case FCTYPE_MACSPC:
547
0
      dst_addr = tvb_get_ptr(tvb, 0, 6);
548
0
      dst_addr_name = get_ether_name(dst_addr);
549
0
      src_addr = tvb_get_ptr(tvb, 6, 6);
550
0
      src_addr_name = get_ether_name(src_addr);
551
552
0
      addr_item = proto_tree_add_ether(tree, hf_docsis_dst, tvb, 0, 6, dst_addr);
553
0
      addr_tree = proto_item_add_subtree(addr_item, ett_addr);
554
0
      addr_item=proto_tree_add_string(addr_tree, hf_docsis_dst_resolved, tvb, 0, 6,
555
0
          dst_addr_name);
556
0
      proto_item_set_generated(addr_item);
557
0
      proto_tree_add_item(addr_tree, hf_docsis_lg, tvb, 0, 3, ENC_BIG_ENDIAN);
558
0
      proto_tree_add_item(addr_tree, hf_docsis_ig, tvb, 0, 3, ENC_BIG_ENDIAN);
559
560
0
      addr_item = proto_tree_add_ether(tree, hf_docsis_src, tvb, 6, 6, src_addr);
561
0
      addr_tree = proto_item_add_subtree(addr_item, ett_addr);
562
0
      addr_item=proto_tree_add_string(addr_tree, hf_docsis_src_resolved, tvb, 6, 6,
563
0
          src_addr_name);
564
0
      proto_item_set_generated(addr_item);
565
0
      proto_tree_add_item(addr_tree, hf_docsis_lg, tvb, 6, 3, ENC_BIG_ENDIAN);
566
0
      proto_tree_add_item(addr_tree, hf_docsis_ig, tvb, 6, 3, ENC_BIG_ENDIAN);
567
568
0
      offset += 12;
569
0
      break;
570
0
  }
571
0
  proto_tree_add_item(tree, hf_docsis_encrypted_payload, tvb, offset, frame_len - offset, ENC_NA);
572
573
0
  return;
574
0
}
575
576
/* Main DOCSIS Dissection Entry Point */
577
/* Code to Dissect the DOCSIS Frames */
578
static int
579
dissect_docsis (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, void* data _U_)
580
889
{
581
889
  uint8_t fc = 0;
582
889
  uint8_t fctype = 0;
583
889
  uint8_t fcparm = 0;
584
889
  uint8_t exthdr = 0;
585
889
  uint16_t mac_parm = 0;
586
889
  uint8_t hdrlen = DOCSIS_MIN_HEADER_LEN;
587
889
  uint16_t len_sid = 0;
588
889
  tvbuff_t *next_tvb = NULL;
589
889
  tvbuff_t *mgt_tvb = NULL;
590
889
  int pdulen = 0;
591
889
  uint16_t payload_length = 0;
592
  /* uint16_t framelen = 0; */
593
889
  bool save_fragmented;
594
889
  bool is_encrypted = false;
595
889
  bool fcs_correct;
596
889
  proto_item *ti;
597
889
  proto_tree *docsis_tree;
598
599
  /* Extract Frame Control parts */
600
889
  fc = tvb_get_uint8 (tvb, 0); /* Frame Control Byte */
601
889
  fctype = (fc >> 6) & 0x03;    /* Frame Control Type:  2 MSB Bits */
602
889
  fcparm = (fc >> 1) & 0x1F;    /* Frame Control Parameter: Next 5 Bits */
603
889
  exthdr = (fc & 0x01);         /* Extended Header Bit: LSB */
604
605
  /* Extract the MAC Parm; MAC Parm and SID offsets; change for a Queue Depth Request */
606
889
  if (fcparm == FCPARM_QUEUE_DEPTH_REQ_FRM) {
607
17
    mac_parm = tvb_get_ntohs (tvb, 1);
608
17
    len_sid = tvb_get_ntohs (tvb, 3);
609
17
    hdrlen = DOCSIS_MIN_HEADER_LEN + 1; // 7-byte header for this message type
610
872
  } else {
611
872
    mac_parm = tvb_get_uint8 (tvb, 1);
612
872
    len_sid = tvb_get_ntohs (tvb, 2);
613
872
  }
614
615
  /* Set Header Length based on presence of Extended header */
616
889
  if (exthdr == EXT_HDR_ON) {
617
133
    hdrlen += mac_parm;
618
133
  }
619
620
  /* Captured Payload Length is based on the length of the header */
621
889
  payload_length = tvb_reported_length_remaining (tvb, hdrlen);
622
623
  /* If this is a Request Frame, then pdulen is 0 and framelen is 6 */
624
889
  if ((fctype == FCTYPE_MACSPC) && (fcparm == FCPARM_RQST_FRM || fcparm == FCPARM_QUEUE_DEPTH_REQ_FRM))
625
1
  {
626
1
    pdulen = 0;
627
    /*
628
    if (fcparm == FCPARM_QUEUE_DEPTH_REQ_FRM)
629
      framelen = DOCSIS_MIN_HEADER_LEN + 1;
630
    else
631
      framelen = DOCSIS_MIN_HEADER_LEN;
632
    */
633
888
  } else {
634
    /* framelen = DOCSIS_MIN_HEADER_LEN + len_sid; */
635
888
    pdulen = len_sid - (mac_parm + 2);
636
888
  }
637
638
  /* Make entries in Protocol column and Info column on summary display */
639
889
  col_set_str (pinfo->cinfo, COL_PROTOCOL, "DOCSIS");
640
641
889
  switch (fctype)
642
889
  {
643
770
    case FCTYPE_PACKET:
644
770
      col_set_str (pinfo->cinfo, COL_INFO, "Packet PDU");
645
770
      break;
646
34
    case FCTYPE_SPECIAL:
647
34
      col_set_str (pinfo->cinfo, COL_INFO, "Special Use");
648
34
      break;
649
40
    case FCTYPE_ISOLAT:
650
40
      col_set_str (pinfo->cinfo, COL_INFO, "Isolation PDU");
651
40
      break;
652
33
    case FCTYPE_MACSPC:
653
33
      if (fcparm == FCPARM_RQST_FRM)
654
0
        col_add_fstr (pinfo->cinfo, COL_INFO,
655
0
                      "Request Frame SID=%u Mini Slots=%u", len_sid,
656
0
                      mac_parm);
657
33
      else if (fcparm == FCPARM_QUEUE_DEPTH_REQ_FRM)
658
1
        col_add_fstr (pinfo->cinfo, COL_INFO,
659
1
                      "Request Frame SID=%u, Requested Size=%uxN bytes", len_sid,
660
1
                      mac_parm);
661
32
      else if (fcparm == FCPARM_FRAG_HDR)
662
10
        col_set_str (pinfo->cinfo, COL_INFO, "Fragmented Frame");
663
22
      else
664
22
        col_set_str (pinfo->cinfo, COL_INFO, "MAC Specific");
665
33
      break;
666
889
  }  /* switch fctype */
667
668
877
  ti = proto_tree_add_item(tree, proto_docsis, tvb, 0, hdrlen, ENC_NA);
669
877
  docsis_tree = proto_item_add_subtree (ti, ett_docsis);
670
671
  /* add an item to the subtree, see section 1.6 for more information */
672
673
  /* Add in FC Byte fields */
674
877
  proto_tree_add_item (docsis_tree, hf_docsis_fctype, tvb, 0, 1, ENC_BIG_ENDIAN);
675
676
877
  switch (fctype)
677
877
  {
678
770
    case FCTYPE_PACKET:
679
770
    {
680
770
      proto_item_append_text (ti, " Packet PDU");
681
770
      proto_tree_add_item (docsis_tree, hf_docsis_fcparm, tvb, 0, 1, ENC_BIG_ENDIAN);
682
770
      proto_tree_add_item (docsis_tree, hf_docsis_exthdr, tvb, 0, 1, ENC_BIG_ENDIAN);
683
      /* Dissect Length field for a PDU */
684
770
      dissect_exthdr_length_field (tvb, pinfo, docsis_tree, exthdr, mac_parm, len_sid, &payload_length, &is_encrypted);
685
      /* Dissect Header Check Sequence field for a PDU */
686
770
      fcs_correct = dissect_hcs_field (tvb, pinfo, docsis_tree, hdrlen);
687
770
      if (fcs_correct && pdulen > 0)
688
0
      {
689
0
        next_tvb =  tvb_new_subset_remaining(tvb, hdrlen);
690
0
        if(is_encrypted && !docsis_dissect_encrypted_frames)
691
0
          dissect_encrypted_frame (next_tvb, pinfo, docsis_tree, fctype, fcparm);
692
0
        else
693
0
          call_dissector (eth_maybefcs_handle, next_tvb, pinfo, docsis_tree);
694
0
      }
695
770
      break;
696
0
    }
697
34
    case FCTYPE_SPECIAL:
698
34
    {
699
34
      proto_item_append_text (ti, " Special Use PDU");
700
34
      proto_tree_add_item (docsis_tree, hf_docsis_machdr_fcparm, tvb, 0, 1, ENC_BIG_ENDIAN);
701
34
      proto_tree_add_item (docsis_tree, hf_docsis_exthdr, tvb, 0, 1, ENC_BIG_ENDIAN);
702
      /* Dissect Length field for a PDU */
703
34
      dissect_exthdr_length_field (tvb, pinfo, docsis_tree, exthdr, mac_parm, len_sid, &payload_length, &is_encrypted);
704
      /* Dissect Header Check Sequence field for a PDU */
705
34
      fcs_correct = dissect_hcs_field (tvb, pinfo, docsis_tree, hdrlen);
706
34
      if (fcs_correct) {
707
0
        if (fcparm == FCPARM_MAC_MGMT_HDR && exthdr == EXT_HDR_OFF) {
708
          /* Pass off to the DOCSIS Management dissector/s */
709
0
          mgt_tvb = tvb_new_subset_remaining(tvb, hdrlen);
710
0
          if (is_encrypted && !docsis_dissect_encrypted_frames)
711
0
            dissect_encrypted_frame (mgt_tvb, pinfo, docsis_tree, fctype, fcparm);
712
0
          else
713
0
            call_dissector (docsis_mgmt_handle, mgt_tvb, pinfo, docsis_tree);
714
0
        } else {
715
          /* Don't do anything for a Reserved Frame */
716
0
          next_tvb =  tvb_new_subset_remaining(tvb, hdrlen);
717
0
          call_data_dissector(next_tvb, pinfo, tree);
718
0
        }
719
0
      }
720
34
      break;
721
0
    }
722
40
    case FCTYPE_ISOLAT:
723
40
    {
724
40
      proto_item_append_text (ti, " Isolation PDU");
725
40
      proto_tree_add_item (docsis_tree, hf_docsis_fcparm, tvb, 0, 1, ENC_BIG_ENDIAN);
726
40
      proto_tree_add_item (docsis_tree, hf_docsis_exthdr, tvb, 0, 1, ENC_BIG_ENDIAN);
727
      /* Dissect Length field for a PDU */
728
40
      dissect_exthdr_length_field (tvb, pinfo, docsis_tree, exthdr, mac_parm, len_sid, &payload_length, &is_encrypted);
729
      /* Dissect Header Check Sequence field for a PDU */
730
40
      fcs_correct = dissect_hcs_field (tvb, pinfo, docsis_tree, hdrlen);
731
40
      if (fcs_correct && pdulen > 0)
732
0
      {
733
0
        next_tvb =  tvb_new_subset_remaining(tvb, hdrlen);
734
0
        if(is_encrypted && !docsis_dissect_encrypted_frames)
735
0
          dissect_encrypted_frame (next_tvb, pinfo, docsis_tree, fctype, fcparm);
736
0
        else
737
0
          call_dissector (eth_maybefcs_handle, next_tvb, pinfo, docsis_tree);
738
0
      }
739
40
      break;
740
0
    }
741
33
    case FCTYPE_MACSPC:
742
33
    {
743
33
      proto_item_append_text (ti, " MAC-Specific PDU");
744
33
      proto_tree_add_item (docsis_tree, hf_docsis_machdr_fcparm, tvb, 0, 1, ENC_BIG_ENDIAN);
745
33
      proto_tree_add_item (docsis_tree, hf_docsis_exthdr, tvb, 0, 1, ENC_BIG_ENDIAN);
746
33
      switch(fcparm)
747
33
      {
748
0
        case FCPARM_TIMING_HDR:
749
          // no break
750
3
        case FCPARM_MAC_MGMT_HDR:
751
3
        {
752
          /* Dissect Length field for a PDU */
753
3
          dissect_exthdr_length_field (tvb, pinfo, docsis_tree, exthdr, mac_parm, len_sid, &payload_length, &is_encrypted);
754
          /* Dissect Header Check Sequence field for a PDU */
755
3
          fcs_correct = dissect_hcs_field (tvb, pinfo, docsis_tree, hdrlen);
756
3
          if (fcs_correct)
757
0
          {
758
            /* Pass off to the DOCSIS Management dissector/s */
759
0
            mgt_tvb = tvb_new_subset_remaining(tvb, hdrlen);
760
0
            if(is_encrypted && !docsis_dissect_encrypted_frames)
761
0
              dissect_encrypted_frame (mgt_tvb, pinfo, docsis_tree, fctype, fcparm);
762
0
            else
763
0
              call_dissector (docsis_mgmt_handle, mgt_tvb, pinfo, docsis_tree);
764
0
          }
765
3
          break;
766
0
        }
767
0
        case FCPARM_RQST_FRM:
768
0
        {
769
          /* Decode for a Request Frame.  No extended header */
770
0
          proto_tree_add_uint (docsis_tree, hf_docsis_mini_slots, tvb, 1, 1, mac_parm);
771
0
          proto_tree_add_uint (docsis_tree, hf_docsis_sid, tvb, 2, 2, len_sid);
772
          /* Dissect Header Check Sequence field for a PDU */
773
0
          fcs_correct = dissect_hcs_field (tvb, pinfo, docsis_tree, hdrlen);
774
0
          if (fcs_correct)
775
0
          {
776
            /* Don't do anything for a Request Frame, there is no data following it */
777
0
          }
778
0
          break;
779
0
        }
780
10
        case FCPARM_FRAG_HDR:
781
10
        {
782
10
          proto_item *length_item;
783
          /* Check if this is a fragmentation header */
784
10
          save_fragmented = pinfo->fragmented;
785
10
          pinfo->fragmented = true;
786
787
          /* Dissect Length field for a PDU */
788
10
          length_item = dissect_exthdr_length_field (tvb, pinfo, docsis_tree, exthdr, mac_parm, len_sid, &payload_length, &is_encrypted);
789
10
          if (len_sid < 4) {
790
0
            expert_add_info_format(pinfo, length_item, &ei_docsis_len_small, "Len field value is too small to fit fragment FCS");
791
0
            THROW(ReportedBoundsError);
792
0
          }
793
          /* Dissect Header Check Sequence field for a PDU */
794
10
          fcs_correct = dissect_hcs_field (tvb, pinfo, docsis_tree, hdrlen);
795
10
          if (fcs_correct)
796
0
          {
797
0
            uint32_t fcs = 0;
798
0
            if (!tvb_bytes_exist(tvb, hdrlen, len_sid)) {
799
0
              fcs_correct = false;
800
0
            } else {
801
              /* Grab the Fragment FCS */
802
0
              uint32_t sent_fcs = tvb_get_ntohl(tvb, (hdrlen + len_sid - 4));
803
0
              fcs = crc32_802_tvb(tvb, hdrlen + len_sid - 4);
804
0
              fcs_correct = (sent_fcs == fcs);
805
0
            }
806
807
            /* Only defragment valid frames with a good FCS */
808
0
            if (fcs_correct)
809
0
            {
810
0
              fragment_head *frag_msg = NULL;
811
0
              frag_msg = fragment_add_seq_check(&docsis_reassembly_table,
812
0
                                                tvb, hdrlen, pinfo,
813
0
                                                frag_sid, NULL, /* ID for fragments belonging together */
814
0
                                                frag_seq, /* Fragment Sequence Number */
815
0
                                                (len_sid - 4), /* fragment length - to the end */
816
0
                                                !(frag_flags & FRAG_LAST)); /* More fragments? */
817
818
0
              next_tvb = process_reassembled_data(tvb, hdrlen, pinfo,
819
0
                                                  "Reassembled Message", frag_msg, &docsis_frag_items,
820
0
                                                  NULL, docsis_tree);
821
822
0
              if (frag_flags == FRAG_LAST)
823
0
                pinfo->fragmented = false;
824
0
              else
825
0
                pinfo->fragmented = true;
826
827
0
              if (frag_msg) { /* Reassembled */
828
0
                proto_item_append_text (ti, " (Message Reassembled)");
829
0
              } else { /* Not last packet of reassembled Short Message */
830
0
                proto_item_append_text (ti, " (Message fragment %u)", frag_seq);
831
832
0
              }
833
834
0
              if(next_tvb)
835
0
              {
836
                /* By default assume an Ethernet payload */
837
0
                if(is_encrypted && !docsis_dissect_encrypted_frames)
838
0
                  dissect_encrypted_frame (next_tvb, pinfo, docsis_tree, fctype, fcparm);
839
0
                else
840
0
                  call_dissector (eth_maybefcs_handle, next_tvb, pinfo, docsis_tree);
841
0
              } else {
842
                /* Otherwise treat as Data */
843
0
                tvbuff_t *payload_tvb = tvb_new_subset_length(tvb, hdrlen, len_sid - 4);
844
0
                call_data_dissector(payload_tvb, pinfo, docsis_tree);
845
0
              }
846
0
            }
847
            /* Add the Fragment FCS to the end of the parent tree */
848
0
            proto_tree_add_checksum(docsis_tree, tvb, (hdrlen + len_sid - 4), hf_docsis_frag_fcs, hf_docsis_frag_fcs_status, &ei_docsis_frag_fcs_bad, pinfo, fcs, ENC_BIG_ENDIAN, PROTO_CHECKSUM_VERIFY);
849
850
0
            pinfo->fragmented = save_fragmented;
851
0
          }
852
10
          break;
853
0
        }
854
1
        case FCPARM_QUEUE_DEPTH_REQ_FRM:
855
1
        {
856
          /* Decode for a Queue-depth Based Request */
857
1
          proto_tree_add_uint (docsis_tree, hf_docsis_requested_size, tvb, 1, 2, mac_parm);
858
1
          proto_tree_add_uint (docsis_tree, hf_docsis_sid, tvb, 3, 2, len_sid);
859
          /* Dissect Header Check Sequence field for a PDU */
860
1
          fcs_correct = dissect_hcs_field (tvb, pinfo, docsis_tree, hdrlen);
861
1
          if (fcs_correct)
862
0
          {
863
          /* No PDU Payload for this frame */
864
0
          }
865
1
          break;
866
0
        }
867
2
        case FCPARM_CONCAT_HDR:
868
2
        {
869
          /* Decode for a Concatenated Header; ONLY for DOCSIS versions < 3.1.  No Extended Header */
870
2
          proto_item_append_text (ti, " (Concatenated Header)");
871
2
          proto_tree_add_item (docsis_tree, hf_docsis_concat_cnt, tvb, 1, 1, ENC_BIG_ENDIAN);
872
2
          proto_tree_add_item (docsis_tree, hf_docsis_len, tvb, 2, 2, ENC_BIG_ENDIAN);
873
          /* Dissect Header Check Sequence field for a PDU */
874
2
          fcs_correct = dissect_hcs_field (tvb, pinfo, docsis_tree, hdrlen);
875
2
          if (fcs_correct)
876
0
          {
877
            // There used to be a section of code here that recursively
878
            // called dissect_docsis. It has been removed. If you plan on
879
            // adding concatenated PDU support back you should consider
880
            // doing something like the following:
881
            // dissect_docsis(...) {
882
            //   while(we_have_pdus_remaining) {
883
            //     int pdu_len = dissect_docsis_pdu(...)
884
            //     if (pdu_len < 1) {
885
            //       add_expert...
886
            //       break;
887
            //     }
888
            //   }
889
            // }
890
            // Adding back this functionality using recursion might result
891
            // in this dissector being disabled by default or removed entirely.
892
0
          }
893
2
          break;
894
0
        }
895
17
        default:
896
            /* Unknown parameter, stop dissection */
897
17
          break;
898
33
      } /* switch fcparm */
899
26
      break;
900
33
    }
901
877
  } /* switch fctype */
902
903
818
  return tvb_captured_length(tvb);
904
877
}
905
906
/* Register the protocol with Wireshark */
907
void
908
proto_register_docsis (void)
909
14
{
910
14
  static hf_register_info hf[] = {
911
14
    {&hf_docsis_fctype,
912
14
     {"FCType", "docsis.fctype",
913
14
      FT_UINT8, BASE_HEX, VALS (fctype_vals), 0xC0,
914
14
      "Frame Control Type", HFILL}
915
14
    },
916
14
    {&hf_docsis_fcparm,
917
14
     {"FCParm", "docsis.fcparm",
918
14
      FT_UINT8, BASE_DEC, VALS (pkt_fcparm_vals), 0x3E,
919
14
      "Parameter Field", HFILL}
920
14
    },
921
14
    {&hf_docsis_machdr_fcparm,
922
14
     {"FCParm", "docsis.fcparm",
923
14
      FT_UINT8, BASE_DEC, VALS (ms_fcparm_vals), 0x3E,
924
14
      "Parameter Field", HFILL}
925
14
    },
926
14
    {&hf_docsis_exthdr,
927
14
     {"EXTHDR", "docsis.exthdr",
928
14
      FT_BOOLEAN, 8, TFS (&exthdr_tfs), 0x01,
929
14
      "Extended Header Presence", HFILL}
930
14
    },
931
14
    {&hf_docsis_macparm,
932
14
     {"MACParm", "docsis.macparm",
933
14
      FT_UINT8, BASE_HEX, NULL, 0x0,
934
14
      "MAC Parameter Field", HFILL}
935
14
    },
936
14
    {&hf_docsis_concat_cnt,
937
14
     {"Number of Concatenated Frames", "docsis.concat_cnt",
938
14
      FT_UINT8, BASE_DEC, NULL, 0x0,
939
14
      NULL, HFILL}
940
14
    },
941
14
    {&hf_docsis_ehdrlen,
942
14
     {"Extended Header Length (bytes)", "docsis.ehdrlen",
943
14
      FT_UINT8, BASE_DEC, NULL, 0x0,
944
14
      NULL, HFILL}
945
14
    },
946
14
    {&hf_docsis_len,
947
14
     {"Length of the MAC frame (bytes)", "docsis.len",
948
14
      FT_UINT16, BASE_DEC, NULL, 0x0,
949
14
      "Length of the MAC frame, not counting the fixed-length MAC header", HFILL}
950
14
    },
951
14
    {&hf_docsis_eh_type,
952
14
     {"Type", "docsis.ehdr.type",
953
14
      FT_UINT8, BASE_DEC, VALS (eh_type_vals), 0xF0,
954
14
      "TLV Type", HFILL}
955
14
    },
956
14
    {&hf_docsis_eh_len,
957
14
     {"Length", "docsis.ehdr.len",
958
14
      FT_UINT8, BASE_DEC, NULL, 0x0F,
959
14
      "TLV Len", HFILL}
960
14
    },
961
14
    {&hf_docsis_eh_val,
962
14
     {"Value", "docsis.ehdr.value",
963
14
      FT_BYTES, BASE_NONE, NULL, 0x0,
964
14
      "TLV Value", HFILL}
965
14
    },
966
14
    {&hf_docsis_ehx_type,
967
14
     {"Extended Type", "docsis.ehdr.ehx_type",
968
14
      FT_UINT8, BASE_DEC, NULL, 0x0,
969
14
      "TLV Type", HFILL}
970
14
    },
971
14
    {&hf_docsis_ehx_len,
972
14
     {"Extended Length", "docsis.ehdr.ehx_len",
973
14
      FT_UINT8, BASE_DEC, NULL, 0x0,
974
14
      "TLV Len", HFILL}
975
14
    },
976
14
    {&hf_docsis_frag_rsvd,
977
14
     {"Reserved", "docsis.frag_rsvd",
978
14
      FT_UINT8, BASE_DEC, NULL, 0xC0,
979
14
      NULL, HFILL}
980
14
    },
981
14
    {&hf_docsis_frag_first,
982
14
     {"First Frame", "docsis.frag_first",
983
14
      FT_BOOLEAN, 8, NULL, 0x20,
984
14
      NULL, HFILL}
985
14
    },
986
14
    {&hf_docsis_frag_last,
987
14
     {"Last Frame", "docsis.frag_last",
988
14
      FT_BOOLEAN, 8, NULL, 0x10,
989
14
      NULL, HFILL}
990
14
    },
991
14
    {&hf_docsis_frag_seq,
992
14
     {"Fragmentation Sequence #", "docsis.frag_seq",
993
14
      FT_UINT8, BASE_DEC, NULL, 0x0F,
994
14
      "Fragmentation Sequence Number", HFILL}
995
14
    },
996
14
    {&hf_docsis_sid,
997
14
     {"SID", "docsis.ehdr.sid",
998
14
      FT_UINT16, BASE_DEC_HEX, NULL, 0x3FFF,
999
14
      "Service Identifier", HFILL}
1000
14
    },
1001
14
    {&hf_docsis_said,
1002
14
     {"SAID", "docsis.ehdr.said",
1003
14
      FT_UINT16, BASE_DEC, NULL, 0x3FFF,
1004
14
      "Security Association Identifier", HFILL}
1005
14
    },
1006
14
    {&hf_docsis_reserved,
1007
14
     {"Reserved", "docsis.ehdr.rsvd",
1008
14
      FT_UINT8, BASE_HEX, NULL, 0x0,
1009
14
      "Reserved Byte", HFILL}
1010
14
    },
1011
14
    {&hf_docsis_mini_slots,
1012
14
     {"MiniSlots", "docsis.ehdr.minislots",
1013
14
      FT_UINT8, BASE_DEC, NULL, 0x0,
1014
14
      "Mini Slots Requested", HFILL}
1015
14
    },
1016
14
    {&hf_docsis_requested_size,
1017
14
     {"Requested bytes in units of N bytes, N a parameter of the service flow for which this request is being made", "docsis.ehdr.reqsize",
1018
14
      FT_UINT16, BASE_DEC, NULL, 0x0,
1019
14
      NULL, HFILL}
1020
14
    },
1021
14
    {&hf_docsis_key_seq,
1022
14
     {"Key Sequence", "docsis.ehdr.keyseq",
1023
14
      FT_UINT8, BASE_DEC, NULL, 0xF0,
1024
14
      NULL, HFILL}
1025
14
    },
1026
14
    {&hf_docsis_ehdr_ver,
1027
14
     {"Version", "docsis.ehdr.ver",
1028
14
      FT_UINT8, BASE_DEC, NULL, 0x0F,
1029
14
      NULL, HFILL}
1030
14
    },
1031
14
    {&hf_docsis_ehdr_phsi,
1032
14
     {"Payload Header Suppression Index", "docsis.ehdr.phsi",
1033
14
      FT_UINT8, BASE_DEC|BASE_SPECIAL_VALS, VALS(unique_no_phs), 0x0,
1034
14
      NULL, HFILL}
1035
14
    },
1036
14
    {&hf_docsis_ehdr_qind,
1037
14
     {"Queue Indicator", "docsis.ehdr.qind",
1038
14
      FT_BOOLEAN, 8, TFS(&qind_tfs), 0x80,
1039
14
      NULL, HFILL}
1040
14
    },
1041
14
    {&hf_docsis_ehdr_grants,
1042
14
     {"Active Grants", "docsis.ehdr.act_grants",
1043
14
      FT_UINT8, BASE_DEC, NULL, 0x7F,
1044
14
      NULL, HFILL}
1045
14
    },
1046
14
    {&hf_docsis_ehdr_bpup2_key_seq,
1047
14
     {"Key Sequence", "docsis.ehdr.bpup2_keyseq",
1048
14
      FT_UINT8, BASE_DEC, NULL, 0xF0,
1049
14
      NULL, HFILL}
1050
14
    },
1051
14
    {&hf_docsis_ehdr_bpup2_ver,
1052
14
     {"Version", "docsis.ehdr.bpup2_ver",
1053
14
      FT_UINT8, BASE_DEC, NULL, 0x0F,
1054
14
      NULL, HFILL}
1055
14
    },
1056
14
    {&hf_docsis_ehdr_bpup2_bpi_en,
1057
14
     {"Encryption", "docsis.ehdr.bpup2_bpi_en",
1058
14
      FT_BOOLEAN, 8, TFS (&tfs_enabled_disabled), 0x80,
1059
14
      "BPI Enable", HFILL}
1060
14
    },
1061
14
    {&hf_docsis_ehdr_bpup2_toggle_bit,
1062
14
     {"Toggle", "docsis.ehdr.bpup2_toggle_bit",
1063
14
      FT_BOOLEAN, 8, TFS (&odd_even_tfs), 0x40,
1064
14
      NULL, HFILL}
1065
14
    },
1066
14
    {&hf_docsis_ehdr_bpup2_sid,
1067
14
     {"SID", "docsis.ehdr.bpup2_sid",
1068
14
      FT_UINT16, BASE_DEC, NULL, 0x3FFF,
1069
14
      "Service Identifier", HFILL}
1070
14
    },
1071
14
    { &hf_docsis_ehdr_pv_st_refpt,
1072
14
     { "Start Reference Point", "docsis.ehdr.pv_start_ref",
1073
14
       FT_UINT8, BASE_DEC, NULL, 0x0,
1074
14
       NULL, HFILL}
1075
14
    },
1076
14
    { &hf_docsis_ehdr_pv_timestamp,
1077
14
     { "Timestamp", "docsis.ehdr.pv_timestamp",
1078
14
       FT_UINT32, BASE_DEC, NULL, 0x0,
1079
14
       NULL, HFILL}
1080
14
    },
1081
14
    {&hf_docsis_ehdr_ds_traffic_pri,
1082
14
     {"DS Traffic Priority", "docsis.ehdr.ds_traffic_pri",
1083
14
      FT_UINT8, BASE_DEC, NULL, 0xE0,
1084
14
      NULL, HFILL}
1085
14
    },
1086
14
    {&hf_docsis_ehdr_ds_seq_chg_cnt,
1087
14
     {"DS Sequence Change Count", "docsis.ehdr.ds_seq_chg_cnt",
1088
14
      FT_UINT8, BASE_DEC, NULL, 0x10,
1089
14
      NULL, HFILL}
1090
14
    },
1091
14
    {&hf_docsis_ehdr_ds_dsid,
1092
14
     {"DS DSID", "docsis.ehdr.ds_dsid",
1093
14
      FT_UINT32, BASE_DEC, NULL, 0x0FFFFF,
1094
14
      NULL, HFILL}
1095
14
    },
1096
14
    {&hf_docsis_ehdr_ds_pkt_seq_num,
1097
14
     {"DS Packet Sequence Number", "docsis.ehdr.ds_pkt_seq_num",
1098
14
      FT_UINT16, BASE_DEC, NULL, 0x0,
1099
14
      NULL, HFILL}
1100
14
    },
1101
14
    {&hf_docsis_hcs,
1102
14
     {"Header check sequence", "docsis.hcs",
1103
14
      FT_UINT16, BASE_HEX, NULL, 0x0,
1104
14
      NULL, HFILL}
1105
14
    },
1106
14
    { &hf_docsis_hcs_status,
1107
14
     { "HCS Status", "docsis.hcs.status",
1108
14
       FT_UINT8, BASE_NONE, VALS(proto_checksum_vals), 0x0,
1109
14
       NULL, HFILL}
1110
14
    },
1111
14
    { &hf_docsis_bpi_en,
1112
14
     { "Encryption", "docsis.bpi_en",
1113
14
       FT_BOOLEAN, 8, TFS (&tfs_enabled_disabled), 0x80,
1114
14
       "BPI Enable", HFILL}
1115
14
    },
1116
14
    { &hf_docsis_toggle_bit,
1117
14
     { "Toggle", "docsis.toggle_bit",
1118
14
       FT_BOOLEAN, 8, TFS (&odd_even_tfs), 0x40,
1119
14
       NULL, HFILL}
1120
14
    },
1121
14
    { &hf_docsis_fragment_overlap,
1122
14
     { "Fragment overlap", "docsis.fragment.overlap",
1123
14
       FT_BOOLEAN, BASE_NONE, NULL, 0x0,
1124
14
       "Fragment overlaps with other fragments", HFILL}
1125
14
    },
1126
14
    { &hf_docsis_fragment_overlap_conflict,
1127
14
     { "Conflicting data in fragment overlap", "docsis.fragment.overlap.conflict",
1128
14
       FT_BOOLEAN, BASE_NONE, NULL, 0x0,
1129
14
       "Overlapping fragments contained conflicting data", HFILL}
1130
14
    },
1131
14
    { &hf_docsis_fragment_multiple_tails,
1132
14
     { "Multiple tail fragments found", "docsis.fragment.multipletails",
1133
14
       FT_BOOLEAN, BASE_NONE, NULL, 0x0,
1134
14
       "Several tails were found when defragmenting the packet", HFILL}
1135
14
    },
1136
14
    { &hf_docsis_fragment_too_long_fragment,
1137
14
     { "Fragment too long", "docsis.fragment.toolongfragment",
1138
14
       FT_BOOLEAN, BASE_NONE, NULL, 0x0,
1139
14
       "Fragment contained data past end of packet", HFILL}
1140
14
    },
1141
14
    { &hf_docsis_fragment_error,
1142
14
     { "Defragmentation error", "docsis.fragment.error",
1143
14
       FT_FRAMENUM, BASE_NONE, NULL, 0x0,
1144
14
       "Defragmentation error due to illegal fragments", HFILL}
1145
14
    },
1146
14
    { &hf_docsis_fragment_count,
1147
14
     { "Fragment count", "docsis.fragment.count",
1148
14
       FT_UINT32, BASE_DEC, NULL, 0x0,
1149
14
       NULL, HFILL}
1150
14
    },
1151
14
    { &hf_docsis_fragment,
1152
14
     { "DOCSIS Fragment", "docsis.fragment",
1153
14
       FT_FRAMENUM, BASE_NONE, NULL, 0x0,
1154
14
       NULL, HFILL}
1155
14
    },
1156
14
    { &hf_docsis_fragments,
1157
14
     { "DOCSIS Fragments", "docsis.fragments",
1158
14
       FT_BYTES, BASE_NONE, NULL, 0x0,
1159
14
       NULL, HFILL}
1160
14
    },
1161
14
    { &hf_docsis_reassembled_in,
1162
14
     { "Reassembled DOCSIS in frame", "docsis.reassembled_in",
1163
14
       FT_FRAMENUM, BASE_NONE, NULL, 0x0,
1164
14
       "This DOCSIS packet is reassembled in this frame", HFILL}
1165
14
    },
1166
14
    { &hf_docsis_reassembled_length,
1167
14
     { "Reassembled DOCSIS length", "docsis.reassembled.length",
1168
14
       FT_UINT32, BASE_DEC, NULL, 0x0,
1169
14
       "The total length of the reassembled payload", HFILL}
1170
14
    },
1171
14
    { &hf_docsis_reassembled_data,
1172
14
     { "Reassembled DOCSIS data", "docsis.reassembled.data",
1173
14
       FT_BYTES, BASE_NONE, NULL, 0x0,
1174
14
       "The reassembled payload", HFILL}
1175
14
    },
1176
14
    { &hf_docsis_frag_fcs,
1177
14
     { "Fragment FCS", "docsis.frag.fcs",
1178
14
       FT_UINT32, BASE_HEX, NULL, 0x0,
1179
14
       NULL, HFILL}
1180
14
    },
1181
14
    { &hf_docsis_frag_fcs_status,
1182
14
     { "Fragment FCS Status", "docsis.frag.fcs.status",
1183
14
       FT_UINT8, BASE_NONE, VALS(proto_checksum_vals), 0x0,
1184
14
       NULL, HFILL}
1185
14
    },
1186
14
    { &hf_docsis_encrypted_payload,
1187
14
      { "Encrypted Payload", "docsis.encrypted_payload",
1188
14
        FT_BYTES, BASE_NONE, NULL, 0x0,
1189
14
        "Encrypted data", HFILL }
1190
14
    }
1191
14
  };
1192
1193
14
  static ei_register_info ei[] = {
1194
14
      { &ei_docsis_hcs_bad, { "docsis.hcs_bad", PI_CHECKSUM, PI_ERROR, "Bad header check sequence", EXPFILL }},
1195
14
      { &ei_docsis_len, { "docsis.len.past_end", PI_MALFORMED, PI_ERROR, "Length field value goes past the end of the payload", EXPFILL }},
1196
14
      { &ei_docsis_len_small, { "docsis.len.too_small", PI_MALFORMED, PI_ERROR, "Length field value is too small", EXPFILL }},
1197
14
      { &ei_docsis_frag_fcs_bad, { "docsis.frag.fcs_bad", PI_CHECKSUM, PI_ERROR, "Bad checksum", EXPFILL }},
1198
14
      { &ei_docsis_eh_len, { "docsis.ehdr.len.past_end", PI_MALFORMED, PI_ERROR, "Extended Header Length Invalid!", EXPFILL }}
1199
14
  };
1200
1201
14
  static int *ett[] = {
1202
14
      &ett_docsis,
1203
14
      &ett_ehdr,
1204
14
      &ett_docsis_fragment,
1205
14
      &ett_docsis_fragments,
1206
14
      &ett_addr
1207
14
  };
1208
1209
14
  module_t *docsis_module;
1210
14
  expert_module_t* expert_docsis;
1211
1212
14
  proto_docsis = proto_register_protocol ("DOCSIS", "DOCSIS", "docsis");
1213
14
  proto_register_field_array (proto_docsis, hf, array_length (hf));
1214
14
  proto_register_subtree_array (ett, array_length (ett));
1215
1216
  /* register expert notifications */
1217
14
  expert_docsis = expert_register_protocol(proto_docsis);
1218
14
  expert_register_field_array(expert_docsis, ei, array_length(ei));
1219
1220
  /* Register configuration preferences */
1221
14
  docsis_module = prefs_register_protocol(proto_docsis, NULL);
1222
14
  prefs_register_bool_preference(docsis_module, "check_fcs",
1223
14
                                 "Validate the DOCSIS checksum if possible",
1224
14
                                 "Whether or not to validate the Header Check Sequence",
1225
14
                                 &docsis_check_fcs);
1226
14
   prefs_register_bool_preference(docsis_module, "dissect_encrypted_frames",
1227
14
                                 "Ignore EH 'encrypted' bit",
1228
14
                                 "Whether or not to attempt to dissect encrypted DOCSIS payload",
1229
14
                                 &docsis_dissect_encrypted_frames);
1230
1231
#if 0
1232
  docsis_dissector_table = register_dissector_table ("docsis",
1233
                                                     "DOCSIS Encapsulation Type", proto_docsis,
1234
                                                     FT_UINT8, BASE_DEC);
1235
#endif
1236
1237
14
  docsis_handle = register_dissector ("docsis", dissect_docsis, proto_docsis);
1238
14
  reassembly_table_register(&docsis_reassembly_table,
1239
14
                        &addresses_reassembly_table_functions);
1240
14
}
1241
1242
void
1243
proto_reg_handoff_docsis (void)
1244
14
{
1245
14
  dissector_add_uint ("wtap_encap", WTAP_ENCAP_DOCSIS, docsis_handle);
1246
1247
14
  hf_docsis_dst = proto_registrar_get_id_byname ("eth.dst");
1248
14
  hf_docsis_dst_resolved = proto_registrar_get_id_byname ("eth.dst_resolved");
1249
14
  hf_docsis_src = proto_registrar_get_id_byname ("eth.src");
1250
14
  hf_docsis_src_resolved = proto_registrar_get_id_byname ("eth.src_resolved");
1251
14
  hf_docsis_lg = proto_registrar_get_id_byname ("eth.lg");
1252
14
  hf_docsis_ig = proto_registrar_get_id_byname ("eth.ig");
1253
1254
14
  docsis_mgmt_handle = find_dissector ("docsis_mgmt");
1255
14
  eth_maybefcs_handle = find_dissector_add_dependency("eth_maybefcs", proto_docsis);
1256
14
}
1257
1258
/*
1259
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
1260
 *
1261
 * Local Variables:
1262
 * c-basic-offset: 2
1263
 * tab-width: 8
1264
 * indent-tabs-mode: nil
1265
 * End:
1266
 *
1267
 * ex: set shiftwidth=2 tabstop=8 expandtab:
1268
 * :indentSize=2:tabSize=8:noTabs=true:
1269
 */