Saturday, March 31, 2012

Fixing the aircrack "Fixed channel mon0: -1

This guide will show you how to fix the "Fixed channel mon0: -1" message that appears when using Airodump-ng and the error Aireplay-ng gives.

The guide will show you how to compile your own kernel with the channel patches. The patch has been tested and works in 3.1.6, and it will probably work on any newer kernel until the patch makes it to the kernel source itself.

First, download he latest kernel source. You can go to http://www.kernel.org/ and find the latest stable source.

Then, open a terminal. Navigate to the directory where the archive is:
cd <directory>

If the source archive was downloaded in /home/user/Downloads, then you would type
cd /home/user/Downloads

Then extract the sources. In a terminal, you can do this to extract it:
tar -xvjf <archive filename>

Using the 3.1.6 kernel source for example, one would do:
tar -xvjf linux-3.1.6.tar.bz2

Now, go into the source directory. If your distro requires any special configuration, you can copy the existing .config from /usr/src/linux-<kernel version>. If you are not sure, do this.
cp /usr/src/linux-<kernel version>/.config .

If your previous kernel version was 3.1.2, for example, you would do this:
cp /usr/src/linux-3.1.2/.config .

Then do
make mrproper

If you need to customize anything for the new kernel, you can do it now.

Now we will download and apply the patches. Make sure you are still in the source directory, and do:
wget http://patches.aircrack-ng.org/mac80211.compat08082009.wl_frag+ack_v1.patch wget http://patches.aircrack-ng.org/channel-negative-one-maxim.patch patch -p1 mac80211.compat08082009.wl_frag+ack_v1.patch patch -p1  channel-negative-one-maxim.patch

Now, compile the new kernel:
make
make modules

Note: If you want to use as much CPU as possible when compiling, use the -j flag on both commands, followed by the numbers of threads to create. For example, -j3 will tell the compiler to have 3 threads.

Then, you can install the kernel. Execute the following commands as root, using su or sudo.
make modules_install
make install

When the kernel has installed without any problems, be sure to update grub, lilo, etc, and put the new kernel into the bootloader's list. Here is some info on bootloaders in case you need help with updating the boot menu:

Grub Legacy: http://www.dedoimedo.com/computers/grub.html

Grub 2: http://www.dedoimedo.com/computers/grub-2.html

Lilo: https://wiki.archlinux.org/index.php/LILO

Pulseaudio: USB sound device hotplug

When using Pulseaudio and pavucontrol, one can easily change the default sound device by clicking the fallback button on the device. However, this assumes that the default device is always connected.
When a USB sound device, for example a headset, is set as fallback and then disconnected, the fallback device becomes the PCI sound device, or whatever device is still connected. This happens both for source and sink configuration.

It is possible to solve the problem by creating a udev rule.
What needs to be done:
- Use udev to identify the USB sound device plugging in.
- Run pacmd to set default source & sink as the current user.

In this example, I used a Speedlink Medusa 5.1 USB headset, which is configured in pulseaudio as "Analog Surround 5.1 Output & Analog Stereo Input". The system I'm using therefore has these devices:

1. Intel HD Audio
2. USB sound device

Using aplay -l displays the following:
[stavros@stavros-laptop ~]$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: Intel [HDA Intel], device 0: ALC889 Analog [ALC889 Analog]
  Subdevices: 0/1
  Subdevice #0: subdevice #0
card 0: Intel [HDA Intel], device 1: ALC889 Digital [ALC889 Digital]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: Intel [HDA Intel], device 3: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: Device [USB Sound Device], device 0: USB Audio [USB Audio]
  Subdevices: 0/1
  Subdevice #0: subdevice #0
As you can see, the internal sound card is listed as card 0, and the USB device I want to set as default is listed as card 1.
Since I won't be plugging in any other sound device, I can use "card1" in a udev rule.

udevadm shows events that can be used to create rules for:
[stavros@stavros-laptop ~]$ udevadm monitor --kernel --subsystem=sound
monitor will print the received events for:
KERNEL - the kernel uevent

KERNEL[2215.105651] add      /devices/pci0000:00/0000:00:1d.0/usb5/5-1/5-1:1.0/sound/card1 (sound)
KERNEL[2215.105732] add      /devices/pci0000:00/0000:00:1d.0/usb5/5-1/5-1:1.0/sound/card1/pcmC1D0p (sound)
KERNEL[2215.105824] add      /devices/pci0000:00/0000:00:1d.0/usb5/5-1/5-1:1.0/sound/card1/pcmC1D0c (sound)
KERNEL[2215.106001] add      /devices/pci0000:00/0000:00:1d.0/usb5/5-1/5-1:1.0/sound/card1/controlC1 (sound)
KERNEL[2215.190918] change   /devices/pci0000:00/0000:00:1d.0/usb5/5-1/5-1:1.0/sound/card1 (sound)

The device was not completely initialised when the "add" event fired, so I used the "change" event at the end, and created the following rule in /etc/udev/rules.d:

/etc/udev/rules.d/60-snd-usb.rules
SUBSYSTEM=="sound", KERNEL=="card1", ACTION=="change", RUN+="/home/stavros/bin/pulse-ins.sh"

This rule will execute /home/stavros/bin/pulse-ins.sh when card1 is inserted.
One script alone would not work, so I used 2, with pulse-ins.sh merely executing the other script

/home/stavros/bin/pulse-ins.sh:
#!/bin/bash
su -c "/home/stavros/bin/pulse_insert_card.sh & exit" stavros
This script is executed by udev, and it runs another script as the current user, since pacmd has to be run as a regular user.

/home/stavros/bin/pulse_insert_card.sh:
#!/bin/bash
/usr/bin/pacmd set-default-sink alsa_output.usb-0d8c_USB_Sound_Device-00-Device.analog-surround-51
/usr/bin/pacmd set-default-source alsa_input.usb-0d8c_USB_Sound_Device-00-Device.analog-stereo
This runs pacmd and sets the default source & sink devices.

Then, the following command reloads the udev rules without having to reboot. It must be run as root:
[root@stavros-laptop stavros]# udevadm control --reload-rules

Now, the USB sound device will be set as fallback when plugged in, and the internal device will be used as fallback when it is disconnected.

Sunday, November 20, 2011

Connecting to Cytanet using own modem

UPDATE: The DSL Access and Netrunner merge is complete, and the modem I use no longer seems to work with the configuration below.

Cytanet, the ISP I'm using, gives out Thomson TG585v7 modems to their customers. However, the modem is in-famous for its lack of features and performance. The ISP's using it also have a tendency to lock it down, and I got the dreaded NAT Type 3 on my PS3, despite forwarding all ports to it. Cytanet also uses a weird configuration only for its simplicity, because every single user just wants Facebook right?
Some people have had problems that made them switch to another ISP, others, however, have perfect service and get the advertised speeds. I happen to be near one of their exchanges, so I get good performance, which was also improved when I changed modems, from a Thomson 585v7 to a TP-Link W8920GB.
The Thomson modem suffers from ISP lock-down and retarded configuration. It is also slow to sync and browsing the configuration pages makes you angry.
Cytanet currently configures the modem as a router as well, but since I am not a networking expert I used the old method, back when they gave out B-Focus modems with bridge only mode.

I have a TP-Link W8920G and a Linksys WRT160N with DD-WRT, connected to the 1st Ethernet port of the TP-Link. I used the TP-Link only as a modem, since all the configuration of port forwards, QoS, etc was done on the Linksys router.

1. Create a Bridging connection, with VPI/VCI 8/35, and LLC encapsulation
2. Create a virtual lan/bridge between the port the router is connected and the bridge
3. Set the router to clone the mac address of the Thomson modem
4. Set the router to use DHCP for its WAN connection


The modem should become a bridge-only device, with only one port being able to access the internet. The other 3 ports on my modem can be used to access its configuration.
The router should get a public IP address, since Cytanet identifies it as the old modem because of the fake MAC.

The TP-Link syncs almost immediately, unlike the Thomson which took about 10-15 seconds. The latency also dropped by around 80ms as well. The PS3 also shows "Nat Type: 2".


I will some day attempt to enable the modem's router mode, because I don't want to trash the remaining 3 ports and Wi-Fi, and also try to make devices that connect through them use the Linksys router's DHCP.