1

I am using 10.04 Server.

I have a 3G wireless card, use the switch program which i get from the manufacturer, i can change the 3G card from USB storage mode to 3G modem mode, then following devices are created in /dev :ttyUSB0,ttyUSB1,ttyUSB2.

But I don't know which device to should choose to use 3G, so i have to run wvdialconfig to scan all the possible port and find the proper one. Is there a way to automatically detect the 3G port without using wvdialconfig to scan all the port every time?

fossfreedom
  • 174,526
HexForFun
  • 111

3 Answers3

1

If you connect with network manager, it will work out which one to use. (You can drive it from the command line with nmcli)

tumbleweed
  • 8,106
0

I use this script to get Data and Control ports for 3g usb dongle.

#!/bin/sh

. /usr/share/libubox/jshn.sh

for a in `ls /sys/bus/usb/devices`; do
    local vendor product
    [ -z "$usb" -a -f /sys/bus/usb/devices/$a/idVendor -a -f /sys/bus/usb/devices/$a/idProduct ] || continue
    vendor=$(cat /sys/bus/usb/devices/$a/idVendor)
    product=$(cat /sys/bus/usb/devices/$a/idProduct)
    echo Vendor $vendor, Product $product
    [ -f /lib/network/wwan/$vendor:$product ] && {
        usb=/lib/network/wwan/$vendor:$product
        devicename=$a
        echo usb: $usb devicename: $devicename
    }
done

[ -n "$usb" ] && {
    local old_cb control data

    json_set_namespace wwan old_cb
    json_init
    json_load "$(cat $usb)"
    echo "$(cat $usb)"

    json_select
    json_get_vars desc control data
    json_set_namespace $old_cb

    [ -n "$control" -a -n "$data" ] && {
        ttys=$(ls -d /sys/bus/usb/devices/$devicename/${devicename}*/tty* | sed "s/.*\///g" | tr "\n" " ")

        ctl_device=$(echo $ttys | cut -d" " -f $((control + 1)))
        [ -n "$ctl_device" ] && ctl_device=/dev/$ctl_device
        dat_device=$(echo $ttys | cut -d" " -f $((data + 1)))
        [ -n "$dat_device" ] && dat_device=/dev/$dat_device
        echo control_device: $ctl_device, data_device: $dat_device
    }
}

Sample outputs:

Connected ZTE MF667

Vendor 1a40, Product 0101 #this is usb hub
Vendor 19d2, Product 0016
usb: /lib/network/wwan/19d2:0016 devicename: 1-1.2
{
        "desc": "ONDA MF110/ZTE",
        "control": 1,
        "data": 2
}}
control_device: /dev/ttyUSB1, data_device: /dev/ttyUSB2

Connected Huawei E3131

Vendor 1a40, Product 0101 #this is usb hub
Vendor 12d1, Product 1506
usb: /lib/network/wwan/12d1:1506 devicename: 1-1.2
{
        "desc": "Huawei E367/E398",
        "control": 2,
        "data": 0
}}
control_device: /dev/ttyUSB2, data_device: /dev/ttyUSB0
0

Suppose your wvconf file is like this:

[Dialer Defaults]
Modem = /dev/ttyUSB1
Baud = 960800                      //Connection speed
Init = ATZ
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
ISDN = 0
Modem Type = USB Modem
Phone = #777                       // Dialling number
Username = jimstech                // username
Password = jimstech                // password
stupid mode = 1                    // setting as true

Your need to replace the line and test : Modem = /dev/ttyUSB1

again suppose your possible devices are : ttyUSB0 ttyUSB1 ttyUSB2 now we need to replace the line (/dev/ttyUSB1) with ttyUSB0 then run test using wvconf then USB2 then USB3.(I hope) To automate the process use this script

#!/bin/bash
#your commands to load device file
array=(ttyUSB0 ttyUSB1 ttyUSB2 ttyUSB3)
len=${#array[*]} #Number of elements of the array

i=0
while [ $i -lt $len ]; do
rep="Modem = /dev/"${array[$i]}
sed 's*Modem = /dev/tty[A-Z]\*[0-9]*'"$rep"' *'  /etc/wvdial.conf
wvdialconf #break with appropriate behavior
sleep 1
let i++
done
wvdial

I don't have wvdial installed so i don't know what will happen if wvdialconf accept the device. This script must need to run with root permission.

shantanu
  • 8,835