WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Huawei USB Modem + UDEV rule  (Read 24113 times)

Offline s3704ssv

  • Newbie
  • *
  • Posts: 30
Huawei USB Modem + UDEV rule
« on: March 10, 2010, 11:58:06 PM »
Hello to All,

I'm trying to make my Huawei USB Modem(s) 'automatically' be configured into "MODEM" mode as I insert/remove these devices every once in a while.

USB Modem Details:
Make and Model: Huawei E1552 [detected as E620]
idVendor: 12d1
idProduct: 1446 [when in Mass Storage Mode]
idProduct: 1001 [when in Modem Mode]

I have manually compiled usb_modeswitch [placed in /sbin] and I can successfully switch these modem(s) into modem mode with: usb_modeswitch -H -v 12d1 -p 1446 -M 55534243123456780000000000000011060000000000000000000000000000


however, I'm really STUCK in making a UDEV rule for it   ???

kindly see the attached udev rule.


Can someone enlightened me in this regards?

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11044
Re: Huawei USB Modem + UDEV rule
« Reply #1 on: March 11, 2010, 06:02:44 AM »
Your rule looks fine. Did you reload rules after putting your rule in /etc/udev/rules.d?
The only barriers that can stop you are the ones you create yourself.

Offline s3704ssv

  • Newbie
  • *
  • Posts: 30
Re: Huawei USB Modem + UDEV rule
« Reply #2 on: March 11, 2010, 06:15:07 AM »
@curaga
I forgot to mention aswell that I reloaded the rules by issuing udevadm control --reload-rules


I have made UDEV rules before and it worked out fine [in Ubuntu], but in TC, I really don't know why this is happening

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11044
Re: Huawei USB Modem + UDEV rule
« Reply #3 on: March 11, 2010, 06:44:23 AM »
See if there is anything interesting in the logs. Start syslogd (either via bootcode or from the control panel), change udev's log level to debug (udevadm control --log-priority=debug), and plug in the modem.
The only barriers that can stop you are the ones you create yourself.

Offline s3704ssv

  • Newbie
  • *
  • Posts: 30
Re: Huawei USB Modem + UDEV rule
« Reply #4 on: March 11, 2010, 06:48:57 AM »
thank you, I'll try it tonight and see what happens, I'll post the results tomorow.

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: Huawei USB Modem + UDEV rule
« Reply #5 on: March 11, 2010, 07:09:15 AM »
I don't think it is an issue, but udevadm version in the repo is 146 while udev in the base is 151. Just for security I submitted matching version 151 of udevadm.
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11044
Re: Huawei USB Modem + UDEV rule
« Reply #6 on: March 11, 2010, 07:15:48 AM »
The udevadm extension shouldn't be necessary for >= 2.9, as udevadm replaced the separate control programs it is included in the base.
The only barriers that can stop you are the ones you create yourself.

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: Huawei USB Modem + UDEV rule
« Reply #7 on: March 11, 2010, 07:21:26 AM »
Originally it was added to the repo just for HAL. As HAL is now obsolate and is outphasing, I'm happy as it is now and do not want to deal with until not really necessary. And udevadm is so small :)
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline s3704ssv

  • Newbie
  • *
  • Posts: 30
Re: Huawei USB Modem + UDEV rule
« Reply #8 on: March 12, 2010, 03:53:44 AM »
@curaga and @bmarkus

I thank you all for the swift reply to my concerns ^_^

anyways..., here are my findings.

in /var/log/messages it reported an error with the usb_modeswitch rule with: "Mar 11 21:01:20 (none) syslog.err root: usb_modeswitch: tcl shell not found, install tcl package!"

and then I found out that tclsh was in /usr/local/bin/tclsh rather than /usr/bin/tclsh as found in the usb_modeswitch.sh [or usb_modeswitch] found in /lib/udev/ directory.
I then corrected the path in the script but funny thing is..., did'nt solved my problem.


what I did upon solving the problem is that I installed normally the usb_modeswitch.
code: [script, binary, configurations]
root@box:/mnt/hda1/usb_modeswitch/usb-modeswitch-1.1.0# make install
install -d /usr/sbin
install --mode=755 ./usb_modeswitch /usr/sbin
install --mode=755 ./usb_modeswitch.sh /lib/udev/usb_modeswitch
install -d /etc/usb_modeswitch.d
install --mode=644 -t /etc/usb_modeswitch.d ./usb_modeswitch.d/*
install --mode=644 usb_modeswitch.1 /usr/share/man/man1
mkdir -p /lib/udev/rules.d
install --mode=644 40-usb_modeswitch.rules /lib/udev/rules.d
if [ `which udevadm 2>/dev/null` ]; then \
                UDEVADM=`which udevadm`; \
                UDEVADM_VER=`$UDEVADM -V 2>/dev/null`; \
                if [ -z $UDEVADM_VER ]; then \
                        UDEVADM_VER=`$UDEVADM --version 2>/dev/null`; \
                fi; \
                if [ $UDEVADM_VER -gt 127 ]; then \
                        $UDEVADM control --reload-rules; \
                else \
                        $UDEVADM control --reload_rules; \
                fi \
        elif [ `which udevcontrol 2>/dev/null` ]; then \
                `which udevcontrol` reload_rules; \
        fi
root@box:/mnt/hda1/usb_modeswitch/usb-modeswitch-1.1.0#

then created another UDEV rule and placed it in /etc/udev/rules.d [copied/modified/stripped from usb_modeswitch]
code:
# This is part of USB_ModeSwitch version 1.x.x
#
ACTION!="add", GOTO="modeswitch_rules_end"
SUBSYSTEM!="usb", GOTO="modeswitch_rules_end"

# All known install partitions are on interface 0
ATTRS{bInterfaceNumber}!="00", GOTO="modeswitch_rules_end"

# only storage class devices are handled; negative
# filtering here would exclude some quirky devices
ATTRS{bDeviceClass}=="08", GOTO="modeswitch_rules_begin"
ATTRS{bInterfaceClass}=="08", GOTO="modeswitch_rules_begin"
GOTO="modeswitch_rules_end"

LABEL="modeswitch_rules_begin"
# Huawei E270+  (HSPA+ modem)
ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="1446", RUN+="/sbin/usb_modeswitch -c /etc/usb_modeswitch.conf"

LABEL="modeswitch_rules_end"


I just don't know why the default UDEV rule which came from usb_modeswitch does'nt work, anyways, attached is the log/files used [in case someone is interested].


by now, I'm assured that my Modem(s) will switch when inserted however, I'm still confused why there are tons of /dev/ttyUSBx for 1 modem!?

is there anyway that I can 'map' this? like...,  I would like to have a particular modem with IMEI of xxxxxxx be mapped to /dev/ttyUSBx correctly?

Im using these huawei devices [4~6units] with the program 'gammu' used as an SMS Server/Gateway Project and Tinycore as its OS ^_^

[attachment deleted by admin]

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11044
Re: Huawei USB Modem + UDEV rule
« Reply #9 on: March 12, 2010, 05:02:17 AM »
There are some devices pre-created in TC /dev.

You could add a rule to symlink to a certain name (SYMLINK+="myhuawei1"). Though, I'm not sure if udev can access the IMEI.
The only barriers that can stop you are the ones you create yourself.

Offline topcat2010

  • Newbie
  • *
  • Posts: 3
Re: Huawei USB Modem + UDEV rule
« Reply #10 on: June 02, 2010, 01:04:08 PM »
I used Sony gsm phone and could create udev rules based on serial the device. To set up symbolic links that used in the configuration file gammu.
 
# lsusb -v

Bus 001 Device 123: ID 0fce:d0c6 Sony Ericsson Mobile Communications AB
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            2 Communications
  bDeviceSubClass         0
  bDeviceProtocol         0
  bMaxPacketSize0        64
  idVendor           0x0fce Sony Ericsson Mobile Communications AB
  idProduct          0xd0c6
  bcdDevice            0.00
  iManufacturer           1 Sony Ericsson
  iProduct                2 Sony Ericsson W760
  iSerial                 3 3592370251135100



# cat /etc/udev/rules.d/10-gammu.rules
KERNEL=="ttyACM*",  SYSFS{serial}=="3592370251135100",  SYMLINK+="sms1", GROUP="uucp", MODE="0660"


Now I am using huawei gsm modem in my project, but these devices have iserial 0, so that now I have the problem of not having a unique value that identifies a modem.

lsusb -d 12d1:1003 -v

Bus 002 Device 041: ID 12d1:1003 Huawei Technologies Co., Ltd. E220 HSDPA Modem / E270 HSDPA/HSUPA Modem
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0
  bDeviceProtocol         0
  bMaxPacketSize0        64
  idVendor           0x12d1 Huawei Technologies Co., Ltd.
  idProduct          0x1003 E220 HSDPA Modem / E270 HSDPA/HSUPA Modem
  bcdDevice            0.00
  iManufacturer           1 HUAWEI Technologies
  iProduct                2 HUAWEI Mobile
  iSerial                 0



I can create udev rules in function of the USB port used?





Offline s3704ssv

  • Newbie
  • *
  • Posts: 30
Re: Huawei USB Modem + UDEV rule
« Reply #11 on: June 02, 2010, 07:35:02 PM »
I'm also aware of that :(

these are the problems of huawei usb Modems :(..., no serial number :(..., and I can't find anything that can distinguish it uniquely :(

anyways..., since your using gammu..., you could the find the imei on a specific huawei and use it with udev? [wild dumb idea  :D]

Offline topcat2010

  • Newbie
  • *
  • Posts: 3
Re: Huawei USB Modem + UDEV rule
« Reply #12 on: June 03, 2010, 07:28:08 PM »
this wild dumb idea, is posible!. I am writting one external script, trigger for udev rules. this capture the IMEI from gsm modem, and retrieve port name ( SYMLINK+ ) from file mapping (portX, IMEI). this procedure permit get  have a uniqueid for each gsm modem. The first test have been sucesfull. I will post this procedure when it is completed.

Offline s3704ssv

  • Newbie
  • *
  • Posts: 30
Re: Huawei USB Modem + UDEV rule
« Reply #13 on: June 04, 2010, 09:04:37 AM »
this wild dumb idea, is posible!. I am writting one external script, trigger for udev rules. this capture the IMEI from gsm modem, and retrieve port name ( SYMLINK+ ) from file mapping (portX, IMEI). this procedure permit get  have a uniqueid for each gsm modem. The first test have been sucesfull. I will post this procedure when it is completed.

please share it! ^_^

Offline topcat2010

  • Newbie
  • *
  • Posts: 3
Re: Huawei USB Modem + UDEV rule
« Reply #14 on: June 04, 2010, 03:07:04 PM »
Release beta!!!
This procedure permit get the uniqueid for each modem gsm.

# cat /etc/udev/rules.d/10-gammu.rules
KERNEL=="ttyUSB*", ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="1003",  PROGRAM="/usr/local/sbin/port_manager.php %k", SYMLINK+="%c", GROUP="uucp", MODE="0660"

# cat /usr/local/sbin/port_manager.php
#!/usr/bin/php -q
<?php
if(isset($argv[1]))
{
$port = trim($argv[1]);
$file = "/etc/gammurc";
$config =  "[gammu]\nport = /dev/".$port."\nconnection = at\n";
file_put_contents($file, $config);
@exec("/usr/bin/gammu nothing --identify", $rs);

$r = "";
for($i=0;$i<count($rs);$i++)
{
 $r.=$rs[$i]."\r\n";
}

if (preg_match("/IMEI(.+) : (.+)/",$r,$s)) {
   $IMEI=trim(str_replace("\n","",$s[2]));
   $output = file_get_contents("/usr/local/sbin/table.txt");
   $output = explode("\n",$output);
   foreach ($output as $value){
   list($mapping, $imei) = preg_split('/,/',$value);
   //$device = "/dev/".$mapping;
   if ( $IMEI == $imei ) {
       echo $mapping;
       exit (0);
   }
}

}
echo $port;
}
?>

# cat /usr/local/sbin/table.txt
port1,355112022089381
port2,356368024112600


# ls -al port2
lrwxrwxrwx 1 root root 7 2010-06-04 11:57 port2 -> ttyUSB2

« Last Edit: June 04, 2010, 06:58:22 PM by topcat2010 »