OpenWrt Forum Archive

Topic: 3g connection doesn't start at boot

The content of this topic has been archived between 23 Apr 2018 and 1 May 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

I have a DIR-320 (brcm47xx 2.6 kernel) and I have setup a 3g connection as a wan interface. It works fine but it doesn't autostart in reboot. I dig into initialization scripts of openwrt and it seems that when booting, only interfaces that exist in /proc/net/dev are started. Of course a 3g connection based on a USB stick is not there and it is never started in boot. It would have started if /etc/init.d/network start was issued (where an ifup -a command exists) but it seems on boot, /etc/rc.d/S40network executes the boot part of the network script and not the start part.

Which is the correct way to fix this? I have now added an "ifup wan3g" in rc.local, but I think there should be a way for openwrt to autostart the 3g interface by its own.

Try adding

config interface wan3g
        option auto 1

The suggestion didn't work.
I quote the /etc/init.d/network script

root@OpenWrt:~# cat /etc/init.d/network 
#!/bin/sh /etc/rc.common
# Copyright (C) 2006 OpenWrt.org

START=40
STOP=90

boot() {
    setup_switch() { return 0; }

    include /lib/network
    setup_switch
    grep -qs config /etc/config/wireless && {
        /sbin/wifi up
    } || {
        rm -f /etc/config/wireless
        /sbin/wifi detect > /etc/config/wireless
    }
}

start() {
    setup_switch() { return 0; }
    
    include /lib/network
    setup_switch
    ifup -a
    /sbin/wifi up
}

stop() {
    ifdown -a
}

restart() {
    start
}

At system startup, the boot() function is run and not start(). boot() only loads wifi. Other interfaces are loaded from /etc/init.d/boot.

        # the coldplugging of network interfaces needs to happen later, so we do it manually here
    for iface in $(awk -F: '/:/ {print $1}' /proc/net/dev); do
        /usr/bin/env -i ACTION=add INTERFACE="$iface" /sbin/hotplug-call net
    done

This section loads only devices in /proc/net/dev

So, the script setup that it is used never loads 3g usb connections.

We could either create a 3g-network startup script that searches configuration for 3g wan interfaces and starts them, or extend network startup script to also load 3g connections.

As a workaround, if I remove boot() code from /etc/init.d/network, then start() is used on reboot and that also loads the 3g interface (because start calls ifup -a)

I made a startup script for 3g connections.

root@OpenWrt:~# cat /etc/init.d/network3g 
#!/bin/sh /etc/rc.common

START=41
STOP=91

start()
{
    include /lib/network
    scan_interfaces
    for ifc in $interfaces; do
        config_get ifproto "$ifc" proto
        config_get ifauto "$ifc" auto
        [ "$ifproto" = "3g" ] && {
        case "$ifauto" in
                1|on|enabled) ifup $ifc;;
        esac
        }
    done 
}

stop()
{
    include /lib/network
    scan_interfaces
    for ifc in $interfaces; do
        config_get ifproto "$ifc" proto
        [ "$ifproto" = "3g" ] && {
            ifdown $ifc 
        }
    done 
}

It autostarts only connections with proto "3g" and with auto "1"

Many thanks, with your script now all is ok wink

This bug still exists sad

I confirm, build r26795 !
Only the script save us smile

(Last edited by Crazy on 1 May 2011, 18:09)

There is already a 3G hotplug script in the comgt package that is supposed to automatically start pre-configured 3G interfaces on hotplug (and coldplug):

package/comgt/files/3g.usb -> /etc/hotplug.d/usb/30-3g

However, there are a couple of issues with it that need to be resolved.

First, the hotplug script needs to be executed when the actual tty (serial) device is added, not the underlying USB device.  For modems that use the serial drivers (e.g. option), the 3g-hotplug gets executed before the actual tty device is created (e.g. ttyUSB0)... so it fails to start-up the interface.  I fixed this in my build by moving the 3g-hotplug script (30-3g) from /etc/hotplug.d/usb to /etc/hotplug.d/tty (and modified the hotplug2 rules to handle the tty subsystem).  This works for all 3G modems (not just cdc-acm and hso devices)... because all 3G modems will have a subsystem of "tty" when added.

Secondly, I modified the 30-3g script to loop over all the tty devices in /dev (not /sys/$DEVPATH/ttyUSB*, etc).

I think this is a better solution than adding a new init.d script... plus it is already implemented (just needs to be fixed).

Regards,
Layne

LinkZ, the tty solution is interesting, I will consider it for possible fixes of the 3g problem - do you have any patches to look at?

I came up with something different which also seems to work well, though at the expense of possible duplicate events: http://luci.subsignal.org/~jow/usb-coldplug.patch
What I do not agree with is to fix this issue with an init script as some dongles need modeswitch which then again relies on hotplug etc. and putting all that into the init system would duplicate the whole hotplug code essentially.

jow - I will post a working patch tonight.

Thank you, I look forward to it.

jow wrote:

LinkZ, the tty solution is interesting, I will consider it for possible fixes of the 3g problem - do you have any patches to look at?

Patches attached to ticket:
https://dev.openwrt.org/ticket/9211

Regards,
Layne

patches attached to ticket 9211 solves autostart problem with kernel 2.6... However I have a dir-320 with backfire 10.03.1-rc6 wich has 2.4 kernel. With 2.4 kernel the usb modem is recognized as /dev/usb/tts/(0,1,2); so the hotplug script doesn't work and I must call ifup wan after each boot. How can I solve the issue?

Regards

I confirm, this bug is still present...
I'm using r32510 on TP-LINK 1043ND sad

So we add the sleep, close the ticket and in 4 months it gets reopened because someone managed to dig out a dongle that takes two seconds wink
Fixed sleeps are rarely a good solution.

You're right, i have tested now a e353 and doesn't work for the same problem.
So sleep 1 isn't the solution...

(Last edited by Crazy on 27 Jun 2012, 20:23)

usb_modeswitch config files have an option do to this:

WaitBefore=2

Since configs are card-specific, the delays are also card-specific. Problem solved!

Unfortunately already tried but seems that the option is ignored on boot sad

Judging from the logs provided in the ticket, the whole hotplug handling for the usb device is not triggered (otherwise there would be at least one message emitted by log()) - so I think that this is a cold vs. warm reset issue.
Can you play a bit with the usbreset utility?

Sure!
root@OpenWrt:~# usbreset /dev/usb1
Resetting USB device /dev/usb1
Error in ioctl: Is a directory
root@OpenWrt:~#

And after in the log...
[  116.120000] usb 1-1: USB disconnect, device number 2
[  116.300000] hub 1-0:1.0: unable to enumerate USB device on port 1
[  120.230000] usb 1-1: new high-speed USB device number 4 using ehci-platform
[  120.800000] usb 1-1: USB disconnect, device number 4
[  124.800000] usb 1-1: new high-speed USB device number 5 using ehci-platform
[  124.950000] option 1-1:1.0: GSM modem (1-port) converter detected
[  124.960000] usb 1-1: GSM modem (1-port) converter now attached to ttyUSB0
[  124.960000] option 1-1:1.1: GSM modem (1-port) converter detected
[  124.970000] usb 1-1: GSM modem (1-port) converter now attached to ttyUSB1
[  124.980000] option 1-1:1.2: GSM modem (1-port) converter detected
[  124.990000] usb 1-1: GSM modem (1-port) converter now attached to ttyUSB2


But usbreset can generate problems with extroot?

(Last edited by Crazy on 28 Jun 2012, 14:59)

So if you put for example "usbreset /dev/usb1" in /etc/rc.local, is the 3g reliably started on every boot? After cold boots and soft resets?

I put "usbreset /dev/usb1" in /etc/rc.local using luci and... incredible... is working!

http://i49.tinypic.com/2yyz70m.jpg

Log:

BusyBox v1.19.4 (2012-06-28 09:18:23 CEST) built-in shell (ash)
Enter 'help' for a list of built-in commands.

  _______                     ________        __
 |       |.-----.-----.-----.|  |  |  |.----.|  |_
 |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
 |_______||   __|_____|__|__||________||__|  |____|
          |__| W I R E L E S S   F R E E D O M
 -----------------------------------------------------
 ATTITUDE ADJUSTMENT (Bleeding Edge, r32517)
 -----------------------------------------------------
  * 1/4 oz Vodka      Pour all ingredients into mixing
  * 1/4 oz Gin        tin with ice, strain into glass.
  * 1/4 oz Amaretto
  * 1/4 oz Triple sec
  * 1/4 oz Peach schnapps
  * 1/4 oz Sour mix
  * 1 splash Cranberry juice
 -----------------------------------------------------
root@OpenWrt:~# dmesg
[    0.000000] Linux version 3.3.8 (massy@debian) (gcc version 4.6.3 20120201 (prerelease) (Linaro GCC 4.6-2012.02) ) #1 Thu Jun 28 09:48:37 CEST 2012
[    0.000000] MyLoader: sysp=f0f0f0f0, boardp=f0f0f0f0, parts=f0f0f0f0
[    0.000000] bootconsole [early0] enabled
[    0.000000] CPU revision is: 00019374 (MIPS 24Kc)
[    0.000000] SoC: Atheros AR7241 rev 1
[    0.000000] Clocks: CPU:400.000MHz, DDR:400.000MHz, AHB:200.000MHz, Ref:5.000MHz
[    0.000000] Determined physical RAM map:
[    0.000000]  memory: 02000000 @ 00000000 (usable)
[    0.000000] Initrd not found or empty - disabling initrd
[    0.000000] Zone PFN ranges:
[    0.000000]   Normal   0x00000000 -> 0x00002000
[    0.000000] Movable zone start PFN for each node
[    0.000000] Early memory PFN ranges
[    0.000000]     0: 0x00000000 -> 0x00002000
[    0.000000] On node 0 totalpages: 8192
[    0.000000] free_area_init_node: node 0, pgdat 802cd590, node_mem_map 81000000
[    0.000000]   Normal zone: 64 pages used for memmap
[    0.000000]   Normal zone: 0 pages reserved
[    0.000000]   Normal zone: 8128 pages, LIFO batch:0
[    0.000000] pcpu-alloc: s0 r0 d32768 u32768 alloc=1*32768
[    0.000000] pcpu-alloc: [0] 0
[    0.000000] Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 8128
[    0.000000] Kernel command line:  board=TL-MR3420 console=ttyS0,115200 rootfstype=squashfs,jffs2 noinitrd
[    0.000000] PID hash table entries: 128 (order: -3, 512 bytes)
[    0.000000] Dentry cache hash table entries: 4096 (order: 2, 16384 bytes)
[    0.000000] Inode-cache hash table entries: 2048 (order: 1, 8192 bytes)
[    0.000000] Primary instruction cache 64kB, VIPT, 4-way, linesize 32 bytes.
[    0.000000] Primary data cache 32kB, 4-way, VIPT, cache aliases, linesize 32 bytes
[    0.000000] Writing ErrCtl register=00000000
[    0.000000] Readback ErrCtl register=00000000
[    0.000000] Memory: 29288k/32768k available (2090k kernel code, 3480k reserved, 396k data, 200k init, 0k highmem)
[    0.000000] SLUB: Genslabs=9, HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[    0.000000] NR_IRQS:48
[    0.000000] Calibrating delay loop... 265.42 BogoMIPS (lpj=1327104)
[    0.080000] pid_max: default: 32768 minimum: 301
[    0.080000] Mount-cache hash table entries: 512
[    0.090000] NET: Registered protocol family 16
[    0.090000] gpiochip_add: registered GPIOs 0 to 17 on device: ath79
[    0.100000] MIPS: machine is TP-LINK TL-MR3420
[    0.500000] registering PCI controller with io_map_base unset
[    0.540000] bio: create slab <bio-0> at 0
[    0.550000] PCI host bridge to bus 0000:00
[    0.550000] pci_bus 0000:00: root bus resource [mem 0x10000000-0x17ffffff]
[    0.560000] pci_bus 0000:00: root bus resource [io  0x0000]
[    0.560000] pci 0000:00:00.0: [168c:002e] type 0 class 0x000280
[    0.560000] pci 0000:00:00.0: fixup device configuration
[    0.570000] pci 0000:00:00.0: reg 10: [mem 0x10000000-0x1000ffff 64bit]
[    0.570000] pci 0000:00:00.0: supports D1
[    0.570000] pci 0000:00:00.0: PME# supported from D0 D1 D3hot
[    0.570000] pci 0000:00:00.0: BAR 0: assigned [mem 0x10000000-0x1000ffff 64bit]
[    0.570000] pci 0000:00:00.0: using irq 40 for pin 1
[    0.580000] Switching to clocksource MIPS
[    0.580000] NET: Registered protocol family 2
[    0.590000] IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.590000] TCP established hash table entries: 1024 (order: 1, 8192 bytes)
[    0.600000] TCP bind hash table entries: 1024 (order: 0, 4096 bytes)
[    0.600000] TCP: Hash tables configured (established 1024 bind 1024)
[    0.610000] TCP reno registered
[    0.610000] UDP hash table entries: 256 (order: 0, 4096 bytes)
[    0.620000] UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
[    0.630000] NET: Registered protocol family 1
[    0.630000] PCI: CLS 0 bytes, default 32
[    0.650000] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[    0.650000] JFFS2 version 2.2 (NAND) (SUMMARY) (LZMA) (RTIME) (CMODE_PRIORITY) (c) 2001-2006 Red Hat, Inc.
[    0.670000] msgmni has been set to 57
[    0.670000] io scheduler noop registered
[    0.670000] io scheduler deadline registered (default)
[    0.680000] Serial: 8250/16550 driver, 1 ports, IRQ sharing disabled
[    0.710000] serial8250.0: ttyS0 at MMIO 0x18020000 (irq = 11) is a 16550A
[    0.710000] console [ttyS0] enabled, bootconsole disabled
[    0.730000] m25p80 spi0.0: found s25sl032a, expected m25p80
[    0.730000] m25p80 spi0.0: s25sl032a (4096 Kbytes)
[    0.740000] 5 tp-link partitions found on MTD device spi0.0
[    0.740000] Creating 5 MTD partitions on "spi0.0":
[    0.750000] 0x000000000000-0x000000020000 : "u-boot"
[    0.760000] 0x000000020000-0x000000100200 : "kernel"
[    0.760000] mtd: partition "kernel" must either start or end on erase block boundary or be smaller than an erase block -- forcing read-only
[    0.780000] 0x000000100200-0x0000003f0000 : "rootfs"
[    0.780000] mtd: partition "rootfs" must either start or end on erase block boundary or be smaller than an erase block -- forcing read-only
[    0.790000] mtd: partition "rootfs" set to be root filesystem
[    0.800000] mtd: partition "rootfs_data" created automatically, ofs=310000, len=E0000
[    0.810000] 0x000000310000-0x0000003f0000 : "rootfs_data"
[    0.820000] 0x0000003f0000-0x000000400000 : "art"
[    0.820000] 0x000000020000-0x0000003f0000 : "firmware"
[    1.070000] ag71xx_mdio: probed
[    1.070000] eth0: Atheros AG71xx at 0xba000000, irq 5
[    1.670000] eth0: Found an AR7240/AR9330 built-in switch
[    2.900000] eth1: Atheros AG71xx at 0xb9000000, irq 4
[    3.510000] ag71xx ag71xx.0: eth1: connected to PHY at ag71xx-mdio.1:04 [uid=004dd041, driver=Generic PHY]
[    3.520000] TCP cubic registered
[    3.520000] NET: Registered protocol family 17
[    3.520000] 8021q: 802.1Q VLAN Support v1.8
[    3.540000] VFS: Mounted root (squashfs filesystem) readonly on device 31:2.
[    3.540000] Freeing unused kernel memory: 200k freed
[    6.950000] Registered led device: tp-link:green:system
[    6.950000] Registered led device: tp-link:green:qss
[    6.950000] Registered led device: tp-link:green:3g
[   10.250000] JFFS2 notice: (415) jffs2_build_xattr_subsystem: complete building xattr subsystem, 1 of xdatum (0 unchecked, 0 orphan) and 13 of xref (0 dead, 2 orphan) found.
[   12.480000] Compat-wireless backport release: compat-wireless-2012-06-14
[   12.490000] Backport based on wireless-testing.git master-2012-06-14
[   12.500000] compat.git: wireless-testing.git
[   12.530000] cfg80211: Calling CRDA to update world regulatory domain
[   12.540000] cfg80211: World regulatory domain updated:
[   12.540000] cfg80211:   (start_freq - end_freq @ bandwidth), (max_antenna_gain, max_eirp)
[   12.550000] cfg80211:   (2402000 KHz - 2472000 KHz @ 40000 KHz), (300 mBi, 2000 mBm)
[   12.560000] cfg80211:   (2457000 KHz - 2482000 KHz @ 20000 KHz), (300 mBi, 2000 mBm)
[   12.570000] cfg80211:   (2474000 KHz - 2494000 KHz @ 20000 KHz), (300 mBi, 2000 mBm)
[   12.570000] cfg80211:   (5170000 KHz - 5250000 KHz @ 40000 KHz), (300 mBi, 2000 mBm)
[   12.580000] cfg80211:   (5735000 KHz - 5835000 KHz @ 40000 KHz), (300 mBi, 2000 mBm)
[   13.030000] usbcore: registered new interface driver usbfs
[   13.040000] usbcore: registered new interface driver hub
[   13.040000] usbcore: registered new device driver usb
[   13.680000] PCI: Enabling device 0000:00:00.0 (0000 -> 0002)
[   13.690000] ath: EEPROM regdomain: 0x0
[   13.690000] ath: EEPROM indicates default country code should be used
[   13.690000] ath: doing EEPROM country->regdmn map search
[   13.690000] ath: country maps to regdmn code: 0x3a
[   13.690000] ath: Country alpha2 being used: US
[   13.690000] ath: Regpair used: 0x3a
[   13.700000] ieee80211 phy0: Selected rate control algorithm 'minstrel_ht'
[   13.700000] Registered led device: ath9k-phy0
[   13.700000] ieee80211 phy0: Atheros AR9287 Rev:2 mem=0xb0000000, irq=40
[   13.700000] cfg80211: Calling CRDA for country: US
[   13.710000] cfg80211: Regulatory domain changed to country: US
[   13.720000] cfg80211:   (start_freq - end_freq @ bandwidth), (max_antenna_gain, max_eirp)
[   13.720000] cfg80211:   (2402000 KHz - 2472000 KHz @ 40000 KHz), (300 mBi, 2700 mBm)
[   13.730000] cfg80211:   (5170000 KHz - 5250000 KHz @ 40000 KHz), (300 mBi, 1700 mBm)
[   13.740000] cfg80211:   (5250000 KHz - 5330000 KHz @ 40000 KHz), (300 mBi, 2000 mBm)
[   13.750000] cfg80211:   (5490000 KHz - 5600000 KHz @ 40000 KHz), (300 mBi, 2000 mBm)
[   13.760000] cfg80211:   (5650000 KHz - 5710000 KHz @ 40000 KHz), (300 mBi, 2000 mBm)
[   13.760000] cfg80211:   (5735000 KHz - 5835000 KHz @ 40000 KHz), (300 mBi, 3000 mBm)
[   13.890000] PPP generic driver version 2.4.2
[   14.260000] ip_tables: (C) 2000-2006 Netfilter Core Team
[   14.450000] NET: Registered protocol family 24
[   14.570000] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
[   14.580000] ehci-platform ehci-platform: Generic Platform EHCI Controller
[   14.580000] ehci-platform ehci-platform: new USB bus registered, assigned bus number 1
[   14.620000] ehci-platform ehci-platform: irq 3, io mem 0x1b000000
[   14.640000] ehci-platform ehci-platform: USB 2.0 started, EHCI 1.00
[   14.640000] hub 1-0:1.0: USB hub found
[   14.650000] hub 1-0:1.0: 1 port detected
[   14.670000] nf_conntrack version 0.5.0 (460 buckets, 1840 max)
[   15.090000] usb 1-1: new high-speed USB device number 2 using ehci-platform
[   15.210000] xt_time: kernel timezone is -0000
[   15.590000] usbcore: registered new interface driver cdc_acm
[   15.600000] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters
[   15.720000] usbcore: registered new interface driver usbserial
[   15.730000] USB Serial support registered for generic
[   15.730000] usbcore: registered new interface driver usbserial_generic
[   15.740000] usbserial: USB Serial Driver core
[   15.840000] USB Serial support registered for GSM modem (1-port)
[   15.840000] usbcore: registered new interface driver option
[   15.850000] option: v0.7.2:USB Driver for GSM modems
[   21.020000] device eth0 entered promiscuous mode
[   33.760000] usb 1-1: USB disconnect, device number 2
[   33.990000] hub 1-0:1.0: unable to enumerate USB device on port 1
[   37.850000] usb 1-1: new high-speed USB device number 4 using ehci-platform
[   38.260000] usb 1-1: USB disconnect, device number 4
[   42.280000] usb 1-1: new high-speed USB device number 5 using ehci-platform
[   42.430000] option 1-1:1.0: GSM modem (1-port) converter detected
[   42.440000] usb 1-1: GSM modem (1-port) converter now attached to ttyUSB0
[   42.450000] option 1-1:1.1: GSM modem (1-port) converter detected
[   42.450000] usb 1-1: GSM modem (1-port) converter now attached to ttyUSB1
[   42.460000] option 1-1:1.2: GSM modem (1-port) converter detected
[   42.470000] usb 1-1: GSM modem (1-port) converter now attached to ttyUSB2
[   70.390000] eth0: link up (1000Mbps/Full duplex)
[   70.390000] br-lan: port 1(eth0) entered forwarding state
[   70.400000] br-lan: port 1(eth0) entered forwarding state
[   72.400000] br-lan: port 1(eth0) entered forwarding state
root@OpenWrt:~#

If I unplug and plug 3G connection work again so it's perfect!

Tried with:
Huawei e353
Huawei e270
ZTE K4505-Z

But now there are problems with extroot on usb?

(Last edited by Crazy on 28 Jun 2012, 16:12)

Yes, but this extroot problem can be mitigated by putting the usbreset into preinit as well, before the extroot is set up.