<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>shapeshifter.se</title>
	<atom:link href="http://www.shapeshifter.se/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.shapeshifter.se</link>
	<description>Mostly miscellaneous technical mumbo-jumbo.</description>
	<lastBuildDate>Mon, 11 Jul 2011 14:19:15 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Pre-compressed JavaScript files</title>
		<link>http://www.shapeshifter.se/2009/11/08/pre-compressed-javascript-files/</link>
		<comments>http://www.shapeshifter.se/2009/11/08/pre-compressed-javascript-files/#comments</comments>
		<pubDate>Sun, 08 Nov 2009 11:54:54 +0000</pubDate>
		<dc:creator>fli</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[gzip]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[thttpd]]></category>

		<guid isPermaLink="false">http://www.shapeshifter.se/?p=671</guid>
		<description><![CDATA[You can save bandwidth by pre-compressing your JavaScript files with gzip without relying on dynamic compression such as mod_deflate.  To to this properly and having it working across all browsers you&#8217;ll need to modify your webserver to return the correct mime type and encoding for the file.
Most browsers are quite liberal in what they accept, [...]]]></description>
			<content:encoded><![CDATA[<p>You can save bandwidth by pre-compressing your JavaScript files with gzip without relying on dynamic compression such as mod_deflate.  To to this properly and having it working across all browsers you&#8217;ll need to modify your webserver to return the correct mime type and encoding for the file.</p>
<p>Most browsers are quite liberal in what they accept, except for Safari/Konqueror. For some reason it doesn&#8217;t like it if a JavaScript file ends in .gz, it ignores the content-encoding and attempts to read the compressed data as JavaScript. The key to make it work is to create a new extension, for example .jgz and set the Content-Encoding for this extension to gzip AND to set the mime type of .js to text/javascript, not text/plain or application/x-javascript.</p>
<p>To recap, call the file script.js.jgz and make sure your webserver delivers it with the following options</p>
<blockquote><pre>
Content-Encoding: gzip
Content-Type: text/javascript</pre>
</blockquote>
<p>Just include the file as usual</p>
<blockquote><pre>
&lt;script type="text/javascript" src="script.js.jgz"&gt;&lt;/script&gt;
</pre>
</blockquote>
<p>This has been tested with the following browsers</p>
<ul>
<li>Firefox 3.0/3.5</li>
<li>Opera 10</li>
<li>Internet Explorer 7</li>
<li>Konqueror (webkit based, behaves like Safari)</li>
<li>Google Chrome 3</li>
<li>Epiphany</li>
</ul>
<h3>Apache</h3>
<p>Put the following in a .htaccess file</p>
<blockquote><pre>
AddType text/javascript .js
AddEncoding gzip .jsz</pre>
</blockquote>
<h3>thttpd</h3>
<p>Add jsz gzip to mime_encodings.txt and change the type for js in mime_types.txt to js text/javascript.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shapeshifter.se/2009/11/08/pre-compressed-javascript-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VirtualBox hacking</title>
		<link>http://www.shapeshifter.se/2009/08/21/virtualbox-hacking/</link>
		<comments>http://www.shapeshifter.se/2009/08/21/virtualbox-hacking/#comments</comments>
		<pubDate>Fri, 21 Aug 2009 14:55:04 +0000</pubDate>
		<dc:creator>fli</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[VirtualBox]]></category>

		<guid isPermaLink="false">http://www.shapeshifter.se/?p=661</guid>
		<description><![CDATA[VirtualBox (host mode) was quite recently ported to FreeBSD, some bits are still missing particular network support. So I spent the last couple of days hacking on it and how have a working implementation that supports bridged adapters.
Update 10 Sep: The patches have been committed upstreams. 
Update 9 Sep: working vboxnetadp and patchset sent upstreams.
Update: [...]]]></description>
			<content:encoded><![CDATA[<p>VirtualBox (host mode) was quite recently ported to FreeBSD, some bits are still missing particular network support. So I spent the last couple of days hacking on it and how have a working implementation that supports bridged adapters.</p>
<p>Update 10 Sep: <a href="http://www.virtualbox.org/changeset/22875">The patches have been committed upstreams. </a><br />
Update 9 Sep: working vboxnetadp and patchset sent upstreams.<br />
Update: Re-written to use netgraph, now works on FreeBSD 7 and 8</p>
<p>Patches can be found at</p>
<p><a href="http://www.shapeshifter.se/pub/patches/virtualbox/vbox-freebsd-netif-20090908.patch">http://www.shapeshifter.se/pub/patches/virtualbox/vbox-freebsd-netif-20090908.patch</a><br />
<a href="http://www.shapeshifter.se/pub/patches/virtualbox/vbox-freebsd-vboxnetadp-20090908.patch">http://www.shapeshifter.se/pub/patches/virtualbox/vbox-freebsd-vboxnetadp-20090908.patch</a><br />
<a href="http://www.shapeshifter.se/pub/patches/virtualbox/vbox-freebsd-vboxnetflt-20090908.patch">http://www.shapeshifter.se/pub/patches/virtualbox/vbox-freebsd-vboxnetflt-20090908.patch</a><br />
<a href="http://www.shapeshifter.se/pub/patches/virtualbox/Config.kmk-20090908.patch">http://www.shapeshifter.se/pub/patches/virtualbox/Config.kmk-20090908.patch</a><br />
<a href="http://www.shapeshifter.se/pub/patches/virtualbox/src-VBox-HostDrivers-Makefile.kmk-20090908.patch">http://www.shapeshifter.se/pub/patches/virtualbox/src-VBox-HostDrivers-Makefile.kmk-20090908.patch</a></p>
<p>Additional patches to test with the <strong>3.0.51.r22226</strong> version in FreeBSD ports.</p>
<p><a href="http://www.shapeshifter.se/pub/patches/virtualbox/Config.kmk-r22226-20090908.patch">http://www.shapeshifter.se/pub/patches/virtualbox/Config.kmk-r22226-20090908.patch</a><br />
<a href="http://www.shapeshifter.se/pub/patches/virtualbox/virtualbox-port-20090907.patch">http://www.shapeshifter.se/pub/patches/virtualbox/virtualbox-port-20090907.patch</a><br />
<a href="http://www.shapeshifter.se/pub/patches/virtualbox/ConsoleImpl2.cpp.patch">http://www.shapeshifter.se/pub/patches/virtualbox/ConsoleImpl2.cpp.patch</a></p>
<p>Re-install VirtualBox through ports using the following commands</p>
<blockquote>
<pre>
Apply/compile with
cd /usr/ports/emulators/virtualbox
make clean patch
mkdir work/virtualbox-3.0.51r22226/src/VBox/HostDrivers/VBoxNetFlt/freebsd
mkdir work/virtualbox-3.0.51r22226/src/VBox/HostDrivers/VBoxNetAdp/freebsd
patch < virtualbox-port-20090907.patch
patch -d work/virtualbox-3.0.51r22226/Config.kmk-r22226-20090908.patch
patch -d work/virtualbox-3.0.51r22226/ConsoleImpl2.cpp.patch
patch -d work/virtualbox-3.0.51r22226/src-VBox-HostDrivers-Makefile.kmk-20090908.patch
patch -d work/virtualbox-3.0.51r22226/vbox-freebsd-netif-20090908.patch
patch -d work/virtualbox-3.0.51r22226/vbox-freebsd-vboxnetadp-20090908.patch
patch -d work/virtualbox-3.0.51r22226/vbox-freebsd-vboxnetflt-20090908.patch
make install
</pre>
</blockquote>
<p>In VirtualBox network settings, under "Bridged Adapter" you should now see your available network interfaces. Select the one connected to your network and boot your virtual machine.  It should now be connected to your local network as any other machine.</p>
<p>Host only adapter mode can be used to create a virtual network with multiple guests, it creates a special vboxnetX adapter on the host. You'll have to do normal routing between this interface to get outside connectivity.</p>
<p>In addition to vboxdrv.ko you'll have to load vboxnetflt.ko and vboxnetadp.ko too.</p>
<blockquote>
<pre>
kldload /boot/modules/vboxnetflt.ko
kldload /boot/modules/vboxnetadp.ko
</pre>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.shapeshifter.se/2009/08/21/virtualbox-hacking/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>uhso(4): Option HSDPA driver for FreeBSD 8</title>
		<link>http://www.shapeshifter.se/2009/07/20/uhso4-option-hsdpa-driver-for-freebsd-8/</link>
		<comments>http://www.shapeshifter.se/2009/07/20/uhso4-option-hsdpa-driver-for-freebsd-8/#comments</comments>
		<pubDate>Mon, 20 Jul 2009 14:52:54 +0000</pubDate>
		<dc:creator>fli</dc:creator>
				<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[hsdpa]]></category>
		<category><![CDATA[hso]]></category>

		<guid isPermaLink="false">http://www.shapeshifter.se/?p=633</guid>
		<description><![CDATA[
A bit late, but here is the first beta of the Option HSDPA driver for FreeBSD 8. It&#8217;s more or less completely rewritten and there are some visible changes to the interface.
Because ucom(4) has matured it can now be utilized instead of mucking around directly with the TTY layer. This results in that the device [...]]]></description>
			<content:encoded><![CDATA[<p><!-- WSA: rules for context 'adsense-post-top' did not apply --></p>
<p>A bit late, but here is the first <strong>beta</strong> of the Option HSDPA driver for FreeBSD 8. It&#8217;s more or less completely rewritten and there are some visible changes to the interface.</p>
<p>Because ucom(4) has matured it can now be utilized instead of mucking around directly with the TTY layer. This results in that the device names in /dev has changed and are now longer called /dev/HSO*, instead they follow the standard ucom names of cuaU*.</p>
<p>The new USB stack attach USB devices per USB interface instead of per USB device, so it&#8217;s possible to get both a cuaU0 and cuaU1 device (instead of just cuaU0.0 and cuaU0.1). The number of found serial ports can be read through sysctl.</p>
<p>The packet interface is now exposed as a raw interface instead of emulating an Ethernet device (I seriously wonder why I did that&#8230;).</p>
<p>The driver switches automatically from install-cd mode to modem mode, there is no longer any need for manual switching through devd. Please remove the option-icon.conf file from your /usr/local/etc/devd directory.<br />
This can be disabled by setting hw.usb.uhso.auto_switch to 0</p>
<p>And last, I&#8217;ve renamed the driver to uhso to reflect its USB nature.</p>
<p>Download: <a href="/pub/hso/uhso-20091122.tar.gz">uhso-20091122.tar.gz</a> &#8211; Add support for iCON 505, fix probing of devices with dynamic number of interfaces, add new custom attach messages based on the port type.</p>
<p>Download: <a href="/pub/hso/uhsoctl-beta-20090820.tar.gz">uhsoctl-beta-20090820.tar.gz</a> &#8211; uhsoctl connection utility, similar to old hsoctl</p>
<p><span style="text-decoration: line-through;">Download: <a href="/pub/hso/uhso-beta-20090812.tar.gz">uhso-beta-20090812.tar.gz</a></span> &#8211; Minor bug fix and reworked sysctl nodes.</p>
<p><span style="text-decoration: line-through;">Download: <a href="/pub/hso/uhso-beta-20090723.tar.gz">uhso-beta-20090723.tar.gz</a></span> &#8211; No longer PTP interface (completely useless), fixed (hopefully) CDC notification on modem port, added several new device IDs. Thanks to Iain Hibbert for this!</p>
<p><span style="text-decoration: line-through;">Download: <a href="/pub/hso/uhso-beta-20090722.tar.gz">uhso-beta-20090722.tar.gz</a></span> &#8211; Bug fixes that should improve RX speed.</p>
<p><span style="text-decoration: line-through;">Download: <a href="/pub/hso/uhso-beta-20090720.tar.gz">uhso-beta-20090720.tar.gz</a></span></p>
<p><strong>If you own an Option device, please leave a comment (or send a mail) with its full name and USB device ID.</strong></p>
<p><strong>I&#8217;m particularly interested in the following devices iCON 031, iCON 210, iCON 315, iCON 322, iCON 401, iCON 431, iCON 451, iCON 452, iCON 505.</strong></p>
<p><strong>If you&#8217;re running FreeBSD 8 and own an Option device, please mail me the output of<br />
</strong></p>
<blockquote>
<pre>usbconfig -u X -a Y dump_device_desc
usbconfig -u X -a Y dump_all_config_desc</pre>
</blockquote>
<p>where X and Y (5 and 2 below) can be obtained through usbconfig</p>
<blockquote>
<pre># usbconfig
...
ugen5.2: &lt;Globetrotter HSDPA Modem Option N.V.&gt; at usbus5, cfg=0 md=HOST spd=FULL (12Mbps) pwr=ON</pre>
</blockquote>
<p><strong>This driver has been tested with a Globesurfer iCON 7.2, iCON 255, iCON 505<br />
</strong></p>
<p><strong>Quick setup for manual connection</strong><br />
<em>uhsoctl works as before!</em></p>
<p>Look up the serial ports</p>
<blockquote>
<pre># sysctl dev.uhso
dev.uhso.0.netif: uhso0
dev.uhso.0.type: Network/Serial
dev.uhso.0.ports: 2
dev.uhso.0.port.control.tty: cuaU0.0
dev.uhso.0.port.control.desc: Control
dev.uhso.0.port.application.tty: cuaU0.1
dev.uhso.0.port.application.desc: Application
...
dev.uhso.1.type: Serial
dev.uhso.1.ports: 1
dev.uhso.1.port.diagnostic.tty: cuaU1
dev.uhso.1.port.diagnostic.desc: Diagnostic</pre>
</blockquote>
<p>Open /dev/cuaU0.0 in a terminal application, for example minicom. Issue the following commands to establish a connection.</p>
<blockquote>
<pre>AT+CPIN="1234" # Your PIN
OK

AT_OWANCALL=1,1,1
OK

AT_OWANDATA=1
_OWANDATA: 1, 95.209.79.126, 0.0.0.0, 80.251.201.177, 80.251.201.178, 0.0.0.0, 0.0.0.0, 72000</pre>
</blockquote>
<p>If you haven&#8217;t configured a PDP context with your providers APN, please see the <a href="http://www.shapeshifter.se/code/hso/">hso page.</a></p>
<p>Configure the interface and set a default route</p>
<blockquote>
<pre># ifconfig uhso0 95.209.79.126
# route add default -interface uhso0</pre>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.shapeshifter.se/2009/07/20/uhso4-option-hsdpa-driver-for-freebsd-8/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>1-wire meets IPv6</title>
		<link>http://www.shapeshifter.se/2009/07/10/1-wire-meets-ipv6/</link>
		<comments>http://www.shapeshifter.se/2009/07/10/1-wire-meets-ipv6/#comments</comments>
		<pubDate>Fri, 10 Jul 2009 12:25:19 +0000</pubDate>
		<dc:creator>fli</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[1-wire]]></category>
		<category><![CDATA[AVR]]></category>
		<category><![CDATA[Ethernet]]></category>
		<category><![CDATA[IPv6]]></category>

		<guid isPermaLink="false">http://www.shapeshifter.se/?p=548</guid>
		<description><![CDATA[A project I&#8217;ve been hacking on for a while is a self-contained 1-wire to IPv6 bridge based on an Atmel AVR ATmega644 and the ENC28J60 Ethernet controller from Microchip.
1-wire: is a serial bus from Dallas Semiconductor/Maxim that only requires 1 data line, there are a number of cheap sensors and other devices for this bus. [...]]]></description>
			<content:encoded><![CDATA[<p>A project I&#8217;ve been hacking on for a while is a self-contained <a href="http://www.maxim-ic.com/products/1-wire/">1-wire</a> to IPv6 bridge based on an <a href="http://www.atmel.com/dyn/products/product_card.asp?PN=ATmega644P%20Automotive">Atmel AVR ATmega644</a> and the <a href="http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en022889">ENC28J60</a> Ethernet controller from Microchip.</p>
<p><strong>1-wire</strong>: is a serial bus from Dallas Semiconductor/Maxim that only requires 1 data line, there are a number of cheap sensors and other devices for this bus. The strength of this bus is not its speed but that it supports large ranges (up to 300 meters).<br />
Also, each 1-wire device has a permanent <em>unique</em> 64-bit serial number.</p>
<p><strong>IPv6</strong>: Insanely large address space. It&#8217;s common to use a 64-bit netmask for site networks so that <a href="http://en.wikipedia.org/wiki/EUI-64">EUI-64</a> based addresses can be used for auto configuration. This leaves 64-bit for the node address &#8211; do you see where this is going now&#8230; :)</p>
<p>Yes..I&#8217;ve built a device that assigned each 1-wire device it&#8217;s connected to its own IPv6 address. Why? you ask, mostly because I can.</p>
<p><!-- WSA: rules for context 'adsense-post-top' did not apply --></p>
<h3>Hardware</h3>
<p>As mentioned above, the device is based on an AVR ATmega644. It has 64KB of flash memory for program code and 4KB of RAM. It&#8217;s running on its built-in oscillator at 8MHz. The ENC28J60 Ethernet chip is connected to the AVR using SPI. The rest of the hardware is mostly for power distribution and management.</p>
<p>The PCB was manufactured by <a href="http://www.batchpcb.com/">BatchPCB</a>, cheap service but a bit slow turn-around time.</p>
<p><a href="http://www.shapeshifter.se/wp-content/uploads/2009/07/DSC00658.JPG"><img class="aligncenter size-medium wp-image-608" title="Populated PCB" src="http://www.shapeshifter.se/wp-content/uploads/2009/07/DSC00658-300x225.jpg" alt="Populated PCB" width="300" height="225" /></a></p>
<p>Unfortunately I  screwed up the SPI connection but I managed to fix that with some green wires (or black wires in this case). You&#8217;ll note them in the picture above.<br />
I also intended to run the AVR at 5V and the ethernet chip at 3.3V. This is what the quad AND-gate in the upper right<br />
corner was for, but since I screwed up the SPI routing it&#8217;s disconnected and the whole circuit is running at 3.3V.<br />
The ENC28J60 can only run at 3.3V, the AVR has a range from 2.8-5V and 1-wire should be ran at 5V but works at 3.3V. Hence the need for TTL voltage translation.</p>
<p>As for the 1-wire devices I had implemented a bus master in software that generated the require waveforms. It worked great up to about 10-15 meters. Any cable length greater than that refused to work.<br />
This was a bit unexpected and without an oscilloscope it was more or less impossible to figure out where and how the signals got mangled. So I simply got a <a href="http://www.maxim-ic.com/quick_view2.cfm/qv_pk/2923">DS2480</a> 1-wire line driver that generates the required signals in hardware with more precise timing.</p>
<div id="attachment_595" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.shapeshifter.se/wp-content/uploads/2009/07/DSC00725.JPG"><img class="size-medium wp-image-595" title="DSC00725" src="http://www.shapeshifter.se/wp-content/uploads/2009/07/DSC00725-300x189.jpg" alt="Add-on board with a 1-wire master" width="300" height="189" /></a><p class="wp-caption-text">Add-on board with a 1-wire master</p></div>
<p>This required an add-on board and because I didn&#8217;t want to wait for a new PCB I used a 2.54mm prototype board. With the DS2480 only available in SOIC8 packages it required some &#8220;creative&#8221; soldering :).<br />
The DS2480 required 5V, thus It had to get its own power supply and also required level translation on the UART line between this device and the AVR. I choose an approach using MOSFETs and a few resistors for this (the TO92 packages in the picture above). This turned out to work really good and I think I&#8217;m going to use this for the SPI level translation in the next revision of the board.<br />
The wire leaving the board on the left side leads to the 1-wire sensor devices.</p>
<p>The add-on board is extremely ugly. But hey, it works.</p>
<p>Future improvements for the next revision</p>
<ul>
<li>Use of external crystal at 16MHz instead of internal 8MHz clock.</li>
<li>Use MOSFETs for 3.3-5 V translation. Need to test it at 16MHz before manufacturing a PCB though.</li>
<li>Obviously fix all PCB errors :)</li>
<li>All SMD parts (resistors and voltage regulators) to shrink PCB size even more.</li>
<li>Better power distribution. I was a bit too conservative with the decoupling capacitors resulting in some weird power problems (fixable with some caps)</li>
<li>Create a real add-on board</li>
</ul>
<p>I&#8217;ll publish the PCB CAD files when the next revision is complete.</p>
<h3>Software</h3>
<p>The only small IPv6 stack I know of is the uIPv6 stack in the <a href="http://www.sics.se/contiki/">Contiki operating system</a> created by Adam Dunkel et al. This is unfortunately only available together with Contiki and not as a stand alone package as the originally uIP (IPv4) stack.</p>
<p>Contiki is a great operating system, but when you only have 4KB of RAM it becomes a bit heavy weight. So I broke out the uIPv6 stack from Contiki and made it run stand alone and ported in to AVR. I also ported the web server application from Contiki and made it run on AVR. As I wanted to use multiple IPv6 addresses I also had to add support for IP aliases to the uIPv6 stack.</p>
<p>Since the uIPv6 was integrated with Contiki it used the Contiki process model which it self is based on &#8220;proto-threads&#8221; (another thing invented by Adam Dunkel). I felt that this didn&#8217;t fit so I turned all processes into a polling mode instead. So one has to call a set of polling functions from the main application loop or from timers.</p>
<p>The other major parts of the code are drivers for ENC28J60, DS2480 and DS1820.</p>
<h5>Software</h5>
<dl>
<dt>1-wire devices</dt>
<dd>30 second polling interval with auto-discovery of new devices.<br />
Each device is assigned its own IPv6 address, requires a /64 network to be available.</dd>
<dt>Webserver</dt>
<dd>Integrated web server makes it possible to visit each address. An XML file with the latest sensor reading is returned. An &#8220;age timestamp&#8221; is also provided which makes it possible to determine how old the reading is. </dd>
</dl>
<p>Currently, with 5 1-wire devices connected it uses about 3KB of RAM.</p>
<ul>
<li><a href="http://svn.h3q.net/work/avr/ethernode/src">Source code</a></li>
<li><a href="http://www.shapeshifter.se/code/uipv6/">uIPv6 port</a></li>
</ul>
<h3>In-action</h3>
<p>I only have temperature sensors connected at the moment. If you happen to have an IPv6 capable connection you can access the sensors through a web browser.</p>
<p><a rel="nofollow,noindex" href="http://[2001:16d8:ffe5:002:2894:eaf6:100:0c7]">2001:16d8:ffe5:002:2894:eaf6:100:0c7</a><br />
<a rel="nofollow,noindex" href="http://[2001:16d8:ffe5:002:28c1:b4f6:100:035]">2001:16d8:ffe5:002:28c1:b4f6:100:035</a><br />
<a rel="nofollow,noindex" href="http://[2001:16d8:ffe5:002:2809:aef6:100:0ca]">2001:16d8:ffe5:002:2809:aef6:100:0ca</a><br />
<a rel="nofollow,noindex" href="http://[2001:16d8:ffe5:002:28c5:a5f6:100:058]">2001:16d8:ffe5:002:28c5:a5f6:100:058</a><br />
<a rel="nofollow,noindex" href="http://[2001:16d8:ffe5:002:2813:caf6:100:050]">2001:16d8:ffe5:002:2813:caf6:100:050</a></p>
<p style="text-align: center;">(If you don&#8217;t have IPv6 you should get it, or you can view graphs based on the sensor values at <a rel="nofollow" href="http://www.lindberg.tl">lindberg.tl</a> instead).</p>
<table style="text-align: center;" border="0" cellspacing="2">
<tbody>
<tr>
<td><a href="/wp-content/uploads/2009/07/DSC00664.JPG"><img title="DSC00664" src="/wp-content/uploads/2009/07/DSC00664-300x225.jpg" alt="DSC00664" width="300" height="225" /></a></td>
<td><a href="/wp-content/uploads/2009/07/DSC00661.JPG"><img title="DSC00661" src="/wp-content/uploads/2009/07/DSC00661-300x225.jpg" alt="DSC00661" width="300" height="225" /></a></td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.shapeshifter.se/2009/07/10/1-wire-meets-ipv6/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>DIY: Female-Female USB-adapter</title>
		<link>http://www.shapeshifter.se/2009/07/07/diy-female-female-usb-adapter/</link>
		<comments>http://www.shapeshifter.se/2009/07/07/diy-female-female-usb-adapter/#comments</comments>
		<pubDate>Tue, 07 Jul 2009 15:18:57 +0000</pubDate>
		<dc:creator>fli</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[usb]]></category>

		<guid isPermaLink="false">http://www.shapeshifter.se/?p=553</guid>
		<description><![CDATA[Do you have a bunch of useless USB-to-PS/2 keyboard adapters laying around? Two of them make a great female-female USB adapter &#8211; If you need one that is. Here is how I made one.

Carefully crack the case open using a knife. You can be quite rough at the PS/2 end of the casing as this [...]]]></description>
			<content:encoded><![CDATA[<p>Do you have a bunch of useless USB-to-PS/2 keyboard adapters laying around? Two of them make a great female-female USB adapter &#8211; If you need one that is. Here is how I made one.</p>
<p><a href="http://www.shapeshifter.se/wp-content/uploads/2009/06/usb_to_ps2_open.jpg"><img src="http://www.shapeshifter.se/wp-content/uploads/2009/06/usb_to_ps2_open-300x133.jpg" alt="usb_to_ps2_open" title="usb_to_ps2_open" width="300" height="133" class="alignright size-medium wp-image-561" /></a></p>
<p>Carefully crack the case open using a knife. You can be quite rough at the PS/2 end of the casing as this part will be<br />
removed anyway. Don&#8217;t destroy the USB side of the casing as this part will be reused for our adapter casing later on.</p>
<p>Once opened you should basically have a USB-connector connected to a PS/2 connector covered in hot glue/plastic wrapped in a thin-foil like material (for shielding). Remove the wrapping and cut away the PS/2 connector with a knife.</p>
<p>Now, carefully remove the remaining plastic. Don&#8217;t worry about the soldered wires but  make sure that you don&#8217;t damage the pins on the USB connector. You should end up with something like this.</p>
<p><a href="http://www.shapeshifter.se/wp-content/uploads/2009/06/usb_to_ps2_stripped.jpg"><img src="http://www.shapeshifter.se/wp-content/uploads/2009/06/usb_to_ps2_stripped-300x200.jpg" alt="usb_to_ps2_stripped" title="usb_to_ps2_stripped" width="300" height="200" class="aligncenter size-medium wp-image-567" /></a></p>
<p>Do the same with another USB-PS/2 adapter so that you basically end up with two USB connectors.<br />
Bring out your soldering iron and de-solder the remaining wires from the connectors.</p>
<p><a href="http://www.shapeshifter.se/wp-content/uploads/2009/06/usb_to_ps2_two_stripped.jpg"><img src="http://www.shapeshifter.se/wp-content/uploads/2009/06/usb_to_ps2_two_stripped-300x178.jpg" alt="usb_to_ps2_two_stripped" title="usb_to_ps2_two_stripped" width="300" height="178" class="aligncenter size-medium wp-image-570" /></a></p>
<p>Place the connectors back-to-back and turn one of them 180 degrees so that it becomes &#8220;up-side-down&#8221;. If you don&#8217;t do this you&#8217;ll end up connecting the pins in the wrong way.<br />
To make the pins touch each other you&#8217;ll have to bend them roughly 30-45 degrees. Solder the pins together.</p>
<p><a href="http://www.shapeshifter.se/wp-content/uploads/2009/06/usb_to_ps2_soldered.jpg"><img src="http://www.shapeshifter.se/wp-content/uploads/2009/06/usb_to_ps2_soldered-300x170.jpg" alt="usb_to_ps2_soldered" title="usb_to_ps2_soldered" width="300" height="170" class="aligncenter size-medium wp-image-564" /></a></p>
<p>Cut out a piece of wire and solder it to the casing off each connector. You can use the existing solder points used for the shielding/ground or create a new. Some flux will help a lot here.</p>
<p><a href="http://www.shapeshifter.se/wp-content/uploads/2009/06/usb_to_ps2_soldered_gnd_side.jpg"><img src="http://www.shapeshifter.se/wp-content/uploads/2009/06/usb_to_ps2_soldered_gnd_side-300x131.jpg" alt="usb_to_ps2_soldered_gnd_side" title="usb_to_ps2_soldered_gnd_side" width="300" height="131" class="aligncenter size-medium wp-image-565" /></a></p>
<p>That&#8217;s it for the connector. Next up is to creating a new casing using the existing casings. Unfortunately I forgot to take pictures of this process.<br />
Take on pair of the two cases, take one of the two pieces and place the USB-USB adapter inside it . Make a mark on the casing approximately in the middle of where the soldered pins meet.<br />
Cut at this point and do the same for the same half of the other case. Just do a rough cut and file the pieces until the adapter fits. Once the bottom fits, do the same for the top part using the bottom pieces as a template.</p>
<p>Place it in the new casing and pour some hot glue over it to make it steady. Glue the top on and it&#8217;s complete.<br />
<a href="http://www.shapeshifter.se/wp-content/uploads/2009/06/usb_to_usb_half_assembled.jpg"><img src="http://www.shapeshifter.se/wp-content/uploads/2009/06/usb_to_usb_half_assembled-300x200.jpg" alt="usb_to_usb_half_assembled" title="usb_to_usb_half_assembled" width="300" height="200" class="aligncenter size-medium wp-image-572" /></a></p>
<p>USB-USB female adapter in action.<br />
<a href="http://www.shapeshifter.se/wp-content/uploads/2009/06/usb_to_usb_assembled.jpg"><img src="http://www.shapeshifter.se/wp-content/uploads/2009/06/usb_to_usb_assembled-300x225.jpg" alt="usb_to_usb_assembled" title="usb_to_usb_assembled" width="300" height="225" class="aligncenter size-medium wp-image-571" /></a></p>
<p>Will it be as good as a commercial adapter? probably not. Will it effect data transmission? probably (depending on how good the solder joints are). Cheaper than a commercial adapter? yep (assuming you already have the parts needed and don&#8217;t factor in the labor :))</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shapeshifter.se/2009/07/07/diy-female-female-usb-adapter/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>AVR System Timer</title>
		<link>http://www.shapeshifter.se/2009/06/02/avr-system-timer/</link>
		<comments>http://www.shapeshifter.se/2009/06/02/avr-system-timer/#comments</comments>
		<pubDate>Tue, 02 Jun 2009 10:17:41 +0000</pubDate>
		<dc:creator>fli</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[AVR]]></category>
		<category><![CDATA[microcontroller]]></category>

		<guid isPermaLink="false">http://www.shapeshifter.se/?p=546</guid>
		<description><![CDATA[Handy system clock for AVR 8-bit microcontrollers suitable for measuring elapsed time or for use with timers. This provides
a monotonic time since system startup (like the POSIX CLOCK_MONOTONIC).
The system clock is based around a 32kHz clock crystal and one of the 8-bit timers provided by the AVR, it is possible to use the CPU frequency [...]]]></description>
			<content:encoded><![CDATA[<p>Handy system clock for AVR 8-bit microcontrollers suitable for measuring elapsed time or for use with timers. This provides<br />
a monotonic time since system startup (like the POSIX CLOCK_MONOTONIC).</p>
<p>The system clock is based around a 32kHz clock crystal and one of the 8-bit timers provided by the AVR, it is possible to use the CPU frequency as a timer base as  long as it&#8217;s a nice, dividable, frequency.<br />
To be able to provide a stable 1 Hz clock but still have sub-second precision we divide 1 second into an arbitrary number of<br />
system ticks. To minimize CPU usage the tick counter should be increased at each interrupt, this means that the number of<br />
ticks per second we we choose determines our interrupt frequency and timer resolution.<br />
How to choose number of ticks? It all depends on your required resolution, if you only want a 1 second resolution a tick and a second becomes equal.</p>
<p>The AVR timer is a 8-bit register that simply counts at the rate of its clock source. The clock source can be either the CPU<br />
clock or an external oscillator, the clock source is also subject to a prescaler to further decrease the frequency.<br />
The timer then generates an interrupt on overflow and/or when it hits a pre-configured value.<br />
Since its a 8-bit timer, we have a maximum of 256 cycles before an interrupt is generated, a smaller interval can be achieved by using the comparator match to generate an interrupt at a specific value.</p>
<p>This example is creating a 1/32 second resolution timer (32 ticks per second) using an external 32768 Hz watch crystal.<br />
<em>comp</em> is the comparator value, to avoid re-arming it with different values it should be limited to 128 or 256, otherwise it has to be changed at each interrupt.</p>
<img src='http://s.wordpress.com/latex.php?latex=F_%7Btimer%7D%20%3D%2032768&#038;bg=FAFAFA&#038;fg=000000&#038;s=1' alt='F_{timer} = 32768' title='F_{timer} = 32768' class='latex' /><br />
<img src='http://s.wordpress.com/latex.php?latex=ticks%20%3D%2032&#038;bg=FAFAFA&#038;fg=000000&#038;s=1' alt='ticks = 32' title='ticks = 32' class='latex' />
<p>The following to equations can be used to calculate either <em>comp</em> or the <em>prescale</em> value.<br />
<em>prescale</em> is limited by the target device, but common values are powers of 2 (8,32,64,128,256,1024).</p>
<p style="text-align: center;"><img src='http://s.wordpress.com/latex.php?latex=comp%20%3D%20%5Cfrac%7B%5Cfrac%7BF_%7Btimer%7D%7D%7Bprescale%7D%7D%7Bticks%7D&#038;bg=FAFAFA&#038;fg=000000&#038;s=2' alt='comp = \frac{\frac{F_{timer}}{prescale}}{ticks}' title='comp = \frac{\frac{F_{timer}}{prescale}}{ticks}' class='latex' /><br />
<img src='http://s.wordpress.com/latex.php?latex=prescale%20%3D%20%5Cfrac%7BF_%7Btimer%7D%7D%7Bcomp%20%5Ctimes%20ticks%7D&#038;bg=FAFAFA&#038;fg=000000&#038;s=2' alt='prescale = \frac{F_{timer}}{comp \times ticks}' title='prescale = \frac{F_{timer}}{comp \times ticks}' class='latex' /></p>
<p>Using 128 as the <em>comp</em> value and inserting the other values into equation 2 yields the following prescaler</p>
<p style="text-align: center;">
<img src='http://s.wordpress.com/latex.php?latex=%5Cfrac%7B32768%7D%7B128%20%5Ctimes%2032%7D%20%3D%208&#038;bg=FAFAFA&#038;fg=000000&#038;s=2' alt='\frac{32768}{128 \times 32} = 8' title='\frac{32768}{128 \times 32} = 8' class='latex' />
</p>
<p>So, a prescaler of 8 gives us two interrupts per 256 cycles, one at 128 and one at 256 (overflow). Using 256 as <em>comp</em> would yield a perscaler of 4 but the target device I used didn&#8217;t have a TS/4 prescaler.</p>
<p>Complete source code for a 1/32 (or 31.25ms) second resolution timer for the ATmegaxx4 using Timer 2 and a 32kHz watch crystal connected to the pins TOSC1 and TOSC2.<br />
Requires <a href="http://www.nongnu.org/avr-libc/">AVR libc</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;avr/io.h&gt;</span>
<span style="color: #339933;">#include &lt;avr/interrupt.h&gt;</span>
&nbsp;
<span style="color: #993333;">typedef</span> uint32_t clock_time_t<span style="color: #339933;">;</span>
<span style="color: #993333;">static</span> clock_time_t global_system_ticks <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* ISR for the timer overflow */</span>
ISR<span style="color: #009900;">&#40;</span>TIMER2_OVF_vect<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    global_system_ticks<span style="color: #339933;">++;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* ISR for the comparator */</span>
ISR<span style="color: #009900;">&#40;</span>TIMER2_COMPA_vect<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    global_system_ticks<span style="color: #339933;">++;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* Return number of elapsed ticks */</span>
clock_time_t clock_time<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span>global_system_ticks<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* Return number of elapsed seconds */</span>
<span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> clock_seconds<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    uint32_t tmp<span style="color: #339933;">;</span>
&nbsp;
    TIMSK2 <span style="color: #339933;">&amp;=</span> ~<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span> <span style="color: #339933;">&lt;&lt;</span> OCIE2A<span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span> <span style="color: #339933;">&lt;&lt;</span> TOIE2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    tmp <span style="color: #339933;">=</span> global_system_ticks <span style="color: #339933;">/</span> <span style="color: #0000dd;">32</span><span style="color: #339933;">;</span>
    TIMSK2 <span style="color: #339933;">|=</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span> <span style="color: #339933;">&lt;&lt;</span> OCIE2A<span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span> <span style="color: #339933;">&lt;&lt;</span> TOIE2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span>tmp<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> clock_init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">/* Enable external oscillator (32 kHz crystal) connected to TOSC{1,2} */</span>
    ASSR <span style="color: #339933;">|=</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span> <span style="color: #339933;">&lt;&lt;</span> AS2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">/* Reset timer */</span>
    TCNT2 <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">/* Set TS/8 prescaler, results in a 4096Hz clock */</span>
    TCCR2B <span style="color: #339933;">|=</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span> <span style="color: #339933;">&lt;&lt;</span> CS21<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">/* Compare at half counter value */</span>
    OCR2A <span style="color: #339933;">=</span> <span style="color: #0000dd;">128</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">/*
     * Enable overflow and compare interrupt.
     * Triggers each 1/32 secs
     */</span>
    TIMSK2 <span style="color: #339933;">|=</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span> <span style="color: #339933;">&lt;&lt;</span> OCIE2A<span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span> <span style="color: #339933;">&lt;&lt;</span> TOIE2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.shapeshifter.se/2009/06/02/avr-system-timer/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>MoreThanAll MagJack Eagle PCB footprint</title>
		<link>http://www.shapeshifter.se/2009/05/28/morethanall-magjack-eagle-pcb-footprint/</link>
		<comments>http://www.shapeshifter.se/2009/05/28/morethanall-magjack-eagle-pcb-footprint/#comments</comments>
		<pubDate>Thu, 28 May 2009 16:02:51 +0000</pubDate>
		<dc:creator>fli</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Eagle]]></category>
		<category><![CDATA[footprint]]></category>
		<category><![CDATA[MagJack]]></category>
		<category><![CDATA[PCB]]></category>

		<guid isPermaLink="false">http://www.shapeshifter.se/?p=507</guid>
		<description><![CDATA[
Creating PCB footprints is usually quite easy as most components come in standard packages.
Footprints for &#8216;magjacks&#8217; (RJ45 with built-in Ethernet transformer) are another thing as different manufactures tend to at least put the LED pins at different positions.
Here is an Eagle PCB footprint I created for the MagJack (MJF13T36L-KF06B3GY-0808) from MoreThanAll sold by Sparkfun.
This one [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.shapeshifter.se/wp-content/uploads/2009/05/magjack.jpg" alt="magjack" title="magjack" width="100" height="107" class="alignleft size-full wp-image-511" /><br />
Creating PCB footprints is usually quite easy as most components come in standard packages.<br />
Footprints for &#8216;magjacks&#8217; (RJ45 with built-in Ethernet transformer) are another thing as different manufactures tend to at least put the LED pins at different positions.</p>
<p>Here is an Eagle PCB footprint I created for the <a href="http://www.morethanall.com/products/index/btype_id/9/type_id/106/id/1217">MagJack</a> (MJF13T36L-KF06B3GY-0808) from MoreThanAll sold by <a href="http://www.sparkfun.com/commerce/product_info.php?products_id=8534">Sparkfun</a>.</p>
<p>This one has been <strong>proven</strong> in production and it works, however you should double- (and triple-) check pin-outs and footprint of your device before sending a PCB for manufacturing using this part. Use at your own risk.</p>
<div id="attachment_505" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.shapeshifter.se/wp-content/uploads/2009/05/magjack_schematic.png"><img src="http://www.shapeshifter.se/wp-content/uploads/2009/05/magjack_schematic-300x300.png" alt="Magjack schematic" title="magjack_schematic" width="300" height="300" class="size-medium wp-image-505" /></a><p class="wp-caption-text">Magjack schematic</p></div>
<div id="attachment_506" class="wp-caption aligncenter" style="width: 235px"><a href="http://www.shapeshifter.se/wp-content/uploads/2009/05/magjack_footprint.png"><img src="http://www.shapeshifter.se/wp-content/uploads/2009/05/magjack_footprint.png" alt="Magjack footprint" title="magjack_footprint" width="225" height="283" class="size-full wp-image-506" /></a><p class="wp-caption-text">Magjack footprint</p></div>
<h3>Download</h3>
<p><a href='http://www.shapeshifter.se/wp-content/uploads/2009/05/morethanall_magjack.lbr'>morethanall_magjack.lbr</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.shapeshifter.se/2009/05/28/morethanall-magjack-eagle-pcb-footprint/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PPTP from FreeBSD</title>
		<link>http://www.shapeshifter.se/2009/03/10/pptp-from-freebsd/</link>
		<comments>http://www.shapeshifter.se/2009/03/10/pptp-from-freebsd/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 20:40:05 +0000</pubDate>
		<dc:creator>fli</dc:creator>
				<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[Mpd]]></category>
		<category><![CDATA[PPTP]]></category>
		<category><![CDATA[VPN]]></category>

		<guid isPermaLink="false">http://www.shapeshifter.se/?p=438</guid>
		<description><![CDATA[
Getting FreeBSD to connect to a Windows VPN using PPTP (who designed that protocol anyway?) is not the most pleasant experience, but at least it&#8217;s doable.
The most competent console tool for this in FreeBSD is probably Mpd5. It&#8217;s quite easy to work with but you&#8217;ll need to get all the details right otherwise it just [...]]]></description>
			<content:encoded><![CDATA[<p><!-- WSA: rules for context 'adsense-post-top' did not apply --><br />
Getting FreeBSD to connect to a Windows VPN using <a href="http://en.wikipedia.org/wiki/Pptp">PPTP</a> (who designed that protocol anyway?) is not the most pleasant experience, but at least it&#8217;s doable.</p>
<p>The most competent console tool for this in FreeBSD is probably <a href="http://mpd.sourceforge.net">Mpd5.</a> It&#8217;s quite easy to work with but you&#8217;ll need to get all the details right otherwise it just won&#8217;t work.</p>
<p>The following mpd.conf configuration file worked for me and allowed me to successfully connect to a Windows VPN. One of the keys were to disable EAP, this particular VPN server just plain refused to work with it enabled</p>
<blockquote>
<pre>default:
    load vpn
vpn:
    create bundle static B1
    # Create a default route (use a net/mask to create specific routes)
    set iface route default
    # Script to execute on connect (custom routes etc)
    # set iface up-script /usr/local/etc/route-up.sh
    # Accept any IP-address
    set ipcp ranges 0.0.0.0/0 0.0.0.0/0
    # Microsoft Point-to-Point Compression, only enable if you have a really fast machine
    # set bundle enable compression
    set ccp yes mppc
    set mppc yes e40
    set mppc yes e56
    set mppc yes e128
    create link static L1 pptp
    set link action bundle B1
    # Replace with you credentials or use the mpd.secret file
    set auth authname USERNAME
    set auth password SECRET
    set link max-redial 0
    set link mtu 1460
    set link keep-alive 20 75
    # Hostname/IP of the VPN server
    set pptp peer vpn.example.com
    set pptp disable windowing
    set link no eap</pre>
</blockquote>
<p>Save it to a file, say mpd.conf in /usr/local/etc/mpd.conf and simply run mpd5 mpd.conf and with some luck you&#8217;ll be connected the the VPN.</p>
<p><strong>The order of the statements are important</strong>. As they only apply to the current selected link (create link) or bundle (create bundle). Keep this in mind when editing.</p>
<h4>Windows logon name</h4>
<p>If you&#8217;re connecting to a Windows network you&#8217;ll probably need to use &#8220;DOMAIN\\username&#8221; as the authname (with the quotes and double backslash).</p>
<h4>Firewall and NAT issues</h4>
<p>The PPTP protocol is far from ideal. If you&#8217;re behind NAT chances are you won&#8217;t be able to do multiple PPTP connections to the <em>same</em> VPN server from within your LAN.</p>
<p>You&#8217;ll also need to allow the GRE protocol through, with Free/OpenBSD pf (packet filter) the following line is enough (you still won&#8217;t be able to do simultaneous connections to the same server though)</p>
<blockquote>
<pre>pass out on $ext_if proto gre from ($ext_if) to any keep state</pre>
</blockquote>
<p>Replace $ext_if with your external network interface.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shapeshifter.se/2009/03/10/pptp-from-freebsd/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>DSPAM: Converting from the hash driver to MySQL driver</title>
		<link>http://www.shapeshifter.se/2009/03/03/dspam-converting-from-the-hash-driver-to-mysql-driver/</link>
		<comments>http://www.shapeshifter.se/2009/03/03/dspam-converting-from-the-hash-driver-to-mysql-driver/#comments</comments>
		<pubDate>Tue, 03 Mar 2009 21:51:46 +0000</pubDate>
		<dc:creator>fli</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[DSPAM]]></category>
		<category><![CDATA[hash]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.shapeshifter.se/?p=422</guid>
		<description><![CDATA[&#8230;or annoyances with the DSPAM hash driver
I&#8217;ve been running DSPAM for a long time and the spam classification is great, unfortunately the maintenance tools are not as it turns out. This is the tale of why and more especially HOW I moved from the hash driver to the mysql driver as a backend for my [...]]]></description>
			<content:encoded><![CDATA[<h2>&#8230;or annoyances with the DSPAM hash driver</h2>
<p>I&#8217;ve been running DSPAM for a long time and the spam classification is great, unfortunately the maintenance tools are not as it turns out. This is the tale of why and more especially HOW I moved from the hash driver to the mysql driver as a backend for my DSPAM installation.</p>
<p><span id="more-422"></span></p>
<p>It all began a few days ago when the <a href="http://johannes.sipsolutions.net/Projects/dovecot-antispam">dovecot-antispam</a> plugin all of a sudden refused to re-classify mails. This was all very weird because I was possible to re-classify mails from the command line, but the same mail/signature failed from the plugin.</p>
<p>After some debugging and messing with the plugin code I established that it successfully called dspam to re-classify the mail but dspam failed. Hm, maybe a permission problem then&#8230;nope. Same command with same permissions worked from the command line.</p>
<p>At this point I was really puzzled (and quite annoyed), the error made no sense.  So I hacked the plugin to call dspam using a system call tracer (in this case truss which is shipped with FreeBSD) to produce a call trace of the dspam processes within the context of the plugin.</p>
<p>After comparing the outputs from a working case and a non-working case, one line stood out.</p>
<blockquote><p>mmap(0&#215;0,263332768,PROT_READ|PROT_WRITE,MAP_SHARED,4,0&#215;0) ERR#12 &#8216;Cannot allocate memory&#8217;</p></blockquote>
<p>For those who don&#8217;t speak truss. This means that the mmap() system call (map a content of file into memory) failed because of an out of memory condition.</p>
<p>WHY!? Well it obviously hit a built-in mmap limit as the system had a lot of free memory. It was not vm.max_proc_mmap (tried bumping it, didn&#8217;t work). vm.kmem_size_max is large (64-bit system) and the uid had unlimited resources (ulimit). I&#8217;m still puzzled by this.</p>
<p>As the title reveals I&#8217;m running DSPAM with the hash driver, why? mostly because it was the default back-end driver in DSPAM when I installed it (and I was young and naive).</p>
<p>Wonder why it hit the limit in the first place, a quick look in /var/db/dspam/data reveals that the hash database with tokens for this particular user had grown to ~250MB.</p>
<p>Why so big? DSPAM comes with a cleaning utility called dspam_clean to clean out unused data, I&#8217;ve been running this nightly to keep stuff neat and tidy. Well, here comes the fun part.</p>
<p>It turns out that dspam_clean doesn&#8217;t actually do anything when you&#8217;re running the hash driver, it just looks like its working and takes ages to execute. There is no mentioning of this in any user documentation I found. With the hash driver you&#8217;re supposed to run cssclean&#8230;only that this program doesn&#8217;t work either &#8211; unless you patch it. I found a patch dubbed <a href="http://www.mail-archive.com/dspam-dev@lists.nuclearelephant.com/msg00066.html">&#8220;cssclean is a redheaded stepchild&#8221;</a> sent to the (now defunct, and moved to sourceforge) dspam-dev@ list at nuclearelephant.com that took care of this. The patch missed an include (at least on FreeBSD) that caused it to crash on 64-bit platforms (64/32-bit pointer truncation). The whole patch is included at the bottom of the page.</p>
<p>To summarize it, the maintenance tools are virtually non-existing when using the hash driver.</p>
<p>Probably a good opportunity to convert to the mysql driver instead (as I&#8217;ve been meaning to do for the last year or so).</p>
<h2>Converting from the hash driver to mysql</h2>
<p>There is a tool included with the DSPAM package called dspam_2sql, but of course this didn&#8217;t work properly either. Most important, it didn&#8217;t work with virtual users and just refused to run. Also timestamps on token data were ignored. I&#8217;ve hacked together a patch to fix theses issues, it&#8217;s available at the bottom of the page.</p>
<p>I first attempted to import non-cleaned data into the SQL database&#8230;big mistake. I aborted the progress when the token table had about 8 million entries (and weren&#8217;t even done with 1 user).</p>
<h3>Quick recipe on how to do the conversion</h3>
<p>First</p>
<ul>
<li>Grab the source package for dspam-3.8.0</li>
<li>Download the patches at the bottom of this page</li>
</ul>
<p>Patch and compile the sources</p>
<blockquote><p>tar xzf dspam-3.8.0.tar.gz<br />
cd dspam-3.8.0<br />
patch -p1 &lt; dspam_cssclean.patch<br />
patch -p1 &lt; dspam_2sql_virtuser.patch<br />
cd src<br />
make</p></blockquote>
<p>The patched cssclean tools can be found in tools.hash_drv</p>
<p>Run tools.hash_drv/cssclean on all users (or users that receive a lot of mail). <strong>Backup your database (/var/db/dspam) first</strong>.</p>
<p>Example</p>
<blockquote><p>tools.hash_drv/cssclean /var/db/dspam/user@domain.tld/user@domain.tld.css</p></blockquote>
<p>You can check the number of entries with cssstat</p>
<p>Create a MySQL database and user for dspam, I&#8217;ve called mine dspam. The table defintions can be found in tools.mysql_drv</p>
<blockquote><p>mysql -D dspam -u dspam -p &lt; tools.mysql_drv/mysql_objects-speed.sql<br />
mysql -D dspam -u dspam -p &lt; tools.mysql_drv/virtual_users.sql</p></blockquote>
<p>You should now have a database with tables and a cleaned hash database, the only thing left is to convert it. dspam_2sql will output SQL statements, just feed these into MySQL.</p>
<p>For example, the conversion can be done like this</p>
<blockquote><p>tools/dspam_2sql | mysql -D dspam -u dspam -p</p></blockquote>
<p>Beaware that it probably will take a lot of time.</p>
<p>You can convert one single user with</p>
<blockquote><p>dspam_2sql &#8211;user=user@domain.tld</p></blockquote>
<p>That&#8217;s it. Modify your dspam.conf to use the MySQL driver and restart dspam.</p>
<h3>Performance</h3>
<p>The MySQL driver IS slower than the hash driver. The processing time for a message with the hash driver was around 0.1-0.2 seconds on this hardware. The MySQL driver takes between 0.2-2 seconds for a message.</p>
<p>The slowdown is not a problem for me. Things like real database consistency (some of my users had duplicated tokens with the hash driver), better maintenance tools, easier manipulation of the data (and the benefits of my MySQL replication+backup configuration) makes it well worth it.</p>
<h2>Patches</h2>
<ul>
<li><a href="http://www.shapeshifter.se/wp-content/uploads/2009/03/dspam_cssclean.patch">dspam_cssclean</a> &#8211; cssclean patch found on mailing list. Posted by Frank Cusack.</li>
<li><a href="http://www.shapeshifter.se/wp-content/uploads/2009/03/dspam_2sql_virtuser.patch">dspam_2sql_virtuser</a> &#8211; dspam_2sql patchset. Virtual user support etc.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.shapeshifter.se/2009/03/03/dspam-converting-from-the-hash-driver-to-mysql-driver/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Obscuring SMTP auth headers &#8211; with IPv6</title>
		<link>http://www.shapeshifter.se/2008/12/10/obscuring-smtp-auth-headers-with-ipv6/</link>
		<comments>http://www.shapeshifter.se/2008/12/10/obscuring-smtp-auth-headers-with-ipv6/#comments</comments>
		<pubDate>Wed, 10 Dec 2008 16:01:19 +0000</pubDate>
		<dc:creator>fli</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[IPv6]]></category>
		<category><![CDATA[postfix]]></category>

		<guid isPermaLink="false">http://www.shapeshifter.se/?p=410</guid>
		<description><![CDATA[
The FreeBSD Diary and Riseup labs describe a way to anonymize the first &#8220;received from&#8221; header with usually contain the IP-address of the computer the mail was sent from.  This information is removed by taking advantage of the &#8220;Authenticated sender&#8221; and the header_checks directive in Postfix.
The &#8220;Authenticated sender&#8221; is added when a user has been [...]]]></description>
			<content:encoded><![CDATA[<p><!-- WSA: rules for context 'adsense-post-top' did not apply --><br />
The <a href="http://www.freebsddiary.org/smtp-headers-rewrite-auth.php">FreeBSD Diary</a> and <a href="http://riseuplabs.org/privacy/postfix/">Riseup labs</a> describe a way to anonymize the first &#8220;received from&#8221; header with usually contain the IP-address of the computer the mail was sent from.  This information is removed by taking advantage of the &#8220;Authenticated sender&#8221; and the header_checks directive in Postfix.</p>
<p>The &#8220;Authenticated sender&#8221; is added when a user has been authenticated by the MTA through SASL and the directive smtpd_sasl_authenticated_header have been set to yes.  The header_checks directive takes a file containing a regular expression which rewrites the header data and removes sensitive information.</p>
<p>This all works well &#8211; with IPv4. The regular expression posted on the pages mentioned above does not take IPv6 addresses into account, I modified it slightly to accept both IPv4 and IPv6 addresses.</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #339933;">/^</span>Received<span style="color: #339933;">:</span> from <span style="color: #009900;">&#40;</span><span style="color: #339933;">.*</span> \<span style="color: #009900;">&#40;</span>\<span style="color: #009900;">&#91;</span><span style="color: #339933;">?</span><span style="color: #009900;">&#91;</span><span style="color: #339933;">-.</span>_<span style="color: #009900;">&#91;</span><span style="color: #339933;">:</span>alnum<span style="color: #339933;">:</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span>\<span style="color: #009900;">&#93;</span><span style="color: #339933;">?</span> \<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>\<span style="color: #339933;">.</span>0<span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">7</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">15</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">|</span>IPv6<span style="color: #009900;">&#91;</span>\<span style="color: #339933;">:</span>a<span style="color: #339933;">-</span>fA<span style="color: #339933;">-</span>F0<span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#41;</span>\<span style="color: #009900;">&#93;</span>\<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">.*</span><span style="color: #009900;">&#41;</span>
\<span style="color: #009900;">&#40;</span>Authenticated sender<span style="color: #339933;">:</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #339933;">^</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#41;</span>\<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">.*</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>by mx1\<span style="color: #339933;">.</span>example\<span style="color: #339933;">.</span>com<span style="color: #009900;">&#41;</span> \<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #339933;">^</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#41;</span>\<span style="color: #009900;">&#41;</span> with <span style="color: #009900;">&#40;</span>E<span style="color: #339933;">?</span>SMTPS<span style="color: #339933;">?</span>A<span style="color: #339933;">?</span><span style="color: #009900;">&#41;</span> id
 <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>A<span style="color: #339933;">-</span>F<span style="color: #009900;">&#91;</span><span style="color: #339933;">:</span>digit<span style="color: #339933;">:</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">.*</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span> REPLACE Received<span style="color: #339933;">:</span> from smtp<span style="color: #339933;">-</span>auth<span style="color: #339933;">.</span>example<span style="color: #339933;">.</span>com <span style="color: #009900;">&#40;</span>smtp<span style="color: #339933;">-</span>auth<span style="color: #339933;">.</span>example<span style="color: #339933;">.</span>com
 <span style="color: #009900;">&#91;</span>127<span style="color: #339933;">.</span>0<span style="color: #339933;">.</span>0<span style="color: #339933;">.</span>1<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span>Authenticated sender<span style="color: #339933;">:</span> hidden<span style="color: #009900;">&#41;</span><span style="color: #0000ff;">$5</span><span style="color: #0000ff;">$6</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$7</span><span style="color: #009900;">&#41;</span> with <span style="color: #0000ff;">$8</span> id <span style="color: #0000ff;">$9</span> <span style="color: #0000ff;">$10</span></pre></div></div>

<p>Note that this should be one single line.</p>
<p>Put this in a file, for example /usr/local/etc/postfix/obscure_smtp_auth and add the following to your Postfix configuration (assuming you have SASL working).</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">header_checks <span style="color: #339933;">=</span> pcre<span style="color: #339933;">:/</span>usr<span style="color: #339933;">/</span>local<span style="color: #339933;">/</span>etc<span style="color: #339933;">/</span>postfix<span style="color: #339933;">/</span>obscure_smtp_auth
smtpd_sasl_authenticated_header <span style="color: #339933;">=</span> yes</pre></div></div>

<p>The first header will now be rewritten, for both IPv4 and IPv6 clients and will look something like this.</p>
<pre>
Received: from smtp-auth.example.com (smtp-auth.example.com [127.0.0.1]) 127.0.0.1 (Authenticated sender: hidden)
	by mx1.example.com (Postfix) with ESMTPSA id 3677033C6F
	for &#038;lthostmaster@example.se&gt;; Wed, 10 Dec 2008 16:31:51 +0100 (CET)
</pre>
<p>instead of</p>
<pre>
Received: from [IPv6:2001:xxxx:xxxx:xxxx:xxxx:xxxx:fedd:7914] (unknown [IPv6:2001:xxxx:xxxx:xxxx:xxxx:xxxx::fedd:7914])
	(Authenticated sender: someuser@example.com)
	by mx1.example.com (Postfix) with ESMTPSA id 3677033C6F
	for  &#038;lthostmaster@example.se&gt;;  Wed, 10 Dec 2008 16:31:51 +0100 (CET)
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.shapeshifter.se/2008/12/10/obscuring-smtp-auth-headers-with-ipv6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
