5 <title>Source: network.js</title>
8 <script src="scripts/prettify/prettify.js"></script>
9 <script src="scripts/prettify/lang-css.js"></script>
10 <script src="scripts/jquery.min.js"></script>
12 <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
14 <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
15 <link type="text/css" rel="stylesheet" href="styles/bootstrap.min.css">
16 <link type="text/css" rel="stylesheet" href="styles/jaguar.css">
20 var config = {"monospaceLinks":true,"cleverLinks":true,"default":{"outputSourceFiles":true}};
27 <div id="wrap" class="clearfix">
29 <div class="navigation">
30 <h3 class="applicationName"><a href="index.html"></a></h3>
33 <input id="search" type="text" class="form-control input-sm" placeholder="Search Documentations">
37 <li class="item" data-name="LuCI">
39 <a href="LuCI.html">LuCI</a>
42 <ul class="members itemMembers">
44 <span class="subtitle">Members</span>
46 <li data-name="LuCI#env"><a href="LuCI.html#env">env</a></li>
49 <ul class="typedefs itemMembers">
51 <span class="subtitle">Typedefs</span>
53 <li data-name="LuCI.requestCallbackFn"><a href="LuCI.html#.requestCallbackFn">requestCallbackFn</a></li>
56 <ul class="typedefs itemMembers">
59 <ul class="methods itemMembers">
61 <span class="subtitle">Methods</span>
63 <li data-name="LuCI#bind"><a href="LuCI.html#bind">bind</a></li>
65 <li data-name="LuCI#error"><a href="LuCI.html#error">error</a></li>
67 <li data-name="LuCI#get"><a href="LuCI.html#get">get</a></li>
69 <li data-name="LuCI#halt"><a href="LuCI.html#halt">halt</a></li>
71 <li data-name="LuCI#hasSystemFeature"><a href="LuCI.html#hasSystemFeature">hasSystemFeature</a></li>
73 <li data-name="LuCI#isObject"><a href="LuCI.html#isObject">isObject</a></li>
75 <li data-name="LuCI#location"><a href="LuCI.html#location">location</a></li>
77 <li data-name="LuCI#path"><a href="LuCI.html#path">path</a></li>
79 <li data-name="LuCI#poll"><a href="LuCI.html#poll">poll</a></li>
81 <li data-name="LuCI#post"><a href="LuCI.html#post">post</a></li>
83 <li data-name="LuCI#raise"><a href="LuCI.html#raise">raise</a></li>
85 <li data-name="LuCI#require"><a href="LuCI.html#require">require</a></li>
87 <li data-name="LuCI#resolveDefault"><a href="LuCI.html#resolveDefault">resolveDefault</a></li>
89 <li data-name="LuCI#resource"><a href="LuCI.html#resource">resource</a></li>
91 <li data-name="LuCI#run"><a href="LuCI.html#run">run</a></li>
93 <li data-name="LuCI#sortedKeys"><a href="LuCI.html#sortedKeys">sortedKeys</a></li>
95 <li data-name="LuCI#stop"><a href="LuCI.html#stop">stop</a></li>
97 <li data-name="LuCI#toArray"><a href="LuCI.html#toArray">toArray</a></li>
99 <li data-name="LuCI#url"><a href="LuCI.html#url">url</a></li>
102 <ul class="events itemMembers">
107 <li class="item" data-name="LuCI.Class">
109 <a href="LuCI.Class.html">LuCI.Class</a>
112 <ul class="members itemMembers">
115 <ul class="typedefs itemMembers">
118 <ul class="typedefs itemMembers">
121 <ul class="methods itemMembers">
123 <span class="subtitle">Methods</span>
125 <li data-name="LuCI.Class.extend"><a href="LuCI.Class.html#.extend">extend</a></li>
127 <li data-name="LuCI.Class.instantiate"><a href="LuCI.Class.html#.instantiate">instantiate</a></li>
129 <li data-name="LuCI.Class.isSubclass"><a href="LuCI.Class.html#.isSubclass">isSubclass</a></li>
131 <li data-name="LuCI.Class.singleton"><a href="LuCI.Class.html#.singleton">singleton</a></li>
133 <li data-name="LuCI.Class#super"><a href="LuCI.Class.html#super">super</a></li>
135 <li data-name="LuCI.Class#varargs"><a href="LuCI.Class.html#varargs">varargs</a></li>
138 <ul class="events itemMembers">
143 <li class="item" data-name="LuCI.dom">
145 <a href="LuCI.dom.html">LuCI.dom</a>
148 <ul class="members itemMembers">
151 <ul class="typedefs itemMembers">
153 <span class="subtitle">Typedefs</span>
155 <li data-name="LuCI.dom~ignoreCallbackFn"><a href="LuCI.dom.html#~ignoreCallbackFn">ignoreCallbackFn</a></li>
158 <ul class="typedefs itemMembers">
161 <ul class="methods itemMembers">
163 <span class="subtitle">Methods</span>
165 <li data-name="LuCI.dom#append"><a href="LuCI.dom.html#append">append</a></li>
167 <li data-name="LuCI.dom#attr"><a href="LuCI.dom.html#attr">attr</a></li>
169 <li data-name="LuCI.dom#bindClassInstance"><a href="LuCI.dom.html#bindClassInstance">bindClassInstance</a></li>
171 <li data-name="LuCI.dom#callClassMethod"><a href="LuCI.dom.html#callClassMethod">callClassMethod</a></li>
173 <li data-name="LuCI.dom#content"><a href="LuCI.dom.html#content">content</a></li>
175 <li data-name="LuCI.dom#create"><a href="LuCI.dom.html#create">create</a></li>
177 <li data-name="LuCI.dom#data"><a href="LuCI.dom.html#data">data</a></li>
179 <li data-name="LuCI.dom#elem"><a href="LuCI.dom.html#elem">elem</a></li>
181 <li data-name="LuCI.dom#findClassInstance"><a href="LuCI.dom.html#findClassInstance">findClassInstance</a></li>
183 <li data-name="LuCI.dom#isEmpty"><a href="LuCI.dom.html#isEmpty">isEmpty</a></li>
185 <li data-name="LuCI.dom#matches"><a href="LuCI.dom.html#matches">matches</a></li>
187 <li data-name="LuCI.dom#parent"><a href="LuCI.dom.html#parent">parent</a></li>
189 <li data-name="LuCI.dom#parse"><a href="LuCI.dom.html#parse">parse</a></li>
192 <ul class="events itemMembers">
197 <li class="item" data-name="LuCI.fs">
199 <a href="LuCI.fs.html">LuCI.fs</a>
202 <ul class="members itemMembers">
205 <ul class="typedefs itemMembers">
207 <span class="subtitle">Typedefs</span>
209 <li data-name="LuCI.fs.FileExecResult"><a href="LuCI.fs.html#.FileExecResult">FileExecResult</a></li>
211 <li data-name="LuCI.fs.FileStatEntry"><a href="LuCI.fs.html#.FileStatEntry">FileStatEntry</a></li>
214 <ul class="typedefs itemMembers">
217 <ul class="methods itemMembers">
219 <span class="subtitle">Methods</span>
221 <li data-name="LuCI.fs#exec"><a href="LuCI.fs.html#exec">exec</a></li>
223 <li data-name="LuCI.fs#lines"><a href="LuCI.fs.html#lines">lines</a></li>
225 <li data-name="LuCI.fs#list"><a href="LuCI.fs.html#list">list</a></li>
227 <li data-name="LuCI.fs#read"><a href="LuCI.fs.html#read">read</a></li>
229 <li data-name="LuCI.fs#remove"><a href="LuCI.fs.html#remove">remove</a></li>
231 <li data-name="LuCI.fs#stat"><a href="LuCI.fs.html#stat">stat</a></li>
233 <li data-name="LuCI.fs#trimmed"><a href="LuCI.fs.html#trimmed">trimmed</a></li>
235 <li data-name="LuCI.fs#write"><a href="LuCI.fs.html#write">write</a></li>
238 <ul class="events itemMembers">
243 <li class="item" data-name="LuCI.Headers">
245 <a href="LuCI.Headers.html">LuCI.Headers</a>
248 <ul class="members itemMembers">
251 <ul class="typedefs itemMembers">
254 <ul class="typedefs itemMembers">
257 <ul class="methods itemMembers">
259 <span class="subtitle">Methods</span>
261 <li data-name="LuCI.Headers#get"><a href="LuCI.Headers.html#get">get</a></li>
263 <li data-name="LuCI.Headers#has"><a href="LuCI.Headers.html#has">has</a></li>
266 <ul class="events itemMembers">
271 <li class="item" data-name="LuCI.Network">
273 <a href="LuCI.Network.html">LuCI.Network</a>
276 <ul class="members itemMembers">
279 <ul class="typedefs itemMembers">
281 <span class="subtitle">Typedefs</span>
283 <li data-name="LuCI.Network.SwitchTopology"><a href="LuCI.Network.html#.SwitchTopology">SwitchTopology</a></li>
285 <li data-name="LuCI.Network.WifiEncryption"><a href="LuCI.Network.html#.WifiEncryption">WifiEncryption</a></li>
287 <li data-name="LuCI.Network.WifiPeerEntry"><a href="LuCI.Network.html#.WifiPeerEntry">WifiPeerEntry</a></li>
289 <li data-name="LuCI.Network.WifiRateEntry"><a href="LuCI.Network.html#.WifiRateEntry">WifiRateEntry</a></li>
291 <li data-name="LuCI.Network.WifiScanResult"><a href="LuCI.Network.html#.WifiScanResult">WifiScanResult</a></li>
294 <ul class="typedefs itemMembers">
297 <ul class="methods itemMembers">
299 <span class="subtitle">Methods</span>
301 <li data-name="LuCI.Network#addNetwork"><a href="LuCI.Network.html#addNetwork">addNetwork</a></li>
303 <li data-name="LuCI.Network#addWifiNetwork"><a href="LuCI.Network.html#addWifiNetwork">addWifiNetwork</a></li>
305 <li data-name="LuCI.Network#deleteNetwork"><a href="LuCI.Network.html#deleteNetwork">deleteNetwork</a></li>
307 <li data-name="LuCI.Network#deleteWifiNetwork"><a href="LuCI.Network.html#deleteWifiNetwork">deleteWifiNetwork</a></li>
309 <li data-name="LuCI.Network#flushCache"><a href="LuCI.Network.html#flushCache">flushCache</a></li>
311 <li data-name="LuCI.Network#formatWifiEncryption"><a href="LuCI.Network.html#formatWifiEncryption">formatWifiEncryption</a></li>
313 <li data-name="LuCI.Network#getDevice"><a href="LuCI.Network.html#getDevice">getDevice</a></li>
315 <li data-name="LuCI.Network#getDevices"><a href="LuCI.Network.html#getDevices">getDevices</a></li>
317 <li data-name="LuCI.Network#getDSLModemType"><a href="LuCI.Network.html#getDSLModemType">getDSLModemType</a></li>
319 <li data-name="LuCI.Network#getHostHints"><a href="LuCI.Network.html#getHostHints">getHostHints</a></li>
321 <li data-name="LuCI.Network#getIfnameOf"><a href="LuCI.Network.html#getIfnameOf">getIfnameOf</a></li>
323 <li data-name="LuCI.Network#getNetwork"><a href="LuCI.Network.html#getNetwork">getNetwork</a></li>
325 <li data-name="LuCI.Network#getNetworks"><a href="LuCI.Network.html#getNetworks">getNetworks</a></li>
327 <li data-name="LuCI.Network#getProtocol"><a href="LuCI.Network.html#getProtocol">getProtocol</a></li>
329 <li data-name="LuCI.Network#getProtocols"><a href="LuCI.Network.html#getProtocols">getProtocols</a></li>
331 <li data-name="LuCI.Network#getSwitchTopologies"><a href="LuCI.Network.html#getSwitchTopologies">getSwitchTopologies</a></li>
333 <li data-name="LuCI.Network#getWAN6Networks"><a href="LuCI.Network.html#getWAN6Networks">getWAN6Networks</a></li>
335 <li data-name="LuCI.Network#getWANNetworks"><a href="LuCI.Network.html#getWANNetworks">getWANNetworks</a></li>
337 <li data-name="LuCI.Network#getWifiDevice"><a href="LuCI.Network.html#getWifiDevice">getWifiDevice</a></li>
339 <li data-name="LuCI.Network#getWifiDevices"><a href="LuCI.Network.html#getWifiDevices">getWifiDevices</a></li>
341 <li data-name="LuCI.Network#getWifiNetwork"><a href="LuCI.Network.html#getWifiNetwork">getWifiNetwork</a></li>
343 <li data-name="LuCI.Network#getWifiNetworks"><a href="LuCI.Network.html#getWifiNetworks">getWifiNetworks</a></li>
345 <li data-name="LuCI.Network#isIgnoredDevice"><a href="LuCI.Network.html#isIgnoredDevice">isIgnoredDevice</a></li>
347 <li data-name="LuCI.Network#maskToPrefix"><a href="LuCI.Network.html#maskToPrefix">maskToPrefix</a></li>
349 <li data-name="LuCI.Network#prefixToMask"><a href="LuCI.Network.html#prefixToMask">prefixToMask</a></li>
351 <li data-name="LuCI.Network#registerErrorCode"><a href="LuCI.Network.html#registerErrorCode">registerErrorCode</a></li>
353 <li data-name="LuCI.Network#registerPatternVirtual"><a href="LuCI.Network.html#registerPatternVirtual">registerPatternVirtual</a></li>
355 <li data-name="LuCI.Network#registerProtocol"><a href="LuCI.Network.html#registerProtocol">registerProtocol</a></li>
357 <li data-name="LuCI.Network#renameNetwork"><a href="LuCI.Network.html#renameNetwork">renameNetwork</a></li>
360 <ul class="events itemMembers">
365 <li class="item" data-name="LuCI.Network.Device">
367 <a href="LuCI.Network.Device.html">LuCI.Network.Device</a>
370 <ul class="members itemMembers">
373 <ul class="typedefs itemMembers">
376 <ul class="typedefs itemMembers">
379 <ul class="methods itemMembers">
381 <span class="subtitle">Methods</span>
383 <li data-name="LuCI.Network.Device#getBridgeID"><a href="LuCI.Network.Device.html#getBridgeID">getBridgeID</a></li>
385 <li data-name="LuCI.Network.Device#getBridgeSTP"><a href="LuCI.Network.Device.html#getBridgeSTP">getBridgeSTP</a></li>
387 <li data-name="LuCI.Network.Device#getI18n"><a href="LuCI.Network.Device.html#getI18n">getI18n</a></li>
389 <li data-name="LuCI.Network.Device#getIP6Addrs"><a href="LuCI.Network.Device.html#getIP6Addrs">getIP6Addrs</a></li>
391 <li data-name="LuCI.Network.Device#getIPAddrs"><a href="LuCI.Network.Device.html#getIPAddrs">getIPAddrs</a></li>
393 <li data-name="LuCI.Network.Device#getMAC"><a href="LuCI.Network.Device.html#getMAC">getMAC</a></li>
395 <li data-name="LuCI.Network.Device#getMTU"><a href="LuCI.Network.Device.html#getMTU">getMTU</a></li>
397 <li data-name="LuCI.Network.Device#getName"><a href="LuCI.Network.Device.html#getName">getName</a></li>
399 <li data-name="LuCI.Network.Device#getNetwork"><a href="LuCI.Network.Device.html#getNetwork">getNetwork</a></li>
401 <li data-name="LuCI.Network.Device#getNetworks"><a href="LuCI.Network.Device.html#getNetworks">getNetworks</a></li>
403 <li data-name="LuCI.Network.Device#getPorts"><a href="LuCI.Network.Device.html#getPorts">getPorts</a></li>
405 <li data-name="LuCI.Network.Device#getRXBytes"><a href="LuCI.Network.Device.html#getRXBytes">getRXBytes</a></li>
407 <li data-name="LuCI.Network.Device#getRXPackets"><a href="LuCI.Network.Device.html#getRXPackets">getRXPackets</a></li>
409 <li data-name="LuCI.Network.Device#getShortName"><a href="LuCI.Network.Device.html#getShortName">getShortName</a></li>
411 <li data-name="LuCI.Network.Device#getTXBytes"><a href="LuCI.Network.Device.html#getTXBytes">getTXBytes</a></li>
413 <li data-name="LuCI.Network.Device#getTXPackets"><a href="LuCI.Network.Device.html#getTXPackets">getTXPackets</a></li>
415 <li data-name="LuCI.Network.Device#getType"><a href="LuCI.Network.Device.html#getType">getType</a></li>
417 <li data-name="LuCI.Network.Device#getTypeI18n"><a href="LuCI.Network.Device.html#getTypeI18n">getTypeI18n</a></li>
419 <li data-name="LuCI.Network.Device#getWifiNetwork"><a href="LuCI.Network.Device.html#getWifiNetwork">getWifiNetwork</a></li>
421 <li data-name="LuCI.Network.Device#isBridge"><a href="LuCI.Network.Device.html#isBridge">isBridge</a></li>
423 <li data-name="LuCI.Network.Device#isBridgePort"><a href="LuCI.Network.Device.html#isBridgePort">isBridgePort</a></li>
425 <li data-name="LuCI.Network.Device#isUp"><a href="LuCI.Network.Device.html#isUp">isUp</a></li>
428 <ul class="events itemMembers">
433 <li class="item" data-name="LuCI.Network.Hosts">
435 <a href="LuCI.Network.Hosts.html">LuCI.Network.Hosts</a>
438 <ul class="members itemMembers">
441 <ul class="typedefs itemMembers">
444 <ul class="typedefs itemMembers">
447 <ul class="methods itemMembers">
449 <span class="subtitle">Methods</span>
451 <li data-name="LuCI.Network.Hosts#getHostnameByIP6Addr"><a href="LuCI.Network.Hosts.html#getHostnameByIP6Addr">getHostnameByIP6Addr</a></li>
453 <li data-name="LuCI.Network.Hosts#getHostnameByIPAddr"><a href="LuCI.Network.Hosts.html#getHostnameByIPAddr">getHostnameByIPAddr</a></li>
455 <li data-name="LuCI.Network.Hosts#getHostnameByMACAddr"><a href="LuCI.Network.Hosts.html#getHostnameByMACAddr">getHostnameByMACAddr</a></li>
457 <li data-name="LuCI.Network.Hosts#getIP6AddrByMACAddr"><a href="LuCI.Network.Hosts.html#getIP6AddrByMACAddr">getIP6AddrByMACAddr</a></li>
459 <li data-name="LuCI.Network.Hosts#getIPAddrByMACAddr"><a href="LuCI.Network.Hosts.html#getIPAddrByMACAddr">getIPAddrByMACAddr</a></li>
461 <li data-name="LuCI.Network.Hosts#getMACAddrByIP6Addr"><a href="LuCI.Network.Hosts.html#getMACAddrByIP6Addr">getMACAddrByIP6Addr</a></li>
463 <li data-name="LuCI.Network.Hosts#getMACAddrByIPAddr"><a href="LuCI.Network.Hosts.html#getMACAddrByIPAddr">getMACAddrByIPAddr</a></li>
465 <li data-name="LuCI.Network.Hosts#getMACHints"><a href="LuCI.Network.Hosts.html#getMACHints">getMACHints</a></li>
468 <ul class="events itemMembers">
473 <li class="item" data-name="LuCI.Network.Protocol">
475 <a href="LuCI.Network.Protocol.html">LuCI.Network.Protocol</a>
478 <ul class="members itemMembers">
481 <ul class="typedefs itemMembers">
484 <ul class="typedefs itemMembers">
487 <ul class="methods itemMembers">
489 <span class="subtitle">Methods</span>
491 <li data-name="LuCI.Network.Protocol#addDevice"><a href="LuCI.Network.Protocol.html#addDevice">addDevice</a></li>
493 <li data-name="LuCI.Network.Protocol#containsDevice"><a href="LuCI.Network.Protocol.html#containsDevice">containsDevice</a></li>
495 <li data-name="LuCI.Network.Protocol#deleteDevice"><a href="LuCI.Network.Protocol.html#deleteDevice">deleteDevice</a></li>
497 <li data-name="LuCI.Network.Protocol#get"><a href="LuCI.Network.Protocol.html#get">get</a></li>
499 <li data-name="LuCI.Network.Protocol#getDevice"><a href="LuCI.Network.Protocol.html#getDevice">getDevice</a></li>
501 <li data-name="LuCI.Network.Protocol#getDevices"><a href="LuCI.Network.Protocol.html#getDevices">getDevices</a></li>
503 <li data-name="LuCI.Network.Protocol#getDNS6Addrs"><a href="LuCI.Network.Protocol.html#getDNS6Addrs">getDNS6Addrs</a></li>
505 <li data-name="LuCI.Network.Protocol#getDNSAddrs"><a href="LuCI.Network.Protocol.html#getDNSAddrs">getDNSAddrs</a></li>
507 <li data-name="LuCI.Network.Protocol#getErrors"><a href="LuCI.Network.Protocol.html#getErrors">getErrors</a></li>
509 <li data-name="LuCI.Network.Protocol#getExpiry"><a href="LuCI.Network.Protocol.html#getExpiry">getExpiry</a></li>
511 <li data-name="LuCI.Network.Protocol#getGateway6Addr"><a href="LuCI.Network.Protocol.html#getGateway6Addr">getGateway6Addr</a></li>
513 <li data-name="LuCI.Network.Protocol#getGatewayAddr"><a href="LuCI.Network.Protocol.html#getGatewayAddr">getGatewayAddr</a></li>
515 <li data-name="LuCI.Network.Protocol#getI18n"><a href="LuCI.Network.Protocol.html#getI18n">getI18n</a></li>
517 <li data-name="LuCI.Network.Protocol#getIfname"><a href="LuCI.Network.Protocol.html#getIfname">getIfname</a></li>
519 <li data-name="LuCI.Network.Protocol#getIP6Addr"><a href="LuCI.Network.Protocol.html#getIP6Addr">getIP6Addr</a></li>
521 <li data-name="LuCI.Network.Protocol#getIP6Addrs"><a href="LuCI.Network.Protocol.html#getIP6Addrs">getIP6Addrs</a></li>
523 <li data-name="LuCI.Network.Protocol#getIP6Prefix"><a href="LuCI.Network.Protocol.html#getIP6Prefix">getIP6Prefix</a></li>
525 <li data-name="LuCI.Network.Protocol#getIPAddr"><a href="LuCI.Network.Protocol.html#getIPAddr">getIPAddr</a></li>
527 <li data-name="LuCI.Network.Protocol#getIPAddrs"><a href="LuCI.Network.Protocol.html#getIPAddrs">getIPAddrs</a></li>
529 <li data-name="LuCI.Network.Protocol#getL2Device"><a href="LuCI.Network.Protocol.html#getL2Device">getL2Device</a></li>
531 <li data-name="LuCI.Network.Protocol#getL3Device"><a href="LuCI.Network.Protocol.html#getL3Device">getL3Device</a></li>
533 <li data-name="LuCI.Network.Protocol#getMetric"><a href="LuCI.Network.Protocol.html#getMetric">getMetric</a></li>
535 <li data-name="LuCI.Network.Protocol#getName"><a href="LuCI.Network.Protocol.html#getName">getName</a></li>
537 <li data-name="LuCI.Network.Protocol#getNetmask"><a href="LuCI.Network.Protocol.html#getNetmask">getNetmask</a></li>
539 <li data-name="LuCI.Network.Protocol#getOpkgPackage"><a href="LuCI.Network.Protocol.html#getOpkgPackage">getOpkgPackage</a></li>
541 <li data-name="LuCI.Network.Protocol#getProtocol"><a href="LuCI.Network.Protocol.html#getProtocol">getProtocol</a></li>
543 <li data-name="LuCI.Network.Protocol#getType"><a href="LuCI.Network.Protocol.html#getType">getType</a></li>
545 <li data-name="LuCI.Network.Protocol#getUptime"><a href="LuCI.Network.Protocol.html#getUptime">getUptime</a></li>
547 <li data-name="LuCI.Network.Protocol#getZoneName"><a href="LuCI.Network.Protocol.html#getZoneName">getZoneName</a></li>
549 <li data-name="LuCI.Network.Protocol#isAlias"><a href="LuCI.Network.Protocol.html#isAlias">isAlias</a></li>
551 <li data-name="LuCI.Network.Protocol#isBridge"><a href="LuCI.Network.Protocol.html#isBridge">isBridge</a></li>
553 <li data-name="LuCI.Network.Protocol#isDynamic"><a href="LuCI.Network.Protocol.html#isDynamic">isDynamic</a></li>
555 <li data-name="LuCI.Network.Protocol#isEmpty"><a href="LuCI.Network.Protocol.html#isEmpty">isEmpty</a></li>
557 <li data-name="LuCI.Network.Protocol#isFloating"><a href="LuCI.Network.Protocol.html#isFloating">isFloating</a></li>
559 <li data-name="LuCI.Network.Protocol#isInstalled"><a href="LuCI.Network.Protocol.html#isInstalled">isInstalled</a></li>
561 <li data-name="LuCI.Network.Protocol#isUp"><a href="LuCI.Network.Protocol.html#isUp">isUp</a></li>
563 <li data-name="LuCI.Network.Protocol#isVirtual"><a href="LuCI.Network.Protocol.html#isVirtual">isVirtual</a></li>
565 <li data-name="LuCI.Network.Protocol#set"><a href="LuCI.Network.Protocol.html#set">set</a></li>
568 <ul class="events itemMembers">
573 <li class="item" data-name="LuCI.Network.WifiDevice">
575 <a href="LuCI.Network.WifiDevice.html">LuCI.Network.WifiDevice</a>
578 <ul class="members itemMembers">
581 <ul class="typedefs itemMembers">
584 <ul class="typedefs itemMembers">
587 <ul class="methods itemMembers">
589 <span class="subtitle">Methods</span>
591 <li data-name="LuCI.Network.WifiDevice#addWifiNetwork"><a href="LuCI.Network.WifiDevice.html#addWifiNetwork">addWifiNetwork</a></li>
593 <li data-name="LuCI.Network.WifiDevice#deleteWifiNetwork"><a href="LuCI.Network.WifiDevice.html#deleteWifiNetwork">deleteWifiNetwork</a></li>
595 <li data-name="LuCI.Network.WifiDevice#get"><a href="LuCI.Network.WifiDevice.html#get">get</a></li>
597 <li data-name="LuCI.Network.WifiDevice#getHTModes"><a href="LuCI.Network.WifiDevice.html#getHTModes">getHTModes</a></li>
599 <li data-name="LuCI.Network.WifiDevice#getHWModes"><a href="LuCI.Network.WifiDevice.html#getHWModes">getHWModes</a></li>
601 <li data-name="LuCI.Network.WifiDevice#getI18n"><a href="LuCI.Network.WifiDevice.html#getI18n">getI18n</a></li>
603 <li data-name="LuCI.Network.WifiDevice#getName"><a href="LuCI.Network.WifiDevice.html#getName">getName</a></li>
605 <li data-name="LuCI.Network.WifiDevice#getScanList"><a href="LuCI.Network.WifiDevice.html#getScanList">getScanList</a></li>
607 <li data-name="LuCI.Network.WifiDevice#getWifiNetwork"><a href="LuCI.Network.WifiDevice.html#getWifiNetwork">getWifiNetwork</a></li>
609 <li data-name="LuCI.Network.WifiDevice#getWifiNetworks"><a href="LuCI.Network.WifiDevice.html#getWifiNetworks">getWifiNetworks</a></li>
611 <li data-name="LuCI.Network.WifiDevice#isDisabled"><a href="LuCI.Network.WifiDevice.html#isDisabled">isDisabled</a></li>
613 <li data-name="LuCI.Network.WifiDevice#isUp"><a href="LuCI.Network.WifiDevice.html#isUp">isUp</a></li>
615 <li data-name="LuCI.Network.WifiDevice#set"><a href="LuCI.Network.WifiDevice.html#set">set</a></li>
618 <ul class="events itemMembers">
623 <li class="item" data-name="LuCI.Network.WifiNetwork">
625 <a href="LuCI.Network.WifiNetwork.html">LuCI.Network.WifiNetwork</a>
628 <ul class="members itemMembers">
631 <ul class="typedefs itemMembers">
634 <ul class="typedefs itemMembers">
637 <ul class="methods itemMembers">
639 <span class="subtitle">Methods</span>
641 <li data-name="LuCI.Network.WifiNetwork#disconnectClient"><a href="LuCI.Network.WifiNetwork.html#disconnectClient">disconnectClient</a></li>
643 <li data-name="LuCI.Network.WifiNetwork#get"><a href="LuCI.Network.WifiNetwork.html#get">get</a></li>
645 <li data-name="LuCI.Network.WifiNetwork#getActiveBSSID"><a href="LuCI.Network.WifiNetwork.html#getActiveBSSID">getActiveBSSID</a></li>
647 <li data-name="LuCI.Network.WifiNetwork#getActiveEncryption"><a href="LuCI.Network.WifiNetwork.html#getActiveEncryption">getActiveEncryption</a></li>
649 <li data-name="LuCI.Network.WifiNetwork#getActiveMode"><a href="LuCI.Network.WifiNetwork.html#getActiveMode">getActiveMode</a></li>
651 <li data-name="LuCI.Network.WifiNetwork#getActiveModeI18n"><a href="LuCI.Network.WifiNetwork.html#getActiveModeI18n">getActiveModeI18n</a></li>
653 <li data-name="LuCI.Network.WifiNetwork#getActiveSSID"><a href="LuCI.Network.WifiNetwork.html#getActiveSSID">getActiveSSID</a></li>
655 <li data-name="LuCI.Network.WifiNetwork#getAssocList"><a href="LuCI.Network.WifiNetwork.html#getAssocList">getAssocList</a></li>
657 <li data-name="LuCI.Network.WifiNetwork#getBitRate"><a href="LuCI.Network.WifiNetwork.html#getBitRate">getBitRate</a></li>
659 <li data-name="LuCI.Network.WifiNetwork#getBSSID"><a href="LuCI.Network.WifiNetwork.html#getBSSID">getBSSID</a></li>
661 <li data-name="LuCI.Network.WifiNetwork#getChannel"><a href="LuCI.Network.WifiNetwork.html#getChannel">getChannel</a></li>
663 <li data-name="LuCI.Network.WifiNetwork#getCountryCode"><a href="LuCI.Network.WifiNetwork.html#getCountryCode">getCountryCode</a></li>
665 <li data-name="LuCI.Network.WifiNetwork#getDevice"><a href="LuCI.Network.WifiNetwork.html#getDevice">getDevice</a></li>
667 <li data-name="LuCI.Network.WifiNetwork#getFrequency"><a href="LuCI.Network.WifiNetwork.html#getFrequency">getFrequency</a></li>
669 <li data-name="LuCI.Network.WifiNetwork#getI18n"><a href="LuCI.Network.WifiNetwork.html#getI18n">getI18n</a></li>
671 <li data-name="LuCI.Network.WifiNetwork#getID"><a href="LuCI.Network.WifiNetwork.html#getID">getID</a></li>
673 <li data-name="LuCI.Network.WifiNetwork#getIfname"><a href="LuCI.Network.WifiNetwork.html#getIfname">getIfname</a></li>
675 <li data-name="LuCI.Network.WifiNetwork#getMeshID"><a href="LuCI.Network.WifiNetwork.html#getMeshID">getMeshID</a></li>
677 <li data-name="LuCI.Network.WifiNetwork#getMode"><a href="LuCI.Network.WifiNetwork.html#getMode">getMode</a></li>
679 <li data-name="LuCI.Network.WifiNetwork#getName"><a href="LuCI.Network.WifiNetwork.html#getName">getName</a></li>
681 <li data-name="LuCI.Network.WifiNetwork#getNetwork"><a href="LuCI.Network.WifiNetwork.html#getNetwork">getNetwork</a></li>
683 <li data-name="LuCI.Network.WifiNetwork#getNetworkNames"><a href="LuCI.Network.WifiNetwork.html#getNetworkNames">getNetworkNames</a></li>
685 <li data-name="LuCI.Network.WifiNetwork#getNetworks"><a href="LuCI.Network.WifiNetwork.html#getNetworks">getNetworks</a></li>
687 <li data-name="LuCI.Network.WifiNetwork#getNoise"><a href="LuCI.Network.WifiNetwork.html#getNoise">getNoise</a></li>
689 <li data-name="LuCI.Network.WifiNetwork#getShortName"><a href="LuCI.Network.WifiNetwork.html#getShortName">getShortName</a></li>
691 <li data-name="LuCI.Network.WifiNetwork#getSignal"><a href="LuCI.Network.WifiNetwork.html#getSignal">getSignal</a></li>
693 <li data-name="LuCI.Network.WifiNetwork#getSignalLevel"><a href="LuCI.Network.WifiNetwork.html#getSignalLevel">getSignalLevel</a></li>
695 <li data-name="LuCI.Network.WifiNetwork#getSignalPercent"><a href="LuCI.Network.WifiNetwork.html#getSignalPercent">getSignalPercent</a></li>
697 <li data-name="LuCI.Network.WifiNetwork#getSSID"><a href="LuCI.Network.WifiNetwork.html#getSSID">getSSID</a></li>
699 <li data-name="LuCI.Network.WifiNetwork#getTXPower"><a href="LuCI.Network.WifiNetwork.html#getTXPower">getTXPower</a></li>
701 <li data-name="LuCI.Network.WifiNetwork#getTXPowerOffset"><a href="LuCI.Network.WifiNetwork.html#getTXPowerOffset">getTXPowerOffset</a></li>
703 <li data-name="LuCI.Network.WifiNetwork#getWifiDevice"><a href="LuCI.Network.WifiNetwork.html#getWifiDevice">getWifiDevice</a></li>
705 <li data-name="LuCI.Network.WifiNetwork#getWifiDeviceName"><a href="LuCI.Network.WifiNetwork.html#getWifiDeviceName">getWifiDeviceName</a></li>
707 <li data-name="LuCI.Network.WifiNetwork#isClientDisconnectSupported"><a href="LuCI.Network.WifiNetwork.html#isClientDisconnectSupported">isClientDisconnectSupported</a></li>
709 <li data-name="LuCI.Network.WifiNetwork#isDisabled"><a href="LuCI.Network.WifiNetwork.html#isDisabled">isDisabled</a></li>
711 <li data-name="LuCI.Network.WifiNetwork#isUp"><a href="LuCI.Network.WifiNetwork.html#isUp">isUp</a></li>
713 <li data-name="LuCI.Network.WifiNetwork#set"><a href="LuCI.Network.WifiNetwork.html#set">set</a></li>
716 <ul class="events itemMembers">
721 <li class="item" data-name="LuCI.Poll">
723 <a href="LuCI.Poll.html">LuCI.Poll</a>
726 <ul class="members itemMembers">
729 <ul class="typedefs itemMembers">
732 <ul class="typedefs itemMembers">
735 <ul class="methods itemMembers">
737 <span class="subtitle">Methods</span>
739 <li data-name="LuCI.Poll#active"><a href="LuCI.Poll.html#active">active</a></li>
741 <li data-name="LuCI.Poll#add"><a href="LuCI.Poll.html#add">add</a></li>
743 <li data-name="LuCI.Poll#remove"><a href="LuCI.Poll.html#remove">remove</a></li>
745 <li data-name="LuCI.Poll#start"><a href="LuCI.Poll.html#start">start</a></li>
747 <li data-name="LuCI.Poll#stop"><a href="LuCI.Poll.html#stop">stop</a></li>
750 <ul class="events itemMembers">
755 <li class="item" data-name="LuCI.Request">
757 <a href="LuCI.Request.html">LuCI.Request</a>
760 <ul class="members itemMembers">
763 <ul class="typedefs itemMembers">
765 <span class="subtitle">Typedefs</span>
767 <li data-name="LuCI.Request.interceptorFn"><a href="LuCI.Request.html#.interceptorFn">interceptorFn</a></li>
769 <li data-name="LuCI.Request.RequestOptions"><a href="LuCI.Request.html#.RequestOptions">RequestOptions</a></li>
772 <ul class="typedefs itemMembers">
775 <ul class="methods itemMembers">
777 <span class="subtitle">Methods</span>
779 <li data-name="LuCI.Request#addInterceptor"><a href="LuCI.Request.html#addInterceptor">addInterceptor</a></li>
781 <li data-name="LuCI.Request#expandURL"><a href="LuCI.Request.html#expandURL">expandURL</a></li>
783 <li data-name="LuCI.Request#get"><a href="LuCI.Request.html#get">get</a></li>
785 <li data-name="LuCI.Request#post"><a href="LuCI.Request.html#post">post</a></li>
787 <li data-name="LuCI.Request#removeInterceptor"><a href="LuCI.Request.html#removeInterceptor">removeInterceptor</a></li>
789 <li data-name="LuCI.Request#request"><a href="LuCI.Request.html#request">request</a></li>
792 <ul class="events itemMembers">
797 <li class="item" data-name="LuCI.Request.poll">
799 <a href="LuCI.Request.poll.html">LuCI.Request.poll</a>
802 <ul class="members itemMembers">
805 <ul class="typedefs itemMembers">
807 <span class="subtitle">Typedefs</span>
809 <li data-name="LuCI.Request.poll~callbackFn"><a href="LuCI.Request.poll.html#~callbackFn">callbackFn</a></li>
812 <ul class="typedefs itemMembers">
815 <ul class="methods itemMembers">
817 <span class="subtitle">Methods</span>
819 <li data-name="LuCI.Request.poll#active"><a href="LuCI.Request.poll.html#active">active</a></li>
821 <li data-name="LuCI.Request.poll#add"><a href="LuCI.Request.poll.html#add">add</a></li>
823 <li data-name="LuCI.Request.poll#remove"><a href="LuCI.Request.poll.html#remove">remove</a></li>
825 <li data-name="LuCI.Request.poll#start"><a href="LuCI.Request.poll.html#start">start</a></li>
827 <li data-name="LuCI.Request.poll#stop"><a href="LuCI.Request.poll.html#stop">stop</a></li>
830 <ul class="events itemMembers">
835 <li class="item" data-name="LuCI.Response">
837 <a href="LuCI.Response.html">LuCI.Response</a>
840 <ul class="members itemMembers">
842 <span class="subtitle">Members</span>
844 <li data-name="LuCI.Response#duration"><a href="LuCI.Response.html#duration">duration</a></li>
846 <li data-name="LuCI.Response#headers"><a href="LuCI.Response.html#headers">headers</a></li>
848 <li data-name="LuCI.Response#ok"><a href="LuCI.Response.html#ok">ok</a></li>
850 <li data-name="LuCI.Response#status"><a href="LuCI.Response.html#status">status</a></li>
852 <li data-name="LuCI.Response#statusText"><a href="LuCI.Response.html#statusText">statusText</a></li>
854 <li data-name="LuCI.Response#url"><a href="LuCI.Response.html#url">url</a></li>
857 <ul class="typedefs itemMembers">
860 <ul class="typedefs itemMembers">
863 <ul class="methods itemMembers">
865 <span class="subtitle">Methods</span>
867 <li data-name="LuCI.Response#clone"><a href="LuCI.Response.html#clone">clone</a></li>
869 <li data-name="LuCI.Response#json"><a href="LuCI.Response.html#json">json</a></li>
871 <li data-name="LuCI.Response#text"><a href="LuCI.Response.html#text">text</a></li>
874 <ul class="events itemMembers">
879 <li class="item" data-name="LuCI.rpc">
881 <a href="LuCI.rpc.html">LuCI.rpc</a>
884 <ul class="members itemMembers">
887 <ul class="typedefs itemMembers">
889 <span class="subtitle">Typedefs</span>
891 <li data-name="LuCI.rpc.DeclareOptions"><a href="LuCI.rpc.html#.DeclareOptions">DeclareOptions</a></li>
893 <li data-name="LuCI.rpc~filterFn"><a href="LuCI.rpc.html#~filterFn">filterFn</a></li>
895 <li data-name="LuCI.rpc~interceptorFn"><a href="LuCI.rpc.html#~interceptorFn">interceptorFn</a></li>
897 <li data-name="LuCI.rpc~invokeFn"><a href="LuCI.rpc.html#~invokeFn">invokeFn</a></li>
900 <ul class="typedefs itemMembers">
903 <ul class="methods itemMembers">
905 <span class="subtitle">Methods</span>
907 <li data-name="LuCI.rpc#addInterceptor"><a href="LuCI.rpc.html#addInterceptor">addInterceptor</a></li>
909 <li data-name="LuCI.rpc#declare"><a href="LuCI.rpc.html#declare">declare</a></li>
911 <li data-name="LuCI.rpc#getBaseURL"><a href="LuCI.rpc.html#getBaseURL">getBaseURL</a></li>
913 <li data-name="LuCI.rpc#getSessionID"><a href="LuCI.rpc.html#getSessionID">getSessionID</a></li>
915 <li data-name="LuCI.rpc#getStatusText"><a href="LuCI.rpc.html#getStatusText">getStatusText</a></li>
917 <li data-name="LuCI.rpc#list"><a href="LuCI.rpc.html#list">list</a></li>
919 <li data-name="LuCI.rpc#removeInterceptor"><a href="LuCI.rpc.html#removeInterceptor">removeInterceptor</a></li>
921 <li data-name="LuCI.rpc#setBaseURL"><a href="LuCI.rpc.html#setBaseURL">setBaseURL</a></li>
923 <li data-name="LuCI.rpc#setSessionID"><a href="LuCI.rpc.html#setSessionID">setSessionID</a></li>
926 <ul class="events itemMembers">
931 <li class="item" data-name="LuCI.uci">
933 <a href="LuCI.uci.html">LuCI.uci</a>
936 <ul class="members itemMembers">
939 <ul class="typedefs itemMembers">
941 <span class="subtitle">Typedefs</span>
943 <li data-name="LuCI.uci.ChangeRecord"><a href="LuCI.uci.html#.ChangeRecord">ChangeRecord</a></li>
945 <li data-name="LuCI.uci.SectionObject"><a href="LuCI.uci.html#.SectionObject">SectionObject</a></li>
947 <li data-name="LuCI.uci~sectionsFn"><a href="LuCI.uci.html#~sectionsFn">sectionsFn</a></li>
950 <ul class="typedefs itemMembers">
953 <ul class="methods itemMembers">
955 <span class="subtitle">Methods</span>
957 <li data-name="LuCI.uci#add"><a href="LuCI.uci.html#add">add</a></li>
959 <li data-name="LuCI.uci#apply"><a href="LuCI.uci.html#apply">apply</a></li>
961 <li data-name="LuCI.uci#changes"><a href="LuCI.uci.html#changes">changes</a></li>
963 <li data-name="LuCI.uci#createSID"><a href="LuCI.uci.html#createSID">createSID</a></li>
965 <li data-name="LuCI.uci#get"><a href="LuCI.uci.html#get">get</a></li>
967 <li data-name="LuCI.uci#get_first"><a href="LuCI.uci.html#get_first">get_first</a></li>
969 <li data-name="LuCI.uci#load"><a href="LuCI.uci.html#load">load</a></li>
971 <li data-name="LuCI.uci#move"><a href="LuCI.uci.html#move">move</a></li>
973 <li data-name="LuCI.uci#remove"><a href="LuCI.uci.html#remove">remove</a></li>
975 <li data-name="LuCI.uci#resolveSID"><a href="LuCI.uci.html#resolveSID">resolveSID</a></li>
977 <li data-name="LuCI.uci#save"><a href="LuCI.uci.html#save">save</a></li>
979 <li data-name="LuCI.uci#sections"><a href="LuCI.uci.html#sections">sections</a></li>
981 <li data-name="LuCI.uci#set"><a href="LuCI.uci.html#set">set</a></li>
983 <li data-name="LuCI.uci#set_first"><a href="LuCI.uci.html#set_first">set_first</a></li>
985 <li data-name="LuCI.uci#unload"><a href="LuCI.uci.html#unload">unload</a></li>
987 <li data-name="LuCI.uci#unset"><a href="LuCI.uci.html#unset">unset</a></li>
989 <li data-name="LuCI.uci#unset_first"><a href="LuCI.uci.html#unset_first">unset_first</a></li>
992 <ul class="events itemMembers">
997 <li class="item" data-name="LuCI.view">
999 <a href="LuCI.view.html">LuCI.view</a>
1002 <ul class="members itemMembers">
1005 <ul class="typedefs itemMembers">
1008 <ul class="typedefs itemMembers">
1011 <ul class="methods itemMembers">
1013 <span class="subtitle">Methods</span>
1015 <li data-name="LuCI.view#addFooter"><a href="LuCI.view.html#addFooter">addFooter</a></li>
1017 <li data-name="LuCI.view#handleReset"><a href="LuCI.view.html#handleReset">handleReset</a></li>
1019 <li data-name="LuCI.view#handleSave"><a href="LuCI.view.html#handleSave">handleSave</a></li>
1021 <li data-name="LuCI.view#handleSaveApply"><a href="LuCI.view.html#handleSaveApply">handleSaveApply</a></li>
1023 <li data-name="LuCI.view#load"><a href="LuCI.view.html#load">load</a></li>
1025 <li data-name="LuCI.view#render"><a href="LuCI.view.html#render">render</a></li>
1028 <ul class="events itemMembers">
1033 <li class="item" data-name="LuCI.XHR">
1034 <span class="title">
1035 <a href="LuCI.XHR.html">LuCI.XHR</a>
1038 <ul class="members itemMembers">
1041 <ul class="typedefs itemMembers">
1044 <ul class="typedefs itemMembers">
1047 <ul class="methods itemMembers">
1049 <span class="subtitle">Methods</span>
1051 <li data-name="LuCI.XHR#abort"><a href="LuCI.XHR.html#abort">abort</a></li>
1053 <li data-name="LuCI.XHR#busy"><a href="LuCI.XHR.html#busy">busy</a></li>
1055 <li data-name="LuCI.XHR#cancel"><a href="LuCI.XHR.html#cancel">cancel</a></li>
1057 <li data-name="LuCI.XHR#get"><a href="LuCI.XHR.html#get">get</a></li>
1059 <li data-name="LuCI.XHR#post"><a href="LuCI.XHR.html#post">post</a></li>
1061 <li data-name="LuCI.XHR#send_form"><a href="LuCI.XHR.html#send_form">send_form</a></li>
1064 <ul class="events itemMembers">
1072 <h1 class="page-title" data-filename="network.js.html">Source: network.js</h1>
1079 <pre id="source-code" class="prettyprint source "><code>'use strict';
1082 'require validation';
1084 var proto_errors = {
1085 CONNECT_FAILED: _('Connection attempt failed'),
1086 INVALID_ADDRESS: _('IP address in invalid'),
1087 INVALID_GATEWAY: _('Gateway address is invalid'),
1088 INVALID_LOCAL_ADDRESS: _('Local IP address is invalid'),
1089 MISSING_ADDRESS: _('IP address is missing'),
1090 MISSING_PEER_ADDRESS: _('Peer address is missing'),
1091 NO_DEVICE: _('Network device is not present'),
1092 NO_IFACE: _('Unable to determine device name'),
1093 NO_IFNAME: _('Unable to determine device name'),
1094 NO_WAN_ADDRESS: _('Unable to determine external IP address'),
1095 NO_WAN_LINK: _('Unable to determine upstream interface'),
1096 PEER_RESOLVE_FAIL: _('Unable to resolve peer host name'),
1097 PIN_FAILED: _('PIN code rejected')
1100 var iface_patterns_ignore = [
1116 var iface_patterns_wireless = [
1123 var iface_patterns_virtual = [ ];
1125 var callLuciNetworkDevices = rpc.declare({
1127 method: 'getNetworkDevices',
1131 var callLuciWirelessDevices = rpc.declare({
1133 method: 'getWirelessDevices',
1137 var callLuciBoardJSON = rpc.declare({
1139 method: 'getBoardJSON'
1142 var callLuciHostHints = rpc.declare({
1144 method: 'getHostHints',
1148 var callIwinfoAssoclist = rpc.declare({
1150 method: 'assoclist',
1151 params: [ 'device', 'mac' ],
1152 expect: { results: [] }
1155 var callIwinfoScan = rpc.declare({
1158 params: [ 'device' ],
1160 expect: { results: [] }
1163 var callNetworkInterfaceDump = rpc.declare({
1164 object: 'network.interface',
1166 expect: { 'interface': [] }
1169 var callNetworkProtoHandlers = rpc.declare({
1171 method: 'get_proto_handlers',
1180 function getProtocolHandlers(cache) {
1181 return callNetworkProtoHandlers().then(function(protos) {
1182 /* Register "none" protocol */
1183 if (!protos.hasOwnProperty('none'))
1184 Object.assign(protos, { none: { no_device: false } });
1186 /* Hack: emulate relayd protocol */
1187 if (!protos.hasOwnProperty('relay'))
1188 Object.assign(protos, { relay: { no_device: true } });
1190 Object.assign(_protospecs, protos);
1192 return Promise.all(Object.keys(protos).map(function(p) {
1193 return Promise.resolve(L.require('protocol.%s'.format(p))).catch(function(err) {
1194 if (L.isObject(err) && err.name != 'NetworkError')
1197 })).then(function() {
1200 }).catch(function() {
1205 function getWifiStateBySid(sid) {
1206 var s = uci.get('wireless', sid);
1208 if (s != null && s['.type'] == 'wifi-iface') {
1209 for (var radioname in _state.radios) {
1210 for (var i = 0; i < _state.radios[radioname].interfaces.length; i++) {
1211 var netstate = _state.radios[radioname].interfaces[i];
1213 if (typeof(netstate.section) != 'string')
1216 var s2 = uci.get('wireless', netstate.section);
1218 if (s2 != null && s['.type'] == s2['.type'] && s['.name'] == s2['.name']) {
1219 if (s2['.anonymous'] == false && netstate.section.charAt(0) == '@')
1222 return [ radioname, _state.radios[radioname], netstate ];
1231 function getWifiStateByIfname(ifname) {
1232 for (var radioname in _state.radios) {
1233 for (var i = 0; i < _state.radios[radioname].interfaces.length; i++) {
1234 var netstate = _state.radios[radioname].interfaces[i];
1236 if (typeof(netstate.ifname) != 'string')
1239 if (netstate.ifname == ifname)
1240 return [ radioname, _state.radios[radioname], netstate ];
1247 function isWifiIfname(ifname) {
1248 for (var i = 0; i < iface_patterns_wireless.length; i++)
1249 if (iface_patterns_wireless[i].test(ifname))
1255 function getWifiSidByNetid(netid) {
1256 var m = /^(\w+)\.network(\d+)$/.exec(netid);
1258 var sections = uci.sections('wireless', 'wifi-iface');
1259 for (var i = 0, n = 0; i < sections.length; i++) {
1260 if (sections[i].device != m[1])
1264 return sections[i]['.name'];
1271 function getWifiSidByIfname(ifname) {
1272 var sid = getWifiSidByNetid(ifname);
1277 var res = getWifiStateByIfname(ifname);
1279 if (res != null && L.isObject(res[2]) && typeof(res[2].section) == 'string')
1280 return res[2].section;
1285 function getWifiNetidBySid(sid) {
1286 var s = uci.get('wireless', sid);
1287 if (s != null && s['.type'] == 'wifi-iface') {
1288 var radioname = s.device;
1289 if (typeof(s.device) == 'string') {
1290 var i = 0, netid = null, sections = uci.sections('wireless', 'wifi-iface');
1291 for (var i = 0, n = 0; i < sections.length; i++) {
1292 if (sections[i].device != s.device)
1297 if (sections[i]['.name'] != s['.name'])
1300 return [ '%s.network%d'.format(s.device, n), s.device ];
1309 function getWifiNetidByNetname(name) {
1310 var sections = uci.sections('wireless', 'wifi-iface');
1311 for (var i = 0; i < sections.length; i++) {
1312 if (typeof(sections[i].network) != 'string')
1315 var nets = sections[i].network.split(/\s+/);
1316 for (var j = 0; j < nets.length; j++) {
1317 if (nets[j] != name)
1320 return getWifiNetidBySid(sections[i]['.name']);
1327 function isVirtualIfname(ifname) {
1328 for (var i = 0; i < iface_patterns_virtual.length; i++)
1329 if (iface_patterns_virtual[i].test(ifname))
1335 function isIgnoredIfname(ifname) {
1336 for (var i = 0; i < iface_patterns_ignore.length; i++)
1337 if (iface_patterns_ignore[i].test(ifname))
1343 function appendValue(config, section, option, value) {
1344 var values = uci.get(config, section, option),
1345 isArray = Array.isArray(values),
1348 if (isArray == false)
1349 values = L.toArray(values);
1351 if (values.indexOf(value) == -1) {
1356 uci.set(config, section, option, isArray ? values : values.join(' '));
1361 function removeValue(config, section, option, value) {
1362 var values = uci.get(config, section, option),
1363 isArray = Array.isArray(values),
1366 if (isArray == false)
1367 values = L.toArray(values);
1369 for (var i = values.length - 1; i >= 0; i--) {
1370 if (values[i] == value) {
1371 values.splice(i, 1);
1376 if (values.length > 0)
1377 uci.set(config, section, option, isArray ? values : values.join(' '));
1379 uci.unset(config, section, option);
1384 function prefixToMask(bits, v6) {
1385 var w = v6 ? 128 : 32,
1391 for (var i = 0; i < w / 16; i++) {
1392 var b = Math.min(16, bits);
1393 m.push((0xffff << (16 - b)) & 0xffff);
1398 return String.prototype.format.apply('%x:%x:%x:%x:%x:%x:%x:%x', m).replace(/:0(?::0)+$/, '::');
1400 return '%d.%d.%d.%d'.format(m[0] >>> 8, m[0] & 0xff, m[1] >>> 8, m[1] & 0xff);
1403 function maskToPrefix(mask, v6) {
1404 var m = v6 ? validation.parseIPv6(mask) : validation.parseIPv4(mask);
1411 for (var i = 0, z = false; i < m.length; i++) {
1414 while (!z && (m[i] & (v6 ? 0x8000 : 0x80))) {
1415 m[i] = (m[i] << 1) & (v6 ? 0xffff : 0xff);
1426 function initNetworkState(refresh) {
1427 if (_state == null || refresh) {
1428 _init = _init || Promise.all([
1429 L.resolveDefault(callNetworkInterfaceDump(), []),
1430 L.resolveDefault(callLuciBoardJSON(), {}),
1431 L.resolveDefault(callLuciNetworkDevices(), {}),
1432 L.resolveDefault(callLuciWirelessDevices(), {}),
1433 L.resolveDefault(callLuciHostHints(), {}),
1434 getProtocolHandlers(),
1435 uci.load(['network', 'wireless', 'luci'])
1436 ]).then(function(data) {
1437 var netifd_ifaces = data[0],
1438 board_json = data[1],
1439 luci_devs = data[2];
1442 isTunnel: {}, isBridge: {}, isSwitch: {}, isWifi: {},
1443 ifaces: netifd_ifaces, radios: data[3], hosts: data[4],
1444 netdevs: {}, bridges: {}, switches: {}, hostapd: {}
1447 for (var name in luci_devs) {
1448 var dev = luci_devs[name];
1450 if (isVirtualIfname(name))
1451 s.isTunnel[name] = true;
1453 if (!s.isTunnel[name] && isIgnoredIfname(name))
1456 s.netdevs[name] = s.netdevs[name] || {
1470 if (Array.isArray(dev.ipaddrs))
1471 for (var i = 0; i < dev.ipaddrs.length; i++)
1472 s.netdevs[name].ipaddrs.push(dev.ipaddrs[i].address + '/' + dev.ipaddrs[i].netmask);
1474 if (Array.isArray(dev.ip6addrs))
1475 for (var i = 0; i < dev.ip6addrs.length; i++)
1476 s.netdevs[name].ip6addrs.push(dev.ip6addrs[i].address + '/' + dev.ip6addrs[i].netmask);
1479 for (var name in luci_devs) {
1480 var dev = luci_devs[name];
1492 for (var i = 0; dev.ports && i < dev.ports.length; i++) {
1493 var subdev = s.netdevs[dev.ports[i]];
1498 b.ifnames.push(subdev);
1502 s.bridges[name] = b;
1503 s.isBridge[name] = true;
1506 if (L.isObject(board_json.switch)) {
1507 for (var switchname in board_json.switch) {
1508 var layout = board_json.switch[switchname],
1515 if (L.isObject(layout) && Array.isArray(layout.ports)) {
1516 for (var i = 0, port; (port = layout.ports[i]) != null; i++) {
1517 if (typeof(port) == 'object' && typeof(port.num) == 'number' &&
1518 (typeof(port.role) == 'string' || typeof(port.device) == 'string')) {
1521 role: port.role || 'cpu',
1522 index: (port.index != null) ? port.index : port.num
1525 if (port.device != null) {
1526 spec.device = port.device;
1527 spec.tagged = spec.need_tag;
1528 netdevs[port.num] = port.device;
1533 if (port.role != null)
1534 nports[port.role] = (nports[port.role] || 0) + 1;
1538 ports.sort(function(a, b) {
1539 if (a.role != b.role)
1540 return (a.role < b.role) ? -1 : 1;
1542 return (a.index - b.index);
1545 for (var i = 0, port; (port = ports[i]) != null; i++) {
1546 if (port.role != role) {
1552 port.label = 'CPU (%s)'.format(port.device);
1553 else if (nports[role] > 1)
1554 port.label = '%s %d'.format(role.toUpperCase(), pnum++);
1556 port.label = role.toUpperCase();
1562 s.switches[switchname] = {
1570 if (L.isObject(board_json.dsl) && L.isObject(board_json.dsl.modem)) {
1571 s.hasDSLModem = board_json.dsl.modem;
1578 if (L.isObject(s.radios))
1579 for (var radio in s.radios)
1580 if (L.isObject(s.radios[radio]) && Array.isArray(s.radios[radio].interfaces))
1581 for (var i = 0; i < s.radios[radio].interfaces.length; i++)
1582 if (L.isObject(s.radios[radio].interfaces[i]) && s.radios[radio].interfaces[i].ifname)
1583 objects.push('hostapd.%s'.format(s.radios[radio].interfaces[i].ifname));
1585 return (objects.length ? L.resolveDefault(rpc.list.apply(rpc, objects), {}) : Promise.resolve({})).then(function(res) {
1586 for (var k in res) {
1587 var m = k.match(/^hostapd\.(.+)$/);
1589 s.hostapd[m[1]] = res[k];
1592 return (_state = s);
1597 return (_state != null ? Promise.resolve(_state) : _init);
1600 function ifnameOf(obj) {
1601 if (obj instanceof Protocol)
1602 return obj.getIfname();
1603 else if (obj instanceof Device)
1604 return obj.getName();
1605 else if (obj instanceof WifiDevice)
1606 return obj.getName();
1607 else if (obj instanceof WifiNetwork)
1608 return obj.getIfname();
1609 else if (typeof(obj) == 'string')
1610 return obj.replace(/:.+$/, '');
1615 function networkSort(a, b) {
1616 return a.getName() > b.getName();
1619 function deviceSort(a, b) {
1620 var typeWeigth = { wifi: 2, alias: 3 },
1621 weightA = typeWeigth[a.getType()] || 1,
1622 weightB = typeWeigth[b.getType()] || 1;
1624 if (weightA != weightB)
1625 return weightA - weightB;
1627 return a.getName() > b.getName();
1630 function formatWifiEncryption(enc) {
1631 if (!L.isObject(enc))
1637 var ciphers = Array.isArray(enc.ciphers)
1638 ? enc.ciphers.map(function(c) { return c.toUpperCase() }) : [ 'NONE' ];
1640 if (Array.isArray(enc.wep)) {
1641 var has_open = false,
1644 for (var i = 0; i < enc.wep.length; i++)
1645 if (enc.wep[i] == 'open')
1647 else if (enc.wep[i] == 'shared')
1650 if (has_open && has_shared)
1651 return 'WEP Open/Shared (%s)'.format(ciphers.join(', '));
1653 return 'WEP Open System (%s)'.format(ciphers.join(', '));
1654 else if (has_shared)
1655 return 'WEP Shared Auth (%s)'.format(ciphers.join(', '));
1660 if (Array.isArray(enc.wpa)) {
1662 suites = Array.isArray(enc.authentication)
1663 ? enc.authentication.map(function(a) { return a.toUpperCase() }) : [ 'NONE' ];
1665 for (var i = 0; i < enc.wpa.length; i++)
1666 switch (enc.wpa[i]) {
1668 versions.push('WPA');
1672 versions.push('WPA%d'.format(enc.wpa[i]));
1676 if (versions.length > 1)
1677 return 'mixed %s %s (%s)'.format(versions.join('/'), suites.join(', '), ciphers.join(', '));
1679 return '%s %s (%s)'.format(versions[0], suites.join(', '), ciphers.join(', '));
1685 function enumerateNetworks() {
1686 var uciInterfaces = uci.sections('network', 'interface'),
1689 for (var i = 0; i < uciInterfaces.length; i++)
1690 networks[uciInterfaces[i]['.name']] = this.instantiateNetwork(uciInterfaces[i]['.name']);
1692 for (var i = 0; i < _state.ifaces.length; i++)
1693 if (networks[_state.ifaces[i].interface] == null)
1694 networks[_state.ifaces[i].interface] =
1695 this.instantiateNetwork(_state.ifaces[i].interface, _state.ifaces[i].proto);
1699 for (var network in networks)
1700 if (networks.hasOwnProperty(network))
1701 rv.push(networks[network]);
1703 rv.sort(networkSort);
1709 var Hosts, Network, Protocol, Device, WifiDevice, WifiNetwork;
1717 * The `LuCI.Network` class combines data from multiple `ubus` apis to
1718 * provide an abstraction of the current network configuration state.
1720 * It provides methods to enumerate interfaces and devices, to query
1721 * current configuration details and to manipulate settings.
1723 Network = L.Class.extend(/** @lends LuCI.Network.prototype */ {
1725 * Converts the given prefix size in bits to a netmask.
1729 * @param {number} bits
1730 * The prefix size in bits.
1732 * @param {boolean} [v6=false]
1733 * Whether to convert the bits value into an IPv4 netmask (`false`) or
1734 * an IPv6 netmask (`true`).
1736 * @returns {null|string}
1737 * Returns a string containing the netmask corresponding to the bit count
1738 * or `null` when the given amount of bits exceeds the maximum possible
1739 * value of `32` for IPv4 or `128` for IPv6.
1741 prefixToMask: prefixToMask,
1744 * Converts the given netmask to a prefix size in bits.
1748 * @param {string} netmask
1749 * The netmask to convert into a bit count.
1751 * @param {boolean} [v6=false]
1752 * Whether to parse the given netmask as IPv4 (`false`) or IPv6 (`true`)
1755 * @returns {null|number}
1756 * Returns the number of prefix bits contained in the netmask or `null`
1757 * if the given netmask value was invalid.
1759 maskToPrefix: maskToPrefix,
1762 * An encryption entry describes active wireless encryption settings
1763 * such as the used key management protocols, active ciphers and
1764 * protocol versions.
1766 * @typedef {Object<string, boolean|Array<number|string>>} LuCI.Network.WifiEncryption
1767 * @memberof LuCI.Network
1769 * @property {boolean} enabled
1770 * Specifies whether any kind of encryption, such as `WEP` or `WPA` is
1771 * enabled. If set to `false`, then no encryption is active and the
1772 * corresponding network is open.
1774 * @property {string[]} [wep]
1775 * When the `wep` property exists, the network uses WEP encryption.
1776 * In this case, the property is set to an array of active WEP modes
1777 * which might be either `open`, `shared` or both.
1779 * @property {number[]} [wpa]
1780 * When the `wpa` property exists, the network uses WPA security.
1781 * In this case, the property is set to an array containing the WPA
1782 * protocol versions used, e.g. `[ 1, 2 ]` for WPA/WPA2 mixed mode or
1783 * `[ 3 ]` for WPA3-SAE.
1785 * @property {string[]} [authentication]
1786 * The `authentication` property only applies to WPA encryption and
1787 * is defined when the `wpa` property is set as well. It points to
1788 * an array of active authentication suites used by the network, e.g.
1789 * `[ "psk" ]` for a WPA(2)-PSK network or `[ "psk", "sae" ]` for
1790 * mixed WPA2-PSK/WPA3-SAE encryption.
1792 * @property {string[]} [ciphers]
1793 * If either WEP or WPA encryption is active, then the `ciphers`
1794 * property will be set to an array describing the active encryption
1795 * ciphers used by the network, e.g. `[ "tkip", "ccmp" ]` for a
1796 * WPA/WPA2-PSK mixed network or `[ "wep-40", "wep-104" ]` for an
1801 * Converts a given {@link LuCI.Network.WifiEncryption encryption entry}
1802 * into a human readable string such as `mixed WPA/WPA2 PSK (TKIP, CCMP)`
1803 * or `WPA3 SAE (CCMP)`.
1807 * @param {LuCI.Network.WifiEncryption} encryption
1808 * The wireless encryption entry to convert.
1810 * @returns {null|string}
1811 * Returns the description string for the given encryption entry or
1812 * `null` if the given entry was invalid.
1814 formatWifiEncryption: formatWifiEncryption,
1817 * Flushes the local network state cache and fetches updated information
1818 * from the remote `ubus` apis.
1820 * @returns {Promise<Object>}
1821 * Returns a promise resolving to the internal network state object.
1823 flushCache: function() {
1824 initNetworkState(true);
1829 * Instantiates the given {@link LuCI.Network.Protocol Protocol} backend,
1830 * optionally using the given network name.
1832 * @param {string} protoname
1833 * The protocol backend to use, e.g. `static` or `dhcp`.
1835 * @param {string} [netname=__dummy__]
1836 * The network name to use for the instantiated protocol. This should be
1837 * usually set to one of the interfaces described in /etc/config/network
1838 * but it is allowed to omit it, e.g. to query protocol capabilities
1839 * without the need for an existing interface.
1841 * @returns {null|LuCI.Network.Protocol}
1842 * Returns the instantiated protocol backend class or `null` if the given
1843 * protocol isn't known.
1845 getProtocol: function(protoname, netname) {
1846 var v = _protocols[protoname];
1848 return new v(netname || '__dummy__');
1854 * Obtains instances of all known {@link LuCI.Network.Protocol Protocol}
1857 * @returns {Array<LuCI.Network.Protocol>}
1858 * Returns an array of protocol class instances.
1860 getProtocols: function() {
1863 for (var protoname in _protocols)
1864 rv.push(new _protocols[protoname]('__dummy__'));
1870 * Registers a new {@link LuCI.Network.Protocol Protocol} subclass
1871 * with the given methods and returns the resulting subclass value.
1873 * This functions internally calls
1874 * {@link LuCI.Class.extend Class.extend()} on the `Network.Protocol`
1877 * @param {string} protoname
1878 * The name of the new protocol to register.
1880 * @param {Object<string, *>} methods
1881 * The member methods and values of the new `Protocol` subclass to
1882 * be passed to {@link LuCI.Class.extend Class.extend()}.
1884 * @returns {LuCI.Network.Protocol}
1885 * Returns the new `Protocol` subclass.
1887 registerProtocol: function(protoname, methods) {
1888 var spec = L.isObject(_protospecs) ? _protospecs[protoname] : null;
1889 var proto = Protocol.extend(Object.assign({
1890 getI18n: function() {
1894 isFloating: function() {
1898 isVirtual: function() {
1899 return (L.isObject(spec) && spec.no_device == true);
1902 renderFormOptions: function(section) {
1906 __init__: function(name) {
1910 getProtocol: function() {
1915 _protocols[protoname] = proto;
1921 * Registers a new regular expression pattern to recognize
1922 * virtual interfaces.
1924 * @param {RegExp} pat
1925 * A `RegExp` instance to match a virtual interface name
1926 * such as `6in4-wan` or `tun0`.
1928 registerPatternVirtual: function(pat) {
1929 iface_patterns_virtual.push(pat);
1933 * Registers a new human readable translation string for a `Protocol`
1936 * @param {string} code
1937 * The `ubus` protocol error code to register a translation for, e.g.
1940 * @param {string} message
1941 * The message to use as translation for the given protocol error code.
1943 * @returns {boolean}
1944 * Returns `true` if the error code description has been added or `false`
1945 * if either the arguments were invalid or if there already was a
1946 * description for the given code.
1948 registerErrorCode: function(code, message) {
1949 if (typeof(code) == 'string' &&
1950 typeof(message) == 'string' &&
1951 !proto_errors.hasOwnProperty(code)) {
1952 proto_errors[code] = message;
1960 * Adds a new network of the given name and update it with the given
1961 * uci option values.
1963 * If a network with the given name already exist but is empty, then
1964 * this function will update its option, otherwise it will do nothing.
1966 * @param {string} name
1967 * The name of the network to add. Must be in the format `[a-zA-Z0-9_]+`.
1969 * @param {Object<string, string|string[]>} [options]
1970 * An object of uci option values to set on the new network or to
1971 * update in an existing, empty network.
1973 * @returns {Promise<null|LuCI.Network.Protocol>}
1974 * Returns a promise resolving to the `Protocol` subclass instance
1975 * describing the added network or resolving to `null` if the name
1976 * was invalid or if a non-empty network of the given name already
1979 addNetwork: function(name, options) {
1980 return this.getNetwork(name).then(L.bind(function(existingNetwork) {
1981 if (name != null && /^[a-zA-Z0-9_]+$/.test(name) && existingNetwork == null) {
1982 var sid = uci.add('network', 'interface', name);
1985 if (L.isObject(options))
1986 for (var key in options)
1987 if (options.hasOwnProperty(key))
1988 uci.set('network', sid, key, options[key]);
1990 return this.instantiateNetwork(sid);
1993 else if (existingNetwork != null && existingNetwork.isEmpty()) {
1994 if (L.isObject(options))
1995 for (var key in options)
1996 if (options.hasOwnProperty(key))
1997 existingNetwork.set(key, options[key]);
1999 return existingNetwork;
2005 * Get a {@link LuCI.Network.Protocol Protocol} instance describing
2006 * the network with the given name.
2008 * @param {string} name
2009 * The logical interface name of the network get, e.g. `lan` or `wan`.
2011 * @returns {Promise<null|LuCI.Network.Protocol>}
2012 * Returns a promise resolving to a
2013 * {@link LuCI.Network.Protocol Protocol} subclass instance describing
2014 * the network or `null` if the network did not exist.
2016 getNetwork: function(name) {
2017 return initNetworkState().then(L.bind(function() {
2018 var section = (name != null) ? uci.get('network', name) : null;
2020 if (section != null && section['.type'] == 'interface') {
2021 return this.instantiateNetwork(name);
2023 else if (name != null) {
2024 for (var i = 0; i < _state.ifaces.length; i++)
2025 if (_state.ifaces[i].interface == name)
2026 return this.instantiateNetwork(name, _state.ifaces[i].proto);
2034 * Gets an array containing all known networks.
2036 * @returns {Promise<Array<LuCI.Network.Protocol>>}
2037 * Returns a promise resolving to a name-sorted array of
2038 * {@link LuCI.Network.Protocol Protocol} subclass instances
2039 * describing all known networks.
2041 getNetworks: function() {
2042 return initNetworkState().then(L.bind(enumerateNetworks, this));
2046 * Deletes the given network and its references from the network and
2047 * firewall configuration.
2049 * @param {string} name
2050 * The name of the network to delete.
2052 * @returns {Promise<boolean>}
2053 * Returns a promise resolving to either `true` if the network and
2054 * references to it were successfully deleted from the configuration or
2055 * `false` if the given network could not be found.
2057 deleteNetwork: function(name) {
2058 var requireFirewall = Promise.resolve(L.require('firewall')).catch(function() {});
2060 return Promise.all([ requireFirewall, initNetworkState() ]).then(function() {
2061 var uciInterface = uci.get('network', name);
2063 if (uciInterface != null && uciInterface['.type'] == 'interface') {
2064 uci.remove('network', name);
2066 uci.sections('luci', 'ifstate', function(s) {
2067 if (s.interface == name)
2068 uci.remove('luci', s['.name']);
2071 uci.sections('network', 'alias', function(s) {
2072 if (s.interface == name)
2073 uci.remove('network', s['.name']);
2076 uci.sections('network', 'route', function(s) {
2077 if (s.interface == name)
2078 uci.remove('network', s['.name']);
2081 uci.sections('network', 'route6', function(s) {
2082 if (s.interface == name)
2083 uci.remove('network', s['.name']);
2086 uci.sections('wireless', 'wifi-iface', function(s) {
2087 var networks = L.toArray(s.network).filter(function(network) { return network != name });
2089 if (networks.length > 0)
2090 uci.set('wireless', s['.name'], 'network', networks.join(' '));
2092 uci.unset('wireless', s['.name'], 'network');
2096 return L.firewall.deleteNetwork(name).then(function() { return true });
2106 * Rename the given network and its references to a new name.
2108 * @param {string} oldName
2109 * The current name of the network.
2111 * @param {string} newName
2112 * The name to rename the network to, must be in the format
2115 * @returns {Promise<boolean>}
2116 * Returns a promise resolving to either `true` if the network was
2117 * successfully renamed or `false` if the new name was invalid, if
2118 * a network with the new name already exists or if the network to
2119 * rename could not be found.
2121 renameNetwork: function(oldName, newName) {
2122 return initNetworkState().then(function() {
2123 if (newName == null || !/^[a-zA-Z0-9_]+$/.test(newName) || uci.get('network', newName) != null)
2126 var oldNetwork = uci.get('network', oldName);
2128 if (oldNetwork == null || oldNetwork['.type'] != 'interface')
2131 var sid = uci.add('network', 'interface', newName);
2133 for (var key in oldNetwork)
2134 if (oldNetwork.hasOwnProperty(key) && key.charAt(0) != '.')
2135 uci.set('network', sid, key, oldNetwork[key]);
2137 uci.sections('luci', 'ifstate', function(s) {
2138 if (s.interface == oldName)
2139 uci.set('luci', s['.name'], 'interface', newName);
2142 uci.sections('network', 'alias', function(s) {
2143 if (s.interface == oldName)
2144 uci.set('network', s['.name'], 'interface', newName);
2147 uci.sections('network', 'route', function(s) {
2148 if (s.interface == oldName)
2149 uci.set('network', s['.name'], 'interface', newName);
2152 uci.sections('network', 'route6', function(s) {
2153 if (s.interface == oldName)
2154 uci.set('network', s['.name'], 'interface', newName);
2157 uci.sections('wireless', 'wifi-iface', function(s) {
2158 var networks = L.toArray(s.network).map(function(network) { return (network == oldName ? newName : network) });
2160 if (networks.length > 0)
2161 uci.set('wireless', s['.name'], 'network', networks.join(' '));
2164 uci.remove('network', oldName);
2171 * Get a {@link LuCI.Network.Device Device} instance describing the
2172 * given network device.
2174 * @param {string} name
2175 * The name of the network device to get, e.g. `eth0` or `br-lan`.
2177 * @returns {Promise<null|LuCI.Network.Device>}
2178 * Returns a promise resolving to the `Device` instance describing
2179 * the network device or `null` if the given device name could not
2182 getDevice: function(name) {
2183 return initNetworkState().then(L.bind(function() {
2187 if (_state.netdevs.hasOwnProperty(name) || isWifiIfname(name))
2188 return this.instantiateDevice(name);
2190 var netid = getWifiNetidBySid(name);
2192 return this.instantiateDevice(netid[0]);
2199 * Get a sorted list of all found network devices.
2201 * @returns {Promise<Array<LuCI.Network.Device>>}
2202 * Returns a promise resolving to a sorted array of `Device` class
2203 * instances describing the network devices found on the system.
2205 getDevices: function() {
2206 return initNetworkState().then(L.bind(function() {
2209 /* find simple devices */
2210 var uciInterfaces = uci.sections('network', 'interface');
2211 for (var i = 0; i < uciInterfaces.length; i++) {
2212 var ifnames = L.toArray(uciInterfaces[i].ifname);
2214 for (var j = 0; j < ifnames.length; j++) {
2215 if (ifnames[j].charAt(0) == '@')
2218 if (isIgnoredIfname(ifnames[j]) || isVirtualIfname(ifnames[j]) || isWifiIfname(ifnames[j]))
2221 devices[ifnames[j]] = this.instantiateDevice(ifnames[j]);
2225 for (var ifname in _state.netdevs) {
2226 if (devices.hasOwnProperty(ifname))
2229 if (isIgnoredIfname(ifname) || isVirtualIfname(ifname) || isWifiIfname(ifname))
2232 devices[ifname] = this.instantiateDevice(ifname);
2235 /* find VLAN devices */
2236 var uciSwitchVLANs = uci.sections('network', 'switch_vlan');
2237 for (var i = 0; i < uciSwitchVLANs.length; i++) {
2238 if (typeof(uciSwitchVLANs[i].ports) != 'string' ||
2239 typeof(uciSwitchVLANs[i].device) != 'string' ||
2240 !_state.switches.hasOwnProperty(uciSwitchVLANs[i].device))
2243 var ports = uciSwitchVLANs[i].ports.split(/\s+/);
2244 for (var j = 0; j < ports.length; j++) {
2245 var m = ports[j].match(/^(\d+)([tu]?)$/);
2249 var netdev = _state.switches[uciSwitchVLANs[i].device].netdevs[m[1]];
2253 if (!devices.hasOwnProperty(netdev))
2254 devices[netdev] = this.instantiateDevice(netdev);
2256 _state.isSwitch[netdev] = true;
2261 var vid = uciSwitchVLANs[i].vid || uciSwitchVLANs[i].vlan;
2262 vid = (vid != null ? +vid : null);
2264 if (vid == null || vid < 0 || vid > 4095)
2267 var vlandev = '%s.%d'.format(netdev, vid);
2269 if (!devices.hasOwnProperty(vlandev))
2270 devices[vlandev] = this.instantiateDevice(vlandev);
2272 _state.isSwitch[vlandev] = true;
2276 /* find wireless interfaces */
2277 var uciWifiIfaces = uci.sections('wireless', 'wifi-iface'),
2280 for (var i = 0; i < uciWifiIfaces.length; i++) {
2281 if (typeof(uciWifiIfaces[i].device) != 'string')
2284 networkCount[uciWifiIfaces[i].device] = (networkCount[uciWifiIfaces[i].device] || 0) + 1;
2286 var netid = '%s.network%d'.format(uciWifiIfaces[i].device, networkCount[uciWifiIfaces[i].device]);
2288 devices[netid] = this.instantiateDevice(netid);
2293 for (var netdev in devices)
2294 if (devices.hasOwnProperty(netdev))
2295 rv.push(devices[netdev]);
2297 rv.sort(deviceSort);
2304 * Test if a given network device name is in the list of patterns for
2305 * device names to ignore.
2307 * Ignored device names are usually Linux network devices which are
2308 * spawned implicitly by kernel modules such as `tunl0` or `hwsim0`
2309 * and which are unsuitable for use in network configuration.
2311 * @param {string} name
2312 * The device name to test.
2314 * @returns {boolean}
2315 * Returns `true` if the given name is in the ignore pattern list,
2316 * else returns `false`.
2318 isIgnoredDevice: function(name) {
2319 return isIgnoredIfname(name);
2323 * Get a {@link LuCI.Network.WifiDevice WifiDevice} instance describing
2324 * the given wireless radio.
2326 * @param {string} devname
2327 * The configuration name of the wireless radio to lookup, e.g. `radio0`
2328 * for the first mac80211 phy on the system.
2330 * @returns {Promise<null|LuCI.Network.WifiDevice>}
2331 * Returns a promise resolving to the `WifiDevice` instance describing
2332 * the underlying radio device or `null` if the wireless radio could not
2335 getWifiDevice: function(devname) {
2336 return initNetworkState().then(L.bind(function() {
2337 var existingDevice = uci.get('wireless', devname);
2339 if (existingDevice == null || existingDevice['.type'] != 'wifi-device')
2342 return this.instantiateWifiDevice(devname, _state.radios[devname] || {});
2347 * Obtain a list of all configured radio devices.
2349 * @returns {Promise<Array<LuCI.Network.WifiDevice>>}
2350 * Returns a promise resolving to an array of `WifiDevice` instances
2351 * describing the wireless radios configured in the system.
2352 * The order of the array corresponds to the order of the radios in
2353 * the configuration.
2355 getWifiDevices: function() {
2356 return initNetworkState().then(L.bind(function() {
2357 var uciWifiDevices = uci.sections('wireless', 'wifi-device'),
2360 for (var i = 0; i < uciWifiDevices.length; i++) {
2361 var devname = uciWifiDevices[i]['.name'];
2362 rv.push(this.instantiateWifiDevice(devname, _state.radios[devname] || {}));
2370 * Get a {@link LuCI.Network.WifiNetwork WifiNetwork} instance describing
2371 * the given wireless network.
2373 * @param {string} netname
2374 * The name of the wireless network to lookup. This may be either an uci
2375 * configuration section ID, a network ID in the form `radio#.network#`
2376 * or a Linux network device name like `wlan0` which is resolved to the
2377 * corresponding configuration section through `ubus` runtime information.
2379 * @returns {Promise<null|LuCI.Network.WifiNetwork>}
2380 * Returns a promise resolving to the `WifiNetwork` instance describing
2381 * the wireless network or `null` if the corresponding network could not
2384 getWifiNetwork: function(netname) {
2385 return initNetworkState()
2386 .then(L.bind(this.lookupWifiNetwork, this, netname));
2390 * Get an array of all {@link LuCI.Network.WifiNetwork WifiNetwork}
2391 * instances describing the wireless networks present on the system.
2393 * @returns {Promise<Array<LuCI.Network.WifiNetwork>>}
2394 * Returns a promise resolving to an array of `WifiNetwork` instances
2395 * describing the wireless networks. The array will be empty if no networks
2398 getWifiNetworks: function() {
2399 return initNetworkState().then(L.bind(function() {
2400 var wifiIfaces = uci.sections('wireless', 'wifi-iface'),
2403 for (var i = 0; i < wifiIfaces.length; i++)
2404 rv.push(this.lookupWifiNetwork(wifiIfaces[i]['.name']));
2406 rv.sort(function(a, b) {
2407 return (a.getID() > b.getID());
2415 * Adds a new wireless network to the configuration and sets its options
2416 * to the provided values.
2418 * @param {Object<string, string|string[]>} options
2419 * The options to set for the newly added wireless network. This object
2420 * must at least contain a `device` property which is set to the radio
2421 * name the new network belongs to.
2423 * @returns {Promise<null|LuCI.Network.WifiNetwork>}
2424 * Returns a promise resolving to a `WifiNetwork` instance describing
2425 * the newly added wireless network or `null` if the given options
2426 * were invalid or if the associated radio device could not be found.
2428 addWifiNetwork: function(options) {
2429 return initNetworkState().then(L.bind(function() {
2430 if (options == null ||
2431 typeof(options) != 'object' ||
2432 typeof(options.device) != 'string')
2435 var existingDevice = uci.get('wireless', options.device);
2436 if (existingDevice == null || existingDevice['.type'] != 'wifi-device')
2439 /* XXX: need to add a named section (wifinet#) here */
2440 var sid = uci.add('wireless', 'wifi-iface');
2441 for (var key in options)
2442 if (options.hasOwnProperty(key))
2443 uci.set('wireless', sid, key, options[key]);
2445 var radioname = existingDevice['.name'],
2446 netid = getWifiNetidBySid(sid) || [];
2448 return this.instantiateWifiNetwork(sid, radioname, _state.radios[radioname], netid[0], null);
2453 * Deletes the given wireless network from the configuration.
2455 * @param {string} netname
2456 * The name of the network to remove. This may be either a
2457 * network ID in the form `radio#.network#` or a Linux network device
2458 * name like `wlan0` which is resolved to the corresponding configuration
2459 * section through `ubus` runtime information.
2461 * @returns {Promise<boolean>}
2462 * Returns a promise resolving to `true` if the wireless network has been
2463 * successfully deleted from the configuration or `false` if it could not
2466 deleteWifiNetwork: function(netname) {
2467 return initNetworkState().then(L.bind(function() {
2468 var sid = getWifiSidByIfname(netname);
2473 uci.remove('wireless', sid);
2479 getStatusByRoute: function(addr, mask) {
2480 return initNetworkState().then(L.bind(function() {
2483 for (var i = 0; i < _state.ifaces.length; i++) {
2484 if (!Array.isArray(_state.ifaces[i].route))
2487 for (var j = 0; j < _state.ifaces[i].route.length; j++) {
2488 if (typeof(_state.ifaces[i].route[j]) != 'object' ||
2489 typeof(_state.ifaces[i].route[j].target) != 'string' ||
2490 typeof(_state.ifaces[i].route[j].mask) != 'number')
2493 if (_state.ifaces[i].route[j].table)
2496 if (_state.ifaces[i].route[j].target != addr ||
2497 _state.ifaces[i].route[j].mask != mask)
2500 rv.push(_state.ifaces[i]);
2509 getStatusByAddress: function(addr) {
2510 return initNetworkState().then(L.bind(function() {
2513 for (var i = 0; i < _state.ifaces.length; i++) {
2514 if (Array.isArray(_state.ifaces[i]['ipv4-address']))
2515 for (var j = 0; j < _state.ifaces[i]['ipv4-address'].length; j++)
2516 if (typeof(_state.ifaces[i]['ipv4-address'][j]) == 'object' &&
2517 _state.ifaces[i]['ipv4-address'][j].address == addr)
2518 return _state.ifaces[i];
2520 if (Array.isArray(_state.ifaces[i]['ipv6-address']))
2521 for (var j = 0; j < _state.ifaces[i]['ipv6-address'].length; j++)
2522 if (typeof(_state.ifaces[i]['ipv6-address'][j]) == 'object' &&
2523 _state.ifaces[i]['ipv6-address'][j].address == addr)
2524 return _state.ifaces[i];
2526 if (Array.isArray(_state.ifaces[i]['ipv6-prefix-assignment']))
2527 for (var j = 0; j < _state.ifaces[i]['ipv6-prefix-assignment'].length; j++)
2528 if (typeof(_state.ifaces[i]['ipv6-prefix-assignment'][j]) == 'object' &&
2529 typeof(_state.ifaces[i]['ipv6-prefix-assignment'][j]['local-address']) == 'object' &&
2530 _state.ifaces[i]['ipv6-prefix-assignment'][j]['local-address'].address == addr)
2531 return _state.ifaces[i];
2539 * Get IPv4 wan networks.
2541 * This function looks up all networks having a default `0.0.0.0/0` route
2542 * and returns them as array.
2544 * @returns {Promise<Array<LuCI.Network.Protocol>>}
2545 * Returns a promise resolving to an array of `Protocol` subclass
2546 * instances describing the found default route interfaces.
2548 getWANNetworks: function() {
2549 return this.getStatusByRoute('0.0.0.0', 0).then(L.bind(function(statuses) {
2550 var rv = [], seen = {};
2552 for (var i = 0; i < statuses.length; i++) {
2553 if (!seen.hasOwnProperty(statuses[i].interface)) {
2554 rv.push(this.instantiateNetwork(statuses[i].interface, statuses[i].proto));
2555 seen[statuses[i].interface] = true;
2564 * Get IPv6 wan networks.
2566 * This function looks up all networks having a default `::/0` route
2567 * and returns them as array.
2569 * @returns {Promise<Array<LuCI.Network.Protocol>>}
2570 * Returns a promise resolving to an array of `Protocol` subclass
2571 * instances describing the found IPv6 default route interfaces.
2573 getWAN6Networks: function() {
2574 return this.getStatusByRoute('::', 0).then(L.bind(function(statuses) {
2575 var rv = [], seen = {};
2577 for (var i = 0; i < statuses.length; i++) {
2578 if (!seen.hasOwnProperty(statuses[i].interface)) {
2579 rv.push(this.instantiateNetwork(statuses[i].interface, statuses[i].proto));
2580 seen[statuses[i].interface] = true;
2589 * Describes an swconfig switch topology by specifying the CPU
2590 * connections and external port labels of a switch.
2592 * @typedef {Object<string, Object|Array>} SwitchTopology
2593 * @memberof LuCI.Network
2595 * @property {Object<number, string>} netdevs
2596 * The `netdevs` property points to an object describing the CPU port
2597 * connections of the switch. The numeric key of the enclosed object is
2598 * the port number, the value contains the Linux network device name the
2599 * port is hardwired to.
2601 * @property {Array<Object<string, boolean|number|string>>} ports
2602 * The `ports` property points to an array describing the populated
2603 * ports of the switch in the external label order. Each array item is
2604 * an object containg the following keys:
2605 * - `num` - the internal switch port number
2606 * - `label` - the label of the port, e.g. `LAN 1` or `CPU (eth0)`
2607 * - `device` - the connected Linux network device name (CPU ports only)
2608 * - `tagged` - a boolean indicating whether the port must be tagged to
2609 * function (CPU ports only)
2613 * Returns the topologies of all swconfig switches found on the system.
2615 * @returns {Promise<Object<string, LuCI.Network.SwitchTopology>>}
2616 * Returns a promise resolving to an object containing the topologies
2617 * of each switch. The object keys correspond to the name of the switches
2618 * such as `switch0`, the values are
2619 * {@link LuCI.Network.SwitchTopology SwitchTopology} objects describing
2622 getSwitchTopologies: function() {
2623 return initNetworkState().then(function() {
2624 return _state.switches;
2629 instantiateNetwork: function(name, proto) {
2633 proto = (proto == null ? uci.get('network', name, 'proto') : proto);
2635 var protoClass = _protocols[proto] || Protocol;
2636 return new protoClass(name);
2640 instantiateDevice: function(name, network, extend) {
2642 return new (Device.extend(extend))(name, network);
2644 return new Device(name, network);
2648 instantiateWifiDevice: function(radioname, radiostate) {
2649 return new WifiDevice(radioname, radiostate);
2653 instantiateWifiNetwork: function(sid, radioname, radiostate, netid, netstate, hostapd) {
2654 return new WifiNetwork(sid, radioname, radiostate, netid, netstate, hostapd);
2658 lookupWifiNetwork: function(netname) {
2659 var sid, res, netid, radioname, radiostate, netstate;
2661 sid = getWifiSidByNetid(netname);
2664 res = getWifiStateBySid(sid);
2666 radioname = res ? res[0] : null;
2667 radiostate = res ? res[1] : null;
2668 netstate = res ? res[2] : null;
2671 res = getWifiStateByIfname(netname);
2675 radiostate = res[1];
2677 sid = netstate.section;
2678 netid = L.toArray(getWifiNetidBySid(sid))[0];
2681 res = getWifiStateBySid(netname);
2685 radiostate = res[1];
2688 netid = L.toArray(getWifiNetidBySid(sid))[0];
2691 res = getWifiNetidBySid(netname);
2702 return this.instantiateWifiNetwork(sid || netname, radioname,
2703 radiostate, netid, netstate,
2704 netstate ? _state.hostapd[netstate.ifname] : null);
2708 * Obtains the the network device name of the given object.
2710 * @param {LuCI.Network.Protocol|LuCI.Network.Device|LuCI.Network.WifiDevice|LuCI.Network.WifiNetwork|string} obj
2711 * The object to get the device name from.
2713 * @returns {null|string}
2714 * Returns a string containing the device name or `null` if the given
2715 * object could not be converted to a name.
2717 getIfnameOf: function(obj) {
2718 return ifnameOf(obj);
2722 * Queries the internal DSL modem type from board information.
2724 * @returns {Promise<null|string>}
2725 * Returns a promise resolving to the type of the internal modem
2726 * (e.g. `vdsl`) or to `null` if no internal modem is present.
2728 getDSLModemType: function() {
2729 return initNetworkState().then(function() {
2730 return _state.hasDSLModem ? _state.hasDSLModem.type : null;
2735 * Queries aggregated information about known hosts.
2737 * This function aggregates information from various sources such as
2738 * DHCP lease databases, ARP and IPv6 neighbour entries, wireless
2739 * association list etc. and returns a {@link LuCI.Network.Hosts Hosts}
2740 * class instance describing the found hosts.
2742 * @returns {Promise<LuCI.Network.Hosts>}
2743 * Returns a `Hosts` instance describing host known on the system.
2745 getHostHints: function() {
2746 return initNetworkState().then(function() {
2747 return new Hosts(_state.hosts);
2754 * @memberof LuCI.Network
2758 * The `LuCI.Network.Hosts` class encapsulates host information aggregated
2759 * from multiple sources and provides convenience functions to access the
2760 * host information by different criteria.
2762 Hosts = L.Class.extend(/** @lends LuCI.Network.Hosts.prototype */ {
2763 __init__: function(hosts) {
2768 * Lookup the hostname associated with the given MAC address.
2770 * @param {string} mac
2771 * The MAC address to lookup.
2773 * @returns {null|string}
2774 * Returns the hostname associated with the given MAC or `null` if
2775 * no matching host could be found or if no hostname is known for
2776 * the corresponding host.
2778 getHostnameByMACAddr: function(mac) {
2779 return this.hosts[mac] ? this.hosts[mac].name : null;
2783 * Lookup the IPv4 address associated with the given MAC address.
2785 * @param {string} mac
2786 * The MAC address to lookup.
2788 * @returns {null|string}
2789 * Returns the IPv4 address associated with the given MAC or `null` if
2790 * no matching host could be found or if no IPv4 address is known for
2791 * the corresponding host.
2793 getIPAddrByMACAddr: function(mac) {
2794 return this.hosts[mac] ? this.hosts[mac].ipv4 : null;
2798 * Lookup the IPv6 address associated with the given MAC address.
2800 * @param {string} mac
2801 * The MAC address to lookup.
2803 * @returns {null|string}
2804 * Returns the IPv6 address associated with the given MAC or `null` if
2805 * no matching host could be found or if no IPv6 address is known for
2806 * the corresponding host.
2808 getIP6AddrByMACAddr: function(mac) {
2809 return this.hosts[mac] ? this.hosts[mac].ipv6 : null;
2813 * Lookup the hostname associated with the given IPv4 address.
2815 * @param {string} ipaddr
2816 * The IPv4 address to lookup.
2818 * @returns {null|string}
2819 * Returns the hostname associated with the given IPv4 or `null` if
2820 * no matching host could be found or if no hostname is known for
2821 * the corresponding host.
2823 getHostnameByIPAddr: function(ipaddr) {
2824 for (var mac in this.hosts)
2825 if (this.hosts[mac].ipv4 == ipaddr && this.hosts[mac].name != null)
2826 return this.hosts[mac].name;
2831 * Lookup the MAC address associated with the given IPv4 address.
2833 * @param {string} ipaddr
2834 * The IPv4 address to lookup.
2836 * @returns {null|string}
2837 * Returns the MAC address associated with the given IPv4 or `null` if
2838 * no matching host could be found or if no MAC address is known for
2839 * the corresponding host.
2841 getMACAddrByIPAddr: function(ipaddr) {
2842 for (var mac in this.hosts)
2843 if (this.hosts[mac].ipv4 == ipaddr)
2849 * Lookup the hostname associated with the given IPv6 address.
2851 * @param {string} ipaddr
2852 * The IPv6 address to lookup.
2854 * @returns {null|string}
2855 * Returns the hostname associated with the given IPv6 or `null` if
2856 * no matching host could be found or if no hostname is known for
2857 * the corresponding host.
2859 getHostnameByIP6Addr: function(ip6addr) {
2860 for (var mac in this.hosts)
2861 if (this.hosts[mac].ipv6 == ip6addr && this.hosts[mac].name != null)
2862 return this.hosts[mac].name;
2867 * Lookup the MAC address associated with the given IPv6 address.
2869 * @param {string} ipaddr
2870 * The IPv6 address to lookup.
2872 * @returns {null|string}
2873 * Returns the MAC address associated with the given IPv6 or `null` if
2874 * no matching host could be found or if no MAC address is known for
2875 * the corresponding host.
2877 getMACAddrByIP6Addr: function(ip6addr) {
2878 for (var mac in this.hosts)
2879 if (this.hosts[mac].ipv6 == ip6addr)
2885 * Return an array of (MAC address, name hint) tuples sorted by
2888 * @param {boolean} [preferIp6=false]
2889 * Whether to prefer IPv6 addresses (`true`) or IPv4 addresses (`false`)
2890 * as name hint when no hostname is known for a specific MAC address.
2892 * @returns {Array<Array<string>>}
2893 * Returns an array of arrays containing a name hint for each found
2894 * MAC address on the system. The array is sorted ascending by MAC.
2896 * Each item of the resulting array is a two element array with the
2897 * MAC being the first element and the name hint being the second
2898 * element. The name hint is either the hostname, an IPv4 or an IPv6
2899 * address related to the MAC address.
2901 * If no hostname but both IPv4 and IPv6 addresses are known, the
2902 * `preferIP6` flag specifies whether the IPv6 or the IPv4 address
2905 getMACHints: function(preferIp6) {
2907 for (var mac in this.hosts) {
2908 var hint = this.hosts[mac].name ||
2909 this.hosts[mac][preferIp6 ? 'ipv6' : 'ipv4'] ||
2910 this.hosts[mac][preferIp6 ? 'ipv4' : 'ipv6'];
2912 rv.push([mac, hint]);
2914 return rv.sort(function(a, b) { return a[0] > b[0] });
2920 * @memberof LuCI.Network
2924 * The `Network.Protocol` class serves as base for protocol specific
2925 * subclasses which describe logical UCI networks defined by `config
2926 * interface` sections in `/etc/config/network`.
2928 Protocol = L.Class.extend(/** @lends LuCI.Network.Protocol.prototype */ {
2929 __init__: function(name) {
2933 _get: function(opt) {
2934 var val = uci.get('network', this.sid, opt);
2936 if (Array.isArray(val))
2937 return val.join(' ');
2942 _ubus: function(field) {
2943 for (var i = 0; i < _state.ifaces.length; i++) {
2944 if (_state.ifaces[i].interface != this.sid)
2947 return (field != null ? _state.ifaces[i][field] : _state.ifaces[i]);
2952 * Read the given UCI option value of this network.
2954 * @param {string} opt
2955 * The UCI option name to read.
2957 * @returns {null|string|string[]}
2958 * Returns the UCI option value or `null` if the requested option is
2961 get: function(opt) {
2962 return uci.get('network', this.sid, opt);
2966 * Set the given UCI option of this network to the given value.
2968 * @param {string} opt
2969 * The name of the UCI option to set.
2971 * @param {null|string|string[]} val
2972 * The value to set or `null` to remove the given option from the
2975 set: function(opt, val) {
2976 return uci.set('network', this.sid, opt, val);
2980 * Get the associared Linux network device of this network.
2982 * @returns {null|string}
2983 * Returns the name of the associated network device or `null` if
2984 * it could not be determined.
2986 getIfname: function() {
2989 if (this.isFloating())
2990 ifname = this._ubus('l3_device');
2992 ifname = this._ubus('device') || this._ubus('l3_device');
2997 var res = getWifiNetidByNetname(this.sid);
2998 return (res != null ? res[0] : null);
3002 * Get the name of this network protocol class.
3004 * This function will be overwritten by subclasses created by
3005 * {@link LuCI.Network#registerProtocol Network.registerProtocol()}.
3009 * Returns the name of the network protocol implementation, e.g.
3010 * `static` or `dhcp`.
3012 getProtocol: function() {
3017 * Return a human readable description for the protcol, such as
3018 * `Static address` or `DHCP client`.
3020 * This function should be overwritten by subclasses.
3024 * Returns the description string.
3026 getI18n: function() {
3027 switch (this.getProtocol()) {
3028 case 'none': return _('Unmanaged');
3029 case 'static': return _('Static address');
3030 case 'dhcp': return _('DHCP client');
3031 default: return _('Unknown');
3036 * Get the type of the underlying interface.
3038 * This function actually is a convenience wrapper around
3039 * `proto.get("type")` and is mainly used by other `LuCI.Network` code
3040 * to check whether the interface is declared as bridge in UCI.
3042 * @returns {null|string}
3043 * Returns the value of the `type` option of the associated logical
3044 * interface or `null` if no `type` option is set.
3046 getType: function() {
3047 return this._get('type');
3051 * Get the name of the associated logical interface.
3054 * Returns the logical interface name, such as `lan` or `wan`.
3056 getName: function() {
3061 * Get the uptime of the logical interface.
3064 * Returns the uptime of the associated interface in seconds.
3066 getUptime: function() {
3067 return this._ubus('uptime') || 0;
3071 * Get the logical interface expiry time in seconds.
3073 * For protocols that have a concept of a lease, such as DHCP or
3074 * DHCPv6, this function returns the remaining time in seconds
3075 * until the lease expires.
3078 * Returns the amount of seconds until the lease expires or `-1`
3079 * if it isn't applicable to the associated protocol.
3081 getExpiry: function() {
3082 var u = this._ubus('uptime'),
3083 d = this._ubus('data');
3085 if (typeof(u) == 'number' && d != null &&
3086 typeof(d) == 'object' && typeof(d.leasetime) == 'number') {
3087 var r = d.leasetime - (u % d.leasetime);
3088 return (r > 0 ? r : 0);
3095 * Get the metric value of the logical interface.
3098 * Returns the current metric value used for device and network
3099 * routes spawned by the associated logical interface.
3101 getMetric: function() {
3102 return this._ubus('metric') || 0;
3106 * Get the requested firewall zone name of the logical interface.
3108 * Some protocol implementations request a specific firewall zone
3109 * to trigger inclusion of their resulting network devices into the
3110 * firewall rule set.
3112 * @returns {null|string}
3113 * Returns the requested firewall zone name as published in the
3114 * `ubus` runtime information or `null` if the remote protocol
3115 * handler didn't request a zone.
3117 getZoneName: function() {
3118 var d = this._ubus('data');
3120 if (L.isObject(d) && typeof(d.zone) == 'string')
3127 * Query the first (primary) IPv4 address of the logical interface.
3129 * @returns {null|string}
3130 * Returns the primary IPv4 address registered by the protocol handler
3131 * or `null` if no IPv4 addresses were set.
3133 getIPAddr: function() {
3134 var addrs = this._ubus('ipv4-address');
3135 return ((Array.isArray(addrs) && addrs.length) ? addrs[0].address : null);
3139 * Query all IPv4 addresses of the logical interface.
3141 * @returns {string[]}
3142 * Returns an array of IPv4 addresses in CIDR notation which have been
3143 * registered by the protocol handler. The order of the resulting array
3144 * follows the order of the addresses in `ubus` runtime information.
3146 getIPAddrs: function() {
3147 var addrs = this._ubus('ipv4-address'),
3150 if (Array.isArray(addrs))
3151 for (var i = 0; i < addrs.length; i++)
3152 rv.push('%s/%d'.format(addrs[i].address, addrs[i].mask));
3158 * Query the first (primary) IPv4 netmask of the logical interface.
3160 * @returns {null|string}
3161 * Returns the netmask of the primary IPv4 address registered by the
3162 * protocol handler or `null` if no IPv4 addresses were set.
3164 getNetmask: function() {
3165 var addrs = this._ubus('ipv4-address');
3166 if (Array.isArray(addrs) && addrs.length)
3167 return prefixToMask(addrs[0].mask, false);
3171 * Query the gateway (nexthop) of the default route associated with
3172 * this logical interface.
3175 * Returns a string containing the IPv4 nexthop address of the associated
3176 * default route or `null` if no default route was found.
3178 getGatewayAddr: function() {
3179 var routes = this._ubus('route');
3181 if (Array.isArray(routes))
3182 for (var i = 0; i < routes.length; i++)
3183 if (typeof(routes[i]) == 'object' &&
3184 routes[i].target == '0.0.0.0' &&
3185 routes[i].mask == 0)
3186 return routes[i].nexthop;
3192 * Query the IPv4 DNS servers associated with the logical interface.
3194 * @returns {string[]}
3195 * Returns an array of IPv4 DNS servers registered by the remote
3198 getDNSAddrs: function() {
3199 var addrs = this._ubus('dns-server'),
3202 if (Array.isArray(addrs))
3203 for (var i = 0; i < addrs.length; i++)
3204 if (!/:/.test(addrs[i]))
3211 * Query the first (primary) IPv6 address of the logical interface.
3213 * @returns {null|string}
3214 * Returns the primary IPv6 address registered by the protocol handler
3215 * in CIDR notation or `null` if no IPv6 addresses were set.
3217 getIP6Addr: function() {
3218 var addrs = this._ubus('ipv6-address');
3220 if (Array.isArray(addrs) && L.isObject(addrs[0]))
3221 return '%s/%d'.format(addrs[0].address, addrs[0].mask);
3223 addrs = this._ubus('ipv6-prefix-assignment');
3225 if (Array.isArray(addrs) && L.isObject(addrs[0]) && L.isObject(addrs[0]['local-address']))
3226 return '%s/%d'.format(addrs[0]['local-address'].address, addrs[0]['local-address'].mask);
3232 * Query all IPv6 addresses of the logical interface.
3234 * @returns {string[]}
3235 * Returns an array of IPv6 addresses in CIDR notation which have been
3236 * registered by the protocol handler. The order of the resulting array
3237 * follows the order of the addresses in `ubus` runtime information.
3239 getIP6Addrs: function() {
3240 var addrs = this._ubus('ipv6-address'),
3243 if (Array.isArray(addrs))
3244 for (var i = 0; i < addrs.length; i++)
3245 if (L.isObject(addrs[i]))
3246 rv.push('%s/%d'.format(addrs[i].address, addrs[i].mask));
3248 addrs = this._ubus('ipv6-prefix-assignment');
3250 if (Array.isArray(addrs))
3251 for (var i = 0; i < addrs.length; i++)
3252 if (L.isObject(addrs[i]) && L.isObject(addrs[i]['local-address']))
3253 rv.push('%s/%d'.format(addrs[i]['local-address'].address, addrs[i]['local-address'].mask));
3259 * Query the gateway (nexthop) of the IPv6 default route associated with
3260 * this logical interface.
3263 * Returns a string containing the IPv6 nexthop address of the associated
3264 * default route or `null` if no default route was found.
3266 getGateway6Addr: function() {
3267 var routes = this._ubus('route');
3269 if (Array.isArray(routes))
3270 for (var i = 0; i < routes.length; i++)
3271 if (typeof(routes[i]) == 'object' &&
3272 routes[i].target == '::' &&
3273 routes[i].mask == 0)
3274 return routes[i].nexthop;
3280 * Query the IPv6 DNS servers associated with the logical interface.
3282 * @returns {string[]}
3283 * Returns an array of IPv6 DNS servers registered by the remote
3286 getDNS6Addrs: function() {
3287 var addrs = this._ubus('dns-server'),
3290 if (Array.isArray(addrs))
3291 for (var i = 0; i < addrs.length; i++)
3292 if (/:/.test(addrs[i]))
3299 * Query the routed IPv6 prefix associated with the logical interface.
3301 * @returns {null|string}
3302 * Returns the routed IPv6 prefix registered by the remote protocol
3303 * handler or `null` if no prefix is present.
3305 getIP6Prefix: function() {
3306 var prefixes = this._ubus('ipv6-prefix');
3308 if (Array.isArray(prefixes) && L.isObject(prefixes[0]))
3309 return '%s/%d'.format(prefixes[0].address, prefixes[0].mask);
3315 * Query interface error messages published in `ubus` runtime state.
3317 * Interface errors are emitted by remote protocol handlers if the setup
3318 * of the underlying logical interface failed, e.g. due to bad
3319 * configuration or network connectivity issues.
3321 * This function will translate the found error codes to human readable
3322 * messages using the descriptions registered by
3323 * {@link LuCI.Network#registerErrorCode Network.registerErrorCode()}
3324 * and fall back to `"Unknown error (%s)"` where `%s` is replaced by the
3325 * error code in case no translation can be found.
3327 * @returns {string[]}
3328 * Returns an array of translated interface error messages.
3330 getErrors: function() {
3331 var errors = this._ubus('errors'),
3334 if (Array.isArray(errors)) {
3335 for (var i = 0; i < errors.length; i++) {
3336 if (!L.isObject(errors[i]) || typeof(errors[i].code) != 'string')
3340 rv.push(proto_errors[errors[i].code] || _('Unknown error (%s)').format(errors[i].code));
3348 * Checks whether the underlying logical interface is declared as bridge.
3350 * @returns {boolean}
3351 * Returns `true` when the interface is declared with `option type bridge`
3352 * and when the associated protocol implementation is not marked virtual
3353 * or `false` when the logical interface is no bridge.
3355 isBridge: function() {
3356 return (!this.isVirtual() && this.getType() == 'bridge');
3360 * Get the name of the opkg package providing the protocol functionality.
3362 * This function should be overwritten by protocol specific subclasses.
3367 * Returns the name of the opkg package required for the protocol to
3368 * function, e.g. `odhcp6c` for the `dhcpv6` prototocol.
3370 getOpkgPackage: function() {
3375 * Checks whether the protocol functionality is installed.
3377 * This function exists for compatibility with old code, it always
3383 * @returns {boolean}
3384 * Returns `true` if the protocol support is installed, else `false`.
3386 isInstalled: function() {
3391 * Checks whether this protocol is "virtual".
3393 * A "virtual" protocol is a protocol which spawns its own interfaces
3394 * on demand instead of using existing physical interfaces.
3396 * Examples for virtual protocols are `6in4` which `gre` spawn tunnel
3397 * network device on startup, examples for non-virtual protcols are
3398 * `dhcp` or `static` which apply IP configuration to existing interfaces.
3400 * This function should be overwritten by subclasses.
3402 * @returns {boolean}
3403 * Returns a boolean indicating whether the underlying protocol spawns
3404 * dynamic interfaces (`true`) or not (`false`).
3406 isVirtual: function() {
3411 * Checks whether this protocol is "floating".
3413 * A "floating" protocol is a protocol which spawns its own interfaces
3414 * on demand, like a virtual one but which relies on an existinf lower
3415 * level interface to initiate the connection.
3417 * An example for such a protocol is "pppoe".
3419 * This function exists for backwards compatibility with older code
3420 * but should not be used anymore.
3423 * @returns {boolean}
3424 * Returns a boolean indicating whether this protocol is floating (`true`)
3427 isFloating: function() {
3432 * Checks whether this logical interface is dynamic.
3434 * A dynamic interface is an interface which has been created at runtime,
3435 * e.g. as sub-interface of another interface, but which is not backed by
3436 * any user configuration. Such dynamic interfaces cannot be edited but
3437 * only brought down or restarted.
3439 * @returns {boolean}
3440 * Returns a boolean indicating whether this interface is dynamic (`true`)
3443 isDynamic: function() {
3444 return (this._ubus('dynamic') == true);
3448 * Checks whether this interface is an alias interface.
3450 * Alias interfaces are interfaces layering on top of another interface
3451 * and are denoted by a special `@interfacename` notation in the
3452 * underlying `ifname` option.
3454 * @returns {null|string}
3455 * Returns the name of the parent interface if this logical interface
3456 * is an alias or `null` if it is not an alias interface.
3458 isAlias: function() {
3459 var ifnames = L.toArray(uci.get('network', this.sid, 'ifname')),
3462 for (var i = 0; i < ifnames.length; i++)
3463 if (ifnames[i].charAt(0) == '@')
3464 parent = ifnames[i].substr(1);
3465 else if (parent != null)
3472 * Checks whether this logical interface is "empty", meaning that ut
3473 * has no network devices attached.
3475 * @returns {boolean}
3476 * Returns `true` if this logical interface is empty, else `false`.
3478 isEmpty: function() {
3479 if (this.isFloating())
3483 ifname = this._get('ifname');
3485 if (ifname != null && ifname.match(/\S+/))
3488 if (empty == true && getWifiNetidBySid(this.sid) != null)
3495 * Checks whether this logical interface is configured and running.
3497 * @returns {boolean}
3498 * Returns `true` when the interface is active or `false` when it is not.
3501 return (this._ubus('up') == true);
3505 * Add the given network device to the logical interface.
3507 * @param {LuCI.Network.Protocol|LuCI.Network.Device|LuCI.Network.WifiDevice|LuCI.Network.WifiNetwork|string} device
3508 * The object or device name to add to the logical interface. In case the
3509 * given argument is not a string, it is resolved though the
3510 * {@link LuCI.Network#getIfnameOf Network.getIfnameOf()} function.
3512 * @returns {boolean}
3513 * Returns `true` if the device name has been added or `false` if any
3514 * argument was invalid, if the device was already part of the logical
3515 * interface or if the logical interface is virtual.
3517 addDevice: function(ifname) {
3518 ifname = ifnameOf(ifname);
3520 if (ifname == null || this.isFloating())
3523 var wif = getWifiSidByIfname(ifname);
3526 return appendValue('wireless', wif, 'network', this.sid);
3528 return appendValue('network', this.sid, 'ifname', ifname);
3532 * Remove the given network device from the logical interface.
3534 * @param {LuCI.Network.Protocol|LuCI.Network.Device|LuCI.Network.WifiDevice|LuCI.Network.WifiNetwork|string} device
3535 * The object or device name to remove from the logical interface. In case
3536 * the given argument is not a string, it is resolved though the
3537 * {@link LuCI.Network#getIfnameOf Network.getIfnameOf()} function.
3539 * @returns {boolean}
3540 * Returns `true` if the device name has been added or `false` if any
3541 * argument was invalid, if the device was already part of the logical
3542 * interface or if the logical interface is virtual.
3544 deleteDevice: function(ifname) {
3547 ifname = ifnameOf(ifname);
3549 if (ifname == null || this.isFloating())
3552 var wif = getWifiSidByIfname(ifname);
3555 rv = removeValue('wireless', wif, 'network', this.sid);
3557 if (removeValue('network', this.sid, 'ifname', ifname))
3564 * Returns the Linux network device associated with this logical
3567 * @returns {LuCI.Network.Device}
3568 * Returns a `Network.Device` class instance representing the
3569 * expected Linux network device according to the configuration.
3571 getDevice: function() {
3572 if (this.isVirtual()) {
3573 var ifname = '%s-%s'.format(this.getProtocol(), this.sid);
3574 _state.isTunnel[this.getProtocol() + '-' + this.sid] = true;
3575 return L.network.instantiateDevice(ifname, this);
3577 else if (this.isBridge()) {
3578 var ifname = 'br-%s'.format(this.sid);
3579 _state.isBridge[ifname] = true;
3580 return new Device(ifname, this);
3583 var ifnames = L.toArray(uci.get('network', this.sid, 'ifname'));
3585 for (var i = 0; i < ifnames.length; i++) {
3586 var m = ifnames[i].match(/^([^:/]+)/);
3587 return ((m && m[1]) ? L.network.instantiateDevice(m[1], this) : null);
3590 ifname = getWifiNetidByNetname(this.sid);
3592 return (ifname != null ? L.network.instantiateDevice(ifname[0], this) : null);
3597 * Returns the layer 2 linux network device currently associated
3598 * with this logical interface.
3600 * @returns {LuCI.Network.Device}
3601 * Returns a `Network.Device` class instance representing the Linux
3602 * network device currently associated with the logical interface.
3604 getL2Device: function() {
3605 var ifname = this._ubus('device');
3606 return (ifname != null ? L.network.instantiateDevice(ifname, this) : null);
3610 * Returns the layer 3 linux network device currently associated
3611 * with this logical interface.
3613 * @returns {LuCI.Network.Device}
3614 * Returns a `Network.Device` class instance representing the Linux
3615 * network device currently associated with the logical interface.
3617 getL3Device: function() {
3618 var ifname = this._ubus('l3_device');
3619 return (ifname != null ? L.network.instantiateDevice(ifname, this) : null);
3623 * Returns a list of network sub-devices associated with this logical
3626 * @returns {null|Array<LuCI.Network.Device>}
3627 * Returns an array of of `Network.Device` class instances representing
3628 * the sub-devices attached to this logical interface or `null` if the
3629 * logical interface does not support sub-devices, e.g. because it is
3630 * virtual and not a bridge.
3632 getDevices: function() {
3635 if (!this.isBridge() && !(this.isVirtual() && !this.isFloating()))
3638 var ifnames = L.toArray(uci.get('network', this.sid, 'ifname'));
3640 for (var i = 0; i < ifnames.length; i++) {
3641 if (ifnames[i].charAt(0) == '@')
3644 var m = ifnames[i].match(/^([^:/]+)/);
3646 rv.push(L.network.instantiateDevice(m[1], this));
3649 var uciWifiIfaces = uci.sections('wireless', 'wifi-iface');
3651 for (var i = 0; i < uciWifiIfaces.length; i++) {
3652 if (typeof(uciWifiIfaces[i].device) != 'string')
3655 var networks = L.toArray(uciWifiIfaces[i].network);
3657 for (var j = 0; j < networks.length; j++) {
3658 if (networks[j] != this.sid)
3661 var netid = getWifiNetidBySid(uciWifiIfaces[i]['.name']);
3664 rv.push(L.network.instantiateDevice(netid[0], this));
3668 rv.sort(deviceSort);
3674 * Checks whether this logical interface contains the given device
3677 * @param {LuCI.Network.Protocol|LuCI.Network.Device|LuCI.Network.WifiDevice|LuCI.Network.WifiNetwork|string} device
3678 * The object or device name to check. In case the given argument is not
3679 * a string, it is resolved though the
3680 * {@link LuCI.Network#getIfnameOf Network.getIfnameOf()} function.
3682 * @returns {boolean}
3683 * Returns `true` when this logical interface contains the given network
3684 * device or `false` if not.
3686 containsDevice: function(ifname) {
3687 ifname = ifnameOf(ifname);
3691 else if (this.isVirtual() && '%s-%s'.format(this.getProtocol(), this.sid) == ifname)
3693 else if (this.isBridge() && 'br-%s'.format(this.sid) == ifname)
3696 var ifnames = L.toArray(uci.get('network', this.sid, 'ifname'));
3698 for (var i = 0; i < ifnames.length; i++) {
3699 var m = ifnames[i].match(/^([^:/]+)/);
3700 if (m != null && m[1] == ifname)
3704 var wif = getWifiSidByIfname(ifname);
3707 var networks = L.toArray(uci.get('wireless', wif, 'network'));
3709 for (var i = 0; i < networks.length; i++)
3710 if (networks[i] == this.sid)
3720 * @memberof LuCI.Network
3724 * A `Network.Device` class instance represents an underlying Linux network
3725 * device and allows querying device details such as packet statistics or MTU.
3727 Device = L.Class.extend(/** @lends LuCI.Network.Device.prototype */ {
3728 __init__: function(ifname, network) {
3729 var wif = getWifiSidByIfname(ifname);
3732 var res = getWifiStateBySid(wif) || [],
3733 netid = getWifiNetidBySid(wif) || [];
3735 this.wif = new WifiNetwork(wif, res[0], res[1], netid[0], res[2], { ifname: ifname });
3736 this.ifname = this.wif.getIfname();
3739 this.ifname = this.ifname || ifname;
3740 this.dev = _state.netdevs[this.ifname];
3741 this.network = network;
3744 _devstate: function(/* ... */) {
3747 for (var i = 0; i < arguments.length; i++)
3749 rv = rv[arguments[i]];
3757 * Get the name of the network device.
3760 * Returns the name of the device, e.g. `eth0` or `wlan0`.
3762 getName: function() {
3763 return (this.wif != null ? this.wif.getIfname() : this.ifname);
3767 * Get the MAC address of the device.
3769 * @returns {null|string}
3770 * Returns the MAC address of the device or `null` if not applicable,
3771 * e.g. for non-ethernet tunnel devices.
3773 getMAC: function() {
3774 var mac = this._devstate('macaddr');
3775 return mac ? mac.toUpperCase() : null;
3779 * Get the MTU of the device.
3782 * Returns the MTU of the device.
3784 getMTU: function() {
3785 return this._devstate('mtu');
3789 * Get the IPv4 addresses configured on the device.
3791 * @returns {string[]}
3792 * Returns an array of IPv4 address strings.
3794 getIPAddrs: function() {
3795 var addrs = this._devstate('ipaddrs');
3796 return (Array.isArray(addrs) ? addrs : []);
3800 * Get the IPv6 addresses configured on the device.
3802 * @returns {string[]}
3803 * Returns an array of IPv6 address strings.
3805 getIP6Addrs: function() {
3806 var addrs = this._devstate('ip6addrs');
3807 return (Array.isArray(addrs) ? addrs : []);
3811 * Get the type of the device..
3814 * Returns a string describing the type of the network device:
3815 * - `alias` if it is an abstract alias device (`@` notation)
3816 * - `wifi` if it is a wireless interface (e.g. `wlan0`)
3817 * - `bridge` if it is a bridge device (e.g. `br-lan`)
3818 * - `tunnel` if it is a tun or tap device (e.g. `tun0`)
3819 * - `vlan` if it is a vlan device (e.g. `eth0.1`)
3820 * - `switch` if it is a switch device (e.g.`eth1` connected to switch0)
3821 * - `ethernet` for all other device types
3823 getType: function() {
3824 if (this.ifname != null && this.ifname.charAt(0) == '@')
3826 else if (this.wif != null || isWifiIfname(this.ifname))
3828 else if (_state.isBridge[this.ifname])
3830 else if (_state.isTunnel[this.ifname])
3832 else if (this.ifname.indexOf('.') > -1)
3834 else if (_state.isSwitch[this.ifname])
3841 * Get a short description string for the device.
3844 * Returns the device name for non-wifi devices or a string containing
3845 * the operation mode and SSID for wifi devices.
3847 getShortName: function() {
3848 if (this.wif != null)
3849 return this.wif.getShortName();
3855 * Get a long description string for the device.
3858 * Returns a string containing the type description and device name
3859 * for non-wifi devices or operation mode and ssid for wifi ones.
3861 getI18n: function() {
3862 if (this.wif != null) {
3863 return '%s: %s "%s"'.format(
3864 _('Wireless Network'),
3865 this.wif.getActiveMode(),
3866 this.wif.getActiveSSID() || this.wif.getActiveBSSID() || this.wif.getID() || '?');
3869 return '%s: "%s"'.format(this.getTypeI18n(), this.getName());
3873 * Get a string describing the device type.
3876 * Returns a string describing the type, e.g. "Wireless Adapter" or
3879 getTypeI18n: function() {
3880 switch (this.getType()) {
3882 return _('Alias Interface');
3885 return _('Wireless Adapter');
3891 return _('Ethernet Switch');
3894 return (_state.isSwitch[this.ifname] ? _('Switch VLAN') : _('Software VLAN'));
3897 return _('Tunnel Interface');
3900 return _('Ethernet Adapter');
3905 * Get the associated bridge ports of the device.
3907 * @returns {null|Array<LuCI.Network.Device>}
3908 * Returns an array of `Network.Device` instances representing the ports
3909 * (slave interfaces) of the bridge or `null` when this device isn't
3912 getPorts: function() {
3913 var br = _state.bridges[this.ifname],
3916 if (br == null || !Array.isArray(br.ifnames))
3919 for (var i = 0; i < br.ifnames.length; i++)
3920 rv.push(L.network.instantiateDevice(br.ifnames[i].name));
3922 rv.sort(deviceSort);
3930 * @returns {null|string}
3931 * Returns the ID of this network bridge or `null` if this network
3932 * device is not a Linux bridge.
3934 getBridgeID: function() {
3935 var br = _state.bridges[this.ifname];
3936 return (br != null ? br.id : null);
3940 * Get the bridge STP setting
3942 * @returns {boolean}
3943 * Returns `true` when this device is a Linux bridge and has `stp`
3944 * enabled, else `false`.
3946 getBridgeSTP: function() {
3947 var br = _state.bridges[this.ifname];
3948 return (br != null ? !!br.stp : false);
3952 * Checks whether this device is up.
3954 * @returns {boolean}
3955 * Returns `true` when the associated device is running pr `false`
3956 * when it is down or absent.
3959 var up = this._devstate('flags', 'up');
3962 up = (this.getType() == 'alias');
3968 * Checks whether this device is a Linux bridge.
3970 * @returns {boolean}
3971 * Returns `true` when the network device is present and a Linux bridge,
3974 isBridge: function() {
3975 return (this.getType() == 'bridge');
3979 * Checks whether this device is part of a Linux bridge.
3981 * @returns {boolean}
3982 * Returns `true` when this network device is part of a bridge,
3985 isBridgePort: function() {
3986 return (this._devstate('bridge') != null);
3990 * Get the amount of transmitted bytes.
3993 * Returns the amount of bytes transmitted by the network device.
3995 getTXBytes: function() {
3996 var stat = this._devstate('stats');
3997 return (stat != null ? stat.tx_bytes || 0 : 0);
4001 * Get the amount of received bytes.
4004 * Returns the amount of bytes received by the network device.
4006 getRXBytes: function() {
4007 var stat = this._devstate('stats');
4008 return (stat != null ? stat.rx_bytes || 0 : 0);
4012 * Get the amount of transmitted packets.
4015 * Returns the amount of packets transmitted by the network device.
4017 getTXPackets: function() {
4018 var stat = this._devstate('stats');
4019 return (stat != null ? stat.tx_packets || 0 : 0);
4023 * Get the amount of received packets.
4026 * Returns the amount of packets received by the network device.
4028 getRXPackets: function() {
4029 var stat = this._devstate('stats');
4030 return (stat != null ? stat.rx_packets || 0 : 0);
4034 * Get the primary logical interface this device is assigned to.
4036 * @returns {null|LuCI.Network.Protocol}
4037 * Returns a `Network.Protocol` instance representing the logical
4038 * interface this device is attached to or `null` if it is not
4039 * assigned to any logical interface.
4041 getNetwork: function() {
4042 return this.getNetworks()[0];
4046 * Get the logical interfaces this device is assigned to.
4048 * @returns {Array<LuCI.Network.Protocol>}
4049 * Returns an array of `Network.Protocol` instances representing the
4050 * logical interfaces this device is assigned to.
4052 getNetworks: function() {
4053 if (this.networks == null) {
4056 var networks = enumerateNetworks.apply(L.network);
4058 for (var i = 0; i < networks.length; i++)
4059 if (networks[i].containsDevice(this.ifname) || networks[i].getIfname() == this.ifname)
4060 this.networks.push(networks[i]);
4062 this.networks.sort(networkSort);
4065 return this.networks;
4069 * Get the related wireless network this device is related to.
4071 * @returns {null|LuCI.Network.WifiNetwork}
4072 * Returns a `Network.WifiNetwork` instance representing the wireless
4073 * network corresponding to this network device or `null` if this device
4074 * is not a wireless device.
4076 getWifiNetwork: function() {
4077 return (this.wif != null ? this.wif : null);
4083 * @memberof LuCI.Network
4087 * A `Network.WifiDevice` class instance represents a wireless radio device
4088 * present on the system and provides wireless capability information as
4089 * well as methods for enumerating related wireless networks.
4091 WifiDevice = L.Class.extend(/** @lends LuCI.Network.WifiDevice.prototype */ {
4092 __init__: function(name, radiostate) {
4093 var uciWifiDevice = uci.get('wireless', name);
4095 if (uciWifiDevice != null &&
4096 uciWifiDevice['.type'] == 'wifi-device' &&
4097 uciWifiDevice['.name'] != null) {
4098 this.sid = uciWifiDevice['.name'];
4101 this.sid = this.sid || name;
4109 ubus: function(/* ... */) {
4110 var v = this._ubusdata;
4112 for (var i = 0; i < arguments.length; i++)
4114 v = v[arguments[i]];
4122 * Read the given UCI option value of this wireless device.
4124 * @param {string} opt
4125 * The UCI option name to read.
4127 * @returns {null|string|string[]}
4128 * Returns the UCI option value or `null` if the requested option is
4131 get: function(opt) {
4132 return uci.get('wireless', this.sid, opt);
4136 * Set the given UCI option of this network to the given value.
4138 * @param {string} opt
4139 * The name of the UCI option to set.
4141 * @param {null|string|string[]} val
4142 * The value to set or `null` to remove the given option from the
4145 set: function(opt, value) {
4146 return uci.set('wireless', this.sid, opt, value);
4150 * Checks whether this wireless radio is disabled.
4152 * @returns {boolean}
4153 * Returns `true` when the wireless radio is marked as disabled in `ubus`
4154 * runtime state or when the `disabled` option is set in the corresponding
4155 * UCI configuration.
4157 isDisabled: function() {
4158 return this.ubus('dev', 'disabled') || this.get('disabled') == '1';
4162 * Get the configuration name of this wireless radio.
4165 * Returns the UCI section name (e.g. `radio0`) of the corresponding
4166 * radio configuration which also serves as unique logical identifier
4167 * for the wireless phy.
4169 getName: function() {
4174 * Gets a list of supported hwmodes.
4176 * The hwmode values describe the frequency band and wireless standard
4177 * versions supported by the wireless phy.
4179 * @returns {string[]}
4180 * Returns an array of valid hwmode values for this radio. Currently
4181 * known mode values are:
4182 * - `a` - Legacy 802.11a mode, 5 GHz, up to 54 Mbit/s
4183 * - `b` - Legacy 802.11b mode, 2.4 GHz, up to 11 Mbit/s
4184 * - `g` - Legacy 802.11g mode, 2.4 GHz, up to 54 Mbit/s
4185 * - `n` - IEEE 802.11n mode, 2.4 or 5 GHz, up to 600 Mbit/s
4186 * - `ac` - IEEE 802.11ac mode, 5 GHz, up to 6770 Mbit/s
4188 getHWModes: function() {
4189 var hwmodes = this.ubus('dev', 'iwinfo', 'hwmodes');
4190 return Array.isArray(hwmodes) ? hwmodes : [ 'b', 'g' ];
4194 * Gets a list of supported htmodes.
4196 * The htmode values describe the wide-frequency options supported by
4199 * @returns {string[]}
4200 * Returns an array of valid htmode values for this radio. Currently
4201 * known mode values are:
4202 * - `HT20` - applicable to IEEE 802.11n, 20 MHz wide channels
4203 * - `HT40` - applicable to IEEE 802.11n, 40 MHz wide channels
4204 * - `VHT20` - applicable to IEEE 802.11ac, 20 MHz wide channels
4205 * - `VHT40` - applicable to IEEE 802.11ac, 40 MHz wide channels
4206 * - `VHT80` - applicable to IEEE 802.11ac, 80 MHz wide channels
4207 * - `VHT160` - applicable to IEEE 802.11ac, 160 MHz wide channels
4209 getHTModes: function() {
4210 var htmodes = this.ubus('dev', 'iwinfo', 'htmodes');
4211 return (Array.isArray(htmodes) && htmodes.length) ? htmodes : null;
4215 * Get a string describing the wireless radio hardware.
4218 * Returns the description string.
4220 getI18n: function() {
4221 var hw = this.ubus('dev', 'iwinfo', 'hardware'),
4222 type = L.isObject(hw) ? hw.name : null;
4224 if (this.ubus('dev', 'iwinfo', 'type') == 'wl')
4227 var hwmodes = this.getHWModes(),
4230 hwmodes.sort(function(a, b) {
4231 return (a.length != b.length ? a.length > b.length : a > b);
4234 modestr = hwmodes.join('');
4236 return '%s 802.11%s Wireless Controller (%s)'.format(type || 'Generic', modestr, this.getName());
4240 * A wireless scan result object describes a neighbouring wireless
4241 * network found in the vincinity.
4243 * @typedef {Object<string, number|string|LuCI.Network.WifiEncryption>} WifiScanResult
4244 * @memberof LuCI.Network
4246 * @property {string} ssid
4247 * The SSID / Mesh ID of the network.
4249 * @property {string} bssid
4250 * The BSSID if the network.
4252 * @property {string} mode
4253 * The operation mode of the network (`Master`, `Ad-Hoc`, `Mesh Point`).
4255 * @property {number} channel
4256 * The wireless channel of the network.
4258 * @property {number} signal
4259 * The received signal strength of the network in dBm.
4261 * @property {number} quality
4262 * The numeric quality level of the signal, can be used in conjunction
4263 * with `quality_max` to calculate a quality percentage.
4265 * @property {number} quality_max
4266 * The maximum possible quality level of the signal, can be used in
4267 * conjunction with `quality` to calculate a quality percentage.
4269 * @property {LuCI.Network.WifiEncryption} encryption
4270 * The encryption used by the wireless network.
4274 * Trigger a wireless scan on this radio device and obtain a list of
4277 * @returns {Promise<Array<LuCI.Network.WifiScanResult>>}
4278 * Returns a promise resolving to an array of scan result objects
4279 * describing the networks found in the vincinity.
4281 getScanList: function() {
4282 return callIwinfoScan(this.sid);
4286 * Check whether the wireless radio is marked as up in the `ubus`
4289 * @returns {boolean}
4290 * Returns `true` when the radio device is up, else `false`.
4293 if (L.isObject(_state.radios[this.sid]))
4294 return (_state.radios[this.sid].up == true);
4300 * Get the wifi network of the given name belonging to this radio device
4302 * @param {string} network
4303 * The name of the wireless network to lookup. This may be either an uci
4304 * configuration section ID, a network ID in the form `radio#.network#`
4305 * or a Linux network device name like `wlan0` which is resolved to the
4306 * corresponding configuration section through `ubus` runtime information.
4308 * @returns {Promise<LuCI.Network.WifiNetwork>}
4309 * Returns a promise resolving to a `Network.WifiNetwork` instance
4310 * representing the wireless network and rejecting with `null` if
4311 * the given network could not be found or is not associated with
4312 * this radio device.
4314 getWifiNetwork: function(network) {
4315 return L.network.getWifiNetwork(network).then(L.bind(function(networkInstance) {
4316 var uciWifiIface = (networkInstance.sid ? uci.get('wireless', networkInstance.sid) : null);
4318 if (uciWifiIface == null || uciWifiIface['.type'] != 'wifi-iface' || uciWifiIface.device != this.sid)
4319 return Promise.reject();
4321 return networkInstance;
4326 * Get all wireless networks associated with this wireless radio device.
4328 * @returns {Promise<Array<LuCI.Network.WifiNetwork>>}
4329 * Returns a promise resolving to an array of `Network.WifiNetwork`
4330 * instances respresenting the wireless networks associated with this
4333 getWifiNetworks: function() {
4334 return L.network.getWifiNetworks().then(L.bind(function(networks) {
4337 for (var i = 0; i < networks.length; i++)
4338 if (networks[i].getWifiDeviceName() == this.getName())
4339 rv.push(networks[i]);
4346 * Adds a new wireless network associated with this radio device to the
4347 * configuration and sets its options to the provided values.
4349 * @param {Object<string, string|string[]>} [options]
4350 * The options to set for the newly added wireless network.
4352 * @returns {Promise<null|LuCI.Network.WifiNetwork>}
4353 * Returns a promise resolving to a `WifiNetwork` instance describing
4354 * the newly added wireless network or `null` if the given options
4357 addWifiNetwork: function(options) {
4358 if (!L.isObject(options))
4361 options.device = this.sid;
4363 return L.network.addWifiNetwork(options);
4367 * Deletes the wireless network with the given name associated with this
4370 * @param {string} network
4371 * The name of the wireless network to lookup. This may be either an uci
4372 * configuration section ID, a network ID in the form `radio#.network#`
4373 * or a Linux network device name like `wlan0` which is resolved to the
4374 * corresponding configuration section through `ubus` runtime information.
4376 * @returns {Promise<boolean>}
4377 * Returns a promise resolving to `true` when the wireless network was
4378 * successfully deleted from the configuration or `false` when the given
4379 * network could not be found or if the found network was not associated
4380 * with this wireless radio device.
4382 deleteWifiNetwork: function(network) {
4385 if (network instanceof WifiNetwork) {
4389 var uciWifiIface = uci.get('wireless', network);
4391 if (uciWifiIface == null || uciWifiIface['.type'] != 'wifi-iface')
4392 sid = getWifiSidByIfname(network);
4395 if (sid == null || uci.get('wireless', sid, 'device') != this.sid)
4396 return Promise.resolve(false);
4398 uci.delete('wireless', network);
4400 return Promise.resolve(true);
4406 * @memberof LuCI.Network
4410 * A `Network.WifiNetwork` instance represents a wireless network (vif)
4411 * configured on top of a radio device and provides functions for querying
4412 * the runtime state of the network. Most radio devices support multiple
4413 * such networks in parallel.
4415 WifiNetwork = L.Class.extend(/** @lends LuCI.Network.WifiNetwork.prototype */ {
4416 __init__: function(sid, radioname, radiostate, netid, netstate, hostapd) {
4427 ubus: function(/* ... */) {
4428 var v = this._ubusdata;
4430 for (var i = 0; i < arguments.length; i++)
4432 v = v[arguments[i]];
4440 * Read the given UCI option value of this wireless network.
4442 * @param {string} opt
4443 * The UCI option name to read.
4445 * @returns {null|string|string[]}
4446 * Returns the UCI option value or `null` if the requested option is
4449 get: function(opt) {
4450 return uci.get('wireless', this.sid, opt);
4454 * Set the given UCI option of this network to the given value.
4456 * @param {string} opt
4457 * The name of the UCI option to set.
4459 * @param {null|string|string[]} val
4460 * The value to set or `null` to remove the given option from the
4463 set: function(opt, value) {
4464 return uci.set('wireless', this.sid, opt, value);
4468 * Checks whether this wireless network is disabled.
4470 * @returns {boolean}
4471 * Returns `true` when the wireless radio is marked as disabled in `ubus`
4472 * runtime state or when the `disabled` option is set in the corresponding
4473 * UCI configuration.
4475 isDisabled: function() {
4476 return this.ubus('dev', 'disabled') || this.get('disabled') == '1';
4480 * Get the configured operation mode of the wireless network.
4483 * Returns the configured operation mode. Possible values are:
4484 * - `ap` - Master (Access Point) mode
4485 * - `sta` - Station (client) mode
4486 * - `adhoc` - Ad-Hoc (IBSS) mode
4487 * - `mesh` - Mesh (IEEE 802.11s) mode
4488 * - `monitor` - Monitor mode
4490 getMode: function() {
4491 return this.ubus('net', 'config', 'mode') || this.get('mode') || 'ap';
4495 * Get the configured SSID of the wireless network.
4497 * @returns {null|string}
4498 * Returns the configured SSID value or `null` when this network is
4501 getSSID: function() {
4502 if (this.getMode() == 'mesh')
4505 return this.ubus('net', 'config', 'ssid') || this.get('ssid');
4509 * Get the configured Mesh ID of the wireless network.
4511 * @returns {null|string}
4512 * Returns the configured mesh ID value or `null` when this network
4513 * is not in mesh mode.
4515 getMeshID: function() {
4516 if (this.getMode() != 'mesh')
4519 return this.ubus('net', 'config', 'mesh_id') || this.get('mesh_id');
4523 * Get the configured BSSID of the wireless network.
4525 * @returns {null|string}
4526 * Returns the BSSID value or `null` if none has been specified.
4528 getBSSID: function() {
4529 return this.ubus('net', 'config', 'bssid') || this.get('bssid');
4533 * Get the names of the logical interfaces this wireless network is
4536 * @returns {string[]}
4537 * Returns an array of logical interface names.
4539 getNetworkNames: function() {
4540 return L.toArray(this.ubus('net', 'config', 'network') || this.get('network'));
4544 * Get the internal network ID of this wireless network.
4546 * The network ID is a LuCI specific identifer in the form
4547 * `radio#.network#` to identify wireless networks by their corresponding
4548 * radio and network index numbers.
4551 * Returns the LuCI specific network ID.
4558 * Get the configuration ID of this wireless network.
4561 * Returns the corresponding UCI section ID of the network.
4563 getName: function() {
4568 * Get the Linux network device name.
4570 * @returns {null|string}
4571 * Returns the current Linux network device name as resolved from
4572 * `ubus` runtime information or `null` if this network has no
4573 * associated network device, e.g. when not configured or up.
4575 getIfname: function() {
4576 var ifname = this.ubus('net', 'ifname') || this.ubus('net', 'iwinfo', 'ifname');
4578 if (ifname == null || ifname.match(/^(wifi|radio)\d/))
4579 ifname = this.netid;
4585 * Get the name of the corresponding wifi radio device.
4587 * @returns {null|string}
4588 * Returns the name of the radio device this network is configured on
4589 * or `null` if it cannot be determined.
4591 getWifiDeviceName: function() {
4592 return this.ubus('radio') || this.get('device');
4596 * Get the corresponding wifi radio device.
4598 * @returns {null|LuCI.Network.WifiDevice}
4599 * Returns a `Network.WifiDevice` instance representing the corresponding
4600 * wifi radio device or `null` if the related radio device could not be
4603 getWifiDevice: function() {
4604 var radioname = this.getWifiDeviceName();
4606 if (radioname == null)
4607 return Promise.reject();
4609 return L.network.getWifiDevice(radioname);
4613 * Check whether the radio network is up.
4615 * This function actually queries the up state of the related radio
4616 * device and assumes this network to be up as well when the parent
4617 * radio is up. This is due to the fact that OpenWrt does not control
4618 * virtual interfaces individually but within one common hostapd
4621 * @returns {boolean}
4622 * Returns `true` when the network is up, else `false`.
4625 var device = this.getDevice();
4630 return device.isUp();
4634 * Query the current operation mode from runtime information.
4637 * Returns the human readable mode name as reported by `ubus` runtime
4638 * state. Possible returned values are:
4650 getActiveMode: function() {
4651 var mode = this.ubus('net', 'iwinfo', 'mode') || this.ubus('net', 'config', 'mode') || this.get('mode') || 'ap';
4654 case 'ap': return 'Master';
4655 case 'sta': return 'Client';
4656 case 'adhoc': return 'Ad-Hoc';
4657 case 'mesh': return 'Mesh';
4658 case 'monitor': return 'Monitor';
4659 default: return mode;
4664 * Query the current operation mode from runtime information as
4665 * translated string.
4668 * Returns the translated, human readable mode name as reported by
4669 *`ubus` runtime state.
4671 getActiveModeI18n: function() {
4672 var mode = this.getActiveMode();
4675 case 'Master': return _('Master');
4676 case 'Client': return _('Client');
4677 case 'Ad-Hoc': return _('Ad-Hoc');
4678 case 'Mash': return _('Mesh');
4679 case 'Monitor': return _('Monitor');
4680 default: return mode;
4685 * Query the current SSID from runtime information.
4688 * Returns the current SSID or Mesh ID as reported by `ubus` runtime
4691 getActiveSSID: function() {
4692 return this.ubus('net', 'iwinfo', 'ssid') || this.ubus('net', 'config', 'ssid') || this.get('ssid');
4696 * Query the current BSSID from runtime information.
4699 * Returns the current BSSID or Mesh ID as reported by `ubus` runtime
4702 getActiveBSSID: function() {
4703 return this.ubus('net', 'iwinfo', 'bssid') || this.ubus('net', 'config', 'bssid') || this.get('bssid');
4707 * Query the current encryption settings from runtime information.
4710 * Returns a string describing the current encryption or `-` if the the
4711 * encryption state could not be found in `ubus` runtime information.
4713 getActiveEncryption: function() {
4714 return formatWifiEncryption(this.ubus('net', 'iwinfo', 'encryption')) || '-';
4718 * A wireless peer entry describes the properties of a remote wireless
4719 * peer associated with a local network.
4721 * @typedef {Object<string, boolean|number|string|LuCI.Network.WifiRateEntry>} WifiPeerEntry
4722 * @memberof LuCI.Network
4724 * @property {string} mac
4725 * The MAC address (BSSID).
4727 * @property {number} signal
4728 * The received signal strength.
4730 * @property {number} [signal_avg]
4731 * The average signal strength if supported by the driver.
4733 * @property {number} [noise]
4734 * The current noise floor of the radio. May be `0` or absent if not
4735 * supported by the driver.
4737 * @property {number} inactive
4738 * The amount of milliseconds the peer has been inactive, e.g. due
4741 * @property {number} connected_time
4742 * The amount of milliseconds the peer is associated to this network.
4744 * @property {number} [thr]
4745 * The estimated throughput of the peer, May be `0` or absent if not
4746 * supported by the driver.
4748 * @property {boolean} authorized
4749 * Specifies whether the peer is authorized to associate to this network.
4751 * @property {boolean} authenticated
4752 * Specifies whether the peer completed authentication to this network.
4754 * @property {string} preamble
4755 * The preamble mode used by the peer. May be `long` or `short`.
4757 * @property {boolean} wme
4758 * Specifies whether the peer supports WME/WMM capabilities.
4760 * @property {boolean} mfp
4761 * Specifies whether management frame protection is active.
4763 * @property {boolean} tdls
4764 * Specifies whether TDLS is active.
4766 * @property {number} [mesh llid]
4767 * The mesh LLID, may be `0` or absent if not applicable or supported
4770 * @property {number} [mesh plid]
4771 * The mesh PLID, may be `0` or absent if not applicable or supported
4774 * @property {string} [mesh plink]
4775 * The mesh peer link state description, may be an empty string (`''`)
4776 * or absent if not applicable or supported by the driver.
4778 * The following states are known:
4788 * @property {number} [mesh local PS]
4789 * The local powersafe mode for the peer link, may be an empty
4790 * string (`''`) or absent if not applicable or supported by
4793 * The following modes are known:
4794 * - `ACTIVE` (no power save)
4799 * @property {number} [mesh peer PS]
4800 * The remote powersafe mode for the peer link, may be an empty
4801 * string (`''`) or absent if not applicable or supported by
4804 * The following modes are known:
4805 * - `ACTIVE` (no power save)
4810 * @property {number} [mesh non-peer PS]
4811 * The powersafe mode for all non-peer neigbours, may be an empty
4812 * string (`''`) or absent if not applicable or supported by the driver.
4814 * The following modes are known:
4815 * - `ACTIVE` (no power save)
4820 * @property {LuCI.Network.WifiRateEntry} rx
4821 * Describes the receiving wireless rate from the peer.
4823 * @property {LuCI.Network.WifiRateEntry} tx
4824 * Describes the transmitting wireless rate to the peer.
4828 * A wireless rate entry describes the properties of a wireless
4829 * transmission rate to or from a peer.
4831 * @typedef {Object<string, boolean|number>} WifiRateEntry
4832 * @memberof LuCI.Network
4834 * @property {number} [drop_misc]
4835 * The amount of received misc. packages that have been dropped, e.g.
4836 * due to corruption or missing authentication. Only applicable to
4839 * @property {number} packets
4840 * The amount of packets that have been received or sent.
4842 * @property {number} bytes
4843 * The amount of bytes that have been received or sent.
4845 * @property {number} [failed]
4846 * The amount of failed tranmission attempts. Only applicable to
4849 * @property {number} [retries]
4850 * The amount of retried transmissions. Only applicable to transmit
4853 * @property {boolean} is_ht
4854 * Specifies whether this rate is an HT (IEEE 802.11n) rate.
4856 * @property {boolean} is_vht
4857 * Specifies whether this rate is an VHT (IEEE 802.11ac) rate.
4859 * @property {number} mhz
4860 * The channel width in MHz used for the transmission.
4862 * @property {number} rate
4863 * The bitrate in bit/s of the transmission.
4865 * @property {number} [mcs]
4866 * The MCS index of the used transmission rate. Only applicable to
4869 * @property {number} [40mhz]
4870 * Specifies whether the tranmission rate used 40MHz wide channel.
4871 * Only applicable to HT or VHT rates.
4873 * Note: this option exists for backwards compatibility only and its
4874 * use is discouraged. The `mhz` field should be used instead to
4875 * determine the channel width.
4877 * @property {boolean} [short_gi]
4878 * Specifies whether a short guard interval is used for the transmission.
4879 * Only applicable to HT or VHT rates.
4881 * @property {number} [nss]
4882 * Specifies the number of spatial streams used by the transmission.
4883 * Only applicable to VHT rates.
4887 * Fetch the list of associated peers.
4889 * @returns {Promise<Array<LuCI.Network.WifiPeerEntry>>}
4890 * Returns a promise resolving to an array of wireless peers associated
4891 * with this network.
4893 getAssocList: function() {
4894 return callIwinfoAssoclist(this.getIfname());
4898 * Query the current operating frequency of the wireless network.
4900 * @returns {null|string}
4901 * Returns the current operating frequency of the network from `ubus`
4902 * runtime information in GHz or `null` if the information is not
4905 getFrequency: function() {
4906 var freq = this.ubus('net', 'iwinfo', 'frequency');
4908 if (freq != null && freq > 0)
4909 return '%.03f'.format(freq / 1000);
4915 * Query the current average bitrate of all peers associated to this
4918 * @returns {null|number}
4919 * Returns the average bit rate among all peers associated to the network
4920 * as reported by `ubus` runtime information or `null` if the information
4923 getBitRate: function() {
4924 var rate = this.ubus('net', 'iwinfo', 'bitrate');
4926 if (rate != null && rate > 0)
4927 return (rate / 1000);
4933 * Query the current wireless channel.
4935 * @returns {null|number}
4936 * Returns the wireless channel as reported by `ubus` runtime information
4937 * or `null` if it cannot be determined.
4939 getChannel: function() {
4940 return this.ubus('net', 'iwinfo', 'channel') || this.ubus('dev', 'config', 'channel') || this.get('channel');
4944 * Query the current wireless signal.
4946 * @returns {null|number}
4947 * Returns the wireless signal in dBm as reported by `ubus` runtime
4948 * information or `null` if it cannot be determined.
4950 getSignal: function() {
4951 return this.ubus('net', 'iwinfo', 'signal') || 0;
4955 * Query the current radio noise floor.
4958 * Returns the radio noise floor in dBm as reported by `ubus` runtime
4959 * information or `0` if it cannot be determined.
4961 getNoise: function() {
4962 return this.ubus('net', 'iwinfo', 'noise') || 0;
4966 * Query the current country code.
4969 * Returns the wireless country code as reported by `ubus` runtime
4970 * information or `00` if it cannot be determined.
4972 getCountryCode: function() {
4973 return this.ubus('net', 'iwinfo', 'country') || this.ubus('dev', 'config', 'country') || '00';
4977 * Query the current radio TX power.
4979 * @returns {null|number}
4980 * Returns the wireless network transmit power in dBm as reported by
4981 * `ubus` runtime information or `null` if it cannot be determined.
4983 getTXPower: function() {
4984 return this.ubus('net', 'iwinfo', 'txpower');
4988 * Query the radio TX power offset.
4990 * Some wireless radios have a fixed power offset, e.g. due to the
4991 * use of external amplifiers.
4994 * Returns the wireless network transmit power offset in dBm as reported
4995 * by `ubus` runtime information or `0` if there is no offset, or if it
4996 * cannot be determined.
4998 getTXPowerOffset: function() {
4999 return this.ubus('net', 'iwinfo', 'txpower_offset') || 0;
5003 * Calculate the current signal.
5007 * Returns the calculated signal level, which is the difference between
5008 * noise and signal (SNR), divided by 5.
5010 getSignalLevel: function(signal, noise) {
5011 if (this.getActiveBSSID() == '00:00:00:00:00:00')
5014 signal = signal || this.getSignal();
5015 noise = noise || this.getNoise();
5017 if (signal < 0 && noise < 0) {
5018 var snr = -1 * (noise - signal);
5019 return Math.floor(snr / 5);
5026 * Calculate the current signal quality percentage.
5029 * Returns the calculated signal quality in percent. The value is
5030 * calculated from the `quality` and `quality_max` indicators reported
5031 * by `ubus` runtime state.
5033 getSignalPercent: function() {
5034 var qc = this.ubus('net', 'iwinfo', 'quality') || 0,
5035 qm = this.ubus('net', 'iwinfo', 'quality_max') || 0;
5037 if (qc > 0 && qm > 0)
5038 return Math.floor((100 / qm) * qc);
5044 * Get a short description string for this wireless network.
5047 * Returns a string describing this network, consisting of the
5048 * active operation mode, followed by either the SSID, BSSID or
5049 * internal network ID, depending on which information is available.
5051 getShortName: function() {
5052 return '%s "%s"'.format(
5053 this.getActiveModeI18n(),
5054 this.getActiveSSID() || this.getActiveBSSID() || this.getID());
5058 * Get a description string for this wireless network.
5061 * Returns a string describing this network, consisting of the
5062 * term `Wireless Network`, followed by the active operation mode,
5063 * the SSID, BSSID or internal network ID and the Linux network device
5064 * name, depending on which information is available.
5066 getI18n: function() {
5067 return '%s: %s "%s" (%s)'.format(
5068 _('Wireless Network'),
5069 this.getActiveModeI18n(),
5070 this.getActiveSSID() || this.getActiveBSSID() || this.getID(),
5075 * Get the primary logical interface this wireless network is attached to.
5077 * @returns {null|LuCI.Network.Protocol}
5078 * Returns a `Network.Protocol` instance representing the logical
5079 * interface or `null` if this network is not attached to any logical
5082 getNetwork: function() {
5083 return this.getNetworks()[0];
5087 * Get the logical interfaces this wireless network is attached to.
5089 * @returns {Array<LuCI.Network.Protocol>}
5090 * Returns an array of `Network.Protocol` instances representing the
5091 * logical interfaces this wireless network is attached to.
5093 getNetworks: function() {
5094 var networkNames = this.getNetworkNames(),
5097 for (var i = 0; i < networkNames.length; i++) {
5098 var uciInterface = uci.get('network', networkNames[i]);
5100 if (uciInterface == null || uciInterface['.type'] != 'interface')
5103 networks.push(L.network.instantiateNetwork(networkNames[i]));
5106 networks.sort(networkSort);
5112 * Get the associated Linux network device.
5114 * @returns {LuCI.Network.Device}
5115 * Returns a `Network.Device` instance representing the Linux network
5116 * device associted with this wireless network.
5118 getDevice: function() {
5119 return L.network.instantiateDevice(this.getIfname());
5123 * Check whether this wifi network supports deauthenticating clients.
5125 * @returns {boolean}
5126 * Returns `true` when this wifi network instance supports forcibly
5127 * deauthenticating clients, otherwise `false`.
5129 isClientDisconnectSupported: function() {
5130 return L.isObject(this.ubus('hostapd', 'del_client'));
5134 * Forcibly disconnect the given client from the wireless network.
5136 * @param {string} mac
5137 * The MAC address of the client to disconnect.
5139 * @param {boolean} [deauth=false]
5140 * Specifies whether to deauthenticate (`true`) or disassociate (`false`)
5143 * @param {number} [reason=1]
5144 * Specifies the IEEE 802.11 reason code to disassoc/deauth the client
5145 * with. Default is `1` which corresponds to `Unspecified reason`.
5147 * @param {number} [ban_time=0]
5148 * Specifies the amount of milliseconds to ban the client from
5149 * reconnecting. By default, no ban time is set which allows the client
5150 * to reassociate / reauthenticate immediately.
5152 * @returns {Promise<number>}
5153 * Returns a promise resolving to the underlying ubus call result code
5154 * which is typically `0`, even for not existing MAC addresses.
5155 * The promise might reject with an error in case invalid arguments
5158 disconnectClient: function(mac, deauth, reason, ban_time) {
5159 if (reason == null || reason == 0)
5165 return rpc.declare({
5166 object: 'hostapd.%s'.format(this.getIfname()),
5167 method: 'del_client',
5168 params: [ 'addr', 'deauth', 'reason', 'ban_time' ]
5169 })(mac, deauth, reason, ban_time);
5186 Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Thu Nov 07 2019 12:36:05 GMT+0100 (Central European Standard Time)
5190 <script>prettyPrint();</script>
5191 <script src="scripts/jaguar.js"></script>