<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="../../assets/xml/rss.xsl" media="all"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>LaForge's home page (Posts about sim)</title><link>https://laforge.gnumonks.org/</link><description></description><atom:link href="https://laforge.gnumonks.org/blog/tags/sim.xml" rel="self" type="application/rss+xml"></atom:link><language>en</language><lastBuildDate>Thu, 24 Oct 2024 20:08:47 GMT</lastBuildDate><generator>Nikola (getnikola.com)</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>OsmoDevCall: "Osmocom SIMtrace2 Tutorial"</title><link>https://laforge.gnumonks.org/blog/20221019-osmodevcall-simtrace2_tutorial/</link><dc:creator>Harald Welte</dc:creator><description>&lt;p&gt;I've presented an
&lt;em&gt;SIMtrace2 Tutorial - SIM protocol tracing: how and why&lt;/em&gt;
as part of the
&lt;a class="reference external" href="https://osmocom.org/projects/osmo-dev-con/wiki/OsmoDevCall"&gt;OsmoDevCall&lt;/a&gt;
talk series on Osmocom and related technology.&lt;/p&gt;
&lt;p&gt;You can find the video recording at
&lt;a class="reference external" href="https://media.ccc.de/v/osmodevcall-20221019-laforge-simtrace2-tutorial"&gt;https://media.ccc.de/v/osmodevcall-20221019-laforge-simtrace2-tutorial&lt;/a&gt;&lt;/p&gt;</description><category>3gpp</category><category>osmocom</category><category>osmodevcall</category><category>sim</category><category>simtrace</category><guid>https://laforge.gnumonks.org/blog/20221019-osmodevcall-simtrace2_tutorial/</guid><pubDate>Tue, 18 Oct 2022 16:00:00 GMT</pubDate></item><item><title>OsmoDevCall: "Advanced SIM card topics: GlobalPlatform SCP02, OTA, ARA-M, ISIM"</title><link>https://laforge.gnumonks.org/blog/20220225-osmodevcall-advanced_sim_topics/</link><dc:creator>Harald Welte</dc:creator><description>&lt;p&gt;I've presented on
&lt;em&gt;Advanced SIM card topics: GlobalPlatform SCP02, OTA, ARA-M, ISIM&lt;/em&gt;
as part of the
&lt;a class="reference external" href="https://osmocom.org/projects/osmo-dev-con/wiki/OsmoDevCall"&gt;OsmoDevCall&lt;/a&gt;
talk series on Osmocom and related technology.&lt;/p&gt;
&lt;p&gt;You can find the video recording at
&lt;a class="reference external" href="https://media.ccc.de/v/osmodevcall-20220225-laforge-advanced-sim-topics"&gt;https://media.ccc.de/v/osmodevcall-20220225-laforge-advanced-sim-topics&lt;/a&gt;&lt;/p&gt;</description><category>3gpp</category><category>osmocom</category><category>osmodevcall</category><category>sim</category><category>simtrace</category><guid>https://laforge.gnumonks.org/blog/20220225-osmodevcall-advanced_sim_topics/</guid><pubDate>Thu, 24 Feb 2022 16:00:00 GMT</pubDate></item><item><title>OsmoDevCall: "SIM card profile creation, personalization, production"</title><link>https://laforge.gnumonks.org/blog/20211022-osmodevcall-sim_card_profile/</link><dc:creator>Harald Welte</dc:creator><description>&lt;p&gt;I've presented on
&lt;em&gt;SIM card profile creation, personalization, production&lt;/em&gt;
as part of the
&lt;a class="reference external" href="https://osmocom.org/projects/osmo-dev-con/wiki/OsmoDevCall"&gt;OsmoDevCall&lt;/a&gt;
talk series on Osmocom and related technology.&lt;/p&gt;
&lt;p&gt;You can find the video recording at
&lt;a class="reference external" href="https://media.ccc.de/v/osmodevcall-20211022-laforge-sim"&gt;https://media.ccc.de/v/osmodevcall-20211022-laforge-sim&lt;/a&gt;&lt;/p&gt;</description><category>osmocom</category><category>osmodevcall</category><category>sim</category><guid>https://laforge.gnumonks.org/blog/20211022-osmodevcall-sim_card_profile/</guid><pubDate>Thu, 11 Nov 2021 16:00:00 GMT</pubDate></item><item><title>OsmoDevCall: "osmo-remsim in practice"</title><link>https://laforge.gnumonks.org/blog/20210827-osmodevcall-osmo_remsim/</link><dc:creator>Harald Welte</dc:creator><description>&lt;p&gt;I've presented on
&lt;em&gt;osmo-remsim in practice&lt;/em&gt;
as part of the
&lt;a class="reference external" href="https://osmocom.org/projects/osmo-dev-con/wiki/OsmoDevCall"&gt;OsmoDevCall&lt;/a&gt;
talk series on Osmocom and related technology.&lt;/p&gt;
&lt;p&gt;You can find the video recording at
&lt;a class="reference external" href="https://media.ccc.de/v/osmodevcall-20210827-laforge-osmo-remsim"&gt;https://media.ccc.de/v/osmodevcall-20210827-laforge-osmo-remsim&lt;/a&gt;&lt;/p&gt;</description><category>osmocom</category><category>osmodevcall</category><category>sim</category><guid>https://laforge.gnumonks.org/blog/20210827-osmodevcall-osmo_remsim/</guid><pubDate>Thu, 26 Aug 2021 16:00:00 GMT</pubDate></item><item><title>OsmoDevCall: "pySim-shell - next generation SIM configuration tool"</title><link>https://laforge.gnumonks.org/blog/20210409-osmodevcall-pysim_shell/</link><dc:creator>Harald Welte</dc:creator><description>&lt;p&gt;I've presented a talk
&lt;em&gt;SS7 and SIGTRAN in 2G/3G networks&lt;/em&gt;
as part of the
&lt;a class="reference external" href="https://osmocom.org/projects/osmo-dev-con/wiki/OsmoDevCall"&gt;OsmoDevCall&lt;/a&gt;
talk series on Osmocom and related technology.&lt;/p&gt;
&lt;p&gt;You can find the video recording at
&lt;a class="reference external" href="https://media.ccc.de/v/osmodevcall-20210409-laforge-pysim-shell"&gt;https://media.ccc.de/v/osmodevcall-20210409-laforge-pysim-shell&lt;/a&gt;&lt;/p&gt;</description><category>osmocom</category><category>osmodevcall</category><category>sim</category><guid>https://laforge.gnumonks.org/blog/20210409-osmodevcall-pysim_shell/</guid><pubDate>Thu, 08 Apr 2021 16:00:00 GMT</pubDate></item><item><title>36C3 Talks on SIM card technology / Mitel DECT</title><link>https://laforge.gnumonks.org/blog/20200105-36c3-talks/</link><dc:creator>Harald Welte</dc:creator><description>&lt;p&gt;At &lt;a class="reference external" href="https://events.ccc.de/congress/2019"&gt;36C3&lt;/a&gt; in December 2019 I had
the pleasure of presenting: One full talk about &lt;a class="reference external" href="https://media.ccc.de/v/36c3-10737-sim_card_technology_from_a-z"&gt;SIM card technology from A to Z&lt;/a&gt;
and another talk where I presented together with eventphone team members
about &lt;a class="reference external" href="https://media.ccc.de/v/36c3-10576-mifail_oder_mit_gigaset_ware_das_nicht_passiert"&gt;Security issues in the Mitel SIP-DECT system&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The SIM card talk was surprisingly successful, both in terms of a full
audience on-site, as well as in terms of the number of viewers of the
recordings on media.ccc.de.   SIM cards are a rather niche topic in the
wider IT industry, and my talk was not covering any vulnerabilities or
the like.  Also, there was nothing novel in the talk: SIM cards have
been around for decades, and not much has changed (except maybe eSIM and
TLS) in recent years.&lt;/p&gt;
&lt;p&gt;In any case, I'm of course happy that it was well received.  So far I've
received lots of positive feedback.&lt;/p&gt;
&lt;p&gt;As I'm working [more than] full time in cellular technology for almost
15 years now, it's sometimes hard to imagine what kind of topics people
might be interested in.  If you have some kind of suggestion on what
kind of subject within my area of expertise you'd like me to talk about,
please don't hesitate to reach out.&lt;/p&gt;
&lt;p&gt;The Mitel DECT talk also went quite well.  I covered about 10 minutes of
technical details regarding the reverse engineering of the firmware and
the communication protocols of the device.  Thanks again to &lt;a class="reference external" href="http://mirider.com/"&gt;Dieter
Spaar&lt;/a&gt; for helping with that.  He is and remains
the best reverse engineer I have met, and it's always a privilege to
collaborate on any project.  It was of course also nice to see what
kind of useful (and/or fun) things the eventphone team have built on
top of the knowledge that was gained by protocol-level reverse
engineering.&lt;/p&gt;
&lt;p&gt;If you want to know more low-level technical detail than the 36C3 talk,
I recommend my &lt;a class="reference external" href="https://media.ccc.de/v/osmodevcon2019-100-aastra-mitel-dect-base-station-dissection"&gt;earlier talk at the OsmoDevCon 2019 about Aastra/Mitel
DET base station dissection&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;If only I had more time, I would love to work on improving the lack of
Free / Open Source Software realted to the DECT protocol family.
There's the abandoned &lt;a class="reference external" href="http://dedected.org/"&gt;deDECTed.org&lt;/a&gt;, and the
equally abandoned &lt;a class="reference external" href="http://dect.osmocom.org/"&gt;dect.osmocom.org&lt;/a&gt;
project.  The former only deals with the loewst levels of DECT
(PHY/MAC).  The latter is to a large extent implemented as part of an
ancient version of the Linux kernel (I would say this should all run in
userspace, like we run all of GSM/UMTS/LTE in userspace today).&lt;/p&gt;
&lt;p&gt;If anyone wants to help out, I still think working on the DECT DLC and
NWK dissectors for wireshark is the best way to start.  It will create a
tool that's important for anyone working with the DECT protocols, and it
will be more or less a requirement for development and debugging should
anyone ever go further in terms of implementing those protocols on
either the PP or FP side.  You can find my humble beginnings of the
related dissectors in the &lt;a class="reference external" href="https://git.osmocom.org/wireshark/log/?h=laforge/dect"&gt;laforge/dect branch of osmocom.org/wireshark.git&lt;/a&gt;.&lt;/p&gt;</description><category>ccc</category><category>dect</category><category>gsm</category><category>osmocom</category><category>sim</category><guid>https://laforge.gnumonks.org/blog/20200105-36c3-talks/</guid><pubDate>Sat, 04 Jan 2020 16:00:00 GMT</pubDate></item><item><title>Sometimes software development is a struggle</title><link>https://laforge.gnumonks.org/blog/20190929-development_is_hard/</link><dc:creator>Harald Welte</dc:creator><description>&lt;p&gt;I'm currently working on the firmware for a new project, an 8-slot smart
card reader.  I will share more about the architecture and design ideas
behind this project soon, but today I'll simply write about how hard it
sometimes is to actually get software development done. Seemingly trivial
things suddenly take ages.  I guess everyone writing code knows this, but
today I felt like I had to share this story.&lt;/p&gt;
&lt;section id="chapter-1-introduction"&gt;
&lt;h2&gt;Chapter 1 - Introduction&lt;/h2&gt;
&lt;p&gt;As I'm quite convinced of test-driven development these days, I don't
want to simply write firmware code that can only execute in the target,
but I'm actually working on a USB CCID (USb Class for Smart Card
readers) stack which is hardware-independent, and which can also run
entirely in userspace on a Linux device with USB gadget (device)
controller.  This way it's much easier to instrument, trace, introspect
and test the code base, and tests with actual target board hardware are
limited to those functions provided by the board.&lt;/p&gt;
&lt;p&gt;So the current architecture for development of the CCID implementation
looks like this:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;p&gt;Implement the USB CCID device using &lt;a class="reference external" href="https://www.kernel.org/doc/Documentation/usb/functionfs.txt"&gt;FunctionFS&lt;/a&gt;
(I did this some months ago, and in fact developing this was a similarly
much more time consuming task than expected, maybe I find time to expand on that)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Attach this USB gadget to a virtual USB bus + host controller using
the Linux kernel &lt;cite&gt;dummy_hcd&lt;/cite&gt; module&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Talk to a dumb &lt;cite&gt;phoenix&lt;/cite&gt; style serial SIM card reader attached to a
USB UART, which is connected to an actual SIM card (or any smart card,
for that matter)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;By using a "stupid" UART based smart card reader, I am very close to the
target environment on a Cortex-M microcntroller, where I also have to
talk to a UART and hence implement all the beauty of ISO 7816-3.  Hence,
the test / mock / development environment is as close as possible to the
target environment.&lt;/p&gt;
&lt;p&gt;So I implemented the various bits and pieces and ended up at a point
where I wanted to test.  And I'm not getting any response from the UART
/ SIM card at all.  I check all my code, add lots of debugging, play
around with various RTS / DTR / ... handshake settings (which sometimes
control power) - no avail.&lt;/p&gt;
&lt;p&gt;In the end, after many hours of trial + error I actually inserted a
different SIM card and finally, I got an ATR from the card.  In more
than 20 years of working with smart cards and SIM cards, this is the
first time I've actually seen a SIM card die in front of me, with no
response whatsoever from the card.&lt;/p&gt;
&lt;/section&gt;
&lt;section id="chapter-2-linux-is-broken"&gt;
&lt;h2&gt;Chapter 2 - Linux is broken&lt;/h2&gt;
&lt;p&gt;Anyway, the next step was to get the T=0 protocol of ISO 7816-3 going.
Since there is only one I/O line between SIM card and reader for both
directions, the protocol is a half-duplex protocol.  This is unlike
"normal" RS232-style UART communication, where you have a separate Rx
and Tx line.&lt;/p&gt;
&lt;p&gt;On the hardware side, this is most often implemented by simply
connecting both the Rx and Tx line of the UART to the SIM I/O pin.  This
in turn means that you're always getting an echo back for every byte you
write.&lt;/p&gt;
&lt;p&gt;One could discard such bytes, but then I'm targeting a microcontroller,
which should be running eight cards in parallel, at preferably
baud-rates up to ~1 megabit speeds, so having to read and discard all
those bytes seems like a big waste of resources.&lt;/p&gt;
&lt;p&gt;The obvious solution around that is to disable the receiver inside the
UART before you start transmitting, and re-enable it after you're done
transmitting.  This is typically done rather easily, as most UART
registers in hardware provide some way to selectively enable transmitter
and/or receiver independently.&lt;/p&gt;
&lt;p&gt;But since I'm working in Linux userspace in my development environment:
How do I approximate this kind of behavior?  At least the older readers
of this blog will remember something called the CREAD flag of &lt;a class="reference external" href="http://man7.org/linux/man-pages/man3/termios.3.html"&gt;termios&lt;/a&gt;.  Clearing that
flag will disable the receiver.  Back in the 1990ies, I did tons of work
with serial ports, and I remembered there was such a flag.&lt;/p&gt;
&lt;p&gt;So I implement my &lt;a class="reference external" href="http://git.osmocom.org/osmo-ccid-firmware/tree/ccid/cuart_driver_tty.c?h=laforge/fsm"&gt;userspace UART backend&lt;/a&gt;
and somehow it simply doesn't want to work.  Again of course I assume I
must be doing something wrong.  I'm using strace, I'm single-stepping
through code - no avail.&lt;/p&gt;
&lt;p&gt;In the end, it turns out that I've just found &lt;a class="reference external" href="https://bugzilla.kernel.org/show_bug.cgi?id=205033"&gt;a bug in the Linux kernel&lt;/a&gt;, one that appears
to be there at least ever since the git history of
linux-2.6.git started.  Almost all USB serial device drivers do not
implement CREAD, and there is no sotware fall-back implemented in the
core serial (or usb-serial) handling that would discard any received
bytes inside the kernel if CREAD is cleared.  Interestingly, the non-USB
serial drivers for classic UARTs attached to local bus, PCI, ... seem to
support it.&lt;/p&gt;
&lt;p&gt;The problem would be half as much of a problem if the syscall to clear
CREAD would actually fail with an error.  But no, it simply returns
success but bytes continue to be received from the UART/tty :/&lt;/p&gt;
&lt;p&gt;So that's the second big surprise of this weekend...&lt;/p&gt;
&lt;/section&gt;
&lt;section id="chapter-3-again-a-broken-card"&gt;
&lt;h2&gt;Chapter 3 - Again a broken card?&lt;/h2&gt;
&lt;p&gt;So I settle for implementing the 'receive as many characters as you
wrote' work-around.  Once that is done, I continue to test the code.
And what happens?  Somehow my state machine (implemented using &lt;a class="reference external" href="http://ftp.osmocom.org/api/latest/libosmocore/core/html/group__fsm.html#details"&gt;osmo-fsm&lt;/a&gt;,
of course) for reading the ATR (code found &lt;a class="reference external" href="http://git.osmocom.org/osmo-ccid-firmware/tree/ccid/iso7816_fsm.c?h=laforge/fsm#n469"&gt;here&lt;/a&gt;)
somehow never wants to complete.  The last byte of the ATR always is
missing.  How can that be?&lt;/p&gt;
&lt;p&gt;Well, guess what, the second SIM card I used is sending a broken,
non-spec compliant ATR where the header indicates 9 historical bytes are
present, but then in reality only 8 bytes are sent by the card.&lt;/p&gt;
&lt;p&gt;Of course every reader has a timeout at that point, but that timeout was
not yet implemented in my code, and I also wasn't expecting to hit that
timeout.&lt;/p&gt;
&lt;p&gt;So after using yet another SIM card (now a sysmoUSIM-SJS1, not sure why
I didn't even start with that one), it suddenly works.&lt;/p&gt;
&lt;p&gt;After a weekend of detours, each of which I would not have assumed at
all before, I finally have code that can obtain the ATR and exchange T=0
TPDUs with cards.  Of course I could have had that very easily if I
wanted (we do have code in pySim for this, e.g.) but not in the
architecture that is as close as it gets to the firmware environment of
the microcontroller of my target board.&lt;/p&gt;
&lt;/section&gt;</description><category>ccid</category><category>gsm</category><category>linux</category><category>octsim</category><category>osmocom</category><category>sim</category><category>usb</category><guid>https://laforge.gnumonks.org/blog/20190929-development_is_hard/</guid><pubDate>Sat, 28 Sep 2019 16:00:00 GMT</pubDate></item></channel></rss>