From 4344b9108e356899a55368f1e7fa6974c9b50842 Mon Sep 17 00:00:00 2001 From: Cedric Roux Date: Thu, 14 Jan 2021 11:23:03 +0100 Subject: [PATCH 1/3] macpdu2wireshark: trace scheduling requests You need a recent version of wireshark for this to work properly. Successfully tested with 3.3.2. --- common/utils/T/T_messages.txt | 2 +- common/utils/T/tracer/macpdu2wireshark.c | 62 ++++++++++++++++++++---- common/utils/T/tracer/packet-mac-lte.h | 40 ++++++--------- 3 files changed, 68 insertions(+), 36 deletions(-) diff --git a/common/utils/T/T_messages.txt b/common/utils/T/T_messages.txt index 84fcdd55af..06ee5bf12b 100644 --- a/common/utils/T/T_messages.txt +++ b/common/utils/T/T_messages.txt @@ -129,7 +129,7 @@ ID = ENB_MAC_UE_DL_PDU_WITH_DATA FORMAT = int,eNB_ID : int,CC_id : int,rnti : int,frame : int,subframe : int,harq_pid : buffer,data ID = ENB_MAC_SCHEDULING_REQUEST DESC = MAC scheduling request detected for an UE - GROUP = ALL:MAC:ENB + GROUP = ALL:MAC:ENB:WIRESHARK FORMAT = int,eNB_ID : int,CC_id : int,frame : int,subframe : int,rnti ID = ENB_MAC_UE_DL_RAR_PDU_WITH_DATA DESC = MAC downlink PDU for an UE diff --git a/common/utils/T/tracer/macpdu2wireshark.c b/common/utils/T/tracer/macpdu2wireshark.c index d262f09e4a..ba961553d2 100644 --- a/common/utils/T/tracer/macpdu2wireshark.c +++ b/common/utils/T/tracer/macpdu2wireshark.c @@ -18,6 +18,7 @@ #define DEFAULT_LIVE_PORT 2021 #define NO_PREAMBLE -1 +#define NO_SR_RNTI -1 typedef struct { int socket; @@ -48,6 +49,10 @@ typedef struct { int rar_frame; int rar_subframe; int rar_data; + /* SR */ + int sr_rnti; + int sr_frame; + int sr_subframe; /* NR traces */ /* NR ul */ @@ -87,7 +92,8 @@ typedef struct { /****************************************************************************/ void trace_lte(ev_data *d, int direction, int rnti_type, int rnti, - int frame, int subframe, void *buf, int bufsize, int preamble) + int frame, int subframe, void *buf, int bufsize, int preamble, + int sr_rnti) { ssize_t ret; int fsf; @@ -118,6 +124,16 @@ void trace_lte(ev_data *d, int direction, int rnti_type, int rnti, PUTC(&d->buf, 0); /* rach attempt - always 0 for us (not sure of this) */ } + if (sr_rnti != NO_SR_RNTI) { + PUTC(&d->buf, MAC_LTE_SR_TAG); + PUTC(&d->buf, 0); /* number of items byte 1 */ + PUTC(&d->buf, 1); /* number of items byte 2 */ + PUTC(&d->buf, 0); /* ueid byte 1 (not used, let's put 0) */ + PUTC(&d->buf, 0); /* ueid byte 2 (not used, let's put 0) */ + PUTC(&d->buf, (sr_rnti>>8) & 255); + PUTC(&d->buf, sr_rnti & 255); + } + PUTC(&d->buf, MAC_LTE_PAYLOAD_TAG); for (i = 0; i < bufsize; i++) @@ -135,7 +151,7 @@ void ul(void *_d, event e) trace_lte(d, DIRECTION_UPLINK, C_RNTI, e.e[d->ul_rnti].i, e.e[d->ul_frame].i, e.e[d->ul_subframe].i, e.e[d->ul_data].b, e.e[d->ul_data].bsize, - NO_PREAMBLE); + NO_PREAMBLE, NO_SR_RNTI); } void dl(void *_d, event e) @@ -154,7 +170,7 @@ void dl(void *_d, event e) e.e[d->dl_rnti].i != 0xffff ? C_RNTI : SI_RNTI, e.e[d->dl_rnti].i, e.e[d->dl_frame].i, e.e[d->dl_subframe].i, e.e[d->dl_data].b, e.e[d->dl_data].bsize, - NO_PREAMBLE); + NO_PREAMBLE, NO_SR_RNTI); } void mib(void *_d, event e) @@ -169,7 +185,7 @@ void mib(void *_d, event e) trace_lte(d, DIRECTION_DOWNLINK, NO_RNTI, 0, e.e[d->mib_frame].i, e.e[d->mib_subframe].i, e.e[d->mib_data].b, e.e[d->mib_data].bsize, - NO_PREAMBLE); + NO_PREAMBLE, NO_SR_RNTI); } void preamble(void *_d, event e) @@ -178,7 +194,7 @@ void preamble(void *_d, event e) trace_lte(d, DIRECTION_UPLINK, NO_RNTI, 0, e.e[d->preamble_frame].i, e.e[d->preamble_subframe].i, NULL, 0, - e.e[d->preamble_preamble].i); + e.e[d->preamble_preamble].i, NO_SR_RNTI); } void rar(void *_d, event e) @@ -187,7 +203,16 @@ void rar(void *_d, event e) trace_lte(d, DIRECTION_DOWNLINK, RA_RNTI, e.e[d->rar_rnti].i, e.e[d->rar_frame].i, e.e[d->rar_subframe].i, e.e[d->rar_data].b, e.e[d->rar_data].bsize, - NO_PREAMBLE); + NO_PREAMBLE, NO_SR_RNTI); +} + +void sr(void *_d, event e) +{ + ev_data *d = _d; + trace_lte(d, DIRECTION_UPLINK, NO_RNTI, 0, + e.e[d->sr_frame].i, e.e[d->sr_subframe].i, + NULL, 0, + NO_PREAMBLE, e.e[d->sr_rnti].i); } /****************************************************************************/ @@ -298,7 +323,7 @@ void nr_rar(void *_d, event e) /****************************************************************************/ void setup_data(ev_data *d, void *database, int ul_id, int dl_id, int mib_id, - int preamble_id, int rar_id, + int preamble_id, int rar_id, int sr_id, int nr_ul_id, int nr_dl_id, int nr_mib_id, int nr_rar_id) { database_event_format f; @@ -321,6 +346,9 @@ void setup_data(ev_data *d, void *database, int ul_id, int dl_id, int mib_id, d->rar_frame = -1; d->rar_subframe = -1; d->rar_data = -1; + d->sr_rnti = -1; + d->sr_frame = -1; + d->sr_subframe = -1; d->nr_ul_rnti = -1; d->nr_ul_frame = -1; @@ -407,6 +435,18 @@ void setup_data(ev_data *d, void *database, int ul_id, int dl_id, int mib_id, if (d->rar_rnti == -1 || d->rar_frame == -1 || d->rar_subframe == -1 || d->rar_data == -1) goto error; + /* sr: rnti, frame, subframe */ + f = get_format(database, sr_id); + + for (i = 0; i < f.count; i++) { + G("rnti", "int", d->sr_rnti); + G("frame", "int", d->sr_frame); + G("subframe", "int", d->sr_subframe); + } + + if (d->sr_rnti == -1 || d->sr_frame == -1 || d->sr_subframe == -1) + goto error; + /* NR ul: rnti, frame, slot, data */ f = get_format(database, nr_ul_id); @@ -530,6 +570,7 @@ int main(int n, char **v) int i; int ul_id, dl_id, mib_id, preamble_id, rar_id; int nr_ul_id, nr_dl_id, nr_mib_id, nr_rar_id; + int sr_id; ev_data d; char *ip = DEFAULT_IP; int port = DEFAULT_PORT; @@ -599,6 +640,7 @@ int main(int n, char **v) on_off(database, "ENB_PHY_MIB", is_on, 1); on_off(database, "ENB_PHY_INITIATE_RA_PROCEDURE", is_on, 1); on_off(database, "ENB_MAC_UE_DL_RAR_PDU_WITH_DATA", is_on, 1); + on_off(database, "ENB_MAC_SCHEDULING_REQUEST", is_on, 1); on_off(database, "GNB_MAC_UL_PDU_WITH_DATA", is_on, 1); on_off(database, "GNB_MAC_DL_PDU_WITH_DATA", is_on, 1); @@ -621,13 +663,14 @@ int main(int n, char **v) mib_id = event_id_from_name(database, "ENB_PHY_MIB"); preamble_id = event_id_from_name(database, "ENB_PHY_INITIATE_RA_PROCEDURE"); rar_id = event_id_from_name(database, "ENB_MAC_UE_DL_RAR_PDU_WITH_DATA"); + sr_id = event_id_from_name(database, "ENB_MAC_SCHEDULING_REQUEST"); nr_ul_id = event_id_from_name(database, "GNB_MAC_UL_PDU_WITH_DATA"); nr_dl_id = event_id_from_name(database, "GNB_MAC_DL_PDU_WITH_DATA"); nr_mib_id = event_id_from_name(database, "GNB_PHY_MIB"); nr_rar_id = event_id_from_name(database, "GNB_MAC_DL_RAR_PDU_WITH_DATA"); - setup_data(&d, database, ul_id, dl_id, mib_id, preamble_id, rar_id, + setup_data(&d, database, ul_id, dl_id, mib_id, preamble_id, rar_id, sr_id, nr_ul_id, nr_dl_id, nr_mib_id, nr_rar_id); register_handler_function(h, ul_id, ul, &d); @@ -635,6 +678,7 @@ int main(int n, char **v) register_handler_function(h, mib_id, mib, &d); register_handler_function(h, preamble_id, preamble, &d); register_handler_function(h, rar_id, rar, &d); + register_handler_function(h, sr_id, sr, &d); register_handler_function(h, nr_ul_id, nr_ul, &d); register_handler_function(h, nr_dl_id, nr_dl, &d); @@ -662,7 +706,7 @@ int main(int n, char **v) if (e.type == -1) break; if (!(e.type == ul_id || e.type == dl_id || e.type == mib_id || - e.type == preamble_id || e.type == rar_id || + e.type == preamble_id || e.type == rar_id || e.type == sr_id || e.type == nr_ul_id || e.type == nr_dl_id || e.type == nr_mib_id || e.type == nr_rar_id)) continue; diff --git a/common/utils/T/tracer/packet-mac-lte.h b/common/utils/T/tracer/packet-mac-lte.h index 54e6d1a09b..60181987a9 100644 --- a/common/utils/T/tracer/packet-mac-lte.h +++ b/common/utils/T/tracer/packet-mac-lte.h @@ -11,26 +11,7 @@ * * Copyright (C) 2009 Martin Mathieson. All rights reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE + * SPDX-License-Identifier: BSD-2-Clause */ #ifndef __COMMON_UTILS_T_TRACER_PACKET_MAC_LTE__H__ @@ -67,9 +48,9 @@ /* and implemented by this dissector, using the definitions */ /* below. A link to an example program showing you how to encode */ /* these headers and send LTE MAC PDUs on a UDP socket is */ -/* provided at https://wiki.wireshark.org/MAC-LTE */ +/* provided at https://wiki.wireshark.org/MAC-LTE */ /* */ -/* A heuristic dissecter (enabled by a preference) will */ +/* A heuristic dissector (enabled by a preference) will */ /* recognise a signature at the beginning of these frames. */ /*****************************************************************/ @@ -126,18 +107,25 @@ MCS index (1 byte), redundancy version (1 byte), resource block length (1 byte), HARQ id (1 byte), NDI (1 byte), TB (1 byte), DL reTx (1 byte) */ -#define MAC_LTE_SIMULT_PUCCH_PUSCH_PCELL 0x0C +#define MAC_LTE_SIMULT_PUCCH_PUSCH_PCELL_TAG 0x0C /* 0 byte */ -#define MAC_LTE_SIMULT_PUCCH_PUSCH_PSCELL 0x0D +#define MAC_LTE_SIMULT_PUCCH_PUSCH_PSCELL_TAG 0x0D /* 0 byte */ -#define MAC_LTE_CE_MODE 0x0E +#define MAC_LTE_CE_MODE_TAG 0x0E /* 1 byte containing mac_lte_ce_mode enum value */ -#define MAC_LTE_NB_MODE 0x0F +#define MAC_LTE_NB_MODE_TAG 0x0F /* 1 byte containing mac_lte_nb_mode enum value */ +#define MAC_LTE_N_UL_RB_TAG 0x10 +/* 1 byte containing the number of UL resource blocks: 6, 15, 25, 50, 75 or 100 */ + +#define MAC_LTE_SR_TAG 0x11 +/* 2 bytes for the number of items, followed by that number of ueid, rnti (2 bytes each) */ + + /* MAC PDU. Following this tag comes the actual MAC PDU (there is no length, the PDU continues until the end of the frame) */ #define MAC_LTE_PAYLOAD_TAG 0x01 From 23b24a3c8a11c7a8a9feef622ea24e83e1854881 Mon Sep 17 00:00:00 2001 From: Cedric Roux Date: Thu, 21 Jan 2021 11:29:29 +0100 Subject: [PATCH 2/3] T tracer macpdu2wireshark: add UE id There was a problem with several UEs in the wireshark log. It seems that wireshark needs the UE id otherwise it gets confused and sees retransmissions where it's just another UE connecting and doing the same as a previous UE. Let's put kind of a UE id. Each RNTI seen by macpdu2wireshark gets an UE id assigned the first time it's seen in a trace. This is a bit hackish but seems to be fine. We could have added UE_id in all the traces, that is change the T() calls in the softmodem. It was less work to do it as it is, ie. only touch macpdu2wireshark.c. The RAR uses the same UE id all the time, may be a problem. To be refined if needed. --- common/utils/T/tracer/macpdu2wireshark.c | 39 ++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/common/utils/T/tracer/macpdu2wireshark.c b/common/utils/T/tracer/macpdu2wireshark.c index ba961553d2..f688e26806 100644 --- a/common/utils/T/tracer/macpdu2wireshark.c +++ b/common/utils/T/tracer/macpdu2wireshark.c @@ -85,6 +85,15 @@ typedef struct { /* runtime vars */ int cur_mib; int cur_sib; + + /* hack to report UE id: + * each time we see a rnti, we allocate the next ue_id + * (two separate versions for lte and nr) + */ + int lte_rnti_to_ueid[65536]; + int lte_next_ue_id; + int nr_rnti_to_ueid[65536]; + int nr_next_ue_id; } ev_data; /****************************************************************************/ @@ -108,6 +117,18 @@ void trace_lte(ev_data *d, int direction, int rnti_type, int rnti, PUTC(&d->buf, MAC_LTE_RNTI_TAG); PUTC(&d->buf, (rnti>>8) & 255); PUTC(&d->buf, rnti & 255); + + /* put UE id */ + if (rnti < 0 || rnti > 65535) { printf("bad rnti!\n"); exit(1); } + /* if no UE id allocated for this rnti then allocate the next one */ + if (d->lte_rnti_to_ueid[rnti] == -1) { + d->lte_rnti_to_ueid[rnti] = d->lte_next_ue_id; + d->lte_next_ue_id++; + } + + PUTC(&d->buf, MAC_LTE_UEID_TAG); + PUTC(&d->buf, (d->lte_rnti_to_ueid[rnti]>>8) & 255); + PUTC(&d->buf, d->lte_rnti_to_ueid[rnti] & 255); } /* for newer version of wireshark? */ @@ -223,6 +244,7 @@ void sr(void *_d, event e) #define MAC_NR_PAYLOAD_TAG 0x01 #define MAC_NR_RNTI_TAG 0x02 +#define MAC_NR_UEID_TAG 0x03 #define MAC_NR_FRAME_SLOT_TAG 0x07 #define NR_FDD_RADIO 1 @@ -250,6 +272,18 @@ void trace_nr(ev_data *d, int direction, int rnti_type, int rnti, PUTC(&d->buf, MAC_NR_RNTI_TAG); PUTC(&d->buf, (rnti>>8) & 255); PUTC(&d->buf, rnti & 255); + + /* put UE id */ + if (rnti < 0 || rnti > 65535) { printf("bad rnti!\n"); exit(1); } + /* if no UE id allocated for this rnti then allocate the next one */ + if (d->nr_rnti_to_ueid[rnti] == -1) { + d->nr_rnti_to_ueid[rnti] = d->nr_next_ue_id; + d->nr_next_ue_id++; + } + + PUTC(&d->buf, MAC_NR_UEID_TAG); + PUTC(&d->buf, (d->nr_rnti_to_ueid[rnti]>>8) & 255); + PUTC(&d->buf, d->nr_rnti_to_ueid[rnti] & 255); } #if 0 @@ -579,6 +613,11 @@ int main(int n, char **v) int live = 0; memset(&d, 0, sizeof(ev_data)); + for (i = 0; i < 65536; i++) { + d.lte_rnti_to_ueid[i] = -1; + d.nr_rnti_to_ueid[i] = -1; + } + for (i = 1; i < n; i++) { if (!strcmp(v[i], "-h") || !strcmp(v[i], "--help")) usage(); if (!strcmp(v[i], "-d")) { if(i>n-2)usage(); database_filename = v[++i]; continue; } From 40f985a95786c2c0c03a9262ec459518c86ad8a1 Mon Sep 17 00:00:00 2001 From: Cedric Roux Date: Thu, 21 Jan 2021 11:44:28 +0100 Subject: [PATCH 3/3] macpdu2wireshark: add UE id into scheduling request logging Same logic as previous commit, same caveats. --- common/utils/T/tracer/macpdu2wireshark.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/common/utils/T/tracer/macpdu2wireshark.c b/common/utils/T/tracer/macpdu2wireshark.c index f688e26806..d04f2c317d 100644 --- a/common/utils/T/tracer/macpdu2wireshark.c +++ b/common/utils/T/tracer/macpdu2wireshark.c @@ -149,8 +149,17 @@ void trace_lte(ev_data *d, int direction, int rnti_type, int rnti, PUTC(&d->buf, MAC_LTE_SR_TAG); PUTC(&d->buf, 0); /* number of items byte 1 */ PUTC(&d->buf, 1); /* number of items byte 2 */ - PUTC(&d->buf, 0); /* ueid byte 1 (not used, let's put 0) */ - PUTC(&d->buf, 0); /* ueid byte 2 (not used, let's put 0) */ + + /* put UE id */ + if (sr_rnti < 0 || sr_rnti > 65535) { printf("bad sr rnti!\n"); exit(1); } + /* if no UE id allocated for this rnti then allocate the next one */ + if (d->lte_rnti_to_ueid[sr_rnti] == -1) { + d->lte_rnti_to_ueid[sr_rnti] = d->lte_next_ue_id; + d->lte_next_ue_id++; + } + PUTC(&d->buf, (d->lte_rnti_to_ueid[sr_rnti]>>8) & 255); + PUTC(&d->buf, d->lte_rnti_to_ueid[sr_rnti] & 255); + PUTC(&d->buf, (sr_rnti>>8) & 255); PUTC(&d->buf, sr_rnti & 255); }