[PATCH 08/25] OCV: Add utility functions to insert OCI elements

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This commit adds utility functions to insert various encoding of the OCI
element.

Signed-off-by: Mathy Vanhoef <Mathy.Vanhoef@xxxxxxxxxxxxxx>
---
 hostapd/Android.mk           |  1 +
 hostapd/Makefile             |  1 +
 src/common/ieee802_11_defs.h |  1 +
 src/common/ocv.c             | 94 ++++++++++++++++++++++++++++++++++++
 src/common/ocv.h             | 37 ++++++++++++++
 src/common/wpa_common.h      |  2 +
 wpa_supplicant/Android.mk    |  1 +
 wpa_supplicant/Makefile      |  1 +
 8 files changed, 138 insertions(+)
 create mode 100644 src/common/ocv.c
 create mode 100644 src/common/ocv.h

diff --git a/hostapd/Android.mk b/hostapd/Android.mk
index 82d43c754..bdc87067c 100644
--- a/hostapd/Android.mk
+++ b/hostapd/Android.mk
@@ -237,6 +237,7 @@ endif
 
 ifdef CONFIG_OCV
 L_CFLAGS += -DCONFIG_OCV
+OBJS += src/common/ocv.c
 CONFIG_IEEE80211W=y
 endif
 
diff --git a/hostapd/Makefile b/hostapd/Makefile
index d88964c32..5fa174b96 100644
--- a/hostapd/Makefile
+++ b/hostapd/Makefile
@@ -280,6 +280,7 @@ endif
 
 ifdef CONFIG_OCV
 CFLAGS += -DCONFIG_OCV
+OBJS += ../src/common/ocv.o
 CONFIG_IEEE80211W=y
 endif
 
diff --git a/src/common/ieee802_11_defs.h b/src/common/ieee802_11_defs.h
index e03a09530..db4d42f29 100644
--- a/src/common/ieee802_11_defs.h
+++ b/src/common/ieee802_11_defs.h
@@ -467,6 +467,7 @@
 #define WLAN_EID_EXT_PASSWORD_IDENTIFIER 33
 #define WLAN_EID_EXT_HE_CAPABILITIES 35
 #define WLAN_EID_EXT_HE_OPERATION 36
+#define WLAN_EID_EXT_OCV_OCI 45
 
 
 /* Action frame categories (IEEE Std 802.11-2016, 9.4.1.11, Table 9-76) */
diff --git a/src/common/ocv.c b/src/common/ocv.c
new file mode 100644
index 000000000..be8ef68ac
--- /dev/null
+++ b/src/common/ocv.c
@@ -0,0 +1,94 @@
+/*
+ * Operating Channel Validation (OCV)
+ * Copyright (c) 2018, Mathy Vanhoef
+ *
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
+ */
+
+#include <stdint.h>
+
+#include "utils/includes.h"
+#include "utils/common.h"
+#include "drivers/driver.h"
+#include "common/ieee802_11_common.h"
+#include "ocv.h"
+
+/**
+ * Caller of OCV functionality may use various debug output functions, so store
+ * the error here and let the caller use an appropriate debug output function.
+ */
+char ocv_errorstr[256];
+
+
+int ocv_derive_all_parameters(struct oci_info *oci)
+{
+	const struct oper_class_map *op_class_map;
+
+	oci->freq = ieee80211_chan_to_freq(NULL, oci->op_class, oci->channel);
+	if (oci->freq < 0) {
+		wpa_printf(MSG_INFO, "Error interpreting OCI: unrecognized "
+			   "opclass/channel pair (%d/%d)", oci->op_class, oci->channel);
+		return -1;
+	}
+
+	op_class_map = get_oper_class(NULL, oci->op_class);
+	if (op_class_map == NULL) {
+		wpa_printf(MSG_INFO,  "Error interpreting OCI: Unrecognized "
+			   "opclass (%d)", oci->op_class);
+		return -1;
+	}
+
+	oci->chanwidth = oper_class_bw_to_int(op_class_map);
+	oci->sec_channel = 0;
+	if (op_class_map->bw == BW40PLUS)
+		oci->sec_channel = 1;
+	else if (op_class_map->bw == BW40MINUS)
+		oci->sec_channel = -1;
+
+	return 0;
+}
+
+
+int ocv_insert_oci(struct wpa_channel_info *ci, u8 **argpos)
+{
+	u8 op_class, channel;
+	u8 *pos = *argpos;
+
+	if (ieee80211_chaninfo_to_channel(ci->frequency, ci->chanwidth,
+					  ci->sec_channel, &op_class, &channel) < 0) {
+		wpa_printf(MSG_WARNING, "Cannot determine operating class "
+			   "and channel for OCI element");
+		return -1;
+	}
+
+	*pos++ = op_class;
+	*pos++ = channel;
+	*pos++ = ci->seg1_idx;
+
+	*argpos = pos;
+	return 0;
+}
+
+
+int ocv_insert_oci_kde(struct wpa_channel_info *ci, u8 **argpos)
+{
+	u8 *pos = *argpos;
+
+	*pos++ = WLAN_EID_VENDOR_SPECIFIC;
+	*pos++ = RSN_SELECTOR_LEN + 3;
+	RSN_SELECTOR_PUT(pos, RSN_KEY_DATA_OCI);
+	pos += RSN_SELECTOR_LEN;
+
+	*argpos = pos;
+	return ocv_insert_oci(ci, argpos);
+}
+
+
+int ocv_insert_extended_oci(struct wpa_channel_info *ci, u8 *pos)
+{
+	*pos++ = WLAN_EID_EXTENSION;
+	*pos++ = 1 + OCV_OCI_LEN;
+	*pos++ = WLAN_EID_EXT_OCV_OCI;
+	return ocv_insert_oci(ci, &pos);
+}
diff --git a/src/common/ocv.h b/src/common/ocv.h
new file mode 100644
index 000000000..b88835345
--- /dev/null
+++ b/src/common/ocv.h
@@ -0,0 +1,37 @@
+/*
+ * Operating Channel Validation (OCV)
+ * Copyright (c) 2018, Mathy Vanhoef
+ *
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
+ */
+
+#ifndef OCV_H
+#define OCV_H
+
+struct wpa_channel_info;
+
+struct oci_info {
+	/** Values in the OCI element */
+	u8 op_class;
+	u8 channel;
+	u8 seg1_idx;
+
+	/** Derived values for easier verification */
+	int freq;
+	int sec_channel;
+	int chanwidth;
+};
+
+#define OCV_OCI_LEN		3
+#define OCV_OCI_EXTENDED_LEN	(3 + OCV_OCI_LEN)
+#define OCV_OCI_KDE_LEN		(2 + RSN_SELECTOR_LEN + OCV_OCI_LEN)
+
+extern char ocv_errorstr[256];
+
+int ocv_derive_all_parameters(struct oci_info *oci);
+int ocv_insert_oci(struct wpa_channel_info *ci, u8 **argpos);
+int ocv_insert_oci_kde(struct wpa_channel_info *ci, u8 **argpos);
+int ocv_insert_extended_oci(struct wpa_channel_info *ci, u8 *pos);
+
+#endif /* OCV_H */
diff --git a/src/common/wpa_common.h b/src/common/wpa_common.h
index 7d12b5e52..b21b1385e 100644
--- a/src/common/wpa_common.h
+++ b/src/common/wpa_common.h
@@ -110,6 +110,7 @@ WPA_CIPHER_BIP_CMAC_256)
 #define RSN_KEY_DATA_KEYID RSN_SELECTOR(0x00, 0x0f, 0xac, 10)
 #define RSN_KEY_DATA_MULTIBAND_GTK RSN_SELECTOR(0x00, 0x0f, 0xac, 11)
 #define RSN_KEY_DATA_MULTIBAND_KEYID RSN_SELECTOR(0x00, 0x0f, 0xac, 12)
+#define RSN_KEY_DATA_OCI RSN_SELECTOR(0x00, 0x0f, 0xac, 13)
 
 #define WFA_KEY_DATA_IP_ADDR_REQ RSN_SELECTOR(0x50, 0x6f, 0x9a, 4)
 #define WFA_KEY_DATA_IP_ADDR_ALLOC RSN_SELECTOR(0x50, 0x6f, 0x9a, 5)
@@ -327,6 +328,7 @@ struct rsn_ftie_sha384 {
 #define FTIE_SUBELEM_GTK 2
 #define FTIE_SUBELEM_R0KH_ID 3
 #define FTIE_SUBELEM_IGTK 4
+#define FTIE_SUBELEM_OCI 5
 
 struct rsn_rdie {
 	u8 id;
diff --git a/wpa_supplicant/Android.mk b/wpa_supplicant/Android.mk
index f3b6d2cfa..d63e4c41c 100644
--- a/wpa_supplicant/Android.mk
+++ b/wpa_supplicant/Android.mk
@@ -209,6 +209,7 @@ endif
 
 ifdef CONFIG_OCV
 L_CFLAGS += -DCONFIG_OCV
+OBJS += src/common/ocv.c
 CONFIG_IEEE80211W=y
 endif
 
diff --git a/wpa_supplicant/Makefile b/wpa_supplicant/Makefile
index 69132bb57..958ea97c2 100644
--- a/wpa_supplicant/Makefile
+++ b/wpa_supplicant/Makefile
@@ -242,6 +242,7 @@ endif
 
 ifdef CONFIG_OCV
 CFLAGS += -DCONFIG_OCV
+OBJS += ../src/common/ocv.o
 CONFIG_IEEE80211W=y
 endif
 
-- 
2.18.0

_______________________________________________
Hostap mailing list
Hostap@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/hostap



[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux