1 from enigma import eTimer
2 from Screens.Screen import Screen
3 from Components.ActionMap import ActionMap, NumberActionMap
4 from Components.Pixmap import Pixmap,MultiPixmap
5 from Components.Label import Label
6 from Components.Sources.StaticText import StaticText
7 from Components.MenuList import MenuList
8 from Components.config import config, getConfigListEntry, ConfigYesNo, NoSave, ConfigSubsection, ConfigText, ConfigSelection, ConfigPassword
9 from Components.ConfigList import ConfigListScreen
10 from Components.Network import Network, iNetwork
11 from Components.Console import Console
12 from Plugins.Plugin import PluginDescriptor
13 from os import system, path as os_path, listdir
14 from Wlan import Wlan, WlanList, wpaSupplicant
15 from Wlan import Status, iStatus
17 plugin_path = "/usr/lib/enigma2/python/Plugins/SystemPlugins/WirelessLan"
23 list.append("WPA/WPA2")
26 weplist.append("ASCII")
29 config.plugins.wlan = ConfigSubsection()
30 config.plugins.wlan.essid = NoSave(ConfigText(default = "home", fixed_size = False))
31 config.plugins.wlan.hiddenessid = NoSave(ConfigText(default = "home", fixed_size = False))
33 config.plugins.wlan.encryption = ConfigSubsection()
34 config.plugins.wlan.encryption.enabled = NoSave(ConfigYesNo(default = False))
35 config.plugins.wlan.encryption.type = NoSave(ConfigSelection(list, default = "WPA/WPA2" ))
36 config.plugins.wlan.encryption.wepkeytype = NoSave(ConfigSelection(weplist, default = "ASCII"))
37 config.plugins.wlan.encryption.psk = NoSave(ConfigPassword(default = "mysecurewlan", fixed_size = False))
40 class WlanStatus(Screen):
42 <screen position="center,center" size="560,400" title="Wireless Network State" >
43 <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
44 <widget source="key_red" render="Label" position="0,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" />
46 <widget source="LabelBSSID" render="Label" position="10,60" size="250,25" valign="left" font="Regular;20" transparent="1" foregroundColor="#FFFFFF" />
47 <widget source="LabelESSID" render="Label" position="10,100" size="250,25" valign="center" font="Regular;20" transparent="1" foregroundColor="#FFFFFF" />
48 <widget source="LabelQuality" render="Label" position="10,140" size="250,25" valign="center" font="Regular;20" transparent="1" foregroundColor="#FFFFFF" />
49 <widget source="LabelSignal" render="Label" position="10,180" size="250,25" valign="center" font="Regular;20" transparent="1" foregroundColor="#FFFFFF" />
50 <widget source="LabelBitrate" render="Label" position="10,220" size="250,25" valign="center" font="Regular;20" transparent="1" foregroundColor="#FFFFFF" />
51 <widget source="LabelEnc" render="Label" position="10,260" size="250,25" valign="center" font="Regular;20" transparent="1" foregroundColor="#FFFFFF" />
53 <widget source="BSSID" render="Label" position="320,60" size="180,25" valign="center" font="Regular;20" transparent="1" foregroundColor="#FFFFFF" />
54 <widget source="ESSID" render="Label" position="320,100" size="180,25" valign="center" font="Regular;20" transparent="1" foregroundColor="#FFFFFF" />
55 <widget source="quality" render="Label" position="320,140" size="180,25" valign="center" font="Regular;20" transparent="1" foregroundColor="#FFFFFF" />
56 <widget source="signal" render="Label" position="320,180" size="180,25" valign="center" font="Regular;20" transparent="1" foregroundColor="#FFFFFF" />
57 <widget source="bitrate" render="Label" position="320,220" size="180,25" valign="center" font="Regular;20" transparent="1" foregroundColor="#FFFFFF" />
58 <widget source="enc" render="Label" position="320,260" size="180,25" valign="center" font="Regular;20" transparent="1" foregroundColor="#FFFFFF" />
60 <ePixmap pixmap="skin_default/div-h.png" position="0,350" zPosition="1" size="560,2" />
61 <widget source="IFtext" render="Label" position="10,355" size="120,21" zPosition="10" font="Regular;20" halign="left" backgroundColor="#25062748" transparent="1" />
62 <widget source="IF" render="Label" position="120,355" size="400,21" zPosition="10" font="Regular;20" halign="left" backgroundColor="#25062748" transparent="1" />
63 <widget source="Statustext" render="Label" position="10,375" size="115,21" zPosition="10" font="Regular;20" halign="left" backgroundColor="#25062748" transparent="1"/>
64 <widget name="statuspic" pixmaps="skin_default/buttons/button_green.png,skin_default/buttons/button_green_off.png" position="130,380" zPosition="10" size="15,16" transparent="1" alphatest="on"/>
68 def __init__(self, session, iface):
69 Screen.__init__(self, session)
70 self.session = session
72 self.skin = WlanStatus.skin
74 self["LabelBSSID"] = StaticText(_('Accesspoint:'))
75 self["LabelESSID"] = StaticText(_('SSID:'))
76 self["LabelQuality"] = StaticText(_('Link Quality:'))
77 self["LabelSignal"] = StaticText(_('Signal Strength:'))
78 self["LabelBitrate"] = StaticText(_('Bitrate:'))
79 self["LabelEnc"] = StaticText(_('Encryption:'))
81 self["BSSID"] = StaticText()
82 self["ESSID"] = StaticText()
83 self["quality"] = StaticText()
84 self["signal"] = StaticText()
85 self["bitrate"] = StaticText()
86 self["enc"] = StaticText()
88 self["IFtext"] = StaticText()
89 self["IF"] = StaticText()
90 self["Statustext"] = StaticText()
91 self["statuspic"] = MultiPixmap()
92 self["statuspic"].hide()
93 self["key_red"] = StaticText(_("Close"))
96 self.updateStatusbar()
98 self["actions"] = NumberActionMap(["WizardActions", "InputActions", "EPGSelectActions", "ShortcutActions"],
104 self.timer = eTimer()
105 self.timer.timeout.get().append(self.resetList)
106 self.onShown.append(lambda: self.timer.start(5000))
107 self.onLayoutFinish.append(self.layoutFinished)
108 self.onClose.append(self.cleanup)
111 iStatus.stopWlanConsole()
113 def layoutFinished(self):
114 self.setTitle(_("Wireless Network State"))
117 print "self.iface im resetlist",self.iface
118 iStatus.getDataForInterface(self.iface,self.getInfoCB)
120 def getInfoCB(self,data,status):
123 if status is not None:
124 self["BSSID"].setText(status[self.iface]["acesspoint"])
125 self["ESSID"].setText(status[self.iface]["essid"])
126 self["quality"].setText(status[self.iface]["quality"]+"%")
127 self["signal"].setText(status[self.iface]["signal"])
128 self["bitrate"].setText(status[self.iface]["bitrate"])
129 self["enc"].setText(status[self.iface]["encryption"])
130 self.updateStatusLink(status)
136 def updateStatusbar(self):
137 print "self.iface im updateStatusbar",self.iface
138 self["BSSID"].setText(_("Please wait..."))
139 self["ESSID"].setText(_("Please wait..."))
140 self["quality"].setText(_("Please wait..."))
141 self["signal"].setText(_("Please wait..."))
142 self["bitrate"].setText(_("Please wait..."))
143 self["enc"].setText(_("Please wait..."))
144 self["IFtext"].setText(_("Network:"))
145 self["IF"].setText(iNetwork.getFriendlyAdapterName(self.iface))
146 self["Statustext"].setText(_("Link:"))
148 def updateStatusLink(self,status):
149 if status is not None:
150 if status[self.iface]["acesspoint"] == "No Connection" or status[self.iface]["acesspoint"] == "Not-Associated" or status[self.iface]["acesspoint"] == False:
151 self["statuspic"].setPixmapNum(1)
153 self["statuspic"].setPixmapNum(0)
154 self["statuspic"].show()
156 class WlanScan(Screen):
158 <screen position="center,center" size="560,400" title="Choose a Wireless Network" >
159 <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
160 <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
161 <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" alphatest="on" />
162 <widget source="key_red" render="Label" position="0,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" />
163 <widget source="key_green" render="Label" position="140,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
164 <widget source="key_yellow" render="Label" position="280,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#a08500" transparent="1" />
165 <widget name="list" position="5,50" size="550,280" scrollbarMode="showOnDemand" />
166 <ePixmap pixmap="skin_default/div-h.png" position="0,340" zPosition="1" size="560,2" />
167 <widget source="info" render="Label" position="0,350" size="560,50" font="Regular;24" halign="center" valign="center" backgroundColor="#25062748" transparent="1" />
171 def __init__(self, session, iface):
172 Screen.__init__(self, session)
173 self.session = session
175 self.skin = WlanScan.skin
176 self.skin_path = plugin_path
177 self.oldInterfaceState = iNetwork.getAdapterAttribute(self.iface, "up")
179 self["info"] = StaticText()
182 self["list"] = WlanList(self.session, self.iface)
186 self["key_red"] = StaticText(_("Close"))
187 self["key_green"] = StaticText(_("Connect"))
188 self["key_yellow"] = StaticText(_("Refresh"))
190 self["actions"] = NumberActionMap(["WizardActions", "InputActions", "EPGSelectActions"],
196 self["shortcuts"] = ActionMap(["ShortcutActions"],
199 "green": self.select,
200 "yellow": self.rescan,
202 self.onLayoutFinish.append(self.layoutFinished)
204 def layoutFinished(self):
205 self.setTitle(_("Choose a wireless network"))
208 cur = self["list"].getCurrent()
211 if cur[1] is not None:
216 self.close(essid,self["list"].getList())
218 self.close(None,None)
220 self.close(None,None)
222 def WlanSetupClosed(self, *ret):
227 self["list"].reload()
231 if self.oldInterfaceState is False:
232 iNetwork.deactivateInterface(self.iface,self.deactivateInterfaceCB)
236 def deactivateInterfaceCB(self,data):
239 iNetwork.getInterfaces(self.cancelCB)
241 def cancelCB(self,data):
247 length = self["list"].getLength()
250 self["info"].setText(_("No wireless networks found! Please refresh."))
252 self["info"].setText(_("1 wireless network found!"))
254 self["info"].setText(str(length)+_(" wireless networks found!"))
257 def WlanStatusScreenMain(session, iface):
258 session.open(WlanStatus, iface)
261 def callFunction(iface):
264 i = w.getWirelessInterfaces()
267 return WlanStatusScreenMain
272 def configStrings(iface):
273 driver = iNetwork.detectWlanModule()
274 print "Found WLAN-Driver:",driver
275 if driver in ('ralink', 'zydas'):
276 return " pre-up /usr/sbin/wpa_supplicant -i"+iface+" -c/etc/wpa_supplicant.conf -B -D"+driver+"\n post-down wpa_cli terminate"
278 if config.plugins.wlan.essid.value == "hidden...":
279 return ' pre-up iwconfig '+iface+' essid "'+config.plugins.wlan.hiddenessid.value+'"\n pre-up /usr/sbin/wpa_supplicant -i'+iface+' -c/etc/wpa_supplicant.conf -B -dd -D'+driver+'\n post-down wpa_cli terminate'
281 return ' pre-up iwconfig '+iface+' essid "'+config.plugins.wlan.essid.value+'"\n pre-up /usr/sbin/wpa_supplicant -i'+iface+' -c/etc/wpa_supplicant.conf -B -dd -D'+driver+'\n post-down wpa_cli terminate'
283 def Plugins(**kwargs):
284 return PluginDescriptor(name=_("Wireless LAN"), description=_("Connect to a Wireless Network"), where = PluginDescriptor.WHERE_NETWORKSETUP, fnc={"ifaceSupported": callFunction, "configStrings": configStrings, "WlanPluginEntry": lambda x: "Wireless Network Configuartion..."})