<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.9.0">Jekyll</generator><link href="http://antoinealb.net/feed.xml" rel="self" type="application/atom+xml" /><link href="http://antoinealb.net/" rel="alternate" type="text/html" /><updated>2021-11-23T21:02:08+00:00</updated><id>http://antoinealb.net/feed.xml</id><title type="html">[ antoinealb.net ]</title><subtitle>A blog about robotics, embedded software and Linux. Also doubles as my personal wiki</subtitle><author><name>Antoine Albertelli</name><email>antoinea101@gmail.com</email></author><entry><title type="html">Automatically restarting an IKEA TRÅDFRI gateway</title><link href="http://antoinealb.net/2019/08/10/automatically-rebooting-tradfri-gateway.html" rel="alternate" type="text/html" title="Automatically restarting an IKEA TRÅDFRI gateway" /><published>2019-08-10T00:00:00+00:00</published><updated>2019-08-10T00:00:00+00:00</updated><id>http://antoinealb.net/2019/08/10/automatically-rebooting-tradfri-gateway</id><content type="html" xml:base="http://antoinealb.net/2019/08/10/automatically-rebooting-tradfri-gateway.html">&lt;p&gt;So I got myself a set of connected light bulbs for my living room.
Based on review, I decided to go with the IKEA models, as they are pretty inexpensive and provide good quality lighting.
I also decided to have a gateway, which allows you to control your lamps from your LAN and provide additional functions like lamp groups.
The gateway also offers an API so I figured it could be a fun thing to hack with.&lt;/p&gt;

&lt;p&gt;In the beginning, everything seemed fine, and controlling the lamps from the smartphone was nice.
However after a while, the lamps seemed to become less responsive, sometimes missing commands.
The app would also have problems connecting to the gateway.
Some research led me to a &lt;a href=&quot;https://github.com/ggravlingen/pytradfri/issues/54&quot;&gt;GitHub issue&lt;/a&gt; where somebody said that &lt;em&gt;“the gateway needs restarting every 1-2 days”&lt;/em&gt;.
And indeed, rebooting the gateway solved the issues I was facing.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://antoinealb.net/assets/media/tradfri-reboot/reboot.gif&quot; alt=&quot;Fixing a TRÅDFRI memory leak&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The gateway API includes a &lt;a href=&quot;https://github.com/ggravlingen/pytradfri/blob/70ff6b83c6c64708f7ed22f2193406b0a10b0e64/pytradfri/gateway.py#L171-L179&quot;&gt;remote reboot command&lt;/a&gt; which we should be able to use to avoid turning it off and on by hand.
I did a quick experiment using the command found in the above GitHub issue to confirm the API worked as expected, and confident enough, decided to automate this.&lt;/p&gt;

&lt;p&gt;My initial plan was to use my router to host the automation for rebooting the gateway, to avoid adding complexity.
However, it turns out compiling custom software on pfSense is &lt;a href=&quot;https://docs.netgate.com/pfsense/en/latest/development/compiling-software-on-the-firewall.html&quot;&gt;more complicated than expected&lt;/a&gt;.
I was already spending more time than I wanted on this so I decided to pull my Raspberry Pi out of the drawer and hook it up.
Maybe one day I will take some time to package the solution for pfSense, but we all know how temporary solutions end up…&lt;/p&gt;

&lt;p&gt;I will assume you have an up to date version of Raspbian installed.
Plenty of blogs on the Internet cover this up already.&lt;/p&gt;

&lt;p&gt;The gateway communicates using a protocol called CoAP, which is a lightweight RPC protocol with semantics resembling HTTP.
An open source implementation of this is &lt;a href=&quot;https://libcoap.net/&quot;&gt;libcoap&lt;/a&gt;, used by a &lt;a href=&quot;https://github.com/ggravlingen/pytradfri&quot;&gt;Python API for the IKEA modules&lt;/a&gt;.
We will install it from source using the following commands:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;apt-get &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;build-essential autoconf automake libtool
git clone &lt;span class=&quot;nt&quot;&gt;--recursive&lt;/span&gt; https://github.com/obgm/libcoap.git &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;libcoap
./autogen.sh
./configure &lt;span class=&quot;nt&quot;&gt;--disable-tests&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;--disable-documentation&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;--enable-examples&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;--with-tinydtls&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;--disable-shared&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;--prefix&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;/usr/local
make &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;make &lt;span class=&quot;nb&quot;&gt;install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;We can install Python and the API:&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;apt &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;python3 python3-pip
pip3 &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;pytradfri
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;We will now write a simple script that takes the security key, authenticates with the gateway and asks it to reboot.
Place the following in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/usr/local/bin/reboot_tradfri.py&lt;/code&gt; and make it executable with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;chmod 755 /usr/local/bin/reboot_tradfri.py&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;#!/usr/bin/env python3
&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&quot;&quot;
Reboots a IKEA Tradfri gatetway.

This can be used from a crontab to avoid a memory leak in the tradfri firmware.
&quot;&quot;&quot;&lt;/span&gt;

&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;pytradfri&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Gateway&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;pytradfri.api.libcoap_api&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;APIFactory&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;retry_timeout&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;pytradfri.error&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;PytradfriError&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;pytradfri.util&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;load_json&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;save_json&lt;/span&gt;

&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;uuid&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;argparse&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;json&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;TIMEOUT_SECONDS&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;40&lt;/span&gt;


&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;parse_args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;parser&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;argparse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ArgumentParser&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;__doc__&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;parser&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'host'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                        &lt;span class=&quot;n&quot;&gt;metavar&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'IP'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                        &lt;span class=&quot;nb&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                        &lt;span class=&quot;n&quot;&gt;help&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'IP Address of your Tradfri gateway'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;parser&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'--key'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                        &lt;span class=&quot;s&quot;&gt;'-k'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                        &lt;span class=&quot;n&quot;&gt;required&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                        &lt;span class=&quot;n&quot;&gt;help&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'Security code found on your Tradfri gateway'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;parser&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;add_argument&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'--config'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                        &lt;span class=&quot;s&quot;&gt;'-c'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                        &lt;span class=&quot;n&quot;&gt;required&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                        &lt;span class=&quot;nb&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;argparse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;FileType&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'a+'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;
                        &lt;span class=&quot;n&quot;&gt;help&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Path to the configuration file. Will be created if it does not exist.&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;parser&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parse_args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;16&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;parser&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Security key must be 16 char long&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;


&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;load_identity&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;config_file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;config&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;load&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;config_file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'identity'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'psk'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;


&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;save_identity&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;config_file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;identity&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;psk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;conf&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'identity'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;identity&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'psk'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;psk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;config_file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;seek&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;config_file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;truncate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dump&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;conf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;config_file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;indent&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;


&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;parse_args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;seek&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;# Try to load a pre-existing shared key from the configuration file
&lt;/span&gt;        &lt;span class=&quot;n&quot;&gt;identity&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;psk&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;load_identity&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;api_factory&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;APIFactory&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;host&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;host&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;psk_id&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;identity&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;psk&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;psk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;timeout&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;TIMEOUT_SECONDS&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;except&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;KeyError&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;JSONDecodeError&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;# We could not load the preexisting key, generate a new one and
&lt;/span&gt;        &lt;span class=&quot;c1&quot;&gt;# associate the gateway with it.
&lt;/span&gt;        &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Generating new identity &amp;amp; PSK&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;identity&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;uuid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;uuid4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;hex&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;api_factory&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;APIFactory&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;host&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;host&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;psk_id&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;identity&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;timeout&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;TIMEOUT_SECONDS&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;psk&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;api_factory&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;generate_psk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;save_identity&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;identity&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;psk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;api&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;retry_timeout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;api_factory&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;retries&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;gateway&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Gateway&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;api&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;gateway&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;reboot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;


&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;__name__&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'__main__'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;You should now be able to reboot your Gateway by running the command below.
Check that it worked by observing the status LEDs on the gateway itself.
Make sure to replace &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$SECURITY_CODE&lt;/code&gt; with the string you can find on the back of your gateway, and $IP with its IP address.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;reboot_tradfri.py &lt;span class=&quot;nv&quot;&gt;$IP&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-k&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$KEY&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-c&lt;/span&gt; ~/tradfri_identity.json
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Note: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tradfri_identity.json&lt;/code&gt; does not exist at this point, but the script will create it and save the pre-shared key in it.&lt;/p&gt;

&lt;p&gt;Finally, we will reboot the gateway each morning at 5 AM.
At this point everybody should be asleep and not using the lights so it should not create any issues.
We will use &lt;a href=&quot;https://en.wikipedia.org/wiki/Cron&quot;&gt;Cron&lt;/a&gt; which is a system used to schedule periodic jobs on UNIX systems.
You configure it using a file called the Crontab, and you can read how this file works by doing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;man 5 crontab&lt;/code&gt;.
Append the following to the crontab by running &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;EDITOR=nano crontab -e&lt;/code&gt;, which will open an editor to modify your cron job definitions.
Once you exit the editor, cron checks the syntax of the file and installs the new jobs if the config is valid.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;0 5 * * * PATH=$PATH:/usr/local/bin &amp;amp;&amp;amp; export PATH &amp;amp;&amp;amp; reboot_tradfri.py -k KEY -c ~/tradfri_identity.json IP
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Your gateway should now reboot everyday automatically, and keep working for a long time.
It is a bit annoying to have to do that kind of workarounds for a commercial product.
I would love either a fix from IKEA, or a way to deploy this on my pfSense box.&lt;/p&gt;

&lt;p&gt;But for now, I can move on to other stuff!&lt;/p&gt;</content><author><name>Antoine Albertelli</name><email>antoinea101@gmail.com</email></author><summary type="html">So I got myself a set of connected light bulbs for my living room. Based on review, I decided to go with the IKEA models, as they are pretty inexpensive and provide good quality lighting. I also decided to have a gateway, which allows you to control your lamps from your LAN and provide additional functions like lamp groups. The gateway also offers an API so I figured it could be a fun thing to hack with.</summary></entry><entry><title type="html">Test your external dependencies</title><link href="http://antoinealb.net/2018/04/12/test-your-external-dependencies.html" rel="alternate" type="text/html" title="Test your external dependencies" /><published>2018-04-12T00:00:00+00:00</published><updated>2018-04-12T00:00:00+00:00</updated><id>http://antoinealb.net/2018/04/12/test-your-external-dependencies</id><content type="html" xml:base="http://antoinealb.net/2018/04/12/test-your-external-dependencies.html">&lt;p&gt;In the unit testing crowd your often hear the mantra that you should not test your external dependencies with unit tests and that they are only for integration testing.
In a way this makes sense: the developper of the library probably took some time to test the library on their own, so why redo the work?
However, I like to write a few unit tests when I am integrating a new library into a project.
Most of the time I even commit them to the source repository and add them to the CI build.&lt;/p&gt;

&lt;p&gt;For sure it takes much longer to integrate the library now.
You have to write some tests, and you may have to code some mock objects as well.
However, I find this investment in time well worth it, for two main reasons:&lt;/p&gt;

&lt;p&gt;First, it gives you a better understanding of the API of your library.
You can clearly see how the library works, which expectations it has.
With mock objects you can also inject faults and see how the code reacts.
In fact, I had the idea for this blog as I was integrating a library I used before in a new project.
It took me so long to debug a weird issue, but when writing a test, it quickly became clear that I just forgot a step in the initialization of the library.&lt;/p&gt;

&lt;p&gt;Second, it can be used as a future reference (or cheat sheet) by you and your team.
This is why I add the tests to the repository: to make sure they will be available when I forget how to do a given operation.&lt;/p&gt;

&lt;p&gt;Finally, once your test suite is in place, it becomes easy to prototype new interactions with the dependency.
Just write tests for this new use case and see if it works.
This is also useful if you ever have to fix a bug in the library: you can try and reproduce it in your familiar testing environment.&lt;/p&gt;

&lt;p&gt;Happy testing!&lt;/p&gt;</content><author><name>Antoine Albertelli</name><email>antoinea101@gmail.com</email></author><summary type="html">In the unit testing crowd your often hear the mantra that you should not test your external dependencies with unit tests and that they are only for integration testing. In a way this makes sense: the developper of the library probably took some time to test the library on their own, so why redo the work? However, I like to write a few unit tests when I am integrating a new library into a project. Most of the time I even commit them to the source repository and add them to the CI build.</summary></entry><entry><title type="html">Measuring program performance with perf(1)</title><link href="http://antoinealb.net/programming/2018/02/23/profiling-with-perf.html" rel="alternate" type="text/html" title="Measuring program performance with perf(1)" /><published>2018-02-23T00:00:00+00:00</published><updated>2018-02-23T00:00:00+00:00</updated><id>http://antoinealb.net/programming/2018/02/23/profiling-with-perf</id><content type="html" xml:base="http://antoinealb.net/programming/2018/02/23/profiling-with-perf.html">&lt;p&gt;In my new internship I am working on optimizing some software.
But before starting making changes to the source code, I need to make sure that I am optimizing important parts.
Imagine for a moment that I spend days making one part of a program go 10x faster (!!), only to realize later that it is responsible for 1% of the total run time.
How much would I have saved?
The answer is not much: the new run time would be 99% + (1% / 10) = 99.1% of the original run time.
In other words, only 1.01 times faster.
Not so impressing now, is it?&lt;/p&gt;

&lt;p&gt;This post will introduce one method to measure how the program is spending its time.
This is known as &lt;em&gt;profiling&lt;/em&gt; the code.
I learnt a lot of techniques from my colleagues, but also a lot comes from &lt;a href=&quot;https://www.youtube.com/watch?v=nXaxk27zwlk&quot;&gt;Chandler Carruth’s talk at CppCon 2015&lt;/a&gt;.
Go watch it if you want more information than what I expose here.&lt;/p&gt;

&lt;h2 id=&quot;sample-program-to-profile&quot;&gt;Sample program to profile&lt;/h2&gt;

&lt;p&gt;For those experiments we will need a small program to profile.
I wrote a simple program (see below) that computes the Fibonacci sequence and displays it.
I know that this is not optimal in any way, but we will see how.&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;#include &amp;lt;vector&amp;gt;
#include &amp;lt;iostream&amp;gt;
&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;#include &amp;lt;benchmark/benchmark.h&amp;gt;
&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Benchmark_Fibonacci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;benchmark&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;State&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;state&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;N&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;state&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;vector&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;push_back&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;push_back&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

        &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;push_back&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;benchmark&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;DoNotOptimize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;benchmark&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ClobberMemory&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;BENCHMARK&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Benchmark_Fibonacci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;BENCHMARK_MAIN&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;We can now build this program using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;g++ benchmark.cpp -o fibo &amp;amp;&amp;amp; ./benchmark&lt;/code&gt;.
No output is produced, but the suite is computed, so it is time to measure what takes some time.&lt;/p&gt;

&lt;p&gt;Now that this is done, we can run the program with the perf utility (found in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;linux-tools&lt;/code&gt;).
We will run it with the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-g&lt;/code&gt; option to record call graph information:
We need to run it as root because the access to performance counter are disabled by default on Linux.
Normal users can be given access to this, but this is out of the scope of this article.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;perf record &lt;span class=&quot;nt&quot;&gt;-g&lt;/span&gt; ./benchmark
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;perf report &lt;span class=&quot;nt&quot;&gt;-g&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'graph,0.5,caller'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;You should now be presented with an interactive window in which you can see how much time your program spent in each function.&lt;/p&gt;

&lt;p&gt;One nice trick in the code above is the use of the functions &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DoNotOptimize&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ClobberMemory&lt;/code&gt;.
Those twp functions basically tell the compiler to ignore the fact that the results of the computation are not used anywhere.
Otherwise, most optimizers will delete the code of our benchmark, as it does not create side effect.&lt;/p&gt;

&lt;p&gt;For those of you who are curious, you can implement it yourself using the following code:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;DoNotOptimize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;volatile&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;asm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;g&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;memory&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;ClobberMemory&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;volatile&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;asm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;memory&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Basically those two lines of code are used to create fake zones where the results of the benchmark &lt;em&gt;might&lt;/em&gt; be used.
The compiler is also disallowed to optimize those parts by the use of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;volatile&lt;/code&gt; keyword.
For more detail on this, see the talk I linked above or GCC’s documentation on inline assembly.&lt;/p&gt;

&lt;p&gt;There is a lot to be said on how to interpret perf’s output and optimize your code, but I just wanted to share what I learnt last week.
The rest will be for another post!&lt;/p&gt;</content><author><name>Antoine Albertelli</name><email>antoinea101@gmail.com</email></author><category term="Programming" /><summary type="html">In my new internship I am working on optimizing some software. But before starting making changes to the source code, I need to make sure that I am optimizing important parts. Imagine for a moment that I spend days making one part of a program go 10x faster (!!), only to realize later that it is responsible for 1% of the total run time. How much would I have saved? The answer is not much: the new run time would be 99% + (1% / 10) = 99.1% of the original run time. In other words, only 1.01 times faster. Not so impressing now, is it?</summary></entry><entry><title type="html">How to read a datasheet ?</title><link href="http://antoinealb.net/2018/01/11/how-to-read-a-datasheet.html" rel="alternate" type="text/html" title="How to read a datasheet ?" /><published>2018-01-11T00:00:00+00:00</published><updated>2018-01-11T00:00:00+00:00</updated><id>http://antoinealb.net/2018/01/11/how-to-read-a-datasheet</id><content type="html" xml:base="http://antoinealb.net/2018/01/11/how-to-read-a-datasheet.html">&lt;p&gt;So, since you started your journey into hardware making one word has
been thrown around a lot: “datasheet”. You are not totally sure of what
it is, but judging by how many times it is referenced by other
engineers, you thought it must be very important. And you were right!
Let me introduce you to this famous document.&lt;/p&gt;

&lt;p&gt;The datasheet (sometimes called the spec sheet), is the document that
lists every characteristic of a part or subassembly. It is provided by
the manufacturer, who wants you to have every information you need to
design a product using their part (and then buy lots of them).&lt;/p&gt;

&lt;p&gt;Datasheets range from simple to very complicated. A small passive
component such as a capacitor will have one or two pages of datasheets,
up to about 1200 pages for the datasheet for a complex microcontroller!
Obviously, you do not want to read so many pages, so you need to learn
how to navigate effectively in this ocean of information.&lt;/p&gt;

&lt;h2 id=&quot;why-do-you-want-to-read-a-datasheet&quot;&gt;Why do you want to read a datasheet?&lt;/h2&gt;

&lt;p&gt;Before you even download a datasheet, it is important to know why. Are
you a programmer who wants to implement a software driver for a chip? An
electrical designer picking the main parts of their next product? A
reverse engineer trying to understand how an old board works? Parts of
the datasheet that might be irrelevant for one of those situations might
be crucial for another one.&lt;/p&gt;

&lt;h2 id=&quot;where-do-you-even-find-those-datasheets&quot;&gt;Where do you even find those datasheets?&lt;/h2&gt;

&lt;p&gt;So now you need to find the document. I usually start by entering the
name of the part I am interested in plus “datasheet” into Google. This
is usually the quickest way to find what you are looking for. Make sure
the part number in the PDF matches what you want, sometimes Google gives
incorrect results!&lt;/p&gt;

&lt;p&gt;Another way to find a datasheet is by going to the manufacturer website.
This technique can be painful, as navigating the website is quite
different for each manufacturer. You can usually find the documents from
the page of the product you are interested in. This is unfortunately the
only way to make sure you have every information about your part, as
some manufacturer like to spread the information in various PDFs.&lt;/p&gt;

&lt;p&gt;Finally, the last method is particularly useful when you are at the
status of component selection. In this phase, you will be looking at a
lot of different components, and searching the relevant datasheets takes
a lot of time. Fortunately, large components retailer, like Digikey,
usually offer datasheets for download from their product browser.&lt;/p&gt;

&lt;p&gt;Like I mentioned some manufacturers keep all the information for one
part in a single document, while others prefer to separate into several.
Document intended for electrical engineers are usually what is called
the datasheet. Software-related indications are typically in other
documents, often named something like &lt;em&gt;Reference Manual&lt;/em&gt;, &lt;em&gt;Programmer’s
manual&lt;/em&gt;, &lt;em&gt;Programming model,&lt;/em&gt; etc. Sometimes the documents are shared
across a device family. For example, the electrical information might be
in the “STM32F407 datasheet”, while the programming documentation is in
the “STM32F4 family reference manual”. Make sure you also download the
&lt;em&gt;errata;&lt;/em&gt; this document lists all the error and issues the manufacturer
has discovered about their product and it helps to know about them.&lt;/p&gt;

&lt;p&gt;Some manufacturers might not give you the datasheet right away; they
might require you to give information about your company/product or sign
a Non-Disclosure Agreement (NDA). I would try to stay away from such
companies if possible, and only try to get their datasheets if you
really cannot do otherwise. These behaviours are red flags: either the
product is really new (the datasheet or the product itself still has
issues) or the company wants to hide something (lack of performance?).
Even if the company really just wants to protect their secrets it will
come back to bite you later.&lt;/p&gt;

&lt;h2 id=&quot;anatomy-of-a-datasheet&quot;&gt;Anatomy of a datasheet&lt;/h2&gt;

&lt;p&gt;The first page(s) of a datasheet is called the &lt;em&gt;Product Brief&lt;/em&gt; (see example below).
It contains a list of all the features of a chip and the most important
characteristics (power supply voltages, package, etc.). Start by reading
those to make sure the chip suits your need. You can probably find
typical applications of this chip here; see if your application is
listed. If you don’t see the features you need on the brief, don’t waste
your time on that part. In this section, you can also find the status of
the chip (pre-release, active or obsolete) and the release date. Make
sure you are not losing time with a very old part or something you won’t
be able to buy in the next 18 months.&lt;/p&gt;

&lt;div class=&quot;text-centered&quot;&gt;&lt;i&gt;Example product brief for an STM32F407 micro controller&lt;/i&gt;&lt;/div&gt;
&lt;p&gt;&lt;img src=&quot;http://antoinealb.net/assets/images/407_product_brief.png&quot; alt=&quot;Example product brief (STM32F407)&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Some datasheets contain a section called &lt;em&gt;Application Information&lt;/em&gt; or
similar. In those sections, the manufacturer discusses the use of the
product, usually with schematic and information regarding the choice of
external components and the equations needed for your design. Sometimes
the manufacturer will even suggest compatible parts to use for their
design. If the datasheet does not contain such sections, look for
documents called &lt;em&gt;Application Notes&lt;/em&gt; (appnotes in short), which are
separate document with the same purpose.&lt;/p&gt;

&lt;div class=&quot;text-centered&quot;&gt;&lt;i&gt;Example absolute maximum rating (STM32F407)&lt;/i&gt;&lt;/div&gt;
&lt;p&gt;&lt;img src=&quot;http://antoinealb.net/assets/images/407_amr.png&quot; alt=&quot;Example absolute maximum rating (STM32F407)&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Next, find the section named “Absolute maximum ratings” (see example above). As the name
implies, this contains the limits you &lt;em&gt;must&lt;/em&gt; respect if you do not want
to break the part. Study it carefully! The content of this section will
vary a lot depending on the device you are studying, so it’s hard to
give specific advice here.&lt;/p&gt;

&lt;p&gt;When reading numerical values in a datasheet, you will see that it is
quite common to have multiple values for one thing: usually a typical
value and a range (min – max). Make sure your design is working over the
whole range of possible values!&lt;/p&gt;

&lt;h2 id=&quot;random-tips&quot;&gt;Random tips&lt;/h2&gt;

&lt;p&gt;When you do not know the exact name of what you are searching for, it is
useful to look at the units: If you are searching for a time, simply
skim the unit columns for something like nanoseconds.&lt;/p&gt;

&lt;p&gt;There will be restrictions and conditions under which a given
information is valid. Be careful, as they might be hidden in footnotes.&lt;/p&gt;

&lt;p&gt;When looking at mechanical drawing, especially of chips, make sure you
are looking at the correct orientation (from above or from below).
Usually chip outlines are given from above, but you can sometimes be
surprised.&lt;/p&gt;

&lt;p&gt;When programming an unfamiliar device, I find it useful to print the
relevant chapters from the datasheet. Then, take notes, draw schematics,
write pseudo-code, highlight important sections etc. You cannot keep
every important information in your head, and they will come back to
bite you.&lt;/p&gt;

&lt;p&gt;The datasheet is like a search engine. Use Ctrl-F a lot, and ask questions to the document.
After a while you will know the kind of jargon used by your device’s manufacturer and you will be able to quickly find the detail you need.&lt;/p&gt;</content><author><name>Antoine Albertelli</name><email>antoinea101@gmail.com</email></author><summary type="html">So, since you started your journey into hardware making one word has been thrown around a lot: “datasheet”. You are not totally sure of what it is, but judging by how many times it is referenced by other engineers, you thought it must be very important. And you were right! Let me introduce you to this famous document.</summary></entry><entry><title type="html">33rd Chaos Communication Congress</title><link href="http://antoinealb.net/2017/02/09/33c3.html" rel="alternate" type="text/html" title="33rd Chaos Communication Congress" /><published>2017-02-09T00:00:00+00:00</published><updated>2017-02-09T00:00:00+00:00</updated><id>http://antoinealb.net/2017/02/09/33c3</id><content type="html" xml:base="http://antoinealb.net/2017/02/09/33c3.html">&lt;p&gt;I spent the time between Christmas and New Year in Hamburg, Germany, at the Chaos Communication Congress, 33rd edition (33C3 in short).
33C3’s motto was “Works for Me”, a phrase that everyone working in IT/engineering will hear at some point during their career.
It quickly became a meme in the congress, showing up every time a presenter had a laptop issue for example.&lt;/p&gt;

&lt;p&gt;I used some of the time between talks to update a bit my personal infrastructure to include Owncloud in addition to the existing Gitlab instance.
This is still a work in progress, and I may write about it in the future.&lt;/p&gt;

&lt;p&gt;I also had a lot of project ideas that I will leave here, in case I need some ways to lose my time soon!&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;WhatsApp-b-gone, an idea that was created after @SyrianSpock and I realized that social gatherings were annoyingly filled with people glaring at their phone.
 The easiest way to implement this is probably to add some rules in the firewall to block WhatsApp traffic.
 The rules should be easy to turn on and off (webapp for example).&lt;/li&gt;
  &lt;li&gt;Learning how to use radare2.
 Radare2 is a reverse engineering framework like IDA pro, but libre and commandline.
 It seems powerful but the learning curve is rather steep, so I must stick to it.&lt;/li&gt;
  &lt;li&gt;Related to the previous one: reverse engineer the Xiaomi Band fitness device.
 This is a small connected device that is still complete enough to be interesting to reverse engineer.
 Gaining code execution on it would be nice, as it is a small wearable device with a lot of autonomy.&lt;/li&gt;
  &lt;li&gt;Modifying the &lt;a href=&quot;https://github.com/cvra/CAN-USB-dongle&quot;&gt;CVRA’s USB to CAN adapter&lt;/a&gt; to use SocketCAN.
 It would allow us to plug it into Linux and use Wireshark to analyze traffic.&lt;/li&gt;
  &lt;li&gt;A “smart” time tracker, which works by detecting what is your current working directory and guessing on which project I am working.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Anyway: as &lt;a href=&quot;/2016/01/01/back-from-32c3.html&quot;&gt;last year&lt;/a&gt; , I took some notes about the talk I went to and also the talk I had to miss, so that I can watch them later.
This year marks the introduction of French translation for streams, which are included in the recording if you want to.
Kudos to the translation team!&lt;/p&gt;

&lt;h2 id=&quot;the-global-assassination-grid&quot;&gt;The Global Assassination Grid&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;As they say in the Air Force, ‚No comms no bombs‘, – A technician’s insight into the invisible networks governing military drones and the quest for accountability&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;video&quot;&gt;
&lt;iframe width=&quot;640&quot; height=&quot;360&quot; src=&quot;https://www.youtube.com/embed/7wwnhyUOuns?ecver=1&quot; frameborder=&quot;0&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;p&gt;It was impressive to hear him talk about his experience as a drone pilot and why he switched to alert the public about the drone program.
I don’t think it is technical but some military acronyms slipped in without being explained.&lt;/p&gt;

&lt;h2 id=&quot;shut-up-and-take-my-money&quot;&gt;Shut Up and Take My Money!&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;FinTechs increasingly cut the ground from under long-established banks’ feet.
With a “Mobile First” strategy, many set their sights on bringing all financial tasks—checking the account balance, making transactions, arranging investments, and ordering an overdraft—on your smartphone.
In a business area that was once entirely committed to security, Fintechs make a hip design and outstanding user experience their one and only priority.
Even though this strategy is rewarded by rapidly increasing customer numbers, it also reveals a flawed understanding of security.
With the example of the pan-European banking startup N26 (formerly Number26), we succeeded independently from the used device to leak customer data, manipulate transactions, and to entirely take over accounts to ultimately issue arbitrary transactions—even without credit.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;video&quot;&gt;
&lt;iframe width=&quot;640&quot; height=&quot;360&quot; src=&quot;https://www.youtube.com/embed/KopWe2ZpVQI?ecver=1&quot; frameborder=&quot;0&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;p&gt;Good talk showing the issues in a banking startup.
The exploits were not complicated but are a good example of what not to do when you are developing an application.
Not very technical.&lt;/p&gt;

&lt;h2 id=&quot;whats-it-doing-now&quot;&gt;What’s It Doing Now?&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;Legend has it that most airline pilots will at one time have uttered the sentence “What’s it Doing now?”, whenever the autopilot or one of its related systems did something unexpected.
I will be exploring some high-profile accidents in which wrong expectations of automation behavior contributed to the outcome.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;video&quot;&gt;
&lt;iframe width=&quot;640&quot; height=&quot;360&quot; src=&quot;https://www.youtube.com/embed/Xi79iJoqe8o?ecver=1&quot; frameborder=&quot;0&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;p&gt;This talk was trying to see how we could transpose the lessons learnt from plane autopilots to self-driving car, especially regarding to what to do when it fails.
Not very technical.&lt;/p&gt;

&lt;h2 id=&quot;dieselgate--a-year-later&quot;&gt;Dieselgate – A year later&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;At 32C3 we gave an overview on the organizational and technical aspects of Dieselgate that had just broken public three months before.
In the last year we have learned a lot and spoken to hundreds of people.
Daniel gives an update on what is known and what is still to be revealed.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;video&quot;&gt;
&lt;iframe width=&quot;640&quot; height=&quot;360&quot; src=&quot;https://www.youtube.com/embed/SjlHtLux9vc?ecver=1&quot; frameborder=&quot;0&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;p&gt;Awesome talk!
Daniel was one of the two presenters on the 32C3 Dieselgate talk.
This year they decided to split their talk in one about politics/law (this one) and one about hacking methods used (I could not watch it).
I recommend it to anyone interested in the Dieselgate scandal.
Not technical.&lt;/p&gt;

&lt;h2 id=&quot;nintendo-hacking-2016&quot;&gt;Nintendo Hacking 2016&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;This talk will give a unique insight of what happens when consoles have been hacked already, but not all secrets are busted yet.
This time we will not only focus on the Nintendo 3DS but also on the Wii U, talking about our experiences wrapping up the end of an era.
We will show how we managed to exploit them in novel ways and discuss why we think that Nintendo has lost the game.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;video&quot;&gt;
&lt;iframe width=&quot;640&quot; height=&quot;360&quot; src=&quot;https://www.youtube.com/embed/8C5cn_Qj0G8?ecver=1&quot; frameborder=&quot;0&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;p&gt;I like talks about console hacking:
Since console systems are exotic, they usually start with an overview of the platform, which allows you to understand the exploits part without too much specific knowledge (unlike say, talks about PC systems).
A good talk, with three passionate hackers showing us how they owned the Wii U and the 3DS.
However, the attacks presented are highly technical, and might be hard to understand if you are not familiar with ROP and Use-after-free.&lt;/p&gt;

&lt;h2 id=&quot;how-physicists-analyze-massive-data-lhc--brain--root--higgs&quot;&gt;How physicists analyze massive data: LHC + brain + ROOT = Higgs&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;Physicists are not computer scientists.
But at CERN and worldwide, they need to analyze petabytes of data, efficiently.
Since more than 20 years now, ROOT helps them with interactive development of analysis algorithms (in the context of the experiments’ multi-gigabyte software libraries), serialization of virtually any C++ object, fast statistical and general math tools, and high quality graphics for publications.
I.e. ROOT helps physicists transform data into knowledge.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;The presentation will introduce the life of data, the role of computing for physicists and how physicists analyze data with ROOT.
It will sketch out how some of us foresee the development of data analysis given that the rest of the world all of a sudden also has big data tools: where they fit, where they don’t, and what’s missing.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;video&quot;&gt;
&lt;iframe width=&quot;640&quot; height=&quot;360&quot; src=&quot;https://www.youtube.com/embed/SKeHPFphdzs?ecver=1&quot; frameborder=&quot;0&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;p&gt;Fun thing about this talk: the topics were chosen by the audience, based on the amount of cheering for a given topic.
However, I did not learn much in this talk, especially on ROOT, which was supposed to be the theme of the talk.
Somewhat technical.&lt;/p&gt;

&lt;h2 id=&quot;no-usb-no-problem&quot;&gt;No USB? No problem.&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;How to get USB running on an ARM microcontroller that has no built in USB hardware.
We’ll cover electrical requirements, pin assignments, and microcontroller considerations, then move all the way up the stack to creating a bidirectional USB HID communications layer entirely in software.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;video&quot;&gt;
&lt;iframe width=&quot;640&quot; height=&quot;360&quot; src=&quot;https://www.youtube.com/embed/GFY_A3jcI28?ecver=1&quot; frameborder=&quot;0&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;p&gt;xobs is the co-creator of the Novena open source laptop.
I highly recommend reading &lt;a href=&quot;https://xobs.io&quot;&gt;his blog&lt;/a&gt;, if you are into hardware hacking or manufacturing.
About the talk itself, I enjoyed it, as it was a nice introduction to USB and debugging, and I worked on those two topics before.
However, if you are not planning to implement USB soon, or don’t like firmware hacking, this talk might not be your cup of tea.&lt;/p&gt;

&lt;h2 id=&quot;formal-verification-of-verilog-hdl-with-yosys-smtbmc&quot;&gt;Formal Verification of Verilog HDL with Yosys-SMTBMC&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;Yosys is a free and open source Verilog synthesis tool and more.
It gained prominence last year because of its role as synthesis tool in the Project IceStorm FOSS Verilog-to-bitstream flow for iCE40 FPGAs.
This presentation however dives into the Yosys-SMTBMC formal verification flow that can be used for verifying formal properties using bounded model checks and/or temporal induction.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;video&quot;&gt;
&lt;iframe width=&quot;640&quot; height=&quot;360&quot; src=&quot;https://www.youtube.com/embed/VJsMLPGg4U4?ecver=1&quot; frameborder=&quot;0&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;p&gt;&lt;em&gt;Insanely&lt;/em&gt; technical talk about formal verification of FPGA programs, which can be used to find bugs not exercised by the simulation or by testing on hardware.
I must admit I did not understand most of the talk, but I think I got an approximate understanding of the process.&lt;/p&gt;

&lt;h2 id=&quot;lockpicking-in-the-iot&quot;&gt;Lockpicking in the IoT&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;“Smart” devices using BTLE, a mobile phone and the Internet are becoming more and more popular.
We will be using mechanical and electronic hardware attacks, TLS MitM, BTLE sniffing and App decompilation to show why those devices and their manufacturers aren’t always that smart after all.
And that even AES128 on top of the BTLE layer doesn’t have to mean “unbreakable”.
Our main target will be electronic locks, but the methods shown apply to many other smart devices as well…&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;video&quot;&gt;
&lt;iframe width=&quot;640&quot; height=&quot;360&quot; src=&quot;https://www.youtube.com/embed/ix_Fw75kKb8?ecver=1&quot; frameborder=&quot;0&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;p&gt;This talk focuses on some digital padlocks that use Bluetooth for unlocking.
The researcher shows how incredibly bad the security of those things are, both mechanically and in software.&lt;/p&gt;

&lt;h2 id=&quot;a-world-without-blockchain&quot;&gt;A world without blockchain&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;Instant money transfer, globally without borders and 24/7.
That’s one of the promises of Bitcoin.
But how does national and international money transfer work in the world of banks?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;video&quot;&gt;
&lt;iframe width=&quot;640&quot; height=&quot;360&quot; src=&quot;https://www.youtube.com/embed/Xqn81bVLB4g?ecver=1&quot; frameborder=&quot;0&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;p&gt;A talk showing what happens behind-the-scenes when you send money to your cousin in Brazil.
Contains both the accounting principles and the technical explanations of what happens.
I would have loved to go a bit more in-depth, but the talk was already short on time.
Not technical.&lt;/p&gt;

&lt;h2 id=&quot;intercoms-hacking&quot;&gt;Intercoms Hacking&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;Call the frontdoor to install your backdoors&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;video&quot;&gt;
&lt;iframe width=&quot;640&quot; height=&quot;360&quot; src=&quot;https://www.youtube.com/embed/6NKIx5ktHF0?ecver=1&quot; frameborder=&quot;0&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;p&gt;The author attack modern intercoms by forcing them to connect to a rogue 3G cell.
They are then able to open the door and spy on door conversation.
It was interesting to see how to create a fake GSM antenna using a BladeRF/HackRF with YateBTS on the software side.
Technical: you might have to search a bit if you don’t know anything about GSM &amp;amp; SDR.&lt;/p&gt;

&lt;h2 id=&quot;radare-demystified&quot;&gt;radare demystified&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;radare is a libre framework and a set of tools to ease several tasks related to reverse engineering, exploiting, forensics, binary patching.
This year, the project gets 10 year old.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;This talk will show the evolution and structure of the project, its roots, some of the most notorious capabilities, showing several usage examples to let the attendees the power in functionalities and extensibility the tool provides.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;video&quot;&gt;
&lt;iframe width=&quot;640&quot; height=&quot;360&quot; src=&quot;https://www.youtube.com/embed/fnpBy3wWabA?ecver=1&quot; frameborder=&quot;0&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;p&gt;I wanted to learn radare2 even before coming to CCC, so this talk was a “must attend”.
What I got back from this talk was some starting points on how to use radare2.
If you are not interested by reverse engineering, I don’t think you are in the audience for this talk.&lt;/p&gt;

&lt;p&gt;Here are my raw notes:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;They apparently have an IRC channel.

Should take between 2 days and one week to get used to it (à la vim).

Commands are mnemonic, based on modifiers (à la vim again)

5 commands to remember:

* s seek
* pd print disassembly
* s? prints help for s
* w is for write
* q quit
* ~ means grep (&quot;p 10 ~ Mov&quot;)
* /m looks for known file format using magic

It appears to be able to read data in structs.

See the blog post &quot;Analysis by default&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;on-smart-cities-smart-energy-and-dumb-security&quot;&gt;On Smart Cities, Smart Energy, And Dumb Security&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;Smart City is an abstract concept everyone talks about but no one knows what it actually means.
No one, except Energy utilities.
In this talk we will explore the vast world of Smart Energy, and see how energy providers used the “Smart City” concept to get better control over our energy consumption, all while almost completely ignoring security aspects along the way.
Join me and see how Smart Energy is making our lives a little bit better, but also dangerously insecure.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;video&quot;&gt;
&lt;iframe width=&quot;640&quot; height=&quot;360&quot; src=&quot;https://www.youtube.com/embed/k2EpY3-kDww?ecver=1&quot; frameborder=&quot;0&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;p&gt;I was disappointed by this talk.
It contained a lot of non-fact based affirmations such as “you can make electricity meters exploded by hacking them” and little technical content.
Same goes for Zigbee: no exploits / concepts, only talk.
I was under the impression that the guy wanted to sell us the product his new startup is developping (he said he was working on this topic at the beginning of the talk though).
I don’t recommend watching it.&lt;/p&gt;

&lt;h2 id=&quot;dissecting-modern-3g4g-cellular-modems&quot;&gt;Dissecting modern (3G/4G) cellular modems&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;Let’s have a detailed look at some modern 3G/4G cellular modems and see what we can find out about their internals using undocumented debug interfaces and software or hardware based hacking techniques.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;video&quot;&gt;
&lt;iframe width=&quot;640&quot; height=&quot;360&quot; src=&quot;https://www.youtube.com/embed/6o_mVPwHYnk?ecver=1&quot; frameborder=&quot;0&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;p&gt;The speakers are coming from the osmocom project so they know quite a lot about reverse engineering.
This is also not their first talk so they know how to present well.
A good talk about reverse engineering obscure hardware, GPL enforcement and weird programming practices.
Technical.&lt;/p&gt;

&lt;p&gt;They also introduced a multi voltage UART adapter called the &lt;a href=&quot;https://osmocom.org/projects/mv-uart/wiki&quot;&gt;Osmocom MV-UART&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;dissecting-hdmi&quot;&gt;Dissecting HDMI&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;Ever wondered what is actually happening when a speaker can’t get their laptop to project?
While developing the FPGA-based HDMI2USB.tv open hardware for recording conferences, we discovered just how convoluted the HDMI protocol can be.
Come hear all the horrible details!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;video&quot;&gt;
&lt;iframe width=&quot;640&quot; height=&quot;360&quot; src=&quot;https://www.youtube.com/embed/yqYBcZzMPGQ?ecver=1&quot; frameborder=&quot;0&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;p&gt;The speaker comes from the &lt;a href=&quot;http://code.timvideos.us&quot;&gt;Timsvideos project&lt;/a&gt;.
The aim of the project is to be able to record conferences, like the CCC, but with less resources.
To do that they wanted to create an HDMI screen capture board, which they implemented on an FPGA.&lt;/p&gt;

&lt;p&gt;He recommended to watch another talk from 28C3 called “Implementation of mitm attack on hdcp-secured links”.
Also a website filled with FPGA resources: &lt;a href=&quot;http://hamsterworks.co.nz/mediawiki/index.php/Main_Page&quot;&gt;hamsterworks&lt;/a&gt;
He also mentions a talk at PyCon AU about designing hardware with FPGAs.&lt;/p&gt;

&lt;h2 id=&quot;the-moon-and-european-space-exploration&quot;&gt;The Moon and European Space Exploration&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;Since the early successes of moon missions in the Sixtie, mankind has moved on to the earth orbit and other deep space missions.
But interest in the moon as a target has intensified recently as the strategies for future missions are evolving.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;video&quot;&gt;
&lt;iframe width=&quot;640&quot; height=&quot;360&quot; src=&quot;https://www.youtube.com/embed/xMm1g8RPR8E?ecver=1&quot; frameborder=&quot;0&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;p&gt;Jan Wörner is the director of the European Space Program.
In this talk he tries to answer the question “Why are we studying space?”
I recommend it to everybody; the talk is fun and not technical.&lt;/p&gt;

&lt;h2 id=&quot;interplanetary-colonization&quot;&gt;Interplanetary Colonization&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;The long term survival of the human species requires that we become an interplanetary species.
But we must answer two big questions: where are we going, and how do we get there?
We explore what scientists know (and don’t know) about humanity’s potential future homes both inside and outside the solar system, and then we’ll dive into the technological challenges of (and potential solutions for) getting humans to and colonizing a new planet.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;video&quot;&gt;
&lt;iframe width=&quot;640&quot; height=&quot;360&quot; src=&quot;https://www.youtube.com/embed/7ioCa4ILEbo?ecver=1&quot; frameborder=&quot;0&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;p&gt;Quick intro to how can we move from planets to planets to colonize them.
Not very technical, but I did not enjoy it as much as the previous one.&lt;/p&gt;

&lt;h2 id=&quot;the-zcash-anonymous-cryptocurrency&quot;&gt;The Zcash anonymous cryptocurrency&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;Zcash is the third iteration of an extension to the Bitcoin protocol that provides true untraceability, i.e. fully anonymous transactions.
It is arguably the first serious attempt to establish this extension, in the form of its own blockchain, beyond the form of an academic proposal.
The talk provides an introduction to the magic that makes it work.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;video&quot;&gt;
&lt;iframe width=&quot;640&quot; height=&quot;360&quot; src=&quot;https://www.youtube.com/embed/7MZva8lGejo?ecver=1&quot; frameborder=&quot;0&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;p&gt;I need to rewatch that one to fully understand the math behind Zcash.
It looked interesting, but I am into crypto; skip if you are not.&lt;/p&gt;

&lt;h2 id=&quot;community&quot;&gt;Community&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;Mitch Altman (born December 22, 1956) is a San Francisco-based hacker and inventor, best known for inventing TV-B-Gone, as featured speaker at hacker conferences, as international expert on the hackerspace movement, and for teaching introductory electronics workshops.
He is also Chief Scientist and CEO of Cornfield Electronics.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;video&quot;&gt;
&lt;iframe width=&quot;640&quot; height=&quot;360&quot; src=&quot;https://www.youtube.com/embed/YG5dKksAyFI?ecver=1&quot; frameborder=&quot;0&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;p&gt;In this talk, Mitch Altman tells us the story of how he entered the hacker scene.
The guy is influential and his message definitely resonated with me.
However, it also revealed that he has some strong bias, against the government for example, which I don’t agree with.&lt;/p&gt;

&lt;h2 id=&quot;retail-surveillance--retail-countersurveillance&quot;&gt;Retail Surveillance / Retail Countersurveillance&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;From geo-magnetic tracking for smartphones to facial recognition for email marketing, from physical shopping cart fingerprinting to computer vision algorithms that use your clothing as metadata, this talk will explore the emerging landscape of hyper-competitive retail surveillance.
Instead of dramatizing these technologies which can lead to calcification and normalization, the aim of this talk is to energize discourse around building creative solutions to counter, adapt to, or rethink emerging surveillance technologies.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;video&quot;&gt;
&lt;iframe width=&quot;640&quot; height=&quot;360&quot; src=&quot;https://www.youtube.com/embed/LLKmyY5ujeU?ecver=1&quot; frameborder=&quot;0&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;p&gt;Those projects are about defeating common surveillance techniques through fashion and makeup.
I liked the concepts, they are very cyberpunk-ish.&lt;/p&gt;

&lt;h2 id=&quot;the-ultimate-gameboy-talk&quot;&gt;The Ultimate Gameboy talk&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;The 8-bit Game Boy was sold between 1989 and 2003, but its architecture more closely resembles machines from the early 1980s, like the Commodore 64 or the NES.
This talk attempts to communicate “everything about the Game Boy” to the listener, including its internals and quirks, as well as the tricks that have been used by games and modern demos, reviving once more the spirit of times when programmers counted clock cycles and hardware limitations were seen as a challenge.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;video&quot;&gt;
&lt;iframe width=&quot;640&quot; height=&quot;360&quot; src=&quot;https://www.youtube.com/embed/HyzD8pNlpwI?ecver=1&quot; frameborder=&quot;0&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;p&gt;Last talk I saw at the congress, with a packed audience.
Very well prepared, and communicates the effects used in Gameboy programming well.&lt;/p&gt;

&lt;h2 id=&quot;shining-some-light-on-the-amazon-dash-button&quot;&gt;Shining some light on the Amazon Dash button&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;This talk will explore the hard- and software of the Amazon Dash button.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;video&quot;&gt;
&lt;iframe width=&quot;640&quot; height=&quot;360&quot; src=&quot;https://www.youtube.com/embed/7he02D7Wqgk?ecver=1&quot; frameborder=&quot;0&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;h2 id=&quot;ps4-pc-master-race&quot;&gt;PS4: PC Master Race&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;Last year, we demonstrated Linux running on the PS4 in a lightning talk - presented on the PS4 itself.
But how did we do it? In a departure from previous Console Hacking talks focusing on security, this year we’re going to focus on the PS4 hardware, what makes it different from a PC, and how we reverse engineered it enough to get a full-blown Linux distro running on it, complete with 3D acceleration.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;video&quot;&gt;
&lt;iframe width=&quot;640&quot; height=&quot;360&quot; src=&quot;https://www.youtube.com/embed/QMiubC6LdTA?ecver=1&quot; frameborder=&quot;0&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;p&gt;Yay, more console hacking!
Very impressive technical level, learnt a lot about hardware and Linux kernel while watching this!&lt;/p&gt;

&lt;h1 id=&quot;talks-i-plan-to-watch-later&quot;&gt;Talks I plan to watch later&lt;/h1&gt;

&lt;p&gt;Since I did not have time to watch everything I wanted, I made a short list of the videos I am going to watch in the coming weeks:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://media.ccc.de/v/33c3-8127-how_do_i_crack_satellite_and_cable_pay_tv&quot;&gt;How Do I Crack Satellite and Cable Pay TV?&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://media.ccc.de/v/33c3-8295-the_fight_for_encryption_in_2016&quot;&gt;The Fight for Encryption in 2016&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://media.ccc.de/v/33c3-8338-building_a_high_throughput_low-latency_pcie_based_sdr&quot;&gt;Building a high throughput low-latency PCIe based SDR&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://media.ccc.de/v/33c3-8314-bootstraping_a_slightly_more_secure_laptop&quot;&gt;Bootstraping a slightly more secure laptop&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://media.ccc.de/v/33c3-8014-untrusting_the_cpu&quot;&gt;Untrusting the CPU&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://media.ccc.de/v/33c3-7904-software_defined_emissions&quot;&gt;Software Defined Emissions&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://media.ccc.de/v/33c3-7964-where_in_the_world_is_carmen_sandiego&quot;&gt;Where in the World Is Carmen Sandiego?&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://media.ccc.de/v/33c3-8061-you_can_-j_reject_but_you_can_not_hide_global_scanning_of_the_ipv6_internet&quot;&gt;You can -j REJECT but you can not hide: Global scanning of the IPv6 Internet&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://media.ccc.de/v/33c3-7909-syrian_archive&quot;&gt;Syrian Archive&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://media.ccc.de/v/33c3-8069-tapping_into_the_core&quot;&gt;Tapping into the core&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://media.ccc.de/v/33c3-7949-wheel_of_fortune&quot;&gt;Wheel of Fortune&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://media.ccc.de/v/33c3-7865-gone_in_60_milliseconds&quot;&gt;Gone in 60 Milliseconds&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://media.ccc.de/v/33c3-8074-recount_2016_an_uninvited_security_audit_of_the_u_s_presidential_election&quot;&gt;Recount 2016: An Uninvited Security Audit of the U.S. Presidential Election&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://media.ccc.de/v/33c3-8416-the_untold_story_of_edward_snowden_s_escape_from_hong_kong&quot;&gt;The Untold Story of Edward Snowden’s Escape from Hong Kong&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://media.ccc.de/v/33c3-7888-downgrading_ios_from_past_to_present&quot;&gt;Downgrading iOS: From past to present&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://media.ccc.de/v/33c3-7873-spinalhdl_an_alternative_hardware_description_language&quot;&gt;SpinalHDL : An alternative hardware description language&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://media.ccc.de/v/33c3-8099-how_do_we_know_our_prngs_work_properly&quot;&gt;How do we know our PRNGs work properly?&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://media.ccc.de/v/33c3-7945-decoding_the_lora_phy&quot;&gt;Decoding the LoRa PHY&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://media.ccc.de/v/33c3-8263-hacking_collective_as_a_laboratory&quot;&gt;Hacking collective as a laboratory&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://media.ccc.de/v/33c3-7975-making_technology_inclusive_through_papercraft_and_sound&quot;&gt;Making Technology Inclusive Through Papercraft and Sound&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://media.ccc.de/v/33c3-7853-do_as_i_say_not_as_i_do_stealth_modification_of_programmable_logic_controllers_i_o_by_pin_control_attack&quot;&gt;Do as I Say not as I Do: Stealth Modification of Programmable Logic Controllers I/O by Pin Control Attack&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Rebel cities&lt;/li&gt;
  &lt;li&gt;The High Priests of the Digital Age&lt;/li&gt;
  &lt;li&gt;Infrastructure review&lt;/li&gt;
  &lt;li&gt;The Transhumanist Paradox&lt;/li&gt;
&lt;/ul&gt;</content><author><name>Antoine Albertelli</name><email>antoinea101@gmail.com</email></author><summary type="html">I spent the time between Christmas and New Year in Hamburg, Germany, at the Chaos Communication Congress, 33rd edition (33C3 in short). 33C3’s motto was “Works for Me”, a phrase that everyone working in IT/engineering will hear at some point during their career. It quickly became a meme in the congress, showing up every time a presenter had a laptop issue for example.</summary></entry><entry><title type="html">Global Game Jam</title><link href="http://antoinealb.net/2017/01/24/ggj17.html" rel="alternate" type="text/html" title="Global Game Jam" /><published>2017-01-24T00:00:00+00:00</published><updated>2017-01-24T00:00:00+00:00</updated><id>http://antoinealb.net/2017/01/24/ggj17</id><content type="html" xml:base="http://antoinealb.net/2017/01/24/ggj17.html">&lt;p&gt;As last year, I took part in the local Global Game Jam chapter.
As last year, we had about 48 hours to create a video game about a specific theme, revealed at the beginning of the jam.
I took part with almost the same team as last year (kudos to them):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Eric and I would do the coding,&lt;/li&gt;
  &lt;li&gt;Chloé and Lionel would do the drawing,&lt;/li&gt;
  &lt;li&gt;Anthony would do the playing (both playing the game and sounds).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This time we were more prepared than last time: we met one week before the event to decide which kind of game we wanted to do.
We wanted something with more motion and more immediate fun than our first game, Duel of Wizard.
We wanted something where implementing a few rules and behavior would lead to something playable early, in order to be able to iterate.&lt;/p&gt;

&lt;p&gt;We decided to do a shoot them up type of game, which are fun to play and dynamic.
It would also be a good exercise in level / game design; designing the enemies, their patterns and the level around them would provide a nice break from just churning out code or assets.
On the technical side we would be using Phaser again.&lt;/p&gt;

&lt;p&gt;The result is &lt;em&gt;Apocalypse Miaou,&lt;/em&gt; a game in where you play a lion and a tiger who fight against enemies ruining their forest.
It is a bit too hard to finish, but it even features a boss!
You can watch the end result below or you can playtest it &lt;a href=&quot;http://edupertuis.net/ApocalypseMiaou/&quot;&gt;online&lt;/a&gt;.&lt;/p&gt;

&lt;div class=&quot;ytvideo&quot;&gt;
&lt;iframe width=&quot;854&quot; height=&quot;480&quot; src=&quot;https://www.youtube.com/embed/zzv6pK40rCI&quot; frameborder=&quot;0&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;p&gt;We learnt a lot about while creating &lt;em&gt;Apocalypse Miaou&lt;/em&gt;, about game programming (behaviors and entities), game design (some enemy patterns are really hard to avoid), and music (the game music is the first time Anthony composed something).
I would like to thank the Swiss Castle Jam Organizers, for this incredible event, and Anthony, Chloé and Lionel for hosting me.&lt;/p&gt;

&lt;p&gt;See you next year!&lt;/p&gt;</content><author><name>Antoine Albertelli</name><email>antoinea101@gmail.com</email></author><summary type="html">As last year, I took part in the local Global Game Jam chapter. As last year, we had about 48 hours to create a video game about a specific theme, revealed at the beginning of the jam. I took part with almost the same team as last year (kudos to them):</summary></entry><entry><title type="html">A value chain approach to understanding Open Source software</title><link href="http://antoinealb.net/2016/12/14/value-chain-open-source.html" rel="alternate" type="text/html" title="A value chain approach to understanding Open Source software" /><published>2016-12-14T00:00:00+00:00</published><updated>2016-12-14T00:00:00+00:00</updated><id>http://antoinealb.net/2016/12/14/value-chain-open-source</id><content type="html" xml:base="http://antoinealb.net/2016/12/14/value-chain-open-source.html">&lt;p&gt;Open Source is a way of developing products – usually software ones, although this is changing – in an open and public way.
To qualify as “proper” Open Source, a product must grant several key freedoms to its customers:
The user must be free to use the product, they must be free to copy the product, they must be free to study and modify the product.
This approach to software distribution started in the 1970s.
At first it only applied to research projects produced in universities, but in the 1990s it became used commercially, especially as backend (i.e. not user-facing) systems.
In recent years, Open Source software left the backend and is now very present even in customer facing products.&lt;/p&gt;

&lt;p&gt;A recent example is the one of Sun Microsystems: they used to develop proprietary systems but decided to open source the Java programming environment.
Java was then reused by several other companies, including Google, who use it for their Android phone operating system (an open source project in itself).
Sun was then bought by Oracle in 2009, due to financial problems.
This begs the question: why was this Sun’s strategy?
Surely, they could have earned a lot more by selling a license for Java, if their product was good.
In this essay, I try to take a look at the Open Source movement from a value chain perspective in order to explain this kind of behavior.
Value chain analysis is concerned with three aspects: value creation, value capture and the global network surrounding those processes.&lt;/p&gt;

&lt;p&gt;We must first ask how are open source products creating value when compared to proprietary one.
First, the open source solution can be cheaper than the proprietary one through a process of &lt;em&gt;commodification&lt;/em&gt;:
some parts of modern IT systems are not a key strategic advantage anymore, for example web servers or operating systems.
Therefore, it makes sense economically to split the development costs with other actors.&lt;/p&gt;

&lt;p&gt;From the customer’s perspective, open source software has an increased value because it reduces risks associated to vendor lock-in.
Proprietary solutions can become a liability when the development is stopped by its vendor.
Open source, on the other hand, allows the user to continue fixing bugs and go on with their operations.&lt;/p&gt;

&lt;p&gt;We now need to understand how a company can capture value by releasing their intellectual property as open source.
Obviously standard methods of selling licenses cannot be used: since the freedom to copy the product is guaranteed without conditions, it is not possible to sell it “as is”.&lt;/p&gt;

&lt;p&gt;One business model which circumvents that limitation is the use of so called “dual licenses”:
the idea is to offer the product as open source but with limitations which might not be acceptable by commercial users.
A commercial license is then offered which removes the limitations.
The most common limitation is to force one company to release their complete product as open source if it includes open source component.&lt;/p&gt;

&lt;p&gt;The second commonly used business model around open source products is the sales of complementors, e.g support contracts or additional features.
This is the approach chosen by Google for their Android system.
By providing phone manufacturers with a high quality open-source model, they attracted users to their platform.
They could then try to sell those users their more lucrative products such as personalized advertisements.&lt;/p&gt;

&lt;p&gt;From a network perspective, open source has a lot for it.
Obviously it eases existing forms of collaboration between actors in a value network, through the process of commodification explained before.&lt;/p&gt;

&lt;p&gt;However it also creates new interesting connections:
users of an open source product can now contribute back to the product they use.
They leave the role of being a pure customer to being directly involved in the creation.
They don’t contribute their solution to the project for the “greater good”, but for economical reasons.
It is usually cheaper to integrate a change into the original project than to maintain a list of changes internal to the company (a practice called “forking”)&lt;/p&gt;

&lt;p&gt;Sharing technology through open source also allows company to find engineers already well-knowledgeable on a given technology.
This reduces their time to market and allow them to scale their staff easily, by only having to train them on in-house, key technologies.
On the other hand engineers also benefit from this, by being able to take their experience with them to a new employer without violating an eventual non disclosure agreement.&lt;/p&gt;

&lt;p&gt;Looking at the open source economy from a network point of view also reveals that software companies have their own form of the “smiley curve”.
The smiley curve was proposed by Stan Shih, founder of Acer, in the early 90s.
He theorized that both ends of the value chain (design and distribution) were much more profitable activities than in the center (manufacturing).
Software companies tend to follow a similar pattern: selling application and user-facing services has a lot more value than selling operating systems.
A good example of this is Microsoft of which most value comes from their Office suite and not from the Windows operating system.
Therefore, it makes sense to try to be at the end of the value chain while avoiding the middle of the technological stack, sharing the cost with other companies.&lt;/p&gt;

&lt;p&gt;In conclusion, we see that the tendency for companies to release some of their software as open source can be explained by a value chain approach.
We also see that open source can increase the value captured by a company, especially in higher value activities.
Similar effects are already emerging in the field of open hardware, and time will tell if this trend continues its rise.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This essay was originally written for a class at EPFL. Thanks to &lt;a href=&quot;http://guidoalb.ch&quot;&gt;Guido Albertelli&lt;/a&gt; for his feedback before putting it online.&lt;/em&gt;&lt;/p&gt;</content><author><name>Antoine Albertelli</name><email>antoinea101@gmail.com</email></author><summary type="html">Open Source is a way of developing products – usually software ones, although this is changing – in an open and public way. To qualify as “proper” Open Source, a product must grant several key freedoms to its customers: The user must be free to use the product, they must be free to copy the product, they must be free to study and modify the product. This approach to software distribution started in the 1970s. At first it only applied to research projects produced in universities, but in the 1990s it became used commercially, especially as backend (i.e. not user-facing) systems. In recent years, Open Source software left the backend and is now very present even in customer facing products.</summary></entry><entry><title type="html">Using Dnsmasq for VM testing</title><link href="http://antoinealb.net/2016/07/04/dnsmasq-for-local-dev-osx.html" rel="alternate" type="text/html" title="Using Dnsmasq for VM testing" /><published>2016-07-04T00:00:00+00:00</published><updated>2016-07-04T00:00:00+00:00</updated><id>http://antoinealb.net/2016/07/04/dnsmasq-for-local-dev-osx</id><content type="html" xml:base="http://antoinealb.net/2016/07/04/dnsmasq-for-local-dev-osx.html">&lt;p&gt;Today I was trying a new configuration option for Gitlab and I wanted to make sure I did not make any mistakes before trying the site live.
Therefore I decided to deploy the configuration in a virtual machine and then copy it on the live server.&lt;/p&gt;

&lt;p&gt;To access the page served by the VM two conditions needed to be met:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;The HTTP port should be forwarded to be available on the host.
 &lt;a href=&quot;https://www.vagrantup.com/&quot;&gt;Vagrant&lt;/a&gt; makes it extremely easy, take a look at this tool if you don’t know it already.&lt;/li&gt;
  &lt;li&gt;The virtual machine should be accessible under the domain given to Gitlab’s web server.
 Simply typing the IP address might not work because a single web server might be configured to serve different sites depending on the domain.
 This part is usually done by hacking &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/etc/hosts&lt;/code&gt; to resolve the chosen name to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;127.0.0.1&lt;/code&gt; but I decided to try using Dnsmasq for this after reading &lt;a href=&quot;https://passingcuriosity.com/2013/dnsmasq-dev-osx/&quot;&gt;a blog post about it&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;what-is-dnsmasq-&quot;&gt;What is Dnsmasq ?&lt;/h2&gt;

&lt;p&gt;Among other things, Dnsmasq can act as a DNS caching server.
This can be used to increase resolution speed, or, in our case, to inject fake DNS records into our network.
Specifically, I will use to resolve all &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.dev&lt;/code&gt; domains to my own machine.&lt;/p&gt;

&lt;h2 id=&quot;installing-dnsmasq-on-osx&quot;&gt;Installing Dnsmasq on OSX&lt;/h2&gt;
&lt;p&gt;Using Homebrew installing Dnsmasq is relatively easy: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;brew install dnsmasq&lt;/code&gt;.
I decided to track the configuration in my &lt;a href=&quot;https://github.com/antoinealb/dotfiles&quot;&gt;dotfiles repository&lt;/a&gt; and to symlink the actual file to the versioned one:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;cp&lt;/span&gt; /usr/local/opt/dnsmasq/dnsmasq.conf.example ~/dotfiles/dnsmasq.conf
&lt;span class=&quot;nb&quot;&gt;sudo ln&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-s&lt;/span&gt; ~/dotfiles/dnsmasq.conf /usr/local/etc/dnsmasq.conf&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h2 id=&quot;configuring-the-dns-server&quot;&gt;Configuring the DNS server&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;Note:&lt;/em&gt; you can find the latest version of the file &lt;a href=&quot;https://github.com/antoinealb/dotfiles/blob/master/dnsmasq.conf&quot;&gt;on Github&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The first step is to be a good netizen by disabling the forwarding of ill-formed domain names.
I don’t know if this is strictly required but the Dnsmasq example guide suggests enabling it.
We will also only allow requests coming from localhost for security reasons.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-conf&quot; data-lang=&quot;conf&quot;&gt;&lt;span class=&quot;c&quot;&gt;# Never forward plain names (without a dot or domain part)
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;domain&lt;/span&gt;-&lt;span class=&quot;n&quot;&gt;needed&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# Never forward addresses in the non-routed address spaces.
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;bogus&lt;/span&gt;-&lt;span class=&quot;n&quot;&gt;priv&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;# Only allow localhost requests
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;listen&lt;/span&gt;-&lt;span class=&quot;n&quot;&gt;address&lt;/span&gt;=&lt;span class=&quot;m&quot;&gt;127&lt;/span&gt;.&lt;span class=&quot;m&quot;&gt;0&lt;/span&gt;.&lt;span class=&quot;m&quot;&gt;0&lt;/span&gt;.&lt;span class=&quot;m&quot;&gt;1&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Then we will add the redirection rules.
We only have one, i.e. sending all &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.dev&lt;/code&gt; to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;127.0.0.1&lt;/code&gt;.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-conf&quot; data-lang=&quot;conf&quot;&gt;&lt;span class=&quot;c&quot;&gt;# Add domains which you want to force to an IP address here.
# Sends all domain ending in .dev to localhost
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;address&lt;/span&gt;=/&lt;span class=&quot;n&quot;&gt;dev&lt;/span&gt;/&lt;span class=&quot;m&quot;&gt;127&lt;/span&gt;.&lt;span class=&quot;m&quot;&gt;0&lt;/span&gt;.&lt;span class=&quot;m&quot;&gt;0&lt;/span&gt;.&lt;span class=&quot;m&quot;&gt;1&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;After restarting Dnsmasq (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sudo brew services restart dnsmasq&lt;/code&gt;), you should be able to test your config by running &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dig foo.dev @localhost&lt;/code&gt;.
If you get an answer mapping to 127.0.0.1, everything is working!&lt;/p&gt;

&lt;h2 id=&quot;sending-dns-requests-to-dnsmasq&quot;&gt;Sending DNS requests to Dnsmasq&lt;/h2&gt;
&lt;p&gt;This step if pretty straightforward: Open System Preferences, go to “Network”, then click “Advanced…” and add &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;127.0.0.1&lt;/code&gt; to your servers under the “DNS” tab.
Don’t forget to click apply once you left the advanced settings!
Now you should be able to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ping foo.dev&lt;/code&gt;, however normal websites won’t be recognized anymore.&lt;/p&gt;

&lt;h2 id=&quot;adding-upstream-servers&quot;&gt;Adding upstream servers&lt;/h2&gt;
&lt;p&gt;The &lt;a href=&quot;https://passingcuriosity.com/2013/dnsmasq-dev-osx/&quot;&gt;original guide&lt;/a&gt; chooses to send &lt;em&gt;only&lt;/em&gt; the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.dev&lt;/code&gt; queries to Dnsmasq, but I preferred to add upstream servers to my config.
Upstream DNS servers are queried when Dnsmasq doesn’t know how to resolve a given query.
Enabling them means that DNS queries will be cached, making them slightly faster.
It also means that you don’t have to fumble with OSX files such as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/etc/resolver/&lt;/code&gt;, which is forbidden by El Capitan (I haven’t updated my laptop to El Capitan though).&lt;/p&gt;

&lt;p&gt;To enable upstream servers add the following to your &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dnsmasq.conf&lt;/code&gt;.
I chose to use two different DNS providers for reliability reasons (Google DNS and OpenDNS).&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-conf&quot; data-lang=&quot;conf&quot;&gt;&lt;span class=&quot;c&quot;&gt;# Upstream DNS servers
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;server&lt;/span&gt;=&lt;span class=&quot;m&quot;&gt;8&lt;/span&gt;.&lt;span class=&quot;m&quot;&gt;8&lt;/span&gt;.&lt;span class=&quot;m&quot;&gt;8&lt;/span&gt;.&lt;span class=&quot;m&quot;&gt;8&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;server&lt;/span&gt;=&lt;span class=&quot;m&quot;&gt;8&lt;/span&gt;.&lt;span class=&quot;m&quot;&gt;8&lt;/span&gt;.&lt;span class=&quot;m&quot;&gt;4&lt;/span&gt;.&lt;span class=&quot;m&quot;&gt;4&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;server&lt;/span&gt;=&lt;span class=&quot;m&quot;&gt;208&lt;/span&gt;.&lt;span class=&quot;m&quot;&gt;67&lt;/span&gt;.&lt;span class=&quot;m&quot;&gt;222&lt;/span&gt;.&lt;span class=&quot;m&quot;&gt;222&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;server&lt;/span&gt;=&lt;span class=&quot;m&quot;&gt;208&lt;/span&gt;.&lt;span class=&quot;m&quot;&gt;67&lt;/span&gt;.&lt;span class=&quot;m&quot;&gt;220&lt;/span&gt;.&lt;span class=&quot;m&quot;&gt;220&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Restart Dnsmasq and voilà!
You are now able to ping google.com and foo.dev should resolve to localhost.
You can now configure your virtual server as foo.dev and it should correctly answer, but that is left as an exercise to the reader ;)&lt;/p&gt;</content><author><name>Antoine Albertelli</name><email>antoinea101@gmail.com</email></author><summary type="html">Today I was trying a new configuration option for Gitlab and I wanted to make sure I did not make any mistakes before trying the site live. Therefore I decided to deploy the configuration in a virtual machine and then copy it on the live server.</summary></entry><entry><title type="html">Using GCC’s Stack Smashing Protector on microcontrollers</title><link href="http://antoinealb.net/programming/2016/06/01/stack-smashing-protector-on-microcontrollers.html" rel="alternate" type="text/html" title="Using GCC’s Stack Smashing Protector on microcontrollers" /><published>2016-06-01T00:00:00+00:00</published><updated>2016-06-01T00:00:00+00:00</updated><id>http://antoinealb.net/programming/2016/06/01/stack-smashing-protector-on-microcontrollers</id><content type="html" xml:base="http://antoinealb.net/programming/2016/06/01/stack-smashing-protector-on-microcontrollers.html">&lt;p&gt;Writing your code in C means manual memory management means a lot of bug types: Double free, use after free, stack overflow, etc.
Those bugs can be especially hard to debug because they will cause erratic behavior but might not trigger an error condition immediately.&lt;/p&gt;

&lt;p&gt;I recently added a memory protection unit (MPU) driver that I used to detect NULL pointer dereference.
This (combined with other patches) significantly increased the stability of our platform, but we still had occasional issues.&lt;/p&gt;

&lt;p&gt;In order to debug those, I wanted to add more memory hardening to the system.
I started with the stack smashing detection, since it was the easiest.&lt;/p&gt;

&lt;h1 id=&quot;what-is-stack-smashing-&quot;&gt;What is stack smashing ?&lt;/h1&gt;

&lt;p&gt;To quote Wikipedia:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;In computer security and programming, a buffer overflow, or buffer overrun, is an anomaly where a program, while writing data to a buffer, overruns the buffer’s boundary and overwrites adjacent memory locations.
This is a special case of the violation of memory safety.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Stack smashing is a class of buffer overflow which occurs on stack-allocated buffers.
It can be used by an attacker to gain code execution by modifying a function return address.
That is not a concern on our robot, but it can be an issue if you are developing an Internet-connected product.&lt;/p&gt;

&lt;p&gt;Consider the following code:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-c&quot; data-lang=&quot;c&quot;&gt;&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;my_buggy_function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user_provided_message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;buffer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;strcpy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;buffer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user_provided_message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;In this overly simplificated example, if the user provided message is longer than nine characters (plus terminating zero), then the copy will overflow from the buffer into following variables.
An attacker could use this to override the function return address, gaining code execution.&lt;/p&gt;

&lt;h2 id=&quot;how-does-stack-smashing-protection-work-&quot;&gt;How does Stack Smashing Protection work ?&lt;/h2&gt;
&lt;p&gt;Stack Smashing Protection (SSP) tries to prevent most of those bugs by adding an extra variable (called a canary) in every function.
On function entry this canary is set to a value and on function exit the canary’s value is checked.
If it has changed during function execution it means the stack has been smashed and a callback is fired.&lt;/p&gt;

&lt;p&gt;Of course SSP cannot detect every buffer overflow but it is still better than nothing for debugging.
It also effectively closes a whole class of security flaws if correctly implemented.
However, it has a (small) runtime cost, which might be a problem depending on your requirements.&lt;/p&gt;

&lt;h1 id=&quot;enabling-ssp&quot;&gt;Enabling SSP&lt;/h1&gt;
&lt;p&gt;Turning on SSP with GCC is quite easy: Just add &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-fstack-protector-all&lt;/code&gt; to your CFLAGS.
You might also be interested in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-fstack-protector&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-fstack-protector-strong&lt;/code&gt; which use some heuristics to exclude some functions from being checked.&lt;/p&gt;

&lt;p&gt;So let’s build and see how it goes:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;arm-none-eabi/bin/ld: cannot find &lt;span class=&quot;nt&quot;&gt;-lssp_nonshared&lt;/span&gt;
arm-none-eabi/bin/ld: cannot find &lt;span class=&quot;nt&quot;&gt;-lssp&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Apparently some libraries are missing.&lt;/p&gt;

&lt;h2 id=&quot;adding-missing-libraries&quot;&gt;Adding missing libraries&lt;/h2&gt;
&lt;p&gt;A bit of Googling teaches me that I should be able to circumvent that problem by linking against empty static libraries instead.
First, ask GCC to look for libraries in the current folder by adding &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-L .&lt;/code&gt; to your &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LDFLAGS&lt;/code&gt;.
Then, create empty &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;libssp.a&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;libssp_nonshared.a&lt;/code&gt; using the following commands:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;arm-none-eabi-ar rcs libssp.a
arm-none-eabi-ar rcs libssp_nonshared.a&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Now, rebuild the project and GCC should complain about missing references to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;__stack_chk_guard&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;__stack_chk_fail&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&quot;writing-the-stack-smashing-protector-callback&quot;&gt;Writing the Stack Smashing protector callback&lt;/h2&gt;
&lt;p&gt;To work correctly SSP requires two symbols to be defined:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;__stack_chk_guard&lt;/code&gt; which contains the initial value of the stack protector, and,&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;__stack_chk_fail&lt;/code&gt; which is called when a stack smashing is detected.
  This function should never return.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is a minimal implementation for ChibiOS but adapting it to your platform should be trivial.
Just be careful to adapt &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;STACK_CHK_GUARD&lt;/code&gt; to the word width of your architecture (the example is for 32 bits).&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-c&quot; data-lang=&quot;c&quot;&gt;&lt;span class=&quot;kt&quot;&gt;uintptr_t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;__stack_chk_guard&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mh&quot;&gt;0xdeadbeef&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;__stack_chk_fail&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;chSysHalt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Stack smashing detected&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;If you want to make your system harder to exploit I recommend setting &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;__stack_chk_guard&lt;/code&gt; to a random value on every boot using the hardware random number generator found in recent microcontrollers.
Otherwise an attacker might be able to find the value of your stack canary and exploit this knowledge to circumvent this protection.&lt;/p&gt;

&lt;h1 id=&quot;testing-the-protection&quot;&gt;Testing the protection&lt;/h1&gt;
&lt;p&gt;We are now able to check if the stack smashing protection works correctly by running the following function:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-c&quot; data-lang=&quot;c&quot;&gt;&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;buffer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;strcpy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;buffer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;hello, I am smashing your stack!&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;If everything goes well your panic handler should be called on function exit (check that with a debugger).
If it doesn’t, try to reduce optimization level or check your console output for any warning/error messages.&lt;/p&gt;

&lt;h1 id=&quot;conclusion--future-work&quot;&gt;Conclusion &amp;amp; Future work&lt;/h1&gt;
&lt;p&gt;SSP is one of the numerous tool you can use to make your code more secure.
It has the advantage of being easy to apply to your whole codebase at once since it does not require any change to your source code.&lt;/p&gt;

&lt;p&gt;I plan to add other other debugging features in the following weeks.
I have an idea on how to use the MPU to prevent thread stack overflows (different from the buffer stack overflow we explored today).
I also would like to implement heap corruption detection but I don’t know how I will do this yet.
If anybody has done this before I would be glad to hear about it.&lt;/p&gt;

&lt;h1 id=&quot;edit-21st-june-2016&quot;&gt;Edit 21st june 2016&lt;/h1&gt;

&lt;p&gt;I realized that &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.a&lt;/code&gt; files cannot be shared accross machines.
I modified my build process to generate the required files automatically by adding the following lines to my &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Makefile&lt;/code&gt;:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-make&quot; data-lang=&quot;make&quot;&gt;&lt;span class=&quot;nl&quot;&gt;libssp.a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;
	arm-none-eabi-ar rcs &lt;span class=&quot;nv&quot;&gt;$@&lt;/span&gt;
&lt;span class=&quot;nl&quot;&gt;libssp_nonshared.a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;
	arm-none-eabi-ar rcs &lt;span class=&quot;nv&quot;&gt;$@&lt;/span&gt;

&lt;span class=&quot;nl&quot;&gt;myproject.elf&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;libssp.a libssp_nonshared.a&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;</content><author><name>Antoine Albertelli</name><email>antoinea101@gmail.com</email></author><category term="Programming" /><category term="c" /><category term="arm" /><summary type="html">Writing your code in C means manual memory management means a lot of bug types: Double free, use after free, stack overflow, etc. Those bugs can be especially hard to debug because they will cause erratic behavior but might not trigger an error condition immediately.</summary></entry><entry><title type="html">10/10, will do again</title><link href="http://antoinealb.net/2016/02/01/ggj16.html" rel="alternate" type="text/html" title="10/10, will do again" /><published>2016-02-01T00:00:00+00:00</published><updated>2016-02-01T00:00:00+00:00</updated><id>http://antoinealb.net/2016/02/01/ggj16</id><content type="html" xml:base="http://antoinealb.net/2016/02/01/ggj16.html">&lt;p&gt;Last weekend I took part in the global game jam chapter organized in my home town.
For those who don’t know the concepts of a game jam, it is a type of events where team gathers to make a game in 48h.
The global in the name means that it simultaneously takes place all over the world, both remotely and with physical gatherings.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/media/ggj16/DuelOfWizards.png&quot; alt=&quot;Duel of wizards screenshot&quot; /&gt;
&lt;em&gt;Screenshot of our game, “Duel of Wizards”&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I took part in the jam with 5 friends I knew from before.
Our main goal was to be able to ship “something”, given that none of us made a game before.
We decided to develop a card game based on the “draft” mechanism: each player picks a card from a set, then gives the set to the opponent who picks a card and passes it back until the set is empty.
If you want to try it, you can play it &lt;a href=&quot;http://edupertuis.net/DuelOfWizards&quot;&gt;in your browser.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The team was quickly divided into three parts:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;@ericdupertuis and myself were going to be the game programmers.&lt;/li&gt;
  &lt;li&gt;Two friends (Anthony and Maëlick) would be our game designers.
 This was a hard task since none of us had experience and it has a lot of impact on the finished game.
 They also ended up choosing the music for the game and writing the booklet for the physical version of the game.&lt;/li&gt;
  &lt;li&gt;The last two team members (Lionel and Chloé) would be our graphics team, making the awesome assets (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;3&lt;/code&gt;) of our game.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The experience was a blast, and everybody in the team loved it as well!
Sadly our game concept wasn’t as catchy as we hoped and the games were too long to stay interesting.
This is largely due to our lack of experience making games, and I am sure we will become better with time.&lt;/p&gt;

&lt;p&gt;Related to the point above, I think we should have done more iterative design.
The coolest part of the jam was when we were integrating the assets, redoing the layout or improving the game and it felt like every 30 min someone had something cool to show to the others.
Doing iterations sooner may have also allowed us to iterate on the gameplay.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Lessons learnt for the next jam:&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Try to have a playable version early on to catch gameplay problems.&lt;/li&gt;
  &lt;li&gt;Our game engine was a little bit too basic, or maybe inappropriate for what we wanted to do.
 We were only able to have a working GUI and start playing rounds of our game after a day.
 This is way too long to see if a concept is fun or not.&lt;/li&gt;
  &lt;li&gt;Related to previous point: Choose the type of game we want to make before the jam and choose appropriate technologies before.&lt;/li&gt;
  &lt;li&gt;Study your tools: I realized after the jam that we reimplemented stuff that was already in the engine, such as game states.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;UPDATE&lt;/strong&gt;: @EricDupertuis posted &lt;a href=&quot;http://edupertuis.net/2016/02/02/ggj16.html&quot;&gt;his own writeup&lt;/a&gt; of the jam.&lt;/p&gt;</content><author><name>Antoine Albertelli</name><email>antoinea101@gmail.com</email></author><summary type="html">Last weekend I took part in the global game jam chapter organized in my home town. For those who don’t know the concepts of a game jam, it is a type of events where team gathers to make a game in 48h. The global in the name means that it simultaneously takes place all over the world, both remotely and with physical gatherings.</summary></entry></feed>