<p>laforge has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/c/simtrace2/+/16631">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">[lib] apdu_dispatch: Don't print APDU state to stdout<br><br>The printing was always only done at the end of osmo_apdu_segment_in(),<br>so let's leave the decision up to the user if he wants to print the<br>state at every iteration or not.<br><br>We now provide osmo_apdu_dump_context_buf() to the user so he can obtain<br>a string representation of the internal state for logging at any time he<br>requires.<br><br>Change-Id: Id3e3cf1605dec84077b158c1c5715f8eef2641d5<br>---<br>M host/include/osmocom/simtrace2/apdu_dispatch.h<br>M host/lib/apdu_dispatch.c<br>2 files changed, 16 insertions(+), 9 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/simtrace2 refs/changes/31/16631/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/host/include/osmocom/simtrace2/apdu_dispatch.h b/host/include/osmocom/simtrace2/apdu_dispatch.h</span><br><span>index af9c989..42a097a 100644</span><br><span>--- a/host/include/osmocom/simtrace2/apdu_dispatch.h</span><br><span>+++ b/host/include/osmocom/simtrace2/apdu_dispatch.h</span><br><span>@@ -1,6 +1,6 @@</span><br><span> /* apdu_dispatch - State machine to determine Rx/Tx phases of APDU</span><br><span>  *</span><br><span style="color: hsl(0, 100%, 40%);">- * (C) 2016 by Harald Welte <hwelte@hmw-consulting.de></span><br><span style="color: hsl(120, 100%, 40%);">+ * (C) 2016-2019 by Harald Welte <hwelte@hmw-consulting.de></span><br><span>  *</span><br><span>  * This program is free software; you can redistribute it and/or</span><br><span>  * modify it under the terms of the GNU General Public License</span><br><span>@@ -44,6 +44,8 @@</span><br><span>        APDU_ACT_RX_MORE_CAPDU_FROM_READER      = 0x0002,</span><br><span> };</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+const char *osmo_apdu_dump_context_buf(char *buf, unsigned int buf_len,</span><br><span style="color: hsl(120, 100%, 40%);">+                                  const struct osmo_apdu_context *ac);</span><br><span> </span><br><span> int osmo_apdu_segment_in(struct osmo_apdu_context *ac, const uint8_t *apdu_buf,</span><br><span>                   unsigned int apdu_len, bool new_apdu);</span><br><span>diff --git a/host/lib/apdu_dispatch.c b/host/lib/apdu_dispatch.c</span><br><span>index 835b8bc..ec368b2 100644</span><br><span>--- a/host/lib/apdu_dispatch.c</span><br><span>+++ b/host/lib/apdu_dispatch.c</span><br><span>@@ -42,7 +42,7 @@</span><br><span>     return (ac->le.tot == ac->le.cur);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-static const char *dump_apdu_hdr(const struct osim_apdu_cmd_hdr *h)</span><br><span style="color: hsl(120, 100%, 40%);">+static const char *stringify_apdu_hdr(const struct osim_apdu_cmd_hdr *h)</span><br><span> {</span><br><span>  static char buf[256];</span><br><span>        sprintf(buf, "CLA=%02x INS=%02x P1=%02x P2=%02x P3=%02x",</span><br><span>@@ -51,12 +51,19 @@</span><br><span>    return buf;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-static void dump_apdu_ctx(const struct osmo_apdu_context *ac)</span><br><span style="color: hsl(120, 100%, 40%);">+/*! generate string representation of APDU context in specified output buffer.</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] buf output string buffer provided by caller</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] buf_len size of buf in bytes</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] ac APDU context to dump in buffer</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \returns pointer to buf on success */</span><br><span style="color: hsl(120, 100%, 40%);">+const char *osmo_apdu_dump_context_buf(char *buf, unsigned int buf_len,</span><br><span style="color: hsl(120, 100%, 40%);">+                                     const struct osmo_apdu_context *ac)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">- printf("%s; case=%d, lc=%d(%d), le=%d(%d)\n",</span><br><span style="color: hsl(0, 100%, 40%);">-         dump_apdu_hdr(&ac->hdr), ac->apdu_case,</span><br><span style="color: hsl(0, 100%, 40%);">-               ac->lc.tot, ac->lc.cur,</span><br><span style="color: hsl(0, 100%, 40%);">-           ac->le.tot, ac->le.cur);</span><br><span style="color: hsl(120, 100%, 40%);">+        snprintf(buf, buf_len, "%s; case=%d, lc=%d(%d), le=%d(%d)\n",</span><br><span style="color: hsl(120, 100%, 40%);">+                stringify_apdu_hdr(&ac->hdr), ac->apdu_case,</span><br><span style="color: hsl(120, 100%, 40%);">+                ac->lc.tot, ac->lc.cur,</span><br><span style="color: hsl(120, 100%, 40%);">+                 ac->le.tot, ac->le.cur);</span><br><span style="color: hsl(120, 100%, 40%);">+       return buf;</span><br><span> }</span><br><span> </span><br><span> /*! \brief input function for APDU segmentation</span><br><span>@@ -168,7 +175,5 @@</span><br><span>                return -1;</span><br><span>   }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   dump_apdu_ctx(ac);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span>   return rc;</span><br><span> }</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/simtrace2/+/16631">change 16631</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/c/simtrace2/+/16631"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: simtrace2 </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: Id3e3cf1605dec84077b158c1c5715f8eef2641d5 </div>
<div style="display:none"> Gerrit-Change-Number: 16631 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: laforge <laforge@osmocom.org> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>