Forced WPS version support for 60G

Add support for forcing WPS version sent in WPS IE. This is needed for
60 GHz WPS tests.

Signed-off-by: Alexei Avshalom Lazar <ailizaro@codeaurora.org>
diff --git a/ap.c b/ap.c
index 2d37062..3aebc00 100644
--- a/ap.c
+++ b/ap.c
@@ -1454,6 +1454,10 @@
 		dut->wsc_fragment = 1;
 	}
 
+	val = get_param(cmd, "WpsVersion");
+	if (val)
+		dut->wps_forced_version = get_wps_forced_version(dut, val);
+
 	val = get_param(cmd, "WscEAPFragment");
 	if (val && strcasecmp(val, "enable") == 0)
 		dut->eap_fragment = 1;
@@ -7651,6 +7655,16 @@
 		}
 	}
 
+	if (dut->wps_forced_version) {
+		snprintf(buf, sizeof(buf), "SET wps_version_number %d",
+			 dut->wps_forced_version);
+		if (hapd_command(ifname, buf) < 0) {
+			send_resp(dut, conn, SIGMA_ERROR,
+				  "errorCode,Fail to set wps_version_number");
+			return STATUS_SENT;
+		}
+	}
+
 	dut->hostapd_running = 1;
 	return 1;
 }
@@ -7938,6 +7952,7 @@
 
 	dut->wsc_fragment = 0;
 	dut->eap_fragment = 0;
+	dut->wps_forced_version = 0;
 
 	if (dut->program == PROGRAM_HT || dut->program == PROGRAM_VHT) {
 		dut->ap_wme = AP_WME_ON;
diff --git a/sigma_dut.h b/sigma_dut.h
index fad77c4..c0eb022 100644
--- a/sigma_dut.h
+++ b/sigma_dut.h
@@ -737,6 +737,7 @@
 	int wps_disable; /* Used for 60G to disable PCP from sending WPS IE */
 	int wsc_fragment; /* simulate WSC IE fragmentation */
 	int eap_fragment; /* simulate EAP fragmentation */
+	int wps_forced_version; /* Used to force reported WPS version */
 	enum {
 		/* no change */
 		FORCE_RSN_IE_NONE = 0,
@@ -963,6 +964,7 @@
 			 char *pin, size_t len);
 void str_remove_chars(char *str, char ch);
 
+int get_wps_forced_version(struct sigma_dut *dut, const char *str);
 int base64_encode(const char *src, size_t len, char *out, size_t out_len);
 int random_get_bytes(char *buf, size_t len);
 
diff --git a/sta.c b/sta.c
index 7989b69..4aae8cb 100644
--- a/sta.c
+++ b/sta.c
@@ -3223,6 +3223,10 @@
 			dut->force_rsn_ie = FORCE_RSN_IE_ADD;
 	}
 
+	val = get_param(cmd, "WpsVersion");
+	if (val)
+		dut->wps_forced_version = get_wps_forced_version(dut, val);
+
 	val = get_param(cmd, "WscEAPFragment");
 	if (val && strcasecmp(val, "enable") == 0)
 		dut->eap_fragment = 1;
@@ -7051,6 +7055,8 @@
 	wpa_command(intf, "ERP_FLUSH");
 	wpa_command(intf, "SET radio_disabled 0");
 
+	dut->wps_forced_version = 0;
+
 	if (dut->wsc_fragment) {
 		dut->wsc_fragment = 0;
 		wpa_command(intf, "SET device_name Test client");
diff --git a/utils.c b/utils.c
index 5bb2836..d2343a3 100644
--- a/utils.c
+++ b/utils.c
@@ -603,6 +603,25 @@
 }
 
 
+int get_wps_forced_version(struct sigma_dut *dut, const char *str)
+{
+	int major, minor, result = 0;
+	int count = sscanf(str, "%d.%d", &major, &minor);
+
+	if (count == 2) {
+		result = major * 16 + minor;
+		sigma_dut_print(dut, DUT_MSG_DEBUG,
+				"Force WPS version to 0x%02x (%s)",
+				result, str);
+	} else {
+		sigma_dut_print(dut, DUT_MSG_ERROR,
+				"Invalid WPS version %s", str);
+	}
+
+	return result;
+}
+
+
 void str_remove_chars(char *str, char ch)
 {
 	char *pr = str, *pw = str;