This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
laforge gerrit-no-reply at lists.osmocom.orglaforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/simtrace2/+/16631 )
Change subject: [lib] apdu_dispatch: Don't print APDU state to stdout
......................................................................
[lib] apdu_dispatch: Don't print APDU state to stdout
The printing was always only done at the end of osmo_apdu_segment_in(),
so let's leave the decision up to the user if he wants to print the
state at every iteration or not.
We now provide osmo_apdu_dump_context_buf() to the user so he can obtain
a string representation of the internal state for logging at any time he
requires.
Change-Id: Id3e3cf1605dec84077b158c1c5715f8eef2641d5
---
M host/include/osmocom/simtrace2/apdu_dispatch.h
M host/lib/apdu_dispatch.c
2 files changed, 16 insertions(+), 9 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/simtrace2 refs/changes/31/16631/1
diff --git a/host/include/osmocom/simtrace2/apdu_dispatch.h b/host/include/osmocom/simtrace2/apdu_dispatch.h
index af9c989..42a097a 100644
--- a/host/include/osmocom/simtrace2/apdu_dispatch.h
+++ b/host/include/osmocom/simtrace2/apdu_dispatch.h
@@ -1,6 +1,6 @@
/* apdu_dispatch - State machine to determine Rx/Tx phases of APDU
*
- * (C) 2016 by Harald Welte <hwelte at hmw-consulting.de>
+ * (C) 2016-2019 by Harald Welte <hwelte at hmw-consulting.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -44,6 +44,8 @@
APDU_ACT_RX_MORE_CAPDU_FROM_READER = 0x0002,
};
+const char *osmo_apdu_dump_context_buf(char *buf, unsigned int buf_len,
+ const struct osmo_apdu_context *ac);
int osmo_apdu_segment_in(struct osmo_apdu_context *ac, const uint8_t *apdu_buf,
unsigned int apdu_len, bool new_apdu);
diff --git a/host/lib/apdu_dispatch.c b/host/lib/apdu_dispatch.c
index 835b8bc..ec368b2 100644
--- a/host/lib/apdu_dispatch.c
+++ b/host/lib/apdu_dispatch.c
@@ -42,7 +42,7 @@
return (ac->le.tot == ac->le.cur);
}
-static const char *dump_apdu_hdr(const struct osim_apdu_cmd_hdr *h)
+static const char *stringify_apdu_hdr(const struct osim_apdu_cmd_hdr *h)
{
static char buf[256];
sprintf(buf, "CLA=%02x INS=%02x P1=%02x P2=%02x P3=%02x",
@@ -51,12 +51,19 @@
return buf;
}
-static void dump_apdu_ctx(const struct osmo_apdu_context *ac)
+/*! generate string representation of APDU context in specified output buffer.
+ * \param[in] buf output string buffer provided by caller
+ * \param[in] buf_len size of buf in bytes
+ * \param[in] ac APDU context to dump in buffer
+ * \returns pointer to buf on success */
+const char *osmo_apdu_dump_context_buf(char *buf, unsigned int buf_len,
+ const struct osmo_apdu_context *ac)
{
- printf("%s; case=%d, lc=%d(%d), le=%d(%d)\n",
- dump_apdu_hdr(&ac->hdr), ac->apdu_case,
- ac->lc.tot, ac->lc.cur,
- ac->le.tot, ac->le.cur);
+ snprintf(buf, buf_len, "%s; case=%d, lc=%d(%d), le=%d(%d)\n",
+ stringify_apdu_hdr(&ac->hdr), ac->apdu_case,
+ ac->lc.tot, ac->lc.cur,
+ ac->le.tot, ac->le.cur);
+ return buf;
}
/*! \brief input function for APDU segmentation
@@ -168,7 +175,5 @@
return -1;
}
- dump_apdu_ctx(ac);
-
return rc;
}
--
To view, visit https://gerrit.osmocom.org/c/simtrace2/+/16631
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: simtrace2
Gerrit-Branch: master
Gerrit-Change-Id: Id3e3cf1605dec84077b158c1c5715f8eef2641d5
Gerrit-Change-Number: 16631
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge at osmocom.org>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20191217/4afcfc7b/attachment.htm>