]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
OCV: Add utility functions to insert OCI elements
authorMathy Vanhoef <Mathy.Vanhoef@cs.kuleuven.be>
Mon, 6 Aug 2018 19:46:26 +0000 (15:46 -0400)
committerJouni Malinen <j@w1.fi>
Sun, 16 Dec 2018 22:02:14 +0000 (00:02 +0200)
This commit adds utility functions to insert various encoding of the OCI
element.

Signed-off-by: Mathy Vanhoef <Mathy.Vanhoef@cs.kuleuven.be>
hostapd/Android.mk
hostapd/Makefile
src/common/ocv.c [new file with mode: 0644]
src/common/ocv.h [new file with mode: 0644]
wpa_supplicant/Android.mk
wpa_supplicant/Makefile

index 82d43c75464b65abf874a9daee2058d3f9de5cfa..bdc87067c7e5ec3225278783742a201b613f9033 100644 (file)
@@ -237,6 +237,7 @@ endif
 
 ifdef CONFIG_OCV
 L_CFLAGS += -DCONFIG_OCV
+OBJS += src/common/ocv.c
 CONFIG_IEEE80211W=y
 endif
 
index d88964c3280fb25d89a639e376b4cc8486e7325b..5fa174b969608a876842149bb699d682b17e540e 100644 (file)
@@ -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/ocv.c b/src/common/ocv.c
new file mode 100644 (file)
index 0000000..17f3855
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ * 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 "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) {
+               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 (file)
index 0000000..3f77438
--- /dev/null
@@ -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 */
index f3b6d2cfab3082ac96f639e12b02e09e487e0e54..d63e4c41c7360669bcdb7054eaddfbcfb2319a93 100644 (file)
@@ -209,6 +209,7 @@ endif
 
 ifdef CONFIG_OCV
 L_CFLAGS += -DCONFIG_OCV
+OBJS += src/common/ocv.c
 CONFIG_IEEE80211W=y
 endif
 
index 69132bb57328bd52e90afaee6ea90638f7d1f591..958ea97c2030e235dc89feb09a923d928ed1008d 100644 (file)
@@ -242,6 +242,7 @@ endif
 
 ifdef CONFIG_OCV
 CFLAGS += -DCONFIG_OCV
+OBJS += ../src/common/ocv.o
 CONFIG_IEEE80211W=y
 endif