Ticket #2015: olpc-mesh-0.84v3.patch

File olpc-mesh-0.84v3.patch, 26.5 KB (added by erikos, 14 years ago)

Contains #1890, too http://git.sugarlabs.org/projects/sugar/repos/mainline/commits/a388ecfea10b153b6b274c2dee055db46d013e52

  • extensions/deviceicon/network.py

    diff --git a/extensions/deviceicon/network.py b/extensions/deviceicon/network.py
    index 14f3474..202c563 100644
    a b  
    11#
    2 # Copyright (C) 2008 One Laptop Per Child
     2# Copyright (C) 2008-2010 One Laptop Per Child
    33# Copyright (C) 2009 Tomeu Vizoso, Simon Schampijer
    44# Copyright (C) 2009 Paraguay Educa, Martin Abente
    55#
    from sugar.graphics.toolbutton import ToolButton 
    3737from sugar.graphics.tray import TrayIcon
    3838from sugar.graphics import xocolor
    3939from sugar.util import unique_id
     40from sugar import profile
    4041
    4142from jarabe.model import network
    4243from jarabe.model.network import Settings
    _NM_PATH = '/org/freedesktop/NetworkManager' 
    5253_NM_DEVICE_IFACE = 'org.freedesktop.NetworkManager.Device'
    5354_NM_WIRED_IFACE = 'org.freedesktop.NetworkManager.Device.Wired'
    5455_NM_WIRELESS_IFACE = 'org.freedesktop.NetworkManager.Device.Wireless'
     56_NM_OLPC_MESH_IFACE = 'org.freedesktop.NetworkManager.Device.OlpcMesh'
    5557_NM_SERIAL_IFACE = 'org.freedesktop.NetworkManager.Device.Serial'
    5658_NM_ACCESSPOINT_IFACE = 'org.freedesktop.NetworkManager.AccessPoint'
    5759_NM_ACTIVE_CONN_IFACE = 'org.freedesktop.NetworkManager.Connection.Active'
    class WirelessPalette(Palette): 
    7981                                   gobject.TYPE_NONE, ([])),
    8082    }
    8183
    82     def __init__(self, primary_text):
     84    def __init__(self, primary_text, can_create=True):
    8385        Palette.__init__(self, label=primary_text)
    8486
    8587        self._disconnect_item = None
    class WirelessPalette(Palette): 
    110112        self._disconnect_item.connect('activate', self.__disconnect_activate_cb)
    111113        self.menu.append(self._disconnect_item)
    112114
    113         self._adhoc_item = gtk.MenuItem(_('Create new wireless network'))
    114         self._adhoc_item.connect('activate', self.__adhoc_activate_cb)
    115         self.menu.append(self._adhoc_item)
    116         self._adhoc_item.show()
     115        if can_create:
     116            self._adhoc_item = gtk.MenuItem(_('Create new wireless network'))
     117            self._adhoc_item.connect('activate', self.__adhoc_activate_cb)
     118            self.menu.append(self._adhoc_item)
     119            self._adhoc_item.show()
    117120
    118121    def set_connecting(self):
    119122        self.props.secondary_text = _('Connecting...')
    120123
    121     def set_connected(self, frequency, iaddress):
     124    def _set_connected(self, iaddress):
    122125        self.set_content(self._info)
    123126        self.props.secondary_text = _('Connected')
    124         self._set_channel(frequency)
    125127        self._set_ip_address(iaddress)
    126128        self._disconnect_item.show()
    127129       
     130    def set_connected_with_frequency(self, frequency, iaddress):
     131        self._set_connected(iaddress)
     132        self._set_frequency(frequency)
     133
     134    def set_connected_with_channel(self, channel, iaddress):
     135        self._set_connected(iaddress)
     136        self._set_channel(channel)
     137
    128138    def set_disconnected(self):
    129139        self.props.primary_text = ''
    130140        self.props.secondary_text = ''
    class WirelessPalette(Palette): 
    137147    def __adhoc_activate_cb(self, menuitem):
    138148        self.emit('create-connection')
    139149
    140     def _set_channel(self, frequency):
     150    def _set_frequency(self, frequency):
    141151        try:
    142152            channel = frequency_to_channel(frequency)
    143153        except KeyError:
    144154            channel = 0
     155        self._set_channel(channel)
     156
     157    def _set_channel(self, channel):
    145158        self._channel_label.set_text("%s: %d" % (_("Channel"), channel))
    146159
    147160    def _set_ip_address(self, ip_address):
    class WirelessDeviceView(ToolButton): 
    479492            self._icon.props.pulsing = True
    480493        elif state == network.DEVICE_STATE_ACTIVATED:
    481494            address = self._device_props.Get(_NM_DEVICE_IFACE, 'Ip4Address')
    482             self._palette.set_connected(self._frequency, address)
     495            self._palette.set_connected_with_frequency(self._frequency,
     496                                                       address)
    483497            self._icon.props.pulsing = False
    484498        else:
    485499            self._icon.props.badge_name = None
    class WirelessDeviceView(ToolButton): 
    566580    def __activate_error_cb(self, err):
    567581        logging.debug('Failed to create network: %s', err)
    568582
     583class OlpcMeshDeviceView(ToolButton):
     584    _ICON_NAME = 'network-mesh'
     585    FRAME_POSITION_RELATIVE = 302
     586
     587    def __init__(self, device):
     588        ToolButton.__init__(self)
     589
     590        self._bus = dbus.SystemBus()
     591        self._device = device
     592        self._device_props = None
     593        self._device_state = None
     594        self._channel = 0
     595
     596        self._icon = PulsingIcon(icon_name=self._ICON_NAME)
     597        self._icon.props.pulse_color = xocolor.XoColor( \
     598            "%s,%s" % (style.COLOR_BUTTON_GREY.get_svg(),
     599                       style.COLOR_TRANSPARENT.get_svg()))
     600        self._icon.props.base_color = profile.get_color()
     601
     602        self.set_icon_widget(self._icon)
     603        self._icon.show()
     604
     605        self.set_palette_invoker(FrameWidgetInvoker(self))
     606        self._palette = WirelessPalette(_("Mesh Network"))
     607        self._palette.connect('deactivate-connection',
     608                              self.__deactivate_connection)
     609        self.set_palette(self._palette)
     610        self._palette.set_group_id('frame')
     611
     612        self._device_props = dbus.Interface(self._device,
     613                                            'org.freedesktop.DBus.Properties')
     614        self._device_props.GetAll(_NM_DEVICE_IFACE, byte_arrays=True,
     615                              reply_handler=self.__get_device_props_reply_cb,
     616                              error_handler=self.__get_device_props_error_cb)
     617        self._device_props.Get(_NM_OLPC_MESH_IFACE, 'ActiveChannel',
     618                            reply_handler=self.__get_active_channel_reply_cb,
     619                            error_handler=self.__get_active_channel_error_cb)
     620
     621        self._bus.add_signal_receiver(self.__state_changed_cb,
     622                                      signal_name='StateChanged',
     623                                      path=self._device.object_path,
     624                                      dbus_interface=_NM_DEVICE_IFACE)
     625        self._bus.add_signal_receiver(self.__wireless_properties_changed_cb,
     626                                      signal_name='PropertiesChanged',
     627                                      path=device.object_path,
     628                                      dbus_interface=_NM_OLPC_MESH_IFACE)
     629
     630    def disconnect(self):
     631        self._bus.remove_signal_receiver(self.__state_changed_cb,
     632                                         signal_name='StateChanged',
     633                                         path=self._device.object_path,
     634                                         dbus_interface=_NM_DEVICE_IFACE)
     635        self._bus.remove_signal_receiver(self.__wireless_properties_changed_cb,
     636                                         signal_name='PropertiesChanged',
     637                                         path=self._device.object_path,
     638                                         dbus_interface=_NM_OLPC_MESH_IFACE)
     639
     640    def __get_device_props_reply_cb(self, properties):
     641        if 'State' in properties:
     642            self._device_state = properties['State']
     643            self._update()
     644
     645    def __get_device_props_error_cb(self, err):
     646        logging.error('Error getting the device properties: %s', err)
     647
     648    def __get_active_channel_reply_cb(self, channel):
     649        self._channel = channel
     650        self._update_text()
     651
     652    def __get_active_channel_error_cb(self, err):
     653        logging.error('Error getting the active channel: %s', err)
     654
     655    def __state_changed_cb(self, new_state, old_state, reason):
     656        self._device_state = new_state
     657        self._update()
     658
     659    def __wireless_properties_changed_cb(self, properties):
     660        if 'ActiveChannel' in properties:
     661            self._channel = properties['ActiveChannel']
     662            self._update_text()
     663
     664    def _update_text(self):
     665        text = _("Mesh Network") + " " + str(self._channel)
     666        self._palette.props.primary_text = text
     667
     668    def _update(self):
     669        state = self._device_state
     670
     671        if state in [network.DEVICE_STATE_PREPARE,
     672                     network.DEVICE_STATE_CONFIG,
     673                     network.DEVICE_STATE_NEED_AUTH,
     674                     network.DEVICE_STATE_IP_CONFIG]:
     675            self._palette.set_connecting()
     676            self._icon.props.pulsing = True
     677        elif state == network.DEVICE_STATE_ACTIVATED:
     678            address = self._device_props.Get(_NM_DEVICE_IFACE, 'Ip4Address')
     679            self._palette.set_connected_with_channel(self._channel, address)
     680            self._icon.props.pulsing = False
     681
     682    def __deactivate_connection(self, palette, data=None):
     683        obj = self._bus.get_object(_NM_SERVICE, _NM_PATH)
     684        netmgr = dbus.Interface(obj, _NM_IFACE)
     685        netmgr_props = dbus.Interface(netmgr, 'org.freedesktop.DBus.Properties')
     686        active_connections_o = netmgr_props.Get(_NM_IFACE,
     687                                                'ActiveConnections')
     688
     689        for conn_o in active_connections_o:
     690            # The connection path for a mesh connection is the device itself.
     691            obj = self._bus.get_object(_NM_IFACE, conn_o)
     692            props = dbus.Interface(obj, 'org.freedesktop.DBus.Properties')
     693            ap_op = props.Get(_NM_ACTIVE_CONN_IFACE, 'SpecificObject')
     694
     695            try:
     696                obj = self._bus.get_object(_NM_IFACE, ap_op)
     697                props = dbus.Interface(obj, 'org.freedesktop.DBus.Properties')
     698                type = props.Get(_NM_DEVICE_IFACE, 'DeviceType')
     699                if type == network.DEVICE_TYPE_802_11_OLPC_MESH:
     700                    netmgr.DeactivateConnection(conn_o)
     701                    break
     702            except dbus.exceptions.DBusException:
     703                pass
     704
    569705class WiredDeviceView(TrayIcon):
    570706
    571707    _ICON_NAME = 'network-wired'
    class GsmDeviceView(TrayIcon): 
    746882        self._palette.connection_time_label.set_text(text)
    747883
    748884class WirelessDeviceObserver(object):
    749     def __init__(self, device, tray):
     885    def __init__(self, device, tray, device_type):
    750886        self._device = device
    751887        self._device_view = None
    752888        self._tray = tray
    753889
    754         self._device_view = WirelessDeviceView(self._device)
     890        if device_type == network.DEVICE_TYPE_802_11_WIRELESS:
     891            self._device_view = WirelessDeviceView(self._device)
     892        elif device_type == network.DEVICE_TYPE_802_11_OLPC_MESH:
     893            self._device_view = OlpcMeshDeviceView(self._device)
     894
    755895        self._tray.add_device(self._device_view)
    756896
    757897    def disconnect(self):
    class NetworkManagerObserver(object): 
    8611001        if device_type == network.DEVICE_TYPE_802_3_ETHERNET:
    8621002            device = WiredDeviceObserver(nm_device, self._tray)
    8631003            self._devices[device_op] = device
    864         elif device_type == network.DEVICE_TYPE_802_11_WIRELESS:
    865             device = WirelessDeviceObserver(nm_device, self._tray)
     1004        elif device_type in [network.DEVICE_TYPE_802_11_WIRELESS,
     1005                             network.DEVICE_TYPE_802_11_OLPC_MESH]:
     1006            device = WirelessDeviceObserver(nm_device, self._tray, device_type)
    8661007            self._devices[device_op] = device
    8671008        elif device_type == network.DEVICE_TYPE_GSM_MODEM:
    8681009            device = GsmDeviceObserver(nm_device, self._tray)
  • src/jarabe/desktop/meshbox.py

    diff --git a/src/jarabe/desktop/meshbox.py b/src/jarabe/desktop/meshbox.py
    index edefbfc..29a9cf1 100644
    a b from sugar.graphics.menuitem import MenuItem 
    3636from sugar.activity.activityhandle import ActivityHandle
    3737from sugar.activity import activityfactory
    3838from sugar.util import unique_id
     39from sugar import profile
    3940
    4041from jarabe.model import neighborhood
    4142from jarabe.view.buddyicon import BuddyIcon
    from jarabe.model.network import Settings 
    5152from jarabe.model.network import IP4Config
    5253from jarabe.model.network import WirelessSecurity
    5354from jarabe.model.network import AccessPoint
     55from jarabe.model.network import OlpcMesh as OlpcMeshSettings
     56from jarabe.model.olpcmesh import OlpcMeshManager
    5457
    5558_NM_SERVICE = 'org.freedesktop.NetworkManager'
    5659_NM_IFACE = 'org.freedesktop.NetworkManager'
    5760_NM_PATH = '/org/freedesktop/NetworkManager'
    5861_NM_DEVICE_IFACE = 'org.freedesktop.NetworkManager.Device'
    5962_NM_WIRELESS_IFACE = 'org.freedesktop.NetworkManager.Device.Wireless'
     63_NM_OLPC_MESH_IFACE = 'org.freedesktop.NetworkManager.Device.OlpcMesh'
    6064_NM_ACCESSPOINT_IFACE = 'org.freedesktop.NetworkManager.AccessPoint'
    6165_NM_ACTIVE_CONN_IFACE = 'org.freedesktop.NetworkManager.Connection.Active'
    6266
    63 _ICON_NAME = 'network-wireless'
    64 
     67_AP_ICON_NAME = 'network-wireless'
     68_OLPC_MESH_ICON_NAME = 'network-mesh'
    6569
    6670class WirelessNetworkView(CanvasPulsingIcon):
    6771    def __init__(self, initial_ap):
    class WirelessNetworkView(CanvasPulsingIcon): 
    139143            and self._name[-15] == '#'
    140144
    141145    def _create_palette(self):
    142         icon_name = get_icon_state(_ICON_NAME, self._strength)
     146        icon_name = get_icon_state(_AP_ICON_NAME, self._strength)
    143147        self._palette_icon = Icon(icon_name=icon_name,
    144148                                  icon_size=style.STANDARD_ICON_SIZE,
    145149                                  badge_name=self.props.badge_name)
    class WirelessNetworkView(CanvasPulsingIcon): 
    216220                if self._mode == network.NM_802_11_MODE_INFRA:
    217221                    connection.set_connected()
    218222
    219             icon_name = '%s-connected' % _ICON_NAME
     223            icon_name = '%s-connected' % _AP_ICON_NAME
    220224        else:
    221             icon_name = _ICON_NAME
     225            icon_name = _AP_ICON_NAME
    222226
    223227        icon_name = get_icon_state(icon_name, self._strength)
    224228        if icon_name:
    class WirelessNetworkView(CanvasPulsingIcon): 
    443447            return None
    444448        return self._access_points[ap_path]
    445449
     450    def is_olpc_mesh(self):
     451        return self._mode == network.NM_802_11_MODE_ADHOC \
     452            and self.name == "olpc-mesh"
     453
     454    def remove_all_aps(self):
     455        for ap in self._access_points.values():
     456            ap.disconnect()
     457        self._access_points = {}
     458        self._active_ap = None
     459        self.update_strength()
     460
    446461    def disconnect(self):
    447462        self._bus.remove_signal_receiver(self.__device_state_changed_cb,
    448463                                         signal_name='StateChanged',
    class WirelessNetworkView(CanvasPulsingIcon): 
    454469                                         dbus_interface=_NM_WIRELESS_IFACE)
    455470
    456471
     472class OlpcMeshView(CanvasPulsingIcon):
     473    def __init__(self, mesh_mgr, channel):
     474        CanvasPulsingIcon.__init__(self, icon_name=_OLPC_MESH_ICON_NAME,
     475                                   size=style.STANDARD_ICON_SIZE, cache=True)
     476        self._bus = dbus.SystemBus()
     477        self._channel = channel
     478        self._mesh_mgr = mesh_mgr
     479        self._disconnect_item = None
     480        self._connect_item = None
     481        self._greyed_out = False
     482        self._name = ''
     483        self._device_state = None
     484        self._connection = None
     485        self._active = False
     486        device = mesh_mgr.mesh_device
     487
     488        self.connect('button-release-event', self.__button_release_event_cb)
     489
     490        interface_props = dbus.Interface(device,
     491                                         'org.freedesktop.DBus.Properties')
     492        interface_props.Get(_NM_DEVICE_IFACE, 'State',
     493                            reply_handler=self.__get_device_state_reply_cb,
     494                            error_handler=self.__get_device_state_error_cb)
     495        interface_props.Get(_NM_OLPC_MESH_IFACE, 'ActiveChannel',
     496                            reply_handler=self.__get_active_channel_reply_cb,
     497                            error_handler=self.__get_active_channel_error_cb)
     498
     499        self._bus.add_signal_receiver(self.__device_state_changed_cb,
     500                                      signal_name='StateChanged',
     501                                      path=device.object_path,
     502                                      dbus_interface=_NM_DEVICE_IFACE)
     503        self._bus.add_signal_receiver(self.__wireless_properties_changed_cb,
     504                                      signal_name='PropertiesChanged',
     505                                      path=device.object_path,
     506                                      dbus_interface=_NM_OLPC_MESH_IFACE)
     507
     508        pulse_color = XoColor('%s,%s' % (style.COLOR_BUTTON_GREY.get_svg(),
     509                                         style.COLOR_TRANSPARENT.get_svg()))
     510        self.props.pulse_color = pulse_color
     511        self.props.base_color = profile.get_color()
     512        self._palette = self._create_palette()
     513        self.set_palette(self._palette)
     514
     515    def _create_palette(self):
     516        _palette = palette.Palette(_("Mesh Network %d") % self._channel)
     517
     518        self._connect_item = MenuItem(_('Connect'), 'dialog-ok')
     519        self._connect_item.connect('activate', self.__connect_activate_cb)
     520        _palette.menu.append(self._connect_item)
     521
     522        return _palette
     523
     524    def __get_device_state_reply_cb(self, state):
     525        self._device_state = state
     526        self._update()
     527
     528    def __get_device_state_error_cb(self, err):
     529        logging.error('Error getting the device state: %s', err)
     530
     531    def __device_state_changed_cb(self, new_state, old_state, reason):
     532        self._device_state = new_state
     533        self._update()
     534
     535    def __get_active_channel_reply_cb(self, channel):
     536        self._active = (channel == self._channel)
     537        self._update()
     538
     539    def __get_active_channel_error_cb(self, err):
     540        logging.error('Error getting the active channel: %s', err)
     541
     542    def __wireless_properties_changed_cb(self, properties):
     543        if 'ActiveChannel' in properties:
     544            channel = properties['ActiveChannel']
     545            self._active = (channel == self._channel)
     546            self._update()
     547
     548    def _update(self):
     549        if self._active:
     550            state = self._device_state
     551        else:
     552            state = network.DEVICE_STATE_UNKNOWN
     553
     554        if state in [network.DEVICE_STATE_PREPARE,
     555                     network.DEVICE_STATE_CONFIG,
     556                     network.DEVICE_STATE_NEED_AUTH,
     557                     network.DEVICE_STATE_IP_CONFIG]:
     558            if self._disconnect_item:
     559                self._disconnect_item.show()
     560            self._connect_item.hide()
     561            self._palette.props.secondary_text = _('Connecting...')
     562            self.props.pulsing = True
     563        elif state == network.DEVICE_STATE_ACTIVATED:
     564            if self._disconnect_item:
     565                self._disconnect_item.show()
     566            self._connect_item.hide()
     567            self._palette.props.secondary_text = _('Connected')
     568            self.props.pulsing = False
     569        else:
     570            if self._disconnect_item:
     571                self._disconnect_item.hide()
     572            self._connect_item.show()
     573            self._palette.props.secondary_text = None
     574            self.props.pulsing = False
     575
     576    def _update_color(self):
     577        if self._greyed_out:
     578            self.props.base_color = XoColor('#D5D5D5,#D5D5D5')
     579        else:
     580            self.props.base_color = profile.get_color()
     581
     582    def __connect_activate_cb(self, icon):
     583        self._connect()
     584
     585    def __button_release_event_cb(self, icon, event):
     586        self._connect()
     587
     588    def _connect(self):
     589        self._mesh_mgr.user_activate_channel(self._channel)
     590
     591    def __activate_reply_cb(self, connection):
     592        logging.debug('Connection activated: %s', connection)
     593
     594    def __activate_error_cb(self, err):
     595        logging.error('Failed to activate connection: %s', err)
     596
     597    def set_filter(self, query):
     598        self._greyed_out = (query != '')
     599        self._update_color()
     600
     601    def disconnect(self):
     602        self._bus.remove_signal_receiver(self.__device_state_changed_cb,
     603                                         signal_name='StateChanged',
     604                                         path=self._device.object_path,
     605                                         dbus_interface=_NM_DEVICE_IFACE)
     606        self._bus.remove_signal_receiver(self.__wireless_properties_changed_cb,
     607                                         signal_name='PropertiesChanged',
     608                                         path=self._device.object_path,
     609                                         dbus_interface=_NM_OLPC_MESH_IFACE)
     610
     611
    457612class ActivityView(hippo.CanvasBox):
    458613    def __init__(self, model):
    459614        hippo.CanvasBox.__init__(self)
    class NetworkManagerObserver(object): 
    752907        device_type = props.Get(_NM_DEVICE_IFACE, 'DeviceType')
    753908        if device_type == network.DEVICE_TYPE_802_11_WIRELESS:
    754909            self._devices[device_o] = DeviceObserver(self._box, device)
     910        elif device_type == network.DEVICE_TYPE_802_11_OLPC_MESH:
     911            self._box.enable_olpc_mesh(device)
    755912
    756913    def _get_device_path_error_cb(self, err):
    757914        logging.error('Failed to get device type: %s', err)
    class NetworkManagerObserver(object): 
    764921            observer = self._devices[device_o]
    765922            observer.disconnect()
    766923            del self._devices[device_o]
     924            return
     925
     926        device = self._bus.get_object(_NM_SERVICE, device_o)
     927        props = dbus.Interface(device, 'org.freedesktop.DBus.Properties')
     928        device_type = props.Get(_NM_DEVICE_IFACE, 'DeviceType')
     929        if device_type == network.DEVICE_TYPE_802_11_OLPC_MESH:
     930            self._box.disable_olpc_mesh(device)
    767931
    768932
    769933class MeshBox(gtk.VBox):
    class MeshBox(gtk.VBox): 
    779943        self._model = neighborhood.get_model()
    780944        self._buddies = {}
    781945        self._activities = {}
    782         self._mesh = {}
     946        self._mesh = []
    783947        self._buddy_to_activity = {}
    784948        self._suspended = True
    785949        self._query = ''
    class MeshBox(gtk.VBox): 
    9241088            del self.wireless_networks[hash]
    9251089 
    9261090    def _ap_props_changed_cb(self, ap, old_hash):
     1091        # if we have mesh hardware, ignore OLPC mesh networks that appear as
     1092        # normal wifi networks
     1093        if len(self._mesh) > 0 and ap.mode == network.NM_802_11_MODE_ADHOC \
     1094                and ap.name == "olpc-mesh":
     1095            logging.debug("ignoring OLPC mesh IBSS")
     1096            ap.disconnect()
     1097            return
     1098
    9271099        if old_hash is None: # new AP finished initializing
    9281100            self._add_ap_to_network(ap)
    9291101            return
    class MeshBox(gtk.VBox): 
    9581130            self._remove_net_if_empty(net, ap.network_hash())
    9591131            return
    9601132
    961         logging.error('Can not remove access point %s', ap_o)
     1133        # it's not an error if the AP isn't found, since we might have ignored
     1134        # it (e.g. olpc-mesh adhoc network)
     1135        logging.debug('Can not remove access point %s' % ap_o)
     1136
     1137    def _add_olpc_mesh_icon(self, mesh_mgr, channel):
     1138        icon = OlpcMeshView(mesh_mgr, channel)
     1139        self._layout.add(icon)
     1140        self._mesh.append(icon)
     1141
     1142    def enable_olpc_mesh(self, mesh_device):
     1143        mesh_mgr = OlpcMeshManager(mesh_device)
     1144        self._add_olpc_mesh_icon(mesh_mgr, 1)
     1145        self._add_olpc_mesh_icon(mesh_mgr, 6)
     1146        self._add_olpc_mesh_icon(mesh_mgr, 11)
     1147
     1148        # the OLPC mesh can be recognised as a "normal" wifi network. remove
     1149        # any such normal networks if they have been created
     1150        for hash, net in self.wireless_networks.iteritems():
     1151            if not net.is_olpc_mesh():
     1152                continue
     1153
     1154            logging.debug("removing OLPC mesh IBSS")
     1155            net.remove_all_aps()
     1156            net.disconnect()
     1157            self._layout.remove(net)
     1158            del self.wireless_networks[hash]
     1159
     1160    def disable_olpc_mesh(self, mesh_device):
     1161        for icon in self._mesh:
     1162            icon.disconnect()
     1163            self._layout.remove(icon)
     1164        self._mesh = []
    9621165
    9631166    def suspend(self):
    9641167        if not self._suspended:
    9651168            self._suspended = True
    966             for net in self.wireless_networks.values():
     1169            for net in self.wireless_networks.values() + self._mesh:
    9671170                net.props.paused = True
    9681171
    9691172    def resume(self):
    9701173        if self._suspended:
    9711174            self._suspended = False
    972             for net in self.wireless_networks.values():
     1175            for net in self.wireless_networks.values() + self._mesh:
    9731176                net.props.paused = False
    9741177
    9751178    def _toolbar_query_changed_cb(self, toolbar, query):
  • src/jarabe/model/Makefile.am

    diff --git a/src/jarabe/model/Makefile.am b/src/jarabe/model/Makefile.am
    index 399db65..18d44da 100644
    a b sugar_PYTHON = \ 
    66        filetransfer.py         \
    77        friends.py              \
    88        invites.py              \
     9        olpcmesh.py             \
    910        owner.py                \
    1011        neighborhood.py         \
    1112        network.py              \
  • src/jarabe/model/network.py

    diff --git a/src/jarabe/model/network.py b/src/jarabe/model/network.py
    index 9de954a..4389b87 100644
    a b from sugar.util import unique_id 
    3333DEVICE_TYPE_802_3_ETHERNET = 1
    3434DEVICE_TYPE_802_11_WIRELESS = 2
    3535DEVICE_TYPE_GSM_MODEM = 3
     36DEVICE_TYPE_802_11_OLPC_MESH = 6
    3637
    3738DEVICE_STATE_UNKNOWN = 0
    3839DEVICE_STATE_UNMANAGED = 1
    class WirelessSecurity(object): 
    117118        return wireless_security
    118119
    119120class Wireless(object):
     121    nm_name = "802-11-wireless"
     122
    120123    def __init__(self):
    121124        self.ssid = None
    122125        self.security = None
    class Wireless(object): 
    133136            wireless['band'] = self.band
    134137        return wireless
    135138
     139class OlpcMesh(object):
     140    nm_name = "802-11-olpc-mesh"
     141
     142    def __init__(self, channel, anycast_addr):
     143        self.channel = channel
     144        self.anycast_addr = anycast_addr
     145
     146    def get_dict(self):
     147        ret = {
     148            "ssid": dbus.ByteArray("olpc-mesh"),
     149            "channel": self.channel,
     150        }
     151
     152        if self.anycast_addr:
     153            ret["dhcp-anycast-address"] = dbus.ByteArray(self.anycast_addr)
     154        return ret
     155
    136156class Connection(object):
    137157    def __init__(self):
    138158        self.id = None
    class Gsm(object): 
    199219        return gsm
    200220
    201221class Settings(object):
    202     def __init__(self):
     222    def __init__(self, wireless_cfg=None):
    203223        self.connection = Connection()
    204224        self.wireless = Wireless()
    205225        self.ip4_config = None
    206226        self.wireless_security = None
    207227
     228        if wireless_cfg is not None:
     229            self.wireless = wireless_cfg
     230        else:
     231            self.wireless = Wireless()
     232
    208233    def get_dict(self):
    209234        settings = {}
    210235        settings['connection'] = self.connection.get_dict()
    211         settings['802-11-wireless'] = self.wireless.get_dict()
     236        settings[self.wireless.nm_name] = self.wireless.get_dict()
    212237        if self.wireless_security is not None:
    213238            settings['802-11-wireless-security'] = \
    214239                self.wireless_security.get_dict()