Added an option to add (or override) Credential attribute(s) in M8
[wpasupplicant] / hostapd / driver_nl80211.c
index e59f5cd..508a379 100644 (file)
 
 #include "hostapd.h"
 #include "driver.h"
-#include "ieee802_1x.h"
 #include "eloop.h"
-#include "ieee802_11.h"
-#include "sta_info.h"
 #include "hw_features.h"
 #include "mlme.h"
 #include "radiotap.h"
 #include "radiotap_iter.h"
+#include "ieee802_11_defs.h"
+
+#ifdef CONFIG_LIBNL20
+/* libnl 2.0 compatibility code */
+#define nl_handle_alloc_cb nl_socket_alloc_cb
+#define nl_handle_destroy nl_socket_free
+#endif /* CONFIG_LIBNL20 */
+
+static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
 
 enum ieee80211_msg_type {
        ieee80211_msg_normal = 0,
@@ -75,6 +81,10 @@ struct i802_driver_data {
 };
 
 
+static int i802_sta_deauth(void *priv, const u8 *addr, int reason);
+static int i802_sta_disassoc(void *priv, const u8 *addr, int reason);
+
+
 static void add_ifidx(struct i802_driver_data *drv, int ifidx)
 {
        int i;
@@ -289,14 +299,10 @@ static int nl_set_encr(int ifindex, struct i802_driver_data *drv,
                    0, NL80211_CMD_SET_KEY, 0);
        NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, idx);
        NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifindex);
-#ifdef NL80211_MFP_PENDING
        if (strcmp(alg, "IGTK") == 0)
                NLA_PUT_FLAG(msg, NL80211_ATTR_KEY_DEFAULT_MGMT);
        else
                NLA_PUT_FLAG(msg, NL80211_ATTR_KEY_DEFAULT);
-#else /* NL80211_MFP_PENDING */
-       NLA_PUT_FLAG(msg, NL80211_ATTR_KEY_DEFAULT);
-#endif /* NL80211_MFP_PENDING */
 
        ret = send_and_recv_msgs(drv, msg, NULL, NULL);
        if (ret == -ENOENT)
@@ -319,11 +325,6 @@ static int i802_set_encryption(const char *iface, void *priv, const char *alg,
        if (ret < 0)
                return ret;
 
-       if (strcmp(alg, "IGTK") == 0) {
-               ret = nl_set_encr(drv->monitor_ifidx, drv, alg, addr, idx, key,
-                                 key_len, txkey);
-       }
-
        return ret;
 }
 
@@ -501,16 +502,16 @@ static int i802_set_freq2(void *priv, struct hostapd_freq_params *freq)
        if (freq->ht_enabled) {
                switch (freq->sec_channel_offset) {
                case -1:
-                       NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_SEC_CHAN_OFFSET,
-                                   NL80211_SEC_CHAN_BELOW);
+                       NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
+                                   NL80211_CHAN_HT40MINUS);
                        break;
                case 1:
-                       NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_SEC_CHAN_OFFSET,
-                                   NL80211_SEC_CHAN_ABOVE);
+                       NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
+                                   NL80211_CHAN_HT40PLUS);
                        break;
                default:
-                       NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_SEC_CHAN_OFFSET,
-                                   NL80211_SEC_CHAN_DISABLED);
+                       NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
+                                   NL80211_CHAN_HT20);
                        break;
                }
        }
@@ -528,7 +529,7 @@ static int i802_set_rts(void *priv, int rts)
        struct iwreq iwr;
 
        memset(&iwr, 0, sizeof(iwr));
-       os_strlcpy(iwr.ifr_name, drv->hapd->conf->iface, IFNAMSIZ);
+       os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
        iwr.u.rts.value = rts;
        iwr.u.rts.fixed = 1;
 
@@ -547,7 +548,7 @@ static int i802_get_rts(void *priv, int *rts)
        struct iwreq iwr;
 
        memset(&iwr, 0, sizeof(iwr));
-       os_strlcpy(iwr.ifr_name, drv->hapd->conf->iface, IFNAMSIZ);
+       os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
 
        if (ioctl(drv->ioctl_sock, SIOCGIWRTS, &iwr) < 0) {
                perror("ioctl[SIOCGIWRTS]");
@@ -566,7 +567,7 @@ static int i802_set_frag(void *priv, int frag)
        struct iwreq iwr;
 
        memset(&iwr, 0, sizeof(iwr));
-       os_strlcpy(iwr.ifr_name, drv->hapd->conf->iface, IFNAMSIZ);
+       os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
        iwr.u.frag.value = frag;
        iwr.u.frag.fixed = 1;
 
@@ -585,7 +586,7 @@ static int i802_get_frag(void *priv, int *frag)
        struct iwreq iwr;
 
        memset(&iwr, 0, sizeof(iwr));
-       os_strlcpy(iwr.ifr_name, drv->hapd->conf->iface, IFNAMSIZ);
+       os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
 
        if (ioctl(drv->ioctl_sock, SIOCGIWFRAG, &iwr) < 0) {
                perror("ioctl[SIOCGIWFRAG]");
@@ -604,18 +605,18 @@ static int i802_set_retry(void *priv, int short_retry, int long_retry)
        struct iwreq iwr;
 
        memset(&iwr, 0, sizeof(iwr));
-       os_strlcpy(iwr.ifr_name, drv->hapd->conf->iface, IFNAMSIZ);
+       os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
 
        iwr.u.retry.value = short_retry;
        iwr.u.retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN;
-       if (ioctl(drv->ioctl_sock, SIOCSIWFRAG, &iwr) < 0) {
+       if (ioctl(drv->ioctl_sock, SIOCSIWRETRY, &iwr) < 0) {
                perror("ioctl[SIOCSIWRETRY(short)]");
                return -1;
        }
 
        iwr.u.retry.value = long_retry;
        iwr.u.retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
-       if (ioctl(drv->ioctl_sock, SIOCSIWFRAG, &iwr) < 0) {
+       if (ioctl(drv->ioctl_sock, SIOCSIWRETRY, &iwr) < 0) {
                perror("ioctl[SIOCSIWRETRY(long)]");
                return -1;
        }
@@ -630,7 +631,7 @@ static int i802_get_retry(void *priv, int *short_retry, int *long_retry)
        struct iwreq iwr;
 
        memset(&iwr, 0, sizeof(iwr));
-       os_strlcpy(iwr.ifr_name, drv->hapd->conf->iface, IFNAMSIZ);
+       os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
 
        iwr.u.retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN;
        if (ioctl(drv->ioctl_sock, SIOCGIWRETRY, &iwr) < 0) {
@@ -904,10 +905,8 @@ static int i802_sta_set_flags(void *priv, const u8 *addr,
        if (total_flags & WLAN_STA_SHORT_PREAMBLE)
                NLA_PUT_FLAG(flags, NL80211_STA_FLAG_SHORT_PREAMBLE);
 
-#ifdef NL80211_MFP_PENDING
        if (total_flags & WLAN_STA_MFP)
                NLA_PUT_FLAG(flags, NL80211_STA_FLAG_MFP);
-#endif /* NL80211_MFP_PENDING */
 
        if (nla_put_nested(msg, NL80211_ATTR_STA_FLAGS, flags))
                goto nla_put_failure;
@@ -921,12 +920,6 @@ static int i802_sta_set_flags(void *priv, const u8 *addr,
 }
 
 
-static int i802_set_regulatory_domain(void *priv, unsigned int rd)
-{
-       return -1;
-}
-
-
 static int i802_set_tx_queue_params(void *priv, int queue, int aifs,
                                    int cw_min, int cw_max, int burst_time)
 {
@@ -1010,8 +1003,7 @@ static int nl80211_create_iface(struct i802_driver_data *drv,
 
        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->hapd->conf->iface));
+       NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
        NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, ifname);
        NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, iftype);
 
@@ -1636,32 +1628,11 @@ static int i802_set_country(void *priv, const char *country)
 }
 
 
-static void handle_unknown_sta(struct hostapd_data *hapd, u8 *ta)
-{
-       struct sta_info *sta;
-
-       sta = ap_get_sta(hapd, ta);
-       if (!sta || !(sta->flags & WLAN_STA_ASSOC)) {
-               printf("Data/PS-poll frame from not associated STA "
-                      MACSTR "\n", MAC2STR(ta));
-               if (sta && (sta->flags & WLAN_STA_AUTH))
-                       hostapd_sta_disassoc(
-                               hapd, ta,
-                               WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
-               else
-                       hostapd_sta_deauth(
-                               hapd, ta,
-                               WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
-       }
-}
-
-
 static void handle_tx_callback(struct hostapd_data *hapd, u8 *buf, size_t len,
                               int ok)
 {
        struct ieee80211_hdr *hdr;
        u16 fc, type, stype;
-       struct sta_info *sta;
 
        hdr = (struct ieee80211_hdr *) buf;
        fc = le_to_host16(hdr->frame_control);
@@ -1673,7 +1644,7 @@ static void handle_tx_callback(struct hostapd_data *hapd, u8 *buf, size_t len,
        case WLAN_FC_TYPE_MGMT:
                wpa_printf(MSG_DEBUG, "MGMT (TX callback) %s",
                           ok ? "ACK" : "fail");
-               ieee802_11_mgmt_cb(hapd, buf, len, stype, ok);
+               hostapd_mgmt_tx_cb(hapd, buf, len, stype, ok);
                break;
        case WLAN_FC_TYPE_CTRL:
                wpa_printf(MSG_DEBUG, "CTRL (TX callback) %s",
@@ -1682,16 +1653,7 @@ static void handle_tx_callback(struct hostapd_data *hapd, u8 *buf, size_t len,
        case WLAN_FC_TYPE_DATA:
                wpa_printf(MSG_DEBUG, "DATA (TX callback) %s",
                           ok ? "ACK" : "fail");
-               sta = ap_get_sta(hapd, hdr->addr1);
-               if (sta && sta->flags & WLAN_STA_PENDING_POLL) {
-                       wpa_printf(MSG_DEBUG, "STA " MACSTR " %s pending "
-                                  "activity poll", MAC2STR(sta->addr),
-                                  ok ? "ACKed" : "did not ACK");
-                       if (ok)
-                               sta->flags &= ~WLAN_STA_PENDING_POLL;
-               }
-               if (sta)
-                       ieee802_1x_tx_status(hapd, sta, buf, len, ok);
+               hostapd_tx_status(hapd, hdr->addr1, buf, len, ok);
                break;
        default:
                printf("unknown TX callback frame type %d\n", type);
@@ -1700,7 +1662,8 @@ static void handle_tx_callback(struct hostapd_data *hapd, u8 *buf, size_t len,
 }
 
 
-static void handle_frame(struct hostapd_iface *iface, u8 *buf, size_t len,
+static void handle_frame(struct i802_driver_data *drv,
+                        struct hostapd_iface *iface, u8 *buf, size_t len,
                         struct hostapd_frame_info *hfi,
                         enum ieee80211_msg_type msg_type)
 {
@@ -1798,18 +1761,18 @@ static void handle_frame(struct hostapd_iface *iface, u8 *buf, size_t len,
                        wpa_printf(MSG_MSGDUMP, "MGMT");
                if (broadcast_bssid) {
                        for (i = 0; i < iface->num_bss; i++)
-                               ieee802_11_mgmt(iface->bss[i], buf, data_len,
+                               hostapd_mgmt_rx(iface->bss[i], buf, data_len,
                                                stype, hfi);
                } else
-                       ieee802_11_mgmt(hapd, buf, data_len, stype, hfi);
+                       hostapd_mgmt_rx(hapd, buf, data_len, stype, hfi);
                break;
        case WLAN_FC_TYPE_CTRL:
                /* can only get here with PS-Poll frames */
                wpa_printf(MSG_DEBUG, "CTRL");
-               handle_unknown_sta(hapd, hdr->addr2);
+               hostapd_rx_from_unknown_sta(drv->hapd, hdr->addr2);
                break;
        case WLAN_FC_TYPE_DATA:
-               handle_unknown_sta(hapd, hdr->addr2);
+               hostapd_rx_from_unknown_sta(drv->hapd, hdr->addr2);
                break;
        }
 }
@@ -1832,7 +1795,7 @@ static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx)
        }
 
        if (have_ifidx(drv, lladdr.sll_ifindex))
-               ieee802_1x_receive(hapd, lladdr.sll_addr, buf, len);
+               hostapd_eapol_receive(hapd, lladdr.sll_addr, buf, len);
 }
 
 
@@ -1908,7 +1871,7 @@ static void handle_monitor_read(int sock, void *eloop_ctx, void *sock_ctx)
        else
                msg_type = ieee80211_msg_tx_callback_ack;
 
-       handle_frame(hapd->iface, buf + iter.max_length,
+       handle_frame(drv, hapd->iface, buf + iter.max_length,
                     len - iter.max_length, &hfi, msg_type);
 }
 
@@ -1999,8 +1962,6 @@ static int i802_init_sockets(struct i802_driver_data *drv, const u8 *bssid)
        struct ifreq ifr;
        struct sockaddr_ll addr;
 
-       drv->ioctl_sock = -1;
-
        drv->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
        if (drv->ioctl_sock < 0) {
                perror("socket[PF_INET,SOCK_DGRAM]");
@@ -2044,11 +2005,18 @@ static int i802_init_sockets(struct i802_driver_data *drv, const u8 *bssid)
                return -1;
        }
 
+#ifdef CONFIG_LIBNL20
+       if (genl_ctrl_alloc_cache(drv->nl_handle, &drv->nl_cache) < 0) {
+               printf("Failed to allocate generic netlink cache.\n");
+               return -1;
+       }
+#else /* CONFIG_LIBNL20 */
        drv->nl_cache = genl_ctrl_alloc_cache(drv->nl_handle);
        if (!drv->nl_cache) {
                printf("Failed to allocate generic netlink cache.\n");
                return -1;
        }
+#endif /* CONFIG_LIBNL20 */
 
        drv->nl80211 = genl_ctrl_search_by_name(drv->nl_cache, "nl80211");
        if (!drv->nl80211) {
@@ -2146,7 +2114,7 @@ hostapd_wireless_event_wireless_custom(struct i802_driver_data *drv,
                }
                pos += 5;
                if (hwaddr_aton(pos, addr) == 0) {
-                       ieee80211_michael_mic_failure(drv->hapd, addr, 1);
+                       hostapd_michael_mic_failure(drv->hapd, addr);
                } else {
                        wpa_printf(MSG_DEBUG,
                                   "MLME-MICHAELMICFAILURE.indication "
@@ -2519,7 +2487,6 @@ const struct wpa_driver_ops wpa_driver_nl80211_ops = {
        .set_retry = i802_set_retry,
        .get_retry = i802_get_retry,
        .set_rate_sets = i802_set_rate_sets,
-       .set_regulatory_domain = i802_set_regulatory_domain,
        .set_beacon = i802_set_beacon,
        .set_internal_bridge = i802_set_internal_bridge,
        .set_beacon_int = i802_set_beacon_int,