linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: md@Linux.IT (Marco d'Itri)
To: linux-hotplug@vger.kernel.org
Subject: hotplug support for USB DSL modems
Date: Tue, 29 Jul 2008 01:42:26 +0000	[thread overview]
Message-ID: <20080729014226.GA29724@bongo.bofh.it> (raw)

[-- Attachment #1: Type: text/plain, Size: 643 bytes --]

This script automatically starts a network connection when an USB DSL
modem is plugged and initialized.

I do not think it's worth distributing it with udev, but I am posting it
in the hope that other distributions will finally provide decent support
for these devices.

SUBSYSTEM=="atm", RUN+="dsl-modem.agent"


# from the Debian hotplug.functions:
wait_for_file() {
  local file=$1
  local timeout=$2
  [ "$timeout" ] || timeout=120

  local count=$timeout
  while [ $count != 0 ]; do
    [ -e "$file" ] && return 0
    sleep 1
    count=$(($count - 1))
  done

  mesg "$file did not appear before the timeout!"
  exit 1
}

-- 
ciao,
Marco

[-- Attachment #2: dsl-modem.agent --]
[-- Type: text/plain, Size: 2274 bytes --]

#!/bin/sh -e 
#
# Copyright 2008 Marco d'Itri <md@Linux.IT>
#
# This script automatically starts networking when a DSL modem is connected
# and its ATM interface is ready.
#
#
# For PPPoE you can set PROTOCOL=2684bridged and then add something like
# this to /etc/network/interfaces:
#
# allow-hotplug nas0
# iface nas0 inet manual
#        pre-up          ip link set up $IFACE
#        up              pppd persist call dsl-provider
#
#
# Support for CLIP (Classical IP over ATM, RFC 1577) may be incomplete.
#

# defaults
[ "$IP_INTERFACE" ] || IP_INTERFACE='nas0'
[ "$VP" ] || VP='8'
[ "$VC" ] || VC='35'

if [ -e /etc/default/dsl-modem.agent ]; then
  . /etc/default/dsl-modem.agent
fi

# just exit unless a protocol is configured
[ "$PROTOCOL" ] || exit 0

##############################################################################
wait_and_run_pppd() {
  # this guarantees that everything pppd needs to work is ready
  wait_for_file /dev/log

  exec pppd persist call ${PPP_PEER:-dsl-provider}
}

wait_and_run_br2684ctl() {
  wait_for_file /dev/log

  exec br2684ctl $BR2684_ARGS -b -c ${IP_INTERFACE#nas} \
    -a ${ATM_INTERFACE}.${VP}.${VC}
}

wait_and_run_atmarp() {
  wait_for_file /var/run/atmarpd.table

  # create the IP interface
  atmarp -c ${IP_INTERFACE:-atm0}
  # setup the VC
#  atmarp -s 192.0.2.254 ${ATM_INTERFACE}.${VP}.${VC}
  exec ifup ${IP_INTERFACE:-atm0} # XXX
}

##############################################################################
ATM_DRIVER=${NAME%%[0-9]*}
ATM_INTERFACE=${NAME##$ATM_DRIVER}

# is this a DSL modem?
case "$ATM_DRIVER" in
cxacru|speedtch|ueagle-atm|xusbatm|UNICORN) ;;
*) exit 0 ;;
esac

cd /lib/udev/
. ./hotplug.functions

##############################################################################
case "$ACTION" in
add)
  case "$PROTOCOL" in
  pppoa)	wait_and_run_pppd & ;;
  2684bridged)	wait_and_run_br2684ctl & ;;
  clip)		wait_and_run_atmarp & ;;
  esac
  ;;

remove)
  case "$PROTOCOL" in
  pppoa)
    # pppd will terminate automatically
    ;;
  2684bridged)
    PIDFILE="/var/run/$IP_INTERFACE.pid"
    if [ -e $PIDFILE ]; then
      kill $(cat $PIDFILE)
      rm -f $PIDFILE
    fi
    ;;
  clip)
    ifdown ${IP_INTERFACE:-atm0} # XXX
#    atmarp -d 192.0.2.254
    ;;
  esac
  ;;
esac

exit 0


                 reply	other threads:[~2008-07-29  1:42 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080729014226.GA29724@bongo.bofh.it \
    --to=md@linux.it \
    --cc=linux-hotplug@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).