You are not logged in.

#1 2012-06-20 11:55:18

kevku
Member
From: Estonia
Registered: 2009-11-21
Posts: 73

Auto (re)connect mobile broadband with netcfg

so currently my setup is like this
using Huawei E173

/etc/network.d/interfaces/wwan0

PRE_UP="/etc/network.d/scripts/mobile-broadband-pre-up.sh"
POST_DOWN="/etc/network.d/scripts/mobile-broadband-post-down.sh"

/etc/network.d/scripts/mobile-broadband-pre-up.sh

#!/bin/bash
/etc/network.d/scripts/mobile-broadband-pre-up.pl > /dev/ttyUSB0 < /dev/ttyUSB0
ip link set dev wwan0 down
ip link set dev wwan0 address 00:01:02:03:04:05

/etc/network.d/scripts/mobile-broadband-pre-up.pl

#! /usr/bin/perl -w

use strict;

## This stuff you may want to modify.
sub getpin {
        # -- uncomment if you want a fixed pin -- #
        # return "1234";

        my $xuser = `/usr/bin/who | /usr/bin/awk '\$NF=="(:0)" { print \$1 }'`;
        $xuser =~ s/\s+$//s;

        if (!$xuser) {
                printf STDERR "Unable to obtain xuser for pin verification.";
                exit (1);
        }

        my $pin = `/bin/su - ${xuser} -c 'DISPLAY=:0 /usr/bin/Xdialog --title "3G Connect" --stdout --passwordbox "Your PIN is required:" 10 40' </dev/null`;
        $pin =~ s/\s+$//s;

        return $pin;
}

sub getapn {
        return "internet";
}

## From here on can probably remain as is.
$|=1;

sub issue {
        my $cmd;
        $cmd = $_[0];
        printf STDERR "Sending $cmd\r\n";
        print "$cmd\r\n";

        while (<>) {
                s/\s+$//s;
                if ($_ eq $cmd) {
                        last
                }
                printf STDERR "Discarding input: $_\r\n";
        }
}

sub request {
        while (<>) {
                s/\s+$//s;
                if ($_) {
                        printf STDERR "Received: $_\r\n";
                        return $_;
                }
        }
}

sub command {
        my $reply;
        my $response;
        issue($_[0]);
        my $ok = "^OK\$";
        if (defined($_[1])) {
                $ok = $_[1];
        }
        while (1) {
                $reply = request();
                if ($reply =~ $ok) {
                        if (!defined($response)) {
                                $response = $reply;
                        }
                        return $response;
                } elsif ($reply =~ "^\\+") {
                        $response = $reply;
                } else {
                        printf STDERR "Failing due to $reply\r\n";
                        exit(1);
                }
        }
}

printf STDERR "Initializing modem\r\n";

alarm(10);

command("ATZ");
command("AT^CURC=1");
#command("AT S7=45 S0=0 L1 V1 X4 &c1 E1 Q0");
my $pinreq = command("AT+CPIN?");

if ($pinreq eq "+CPIN: SIM PIN") {
        alarm(0);
        printf STDERR "Attempting to obtain PIN.\r\n";

        my $pin = getpin("3G PIN");

        alarm(10);
        command("AT+CPIN=$pin");
}

my $apn = getapn("3G");
command("AT^NDISDUP=1,1,\"$apn\"");
exit(0);

/etc/network.d/scripts/mobile-broadband-post-down.sh

/etc/network.d/scripts/mobile-broadband-post-down.pl < /dev/ttyUSB0 > /dev/ttyUSB0
ip link set dev wwan0 down

/etc/network.d/scripts/mobile-broadband-post-down.pl

#! /usr/bin/perl -w

use strict;

## From here on can probably remain as is.
$|=1;

sub issue {
        my $cmd;
        $cmd = $_[0];
        printf STDERR "Sending $cmd\r\n";
        print "$cmd\r\n";

        while (<>) {
                s/\s+$//s;
                if ($_ eq $cmd) {
                        last
                }
                printf STDERR "Discarding input: $_\r\n";
        }
}

sub request {
        while (<>) {
                s/\s+$//s;
                if ($_) {
                        printf STDERR "Received: $_\r\n";
                        return $_;
                }
        }
}

sub command {
        my $reply;
        my $response;
        issue($_[0]);
        my $ok = "^OK\$";
        if (defined($_[1])) {
                $ok = $_[1];
        }
        while (1) {
                $reply = request();
                if ($reply =~ $ok) {
                        if (!defined($response)) {
                                $response = $reply;
                        }
                        return $response;
                } elsif ($reply =~ "^\\+") {
                        $response = $reply;
                } else {
                        printf STDERR "Failing due to $reply\r\n";
                        exit(1);
                }
        }
}

alarm(10);

command("AT^NDISDUP=1,0");
exit(0);

/etc/network.d/3G

CONNECTION='ethernet'
INTERFACE='wwan0'
IP='dhcp'

while this normally works fine it doesn't do reconnect
so looking for some ideas how to make it (re)connect when modem is reentered / link is dropped

Last edited by kevku (2012-06-20 11:56:13)

Offline

#2 2012-06-20 19:55:49

Strike0
Member
From: Germany
Registered: 2011-09-05
Posts: 1,429

Re: Auto (re)connect mobile broadband with netcfg

I have not tried it with netcfg for 3G, but seeing your scripts I wonder if using the "net-auto-wireless" daemon should work (or why not).

Offline

#3 2012-06-20 20:00:42

kevku
Member
From: Estonia
Registered: 2009-11-21
Posts: 73

Re: Auto (re)connect mobile broadband with netcfg

well the wwan0 interface is only present when modem is plugged in, ifplugd/net-auto doesnt like that
prob some custom udev rules can connect it at startup but not sure about reconnect.

Offline

#4 2012-06-20 20:05:04

Inxsible
Forum Fellow
From: Chicago
Registered: 2008-06-09
Posts: 9,183

Re: Auto (re)connect mobile broadband with netcfg

you could probably use the PRE_UP in the profiles to first check if the modem is connected & wwan0 is available and then start up wwan0 if it is connected and available.


Forum Rules

There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !

Offline

Board footer

Powered by FluxBB