diff options
author | Pascal Quantin <pascal@wireshark.org> | 2019-06-16 14:45:58 +0200 |
---|---|---|
committer | Alexis La Goutte <alexis.lagoutte@gmail.com> | 2019-06-16 14:40:57 +0000 |
commit | c86c46ebafaa252089a4105b3eb4409cf5978827 (patch) | |
tree | c4b040691c88cfbd8c4cd34c74d74ed13257b4b3 /epan | |
parent | cde07b8ba370e631089f36c8199a5aa28d1f07e7 (diff) |
NAS 5GS: fix dissection of N1 Message Content
Change-Id: Ia93cc5a9d5adb46721775886744e7c8cf71fcd22
Reviewed-on: https://code.wireshark.org/review/33624
Reviewed-by: Pascal Quantin <pascal@wireshark.org>
Petri-Dish: Pascal Quantin <pascal@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
Diffstat (limited to 'epan')
-rw-r--r-- | epan/dissectors/packet-nas_5gs.c | 66 |
1 files changed, 65 insertions, 1 deletions
diff --git a/epan/dissectors/packet-nas_5gs.c b/epan/dissectors/packet-nas_5gs.c index 49e9a356fb..06edc04df8 100644 --- a/epan/dissectors/packet-nas_5gs.c +++ b/epan/dissectors/packet-nas_5gs.c @@ -19,9 +19,11 @@ #include <epan/proto_data.h> #include <wsutil/pow2.h> +#include <wsutil/wsjson.h> #include "packet-gsm_a_common.h" #include "packet-e212.h" +#include "packet-http.h" void proto_register_nas_5gs(void); void proto_reg_handoff_nas_5gs(void); @@ -36,11 +38,14 @@ static dissector_handle_t nas_5gs_handle = NULL; static dissector_handle_t eap_handle = NULL; static dissector_handle_t nas_eps_handle = NULL; static dissector_handle_t nas_eps_plain_handle = NULL; +static dissector_handle_t lpp_handle = NULL; #define PNAME "Non-Access-Stratum 5GS (NAS)PDU" #define PSNAME "NAS-5GS" #define PFNAME "nas-5gs" +static int proto_json = -1; + static int proto_nas_5gs = -1; int hf_nas_5gs_common_elem_id = -1; @@ -5626,6 +5631,63 @@ de_nas_5gs_s1_mode_to_n1_mode_nas_transparent_cont(tvbuff_t *tvb, proto_tree *tr } } +/* 3GPP TS 29.518 chapter 6.1.6.4.2 */ +static int +dissect_nas_5gs_media_type(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, void* data) +{ + int ret; + char *json_data; + const char *n1_msg_class, *str; + jsmntok_t *tokens, *cur_tok; + dissector_handle_t subdissector; + tvbuff_t* json_tvb = (tvbuff_t*)p_get_proto_data(pinfo->pool, pinfo, proto_json, 0); + http_message_info_t *message_info = (http_message_info_t *)data; + + if (!json_tvb || !message_info || !message_info->content_id) + return 0; + + json_data = tvb_get_string_enc(wmem_packet_scope(), json_tvb, 0, tvb_reported_length(json_tvb), ENC_UTF_8|ENC_NA); + ret = json_parse(json_data, NULL, 0); + if (ret < 0) + return 0; + tokens = wmem_alloc_array(wmem_packet_scope(), jsmntok_t, ret); + if (json_parse(json_data, tokens, ret) < 0) + return 0; + cur_tok = json_get_object(json_data, tokens, "n1MessageContainer"); + if (!cur_tok) + return 0; + n1_msg_class = json_get_string(json_data, cur_tok, "n1MessageClass"); + if (!n1_msg_class) + return 0; + cur_tok = json_get_object(json_data, cur_tok, "n1MessageContent"); + if (!cur_tok) + return 0; + str = json_get_string(json_data, cur_tok, "contentId"); + if (!str || strcmp(str, message_info->content_id)) + return 0; + if (!strcmp(n1_msg_class, "5GMM") || + !strcmp(n1_msg_class, "SM")) { + subdissector = nas_5gs_handle; + } else if (!strcmp(n1_msg_class, "LPP")) { + subdissector = lpp_handle; + } else if (!strcmp(n1_msg_class, "SMS")) { + /* how to know the direction? */ + subdissector = NULL; + } else if (!strcmp(n1_msg_class, "UPDP")) { + /* UD policy delivery service not dissected yet */ + subdissector = NULL; + } else { + subdissector = NULL; + } + + if (subdissector) { + call_dissector_with_data(subdissector, tvb, pinfo, tree, NULL); + return tvb_captured_length(tvb); + } else { + return 0; + } +} + void proto_register_nas_5gs(void) { @@ -7016,7 +7078,9 @@ proto_reg_handoff_nas_5gs(void) eap_handle = find_dissector("eap"); nas_eps_handle = find_dissector("nas-eps"); nas_eps_plain_handle = find_dissector("nas-eps_plain"); - dissector_add_string("media_type", "application/vnd.3gpp.5gnas", nas_5gs_handle); + lpp_handle = find_dissector("lpp"); + dissector_add_string("media_type", "application/vnd.3gpp.5gnas", create_dissector_handle(dissect_nas_5gs_media_type, proto_nas_5gs)); + proto_json = proto_get_id_by_filter_name("json"); } /* |