summaryrefslogtreecommitdiff
path: root/src/conf_mode/interfaces-wirelessmodem.py
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-03-19 20:04:53 +0100
committerChristian Poessinger <christian@poessinger.com>2020-03-28 20:48:32 +0100
commit65f0c6bf68f4f903d8011d0083385aa0f3c280ce (patch)
tree25c9025e9c5fb2bad314d20795427dbed45babf6 /src/conf_mode/interfaces-wirelessmodem.py
parentced45949bc282d23b0767f698f31b580602f0c9c (diff)
downloadvyos-1x-65f0c6bf68f4f903d8011d0083385aa0f3c280ce.tar.gz
vyos-1x-65f0c6bf68f4f903d8011d0083385aa0f3c280ce.zip
wwan: T1988: support interface disable
Diffstat (limited to 'src/conf_mode/interfaces-wirelessmodem.py')
-rwxr-xr-xsrc/conf_mode/interfaces-wirelessmodem.py45
1 files changed, 38 insertions, 7 deletions
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': ''
}
@@ -106,6 +120,10 @@ def get_config():
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):