wifi.lua 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946
  1. -- Copyright 2008 Steven Barth <steven@midlink.org>
  2. -- Licensed to the public under the Apache License 2.0.
  3. local wa = require "luci.tools.webadmin"
  4. local nw = require "luci.model.network"
  5. local ut = require "luci.util"
  6. local nt = require "luci.sys".net
  7. local fs = require "nixio.fs"
  8. arg[1] = arg[1] or ""
  9. m = Map("wireless", "",
  10. translate("The <em>Device Configuration</em> section covers physical settings of the radio " ..
  11. "hardware such as channel, transmit power or antenna selection which are shared among all " ..
  12. "defined wireless networks (if the radio hardware is multi-SSID capable). Per network settings " ..
  13. "like encryption or operation mode are grouped in the <em>Interface Configuration</em>."))
  14. m:chain("network")
  15. m:chain("firewall")
  16. m.redirect = luci.dispatcher.build_url("admin/network/wireless")
  17. local ifsection
  18. function m.on_commit(map)
  19. local wnet = nw:get_wifinet(arg[1])
  20. if ifsection and wnet then
  21. ifsection.section = wnet.sid
  22. m.title = luci.util.pcdata(wnet:get_i18n())
  23. end
  24. end
  25. nw.init(m.uci)
  26. local wnet = nw:get_wifinet(arg[1])
  27. local wdev = wnet and wnet:get_device()
  28. -- redirect to overview page if network does not exist anymore (e.g. after a revert)
  29. if not wnet or not wdev then
  30. luci.http.redirect(luci.dispatcher.build_url("admin/network/wireless"))
  31. return
  32. end
  33. -- wireless toggle was requested, commit and reload page
  34. function m.parse(map)
  35. if m:formvalue("cbid.wireless.%s.__toggle" % wdev:name()) then
  36. if wdev:get("disabled") == "1" or wnet:get("disabled") == "1" then
  37. wnet:set("disabled", nil)
  38. else
  39. wnet:set("disabled", "1")
  40. end
  41. wdev:set("disabled", nil)
  42. nw:commit("wireless")
  43. luci.sys.call("(env -i /bin/ubus call network reload) >/dev/null 2>/dev/null")
  44. luci.http.redirect(luci.dispatcher.build_url("admin/network/wireless", arg[1]))
  45. return
  46. end
  47. Map.parse(map)
  48. end
  49. m.title = luci.util.pcdata(wnet:get_i18n())
  50. local function txpower_list(iw)
  51. local list = iw.txpwrlist or { }
  52. local off = tonumber(iw.txpower_offset) or 0
  53. local new = { }
  54. local prev = -1
  55. local _, val
  56. for _, val in ipairs(list) do
  57. local dbm = val.dbm + off
  58. local mw = math.floor(10 ^ (dbm / 10))
  59. if mw ~= prev then
  60. prev = mw
  61. new[#new+1] = {
  62. display_dbm = dbm,
  63. display_mw = mw,
  64. driver_dbm = val.dbm,
  65. driver_mw = val.mw
  66. }
  67. end
  68. end
  69. return new
  70. end
  71. local function txpower_current(pwr, list)
  72. pwr = tonumber(pwr)
  73. if pwr ~= nil then
  74. local _, item
  75. for _, item in ipairs(list) do
  76. if item.driver_dbm >= pwr then
  77. return item.driver_dbm
  78. end
  79. end
  80. end
  81. return (list[#list] and list[#list].driver_dbm) or pwr or 0
  82. end
  83. local iw = luci.sys.wifi.getiwinfo(arg[1])
  84. local hw_modes = iw.hwmodelist or { }
  85. local tx_power_list = txpower_list(iw)
  86. local tx_power_cur = txpower_current(wdev:get("txpower"), tx_power_list)
  87. s = m:section(NamedSection, wdev:name(), "wifi-device", translate("Device Configuration"))
  88. s.addremove = false
  89. s:tab("general", translate("General Setup"))
  90. s:tab("macfilter", translate("MAC-Filter"))
  91. s:tab("advanced", translate("Advanced Settings"))
  92. --[[
  93. back = s:option(DummyValue, "_overview", translate("Overview"))
  94. back.value = ""
  95. back.titleref = luci.dispatcher.build_url("admin", "network", "wireless")
  96. ]]
  97. st = s:taboption("general", DummyValue, "__status", translate("Status"))
  98. st.template = "admin_network/wifi_status"
  99. st.ifname = arg[1]
  100. en = s:taboption("general", Button, "__toggle")
  101. if wdev:get("disabled") == "1" or wnet:get("disabled") == "1" then
  102. en.title = translate("Wireless network is disabled")
  103. en.inputtitle = translate("Enable")
  104. en.inputstyle = "apply"
  105. else
  106. en.title = translate("Wireless network is enabled")
  107. en.inputtitle = translate("Disable")
  108. en.inputstyle = "reset"
  109. end
  110. local hwtype = wdev:get("type")
  111. -- NanoFoo
  112. local nsantenna = wdev:get("antenna")
  113. -- Check whether there are client interfaces on the same radio,
  114. -- if yes, lock the channel choice as these stations will dicatate the freq
  115. local found_sta = nil
  116. local _, net
  117. if wnet:mode() ~= "sta" then
  118. for _, net in ipairs(wdev:get_wifinets()) do
  119. if net:mode() == "sta" and net:get("disabled") ~= "1" then
  120. if not found_sta then
  121. found_sta = {}
  122. found_sta.channel = net:channel()
  123. found_sta.names = {}
  124. end
  125. found_sta.names[#found_sta.names+1] = net:shortname()
  126. end
  127. end
  128. end
  129. if found_sta then
  130. ch = s:taboption("general", DummyValue, "choice", translate("Channel"))
  131. ch.value = translatef("Locked to channel %d used by: %s",
  132. found_sta.channel, table.concat(found_sta.names, ", "))
  133. else
  134. ch = s:taboption("general", Value, "_mode_freq", '<br />'..translate("Operating frequency"))
  135. ch.hwmodes = iw.hwmodelist
  136. ch.freqlist = iw.freqlist
  137. ch.template = "cbi/wireless_modefreq"
  138. function ch.cfgvalue(self, section)
  139. return {
  140. m:get(section, "hwmode") or "",
  141. m:get(section, "channel") or "auto",
  142. m:get(section, "htmode") or ""
  143. }
  144. end
  145. function ch.formvalue(self, section)
  146. return {
  147. m:formvalue(self:cbid(section) .. ".band") or (iw.hwmodelist.g and "11g" or "11a"),
  148. m:formvalue(self:cbid(section) .. ".channel") or "auto",
  149. m:formvalue(self:cbid(section) .. ".htmode") or ""
  150. }
  151. end
  152. function ch.write(self, section, value)
  153. m:set(section, "hwmode", value[1])
  154. m:set(section, "channel", value[2])
  155. m:set(section, "htmode", value[3])
  156. end
  157. end
  158. ------------------- MAC80211 Device ------------------
  159. if hwtype == "mac80211" then
  160. if #tx_power_list > 1 then
  161. tp = s:taboption("general", ListValue,
  162. "txpower", translate("Transmit Power"), "dBm")
  163. tp.rmempty = true
  164. tp.default = tx_power_cur
  165. function tp.cfgvalue(...)
  166. return txpower_current(Value.cfgvalue(...), tx_power_list)
  167. end
  168. for _, p in ipairs(tx_power_list) do
  169. tp:value(p.driver_dbm, "%i dBm (%i mW)"
  170. %{ p.display_dbm, p.display_mw })
  171. end
  172. end
  173. local cl = iw and iw.countrylist
  174. if cl and #cl > 0 then
  175. cc = s:taboption("advanced", ListValue, "country", translate("Country Code"), translate("Use ISO/IEC 3166 alpha2 country codes."))
  176. cc.default = tostring(iw and iw.country or "00")
  177. for _, c in ipairs(cl) do
  178. cc:value(c.alpha2, "%s - %s" %{ c.alpha2, c.name })
  179. end
  180. else
  181. s:taboption("advanced", Value, "country", translate("Country Code"), translate("Use ISO/IEC 3166 alpha2 country codes."))
  182. end
  183. s:taboption("advanced", Value, "distance", translate("Distance Optimization"),
  184. translate("Distance to farthest network member in meters."))
  185. -- external antenna profiles
  186. local eal = iw and iw.extant
  187. if eal and #eal > 0 then
  188. ea = s:taboption("advanced", ListValue, "extant", translate("Antenna Configuration"))
  189. for _, eap in ipairs(eal) do
  190. ea:value(eap.id, "%s (%s)" %{ eap.name, eap.description })
  191. if eap.selected then
  192. ea.default = eap.id
  193. end
  194. end
  195. end
  196. s:taboption("advanced", Value, "frag", translate("Fragmentation Threshold"))
  197. s:taboption("advanced", Value, "rts", translate("RTS/CTS Threshold"))
  198. end
  199. ------------------- Madwifi Device ------------------
  200. if hwtype == "atheros" then
  201. tp = s:taboption("general",
  202. (#tx_power_list > 0) and ListValue or Value,
  203. "txpower", translate("Transmit Power"), "dBm")
  204. tp.rmempty = true
  205. tp.default = tx_power_cur
  206. function tp.cfgvalue(...)
  207. return txpower_current(Value.cfgvalue(...), tx_power_list)
  208. end
  209. for _, p in ipairs(tx_power_list) do
  210. tp:value(p.driver_dbm, "%i dBm (%i mW)"
  211. %{ p.display_dbm, p.display_mw })
  212. end
  213. s:taboption("advanced", Flag, "diversity", translate("Diversity")).rmempty = false
  214. if not nsantenna then
  215. ant1 = s:taboption("advanced", ListValue, "txantenna", translate("Transmitter Antenna"))
  216. ant1.widget = "radio"
  217. ant1.orientation = "horizontal"
  218. ant1:depends("diversity", "")
  219. ant1:value("0", translate("auto"))
  220. ant1:value("1", translate("Antenna 1"))
  221. ant1:value("2", translate("Antenna 2"))
  222. ant2 = s:taboption("advanced", ListValue, "rxantenna", translate("Receiver Antenna"))
  223. ant2.widget = "radio"
  224. ant2.orientation = "horizontal"
  225. ant2:depends("diversity", "")
  226. ant2:value("0", translate("auto"))
  227. ant2:value("1", translate("Antenna 1"))
  228. ant2:value("2", translate("Antenna 2"))
  229. else -- NanoFoo
  230. local ant = s:taboption("advanced", ListValue, "antenna", translate("Transmitter Antenna"))
  231. ant:value("auto")
  232. ant:value("vertical")
  233. ant:value("horizontal")
  234. ant:value("external")
  235. end
  236. s:taboption("advanced", Value, "distance", translate("Distance Optimization"),
  237. translate("Distance to farthest network member in meters."))
  238. s:taboption("advanced", Value, "regdomain", translate("Regulatory Domain"))
  239. s:taboption("advanced", Value, "country", translate("Country Code"))
  240. s:taboption("advanced", Flag, "outdoor", translate("Outdoor Channels"))
  241. --s:option(Flag, "nosbeacon", translate("Disable HW-Beacon timer"))
  242. end
  243. ------------------- Broadcom Device ------------------
  244. if hwtype == "broadcom" then
  245. tp = s:taboption("general",
  246. (#tx_power_list > 0) and ListValue or Value,
  247. "txpower", translate("Transmit Power"), "dBm")
  248. tp.rmempty = true
  249. tp.default = tx_power_cur
  250. function tp.cfgvalue(...)
  251. return txpower_current(Value.cfgvalue(...), tx_power_list)
  252. end
  253. for _, p in ipairs(tx_power_list) do
  254. tp:value(p.driver_dbm, "%i dBm (%i mW)"
  255. %{ p.display_dbm, p.display_mw })
  256. end
  257. ant1 = s:taboption("advanced", ListValue, "txantenna", translate("Transmitter Antenna"))
  258. ant1.widget = "radio"
  259. ant1:depends("diversity", "")
  260. ant1:value("3", translate("auto"))
  261. ant1:value("0", translate("Antenna 1"))
  262. ant1:value("1", translate("Antenna 2"))
  263. ant2 = s:taboption("advanced", ListValue, "rxantenna", translate("Receiver Antenna"))
  264. ant2.widget = "radio"
  265. ant2:depends("diversity", "")
  266. ant2:value("3", translate("auto"))
  267. ant2:value("0", translate("Antenna 1"))
  268. ant2:value("1", translate("Antenna 2"))
  269. s:taboption("advanced", Flag, "frameburst", translate("Frame Bursting"))
  270. s:taboption("advanced", Value, "distance", translate("Distance Optimization"))
  271. --s:option(Value, "slottime", translate("Slot time"))
  272. s:taboption("advanced", Value, "country", translate("Country Code"))
  273. s:taboption("advanced", Value, "maxassoc", translate("Connection Limit"))
  274. end
  275. --------------------- HostAP Device ---------------------
  276. if hwtype == "prism2" then
  277. s:taboption("advanced", Value, "txpower", translate("Transmit Power"), "att units").rmempty = true
  278. s:taboption("advanced", Flag, "diversity", translate("Diversity")).rmempty = false
  279. s:taboption("advanced", Value, "txantenna", translate("Transmitter Antenna"))
  280. s:taboption("advanced", Value, "rxantenna", translate("Receiver Antenna"))
  281. end
  282. ----------------------- Interface -----------------------
  283. s = m:section(NamedSection, wnet.sid, "wifi-iface", translate("Interface Configuration"))
  284. ifsection = s
  285. s.addremove = false
  286. s.anonymous = true
  287. s.defaults.device = wdev:name()
  288. s:tab("general", translate("General Setup"))
  289. s:tab("encryption", translate("Wireless Security"))
  290. s:tab("macfilter", translate("MAC-Filter"))
  291. s:tab("advanced", translate("Advanced Settings"))
  292. s:taboption("general", Value, "ssid", translate("<abbr title=\"Extended Service Set Identifier\">ESSID</abbr>"))
  293. mode = s:taboption("general", ListValue, "mode", translate("Mode"))
  294. mode.override_values = true
  295. mode:value("ap", translate("Access Point"))
  296. mode:value("sta", translate("Client"))
  297. mode:value("adhoc", translate("Ad-Hoc"))
  298. bssid = s:taboption("general", Value, "bssid", translate("<abbr title=\"Basic Service Set Identifier\">BSSID</abbr>"))
  299. network = s:taboption("general", Value, "network", translate("Network"),
  300. translate("Choose the network(s) you want to attach to this wireless interface or " ..
  301. "fill out the <em>create</em> field to define a new network."))
  302. network.rmempty = true
  303. network.template = "cbi/network_netlist"
  304. network.widget = "checkbox"
  305. network.novirtual = true
  306. function network.write(self, section, value)
  307. local i = nw:get_interface(section)
  308. if i then
  309. if value == '-' then
  310. value = m:formvalue(self:cbid(section) .. ".newnet")
  311. if value and #value > 0 then
  312. local n = nw:add_network(value, {proto="none"})
  313. if n then n:add_interface(i) end
  314. else
  315. local n = i:get_network()
  316. if n then n:del_interface(i) end
  317. end
  318. else
  319. local v
  320. for _, v in ipairs(i:get_networks()) do
  321. v:del_interface(i)
  322. end
  323. for v in ut.imatch(value) do
  324. local n = nw:get_network(v)
  325. if n then
  326. if not n:is_empty() then
  327. n:set("type", "bridge")
  328. end
  329. n:add_interface(i)
  330. end
  331. end
  332. end
  333. end
  334. end
  335. -------------------- MAC80211 Interface ----------------------
  336. if hwtype == "mac80211" then
  337. if fs.access("/usr/sbin/iw") then
  338. mode:value("mesh", "802.11s")
  339. end
  340. mode:value("ahdemo", translate("Pseudo Ad-Hoc (ahdemo)"))
  341. mode:value("monitor", translate("Monitor"))
  342. bssid:depends({mode="adhoc"})
  343. bssid:depends({mode="sta"})
  344. bssid:depends({mode="sta-wds"})
  345. mp = s:taboption("macfilter", ListValue, "macfilter", translate("MAC-Address Filter"))
  346. mp:depends({mode="ap"})
  347. mp:depends({mode="ap-wds"})
  348. mp:value("", translate("disable"))
  349. mp:value("allow", translate("Allow listed only"))
  350. mp:value("deny", translate("Allow all except listed"))
  351. ml = s:taboption("macfilter", DynamicList, "maclist", translate("MAC-List"))
  352. ml.datatype = "macaddr"
  353. ml:depends({macfilter="allow"})
  354. ml:depends({macfilter="deny"})
  355. nt.mac_hints(function(mac, name) ml:value(mac, "%s (%s)" %{ mac, name }) end)
  356. mode:value("ap-wds", "%s (%s)" % {translate("Access Point"), translate("WDS")})
  357. mode:value("sta-wds", "%s (%s)" % {translate("Client"), translate("WDS")})
  358. function mode.write(self, section, value)
  359. if value == "ap-wds" then
  360. ListValue.write(self, section, "ap")
  361. m.uci:set("wireless", section, "wds", 1)
  362. elseif value == "sta-wds" then
  363. ListValue.write(self, section, "sta")
  364. m.uci:set("wireless", section, "wds", 1)
  365. else
  366. ListValue.write(self, section, value)
  367. m.uci:delete("wireless", section, "wds")
  368. end
  369. end
  370. function mode.cfgvalue(self, section)
  371. local mode = ListValue.cfgvalue(self, section)
  372. local wds = m.uci:get("wireless", section, "wds") == "1"
  373. if mode == "ap" and wds then
  374. return "ap-wds"
  375. elseif mode == "sta" and wds then
  376. return "sta-wds"
  377. else
  378. return mode
  379. end
  380. end
  381. hidden = s:taboption("general", Flag, "hidden", translate("Hide <abbr title=\"Extended Service Set Identifier\">ESSID</abbr>"))
  382. hidden:depends({mode="ap"})
  383. hidden:depends({mode="ap-wds"})
  384. wmm = s:taboption("general", Flag, "wmm", translate("WMM Mode"))
  385. wmm:depends({mode="ap"})
  386. wmm:depends({mode="ap-wds"})
  387. wmm.default = wmm.enabled
  388. end
  389. -------------------- Madwifi Interface ----------------------
  390. if hwtype == "atheros" then
  391. mode:value("ahdemo", translate("Pseudo Ad-Hoc (ahdemo)"))
  392. mode:value("monitor", translate("Monitor"))
  393. mode:value("ap-wds", "%s (%s)" % {translate("Access Point"), translate("WDS")})
  394. mode:value("sta-wds", "%s (%s)" % {translate("Client"), translate("WDS")})
  395. mode:value("wds", translate("Static WDS"))
  396. function mode.write(self, section, value)
  397. if value == "ap-wds" then
  398. ListValue.write(self, section, "ap")
  399. m.uci:set("wireless", section, "wds", 1)
  400. elseif value == "sta-wds" then
  401. ListValue.write(self, section, "sta")
  402. m.uci:set("wireless", section, "wds", 1)
  403. else
  404. ListValue.write(self, section, value)
  405. m.uci:delete("wireless", section, "wds")
  406. end
  407. end
  408. function mode.cfgvalue(self, section)
  409. local mode = ListValue.cfgvalue(self, section)
  410. local wds = m.uci:get("wireless", section, "wds") == "1"
  411. if mode == "ap" and wds then
  412. return "ap-wds"
  413. elseif mode == "sta" and wds then
  414. return "sta-wds"
  415. else
  416. return mode
  417. end
  418. end
  419. bssid:depends({mode="adhoc"})
  420. bssid:depends({mode="ahdemo"})
  421. bssid:depends({mode="wds"})
  422. wdssep = s:taboption("advanced", Flag, "wdssep", translate("Separate WDS"))
  423. wdssep:depends({mode="ap-wds"})
  424. s:taboption("advanced", Flag, "doth", "802.11h")
  425. hidden = s:taboption("general", Flag, "hidden", translate("Hide <abbr title=\"Extended Service Set Identifier\">ESSID</abbr>"))
  426. hidden:depends({mode="ap"})
  427. hidden:depends({mode="adhoc"})
  428. hidden:depends({mode="ap-wds"})
  429. hidden:depends({mode="sta-wds"})
  430. isolate = s:taboption("advanced", Flag, "isolate", translate("Separate Clients"),
  431. translate("Prevents client-to-client communication"))
  432. isolate:depends({mode="ap"})
  433. s:taboption("advanced", Flag, "bgscan", translate("Background Scan"))
  434. mp = s:taboption("macfilter", ListValue, "macpolicy", translate("MAC-Address Filter"))
  435. mp:value("", translate("disable"))
  436. mp:value("allow", translate("Allow listed only"))
  437. mp:value("deny", translate("Allow all except listed"))
  438. ml = s:taboption("macfilter", DynamicList, "maclist", translate("MAC-List"))
  439. ml.datatype = "macaddr"
  440. ml:depends({macpolicy="allow"})
  441. ml:depends({macpolicy="deny"})
  442. nt.mac_hints(function(mac, name) ml:value(mac, "%s (%s)" %{ mac, name }) end)
  443. s:taboption("advanced", Value, "rate", translate("Transmission Rate"))
  444. s:taboption("advanced", Value, "mcast_rate", translate("Multicast Rate"))
  445. s:taboption("advanced", Value, "frag", translate("Fragmentation Threshold"))
  446. s:taboption("advanced", Value, "rts", translate("RTS/CTS Threshold"))
  447. s:taboption("advanced", Value, "minrate", translate("Minimum Rate"))
  448. s:taboption("advanced", Value, "maxrate", translate("Maximum Rate"))
  449. s:taboption("advanced", Flag, "compression", translate("Compression"))
  450. s:taboption("advanced", Flag, "bursting", translate("Frame Bursting"))
  451. s:taboption("advanced", Flag, "turbo", translate("Turbo Mode"))
  452. s:taboption("advanced", Flag, "ff", translate("Fast Frames"))
  453. s:taboption("advanced", Flag, "wmm", translate("WMM Mode"))
  454. s:taboption("advanced", Flag, "xr", translate("XR Support"))
  455. s:taboption("advanced", Flag, "ar", translate("AR Support"))
  456. local swm = s:taboption("advanced", Flag, "sw_merge", translate("Disable HW-Beacon timer"))
  457. swm:depends({mode="adhoc"})
  458. local nos = s:taboption("advanced", Flag, "nosbeacon", translate("Disable HW-Beacon timer"))
  459. nos:depends({mode="sta"})
  460. nos:depends({mode="sta-wds"})
  461. local probereq = s:taboption("advanced", Flag, "probereq", translate("Do not send probe responses"))
  462. probereq.enabled = "0"
  463. probereq.disabled = "1"
  464. end
  465. -------------------- Broadcom Interface ----------------------
  466. if hwtype == "broadcom" then
  467. mode:value("wds", translate("WDS"))
  468. mode:value("monitor", translate("Monitor"))
  469. hidden = s:taboption("general", Flag, "hidden", translate("Hide <abbr title=\"Extended Service Set Identifier\">ESSID</abbr>"))
  470. hidden:depends({mode="ap"})
  471. hidden:depends({mode="adhoc"})
  472. hidden:depends({mode="wds"})
  473. isolate = s:taboption("advanced", Flag, "isolate", translate("Separate Clients"),
  474. translate("Prevents client-to-client communication"))
  475. isolate:depends({mode="ap"})
  476. s:taboption("advanced", Flag, "doth", "802.11h")
  477. s:taboption("advanced", Flag, "wmm", translate("WMM Mode"))
  478. bssid:depends({mode="wds"})
  479. bssid:depends({mode="adhoc"})
  480. end
  481. ----------------------- HostAP Interface ---------------------
  482. if hwtype == "prism2" then
  483. mode:value("wds", translate("WDS"))
  484. mode:value("monitor", translate("Monitor"))
  485. hidden = s:taboption("general", Flag, "hidden", translate("Hide <abbr title=\"Extended Service Set Identifier\">ESSID</abbr>"))
  486. hidden:depends({mode="ap"})
  487. hidden:depends({mode="adhoc"})
  488. hidden:depends({mode="wds"})
  489. bssid:depends({mode="sta"})
  490. mp = s:taboption("macfilter", ListValue, "macpolicy", translate("MAC-Address Filter"))
  491. mp:value("", translate("disable"))
  492. mp:value("allow", translate("Allow listed only"))
  493. mp:value("deny", translate("Allow all except listed"))
  494. ml = s:taboption("macfilter", DynamicList, "maclist", translate("MAC-List"))
  495. ml:depends({macpolicy="allow"})
  496. ml:depends({macpolicy="deny"})
  497. nt.mac_hints(function(mac, name) ml:value(mac, "%s (%s)" %{ mac, name }) end)
  498. s:taboption("advanced", Value, "rate", translate("Transmission Rate"))
  499. s:taboption("advanced", Value, "frag", translate("Fragmentation Threshold"))
  500. s:taboption("advanced", Value, "rts", translate("RTS/CTS Threshold"))
  501. end
  502. ------------------- WiFI-Encryption -------------------
  503. encr = s:taboption("encryption", ListValue, "encryption", translate("Encryption"))
  504. encr.override_values = true
  505. encr.override_depends = true
  506. encr:depends({mode="ap"})
  507. encr:depends({mode="sta"})
  508. encr:depends({mode="adhoc"})
  509. encr:depends({mode="ahdemo"})
  510. encr:depends({mode="ap-wds"})
  511. encr:depends({mode="sta-wds"})
  512. encr:depends({mode="mesh"})
  513. cipher = s:taboption("encryption", ListValue, "cipher", translate("Cipher"))
  514. cipher:depends({encryption="wpa"})
  515. cipher:depends({encryption="wpa2"})
  516. cipher:depends({encryption="psk"})
  517. cipher:depends({encryption="psk2"})
  518. cipher:depends({encryption="wpa-mixed"})
  519. cipher:depends({encryption="psk-mixed"})
  520. cipher:value("auto", translate("auto"))
  521. cipher:value("ccmp", translate("Force CCMP (AES)"))
  522. cipher:value("tkip", translate("Force TKIP"))
  523. cipher:value("tkip+ccmp", translate("Force TKIP and CCMP (AES)"))
  524. function encr.cfgvalue(self, section)
  525. local v = tostring(ListValue.cfgvalue(self, section))
  526. if v == "wep" then
  527. return "wep-open"
  528. elseif v and v:match("%+") then
  529. return (v:gsub("%+.+$", ""))
  530. end
  531. return v
  532. end
  533. function encr.write(self, section, value)
  534. local e = tostring(encr:formvalue(section))
  535. local c = tostring(cipher:formvalue(section))
  536. if value == "wpa" or value == "wpa2" then
  537. self.map.uci:delete("wireless", section, "key")
  538. end
  539. if e and (c == "tkip" or c == "ccmp" or c == "tkip+ccmp") then
  540. e = e .. "+" .. c
  541. end
  542. self.map:set(section, "encryption", e)
  543. end
  544. function cipher.cfgvalue(self, section)
  545. local v = tostring(ListValue.cfgvalue(encr, section))
  546. if v and v:match("%+") then
  547. v = v:gsub("^[^%+]+%+", "")
  548. if v == "aes" then v = "ccmp"
  549. elseif v == "tkip+aes" then v = "tkip+ccmp"
  550. elseif v == "aes+tkip" then v = "tkip+ccmp"
  551. elseif v == "ccmp+tkip" then v = "tkip+ccmp"
  552. end
  553. end
  554. return v
  555. end
  556. function cipher.write(self, section)
  557. return encr:write(section)
  558. end
  559. encr:value("none", "No Encryption")
  560. encr:value("wep-open", translate("WEP Open System"), {mode="ap"}, {mode="sta"}, {mode="ap-wds"}, {mode="sta-wds"}, {mode="adhoc"}, {mode="ahdemo"}, {mode="wds"})
  561. encr:value("wep-shared", translate("WEP Shared Key"), {mode="ap"}, {mode="sta"}, {mode="ap-wds"}, {mode="sta-wds"}, {mode="adhoc"}, {mode="ahdemo"}, {mode="wds"})
  562. if hwtype == "atheros" or hwtype == "mac80211" or hwtype == "prism2" then
  563. local supplicant = fs.access("/usr/sbin/wpa_supplicant")
  564. local hostapd = fs.access("/usr/sbin/hostapd")
  565. -- Probe EAP support
  566. local has_ap_eap = (os.execute("hostapd -veap >/dev/null 2>/dev/null") == 0)
  567. local has_sta_eap = (os.execute("wpa_supplicant -veap >/dev/null 2>/dev/null") == 0)
  568. if hostapd and supplicant then
  569. encr:value("psk", "WPA-PSK", {mode="ap"}, {mode="sta"}, {mode="ap-wds"}, {mode="sta-wds"})
  570. encr:value("psk2", "WPA2-PSK", {mode="ap"}, {mode="sta"}, {mode="ap-wds"}, {mode="sta-wds"})
  571. encr:value("psk-mixed", "WPA-PSK/WPA2-PSK Mixed Mode", {mode="ap"}, {mode="sta"}, {mode="ap-wds"}, {mode="sta-wds"})
  572. if has_ap_eap and has_sta_eap then
  573. encr:value("wpa", "WPA-EAP", {mode="ap"}, {mode="sta"}, {mode="ap-wds"}, {mode="sta-wds"})
  574. encr:value("wpa2", "WPA2-EAP", {mode="ap"}, {mode="sta"}, {mode="ap-wds"}, {mode="sta-wds"})
  575. end
  576. elseif hostapd and not supplicant then
  577. encr:value("psk", "WPA-PSK", {mode="ap"}, {mode="ap-wds"})
  578. encr:value("psk2", "WPA2-PSK", {mode="ap"}, {mode="ap-wds"})
  579. encr:value("psk-mixed", "WPA-PSK/WPA2-PSK Mixed Mode", {mode="ap"}, {mode="ap-wds"})
  580. if has_ap_eap then
  581. encr:value("wpa", "WPA-EAP", {mode="ap"}, {mode="ap-wds"})
  582. encr:value("wpa2", "WPA2-EAP", {mode="ap"}, {mode="ap-wds"})
  583. end
  584. encr.description = translate(
  585. "WPA-Encryption requires wpa_supplicant (for client mode) or hostapd (for AP " ..
  586. "and ad-hoc mode) to be installed."
  587. )
  588. elseif not hostapd and supplicant then
  589. encr:value("psk", "WPA-PSK", {mode="sta"}, {mode="sta-wds"})
  590. encr:value("psk2", "WPA2-PSK", {mode="sta"}, {mode="sta-wds"})
  591. encr:value("psk-mixed", "WPA-PSK/WPA2-PSK Mixed Mode", {mode="sta"}, {mode="sta-wds"})
  592. if has_sta_eap then
  593. encr:value("wpa", "WPA-EAP", {mode="sta"}, {mode="sta-wds"})
  594. encr:value("wpa2", "WPA2-EAP", {mode="sta"}, {mode="sta-wds"})
  595. end
  596. encr.description = translate(
  597. "WPA-Encryption requires wpa_supplicant (for client mode) or hostapd (for AP " ..
  598. "and ad-hoc mode) to be installed."
  599. )
  600. else
  601. encr.description = translate(
  602. "WPA-Encryption requires wpa_supplicant (for client mode) or hostapd (for AP " ..
  603. "and ad-hoc mode) to be installed."
  604. )
  605. end
  606. elseif hwtype == "broadcom" then
  607. encr:value("psk", "WPA-PSK")
  608. encr:value("psk2", "WPA2-PSK")
  609. encr:value("psk+psk2", "WPA-PSK/WPA2-PSK Mixed Mode")
  610. end
  611. auth_server = s:taboption("encryption", Value, "auth_server", translate("Radius-Authentication-Server"))
  612. auth_server:depends({mode="ap", encryption="wpa"})
  613. auth_server:depends({mode="ap", encryption="wpa2"})
  614. auth_server:depends({mode="ap-wds", encryption="wpa"})
  615. auth_server:depends({mode="ap-wds", encryption="wpa2"})
  616. auth_server.rmempty = true
  617. auth_server.datatype = "host"
  618. auth_port = s:taboption("encryption", Value, "auth_port", translate("Radius-Authentication-Port"), translatef("Default %d", 1812))
  619. auth_port:depends({mode="ap", encryption="wpa"})
  620. auth_port:depends({mode="ap", encryption="wpa2"})
  621. auth_port:depends({mode="ap-wds", encryption="wpa"})
  622. auth_port:depends({mode="ap-wds", encryption="wpa2"})
  623. auth_port.rmempty = true
  624. auth_port.datatype = "port"
  625. auth_secret = s:taboption("encryption", Value, "auth_secret", translate("Radius-Authentication-Secret"))
  626. auth_secret:depends({mode="ap", encryption="wpa"})
  627. auth_secret:depends({mode="ap", encryption="wpa2"})
  628. auth_secret:depends({mode="ap-wds", encryption="wpa"})
  629. auth_secret:depends({mode="ap-wds", encryption="wpa2"})
  630. auth_secret.rmempty = true
  631. auth_secret.password = true
  632. acct_server = s:taboption("encryption", Value, "acct_server", translate("Radius-Accounting-Server"))
  633. acct_server:depends({mode="ap", encryption="wpa"})
  634. acct_server:depends({mode="ap", encryption="wpa2"})
  635. acct_server:depends({mode="ap-wds", encryption="wpa"})
  636. acct_server:depends({mode="ap-wds", encryption="wpa2"})
  637. acct_server.rmempty = true
  638. acct_server.datatype = "host"
  639. acct_port = s:taboption("encryption", Value, "acct_port", translate("Radius-Accounting-Port"), translatef("Default %d", 1813))
  640. acct_port:depends({mode="ap", encryption="wpa"})
  641. acct_port:depends({mode="ap", encryption="wpa2"})
  642. acct_port:depends({mode="ap-wds", encryption="wpa"})
  643. acct_port:depends({mode="ap-wds", encryption="wpa2"})
  644. acct_port.rmempty = true
  645. acct_port.datatype = "port"
  646. acct_secret = s:taboption("encryption", Value, "acct_secret", translate("Radius-Accounting-Secret"))
  647. acct_secret:depends({mode="ap", encryption="wpa"})
  648. acct_secret:depends({mode="ap", encryption="wpa2"})
  649. acct_secret:depends({mode="ap-wds", encryption="wpa"})
  650. acct_secret:depends({mode="ap-wds", encryption="wpa2"})
  651. acct_secret.rmempty = true
  652. acct_secret.password = true
  653. wpakey = s:taboption("encryption", Value, "_wpa_key", translate("Key"))
  654. wpakey:depends("encryption", "psk")
  655. wpakey:depends("encryption", "psk2")
  656. wpakey:depends("encryption", "psk+psk2")
  657. wpakey:depends("encryption", "psk-mixed")
  658. wpakey.datatype = "wpakey"
  659. wpakey.rmempty = true
  660. wpakey.password = true
  661. wpakey.cfgvalue = function(self, section, value)
  662. local key = m.uci:get("wireless", section, "key")
  663. if key == "1" or key == "2" or key == "3" or key == "4" then
  664. return nil
  665. end
  666. return key
  667. end
  668. wpakey.write = function(self, section, value)
  669. self.map.uci:set("wireless", section, "key", value)
  670. self.map.uci:delete("wireless", section, "key1")
  671. end
  672. wepslot = s:taboption("encryption", ListValue, "_wep_key", translate("Used Key Slot"))
  673. wepslot:depends("encryption", "wep-open")
  674. wepslot:depends("encryption", "wep-shared")
  675. wepslot:value("1", translatef("Key #%d", 1))
  676. wepslot:value("2", translatef("Key #%d", 2))
  677. wepslot:value("3", translatef("Key #%d", 3))
  678. wepslot:value("4", translatef("Key #%d", 4))
  679. wepslot.cfgvalue = function(self, section)
  680. local slot = tonumber(m.uci:get("wireless", section, "key"))
  681. if not slot or slot < 1 or slot > 4 then
  682. return 1
  683. end
  684. return slot
  685. end
  686. wepslot.write = function(self, section, value)
  687. self.map.uci:set("wireless", section, "key", value)
  688. end
  689. local slot
  690. for slot=1,4 do
  691. wepkey = s:taboption("encryption", Value, "key" .. slot, translatef("Key #%d", slot))
  692. wepkey:depends("encryption", "wep-open")
  693. wepkey:depends("encryption", "wep-shared")
  694. wepkey.datatype = "wepkey"
  695. wepkey.rmempty = true
  696. wepkey.password = true
  697. function wepkey.write(self, section, value)
  698. if value and (#value == 5 or #value == 13) then
  699. value = "s:" .. value
  700. end
  701. return Value.write(self, section, value)
  702. end
  703. end
  704. if hwtype == "atheros" or hwtype == "mac80211" or hwtype == "prism2" then
  705. nasid = s:taboption("encryption", Value, "nasid", translate("NAS ID"))
  706. nasid:depends({mode="ap", encryption="wpa"})
  707. nasid:depends({mode="ap", encryption="wpa2"})
  708. nasid:depends({mode="ap-wds", encryption="wpa"})
  709. nasid:depends({mode="ap-wds", encryption="wpa2"})
  710. nasid.rmempty = true
  711. eaptype = s:taboption("encryption", ListValue, "eap_type", translate("EAP-Method"))
  712. eaptype:value("tls", "TLS")
  713. eaptype:value("ttls", "TTLS")
  714. eaptype:value("peap", "PEAP")
  715. eaptype:depends({mode="sta", encryption="wpa"})
  716. eaptype:depends({mode="sta", encryption="wpa2"})
  717. eaptype:depends({mode="sta-wds", encryption="wpa"})
  718. eaptype:depends({mode="sta-wds", encryption="wpa2"})
  719. cacert = s:taboption("encryption", FileUpload, "ca_cert", translate("Path to CA-Certificate"))
  720. cacert:depends({mode="sta", encryption="wpa"})
  721. cacert:depends({mode="sta", encryption="wpa2"})
  722. cacert:depends({mode="sta-wds", encryption="wpa"})
  723. cacert:depends({mode="sta-wds", encryption="wpa2"})
  724. clientcert = s:taboption("encryption", FileUpload, "client_cert", translate("Path to Client-Certificate"))
  725. clientcert:depends({mode="sta", encryption="wpa"})
  726. clientcert:depends({mode="sta", encryption="wpa2"})
  727. clientcert:depends({mode="sta-wds", encryption="wpa"})
  728. clientcert:depends({mode="sta-wds", encryption="wpa2"})
  729. privkey = s:taboption("encryption", FileUpload, "priv_key", translate("Path to Private Key"))
  730. privkey:depends({mode="sta", eap_type="tls", encryption="wpa2"})
  731. privkey:depends({mode="sta", eap_type="tls", encryption="wpa"})
  732. privkey:depends({mode="sta-wds", eap_type="tls", encryption="wpa2"})
  733. privkey:depends({mode="sta-wds", eap_type="tls", encryption="wpa"})
  734. privkeypwd = s:taboption("encryption", Value, "priv_key_pwd", translate("Password of Private Key"))
  735. privkeypwd:depends({mode="sta", eap_type="tls", encryption="wpa2"})
  736. privkeypwd:depends({mode="sta", eap_type="tls", encryption="wpa"})
  737. privkeypwd:depends({mode="sta-wds", eap_type="tls", encryption="wpa2"})
  738. privkeypwd:depends({mode="sta-wds", eap_type="tls", encryption="wpa"})
  739. auth = s:taboption("encryption", Value, "auth", translate("Authentication"))
  740. auth:value("PAP")
  741. auth:value("CHAP")
  742. auth:value("MSCHAP")
  743. auth:value("MSCHAPV2")
  744. auth:depends({mode="sta", eap_type="peap", encryption="wpa2"})
  745. auth:depends({mode="sta", eap_type="peap", encryption="wpa"})
  746. auth:depends({mode="sta", eap_type="ttls", encryption="wpa2"})
  747. auth:depends({mode="sta", eap_type="ttls", encryption="wpa"})
  748. auth:depends({mode="sta-wds", eap_type="peap", encryption="wpa2"})
  749. auth:depends({mode="sta-wds", eap_type="peap", encryption="wpa"})
  750. auth:depends({mode="sta-wds", eap_type="ttls", encryption="wpa2"})
  751. auth:depends({mode="sta-wds", eap_type="ttls", encryption="wpa"})
  752. identity = s:taboption("encryption", Value, "identity", translate("Identity"))
  753. identity:depends({mode="sta", eap_type="peap", encryption="wpa2"})
  754. identity:depends({mode="sta", eap_type="peap", encryption="wpa"})
  755. identity:depends({mode="sta", eap_type="ttls", encryption="wpa2"})
  756. identity:depends({mode="sta", eap_type="ttls", encryption="wpa"})
  757. identity:depends({mode="sta-wds", eap_type="peap", encryption="wpa2"})
  758. identity:depends({mode="sta-wds", eap_type="peap", encryption="wpa"})
  759. identity:depends({mode="sta-wds", eap_type="ttls", encryption="wpa2"})
  760. identity:depends({mode="sta-wds", eap_type="ttls", encryption="wpa"})
  761. password = s:taboption("encryption", Value, "password", translate("Password"))
  762. password:depends({mode="sta", eap_type="peap", encryption="wpa2"})
  763. password:depends({mode="sta", eap_type="peap", encryption="wpa"})
  764. password:depends({mode="sta", eap_type="ttls", encryption="wpa2"})
  765. password:depends({mode="sta", eap_type="ttls", encryption="wpa"})
  766. password:depends({mode="sta-wds", eap_type="peap", encryption="wpa2"})
  767. password:depends({mode="sta-wds", eap_type="peap", encryption="wpa"})
  768. password:depends({mode="sta-wds", eap_type="ttls", encryption="wpa2"})
  769. password:depends({mode="sta-wds", eap_type="ttls", encryption="wpa"})
  770. end
  771. if hwtype == "atheros" or hwtype == "mac80211" or hwtype == "prism2" then
  772. local wpasupplicant = fs.access("/usr/sbin/wpa_supplicant")
  773. local hostcli = fs.access("/usr/sbin/hostapd_cli")
  774. if hostcli and wpasupplicant then
  775. wps = s:taboption("encryption", Flag, "wps_pushbutton", translate("Enable WPS pushbutton, requires WPA(2)-PSK"))
  776. wps.enabled = "1"
  777. wps.disabled = "0"
  778. wps.rmempty = false
  779. wps:depends("encryption", "psk")
  780. wps:depends("encryption", "psk2")
  781. wps:depends("encryption", "psk-mixed")
  782. end
  783. end
  784. return m