📄 rtmp_main.c
字号:
/*************************************************************************** * RT2x00 SourceForge Project - http://rt2x00.serialmonkey.com * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * * * Licensed under the GNU GPL * * Original code supplied under license from RaLink Inc, 2004. * ***************************************************************************//*************************************************************************** * Module Name: rtmp_main.c * * Abstract: Main initialization routines * * Revision History: * Who When What * -------- ---------- ----------------------------- * Jan Lee 01-10-2005 modified * idamlaj 04-10-2006 Apply patch by Ace17 (from forum) * ***************************************************************************/#include "rt_config.h"ULONG RTDebugLevel = RT_DEBUG_OFF;static ULONG debug = RT_DEBUG_OFF;static char *ifname = NULL;static char *firmName = RT2573_IMAGE_FILE_NAME;#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)MODULE_PARM(debug, "i");MODULE_PARM(ifname, "s");MODULE_PARM(firmName, "s");#elsemodule_param(debug, int, 0);module_param(ifname, charp, 0444);module_param(firmName, charp, S_IRUGO );#endifMODULE_PARM_DESC(debug, "Debug mask: n selects filter, 0 for none");MODULE_PARM_DESC(ifname, "Network device name (default wlan%d)");MODULE_PARM_DESC(firmName, "Permit to load a different firmware: (default: rt73.bin) ");// Following information will be show when you run 'modinfo'MODULE_AUTHOR("http://rt2x00.serialmonkey.com");MODULE_DESCRIPTION("Ralink RT73 802.11abg WLAN Driver " DRIVER_VERSION " " DRIVER_RELDATE);// *** open source releaseMODULE_LICENSE("GPL");/* Kernel thread and vars, which handles packets that are completed. Only * packets that have a "complete" function are sent here. This way, the * completion is run out of kernel context, and doesn't block the rest of * the stack. */extern const struct iw_handler_def rt73_iw_handler_def;/* module table */struct usb_device_id rtusb_usb_id[] = RT73_USB_DEVICES;INT const rtusb_usb_id_len = sizeof(rtusb_usb_id) / sizeof(struct usb_device_id);MODULE_DEVICE_TABLE(usb, rtusb_usb_id);#ifndef PF_NOFREEZE#define PF_NOFREEZE 0#endif/**************************************************************************//**************************************************************************///tested for kernel 2.4 series/**************************************************************************//**************************************************************************/#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)static void usb_rtusb_disconnect(struct usb_device *dev, void *ptr);static void *usb_rtusb_probe(struct usb_device *dev, UINT interface, const struct usb_device_id *id_table);struct usb_driver rtusb_driver = { name:"rt73", probe:usb_rtusb_probe, disconnect:usb_rtusb_disconnect, id_table:rtusb_usb_id, };#else/**************************************************************************//**************************************************************************///tested for kernel 2.6series/**************************************************************************//**************************************************************************/static int usb_rtusb_probe (struct usb_interface *intf, const struct usb_device_id *id);static void usb_rtusb_disconnect(struct usb_interface *intf);static int rt73_suspend(struct usb_interface *intf, pm_message_t state);static int rt73_resume(struct usb_interface *intf);struct usb_driver rtusb_driver = {#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15) .owner = THIS_MODULE,#endif .name="rt73", .probe=usb_rtusb_probe, .disconnect=usb_rtusb_disconnect, .id_table=rtusb_usb_id,#ifdef CONFIG_PM .suspend = rt73_suspend, .resume = rt73_resume,#endif };#endifstruct net_device_stats *rt73_get_ether_stats( IN struct net_device *net_dev){ PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) net_dev->priv; DBGPRINT(RT_DEBUG_INFO, "rt73_get_ether_stats --->\n"); pAd->stats.rx_packets = pAd->WlanCounters.ReceivedFragmentCount.vv.LowPart; // total packets received pAd->stats.tx_packets = pAd->WlanCounters.TransmittedFragmentCount.vv.LowPart; // total packets transmitted pAd->stats.rx_bytes= pAd->RalinkCounters.ReceivedByteCount; // total bytes received pAd->stats.tx_bytes = pAd->RalinkCounters.TransmittedByteCount; // total bytes transmitted pAd->stats.rx_errors = pAd->Counters8023.RxErrors; // bad packets received pAd->stats.tx_errors = pAd->Counters8023.TxErrors; // packet transmit problems pAd->stats.rx_dropped = pAd->Counters8023.RxNoBuffer; // no space in linux buffers pAd->stats.tx_dropped = pAd->WlanCounters.FailedCount.vv.LowPart; // no space available in linux pAd->stats.multicast = pAd->WlanCounters.MulticastReceivedFrameCount.vv.LowPart; // multicast packets received pAd->stats.collisions = pAd->Counters8023.OneCollision + pAd->Counters8023.MoreCollisions; // Collision packets pAd->stats.rx_length_errors = 0; pAd->stats.rx_over_errors = pAd->Counters8023.RxNoBuffer; // receiver ring buff overflow pAd->stats.rx_crc_errors = 0;//pAd->WlanCounters.FCSErrorCount; // recved pkt with crc error pAd->stats.rx_frame_errors = pAd->Counters8023.RcvAlignmentErrors; // recv'd frame alignment error pAd->stats.rx_fifo_errors = pAd->Counters8023.RxNoBuffer; // recv'r fifo overrun pAd->stats.rx_missed_errors = 0; // receiver missed packet // detailed tx_errors pAd->stats.tx_aborted_errors = 0; pAd->stats.tx_carrier_errors = 0; pAd->stats.tx_fifo_errors = 0; pAd->stats.tx_heartbeat_errors = 0; pAd->stats.tx_window_errors = 0; // for cslip etc pAd->stats.rx_compressed = 0; pAd->stats.tx_compressed = 0; return &pAd->stats;}#if WIRELESS_EXT >= 12/* ======================================================================== Routine Description: get wireless statistics Arguments: net_dev Pointer to net_device Return Value: struct iw_statistics Note: This function will be called when query /proc ========================================================================*/long rt_abs(long arg) { return (arg<0)? -arg : arg;}struct iw_statistics *rt73_get_wireless_stats( IN struct net_device *net_dev){ PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) net_dev->priv; DBGPRINT(RT_DEBUG_TRACE, "rt73_get_wireless_stats --->\n"); // TODO: All elements are zero before be implemented pAd->iw_stats.status = 0; // Status - device dependent for now pAd->iw_stats.qual.qual = pAd->Mlme.ChannelQuality; // link quality (%retries, SNR, %missed beacons or better...)#ifdef RTMP_EMBEDDED pAd->iw_stats.qual.level = rt_abs(pAd->PortCfg.LastRssi); // signal level (dBm)#else pAd->iw_stats.qual.level = abs(pAd->PortCfg.LastRssi); // signal level (dBm)#endif pAd->iw_stats.qual.level += 256 - pAd->BbpRssiToDbmDelta; pAd->iw_stats.qual.noise = (pAd->BbpWriteLatch[17] > pAd->BbpTuning.R17UpperBoundG) ? pAd->BbpTuning.R17UpperBoundG : ((ULONG) pAd->BbpWriteLatch[17]); // noise level (dBm) pAd->iw_stats.qual.noise += 256 - 143; pAd->iw_stats.qual.updated = 1; // Flags to know if updated pAd->iw_stats.discard.nwid = 0; // Rx : Wrong nwid/essid pAd->iw_stats.miss.beacon = 0; // Missed beacons/superframe // pAd->iw_stats.discard.code, discard.fragment, discard.retries, discard.misc has counted in other place return &pAd->iw_stats;}#endif// must be called with usb dev semaphore held - bbstatic void disassocSTA(PRTMP_ADAPTER pAd){ if (INFRA_ON(pAd) || ADHOC_ON(pAd)) { // Set to immediately send the media disconnect event MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, OID_802_11_DISASSOCIATE, 0, NULL); MlmeHandler(pAd); }} /* End disassocSTA () */VOID RTUSBHalt( IN PRTMP_ADAPTER pAd, IN BOOLEAN IsFree){ INT i; DBGPRINT(RT_DEBUG_TRACE, "--> RTUSBHalt\n"); // // before set flag fRTMP_ADAPTER_HALT_IN_PROGRESS, // we should send a disassoc frame to our AP. // if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) { disassocSTA(pAd); // // Patch to fully turn off BBP, need to send a fake NULL frame. // RTUSBWriteMACRegister(pAd, MAC_CSR10, 0x0018); for (i=0; i<10; i++) { RTMPSendNullFrame(pAd, RATE_6); RTMPusecDelay(1000); } // disable BEACON generation and other BEACON related hardware timers AsicDisableSync(pAd); RTMPSetLED(pAd, LED_HALT); } RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS); // Free MLME stuff MlmeHalt(pAd); // Sleep 50 milliseconds so pending io might finish normally RTMPusecDelay(50000); RTMP_CLEAR_FLAGS(pAd); OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_INFRA_ON|fOP_STATUS_ADHOC_ON); DBGPRINT(RT_DEBUG_TRACE, "<-- RTUSBHalt\n");}VOID CMDHandler( IN PRTMP_ADAPTER pAd){ PCmdQElmt cmdqelmt; PUCHAR pData; NDIS_STATUS NdisStatus = NDIS_STATUS_SUCCESS; unsigned long flags; ULONG Now; while (pAd->CmdQ.size > 0) { NdisStatus = NDIS_STATUS_SUCCESS; NdisAcquireSpinLock(&pAd->CmdQLock); RTUSBDequeueCmd(&pAd->CmdQ, &cmdqelmt); NdisReleaseSpinLock(&pAd->CmdQLock); DBGPRINT(RT_DEBUG_INFO, "- %s: Cmd = %04x\n", __FUNCTION__, cmdqelmt == NULL? 0xdeadbeef: cmdqelmt->command); if (cmdqelmt == NULL) break; pData = cmdqelmt->buffer; switch (cmdqelmt->command) { case RT_OID_CHECK_GPIO: { ULONG data; DBGPRINT(RT_DEBUG_TRACE, "- (%s)::RT_OID_CHECK_GPIO\n", __FUNCTION__); // Read GPIO pin7 as Hardware controlled radio state RTUSBReadMACRegister(pAd, MAC_CSR13, &data); if (data & 0x80) { pAd->PortCfg.bHwRadio = TRUE; } else { pAd->PortCfg.bHwRadio = FALSE; } if (pAd->PortCfg.bRadio != (pAd->PortCfg.bHwRadio && pAd->PortCfg.bSwRadio)) { pAd->PortCfg.bRadio = (pAd->PortCfg.bHwRadio && pAd->PortCfg.bSwRadio); if (pAd->PortCfg.bRadio == TRUE) { MlmeRadioOn(pAd); // Update extra information pAd->ExtraInfo = EXTRA_INFO_CLEAR; } else { disassocSTA(pAd); MlmeRadioOff(pAd); // Update extra information pAd->ExtraInfo = HW_RADIO_OFF; } } } break; case RT_OID_PERIODIC_EXECUT: MlmePeriodicExec(pAd); break; case OID_802_11_BSSID_LIST_SCAN: { if (pAd->Mlme.CntlMachine.CurrState != CNTL_IDLE) { MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, RT_CMD_RESET_MLME, 0, NULL); } Now = jiffies; pAd->MlmeAux.CurrReqIsFromNdis = FALSE; // Reset Missed scan number pAd->PortCfg.ScanCnt = 0; pAd->PortCfg.LastScanTime = Now; MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, OID_802_11_BSSID_LIST_SCAN, 0, NULL); RTUSBMlmeUp(pAd); } break; case RT_OID_802_11_BSSID: { if (pAd->Mlme.CntlMachine.CurrState != CNTL_IDLE) { MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, RT_CMD_RESET_MLME, 0, NULL); } pAd->MlmeAux.CurrReqIsFromNdis = FALSE; // Reset allowed scan retries pAd->PortCfg.ScanCnt = 0; MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, OID_802_11_BSSID, cmdqelmt->bufferlength, cmdqelmt->buffer); RTUSBMlmeUp(pAd); } break; case OID_802_11_SSID: { if (pAd->Mlme.CntlMachine.CurrState != CNTL_IDLE) { MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, RT_CMD_RESET_MLME, 0, NULL); } pAd->MlmeAux.CurrReqIsFromNdis = FALSE; // Reset allowed scan retries pAd->PortCfg.ScanCnt = 0; pAd->bConfigChanged = TRUE; MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, OID_802_11_SSID, cmdqelmt->bufferlength, pData); RTUSBMlmeUp(pAd); } break; case OID_802_11_DISASSOCIATE: { if (pAd->Mlme.CntlMachine.CurrState != CNTL_IDLE) { MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, RT_CMD_RESET_MLME, 0, NULL); } // Set to immediately send the media disconnect event pAd->MlmeAux.CurrReqIsFromNdis = TRUE; MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, OID_802_11_DISASSOCIATE, 0, NULL); RTUSBMlmeUp(pAd); } break; case OID_802_11_RX_ANTENNA_SELECTED: { NDIS_802_11_ANTENNA Antenna = *(NDIS_802_11_ANTENNA *)pData; if (Antenna == 0) pAd->Antenna.field.RxDefaultAntenna = 1; // ant-A
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -