linux/drivers/staging/rtl8188eu/hal/rtl8188e_rxdesc.c
<<
>>
Prefs
   1/******************************************************************************
   2 *
   3 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
   4 *
   5 * This program is free software; you can redistribute it and/or modify it
   6 * under the terms of version 2 of the GNU General Public License as
   7 * published by the Free Software Foundation.
   8 *
   9 * This program is distributed in the hope that it will be useful, but WITHOUT
  10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12 * more details.
  13 *
  14 ******************************************************************************/
  15#define _RTL8188E_REDESC_C_
  16
  17#include <osdep_service.h>
  18#include <drv_types.h>
  19#include <rtl8188e_hal.h>
  20
  21static void process_rssi(struct adapter *padapter, struct recv_frame *prframe)
  22{
  23        struct rx_pkt_attrib *pattrib = &prframe->attrib;
  24        struct signal_stat *signal_stat = &padapter->recvpriv.signal_strength_data;
  25
  26        if (signal_stat->update_req) {
  27                signal_stat->total_num = 0;
  28                signal_stat->total_val = 0;
  29                signal_stat->update_req = 0;
  30        }
  31
  32        signal_stat->total_num++;
  33        signal_stat->total_val  += pattrib->phy_info.SignalStrength;
  34        signal_stat->avg_val = signal_stat->total_val / signal_stat->total_num;
  35} /*  Process_UI_RSSI_8192C */
  36
  37static void process_link_qual(struct adapter *padapter,
  38                              struct recv_frame *prframe)
  39{
  40        struct rx_pkt_attrib *pattrib;
  41        struct signal_stat *signal_stat;
  42
  43        if (!prframe || !padapter)
  44                return;
  45
  46        pattrib = &prframe->attrib;
  47        signal_stat = &padapter->recvpriv.signal_qual_data;
  48
  49        if (signal_stat->update_req) {
  50                signal_stat->total_num = 0;
  51                signal_stat->total_val = 0;
  52                signal_stat->update_req = 0;
  53        }
  54
  55        signal_stat->total_num++;
  56        signal_stat->total_val  += pattrib->phy_info.SignalQuality;
  57        signal_stat->avg_val = signal_stat->total_val / signal_stat->total_num;
  58}
  59
  60void rtl8188e_process_phy_info(struct adapter *padapter,
  61                               struct recv_frame *precvframe)
  62{
  63        /*  Check RSSI */
  64        process_rssi(padapter, precvframe);
  65        /*  Check EVM */
  66        process_link_qual(padapter,  precvframe);
  67}
  68
  69void update_recvframe_attrib_88e(struct recv_frame *precvframe,
  70                                 struct recv_stat *prxstat)
  71{
  72        struct rx_pkt_attrib    *pattrib;
  73        struct recv_stat        report;
  74
  75        report.rxdw0 = prxstat->rxdw0;
  76        report.rxdw1 = prxstat->rxdw1;
  77        report.rxdw2 = prxstat->rxdw2;
  78        report.rxdw3 = prxstat->rxdw3;
  79        report.rxdw4 = prxstat->rxdw4;
  80        report.rxdw5 = prxstat->rxdw5;
  81
  82        pattrib = &precvframe->attrib;
  83        memset(pattrib, 0, sizeof(struct rx_pkt_attrib));
  84
  85        pattrib->crc_err = (u8)((le32_to_cpu(report.rxdw0) >> 14) & 0x1);/* u8)prxreport->crc32; */
  86
  87        /*  update rx report to recv_frame attribute */
  88        pattrib->pkt_rpt_type = (u8)((le32_to_cpu(report.rxdw3) >> 14) & 0x3);/* prxreport->rpt_sel; */
  89
  90        if (pattrib->pkt_rpt_type == NORMAL_RX) { /* Normal rx packet */
  91                pattrib->pkt_len = (u16)(le32_to_cpu(report.rxdw0) & 0x00003fff);/* u16)prxreport->pktlen; */
  92                pattrib->drvinfo_sz = (u8)((le32_to_cpu(report.rxdw0) >> 16) & 0xf) * 8;/* u8)(prxreport->drvinfosize << 3); */
  93
  94                pattrib->physt =  (u8)((le32_to_cpu(report.rxdw0) >> 26) & 0x1);/* u8)prxreport->physt; */
  95
  96                pattrib->bdecrypted = (le32_to_cpu(report.rxdw0) & BIT(27)) ? 0 : 1;/* u8)(prxreport->swdec ? 0 : 1); */
  97                pattrib->encrypt = (u8)((le32_to_cpu(report.rxdw0) >> 20) & 0x7);/* u8)prxreport->security; */
  98
  99                pattrib->qos = (u8)((le32_to_cpu(report.rxdw0) >> 23) & 0x1);/* u8)prxreport->qos; */
 100                pattrib->priority = (u8)((le32_to_cpu(report.rxdw1) >> 8) & 0xf);/* u8)prxreport->tid; */
 101
 102                pattrib->amsdu = (u8)((le32_to_cpu(report.rxdw1) >> 13) & 0x1);/* u8)prxreport->amsdu; */
 103
 104                pattrib->seq_num = (u16)(le32_to_cpu(report.rxdw2) & 0x00000fff);/* u16)prxreport->seq; */
 105                pattrib->frag_num = (u8)((le32_to_cpu(report.rxdw2) >> 12) & 0xf);/* u8)prxreport->frag; */
 106                pattrib->mfrag = (u8)((le32_to_cpu(report.rxdw1) >> 27) & 0x1);/* u8)prxreport->mf; */
 107                pattrib->mdata = (u8)((le32_to_cpu(report.rxdw1) >> 26) & 0x1);/* u8)prxreport->md; */
 108
 109                pattrib->mcs_rate = (u8)(le32_to_cpu(report.rxdw3) & 0x3f);/* u8)prxreport->rxmcs; */
 110                pattrib->rxht = (u8)((le32_to_cpu(report.rxdw3) >> 6) & 0x1);/* u8)prxreport->rxht; */
 111
 112                pattrib->icv_err = (u8)((le32_to_cpu(report.rxdw0) >> 15) & 0x1);/* u8)prxreport->icverr; */
 113                pattrib->shift_sz = (u8)((le32_to_cpu(report.rxdw0) >> 24) & 0x3);
 114        } else if (pattrib->pkt_rpt_type == TX_REPORT1) { /* CCX */
 115                pattrib->pkt_len = TX_RPT1_PKT_LEN;
 116                pattrib->drvinfo_sz = 0;
 117        } else if (pattrib->pkt_rpt_type == TX_REPORT2) { /*  TX RPT */
 118                pattrib->pkt_len = (u16)(le32_to_cpu(report.rxdw0) & 0x3FF);/* Rx length[9:0] */
 119                pattrib->drvinfo_sz = 0;
 120
 121                /*  */
 122                /*  Get TX report MAC ID valid. */
 123                /*  */
 124                pattrib->MacIDValidEntry[0] = le32_to_cpu(report.rxdw4);
 125                pattrib->MacIDValidEntry[1] = le32_to_cpu(report.rxdw5);
 126
 127        } else if (pattrib->pkt_rpt_type == HIS_REPORT) { /*  USB HISR RPT */
 128                pattrib->pkt_len = (u16)(le32_to_cpu(report.rxdw0) & 0x00003fff);/* u16)prxreport->pktlen; */
 129        }
 130}
 131
 132/*
 133 * Notice:
 134 *      Before calling this function,
 135 *      precvframe->rx_data should be ready!
 136 */
 137void update_recvframe_phyinfo_88e(struct recv_frame *precvframe,
 138                                  struct phy_stat *pphy_status)
 139{
 140        struct adapter *padapter = precvframe->adapter;
 141        struct rx_pkt_attrib *pattrib = &precvframe->attrib;
 142        struct odm_phy_status_info *pPHYInfo  = (struct odm_phy_status_info *)(&pattrib->phy_info);
 143        u8 *wlanhdr;
 144        struct odm_per_pkt_info pkt_info;
 145        u8 *sa = NULL;
 146        struct sta_priv *pstapriv;
 147        struct sta_info *psta;
 148
 149        pkt_info.bPacketMatchBSSID = false;
 150        pkt_info.bPacketToSelf = false;
 151        pkt_info.bPacketBeacon = false;
 152
 153        wlanhdr = precvframe->pkt->data;
 154
 155        pkt_info.bPacketMatchBSSID = ((!IsFrameTypeCtrl(wlanhdr)) &&
 156                !pattrib->icv_err && !pattrib->crc_err &&
 157                !memcmp(get_hdr_bssid(wlanhdr),
 158                 get_bssid(&padapter->mlmepriv), ETH_ALEN));
 159
 160        pkt_info.bPacketToSelf = pkt_info.bPacketMatchBSSID &&
 161                                 (!memcmp(get_da(wlanhdr),
 162                                  myid(&padapter->eeprompriv), ETH_ALEN));
 163
 164        pkt_info.bPacketBeacon = pkt_info.bPacketMatchBSSID &&
 165                                 (GetFrameSubType(wlanhdr) == WIFI_BEACON);
 166
 167        if (pkt_info.bPacketBeacon) {
 168                if (check_fwstate(&padapter->mlmepriv, WIFI_STATION_STATE))
 169                        sa = padapter->mlmepriv.cur_network.network.MacAddress;
 170                /* to do Ad-hoc */
 171        } else {
 172                sa = get_sa(wlanhdr);
 173        }
 174
 175        pstapriv = &padapter->stapriv;
 176        pkt_info.StationID = 0xFF;
 177        psta = rtw_get_stainfo(pstapriv, sa);
 178        if (psta)
 179                pkt_info.StationID = psta->mac_id;
 180        pkt_info.Rate = pattrib->mcs_rate;
 181
 182        ODM_PhyStatusQuery(&padapter->HalData->odmpriv, pPHYInfo,
 183                           (u8 *)pphy_status, &(pkt_info));
 184
 185        precvframe->psta = NULL;
 186        if (pkt_info.bPacketMatchBSSID &&
 187            (check_fwstate(&padapter->mlmepriv, WIFI_AP_STATE))) {
 188                if (psta) {
 189                        precvframe->psta = psta;
 190                        rtl8188e_process_phy_info(padapter, precvframe);
 191                }
 192        } else if (pkt_info.bPacketToSelf || pkt_info.bPacketBeacon) {
 193                if (check_fwstate(&padapter->mlmepriv, WIFI_ADHOC_STATE|WIFI_ADHOC_MASTER_STATE)) {
 194                        if (psta)
 195                                precvframe->psta = psta;
 196                }
 197                rtl8188e_process_phy_info(padapter, precvframe);
 198        }
 199}
 200