From bf628f732acedce1ff1837202627260c6fd4533d Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Sun, 26 Jan 2020 18:06:22 +0100 Subject: wwan: T1988: initial XML/Python representation --- src/conf_mode/interfaces-wirelessmodem.py | 192 ++++++++++++++++++++++++++++++ src/etc/ppp/peers/chat/att | 6 + src/etc/ppp/peers/chat/sc1 | 13 ++ src/etc/ppp/peers/chat/verizon | 5 + 4 files changed, 216 insertions(+) create mode 100755 src/conf_mode/interfaces-wirelessmodem.py create mode 100644 src/etc/ppp/peers/chat/att create mode 100644 src/etc/ppp/peers/chat/sc1 create mode 100644 src/etc/ppp/peers/chat/verizon (limited to 'src') diff --git a/src/conf_mode/interfaces-wirelessmodem.py b/src/conf_mode/interfaces-wirelessmodem.py new file mode 100755 index 000000000..388d98f4e --- /dev/null +++ b/src/conf_mode/interfaces-wirelessmodem.py @@ -0,0 +1,192 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2020 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import os + +from sys import exit +from copy import deepcopy +from jinja2 import Template +from subprocess import Popen, PIPE +from pwd import getpwnam +from grp import getgrnam + +from vyos.config import Config +from vyos import ConfigError + +# Please be careful if you edit the template. +config_wwan_tmpl = """### Autogenerated by interfaces-wirelessmodem.py ### +{% if description %} +# {{ description }} +{% endif %} + +ipparam {{ intf }} {{ metric }} +{% if on_demand -%} +demand +{%- endif %} +{% if name_server -%} +usepeerdns +{%- endif %} +logfile {{ logfile }} +linkname {{ intf }} +lcp-echo-failure 0 +115200 +debug +nodefaultroute +ipcp-max-failure 4 +ipcp-accept-local +ipcp-accept-remote +noauth +crtscts +lock +persist + +""" + +default_config_data = { + 'address': [], + 'deleted': False, + 'description': '', + 'device': 'ttyUSB0', + 'disable': False, + 'disable_link_detect': 1, + 'on_demand': False, + 'logfile': '', + 'metric': '10', + 'mtu': '1500', + 'name_server': True, + 'network': 'att', + 'intf': '' +} + +def subprocess_cmd(command): + p = Popen(command, stdout=PIPE, shell=True) + p.communicate() + +def check_kmod(): + modules = ['option', 'usb_wwan', 'usbserial'] + for module in modules: + if not os.path.exists(f'/sys/module/{module}'): + if os.system(f'modprobe {module}') != 0: + raise ConfigError(f'Loading Kernel module {module} failed') + +def get_config(): + wwan = deepcopy(default_config_data) + conf = Config() + + # determine tagNode instance + if 'VYOS_TAGNODE_VALUE' not in os.environ: + raise ConfigError('Interface (VYOS_TAGNODE_VALUE) not specified') + + wwan['intf'] = os.environ['VYOS_TAGNODE_VALUE'] + wwan['logfile'] = f"/var/log/vyatta/ppp_{wwan['intf']}.log" + + # Check if interface has been removed + if not conf.exists('interfaces wirelessmodem ' + wwan['intf']): + wwan['deleted'] = True + return wwan + + # set new configuration level + conf.set_level('interfaces wirelessmodem ' + wwan['intf']) + + # get metrick for backup default route + if conf.exists(['backup', 'distance']): + wwan['metric'] = conf.return_value(['backup', 'distance']) + + # Retrieve interface description + if conf.exists(['description']): + wwan['description'] = conf.return_value(['description']) + + # System device name + if conf.exists(['device']): + wwan['device'] = conf.return_value(['device']) + + # ignore link state changes + if conf.exists('disable-link-detect'): + wwan['disable_link_detect'] = 2 + + # Do not use DNS servers provided by the peer + if conf.exists(['mtu']): + wwan['mtu'] = conf.return_value(['mtu']) + + # Do not use DNS servers provided by the peer + if conf.exists(['network']): + wwan['network'] = conf.return_value(['network']) + + # Do not use DNS servers provided by the peer + if conf.exists(['no-dns']): + wwan['name_server'] = False + + # Access concentrator name (only connect to this concentrator) + if conf.exists(['ondemand']): + wwan['on_demand'] = True + + return wwan + +def verify(wwan): + if wwan is None: + return None + + return None + +def generate(wwan): + config_file_wwan = f"/etc/ppp/peers/{wwan['intf']}" + + # Always hang-up WWAN connection prior generating new configuration file + cmd = f"systemctl stop ppp@{wwan['intf']}.service" + subprocess_cmd(cmd) + + if wwan['deleted']: + # Delete PPP configuration files + if os.path.exists(config_file_wwan): + os.unlink(config_file_wwan) + + else: + # Create PPP configuration files + tmpl = Template(config_wwan_tmpl) + config_text = tmpl.render(wwan) + with open(config_file_wwan, 'w') as f: + f.write(config_text) + + return None + +def apply(wwan): + if wwan['deleted']: + # bail out early + return None + + if not wwan['disable']: + # dial WWAN connection + cmd = f"systemctl start ppp@{wwan['intf']}.service" + subprocess_cmd(cmd) + + # make logfile owned by root / vyattacfg + if os.path.isfile(wwan['logfile']): + uid = getpwnam('root').pw_uid + gid = getgrnam('vyattacfg').gr_gid + os.chown(wwan['logfile'], uid, gid) + + return None + +if __name__ == '__main__': + try: + check_kmod() + c = get_config() + verify(c) + generate(c) + apply(c) + except ConfigError as e: + print(e) + exit(1) diff --git a/src/etc/ppp/peers/chat/att b/src/etc/ppp/peers/chat/att new file mode 100644 index 000000000..7a02682f5 --- /dev/null +++ b/src/etc/ppp/peers/chat/att @@ -0,0 +1,6 @@ +ABORT 'NO DIAL TONE' ABORT 'NO ANSWER' ABORT 'NO CARRIER' ABORT DELAYED +'' AT +OK ATZ +OK 'AT+CGDCONT=1,"IP","ISP.CINGULAR"' +OK ATD*99# +CONNECT '' diff --git a/src/etc/ppp/peers/chat/sc1 b/src/etc/ppp/peers/chat/sc1 new file mode 100644 index 000000000..fbfabd8c2 --- /dev/null +++ b/src/etc/ppp/peers/chat/sc1 @@ -0,0 +1,13 @@ +TIMEOUT 60 +ABORT ERROR +ABORT BUSY +ABORT VOICE +ABORT "NO CARRIER" +ABORT "NO DIALTONE" +ABORT "NO DIAL TONE" +ABORT "NO ANSWER" +"" "ATZ" +"" "AT&FH0M0" +OK-AT-OK "ATDT*99#" +TIMEOUT 75 +CONNECT diff --git a/src/etc/ppp/peers/chat/verizon b/src/etc/ppp/peers/chat/verizon new file mode 100644 index 000000000..a36a3e915 --- /dev/null +++ b/src/etc/ppp/peers/chat/verizon @@ -0,0 +1,5 @@ +ABORT 'NO CARRIER' ABORT 'ERROR' ABORT 'NO DIALTONE' ABORT +'BUSY' ABORT 'NO ANSWER' +'' ATZ +OK-AT-OK ATDT#777 +CONNECT \d\c -- cgit v1.2.3 From ced45949bc282d23b0767f698f31b580602f0c9c Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Tue, 10 Mar 2020 19:50:00 +0100 Subject: wwan: T1988: add support for Sierra Wireless MC7710 modem --- debian/vyos-1x.install | 1 + src/conf_mode/interfaces-wirelessmodem.py | 11 ++++++++++- src/etc/udev/rules.d/99-vyos-wwan.rules | 11 +++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 src/etc/udev/rules.d/99-vyos-wwan.rules (limited to 'src') diff --git a/debian/vyos-1x.install b/debian/vyos-1x.install index 5bb7ea507..5004d111f 100644 --- a/debian/vyos-1x.install +++ b/debian/vyos-1x.install @@ -3,6 +3,7 @@ etc/init.d etc/ppp etc/rsyslog.d etc/systemd +etc/udev etc/vyos lib/ opt/ diff --git a/src/conf_mode/interfaces-wirelessmodem.py b/src/conf_mode/interfaces-wirelessmodem.py index 388d98f4e..93f60d038 100755 --- a/src/conf_mode/interfaces-wirelessmodem.py +++ b/src/conf_mode/interfaces-wirelessmodem.py @@ -32,6 +32,9 @@ config_wwan_tmpl = """### Autogenerated by interfaces-wirelessmodem.py ### # {{ description }} {% endif %} +# physical device +/dev/{{ device }} + ipparam {{ intf }} {{ metric }} {% if on_demand -%} demand @@ -53,6 +56,7 @@ crtscts lock persist + """ default_config_data = { @@ -136,9 +140,14 @@ def get_config(): return wwan def verify(wwan): - if wwan is None: + if wwan['deleted']: return None + # we can not use isfile() here as Linux device files are no regular files + # thus the check will return False + if not os.path.exists(f"/dev/{wwan['device']}"): + raise ConfigError(f"Device {wwan['device']} does not exist") + return None def generate(wwan): diff --git a/src/etc/udev/rules.d/99-vyos-wwan.rules b/src/etc/udev/rules.d/99-vyos-wwan.rules new file mode 100644 index 000000000..67f30a3dd --- /dev/null +++ b/src/etc/udev/rules.d/99-vyos-wwan.rules @@ -0,0 +1,11 @@ +ACTION!="add|change", GOTO="mbim_to_qmi_rules_end" + +SUBSYSTEM!="usb", GOTO="mbim_to_qmi_rules_end" + +# ignore any device with only one configuration +ATTR{bNumConfigurations}=="1", GOTO="mbim_to_qmi_rules_end" + +# force Sierra Wireless MC7710 to configuration #1 +ATTR{idVendor}=="1199",ATTR{idProduct}=="68a2",ATTR{bConfigurationValue}="1" + +LABEL="mbim_to_qmi_rules_end" -- cgit v1.2.3 From 65f0c6bf68f4f903d8011d0083385aa0f3c280ce Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Thu, 19 Mar 2020 20:04:53 +0100 Subject: wwan: T1988: support interface disable --- .../interfaces-wirelessmodem.xml.in | 18 +++---- src/conf_mode/interfaces-wirelessmodem.py | 45 +++++++++++++--- src/migration-scripts/interfaces/6-to-7 | 63 ++++++++++++++++++++++ 3 files changed, 109 insertions(+), 17 deletions(-) create mode 100755 src/migration-scripts/interfaces/6-to-7 (limited to 'src') diff --git a/interface-definitions/interfaces-wirelessmodem.xml.in b/interface-definitions/interfaces-wirelessmodem.xml.in index e8946fa68..81efbdb54 100644 --- a/interface-definitions/interfaces-wirelessmodem.xml.in +++ b/interface-definitions/interfaces-wirelessmodem.xml.in @@ -16,6 +16,11 @@ + + + Access Point Name (APN) + + Insert backup default route @@ -37,26 +42,19 @@ #include + #include System device name (default: ttyUSB0) - >ttyXXX%lt; + ttyXXX System TTY device name #include #include - - - Carrier network to define dial strings - - - - - - + Do not use peer supplied DNS server information diff --git a/src/conf_mode/interfaces-wirelessmodem.py b/src/conf_mode/interfaces-wirelessmodem.py index 93f60d038..adb8bdc2d 100755 --- a/src/conf_mode/interfaces-wirelessmodem.py +++ b/src/conf_mode/interfaces-wirelessmodem.py @@ -36,6 +36,8 @@ config_wwan_tmpl = """### Autogenerated by interfaces-wirelessmodem.py ### /dev/{{ device }} ipparam {{ intf }} {{ metric }} +ifname {{ intf }} +linkname {{ intf }} {% if on_demand -%} demand {%- endif %} @@ -43,7 +45,7 @@ demand usepeerdns {%- endif %} logfile {{ logfile }} -linkname {{ intf }} + lcp-echo-failure 0 115200 debug @@ -56,11 +58,24 @@ crtscts lock persist +connect '/usr/sbin/chat -v -t6 -f /etc/ppp/peers/{{ intf }}.chat' + +""" + +# Please be careful if you edit the template. +chat_wwan_tmpl = """ +ABORT 'NO DIAL TONE' ABORT 'NO ANSWER' ABORT 'NO CARRIER' ABORT DELAYED +'' AT +OK ATZ +OK 'AT+CGDCONT=1,"IP","{{ apn }}"' +OK ATD*99# +CONNECT '' """ default_config_data = { 'address': [], + 'apn': '', 'deleted': False, 'description': '', 'device': 'ttyUSB0', @@ -71,7 +86,6 @@ default_config_data = { 'metric': '10', 'mtu': '1500', 'name_server': True, - 'network': 'att', 'intf': '' } @@ -105,6 +119,10 @@ def get_config(): # set new configuration level conf.set_level('interfaces wirelessmodem ' + wwan['intf']) + # get metrick for backup default route + if conf.exists(['apn']): + wwan['apn'] = conf.return_value(['apn']) + # get metrick for backup default route if conf.exists(['backup', 'distance']): wwan['metric'] = conf.return_value(['backup', 'distance']) @@ -117,6 +135,10 @@ def get_config(): if conf.exists(['device']): wwan['device'] = conf.return_value(['device']) + # disable interface + if conf.exists('disable'): + wwan['disable'] = True + # ignore link state changes if conf.exists('disable-link-detect'): wwan['disable_link_detect'] = 2 @@ -126,11 +148,7 @@ def get_config(): wwan['mtu'] = conf.return_value(['mtu']) # Do not use DNS servers provided by the peer - if conf.exists(['network']): - wwan['network'] = conf.return_value(['network']) - - # Do not use DNS servers provided by the peer - if conf.exists(['no-dns']): + if conf.exists(['no-peer-dns']): wwan['name_server'] = False # Access concentrator name (only connect to this concentrator) @@ -143,6 +161,9 @@ def verify(wwan): if wwan['deleted']: return None + if not wwan['apn']: + raise ConfigError(f"APN for {wwan['intf']} not configured") + # we can not use isfile() here as Linux device files are no regular files # thus the check will return False if not os.path.exists(f"/dev/{wwan['device']}"): @@ -152,6 +173,7 @@ def verify(wwan): def generate(wwan): config_file_wwan = f"/etc/ppp/peers/{wwan['intf']}" + chat_file_wwan = f"/etc/ppp/peers/{wwan['intf']}.chat" # Always hang-up WWAN connection prior generating new configuration file cmd = f"systemctl stop ppp@{wwan['intf']}.service" @@ -161,6 +183,8 @@ def generate(wwan): # Delete PPP configuration files if os.path.exists(config_file_wwan): os.unlink(config_file_wwan) + if os.path.exists(chat_file_wwan): + os.unlink(chat_file_wwan) else: # Create PPP configuration files @@ -169,6 +193,13 @@ def generate(wwan): with open(config_file_wwan, 'w') as f: f.write(config_text) + + # Create PPP chat script + tmpl = Template(chat_wwan_tmpl) + config_text = tmpl.render(wwan) + with open(chat_file_wwan, 'w') as f: + f.write(config_text) + return None def apply(wwan): diff --git a/src/migration-scripts/interfaces/6-to-7 b/src/migration-scripts/interfaces/6-to-7 new file mode 100755 index 000000000..b4f59c363 --- /dev/null +++ b/src/migration-scripts/interfaces/6-to-7 @@ -0,0 +1,63 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2020 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Remove network provider name from CLI and rather use provider APN from CLI + +import sys +from vyos.configtree import ConfigTree + +if __name__ == '__main__': + if (len(sys.argv) < 1): + print("Must specify file name!") + exit(1) + + file_name = sys.argv[1] + with open(file_name, 'r') as f: + config_file = f.read() + + config = ConfigTree(config_file) + base = ['interfaces', 'wirelessmodem'] + + if not config.exists(base): + # Nothing to do + sys.exit(0) + + # list all individual interface types like dummy, ethernet and so on + for i in config.list_nodes(base): + iface = base + [i] + + # only three carries have been supported in the past, thus + # this will be fairly simple \o/ - and only one (AT&T) did + # configure an APN + if config.exists(iface + ['network']): + network = config.return_value(iface + ['network']) + if network == "att": + apn = 'isp.cingular' + config.set(iface + ['apn'], value=apn) + + config.delete(iface + ['network']) + + # synchronize DNS configuration with PPPoE interfaces to have a + # uniform CLI experience + if config.exists(iface + ['no-dns']): + config.rename(iface + ['no-dns'], 'no-peer-dns') + + try: + with open(file_name, 'w') as f: + f.write(config.to_string()) + except OSError as e: + print("Failed to save the modified config: {}".format(e)) + sys.exit(1) -- cgit v1.2.3 From 2c6b33d3fcb88551d85c740288a916a1be76a8d3 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Sat, 28 Mar 2020 18:49:45 +0100 Subject: wwan: T1988: migrate operational mode commands --- .../show-interfaces-wirelessmodem.xml | 45 ++++++++++++++++++++++ src/completion/list_wlm_peers.sh | 6 +++ 2 files changed, 51 insertions(+) create mode 100644 op-mode-definitions/show-interfaces-wirelessmodem.xml create mode 100755 src/completion/list_wlm_peers.sh (limited to 'src') diff --git a/op-mode-definitions/show-interfaces-wirelessmodem.xml b/op-mode-definitions/show-interfaces-wirelessmodem.xml new file mode 100644 index 000000000..681f54f3d --- /dev/null +++ b/op-mode-definitions/show-interfaces-wirelessmodem.xml @@ -0,0 +1,45 @@ + + + + + + + + + Show Wireless Modem (WWAN) interface information + + + + + ${vyatta_bindir}/vyatta-show-interfaces.pl --intf="$4" + + + + Show PPPoE logs + + cat /var/log/vyatta/ppp_$4.log + + + + Watch PPPoE logs + + tail --follow=name /var/log/vyatta/ppp_$4.log + + + + + + Show specified wirelessmodem interface statistics + + + + + /usr/sbin/pppstats $4 + + + + + + + + diff --git a/src/completion/list_wlm_peers.sh b/src/completion/list_wlm_peers.sh new file mode 100755 index 000000000..12dd00650 --- /dev/null +++ b/src/completion/list_wlm_peers.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +if [ -d /etc/ppp/peers ]; then + cd /etc/ppp/peers + ls wlm* +fi -- cgit v1.2.3 From a7b74971e5f19a3d460bf6666cbae9702154aa43 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Sat, 28 Mar 2020 18:50:42 +0100 Subject: wwan: T1988: ppp: change order of debug and logfile options --- src/conf_mode/interfaces-wirelessmodem.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/conf_mode/interfaces-wirelessmodem.py b/src/conf_mode/interfaces-wirelessmodem.py index adb8bdc2d..14178d74c 100755 --- a/src/conf_mode/interfaces-wirelessmodem.py +++ b/src/conf_mode/interfaces-wirelessmodem.py @@ -44,11 +44,10 @@ demand {% if name_server -%} usepeerdns {%- endif %} -logfile {{ logfile }} - lcp-echo-failure 0 115200 debug +logfile {{ logfile }} nodefaultroute ipcp-max-failure 4 ipcp-accept-local @@ -58,7 +57,7 @@ crtscts lock persist -connect '/usr/sbin/chat -v -t6 -f /etc/ppp/peers/{{ intf }}.chat' +connect '/usr/sbin/chat -v -t6 -f {{ chat_script }}' """ @@ -76,6 +75,7 @@ CONNECT '' default_config_data = { 'address': [], 'apn': '', + 'chat_script': '', 'deleted': False, 'description': '', 'device': 'ttyUSB0', @@ -110,6 +110,7 @@ def get_config(): wwan['intf'] = os.environ['VYOS_TAGNODE_VALUE'] wwan['logfile'] = f"/var/log/vyatta/ppp_{wwan['intf']}.log" + wwan['chat_script'] = f"/etc/ppp/peers/chat.{wwan['intf']}" # Check if interface has been removed if not conf.exists('interfaces wirelessmodem ' + wwan['intf']): @@ -173,7 +174,6 @@ def verify(wwan): def generate(wwan): config_file_wwan = f"/etc/ppp/peers/{wwan['intf']}" - chat_file_wwan = f"/etc/ppp/peers/{wwan['intf']}.chat" # Always hang-up WWAN connection prior generating new configuration file cmd = f"systemctl stop ppp@{wwan['intf']}.service" @@ -183,8 +183,8 @@ def generate(wwan): # Delete PPP configuration files if os.path.exists(config_file_wwan): os.unlink(config_file_wwan) - if os.path.exists(chat_file_wwan): - os.unlink(chat_file_wwan) + if os.path.exists(wwan['chat_script']): + os.unlink(wwan['chat_script']) else: # Create PPP configuration files @@ -197,7 +197,7 @@ def generate(wwan): # Create PPP chat script tmpl = Template(chat_wwan_tmpl) config_text = tmpl.render(wwan) - with open(chat_file_wwan, 'w') as f: + with open(wwan['chat_script'], 'w') as f: f.write(config_text) return None -- cgit v1.2.3