iwinfo: add support for mt798x vendor driver

This commit is contained in:
hanwckf 2023-11-28 12:48:23 +08:00
parent 87a1eb4821
commit 95c3efbca9
7 changed files with 2078 additions and 1 deletions

View File

@ -80,7 +80,7 @@ MAKE_FLAGS += \
FPIC="$(FPIC)" \
CFLAGS="$(TARGET_CFLAGS)" \
LDFLAGS="$(TARGET_LDFLAGS)" \
BACKENDS="nl80211" \
BACKENDS="nl80211 mtk" \
SOVERSION="$(IWINFO_ABI_VERSION)"
define Build/InstallDev

View File

@ -0,0 +1,32 @@
Index: libiwinfo-2023-05-17-c9f5c3f7/api/wext.h
===================================================================
--- libiwinfo-2023-05-17-c9f5c3f7.orig/api/wext.h
+++ libiwinfo-2023-05-17-c9f5c3f7/api/wext.h
@@ -677,7 +677,7 @@
*/
struct iw_param
{
- int32_t value; /* The value of the parameter itself */
+ uint64_t value; /* The value of the parameter itself */
uint8_t fixed; /* Hardware should not use auto select */
uint8_t disabled; /* Disable the feature */
uint16_t flags; /* Various specifc flags (if any) */
@@ -988,6 +988,9 @@ struct iw_range
uint16_t old_num_channels;
uint8_t old_num_frequency;
+ /* Scan capabilities */
+ uint8_t scan_capa; /* IW_SCAN_CAPA_* bit field */
+
/* Wireless event capability bitmasks */
uint32_t event_capa[6];
@@ -1013,7 +1016,7 @@ struct iw_range
/* Rates */
uint8_t num_bitrates; /* Number of entries in the list */
- int32_t bitrate[IW_MAX_BITRATES]; /* list, in bps */
+ uint64_t bitrate[IW_MAX_BITRATES]; /* list, in bps */
/* RTS threshold */
int32_t min_rts; /* Minimal RTS threshold */

View File

@ -0,0 +1,195 @@
--- a/Makefile
+++ b/Makefile
@@ -32,6 +32,11 @@ ifneq ($(filter madwifi,$(IWINFO_BACKEND
IWINFO_LIB_OBJ += iwinfo_madwifi.o
endif
+ifneq ($(filter mtk,$(IWINFO_BACKENDS)),)
+ IWINFO_CFLAGS += -DUSE_MTK
+ IWINFO_LIB_OBJ += iwinfo_mtk.o iwinfo_mtk_rate.o
+endif
+
ifneq ($(filter nl80211,$(IWINFO_BACKENDS)),)
IWINFO_CFLAGS += -DUSE_NL80211
IWINFO_CLI_LDFLAGS += -lnl-tiny
--- a/include/iwinfo.h
+++ b/include/iwinfo.h
@@ -313,6 +313,7 @@ extern const struct iwinfo_ops wext_ops;
extern const struct iwinfo_ops madwifi_ops;
extern const struct iwinfo_ops nl80211_ops;
extern const struct iwinfo_ops wl_ops;
+extern const struct iwinfo_ops mtk_ops;
#include "iwinfo/utils.h"
--- a/iwinfo_lib.c
+++ b/iwinfo_lib.c
@@ -347,6 +347,9 @@ static const struct iwinfo_ops *backends
#ifdef USE_WEXT
&wext_ops,
#endif
+#ifdef USE_MTK
+ &mtk_ops,
+#endif
};
const char * iwinfo_type(const char *ifname)
--- a/include/iwinfo/lua.h
+++ b/include/iwinfo/lua.h
@@ -41,6 +41,9 @@
#define IWINFO_NL80211_META "iwinfo.nl80211"
#endif
+#ifdef USE_MTK
+#define IWINFO_MTK_META "iwinfo.mtk"
+#endif
#define LUA_REG(type,op) \
{ #op, iwinfo_L_##type##_##op }
--- a/iwinfo_lua.c
+++ b/iwinfo_lua.c
@@ -775,6 +775,35 @@ LUA_WRAP_STRUCT_OP(nl80211,mbssid_suppor
LUA_WRAP_STRUCT_OP(nl80211,hardware_id)
#endif
+#ifdef USE_MTK
+LUA_WRAP_INT_OP(mtk,channel)
+LUA_WRAP_INT_OP(mtk,frequency)
+LUA_WRAP_INT_OP(mtk,frequency_offset)
+LUA_WRAP_INT_OP(mtk,txpower)
+LUA_WRAP_INT_OP(mtk,txpower_offset)
+LUA_WRAP_INT_OP(mtk,bitrate)
+LUA_WRAP_INT_OP(mtk,signal)
+LUA_WRAP_INT_OP(mtk,noise)
+LUA_WRAP_INT_OP(mtk,quality)
+LUA_WRAP_INT_OP(mtk,quality_max)
+LUA_WRAP_STRING_OP(mtk,ssid)
+LUA_WRAP_STRING_OP(mtk,bssid)
+LUA_WRAP_STRING_OP(mtk,country)
+LUA_WRAP_STRING_OP(mtk,hardware_name)
+LUA_WRAP_STRING_OP(mtk,phyname)
+LUA_WRAP_STRUCT_OP(mtk,mode)
+LUA_WRAP_STRUCT_OP(mtk,assoclist)
+LUA_WRAP_STRUCT_OP(mtk,txpwrlist)
+LUA_WRAP_STRUCT_OP(mtk,scanlist)
+LUA_WRAP_STRUCT_OP(mtk,freqlist)
+LUA_WRAP_STRUCT_OP(mtk,countrylist)
+LUA_WRAP_STRUCT_OP(mtk,hwmodelist)
+LUA_WRAP_STRUCT_OP(mtk,htmodelist)
+LUA_WRAP_STRUCT_OP(mtk,encryption)
+LUA_WRAP_STRUCT_OP(mtk,mbssid_support)
+LUA_WRAP_STRUCT_OP(mtk,hardware_id)
+#endif
+
/* Wext */
#ifdef USE_WEXT
LUA_WRAP_INT_OP(wext,channel)
@@ -904,6 +933,38 @@ static const luaL_reg R_nl80211[] = {
};
#endif
+#ifdef USE_MTK
+static const luaL_reg R_mtk[] = {
+ LUA_REG(mtk,channel),
+ LUA_REG(mtk,frequency),
+ LUA_REG(mtk,frequency_offset),
+ LUA_REG(mtk,txpower),
+ LUA_REG(mtk,txpower_offset),
+ LUA_REG(mtk,bitrate),
+ LUA_REG(mtk,signal),
+ LUA_REG(mtk,noise),
+ LUA_REG(mtk,quality),
+ LUA_REG(mtk,quality_max),
+ LUA_REG(mtk,mode),
+ LUA_REG(mtk,ssid),
+ LUA_REG(mtk,bssid),
+ LUA_REG(mtk,country),
+ LUA_REG(mtk,assoclist),
+ LUA_REG(mtk,txpwrlist),
+ LUA_REG(mtk,scanlist),
+ LUA_REG(mtk,freqlist),
+ LUA_REG(mtk,countrylist),
+ LUA_REG(mtk,hwmodelist),
+ LUA_REG(mtk,htmodelist),
+ LUA_REG(mtk,encryption),
+ LUA_REG(mtk,mbssid_support),
+ LUA_REG(mtk,hardware_id),
+ LUA_REG(mtk,hardware_name),
+ LUA_REG(mtk,phyname),
+ { NULL, NULL }
+};
+#endif
+
/* Wext table */
#ifdef USE_WEXT
static const luaL_reg R_wext[] = {
@@ -975,6 +1036,15 @@ LUALIB_API int luaopen_iwinfo(lua_State
lua_setfield(L, -2, "nl80211");
#endif
+#ifdef USE_MTK
+ luaL_newmetatable(L, IWINFO_MTK_META);
+ luaL_register(L, NULL, R_common);
+ luaL_register(L, NULL, R_mtk);
+ lua_pushvalue(L, -1);
+ lua_setfield(L, -2, "__index");
+ lua_setfield(L, -2, "mtk");
+#endif
+
#ifdef USE_WEXT
luaL_newmetatable(L, IWINFO_WEXT_META);
luaL_register(L, NULL, R_common);
--- a/devices.txt
+++ b/devices.txt
@@ -197,6 +197,7 @@
0x14c3 0x7662 0x14c3 0x7662 0 0 "MediaTek" "MT76x2E"
0x14c3 0x7915 0x14c3 0x7915 0 0 "MediaTek" "MT7915E"
0x14c3 0x7986 0x14c3 0x7986 0 0 "MediaTek" "MT7986"
+0x14c3 0x7981 0x14c3 0x7981 0 0 "MediaTek" "MT7981"
0x14e4 0xaa52 0x14e4 0xaa52 0 0 "Broadcom" "BCM43602"
0x02d0 0xa9a6 0x0000 0x0000 0 0 "Cypress" "CYW43455"
0x1ae9 0x0310 0x1ae9 0x0000 0 0 "Wilocity" "Wil6210"
--- a/iwinfo_utils.c
+++ b/iwinfo_utils.c
@@ -176,6 +176,7 @@ int iwinfo_hardware_id_from_mtd(struct i
{
FILE *mtd;
uint16_t *bc;
+ uint16_t ident;
int fd, off;
unsigned int len;
@@ -188,7 +189,7 @@ int iwinfo_hardware_id_from_mtd(struct i
{
if (fscanf(mtd, "mtd%d: %x %*x %127s", &off, &len, buf) < 3 ||
(strcmp(buf, "\"boardconfig\"") && strcmp(buf, "\"EEPROM\"") &&
- strcmp(buf, "\"factory\"")))
+ strcmp(buf, "\"factory\"") && strcmp(buf, "\"Factory\"")))
{
off = -1;
continue;
@@ -207,6 +208,24 @@ int iwinfo_hardware_id_from_mtd(struct i
if ((fd = open(buf, O_RDONLY)) < 0)
return -1;
+ if (read(fd, &ident, sizeof(ident)) != -1)
+ {
+ if (ident == 0x7981 || ident == 0x7986
+ || ident == 0x8179 || ident == 0x8679)
+ {
+ if ((ident & 0xff) == 0x79)
+ id->device_id = (ident >> 8) | (ident & 0x00ff) << 8;
+ else
+ id->device_id = ident;
+ id->vendor_id = 0x14c3;
+ id->subsystem_vendor_id = 0x14c3;
+ id->subsystem_device_id = id->device_id;
+ close(fd);
+ return 0;
+ }
+ }
+ lseek(fd, 0, SEEK_SET);
+
bc = mmap(NULL, len, PROT_READ, MAP_PRIVATE|MAP_LOCKED, fd, 0);
if ((void *)bc != MAP_FAILED)

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,103 @@
static const char *mtk_country_codes[] = {
// "DB",
"AE",
"AL",
"AR",
"AT",
"AM",
"AU",
"AZ",
"BE",
"BH",
"BY",
"BO",
"BR",
"BN",
"BG",
"BZ",
"CA",
"CH",
"CL",
"CN",
"CO",
"CR",
"CY",
"CZ",
"DE",
"DK",
"DO",
"DZ",
"EC",
"EG",
"EE",
"ES",
"FI",
"FR",
"GE",
"GB",
"GR",
"GT",
"HN",
"HK",
"HU",
"HR",
"IS",
"IN",
"ID",
"IR",
"IE",
"IL",
"IT",
"JP",
"JO",
"KP",
"KR",
"KW",
"KZ",
"LB",
"LI",
"LT",
"LU",
"LV",
"MA",
"MC",
"MO",
"MK",
"MX",
"MY",
"NL",
"NO",
"NZ",
"OM",
"PA",
"PE",
"PH",
"PL",
"PK",
"PT",
"PR",
"QA",
"RO",
"RU",
"SA",
"SG",
"SK",
"SI",
"SV",
"SE",
"SY",
"TH",
"TN",
"TR",
"TT",
"TW",
"UA",
"US",
"UY",
"UZ",
"VE",
"VN",
"YE",
"ZA",
"ZW",
};

View File

@ -0,0 +1,479 @@
#include "mtwifi.h"
#define MAX_NUM_HE_BANDWIDTHS 4
#define MAX_NUM_HE_SPATIAL_STREAMS 4
#define MAX_NUM_HE_MCS_ENTRIES 12
UINT32 cck_to_mcs(UINT32 mcs) {
UINT32 ret = 0;
if (mcs == TMI_TX_RATE_CCK_1M_LP)
ret = 0;
else if (mcs == TMI_TX_RATE_CCK_2M_LP)
ret = 1;
else if (mcs == TMI_TX_RATE_CCK_5M_LP)
ret = 2;
else if (mcs == TMI_TX_RATE_CCK_11M_LP)
ret = 3;
else if (mcs == TMI_TX_RATE_CCK_2M_SP)
ret = 1;
else if (mcs == TMI_TX_RATE_CCK_5M_SP)
ret = 2;
else if (mcs == TMI_TX_RATE_CCK_11M_SP)
ret = 3;
return ret;
}
static UINT16 he_mcs_phyrate_mapping_table[MAX_NUM_HE_BANDWIDTHS][MAX_NUM_HE_SPATIAL_STREAMS][MAX_NUM_HE_MCS_ENTRIES] = {
{ /*20 Mhz*/
/* 1 SS */
{
/* DCM 0*/
8,
17,
25,
34,
51,
68,
77,
86,
103,
114,
129,
143
},
/* 2 SS */
{
/* DCM 0 */
17,
34,
51,
68,
103,
137,
154,
172,
206,
229,
258,
286
},
/* 3 SS */
{
/* DCM 0 */
25,
51,
77,
103,
154,
206,
232,
258,
309,
344,
387,
430
},
/* 4 SS */
{
/* DCM 0 */
34,
68,
103,
137,
206,
275,
309,
344,
412,
458,
516,
573
}
},
{ /*40 Mhz*/
/* 1 SS */
{
/* DCM 0*/
17,
34,
51,
68,
103,
137,
154,
172,
206,
229,
258,
286
},
/* 2 SS */
{
/* DCM 0 */
34,
68,
103,
137,
206,
275,
309,
344,
412,
458,
516,
573
},
/* 3 SS */
{
/* DCM 0 */
51,
103,
154,
206,
309,
412,
464,
516,
619,
688,
774,
860
},
/* 4 SS */
{
/* DCM 0 */
68,
137,
206,
275,
412,
550,
619,
688,
825,
917,
1032,
1147
}
},
{ /*80 Mhz*/
/* 1 SS */
{
/* DCM 0*/
36,
72,
108,
144,
216,
288,
324,
360,
432,
480,
540,
600
},
/* 2 SS */
{
/* DCM 0 */
72,
144,
216,
288,
432,
576,
648,
720,
864,
960,
1080,
1201
},
/* 3 SS */
{
/* DCM 0 */
108,
216,
324,
432,
648,
864,
972,
1080,
1297,
1441,
1621,
1801
},
/* 4 SS */
{
/* DCM 0 */
144,
288,
432,
576,
864,
1152,
1297,
1141,
1729,
1921,
2161,
2401
}
},
{ /*160 Mhz*/
/* 1 SS */
{
/* DCM 0*/
72,
144,
216,
288,
432,
576,
648,
720,
864,
960,
1080,
1201
},
/* 2 SS */
{
/* DCM 0 */
144,
288,
432,
576,
864,
1152,
1297,
1441,
1729,
1921,
2161,
2401
},
/* 3 SS */
{
/* DCM 0 */
216,
432,
648,
864,
1297,
1729,
1945,
2161,
2594,
2882,
3242,
3602
},
/* 4 SS */
{
/* DCM 0 */
288,
576,
864,
1152,
1729,
2305,
2594,
2882,
3458,
3843,
4323,
4803
},
}
};
void get_rate_he(UINT8 mcs, UINT8 bw, UINT8 nss, UINT8 dcm, ULONG *last_tx_rate)
{
ULONG value = 0;
if (nss == 0)
nss = 1;
if (mcs >= MAX_NUM_HE_MCS_ENTRIES)
mcs = MAX_NUM_HE_MCS_ENTRIES - 1;
if (nss > MAX_NUM_HE_SPATIAL_STREAMS)
nss = MAX_NUM_HE_SPATIAL_STREAMS;
if (bw >= MAX_NUM_HE_BANDWIDTHS)
bw = MAX_NUM_HE_BANDWIDTHS - 1;
nss--;
value = he_mcs_phyrate_mapping_table[bw][nss][mcs];
/*In spec data rate when DCM =1 is half of the data rate when DCM = 0*/
if (dcm && value)
value = value / 2 ;
*last_tx_rate = (ULONG)value;
return;
}
static INT32 getLegacyOFDMMCSIndex(UINT8 MCS)
{
INT32 mcs_index = MCS;
if (MCS == 0xb)
mcs_index = 0;
else if (MCS == 0xf)
mcs_index = 1;
else if (MCS == 0xa)
mcs_index = 2;
else if (MCS == 0xe)
mcs_index = 3;
else if (MCS == 0x9)
mcs_index = 4;
else if (MCS == 0xd)
mcs_index = 5;
else if (MCS == 0x8)
mcs_index = 6;
else if (MCS == 0xc)
mcs_index = 7;
return mcs_index;
}
static INT MCSMappingRateTable[] = {
2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108, 109, 110, 111, 112,/* CCK and OFDM */
13, 26, 39, 52, 78, 104, 117, 130, 26, 52, 78, 104, 156, 208, 234, 260,
39, 78, 117, 156, 234, 312, 351, 390, /* BW 20, 800ns GI, MCS 0~23 */
27, 54, 81, 108, 162, 216, 243, 270, 54, 108, 162, 216, 324, 432, 486, 540,
81, 162, 243, 324, 486, 648, 729, 810, /* BW 40, 800ns GI, MCS 0~23 */
14, 29, 43, 57, 87, 115, 130, 144, 29, 59, 87, 115, 173, 230, 260, 288,
43, 87, 130, 173, 260, 317, 390, 433, /* BW 20, 400ns GI, MCS 0~23 */
30, 60, 90, 120, 180, 240, 270, 300, 60, 120, 180, 240, 360, 480, 540, 600,
90, 180, 270, 360, 540, 720, 810, 900, /* BW 40, 400ns GI, MCS 0~23 */
/*for 11ac:20 Mhz 800ns GI*/
6, 13, 19, 26, 39, 52, 58, 65, 78, 90, /*1ss mcs 0~8*/
13, 26, 39, 52, 78, 104, 117, 130, 156, 180, /*2ss mcs 0~8*/
19, 39, 58, 78, 117, 156, 175, 195, 234, 260, /*3ss mcs 0~9*/
26, 52, 78, 104, 156, 208, 234, 260, 312, 360, /*4ss mcs 0~8*/
/*for 11ac:40 Mhz 800ns GI*/
13, 27, 40, 54, 81, 108, 121, 135, 162, 180, /*1ss mcs 0~9*/
27, 54, 81, 108, 162, 216, 243, 270, 324, 360, /*2ss mcs 0~9*/
40, 81, 121, 162, 243, 324, 364, 405, 486, 540, /*3ss mcs 0~9*/
54, 108, 162, 216, 324, 432, 486, 540, 648, 720, /*4ss mcs 0~9*/
/*for 11ac:80 Mhz 800ns GI*/
29, 58, 87, 117, 175, 234, 263, 292, 351, 390, /*1ss mcs 0~9*/
58, 117, 175, 243, 351, 468, 526, 585, 702, 780, /*2ss mcs 0~9*/
87, 175, 263, 351, 526, 702, 0, 877, 1053, 1170, /*3ss mcs 0~9*/
117, 234, 351, 468, 702, 936, 1053, 1170, 1404, 1560, /*4ss mcs 0~9*/
/*for 11ac:160 Mhz 800ns GI*/
58, 117, 175, 234, 351, 468, 526, 585, 702, 780, /*1ss mcs 0~9*/
117, 234, 351, 468, 702, 936, 1053, 1170, 1404, 1560, /*2ss mcs 0~9*/
175, 351, 526, 702, 1053, 1404, 1579, 1755, 2160, 0, /*3ss mcs 0~8*/
234, 468, 702, 936, 1404, 1872, 2106, 2340, 2808, 3120, /*4ss mcs 0~9*/
/*for 11ac:20 Mhz 400ns GI*/
7, 14, 21, 28, 43, 57, 65, 72, 86, 100, /*1ss mcs 0~8*/
14, 28, 43, 57, 86, 115, 130, 144, 173, 200, /*2ss mcs 0~8*/
21, 43, 65, 86, 130, 173, 195, 216, 260, 288, /*3ss mcs 0~9*/
28, 57, 86, 115, 173, 231, 260, 288, 346, 400, /*4ss mcs 0~8*/
/*for 11ac:40 Mhz 400ns GI*/
15, 30, 45, 60, 90, 120, 135, 150, 180, 200, /*1ss mcs 0~9*/
30, 60, 90, 120, 180, 240, 270, 300, 360, 400, /*2ss mcs 0~9*/
45, 90, 135, 180, 270, 360, 405, 450, 540, 600, /*3ss mcs 0~9*/
60, 120, 180, 240, 360, 480, 540, 600, 720, 800, /*4ss mcs 0~9*/
/*for 11ac:80 Mhz 400ns GI*/
32, 65, 97, 130, 195, 260, 292, 325, 390, 433, /*1ss mcs 0~9*/
65, 130, 195, 260, 390, 520, 585, 650, 780, 866, /*2ss mcs 0~9*/
97, 195, 292, 390, 585, 780, 0, 975, 1170, 1300, /*3ss mcs 0~9*/
130, 260, 390, 520, 780, 1040, 1170, 1300, 1560, 1733, /*4ss mcs 0~9*/
/*for 11ac:160 Mhz 400ns GI*/
65, 130, 195, 260, 390, 520, 585, 650, 780, 866, /*1ss mcs 0~9*/
130, 260, 390, 520, 780, 1040, 1170, 1300, 1560, 1733, /*2ss mcs 0~9*/
195, 390, 585, 780, 1170, 1560, 1755, 1950, 2340, 0, /*3ss mcs 0~8*/
260, 520, 780, 1040, 1560, 2080, 2340, 2600, 3120, 3466, /*4ss mcs 0~9*/
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37
}; /* 3*3 */
void getRate(HTTRANSMIT_SETTING HTSetting, ULONG *fLastTxRxRate)
{
UINT8 Antenna = 0;
UINT8 MCS = HTSetting.field.MCS;
int rate_count = sizeof(MCSMappingRateTable) / sizeof(int);
int rate_index = 0;
int value = 0;
if (HTSetting.field.MODE >= MODE_VHT) {
MCS = HTSetting.field.MCS & 0xf;
Antenna = (HTSetting.field.MCS >> 4) + 1;
if (HTSetting.field.BW == BW_20) {
rate_index = 112 + ((Antenna - 1) * 10) +
((UCHAR)HTSetting.field.ShortGI * 160) +
((UCHAR)MCS);
} else if (HTSetting.field.BW == BW_40) {
rate_index = 152 + ((Antenna - 1) * 10) +
((UCHAR)HTSetting.field.ShortGI * 160) +
((UCHAR)MCS);
} else if (HTSetting.field.BW == BW_80) {
rate_index = 192 + ((Antenna - 1) * 10) +
((UCHAR)HTSetting.field.ShortGI * 160) +
((UCHAR)MCS);
} else if (HTSetting.field.BW == BW_160) {
rate_index = 232 + ((Antenna - 1) * 10) +
((UCHAR)HTSetting.field.ShortGI * 160) +
((UCHAR)MCS);
}
} else {
if (HTSetting.field.MODE >= MODE_HTMIX) {
MCS = HTSetting.field.MCS;
if ((HTSetting.field.MODE == MODE_HTMIX)
|| (HTSetting.field.MODE == MODE_HTGREENFIELD))
Antenna = (MCS >> 3) + 1;
/* map back to 1SS MCS , multiply by antenna numbers later */
if (MCS > 7)
MCS %= 8;
rate_index = 16 + ((UCHAR)HTSetting.field.BW * 24) + ((UCHAR)HTSetting.field.ShortGI * 48) + ((UCHAR)MCS);
} else {
if (HTSetting.field.MODE == MODE_OFDM)
rate_index = getLegacyOFDMMCSIndex(HTSetting.field.MCS) + 4;
else if (HTSetting.field.MODE == MODE_CCK)
rate_index = (UCHAR)(HTSetting.field.MCS);
}
}
if (rate_index < 0)
rate_index = 0;
if (rate_index >= rate_count)
rate_index = rate_count - 1;
if (HTSetting.field.MODE < MODE_VHT)
value = (MCSMappingRateTable[rate_index] * 5) / 10;
else
value = MCSMappingRateTable[rate_index];
if (HTSetting.field.MODE >= MODE_HTMIX && HTSetting.field.MODE < MODE_VHT)
value *= Antenna;
*fLastTxRxRate = (ULONG)value;
return;
}

View File

@ -0,0 +1,266 @@
#ifndef __MTWIFI_H
#define __MTWIFI_H
#define USHORT unsigned short
#define UCHAR unsigned char
#define ULONG unsigned long
#define UINT8 unsigned char
#define UINT16 unsigned short
#define UINT32 unsigned int
#define INT32 int
#define INT int
typedef union _HTTRANSMIT_SETTING_FIX {
struct {
unsigned short MCS:6;
unsigned short ldpc:1;
unsigned short BW:2;
unsigned short ShortGI:2;
unsigned short STBC:1;
unsigned short eTxBF:1;
unsigned short iTxBF:1;
unsigned short MODE:4;
} field;
unsigned int word;
} HTTRANSMIT_SETTING, *PHTTRANSMIT_SETTING;
typedef struct _RT_802_11_MAC_ENTRY_FIX {
unsigned char ApIdx;
unsigned char Addr[6];
unsigned short Aid;
unsigned char Psm;
unsigned char MimoPs;
signed char AvgRssi0;
signed char AvgRssi1;
signed char AvgRssi2;
signed char AvgRssi3;
unsigned int ConnectedTime;
HTTRANSMIT_SETTING TxRate;
HTTRANSMIT_SETTING LastRxRate;
short StreamSnr[3];
short SoundingRespSnr[3];
unsigned int EncryMode;
unsigned int AuthMode;
} RT_802_11_MAC_ENTRY;
#define MAX_NUMBER_OF_MAC 544
typedef struct _RT_802_11_MAC_TABLE_FIX {
unsigned long Num;
RT_802_11_MAC_ENTRY Entry[MAX_NUMBER_OF_MAC];
} RT_802_11_MAC_TABLE;
#define RT_PRIV_IOCTL (SIOCIWFIRSTPRIV + 0x01)
#define RTPRIV_IOCTL_SET (SIOCIWFIRSTPRIV + 0x02)
#define RTPRIV_IOCTL_E2P (SIOCIWFIRSTPRIV + 0x07)
#define RTPRIV_IOCTL_GET_MAC_TABLE_STRUCT (SIOCIWFIRSTPRIV + 0x1F)
#define RTPRIV_IOCTL_SHOW (SIOCIWFIRSTPRIV + 0x11)
#define RTPRIV_IOCTL_GSITESURVEY (SIOCIWFIRSTPRIV + 0x0D)
#define RTPRIV_IOCTL_PHY_STATE (SIOCIWFIRSTPRIV + 0x21)
#define RTPRIV_IOCTL_GET_DRIVER_INFO (SIOCIWFIRSTPRIV + 0x1D)
#define OID_802_11_COUNTRYCODE 0x1907
#define OID_802_11_BW 0x1903
#define OID_GET_CHAN_LIST 0x0998
#define OID_GET_WIRELESS_BAND 0x09B4
#define OID_802_11_SECURITY_TYPE 0x093e
#define RT_OID_802_11_PHY_MODE 0x050C
#define GET_MAC_TABLE_STRUCT_FLAG_RAW_SSID 0x1
#define MODE_CCK 0
#define MODE_OFDM 1
#define MODE_HTMIX 2
#define MODE_HTGREENFIELD 3
#define MODE_VHT 4
#define MODE_HE 5
#define MODE_HE_5G 6
#define MODE_HE_24G 7
#define MODE_HE_SU 8
#define MODE_HE_EXT_SU 9
#define MODE_HE_TRIG 10
#define MODE_HE_MU 11
#define TMI_TX_RATE_OFDM_6M 11
#define TMI_TX_RATE_OFDM_9M 15
#define TMI_TX_RATE_OFDM_12M 10
#define TMI_TX_RATE_OFDM_18M 14
#define TMI_TX_RATE_OFDM_24M 9
#define TMI_TX_RATE_OFDM_36M 13
#define TMI_TX_RATE_OFDM_48M 8
#define TMI_TX_RATE_OFDM_54M 12
#define TMI_TX_RATE_CCK_1M_LP 0
#define TMI_TX_RATE_CCK_2M_LP 1
#define TMI_TX_RATE_CCK_5M_LP 2
#define TMI_TX_RATE_CCK_11M_LP 3
#define TMI_TX_RATE_CCK_2M_SP 5
#define TMI_TX_RATE_CCK_5M_SP 6
#define TMI_TX_RATE_CCK_11M_SP 7
enum oid_bw {
BAND_WIDTH_20,
BAND_WIDTH_40,
BAND_WIDTH_80,
BAND_WIDTH_160,
BAND_WIDTH_10,
BAND_WIDTH_5,
BAND_WIDTH_8080,
BAND_WIDTH_BOTH,
BAND_WIDTH_25,
BAND_WIDTH_20_242TONE,
BAND_WIDTH_NUM
};
#define BW_20 BAND_WIDTH_20
#define BW_40 BAND_WIDTH_40
#define BW_80 BAND_WIDTH_80
#define BW_160 BAND_WIDTH_160
#define BW_10 BAND_WIDTH_10
#define BW_5 BAND_WIDTH_5
#define BW_8080 BAND_WIDTH_8080
#define BW_25 BAND_WIDTH_25
#define BW_20_242TONE BAND_WIDTH_20_242TONE
#define BW_NUM BAND_WIDTH_NUM
enum WIFI_MODE {
WMODE_INVALID = 0,
WMODE_A = 1 << 0,
WMODE_B = 1 << 1,
WMODE_G = 1 << 2,
WMODE_GN = 1 << 3,
WMODE_AN = 1 << 4,
WMODE_AC = 1 << 5,
WMODE_AX_24G = 1 << 6,
WMODE_AX_5G = 1 << 7,
WMODE_AX_6G = 1 << 8,
WMODE_COMP = 9,
};
#define WMODE_CAP_N(_x) (((_x) & (WMODE_GN | WMODE_AN)) != 0)
#define WMODE_CAP_AC(_x) (((_x) & (WMODE_AC)) != 0)
#define WMODE_CAP_AX(_x) ((_x) & (WMODE_AX_24G | WMODE_AX_5G | WMODE_AX_6G))
enum MTK_CH_BAND {
MTK_CH_BAND_24G = 0,
MTK_CH_BAND_5G = 1,
MTK_CH_BAND_6G = 2,
};
#define MAX_NUM_OF_CHANNELS 59
struct __attribute__ ((packed)) chnList {
unsigned char channel;
unsigned char pref;
unsigned short cac_timer;
};
typedef struct __attribute__ ((packed)) _wdev_chn_info {
unsigned char op_ch;
unsigned char op_class;
unsigned short band;
unsigned char ch_list_num;
unsigned char non_op_chn_num;
unsigned short dl_mcs;
struct chnList ch_list[32];
unsigned char non_op_ch_list[32];
unsigned char AutoChannelSkipListNum;
unsigned char AutoChannelSkipList[MAX_NUM_OF_CHANNELS + 1];
} wdev_chn_info;
struct security_info {
unsigned int ifindex;
unsigned int auth_mode;
unsigned int encryp_type;
};
typedef enum _SEC_CIPHER_MODE {
SEC_CIPHER_NONE,
SEC_CIPHER_WEP40,
SEC_CIPHER_WEP104,
SEC_CIPHER_WEP128,
SEC_CIPHER_TKIP,
SEC_CIPHER_CCMP128,
SEC_CIPHER_CCMP256,
SEC_CIPHER_GCMP128,
SEC_CIPHER_GCMP256,
SEC_CIPHER_BIP_CMAC128,
SEC_CIPHER_BIP_CMAC256,
SEC_CIPHER_BIP_GMAC128,
SEC_CIPHER_BIP_GMAC256,
SEC_CIPHER_WPI_SMS4, /* WPI SMS4 support */
SEC_CIPHER_MAX /* Not a real mode, defined as upper bound */
} SEC_CIPHER_MODE;
#define IS_CIPHER_NONE(_Cipher) (((_Cipher) & (1 << SEC_CIPHER_NONE)) > 0)
#define IS_CIPHER_WEP40(_Cipher) (((_Cipher) & (1 << SEC_CIPHER_WEP40)) > 0)
#define IS_CIPHER_WEP104(_Cipher) (((_Cipher) & (1 << SEC_CIPHER_WEP104)) > 0)
#define IS_CIPHER_WEP128(_Cipher) (((_Cipher) & (1 << SEC_CIPHER_WEP128)) > 0)
#define IS_CIPHER_WEP(_Cipher) (((_Cipher) & ((1 << SEC_CIPHER_WEP40) | (1 << SEC_CIPHER_WEP104) | (1 << SEC_CIPHER_WEP128))) > 0)
#define IS_CIPHER_TKIP(_Cipher) (((_Cipher) & (1 << SEC_CIPHER_TKIP)) > 0)
#define IS_CIPHER_WEP_TKIP_ONLY(_Cipher) ((IS_CIPHER_WEP(_Cipher) || IS_CIPHER_TKIP(_Cipher)) && (_Cipher < (1 << SEC_CIPHER_CCMP128)))
#define IS_CIPHER_CCMP128(_Cipher) (((_Cipher) & (1 << SEC_CIPHER_CCMP128)) > 0)
#define IS_CIPHER_CCMP256(_Cipher) (((_Cipher) & (1 << SEC_CIPHER_CCMP256)) > 0)
#define IS_CIPHER_GCMP128(_Cipher) (((_Cipher) & (1 << SEC_CIPHER_GCMP128)) > 0)
#define IS_CIPHER_GCMP256(_Cipher) (((_Cipher) & (1 << SEC_CIPHER_GCMP256)) > 0)
#define IS_CIPHER_BIP_CMAC128(_Cipher) (((_Cipher) & (1 << SEC_CIPHER_BIP_CMAC128)) > 0)
#define IS_CIPHER_BIP_CMAC256(_Cipher) (((_Cipher) & (1 << SEC_CIPHER_BIP_CMAC256)) > 0)
#define IS_CIPHER_BIP_GMAC128(_Cipher) (((_Cipher) & (1 << SEC_CIPHER_BIP_GMAC128)) > 0)
#define IS_CIPHER_BIP_GMAC256(_Cipher) (((_Cipher) & (1 << SEC_CIPHER_BIP_GMAC256)) > 0)
/* 802.11 authentication and key management */
typedef enum _SEC_AKM_MODE {
SEC_AKM_OPEN,
SEC_AKM_SHARED,
SEC_AKM_AUTOSWITCH,
SEC_AKM_WPA1, /* Enterprise security over 802.1x */
SEC_AKM_WPA1PSK,
SEC_AKM_WPANone, /* For Win IBSS, directly PTK, no handshark */
SEC_AKM_WPA2, /* Enterprise security over 802.1x */
SEC_AKM_WPA2PSK,
SEC_AKM_FT_WPA2,
SEC_AKM_FT_WPA2PSK,
SEC_AKM_WPA2_SHA256,
SEC_AKM_WPA2PSK_SHA256,
SEC_AKM_TDLS,
SEC_AKM_SAE_SHA256,
SEC_AKM_FT_SAE_SHA256,
SEC_AKM_SUITEB_SHA256,
SEC_AKM_SUITEB_SHA384,
SEC_AKM_FT_WPA2_SHA384,
SEC_AKM_WAICERT, /* WAI certificate authentication */
SEC_AKM_WAIPSK, /* WAI pre-shared key */
SEC_AKM_OWE,
SEC_AKM_FILS_SHA256,
SEC_AKM_FILS_SHA384,
SEC_AKM_WPA3, /* WPA3(ent) = WPA2(ent) + PMF MFPR=1 => WPA3 code flow is same as WPA2, the usage of SEC_AKM_WPA3 is to force pmf on */
SEC_AKM_MAX /* Not a real mode, defined as upper bound */
} SEC_AKM_MODE;
#define IS_AKM_OPEN(_AKMMap) ((_AKMMap & (1 << SEC_AKM_OPEN)) > 0)
#define IS_AKM_SHARED(_AKMMap) ((_AKMMap & (1 << SEC_AKM_SHARED)) > 0)
#define IS_AKM_AUTOSWITCH(_AKMMap) ((_AKMMap & (1 << SEC_AKM_AUTOSWITCH)) > 0)
#define IS_AKM_WPA1(_AKMMap) ((_AKMMap & (1 << SEC_AKM_WPA1)) > 0)
#define IS_AKM_WPA1PSK(_AKMMap) ((_AKMMap & (1 << SEC_AKM_WPA1PSK)) > 0)
#define IS_AKM_WPANONE(_AKMMap) ((_AKMMap & (1 << SEC_AKM_WPANone)) > 0)
#define IS_AKM_WPA2(_AKMMap) ((_AKMMap & (1 << SEC_AKM_WPA2)) > 0)
#define IS_AKM_WPA2PSK(_AKMMap) ((_AKMMap & (1 << SEC_AKM_WPA2PSK)) > 0)
#define IS_AKM_FT_WPA2(_AKMMap) ((_AKMMap & (1 << SEC_AKM_FT_WPA2)) > 0)
#define IS_AKM_FT_WPA2PSK(_AKMMap) ((_AKMMap & (1 << SEC_AKM_FT_WPA2PSK)) > 0)
#define IS_AKM_WPA2_SHA256(_AKMMap) ((_AKMMap & (1 << SEC_AKM_WPA2_SHA256)) > 0)
#define IS_AKM_WPA2PSK_SHA256(_AKMMap) ((_AKMMap & (1 << SEC_AKM_WPA2PSK_SHA256)) > 0)
#define IS_AKM_TDLS(_AKMMap) ((_AKMMap & (1 << SEC_AKM_TDLS)) > 0)
#define IS_AKM_SAE_SHA256(_AKMMap) ((_AKMMap & (1 << SEC_AKM_SAE_SHA256)) > 0)
#define IS_AKM_FT_SAE_SHA256(_AKMMap) ((_AKMMap & (1 << SEC_AKM_FT_SAE_SHA256)) > 0)
#define IS_AKM_SUITEB_SHA256(_AKMMap) ((_AKMMap & (1 << SEC_AKM_SUITEB_SHA256)) > 0)
#define IS_AKM_SUITEB_SHA384(_AKMMap) ((_AKMMap & (1 << SEC_AKM_SUITEB_SHA384)) > 0)
#define IS_AKM_FT_WPA2_SHA384(_AKMMap) ((_AKMMap & (1 << SEC_AKM_FT_WPA2_SHA384)) > 0)
#define IS_AKM_WPA3(_AKMMap) ((_AKMMap & (1 << SEC_AKM_WPA3)) > 0)
#define IS_AKM_WPA3PSK(_AKMMap) (IS_AKM_SAE_SHA256(_AKMMap))
#define IS_AKM_WPA3_192BIT(_AKMMap) (IS_AKM_SUITEB_SHA384(_AKMMap))
#define IS_AKM_OWE(_AKMMap) ((_AKMMap & (1 << SEC_AKM_OWE)) > 0)
void getRate(HTTRANSMIT_SETTING HTSetting, ULONG *fLastTxRxRate);
void get_rate_he(UINT8 mcs, UINT8 bw, UINT8 nss, UINT8 dcm, ULONG *last_tx_rate);
UINT32 cck_to_mcs(UINT32 mcs);
#endif