aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohannes Berg <johannes@sipsolutions.net>2008-02-07 03:28:54 (GMT)
committerJouni Malinen <j@w1.fi>2008-02-07 03:28:54 (GMT)
commit672e26f5cb6b9e2ae7d6c797b42bf2680f936663 (patch)
treee3164534aff26844ba105b04430f01d37fa1e98d
parentd4aa9369f4d10cc485b1e579d293ec6f7a89c9a8 (diff)
downloadhostap-history-672e26f5cb6b9e2ae7d6c797b42bf2680f936663.zip
hostap-history-672e26f5cb6b9e2ae7d6c797b42bf2680f936663.tar.gz
hostap-history-672e26f5cb6b9e2ae7d6c797b42bf2680f936663.tar.bz2
nl80211 driver: use nl80211 for hw info
This patch changes the nl80211 driver to use the new nl80211 API for obtaining hardware information, rather than try to use the deprecated/unsupported prism2 hostapd ioctl. Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
-rw-r--r--hostapd/driver_nl80211.c302
1 files changed, 189 insertions, 113 deletions
diff --git a/hostapd/driver_nl80211.c b/hostapd/driver_nl80211.c
index 8a6792d..81b620c 100644
--- a/hostapd/driver_nl80211.c
+++ b/hostapd/driver_nl80211.c
@@ -51,8 +51,6 @@
#define PRISM2_PARAM_AP_BRIDGE_PACKETS 10
#define PRISM2_PARAM_IEEE_802_1X 23
-#define PRISM2_HOSTAPD_GET_HW_FEATURES 1002
-#define PRISM2_HOSTAPD_MAX_BUF_SIZE 2048
#ifndef ALIGNED
#define ALIGNED __attribute__ ((aligned))
@@ -64,11 +62,6 @@ struct prism2_hostapd_param {
u8 pad[2];
union {
struct {
- u16 num_modes;
- u16 flags;
- u8 data[0] ALIGNED; /* num_modes * feature data */
- } hw_features;
- struct {
u16 mode; /* MODE_* */
u16 num_supported_rates;
u16 num_basic_rates;
@@ -111,12 +104,6 @@ enum {
PRISM2_PARAM_NEXT_MODE = 1008,
};
-struct hostapd_ioctl_hw_modes_hdr {
- int mode;
- int num_channels;
- int num_rates;
-};
-
enum ieee80211_msg_type {
ieee80211_msg_normal = 0,
ieee80211_msg_tx_callback_ack = 1,
@@ -258,32 +245,6 @@ static int hostapd_set_iface_flags(struct i802_driver_data *drv,
}
-static int hostapd_ioctl_iface(const char *iface, struct i802_driver_data *drv,
- struct prism2_hostapd_param *param, int len)
-{
- struct iwreq iwr;
-
- memset(&iwr, 0, sizeof(iwr));
- os_strlcpy(iwr.ifr_name, iface, IFNAMSIZ);
- iwr.u.data.pointer = (caddr_t) param;
- iwr.u.data.length = len;
-
- if (ioctl(drv->ioctl_sock, PRISM2_IOCTL_HOSTAPD, &iwr) < 0) {
- /* perror("ioctl[PRISM2_IOCTL_HOSTAPD]"); */
- return -1;
- }
-
- return 0;
-}
-
-
-static int hostapd_ioctl(struct i802_driver_data *drv,
- struct prism2_hostapd_param *param, int len)
-{
- return hostapd_ioctl_iface(drv->iface, drv, param, len);
-}
-
-
static int i802_set_encryption(const char *iface, void *priv, const char *alg,
const u8 *addr, int idx, const u8 *key,
size_t key_len, int txkey)
@@ -1396,92 +1357,207 @@ static int i802_if_remove(void *priv, enum hostapd_driver_if_type type,
}
-static struct hostapd_hw_modes * i802_get_hw_feature_data(void *priv,
- u16 *num_modes,
- u16 *flags)
-{
- struct i802_driver_data *drv = priv;
- struct prism2_hostapd_param *param;
- u8 *pos, *end;
+struct phy_info_arg {
+ u16 *num_modes;
struct hostapd_hw_modes *modes;
- int i;
+ int error;
+};
- param = os_zalloc(PRISM2_HOSTAPD_MAX_BUF_SIZE);
- if (param == NULL)
- return NULL;
- param->cmd = PRISM2_HOSTAPD_GET_HW_FEATURES;
- if (hostapd_ioctl(drv, param, PRISM2_HOSTAPD_MAX_BUF_SIZE)) {
- free(param);
- return NULL;
- }
+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;
- *num_modes = param->u.hw_features.num_modes;
- *flags = param->u.hw_features.flags;
+ struct nlattr *tb_band[NL80211_BAND_ATTR_MAX + 1];
- pos = param->u.hw_features.data;
- end = pos + PRISM2_HOSTAPD_MAX_BUF_SIZE -
- (param->u.hw_features.data - (u8 *) param);
+ 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 },
+ };
- modes = os_zalloc(*num_modes * sizeof(struct hostapd_hw_modes));
- if (modes == NULL) {
- free(param);
- return NULL;
- }
+ 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 },
+ };
- for (i = 0; i < *num_modes; i++) {
- struct hostapd_ioctl_hw_modes_hdr *hdr;
- struct hostapd_hw_modes *feature;
- int clen, rlen;
+ struct nlattr *nl_band;
+ struct nlattr *nl_freq;
+ struct nlattr *nl_rate;
+ int rem_band, rem_freq, rem_rate;
+ struct hostapd_hw_modes *mode;
+ int idx, mode_is_set;
- hdr = (struct hostapd_ioctl_hw_modes_hdr *) pos;
- feature = &modes[i];
- switch (hdr->mode) {
- case MODE_IEEE80211A:
- feature->mode = HOSTAPD_MODE_IEEE80211A;
- break;
- case MODE_IEEE80211B:
- feature->mode = HOSTAPD_MODE_IEEE80211B;
- break;
- case MODE_IEEE80211G:
- feature->mode = HOSTAPD_MODE_IEEE80211G;
- break;
- default:
- wpa_printf(MSG_ERROR, "Unknown hw_mode=%d in "
- "get_hw_features data", hdr->mode);
- hostapd_free_hw_features(modes, *num_modes);
- modes = NULL;
- break;
+ 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 = 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)];
+ 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++;
}
- feature->num_channels = hdr->num_channels;
- feature->num_rates = hdr->num_rates;
-
- pos = (u8 *) (hdr + 1);
-
- clen = hdr->num_channels *
- sizeof(struct hostapd_channel_data);
- rlen = hdr->num_rates *
- sizeof(struct hostapd_rate_data);
-
- feature->channels = malloc(clen);
- feature->rates = malloc(rlen);
- if (!feature->channels || !feature->rates ||
- pos + clen + rlen > end) {
- wpa_printf(MSG_ERROR, "%s: Could not parse data",
- __func__);
- hostapd_free_hw_features(modes, *num_modes);
- modes = NULL;
- break;
+
+ mode->channels = calloc(mode->num_channels, sizeof(struct hostapd_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 |= HOSTAPD_CHAN_W_SCAN |
+ HOSTAPD_CHAN_W_ACTIVE_SCAN |
+ HOSTAPD_CHAN_W_IBSS;
+
+ if (!mode_is_set) {
+ /* crude heuristic */
+ if (mode->channels[idx].freq < 4000)
+ mode->mode = HOSTAPD_MODE_IEEE80211B;
+ else
+ mode->mode = HOSTAPD_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 &= ~HOSTAPD_CHAN_W_SCAN;
+ if (tb_freq[NL80211_FREQUENCY_ATTR_PASSIVE_SCAN])
+ mode->channels[idx].flag &= ~HOSTAPD_CHAN_W_ACTIVE_SCAN;
+ if (tb_freq[NL80211_FREQUENCY_ATTR_NO_IBSS])
+ mode->channels[idx].flag &= ~HOSTAPD_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++;
}
- memcpy(feature->channels, pos, clen);
- pos += clen;
- memcpy(feature->rates, pos, rlen);
- pos += rlen;
+ mode->rates = calloc(mode->num_rates, sizeof(struct hostapd_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 == HOSTAPD_MODE_IEEE80211B &&
+ mode->rates[idx].rate > 200)
+ mode->mode = HOSTAPD_MODE_IEEE80211G;
+
+ if (tb_rate[NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE])
+ mode->rates[idx].flags |= HOSTAPD_RATE_PREAMBLE2;
+
+ idx++;
+ }
}
- free(param);
+ phy_info->error = 0;
- return modes;
+ return NL_SKIP;
+}
+
+static struct hostapd_hw_modes *i802_get_hw_feature_data(void *priv,
+ u16 *num_modes,
+ u16 *flags)
+{
+ struct i802_driver_data *drv = priv;
+ struct nl_msg *msg;
+ int err = -1;
+ struct nl_cb *cb = NULL;
+ int finished;
+ struct phy_info_arg result = {
+ .num_modes = num_modes,
+ .modes = NULL,
+ .error = 1,
+ };
+
+ *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, if_nametoindex(drv->iface));
+
+ cb = nl_cb_alloc(NL_CB_CUSTOM);
+ if (!cb)
+ goto out;
+
+ if (nl_send_auto_complete(drv->nl_handle, msg) < 0)
+ goto out;
+
+ nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, phy_info_handler, &result);
+ nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_wait_handler, &finished);
+
+ err = nl_recvmsgs(drv->nl_handle, cb);
+
+ if (!finished)
+ err = nl_wait_for_ack(drv->nl_handle);
+
+ if (err < 0 || result.error) {
+ hostapd_free_hw_features(result.modes, *num_modes);
+ result.modes = NULL;
+ }
+
+ out:
+ nl_cb_put(cb);
+ nla_put_failure:
+ if (err)
+ fprintf(stderr, "failed to get information: %d\n", err);
+ nlmsg_free(msg);
+ return result.modes;
}
@@ -1508,7 +1584,7 @@ static int i802_set_sta_vlan(void *priv, const u8 *addr,
ret = 0;
if (nl_send_auto_complete(drv->nl_handle, msg) < 0 ||
- nl_wait_for_ack(drv->nl_handle) < 0) {
+ (errno = nl_wait_for_ack(drv->nl_handle) < 0)) {
ret = -1;
}