From 6ff94aca3573913f957bf31b9042d143e46d57e1 Mon Sep 17 00:00:00 2001
From: kb-light <freifunk@kb-light.de>
Date: Wed, 3 Aug 2016 11:02:20 +0200
Subject: [PATCH] gluon-core: make wifi rates configurable by site.conf

and add documentation
---
 docs/site-example/site.conf                          |  8 ++++++++
 docs/user/site.rst                                   |  8 ++++++++
 package/gluon-core/check_site.lua                    |  8 ++++++++
 .../gluon-core/luasrc/lib/gluon/upgrade/200-wireless | 12 ++++++++++++
 4 files changed, 36 insertions(+)

diff --git a/docs/site-example/site.conf b/docs/site-example/site.conf
index 45719b940..964324df7 100644
--- a/docs/site-example/site.conf
+++ b/docs/site-example/site.conf
@@ -35,6 +35,14 @@
     -- Wireless channel.
     channel = 1,
 
+    -- List of supported wifi rates (optional)
+    -- Example removes 802.11b compatibility for better performance
+    supported_rates = {6000, 9000, 12000, 18000, 24000, 36000, 48000, 54000},
+
+    -- List of basic wifi rates (optional, required if supported_rates is set)
+    -- Example removes 802.11b compatibility for better performance
+    basic_rate = {6000, 9000, 18000, 36000, 54000},
+
     -- ESSID used for client network.
     ap = {
       ssid = 'entenhausen.freifunk.net',
diff --git a/docs/user/site.rst b/docs/user/site.rst
index 20919a65f..616a074d8 100644
--- a/docs/user/site.rst
+++ b/docs/user/site.rst
@@ -98,6 +98,12 @@ wifi24 \: optional
     This will only affect new installations.
     Upgrades will not changed the disabled state.
 
+    Additionally it is possible to configure the ``supported_rates`` and ``basic_rate``
+    of each radio. Both are optional, by default hostapd/driver dictate the rates.
+    If ``supported_rates`` is set, ``basic_rate`` is required, because ``basic_rate``
+    has to be a subset of ``supported_rates``.
+    The example below disables 802.11b rates.
+
     ``ap`` requires a single parameter, a string, named ``ssid`` which sets the
     interface's ESSID.
 
@@ -112,6 +118,8 @@ wifi24 \: optional
 
        wifi24 = {
          channel = 11,
+         supported_rates = {6000, 9000, 12000, 18000, 24000, 36000, 48000, 54000},
+         basic_rate = {6000, 9000, 18000, 36000, 54000},
          ap = {
            ssid = 'entenhausen.freifunk.net',
          },
diff --git a/package/gluon-core/check_site.lua b/package/gluon-core/check_site.lua
index 1c81371e0..3586149ec 100644
--- a/package/gluon-core/check_site.lua
+++ b/package/gluon-core/check_site.lua
@@ -28,6 +28,14 @@ for _, config in ipairs({'wifi24', 'wifi5'}) do
     need_string('regdom') -- regdom is only required when wifi24 or wifi5 is configured
 
     need_number(config .. '.channel')
+
+    local rates = {1000, 2000, 5500, 6000, 9000, 11000, 12000, 18000, 24000, 36000, 48000, 54000}
+    local supported_rates = need_array_of(config .. '.supported_rates', rates, false)
+    if supported_rates then
+      need_array_of(config .. '.basic_rate', supported_rates, true)
+    else
+      need_array_of(config .. '.basic_rate', rates, false)
+    end
   end
 end
 
diff --git a/package/gluon-core/luasrc/lib/gluon/upgrade/200-wireless b/package/gluon-core/luasrc/lib/gluon/upgrade/200-wireless
index 5a4ec0a47..2760fae79 100755
--- a/package/gluon-core/luasrc/lib/gluon/upgrade/200-wireless
+++ b/package/gluon-core/luasrc/lib/gluon/upgrade/200-wireless
@@ -27,6 +27,18 @@ local function configure_radio(radio, index, config)
     uci:set('wireless', radio, 'channel', channel)
     uci:set('wireless', radio, 'htmode', 'HT20')
     uci:set('wireless', radio, 'country', site.regdom)
+
+    if config.supported_rates then
+      uci:set_list('wireless', radio, 'supported_rates', config.supported_rates)
+    else
+      uci:delete('wireless', radio, 'supported_rates')
+    end
+
+    if config.basic_rate then
+      uci:set_list('wireless', radio, 'basic_rate', config.basic_rate)
+    else
+      uci:delete('wireless', radio, 'basic_rate')
+    end
   end
 end
 
-- 
GitLab