示例#1
0
def test_discovery_long_listen(dev):
    """Long P2P_LISTEN and offchannel TX"""
    addr0 = dev[0].p2p_dev_addr()
    dev[0].p2p_listen()

    wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
    wpas.interface_add("wlan5")
    addr = wpas.p2p_dev_addr()
    if not wpas.discover_peer(addr0):
        raise Exception("Device discovery timed out")
    peer = wpas.get_peer(addr0)
    chan = '1' if peer['listen_freq'] == '2462' else '11'

    wpas.request("P2P_SET listen_channel " + chan)
    wpas.request("P2P_LISTEN 10")
    if not dev[0].discover_peer(addr):
        raise Exception("Device discovery timed out (2)")

    time.sleep(0.1)
    wpas.global_request("P2P_PROV_DISC " + addr0 + " display")
    ev = dev[0].wait_global_event(["P2P-PROV-DISC-SHOW-PIN"], timeout=15)
    if ev is None:
        raise Exception("Provision discovery timed out")
    dev[0].p2p_stop_find()

    # Verify that the long listen period is still continuing after off-channel
    # TX of Provision Discovery frames.
    if not dev[1].discover_peer(addr):
        raise Exception("Device discovery timed out (3)")

    dev[1].p2p_stop_find()
    wpas.p2p_stop_find()
示例#2
0
def test_discovery_long_listen(dev):
    """Long P2P_LISTEN and offchannel TX"""
    addr0 = dev[0].p2p_dev_addr()
    dev[0].p2p_listen()

    wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
    wpas.interface_add("wlan5")
    addr = wpas.p2p_dev_addr()
    if not wpas.discover_peer(addr0):
        raise Exception("Device discovery timed out")
    peer = wpas.get_peer(addr0)
    chan = '1' if peer['listen_freq'] == '2462' else '11'

    wpas.request("P2P_SET listen_channel " + chan)
    wpas.request("P2P_LISTEN 10")
    if not dev[0].discover_peer(addr):
        raise Exception("Device discovery timed out (2)")

    time.sleep(0.1)
    wpas.global_request("P2P_PROV_DISC " + addr0 + " display")
    ev = dev[0].wait_global_event(["P2P-PROV-DISC-SHOW-PIN"], timeout=15)
    if ev is None:
        raise Exception("Provision discovery timed out")
    dev[0].p2p_stop_find()

    # Verify that the long listen period is still continuing after off-channel
    # TX of Provision Discovery frames.
    if not dev[1].discover_peer(addr):
        raise Exception("Device discovery timed out (3)")

    dev[1].p2p_stop_find()
    wpas.p2p_stop_find()
示例#3
0
def test_p2p_device_grpform_timeout_go(dev, apdev):
    """P2P group formation timeout on GO with cfg80211 P2P Device"""
    with HWSimRadio(use_p2p_device=True) as (radio, iface):
        wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
        wpas.interface_add(iface)
        addr0 = dev[0].p2p_dev_addr()
        addr5 = wpas.p2p_dev_addr()
        wpas.p2p_listen()
        dev[0].discover_peer(addr5)
        dev[0].p2p_listen()
        wpas.discover_peer(addr0)
        wpas.p2p_ext_listen(100, 150)
        dev[0].global_request("P2P_CONNECT " + addr5 +
                              " 12345670 enter go_intent=0 auth")
        wpas.global_request("P2P_CONNECT " + addr0 +
                            " 12345670 display go_intent=15")
        ev = dev[0].wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout=5)
        if ev is None:
            raise Exception("GO Negotiation did not succeed")
        ev = dev[0].wait_global_event(["WPS-SUCCESS"], timeout=10)
        if ev is None:
            raise Exception("WPS did not succeed (Client)")
        if "OK" not in dev[0].global_request("P2P_CANCEL"):
            if "OK" not in dev[0].global_request("P2P_GROUP_REMOVE *"):
                wpas.global_request("P2P_CANCEL")
                del wpas
                raise HwsimSkip("Did not manage to cancel group formation")
        dev[0].dump_monitor()
        ev = wpas.wait_global_event(["WPS-SUCCESS"], timeout=10)
        if ev is None:
            raise Exception("WPS did not succeed (GO)")
        dev[0].dump_monitor()
        ev = wpas.wait_global_event(["P2P-GROUP-FORMATION-FAILURE"],
                                    timeout=20)
        if ev is None:
            raise Exception("Group formation timeout not seen on GO")
        ev = wpas.wait_global_event(["P2P-GROUP-REMOVED"], timeout=5)
        if ev is None:
            raise Exception("Group removal not seen on GO")
        wpas.p2p_cancel_ext_listen()
        time.sleep(0.1)
        ifaces = wpas.global_request("INTERFACES")
        logger.info("Remaining interfaces: " + ifaces)
        del wpas
        if "p2p-" + iface + "-" in ifaces:
            raise Exception("Group interface still present after failure")
def test_p2p_device_grpform_timeout_go(dev, apdev):
    """P2P group formation timeout on GO with cfg80211 P2P Device"""
    with HWSimRadio(use_p2p_device=True) as (radio, iface):
        wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
        wpas.interface_add(iface)
        addr0 = dev[0].p2p_dev_addr()
        addr5 = wpas.p2p_dev_addr()
        wpas.p2p_listen()
        dev[0].discover_peer(addr5)
        dev[0].p2p_listen()
        wpas.discover_peer(addr0)
        wpas.p2p_ext_listen(100, 150)
        dev[0].global_request("P2P_CONNECT " + addr5 + " 12345670 enter go_intent=0 auth")
        wpas.global_request("P2P_CONNECT " + addr0 + " 12345670 display go_intent=15")
        ev = dev[0].wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout=5)
        if ev is None:
            raise Exception("GO Negotiation did not succeed")
        ev = dev[0].wait_global_event(["WPS-SUCCESS"], timeout=10)
        if ev is None:
            raise Exception("WPS did not succeed (Client)")
        if "OK" not in dev[0].global_request("P2P_CANCEL"):
            if "OK" not in dev[0].global_request("P2P_GROUP_REMOVE *"):
                wpas.global_request("P2P_CANCEL")
                del wpas
                raise HwsimSkip("Did not manage to cancel group formation")
        dev[0].dump_monitor()
        ev = wpas.wait_global_event(["WPS-SUCCESS"], timeout=10)
        if ev is None:
            raise Exception("WPS did not succeed (GO)")
        dev[0].dump_monitor()
        ev = wpas.wait_global_event(["P2P-GROUP-FORMATION-FAILURE"], timeout=20)
        if ev is None:
            raise Exception("Group formation timeout not seen on GO")
        ev = wpas.wait_global_event(["P2P-GROUP-REMOVED"], timeout=5)
        if ev is None:
            raise Exception("Group removal not seen on GO")
        wpas.p2p_cancel_ext_listen()
        time.sleep(0.1)
        ifaces = wpas.global_request("INTERFACES")
        logger.info("Remaining interfaces: " + ifaces)
        del wpas
        if "p2p-" + iface + "-" in ifaces:
            raise Exception("Group interface still present after failure")
示例#5
0
def _test_grpform_ext_listen_oper(dev):
    addr0 = dev[0].p2p_dev_addr()
    dev[0].global_request("SET p2p_no_group_iface 0")
    wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
    wpas.interface_add("wlan5")
    addr1 = wpas.p2p_dev_addr()
    wpas.request("P2P_SET listen_channel 1")
    wpas.global_request("SET p2p_no_group_iface 0")
    wpas.request("P2P_LISTEN")
    if not dev[0].discover_peer(addr1):
        raise Exception("Could not discover peer")
    dev[0].request("P2P_LISTEN")
    if not wpas.discover_peer(addr0):
        raise Exception("Could not discover peer (2)")

    dev[0].global_request("P2P_EXT_LISTEN 300 500")
    dev[0].global_request("P2P_CONNECT " + addr1 +
                          " 12345670 display auth go_intent=0 freq=2417")
    wpas.global_request("P2P_CONNECT " + addr0 +
                        " 12345670 enter go_intent=15 freq=2417")
    ev = dev[0].wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout=15)
    if ev is None:
        raise Exception("GO Negotiation failed")
    ifaces = wpas.request("INTERFACES").splitlines()
    iface = ifaces[0] if "p2p-wlan" in ifaces[0] else ifaces[1]
    wpas.group_ifname = iface
    if "OK" not in wpas.group_request("STOP_AP"):
        raise Exception("STOP_AP failed")
    wpas.group_request("SET ext_mgmt_frame_handling 1")
    dev[1].p2p_find(social=True)
    time.sleep(1)
    if dev[1].peer_known(addr0):
        raise Exception("Unexpected peer discovery")
    ifaces = dev[0].request("INTERFACES").splitlines()
    iface = ifaces[0] if "p2p-wlan" in ifaces[0] else ifaces[1]
    if "OK" not in dev[0].global_request("P2P_GROUP_REMOVE " + iface):
        raise Exception("Failed to request group removal")
    wpas.remove_group()

    count = 0
    timeout = 15
    found = False
    while count < timeout * 4:
        time.sleep(0.25)
        count = count + 1
        if dev[1].peer_known(addr0):
            found = True
            break
    dev[1].p2p_stop_find()
    if not found:
        raise Exception(
            "Could not discover peer that was supposed to use extended listen")
示例#6
0
def _test_grpform_ext_listen_oper(dev):
    addr0 = dev[0].p2p_dev_addr()
    dev[0].global_request("SET p2p_no_group_iface 0")
    wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
    wpas.interface_add("wlan5")
    addr1 = wpas.p2p_dev_addr()
    wpas.request("P2P_SET listen_channel 1")
    wpas.global_request("SET p2p_no_group_iface 0")
    wpas.request("P2P_LISTEN")
    if not dev[0].discover_peer(addr1):
        raise Exception("Could not discover peer")
    dev[0].request("P2P_LISTEN")
    if not wpas.discover_peer(addr0):
        raise Exception("Could not discover peer (2)")

    dev[0].global_request("P2P_EXT_LISTEN 300 500")
    dev[0].global_request("P2P_CONNECT " + addr1 + " 12345670 display auth go_intent=0 freq=2417")
    wpas.global_request("P2P_CONNECT " + addr0 + " 12345670 enter go_intent=15 freq=2417")
    ev = dev[0].wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout=15)
    if ev is None:
        raise Exception("GO Negotiation failed")
    ifaces = wpas.request("INTERFACES").splitlines()
    iface = ifaces[0] if "p2p-wlan" in ifaces[0] else ifaces[1]
    wpas.group_ifname = iface
    if "OK" not in wpas.group_request("STOP_AP"):
        raise Exception("STOP_AP failed")
    wpas.group_request("SET ext_mgmt_frame_handling 1")
    dev[1].p2p_find(social=True)
    time.sleep(1)
    if dev[1].peer_known(addr0):
        raise Exception("Unexpected peer discovery")
    ifaces = dev[0].request("INTERFACES").splitlines()
    iface = ifaces[0] if "p2p-wlan" in ifaces[0] else ifaces[1]
    if "OK" not in dev[0].global_request("P2P_GROUP_REMOVE " + iface):
        raise Exception("Failed to request group removal")
    wpas.remove_group()

    count = 0
    timeout = 15
    found = False
    while count < timeout * 4:
        time.sleep(0.25)
        count = count + 1
        if dev[1].peer_known(addr0):
            found = True
            break
    dev[1].p2p_stop_find()
    if not found:
        raise Exception("Could not discover peer that was supposed to use extended listen")
示例#7
0
def test_p2p_delay_go_csa(dev, apdev, params):
    """P2P GO CSA delayed when inviting a P2P Device to an active P2P Group"""
    with HWSimRadio(n_channels=2) as (radio, iface):
        wpas = WpaSupplicant(global_iface="/tmp/wpas-wlan5")
        wpas.interface_add(iface)

        wpas.global_request("SET p2p_no_group_iface 0")

        if wpas.get_mcc() < 2:
            raise Exception("New radio does not support MCC")

        addr0 = wpas.p2p_dev_addr()
        addr1 = dev[1].p2p_dev_addr()

        try:
            dev[1].p2p_listen()
            if not wpas.discover_peer(addr1, social=True):
                raise Exception("Peer " + addr1 + " not found")
            wpas.p2p_stop_find()

            hapd = hostapd.add_ap(apdev[0]["ifname"], {"ssid": "bss-2.4ghz", "channel": "1"})

            wpas.connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2412")

            wpas.global_request("SET p2p_go_freq_change_policy 0")
            wpas.dump_monitor()

            logger.info("Start GO on channel 6")
            res = autogo(wpas, freq=2437)
            if res["freq"] != "2437":
                raise Exception("GO set on a freq=%s instead of 2437" % res["freq"])

            # Start find on dev[1] to run scans with dev[2] in parallel
            dev[1].p2p_find(social=True)

            # Use another client device to stop the initial client connection
            # timeout on the GO
            if not dev[2].discover_peer(addr0, social=True):
                raise Exception("Peer2 did not find the GO")
            dev[2].p2p_stop_find()
            pin = dev[2].wps_read_pin()
            wpas.p2p_go_authorize_client(pin)
            dev[2].global_request("P2P_CONNECT " + addr0 + " " + pin + " join freq=2437")
            ev = dev[2].wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
            if ev is None:
                raise Exception("Peer2 did not get connected")

            if not dev[1].discover_peer(addr0, social=True):
                raise Exception("Peer did not find the GO")

            pin = dev[1].wps_read_pin()
            dev[1].global_request("P2P_CONNECT " + addr0 + " " + pin + " join auth")
            dev[1].p2p_listen()

            # Force P2P GO channel switch on successful invitation signaling
            wpas.group_request("SET p2p_go_csa_on_inv 1")

            logger.info("Starting invitation")
            wpas.p2p_go_authorize_client(pin)
            wpas.global_request("P2P_INVITE group=" + wpas.group_ifname + " peer=" + addr1)
            ev = dev[1].wait_global_event(["P2P-INVITATION-RECEIVED", "P2P-GROUP-STARTED"], timeout=10)

            if ev is None:
                raise Exception("Timeout on invitation on peer")
            if "P2P-INVITATION-RECEIVED" in ev:
                raise Exception("Unexpected request to accept pre-authorized invitation")

            # A P2P GO move is not expected at this stage, as during the
            # invitation signaling, the P2P GO includes only its current
            # operating channel in the channel list, and as the invitation
            # response can only include channels that were also in the
            # invitation request channel list, the group common channels
            # includes only the current P2P GO operating channel.
            ev = wpas.wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP", "AP-CSA-FINISHED"], timeout=1)
            if ev is not None:
                raise Exception("Unexpected + " + ev + " event")

        finally:
            wpas.global_request("SET p2p_go_freq_change_policy 2")
示例#8
0
def test_p2p_delay_go_csa(dev, apdev, params):
    """P2P GO CSA delayed when inviting a P2P Device to an active P2P Group"""
    with HWSimRadio(n_channels=2) as (radio, iface):
        wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
        wpas.interface_add(iface)

        wpas.global_request("SET p2p_no_group_iface 0")

        if wpas.get_mcc() < 2:
            raise Exception("New radio does not support MCC")

        addr0 = wpas.p2p_dev_addr()
        addr1 = dev[1].p2p_dev_addr()

        try:
            dev[1].p2p_listen()
            if not wpas.discover_peer(addr1, social=True):
                raise Exception("Peer " + addr1 + " not found")
            wpas.p2p_stop_find()

            hapd = hostapd.add_ap(apdev[0]['ifname'], {
                "ssid": 'bss-2.4ghz',
                "channel": '1'
            })

            wpas.connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2412")

            wpas.global_request("SET p2p_go_freq_change_policy 0")
            wpas.dump_monitor()

            logger.info("Start GO on channel 6")
            res = autogo(wpas, freq=2437)
            if res['freq'] != "2437":
                raise Exception("GO set on a freq=%s instead of 2437" %
                                res['freq'])

            # Start find on dev[1] to run scans with dev[2] in parallel
            dev[1].p2p_find(social=True)

            # Use another client device to stop the initial client connection
            # timeout on the GO
            if not dev[2].discover_peer(addr0, social=True):
                raise Exception("Peer2 did not find the GO")
            dev[2].p2p_stop_find()
            pin = dev[2].wps_read_pin()
            wpas.p2p_go_authorize_client(pin)
            dev[2].global_request("P2P_CONNECT " + addr0 + " " + pin +
                                  " join freq=2437")
            ev = dev[2].wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
            if ev is None:
                raise Exception("Peer2 did not get connected")

            if not dev[1].discover_peer(addr0, social=True):
                raise Exception("Peer did not find the GO")

            pin = dev[1].wps_read_pin()
            dev[1].global_request("P2P_CONNECT " + addr0 + " " + pin +
                                  " join auth")
            dev[1].p2p_listen()

            # Force P2P GO channel switch on successful invitation signaling
            wpas.group_request("SET p2p_go_csa_on_inv 1")

            logger.info("Starting invitation")
            wpas.p2p_go_authorize_client(pin)
            wpas.global_request("P2P_INVITE group=" + wpas.group_ifname +
                                " peer=" + addr1)
            ev = dev[1].wait_global_event(
                ["P2P-INVITATION-RECEIVED", "P2P-GROUP-STARTED"], timeout=10)

            if ev is None:
                raise Exception("Timeout on invitation on peer")
            if "P2P-INVITATION-RECEIVED" in ev:
                raise Exception(
                    "Unexpected request to accept pre-authorized invitation")

            # A P2P GO move is not expected at this stage, as during the
            # invitation signaling, the P2P GO includes only its current
            # operating channel in the channel list, and as the invitation
            # response can only include channels that were also in the
            # invitation request channel list, the group common channels
            # includes only the current P2P GO operating channel.
            ev = wpas.wait_group_event(
                ["P2P-REMOVE-AND-REFORM-GROUP", "AP-CSA-FINISHED"], timeout=1)
            if ev is not None:
                raise Exception("Unexpected + " + ev + " event")

        finally:
            wpas.global_request("SET p2p_go_freq_change_policy 2")