Skip to content

Commit

Permalink
[openwrt] Radio driver now defaults to mac80211 #73
Browse files Browse the repository at this point in the history
Radio driver has a default value and is not required anymore.
  • Loading branch information
nemesifier committed May 23, 2017
1 parent 52486da commit 1043612
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
6 changes: 3 additions & 3 deletions netjsonconfig/backends/openwrt/renderers.py
Expand Up @@ -6,6 +6,7 @@
from ..base import BaseRenderer
from ..openvpn.renderers import OpenVpnRenderer as BaseOpenVpnRenderer
from .timezones import timezones
from .schema import default_radio_driver


def logical_name(name):
Expand Down Expand Up @@ -302,16 +303,15 @@ def _get_radios(self):
uci_radio['txpower'] = radio['tx_power']
del uci_radio['tx_power']
# rename driver to type
uci_radio['type'] = radio['driver']
del uci_radio['driver']
uci_radio['type'] = uci_radio.pop('driver', default_radio_driver)
# determine hwmode option
uci_radio['hwmode'] = self.__get_hwmode(radio)
del uci_radio['protocol']
# check if using channel 0, that means "auto"
if uci_radio['channel'] is 0:
uci_radio['channel'] = 'auto'
# determine channel width
if radio['driver'] == 'mac80211':
if uci_radio['type'] == 'mac80211':
uci_radio['htmode'] = self.__get_htmode(radio)
del uci_radio['channel_width']
# ensure country is uppercase
Expand Down
4 changes: 3 additions & 1 deletion netjsonconfig/backends/openwrt/schema.py
Expand Up @@ -7,6 +7,8 @@
from ..openvpn.schema import base_openvpn_schema
from .timezones import timezones

default_radio_driver = "mac80211"

schema = merge_config(default_schema, {
"definitions": {
"interface_settings": {
Expand Down Expand Up @@ -113,7 +115,6 @@
]
},
"base_radio_settings": {
"required": ["driver"],
"properties": {
"driver": {
"type": "string",
Expand All @@ -124,6 +125,7 @@
"ath9k",
"broadcom"
],
"default": default_radio_driver,
"propertyOrder": 2,
}
}
Expand Down
29 changes: 29 additions & 0 deletions tests/openwrt/test_radio.py
Expand Up @@ -380,5 +380,34 @@ def test_htmode_override(self):
option hwmode '11a'
option phy 'phy0'
option type 'mac80211'
""")
self.assertEqual(o.render(), expected)

def test_default_driver(self):
o = OpenWrt({
"radios": [
{
"name": "radio0",
"protocol": "802.11ac",
"channel": 1,
"channel_width": 80,
"phy": "phy0",
"country": "US",
"tx_power": 10,
"disabled": False,
}
]
})
expected = self._tabs("""package wireless
config wifi-device 'radio0'
option channel '1'
option country 'US'
option disabled '0'
option htmode 'VHT80'
option hwmode '11g'
option phy 'phy0'
option txpower '10'
option type 'mac80211'
""")
self.assertEqual(o.render(), expected)

0 comments on commit 1043612

Please sign in to comment.