|
| 1 | +#!/usr/bin/env python3 |
| 2 | +r""" |
| 3 | +WiFi station set up from a scan-only interface |
| 4 | +
|
| 5 | +A WiFi interface with only a radio, no station or access point, is in |
| 6 | +scan-only mode. That is how the factory configuration of boards with a |
| 7 | +built-in radio ships, so the usual way to get online is to add the station |
| 8 | +settings to that existing interface. The connection has to come up from |
| 9 | +that change alone, without a reboot or a service restart. |
| 10 | +
|
| 11 | +Topology: |
| 12 | +.... |
| 13 | + host ==(mgmt)== ap ))) ~ cell ~ ((( station ==(mgmt)== host |
| 14 | +.... |
| 15 | +""" |
| 16 | +import infamy |
| 17 | +import infamy.iface as iface |
| 18 | +import infamy.wifi as wifi |
| 19 | +from infamy.util import until, parallel |
| 20 | + |
| 21 | +SSID = "infix-scan" |
| 22 | +PSK = "infixinfix" |
| 23 | + |
| 24 | +SUBNET = "192.168.21.0/24" |
| 25 | +AP_IP = "192.168.21.1" |
| 26 | +LEASE = "192.168.21.100" |
| 27 | + |
| 28 | + |
| 29 | +with infamy.Test() as test: |
| 30 | + with test.step("Set up topology and attach to the ap and the station"): |
| 31 | + env = infamy.Env() |
| 32 | + ap, station = parallel( |
| 33 | + lambda: env.attach("ap", "mgmt"), |
| 34 | + lambda: env.attach("station", "mgmt"), |
| 35 | + ) |
| 36 | + wifi.skip_unless_supported(test, ap, station) |
| 37 | + |
| 38 | + with test.step("Configure the ap with access point 'infix-scan' and a DHCP server on 192.168.21.1"): |
| 39 | + ap.put_config_dicts({ |
| 40 | + "ietf-hardware": {"hardware": {"component": [ |
| 41 | + wifi.radio("radio0", band="2.4GHz", channel=1)]}}, |
| 42 | + "ietf-keystore": wifi.keystore({"wifi": PSK}), |
| 43 | + "ietf-interfaces": {"interfaces": {"interface": [ |
| 44 | + wifi.iface("wifi0", "02:00:00:00:00:01", { |
| 45 | + "radio": "radio0", |
| 46 | + "access-point": { |
| 47 | + "ssid": SSID, |
| 48 | + "security": {"mode": "wpa2-wpa3-personal", "secret": "wifi"}, |
| 49 | + }, |
| 50 | + }, ipv4={"address": [{"ip": AP_IP, "prefix-length": 24}]}), |
| 51 | + ]}}, |
| 52 | + "infix-dhcp-server": {"dhcp-server": {"subnet": [{ |
| 53 | + "subnet": SUBNET, |
| 54 | + "pool": {"start-address": LEASE, "end-address": LEASE}, |
| 55 | + }]}}, |
| 56 | + }) |
| 57 | + |
| 58 | + with test.step("Configure wifi0 on the station with only radio0, scan-only mode"): |
| 59 | + station.put_config_dicts({ |
| 60 | + "ietf-hardware": {"hardware": {"component": [wifi.radio("radio0")]}}, |
| 61 | + "ietf-interfaces": {"interfaces": {"interface": [ |
| 62 | + wifi.iface("wifi0", "02:00:00:00:00:02", {"radio": "radio0"}, |
| 63 | + ipv4={"infix-dhcp-client:dhcp": {}}), |
| 64 | + ]}}, |
| 65 | + }) |
| 66 | + |
| 67 | + with test.step("Verify the station sees 'infix-scan' in its scan results"): |
| 68 | + until(lambda: SSID in {n.get("ssid") for n in |
| 69 | + wifi.station(station).get("scan-results") or []}, |
| 70 | + attempts=60, interval=2) |
| 71 | + |
| 72 | + with test.step("Add station settings for 'infix-scan' to wifi0 on the station"): |
| 73 | + station.put_config_dicts({ |
| 74 | + "ietf-keystore": wifi.keystore({"wifi": PSK}), |
| 75 | + "ietf-interfaces": {"interfaces": {"interface": [ |
| 76 | + {"name": "wifi0", "infix-interfaces:wifi": { |
| 77 | + "radio": "radio0", |
| 78 | + "station": { |
| 79 | + "ssid": SSID, |
| 80 | + "security": {"mode": "auto", "secret": "wifi"}, |
| 81 | + }, |
| 82 | + }}, |
| 83 | + ]}}, |
| 84 | + }) |
| 85 | + |
| 86 | + with test.step("Verify the station associates to 'infix-scan' without a restart"): |
| 87 | + until(lambda: wifi.associated(station, SSID), attempts=60, interval=2) |
| 88 | + |
| 89 | + with test.step("Verify the station leases 192.168.21.100 over wifi"): |
| 90 | + until(lambda: iface.address_exist(station, "wifi0", LEASE), |
| 91 | + attempts=60, interval=2) |
| 92 | + |
| 93 | + test.succeed() |
0 commit comments