def get_phonebook_size(self): """ Returns the phonebook size of the SIM card @return: A C{re.MatchObject} with the size of the phonebook @raise common.exceptions.CMEErrorSIMBusy: When the SIM is not ready. @raise common.exceptions.CMSError500: When the SIM is not ready. @raise common.exceptions.ATError: When the SIM is not ready. """ cmd = ATCmd('AT+CPBR=?', name='get_phonebook_size') cmd.timeout = 30 return self.queue_at_cmd(cmd)
def change_pin(self, oldpin, newpin): """ Changes C{oldpin} to C{newpin} in the SIM card @type oldpin: C{str} @type newpin: C{str} @return: If everything goes well, it will return an 'OK' through the callback, otherwise it will raise an exception. @raise common.exceptions.ATError: When the password is incorrect. @raise common.exceptions.CMEErrorIncorrectPassword: When the password is incorrect. @raise common.exceptions.InputValueError: When the PIN != \d{4} """ if (self.device.sim.charset == 'UCS2'): facility = pack_ucs2_bytes('SC') oldpin = pack_ucs2_bytes(oldpin) newpin = pack_ucs2_bytes(newpin) else: facility = 'SC' cmd = ATCmd('AT+CPWD="%s","%s","%s"' % (facility, oldpin, newpin), name='change_pin') return self.queue_at_cmd(cmd)
def add_contact(self, name, number, index): """ Adds a contact to the SIM card """ category = number.startswith('+') and 145 or 129 args = (index, number, category, name) cmd = ATCmd('AT+CPBW=%d,"%s",%d,"%s"' % args, name='add_contact') return self.queue_at_cmd(cmd)
def reset_settings(self): """ Resets the settings to factory settings @rtype: C{Deferred} """ cmd = ATCmd('AT&F', name='reset_settings') return self.queue_at_cmd(cmd)
def error_reporting(self, type=1): """ Error reporting method 0 disable +CME ERROR: <err> result code and use ERROR instead 1 enable +CME ERROR: <err> result code and use numeric <err> values 2 enable +CME ERROR: <err> result code and use verbose <err> values """ cmd = ATCmd('AT+CMEE=%d' % type, name='error_reporting') return self.queue_at_cmd(cmd)
def check_pin(self): """ Checks what's necessary to authenticate against the SIM card @return: If everything goes well, it will return one of the following 1. +CPIN: READY 2. +CPIN: SIM PIN 3. +CPIN: SIM PUK 4. +CPIN: SIM PUK2 @raise common.exceptions.CMEErrorSIMBusy: When the SIM is not ready @raise common.exceptions.CMEErrorSIMNotStarted: When the SIM is not ready @raise common.exceptions.CMEErrorSIMFailure: This exception is raised by GlobeTrotter's 3G cards (without HSDPA) when PIN authentication is disabled """ cmd = ATCmd('AT+CPIN?', name='check_pin') cmd.timeout=5 return self.queue_at_cmd(cmd)
def check_pin(self): """ Checks what's necessary to authenticate against the SIM card @return: If everything goes well, it will return one of the following 1. +CPIN: READY 2. +CPIN: SIM PIN 3. +CPIN: SIM PUK 4. +CPIN: SIM PUK2 @raise common.exceptions.CMEErrorSIMBusy: When the SIM is not ready @raise common.exceptions.CMEErrorSIMNotStarted: When the SIM is not ready @raise common.exceptions.CMEErrorSIMFailure: This exception is raised by GlobeTrotter's 3G cards (without HSDPA) when PIN authentication is disabled """ cmd = ATCmd('AT+CPIN?', name='check_pin') cmd.timeout = 5 return self.queue_at_cmd(cmd)
def get_signal_level(self): """ Returns the signal level @rtype: C{Deferred} Overloaded to poll the RFSWITCH status """ cmd = ATCmd('AT^RFSWITCH?', name='get_radio') d = self.queue_at_cmd(cmd) d.addCallback( lambda _: super(HuaweiEMXXAdapter, self).get_signal_level()) return d
def send_puk(self, puk, pin): """ Sends PUK and PIN to the SIM card @return: C{True} if everything went ok @raise common.exceptions.ATError: Exception raised by Nozomi when the PUK is incorrect. @raise common.exceptions.CMEErrorIncorrectPassword: Exception raised when the PUK is incorrect. """ atstr = 'AT+CPIN="%s","%s"' % (str(puk), str(pin)) cmd = ATCmd(atstr, name='send_puk') return self.queue_at_cmd(cmd)
def enable_pin(self, pin): """ Enables pin authentication at startup @type pin: C{int} @return: If everything goes well, it will return an 'OK' through the callback, otherwise it will raise an exception. @raise common.exceptions.ATError: When the PIN is incorrect. @raise common.exceptions.CMEErrorIncorrectPassword: When the PIN is incorrect. @raise common.exceptions.InputValueError: When the PIN != \d{4} """ cmd = ATCmd('AT+CLCK="SC",1,"%s"' % str(pin), name='enable_pin') return self.queue_at_cmd(cmd)
def get_signal_level(self): """ On Ericsson, AT+CSQ only returns valid data in GPRS mode So we need to override and provide an alternative. +CIND returns an indication between 0-5 so let's just multiply that by 5 to get a very rough rssi @rtype: C{Deferred} """ cmd = ATCmd('AT+CIND?', name='get_signal_indication') d = self.queue_at_cmd(cmd) d.addCallback(lambda response: int(response[0].group('sig')) * 5) return d
def get_contacts(self): """ Returns a list with all the contacts stored in the SIM card @return: Returns a list of C{re.MatchObject} with the contacts. @raise common.exceptions.ATError: When no contacts are found. @raise common.exceptions.CMEErrorNotFound: When no contacts are found. @raise common.exceptions.CMEErrorSIMBusy: When the SIM is not ready. @raise common.exceptions.CMEErrorSIMNotStarted: When the SIM is not ready. """ cmd = ATCmd('AT+CPBR=1,%d' % self.device.sim.size, name='get_contacts') return self.queue_at_cmd(cmd)
def hw_add_contact(name, number, index): """ Adds a contact to the SIM card """ try: # are all ascii chars name.encode('ascii') raw = 0 except: # write in TS31.101 type 80 raw format name = '80' + pack_ucs2_bytes(name) + 'FF' raw = 1 category = number.startswith('+') and 145 or 129 args = (index, number, category, name, raw) cmd = ATCmd('AT^CPBW=%d,"%s",%d,"%s",%d' % args, name='add_contact') return self.queue_at_cmd(cmd)
def get_sms(self): """ Returns a list with all the messages stored in the SIM card @return: Returns a list of C{re.MatchObject} with the messages. @raise common.exceptions.ATError: When no messages are found. @raise common.exceptions.CMEErrorNotFound: When no messages are found. @raise common.exceptions.CMEErrorSIMBusy: When the SIM is not ready. @raise common.exceptions.CMEErrorSIMNotStarted: When the SIM is not ready. @raise common.exceptions.CMSError500: When the SIM is not ready. """ cmd = ATCmd('AT+CMGL=4', name='get_sms') return self.queue_at_cmd(cmd)
def change_pin(self, oldpin, newpin): """ Changes C{oldpin} to C{newpin} in the SIM card @type oldpin: C{str} @type newpin: C{str} @return: If everything goes well, it will return an 'OK' through the callback, otherwise it will raise an exception. @raise common.exceptions.ATError: When the password is incorrect. @raise common.exceptions.CMEErrorIncorrectPassword: When the password is incorrect. @raise common.exceptions.InputValueError: When the PIN != \d{4} """ atstr = 'AT+CPWD="SC","%s","%s"' % (str(oldpin), str(newpin)) cmd = ATCmd(atstr, name='change_pin') return self.queue_at_cmd(cmd)
def enable_pin(self, pin): """ Enables pin authentication at startup @type pin: C{int} @return: If everything goes well, it will return an 'OK' through the callback, otherwise it will raise an exception. @raise common.exceptions.ATError: When the PIN is incorrect. @raise common.exceptions.CMEErrorIncorrectPassword: When the PIN is incorrect. @raise common.exceptions.InputValueError: When the PIN != \d{4} """ if (self.device.sim.charset == 'UCS2'): facility = pack_ucs2_bytes('SC') pin = pack_ucs2_bytes(pin) else: facility = 'SC' cmd = ATCmd('AT+CLCK="%s",1,"%s"' % (facility, pin), name='enable_pin') return self.queue_at_cmd(cmd)
def send_sms(self, pdu, pdu_len): """Sends the given pdu and returns the index""" cmd = ATCmd('AT+CMGS=%d' % pdu_len, name='send_sms', eol='\r') cmd.splitcmd = '%s\x1a' % pdu return self.queue_at_cmd(cmd)
def set_smsc(self, number): """Sets the SMSC""" cmd = ATCmd('AT+CSCA="%s"' % number, name='set_smsc') return self.queue_at_cmd(cmd)
def set_sms_indication(self, mode=2, mt=1, bm=0, ds=0, bfr=0): """Sets the SMS indication mode""" args = 'AT+CNMI=' + ','.join(map(str, [mode, mt, bm, ds, bfr])) cmd = ATCmd(args, name='set_sms_indication') return self.queue_at_cmd(cmd)
def get_smsc(self): cmd = ATCmd('AT+CSCA?', name='get_smsc') return self.queue_at_cmd(cmd)
def get_pin_status(self): """Checks wether the pin is enabled or disabled""" cmd = ATCmd('AT+CLCK="SC",2', name='get_pin_status') return self.queue_at_cmd(cmd)
def ericsson_get_pin_status(facility): """ Checks whether the pin is enabled or disabled """ cmd = ATCmd('AT+CLCK="%s",2' % facility, name='get_pin_status') return self.queue_at_cmd(cmd)
def send_pin(self, pin): """Sends the PIN to the SIM card""" cmd = ATCmd('AT+CPIN=%s' % str(pin), name='send_pin') return self.queue_at_cmd(cmd)
def send_at(self, at_str): """Send an arbitrary AT string to the SIM card""" cmd = ATCmd(at_str, name='send_at') return self.queue_at_cmd(cmd)
def reset_settings(self): """Resets the settings to factory settings""" cmd = ATCmd('ATZ', name='reset_settings') return self.queue_at_cmd(cmd)
def register_with_network(self, netid, mode=1, format=2): """Registers with the given netid""" atstr = 'AT+COPS=%d,%d,"%d"' % (mode, format, netid) cmd = ATCmd(atstr, name='register_with_network') return self.queue_at_cmd(cmd)
def set_charset(self, charset): """Sets the character set used on the SIM""" cmd = ATCmd('AT+CSCS="%s"' % charset, name='set_charset') return self.queue_at_cmd(cmd)
def set_netreg_notification(self, val=1): """Sets CREG unsolicited notification""" cmd = ATCmd('AT+CREG=%d' % val, name='set_netreg_notification') return self.queue_at_cmd(cmd)
def add_sms(self, pdu_len, pdu): """Adds C{sms} to the SIM and returns the index""" atstr = 'AT+CMGW=%d' % pdu_len cmd = ATCmd(atstr, name='add_sms', eol='\r') cmd.splitcmd = '%s\x1a' % pdu return self.queue_at_cmd(cmd)
def set_network_info_format(self, mode=0, format=2): cmd = ATCmd('AT+COPS=%d,%d' % (mode, format), name='set_network_info_format') return self.queue_at_cmd(cmd)
def get_network_names(self): """Returns a tuple with the network info""" cmd = ATCmd('AT+COPS=?', name='get_network_names') cmd.timeout = 40 return self.queue_at_cmd(cmd)
def set_sms_format(self, format=1): """Sets the format of the SMS""" cmd = ATCmd('AT+CMGF=%d' % format, name='set_sms_format') return self.queue_at_cmd(cmd)
def get_sms_by_index(self, index): """Returns the message stored at index""" cmd = ATCmd('AT+CMGR=%d' % index, name='get_sms_by_index') return self.queue_at_cmd(cmd)