From efd38029996fd8103377568f8c7141606c0a6600 Mon Sep 17 00:00:00 2001
From: root <root@localhost.localdomain>
Date: Thu, 14 Jan 2010 16:04:10 -0200
Subject: [PATCH 3/3] Pin-Puk Configuration 3G Support
---
extensions/cpsection/modemconfiguration/model.py | 12 ++++++
extensions/cpsection/modemconfiguration/view.py | 44 +++++++++++++++++++++-
extensions/deviceicon/network.py | 19 +++++++--
src/jarabe/model/network.py | 29 ++++++++++++--
4 files changed, 93 insertions(+), 11 deletions(-)
diff --git a/extensions/cpsection/modemconfiguration/model.py b/extensions/cpsection/modemconfiguration/model.py
index 0a6bcae..bf3c51f 100644
a
|
b
|
def get_number(): |
30 | 30 | def get_apn(): |
31 | 31 | return get_storage().get_apn() |
32 | 32 | |
| 33 | def get_pin(): |
| 34 | return get_storage().get_pin() |
| 35 | |
| 36 | def get_puk(): |
| 37 | return get_storage().get_puk() |
| 38 | |
33 | 39 | def set_username(username): |
34 | 40 | get_storage().set_username(username) |
35 | 41 | |
… |
… |
def set_number(number): |
42 | 48 | def set_apn(apn): |
43 | 49 | get_storage().set_apn(apn) |
44 | 50 | |
| 51 | def set_pin(pin): |
| 52 | get_storage().set_pin(pin) |
| 53 | |
| 54 | def set_puk(puk): |
| 55 | get_storage().set_puk(puk) |
| 56 | |
45 | 57 | def get_storage(): |
46 | 58 | global _storage |
47 | 59 | |
diff --git a/extensions/cpsection/modemconfiguration/view.py b/extensions/cpsection/modemconfiguration/view.py
index 7b65321..c5911db 100644
a
|
b
|
class ApnEntry(GsmEntry): |
102 | 102 | def set_method(self, apn): |
103 | 103 | return self._model.set_apn(apn) |
104 | 104 | |
| 105 | class PinEntry(GsmEntry): |
| 106 | def __init__(self, model): |
| 107 | GsmEntry.__init__(self) |
| 108 | self._model = model |
| 109 | |
| 110 | def get_method(self): |
| 111 | return self._model.get_pin() |
| 112 | |
| 113 | def set_method(self, pin): |
| 114 | return self._model.set_pin(pin) |
| 115 | |
| 116 | class PukEntry(GsmEntry): |
| 117 | def __init__(self, model): |
| 118 | GsmEntry.__init__(self) |
| 119 | self._model = model |
| 120 | |
| 121 | def get_method(self): |
| 122 | return self._model.get_puk() |
| 123 | |
| 124 | def set_method(self, puk): |
| 125 | return self._model.set_puk(puk) |
| 126 | |
| 127 | |
105 | 128 | class ModemConfiguration(SectionView): |
106 | 129 | def __init__(self, model, alerts=None): |
107 | 130 | SectionView.__init__(self) |
… |
… |
class ModemConfiguration(SectionView): |
129 | 152 | apn_field = self._create_field(self._apn_entry, _('APN:')) |
130 | 153 | self.pack_start(apn_field, False) |
131 | 154 | |
| 155 | self._pin_entry = PinEntry(model) |
| 156 | pin_field = self._create_field(self._pin_entry, _('PIN:')) |
| 157 | self.pack_start(pin_field, False) |
| 158 | |
| 159 | self._puk_entry = PukEntry(model) |
| 160 | puk_field = self._create_field(self._puk_entry, _('PUK:')) |
| 161 | self.pack_start(puk_field, False) |
| 162 | |
132 | 163 | self.setup() |
133 | 164 | |
134 | 165 | def _create_field(self, entry, label_text): |
… |
… |
class ModemConfiguration(SectionView): |
148 | 179 | self._password_entry.set_text_from_model() |
149 | 180 | self._number_entry.set_text_from_model() |
150 | 181 | self._apn_entry.set_text_from_model() |
| 182 | self._pin_entry.set_text_from_model() |
| 183 | self._puk_entry.set_text_from_model() |
151 | 184 | |
152 | 185 | self.needs_restart = False |
153 | 186 | |
… |
… |
class ModemConfiguration(SectionView): |
155 | 188 | self._password_entry.connect_changed(self.__changed_cb) |
156 | 189 | self._number_entry.connect_changed(self.__changed_cb) |
157 | 190 | self._apn_entry.connect_changed(self.__changed_cb) |
| 191 | self._pin_entry.connect_changed(self.__changed_cb) |
| 192 | self._puk_entry.connect_changed(self.__changed_cb) |
| 193 | |
158 | 194 | |
159 | 195 | def undo(self): |
160 | 196 | self._username_entry.disconnect_changed() |
161 | 197 | self._password_entry.disconnect_changed() |
162 | 198 | self._number_entry.disconnect_changed() |
163 | 199 | self._apn_entry.disconnect_changed() |
| 200 | self._pin_entry.disconnect_changed() |
| 201 | self._puk_entry.disconnect_changed() |
164 | 202 | |
165 | 203 | self._model.undo() |
166 | 204 | |
… |
… |
class ModemConfiguration(SectionView): |
168 | 206 | if self._username_entry.is_valid and \ |
169 | 207 | self._password_entry.is_valid and \ |
170 | 208 | self._number_entry.is_valid and \ |
171 | | self._apn_entry.is_valid: |
172 | | self.props.is_valid = True |
| 209 | self._apn_entry.is_valid and \ |
| 210 | self._pin_entry.is_valid and \ |
| 211 | self._puk_entry.is_valid: |
| 212 | self.props.is_valid = True |
173 | 213 | else: |
174 | 214 | self.props.is_valid = False |
175 | 215 | |
diff --git a/extensions/deviceicon/network.py b/extensions/deviceicon/network.py
index 088fbd0..28051af 100644
a
|
b
|
_GSM_STATE_NOT_READY = 0 |
70 | 70 | _GSM_STATE_DISCONNECTED = 1 |
71 | 71 | _GSM_STATE_CONNECTING = 2 |
72 | 72 | _GSM_STATE_CONNECTED = 3 |
| 73 | _GSM_STATE_NEED_AUTH = 4 |
73 | 74 | |
74 | 75 | def frequency_to_channel(frequency): |
75 | 76 | ftoc = { 2412: 1, 2417: 2, 2422: 3, 2427: 4, |
… |
… |
class GsmPalette(Palette): |
275 | 276 | elif self._current_state == _GSM_STATE_CONNECTED: |
276 | 277 | self._toggle_state_item.get_child().set_label(_('Disconnect')) |
277 | 278 | self.props.secondary_text = _('Connected') |
| 279 | |
| 280 | elif self._current_state == _GSM_STATE_NEED_AUTH: |
| 281 | self._toggle_state_item.get_child().set_label(_('Sim requires Pin/Puk')) |
| 282 | self.props.secondary_text = _('Authentication Error') |
| 283 | |
278 | 284 | else: |
279 | 285 | logging.error('Invalid GSM state while updating label and text, %s', str(self._current_state)) |
280 | 286 | |
… |
… |
class GsmPalette(Palette): |
290 | 296 | |
291 | 297 | elif self._current_state == _GSM_STATE_CONNECTED: |
292 | 298 | self.emit('gsm-disconnect') |
| 299 | |
| 300 | elif self._current_state == _GSM_STATE_NEED_AUTH: |
| 301 | self.emit('gsm-disconnect') |
293 | 302 | else: |
294 | 303 | logging.error('Invalid GSM state while emitting signal, %s', str(self._current_state)) |
295 | | |
| 304 | |
296 | 305 | class WirelessDeviceView(ToolButton): |
297 | 306 | |
298 | 307 | _ICON_NAME = 'network-wireless' |
… |
… |
class GsmDeviceView(TrayIcon): |
626 | 635 | if connection is not None: |
627 | 636 | obj = self._bus.get_object(_NM_SERVICE, _NM_PATH) |
628 | 637 | netmgr = dbus.Interface(obj, _NM_IFACE) |
629 | | |
630 | 638 | netmgr.ActivateConnection(network.SETTINGS_SERVICE, |
631 | 639 | connection.path, |
632 | 640 | self._device.object_path, |
… |
… |
class GsmDeviceView(TrayIcon): |
635 | 643 | logging.exception('Could not connect to gsm connection, %s', detail) |
636 | 644 | |
637 | 645 | def __gsm_disconnect_cb(self, palette, data=None): |
638 | | |
639 | 646 | obj = self._bus.get_object(_NM_SERVICE, _NM_PATH) |
640 | 647 | netmgr = dbus.Interface(obj, _NM_IFACE) |
641 | 648 | netmgr_props = dbus.Interface(netmgr, 'org.freedesktop.DBus.Properties') |
… |
… |
class GsmDeviceView(TrayIcon): |
653 | 660 | pass |
654 | 661 | |
655 | 662 | def __state_changed_cb(self, new_state, old_state, reason): |
| 663 | logging.debug('State: %s to %s, reason %s', old_state, new_state, reason) |
656 | 664 | self._update_state(int(new_state)) |
657 | 665 | |
658 | 666 | def __current_state_check_cb(self, properties): |
… |
… |
class GsmDeviceView(TrayIcon): |
687 | 695 | |
688 | 696 | elif state in [_NM_DEVICE_STATE_PREPARE, _NM_DEVICE_STATE_CONFIG, _NM_DEVICE_STATE_IP_CONFIG]: |
689 | 697 | gsm_state = _GSM_STATE_CONNECTING |
690 | | |
| 698 | |
| 699 | elif state in [_NM_DEVICE_STATE_NEED_AUTH]: |
| 700 | gsm_state = _GSM_STATE_NEED_AUTH |
| 701 | |
691 | 702 | if self._palette is not None: |
692 | 703 | self._palette.set_state(gsm_state) |
693 | 704 | |
diff --git a/src/jarabe/model/network.py b/src/jarabe/model/network.py
index 18c15d0..e9dca5e 100644
a
|
b
|
GSM_USERNAME_PATH = '/sugar/nm/gsm/username' |
91 | 91 | GSM_PASSWORD_PATH = '/sugar/nm/gsm/password' |
92 | 92 | GSM_NUMBER_PATH = '/sugar/nm/gsm/number' |
93 | 93 | GSM_APN_PATH = '/sugar/nm/gsm/apn' |
| 94 | GSM_PIN_PATH = '/sugar/nm/gsm/pin' |
| 95 | GSM_PUK_PATH = '/sugar/nm/gsm/puk' |
94 | 96 | |
95 | 97 | _nm_settings = None |
96 | 98 | _conn_counter = 0 |
… |
… |
class SettingsGsm(object): |
261 | 263 | class SecretsGsm(object): |
262 | 264 | def __init__(self): |
263 | 265 | self.password = None |
264 | | |
| 266 | self.pin = None |
| 267 | self.puk = None |
| 268 | |
265 | 269 | def get_dict(self): |
266 | 270 | secrets = {} |
267 | 271 | if self.password is not None: |
268 | 272 | secrets['password'] = self.password |
| 273 | if self.pin is not None: |
| 274 | secrets['pin'] = self.pin |
| 275 | if self.puk is not None: |
| 276 | secrets['puk'] = self.puk |
269 | 277 | return {'gsm': secrets} |
270 | 278 | |
271 | 279 | class NMSettings(dbus.service.Object): |
… |
… |
class NMSettingsConnection(dbus.service.Object): |
409 | 417 | def GetSecrets(self, setting_name, hints, request_new, reply, error): |
410 | 418 | logging.debug('Secrets requested for connection %s request_new=%s', |
411 | 419 | self.path, request_new) |
412 | | |
413 | 420 | if request_new or self._secrets is None: |
414 | 421 | # request_new is for example the case when the pw on the AP changes |
415 | 422 | response = SecretsResponse(self, reply, error) |
… |
… |
class StorageGsm(object): |
541 | 548 | def get_apn(self): |
542 | 549 | return self.verified(self._client.get_string(GSM_APN_PATH)) |
543 | 550 | |
| 551 | def get_pin(self): |
| 552 | return self.verified(self._client.get_string(GSM_PIN_PATH)) |
| 553 | |
| 554 | def get_puk(self): |
| 555 | return self.verified(self._client.get_string(GSM_PUK_PATH)) |
| 556 | |
544 | 557 | def set_username(self, username): |
545 | 558 | self._client.set_string(GSM_USERNAME_PATH, username) |
546 | 559 | |
… |
… |
class StorageGsm(object): |
553 | 566 | def set_apn(self, apn): |
554 | 567 | self._client.set_string(GSM_APN_PATH, apn) |
555 | 568 | |
| 569 | def set_pin(self, pin): |
| 570 | self._client.set_string(GSM_PIN_PATH, pin) |
| 571 | |
| 572 | def set_puk(self, puk): |
| 573 | self._client.set_string(GSM_PUK_PATH, puk) |
| 574 | |
556 | 575 | def verified(self, value): |
557 | 576 | if value is None: |
558 | 577 | return '' |
… |
… |
def load_gsm_connection(): |
665 | 684 | settings.gsm.username = storage.get_username() |
666 | 685 | settings.gsm.number = storage.get_number() |
667 | 686 | settings.gsm.apn = storage.get_apn() |
| 687 | |
668 | 688 | password = storage.get_password() |
669 | | |
| 689 | secrets.pin = storage.get_pin() |
| 690 | secrets.puk = storage.get_puk() |
670 | 691 | except ValueError, detail: |
671 | 692 | logging.exception('While reading gsm settings from storage, %s', detail) |
672 | | |
673 | 693 | else: |
674 | 694 | if password: |
675 | 695 | secrets.password = password |
676 | | |
677 | 696 | settings.connection.id = 'gsm' |
678 | 697 | settings.connection.type = NM_CONNECTION_TYPE_GSM |
679 | 698 | uuid = settings.connection.uuid = unique_id() |