Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSayamindu Dasgupta <sayamindu@gmail.com>2010-05-10 13:41:16 (GMT)
committer Sayamindu Dasgupta <sayamindu@gmail.com>2010-05-10 13:41:16 (GMT)
commit027676174d3e0f287e64257841ada3e9635ac6b6 (patch)
treec4b8d12b0b56f45a5e64806f0bcc5da3d8841da4 /src
parent9e0ba21be6e1cd8de34adc831a68c3305f6177d1 (diff)
Initial support for 3G modems
Diffstat (limited to 'src')
-rw-r--r--src/jarabe/desktop/meshbox.py12
-rw-r--r--src/jarabe/model/network.py147
2 files changed, 142 insertions, 17 deletions
diff --git a/src/jarabe/desktop/meshbox.py b/src/jarabe/desktop/meshbox.py
index 81363ac..edefbfc 100644
--- a/src/jarabe/desktop/meshbox.py
+++ b/src/jarabe/desktop/meshbox.py
@@ -211,7 +211,7 @@ class WirelessNetworkView(CanvasPulsingIcon):
state = network.DEVICE_STATE_UNKNOWN
if state == network.DEVICE_STATE_ACTIVATED:
- connection = network.find_connection(self._name)
+ connection = network.find_connection_by_ssid(self._name)
if connection:
if self._mode == network.NM_802_11_MODE_INFRA:
connection.set_connected()
@@ -256,7 +256,7 @@ class WirelessNetworkView(CanvasPulsingIcon):
self.props.base_color = self._color
def _update_badge(self):
- if network.find_connection(self._name) is not None:
+ if network.find_connection_by_ssid(self._name) is not None:
self.props.badge_name = "emblem-favorite"
self._palette_icon.props.badge_name = "emblem-favorite"
elif self._flags == network.NM_802_11_AP_FLAGS_PRIVACY:
@@ -267,7 +267,7 @@ class WirelessNetworkView(CanvasPulsingIcon):
self._palette_icon.props.badge_name = None
def _disconnect_activate_cb(self, item):
- connection = network.find_connection(self._name)
+ connection = network.find_connection_by_ssid(self._name)
if connection:
if self._mode == network.NM_802_11_MODE_INFRA:
connection.set_disconnected()
@@ -360,11 +360,11 @@ class WirelessNetworkView(CanvasPulsingIcon):
self._connect()
def _connect(self):
- connection = network.find_connection(self._name)
+ connection = network.find_connection_by_ssid(self._name)
if connection is None:
settings = Settings()
settings.connection.id = 'Auto ' + self._name
- settings.connection.uuid = unique_id()
+ uuid = settings.connection.uuid = unique_id()
settings.connection.type = '802-11-wireless'
settings.wireless.ssid = self._name
@@ -382,7 +382,7 @@ class WirelessNetworkView(CanvasPulsingIcon):
if wireless_security is not None:
settings.wireless.security = '802-11-wireless-security'
- connection = network.add_connection(self._name, settings)
+ connection = network.add_connection(uuid, settings)
obj = self._bus.get_object(_NM_SERVICE, _NM_PATH)
netmgr = dbus.Interface(obj, _NM_IFACE)
diff --git a/src/jarabe/model/network.py b/src/jarabe/model/network.py
index 23b7472..d0d3112 100644
--- a/src/jarabe/model/network.py
+++ b/src/jarabe/model/network.py
@@ -1,6 +1,7 @@
# Copyright (C) 2008 Red Hat, Inc.
# Copyright (C) 2009 Tomeu Vizoso, Simon Schampijer
# Copyright (C) 2009 One Laptop per Child
+# Copyright (C) 2009 Paraguay Educa, Martin Abente
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -23,12 +24,15 @@ import time
import dbus
import gobject
import ConfigParser
+import gconf
from sugar import dispatch
from sugar import env
+from sugar.util import unique_id
DEVICE_TYPE_802_3_ETHERNET = 1
DEVICE_TYPE_802_11_WIRELESS = 2
+DEVICE_TYPE_GSM_MODEM = 3
DEVICE_STATE_UNKNOWN = 0
DEVICE_STATE_UNMANAGED = 1
@@ -41,6 +45,9 @@ DEVICE_STATE_IP_CONFIG = 7
DEVICE_STATE_ACTIVATED = 8
DEVICE_STATE_FAILED = 9
+NM_CONNECTION_TYPE_802_11_WIRELESS = '802-11-wireless'
+NM_CONNECTION_TYPE_GSM = 'gsm'
+
NM_ACTIVE_CONNECTION_STATE_UNKNOWN = 0
NM_ACTIVE_CONNECTION_STATE_ACTIVATING = 1
NM_ACTIVE_CONNECTION_STATE_ACTIVATED = 2
@@ -80,6 +87,11 @@ NM_CONNECTION_IFACE = 'org.freedesktop.NetworkManagerSettings.Connection'
NM_SECRETS_IFACE = 'org.freedesktop.NetworkManagerSettings.Connection.Secrets'
NM_ACCESSPOINT_IFACE = 'org.freedesktop.NetworkManager.AccessPoint'
+GSM_USERNAME_PATH = '/sugar/network/gsm/username'
+GSM_PASSWORD_PATH = '/sugar/network/gsm/password'
+GSM_NUMBER_PATH = '/sugar/network/gsm/number'
+GSM_APN_PATH = '/sugar/network/gsm/apn'
+
_nm_settings = None
_conn_counter = 0
@@ -146,6 +158,44 @@ class IP4Config(object):
ip4_config['method'] = self.method
return ip4_config
+class Serial(object):
+ def __init__(self):
+ self.baud = None
+
+ def get_dict(self):
+ serial = {}
+
+ if self.baud is not None:
+ serial['baud'] = self.baud
+
+ return serial
+
+class Ppp(object):
+ def __init__(self):
+ pass
+
+ def get_dict(self):
+ ppp = {}
+ return ppp
+
+class Gsm(object):
+ def __init__(self):
+ self.apn = None
+ self.number = None
+ self.username = None
+
+ def get_dict(self):
+ gsm = {}
+
+ if self.apn is not None:
+ gsm['apn'] = self.apn
+ if self.number is not None:
+ gsm['number'] = self.number
+ if self.username is not None:
+ gsm['username'] = self.username
+
+ return gsm
+
class Settings(object):
def __init__(self):
self.connection = Connection()
@@ -189,6 +239,35 @@ class Secrets(object):
return settings
+class SettingsGsm(object):
+ def __init__(self):
+ self.connection = Connection()
+ self.ip4_config = IP4Config()
+ self.serial = Serial()
+ self.ppp = Ppp()
+ self.gsm = Gsm()
+
+ def get_dict(self):
+ settings = {}
+
+ settings['connection'] = self.connection.get_dict()
+ settings['serial'] = self.serial.get_dict()
+ settings['ppp'] = self.ppp.get_dict()
+ settings['gsm'] = self.gsm.get_dict()
+ settings['ipv4'] = self.ip4_config.get_dict()
+
+ return settings
+
+class SecretsGsm(object):
+ def __init__(self):
+ self.password = None
+
+ def get_dict(self):
+ secrets = {}
+ if self.password is not None:
+ secrets['password'] = self.password
+ return {'gsm': secrets}
+
class NMSettings(dbus.service.Object):
def __init__(self):
bus = dbus.SystemBus()
@@ -207,8 +286,8 @@ class NMSettings(dbus.service.Object):
def NewConnection(self, connection_path):
pass
- def add_connection(self, ssid, conn):
- self.connections[ssid] = conn
+ def add_connection(self, uuid, conn):
+ self.connections[uuid] = conn
conn.secrets_request.connect(self.__secrets_request_cb)
self.NewConnection(conn.path)
@@ -281,6 +360,10 @@ class NMSettingsConnection(dbus.service.Object):
return self._settings
def save(self):
+ # We only save wifi settins
+ if self._settings.connection.type != NM_CONNECTION_TYPE_802_11_WIRELESS:
+ return
+
profile_path = env.get_profile_path()
config_path = os.path.join(profile_path, 'nm', 'connections.cfg')
@@ -473,24 +556,28 @@ def get_settings():
load_connections()
return _nm_settings
-def find_connection(ssid):
+def find_connection_by_ssid(ssid):
connections = get_settings().connections
- if ssid in connections:
- return connections[ssid]
- else:
- return None
-def add_connection(ssid, settings, secrets=None):
+ for conn_index in connections:
+ connection = connections[conn_index]
+ if connection._settings.connection.type == NM_CONNECTION_TYPE_802_11_WIRELESS:
+ if connection._settings.wireless.ssid == ssid:
+ return connection
+
+ return None
+
+def add_connection(uuid, settings, secrets=None):
global _conn_counter
path = NM_SETTINGS_PATH + '/' + str(_conn_counter)
_conn_counter += 1
conn = NMSettingsConnection(path, settings, secrets)
- _nm_settings.add_connection(ssid, conn)
+ _nm_settings.add_connection(uuid, conn)
return conn
-def load_connections():
+def load_wifi_connections():
profile_path = env.get_profile_path()
config_path = os.path.join(profile_path, 'nm', 'connections.cfg')
@@ -553,7 +640,7 @@ def load_connections():
except ConfigParser.Error, e:
logging.error('Error reading section: %s' % e)
else:
- add_connection(ssid, settings, secrets)
+ add_connection(uuid, settings, secrets)
def count_connections():
return len(get_settings().connections)
@@ -568,3 +655,41 @@ def clear_connections():
os.makedirs(os.path.dirname(config_path), 0755)
f = open(config_path, 'w')
f.close()
+
+def load_gsm_connection():
+ settings = SettingsGsm()
+ secrets = SecretsGsm()
+
+ client = gconf.client_get_default()
+ settings.gsm.username = client.get_string(GSM_USERNAME_PATH) or ''
+ settings.gsm.number = client.get_string(GSM_NUMBER_PATH) or ''
+ settings.gsm.apn = client.get_string(GSM_APN_PATH) or ''
+ password = client.get_string(GSM_PASSWORD_PATH) or ''
+
+ if password:
+ secrets.password = password
+
+ settings.connection.id = 'gsm'
+ settings.connection.type = NM_CONNECTION_TYPE_GSM
+ uuid = settings.connection.uuid = unique_id()
+ settings.connection.autoconnect = False
+ settings.ip4_config.method = 'auto'
+ settings.serial.baud = 115200
+
+ try:
+ add_connection(uuid, settings, secrets)
+ except Exception:
+ logging.exception('While adding gsm connection')
+
+def load_connections():
+ load_wifi_connections()
+ load_gsm_connection()
+
+def find_gsm_connection():
+ connections = get_settings().connections
+
+ for connection in connections.values():
+ if connection.get_settings().connection.type == NM_CONNECTION_TYPE_GSM:
+ return connection
+
+ return None