diff mbox

[PATCHv2,10c/21] VLAN: Use new data type for VLAN description.

Message ID c90ff9623644aa263ff05ef827ca7eeea27c31de2.1370512966.git.michael-dev@fami-braun.de
State Superseded
Headers show

Commit Message

michael-dev May 17, 2013, 9:44 a.m. UTC
This hides away the details of the currently in-use VLAN model
and is preparing for adding tagged VLAN support later on.
Implementing this as inline functions lets the compiler create
as fast code as before the change.

Signed-hostap: Michael Braun <michael-dev@fami-braun.de>

 create mode 100644 src/common/vlan.h
diff mbox

Patch

diff --git a/src/common/vlan.h b/src/common/vlan.h
new file mode 100644
index 0000000..fdfb187
--- /dev/null
+++ b/src/common/vlan.h
@@ -0,0 +1,53 @@ 
+/*
+ * hostapd / VLAN definitions and helpers functions
+ * Copyright (c) 2013, Michael Braun <michael-dev@fami-braun.de>
+ *
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
+ */
+
+#ifndef HOSTAPD_VLAN_H
+#define HOSTAPD_VLAN_H
+
+#define VLAN_NULL 0
+typedef uint16_t vlan_t;
+
+static inline void vlan_alloc(vlan_t *dst, const int untagged)
+{
+	*dst = untagged;
+}
+
+static inline void vlan_alloc_copy(vlan_t *dst, const vlan_t *src)
+{
+	*dst = *src;
+}
+
+static inline void vlan_free(vlan_t *dst)
+{
+	*dst = 0;
+}
+
+static inline int vlan_cmp(const vlan_t *a, const vlan_t *b)
+{
+	if (!a && !b)
+		return 1;
+	if (!a || !b)
+		return 0;
+	return (*a == *b);
+}
+
+static inline int vlan_untagged(const vlan_t *a)
+{
+	if (!a)
+		return 0;
+	return *a;
+}
+
+static inline int vlan_notempty(const vlan_t *a)
+{
+	if (!a)
+		return 0;
+	return *a;
+}
+
+#endif
diff --git a/src/drivers/driver.h b/src/drivers/driver.h
index 03fc2b3..6b9392d 100644
--- a/src/drivers/driver.h
+++ b/src/drivers/driver.h
@@ -20,6 +20,7 @@ 
 #define WPA_SUPPLICANT_DRIVER_VERSION 4
 
 #include "common/defs.h"
+#include "common/vlan.h"
 
 #define HOSTAPD_CHAN_DISABLED 0x00000001
 #define HOSTAPD_CHAN_PASSIVE_SCAN 0x00000002
@@ -1932,7 +1933,7 @@  struct wpa_driver_ops {
 	 * domains to be used with a single BSS.
 	 */
 	int (*set_sta_vlan)(void *priv, const u8 *addr, const char *ifname,
-			    int vlan_id);
+			    vlan_t vlan_id);
 
 	/**
 	 * commit - Optional commit changes handler (AP only)
diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
index e1e27ea..215aaf4 100644
--- a/src/drivers/driver_nl80211.c
+++ b/src/drivers/driver_nl80211.c
@@ -8149,7 +8149,7 @@  static int i802_set_tx_queue_params(void *priv, int queue, int aifs,
 
 
 static int i802_set_sta_vlan(struct i802_bss *bss, const u8 *addr,
-			     const char *ifname, int vlan_id)
+			     const char *ifname, vlan_t vlan_id)
 {
 	struct wpa_driver_nl80211_data *drv = bss->drv;
 	struct nl_msg *msg;
@@ -8172,7 +8172,7 @@  static int i802_set_sta_vlan(struct i802_bss *bss, const u8 *addr,
 	if (ret < 0) {
 		wpa_printf(MSG_ERROR, "nl80211: NL80211_ATTR_STA_VLAN (addr="
 			   MACSTR " ifname=%s vlan_id=%d) failed: %d (%s)",
-			   MAC2STR(addr), ifname, vlan_id, ret,
+			   MAC2STR(addr), ifname, vlan_untagged(&vlan_id), ret,
 			   strerror(-ret));
 	}
  nla_put_failure:
@@ -8342,13 +8342,13 @@  static int i802_set_wds_sta(void *priv, const u8 *addr, int aid, int val,
 			wpa_printf(MSG_ERROR, "nl80211: Failed to set WDS STA "
 				   "interface %s up", name);
 		}
-		return i802_set_sta_vlan(priv, addr, name, 0);
+		return i802_set_sta_vlan(priv, addr, name, VLAN_NULL);
 	} else {
 		if (bridge_ifname)
 			linux_br_del_if(drv->global->ioctl_sock, bridge_ifname,
 					name);
 
-		i802_set_sta_vlan(priv, addr, bss->ifname, 0);
+		i802_set_sta_vlan(priv, addr, bss->ifname, VLAN_NULL);
 		return wpa_driver_nl80211_if_remove(priv, WPA_IF_AP_VLAN,
 						    name);
 	}
@@ -9889,7 +9889,7 @@  static int driver_nl80211_sta_remove(void *priv, const u8 *addr)
 
 #if defined(HOSTAPD) || defined(CONFIG_AP)
 static int driver_nl80211_set_sta_vlan(void *priv, const u8 *addr,
-				       const char *ifname, int vlan_id)
+				       const char *ifname, vlan_t vlan_id)
 {
 	struct i802_bss *bss = priv;
 	return i802_set_sta_vlan(bss, addr, ifname, vlan_id);
diff --git a/src/drivers/driver_test.c b/src/drivers/driver_test.c
index 541ebcc..e19845f 100644
--- a/src/drivers/driver_test.c
+++ b/src/drivers/driver_test.c
@@ -1127,10 +1127,10 @@  static int test_driver_set_privacy(void *priv, int enabled)
 
 
 static int test_driver_set_sta_vlan(void *priv, const u8 *addr,
-				    const char *ifname, int vlan_id)
+				    const char *ifname, vlan_t vlan_id)
 {
 	wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " ifname=%s vlan_id=%d)",
-		   __func__, MAC2STR(addr), ifname, vlan_id);
+		   __func__, MAC2STR(addr), ifname, vlan_untagged(&vlan_id));
 	return 0;
 }
 
diff --git a/wpa_supplicant/ibss_rsn.c b/wpa_supplicant/ibss_rsn.c
index 046f181..f74844d 100644
--- a/wpa_supplicant/ibss_rsn.c
+++ b/wpa_supplicant/ibss_rsn.c
@@ -261,7 +261,7 @@  static int auth_send_eapol(void *ctx, const u8 *addr, const u8 *data,
 }
 
 
-static int auth_set_key(void *ctx, int vlan_id, enum wpa_alg alg,
+static int auth_set_key(void *ctx, vlan_t vlan_id, enum wpa_alg alg,
 			const u8 *addr, int idx, u8 *key, size_t key_len)
 {
 	struct ibss_rsn *ibss_rsn = ctx;
diff --git a/wpa_supplicant/tests/link_test.c b/wpa_supplicant/tests/link_test.c
index 3bfbed5..a772586 100644
--- a/wpa_supplicant/tests/link_test.c
+++ b/wpa_supplicant/tests/link_test.c
@@ -40,7 +40,7 @@  void ap_sta_session_timeout(struct hostapd_data *hapd, struct sta_info *sta,
 
 
 int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta,
-		     int old_vlanid)
+		     vlan_t old_vlanid)
 {
 	return 0;
 }
@@ -77,7 +77,8 @@  hostapd_get_eap_user(const struct hostapd_bss_config *conf, const u8 *identity,
 }
 
 
-const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id)
+const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan,
+                                        vlan_t vlan_id)
 {
 	return NULL;
 }