|
@@ -11,6 +11,7 @@
|
|
|
* Page-allocated buffers only: the kernel image must stay below 0x90000. */
|
|
* Page-allocated buffers only: the kernel image must stay below 0x90000. */
|
|
|
|
|
|
|
|
#include "wifi.h"
|
|
#include "wifi.h"
|
|
|
|
|
+#include "ccmp.h"
|
|
|
#include "iwl_mvm.h"
|
|
#include "iwl_mvm.h"
|
|
|
#include "iwl_trans.h"
|
|
#include "iwl_trans.h"
|
|
|
#include "io.h"
|
|
#include "io.h"
|
|
@@ -57,7 +58,16 @@ static struct {
|
|
|
unsigned int eapq_head, eapq_tail;
|
|
unsigned int eapq_head, eapq_tail;
|
|
|
unsigned char *txbuf; /* one 2 KB frame build buffer */
|
|
unsigned char *txbuf; /* one 2 KB frame build buffer */
|
|
|
unsigned int rx_frames, tx_frames, rx_dropped;
|
|
unsigned int rx_frames, tx_frames, rx_dropped;
|
|
|
|
|
+ unsigned int rx_logged_grp, rx_logged_uni;
|
|
|
|
|
+ int beacon_log;
|
|
|
|
|
+ unsigned char tk[16], gtk[16]; /* software CCMP RX keys */
|
|
|
|
|
+ int have_tk, have_gtk;
|
|
|
|
|
+ unsigned int gtk_idx;
|
|
|
|
|
+ int sw_rx_log, sw_fail_log;
|
|
|
unsigned int conn_id;
|
|
unsigned int conn_id;
|
|
|
|
|
+ unsigned char ptk[48];
|
|
|
|
|
+ unsigned char ptk_replay[8];
|
|
|
|
|
+ unsigned int ptk_conn;
|
|
|
const char *detail;
|
|
const char *detail;
|
|
|
} W;
|
|
} W;
|
|
|
|
|
|
|
@@ -258,20 +268,66 @@ static void queue_eapol(const unsigned char *p, unsigned int len)
|
|
|
W.eapq_head = (W.eapq_head + 1) % EAPOLQ_SLOTS;
|
|
W.eapq_head = (W.eapq_head + 1) % EAPOLQ_SLOTS;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-/* First few data-path drops go to serial/netmon with the reason and the
|
|
|
|
|
- * firmware RX status (decrypt result in bits 8..10, MIC_OK bit 6). */
|
|
|
|
|
-static void rx_drop(const char *why, const unsigned char *f,
|
|
|
|
|
|
|
+static void puthex2(unsigned int v)
|
|
|
|
|
+{
|
|
|
|
|
+ static const char hx[] = "0123456789abcdef";
|
|
|
|
|
+
|
|
|
|
|
+ serial_putc(SERIAL_COM1, hx[(v >> 4) & 15]);
|
|
|
|
|
+ serial_putc(SERIAL_COM1, hx[v & 15]);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+static void putmac(const unsigned char *m)
|
|
|
|
|
+{
|
|
|
|
|
+ unsigned int i;
|
|
|
|
|
+
|
|
|
|
|
+ for (i = 0; i < 6; i++) {
|
|
|
|
|
+ if (i)
|
|
|
|
|
+ serial_putc(SERIAL_COM1, ':');
|
|
|
|
|
+ puthex2(m[i]);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/* First few data-path drops of each kind (group and unicast) go to
|
|
|
|
|
+ * serial/netmon with the reason, address, CCMP key ID and the firmware RX
|
|
|
|
|
+ * status (decrypt result in bits 8..10, MIC_OK bit 6, replay bit 7,
|
|
|
|
|
+ * DEC_DONE bit 11). */
|
|
|
|
|
+static void rx_drop(const char *why, const unsigned char *f, unsigned int len,
|
|
|
unsigned int status)
|
|
unsigned int status)
|
|
|
{
|
|
{
|
|
|
|
|
+ unsigned int hdr = 24 + (((f[0] >> 4) & 0xf) & 8 ? 2 : 0);
|
|
|
|
|
+ int grp = f[4] & 1;
|
|
|
|
|
+
|
|
|
W.rx_dropped++;
|
|
W.rx_dropped++;
|
|
|
- if (W.rx_dropped > 12)
|
|
|
|
|
- return;
|
|
|
|
|
|
|
+ if (grp) {
|
|
|
|
|
+ if (W.rx_logged_grp++ >= 8)
|
|
|
|
|
+ return;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if (W.rx_logged_uni++ >= 8)
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
serial_puts(SERIAL_COM1, "wifi: rx drop ");
|
|
serial_puts(SERIAL_COM1, "wifi: rx drop ");
|
|
|
serial_puts(SERIAL_COM1, why);
|
|
serial_puts(SERIAL_COM1, why);
|
|
|
serial_puts(SERIAL_COM1, " fc ");
|
|
serial_puts(SERIAL_COM1, " fc ");
|
|
|
serial_puthex(SERIAL_COM1, f[0] | (f[1] << 8));
|
|
serial_puthex(SERIAL_COM1, f[0] | (f[1] << 8));
|
|
|
- serial_puts(SERIAL_COM1, " da ");
|
|
|
|
|
- serial_puthex(SERIAL_COM1, (f[4] << 8) | f[5]);
|
|
|
|
|
|
|
+ serial_puts(SERIAL_COM1, " len ");
|
|
|
|
|
+ serial_putdec(SERIAL_COM1, len);
|
|
|
|
|
+ serial_puts(SERIAL_COM1, " a1 ");
|
|
|
|
|
+ putmac(f + 4);
|
|
|
|
|
+ serial_puts(SERIAL_COM1, " a2 ");
|
|
|
|
|
+ putmac(f + 10);
|
|
|
|
|
+ serial_puts(SERIAL_COM1, " ccmp ");
|
|
|
|
|
+ serial_putdec(SERIAL_COM1, len >= hdr + 8 ? (f[hdr + 3] >> 6) & 3
|
|
|
|
|
+ : 0xff);
|
|
|
|
|
+ serial_puts(SERIAL_COM1, " sec ");
|
|
|
|
|
+ serial_putdec(SERIAL_COM1, (status >> 8) & 7);
|
|
|
|
|
+ serial_puts(SERIAL_COM1, " kv ");
|
|
|
|
|
+ serial_putdec(SERIAL_COM1, (status >> 3) & 1);
|
|
|
|
|
+ serial_puts(SERIAL_COM1, " mic ");
|
|
|
|
|
+ serial_putdec(SERIAL_COM1, (status >> 6) & 1);
|
|
|
|
|
+ serial_puts(SERIAL_COM1, " dec ");
|
|
|
|
|
+ serial_putdec(SERIAL_COM1, (status >> 11) & 1);
|
|
|
|
|
+ serial_puts(SERIAL_COM1, " rep ");
|
|
|
|
|
+ serial_putdec(SERIAL_COM1, (status >> 7) & 1);
|
|
|
serial_puts(SERIAL_COM1, " status ");
|
|
serial_puts(SERIAL_COM1, " status ");
|
|
|
serial_puthex(SERIAL_COM1, status);
|
|
serial_puthex(SERIAL_COM1, status);
|
|
|
serial_puts(SERIAL_COM1, "\n");
|
|
serial_puts(SERIAL_COM1, "\n");
|
|
@@ -295,10 +351,63 @@ static void rx_data(const unsigned char *f, unsigned int len,
|
|
|
if (stype & 8)
|
|
if (stype & 8)
|
|
|
hdr += 2; /* QoS control */
|
|
hdr += 2; /* QoS control */
|
|
|
if (prot) {
|
|
if (prot) {
|
|
|
- if ((status & IWL_RX_SEC_MSK) != IWL_RX_SEC_CCM ||
|
|
|
|
|
- !(status & IWL_RX_MIC_OK)) {
|
|
|
|
|
- rx_drop("not decrypted", f, status);
|
|
|
|
|
- return;
|
|
|
|
|
|
|
+ unsigned int kid = (f[hdr + 3] >> 6) & 3;
|
|
|
|
|
+ const unsigned char *key = 0;
|
|
|
|
|
+ int fw_ok = (status & IWL_RX_SEC_MSK) == IWL_RX_SEC_CCM &&
|
|
|
|
|
+ (status & IWL_RX_MIC_OK);
|
|
|
|
|
+
|
|
|
|
|
+ /* The firmware sometimes does the AES-CTR step in place but
|
|
|
|
|
+ * still reports a failed MIC/decrypt status. The SNAP header
|
|
|
|
|
+ * in the clear is a reliable sign that the payload is already
|
|
|
|
|
+ * plaintext. */
|
|
|
|
|
+ if (!fw_ok && len >= hdr + 16 &&
|
|
|
|
|
+ meq(f + hdr + 8, snap, 6)) {
|
|
|
|
|
+ if (W.sw_rx_log < 4) {
|
|
|
|
|
+ W.sw_rx_log++;
|
|
|
|
|
+ serial_puts(SERIAL_COM1,
|
|
|
|
|
+ "wifi: fw plaintext id ");
|
|
|
|
|
+ serial_putdec(SERIAL_COM1, kid);
|
|
|
|
|
+ serial_puts(SERIAL_COM1, "\n");
|
|
|
|
|
+ }
|
|
|
|
|
+ fw_ok = 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!fw_ok) {
|
|
|
|
|
+ /* The firmware's RX crypto path sometimes reports
|
|
|
|
|
+ * SEC_ENC_ERR for keys it has installed. Decrypt in
|
|
|
|
|
+ * software with the same TK/GTK; TX proves they are
|
|
|
|
|
+ * correct. */
|
|
|
|
|
+ if (f[4] & 1) {
|
|
|
|
|
+ if (W.have_gtk && kid == W.gtk_idx)
|
|
|
|
|
+ key = W.gtk;
|
|
|
|
|
+ } else if (kid == 0 && W.have_tk) {
|
|
|
|
|
+ key = W.tk;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!key) {
|
|
|
|
|
+ rx_drop("no key", f, len, status);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (ccmp_rx_decrypt((unsigned char *)f, len, hdr,
|
|
|
|
|
+ key) < 0) {
|
|
|
|
|
+ if (W.sw_fail_log < 3 && len >= hdr + 16) {
|
|
|
|
|
+ unsigned int z;
|
|
|
|
|
+
|
|
|
|
|
+ W.sw_fail_log++;
|
|
|
|
|
+ serial_puts(SERIAL_COM1,
|
|
|
|
|
+ "wifi: sw ccmp failed payload ");
|
|
|
|
|
+ for (z = 0; z < 8; z++)
|
|
|
|
|
+ puthex2(f[hdr + 8 + z]);
|
|
|
|
|
+ serial_puts(SERIAL_COM1, "\n");
|
|
|
|
|
+ }
|
|
|
|
|
+ rx_drop("sw ccmp failed", f, len, status);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (W.sw_rx_log < 4) {
|
|
|
|
|
+ W.sw_rx_log++;
|
|
|
|
|
+ serial_puts(SERIAL_COM1,
|
|
|
|
|
+ "wifi: sw ccmp ok id ");
|
|
|
|
|
+ serial_putdec(SERIAL_COM1, kid);
|
|
|
|
|
+ serial_puts(SERIAL_COM1, "\n");
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
hdr += 8; /* CCMP header */
|
|
hdr += 8; /* CCMP header */
|
|
|
if (len < hdr + 8)
|
|
if (len < hdr + 8)
|
|
@@ -306,7 +415,7 @@ static void rx_data(const unsigned char *f, unsigned int len,
|
|
|
len -= 8; /* MIC */
|
|
len -= 8; /* MIC */
|
|
|
}
|
|
}
|
|
|
if (len < hdr + 8 || !meq(f + hdr, snap, 6)) {
|
|
if (len < hdr + 8 || !meq(f + hdr, snap, 6)) {
|
|
|
- rx_drop("no LLC/SNAP", f, status);
|
|
|
|
|
|
|
+ rx_drop("no LLC/SNAP", f, len, status);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
type = (f[hdr + 6] << 8) | f[hdr + 7];
|
|
type = (f[hdr + 6] << 8) | f[hdr + 7];
|
|
@@ -319,12 +428,13 @@ static void rx_data(const unsigned char *f, unsigned int len,
|
|
|
/* Before the keys are in, or unprotected after: drop. */
|
|
/* Before the keys are in, or unprotected after: drop. */
|
|
|
if (W.state != SYS_WIFI_ST_LINK || (W.protect && !prot)) {
|
|
if (W.state != SYS_WIFI_ST_LINK || (W.protect && !prot)) {
|
|
|
rx_drop(W.state != SYS_WIFI_ST_LINK ? "port closed"
|
|
rx_drop(W.state != SYS_WIFI_ST_LINK ? "port closed"
|
|
|
- : "unprotected", f, status);
|
|
|
|
|
|
|
+ : "unprotected", f, len,
|
|
|
|
|
+ status);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
if (plen + 14 > RXQ_FRAME ||
|
|
if (plen + 14 > RXQ_FRAME ||
|
|
|
((W.rxq_head + 1) % RXQ_SLOTS) == W.rxq_tail) {
|
|
((W.rxq_head + 1) % RXQ_SLOTS) == W.rxq_tail) {
|
|
|
- rx_drop("queue full", f, status);
|
|
|
|
|
|
|
+ rx_drop("queue full", f, len, status);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
s = &W.rxq[W.rxq_head];
|
|
s = &W.rxq[W.rxq_head];
|
|
@@ -341,11 +451,23 @@ static void rx_data(const unsigned char *f, unsigned int len,
|
|
|
void wifi_rx_frame(const unsigned char *frame, unsigned int len, int rssi,
|
|
void wifi_rx_frame(const unsigned char *frame, unsigned int len, int rssi,
|
|
|
unsigned int status, unsigned int channel)
|
|
unsigned int status, unsigned int channel)
|
|
|
{
|
|
{
|
|
|
- unsigned int type;
|
|
|
|
|
|
|
+ unsigned int type, stype;
|
|
|
|
|
|
|
|
if (len < 24)
|
|
if (len < 24)
|
|
|
return;
|
|
return;
|
|
|
type = (frame[0] >> 2) & 3;
|
|
type = (frame[0] >> 2) & 3;
|
|
|
|
|
+ stype = (frame[0] >> 4) & 0xf;
|
|
|
|
|
+ if (W.state >= SYS_WIFI_ST_ASSOC && type == 0 && stype == 8 &&
|
|
|
|
|
+ W.beacon_log < 3) {
|
|
|
|
|
+ W.beacon_log++;
|
|
|
|
|
+ serial_puts(SERIAL_COM1, "wifi: beacon status ");
|
|
|
|
|
+ serial_puthex(SERIAL_COM1, status);
|
|
|
|
|
+ serial_puts(SERIAL_COM1, " srcfound ");
|
|
|
|
|
+ serial_putdec(SERIAL_COM1, (status >> 2) & 1);
|
|
|
|
|
+ serial_puts(SERIAL_COM1, " staid ");
|
|
|
|
|
+ serial_putdec(SERIAL_COM1, (status >> 24) & 0x1f);
|
|
|
|
|
+ serial_puts(SERIAL_COM1, "\n");
|
|
|
|
|
+ }
|
|
|
if (type == 0)
|
|
if (type == 0)
|
|
|
rx_mgmt(frame, len, rssi, channel);
|
|
rx_mgmt(frame, len, rssi, channel);
|
|
|
else if (type == 2)
|
|
else if (type == 2)
|
|
@@ -460,6 +582,11 @@ static int do_connect(const struct sys_wifi_connect *c)
|
|
|
W.eapq_head = W.eapq_tail = 0;
|
|
W.eapq_head = W.eapq_tail = 0;
|
|
|
W.rxq_head = W.rxq_tail = 0;
|
|
W.rxq_head = W.rxq_tail = 0;
|
|
|
W.rx_dropped = 0;
|
|
W.rx_dropped = 0;
|
|
|
|
|
+ W.rx_logged_grp = W.rx_logged_uni = 0;
|
|
|
|
|
+ W.beacon_log = 0;
|
|
|
|
|
+ W.have_tk = W.have_gtk = 0;
|
|
|
|
|
+ W.sw_rx_log = W.sw_fail_log = 0;
|
|
|
|
|
+ W.ptk_conn = 0;
|
|
|
|
|
|
|
|
if (iwl_mvm_prepare_connect(c->bssid, c->channel, W.cur.beacon_int) < 0) {
|
|
if (iwl_mvm_prepare_connect(c->bssid, c->channel, W.cur.beacon_int) < 0) {
|
|
|
W.detail = "firmware connect setup failed";
|
|
W.detail = "firmware connect setup failed";
|
|
@@ -538,6 +665,8 @@ static void do_disconnect(void)
|
|
|
{
|
|
{
|
|
|
static const unsigned char reason[2] = { 3, 0 }; /* leaving */
|
|
static const unsigned char reason[2] = { 3, 0 }; /* leaving */
|
|
|
|
|
|
|
|
|
|
+ W.have_tk = W.have_gtk = 0;
|
|
|
|
|
+ W.ptk_conn = 0;
|
|
|
if (W.state >= SYS_WIFI_ST_ASSOC) {
|
|
if (W.state >= SYS_WIFI_ST_ASSOC) {
|
|
|
tx_mgmt_frame(12, reason, 2);
|
|
tx_mgmt_frame(12, reason, 2);
|
|
|
iwl_mvm_poll();
|
|
iwl_mvm_poll();
|
|
@@ -806,12 +935,47 @@ int sys_wifi(int op, int a2, int a3)
|
|
|
}
|
|
}
|
|
|
case SYS_WIFI_SET_KEY: {
|
|
case SYS_WIFI_SET_KEY: {
|
|
|
struct sys_wifi_key k;
|
|
struct sys_wifi_key k;
|
|
|
|
|
+ int r;
|
|
|
|
|
|
|
|
if (W.state < SYS_WIFI_ST_ASSOC || !user_ok(a2, sizeof(k), 0))
|
|
if (W.state < SYS_WIFI_ST_ASSOC || !user_ok(a2, sizeof(k), 0))
|
|
|
return -1;
|
|
return -1;
|
|
|
wmemcpy(&k, (const void *)a2, sizeof(k));
|
|
wmemcpy(&k, (const void *)a2, sizeof(k));
|
|
|
- return iwl_mvm_set_key(k.pairwise, k.keyidx, k.key,
|
|
|
|
|
- k.pairwise ? 0 : k.rsc);
|
|
|
|
|
|
|
+ r = iwl_mvm_set_key(k.pairwise, k.keyidx, k.key,
|
|
|
|
|
+ k.pairwise ? 0 : k.rsc);
|
|
|
|
|
+ if (r == 0) {
|
|
|
|
|
+ if (k.pairwise) {
|
|
|
|
|
+ wmemcpy(W.tk, k.key, 16);
|
|
|
|
|
+ W.have_tk = 1;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ wmemcpy(W.gtk, k.key, 16);
|
|
|
|
|
+ W.gtk_idx = k.keyidx & 3;
|
|
|
|
|
+ W.have_gtk = 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return r;
|
|
|
|
|
+ }
|
|
|
|
|
+ case SYS_WIFI_SET_PTK: {
|
|
|
|
|
+ struct sys_wifi_ptk p;
|
|
|
|
|
+
|
|
|
|
|
+ if (W.state < SYS_WIFI_ST_ASSOC || !user_ok(a2, sizeof(p), 0))
|
|
|
|
|
+ return -1;
|
|
|
|
|
+ wmemcpy(&p, (const void *)a2, sizeof(p));
|
|
|
|
|
+ wmemcpy(W.ptk, p.ptk, 48);
|
|
|
|
|
+ wmemcpy(W.ptk_replay, p.replay, 8);
|
|
|
|
|
+ W.ptk_conn = p.conn_id;
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ case SYS_WIFI_GET_PTK: {
|
|
|
|
|
+ struct sys_wifi_ptk p;
|
|
|
|
|
+
|
|
|
|
|
+ if (!W.ptk_conn || (unsigned int)a3 != W.ptk_conn ||
|
|
|
|
|
+ !user_ok(a2, sizeof(p), 1))
|
|
|
|
|
+ return -1;
|
|
|
|
|
+ p.conn_id = W.ptk_conn;
|
|
|
|
|
+ wmemcpy(p.ptk, W.ptk, 48);
|
|
|
|
|
+ wmemcpy(p.replay, W.ptk_replay, 8);
|
|
|
|
|
+ wmemcpy((void *)a2, &p, sizeof(p));
|
|
|
|
|
+ return 0;
|
|
|
}
|
|
}
|
|
|
case SYS_WIFI_AUTHORIZE:
|
|
case SYS_WIFI_AUTHORIZE:
|
|
|
if (W.state < SYS_WIFI_ST_ASSOC)
|
|
if (W.state < SYS_WIFI_ST_ASSOC)
|