1 from Plugins.Plugin import PluginDescriptor
3 from Screens.Screen import Screen
4 from Screens.MessageBox import MessageBox
5 from Screens.DefaultWizard import DefaultWizard
6 from Screens.Standby import TryQuitMainloop
7 from Screens.VirtualKeyBoard import VirtualKeyBoard
9 from Components.Label import Label
10 from Components.Sources.StaticText import StaticText
11 from Components.ActionMap import NumberActionMap, ActionMap
12 from Components.Network import iNetwork
13 from Components.MenuList import MenuList
14 from Components.config import config, getConfigListEntry, ConfigInteger, ConfigSubsection, ConfigSelection, ConfigText, ConfigYesNo, NoSave, ConfigNothing
15 from Components.ConfigList import ConfigListScreen
16 from Components.Pixmap import Pixmap
18 from Tools.Directories import resolveFilename, SCOPE_PLUGINS, SCOPE_CURRENT_PLUGIN
20 from enigma import eTimer, eConsoleAppContainer, eSocketNotifier, getDesktop
21 from select import POLLIN, POLLPRI
22 from xml.sax import make_parser, handler
23 import os, socket, time
25 debug_mode_modem_mgr = False
26 def printDebugModemMgr(msg):
27 global debug_mode_modem_mgr
28 if debug_mode_modem_mgr:
29 print "[ModemManager Plugin] Debug >>", msg
31 def printInfoModemMgr(msg):
32 print "[ModemManager Plugin] Info >>", msg
34 isEmpty = lambda x: x is None or len(x)==0
37 def read_file(path, key):
38 if os.path.exists(path):
39 return key + open(path).read()
42 def parse_usb_uevent(datas):
44 datas_lines = datas.splitlines()
45 for data in datas_lines:
47 if kv[0] in ('BUSNUM', 'DRIVER', 'PRODUCT', 'SERIAL', 'PNAME', 'MANUFACTUER', 'PRODUCTID', 'VENDORID'):
48 uevent_map[kv[0]] = kv[1]
52 def read_usb_uevent(dir_path):
53 uevent_data = open(dir_path + "/uevent").read()
54 if uevent_data.find('DRIVER=hub') == -1:
55 uevent_data += read_file(dir_path + "/serial", "SERIAL=")
56 uevent_data += read_file(dir_path + "/product", "PNAME=")
57 uevent_data += read_file(dir_path + "/idProduct", "PRODUCTID=")
58 uevent_data += read_file(dir_path + "/idVendor", "VENDORID=")
59 uevent_data += read_file(dir_path + "/manufacturer", "MANUFACTUER=")
63 def make_script(item):
66 script += 'T: Bus=%s\n' % (item['BUSNUM'])
69 script += 'P: Vendor=%s ProdID=%s\n' % (item['VENDORID'], item['PRODUCTID'])
72 script += 'S: Manufacturer=%s\n' % (item['MANUFACTUER'])
75 script += 'S: Product=%s\n' % (item['PNAME'])
78 script += 'S: SerialNumber=%s\n' % (item['SERIAL'])
81 script += 'I:* Driver=%s\n' % (item['DRIVER'])
90 for root, dirs, files in os.walk('/sys/bus/usb/devices', topdown=False):
92 if name.startswith('usb'):
94 uevnet_data = read_usb_uevent(os.path.join(root, name))
95 if uevnet_data is not None:
96 uevent_map = parse_usb_uevent(uevnet_data)
97 devices_list.append(uevent_map)
100 for item in devices_list:
102 if item['DRIVER'] == 'usb-storage':
103 usbstorage_list.append(item['PRODUCT'])
106 for item1 in usbstorage_list:
107 for item2 in devices_list:
109 if item2['PRODUCT'] == item1 and item2['DRIVER'] == 'usb':
110 all_script += make_script(item2)
114 class DeviceEventListener:
115 notifyCallbackFunctionList = []
117 self.sock = socket.socket(socket.AF_NETLINK, socket.SOCK_DGRAM, 15)
119 self.sock.bind((os.getpid(), 1))
120 self.notifier = eSocketNotifier(self.sock.fileno(), POLLIN|POLLPRI)
121 self.notifier.callback.append(self.cbEventHandler)
122 except Exception, msg:
123 print "[ModemManager Plugin] Error >>", msg
126 def cbEventHandler(self, sockfd):
127 recv = self.sock.recv(65536)
128 #printDebugModemMgr(str(recv.splitlines()))
129 if recv.startswith("add@/block") or recv.startswith("remove@/block"):
130 for x in self.notifyCallbackFunctionList:
132 except: self.notifyCallbackFunctionList.remove(x)
134 def addCallback(self, func):
136 self.notifyCallbackFunctionList.append(func)
138 def delCallback(self, func):
140 self.notifyCallbackFunctionList.remove(func)
144 self.notifier.callback.remove(self.cbEventHandler)
152 self.gTaskInstance = None
153 self.occurError = False
154 self.cbSetStatusCB = None
156 def append(self, command, cbDataFunc, cbCloseFunc):
157 self.taskList.append([command+'\n', cbDataFunc, cbCloseFunc])
160 print "############### TASK ###############"
161 print "Current Task Index :", self.taskIdx
162 print "Current Task Instance :", self.gTaskInstance
163 print "Occur Error :", self.occurError
164 print "Task List:\n", self.taskList
165 print "####################################"
168 printInfoModemMgr("set task error!!")
169 self.occurError = True
173 self.gTaskInstance = None
174 self.occurError = False
179 self.cbSetStatusCB = None
185 def setStatusCB(self, cbfunc):
186 self.cbSetStatusCB = cbfunc
189 if self.taskIdx >= len(self.taskList) or self.occurError:
190 printInfoModemMgr("can't run task!!")
192 command = self.taskList[self.taskIdx][0]
193 cbDataFunc = self.taskList[self.taskIdx][1]
194 cbCloseFunc = self.taskList[self.taskIdx][2]
196 self.gTaskInstance = eConsoleAppContainer()
197 if cbDataFunc is not None:
198 self.gTaskInstance.dataAvail.append(cbDataFunc)
199 if cbCloseFunc is not None:
200 self.gTaskInstance.appClosed.append(cbCloseFunc)
201 if self.cbSetStatusCB is not None:
202 self.cbSetStatusCB(self.taskIdx)
204 printInfoModemMgr("prepared command :%s"%(command))
205 self.gTaskInstance.execute(command)
209 class ParserHandler(handler.ContentHandler):
213 def startDocument(self):
215 def endDocument(self):
217 def startElement(self, name, attrs):
220 for attr in attrs.getNames():
221 node[attr] = str(attrs.getValue(attr))
222 self.nodeList.append(node)
223 def endElement(self, name):
225 def characters(self, content):
227 def setDocumentLocator(self, locator):
229 def getNodeList(self):
232 class EditModemManual(ConfigListScreen, Screen):
233 param = int(getDesktop(0).size().height()) >= 720 and (450,360) or (160,300)
235 <screen position="center,center" size="600,360" title="3G Modem Manager Config Edit">
236 <widget name="config" zPosition="2" position="0,0" size="600,300" scrollbarMode="showOnDemand" transparent="1" />
238 <ePixmap pixmap="skin_default/buttons/red.png" position="5,320" size="140,40" alphatest="on" />
239 <ePixmap pixmap="skin_default/buttons/green.png" position="155,320" size="140,40" alphatest="on" />
240 <ePixmap pixmap="skin_default/buttons/yellow.png" position="305,320" size="140,40" alphatest="on" />
241 <ePixmap pixmap="skin_default/buttons/blue.png" position="455,320" size="140,40" alphatest="on" />
243 <widget source="key_red" render="Label" position="5,320" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" foregroundColor="#ffffff" transparent="1" />
244 <widget source="key_green" render="Label" position="155,320" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" foregroundColor="#ffffff" transparent="1" />
245 <widget source="key_blue" render="Label" position="455,320" zPosition="1" size="140,40" font="Regular;20" valign="center" halign="center" backgroundColor="#18188b" foregroundColor="#ffffff" transparent="1" />
247 <widget name="VKeyIcon" pixmap="skin_default/buttons/key_text.png" position="50,200" zPosition="10" size="35,25" transparent="1" alphatest="on" />
248 <widget name="HelpWindow" pixmap="skin_default/vkey_icon.png" position="%d,%d" zPosition="1" size="1,1" transparent="1" alphatest="on" />
252 def __init__(self, session, cbFuncClose, uid=None, pwd=None, pin=None, apn=None, phone='*99#', isAdd=False):
253 Screen.__init__(self, session)
254 self.cbFuncClose, self.isAdd = cbFuncClose, isAdd
257 self.uid,self.pwd,self.pin,self.apn,self.phone = "","","","",""
259 self.uid,self.pwd,self.pin,self.apn,self.phone = uid,pwd,pin,apn,phone
260 if self.uid is None: self.uid = ""
261 if self.pwd is None: self.pwd = ""
262 if self.pin is None: self.pin = ""
263 if self.apn is None: self.apn = ""
264 if self.phone is None: self.phone = ""
266 self["actions"] = ActionMap(["OkCancelActions", "ShortcutActions", "WizardActions", "ColorActions", "SetupActions",],
269 "cancel": self.keyExit,
272 "blue": self.keyRemove,
275 self["VirtualKB"] = ActionMap(["VirtualKeyboardActions" ],
277 "showVirtualKeyboard": self.KeyText,
281 ConfigListScreen.__init__(self, self.configList, session=session)
282 self.createConfigList()
284 self["key_red"] = StaticText(_("Cancel"))
285 self["key_green"] = StaticText(_("Save"))
286 self["key_blue"] = StaticText(_(self.isAdd and " " or "Remove"))
287 self["VKeyIcon"] = Pixmap()
288 self["HelpWindow"] = Pixmap()
289 self["VirtualKB"].setEnabled(False)
291 self.setTitle("3G Modem Manager Config Add")
293 def createConfigList(self):
294 self.configName = ConfigText(default="", visible_width=50, fixed_size=False)
295 self.configUserName = ConfigText(default=str(self.uid), visible_width=50, fixed_size=False)
296 self.configPassword = ConfigText(default=str(self.pwd), visible_width=50, fixed_size=False)
297 self.configAPN = ConfigText(default=str(self.apn), visible_width=50, fixed_size=False)
298 self.configPIN = ConfigText(default=str(self.pin), visible_width=50, fixed_size=False)
299 self.configPhone = ConfigText(default=str(self.phone), visible_width=50, fixed_size=False)
301 self.configEntryName = getConfigListEntry(_("Name :"), self.configName)
302 self.configEntryUserName = getConfigListEntry(_("User :"), self.configUserName)
303 self.configEntryPassword = getConfigListEntry(_("Password :"), self.configPassword)
304 self.configEntryAPN = getConfigListEntry(_("APN :"), self.configAPN)
305 self.configEntryPIN = getConfigListEntry(_("PIN :"), self.configPIN)
306 self.configEntryPhone = getConfigListEntry(_("Phone :"), self.configPhone)
309 self.configList.append(self.configEntryName)
310 self.configList.append(self.configEntryUserName)
311 self.configList.append(self.configEntryPassword)
312 self.configList.append(self.configEntryAPN)
313 self.configList.append(self.configEntryPIN)
314 self.configList.append(self.configEntryPhone)
316 self["config"].list = self.configList
317 self["config"].l.setList(self.configList)
319 def getCurrentItem(self):
320 currentPosition = self["config"].getCurrent()
321 if currentPosition == self.configEntryName:
322 return self.configName
323 if currentPosition == self.configEntryUserName:
324 return self.configUserName
325 elif currentPosition == self.configEntryPassword:
326 return self.configPassword
327 elif currentPosition == self.configEntryAPN:
328 return self.configAPN
329 elif currentPosition == self.configEntryPIN:
330 return self.configPIN
331 elif currentPosition == self.configEntryPhone:
332 return self.configPhone
336 currentItemValue = ""
337 currentItem = self.getCurrentItem()
338 if currentItem is not None:
339 currentItemValue = currentItem.value
340 if isEmpty(currentItemValue):
341 currentItemValue = ""
342 self.session.openWithCallback(self.cbKeyText, VirtualKeyBoard, title=("Please input here"), text=currentItemValue)
344 def cbKeyText(self, data=None):
346 currentItem = self.getCurrentItem()
347 if currentItem is not None:
348 currentItem.setValue(data)
356 if self.cbFuncClose is not None:
357 self.cbFuncClose(isRemove = True)
360 def showKeyboard(self, ret=None):
361 self["VKeyIcon"].show()
362 current = self["config"].getCurrent()
363 if hasattr(current[1], 'help_window'):
364 if current[1].help_window.instance is not None:
365 current[1].help_window.instance.show()
367 def hideKeyboard(self):
368 self["VKeyIcon"].hide()
369 current = self["config"].getCurrent()
370 if hasattr(current[1], 'help_window'):
371 if current[1].help_window.instance is not None:
372 current[1].help_window.instance.hide()
375 message = '%s field is empty!!'
376 if isEmpty(self.configName.value) and self.isAdd:
378 self.session.openWithCallback(self.showKeyboard, MessageBox, message%('Name'), MessageBox.TYPE_INFO)
380 if isEmpty(self.configAPN.value):
382 self.session.openWithCallback(self.showKeyboard, MessageBox, message%('APN'), MessageBox.TYPE_INFO)
385 if self.cbFuncClose is not None:
386 self.uid = self.configUserName.value
387 self.pwd = self.configPassword.value
388 self.pin = self.configPIN.value
389 self.apn = self.configAPN.value
390 self.phone = self.configPhone.value
391 self.name = self.isAdd and self.configName.value or None
392 self.cbFuncClose(self.uid,self.pwd,self.pin,self.apn,self.phone,self.name)
395 class ModemManual(Screen):
397 <screen position="center,center" size="600,360" title="3G Modem Manager Config">
398 <widget name="menulist" position="0,0" size="300,300" backgroundColor="#000000" zPosition="10" scrollbarMode="showOnDemand" />
399 <widget name="apnInfo" position="310,0" size="290,300" font="Regular;20" halign="left" backgroundColor="#a08500" transparent="1" />
401 <ePixmap pixmap="skin_default/buttons/red.png" position="5,320" size="140,40" alphatest="on" />
402 <ePixmap pixmap="skin_default/buttons/green.png" position="155,320" size="140,40" alphatest="on" />
403 <ePixmap pixmap="skin_default/buttons/yellow.png" position="305,320" size="140,40" alphatest="on" />
404 <ePixmap pixmap="skin_default/buttons/blue.png" position="455,320" size="140,40" alphatest="on" />
406 <widget source="key_red" render="Label" position="5,320" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" foregroundColor="#ffffff" transparent="1" />
407 <widget source="key_green" render="Label" position="155,320" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" foregroundColor="#ffffff" transparent="1" />
408 <widget source="key_yellow" render="Label" position="305,320" zPosition="1" size="140,40" font="Regular;20" valign="center" halign="center" backgroundColor="#a08500" foregroundColor="#ffffff" transparent="1" />
409 <widget source="key_blue" render="Label" position="455,320" zPosition="1" size="140,40" font="Regular;20" valign="center" halign="center" backgroundColor="#18188b" foregroundColor="#ffffff" transparent="1" />
413 def __init__(self, session, cbFuncClose, uid=None, pwd=None, pin=None, apn=None, phone='*99#'):
414 Screen.__init__(self, session)
415 self.cbFuncClose,self.uid,self.pwd,self.pin,self.apn,self.phone = cbFuncClose,uid,pwd,pin,apn,phone
416 self["actions"] = ActionMap(["OkCancelActions", "ShortcutActions", "WizardActions", "ColorActions", "SetupActions"],
419 "cancel": self.keyExit,
422 "yellow": self.keyEdit,
424 "left": self.keyLeft,
425 "right": self.keyRight,
427 "down": self.keyDown,
430 self.apnItems = self.setListOnView()
431 self["menulist"] = MenuList(self.apnItems)
432 self["key_red"] = StaticText(_("Cancel"))
433 self["key_green"] = StaticText(_("OK"))
434 self["key_yellow"] = StaticText(_("Edit"))
435 self["key_blue"] = StaticText(_("Add"))
436 self["apnInfo"] = Label(' ')
441 self.session.open(EditModemManual, self.cb3GManualSetting, isAdd=True)
444 self.session.open(EditModemManual, self.cb3GManualSetting, self.uid,self.pwd,self.pin,self.apn,self.phone)
446 def cb3GManualSetting(self, uid=None, pwd=None, pin=None, apn=None, phone='*99#', name=None, isRemove=False):
448 self.uid = isEmpty(uid) and "" or uid
449 self.pwd = isEmpty(pwd) and "" or pwd
450 self.pin = isEmpty(pin) and "" or pin
451 self.apn = isEmpty(apn) and "" or apn
452 self.phone = isEmpty(phone) and "" or phone
455 self["menulist"].list.append((name, {'carrier':name, 'apn':self.apn, 'user':self.uid, 'password':self.pwd, 'pin':self.pin, 'phone':self.phone}))
456 self["menulist"].setList(self["menulist"].list)
457 self["menulist"].moveToIndex(len(self["menulist"].list)-1)
461 selectedIndex = self["menulist"].getSelectionIndex()
462 for x in self["menulist"].list:
463 if index == selectedIndex:
468 self["menulist"].setList(newList)
469 self["menulist"].moveToIndex(0)
470 self.setAPNInfo(True)
472 if not isRemove and isEmpty(name):
475 self.saveAPNList(name)
477 def updateAPNList(self):
478 selectedIndex = self["menulist"].getSelectionIndex()
479 apnList = self["menulist"].list
480 currentListItem = apnList[selectedIndex][1]
482 currentListItem['user'] = self.uid
483 currentListItem['apn'] = self.apn
484 currentListItem['password'] = self.pwd
485 currentListItem['pin'] = self.pin
486 currentListItem['phone'] = self.phone
488 self["menulist"].setList(apnList)
490 def saveAPNList(self, name=None):
491 apnList = self["menulist"].list
492 selectedIndex = self["menulist"].getSelectionIndex()
494 def makeItem(carrier, apn, user, password, pin, phone):
495 printDebugModemMgr("%s, %s, %s, %s, %s, %s"%(carrier, apn, user, password, pin, phone))
497 tempStr += ' carrier="%s"'%(carrier)
498 tempStr += ' apn="%s"'%(apn)
499 if not isEmpty(user): tempStr += ' user="%s"'%(user)
500 if not isEmpty(password): tempStr += ' password="%s"'%(password)
501 if not isEmpty(pin): tempStr += ' pin="%s"'%(pin)
502 if not isEmpty(phone) : tempStr += ' phone="%s"'%(phone)
507 apnString = '<apns version="1">\n'
510 if selectedIndex == tempIndex and name is None:
511 apnString += makeItem(x[0], self.apn, self.uid, self.pwd, self.pin, self.phone)
513 apnString += makeItem(x[1].get('carrier'), x[1].get('apn'), x[1].get('user'), x[1].get('password'), x[1].get('pin'), x[1].get('phone'))
514 finally: tempIndex += 1
515 apnString += '</apns>\n'
516 printDebugModemMgr(apnString)
517 apnListFile = file(resolveFilename(SCOPE_CURRENT_PLUGIN, "SystemPlugins/3GModemManager/apnlist.xml"), 'w')
518 apnListFile.write(apnString)
522 self['menulist'].pageUp()
526 self['menulist'].pageDown()
530 self['menulist'].up()
534 self['menulist'].down()
538 if self.cbFuncClose is not None:
539 self.cbFuncClose(self.uid,self.pwd,self.pin,self.apn,self.phone)
545 def setAPNInfo(self, noUpdate=False):
547 x = self["menulist"].getCurrent()[1]
548 self.apn, self.uid, self.pwd, self.pin, self.phone = x.get("apn"), x.get("user"), x.get("password"), x.get('pin'), x.get('phone')
549 except Exception, err: pass
553 def updateAPNInfo(self):
554 apn,uid,pwd,pin,phone = self.apn,self.uid,self.pwd,self.pin,self.phone
555 if apn is None: apn = ""
556 if uid is None: uid = ""
557 if pwd is None: pwd = ""
558 if pin is None: pin = ""
559 if phone is None: phone = ""
560 info = 'APN : %s\nUSER : %s\nPASSWD : %s\nPIN : %s\nPHONE : %s\n' % (apn, uid, pwd, pin, phone)
561 self["apnInfo"].setText(info)
563 def setListOnView(self):
565 def uppercaseCompare(a,b):
566 aa = a.get("carrier")
567 bb = b.get("carrier")
568 if isEmpty(aa): aa = ""
569 if isEmpty(bb): bb = ""
570 return cmp(aa.upper(),bb.upper())
571 def isExistAPN(name):
577 handle = ParserHandler()
578 parser = make_parser()
579 parser.setContentHandler(handle)
580 parser.parse(resolveFilename(SCOPE_CURRENT_PLUGIN, "SystemPlugins/3GModemManager/apnlist.xml"))
582 apnList = handle.getNodeList()
583 apnList.sort(uppercaseCompare)
585 name = str(x.get('carrier'))
592 d['apn'] = x.get('apn')
593 d['user'] = x.get('user')
594 d['password'] = x.get('password')
595 d['pin'] = x.get('pin')
596 d['phone'] = x.get('phone')
597 lvApnItems.append((name,d))
598 except Exception, err: pass
602 class ModemManager(Screen):
604 <screen position="center,center" size="600,360" title="3G Modem Manager">
605 <widget name="menulist" position="0,0" size="300,150" backgroundColor="#000000" zPosition="10" scrollbarMode="showOnDemand" />
606 <widget name="usbinfo" position="310,0" size="290,150" font="Regular;18" halign="left" />
608 <widget name="statusTitle" position="0,160" size="600,120" font="Regular;20" halign="center" backgroundColor="#a08500" transparent="1" />
609 <widget name="statusInfo" position="0,185" size="600,120" font="Regular;20" halign="left" backgroundColor="#a08500" transparent="1" />
611 <ePixmap pixmap="skin_default/buttons/red.png" position="5,320" size="140,40" alphatest="on" />
612 <ePixmap pixmap="skin_default/buttons/green.png" position="155,320" size="140,40" alphatest="on" />
613 <ePixmap pixmap="skin_default/buttons/yellow.png" position="305,320" size="140,40" alphatest="on" />
614 <ePixmap pixmap="skin_default/buttons/blue.png" position="455,320" size="140,40" alphatest="on" />
616 <widget source="key_red" render="Label" position="5,320" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" foregroundColor="#ffffff" transparent="1" />
617 <widget source="key_green" render="Label" position="155,320" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" foregroundColor="#ffffff" transparent="1" />
618 <widget source="key_yellow" render="Label" position="305,320" zPosition="1" size="140,40" font="Regular;20" valign="center" halign="center" backgroundColor="#a08500" foregroundColor="#ffffff" transparent="1" />
619 <widget source="key_blue" render="Label" position="455,320" zPosition="1" size="140,40" font="Regular;20" valign="center" halign="center" backgroundColor="#18188b" foregroundColor="#ffffff" transparent="1" />
622 uid,pwd,pin,apn,phone = None,None,None,None,'*99#'
624 def __init__(self, session):
625 Screen.__init__(self, session)
626 self.usb_lv_items = self.setListOnView()
628 self["actions"] = ActionMap(["OkCancelActions", "ShortcutActions", "WizardActions", "ColorActions", "SetupActions", "NumberActions"],
631 "cancel": self.keyExit,
634 "yellow": self.keyManual,
635 "blue": self.keyReset,
637 "down": self.keyDown,
638 "left": self.keyLeft,
639 "right": self.keyRight,
642 self["menulist"] = MenuList(self.usb_lv_items)
643 self['usbinfo'] = Label(' ')
644 self['statusTitle'] = Label('[ Status ]')
645 self['statusInfo'] = Label(' ')
646 self["key_red"] = StaticText(_("Exit"))
647 if self.isConnected():
648 self["key_green"] = StaticText("Disconnect")
649 self.setDisconnectStatus(0)
651 self["key_green"] = StaticText("Connect")
652 self.setConnectStatus(0)
653 self["key_yellow"] = StaticText(_("Manual"))
654 self["key_blue"] = StaticText(_("Reset"))
658 self.udevListener = DeviceEventListener()
659 self.udevListener.addCallback(self.cbUdevListener)
661 self.taskManager = TaskManager()
663 self.refreshStatusTimer = eTimer()
664 self.refreshStatusTimer.callback.append(self.cbRefreshStatus)
666 #self.restartAppTimer = eTimer()
667 #self.restartAppTimer.callback.append(self.cbRestartAppTimer)
668 self.commandBin = resolveFilename(SCOPE_CURRENT_PLUGIN, "SystemPlugins/3GModemManager/3gcommand")
669 self.forceStop = False
671 def cbRestartAppTimer(self):
672 self.restartAppTimer.stop()
673 model = file('/proc/stb/info/vumodel').read().strip()
674 if model is not None:
675 if model == 'solo' or model == 'bm750':
676 self.session.open(TryQuitMainloop, 3)
678 def cbRefreshStatus(self):
679 self.refreshStatusTimer.stop()
680 if self["key_green"].getText() == 'Connect':
681 self.setConnectStatus(0)
682 elif self["key_green"].getText() == 'Disconnect':
683 self.setDisconnectStatus(0)
685 def cbUdevListener(self, data):
686 printDebugModemMgr('Udev Listener Refresh!!')
688 self["menulist"].setList(self.setListOnView())
691 def isAttemptConnect(self):
692 if self.connectionStatus == 0 or self.forceStop:
695 if self["key_green"].getText() == 'Disconnect':
697 if self.connectionStatus < maxIdx:
698 printInfoModemMgr("can't excute a command during connecting...")
703 if self.isAttemptConnect():
705 self.session.open(ModemManual, self.cb3GManualSetting, self.uid,self.pwd,self.pin,self.apn,self.phone)
706 #self.session.open(ModemManual, self.cb3GManualSetting)
709 if self.isAttemptConnect():
711 self.cb3GManualSetting()
713 def cb3GManualSetting(self, uid=None, pwd=None, pin=None, apn=None, phone='*99#'):
714 self.uid,self.pwd,self.pin,self.apn,self.phone = uid,pwd,pin,apn,phone
717 def keyNumber(self, num=None):
718 global debug_mode_modem_mgr
719 debug_mode_modem_mgr = not debug_mode_modem_mgr
720 printInfoModemMgr('changed log mode, debug %s'%(debug_mode_modem_mgr and 'on' or 'off'))
723 if self.isAttemptConnect():
724 message = "Can't disconnect doring connecting..\nDo you want to forcibly exit?"
725 self.session.openWithCallback(self.cbForciblyExit, MessageBox, _(message), default = False)
727 self.udevListener.close()
730 def cbForciblyExit(self, result):
732 os.system('%s -s 6' % self.commandBin)
733 self.udevListener.close()
737 self["menulist"].pageUp()
741 self["menulist"].pageDown()
745 self["menulist"].up()
749 self["menulist"].down()
753 self.forceStop = False
754 if self.isAttemptConnect():
757 def areadyExistAnotherAdapter():
758 networkAdapters = iNetwork.getConfiguredAdapters()
759 for x in networkAdapters:
764 if self["key_green"].getText() == 'Disconnect':
765 message = "Do you want to disconnect?"
766 self.session.openWithCallback(self.cbConfirmDone, MessageBox, _(message), default = False)
769 if areadyExistAnotherAdapter():
770 message = "Another adapter connected has been found.\n\nA connection is attempted after disconnect all of other device. Do you want to?"
771 self.session.openWithCallback(self.cbConfirmDone, MessageBox, _(message), default = True)
772 else: self.cbConfirmDone(True)
774 def cbConfirmDone(self, ret):
776 if self["key_green"].getText() == 'Connect':
777 networkAdapters = iNetwork.getConfiguredAdapters()
778 for x in networkAdapters:
779 if x[:3] == 'ppp': continue
780 iNetwork.setAdapterAttribute(x, "up", False)
781 iNetwork.deactivateInterface(x)
784 try: x = self["menulist"].getCurrent()[1]
786 printInfoModemMgr('no selected device..')
789 devFile = '/usr/share/usb_modeswitch/%s:%s' % (x.get("Vendor"), x.get("ProdID"))
790 if not os.path.exists(devFile) :
791 message = "Can't found device file!! [%s]" % (devFile)
792 printInfoModemMgr(message)
793 self.session.open(MessageBox, _(message), MessageBox.TYPE_INFO)
796 if self["key_green"].getText() == 'Disconnect':
797 cmd = "%s -s 0" % (self.commandBin)
798 self.taskManager.append(cmd, self.cbPrintAvail, self.cbPrintClose)
800 cmd = "%s -s 1" % (self.commandBin)
801 self.taskManager.append(cmd, self.cbPrintAvail, self.cbUnloadClose)
802 self.taskManager.setStatusCB(self.setDisconnectStatus)
804 cmd = "%s -s 2 -e vendor=0x%s -e product=0x%s" % (self.commandBin, x.get("Vendor"), x.get("ProdID"))
805 self.taskManager.append(cmd, self.cbStep1PrintAvail, self.cbPrintClose)
807 cmd = "%s -s 3 -e %s:%s" % (self.commandBin, x.get("Vendor"), x.get("ProdID"))
808 self.taskManager.append(cmd, self.cbPrintAvail, self.cbPrintClose)
810 cmd = "%s -s 4" % (self.commandBin)
811 self.taskManager.append(cmd, self.cbStep3PrintAvail, self.cbMakeWvDialClose)
813 cmd = "%s -s 5" % (self.commandBin)
814 self.taskManager.append(cmd, self.cbRunWvDialAvail, self.cbPrintClose)
815 self.taskManager.setStatusCB(self.setConnectStatus)
817 self.taskManager.next()
819 def printStatus(self, idx, STATUS):
821 self.connectionStatus = idx
822 for x in range(0,len(STATUS)):
828 self['statusInfo'].setText(message)
830 def setConnectStatus(self, idx):
832 0:'1. Load a Mobile Broadband Device'
833 ,1:'2. Set up a Mobile Broadband Device'
834 ,2:'3. Generate a WvDial profile'
835 ,3:'4. Attempt to connect'
838 self.printStatus(idx, STATUS)
840 def setDisconnectStatus(self, idx):
843 ,1:'2. Unload a Mobile Broadband Device'
846 self.printStatus(idx, STATUS)
848 def cbStep1PrintAvail(self, data):
850 if data.find('modules.dep') > -1:
851 self.forceStop = True
853 def cbStep3PrintAvail(self, data):
855 if data.find('no modem was detected') > -1:
856 self.forceStop = True
858 def cbPrintAvail(self, data):
861 def cbPrintClose(self, ret):
863 self.taskManager.clean()
865 message = "Occur error during connection...\nPlease, Check your setting!!"
866 self.session.open(MessageBox, _(message), MessageBox.TYPE_INFO)
868 self.taskManager.next()
870 def cbUnloadClose(self, ret):
871 self.taskManager.clean()
873 self["key_green"].setText('Connect')
874 self.setDisconnectStatus(2)
875 self.refreshStatusTimer.start(1000)
877 def cbRunWvDialAvail(self, data):
879 if data.find('Bad init') > -1 or data.find('Invalid dial') > -1 or data.find('No Carrier') > -1:
880 self.forceStop = True
882 if data.find('Pid of pppd:') > -1:
883 self.taskManager.clean()
885 self["key_green"].setText('Disconnect')
886 self.setConnectStatus(4)
887 self.refreshStatusTimer.start(1000)
888 #self.restartAppTimer.start(3000)
890 def cbMakeWvDialClose(self, ret):
892 self.taskManager.clean()
894 message = "Occur error during connection...\nPlease, Check your setting!!"
895 self.session.open(MessageBox, _(message), MessageBox.TYPE_INFO)
901 datalist = file('/etc/wvdial.conf').read().splitlines()
903 if x.startswith('Modem ='):
905 info['Modem'] = x[7:].strip()
906 elif x.startswith('Init2 ='):
908 info['Init'] = x[7:].strip()
909 elif x.startswith('Baud ='):
911 info['Baud'] = x[6:].strip()
912 except Exception, err:
913 printDebugModemMgr("getModemInfo Error : [%s]" % (str(err)))
914 # TODO : occur error!!
917 if not isEmpty(self.apn): info['apn'] = self.apn
918 if not isEmpty(self.uid): info['uid'] = self.uid
919 if not isEmpty(self.pwd): info['pwd'] = self.pwd
920 if not isEmpty(self.pin): info['pin'] = self.pin
921 if not isEmpty(self.phone): info['phone'] = self.phone
922 #info['phone'] = '*99#'
923 self.makeWvDialConf(info)
924 self.taskManager.next()
926 def writeConf(self, data, oper='>>'):
927 confFile = '/etc/wvdial.conf'
929 os.system('mv %s %s.bak' % (confFile, confFile))
930 cmd = "echo '%s' %s %s" % (data, oper, confFile)
933 def makeWvDialConf(self, params):
934 baud = params.get('Baud')
935 init = params.get('Init')
936 modem = params.get('Modem')
937 phone = params.get('phone')
938 apn = params.get('apn')
939 uid = params.get('uid')
940 pwd = params.get('pwd')
941 pin = params.get('pin')
944 if isEmpty(phone): phone = '*99#'
945 if isEmpty(uid): uid = 'USER'
946 if isEmpty(pwd): pwd = 'PASSWORD'
948 self.writeConf('','>')
950 self.writeConf('[Dialer Defaults]')
951 if isEmpty(modem) or isEmpty(init) or isEmpty(baud):
953 self.writeConf('Modem = %s' % (modem))
954 self.writeConf('Baud = %s' % (baud))
955 self.writeConf('Dial Command = ATDT')
956 self.writeConf('Init%d = ATZ' % (idxInit))
957 idxInit = idxInit + 1
959 self.writeConf('Init%d = AT+CPIN=%s' % (idxInit, pin))
960 idxInit = idxInit + 1
961 self.writeConf('Init%d = %s' % (idxInit, init))
962 idxInit = idxInit + 1
963 if isEmpty(apn) and isEmpty(uid) and isEmpty(pwd) and isEmpty(pin):
964 self.writeConf('Init%d = AT&F' % (idxInit))
965 idxInit = idxInit + 1
967 self.writeConf('Init%d = AT+CGDCONT=1,"IP","%s"' % (idxInit, apn))
968 idxInit = idxInit + 1
969 self.writeConf('Init%d = AT+CFUN = 1' % (idxInit))
970 self.writeConf('Username = %s' % (uid))
971 self.writeConf('Password = %s' % (pwd))
972 self.writeConf('Phone = %s' % (phone)) #*99#
973 self.writeConf('Modem Type = Analog Modem')
974 self.writeConf('ISDN = 0')
975 self.writeConf('Carrier Check = 0')
976 self.writeConf('Abort on No Dialtone = 0')
977 self.writeConf('Stupid Mode = 1')
978 self.writeConf('Check DNS = 1')
979 self.writeConf('Check Def Route = 1')
980 self.writeConf('Auto DNS = 1')
981 if debug_mode_modem_mgr:
982 printDebugModemMgr(file('/etc/wvdial.conf').read())
984 def isConnected(self):
985 return len(os.popen('ifconfig -a | grep ppp').read().strip()) > 0
987 def updateUSBInfo(self):
990 apn,uid,pwd,pin,phone = self.apn,self.uid,self.pwd,self.pin,self.phone
991 if apn is None: apn = ""
992 if uid is None: uid = ""
993 if pwd is None: pwd = ""
994 if pin is None: pin = ""
995 if phone is None: phone = ""
996 x = self["menulist"].getCurrent()[1]
997 info = 'Vendor : %s/%s\nAPN : %s\nUser : %s\nPassword : %s\nPin : %s\nPhone : %s' % (
1007 self['usbinfo'].setText(info)
1009 def setListOnView(self):
1012 for x in self.getUSBList():
1013 lv_usb_items.append((x.get("Product"),x))
1015 printDebugModemMgr(str(lv_usb_items))
1018 def getUSBList(self):
1019 parsed_usb_list = []
1020 usb_devices = lsusb_devices()
1022 for x in usb_devices.splitlines():
1023 if x is None or len(x) == 0:
1024 printDebugModemMgr("TMP DEVICE : [%s]" % (tmp_device))
1026 parsed_usb_list.append(tmp_device)
1030 if x[0] in ('P', 'S', 'I', 'T'):
1032 printDebugModemMgr("TMP : [%s]" % (tmp))
1033 if tmp.startswith('Bus='):
1034 #printDebugModemMgr("TMP SPLIT for BUS : [%s]" % (str(tmp.split())))
1035 for xx in tmp.split():
1036 if xx.startswith('Bus='):
1037 tmp_device['Bus'] = xx[4:]
1039 if tmp.startswith('Manufacturer='):
1040 tmp_device['Manufacturer'] = tmp[13:]
1041 if tmp.startswith('Product='):
1042 tmp_device['Product'] = tmp[8:]
1043 elif tmp.startswith('SerialNumber='):
1044 tmp_device['SerialNumber'] = tmp[13:]
1045 elif tmp.startswith('Vendor='):
1046 #printDebugModemMgr("TMP SPLIT for BUS : [%s]" % (str(tmp.split())))
1047 for xx in tmp.split():
1048 if xx.startswith('Vendor='):
1049 tmp_device['Vendor'] = xx[7:]
1050 elif xx.startswith('ProdID='):
1051 tmp_device['ProdID'] = xx[7:]
1052 #tmp_device['Vendor'] = tmp
1053 elif tmp.find('Driver=') > 0:
1054 d = tmp[tmp.find('Driver=')+7:]
1056 tmp_device['Interface'] = d
1057 except Exception, errmsg:
1060 parsed_usb_list.append(tmp_device)
1061 printDebugModemMgr("PARSED DEVICE LIST : " + str(parsed_usb_list))
1063 for x in parsed_usb_list:
1064 printDebugModemMgr('Looking >> ' + str(x))
1066 xx = x.get("Interface")
1067 if xx.startswith('usb'):
1068 rt_usb_list.append(x)
1070 printInfoModemMgr("USB DEVICE LIST : " + str(rt_usb_list))
1073 def main(session, **kwargs):
1074 session.open(ModemManager)
1076 def Plugins(**kwargs):
1077 return PluginDescriptor(name=_("Modem Manager"), description="management 3g modem", where = PluginDescriptor.WHERE_PLUGINMENU, fnc=main)