|
@@ -19,14 +19,8 @@
|
|
|
#include <netlink/genl/family.h>
|
|
|
#include <netlink/genl/ctrl.h>
|
|
|
#include "nl80211_copy.h"
|
|
|
-#ifdef CONFIG_CLIENT_MLME
|
|
|
-#include <netpacket/packet.h>
|
|
|
-#include <linux/if_ether.h>
|
|
|
-#include "radiotap.h"
|
|
|
-#include "radiotap_iter.h"
|
|
|
-#endif /* CONFIG_CLIENT_MLME */
|
|
|
-
|
|
|
#include "wireless_copy.h"
|
|
|
+
|
|
|
#include "common.h"
|
|
|
#include "driver.h"
|
|
|
#include "eloop.h"
|
|
@@ -90,11 +84,6 @@ struct wpa_driver_nl80211_data {
|
|
|
struct nl_cb *nl_cb;
|
|
|
struct genl_family *nl80211;
|
|
|
|
|
|
-#ifdef CONFIG_CLIENT_MLME
|
|
|
- int monitor_sock; /* socket for monitor */
|
|
|
- int monitor_ifidx;
|
|
|
-#endif /* CONFIG_CLIENT_MLME */
|
|
|
-
|
|
|
u8 bssid[ETH_ALEN];
|
|
|
int associated;
|
|
|
};
|
|
@@ -1266,258 +1255,6 @@ nla_put_failure:
|
|
|
}
|
|
|
|
|
|
|
|
|
-#ifdef CONFIG_CLIENT_MLME
|
|
|
-
|
|
|
-static int nl80211_set_vif(struct wpa_driver_nl80211_data *drv,
|
|
|
- int drop_unencrypted, int userspace_mlme)
|
|
|
-{
|
|
|
-#ifdef NL80211_CMD_SET_VIF
|
|
|
- struct nl_msg *msg;
|
|
|
- int ret = -1;
|
|
|
-
|
|
|
- msg = nlmsg_alloc();
|
|
|
- if (!msg)
|
|
|
- return -ENOMEM;
|
|
|
-
|
|
|
- genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, 0,
|
|
|
- NL80211_CMD_SET_VIF, 0);
|
|
|
-
|
|
|
- if (drop_unencrypted >= 0)
|
|
|
- NLA_PUT_U8(msg, NL80211_ATTR_VIF_DROP_UNENCRYPTED,
|
|
|
- drop_unencrypted);
|
|
|
- if (userspace_mlme >= 0)
|
|
|
- NLA_PUT_U8(msg, NL80211_ATTR_VIF_USERSPACE_MLME,
|
|
|
- userspace_mlme);
|
|
|
-
|
|
|
- ret = 0;
|
|
|
-
|
|
|
- NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex);
|
|
|
-
|
|
|
- ret = send_and_recv_msgs(drv, msg, NULL, NULL);
|
|
|
- return ret;
|
|
|
-
|
|
|
-nla_put_failure:
|
|
|
- return -ENOBUFS;
|
|
|
-#else /* NL80211_CMD_SET_VIF */
|
|
|
- return -1;
|
|
|
-#endif /* NL80211_CMD_SET_VIF */
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-static int wpa_driver_nl80211_set_userspace_mlme(
|
|
|
- struct wpa_driver_nl80211_data *drv, int enabled)
|
|
|
-{
|
|
|
- return nl80211_set_vif(drv, -1, enabled);
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-static void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv,
|
|
|
- int ifidx)
|
|
|
-{
|
|
|
- struct nl_msg *msg;
|
|
|
-
|
|
|
- msg = nlmsg_alloc();
|
|
|
- if (!msg)
|
|
|
- goto nla_put_failure;
|
|
|
-
|
|
|
- genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
|
|
|
- 0, NL80211_CMD_DEL_INTERFACE, 0);
|
|
|
- NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifidx);
|
|
|
- if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0)
|
|
|
- return;
|
|
|
-nla_put_failure:
|
|
|
- wpa_printf(MSG_ERROR, "nl80211: Failed to remove interface.");
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-static int nl80211_create_iface(struct wpa_driver_nl80211_data *drv,
|
|
|
- const char *ifname, enum nl80211_iftype iftype)
|
|
|
-{
|
|
|
- struct nl_msg *msg, *flags = NULL;
|
|
|
- int ifidx, err;
|
|
|
- int ret = -ENOBUFS;
|
|
|
-
|
|
|
- msg = nlmsg_alloc();
|
|
|
- if (!msg)
|
|
|
- return -1;
|
|
|
-
|
|
|
- genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
|
|
|
- 0, NL80211_CMD_NEW_INTERFACE, 0);
|
|
|
- NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->ifname));
|
|
|
- NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, ifname);
|
|
|
- NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, iftype);
|
|
|
-
|
|
|
- if (iftype == NL80211_IFTYPE_MONITOR) {
|
|
|
- flags = nlmsg_alloc();
|
|
|
- if (!flags)
|
|
|
- goto nla_put_failure;
|
|
|
-
|
|
|
- NLA_PUT_FLAG(flags, NL80211_MNTR_FLAG_COOK_FRAMES);
|
|
|
-
|
|
|
- err = nla_put_nested(msg, NL80211_ATTR_MNTR_FLAGS, flags);
|
|
|
-
|
|
|
- nlmsg_free(flags);
|
|
|
-
|
|
|
- if (err)
|
|
|
- goto nla_put_failure;
|
|
|
- }
|
|
|
-
|
|
|
- ret = send_and_recv_msgs(drv, msg, NULL, NULL);
|
|
|
- if (ret) {
|
|
|
- nla_put_failure:
|
|
|
- wpa_printf(MSG_ERROR, "nl80211: Failed to create interface %d",
|
|
|
- ret);
|
|
|
- return ret;
|
|
|
- }
|
|
|
-
|
|
|
- ifidx = if_nametoindex(ifname);
|
|
|
- if (ifidx <= 0)
|
|
|
- return -1;
|
|
|
-
|
|
|
- return ifidx;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-static void handle_monitor_read(int sock, void *eloop_ctx, void *sock_ctx)
|
|
|
-{
|
|
|
- struct wpa_driver_nl80211_data *drv = eloop_ctx;
|
|
|
- int len;
|
|
|
- unsigned char buf[3000];
|
|
|
- struct ieee80211_radiotap_iterator iter;
|
|
|
- int ret;
|
|
|
- int injected = 0, failed = 0, rxflags = 0;
|
|
|
- struct ieee80211_rx_status rx_status;
|
|
|
-
|
|
|
- len = recv(sock, buf, sizeof(buf), 0);
|
|
|
- if (len < 0) {
|
|
|
- perror("recv");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if (ieee80211_radiotap_iterator_init(&iter, (void *) buf, len)) {
|
|
|
- wpa_printf(MSG_DEBUG, "nl80211: received invalid radiotap "
|
|
|
- "frame");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- os_memset(&rx_status, 0, sizeof(rx_status));
|
|
|
-
|
|
|
- while (1) {
|
|
|
- ret = ieee80211_radiotap_iterator_next(&iter);
|
|
|
- if (ret == -ENOENT)
|
|
|
- break;
|
|
|
- if (ret) {
|
|
|
- wpa_printf(MSG_DEBUG, "nl80211: received invalid "
|
|
|
- "radiotap frame (%d)", ret);
|
|
|
- return;
|
|
|
- }
|
|
|
- switch (iter.this_arg_index) {
|
|
|
- case IEEE80211_RADIOTAP_FLAGS:
|
|
|
- if (*iter.this_arg & IEEE80211_RADIOTAP_F_FCS)
|
|
|
- len -= 4;
|
|
|
- break;
|
|
|
- case IEEE80211_RADIOTAP_RX_FLAGS:
|
|
|
- rxflags = 1;
|
|
|
- break;
|
|
|
- case IEEE80211_RADIOTAP_TX_FLAGS:
|
|
|
- injected = 1;
|
|
|
- failed = le_to_host16((*(u16 *) iter.this_arg)) &
|
|
|
- IEEE80211_RADIOTAP_F_TX_FAIL;
|
|
|
- break;
|
|
|
- case IEEE80211_RADIOTAP_DATA_RETRIES:
|
|
|
- break;
|
|
|
- case IEEE80211_RADIOTAP_CHANNEL:
|
|
|
- /* TODO convert from freq/flags to channel number
|
|
|
- * rx_status.channel = XXX;
|
|
|
- */
|
|
|
- break;
|
|
|
- case IEEE80211_RADIOTAP_RATE:
|
|
|
- break;
|
|
|
- case IEEE80211_RADIOTAP_DB_ANTSIGNAL:
|
|
|
- rx_status.ssi = *iter.this_arg;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (rxflags && injected)
|
|
|
- return;
|
|
|
-
|
|
|
- if (!injected) {
|
|
|
- wpa_supplicant_sta_rx(drv->ctx, buf + iter.max_length,
|
|
|
- len - iter.max_length, &rx_status);
|
|
|
- } else if (failed) {
|
|
|
- /* TX failure callback */
|
|
|
- } else {
|
|
|
- /* TX success (ACK) callback */
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-static int wpa_driver_nl80211_create_monitor_interface(
|
|
|
- struct wpa_driver_nl80211_data *drv)
|
|
|
-{
|
|
|
- char buf[IFNAMSIZ];
|
|
|
- struct sockaddr_ll ll;
|
|
|
- int optval, flags;
|
|
|
- socklen_t optlen;
|
|
|
-
|
|
|
- os_snprintf(buf, IFNAMSIZ, "mon.%s", drv->ifname);
|
|
|
- buf[IFNAMSIZ - 1] = '\0';
|
|
|
-
|
|
|
- drv->monitor_ifidx =
|
|
|
- nl80211_create_iface(drv, buf, NL80211_IFTYPE_MONITOR);
|
|
|
-
|
|
|
- if (drv->monitor_ifidx < 0)
|
|
|
- return -1;
|
|
|
-
|
|
|
- if (wpa_driver_nl80211_get_ifflags_ifname(drv, buf, &flags) != 0 ||
|
|
|
- wpa_driver_nl80211_set_ifflags_ifname(drv, buf, flags | IFF_UP) !=
|
|
|
- 0) {
|
|
|
- wpa_printf(MSG_ERROR, "nl80211: Could not set interface '%s' "
|
|
|
- "UP", buf);
|
|
|
- goto error;
|
|
|
- }
|
|
|
-
|
|
|
- os_memset(&ll, 0, sizeof(ll));
|
|
|
- ll.sll_family = AF_PACKET;
|
|
|
- ll.sll_ifindex = drv->monitor_ifidx;
|
|
|
- drv->monitor_sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
|
|
|
- if (drv->monitor_sock < 0) {
|
|
|
- perror("socket[PF_PACKET,SOCK_RAW]");
|
|
|
- goto error;
|
|
|
- }
|
|
|
-
|
|
|
- if (bind(drv->monitor_sock, (struct sockaddr *) &ll,
|
|
|
- sizeof(ll)) < 0) {
|
|
|
- perror("monitor socket bind");
|
|
|
- goto error;
|
|
|
- }
|
|
|
-
|
|
|
- optlen = sizeof(optval);
|
|
|
- optval = 20;
|
|
|
- if (setsockopt
|
|
|
- (drv->monitor_sock, SOL_SOCKET, SO_PRIORITY, &optval, optlen)) {
|
|
|
- perror("Failed to set socket priority");
|
|
|
- goto error;
|
|
|
- }
|
|
|
-
|
|
|
- if (eloop_register_read_sock(drv->monitor_sock, handle_monitor_read,
|
|
|
- drv, NULL)) {
|
|
|
- wpa_printf(MSG_ERROR, "nl80211: Could not register monitor "
|
|
|
- "read socket");
|
|
|
- goto error;
|
|
|
- }
|
|
|
-
|
|
|
- return 0;
|
|
|
-
|
|
|
- error:
|
|
|
- nl80211_remove_iface(drv, drv->monitor_ifidx);
|
|
|
- return -1;
|
|
|
-}
|
|
|
-
|
|
|
-#endif /* CONFIG_CLIENT_MLME */
|
|
|
-
|
|
|
-
|
|
|
struct wiphy_info_data {
|
|
|
int max_scan_ssids;
|
|
|
};
|
|
@@ -1761,17 +1498,6 @@ static void wpa_driver_nl80211_deinit(void *priv)
|
|
|
struct wpa_driver_nl80211_data *drv = priv;
|
|
|
int flags;
|
|
|
|
|
|
-#ifdef CONFIG_CLIENT_MLME
|
|
|
- if (drv->monitor_sock >= 0) {
|
|
|
- eloop_unregister_read_sock(drv->monitor_sock);
|
|
|
- close(drv->monitor_sock);
|
|
|
- }
|
|
|
- if (drv->monitor_ifidx > 0)
|
|
|
- nl80211_remove_iface(drv, drv->monitor_ifidx);
|
|
|
- if (drv->capa.flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME)
|
|
|
- wpa_driver_nl80211_set_userspace_mlme(drv, 0);
|
|
|
-#endif /* CONFIG_CLIENT_MLME */
|
|
|
-
|
|
|
eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx);
|
|
|
|
|
|
/*
|
|
@@ -2779,354 +2505,6 @@ static int wpa_driver_nl80211_set_operstate(void *priv, int state)
|
|
|
}
|
|
|
|
|
|
|
|
|
-#ifdef CONFIG_CLIENT_MLME
|
|
|
-static int wpa_driver_nl80211_open_mlme(struct wpa_driver_nl80211_data *drv)
|
|
|
-{
|
|
|
- if (wpa_driver_nl80211_set_userspace_mlme(drv, 1) < 0) {
|
|
|
- wpa_printf(MSG_ERROR, "nl80211: Failed to enable userspace "
|
|
|
- "MLME");
|
|
|
- return -1;
|
|
|
- }
|
|
|
- if (wpa_driver_nl80211_create_monitor_interface(drv)) {
|
|
|
- wpa_printf(MSG_ERROR, "nl80211: Failed to create monitor "
|
|
|
- "interface");
|
|
|
- return -1;
|
|
|
- }
|
|
|
- return 0;
|
|
|
-}
|
|
|
-#endif /* CONFIG_CLIENT_MLME */
|
|
|
-
|
|
|
-
|
|
|
-static int wpa_driver_nl80211_set_param(void *priv, const char *param)
|
|
|
-{
|
|
|
-#ifdef CONFIG_CLIENT_MLME
|
|
|
- struct wpa_driver_nl80211_data *drv = priv;
|
|
|
-
|
|
|
- if (param == NULL)
|
|
|
- return 0;
|
|
|
-
|
|
|
- wpa_printf(MSG_DEBUG, "%s: param='%s'", __func__, param);
|
|
|
-
|
|
|
- if (os_strstr(param, "use_mlme=1")) {
|
|
|
- wpa_printf(MSG_DEBUG, "nl80211: Using user space MLME");
|
|
|
- drv->capa.flags |= WPA_DRIVER_FLAGS_USER_SPACE_MLME;
|
|
|
-
|
|
|
- if (wpa_driver_nl80211_open_mlme(drv))
|
|
|
- return -1;
|
|
|
- }
|
|
|
-#endif /* CONFIG_CLIENT_MLME */
|
|
|
-
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-#ifdef CONFIG_CLIENT_MLME
|
|
|
-
|
|
|
-struct phy_info_arg {
|
|
|
- u16 *num_modes;
|
|
|
- struct wpa_hw_modes *modes;
|
|
|
-};
|
|
|
-
|
|
|
-
|
|
|
-static int phy_info_handler(struct nl_msg *msg, void *arg)
|
|
|
-{
|
|
|
- struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
|
|
|
- struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
|
|
|
- struct phy_info_arg *phy_info = arg;
|
|
|
-
|
|
|
- struct nlattr *tb_band[NL80211_BAND_ATTR_MAX + 1];
|
|
|
-
|
|
|
- struct nlattr *tb_freq[NL80211_FREQUENCY_ATTR_MAX + 1];
|
|
|
- static struct nla_policy freq_policy[NL80211_FREQUENCY_ATTR_MAX + 1]
|
|
|
- = {
|
|
|
- [NL80211_FREQUENCY_ATTR_FREQ] = { .type = NLA_U32 },
|
|
|
- [NL80211_FREQUENCY_ATTR_DISABLED] = { .type = NLA_FLAG },
|
|
|
- [NL80211_FREQUENCY_ATTR_PASSIVE_SCAN] = { .type = NLA_FLAG },
|
|
|
- [NL80211_FREQUENCY_ATTR_NO_IBSS] = { .type = NLA_FLAG },
|
|
|
- [NL80211_FREQUENCY_ATTR_RADAR] = { .type = NLA_FLAG },
|
|
|
- };
|
|
|
-
|
|
|
- struct nlattr *tb_rate[NL80211_BITRATE_ATTR_MAX + 1];
|
|
|
- static struct nla_policy rate_policy[NL80211_BITRATE_ATTR_MAX + 1] = {
|
|
|
- [NL80211_BITRATE_ATTR_RATE] = { .type = NLA_U32 },
|
|
|
- [NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE] =
|
|
|
- { .type = NLA_FLAG },
|
|
|
- };
|
|
|
-
|
|
|
- struct nlattr *nl_band;
|
|
|
- struct nlattr *nl_freq;
|
|
|
- struct nlattr *nl_rate;
|
|
|
- int rem_band, rem_freq, rem_rate;
|
|
|
- struct wpa_hw_modes *mode;
|
|
|
- int idx, mode_is_set;
|
|
|
-
|
|
|
- nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
|
|
|
- genlmsg_attrlen(gnlh, 0), NULL);
|
|
|
-
|
|
|
- if (!tb_msg[NL80211_ATTR_WIPHY_BANDS])
|
|
|
- return NL_SKIP;
|
|
|
-
|
|
|
- nla_for_each_nested(nl_band, tb_msg[NL80211_ATTR_WIPHY_BANDS],
|
|
|
- rem_band) {
|
|
|
- mode = os_realloc(phy_info->modes,
|
|
|
- (*phy_info->num_modes + 1) * sizeof(*mode));
|
|
|
- if (!mode)
|
|
|
- return NL_SKIP;
|
|
|
- phy_info->modes = mode;
|
|
|
-
|
|
|
- mode_is_set = 0;
|
|
|
-
|
|
|
- mode = &phy_info->modes[*(phy_info->num_modes)];
|
|
|
- os_memset(mode, 0, sizeof(*mode));
|
|
|
- *(phy_info->num_modes) += 1;
|
|
|
-
|
|
|
- nla_parse(tb_band, NL80211_BAND_ATTR_MAX, nla_data(nl_band),
|
|
|
- nla_len(nl_band), NULL);
|
|
|
-
|
|
|
- nla_for_each_nested(nl_freq, tb_band[NL80211_BAND_ATTR_FREQS],
|
|
|
- rem_freq) {
|
|
|
- nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX,
|
|
|
- nla_data(nl_freq), nla_len(nl_freq),
|
|
|
- freq_policy);
|
|
|
- if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
|
|
|
- continue;
|
|
|
- mode->num_channels++;
|
|
|
- }
|
|
|
-
|
|
|
- mode->channels = os_zalloc(mode->num_channels *
|
|
|
- sizeof(struct wpa_channel_data));
|
|
|
- if (!mode->channels)
|
|
|
- return NL_SKIP;
|
|
|
-
|
|
|
- idx = 0;
|
|
|
-
|
|
|
- nla_for_each_nested(nl_freq, tb_band[NL80211_BAND_ATTR_FREQS],
|
|
|
- rem_freq) {
|
|
|
- nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX,
|
|
|
- nla_data(nl_freq), nla_len(nl_freq),
|
|
|
- freq_policy);
|
|
|
- if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
|
|
|
- continue;
|
|
|
-
|
|
|
- mode->channels[idx].freq = nla_get_u32(
|
|
|
- tb_freq[NL80211_FREQUENCY_ATTR_FREQ]);
|
|
|
- mode->channels[idx].flag |= WPA_CHAN_W_SCAN |
|
|
|
- WPA_CHAN_W_ACTIVE_SCAN |
|
|
|
- WPA_CHAN_W_IBSS;
|
|
|
-
|
|
|
- if (!mode_is_set) {
|
|
|
- /* crude heuristic */
|
|
|
- if (mode->channels[idx].freq < 4000)
|
|
|
- mode->mode = WPA_MODE_IEEE80211B;
|
|
|
- else
|
|
|
- mode->mode = WPA_MODE_IEEE80211A;
|
|
|
- mode_is_set = 1;
|
|
|
- }
|
|
|
-
|
|
|
- /* crude heuristic */
|
|
|
- if (mode->channels[idx].freq < 4000) {
|
|
|
- if (mode->channels[idx].freq == 2848)
|
|
|
- mode->channels[idx].chan = 14;
|
|
|
- else
|
|
|
- mode->channels[idx].chan =
|
|
|
- (mode->channels[idx].freq -
|
|
|
- 2407) / 5;
|
|
|
- } else
|
|
|
- mode->channels[idx].chan =
|
|
|
- mode->channels[idx].freq / 5 - 1000;
|
|
|
-
|
|
|
- if (tb_freq[NL80211_FREQUENCY_ATTR_DISABLED])
|
|
|
- mode->channels[idx].flag &= ~WPA_CHAN_W_SCAN;
|
|
|
- if (tb_freq[NL80211_FREQUENCY_ATTR_PASSIVE_SCAN])
|
|
|
- mode->channels[idx].flag &=
|
|
|
- ~WPA_CHAN_W_ACTIVE_SCAN;
|
|
|
- if (tb_freq[NL80211_FREQUENCY_ATTR_NO_IBSS])
|
|
|
- mode->channels[idx].flag &= ~WPA_CHAN_W_IBSS;
|
|
|
- idx++;
|
|
|
- }
|
|
|
-
|
|
|
- nla_for_each_nested(nl_rate, tb_band[NL80211_BAND_ATTR_RATES],
|
|
|
- rem_rate) {
|
|
|
- nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX,
|
|
|
- nla_data(nl_rate), nla_len(nl_rate),
|
|
|
- rate_policy);
|
|
|
- if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
|
|
|
- continue;
|
|
|
- mode->num_rates++;
|
|
|
- }
|
|
|
-
|
|
|
- mode->rates = os_zalloc(mode->num_rates *
|
|
|
- sizeof(struct wpa_rate_data));
|
|
|
- if (!mode->rates)
|
|
|
- return NL_SKIP;
|
|
|
-
|
|
|
- idx = 0;
|
|
|
-
|
|
|
- nla_for_each_nested(nl_rate, tb_band[NL80211_BAND_ATTR_RATES],
|
|
|
- rem_rate) {
|
|
|
- nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX,
|
|
|
- nla_data(nl_rate), nla_len(nl_rate),
|
|
|
- rate_policy);
|
|
|
- if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
|
|
|
- continue;
|
|
|
- mode->rates[idx].rate = nla_get_u32(
|
|
|
- tb_rate[NL80211_BITRATE_ATTR_RATE]);
|
|
|
-
|
|
|
- /* crude heuristic */
|
|
|
- if (mode->mode == WPA_MODE_IEEE80211B &&
|
|
|
- mode->rates[idx].rate > 200)
|
|
|
- mode->mode = WPA_MODE_IEEE80211G;
|
|
|
-
|
|
|
- if (tb_rate[NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE])
|
|
|
- mode->rates[idx].flags |= WPA_RATE_PREAMBLE2;
|
|
|
-
|
|
|
- idx++;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return NL_SKIP;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-static struct wpa_hw_modes *
|
|
|
-wpa_driver_nl80211_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags)
|
|
|
-{
|
|
|
- struct wpa_driver_nl80211_data *drv = priv;
|
|
|
- struct nl_msg *msg;
|
|
|
- struct phy_info_arg result = {
|
|
|
- .num_modes = num_modes,
|
|
|
- .modes = NULL,
|
|
|
- };
|
|
|
-
|
|
|
- *num_modes = 0;
|
|
|
- *flags = 0;
|
|
|
-
|
|
|
- msg = nlmsg_alloc();
|
|
|
- if (!msg)
|
|
|
- return NULL;
|
|
|
-
|
|
|
- genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
|
|
|
- 0, NL80211_CMD_GET_WIPHY, 0);
|
|
|
-
|
|
|
- NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex);
|
|
|
-
|
|
|
- if (send_and_recv_msgs(drv, msg, phy_info_handler, &result) == 0)
|
|
|
- return result.modes;
|
|
|
-nla_put_failure:
|
|
|
- return NULL;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-static int wpa_driver_nl80211_set_channel(void *priv, wpa_hw_mode phymode,
|
|
|
- int chan, int freq)
|
|
|
-{
|
|
|
- return wpa_driver_nl80211_set_freq(priv, freq);
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-static int wpa_driver_nl80211_send_mlme(void *priv, const u8 *data,
|
|
|
- size_t data_len)
|
|
|
-{
|
|
|
- struct wpa_driver_nl80211_data *drv = priv;
|
|
|
- __u8 rtap_hdr[] = {
|
|
|
- 0x00, 0x00, /* radiotap version */
|
|
|
- 0x0e, 0x00, /* radiotap length */
|
|
|
- 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
|
|
|
- 0x0c, /* F_WEP | F_FRAG (encrypt/fragment if required) */
|
|
|
- 0x00, /* padding */
|
|
|
- 0x00, 0x00, /* RX and TX flags to indicate that */
|
|
|
- 0x00, 0x00, /* this is the injected frame directly */
|
|
|
- };
|
|
|
- struct iovec iov[2] = {
|
|
|
- {
|
|
|
- .iov_base = &rtap_hdr,
|
|
|
- .iov_len = sizeof(rtap_hdr),
|
|
|
- },
|
|
|
- {
|
|
|
- .iov_base = (void *) data,
|
|
|
- .iov_len = data_len,
|
|
|
- }
|
|
|
- };
|
|
|
- struct msghdr msg = {
|
|
|
- .msg_name = NULL,
|
|
|
- .msg_namelen = 0,
|
|
|
- .msg_iov = iov,
|
|
|
- .msg_iovlen = 2,
|
|
|
- .msg_control = NULL,
|
|
|
- .msg_controllen = 0,
|
|
|
- .msg_flags = 0,
|
|
|
- };
|
|
|
-
|
|
|
- if (sendmsg(drv->monitor_sock, &msg, 0) < 0) {
|
|
|
- perror("send[MLME]");
|
|
|
- return -1;
|
|
|
- }
|
|
|
-
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-static int wpa_driver_nl80211_mlme_add_sta(void *priv, const u8 *addr,
|
|
|
- const u8 *supp_rates,
|
|
|
- size_t supp_rates_len)
|
|
|
-{
|
|
|
- struct wpa_driver_nl80211_data *drv = priv;
|
|
|
- struct nl_msg *msg;
|
|
|
- int ret = -1;
|
|
|
-
|
|
|
- msg = nlmsg_alloc();
|
|
|
- if (!msg)
|
|
|
- return -ENOMEM;
|
|
|
-
|
|
|
- genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
|
|
|
- 0, NL80211_CMD_NEW_STATION, 0);
|
|
|
-
|
|
|
- NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex);
|
|
|
- NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
|
|
|
- /* TODO: Get proper Association ID and listen interval */
|
|
|
- NLA_PUT_U16(msg, NL80211_ATTR_STA_AID, 1);
|
|
|
- NLA_PUT(msg, NL80211_ATTR_STA_SUPPORTED_RATES, supp_rates_len,
|
|
|
- supp_rates);
|
|
|
- NLA_PUT_U16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, 1);
|
|
|
-
|
|
|
- ret = send_and_recv_msgs(drv, msg, NULL, NULL);
|
|
|
- /* ignore EEXIST, this happens if a STA associates while associated */
|
|
|
- if (ret == -EEXIST || ret >= 0)
|
|
|
- ret = 0;
|
|
|
-
|
|
|
-nla_put_failure:
|
|
|
- return ret;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-static int wpa_driver_nl80211_mlme_remove_sta(void *priv, const u8 *addr)
|
|
|
-{
|
|
|
- struct wpa_driver_nl80211_data *drv = priv;
|
|
|
- struct nl_msg *msg;
|
|
|
- int ret = -1;
|
|
|
-
|
|
|
- msg = nlmsg_alloc();
|
|
|
- if (!msg)
|
|
|
- return -ENOMEM;
|
|
|
-
|
|
|
- genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
|
|
|
- 0, NL80211_CMD_DEL_STATION, 0);
|
|
|
-
|
|
|
- NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex);
|
|
|
- NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
|
|
|
-
|
|
|
- ret = 0;
|
|
|
-
|
|
|
- ret = send_and_recv_msgs(drv, msg, NULL, NULL);
|
|
|
- return ret;
|
|
|
-
|
|
|
-nla_put_failure:
|
|
|
- return -ENOBUFS;
|
|
|
-}
|
|
|
-
|
|
|
-#endif /* CONFIG_CLIENT_MLME */
|
|
|
-
|
|
|
-
|
|
|
const struct wpa_driver_ops wpa_driver_nl80211_ops = {
|
|
|
.name = "nl80211",
|
|
|
.desc = "Linux nl80211/cfg80211",
|
|
@@ -3143,22 +2521,12 @@ const struct wpa_driver_ops wpa_driver_nl80211_ops = {
|
|
|
.associate = wpa_driver_nl80211_associate,
|
|
|
.init = wpa_driver_nl80211_init,
|
|
|
.deinit = wpa_driver_nl80211_deinit,
|
|
|
- .set_param = wpa_driver_nl80211_set_param,
|
|
|
.add_pmkid = wpa_driver_nl80211_add_pmkid,
|
|
|
.remove_pmkid = wpa_driver_nl80211_remove_pmkid,
|
|
|
.flush_pmkid = wpa_driver_nl80211_flush_pmkid,
|
|
|
.get_capa = wpa_driver_nl80211_get_capa,
|
|
|
.set_operstate = wpa_driver_nl80211_set_operstate,
|
|
|
.set_country = wpa_driver_nl80211_set_country,
|
|
|
-#ifdef CONFIG_CLIENT_MLME
|
|
|
- .get_hw_feature_data = wpa_driver_nl80211_get_hw_feature_data,
|
|
|
- .set_channel = wpa_driver_nl80211_set_channel,
|
|
|
- .set_ssid = wpa_driver_nl80211_set_ssid,
|
|
|
- .set_bssid = wpa_driver_nl80211_set_bssid,
|
|
|
- .send_mlme = wpa_driver_nl80211_send_mlme,
|
|
|
- .mlme_add_sta = wpa_driver_nl80211_mlme_add_sta,
|
|
|
- .mlme_remove_sta = wpa_driver_nl80211_mlme_remove_sta,
|
|
|
-#endif /* CONFIG_CLIENT_MLME */
|
|
|
#ifdef WEXT_COMPAT
|
|
|
.set_wpa = wpa_driver_nl80211_set_wpa,
|
|
|
.set_countermeasures = wpa_driver_nl80211_set_countermeasures,
|