laforge has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/simtrace2/+/27000 )


Change subject: simtrace2-cardem-pcsc: Move all logging into libosmocore
......................................................................

simtrace2-cardem-pcsc: Move all logging into libosmocore

* drop log statements that are already in libosmo-simtrace2
* don't printf directly, but go via LOGCI
* make LOGCI use libosmocore logging
* configure libosmocore logging in a 'convenient' way

Change-Id: I6fa0da966e6d8e723c187404c17e90cfb3f3dd9f
---
M host/src/simtrace2-cardem-pcsc.c
1 file changed, 26 insertions(+), 13 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/simtrace2 refs/changes/00/27000/1

diff --git a/host/src/simtrace2-cardem-pcsc.c b/host/src/simtrace2-cardem-pcsc.c
index 19ed94e..807df72 100644
--- a/host/src/simtrace2-cardem-pcsc.c
+++ b/host/src/simtrace2-cardem-pcsc.c
@@ -1,7 +1,7 @@
 /* simtrace2-cardem-pcsc - main program for the host PC to provide a remote SIM
  * using the SIMtrace 2 firmware in card emulation mode
  *
- * (C) 2016-2021 by Harald Welte <[email protected]>
+ * (C) 2016-2022 by Harald Welte <[email protected]>
  * (C) 2018, sysmocom -s.f.m.c. GmbH, Author: Kevin Redon <[email protected]>
  *
  * This program is free software; you can redistribute it and/or
@@ -49,7 +49,7 @@
 #include <osmocom/sim/class_tables.h>
 #include <osmocom/sim/sim.h>

-#define LOGCI(ci, lvl, fmt, args ...) printf(fmt, ## args)
+#define LOGCI(ci, lvl, fmt, args ...) LOGP(DLGLOBAL, lvl,  fmt, ## args)

 static void atr_update_csum(uint8_t *atr, unsigned int atr_len)
 {
@@ -93,6 +93,17 @@
        last_status_flags = flags;
 }

+static const char *cemu_data_flags2str(uint32_t flags)
+{
+       static char out[64];
+       snprintf(out, sizeof(out), "%s%s%s%s",
+                flags & CEMU_DATA_F_TPDU_HDR ? "HDR " : "",
+                flags & CEMU_DATA_F_FINAL ? "FINAL " : "",
+                flags & CEMU_DATA_F_PB_AND_TX ? "PB_AND_TX " : "",
+                flags & CEMU_DATA_F_PB_AND_RX ? "PB_AND_RX" : "");
+       return out;
+}
+
 /***********************************************************************
  * Incoming Messages
  ***********************************************************************/
@@ -104,7 +115,7 @@
        char fbuf[80];

        cemu_status_flags2str(fbuf, sizeof(fbuf), status->flags);
-       printf("=> STATUS: flags=0x%x, fi=%u, di=%u, wi=%u wtime=%u (%s)\n",
+       LOGCI(ci, LOGL_NOTICE, "=> STATUS: flags=0x%x, fi=%u, di=%u, wi=%u 
wtime=%u (%s)\n",
                status->flags, status->fi, status->di, status->wi,
                status->waiting_time, fbuf);

@@ -119,7 +130,7 @@
        struct cardemu_usb_msg_pts_info *pts;
        pts = (struct cardemu_usb_msg_pts_info *) buf;

-       printf("=> PTS req: %s\n", osmo_hexdump(pts->req, sizeof(pts->req)));
+       LOGCI(ci, LOGL_NOTICE, "=> PTS req: %s\n", osmo_hexdump(pts->req, 
pts->pts_len));

        return 0;
 }
@@ -133,8 +144,8 @@

        data = (struct cardemu_usb_msg_rx_data *) buf;

-       printf("=> DATA: flags=%x, %s: ", data->flags,
-               osmo_hexdump(data->data, data->data_len));
+       LOGCI(ci, LOGL_INFO, "=> DATA: flags=0x%02x (%s), %s\n ", data->flags,
+             cemu_data_flags2str(data->flags), osmo_hexdump(data->data, 
data->data_len));

        rc = osmo_apdu_segment_in(&ac, data->data, data->data_len,
                                  data->flags & CEMU_DATA_F_TPDU_HDR);
@@ -163,7 +174,6 @@
                msgb_apdu_sw(tmsg) = msgb_get_u16(tmsg);
                ac.sw[0] = msgb_apdu_sw(tmsg) >> 8;
                ac.sw[1] = msgb_apdu_sw(tmsg) & 0xff;
-               printf("SW=0x%04x, len_rx=%d\n", msgb_apdu_sw(tmsg), 
msgb_l3len(tmsg));
                if (msgb_l3len(tmsg))
                        osmo_st2_cardem_request_pb_and_tx(ci, ac.hdr.ins, 
tmsg->l3h, msgb_l3len(tmsg));
                osmo_st2_cardem_request_sw_tx(ci, ac.sw);
@@ -179,8 +189,6 @@
        struct simtrace_msg_hdr *sh = (struct simtrace_msg_hdr *)buf;
        int rc;

-       printf("-> %s\n", osmo_hexdump(buf, len));
-
        buf += sizeof(*sh);

        switch (sh->msg_type) {
@@ -213,7 +221,7 @@
        char fbuf[80];

        cemu_status_flags2str(fbuf, sizeof(fbuf), status->flags);
-       LOGCI(ci, LOGL_INFO, "=> IRQ STATUS: flags=0x%x, fi=%u, di=%u, wi=%u 
wtime=%u (%s)\n",
+       LOGCI(ci, LOGL_NOTICE, "=> IRQ STATUS: flags=0x%x, fi=%u, di=%u, wi=%u 
wtime=%u (%s)\n",
                status->flags, status->fi, status->di, status->wi,
                status->waiting_time, fbuf);

@@ -227,8 +235,6 @@
        struct simtrace_msg_hdr *sh = (struct simtrace_msg_hdr *)buf;
        int rc;

-       LOGCI(ci, LOGL_INFO, "SIMtrace IRQ %s\n", osmo_hexdump(buf, len));
-
        buf += sizeof(*sh);

        switch (sh->msg_type) {
@@ -351,7 +357,7 @@
 static void print_welcome(void)
 {
        printf("simtrace2-cardem-pcsc - Using PC/SC reader as SIM\n"
-              "(C) 2010-2020, Harald Welte <[email protected]>\n"
+              "(C) 2010-2022, Harald Welte <[email protected]>\n"
               "(C) 2018, sysmocom -s.f.m.c. GmbH, Author: Kevin Redon 
<[email protected]>\n\n");
 }

@@ -454,6 +460,13 @@
        }

        osmo_init_logging2(NULL, &log_info);
+       log_set_print_category_hex(osmo_stderr_target, false);
+       log_set_print_category(osmo_stderr_target, true);
+       log_set_print_level(osmo_stderr_target, true);
+       log_set_print_filename_pos(osmo_stderr_target, 
LOG_FILENAME_POS_LINE_END);
+       log_set_print_filename2(osmo_stderr_target, LOG_FILENAME_NONE);
+       log_set_category_filter(osmo_stderr_target, DLINP, 1, LOGL_DEBUG);
+       log_set_category_filter(osmo_stderr_target, DLGLOBAL, 1, LOGL_DEBUG);

        while (1) {
                int option_index = 0;

--
To view, visit https://gerrit.osmocom.org/c/simtrace2/+/27000
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: simtrace2
Gerrit-Branch: master
Gerrit-Change-Id: I6fa0da966e6d8e723c187404c17e90cfb3f3dd9f
Gerrit-Change-Number: 27000
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <[email protected]>
Gerrit-MessageType: newchange

Reply via email to