summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/conf_mode/interfaces-wireless.py33
1 files changed, 29 insertions, 4 deletions
diff --git a/src/conf_mode/interfaces-wireless.py b/src/conf_mode/interfaces-wireless.py
index 19e1f01b8..40d8912cc 100755
--- a/src/conf_mode/interfaces-wireless.py
+++ b/src/conf_mode/interfaces-wireless.py
@@ -22,10 +22,12 @@ from sys import exit
from stat import S_IRWXU,S_IRGRP,S_IXGRP,S_IROTH,S_IXOTH
from pwd import getpwnam
from grp import getgrnam
+from re import findall
from subprocess import Popen, PIPE
from psutil import pid_exists
from netifaces import interfaces
+from netaddr import *
from vyos.ifconfig import EthernetIf
from vyos.ifconfig_vlan import apply_vlan_config, verify_vlan_config
@@ -1144,6 +1146,10 @@ def get_config():
if conf.exists('ip enable-arp-ignore'):
wifi['ip_enable_arp_ignore'] = 1
+ # Wireless physical device
+ if conf.exists('physical-device'):
+ wifi['phy'] = conf.return_value('physical-device')
+
# Media Access Control (MAC) address
if conf.exists('mac'):
wifi['mac'] = conf.return_value('mac')
@@ -1164,10 +1170,6 @@ def get_config():
if conf.exists('vrf'):
wifi['vrf'] = conf.return_value('vrf')
- # Wireless physical device
- if conf.exists('phy'):
- wifi['phy'] = conf.return_value('phy')
-
# Transmission power reduction in dBm
if conf.exists('reduce-transmit-power'):
wifi['reduce_transmit_power'] = conf.return_value('reduce-transmit-power')
@@ -1288,6 +1290,9 @@ def verify(wifi):
if wifi['type'] != 'monitor' and not wifi['ssid']:
raise ConfigError('SSID must be set for {}'.format(wifi['intf']))
+ if not wifi['phy']:
+ raise ConfigError('You must specify physical-device')
+
if wifi['type'] == 'access-point':
c = Config()
if not c.exists('system wifi-regulatory-domain'):
@@ -1326,6 +1331,26 @@ def verify(wifi):
return None
def generate(wifi):
+
+ if not wifi['mac']:
+ # http://wiki.stocksy.co.uk/wiki/Multiple_SSIDs_with_hostapd
+ # generate locally administered MAC address from used phy interface
+ with open('/sys/class/ieee80211/{}/addresses'.format(wifi['phy']), 'r') as f:
+ tmp = EUI(f.read().rstrip()).value
+ # mask last nibble from the MAC address
+ tmp &= 0xfffffffffff0
+ # set locally administered bit in MAC address
+ tmp |= 0x020000000000
+ # we now need to add an offset to our MAC address indicating this
+ # subinterfaces index
+ tmp += int(findall(r'\d+', wifi['intf'])[0])
+
+ # convert integer to "real" MAC address representation
+ mac = EUI(hex(tmp).split('x')[-1])
+ # change dialect to use : as delimiter instead of -
+ mac.dialect = mac_unix_expanded
+ wifi['mac'] = str(mac)
+
pid = 0
# always stop hostapd service first before reconfiguring it
pidfile = get_pid('hostapd', wifi['intf'])