2 hostapd/driver_devicescape.c | 330 ++++++++++++++++++++++++++++++++-----------
3 1 file changed, 249 insertions(+), 81 deletions(-)
5 --- hostap.orig/hostapd/driver_devicescape.c 2007-11-09 13:41:15.000000000 +0100
6 +++ hostap/hostapd/driver_devicescape.c 2007-11-09 13:41:16.000000000 +0100
7 @@ -75,8 +75,14 @@ struct i802_driver_data {
9 #define HAPD_DECL struct hostapd_data *hapd = iface->bss[0]
11 -static int i802_sta_set_flags(void *priv, const u8 *addr,
12 - int total_flags, int flags_or, int flags_and);
13 +/* helper for netlink get routines */
14 +static int ack_wait_handler(struct nl_msg *msg, void *arg)
16 + int *finished = arg;
23 static int hostapd_set_iface_flags(struct i802_driver_data *drv, int dev_up)
24 @@ -255,14 +261,6 @@ static int get_key_handler(struct nl_msg
28 -static int ack_wait_handler(struct nl_msg *msg, void *arg)
30 - int *finished = arg;
36 static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr,
39 @@ -629,43 +627,126 @@ static int i802_get_retry(void *priv, in
40 static int i802_flush(void *priv)
42 struct i802_driver_data *drv = priv;
43 - struct prism2_hostapd_param param;
47 - memset(¶m, 0, sizeof(param));
48 - param.cmd = PRISM2_HOSTAPD_FLUSH;
49 - return hostapd_ioctl(drv, ¶m, sizeof(param));
50 + msg = nlmsg_alloc();
54 + genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
55 + 0, NL80211_CMD_NEW_STATION, 0);
58 + * XXX: FIX! this needs to flush all VLANs too
60 + NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
61 + if_nametoindex(drv->iface));
65 + if (nl_send_auto_complete(drv->nl_handle, msg) < 0 ||
66 + nl_wait_for_ack(drv->nl_handle) < 0) {
78 +static int get_sta_handler(struct nl_msg *msg, void *arg)
80 + struct nlattr *tb[NL80211_ATTR_MAX + 1];
81 + struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
82 + struct hostap_sta_driver_data *data = arg;
83 + struct nlattr *stats[NL80211_STA_STAT_MAX + 1];
84 + static struct nla_policy stats_policy[NL80211_STA_STAT_MAX + 1] = {
85 + [NL80211_STA_STAT_INACTIVE_TIME] = { .type = NLA_U32 },
86 + [NL80211_STA_STAT_RX_BYTES] = { .type = NLA_U32 },
87 + [NL80211_STA_STAT_TX_BYTES] = { .type = NLA_U32 },
90 + nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
91 + genlmsg_attrlen(gnlh, 0), NULL);
94 + * TODO: validate the interface and mac address!
95 + * Otherwise, there's a race condition as soon as
96 + * the kernel starts sending station notifications.
99 + if (!tb[NL80211_ATTR_STA_STATS]) {
100 + printf("sta stats missing!\n");
103 + if (nla_parse_nested(stats, NL80211_STA_STAT_MAX,
104 + tb[NL80211_ATTR_STA_STATS],
106 + printf("failed to parse nested attributes!\n");
110 + if (stats[NL80211_STA_STAT_INACTIVE_TIME])
111 + data->inactive_msec =
112 + nla_get_u32(stats[NL80211_STA_STAT_INACTIVE_TIME]);
113 + if (stats[NL80211_STA_STAT_RX_BYTES])
114 + data->rx_bytes = nla_get_u32(stats[NL80211_STA_STAT_RX_BYTES]);
115 + if (stats[NL80211_STA_STAT_TX_BYTES])
116 + data->rx_bytes = nla_get_u32(stats[NL80211_STA_STAT_TX_BYTES]);
121 static int i802_read_sta_data(void *priv, struct hostap_sta_driver_data *data,
124 struct i802_driver_data *drv = priv;
125 - struct prism2_hostapd_param param;
126 + struct nl_msg *msg;
127 + struct nl_cb *cb = NULL;
132 - memset(data, 0, sizeof(*data));
133 + msg = nlmsg_alloc();
137 - memset(¶m, 0, sizeof(param));
138 - param.cmd = PRISM2_HOSTAPD_GET_INFO_STA;
139 - memcpy(param.sta_addr, addr, ETH_ALEN);
140 - if (hostapd_ioctl(drv, ¶m, sizeof(param))) {
141 - printf(" Could not get station info from kernel driver.\n");
144 + genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
145 + 0, NL80211_CMD_GET_STATION, 0);
147 + NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
148 + NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
150 + cb = nl_cb_alloc(NL_CB_CUSTOM);
154 + if (nl_send_auto_complete(drv->nl_handle, msg) < 0)
157 + nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, get_sta_handler, data);
158 + nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_wait_handler, &finished);
160 + err = nl_recvmsgs(drv->nl_handle, cb);
163 + err = nl_wait_for_ack(drv->nl_handle);
176 - data->inactive_msec = param.u.get_info_sta.inactive_msec;
177 - data->rx_packets = param.u.get_info_sta.rx_packets;
178 - data->tx_packets = param.u.get_info_sta.tx_packets;
179 - data->rx_bytes = param.u.get_info_sta.rx_bytes;
180 - data->tx_bytes = param.u.get_info_sta.tx_bytes;
181 - data->current_tx_rate = param.u.get_info_sta.current_tx_rate;
182 - data->flags = param.u.get_info_sta.flags;
183 - data->num_ps_buf_frames = param.u.get_info_sta.num_ps_buf_frames;
184 - data->tx_retry_failed = param.u.get_info_sta.tx_retry_failed;
185 - data->tx_retry_count = param.u.get_info_sta.tx_retry_count;
186 - data->last_rssi = param.u.get_info_sta.last_rssi;
187 - data->last_ack_rssi = param.u.get_info_sta.last_ack_rssi;
192 @@ -744,35 +825,68 @@ static int i802_sta_add(const char *ifna
193 size_t supp_rates_len, int flags)
195 struct i802_driver_data *drv = priv;
196 - struct prism2_hostapd_param param;
198 + struct nl_msg *msg;
201 - memset(¶m, 0, sizeof(param));
202 - param.cmd = PRISM2_HOSTAPD_ADD_STA;
203 - memcpy(param.sta_addr, addr, ETH_ALEN);
204 - param.u.add_sta.aid = aid;
205 - param.u.add_sta.capability = capability;
206 - len = supp_rates_len;
207 - if (len > sizeof(param.u.add_sta.supp_rates))
208 - len = sizeof(param.u.add_sta.supp_rates);
209 - memcpy(param.u.add_sta.supp_rates, supp_rates, len);
210 - return hostapd_ioctl_iface(ifname, drv, ¶m, sizeof(param));
211 + msg = nlmsg_alloc();
215 + genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
216 + 0, NL80211_CMD_NEW_STATION, 0);
218 + NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
219 + if_nametoindex(drv->iface));
220 + NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
221 + NLA_PUT_U16(msg, NL80211_ATTR_STA_AID, aid);
222 + NLA_PUT(msg, NL80211_ATTR_STA_SUPPORTED_RATES, supp_rates_len,
224 + NLA_PUT_U16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, 0);
228 + if (nl_send_auto_complete(drv->nl_handle, msg) < 0 ||
229 + nl_wait_for_ack(drv->nl_handle) < 0) {
241 static int i802_sta_remove(void *priv, const u8 *addr)
243 struct i802_driver_data *drv = priv;
244 - struct prism2_hostapd_param param;
245 + struct nl_msg *msg;
248 - i802_sta_set_flags(drv, addr, 0, 0, ~WLAN_STA_AUTHORIZED);
249 + msg = nlmsg_alloc();
253 - memset(¶m, 0, sizeof(param));
254 - param.cmd = PRISM2_HOSTAPD_REMOVE_STA;
255 - memcpy(param.sta_addr, addr, ETH_ALEN);
256 - if (hostapd_ioctl(drv, ¶m, sizeof(param)))
259 + genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
260 + 0, NL80211_CMD_DEL_STATION, 0);
262 + NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
263 + if_nametoindex(drv->iface));
264 + NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
268 + if (nl_send_auto_complete(drv->nl_handle, msg) < 0 ||
269 + nl_wait_for_ack(drv->nl_handle) < 0) {
281 @@ -780,14 +894,51 @@ static int i802_sta_set_flags(void *priv
282 int total_flags, int flags_or, int flags_and)
284 struct i802_driver_data *drv = priv;
285 - struct prism2_hostapd_param param;
286 + struct nl_msg *msg, *flags = NULL;
289 - memset(¶m, 0, sizeof(param));
290 - param.cmd = PRISM2_HOSTAPD_SET_FLAGS_STA;
291 - memcpy(param.sta_addr, addr, ETH_ALEN);
292 - param.u.set_flags_sta.flags_or = flags_or;
293 - param.u.set_flags_sta.flags_and = flags_and;
294 - return hostapd_ioctl(drv, ¶m, sizeof(param));
295 + msg = nlmsg_alloc();
299 + flags = nlmsg_alloc();
303 + genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
304 + 0, NL80211_CMD_SET_STATION, 0);
306 + NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
307 + if_nametoindex(drv->iface));
308 + NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
310 + if (total_flags & WLAN_STA_AUTHORIZED)
311 + NLA_PUT_FLAG(flags, NL80211_STA_FLAG_AUTHORIZED);
313 + if (total_flags & WLAN_STA_WME)
314 + NLA_PUT_FLAG(flags, NL80211_STA_FLAG_WME);
316 + if (total_flags & WLAN_STA_SHORT_PREAMBLE)
317 + NLA_PUT_FLAG(flags, NL80211_STA_FLAG_SHORT_PREAMBLE);
319 + if (nla_put_nested(msg, NL80211_ATTR_STA_FLAGS, flags))
320 + goto nla_put_failure;
324 + if (nl_send_auto_complete(drv->nl_handle, msg) < 0 ||
325 + nl_wait_for_ack(drv->nl_handle) < 0) {
340 @@ -1257,18 +1408,38 @@ static struct hostapd_hw_modes * i802_ge
344 -static int i802_set_sta_vlan(void *priv, const u8 *addr, const char *ifname,
346 +static int i802_set_sta_vlan(void *priv, const u8 *addr,
347 + const char *ifname, int vlan_id)
349 struct i802_driver_data *drv = priv;
350 - struct prism2_hostapd_param param;
351 + struct nl_msg *msg;
354 - memset(¶m, 0, sizeof(param));
355 - param.cmd = PRISM2_HOSTAPD_SET_STA_VLAN;
356 - memcpy(param.sta_addr, addr, ETH_ALEN);
357 - os_strlcpy(param.u.set_sta_vlan.vlan_name, ifname, IFNAMSIZ);
358 - param.u.set_sta_vlan.vlan_id = vlan_id;
359 - return hostapd_ioctl(drv, ¶m, sizeof(param));
360 + msg = nlmsg_alloc();
364 + genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
365 + 0, NL80211_CMD_SET_STATION, 0);
367 + NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
368 + if_nametoindex(drv->iface));
369 + NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
370 + NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
371 + if_nametoindex(ifname));
375 + if (nl_send_auto_complete(drv->nl_handle, msg) < 0 ||
376 + nl_wait_for_ack(drv->nl_handle) < 0) {
388 @@ -1750,17 +1921,14 @@ static int i802_init_sockets(struct i802
390 static int i802_get_inact_sec(void *priv, const u8 *addr)
392 - struct i802_driver_data *drv = priv;
393 - struct prism2_hostapd_param param;
394 + struct hostap_sta_driver_data data;
397 - memset(¶m, 0, sizeof(param));
398 - param.cmd = PRISM2_HOSTAPD_GET_INFO_STA;
399 - memcpy(param.sta_addr, addr, ETH_ALEN);
400 - if (hostapd_ioctl(drv, ¶m, sizeof(param))) {
401 + data.inactive_msec = -1;
402 + ret = i802_read_sta_data(priv, &data, addr);
403 + if (ret || data.inactive_msec == -1)
407 - return param.u.get_info_sta.inactive_msec / 1000;
408 + return data.inactive_msec / 1000;