📄 rtusb_info.c
字号:
/*************************************************************************** * RT2x00 SourceForge Project - http://rt2x00.sourceforge.net * * * * 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: rtusb_info.c * * Abstract: * * Revision History: * Who When What * -------- ---------- ------------------------- * Name Date Modification logs * Jan Lee 2005-06-01 Release * RobinC 02-06-2005 RFMON Mode added * RobinC 02-06-2005 Fix frequency reporting * MarkW 13-07-2005 Fix ESSID reporting *************************************************************************/#include "rt_config.h"#include <net/iw_handler.h>#define NR_WEP_KEYS 4#define WEP_SMALL_KEY_LEN (40/8)#define WEP_LARGE_KEY_LEN (104/8)#define MAP_CHANNEL_ID_TO_KHZ(ch, khz) { \ switch (ch) \ { \ case 1: khz = 2412000; break; \ case 2: khz = 2417000; break; \ case 3: khz = 2422000; break; \ case 4: khz = 2427000; break; \ case 5: khz = 2432000; break; \ case 6: khz = 2437000; break; \ case 7: khz = 2442000; break; \ case 8: khz = 2447000; break; \ case 9: khz = 2452000; break; \ case 10: khz = 2457000; break; \ case 11: khz = 2462000; break; \ case 12: khz = 2467000; break; \ case 13: khz = 2472000; break; \ case 14: khz = 2484000; break; \ case 36: /* UNII */ khz = 5180000; break; \ case 40: /* UNII */ khz = 5200000; break; \ case 44: /* UNII */ khz = 5220000; break; \ case 48: /* UNII */ khz = 5240000; break; \ case 52: /* UNII */ khz = 5260000; break; \ case 56: /* UNII */ khz = 5280000; break; \ case 60: /* UNII */ khz = 5300000; break; \ case 64: /* UNII */ khz = 5320000; break; \ case 149: /* UNII */ khz = 5745000; break; \ case 153: /* UNII */ khz = 5765000; break; \ case 157: /* UNII */ khz = 5785000; break; \ case 161: /* UNII */ khz = 5805000; break; \ case 100: /* HiperLAN2 */ khz = 5500000; break; \ case 104: /* HiperLAN2 */ khz = 5520000; break; \ case 108: /* HiperLAN2 */ khz = 5540000; break; \ case 112: /* HiperLAN2 */ khz = 5560000; break; \ case 116: /* HiperLAN2 */ khz = 5580000; break; \ case 120: /* HiperLAN2 */ khz = 5600000; break; \ case 124: /* HiperLAN2 */ khz = 5620000; break; \ case 128: /* HiperLAN2 */ khz = 5640000; break; \ case 132: /* HiperLAN2 */ khz = 5660000; break; \ case 136: /* HiperLAN2 */ khz = 5680000; break; \ case 140: /* HiperLAN2 */ khz = 5700000; break; \ case 34: /* Japan MMAC */ khz = 5170000; break; \ case 38: /* Japan MMAC */ khz = 5190000; break; \ case 42: /* Japan MMAC */ khz = 5210000; break; \ case 46: /* Japan MMAC */ khz = 5230000; break; \ default: khz = 2412000; break; \ } \ }#define MAP_KHZ_TO_CHANNEL_ID(khz, ch) { \ switch (khz) \ { \ case 2412000: ch = 1; break; \ case 2417000: ch = 2; break; \ case 2422000: ch = 3; break; \ case 2427000: ch = 4; break; \ case 2432000: ch = 5; break; \ case 2437000: ch = 6; break; \ case 2442000: ch = 7; break; \ case 2447000: ch = 8; break; \ case 2452000: ch = 9; break; \ case 2457000: ch = 10; break; \ case 2462000: ch = 11; break; \ case 2467000: ch = 12; break; \ case 2472000: ch = 13; break; \ case 2484000: ch = 14; break; \ case 5180000: ch = 36; /* UNII */ break; \ case 5200000: ch = 40; /* UNII */ break; \ case 5220000: ch = 44; /* UNII */ break; \ case 5240000: ch = 48; /* UNII */ break; \ case 5260000: ch = 52; /* UNII */ break; \ case 5280000: ch = 56; /* UNII */ break; \ case 5300000: ch = 60; /* UNII */ break; \ case 5320000: ch = 64; /* UNII */ break; \ case 5745000: ch = 149; /* UNII */ break; \ case 5765000: ch = 153; /* UNII */ break; \ case 5785000: ch = 157; /* UNII */ break; \ case 5805000: ch = 161; /* UNII */ break; \ case 5500000: ch = 100; /* HiperLAN2 */ break; \ case 5520000: ch = 104; /* HiperLAN2 */ break; \ case 5540000: ch = 108; /* HiperLAN2 */ break; \ case 5560000: ch = 112; /* HiperLAN2 */ break; \ case 5580000: ch = 116; /* HiperLAN2 */ break; \ case 5600000: ch = 120; /* HiperLAN2 */ break; \ case 5620000: ch = 124; /* HiperLAN2 */ break; \ case 5640000: ch = 128; /* HiperLAN2 */ break; \ case 5660000: ch = 132; /* HiperLAN2 */ break; \ case 5680000: ch = 136; /* HiperLAN2 */ break; \ case 5700000: ch = 140; /* HiperLAN2 */ break; \ case 5170000: ch = 34; /* Japan MMAC */ break; \ case 5190000: ch = 38; /* Japan MMAC */ break; \ case 5210000: ch = 42; /* Japan MMAC */ break; \ case 5230000: ch = 46; /* Japan MMAC */ break; \ default: ch = 1; break; \ } \ }#if 0static struct { char *name; int (*set_proc)(PRT2570ADAPTER pAdapter, PUCHAR arg);} *PRTMP_PRIVATE_SET_PROC, RTMP_PRIVATE_SUPPORT_PROC[] = { {"CountryRegion", Set_CountryRegion_Proc }, {"SSID", Set_SSID_Proc}, {"WirelessMode", Set_WirelessMode_Proc}, {"TxRate", Set_TxRate_Proc}, {"Channel", Set_Channel_Proc}, {"BGProtection", Set_BGProtection_Proc}, {"TxPreamble", Set_TxPreamble_Proc}, {"RTSThreshold", Set_RTSThreshold_Proc}, {"FragThreshold", Set_FragThreshold_Proc}, {"TxBurst", Set_TxBurst_Proc}, {"TurboRate", Set_TurboRate_Proc}, {"AuthMode", Set_AuthMode_Proc}, {"EncrypType", Set_EncrypType_Proc}, {"DefaultKeyID", Set_DefaultKeyID_Proc}, {"Key1", Set_Key1_Proc}, {"Key2", Set_Key2_Proc}, {"Key3", Set_Key3_Proc}, {"Key4", Set_Key4_Proc}, {"WPAPSK", Set_WPAPSK_Proc}, {"bb", Set_R17_Proc}, {"rr", Read_R17_Proc}, {NULL,}};#endifintrtusb_ioctl_giwname(struct net_device *dev, struct iw_request_info *info, char *name, char *extra){ strncpy(name, "RT2500USB WLAN", IFNAMSIZ); return 0;}int rtusb_ioctl_siwfreq(struct net_device *dev, struct iw_request_info *info, struct iw_freq *freq, char *extra){ PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv; int chan = -1; if (freq->e > 1) return -EINVAL; if((freq->e == 0) && (freq->m <= 1000)) chan = freq->m; // Setting by channel number else MAP_KHZ_TO_CHANNEL_ID( (freq->m /100) , chan); // Setting by frequency - search the table , like 2.412G, 2.422G, pAdapter->PortCfg.IbssConfig.Channel = chan; DBGPRINT(RT_DEBUG_ERROR, "<==SIOCSIWFREQ[cmd=0x%x] (Channel=%d)\n", SIOCSIWFREQ, pAdapter->PortCfg.IbssConfig.Channel); // CD: setting the channel in Monitor mode is unrelated to RFMONTx if (pAdapter->PortCfg.BssType == BSS_MONITOR) { pAdapter->PortCfg.Channel = pAdapter->PortCfg.IbssConfig.Channel; AsicSwitchChannel(pAdapter, pAdapter->PortCfg.Channel); AsicLockChannel(pAdapter, pAdapter->PortCfg.Channel); } return 0;}int rtusb_ioctl_giwfreq(struct net_device *dev, struct iw_request_info *info, struct iw_freq *freq, char *extra){ PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv; DBGPRINT(RT_DEBUG_TRACE,"==>IOCTL::rtusb_ioctl_giwfreq %d\n",pAdapter->PortCfg.Channel); if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter)) { MAP_CHANNEL_ID_TO_KHZ(pAdapter->PortCfg.Channel, freq->m); } else { MAP_CHANNEL_ID_TO_KHZ(pAdapter->PortCfg.IbssConfig.Channel, freq->m ); } freq->e = 3; freq->i = 0; return 0;}int rtusb_ioctl_siwmode(struct net_device *dev, struct iw_request_info *info, __u32 *mode, char *extra){ PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv; switch (*mode) { case IW_MODE_ADHOC: if (pAdapter->PortCfg.BssType != BSS_INDEP) { // Config has changed if INFRA_ON(pAdapter) { RTUSBEnqueueInternalCmd(pAdapter, RT_OID_LINK_DOWN); // First cancel linkdown timer DBGPRINT(RT_DEBUG_TRACE, "NDIS_STATUS_MEDIA_DISCONNECT Event BB!\n"); } pAdapter->bConfigChanged = TRUE; } pAdapter->net->type = 1; pAdapter->PortCfg.BssType = BSS_INDEP; DBGPRINT(RT_DEBUG_TRACE, "ioctl::SIOCSIWMODE (AD-HOC)\n"); break; case IW_MODE_INFRA: if (pAdapter->PortCfg.BssType != BSS_INFRA) { // Config has changed if (pAdapter->PortCfg.BssType != BSS_INFRA) { // Config has changed // pAdapter->bConfigChanged = TRUE; if ADHOC_ON(pAdapter) RTUSBEnqueueInternalCmd(pAdapter, RT_OID_LINK_DOWN); } pAdapter->bConfigChanged = TRUE; } pAdapter->net->type = 1; pAdapter->PortCfg.BssType = BSS_INFRA; DBGPRINT(RT_DEBUG_TRACE, "ioctl::SIOCSIWMODE (INFRA)\n"); break; case IW_MODE_MONITOR: pAdapter->PortCfg.BssType=BSS_MONITOR; RTUSBEnqueueInternalCmd(pAdapter, RT_OID_LINK_DOWN); pAdapter->bConfigChanged = TRUE; if (pAdapter->PortCfg.MallowRFMONTx == TRUE) { if (pAdapter->PortCfg.ForcePrismHeader == 1) pAdapter->net->type = 802; // ARPHRD_IEEE80211_PRISM else pAdapter->net->type = 801; // ARPHRD_IEEE80211 } else { if (pAdapter->PortCfg.ForcePrismHeader == 2) pAdapter->net->type = 801; // ARPHRD_IEEE80211 else pAdapter->net->type = 802; // ARPHRD_IEEE80211_PRISM } RTUSBWriteMACRegister(pAdapter, TXRX_CSR2, 0x4e); break; default: DBGPRINT(RT_DEBUG_TRACE, "ioctl::SIOCSIWMODE (unknown)\n"); return -EINVAL; } // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key pAdapter->PortCfg.WpaState = SS_NOTUSE; return 0;}int rtusb_ioctl_giwmode(struct net_device *dev, struct iw_request_info *info, __u32 *mode, char *extra){ PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv; if (pAdapter->PortCfg.BssType == BSS_MONITOR) *mode = IW_MODE_MONITOR; else { if (ADHOC_ON(pAdapter)) *mode = IW_MODE_ADHOC; else *mode = IW_MODE_INFRA; } DBGPRINT(RT_DEBUG_TEMP,"--->rtusb_ioctl_giwmode\n"); return 0;}int rtusb_ioctl_siwsens(struct net_device *dev, struct iw_request_info *info, char *name, char *extra){ return 0;}int rtusb_ioctl_giwsens(struct net_device *dev, struct iw_request_info *info, char *name, char *extra){ return 0;}/*This is required for LinEX2004/kernel2.6.7 to provide iwlist scanning function*/int rtusb_ioctl_giwrange(struct net_device *dev, struct iw_request_info *info, struct iw_point *data, char *extra){ PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv; struct iw_range *range = (struct iw_range *) extra; u16 val; int i; ULONG m; data->length = sizeof(struct iw_range); memset(range, 0, sizeof(struct iw_range)); range->txpower_capa = IW_TXPOW_DBM; if (INFRA_ON(pAdapter)||ADHOC_ON(pAdapter)) { range->min_pmp = 1 * 1024; range->max_pmp = 65535 * 1024; range->min_pmt = 1 * 1024; range->max_pmt = 1000 * 1024; range->pmp_flags = IW_POWER_PERIOD; range->pmt_flags = IW_POWER_TIMEOUT; range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_UNICAST_R | IW_POWER_ALL_R; } range->we_version_compiled = WIRELESS_EXT; range->we_version_source = 16; range->retry_capa = IW_RETRY_LIMIT; range->retry_flags = IW_RETRY_LIMIT; range->min_retry = 0; range->max_retry = 255; range->num_channels = pAdapter->PortCfg.ChannelListNum; val = 0; for (i = 0; i < pAdapter->PortCfg.SupportedRatesLen; i++) { range->freq[val].i =(pAdapter->PortCfg.SupportedRates[i] & 0x7f)/2; range->freq[val].m = (pAdapter->PortCfg.SupportedRates[i] & 0x7f)/2 * 100000; range->freq[val].e = 1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -