<div dir="ltr">Dean<br><br>Just noticed that you wanted the firmware.  So I am including the pre-compiled image in case you didn't want to recompile yourself.<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">

On Fri, Jan 24, 2014 at 11:24 AM, Min Xu <span dir="ltr"><<a href="mailto:mxu@sanjole.com" target="_blank">mxu@sanjole.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div dir="ltr"><div><div>It's incompatible because due to the way the USB peripheral transfer the data out to the host, there is NO mechanism to indicate exactly where the next USB transaction should start.  Therefore, when the data is flowing very fast, every 64 byte (the bus width) write to the USB peripheral will be concatenated together, resulting in the host read to combine multiple req_ctx buffers.<br>


<br>The way I solved it is by adding fields to the simtrace_hdr structure:  (the + indicates the new fields).  This allows me on the host to keep track if / where a new req_ctx begins in the received usb data.<br><br> struct simtrace_hdr {<br>


        u_int8_t cmd;<br>        u_int8_t flags;<br>        u_int8_t res[2];<br>+       u_int16_t seq_num;<br>+       u_int16_t offset;<br>+       u_int16_t tot_len;<br>        u_int8_t data[0];<br> } __attribute__ ((packed));<br>


<br><br></div>Since the laptop that I was using to create multiple commits is not available at the moment, I am attaching the   git  diff   from the repository (instead of from my last commits in previous email).  Meaning this is a single diff file.<br>


<br></div>For the host software, the basic change in the process_usb_msg function.  My implementation is a naive implementation using a much larger buffer to copy data to, where if a req_ctx is split across multiple usb transfers, it will join those fragments then process:<br>


<br>struct simtrace_hdr {<br>    u_int8_t cmd;<br>    u_int8_t flags;<br>    u_int8_t res[2];<br>    u_int16_t seq_num;<br>    u_int16_t offset;<br>    u_int16_t tot_len;<br>    u_int8_t data[0];<br>} /* __attribute__ ((packed)) */;<br>


<br>static char usb_buffer[66000];<br>static unsigned usb_remainder = 0;<br><br>int process_usb_msg(uint8_t *buf, int len) {<br>    struct simtrace_hdr *sh;<br>    uint8_t *payload;<br>    int payload_len, sh_offset, i;<br>


<br>    sendto(s, buf, len, 0, (struct sockaddr*)&destUSB, sizeof(struct sockaddr_in));<br><br>    memcpy(usb_buffer + usb_remainder, buf, len);<br>    len += usb_remainder;<br>    usb_remainder = len;<br>    sh_offset = 0;<br>


    sh = usb_buffer;<br>    payload = (char*)sh + sizeof(struct simtrace_hdr);<br>    payload_len = sh->tot_len - sizeof(struct simtrace_hdr);<br>    if (usb_remainder < sh->tot_len)<br>        sh = NULL;<br><br>


    while (sh) {<br>        switch (sh->cmd) {<br>            case SIMTRACE_MSGT_DATA:<br>                /* special treatment for ATR */<br>                if (sh->flags & SIMTRACE_FLAG_ATR) {<br>                    apdu_split_reset(as);<br>


                    break;<br>                }<br>                if (sh->flags & SIMTRACE_FLAG_PPS_FIDI) {<br>                    module_out("PPS(Fi=%u/Di=%u)\n",<br>                        sh->res[0], sh->res[1]);<br>


                }<br>                /* everything else goes into APDU splitter */<br>                apdu_split_in(as, payload, payload_len);<br>        #if 0<br>                /* If waiting time has expired, signal explicit boundary */<br>


                if (sh->flags & SIMTRACE_FLAG_WTIME_EXP)<br>                    apdu_split_boundary(as);<br>        #endif<br>                break;<br>            case SIMTRACE_MSGT_RESET:<br>            default:<br>


                module_out("unknown simtrace msg type 0x%02x\n", sh->cmd);<br>                break;<br>        }<br>        sh_offset += sh->tot_len;<br>        sh = usb_buffer + sh_offset;<br>        if (sh_offset < len) {<br>


            if (sh_offset + sh->tot_len > len) {<br>                memcpy(usb_buffer, sh, len - sh_offset);<br>                usb_remainder = len - sh_offset;<br>                sh = NULL;<br>            } else {<br>


                payload = (char*)sh + sizeof(struct simtrace_hdr);<br>                payload_len = sh->tot_len - sizeof(struct simtrace_hdr);<br>            }<br>        } else {<br>            sh = NULL;<br>            usb_remainder = 0;<br>


        }<br>    }<br>    return 0;<br>}<br><div><br><br><div><div><br></div></div></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Jan 24, 2014 at 11:06 AM, Dean Chester <span dir="ltr"><<a href="mailto:dean.g.chester@gmail.com" target="_blank">dean.g.chester@gmail.com</a>></span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div>Hi min,</div><div><br></div><div>How do you mean that they would be incompatible with early firmware based tracers? </div>


<div><br></div><div>I'd be interested in using your firmware if you were to make it available, I'm also working on a more user friendly host software. </div><div><br></div><div>Kind regards </div><div><br></div><div>


Dean Chester. <br><br>Sent from my iPad</div><div><div><div><br>On 24 Jan 2014, at 19:41, Min Xu <<a href="mailto:mxu@sanjole.com" target="_blank">mxu@sanjole.com</a>> wrote:<br><br></div><blockquote type="cite">
<div><div dir="ltr"><div>Hi Holger<br><br></div><div>To give you an update.  As far as I can tell, the changes I have submitted, with the addition of a change (on my local system) where the USB protocol has been modified to remove USB overrun, is stable so I can monitor iPhone 5S as well as Galaxy S4 continuously.  If anyone asks, I would be happy to send them the USB protocol changes.  However, it will be INCOMPATIBLE with earlier firmware based SIMTrace boards.<br>




<br></div><div>I am making changes to the host program (on Windows) to monitor multiple SIMTrace devices, and am interested to know if anyone else is working on something similar.  <br><br></div><div>Best Regards<br></div>




<div><div><br><br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Date: Wed, 22 Jan 2014 21:27:31 +0100<br>
From: Holger Hans Peter Freyther <<a href="mailto:holger@freyther.de" target="_blank">holger@freyther.de</a>><br>
To: Dean Chester <<a href="mailto:dean.g.chester@gmail.com" target="_blank">dean.g.chester@gmail.com</a>><br>
Cc: "<a href="mailto:simtrace@lists.osmocom.org" target="_blank">simtrace@lists.osmocom.org</a>" <<a href="mailto:simtrace@lists.osmocom.org" target="_blank">simtrace@lists.osmocom.org</a>><br>
Subject: Re: Fast SIM cards loosing bytes<br>
Message-ID: <<a href="mailto:20140122202731.GL15138@xiaoyu.lan" target="_blank">20140122202731.GL15138@xiaoyu.lan</a>><br>
Content-Type: text/plain; charset=us-ascii<br>
<br>
On Mon, Jan 13, 2014 at 08:35:05AM +0000, Dean Chester wrote:<br>
> Hi,<br>
><br>
> I see earlier in the archives that reducing the buffer size in the firmware will resolve this. Hasn't this already been done though in new releases of the firmware? As I have pulled the latest version from the openpcd git repo and built it. If not what have people reduced the buffer size to? And has it had any fixes?<br>





<br>
The closest are the patches that Min Xu sent. They require some<br>
clean-ups and review (specially the code changing the interrupt<br>
handling).<br>
<br>
holger<br>
<br>
<br>
<br>
------------------------------<br>
<br>
_______________________________________________<br>
simtrace mailing list<br>
<a href="mailto:simtrace@lists.osmocom.org" target="_blank">simtrace@lists.osmocom.org</a><br>
<a href="https://lists.osmocom.org/mailman/listinfo/simtrace" target="_blank">https://lists.osmocom.org/mailman/listinfo/simtrace</a><br>
<br>
<br>
End of simtrace Digest, Vol 33, Issue 4<br>
***************************************<br>
</blockquote></div><br></div></div></div></div>
</div></blockquote></div></div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>