Sunday, October 11, 2009

My second *useful* script for starting newer USB mobile broadband modems on Linux Ubuntu Jaunty

My first and only script was for clearing printer queues at Computerbank network sites with every reboot. I've seen other scripts and can figure out what they do.

I attempted a script for initialising different modems - K3565-Z, MF627, U6T. It works! I am polishing it up as well. For eg, it would be good for the thing to have an error message if the user chooses the wrong modem.

For now it does the job, initialises the right modem (based on user choice). It is also user friendly, with nice dialog boxes. I'm trying to figure out how to put an icon in for disconnected network manager in one of the info boxes. Icing on the cake. I found zenity very easy to use and thank the internets for all the good info and examples that got me started.

Anyway here it is (complete with debugging help by Patrick, David and Barry). Watch out for stray spaces!

#!/bin/sh
# AU 3G Modem Chooser and Initialisation Script
# Needs to be run with gksu (friendly user prompt for password) or sudo when calling
# from the command line.
# Author: Kylie Davies
# Date: 10/10/09
{
# Start with a message, in case user starts accidentally.

if $(zenity --question --text="Use this utility to select and activate USB Mobile Broadband modems." --title="USB Modem Helper")
then

ans=$(zenity --list --text "Choose your USB mobile broadband modem from the list." \
--radiolist --height=220 --column "Pick" --column "USB Modem Type or Model" TRUE Pink\ GRL\ modem\ -\ U6T FALSE White\ Vodafone\ modem\ -\ K3565-Z \
FALSE Black\ and\ green\ Three\ modem\ -\ MF627 FALSE Not\ Listed.);

echo "||$ans||"
if [ "$ans" = "Pink GRL modem - U6T" ]
then
echo "1111"
sudo modprobe option && echo "0x05c6 0x9000" > /sys/bus/usb-serial/drivers/option1/new_id && sleep 1 |zenity --progress --text "Starting Modem" --title "Starting Modem"
zenity --info --title "Modem Ready" --text "Your modem is ready. Left click the icon at the top right of your screen to create or use a mobile broadband connection."

elif [ "$ans" = "White Vodafone modem - K3565-Z" ]
then
echo "2222"
sudo modprobe option && echo "0x19d2 0x0052" > /sys/bus/usb-serial/drivers/option1/new_id && sleep 1 |zenity --progress --text "Starting Modem" --title "Starting Modem"
zenity --info --title "Modem Ready" --text "Your modem is ready. Left click the icon at the top right of your screen to create or use a mobile broadband connection."

elif [ "$ans" = "Black and green Three modem - MF627" ]
then
echo "333"
sudo modprobe option && echo "0x19d2 0x0064" >> /sys/bus/usb-serial/drivers/option1/new_id && sleep 1 |zenity --progress --text "Starting Modem" --title "Starting Modem"
zenity --info --title "Modem Ready" --text "Your modem is ready. Left click the icon at the top right of your screen to create or use a mobile broadband connection."

elif [ "$ans" = "Not Listed." ]
then
echo "555"
zenity --info --title "More Info Needed" --text "Call Computerbank for advice."

else
echo "444"
fi
fi
}

4 comments:

  1. Beautiful! Though I run Debian proper, not Ubuntu, your work has helped me improve the inelegant hack I use with my 3 Mobile ZTE MF-627 (AU).
    I was using the usbserial module (2.6.26-2-686) but the option module seems to work better. I have turned off the autorun on mine, but Lenny still loads usb_storage when it detects vendor=0x19d2 product=0x0064 ;-(

    So in order to get /dev/ttyUSB2 I need to rmmod usb_storage first. I ,was, then running modprobe usbserial vendor=0x19d2 product=0x0064 ,which would create /dev/ttyUSB0-2, then using wvdial to connect to /dev/ttyUSB2. gnokii connects to the same port for sms. Until I figure out how usb_storage gets loaded I just prepend rmmod usb_storage; to your echo command.

    The default buffer with the standard modules I use is only 64b, I need to rebuild option or usbserial to allow setting a larger buffer for higher data transfer speeds.... If your Ubuntu option module supports a larger buffer you can set it by appending maxSize=n to your modprobe line. eg. modprobe option vendor=0x19d2 product=0x0064 maxSize=4096
    You can check if your option module is capable with something like strings /lib/modules/2.6.26-2-686/kernel/drivers/usb/serial/option.ko | grep maxSize

    PS. Instead of using modprobe in your zenity script, have you thought of using an entry in /etc/modules.conf instead?? eg. options usbserial vendor=0x16d2 product=0x0064 maxSize=4096

    ReplyDelete
  2. Hi Scott,

    Good to know you found this useful.

    I'm not sure about modules.conf - maybe it didn't work with NM?

    Computerbank needs to support a variety of these devices and some of them are new to using a mouse!

    If modules.conf can support a range of configs, and if a device is inserted, NM knows and becomes aware so the user can configure it via the wizard tool.

    Hopefully this can happen without any user assistance. So nice.

    We just came across another new device that won't play nice - the Vodafone K3765 ! Hopefully one of the Computerbank volunteers sort it out.

    ReplyDelete
  3. Oops.. to clarify.. some of our users are new to using a mouse. :)

    ReplyDelete
  4. Huawei K3765-Z Vendor=0x12d1 Product=0x1465???? modprobe usbserial/option etc etc will/should do it.

    ReplyDelete