summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--debian/control1
-rw-r--r--interface-definitions/interfaces-wirelessmodem.xml.in75
-rwxr-xr-xsrc/conf_mode/interfaces-wirelessmodem.py192
-rw-r--r--src/etc/ppp/peers/chat/att6
-rw-r--r--src/etc/ppp/peers/chat/sc113
-rw-r--r--src/etc/ppp/peers/chat/verizon5
6 files changed, 292 insertions, 0 deletions
diff --git a/debian/control b/debian/control
index 366e8df94..bccfc02d4 100644
--- a/debian/control
+++ b/debian/control
@@ -79,6 +79,7 @@ Depends: python3,
frr,
radvd,
dbus,
+ usb-modeswitch,
hostapd (>= 0.6.8),
wpasupplicant (>= 0.6.7),
iw,
diff --git a/interface-definitions/interfaces-wirelessmodem.xml.in b/interface-definitions/interfaces-wirelessmodem.xml.in
new file mode 100644
index 000000000..e8946fa68
--- /dev/null
+++ b/interface-definitions/interfaces-wirelessmodem.xml.in
@@ -0,0 +1,75 @@
+<?xml version="1.0"?>
+<interfaceDefinition>
+ <node name="interfaces">
+ <children>
+ <tagNode name="wirelessmodem" owner="${vyos_conf_scripts_dir}/interfaces-wirelessmodem.py">
+ <properties>
+ <help>Wireless Modem (WWAN) Interface</help>
+ <priority>350</priority>
+ <constraint>
+ <regex>wlm[0-9]+$</regex>
+ </constraint>
+ <constraintErrorMessage>Wireless Modem interface must be named wlmN</constraintErrorMessage>
+ <valueHelp>
+ <format>wlmN</format>
+ <description>Wireless modem interface name</description>
+ </valueHelp>
+ </properties>
+ <children>
+ <node name="backup">
+ <properties>
+ <help>Insert backup default route</help>
+ </properties>
+ <children>
+ <leafNode name="distance">
+ <properties>
+ <help>Distance backup default route</help>
+ <valueHelp>
+ <format>1-255</format>
+ <description>Distance of the backup route (default: 10) </description>
+ </valueHelp>
+ <constraint>
+ <validator name="numeric" argument="--range 1-255"/>
+ </constraint>
+ <constraintErrorMessage>Must be between (1-255)</constraintErrorMessage>
+ </properties>
+ </leafNode>
+ </children>
+ </node>
+ #include <include/interface-description.xml.i>
+ <leafNode name="device">
+ <properties>
+ <help>System device name (default: ttyUSB0)</help>
+ <valueHelp>
+ <format>&gt;ttyXXX%lt;</format>
+ <description>System TTY device name</description>
+ </valueHelp>
+ </properties>
+ </leafNode>
+ #include <include/interface-disable-link-detect.xml.i>
+ #include <include/interface-mtu-68-9000.xml.i>
+ <leafNode name="network">
+ <properties>
+ <help>Carrier network to define dial strings</help>
+ <completionHelp>
+ <script>ls /etc/ppp/peers/chat</script>
+ </completionHelp>
+ </properties>
+ </leafNode>
+ <leafNode name="no-dns">
+ <properties>
+ <help>Do not use peer supplied DNS server information</help>
+ <valueless/>
+ </properties>
+ </leafNode>
+ <leafNode name="ondemand">
+ <properties>
+ <help>Only dial when traffic is available</help>
+ <valueless/>
+ </properties>
+ </leafNode>
+ </children>
+ </tagNode>
+ </children>
+ </node>
+</interfaceDefinition>
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 <http://www.gnu.org/licenses/>.
+
+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