Merge branch 'for-davem' of git://git.kernel.org/pub/scm/linux/kernel/git/linville...
[cascardo/linux.git] / net / mac80211 / key.c
index 3203d1d..3570f8c 100644 (file)
@@ -60,7 +60,7 @@ static struct ieee80211_sta *get_sta_for_key(struct ieee80211_key *key)
        return NULL;
 }
 
-static void ieee80211_key_enable_hw_accel(struct ieee80211_key *key)
+static int ieee80211_key_enable_hw_accel(struct ieee80211_key *key)
 {
        struct ieee80211_sub_if_data *sdata;
        struct ieee80211_sta *sta;
@@ -68,8 +68,10 @@ static void ieee80211_key_enable_hw_accel(struct ieee80211_key *key)
 
        might_sleep();
 
-       if (!key->local->ops->set_key)
-               return;
+       if (!key->local->ops->set_key) {
+               ret = -EOPNOTSUPP;
+               goto out_unsupported;
+       }
 
        assert_key_lock(key->local);
 
@@ -87,10 +89,27 @@ static void ieee80211_key_enable_hw_accel(struct ieee80211_key *key)
                key->flags |= KEY_FLAG_UPLOADED_TO_HARDWARE;
 
        if (ret && ret != -ENOSPC && ret != -EOPNOTSUPP)
-               printk(KERN_ERR "mac80211-%s: failed to set key "
-                      "(%d, %pM) to hardware (%d)\n",
-                      wiphy_name(key->local->hw.wiphy),
-                      key->conf.keyidx, sta ? sta->addr : bcast_addr, ret);
+               wiphy_err(key->local->hw.wiphy,
+                         "failed to set key (%d, %pM) to hardware (%d)\n",
+                         key->conf.keyidx, sta ? sta->addr : bcast_addr, ret);
+
+out_unsupported:
+       if (ret) {
+               switch (key->conf.cipher) {
+               case WLAN_CIPHER_SUITE_WEP40:
+               case WLAN_CIPHER_SUITE_WEP104:
+               case WLAN_CIPHER_SUITE_TKIP:
+               case WLAN_CIPHER_SUITE_CCMP:
+               case WLAN_CIPHER_SUITE_AES_CMAC:
+                       /* all of these we can do in software */
+                       ret = 0;
+                       break;
+               default:
+                       ret = -EINVAL;
+               }
+       }
+
+       return ret;
 }
 
 static void ieee80211_key_disable_hw_accel(struct ieee80211_key *key)
@@ -121,10 +140,9 @@ static void ieee80211_key_disable_hw_accel(struct ieee80211_key *key)
                          sta, &key->conf);
 
        if (ret)
-               printk(KERN_ERR "mac80211-%s: failed to remove key "
-                      "(%d, %pM) from hardware (%d)\n",
-                      wiphy_name(key->local->hw.wiphy),
-                      key->conf.keyidx, sta ? sta->addr : bcast_addr, ret);
+               wiphy_err(key->local->hw.wiphy,
+                         "failed to remove key (%d, %pM) from hardware (%d)\n",
+                         key->conf.keyidx, sta ? sta->addr : bcast_addr, ret);
 
        key->flags &= ~KEY_FLAG_UPLOADED_TO_HARDWARE;
 }
@@ -277,19 +295,6 @@ struct ieee80211_key *ieee80211_key_alloc(u32 cipher, int idx, size_t key_len,
                                        key->u.ccmp.rx_pn[i][j] =
                                                seq[CCMP_PN_LEN - j - 1];
                }
-               break;
-       case WLAN_CIPHER_SUITE_AES_CMAC:
-               key->conf.iv_len = 0;
-               key->conf.icv_len = sizeof(struct ieee80211_mmie);
-               if (seq)
-                       for (j = 0; j < 6; j++)
-                               key->u.aes_cmac.rx_pn[j] = seq[6 - j - 1];
-               break;
-       }
-       memcpy(key->conf.key, key_data, key_len);
-       INIT_LIST_HEAD(&key->list);
-
-       if (cipher == WLAN_CIPHER_SUITE_CCMP) {
                /*
                 * Initialize AES key state here as an optimization so that
                 * it does not need to be initialized for every packet.
@@ -300,9 +305,13 @@ struct ieee80211_key *ieee80211_key_alloc(u32 cipher, int idx, size_t key_len,
                        kfree(key);
                        key = ERR_PTR(err);
                }
-       }
-
-       if (cipher == WLAN_CIPHER_SUITE_AES_CMAC) {
+               break;
+       case WLAN_CIPHER_SUITE_AES_CMAC:
+               key->conf.iv_len = 0;
+               key->conf.icv_len = sizeof(struct ieee80211_mmie);
+               if (seq)
+                       for (j = 0; j < 6; j++)
+                               key->u.aes_cmac.rx_pn[j] = seq[6 - j - 1];
                /*
                 * Initialize AES key state here as an optimization so that
                 * it does not need to be initialized for every packet.
@@ -314,7 +323,10 @@ struct ieee80211_key *ieee80211_key_alloc(u32 cipher, int idx, size_t key_len,
                        kfree(key);
                        key = ERR_PTR(err);
                }
+               break;
        }
+       memcpy(key->conf.key, key_data, key_len);
+       INIT_LIST_HEAD(&key->list);
 
        return key;
 }
@@ -337,12 +349,12 @@ static void __ieee80211_key_destroy(struct ieee80211_key *key)
        kfree(key);
 }
 
-void ieee80211_key_link(struct ieee80211_key *key,
-                       struct ieee80211_sub_if_data *sdata,
-                       struct sta_info *sta)
+int ieee80211_key_link(struct ieee80211_key *key,
+                      struct ieee80211_sub_if_data *sdata,
+                      struct sta_info *sta)
 {
        struct ieee80211_key *old_key;
-       int idx;
+       int idx, ret;
 
        BUG_ON(!sdata);
        BUG_ON(!key);
@@ -397,9 +409,11 @@ void ieee80211_key_link(struct ieee80211_key *key,
 
        ieee80211_debugfs_key_add(key);
 
-       ieee80211_key_enable_hw_accel(key);
+       ret = ieee80211_key_enable_hw_accel(key);
 
        mutex_unlock(&sdata->local->key_mtx);
+
+       return ret;
 }
 
 static void __ieee80211_key_free(struct ieee80211_key *key)