From 754a4c1094338bec4b07abe06948ac51843b07ca Mon Sep 17 00:00:00 2001 From: Robbie Smith Date: Mon, 1 Apr 2013 18:26:03 +1100 Subject: Added ppp mobile by porting from netcfg. --- docs/examples/mobile | 37 ++++++++++++ src/lib/connections/ppp | 148 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 185 insertions(+) create mode 100644 docs/examples/mobile create mode 100644 src/lib/connections/ppp diff --git a/docs/examples/mobile b/docs/examples/mobile new file mode 100644 index 0000000..e78c595 --- /dev/null +++ b/docs/examples/mobile @@ -0,0 +1,37 @@ +Description='Example PPP mobile connection' +Interface=ppp0 +Connection=mobile +Peer=mobile-broadband +IdleTimeout=30 + +# Debug pppd / chat output (separately from netctl) +#PPPDebug=true + +# The device will usually be /dev/ttyUSB* (default: ttyUSB0 +Device=ttyUSB0 + +# Use default route provided by the peer (default: true) +#DefaultRoute=true +# Use DNS provided by the peer (default: true) +#UsePeerDNS=true + +# Always keep a connection established +ConnectionMode='persist' +# Establish connection on demand +#ConnectionMode='demand' +#IdleTimeout=300 + +# The user and password are not always required +#User='example@yourprovider.com' +#Password='very secret' + +# The access point name you are connecting to +AccessPointName=apn + +# If your device has a PIN code, set it here. Defaults to None +#Pin=None + +# Mode can be one of 3Gpref, 3Gonly, GPRSpref, GPRSonly, None +# These only work for Huawei USB modems; all other devices should use None +Mode=3Gpref + diff --git a/src/lib/connections/ppp b/src/lib/connections/ppp new file mode 100644 index 0000000..54bedba --- /dev/null +++ b/src/lib/connections/ppp @@ -0,0 +1,148 @@ +# Contributed by Robbie Smith +# Based on Thomas Bächler’s pppoe script +# Also see for more information. + +: ${PPPD:=pppd} + +_quotestring() { + echo "\"${1/\"/\\\"}\"" +} + +mobile_up() { + local cfg + local chat + + mkdir -p "$STATE_DIR/mobile.${Interface}.${Profile}/" + chmod 700 "$STATE_DIR/mobile.${Interface}.${Profile}/" + cfg="$STATE_DIR/mobile.${Interface}.${Profile}/options" + chat="$STATE_DIR/mobile.${Interface}.${Profile}/modem.chat" + : > "${cfg}" + chmod 600 "${cfg}" + + echo "linkname $(_quotestring "${Profile}")" >> "${cfg}" + + # Set device + if [ -n "${Device}" ]; then + echo "${Device}" >> "${cfg}" + else + echo "ttyUSB0" >> "${cfg}" + fi + + echo "921600" >> "${cfg}" + echo "lock" >> "${cfg}" + echo "crtscts" >> "${cfg}" + echo "modem" >> "${cfg}" + echo "passive" >> "${cfg}" + echo "novj" >> "${cfg}" + echo "holdoff 10" >> "${cfg}" + echo "maxfail 5" >> "${cfg}" + + # Debug pppd output separately from netcfg + if is_yes "${PPPDebug:-yes}"; then + echo "debug" >> "${cfg}" + fi + + # Sets up route + if is_yes "${DefaultRoute:-yes}"; then + echo "defaultroute" >> "${cfg}" + else + echo "nodefaultroute" >> "${cfg}" + fi + if is_yes "${UsePeerDNS:-yes}"; then + echo "usepeerdns" >> "${cfg}" + fi + + # Writes username and password + echo "noauth" >> "${cfg}" + echo "hide-password" >> ${cfg} + [[ -n ${User} ]] && echo "user $(_quotestring "${User}")" >> "${cfg}" + [[ -n ${Password} ]] && echo "password $(_quotestring "${Password}")" >> "${cfg}" + + # Now that we’ve got the ppp configuration set up, write the chat script + echo "ECHO ON" >> "${chat}" + echo "ABORT 'BUSY'" >> "${chat}" + echo "ABORT 'NO CARRIER'" >> "${chat}" + echo "ABORT 'VOICE'" >> "${chat}" + echo "ABORT 'NO DIALTONE'" >> "${chat}" + echo "ABORT 'NO DIAL TONE'" >> "${chat}" + echo "ABORT 'NO ANSWER'" >> "${chat}" + echo "ABORT 'DELAYED'" >> "${chat}" + echo "ABORT '\nRINGING\r\n\r\nRINGING\r'" >> "${chat}" + echo "REPORT CONNECT" >> "${chat}" + echo "TIMEOUT 6" >> "${chat}" + echo "'' 'ATQ0'" >> "${chat}" + echo "'OK-AT-OK' 'ATZ'" >> "${chat}" + echo "TIMEOUT 3" >> "${chat}" + + #echo "'OK' @/etc/ppp/chatscripts/pin" >> "${chat}" + if [ -n "${Pin}" ]; then + echo "'OK' 'AT+CPIN=${Pin}'" >> "${chat}" + else + echo "'OK' 'AT'" >> "${chat}" + fi + + echo "'OK\d-AT-OK' 'ATI'" >> "${chat}" + echo "'OK' 'ATZ'" >> "${chat}" + echo "'OK' 'ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0'" >> "${chat}" + + # Mode can be one of 3Gpref, 3Gonly, GPRSpref, GPRSonly, None + # Only works for Huawei modems + #echo "'OK' @/etc/ppp/chatscripts/mode" >> "${chat}" + case "${Mode}" in + 3Gonly) + echo "'OK' 'AT\^SYSCFG=14,2,3fffffff,0,1'" >> "${chat}" + ;; + 3Gpref) + echo "'OK' 'AT\^SYSCFG=2,2,3fffffff,0,1'" >> "${chat}" + ;; + GPRSonly) + echo "'OK' 'AT\^SYSCFG=13,1,3fffffff,0,0'" >> "${chat}" + ;; + GPRSpref) + echo "'OK' 'AT\^SYSCFG=2,1,3fffffff,0,0'" >> "${chat}" + ;; + *) + echo "'OK' 'AT'" >> "${chat}" + ;; + esac + + # Set up Access Point Name + echo "'OK-AT-OK' AT+CGDCONT=1,\"IP\",\"${AccessPointName}\"" >> "${chat}" + + echo "'OK' 'ATDT*99#'" >> "${chat}" + echo "TIMEOUT 30" >> "${chat}" + echo "CONNECT ''" >> "${chat}" + + # Add the chat script line to the configuration + echo "connect \"/usr/sbin/chat -v -t15 -f ${chat}\"" >> "${cfg}" + + ip link set dev "${Interface}" up + #$PPPD call "$Peer" updetach child-timeout "$PPPTimeout" linkname "$Peer" + $PPPD file "${cfg}" + + if [[ $? -ne 0 ]]; then + rmdir "$STATE_DIR/mobile.${Interface}.${Profile}/" + report_error "Couldn't make pppd connection." + return 1 + fi +} + +mobile_down() { + local cfg + local chat + cfg="$STATE_DIR/mobile.${Interface}.${Profile}/options" + chat="$STATE_DIR/mobile.${Interface}.${Profile}/modem.chat" + PIDFILE="/var/run/mobile-${Profile}.pid" + + if [[ -e $PIDFILE ]]; then + read PID < "$PIDFILE" + [[ "$PID" ]] && kill "$PID" + fi + + rm "${cfg}" + rm "${chat}" + rmdir "$STATE_DIR/mobile.${Interface}.${Profile}/" +} + + +# vim: ft=sh ts=4 et sw=4: -- cgit v1.2.3-24-g4f1b From 5446a009aa33f53d58ee2dfb099ea1edcc877036 Mon Sep 17 00:00:00 2001 From: Jouke Witteveen Date: Fri, 29 Mar 2013 12:05:01 +0100 Subject: Simplify wpa network block creation It had grown a little diffuse. --- src/lib/8021x | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/src/lib/8021x b/src/lib/8021x index 7a841a4..65ef8f9 100644 --- a/src/lib/8021x +++ b/src/lib/8021x @@ -195,23 +195,6 @@ wpa_make_config_file() { ## Generate a network block for wpa_supplicant # $Security: type of wireless security wpa_make_config_block() { - case $Security in - none|wep|wpa) - echo "ssid=$(wpa_quote "$ESSID")" - [[ $AP ]] && echo "bssid=${AP,,}" - is_yes "${AdHoc:-no}" && echo "mode=1" - ;; - wpa-configsection) - printf "%s\n" "${WPAConfigSection[@]}" - return - ;; - *) - report_error "Unsupported security setting: '$Security'" - return 1 - ;; - esac - - # Key management case $Security in none) echo "key_mgmt=NONE" @@ -229,12 +212,20 @@ wpa_make_config_block() { echo "psk=$(wpa_quote "$Key")" fi ;; + wpa-configsection) + printf "%s\n" "${WPAConfigSection[@]}" + return + ;; + *) + report_error "Unsupported security setting: '$Security'" + return 1 + ;; esac - # Hidden SSID + echo "ssid=$(wpa_quote "$ESSID")" + [[ $AP ]] && echo "bssid=${AP,,}" is_yes "${Hidden:-no}" && echo "scan_ssid=1" - - # Priority group for the network + is_yes "${AdHoc:-no}" && echo "mode=1" [[ $Priority ]] && echo "priority=$Priority" } -- cgit v1.2.3-24-g4f1b From 1bb83f8bd73ebf86908685850c727d6786922cd4 Mon Sep 17 00:00:00 2001 From: Jouke Witteveen Date: Fri, 29 Mar 2013 12:06:49 +0100 Subject: Documentation update Rebuild all the manpages because version information may have changed. Add a few words on options that are ignored in some cases. --- Makefile | 2 +- docs/netctl.1.txt | 2 +- docs/netctl.profile.5.txt | 71 +++++++++++++++++++++++++---------------------- 3 files changed, 40 insertions(+), 35 deletions(-) diff --git a/Makefile b/Makefile index f822cd9..b1bc626 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,7 @@ install-docs: docs install -m644 docs/*.7 $(DESTDIR)/usr/share/man/man7/ docs: - $(MAKE) -C $@ + $(MAKE) -B -C $@ tarball: netctl-$(VERSION).tar.xz netctl-$(VERSION).tar.xz: | docs diff --git a/docs/netctl.1.txt b/docs/netctl.1.txt index 06638a2..9edd74a 100644 --- a/docs/netctl.1.txt +++ b/docs/netctl.1.txt @@ -81,7 +81,7 @@ On success 0 is returned, a non-zero failure code otherwise. ENVIRONMENT ----------- '$NETCTL_DEBUG':: - If set to `"yes"`, debugging output is generated. + If set to +"yes"+, debugging output is generated. '$NETCTL_STATE_FILE':: The location of the state file. Defaults to '/var/lib/netctl/netctl.state'. diff --git a/docs/netctl.profile.5.txt b/docs/netctl.profile.5.txt index 5d9964e..504a8b5 100644 --- a/docs/netctl.profile.5.txt +++ b/docs/netctl.profile.5.txt @@ -103,7 +103,7 @@ network. In particular, these connection types are +ethernet+, packages, which is blocked by `no'. 'Address=()' [requires 'IP=static']:: - An array of IP addresses suffixed with ``/`'. + An array of IP addresses suffixed with `++/++'. Leaving out brackets for arrays consisting of a single element is accepted in the Bash syntax. @@ -147,21 +147,21 @@ network. In particular, these connection types are +ethernet+, of the DNS nameservers. 'DNSDomain=':: - A ``domain`' line for '/etc/resolv.conf'. + A `++domain++' line for '/etc/resolv.conf'. 'DNSSearch=':: - A ``search`' line for '/etc/resolv.conf'. + A `++search++' line for '/etc/resolv.conf'. 'DNSOptions=()':: - An array of ``options`' lines for '/etc/resolv.conf'. + An array of `++options++' lines for '/etc/resolv.conf'. 'TimeoutDHCP=':: Maximum time, in seconds, to wait for DHCP to be successful. - Defaults to ``10`'. + Defaults to `++10++'. 'TimeoutDAD=':: Maximum time, in seconds, to wait for IPv6's Duplicate Address - Detection to succeed. Defaults to ``3`'. + Detection to succeed. Defaults to `++3++'. OPTIONS FOR `ethernet' CONNECTIONS @@ -171,10 +171,10 @@ of the `ethernet' type: 'SkipNoCarrier=':: Whether or not the absence of a carrier (plugged-in cable) is - acceptable. Defaults to ``no`'. + acceptable. Defaults to `++no++'. 'Auth8021X=':: - Set to ``yes`' to use 802.11x authentication. + Set to `++yes++' to use 802.11x authentication. 'WPAConfigFile=':: Path to a *wpa_supplicant* configuration file. Defaults to @@ -182,14 +182,15 @@ of the `ethernet' type: 'WPADriver=':: The *wpa_supplicant* driver to use for 802.11x authentication. - Defaults to ``wired`'. + Defaults to `++wired++'. 'TimeoutCarrier=':: - Maximum time, in seconds, to wait for a carrier. Defaults to ``5`'. + Maximum time, in seconds, to wait for a carrier. Defaults to + `++5++'. 'TimeoutWPA=':: Maximum time, in seconds, to wait for 802.11x authentication to - succeed. Defaults to ``15`'. + succeed. Defaults to `++15++'. OPTIONS FOR `wireless' CONNECTIONS @@ -199,7 +200,7 @@ of the `wireless' type: 'Security=':: One of `none', `wep', `wpa', `wpa-configsection', or `wpa-config'. - Defaults to ``none`'. + Defaults to `++none++'. 'ESSID=' [mandatory]:: The name of the network to connect to. @@ -214,48 +215,51 @@ of the `wireless' type: 'Hidden=':: Whether or not the specified network is a hidden network. Defaults - to ``no`'. + to `++no++'. 'AdHoc=':: - Whether or not to use ad-hoc mode. Defaults to ``no`'. - -'Country=':: - The country for which frequency regulations will be enforced. + Whether or not to use ad-hoc mode. Defaults to `++no++'. 'Priority=':: Priority group for the network. In case of automatic profile selection, the matched network with the highest priority will be - selected. Defaults to ``0`'. - -'ExcludeAuto=':: - Whether or not to exclude this profile from automatic profile - selection. Defaults to ``no`'. - -'WPAGroup=':: - Group that has the authority to configure *wpa_supplicant* via its - control interface. Defaults to ``wheel`'. + selected. Defaults to `++0++'. 'WPAConfigSection=()' [mandatory for 'Security=wpa-configsection']:: - Array of lines that form a network block for *wpa_supplicant*. + Array of lines that form a network block for *wpa_supplicant*. All + of the above options will be ignored. 'WPAConfigFile=':: - Path to a *wpa_supplicant* configuration file. Defaults to - '/etc/wpa_supplicant.conf'. Used for 'Security=wpa-config'. + Path to a *wpa_supplicant* configuration file. Used only for + 'Security=wpa-config'. All options except 'WPADriver', 'TimeoutWPA', + and 'RFKill' will be ignored. The profile is excluded from + automatic profile selection. Defaults to '/etc/wpa_supplicant.conf'. + +'Country=':: + The country for which frequency regulations will be enforced. + +'WPAGroup=':: + Group that has the authority to configure *wpa_supplicant* via its + control interface. Defaults to `++wheel++'. 'WPADriver=':: - The *wpa_supplicant* driver to use. Defaults to ``nl80211,wext`'. + The *wpa_supplicant* driver to use. Defaults to `++nl80211,wext++'. 'TimeoutWPA=':: Maximum time, in seconds, to wait for steps in the association and - authentication to succeed. Defaults to ``15`'. + authentication to succeed. Defaults to `++15++'. 'RFKill=':: The name of an *rfkill* device. When specified, the device is used to block/unblock the interface when appropriate. Names can be found in '/sys/class/rfkill/rfkillX/name'. It is also possible to set this - variable to ``auto`'. In that case an *rfkill* device that is + variable to `++auto++'. In that case an *rfkill* device that is associated with the network interface is used. +'ExcludeAuto=':: + Whether or not to exclude this profile from automatic profile + selection. Defaults to `++no++'. + OPTIONS FOR `bond' CONNECTIONS ------------------------------ @@ -288,6 +292,7 @@ the *ip options*, the following are understood for connections of the 'Local=':: The address of the local end of the tunnel. + 'Remote=':: The address of the remote end of the tunnel. @@ -299,7 +304,7 @@ the *ip options*, the following are understood for connections of the `tuntap' type: 'Mode=':: - Either ``tun`', or ``tap`'. + Either `tun', or `tap'. 'User=':: The owning user of the tun/tap interface. -- cgit v1.2.3-24-g4f1b From e34538b84fee1ba1b98952bb07f2343ea88141c1 Mon Sep 17 00:00:00 2001 From: Jouke Witteveen Date: Sat, 30 Mar 2013 10:58:04 +0100 Subject: Support more interface types This allows future connection types to use interfaces other than networking interfaces, for instance to use USB interfaces. --- src/netctl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/netctl b/src/netctl index c8703c6..4441838 100755 --- a/src/netctl +++ b/src/netctl @@ -110,9 +110,10 @@ unit_enable() { echo -e "\n[Unit]" >> "$unit" [[ -n $Description ]] && echo "Description=$Description" >> "$unit" if [[ -n ${BindsToInterfaces=$Interface} ]]; then - printf 'BindsTo=sys-subsystem-net-devices-%s.device\n' \ + : ${InterfaceRoot=sys/subsystem/net/devices/} + printf "BindsTo=$(sd_escape "$InterfaceRoot")%s.device\n" \ $(sd_escape "${BindsToInterfaces[@]}") >> "$unit" - printf 'After=sys-subsystem-net-devices-%s.device\n' \ + printf "After=$(sd_escape "$InterfaceRoot")%s.device\n" \ $(sd_escape "${BindsToInterfaces[@]}") >> "$unit" fi if [[ -n $After ]]; then -- cgit v1.2.3-24-g4f1b From 7cd83d3db74606f6a7a881e123b0c3e49f497ed8 Mon Sep 17 00:00:00 2001 From: Robbie Smith Date: Wed, 3 Apr 2013 16:15:33 +1100 Subject: Code tidying up. Renamed mobile connection to mobile-ppp. Also: - Replaced echos with invocations of cat, where possible. - Fixed PIDFILE to point to the file ppp creates. This ensures the interface can be brought down. - Fixed setting of InterfaceRoot. - Removed vim syntax highlighting from ethernet connection. --- docs/examples/mobile | 37 ----------- docs/examples/mobile-ppp | 34 ++++++++++ src/lib/connections/mobile-ppp | 147 ++++++++++++++++++++++++++++++++++++++++ src/lib/connections/ppp | 148 ----------------------------------------- 4 files changed, 181 insertions(+), 185 deletions(-) delete mode 100644 docs/examples/mobile create mode 100644 docs/examples/mobile-ppp create mode 100644 src/lib/connections/mobile-ppp delete mode 100644 src/lib/connections/ppp diff --git a/docs/examples/mobile b/docs/examples/mobile deleted file mode 100644 index e78c595..0000000 --- a/docs/examples/mobile +++ /dev/null @@ -1,37 +0,0 @@ -Description='Example PPP mobile connection' -Interface=ppp0 -Connection=mobile -Peer=mobile-broadband -IdleTimeout=30 - -# Debug pppd / chat output (separately from netctl) -#PPPDebug=true - -# The device will usually be /dev/ttyUSB* (default: ttyUSB0 -Device=ttyUSB0 - -# Use default route provided by the peer (default: true) -#DefaultRoute=true -# Use DNS provided by the peer (default: true) -#UsePeerDNS=true - -# Always keep a connection established -ConnectionMode='persist' -# Establish connection on demand -#ConnectionMode='demand' -#IdleTimeout=300 - -# The user and password are not always required -#User='example@yourprovider.com' -#Password='very secret' - -# The access point name you are connecting to -AccessPointName=apn - -# If your device has a PIN code, set it here. Defaults to None -#Pin=None - -# Mode can be one of 3Gpref, 3Gonly, GPRSpref, GPRSonly, None -# These only work for Huawei USB modems; all other devices should use None -Mode=3Gpref - diff --git a/docs/examples/mobile-ppp b/docs/examples/mobile-ppp new file mode 100644 index 0000000..b624175 --- /dev/null +++ b/docs/examples/mobile-ppp @@ -0,0 +1,34 @@ +Description='Example PPP mobile connection' +Interface=ttyUSB0 +Connection=mobile-ppp +IdleTimeout=30 + +# Debug pppd / chat output (separately from netctl) +#PPPDebug=true + +# Use default route provided by the peer (default: true) +#DefaultRoute=true +# Use DNS provided by the peer (default: true) +#UsePeerDNS=true + +# Always keep a connection established +ConnectionMode='persist' +# Establish connection on demand +#ConnectionMode='demand' +#IdleTimeout=300 + +# The user and password are not always required +#User='example@yourprovider.com' +#Password='very secret' + +# The access point name you are connecting to +AccessPointName=apn + +# If your device has a PIN code, set it here. Defaults to None +#Pin=None + +# Mode can be one of 3Gpref, 3Gonly, GPRSpref, GPRSonly, None +# These only work for Huawei USB modems; all other devices should use None +Mode=3Gpref + +# vim:ft=dosini diff --git a/src/lib/connections/mobile-ppp b/src/lib/connections/mobile-ppp new file mode 100644 index 0000000..6a11fdd --- /dev/null +++ b/src/lib/connections/mobile-ppp @@ -0,0 +1,147 @@ +# Contributed by Robbie Smith +# Based on Thomas Bächler’s pppoe script +# Also see for more information. + +: ${PPPD:=pppd} +# Set the interface route +: ${InterfaceRoot=dev/} + +_quotestring() { + echo "\"${1/\"/\\\"}\"" +} + +mobile-ppp_up() { + local cfg + local chat + + mkdir -p "$STATE_DIR/mobile-ppp.${Interface}.${Profile}/" + chmod 700 "$STATE_DIR/mobile-ppp.${Interface}.${Profile}/" + cfg="$STATE_DIR/mobile-ppp.${Interface}.${Profile}/options" + chat="$STATE_DIR/mobile-ppp.${Interface}.${Profile}/modem.chat" + : > "${cfg}" + chmod 600 "${cfg}" + + echo "linkname $(_quotestring "${Profile}")" >> "${cfg}" + + cat >> "${cfg}" << EOF +${Interface} +921600 +lock +crtscts +modem +passive +novj +holdoff 10 +maxfail 5 +EOF + + # Debug pppd output separately from netcfg + if is_yes "${PPPDebug:-yes}"; then + echo "debug" >> "${cfg}" + fi + + # Sets up route + if is_yes "${DefaultRoute:-yes}"; then + echo "defaultroute" >> "${cfg}" + else + echo "nodefaultroute" >> "${cfg}" + fi + if is_yes "${UsePeerDNS:-yes}"; then + echo "usepeerdns" >> "${cfg}" + fi + + # Writes username and password + echo "noauth" >> "${cfg}" + echo "hide-password" >> ${cfg} + [[ -n ${User} ]] && echo "user $(_quotestring "${User}")" >> "${cfg}" + [[ -n ${Password} ]] && echo "password $(_quotestring "${Password}")" >> "${cfg}" + + #echo "'OK' @/etc/ppp/chatscripts/pin" >> "${chat}" + if [ -n "${Pin}" ]; then + PinStr="'OK' 'AT+CPIN=${Pin}'" + else + PinStr="'OK' 'AT'" + fi + report_debug echo $PinStr + + # Mode can be one of 3Gpref, 3Gonly, GPRSpref, GPRSonly, None + # Only works for Huawei modems + #echo "'OK' @/etc/ppp/chatscripts/mode" >> "${chat}" + case "${Mode}" in + 3Gonly) + ModeStr="'OK' 'AT\^SYSCFG=14,2,3fffffff,0,1'" + ;; + 3Gpref) + ModeStr="'OK' 'AT\^SYSCFG=2,2,3fffffff,0,1'" + ;; + GPRSonly) + ModeStr="'OK' 'AT\^SYSCFG=13,1,3fffffff,0,0'" + ;; + GPRSpref) + ModeStr="'OK' 'AT\^SYSCFG=2,1,3fffffff,0,0'" + ;; + *) + ModeStr="'OK' 'AT'" + ;; + esac + + # Now that we’ve got the ppp configuration set up, write the chat script + cat >> "${chat}" << EOF +ECHO ON +ABORT 'BUSY' +ABORT 'NO CARRIER' +ABORT 'VOICE' +ABORT 'NO DIALTONE' +ABORT 'NO DIAL TONE' +ABORT 'NO ANSWER' +ABORT 'DELAYED' +ABORT '\nRINGING\r\n\r\nRINGING\r' +REPORT CONNECT +TIMEOUT 6 +'' 'ATQ0' +'OK-AT-OK' 'ATZ' +TIMEOUT 3 +${PinStr} +'OK\d-AT-OK' 'ATI' +'OK' 'ATZ' +'OK' 'ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0' +${ModeStr} +'OK-AT-OK' 'AT+CGDCONT=1,"IP","${AccessPointName}"' +'OK' 'ATDT*99#' +TIMEOUT 30 +CONNECT '' +EOF + + # Add the chat script line to the configuration + echo "connect \"/usr/sbin/chat -v -t15 -f ${chat}\"" >> "${cfg}" + + ip link set dev "${Interface}" up + #$PPPD call "$Peer" updetach child-timeout "$PPPTimeout" linkname "$Peer" + $PPPD file "${cfg}" + + if [[ $? -ne 0 ]]; then + rmdir "$STATE_DIR/mobile-ppp.${Interface}.${Profile}/" + report_error "Couldn't make pppd connection." + return 1 + fi +} + +mobile-ppp_down() { + local cfg + local chat + cfg="$STATE_DIR/mobile-ppp.${Interface}.${Profile}/options" + chat="$STATE_DIR/mobile-ppp.${Interface}.${Profile}/modem.chat" + PIDFILE="/var/run/ppp-${Profile}.pid" + + if [[ -e $PIDFILE ]]; then + read PID < "$PIDFILE" + [[ "$PID" ]] && kill "$PID" + fi + + rm "${cfg}" + rm "${chat}" + rmdir "$STATE_DIR/mobile-ppp.${Interface}.${Profile}/" +} + + +# vim: ft=sh ts=4 et sw=4: diff --git a/src/lib/connections/ppp b/src/lib/connections/ppp deleted file mode 100644 index 54bedba..0000000 --- a/src/lib/connections/ppp +++ /dev/null @@ -1,148 +0,0 @@ -# Contributed by Robbie Smith -# Based on Thomas Bächler’s pppoe script -# Also see for more information. - -: ${PPPD:=pppd} - -_quotestring() { - echo "\"${1/\"/\\\"}\"" -} - -mobile_up() { - local cfg - local chat - - mkdir -p "$STATE_DIR/mobile.${Interface}.${Profile}/" - chmod 700 "$STATE_DIR/mobile.${Interface}.${Profile}/" - cfg="$STATE_DIR/mobile.${Interface}.${Profile}/options" - chat="$STATE_DIR/mobile.${Interface}.${Profile}/modem.chat" - : > "${cfg}" - chmod 600 "${cfg}" - - echo "linkname $(_quotestring "${Profile}")" >> "${cfg}" - - # Set device - if [ -n "${Device}" ]; then - echo "${Device}" >> "${cfg}" - else - echo "ttyUSB0" >> "${cfg}" - fi - - echo "921600" >> "${cfg}" - echo "lock" >> "${cfg}" - echo "crtscts" >> "${cfg}" - echo "modem" >> "${cfg}" - echo "passive" >> "${cfg}" - echo "novj" >> "${cfg}" - echo "holdoff 10" >> "${cfg}" - echo "maxfail 5" >> "${cfg}" - - # Debug pppd output separately from netcfg - if is_yes "${PPPDebug:-yes}"; then - echo "debug" >> "${cfg}" - fi - - # Sets up route - if is_yes "${DefaultRoute:-yes}"; then - echo "defaultroute" >> "${cfg}" - else - echo "nodefaultroute" >> "${cfg}" - fi - if is_yes "${UsePeerDNS:-yes}"; then - echo "usepeerdns" >> "${cfg}" - fi - - # Writes username and password - echo "noauth" >> "${cfg}" - echo "hide-password" >> ${cfg} - [[ -n ${User} ]] && echo "user $(_quotestring "${User}")" >> "${cfg}" - [[ -n ${Password} ]] && echo "password $(_quotestring "${Password}")" >> "${cfg}" - - # Now that we’ve got the ppp configuration set up, write the chat script - echo "ECHO ON" >> "${chat}" - echo "ABORT 'BUSY'" >> "${chat}" - echo "ABORT 'NO CARRIER'" >> "${chat}" - echo "ABORT 'VOICE'" >> "${chat}" - echo "ABORT 'NO DIALTONE'" >> "${chat}" - echo "ABORT 'NO DIAL TONE'" >> "${chat}" - echo "ABORT 'NO ANSWER'" >> "${chat}" - echo "ABORT 'DELAYED'" >> "${chat}" - echo "ABORT '\nRINGING\r\n\r\nRINGING\r'" >> "${chat}" - echo "REPORT CONNECT" >> "${chat}" - echo "TIMEOUT 6" >> "${chat}" - echo "'' 'ATQ0'" >> "${chat}" - echo "'OK-AT-OK' 'ATZ'" >> "${chat}" - echo "TIMEOUT 3" >> "${chat}" - - #echo "'OK' @/etc/ppp/chatscripts/pin" >> "${chat}" - if [ -n "${Pin}" ]; then - echo "'OK' 'AT+CPIN=${Pin}'" >> "${chat}" - else - echo "'OK' 'AT'" >> "${chat}" - fi - - echo "'OK\d-AT-OK' 'ATI'" >> "${chat}" - echo "'OK' 'ATZ'" >> "${chat}" - echo "'OK' 'ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0'" >> "${chat}" - - # Mode can be one of 3Gpref, 3Gonly, GPRSpref, GPRSonly, None - # Only works for Huawei modems - #echo "'OK' @/etc/ppp/chatscripts/mode" >> "${chat}" - case "${Mode}" in - 3Gonly) - echo "'OK' 'AT\^SYSCFG=14,2,3fffffff,0,1'" >> "${chat}" - ;; - 3Gpref) - echo "'OK' 'AT\^SYSCFG=2,2,3fffffff,0,1'" >> "${chat}" - ;; - GPRSonly) - echo "'OK' 'AT\^SYSCFG=13,1,3fffffff,0,0'" >> "${chat}" - ;; - GPRSpref) - echo "'OK' 'AT\^SYSCFG=2,1,3fffffff,0,0'" >> "${chat}" - ;; - *) - echo "'OK' 'AT'" >> "${chat}" - ;; - esac - - # Set up Access Point Name - echo "'OK-AT-OK' AT+CGDCONT=1,\"IP\",\"${AccessPointName}\"" >> "${chat}" - - echo "'OK' 'ATDT*99#'" >> "${chat}" - echo "TIMEOUT 30" >> "${chat}" - echo "CONNECT ''" >> "${chat}" - - # Add the chat script line to the configuration - echo "connect \"/usr/sbin/chat -v -t15 -f ${chat}\"" >> "${cfg}" - - ip link set dev "${Interface}" up - #$PPPD call "$Peer" updetach child-timeout "$PPPTimeout" linkname "$Peer" - $PPPD file "${cfg}" - - if [[ $? -ne 0 ]]; then - rmdir "$STATE_DIR/mobile.${Interface}.${Profile}/" - report_error "Couldn't make pppd connection." - return 1 - fi -} - -mobile_down() { - local cfg - local chat - cfg="$STATE_DIR/mobile.${Interface}.${Profile}/options" - chat="$STATE_DIR/mobile.${Interface}.${Profile}/modem.chat" - PIDFILE="/var/run/mobile-${Profile}.pid" - - if [[ -e $PIDFILE ]]; then - read PID < "$PIDFILE" - [[ "$PID" ]] && kill "$PID" - fi - - rm "${cfg}" - rm "${chat}" - rmdir "$STATE_DIR/mobile.${Interface}.${Profile}/" -} - - -# vim: ft=sh ts=4 et sw=4: -- cgit v1.2.3-24-g4f1b From 492fe67b4ae418feda69074f3335be14fbcc79ab Mon Sep 17 00:00:00 2001 From: Robbie Smith Date: Wed, 10 Apr 2013 11:33:37 +1000 Subject: Changed connections to use underscores. --- docs/examples/mobile-ppp | 34 ---------- docs/examples/mobile_ppp | 34 ++++++++++ src/lib/connections/mobile-ppp | 147 ----------------------------------------- src/lib/connections/mobile_ppp | 147 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 181 insertions(+), 181 deletions(-) delete mode 100644 docs/examples/mobile-ppp create mode 100644 docs/examples/mobile_ppp delete mode 100644 src/lib/connections/mobile-ppp create mode 100644 src/lib/connections/mobile_ppp diff --git a/docs/examples/mobile-ppp b/docs/examples/mobile-ppp deleted file mode 100644 index b624175..0000000 --- a/docs/examples/mobile-ppp +++ /dev/null @@ -1,34 +0,0 @@ -Description='Example PPP mobile connection' -Interface=ttyUSB0 -Connection=mobile-ppp -IdleTimeout=30 - -# Debug pppd / chat output (separately from netctl) -#PPPDebug=true - -# Use default route provided by the peer (default: true) -#DefaultRoute=true -# Use DNS provided by the peer (default: true) -#UsePeerDNS=true - -# Always keep a connection established -ConnectionMode='persist' -# Establish connection on demand -#ConnectionMode='demand' -#IdleTimeout=300 - -# The user and password are not always required -#User='example@yourprovider.com' -#Password='very secret' - -# The access point name you are connecting to -AccessPointName=apn - -# If your device has a PIN code, set it here. Defaults to None -#Pin=None - -# Mode can be one of 3Gpref, 3Gonly, GPRSpref, GPRSonly, None -# These only work for Huawei USB modems; all other devices should use None -Mode=3Gpref - -# vim:ft=dosini diff --git a/docs/examples/mobile_ppp b/docs/examples/mobile_ppp new file mode 100644 index 0000000..4e5079f --- /dev/null +++ b/docs/examples/mobile_ppp @@ -0,0 +1,34 @@ +Description='Example PPP mobile connection' +Interface=ttyUSB0 +Connection=mobile_ppp +IdleTimeout=30 + +# Debug pppd / chat output (separately from netctl) +#PPPDebug=true + +# Use default route provided by the peer (default: true) +#DefaultRoute=true +# Use DNS provided by the peer (default: true) +#UsePeerDNS=true + +# Always keep a connection established +ConnectionMode='persist' +# Establish connection on demand +#ConnectionMode='demand' +#IdleTimeout=300 + +# The user and password are not always required +#User='example@yourprovider.com' +#Password='very secret' + +# The access point name you are connecting to +AccessPointName=apn + +# If your device has a PIN code, set it here. Defaults to None +#Pin=None + +# Mode can be one of 3Gpref, 3Gonly, GPRSpref, GPRSonly, None +# These only work for Huawei USB modems; all other devices should use None +Mode=3Gpref + +# vim:ft=dosini diff --git a/src/lib/connections/mobile-ppp b/src/lib/connections/mobile-ppp deleted file mode 100644 index 6a11fdd..0000000 --- a/src/lib/connections/mobile-ppp +++ /dev/null @@ -1,147 +0,0 @@ -# Contributed by Robbie Smith -# Based on Thomas Bächler’s pppoe script -# Also see for more information. - -: ${PPPD:=pppd} -# Set the interface route -: ${InterfaceRoot=dev/} - -_quotestring() { - echo "\"${1/\"/\\\"}\"" -} - -mobile-ppp_up() { - local cfg - local chat - - mkdir -p "$STATE_DIR/mobile-ppp.${Interface}.${Profile}/" - chmod 700 "$STATE_DIR/mobile-ppp.${Interface}.${Profile}/" - cfg="$STATE_DIR/mobile-ppp.${Interface}.${Profile}/options" - chat="$STATE_DIR/mobile-ppp.${Interface}.${Profile}/modem.chat" - : > "${cfg}" - chmod 600 "${cfg}" - - echo "linkname $(_quotestring "${Profile}")" >> "${cfg}" - - cat >> "${cfg}" << EOF -${Interface} -921600 -lock -crtscts -modem -passive -novj -holdoff 10 -maxfail 5 -EOF - - # Debug pppd output separately from netcfg - if is_yes "${PPPDebug:-yes}"; then - echo "debug" >> "${cfg}" - fi - - # Sets up route - if is_yes "${DefaultRoute:-yes}"; then - echo "defaultroute" >> "${cfg}" - else - echo "nodefaultroute" >> "${cfg}" - fi - if is_yes "${UsePeerDNS:-yes}"; then - echo "usepeerdns" >> "${cfg}" - fi - - # Writes username and password - echo "noauth" >> "${cfg}" - echo "hide-password" >> ${cfg} - [[ -n ${User} ]] && echo "user $(_quotestring "${User}")" >> "${cfg}" - [[ -n ${Password} ]] && echo "password $(_quotestring "${Password}")" >> "${cfg}" - - #echo "'OK' @/etc/ppp/chatscripts/pin" >> "${chat}" - if [ -n "${Pin}" ]; then - PinStr="'OK' 'AT+CPIN=${Pin}'" - else - PinStr="'OK' 'AT'" - fi - report_debug echo $PinStr - - # Mode can be one of 3Gpref, 3Gonly, GPRSpref, GPRSonly, None - # Only works for Huawei modems - #echo "'OK' @/etc/ppp/chatscripts/mode" >> "${chat}" - case "${Mode}" in - 3Gonly) - ModeStr="'OK' 'AT\^SYSCFG=14,2,3fffffff,0,1'" - ;; - 3Gpref) - ModeStr="'OK' 'AT\^SYSCFG=2,2,3fffffff,0,1'" - ;; - GPRSonly) - ModeStr="'OK' 'AT\^SYSCFG=13,1,3fffffff,0,0'" - ;; - GPRSpref) - ModeStr="'OK' 'AT\^SYSCFG=2,1,3fffffff,0,0'" - ;; - *) - ModeStr="'OK' 'AT'" - ;; - esac - - # Now that we’ve got the ppp configuration set up, write the chat script - cat >> "${chat}" << EOF -ECHO ON -ABORT 'BUSY' -ABORT 'NO CARRIER' -ABORT 'VOICE' -ABORT 'NO DIALTONE' -ABORT 'NO DIAL TONE' -ABORT 'NO ANSWER' -ABORT 'DELAYED' -ABORT '\nRINGING\r\n\r\nRINGING\r' -REPORT CONNECT -TIMEOUT 6 -'' 'ATQ0' -'OK-AT-OK' 'ATZ' -TIMEOUT 3 -${PinStr} -'OK\d-AT-OK' 'ATI' -'OK' 'ATZ' -'OK' 'ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0' -${ModeStr} -'OK-AT-OK' 'AT+CGDCONT=1,"IP","${AccessPointName}"' -'OK' 'ATDT*99#' -TIMEOUT 30 -CONNECT '' -EOF - - # Add the chat script line to the configuration - echo "connect \"/usr/sbin/chat -v -t15 -f ${chat}\"" >> "${cfg}" - - ip link set dev "${Interface}" up - #$PPPD call "$Peer" updetach child-timeout "$PPPTimeout" linkname "$Peer" - $PPPD file "${cfg}" - - if [[ $? -ne 0 ]]; then - rmdir "$STATE_DIR/mobile-ppp.${Interface}.${Profile}/" - report_error "Couldn't make pppd connection." - return 1 - fi -} - -mobile-ppp_down() { - local cfg - local chat - cfg="$STATE_DIR/mobile-ppp.${Interface}.${Profile}/options" - chat="$STATE_DIR/mobile-ppp.${Interface}.${Profile}/modem.chat" - PIDFILE="/var/run/ppp-${Profile}.pid" - - if [[ -e $PIDFILE ]]; then - read PID < "$PIDFILE" - [[ "$PID" ]] && kill "$PID" - fi - - rm "${cfg}" - rm "${chat}" - rmdir "$STATE_DIR/mobile-ppp.${Interface}.${Profile}/" -} - - -# vim: ft=sh ts=4 et sw=4: diff --git a/src/lib/connections/mobile_ppp b/src/lib/connections/mobile_ppp new file mode 100644 index 0000000..fe01fe0 --- /dev/null +++ b/src/lib/connections/mobile_ppp @@ -0,0 +1,147 @@ +# Contributed by Robbie Smith +# Based on Thomas Bächler’s pppoe script +# Also see for more information. + +: ${PPPD:=pppd} +# Set the interface route +: ${InterfaceRoot=dev/} + +_quotestring() { + echo "\"${1/\"/\\\"}\"" +} + +mobile_ppp_up() { + local cfg + local chat + + mkdir -p "$STATE_DIR/mobile_ppp.${Interface}.${Profile}/" + chmod 700 "$STATE_DIR/mobile_ppp.${Interface}.${Profile}/" + cfg="$STATE_DIR/mobile_ppp.${Interface}.${Profile}/options" + chat="$STATE_DIR/mobile_ppp.${Interface}.${Profile}/modem.chat" + : > "${cfg}" + chmod 600 "${cfg}" + + echo "linkname $(_quotestring "${Profile}")" >> "${cfg}" + + cat >> "${cfg}" << EOF +${Interface} +921600 +lock +crtscts +modem +passive +novj +holdoff 10 +maxfail 5 +EOF + + # Debug pppd output separately from netcfg + if is_yes "${PPPDebug:-yes}"; then + echo "debug" >> "${cfg}" + fi + + # Sets up route + if is_yes "${DefaultRoute:-yes}"; then + echo "defaultroute" >> "${cfg}" + else + echo "nodefaultroute" >> "${cfg}" + fi + if is_yes "${UsePeerDNS:-yes}"; then + echo "usepeerdns" >> "${cfg}" + fi + + # Writes username and password + echo "noauth" >> "${cfg}" + echo "hide-password" >> ${cfg} + [[ -n ${User} ]] && echo "user $(_quotestring "${User}")" >> "${cfg}" + [[ -n ${Password} ]] && echo "password $(_quotestring "${Password}")" >> "${cfg}" + + #echo "'OK' @/etc/ppp/chatscripts/pin" >> "${chat}" + if [ -n "${Pin}" ]; then + PinStr="'OK' 'AT+CPIN=${Pin}'" + else + PinStr="'OK' 'AT'" + fi + report_debug echo $PinStr + + # Mode can be one of 3Gpref, 3Gonly, GPRSpref, GPRSonly, None + # Only works for Huawei modems + #echo "'OK' @/etc/ppp/chatscripts/mode" >> "${chat}" + case "${Mode}" in + 3Gonly) + ModeStr="'OK' 'AT\^SYSCFG=14,2,3fffffff,0,1'" + ;; + 3Gpref) + ModeStr="'OK' 'AT\^SYSCFG=2,2,3fffffff,0,1'" + ;; + GPRSonly) + ModeStr="'OK' 'AT\^SYSCFG=13,1,3fffffff,0,0'" + ;; + GPRSpref) + ModeStr="'OK' 'AT\^SYSCFG=2,1,3fffffff,0,0'" + ;; + *) + ModeStr="'OK' 'AT'" + ;; + esac + + # Now that we’ve got the ppp configuration set up, write the chat script + cat >> "${chat}" << EOF +ECHO ON +ABORT 'BUSY' +ABORT 'NO CARRIER' +ABORT 'VOICE' +ABORT 'NO DIALTONE' +ABORT 'NO DIAL TONE' +ABORT 'NO ANSWER' +ABORT 'DELAYED' +ABORT '\nRINGING\r\n\r\nRINGING\r' +REPORT CONNECT +TIMEOUT 6 +'' 'ATQ0' +'OK-AT-OK' 'ATZ' +TIMEOUT 3 +${PinStr} +'OK\d-AT-OK' 'ATI' +'OK' 'ATZ' +'OK' 'ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0' +${ModeStr} +'OK-AT-OK' 'AT+CGDCONT=1,"IP","${AccessPointName}"' +'OK' 'ATDT*99#' +TIMEOUT 30 +CONNECT '' +EOF + + # Add the chat script line to the configuration + echo "connect \"/usr/sbin/chat -v -t15 -f ${chat}\"" >> "${cfg}" + + ip link set dev "${Interface}" up + #$PPPD call "$Peer" updetach child-timeout "$PPPTimeout" linkname "$Peer" + $PPPD file "${cfg}" + + if [[ $? -ne 0 ]]; then + rmdir "$STATE_DIR/mobile_ppp.${Interface}.${Profile}/" + report_error "Couldn't make pppd connection." + return 1 + fi +} + +mobile_ppp_down() { + local cfg + local chat + cfg="$STATE_DIR/mobile_ppp.${Interface}.${Profile}/options" + chat="$STATE_DIR/mobile_ppp.${Interface}.${Profile}/modem.chat" + PIDFILE="/var/run/ppp-${Profile}.pid" + + if [[ -e $PIDFILE ]]; then + read PID < "$PIDFILE" + [[ "$PID" ]] && kill "$PID" + fi + + rm "${cfg}" + rm "${chat}" + rmdir "$STATE_DIR/mobile_ppp.${Interface}.${Profile}/" +} + + +# vim: ft=sh ts=4 et sw=4: -- cgit v1.2.3-24-g4f1b