2 hostapd/driver_devicescape.c | 332 ++++++++++++++++++++++++++++++++-----------
3 1 file changed, 251 insertions(+), 81 deletions(-)
5 --- hostap.orig/hostapd/driver_devicescape.c 2007-11-14 17:31:15.000000000 +0100
6 +++ hostap/hostapd/driver_devicescape.c 2007-11-14 17:31: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 + msg = nlmsg_alloc();
136 - memset(data, 0, sizeof(*data));
137 + genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
138 + 0, NL80211_CMD_GET_STATION, 0);
140 - memset(¶m, 0, sizeof(param));
141 - param.cmd = PRISM2_HOSTAPD_GET_INFO_STA;
142 - memcpy(param.sta_addr, addr, ETH_ALEN);
143 - if (hostapd_ioctl(drv, ¶m, sizeof(param))) {
144 - printf(" Could not get station info from kernel driver.\n");
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,70 @@ 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);
226 + ret = nl_send_auto_complete(drv->nl_handle, msg);
228 + goto nla_put_failure;
230 + ret = nl_wait_for_ack(drv->nl_handle);
231 + /* ignore EEXIST, this happens if a STA associates while associated */
232 + if (ret == -EEXIST || ret >= 0)
243 static int i802_sta_remove(void *priv, const u8 *addr)
245 struct i802_driver_data *drv = priv;
246 - struct prism2_hostapd_param param;
247 + struct nl_msg *msg;
250 - i802_sta_set_flags(drv, addr, 0, 0, ~WLAN_STA_AUTHORIZED);
251 + msg = nlmsg_alloc();
255 - memset(¶m, 0, sizeof(param));
256 - param.cmd = PRISM2_HOSTAPD_REMOVE_STA;
257 - memcpy(param.sta_addr, addr, ETH_ALEN);
258 - if (hostapd_ioctl(drv, ¶m, sizeof(param)))
261 + genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
262 + 0, NL80211_CMD_DEL_STATION, 0);
264 + NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
265 + if_nametoindex(drv->iface));
266 + NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
270 + if (nl_send_auto_complete(drv->nl_handle, msg) < 0 ||
271 + nl_wait_for_ack(drv->nl_handle) < 0) {
283 @@ -780,14 +896,51 @@ static int i802_sta_set_flags(void *priv
284 int total_flags, int flags_or, int flags_and)
286 struct i802_driver_data *drv = priv;
287 - struct prism2_hostapd_param param;
288 + struct nl_msg *msg, *flags = NULL;
291 - memset(¶m, 0, sizeof(param));
292 - param.cmd = PRISM2_HOSTAPD_SET_FLAGS_STA;
293 - memcpy(param.sta_addr, addr, ETH_ALEN);
294 - param.u.set_flags_sta.flags_or = flags_or;
295 - param.u.set_flags_sta.flags_and = flags_and;
296 - return hostapd_ioctl(drv, ¶m, sizeof(param));
297 + msg = nlmsg_alloc();
301 + flags = nlmsg_alloc();
305 + genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
306 + 0, NL80211_CMD_SET_STATION, 0);
308 + NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
309 + if_nametoindex(drv->iface));
310 + NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
312 + if (total_flags & WLAN_STA_AUTHORIZED)
313 + NLA_PUT_FLAG(flags, NL80211_STA_FLAG_AUTHORIZED);
315 + if (total_flags & WLAN_STA_WME)
316 + NLA_PUT_FLAG(flags, NL80211_STA_FLAG_WME);
318 + if (total_flags & WLAN_STA_SHORT_PREAMBLE)
319 + NLA_PUT_FLAG(flags, NL80211_STA_FLAG_SHORT_PREAMBLE);
321 + if (nla_put_nested(msg, NL80211_ATTR_STA_FLAGS, flags))
322 + goto nla_put_failure;
326 + if (nl_send_auto_complete(drv->nl_handle, msg) < 0 ||
327 + nl_wait_for_ack(drv->nl_handle) < 0) {
342 @@ -1257,18 +1410,38 @@ static struct hostapd_hw_modes * i802_ge
346 -static int i802_set_sta_vlan(void *priv, const u8 *addr, const char *ifname,
348 +static int i802_set_sta_vlan(void *priv, const u8 *addr,
349 + const char *ifname, int vlan_id)
351 struct i802_driver_data *drv = priv;
352 - struct prism2_hostapd_param param;
353 + struct nl_msg *msg;
356 - memset(¶m, 0, sizeof(param));
357 - param.cmd = PRISM2_HOSTAPD_SET_STA_VLAN;
358 - memcpy(param.sta_addr, addr, ETH_ALEN);
359 - os_strlcpy(param.u.set_sta_vlan.vlan_name, ifname, IFNAMSIZ);
360 - param.u.set_sta_vlan.vlan_id = vlan_id;
361 - return hostapd_ioctl(drv, ¶m, sizeof(param));
362 + msg = nlmsg_alloc();
366 + genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
367 + 0, NL80211_CMD_SET_STATION, 0);
369 + NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
370 + if_nametoindex(drv->iface));
371 + NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
372 + NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
373 + if_nametoindex(ifname));
377 + if (nl_send_auto_complete(drv->nl_handle, msg) < 0 ||
378 + nl_wait_for_ack(drv->nl_handle) < 0) {
390 @@ -1752,17 +1925,14 @@ static int i802_init_sockets(struct i802
392 static int i802_get_inact_sec(void *priv, const u8 *addr)
394 - struct i802_driver_data *drv = priv;
395 - struct prism2_hostapd_param param;
396 + struct hostap_sta_driver_data data;
399 - memset(¶m, 0, sizeof(param));
400 - param.cmd = PRISM2_HOSTAPD_GET_INFO_STA;
401 - memcpy(param.sta_addr, addr, ETH_ALEN);
402 - if (hostapd_ioctl(drv, ¶m, sizeof(param))) {
403 + data.inactive_msec = -1;
404 + ret = i802_read_sta_data(priv, &data, addr);
405 + if (ret || data.inactive_msec == -1)
409 - return param.u.get_info_sta.inactive_msec / 1000;
410 + return data.inactive_msec / 1000;