Skip to content

Commit 9bceb18

Browse files
pandafynemesifier
andauthored
[feature] Added support for basic 802.11r options in OpenWRT #175
Closes #175 Co-authored-by: Federico Capoano <f.capoano@openwisp.io>
1 parent cfc388a commit 9bceb18

4 files changed

Lines changed: 195 additions & 15 deletions

File tree

docs/source/backends/openwrt.rst

Lines changed: 76 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -622,17 +622,29 @@ The ``OpenWrt`` backend NetJSON extensions for wireless interfaces:
622622

623623
Some extensions are applicable only when ``mode`` is ``access_point``:
624624

625-
+---------------+---------+-------------+------------------------------------------------------+
626-
| key name | type | default | allowed values |
627-
+===============+=========+=============+======================================================+
628-
| ``wmm`` | boolean | ``True`` | enables WMM (802.11e) support |
629-
+---------------+---------+-------------+------------------------------------------------------+
630-
| ``isolate`` | boolean | ``False`` | isolate wireless clients from one another |
631-
+---------------+---------+-------------+------------------------------------------------------+
632-
| ``macfilter`` | string | ``disable`` | ACL policy, accepts: "disable", "allow" and "deny" |
633-
+---------------+---------+-------------+------------------------------------------------------+
634-
| ``maclist`` | array | ``[]`` | mac addresses filtered according to macfilter policy |
635-
+---------------+---------+-------------+------------------------------------------------------+
625+
+----------------------------+---------+-------------+------------------------------------------------------+
626+
| key name | type | default | allowed values |
627+
+============================+=========+=============+======================================================+
628+
| ``wmm`` | boolean | ``True`` | enables WMM (802.11e) support |
629+
+----------------------------+---------+-------------+------------------------------------------------------+
630+
| ``ieee80211r`` | boolean | ``False`` | enables fast BSS transition (802.11r) support |
631+
+----------------------------+---------+-------------+------------------------------------------------------+
632+
| ``reassociation_deadline`` | integer | ``1000`` | reassociation deadline in time units |
633+
| | | | (TUs / 1.024 ms, 1000-65535) |
634+
+----------------------------+---------+-------------+------------------------------------------------------+
635+
| ``ft_psk_generate_local`` | boolean | ``False`` | whether to generate FT response locally |
636+
| | | | for PSK networks |
637+
+----------------------------+---------+-------------+------------------------------------------------------+
638+
| ``ft_over_ds`` | boolean | ``True`` | whether to enable FT-over-DS |
639+
+----------------------------+---------+-------------+------------------------------------------------------+
640+
| ``rsn_preauth`` | boolean | ``False`` | allow pre-authentication for WPA2-EAP networks |
641+
+----------------------------+---------+-------------+------------------------------------------------------+
642+
| ``isolate`` | boolean | ``False`` | isolate wireless clients from one another |
643+
+----------------------------+---------+-------------+------------------------------------------------------+
644+
| ``macfilter`` | string | ``disable`` | ACL policy, accepts: "disable", "allow" and "deny" |
645+
+----------------------------+---------+-------------+------------------------------------------------------+
646+
| ``maclist`` | array | ``[]`` | mac addresses filtered according to macfilter policy |
647+
+----------------------------+---------+-------------+------------------------------------------------------+
636648

637649
These extensions must be used the ``wireless`` object of a wireless interface eg:
638650

@@ -852,6 +864,59 @@ UCI output::
852864
option network 'wlan0'
853865
option ssid 'MyWifiAP'
854866

867+
Wireless access point with roaming (802.11r)
868+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
869+
870+
The ``OpenWrt`` backend supports custom NetJSON extensions to support
871+
(802.11r) in wireless access point interfaces (refer
872+
`"Fast BSS transition options" section in the OpenWRT documentation for Wireless configuration <https://openwrt.org/docs/guide-user/network/wifi/basic#fast_bss_transition_options_80211r>`_).
873+
874+
In the following example we configure roaming options for a wireless access point:
875+
876+
.. code-block:: python
877+
878+
{
879+
"interfaces": [
880+
{
881+
"name": "wlan0",
882+
"type": "wireless",
883+
"wireless": {
884+
"radio": "radio0",
885+
"mode": "access_point",
886+
"ssid": "MyWifiAP",
887+
"ieee80211r": True,
888+
"ft_over_ds": False,
889+
"ft_psk_generate_local": True,
890+
"rsn_preauth": True,
891+
"reassociation_deadline": 1000,
892+
"network": ["lan"]
893+
}
894+
}
895+
]
896+
}
897+
898+
UCI output::
899+
900+
package network
901+
902+
config interface 'wlan0'
903+
option ifname 'wlan0'
904+
option proto 'none'
905+
906+
package wireless
907+
908+
config wifi-iface 'wifi_wlan0'
909+
option device 'radio0'
910+
option ft_over_ds '0'
911+
option ft_psk_generate_local '1'
912+
option ieee80211r '1'
913+
option ifname 'wlan0'
914+
option mode 'ap'
915+
option network 'lan'
916+
option reassociation_deadline '1000'
917+
option rsn_preauth '1'
918+
option ssid 'MyWifiAP'
919+
855920
Wireless mesh (802.11s) example
856921
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
857922

netjsonconfig/backends/openwrt/converters/wireless.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,21 @@ def __netjson_wifi(self, wifi, interface):
168168
return wifi
169169

170170
def __netjson_wifi_typecast(self, wifi):
171-
if 'hidden' in wifi:
172-
wifi['hidden'] = wifi['hidden'] == '1'
173-
if 'wds' in wifi:
174-
wifi['wds'] = wifi['wds'] == '1'
171+
for attr in [
172+
'hidden',
173+
'wds',
174+
'ft_over_ds',
175+
'ft_psk_generate_local',
176+
'ieee80211r',
177+
'rsn_preauth',
178+
]:
179+
if attr in wifi:
180+
wifi[attr] = wifi[attr] == '1'
181+
if 'reassociation_deadline' in wifi:
182+
try:
183+
wifi['reassociation_deadline'] = int(wifi['reassociation_deadline'])
184+
except ValueError:
185+
del wifi['reassociation_deadline']
175186

176187
_encryption_keys = [
177188
'key',

netjsonconfig/backends/openwrt/schema.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,50 @@
7373
"format": "checkbox",
7474
"propertyOrder": 9,
7575
},
76+
"ieee80211r": {
77+
"type": "boolean",
78+
"title": "roaming",
79+
"description": "enables fast BSS transition (802.11r) support",
80+
"default": False,
81+
"format": "checkbox",
82+
"propertyOrder": 9,
83+
},
84+
"reassociation_deadline": {
85+
"type": "integer",
86+
"title": "reassociation deadline",
87+
"description": (
88+
"reassociation deadline in time units "
89+
"(TUs / 1.024 ms, 1000-65535)"
90+
),
91+
"default": 1000,
92+
"minimum": 1000,
93+
"maximum": 65535,
94+
"propertyOrder": 9,
95+
},
96+
"ft_psk_generate_local": {
97+
"type": "boolean",
98+
"title": "FT PSK generate local",
99+
"description": "whether to generate FT response locally for PSK networks",
100+
"default": False,
101+
"format": "checkbox",
102+
"propertyOrder": 9,
103+
},
104+
"ft_over_ds": {
105+
"type": "boolean",
106+
"title": "FT-over-DS",
107+
"description": "whether to enable FT-over-DS",
108+
"default": True,
109+
"format": "checkbox",
110+
"propertyOrder": 9,
111+
},
112+
"rsn_preauth": {
113+
"type": "boolean",
114+
"title": "WPA2-EAP pre-authentication",
115+
"description": "allow preauthentication for WPA2-EAP networks",
116+
"default": False,
117+
"format": "checkbox",
118+
"propertyOrder": 9,
119+
},
76120
"macfilter": {
77121
"type": "string",
78122
"title": "MAC Filter",

tests/openwrt/test_wireless.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import unittest
2+
from copy import deepcopy
23

34
from netjsonconfig import OpenWrt
45
from netjsonconfig.exceptions import ValidationError
@@ -732,6 +733,65 @@ def test_parse_wds_bridge(self):
732733
o = OpenWrt(native=self._wds_bridge_uci)
733734
self.assertEqual(o.config, self._wds_bridge_netjson)
734735

736+
_80211r_netjson = {
737+
"interfaces": [
738+
{
739+
"name": "wlan0",
740+
"type": "wireless",
741+
"wireless": {
742+
"radio": "radio0",
743+
"mode": "access_point",
744+
"ssid": "MyWifiAP",
745+
"ieee80211r": True,
746+
"ft_over_ds": False,
747+
"ft_psk_generate_local": True,
748+
"rsn_preauth": True,
749+
"reassociation_deadline": 1000,
750+
"network": ["lan"],
751+
},
752+
}
753+
]
754+
}
755+
_80211r_uci = """package network
756+
757+
config interface 'wlan0'
758+
option ifname 'wlan0'
759+
option proto 'none'
760+
761+
package wireless
762+
763+
config wifi-iface 'wifi_wlan0'
764+
option device 'radio0'
765+
option ft_over_ds '0'
766+
option ft_psk_generate_local '1'
767+
option ieee80211r '1'
768+
option ifname 'wlan0'
769+
option mode 'ap'
770+
option network 'lan'
771+
option reassociation_deadline '1000'
772+
option rsn_preauth '1'
773+
option ssid 'MyWifiAP'
774+
"""
775+
776+
def test_render_access_point_80211r(self):
777+
o = OpenWrt(self._80211r_netjson)
778+
expected = self._tabs(self._80211r_uci)
779+
self.assertEqual(o.render(), expected)
780+
781+
def test_parse_access_point_80211r(self):
782+
o = OpenWrt(native=self._80211r_uci)
783+
self.assertEqual(o.config, self._80211r_netjson)
784+
785+
with self.subTest('ignore bogus reassociation_deadline'):
786+
bogus_uci = self._80211r_uci
787+
bogus_uci = bogus_uci.replace(
788+
"reassociation_deadline '1000'", "reassociation_deadline 'bogus'"
789+
)
790+
o = OpenWrt(native=bogus_uci)
791+
netjson_80211r = deepcopy(self._80211r_netjson)
792+
del netjson_80211r['interfaces'][0]['wireless']['reassociation_deadline']
793+
self.assertEqual(o.config, netjson_80211r)
794+
735795
_80211s_netjson = {
736796
"interfaces": [
737797
{

0 commit comments

Comments
 (0)