linux/drivers/staging/vt6655/dpc.c
<<
>>
Prefs
   1/*
   2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
   3 * All rights reserved.
   4 *
   5 * This program is free software; you can redistribute it and/or modify
   6 * it under the terms of the GNU General Public License as published by
   7 * the Free Software Foundation; either version 2 of the License, or
   8 * (at your option) any later version.
   9 *
  10 * This program is distributed in the hope that it will be useful,
  11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13 * GNU General Public License for more details.
  14 *
  15 * File: dpc.c
  16 *
  17 * Purpose: handle dpc rx functions
  18 *
  19 * Author: Lyndon Chen
  20 *
  21 * Date: May 20, 2003
  22 *
  23 * Functions:
  24 *
  25 * Revision History:
  26 *
  27 */
  28
  29#include "device.h"
  30#include "baseband.h"
  31#include "rf.h"
  32#include "dpc.h"
  33
  34static bool vnt_rx_data(struct vnt_private *priv, struct sk_buff *skb,
  35                        u16 bytes_received)
  36{
  37        struct ieee80211_hw *hw = priv->hw;
  38        struct ieee80211_supported_band *sband;
  39        struct ieee80211_rx_status rx_status = { 0 };
  40        struct ieee80211_hdr *hdr;
  41        __le16 fc;
  42        u8 *rsr, *new_rsr, *rssi;
  43        __le64 *tsf_time;
  44        u16 frame_size;
  45        int ii, r;
  46        u8 *rx_sts, *rx_rate, *sq;
  47        u8 *skb_data;
  48        u8 rate_idx = 0;
  49        u8 rate[MAX_RATE] = {2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108};
  50        long rx_dbm;
  51
  52        /* [31:16]RcvByteCount ( not include 4-byte Status ) */
  53        frame_size = le16_to_cpu(*((__le16 *)(skb->data + 2)));
  54        if (frame_size > 2346 || frame_size < 14) {
  55                dev_dbg(&priv->pcid->dev, "------- WRONG Length 1\n");
  56                return false;
  57        }
  58
  59        skb_data = (u8 *)skb->data;
  60
  61        rx_sts = skb_data;
  62        rx_rate = skb_data + 1;
  63
  64        sband = hw->wiphy->bands[hw->conf.chandef.chan->band];
  65
  66        for (r = RATE_1M; r < MAX_RATE; r++) {
  67                if (*rx_rate == rate[r])
  68                        break;
  69        }
  70
  71        priv->rx_rate = r;
  72
  73        for (ii = 0; ii < sband->n_bitrates; ii++) {
  74                if (sband->bitrates[ii].hw_value == r) {
  75                        rate_idx = ii;
  76                                break;
  77                }
  78        }
  79
  80        if (ii == sband->n_bitrates) {
  81                dev_dbg(&priv->pcid->dev, "Wrong RxRate %x\n", *rx_rate);
  82                return false;
  83        }
  84
  85        tsf_time = (__le64 *)(skb_data + bytes_received - 12);
  86        sq = skb_data + bytes_received - 4;
  87        new_rsr = skb_data + bytes_received - 3;
  88        rssi = skb_data + bytes_received - 2;
  89        rsr = skb_data + bytes_received - 1;
  90        if (*rsr & (RSR_IVLDTYP | RSR_IVLDLEN))
  91                return false;
  92
  93        RFvRSSITodBm(priv, *rssi, &rx_dbm);
  94
  95        priv->byBBPreEDRSSI = (u8)rx_dbm + 1;
  96        priv->uCurrRSSI = *rssi;
  97
  98        skb_pull(skb, 4);
  99        skb_trim(skb, frame_size);
 100
 101        rx_status.mactime = le64_to_cpu(*tsf_time);
 102        rx_status.band = hw->conf.chandef.chan->band;
 103        rx_status.signal = rx_dbm;
 104        rx_status.flag = 0;
 105        rx_status.freq = hw->conf.chandef.chan->center_freq;
 106
 107        if (!(*rsr & RSR_CRCOK))
 108                rx_status.flag |= RX_FLAG_FAILED_FCS_CRC;
 109
 110        hdr = (struct ieee80211_hdr *)(skb->data);
 111        fc = hdr->frame_control;
 112
 113        rx_status.rate_idx = rate_idx;
 114
 115        if (ieee80211_has_protected(fc)) {
 116                if (priv->byLocalID > REV_ID_VT3253_A1)
 117                        rx_status.flag |= RX_FLAG_DECRYPTED;
 118
 119                /* Drop packet */
 120                if (!(*new_rsr & NEWRSR_DECRYPTOK))
 121                        return false;
 122        }
 123
 124        memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status));
 125
 126        ieee80211_rx_irqsafe(priv->hw, skb);
 127
 128        return true;
 129}
 130
 131bool vnt_receive_frame(struct vnt_private *priv, struct vnt_rx_desc *curr_rd)
 132{
 133        struct vnt_rd_info *rd_info = curr_rd->rd_info;
 134        struct sk_buff *skb;
 135        u16 frame_size;
 136
 137        skb = rd_info->skb;
 138
 139        dma_unmap_single(&priv->pcid->dev, rd_info->skb_dma,
 140                         priv->rx_buf_sz, DMA_FROM_DEVICE);
 141
 142        frame_size = le16_to_cpu(curr_rd->rd1.req_count)
 143                        - le16_to_cpu(curr_rd->rd0.res_count);
 144
 145        if ((frame_size > 2364) || (frame_size < 33)) {
 146                /* Frame Size error drop this packet.*/
 147                dev_dbg(&priv->pcid->dev, "Wrong frame size %d\n", frame_size);
 148                dev_kfree_skb_irq(skb);
 149                return true;
 150        }
 151
 152        if (vnt_rx_data(priv, skb, frame_size))
 153                return true;
 154
 155        dev_kfree_skb_irq(skb);
 156
 157        return true;
 158}
 159