From 4278a21ef06f73d3cab06c8ef96780a41f32f6b2 Mon Sep 17 00:00:00 2001 From: Daniel Roethlisberger Date: Fri, 2 Apr 2010 16:07:54 +0200 Subject: [PATCH] Add wwan connection type for USB CDC Ethernet based WWAN devices. Concrete device support is modular, currently only the Ericsson F3507g is supported. --- Makefile | 3 +- examples/wwan-f3507g | 8 ++++ src/connections/wwan | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/wwan/F3507g | 50 ++++++++++++++++++++++++ 4 files changed, 164 insertions(+), 1 deletions(-) create mode 100644 examples/wwan-f3507g create mode 100644 src/connections/wwan create mode 100644 src/wwan/F3507g diff --git a/Makefile b/Makefile index acb4062..c99c498 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ VERSION=2.5.4 VPATH = doc install: - install -d $(DESTDIR)/usr/lib/network/{connections,hooks} \ + install -d $(DESTDIR)/usr/lib/network/{connections,hooks,wwan} \ $(DESTDIR)/etc/network.d/{examples,hooks,interfaces} \ $(DESTDIR)/etc/rc.d \ $(DESTDIR)/var/run/network/{interfaces,profiles} \ @@ -16,6 +16,7 @@ install: # Libs install -m644 src/{network,wireless,8021x,globals} $(DESTDIR)/usr/lib/network install -m755 src/connections/* ${DESTDIR}/usr/lib/network/connections + install -m644 src/wwan/* ${DESTDIR}/usr/lib/network/wwan ln -s ethernet $(DESTDIR)/usr/lib/network/connections/ethernet-iproute # Hooks install -m755 src/hooks/* ${DESTDIR}/usr/lib/network/hooks/ diff --git a/examples/wwan-f3507g b/examples/wwan-f3507g new file mode 100644 index 0000000..aeba64d --- /dev/null +++ b/examples/wwan-f3507g @@ -0,0 +1,8 @@ +CONNECTION='wwan' +DESCRIPTION='An Ericsson F3507g 3G WWAN example' +INTERFACE='usb0' +HANDLER='F3507g' +CONTROL_DEVICE='/dev/ttyACM1' +RFKILL_DEVICE='/sys/devices/platform/thinkpad_acpi/wwan_enable' +APN='gprs' +PIN='1234' diff --git a/src/connections/wwan b/src/connections/wwan new file mode 100644 index 0000000..686becd --- /dev/null +++ b/src/connections/wwan @@ -0,0 +1,104 @@ +#! /bin/bash +. /usr/lib/network/network + +# This is for WWAN devices which use a CDC Ethernet interface. + +report_iproute() +{ + report_fail "$*" + bring_interface down "$INTERFACE" + exit 1 +} + +wwan_up() { + load_profile "$1" + . /usr/lib/network/wwan/$HANDLER + + if ! wwan_${HANDLER}_powerup; then + report_fail "$HANDLER powerup failed." + return 1 + fi + + if [[ ! -e "/sys/class/net/$INTERFACE" ]]; then + if ! echo "$INTERFACE" | fgrep -q ":"; then + report_iproute "Interface $INTERFACE does not exist" + fi + fi + + if ! wwan_${HANDLER}_unlock; then + wwan_${HANDLER}_powerdown + report_fail "$HANDLER unlock failed." + return 1 + fi + + if ! wwan_${HANDLER}_enable; then + wwan_${HANDLER}_powerdown + report_fail "$HANDLER enable failed." + return 1 + fi + + if ! wwan_${HANDLER}_connect; then + wwan_${HANDLER}_powerdown + report_fail "$HANDLER connect failed." + return 1 + fi + + report_debug wwan_iproute_up ifup + bring_interface up "$INTERFACE" + + if checkyesno "${DHCLIENT:-no}"; then + rm -r "/var/run/dhclient-${INTERFACE}.pid" >/dev/null 2>&1 + report_debug ethernet_up dhclient -q -e TIMEOUT="${DHCP_TIMEOUT:-10}" -pf "/var/run/dhclient-$INTERFACE.pid" "$INTERFACE" + if ! dhclient -q -e TIMEOUT="${DHCP_TIMEOUT:-10}" -pf "/var/run/dhclient-${INTERFACE}.pid" ${DHCLIENT_OPTIONS} "$INTERFACE"; then + report_fail "DHCP IP lease attempt failed." + return 1 + fi + else + # Clear remaining pid files. + rm -f "/var/run/dhcpcd-$INTERFACE".{pid,cache} >/dev/null 2>&1 + # Start dhcpcd + report_debug wwan_up dhcpcd -qL -t "${DHCP_TIMEOUT:-10}" $DHCP_OPTIONS "$INTERFACE" + dhcpcd -qL -t "${DHCP_TIMEOUT:-10}" $DHCP_OPTIONS "$INTERFACE" 2>&1 | report_debug "$(cat)" + if [[ "$PIPESTATUS" -ne 0 ]]; then + report_fail "DHCP IP lease attempt failed." + return 1 + fi + fi + + return 0 +} + +wwan_down() { + load_profile "$1" + . /usr/lib/network/wwan/$HANDLER + + if [[ -f "/var/run/dhcpcd-${INTERFACE}.pid" ]]; then + report_debug wwan_down dhcpcd -qx "$INTERFACE" + dhcpcd -qx "$INTERFACE" &>/dev/null + fi + + report_debug wwan_down if_down + bring_interface down "$INTERFACE" + + if ! wwan_${HANDLER}_disconnect; then + report_fail "$HANDLER disconnect failed." + fi + + if ! wwan_${HANDLER}_powerdown; then + report_fail "$HANDLER powerdown failed." + fi + + return 0 +} + +# Returns status of profile - is it still functional? +wwan_status() { + if ! ip link show dev "$INTERFACE" | fgrep -q "state UP"; then + return 1 + fi +} + +wwan_$1 "$2" +exit $? +# vim: set ts=4 et sw=4: + diff --git a/src/wwan/F3507g b/src/wwan/F3507g new file mode 100644 index 0000000..7608606 --- /dev/null +++ b/src/wwan/F3507g @@ -0,0 +1,50 @@ +# WWAN Handler for Ericsson F3507g + +# helper functions + +wwan_F3507g_chat () { + /usr/sbin/chat $CHAT_ARGS ABORT ERROR TIMEOUT 10 "$@" > "$CONTROL_DEVICE" < "$CONTROL_DEVICE" +} + +# exposed interface + +wwan_F3507g_powerup () { + if [ -e "$RFKILL_DEVICE" ]; then + echo 1 > "$RFKILL_DEVICE" || return 1 + while [ ! -c "$CONTROL_DEVICE" ]; do sleep 0.5; done + sleep 3 + fi + wwan_F3507g_chat '' AT OK +} + +wwan_F3507g_unlock () { + if [ -n "$PIN" ]; then + if wwan_F3507g_chat '' AT OK 'AT+CPIN?' 'READY' '\c' OK; then + return 0 + fi + wwan_F3507g_chat '' AT OK 'AT+CPIN?' 'SIM PIN' '\c' OK "AT+CPIN=\"$PIN\"" OK '\dAT+CPIN?' READY '\c' OK + fi +} + +wwan_F3507g_enable () { + wwan_F3507g_chat '' AT OK 'AT+CPIN?' READY '\c' OK 'AT+CFUN=1' '+PACSP0' +} + +wwan_F3507g_connect () { + wwan_F3507g_chat '' AT OK 'AT+CFUN?' '+CFUN: 1' '\c' OK "AT+CGDCONT=1,\"IP\",\"$APN\"" OK 'AT*ENAP=1,1' OK +} + +wwan_F3507g_disconnect () { + wwan_F3507g_chat '' AT OK 'AT*ENAP=0' OK +} + +wwan_F3507g_powerdown () { + wwan_F3507g_chat '' AT OK 'AT+CFUN=0' OK + if [ -e "$RFKILL_DEVICE" ]; then + echo 0 > "$RFKILL_DEVICE" + while [ -c "$CONTROL_DEVICE" ]; do sleep 0.5; done + fi +} + +# vim: set ts=4 et sw=4: + -- 1.7.0.3