From 28a9933fd9ea78ad79309adf9b85a1bf2b2e1397 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Wed, 13 Jul 2016 17:04:34 +0530 Subject: [PATCH] networks: Configure wireless BSSID, band, channel Select the frequency band (2.4 GHz vs. 5 GHz) is a prerequisite for selecting the channel. Channel selection is useful primarily as follow: - Restrict to a particular access point when multiple access points use the same SSID (AP name) but are available on different frequencies. - Configure for a particular ad-hoc mesh network. - Setup multiple access points from a single FreedomBox on multiple channels to maximize the throughput and number of simultaneous clients. Ability to specify a particular BSSID will help associate with a particular access point when multiple access points use the same SSID (AP name). This is also makes it slightly harder to trick clients into connection to a malicious device. Also configuring BATMAN-adv seems to require setting a particular BSSID. --- plinth/modules/networks/forms.py | 29 +++++++++++++++++++++++++++-- plinth/modules/networks/networks.py | 4 ++++ plinth/network.py | 8 ++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/plinth/modules/networks/forms.py b/plinth/modules/networks/forms.py index 0850c1fd4..6921249a7 100644 --- a/plinth/modules/networks/forms.py +++ b/plinth/modules/networks/forms.py @@ -188,8 +188,9 @@ class PPPoEForm(EthernetForm): class WifiForm(ConnectionForm): """Form to create/edit a Wi-Fi connection.""" - field_order = ['name', 'interface', 'zone', 'ssid', 'mode', 'auth_mode', - 'passphrase', 'ipv4_method', 'ipv4_address', 'ipv4_netmask', + field_order = ['name', 'interface', 'zone', 'ssid', 'mode', 'band', + 'channel', 'bssid', 'auth_mode', 'passphrase', + 'ipv4_method', 'ipv4_address', 'ipv4_netmask', 'ipv4_gateway', 'ipv4_dns', 'ipv4_second_dns'] ssid = forms.CharField( @@ -200,6 +201,27 @@ class WifiForm(ConnectionForm): choices=[('infrastructure', _('Infrastructure')), ('ap', _('Access Point')), ('adhoc', _('Ad-hoc'))]) + band = forms.ChoiceField( + label=_('Frequency Band'), + choices=[('auto', _('Automatic')), + ('a', _('A (5 GHz)')), + ('bg', _('B/G (2.4 GHz)'))]) + channel = forms.IntegerField( + label=_('Channel'), + help_text=_('Optional value. Wireless channel in the selected ' + 'frequency band to restrict to. Blank or 0 value means ' + 'automatic selection.'), + min_value=0, + max_value=255, + required=False) + bssid = forms.RegexField( + label=_('BSSID'), + help_text=_('Optional value. Unique identifier for the access point. ' + 'When connecting to an access point, connect only if the ' + 'BSSID of the access point matches the one provided. ' + 'Example: 00:11:22:aa:bb:cc.'), + regex=r'^([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}$', + required=False) auth_mode = forms.ChoiceField( label=_('Authentication Mode'), help_text=_('Select WPA if the wireless network is secured and \ @@ -224,6 +246,9 @@ requires clients to have the password to connect.'), settings['wireless'] = { 'ssid': self.cleaned_data['ssid'], 'mode': self.cleaned_data['mode'], + 'band': self.cleaned_data['band'], + 'channel': self.cleaned_data['channel'], + 'bssid': self.cleaned_data['bssid'], 'auth_mode': self.cleaned_data['auth_mode'], 'passphrase': self.cleaned_data['passphrase'], } diff --git a/plinth/modules/networks/networks.py b/plinth/modules/networks/networks.py index 1caaeaa5b..93b1d6753 100644 --- a/plinth/modules/networks/networks.py +++ b/plinth/modules/networks/networks.py @@ -164,6 +164,9 @@ def edit(request, uuid): settings_wireless = connection.get_setting_wireless() form_data['ssid'] = settings_wireless.get_ssid().get_data() form_data['mode'] = settings_wireless.get_mode() + form_data['band'] = settings_wireless.get_band() or 'auto' + form_data['channel'] = settings_wireless.get_channel() + form_data['bssid'] = settings_wireless.get_bssid() try: wifi_sec = connection.get_setting_wireless_security() if wifi_sec: @@ -328,6 +331,7 @@ def add_wifi(request, ssid=None, interface_name=None): 'zone': 'external', 'ssid': ssid, 'mode': 'infrastructure', + 'band': 'auto', 'auth_mode': 'wpa', 'ipv4_method': 'auto'} diff --git a/plinth/network.py b/plinth/network.py index 67e5f4491..ca0a66f81 100644 --- a/plinth/network.py +++ b/plinth/network.py @@ -383,6 +383,14 @@ def _update_wireless_settings(connection, wireless): ssid_gbytes = glib.Bytes.new(wireless['ssid'].encode()) settings.set_property(nm.SETTING_WIRELESS_SSID, ssid_gbytes) settings.set_property(nm.SETTING_WIRELESS_MODE, wireless['mode']) + band = wireless['band'] if wireless['band'] != 'auto' else None + settings.set_property(nm.SETTING_WIRELESS_BAND, band) + channel = wireless['channel'] + if wireless['band'] == 'auto' or not wireless['channel']: + channel = 0 + + settings.set_property(nm.SETTING_WIRELESS_CHANNEL, channel) + settings.set_property(nm.SETTING_WIRELESS_BSSID, wireless['bssid'] or None) # Wireless Security if wireless['auth_mode'] == 'wpa' and wireless['passphrase']: