Wireshark-dev: [Wireshark-dev] [PATCH] packet-gsmtap.c: handling LTE RRC and MAC messages
From: altaf sk <altaf329@xxxxxxxxx>
Date: Mon, 19 Jan 2015 11:04:46 +0100
Hello

Here is a patch to the packet-gsmtap.c  that

1. can handle LTE RRC messages and call respective dissectors

2. can handle LTE MAC frames, fill in the struct mac_lte_info and then call the mac-lte dissector. Following the GSMTAP header, there is a 15 byte mac_info which is needed to fill the struct mac_lte_info. Following this mac_info is the MAC payload (frame).

The size mac_info need not necessarily be 15 byte. But these 15 bytes are necessary for the lte-mac dissector to understand the frame. 15 byte header is used by the LTE_FDD_EnodeB application from the openLTE project.

The corresponding gsmtap.h file is patched on the libosmocore directory.

Please let me know your comments.


Best Regards,

Altaf

From b415a41a8a39f8271234d4d4c7f9c896e0575b5d Mon Sep 17 00:00:00 2001
From: altaf <altaf329@xxxxxxxxx>
Date: Mon, 12 Jan 2015 14:38:01 +0100
Subject: [PATCH] dissector handles for LTE RRC messages and LTE MAC frames

formatting

formatting

format
---
 epan/dissectors/packet-gsmtap.c | 76 +++++++++++++++++++++++++++++++++++++++--
 1 file changed, 73 insertions(+), 3 deletions(-)

diff --git a/epan/dissectors/packet-gsmtap.c b/epan/dissectors/packet-gsmtap.c
index 19e34d9..62a9076 100644
--- a/epan/dissectors/packet-gsmtap.c
+++ b/epan/dissectors/packet-gsmtap.c
@@ -43,6 +43,7 @@
 #include <epan/packet.h>
 
 #include "packet-tetra.h"
+#include "packet-mac-lte.h"
 
 void proto_register_gsmtap(void);
 void proto_reg_handoff_gsmtap(void);
@@ -72,6 +73,8 @@ void proto_reg_handoff_gsmtap(void);
 #define GSMTAP_TYPE_GMR1_UM				0x0a	/* GMR-1 L2 packets */
 #define GSMTAP_TYPE_UMTS_RLC_MAC	0x0b
 #define GSMTAP_TYPE_UMTS_RRC		0x0c
+#define GSMTAP_TYPE_LTE_RRC			0x0d	/* LTE interface */
+#define GSMTAP_TYPE_LTE_MAC			0x0e	/* LTE interface */
 
 /* ====== DO NOT MAKE UNAPPROVED MODIFICATIONS HERE ===== */
 #define GSMTAP_BURST_UNKNOWN		0x00
@@ -229,6 +232,9 @@ enum {
 	/* UMTS */
 	GSMTAP_SUB_UMTS_RLC_MAC,
 	GSMTAP_SUB_UMTS_RRC,
+		/* LTE*/
+	GSMTAP_SUB_LTE_RRC,
+	GSMTAP_SUB_LTE_MAC,
 
 	GSMTAP_SUB_MAX
 };
@@ -299,9 +305,23 @@ enum {
 
 	GSMTAP_RRC_SUB_MAX
 };
+/* LTE RRC message types */
+enum {
+	GSMTAP_LTE_RRC_SUB_DL_CCCH_Message = 0,
+	GSMTAP_LTE_RRC_SUB_DL_DCCH_Message,
+	GSMTAP_LTE_RRC_SUB_UL_CCCH_Message,
+	GSMTAP_LTE_RRC_SUB_UL_DCCH_Message,
+	GSMTAP_LTE_RRC_SUB_BCCH_BCH_Message,
+	GSMTAP_LTE_RRC_SUB_BCCH_DL_SCH_Message,
+	GSMTAP_LTE_RRC_SUB_PCCH_Message,
+	GSMTAP_LTE_RRC_SUB_MCCH_Message,
+
+	GSMTAP_LTE_RRC_SUB_MAX
+};
 
 static dissector_handle_t sub_handles[GSMTAP_SUB_MAX];
 static dissector_handle_t rrc_sub_handles[GSMTAP_RRC_SUB_MAX];
+static dissector_handle_t lte_rrc_sub_handles[GSMTAP_LTE_RRC_SUB_MAX];
 
 static dissector_table_t gsmtap_dissector_table;
 
@@ -421,6 +441,8 @@ static const value_string gsmtap_types[] = {
 	{ GSMTAP_TYPE_GMR1_UM, "GMR-1 air interfeace (MES-MS<->GTS)" },
 	{ GSMTAP_TYPE_UMTS_RLC_MAC,	"UMTS RLC/MAC" },
 	{ GSMTAP_TYPE_UMTS_RRC,		"UMTS RRC" },
+	{ GSMTAP_TYPE_UMTS_RRC,		"LTE RRC" },
+	{ GSMTAP_TYPE_UMTS_RRC,		"LTE MAC" },
 	{ 0,			NULL },
 };
 
@@ -463,15 +485,35 @@ handle_tetra(int channel _U_, tvbuff_t *payload_tvb _U_, packet_info *pinfo _U_,
 	tetra_dissect_pdu(tetra_chan, TETRA_DOWNLINK, payload_tvb, tree, pinfo);
 }
 
+static void
+attach_mac_lte_info(tvbuff_t *lte_mac_info_tvb, int len, guint8 gsmtap_hdr_len, packet_info *pinfo)
+{
+	struct mac_lte_info *p_mac_lte_info;
+	guint8 lte_mac_info_len = 15;
+	int offset = 0;
+
+	p_mac_lte_info = get_mac_lte_proto_data(pinfo);
+	p_mac_lte_info = wmem_new0(wmem_file_scope(), struct mac_lte_info);
+	p_mac_lte_info->radioType = tvb_get_guint8(lte_mac_info_tvb, offset);
+	p_mac_lte_info->direction = tvb_get_guint8(lte_mac_info_tvb, offset+1);
+	p_mac_lte_info->rntiType = tvb_get_guint8(lte_mac_info_tvb, offset+2);
+	p_mac_lte_info->rnti = tvb_get_ntohs(lte_mac_info_tvb, offset+4);
+	p_mac_lte_info->ueid = tvb_get_ntohs(lte_mac_info_tvb, offset+7);
+	p_mac_lte_info->subframeNumber = tvb_get_ntohs(lte_mac_info_tvb, offset+10);
+	p_mac_lte_info->length = len - (gsmtap_hdr_len + lte_mac_info_len);
+
+	set_mac_lte_proto_data(pinfo, p_mac_lte_info);
+}
+
 /* dissect a GSMTAP header and hand payload off to respective dissector */
 static void
 dissect_gsmtap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 {
-	int sub_handle, rrc_sub_handle = 0, len, offset = 0;
+	int sub_handle, rrc_sub_handle = 0, lte_rrc_sub_handle = 0, len, offset = 0;
 	proto_item *ti;
 	proto_tree *gsmtap_tree = NULL;
-	tvbuff_t *payload_tvb, *l1h_tvb = NULL;
-	guint8 hdr_len, type, sub_type, timeslot, subslot;
+	tvbuff_t *payload_tvb, *l1h_tvb = NULL, *lte_mac_info_tvb=NULL;
+	guint8 hdr_len, type, sub_type, timeslot, subslot, lte_mac_info_len = 15;
 	guint16 arfcn;
 
 	len = tvb_reported_length(tvb);
@@ -489,6 +531,9 @@ dissect_gsmtap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 	    sub_type & GSMTAP_CHANNEL_ACCH) {
 		l1h_tvb = tvb_new_subset_length(tvb, hdr_len, 2);
 		payload_tvb = tvb_new_subset_length(tvb, hdr_len+2, len-(hdr_len+2));
+	} else if (type == GSMTAP_TYPE_LTE_MAC) {
+		lte_mac_info_tvb = tvb_new_subset_length(tvb, hdr_len, lte_mac_info_len);
+		payload_tvb = tvb_new_subset_length(tvb, hdr_len+lte_mac_info_len, len - (hdr_len + lte_mac_info_len));
 	} else {
 		payload_tvb = tvb_new_subset_length(tvb, hdr_len, len-hdr_len);
 	}
@@ -604,6 +649,18 @@ dissect_gsmtap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 		 * sub-dissector */
 		col_set_str(pinfo->cinfo, COL_PROTOCOL, "RRC");
 		break;
+	case GSMTAP_TYPE_LTE_RRC:
+		sub_handle = GSMTAP_SUB_LTE_RRC;
+		lte_rrc_sub_handle = sub_type;
+		if (lte_rrc_sub_handle >= GSMTAP_LTE_RRC_SUB_MAX) {
+			sub_handle = GSMTAP_SUB_DATA;
+		}
+		/*Directly call the respective lte rrc message dissector */
+		break;
+	case GSMTAP_TYPE_LTE_MAC:
+		attach_mac_lte_info(lte_mac_info_tvb, len, hdr_len, pinfo);
+		sub_handle=GSMTAP_SUB_LTE_MAC;
+		break;
 	case GSMTAP_TYPE_UM:
 		if (l1h_tvb)
 			dissect_sacch_l1h(l1h_tvb, tree);
@@ -712,6 +769,9 @@ dissect_gsmtap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 	if (sub_handle == GSMTAP_SUB_UMTS_RRC)
 		call_dissector(rrc_sub_handles[rrc_sub_handle], payload_tvb,
 			       pinfo, tree);
+	else if (sub_handle == GSMTAP_SUB_LTE_RRC)
+		call_dissector(lte_rrc_sub_handles[lte_rrc_sub_handle], payload_tvb,
+			       pinfo, tree);
 	else if (sub_handles[sub_handle] != NULL)
 		call_dissector(sub_handles[sub_handle], payload_tvb, pinfo, tree);
 	/* TODO: warn user that the WiMAX plugin must be enabled for some types */
@@ -803,6 +863,7 @@ proto_reg_handoff_gsmtap(void)
 	sub_handles[GSMTAP_SUB_GMR1_LAPSAT] = find_dissector("lapsat");
 	sub_handles[GSMTAP_SUB_GMR1_RACH] = find_dissector("gmr1_rach");
 	sub_handles[GSMTAP_SUB_UMTS_RRC] = find_dissector("rrc");
+	sub_handles[GSMTAP_SUB_LTE_MAC] = find_dissector("mac-lte");
 
 	rrc_sub_handles[GSMTAP_RRC_SUB_DL_DCCH_Message] = find_dissector("rrc.dl.dcch");
 	rrc_sub_handles[GSMTAP_RRC_SUB_UL_DCCH_Message] = find_dissector("rrc.ul.dcch");
@@ -867,6 +928,15 @@ proto_reg_handoff_gsmtap(void)
 	rrc_sub_handles[GSMTAP_RRC_SUB_ToTargetRNC_Container] = find_dissector("rrc.s_to_trnc_cont");
 	rrc_sub_handles[GSMTAP_RRC_SUB_TargetRNC_ToSourceRNC_Container] = find_dissector("rrc.t_to_srnc_cont");
 
+	lte_rrc_sub_handles[GSMTAP_LTE_RRC_SUB_DL_CCCH_Message] = find_dissector("lte_rrc.dl_ccch");
+	lte_rrc_sub_handles[GSMTAP_LTE_RRC_SUB_DL_DCCH_Message] = find_dissector("lte_rrc.dl_dcch");
+	lte_rrc_sub_handles[GSMTAP_LTE_RRC_SUB_UL_CCCH_Message] = find_dissector("lte_rrc.ul_ccch");
+	lte_rrc_sub_handles[GSMTAP_LTE_RRC_SUB_UL_DCCH_Message] = find_dissector("lte_rrc.ul_dcch");
+	lte_rrc_sub_handles[GSMTAP_LTE_RRC_SUB_BCCH_BCH_Message] = find_dissector("lte_rrc.bcch_bch");
+	lte_rrc_sub_handles[GSMTAP_LTE_RRC_SUB_BCCH_DL_SCH_Message] = find_dissector("lte_rrc.bcch_dl_sch");
+	lte_rrc_sub_handles[GSMTAP_LTE_RRC_SUB_PCCH_Message] = find_dissector("lte_rrc.pcch");
+	lte_rrc_sub_handles[GSMTAP_LTE_RRC_SUB_MCCH_Message] = find_dissector("lte_rrc.mcch");
+
 	gsmtap_handle = create_dissector_handle(dissect_gsmtap, proto_gsmtap);
 	dissector_add_uint("udp.port", GSMTAP_UDP_PORT, gsmtap_handle);
 }
-- 
1.9.1