Coverage Report

Created: 2026-07-12 07:10

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