Commit 9a6d30d7 authored by Cedric Roux's avatar Cedric Roux

T: macpdu2wireshark: cleanup

- factorize
- harmonize
- simplify
parent 35a7e3a1
Pipeline #10850 passed with stage
in 0 seconds
......@@ -14,7 +14,10 @@
#define DEFAULT_IP "127.0.0.1"
#define DEFAULT_PORT 9999
#define NO_PREAMBLE -1
int no_sib = 0;
int no_mib = 0;
typedef struct {
int socket;
......@@ -45,9 +48,9 @@ typedef struct {
int rar_data;
} ev_data;
void ul(void *_d, event e)
void trace(ev_data *d, int direction, int rnti_type, int rnti,
int frame, int subframe, void *buf, int bufsize, int preamble)
{
ev_data *d = _d;
ssize_t ret;
int fsf;
int i;
......@@ -56,171 +59,88 @@ void ul(void *_d, event e)
PUTS(&d->buf, MAC_LTE_START_STRING);
PUTC(&d->buf, FDD_RADIO);
PUTC(&d->buf, DIRECTION_UPLINK);
PUTC(&d->buf, C_RNTI);
PUTC(&d->buf, direction);
PUTC(&d->buf, rnti_type);
PUTC(&d->buf, MAC_LTE_RNTI_TAG);
PUTC(&d->buf, (e.e[d->ul_rnti].i>>8) & 255);
PUTC(&d->buf, e.e[d->ul_rnti].i & 255);
if (rnti_type == C_RNTI || rnti_type == RA_RNTI) {
PUTC(&d->buf, MAC_LTE_RNTI_TAG);
PUTC(&d->buf, (rnti>>8) & 255);
PUTC(&d->buf, rnti & 255);
}
/* for newer version of wireshark? */
fsf = (e.e[d->ul_frame].i << 4) + e.e[d->ul_subframe].i;
fsf = (frame << 4) + subframe;
/* for older version? */
fsf = e.e[d->ul_subframe].i;
//fsf = subframe;
PUTC(&d->buf, MAC_LTE_FRAME_SUBFRAME_TAG);
PUTC(&d->buf, (fsf>>8) & 255);
PUTC(&d->buf, fsf & 255);
if (preamble != NO_PREAMBLE) {
PUTC(&d->buf, MAC_LTE_SEND_PREAMBLE_TAG);
PUTC(&d->buf, preamble);
PUTC(&d->buf, 0); /* rach attempt - always 0 for us (not sure of this) */
}
PUTC(&d->buf, MAC_LTE_PAYLOAD_TAG);
for (i = 0; i < e.e[d->ul_data].bsize; i++)
PUTC(&d->buf, ((char*)e.e[d->ul_data].b)[i]);
for (i = 0; i < bufsize; i++)
PUTC(&d->buf, ((char*)buf)[i]);
ret = sendto(d->socket, d->buf.obuf, d->buf.osize, 0,
(struct sockaddr *)&d->to, sizeof(struct sockaddr_in));
if (ret != d->buf.osize) abort();
}
void ul(void *_d, event e)
{
ev_data *d = _d;
trace(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);
}
void dl(void *_d, event e)
{
ev_data *d = _d;
ssize_t ret;
int fsf;
int i;
if (e.e[d->dl_rnti].i == 0xffff && no_sib) return;
d->buf.osize = 0;
PUTS(&d->buf, MAC_LTE_START_STRING);
PUTC(&d->buf, FDD_RADIO);
PUTC(&d->buf, DIRECTION_DOWNLINK);
if (e.e[d->dl_rnti].i != 0xffff) {
PUTC(&d->buf, C_RNTI);
PUTC(&d->buf, MAC_LTE_RNTI_TAG);
PUTC(&d->buf, (e.e[d->dl_rnti].i>>8) & 255);
PUTC(&d->buf, e.e[d->dl_rnti].i & 255);
} else {
PUTC(&d->buf, SI_RNTI);
}
/* for newer version of wireshark? */
fsf = (e.e[d->dl_frame].i << 4) + e.e[d->dl_subframe].i;
/* for older version? */
//fsf = e.e[d->dl_subframe].i;
PUTC(&d->buf, MAC_LTE_FRAME_SUBFRAME_TAG);
PUTC(&d->buf, (fsf>>8) & 255);
PUTC(&d->buf, fsf & 255);
PUTC(&d->buf, MAC_LTE_PAYLOAD_TAG);
for (i = 0; i < e.e[d->dl_data].bsize; i++)
PUTC(&d->buf, ((char*)e.e[d->dl_data].b)[i]);
ret = sendto(d->socket, d->buf.obuf, d->buf.osize, 0,
(struct sockaddr *)&d->to, sizeof(struct sockaddr_in));
if (ret != d->buf.osize) abort();
trace(d, DIRECTION_DOWNLINK,
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);
}
void mib(void *_d, event e)
{
ev_data *d = _d;
ssize_t ret;
int fsf;
int i;
d->buf.osize = 0;
PUTS(&d->buf, MAC_LTE_START_STRING);
PUTC(&d->buf, FDD_RADIO);
PUTC(&d->buf, DIRECTION_DOWNLINK);
PUTC(&d->buf, NO_RNTI);
/* for newer version of wireshark? */
fsf = (e.e[d->mib_frame].i << 4) + e.e[d->mib_subframe].i;
/* for older version? */
//fsf = e.e[d->mib_subframe].i;
PUTC(&d->buf, MAC_LTE_FRAME_SUBFRAME_TAG);
PUTC(&d->buf, (fsf>>8) & 255);
PUTC(&d->buf, fsf & 255);
PUTC(&d->buf, MAC_LTE_PAYLOAD_TAG);
for (i = 0; i < e.e[d->mib_data].bsize; i++)
PUTC(&d->buf, ((char*)e.e[d->mib_data].b)[i]);
if (no_mib) return;
ret = sendto(d->socket, d->buf.obuf, d->buf.osize, 0,
(struct sockaddr *)&d->to, sizeof(struct sockaddr_in));
if (ret != d->buf.osize) abort();
trace(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);
}
void preamble(void *_d, event e)
{
ev_data *d = _d;
ssize_t ret;
int fsf;
d->buf.osize = 0;
PUTS(&d->buf, MAC_LTE_START_STRING);
PUTC(&d->buf, FDD_RADIO);
PUTC(&d->buf, DIRECTION_UPLINK);
PUTC(&d->buf, NO_RNTI);
/* for newer version of wireshark? */
fsf = (e.e[d->preamble_frame].i << 4) + e.e[d->preamble_subframe].i;
/* for older version? */
//fsf = e.e[d->preamble_subframe].i;
PUTC(&d->buf, MAC_LTE_FRAME_SUBFRAME_TAG);
PUTC(&d->buf, (fsf>>8) & 255);
PUTC(&d->buf, fsf & 255);
PUTC(&d->buf, MAC_LTE_SEND_PREAMBLE_TAG);
PUTC(&d->buf, e.e[d->preamble_preamble].i);
PUTC(&d->buf, 0); /* rach attempt - always 0 for us (not sure of this) */
/* if we don't put this (even with no data) wireshark (2.4.5) is not happy */
PUTC(&d->buf, MAC_LTE_PAYLOAD_TAG);
ret = sendto(d->socket, d->buf.obuf, d->buf.osize, 0,
(struct sockaddr *)&d->to, sizeof(struct sockaddr_in));
if (ret != d->buf.osize) abort();
trace(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);
}
void rar(void *_d, event e)
{
ev_data *d = _d;
ssize_t ret;
int fsf;
int i;
if (e.e[d->rar_rnti].i == 0xffff && no_sib) return;
d->buf.osize = 0;
PUTS(&d->buf, MAC_LTE_START_STRING);
PUTC(&d->buf, FDD_RADIO);
PUTC(&d->buf, DIRECTION_DOWNLINK);
PUTC(&d->buf, RA_RNTI);
PUTC(&d->buf, MAC_LTE_RNTI_TAG);
PUTC(&d->buf, (e.e[d->rar_rnti].i>>8) & 255);
PUTC(&d->buf, e.e[d->rar_rnti].i & 255);
/* for newer version of wireshark? */
fsf = (e.e[d->rar_frame].i << 4) + e.e[d->rar_subframe].i;
/* for older version? */
//fsf = e.e[d->rar_subframe].i;
PUTC(&d->buf, MAC_LTE_FRAME_SUBFRAME_TAG);
PUTC(&d->buf, (fsf>>8) & 255);
PUTC(&d->buf, fsf & 255);
PUTC(&d->buf, MAC_LTE_PAYLOAD_TAG);
for (i = 0; i < e.e[d->rar_data].bsize; i++)
PUTC(&d->buf, ((char*)e.e[d->rar_data].b)[i]);
ret = sendto(d->socket, d->buf.obuf, d->buf.osize, 0,
(struct sockaddr *)&d->to, sizeof(struct sockaddr_in));
if (ret != d->buf.osize) abort();
trace(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);
}
void setup_data(ev_data *d, void *database, int ul_id, int dl_id, int mib_id,
......@@ -281,17 +201,15 @@ void setup_data(ev_data *d, void *database, int ul_id, int dl_id, int mib_id,
if (d->dl_rnti == -1 || d->dl_frame == -1 || d->dl_subframe == -1 ||
d->dl_data == -1) goto error;
if (mib_id != -1) {
/* MIB: frame, subframe, data */
f = get_format(database, mib_id);
for (i = 0; i < f.count; i++) {
G("frame", "int", d->mib_frame);
G("subframe", "int", d->mib_subframe);
G("data", "buffer", d->mib_data);
}
if (d->mib_frame == -1 || d->mib_subframe == -1 || d->mib_data == -1)
goto error;
/* MIB: frame, subframe, data */
f = get_format(database, mib_id);
for (i = 0; i < f.count; i++) {
G("frame", "int", d->mib_frame);
G("subframe", "int", d->mib_subframe);
G("data", "buffer", d->mib_data);
}
if (d->mib_frame == -1 || d->mib_subframe == -1 || d->mib_data == -1)
goto error;
/* preamble: frame, subframe, preamble */
f = get_format(database, preamble_id);
......@@ -370,7 +288,6 @@ int main(int n, char **v)
ev_data d;
char *ip = DEFAULT_IP;
int port = DEFAULT_PORT;
int do_mib = 1;
memset(&d, 0, sizeof(ev_data));
......@@ -382,7 +299,7 @@ int main(int n, char **v)
{ if (i > n-2) usage(); input_filename = v[++i]; continue; }
if (!strcmp(v[i], "-ip")) { if (i > n-2) usage(); ip = v[++i]; continue; }
if (!strcmp(v[i], "-p")) {if(i>n-2)usage(); port=atoi(v[++i]); continue; }
if (!strcmp(v[i], "-no-mib")) { do_mib = 0; continue; }
if (!strcmp(v[i], "-no-mib")) { no_mib = 1; continue; }
if (!strcmp(v[i], "-no-sib")) { no_sib = 1; continue; }
usage();
}
......@@ -407,14 +324,14 @@ int main(int n, char **v)
ul_id = event_id_from_name(database, "ENB_MAC_UE_UL_PDU_WITH_DATA");
dl_id = event_id_from_name(database, "ENB_MAC_UE_DL_PDU_WITH_DATA");
if (do_mib) mib_id = event_id_from_name(database, "ENB_PHY_MIB");
preamble_id=event_id_from_name(database, "ENB_PHY_INITIATE_RA_PROCEDURE");
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");
setup_data(&d, database, ul_id, dl_id, mib_id, preamble_id, rar_id);
register_handler_function(h, ul_id, ul, &d);
register_handler_function(h, dl_id, dl, &d);
if (do_mib) register_handler_function(h, mib_id, mib, &d);
register_handler_function(h, mib_id, mib, &d);
register_handler_function(h, preamble_id, preamble, &d);
register_handler_function(h, rar_id, rar, &d);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment