41 #include <linux/slab.h>
42 #include <linux/module.h>
50 static void carl9170_dbg_message(
struct ar9170 *
ar,
const char *
buf,
u32 len)
58 if (ar->
fw.err_counter > 3) {
85 if (ar->
ps.state != new_ps) {
93 ar->
ps.state = new_ps;
97 static int carl9170_check_sequence(
struct ar9170 *ar,
unsigned int seq)
117 count = (seq - ar->
cmd_seq) % ar->
fw.cmd_bufs;
119 wiphy_err(ar->
hw->wiphy,
"lost %d command responses/traps! "
120 "w:%d g:%d\n", count, ar->
cmd_seq, seq);
130 static void carl9170_cmd_callback(
struct ar9170 *ar,
u32 len,
void *
buffer)
138 dev_warn(&ar->
udev->dev,
"received invalid command response:"
139 "got %d, instead of %d\n", len - 4, ar->
readlen);
167 if (carl9170_check_sequence(ar, cmd->
hdr.seq))
172 carl9170_cmd_callback(ar, len, buf);
179 wiphy_err(ar->
hw->wiphy,
"FW: received over-/under"
180 "sized event %x (%d, but should be %d).\n",
181 cmd->
hdr.cmd, cmd->
hdr.len, len - 4);
191 switch (cmd->
hdr.cmd) {
195 vif = carl9170_get_main_vif(ar);
204 carl9170_handle_ps(ar, cmd);
248 carl9170_dbg_message(ar, (
char *)buf + 4, len - 4);
254 (
char *)buf + 4, len - 4);
261 wiphy_info(ar->
hw->wiphy,
"FW: RADAR! Please report this "
266 #ifdef CONFIG_CARL9170_WPC
271 if (state != ar->wps.pbc_state) {
272 ar->wps.pbc_state =
state;
275 input_sync(ar->wps.pbc);
286 wiphy_err(ar->
hw->wiphy,
"FW: received unhandled event %x\n",
293 static int carl9170_rx_mac_status(
struct ar9170 *ar,
326 decrypt = ar9170_get_decrypt_type(mac);
340 AR9170_RX_ERROR_FCS |
341 AR9170_RX_ERROR_WRONG_RA |
351 "suspicious error code (%#x).\n", error);
366 switch (head->
plcp[0]) {
382 "rate (%x).\n", head->
plcp[0]);
391 switch (head->
plcp[0] & 0xf) {
419 "rate (%x).\n", head->
plcp[0]);
429 if (head->
plcp[3] & 0x80)
431 if (head->
plcp[6] & 0x80)
446 static void carl9170_rx_phy_status(
struct ar9170 *ar,
453 for (i = 0; i < 3; i++)
454 if (phy->
rssi[i] != 0x80)
458 for (i = 0; i < 7; i++)
459 if (phy->
rssi[i] & 0x80)
460 phy->
rssi[
i] = ((phy->
rssi[
i] & 0x7f) + 1) & 0x7f;
466 static struct sk_buff *carl9170_rx_copy_data(
u8 *buf,
int len)
473 u8 *qc = ieee80211_get_qos_ctl(hdr);
485 skb = dev_alloc_skb(len + reserved);
487 skb_reserve(skb, reserved);
494 static u8 *carl9170_find_ie(
u8 *
data,
unsigned int len,
u8 ie)
499 pos = (
u8 *)mgmt->
u.beacon.variable;
502 if (pos + 2 + pos[1] > end)
522 static void carl9170_ps_beacon(
struct ar9170 *ar,
void *data,
unsigned int len)
542 if (!ether_addr_equal(hdr->
addr3, ar->
common.curbssid) ||
552 if (tim[1] <
sizeof(*tim_ie))
560 ar->
hw->conf.ps_dtim_period;
565 cam = ieee80211_check_tim(tim_ie, tim_len, ar->
common.curaid);
580 static void carl9170_ba_check(
struct ar9170 *ar,
void *data,
unsigned int len)
589 if (len <=
sizeof(*bar) +
FCS_LEN)
597 list_for_each_entry_rcu(entry, &ar->
bar_list[queue],
list) {
602 #define TID_CHECK(a, b) ( \
603 ((a) & cpu_to_le16(IEEE80211_BAR_CTRL_TID_INFO_MASK)) == \
604 ((b) & cpu_to_le16(IEEE80211_BAR_CTRL_TID_INFO_MASK))) \
608 compare_ether_addr(bar->
ra, entry_bar->ta) == 0 &&
609 compare_ether_addr(bar->
ta, entry_bar->ra) == 0) {
612 tx_info = IEEE80211_SKB_CB(entry_skb);
616 list_del_rcu(&entry->
list);
627 static bool carl9170_ampdu_check(
struct ar9170 *ar,
u8 *buf,
u8 ms,
653 if (ieee80211_is_data_qos(fc) && ieee80211_is_data_present(fc))
656 if (ieee80211_is_ack(fc) || ieee80211_is_back(fc) ||
657 ieee80211_is_back_req(fc))
660 if (ieee80211_is_action(fc))
676 static void carl9170_handle_mpdu(
struct ar9170 *ar,
u8 *buf,
int len)
692 memset(&status, 0,
sizeof(status));
694 mpdu_len = len -
sizeof(*mac);
696 mac = (
void *)(buf + mpdu_len);
697 mac_status = mac->status;
698 switch (mac_status & AR9170_RX_STATUS_MPDU) {
740 phy = (
void *)(buf + mpdu_len);
756 wiphy_err(ar->
hw->wiphy,
"rx stream does not start "
757 "with a first_mpdu frame tag.\n");
773 phy = (
void *)(buf + mpdu_len);
785 if (
unlikely(carl9170_rx_mac_status(ar, head, mac, &status)))
788 if (!carl9170_ampdu_check(ar, buf, mac_status, &status))
792 carl9170_rx_phy_status(ar, phy, &status);
794 carl9170_ps_beacon(ar, buf, mpdu_len);
796 carl9170_ba_check(ar, buf, mpdu_len);
798 skb = carl9170_rx_copy_data(buf, mpdu_len);
802 memcpy(IEEE80211_SKB_RXCB(skb), &status,
sizeof(status));
810 static void carl9170_rx_untie_cmds(
struct ar9170 *ar,
const u8 *respbuf,
811 const unsigned int resplen)
816 while (i < resplen) {
817 cmd = (
void *) &respbuf[i];
819 i += cmd->
hdr.len + 4;
830 wiphy_err(ar->
hw->wiphy,
"malformed firmware trap:\n");
836 static void __carl9170_rx(
struct ar9170 *ar,
u8 *buf,
unsigned int len)
841 while (len > 2 && i < 12 && buf[0] == 0xff && buf[1] == 0xff) {
852 carl9170_rx_untie_cmds(ar, buf, len);
854 carl9170_handle_mpdu(ar, buf, len);
857 static void carl9170_rx_stream(
struct ar9170 *ar,
void *buf,
unsigned int len)
859 unsigned int tlen, wlen = 0,
clen = 0;
867 rx_stream = (
void *) tbuf;
887 __carl9170_rx(ar, tbuf, tlen);
895 "stream corruption!\n");
926 if (wlen > tlen - 4) {
931 "stream corruption!\n");
956 wiphy_err(ar->
hw->wiphy,
"%d bytes of unprocessed "
957 "data left in rx stream!\n", tlen);
966 wiphy_err(ar->
hw->wiphy,
"damaged RX stream data [want:%d, "
967 "data:%d, rx:%d, pending:%d ]\n",
clen, wlen, tlen,
978 wiphy_err(ar->
hw->wiphy,
"please check your hardware and cables, if "
979 "you see this message frequently.\n");
991 if (ar->
fw.rx_stream)
992 carl9170_rx_stream(ar, buf, len);
994 __carl9170_rx(ar, buf, len);