Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/jarabe/desktop/meshbox.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/jarabe/desktop/meshbox.py')
-rw-r--r--src/jarabe/desktop/meshbox.py141
1 files changed, 112 insertions, 29 deletions
diff --git a/src/jarabe/desktop/meshbox.py b/src/jarabe/desktop/meshbox.py
index eaf2792..f00fad5 100644
--- a/src/jarabe/desktop/meshbox.py
+++ b/src/jarabe/desktop/meshbox.py
@@ -43,6 +43,8 @@ from jarabe.desktop.spreadlayout import SpreadLayout
from jarabe.desktop import keydialog
from jarabe.model import bundleregistry
from jarabe.model import network
+from jarabe.model.network import Settings
+from jarabe.model.network import WirelessSecurity
_NM_SERVICE = 'org.freedesktop.NetworkManager'
_NM_IFACE = 'org.freedesktop.NetworkManager'
@@ -68,7 +70,11 @@ class AccessPointView(CanvasPulsingIcon):
self._strength = 0
self._flags = 0
self._wpa_flags = 0
+ self._rsn_flags = 0
+ self._mode = 0
+ self._device_caps = 0
self._device_state = None
+ self._connection = None
self._active = True
self.connect('activated', self._activate_cb)
@@ -93,6 +99,9 @@ class AccessPointView(CanvasPulsingIcon):
self._device.Get(_NM_DEVICE_IFACE, 'State',
reply_handler=self.__get_device_state_reply_cb,
error_handler=self.__get_device_state_error_cb)
+ self._device.Get(_NM_WIRELESS_IFACE, 'WirelessCapabilities',
+ reply_handler=self.__get_device_caps_reply_cb,
+ error_handler=self.__get_device_caps_error_cb)
self._device.Get(_NM_WIRELESS_IFACE, 'ActiveAccessPoint',
reply_handler=self.__get_active_ap_reply_cb,
error_handler=self.__get_active_ap_error_cb)
@@ -140,16 +149,19 @@ class AccessPointView(CanvasPulsingIcon):
self._active = (ap == self._model.object_path)
self._update_state()
- def _update_properties(self, props):
- if 'Ssid' in props:
- self._name = props['Ssid']
- if 'Strength' in props:
- self._strength = props['Strength']
- if 'Flags' in props:
- self._flags = props['Flags']
- if 'WpaFlags' in props:
- self._wpa_flags = props['WpaFlags']
-
+ def _update_properties(self, properties):
+ if 'Ssid' in properties:
+ self._name = properties['Ssid']
+ if 'Strength' in properties:
+ self._strength = properties['Strength']
+ if 'Flags' in properties:
+ self._flags = properties['Flags']
+ if 'WpaFlags' in properties:
+ self._wpa_flags = properties['WpaFlags']
+ if 'RsnFlags' in properties:
+ self._rsn_flags = properties['RsnFlags']
+ if 'Mode' in properties:
+ self._mode = properties['Mode']
self._update()
def _compute_color(self):
@@ -169,6 +181,12 @@ class AccessPointView(CanvasPulsingIcon):
def __get_active_ap_error_cb(self, err):
logging.debug('Error getting the active access point: %s', err)
+ def __get_device_caps_reply_cb(self, caps):
+ self._device_caps = caps
+
+ def __get_device_caps_error_cb(self, err):
+ logging.debug('Error getting the wireless device properties: %s', err)
+
def __get_device_state_reply_cb(self, state):
self._device_state = state
self._update()
@@ -183,7 +201,7 @@ class AccessPointView(CanvasPulsingIcon):
logging.debug('Error getting the access point properties: %s', err)
def _update(self):
- if self._flags == network.AP_FLAGS_802_11_PRIVACY:
+ if self._flags == network.NM_802_11_AP_FLAGS_PRIVACY:
self.props.badge_name = "emblem-locked"
else:
self.props.badge_name = None
@@ -240,29 +258,99 @@ class AccessPointView(CanvasPulsingIcon):
def _disconnect_activate_cb(self, item):
pass
+
+ def _add_ciphers_from_flags(self, flags, pairwise):
+ ciphers = []
+ if pairwise:
+ if flags & network.NM_802_11_AP_SEC_PAIR_TKIP:
+ ciphers.append("tkip")
+ if flags & network.NM_802_11_AP_SEC_PAIR_CCMP:
+ ciphers.append("ccmp")
+ else:
+ if flags & network.NM_802_11_AP_SEC_GROUP_WEP40:
+ ciphers.append("wep40")
+ if flags & network.NM_802_11_AP_SEC_GROUP_WEP104:
+ ciphers.append("wep104")
+ if flags & network.NM_802_11_AP_SEC_GROUP_TKIP:
+ ciphers.append("tkip")
+ if flags & network.NM_802_11_AP_SEC_GROUP_CCMP:
+ ciphers.append("ccmp")
+ return ciphers
+
+ def _get_security(self):
+ if not (self._flags & network.NM_802_11_AP_FLAGS_PRIVACY) and \
+ (self._wpa_flags == network.NM_802_11_AP_SEC_NONE) and \
+ (self._rsn_flags == network.NM_802_11_AP_SEC_NONE):
+ # No security
+ return None
+
+ if (self._flags & network.NM_802_11_AP_FLAGS_PRIVACY) and \
+ (self._wpa_flags == network.NM_802_11_AP_SEC_NONE) and \
+ (self._rsn_flags == network.NM_802_11_AP_SEC_NONE):
+ # Static WEP, Dynamic WEP, or LEAP
+ wireless_security = WirelessSecurity()
+ wireless_security.key_mgmt = 'none'
+ return wireless_security
+
+ if (self._mode != network.NM_802_11_MODE_INFRA):
+ # Stuff after this point requires infrastructure
+ logging.error('The infrastructure mode is not supoorted'
+ ' by your wireless device.')
+ return None
+
+ if (self._rsn_flags & network.NM_802_11_AP_SEC_KEY_MGMT_PSK) and \
+ (self._dev_caps & network.NM_802_11_DEVICE_CAP_RSN):
+ # WPA2 PSK first
+ pairwise = self._add_ciphers_from_flags(self._rsn_flags, True)
+ group = self._add_ciphers_from_flags(self._rsn_flags, False)
+ wireless_security = WirelessSecurity()
+ wireless_security.key_mgmt = 'wpa-psk'
+ wireless_security.proto = 'rsn'
+ wireless_security.pairwise = pairwise
+ wireless_security.group = group
+ return wireless_security
+
+ if (self._wpa_flags & network.NM_802_11_AP_SEC_KEY_MGMT_PSK) and \
+ (self._dev_caps & network.NM_802_11_DEVICE_CAP_WPA):
+ # WPA PSK
+ pairwise = self._add_ciphers_from_flags(self._wpa_flags, True)
+ group = self._add_ciphers_from_flags(self._wpa_flags, False)
+ wireless_security = WirelessSecurity()
+ wireless_security.key_mgmt = 'wpa-psk'
+ wireless_security.proto = 'wpa'
+ wireless_security.pairwise = pairwise
+ wireless_security.group = group
+ return wireless_security
+
def _activate_cb(self, icon):
- conn = network.find_connection(self._name)
- if conn is None:
- info = { 'connection': { 'id' : 'Auto ' + self._name,
- 'uuid' : unique_id(),
- 'type' : '802-11-wireless' } ,
- '802-11-wireless' : { 'ssid': self._name }
- }
+ connection = network.find_connection(self._name)
+ if connection is None:
+ settings = Settings()
+ settings.connection.id = 'Auto ' + self._name
+ settings.connection.uuid = unique_id()
+ settings.connection.type = '802-11-wireless'
+ settings.wireless.ssid = self._name
+
+ wireless_security = self._get_security()
+ settings.wireless_security = wireless_security
- if self._flags == network.AP_FLAGS_802_11_PRIVACY:
- info["802-11-wireless-security"] = { "key-mgmt": "none" }
+ connection = network.add_connection(self._name, settings)
- conn = network.add_connection(self._name, info)
+ if wireless_security is None:
+ self._connection = connection
obj = self._bus.get_object(_NM_SERVICE, _NM_PATH)
netmgr = dbus.Interface(obj, _NM_IFACE)
- netmgr.ActivateConnection(network.SETTINGS_SERVICE, conn.path,
+
+ netmgr.ActivateConnection(network.SETTINGS_SERVICE, connection.path,
self._device.object_path,
self._model.object_path,
reply_handler=self.__activate_reply_cb,
error_handler=self.__activate_error_cb)
def __activate_reply_cb(self, connection):
+ if self._connection:
+ self._connection.save()
logging.debug('Connection activated: %s', connection)
def __activate_error_cb(self, err):
@@ -273,7 +361,8 @@ class AccessPointView(CanvasPulsingIcon):
self._update_state()
def create_keydialog(self, response):
- keydialog.create(self._name, self._wpa_flags, response)
+ keydialog.create(self._name, self._flags, self._wpa_flags,
+ self._rsn_flags, self._device_caps, response)
def disconnect(self):
self._bus.remove_signal_receiver(self.__ap_properties_changed_cb,
@@ -662,12 +751,6 @@ class MeshBox(gtk.VBox):
def _activity_removed_cb(self, model, activity_model):
self._remove_activity(activity_model)
- def _access_point_added_cb(self, model, ap_model):
- self._add_access_point(ap_model)
-
- def _access_point_removed_cb(self, model, ap_model):
- self._remove_access_point(ap_model)
-
def _add_alone_buddy(self, buddy_model):
icon = BuddyIcon(buddy_model)
if buddy_model.is_owner():