Python on a WRT54GS ?

Ok, I ‘ve been off for a little time right now. The main reason, is that I spend some time hacking my new Wireless access point: WRT54GS.

I spend a lot of time tweaking the config to use this in client mode with dhcp thought the WAN port and other nuts. I spend some time on http://www.brest-wireless.org too. But this is the mean reason of this post :)

Some people would think I’m a crazy boy but this is perhaps true. I managed to cross-compile python for the WRT. If you ask me why, I would simply answer that there is a lot of network stuff on a WRT that can be writen in a couple of python lines: dhcpd, dns cache, http server, dynamic pages rendering, dynamic firewall rules (check out last posts ..), diagnostics tools .. That’s it, now we need to figure out if this is do-able :)

WRT use a broadcom misp processor, so we need:

  • to install a cross-compile environnement: Not to hard.
  • tweak the python Makefile to use this, a little more funny but it works.
  • first tests..

As you can imagine, this doesn’t work at all :) The main issue is that current python use g++ (2.3), and the WRT only came with uClib, not the uClib++. After this wrong experience, I decided to take a old python: 1.5.2 . This one only needs gcc fine ! Ok, let’s see the result:

telnet host50
Trying 192.168.1.50...
Connected to host50.soif.fr.
Escape character is '^]'.

BusyBox v1.00 (2004.11.20-09:17+0000) Built-in shell (ash)
Enter 'help' for a list of built-in commands.

@OpenWrt:/# /tmp/python
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
'import exceptions' failed; use -v for traceback
Warning!  Falling back to string-based exceptions
'import site' failed; use -v for traceback
Python 1.5.2 (#2, Nov 21 2004, 05:52:09)  [GCC 3.2.3 with Broadcom modifications] on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import sys
>>> import os
Traceback (innermost last):
File "<stdin>", line 1, in ?
ImportError: No module named os
>>>

As you can see on this little capture, some parts of the interpreter works, but other don’t. The main issue is the build of modules. Something goes wrong at the link (ld), and I was unable to fully compile this.

Anyway this is not a big issue, because right now, I don’t think python 1.5.2 is a great challenger anyways. For people interested the python exec does 1.6Mo but a WRT54GS has 6Mo of free ROM.

I would really enjoy to hear your comments about your experience w/ ‘embeded python’. I guess that java has this kind of cross-compile issue too, but java is ready for cellphones, or other stuffs. Why not python ?

Alternative Firmware for the WRT54GS

Ok, yes, I bought a new WRT54GS, this works quite fine. I ‘m able to do what i want with that stuff. I will explain in a future post how to use this stuff in a secure way without using WEP.

Here is the list of firmware to use on this little box:

  • The Official one (pretty nice, but doesn’t allow telnet over device )
  • Sveasoft (the infamous weaked GPL one)
  • EWRT (sveasoft + nocat -> hotspot)
  • Wifi-box (hum not tested yet)
  • openWRT (minimal setup without http)
  • MeshBoxKit (openWRT + OLSR, special for Meshing)

Look at Seattle wiki on WRT for more infos. Do you use another one ?

Netgear WG311 as AP on NetBSD

To use a atheros wireless card and NetBSD, as a wireless AP simply do:

ifconfig ath0 ssid YouSSID mode 11g mediaopt hostap
ifconfig ath0 192.168.2.1 #ip of the AP

# allow forwarding
sysctl -w net.inet.ip.forwarding=1

This is pretty simple no ? In fact, it take me a while to find the mediaopt option.

Packet filtering w/ Python and Linux

While looking for a fun way to filter my WIFI traffic, I decided to look at userland firewall API in Python. I found: ipqueue.

I haven’t really wrote a full featured app with it, but here the first things to make it work.

# load the kernel queue module
modprobe ip_queue
# all outgoing ping will pass throught the queue
iptables -A OUTPUT -p icmp -j QUEUE

Now here a little script that act as the queue

import ipqueue

q = ipqueue.IPQ(ipqueue.IPQ_COPY_PACKET)

while 1:
p = q.read()
pID = p[ipqueue.PACKET_ID]

print pID
# accept the packet
q.set_verdict(pID,ipqueue.NF_ACCEPT)

Next step, simply run this script with the root privilege, and you will see outgoing ping print on the stdout.

Additionnal note: ipqueue only works on python2.2 right now, I hope Neale will fix that soon. Anyway this is really a nice piece of code thanks guy!

Let’s flood VirginMega !

Ok, while looking for the latest Placebo Bonus CD on the net, (I saw it at my local retailler but i just want to buy the Bonus CD, not ‘Best of’ that come w/) I decide to go on http://www.virginmega.fr/. And I get this:

'We only support Windows platform 98/SE and upper ..' 
(I translated because it display this in french)

So dear hackers, geekies, script kiddies, mac-users, open source newbies, ipod-ers, Clie-users, PlamOS-geekies … please flood with your favorite OS ! For windows-losers please hijack your OS identity.

I just want to see the face of the webmaster, just saying : We have an issue, we support only 70% of the current OS .. I know this will never happen in fact

Music industry are loosers, I hope to see lot of bands distribute their music directly on the net, without this merde !

Gtk-Womitor 0.2

Ok the name, is funny .. But I decided to write a little app to monitor my wifi signal level.

/static/gtk-womitor.png

The code is too ugly right now, I need to add noise, signal .. and a better OO API. Anyway, it tooks me 2 hours to write this, and that’s why I like Python.

Update

I spend a little time tonight to clean the code and add this to the SVN. So you can find this program at here

I switched to another card, as I’m usually working w/ a broadcom and ndiswrapper which don’t provide noise, and level information. This graph is done with a NetGear (prism54g based card). I’m still wondering why the noise has a so strange graph ??

Suspend to disc with Dell Latitude D400 on Linux

I now have a Dell Latitude D400 for 1 month. This little (really small) computer is pretty nice to use, but it right now, it’s really hard to have suspend working on this kind of stuff. The main reason: it only support ACPI (no APM), and ACPI isn’t well supported by the Linux kernel.

I have tested several way to fix this issue. The only that’s working fine right now, is to use swsup. So to make it work:

  • install the latest 2.6.9 kernel (the 2.6.8 has a issue w/ agpart and drm)
  • in kernel select ‘ACPI -> sleep state’
  • and ‘ACPI -> swsup’
  • build the kernel
  • create a swap partition if you don’t have one (i resized a ntfs w/ qparted)
  • mkswap /dev/hda4 (for example)
  • add ‘resume=/dev/hda4′ in your boot prompt (in grub for example)

Now your system is ready. Reboot :) ..To put the the system in standby and dump the current state in the swap: echo 4 > /proc/acpi/sleep.

Next step simply bind the power button on this action. This is done w/ the acpid.

#!/bin/sh
# /etc/acpi/powerbtn.sh

# put the box in swsup mode
echo 4 > /proc/acpi/sleep

Beside the S2/S3 ACPI doesn’t work right now, swsup permit to have suspend to disk without too much trouble.