mac80211: update to wireless-testing 2010-10-06
[openwrt/openwrt.git] / package / mac80211 / patches / 020-nl80211_backport.patch
1 --- a/include/linux/compat-2.6.37.h
2 +++ b/include/linux/compat-2.6.37.h
3 @@ -45,6 +45,68 @@ static inline void skb_checksum_none_ass
4
5 #define pcmcia_enable_device(link) pcmcia_request_configuration(link, &link->conf)
6
7 +#include <net/genetlink.h>
8 +
9 +struct compat_genl_info {
10 + struct genl_info *info;
11 +
12 + u32 snd_seq;
13 + u32 snd_pid;
14 + struct genlmsghdr *genlhdr;
15 + struct nlattr **attrs;
16 + void *user_ptr[2];
17 +};
18 +#define genl_info compat_genl_info
19 +
20 +struct compat_genl_ops {
21 + struct genl_ops ops;
22 +
23 + u8 cmd;
24 + u8 internal_flags;
25 + unsigned int flags;
26 + const struct nla_policy *policy;
27 +
28 + int (*doit)(struct sk_buff *skb, struct genl_info *info);
29 + int (*dumpit)(struct sk_buff *skb, struct netlink_callback *cb);
30 + int (*done)(struct netlink_callback *cb);
31 +};
32 +#define genl_ops compat_genl_ops
33 +
34 +struct compat_genl_family {
35 + struct genl_family family;
36 +
37 + struct list_head list;
38 +
39 + unsigned int id, hdrsize, version, maxattr;
40 + const char *name;
41 + bool netnsok;
42 +
43 + struct nlattr **attrbuf;
44 +
45 + int (*pre_doit)(struct genl_ops *ops, struct sk_buff *skb,
46 + struct genl_info *info);
47 +
48 + void (*post_doit)(struct genl_ops *ops, struct sk_buff *skb,
49 + struct genl_info *info);
50 +};
51 +
52 +#define genl_family compat_genl_family
53 +
54 +#define genl_register_family_with_ops compat_genl_register_family_with_ops
55 +
56 +int genl_register_family_with_ops(struct genl_family *family,
57 + struct genl_ops *ops, size_t n_ops);
58 +
59 +#define genl_unregister_family compat_genl_unregister_family
60 +
61 +int genl_unregister_family(struct genl_family *family);
62 +
63 +#define genl_info_net(_info) genl_info_net((_info)->info)
64 +#define genlmsg_reply(_msg, _info) genlmsg_reply(_msg, (_info)->info)
65 +#define genlmsg_put(_skb, _pid, _seq, _fam, _flags, _cmd) genlmsg_put(_skb, _pid, _seq, &(_fam)->family, _flags, _cmd)
66 +#define genl_register_mc_group(_fam, _grp) genl_register_mc_group(&(_fam)->family, _grp)
67 +#define genl_unregister_mc_group(_fam, _grp) genl_unregister_mc_group(&(_fam)->family, _grp)
68 +
69 #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,37)) */
70
71 #endif /* LINUX_26_37_COMPAT_H */
72 --- a/compat/compat-2.6.37.c
73 +++ b/compat/compat-2.6.37.c
74 @@ -42,4 +42,116 @@ EXPORT_SYMBOL_GPL(net_ns_type_operations
75
76 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)*/
77
78 +#undef genl_info
79 +#undef genl_unregister_family
80 +
81 +static LIST_HEAD(compat_nl_fam);
82 +
83 +static struct genl_ops *genl_get_cmd(u8 cmd, struct genl_family *family)
84 +{
85 + struct genl_ops *ops;
86 +
87 + list_for_each_entry(ops, &family->family.ops_list, ops.ops_list)
88 + if (ops->cmd == cmd)
89 + return ops;
90 +
91 + return NULL;
92 +}
93 +
94 +
95 +static int nl_doit_wrapper(struct sk_buff *skb, struct genl_info *info)
96 +{
97 + struct compat_genl_info compat_info;
98 + struct genl_family *family;
99 + struct genl_ops *ops;
100 + int err;
101 +
102 + list_for_each_entry(family, &compat_nl_fam, list) {
103 + if (family->id == info->nlhdr->nlmsg_type)
104 + goto found;
105 + }
106 + return -ENOENT;
107 +
108 +found:
109 + ops = genl_get_cmd(info->genlhdr->cmd, family);
110 + if (!ops)
111 + return -ENOENT;
112 +
113 + memset(&compat_info.user_ptr, 0, sizeof(compat_info.user_ptr));
114 + compat_info.info = info;
115 +#define __copy(_field) compat_info._field = info->_field
116 + __copy(snd_seq);
117 + __copy(snd_pid);
118 + __copy(genlhdr);
119 + __copy(attrs);
120 +#undef __copy
121 + if (family->pre_doit) {
122 + err = family->pre_doit(ops, skb, &compat_info);
123 + if (err)
124 + return err;
125 + }
126 +
127 + err = ops->doit(skb, &compat_info);
128 +
129 + if (family->post_doit)
130 + family->post_doit(ops, skb, &compat_info);
131 +
132 + return err;
133 +}
134 +
135 +int compat_genl_register_family_with_ops(struct genl_family *family,
136 + struct genl_ops *ops, size_t n_ops)
137 +{
138 + int i, ret;
139 +
140 +#define __copy(_field) family->family._field = family->_field
141 + __copy(id);
142 + __copy(hdrsize);
143 + __copy(version);
144 + __copy(maxattr);
145 + strncpy(family->family.name, family->name, sizeof(family->family.name));
146 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32))
147 + __copy(netnsok);
148 +#endif
149 +#undef __copy
150 +
151 + ret = genl_register_family(&family->family);
152 + if (ret < 0)
153 + return ret;
154 +
155 + family->attrbuf = family->family.attrbuf;
156 + family->id = family->family.id;
157 +
158 + for (i = 0; i < n_ops; i++) {
159 +#define __copy(_field) ops[i].ops._field = ops[i]._field
160 + __copy(cmd);
161 + __copy(flags);
162 + __copy(policy);
163 + __copy(dumpit);
164 + __copy(done);
165 +#undef __copy
166 + ops[i].ops.doit = nl_doit_wrapper;
167 + ret = genl_register_ops(&family->family, &ops[i].ops);
168 + if (ret < 0)
169 + goto error_ops;
170 + }
171 + list_add(&family->list, &compat_nl_fam);
172 +
173 + return ret;
174 +
175 +error_ops:
176 + compat_genl_unregister_family(family);
177 + return ret;
178 +}
179 +EXPORT_SYMBOL(compat_genl_register_family_with_ops);
180 +
181 +int compat_genl_unregister_family(struct genl_family *family)
182 +{
183 + int err;
184 + err = genl_unregister_family(&family->family);
185 + list_del(&family->list);
186 + return err;
187 +}
188 +EXPORT_SYMBOL(compat_genl_unregister_family);
189 +
190 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,37) */