Saturday, July 4, 2009

Enable UPnP support in Mandriva with Shorewall

I found that in order to enable UPnP support in Shorewall, I need to have linux-igd installed. However, I couldn't find a ready-to-install linux-igd RPM for Mandriva. Therefore, I had to perform the following
  • Downloaded the linux-igd-1.0-7 RPM for Fedora 10 from here
  • Install libupnp3-1.6.6-1mdv2009.0 by running urpmi libupnp3
  • Install the linux-igd in Mandriva by running rpm -Uvh --nodeps linux-igd-1.0-7.fc10.i386.rpm.rpm
  • Update the file  /etc/sysconfig/upnpd  with the right interfaces
  • Make the following changes in /etc/init.d/upnpd to make it compatible with MSN/Windows live messenger. (I used the tag <pre name="code" class="cpp"></pre> to embed code here)
9a10,16
> #
> ### BEGIN INIT INFO
> # Provides: upnpd
> # Default-Start: 3 4 5
> # Short-Description: Internet Gateway Device
> # Description: Emulates Microsoft's Internet Connection Service (ICS)
> ### END INIT INFO
15c22
< allow_multicast="no"> ALLOW_MULTICAST=yes
36c43
<           [ "$ALLOW_MULTICAST" != "no" ] && route add -net 239.0.0.0 netmask 255.0.0.0 $INTIFACE --- >           [ "$ALLOW_MULTICAST" != "no" ] && route add -net 224.0.0.0 netmask 240.0.0.0 $INTIFACE
50c57
<       [ "$ALLOW_MULTICAST" != "no" ] && route del -net 239.0.0.0 netmask 255.0.0.0 $INTIFACE --- >       [ "$ALLOW_MULTICAST" != "no" ] && route del -net 224.0.0.0 netmask 240.0.0.0 $INTIFACE
63c70,71
<>       stop
>       start

and the following changes to /etc/upnpd.conf as described in ShoreWall and UPnP.
51c51
< forward_chain_name =" FORWARD"> forward_chain_name = forwardUPnP
57c57
< prerouting_chain_name =" PREROUTING"> prerouting_chain_name = UPnP
63c63
< upstream_bitrate =" 512000"> upstream_bitrate = 384000
69c69
< downstream_bitrate =" 512000"> downstream_bitrate = 1000000

I also made the following changes to the ShoreWall configuration files (my loc->fw policy is already ACCEPT)
grep -i pnp /etc/shorewall/*    
/etc/shorewall/interfaces:net     eth1            detect dhcp,tcpflags,nosmurfs,routefilter,upnp
/etc/shorewall/rules:forwardUPnP     net        loc

Finally I started the upnpd daemon by servcie upnpd start and chkconfig --add upnpd then service shorewall restart.

After a windows workstation initiated a video call in MSN messenger, the following ports were opened:
iptables -t nat -L UPnP
Chain UPnP (1 references)
target     prot opt source               destination         
DNAT       udp  --  anywhere             anywhere            udp dpt:36481 to:192.168.0.113:16727 
DNAT       tcp  --  anywhere             anywhere            tcp dpt:32995 to:192.168.0.113:9049

The version of relevant packages:
Kernel: 2.6.29.1-server-4mnb
Iptables: 1.4.3.1-3mnb2
Shorewall: 4.2.10-1mdv2010.0

Friday, July 3, 2009

Use Opti-UPS CS730B with Linux

It has a USB port, however it can not be autodetected by nut-2.4.1 of my Mandriva linux since the port /dev/ttyUSB0 was not created when it's plugged in. The kernel detected a powercom USB to serial converter but the usbhid driver is binding to it as shown in /proc/bus/usb/devices

T: Bus=02 Lev=01 Prnt=01 Port=03 Cnt=01 Dev#= 7 Spd=1.5 MxCh= 0
D: Ver= 1.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1
P: Vendor=0d9f ProdID=0002 Rev= 0.00
S: Manufacturer=POWERCOM CO., LTD.
S: Product=USB to Serial
C:* #Ifs= 1 Cfg#= 1 Atr=80 MxPwr=100mA
I:* If#= 0 Alt= 0 #EPs= 2 Cls=03(HID ) Sub=00 Prot=00 Driver=usbhid
E: Ad=81(I) Atr=03(Int.) MxPS= 8 Ivl=10ms
E: Ad=02(O) Atr=03(Int.) MxPS= 8 Ivl=10ms

Apparently it's not of the USB/HID UPS type since it can't be matched to any known device by usbhid-ups. I searched the internet and found a proposed fix: In order to recognize it correctly, I had to rmmod usbhid cypress_m8 and modprobe cypress_m8. Afterwards the following is shown in




T:  Bus=01 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#=  4 Spd=1.5 MxCh= 0
D:  Ver= 1.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 8 #Cfgs=  1
P:  Vendor=0d9f ProdID=0002 Rev= 0.00
S:  Manufacturer=POWERCOM CO., LTD.
S:  Product=USB to Serial
C:* #Ifs= 1 Cfg#= 1 Atr=80 MxPwr=100mA
I:* If#= 0 Alt= 0 #EPs= 2 Cls=03(HID  ) Sub=00 Prot=00 Driver=cypress
E:  Ad=81(I) Atr=03(Int.) MxPS=   8 Ivl=10ms
E:  Ad=02(O) Atr=03(Int.) MxPS=   8 Ivl=10ms



and the following from dmesg:

cypress 2-4:1.0: HID->COM RS232 Adapter converter detected
usb 2-4: HID->COM RS232 Adapter converter now attached to ttyUSB0


Subsequent modprobe usbhid doesn't remove the port ttyUSB0. Now I can download a copy of the managing software from the manufacture OPTI-UPS: OPTI SAFE Xtreme+ V1.0 for Linux (dated 2009-05-21), which appears to me a tar archive. Its License Key (85OPT4-584499) & User Manual can be downloaded from the same link (RAR archive). After I install it, I have the following lines in /usr/ups/ups.cfg
UpsModel=--CLEVER Series 110V/60Hz--
UpsDevice=/dev/ttyUSB0:1200,n,8,1
UpsCable=0
PortTCP=8081

Then I can start the upsman and

  • Connect to its web server through http://localhost:8081/ and monitor the status of the CS730B. After disconnect, I can also configure it through the web.
  • Configure the UPS by running the command service upsman conf