Re: [PATCH] cfg80211: new wireless config infrastructure

2007-04-25 Thread Ingo Oeser
Hi there,

John W. Linville schrieb:
> From: Johannes Berg <[EMAIL PROTECTED]>
> --- /dev/null
> +++ b/net/wireless/core.c
> @@ -0,0 +1,209 @@
> +/*
> + * This is the linux wireless configuration interface.
> + *
> + * Copyright 2006, 2007  Johannes Berg <[EMAIL PROTECTED]>
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include "core.h"
> +#include "sysfs.h"
> +
> +/* name for sysfs, %d is appended */
> +#define PHY_NAME "phy"
> +
> +MODULE_AUTHOR("Johannes Berg");
> +MODULE_LICENSE("GPL");
> +MODULE_DESCRIPTION("wireless configuration support");
> +
> +/* RCU might be appropriate here since we usually
> + * only read the list, and that can happen quite
> + * often because we need to do it for each command */
> +LIST_HEAD(cfg80211_drv_list);
> +DEFINE_MUTEX(cfg80211_drv_mutex);
> +static int wiphy_counter;
> +
> +/* for debugfs */
> +static struct dentry *ieee80211_debugfs_dir;
> +
> +/* exported functions */
> +
> +struct wiphy *wiphy_new(struct cfg80211_ops *ops, int sizeof_priv)
> +{
> + struct cfg80211_registered_device *drv;
> + int alloc_size;
> +
> + alloc_size = sizeof(*drv) + sizeof_priv;
> +
> + drv = kzalloc(alloc_size, GFP_KERNEL);
> + if (!drv)
> + return NULL;
> +
> + drv->ops = ops;
> +
> + mutex_lock(&cfg80211_drv_mutex);
> +
> + if (unlikely(wiphy_counter<0)) {

mutex_unlock(&cfg80211_drv_mutex);

> + /* ugh, wrapped! */
> + kfree(drv);
> + return NULL;
> + }
> + drv->idx = wiphy_counter;
> +
> + /* give it a proper name */
> + snprintf(drv->wiphy.dev.bus_id, BUS_ID_SIZE,
> +  PHY_NAME "%d", drv->idx);
> +
> + /* now increase counter for the next time */
> + wiphy_counter++;
> + mutex_unlock(&cfg80211_drv_mutex);

Since drv and its contents are not visible to anyone yet, 
I suggest the following code flow for that:

mutex_lock(&cfg80211_drv_mutex);

drv->idx = wiphy_counter;

/* increase counter for the next time, if id didn't wrap */
if (drv->idx >= 0)
wiphy_counter++;

mutex_unlock(&cfg80211_drv_mutex);

if (drv->idx < 0) {
kfree(drv);
return NULL;
}

/* give it a proper name */
snprintf(drv->wiphy.dev.bus_id, BUS_ID_SIZE,
 PHY_NAME "%d", drv->idx);

[enqueue to all lists here]


Rest looks good so far.

Regards

Ingo Oeser
-
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] cfg80211: new wireless config infrastructure

2007-04-23 Thread John W. Linville
From: Johannes Berg <[EMAIL PROTECTED]>

This patch creates the core cfg80211 code along with some sysfs bits.
This is a stripped down version to allow mac80211 to function, but
doesn't include any configuration yet except for creating and removing
virtual interfaces.

This patch includes the nl80211 header file but it only contains the
interface types which the cfg80211 interface for creating virtual
interfaces relies on.

Signed-off-by: Johannes Berg <[EMAIL PROTECTED]>
Signed-off-by: John W. Linville <[EMAIL PROTECTED]>
---
 CREDITS   |6 ++
 MAINTAINERS   |6 ++
 include/linux/Kbuild  |1 +
 include/linux/netdevice.h |4 +
 include/linux/nl80211.h   |   38 
 include/net/cfg80211.h|   36 
 include/net/wireless.h|  139 ++
 net/wireless/Kconfig  |3 +
 net/wireless/Makefile |4 +-
 net/wireless/core.c   |  209 +
 net/wireless/core.h   |   49 +++
 net/wireless/sysfs.c  |   80 +
 net/wireless/sysfs.h  |9 ++
 13 files changed, 583 insertions(+), 1 deletions(-)
 create mode 100644 include/linux/nl80211.h
 create mode 100644 include/net/cfg80211.h
 create mode 100644 include/net/wireless.h
 create mode 100644 net/wireless/core.c
 create mode 100644 net/wireless/core.h
 create mode 100644 net/wireless/sysfs.c
 create mode 100644 net/wireless/sysfs.h

diff --git a/CREDITS b/CREDITS
index e3e7271..dede114 100644
--- a/CREDITS
+++ b/CREDITS
@@ -317,6 +317,12 @@ S: 2322 37th Ave SW
 S: Seattle, Washington 98126-2010
 S: USA
 
+N: Johannes Berg
+E: [EMAIL PROTECTED]
+W: http://johannes.sipsolutions.net/
+P: 1024D/9AB78CA5 AD02 0176 4E29 C137 1DF6 08D2 FC44 CF86 9AB7 8CA5
+D: powerpc & 802.11 hacker
+
 N: Stephen R. van den Berg (AKA BuGless)
 E: [EMAIL PROTECTED]
 D: General kernel, gcc, and libc hacker
diff --git a/MAINTAINERS b/MAINTAINERS
index a15ec1a..3994eee 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -894,6 +894,12 @@ M: [EMAIL PROTECTED]
 L: [EMAIL PROTECTED]
 S: Maintained
 
+CFG80211 and NL80211
+P: Johannes Berg
+M: [EMAIL PROTECTED]
+L: [EMAIL PROTECTED]
+S: Maintained
+
 COMMON INTERNET FILE SYSTEM (CIFS)
 P: Steve French
 M: [EMAIL PROTECTED]
diff --git a/include/linux/Kbuild b/include/linux/Kbuild
index ea86f2e..4ff0f57 100644
--- a/include/linux/Kbuild
+++ b/include/linux/Kbuild
@@ -113,6 +113,7 @@ header-y += netrom.h
 header-y += nfs2.h
 header-y += nfs4_mount.h
 header-y += nfs_mount.h
+header-y += nl80211.h
 header-y += oom.h
 header-y += param.h
 header-y += pci_regs.h
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 71fc8ff..584c199 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -42,6 +42,8 @@
 struct vlan_group;
 struct ethtool_ops;
 struct netpoll_info;
+/* 802.11 specific */
+struct wireless_dev;
/* source back-compat hooks */
 #define SET_ETHTOOL_OPS(netdev,ops) \
( (netdev)->ethtool_ops = (ops) )
@@ -400,6 +402,8 @@ struct net_device
void*ip6_ptr;   /* IPv6 specific data */
void*ec_ptr;/* Econet specific data */
void*ax25_ptr;  /* AX.25 specific data */
+   struct wireless_dev *ieee80211_ptr; /* IEEE 802.11 specific data,
+  assign before registering */
 
 /*
  * Cache line mostly used on receive path (including eth_type_trans())
diff --git a/include/linux/nl80211.h b/include/linux/nl80211.h
new file mode 100644
index 000..9a30ba2
--- /dev/null
+++ b/include/linux/nl80211.h
@@ -0,0 +1,38 @@
+#ifndef __LINUX_NL80211_H
+#define __LINUX_NL80211_H
+/*
+ * 802.11 netlink interface public header
+ *
+ * Copyright 2006, 2007 Johannes Berg <[EMAIL PROTECTED]>
+ */
+
+/**
+ * enum nl80211_iftype - (virtual) interface types
+ * @NL80211_IFTYPE_UNSPECIFIED: unspecified type, driver decides
+ * @NL80211_IFTYPE_ADHOC: independent BSS member
+ * @NL80211_IFTYPE_STATION: managed BSS member
+ * @NL80211_IFTYPE_AP: access point
+ * @NL80211_IFTYPE_AP_VLAN: VLAN interface for access points
+ * @NL80211_IFTYPE_WDS: wireless distribution interface
+ * @NL80211_IFTYPE_MONITOR: monitor interface receiving all frames
+ * @__NL80211_IFTYPE_AFTER_LAST: internal use
+ *
+ * These values are used with the NL80211_ATTR_IFTYPE
+ * to set the type of an interface.
+ *
+ */
+enum nl80211_iftype {
+   NL80211_IFTYPE_UNSPECIFIED,
+   NL80211_IFTYPE_ADHOC,
+   NL80211_IFTYPE_STATION,
+   NL80211_IFTYPE_AP,
+   NL80211_IFTYPE_AP_VLAN,
+   NL80211_IFTYPE_WDS,
+   NL80211_IFTYPE_MONITOR,
+
+   /* keep last */
+   __NL80211_IFTYPE_AFTER_LAST
+};
+#define NL80211_IFTYPE_MAX (__NL80211_IFTYPE_AFTER_LAST - 1)
+
+#endif /* __LINUX_NL80211_H */
diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
new file m