예제 #1
0
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)
예제 #2
0
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)
예제 #3
0
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
예제 #4
0
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")
예제 #5
0
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)
예제 #6
0
        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
예제 #7
0
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")
예제 #8
0
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)
예제 #9
0
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)
예제 #10
0
파일: test_nm.py 프로젝트: ds1019/comitup
def test_get_active_ssid(device_fxt):
    assert nm.get_active_ssid(nm.get_wifi_device()) == "myssid"
예제 #11
0
파일: test_nm.py 프로젝트: ds1019/comitup
def test_no_active_ssid(device_no_conn_fxt):
    assert nm.get_active_ssid(nm.get_wifi_device()) is None
예제 #12
0
 def to_fn():
     ssid = nm.get_active_ssid(modemgr.get_link_device())
     nm.del_connection_by_ssid(ssid)
     states.set_state('HOTSPOT')
     return False
예제 #13
0
def test_get_active_ssid(device_fxt):
    assert nm.get_active_ssid() == "myssid"
예제 #14
0
def test_no_active_ssid(device_no_conn_fxt):
    assert nm.get_active_ssid() is None
예제 #15
0
파일: statemgr.py 프로젝트: krebbi/comitup
 def delete_connection(self):
     ssid = nm.get_active_ssid(modemgr.get_link_device())
     nm.del_connection_by_ssid(ssid)
     states.set_state('HOTSPOT')
예제 #16
0
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')