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 class DeviceEventListener:
35 notifyCallbackFunctionList = []
37 self.sock = socket.socket(socket.AF_NETLINK, socket.SOCK_DGRAM, 15)
39 self.sock.bind((os.getpid(), 1))
40 self.notifier = eSocketNotifier(self.sock.fileno(), POLLIN|POLLPRI)
41 self.notifier.callback.append(self.cbEventHandler)
42 except Exception, msg:
43 print "[ModemManager Plugin] Error >>", msg
46 def cbEventHandler(self, sockfd):
47 recv = self.sock.recv(65536)
48 #printDebugModemMgr(str(recv.splitlines()))
49 if recv.startswith("add@/block") or recv.startswith("remove@/block"):
50 for x in self.notifyCallbackFunctionList:
52 except: self.notifyCallbackFunctionList.remove(x)
54 def addCallback(self, func):
56 self.notifyCallbackFunctionList.append(func)
58 def delCallback(self, func):
60 self.notifyCallbackFunctionList.remove(func)
64 self.notifier.callback.remove(self.cbEventHandler)
72 self.gTaskInstance = None
73 self.occurError = False
74 self.cbSetStatusCB = None
76 def append(self, command, cbDataFunc, cbCloseFunc):
77 self.taskList.append([command+'\n', cbDataFunc, cbCloseFunc])
80 print "############### TASK ###############"
81 print "Current Task Index :", self.taskIdx
82 print "Current Task Instance :", self.gTaskInstance
83 print "Occur Error :", self.occurError
84 print "Task List:\n", self.taskList
85 print "####################################"
88 printInfoModemMgr("set task error!!")
89 self.occurError = True
93 self.gTaskInstance = None
94 self.occurError = False
99 self.cbSetStatusCB = None
105 def setStatusCB(self, cbfunc):
106 self.cbSetStatusCB = cbfunc
109 if self.taskIdx >= len(self.taskList) or self.occurError:
110 printInfoModemMgr("can't run task!!")
112 command = self.taskList[self.taskIdx][0]
113 cbDataFunc = self.taskList[self.taskIdx][1]
114 cbCloseFunc = self.taskList[self.taskIdx][2]
116 self.gTaskInstance = eConsoleAppContainer()
117 if cbDataFunc is not None:
118 self.gTaskInstance.dataAvail.append(cbDataFunc)
119 if cbCloseFunc is not None:
120 self.gTaskInstance.appClosed.append(cbCloseFunc)
121 if self.cbSetStatusCB is not None:
122 self.cbSetStatusCB(self.taskIdx)
124 printInfoModemMgr("prepared command :%s"%(command))
125 self.gTaskInstance.execute(command)
129 class ParserHandler(handler.ContentHandler):
131 def startDocument(self):
133 def endDocument(self):
135 def startElement(self, name, attrs):
138 for attr in attrs.getNames():
139 node[attr] = attrs.getValue(attr)
140 self.nodeList.append(node)
141 def endElement(self, name):
143 def characters(self, content):
145 def setDocumentLocator(self, locator):
147 def getNodeList(self):
150 class EditModemManual(ConfigListScreen, Screen):
151 param = int(getDesktop(0).size().height()) >= 720 and (450,360) or (160,300)
153 <screen position="center,center" size="600,360" title="3G Modem Manager Config Edit">
154 <widget name="config" zPosition="2" position="0,0" size="600,300" scrollbarMode="showOnDemand" transparent="1" />
156 <ePixmap pixmap="skin_default/buttons/red.png" position="5,320" size="140,40" alphatest="on" />
157 <ePixmap pixmap="skin_default/buttons/green.png" position="155,320" size="140,40" alphatest="on" />
158 <ePixmap pixmap="skin_default/buttons/yellow.png" position="305,320" size="140,40" alphatest="on" />
159 <ePixmap pixmap="skin_default/buttons/blue.png" position="455,320" size="140,40" alphatest="on" />
161 <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" />
162 <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" />
164 <widget name="VKeyIcon" pixmap="skin_default/buttons/key_text.png" position="50,200" zPosition="10" size="35,25" transparent="1" alphatest="on" />
165 <widget name="HelpWindow" pixmap="skin_default/vkey_icon.png" position="%d,%d" zPosition="1" size="1,1" transparent="1" alphatest="on" />
169 def __init__(self, session, cbFuncClose, uid=None, pwd=None, pin=None, apn=None, phone='*99#'):
170 Screen.__init__(self, session)
171 self.cbFuncClose,self.uid,self.pwd,self.pin,self.apn,self.phone = cbFuncClose,uid,pwd,pin,apn,phone
173 self["actions"] = ActionMap(["OkCancelActions", "ShortcutActions", "WizardActions", "ColorActions", "SetupActions",],
176 "cancel": self.keyExit,
181 self["VirtualKB"] = ActionMap(["VirtualKeyboardActions" ],
183 "showVirtualKeyboard": self.KeyText,
187 ConfigListScreen.__init__(self, self.configList, session=session)
188 self.createConfigList()
190 self["key_red"] = StaticText(_("Cancel"))
191 self["key_green"] = StaticText(_("Save"))
192 self["VKeyIcon"] = Pixmap()
193 self["HelpWindow"] = Pixmap()
194 self["VirtualKB"].setEnabled(False)
196 def createConfigList(self):
197 self.configUserName = ConfigText(default=str(self.uid), visible_width=50, fixed_size=False)
198 self.configPassword = ConfigText(default=str(self.pwd), visible_width=50, fixed_size=False)
199 self.configAPN = ConfigText(default=str(self.apn), visible_width=50, fixed_size=False)
200 self.configPIN = ConfigText(default=str(self.pin), visible_width=50, fixed_size=False)
201 self.configPhone = ConfigText(default=str(self.phone), visible_width=50, fixed_size=False)
203 self.configEntryUserName = getConfigListEntry(_("User :"), self.configUserName)
204 self.configEntryPassword = getConfigListEntry(_("Password :"), self.configPassword)
205 self.configEntryAPN = getConfigListEntry(_("APN :"), self.configAPN)
206 self.configEntryPIN = getConfigListEntry(_("PIN :"), self.configPIN)
207 self.configEntryPhone = getConfigListEntry(_("Phone :"), self.configPhone)
209 self.configList.append(self.configEntryUserName)
210 self.configList.append(self.configEntryPassword)
211 self.configList.append(self.configEntryAPN)
212 self.configList.append(self.configEntryPIN)
213 self.configList.append(self.configEntryPhone)
215 self["config"].list = self.configList
216 self["config"].l.setList(self.configList)
218 def getCurrentItem(self):
219 currentPosition = self["config"].getCurrent()
220 if currentPosition == self.configEntryUserName:
221 return self.configUserName
222 elif currentPosition == self.configEntryPassword:
223 return self.configPassword
224 elif currentPosition == self.configEntryAPN:
225 return self.configAPN
226 elif currentPosition == self.configEntryPIN:
227 return self.configPIN
228 elif currentPosition == self.configEntryPhone:
229 return self.configPhone
233 currentItemValue = ""
234 currentItem = self.getCurrentItem()
235 if currentItem is None:
236 currentItemValue = currentItem.value
237 self.session.openWithCallback(self.cbKeyText, VirtualKeyBoard, title=("Please enter ap-info here"), text=currentItemValue)
239 def cbKeyText(self, data=None):
241 currentItem = self.getCurrentItem()
242 if currentItem is not None:
243 currentItem.setValue(data)
249 if self.cbFuncClose is not None:
250 self.uid = self.configUserName.value
251 self.pwd = self.configPassword.value
252 self.pin = self.configPIN.value
253 self.apn = self.configAPN.value
254 self.phone = self.configPhone.value
255 self.cbFuncClose(self.uid,self.pwd,self.pin,self.apn,self.phone)
259 class ModemManual(Screen):
261 <screen position="center,center" size="600,360" title="3G Modem Manager Config">
262 <widget name="menulist" position="0,0" size="300,300" backgroundColor="#000000" zPosition="10" scrollbarMode="showOnDemand" />
263 <widget name="apnInfo" position="310,0" size="290,300" font="Regular;20" halign="left" backgroundColor="#a08500" transparent="1" />
265 <ePixmap pixmap="skin_default/buttons/red.png" position="5,320" size="140,40" alphatest="on" />
266 <ePixmap pixmap="skin_default/buttons/green.png" position="155,320" size="140,40" alphatest="on" />
267 <ePixmap pixmap="skin_default/buttons/yellow.png" position="305,320" size="140,40" alphatest="on" />
268 <ePixmap pixmap="skin_default/buttons/blue.png" position="455,320" size="140,40" alphatest="on" />
270 <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" />
271 <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" />
272 <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" />
276 def __init__(self, session, cbFuncClose, uid=None, pwd=None, pin=None, apn=None, phone='*99#'):
277 Screen.__init__(self, session)
278 self.cbFuncClose,self.uid,self.pwd,self.pin,self.apn,self.phone = cbFuncClose,uid,pwd,pin,apn,phone
279 self["actions"] = ActionMap(["OkCancelActions", "ShortcutActions", "WizardActions", "ColorActions", "SetupActions"],
282 "cancel": self.keyExit,
285 "yellow": self.keyEdit,
286 "left": self.keyLeft,
287 "right": self.keyRight,
289 "down": self.keyDown,
292 self.apnItems = self.setListOnView()
293 self["menulist"] = MenuList(self.apnItems)
294 self["key_red"] = StaticText(_("Cancel"))
295 self["key_green"] = StaticText(_("OK"))
296 self["key_yellow"] = StaticText(_("Edit"))
297 self["apnInfo"] = Label(' ')
302 self.session.open(EditModemManual, self.cb3GManualSetting, self.uid,self.pwd,self.pin,self.apn,self.phone)
304 def cb3GManualSetting(self, uid=None, pwd=None, pin=None, apn=None, phone='*99#'):
305 self.uid,self.pwd,self.pin,self.apn,self.phone = uid, pwd, pin, apn, phone
309 self['menulist'].pageUp()
313 self['menulist'].pageDown()
317 self['menulist'].up()
321 self['menulist'].down()
325 if self.cbFuncClose is not None:
326 self.cbFuncClose(self.uid,self.pwd,self.pin,self.apn,self.phone)
332 def setAPNInfo(self):
334 x = self["menulist"].getCurrent()[1]
335 self.apn, self.uid, self.pwd = x.get("apn"), x.get("user"), x.get("password")
336 except Exception, err:
340 def updateAPNInfo(self):
341 info = 'APN : %s\nUSER : %s\nPASSWD : %s\nPIN : %s\nPHONE : %s\n' % (str(self.apn), str(self.uid), str(self.pwd), str(self.pin), str(self.phone))
342 self["apnInfo"].setText(info)
344 def setListOnView(self):
346 def uppercaseCompare(a,b):
347 aa = str(a.get("carrier"))
348 bb = str(b.get("carrier"))
349 return cmp(aa.upper(),bb.upper())
350 def isExistAPN(name):
356 handle = ParserHandler()
357 parser = make_parser()
358 parser.setContentHandler(handle)
359 parser.parse(resolveFilename(SCOPE_CURRENT_PLUGIN, "SystemPlugins/3GModemManager/apnlist.xml"))
361 apnList = handle.getNodeList()
362 apnList.sort(uppercaseCompare)
364 name = str(x.get('carrier'))
365 if name is None or name == 'None':
370 d['apn'] = str(x.get('apn'))
371 d['user'] = str(x.get('user'))
372 d['password'] = str(x.get('password'))
373 lvApnItems.append((name,d))
374 except Exception, err:
375 print "ERROR >>", err
379 class ModemManager(Screen):
381 <screen position="center,center" size="600,360" title="3G Modem Manager">
382 <widget name="menulist" position="0,0" size="300,150" backgroundColor="#000000" zPosition="10" scrollbarMode="showOnDemand" />
383 <widget name="usbinfo" position="310,0" size="290,150" font="Regular;18" halign="left" />
385 <widget name="statusTitle" position="0,160" size="600,120" font="Regular;20" halign="center" backgroundColor="#a08500" transparent="1" />
386 <widget name="statusInfo" position="0,185" size="600,120" font="Regular;20" halign="left" backgroundColor="#a08500" transparent="1" />
388 <ePixmap pixmap="skin_default/buttons/red.png" position="5,320" size="140,40" alphatest="on" />
389 <ePixmap pixmap="skin_default/buttons/green.png" position="155,320" size="140,40" alphatest="on" />
390 <ePixmap pixmap="skin_default/buttons/yellow.png" position="305,320" size="140,40" alphatest="on" />
391 <ePixmap pixmap="skin_default/buttons/blue.png" position="455,320" size="140,40" alphatest="on" />
393 <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" />
394 <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" />
395 <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" />
396 <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" />
399 uid,pwd,pin,apn,phone = None,None,None,None,'*99#'
401 def __init__(self, session):
402 Screen.__init__(self, session)
403 self.usb_lv_items = self.setListOnView()
405 self["actions"] = ActionMap(["OkCancelActions", "ShortcutActions", "WizardActions", "ColorActions", "SetupActions", "NumberActions"],
408 "cancel": self.keyExit,
411 "yellow": self.keyManual,
412 "blue": self.keyReset,
414 "down": self.keyDown,
415 "left": self.keyLeft,
416 "right": self.keyRight,
419 self["menulist"] = MenuList(self.usb_lv_items)
420 self['usbinfo'] = Label(' ')
421 self['statusTitle'] = Label('[ Status ]')
422 self['statusInfo'] = Label(' ')
423 self["key_red"] = StaticText(_("Exit"))
424 if self.isConnected():
425 self["key_green"] = StaticText("Disconnect")
426 self.setDisconnectStatus(0)
428 self["key_green"] = StaticText("Connect")
429 self.setConnectStatus(0)
430 self["key_yellow"] = StaticText(_("Manual"))
431 self["key_blue"] = StaticText(_("Reset"))
435 self.udevListener = DeviceEventListener()
436 self.udevListener.addCallback(self.cbUdevListener)
438 self.taskManager = TaskManager()
440 self.refreshStatusTimer = eTimer()
441 self.refreshStatusTimer.callback.append(self.cbRefreshStatus)
443 #self.restartAppTimer = eTimer()
444 #self.restartAppTimer.callback.append(self.cbRestartAppTimer)
446 self.forceStop = False
448 def cbRestartAppTimer(self):
449 self.restartAppTimer.stop()
450 model = file('/proc/stb/info/vumodel').read().strip()
451 if model is not None:
452 if model == 'solo' or model == 'bm750':
453 self.session.open(TryQuitMainloop, 3)
455 def cbRefreshStatus(self):
456 self.refreshStatusTimer.stop()
457 if self["key_green"].getText() == 'Connect':
458 self.setConnectStatus(0)
459 elif self["key_green"].getText() == 'Disconnect':
460 self.setDisconnectStatus(0)
462 def cbUdevListener(self, data):
463 printDebugModemMgr('Udev Listener Refresh!!')
465 self["menulist"].setList(self.setListOnView())
468 def isAttemptConnect(self):
469 if self.connectionStatus == 0 or self.forceStop:
472 if self["key_green"].getText() == 'Disconnect':
474 if self.connectionStatus < maxIdx:
475 printInfoModemMgr("can't excute a command during connecting...")
480 if self.isAttemptConnect():
482 self.session.open(ModemManual, self.cb3GManualSetting, self.uid,self.pwd,self.pin,self.apn,self.phone)
485 if self.isAttemptConnect():
487 self.cb3GManualSetting()
489 def cb3GManualSetting(self, uid=None, pwd=None, pin=None, apn=None, phone='*99#'):
490 self.uid,self.pwd,self.pin,self.apn,self.phone = uid,pwd,pin,apn,phone
493 def keyNumber(self, num=None):
494 global debug_mode_modem_mgr
495 debug_mode_modem_mgr = not debug_mode_modem_mgr
496 printInfoModemMgr('changed log mode, debug %s'%(debug_mode_modem_mgr and 'on' or 'off'))
499 if self.isAttemptConnect():
500 message = "Can't disconnect doring connecting.."
501 self.session.open(MessageBox, _(message), MessageBox.TYPE_INFO)
503 self.udevListener.close()
507 self["menulist"].pageUp()
511 self["menulist"].pageDown()
515 self["menulist"].up()
519 self["menulist"].down()
523 self.forceStop = False
524 if self.isAttemptConnect():
527 def areadyExistAnotherAdapter():
528 networkAdapters = iNetwork.getConfiguredAdapters()
529 for x in networkAdapters:
534 if self["key_green"].getText() == 'Disconnect':
535 message = "Do you want to disconnect?"
536 self.session.openWithCallback(self.cbConfirmDone, MessageBox, _(message), default = False)
539 if areadyExistAnotherAdapter():
540 message = "Another adapter connected has been found.\n\nA connection is attempted after disconnect all of other device. Do you want to?"
541 self.session.openWithCallback(self.cbConfirmDone, MessageBox, _(message), default = True)
542 else: self.cbConfirmDone(True)
544 def cbConfirmDone(self, ret):
546 if self["key_green"].getText() == 'Connect':
547 networkAdapters = iNetwork.getConfiguredAdapters()
548 for x in networkAdapters:
549 if x[:3] == 'ppp': continue
550 iNetwork.setAdapterAttribute(x, "up", False)
551 iNetwork.deactivateInterface(x)
554 try: x = self["menulist"].getCurrent()[1]
556 printInfoModemMgr('no selected device..')
559 devFile = '/usr/share/usb_modeswitch/%s:%s' % (x.get("Vendor"), x.get("ProdID"))
560 if not os.path.exists(devFile) :
561 message = "Can't found device file!! [%s]" % (devFile)
562 printInfoModemMgr(message)
563 self.session.open(MessageBox, _(message), MessageBox.TYPE_INFO)
566 commandBin = resolveFilename(SCOPE_CURRENT_PLUGIN, "SystemPlugins/3GModemManager/3gcommand")
567 if self["key_green"].getText() == 'Disconnect':
568 cmd = "%s -s 0" % (commandBin)
569 self.taskManager.append(cmd, self.cbPrintAvail, self.cbPrintClose)
571 cmd = "%s -s 1" % (commandBin)
572 self.taskManager.append(cmd, self.cbPrintAvail, self.cbUnloadClose)
573 self.taskManager.setStatusCB(self.setDisconnectStatus)
575 cmd = "%s -s 2 -e vendor=0x%s -e product=0x%s" % (commandBin, x.get("Vendor"), x.get("ProdID"))
576 self.taskManager.append(cmd, self.cbStep1PrintAvail, self.cbPrintClose)
578 cmd = "%s -s 3 -e %s:%s" % (commandBin, x.get("Vendor"), x.get("ProdID"))
579 self.taskManager.append(cmd, self.cbPrintAvail, self.cbPrintClose)
581 cmd = "%s -s 4" % (commandBin)
582 self.taskManager.append(cmd, self.cbStep3PrintAvail, self.cbMakeWvDialClose)
584 cmd = "%s -s 5" % (commandBin)
585 self.taskManager.append(cmd, self.cbRunWvDialAvail, self.cbPrintClose)
586 self.taskManager.setStatusCB(self.setConnectStatus)
588 self.taskManager.next()
590 def printStatus(self, idx, STATUS):
592 self.connectionStatus = idx
593 for x in range(0,len(STATUS)):
599 self['statusInfo'].setText(message)
601 def setConnectStatus(self, idx):
603 0:'1. Load a Mobile Broadband Device'
604 ,1:'2. Set up a Mobile Broadband Device'
605 ,2:'3. Generate a WvDial profile'
606 ,3:'4. Attempt to connect'
609 self.printStatus(idx, STATUS)
611 def setDisconnectStatus(self, idx):
614 ,1:'2. Unload a Mobile Broadband Device'
617 self.printStatus(idx, STATUS)
619 def cbStep1PrintAvail(self, data):
621 if data.find('modules.dep') > -1:
622 self.forceStop = True
624 def cbStep3PrintAvail(self, data):
626 if data.find('Sorry, no modem was detected') > -1:
627 self.forceStop = True
629 def cbPrintAvail(self, data):
632 def cbPrintClose(self, ret):
634 self.taskManager.clean()
636 message = "Occur error during connection...\nPlease, check log!!"
637 self.session.open(MessageBox, _(message), MessageBox.TYPE_INFO)
639 self.taskManager.next()
641 def cbUnloadClose(self, ret):
642 self.taskManager.clean()
644 self["key_green"].setText('Connect')
645 self.setDisconnectStatus(2)
646 self.refreshStatusTimer.start(1000)
648 def cbRunWvDialAvail(self, data):
650 if data.find('Pid of pppd:') > -1:
651 self.taskManager.clean()
653 self["key_green"].setText('Disconnect')
654 self.setConnectStatus(4)
655 self.refreshStatusTimer.start(1000)
656 #self.restartAppTimer.start(3000)
658 def cbMakeWvDialClose(self, ret):
662 datalist = file('/etc/wvdial.conf').read().splitlines()
664 if x.startswith('Modem ='):
666 info['Modem'] = x[7:].strip()
667 elif x.startswith('Init2 ='):
669 info['Init'] = x[7:].strip()
670 elif x.startswith('Baud ='):
672 info['Baud'] = x[6:].strip()
673 except Exception, err:
674 printDebugModemMgr("getModemInfo Error : [%s]" % (str(err)))
675 # TODO : occur error!!
678 if self.apn is not None:
679 info['apn'] = self.apn
680 if self.uid is not None:
681 info['uid'] = self.uid
682 if self.pwd is not None:
683 info['pwd'] = self.pwd
684 if self.pin is not None:
685 info['pin'] = self.pin
686 if self.phone is not None:
687 info['phone'] = self.phone
688 #info['phone'] = '*99#'
689 self.makeWvDialConf(info)
690 self.taskManager.next()
692 def writeConf(self, data, oper='>>'):
693 confFile = '/etc/wvdial.conf'
695 os.system('mv %s %s.bak' % (confFile, confFile))
696 cmd = "echo '%s' %s %s" % (data, oper, confFile)
699 def makeWvDialConf(self, params):
700 baud = params.get('Baud')
701 init = params.get('Init')
702 modem = params.get('Modem')
703 phone = params.get('phone')
704 apn = params.get('apn')
705 uid = params.get('uid')
706 pwd = params.get('pwd')
707 pin = params.get('pin')
710 self.writeConf('','>')
712 self.writeConf('[Dialer Defaults]')
713 if modem is None or init is None or baud is None:
715 self.writeConf('Modem = %s' % (modem))
716 self.writeConf('Baud = %s' % (baud))
717 self.writeConf('Dial Command = ATDT')
718 self.writeConf('Init%d = ATZ' % (idxInit))
719 idxInit = idxInit + 1
721 writeConf('Init%d = AT+CPIN=%s' % (init_idx, pin))
722 idxInit = idxInit + 1
723 self.writeConf('Init%d = %s' % (idxInit, init))
724 idxInit = idxInit + 1
725 if apn is None and uid is None and pwd is None and pin is None:
726 self.writeConf('Init%d = AT&F' % (idxInit))
727 idxInit = idxInit + 1
729 self.writeConf('Init%d = AT+CGDCONT=1,"IP","%s"' % (idxInit, apn))
730 idxInit = idxInit + 1
731 self.writeConf('Init%d = AT+CFUN = 1' % (idxInit))
732 self.writeConf('Username = %s' % (uid))
733 self.writeConf('Password = %s' % (pwd))
734 self.writeConf('Phone = %s' % (phone)) #*99#
735 self.writeConf('Modem Type = Analog Modem')
736 self.writeConf('ISDN = 0')
737 self.writeConf('Carrier Check = 0')
738 self.writeConf('Abort on No Dialtone = 0')
739 self.writeConf('Stupid Mode = 1')
740 self.writeConf('Check DNS = 1')
741 self.writeConf('Check Def Route = 1')
742 self.writeConf('Auto DNS = 1')
744 def isConnected(self):
745 return len(os.popen('ifconfig -a | grep ppp').read().strip()) > 0
747 def updateUSBInfo(self):
750 x = self["menulist"].getCurrent()[1]
751 info = 'Vendor : %s/%s\nAPN : %s\nUser : %s\nPassword : %s\nPin : %s\nPhone : %s' % (
761 self['usbinfo'].setText(info)
763 def setListOnView(self):
766 for x in self.getUSBList():
767 lv_usb_items.append((x.get("Product"),x))
771 def getUSBList(self):
773 usb_devices = os.popen('cat /proc/bus/usb/devices').read()
775 for x in usb_devices.splitlines():
776 if x is None or len(x) == 0:
777 printDebugModemMgr("TMP DEVICE : [%s]" % (tmp_device))
779 parsed_usb_list.append(tmp_device)
783 if x[0] in ('P', 'S', 'I', 'T'):
785 printDebugModemMgr("TMP : [%s]" % (tmp))
786 if tmp.startswith('Bus='):
787 #printDebugModemMgr("TMP SPLIT for BUS : [%s]" % (str(tmp.split())))
788 for xx in tmp.split():
789 if xx.startswith('Bus='):
790 tmp_device['Bus'] = xx[4:]
792 if tmp.startswith('Manufacturer='):
793 tmp_device['Manufacturer'] = tmp[13:]
794 if tmp.startswith('Product='):
795 tmp_device['Product'] = tmp[8:]
796 elif tmp.startswith('SerialNumber='):
797 tmp_device['SerialNumber'] = tmp[13:]
798 elif tmp.startswith('Vendor='):
799 #printDebugModemMgr("TMP SPLIT for BUS : [%s]" % (str(tmp.split())))
800 for xx in tmp.split():
801 if xx.startswith('Vendor='):
802 tmp_device['Vendor'] = xx[7:]
803 elif xx.startswith('ProdID='):
804 tmp_device['ProdID'] = xx[7:]
805 #tmp_device['Vendor'] = tmp
806 elif tmp.find('Driver=') > 0:
807 d = tmp[tmp.find('Driver=')+7:]
809 tmp_device['Interface'] = d
810 except Exception, errmsg:
813 parsed_usb_list.append(tmp_device)
814 printDebugModemMgr("PARSED DEVICE LIST : " + str(parsed_usb_list))
816 for x in parsed_usb_list:
817 printDebugModemMgr('Looking >> ' + str(x))
819 xx = x.get("Interface")
820 if xx.startswith('usb'):
821 rt_usb_list.append(x)
823 printInfoModemMgr("USB DEVICE LIST : " + str(rt_usb_list))
826 def main(session, **kwargs):
827 session.open(ModemManager)
829 def Plugins(**kwargs):
830 return PluginDescriptor(name=_("Modem Manager"), description="management 3g modem", where = PluginDescriptor.WHERE_PLUGINMENU, fnc=main)