diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-09-19 04:14:53 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-09-19 04:14:53 +0000 |
commit | a86c5f7cae7ec9a3398300555a0b644689d946a1 (patch) | |
tree | 39fe4b107c71174fd1e8a8ceb9a4d2aa14116248 /epan/dissectors/packet-docsis.c | |
parent | Releasing progress-linux version 4.2.6-1~progress7.99u1. (diff) | |
download | wireshark-a86c5f7cae7ec9a3398300555a0b644689d946a1.tar.xz wireshark-a86c5f7cae7ec9a3398300555a0b644689d946a1.zip |
Merging upstream version 4.4.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'epan/dissectors/packet-docsis.c')
-rw-r--r-- | epan/dissectors/packet-docsis.c | 278 |
1 files changed, 143 insertions, 135 deletions
diff --git a/epan/dissectors/packet-docsis.c b/epan/dissectors/packet-docsis.c index 3de7f8aa..f4e7f31b 100644 --- a/epan/dissectors/packet-docsis.c +++ b/epan/dissectors/packet-docsis.c @@ -44,7 +44,7 @@ #include <epan/prefs.h> #include <epan/reassemble.h> #include <epan/addr_resolv.h> -#include <epan/exceptions.h> +#include <epan/tfs.h> #include <epan/crc16-tvb.h> #include <epan/crc32-tvb.h> @@ -52,13 +52,13 @@ void proto_register_docsis(void); void proto_reg_handoff_docsis(void); /* Assume all packets have an FCS */ -static gboolean docsis_check_fcs = TRUE; -static gboolean docsis_dissect_encrypted_frames = FALSE; +static bool docsis_check_fcs = true; +static bool docsis_dissect_encrypted_frames; #define DOCSIS_MIN_HEADER_LEN 6 #define FCTYPE_PACKET 0x00 -#define FCTYPE_RESERVED 0x01 +#define FCTYPE_SPECIAL 0x01 #define FCTYPE_ISOLAT 0x02 #define FCTYPE_MACSPC 0x03 @@ -95,71 +95,71 @@ static gboolean docsis_dissect_encrypted_frames = FALSE; #define EH_EXTENDED 15 /* Initialize the protocol and registered fields */ -static int proto_docsis = -1; -static int hf_docsis_fctype = -1; -static int hf_docsis_machdr_fcparm = -1; -static int hf_docsis_fcparm = -1; -static int hf_docsis_exthdr = -1; -static int hf_docsis_concat_cnt = -1; -static int hf_docsis_macparm = -1; -static int hf_docsis_ehdrlen = -1; -static int hf_docsis_len = -1; -static int hf_docsis_eh_type = -1; -static int hf_docsis_eh_len = -1; -static int hf_docsis_eh_val = -1; -static int hf_docsis_ehx_type = -1; -static int hf_docsis_ehx_len = -1; -static int hf_docsis_frag_rsvd = -1; -static int hf_docsis_frag_first = -1; -static int hf_docsis_frag_last = -1; -static int hf_docsis_frag_seq = -1; -static int hf_docsis_sid = -1; -static int hf_docsis_mini_slots = -1; -static int hf_docsis_requested_size = -1; -static int hf_docsis_hcs = -1; -static int hf_docsis_hcs_status = -1; -static int hf_docsis_bpi_en = -1; -static int hf_docsis_toggle_bit = -1; -static int hf_docsis_key_seq = -1; -static int hf_docsis_ehdr_ver = -1; -static int hf_docsis_said = -1; -static int hf_docsis_ehdr_phsi = -1; -static int hf_docsis_ehdr_qind = -1; -static int hf_docsis_ehdr_grants = -1; -static int hf_docsis_reserved = -1; -static int hf_docsis_ehdr_ds_traffic_pri = -1; -static int hf_docsis_ehdr_ds_seq_chg_cnt = -1; -static int hf_docsis_ehdr_ds_dsid = -1; -static int hf_docsis_ehdr_ds_pkt_seq_num = -1; -static int hf_docsis_ehdr_bpup2_bpi_en = -1; -static int hf_docsis_ehdr_bpup2_toggle_bit = -1; -static int hf_docsis_ehdr_bpup2_key_seq = -1; -static int hf_docsis_ehdr_bpup2_ver = -1; -static int hf_docsis_ehdr_bpup2_sid = -1; -static int hf_docsis_ehdr_pv_st_refpt = -1; -static int hf_docsis_ehdr_pv_timestamp = -1; - -static int hf_docsis_fragments = -1; -static int hf_docsis_fragment = -1; -static int hf_docsis_fragment_overlap = -1; -static int hf_docsis_fragment_overlap_conflict = -1; -static int hf_docsis_fragment_multiple_tails = -1; -static int hf_docsis_fragment_too_long_fragment = -1; -static int hf_docsis_fragment_error = -1; -static int hf_docsis_fragment_count = -1; -static int hf_docsis_reassembled_in = -1; -static int hf_docsis_reassembled_length = -1; -static int hf_docsis_reassembled_data = -1; -static int hf_docsis_frag_fcs = -1; -static int hf_docsis_frag_fcs_status = -1; - -static int hf_docsis_dst = -1; -static int hf_docsis_dst_resolved = -1; -static int hf_docsis_src = -1; -static int hf_docsis_src_resolved = -1; -static int hf_docsis_lg = -1; -static int hf_docsis_ig = -1; -static int hf_docsis_encrypted_payload = -1; +static int proto_docsis; +static int hf_docsis_fctype; +static int hf_docsis_machdr_fcparm; +static int hf_docsis_fcparm; +static int hf_docsis_exthdr; +static int hf_docsis_concat_cnt; +static int hf_docsis_macparm; +static int hf_docsis_ehdrlen; +static int hf_docsis_len; +static int hf_docsis_eh_type; +static int hf_docsis_eh_len; +static int hf_docsis_eh_val; +static int hf_docsis_ehx_type; +static int hf_docsis_ehx_len; +static int hf_docsis_frag_rsvd; +static int hf_docsis_frag_first; +static int hf_docsis_frag_last; +static int hf_docsis_frag_seq; +static int hf_docsis_sid; +static int hf_docsis_mini_slots; +static int hf_docsis_requested_size; +static int hf_docsis_hcs; +static int hf_docsis_hcs_status; +static int hf_docsis_bpi_en; +static int hf_docsis_toggle_bit; +static int hf_docsis_key_seq; +static int hf_docsis_ehdr_ver; +static int hf_docsis_said; +static int hf_docsis_ehdr_phsi; +static int hf_docsis_ehdr_qind; +static int hf_docsis_ehdr_grants; +static int hf_docsis_reserved; +static int hf_docsis_ehdr_ds_traffic_pri; +static int hf_docsis_ehdr_ds_seq_chg_cnt; +static int hf_docsis_ehdr_ds_dsid; +static int hf_docsis_ehdr_ds_pkt_seq_num; +static int hf_docsis_ehdr_bpup2_bpi_en; +static int hf_docsis_ehdr_bpup2_toggle_bit; +static int hf_docsis_ehdr_bpup2_key_seq; +static int hf_docsis_ehdr_bpup2_ver; +static int hf_docsis_ehdr_bpup2_sid; +static int hf_docsis_ehdr_pv_st_refpt; +static int hf_docsis_ehdr_pv_timestamp; + +static int hf_docsis_fragments; +static int hf_docsis_fragment; +static int hf_docsis_fragment_overlap; +static int hf_docsis_fragment_overlap_conflict; +static int hf_docsis_fragment_multiple_tails; +static int hf_docsis_fragment_too_long_fragment; +static int hf_docsis_fragment_error; +static int hf_docsis_fragment_count; +static int hf_docsis_reassembled_in; +static int hf_docsis_reassembled_length; +static int hf_docsis_reassembled_data; +static int hf_docsis_frag_fcs; +static int hf_docsis_frag_fcs_status; + +static int hf_docsis_dst; +static int hf_docsis_dst_resolved; +static int hf_docsis_src; +static int hf_docsis_src_resolved; +static int hf_docsis_lg; +static int hf_docsis_ig; +static int hf_docsis_encrypted_payload; static dissector_handle_t docsis_handle; static dissector_handle_t eth_withoutfcs_handle; @@ -168,21 +168,21 @@ static dissector_handle_t docsis_mgmt_handle; static dissector_table_t docsis_dissector_table; #endif -static expert_field ei_docsis_hcs_bad = EI_INIT; -static expert_field ei_docsis_len = EI_INIT; -static expert_field ei_docsis_frag_fcs_bad = EI_INIT; -static expert_field ei_docsis_eh_len = EI_INIT; +static expert_field ei_docsis_hcs_bad; +static expert_field ei_docsis_len; +static expert_field ei_docsis_frag_fcs_bad; +static expert_field ei_docsis_eh_len; /* Initialize the subtree pointers */ -static gint ett_docsis = -1; -static gint ett_ehdr = -1; -static gint ett_docsis_fragments = -1; -static gint ett_docsis_fragment = -1; -static gint ett_addr = -1; +static int ett_docsis; +static int ett_ehdr; +static int ett_docsis_fragments; +static int ett_docsis_fragment; +static int ett_addr; static const value_string fctype_vals[] = { {FCTYPE_PACKET, "Packet PDU"}, - {FCTYPE_RESERVED, "Reserved"}, + {FCTYPE_SPECIAL, "Special Use"}, {FCTYPE_ISOLAT, "Isolation PDU"}, {FCTYPE_MACSPC, "MAC Specific"}, {0, NULL} @@ -255,9 +255,9 @@ static const value_string unique_no_phs[] = { }; /* Fragmentation Flags / Sequence */ -static guint8 frag_flags; -static guint8 frag_seq; -static guint16 frag_sid; +static uint8_t frag_flags; +static uint8_t frag_seq; +static uint16_t frag_sid; /* * Defragmentation of DOCSIS @@ -285,24 +285,24 @@ static const fragment_items docsis_frag_items = { /* Dissection */ /* Code to Dissect the extended header; TLV Formatted headers */ static void -dissect_ehdr (tvbuff_t * tvb, proto_tree * tree, packet_info * pinfo, gboolean *is_encrypted) +dissect_ehdr (tvbuff_t * tvb, proto_tree * tree, packet_info * pinfo, bool *is_encrypted) { proto_tree *ehdr_tree; proto_item *eh_length_item; - gint ehdrlen; + int ehdrlen; int pos; - guint8 type; - guint8 len; + uint8_t type; + uint8_t len; - ehdrlen = tvb_get_guint8 (tvb, 1); + ehdrlen = tvb_get_uint8 (tvb, 1); pos = 4; ehdr_tree = proto_tree_add_subtree(tree, tvb, pos, ehdrlen, ett_ehdr, NULL, "Extended Header"); while (pos < ehdrlen + 4) { - type = (tvb_get_guint8 (tvb, pos) & 0xF0); - len = (tvb_get_guint8 (tvb, pos) & 0x0F); + type = (tvb_get_uint8 (tvb, pos) & 0xF0); + len = (tvb_get_uint8 (tvb, pos) & 0x0F); if ((((type >> 4) & 0x0F)== 6) && (len == 2)) { proto_tree_add_uint_format_value(ehdr_tree, hf_docsis_eh_type, tvb, pos, 1, 0x60, "Unsolicited Grant Sync EHDR Sub-Element"); @@ -354,19 +354,19 @@ dissect_ehdr (tvbuff_t * tvb, proto_tree * tree, packet_info * pinfo, gboolean * 1, ENC_BIG_ENDIAN); proto_tree_add_item (ehdr_tree, hf_docsis_sid, tvb, pos + 1, 2, ENC_BIG_ENDIAN); - frag_sid = tvb_get_guint8 (tvb, pos+1) & 0xCFFF; + frag_sid = tvb_get_uint8 (tvb, pos+1) & 0xCFFF; proto_tree_add_item (ehdr_tree, hf_docsis_mini_slots, tvb, pos + 3, 1, ENC_BIG_ENDIAN); if (pinfo->fragmented) { proto_tree_add_item (ehdr_tree, hf_docsis_frag_rsvd, tvb, pos+4, 1, ENC_BIG_ENDIAN); - frag_flags = tvb_get_guint8 (tvb, pos+4) & 0x30; + frag_flags = tvb_get_uint8 (tvb, pos+4) & 0x30; proto_tree_add_item (ehdr_tree, hf_docsis_frag_first, tvb, pos+4, 1, ENC_BIG_ENDIAN); proto_tree_add_item (ehdr_tree, hf_docsis_frag_last, tvb, pos+4, 1, ENC_BIG_ENDIAN); - frag_seq = tvb_get_guint8 (tvb, pos+4) & 0x0F; + frag_seq = tvb_get_uint8 (tvb, pos+4) & 0x0F; proto_tree_add_item (ehdr_tree, hf_docsis_frag_seq, tvb, pos+4, 1, ENC_BIG_ENDIAN); } @@ -440,7 +440,7 @@ dissect_ehdr (tvbuff_t * tvb, proto_tree * tree, packet_info * pinfo, gboolean * proto_tree_add_item(ehdr_tree, hf_docsis_ehx_type, tvb, pos, 1, ENC_NA); pos++; proto_tree_add_item(ehdr_tree, hf_docsis_ehx_len, tvb, pos, 1, ENC_NA); - len = tvb_get_guint8(tvb, pos); + len = tvb_get_uint8(tvb, pos); pos++; /* FALLTHROUGH */ default: @@ -455,31 +455,31 @@ dissect_ehdr (tvbuff_t * tvb, proto_tree * tree, packet_info * pinfo, gboolean * } /* Code to Dissect the Header Check Sequence field */ -/* Return FALSE in case FCS validation is enabled, but FCS is incorrect */ -/* Return TRUE in all other cases */ -static gboolean -dissect_hcs_field (tvbuff_t * tvb, packet_info * pinfo, proto_tree * docsis_tree, gint hdrlen) +/* Return false in case FCS validation is enabled, but FCS is incorrect */ +/* Return true in all other cases */ +static bool +dissect_hcs_field (tvbuff_t * tvb, packet_info * pinfo, proto_tree * docsis_tree, int hdrlen) { /* dissect the header check sequence */ if(docsis_check_fcs){ /* CRC-CCITT(16+12+5+1) */ - guint16 fcs = g_ntohs(crc16_ccitt_tvb(tvb, (hdrlen - 2))); + uint16_t fcs = g_ntohs(crc16_ccitt_tvb(tvb, (hdrlen - 2))); 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); - return (tvb_get_ntohs(tvb, (hdrlen - 2)) == fcs) ? TRUE : FALSE; + return (tvb_get_ntohs(tvb, (hdrlen - 2)) == fcs) ? true : false; } else { 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); } - return TRUE; + return true; } /* Code to Dissect the extended header length / MAC Param field and Length field */ /* The length field may condain a SID, but this logic is not handled here */ static void dissect_exthdr_length_field (tvbuff_t * tvb, packet_info * pinfo, proto_tree * docsis_tree, - guint8 exthdr, guint16 mac_parm, guint16 len_sid, guint16 *payload_length, gboolean *is_encrypted) + uint8_t exthdr, uint16_t mac_parm, uint16_t len_sid, uint16_t *payload_length, bool *is_encrypted) { proto_item *length_item; if (exthdr == EXT_HDR_ON) @@ -515,10 +515,10 @@ dissect_exthdr_length_field (tvbuff_t * tvb, packet_info * pinfo, proto_tree * d /* Print DST and SRC MACs and do not dissect the payload */ /* Implementation inferred from packet-eth.c */ static void -dissect_encrypted_frame (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, const guint8 fctype, const guint8 fcparm) +dissect_encrypted_frame (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, const uint8_t fctype, const uint8_t fcparm) { - guint32 offset, frame_len; - const guint8 *src_addr, *dst_addr; + uint32_t offset, frame_len; + const uint8_t *src_addr, *dst_addr; const char *src_addr_name, *dst_addr_name; proto_item *addr_item; proto_tree *addr_tree=NULL; @@ -586,26 +586,26 @@ dissect_encrypted_frame (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, static int dissect_docsis (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, void* data _U_) { - guint8 fc = 0; - guint8 fctype = 0; - guint8 fcparm = 0; - guint8 exthdr = 0; - guint16 mac_parm = 0; - guint8 hdrlen = DOCSIS_MIN_HEADER_LEN; - guint16 len_sid = 0; + uint8_t fc = 0; + uint8_t fctype = 0; + uint8_t fcparm = 0; + uint8_t exthdr = 0; + uint16_t mac_parm = 0; + uint8_t hdrlen = DOCSIS_MIN_HEADER_LEN; + uint16_t len_sid = 0; tvbuff_t *next_tvb = NULL; tvbuff_t *mgt_tvb = NULL; - gint pdulen = 0; - guint16 payload_length = 0; - /* guint16 framelen = 0; */ - gboolean save_fragmented; - gboolean is_encrypted = FALSE; - gboolean fcs_correct; + int pdulen = 0; + uint16_t payload_length = 0; + /* uint16_t framelen = 0; */ + bool save_fragmented; + bool is_encrypted = false; + bool fcs_correct; proto_item *ti; proto_tree *docsis_tree; /* Extract Frame Control parts */ - fc = tvb_get_guint8 (tvb, 0); /* Frame Control Byte */ + fc = tvb_get_uint8 (tvb, 0); /* Frame Control Byte */ fctype = (fc >> 6) & 0x03; /* Frame Control Type: 2 MSB Bits */ fcparm = (fc >> 1) & 0x1F; /* Frame Control Parameter: Next 5 Bits */ exthdr = (fc & 0x01); /* Extended Header Bit: LSB */ @@ -616,7 +616,7 @@ dissect_docsis (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, void* da len_sid = tvb_get_ntohs (tvb, 3); hdrlen = DOCSIS_MIN_HEADER_LEN + 1; // 7-byte header for this message type } else { - mac_parm = tvb_get_guint8 (tvb, 1); + mac_parm = tvb_get_uint8 (tvb, 1); len_sid = tvb_get_ntohs (tvb, 2); } @@ -651,8 +651,8 @@ dissect_docsis (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, void* da case FCTYPE_PACKET: col_set_str (pinfo->cinfo, COL_INFO, "Packet PDU"); break; - case FCTYPE_RESERVED: - col_set_str (pinfo->cinfo, COL_INFO, "Reserved PDU"); + case FCTYPE_SPECIAL: + col_set_str (pinfo->cinfo, COL_INFO, "Special Use"); break; case FCTYPE_ISOLAT: col_set_str (pinfo->cinfo, COL_INFO, "Isolation PDU"); @@ -702,20 +702,28 @@ dissect_docsis (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, void* da } break; } - case FCTYPE_RESERVED: + case FCTYPE_SPECIAL: { - proto_item_append_text (ti, " Reserved PDU"); - proto_tree_add_item (docsis_tree, hf_docsis_fcparm, tvb, 0, 1, ENC_BIG_ENDIAN); + proto_item_append_text (ti, " Special Use PDU"); + proto_tree_add_item (docsis_tree, hf_docsis_machdr_fcparm, tvb, 0, 1, ENC_BIG_ENDIAN); proto_tree_add_item (docsis_tree, hf_docsis_exthdr, tvb, 0, 1, ENC_BIG_ENDIAN); /* Dissect Length field for a PDU */ dissect_exthdr_length_field (tvb, pinfo, docsis_tree, exthdr, mac_parm, len_sid, &payload_length, &is_encrypted); /* Dissect Header Check Sequence field for a PDU */ fcs_correct = dissect_hcs_field (tvb, pinfo, docsis_tree, hdrlen); - if (fcs_correct) - { - /* Don't do anything for a Reserved Frame */ - next_tvb = tvb_new_subset_remaining(tvb, hdrlen); - call_data_dissector(next_tvb, pinfo, tree); + if (fcs_correct) { + if (fcparm == FCPARM_MAC_MGMT_HDR && exthdr == EXT_HDR_OFF) { + /* Pass off to the DOCSIS Management dissector/s */ + mgt_tvb = tvb_new_subset_remaining(tvb, hdrlen); + if (is_encrypted && !docsis_dissect_encrypted_frames) + dissect_encrypted_frame (mgt_tvb, pinfo, docsis_tree, fctype, fcparm); + else + call_dissector (docsis_mgmt_handle, mgt_tvb, pinfo, docsis_tree); + } else { + /* Don't do anything for a Reserved Frame */ + next_tvb = tvb_new_subset_remaining(tvb, hdrlen); + call_data_dissector(next_tvb, pinfo, tree); + } } break; } @@ -781,7 +789,7 @@ dissect_docsis (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, void* da { /* Check if this is a fragmentation header */ save_fragmented = pinfo->fragmented; - pinfo->fragmented = TRUE; + pinfo->fragmented = true; /* Dissect Length field for a PDU */ dissect_exthdr_length_field (tvb, pinfo, docsis_tree, exthdr, mac_parm, len_sid, &payload_length, &is_encrypted); @@ -790,8 +798,8 @@ dissect_docsis (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, void* da if (fcs_correct) { /* Grab the Fragment FCS */ - guint32 sent_fcs = tvb_get_ntohl(tvb, (hdrlen + len_sid - 4)); - guint32 fcs = crc32_802_tvb(tvb, tvb_captured_length(tvb) - 4); + uint32_t sent_fcs = tvb_get_ntohl(tvb, (hdrlen + len_sid - 4)); + uint32_t fcs = crc32_802_tvb(tvb, tvb_captured_length(tvb) - 4); /* Only defragment valid frames with a good FCS */ if (sent_fcs == fcs) @@ -809,9 +817,9 @@ dissect_docsis (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, void* da NULL, docsis_tree); if (frag_flags == FRAG_LAST) - pinfo->fragmented = FALSE; + pinfo->fragmented = false; else - pinfo->fragmented = TRUE; + pinfo->fragmented = true; if (frag_msg) { /* Reassembled */ proto_item_append_text (ti, " (Message Reassembled)"); @@ -1189,7 +1197,7 @@ proto_register_docsis (void) { &ei_docsis_eh_len, { "docsis.ehdr.len.past_end", PI_MALFORMED, PI_ERROR, "Extended Header Length Invalid!", EXPFILL }} }; - static gint *ett[] = { + static int *ett[] = { &ett_docsis, &ett_ehdr, &ett_docsis_fragment, |