[RFC 3/3] wpa_supplicant: Use -m to specify a global configuration file

Ilan Peer ilan.peer
Thu Mar 20 01:38:25 PDT 2014


Modify the -m switch so it could be used to specify a global
configuration file that holds the wpa_supplicant wide configuration
parameters such as WPS and P2P configuration parameters.

For non P2P Device interfaces, this configuration file would be
processed to extract the common global configuration data.

For the P2P Device interface, this configuration file would be used as
the main configuration file of the interface. In such a case if the
configuration file is not specified, the wpa_supplicant will fail to
initialize.

Signed-off-by: Ilan Peer <ilan.peer at intel.com>
---
 wpa_supplicant/main.c             |   25 +++++++++++++++++--------
 wpa_supplicant/p2p_supplicant.c   |   16 ++--------------
 wpa_supplicant/p2p_supplicant.h   |    3 ++-
 wpa_supplicant/wpa_supplicant.c   |   15 +++++++--------
 wpa_supplicant/wpa_supplicant_i.h |   19 ++++++++-----------
 5 files changed, 36 insertions(+), 42 deletions(-)

diff --git a/wpa_supplicant/main.c b/wpa_supplicant/main.c
index d2e839d..1cbcbf3 100644
--- a/wpa_supplicant/main.c
+++ b/wpa_supplicant/main.c
@@ -44,7 +44,7 @@ static void usage(void)
 	       "        [-N -i<ifname> -c<conf> [-C<ctrl>] "
 	       "[-D<driver>] \\\n"
 #ifdef CONFIG_P2P
-	       "        [-m<P2P Device config file>] \\\n"
+	       "        [-m<Common global config file>] \\\n"
 #endif /* CONFIG_P2P */
 	       "        [-p<driver_param>] [-b<br_ifname>] [-I<config file>] "
 	       "...]\n"
@@ -96,7 +96,7 @@ static void usage(void)
 	printf("  -v = show version\n"
 	       "  -W = wait for a control interface monitor before starting\n"
 #ifdef CONFIG_P2P
-	       "  -m = Configuration file for the P2P Device interface\n"
+	       "  -m = Common global configuration file for WPS, P2P etc.\n"
 #endif /* CONFIG_P2P */
 	       "  -N = start describing new interface\n");
 
@@ -159,6 +159,7 @@ int main(int argc, char *argv[])
 	int iface_count, exitcode = -1;
 	struct wpa_params params;
 	struct wpa_global *global;
+	char *conf_common = NULL;
 
 	if (os_program_init())
 		return -1;
@@ -235,11 +236,9 @@ int main(int argc, char *argv[])
 			license();
 			exitcode = 0;
 			goto out;
-#ifdef CONFIG_P2P
 		case 'm':
-			iface->conf_p2p_dev = optarg;
+			conf_common = optarg;
 			break;
-#endif /* CONFIG_P2P */
 		case 'o':
 			params.override_driver = optarg;
 			break;
@@ -322,6 +321,7 @@ int main(int argc, char *argv[])
 			exitcode = -1;
 			break;
 		}
+		ifaces[i].conf_common = conf_common;
 		wpa_s = wpa_supplicant_add_iface(global, &ifaces[i]);
 		if (wpa_s == NULL) {
 			exitcode = -1;
@@ -330,9 +330,18 @@ int main(int argc, char *argv[])
 #ifdef CONFIG_P2P
 		if (wpa_s->global->p2p == NULL &&
 		    (wpa_s->drv_flags &
-		     WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
-		    wpas_p2p_add_p2pdev_interface(wpa_s) < 0)
-			exitcode = -1;
+		     WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
+			if (conf_common) {
+				if (wpas_p2p_add_p2pdev_interface(wpa_s,
+								  conf_common)
+				    < 0)
+					exitcode = -1;
+			} else {
+				wpa_printf(MSG_ERROR,
+					   "-m must be specified when using a dedicate P2P_DEVICE interface");
+				exitcode = -1;
+			}
+		}
 #endif /* CONFIG_P2P */
 	}
 
diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c
index 487d44d..aaa9512 100644
--- a/wpa_supplicant/p2p_supplicant.c
+++ b/wpa_supplicant/p2p_supplicant.c
@@ -3654,7 +3654,7 @@ static void wpas_p2p_debug_print(void *ctx, int level, const char *msg)
 }
 
 
-int wpas_p2p_add_p2pdev_interface(struct wpa_supplicant *wpa_s)
+int wpas_p2p_add_p2pdev_interface(struct wpa_supplicant *wpa_s, char *confname)
 {
 	struct wpa_interface iface;
 	struct wpa_supplicant *p2pdev_wpa_s;
@@ -3677,23 +3677,11 @@ int wpas_p2p_add_p2pdev_interface(struct wpa_supplicant *wpa_s)
 
 	os_memset(&iface, 0, sizeof(iface));
 	iface.p2p_mgmt = 1;
+	iface.confname = confname;
 	iface.ifname = wpa_s->pending_interface_name;
 	iface.driver = wpa_s->driver->name;
 	iface.driver_param = wpa_s->conf->driver_param;
 
-	/*
-	 * If a P2P Device configuration file was given, use it as the interface
-	 * configuration file (instead of using parent's configuration file.
-	 */
-	if (wpa_s->conf_p2p_dev) {
-		iface.confname = wpa_s->conf_p2p_dev;
-		iface.ctrl_interface = NULL;
-	} else {
-		iface.confname = wpa_s->confname;
-		iface.ctrl_interface = wpa_s->conf->ctrl_interface;
-	}
-	iface.conf_p2p_dev = NULL;
-
 	p2pdev_wpa_s = wpa_supplicant_add_iface(wpa_s->global, &iface);
 	if (!p2pdev_wpa_s) {
 		wpa_printf(MSG_DEBUG, "P2P: Failed to add P2P Device interface");
diff --git a/wpa_supplicant/p2p_supplicant.h b/wpa_supplicant/p2p_supplicant.h
index d3d36b1..403fdd2 100644
--- a/wpa_supplicant/p2p_supplicant.h
+++ b/wpa_supplicant/p2p_supplicant.h
@@ -19,7 +19,8 @@ struct wps_event_fail;
 int wpas_p2p_init(struct wpa_global *global, struct wpa_supplicant *wpa_s);
 void wpas_p2p_deinit(struct wpa_supplicant *wpa_s);
 void wpas_p2p_deinit_global(struct wpa_global *global);
-int wpas_p2p_add_p2pdev_interface(struct wpa_supplicant *wpa_s);
+int wpas_p2p_add_p2pdev_interface(struct wpa_supplicant *wpa_s,
+				  char *confname);
 int wpas_p2p_connect(struct wpa_supplicant *wpa_s, const u8 *peer_addr,
 		     const char *pin, enum p2p_wps_method wps_method,
 		     int persistent_group, int auto_join, int join,
diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c
index 499dcb3..e3d563b 100644
--- a/wpa_supplicant/wpa_supplicant.c
+++ b/wpa_supplicant/wpa_supplicant.c
@@ -397,10 +397,8 @@ static void wpa_supplicant_cleanup(struct wpa_supplicant *wpa_s)
 	os_free(wpa_s->confanother);
 	wpa_s->confanother = NULL;
 
-#ifdef CONFIG_P2P
-	os_free(wpa_s->conf_p2p_dev);
-	wpa_s->conf_p2p_dev = NULL;
-#endif /* CONFIG_P2P */
+	os_free(wpa_s->conf_common);
+	wpa_s->conf_common = NULL;
 
 	wpa_sm_set_eapol(wpa_s->wpa, NULL);
 	eapol_sm_deinit(wpa_s->eapol);
@@ -3411,10 +3409,11 @@ static int wpa_supplicant_init_iface(struct wpa_supplicant *wpa_s,
 		wpa_s->confanother = os_rel2abs_path(iface->confanother);
 		wpa_config_read(wpa_s->confanother, wpa_s->conf);
 
-#ifdef CONFIG_P2P
-		wpa_s->conf_p2p_dev = os_rel2abs_path(iface->conf_p2p_dev);
-		wpa_config_read(wpa_s->conf_p2p_dev, wpa_s->conf);
-#endif /* CONFIG_P2P */
+		if (iface->conf_common) {
+			wpa_s->conf_common =
+				os_rel2abs_path(iface->conf_common);
+			wpa_config_read_common(wpa_s->conf_common, wpa_s->conf);
+		}
 
 		/*
 		 * Override ctrl_interface and driver_param if set on command
diff --git a/wpa_supplicant/wpa_supplicant_i.h b/wpa_supplicant/wpa_supplicant_i.h
index 739b11f..a887f94 100644
--- a/wpa_supplicant/wpa_supplicant_i.h
+++ b/wpa_supplicant/wpa_supplicant_i.h
@@ -64,16 +64,16 @@ struct wpa_interface {
 	 */
 	const char *confanother;
 
-#ifdef CONFIG_P2P
 	/**
-	 * conf_p2p_dev - Additional configuration file used to hold the
-	 * P2P Device configuration parameters.
+	 * conf_common - Configuration file for global common parameters.
 	 *
-	 * This can also be %NULL. In such a case, if a P2P Device dedicated
-	 * interfaces is created, the main configuration file will be used.
+	 * This can be used to specify global parameters that should be common
+	 * among all the wpa_supplicant interfaces. This among other includes
+	 * the WPS configuration parameters and P2P configuration parameters and
+	 * networks. In case a dedicated P2P Device interface is created, this
+	 * configuration file would be used as the main configuration file.
 	 */
-	const char *conf_p2p_dev;
-#endif /* CONFIG_P2P */
+	const char *conf_common;
 
 	/**
 	 * ctrl_interface - Control interface parameter
@@ -397,10 +397,7 @@ struct wpa_supplicant {
 
 	char *confname;
 	char *confanother;
-
-#ifdef CONFIG_P2P
-	char *conf_p2p_dev;
-#endif /* CONFIG_P2P */
+	char *conf_common;
 
 	struct wpa_config *conf;
 	int countermeasures;
-- 
1.7.10.4




More information about the Hostap mailing list