diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 20:34:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 20:34:10 +0000 |
commit | e4ba6dbc3f1e76890b22773807ea37fe8fa2b1bc (patch) | |
tree | 68cb5ef9081156392f1dd62a00c6ccc1451b93df /epan/dissectors/asn1/h450/packet-h450-template.c | |
parent | Initial commit. (diff) | |
download | wireshark-e4ba6dbc3f1e76890b22773807ea37fe8fa2b1bc.tar.xz wireshark-e4ba6dbc3f1e76890b22773807ea37fe8fa2b1bc.zip |
Adding upstream version 4.2.2.upstream/4.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'epan/dissectors/asn1/h450/packet-h450-template.c')
-rw-r--r-- | epan/dissectors/asn1/h450/packet-h450-template.c | 312 |
1 files changed, 312 insertions, 0 deletions
diff --git a/epan/dissectors/asn1/h450/packet-h450-template.c b/epan/dissectors/asn1/h450/packet-h450-template.c new file mode 100644 index 00000000..b9a72714 --- /dev/null +++ b/epan/dissectors/asn1/h450/packet-h450-template.c @@ -0,0 +1,312 @@ +/* packet-h450.c + * Routines for h450 packet dissection + * Based on the previous h450 dissector by: + * 2003 Graeme Reid (graeme.reid@norwoodsystems.com) + * Copyright 2005, Anders Broman <anders.broman@ericsson.com> + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * SPDX-License-Identifier: GPL-2.0-or-later + * + * Credit to Tomas Kukosa for developing the asn2wrs compiler. + * + */ + +#include "config.h" + +#include <epan/packet.h> +#include <epan/expert.h> + +#include <epan/asn1.h> + +#include "packet-per.h" +#include "packet-h225.h" + +#include "packet-h450-ros.h" + +#define PNAME "H.450 Supplementary Services" +#define PSNAME "H.450" +#define PFNAME "h450" + +void proto_register_h450(void); +void proto_reg_handoff_h450(void); + +static dissector_handle_t h450_arg_handle; +static dissector_handle_t h450_res_handle; +static dissector_handle_t h450_err_handle; + +/* Initialize the protocol and registered fields */ +static int proto_h450 = -1; +static int hf_h450_operation = -1; +static int hf_h450_error = -1; +#include "packet-h450-hf.c" + +/* Initialize the subtree pointers */ +#include "packet-h450-ett.c" + +static expert_field ei_h450_unsupported_arg_type = EI_INIT; +static expert_field ei_h450_unsupported_result_type = EI_INIT; +static expert_field ei_h450_unsupported_error_type = EI_INIT; + +static const value_string h450_str_operation[] = { +#include "packet-h450-table10.c" + { 0, NULL} +}; + +static const value_string h450_str_error[] = { +#include "packet-h450-table20.c" + { 0, NULL} +}; + +/* ROSE context */ +static rose_ctx_t h450_rose_ctx; + +/* Global variables */ + +#include "packet-h450-fn.c" + +typedef struct _h450_op_t { + gint32 opcode; + dissector_t arg_pdu; + dissector_t res_pdu; +} h450_op_t; + +static const h450_op_t h450_op_tab[] = { +#include "packet-h450-table11.c" +}; + +typedef struct _h450_err_t { + gint32 errcode; + dissector_t err_pdu; +} h450_err_t; + +static const h450_err_t h450_err_tab[] = { +#include "packet-h450-table21.c" +}; + +static const h450_op_t *get_op(gint32 opcode) { + int i; + + /* search from the end to get the last occurrence if the operation is redefined in some newer specification */ + for (i = array_length(h450_op_tab) - 1; i >= 0; i--) + if (h450_op_tab[i].opcode == opcode) + return &h450_op_tab[i]; + return NULL; +} + +static const h450_err_t *get_err(gint32 errcode) { + int i; + + /* search from the end to get the last occurrence if the operation is redefined in some newer specification */ + for (i = array_length(h450_err_tab) - 1; i >= 0; i--) + if (h450_err_tab[i].errcode == errcode) + return &h450_err_tab[i]; + return NULL; +} + +/*--- dissect_h450_arg ------------------------------------------------------*/ +static int +dissect_h450_arg(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) { + proto_item *hidden_item; + int offset = 0; + rose_ctx_t *rctx; + gint32 opcode; + const h450_op_t *op_ptr; + const gchar *p; + + /* Reject the packet if data is NULL */ + if (data == NULL) + return 0; + rctx = get_rose_ctx(data); + DISSECTOR_ASSERT(rctx); + + if (rctx->d.pdu != 1) /* invoke */ + return offset; + if (rctx->d.code != 0) /* local */ + return offset; + opcode = rctx->d.code_local; + op_ptr = get_op(opcode); + if (!op_ptr) + return offset; + + hidden_item = proto_tree_add_uint(tree, hf_h450_operation, tvb, 0, 0, opcode); + proto_item_set_hidden(hidden_item); + p = try_val_to_str(opcode, VALS(h450_str_operation)); + if (p) { + proto_item_append_text(rctx->d.code_item, " - %s", p); + if (rctx->apdu_depth >= 0) + proto_item_append_text(proto_item_get_parent_nth(proto_tree_get_parent(tree), rctx->apdu_depth), " %s", p); + } + + if (op_ptr->arg_pdu && (tvb_reported_length_remaining(tvb, offset) > 0)) + offset = op_ptr->arg_pdu(tvb, pinfo, tree, NULL); + else + if (tvb_reported_length_remaining(tvb, offset) > 0) { + proto_tree_add_expert(tree, pinfo, &ei_h450_unsupported_arg_type, tvb, offset, -1); + offset += tvb_reported_length_remaining(tvb, offset); + } + + return offset; +} + +/*--- dissect_h450_res ------------------------------------------------------*/ +static int +dissect_h450_res(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) { + proto_item *hidden_item; + int offset = 0; + rose_ctx_t *rctx; + gint32 opcode; + const h450_op_t *op_ptr; + const gchar *p; + + /* Reject the packet if data is NULL */ + if (data == NULL) + return 0; + rctx = get_rose_ctx(data); + DISSECTOR_ASSERT(rctx); + + if (rctx->d.pdu != 2) /* returnResult */ + return offset; + if (rctx->d.code != 0) /* local */ + return offset; + opcode = rctx->d.code_local; + op_ptr = get_op(opcode); + if (!op_ptr) + return offset; + + hidden_item = proto_tree_add_uint(tree, hf_h450_operation, tvb, 0, 0, opcode); + proto_item_set_hidden(hidden_item); + p = try_val_to_str(opcode, VALS(h450_str_operation)); + if (p) { + proto_item_append_text(rctx->d.code_item, " - %s", p); + if (rctx->apdu_depth >= 0) + proto_item_append_text(proto_item_get_parent_nth(proto_tree_get_parent(tree), rctx->apdu_depth), " %s", p); + } + + if (op_ptr->res_pdu && (tvb_reported_length_remaining(tvb, offset) > 0)) + offset = op_ptr->res_pdu(tvb, pinfo, tree, NULL); + else + if (tvb_reported_length_remaining(tvb, offset) > 0) { + proto_tree_add_expert(tree, pinfo, &ei_h450_unsupported_result_type, tvb, offset, -1); + offset += tvb_reported_length_remaining(tvb, offset); + } + + return offset; +} + +/*--- dissect_h450_err ------------------------------------------------------*/ +static int +dissect_h450_err(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) { + proto_item *hidden_item; + int offset = 0; + rose_ctx_t *rctx; + gint32 errcode; + const h450_err_t *err_ptr; + const gchar *p; + + /* Reject the packet if data is NULL */ + if (data == NULL) + return 0; + rctx = get_rose_ctx(data); + DISSECTOR_ASSERT(rctx); + + if (rctx->d.pdu != 3) /* returnError */ + return offset; + if (rctx->d.code != 0) /* local */ + return offset; + errcode = rctx->d.code_local; + err_ptr = get_err(errcode); + if (!err_ptr) + return offset; + + hidden_item = proto_tree_add_uint(tree, hf_h450_error, tvb, 0, 0, errcode); + proto_item_set_hidden(hidden_item); + p = try_val_to_str(errcode, VALS(h450_str_error)); + if (p) { + proto_item_append_text(rctx->d.code_item, " - %s", p); + if (rctx->apdu_depth >= 0) + proto_item_append_text(proto_item_get_parent_nth(proto_tree_get_parent(tree), rctx->apdu_depth), " %s", p); + } + + if (err_ptr->err_pdu && (tvb_reported_length_remaining(tvb, offset) > 0)) + offset = err_ptr->err_pdu(tvb, pinfo, tree, NULL); + else + if (tvb_reported_length_remaining(tvb, offset) > 0) { + proto_tree_add_expert(tree, pinfo, &ei_h450_unsupported_error_type, tvb, offset, -1); + offset += tvb_reported_length_remaining(tvb, offset); + } + + return offset; +} + +/*--- proto_register_h450 -------------------------------------------*/ +void proto_register_h450(void) { + + /* List of fields */ + static hf_register_info hf[] = { + { &hf_h450_operation, { "Operation", "h450.operation", + FT_UINT8, BASE_DEC, VALS(h450_str_operation), 0x0, + NULL, HFILL }}, + { &hf_h450_error, { "Error", "h450.error", + FT_UINT16, BASE_DEC, VALS(h450_str_error), 0x0, + NULL, HFILL }}, +#include "packet-h450-hfarr.c" + }; + + /* List of subtrees */ + static gint *ett[] = { +#include "packet-h450-ettarr.c" + }; + + static ei_register_info ei[] = { + { &ei_h450_unsupported_arg_type, { "h450.unsupported.arg_type", PI_UNDECODED, PI_WARN, "UNSUPPORTED ARGUMENT TYPE (H.450)", EXPFILL }}, + { &ei_h450_unsupported_result_type, { "h450.unsupported.result_type", PI_UNDECODED, PI_WARN, "UNSUPPORTED RESULT TYPE (H.450)", EXPFILL }}, + { &ei_h450_unsupported_error_type, { "h450.unsupported.error_type", PI_UNDECODED, PI_WARN, "UNSUPPORTED ERROR TYPE (H.450)", EXPFILL }}, + }; + + expert_module_t* expert_h450; + + /* Register protocol */ + proto_h450 = proto_register_protocol(PNAME, PSNAME, PFNAME); + register_dissector("h4501", dissect_h450_H4501SupplementaryService_PDU, proto_h450); + /* Register fields and subtrees */ + proto_register_field_array(proto_h450, hf, array_length(hf)); + proto_register_subtree_array(ett, array_length(ett)); + expert_h450 = expert_register_protocol(proto_h450); + expert_register_field_array(expert_h450, ei, array_length(ei)); + + rose_ctx_init(&h450_rose_ctx); + + /* Register dissectors */ + h450_arg_handle = register_dissector("h4501_arg", dissect_h450_arg, proto_h450); + h450_res_handle = register_dissector("h4501_res", dissect_h450_res, proto_h450); + h450_err_handle = register_dissector("h4501_err", dissect_h450_err, proto_h450); + + /* Register dissector tables */ + h450_rose_ctx.arg_global_dissector_table = register_dissector_table("h450.ros.global.arg", "H.450 Operation Argument (global opcode)", proto_h450, FT_STRING, STRING_CASE_SENSITIVE); + h450_rose_ctx.res_global_dissector_table = register_dissector_table("h450.ros.global.res", "H.450 Operation Result (global opcode)", proto_h450, FT_STRING, STRING_CASE_SENSITIVE); + h450_rose_ctx.arg_local_dissector_table = register_dissector_table("h450.ros.local.arg", "H.450 Operation Argument (local opcode)", proto_h450, FT_UINT32, BASE_HEX); + h450_rose_ctx.res_local_dissector_table = register_dissector_table("h450.ros.local.res", "H.450 Operation Result (local opcode)", proto_h450, FT_UINT32, BASE_HEX); + h450_rose_ctx.err_global_dissector_table = register_dissector_table("h450.ros.global.err", "H.450 Error (global opcode)", proto_h450, FT_STRING, STRING_CASE_SENSITIVE); + h450_rose_ctx.err_local_dissector_table = register_dissector_table("h450.ros.local.err", "H.450 Error (local opcode)", proto_h450, FT_UINT32, BASE_HEX); + +} + + +/*--- proto_reg_handoff_h450 ---------------------------------------*/ +void +proto_reg_handoff_h450(void) +{ + int i; + + for (i=0; i<(int)array_length(h450_op_tab); i++) { + dissector_add_uint("h450.ros.local.arg", h450_op_tab[i].opcode, h450_arg_handle); + dissector_add_uint("h450.ros.local.res", h450_op_tab[i].opcode, h450_res_handle); + } + for (i=0; i<(int)array_length(h450_err_tab); i++) { + dissector_add_uint("h450.ros.local.err", h450_err_tab[i].errcode, h450_err_handle); + } + +} |