Esempio n. 1
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)
Esempio n. 2
0
def init_states(hosts, callbacks):
    global hotspot_name

    nmmon.init_nmmon()
    set_hosts(*hosts)

    for callback in callbacks:
        add_state_callback(callback)

    hotspot_name = dns_to_conn(hosts[0])

    assure_hotspot(hotspot_name, modemgr.get_ap_device())
Esempio n. 3
0
def run_dns(confpath):
    log.debug("Running dnsmasq using {}".format(confpath))

    kill_dns(pidpath, signal.SIGTERM)

    dev = modemgr.get_ap_device().Interface

    cmd = "dnsmasq --conf-file={0} --interface={1}".format(confpath, dev)

    for _ in range(5):
        cp = subprocess.run(cmd.split())
        if cp.returncode == 0:
            break
        time.sleep(.1)
Esempio n. 4
0
def hotspot_timeout():
    if iwscan.ap_conn_count() == 0 or modemgr.get_mode() != 'single':
        log.debug('Periodic connection attempt')

        dev = modemgr.get_state_device('CONNECTED')
        conn_list = candidate_connections(dev)
        if conn_list:
            set_state('CONNECTING', conn_list)
        else:
            log.info('No candidates - skipping CONNECTING scan')
    else:
        log.info('AP active - skipping CONNECTING scan')

    wpa.check_wpa(modemgr.get_ap_device().Interface)
Esempio n. 5
0
def init_states(hosts, callbacks, hotspot_pw):
    global hotspot_name

    nmmon.init_nmmon()
    set_hosts(*hosts)

    for callback in callbacks:
        add_state_callback(callback)

    hotspot_name = dns_to_conn(hosts[0])
    assure_hotspot(hotspot_name, modemgr.get_ap_device())

    # Set an early kick to set CONNECTING mode
    set_state('HOTSPOT')
    timeout_add(5 * 1000, hotspot_timeout, state_id)
Esempio n. 6
0
def main():
    handler = logging.StreamHandler(stream=None)
    log.addHandler(handler)
    log.setLevel(logging.DEBUG)

    log.info('starting')

    init_nmmon()

    def up():
        print("wifi up")

    def down():
        print("wifi down")

    enable(modemgr.get_ap_device(), up, down)

    loop = MainLoop()
    loop.run()
Esempio n. 7
0
def init_nmmon():
    set_device_listeners(modemgr.get_ap_device(), modemgr.get_link_device())
Esempio n. 8
0
def run_cmds(cmds):
    linkdev = nm.device_name(modemgr.get_link_device())
    apdev = nm.device_name(modemgr.get_ap_device())
    for cmd in cmds:
        subprocess.call(cmd.format(link=linkdev, ap=apdev), shell=True)