+ if wlanconfig.method.value =="wep":
+ self.writeWpasupplicantConf("wep") # passphrasekey is not None
+ else:
+ if wlanconfig.essid.value == 'Input hidden ESSID':
+ cmd = "wpa_passphrase '%s' %s" % (wlanconfig.hiddenessid.value,wlanconfig.key.value)
+ else :
+ cmd = "wpa_passphrase '%s' %s" % (wlanconfig.essid.value,wlanconfig.key.value)
+ print cmd
+ self.wpaphraseconsole = Console()
+ self.wpaphraseconsole.ePopen(cmd, self.parseWpaPhrase, self.writeWpasupplicantConf)
+
+ def parseWpaPhrase(self, result, retval, extra_args):
+ (writewlanconfig) = extra_args
+ if self.wpaphraseconsole is not None:
+ if retval == 0:
+ self.wpaphraseconsole.killAll()
+ self.wpaphraseconsole = None
+# print "parseWpaPhrase result : "
+# print result
+ psk = None
+ for line in result.splitlines():
+ if line.find('ssid') == -1 and line.find('#psk=') != -1:
+ plainpwd = line
+ elif line.find('psk=') != -1:
+ psk = line
+ if psk:
+ writewlanconfig(psk,plainpwd)
+ else:
+ writewlanconfig(None)
+ else:
+ writewlanconfig(None)
+
+ def writeWpasupplicantConf(self, passphrasekey=None,plainpwd=None):
+ if passphrasekey:
+ wpafd = open("/etc/wpa_supplicant.conf","w")
+ if wpafd > 0:
+ contents = "#WPA Supplicant Configuration by STB\n"
+ contents += "ctrl_interface=/var/run/wpa_supplicant\n"
+ contents += "eapol_version=1\n"
+ contents += "fast_reauth=1\n"
+ contents += "ap_scan=1\n"
+ contents += "network={\n"
+ if wlanconfig.essid.value == 'Input hidden ESSID':
+ contents += "\tssid=\""+wlanconfig.hiddenessid.value+"\"\n"
+ contents += "\tscan_ssid=1\n"
+ else :
+ contents += "\tssid=\""+wlanconfig.essid.value+"\"\n"
+ contents += "\tscan_ssid=0\n"
+ if wlanconfig.encrypt.value == "on":
+ if wlanconfig.method.value =="wep":
+ contents += "\tkey_mgmt=NONE\n"
+ contents += "\twep_key0="
+ if wlanconfig.keytype.value == "ascii":
+ contents += "\""+wlanconfig.key.value+"\"\n"
+ else:
+ contents += wlanconfig.key.value+"\n"
+ else:
+# print "plainpwd : ",plainpwd
+# print "passphrasekey : ",passphrasekey
+ if wlanconfig.method.value == "wpa":
+ contents += "\tkey_mgmt=WPA-PSK\n"
+ contents += "\tproto=WPA\n"
+ contents += "\tpairwise=CCMP TKIP\n"
+ contents += "\tgroup=CCMP TKIP\n"
+ elif wlanconfig.method.value == "wpa2":
+ contents += "\tkey_mgmt=WPA-PSK\n"
+ contents += "\tproto=RSN\n"
+ contents += "\tpairwise=CCMP TKIP\n"
+ contents += "\tgroup=CCMP TKIP\n"
+ else:
+ contents += "\tkey_mgmt=WPA-PSK\n"
+ contents += "\tproto=WPA RSN\n"
+ contents += "\tpairwise=CCMP TKIP\n"
+ contents += "\tgroup=CCMP TKIP\n"
+ contents += plainpwd+"\n"
+ contents += passphrasekey+"\n"
+ else:
+ contents += "\tkey_mgmt=NONE\n"
+ contents += "}\n"
+ print "content = \n"+contents
+ wpafd.write(contents)
+ wpafd.close()
+ self.writeNetConfig(0)
+ else :
+ self.session.open(MessageBox, _("wpa_supplicant.conf open error."), type = MessageBox.TYPE_ERROR, timeout = 10)
+ self.writeNetConfig(-1)
+ else:
+ self.writeNetConfig(-2)
+
+ def writeNetConfig(self,ret = -1):