mac80211: refresh patches

Signed-off-by: Felix Fietkau <nbd@nbd.name>
This commit is contained in:
Felix Fietkau 2017-02-12 15:00:20 +01:00
parent 75216a76b0
commit f28eef4460
4 changed files with 106 additions and 95 deletions

View file

@ -43,118 +43,122 @@
- struct aead_request *aead_req; - struct aead_request *aead_req;
- int reqsize = sizeof(*aead_req) + crypto_aead_reqsize(tfm); - int reqsize = sizeof(*aead_req) + crypto_aead_reqsize(tfm);
- u8 *__aad; - u8 *__aad;
+ int i; -
- aead_req = kzalloc(reqsize + CCM_AAD_LEN, GFP_ATOMIC); - aead_req = kzalloc(reqsize + CCM_AAD_LEN, GFP_ATOMIC);
- if (!aead_req) - if (!aead_req)
- return -ENOMEM; - return -ENOMEM;
+ crypto_cipher_encrypt_one(tfm, b, b_0); -
- __aad = (u8 *)aead_req + reqsize; - __aad = (u8 *)aead_req + reqsize;
- memcpy(__aad, aad, CCM_AAD_LEN); - memcpy(__aad, aad, CCM_AAD_LEN);
+ /* Extra Authenticate-only data (always two AES blocks) */ -
+ for (i = 0; i < AES_BLOCK_SIZE; i++)
+ aad[i] ^= b[i];
+ crypto_cipher_encrypt_one(tfm, b, aad);
- sg_init_table(sg, 3); - sg_init_table(sg, 3);
- sg_set_buf(&sg[0], &__aad[2], be16_to_cpup((__be16 *)__aad)); - sg_set_buf(&sg[0], &__aad[2], be16_to_cpup((__be16 *)__aad));
- sg_set_buf(&sg[1], data, data_len); - sg_set_buf(&sg[1], data, data_len);
- sg_set_buf(&sg[2], mic, mic_len); - sg_set_buf(&sg[2], mic, mic_len);
+ aad += AES_BLOCK_SIZE; -
- aead_request_set_tfm(aead_req, tfm); - aead_request_set_tfm(aead_req, tfm);
- aead_request_set_crypt(aead_req, sg, sg, data_len, b_0); - aead_request_set_crypt(aead_req, sg, sg, data_len, b_0);
- aead_request_set_ad(aead_req, sg[0].length); - aead_request_set_ad(aead_req, sg[0].length);
+ for (i = 0; i < AES_BLOCK_SIZE; i++) + int i;
+ aad[i] ^= b[i];
+ crypto_cipher_encrypt_one(tfm, a, aad);
- crypto_aead_encrypt(aead_req); - crypto_aead_encrypt(aead_req);
- kzfree(aead_req); - kzfree(aead_req);
+ /* Mask out bits from auth-only-b_0 */ + crypto_cipher_encrypt_one(tfm, b, b_0);
+ b_0[0] &= 0x07;
- return 0; - return 0;
+ /* Extra Authenticate-only data (always two AES blocks) */
+ for (i = 0; i < AES_BLOCK_SIZE; i++)
+ aad[i] ^= b[i];
+ crypto_cipher_encrypt_one(tfm, b, aad);
+
+ aad += AES_BLOCK_SIZE;
+
+ for (i = 0; i < AES_BLOCK_SIZE; i++)
+ aad[i] ^= b[i];
+ crypto_cipher_encrypt_one(tfm, a, aad);
+
+ /* Mask out bits from auth-only-b_0 */
+ b_0[0] &= 0x07;
+
+ /* S_0 is used to encrypt T (= MIC) */ + /* S_0 is used to encrypt T (= MIC) */
+ b_0[14] = 0; + b_0[14] = 0;
+ b_0[15] = 0; + b_0[15] = 0;
+ crypto_cipher_encrypt_one(tfm, s_0, b_0); + crypto_cipher_encrypt_one(tfm, s_0, b_0);
} +}
+
-int ieee80211_aes_ccm_decrypt(struct crypto_aead *tfm, u8 *b_0, u8 *aad,
- u8 *data, size_t data_len, u8 *mic,
- size_t mic_len)
+ +
+void ieee80211_aes_ccm_encrypt(struct crypto_cipher *tfm, u8 *b_0, u8 *aad, +void ieee80211_aes_ccm_encrypt(struct crypto_cipher *tfm, u8 *b_0, u8 *aad,
+ u8 *data, size_t data_len, u8 *mic, + u8 *data, size_t data_len, u8 *mic,
+ size_t mic_len) + size_t mic_len)
{ +{
- struct scatterlist sg[3];
- struct aead_request *aead_req;
- int reqsize = sizeof(*aead_req) + crypto_aead_reqsize(tfm);
- u8 *__aad;
- int err;
+ int i, j, last_len, num_blocks; + int i, j, last_len, num_blocks;
+ u8 b[AES_BLOCK_SIZE]; + u8 b[AES_BLOCK_SIZE];
+ u8 s_0[AES_BLOCK_SIZE]; + u8 s_0[AES_BLOCK_SIZE];
+ u8 e[AES_BLOCK_SIZE]; + u8 e[AES_BLOCK_SIZE];
+ u8 *pos, *cpos; + u8 *pos, *cpos;
+
- if (data_len == 0)
- return -EINVAL;
+ num_blocks = DIV_ROUND_UP(data_len, AES_BLOCK_SIZE); + num_blocks = DIV_ROUND_UP(data_len, AES_BLOCK_SIZE);
+ last_len = data_len % AES_BLOCK_SIZE; + last_len = data_len % AES_BLOCK_SIZE;
+ aes_ccm_prepare(tfm, b_0, aad, s_0, b, b); + aes_ccm_prepare(tfm, b_0, aad, s_0, b, b);
+
- aead_req = kzalloc(reqsize + CCM_AAD_LEN, GFP_ATOMIC);
- if (!aead_req)
- return -ENOMEM;
+ /* Process payload blocks */ + /* Process payload blocks */
+ pos = data; + pos = data;
+ cpos = data; + cpos = data;
+ for (j = 1; j <= num_blocks; j++) { + for (j = 1; j <= num_blocks; j++) {
+ int blen = (j == num_blocks && last_len) ? + int blen = (j == num_blocks && last_len) ?
+ last_len : AES_BLOCK_SIZE; + last_len : AES_BLOCK_SIZE;
+
- __aad = (u8 *)aead_req + reqsize;
- memcpy(__aad, aad, CCM_AAD_LEN);
+ /* Authentication followed by encryption */ + /* Authentication followed by encryption */
+ for (i = 0; i < blen; i++) + for (i = 0; i < blen; i++)
+ b[i] ^= pos[i]; + b[i] ^= pos[i];
+ crypto_cipher_encrypt_one(tfm, b, b); + crypto_cipher_encrypt_one(tfm, b, b);
+
- sg_init_table(sg, 3);
- sg_set_buf(&sg[0], &__aad[2], be16_to_cpup((__be16 *)__aad));
- sg_set_buf(&sg[1], data, data_len);
- sg_set_buf(&sg[2], mic, mic_len);
+ b_0[14] = (j >> 8) & 0xff; + b_0[14] = (j >> 8) & 0xff;
+ b_0[15] = j & 0xff; + b_0[15] = j & 0xff;
+ crypto_cipher_encrypt_one(tfm, e, b_0); + crypto_cipher_encrypt_one(tfm, e, b_0);
+ for (i = 0; i < blen; i++) + for (i = 0; i < blen; i++)
+ *cpos++ = *pos++ ^ e[i]; + *cpos++ = *pos++ ^ e[i];
+ } + }
+
+ for (i = 0; i < mic_len; i++)
+ mic[i] = b[i] ^ s_0[i];
}
-int ieee80211_aes_ccm_decrypt(struct crypto_aead *tfm, u8 *b_0, u8 *aad,
+int ieee80211_aes_ccm_decrypt(struct crypto_cipher *tfm, u8 *b_0, u8 *aad,
u8 *data, size_t data_len, u8 *mic,
size_t mic_len)
{
- struct scatterlist sg[3];
- struct aead_request *aead_req;
- int reqsize = sizeof(*aead_req) + crypto_aead_reqsize(tfm);
- u8 *__aad;
- int err;
-
- if (data_len == 0)
- return -EINVAL;
-
- aead_req = kzalloc(reqsize + CCM_AAD_LEN, GFP_ATOMIC);
- if (!aead_req)
- return -ENOMEM;
-
- __aad = (u8 *)aead_req + reqsize;
- memcpy(__aad, aad, CCM_AAD_LEN);
-
- sg_init_table(sg, 3);
- sg_set_buf(&sg[0], &__aad[2], be16_to_cpup((__be16 *)__aad));
- sg_set_buf(&sg[1], data, data_len);
- sg_set_buf(&sg[2], mic, mic_len);
-
- aead_request_set_tfm(aead_req, tfm); - aead_request_set_tfm(aead_req, tfm);
- aead_request_set_crypt(aead_req, sg, sg, data_len + mic_len, b_0); - aead_request_set_crypt(aead_req, sg, sg, data_len + mic_len, b_0);
- aead_request_set_ad(aead_req, sg[0].length); - aead_request_set_ad(aead_req, sg[0].length);
+ for (i = 0; i < mic_len; i++)
+ mic[i] = b[i] ^ s_0[i];
+}
- err = crypto_aead_decrypt(aead_req);
- kzfree(aead_req);
+int ieee80211_aes_ccm_decrypt(struct crypto_cipher *tfm, u8 *b_0, u8 *aad,
+ u8 *data, size_t data_len, u8 *mic,
+ size_t mic_len)
+{
+ int i, j, last_len, num_blocks; + int i, j, last_len, num_blocks;
+ u8 *pos, *cpos; + u8 *pos, *cpos;
+ u8 a[AES_BLOCK_SIZE]; + u8 a[AES_BLOCK_SIZE];
+ u8 b[AES_BLOCK_SIZE]; + u8 b[AES_BLOCK_SIZE];
+ u8 s_0[AES_BLOCK_SIZE]; + u8 s_0[AES_BLOCK_SIZE];
+
- return err;
+ num_blocks = DIV_ROUND_UP(data_len, AES_BLOCK_SIZE); + num_blocks = DIV_ROUND_UP(data_len, AES_BLOCK_SIZE);
+ last_len = data_len % AES_BLOCK_SIZE; + last_len = data_len % AES_BLOCK_SIZE;
+ aes_ccm_prepare(tfm, b_0, aad, s_0, a, b); + aes_ccm_prepare(tfm, b_0, aad, s_0, a, b);
@ -181,7 +185,11 @@
+ if ((mic[i] ^ s_0[i]) != a[i]) + if ((mic[i] ^ s_0[i]) != a[i])
+ return -1; + return -1;
+ } + }
+
- err = crypto_aead_decrypt(aead_req);
- kzfree(aead_req);
-
- return err;
+ return 0; + return 0;
} }
@ -194,12 +202,12 @@
{ {
- struct crypto_aead *tfm; - struct crypto_aead *tfm;
- int err; - int err;
- + struct crypto_cipher *tfm;
- tfm = crypto_alloc_aead("ccm(aes)", 0, CRYPTO_ALG_ASYNC); - tfm = crypto_alloc_aead("ccm(aes)", 0, CRYPTO_ALG_ASYNC);
- if (IS_ERR(tfm)) - if (IS_ERR(tfm))
- return tfm; - return tfm;
+ struct crypto_cipher *tfm; -
- err = crypto_aead_setkey(tfm, key, key_len); - err = crypto_aead_setkey(tfm, key, key_len);
- if (err) - if (err)
- goto free_aead; - goto free_aead;

View file

@ -29,6 +29,21 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
- npend = ath9k_hw_numtxpending(ah, i); - npend = ath9k_hw_numtxpending(ah, i);
- if (npend) - if (npend)
- break; - break;
- }
-
- if (ah->external_reset &&
- (npend || type == ATH9K_RESET_COLD)) {
- int reset_err = 0;
-
- ath_dbg(ath9k_hw_common(ah), RESET,
- "reset MAC via external reset\n");
-
- reset_err = ah->external_reset();
- if (reset_err) {
- ath_err(ath9k_hw_common(ah),
- "External reset failed, err=%d\n",
- reset_err);
- return false;
+ if (type == ATH9K_RESET_COLD) + if (type == ATH9K_RESET_COLD)
+ return true; + return true;
+ +
@ -44,47 +59,35 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
+ for (i = 0; i < AR_NUM_QCU; i++) { + for (i = 0; i < AR_NUM_QCU; i++) {
+ if (ath9k_hw_numtxpending(ah, i)) + if (ath9k_hw_numtxpending(ah, i))
+ return true; + return true;
+ } }
} + }
+
- if (ah->external_reset &&
- (npend || type == ATH9K_RESET_COLD)) {
- int reset_err = 0;
+ return false; + return false;
+} +}
+
- ath_dbg(ath9k_hw_common(ah), RESET,
- "reset MAC via external reset\n");
+static bool ath9k_hw_external_reset(struct ath_hw *ah, int type) +static bool ath9k_hw_external_reset(struct ath_hw *ah, int type)
+{ +{
+ int err; + int err;
+
- reset_err = ah->external_reset();
- if (reset_err) {
- ath_err(ath9k_hw_common(ah),
- "External reset failed, err=%d\n",
- reset_err);
- return false;
- }
+ if (!ah->external_reset || !ath9k_hw_need_external_reset(ah, type)) + if (!ah->external_reset || !ath9k_hw_need_external_reset(ah, type))
+ return true; + return true;
+
- REG_WRITE(ah, AR_RTC_RESET, 1);
+ ath_dbg(ath9k_hw_common(ah), RESET, + ath_dbg(ath9k_hw_common(ah), RESET,
+ "reset MAC via external reset\n"); + "reset MAC via external reset\n");
+
- REG_WRITE(ah, AR_RTC_RESET, 1);
+ err = ah->external_reset(); + err = ah->external_reset();
+ if (err) { + if (err) {
+ ath_err(ath9k_hw_common(ah), + ath_err(ath9k_hw_common(ah),
+ "External reset failed, err=%d\n", err); + "External reset failed, err=%d\n", err);
+ return false; + return false;
+ } }
+
+ if (AR_SREV_9550(ah)) { + if (AR_SREV_9550(ah)) {
+ REG_WRITE(ah, AR_RTC_RESET, 0); + REG_WRITE(ah, AR_RTC_RESET, 0);
+ udelay(10); + udelay(10);
} + }
+
+ REG_WRITE(ah, AR_RTC_RESET, 1); + REG_WRITE(ah, AR_RTC_RESET, 1);
+ udelay(10); + udelay(10);
+ +

View file

@ -103,8 +103,7 @@
+ GFP_KERNEL); + GFP_KERNEL);
+ if (!led) + if (!led)
+ return -ENOMEM; + return -ENOMEM;
+
- ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, val);
+ led->gpio = gpio = (struct gpio_led *) (led + 1); + led->gpio = gpio = (struct gpio_led *) (led + 1);
+ _name = (char *) (led->gpio + 1); + _name = (char *) (led->gpio + 1);
+ +
@ -117,7 +116,8 @@
+ ret = ath_add_led(sc, led); + ret = ath_add_led(sc, led);
+ if (unlikely(ret < 0)) + if (unlikely(ret < 0))
+ kfree(led); + kfree(led);
+
- ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, val);
+ return ret; + return ret;
} }
@ -125,11 +125,11 @@
{ {
- if (!sc->led_registered) - if (!sc->led_registered)
- return; - return;
-
- ath_led_brightness(&sc->led_cdev, LED_OFF);
- led_classdev_unregister(&sc->led_cdev);
+ struct ath_led *led; + struct ath_led *led;
- ath_led_brightness(&sc->led_cdev, LED_OFF);
- led_classdev_unregister(&sc->led_cdev);
-
- ath9k_hw_gpio_free(sc->sc_ah, sc->sc_ah->led_pin); - ath9k_hw_gpio_free(sc->sc_ah, sc->sc_ah->led_pin);
+ while (!list_empty(&sc->leds)) { + while (!list_empty(&sc->leds)) {
+ led = list_first_entry(&sc->leds, struct ath_led, list); + led = list_first_entry(&sc->leds, struct ath_led, list);

View file

@ -843,7 +843,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
static void rt2800_init_bbp(struct rt2x00_dev *rt2x00dev) static void rt2800_init_bbp(struct rt2x00_dev *rt2x00dev)
{ {
unsigned int i; unsigned int i;
@@ -6117,7 +6735,10 @@ static void rt2800_init_bbp(struct rt2x0 @@ -6117,7 +6734,10 @@ static void rt2800_init_bbp(struct rt2x0
return; return;
case RT5390: case RT5390:
case RT5392: case RT5392:
@ -855,7 +855,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
break; break;
case RT5592: case RT5592:
rt2800_init_bbp_5592(rt2x00dev); rt2800_init_bbp_5592(rt2x00dev);
@@ -7331,6 +7952,277 @@ static void rt2800_init_rfcsr_5592(struc @@ -7331,6 +7951,277 @@ static void rt2800_init_rfcsr_5592(struc
rt2800_led_open_drain_enable(rt2x00dev); rt2800_led_open_drain_enable(rt2x00dev);
} }
@ -1133,7 +1133,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
static void rt2800_init_rfcsr(struct rt2x00_dev *rt2x00dev) static void rt2800_init_rfcsr(struct rt2x00_dev *rt2x00dev)
{ {
if (rt2800_is_305x_soc(rt2x00dev)) { if (rt2800_is_305x_soc(rt2x00dev)) {
@@ -7366,7 +8258,10 @@ static void rt2800_init_rfcsr(struct rt2 @@ -7366,7 +8257,10 @@ static void rt2800_init_rfcsr(struct rt2
rt2800_init_rfcsr_5350(rt2x00dev); rt2800_init_rfcsr_5350(rt2x00dev);
break; break;
case RT5390: case RT5390:
@ -1145,7 +1145,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
break; break;
case RT5392: case RT5392:
rt2800_init_rfcsr_5392(rt2x00dev); rt2800_init_rfcsr_5392(rt2x00dev);
@@ -7780,6 +8675,7 @@ static int rt2800_init_eeprom(struct rt2 @@ -7780,6 +8674,7 @@ static int rt2800_init_eeprom(struct rt2
case RF5390: case RF5390:
case RF5392: case RF5392:
case RF5592: case RF5592:
@ -1153,7 +1153,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
break; break;
default: default:
rt2x00_err(rt2x00dev, "Invalid RF chipset 0x%04x detected\n", rt2x00_err(rt2x00dev, "Invalid RF chipset 0x%04x detected\n",
@@ -8258,6 +9154,24 @@ static const struct rf_channel rf_vals_5 @@ -8258,6 +9153,24 @@ static const struct rf_channel rf_vals_5
{196, 83, 0, 12, 1}, {196, 83, 0, 12, 1},
}; };
@ -1178,7 +1178,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
static int rt2800_probe_hw_mode(struct rt2x00_dev *rt2x00dev) static int rt2800_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
{ {
struct hw_mode_spec *spec = &rt2x00dev->spec; struct hw_mode_spec *spec = &rt2x00dev->spec;
@@ -8361,6 +9275,11 @@ static int rt2800_probe_hw_mode(struct r @@ -8361,6 +9274,11 @@ static int rt2800_probe_hw_mode(struct r
spec->channels = rf_vals_3x; spec->channels = rf_vals_3x;
break; break;
@ -1190,7 +1190,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
case RF3052: case RF3052:
case RF3053: case RF3053:
spec->num_channels = ARRAY_SIZE(rf_vals_3x); spec->num_channels = ARRAY_SIZE(rf_vals_3x);
@@ -8498,6 +9417,7 @@ static int rt2800_probe_hw_mode(struct r @@ -8498,6 +9416,7 @@ static int rt2800_probe_hw_mode(struct r
case RF5390: case RF5390:
case RF5392: case RF5392:
case RF5592: case RF5592: