Skip to content

Commit

Permalink
[openwrt] Add support for WPA2/WPA3-Personal-mixed
Browse files Browse the repository at this point in the history
This patch is tested on these.
- OpenWrt: latest (4b587f25614f3f7215360f96807ce760fa4ef3aa)
- hardware: TP-Link Archer C6 v2

Signed-off-by: Masashi Honma <masashi.honma@gmail.com>
  • Loading branch information
masap committed Jan 4, 2022
1 parent cc2a887 commit c9f714c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 4 deletions.
10 changes: 7 additions & 3 deletions netjsonconfig/backends/openwrt/converters/wireless.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def __intermediate_encryption(self, wireless):
'wpa2_personal': 'psk2',
'wpa3_personal': 'sae',
'wpa_personal_mixed': 'psk-mixed',
'wpa2_personal_mixed': 'sae-mixed',
'wpa_enterprise': 'wpa',
'wpa2_enterprise': 'wpa2',
'wpa_enterprise_mixed': 'wpa-mixed',
Expand Down Expand Up @@ -111,10 +112,12 @@ def __intermediate_encryption(self, wireless):
uci['key'] = encryption['key']
# add ciphers
cipher = encryption.get('cipher')
if protocol == 'wpa3_personal':
if protocol == 'wpa3_personal' or protocol == 'wpa2_personal_mixed':
cipher = 'auto'
if 'ieee80211w' not in uci or uci['ieee80211w'] == '0':
uci['ieee80211w'] = '1'
if protocol == 'wpa3_personal' and (
'ieee80211w' not in uci or uci['ieee80211w'] == '0'
):
uci['ieee80211w'] = '1'
if cipher and protocol.startswith('wpa') and cipher != 'auto':
uci['encryption'] += '+{0}'.format(cipher)
return uci
Expand Down Expand Up @@ -239,6 +242,7 @@ def __netjson_encryption(self, wifi):
'psk2': 'wpa2_personal',
'sae': 'wpa3_personal',
'psk-mixed': 'wpa_personal_mixed',
'sae-mixed': 'wpa2_personal_mixed',
'wpa': 'wpa_enterprise',
'wpa2': 'wpa2_enterprise',
'wpa-mixed': 'wpa_enterprise_mixed',
Expand Down
4 changes: 3 additions & 1 deletion netjsonconfig/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,14 +465,16 @@
"enum": [
"wpa3_personal",
"wpa2_personal",
"wpa2_personal_mixed",
"wpa_personal_mixed",
"wpa_personal",
],
"options": {
"enum_titles": [
"WPA3 Personal",
"WPA2 Personal",
"WPA Personal Mixed Mode",
"WPA2/WPA3 Personal Mixed Mode",
"WPA/WPA2 Personal Mixed Mode",
"WPA Personal",
]
},
Expand Down
45 changes: 45 additions & 0 deletions tests/openwrt/test_encryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,51 @@ def test_parse_wpa3_personal(self):
o = OpenWrt(native=self._wpa3_personal_uci)
self.assertEqual(o.config, self._wpa3_personal_netjson)

_wpa2_personal_mixed_netjson = {
"interfaces": [
{
"name": "wlan0",
"type": "wireless",
"wireless": {
"radio": "radio0",
"mode": "access_point",
"ssid": "wpa2-3-personal-mixed",
"encryption": {
"protocol": "wpa2_personal_mixed",
"cipher": "auto",
"key": "passphrase012345",
},
},
}
]
}
_wpa2_personal_mixed_uci = """package network
config interface 'wlan0'
option ifname 'wlan0'
option proto 'none'
package wireless
config wifi-iface 'wifi_wlan0'
option device 'radio0'
option encryption 'sae-mixed'
option ifname 'wlan0'
option key 'passphrase012345'
option mode 'ap'
option network 'wlan0'
option ssid 'wpa2-3-personal-mixed'
"""

def test_render_wpa2_personal_mixed(self):
o = OpenWrt(self._wpa2_personal_mixed_netjson)
expected = self._tabs(self._wpa2_personal_mixed_uci)
self.assertEqual(o.render(), expected)

def test_parse_wpa2_personal_mixed(self):
o = OpenWrt(native=self._wpa2_personal_mixed_uci)
self.assertEqual(o.config, self._wpa2_personal_mixed_netjson)

_wpa2_personal_netjson = {
"interfaces": [
{
Expand Down

0 comments on commit c9f714c

Please sign in to comment.