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)
Exemple #2
0
    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)
Exemple #3
0
def v_ucs2_name(value):
    if value == '':
        return PARTIAL
    from vmc.common.encoding import pack_ucs2_bytes
    try:
        pack_ucs2_bytes(value)
    except:
        return PARTIAL
    else:
        return VALID
def v_ucs2_name(value):
    if value == '':
        return PARTIAL
    from vmc.common.encoding import pack_ucs2_bytes
    try:
        pack_ucs2_bytes(value)
    except:
        return PARTIAL
    else:
        return VALID
Exemple #5
0
    def add_contact(self, contact):
        """
        Adds C{contact} to the SIM and returns the index where was stored
        
        @rtype: C{defer.Deferred}
        """
        name = from_u(contact.get_name())

        if 'UCS2' in self.device.sim.charset:
            name = pack_ucs2_bytes(name)

        # common arguments for both operations (name and number)
        args = [name, from_u(contact.get_number())]

        if contact.index:
            # contact.index is set, user probably wants to overwrite an
            # existing contact
            args.append(contact.index)
            d = super(SIMCardConnAdapter, self).add_contact(*args)
            d.addCallback(lambda _: contact.index)
            return d

        # contact.index is not set, this means that we need to obtain the
        # first slot free on the phonebook and then add the contact
        def get_next_id_cb(index):
            args.append(index)
            d2 = super(SIMCardConnAdapter, self).add_contact(*args)
            # now we just fake add_contact's response and we return the index
            d2.addCallback(lambda _: index)
            return d2

        d = super(SIMCardConnAdapter, self).get_next_contact_id()
        d.addCallback(get_next_id_cb)
        return d
Exemple #6
0
    def get_pin_status(self):
        """
        Returns 1 if PIN auth is active and 0 if its not

        @rtype: C{Deferred}
        """
        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 pinreq_errback(failure):
            failure.trap(ex.CMEErrorSIMPINRequired)
            return 1

        def aterror_eb(failure):
            failure.trap(ex.ATError)
            # return the failure or wont work
            return failure

        facility = (self.device.sim.charset
                    == 'UCS2') and pack_ucs2_bytes('SC') or 'SC'

        d = ericsson_get_pin_status(facility)  # call the local one
        d.addCallback(lambda response: int(response[0].group('status')))
        d.addErrback(pinreq_errback)
        d.addErrback(aterror_eb)
        return d
    def get_pin_status(self):
        """
        Returns 1 if PIN auth is active and 0 if its not

        @rtype: C{Deferred}
        """

        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 pinreq_errback(failure):
            failure.trap(ex.CMEErrorSIMPINRequired)
            return 1

        def aterror_eb(failure):
            failure.trap(ex.ATError)
            # return the failure or wont work
            return failure

        facility = (self.device.sim.charset == 'UCS2') and pack_ucs2_bytes('SC') or 'SC'

        d = ericsson_get_pin_status(facility)                    # call the local one
        d.addCallback(lambda response: int(response[0].group('status')))
        d.addErrback(pinreq_errback)
        d.addErrback(aterror_eb)
        return d
 def add_contact(self, contact):
     """
     Adds C{contact} to the SIM and returns the index where was stored
     
     @rtype: C{defer.Deferred}
     """ 
     name = from_u(contact.get_name())
     
     if 'UCS2' in self.device.sim.charset:
         name = pack_ucs2_bytes(name)
     
     # common arguments for both operations (name and number)
     args = [name, from_u(contact.get_number())]
     
     if contact.index:
         # contact.index is set, user probably wants to overwrite an
         # existing contact
         args.append(contact.index)
         d = super(SIMCardConnAdapter, self).add_contact(*args)
         d.addCallback(lambda _: contact.index)
         return d
     
     # contact.index is not set, this means that we need to obtain the
     # first slot free on the phonebook and then add the contact
     def get_next_id_cb(index):
         args.append(index)
         d2 = super(SIMCardConnAdapter, self).add_contact(*args)
         # now we just fake add_contact's response and we return the index
         d2.addCallback(lambda _: index)
         return d2
     
     d = super(SIMCardConnAdapter, self).get_next_contact_id()
     d.addCallback(get_next_id_cb)
     return d
Exemple #9
0
 def find_contacts(self, pattern):
     """Returns a list of C{Contact} whose name matches pattern"""
     if 'UCS2' in self.device.sim.charset:
         pattern = pack_ucs2_bytes(pattern)
     d = super(SIMCardConnAdapter, self).find_contacts(pattern)
     d.addCallback(
         lambda matches: [process_contact_match(m) for m in matches])
     return d
 def find_contacts(self, pattern):
     """Returns a list of C{Contact} whose name matches pattern"""
     if 'UCS2' in self.device.sim.charset:
         pattern = pack_ucs2_bytes(pattern)
     d = super(SIMCardConnAdapter, self).find_contacts(pattern)
     d.addCallback(lambda matches: [process_contact_match(m)
                                     for m in matches])
     return d
Exemple #11
0
 def __set_text(self, text):
     try:
         sms_text = text.encode('sms-default')
         self.user_data_length = len(sms_text)
         self.user_data = pack_7bit_bytes(sms_text)
         self.encoding = DEFAULT_ALPHABET
     except UnicodeError, e:
         self.user_data = pack_ucs2_bytes(text)
         self.user_data_length = len(self.user_data) / 2
         self.encoding = UCS2
 def __set_text(self, text):
     try:
         sms_text = text.encode('sms-default')
         self.user_data_length = len(sms_text)
         self.user_data = pack_7bit_bytes(sms_text)
         self.encoding = DEFAULT_ALPHABET
     except UnicodeError, e:
         self.user_data = pack_ucs2_bytes(text)
         self.user_data_length = len(self.user_data) / 2
         self.encoding = UCS2
Exemple #13
0
        def get_net_info_cb(netinfo):
            """
            Returns a (Networname, ConnType) tuple
            
            It returns None if there's no info
            """
            if not netinfo:
                return None
            
            netinfo = netinfo[0]
            
            if netinfo.group('error'):
                # this means that we've received a response like
                # +COPS: 0 which means that we don't have network temporaly
                # we should raise an exception here
                raise ex.NetworkTemporalyUnavailableError

            try:
                status = int(netinfo.group('status'))
                conn_type = (status == 0) and 'GPRS' or '3G'
            except IndexError:
                conn_type = 'GPRS'
                
            netname = netinfo.group('netname')
            
            if netname in ['Limited Service',
                           pack_ucs2_bytes('Limited Service')]:
                return netname, conn_type
            
            # netname can be in UCS2, as a string, or as a network id (int)
            if check_if_ucs2(netname):
                return unpack_ucs2_bytes(netname), conn_type
            else:
                # now can be either a string or a network id (int)
                try:
                    netname = int(netname)
                except ValueError:
                    # we got a string ID
                    return netname, conn_type
                
                # if we have arrived here, that means that the network id
                # is a five digit integer
                if not process:
                    return netname, conn_type
                
                # we got a numeric id, lets convert it
                from vmc.common.persistent import net_manager
                network = net_manager.get_network_by_id(netname)
                if network:
                    return network.get_name(), conn_type
# ajb: make consistent display between network returned via id or name
                #    return network.get_full_name(), conn_type
                
                return _('Unknown Network'), conn_type
    def set_charset(self, charset):
        """
        Sets the character set used on the SIM

        The oddity here is that the set command needs to have its charset value
        encoded in the current character set
        """
        if (self.device.sim.charset == 'UCS2'):
            charset = pack_ucs2_bytes(charset)

        d = super(EricssonAdapter, self).set_charset(charset)
        return d
Exemple #15
0
    def set_charset(self, charset):
        """
        Sets the character set used on the SIM

        The oddity here is that the set command needs to have its charset value
        encoded in the current character set
        """
        if (self.device.sim.charset == 'UCS2'):
            charset = pack_ucs2_bytes(charset)

        d = super(EricssonAdapter, self).set_charset(charset)
        return d
Exemple #16
0
    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 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 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 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)
Exemple #20
0
 def set_smsc(self, smsc):
     """Sets the SIMS's SMSC number to C{smsc}"""
     if 'UCS2' in self.device.sim.charset:
         smsc = pack_ucs2_bytes(smsc)
     return super(SIMCardConnAdapter, self).set_smsc(smsc)
 def test_pack_ucs2_bytes(self):
     # 07911356131313F311000A9260214365870008AA080068006F006C0061
     self.assertEqual(pack_ucs2_bytes('hola'), '0068006F006C0061')
     # 07911356131313F311000A9260214365870008AA0A0068006F006C00610073
     self.assertEqual(pack_ucs2_bytes('holas'), '0068006F006C00610073')
 def set_smsc(self, smsc):
     """Sets the SIMS's SMSC number to C{smsc}"""
     if 'UCS2' in self.device.sim.charset:
         smsc = pack_ucs2_bytes(smsc)
     return super(SIMCardConnAdapter, self).set_smsc(smsc)