Category Archives: Computers

DMCA takedown? Use HTTP error code 451!

A few hours ago, I received a delightful (or as delightful as they can be) copyright infringement takedown notice — what’s known in the trade as a “17 USC 512 (c)(3)(A)” or “DMCA” notice of infringement. Rather than remove the content permanently as if it never existed (and thus risking having people email me to ask where it went), I decided to do something a little different.

A little over a year ago, Tim Bray (@timbray) proposed that HTTP error code 451 be allocated for use in occasions like this. (I’ve linked to the latest draft at the time of writing, draft-tbray-http-legally-restricted-status-03, dated July 10, 2013).

The first problem is that Apache doesn’t recognise this error code, so you can’t use it in a Redirect directive. Thankfully there’s a workaround – create a PHP script which serves up the 451 error, then use mod_rewrite to redirect relevant requests to the script. Let’s say we want to block an entire directory…

First we create a .htaccess file in that directory, containing these two lines:

RewriteEngine On
RewriteRule .* .451.php

This enables mod_rewrite and redirects any requests to pages within this directory to the HTTP 451 handler script. Note that there’s a leading period on the script filename – this is intentional (on UNIX systems, a hidden file is denoted by a leading period in its filename).

Now we create the PHP script:

<?php header("HTTP/1.1 451 Unavailable for Legal Reasons"); ?>
<html>
<head>
<title>HTTP/1.1 451 Unavailable For Legal Reasons</title>
</head>
<body>
<h1>HTTP/1.1 451 Unavailable For Legal Reasons</h1>
<p>This request may not be serviced as a result of the issuance of a 17 USC 512 (c)(3)(A) (DMCA) infringement notice by Bilbo Baggins, Editor In Chief, Shire Weekly, relating to an article entitled "My Journey to Mordor," authored by one Frodo Baggins.</p>
<p>The aforementioned DMCA notice is on file at <a href="http://www.chillingeffects.org/12345">The Chilling Effects Clearinghouse</a>.</p>
</body>
</html>

Obviously the text of the error message is only an example and you should edit it to suit your circumstances.

Making a Wacom A6 ArtPad (KT-0405-R) work on Ubuntu 9.04

A couple of years ago, I picked up a Wacom A6 ArtPad at a computer fair for very little cash (I think it was about £5 or £10) sans power supply, and it’s been sitting gathering dust since I upgraded my PC and lost the serial port. Sadly it doesn’t work on 64-bit Windows XP (no drivers). Well, I’m using Linux now, so I figured, why not make the ArtPad work again?

(I also intend to learn to draw “at some point in time” — that may take a while…)

Anyway, on with the show!

You will need:
– A6 ArtPad, pen and power supply (I used a £10 Maplin switched-mode power supply — you need 12V DC, centre negative, and the orange-coloured round tip)
– FTDI-based USB-to-serial cable. I used one of FTDI’s “evaluation kit” cables, the US232R. This is optional if your PC’s motherboard has a serial port.

Procedure:
First you need to get the Artpad connected to the PC. If you have a proper, motherboard or PCI-mounted serial port, use it — the latency on those is streets ahead of the USB-to-serial converters. Skip the next step if you managed to find a serial port.

The default latency on the FTDI converters is 16 milliseconds or “whenever the buffer’s full”. If we leave the latency this high, you’ll notice a lot of lag (delay) between moving the pen and the cursor updating. That’s a bad thing. So let’s make the machine drop the latency to minimum when it initialises the adapter…

First we need to know the USB ID and serial number of the adapter. It’s usually 0403:6001, but it may be different. Let’s find out… Open a terminal, then enter the following command:

lsusb

You’ll see something like the following:

Bus 001 Device 030: ID 0403:6001 Future Technology Devices International, Ltd FT232 USB-Serial (UART) IC
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

Look for the line that references the FT232 (it’s easier if the FT232 adapter is the only USB device plugged in), then write down the Bus and Device numbers, and the ID. Now we need the serial number. This is where it gets a bit hairy… In the same terminal, enter this command:

lsusb -v -s 1:30

You need to replace “1:30” with the bus and device numbers (in my case, this is Bus 1 and Device 30), but with the leading zeroes trimmed. That means Bus 001 becomes Bus 1, and Device 030 becomes Device 30. Put those two numbers together, and you get “1:30”.

This should output something like this:

Bus 001 Device 030: ID 0403:6001 Future Technology Devices International, Ltd FT232 USB-Serial (UART) IC
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 0 (Defined at Interface level)
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 8
idVendor 0x0403 Future Technology Devices International, Ltd
idProduct 0x6001 FT232 USB-Serial (UART) IC
bcdDevice 6.00
iManufacturer 1 FTDI
iProduct 2 US232R
iSerial 3 FTDN3G52
bNumConfigurations 1

(trim lots of stuff)

Note the ‘iSerial’ value — ignore the number “3”, but write down the string next to it (“FTDN3G52″ in my case).

Now open a terminal, then enter the following command:

gksudo gedit /etc/udev/rules.d/99-wacomtablet.sh

You’ll be asked to enter your logon password — do so, then click OK and Gedit will open. Paste the following text into the file:

~~~
# Set the Wacom tablet’s latency timer to 1ms (stops all that nasty jittering and cursor lag)
SUBSYSTEM==”usb-serial”, ATTRS{idVendor}==”0403″, ATTRS{idProduct}==”6001″,
ATTRS{serial}==”XXXXXXXX”, PROGRAM=”/bin/sh -c ‘echo 1 > /sys%p/latency_timer'”, SYMLINK+=”ttyARTPAD”
# Assign a symlink to make things a little easier
KERNEL==”ttyUSB[0-9*]”, ATTRS{idVendor}==”0403″, ATTRS{idProduct}==”6001″, ATTRS{serial}==”FTDN3G52″, SYMLINK=”ttyARTPAD”
~~~

Now you need to edit the USB IDs. Replace “0403” and “6001” with your USB-RS232 dongle’s Vendor and Product IDs (respectively), and replace XXXXXXXX with your dongle’s serial number. Save the file, and close Gedit.

Lastly, we need to modify the X11 configuration a little. Enter these commands in a terminal:

cd /etc/X11
sudo cp xorg.conf xorg.conf.default
gksudo gedit xorg.conf

Copy this text into the file:

~~~~
Section “InputDevice”
Driver “wacom”
Identifier “stylus”
Option “Device” “/dev/ttyARTPAD”
Option “Type” “stylus”
EndSection

Section “InputDevice”
Driver “wacom”
Identifier “eraser”
Option “Device” “/dev/ttyARTPAD”
Option “Type” “eraser”
EndSection

Section “InputDevice”
Driver “wacom”
Identifier “cursor”
Option “Device” “/dev/ttyARTPAD”
Option “Type” “cursor”
EndSection

# yes, this really *is* necessary for the wacom
# remove it if the wacom tablet is removed
Section “ServerLayout”
Identifier “Default Layout”
Screen “Default Screen”

InputDevice “stylus” “SendCoreEvents”
InputDevice “eraser” “SendCoreEvents”
InputDevice “cursor” “SendCoreEvents”
EndSection
~~~~

Be careful — you will need to add the InputDevice sections to xorg.conf, but if you already have a ServerLayout section, don’t add a second one. Instead, copy the InputDevice lines from the ServerLayout section above into the existing ServerLayout section in your xorg.conf file.

Once you’re finished, save the file and close gedit. Plug the ArtPad in (power to the ArtPad, RS232 from the ArtPad to the dongle, then USB from the dongle to your PC) and reboot.

Lastly, configure GIMP and Inkscape to use pressure sensitivity — there’s more information about doing this [here](http://ubuntuforums.org/showthread.php?t=25151).

Enjoy!

First impressions on Ubuntu 9.04

After swearing that I’d give up on Windows since I started using Ubuntu, I’ve finally taken steps towards my goal. This morning, I hosed my Ubuntu 8.10 install and decided that it was high time I tried 9.04. After all, it’s been around for a good three months, so it should be pretty stable.

Well, it turns out it is stable. Just as good as its predecessor (8.10) in fact. I used the Alternate (text mode) installer because my system uses a FakeRAID, and said FakeRAID was detected with absolutely no problems whatsoever. In fact, the only way I could tell it was using a fakeraid was the prompt that asked me if I wanted to enable the FR volumes. Very nice.

First boot took less than 30 seconds, and the little bit of configuration I needed to do (installing the nVIDIA drivers and some security updates) took about 10 minutes. Most of which was the time it took to actually download the stuff… Installing build-essential, debhelper, Mercurial, Subversion, a few video plugins, and Kaffeine was just as breezy. And I killed off Compiz. Sorry, if I wanted Vista, I’d have gone to CCL, bought a copy and installed it.

There are a few things I don’t like, though. Most of them are to do with the app bundle included with GNOME…

* **The default media player (Totem) can’t handle DVB.** Despite the options in the menu, the DVB functions in Totem just plain don’t work. I think I spent a good half hour trying to make it work, got a channel list, but couldn’t get it to actually play video. I gave up, removed Totem and installed Kaffeine instead (which took five minutes or so to do a full scan of the local Freeview muxes, then displayed BBC One as its starting act, complete with EPG).
* **Sound-juicer seems to have “problems”.** Clicking “Help” in the Edit Profiles window makes sound-juicer exit with neither rhyme nor reason. Poof, gone.
* **Sandisk Sansa isn’t detected.** Pretty much as it says. 9.04’s kernel doesn’t detect my brother’s Sansa e280 media player. Meaning he’s cheesed off because I can’t copy bits of my music collection onto it for him to listen to.

On the plus side:

* The GNOME interface still looks pretty spiffy. One quick-access bar and system tray, one window list and desktop-switcher. Not a single bit of wasted space. Turning subpixel anti-aliasing off did clean it up a bit, though (white text in the Terminal gained a light blue tinge — turning SPA off fixed this).
* Rhythmbox seems to have improved a lot since the days of 8.04 — in fact, it resembles an earlier version of Amarok 1.4. I can’t actually see any point in installing Amarok any more…

So a bit of a mixed bag really… I like 9.04, but I’m going to be leaving 8.10 on my Eee until I can find some updated ACPI scripts and packages for it. I really don’t fancy installing Netbook Remix…

Makefile template v1.4

Hi folks,
I’ve done a little bit more work on my Makefile template..

Here be version 1.4

I’ve added a small bugfix — if you built a program solely from C code, the C++ linker would still be called to link the object files into an executable. This means that while the executable would work, the C++ runtime would also be linked in, adding an extra runtime dependency (libstdc++), and bloating the executable.

Now you specify the program type — whether it contains any C++ code, or consists solely of C code — in the SRC_TYPE Makefile variable, and the relevant compiler is called at build-time.

“Oops”.

Kubuntu -> Ubuntu, stage one complete…

Well, the upgrade from Kubuntu 8.04.1 LTS to 8.10 was fairly painless. I’ve lost the Eee OSD and ACPI script fixes I applied, and the installer rather helpfully removed the Array.org kernel, so I can’t use the WiFi on my Eee 1000H any more. Those are easy to fix, though.

KDE4.1 is… well… awful. It’s redlining the CPU and thrashing the HDD quite badly (on a 1.6GHz Intel Atom N270 with 2GB RAM no less). The UI is slow. Slow, slow, slow, slow, SLOW! I though the Vista beta in VMware Server was bad, but this takes the biscuit!

I like (some of) the eye-candy, but the plasmoids are completely over the top, and the random graphics glitches are awful.

Four and a half minutes from entering my password to actually being able to start an application.. Ugh.

Going cold turkey on KDE…

Those of you who know me in real life will probably know that I’ve been a KDE user since I started using Linux, back in the days of Mandrake (now Mandriva) 6.1. Wikipedia says that was 1999. Wow. Nearly ten years of Linux geekery… I feel old.

Since then I’ve used Slackware from about 2002 to 2004, then Fedora from ’04 to the back end of ’07. A very nice bloke by the name of Anthony Fielding then showed me the True Light of Ubuntu, and I adopted Kubuntu 7.10 on my desktop box. The one constant through all this was KDE.

Not anymore.

KDE4 is, in my opinion, a total joke. While I realise it’s still under heavy development, its default installation looks far too much like Windows Vista. The default taskbar colour scheme is awful (and KDE Control Centre won’t let you change it, at least not in 4.0 and not easily), and the speed on my Eee 1000H has gone from “reasonable” to “I could make a cup of tea before that finishes!”

I’ve been stubbornly sticking to Kubuntu 8.04.1 LTS (seeing as that’s the last KDE3 release) and lamenting the relative lack of updates to the Intel graphics drivers (which apparently fix a nasty bug that causes the VGA-out to cut out after an hour on 1000Hes, necessitating the use of the internal LCD or a reboot)… This evening I installed Ubuntu 8.10 on an 8GB Cruzer Titanium pendrive (which, incidentally looks awful by comparison to the earlier 2GB Titanium — Sandisk, what are you doing?) and spent a few minutes playing with Gnome.

I’m in love.

Again.

But even though I’m ditching KDE, I’m keeping Amarok. And maybe Kaffeine… Somehow Rhythmbox doesn’t quite suit the way I listen to music, and as for Kaffeine.. well, it’s just about the only Linux video player I can find that handles DVB correctly (as in: gives me a channel list instead of asking for frequencies, QAM constellation types and symbol rates).

Floppy disc reader/writer project — update 200810/1

A few of you might be aware of my pet project — a floppy disc reader/writer that operates at an insanely low level (it operates on individual magnetic flux transitions). The advantage of this thing being that it’ll be able to read (and write!) just about any disc format that can be read in a standard 3.5″, 5.25″ or 8″ disc drive.

Well the big news is that I’ve got approval to cover the software side of things for my final year university project. I’ve also taken a different route to developing the hardware — I’m going to use an Altera Cyclone II Starter Kit (and a pair of bodge-boards) to build a prototype, then work on pulling it into the CAD software later. Given that the HDL code is basically done, this means I can spend nearly all of my 30 weeks (well, 27 weeks now) getting the software finished.

For anyone who hasn’t seen the C2SK board, it’s basically a rebadged TerASIC DE1 development board. 18 LEDs, four momentary switches, 10 two-position switches, a four-digit seven-segment display, 8MBytes of SDRAM, 4MBytes of flash, 512KBytes of SRAM, an SD card slot (!), VGA out, RS232, audio in and out, a PS/2 keyboard connector and two User I/O connectors… which are good old 40-pin IDC sockets. All for £99 plus VAT from Digikey.

And the default startup program does a neat LED chaser display that has been described as “[airport security attract mode](http://flickr.com/photos/68931440@N00/1590316984/)”. I can’t help but agree, the demo sequence is very show-offy.

Software-wise, I’ve done a few quick tests to do histogram analysis of disc track data, but I’m going to have a crack at some MFM decoding over the next week or so. Chuck G. was kind enough to send me some FM, MFM and GCR samples last year, which I’m ashamed to admit I haven’t had a serious look at yet. I really need to get my hands on a few floppy discs from “strange and unusual” machines. I’m aiming for Amiga and BBC Micro at the moment, but I’ll probably add PC floppies to the mix later on.

But first, I need to get the SDRAM working with the FDDReaderWriter HDL code…

USB-TMC isn’t all it’s cracked up to be

Why can’t anything be as easy as it looks?

I’ve spent the past two days trying to get my Tek TDS2024B to talk to a Linux box via a homebrew USB-TMC driver library. Based on the USB-TMC spec, I’m doing everything by the book — and in fact, I can get the scope to respond to a GET_CAPABILITIES control request. Problem is, as soon as I try and send a command over the Bulk endpoint, it times out.

Urgh. I’m going to spend a few minutes reading through some libusb sample code, then if I still can’t get it going I’ll try and finish reverse-engineering the nasty binary serial protocol the HM8130-3 signal generator uses.

QUICK PROJECT: Improving the Freecom 25451 Rev3 DVB-T stick

I’ve finally gotten sick of the incredibly dire SMB connector on my Freecom 25451 Rev3 USB DVB-T receiver ‘stick’. The adapter that converts the SMB into a more standard Belling-Lee UHF connector (which is a horrible design as well, but a necessary evil around these parts) has been falling out, slipping and causing signal dropouts for weeks. All of this, of course, makes it rather difficult to watch any TV, let alone film4 (which is on Freeview Mux D — the mux on the Emley Moor transmitter that has the lowest transmission power).

At about this time, I decided the rat-bitten LNB cable on the Sky dish had to be replaced. This was duly done (earning me a great many cuts and scratches courtesy of the local flora) and I had a bag of half a dozen F connectors and a few metres of WF100 satellite cable left over. What better to do than fit a proper RF connector to the DVB stick?

The first step is getting the thing open. Hold the ‘451 with the “FREECOM DVB” logo badge facing upwards, the serial number label facing down, and the USB plug facing towards you. Insert a screwdriver in the gap between the top edge of the USB connector and the top section of the plastic case. Prise it apart gently until you hear a ‘snap’ as the first bit of glue gives way. Do this all the way around the ‘451, then pull it apart. Put the top cover to one side – you’ll need it later.

The next step is to remove the PCB. This is a bit easier – hold the base plastic, then lift the USB connector up and away. The SMB connector will snap out of the back when you do this.

Now desolder the SMB connector. Desolder the metal body of the connector using desoldering wick (you’ll need a lot of heat to do this — use a 50W solder station set to about 400 C). Once you’ve done that to all four pads (two on the top, two on the bottom), desolder the central pin. Remove the connector (careful, it’s hot!) and put it to one side. Clean up the solder pads by wiping the (clean!) tip of the soldering iron across them a few times.

Now prepare the cable. Cut a ~6in length of WF100 cable (the proper stuff is labelled “WEBRO WF100 CAI”). This is foam-core satellite-grade double-shielded low-loss coaxial cable, and is quite expensive, but the cost is worth it (and the foam is fairly heat-resistant). Strip about an inch of the outer insulation from both ends, without damaging the shielding braid. Pull the braid back, and separate it into four equally-sized bundles. Twist these bundles together to form four pigtails, then tin them. Remove the copper tape insulation and remove all but 5mm or so of the inner foam. The easiest way to do this is to cut half way through the foam all the way around the cable, then pull the two sections apart. Leave this section of the cable for now, and fit an F connector plug to the other end of the cable.

Put the now-bare end of the cable against the PCB, and cut the inner wire down so that it covers about three quarters of the PCB pad that was connected to the SMB connector’s inner pin. Match each of the four pigtails up with a ground pad and cut them down to match the ground pads. Solder the grounds down, then the centre wire.

Now check your soldering – make certain there are no little flakes of shielding touching the inner wire, and that the solder joints are solid and shiny. If they’re not, fix them. Also make sure you haven’t shorted out any of the pads – there’s not a lot of clearance, especially between the ground pads and the PCB components.

Put the PCB back into the case, and push it down. The co-ax cable will not sit properly in the grip that held the SMB connector – push it down firmly until it sits on the flat at the bottom. Fit the top cover and squeeze it together around the co-ax cable. You’ll note that one part of the top casing will not sit flush with the cable. Get a small file and trim it down a few millimetres so the case fits together correctly.

Now plug the USB stick in and test it. Make sure you can tune to a channel and watch TV as normal. If everything seems to work, take the bottom section (with PCB), put a few drops of superglue along the edge and squeeze the case together (I find the gel-type superglues easier to use for this). Hold it together until the glue takes hold. Leave it for about an hour (or so) to set.

There you go – one DVB-T stick with a “proper” RF connector. Fit a coupler to the F plug (of the sort used to connect two F plugs together), and make (or buy) a cable to go from your TV aerial outlet socket to the F connector on the coupler. Wire everything up, and enjoy.

Photos coming soon…

HOWTO: Fix the USB VID/PID on a Freecom DVB stick

A power cut scrambled the USB IDs on my Freecom DVB-T stick this morning… Freecom didn’t want to reply, the supplier just didn’t want to know (“your warranty is with Freecom, not us” – so much for the Sale of Goods Act). Anyway, here’s what I did to fix the VID/PID block on my DVB stick:

Note: this applies to the Freecom 25345-rev.3 DVB stick and may or may not work on others (e.g. the other Wideview WT220U clones with Cypress USB chipsets). Feel free to try this out, but if you bugger up your DVB stick beyond repair, you agree not to hold me liable for your cock-up. But of course, if your DVB stick is fried, you don’t exactly have anything to lose, do you? 🙂

OK, first you need the USB vendor and product ID your USB stick has adopted. Boot off a Linux LiveCD with the DVB stick plugged in by itself – that means NO OTHER USB DEVICES. Then as root run the command:
cat /proc/bus/usb/devices
Ignore all the crap about USB host adapters – what you’re looking for is a line like this:
P: Vendor=1402 ProdID=0255 Rev= 0.00
So we know the DVB stick has adopted the Vendor ID (VID) 0x1402, and the Product ID (PID) 0x0255. Shut down and reboot into Windows.

Rebooted yet? Good. Grab yourself a copy of the Cypress “CY4604 – USB Developer’s uStudio” and install it.

Now we need to do something a little fiddly. Go into C:\Program Files\Cypress\USB DevStudio\Driver, and open CyUSB.inf in Notepad. Search for this:
[Cypress]
;%VID_VVVV&PID_PPPP.DeviceDesc%=CyUsb, USB\VID_VVVV&PID_PPPP

Note that the USB VID/PID spec line is commented out with a leading semicolon. Remove that semicolon, then do a search-and-replace over the entire file – replace VVVV with the USB vendor ID (without the 0x radix specifier) and PPPP with the Product ID you found earlier (again without the radix specifier). Save the file and close Notepad.

Now plug the DVB stick in. When windows asks for drivers, point it to C:\Program Files\Cypress\USB DevStudio\Driver – the Cypress driver will install.

Run Cypress CyConsole (Start, Programs, Cypress, USB, CyConsole). You should see the DVB stick in the device list. Select the device from the list, then go to Options -> EZ-USB Interface.

Click the “Select Mon” button, then select C:\Program Files\Cypress\USB DevStudio\CyConsole\FW\Vend_Ax.hex (this is the Cypress EEPROM Bootloader).
Click the “Load Mon” button to load the bootloader, and wait for the text to stop scrolling.

In the “Vendor Request” panel (with the “Vend Req” button on the left of it), enter the following values, in this order:
Req: 0xA2
Value: 0x0000
Index: 0x0000
Dir: 1 IN
Hexbytes: (empty)
Length: 256

Press the Clear button, then the Vend Req button. Copy and paste the contents of the log display into a text file.

Now look at the first line of the data that was returned, in my case this was:
0000 C0 02 14 25 02 00 00 08 FF FF FF FF FF FF FF FF

The first byte (C0) is the Boot Specifier – this tells the EZ-USB chip that the data in the EEPROM is a vendor/product ID pair.

The two bytes after that are the Vendor ID in low-byte/high-byte (little endian) order. The two bytes after those are the Product ID, again in little endian byte order. We need to fix these. I want my stick’s VID to be 0x14AA, and its PID to be 0x0225. That means I need to write the following data to the EEPROM:
C0 AA 14 25 02

Hit the Clear button again, and focus your attention on the Vendor Request panel once more. This time set these values:
Req: 0xA2
Value: 0x0000
Index: 0x0000
Dir: 0 OUT
Hexbytes: The data you want to write – in my case, C0 AA 14 25 02
Length: Should be 5, otherwise you’ve done something wrong.

Hit Vend Req again. Another line of text will appear at the end of the log – that’s the data that was sent to the bootloader.

Now set Dir to “1 IN” and clear the Hexbytes field. Set Length to 16 and hit the Vend Req button again. Another line will appear under the ‘data written’ line – it should look a bit like this now:
0000 C0 02 14 25 02
0000 C0 02 14 25 02 00 00 08 FF FF FF FF FF FF FF FF

As long as the first five bytes of the data are correct, you’re done. Unplug the USB stick, wait a few seconds for it to reset, then plug it back in again. Your USB DVB-T stick should now know what it is, and more importantly the drivers will recognise it again.