Skip to contentSkip to conversation

ap: Pass "ops" struct to ap_start()

PATCH Applied Andrew Zaborowski 2 participants 8 messages Sep 16, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/6 ap: Pass "ops" struct to ap_start()

Pass the event callback function pointer in a "struct ap_ops" instead of as individual ap_start() argument to make adding new callbacks easier.

---
 src/ap.c | 65 +++++++++++++++++++++++++++++++-------------------------
 src/ap.h |  9 +++++---
 2 files changed, 42 insertions(+), 32 deletions(-)
src/ap.c +36 -29
index dfa12444..7c135150 100644
@@ -53,7 +53,7 @@
 struct ap_state {
 	struct netdev *netdev;
 	struct l_genl_family *nl80211;
-	ap_event_func_t event_func;
+	const struct ap_ops *ops;
 	ap_stopped_func_t stopped_func;
 	void *user_data;
 	struct ap_config *config;
@@ -211,7 +211,7 @@ static void ap_del_station(struct sta_state *sta, uint16_t reason,
 	sta->associated = false;
 
 	if (sta->rsna) {
-		if (ap->event_func) {
+		if (ap->ops->handle_event) {
 			memset(&event_data, 0, sizeof(event_data));
 			event_data.mac = sta->addr;
 			event_data.reason = reason;
@@ -229,8 +229,8 @@ static void ap_del_station(struct sta_state *sta, uint16_t reason,
 	ap_stop_handshake(sta);
 
 	if (send_event)
-		ap->event_func(AP_EVENT_STATION_REMOVED, &event_data,
-				ap->user_data);
+		ap->ops->handle_event(AP_EVENT_STATION_REMOVED, &event_data,
+					ap->user_data);
 }
 
 static bool ap_sta_match_addr(const void *a, const void *b)
@@ -270,12 +270,12 @@ static void ap_new_rsna(struct sta_state *sta)
 
 	sta->rsna = true;
 
-	if (ap->event_func) {
+	if (ap->ops->handle_event) {
 		struct ap_event_station_added_data event_data = {};
 		event_data.mac = sta->addr;
 		event_data.rsn_ie = sta->assoc_rsne;
-		ap->event_func(AP_EVENT_STATION_ADDED, &event_data,
-				ap->user_data);
+		ap->ops->handle_event(AP_EVENT_STATION_ADDED, &event_data,
+					ap->user_data);
 	}
 }
 
@@ -309,11 +309,11 @@ static void ap_drop_rsna(struct sta_state *sta)
 
 	ap_stop_handshake(sta);
 
-	if (ap->event_func) {
+	if (ap->ops->handle_event) {
 		struct ap_event_station_removed_data event_data = {};
 		event_data.mac = sta->addr;
-		ap->event_func(AP_EVENT_STATION_REMOVED, &event_data,
-				ap->user_data);
+		ap->ops->handle_event(AP_EVENT_STATION_REMOVED, &event_data,
+					ap->user_data);
 	}
 }
 
@@ -544,7 +544,7 @@ static void ap_wsc_exit_pbc(struct ap_state *ap)
 	ap->wsc_dpid = 0;
 	ap_update_beacon(ap);
 
-	ap->event_func(AP_EVENT_PBC_MODE_EXIT, NULL, ap->user_data);
+	ap->ops->handle_event(AP_EVENT_PBC_MODE_EXIT, NULL, ap->user_data);
 }
 
 static uint32_t ap_send_mgmt_frame(struct ap_state *ap,
@@ -751,8 +751,9 @@ static void ap_wsc_handshake_event(struct handshake_state *hs,
 					&expiry_data);
 
 		event_data.mac = sta->addr;
-		sta->ap->event_func(AP_EVENT_REGISTRATION_SUCCESS, &event_data,
-					sta->ap->user_data);
+		sta->ap->ops->handle_event(AP_EVENT_REGISTRATION_SUCCESS,
+						&event_data,
+						sta->ap->user_data);
 		break;
 	default:
 		break;
@@ -1336,8 +1337,8 @@ static void ap_assoc_reassoc(struct sta_state *sta, bool reassoc,
 		sta->wsc_v2 = wsc_req.version2;
 
 		event_data.mac = sta->addr;
-		ap->event_func(AP_EVENT_REGISTRATION_START, &event_data,
-				ap->user_data);
+		ap->ops->handle_event(AP_EVENT_REGISTRATION_START, &event_data,
+					ap->user_data);
 
 		/*
 		 * Since we're starting the PBC Registration Protocol
@@ -1920,7 +1921,8 @@ static void ap_start_cb(struct l_genl_msg *msg, void *user_data)
 	if (l_genl_msg_get_error(msg) < 0) {
 		l_error("START_AP failed: %i", l_genl_msg_get_error(msg));
 
-		ap->event_func(AP_EVENT_START_FAILED, NULL, ap->user_data);
+		ap->ops->handle_event(AP_EVENT_START_FAILED, NULL,
+					ap->user_data);
 		ap_reset(ap);
 		l_genl_family_free(ap->nl80211);
 		l_free(ap);
@@ -1928,7 +1930,7 @@ static void ap_start_cb(struct l_genl_msg *msg, void *user_data)
 	}
 
 	ap->started = true;
-	ap->event_func(AP_EVENT_STARTED, NULL, ap->user_data);
+	ap->ops->handle_event(AP_EVENT_STARTED, NULL, ap->user_data);
 }
 
 static struct l_genl_msg *ap_build_cmd_start_ap(struct ap_state *ap)
@@ -2015,11 +2017,12 @@ static void ap_mlme_notify(struct l_genl_msg *msg, void *user_data)
 			l_genl_family_cancel(ap->nl80211,
 						ap->start_stop_cmd_id);
 			ap->start_stop_cmd_id = 0;
-			ap->event_func(AP_EVENT_START_FAILED, NULL,
-					ap->user_data);
+			ap->ops->handle_event(AP_EVENT_START_FAILED, NULL,
+						ap->user_data);
 		} else if (ap->started) {
 			ap->started = false;
-			ap->event_func(AP_EVENT_STOPPING, NULL, ap->user_data);
+			ap->ops->handle_event(AP_EVENT_STOPPING, NULL,
+						ap->user_data);
 		}
 
 		ap_reset(ap);
@@ -2032,17 +2035,17 @@ static void ap_mlme_notify(struct l_genl_msg *msg, void *user_data)
 /*
  * Start a simple independent WPA2 AP on given netdev.
  *
- * @event_func is required and must react to AP_EVENT_START_FAILED
- * and AP_EVENT_STOPPING by forgetting the ap_state struct, which
- * is going to be freed automatically.
- * In the @config struct only .ssid and .psk need to be non-NUL,
+ * @ops.handle_event is required and must react to AP_EVENT_START_FAILED
+ * and AP_EVENT_STOPPING by forgetting the ap_state struct, which is
+ * going to be freed automatically.
+ * In the @config struct only .ssid and .psk need to be non-NULL,
  * other fields are optional.  If @ap_start succeeds, the returned
  * ap_state takes ownership of @config and the caller shouldn't
  * free it or any of the memory pointed to by its members (they
  * also can't be static).
  */
 struct ap_state *ap_start(struct netdev *netdev, struct ap_config *config,
-				ap_event_func_t event_func, void *user_data)
+				const struct ap_ops *ops, void *user_data)
 {
 	struct ap_state *ap;
 	struct wiphy *wiphy = netdev_get_wiphy(netdev);
@@ -2053,7 +2056,7 @@ struct ap_state *ap_start(struct netdev *netdev, struct ap_config *config,
 	ap->nl80211 = l_genl_family_new(iwd_get_genl(), NL80211_GENL_NAME);
 	ap->config = config;
 	ap->netdev = netdev;
-	ap->event_func = event_func;
+	ap->ops = ops;
 	ap->user_data = user_data;
 
 	if (!config->channel)
@@ -2184,7 +2187,7 @@ static struct l_genl_msg *ap_build_cmd_stop_ap(struct ap_state *ap)
 
 /*
  * Schedule the running @ap to be stopped and freed.  The original
- * event_func and user_data are forgotten and a new callback can be
+ * ops and user_data are forgotten and a new callback can be
  * provided if the caller needs to know when the interface becomes
  * free, for example for a new ap_start call.
  *
@@ -2201,7 +2204,7 @@ void ap_shutdown(struct ap_state *ap, ap_stopped_func_t stopped_func,
 
 	if (ap->started) {
 		ap->started = false;
-		ap->event_func(AP_EVENT_STOPPING, NULL, ap->user_data);
+		ap->ops->handle_event(AP_EVENT_STOPPING, NULL, ap->user_data);
 	}
 
 	ap_reset(ap);
@@ -2371,6 +2374,10 @@ static void ap_if_event_func(enum ap_event_type type, const void *event_data,
 	}
 }
 
+static const struct ap_ops ap_dbus_ops = {
+	.handle_event = ap_if_event_func,
+};
+
 static struct l_dbus_message *ap_dbus_start(struct l_dbus *dbus,
 		struct l_dbus_message *message, void *user_data)
 {
@@ -2391,7 +2398,7 @@ static struct l_dbus_message *ap_dbus_start(struct l_dbus *dbus,
 	config->ssid = l_strdup(ssid);
 	config->psk = l_strdup(wpa2_psk);
 
-	ap_if->ap = ap_start(ap_if->netdev, config, ap_if_event_func, ap_if);
+	ap_if->ap = ap_start(ap_if->netdev, config, &ap_dbus_ops, ap_if);
 	if (!ap_if->ap) {
 		ap_config_free(config);
 		return dbus_error_invalid_args(message);
src/ap.h +6 -3
index cb5238d1..bbfecd6d 100644
@@ -52,8 +52,6 @@ struct ap_event_registration_success_data {
 	const uint8_t *mac;
 };
 
-typedef void (*ap_event_func_t)(enum ap_event_type type, const void *event_data,
-				void *user_data);
 typedef void (*ap_stopped_func_t)(void *user_data);
 
 struct ap_config {
@@ -67,10 +65,15 @@ struct ap_config {
 	bool no_cck_rates : 1;
 };
 
+struct ap_ops {
+	void (*handle_event)(enum ap_event_type type, const void *event_data,
+				void *user_data);
+};
+
 void ap_config_free(struct ap_config *config);
 
 struct ap_state *ap_start(struct netdev *netdev, struct ap_config *config,
-				ap_event_func_t event_func, void *user_data);
+				const struct ap_ops *ops, void *user_data);
 void ap_shutdown(struct ap_state *ap, ap_stopped_func_t stopped_func,
 			void *user_data);
 void ap_free(struct ap_state *ap);
Signature · 1 line
2.25.1
#1 lore raw

PATCH 2/6 ap: Support working without passphrase

Add a "psk" setting to allow the user to pass the binary PSK directly instead of generating it from the passphrase and the SSID. In that case we'll only send the PSK to WSC enrollees.

---
 src/ap.c | 48 +++++++++++++++++++++++++++++-------------------
 src/ap.h |  3 ++-
 2 files changed, 31 insertions(+), 20 deletions(-)
src/ap.c +29 -19
index 7c135150..626c983b 100644
@@ -62,7 +62,6 @@ struct ap_state {
 	enum ie_rsn_cipher_suite group_cipher;
 	uint32_t beacon_interval;
 	struct l_uintset *rates;
-	uint8_t pmk[32];
 	uint32_t start_stop_cmd_id;
 	uint32_t mlme_watch;
 	uint8_t gtk[CRYPTO_MAX_GTK_LEN];
@@ -114,11 +113,8 @@ void ap_config_free(struct ap_config *config)
 
 	l_free(config->ssid);
 
-	if (config->psk) {
-		explicit_bzero(config->psk, strlen(config->psk));
-		l_free(config->psk);
-	}
-
+	explicit_bzero(config->passphrase, sizeof(config->passphrase));
+	explicit_bzero(config->psk, sizeof(config->psk));
 	l_free(config->authorized_macs);
 	l_free(config->wsc_name);
 	l_free(config);
@@ -177,8 +173,6 @@ static void ap_reset(struct ap_state *ap)
 {
 	struct netdev *netdev = ap->netdev;
 
-	explicit_bzero(ap->pmk, sizeof(ap->pmk));
-
 	if (ap->mlme_watch)
 		l_genl_family_unregister(ap->nl80211, ap->mlme_watch);
 
@@ -652,7 +646,7 @@ static void ap_start_rsna(struct sta_state *sta, const uint8_t *gtk_rsc)
 	handshake_state_set_authenticator(sta->hs, true);
 	handshake_state_set_event_func(sta->hs, ap_handshake_event, sta);
 	handshake_state_set_supplicant_ie(sta->hs, sta->assoc_rsne);
-	handshake_state_set_pmk(sta->hs, sta->ap->pmk, 32);
+	handshake_state_set_pmk(sta->hs, sta->ap->config->psk, 32);
 
 	if (gtk_rsc)
 		handshake_state_set_gtk(sta->hs, sta->ap->gtk,
@@ -795,8 +789,14 @@ static void ap_start_eap_wsc(struct sta_state *sta)
 				WSC_CONFIGURATION_METHOD_PUSH_BUTTON);
 	l_settings_set_string(sta->wsc_settings, "WSC", "WPA2-SSID",
 				ap->config->ssid);
-	l_settings_set_string(sta->wsc_settings, "WSC", "WPA2-Passphrase",
-				ap->config->psk);
+
+	if (ap->config->passphrase[0])
+		l_settings_set_string(sta->wsc_settings,
+					"WSC", "WPA2-Passphrase",
+					ap->config->passphrase);
+	else
+		l_settings_set_bytes(sta->wsc_settings,
+					"WSC", "WPA2-PSK", ap->config->psk, 32);
 
 	sta->hs = netdev_handshake_state_new(ap->netdev);
 	handshake_state_set_authenticator(sta->hs, true);
@@ -2038,11 +2038,11 @@ static void ap_mlme_notify(struct l_genl_msg *msg, void *user_data)
  * @ops.handle_event is required and must react to AP_EVENT_START_FAILED
  * and AP_EVENT_STOPPING by forgetting the ap_state struct, which is
  * going to be freed automatically.
- * In the @config struct only .ssid and .psk need to be non-NULL,
- * other fields are optional.  If @ap_start succeeds, the returned
- * ap_state takes ownership of @config and the caller shouldn't
- * free it or any of the memory pointed to by its members (they
- * also can't be static).
+ * In the @config struct the .ssid field is required and one of
+ * .passphrase and .psk must be filled in.  All other fields are optional.
+ * If @ap_start succeeds, the returned ap_state takes ownership of
+ * @config and the caller shouldn't free it or any of the memory pointed
+ * to by its members (which also can't be static).
  */
 struct ap_state *ap_start(struct netdev *netdev, struct ap_config *config,
 				const struct ap_ops *ops, void *user_data)
@@ -2052,6 +2052,13 @@ struct ap_state *ap_start(struct netdev *netdev, struct ap_config *config,
 	struct l_genl_msg *cmd;
 	uint64_t wdev_id = netdev_get_wdev_id(netdev);
 
+	if (L_WARN_ON(!config->ssid))
+		return NULL;
+
+	if (L_WARN_ON(!config->passphrase[0] && util_mem_is_zero(config->psk,
+							sizeof(config->psk))))
+		return NULL;
+
 	ap = l_new(struct ap_state, 1);
 	ap->nl80211 = l_genl_family_new(iwd_get_genl(), NL80211_GENL_NAME);
 	ap->config = config;
@@ -2098,8 +2105,11 @@ struct ap_state *ap_start(struct netdev *netdev, struct ap_config *config,
 
 	wsc_uuid_from_addr(netdev_get_address(netdev), ap->wsc_uuid_r);
 
-	if (crypto_psk_from_passphrase(config->psk, (uint8_t *) config->ssid,
-					strlen(config->ssid), ap->pmk) < 0)
+	if (config->passphrase[0] &&
+			crypto_psk_from_passphrase(config->passphrase,
+						(uint8_t *) config->ssid,
+						strlen(config->ssid),
+						config->psk) < 0)
 		goto error;
 
 	if (!frame_watch_add(wdev_id, 0, 0x0000 |
@@ -2396,7 +2406,7 @@ static struct l_dbus_message *ap_dbus_start(struct l_dbus *dbus,
 
 	config = l_new(struct ap_config, 1);
 	config->ssid = l_strdup(ssid);
-	config->psk = l_strdup(wpa2_psk);
+	l_strlcpy(config->passphrase, wpa2_psk, sizeof(config->passphrase));
 
 	ap_if->ap = ap_start(ap_if->netdev, config, &ap_dbus_ops, ap_if);
 	if (!ap_if->ap) {
src/ap.h +2 -1
index bbfecd6d..a39797aa 100644
@@ -56,7 +56,8 @@ typedef void (*ap_stopped_func_t)(void *user_data);
 
 struct ap_config {
 	char *ssid;
-	char *psk;
+	char passphrase[64];
+	uint8_t psk[32];
 	uint8_t channel;
 	uint8_t *authorized_macs;
 	unsigned int authorized_macs_num;
Signature · 1 line
2.25.1
#2 lore raw

PATCH 3/6 ap: Rename wpa2_psk to wpa2_passphrase on DBus

In reply to Andrew Zaborowski

Use the passphrase naming instead of PSK.

---
 src/ap.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
src/ap.c +6 -4
index 626c983b..4f90323b 100644
@@ -2392,7 +2392,7 @@ static struct l_dbus_message *ap_dbus_start(struct l_dbus *dbus,
 		struct l_dbus_message *message, void *user_data)
 {
 	struct ap_if_data *ap_if = user_data;
-	const char *ssid, *wpa2_psk;
+	const char *ssid, *wpa2_passphrase;
 	struct ap_config *config;
 
 	if (ap_if->ap && ap_if->ap->started)
@@ -2401,12 +2401,14 @@ static struct l_dbus_message *ap_dbus_start(struct l_dbus *dbus,
 	if (ap_if->ap || ap_if->pending)
 		return dbus_error_busy(message);
 
-	if (!l_dbus_message_get_arguments(message, "ss", &ssid, &wpa2_psk))
+	if (!l_dbus_message_get_arguments(message, "ss",
+						&ssid, &wpa2_passphrase))
 		return dbus_error_invalid_args(message);
 
 	config = l_new(struct ap_config, 1);
 	config->ssid = l_strdup(ssid);
-	l_strlcpy(config->passphrase, wpa2_psk, sizeof(config->passphrase));
+	l_strlcpy(config->passphrase, wpa2_passphrase,
+			sizeof(config->passphrase));
 
 	ap_if->ap = ap_start(ap_if->netdev, config, &ap_dbus_ops, ap_if);
 	if (!ap_if->ap) {
@@ -2472,7 +2474,7 @@ static bool ap_dbus_property_get_started(struct l_dbus *dbus,
 static void ap_setup_interface(struct l_dbus_interface *interface)
 {
 	l_dbus_interface_method(interface, "Start", 0, ap_dbus_start, "",
-			"ss", "ssid", "wpa2_psk");
+			"ss", "ssid", "wpa2_passphrase");
 	l_dbus_interface_method(interface, "Stop", 0, ap_dbus_stop, "", "");
 
 	l_dbus_interface_property(interface, "Started", 0, "b",
Signature · 1 line
2.25.1
#3 lore raw

PATCH 4/6 p2p: Start a basic P2P Group after GO Negotiation

In reply to Andrew Zaborowski

Use the ap.c API to start an AP on a P2P_GO interface after we've been selected as the GO in the GO Negotiation.

---
 src/p2p.c | 135 ++++++++++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 122 insertions(+), 13 deletions(-)
src/p2p.c +122 -13
index ac9a8f97..cf4d4bf3 100644
@@ -55,6 +55,7 @@
 #include "src/frame-xchg.h"
 #include "src/nl80211util.h"
 #include "src/netconfig.h"
+#include "src/ap.h"
 #include "src/p2p.h"
 
 struct p2p_device {
@@ -110,6 +111,7 @@ struct p2p_device {
 	uint8_t conn_peer_interface_addr[6];
 
 	struct p2p_group_id_attr go_group_id;
+	struct ap_state *group;
 
 	bool enabled : 1;
 	bool have_roc_cookie : 1;
@@ -123,6 +125,7 @@ struct p2p_device {
 	bool disconnecting : 1;
 	bool is_go : 1;
 	bool conn_go_tie_breaker : 1;
+	bool conn_peer_added : 1;
 };
 
 struct p2p_discovery_user {
@@ -217,8 +220,9 @@ static void p2p_discovery_user_free(void *data)
 
 static inline bool p2p_peer_operational(struct p2p_peer *peer)
 {
-	return peer && peer->dev->conn_netdev && !peer->dev->conn_wsc_bss &&
-		!peer->wsc.pending_connect && !peer->dev->disconnecting;
+	return peer && peer->dev->conn_netdev && !peer->dev->disconnecting &&
+		((!peer->dev->is_go && !peer->dev->conn_wsc_bss) ||
+		 (peer->dev->is_go && peer->dev->conn_peer_added));
 }
 
 static bool p2p_peer_match(const void *a, const void *b)
@@ -457,6 +461,14 @@ static void p2p_connection_reset(struct p2p_device *dev)
 	if (dev->conn_enrollee)
 		wsc_enrollee_cancel(dev->conn_enrollee, false);
 
+	if (dev->group) {
+		ap_free(dev->group);
+		dev->group = NULL;
+		dev->conn_peer_added = false;
+	}
+
+	dev->capability.group_caps = 0;
+
 	if (dev->conn_netdev) {
 		struct l_genl_msg *msg;
 		uint64_t wdev_id = netdev_get_wdev_id(dev->conn_netdev);
@@ -628,10 +640,12 @@ static void p2p_peer_connect_done(struct p2p_device *dev)
 {
 	struct p2p_peer *peer = dev->conn_peer;
 
-	/* We can free anything potentially needed for a retry */
-	scan_bss_free(dev->conn_wsc_bss);
-	dev->conn_wsc_bss = NULL;
-	explicit_bzero(dev->conn_psk, 32);
+	if (!dev->is_go) {
+		/* We can free anything potentially needed for a retry */
+		scan_bss_free(dev->conn_wsc_bss);
+		dev->conn_wsc_bss = NULL;
+		explicit_bzero(dev->conn_psk, 32);
+	}
 
 	dbus_pending_reply(&peer->wsc.pending_connect,
 				l_dbus_message_new_method_return(
@@ -649,6 +663,96 @@ static void p2p_peer_connect_done(struct p2p_device *dev)
 				"ConnectedIP");
 }
 
+static void p2p_group_event(enum ap_event_type type, const void *event_data,
+				void *user_data)
+{
+	struct p2p_device *dev = user_data;
+
+	l_debug("type=%i", type);
+
+	switch (type) {
+	case AP_EVENT_START_FAILED:
+	case AP_EVENT_STOPPING:
+		dev->group = NULL;
+		p2p_connect_failed(dev);
+		break;
+
+	case AP_EVENT_STARTED:
+		ap_push_button(dev->group);
+		break;
+
+	case AP_EVENT_STATION_ADDED:
+		dev->conn_peer_added = true;
+		p2p_peer_connect_done(dev);
+		break;
+
+	case AP_EVENT_STATION_REMOVED:
+		dev->conn_peer_added = false;
+		p2p_connect_failed(dev);
+		break;
+
+	case AP_EVENT_REGISTRATION_START:
+		/* Don't validate the P2P IE or WFD IE at this stage */
+		break;
+	case AP_EVENT_REGISTRATION_SUCCESS:
+		dev->capability.group_caps &= ~P2P_GROUP_CAP_GROUP_FORMATION;
+		break;
+	case AP_EVENT_PBC_MODE_EXIT:
+		break;
+	};
+}
+
+static const struct ap_ops p2p_go_ops = {
+	.handle_event = p2p_group_event,
+};
+
+static void p2p_group_start(struct p2p_device *dev)
+{
+	struct ap_config *config = l_new(struct ap_config, 1);
+
+	config->ssid = l_strdup(dev->go_group_id.ssid);
+	config->channel = dev->listen_channel;
+	config->wsc_name = l_strdup(dev->device_info.device_name);
+	config->wsc_primary_device_type = dev->device_info.primary_device_type;
+	config->no_cck_rates = true;
+
+	/*
+	 * Section 3.2.1: "The Credentials for a P2P Group issued to a
+	 * P2P Device shall: [...]
+	 *  - Use a Network Key Type of 64 Hex characters."
+	 *
+	 * This implies we have to send the PSK and not the passphrase to
+	 * the WSC clients.  For simplicity we directly generate random
+	 * PSKs and don't currently respect the requirement to maintain
+	 * a passphrase.  We have no practical use for the passphrase and
+	 * it's a little costlier to generate for the same cryptographic
+	 * strength as the PSK.
+	 */
+	if (!l_getrandom(config->psk, 32)) {
+		l_error("l_getrandom() failed");
+		ap_config_free(config);
+		p2p_connect_failed(dev);
+		return;
+	}
+
+	/*
+	 * Section 3.1.4.4: "It shall only allow association by the
+	 * P2P Device that it is currently in Group Formation with."
+	 */
+	config->authorized_macs = l_memdup(dev->conn_peer_interface_addr, 6);
+	config->authorized_macs_num = 1;
+
+	dev->capability.group_caps |= P2P_GROUP_CAP_GO;
+	dev->capability.group_caps |= P2P_GROUP_CAP_GROUP_FORMATION;
+
+	dev->group = ap_start(dev->conn_netdev, config, &p2p_go_ops, dev);
+	if (!dev->group) {
+		ap_config_free(config);
+		p2p_connect_failed(dev);
+		return;
+	}
+}
+
 static void p2p_netconfig_event_handler(enum netconfig_event event,
 					void *user_data)
 {
@@ -682,7 +786,7 @@ static void p2p_dhcp_timeout_destroy(void *user_data)
 	dev->conn_dhcp_timeout = NULL;
 }
 
-static void p2p_start_dhcp(struct p2p_device *dev)
+static void p2p_start_dhcp_client(struct p2p_device *dev)
 {
 	uint32_t ifindex = netdev_get_ifindex(dev->conn_netdev);
 	unsigned int dhcp_timeout_val;
@@ -723,7 +827,7 @@ static void p2p_netdev_connect_cb(struct netdev *netdev,
 
 	switch (result) {
 	case NETDEV_RESULT_OK:
-		p2p_start_dhcp(dev);
+		p2p_start_dhcp_client(dev);
 		break;
 	case NETDEV_RESULT_AUTHENTICATION_FAILED:
 	case NETDEV_RESULT_ASSOCIATION_FAILED:
@@ -1034,10 +1138,14 @@ static void p2p_device_netdev_notify(struct netdev *netdev,
 	case NETDEV_WATCH_EVENT_NEW:
 		/* Ignore the event if we're already connecting/connected */
 		if (dev->conn_enrollee || dev->conn_retry_count ||
-				!netdev_get_is_up(netdev))
+				dev->group || !netdev_get_is_up(netdev))
 			break;
 
-		p2p_provision_connect(dev);
+		if (dev->is_go)
+			p2p_group_start(dev);
+		else
+			p2p_provision_connect(dev);
+
 		break;
 	case NETDEV_WATCH_EVENT_DEL:
 		dev->conn_netdev = NULL;
@@ -1094,13 +1202,14 @@ static void p2p_device_new_interface_destroy(void *user_data)
 
 static void p2p_device_interface_create(struct p2p_device *dev)
 {
-	uint32_t iftype = NL80211_IFTYPE_P2P_CLIENT;
+	uint32_t iftype = dev->is_go ? NL80211_IFTYPE_P2P_GO :
+		NL80211_IFTYPE_P2P_CLIENT;
 	char ifname[32];
 	uint32_t wiphy_id = dev->wdev_id >> 32;
 	struct l_genl_msg *msg;
 
-	snprintf(ifname, sizeof(ifname), "wlan%i-p2p-cl%i",
-			wiphy_id, dev->conn_num++);
+	snprintf(ifname, sizeof(ifname), "wlan%i-p2p-%s%i",
+			wiphy_id, dev->is_go ? "go" : "cl", dev->conn_num++);
 	l_debug("creating %s", ifname);
 
 	msg = l_genl_msg_new(NL80211_CMD_NEW_INTERFACE);
Signature · 1 line
2.25.1
#4 lore raw

PATCH 5/6 p2p: Try IP allocation during 4-Way handshake on client

In reply to Andrew Zaborowski
---
 src/p2p.c | 60 +++++++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 50 insertions(+), 10 deletions(-)
src/p2p.c +50 -10
index cf4d4bf3..5ee887d3 100644
@@ -32,6 +32,8 @@
 #include <stdio.h>
 #include <time.h>
 #include <errno.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
 
 #include <ell/ell.h>
 
@@ -97,7 +99,9 @@ struct p2p_device {
 	uint32_t conn_new_intf_cmd_id;
 	struct wsc_enrollee *conn_enrollee;
 	struct netconfig *conn_netconfig;
+	struct l_settings *conn_netconfig_settings;
 	struct l_timeout *conn_dhcp_timeout;
+	char *conn_peer_ip;
 	struct p2p_wfd_properties *conn_own_wfd;
 	uint8_t conn_psk[32];
 	int conn_retry_count;
@@ -109,6 +113,7 @@ struct p2p_device {
 	unsigned int conn_go_scan_retry;
 	uint32_t conn_go_oper_freq;
 	uint8_t conn_peer_interface_addr[6];
+	struct p2p_capability_attr conn_peer_capability;
 
 	struct p2p_group_id_attr go_group_id;
 	struct ap_state *group;
@@ -446,6 +451,9 @@ static void p2p_connection_reset(struct p2p_device *dev)
 	if (dev->conn_netconfig) {
 		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;
 	}
 
 	if (dev->conn_new_intf_cmd_id)
@@ -761,6 +769,11 @@ static void p2p_netconfig_event_handler(enum netconfig_event event,
 	switch (event) {
 	case NETCONFIG_EVENT_CONNECTED:
 		l_timeout_remove(dev->conn_dhcp_timeout);
+
+		if (!dev->conn_peer_ip)
+			dev->conn_peer_ip = netconfig_get_dhcp_server_ipv4(
+							dev->conn_netconfig);
+
 		p2p_peer_connect_done(dev);
 		break;
 	default:
@@ -786,10 +799,11 @@ static void p2p_dhcp_timeout_destroy(void *user_data)
 	dev->conn_dhcp_timeout = NULL;
 }
 
-static void p2p_start_dhcp_client(struct p2p_device *dev)
+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))
@@ -803,9 +817,9 @@ static void p2p_start_dhcp_client(struct p2p_device *dev)
 		}
 	}
 
-	netconfig_configure(dev->conn_netconfig, p2p_dhcp_settings,
-				dev->conn_addr, p2p_netconfig_event_handler,
-				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,
 						p2p_dhcp_timeout, dev,
 						p2p_dhcp_timeout_destroy);
@@ -827,7 +841,7 @@ static void p2p_netdev_connect_cb(struct netdev *netdev,
 
 	switch (result) {
 	case NETDEV_RESULT_OK:
-		p2p_start_dhcp_client(dev);
+		p2p_start_client_netconfig(dev);
 		break;
 	case NETDEV_RESULT_AUTHENTICATION_FAILED:
 	case NETDEV_RESULT_ASSOCIATION_FAILED:
@@ -916,6 +930,13 @@ static void p2p_netdev_event(struct netdev *netdev, enum netdev_event event,
 	};
 }
 
+static const char *p2p_ip_to_string(uint32_t addr)
+{
+	struct in_addr ia = { .s_addr = L_CPU_TO_BE32(addr) };
+
+	return inet_ntoa(ia);
+}
+
 static void p2p_handshake_event(struct handshake_state *hs,
 				enum handshake_event event, void *user_data,
 				...)
@@ -925,6 +946,24 @@ static void p2p_handshake_event(struct handshake_state *hs,
 	va_start(args, user_data);
 
 	switch (event) {
+	case HANDSHAKE_EVENT_COMPLETE:
+	{
+		struct p2p_device *dev = user_data;
+		struct l_settings *ip_config;
+
+		if (!hs->support_ip_allocation)
+			break;
+
+		ip_config = l_settings_new();
+		l_settings_set_string(ip_config, "IPv4", "Address",
+					p2p_ip_to_string(hs->client_ip_addr));
+		l_settings_set_string(ip_config, "IPv4", "Netmask",
+					p2p_ip_to_string(hs->subnet_mask));
+		dev->conn_netconfig_settings = ip_config;
+		dev->conn_peer_ip = l_strdup(p2p_ip_to_string(hs->go_ip_addr));
+
+		break;
+	}
 	case HANDSHAKE_EVENT_FAILED:
 		netdev_handshake_failed(hs, va_arg(args, int));
 		break;
@@ -993,6 +1032,9 @@ static void p2p_try_connect_group(struct p2p_device *dev)
 	handshake_state_set_ssid(hs, bss->ssid, bss->ssid_len);
 	handshake_state_set_pmk(hs, dev->conn_psk, 32);
 
+	if (dev->conn_peer_capability.group_caps & P2P_GROUP_CAP_IP_ALLOCATION)
+		hs->support_ip_allocation = true;
+
 	r = netdev_connect(dev->conn_netdev, bss, hs, ie_iov, ie_num,
 				p2p_netdev_event, p2p_netdev_connect_cb, dev);
 	if (r < 0) {
@@ -1393,6 +1435,7 @@ static bool p2p_provision_scan_notify(int err, struct l_queue *bss_list,
 		l_debug("GO found in the scan results");
 
 		dev->conn_wsc_bss = bss;
+		dev->conn_peer_capability = *capability;
 		p2p_device_interface_create(dev);
 		l_queue_remove(bss_list, bss);
 		l_queue_destroy(bss_list,
@@ -4405,14 +4448,11 @@ static bool p2p_peer_get_connected_ip(struct l_dbus *dbus,
 					void *user_data)
 {
 	struct p2p_peer *peer = user_data;
-	char *server_ip;
 
-	if (!p2p_peer_operational(peer))
+	if (!p2p_peer_operational(peer) || !peer->dev->conn_peer_ip)
 		return false;
 
-	server_ip = netconfig_get_dhcp_server_ipv4(peer->dev->conn_netconfig);
-	l_dbus_message_builder_append_basic(builder, 's', server_ip);
-	l_free(server_ip);
+	l_dbus_message_builder_append_basic(builder, 's', peer->dev->conn_peer_ip);
 	return true;
 }
 
Signature · 1 line
2.25.1
#5 lore raw

PATCH 6/6 treewide: Use l_settings_{set,get}_bytes

In reply to Andrew Zaborowski
---
 src/ap.c           | 14 ++++----------
 src/eap-mschapv2.c | 39 ++++++++++++---------------------------
 src/eap-wsc.c      | 23 +++++++++--------------
 src/hotspot.c      | 26 ++++++++++++++------------
 src/network.c      | 30 +++++++++++++++---------------
 src/wsc.c          | 13 ++++---------
 unit/test-wsc.c    | 36 +++++++++++-------------------------
 7 files changed, 69 insertions(+), 112 deletions(-)
src/ap.c +4 -10
index 4f90323b..da2a3a82 100644
@@ -768,21 +768,15 @@ static void ap_start_eap_wsc(struct sta_state *sta)
 	 */
 	bool wait_for_eapol_start = !sta->wsc_v2;
 
-	L_AUTO_FREE_VAR(char *, uuid_r_str) = NULL;
-	L_AUTO_FREE_VAR(char *, uuid_e_str) = NULL;
-
-	uuid_r_str = l_util_hexstring(ap->wsc_uuid_r, 16);
-	uuid_e_str = l_util_hexstring(sta->wsc_uuid_e, 16);
-
 	sta->wsc_settings = l_settings_new();
 	l_settings_set_string(sta->wsc_settings, "Security", "EAP-Method",
 				"WSC-R");
 	l_settings_set_string(sta->wsc_settings, "WSC", "EnrolleeMAC",
 				util_address_to_string(sta->addr));
-	l_settings_set_string(sta->wsc_settings, "WSC", "UUID-R",
-				uuid_r_str);
-	l_settings_set_string(sta->wsc_settings, "WSC", "UUID-E",
-				uuid_e_str);
+	l_settings_set_bytes(sta->wsc_settings, "WSC", "UUID-R",
+				ap->wsc_uuid_r, 16);
+	l_settings_set_bytes(sta->wsc_settings, "WSC", "UUID-E",
+				sta->wsc_uuid_e, 16);
 	l_settings_set_uint(sta->wsc_settings, "WSC", "RFBand",
 				WSC_RF_BAND_2_4_GHZ);
 	l_settings_set_uint(sta->wsc_settings, "WSC", "ConfigurationMethods",
src/eap-mschapv2.c +12 -27
index 49b5335c..7eac260b 100644
@@ -428,13 +428,14 @@ static int eap_mschapv2_check_settings(struct l_settings *settings,
 					const char *prefix,
 					struct l_queue **out_missing)
 {
-	const char *password_hash;
+	L_AUTO_FREE_VAR(uint8_t *, password_hash) = NULL;
 	L_AUTO_FREE_VAR(char *, password) = NULL;
 	L_AUTO_FREE_VAR(char *, identity);
 	const struct eap_secret_info *secret;
 	char setting[64], setting2[64];
 	uint8_t hash[16];
 	int r = 0;
+	size_t hash_len;
 
 	snprintf(setting, sizeof(setting), "%sIdentity", prefix);
 	identity = l_settings_get_string(settings, "Security", setting);
@@ -460,8 +461,8 @@ static int eap_mschapv2_check_settings(struct l_settings *settings,
 	password = l_settings_get_string(settings, "Security", setting2);
 
 	snprintf(setting, sizeof(setting), "%sPassword-Hash", prefix);
-	password_hash = l_settings_get_value(settings, "Security",
-						setting);
+	password_hash = l_settings_get_bytes(settings, "Security",
+						setting, &hash_len);
 
 	if (password && password_hash) {
 		l_error("Exactly one of (%s, %s) must be present",
@@ -471,16 +472,7 @@ static int eap_mschapv2_check_settings(struct l_settings *settings,
 	}
 
 	if (password_hash) {
-		unsigned char *tmp;
-		size_t len;
-
-		tmp = l_util_from_hexstring(password_hash, &len);
-		if (tmp)
-			explicit_bzero(tmp, len);
-
-		l_free(tmp);
-
-		if (!tmp || len != 16) {
+		if (hash_len != 16) {
 			l_error("Property %s is not a 16-byte hexstring",
 				setting);
 			return -EINVAL;
@@ -534,22 +526,15 @@ static bool eap_mschapv2_load_settings(struct eap_state *eap,
 		set_password_from_string(state, password);
 		explicit_bzero(password, strlen(password));
 	} else {
-		unsigned char *tmp;
-		size_t len;
-		const char *hash_str;
+		size_t hash_len;
+		uint8_t *hash;
 
 		snprintf(setting, sizeof(setting), "%sPassword-Hash", prefix);
-		hash_str = l_settings_get_value(settings, "Security", setting);
-		if (!hash_str)
-			goto error;
-
-		tmp = l_util_from_hexstring(hash_str, &len);
-		if (!tmp)
-			goto error;
-
-		memcpy(state->password_hash, tmp, len);
-		explicit_bzero(tmp, len);
-		l_free(tmp);
+		hash = l_settings_get_bytes(settings, "Security", setting,
+						&hash_len);
+		memcpy(state->password_hash, hash, 16);
+		explicit_bzero(hash, 16);
+		l_free(hash);
 	}
 
 	eap_set_data(eap, state);
src/eap-wsc.c +9 -14
index 5b87924a..817cf82f 100644
@@ -1718,27 +1718,22 @@ static void eap_wsc_handle_retransmit(struct eap_state *eap,
 static bool load_hexencoded(struct l_settings *settings, const char *key,
 						uint8_t *to, size_t len)
 {
-	const char *v;
-	size_t decoded_len;
-	unsigned char *decoded;
+	uint8_t *v;
+	size_t v_len;
 
-	v = l_settings_get_value(settings, "WSC", key);
+	v = l_settings_get_bytes(settings, "WSC", key, &v_len);
 	if (!v)
 		return false;
 
-	decoded = l_util_from_hexstring(v, &decoded_len);
-	if (!decoded)
-		return false;
-
-	if (decoded_len != len) {
-		explicit_bzero(decoded, decoded_len);
-		l_free(decoded);
+	if (v_len != len) {
+		explicit_bzero(v, v_len);
+		l_free(v);
 		return false;
 	}
 
-	memcpy(to, decoded, len);
-	explicit_bzero(decoded, decoded_len);
-	l_free(decoded);
+	memcpy(to, v, len);
+	explicit_bzero(v, v_len);
+	l_free(v);
 
 	return true;
 }
src/hotspot.c +14 -12
index 0db42eb0..ea11d59a 100644
@@ -319,7 +319,8 @@ static struct hs20_config *hs20_config_new(struct l_settings *settings,
 	struct hs20_config *config;
 	char *hessid_str;
 	char **nai_realms = NULL;
-	const char *rc_str;
+	size_t rc_len;
+	uint8_t *rc;
 	char *name;
 	bool autoconnect;
 
@@ -329,7 +330,8 @@ static struct hs20_config *hs20_config_new(struct l_settings *settings,
 	nai_realms = l_settings_get_string_list(settings, "Hotspot",
 						"NAIRealmNames", ',');
 
-	rc_str = l_settings_get_value(settings, "Hotspot", "RoamingConsortium");
+	rc = l_settings_get_bytes(settings, "Hotspot", "RoamingConsortium",
+								&rc_len);
 
 	if (!l_settings_get_bool(settings, "Settings", "AutoConnect",
 								&autoconnect))
@@ -337,7 +339,7 @@ static struct hs20_config *hs20_config_new(struct l_settings *settings,
 
 	name = l_settings_get_string(settings, "Hotspot", "Name");
 
-	if ((!hessid_str && !nai_realms && !rc_str) || !name) {
+	if ((!hessid_str && !nai_realms && !rc) || !name) {
 		l_error("Could not parse hotspot config %s", filename);
 		goto free_values;
 	}
@@ -357,22 +359,21 @@ static struct hs20_config *hs20_config_new(struct l_settings *settings,
 	if (nai_realms)
 		config->nai_realms = nai_realms;
 
-	if (rc_str) {
-		config->rc = l_util_from_hexstring(rc_str,
-							&config->rc_len);
+	if (rc) {
 		/*
 		 * WiFi Alliance Hotspot 2.0 Spec - Section 3.1.4
 		 *
 		 * "The Consortium OI field is 3 or 5-octet field set to a value
 		 * of a roaming consortium OI"
 		 */
-		if (config->rc && config->rc_len != 3 &&
-						config->rc_len != 5) {
-			l_warn("invalid RoamingConsortium length %zu",
-					config->rc_len);
-			l_free(config->rc);
-			config->rc = NULL;
+		if (rc && rc_len != 3 && rc_len != 5) {
+			l_warn("invalid RoamingConsortium length %zu", rc_len);
+			l_free(rc);
+			rc = NULL;
 		}
+
+		config->rc = rc;
+		config->rc_len = rc_len;
 	}
 
 	config->super.is_autoconnectable = autoconnect;
@@ -392,6 +393,7 @@ free_values:
 	l_strv_free(nai_realms);
 	l_free(hessid_str);
 	l_free(name);
+	l_free(rc);
 
 	return NULL;
 }
src/network.c +15 -15
index a7d59ca0..3e856aa1 100644
@@ -374,16 +374,18 @@ static int network_load_psk(struct network *network, bool need_passphrase)
 {
 	const char *ssid = network_get_ssid(network);
 	enum security security = network_get_security(network);
-	size_t len;
-	const char *psk = l_settings_get_value(network->settings,
-						"Security", "PreSharedKey");
+	size_t psk_len;
+	uint8_t *psk = l_settings_get_bytes(network->settings, "Security",
+						"PreSharedKey", &psk_len);
 	char *passphrase = l_settings_get_string(network->settings,
 						"Security", "Passphrase");
 	int r;
 
 	/* PSK can be generated from the passphrase but not the other way */
-	if ((!psk || need_passphrase) && !passphrase)
+	if ((!psk || need_passphrase) && !passphrase) {
+		l_free(psk);
 		return -ENOKEY;
+	}
 
 	network_reset_passphrase(network);
 	network_reset_psk(network);
@@ -392,11 +394,10 @@ static int network_load_psk(struct network *network, bool need_passphrase)
 	if (psk) {
 		char *path;
 
-		network->psk = l_util_from_hexstring(psk, &len);
-		if (network->psk && len == 32)
+		if (psk_len == 32) {
+			network->psk = psk;
 			return 0;
-
-		network_reset_psk(network);
+		}
 
 		path = storage_get_network_file_path(security, ssid);
 		l_error("%s: invalid PreSharedKey format", path);
@@ -439,15 +440,14 @@ void network_sync_psk(struct network *network)
 	fs_settings = storage_network_open(SECURITY_PSK, ssid);
 
 	if (network->psk) {
-		char *hex = l_util_hexstring(network->psk, 32);
-		l_settings_set_value(network->settings, "Security",
-						"PreSharedKey", hex);
+		l_settings_set_bytes(network->settings, "Security",
+						"PreSharedKey",
+						network->psk, 32);
 
 		if (fs_settings)
-			l_settings_set_value(fs_settings, "Security",
-						"PreSharedKey", hex);
-
-		l_free(hex);
+			l_settings_set_bytes(fs_settings, "Security",
+						"PreSharedKey",
+						network->psk, 32);
 	}
 
 	if (network->passphrase) {
src/wsc.c +4 -9
index fa91f459..66ddb8bf 100644
@@ -536,15 +536,10 @@ static void wsc_store_credentials(struct wsc_credentials_info *creds,
 		l_debug("Storing credential for '%s(%s)'", ssid,
 						security_to_str(security));
 
-		if (security == SECURITY_PSK) {
-			char *hex = l_util_hexstring(creds[i].psk,
-						sizeof(creds[i].psk));
-
-			l_settings_set_value(settings, "Security",
-							"PreSharedKey", hex);
-			explicit_bzero(hex, strlen(hex));
-			l_free(hex);
-		}
+		if (security == SECURITY_PSK)
+			l_settings_set_bytes(settings, "Security",
+						"PreSharedKey", creds[i].psk,
+                                                sizeof(creds[i].psk));
 
 		storage_network_sync(security, ssid, settings);
 		l_settings_free(settings);
unit/test-wsc.c +11 -25
index 2063244c..f2e9b864 100644
@@ -2005,7 +2005,6 @@ static void wsc_test_pbc_handshake(const void *data)
 	struct verify_data verify;
 	struct handshake_state *hs;
 	struct eapol_sm *sm;
-	char *hex;
 	struct l_settings *settings;
 
 	eap_init();
@@ -2037,16 +2036,11 @@ static void wsc_test_pbc_handshake(const void *data)
 					"0-00000000-0");
 	l_settings_set_string(settings, "WSC", "EnrolleeMAC",
 					util_address_to_string(sta_address));
-
-	hex = l_util_hexstring(m1_data_2.expected.enrollee_nonce, 16);
-	l_settings_set_string(settings, "WSC", "EnrolleeNonce", hex);
-	l_free(hex);
-
-	hex = l_util_hexstring(m1_data_2.private_key,
-						m1_data_2.private_key_size);
-	l_settings_set_string(settings, "WSC", "PrivateKey", hex);
-	l_free(hex);
-
+	l_settings_set_bytes(settings, "WSC", "EnrolleeNonce",
+				m1_data_2.expected.enrollee_nonce, 16);
+	l_settings_set_bytes(settings, "WSC", "PrivateKey",
+				m1_data_2.private_key,
+				m1_data_2.private_key_size);
 	l_settings_set_string(settings, "WSC", "E-SNonce1",
 					"fdbb480ee6f572f3591cc3b364f2185b");
 	l_settings_set_string(settings, "WSC", "E-SNonce2",
@@ -2111,7 +2105,6 @@ static void wsc_test_retransmission_no_fragmentation(const void *data)
 	struct verify_data verify;
 	struct handshake_state *hs;
 	struct eapol_sm *sm;
-	char *hex;
 	struct l_settings *settings;
 
 	eap_init();
@@ -2143,16 +2136,11 @@ static void wsc_test_retransmission_no_fragmentation(const void *data)
 					"0-00000000-0");
 	l_settings_set_string(settings, "WSC", "EnrolleeMAC",
 					util_address_to_string(sta_address));
-
-	hex = l_util_hexstring(m1_data_2.expected.enrollee_nonce, 16);
-	l_settings_set_string(settings, "WSC", "EnrolleeNonce", hex);
-	l_free(hex);
-
-	hex = l_util_hexstring(m1_data_2.private_key,
-						m1_data_2.private_key_size);
-	l_settings_set_string(settings, "WSC", "PrivateKey", hex);
-	l_free(hex);
-
+	l_settings_set_bytes(settings, "WSC", "EnrolleeNonce",
+				m1_data_2.expected.enrollee_nonce, 16);
+	l_settings_set_bytes(settings, "WSC", "PrivateKey",
+				m1_data_2.private_key,
+				m1_data_2.private_key_size);
 	l_settings_set_string(settings, "WSC", "E-SNonce1",
 					"fdbb480ee6f572f3591cc3b364f2185b");
 	l_settings_set_string(settings, "WSC", "E-SNonce2",
@@ -2479,11 +2467,9 @@ static void wsc_r_test_pbc_handshake(const void *data)
 		.expected_creds = *expected_creds,
 	};
 	uint8_t uuid_e[16];
-	L_AUTO_FREE_VAR(char *, uuid_e_str) = NULL;
 	char ssid_str[33];
 
 	wsc_uuid_from_addr(s.sta_address, uuid_e);
-	uuid_e_str = l_util_hexstring(uuid_e, 16);
 
 	memcpy(wsc_data.expected_creds.addr, s.sta_address, 6);
 	memset(wsc_data.expected_creds.ssid + expected_creds->ssid_len, 0,
@@ -2500,7 +2486,7 @@ static void wsc_r_test_pbc_handshake(const void *data)
 					strlen(ap_8021x_str));
 	l_settings_set_string(ap_8021x_settings, "WSC", "EnrolleeMAC",
 				util_address_to_string(s.sta_address));
-	l_settings_set_string(ap_8021x_settings, "WSC", "UUID-E", uuid_e_str);
+	l_settings_set_bytes(ap_8021x_settings, "WSC", "UUID-E", uuid_e, 16);
 
 	if (expected_creds->auth_type == WSC_AUTHENTICATION_TYPE_WPA2_PERSONAL) {
 		l_settings_set_string(ap_8021x_settings, "WSC",
Signature · 1 line
2.25.1
#6 lore raw

Re: [PATCH 6/6] treewide: Use l_settings_{set,get}_bytes

Hi Andrew,

Quoted 10 lines · Andrew Zaborowski
---
  src/ap.c           | 14 ++++----------
  src/eap-mschapv2.c | 39 ++++++++++++---------------------------
  src/eap-wsc.c      | 23 +++++++++--------------
  src/hotspot.c      | 26 ++++++++++++++------------
  src/network.c      | 30 +++++++++++++++---------------
  src/wsc.c          | 13 ++++---------
  unit/test-wsc.c    | 36 +++++++++++-------------------------
  7 files changed, 69 insertions(+), 112 deletions(-)

Applied, thanks.

Regards,
-Denis

#7 lore raw
In reply to Andrew Zaborowski

Hi Andrew,

Quoted 7 lines · Andrew Zaborowski

Pass the event callback function pointer in a "struct ap_ops" instead of as individual ap_start() argument to make adding new callbacks easier.

---
  src/ap.c | 65 +++++++++++++++++++++++++++++++-------------------------
  src/ap.h |  9 +++++---
  2 files changed, 42 insertions(+), 32 deletions(-)

Patches 1-5 applied, thanks.

Regards,
-Denis