def connected_timeout(dummy: int) -> None: active_ssid: Optional[str] active_ssid = nm.get_active_ssid(modemgr.get_state_device("CONNECTED")) log.debug("connected_timeout comparing {} to {}".format( connection, active_ssid)) if connection != active_ssid: log.warning("Connection lost on timeout") dev = modemgr.get_state_device("CONNECTED") set_state("CONNECTING", candidate_connections(dev)) if modemgr.get_mode() == modemgr.MULTI_MODE: wpa.check_wpa(modemgr.get_ap_device().Interface) active_ssid = nm.get_active_ssid(modemgr.get_state_device("HOTSPOT")) if not active_ssid: log.warning("Hotspot lost on timeout") set_state("HOTSPOT") defroute_devname: Optional[str] = routemgr.defroute_dev() ap_dev: NetworkManager.Device = modemgr.get_ap_device() link_dev: NetworkManager.Device = modemgr.get_link_device() if defroute_devname == nm.device_name(ap_dev): # default route is bad. Disconnect link and count on state # processing to restore log.error("AP is holding default route while CONNECTED, kicking") nm.disconnect(link_dev)
def connected_timeout(): log.debug("states: Calling nm.get_active_ssid()") if connection != nm.get_active_ssid(modemgr.get_state_device('CONNECTED')): log.warning("Connection lost on timeout") set_state('HOTSPOT') if modemgr.get_mode() == modemgr.MULTI_MODE: wpa.check_wpa(modemgr.get_ap_device().Interface)
def hotspot_pass(reason: int) -> None: global startup dev: NetworkManager.Device = modemgr.get_state_device("CONNECTED") conn_list = candidate_connections(dev) active_ssid = nm.get_active_ssid(modemgr.get_state_device("CONNECTED")) if startup or active_ssid in conn_list: set_state("CONNECTING", conn_list) startup = False
def connected_fail(reason: int) -> None: global startup log.warning("Connection lost") active_ssid: Optional[str] active_ssid = nm.get_active_ssid(modemgr.get_state_device("HOTSPOT")) if modemgr.get_mode() == modemgr.MULTI_MODE and not active_ssid: log.warning("Hotspot lost while CONNECTED") set_state("HOTSPOT") else: startup = True set_state("HOTSPOT")
def hotspot_start(): global conn_list log.info("Activating hotspot") hs_ssid = dns_to_conn(dns_names[0]) log.debug("states: Calling nm.get_active_ssid()") if hs_ssid != nm.get_active_ssid(modemgr.get_state_device('HOTSPOT')): conn_list = [] activate_connection(hs_ssid, 'HOTSPOT') else: log.debug("Didn't need to reactivate - already running") # the connect callback won't happen - let's 'pass' manually timeout_add(100, fake_hs_pass, state_id)
def is_connected(ssid): import NetworkManager from importlib import reload from comitup import nm try: # this is super weird because the NetworkManager definitions is based of dynamically-loaded dbus information. # this means that if NetworkManager is down (which it should be while it restarts), GetDevices() doesn't exist., # so we try to acccess it, then if we hit an AttributeError, reload the networkmanager and try again devices = NetworkManager.NetworkManager.GetDevices() return any( nm.get_active_ssid(device) == ssid for device in NetworkManager.NetworkManager.GetDevices()) except NetworkManager.ObjectVanished: return False except AttributeError: reload(NetworkManager) return False
def connecting_start(dummy: int) -> None: global conn_list, connection dev = modemgr.get_state_device("CONNECTED") full_conn_list = candidate_connections(dev) active_ssid = nm.get_active_ssid(modemgr.get_state_device("CONNECTED")) if active_ssid in full_conn_list: log.debug("Didn't need to connect - already connected") connection = active_ssid # the connect callback won't happen - let's 'pass' manually timeout_add(100, fake_cg_pass, state_id) else: if conn_list: log.debug("states: Calling nm.disconnect()") nm.disconnect(modemgr.get_state_device("CONNECTING")) conn = conn_list.pop(0) log.info("Attempting connection to %s" % conn) activate_connection(conn, "CONNECTING") else: set_state("HOTSPOT")
def hotspot_start(dummy: int) -> None: global conn_list log.info("Activating hotspot") if startup: mdns.clear_entries() mdns.add_hosts(dns_names) hs_ssid: str = dns_to_conn(dns_names[0]) if startup and modemgr.get_mode() == modemgr.SINGLE_MODE: log.debug("Passing on hotspot connection for now") timeout_add(100, fake_hs_pass, state_id) elif hs_ssid != nm.get_active_ssid(modemgr.get_state_device("HOTSPOT")): conn_list = [] log.debug("Activating connection {}".format(hs_ssid)) activate_connection(hs_ssid, "HOTSPOT") else: log.debug("Didn't need to reactivate - already running") # the connect callback won't happen - let's 'pass' manually timeout_add(100, fake_hs_pass, state_id)
def hotspot_start(): global conn_list log.info("Activating hotspot") hs_ssid = dns_to_conn(dns_names[0]) # if we are in two-wifi device mode, skip the reconnect if possible, # to avoid kicking some clients off log.debug("states: Calling nm.get_active_ssid()") if hs_ssid != nm.get_active_ssid(modemgr.get_state_device('HOTSPOT')): mdns.clear_entries() conn_list = [] # tolerate Raspberry Pi 2 try: activate_connection(hs_ssid, 'HOTSPOT') except DBusException: log.warn("Error connecting hotspot") else: log.debug("Didn't need to reactivate - already running") # the connect callback won't happen - let's 'pass' manually timeout_add(100, fake_hs_pass)
def test_get_active_ssid(device_fxt): assert nm.get_active_ssid(nm.get_wifi_device()) == "myssid"
def test_no_active_ssid(device_no_conn_fxt): assert nm.get_active_ssid(nm.get_wifi_device()) is None
def to_fn(): ssid = nm.get_active_ssid(modemgr.get_link_device()) nm.del_connection_by_ssid(ssid) states.set_state('HOTSPOT') return False
def test_get_active_ssid(device_fxt): assert nm.get_active_ssid() == "myssid"
def test_no_active_ssid(device_no_conn_fxt): assert nm.get_active_ssid() is None
def delete_connection(self): ssid = nm.get_active_ssid(modemgr.get_link_device()) nm.del_connection_by_ssid(ssid) states.set_state('HOTSPOT')
def connected_timeout(): log.debug("states: Calling nm.get_active_ssid()") if connection != nm.get_active_ssid(modemgr.get_state_device('CONNECTED')): log.warn("Connection lost on timeout") set_state('HOTSPOT')