wl1271: Fix keep-alive related command error
[safe/jmp/linux-2.6] / drivers / net / wireless / rndis_wlan.c
index a4f70de..267afd7 100644 (file)
@@ -117,6 +117,7 @@ MODULE_PARM_DESC(workaround_interval,
 #define OID_802_11_ADD_KEY                     cpu_to_le32(0x0d01011d)
 #define OID_802_11_REMOVE_KEY                  cpu_to_le32(0x0d01011e)
 #define OID_802_11_ASSOCIATION_INFORMATION     cpu_to_le32(0x0d01011f)
+#define OID_802_11_CAPABILITY                  cpu_to_le32(0x0d010122)
 #define OID_802_11_PMKID                       cpu_to_le32(0x0d010123)
 #define OID_802_11_NETWORK_TYPES_SUPPORTED     cpu_to_le32(0x0d010203)
 #define OID_802_11_NETWORK_TYPE_IN_USE         cpu_to_le32(0x0d010204)
@@ -358,6 +359,30 @@ struct ndis_80211_assoc_info {
        __le32 offset_resp_ies;
 } __attribute__((packed));
 
+struct ndis_80211_auth_encr_pair {
+       __le32 auth_mode;
+       __le32 encr_mode;
+} __attribute__((packed));
+
+struct ndis_80211_capability {
+       __le32 length;
+       __le32 version;
+       __le32 num_pmkids;
+       __le32 num_auth_encr_pair;
+       struct ndis_80211_auth_encr_pair auth_encr_pair[0];
+} __attribute__((packed));
+
+struct ndis_80211_bssid_info {
+       u8 bssid[6];
+       u8 pmkid[16];
+};
+
+struct ndis_80211_pmkid {
+       __le32 length;
+       __le32 bssid_info_count;
+       struct ndis_80211_bssid_info bssid_info[0];
+};
+
 /*
  *  private data
  */
@@ -476,13 +501,7 @@ struct rndis_wlan_private {
        /* encryption stuff */
        int  encr_tx_key_index;
        struct rndis_wlan_encr_key encr_keys[4];
-       enum nl80211_auth_type wpa_auth_type;
        int  wpa_version;
-       int  wpa_keymgmt;
-       int  wpa_ie_len;
-       u8  *wpa_ie;
-       int  wpa_cipher_pair;
-       int  wpa_cipher_group;
 
        u8 command_buffer[COMMAND_BUFFER_SIZE];
 };
@@ -534,6 +553,14 @@ static int rndis_get_station(struct wiphy *wiphy, struct net_device *dev,
 static int rndis_dump_station(struct wiphy *wiphy, struct net_device *dev,
                               int idx, u8 *mac, struct station_info *sinfo);
 
+static int rndis_set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
+                               struct cfg80211_pmksa *pmksa);
+
+static int rndis_del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
+                               struct cfg80211_pmksa *pmksa);
+
+static int rndis_flush_pmksa(struct wiphy *wiphy, struct net_device *netdev);
+
 static struct cfg80211_ops rndis_config_ops = {
        .change_virtual_intf = rndis_change_virtual_intf,
        .scan = rndis_scan,
@@ -550,6 +577,9 @@ static struct cfg80211_ops rndis_config_ops = {
        .set_default_key = rndis_set_default_key,
        .get_station = rndis_get_station,
        .dump_station = rndis_dump_station,
+       .set_pmksa = rndis_set_pmksa,
+       .del_pmksa = rndis_del_pmksa,
+       .flush_pmksa = rndis_flush_pmksa,
 };
 
 static void *rndis_wiphy_privid = &rndis_wiphy_privid;
@@ -1116,8 +1146,6 @@ static int set_auth_mode(struct usbnet *usbdev, u32 wpa_version,
        }
 
        priv->wpa_version = wpa_version;
-       priv->wpa_auth_type = auth_type;
-       priv->wpa_keymgmt = keymgmt;
 
        return 0;
 }
@@ -1142,7 +1170,6 @@ static int set_priv_filter(struct usbnet *usbdev)
 
 static int set_encr_mode(struct usbnet *usbdev, int pairwise, int groupwise)
 {
-       struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
        __le32 tmp;
        int encr_mode, ret;
 
@@ -1171,8 +1198,6 @@ static int set_encr_mode(struct usbnet *usbdev, int pairwise, int groupwise)
                return ret;
        }
 
-       priv->wpa_cipher_pair = pairwise;
-       priv->wpa_cipher_group = groupwise;
        return 0;
 }
 
@@ -1577,6 +1602,194 @@ static void set_multicast_list(struct usbnet *usbdev)
                   le32_to_cpu(filter), ret);
 }
 
+#ifdef DEBUG
+static void debug_print_pmkids(struct usbnet *usbdev,
+                               struct ndis_80211_pmkid *pmkids,
+                               const char *func_str)
+{
+       struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
+       int i, len, count, max_pmkids, entry_len;
+
+       max_pmkids = priv->wdev.wiphy->max_num_pmkids;
+       len = le32_to_cpu(pmkids->length);
+       count = le32_to_cpu(pmkids->bssid_info_count);
+
+       entry_len = (count > 0) ? (len - sizeof(*pmkids)) / count : -1;
+
+       netdev_dbg(usbdev->net, "%s(): %d PMKIDs (data len: %d, entry len: "
+                               "%d)\n", func_str, count, len, entry_len);
+
+       if (count > max_pmkids)
+               count = max_pmkids;
+
+       for (i = 0; i < count; i++) {
+               u32 *tmp = (u32 *)pmkids->bssid_info[i].pmkid;
+
+               netdev_dbg(usbdev->net, "%s():  bssid: %pM, "
+                               "pmkid: %08X:%08X:%08X:%08X\n",
+                               func_str, pmkids->bssid_info[i].bssid,
+                               cpu_to_be32(tmp[0]), cpu_to_be32(tmp[1]),
+                               cpu_to_be32(tmp[2]), cpu_to_be32(tmp[3]));
+       }
+}
+#else
+static void debug_print_pmkids(struct usbnet *usbdev,
+                               struct ndis_80211_pmkid *pmkids,
+                               const char *func_str)
+{
+       return;
+}
+#endif
+
+static struct ndis_80211_pmkid *get_device_pmkids(struct usbnet *usbdev)
+{
+       struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
+       struct ndis_80211_pmkid *pmkids;
+       int len, ret, max_pmkids;
+
+       max_pmkids = priv->wdev.wiphy->max_num_pmkids;
+       len = sizeof(*pmkids) + max_pmkids * sizeof(pmkids->bssid_info[0]);
+
+       pmkids = kzalloc(len, GFP_KERNEL);
+       if (!pmkids)
+               return ERR_PTR(-ENOMEM);
+
+       pmkids->length = cpu_to_le32(len);
+       pmkids->bssid_info_count = cpu_to_le32(max_pmkids);
+
+       ret = rndis_query_oid(usbdev, OID_802_11_PMKID, pmkids, &len);
+       if (ret < 0) {
+               netdev_dbg(usbdev->net, "%s(): OID_802_11_PMKID(%d, %d)"
+                               " -> %d\n", __func__, len, max_pmkids, ret);
+
+               kfree(pmkids);
+               return ERR_PTR(ret);
+       }
+
+       if (le32_to_cpu(pmkids->bssid_info_count) > max_pmkids)
+               pmkids->bssid_info_count = cpu_to_le32(max_pmkids);
+
+       debug_print_pmkids(usbdev, pmkids, __func__);
+
+       return pmkids;
+}
+
+static int set_device_pmkids(struct usbnet *usbdev,
+                               struct ndis_80211_pmkid *pmkids)
+{
+       int ret, len, num_pmkids;
+
+       num_pmkids = le32_to_cpu(pmkids->bssid_info_count);
+       len = sizeof(*pmkids) + num_pmkids * sizeof(pmkids->bssid_info[0]);
+       pmkids->length = cpu_to_le32(len);
+
+       debug_print_pmkids(usbdev, pmkids, __func__);
+
+       ret = rndis_set_oid(usbdev, OID_802_11_PMKID, pmkids,
+                                               le32_to_cpu(pmkids->length));
+       if (ret < 0) {
+               netdev_dbg(usbdev->net, "%s(): OID_802_11_PMKID(%d, %d) -> %d"
+                               "\n", __func__, len, num_pmkids, ret);
+       }
+
+       kfree(pmkids);
+       return ret;
+}
+
+static struct ndis_80211_pmkid *remove_pmkid(struct usbnet *usbdev,
+                                               struct ndis_80211_pmkid *pmkids,
+                                               struct cfg80211_pmksa *pmksa,
+                                               int max_pmkids)
+{
+       int i, len, count, newlen, err;
+
+       len = le32_to_cpu(pmkids->length);
+       count = le32_to_cpu(pmkids->bssid_info_count);
+
+       if (count > max_pmkids)
+               count = max_pmkids;
+
+       for (i = 0; i < count; i++)
+               if (!compare_ether_addr(pmkids->bssid_info[i].bssid,
+                                                       pmksa->bssid))
+                       break;
+
+       /* pmkid not found */
+       if (i == count) {
+               netdev_dbg(usbdev->net, "%s(): bssid not found (%pM)\n",
+                                       __func__, pmksa->bssid);
+               err = -ENOENT;
+               goto error;
+       }
+
+       for (; i + 1 < count; i++)
+               pmkids->bssid_info[i] = pmkids->bssid_info[i + 1];
+
+       count--;
+       newlen = sizeof(*pmkids) + count * sizeof(pmkids->bssid_info[0]);
+
+       pmkids->length = cpu_to_le32(newlen);
+       pmkids->bssid_info_count = cpu_to_le32(count);
+
+       return pmkids;
+error:
+       kfree(pmkids);
+       return ERR_PTR(err);
+}
+
+static struct ndis_80211_pmkid *update_pmkid(struct usbnet *usbdev,
+                                               struct ndis_80211_pmkid *pmkids,
+                                               struct cfg80211_pmksa *pmksa,
+                                               int max_pmkids)
+{
+       int i, err, len, count, newlen;
+
+       len = le32_to_cpu(pmkids->length);
+       count = le32_to_cpu(pmkids->bssid_info_count);
+
+       if (count > max_pmkids)
+               count = max_pmkids;
+
+       /* update with new pmkid */
+       for (i = 0; i < count; i++) {
+               if (compare_ether_addr(pmkids->bssid_info[i].bssid,
+                                                       pmksa->bssid))
+                       continue;
+
+               memcpy(pmkids->bssid_info[i].pmkid, pmksa->pmkid,
+                                                               WLAN_PMKID_LEN);
+
+               return pmkids;
+       }
+
+       /* out of space, return error */
+       if (i == max_pmkids) {
+               netdev_dbg(usbdev->net, "%s(): out of space\n", __func__);
+               err = -ENOSPC;
+               goto error;
+       }
+
+       /* add new pmkid */
+       newlen = sizeof(*pmkids) + (count + 1) * sizeof(pmkids->bssid_info[0]);
+
+       pmkids = krealloc(pmkids, newlen, GFP_KERNEL);
+       if (!pmkids) {
+               err = -ENOMEM;
+               goto error;
+       }
+
+       pmkids->length = cpu_to_le32(newlen);
+       pmkids->bssid_info_count = cpu_to_le32(count + 1);
+
+       memcpy(pmkids->bssid_info[count].bssid, pmksa->bssid, ETH_ALEN);
+       memcpy(pmkids->bssid_info[count].pmkid, pmksa->pmkid, WLAN_PMKID_LEN);
+
+       return pmkids;
+error:
+       kfree(pmkids);
+       return ERR_PTR(err);
+}
+
 /*
  * cfg80211 ops
  */
@@ -2187,6 +2400,78 @@ static int rndis_dump_station(struct wiphy *wiphy, struct net_device *dev,
        return 0;
 }
 
+static int rndis_set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
+                               struct cfg80211_pmksa *pmksa)
+{
+       struct rndis_wlan_private *priv = wiphy_priv(wiphy);
+       struct usbnet *usbdev = priv->usbdev;
+       struct ndis_80211_pmkid *pmkids;
+       u32 *tmp = (u32 *)pmksa->pmkid;
+
+       netdev_dbg(usbdev->net, "%s(%pM, %08X:%08X:%08X:%08X)\n", __func__,
+                       pmksa->bssid,
+                       cpu_to_be32(tmp[0]), cpu_to_be32(tmp[1]),
+                       cpu_to_be32(tmp[2]), cpu_to_be32(tmp[3]));
+
+       pmkids = get_device_pmkids(usbdev);
+       if (IS_ERR(pmkids)) {
+               /* couldn't read PMKID cache from device */
+               return PTR_ERR(pmkids);
+       }
+
+       pmkids = update_pmkid(usbdev, pmkids, pmksa, wiphy->max_num_pmkids);
+       if (IS_ERR(pmkids)) {
+               /* not found, list full, etc */
+               return PTR_ERR(pmkids);
+       }
+
+       return set_device_pmkids(usbdev, pmkids);
+}
+
+static int rndis_del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
+                               struct cfg80211_pmksa *pmksa)
+{
+       struct rndis_wlan_private *priv = wiphy_priv(wiphy);
+       struct usbnet *usbdev = priv->usbdev;
+       struct ndis_80211_pmkid *pmkids;
+       u32 *tmp = (u32 *)pmksa->pmkid;
+
+       netdev_dbg(usbdev->net, "%s(%pM, %08X:%08X:%08X:%08X)\n", __func__,
+                       pmksa->bssid,
+                       cpu_to_be32(tmp[0]), cpu_to_be32(tmp[1]),
+                       cpu_to_be32(tmp[2]), cpu_to_be32(tmp[3]));
+
+       pmkids = get_device_pmkids(usbdev);
+       if (IS_ERR(pmkids)) {
+               /* Couldn't read PMKID cache from device */
+               return PTR_ERR(pmkids);
+       }
+
+       pmkids = remove_pmkid(usbdev, pmkids, pmksa, wiphy->max_num_pmkids);
+       if (IS_ERR(pmkids)) {
+               /* not found, etc */
+               return PTR_ERR(pmkids);
+       }
+
+       return set_device_pmkids(usbdev, pmkids);
+}
+
+static int rndis_flush_pmksa(struct wiphy *wiphy, struct net_device *netdev)
+{
+       struct rndis_wlan_private *priv = wiphy_priv(wiphy);
+       struct usbnet *usbdev = priv->usbdev;
+       struct ndis_80211_pmkid pmkid;
+
+       netdev_dbg(usbdev->net, "%s()\n", __func__);
+
+       memset(&pmkid, 0, sizeof(pmkid));
+
+       pmkid.length = cpu_to_le32(sizeof(pmkid));
+       pmkid.bssid_info_count = cpu_to_le32(0);
+
+       return rndis_set_oid(usbdev, OID_802_11_PMKID, &pmkid, sizeof(pmkid));
+}
+
 /*
  * workers, indication handlers, device poller
  */
@@ -2531,12 +2816,14 @@ static void rndis_wlan_indication(struct usbnet *usbdev, void *ind, int buflen)
        }
 }
 
-static int rndis_wlan_get_caps(struct usbnet *usbdev)
+static int rndis_wlan_get_caps(struct usbnet *usbdev, struct wiphy *wiphy)
 {
        struct {
                __le32  num_items;
                __le32  items[8];
        } networks_supported;
+       struct ndis_80211_capability *caps;
+       u8 caps_buf[sizeof(*caps) + sizeof(caps->auth_encr_pair) * 16];
        int len, retval, i, n;
        struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
 
@@ -2564,6 +2851,21 @@ static int rndis_wlan_get_caps(struct usbnet *usbdev)
                }
        }
 
+       /* get device 802.11 capabilities, number of PMKIDs */
+       caps = (struct ndis_80211_capability *)caps_buf;
+       len = sizeof(caps_buf);
+       retval = rndis_query_oid(usbdev, OID_802_11_CAPABILITY, caps, &len);
+       if (retval >= 0) {
+               netdev_dbg(usbdev->net, "OID_802_11_CAPABILITY -> len %d, "
+                               "ver %d, pmkids %d, auth-encr-pairs %d\n",
+                               le32_to_cpu(caps->length),
+                               le32_to_cpu(caps->version),
+                               le32_to_cpu(caps->num_pmkids),
+                               le32_to_cpu(caps->num_auth_encr_pair));
+               wiphy->max_num_pmkids = le32_to_cpu(caps->num_pmkids);
+       } else
+               wiphy->max_num_pmkids = 0;
+
        return retval;
 }
 
@@ -2811,7 +3113,7 @@ static int rndis_wlan_bind(struct usbnet *usbdev, struct usb_interface *intf)
        wiphy->max_scan_ssids = 1;
 
        /* TODO: fill-out band/encr information based on priv->caps */
-       rndis_wlan_get_caps(usbdev);
+       rndis_wlan_get_caps(usbdev, wiphy);
 
        memcpy(priv->channels, rndis_channels, sizeof(rndis_channels));
        memcpy(priv->rates, rndis_rates, sizeof(rndis_rates));
@@ -2871,9 +3173,6 @@ static void rndis_wlan_unbind(struct usbnet *usbdev, struct usb_interface *intf)
        flush_workqueue(priv->workqueue);
        destroy_workqueue(priv->workqueue);
 
-       if (priv && priv->wpa_ie_len)
-               kfree(priv->wpa_ie);
-
        rndis_unbind(usbdev, intf);
 
        wiphy_unregister(priv->wdev.wiphy);