Ticket #1654: 0001-Pin-Puk-Configuration-3G-Support.patch

File 0001-Pin-Puk-Configuration-3G-Support.patch, 10.0 KB (added by tomeu, 14 years ago)

rebased, applies on top of #1652

  • extensions/cpsection/modemconfiguration/model.py

    From ef0deba6941f167673d9a2aac5c9bcdf186d727d Mon Sep 17 00:00:00 2001
    From: root <root@localhost.localdomain>
    Date: Thu, 14 Jan 2010 16:04:10 -0200
    Subject: [PATCH] Pin-Puk Configuration 3G Support
    
    ---
     extensions/cpsection/modemconfiguration/model.py |   25 ++++++++++-
     extensions/cpsection/modemconfiguration/view.py  |   51 +++++++++++++++++++---
     extensions/deviceicon/network.py                 |   14 ++++++-
     src/jarabe/model/network.py                      |   22 ++++++---
     4 files changed, 97 insertions(+), 15 deletions(-)
    
    diff --git a/extensions/cpsection/modemconfiguration/model.py b/extensions/cpsection/modemconfiguration/model.py
    index f96e88f..d69925d 100644
    a b  
    1717import gconf
    1818
    1919from jarabe.model.network import GSM_USERNAME_PATH, GSM_PASSWORD_PATH, \
    20                                  GSM_NUMBER_PATH, GSM_APN_PATH
     20                                 GSM_NUMBER_PATH, GSM_APN_PATH, GSM_PIN_PATH, \
     21                                 GSM_PUK_PATH
    2122
    2223def get_username():
    2324    client = gconf.client_get_default()
    def get_apn(): 
    3536    client = gconf.client_get_default()
    3637    return client.get_string(GSM_APN_PATH) or ''
    3738
     39def get_pin():
     40    client = gconf.client_get_default()
     41    return client.get_string(GSM_PIN_PATH) or ''
     42
     43def get_puk():
     44    client = gconf.client_get_default()
     45    return client.get_string(GSM_PUK_PATH) or ''
     46
     47def get_pin():
     48    return get_storage().get_pin()
     49
     50def get_puk():
     51    return get_storage().get_puk()
     52
    3853def set_username(username):
    3954    client = gconf.client_get_default()
    4055    client.set_string(GSM_USERNAME_PATH, username)
    def set_apn(apn): 
    5166    client = gconf.client_get_default()
    5267    client.set_string(GSM_APN_PATH, apn)
    5368
     69def set_pin(pin):
     70    client = gconf.client_get_default()
     71    client.set_string(GSM_PIN_PATH, pin)
     72
     73def set_puk(puk):
     74    client = gconf.client_get_default()
     75    client.set_string(GSM_PUK_PATH, puk)
     76
  • extensions/cpsection/modemconfiguration/view.py

    diff --git a/extensions/cpsection/modemconfiguration/view.py b/extensions/cpsection/modemconfiguration/view.py
    index d66f1d5..592b03a 100644
    a b class UsernameEntry(EntryWithLabel): 
    9494        return self._model.get_username()
    9595
    9696    def set_value(self, username):
    97         return self._model.set_username(username)
     97        self._model.set_username(username)
    9898
    9999class PasswordEntry(EntryWithLabel):
    100100    def __init__(self, model):
    class PasswordEntry(EntryWithLabel): 
    105105        return self._model.get_password()
    106106
    107107    def set_value(self, password):
    108         return self._model.set_password(password)
     108        self._model.set_password(password)
    109109
    110110class NumberEntry(EntryWithLabel):
    111111    def __init__(self, model):
    class NumberEntry(EntryWithLabel): 
    116116        return self._model.get_number()
    117117
    118118    def set_value(self, number):
    119         return self._model.set_number(number)
     119        self._model.set_number(number)
    120120
    121121class ApnEntry(EntryWithLabel):
    122122    def __init__(self, model):
    class ApnEntry(EntryWithLabel): 
    127127        return self._model.get_apn()
    128128
    129129    def set_value(self, apn):
    130         return self._model.set_apn(apn)
     130        self._model.set_apn(apn)
     131
     132class PinEntry(EntryWithLabel):
     133    def __init__(self, model):
     134        EntryWithLabel.__init__(self, _('PIN:'))
     135        self._model = model
     136
     137    def get_value(self):
     138        return self._model.get_pin()
     139
     140    def set_value(self, pin):
     141        self._model.set_pin(pin)
     142
     143class PukEntry(EntryWithLabel):
     144    def __init__(self, model):
     145        EntryWithLabel.__init__(self, _('PUK:'))
     146        self._model = model
     147
     148    def get_value(self):
     149        return self._model.get_puk()
     150
     151    def set_value(self, puk):
     152        self._model.set_puk(puk)
     153
    131154
    132155class ModemConfiguration(SectionView):
    133156    def __init__(self, model, alerts=None):
    class ModemConfiguration(SectionView): 
    163186        self.pack_start(self._apn_entry, expand=False)
    164187        self._apn_entry.show()
    165188
     189        self._pin_entry = PinEntry(model)
     190        self._pin_entry.connect('notify::is-valid',
     191                                self.__notify_is_valid_cb)
     192        self.pack_start(self._pin_entry, expand=False)
     193        self._pin_entry.show()
     194       
     195        self._puk_entry = PukEntry(model)
     196        self._puk_entry.connect('notify::is-valid',
     197                                self.__notify_is_valid_cb)
     198        self.pack_start(puk_field, expand=False)       
     199        self._puk_entry.show()
     200
    166201        self.setup()
    167202
    168203    def setup(self):
    class ModemConfiguration(SectionView): 
    170205        self._password_entry.set_text_from_model()
    171206        self._number_entry.set_text_from_model()
    172207        self._apn_entry.set_text_from_model()
     208        self._pin_entry.set_text_from_model()
     209        self._puk_entry.set_text_from_model()
    173210
    174211        self.needs_restart = False
    175212
    class ModemConfiguration(SectionView): 
    180217        if self._username_entry.is_valid and \
    181218            self._password_entry.is_valid and \
    182219                self._number_entry.is_valid and \
    183                     self._apn_entry.is_valid:
    184                         self.props.is_valid = True
     220                    self._apn_entry.is_valid and \
     221                        self._pin_entry.is_valid and \
     222                            self._puk_entry.is_valid:
     223                                self.props.is_valid = True
    185224        else:
    186225            self.props.is_valid = False
    187226
  • extensions/deviceicon/network.py

    diff --git a/extensions/deviceicon/network.py b/extensions/deviceicon/network.py
    index 8e8eb64..b3ce3d7 100644
    a b _GSM_STATE_NOT_READY = 0 
    6161_GSM_STATE_DISCONNECTED = 1
    6262_GSM_STATE_CONNECTING = 2
    6363_GSM_STATE_CONNECTED = 3
     64_GSM_STATE_NEED_AUTH = 4
    6465
    6566def frequency_to_channel(frequency):
    6667    ftoc = { 2412: 1, 2417: 2, 2422: 3, 2427: 4,
    class GsmPalette(Palette): 
    276277        elif self._current_state == _GSM_STATE_CONNECTED:
    277278            self._toggle_state_item.get_child().set_label(_('Disconnect'))
    278279            self.props.secondary_text = _('Connected')
     280           
     281        elif self._current_state == _GSM_STATE_NEED_AUTH:
     282            self._toggle_state_item.get_child().set_label(_('Sim requires Pin/Puk'))
     283            self.props.secondary_text = _('Authentication Error')
     284           
    279285        else:
    280286            raise ValueError('Invalid GSM state while updating label and ' \
    281287                             'text, %s' % str(self._current_state))
    class GsmPalette(Palette): 
    289295            self.emit('gsm-disconnect')
    290296        elif self._current_state == _GSM_STATE_CONNECTED:
    291297            self.emit('gsm-disconnect')
     298        elif self._current_state == _GSM_STATE_NEED_AUTH:
     299            self.emit('gsm-disconnect')
    292300        else:
    293301            raise ValueError('Invalid GSM state while emitting signal, %s' % \
    294302                             str(self._current_state))
    class GsmDeviceView(TrayIcon): 
    787795        raise RuntimeError('Error when disconnecting gsm device, %s' % error)
    788796
    789797    def __state_changed_cb(self, new_state, old_state, reason):
     798        logging.debug('State: %s to %s, reason %s', old_state, new_state, reason)
    790799        self._update_state(int(new_state))
    791800
    792801    def __current_state_check_cb(self, properties):
    class GsmDeviceView(TrayIcon): 
    825834                       network.DEVICE_STATE_CONFIG,
    826835                       network.DEVICE_STATE_IP_CONFIG]:
    827836            gsm_state = _GSM_STATE_CONNECTING
    828 
     837           
     838        elif state in [_NM_DEVICE_STATE_NEED_AUTH]:
     839            gsm_state = _GSM_STATE_NEED_AUTH
     840           
    829841        if self._palette is not None:
    830842            self._palette.set_state(gsm_state)
    831843
  • src/jarabe/model/network.py

    diff --git a/src/jarabe/model/network.py b/src/jarabe/model/network.py
    index 00db4e7..82b5f8f 100644
    a b GSM_USERNAME_PATH = '/sugar/network/gsm/username' 
    9292GSM_PASSWORD_PATH = '/sugar/network/gsm/password'
    9393GSM_NUMBER_PATH = '/sugar/network/gsm/number'
    9494GSM_APN_PATH = '/sugar/network/gsm/apn'
     95GSM_PIN_PATH = '/sugar/network/gsm/pin'
     96GSM_PUK_PATH = '/sugar/network/gsm/puk'
    9597
    9698_nm_settings = None
    9799_conn_counter = 0
    class SettingsGsm(object): 
    287289class SecretsGsm(object):
    288290    def __init__(self):
    289291        self.password = None
    290 
     292        self.pin = None
     293        self.puk = None
     294       
    291295    def get_dict(self):
    292296        secrets = {}
    293297        if self.password is not None:
    294298            secrets['password'] = self.password
     299        if self.pin is not None:
     300            secrets['pin'] = self.pin
     301        if self.puk is not None:   
     302            secrets['puk'] = self.puk
    295303        return {'gsm': secrets}
    296304
    297305class NMSettings(dbus.service.Object):
    class NMSettingsConnection(dbus.service.Object): 
    435443    def GetSecrets(self, setting_name, hints, request_new, reply, error):
    436444        logging.debug('Secrets requested for connection %s request_new=%s',
    437445            self.path, request_new)
    438 
    439446        if request_new or self._secrets is None:
    440447            # request_new is for example the case when the pw on the AP changes
    441448            response = SecretsResponse(self, reply, error)
    def load_wifi_connections(): 
    651658
    652659
    653660def load_gsm_connection():
    654     settings = SettingsGsm()
    655     secrets = SecretsGsm()
    656 
    657661    client = gconf.client_get_default()
     662
     663    settings = SettingsGsm()
    658664    settings.gsm.username = client.get_string(GSM_USERNAME_PATH) or ''
    659665    settings.gsm.number = client.get_string(GSM_NUMBER_PATH) or ''
    660666    settings.gsm.apn = client.get_string(GSM_APN_PATH) or ''
    661667    password = client.get_string(GSM_PASSWORD_PATH) or ''
    662668
    663     if password:
    664         secrets.password = password
     669    secrets = SecretsGsm()
     670    secrets.pin = storage.get_pin()
     671    secrets.puk = storage.get_puk()
     672    secrets.password = password
    665673
    666674    settings.connection.id = 'gsm'
    667675    settings.connection.type = NM_CONNECTION_TYPE_GSM