+ local macaddr = cursor:get("wireless", device, "macaddr") or "!"
+ local hwmode = cursor:get("wireless", device, "hwmode")
+ local modes = {}
+ local phy
+ local allowed = {}
+ for entry in fs.glob("/sys/class/ieee80211/*") do
+ if (fs.readfile(entry .. "/macaddress") or ""):find(macaddr) == 1 then
+ phy = entry:sub(22)
+ end
+ end
+ if phy then
+ local iwp = io.popen("iw phy " .. phy .. " info")
+ local iwin = iwp:read("*a")
+
+ if iwp then
+ iwp:close()
+ local htcap = iwin:match("HT capabilities:%s*0x([0-9a-fA-F]+)")
+ allowed.n = (htcap and tonumber(htcap, 16) or 0) > 0
+ allowed.g = iwin:find("2412 MHz")
+ allowed.a = iwin:find("5180 MHz")
+ end
+ end
+
+ if next(allowed) then
+ mode = s:taboption("expert", ListValue, "hwmode", translate("Communication Protocol"))
+ if allowed.n and allowed.g then
+ mode:value("11ng", "802.11n (2.4 GHz)")
+ end
+ if allowed.n and allowed.a then
+ mode:value("11na", "802.11n (5 GHz)")
+ end
+ if allowed.a then
+ mode:value("11a", "802.11a (5 GHz)")
+ end
+ if allowed.g then
+ mode:value("11g", "802.11g (2.4 GHz)")
+ mode:value("11bg", "802.11b+g (2.4 GHz)")
+ mode:value("11b", "802.11b (2.4 GHz)")
+ end
+ end
+