Skip to contentSkip to conversation

ap: Drop unneeded broadcast address calculation

PATCH In review Andrew Zaborowski 2 participants 16 messages Jun 4, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/15 ap: Drop unneeded broadcast address calculation

It's already done in l_rtnl_address_new().

---
 src/ap.c | 19 -------------------
 1 file changed, 19 deletions(-)
src/ap.c +0 -19
index dc067352..f0a38bb6 100644
@@ -131,18 +131,6 @@ static char **global_addr4_strs;
 static uint32_t netdev_watch;
 static struct l_netlink *rtnl;
 
-static const char *broadcast_from_ip(const char *ip, uint8_t prefix_len)
-{
-	struct in_addr ia;
-	uint32_t netmask = util_netmask_from_prefix(prefix_len);
-
-	if (inet_aton(ip, &ia) != 1)
-		return NULL;
-
-	ia.s_addr |= htonl(~netmask);
-	return inet_ntoa(ia);
-}
-
 static void ap_stop_handshake(struct sta_state *sta)
 {
 	if (sta->sm) {
@@ -2444,13 +2432,6 @@ static int ap_setup_netconfig4(struct ap_state *ap, const char **addr_str_list,
 		}
 
 		new_addr = l_rtnl_address_new(addr_str_buf, prefix_len);
-
-		if (!l_rtnl_address_set_broadcast(new_addr,
-				broadcast_from_ip(addr_str_buf, prefix_len))) {
-			ret = -EIO;
-			goto cleanup;
-		}
-
 		ret = 0;
 	} else {
 		if (!prefix_len)
Signature · 1 line
2.30.2
#1 lore raw

PATCH 2/15 ap: Warn about APRanges having been deprecated

---
 src/ap.c | 3 +++
 1 file changed, 3 insertions(+)
src/ap.c +3 -0
index f0a38bb6..20422d4e 100644
@@ -3547,6 +3547,9 @@ static int ap_init(void)
 			}
 		} else if (l_settings_get_value(settings,
 						"General", "APRanges")) {
+			l_warn("The [General].APRanges setting is deprecated, "
+				"use [IPv4].APAddressPool instead");
+
 			global_addr4_strs = l_settings_get_string_list(settings,
 								"General",
 								"APRanges",
Signature · 1 line
2.30.2
#2 lore raw

PATCH 3/15 ap: Fix leaking of ap->wsc_pbc_timeout

In reply to Andrew Zaborowski
---
 src/ap.c | 1 +
 1 file changed, 1 insertion(+)
src/ap.c +1 -0
index 20422d4e..0602792c 100644
@@ -211,6 +211,7 @@ static void ap_reset(struct ap_state *ap)
 		l_uintset_free(ap->rates);
 
 	l_queue_destroy(ap->wsc_pbc_probes, l_free);
+	l_timeout_remove(ap->wsc_pbc_timeout);
 
 	ap->started = false;
 
Signature · 1 line
2.30.2
#3 lore raw

PATCH 4/15 wscutil: Fix a return statement

In reply to Andrew Zaborowski
Fixes 8d58f5b679b5 ('wscutil: Move DeviceType parsing from p2p & eap-wsc to a function')
---
 src/wscutil.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/wscutil.c +1 -1
index a48d2aa5..dac10f73 100644
@@ -3073,7 +3073,7 @@ bool wsc_device_type_from_setting_str(const char *value,
 	 * DeviceType=1-0050f204-1
 	 */
 	if (wsc_device_type_from_subcategory_str(out, value))
-		true;
+		return true;
 
 	u = strtoull(value, &endp, 0);
 
Signature · 1 line
2.30.2
#4 lore raw

PATCH 5/15 p2putil: Ensure non-negative index in p2p_get_random_string

In reply to Andrew Zaborowski
---
 src/p2putil.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/p2putil.c +1 -1
index 6ea18b74..5313b34c 100644
@@ -2637,7 +2637,7 @@ void p2p_get_random_string(char *buf, size_t len)
 	l_getrandom(buf, len);
 
 	while (len) {
-		int index = *buf % set_size;
+		int index = (uint8_t) *buf % set_size;
 
 		*buf++ = CHARSET[index];
 		len--;
Signature · 1 line
2.30.2
#5 lore raw

PATCH 6/15 p2p: Fix a leak of ie_tlv_extract_p2p_payload() result

In reply to Andrew Zaborowski
---
 src/p2p.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
src/p2p.c +3 -2
index 580eb53f..7e828412 100644
@@ -1032,6 +1032,7 @@ static size_t p2p_group_write_p2p_ie(struct p2p_device *dev,
 
 	case MPDU_MANAGEMENT_SUBTYPE_PROBE_RESPONSE:
 	{
+		L_AUTO_FREE_VAR(uint8_t *, tmp) = NULL;
 		struct p2p_probe_resp info = {};
 		const struct mmpdu_probe_request *req =
 			mmpdu_body(client_frame);
@@ -1045,8 +1046,8 @@ static size_t p2p_group_write_p2p_ie(struct p2p_device *dev,
 		 * Response frame if the received Probe Request frame does
 		 * not contain a P2P IE."
 		 */
-		if (!ie_tlv_extract_p2p_payload(req->ies, req_ies_len,
-							&req_p2p_data_size))
+		if (!(tmp = ie_tlv_extract_p2p_payload(req->ies, req_ies_len,
+							&req_p2p_data_size)))
 			return 0;
 
 		info.capability = dev->capability;
Signature · 1 line
2.30.2
#6 lore raw

PATCH 7/15 p2p: Fix parsing of Association Req P2P IEs

In reply to Andrew Zaborowski

p2p_parse_association_req() already extracts the P2P IE payload from the IE sequence, there's no need to call ie_tlv_extract_p2p_payload before it. Pass the IE sequence directly to p2p_parse_association_req().

---
 src/p2p.c | 15 ++-------------
 1 file changed, 2 insertions(+), 13 deletions(-)
src/p2p.c +2 -13
index 7e828412..bc2d154d 100644
@@ -898,22 +898,11 @@ static void p2p_group_event(enum ap_event_type type, const void *event_data,
 	case AP_EVENT_STATION_ADDED:
 	{
 		const struct ap_event_station_added_data *data = event_data;
-		L_AUTO_FREE_VAR(uint8_t *, p2p_data) = NULL;
-		ssize_t p2p_data_len;
 		L_AUTO_FREE_VAR(uint8_t *, wfd_data) = NULL;
 		ssize_t wfd_data_len;
 		struct p2p_association_req req_info;
 		int r;
 
-		p2p_data = ie_tlv_extract_p2p_payload(data->assoc_ies,
-							data->assoc_ies_len,
-							&p2p_data_len);
-		if (!p2p_data) {
-			l_error("Missing or invalid P2P IEs: %s (%i)",
-				strerror(-p2p_data_len), (int) -p2p_data_len);
-			goto invalid_ie;
-		}
-
 		/*
 		 * We don't need to validate most of the Association Request
 		 * P2P IE contents as we already have all the information there
@@ -928,8 +917,8 @@ static void p2p_group_event(enum ap_event_type type, const void *event_data,
 		 * information shall be used by the P2P Group Owner for Group
 		 * Information Advertisement.
 		 */
-		r = p2p_parse_association_req(p2p_data, p2p_data_len,
-						&req_info);
+		r = p2p_parse_association_req(data->assoc_ies,
+						data->assoc_ies_len, &req_info);
 		if (r < 0) {
 			l_error("Can't parse P2P Association Request: %s (%i)",
 				strerror(-r), -r);
Signature · 1 line
2.30.2
#7 lore raw

PATCH 8/15 ap: Forward DHCP events to AP event handler

In reply to Andrew Zaborowski
---
 src/ap.c | 42 ++++++++++++++++++++++++++++++++++++++----
 src/ap.h |  2 ++
 2 files changed, 40 insertions(+), 4 deletions(-)
src/ap.c +38 -4
index 0602792c..86e17387 100644
@@ -2044,6 +2044,28 @@ static void ap_start_failed(struct ap_state *ap, int err)
 	l_free(ap);
 }
 
+static void ap_dhcp_event_cb(struct l_dhcp_server *server,
+				enum l_dhcp_server_event event, void *user_data,
+				const struct l_dhcp_lease *lease)
+{
+	struct ap_state *ap = user_data;
+
+	switch (event) {
+	case L_DHCP_SERVER_EVENT_NEW_LEASE:
+		ap->ops->handle_event(AP_EVENT_DHCP_NEW_LEASE, lease,
+					ap->user_data);
+		break;
+
+	case L_DHCP_SERVER_EVENT_LEASE_EXPIRED:
+		ap->ops->handle_event(AP_EVENT_DHCP_LEASE_EXPIRED, lease,
+					ap->user_data);
+		break;
+
+	default:
+		break;
+	}
+}
+
 static void ap_start_cb(struct l_genl_msg *msg, void *user_data)
 {
 	struct ap_state *ap = user_data;
@@ -2056,10 +2078,20 @@ static void ap_start_cb(struct l_genl_msg *msg, void *user_data)
 		return;
 	}
 
-	if (ap->netconfig_dhcp && !l_dhcp_server_start(ap->netconfig_dhcp)) {
-		l_error("DHCP server failed to start");
-		ap_start_failed(ap, -EINVAL);
-		return;
+	if (ap->netconfig_dhcp) {
+		if (!l_dhcp_server_start(ap->netconfig_dhcp)) {
+			l_error("DHCP server failed to start");
+			ap_start_failed(ap, -EINVAL);
+			return;
+		}
+
+		if (!l_dhcp_server_set_event_handler(ap->netconfig_dhcp,
+							ap_dhcp_event_cb,
+							ap, NULL)) {
+			l_error("l_dhcp_server_set_event_handler failed");
+			ap_start_failed(ap, -EIO);
+			return;
+		}
 	}
 
 	ap->started = true;
@@ -3200,6 +3232,8 @@ static void ap_if_event_func(enum ap_event_type type, const void *event_data,
 	case AP_EVENT_REGISTRATION_START:
 	case AP_EVENT_REGISTRATION_SUCCESS:
 	case AP_EVENT_PBC_MODE_EXIT:
+	case AP_EVENT_DHCP_NEW_LEASE:
+	case AP_EVENT_DHCP_LEASE_EXPIRED:
 		/* Ignored */
 		break;
 	}
src/ap.h +2 -0
index 9a03d3ae..94d6c04d 100644
@@ -33,6 +33,8 @@ enum ap_event_type {
 	AP_EVENT_REGISTRATION_START,
 	AP_EVENT_REGISTRATION_SUCCESS,
 	AP_EVENT_PBC_MODE_EXIT,
+	AP_EVENT_DHCP_NEW_LEASE,
+	AP_EVENT_DHCP_LEASE_EXPIRED,
 };
 
 struct ap_event_start_failed_data {
Signature · 1 line
2.30.2
#8 lore raw

PATCH 9/15 p2p: Also set a DHCP timeout in Group Owner role

In reply to Andrew Zaborowski

Move the loading of the [P2P].DHCPTimeout setting to initialization and set the timeout both in P2P Client and P2P GO roles.

---
 src/p2p.c | 53 ++++++++++++++++++++++++++++++-----------------------
 1 file changed, 30 insertions(+), 23 deletions(-)
src/p2p.c +30 -23
index bc2d154d..22ce7042 100644
@@ -170,6 +170,7 @@ struct p2p_wfd_properties {
 };
 
 static struct l_queue *p2p_device_list;
+static unsigned int p2p_dhcp_timeout_val;
 static struct l_settings *p2p_dhcp_settings;
 static struct p2p_wfd_properties *p2p_own_wfd;
 static unsigned int p2p_wfd_disconnect_watch;
@@ -1175,6 +1176,22 @@ static const struct ap_ops p2p_go_ops = {
 	.write_extra_ies = p2p_group_write_ies,
 };
 
+static void p2p_dhcp_timeout(struct l_timeout *timeout, void *user_data)
+{
+	struct p2p_device *dev = user_data;
+
+	l_debug("");
+
+	p2p_connect_failed(dev);
+}
+
+static void p2p_dhcp_timeout_destroy(void *user_data)
+{
+	struct p2p_device *dev = user_data;
+
+	dev->conn_dhcp_timeout = NULL;
+}
+
 static void p2p_group_start(struct p2p_device *dev)
 {
 	struct l_settings *config = l_settings_new();
@@ -1233,8 +1250,15 @@ static void p2p_group_start(struct p2p_device *dev)
 	dev->group = ap_start(dev->conn_netdev, config, &p2p_go_ops, NULL, dev);
 	l_settings_free(config);
 
-	if (!dev->group)
+	if (!dev->group) {
 		p2p_connect_failed(dev);
+		return;
+	}
+
+	/* Set timeout on client connecting and getting its IP */
+	dev->conn_dhcp_timeout = l_timeout_create(p2p_dhcp_timeout_val,
+						p2p_dhcp_timeout, dev,
+						p2p_dhcp_timeout_destroy);
 }
 
 static void p2p_netconfig_event_handler(enum netconfig_event event,
@@ -1259,32 +1283,11 @@ static void p2p_netconfig_event_handler(enum netconfig_event event,
 	}
 }
 
-static void p2p_dhcp_timeout(struct l_timeout *timeout, void *user_data)
-{
-	struct p2p_device *dev = user_data;
-
-	l_debug("");
-
-	p2p_connect_failed(dev);
-}
-
-static void p2p_dhcp_timeout_destroy(void *user_data)
-{
-	struct p2p_device *dev = user_data;
-
-	dev->conn_dhcp_timeout = NULL;
-}
-
 static void p2p_start_client_netconfig(struct p2p_device *dev)
 {
 	uint32_t ifindex = netdev_get_ifindex(dev->conn_netdev);
-	unsigned int dhcp_timeout_val;
 	struct l_settings *settings;
 
-	if (!l_settings_get_uint(iwd_get_config(), "P2P", "DHCPTimeout",
-					&dhcp_timeout_val))
-		dhcp_timeout_val = 20;	/* 20s default */
-
 	if (!dev->conn_netconfig) {
 		dev->conn_netconfig = netconfig_new(ifindex);
 		if (!dev->conn_netconfig) {
@@ -1296,7 +1299,7 @@ static void p2p_start_client_netconfig(struct p2p_device *dev)
 	settings = dev->conn_netconfig_settings ?: p2p_dhcp_settings;
 	netconfig_configure(dev->conn_netconfig, settings, dev->conn_addr,
 				p2p_netconfig_event_handler, dev);
-	dev->conn_dhcp_timeout = l_timeout_create(dhcp_timeout_val,
+	dev->conn_dhcp_timeout = l_timeout_create(p2p_dhcp_timeout_val,
 						p2p_dhcp_timeout, dev,
 						p2p_dhcp_timeout_destroy);
 }
@@ -5110,6 +5113,10 @@ static int p2p_init(void)
 					NULL))
 		l_error("Unable to register the P2P Service Manager object");
 
+	if (!l_settings_get_uint(iwd_get_config(), "P2P", "DHCPTimeout",
+					&p2p_dhcp_timeout_val))
+		p2p_dhcp_timeout_val = 20;	/* 20s default */
+
 	return 0;
 }
 
Signature · 1 line
2.30.2
#9 lore raw

PATCH 10/15 p2p: As GO delay connect success until client gets IP

In reply to Andrew Zaborowski

Don't signal the connected state until the client has obtained a DHCP lease and we can set the ConnectedIP property. From now on that property is always set when there's a connection.

---
 src/p2p.c | 36 ++++++++++++++++++++++++++++++------
 1 file changed, 30 insertions(+), 6 deletions(-)
src/p2p.c +30 -6
index 22ce7042..c7c8d785 100644
@@ -659,10 +659,11 @@ static void p2p_connection_reset(struct p2p_device *dev)
 		netconfig_destroy(dev->conn_netconfig);
 		dev->conn_netconfig = NULL;
 		l_settings_free(dev->conn_netconfig_settings);
-		l_free(dev->conn_peer_ip);
-		dev->conn_peer_ip = NULL;
 	}
 
+	l_free(dev->conn_peer_ip);
+	dev->conn_peer_ip = NULL;
+
 	if (dev->conn_new_intf_cmd_id)
 		/*
 		 * Note this may result in the interface being created
@@ -948,8 +949,8 @@ static void p2p_group_event(enum ap_event_type type, const void *event_data,
 			p2p_extract_wfd_properties(wfd_data, wfd_data_len,
 							dev->conn_peer->wfd);
 
-		dev->conn_peer_added = true;
-		p2p_peer_connect_done(dev);
+		/* Setup is progressing so re-arm the timeout */
+		l_timeout_modify(dev->conn_dhcp_timeout, p2p_dhcp_timeout_val);
 		break;
 	}
 
@@ -968,6 +969,28 @@ static void p2p_group_event(enum ap_event_type type, const void *event_data,
 		break;
 	case AP_EVENT_PBC_MODE_EXIT:
 		break;
+
+	case AP_EVENT_DHCP_NEW_LEASE:
+	{
+		const struct l_dhcp_lease *lease = event_data;
+
+		if (dev->conn_peer_added)
+			break;
+
+		dev->conn_peer_added = true;
+		dev->conn_peer_ip = l_dhcp_lease_get_address(lease);
+		l_timeout_remove(dev->conn_dhcp_timeout);
+		p2p_peer_connect_done(dev);
+		break;
+	}
+
+	case AP_EVENT_DHCP_LEASE_EXPIRED:
+		/*
+		 * Only one DHCP lease allowed for now, as soon as it expires
+		 * the connection is considered to be down.
+		 */
+		p2p_connect_failed(dev);
+		break;
 	};
 
 	return;
@@ -1242,7 +1265,8 @@ static void p2p_group_start(struct p2p_device *dev)
 
 	l_settings_set_bytes(config, "Security", "PreSharedKey", psk, 32);
 
-	l_settings_add_group(config, "IPv4");
+	/* Enable netconfig, set maximum usable DHCP lease time */
+	l_settings_set_uint(config, "IPv4", "LeaseTime", 0x7fffffff);
 
 	dev->capability.group_caps |= P2P_GROUP_CAP_GO;
 	dev->capability.group_caps |= P2P_GROUP_CAP_GROUP_FORMATION;
@@ -4757,7 +4781,7 @@ static bool p2p_peer_get_connected_ip(struct l_dbus *dbus,
 {
 	struct p2p_peer *peer = user_data;
 
-	if (!p2p_peer_operational(peer) || !peer->dev->conn_peer_ip)
+	if (!p2p_peer_operational(peer))
 		return false;
 
 	l_dbus_message_builder_append_basic(builder, 's', peer->dev->conn_peer_ip);
Signature · 1 line
2.30.2
#10 lore raw

PATCH 11/15 p2p: Set Linkmode/operstate on GO connection

In reply to Andrew Zaborowski
---
 src/p2p.c | 6 ++++++
 1 file changed, 6 insertions(+)
src/p2p.c +6 -0
index c7c8d785..cb6cd98b 100644
@@ -34,6 +34,7 @@
 #include <errno.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
+#include <linux/if.h>
 
 #include <ell/ell.h>
 
@@ -977,6 +978,11 @@ static void p2p_group_event(enum ap_event_type type, const void *event_data,
 		if (dev->conn_peer_added)
 			break;
 
+		l_rtnl_set_linkmode_and_operstate(iwd_get_rtnl(),
+					netdev_get_ifindex(dev->conn_netdev),
+					IF_LINK_MODE_DEFAULT, IF_OPER_UP,
+					NULL, NULL, NULL);
+
 		dev->conn_peer_added = true;
 		dev->conn_peer_ip = l_dhcp_lease_get_address(lease);
 		l_timeout_remove(dev->conn_dhcp_timeout);
Signature · 1 line
2.30.2
#11 lore raw

PATCH 12/15 autotests: Initialise P2PPeer objects with correct namespace

In reply to Andrew Zaborowski
---
 autotests/util/iwd.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
autotests/util/iwd.py +1 -1
index e6421088..350e1aca 100755
@@ -826,7 +826,7 @@ class P2PDevice(IWDDBusAbstract):
         self._peer_dict = {}
 
         for path, rssi in self._iface.GetPeers():
-            self._peer_dict[path] = old_dict[path] if path in old_dict else P2PPeer(path)
+            self._peer_dict[path] = old_dict[path] if path in old_dict else P2PPeer(path, namespace=self._namespace)
             self._peer_dict[path].rssi = rssi
 
         return self._peer_dict
Signature · 1 line
2.30.2
#12 lore raw

PATCH 13/15 autotests: Add missing space in wpas P2P_CONNECT commands

In reply to Andrew Zaborowski
---
 autotests/util/wpas.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
autotests/util/wpas.py +3 -3
index ec19b101..c54becbc 100644
@@ -203,20 +203,20 @@ class Wpas:
     def p2p_connect(self, peer, pin=None, go_intent=None):
         self._rx_data = []
         self._ctrl_request('P2P_CONNECT ' + peer['p2p_dev_addr'] + ' ' + ('pbc' if pin is None else pin) +
-                        ('' if go_intent is None else 'go_intent=' + str(go_intent)))
+                        ('' if go_intent is None else ' go_intent=' + str(go_intent)))
         self.wait_for_event('OK')
 
     def p2p_accept_go_neg_request(self, request, pin=None, go_intent=None):
         self._rx_data = []
         self._ctrl_request('P2P_CONNECT ' + request['p2p_dev_addr'] + ' ' + ('pbc' if pin is None else pin) +
-                        ('' if go_intent is None else 'go_intent=' + str(go_intent)))
+                        ('' if go_intent is None else ' go_intent=' + str(go_intent)))
         self.wait_for_event('OK')
 
     # Pre-accept the next GO Negotiation Request from this peer to avoid the extra Respone + Request frames
     def p2p_authorize(self, peer, pin=None, go_intent=None):
         self._rx_data = []
         self._ctrl_request('P2P_CONNECT ' + peer['p2p_dev_addr'] + ' ' + ('pbc' if pin is None else pin) +
-                        ('' if go_intent is None else 'go_intent=' + str(go_intent)) + ' auth')
+                        ('' if go_intent is None else ' go_intent=' + str(go_intent)) + ' auth')
         self.wait_for_event('OK')
 
     # Probably needed: remove references to self so that the GC can call __del__ automatically
Signature · 1 line
2.30.2
#13 lore raw

PATCH 14/15 autotests: Add P2P GO role test scenarios

In reply to Andrew Zaborowski

autotests/testP2P/client_test.py is renamed to connection_test.py to reflect that it now tests both roles.

---
 .../{client_test.py => connection_test.py}    | 71 ++++++++++++++-----
 autotests/testP2P/dhclient-script             | 17 +++++
 autotests/testP2P/main.conf                   |  3 +
 autotests/util/wpas.py                        | 63 ++++++++++------
 4 files changed, 114 insertions(+), 40 deletions(-)
 rename autotests/testP2P/{client_test.py => connection_test.py} (51%)
 create mode 100755 autotests/testP2P/dhclient-script
autotests/testP2P/connection_test.py renamed from autotests/testP2P/client_test.py +52 -19
similarity index 51%
rename from autotests/testP2P/client_test.py
rename to autotests/testP2P/connection_test.py
index 4994de76..9bb0e34e 100644
@@ -4,6 +4,7 @@ import unittest
 import sys
 import netifaces
 import os
+import time
 
 import iwd
 from iwd import IWD
@@ -13,14 +14,21 @@ from wpas import Wpas
 
 class Test(unittest.TestCase):
     def test_1_client_go_neg_responder(self):
-        self.p2p_client_test(False)
+        self.p2p_connect_test(preauthorize=False, go=False)
 
     def test_2_client_go_neg_initiator(self):
-        self.p2p_client_test(True)
+        self.p2p_connect_test(preauthorize=True, go=False)
 
-    def p2p_client_test(self, preauthorize):
-        wpas = Wpas(p2p=True)
+    def test_3_go_go_neg_responder(self):
+        self.p2p_connect_test(preauthorize=False, go=True)
+
+    def test_4_go_go_neg_initiator(self):
+        self.p2p_connect_test(preauthorize=True, go=True)
+
+    def p2p_connect_test(self, preauthorize, go):
         wd = IWD()
+        wpas = Wpas(p2p=True)
+        wpas_go_intent = 10 if not go else 1
 
         # Not strictly necessary but prevents the station interface from queuing its scans
         # in the wiphy radio work queue and delaying P2P scans.
@@ -51,7 +59,7 @@ class Test(unittest.TestCase):
         self.assertEqual(wpas_peer['config_methods'], '0x1080')
 
         if preauthorize:
-            wpas.p2p_authorize(wpas_peer)
+            wpas.p2p_authorize(wpas_peer, go_intent=wpas_go_intent)
 
         peer.connect(wait=False)
 
@@ -64,38 +72,63 @@ class Test(unittest.TestCase):
             self.assertEqual(request['dev_passwd_id'], '4')
             self.assertEqual(request['go_intent'], '2') # Hardcoded in src/p2p.c
 
-            wpas.p2p_accept_go_neg_request(request)
+            wpas.p2p_accept_go_neg_request(request, go_intent=wpas_go_intent)
 
         wd.wait_for_object_condition(request, '\'success\' in obj', max_wait=3)
         self.assertEqual(request['success'], True)
-        self.assertEqual(request['role'], 'GO')
+        self.assertEqual(request['role'], 'GO' if not go else 'client')
         self.assertEqual(request['wps_method'], 'PBC')
         self.assertEqual(request['p2p_dev_addr'], wpas_peer['p2p_dev_addr'])
 
+        if go:
+            # For some reason wpa_supplicant's newly created P2P-client interface doesn't inherit
+            # the settings from the main interface which were loaded from the config file
+            # (P2P-device and P2P-GO interfaces do), we need to set config_methods again.
+            peer_ifname = 'p2p-' + wpas.interface.name + '-0'
+            wpas.set('config_methods', wpas.config['config_methods'], ifname=peer_ifname)
+            wpas.set('device_name', wpas.config['device_name'], ifname=peer_ifname)
+            wpas.set('device_type', wpas.config['device_type'], ifname=peer_ifname)
+
         wd.wait_for_object_condition(wpas, 'obj.p2p_group is not None', max_wait=3)
-        go_ifname = wpas.p2p_group['ifname']
-        ctx.start_process(['ifconfig', go_ifname, '192.168.1.20', 'netmask', '255.255.255.0'], wait=True)
-        os.system('> /tmp/dhcpd.leases')
-        dhcpd = ctx.start_process(['dhcpd', '-f', '-cf', '/tmp/dhcpd.conf', '-lf', '/tmp/dhcpd.leases', go_ifname])
+        peer_ifname = wpas.p2p_group['ifname']
+
+        if not go:
+            ctx.start_process(['ifconfig', peer_ifname, '192.168.1.20', 'netmask', '255.255.255.0'], wait=True)
+            os.system('> /tmp/dhcpd.leases')
+            dhcp = ctx.start_process(['dhcpd', '-f', '-cf', '/tmp/dhcpd.conf', '-lf', '/tmp/dhcpd.leases', peer_ifname])
 
-        wd.wait_for_object_condition(wpas, 'len(obj.p2p_clients) == 1', max_wait=3)
-        client = wpas.p2p_clients[request['peer_iface']]
-        self.assertEqual(client['p2p_dev_addr'], wpas_peer['p2p_dev_addr'])
+            wd.wait_for_object_condition(wpas, 'len(obj.p2p_clients) == 1', max_wait=3)
+            client = wpas.p2p_clients[request['peer_iface']]
+            self.assertEqual(client['p2p_dev_addr'], wpas_peer['p2p_dev_addr'])
+        else:
+            dhcp = ctx.start_process(['dhclient', '-v', '-d', '--no-pid', '-cf', '/dev/null', '-lf', '/tmp/dhcpd.leases',
+                '-sf', '/tmp/dhclient-script', peer_ifname])
 
         wd.wait_for_object_condition(peer, 'obj.connected', max_wait=15)
+        time.sleep(1) # Give the client time to set the IP
         our_ip = netifaces.ifaddresses(peer.connected_interface)[netifaces.AF_INET][0]['addr']
-        self.assertEqual(peer.connected_ip, '192.168.1.20')
-        self.assertEqual(our_ip, '192.168.1.30')
+        peer_ip = netifaces.ifaddresses(peer_ifname)[netifaces.AF_INET][0]['addr']
+        self.assertEqual(peer.connected_ip, peer_ip)
+
+        if not go:
+            self.assertEqual(our_ip, '192.168.1.30')
+            self.assertEqual(peer_ip, '192.168.1.20')
+        else:
+            self.assertEqual(our_ip, '192.168.1.1')
+            self.assertEqual(peer_ip, '192.168.1.2')
 
         testutil.test_iface_operstate(peer.connected_interface)
-        testutil.test_ifaces_connected(peer.connected_interface, go_ifname)
+        testutil.test_ifaces_connected(peer.connected_interface, peer_ifname)
 
         peer.disconnect()
-        wd.wait_for_object_condition(wpas, 'len(obj.p2p_clients) == 0', max_wait=3)
+        if not go:
+            wd.wait_for_object_condition(wpas, 'len(obj.p2p_clients) == 0', max_wait=3)
+        else:
+            wd.wait_for_object_condition(wpas, 'obj.p2p_group is None', max_wait=3)
         self.assertEqual(peer.connected, False)
 
         p2p.enabled = False
-        ctx.stop_process(dhcpd)
+        ctx.stop_process(dhcp)
         wpas.clean_up()
 
     @classmethod
autotests/testP2P/dhclient-script new file +17 -0
new file mode 100755
index 00000000..276880b6
@@ -0,0 +1,17 @@
+#! /bin/bash
+case $reason in
+BOUND|RENEW|REBIND|REBOOT)
+  if [ x$new_ip_address != x ] && \
+     [ x$new_ip_address != x$old_ip_address -o \
+       x$reason = xBOUND -o x$reason = xREBOOT ]; then
+    /sbin/ip addr add $new_ip_address/${new_subnet_mask:-32} \
+                      ${new_broadcast_arg} \
+                      dev $interface
+  fi
+;;
+EXPIRE|FAIL|RELEASE|STOP)
+  if [ x$old_ip_address != x ]; then
+    /sbin/ip -4 addr flush dev $interface
+  fi
+;;
+esac
autotests/testP2P/main.conf +3 -0
index 75040f78..b0bb5794 100644
@@ -4,3 +4,6 @@ EnableNetworkConfiguration=true
 [P2P]
 # Something different from the default of 'pc' for validation
 DeviceType=desktop
+
+[IPv4]
+APAddressPool=192.168.1.0/28
autotests/util/wpas.py +42 -21

103 lines not on this page · raw message

Signature · 1 line
2.30.2
#14 lore raw

PATCH 15/15 doc: Document autotests' wpa_supplicant dependency

In reply to Andrew Zaborowski
---
 doc/test-runner.txt | 1 +
 1 file changed, 1 insertion(+)
doc/test-runner.txt +1 -0
index 89a7c44c..9140aa0f 100644
@@ -28,6 +28,7 @@ OS:
 	10. <iwd>/src/iwd	0.0
 	11. ofono (optional)
 	12. phonesim (optional)
+	13. wpa_supplicant	2.9
 
 Note: The version for hostapd is listed as 'recent'. Older hostapd versions
 will work but we are continually adopting new features from hostapd and using
Signature · 1 line
2.30.2
#15 lore raw
In reply to Andrew Zaborowski

Hi Andrew,

Quoted 5 lines · Andrew Zaborowski

It's already done in l_rtnl_address_new().

---
  src/ap.c | 19 -------------------
  1 file changed, 19 deletions(-)

All applied, thanks.

Regards,
-Denis