mirror of
https://github.com/revyos/thead-kernel.git
synced 2026-06-21 17:22:24 +02:00
Compare commits
34 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e4d83fe5e9 | ||
|
|
d006b031de | ||
|
|
c60ffab855 | ||
|
|
61d6e77d70 | ||
|
|
28105dd629 | ||
|
|
58343a5e88 | ||
|
|
b62e9d2bad | ||
|
|
96fb165dd9 | ||
|
|
9333b0b1cc | ||
|
|
ebfc038d19 | ||
|
|
e918e0cca4 | ||
|
|
82e7b4b427 | ||
|
|
166b2fb1fa | ||
|
|
5fae7c4a41 | ||
|
|
43759394d6 | ||
|
|
ea8582dab3 | ||
|
|
38d42bd66e | ||
|
|
e7aceec67d | ||
|
|
85890f4a0b | ||
|
|
797b673ebf | ||
|
|
7029ef3704 | ||
|
|
a78c95c854 | ||
|
|
fd760c09e1 | ||
|
|
fa34a6a78e | ||
|
|
44361ed63a | ||
|
|
32539f0dc7 | ||
|
|
4e582eb6b3 | ||
|
|
f50a437148 | ||
|
|
15d53ae438 | ||
|
|
9d3e776a62 | ||
|
|
b76b15d078 | ||
|
|
92ed9d94c6 | ||
|
|
698e02e86a | ||
|
|
a1feea7628 |
2
.github/workflows/kernel.yml
vendored
2
.github/workflows/kernel.yml
vendored
@@ -14,7 +14,7 @@ env:
|
||||
mainline_toolchain_file_name: riscv64-glibc-ubuntu-22.04-gcc-nightly-2024.03.01-nightly.tar.gz
|
||||
wget_alias: 'wget --retry-connrefused --waitretry=1 --read-timeout=20 --timeout=15 -t 0'
|
||||
ARCH: riscv
|
||||
board: th1520
|
||||
board: yocto-standard
|
||||
KBUILD_BUILD_USER: builder
|
||||
KBUILD_BUILD_HOST: revyos-riscv-builder
|
||||
KDEB_COMPRESS: none
|
||||
|
||||
@@ -61,6 +61,9 @@ dtb-$(CONFIG_SOC_THEAD) += th1520-lpi4a-cluster.dtb th1520-lpi4a-cluster-16gb.dt
|
||||
dtb-$(CONFIG_SOC_THEAD) += th1520-lpi4a-z14inch-m0.dtb th1520-lpi4a-z14inch-m0-16g.dtb
|
||||
dtb-$(CONFIG_SOC_THEAD) += th1520-milkv-meles.dtb th1520-milkv-meles-4g.dtb th1520-milkv-meles-dsi0.dtb
|
||||
|
||||
# huiwei support
|
||||
dtb-$(CONFIG_SOC_THEAD) += th1520-huiwei-product.dtb th1520-huiwei-dsi0.dtb
|
||||
|
||||
# compat old name
|
||||
dtb-$(CONFIG_SOC_THEAD) += light-lpi4a.dtb light-lpi4a-16gb.dtb
|
||||
dtb-$(CONFIG_SOC_THEAD) += light-lpi4a-console.dtb light-lpi4a-console-16g.dtb
|
||||
|
||||
161
arch/riscv/boot/dts/thead/th1520-huiwei-dsi0.dts
Normal file
161
arch/riscv/boot/dts/thead/th1520-huiwei-dsi0.dts
Normal file
@@ -0,0 +1,161 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
/*
|
||||
* Copyright (C) 2022 Alibaba Group Holding Limited.
|
||||
*/
|
||||
|
||||
#include "th1520-huiwei.dtsi"
|
||||
|
||||
/ {
|
||||
model = "TH1520 Huiweibook";
|
||||
compatible = "thead,light-val", "thead,light-lpi4a", "thead,light";
|
||||
|
||||
memory@0 {
|
||||
device_type = "memory";
|
||||
reg = <0x0 0x00000000 0x2 0x00000000>;
|
||||
};
|
||||
|
||||
vcc1v8_lontium: vcc1v8-lontium {
|
||||
compatible = "regulator-fixed";
|
||||
enable-active-high;
|
||||
regulator-min-microvolt = <1800000>;
|
||||
regulator-max-microvolt = <1800000>;
|
||||
gpio = <&gpio3_porta 17 GPIO_ACTIVE_HIGH>;
|
||||
pinctrl-names = "default";
|
||||
pinctrl-0 = <&vcc1v8_lontium_pwren>;
|
||||
regulator-name = "vcc1v8-lontium";
|
||||
};
|
||||
|
||||
vcc3v3_edp: vcc3v3-edp {
|
||||
compatible = "regulator-fixed";
|
||||
enable-active-high;
|
||||
regulator-min-microvolt = <3300000>;
|
||||
regulator-max-microvolt = <3300000>;
|
||||
gpio = <&gpio2_porta 18 GPIO_ACTIVE_HIGH>;
|
||||
pinctrl-names = "default";
|
||||
pinctrl-0 = <&vcc3v3_edp_pwren>;
|
||||
regulator-name = "vcc3v3-edp";
|
||||
};
|
||||
};
|
||||
|
||||
&cmamem {
|
||||
alloc-ranges = <0x1 0xe4000000 0 0x14000000>; // [0x1E400_0000 ~ 0x1F800_0000]
|
||||
};
|
||||
|
||||
&pwm {
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
&qspi0 {
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
&qspi1 {
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
&i2c3 {
|
||||
clock-frequency = <400000>;
|
||||
status = "okay";
|
||||
pinctrl-names = "default";
|
||||
pinctrl-0 = <&pinctrl_i2c3>;
|
||||
|
||||
lt8911i2c: lt8911i2c@29{
|
||||
compatible = "i2c,lt8911";
|
||||
reg = <0x29>;
|
||||
};
|
||||
};
|
||||
|
||||
&dpu_enc0 {
|
||||
status = "okay";
|
||||
|
||||
ports {
|
||||
/* output */
|
||||
port@1 {
|
||||
reg = <1>;
|
||||
|
||||
enc0_out: endpoint {
|
||||
remote-endpoint = <&dsi0_in>;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
&dpu_enc1 {
|
||||
ports {
|
||||
/delete-node/ port@0;
|
||||
};
|
||||
};
|
||||
|
||||
&dpu {
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
&dsi0 {
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
&dhost_0 {
|
||||
panel0@0 {
|
||||
compatible = "i2c_dsi,lt8911";
|
||||
reg = <0>;
|
||||
lt8911,backlight-gpio = <&gpio2_porta 20 GPIO_ACTIVE_HIGH>;
|
||||
lt8911,irq-gpio = <&gpio3_porta 16 GPIO_ACTIVE_LOW>;
|
||||
lt8911,reset-gpio = <&gpio3_porta 15 GPIO_ACTIVE_LOW>;
|
||||
lt8911,rst-delay-ms = <10>;
|
||||
lt8911,edp-lane-cnt = <2>;
|
||||
lt8911,mipi-lane-cnt = <4>;
|
||||
lt8911,edp-depth = <8>; /* 6 or 8 */
|
||||
pinctrl-names = "default";
|
||||
pinctrl-0 = <<8911exb_gpios>;
|
||||
hsvcc-supply = <&vcc1v8_lontium>;
|
||||
vspn3v3-supply = <&vcc3v3_edp>;
|
||||
|
||||
port {
|
||||
panel0_in: endpoint {
|
||||
remote-endpoint = <&dsi0_out>;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
&padctrl0_apsys { /* right-pinctrl */
|
||||
light-evb-padctrl0 {
|
||||
/*
|
||||
* Pin Configuration Node:
|
||||
* Format: <pin_id mux_node config>
|
||||
*/
|
||||
pinctrl_i2c3: i2c3grp {
|
||||
thead,pins = <
|
||||
FM_I2C3_SCL LIGHT_PIN_FUNC_0 0x204
|
||||
FM_I2C3_SDA LIGHT_PIN_FUNC_0 0x204
|
||||
>;
|
||||
};
|
||||
|
||||
lt8911exb_gpios: lt8911exb-gpios {
|
||||
thead,pins = <
|
||||
FM_GPIO2_20 LIGHT_PIN_FUNC_0 0x208
|
||||
FM_GMAC0_RXD1 LIGHT_PIN_FUNC_3 0x0
|
||||
FM_GMAC0_RXD0 LIGHT_PIN_FUNC_3 0x208
|
||||
>;
|
||||
};
|
||||
|
||||
vcc1v8_lontium_pwren: vcc1v8-lontium-pwren {
|
||||
thead,pins = <
|
||||
FM_GMAC0_RXD2 LIGHT_PIN_FUNC_3 0x208
|
||||
>;
|
||||
};
|
||||
|
||||
vcc3v3_edp_pwren: vcc3v3-edp-pwren {
|
||||
thead,pins = <
|
||||
FM_GPIO2_18 LIGHT_PIN_FUNC_0 0x208
|
||||
>;
|
||||
};
|
||||
dsi_reset_gpio: dsi-reset-gpio {
|
||||
thead,pins = <
|
||||
FM_GPIO2_22 LIGHT_PIN_FUNC_0 0x0
|
||||
>;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
/delete-node/ &iso7816;
|
||||
40
arch/riscv/boot/dts/thead/th1520-huiwei-product.dts
Normal file
40
arch/riscv/boot/dts/thead/th1520-huiwei-product.dts
Normal file
@@ -0,0 +1,40 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
/*
|
||||
* Copyright (C) 2021 Alibaba Group Holding Limited.
|
||||
*/
|
||||
|
||||
/dts-v1/;
|
||||
|
||||
#include "th1520-huiwei-dsi0.dts"
|
||||
|
||||
&lightsound {
|
||||
status = "okay";
|
||||
simple-audio-card,dai-link@0 { /* I2S - AUDIO SYS CODEC 8388*/
|
||||
reg = <0>;
|
||||
format = "i2s";
|
||||
cpu {
|
||||
sound-dai = <&i2s1 0>;
|
||||
};
|
||||
codec {
|
||||
sound-dai = <&es8388_audio_codec>;
|
||||
};
|
||||
};
|
||||
simple-audio-card,dai-link@1 { /* I2S - AUDIO SYS CODEC HDMI*/
|
||||
reg = <2>;
|
||||
format = "i2s";
|
||||
cpu {
|
||||
sound-dai = <&light_i2s 1>;
|
||||
};
|
||||
codec {
|
||||
sound-dai = <&dummy_codec>;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
&dpu_enc0 {
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
&dsi0 {
|
||||
status = "okay";
|
||||
};
|
||||
2157
arch/riscv/boot/dts/thead/th1520-huiwei.dtsi
Normal file
2157
arch/riscv/boot/dts/thead/th1520-huiwei.dtsi
Normal file
File diff suppressed because it is too large
Load Diff
@@ -987,7 +987,7 @@
|
||||
};
|
||||
|
||||
&sdhci1 {
|
||||
max-frequency = <100000000>;
|
||||
max-frequency = <198000000>;
|
||||
bus-width = <4>;
|
||||
pull_up;
|
||||
no-sd;
|
||||
@@ -996,6 +996,7 @@
|
||||
io_fixed_1v8;
|
||||
post-power-on-delay-ms = <50>;
|
||||
wprtn_ignore;
|
||||
sd-uhs-sdr104;
|
||||
cap-sd-highspeed;
|
||||
wakeup-source;
|
||||
status = "okay";
|
||||
|
||||
@@ -1767,8 +1767,8 @@
|
||||
light,sel = "ap_i2s";
|
||||
interrupt-parent = <&intc>;
|
||||
interrupts = <70>;
|
||||
dmas = <&dmac0 35>, <&dmac0 40>;
|
||||
dma-names = "tx", "rx";
|
||||
dmas = <&dmac0 35>;
|
||||
dma-names = "tx";
|
||||
light,dma_maxburst = <4>;
|
||||
#dma-cells = <1>;
|
||||
clocks = <&vosys_clk_gate LIGHT_CLKGEN_HDMI_I2S_CLK>;
|
||||
|
||||
@@ -38,7 +38,6 @@ CONFIG_FORCE_MAX_ZONEORDER=15
|
||||
CONFIG_SOC_SIFIVE=y
|
||||
CONFIG_SOC_THEAD=y
|
||||
CONFIG_SMP=y
|
||||
CONFIG_VECTOR=y
|
||||
CONFIG_CPU_IDLE=y
|
||||
CONFIG_CPU_IDLE_GOV_LADDER=y
|
||||
CONFIG_CPU_FREQ=y
|
||||
@@ -62,7 +61,6 @@ CONFIG_MODULES=y
|
||||
CONFIG_MODULE_UNLOAD=y
|
||||
CONFIG_BLK_DEV_THROTTLING=y
|
||||
CONFIG_BINFMT_MISC=m
|
||||
CONFIG_CMA=y
|
||||
CONFIG_CMA_DEBUGFS=y
|
||||
CONFIG_CMA_AREAS=16
|
||||
CONFIG_NET=y
|
||||
@@ -154,6 +152,7 @@ CONFIG_BLK_DEV_LOOP=y
|
||||
CONFIG_VIRTIO_BLK=y
|
||||
CONFIG_LIGHT_DSMART_CARD=y
|
||||
CONFIG_EEPROM_AT24=y
|
||||
CONFIG_MCU_HC32FX=y
|
||||
CONFIG_SCSI=y
|
||||
CONFIG_BLK_DEV_SD=y
|
||||
CONFIG_MD=y
|
||||
@@ -181,11 +180,11 @@ CONFIG_USB_USBNET=m
|
||||
# CONFIG_USB_NET_AX88179_178A is not set
|
||||
# CONFIG_USB_NET_NET1080 is not set
|
||||
CONFIG_BRCMFMAC=m
|
||||
CONFIG_RTL8723DS=y
|
||||
CONFIG_RTL8723DS=m
|
||||
CONFIG_AIC_WLAN_SUPPORT=y
|
||||
CONFIG_AIC_FW_PATH="/lib/firmware/aic8800"
|
||||
CONFIG_AIC8800_WLAN_SUPPORT=m
|
||||
CONFIG_AIC8800_BTLPM_SUPPORT=m
|
||||
CONFIG_RTL8822CS=m
|
||||
CONFIG_INPUT_MOUSEDEV=y
|
||||
CONFIG_INPUT_JOYDEV=y
|
||||
CONFIG_INPUT_EVDEV=y
|
||||
@@ -193,9 +192,9 @@ CONFIG_KEYBOARD_GPIO=y
|
||||
# CONFIG_INPUT_MOUSE is not set
|
||||
CONFIG_INPUT_TOUCHSCREEN=y
|
||||
CONFIG_TOUCHSCREEN_GOODIX=y
|
||||
CONFIG_TOUCHSCREEN_GT9XX=y
|
||||
CONFIG_INPUT_MISC=y
|
||||
CONFIG_INPUT_UINPUT=y
|
||||
CONFIG_MTK_FINGERPRINT_SUPPORT=y
|
||||
CONFIG_SERIAL_8250=y
|
||||
# CONFIG_SERIAL_8250_DEPRECATED_OPTIONS is not set
|
||||
CONFIG_SERIAL_8250_CONSOLE=y
|
||||
@@ -207,6 +206,8 @@ CONFIG_SERIAL_EARLYCON_RISCV_SBI=y
|
||||
CONFIG_VIRTIO_CONSOLE=y
|
||||
CONFIG_HW_RANDOM=y
|
||||
CONFIG_HW_RANDOM_VIRTIO=y
|
||||
CONFIG_TCG_TPM=y
|
||||
CONFIG_TCG_TIS_SPI=y
|
||||
CONFIG_I2C_CHARDEV=y
|
||||
CONFIG_I2C_DESIGNWARE_PLATFORM=y
|
||||
CONFIG_SPI=y
|
||||
@@ -221,12 +222,10 @@ CONFIG_GPIO_SYSFS=y
|
||||
CONFIG_GPIO_DWAPB=y
|
||||
CONFIG_GPIO_PCA953X=y
|
||||
CONFIG_GPIO_PCA953X_IRQ=y
|
||||
CONFIG_POWER_SUPPLY=y
|
||||
CONFIG_BATTERY_CW2015=m
|
||||
CONFIG_CHARGER_GPIO=m
|
||||
CONFIG_SENSORS_MR75203=y
|
||||
CONFIG_SENSORS_PWM_FAN=y
|
||||
CONFIG_THERMAL=y
|
||||
CONFIG_THERMAL_GOV_POWER_ALLOCATOR=y
|
||||
CONFIG_CPU_THERMAL=y
|
||||
CONFIG_THERMAL_EMULATION=y
|
||||
@@ -293,6 +292,7 @@ CONFIG_DRM_PANEL_HX8394=y
|
||||
CONFIG_DRM_PANEL_JADARD_JD9365DA_H3=y
|
||||
CONFIG_DRM_PANEL_MINGJUN_070BI30IA2=y
|
||||
CONFIG_DRM_PANEL_HX8279=y
|
||||
CONFIG_DRM_PANEL_LT8911=y
|
||||
CONFIG_DRM_LONTIUM_LT8911EXB=m
|
||||
CONFIG_DRM_ETNAVIV=m
|
||||
CONFIG_DRM_VERISILICON=y
|
||||
@@ -311,13 +311,15 @@ CONFIG_SND_SOC_AW87519=y
|
||||
CONFIG_SND_SOC_BT_SCO=y
|
||||
CONFIG_SND_SOC_ES7210=y
|
||||
CONFIG_SND_SOC_ES8156=y
|
||||
CONFIG_SND_SOC_ES8323=y
|
||||
CONFIG_SND_SOC_WM8960=y
|
||||
CONFIG_SND_SIMPLE_CARD=y
|
||||
CONFIG_SND_AUDIO_GRAPH_CARD=y
|
||||
CONFIG_RK_HEADSET=y
|
||||
CONFIG_UHID=y
|
||||
CONFIG_HID_PID=y
|
||||
CONFIG_USB_HIDDEV=y
|
||||
CONFIG_I2C_HID=m
|
||||
CONFIG_I2C_HID=y
|
||||
CONFIG_USB=y
|
||||
CONFIG_USB_XHCI_HCD=y
|
||||
CONFIG_USB_XHCI_PLATFORM=y
|
||||
@@ -393,7 +395,9 @@ CONFIG_USB_MASS_STORAGE=m
|
||||
CONFIG_USB_G_SERIAL=m
|
||||
CONFIG_USB_G_MULTI=m
|
||||
CONFIG_USB_G_MULTI_CDC=y
|
||||
CONFIG_USB_ROLE_SWITCH=m
|
||||
CONFIG_TYPEC=m
|
||||
CONFIG_TYPEC_TCPM=m
|
||||
CONFIG_TYPEC_TCPCI=m
|
||||
CONFIG_MMC=y
|
||||
CONFIG_MMC_SDHCI=y
|
||||
CONFIG_MMC_SDHCI_PLTFM=y
|
||||
@@ -436,7 +440,6 @@ CONFIG_HWSPINLOCK=y
|
||||
CONFIG_HWSPINLOCK_LIGHT=y
|
||||
CONFIG_HWSPINLOCK_LIGHT_TEST=m
|
||||
CONFIG_MAILBOX=y
|
||||
CONFIG_RPMSG=y
|
||||
CONFIG_RPMSG_CHAR=y
|
||||
CONFIG_RPMSG_THEAD_LIGHT=y
|
||||
CONFIG_RPMSG_VIRTIO=y
|
||||
@@ -446,7 +449,6 @@ CONFIG_DEVFREQ_GOV_PERFORMANCE=y
|
||||
CONFIG_DEVFREQ_GOV_POWERSAVE=y
|
||||
CONFIG_DEVFREQ_GOV_USERSPACE=y
|
||||
CONFIG_DEVFREQ_GOV_PASSIVE=y
|
||||
CONFIG_PM_DEVFREQ=y
|
||||
CONFIG_PM_DEVFREQ_EVENT=y
|
||||
CONFIG_EXTCON=y
|
||||
CONFIG_IIO=y
|
||||
@@ -469,7 +471,6 @@ CONFIG_OVERLAY_FS=y
|
||||
CONFIG_MSDOS_FS=y
|
||||
CONFIG_VFAT_FS=y
|
||||
CONFIG_EXFAT_FS=m
|
||||
CONFIG_TMPFS=y
|
||||
CONFIG_TMPFS_POSIX_ACL=y
|
||||
CONFIG_HUGETLBFS=y
|
||||
CONFIG_JFFS2_FS=y
|
||||
@@ -503,7 +504,6 @@ CONFIG_CRYPTO_USER_API_HASH=y
|
||||
CONFIG_CRYPTO_USER_API_SKCIPHER=y
|
||||
CONFIG_CRYPTO_USER_API_RNG=y
|
||||
CONFIG_CRYPTO_USER_API_AEAD=y
|
||||
CONFIG_DMA_CMA=y
|
||||
CONFIG_DMA_PERNUMA_CMA=y
|
||||
CONFIG_CMA_SIZE_MBYTES=32
|
||||
CONFIG_PRINTK_TIME=y
|
||||
|
||||
@@ -775,6 +775,7 @@ static int dwapb_gpio_suspend(struct device *dev)
|
||||
static int dwapb_gpio_resume(struct device *dev)
|
||||
{
|
||||
struct dwapb_gpio *gpio = dev_get_drvdata(dev);
|
||||
struct dwapb_context *ctx = gpio->ports[0].ctx;
|
||||
struct gpio_chip *gc = &gpio->ports[0].gc;
|
||||
unsigned long flags;
|
||||
int i, err;
|
||||
@@ -788,6 +789,7 @@ static int dwapb_gpio_resume(struct device *dev)
|
||||
spin_lock_irqsave(&gc->bgpio_lock, flags);
|
||||
for (i = 0; i < gpio->nr_ports; i++) {
|
||||
unsigned int offset;
|
||||
unsigned int int_pol,preserve_bit,resume_bit;
|
||||
unsigned int idx = gpio->ports[i].idx;
|
||||
struct dwapb_context *ctx = gpio->ports[i].ctx;
|
||||
|
||||
@@ -803,7 +805,11 @@ static int dwapb_gpio_resume(struct device *dev)
|
||||
/* Only port A can provide interrupts */
|
||||
if (idx == 0) {
|
||||
dwapb_write(gpio, GPIO_INTTYPE_LEVEL, ctx->int_type);
|
||||
dwapb_write(gpio, GPIO_INT_POLARITY, ctx->int_pol);
|
||||
int_pol = dwapb_read(gpio, GPIO_INT_POLARITY);
|
||||
preserve_bit = int_pol & ctx->wake_en;
|
||||
resume_bit = ctx->int_pol & (~ctx->wake_en);
|
||||
int_pol = preserve_bit | resume_bit;
|
||||
dwapb_write(gpio, GPIO_INT_POLARITY, int_pol);
|
||||
dwapb_write(gpio, GPIO_PORTA_DEBOUNCE, ctx->int_deb);
|
||||
dwapb_write(gpio, GPIO_INTEN, ctx->int_en);
|
||||
dwapb_write(gpio, GPIO_INTMASK, ctx->int_mask);
|
||||
@@ -818,8 +824,13 @@ static int dwapb_gpio_resume(struct device *dev)
|
||||
}
|
||||
#endif
|
||||
|
||||
static SIMPLE_DEV_PM_OPS(dwapb_gpio_pm_ops, dwapb_gpio_suspend,
|
||||
dwapb_gpio_resume);
|
||||
static const struct dev_pm_ops dwapb_gpio_pm_ops = {
|
||||
SET_LATE_SYSTEM_SLEEP_PM_OPS(dwapb_gpio_suspend, dwapb_gpio_resume)
|
||||
};
|
||||
|
||||
|
||||
//static SIMPLE_DEV_PM_OPS(dwapb_gpio_pm_ops, dwapb_gpio_suspend,
|
||||
// dwapb_gpio_resume);
|
||||
|
||||
static struct platform_driver dwapb_gpio_driver = {
|
||||
.driver = {
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include <drm/drm_print.h>
|
||||
#include <drm/drm_probe_helper.h>
|
||||
#include <drm/drm_scdc_helper.h>
|
||||
#include <linux/suspend.h>
|
||||
|
||||
#include "dw-hdmi-audio.h"
|
||||
#include "dw-hdmi-cec.h"
|
||||
@@ -219,8 +220,12 @@ struct dw_hdmi {
|
||||
hdmi_codec_plugged_cb plugged_cb;
|
||||
struct device *codec_dev;
|
||||
enum drm_connector_status last_connector_result;
|
||||
|
||||
struct notifier_block pm_notify; /*Used to receive STD notification*/
|
||||
};
|
||||
|
||||
static bool g_is_hdmi_std_suspend __nosavedata;
|
||||
|
||||
#define HDMI_IH_PHY_STAT0_RX_SENSE \
|
||||
(HDMI_IH_PHY_STAT0_RX_SENSE0 | HDMI_IH_PHY_STAT0_RX_SENSE1 | \
|
||||
HDMI_IH_PHY_STAT0_RX_SENSE2 | HDMI_IH_PHY_STAT0_RX_SENSE3)
|
||||
@@ -1431,6 +1436,11 @@ static int dw_hdmi_phy_power_on(struct dw_hdmi *hdmi)
|
||||
unsigned int i;
|
||||
u8 val;
|
||||
|
||||
if(g_is_hdmi_std_suspend){
|
||||
printk(KERN_INFO "dw_hdmi_phy_power_on under std mod, do not resume\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (phy->gen == 1) {
|
||||
dw_hdmi_phy_enable_powerdown(hdmi, false);
|
||||
|
||||
@@ -3284,6 +3294,27 @@ static void dw_hdmi_init_hw(struct dw_hdmi *hdmi)
|
||||
hdmi->phy.ops->setup_hpd(hdmi, hdmi->phy.data);
|
||||
}
|
||||
|
||||
static int hdmi_light_notify(struct notifier_block *notify_block,
|
||||
unsigned long mode, void *unused)
|
||||
{
|
||||
printk(KERN_INFO"pm_notify: mode (%ld)\n", mode);
|
||||
|
||||
switch (mode) {
|
||||
case PM_HIBERNATION_PREPARE:
|
||||
printk(KERN_INFO"hdmi_pm_notify PM_HIBERNATION_PREPARE\n");
|
||||
g_is_hdmi_std_suspend = true;
|
||||
break;
|
||||
case PM_POST_HIBERNATION:
|
||||
printk(KERN_INFO"hdmi_pm_notify PM_HIBERNATION_PREPARE\n");
|
||||
g_is_hdmi_std_suspend = false;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return NOTIFY_DONE;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Probe/remove API, used from platforms based on the DRM bridge API.
|
||||
*/
|
||||
@@ -3551,6 +3582,13 @@ struct dw_hdmi *dw_hdmi_probe(struct platform_device *pdev,
|
||||
|
||||
drm_bridge_add(&hdmi->bridge);
|
||||
|
||||
if (IS_ENABLED(CONFIG_PM))
|
||||
hdmi->pm_notify.notifier_call = hdmi_light_notify;
|
||||
|
||||
ret = register_pm_notifier(&hdmi->pm_notify);
|
||||
if (ret)
|
||||
printk(KERN_ERR"register_pm_notifier failed: %d\n", ret);
|
||||
|
||||
return hdmi;
|
||||
|
||||
err_res:
|
||||
@@ -3562,6 +3600,8 @@ EXPORT_SYMBOL_GPL(dw_hdmi_probe);
|
||||
|
||||
void dw_hdmi_remove(struct dw_hdmi *hdmi)
|
||||
{
|
||||
unregister_pm_notifier(&hdmi->pm_notify);
|
||||
|
||||
drm_bridge_remove(&hdmi->bridge);
|
||||
|
||||
if (hdmi->audio && !IS_ERR(hdmi->audio))
|
||||
|
||||
@@ -557,4 +557,13 @@ config DRM_PANEL_HX8279
|
||||
Say Y if you want to enable support for panels based on the
|
||||
HX8279 controller.
|
||||
|
||||
config DRM_PANEL_LT8911
|
||||
tristate "LT8911-based panels"
|
||||
depends on OF
|
||||
depends on DRM_MIPI_DSI
|
||||
depends on BACKLIGHT_CLASS_DEVICE
|
||||
help
|
||||
Say Y if you want to enable support for panels based on the
|
||||
lt8911 controller.
|
||||
|
||||
endmenu
|
||||
|
||||
@@ -59,3 +59,4 @@ obj-$(CONFIG_DRM_PANEL_HX8394) += panel-himax8394.o
|
||||
obj-$(CONFIG_DRM_PANEL_JADARD_JD9365DA_H3) += panel-jadard-jd9365da-h3.o
|
||||
obj-$(CONFIG_DRM_PANEL_MINGJUN_070BI30IA2) += panel-mingjun-070bi30ia2.o
|
||||
obj-$(CONFIG_DRM_PANEL_HX8279) += panel-hx8279.o
|
||||
obj-$(CONFIG_DRM_PANEL_LT8911) += panel-lt8911.o
|
||||
|
||||
@@ -212,20 +212,20 @@ static const struct drm_panel_funcs panel_funcs = {
|
||||
};
|
||||
|
||||
static const struct drm_display_mode jadard_default_mode = {
|
||||
.clock = 76000,
|
||||
.hdisplay = 800,
|
||||
.hsync_start = 800 + 32,
|
||||
.hsync_end = 800 + 32 + 8,
|
||||
.htotal = 800 + 32 + 8 + 32,
|
||||
.clock = 152840,
|
||||
.hdisplay = 1920,
|
||||
.hsync_start = 1920 + 140,
|
||||
.hsync_end = 1920 + 140 + 160,
|
||||
.htotal = 1920 + 140 + 160 + 30,
|
||||
|
||||
.vdisplay = 1280,
|
||||
.vsync_start = 1280 + 16,
|
||||
.vsync_end = 1280 + 16 + 8,
|
||||
.vtotal = 1280 + 16 + 8 + 16,
|
||||
.vdisplay = 1080,
|
||||
.vsync_start = 1080 + 18,
|
||||
.vsync_end = 1080 + 18 + 28,
|
||||
.vtotal = 1080 + 18 + 28 + 6,
|
||||
|
||||
.width_mm = 62,
|
||||
.height_mm = 110,
|
||||
.flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC,
|
||||
.width_mm = 110,
|
||||
.height_mm = 62,
|
||||
.flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC,
|
||||
};
|
||||
|
||||
|
||||
|
||||
989
drivers/gpu/drm/panel/panel-lt8911.c
Normal file
989
drivers/gpu/drm/panel/panel-lt8911.c
Normal file
@@ -0,0 +1,989 @@
|
||||
#include "panel-lt8911.h"
|
||||
#include <linux/version.h>
|
||||
#include <linux/of_gpio.h>
|
||||
#include <linux/regulator/consumer.h>
|
||||
|
||||
#define ILI9881_PAGE(_page) DSI_DCS_WRITE(dsi, 0xff, 0x98, 0x81, _page)
|
||||
#define IILI9881_COMMAND(_cmd, _data...) DSI_DCS_WRITE(dsi, _cmd, _data)
|
||||
#define DCS_CMD_READ_ID1 0xDA
|
||||
|
||||
#define LT_8911_I2C_ADAPTER 3
|
||||
#define LT_8911_I2C_ADDR 0x45
|
||||
|
||||
static struct i2c_mipi_dsi g_lt8911_mipi_dsi;
|
||||
static bool g_is_std_suspend __nosavedata;
|
||||
|
||||
static const struct drm_display_mode lt8911_default_mode = {
|
||||
.clock = 152840,
|
||||
.hdisplay = 1920,
|
||||
.hsync_start = 1920 + 140,
|
||||
.hsync_end = 1920 + 140 + 160,
|
||||
.htotal = 1920 + 140 + 160 + 30,
|
||||
|
||||
.vdisplay = 1080,
|
||||
.vsync_start = 1080 + 18,
|
||||
.vsync_end = 1080 + 18 + 28,
|
||||
.vtotal = 1080 + 18 + 28 + 6,
|
||||
|
||||
.width_mm = 110,
|
||||
.height_mm = 62,
|
||||
.flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC,
|
||||
};
|
||||
|
||||
static const struct panel_data lt8911_panel_data = {
|
||||
.display_mode = <8911_default_mode,
|
||||
.mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_LPM | MIPI_DSI_MODE_VIDEO_BURST,
|
||||
.format = MIPI_DSI_FMT_RGB888,
|
||||
.lanes = 4,
|
||||
};
|
||||
|
||||
enum {
|
||||
hfp = 0,
|
||||
hs,
|
||||
hbp,
|
||||
hact,
|
||||
htotal,
|
||||
vfp,
|
||||
vs,
|
||||
vbp,
|
||||
vact,
|
||||
vtotal,
|
||||
pclk_10khz
|
||||
};
|
||||
|
||||
static int mipi_timing[] = {
|
||||
140, /* hfp */
|
||||
30, /* hs */
|
||||
160, /* hbp */
|
||||
1920, /* hact */
|
||||
2250, /* htotal */
|
||||
18, /* vfp */
|
||||
6, /* vs */
|
||||
28, /* vbp */
|
||||
1080, /* vact */
|
||||
1132, /* vtotal */
|
||||
15284 /* pixel_clk / 10000 */
|
||||
};
|
||||
|
||||
static int lt8911_i2c_write(struct i2c_client *client,
|
||||
uint8_t reg, uint8_t val)
|
||||
{
|
||||
int ret = -1;
|
||||
int retries = 0;
|
||||
uint8_t buf[2] = { reg, val };
|
||||
struct i2c_msg msg = {
|
||||
.flags = !I2C_M_RD,
|
||||
.addr = client->addr,
|
||||
.len = 2,
|
||||
.buf = buf,
|
||||
};
|
||||
|
||||
while (retries < 5) {
|
||||
ret = i2c_transfer(client->adapter, &msg, 1);
|
||||
if (ret == 1)
|
||||
return 0;
|
||||
retries++;
|
||||
}
|
||||
|
||||
DBG_FUNC("%s: write addr 0x%02x error! ret = %d\n",
|
||||
__func__, reg, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int lt8911_i2c_read(struct i2c_client *client, uint8_t reg)
|
||||
{
|
||||
int ret = -1;
|
||||
int retries = 0;
|
||||
uint8_t buf[2] = { reg, 0 };
|
||||
struct i2c_msg msgs[2];
|
||||
|
||||
msgs[0].flags = client->flags;
|
||||
msgs[0].addr = client->addr;
|
||||
msgs[0].len = 1;
|
||||
msgs[0].buf = &buf[0];
|
||||
|
||||
msgs[1].flags = client->flags | I2C_M_RD;
|
||||
msgs[1].addr = client->addr;
|
||||
msgs[1].len = 1;
|
||||
msgs[1].buf = &buf[1];
|
||||
|
||||
while (retries < 5) {
|
||||
ret = i2c_transfer(client->adapter, msgs, 2);
|
||||
if (ret == 2)
|
||||
return buf[1];
|
||||
retries++;
|
||||
}
|
||||
|
||||
DBG_FUNC("%s: read addr 0x%02x error! ret = %d\n",
|
||||
__func__, reg, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void lt8911_reset(struct i2c_mipi_dsi *md)
|
||||
{
|
||||
gpio_set_value(md->reset_pin, 0);
|
||||
msleep(md->rst_delay_ms);
|
||||
gpio_set_value(md->reset_pin, 1);
|
||||
msleep(md->rst_delay_ms);
|
||||
}
|
||||
|
||||
static void lt8911exb_cfg_set_mipi_timing(struct i2c_mipi_dsi *md)
|
||||
{
|
||||
struct i2c_client *client = md->client;
|
||||
|
||||
/* lt8911exb MIPI video timing configuration */
|
||||
lt8911_i2c_write(client, 0xff, 0xd0);
|
||||
lt8911_i2c_write(client, 0x0d, (u8)(mipi_timing[vtotal] / 256));
|
||||
lt8911_i2c_write(client, 0x0e, (u8)(mipi_timing[vtotal] % 256));
|
||||
lt8911_i2c_write(client, 0x0f, (u8)(mipi_timing[vact] / 256));
|
||||
lt8911_i2c_write(client, 0x10, (u8)(mipi_timing[vact] % 256));
|
||||
lt8911_i2c_write(client, 0x11, (u8)(mipi_timing[htotal] / 256));
|
||||
lt8911_i2c_write(client, 0x12, (u8)(mipi_timing[htotal] % 256));
|
||||
lt8911_i2c_write(client, 0x13, (u8)(mipi_timing[hact] / 256));
|
||||
lt8911_i2c_write(client, 0x14, (u8)(mipi_timing[hact] % 256));
|
||||
lt8911_i2c_write(client, 0x15, (u8)(mipi_timing[vs] % 256));
|
||||
lt8911_i2c_write(client, 0x16, (u8)(mipi_timing[hs] % 256));
|
||||
lt8911_i2c_write(client, 0x17, (u8)(mipi_timing[vfp] / 256));
|
||||
lt8911_i2c_write(client, 0x18, (u8)(mipi_timing[vfp] % 256));
|
||||
lt8911_i2c_write(client, 0x19, (u8)(mipi_timing[hfp] / 256));
|
||||
lt8911_i2c_write(client, 0x1a, (u8)(mipi_timing[hfp] % 256));
|
||||
}
|
||||
|
||||
static void lt8911exb_cfg_set_edp_timing(struct i2c_mipi_dsi *md)
|
||||
{
|
||||
struct i2c_client *client = md->client;
|
||||
|
||||
/* lt8911exb eDP video timing configuration */
|
||||
lt8911_i2c_write(client, 0xff, 0xa8);
|
||||
lt8911_i2c_write(client, 0x2d, 0x88);
|
||||
lt8911_i2c_write(client, 0x05,
|
||||
(u8)(mipi_timing[htotal] / 256));
|
||||
lt8911_i2c_write(client, 0x06,
|
||||
(u8)(mipi_timing[htotal] % 256));
|
||||
lt8911_i2c_write(client, 0x07,
|
||||
(u8)((mipi_timing[hs] + mipi_timing[hbp]) / 256));
|
||||
lt8911_i2c_write(client, 0x08,
|
||||
(u8)((mipi_timing[hs] + mipi_timing[hbp]) % 256));
|
||||
lt8911_i2c_write(client, 0x09,
|
||||
(u8)(mipi_timing[hs] / 256));
|
||||
lt8911_i2c_write(client, 0x0a,
|
||||
(u8)(mipi_timing[hs] % 256));
|
||||
lt8911_i2c_write(client, 0x0b,
|
||||
(u8)(mipi_timing[hact] / 256));
|
||||
lt8911_i2c_write(client, 0x0c,
|
||||
(u8)(mipi_timing[hact] % 256));
|
||||
lt8911_i2c_write(client, 0x0d,
|
||||
(u8)(mipi_timing[vtotal] / 256));
|
||||
lt8911_i2c_write(client, 0x0e,
|
||||
(u8)(mipi_timing[vtotal] % 256));
|
||||
lt8911_i2c_write(client, 0x11,
|
||||
(u8)((mipi_timing[vs] + mipi_timing[vbp]) / 256));
|
||||
lt8911_i2c_write(client, 0x12,
|
||||
(u8)((mipi_timing[vs] + mipi_timing[vbp]) % 256));
|
||||
lt8911_i2c_write(client, 0x14,
|
||||
(u8)(mipi_timing[vs] % 256));
|
||||
lt8911_i2c_write(client, 0x15,
|
||||
(u8)(mipi_timing[vact] / 256));
|
||||
lt8911_i2c_write(client, 0x16,
|
||||
(u8)(mipi_timing[vact] % 256));
|
||||
}
|
||||
|
||||
static void lt8911exb_cfg_init_regs(struct i2c_mipi_dsi *md)
|
||||
{
|
||||
u32 val = 0;
|
||||
u8 i, pcr_pll_postdiv, pcr_m;
|
||||
struct i2c_client *client = md->client;
|
||||
u8 swing_ds1[13][2] = {
|
||||
{ 0x83, 0x00 }, /* 27.8 mA */
|
||||
{ 0x82, 0xe0 }, /* 26.2 mA */
|
||||
{ 0x82, 0xc0 }, /* 24.6 mA */
|
||||
{ 0x82, 0xa0 }, /* 23.0 mA */
|
||||
{ 0x82, 0x80 }, /* 21.4 mA */
|
||||
{ 0x82, 0x40 }, /* 18.2 mA */
|
||||
{ 0x82, 0x20 }, /* 16.6 mA */
|
||||
{ 0x82, 0x00 }, /* 15.0 mA */
|
||||
{ 0x81, 0x00 }, /* 12.8 mA */
|
||||
{ 0x80, 0xe0 }, /* 11.2 mA */
|
||||
{ 0x80, 0xc0 }, /* 9.6 mA */
|
||||
{ 0x80, 0xa0 }, /* 8 mA */
|
||||
{ 0x80, 0x80 } /* 6 mA */
|
||||
};
|
||||
|
||||
/* initialization */
|
||||
lt8911_i2c_write(client, 0xff, 0x81);
|
||||
lt8911_i2c_write(client, 0x49, 0xff);
|
||||
lt8911_i2c_write(client, 0xff, 0x82);
|
||||
lt8911_i2c_write(client, 0x5a, 0x0e);
|
||||
|
||||
/* MIPI Rx analog */
|
||||
lt8911_i2c_write(client, 0xff, 0x82);
|
||||
lt8911_i2c_write(client, 0x32, 0x51);
|
||||
lt8911_i2c_write(client, 0x35, 0x22);
|
||||
lt8911_i2c_write(client, 0x4c, 0x0c);
|
||||
lt8911_i2c_write(client, 0x4d, 0x00);
|
||||
|
||||
lt8911_i2c_write(client, 0x3a, 0x77);
|
||||
lt8911_i2c_write(client, 0x3b, 0x77);
|
||||
|
||||
/* dessc_pcr pll analog */
|
||||
lt8911_i2c_write(client, 0xff, 0x82);
|
||||
lt8911_i2c_write(client, 0x6a, 0x40);
|
||||
lt8911_i2c_write(client, 0x6b, 0x40);
|
||||
|
||||
if (mipi_timing[pclk_10khz] < 8800) {
|
||||
/* 0x44: pre-div = 2, pixel_clk = 44~88MHz */
|
||||
lt8911_i2c_write(client, 0x6e, 0x82);
|
||||
pcr_pll_postdiv = 0x08;
|
||||
} else {
|
||||
/* 0x40: pre-div = 1, pixel_clk = 88~176MHz */
|
||||
lt8911_i2c_write(client, 0x6e, 0x81);
|
||||
pcr_pll_postdiv = 0x04;
|
||||
}
|
||||
pcr_m = (u8)(mipi_timing[pclk_10khz] * pcr_pll_postdiv / 25 / 100);
|
||||
|
||||
/* dessc pll digital */
|
||||
lt8911_i2c_write(client, 0xff, 0x85);
|
||||
lt8911_i2c_write(client, 0xa9, 0x31);
|
||||
lt8911_i2c_write(client, 0xaa, 0x17);
|
||||
lt8911_i2c_write(client, 0xab, 0xba);
|
||||
lt8911_i2c_write(client, 0xac, 0xe1);
|
||||
lt8911_i2c_write(client, 0xad, 0x47);
|
||||
lt8911_i2c_write(client, 0xae, 0x01);
|
||||
lt8911_i2c_write(client, 0xae, 0x11);
|
||||
|
||||
/* digital top */
|
||||
lt8911_i2c_write(client, 0xff, 0x85);
|
||||
lt8911_i2c_write(client, 0xc0, 0x01);/* select mipi rx */
|
||||
|
||||
if (md->edp_depth == 6)
|
||||
val = 0xd0; /* enable dither */
|
||||
else if (md->edp_depth == 8)
|
||||
val = 0x00; /* disable dither */
|
||||
lt8911_i2c_write(client, 0xb0, val);
|
||||
|
||||
/* MIPI Rx digital */
|
||||
lt8911_i2c_write(client, 0xff, 0xd0);
|
||||
/* 0: 4 lane; 1: 1 lane; 2: 2 lane; 3: 3 lane */
|
||||
lt8911_i2c_write(client, 0x00, md->mipi_lane_cnt % 4);
|
||||
lt8911_i2c_write(client, 0x02, 0x08);
|
||||
lt8911_i2c_write(client, 0x08, 0x00);
|
||||
lt8911_i2c_write(client, 0x0a, 0x12);/* pcr mode */
|
||||
lt8911_i2c_write(client, 0x0c, 0x40);
|
||||
|
||||
lt8911_i2c_write(client, 0x1c, 0x3a);
|
||||
lt8911_i2c_write(client, 0x31, 0x0a);
|
||||
|
||||
lt8911_i2c_write(client, 0x3f, 0x10);
|
||||
lt8911_i2c_write(client, 0x40, 0x20);
|
||||
lt8911_i2c_write(client, 0x41, 0x30);
|
||||
|
||||
#ifdef TEST_PATTERN
|
||||
lt8911_i2c_write(client, 0x26, pcr_m | 0x80);
|
||||
#else
|
||||
lt8911_i2c_write(client, 0x26, pcr_m);
|
||||
#endif
|
||||
|
||||
lt8911_i2c_write(client, 0x27, 0x28);
|
||||
lt8911_i2c_write(client, 0x28, 0xf8);
|
||||
|
||||
lt8911_i2c_write(client, 0xff, 0x81);/* pcr reset */
|
||||
lt8911_i2c_write(client, 0x03, 0x7b);
|
||||
lt8911_i2c_write(client, 0x03, 0xff);
|
||||
|
||||
/* Tx PLL 2.7GHz */
|
||||
lt8911_i2c_write(client, 0xff, 0x87);
|
||||
lt8911_i2c_write(client, 0x19, 0x31);
|
||||
lt8911_i2c_write(client, 0xff, 0x82);
|
||||
lt8911_i2c_write(client, 0x02, 0x42);
|
||||
lt8911_i2c_write(client, 0x03, 0x00);
|
||||
lt8911_i2c_write(client, 0x03, 0x01);
|
||||
lt8911_i2c_write(client, 0xff, 0x81);
|
||||
lt8911_i2c_write(client, 0x09, 0xfc);
|
||||
lt8911_i2c_write(client, 0x09, 0xfd);
|
||||
lt8911_i2c_write(client, 0xff, 0x87);
|
||||
lt8911_i2c_write(client, 0x0c, 0x11);
|
||||
|
||||
for (i = 0; i < 5; i++) {
|
||||
msleep(5);
|
||||
if (lt8911_i2c_read(client, 0x37) & 0x02) {
|
||||
DBG_FUNC("%s: lt8911exb tx pll locked\n",
|
||||
__func__);
|
||||
break;
|
||||
}
|
||||
|
||||
DBG_FUNC("%s: lt8911exb tx pll unlocked\n", __func__);
|
||||
lt8911_i2c_write(client, 0xff, 0x81);
|
||||
lt8911_i2c_write(client, 0x09, 0xfc);
|
||||
lt8911_i2c_write(client, 0x09, 0xfd);
|
||||
lt8911_i2c_write(client, 0xff, 0x87);
|
||||
lt8911_i2c_write(client, 0x0c, 0x10);
|
||||
lt8911_i2c_write(client, 0x0c, 0x11);
|
||||
}
|
||||
|
||||
/* Tx PHY */
|
||||
lt8911_i2c_write(client, 0xff, 0x82);
|
||||
lt8911_i2c_write(client, 0x11, 0x00);
|
||||
lt8911_i2c_write(client, 0x13, 0x10);
|
||||
lt8911_i2c_write(client, 0x14, 0x0c);
|
||||
lt8911_i2c_write(client, 0x14, 0x08);
|
||||
lt8911_i2c_write(client, 0x13, 0x20);
|
||||
lt8911_i2c_write(client, 0xff, 0x82);
|
||||
lt8911_i2c_write(client, 0x0e, 0x25);
|
||||
lt8911_i2c_write(client, 0x12, 0xff);
|
||||
|
||||
/* eDP tx digital */
|
||||
lt8911_i2c_write(client, 0xff, 0xa8);
|
||||
|
||||
#ifdef TEST_PATTERN
|
||||
/* bit[2:0]: test panttern image mode */
|
||||
lt8911_i2c_write(client, 0x24, 0x50);
|
||||
/* bit[6:4]: test pattern color */
|
||||
lt8911_i2c_write(client, 0x25, 0x70);
|
||||
/* 0x50: pattern; 0x10: mipi video */
|
||||
lt8911_i2c_write(client, 0x27, 0x50);
|
||||
#else
|
||||
/* 0x50: pattern; 0x10: mipi video */
|
||||
lt8911_i2c_write(client, 0x27, 0x10);
|
||||
#endif
|
||||
|
||||
if (md->edp_depth == 6)
|
||||
val = 0x00;
|
||||
else if (md->edp_depth == 8)
|
||||
val = 0x10;
|
||||
lt8911_i2c_write(client, 0x17, val);
|
||||
lt8911_i2c_write(client, 0x18, val << 1);
|
||||
|
||||
lt8911_i2c_write(client, 0xff, 0xa0);
|
||||
lt8911_i2c_write(client, 0x00, 0x08);
|
||||
lt8911_i2c_write(client, 0x01, 0x00);
|
||||
|
||||
/* set eDP drive strength */
|
||||
lt8911_i2c_write(client, 0xff, 0x82);
|
||||
/* lane 0 tap0 */
|
||||
lt8911_i2c_write(client, 0x22, swing_ds1[0][0]);
|
||||
lt8911_i2c_write(client, 0x23, swing_ds1[0][1]);
|
||||
/* lane 0 tap1 */
|
||||
lt8911_i2c_write(client, 0x24, 0x80);
|
||||
lt8911_i2c_write(client, 0x25, 0x00);
|
||||
/* lane 1 tap0 */
|
||||
lt8911_i2c_write(client, 0x26, swing_ds1[0][0]);
|
||||
lt8911_i2c_write(client, 0x27, swing_ds1[0][1]);
|
||||
/* lane 1 tap1 */
|
||||
lt8911_i2c_write(client, 0x28, 0x80);
|
||||
lt8911_i2c_write(client, 0x29, 0x00);
|
||||
}
|
||||
|
||||
/*
|
||||
* MIPI signal from SoC should be ready before
|
||||
* configuring below video check setting
|
||||
*/
|
||||
static void lt8911exb_dbg_check_mipi_timing(struct i2c_mipi_dsi *md)
|
||||
{
|
||||
u32 val = 0;
|
||||
struct i2c_client *client = md->client;
|
||||
|
||||
/* MIPI byte clk check */
|
||||
lt8911_i2c_write(client, 0xff, 0x85);
|
||||
/* FM select byte clk */
|
||||
lt8911_i2c_write(client, 0x1d, 0x00);
|
||||
lt8911_i2c_write(client, 0x40, 0xf7);
|
||||
lt8911_i2c_write(client, 0x41, 0x30);
|
||||
/* eDP scramble mode; video chech from mipi */
|
||||
lt8911_i2c_write(client, 0xa1, 0x02);
|
||||
/* 0xf0: close scramble; 0xD0: open scramble */
|
||||
//lt8911_i2c_write(client, 0x17, 0xf0);
|
||||
|
||||
/* video check reset */
|
||||
lt8911_i2c_write(client, 0xff, 0x81);
|
||||
lt8911_i2c_write(client, 0x09, 0x7d);
|
||||
lt8911_i2c_write(client, 0x09, 0xfd);
|
||||
|
||||
lt8911_i2c_write(client, 0xff, 0x85);
|
||||
//msleep(200);
|
||||
msleep(10);
|
||||
if (lt8911_i2c_read(client, 0x50) == 0x03) {
|
||||
val = lt8911_i2c_read(client, 0x4d);
|
||||
val = (val << 8) + lt8911_i2c_read(client, 0x4e);
|
||||
val = (val << 8) + lt8911_i2c_read(client, 0x4f);
|
||||
/* MIPI clk = val * 1000 */
|
||||
DBG_FUNC("%s: video check: mipi clk = %d\n",
|
||||
__func__, val);
|
||||
} else {
|
||||
DBG_FUNC("%s: video check: mipi clk unstable",
|
||||
__func__);
|
||||
}
|
||||
|
||||
/* MIPI Vtotal check */
|
||||
val = lt8911_i2c_read(client, 0x76);
|
||||
val = (val << 8) + lt8911_i2c_read(client, 0x77);
|
||||
DBG_FUNC("%s: video check: Vtotal = %d\n",
|
||||
__func__, val);
|
||||
|
||||
/* MIPI word count check */
|
||||
lt8911_i2c_write(client, 0xff, 0xd0);
|
||||
val = lt8911_i2c_read(client, 0x82);
|
||||
val = (val << 8) + lt8911_i2c_read(client, 0x83);
|
||||
val = val / 3;
|
||||
DBG_FUNC("%s: video check: Hact(word counter) = %d\n",
|
||||
__func__, val);
|
||||
|
||||
/* MIPI Vact check */
|
||||
val = lt8911_i2c_read(client, 0x85);
|
||||
val = (val << 8) + lt8911_i2c_read(client, 0x86);
|
||||
DBG_FUNC("%s: video check: Vact = %d\n",
|
||||
__func__, val);
|
||||
}
|
||||
|
||||
static void lt8911exb_link_train_start(struct i2c_mipi_dsi *md)
|
||||
{
|
||||
struct i2c_client *client = md->client;
|
||||
|
||||
/* lt8911exb link training */
|
||||
lt8911_i2c_write(client, 0xff, 0x85);
|
||||
/* eDP scramble mode */
|
||||
lt8911_i2c_write(client, 0xa1, 0x02);
|
||||
|
||||
/* AUX setup */
|
||||
lt8911_i2c_write(client, 0xff, 0xac);
|
||||
/* soft link training */
|
||||
lt8911_i2c_write(client, 0x00, 0x60);
|
||||
lt8911_i2c_write(client, 0xff, 0xa6);
|
||||
lt8911_i2c_write(client, 0x2a, 0x00);
|
||||
|
||||
lt8911_i2c_write(client, 0xff, 0x81);
|
||||
lt8911_i2c_write(client, 0x07, 0xfe);
|
||||
lt8911_i2c_write(client, 0x07, 0xff);
|
||||
lt8911_i2c_write(client, 0x0a, 0xfc);
|
||||
lt8911_i2c_write(client, 0x0a, 0xfe);
|
||||
|
||||
/* link training */
|
||||
lt8911_i2c_write(client, 0xff, 0x85);
|
||||
lt8911_i2c_write(client, 0x1a, md->edp_lane_cnt);
|
||||
//lt8911_i2c_write(client, 0x13, 0xd1);
|
||||
lt8911_i2c_write(client, 0xff, 0xac);
|
||||
lt8911_i2c_write(client, 0x00, 0x64);
|
||||
lt8911_i2c_write(client, 0x01, 0x0a);
|
||||
lt8911_i2c_write(client, 0x0c, 0x85);
|
||||
lt8911_i2c_write(client, 0x0c, 0xc5);
|
||||
}
|
||||
|
||||
static void lt8911exb_link_train_get_result(struct i2c_mipi_dsi *md)
|
||||
{
|
||||
u32 i, val;
|
||||
struct i2c_client *client = md->client;
|
||||
|
||||
lt8911_i2c_write(client, 0xff, 0xac);
|
||||
for (i = 0; i < 10; i++) {
|
||||
val = lt8911_i2c_read(client, 0x82);
|
||||
if (val & 0x20) {
|
||||
if ((val & 0x1f) == 0x1e)
|
||||
DBG_FUNC("%s: link training succeeded\n",
|
||||
__func__);
|
||||
else
|
||||
DBG_FUNC("%s: link training failed\n",
|
||||
__func__);
|
||||
|
||||
DBG_FUNC("%s: panel link rate: %d\n", __func__,
|
||||
lt8911_i2c_read(client, 0x83));
|
||||
DBG_FUNC("%s: panel link count: %d\n", __func__,
|
||||
lt8911_i2c_read(client, 0x84));
|
||||
break;
|
||||
}
|
||||
DBG_FUNC("%s: link training ongoing...\n", __func__);
|
||||
msleep(100);
|
||||
}
|
||||
}
|
||||
|
||||
/* panel_funcs */
|
||||
static int panel_prepare(struct drm_panel *panel)
|
||||
{
|
||||
int ret = 0;
|
||||
struct i2c_mipi_dsi *md = panel_to_md(panel);
|
||||
struct i2c_client *client = md->client;
|
||||
|
||||
DBG_FUNC("lt8911exb enter\n");
|
||||
|
||||
if(g_is_std_suspend){
|
||||
DBG_FUNC("lt8911exb prepare under std mode, do not prepare\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(md->client == NULL){
|
||||
DBG_FUNC("lt8911exb i2c client still not ready\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = regulator_enable(md->vspn3v3);
|
||||
if(ret){
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = regulator_enable(md->hsvcc);
|
||||
if(ret){
|
||||
goto fail;
|
||||
}
|
||||
|
||||
//msleep(200);
|
||||
msleep(10);
|
||||
|
||||
lt8911_reset(md);
|
||||
|
||||
lt8911_i2c_write(client, 0xff, 0x81); /* 0x81: register bank */
|
||||
lt8911_i2c_write(client, 0x08, 0x7f);
|
||||
|
||||
DBG_FUNC("%s: lt8911exb chip ID: 0x%02x-0x%02x-0x%02x\n",
|
||||
__func__, lt8911_i2c_read(client, 0x00),
|
||||
lt8911_i2c_read(client, 0x01),
|
||||
lt8911_i2c_read(client, 0x02));
|
||||
|
||||
return 0;
|
||||
|
||||
fail:
|
||||
gpio_set_value(md->reset_pin, 0);
|
||||
regulator_disable(md->hsvcc);
|
||||
regulator_disable(md->vspn3v3);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int panel_unprepare(struct drm_panel *panel)
|
||||
{
|
||||
int ret = 0;
|
||||
struct i2c_mipi_dsi *md = panel_to_md(panel);
|
||||
|
||||
DBG_FUNC("panel_unprepare enter\n");
|
||||
gpio_set_value(md->reset_pin, 0);
|
||||
|
||||
regulator_disable(md->hsvcc);
|
||||
regulator_disable(md->vspn3v3);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int panel_enable(struct drm_panel *panel)
|
||||
{
|
||||
int ret = 0;
|
||||
struct i2c_mipi_dsi *md = panel_to_md(panel);
|
||||
|
||||
DBG_FUNC("panel_enable enter\n");
|
||||
|
||||
if(g_is_std_suspend){
|
||||
DBG_FUNC("lt8911exb enable under std mode, do not enable\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
gpio_set_value(md->backlight_pin, 1);
|
||||
|
||||
lt8911exb_cfg_set_mipi_timing(md);
|
||||
lt8911exb_cfg_set_edp_timing(md);
|
||||
lt8911exb_cfg_init_regs(md);
|
||||
lt8911exb_dbg_check_mipi_timing(md);
|
||||
lt8911exb_link_train_start(md);
|
||||
lt8911exb_link_train_get_result(md);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int panel_disable(struct drm_panel *panel)
|
||||
{
|
||||
int ret = 0;
|
||||
struct i2c_mipi_dsi *md = panel_to_md(panel);
|
||||
|
||||
DBG_FUNC("panel_disable enter\n");
|
||||
|
||||
gpio_set_value(md->backlight_pin, 0);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int panel_get_modes(struct drm_panel *panel, struct drm_connector *connector)
|
||||
{
|
||||
struct i2c_mipi_dsi *md = panel_to_md(panel);
|
||||
const struct drm_display_mode *m = md->desc->display_mode;
|
||||
struct drm_display_mode *mode;
|
||||
|
||||
DBG_FUNC("panel_get_modes enter\n");
|
||||
|
||||
mode = drm_mode_duplicate(connector->dev, m);
|
||||
if (!mode) {
|
||||
/*
|
||||
dev_err(pinfo->base.dev, "failed to add mode %ux%u@%u\n",
|
||||
m->hdisplay, m->vdisplay, drm_mode_vrefresh(m));
|
||||
*/
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
drm_mode_set_name(mode);
|
||||
|
||||
mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
|
||||
drm_mode_probed_add(connector, mode);
|
||||
|
||||
connector->display_info.width_mm = mode->width_mm;
|
||||
connector->display_info.height_mm = mode->height_mm;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const struct drm_panel_funcs panel_funcs = {
|
||||
.prepare = panel_prepare,
|
||||
.unprepare = panel_unprepare,
|
||||
.enable = panel_enable,
|
||||
.disable = panel_disable,
|
||||
.get_modes = panel_get_modes,
|
||||
};
|
||||
|
||||
/* backlight */
|
||||
static int backlight_update(struct backlight_device *bd)
|
||||
{
|
||||
struct i2c_mipi_dsi *md = bl_get_data(bd);
|
||||
int brightness = bd->props.brightness;
|
||||
|
||||
if (bd->props.power != FB_BLANK_UNBLANK ||
|
||||
bd->props.fb_blank != FB_BLANK_UNBLANK ||
|
||||
(bd->props.state & (BL_CORE_SUSPENDED | BL_CORE_FBBLANK))) {
|
||||
brightness = 0;
|
||||
}
|
||||
|
||||
md->brightness = brightness;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct backlight_ops backlight_ops = {
|
||||
.options = BL_CORE_SUSPENDRESUME,
|
||||
.update_status = backlight_update,
|
||||
};
|
||||
|
||||
static int lt8911_pm_notify(struct notifier_block *notify_block,
|
||||
unsigned long mode, void *unused)
|
||||
{
|
||||
struct i2c_mipi_dsi *ctx = container_of(
|
||||
notify_block, struct i2c_mipi_dsi, pm_notify);
|
||||
|
||||
DBG_FUNC("pm_notify: mode (%ld)\n", mode);
|
||||
|
||||
switch (mode) {
|
||||
case PM_HIBERNATION_PREPARE:
|
||||
DBG_FUNC("pm_notify PM_HIBERNATION_PREPARE\n");
|
||||
g_is_std_suspend = true;
|
||||
break;
|
||||
case PM_POST_HIBERNATION:
|
||||
DBG_FUNC("pm_notify PM_HIBERNATION_PREPARE\n");
|
||||
g_is_std_suspend = false;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return NOTIFY_DONE;
|
||||
}
|
||||
|
||||
/**
|
||||
static int backlight_init(struct i2c_mipi_dsi *md)
|
||||
{
|
||||
struct device *dev = &md->client->dev;
|
||||
struct backlight_properties props;
|
||||
struct backlight_device *bd;
|
||||
|
||||
printk(KERN_ERR "=====Function %s line %d\n", __FUNCTION__, __LINE__);
|
||||
|
||||
memset(&props, 0, sizeof(props));
|
||||
props.type = BACKLIGHT_RAW;
|
||||
props.max_brightness = 255;
|
||||
bd = devm_backlight_device_register(dev, dev_name(dev),
|
||||
dev, md, &backlight_ops,
|
||||
&props);
|
||||
if (IS_ERR(bd)) {
|
||||
dev_err(dev, "failed to register backlight\n");
|
||||
return PTR_ERR(bd);
|
||||
}
|
||||
|
||||
bd->props.brightness = 255;
|
||||
backlight_update_status(bd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
static int i2c_md_probe(struct i2c_client *client, const struct i2c_device_id *id)
|
||||
{
|
||||
struct device *dev = &client->dev;
|
||||
struct i2c_mipi_dsi *md = &g_lt8911_mipi_dsi;
|
||||
|
||||
DBG_FUNC("start");
|
||||
|
||||
i2c_set_clientdata(client, md);
|
||||
mutex_init(&md->mutex);
|
||||
md->client = client;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int i2c_md_remove(struct i2c_client *i2c)
|
||||
{
|
||||
struct i2c_mipi_dsi *md = i2c_get_clientdata(i2c);
|
||||
|
||||
DBG_FUNC();
|
||||
|
||||
mipi_dsi_detach(md->dsi);
|
||||
drm_panel_remove(&md->panel);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void i2c_md_shutdown(struct i2c_client *i2c)
|
||||
{
|
||||
struct i2c_mipi_dsi *md = i2c_get_clientdata(i2c);
|
||||
|
||||
DBG_FUNC();
|
||||
|
||||
mipi_dsi_detach(md->dsi);
|
||||
drm_panel_remove(&md->panel);
|
||||
}
|
||||
|
||||
static int lt8911_parse_dt(struct i2c_mipi_dsi *md)
|
||||
{
|
||||
int ret = -1;
|
||||
struct mipi_dsi_device *dsi = md->dsi;
|
||||
struct device_node *np = dsi->dev.of_node;
|
||||
|
||||
md->hsvcc = devm_regulator_get(&dsi->dev, "hsvcc");
|
||||
if (IS_ERR(md->hsvcc))
|
||||
return dev_err_probe(&dsi->dev, PTR_ERR(md->hsvcc),
|
||||
"Failed to request hsvcc regulator\n");
|
||||
|
||||
md->vspn3v3 = devm_regulator_get(&dsi->dev, "vspn3v3");
|
||||
if (IS_ERR(md->vspn3v3))
|
||||
return dev_err_probe(&dsi->dev, PTR_ERR(md->vspn3v3),
|
||||
"Failed to request vspn3v3 regulator\n");
|
||||
|
||||
md->backlight_pin = of_get_named_gpio_flags(np,
|
||||
"lt8911,backlight-gpio",
|
||||
0, NULL);
|
||||
if (!gpio_is_valid(md->backlight_pin)) {
|
||||
DBG_FUNC("%s: backlight-gpio is invalid\n", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = devm_gpio_request_one(&dsi->dev,
|
||||
md->backlight_pin,
|
||||
GPIOF_DIR_OUT, NULL);
|
||||
if (ret) {
|
||||
DBG_FUNC("%s: failed to request backlight gpio\n",
|
||||
__func__);
|
||||
return ret;
|
||||
}
|
||||
gpio_set_value(md->backlight_pin, 0);
|
||||
DBG_FUNC("%s: succeed to init backlight gpio\n", __func__);
|
||||
|
||||
md->irq_pin = of_get_named_gpio_flags(np,
|
||||
"lt8911,irq-gpio", 0, NULL);
|
||||
if (!gpio_is_valid(md->irq_pin)) {
|
||||
DBG_FUNC("%s: irq-gpio is invalid\n", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = devm_gpio_request_one(&dsi->dev,
|
||||
md->irq_pin,
|
||||
GPIOF_DIR_IN, NULL);
|
||||
if (ret) {
|
||||
DBG_FUNC("%s: failed to request irq gpio\n",
|
||||
__func__);
|
||||
return ret;
|
||||
}
|
||||
DBG_FUNC("%s: succeed to init irq gpio\n", __func__);
|
||||
|
||||
ret = of_property_read_u32(np, "lt8911,rst-delay-ms",
|
||||
&md->rst_delay_ms);
|
||||
if (ret < 0) {
|
||||
DBG_FUNC("%s: no rst-delay-ms property in dts\n",
|
||||
__func__);
|
||||
md->rst_delay_ms = 100;
|
||||
}
|
||||
|
||||
md->reset_pin = of_get_named_gpio_flags(np,
|
||||
"lt8911,reset-gpio", 0, NULL);
|
||||
if (!gpio_is_valid(md->reset_pin)) {
|
||||
DBG_FUNC("%s: reset-gpio is invalid\n", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = devm_gpio_request_one(&dsi->dev,
|
||||
md->reset_pin,
|
||||
GPIOF_DIR_OUT, NULL);
|
||||
if (ret) {
|
||||
DBG_FUNC("%s: failed to request reset gpio\n",
|
||||
__func__);
|
||||
return ret;
|
||||
}
|
||||
gpio_set_value(md->reset_pin, 0);
|
||||
DBG_FUNC("%s: succeed to init reset gpio\n", __func__);
|
||||
|
||||
if (of_property_read_u32(np, "lt8911,edp-lane-cnt",
|
||||
&md->edp_lane_cnt)) {
|
||||
DBG_FUNC("%s: miss edp-lane-cnt property in dts\n",
|
||||
__func__);
|
||||
md->edp_lane_cnt = 2; /* default value */
|
||||
}
|
||||
|
||||
if (of_property_read_u32(np, "lt8911,mipi-lane-cnt",
|
||||
&md->mipi_lane_cnt)) {
|
||||
DBG_FUNC("%s: miss mipi-lane-cnt property in dts\n",
|
||||
__func__);
|
||||
md->mipi_lane_cnt = 4;
|
||||
}
|
||||
|
||||
/*
|
||||
* eDP panel color depth:
|
||||
* 6 bit: 262K colors
|
||||
* 8 bit: 16.7M colors
|
||||
*/
|
||||
if (of_property_read_u32(np, "lt8911,edp-depth",
|
||||
&md->edp_depth)) {
|
||||
DBG_FUNC("%s: miss edp-depth property in dts\n",
|
||||
__func__);
|
||||
md->edp_depth = 8;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const struct of_device_id i2c_md_of_ids[] = {
|
||||
{
|
||||
.compatible = "i2c,lt8911",
|
||||
},
|
||||
{ }
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, i2c_md_of_ids);
|
||||
|
||||
#ifdef CONFIG_PM_SLEEP
|
||||
|
||||
static int edpi2c_suspend(struct device *dev)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int edpi2c_resume(struct device *dev)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct dev_pm_ops edpi2c_pm_ops = {
|
||||
SET_LATE_SYSTEM_SLEEP_PM_OPS(edpi2c_suspend,
|
||||
edpi2c_resume)
|
||||
};
|
||||
|
||||
#define EDPI2C_PM_OPS &edpi2c_pm_ops
|
||||
|
||||
#else
|
||||
|
||||
#define EDPI2C_PM_OPS NULL
|
||||
|
||||
#endif
|
||||
|
||||
static struct i2c_driver i2c_md_driver = {
|
||||
.driver = {
|
||||
.name = "i2c_mipi_dsi",
|
||||
.pm = EDPI2C_PM_OPS,
|
||||
.of_match_table = i2c_md_of_ids,
|
||||
},
|
||||
.probe = i2c_md_probe,
|
||||
.remove = i2c_md_remove,
|
||||
.shutdown = i2c_md_shutdown,
|
||||
};
|
||||
|
||||
module_i2c_driver(i2c_md_driver);
|
||||
|
||||
static int lt8911_dsi_probe(struct mipi_dsi_device *dsi)
|
||||
{
|
||||
int ret;
|
||||
struct i2c_mipi_dsi *ctx;
|
||||
|
||||
ctx = &g_lt8911_mipi_dsi;
|
||||
|
||||
if(ctx == NULL){
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
if(ctx->client == NULL){
|
||||
return -EPROBE_DEFER;
|
||||
}
|
||||
|
||||
g_is_std_suspend = false;
|
||||
|
||||
ctx->dsi = dsi;
|
||||
ctx->desc = <8911_panel_data;
|
||||
ret = lt8911_parse_dt(ctx);
|
||||
if (ret) {
|
||||
DBG_FUNC("%s: failed to parse device tree\n", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
dsi->mode_flags = ctx->desc->mode_flags;
|
||||
dsi->format = ctx->desc->format;
|
||||
dsi->lanes = ctx->desc->lanes;
|
||||
|
||||
mipi_dsi_set_drvdata(dsi, ctx);
|
||||
|
||||
//ctx->panel_data->set_dsi(ctx->dsi);
|
||||
drm_panel_init(&ctx->panel, &dsi->dev, &panel_funcs, DRM_MODE_CONNECTOR_DSI);
|
||||
|
||||
ret = drm_panel_of_backlight(&ctx->panel);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
drm_panel_add(&ctx->panel);
|
||||
|
||||
//backlight_init(ctx);
|
||||
|
||||
if (IS_ENABLED(CONFIG_PM))
|
||||
ctx->pm_notify.notifier_call = lt8911_pm_notify;
|
||||
|
||||
ret = register_pm_notifier(&ctx->pm_notify);
|
||||
if (ret)
|
||||
DBG_FUNC("register_pm_notifier failed: %d\n", ret);
|
||||
|
||||
ret = mipi_dsi_attach(dsi);
|
||||
if (ret < 0)
|
||||
{
|
||||
drm_panel_remove(&ctx->panel);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int lt8911_dsi_remove(struct mipi_dsi_device *dsi)
|
||||
{
|
||||
struct i2c_mipi_dsi *ctx = mipi_dsi_get_drvdata(dsi);
|
||||
|
||||
unregister_pm_notifier(&ctx->pm_notify);
|
||||
|
||||
mipi_dsi_detach(dsi);
|
||||
drm_panel_remove(&ctx->panel);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void lt8911_dsi_shutdown(struct mipi_dsi_device *dsi)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
static const struct of_device_id lt8911_of_match[] = {
|
||||
{.compatible = "i2c_dsi,lt8911", },
|
||||
{ }
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, lt8911_of_match);
|
||||
|
||||
static struct mipi_dsi_driver lt8911_dsi_driver = {
|
||||
.probe = lt8911_dsi_probe,
|
||||
.remove = lt8911_dsi_remove,
|
||||
.shutdown = lt8911_dsi_shutdown,
|
||||
.driver = {
|
||||
.name = "panel-lt8911",
|
||||
.of_match_table = lt8911_of_match,
|
||||
},
|
||||
};
|
||||
module_mipi_dsi_driver(lt8911_dsi_driver);
|
||||
|
||||
MODULE_DESCRIPTION("LT8911 Controller Driver");
|
||||
MODULE_LICENSE("GPL v2");
|
||||
89
drivers/gpu/drm/panel/panel-lt8911.h
Normal file
89
drivers/gpu/drm/panel/panel-lt8911.h
Normal file
@@ -0,0 +1,89 @@
|
||||
#ifndef __MIPI_DSI_H__
|
||||
#define __MIPI_DSI_H__
|
||||
|
||||
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/bitops.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/string.h>
|
||||
|
||||
#include <linux/delay.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/fb.h>
|
||||
#include <linux/gpio.h>
|
||||
#include <linux/gpio/consumer.h>
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/of.h>
|
||||
#include <linux/of_device.h>
|
||||
#include <linux/of_graph.h>
|
||||
#include <linux/pm.h>
|
||||
|
||||
#include <drm/drm_crtc.h>
|
||||
#include <drm/drm_device.h>
|
||||
#include <drm/drm_mipi_dsi.h>
|
||||
#include <drm/drm_panel.h>
|
||||
#include <drm/drm_modes.h>
|
||||
|
||||
#include <video/mipi_display.h>
|
||||
|
||||
|
||||
#if 0
|
||||
#define DBG_FUNC(format, x...) printk(KERN_ERR "[DSI]%s:" format"\n", __func__, ##x)
|
||||
#define DBG_PRINT(format, x...) printk(KERN_ERR "[DSI]" format"\n", ##x)
|
||||
#else
|
||||
#define DBG_FUNC(format, x...)
|
||||
#define DBG_PRINT(format, x...)
|
||||
#endif
|
||||
|
||||
#define DSI_DRIVER_NAME "i2c_mipi_dsi"
|
||||
|
||||
#define DSI_DCS_WRITE(dsi, seq...) \
|
||||
{ \
|
||||
int ret = 0; \
|
||||
const u8 d[] = { seq }; \
|
||||
ret = mipi_dsi_dcs_write_buffer(dsi, d, ARRAY_SIZE(d)); \
|
||||
if (ret < 0) \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
struct panel_data {
|
||||
struct drm_display_mode *display_mode;
|
||||
unsigned long mode_flags;
|
||||
enum mipi_dsi_pixel_format format;
|
||||
unsigned int lanes;
|
||||
};
|
||||
|
||||
struct i2c_mipi_dsi {
|
||||
struct i2c_client *client;
|
||||
struct mutex mutex;
|
||||
|
||||
struct regulator *hsvcc;
|
||||
struct regulator *vspn3v3;
|
||||
|
||||
struct notifier_block pm_notify;
|
||||
|
||||
// panel
|
||||
struct drm_panel panel;
|
||||
struct panel_data *desc;
|
||||
|
||||
// dsi
|
||||
struct mipi_dsi_device *dsi;
|
||||
|
||||
int backlight_pin;
|
||||
int irq_pin;
|
||||
int reset_pin;
|
||||
int enable_pin;
|
||||
int rst_delay_ms;
|
||||
|
||||
u32 edp_lane_cnt;
|
||||
u32 mipi_lane_cnt;
|
||||
u32 edp_depth;
|
||||
|
||||
// backlight
|
||||
int brightness;
|
||||
};
|
||||
|
||||
#define panel_to_md(_p) container_of(_p, struct i2c_mipi_dsi, panel)
|
||||
|
||||
#endif /*End of header guard macro */
|
||||
@@ -158,7 +158,7 @@ static int dw_hdmi_light_probe(struct platform_device *pdev)
|
||||
|
||||
static int dw_hdmi_light_remove(struct platform_device *pdev)
|
||||
{
|
||||
component_del(&pdev->dev, &dw_hdmi_light_ops);
|
||||
component_del(&pdev->dev, &dw_hdmi_light_ops);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -181,10 +181,10 @@ static int hdmi_runtime_resume(struct device *dev)
|
||||
#ifdef CONFIG_PM_SLEEP
|
||||
static int hdmi_resume(struct device *dev)
|
||||
{
|
||||
struct light_hdmi *hdmi = dev_get_drvdata(dev);
|
||||
dev_info(dev,"hdmi resume\n");
|
||||
dw_hdmi_resume(hdmi->dw_hdmi);
|
||||
return 0;
|
||||
struct light_hdmi *hdmi = dev_get_drvdata(dev);
|
||||
dev_info(dev,"hdmi resume\n");
|
||||
dw_hdmi_resume(hdmi->dw_hdmi);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
static const struct dev_pm_ops dw_hdmi_pm_ops = {
|
||||
|
||||
0
drivers/gpu/drm/verisilicon/vs_dc.c
Normal file → Executable file
0
drivers/gpu/drm/verisilicon/vs_dc.c
Normal file → Executable file
@@ -66,6 +66,10 @@ static bool debug;
|
||||
module_param(debug, bool, 0444);
|
||||
MODULE_PARM_DESC(debug, "print a lot of debug information");
|
||||
|
||||
#ifdef CONFIG_HS_MH248
|
||||
extern bool get_hall_status(void);
|
||||
#endif
|
||||
|
||||
#define i2c_hid_dbg(ihid, fmt, arg...) \
|
||||
do { \
|
||||
if (debug) \
|
||||
@@ -262,13 +266,22 @@ static int __i2c_hid_command(struct i2c_client *client,
|
||||
if (wait)
|
||||
set_bit(I2C_HID_RESET_PENDING, &ihid->flags);
|
||||
|
||||
ret = i2c_transfer(client->adapter, msg, msg_num);
|
||||
int retry = 10;
|
||||
while(retry) {
|
||||
ret = i2c_transfer(client->adapter, msg, msg_num);
|
||||
|
||||
if (data_len > 0)
|
||||
clear_bit(I2C_HID_READ_PENDING, &ihid->flags);
|
||||
if (data_len > 0)
|
||||
clear_bit(I2C_HID_READ_PENDING, &ihid->flags);
|
||||
|
||||
if (ret != msg_num)
|
||||
if (ret == msg_num) {
|
||||
break;
|
||||
}
|
||||
retry--;
|
||||
}
|
||||
|
||||
if (ret != msg_num) {
|
||||
return ret < 0 ? ret : -EIO;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
@@ -1166,6 +1179,9 @@ static int i2c_hid_probe(struct i2c_client *client,
|
||||
goto err_mem_free;
|
||||
}
|
||||
|
||||
if (client->dev.of_node && of_property_read_bool(client->dev.of_node, "wakeup-source"))
|
||||
device_init_wakeup(&client->dev, 1);
|
||||
|
||||
return 0;
|
||||
|
||||
err_mem_free:
|
||||
@@ -1189,6 +1205,10 @@ static int i2c_hid_remove(struct i2c_client *client)
|
||||
hid = ihid->hid;
|
||||
hid_destroy_device(hid);
|
||||
|
||||
if (device_may_wakeup(&client->dev))
|
||||
device_init_wakeup(&client->dev, 0);
|
||||
|
||||
|
||||
free_irq(client->irq, ihid);
|
||||
|
||||
if (ihid->bufsize)
|
||||
@@ -1204,6 +1224,9 @@ static void i2c_hid_shutdown(struct i2c_client *client)
|
||||
{
|
||||
struct i2c_hid *ihid = i2c_get_clientdata(client);
|
||||
|
||||
if (device_may_wakeup(&client->dev))
|
||||
device_init_wakeup(&client->dev, 0);
|
||||
|
||||
i2c_hid_set_power(client, I2C_HID_PWR_SLEEP);
|
||||
free_irq(client->irq, ihid);
|
||||
|
||||
@@ -1216,6 +1239,7 @@ static int i2c_hid_suspend(struct device *dev)
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
struct i2c_hid *ihid = i2c_get_clientdata(client);
|
||||
struct hid_device *hid = ihid->hid;
|
||||
bool hall_open = true;
|
||||
int ret;
|
||||
int wake_status;
|
||||
|
||||
@@ -1228,8 +1252,6 @@ static int i2c_hid_suspend(struct device *dev)
|
||||
/* Save some power */
|
||||
i2c_hid_set_power(client, I2C_HID_PWR_SLEEP);
|
||||
|
||||
disable_irq(client->irq);
|
||||
|
||||
if (device_may_wakeup(&client->dev)) {
|
||||
wake_status = enable_irq_wake(client->irq);
|
||||
if (!wake_status)
|
||||
@@ -1239,9 +1261,16 @@ static int i2c_hid_suspend(struct device *dev)
|
||||
wake_status);
|
||||
} else {
|
||||
regulator_bulk_disable(ARRAY_SIZE(ihid->pdata.supplies),
|
||||
ihid->pdata.supplies);
|
||||
ihid->pdata.supplies);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_HS_MH248
|
||||
hall_open = get_hall_status();
|
||||
#endif
|
||||
|
||||
if(!hall_open) {
|
||||
disable_irq(client->irq);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,16 @@ config INPUT
|
||||
To compile this driver as a module, choose M here: the
|
||||
module will be called input.
|
||||
|
||||
config INPUT_FINGERPRINT
|
||||
default y
|
||||
help
|
||||
fingerprint
|
||||
|
||||
config INPUT_HALL
|
||||
default y
|
||||
help
|
||||
hall
|
||||
|
||||
if INPUT
|
||||
|
||||
config INPUT_LEDS
|
||||
@@ -211,5 +221,9 @@ source "drivers/input/gameport/Kconfig"
|
||||
|
||||
endmenu
|
||||
|
||||
source "drivers/input/fingerprint/Kconfig"
|
||||
|
||||
source "drivers/input/hall/Kconfig"
|
||||
|
||||
endmenu
|
||||
|
||||
|
||||
@@ -25,6 +25,8 @@ obj-$(CONFIG_INPUT_JOYSTICK) += joystick/
|
||||
obj-$(CONFIG_INPUT_TABLET) += tablet/
|
||||
obj-$(CONFIG_INPUT_TOUCHSCREEN) += touchscreen/
|
||||
obj-$(CONFIG_INPUT_MISC) += misc/
|
||||
obj-$(CONFIG_MICROARRAY_FINGERPRINT) += fingerprint/
|
||||
obj-$(CONFIG_HS_MH248) += hall/
|
||||
|
||||
obj-$(CONFIG_INPUT_APMPOWER) += apm-power.o
|
||||
|
||||
|
||||
51
drivers/input/fingerprint/Kconfig
Normal file
51
drivers/input/fingerprint/Kconfig
Normal file
@@ -0,0 +1,51 @@
|
||||
#
|
||||
#Fingerprint
|
||||
#
|
||||
menu "Fingerprint support"
|
||||
depends on INPUT
|
||||
|
||||
config MTK_FINGERPRINT_SUPPORT
|
||||
bool "Mediatek Fingerprint"
|
||||
default n
|
||||
help
|
||||
Fingerprint mtk driver enable/disable in the kernel.
|
||||
Say Y here if you want to use mediatek fingerprint driver,
|
||||
fingerprint driver will support fingerprint function
|
||||
|
||||
if MTK_FINGERPRINT_SUPPORT
|
||||
|
||||
config MICROARRAY_FINGERPRINT
|
||||
bool "Microarray Fingerprint"
|
||||
default y
|
||||
help
|
||||
Microarray fingerprint Microarray's 121/112/88/64/48 device.
|
||||
|
||||
if MICROARRAY_FINGERPRINT = ""
|
||||
config MTK_FINGERPRINT_SELECT
|
||||
string "sensor type"
|
||||
default "GF318M"
|
||||
endif
|
||||
|
||||
if MTK_FINGERPRINT_SELECT = "FPC1145"
|
||||
config FPC_FINGERPRINT
|
||||
bool "FPC Fingerprint"
|
||||
default y
|
||||
help
|
||||
FPC fingerprint FPC's 102x/104x device.
|
||||
endif
|
||||
|
||||
if MTK_FINGERPRINT_SELECT = "GF318M"
|
||||
config GOODIX_FINGERPRINT
|
||||
bool "Goodix Fingerprint"
|
||||
default y
|
||||
help
|
||||
Goodix Fingerprint chip GF316M/GF318M/GF3118M/GF518M/GF5118M/GF516M/GF816M/GF3208/GF5216 TEE driver
|
||||
|
||||
config GOODIX_SENSOR_TYPE
|
||||
string "SENSOR_TYPE"
|
||||
default "GF318M"
|
||||
help
|
||||
Must input sensor type, or default is GF316M GF318M GF3118M GF518M GF5118M GF516M GF816M GF3208 GF5216
|
||||
endif
|
||||
endif
|
||||
endmenu
|
||||
7
drivers/input/fingerprint/Makefile
Normal file
7
drivers/input/fingerprint/Makefile
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
# Makefile for all kinds of Fingerprint
|
||||
#
|
||||
|
||||
# obj-$(CONFIG_GOODIX_FINGERPRINT) += goodix/
|
||||
# obj-$(CONFIG_FPC_FINGERPRINT) += fpc/
|
||||
obj-$(CONFIG_MICROARRAY_FINGERPRINT) += microarray_fp/
|
||||
8
drivers/input/fingerprint/microarray_fp/Kconfig
Normal file
8
drivers/input/fingerprint/microarray_fp/Kconfig
Normal file
@@ -0,0 +1,8 @@
|
||||
# Copyright (C) MicroArray
|
||||
# MicroArray Fprint Driver Code
|
||||
# Kconfig
|
||||
# Date: 2017-3-15
|
||||
# Version: v4.0.06
|
||||
# Author: guq
|
||||
# Contact: guq@microarray.com.cn
|
||||
|
||||
30
drivers/input/fingerprint/microarray_fp/Makefile
Normal file
30
drivers/input/fingerprint/microarray_fp/Makefile
Normal file
@@ -0,0 +1,30 @@
|
||||
# Copyright (C) Microarray
|
||||
# MicroArray Fprint Driver Code
|
||||
# MAKEFILE
|
||||
# Date: 2017-3-15
|
||||
# Version: v4.0.06
|
||||
# Author: guq
|
||||
# Contact: guq@microarray.com.cn
|
||||
|
||||
|
||||
subdir-ccflags-y += -I$(srctree)/drivers/misc/mediatek/include/mt-plat/$(MTK_PLATFORM)/include \
|
||||
-I$(srctree)/drivers/misc/mediatek/include/mt-plat
|
||||
|
||||
MTK_PLATFORM := $(subst ",,$(CONFIG_MTK_PLATFORM))
|
||||
subdir-ccflags-y += -Werror
|
||||
subdir-ccflags-y += -I$(srctree)/drivers/misc/mediatek/include
|
||||
subdir-ccflags-y += -I$(srctree)/drivers/misc/mediatek/$(MTK_PLATFORM)
|
||||
subdir-ccflags-y += -I$(srctree)/drivers/misc/mediatek/include/mt-plat/$(MTK_PLATFORM)/include
|
||||
subdir-ccflags-y += -I$(srctree)/drivers/misc/mediatek/include/mt-plat
|
||||
subdir-ccflags-y += -I$(srctree)/drivers/spi/mediatek/$(MTK_PLATFORM)
|
||||
|
||||
#compatible for trustkernel
|
||||
subdir-ccflags-y += -I$(srctree)/drivers/misc/mediatek/tkcore/include/
|
||||
subdir-ccflags-y += -I$(srctree)/drivers/misc/mediatek/tkcore/core
|
||||
|
||||
#compatible for microtrust
|
||||
ccflags-y += -I$(srctree)/drivers/misc/mediatek/teei/V1.0/tz_vfs
|
||||
|
||||
obj-y += madev.o mtk-settings.o
|
||||
|
||||
|
||||
65
drivers/input/fingerprint/microarray_fp/ioctl_cmd.h
Normal file
65
drivers/input/fingerprint/microarray_fp/ioctl_cmd.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/* Copyright (C) MicroArray
|
||||
* MicroArray Fprint Driver Code
|
||||
* ioctl_cmd.h
|
||||
* Date: 2017-3-15
|
||||
* Version: v4.0.06
|
||||
* Author: guq
|
||||
* Contact: guq@microarray.com.cn
|
||||
*/
|
||||
#ifndef __IOCTL_CMD_H__
|
||||
#define __IOCTL_CMD_H__
|
||||
|
||||
#define MA_DRV_VERSION (0x00004006)
|
||||
|
||||
#define MA_IOC_MAGIC 'M'
|
||||
//#define MA_IOC_INIT _IOR(MA_IOC_MAGIC, 0, unsigned char)
|
||||
#define TIMEOUT_WAKELOCK _IO(MA_IOC_MAGIC, 1)
|
||||
#define SLEEP _IO(MA_IOC_MAGIC, 2) //陷入内核
|
||||
#define WAKEUP _IO(MA_IOC_MAGIC, 3) //唤醒
|
||||
#define ENABLE_CLK _IO(MA_IOC_MAGIC, 4) //打开spi时钟
|
||||
#define DISABLE_CLK _IO(MA_IOC_MAGIC, 5) //关闭spi时钟
|
||||
#define ENABLE_INTERRUPT _IO(MA_IOC_MAGIC, 6) //开启中断上报
|
||||
#define DISABLE_INTERRUPT _IO(MA_IOC_MAGIC, 7) //关闭中断上报
|
||||
#define TAP_DOWN _IO(MA_IOC_MAGIC, 8)
|
||||
#define TAP_UP _IO(MA_IOC_MAGIC, 9)
|
||||
#define SINGLE_TAP _IO(MA_IOC_MAGIC, 11)
|
||||
#define DOUBLE_TAP _IO(MA_IOC_MAGIC, 12)
|
||||
#define LONG_TAP _IO(MA_IOC_MAGIC, 13)
|
||||
|
||||
#define MA_IOC_VTIM _IOR(MA_IOC_MAGIC, 14, unsigned char) //version time
|
||||
#define MA_IOC_CNUM _IOR(MA_IOC_MAGIC, 15, unsigned char) //cover num
|
||||
#define MA_IOC_SNUM _IOR(MA_IOC_MAGIC, 16, unsigned char) //sensor type
|
||||
#define MA_IOC_UKRP _IOW(MA_IOC_MAGIC, 17, unsigned char) //user define the report key
|
||||
|
||||
#define MA_KEY_UP/*KEY_UP*/ _IO(MA_IOC_MAGIC, 18) //nav up
|
||||
#define MA_KEY_LEFT/*KEY_LEFT*/ _IO(MA_IOC_MAGIC, 19) //nav left
|
||||
#define MA_KEY_DOWN/*KEY_DOWN*/ _IO(MA_IOC_MAGIC, 20) //nav down
|
||||
#define MA_KEY_RIGHT/*KEY_RIGHT*/ _IO(MA_IOC_MAGIC, 21) //nav right
|
||||
|
||||
#define MA_KEY_F14/*KEY_F14*/ _IO(MA_IOC_MAGIC, 23) //for chuanyin
|
||||
#define SET_MODE _IOW(MA_IOC_MAGIC, 33, unsigned int) //for yude
|
||||
#define GET_MODE _IOR(MA_IOC_MAGIC, 34, unsigned int) //for yude
|
||||
|
||||
|
||||
#define ENABLE_IRQ/*ENABLE_IQ*/ _IO(MA_IOC_MAGIC, 31)
|
||||
#define DISABLE_IRQ/*DISABLE_IQ*/ _IO(MA_IOC_MAGIC, 32)
|
||||
|
||||
#define MA_IOC_GVER _IOR(MA_IOC_MAGIC, 35, unsigned int) //get the driver version,the version mapping in the u32 is the final 4+4+8,as ******** ******* ****(major verson number) ****(minor version number) ********(revised version number), the front 16 byte is reserved.
|
||||
#define SCREEN_OFF _IO(MA_IOC_MAGIC, 36)
|
||||
#define SCREEN_ON _IO(MA_IOC_MAGIC, 37)
|
||||
#define SET_SPI_SPEED _IOW(MA_IOC_MAGIC, 38, unsigned int)
|
||||
|
||||
|
||||
#define WAIT_FACTORY_CMD _IO(MA_IOC_MAGIC, 39)//for fingerprintd
|
||||
#define WAKEUP_FINGERPRINTD _IO(MA_IOC_MAGIC, 40)//for factory test
|
||||
#define WAIT_FINGERPRINTD_RESPONSE _IOR(MA_IOC_MAGIC, 41, unsigned int)//for factory test
|
||||
#define WAKEUP_FACTORY_TEST_SEND_FINGERPRINTD_RESPONSE _IOW(MA_IOC_MAGIC, 42, unsigned int)//for fingerprintd
|
||||
#define WAIT_SCREEN_STATUS_CHANGE _IOR(MA_IOC_MAGIC, 43, unsigned int)
|
||||
#define GET_INTERRUPT_STATUS _IOR(MA_IOC_MAGIC, 44, unsigned int)
|
||||
#define SYNC _IO(MA_IOC_MAGIC, 45)
|
||||
#define SYNC2 _IO(MA_IOC_MAGIC, 46)
|
||||
#define GET_SCREEN_STATUS _IOR(MA_IOC_MAGIC, 47, unsigned int)
|
||||
#define MA_RESET _IOW(MA_IOC_MAGIC, 48, unsigned int)
|
||||
#define GET_MA_RESET_STATE _IOR(MA_IOC_MAGIC, 49, unsigned int)
|
||||
#endif /* __IOCTL_CMD_H__ */
|
||||
|
||||
889
drivers/input/fingerprint/microarray_fp/madev.c
Normal file
889
drivers/input/fingerprint/microarray_fp/madev.c
Normal file
@@ -0,0 +1,889 @@
|
||||
/* Copyright (C) MicroArray
|
||||
oALOGD("start");
|
||||
* MicroArray Fprint Driver Code for REE enviroment
|
||||
* madev.c
|
||||
* Date: 2017-3-15
|
||||
* Version: v4.0.06
|
||||
* Author: guq
|
||||
* Contact: guq@microarray.com.cn
|
||||
*/
|
||||
#include "madev.h"
|
||||
|
||||
#ifdef TEE_ID_COMPATIBLE_MICROTRUST
|
||||
#include <fp_vendor.h>
|
||||
#include "teei_fp.h"
|
||||
#include "tee_client_api.h"
|
||||
#endif
|
||||
|
||||
//spdev use for recording the data for other use
|
||||
static unsigned int irq, ret;
|
||||
static unsigned int ma_drv_reg;
|
||||
static unsigned int ma_speed;
|
||||
static unsigned int is_screen_on;
|
||||
static struct notifier_block notifier;
|
||||
static unsigned int int_pin_state;
|
||||
static unsigned int compatible;
|
||||
static unsigned int screen_flag;
|
||||
static DECLARE_WAIT_QUEUE_HEAD(screenwaitq);
|
||||
static DECLARE_WAIT_QUEUE_HEAD(gWaitq);
|
||||
static DECLARE_WAIT_QUEUE_HEAD(U1_Waitq);
|
||||
static DECLARE_WAIT_QUEUE_HEAD(U2_Waitq);
|
||||
#ifdef CONFIG_PM_WAKELOCKS
|
||||
struct wakeup_source *gProcessWakeLock;
|
||||
#else
|
||||
struct wake_lock gProcessWakeLock;
|
||||
#endif
|
||||
|
||||
struct work_struct gWork;
|
||||
struct workqueue_struct *gWorkq;
|
||||
//
|
||||
static LIST_HEAD(dev_list);
|
||||
static DEFINE_MUTEX(dev_lock);
|
||||
static DEFINE_MUTEX(drv_lock);
|
||||
static DEFINE_MUTEX(ioctl_lock);
|
||||
#ifdef COMPATIBLE_VERSION3
|
||||
static DECLARE_WAIT_QUEUE_HEAD(drv_waitq);
|
||||
#endif
|
||||
|
||||
static struct fprint_dev *sdev = NULL;
|
||||
static struct fprint_spi *smas = NULL;
|
||||
|
||||
static u8* stxb;
|
||||
static u8* srxb;
|
||||
|
||||
#define IMAGE_SIZE 13312
|
||||
#define IMAGE_DMA_SIZE 32*1024
|
||||
|
||||
static void mas_work(struct work_struct *pws) {
|
||||
smas->f_irq = 1;
|
||||
wake_up(&gWaitq);
|
||||
#ifdef COMPATIBLE_VERSION3
|
||||
wake_up(&drv_waitq);
|
||||
#endif
|
||||
}
|
||||
|
||||
static irqreturn_t mas_interrupt(int irq, void *dev_id) {
|
||||
|
||||
#ifdef CONFIG_PM_WAKELOCKS
|
||||
__pm_wakeup_event(gProcessWakeLock, 5000);
|
||||
#else
|
||||
wake_lock_timeout(&gProcessWakeLock, 5 * HZ);
|
||||
#endif
|
||||
#ifdef DOUBLE_EDGE_IRQ
|
||||
if(mas_get_interrupt_gpio(0)==1){
|
||||
//TODO IRQF_TRIGGER_RISING
|
||||
}else{
|
||||
//TODO IRQF_TRIGGER_FALLING
|
||||
}
|
||||
#else
|
||||
|
||||
queue_work(gWorkq, &gWork);
|
||||
#endif
|
||||
return IRQ_HANDLED;
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------- fops ------------------------------------*/
|
||||
|
||||
/* 读写数据
|
||||
* @buf 数据
|
||||
* @len 长度
|
||||
* @返回值:0成功,否则失败
|
||||
*/
|
||||
int mas_sync(u8 *txb, u8 *rxb, int len) {
|
||||
int ret = 0;
|
||||
#if 1
|
||||
|
||||
struct spi_message m;
|
||||
struct spi_transfer t = {
|
||||
.tx_buf = txb,
|
||||
.rx_buf = rxb,
|
||||
.len = len,
|
||||
.speed_hz = smas->spi->max_speed_hz,
|
||||
};
|
||||
mutex_lock(&dev_lock);
|
||||
// len = (len + 1023) << 10 >> 10;
|
||||
// t.len = len;
|
||||
spi_message_init(&m);
|
||||
spi_message_add_tail(&t, &m);
|
||||
ret= spi_sync(smas->spi,&m);
|
||||
mutex_unlock(&dev_lock);
|
||||
|
||||
return ret;
|
||||
#else
|
||||
|
||||
|
||||
mutex_lock(&dev_lock);
|
||||
mas_select_transfer(smas->spi, len);
|
||||
smas->xfer.tx_nbits=SPI_NBITS_SINGLE;
|
||||
smas->xfer.tx_buf = txb;
|
||||
smas->xfer.rx_nbits=SPI_NBITS_SINGLE;
|
||||
smas->xfer.rx_buf = rxb;
|
||||
smas->xfer.delay_usecs = 1;
|
||||
smas->xfer.len = len;
|
||||
smas->xfer.bits_per_word = 8;
|
||||
smas->xfer.speed_hz = smas->spi->max_speed_hz;
|
||||
spi_message_init(&smas->msg);
|
||||
spi_message_add_tail(&smas->xfer, &smas->msg);
|
||||
ret = spi_sync(smas->spi, &smas->msg);
|
||||
mutex_unlock(&dev_lock);
|
||||
|
||||
return ret;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* 读数据
|
||||
* @return 成功:count, -1count太大,-2通讯失败, -3拷贝失败
|
||||
*/
|
||||
static ssize_t mas_read(struct file *filp, char __user *buf, size_t count, loff_t *f_pos) {
|
||||
int val, ret = 0;
|
||||
//MALOGD("start");
|
||||
//printk("zzzz count - %d\n", (int)count);
|
||||
ret = mas_sync(stxb, srxb, count);
|
||||
if(ret) {
|
||||
MALOGW("mas_sync failed.");
|
||||
return -2;
|
||||
}
|
||||
ret = copy_to_user(buf, srxb, count);
|
||||
if(!ret) val = count;
|
||||
else {
|
||||
val = -3;
|
||||
MALOGW("copy_to_user failed.");
|
||||
}
|
||||
//MALOGD("end.");
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
static void mas_set_input(void) {
|
||||
struct input_dev *input = NULL;
|
||||
input = input_allocate_device();
|
||||
if (!input) {
|
||||
MALOGW("input_allocate_device failed.");
|
||||
return ;
|
||||
}
|
||||
set_bit(EV_KEY, input->evbit);
|
||||
//set_bit(EV_ABS, input->evbit);
|
||||
set_bit(EV_SYN, input->evbit);
|
||||
set_bit(FINGERPRINT_SWIPE_UP, input->keybit); //单触
|
||||
set_bit(FINGERPRINT_SWIPE_DOWN, input->keybit);
|
||||
set_bit(FINGERPRINT_SWIPE_LEFT, input->keybit);
|
||||
set_bit(FINGERPRINT_SWIPE_RIGHT, input->keybit);
|
||||
set_bit(FINGERPRINT_TAP, input->keybit);
|
||||
set_bit(FINGERPRINT_DTAP, input->keybit);
|
||||
set_bit(FINGERPRINT_LONGPRESS, input->keybit);
|
||||
|
||||
set_bit(KEY_POWER, input->keybit);
|
||||
|
||||
input->name = MA_CHR_DEV_NAME;
|
||||
input->id.bustype = BUS_SPI;
|
||||
ret = input_register_device(input);
|
||||
if (ret) {
|
||||
input_free_device(input);
|
||||
MALOGW("failed to register input device.");
|
||||
return;
|
||||
}
|
||||
smas->input = input;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//static int mas_ioctl (struct inode *node, struct file *filp, unsigned int cmd, uns igned long arg)
|
||||
//this function only supported while the linux kernel version under v2.6.36,while the kernel version under v2.6.36, use this line
|
||||
static long mas_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) {
|
||||
//MALOGF("start");
|
||||
int tmp;
|
||||
switch(cmd){
|
||||
case TIMEOUT_WAKELOCK: //延时锁 timeout lock
|
||||
#ifdef CONFIG_PM_WAKELOCKS
|
||||
__pm_wakeup_event(gProcessWakeLock, 5000);
|
||||
#else
|
||||
wake_lock_timeout(&gProcessWakeLock, 5 * HZ);
|
||||
#endif
|
||||
break;
|
||||
case SLEEP: //remove the process out of the runqueue
|
||||
if(mas_get_interrupt_gpio(0) == 1) {
|
||||
MALOGF("int pull down failed!");
|
||||
return 0;
|
||||
}
|
||||
smas->f_irq = 0;
|
||||
ret = wait_event_freezable(gWaitq, smas->f_irq != 0);
|
||||
break;
|
||||
case WAKEUP: //wake up, schedule the process into the runqueue
|
||||
smas->f_irq = 1;
|
||||
wake_up(&gWaitq);
|
||||
break;
|
||||
case ENABLE_CLK:
|
||||
mas_enable_spi_clock(smas->spi); //if the spi clock is not opening always, do this methods
|
||||
break;
|
||||
case DISABLE_CLK:
|
||||
mas_disable_spi_clock(smas->spi); //disable the spi clock
|
||||
break;
|
||||
case ENABLE_INTERRUPT:
|
||||
enable_irq(irq); //enable the irq,in fact, you can make irq enable always
|
||||
break;
|
||||
case DISABLE_INTERRUPT:
|
||||
disable_irq(irq); //disable the irq
|
||||
break;
|
||||
case TAP_DOWN:
|
||||
input_report_key(smas->input, FINGERPRINT_TAP, 1);
|
||||
input_sync(smas->input); //tap down
|
||||
break;
|
||||
case TAP_UP:
|
||||
input_report_key(smas->input, FINGERPRINT_TAP, 0);
|
||||
input_sync(smas->input); //tap up
|
||||
break;
|
||||
case SINGLE_TAP:
|
||||
input_report_key(smas->input, FINGERPRINT_TAP, 1);
|
||||
input_sync(smas->input);
|
||||
input_report_key(smas->input, FINGERPRINT_TAP, 0);
|
||||
input_sync(smas->input); //single tap
|
||||
break;
|
||||
case DOUBLE_TAP:
|
||||
input_report_key(smas->input, FINGERPRINT_DTAP, 1);
|
||||
input_sync(smas->input);
|
||||
input_report_key(smas->input, FINGERPRINT_DTAP, 0);
|
||||
input_sync(smas->input); //double tap
|
||||
break;
|
||||
case LONG_TAP:
|
||||
input_report_key(smas->input, FINGERPRINT_LONGPRESS, 1);
|
||||
input_sync(smas->input);
|
||||
input_report_key(smas->input, FINGERPRINT_LONGPRESS, 0);
|
||||
input_sync(smas->input); //long tap
|
||||
break;
|
||||
case MA_KEY_UP:
|
||||
input_report_key(smas->input, FINGERPRINT_SWIPE_UP, 1);
|
||||
input_sync(smas->input);
|
||||
input_report_key(smas->input, FINGERPRINT_SWIPE_UP, 0);
|
||||
input_sync(smas->input);
|
||||
break;
|
||||
case MA_KEY_LEFT:
|
||||
input_report_key(smas->input, FINGERPRINT_SWIPE_LEFT, 1);
|
||||
input_sync(smas->input);
|
||||
input_report_key(smas->input, FINGERPRINT_SWIPE_LEFT, 0);
|
||||
input_sync(smas->input);
|
||||
break;
|
||||
case MA_KEY_DOWN:
|
||||
input_report_key(smas->input, FINGERPRINT_SWIPE_DOWN, 1);
|
||||
input_sync(smas->input);
|
||||
input_report_key(smas->input, FINGERPRINT_SWIPE_DOWN, 0);
|
||||
input_sync(smas->input);
|
||||
break;
|
||||
case MA_KEY_RIGHT:
|
||||
input_report_key(smas->input, FINGERPRINT_SWIPE_RIGHT, 1);
|
||||
input_sync(smas->input);
|
||||
input_report_key(smas->input, FINGERPRINT_SWIPE_RIGHT, 0);
|
||||
input_sync(smas->input);
|
||||
break;
|
||||
case SET_MODE:
|
||||
mutex_lock(&ioctl_lock);
|
||||
ret = copy_from_user(&ma_drv_reg, (unsigned int*)arg, sizeof(unsigned int));
|
||||
mutex_unlock(&ioctl_lock);
|
||||
break;
|
||||
case GET_MODE:
|
||||
mutex_lock(&ioctl_lock);
|
||||
ret = copy_to_user((unsigned int*)arg, &ma_drv_reg, sizeof(unsigned int));
|
||||
mutex_unlock(&ioctl_lock);
|
||||
break;
|
||||
case MA_IOC_GVER:
|
||||
{
|
||||
unsigned int ma_drv_version = MA_DRV_VERSION;
|
||||
mutex_lock(&ioctl_lock);
|
||||
if (copy_to_user((void *)arg, &ma_drv_version, sizeof(unsigned int))) {
|
||||
MALOGE("copy_to_user(..) failed.\n");
|
||||
ret = (-EFAULT);
|
||||
}
|
||||
mutex_unlock(&ioctl_lock);
|
||||
}
|
||||
break;
|
||||
case SCREEN_ON:
|
||||
mas_switch_power(1);
|
||||
break;
|
||||
case SCREEN_OFF:
|
||||
mas_switch_power(0);
|
||||
break;
|
||||
case MA_RESET:
|
||||
mas_finger_set_reset(arg);
|
||||
break;
|
||||
case GET_MA_RESET_STATE:
|
||||
break;
|
||||
|
||||
case SET_SPI_SPEED:
|
||||
ret = copy_from_user(&ma_speed, (unsigned int*)arg, sizeof(unsigned int));
|
||||
ma_spi_change(smas->spi, ma_speed, 0);
|
||||
break;
|
||||
case WAIT_FACTORY_CMD:
|
||||
smas->u2_flag = 0;
|
||||
ret = wait_event_freezable(U2_Waitq, smas->u2_flag != 0);
|
||||
break;
|
||||
case WAKEUP_FINGERPRINTD:
|
||||
smas->u2_flag = 1;
|
||||
wake_up(&U2_Waitq);
|
||||
break;
|
||||
case WAIT_FINGERPRINTD_RESPONSE:
|
||||
smas->u1_flag = 0;
|
||||
ret = wait_event_freezable(U1_Waitq, smas->u1_flag != 0);
|
||||
mutex_lock(&ioctl_lock);
|
||||
tmp = copy_to_user((unsigned int*)arg, &ma_drv_reg, sizeof(unsigned int));
|
||||
mutex_unlock(&ioctl_lock);
|
||||
break;
|
||||
case WAKEUP_FACTORY_TEST_SEND_FINGERPRINTD_RESPONSE:
|
||||
mutex_lock(&ioctl_lock);
|
||||
ret = copy_from_user(&ma_drv_reg, (unsigned int*)arg, sizeof(unsigned int));
|
||||
mutex_unlock(&ioctl_lock);
|
||||
msleep(4);
|
||||
smas->u1_flag = 1;
|
||||
wake_up(&U1_Waitq);
|
||||
break;
|
||||
case WAIT_SCREEN_STATUS_CHANGE:
|
||||
screen_flag = 0;
|
||||
ret = wait_event_freezable(screenwaitq, screen_flag != 0);
|
||||
mutex_lock(&ioctl_lock);
|
||||
tmp = copy_to_user((unsigned int*)arg, &is_screen_on, sizeof(unsigned int));
|
||||
mutex_unlock(&ioctl_lock);
|
||||
break;
|
||||
case GET_INTERRUPT_STATUS:
|
||||
int_pin_state = mas_get_interrupt_gpio(0);
|
||||
mutex_lock(&ioctl_lock);
|
||||
tmp = copy_to_user((unsigned int*)arg, &int_pin_state, sizeof(unsigned int));
|
||||
mutex_unlock(&ioctl_lock);
|
||||
break;
|
||||
case GET_SCREEN_STATUS:
|
||||
mutex_lock(&ioctl_lock);
|
||||
ret = copy_to_user((unsigned int*)arg, &is_screen_on, sizeof(unsigned int));
|
||||
mutex_unlock(&ioctl_lock);
|
||||
break;
|
||||
default:
|
||||
ret = -EINVAL;
|
||||
MALOGW("mas_ioctl no such cmd");
|
||||
}
|
||||
//MALOGF("end");
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_COMPAT
|
||||
static long mas_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
|
||||
{
|
||||
int retval = 0;
|
||||
retval = filp->f_op->unlocked_ioctl(filp, cmd, arg);
|
||||
return retval;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef COMPATIBLE_VERSION3
|
||||
int version3_ioctl(int cmd, int arg){
|
||||
int ret = 0;
|
||||
|
||||
printd("%s: start cmd=0x%.3x arg=%d\n", __func__, cmd, arg);
|
||||
|
||||
switch (cmd) {
|
||||
case IOCTL_DEBUG:
|
||||
sdeb = (u8) arg;
|
||||
break;
|
||||
case IOCTL_IRQ_ENABLE:
|
||||
break;
|
||||
case IOCTL_SPI_SPEED:
|
||||
smas->spi->max_speed_hz = (u32) arg;
|
||||
spi_setup(smas->spi);
|
||||
break;
|
||||
case IOCTL_COVER_NUM:
|
||||
ret = COVER_NUM;
|
||||
break;
|
||||
case IOCTL_GET_VDATE:
|
||||
ret = 20160425;
|
||||
break;
|
||||
case IOCTL_CLR_INTF:
|
||||
smas->f_irq = FALSE;
|
||||
break;
|
||||
case IOCTL_GET_INTF:
|
||||
ret = smas->f_irq;
|
||||
break;
|
||||
case IOCTL_REPORT_FLAG:
|
||||
smas->f_repo = arg;
|
||||
break;
|
||||
case IOCTL_REPORT_KEY:
|
||||
input_report_key(smas->input, arg, 1);
|
||||
input_sync(smas->input);
|
||||
input_report_key(smas->input, arg, 0);
|
||||
input_sync(smas->input);
|
||||
break;
|
||||
case IOCTL_SET_WORK:
|
||||
smas->do_what = arg;
|
||||
break;
|
||||
case IOCTL_GET_WORK:
|
||||
ret = smas->do_what;
|
||||
break;
|
||||
case IOCTL_SET_VALUE:
|
||||
smas->value = arg;
|
||||
break;
|
||||
case IOCTL_GET_VALUE:
|
||||
ret = smas->value;
|
||||
break;
|
||||
case IOCTL_TRIGGER:
|
||||
smas->f_wake = TRUE;
|
||||
wake_up_interruptible(&drv_waitq);
|
||||
break;
|
||||
case IOCTL_WAKE_LOCK:
|
||||
#ifdef CONFIG_PM_WAKELOCKS
|
||||
__pm_stay_awake(&smas->wl);
|
||||
#else
|
||||
wake_lock(&smas->wl);
|
||||
#endif
|
||||
break;
|
||||
case IOCTL_WAKE_UNLOCK:
|
||||
#ifdef CONFIG_PM_WAKELOCKS
|
||||
__pm_relax(&smas->wl);
|
||||
#else
|
||||
wake_unlock(&smas->wl);
|
||||
#endif
|
||||
break;
|
||||
case IOCTL_KEY_DOWN:
|
||||
input_report_key(smas->input, KEY_F11 1);
|
||||
input_sync(smas->input);
|
||||
break;
|
||||
case IOCTL_KEY_UP:
|
||||
input_report_key(smas->input, KEY_F11, 0);
|
||||
input_sync(smas->input);
|
||||
break;
|
||||
}
|
||||
|
||||
printd("%s: end. ret=%d f_irq=%d, f_repo=%d\n", __func__, ret, smas->f_irq, smas->f_repo);
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
/* 写数据
|
||||
* @return 成功:count, -1count太大,-2拷贝失败
|
||||
*/
|
||||
static ssize_t mas_write(struct file *filp, const char __user *buf, size_t count, loff_t *f_pos) {
|
||||
int val = 0;
|
||||
//MALOGD("start");
|
||||
if(count==6) { //cmd ioctl, old version used the write interface to do ioctl, this is only for the old version
|
||||
int cmd, arg;
|
||||
u8 tmp[6];
|
||||
ret = copy_from_user(tmp, buf, count);
|
||||
cmd = tmp[0];
|
||||
cmd <<= 8;
|
||||
cmd += tmp[1];
|
||||
arg = tmp[2];
|
||||
arg <<= 8;
|
||||
arg += tmp[3];
|
||||
arg <<= 8;
|
||||
arg += tmp[4];
|
||||
arg <<= 8;
|
||||
arg += tmp[5];
|
||||
#ifdef COMPATIBLE_VERSION3
|
||||
val = (int)version3_ioctl(NULL, (unsigned int)cmd, (unsigned long)arg);
|
||||
#endif
|
||||
} else {
|
||||
//memset(stxb, 0, FBUF);
|
||||
memset(stxb, 0xff, IMAGE_DMA_SIZE);
|
||||
ret = copy_from_user(stxb, buf, count);
|
||||
if(ret) {
|
||||
MALOGW("copy form user failed");
|
||||
val = -2;
|
||||
} else {
|
||||
val = count;
|
||||
}
|
||||
}
|
||||
return val;
|
||||
}
|
||||
void * kernel_memaddr = NULL;
|
||||
unsigned long kernel_memesize = 0;
|
||||
|
||||
int mas_mmap(struct file *filp, struct vm_area_struct *vma){
|
||||
unsigned long page;
|
||||
if ( !kernel_memaddr ) {
|
||||
kernel_memaddr = kmalloc(128*1024, GFP_KERNEL);
|
||||
if( !kernel_memaddr ) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
page = virt_to_phys((void *)kernel_memaddr) >> PAGE_SHIFT;
|
||||
vma->vm_page_prot=pgprot_noncached(vma->vm_page_prot);
|
||||
if( remap_pfn_range(vma, vma->vm_start, page, (vma->vm_end - vma->vm_start),
|
||||
vma->vm_page_prot) )
|
||||
return -1;
|
||||
//vma->vm_flags |= VM_RESERVED;
|
||||
vma->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP;
|
||||
printk("remap_pfn_rang page:[%lu] ok.\n", page);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef COMPATIBLE_VERSION3
|
||||
static unsigned int mas_poll(struct file *filp, struct poll_table_struct *wait) {
|
||||
unsigned int mask = 0;
|
||||
|
||||
printd("%s: start. f_irq=%d f_repo=%d f_wake=%d\n",
|
||||
__func__, smas->f_irq, smas->f_repo, smas->f_wake);
|
||||
|
||||
poll_wait(filp, &drv_waitq, wait);
|
||||
if(smas->f_irq && smas->f_repo) {
|
||||
smas->f_repo = FALSE;
|
||||
mask |= POLLIN | POLLRDNORM;
|
||||
} else if( smas->f_wake ) {
|
||||
smas->f_wake = FALSE;
|
||||
mask |= POLLPRI;
|
||||
}
|
||||
|
||||
printd("%s: end. mask=%d\n", __func__, mask);
|
||||
|
||||
return mask;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*---------------------------------- fops ------------------------------------*/
|
||||
static const struct file_operations sfops = {
|
||||
.owner = THIS_MODULE,
|
||||
.write = mas_write,
|
||||
.read = mas_read,
|
||||
.unlocked_ioctl = mas_ioctl,
|
||||
.mmap = mas_mmap,
|
||||
//.ioctl = mas_ioctl,
|
||||
//using the previous line replacing the unlock_ioctl while the linux kernel under version2.6.36
|
||||
#ifdef CONFIG_COMPAT
|
||||
.compat_ioctl = mas_compat_ioctl,
|
||||
#endif
|
||||
#ifdef COMPATIBLE_VERSION3
|
||||
.poll = mas_poll,
|
||||
#endif
|
||||
};
|
||||
/*---------------------------------- fops end ---------------------------------*/
|
||||
|
||||
static int init_file_node(void)
|
||||
{
|
||||
int ret;
|
||||
//MALOGF("start");
|
||||
ret = alloc_chrdev_region(&sdev->idd, 0, 1, MA_CHR_DEV_NAME);
|
||||
if(ret < 0)
|
||||
{
|
||||
MALOGW("alloc_chrdev_region error!");
|
||||
return -1;
|
||||
}
|
||||
sdev->chd = cdev_alloc();
|
||||
if (!sdev->chd)
|
||||
{
|
||||
MALOGW("cdev_alloc error!");
|
||||
return -1;
|
||||
}
|
||||
sdev->chd->owner = THIS_MODULE;
|
||||
sdev->chd->ops = &sfops;
|
||||
cdev_add(sdev->chd, sdev->idd, 1);
|
||||
sdev->cls = class_create(THIS_MODULE, MA_CHR_DEV_NAME);
|
||||
if (IS_ERR(sdev->cls)) {
|
||||
MALOGE("class_create");
|
||||
return -1;
|
||||
}
|
||||
sdev->dev = device_create(sdev->cls, NULL, sdev->idd, NULL, MA_CHR_FILE_NAME);
|
||||
ret = IS_ERR(sdev->dev) ? PTR_ERR(sdev->dev) : 0;
|
||||
if(ret){
|
||||
MALOGE("device_create");
|
||||
}
|
||||
//MALOGF("end");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int deinit_file_node(void)
|
||||
{
|
||||
cdev_del(sdev->chd);
|
||||
device_destroy(sdev->cls, sdev->idd);
|
||||
unregister_chrdev_region(sdev->idd, 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int init_interrupt(void)
|
||||
{
|
||||
const char*tname = MA_EINT_NAME;
|
||||
irq = mas_get_irq(&smas->spi->dev);
|
||||
if(irq<=0){
|
||||
ret = irq;
|
||||
MALOGE("mas_get_irq");
|
||||
}
|
||||
#ifdef DOUBLE_EDGE_IRQ
|
||||
ret = request_irq(irq, mas_interrupt, IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, tname, NULL);
|
||||
#else
|
||||
ret = request_irq(irq, mas_interrupt, IRQF_TRIGGER_RISING, tname, NULL);
|
||||
#endif
|
||||
if(ret<0){
|
||||
MALOGE("request_irq");
|
||||
}
|
||||
enable_irq_wake(irq);
|
||||
return ret;
|
||||
}
|
||||
static int deinit_interrupt(void)
|
||||
{
|
||||
disable_irq(irq);
|
||||
free_irq(irq, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int init_vars(void)
|
||||
{
|
||||
sdev = kmalloc(sizeof(struct fprint_dev), GFP_KERNEL);
|
||||
smas = kmalloc(sizeof(struct fprint_spi), GFP_KERNEL);
|
||||
stxb = (u8*)__get_free_pages(GFP_KERNEL, get_order(IMAGE_DMA_SIZE));
|
||||
srxb = (u8*)__get_free_pages(GFP_KERNEL, get_order(IMAGE_DMA_SIZE));
|
||||
|
||||
if (sdev==NULL || smas==NULL || stxb==NULL || srxb==NULL) {
|
||||
MALOGW("smas kmalloc failed.");
|
||||
if(sdev!=NULL) kfree(sdev);
|
||||
if(smas!=NULL) kfree(smas);
|
||||
if(stxb!=NULL) free_pages((unsigned long)stxb, get_order(IMAGE_DMA_SIZE));
|
||||
if(srxb!=NULL) free_pages((unsigned long)srxb, get_order(IMAGE_DMA_SIZE));
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
memset(stxb,0x00,get_order(IMAGE_DMA_SIZE));
|
||||
memset(srxb,0x00,get_order(IMAGE_DMA_SIZE));
|
||||
|
||||
#ifdef CONFIG_PM_WAKELOCKS
|
||||
//wakeup_source_init(&gProcessWakeLock, "microarray_process_wakelock");
|
||||
//wakeup_source_add(&gProcessWakeLock, "microarray_process_wakelock");
|
||||
gProcessWakeLock = wakeup_source_register(NULL,"microarray_process_wakelock");
|
||||
#else
|
||||
wake_lock_init(&gProcessWakeLock, WAKE_LOCK_SUSPEND, "microarray_process_wakelock");
|
||||
#endif
|
||||
|
||||
INIT_WORK(&gWork, mas_work);
|
||||
gWorkq = create_singlethread_workqueue("mas_workqueue");
|
||||
if (!gWorkq) {
|
||||
MALOGW("create_single_workqueue error!");
|
||||
return -ENOMEM;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
static int deinit_vars(void)
|
||||
{
|
||||
destroy_workqueue(gWorkq);
|
||||
//wake_lock_destroy(&gProcessWakeLock);
|
||||
wakeup_source_unregister(gProcessWakeLock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int init_spi(struct spi_device *spi){
|
||||
smas->spi = spi;
|
||||
smas->spi->max_speed_hz = SPI_SPEED;
|
||||
spi_setup(spi);
|
||||
INIT_LIST_HEAD(&smas->dev_entry);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int deinit_spi(struct spi_device *spi){
|
||||
smas->spi = NULL;
|
||||
return 0;
|
||||
}
|
||||
/*
|
||||
* init_connect function to check whether the chip is microarray's
|
||||
* @return 0 not 1 yes
|
||||
* param void
|
||||
*/
|
||||
int init_connect(void){
|
||||
int i;
|
||||
MALOGD("start");
|
||||
for(i=0; i<4; i++){
|
||||
stxb[0] = 0x8c;
|
||||
stxb[1] = 0xff;
|
||||
stxb[2] = 0xff;
|
||||
stxb[3] = 0xff;
|
||||
#ifdef TEE_ID_COMPATIBLE_TRUSTKERNEL
|
||||
mas_tee_spi_transfer(stxb, srxb, 4);
|
||||
#else
|
||||
mas_sync(stxb, srxb, 4);
|
||||
#endif
|
||||
msleep(8);
|
||||
stxb[0] = 0x00;
|
||||
stxb[1] = 0xff;
|
||||
stxb[2] = 0xff;
|
||||
stxb[3] = 0xff;
|
||||
#ifdef TEE_ID_COMPATIBLE_TRUSTKERNEL
|
||||
ret = mas_tee_spi_transfer(stxb, srxb, 4);
|
||||
#else
|
||||
ret = mas_sync(stxb, srxb, 4);
|
||||
#endif
|
||||
if(ret!=0) MALOGW("do init_connect failed!");
|
||||
printk("guq srxb[3] = %d srxb[2] = %d\n", srxb[3], srxb[2]);
|
||||
if(srxb[3] == 0x41 || srxb[3] == 0x45) return 1;
|
||||
}
|
||||
MALOGD("end");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int deinit_connect(void){
|
||||
mas_free_dts_info();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int mas_fb_notifier_callback(struct notifier_block *self, unsigned long event, void *data){
|
||||
struct fb_event *evdata = data;
|
||||
unsigned int blank;
|
||||
if(event != FB_EVENT_BLANK) {
|
||||
return 0;
|
||||
}
|
||||
blank = *(int *)evdata->data;
|
||||
switch(blank){
|
||||
case FB_BLANK_UNBLANK:
|
||||
is_screen_on = 1;
|
||||
break;
|
||||
case FB_BLANK_POWERDOWN:
|
||||
is_screen_on = 0;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
screen_flag = 1;
|
||||
wake_up(&screenwaitq);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int init_notifier_call(void);
|
||||
static int deinit_notifier_call(void);
|
||||
|
||||
static int init_notifier_call(){
|
||||
notifier.notifier_call = mas_fb_notifier_callback;
|
||||
fb_register_client(¬ifier);
|
||||
is_screen_on = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int deinit_notifier_call(){
|
||||
fb_unregister_client(¬ifier);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mas_plat_probe(struct platform_device *pdev) {
|
||||
MALOGD("start");
|
||||
ret = mas_finger_get_gpio_info(pdev);
|
||||
if(ret){
|
||||
MALOGE("mas_plat_probe do mas_finger_get_gpio_info");
|
||||
}
|
||||
ret = mas_finger_set_gpio_info(1);
|
||||
if(ret){
|
||||
MALOGE("mas_plat_probe do mas_finger_set_gpio_info");
|
||||
}
|
||||
MALOGD("end");
|
||||
return ret;
|
||||
}
|
||||
|
||||
int mas_plat_remove(struct platform_device *pdev) {
|
||||
mas_finger_set_gpio_info(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int mas_probe(struct spi_device *spi) {
|
||||
|
||||
int ret = 0;
|
||||
|
||||
MALOGD("start");
|
||||
|
||||
mas_do_some_for_probe(spi);
|
||||
ret = init_vars();
|
||||
if(ret){
|
||||
goto err1;
|
||||
}
|
||||
|
||||
MALOGD("start3333");
|
||||
ret = init_spi(spi);
|
||||
if(ret){
|
||||
goto err2;
|
||||
}
|
||||
#ifdef READ_CHIP_ID
|
||||
mas_enable_spi_clock(smas->spi);
|
||||
ret = init_connect();
|
||||
mas_disable_spi_clock(smas->spi);
|
||||
|
||||
|
||||
if(ret == 0){//not chip
|
||||
goto err3;
|
||||
} else {
|
||||
#ifdef TEE_ID_COMPATIBLE_MICROTRUST
|
||||
struct TEEC_UUID vendor_uuid = {0xedcf9395, 0x3518, 0x9067, { 0x61, 0x4c, 0xaf, 0xae, 0x29, 0x09, 0x77, 0x5b }};
|
||||
//memcpy(&uuid_ta, &vendor_uuid, sizeof(struct TEEC_UUID));
|
||||
memcpy(&uuid_fp, &vendor_uuid, sizeof(struct TEEC_UUID));
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
ret = 0;
|
||||
#endif
|
||||
|
||||
MALOGD("start11111");
|
||||
|
||||
|
||||
ret = init_interrupt();
|
||||
if(ret < 0){
|
||||
goto err4;
|
||||
}
|
||||
|
||||
MALOGD("start22222");
|
||||
ret = init_file_node();
|
||||
if(ret){
|
||||
goto err5;
|
||||
}
|
||||
|
||||
mas_set_input();
|
||||
MALOGF("end");
|
||||
ret = init_notifier_call();
|
||||
if(ret != 0){
|
||||
ret = -ENODEV;
|
||||
goto err6;
|
||||
}
|
||||
|
||||
|
||||
MALOGD("end1111");
|
||||
return ret;
|
||||
|
||||
err6:
|
||||
deinit_notifier_call();
|
||||
err5:
|
||||
deinit_file_node();
|
||||
err4:
|
||||
deinit_interrupt();
|
||||
#ifdef READ_CHIP_ID
|
||||
err3:
|
||||
deinit_connect();
|
||||
#endif
|
||||
err2:
|
||||
deinit_spi(spi);
|
||||
err1:
|
||||
deinit_vars();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int mas_remove(struct spi_device *spi) {
|
||||
deinit_file_node();
|
||||
deinit_interrupt();
|
||||
deinit_vars();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int __init mas_init(void)
|
||||
{
|
||||
int ret = 0;
|
||||
MALOGF("start");
|
||||
compatible = 1;
|
||||
ret = mas_get_platform();
|
||||
if(ret){
|
||||
MALOGE("mas_get_platform");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void __exit mas_exit(void)
|
||||
{
|
||||
}
|
||||
|
||||
late_initcall_sync(mas_init);
|
||||
module_exit(mas_exit);
|
||||
|
||||
MODULE_AUTHOR("Microarray");
|
||||
MODULE_DESCRIPTION("Driver for microarray fingerprint sensor");
|
||||
MODULE_LICENSE("GPL");
|
||||
236
drivers/input/fingerprint/microarray_fp/madev.h
Normal file
236
drivers/input/fingerprint/microarray_fp/madev.h
Normal file
@@ -0,0 +1,236 @@
|
||||
/* Copyright (C) MicroArray
|
||||
* MicroArray Fprint Driver Code * madev.h
|
||||
* Date: 2017-3-15
|
||||
* Version: v4.0.06
|
||||
* Author: guq
|
||||
* Contact: guq@microarray.com.cn
|
||||
*/
|
||||
|
||||
#ifndef __MADEV_H_
|
||||
#define __MADEV_H_
|
||||
|
||||
// #define CONFIG_PM_WAKELOCKS
|
||||
|
||||
//settings macro
|
||||
#define MTK //[MTK|QUALCOMM|SPRD|X86]
|
||||
|
||||
//#define READ_CHIP_ID //detect the chip id when defined
|
||||
|
||||
#define MALOGD_LEVEL KERN_EMERG //[KERN_DEBUG|KERN_EMERG] usually, the debug level is used for the release version
|
||||
|
||||
#define MA_CHR_FILE_NAME "madev0" //do not neeed modify usually
|
||||
#define MA_CHR_DEV_NAME "madev" //do not neeed modify usually
|
||||
|
||||
#define MA_EINT_NAME "mediatek,finger_print-eint"
|
||||
|
||||
|
||||
//#define DOUBLE_EDGE_IRQ
|
||||
|
||||
//#define COMPATIBLE_VERSION3
|
||||
|
||||
//key define just modify the KEY_FN_* for different platform
|
||||
#define FINGERPRINT_SWIPE_UP KEY_FN_F1//827
|
||||
#define FINGERPRINT_SWIPE_DOWN KEY_FN_F2//828
|
||||
#define FINGERPRINT_SWIPE_LEFT KEY_FN_F3//829
|
||||
#define FINGERPRINT_SWIPE_RIGHT KEY_FN_F4//830
|
||||
#define FINGERPRINT_TAP KEY_FN_F9// 831
|
||||
#define FINGERPRINT_DTAP KEY_FN_F6// 832
|
||||
#define FINGERPRINT_LONGPRESS KEY_FN_F7//833
|
||||
|
||||
//key define end
|
||||
|
||||
|
||||
//old macro
|
||||
#define SPI_SPEED (4*1000000) //120/121:10M, 80/81:6M
|
||||
|
||||
//表面类型
|
||||
#define COVER_T 1
|
||||
#define COVER_N 2
|
||||
#define COVER_M 3
|
||||
#define COVER_NUM COVER_N
|
||||
|
||||
//指纹类型
|
||||
#define AFS120 0x78
|
||||
//#define AFS80 0x50
|
||||
|
||||
#define FBUF (32*1024)
|
||||
|
||||
#if defined(AFS120)
|
||||
#define W 120 //宽
|
||||
#define H 120 //高
|
||||
#define WBUF 121
|
||||
#elif defined(AFS80)
|
||||
#define W 80 //宽
|
||||
#define H 192 //高
|
||||
#define WBUF 81
|
||||
#define FIMG (W*H)
|
||||
#endif
|
||||
|
||||
//settings macro end
|
||||
#include <linux/poll.h>
|
||||
#include <linux/notifier.h>
|
||||
#include <linux/fb.h>
|
||||
//this two head file for the screen on/off test
|
||||
#include <linux/freezer.h>
|
||||
|
||||
#include <asm/ioctl.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/device.h>
|
||||
#include <linux/mutex.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/compat.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/workqueue.h>
|
||||
#include <linux/kthread.h>
|
||||
#include <linux/sched.h>
|
||||
#include <linux/wait.h>
|
||||
#include <linux/time.h>
|
||||
#include <linux/input.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/cdev.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/delay.h>
|
||||
#include <asm/uaccess.h>
|
||||
#include <linux/of.h>
|
||||
#include <linux/of_irq.h>
|
||||
#include <linux/gpio.h>
|
||||
#include <linux/spi/spi.h>
|
||||
#include <linux/ioctl.h>
|
||||
//#include <linux/wakelock.h>
|
||||
//#include <linux/pm_wakeup.h>
|
||||
|
||||
#ifdef CONFIG_PM_WAKELOCKS
|
||||
#include <linux/pm_wakeup.h>
|
||||
#else
|
||||
#include <linux/wakelock.h>
|
||||
#endif
|
||||
|
||||
#include <linux/mm.h>
|
||||
#include "ioctl_cmd.h"
|
||||
|
||||
#ifdef MTK
|
||||
#include "mtk-settings.h"
|
||||
#elif defined QUALCOMM
|
||||
#include "qualcomm-settings.h"
|
||||
#elif defined SPRD
|
||||
#include "sprd-settings.h"
|
||||
#elif defined X86
|
||||
#include "x86-settings.h"
|
||||
#endif
|
||||
|
||||
|
||||
//value define
|
||||
//fprint_spi struct use to save the value
|
||||
struct fprint_spi {
|
||||
u8 do_what; //工作内容
|
||||
u8 f_wake; //唤醒标志
|
||||
int value;
|
||||
volatile u8 f_irq; //中断标志
|
||||
volatile u8 u1_flag; //reserve for ours thread interrupt
|
||||
volatile u8 u2_flag; //reserve for ours thread interrupt
|
||||
volatile u8 f_repo; //上报开关
|
||||
spinlock_t spi_lock;
|
||||
struct spi_device *spi;
|
||||
struct list_head dev_entry;
|
||||
struct spi_message msg;
|
||||
struct spi_transfer xfer;
|
||||
struct input_dev *input;
|
||||
struct work_struct work;
|
||||
struct workqueue_struct *workq;
|
||||
#ifdef CONFIG_HAS_EARLYSUSPEND
|
||||
struct early_suspend suspend;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_PM_WAKELOCKS
|
||||
struct wakeup_source wl;
|
||||
#else
|
||||
struct wake_lock wl;
|
||||
#endif
|
||||
};
|
||||
//end
|
||||
|
||||
struct fprint_dev {
|
||||
dev_t idd;
|
||||
int major;
|
||||
int minor;
|
||||
struct cdev *chd;
|
||||
struct class *cls;
|
||||
struct device *dev;
|
||||
};
|
||||
|
||||
|
||||
//function define
|
||||
|
||||
//extern the settings.h function
|
||||
extern void mas_select_transfer(struct spi_device *spi, int len);
|
||||
extern int mas_finger_get_gpio_info(struct platform_device *pdev);
|
||||
extern int mas_finger_set_gpio_info(int cmd);
|
||||
extern void mas_enable_spi_clock(struct spi_device *spi);
|
||||
extern void mas_disable_spi_clock(struct spi_device *spi);
|
||||
extern unsigned int mas_get_irq(struct device *dev);
|
||||
extern int mas_get_platform(void);
|
||||
extern int mas_remove_platform(void);
|
||||
extern void ma_spi_change(struct spi_device *spi, unsigned int speed, int flag);
|
||||
extern int mas_get_interrupt_gpio(unsigned int index);
|
||||
extern int mas_switch_power(unsigned int on_off);
|
||||
extern int mas_do_some_for_probe(struct spi_device *spi);
|
||||
//end
|
||||
|
||||
//use for the log print
|
||||
#define MALOG_TAG "MAFP_"
|
||||
//#define MALOGE(x) printk(KERN_ERR "%s%s: error log! the function %s is failed, ret = %d\n", MALOG_TAG, __func__, x, ret); //error log
|
||||
//#define MALOGF(x) printk(MALOGD_LEVEL "%s%s: debug log! %s!\n", MALOG_TAG, __func__, x); //flag log
|
||||
//#define MALOGD(x) MALOGF(x) //debug log
|
||||
//#define MALOGW(x) printk(KERN_WARNING "%s%s: warning log! the function %s's ret = %d\n", MALOG_TAG, __func__,x, ret); //warning log
|
||||
//use for the log print
|
||||
|
||||
#define MALOGD(fmt, args...) do{printk(KERN_ERR "<mafp>-dbg-[%04d]-[@%s]" fmt "\n", __LINE__, __FUNCTION__, ##args);}while(0)
|
||||
#define MALOGE(fmt, args...) do{printk(KERN_ERR "<mafp>-err-[%04d]-[@%s]" fmt "\n", __LINE__, __FUNCTION__, ##args);}while(0)
|
||||
#define MALOGF(x) do{printk(KERN_ERR "<mafp>-fun-[%04d]-[@%s] is called!\n", __LINE__, __FUNCTION__);}while(0)
|
||||
#define MALOGW(fmt, args...) do{printk(KERN_ERR "<mafp>-warn-[%04d]-[@%s]" fmt "\n", __LINE__, __FUNCTION__, ##args);}while(0)
|
||||
|
||||
|
||||
/**
|
||||
* the old ioctl command, compatible for the old version
|
||||
*/
|
||||
//ioctl cmd
|
||||
#ifdef COMPATIBLE_VERSION3
|
||||
#define IOCTL_DEBUG 0x100 //调试信息 //debug message
|
||||
#define IOCTL_IRQ_ENABLE 0x101 //中断使能 //enable interrupt
|
||||
#define IOCTL_SPI_SPEED 0x102 //SPI速度 //spi speed
|
||||
#define IOCTL_READ_FLEN 0x103 //读帧长度(保留) //the length of one frame
|
||||
#define IOCTL_LINK_DEV 0x104 //连接设备(保留) //connect the device
|
||||
#define IOCTL_COVER_NUM 0x105 //材料编号 //the index of the material
|
||||
#define IOCTL_GET_VDATE 0x106 //版本日期 //the date fo the version
|
||||
|
||||
#define IOCTL_CLR_INTF 0x110 //清除中断标志
|
||||
#define IOCTL_GET_INTF 0x111 //获取中断标志
|
||||
#define IOCTL_REPORT_FLAG 0x112 //上报标志
|
||||
#define IOCTL_REPORT_KEY 0x113 //上报键值
|
||||
#define IOCTL_SET_WORK 0x114 //设置工作
|
||||
#define IOCTL_GET_WORK 0x115 //获取工作
|
||||
#define IOCTL_SET_VALUE 0x116 //设值
|
||||
#define IOCTL_GET_VALUE 0x117 //取值
|
||||
#define IOCTL_TRIGGER 0x118 //自触发
|
||||
#define IOCTL_WAKE_LOCK 0x119 //唤醒上锁
|
||||
#define IOCTL_WAKE_UNLOCK 0x120 //唤醒解锁
|
||||
|
||||
#define IOCTL_SCREEN_ON 0x121
|
||||
|
||||
#define IOCTL_KEY_DOWN 0x121 //按下
|
||||
#define IOCTL_KEY_UP 0x122 //抬起
|
||||
#define IOCTL_SET_X 0x123 //偏移X
|
||||
#define IOCTL_SET_Y 0x124 //偏移Y
|
||||
#define IOCTL_KEY_TAP 0x125 //单击
|
||||
#define IOCTL_KEY_DTAP 0x126 //双击
|
||||
#define IOCTL_KEY_LTAP 0x127 //长按
|
||||
|
||||
#define IOCTL_ENABLE_CLK 0x128
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
#endif
|
||||
|
||||
#endif /* __MADEV_H_ */
|
||||
|
||||
486
drivers/input/fingerprint/microarray_fp/mtk-settings.c
Normal file
486
drivers/input/fingerprint/microarray_fp/mtk-settings.c
Normal file
@@ -0,0 +1,486 @@
|
||||
/* Copyright (C) MicroArray
|
||||
* MicroArray Fprint Driver Code
|
||||
* mtk-settings.c
|
||||
* Date: 2017-3-15
|
||||
* Version: v4.0.06
|
||||
* Author: guq
|
||||
* Contact: guq@microarray.com.cn
|
||||
*/
|
||||
|
||||
#include "mtk-settings.h"
|
||||
|
||||
#ifdef TEE_ID_COMPATIBLE_TRUSTKERNEL
|
||||
#include <linux/tee_fp.h>
|
||||
#endif
|
||||
static int ret;
|
||||
//pin control sturct data, define using for the dts settings,
|
||||
struct pinctrl *mas_finger_pinctrl;
|
||||
struct pinctrl_state *mas_finger_power2v8_on, *mas_finger_power2v8_off, //power2v8
|
||||
*mas_finger_power1v8_on, *mas_finger_power1v8_off, //power1v8
|
||||
*mas_finger_eint_on, *mas_finger_eint_off, //eint
|
||||
*mas_spi_ck_on, *mas_spi_ck_off, //for ck
|
||||
*mas_spi_cs_on, *mas_spi_cs_off, //for cs
|
||||
*mas_spi_mi_on, *mas_spi_mi_off, //for mi
|
||||
*mas_spi_mo_on, *mas_spi_mo_off, //for mo
|
||||
*mas_spi_default; //same odms only use default to setting the dts
|
||||
static struct device_node *node;
|
||||
|
||||
static unsigned int finger_int_pin;
|
||||
|
||||
/**
|
||||
* the platform struct start,for getting the platform device to set gpio state
|
||||
*/
|
||||
//#ifdef CONFIG_OF
|
||||
static struct of_device_id sof_match[] = {
|
||||
{ .compatible = MA_DTS_NAME, }, //this name is used for matching the dts device for settings the gpios
|
||||
};
|
||||
static struct of_device_id sof_dev_match[] = {
|
||||
{ .compatible = "microarray,microarray-fp", }, //this name is used for matching the dts device for settings the gpios
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, sof_match);
|
||||
MODULE_DEVICE_TABLE(of, sof_dev_match);
|
||||
//#endif
|
||||
static struct platform_driver spdrv = {
|
||||
.probe = mas_plat_probe,
|
||||
.remove = mas_plat_remove,
|
||||
.driver = {
|
||||
.name = MA_DRV_NAME,
|
||||
.owner = THIS_MODULE,
|
||||
//#ifdef CONFIG_OF
|
||||
.of_match_table = sof_match,
|
||||
//#endif
|
||||
}
|
||||
};
|
||||
/**
|
||||
* the platform struct start,for getting the platform device to set gpio state end
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* the spi struct date start,for getting the spi_device to set the spi clock enable start
|
||||
*/
|
||||
|
||||
struct spi_device_id sdev_id = {MA_DRV_NAME, 0};
|
||||
struct spi_driver sdrv = {
|
||||
.driver = {
|
||||
.name = MA_DRV_NAME,
|
||||
.bus = &spi_bus_type,
|
||||
.owner = THIS_MODULE,
|
||||
#ifdef CONFIG_OF
|
||||
.of_match_table = sof_dev_match,
|
||||
#endif
|
||||
},
|
||||
.probe = mas_probe,
|
||||
.remove = mas_remove,
|
||||
.id_table = &sdev_id,
|
||||
};
|
||||
|
||||
#ifdef TEE_ID_COMPATIBLE_TRUSTKERNEL
|
||||
//driver end
|
||||
static struct mt_chip_conf smt_conf = {
|
||||
.setuptime=15,
|
||||
.holdtime=15,
|
||||
.high_time=15, // 10--6m 15--4m 20--3m 30--2m [ 60--1m 120--0.5m 300--0.2m]
|
||||
.low_time=15,
|
||||
.cs_idletime=15,
|
||||
.ulthgh_thrsh=0,
|
||||
.cpol=0,
|
||||
.cpha=0,
|
||||
.rx_mlsb=SPI_MSB,
|
||||
.tx_mlsb=SPI_MSB,
|
||||
.tx_endian=0,
|
||||
.rx_endian=0,
|
||||
.com_mod=FIFO_TRANSFER,
|
||||
.pause=0,
|
||||
.finish_intr=5,
|
||||
.deassert=0,
|
||||
.ulthigh=0,
|
||||
.tckdly=0,
|
||||
};
|
||||
#endif
|
||||
|
||||
struct spi_board_info smt_info[] __initdata = {
|
||||
[0] = {
|
||||
.modalias = MA_DRV_NAME,
|
||||
.max_speed_hz = (4*1000000),
|
||||
.bus_num = 0,
|
||||
.chip_select = 0,
|
||||
.mode = SPI_MODE_0,
|
||||
//.controller_data = &smt_conf,
|
||||
},
|
||||
};
|
||||
//device end
|
||||
|
||||
/**
|
||||
* the spi struct date start,for getting the spi_device to set the spi clock enable end
|
||||
*/
|
||||
|
||||
|
||||
void mas_select_transfer(struct spi_device *spi, int len) {
|
||||
/* static int mode = -1;
|
||||
int tmp = len>32? DMA_TRANSFER: FIFO_TRANSFER;
|
||||
struct mt_chip_conf *conf = NULL;
|
||||
if(tmp!=mode) {
|
||||
conf = (struct mt_chip_conf *) spi->controller_data;
|
||||
conf->com_mod = tmp;
|
||||
spi_setup(spi);
|
||||
mode = tmp;
|
||||
}*/
|
||||
}
|
||||
|
||||
/*
|
||||
* set spi speed, often we must check whether the setting is efficient
|
||||
*/
|
||||
|
||||
void ma_spi_change(struct spi_device *spi, unsigned int speed, int flag)
|
||||
{
|
||||
/* struct mt_chip_conf *mcc = (struct mt_chip_conf *)spi->controller_data;
|
||||
if(flag == 0) {
|
||||
mcc->com_mod = FIFO_TRANSFER;
|
||||
} else {
|
||||
mcc->com_mod = DMA_TRANSFER;
|
||||
}
|
||||
mcc->high_time = speed;
|
||||
mcc->low_time = speed;
|
||||
if(spi_setup(spi) < 0){
|
||||
MALOGE("change the spi error!\n");
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
int mas_do_some_for_probe(struct spi_device *spi){
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int mas_get_platform(void) {
|
||||
MALOGD("start!");
|
||||
ret = platform_driver_register(&spdrv);
|
||||
if(ret){
|
||||
MALOGE("platform_driver_register");
|
||||
}
|
||||
/*MALOGD("start board info");
|
||||
ret = spi_register_board_info(smt_info, ARRAY_SIZE(smt_info));
|
||||
if(ret){
|
||||
MALOGE("spi_register_board_info");
|
||||
}*/
|
||||
|
||||
MALOGD("start register spi");
|
||||
ret = spi_register_driver(&sdrv);
|
||||
if(ret) {
|
||||
MALOGE("spi_register_driver");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int mas_remove_platform(void){
|
||||
spi_unregister_driver(&sdrv);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mas_finger_get_gpio_info(struct platform_device *pdev){
|
||||
MALOGD("start!");
|
||||
node = of_find_compatible_node(NULL, NULL, MA_DTS_NAME);
|
||||
//pdev = of_find_device_by_node(node);
|
||||
mas_finger_pinctrl = devm_pinctrl_get(&pdev->dev);
|
||||
if (IS_ERR(mas_finger_pinctrl)) {
|
||||
ret = PTR_ERR(mas_finger_pinctrl);
|
||||
dev_err(&pdev->dev, "mas_finger_pinctrl cannot find pinctrl\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
/** this is the demo, setup follow the requirement
|
||||
* mas_finger_eint_on = pinctrl_lookup_state(mas_finger_pinctrl, "finger_int_as_int");
|
||||
* if (IS_ERR(mas_finger_eint_on)) {
|
||||
* ret = PTR_ERR(mas_finger_eint_on);
|
||||
* dev_err(&pdev->dev, " Cannot find mas_finger pinctrl mas_finger_eint_on!\n");
|
||||
* return ret;
|
||||
* }
|
||||
* if needed, change the dts label and the pinctrl for the other gpio
|
||||
*/
|
||||
|
||||
|
||||
mas_finger_power2v8_on = pinctrl_lookup_state(mas_finger_pinctrl, "finger_power_en1");
|
||||
if (IS_ERR(mas_finger_power2v8_on)) {
|
||||
ret = PTR_ERR(mas_finger_power2v8_on);
|
||||
dev_err(&pdev->dev, " Cannot find mas_finger_power2v8_on pinctrl!\n");
|
||||
return ret;
|
||||
}
|
||||
mas_finger_power2v8_off = pinctrl_lookup_state(mas_finger_pinctrl, "finger_power_en0");
|
||||
if (IS_ERR(mas_finger_power2v8_off)) {
|
||||
ret = PTR_ERR(mas_finger_power2v8_off);
|
||||
dev_err(&pdev->dev, " Cannot find mas_finger_power2v8_off pinctrl!\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
mas_finger_power1v8_on = pinctrl_lookup_state(mas_finger_pinctrl, "finger_power_18v_en1");
|
||||
if (IS_ERR(mas_finger_power1v8_on)) {
|
||||
ret = PTR_ERR(mas_finger_power1v8_on);
|
||||
dev_err(&pdev->dev, " Cannot find mas_finger_power1v8_on pinctrl!\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
mas_finger_power1v8_off = pinctrl_lookup_state(mas_finger_pinctrl, "finger_power_18v_en0");
|
||||
if (IS_ERR(mas_finger_power1v8_off)) {
|
||||
ret = PTR_ERR(mas_finger_power1v8_off);
|
||||
dev_err(&pdev->dev, " Cannot find mas_finger_power1v8_off pinctrl!\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
mas_spi_mi_on = pinctrl_lookup_state(mas_finger_pinctrl, "finger_spi0_mi_as_spi0_mi");
|
||||
if (IS_ERR(mas_spi_mi_on)) {
|
||||
ret = PTR_ERR(mas_spi_mi_on);
|
||||
dev_err(&pdev->dev, " Cannot find mas_spi_mi_on pinctrl!\n");
|
||||
return ret;
|
||||
}
|
||||
mas_spi_mi_off = pinctrl_lookup_state(mas_finger_pinctrl, "finger_spi0_mi_as_gpio");
|
||||
if (IS_ERR(mas_spi_mi_off)) {
|
||||
ret = PTR_ERR(mas_spi_mi_off);
|
||||
dev_err(&pdev->dev, " Cannot find mas_spi_mi_off pinctrl!\n");
|
||||
return ret;
|
||||
}
|
||||
mas_spi_mo_on = pinctrl_lookup_state(mas_finger_pinctrl, "finger_spi0_mo_as_spi0_mo");
|
||||
if (IS_ERR(mas_spi_mo_on)) {
|
||||
ret = PTR_ERR(mas_spi_mo_on);
|
||||
dev_err(&pdev->dev, " Cannot find mas_spi_mo_on pinctrl!\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
mas_spi_mo_off = pinctrl_lookup_state(mas_finger_pinctrl, "finger_spi0_mo_as_gpio");
|
||||
if (IS_ERR(mas_spi_mo_off)) {
|
||||
ret = PTR_ERR(mas_spi_mo_off);
|
||||
dev_err(&pdev->dev, " Cannot find mas_spi_mo_off!\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
mas_spi_ck_on = pinctrl_lookup_state(mas_finger_pinctrl, "finger_spi0_clk_as_spi0_clk");
|
||||
if (IS_ERR(mas_spi_ck_on)) {
|
||||
ret = PTR_ERR(mas_spi_ck_on);
|
||||
dev_err(&pdev->dev, " Cannot find mas_spi_ck_on pinctrl!\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
mas_spi_ck_off = pinctrl_lookup_state(mas_finger_pinctrl, "finger_spi0_clk_as_gpio");
|
||||
if (IS_ERR(mas_spi_ck_off)) {
|
||||
ret = PTR_ERR(mas_spi_ck_off);
|
||||
dev_err(&pdev->dev, " Cannot find mas_spi_ck_off pinctrl !\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
mas_spi_cs_on = pinctrl_lookup_state(mas_finger_pinctrl, "finger_spi0_cs_as_spi0_cs");
|
||||
if (IS_ERR(mas_spi_cs_on)) {
|
||||
ret = PTR_ERR(mas_spi_cs_on);
|
||||
dev_err(&pdev->dev, " Cannot find mas_spi_cs_on pinctrl!\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
mas_spi_cs_off = pinctrl_lookup_state(mas_finger_pinctrl, "finger_spi0_cs_as_gpio");
|
||||
if (IS_ERR(mas_spi_cs_off)) {
|
||||
ret = PTR_ERR(mas_spi_cs_off);
|
||||
dev_err(&pdev->dev, " Cannot find mas_spi_cs_off pinctrl!\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
mas_finger_eint_on = pinctrl_lookup_state(mas_finger_pinctrl, "finger_int_as_int");
|
||||
if (IS_ERR(mas_finger_eint_on)) {
|
||||
ret = PTR_ERR(mas_finger_eint_on);
|
||||
dev_err(&pdev->dev, " Cannot find mas_finger_eint_on pinctrl!\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
MALOGD("end!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mas_free_dts_info(void)
|
||||
{
|
||||
if(mas_finger_pinctrl != NULL) devm_pinctrl_put(mas_finger_pinctrl);
|
||||
}
|
||||
|
||||
int mas_finger_set_spi(int cmd){
|
||||
//#if 0
|
||||
switch(cmd)
|
||||
{
|
||||
case 0:
|
||||
if( (!IS_ERR(mas_spi_cs_off)) & (!IS_ERR(mas_spi_ck_off)) & (!IS_ERR(mas_spi_mi_off)) & (!IS_ERR(mas_spi_mo_off)) ){
|
||||
pinctrl_select_state(mas_finger_pinctrl, mas_spi_cs_off);
|
||||
pinctrl_select_state(mas_finger_pinctrl, mas_spi_ck_off);
|
||||
pinctrl_select_state(mas_finger_pinctrl, mas_spi_mi_off);
|
||||
pinctrl_select_state(mas_finger_pinctrl, mas_spi_mo_off);
|
||||
}else{
|
||||
MALOGE("mas_spi_gpio_slect_pinctrl cmd=0 err!");
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if( (!IS_ERR(mas_spi_cs_on)) & (!IS_ERR(mas_spi_ck_on)) & (!IS_ERR(mas_spi_mi_on)) & (!IS_ERR(mas_spi_mo_on)) ){
|
||||
pinctrl_select_state(mas_finger_pinctrl, mas_spi_cs_on);
|
||||
pinctrl_select_state(mas_finger_pinctrl, mas_spi_ck_on);
|
||||
pinctrl_select_state(mas_finger_pinctrl, mas_spi_mi_on);
|
||||
pinctrl_select_state(mas_finger_pinctrl, mas_spi_mo_on);
|
||||
}else{
|
||||
MALOGE("mas_spi_gpio_slect_pinctrl cmd=1 err!");
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
//#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void mas_finger_set_reset(int count)
|
||||
{
|
||||
pinctrl_select_state(mas_finger_pinctrl, mas_finger_power1v8_on);
|
||||
mdelay(count);
|
||||
pinctrl_select_state(mas_finger_pinctrl, mas_finger_power1v8_off);
|
||||
}
|
||||
|
||||
|
||||
int mas_finger_set_power(int cmd)
|
||||
{
|
||||
|
||||
pinctrl_select_state(mas_finger_pinctrl, mas_finger_power2v8_on);
|
||||
#if 0
|
||||
switch (cmd)
|
||||
{
|
||||
case 0 :
|
||||
if( (!IS_ERR(mas_finger_power2v8_off)) & (!IS_ERR(mas_finger_power1v8_off)) ){
|
||||
pinctrl_select_state(mas_finger_pinctrl, mas_finger_power2v8_off);
|
||||
//pinctrl_select_state(mas_finger_pinctrl, mas_finger_power1v8_off);
|
||||
}else{
|
||||
MALOGE("mas_power_gpio_slect_pinctrl cmd=0 err!");
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
case 1 :
|
||||
if( (!IS_ERR(mas_finger_power2v8_on)) & (!IS_ERR(mas_finger_power1v8_on)) ){
|
||||
pinctrl_select_state(mas_finger_pinctrl, mas_finger_power2v8_on);
|
||||
//pinctrl_select_state(mas_finger_pinctrl, mas_finger_power1v8_on);
|
||||
}else{
|
||||
MALOGE("mas_power_gpio_slect_pinctrl cmd=1 err!");
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* this is a demo function,if the power on-off switch by other way
|
||||
* modify it as the right way
|
||||
* on_off 1 on 0 off
|
||||
*/
|
||||
int mas_switch_power(unsigned int on_off){
|
||||
mas_finger_set_power(on_off); //use this fuction directly if the dts way
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mas_finger_set_eint(int cmd)
|
||||
{
|
||||
switch (cmd)
|
||||
{
|
||||
case 0 :
|
||||
if(!IS_ERR(mas_finger_eint_off)){
|
||||
pinctrl_select_state(mas_finger_pinctrl, mas_finger_eint_off);
|
||||
}else{
|
||||
MALOGE("mas_eint_gpio_slect_pinctrl cmd=0 err!");
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
case 1 :
|
||||
if(!IS_ERR(mas_finger_eint_on)){
|
||||
pinctrl_select_state(mas_finger_pinctrl, mas_finger_eint_on);
|
||||
}else{
|
||||
MALOGE("mas_eint_gpio_slect_pinctrl cmd=1 err!");
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int mas_finger_set_gpio_info(int cmd){
|
||||
ret = 0;
|
||||
MALOGD("start!");
|
||||
ret |= mas_finger_set_spi(cmd);
|
||||
ret |= mas_finger_set_power(cmd);
|
||||
// ret |= mas_finger_set_eint(cmd);
|
||||
MALOGD("end!");
|
||||
return ret;
|
||||
}
|
||||
|
||||
void mas_enable_spi_clock(struct spi_device *spi){
|
||||
|
||||
#if defined(TEE_ID_COMPATIBLE_TRUSTKERNEL) || defined(TEE_ID_COMPATIBLE_MICROTRUST)
|
||||
#ifdef CONFIG_MTK_CLKMGR
|
||||
enable_clock(MT_CG_PERI_SPI0, "spi");
|
||||
#elif defined(MT6797)
|
||||
mt_spi_enable_clk(spi_master_get_devdata(spi->master));
|
||||
#else
|
||||
mt_spi_enable_master_clk(spi);
|
||||
//enable_clk();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void mas_disable_spi_clock(struct spi_device *spi){
|
||||
|
||||
#if defined(TEE_ID_COMPATIBLE_TRUSTKERNEL) || defined(TEE_ID_COMPATIBLE_MICROTRUST)
|
||||
#ifdef CONFIG_MTK_CLKMGR
|
||||
disable_clock(MT_CG_PERI_SPI0, "spi");
|
||||
#elif defined(MT6797)
|
||||
mt_spi_disable_clk(spi_master_get_devdata(spi->master));
|
||||
#else
|
||||
mt_spi_disable_master_clk(spi);
|
||||
//disable_clk();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
int mas_tee_spi_transfer(u8 *txb, u8 *rxb, int len) {
|
||||
int val = 0;
|
||||
|
||||
#ifdef TEE_ID_COMPATIBLE_TRUSTKERNEL
|
||||
val = tee_spi_transfer(&smt_conf,sizeof(struct mt_chip_conf),txb, rxb, 4);
|
||||
#endif
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
unsigned int mas_get_irq(struct device *dev){
|
||||
int irq_num;
|
||||
finger_int_pin = of_get_named_gpio_flags(dev->of_node,
|
||||
"fingerprint,touch-int-gpio", 0, NULL);
|
||||
if (!gpio_is_valid(finger_int_pin)){
|
||||
MALOGE("invalid irq gpio!");
|
||||
return -EINVAL;
|
||||
}
|
||||
gpio_direction_input(finger_int_pin);
|
||||
irq_num = gpio_to_irq(finger_int_pin);
|
||||
return irq_num;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* this function used for check the interrupt gpio state
|
||||
* @index 0 gpio level 1 gpio mode, often use 0
|
||||
* @return 0 gpio low 1 gpio high if index = 1,the return is the gpio mode
|
||||
* under 0 the of_property_read_u32_index return errno,check the dts as below:
|
||||
* last but not least use this function must checkt the label on dts file, after is an example:
|
||||
* ma_finger: ma_finger{
|
||||
* compatible = "mediatek,afs120x";
|
||||
* finger_int_pin = <100 0>;
|
||||
* }
|
||||
*/
|
||||
int mas_get_interrupt_gpio(unsigned int index){
|
||||
int val;
|
||||
val = gpio_get_value(finger_int_pin);
|
||||
//printk if need
|
||||
return val;
|
||||
}
|
||||
|
||||
220
drivers/input/fingerprint/microarray_fp/mtk-settings.h
Normal file
220
drivers/input/fingerprint/microarray_fp/mtk-settings.h
Normal file
@@ -0,0 +1,220 @@
|
||||
/* Copyright (C) MicroArray
|
||||
* MicroArray Fprint Driver Code
|
||||
* mtk-settings.h
|
||||
* Date: 2017-3-15
|
||||
* Version: v4.0.06
|
||||
* Author: guq
|
||||
* Contact: guq@microarray.com.cn
|
||||
*/
|
||||
|
||||
#ifndef __MTK_SETTINGS_H_
|
||||
#define __MTK_SETTINGS_H_
|
||||
|
||||
|
||||
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/gpio.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/device.h>
|
||||
#include <linux/of_irq.h>
|
||||
#include <linux/of.h>
|
||||
#include <linux/of_address.h>
|
||||
#include <linux/of_platform.h>
|
||||
#include <linux/of_gpio.h>
|
||||
#include "madev.h"
|
||||
#include <linux/spi/spi.h>
|
||||
//#include <linux/wakelock.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/device.h>
|
||||
#include <linux/mutex.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/compat.h>
|
||||
#include <linux/spi/spi.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/workqueue.h>
|
||||
#include <linux/kthread.h>
|
||||
#include <linux/sched.h>
|
||||
#include <linux/wait.h>
|
||||
#include <linux/time.h>
|
||||
#include <linux/input.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/cdev.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/delay.h>
|
||||
#include <asm/uaccess.h>
|
||||
#include <linux/gpio.h>
|
||||
#include <linux/spi/spi.h>
|
||||
////lude "mt_spi.h"
|
||||
//#include <linux/wakelock.h>
|
||||
////lude <mt-plat/mt_gpio.h>
|
||||
#ifdef CONFIG_MTK_CLKMGR
|
||||
#include "mach/mt_clkmgr.h"
|
||||
#endif
|
||||
//macro settings
|
||||
#include <linux/clk.h>
|
||||
|
||||
#define MA_DRV_NAME "madev"
|
||||
|
||||
#define MA_DTS_NAME "mediatek,microarray_finger"
|
||||
|
||||
#define MA_EINT_DTS_NAME "mediatek,microarray_finger"
|
||||
|
||||
#define MA_INT_PIN_LABEL "finger_int_pin"
|
||||
//#define TEE_ID_COMPATIBLE_TRUSTKERNEL //TrustKernel TEE
|
||||
//#define TEE_ID_COMPATIBLE_MICROTRUST //MicroTrust TEE
|
||||
//macro settings end
|
||||
|
||||
|
||||
|
||||
//call madev function
|
||||
extern int mas_plat_probe(struct platform_device *pdev);
|
||||
extern int mas_plat_remove(struct platform_device *pdev);
|
||||
|
||||
extern int mas_probe(struct spi_device *spi);
|
||||
extern int mas_remove(struct spi_device *spi);
|
||||
|
||||
/* add for spi cls ctl start */
|
||||
#ifdef CONFIG_SPI_MT65XX
|
||||
|
||||
#include <linux/spi/spi.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/io.h>
|
||||
|
||||
enum spi_sample_sel {
|
||||
POSEDGE,
|
||||
NEGEDGE
|
||||
};
|
||||
enum spi_cs_pol {
|
||||
ACTIVE_LOW,
|
||||
ACTIVE_HIGH
|
||||
};
|
||||
|
||||
enum spi_cpol {
|
||||
SPI_CPOL_0,
|
||||
SPI_CPOL_1
|
||||
};
|
||||
|
||||
enum spi_cpha {
|
||||
SPI_CPHA_0,
|
||||
SPI_CPHA_1
|
||||
};
|
||||
|
||||
enum spi_mlsb {
|
||||
SPI_LSB,
|
||||
SPI_MSB
|
||||
};
|
||||
|
||||
enum spi_endian {
|
||||
SPI_LENDIAN,
|
||||
SPI_BENDIAN
|
||||
};
|
||||
|
||||
enum spi_transfer_mode {
|
||||
FIFO_TRANSFER,
|
||||
DMA_TRANSFER,
|
||||
OTHER1,
|
||||
OTHER2,
|
||||
};
|
||||
|
||||
enum spi_pause_mode {
|
||||
PAUSE_MODE_DISABLE,
|
||||
PAUSE_MODE_ENABLE
|
||||
};
|
||||
enum spi_finish_intr {
|
||||
FINISH_INTR_DIS,
|
||||
FINISH_INTR_EN,
|
||||
};
|
||||
|
||||
enum spi_deassert_mode {
|
||||
DEASSERT_DISABLE,
|
||||
DEASSERT_ENABLE
|
||||
};
|
||||
|
||||
enum spi_ulthigh {
|
||||
ULTRA_HIGH_DISABLE,
|
||||
ULTRA_HIGH_ENABLE
|
||||
};
|
||||
|
||||
enum spi_tckdly {
|
||||
TICK_DLY0,
|
||||
TICK_DLY1,
|
||||
TICK_DLY2,
|
||||
TICK_DLY3
|
||||
};
|
||||
|
||||
struct mt_chip_conf {
|
||||
u32 setuptime;
|
||||
u32 holdtime;
|
||||
u32 high_time;
|
||||
u32 low_time;
|
||||
u32 cs_idletime;
|
||||
u32 ulthgh_thrsh;
|
||||
enum spi_sample_sel sample_sel;
|
||||
enum spi_cs_pol cs_pol;
|
||||
enum spi_cpol cpol;
|
||||
enum spi_cpha cpha;
|
||||
enum spi_mlsb tx_mlsb;
|
||||
enum spi_mlsb rx_mlsb;
|
||||
enum spi_endian tx_endian;
|
||||
enum spi_endian rx_endian;
|
||||
enum spi_transfer_mode com_mod;
|
||||
enum spi_pause_mode pause;
|
||||
enum spi_finish_intr finish_intr;
|
||||
enum spi_deassert_mode deassert;
|
||||
enum spi_ulthigh ulthigh;
|
||||
enum spi_tckdly tckdly;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
struct mt_spi_t {
|
||||
struct platform_device *pdev;
|
||||
void __iomem *regs;
|
||||
int irq;
|
||||
int running;
|
||||
//struct wake_lock wk_lock;
|
||||
struct mt_chip_conf *config;
|
||||
struct spi_master *master;
|
||||
|
||||
struct spi_transfer *cur_transfer;
|
||||
struct spi_transfer *next_transfer;
|
||||
|
||||
spinlock_t lock;
|
||||
struct list_head queue;
|
||||
#if !defined(CONFIG_MTK_CLKMGR)
|
||||
struct clk *clk_main;
|
||||
#endif
|
||||
};
|
||||
void mt_spi_enable_clk(struct mt_spi_t *ms);
|
||||
void mt_spi_disable_clk(struct mt_spi_t *ms);
|
||||
void mt_spi_enable_master_clk(struct spi_device *spidev);
|
||||
void mt_spi_disable_master_clk(struct spi_device *spidev);
|
||||
|
||||
/* add for spi cls ctl end this func only used in tee enviroment*/
|
||||
//packaging
|
||||
//void mas_enable_spi_clock(struct spi_device *spi);
|
||||
//void mas_diasble_spi_clock(struct spi_device *spi);
|
||||
//packaging end
|
||||
|
||||
//the interface called by madev
|
||||
void mas_select_transfer(struct spi_device *spi, int len);
|
||||
int mas_finger_get_gpio_info(struct platform_device *pdev);
|
||||
int mas_finger_set_gpio_info(int cmd);
|
||||
void mas_enable_spi_clock(struct spi_device *spi);
|
||||
void mas_disable_spi_clock(struct spi_device *spi);
|
||||
|
||||
unsigned int mas_get_irq(struct device *dev);
|
||||
int mas_get_platform(void);
|
||||
int mas_remove_platform(void);
|
||||
int mas_power(int cmd);
|
||||
int get_screen(void);
|
||||
void ma_spi_change(struct spi_device *spi, unsigned int speed, int flag);
|
||||
int mas_get_interrupt_gpio(unsigned int index);
|
||||
int mas_switch_power(unsigned int on_off);
|
||||
int mas_do_some_for_probe(struct spi_device *spi);
|
||||
void mas_finger_set_reset(int count);
|
||||
void mas_free_dts_info(void);
|
||||
int mas_tee_spi_transfer(u8 *txb, u8 *rxb, int len);
|
||||
#endif
|
||||
14
drivers/input/hall/Kconfig
Normal file
14
drivers/input/hall/Kconfig
Normal file
@@ -0,0 +1,14 @@
|
||||
# SPDX-License-Identifier: GPL-2.0
|
||||
#
|
||||
# hall sensor drivers configuration
|
||||
#
|
||||
|
||||
# menuconfig HALL_DEVICE
|
||||
# tristate "hall sensor device support"
|
||||
|
||||
# if HALL_DEVICE
|
||||
|
||||
config HS_MH248
|
||||
tristate "hall sensor mh248"
|
||||
|
||||
# endif
|
||||
2
drivers/input/hall/Makefile
Normal file
2
drivers/input/hall/Makefile
Normal file
@@ -0,0 +1,2 @@
|
||||
# SPDX-License-Identifier: GPL-2.0
|
||||
obj-$(CONFIG_HS_MH248) += mh248.o
|
||||
211
drivers/input/hall/mh248.c
Executable file
211
drivers/input/hall/mh248.c
Executable file
@@ -0,0 +1,211 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
/*
|
||||
* Copyright (c) 2020 Rockchip Electronics Co. Ltd.
|
||||
*
|
||||
* Author: Bin Yang <yangbin@rock-chips.com>
|
||||
*/
|
||||
|
||||
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/irq.h>
|
||||
#include <linux/miscdevice.h>
|
||||
#include <linux/gpio.h>
|
||||
#include <linux/uaccess.h>
|
||||
#include <linux/atomic.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/input.h>
|
||||
#include <linux/workqueue.h>
|
||||
#include <linux/freezer.h>
|
||||
#include <linux/of_gpio.h>
|
||||
#include <linux/sensor-dev.h>
|
||||
#include <linux/fb.h>
|
||||
#include <linux/notifier.h>
|
||||
#include <linux/rk_keys.h>
|
||||
#include <linux/input.h>
|
||||
|
||||
struct mh248_para {
|
||||
struct device *dev;
|
||||
struct notifier_block fb_notif;
|
||||
struct mutex ops_lock;
|
||||
struct input_dev *hall_input;
|
||||
bool is_open;
|
||||
int is_suspend;
|
||||
int gpio_pin;
|
||||
int irq;
|
||||
int active_value;
|
||||
};
|
||||
struct mh248_para *g_mh248;
|
||||
|
||||
bool get_hall_status(void)
|
||||
{
|
||||
if(g_mh248) {
|
||||
return g_mh248->is_open;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
EXPORT_SYMBOL(get_hall_status);
|
||||
|
||||
static int hall_fb_notifier_callback(struct notifier_block *self,
|
||||
unsigned long action, void *data)
|
||||
{
|
||||
struct mh248_para *mh248;
|
||||
struct fb_event *event = data;
|
||||
|
||||
mh248 = container_of(self, struct mh248_para, fb_notif);
|
||||
|
||||
if (action != FB_EVENT_BLANK)
|
||||
return NOTIFY_DONE;
|
||||
|
||||
mutex_lock(&mh248->ops_lock);
|
||||
switch (*((int *)event->data)) {
|
||||
case FB_BLANK_UNBLANK:
|
||||
mh248->is_suspend = 0;
|
||||
break;
|
||||
default:
|
||||
mh248->is_suspend = 1;
|
||||
break;
|
||||
}
|
||||
mutex_unlock(&mh248->ops_lock);
|
||||
|
||||
return NOTIFY_OK;
|
||||
}
|
||||
|
||||
static irqreturn_t hall_mh248_interrupt(int irq, void *dev_id)
|
||||
{
|
||||
struct mh248_para *mh248 = (struct mh248_para *)dev_id;
|
||||
int gpio_value = 0;
|
||||
|
||||
gpio_value = gpio_get_value(mh248->gpio_pin);
|
||||
if ((gpio_value != mh248->active_value) ) {
|
||||
//input_report_key(mh248->hall_input, KEY_SLEEP, 1);
|
||||
//input_sync(mh248->hall_input);
|
||||
//input_report_key(mh248->hall_input, KEY_SLEEP, 0);
|
||||
mh248->is_open = false;
|
||||
input_report_switch(mh248->hall_input, SW_LID, 1);
|
||||
input_sync(mh248->hall_input);
|
||||
} else if ((gpio_value == mh248->active_value) ) {
|
||||
//input_report_key(mh248->hall_input, KEY_WAKEUP, 1);
|
||||
//input_sync(mh248->hall_input);
|
||||
//input_report_key(mh248->hall_input, KEY_WAKEUP, 0);
|
||||
mh248->is_open = true;
|
||||
input_report_switch(mh248->hall_input, SW_LID, 0);
|
||||
input_sync(mh248->hall_input);
|
||||
}
|
||||
|
||||
return IRQ_HANDLED;
|
||||
}
|
||||
|
||||
static int hall_mh248_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct device_node *np = pdev->dev.of_node;
|
||||
struct mh248_para *mh248;
|
||||
enum of_gpio_flags irq_flags;
|
||||
int hallactive = 0;
|
||||
int ret = 0;
|
||||
|
||||
mh248 = devm_kzalloc(&pdev->dev, sizeof(*mh248), GFP_KERNEL);
|
||||
if (!mh248)
|
||||
return -ENOMEM;
|
||||
|
||||
g_mh248 = mh248;
|
||||
mh248->dev = &pdev->dev;
|
||||
mh248->is_open = true;
|
||||
mh248->gpio_pin = of_get_named_gpio_flags(np, "irq-gpio",
|
||||
0, &irq_flags);
|
||||
if (!gpio_is_valid(mh248->gpio_pin)) {
|
||||
dev_err(mh248->dev, "Can not read property irq-gpio\n");
|
||||
return mh248->gpio_pin;
|
||||
}
|
||||
mh248->irq = gpio_to_irq(mh248->gpio_pin);
|
||||
|
||||
of_property_read_u32(np, "hall-active", &hallactive);
|
||||
mh248->active_value = hallactive;
|
||||
mh248->is_suspend = 0;
|
||||
mutex_init(&mh248->ops_lock);
|
||||
|
||||
ret = devm_gpio_request_one(mh248->dev, mh248->gpio_pin,
|
||||
GPIOF_DIR_IN, "hall_mh248");
|
||||
if (ret < 0) {
|
||||
dev_err(mh248->dev, "fail to request gpio:%d\n", mh248->gpio_pin);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = devm_request_threaded_irq(mh248->dev, mh248->irq,
|
||||
NULL, hall_mh248_interrupt,
|
||||
irq_flags | IRQF_NO_SUSPEND | IRQF_ONESHOT,
|
||||
"hall_mh248", mh248);
|
||||
if (ret < 0) {
|
||||
dev_err(mh248->dev, "request irq(%d) failed, ret=%d\n",
|
||||
mh248->irq, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
mh248->hall_input = devm_input_allocate_device(&pdev->dev);
|
||||
if (!mh248->hall_input) {
|
||||
dev_err(&pdev->dev, "Can't allocate hall input dev\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
mh248->hall_input->name = "hall wake key";
|
||||
//input_set_capability(mh248->hall_input, EV_KEY, KEY_SLEEP);
|
||||
//input_set_capability(mh248->hall_input, EV_KEY, KEY_WAKEUP);
|
||||
input_set_capability(mh248->hall_input, EV_SW, SW_LID);
|
||||
|
||||
ret = input_register_device(mh248->hall_input);
|
||||
if (ret) {
|
||||
dev_err(&pdev->dev, "Unable to register input device, error: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
enable_irq_wake(mh248->irq);
|
||||
mh248->fb_notif.notifier_call = hall_fb_notifier_callback;
|
||||
fb_register_client(&mh248->fb_notif);
|
||||
platform_set_drvdata(pdev, mh248);
|
||||
dev_info(mh248->dev, "hall_mh248_probe success.\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
#ifdef CONFIG_PM_SLEEP
|
||||
static int hall_mh248_resume(struct device *dev)
|
||||
{
|
||||
struct mh248_para *mh248 = dev_get_drvdata(dev);
|
||||
int gpio_value = 0;
|
||||
|
||||
gpio_value = gpio_get_value(mh248->gpio_pin);
|
||||
|
||||
if ((gpio_value == mh248->active_value) ) {
|
||||
input_report_switch(mh248->hall_input, SW_LID, 0);
|
||||
input_sync(mh248->hall_input);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct dev_pm_ops hall_mh248_pm_ops = {
|
||||
SET_SYSTEM_SLEEP_PM_OPS(NULL, hall_mh248_resume)
|
||||
|
||||
};
|
||||
#endif
|
||||
static const struct of_device_id hall_mh248_match[] = {
|
||||
{ .compatible = "hall-mh248" },
|
||||
{ /* Sentinel */ }
|
||||
};
|
||||
|
||||
static struct platform_driver hall_mh248_driver = {
|
||||
.probe = hall_mh248_probe,
|
||||
.driver = {
|
||||
.name = "mh248",
|
||||
.owner = THIS_MODULE,
|
||||
.of_match_table = hall_mh248_match,
|
||||
.pm = &hall_mh248_pm_ops,
|
||||
},
|
||||
};
|
||||
|
||||
module_platform_driver(hall_mh248_driver);
|
||||
|
||||
MODULE_ALIAS("platform:mh248");
|
||||
MODULE_AUTHOR("Bin Yang <yangbin@rock-chips.com>");
|
||||
MODULE_LICENSE("GPL v2");
|
||||
MODULE_DESCRIPTION("Hall Sensor MH248 driver");
|
||||
@@ -487,6 +487,10 @@ config LIGHT_DSMART_CARD
|
||||
help
|
||||
The DCD SMART CARD IP driver which follwing the ISO7816 Protocl on THEAD Light SoCs
|
||||
|
||||
config USBEN
|
||||
tristate "TVI1432V project usb enable item"
|
||||
default y
|
||||
|
||||
source "drivers/misc/c2port/Kconfig"
|
||||
source "drivers/misc/eeprom/Kconfig"
|
||||
source "drivers/misc/cb710/Kconfig"
|
||||
@@ -502,4 +506,5 @@ source "drivers/misc/ocxl/Kconfig"
|
||||
source "drivers/misc/cardreader/Kconfig"
|
||||
source "drivers/misc/habanalabs/Kconfig"
|
||||
source "drivers/misc/uacce/Kconfig"
|
||||
source "drivers/misc/hc32fx/Kconfig"
|
||||
endmenu
|
||||
|
||||
@@ -59,3 +59,5 @@ obj-$(CONFIG_XILINX_SDFEC) += xilinx_sdfec.o
|
||||
obj-$(CONFIG_HISI_HIKEY_USB) += hisi_hikey_usb.o
|
||||
obj-$(CONFIG_UID_SYS_STATS) += uid_sys_stats.o
|
||||
obj-$(CONFIG_LIGHT_DSMART_CARD) += dsmart_card.o
|
||||
obj-$(CONFIG_USBEN) += usb_en.o
|
||||
obj-$(CONFIG_MCU_HC32FX) += hc32fx/
|
||||
7
drivers/misc/hc32fx/Kconfig
Executable file
7
drivers/misc/hc32fx/Kconfig
Executable file
@@ -0,0 +1,7 @@
|
||||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
|
||||
config MCU_HC32FX
|
||||
tristate "enable hc32fx mcu"
|
||||
depends on I2C
|
||||
help
|
||||
enable hc32fx mcu
|
||||
3
drivers/misc/hc32fx/Makefile
Executable file
3
drivers/misc/hc32fx/Makefile
Executable file
@@ -0,0 +1,3 @@
|
||||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
|
||||
obj-$(CONFIG_MCU_HC32FX) += hc32fx_mcu.o
|
||||
284
drivers/misc/hc32fx/hc32fx_mcu.c
Normal file
284
drivers/misc/hc32fx/hc32fx_mcu.c
Normal file
@@ -0,0 +1,284 @@
|
||||
#include <linux/module.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/gpio.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/of_gpio.h>
|
||||
#include <linux/of_device.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/mutex.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/completion.h>
|
||||
#include <linux/kobject.h>
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/regmap.h>
|
||||
#include <linux/input.h>
|
||||
#include <linux/syscore_ops.h>
|
||||
#include "hc32fx_mcu.h"
|
||||
|
||||
#if 1
|
||||
#define DBG(x...) printk(x)
|
||||
#else
|
||||
#define DBG(x...) do { } while (0)
|
||||
#endif
|
||||
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
||||
|
||||
struct i2c_client *g_client;
|
||||
|
||||
struct hc32fx {
|
||||
int gpio_int;
|
||||
struct regmap *regmap;
|
||||
struct device dev;
|
||||
struct input_dev *input;
|
||||
};
|
||||
|
||||
int debug_array[] = {
|
||||
HC32FX_MCUVERSION_00,
|
||||
HC32FX_MCUSTATUS_10,
|
||||
HC32FX_SYSPOWERCONTROL_20,
|
||||
HC32FX_MCUUPDATESTATUS_E0,
|
||||
HC32FX_BOOTLOADERMODE_F1,
|
||||
};
|
||||
|
||||
static int debug_mode(void)
|
||||
{
|
||||
u32 rbuf;
|
||||
int i,ret;
|
||||
struct hc32fx *hc32fx = i2c_get_clientdata(g_client);
|
||||
|
||||
for(i=0; i<ARRAY_SIZE(debug_array); i++)
|
||||
{
|
||||
ret = regmap_read(hc32fx->regmap, debug_array[i], &rbuf);
|
||||
if(ret < 0)
|
||||
printk("read reg:0x%x fail \n", debug_array[i]);
|
||||
else
|
||||
printk("read reg:0x%x val:0x%x \n", debug_array[i], rbuf);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ssize_t debug_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
|
||||
{
|
||||
|
||||
if (!strncmp(buf, "debug", 5)) {
|
||||
debug_mode();
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
static DEVICE_ATTR_WO(debug);
|
||||
|
||||
static struct attribute *debug_attrs[] = {
|
||||
&dev_attr_debug.attr,
|
||||
NULL,
|
||||
};
|
||||
|
||||
static struct attribute_group debug_attr_group = {
|
||||
.attrs = debug_attrs,
|
||||
};
|
||||
|
||||
static void hc32fx_shutdown(struct i2c_client *client)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
static int hc32fx_suspend(struct device *dev)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int hc32fx_resume(struct device *dev)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int hc32fx_parse_dt(struct hc32fx *hc32fx)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int hc32fx_init(struct hc32fx *hc32fx)
|
||||
{
|
||||
// poweron, reset...
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool hc32fx_readable(struct device *dev, unsigned int reg)
|
||||
{
|
||||
if (reg <= HC32FX_MAXREG_FF)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool hc32fx_volatile(struct device *dev, unsigned int reg)
|
||||
{
|
||||
if (reg <= HC32FX_MAXREG_FF)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
static const struct regmap_config hc32fx_regmap_config = {
|
||||
.reg_bits = 8,
|
||||
.val_bits = 8,
|
||||
.max_register = HC32FX_MAXREG_FF,
|
||||
.cache_type = REGCACHE_RBTREE,
|
||||
.use_single_read = true,
|
||||
.use_single_write = true,
|
||||
.volatile_reg = hc32fx_volatile,
|
||||
.readable_reg = hc32fx_readable,
|
||||
};
|
||||
|
||||
static irqreturn_t hc32fx_irq_handler_thread(int irq, void *private)
|
||||
{
|
||||
DBG("%s %d \n", __func__, __LINE__);
|
||||
struct hc32fx *hc32fx = (struct hc32fx *)private;
|
||||
|
||||
input_report_key(hc32fx->input, KEY_POWER, 1);
|
||||
input_sync(hc32fx->input);
|
||||
|
||||
input_report_key(hc32fx->input, KEY_POWER, 0);
|
||||
input_sync(hc32fx->input);
|
||||
|
||||
return IRQ_HANDLED;
|
||||
}
|
||||
|
||||
static void TH1520_syscore_shutdown(void)
|
||||
{
|
||||
int ret;
|
||||
struct hc32fx *hc32fx = i2c_get_clientdata(g_client);
|
||||
|
||||
if (system_state == SYSTEM_POWER_OFF) {
|
||||
printk("power off %s\n", __func__);
|
||||
ret = regmap_write(hc32fx->regmap, HC32FX_SYSPOWERCONTROL_20, POWER_OFF);
|
||||
if (ret) {
|
||||
printk(" @@@@@@@@@@@@ fail power off %s %d \n",
|
||||
__func__, __LINE__);
|
||||
}
|
||||
mdelay(10);
|
||||
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
static struct syscore_ops TH1520_syscore_ops = {
|
||||
.shutdown = TH1520_syscore_shutdown,
|
||||
};
|
||||
|
||||
static int hc32fx_probe(struct i2c_client *client,
|
||||
const struct i2c_device_id *i2c_id)
|
||||
{
|
||||
int ret;
|
||||
struct hc32fx *hc32fx;
|
||||
|
||||
DBG("%s %d start\n", __func__, __LINE__);
|
||||
|
||||
struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
|
||||
if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
|
||||
dev_warn(&adapter->dev,
|
||||
"I2C-Adapter doesn't support I2C_FUNC_I2C\n");
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
hc32fx = devm_kzalloc(&client->dev, sizeof(struct hc32fx), GFP_KERNEL);
|
||||
if (!hc32fx) {
|
||||
dev_err(&client->dev, "failed to allocate memory\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
hc32fx->regmap = devm_regmap_init_i2c(client, &hc32fx_regmap_config);
|
||||
if (IS_ERR(hc32fx->regmap))
|
||||
return PTR_ERR(hc32fx->regmap);
|
||||
|
||||
i2c_set_clientdata(client, hc32fx);
|
||||
hc32fx->dev = client->dev;
|
||||
g_client = client;
|
||||
|
||||
hc32fx->input = devm_input_allocate_device(&client->dev);
|
||||
if (!hc32fx->input) {
|
||||
dev_err(&client->dev, "Can't allocate power button\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
hc32fx->input->name = "TH1520 pwrkey";
|
||||
hc32fx->input->phys = "TH1520_pwrkey/input0";
|
||||
hc32fx->input->id.bustype = BUS_HOST;
|
||||
input_set_capability(hc32fx->input, EV_KEY, KEY_POWER);
|
||||
|
||||
ret = input_register_device(hc32fx->input);
|
||||
if (ret) {
|
||||
dev_err(&client->dev, "Can't register power button: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = hc32fx_parse_dt(hc32fx);
|
||||
if (ret < 0) {
|
||||
dev_err(&client->dev, "[mcu] parse dt failed!\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = hc32fx_init(hc32fx);
|
||||
if (ret < 0) {
|
||||
dev_err(&client->dev, "[mcu] init failed!\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = sysfs_create_group(&hc32fx->dev.kobj, &debug_attr_group);
|
||||
if(ret) {
|
||||
dev_warn(&client->dev, "attr group create failed\n");
|
||||
}
|
||||
|
||||
if (client->irq < 0) {
|
||||
dev_err(&client->dev, "No irq resource found.\n");
|
||||
return client->irq;
|
||||
}
|
||||
|
||||
ret = devm_request_threaded_irq(&hc32fx->dev, client->irq, NULL,
|
||||
hc32fx_irq_handler_thread,
|
||||
IRQF_TRIGGER_FALLING | IRQF_ONESHOT, "hc32fx_irq",
|
||||
hc32fx);
|
||||
if (ret)
|
||||
goto irq_fail;
|
||||
enable_irq_wake(client->irq);
|
||||
|
||||
register_syscore_ops(&TH1520_syscore_ops);
|
||||
DBG("%s %d end\n", __func__, __LINE__);
|
||||
|
||||
irq_fail:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct of_device_id hc32fx_of_match[] = {
|
||||
{.compatible = "hc32fx-mcu"},
|
||||
{}
|
||||
}
|
||||
MODULE_DEVICE_TABLE(of, hc32fx_of_match);
|
||||
|
||||
static const struct i2c_device_id hc32fx_id[] = {
|
||||
{ "hc32fx", 0 },
|
||||
{ }
|
||||
};
|
||||
MODULE_DEVICE_TABLE(i2c, hc32fx_id);
|
||||
|
||||
static const struct dev_pm_ops hc32fx_pm_ops = {
|
||||
.suspend = hc32fx_suspend,
|
||||
.resume = hc32fx_resume,
|
||||
};
|
||||
|
||||
static struct i2c_driver hc32fx_i2c_driver = {
|
||||
.driver = {
|
||||
.name = "hc32fx_driver",
|
||||
.pm = &hc32fx_pm_ops,
|
||||
.of_match_table = of_match_ptr(hc32fx_of_match),
|
||||
},
|
||||
.probe = hc32fx_probe,
|
||||
.shutdown = hc32fx_shutdown,
|
||||
.id_table = hc32fx_id,
|
||||
};
|
||||
|
||||
module_i2c_driver(hc32fx_i2c_driver);
|
||||
MODULE_AUTHOR("lin_jiayong@techvision.com.cn");
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_DESCRIPTION("driver for HC32F005C6UA MCU");
|
||||
14
drivers/misc/hc32fx/hc32fx_mcu.h
Executable file
14
drivers/misc/hc32fx/hc32fx_mcu.h
Executable file
@@ -0,0 +1,14 @@
|
||||
#ifndef _HC32Fx_H_
|
||||
#define _HC32Fx_H_
|
||||
|
||||
#define HC32FX_MCUVERSION_00 0x00
|
||||
#define HC32FX_MCUSTATUS_10 0x10
|
||||
#define HC32FX_SYSPOWERCONTROL_20 0x20
|
||||
#define HC32FX_MCUUPDATESTATUS_E0 0xE0
|
||||
#define HC32FX_BOOTLOADERMODE_F1 0xF1
|
||||
#define HC32FX_MAXREG_FF 0xFF
|
||||
|
||||
// MCU COMMAND
|
||||
#define POWER_OFF 0x55
|
||||
#define BOOTLOADER 0x1F
|
||||
#endif
|
||||
126
drivers/misc/usb_en.c
Normal file
126
drivers/misc/usb_en.c
Normal file
@@ -0,0 +1,126 @@
|
||||
#include <dt-bindings/gpio/gpio.h>
|
||||
#include <linux/gpio.h>
|
||||
#include <linux/of_gpio.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/delay.h>
|
||||
|
||||
struct usb_priv {
|
||||
unsigned int usbhost_en;
|
||||
unsigned int usbhub_en;
|
||||
unsigned int usb_sw;
|
||||
};
|
||||
struct usb_priv *priv;
|
||||
|
||||
static struct of_device_id usb_en_of_match[] = {
|
||||
{ .compatible = "usb_en" },
|
||||
{ }
|
||||
};
|
||||
|
||||
MODULE_DEVICE_TABLE(of, usb_en_of_match);
|
||||
|
||||
static int usb_en_probe(struct platform_device *pdev)
|
||||
{
|
||||
int ret=-1;
|
||||
struct device_node *node = pdev->dev.of_node;
|
||||
|
||||
struct usb_priv *usb_priv = devm_kzalloc(&pdev->dev, sizeof(*usb_priv), GFP_KERNEL);
|
||||
if (!usb_priv) {
|
||||
printk("%s failed to allocate driver data\n", __func__);
|
||||
return -ENOMEM;
|
||||
}
|
||||
priv = usb_priv;
|
||||
|
||||
ret = of_get_named_gpio_flags(node, "host-en-gpio", 0, NULL);
|
||||
if (ret < 0) {
|
||||
dev_err(&pdev->dev, "Can not read property host-en-gpio\n");
|
||||
} else {
|
||||
usb_priv->usbhost_en = ret;
|
||||
ret = devm_gpio_request(&pdev->dev, usb_priv->usbhost_en,
|
||||
"usbhost_en");
|
||||
if (ret < 0) {
|
||||
dev_err(&pdev->dev, "usbhost_en request fail\n");
|
||||
} else {
|
||||
gpio_direction_output(usb_priv->usbhost_en, 1);
|
||||
}
|
||||
}
|
||||
|
||||
ret = of_get_named_gpio_flags(node, "hub-en-gpio", 0, NULL);
|
||||
if (ret < 0) {
|
||||
dev_err(&pdev->dev, "Can not read property hub-en-gpio\n");
|
||||
} else {
|
||||
usb_priv->usbhub_en = ret;
|
||||
ret = devm_gpio_request(&pdev->dev, usb_priv->usbhub_en,
|
||||
"usbhub_en");
|
||||
if (ret < 0) {
|
||||
dev_err(&pdev->dev, "usbhub_en request fail\n");
|
||||
} else {
|
||||
gpio_direction_output(usb_priv->usbhub_en, 1);
|
||||
}
|
||||
}
|
||||
|
||||
ret = of_get_named_gpio_flags(node, "usb_sw-gpio", 0, NULL);
|
||||
if (ret < 0) {
|
||||
dev_err(&pdev->dev, "Can not read property usb_sw-gpio\n");
|
||||
} else {
|
||||
usb_priv->usb_sw = ret;
|
||||
ret = devm_gpio_request(&pdev->dev, usb_priv->usb_sw,
|
||||
"usb_sw");
|
||||
if (ret < 0) {
|
||||
dev_err(&pdev->dev, "usb_sw request fail\n");
|
||||
} else {
|
||||
gpio_direction_output(usb_priv->usb_sw, 0);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int usb_en_remove(struct platform_device *pdev)
|
||||
{
|
||||
printk("func: _________%s\n", __func__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_PM_SLEEP
|
||||
static int usb_en_suspend(struct device *dev)
|
||||
{
|
||||
printk("func: _________%s\n", __func__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int usb_en_resume(struct device *dev)
|
||||
{
|
||||
printk("func: _________%s\n", __func__);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static const struct dev_pm_ops usb_en_pm_ops = {
|
||||
#ifdef CONFIG_PM_SLEEP
|
||||
.suspend = usb_en_suspend,
|
||||
.resume = usb_en_resume,
|
||||
.poweroff = usb_en_suspend,
|
||||
.restore = usb_en_resume,
|
||||
#endif
|
||||
};
|
||||
|
||||
static struct platform_driver usb_en_driver = {
|
||||
.driver = {
|
||||
.name = "usb_en",
|
||||
.owner = THIS_MODULE,
|
||||
.pm = &usb_en_pm_ops,
|
||||
.of_match_table = of_match_ptr(usb_en_of_match),
|
||||
},
|
||||
.probe = usb_en_probe,
|
||||
.remove = usb_en_remove,
|
||||
};
|
||||
|
||||
module_platform_driver(usb_en_driver);
|
||||
MODULE_DESCRIPTION("usb power control Driver");
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_ALIAS("platform:usb_en");
|
||||
@@ -51,6 +51,7 @@ source "drivers/net/wireless/quantenna/Kconfig"
|
||||
source "drivers/net/wireless/rtl8723ds/Kconfig"
|
||||
source "drivers/net/wireless/bcmdhd.101.10.361.x/Kconfig"
|
||||
source "drivers/net/wireless/aic8800/Kconfig"
|
||||
source "drivers/net/wireless/rtl8822cs/Kconfig"
|
||||
|
||||
config PCMCIA_RAYCS
|
||||
tristate "Aviator/Raytheon 2.4GHz wireless support"
|
||||
|
||||
@@ -35,3 +35,4 @@ obj-$(CONFIG_RTL8723DS) += rtl8723ds/
|
||||
obj-$(CONFIG_BCMDHD) += bcmdhd.101.10.361.x/
|
||||
|
||||
obj-$(CONFIG_AIC_WLAN_SUPPORT) += aic8800/
|
||||
obj-$(CONFIG_RTL8822CS) += rtl8822cs/
|
||||
|
||||
4
drivers/net/wireless/rtl8822cs/Kconfig
Normal file
4
drivers/net/wireless/rtl8822cs/Kconfig
Normal file
@@ -0,0 +1,4 @@
|
||||
config RTL8822CS
|
||||
tristate "Realtek 8822C SDIO WiFi"
|
||||
default y
|
||||
help
|
||||
2755
drivers/net/wireless/rtl8822cs/Makefile
Normal file
2755
drivers/net/wireless/rtl8822cs/Makefile
Normal file
File diff suppressed because it is too large
Load Diff
5
drivers/net/wireless/rtl8822cs/clean
Normal file
5
drivers/net/wireless/rtl8822cs/clean
Normal file
@@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
rmmod 8192cu
|
||||
rmmod 8192ce
|
||||
rmmod 8192du
|
||||
rmmod 8192de
|
||||
211
drivers/net/wireless/rtl8822cs/core/crypto/aes-ccm.c
Normal file
211
drivers/net/wireless/rtl8822cs/core/crypto/aes-ccm.c
Normal file
@@ -0,0 +1,211 @@
|
||||
/*
|
||||
* Counter with CBC-MAC (CCM) with AES
|
||||
*
|
||||
* Copyright (c) 2010-2012, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This software may be distributed under the terms of the BSD license.
|
||||
* See README for more details.
|
||||
*/
|
||||
|
||||
#include "rtw_crypto_wrap.h"
|
||||
|
||||
#include "aes.h"
|
||||
#include "aes_wrap.h"
|
||||
|
||||
|
||||
static void xor_aes_block(u8 *dst, const u8 *src)
|
||||
{
|
||||
u32 *d = (u32 *) dst;
|
||||
u32 *s = (u32 *) src;
|
||||
*d++ ^= *s++;
|
||||
*d++ ^= *s++;
|
||||
*d++ ^= *s++;
|
||||
*d++ ^= *s++;
|
||||
}
|
||||
|
||||
|
||||
static void aes_ccm_auth_start(void *aes, size_t M, size_t L, const u8 *nonce,
|
||||
const u8 *aad, size_t aad_len, size_t plain_len,
|
||||
u8 *x)
|
||||
{
|
||||
u8 aad_buf[2 * AES_BLOCK_SIZE];
|
||||
u8 b[AES_BLOCK_SIZE];
|
||||
|
||||
/* Authentication */
|
||||
/* B_0: Flags | Nonce N | l(m) */
|
||||
b[0] = aad_len ? 0x40 : 0 /* Adata */;
|
||||
b[0] |= (((M - 2) / 2) /* M' */ << 3);
|
||||
b[0] |= (L - 1) /* L' */;
|
||||
os_memcpy(&b[1], nonce, 15 - L);
|
||||
WPA_PUT_BE16(&b[AES_BLOCK_SIZE - L], plain_len);
|
||||
|
||||
wpa_hexdump_key(_MSG_EXCESSIVE_, "CCM B_0", b, AES_BLOCK_SIZE);
|
||||
wpa_aes_encrypt(aes, b, x); /* X_1 = E(K, B_0) */
|
||||
|
||||
if (!aad_len)
|
||||
return;
|
||||
|
||||
WPA_PUT_BE16(aad_buf, aad_len);
|
||||
os_memcpy(aad_buf + 2, aad, aad_len);
|
||||
os_memset(aad_buf + 2 + aad_len, 0, sizeof(aad_buf) - 2 - aad_len);
|
||||
|
||||
xor_aes_block(aad_buf, x);
|
||||
wpa_aes_encrypt(aes, aad_buf, x); /* X_2 = E(K, X_1 XOR B_1) */
|
||||
|
||||
if (aad_len > AES_BLOCK_SIZE - 2) {
|
||||
xor_aes_block(&aad_buf[AES_BLOCK_SIZE], x);
|
||||
/* X_3 = E(K, X_2 XOR B_2) */
|
||||
wpa_aes_encrypt(aes, &aad_buf[AES_BLOCK_SIZE], x);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void aes_ccm_auth(void *aes, const u8 *data, size_t len, u8 *x)
|
||||
{
|
||||
size_t last = len % AES_BLOCK_SIZE;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < len / AES_BLOCK_SIZE; i++) {
|
||||
/* X_i+1 = E(K, X_i XOR B_i) */
|
||||
xor_aes_block(x, data);
|
||||
data += AES_BLOCK_SIZE;
|
||||
wpa_aes_encrypt(aes, x, x);
|
||||
}
|
||||
if (last) {
|
||||
/* XOR zero-padded last block */
|
||||
for (i = 0; i < last; i++)
|
||||
x[i] ^= *data++;
|
||||
wpa_aes_encrypt(aes, x, x);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void aes_ccm_encr_start(size_t L, const u8 *nonce, u8 *a)
|
||||
{
|
||||
/* A_i = Flags | Nonce N | Counter i */
|
||||
a[0] = L - 1; /* Flags = L' */
|
||||
os_memcpy(&a[1], nonce, 15 - L);
|
||||
}
|
||||
|
||||
|
||||
static void aes_ccm_encr(void *aes, size_t L, const u8 *in, size_t len, u8 *out,
|
||||
u8 *a)
|
||||
{
|
||||
size_t last = len % AES_BLOCK_SIZE;
|
||||
size_t i;
|
||||
|
||||
/* crypt = msg XOR (S_1 | S_2 | ... | S_n) */
|
||||
for (i = 1; i <= len / AES_BLOCK_SIZE; i++) {
|
||||
WPA_PUT_BE16(&a[AES_BLOCK_SIZE - 2], i);
|
||||
/* S_i = E(K, A_i) */
|
||||
wpa_aes_encrypt(aes, a, out);
|
||||
xor_aes_block(out, in);
|
||||
out += AES_BLOCK_SIZE;
|
||||
in += AES_BLOCK_SIZE;
|
||||
}
|
||||
if (last) {
|
||||
WPA_PUT_BE16(&a[AES_BLOCK_SIZE - 2], i);
|
||||
wpa_aes_encrypt(aes, a, out);
|
||||
/* XOR zero-padded last block */
|
||||
for (i = 0; i < last; i++)
|
||||
*out++ ^= *in++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void aes_ccm_encr_auth(void *aes, size_t M, u8 *x, u8 *a, u8 *auth)
|
||||
{
|
||||
size_t i;
|
||||
u8 tmp[AES_BLOCK_SIZE];
|
||||
|
||||
wpa_hexdump_key(_MSG_EXCESSIVE_, "CCM T", x, M);
|
||||
/* U = T XOR S_0; S_0 = E(K, A_0) */
|
||||
WPA_PUT_BE16(&a[AES_BLOCK_SIZE - 2], 0);
|
||||
wpa_aes_encrypt(aes, a, tmp);
|
||||
for (i = 0; i < M; i++)
|
||||
auth[i] = x[i] ^ tmp[i];
|
||||
wpa_hexdump_key(_MSG_EXCESSIVE_, "CCM U", auth, M);
|
||||
}
|
||||
|
||||
|
||||
static void aes_ccm_decr_auth(void *aes, size_t M, u8 *a, const u8 *auth, u8 *t)
|
||||
{
|
||||
size_t i;
|
||||
u8 tmp[AES_BLOCK_SIZE];
|
||||
|
||||
wpa_hexdump_key(_MSG_EXCESSIVE_, "CCM U", auth, M);
|
||||
/* U = T XOR S_0; S_0 = E(K, A_0) */
|
||||
WPA_PUT_BE16(&a[AES_BLOCK_SIZE - 2], 0);
|
||||
wpa_aes_encrypt(aes, a, tmp);
|
||||
for (i = 0; i < M; i++)
|
||||
t[i] = auth[i] ^ tmp[i];
|
||||
wpa_hexdump_key(_MSG_EXCESSIVE_, "CCM T", t, M);
|
||||
}
|
||||
|
||||
|
||||
/* AES-CCM with fixed L=2 and aad_len <= 30 assumption */
|
||||
int aes_ccm_ae(const u8 *key, size_t key_len, const u8 *nonce,
|
||||
size_t M, const u8 *plain, size_t plain_len,
|
||||
const u8 *aad, size_t aad_len, u8 *crypt, u8 *auth)
|
||||
{
|
||||
const size_t L = 2;
|
||||
void *aes;
|
||||
u8 x[AES_BLOCK_SIZE], a[AES_BLOCK_SIZE];
|
||||
|
||||
if (aad_len > 30 || M > AES_BLOCK_SIZE)
|
||||
return -1;
|
||||
|
||||
aes = aes_encrypt_init(key, key_len);
|
||||
if (aes == NULL)
|
||||
return -1;
|
||||
|
||||
aes_ccm_auth_start(aes, M, L, nonce, aad, aad_len, plain_len, x);
|
||||
aes_ccm_auth(aes, plain, plain_len, x);
|
||||
|
||||
/* Encryption */
|
||||
aes_ccm_encr_start(L, nonce, a);
|
||||
aes_ccm_encr(aes, L, plain, plain_len, crypt, a);
|
||||
aes_ccm_encr_auth(aes, M, x, a, auth);
|
||||
|
||||
aes_encrypt_deinit(aes);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* AES-CCM with fixed L=2 and aad_len <= 30 assumption */
|
||||
int aes_ccm_ad(const u8 *key, size_t key_len, const u8 *nonce,
|
||||
size_t M, const u8 *crypt, size_t crypt_len,
|
||||
const u8 *aad, size_t aad_len, const u8 *auth, u8 *plain)
|
||||
{
|
||||
const size_t L = 2;
|
||||
void *aes;
|
||||
u8 x[AES_BLOCK_SIZE], a[AES_BLOCK_SIZE];
|
||||
u8 t[AES_BLOCK_SIZE];
|
||||
|
||||
if (aad_len > 30 || M > AES_BLOCK_SIZE)
|
||||
return -1;
|
||||
|
||||
aes = aes_encrypt_init(key, key_len);
|
||||
if (aes == NULL)
|
||||
return -1;
|
||||
|
||||
/* Decryption */
|
||||
aes_ccm_encr_start(L, nonce, a);
|
||||
aes_ccm_decr_auth(aes, M, a, auth, t);
|
||||
|
||||
/* plaintext = msg XOR (S_1 | S_2 | ... | S_n) */
|
||||
aes_ccm_encr(aes, L, crypt, crypt_len, plain, a);
|
||||
|
||||
aes_ccm_auth_start(aes, M, L, nonce, aad, aad_len, crypt_len, x);
|
||||
aes_ccm_auth(aes, plain, crypt_len, x);
|
||||
|
||||
aes_encrypt_deinit(aes);
|
||||
|
||||
if (os_memcmp_const(x, t, M) != 0) {
|
||||
wpa_printf(_MSG_EXCESSIVE_, "CCM: Auth mismatch");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
70
drivers/net/wireless/rtl8822cs/core/crypto/aes-ctr.c
Normal file
70
drivers/net/wireless/rtl8822cs/core/crypto/aes-ctr.c
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* AES-128/192/256 CTR
|
||||
*
|
||||
* Copyright (c) 2003-2007, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This software may be distributed under the terms of the BSD license.
|
||||
* See README for more details.
|
||||
*/
|
||||
|
||||
#include "rtw_crypto_wrap.h"
|
||||
|
||||
#include "aes.h"
|
||||
#include "aes_wrap.h"
|
||||
|
||||
/**
|
||||
* aes_ctr_encrypt - AES-128/192/256 CTR mode encryption
|
||||
* @key: Key for encryption (key_len bytes)
|
||||
* @key_len: Length of the key (16, 24, or 32 bytes)
|
||||
* @nonce: Nonce for counter mode (16 bytes)
|
||||
* @data: Data to encrypt in-place
|
||||
* @data_len: Length of data in bytes
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*/
|
||||
int aes_ctr_encrypt(const u8 *key, size_t key_len, const u8 *nonce,
|
||||
u8 *data, size_t data_len)
|
||||
{
|
||||
void *ctx;
|
||||
size_t j, len, left = data_len;
|
||||
int i;
|
||||
u8 *pos = data;
|
||||
u8 counter[AES_BLOCK_SIZE], buf[AES_BLOCK_SIZE];
|
||||
|
||||
ctx = aes_encrypt_init(key, key_len);
|
||||
if (ctx == NULL)
|
||||
return -1;
|
||||
os_memcpy(counter, nonce, AES_BLOCK_SIZE);
|
||||
|
||||
while (left > 0) {
|
||||
wpa_aes_encrypt(ctx, counter, buf);
|
||||
|
||||
len = (left < AES_BLOCK_SIZE) ? left : AES_BLOCK_SIZE;
|
||||
for (j = 0; j < len; j++)
|
||||
pos[j] ^= buf[j];
|
||||
pos += len;
|
||||
left -= len;
|
||||
|
||||
for (i = AES_BLOCK_SIZE - 1; i >= 0; i--) {
|
||||
counter[i]++;
|
||||
if (counter[i])
|
||||
break;
|
||||
}
|
||||
}
|
||||
aes_encrypt_deinit(ctx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* aes_128_ctr_encrypt - AES-128 CTR mode encryption
|
||||
* @key: Key for encryption (key_len bytes)
|
||||
* @nonce: Nonce for counter mode (16 bytes)
|
||||
* @data: Data to encrypt in-place
|
||||
* @data_len: Length of data in bytes
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*/
|
||||
int aes_128_ctr_encrypt(const u8 *key, const u8 *nonce,
|
||||
u8 *data, size_t data_len)
|
||||
{
|
||||
return aes_ctr_encrypt(key, 16, nonce, data, data_len);
|
||||
}
|
||||
326
drivers/net/wireless/rtl8822cs/core/crypto/aes-gcm.c
Normal file
326
drivers/net/wireless/rtl8822cs/core/crypto/aes-gcm.c
Normal file
@@ -0,0 +1,326 @@
|
||||
/*
|
||||
* Galois/Counter Mode (GCM) and GMAC with AES
|
||||
*
|
||||
* Copyright (c) 2012, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This software may be distributed under the terms of the BSD license.
|
||||
* See README for more details.
|
||||
*/
|
||||
|
||||
#include "rtw_crypto_wrap.h"
|
||||
|
||||
#include "aes.h"
|
||||
#include "aes_wrap.h"
|
||||
|
||||
static void inc32(u8 *block)
|
||||
{
|
||||
u32 val;
|
||||
val = WPA_GET_BE32(block + AES_BLOCK_SIZE - 4);
|
||||
val++;
|
||||
WPA_PUT_BE32(block + AES_BLOCK_SIZE - 4, val);
|
||||
}
|
||||
|
||||
|
||||
static void xor_block(u8 *dst, const u8 *src)
|
||||
{
|
||||
u32 *d = (u32 *) dst;
|
||||
u32 *s = (u32 *) src;
|
||||
*d++ ^= *s++;
|
||||
*d++ ^= *s++;
|
||||
*d++ ^= *s++;
|
||||
*d++ ^= *s++;
|
||||
}
|
||||
|
||||
|
||||
static void shift_right_block(u8 *v)
|
||||
{
|
||||
u32 val;
|
||||
|
||||
val = WPA_GET_BE32(v + 12);
|
||||
val >>= 1;
|
||||
if (v[11] & 0x01)
|
||||
val |= 0x80000000;
|
||||
WPA_PUT_BE32(v + 12, val);
|
||||
|
||||
val = WPA_GET_BE32(v + 8);
|
||||
val >>= 1;
|
||||
if (v[7] & 0x01)
|
||||
val |= 0x80000000;
|
||||
WPA_PUT_BE32(v + 8, val);
|
||||
|
||||
val = WPA_GET_BE32(v + 4);
|
||||
val >>= 1;
|
||||
if (v[3] & 0x01)
|
||||
val |= 0x80000000;
|
||||
WPA_PUT_BE32(v + 4, val);
|
||||
|
||||
val = WPA_GET_BE32(v);
|
||||
val >>= 1;
|
||||
WPA_PUT_BE32(v, val);
|
||||
}
|
||||
|
||||
|
||||
/* Multiplication in GF(2^128) */
|
||||
static void gf_mult(const u8 *x, const u8 *y, u8 *z)
|
||||
{
|
||||
u8 v[16];
|
||||
int i, j;
|
||||
|
||||
os_memset(z, 0, 16); /* Z_0 = 0^128 */
|
||||
os_memcpy(v, y, 16); /* V_0 = Y */
|
||||
|
||||
for (i = 0; i < 16; i++) {
|
||||
for (j = 0; j < 8; j++) {
|
||||
if (x[i] & BIT(7 - j)) {
|
||||
/* Z_(i + 1) = Z_i XOR V_i */
|
||||
xor_block(z, v);
|
||||
} else {
|
||||
/* Z_(i + 1) = Z_i */
|
||||
}
|
||||
|
||||
if (v[15] & 0x01) {
|
||||
/* V_(i + 1) = (V_i >> 1) XOR R */
|
||||
shift_right_block(v);
|
||||
/* R = 11100001 || 0^120 */
|
||||
v[0] ^= 0xe1;
|
||||
} else {
|
||||
/* V_(i + 1) = V_i >> 1 */
|
||||
shift_right_block(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void ghash_start(u8 *y)
|
||||
{
|
||||
/* Y_0 = 0^128 */
|
||||
os_memset(y, 0, 16);
|
||||
}
|
||||
|
||||
|
||||
static void ghash(const u8 *h, const u8 *x, size_t xlen, u8 *y)
|
||||
{
|
||||
size_t m, i;
|
||||
const u8 *xpos = x;
|
||||
u8 tmp[16];
|
||||
|
||||
m = xlen / 16;
|
||||
|
||||
for (i = 0; i < m; i++) {
|
||||
/* Y_i = (Y^(i-1) XOR X_i) dot H */
|
||||
xor_block(y, xpos);
|
||||
xpos += 16;
|
||||
|
||||
/* dot operation:
|
||||
* multiplication operation for binary Galois (finite) field of
|
||||
* 2^128 elements */
|
||||
gf_mult(y, h, tmp);
|
||||
os_memcpy(y, tmp, 16);
|
||||
}
|
||||
|
||||
if (x + xlen > xpos) {
|
||||
/* Add zero padded last block */
|
||||
size_t last = x + xlen - xpos;
|
||||
os_memcpy(tmp, xpos, last);
|
||||
os_memset(tmp + last, 0, sizeof(tmp) - last);
|
||||
|
||||
/* Y_i = (Y^(i-1) XOR X_i) dot H */
|
||||
xor_block(y, tmp);
|
||||
|
||||
/* dot operation:
|
||||
* multiplication operation for binary Galois (finite) field of
|
||||
* 2^128 elements */
|
||||
gf_mult(y, h, tmp);
|
||||
os_memcpy(y, tmp, 16);
|
||||
}
|
||||
|
||||
/* Return Y_m */
|
||||
}
|
||||
|
||||
|
||||
static void aes_gctr(void *aes, const u8 *icb, const u8 *x, size_t xlen, u8 *y)
|
||||
{
|
||||
size_t i, n, last;
|
||||
u8 cb[AES_BLOCK_SIZE], tmp[AES_BLOCK_SIZE];
|
||||
const u8 *xpos = x;
|
||||
u8 *ypos = y;
|
||||
|
||||
if (xlen == 0)
|
||||
return;
|
||||
|
||||
n = xlen / 16;
|
||||
|
||||
os_memcpy(cb, icb, AES_BLOCK_SIZE);
|
||||
/* Full blocks */
|
||||
for (i = 0; i < n; i++) {
|
||||
wpa_aes_encrypt(aes, cb, ypos);
|
||||
xor_block(ypos, xpos);
|
||||
xpos += AES_BLOCK_SIZE;
|
||||
ypos += AES_BLOCK_SIZE;
|
||||
inc32(cb);
|
||||
}
|
||||
|
||||
last = x + xlen - xpos;
|
||||
if (last) {
|
||||
/* Last, partial block */
|
||||
wpa_aes_encrypt(aes, cb, tmp);
|
||||
for (i = 0; i < last; i++)
|
||||
*ypos++ = *xpos++ ^ tmp[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void * aes_gcm_init_hash_subkey(const u8 *key, size_t key_len, u8 *H)
|
||||
{
|
||||
void *aes;
|
||||
|
||||
aes = aes_encrypt_init(key, key_len);
|
||||
if (aes == NULL)
|
||||
return NULL;
|
||||
|
||||
/* Generate hash subkey H = AES_K(0^128) */
|
||||
os_memset(H, 0, AES_BLOCK_SIZE);
|
||||
wpa_aes_encrypt(aes, H, H);
|
||||
wpa_hexdump_key(_MSG_EXCESSIVE_, "Hash subkey H for GHASH",
|
||||
H, AES_BLOCK_SIZE);
|
||||
return aes;
|
||||
}
|
||||
|
||||
|
||||
static void aes_gcm_prepare_j0(const u8 *iv, size_t iv_len, const u8 *H, u8 *J0)
|
||||
{
|
||||
u8 len_buf[16];
|
||||
|
||||
if (iv_len == 12) {
|
||||
/* Prepare block J_0 = IV || 0^31 || 1 [len(IV) = 96] */
|
||||
os_memcpy(J0, iv, iv_len);
|
||||
os_memset(J0 + iv_len, 0, AES_BLOCK_SIZE - iv_len);
|
||||
J0[AES_BLOCK_SIZE - 1] = 0x01;
|
||||
} else {
|
||||
/*
|
||||
* s = 128 * ceil(len(IV)/128) - len(IV)
|
||||
* J_0 = GHASH_H(IV || 0^(s+64) || [len(IV)]_64)
|
||||
*/
|
||||
ghash_start(J0);
|
||||
ghash(H, iv, iv_len, J0);
|
||||
WPA_PUT_BE64(len_buf, 0);
|
||||
WPA_PUT_BE64(len_buf + 8, iv_len * 8);
|
||||
ghash(H, len_buf, sizeof(len_buf), J0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void aes_gcm_gctr(void *aes, const u8 *J0, const u8 *in, size_t len,
|
||||
u8 *out)
|
||||
{
|
||||
u8 J0inc[AES_BLOCK_SIZE];
|
||||
|
||||
if (len == 0)
|
||||
return;
|
||||
|
||||
os_memcpy(J0inc, J0, AES_BLOCK_SIZE);
|
||||
inc32(J0inc);
|
||||
aes_gctr(aes, J0inc, in, len, out);
|
||||
}
|
||||
|
||||
|
||||
static void aes_gcm_ghash(const u8 *H, const u8 *aad, size_t aad_len,
|
||||
const u8 *crypt, size_t crypt_len, u8 *S)
|
||||
{
|
||||
u8 len_buf[16];
|
||||
|
||||
/*
|
||||
* u = 128 * ceil[len(C)/128] - len(C)
|
||||
* v = 128 * ceil[len(A)/128] - len(A)
|
||||
* S = GHASH_H(A || 0^v || C || 0^u || [len(A)]64 || [len(C)]64)
|
||||
* (i.e., zero padded to block size A || C and lengths of each in bits)
|
||||
*/
|
||||
ghash_start(S);
|
||||
ghash(H, aad, aad_len, S);
|
||||
ghash(H, crypt, crypt_len, S);
|
||||
WPA_PUT_BE64(len_buf, aad_len * 8);
|
||||
WPA_PUT_BE64(len_buf + 8, crypt_len * 8);
|
||||
ghash(H, len_buf, sizeof(len_buf), S);
|
||||
|
||||
wpa_hexdump_key(_MSG_EXCESSIVE_, "S = GHASH_H(...)", S, 16);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* aes_gcm_ae - GCM-AE_K(IV, P, A)
|
||||
*/
|
||||
int aes_gcm_ae(const u8 *key, size_t key_len, const u8 *iv, size_t iv_len,
|
||||
const u8 *plain, size_t plain_len,
|
||||
const u8 *aad, size_t aad_len, u8 *crypt, u8 *tag)
|
||||
{
|
||||
u8 H[AES_BLOCK_SIZE];
|
||||
u8 J0[AES_BLOCK_SIZE];
|
||||
u8 S[16];
|
||||
void *aes;
|
||||
|
||||
aes = aes_gcm_init_hash_subkey(key, key_len, H);
|
||||
if (aes == NULL)
|
||||
return -1;
|
||||
|
||||
aes_gcm_prepare_j0(iv, iv_len, H, J0);
|
||||
|
||||
/* C = GCTR_K(inc_32(J_0), P) */
|
||||
aes_gcm_gctr(aes, J0, plain, plain_len, crypt);
|
||||
|
||||
aes_gcm_ghash(H, aad, aad_len, crypt, plain_len, S);
|
||||
|
||||
/* T = MSB_t(GCTR_K(J_0, S)) */
|
||||
aes_gctr(aes, J0, S, sizeof(S), tag);
|
||||
|
||||
/* Return (C, T) */
|
||||
|
||||
aes_encrypt_deinit(aes);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* aes_gcm_ad - GCM-AD_K(IV, C, A, T)
|
||||
*/
|
||||
int aes_gcm_ad(const u8 *key, size_t key_len, const u8 *iv, size_t iv_len,
|
||||
const u8 *crypt, size_t crypt_len,
|
||||
const u8 *aad, size_t aad_len, const u8 *tag, u8 *plain)
|
||||
{
|
||||
u8 H[AES_BLOCK_SIZE];
|
||||
u8 J0[AES_BLOCK_SIZE];
|
||||
u8 S[16], T[16];
|
||||
void *aes;
|
||||
|
||||
aes = aes_gcm_init_hash_subkey(key, key_len, H);
|
||||
if (aes == NULL)
|
||||
return -1;
|
||||
|
||||
aes_gcm_prepare_j0(iv, iv_len, H, J0);
|
||||
|
||||
/* P = GCTR_K(inc_32(J_0), C) */
|
||||
aes_gcm_gctr(aes, J0, crypt, crypt_len, plain);
|
||||
|
||||
aes_gcm_ghash(H, aad, aad_len, crypt, crypt_len, S);
|
||||
|
||||
/* T' = MSB_t(GCTR_K(J_0, S)) */
|
||||
aes_gctr(aes, J0, S, sizeof(S), T);
|
||||
|
||||
aes_encrypt_deinit(aes);
|
||||
|
||||
if (os_memcmp_const(tag, T, 16) != 0) {
|
||||
wpa_printf(_MSG_EXCESSIVE_, "GCM: Tag mismatch");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int aes_gmac(const u8 *key, size_t key_len, const u8 *iv, size_t iv_len,
|
||||
const u8 *aad, size_t aad_len, u8 *tag)
|
||||
{
|
||||
return aes_gcm_ae(key, key_len, iv, iv_len, NULL, 0, aad, aad_len, NULL,
|
||||
tag);
|
||||
}
|
||||
129
drivers/net/wireless/rtl8822cs/core/crypto/aes-internal-enc.c
Normal file
129
drivers/net/wireless/rtl8822cs/core/crypto/aes-internal-enc.c
Normal file
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* AES (Rijndael) cipher - encrypt
|
||||
*
|
||||
* Modifications to public domain implementation:
|
||||
* - cleanup
|
||||
* - use C pre-processor to make it easier to change S table access
|
||||
* - added option (AES_SMALL_TABLES) for reducing code size by about 8 kB at
|
||||
* cost of reduced throughput (quite small difference on Pentium 4,
|
||||
* 10-25% when using -O1 or -O2 optimization)
|
||||
*
|
||||
* Copyright (c) 2003-2012, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This software may be distributed under the terms of the BSD license.
|
||||
* See README for more details.
|
||||
*/
|
||||
|
||||
#include "rtw_crypto_wrap.h"
|
||||
|
||||
#include "aes_i.h"
|
||||
|
||||
static void rijndaelEncrypt(const u32 rk[], int Nr, const u8 pt[16], u8 ct[16])
|
||||
{
|
||||
u32 s0, s1, s2, s3, t0, t1, t2, t3;
|
||||
#ifndef FULL_UNROLL
|
||||
int r;
|
||||
#endif /* ?FULL_UNROLL */
|
||||
|
||||
/*
|
||||
* map byte array block to cipher state
|
||||
* and add initial round key:
|
||||
*/
|
||||
s0 = GETU32(pt ) ^ rk[0];
|
||||
s1 = GETU32(pt + 4) ^ rk[1];
|
||||
s2 = GETU32(pt + 8) ^ rk[2];
|
||||
s3 = GETU32(pt + 12) ^ rk[3];
|
||||
|
||||
#define ROUND(i,d,s) \
|
||||
d##0 = TE0(s##0) ^ TE1(s##1) ^ TE2(s##2) ^ TE3(s##3) ^ rk[4 * i]; \
|
||||
d##1 = TE0(s##1) ^ TE1(s##2) ^ TE2(s##3) ^ TE3(s##0) ^ rk[4 * i + 1]; \
|
||||
d##2 = TE0(s##2) ^ TE1(s##3) ^ TE2(s##0) ^ TE3(s##1) ^ rk[4 * i + 2]; \
|
||||
d##3 = TE0(s##3) ^ TE1(s##0) ^ TE2(s##1) ^ TE3(s##2) ^ rk[4 * i + 3]
|
||||
|
||||
#ifdef FULL_UNROLL
|
||||
|
||||
ROUND(1,t,s);
|
||||
ROUND(2,s,t);
|
||||
ROUND(3,t,s);
|
||||
ROUND(4,s,t);
|
||||
ROUND(5,t,s);
|
||||
ROUND(6,s,t);
|
||||
ROUND(7,t,s);
|
||||
ROUND(8,s,t);
|
||||
ROUND(9,t,s);
|
||||
if (Nr > 10) {
|
||||
ROUND(10,s,t);
|
||||
ROUND(11,t,s);
|
||||
if (Nr > 12) {
|
||||
ROUND(12,s,t);
|
||||
ROUND(13,t,s);
|
||||
}
|
||||
}
|
||||
|
||||
rk += Nr << 2;
|
||||
|
||||
#else /* !FULL_UNROLL */
|
||||
|
||||
/* Nr - 1 full rounds: */
|
||||
r = Nr >> 1;
|
||||
for (;;) {
|
||||
ROUND(1,t,s);
|
||||
rk += 8;
|
||||
if (--r == 0)
|
||||
break;
|
||||
ROUND(0,s,t);
|
||||
}
|
||||
|
||||
#endif /* ?FULL_UNROLL */
|
||||
|
||||
#undef ROUND
|
||||
|
||||
/*
|
||||
* apply last round and
|
||||
* map cipher state to byte array block:
|
||||
*/
|
||||
s0 = TE41(t0) ^ TE42(t1) ^ TE43(t2) ^ TE44(t3) ^ rk[0];
|
||||
PUTU32(ct , s0);
|
||||
s1 = TE41(t1) ^ TE42(t2) ^ TE43(t3) ^ TE44(t0) ^ rk[1];
|
||||
PUTU32(ct + 4, s1);
|
||||
s2 = TE41(t2) ^ TE42(t3) ^ TE43(t0) ^ TE44(t1) ^ rk[2];
|
||||
PUTU32(ct + 8, s2);
|
||||
s3 = TE41(t3) ^ TE42(t0) ^ TE43(t1) ^ TE44(t2) ^ rk[3];
|
||||
PUTU32(ct + 12, s3);
|
||||
}
|
||||
|
||||
|
||||
void * aes_encrypt_init(const u8 *key, size_t len)
|
||||
{
|
||||
u32 *rk;
|
||||
int res;
|
||||
|
||||
if (TEST_FAIL())
|
||||
return NULL;
|
||||
|
||||
rk = os_malloc(AES_PRIV_SIZE);
|
||||
if (rk == NULL)
|
||||
return NULL;
|
||||
res = rijndaelKeySetupEnc(rk, key, len * 8);
|
||||
if (res < 0) {
|
||||
rtw_mfree(rk, AES_PRIV_SIZE);
|
||||
return NULL;
|
||||
}
|
||||
rk[AES_PRIV_NR_POS] = res;
|
||||
return rk;
|
||||
}
|
||||
|
||||
|
||||
int wpa_aes_encrypt(void *ctx, const u8 *plain, u8 *crypt)
|
||||
{
|
||||
u32 *rk = ctx;
|
||||
rijndaelEncrypt(ctx, rk[AES_PRIV_NR_POS], plain, crypt);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void aes_encrypt_deinit(void *ctx)
|
||||
{
|
||||
os_memset(ctx, 0, AES_PRIV_SIZE);
|
||||
rtw_mfree(ctx, AES_PRIV_SIZE);
|
||||
}
|
||||
843
drivers/net/wireless/rtl8822cs/core/crypto/aes-internal.c
Normal file
843
drivers/net/wireless/rtl8822cs/core/crypto/aes-internal.c
Normal file
@@ -0,0 +1,843 @@
|
||||
/*
|
||||
* AES (Rijndael) cipher
|
||||
*
|
||||
* Modifications to public domain implementation:
|
||||
* - cleanup
|
||||
* - use C pre-processor to make it easier to change S table access
|
||||
* - added option (AES_SMALL_TABLES) for reducing code size by about 8 kB at
|
||||
* cost of reduced throughput (quite small difference on Pentium 4,
|
||||
* 10-25% when using -O1 or -O2 optimization)
|
||||
*
|
||||
* Copyright (c) 2003-2012, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This software may be distributed under the terms of the BSD license.
|
||||
* See README for more details.
|
||||
*/
|
||||
|
||||
#include "rtw_crypto_wrap.h"
|
||||
|
||||
#include "aes_i.h"
|
||||
|
||||
/*
|
||||
* rijndael-alg-fst.c
|
||||
*
|
||||
* @version 3.0 (December 2000)
|
||||
*
|
||||
* Optimised ANSI C code for the Rijndael cipher (now AES)
|
||||
*
|
||||
* @author Vincent Rijmen <vincent.rijmen@esat.kuleuven.ac.be>
|
||||
* @author Antoon Bosselaers <antoon.bosselaers@esat.kuleuven.ac.be>
|
||||
* @author Paulo Barreto <paulo.barreto@terra.com.br>
|
||||
*
|
||||
* This code is hereby placed in the public domain.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
Te0[x] = S [x].[02, 01, 01, 03];
|
||||
Te1[x] = S [x].[03, 02, 01, 01];
|
||||
Te2[x] = S [x].[01, 03, 02, 01];
|
||||
Te3[x] = S [x].[01, 01, 03, 02];
|
||||
Te4[x] = S [x].[01, 01, 01, 01];
|
||||
|
||||
Td0[x] = Si[x].[0e, 09, 0d, 0b];
|
||||
Td1[x] = Si[x].[0b, 0e, 09, 0d];
|
||||
Td2[x] = Si[x].[0d, 0b, 0e, 09];
|
||||
Td3[x] = Si[x].[09, 0d, 0b, 0e];
|
||||
Td4[x] = Si[x].[01, 01, 01, 01];
|
||||
*/
|
||||
|
||||
const u32 Te0[256] = {
|
||||
0xc66363a5U, 0xf87c7c84U, 0xee777799U, 0xf67b7b8dU,
|
||||
0xfff2f20dU, 0xd66b6bbdU, 0xde6f6fb1U, 0x91c5c554U,
|
||||
0x60303050U, 0x02010103U, 0xce6767a9U, 0x562b2b7dU,
|
||||
0xe7fefe19U, 0xb5d7d762U, 0x4dababe6U, 0xec76769aU,
|
||||
0x8fcaca45U, 0x1f82829dU, 0x89c9c940U, 0xfa7d7d87U,
|
||||
0xeffafa15U, 0xb25959ebU, 0x8e4747c9U, 0xfbf0f00bU,
|
||||
0x41adadecU, 0xb3d4d467U, 0x5fa2a2fdU, 0x45afafeaU,
|
||||
0x239c9cbfU, 0x53a4a4f7U, 0xe4727296U, 0x9bc0c05bU,
|
||||
0x75b7b7c2U, 0xe1fdfd1cU, 0x3d9393aeU, 0x4c26266aU,
|
||||
0x6c36365aU, 0x7e3f3f41U, 0xf5f7f702U, 0x83cccc4fU,
|
||||
0x6834345cU, 0x51a5a5f4U, 0xd1e5e534U, 0xf9f1f108U,
|
||||
0xe2717193U, 0xabd8d873U, 0x62313153U, 0x2a15153fU,
|
||||
0x0804040cU, 0x95c7c752U, 0x46232365U, 0x9dc3c35eU,
|
||||
0x30181828U, 0x379696a1U, 0x0a05050fU, 0x2f9a9ab5U,
|
||||
0x0e070709U, 0x24121236U, 0x1b80809bU, 0xdfe2e23dU,
|
||||
0xcdebeb26U, 0x4e272769U, 0x7fb2b2cdU, 0xea75759fU,
|
||||
0x1209091bU, 0x1d83839eU, 0x582c2c74U, 0x341a1a2eU,
|
||||
0x361b1b2dU, 0xdc6e6eb2U, 0xb45a5aeeU, 0x5ba0a0fbU,
|
||||
0xa45252f6U, 0x763b3b4dU, 0xb7d6d661U, 0x7db3b3ceU,
|
||||
0x5229297bU, 0xdde3e33eU, 0x5e2f2f71U, 0x13848497U,
|
||||
0xa65353f5U, 0xb9d1d168U, 0x00000000U, 0xc1eded2cU,
|
||||
0x40202060U, 0xe3fcfc1fU, 0x79b1b1c8U, 0xb65b5bedU,
|
||||
0xd46a6abeU, 0x8dcbcb46U, 0x67bebed9U, 0x7239394bU,
|
||||
0x944a4adeU, 0x984c4cd4U, 0xb05858e8U, 0x85cfcf4aU,
|
||||
0xbbd0d06bU, 0xc5efef2aU, 0x4faaaae5U, 0xedfbfb16U,
|
||||
0x864343c5U, 0x9a4d4dd7U, 0x66333355U, 0x11858594U,
|
||||
0x8a4545cfU, 0xe9f9f910U, 0x04020206U, 0xfe7f7f81U,
|
||||
0xa05050f0U, 0x783c3c44U, 0x259f9fbaU, 0x4ba8a8e3U,
|
||||
0xa25151f3U, 0x5da3a3feU, 0x804040c0U, 0x058f8f8aU,
|
||||
0x3f9292adU, 0x219d9dbcU, 0x70383848U, 0xf1f5f504U,
|
||||
0x63bcbcdfU, 0x77b6b6c1U, 0xafdada75U, 0x42212163U,
|
||||
0x20101030U, 0xe5ffff1aU, 0xfdf3f30eU, 0xbfd2d26dU,
|
||||
0x81cdcd4cU, 0x180c0c14U, 0x26131335U, 0xc3ecec2fU,
|
||||
0xbe5f5fe1U, 0x359797a2U, 0x884444ccU, 0x2e171739U,
|
||||
0x93c4c457U, 0x55a7a7f2U, 0xfc7e7e82U, 0x7a3d3d47U,
|
||||
0xc86464acU, 0xba5d5de7U, 0x3219192bU, 0xe6737395U,
|
||||
0xc06060a0U, 0x19818198U, 0x9e4f4fd1U, 0xa3dcdc7fU,
|
||||
0x44222266U, 0x542a2a7eU, 0x3b9090abU, 0x0b888883U,
|
||||
0x8c4646caU, 0xc7eeee29U, 0x6bb8b8d3U, 0x2814143cU,
|
||||
0xa7dede79U, 0xbc5e5ee2U, 0x160b0b1dU, 0xaddbdb76U,
|
||||
0xdbe0e03bU, 0x64323256U, 0x743a3a4eU, 0x140a0a1eU,
|
||||
0x924949dbU, 0x0c06060aU, 0x4824246cU, 0xb85c5ce4U,
|
||||
0x9fc2c25dU, 0xbdd3d36eU, 0x43acacefU, 0xc46262a6U,
|
||||
0x399191a8U, 0x319595a4U, 0xd3e4e437U, 0xf279798bU,
|
||||
0xd5e7e732U, 0x8bc8c843U, 0x6e373759U, 0xda6d6db7U,
|
||||
0x018d8d8cU, 0xb1d5d564U, 0x9c4e4ed2U, 0x49a9a9e0U,
|
||||
0xd86c6cb4U, 0xac5656faU, 0xf3f4f407U, 0xcfeaea25U,
|
||||
0xca6565afU, 0xf47a7a8eU, 0x47aeaee9U, 0x10080818U,
|
||||
0x6fbabad5U, 0xf0787888U, 0x4a25256fU, 0x5c2e2e72U,
|
||||
0x381c1c24U, 0x57a6a6f1U, 0x73b4b4c7U, 0x97c6c651U,
|
||||
0xcbe8e823U, 0xa1dddd7cU, 0xe874749cU, 0x3e1f1f21U,
|
||||
0x964b4bddU, 0x61bdbddcU, 0x0d8b8b86U, 0x0f8a8a85U,
|
||||
0xe0707090U, 0x7c3e3e42U, 0x71b5b5c4U, 0xcc6666aaU,
|
||||
0x904848d8U, 0x06030305U, 0xf7f6f601U, 0x1c0e0e12U,
|
||||
0xc26161a3U, 0x6a35355fU, 0xae5757f9U, 0x69b9b9d0U,
|
||||
0x17868691U, 0x99c1c158U, 0x3a1d1d27U, 0x279e9eb9U,
|
||||
0xd9e1e138U, 0xebf8f813U, 0x2b9898b3U, 0x22111133U,
|
||||
0xd26969bbU, 0xa9d9d970U, 0x078e8e89U, 0x339494a7U,
|
||||
0x2d9b9bb6U, 0x3c1e1e22U, 0x15878792U, 0xc9e9e920U,
|
||||
0x87cece49U, 0xaa5555ffU, 0x50282878U, 0xa5dfdf7aU,
|
||||
0x038c8c8fU, 0x59a1a1f8U, 0x09898980U, 0x1a0d0d17U,
|
||||
0x65bfbfdaU, 0xd7e6e631U, 0x844242c6U, 0xd06868b8U,
|
||||
0x824141c3U, 0x299999b0U, 0x5a2d2d77U, 0x1e0f0f11U,
|
||||
0x7bb0b0cbU, 0xa85454fcU, 0x6dbbbbd6U, 0x2c16163aU,
|
||||
};
|
||||
#ifndef AES_SMALL_TABLES
|
||||
const u32 Te1[256] = {
|
||||
0xa5c66363U, 0x84f87c7cU, 0x99ee7777U, 0x8df67b7bU,
|
||||
0x0dfff2f2U, 0xbdd66b6bU, 0xb1de6f6fU, 0x5491c5c5U,
|
||||
0x50603030U, 0x03020101U, 0xa9ce6767U, 0x7d562b2bU,
|
||||
0x19e7fefeU, 0x62b5d7d7U, 0xe64dababU, 0x9aec7676U,
|
||||
0x458fcacaU, 0x9d1f8282U, 0x4089c9c9U, 0x87fa7d7dU,
|
||||
0x15effafaU, 0xebb25959U, 0xc98e4747U, 0x0bfbf0f0U,
|
||||
0xec41adadU, 0x67b3d4d4U, 0xfd5fa2a2U, 0xea45afafU,
|
||||
0xbf239c9cU, 0xf753a4a4U, 0x96e47272U, 0x5b9bc0c0U,
|
||||
0xc275b7b7U, 0x1ce1fdfdU, 0xae3d9393U, 0x6a4c2626U,
|
||||
0x5a6c3636U, 0x417e3f3fU, 0x02f5f7f7U, 0x4f83ccccU,
|
||||
0x5c683434U, 0xf451a5a5U, 0x34d1e5e5U, 0x08f9f1f1U,
|
||||
0x93e27171U, 0x73abd8d8U, 0x53623131U, 0x3f2a1515U,
|
||||
0x0c080404U, 0x5295c7c7U, 0x65462323U, 0x5e9dc3c3U,
|
||||
0x28301818U, 0xa1379696U, 0x0f0a0505U, 0xb52f9a9aU,
|
||||
0x090e0707U, 0x36241212U, 0x9b1b8080U, 0x3ddfe2e2U,
|
||||
0x26cdebebU, 0x694e2727U, 0xcd7fb2b2U, 0x9fea7575U,
|
||||
0x1b120909U, 0x9e1d8383U, 0x74582c2cU, 0x2e341a1aU,
|
||||
0x2d361b1bU, 0xb2dc6e6eU, 0xeeb45a5aU, 0xfb5ba0a0U,
|
||||
0xf6a45252U, 0x4d763b3bU, 0x61b7d6d6U, 0xce7db3b3U,
|
||||
0x7b522929U, 0x3edde3e3U, 0x715e2f2fU, 0x97138484U,
|
||||
0xf5a65353U, 0x68b9d1d1U, 0x00000000U, 0x2cc1ededU,
|
||||
0x60402020U, 0x1fe3fcfcU, 0xc879b1b1U, 0xedb65b5bU,
|
||||
0xbed46a6aU, 0x468dcbcbU, 0xd967bebeU, 0x4b723939U,
|
||||
0xde944a4aU, 0xd4984c4cU, 0xe8b05858U, 0x4a85cfcfU,
|
||||
0x6bbbd0d0U, 0x2ac5efefU, 0xe54faaaaU, 0x16edfbfbU,
|
||||
0xc5864343U, 0xd79a4d4dU, 0x55663333U, 0x94118585U,
|
||||
0xcf8a4545U, 0x10e9f9f9U, 0x06040202U, 0x81fe7f7fU,
|
||||
0xf0a05050U, 0x44783c3cU, 0xba259f9fU, 0xe34ba8a8U,
|
||||
0xf3a25151U, 0xfe5da3a3U, 0xc0804040U, 0x8a058f8fU,
|
||||
0xad3f9292U, 0xbc219d9dU, 0x48703838U, 0x04f1f5f5U,
|
||||
0xdf63bcbcU, 0xc177b6b6U, 0x75afdadaU, 0x63422121U,
|
||||
0x30201010U, 0x1ae5ffffU, 0x0efdf3f3U, 0x6dbfd2d2U,
|
||||
0x4c81cdcdU, 0x14180c0cU, 0x35261313U, 0x2fc3ececU,
|
||||
0xe1be5f5fU, 0xa2359797U, 0xcc884444U, 0x392e1717U,
|
||||
0x5793c4c4U, 0xf255a7a7U, 0x82fc7e7eU, 0x477a3d3dU,
|
||||
0xacc86464U, 0xe7ba5d5dU, 0x2b321919U, 0x95e67373U,
|
||||
0xa0c06060U, 0x98198181U, 0xd19e4f4fU, 0x7fa3dcdcU,
|
||||
0x66442222U, 0x7e542a2aU, 0xab3b9090U, 0x830b8888U,
|
||||
0xca8c4646U, 0x29c7eeeeU, 0xd36bb8b8U, 0x3c281414U,
|
||||
0x79a7dedeU, 0xe2bc5e5eU, 0x1d160b0bU, 0x76addbdbU,
|
||||
0x3bdbe0e0U, 0x56643232U, 0x4e743a3aU, 0x1e140a0aU,
|
||||
0xdb924949U, 0x0a0c0606U, 0x6c482424U, 0xe4b85c5cU,
|
||||
0x5d9fc2c2U, 0x6ebdd3d3U, 0xef43acacU, 0xa6c46262U,
|
||||
0xa8399191U, 0xa4319595U, 0x37d3e4e4U, 0x8bf27979U,
|
||||
0x32d5e7e7U, 0x438bc8c8U, 0x596e3737U, 0xb7da6d6dU,
|
||||
0x8c018d8dU, 0x64b1d5d5U, 0xd29c4e4eU, 0xe049a9a9U,
|
||||
0xb4d86c6cU, 0xfaac5656U, 0x07f3f4f4U, 0x25cfeaeaU,
|
||||
0xafca6565U, 0x8ef47a7aU, 0xe947aeaeU, 0x18100808U,
|
||||
0xd56fbabaU, 0x88f07878U, 0x6f4a2525U, 0x725c2e2eU,
|
||||
0x24381c1cU, 0xf157a6a6U, 0xc773b4b4U, 0x5197c6c6U,
|
||||
0x23cbe8e8U, 0x7ca1ddddU, 0x9ce87474U, 0x213e1f1fU,
|
||||
0xdd964b4bU, 0xdc61bdbdU, 0x860d8b8bU, 0x850f8a8aU,
|
||||
0x90e07070U, 0x427c3e3eU, 0xc471b5b5U, 0xaacc6666U,
|
||||
0xd8904848U, 0x05060303U, 0x01f7f6f6U, 0x121c0e0eU,
|
||||
0xa3c26161U, 0x5f6a3535U, 0xf9ae5757U, 0xd069b9b9U,
|
||||
0x91178686U, 0x5899c1c1U, 0x273a1d1dU, 0xb9279e9eU,
|
||||
0x38d9e1e1U, 0x13ebf8f8U, 0xb32b9898U, 0x33221111U,
|
||||
0xbbd26969U, 0x70a9d9d9U, 0x89078e8eU, 0xa7339494U,
|
||||
0xb62d9b9bU, 0x223c1e1eU, 0x92158787U, 0x20c9e9e9U,
|
||||
0x4987ceceU, 0xffaa5555U, 0x78502828U, 0x7aa5dfdfU,
|
||||
0x8f038c8cU, 0xf859a1a1U, 0x80098989U, 0x171a0d0dU,
|
||||
0xda65bfbfU, 0x31d7e6e6U, 0xc6844242U, 0xb8d06868U,
|
||||
0xc3824141U, 0xb0299999U, 0x775a2d2dU, 0x111e0f0fU,
|
||||
0xcb7bb0b0U, 0xfca85454U, 0xd66dbbbbU, 0x3a2c1616U,
|
||||
};
|
||||
const u32 Te2[256] = {
|
||||
0x63a5c663U, 0x7c84f87cU, 0x7799ee77U, 0x7b8df67bU,
|
||||
0xf20dfff2U, 0x6bbdd66bU, 0x6fb1de6fU, 0xc55491c5U,
|
||||
0x30506030U, 0x01030201U, 0x67a9ce67U, 0x2b7d562bU,
|
||||
0xfe19e7feU, 0xd762b5d7U, 0xabe64dabU, 0x769aec76U,
|
||||
0xca458fcaU, 0x829d1f82U, 0xc94089c9U, 0x7d87fa7dU,
|
||||
0xfa15effaU, 0x59ebb259U, 0x47c98e47U, 0xf00bfbf0U,
|
||||
0xadec41adU, 0xd467b3d4U, 0xa2fd5fa2U, 0xafea45afU,
|
||||
0x9cbf239cU, 0xa4f753a4U, 0x7296e472U, 0xc05b9bc0U,
|
||||
0xb7c275b7U, 0xfd1ce1fdU, 0x93ae3d93U, 0x266a4c26U,
|
||||
0x365a6c36U, 0x3f417e3fU, 0xf702f5f7U, 0xcc4f83ccU,
|
||||
0x345c6834U, 0xa5f451a5U, 0xe534d1e5U, 0xf108f9f1U,
|
||||
0x7193e271U, 0xd873abd8U, 0x31536231U, 0x153f2a15U,
|
||||
0x040c0804U, 0xc75295c7U, 0x23654623U, 0xc35e9dc3U,
|
||||
0x18283018U, 0x96a13796U, 0x050f0a05U, 0x9ab52f9aU,
|
||||
0x07090e07U, 0x12362412U, 0x809b1b80U, 0xe23ddfe2U,
|
||||
0xeb26cdebU, 0x27694e27U, 0xb2cd7fb2U, 0x759fea75U,
|
||||
0x091b1209U, 0x839e1d83U, 0x2c74582cU, 0x1a2e341aU,
|
||||
0x1b2d361bU, 0x6eb2dc6eU, 0x5aeeb45aU, 0xa0fb5ba0U,
|
||||
0x52f6a452U, 0x3b4d763bU, 0xd661b7d6U, 0xb3ce7db3U,
|
||||
0x297b5229U, 0xe33edde3U, 0x2f715e2fU, 0x84971384U,
|
||||
0x53f5a653U, 0xd168b9d1U, 0x00000000U, 0xed2cc1edU,
|
||||
0x20604020U, 0xfc1fe3fcU, 0xb1c879b1U, 0x5bedb65bU,
|
||||
0x6abed46aU, 0xcb468dcbU, 0xbed967beU, 0x394b7239U,
|
||||
0x4ade944aU, 0x4cd4984cU, 0x58e8b058U, 0xcf4a85cfU,
|
||||
0xd06bbbd0U, 0xef2ac5efU, 0xaae54faaU, 0xfb16edfbU,
|
||||
0x43c58643U, 0x4dd79a4dU, 0x33556633U, 0x85941185U,
|
||||
0x45cf8a45U, 0xf910e9f9U, 0x02060402U, 0x7f81fe7fU,
|
||||
0x50f0a050U, 0x3c44783cU, 0x9fba259fU, 0xa8e34ba8U,
|
||||
0x51f3a251U, 0xa3fe5da3U, 0x40c08040U, 0x8f8a058fU,
|
||||
0x92ad3f92U, 0x9dbc219dU, 0x38487038U, 0xf504f1f5U,
|
||||
0xbcdf63bcU, 0xb6c177b6U, 0xda75afdaU, 0x21634221U,
|
||||
0x10302010U, 0xff1ae5ffU, 0xf30efdf3U, 0xd26dbfd2U,
|
||||
0xcd4c81cdU, 0x0c14180cU, 0x13352613U, 0xec2fc3ecU,
|
||||
0x5fe1be5fU, 0x97a23597U, 0x44cc8844U, 0x17392e17U,
|
||||
0xc45793c4U, 0xa7f255a7U, 0x7e82fc7eU, 0x3d477a3dU,
|
||||
0x64acc864U, 0x5de7ba5dU, 0x192b3219U, 0x7395e673U,
|
||||
0x60a0c060U, 0x81981981U, 0x4fd19e4fU, 0xdc7fa3dcU,
|
||||
0x22664422U, 0x2a7e542aU, 0x90ab3b90U, 0x88830b88U,
|
||||
0x46ca8c46U, 0xee29c7eeU, 0xb8d36bb8U, 0x143c2814U,
|
||||
0xde79a7deU, 0x5ee2bc5eU, 0x0b1d160bU, 0xdb76addbU,
|
||||
0xe03bdbe0U, 0x32566432U, 0x3a4e743aU, 0x0a1e140aU,
|
||||
0x49db9249U, 0x060a0c06U, 0x246c4824U, 0x5ce4b85cU,
|
||||
0xc25d9fc2U, 0xd36ebdd3U, 0xacef43acU, 0x62a6c462U,
|
||||
0x91a83991U, 0x95a43195U, 0xe437d3e4U, 0x798bf279U,
|
||||
0xe732d5e7U, 0xc8438bc8U, 0x37596e37U, 0x6db7da6dU,
|
||||
0x8d8c018dU, 0xd564b1d5U, 0x4ed29c4eU, 0xa9e049a9U,
|
||||
0x6cb4d86cU, 0x56faac56U, 0xf407f3f4U, 0xea25cfeaU,
|
||||
0x65afca65U, 0x7a8ef47aU, 0xaee947aeU, 0x08181008U,
|
||||
0xbad56fbaU, 0x7888f078U, 0x256f4a25U, 0x2e725c2eU,
|
||||
0x1c24381cU, 0xa6f157a6U, 0xb4c773b4U, 0xc65197c6U,
|
||||
0xe823cbe8U, 0xdd7ca1ddU, 0x749ce874U, 0x1f213e1fU,
|
||||
0x4bdd964bU, 0xbddc61bdU, 0x8b860d8bU, 0x8a850f8aU,
|
||||
0x7090e070U, 0x3e427c3eU, 0xb5c471b5U, 0x66aacc66U,
|
||||
0x48d89048U, 0x03050603U, 0xf601f7f6U, 0x0e121c0eU,
|
||||
0x61a3c261U, 0x355f6a35U, 0x57f9ae57U, 0xb9d069b9U,
|
||||
0x86911786U, 0xc15899c1U, 0x1d273a1dU, 0x9eb9279eU,
|
||||
0xe138d9e1U, 0xf813ebf8U, 0x98b32b98U, 0x11332211U,
|
||||
0x69bbd269U, 0xd970a9d9U, 0x8e89078eU, 0x94a73394U,
|
||||
0x9bb62d9bU, 0x1e223c1eU, 0x87921587U, 0xe920c9e9U,
|
||||
0xce4987ceU, 0x55ffaa55U, 0x28785028U, 0xdf7aa5dfU,
|
||||
0x8c8f038cU, 0xa1f859a1U, 0x89800989U, 0x0d171a0dU,
|
||||
0xbfda65bfU, 0xe631d7e6U, 0x42c68442U, 0x68b8d068U,
|
||||
0x41c38241U, 0x99b02999U, 0x2d775a2dU, 0x0f111e0fU,
|
||||
0xb0cb7bb0U, 0x54fca854U, 0xbbd66dbbU, 0x163a2c16U,
|
||||
};
|
||||
const u32 Te3[256] = {
|
||||
|
||||
0x6363a5c6U, 0x7c7c84f8U, 0x777799eeU, 0x7b7b8df6U,
|
||||
0xf2f20dffU, 0x6b6bbdd6U, 0x6f6fb1deU, 0xc5c55491U,
|
||||
0x30305060U, 0x01010302U, 0x6767a9ceU, 0x2b2b7d56U,
|
||||
0xfefe19e7U, 0xd7d762b5U, 0xababe64dU, 0x76769aecU,
|
||||
0xcaca458fU, 0x82829d1fU, 0xc9c94089U, 0x7d7d87faU,
|
||||
0xfafa15efU, 0x5959ebb2U, 0x4747c98eU, 0xf0f00bfbU,
|
||||
0xadadec41U, 0xd4d467b3U, 0xa2a2fd5fU, 0xafafea45U,
|
||||
0x9c9cbf23U, 0xa4a4f753U, 0x727296e4U, 0xc0c05b9bU,
|
||||
0xb7b7c275U, 0xfdfd1ce1U, 0x9393ae3dU, 0x26266a4cU,
|
||||
0x36365a6cU, 0x3f3f417eU, 0xf7f702f5U, 0xcccc4f83U,
|
||||
0x34345c68U, 0xa5a5f451U, 0xe5e534d1U, 0xf1f108f9U,
|
||||
0x717193e2U, 0xd8d873abU, 0x31315362U, 0x15153f2aU,
|
||||
0x04040c08U, 0xc7c75295U, 0x23236546U, 0xc3c35e9dU,
|
||||
0x18182830U, 0x9696a137U, 0x05050f0aU, 0x9a9ab52fU,
|
||||
0x0707090eU, 0x12123624U, 0x80809b1bU, 0xe2e23ddfU,
|
||||
0xebeb26cdU, 0x2727694eU, 0xb2b2cd7fU, 0x75759feaU,
|
||||
0x09091b12U, 0x83839e1dU, 0x2c2c7458U, 0x1a1a2e34U,
|
||||
0x1b1b2d36U, 0x6e6eb2dcU, 0x5a5aeeb4U, 0xa0a0fb5bU,
|
||||
0x5252f6a4U, 0x3b3b4d76U, 0xd6d661b7U, 0xb3b3ce7dU,
|
||||
0x29297b52U, 0xe3e33eddU, 0x2f2f715eU, 0x84849713U,
|
||||
0x5353f5a6U, 0xd1d168b9U, 0x00000000U, 0xeded2cc1U,
|
||||
0x20206040U, 0xfcfc1fe3U, 0xb1b1c879U, 0x5b5bedb6U,
|
||||
0x6a6abed4U, 0xcbcb468dU, 0xbebed967U, 0x39394b72U,
|
||||
0x4a4ade94U, 0x4c4cd498U, 0x5858e8b0U, 0xcfcf4a85U,
|
||||
0xd0d06bbbU, 0xefef2ac5U, 0xaaaae54fU, 0xfbfb16edU,
|
||||
0x4343c586U, 0x4d4dd79aU, 0x33335566U, 0x85859411U,
|
||||
0x4545cf8aU, 0xf9f910e9U, 0x02020604U, 0x7f7f81feU,
|
||||
0x5050f0a0U, 0x3c3c4478U, 0x9f9fba25U, 0xa8a8e34bU,
|
||||
0x5151f3a2U, 0xa3a3fe5dU, 0x4040c080U, 0x8f8f8a05U,
|
||||
0x9292ad3fU, 0x9d9dbc21U, 0x38384870U, 0xf5f504f1U,
|
||||
0xbcbcdf63U, 0xb6b6c177U, 0xdada75afU, 0x21216342U,
|
||||
0x10103020U, 0xffff1ae5U, 0xf3f30efdU, 0xd2d26dbfU,
|
||||
0xcdcd4c81U, 0x0c0c1418U, 0x13133526U, 0xecec2fc3U,
|
||||
0x5f5fe1beU, 0x9797a235U, 0x4444cc88U, 0x1717392eU,
|
||||
0xc4c45793U, 0xa7a7f255U, 0x7e7e82fcU, 0x3d3d477aU,
|
||||
0x6464acc8U, 0x5d5de7baU, 0x19192b32U, 0x737395e6U,
|
||||
0x6060a0c0U, 0x81819819U, 0x4f4fd19eU, 0xdcdc7fa3U,
|
||||
0x22226644U, 0x2a2a7e54U, 0x9090ab3bU, 0x8888830bU,
|
||||
0x4646ca8cU, 0xeeee29c7U, 0xb8b8d36bU, 0x14143c28U,
|
||||
0xdede79a7U, 0x5e5ee2bcU, 0x0b0b1d16U, 0xdbdb76adU,
|
||||
0xe0e03bdbU, 0x32325664U, 0x3a3a4e74U, 0x0a0a1e14U,
|
||||
0x4949db92U, 0x06060a0cU, 0x24246c48U, 0x5c5ce4b8U,
|
||||
0xc2c25d9fU, 0xd3d36ebdU, 0xacacef43U, 0x6262a6c4U,
|
||||
0x9191a839U, 0x9595a431U, 0xe4e437d3U, 0x79798bf2U,
|
||||
0xe7e732d5U, 0xc8c8438bU, 0x3737596eU, 0x6d6db7daU,
|
||||
0x8d8d8c01U, 0xd5d564b1U, 0x4e4ed29cU, 0xa9a9e049U,
|
||||
0x6c6cb4d8U, 0x5656faacU, 0xf4f407f3U, 0xeaea25cfU,
|
||||
0x6565afcaU, 0x7a7a8ef4U, 0xaeaee947U, 0x08081810U,
|
||||
0xbabad56fU, 0x787888f0U, 0x25256f4aU, 0x2e2e725cU,
|
||||
0x1c1c2438U, 0xa6a6f157U, 0xb4b4c773U, 0xc6c65197U,
|
||||
0xe8e823cbU, 0xdddd7ca1U, 0x74749ce8U, 0x1f1f213eU,
|
||||
0x4b4bdd96U, 0xbdbddc61U, 0x8b8b860dU, 0x8a8a850fU,
|
||||
0x707090e0U, 0x3e3e427cU, 0xb5b5c471U, 0x6666aaccU,
|
||||
0x4848d890U, 0x03030506U, 0xf6f601f7U, 0x0e0e121cU,
|
||||
0x6161a3c2U, 0x35355f6aU, 0x5757f9aeU, 0xb9b9d069U,
|
||||
0x86869117U, 0xc1c15899U, 0x1d1d273aU, 0x9e9eb927U,
|
||||
0xe1e138d9U, 0xf8f813ebU, 0x9898b32bU, 0x11113322U,
|
||||
0x6969bbd2U, 0xd9d970a9U, 0x8e8e8907U, 0x9494a733U,
|
||||
0x9b9bb62dU, 0x1e1e223cU, 0x87879215U, 0xe9e920c9U,
|
||||
0xcece4987U, 0x5555ffaaU, 0x28287850U, 0xdfdf7aa5U,
|
||||
0x8c8c8f03U, 0xa1a1f859U, 0x89898009U, 0x0d0d171aU,
|
||||
0xbfbfda65U, 0xe6e631d7U, 0x4242c684U, 0x6868b8d0U,
|
||||
0x4141c382U, 0x9999b029U, 0x2d2d775aU, 0x0f0f111eU,
|
||||
0xb0b0cb7bU, 0x5454fca8U, 0xbbbbd66dU, 0x16163a2cU,
|
||||
};
|
||||
const u32 Te4[256] = {
|
||||
0x63636363U, 0x7c7c7c7cU, 0x77777777U, 0x7b7b7b7bU,
|
||||
0xf2f2f2f2U, 0x6b6b6b6bU, 0x6f6f6f6fU, 0xc5c5c5c5U,
|
||||
0x30303030U, 0x01010101U, 0x67676767U, 0x2b2b2b2bU,
|
||||
0xfefefefeU, 0xd7d7d7d7U, 0xababababU, 0x76767676U,
|
||||
0xcacacacaU, 0x82828282U, 0xc9c9c9c9U, 0x7d7d7d7dU,
|
||||
0xfafafafaU, 0x59595959U, 0x47474747U, 0xf0f0f0f0U,
|
||||
0xadadadadU, 0xd4d4d4d4U, 0xa2a2a2a2U, 0xafafafafU,
|
||||
0x9c9c9c9cU, 0xa4a4a4a4U, 0x72727272U, 0xc0c0c0c0U,
|
||||
0xb7b7b7b7U, 0xfdfdfdfdU, 0x93939393U, 0x26262626U,
|
||||
0x36363636U, 0x3f3f3f3fU, 0xf7f7f7f7U, 0xccccccccU,
|
||||
0x34343434U, 0xa5a5a5a5U, 0xe5e5e5e5U, 0xf1f1f1f1U,
|
||||
0x71717171U, 0xd8d8d8d8U, 0x31313131U, 0x15151515U,
|
||||
0x04040404U, 0xc7c7c7c7U, 0x23232323U, 0xc3c3c3c3U,
|
||||
0x18181818U, 0x96969696U, 0x05050505U, 0x9a9a9a9aU,
|
||||
0x07070707U, 0x12121212U, 0x80808080U, 0xe2e2e2e2U,
|
||||
0xebebebebU, 0x27272727U, 0xb2b2b2b2U, 0x75757575U,
|
||||
0x09090909U, 0x83838383U, 0x2c2c2c2cU, 0x1a1a1a1aU,
|
||||
0x1b1b1b1bU, 0x6e6e6e6eU, 0x5a5a5a5aU, 0xa0a0a0a0U,
|
||||
0x52525252U, 0x3b3b3b3bU, 0xd6d6d6d6U, 0xb3b3b3b3U,
|
||||
0x29292929U, 0xe3e3e3e3U, 0x2f2f2f2fU, 0x84848484U,
|
||||
0x53535353U, 0xd1d1d1d1U, 0x00000000U, 0xededededU,
|
||||
0x20202020U, 0xfcfcfcfcU, 0xb1b1b1b1U, 0x5b5b5b5bU,
|
||||
0x6a6a6a6aU, 0xcbcbcbcbU, 0xbebebebeU, 0x39393939U,
|
||||
0x4a4a4a4aU, 0x4c4c4c4cU, 0x58585858U, 0xcfcfcfcfU,
|
||||
0xd0d0d0d0U, 0xefefefefU, 0xaaaaaaaaU, 0xfbfbfbfbU,
|
||||
0x43434343U, 0x4d4d4d4dU, 0x33333333U, 0x85858585U,
|
||||
0x45454545U, 0xf9f9f9f9U, 0x02020202U, 0x7f7f7f7fU,
|
||||
0x50505050U, 0x3c3c3c3cU, 0x9f9f9f9fU, 0xa8a8a8a8U,
|
||||
0x51515151U, 0xa3a3a3a3U, 0x40404040U, 0x8f8f8f8fU,
|
||||
0x92929292U, 0x9d9d9d9dU, 0x38383838U, 0xf5f5f5f5U,
|
||||
0xbcbcbcbcU, 0xb6b6b6b6U, 0xdadadadaU, 0x21212121U,
|
||||
0x10101010U, 0xffffffffU, 0xf3f3f3f3U, 0xd2d2d2d2U,
|
||||
0xcdcdcdcdU, 0x0c0c0c0cU, 0x13131313U, 0xececececU,
|
||||
0x5f5f5f5fU, 0x97979797U, 0x44444444U, 0x17171717U,
|
||||
0xc4c4c4c4U, 0xa7a7a7a7U, 0x7e7e7e7eU, 0x3d3d3d3dU,
|
||||
0x64646464U, 0x5d5d5d5dU, 0x19191919U, 0x73737373U,
|
||||
0x60606060U, 0x81818181U, 0x4f4f4f4fU, 0xdcdcdcdcU,
|
||||
0x22222222U, 0x2a2a2a2aU, 0x90909090U, 0x88888888U,
|
||||
0x46464646U, 0xeeeeeeeeU, 0xb8b8b8b8U, 0x14141414U,
|
||||
0xdedededeU, 0x5e5e5e5eU, 0x0b0b0b0bU, 0xdbdbdbdbU,
|
||||
0xe0e0e0e0U, 0x32323232U, 0x3a3a3a3aU, 0x0a0a0a0aU,
|
||||
0x49494949U, 0x06060606U, 0x24242424U, 0x5c5c5c5cU,
|
||||
0xc2c2c2c2U, 0xd3d3d3d3U, 0xacacacacU, 0x62626262U,
|
||||
0x91919191U, 0x95959595U, 0xe4e4e4e4U, 0x79797979U,
|
||||
0xe7e7e7e7U, 0xc8c8c8c8U, 0x37373737U, 0x6d6d6d6dU,
|
||||
0x8d8d8d8dU, 0xd5d5d5d5U, 0x4e4e4e4eU, 0xa9a9a9a9U,
|
||||
0x6c6c6c6cU, 0x56565656U, 0xf4f4f4f4U, 0xeaeaeaeaU,
|
||||
0x65656565U, 0x7a7a7a7aU, 0xaeaeaeaeU, 0x08080808U,
|
||||
0xbabababaU, 0x78787878U, 0x25252525U, 0x2e2e2e2eU,
|
||||
0x1c1c1c1cU, 0xa6a6a6a6U, 0xb4b4b4b4U, 0xc6c6c6c6U,
|
||||
0xe8e8e8e8U, 0xddddddddU, 0x74747474U, 0x1f1f1f1fU,
|
||||
0x4b4b4b4bU, 0xbdbdbdbdU, 0x8b8b8b8bU, 0x8a8a8a8aU,
|
||||
0x70707070U, 0x3e3e3e3eU, 0xb5b5b5b5U, 0x66666666U,
|
||||
0x48484848U, 0x03030303U, 0xf6f6f6f6U, 0x0e0e0e0eU,
|
||||
0x61616161U, 0x35353535U, 0x57575757U, 0xb9b9b9b9U,
|
||||
0x86868686U, 0xc1c1c1c1U, 0x1d1d1d1dU, 0x9e9e9e9eU,
|
||||
0xe1e1e1e1U, 0xf8f8f8f8U, 0x98989898U, 0x11111111U,
|
||||
0x69696969U, 0xd9d9d9d9U, 0x8e8e8e8eU, 0x94949494U,
|
||||
0x9b9b9b9bU, 0x1e1e1e1eU, 0x87878787U, 0xe9e9e9e9U,
|
||||
0xcecececeU, 0x55555555U, 0x28282828U, 0xdfdfdfdfU,
|
||||
0x8c8c8c8cU, 0xa1a1a1a1U, 0x89898989U, 0x0d0d0d0dU,
|
||||
0xbfbfbfbfU, 0xe6e6e6e6U, 0x42424242U, 0x68686868U,
|
||||
0x41414141U, 0x99999999U, 0x2d2d2d2dU, 0x0f0f0f0fU,
|
||||
0xb0b0b0b0U, 0x54545454U, 0xbbbbbbbbU, 0x16161616U,
|
||||
};
|
||||
#endif /* AES_SMALL_TABLES */
|
||||
const u32 Td0[256] = {
|
||||
0x51f4a750U, 0x7e416553U, 0x1a17a4c3U, 0x3a275e96U,
|
||||
0x3bab6bcbU, 0x1f9d45f1U, 0xacfa58abU, 0x4be30393U,
|
||||
0x2030fa55U, 0xad766df6U, 0x88cc7691U, 0xf5024c25U,
|
||||
0x4fe5d7fcU, 0xc52acbd7U, 0x26354480U, 0xb562a38fU,
|
||||
0xdeb15a49U, 0x25ba1b67U, 0x45ea0e98U, 0x5dfec0e1U,
|
||||
0xc32f7502U, 0x814cf012U, 0x8d4697a3U, 0x6bd3f9c6U,
|
||||
0x038f5fe7U, 0x15929c95U, 0xbf6d7aebU, 0x955259daU,
|
||||
0xd4be832dU, 0x587421d3U, 0x49e06929U, 0x8ec9c844U,
|
||||
0x75c2896aU, 0xf48e7978U, 0x99583e6bU, 0x27b971ddU,
|
||||
0xbee14fb6U, 0xf088ad17U, 0xc920ac66U, 0x7dce3ab4U,
|
||||
0x63df4a18U, 0xe51a3182U, 0x97513360U, 0x62537f45U,
|
||||
0xb16477e0U, 0xbb6bae84U, 0xfe81a01cU, 0xf9082b94U,
|
||||
0x70486858U, 0x8f45fd19U, 0x94de6c87U, 0x527bf8b7U,
|
||||
0xab73d323U, 0x724b02e2U, 0xe31f8f57U, 0x6655ab2aU,
|
||||
0xb2eb2807U, 0x2fb5c203U, 0x86c57b9aU, 0xd33708a5U,
|
||||
0x302887f2U, 0x23bfa5b2U, 0x02036abaU, 0xed16825cU,
|
||||
0x8acf1c2bU, 0xa779b492U, 0xf307f2f0U, 0x4e69e2a1U,
|
||||
0x65daf4cdU, 0x0605bed5U, 0xd134621fU, 0xc4a6fe8aU,
|
||||
0x342e539dU, 0xa2f355a0U, 0x058ae132U, 0xa4f6eb75U,
|
||||
0x0b83ec39U, 0x4060efaaU, 0x5e719f06U, 0xbd6e1051U,
|
||||
0x3e218af9U, 0x96dd063dU, 0xdd3e05aeU, 0x4de6bd46U,
|
||||
0x91548db5U, 0x71c45d05U, 0x0406d46fU, 0x605015ffU,
|
||||
0x1998fb24U, 0xd6bde997U, 0x894043ccU, 0x67d99e77U,
|
||||
0xb0e842bdU, 0x07898b88U, 0xe7195b38U, 0x79c8eedbU,
|
||||
0xa17c0a47U, 0x7c420fe9U, 0xf8841ec9U, 0x00000000U,
|
||||
0x09808683U, 0x322bed48U, 0x1e1170acU, 0x6c5a724eU,
|
||||
0xfd0efffbU, 0x0f853856U, 0x3daed51eU, 0x362d3927U,
|
||||
0x0a0fd964U, 0x685ca621U, 0x9b5b54d1U, 0x24362e3aU,
|
||||
0x0c0a67b1U, 0x9357e70fU, 0xb4ee96d2U, 0x1b9b919eU,
|
||||
0x80c0c54fU, 0x61dc20a2U, 0x5a774b69U, 0x1c121a16U,
|
||||
0xe293ba0aU, 0xc0a02ae5U, 0x3c22e043U, 0x121b171dU,
|
||||
0x0e090d0bU, 0xf28bc7adU, 0x2db6a8b9U, 0x141ea9c8U,
|
||||
0x57f11985U, 0xaf75074cU, 0xee99ddbbU, 0xa37f60fdU,
|
||||
0xf701269fU, 0x5c72f5bcU, 0x44663bc5U, 0x5bfb7e34U,
|
||||
0x8b432976U, 0xcb23c6dcU, 0xb6edfc68U, 0xb8e4f163U,
|
||||
0xd731dccaU, 0x42638510U, 0x13972240U, 0x84c61120U,
|
||||
0x854a247dU, 0xd2bb3df8U, 0xaef93211U, 0xc729a16dU,
|
||||
0x1d9e2f4bU, 0xdcb230f3U, 0x0d8652ecU, 0x77c1e3d0U,
|
||||
0x2bb3166cU, 0xa970b999U, 0x119448faU, 0x47e96422U,
|
||||
0xa8fc8cc4U, 0xa0f03f1aU, 0x567d2cd8U, 0x223390efU,
|
||||
0x87494ec7U, 0xd938d1c1U, 0x8ccaa2feU, 0x98d40b36U,
|
||||
0xa6f581cfU, 0xa57ade28U, 0xdab78e26U, 0x3fadbfa4U,
|
||||
0x2c3a9de4U, 0x5078920dU, 0x6a5fcc9bU, 0x547e4662U,
|
||||
0xf68d13c2U, 0x90d8b8e8U, 0x2e39f75eU, 0x82c3aff5U,
|
||||
0x9f5d80beU, 0x69d0937cU, 0x6fd52da9U, 0xcf2512b3U,
|
||||
0xc8ac993bU, 0x10187da7U, 0xe89c636eU, 0xdb3bbb7bU,
|
||||
0xcd267809U, 0x6e5918f4U, 0xec9ab701U, 0x834f9aa8U,
|
||||
0xe6956e65U, 0xaaffe67eU, 0x21bccf08U, 0xef15e8e6U,
|
||||
0xbae79bd9U, 0x4a6f36ceU, 0xea9f09d4U, 0x29b07cd6U,
|
||||
0x31a4b2afU, 0x2a3f2331U, 0xc6a59430U, 0x35a266c0U,
|
||||
0x744ebc37U, 0xfc82caa6U, 0xe090d0b0U, 0x33a7d815U,
|
||||
0xf104984aU, 0x41ecdaf7U, 0x7fcd500eU, 0x1791f62fU,
|
||||
0x764dd68dU, 0x43efb04dU, 0xccaa4d54U, 0xe49604dfU,
|
||||
0x9ed1b5e3U, 0x4c6a881bU, 0xc12c1fb8U, 0x4665517fU,
|
||||
0x9d5eea04U, 0x018c355dU, 0xfa877473U, 0xfb0b412eU,
|
||||
0xb3671d5aU, 0x92dbd252U, 0xe9105633U, 0x6dd64713U,
|
||||
0x9ad7618cU, 0x37a10c7aU, 0x59f8148eU, 0xeb133c89U,
|
||||
0xcea927eeU, 0xb761c935U, 0xe11ce5edU, 0x7a47b13cU,
|
||||
0x9cd2df59U, 0x55f2733fU, 0x1814ce79U, 0x73c737bfU,
|
||||
0x53f7cdeaU, 0x5ffdaa5bU, 0xdf3d6f14U, 0x7844db86U,
|
||||
0xcaaff381U, 0xb968c43eU, 0x3824342cU, 0xc2a3405fU,
|
||||
0x161dc372U, 0xbce2250cU, 0x283c498bU, 0xff0d9541U,
|
||||
0x39a80171U, 0x080cb3deU, 0xd8b4e49cU, 0x6456c190U,
|
||||
0x7bcb8461U, 0xd532b670U, 0x486c5c74U, 0xd0b85742U,
|
||||
};
|
||||
#ifndef AES_SMALL_TABLES
|
||||
const u32 Td1[256] = {
|
||||
0x5051f4a7U, 0x537e4165U, 0xc31a17a4U, 0x963a275eU,
|
||||
0xcb3bab6bU, 0xf11f9d45U, 0xabacfa58U, 0x934be303U,
|
||||
0x552030faU, 0xf6ad766dU, 0x9188cc76U, 0x25f5024cU,
|
||||
0xfc4fe5d7U, 0xd7c52acbU, 0x80263544U, 0x8fb562a3U,
|
||||
0x49deb15aU, 0x6725ba1bU, 0x9845ea0eU, 0xe15dfec0U,
|
||||
0x02c32f75U, 0x12814cf0U, 0xa38d4697U, 0xc66bd3f9U,
|
||||
0xe7038f5fU, 0x9515929cU, 0xebbf6d7aU, 0xda955259U,
|
||||
0x2dd4be83U, 0xd3587421U, 0x2949e069U, 0x448ec9c8U,
|
||||
0x6a75c289U, 0x78f48e79U, 0x6b99583eU, 0xdd27b971U,
|
||||
0xb6bee14fU, 0x17f088adU, 0x66c920acU, 0xb47dce3aU,
|
||||
0x1863df4aU, 0x82e51a31U, 0x60975133U, 0x4562537fU,
|
||||
0xe0b16477U, 0x84bb6baeU, 0x1cfe81a0U, 0x94f9082bU,
|
||||
0x58704868U, 0x198f45fdU, 0x8794de6cU, 0xb7527bf8U,
|
||||
0x23ab73d3U, 0xe2724b02U, 0x57e31f8fU, 0x2a6655abU,
|
||||
0x07b2eb28U, 0x032fb5c2U, 0x9a86c57bU, 0xa5d33708U,
|
||||
0xf2302887U, 0xb223bfa5U, 0xba02036aU, 0x5ced1682U,
|
||||
0x2b8acf1cU, 0x92a779b4U, 0xf0f307f2U, 0xa14e69e2U,
|
||||
0xcd65daf4U, 0xd50605beU, 0x1fd13462U, 0x8ac4a6feU,
|
||||
0x9d342e53U, 0xa0a2f355U, 0x32058ae1U, 0x75a4f6ebU,
|
||||
0x390b83ecU, 0xaa4060efU, 0x065e719fU, 0x51bd6e10U,
|
||||
0xf93e218aU, 0x3d96dd06U, 0xaedd3e05U, 0x464de6bdU,
|
||||
0xb591548dU, 0x0571c45dU, 0x6f0406d4U, 0xff605015U,
|
||||
0x241998fbU, 0x97d6bde9U, 0xcc894043U, 0x7767d99eU,
|
||||
0xbdb0e842U, 0x8807898bU, 0x38e7195bU, 0xdb79c8eeU,
|
||||
0x47a17c0aU, 0xe97c420fU, 0xc9f8841eU, 0x00000000U,
|
||||
0x83098086U, 0x48322bedU, 0xac1e1170U, 0x4e6c5a72U,
|
||||
0xfbfd0effU, 0x560f8538U, 0x1e3daed5U, 0x27362d39U,
|
||||
0x640a0fd9U, 0x21685ca6U, 0xd19b5b54U, 0x3a24362eU,
|
||||
0xb10c0a67U, 0x0f9357e7U, 0xd2b4ee96U, 0x9e1b9b91U,
|
||||
0x4f80c0c5U, 0xa261dc20U, 0x695a774bU, 0x161c121aU,
|
||||
0x0ae293baU, 0xe5c0a02aU, 0x433c22e0U, 0x1d121b17U,
|
||||
0x0b0e090dU, 0xadf28bc7U, 0xb92db6a8U, 0xc8141ea9U,
|
||||
0x8557f119U, 0x4caf7507U, 0xbbee99ddU, 0xfda37f60U,
|
||||
0x9ff70126U, 0xbc5c72f5U, 0xc544663bU, 0x345bfb7eU,
|
||||
0x768b4329U, 0xdccb23c6U, 0x68b6edfcU, 0x63b8e4f1U,
|
||||
0xcad731dcU, 0x10426385U, 0x40139722U, 0x2084c611U,
|
||||
0x7d854a24U, 0xf8d2bb3dU, 0x11aef932U, 0x6dc729a1U,
|
||||
0x4b1d9e2fU, 0xf3dcb230U, 0xec0d8652U, 0xd077c1e3U,
|
||||
0x6c2bb316U, 0x99a970b9U, 0xfa119448U, 0x2247e964U,
|
||||
0xc4a8fc8cU, 0x1aa0f03fU, 0xd8567d2cU, 0xef223390U,
|
||||
0xc787494eU, 0xc1d938d1U, 0xfe8ccaa2U, 0x3698d40bU,
|
||||
0xcfa6f581U, 0x28a57adeU, 0x26dab78eU, 0xa43fadbfU,
|
||||
0xe42c3a9dU, 0x0d507892U, 0x9b6a5fccU, 0x62547e46U,
|
||||
0xc2f68d13U, 0xe890d8b8U, 0x5e2e39f7U, 0xf582c3afU,
|
||||
0xbe9f5d80U, 0x7c69d093U, 0xa96fd52dU, 0xb3cf2512U,
|
||||
0x3bc8ac99U, 0xa710187dU, 0x6ee89c63U, 0x7bdb3bbbU,
|
||||
0x09cd2678U, 0xf46e5918U, 0x01ec9ab7U, 0xa8834f9aU,
|
||||
0x65e6956eU, 0x7eaaffe6U, 0x0821bccfU, 0xe6ef15e8U,
|
||||
0xd9bae79bU, 0xce4a6f36U, 0xd4ea9f09U, 0xd629b07cU,
|
||||
0xaf31a4b2U, 0x312a3f23U, 0x30c6a594U, 0xc035a266U,
|
||||
0x37744ebcU, 0xa6fc82caU, 0xb0e090d0U, 0x1533a7d8U,
|
||||
0x4af10498U, 0xf741ecdaU, 0x0e7fcd50U, 0x2f1791f6U,
|
||||
0x8d764dd6U, 0x4d43efb0U, 0x54ccaa4dU, 0xdfe49604U,
|
||||
0xe39ed1b5U, 0x1b4c6a88U, 0xb8c12c1fU, 0x7f466551U,
|
||||
0x049d5eeaU, 0x5d018c35U, 0x73fa8774U, 0x2efb0b41U,
|
||||
0x5ab3671dU, 0x5292dbd2U, 0x33e91056U, 0x136dd647U,
|
||||
0x8c9ad761U, 0x7a37a10cU, 0x8e59f814U, 0x89eb133cU,
|
||||
0xeecea927U, 0x35b761c9U, 0xede11ce5U, 0x3c7a47b1U,
|
||||
0x599cd2dfU, 0x3f55f273U, 0x791814ceU, 0xbf73c737U,
|
||||
0xea53f7cdU, 0x5b5ffdaaU, 0x14df3d6fU, 0x867844dbU,
|
||||
0x81caaff3U, 0x3eb968c4U, 0x2c382434U, 0x5fc2a340U,
|
||||
0x72161dc3U, 0x0cbce225U, 0x8b283c49U, 0x41ff0d95U,
|
||||
0x7139a801U, 0xde080cb3U, 0x9cd8b4e4U, 0x906456c1U,
|
||||
0x617bcb84U, 0x70d532b6U, 0x74486c5cU, 0x42d0b857U,
|
||||
};
|
||||
const u32 Td2[256] = {
|
||||
0xa75051f4U, 0x65537e41U, 0xa4c31a17U, 0x5e963a27U,
|
||||
0x6bcb3babU, 0x45f11f9dU, 0x58abacfaU, 0x03934be3U,
|
||||
0xfa552030U, 0x6df6ad76U, 0x769188ccU, 0x4c25f502U,
|
||||
0xd7fc4fe5U, 0xcbd7c52aU, 0x44802635U, 0xa38fb562U,
|
||||
0x5a49deb1U, 0x1b6725baU, 0x0e9845eaU, 0xc0e15dfeU,
|
||||
0x7502c32fU, 0xf012814cU, 0x97a38d46U, 0xf9c66bd3U,
|
||||
0x5fe7038fU, 0x9c951592U, 0x7aebbf6dU, 0x59da9552U,
|
||||
0x832dd4beU, 0x21d35874U, 0x692949e0U, 0xc8448ec9U,
|
||||
0x896a75c2U, 0x7978f48eU, 0x3e6b9958U, 0x71dd27b9U,
|
||||
0x4fb6bee1U, 0xad17f088U, 0xac66c920U, 0x3ab47dceU,
|
||||
0x4a1863dfU, 0x3182e51aU, 0x33609751U, 0x7f456253U,
|
||||
0x77e0b164U, 0xae84bb6bU, 0xa01cfe81U, 0x2b94f908U,
|
||||
0x68587048U, 0xfd198f45U, 0x6c8794deU, 0xf8b7527bU,
|
||||
0xd323ab73U, 0x02e2724bU, 0x8f57e31fU, 0xab2a6655U,
|
||||
0x2807b2ebU, 0xc2032fb5U, 0x7b9a86c5U, 0x08a5d337U,
|
||||
0x87f23028U, 0xa5b223bfU, 0x6aba0203U, 0x825ced16U,
|
||||
0x1c2b8acfU, 0xb492a779U, 0xf2f0f307U, 0xe2a14e69U,
|
||||
0xf4cd65daU, 0xbed50605U, 0x621fd134U, 0xfe8ac4a6U,
|
||||
0x539d342eU, 0x55a0a2f3U, 0xe132058aU, 0xeb75a4f6U,
|
||||
0xec390b83U, 0xefaa4060U, 0x9f065e71U, 0x1051bd6eU,
|
||||
|
||||
0x8af93e21U, 0x063d96ddU, 0x05aedd3eU, 0xbd464de6U,
|
||||
0x8db59154U, 0x5d0571c4U, 0xd46f0406U, 0x15ff6050U,
|
||||
0xfb241998U, 0xe997d6bdU, 0x43cc8940U, 0x9e7767d9U,
|
||||
0x42bdb0e8U, 0x8b880789U, 0x5b38e719U, 0xeedb79c8U,
|
||||
0x0a47a17cU, 0x0fe97c42U, 0x1ec9f884U, 0x00000000U,
|
||||
0x86830980U, 0xed48322bU, 0x70ac1e11U, 0x724e6c5aU,
|
||||
0xfffbfd0eU, 0x38560f85U, 0xd51e3daeU, 0x3927362dU,
|
||||
0xd9640a0fU, 0xa621685cU, 0x54d19b5bU, 0x2e3a2436U,
|
||||
0x67b10c0aU, 0xe70f9357U, 0x96d2b4eeU, 0x919e1b9bU,
|
||||
0xc54f80c0U, 0x20a261dcU, 0x4b695a77U, 0x1a161c12U,
|
||||
0xba0ae293U, 0x2ae5c0a0U, 0xe0433c22U, 0x171d121bU,
|
||||
0x0d0b0e09U, 0xc7adf28bU, 0xa8b92db6U, 0xa9c8141eU,
|
||||
0x198557f1U, 0x074caf75U, 0xddbbee99U, 0x60fda37fU,
|
||||
0x269ff701U, 0xf5bc5c72U, 0x3bc54466U, 0x7e345bfbU,
|
||||
0x29768b43U, 0xc6dccb23U, 0xfc68b6edU, 0xf163b8e4U,
|
||||
0xdccad731U, 0x85104263U, 0x22401397U, 0x112084c6U,
|
||||
0x247d854aU, 0x3df8d2bbU, 0x3211aef9U, 0xa16dc729U,
|
||||
0x2f4b1d9eU, 0x30f3dcb2U, 0x52ec0d86U, 0xe3d077c1U,
|
||||
0x166c2bb3U, 0xb999a970U, 0x48fa1194U, 0x642247e9U,
|
||||
0x8cc4a8fcU, 0x3f1aa0f0U, 0x2cd8567dU, 0x90ef2233U,
|
||||
0x4ec78749U, 0xd1c1d938U, 0xa2fe8ccaU, 0x0b3698d4U,
|
||||
0x81cfa6f5U, 0xde28a57aU, 0x8e26dab7U, 0xbfa43fadU,
|
||||
0x9de42c3aU, 0x920d5078U, 0xcc9b6a5fU, 0x4662547eU,
|
||||
0x13c2f68dU, 0xb8e890d8U, 0xf75e2e39U, 0xaff582c3U,
|
||||
0x80be9f5dU, 0x937c69d0U, 0x2da96fd5U, 0x12b3cf25U,
|
||||
0x993bc8acU, 0x7da71018U, 0x636ee89cU, 0xbb7bdb3bU,
|
||||
0x7809cd26U, 0x18f46e59U, 0xb701ec9aU, 0x9aa8834fU,
|
||||
0x6e65e695U, 0xe67eaaffU, 0xcf0821bcU, 0xe8e6ef15U,
|
||||
0x9bd9bae7U, 0x36ce4a6fU, 0x09d4ea9fU, 0x7cd629b0U,
|
||||
0xb2af31a4U, 0x23312a3fU, 0x9430c6a5U, 0x66c035a2U,
|
||||
0xbc37744eU, 0xcaa6fc82U, 0xd0b0e090U, 0xd81533a7U,
|
||||
0x984af104U, 0xdaf741ecU, 0x500e7fcdU, 0xf62f1791U,
|
||||
0xd68d764dU, 0xb04d43efU, 0x4d54ccaaU, 0x04dfe496U,
|
||||
0xb5e39ed1U, 0x881b4c6aU, 0x1fb8c12cU, 0x517f4665U,
|
||||
0xea049d5eU, 0x355d018cU, 0x7473fa87U, 0x412efb0bU,
|
||||
0x1d5ab367U, 0xd25292dbU, 0x5633e910U, 0x47136dd6U,
|
||||
0x618c9ad7U, 0x0c7a37a1U, 0x148e59f8U, 0x3c89eb13U,
|
||||
0x27eecea9U, 0xc935b761U, 0xe5ede11cU, 0xb13c7a47U,
|
||||
0xdf599cd2U, 0x733f55f2U, 0xce791814U, 0x37bf73c7U,
|
||||
0xcdea53f7U, 0xaa5b5ffdU, 0x6f14df3dU, 0xdb867844U,
|
||||
0xf381caafU, 0xc43eb968U, 0x342c3824U, 0x405fc2a3U,
|
||||
0xc372161dU, 0x250cbce2U, 0x498b283cU, 0x9541ff0dU,
|
||||
0x017139a8U, 0xb3de080cU, 0xe49cd8b4U, 0xc1906456U,
|
||||
0x84617bcbU, 0xb670d532U, 0x5c74486cU, 0x5742d0b8U,
|
||||
};
|
||||
const u32 Td3[256] = {
|
||||
0xf4a75051U, 0x4165537eU, 0x17a4c31aU, 0x275e963aU,
|
||||
0xab6bcb3bU, 0x9d45f11fU, 0xfa58abacU, 0xe303934bU,
|
||||
0x30fa5520U, 0x766df6adU, 0xcc769188U, 0x024c25f5U,
|
||||
0xe5d7fc4fU, 0x2acbd7c5U, 0x35448026U, 0x62a38fb5U,
|
||||
0xb15a49deU, 0xba1b6725U, 0xea0e9845U, 0xfec0e15dU,
|
||||
0x2f7502c3U, 0x4cf01281U, 0x4697a38dU, 0xd3f9c66bU,
|
||||
0x8f5fe703U, 0x929c9515U, 0x6d7aebbfU, 0x5259da95U,
|
||||
0xbe832dd4U, 0x7421d358U, 0xe0692949U, 0xc9c8448eU,
|
||||
0xc2896a75U, 0x8e7978f4U, 0x583e6b99U, 0xb971dd27U,
|
||||
0xe14fb6beU, 0x88ad17f0U, 0x20ac66c9U, 0xce3ab47dU,
|
||||
0xdf4a1863U, 0x1a3182e5U, 0x51336097U, 0x537f4562U,
|
||||
0x6477e0b1U, 0x6bae84bbU, 0x81a01cfeU, 0x082b94f9U,
|
||||
0x48685870U, 0x45fd198fU, 0xde6c8794U, 0x7bf8b752U,
|
||||
0x73d323abU, 0x4b02e272U, 0x1f8f57e3U, 0x55ab2a66U,
|
||||
0xeb2807b2U, 0xb5c2032fU, 0xc57b9a86U, 0x3708a5d3U,
|
||||
0x2887f230U, 0xbfa5b223U, 0x036aba02U, 0x16825cedU,
|
||||
0xcf1c2b8aU, 0x79b492a7U, 0x07f2f0f3U, 0x69e2a14eU,
|
||||
0xdaf4cd65U, 0x05bed506U, 0x34621fd1U, 0xa6fe8ac4U,
|
||||
0x2e539d34U, 0xf355a0a2U, 0x8ae13205U, 0xf6eb75a4U,
|
||||
0x83ec390bU, 0x60efaa40U, 0x719f065eU, 0x6e1051bdU,
|
||||
0x218af93eU, 0xdd063d96U, 0x3e05aeddU, 0xe6bd464dU,
|
||||
0x548db591U, 0xc45d0571U, 0x06d46f04U, 0x5015ff60U,
|
||||
0x98fb2419U, 0xbde997d6U, 0x4043cc89U, 0xd99e7767U,
|
||||
0xe842bdb0U, 0x898b8807U, 0x195b38e7U, 0xc8eedb79U,
|
||||
0x7c0a47a1U, 0x420fe97cU, 0x841ec9f8U, 0x00000000U,
|
||||
0x80868309U, 0x2bed4832U, 0x1170ac1eU, 0x5a724e6cU,
|
||||
0x0efffbfdU, 0x8538560fU, 0xaed51e3dU, 0x2d392736U,
|
||||
0x0fd9640aU, 0x5ca62168U, 0x5b54d19bU, 0x362e3a24U,
|
||||
0x0a67b10cU, 0x57e70f93U, 0xee96d2b4U, 0x9b919e1bU,
|
||||
0xc0c54f80U, 0xdc20a261U, 0x774b695aU, 0x121a161cU,
|
||||
0x93ba0ae2U, 0xa02ae5c0U, 0x22e0433cU, 0x1b171d12U,
|
||||
0x090d0b0eU, 0x8bc7adf2U, 0xb6a8b92dU, 0x1ea9c814U,
|
||||
0xf1198557U, 0x75074cafU, 0x99ddbbeeU, 0x7f60fda3U,
|
||||
0x01269ff7U, 0x72f5bc5cU, 0x663bc544U, 0xfb7e345bU,
|
||||
0x4329768bU, 0x23c6dccbU, 0xedfc68b6U, 0xe4f163b8U,
|
||||
0x31dccad7U, 0x63851042U, 0x97224013U, 0xc6112084U,
|
||||
0x4a247d85U, 0xbb3df8d2U, 0xf93211aeU, 0x29a16dc7U,
|
||||
0x9e2f4b1dU, 0xb230f3dcU, 0x8652ec0dU, 0xc1e3d077U,
|
||||
0xb3166c2bU, 0x70b999a9U, 0x9448fa11U, 0xe9642247U,
|
||||
0xfc8cc4a8U, 0xf03f1aa0U, 0x7d2cd856U, 0x3390ef22U,
|
||||
0x494ec787U, 0x38d1c1d9U, 0xcaa2fe8cU, 0xd40b3698U,
|
||||
0xf581cfa6U, 0x7ade28a5U, 0xb78e26daU, 0xadbfa43fU,
|
||||
0x3a9de42cU, 0x78920d50U, 0x5fcc9b6aU, 0x7e466254U,
|
||||
0x8d13c2f6U, 0xd8b8e890U, 0x39f75e2eU, 0xc3aff582U,
|
||||
0x5d80be9fU, 0xd0937c69U, 0xd52da96fU, 0x2512b3cfU,
|
||||
0xac993bc8U, 0x187da710U, 0x9c636ee8U, 0x3bbb7bdbU,
|
||||
0x267809cdU, 0x5918f46eU, 0x9ab701ecU, 0x4f9aa883U,
|
||||
0x956e65e6U, 0xffe67eaaU, 0xbccf0821U, 0x15e8e6efU,
|
||||
0xe79bd9baU, 0x6f36ce4aU, 0x9f09d4eaU, 0xb07cd629U,
|
||||
0xa4b2af31U, 0x3f23312aU, 0xa59430c6U, 0xa266c035U,
|
||||
0x4ebc3774U, 0x82caa6fcU, 0x90d0b0e0U, 0xa7d81533U,
|
||||
0x04984af1U, 0xecdaf741U, 0xcd500e7fU, 0x91f62f17U,
|
||||
0x4dd68d76U, 0xefb04d43U, 0xaa4d54ccU, 0x9604dfe4U,
|
||||
0xd1b5e39eU, 0x6a881b4cU, 0x2c1fb8c1U, 0x65517f46U,
|
||||
0x5eea049dU, 0x8c355d01U, 0x877473faU, 0x0b412efbU,
|
||||
0x671d5ab3U, 0xdbd25292U, 0x105633e9U, 0xd647136dU,
|
||||
0xd7618c9aU, 0xa10c7a37U, 0xf8148e59U, 0x133c89ebU,
|
||||
0xa927eeceU, 0x61c935b7U, 0x1ce5ede1U, 0x47b13c7aU,
|
||||
0xd2df599cU, 0xf2733f55U, 0x14ce7918U, 0xc737bf73U,
|
||||
0xf7cdea53U, 0xfdaa5b5fU, 0x3d6f14dfU, 0x44db8678U,
|
||||
0xaff381caU, 0x68c43eb9U, 0x24342c38U, 0xa3405fc2U,
|
||||
0x1dc37216U, 0xe2250cbcU, 0x3c498b28U, 0x0d9541ffU,
|
||||
0xa8017139U, 0x0cb3de08U, 0xb4e49cd8U, 0x56c19064U,
|
||||
0xcb84617bU, 0x32b670d5U, 0x6c5c7448U, 0xb85742d0U,
|
||||
};
|
||||
const u32 Td4[256] = {
|
||||
0x52525252U, 0x09090909U, 0x6a6a6a6aU, 0xd5d5d5d5U,
|
||||
0x30303030U, 0x36363636U, 0xa5a5a5a5U, 0x38383838U,
|
||||
0xbfbfbfbfU, 0x40404040U, 0xa3a3a3a3U, 0x9e9e9e9eU,
|
||||
0x81818181U, 0xf3f3f3f3U, 0xd7d7d7d7U, 0xfbfbfbfbU,
|
||||
0x7c7c7c7cU, 0xe3e3e3e3U, 0x39393939U, 0x82828282U,
|
||||
0x9b9b9b9bU, 0x2f2f2f2fU, 0xffffffffU, 0x87878787U,
|
||||
0x34343434U, 0x8e8e8e8eU, 0x43434343U, 0x44444444U,
|
||||
0xc4c4c4c4U, 0xdedededeU, 0xe9e9e9e9U, 0xcbcbcbcbU,
|
||||
0x54545454U, 0x7b7b7b7bU, 0x94949494U, 0x32323232U,
|
||||
0xa6a6a6a6U, 0xc2c2c2c2U, 0x23232323U, 0x3d3d3d3dU,
|
||||
0xeeeeeeeeU, 0x4c4c4c4cU, 0x95959595U, 0x0b0b0b0bU,
|
||||
0x42424242U, 0xfafafafaU, 0xc3c3c3c3U, 0x4e4e4e4eU,
|
||||
0x08080808U, 0x2e2e2e2eU, 0xa1a1a1a1U, 0x66666666U,
|
||||
0x28282828U, 0xd9d9d9d9U, 0x24242424U, 0xb2b2b2b2U,
|
||||
0x76767676U, 0x5b5b5b5bU, 0xa2a2a2a2U, 0x49494949U,
|
||||
0x6d6d6d6dU, 0x8b8b8b8bU, 0xd1d1d1d1U, 0x25252525U,
|
||||
0x72727272U, 0xf8f8f8f8U, 0xf6f6f6f6U, 0x64646464U,
|
||||
0x86868686U, 0x68686868U, 0x98989898U, 0x16161616U,
|
||||
0xd4d4d4d4U, 0xa4a4a4a4U, 0x5c5c5c5cU, 0xccccccccU,
|
||||
0x5d5d5d5dU, 0x65656565U, 0xb6b6b6b6U, 0x92929292U,
|
||||
0x6c6c6c6cU, 0x70707070U, 0x48484848U, 0x50505050U,
|
||||
0xfdfdfdfdU, 0xededededU, 0xb9b9b9b9U, 0xdadadadaU,
|
||||
0x5e5e5e5eU, 0x15151515U, 0x46464646U, 0x57575757U,
|
||||
0xa7a7a7a7U, 0x8d8d8d8dU, 0x9d9d9d9dU, 0x84848484U,
|
||||
0x90909090U, 0xd8d8d8d8U, 0xababababU, 0x00000000U,
|
||||
0x8c8c8c8cU, 0xbcbcbcbcU, 0xd3d3d3d3U, 0x0a0a0a0aU,
|
||||
0xf7f7f7f7U, 0xe4e4e4e4U, 0x58585858U, 0x05050505U,
|
||||
0xb8b8b8b8U, 0xb3b3b3b3U, 0x45454545U, 0x06060606U,
|
||||
0xd0d0d0d0U, 0x2c2c2c2cU, 0x1e1e1e1eU, 0x8f8f8f8fU,
|
||||
0xcacacacaU, 0x3f3f3f3fU, 0x0f0f0f0fU, 0x02020202U,
|
||||
0xc1c1c1c1U, 0xafafafafU, 0xbdbdbdbdU, 0x03030303U,
|
||||
0x01010101U, 0x13131313U, 0x8a8a8a8aU, 0x6b6b6b6bU,
|
||||
0x3a3a3a3aU, 0x91919191U, 0x11111111U, 0x41414141U,
|
||||
0x4f4f4f4fU, 0x67676767U, 0xdcdcdcdcU, 0xeaeaeaeaU,
|
||||
0x97979797U, 0xf2f2f2f2U, 0xcfcfcfcfU, 0xcecececeU,
|
||||
0xf0f0f0f0U, 0xb4b4b4b4U, 0xe6e6e6e6U, 0x73737373U,
|
||||
0x96969696U, 0xacacacacU, 0x74747474U, 0x22222222U,
|
||||
0xe7e7e7e7U, 0xadadadadU, 0x35353535U, 0x85858585U,
|
||||
0xe2e2e2e2U, 0xf9f9f9f9U, 0x37373737U, 0xe8e8e8e8U,
|
||||
0x1c1c1c1cU, 0x75757575U, 0xdfdfdfdfU, 0x6e6e6e6eU,
|
||||
0x47474747U, 0xf1f1f1f1U, 0x1a1a1a1aU, 0x71717171U,
|
||||
0x1d1d1d1dU, 0x29292929U, 0xc5c5c5c5U, 0x89898989U,
|
||||
0x6f6f6f6fU, 0xb7b7b7b7U, 0x62626262U, 0x0e0e0e0eU,
|
||||
0xaaaaaaaaU, 0x18181818U, 0xbebebebeU, 0x1b1b1b1bU,
|
||||
0xfcfcfcfcU, 0x56565656U, 0x3e3e3e3eU, 0x4b4b4b4bU,
|
||||
0xc6c6c6c6U, 0xd2d2d2d2U, 0x79797979U, 0x20202020U,
|
||||
0x9a9a9a9aU, 0xdbdbdbdbU, 0xc0c0c0c0U, 0xfefefefeU,
|
||||
0x78787878U, 0xcdcdcdcdU, 0x5a5a5a5aU, 0xf4f4f4f4U,
|
||||
0x1f1f1f1fU, 0xddddddddU, 0xa8a8a8a8U, 0x33333333U,
|
||||
0x88888888U, 0x07070707U, 0xc7c7c7c7U, 0x31313131U,
|
||||
0xb1b1b1b1U, 0x12121212U, 0x10101010U, 0x59595959U,
|
||||
0x27272727U, 0x80808080U, 0xececececU, 0x5f5f5f5fU,
|
||||
0x60606060U, 0x51515151U, 0x7f7f7f7fU, 0xa9a9a9a9U,
|
||||
0x19191919U, 0xb5b5b5b5U, 0x4a4a4a4aU, 0x0d0d0d0dU,
|
||||
0x2d2d2d2dU, 0xe5e5e5e5U, 0x7a7a7a7aU, 0x9f9f9f9fU,
|
||||
0x93939393U, 0xc9c9c9c9U, 0x9c9c9c9cU, 0xefefefefU,
|
||||
0xa0a0a0a0U, 0xe0e0e0e0U, 0x3b3b3b3bU, 0x4d4d4d4dU,
|
||||
0xaeaeaeaeU, 0x2a2a2a2aU, 0xf5f5f5f5U, 0xb0b0b0b0U,
|
||||
0xc8c8c8c8U, 0xebebebebU, 0xbbbbbbbbU, 0x3c3c3c3cU,
|
||||
0x83838383U, 0x53535353U, 0x99999999U, 0x61616161U,
|
||||
0x17171717U, 0x2b2b2b2bU, 0x04040404U, 0x7e7e7e7eU,
|
||||
0xbabababaU, 0x77777777U, 0xd6d6d6d6U, 0x26262626U,
|
||||
0xe1e1e1e1U, 0x69696969U, 0x14141414U, 0x63636363U,
|
||||
0x55555555U, 0x21212121U, 0x0c0c0c0cU, 0x7d7d7d7dU,
|
||||
};
|
||||
const u32 rcon[] = {
|
||||
0x01000000, 0x02000000, 0x04000000, 0x08000000,
|
||||
0x10000000, 0x20000000, 0x40000000, 0x80000000,
|
||||
0x1B000000, 0x36000000, /* for 128-bit blocks, Rijndael never uses more than 10 rcon values */
|
||||
};
|
||||
#else /* AES_SMALL_TABLES */
|
||||
const u8 Td4s[256] = {
|
||||
0x52U, 0x09U, 0x6aU, 0xd5U, 0x30U, 0x36U, 0xa5U, 0x38U,
|
||||
0xbfU, 0x40U, 0xa3U, 0x9eU, 0x81U, 0xf3U, 0xd7U, 0xfbU,
|
||||
0x7cU, 0xe3U, 0x39U, 0x82U, 0x9bU, 0x2fU, 0xffU, 0x87U,
|
||||
0x34U, 0x8eU, 0x43U, 0x44U, 0xc4U, 0xdeU, 0xe9U, 0xcbU,
|
||||
0x54U, 0x7bU, 0x94U, 0x32U, 0xa6U, 0xc2U, 0x23U, 0x3dU,
|
||||
0xeeU, 0x4cU, 0x95U, 0x0bU, 0x42U, 0xfaU, 0xc3U, 0x4eU,
|
||||
0x08U, 0x2eU, 0xa1U, 0x66U, 0x28U, 0xd9U, 0x24U, 0xb2U,
|
||||
0x76U, 0x5bU, 0xa2U, 0x49U, 0x6dU, 0x8bU, 0xd1U, 0x25U,
|
||||
0x72U, 0xf8U, 0xf6U, 0x64U, 0x86U, 0x68U, 0x98U, 0x16U,
|
||||
0xd4U, 0xa4U, 0x5cU, 0xccU, 0x5dU, 0x65U, 0xb6U, 0x92U,
|
||||
0x6cU, 0x70U, 0x48U, 0x50U, 0xfdU, 0xedU, 0xb9U, 0xdaU,
|
||||
0x5eU, 0x15U, 0x46U, 0x57U, 0xa7U, 0x8dU, 0x9dU, 0x84U,
|
||||
0x90U, 0xd8U, 0xabU, 0x00U, 0x8cU, 0xbcU, 0xd3U, 0x0aU,
|
||||
0xf7U, 0xe4U, 0x58U, 0x05U, 0xb8U, 0xb3U, 0x45U, 0x06U,
|
||||
0xd0U, 0x2cU, 0x1eU, 0x8fU, 0xcaU, 0x3fU, 0x0fU, 0x02U,
|
||||
0xc1U, 0xafU, 0xbdU, 0x03U, 0x01U, 0x13U, 0x8aU, 0x6bU,
|
||||
0x3aU, 0x91U, 0x11U, 0x41U, 0x4fU, 0x67U, 0xdcU, 0xeaU,
|
||||
0x97U, 0xf2U, 0xcfU, 0xceU, 0xf0U, 0xb4U, 0xe6U, 0x73U,
|
||||
0x96U, 0xacU, 0x74U, 0x22U, 0xe7U, 0xadU, 0x35U, 0x85U,
|
||||
0xe2U, 0xf9U, 0x37U, 0xe8U, 0x1cU, 0x75U, 0xdfU, 0x6eU,
|
||||
0x47U, 0xf1U, 0x1aU, 0x71U, 0x1dU, 0x29U, 0xc5U, 0x89U,
|
||||
0x6fU, 0xb7U, 0x62U, 0x0eU, 0xaaU, 0x18U, 0xbeU, 0x1bU,
|
||||
0xfcU, 0x56U, 0x3eU, 0x4bU, 0xc6U, 0xd2U, 0x79U, 0x20U,
|
||||
0x9aU, 0xdbU, 0xc0U, 0xfeU, 0x78U, 0xcdU, 0x5aU, 0xf4U,
|
||||
0x1fU, 0xddU, 0xa8U, 0x33U, 0x88U, 0x07U, 0xc7U, 0x31U,
|
||||
0xb1U, 0x12U, 0x10U, 0x59U, 0x27U, 0x80U, 0xecU, 0x5fU,
|
||||
0x60U, 0x51U, 0x7fU, 0xa9U, 0x19U, 0xb5U, 0x4aU, 0x0dU,
|
||||
0x2dU, 0xe5U, 0x7aU, 0x9fU, 0x93U, 0xc9U, 0x9cU, 0xefU,
|
||||
0xa0U, 0xe0U, 0x3bU, 0x4dU, 0xaeU, 0x2aU, 0xf5U, 0xb0U,
|
||||
0xc8U, 0xebU, 0xbbU, 0x3cU, 0x83U, 0x53U, 0x99U, 0x61U,
|
||||
0x17U, 0x2bU, 0x04U, 0x7eU, 0xbaU, 0x77U, 0xd6U, 0x26U,
|
||||
0xe1U, 0x69U, 0x14U, 0x63U, 0x55U, 0x21U, 0x0cU, 0x7dU,
|
||||
};
|
||||
const u8 rcons[] = {
|
||||
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1B, 0x36
|
||||
/* for 128-bit blocks, Rijndael never uses more than 10 rcon values */
|
||||
};
|
||||
#endif /* AES_SMALL_TABLES */
|
||||
/**
|
||||
* Expand the cipher key into the encryption key schedule.
|
||||
*
|
||||
* @return the number of rounds for the given cipher key size.
|
||||
*/
|
||||
int rijndaelKeySetupEnc(u32 rk[], const u8 cipherKey[], int keyBits)
|
||||
{
|
||||
int i;
|
||||
u32 temp;
|
||||
|
||||
rk[0] = GETU32(cipherKey );
|
||||
rk[1] = GETU32(cipherKey + 4);
|
||||
rk[2] = GETU32(cipherKey + 8);
|
||||
rk[3] = GETU32(cipherKey + 12);
|
||||
|
||||
if (keyBits == 128) {
|
||||
for (i = 0; i < 10; i++) {
|
||||
temp = rk[3];
|
||||
rk[4] = rk[0] ^ TE421(temp) ^ TE432(temp) ^
|
||||
TE443(temp) ^ TE414(temp) ^ RCON(i);
|
||||
rk[5] = rk[1] ^ rk[4];
|
||||
rk[6] = rk[2] ^ rk[5];
|
||||
rk[7] = rk[3] ^ rk[6];
|
||||
rk += 4;
|
||||
}
|
||||
return 10;
|
||||
}
|
||||
|
||||
rk[4] = GETU32(cipherKey + 16);
|
||||
rk[5] = GETU32(cipherKey + 20);
|
||||
|
||||
if (keyBits == 192) {
|
||||
for (i = 0; i < 8; i++) {
|
||||
temp = rk[5];
|
||||
rk[6] = rk[0] ^ TE421(temp) ^ TE432(temp) ^
|
||||
TE443(temp) ^ TE414(temp) ^ RCON(i);
|
||||
rk[7] = rk[1] ^ rk[6];
|
||||
rk[8] = rk[2] ^ rk[7];
|
||||
rk[9] = rk[3] ^ rk[8];
|
||||
if (i == 7)
|
||||
return 12;
|
||||
rk[10] = rk[4] ^ rk[9];
|
||||
rk[11] = rk[5] ^ rk[10];
|
||||
rk += 6;
|
||||
}
|
||||
}
|
||||
|
||||
rk[6] = GETU32(cipherKey + 24);
|
||||
rk[7] = GETU32(cipherKey + 28);
|
||||
|
||||
if (keyBits == 256) {
|
||||
for (i = 0; i < 7; i++) {
|
||||
temp = rk[7];
|
||||
rk[8] = rk[0] ^ TE421(temp) ^ TE432(temp) ^
|
||||
TE443(temp) ^ TE414(temp) ^ RCON(i);
|
||||
rk[9] = rk[1] ^ rk[8];
|
||||
rk[10] = rk[2] ^ rk[9];
|
||||
rk[11] = rk[3] ^ rk[10];
|
||||
if (i == 6)
|
||||
return 14;
|
||||
temp = rk[11];
|
||||
rk[12] = rk[4] ^ TE411(temp) ^ TE422(temp) ^
|
||||
TE433(temp) ^ TE444(temp);
|
||||
rk[13] = rk[5] ^ rk[12];
|
||||
rk[14] = rk[6] ^ rk[13];
|
||||
rk[15] = rk[7] ^ rk[14];
|
||||
rk += 8;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
172
drivers/net/wireless/rtl8822cs/core/crypto/aes-omac1.c
Normal file
172
drivers/net/wireless/rtl8822cs/core/crypto/aes-omac1.c
Normal file
@@ -0,0 +1,172 @@
|
||||
/*
|
||||
* One-key CBC MAC (OMAC1) hash with AES
|
||||
*
|
||||
* Copyright (c) 2003-2007, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This software may be distributed under the terms of the BSD license.
|
||||
* See README for more details.
|
||||
*/
|
||||
|
||||
#include "rtw_crypto_wrap.h"
|
||||
|
||||
#include "aes.h"
|
||||
#include "aes_wrap.h"
|
||||
|
||||
static void gf_mulx(u8 *pad)
|
||||
{
|
||||
int i, carry;
|
||||
|
||||
carry = pad[0] & 0x80;
|
||||
for (i = 0; i < AES_BLOCK_SIZE - 1; i++)
|
||||
pad[i] = (pad[i] << 1) | (pad[i + 1] >> 7);
|
||||
pad[AES_BLOCK_SIZE - 1] <<= 1;
|
||||
if (carry)
|
||||
pad[AES_BLOCK_SIZE - 1] ^= 0x87;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* omac1_aes_vector - One-Key CBC MAC (OMAC1) hash with AES
|
||||
* @key: Key for the hash operation
|
||||
* @key_len: Key length in octets
|
||||
* @num_elem: Number of elements in the data vector
|
||||
* @addr: Pointers to the data areas
|
||||
* @len: Lengths of the data blocks
|
||||
* @mac: Buffer for MAC (128 bits, i.e., 16 bytes)
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*
|
||||
* This is a mode for using block cipher (AES in this case) for authentication.
|
||||
* OMAC1 was standardized with the name CMAC by NIST in a Special Publication
|
||||
* (SP) 800-38B.
|
||||
*/
|
||||
int omac1_aes_vector(const u8 *key, size_t key_len, size_t num_elem,
|
||||
const u8 *addr[], const size_t *len, u8 *mac)
|
||||
{
|
||||
void *ctx;
|
||||
u8 cbc[AES_BLOCK_SIZE], pad[AES_BLOCK_SIZE];
|
||||
const u8 *pos, *end;
|
||||
size_t i, e, left, total_len;
|
||||
|
||||
if (TEST_FAIL())
|
||||
return -1;
|
||||
|
||||
ctx = aes_encrypt_init(key, key_len);
|
||||
if (ctx == NULL)
|
||||
return -1;
|
||||
os_memset(cbc, 0, AES_BLOCK_SIZE);
|
||||
|
||||
total_len = 0;
|
||||
for (e = 0; e < num_elem; e++)
|
||||
total_len += len[e];
|
||||
left = total_len;
|
||||
|
||||
e = 0;
|
||||
pos = addr[0];
|
||||
end = pos + len[0];
|
||||
|
||||
while (left >= AES_BLOCK_SIZE) {
|
||||
for (i = 0; i < AES_BLOCK_SIZE; i++) {
|
||||
cbc[i] ^= *pos++;
|
||||
if (pos >= end) {
|
||||
/*
|
||||
* Stop if there are no more bytes to process
|
||||
* since there are no more entries in the array.
|
||||
*/
|
||||
if (i + 1 == AES_BLOCK_SIZE &&
|
||||
left == AES_BLOCK_SIZE)
|
||||
break;
|
||||
e++;
|
||||
pos = addr[e];
|
||||
end = pos + len[e];
|
||||
}
|
||||
}
|
||||
if (left > AES_BLOCK_SIZE)
|
||||
wpa_aes_encrypt(ctx, cbc, cbc);
|
||||
left -= AES_BLOCK_SIZE;
|
||||
}
|
||||
|
||||
os_memset(pad, 0, AES_BLOCK_SIZE);
|
||||
wpa_aes_encrypt(ctx, pad, pad);
|
||||
gf_mulx(pad);
|
||||
|
||||
if (left || total_len == 0) {
|
||||
for (i = 0; i < left; i++) {
|
||||
cbc[i] ^= *pos++;
|
||||
if (pos >= end) {
|
||||
/*
|
||||
* Stop if there are no more bytes to process
|
||||
* since there are no more entries in the array.
|
||||
*/
|
||||
if (i + 1 == left)
|
||||
break;
|
||||
e++;
|
||||
pos = addr[e];
|
||||
end = pos + len[e];
|
||||
}
|
||||
}
|
||||
cbc[left] ^= 0x80;
|
||||
gf_mulx(pad);
|
||||
}
|
||||
|
||||
for (i = 0; i < AES_BLOCK_SIZE; i++)
|
||||
pad[i] ^= cbc[i];
|
||||
wpa_aes_encrypt(ctx, pad, mac);
|
||||
aes_encrypt_deinit(ctx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* omac1_aes_128_vector - One-Key CBC MAC (OMAC1) hash with AES-128
|
||||
* @key: 128-bit key for the hash operation
|
||||
* @num_elem: Number of elements in the data vector
|
||||
* @addr: Pointers to the data areas
|
||||
* @len: Lengths of the data blocks
|
||||
* @mac: Buffer for MAC (128 bits, i.e., 16 bytes)
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*
|
||||
* This is a mode for using block cipher (AES in this case) for authentication.
|
||||
* OMAC1 was standardized with the name CMAC by NIST in a Special Publication
|
||||
* (SP) 800-38B.
|
||||
*/
|
||||
int omac1_aes_128_vector(const u8 *key, size_t num_elem,
|
||||
const u8 *addr[], const size_t *len, u8 *mac)
|
||||
{
|
||||
return omac1_aes_vector(key, 16, num_elem, addr, len, mac);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* omac1_aes_128 - One-Key CBC MAC (OMAC1) hash with AES-128 (aka AES-CMAC)
|
||||
* @key: 128-bit key for the hash operation
|
||||
* @data: Data buffer for which a MAC is determined
|
||||
* @data_len: Length of data buffer in bytes
|
||||
* @mac: Buffer for MAC (128 bits, i.e., 16 bytes)
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*
|
||||
* This is a mode for using block cipher (AES in this case) for authentication.
|
||||
* OMAC1 was standardized with the name CMAC by NIST in a Special Publication
|
||||
* (SP) 800-38B.
|
||||
*/
|
||||
int omac1_aes_128(const u8 *key, const u8 *data, size_t data_len, u8 *mac)
|
||||
{
|
||||
return omac1_aes_128_vector(key, 1, &data, &data_len, mac);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* omac1_aes_256 - One-Key CBC MAC (OMAC1) hash with AES-256 (aka AES-CMAC)
|
||||
* @key: 256-bit key for the hash operation
|
||||
* @data: Data buffer for which a MAC is determined
|
||||
* @data_len: Length of data buffer in bytes
|
||||
* @mac: Buffer for MAC (128 bits, i.e., 16 bytes)
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*
|
||||
* This is a mode for using block cipher (AES in this case) for authentication.
|
||||
* OMAC1 was standardized with the name CMAC by NIST in a Special Publication
|
||||
* (SP) 800-38B.
|
||||
*/
|
||||
int omac1_aes_256(const u8 *key, const u8 *data, size_t data_len, u8 *mac)
|
||||
{
|
||||
return omac1_aes_vector(key, 32, 1, &data, &data_len, mac);
|
||||
}
|
||||
207
drivers/net/wireless/rtl8822cs/core/crypto/aes-siv.c
Normal file
207
drivers/net/wireless/rtl8822cs/core/crypto/aes-siv.c
Normal file
@@ -0,0 +1,207 @@
|
||||
/*
|
||||
* AES SIV (RFC 5297)
|
||||
* Copyright (c) 2013 Cozybit, Inc.
|
||||
*
|
||||
* This software may be distributed under the terms of the BSD license.
|
||||
* See README for more details.
|
||||
*/
|
||||
|
||||
#include "rtw_crypto_wrap.h"
|
||||
|
||||
#include "aes.h"
|
||||
#include "aes_wrap.h"
|
||||
#include "aes_siv.h"
|
||||
|
||||
|
||||
static const u8 zero[AES_BLOCK_SIZE];
|
||||
|
||||
|
||||
static void dbl(u8 *pad)
|
||||
{
|
||||
int i, carry;
|
||||
|
||||
carry = pad[0] & 0x80;
|
||||
for (i = 0; i < AES_BLOCK_SIZE - 1; i++)
|
||||
pad[i] = (pad[i] << 1) | (pad[i + 1] >> 7);
|
||||
pad[AES_BLOCK_SIZE - 1] <<= 1;
|
||||
if (carry)
|
||||
pad[AES_BLOCK_SIZE - 1] ^= 0x87;
|
||||
}
|
||||
|
||||
|
||||
static void xor(u8 *a, const u8 *b)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < AES_BLOCK_SIZE; i++)
|
||||
*a++ ^= *b++;
|
||||
}
|
||||
|
||||
|
||||
static void xorend(u8 *a, int alen, const u8 *b, int blen)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (alen < blen)
|
||||
return;
|
||||
|
||||
for (i = 0; i < blen; i++)
|
||||
a[alen - blen + i] ^= b[i];
|
||||
}
|
||||
|
||||
|
||||
static void pad_block(u8 *pad, const u8 *addr, size_t len)
|
||||
{
|
||||
os_memset(pad, 0, AES_BLOCK_SIZE);
|
||||
os_memcpy(pad, addr, len);
|
||||
|
||||
if (len < AES_BLOCK_SIZE)
|
||||
pad[len] = 0x80;
|
||||
}
|
||||
|
||||
|
||||
static int aes_s2v(const u8 *key, size_t key_len,
|
||||
size_t num_elem, const u8 *addr[], size_t *len, u8 *mac)
|
||||
{
|
||||
u8 tmp[AES_BLOCK_SIZE], tmp2[AES_BLOCK_SIZE];
|
||||
u8 *buf = NULL;
|
||||
int ret;
|
||||
size_t i;
|
||||
const u8 *data[1];
|
||||
size_t data_len[1];
|
||||
|
||||
if (!num_elem) {
|
||||
os_memcpy(tmp, zero, sizeof(zero));
|
||||
tmp[AES_BLOCK_SIZE - 1] = 1;
|
||||
data[0] = tmp;
|
||||
data_len[0] = sizeof(tmp);
|
||||
return omac1_aes_vector(key, key_len, 1, data, data_len, mac);
|
||||
}
|
||||
|
||||
data[0] = zero;
|
||||
data_len[0] = sizeof(zero);
|
||||
ret = omac1_aes_vector(key, key_len, 1, data, data_len, tmp);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
for (i = 0; i < num_elem - 1; i++) {
|
||||
ret = omac1_aes_vector(key, key_len, 1, &addr[i], &len[i],
|
||||
tmp2);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
dbl(tmp);
|
||||
xor(tmp, tmp2);
|
||||
}
|
||||
if (len[i] >= AES_BLOCK_SIZE) {
|
||||
buf = os_memdup(addr[i], len[i]);
|
||||
if (!buf)
|
||||
return -ENOMEM;
|
||||
|
||||
xorend(buf, len[i], tmp, AES_BLOCK_SIZE);
|
||||
data[0] = buf;
|
||||
ret = omac1_aes_vector(key, key_len, 1, data, &len[i], mac);
|
||||
bin_clear_free(buf, len[i]);
|
||||
return ret;
|
||||
}
|
||||
|
||||
dbl(tmp);
|
||||
pad_block(tmp2, addr[i], len[i]);
|
||||
xor(tmp, tmp2);
|
||||
|
||||
data[0] = tmp;
|
||||
data_len[0] = sizeof(tmp);
|
||||
return omac1_aes_vector(key, key_len, 1, data, data_len, mac);
|
||||
}
|
||||
|
||||
|
||||
int aes_siv_encrypt(const u8 *key, size_t key_len,
|
||||
const u8 *pw, size_t pwlen,
|
||||
size_t num_elem, const u8 *addr[], const size_t *len,
|
||||
u8 *out)
|
||||
{
|
||||
const u8 *_addr[6];
|
||||
size_t _len[6];
|
||||
const u8 *k1, *k2;
|
||||
u8 v[AES_BLOCK_SIZE];
|
||||
size_t i;
|
||||
u8 *iv, *crypt_pw;
|
||||
|
||||
if (num_elem > ARRAY_SIZE(_addr) - 1 ||
|
||||
(key_len != 32 && key_len != 48 && key_len != 64))
|
||||
return -1;
|
||||
|
||||
key_len /= 2;
|
||||
k1 = key;
|
||||
k2 = key + key_len;
|
||||
|
||||
for (i = 0; i < num_elem; i++) {
|
||||
_addr[i] = addr[i];
|
||||
_len[i] = len[i];
|
||||
}
|
||||
_addr[num_elem] = pw;
|
||||
_len[num_elem] = pwlen;
|
||||
|
||||
if (aes_s2v(k1, key_len, num_elem + 1, _addr, _len, v))
|
||||
return -1;
|
||||
|
||||
iv = out;
|
||||
crypt_pw = out + AES_BLOCK_SIZE;
|
||||
|
||||
os_memcpy(iv, v, AES_BLOCK_SIZE);
|
||||
os_memcpy(crypt_pw, pw, pwlen);
|
||||
|
||||
/* zero out 63rd and 31st bits of ctr (from right) */
|
||||
v[8] &= 0x7f;
|
||||
v[12] &= 0x7f;
|
||||
return aes_ctr_encrypt(k2, key_len, v, crypt_pw, pwlen);
|
||||
}
|
||||
|
||||
|
||||
int aes_siv_decrypt(const u8 *key, size_t key_len,
|
||||
const u8 *iv_crypt, size_t iv_c_len,
|
||||
size_t num_elem, const u8 *addr[], const size_t *len,
|
||||
u8 *out)
|
||||
{
|
||||
const u8 *_addr[6];
|
||||
size_t _len[6];
|
||||
const u8 *k1, *k2;
|
||||
size_t crypt_len;
|
||||
size_t i;
|
||||
int ret;
|
||||
u8 iv[AES_BLOCK_SIZE];
|
||||
u8 check[AES_BLOCK_SIZE];
|
||||
|
||||
if (iv_c_len < AES_BLOCK_SIZE || num_elem > ARRAY_SIZE(_addr) - 1 ||
|
||||
(key_len != 32 && key_len != 48 && key_len != 64))
|
||||
return -1;
|
||||
crypt_len = iv_c_len - AES_BLOCK_SIZE;
|
||||
key_len /= 2;
|
||||
k1 = key;
|
||||
k2 = key + key_len;
|
||||
|
||||
for (i = 0; i < num_elem; i++) {
|
||||
_addr[i] = addr[i];
|
||||
_len[i] = len[i];
|
||||
}
|
||||
_addr[num_elem] = out;
|
||||
_len[num_elem] = crypt_len;
|
||||
|
||||
os_memcpy(iv, iv_crypt, AES_BLOCK_SIZE);
|
||||
os_memcpy(out, iv_crypt + AES_BLOCK_SIZE, crypt_len);
|
||||
|
||||
iv[8] &= 0x7f;
|
||||
iv[12] &= 0x7f;
|
||||
|
||||
ret = aes_ctr_encrypt(k2, key_len, iv, out, crypt_len);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = aes_s2v(k1, key_len, num_elem + 1, _addr, _len, check);
|
||||
if (ret)
|
||||
return ret;
|
||||
if (os_memcmp(check, iv_crypt, AES_BLOCK_SIZE) == 0)
|
||||
return 0;
|
||||
|
||||
return -1;
|
||||
}
|
||||
21
drivers/net/wireless/rtl8822cs/core/crypto/aes.h
Normal file
21
drivers/net/wireless/rtl8822cs/core/crypto/aes.h
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* AES functions
|
||||
* Copyright (c) 2003-2006, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This software may be distributed under the terms of the BSD license.
|
||||
* See README for more details.
|
||||
*/
|
||||
|
||||
#ifndef AES_H
|
||||
#define AES_H
|
||||
|
||||
#define AES_BLOCK_SIZE 16
|
||||
|
||||
void * aes_encrypt_init(const u8 *key, size_t len);
|
||||
int wpa_aes_encrypt(void *ctx, const u8 *plain, u8 *crypt);
|
||||
void aes_encrypt_deinit(void *ctx);
|
||||
void * aes_decrypt_init(const u8 *key, size_t len);
|
||||
int aes_decrypt(void *ctx, const u8 *crypt, u8 *plain);
|
||||
void aes_decrypt_deinit(void *ctx);
|
||||
|
||||
#endif /* AES_H */
|
||||
125
drivers/net/wireless/rtl8822cs/core/crypto/aes_i.h
Normal file
125
drivers/net/wireless/rtl8822cs/core/crypto/aes_i.h
Normal file
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* AES (Rijndael) cipher
|
||||
* Copyright (c) 2003-2012, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This software may be distributed under the terms of the BSD license.
|
||||
* See README for more details.
|
||||
*/
|
||||
|
||||
#ifndef AES_I_H
|
||||
#define AES_I_H
|
||||
|
||||
#include "aes.h"
|
||||
|
||||
/* #define FULL_UNROLL */
|
||||
#define AES_SMALL_TABLES
|
||||
|
||||
extern const u32 Te0[256];
|
||||
extern const u32 Te1[256];
|
||||
extern const u32 Te2[256];
|
||||
extern const u32 Te3[256];
|
||||
extern const u32 Te4[256];
|
||||
extern const u32 Td0[256];
|
||||
extern const u32 Td1[256];
|
||||
extern const u32 Td2[256];
|
||||
extern const u32 Td3[256];
|
||||
extern const u32 Td4[256];
|
||||
extern const u32 rcon[10];
|
||||
extern const u8 Td4s[256];
|
||||
extern const u8 rcons[10];
|
||||
|
||||
#ifndef AES_SMALL_TABLES
|
||||
|
||||
#define RCON(i) rcon[(i)]
|
||||
|
||||
#define TE0(i) Te0[((i) >> 24) & 0xff]
|
||||
#define TE1(i) Te1[((i) >> 16) & 0xff]
|
||||
#define TE2(i) Te2[((i) >> 8) & 0xff]
|
||||
#define TE3(i) Te3[(i) & 0xff]
|
||||
#define TE41(i) (Te4[((i) >> 24) & 0xff] & 0xff000000)
|
||||
#define TE42(i) (Te4[((i) >> 16) & 0xff] & 0x00ff0000)
|
||||
#define TE43(i) (Te4[((i) >> 8) & 0xff] & 0x0000ff00)
|
||||
#define TE44(i) (Te4[(i) & 0xff] & 0x000000ff)
|
||||
#define TE421(i) (Te4[((i) >> 16) & 0xff] & 0xff000000)
|
||||
#define TE432(i) (Te4[((i) >> 8) & 0xff] & 0x00ff0000)
|
||||
#define TE443(i) (Te4[(i) & 0xff] & 0x0000ff00)
|
||||
#define TE414(i) (Te4[((i) >> 24) & 0xff] & 0x000000ff)
|
||||
#define TE411(i) (Te4[((i) >> 24) & 0xff] & 0xff000000)
|
||||
#define TE422(i) (Te4[((i) >> 16) & 0xff] & 0x00ff0000)
|
||||
#define TE433(i) (Te4[((i) >> 8) & 0xff] & 0x0000ff00)
|
||||
#define TE444(i) (Te4[(i) & 0xff] & 0x000000ff)
|
||||
#define TE4(i) (Te4[(i)] & 0x000000ff)
|
||||
|
||||
#define TD0(i) Td0[((i) >> 24) & 0xff]
|
||||
#define TD1(i) Td1[((i) >> 16) & 0xff]
|
||||
#define TD2(i) Td2[((i) >> 8) & 0xff]
|
||||
#define TD3(i) Td3[(i) & 0xff]
|
||||
#define TD41(i) (Td4[((i) >> 24) & 0xff] & 0xff000000)
|
||||
#define TD42(i) (Td4[((i) >> 16) & 0xff] & 0x00ff0000)
|
||||
#define TD43(i) (Td4[((i) >> 8) & 0xff] & 0x0000ff00)
|
||||
#define TD44(i) (Td4[(i) & 0xff] & 0x000000ff)
|
||||
#define TD0_(i) Td0[(i) & 0xff]
|
||||
#define TD1_(i) Td1[(i) & 0xff]
|
||||
#define TD2_(i) Td2[(i) & 0xff]
|
||||
#define TD3_(i) Td3[(i) & 0xff]
|
||||
|
||||
#else /* AES_SMALL_TABLES */
|
||||
|
||||
#define RCON(i) (rcons[(i)] << 24)
|
||||
|
||||
static inline u32 rotr(u32 val, int bits)
|
||||
{
|
||||
return (val >> bits) | (val << (32 - bits));
|
||||
}
|
||||
|
||||
#define TE0(i) Te0[((i) >> 24) & 0xff]
|
||||
#define TE1(i) rotr(Te0[((i) >> 16) & 0xff], 8)
|
||||
#define TE2(i) rotr(Te0[((i) >> 8) & 0xff], 16)
|
||||
#define TE3(i) rotr(Te0[(i) & 0xff], 24)
|
||||
#define TE41(i) ((Te0[((i) >> 24) & 0xff] << 8) & 0xff000000)
|
||||
#define TE42(i) (Te0[((i) >> 16) & 0xff] & 0x00ff0000)
|
||||
#define TE43(i) (Te0[((i) >> 8) & 0xff] & 0x0000ff00)
|
||||
#define TE44(i) ((Te0[(i) & 0xff] >> 8) & 0x000000ff)
|
||||
#define TE421(i) ((Te0[((i) >> 16) & 0xff] << 8) & 0xff000000)
|
||||
#define TE432(i) (Te0[((i) >> 8) & 0xff] & 0x00ff0000)
|
||||
#define TE443(i) (Te0[(i) & 0xff] & 0x0000ff00)
|
||||
#define TE414(i) ((Te0[((i) >> 24) & 0xff] >> 8) & 0x000000ff)
|
||||
#define TE411(i) ((Te0[((i) >> 24) & 0xff] << 8) & 0xff000000)
|
||||
#define TE422(i) (Te0[((i) >> 16) & 0xff] & 0x00ff0000)
|
||||
#define TE433(i) (Te0[((i) >> 8) & 0xff] & 0x0000ff00)
|
||||
#define TE444(i) ((Te0[(i) & 0xff] >> 8) & 0x000000ff)
|
||||
#define TE4(i) ((Te0[(i)] >> 8) & 0x000000ff)
|
||||
|
||||
#define TD0(i) Td0[((i) >> 24) & 0xff]
|
||||
#define TD1(i) rotr(Td0[((i) >> 16) & 0xff], 8)
|
||||
#define TD2(i) rotr(Td0[((i) >> 8) & 0xff], 16)
|
||||
#define TD3(i) rotr(Td0[(i) & 0xff], 24)
|
||||
#define TD41(i) (Td4s[((i) >> 24) & 0xff] << 24)
|
||||
#define TD42(i) (Td4s[((i) >> 16) & 0xff] << 16)
|
||||
#define TD43(i) (Td4s[((i) >> 8) & 0xff] << 8)
|
||||
#define TD44(i) (Td4s[(i) & 0xff])
|
||||
#define TD0_(i) Td0[(i) & 0xff]
|
||||
#define TD1_(i) rotr(Td0[(i) & 0xff], 8)
|
||||
#define TD2_(i) rotr(Td0[(i) & 0xff], 16)
|
||||
#define TD3_(i) rotr(Td0[(i) & 0xff], 24)
|
||||
|
||||
#endif /* AES_SMALL_TABLES */
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define SWAP(x) (_lrotl(x, 8) & 0x00ff00ff | _lrotr(x, 8) & 0xff00ff00)
|
||||
#define GETU32(p) SWAP(*((u32 *)(p)))
|
||||
#define PUTU32(ct, st) { *((u32 *)(ct)) = SWAP((st)); }
|
||||
#else
|
||||
#define GETU32(pt) (((u32)(pt)[0] << 24) ^ ((u32)(pt)[1] << 16) ^ \
|
||||
((u32)(pt)[2] << 8) ^ ((u32)(pt)[3]))
|
||||
#define PUTU32(ct, st) { \
|
||||
(ct)[0] = (u8)((st) >> 24); (ct)[1] = (u8)((st) >> 16); \
|
||||
(ct)[2] = (u8)((st) >> 8); (ct)[3] = (u8)(st); }
|
||||
#endif
|
||||
|
||||
#define AES_PRIV_SIZE (4 * 4 * 15 + 4)
|
||||
#define AES_PRIV_NR_POS (4 * 15)
|
||||
|
||||
int rijndaelKeySetupEnc(u32 rk[], const u8 cipherKey[], int keyBits);
|
||||
|
||||
#endif /* AES_I_H */
|
||||
21
drivers/net/wireless/rtl8822cs/core/crypto/aes_siv.h
Normal file
21
drivers/net/wireless/rtl8822cs/core/crypto/aes_siv.h
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* AES SIV (RFC 5297)
|
||||
* Copyright (c) 2013 Cozybit, Inc.
|
||||
*
|
||||
* This software may be distributed under the terms of the BSD license.
|
||||
* See README for more details.
|
||||
*/
|
||||
|
||||
#ifndef AES_SIV_H
|
||||
#define AES_SIV_H
|
||||
|
||||
int aes_siv_encrypt(const u8 *key, size_t key_len,
|
||||
const u8 *pw, size_t pwlen,
|
||||
size_t num_elem, const u8 *addr[], const size_t *len,
|
||||
u8 *out);
|
||||
int aes_siv_decrypt(const u8 *key, size_t key_len,
|
||||
const u8 *iv_crypt, size_t iv_c_len,
|
||||
size_t num_elem, const u8 *addr[], const size_t *len,
|
||||
u8 *out);
|
||||
|
||||
#endif /* AES_SIV_H */
|
||||
73
drivers/net/wireless/rtl8822cs/core/crypto/aes_wrap.h
Normal file
73
drivers/net/wireless/rtl8822cs/core/crypto/aes_wrap.h
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* AES-based functions
|
||||
*
|
||||
* - AES Key Wrap Algorithm (RFC3394)
|
||||
* - One-Key CBC MAC (OMAC1) hash with AES-128 and AES-256
|
||||
* - AES-128/192/256 CTR mode encryption
|
||||
* - AES-128 EAX mode encryption/decryption
|
||||
* - AES-128 CBC
|
||||
* - AES-GCM
|
||||
* - AES-CCM
|
||||
*
|
||||
* Copyright (c) 2003-2012, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This software may be distributed under the terms of the BSD license.
|
||||
* See README for more details.
|
||||
*/
|
||||
|
||||
#ifndef AES_WRAP_H
|
||||
#define AES_WRAP_H
|
||||
|
||||
int __must_check aes_wrap(const u8 *kek, size_t kek_len, int n, const u8 *plain,
|
||||
u8 *cipher);
|
||||
int __must_check aes_unwrap(const u8 *kek, size_t kek_len, int n,
|
||||
const u8 *cipher, u8 *plain);
|
||||
int __must_check omac1_aes_vector(const u8 *key, size_t key_len,
|
||||
size_t num_elem, const u8 *addr[],
|
||||
const size_t *len, u8 *mac);
|
||||
int __must_check omac1_aes_128_vector(const u8 *key, size_t num_elem,
|
||||
const u8 *addr[], const size_t *len,
|
||||
u8 *mac);
|
||||
int __must_check omac1_aes_128(const u8 *key, const u8 *data, size_t data_len,
|
||||
u8 *mac);
|
||||
int __must_check omac1_aes_256(const u8 *key, const u8 *data, size_t data_len,
|
||||
u8 *mac);
|
||||
int __must_check aes_128_encrypt_block(const u8 *key, const u8 *in, u8 *out);
|
||||
int __must_check aes_ctr_encrypt(const u8 *key, size_t key_len, const u8 *nonce,
|
||||
u8 *data, size_t data_len);
|
||||
int __must_check aes_128_ctr_encrypt(const u8 *key, const u8 *nonce,
|
||||
u8 *data, size_t data_len);
|
||||
int __must_check aes_128_eax_encrypt(const u8 *key,
|
||||
const u8 *nonce, size_t nonce_len,
|
||||
const u8 *hdr, size_t hdr_len,
|
||||
u8 *data, size_t data_len, u8 *tag);
|
||||
int __must_check aes_128_eax_decrypt(const u8 *key,
|
||||
const u8 *nonce, size_t nonce_len,
|
||||
const u8 *hdr, size_t hdr_len,
|
||||
u8 *data, size_t data_len, const u8 *tag);
|
||||
int __must_check aes_128_cbc_encrypt(const u8 *key, const u8 *iv, u8 *data,
|
||||
size_t data_len);
|
||||
int __must_check aes_128_cbc_decrypt(const u8 *key, const u8 *iv, u8 *data,
|
||||
size_t data_len);
|
||||
int __must_check aes_gcm_ae(const u8 *key, size_t key_len,
|
||||
const u8 *iv, size_t iv_len,
|
||||
const u8 *plain, size_t plain_len,
|
||||
const u8 *aad, size_t aad_len,
|
||||
u8 *crypt, u8 *tag);
|
||||
int __must_check aes_gcm_ad(const u8 *key, size_t key_len,
|
||||
const u8 *iv, size_t iv_len,
|
||||
const u8 *crypt, size_t crypt_len,
|
||||
const u8 *aad, size_t aad_len, const u8 *tag,
|
||||
u8 *plain);
|
||||
int __must_check aes_gmac(const u8 *key, size_t key_len,
|
||||
const u8 *iv, size_t iv_len,
|
||||
const u8 *aad, size_t aad_len, u8 *tag);
|
||||
int __must_check aes_ccm_ae(const u8 *key, size_t key_len, const u8 *nonce,
|
||||
size_t M, const u8 *plain, size_t plain_len,
|
||||
const u8 *aad, size_t aad_len, u8 *crypt, u8 *auth);
|
||||
int __must_check aes_ccm_ad(const u8 *key, size_t key_len, const u8 *nonce,
|
||||
size_t M, const u8 *crypt, size_t crypt_len,
|
||||
const u8 *aad, size_t aad_len, const u8 *auth,
|
||||
u8 *plain);
|
||||
|
||||
#endif /* AES_WRAP_H */
|
||||
385
drivers/net/wireless/rtl8822cs/core/crypto/ccmp.c
Normal file
385
drivers/net/wireless/rtl8822cs/core/crypto/ccmp.c
Normal file
@@ -0,0 +1,385 @@
|
||||
/*
|
||||
* CTR with CBC-MAC Protocol (CCMP)
|
||||
* Copyright (c) 2010-2012, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This software may be distributed under the terms of the BSD license.
|
||||
* See README for more details.
|
||||
*/
|
||||
|
||||
#include "rtw_crypto_wrap.h"
|
||||
|
||||
#include "aes.h"
|
||||
#include "aes_wrap.h"
|
||||
#include "wlancrypto_wrap.h"
|
||||
|
||||
|
||||
|
||||
static void ccmp_aad_nonce(_adapter *padapter, const struct ieee80211_hdr *hdr, const u8 *data,
|
||||
u8 *aad, size_t *aad_len, u8 *nonce)
|
||||
{
|
||||
u16 fc, stype, seq;
|
||||
int qos = 0, addr4 = 0;
|
||||
u8 *pos;
|
||||
|
||||
nonce[0] = 0;
|
||||
|
||||
fc = le_to_host16(hdr->frame_control);
|
||||
stype = WLAN_FC_GET_STYPE(fc);
|
||||
if ((fc & (WLAN_FC_TODS | WLAN_FC_FROMDS)) ==
|
||||
(WLAN_FC_TODS | WLAN_FC_FROMDS))
|
||||
addr4 = 1;
|
||||
|
||||
if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_DATA) {
|
||||
fc &= ~0x0070; /* Mask subtype bits */
|
||||
if (stype & WLAN_FC_STYPE_QOS_DATA) {
|
||||
const u8 *qc;
|
||||
qos = 1;
|
||||
fc &= ~WLAN_FC_ORDER;
|
||||
qc = (const u8 *)hdr + 24;
|
||||
if (addr4)
|
||||
qc += ETH_ALEN;
|
||||
nonce[0] = qc[0] & 0x0f;
|
||||
}
|
||||
} else if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT)
|
||||
nonce[0] |= 0x10; /* Management */
|
||||
|
||||
fc &= ~(WLAN_FC_RETRY | WLAN_FC_PWRMGT | WLAN_FC_MOREDATA);
|
||||
fc |= WLAN_FC_ISWEP;
|
||||
WPA_PUT_LE16(aad, fc);
|
||||
pos = aad + 2;
|
||||
os_memcpy(pos, GetAddr1Ptr((u8 *)hdr), 3 * ETH_ALEN);
|
||||
pos += 3 * ETH_ALEN;
|
||||
seq = le_to_host16(hdr->seq_ctrl);
|
||||
seq &= ~0xfff0; /* Mask Seq#; do not modify Frag# */
|
||||
WPA_PUT_LE16(pos, seq);
|
||||
pos += 2;
|
||||
|
||||
os_memcpy(pos, (u8 *)hdr + 24, addr4 * ETH_ALEN + qos * 2);
|
||||
pos += addr4 * ETH_ALEN;
|
||||
if (qos) {
|
||||
pos[0] &= ~0x70;
|
||||
/* only spp mode need to refer QoS bit7 */
|
||||
if (padapter->registrypriv.amsdu_mode != RTW_AMSDU_MODE_SPP)
|
||||
pos[0] &= ~0x80;
|
||||
pos++;
|
||||
*pos++ = 0x00;
|
||||
}
|
||||
|
||||
*aad_len = pos - aad;
|
||||
|
||||
os_memcpy(nonce + 1, hdr->addr2, ETH_ALEN);
|
||||
nonce[7] = data[7]; /* PN5 */
|
||||
nonce[8] = data[6]; /* PN4 */
|
||||
nonce[9] = data[5]; /* PN3 */
|
||||
nonce[10] = data[4]; /* PN2 */
|
||||
nonce[11] = data[1]; /* PN1 */
|
||||
nonce[12] = data[0]; /* PN0 */
|
||||
}
|
||||
|
||||
|
||||
static void ccmp_aad_nonce_pv1(const u8 *hdr, const u8 *a1, const u8 *a2,
|
||||
const u8 *a3, const u8 *pn,
|
||||
u8 *aad, size_t *aad_len, u8 *nonce)
|
||||
{
|
||||
u16 fc, type;
|
||||
u8 *pos;
|
||||
|
||||
nonce[0] = BIT(5); /* PV1 */
|
||||
/* TODO: Priority for QMF; 0 is used for Data frames */
|
||||
|
||||
fc = WPA_GET_LE16(hdr);
|
||||
type = (fc & (BIT(2) | BIT(3) | BIT(4))) >> 2;
|
||||
|
||||
if (type == 1)
|
||||
nonce[0] |= 0x10; /* Management */
|
||||
|
||||
fc &= ~(BIT(10) | BIT(11) | BIT(13) | BIT(14) | BIT(15));
|
||||
fc |= BIT(12);
|
||||
WPA_PUT_LE16(aad, fc);
|
||||
pos = aad + 2;
|
||||
if (type == 0 || type == 3) {
|
||||
const u8 *sc;
|
||||
|
||||
os_memcpy(pos, a1, ETH_ALEN);
|
||||
pos += ETH_ALEN;
|
||||
os_memcpy(pos, a2, ETH_ALEN);
|
||||
pos += ETH_ALEN;
|
||||
|
||||
if (type == 0) {
|
||||
/* Either A1 or A2 contains SID */
|
||||
sc = hdr + 2 + 2 + ETH_ALEN;
|
||||
} else {
|
||||
/* Both A1 and A2 contain full addresses */
|
||||
sc = hdr + 2 + 2 * ETH_ALEN;
|
||||
}
|
||||
/* SC with Sequence Number subfield (bits 4-15 of the Sequence
|
||||
* Control field) masked to 0. */
|
||||
*pos++ = *sc & 0x0f;
|
||||
*pos++ = 0;
|
||||
|
||||
if (a3) {
|
||||
os_memcpy(pos, a3, ETH_ALEN);
|
||||
pos += ETH_ALEN;
|
||||
}
|
||||
}
|
||||
|
||||
*aad_len = pos - aad;
|
||||
|
||||
os_memcpy(nonce + 1, a2, ETH_ALEN);
|
||||
nonce[7] = pn[5]; /* PN5 */
|
||||
nonce[8] = pn[4]; /* PN4 */
|
||||
nonce[9] = pn[3]; /* PN3 */
|
||||
nonce[10] = pn[2]; /* PN2 */
|
||||
nonce[11] = pn[1]; /* PN1 */
|
||||
nonce[12] = pn[0]; /* PN0 */
|
||||
}
|
||||
|
||||
|
||||
u8 * ccmp_decrypt(_adapter *padapter, const u8 *tk, const struct ieee80211_hdr *hdr,
|
||||
const u8 *data, size_t data_len, size_t *decrypted_len)
|
||||
{
|
||||
u8 aad[30], nonce[13];
|
||||
size_t aad_len;
|
||||
size_t mlen;
|
||||
u8 *plain;
|
||||
|
||||
if (data_len < 8 + 8)
|
||||
return NULL;
|
||||
|
||||
plain = os_malloc(data_len + AES_BLOCK_SIZE);
|
||||
if (plain == NULL)
|
||||
return NULL;
|
||||
|
||||
mlen = data_len - 8 - 8;
|
||||
|
||||
os_memset(aad, 0, sizeof(aad));
|
||||
ccmp_aad_nonce(padapter, hdr, data, aad, &aad_len, nonce);
|
||||
wpa_hexdump(_MSG_EXCESSIVE_, "CCMP AAD", aad, aad_len);
|
||||
wpa_hexdump(_MSG_EXCESSIVE_, "CCMP nonce", nonce, 13);
|
||||
|
||||
if (aes_ccm_ad(tk, 16, nonce, 8, data + 8, mlen, aad, aad_len,
|
||||
data + 8 + mlen, plain) < 0) {
|
||||
u16 seq_ctrl = le_to_host16(hdr->seq_ctrl);
|
||||
wpa_printf(_MSG_INFO_, "Invalid CCMP MIC in frame: A1=" MACSTR
|
||||
" A2=" MACSTR " A3=" MACSTR " seq=%u frag=%u",
|
||||
MAC2STR(hdr->addr1), MAC2STR(hdr->addr2),
|
||||
MAC2STR(hdr->addr3),
|
||||
WLAN_GET_SEQ_SEQ(seq_ctrl),
|
||||
WLAN_GET_SEQ_FRAG(seq_ctrl));
|
||||
rtw_mfree(plain, data_len + AES_BLOCK_SIZE);
|
||||
return NULL;
|
||||
}
|
||||
wpa_hexdump(_MSG_EXCESSIVE_, "CCMP decrypted", plain, mlen);
|
||||
|
||||
*decrypted_len = mlen;
|
||||
return plain;
|
||||
}
|
||||
|
||||
|
||||
void ccmp_get_pn(u8 *pn, const u8 *data)
|
||||
{
|
||||
pn[0] = data[7]; /* PN5 */
|
||||
pn[1] = data[6]; /* PN4 */
|
||||
pn[2] = data[5]; /* PN3 */
|
||||
pn[3] = data[4]; /* PN2 */
|
||||
pn[4] = data[1]; /* PN1 */
|
||||
pn[5] = data[0]; /* PN0 */
|
||||
}
|
||||
|
||||
|
||||
u8 * ccmp_encrypt(_adapter *padapter, const u8 *tk, u8 *frame, size_t len, size_t hdrlen, u8 *qos,
|
||||
u8 *pn, int keyid, size_t *encrypted_len)
|
||||
{
|
||||
u8 aad[30], nonce[13];
|
||||
size_t aad_len, plen;
|
||||
u8 *crypt, *pos, *pdata;
|
||||
struct ieee80211_hdr *hdr;
|
||||
|
||||
if (len < hdrlen || hdrlen < 24)
|
||||
return NULL;
|
||||
plen = len - hdrlen;
|
||||
|
||||
crypt = os_malloc(hdrlen + 8 + plen + 8 + AES_BLOCK_SIZE);
|
||||
if (crypt == NULL)
|
||||
return NULL;
|
||||
|
||||
if (pn == NULL) {
|
||||
os_memcpy(crypt, frame, hdrlen + 8);
|
||||
hdr = (struct ieee80211_hdr *) crypt;
|
||||
hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP);
|
||||
pos = crypt + hdrlen + 8;
|
||||
pdata = frame + hdrlen + 8;
|
||||
} else {
|
||||
os_memcpy(crypt, frame, hdrlen);
|
||||
hdr = (struct ieee80211_hdr *) crypt;
|
||||
hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP);
|
||||
pos = crypt + hdrlen;
|
||||
*pos++ = pn[5]; /* PN0 */
|
||||
*pos++ = pn[4]; /* PN1 */
|
||||
*pos++ = 0x00; /* Rsvd */
|
||||
*pos++ = 0x20 | (keyid << 6);
|
||||
*pos++ = pn[3]; /* PN2 */
|
||||
*pos++ = pn[2]; /* PN3 */
|
||||
*pos++ = pn[1]; /* PN4 */
|
||||
*pos++ = pn[0]; /* PN5 */
|
||||
pdata = frame + hdrlen;
|
||||
}
|
||||
|
||||
os_memset(aad, 0, sizeof(aad));
|
||||
ccmp_aad_nonce(padapter, hdr, crypt + hdrlen, aad, &aad_len, nonce);
|
||||
wpa_hexdump(_MSG_EXCESSIVE_, "CCMP AAD", aad, aad_len);
|
||||
wpa_hexdump(_MSG_EXCESSIVE_, "CCMP nonce", nonce, 13);
|
||||
|
||||
if (aes_ccm_ae(tk, 16, nonce, 8, pdata, plen, aad, aad_len,
|
||||
pos, pos + plen) < 0) {
|
||||
rtw_mfree(crypt, hdrlen + 8 + plen + 8 + AES_BLOCK_SIZE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wpa_hexdump(_MSG_EXCESSIVE_, "CCMP encrypted", crypt + hdrlen + 8, plen);
|
||||
|
||||
*encrypted_len = hdrlen + 8 + plen + 8;
|
||||
|
||||
return crypt;
|
||||
}
|
||||
|
||||
|
||||
u8 * ccmp_encrypt_pv1(const u8 *tk, const u8 *a1, const u8 *a2, const u8 *a3,
|
||||
const u8 *frame, size_t len,
|
||||
size_t hdrlen, const u8 *pn, int keyid,
|
||||
size_t *encrypted_len)
|
||||
{
|
||||
u8 aad[24], nonce[13];
|
||||
size_t aad_len, plen;
|
||||
u8 *crypt, *pos;
|
||||
struct ieee80211_hdr *hdr;
|
||||
|
||||
if (len < hdrlen || hdrlen < 12)
|
||||
return NULL;
|
||||
plen = len - hdrlen;
|
||||
|
||||
crypt = os_malloc(hdrlen + plen + 8 + AES_BLOCK_SIZE);
|
||||
if (crypt == NULL)
|
||||
return NULL;
|
||||
|
||||
os_memcpy(crypt, frame, hdrlen);
|
||||
hdr = (struct ieee80211_hdr *) crypt;
|
||||
hdr->frame_control |= host_to_le16(BIT(12)); /* Protected Frame */
|
||||
pos = crypt + hdrlen;
|
||||
|
||||
os_memset(aad, 0, sizeof(aad));
|
||||
ccmp_aad_nonce_pv1(crypt, a1, a2, a3, pn, aad, &aad_len, nonce);
|
||||
wpa_hexdump(_MSG_EXCESSIVE_, "CCMP AAD", aad, aad_len);
|
||||
wpa_hexdump(_MSG_EXCESSIVE_, "CCMP nonce", nonce, sizeof(nonce));
|
||||
|
||||
if (aes_ccm_ae(tk, 16, nonce, 8, frame + hdrlen, plen, aad, aad_len,
|
||||
pos, pos + plen) < 0) {
|
||||
rtw_mfree(crypt, hdrlen + plen + 8 + AES_BLOCK_SIZE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wpa_hexdump(_MSG_EXCESSIVE_, "CCMP encrypted", crypt + hdrlen, plen);
|
||||
|
||||
*encrypted_len = hdrlen + plen + 8;
|
||||
|
||||
return crypt;
|
||||
}
|
||||
|
||||
|
||||
u8 * ccmp_256_decrypt(_adapter *padapter, const u8 *tk, const struct ieee80211_hdr *hdr,
|
||||
const u8 *data, size_t data_len, size_t *decrypted_len)
|
||||
{
|
||||
u8 aad[30], nonce[13];
|
||||
size_t aad_len;
|
||||
size_t mlen;
|
||||
u8 *plain;
|
||||
|
||||
if (data_len < 8 + 16)
|
||||
return NULL;
|
||||
|
||||
plain = os_malloc(data_len + AES_BLOCK_SIZE);
|
||||
if (plain == NULL)
|
||||
return NULL;
|
||||
|
||||
mlen = data_len - 8 - 16;
|
||||
|
||||
os_memset(aad, 0, sizeof(aad));
|
||||
ccmp_aad_nonce(padapter, hdr, data, aad, &aad_len, nonce);
|
||||
wpa_hexdump(_MSG_EXCESSIVE_, "CCMP-256 AAD", aad, aad_len);
|
||||
wpa_hexdump(_MSG_EXCESSIVE_, "CCMP-256 nonce", nonce, 13);
|
||||
|
||||
if (aes_ccm_ad(tk, 32, nonce, 16, data + 8, mlen, aad, aad_len,
|
||||
data + 8 + mlen, plain) < 0) {
|
||||
u16 seq_ctrl = le_to_host16(hdr->seq_ctrl);
|
||||
wpa_printf(_MSG_INFO_, "Invalid CCMP-256 MIC in frame: A1=" MACSTR
|
||||
" A2=" MACSTR " A3=" MACSTR " seq=%u frag=%u",
|
||||
MAC2STR(hdr->addr1), MAC2STR(hdr->addr2),
|
||||
MAC2STR(hdr->addr3),
|
||||
WLAN_GET_SEQ_SEQ(seq_ctrl),
|
||||
WLAN_GET_SEQ_FRAG(seq_ctrl));
|
||||
rtw_mfree(plain, data_len + AES_BLOCK_SIZE);
|
||||
return NULL;
|
||||
}
|
||||
wpa_hexdump(_MSG_EXCESSIVE_, "CCMP-256 decrypted", plain, mlen);
|
||||
|
||||
*decrypted_len = mlen;
|
||||
return plain;
|
||||
}
|
||||
|
||||
|
||||
u8 * ccmp_256_encrypt(_adapter *padapter, const u8 *tk, u8 *frame, size_t len, size_t hdrlen,
|
||||
u8 *qos, u8 *pn, int keyid, size_t *encrypted_len)
|
||||
{
|
||||
u8 aad[30], nonce[13];
|
||||
size_t aad_len, plen;
|
||||
u8 *crypt, *pos, *pdata;
|
||||
struct ieee80211_hdr *hdr;
|
||||
|
||||
if (len < hdrlen || hdrlen < 24)
|
||||
return NULL;
|
||||
plen = len - hdrlen;
|
||||
|
||||
crypt = os_malloc(hdrlen + 8 + plen + 16 + AES_BLOCK_SIZE);
|
||||
if (crypt == NULL)
|
||||
return NULL;
|
||||
|
||||
if (pn == NULL) {
|
||||
os_memcpy(crypt, frame, hdrlen + 8);
|
||||
hdr = (struct ieee80211_hdr *) crypt;
|
||||
hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP);
|
||||
pos = crypt + hdrlen + 8;
|
||||
pdata = frame + hdrlen + 8;
|
||||
} else {
|
||||
os_memcpy(crypt, frame, hdrlen);
|
||||
hdr = (struct ieee80211_hdr *) crypt;
|
||||
hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP);
|
||||
pos = crypt + hdrlen;
|
||||
*pos++ = pn[5]; /* PN0 */
|
||||
*pos++ = pn[4]; /* PN1 */
|
||||
*pos++ = 0x00; /* Rsvd */
|
||||
*pos++ = 0x20 | (keyid << 6);
|
||||
*pos++ = pn[3]; /* PN2 */
|
||||
*pos++ = pn[2]; /* PN3 */
|
||||
*pos++ = pn[1]; /* PN4 */
|
||||
*pos++ = pn[0]; /* PN5 */
|
||||
pdata = frame + hdrlen;
|
||||
}
|
||||
|
||||
os_memset(aad, 0, sizeof(aad));
|
||||
ccmp_aad_nonce(padapter, hdr, crypt + hdrlen, aad, &aad_len, nonce);
|
||||
wpa_hexdump(_MSG_EXCESSIVE_, "CCMP-256 AAD", aad, aad_len);
|
||||
wpa_hexdump(_MSG_EXCESSIVE_, "CCMP-256 nonce", nonce, 13);
|
||||
|
||||
if (aes_ccm_ae(tk, 32, nonce, 16, pdata, plen, aad, aad_len,
|
||||
pos, pos + plen) < 0) {
|
||||
rtw_mfree(crypt, hdrlen + 8 + plen + 16 + AES_BLOCK_SIZE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wpa_hexdump(_MSG_EXCESSIVE_, "CCMP-256 encrypted", crypt + hdrlen + 8,
|
||||
plen);
|
||||
|
||||
*encrypted_len = hdrlen + 8 + plen + 16;
|
||||
|
||||
return crypt;
|
||||
}
|
||||
194
drivers/net/wireless/rtl8822cs/core/crypto/gcmp.c
Normal file
194
drivers/net/wireless/rtl8822cs/core/crypto/gcmp.c
Normal file
@@ -0,0 +1,194 @@
|
||||
/*
|
||||
* GCM with GMAC Protocol (GCMP)
|
||||
* Copyright (c) 2012, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This software may be distributed under the terms of the BSD license.
|
||||
* See README for more details.
|
||||
*/
|
||||
|
||||
#include "rtw_crypto_wrap.h"
|
||||
|
||||
#include "aes.h"
|
||||
#include "aes_wrap.h"
|
||||
#include "wlancrypto_wrap.h"
|
||||
|
||||
|
||||
static void gcmp_aad_nonce(_adapter * padapter, const struct ieee80211_hdr *hdr, const u8 *data,
|
||||
u8 *aad, size_t *aad_len, u8 *nonce)
|
||||
{
|
||||
u16 fc, stype, seq;
|
||||
int qos = 0, addr4 = 0;
|
||||
u8 *pos;
|
||||
|
||||
fc = le_to_host16(hdr->frame_control);
|
||||
stype = WLAN_FC_GET_STYPE(fc);
|
||||
if ((fc & (WLAN_FC_TODS | WLAN_FC_FROMDS)) ==
|
||||
(WLAN_FC_TODS | WLAN_FC_FROMDS))
|
||||
addr4 = 1;
|
||||
|
||||
if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_DATA) {
|
||||
fc &= ~0x0070; /* Mask subtype bits */
|
||||
if (stype & WLAN_FC_STYPE_QOS_DATA) {
|
||||
const u8 *qc;
|
||||
qos = 1;
|
||||
fc &= ~WLAN_FC_ORDER;
|
||||
qc = (const u8 *)hdr + 24;
|
||||
if (addr4)
|
||||
qc += ETH_ALEN;
|
||||
}
|
||||
}
|
||||
|
||||
fc &= ~(WLAN_FC_RETRY | WLAN_FC_PWRMGT | WLAN_FC_MOREDATA);
|
||||
WPA_PUT_LE16(aad, fc);
|
||||
pos = aad + 2;
|
||||
os_memcpy(pos, GetAddr1Ptr((u8 *)hdr), 3 * ETH_ALEN);
|
||||
pos += 3 * ETH_ALEN;
|
||||
seq = le_to_host16(hdr->seq_ctrl);
|
||||
seq &= ~0xfff0; /* Mask Seq#; do not modify Frag# */
|
||||
WPA_PUT_LE16(pos, seq);
|
||||
pos += 2;
|
||||
|
||||
wpa_printf(_MSG_INFO_, "pos - aad = %u, qos(%d)\n", (pos - aad), qos);
|
||||
|
||||
os_memcpy(pos, (u8 *)hdr + 24, addr4 * ETH_ALEN + qos * 2);
|
||||
pos += addr4 * ETH_ALEN;
|
||||
if (qos) {
|
||||
pos[0] &= ~0x70;
|
||||
/* only spp mode need to refer QoS bit7 */
|
||||
if (padapter->registrypriv.amsdu_mode != RTW_AMSDU_MODE_SPP)
|
||||
pos[0] &= ~0x80;
|
||||
pos++;
|
||||
*pos++ = 0x00;
|
||||
}
|
||||
|
||||
wpa_printf(_MSG_INFO_, "pos - aad = %u\n", (pos - aad));
|
||||
*aad_len = pos - aad;
|
||||
|
||||
os_memcpy(nonce, hdr->addr2, ETH_ALEN);
|
||||
nonce[6] = data[7]; /* PN5 */
|
||||
nonce[7] = data[6]; /* PN4 */
|
||||
nonce[8] = data[5]; /* PN3 */
|
||||
nonce[9] = data[4]; /* PN2 */
|
||||
nonce[10] = data[1]; /* PN1 */
|
||||
nonce[11] = data[0]; /* PN0 */
|
||||
}
|
||||
|
||||
/**
|
||||
* gcmp_decrypt -
|
||||
* @tk: the temporal key
|
||||
* @tk_len: length of @tk
|
||||
* @hdr: the mac header
|
||||
* @data: payload after mac header (PN + enc_data + MIC)
|
||||
* @data_len: length of @data (PN + enc_data + MIC)
|
||||
* @decrypted_len: length of the data decrypted
|
||||
*/
|
||||
u8 * gcmp_decrypt(_adapter *padapter, const u8 *tk, size_t tk_len, const struct ieee80211_hdr *hdr,
|
||||
const u8 *data, size_t data_len, size_t *decrypted_len)
|
||||
{
|
||||
u8 aad[30], nonce[12], *plain;
|
||||
size_t aad_len, mlen;
|
||||
const u8 *m;
|
||||
|
||||
if (data_len < 8 + 16)
|
||||
return NULL;
|
||||
|
||||
plain = os_malloc(data_len + AES_BLOCK_SIZE);
|
||||
if (plain == NULL)
|
||||
return NULL;
|
||||
|
||||
m = data + 8;
|
||||
mlen = data_len - 8 - 16;
|
||||
|
||||
os_memset(aad, 0, sizeof(aad));
|
||||
gcmp_aad_nonce(padapter, hdr, data, aad, &aad_len, nonce);
|
||||
wpa_hexdump(_MSG_EXCESSIVE_, "GCMP AAD", aad, aad_len);
|
||||
wpa_hexdump(_MSG_EXCESSIVE_, "GCMP nonce", nonce, sizeof(nonce));
|
||||
|
||||
if (aes_gcm_ad(tk, tk_len, nonce, sizeof(nonce), m, mlen, aad, aad_len,
|
||||
m + mlen, plain) < 0) {
|
||||
u16 seq_ctrl = le_to_host16(hdr->seq_ctrl);
|
||||
wpa_printf(_MSG_INFO_, "Invalid GCMP frame: A1=" MACSTR
|
||||
" A2=" MACSTR " A3=" MACSTR " seq=%u frag=%u",
|
||||
MAC2STR(hdr->addr1), MAC2STR(hdr->addr2),
|
||||
MAC2STR(hdr->addr3),
|
||||
WLAN_GET_SEQ_SEQ(seq_ctrl),
|
||||
WLAN_GET_SEQ_FRAG(seq_ctrl));
|
||||
rtw_mfree(plain, data_len + AES_BLOCK_SIZE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*decrypted_len = mlen;
|
||||
return plain;
|
||||
}
|
||||
|
||||
/**
|
||||
* gcmp_encrypt -
|
||||
* @tk: the temporal key
|
||||
* @tk_len: length of @tk
|
||||
* @frame: the point to mac header, the frame including mac header and payload,
|
||||
* if @pn is NULL, then the frame including pn
|
||||
* @len: length of @frame
|
||||
* length = mac header + payload
|
||||
* @hdrlen: length of the mac header
|
||||
* @qos: pointer to the QOS field of the frame
|
||||
* @pn: packet number
|
||||
* @keyid: key id
|
||||
* @encrypted_len: length of the encrypted frame
|
||||
* including mac header, pn, payload and MIC
|
||||
*/
|
||||
u8 * gcmp_encrypt(_adapter *padapter, const u8 *tk, size_t tk_len, const u8 *frame, size_t len,
|
||||
size_t hdrlen, const u8 *qos,
|
||||
const u8 *pn, int keyid, size_t *encrypted_len)
|
||||
{
|
||||
u8 aad[30], nonce[12], *crypt, *pos;
|
||||
const u8 *pdata;
|
||||
size_t aad_len, plen;
|
||||
struct ieee80211_hdr *hdr;
|
||||
|
||||
if (len < hdrlen || hdrlen < 24)
|
||||
return NULL;
|
||||
plen = len - hdrlen;
|
||||
|
||||
crypt = os_malloc(hdrlen + 8 + plen + 16 + AES_BLOCK_SIZE);
|
||||
if (crypt == NULL)
|
||||
return NULL;
|
||||
|
||||
if (pn == NULL) {
|
||||
os_memcpy(crypt, frame, hdrlen + 8);
|
||||
hdr = (struct ieee80211_hdr *)crypt;
|
||||
pos = crypt + hdrlen + 8;
|
||||
pdata = frame + hdrlen + 8;
|
||||
} else {
|
||||
os_memcpy(crypt, frame, hdrlen);
|
||||
hdr = (struct ieee80211_hdr *)crypt;
|
||||
pos = crypt + hdrlen;
|
||||
|
||||
*pos++ = pn[5]; /* PN0 */
|
||||
*pos++ = pn[4]; /* PN1 */
|
||||
*pos++ = 0x00; /* Rsvd */
|
||||
*pos++ = 0x20 | (keyid << 6);
|
||||
*pos++ = pn[3]; /* PN2 */
|
||||
*pos++ = pn[2]; /* PN3 */
|
||||
*pos++ = pn[1]; /* PN4 */
|
||||
*pos++ = pn[0]; /* PN5 */
|
||||
pdata = frame + hdrlen;
|
||||
}
|
||||
|
||||
os_memset(aad, 0, sizeof(aad));
|
||||
gcmp_aad_nonce(padapter, hdr, crypt + hdrlen, aad, &aad_len, nonce);
|
||||
wpa_hexdump(_MSG_EXCESSIVE_, "GCMP AAD", aad, aad_len);
|
||||
wpa_hexdump(_MSG_EXCESSIVE_, "GCMP nonce", nonce, sizeof(nonce));
|
||||
|
||||
if (aes_gcm_ae(tk, tk_len, nonce, sizeof(nonce), pdata, plen,
|
||||
aad, aad_len, pos, pos + plen) < 0) {
|
||||
rtw_mfree(crypt, hdrlen + 8 + plen + 16 + AES_BLOCK_SIZE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wpa_hexdump(_MSG_EXCESSIVE_, "GCMP MIC", pos + plen, 16);
|
||||
wpa_hexdump(_MSG_EXCESSIVE_, "GCMP encrypted", pos, plen);
|
||||
|
||||
*encrypted_len = hdrlen + 8 + plen + 16;
|
||||
|
||||
return crypt;
|
||||
}
|
||||
85
drivers/net/wireless/rtl8822cs/core/crypto/rtw_crypto_wrap.c
Normal file
85
drivers/net/wireless/rtl8822cs/core/crypto/rtw_crypto_wrap.c
Normal file
@@ -0,0 +1,85 @@
|
||||
#include "rtw_crypto_wrap.h"
|
||||
|
||||
#ifndef DEBUG_CRYPTO
|
||||
#define DEBUG_CRYPTO 0
|
||||
#endif /* DEBUG_CRYTO */
|
||||
|
||||
int os_memcmp(const void *s1, const void *s2, size_t n)
|
||||
{
|
||||
return _rtw_memcmp2(s1, s2, n);
|
||||
}
|
||||
|
||||
int os_memcmp_const(const void *a, const void *b, size_t len)
|
||||
{
|
||||
const u8 *aa = a;
|
||||
const u8 *bb = b;
|
||||
size_t i;
|
||||
u8 res;
|
||||
|
||||
for (res = 0, i = 0; i < len; i++)
|
||||
res |= aa[i] ^ bb[i];
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void* os_memdup(const void *src, u32 sz)
|
||||
{
|
||||
void *r = rtw_malloc(sz);
|
||||
|
||||
if (r && src)
|
||||
_rtw_memcpy(r, src, sz);
|
||||
return r;
|
||||
}
|
||||
|
||||
size_t os_strlen(const char *s)
|
||||
{
|
||||
const char *p = s;
|
||||
while (*p)
|
||||
p++;
|
||||
return p - s;
|
||||
}
|
||||
|
||||
|
||||
void forced_memzero(void *ptr, size_t len)
|
||||
{
|
||||
_rtw_memset(ptr, 0, len);
|
||||
}
|
||||
|
||||
void bin_clear_free(void *bin, size_t len)
|
||||
{
|
||||
if (bin) {
|
||||
forced_memzero(bin, len);
|
||||
rtw_mfree(bin, len);
|
||||
}
|
||||
}
|
||||
|
||||
void wpa_printf(int level, const char *fmt, ...)
|
||||
{
|
||||
#if DEBUG_CRYPTO
|
||||
#define MSG_LEN 100
|
||||
va_list args;
|
||||
u8 buf[MSG_LEN] = { 0 };
|
||||
int err;
|
||||
|
||||
va_start(args, fmt);
|
||||
err = vsnprintf(buf, MSG_LEN, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
RTW_INFO("%s", buf);
|
||||
#undef MSG_LEN
|
||||
#endif /* DEBUG_CRYPTO */
|
||||
}
|
||||
|
||||
void wpa_hexdump(int level, const char *title, const void *buf, size_t len)
|
||||
{
|
||||
#if DEBUG_CRYPTO
|
||||
RTW_INFO_DUMP((u8 *)title, buf, len);
|
||||
#endif /* DEBUG_CRYPTO */
|
||||
}
|
||||
|
||||
void wpa_hexdump_key(int level, const char *title, const void *buf, size_t len)
|
||||
{
|
||||
#if DEBUG_CRYPTO
|
||||
RTW_INFO_DUMP((u8 *)title, buf, len);
|
||||
#endif /* DEBUG_CRYPTO */
|
||||
}
|
||||
64
drivers/net/wireless/rtl8822cs/core/crypto/rtw_crypto_wrap.h
Normal file
64
drivers/net/wireless/rtl8822cs/core/crypto/rtw_crypto_wrap.h
Normal file
@@ -0,0 +1,64 @@
|
||||
#ifndef RTW_CRYTO_WRAP_H
|
||||
#define RTW_CRYTO_WRAP_H
|
||||
|
||||
#include <drv_types.h>
|
||||
|
||||
#define TEST_FAIL() 0
|
||||
|
||||
#define os_memset _rtw_memset
|
||||
#define os_memcpy _rtw_memcpy
|
||||
#define os_malloc rtw_malloc
|
||||
|
||||
#define le_to_host16 le16_to_cpu
|
||||
#define host_to_le16 cpu_to_le16
|
||||
|
||||
#define WPA_PUT_LE16 RTW_PUT_LE16
|
||||
#define WPA_GET_LE16 RTW_GET_LE16
|
||||
#define WPA_PUT_LE32 RTW_PUT_LE32
|
||||
#define WPA_GET_LE32 RTW_GET_LE32
|
||||
#define WPA_PUT_LE64 RTW_PUT_LE64
|
||||
#define WPA_GET_LE64 RTW_GET_LE64
|
||||
#define WPA_PUT_BE16 RTW_PUT_BE16
|
||||
#define WPA_GET_BE16 RTW_GET_BE16
|
||||
#define WPA_PUT_BE32 RTW_PUT_BE32
|
||||
#define WPA_GET_BE32 RTW_GET_BE32
|
||||
#define WPA_PUT_BE64 RTW_PUT_BE64
|
||||
#define WPA_GET_BE64 RTW_GET_BE64
|
||||
|
||||
#ifndef MAC2STR
|
||||
#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
|
||||
#define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
|
||||
#endif
|
||||
|
||||
#define WLAN_FC_PVER 0x0003
|
||||
#define WLAN_FC_TODS 0x0100
|
||||
#define WLAN_FC_FROMDS 0x0200
|
||||
#define WLAN_FC_MOREFRAG 0x0400
|
||||
#define WLAN_FC_RETRY 0x0800
|
||||
#define WLAN_FC_PWRMGT 0x1000
|
||||
#define WLAN_FC_MOREDATA 0x2000
|
||||
#define WLAN_FC_ISWEP 0x4000
|
||||
#define WLAN_FC_ORDER 0x8000
|
||||
|
||||
#define WLAN_FC_TYPE_DATA RTW_IEEE80211_FTYPE_DATA
|
||||
#define WLAN_FC_TYPE_MGMT RTW_IEEE80211_FTYPE_MGMT
|
||||
|
||||
#define WLAN_FC_STYPE_QOS_DATA RTW_IEEE80211_STYPE_QOS_DATA
|
||||
|
||||
enum {
|
||||
_MSG_EXCESSIVE_, _MSG_MSGDUMP_, _MSG_DEBUG_, _MSG_INFO_, _MSG_WARNING_, _MSG_ERROR_
|
||||
};
|
||||
|
||||
int os_memcmp(const void *s1, const void *s2, size_t n);
|
||||
int os_memcmp_const(const void *a, const void *b, size_t len);
|
||||
void* os_memdup(const void *src, u32 sz);
|
||||
size_t os_strlen(const char *s);
|
||||
|
||||
void forced_memzero(void *ptr, size_t len);
|
||||
void bin_clear_free(void *bin, size_t len);
|
||||
|
||||
void wpa_printf(int level, const char *fmt, ...);
|
||||
void wpa_hexdump(int level, const char *title, const void *buf, size_t len);
|
||||
void wpa_hexdump_key(int level, const char *title, const void *buf, size_t len);
|
||||
|
||||
#endif /* RTW_CRYTO_WRAP_H */
|
||||
230
drivers/net/wireless/rtl8822cs/core/crypto/sha256-internal.c
Normal file
230
drivers/net/wireless/rtl8822cs/core/crypto/sha256-internal.c
Normal file
@@ -0,0 +1,230 @@
|
||||
/*
|
||||
* SHA-256 hash implementation and interface functions
|
||||
* Copyright (c) 2003-2011, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This software may be distributed under the terms of the BSD license.
|
||||
* See README for more details.
|
||||
*/
|
||||
|
||||
#include "rtw_crypto_wrap.h"
|
||||
|
||||
//#include "common.h"
|
||||
#include "sha256.h"
|
||||
#include "sha256_i.h"
|
||||
//#include "crypto.h"
|
||||
#include "wlancrypto_wrap.h"
|
||||
|
||||
|
||||
/**
|
||||
* sha256_vector - SHA256 hash for data vector
|
||||
* @num_elem: Number of elements in the data vector
|
||||
* @addr: Pointers to the data areas
|
||||
* @len: Lengths of the data blocks
|
||||
* @mac: Buffer for the hash
|
||||
* Returns: 0 on success, -1 of failure
|
||||
*/
|
||||
int sha256_vector(size_t num_elem, const u8 *addr[], const size_t *len,
|
||||
u8 *mac)
|
||||
{
|
||||
struct _sha256_state ctx;
|
||||
size_t i;
|
||||
|
||||
if (TEST_FAIL())
|
||||
return -1;
|
||||
|
||||
_sha256_init(&ctx);
|
||||
for (i = 0; i < num_elem; i++)
|
||||
if (sha256_process(&ctx, addr[i], len[i]))
|
||||
return -1;
|
||||
if (sha256_done(&ctx, mac))
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* ===== start - public domain SHA256 implementation ===== */
|
||||
|
||||
/* This is based on SHA256 implementation in LibTomCrypt that was released into
|
||||
* public domain by Tom St Denis. */
|
||||
|
||||
/* the K array */
|
||||
static const unsigned long K[64] = {
|
||||
0x428a2f98UL, 0x71374491UL, 0xb5c0fbcfUL, 0xe9b5dba5UL, 0x3956c25bUL,
|
||||
0x59f111f1UL, 0x923f82a4UL, 0xab1c5ed5UL, 0xd807aa98UL, 0x12835b01UL,
|
||||
0x243185beUL, 0x550c7dc3UL, 0x72be5d74UL, 0x80deb1feUL, 0x9bdc06a7UL,
|
||||
0xc19bf174UL, 0xe49b69c1UL, 0xefbe4786UL, 0x0fc19dc6UL, 0x240ca1ccUL,
|
||||
0x2de92c6fUL, 0x4a7484aaUL, 0x5cb0a9dcUL, 0x76f988daUL, 0x983e5152UL,
|
||||
0xa831c66dUL, 0xb00327c8UL, 0xbf597fc7UL, 0xc6e00bf3UL, 0xd5a79147UL,
|
||||
0x06ca6351UL, 0x14292967UL, 0x27b70a85UL, 0x2e1b2138UL, 0x4d2c6dfcUL,
|
||||
0x53380d13UL, 0x650a7354UL, 0x766a0abbUL, 0x81c2c92eUL, 0x92722c85UL,
|
||||
0xa2bfe8a1UL, 0xa81a664bUL, 0xc24b8b70UL, 0xc76c51a3UL, 0xd192e819UL,
|
||||
0xd6990624UL, 0xf40e3585UL, 0x106aa070UL, 0x19a4c116UL, 0x1e376c08UL,
|
||||
0x2748774cUL, 0x34b0bcb5UL, 0x391c0cb3UL, 0x4ed8aa4aUL, 0x5b9cca4fUL,
|
||||
0x682e6ff3UL, 0x748f82eeUL, 0x78a5636fUL, 0x84c87814UL, 0x8cc70208UL,
|
||||
0x90befffaUL, 0xa4506cebUL, 0xbef9a3f7UL, 0xc67178f2UL
|
||||
};
|
||||
|
||||
|
||||
/* Various logical functions */
|
||||
#define RORc(x, y) \
|
||||
( ((((unsigned long) (x) & 0xFFFFFFFFUL) >> (unsigned long) ((y) & 31)) | \
|
||||
((unsigned long) (x) << (unsigned long) (32 - ((y) & 31)))) & 0xFFFFFFFFUL)
|
||||
#define Ch(x,y,z) (z ^ (x & (y ^ z)))
|
||||
#define Maj(x,y,z) (((x | y) & z) | (x & y))
|
||||
#define S(x, n) RORc((x), (n))
|
||||
#define R(x, n) (((x)&0xFFFFFFFFUL)>>(n))
|
||||
#define Sigma0(x) (S(x, 2) ^ S(x, 13) ^ S(x, 22))
|
||||
#define Sigma1(x) (S(x, 6) ^ S(x, 11) ^ S(x, 25))
|
||||
#define Gamma0(x) (S(x, 7) ^ S(x, 18) ^ R(x, 3))
|
||||
#define Gamma1(x) (S(x, 17) ^ S(x, 19) ^ R(x, 10))
|
||||
#ifndef MIN
|
||||
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
|
||||
#endif
|
||||
|
||||
/* compress 512-bits */
|
||||
static int sha256_compress(struct _sha256_state *md, unsigned char *buf)
|
||||
{
|
||||
u32 S[8], W[64], t0, t1;
|
||||
u32 t;
|
||||
int i;
|
||||
|
||||
/* copy state into S */
|
||||
for (i = 0; i < 8; i++) {
|
||||
S[i] = md->state[i];
|
||||
}
|
||||
|
||||
/* copy the state into 512-bits into W[0..15] */
|
||||
for (i = 0; i < 16; i++)
|
||||
W[i] = WPA_GET_BE32(buf + (4 * i));
|
||||
|
||||
/* fill W[16..63] */
|
||||
for (i = 16; i < 64; i++) {
|
||||
W[i] = Gamma1(W[i - 2]) + W[i - 7] + Gamma0(W[i - 15]) +
|
||||
W[i - 16];
|
||||
}
|
||||
|
||||
/* Compress */
|
||||
#define RND(a,b,c,d,e,f,g,h,i) \
|
||||
t0 = h + Sigma1(e) + Ch(e, f, g) + K[i] + W[i]; \
|
||||
t1 = Sigma0(a) + Maj(a, b, c); \
|
||||
d += t0; \
|
||||
h = t0 + t1;
|
||||
|
||||
for (i = 0; i < 64; ++i) {
|
||||
RND(S[0], S[1], S[2], S[3], S[4], S[5], S[6], S[7], i);
|
||||
t = S[7]; S[7] = S[6]; S[6] = S[5]; S[5] = S[4];
|
||||
S[4] = S[3]; S[3] = S[2]; S[2] = S[1]; S[1] = S[0]; S[0] = t;
|
||||
}
|
||||
|
||||
/* feedback */
|
||||
for (i = 0; i < 8; i++) {
|
||||
md->state[i] = md->state[i] + S[i];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* Initialize the hash state */
|
||||
void _sha256_init(struct _sha256_state *md)
|
||||
{
|
||||
md->curlen = 0;
|
||||
md->length = 0;
|
||||
md->state[0] = 0x6A09E667UL;
|
||||
md->state[1] = 0xBB67AE85UL;
|
||||
md->state[2] = 0x3C6EF372UL;
|
||||
md->state[3] = 0xA54FF53AUL;
|
||||
md->state[4] = 0x510E527FUL;
|
||||
md->state[5] = 0x9B05688CUL;
|
||||
md->state[6] = 0x1F83D9ABUL;
|
||||
md->state[7] = 0x5BE0CD19UL;
|
||||
}
|
||||
|
||||
/**
|
||||
Process a block of memory though the hash
|
||||
@param md The hash state
|
||||
@param in The data to hash
|
||||
@param inlen The length of the data (octets)
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int sha256_process(struct _sha256_state *md, const unsigned char *in,
|
||||
unsigned long inlen)
|
||||
{
|
||||
unsigned long n;
|
||||
|
||||
if (md->curlen >= sizeof(md->buf))
|
||||
return -1;
|
||||
|
||||
while (inlen > 0) {
|
||||
if (md->curlen == 0 && inlen >= SHA256_BLOCK_SIZE) {
|
||||
if (sha256_compress(md, (unsigned char *) in) < 0)
|
||||
return -1;
|
||||
md->length += SHA256_BLOCK_SIZE * 8;
|
||||
in += SHA256_BLOCK_SIZE;
|
||||
inlen -= SHA256_BLOCK_SIZE;
|
||||
} else {
|
||||
n = MIN(inlen, (SHA256_BLOCK_SIZE - md->curlen));
|
||||
os_memcpy(md->buf + md->curlen, in, n);
|
||||
md->curlen += n;
|
||||
in += n;
|
||||
inlen -= n;
|
||||
if (md->curlen == SHA256_BLOCK_SIZE) {
|
||||
if (sha256_compress(md, md->buf) < 0)
|
||||
return -1;
|
||||
md->length += 8 * SHA256_BLOCK_SIZE;
|
||||
md->curlen = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Terminate the hash to get the digest
|
||||
@param md The hash state
|
||||
@param out [out] The destination of the hash (32 bytes)
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int sha256_done(struct _sha256_state *md, unsigned char *out)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (md->curlen >= sizeof(md->buf))
|
||||
return -1;
|
||||
|
||||
/* increase the length of the message */
|
||||
md->length += md->curlen * 8;
|
||||
|
||||
/* append the '1' bit */
|
||||
md->buf[md->curlen++] = (unsigned char) 0x80;
|
||||
|
||||
/* if the length is currently above 56 bytes we append zeros
|
||||
* then compress. Then we can fall back to padding zeros and length
|
||||
* encoding like normal.
|
||||
*/
|
||||
if (md->curlen > 56) {
|
||||
while (md->curlen < SHA256_BLOCK_SIZE) {
|
||||
md->buf[md->curlen++] = (unsigned char) 0;
|
||||
}
|
||||
sha256_compress(md, md->buf);
|
||||
md->curlen = 0;
|
||||
}
|
||||
|
||||
/* pad up to 56 bytes of zeroes */
|
||||
while (md->curlen < 56) {
|
||||
md->buf[md->curlen++] = (unsigned char) 0;
|
||||
}
|
||||
|
||||
/* store length */
|
||||
WPA_PUT_BE64(md->buf + 56, md->length);
|
||||
sha256_compress(md, md->buf);
|
||||
|
||||
/* copy output */
|
||||
for (i = 0; i < 8; i++)
|
||||
WPA_PUT_BE32(out + (4 * i), md->state[i]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ===== end - public domain SHA256 implementation ===== */
|
||||
109
drivers/net/wireless/rtl8822cs/core/crypto/sha256-prf.c
Normal file
109
drivers/net/wireless/rtl8822cs/core/crypto/sha256-prf.c
Normal file
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* SHA256-based PRF (IEEE 802.11r)
|
||||
* Copyright (c) 2003-2016, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This software may be distributed under the terms of the BSD license.
|
||||
* See README for more details.
|
||||
*/
|
||||
|
||||
#include "rtw_crypto_wrap.h"
|
||||
|
||||
//#include "common.h"
|
||||
#include "sha256.h"
|
||||
//#include "crypto.h"
|
||||
#include "wlancrypto_wrap.h"
|
||||
|
||||
|
||||
/**
|
||||
* sha256_prf - SHA256-based Pseudo-Random Function (IEEE 802.11r, 8.5.1.5.2)
|
||||
* @key: Key for PRF
|
||||
* @key_len: Length of the key in bytes
|
||||
* @label: A unique label for each purpose of the PRF
|
||||
* @data: Extra data to bind into the key
|
||||
* @data_len: Length of the data
|
||||
* @buf: Buffer for the generated pseudo-random key
|
||||
* @buf_len: Number of bytes of key to generate
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*
|
||||
* This function is used to derive new, cryptographically separate keys from a
|
||||
* given key.
|
||||
*/
|
||||
int sha256_prf(const u8 *key, size_t key_len, const char *label,
|
||||
const u8 *data, size_t data_len, u8 *buf, size_t buf_len)
|
||||
{
|
||||
return sha256_prf_bits(key, key_len, label, data, data_len, buf,
|
||||
buf_len * 8);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* sha256_prf_bits - IEEE Std 802.11-2012, 11.6.1.7.2 Key derivation function
|
||||
* @key: Key for KDF
|
||||
* @key_len: Length of the key in bytes
|
||||
* @label: A unique label for each purpose of the PRF
|
||||
* @data: Extra data to bind into the key
|
||||
* @data_len: Length of the data
|
||||
* @buf: Buffer for the generated pseudo-random key
|
||||
* @buf_len: Number of bits of key to generate
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*
|
||||
* This function is used to derive new, cryptographically separate keys from a
|
||||
* given key. If the requested buf_len is not divisible by eight, the least
|
||||
* significant 1-7 bits of the last octet in the output are not part of the
|
||||
* requested output.
|
||||
*/
|
||||
int sha256_prf_bits(const u8 *key, size_t key_len, const char *label,
|
||||
const u8 *data, size_t data_len, u8 *buf,
|
||||
size_t buf_len_bits)
|
||||
{
|
||||
u16 counter = 1;
|
||||
size_t pos, plen;
|
||||
u8 hash[SHA256_MAC_LEN];
|
||||
const u8 *addr[4];
|
||||
size_t len[4];
|
||||
u8 counter_le[2], length_le[2];
|
||||
size_t buf_len = (buf_len_bits + 7) / 8;
|
||||
|
||||
addr[0] = counter_le;
|
||||
len[0] = 2;
|
||||
addr[1] = (u8 *) label;
|
||||
len[1] = os_strlen(label);
|
||||
addr[2] = data;
|
||||
len[2] = data_len;
|
||||
addr[3] = length_le;
|
||||
len[3] = sizeof(length_le);
|
||||
|
||||
WPA_PUT_LE16(length_le, buf_len_bits);
|
||||
pos = 0;
|
||||
while (pos < buf_len) {
|
||||
plen = buf_len - pos;
|
||||
WPA_PUT_LE16(counter_le, counter);
|
||||
if (plen >= SHA256_MAC_LEN) {
|
||||
if (hmac_sha256_vector(key, key_len, 4, addr, len,
|
||||
&buf[pos]) < 0)
|
||||
return -1;
|
||||
pos += SHA256_MAC_LEN;
|
||||
} else {
|
||||
if (hmac_sha256_vector(key, key_len, 4, addr, len,
|
||||
hash) < 0)
|
||||
return -1;
|
||||
os_memcpy(&buf[pos], hash, plen);
|
||||
pos += plen;
|
||||
break;
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
|
||||
/*
|
||||
* Mask out unused bits in the last octet if it does not use all the
|
||||
* bits.
|
||||
*/
|
||||
if (buf_len_bits % 8) {
|
||||
u8 mask = 0xff << (8 - buf_len_bits % 8);
|
||||
buf[pos - 1] &= mask;
|
||||
}
|
||||
|
||||
forced_memzero(hash, sizeof(hash));
|
||||
|
||||
return 0;
|
||||
}
|
||||
104
drivers/net/wireless/rtl8822cs/core/crypto/sha256.c
Normal file
104
drivers/net/wireless/rtl8822cs/core/crypto/sha256.c
Normal file
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* SHA-256 hash implementation and interface functions
|
||||
* Copyright (c) 2003-2012, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This software may be distributed under the terms of the BSD license.
|
||||
* See README for more details.
|
||||
*/
|
||||
|
||||
#include "rtw_crypto_wrap.h"
|
||||
|
||||
#include "sha256.h"
|
||||
//#include "crypto.h"
|
||||
#include "wlancrypto_wrap.h"
|
||||
|
||||
|
||||
/**
|
||||
* hmac_sha256_vector - HMAC-SHA256 over data vector (RFC 2104)
|
||||
* @key: Key for HMAC operations
|
||||
* @key_len: Length of the key in bytes
|
||||
* @num_elem: Number of elements in the data vector
|
||||
* @addr: Pointers to the data areas
|
||||
* @len: Lengths of the data blocks
|
||||
* @mac: Buffer for the hash (32 bytes)
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*/
|
||||
int hmac_sha256_vector(const u8 *key, size_t key_len, size_t num_elem,
|
||||
const u8 *addr[], const size_t *len, u8 *mac)
|
||||
{
|
||||
unsigned char k_pad[64]; /* padding - key XORd with ipad/opad */
|
||||
unsigned char tk[32];
|
||||
const u8 *_addr[6];
|
||||
size_t _len[6], i;
|
||||
|
||||
if (num_elem > 5) {
|
||||
/*
|
||||
* Fixed limit on the number of fragments to avoid having to
|
||||
* allocate memory (which could fail).
|
||||
*/
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* if key is longer than 64 bytes reset it to key = SHA256(key) */
|
||||
if (key_len > 64) {
|
||||
if (sha256_vector(1, &key, &key_len, tk) < 0)
|
||||
return -1;
|
||||
key = tk;
|
||||
key_len = 32;
|
||||
}
|
||||
|
||||
/* the HMAC_SHA256 transform looks like:
|
||||
*
|
||||
* SHA256(K XOR opad, SHA256(K XOR ipad, text))
|
||||
*
|
||||
* where K is an n byte key
|
||||
* ipad is the byte 0x36 repeated 64 times
|
||||
* opad is the byte 0x5c repeated 64 times
|
||||
* and text is the data being protected */
|
||||
|
||||
/* start out by storing key in ipad */
|
||||
os_memset(k_pad, 0, sizeof(k_pad));
|
||||
os_memcpy(k_pad, key, key_len);
|
||||
/* XOR key with ipad values */
|
||||
for (i = 0; i < 64; i++)
|
||||
k_pad[i] ^= 0x36;
|
||||
|
||||
/* perform inner SHA256 */
|
||||
_addr[0] = k_pad;
|
||||
_len[0] = 64;
|
||||
for (i = 0; i < num_elem; i++) {
|
||||
_addr[i + 1] = addr[i];
|
||||
_len[i + 1] = len[i];
|
||||
}
|
||||
if (sha256_vector(1 + num_elem, _addr, _len, mac) < 0)
|
||||
return -1;
|
||||
|
||||
os_memset(k_pad, 0, sizeof(k_pad));
|
||||
os_memcpy(k_pad, key, key_len);
|
||||
/* XOR key with opad values */
|
||||
for (i = 0; i < 64; i++)
|
||||
k_pad[i] ^= 0x5c;
|
||||
|
||||
/* perform outer SHA256 */
|
||||
_addr[0] = k_pad;
|
||||
_len[0] = 64;
|
||||
_addr[1] = mac;
|
||||
_len[1] = SHA256_MAC_LEN;
|
||||
return sha256_vector(2, _addr, _len, mac);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* hmac_sha256 - HMAC-SHA256 over data buffer (RFC 2104)
|
||||
* @key: Key for HMAC operations
|
||||
* @key_len: Length of the key in bytes
|
||||
* @data: Pointers to the data area
|
||||
* @data_len: Length of the data area
|
||||
* @mac: Buffer for the hash (32 bytes)
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*/
|
||||
int hmac_sha256(const u8 *key, size_t key_len, const u8 *data,
|
||||
size_t data_len, u8 *mac)
|
||||
{
|
||||
return hmac_sha256_vector(key, key_len, 1, &data, &data_len, mac);
|
||||
}
|
||||
30
drivers/net/wireless/rtl8822cs/core/crypto/sha256.h
Normal file
30
drivers/net/wireless/rtl8822cs/core/crypto/sha256.h
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* SHA256 hash implementation and interface functions
|
||||
* Copyright (c) 2003-2016, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This software may be distributed under the terms of the BSD license.
|
||||
* See README for more details.
|
||||
*/
|
||||
|
||||
#ifndef SHA256_H
|
||||
#define SHA256_H
|
||||
|
||||
#define SHA256_MAC_LEN 32
|
||||
|
||||
int hmac_sha256_vector(const u8 *key, size_t key_len, size_t num_elem,
|
||||
const u8 *addr[], const size_t *len, u8 *mac);
|
||||
int hmac_sha256(const u8 *key, size_t key_len, const u8 *data,
|
||||
size_t data_len, u8 *mac);
|
||||
int sha256_prf(const u8 *key, size_t key_len, const char *label,
|
||||
const u8 *data, size_t data_len, u8 *buf, size_t buf_len);
|
||||
int sha256_prf_bits(const u8 *key, size_t key_len, const char *label,
|
||||
const u8 *data, size_t data_len, u8 *buf,
|
||||
size_t buf_len_bits);
|
||||
void tls_prf_sha256(const u8 *secret, size_t secret_len,
|
||||
const char *label, const u8 *seed, size_t seed_len,
|
||||
u8 *out, size_t outlen);
|
||||
int hmac_sha256_kdf(const u8 *secret, size_t secret_len,
|
||||
const char *label, const u8 *seed, size_t seed_len,
|
||||
u8 *out, size_t outlen);
|
||||
|
||||
#endif /* SHA256_H */
|
||||
25
drivers/net/wireless/rtl8822cs/core/crypto/sha256_i.h
Normal file
25
drivers/net/wireless/rtl8822cs/core/crypto/sha256_i.h
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* SHA-256 internal definitions
|
||||
* Copyright (c) 2003-2011, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This software may be distributed under the terms of the BSD license.
|
||||
* See README for more details.
|
||||
*/
|
||||
|
||||
#ifndef SHA256_I_H
|
||||
#define SHA256_I_H
|
||||
|
||||
#define SHA256_BLOCK_SIZE 64
|
||||
|
||||
struct _sha256_state {
|
||||
u64 length;
|
||||
u32 state[8], curlen;
|
||||
u8 buf[SHA256_BLOCK_SIZE];
|
||||
};
|
||||
|
||||
void _sha256_init(struct _sha256_state *md);
|
||||
int sha256_process(struct _sha256_state *md, const unsigned char *in,
|
||||
unsigned long inlen);
|
||||
int sha256_done(struct _sha256_state *md, unsigned char *out);
|
||||
|
||||
#endif /* SHA256_I_H */
|
||||
34
drivers/net/wireless/rtl8822cs/core/crypto/wlancrypto_wrap.h
Normal file
34
drivers/net/wireless/rtl8822cs/core/crypto/wlancrypto_wrap.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* wlantest - IEEE 802.11 protocol monitoring and testing tool
|
||||
* Copyright (c) 2010-2013, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This software may be distributed under the terms of the BSD license.
|
||||
* See README for more details.
|
||||
*/
|
||||
|
||||
#ifndef WLANCRYPTO_WRAP_H
|
||||
#define WLANCRYPTO_WRAP_H
|
||||
|
||||
int sha256_vector(size_t num_elem, const u8 *addr[], const size_t *len,
|
||||
u8 *mac);
|
||||
|
||||
u8* ccmp_decrypt(_adapter *padapter, const u8 *tk, const struct ieee80211_hdr *hdr,
|
||||
const u8 *data, size_t data_len, size_t *decrypted_len);
|
||||
u8* ccmp_encrypt(_adapter *padapter, const u8 *tk, u8 *frame, size_t len, size_t hdrlen, u8 *qos,
|
||||
u8 *pn, int keyid, size_t *encrypted_len);
|
||||
u8* ccmp_encrypt_pv1(const u8 *tk, const u8 *a1, const u8 *a2, const u8 *a3,
|
||||
const u8 *frame, size_t len,
|
||||
size_t hdrlen, const u8 *pn, int keyid,
|
||||
size_t *encrypted_len);
|
||||
u8* ccmp_256_decrypt(_adapter *padapter, const u8 *tk, const struct ieee80211_hdr *hdr,
|
||||
const u8 *data, size_t data_len, size_t *decrypted_len);
|
||||
u8* ccmp_256_encrypt(_adapter *padapter, const u8 *tk, u8 *frame, size_t len, size_t hdrlen,
|
||||
u8 *qos, u8 *pn, int keyid, size_t *encrypted_len);
|
||||
|
||||
u8* gcmp_decrypt(_adapter *padapter, const u8 *tk, size_t tk_len, const struct ieee80211_hdr *hdr,
|
||||
const u8 *data, size_t data_len, size_t *decrypted_len);
|
||||
u8* gcmp_encrypt(_adapter *padapter, const u8 *tk, size_t tk_len, const u8 *frame, size_t len,
|
||||
size_t hdrlen, const u8 *qos,
|
||||
const u8 *pn, int keyid, size_t *encrypted_len);
|
||||
|
||||
#endif /* WLANCRYPTO_WRAP_H */
|
||||
1519
drivers/net/wireless/rtl8822cs/core/def_module_country_chplan.h
Normal file
1519
drivers/net/wireless/rtl8822cs/core/def_module_country_chplan.h
Normal file
File diff suppressed because it is too large
Load Diff
3789
drivers/net/wireless/rtl8822cs/core/efuse/rtw_efuse.c
Normal file
3789
drivers/net/wireless/rtl8822cs/core/efuse/rtw_efuse.c
Normal file
File diff suppressed because it is too large
Load Diff
4353
drivers/net/wireless/rtl8822cs/core/mesh/rtw_mesh.c
Normal file
4353
drivers/net/wireless/rtl8822cs/core/mesh/rtw_mesh.c
Normal file
File diff suppressed because it is too large
Load Diff
537
drivers/net/wireless/rtl8822cs/core/mesh/rtw_mesh.h
Normal file
537
drivers/net/wireless/rtl8822cs/core/mesh/rtw_mesh.h
Normal file
@@ -0,0 +1,537 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright(c) 2007 - 2017 Realtek Corporation.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of version 2 of the GNU General Public License as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*****************************************************************************/
|
||||
#ifndef __RTW_MESH_H_
|
||||
#define __RTW_MESH_H_
|
||||
|
||||
#ifndef CONFIG_AP_MODE
|
||||
#error "CONFIG_RTW_MESH can't be enabled when CONFIG_AP_MODE is not defined\n"
|
||||
#endif
|
||||
|
||||
#define RTW_MESH_TTL 31
|
||||
#define RTW_MESH_PERR_MIN_INT 100
|
||||
#define RTW_MESH_DEFAULT_ELEMENT_TTL 31
|
||||
#define RTW_MESH_RANN_INTERVAL 5000
|
||||
#define RTW_MESH_PATH_TO_ROOT_TIMEOUT 6000
|
||||
#define RTW_MESH_DIAM_TRAVERSAL_TIME 50
|
||||
#define RTW_MESH_PATH_TIMEOUT 5000
|
||||
#define RTW_MESH_PREQ_MIN_INT 10
|
||||
#define RTW_MESH_MAX_PREQ_RETRIES 4
|
||||
#define RTW_MESH_MIN_DISCOVERY_TIMEOUT (2 * RTW_MESH_DIAM_TRAVERSAL_TIME)
|
||||
#define RTW_MESH_ROOT_CONFIRMATION_INTERVAL 2000
|
||||
#define RTW_MESH_PATH_REFRESH_TIME 1000
|
||||
#define RTW_MESH_ROOT_INTERVAL 5000
|
||||
|
||||
#define RTW_MESH_SANE_METRIC_DELTA 100
|
||||
#define RTW_MESH_MAX_ROOT_ADD_CHK_CNT 2
|
||||
|
||||
#define RTW_MESH_PLINK_UNKNOWN 0
|
||||
#define RTW_MESH_PLINK_LISTEN 1
|
||||
#define RTW_MESH_PLINK_OPN_SNT 2
|
||||
#define RTW_MESH_PLINK_OPN_RCVD 3
|
||||
#define RTW_MESH_PLINK_CNF_RCVD 4
|
||||
#define RTW_MESH_PLINK_ESTAB 5
|
||||
#define RTW_MESH_PLINK_HOLDING 6
|
||||
#define RTW_MESH_PLINK_BLOCKED 7
|
||||
|
||||
extern const char *_rtw_mesh_plink_str[];
|
||||
#define rtw_mesh_plink_str(s) ((s <= RTW_MESH_PLINK_BLOCKED) ? _rtw_mesh_plink_str[s] : _rtw_mesh_plink_str[RTW_MESH_PLINK_UNKNOWN])
|
||||
|
||||
#define RTW_MESH_PS_UNKNOWN 0
|
||||
#define RTW_MESH_PS_ACTIVE 1
|
||||
#define RTW_MESH_PS_LSLEEP 2
|
||||
#define RTW_MESH_PS_DSLEEP 3
|
||||
|
||||
extern const char *_rtw_mesh_ps_str[];
|
||||
#define rtw_mesh_ps_str(mps) ((mps <= RTW_MESH_PS_DSLEEP) ? _rtw_mesh_ps_str[mps] : _rtw_mesh_ps_str[RTW_MESH_PS_UNKNOWN])
|
||||
|
||||
#define GET_MESH_CONF_ELE_PATH_SEL_PROTO_ID(_iec) LE_BITS_TO_1BYTE(((u8 *)(_iec)) + 0, 0, 8)
|
||||
#define GET_MESH_CONF_ELE_PATH_SEL_METRIC_ID(_iec) LE_BITS_TO_1BYTE(((u8 *)(_iec)) + 1, 0, 8)
|
||||
#define GET_MESH_CONF_ELE_CONGEST_CTRL_MODE_ID(_iec) LE_BITS_TO_1BYTE(((u8 *)(_iec)) + 2, 0, 8)
|
||||
#define GET_MESH_CONF_ELE_SYNC_METHOD_ID(_iec) LE_BITS_TO_1BYTE(((u8 *)(_iec)) + 3, 0, 8)
|
||||
#define GET_MESH_CONF_ELE_AUTH_PROTO_ID(_iec) LE_BITS_TO_1BYTE(((u8 *)(_iec)) + 4, 0, 8)
|
||||
|
||||
#define GET_MESH_CONF_ELE_MESH_FORMATION(_iec) LE_BITS_TO_1BYTE(((u8 *)(_iec)) + 5, 0, 8)
|
||||
#define GET_MESH_CONF_ELE_CTO_MGATE(_iec) LE_BITS_TO_1BYTE(((u8 *)(_iec)) + 5, 0, 1)
|
||||
#define GET_MESH_CONF_ELE_NUM_OF_PEERINGS(_iec) LE_BITS_TO_1BYTE(((u8 *)(_iec)) + 5, 1, 6)
|
||||
#define GET_MESH_CONF_ELE_CTO_AS(_iec) LE_BITS_TO_1BYTE(((u8 *)(_iec)) + 5, 7, 1)
|
||||
|
||||
#define GET_MESH_CONF_ELE_MESH_CAP(_iec) LE_BITS_TO_1BYTE(((u8 *)(_iec)) + 6, 0, 8)
|
||||
#define GET_MESH_CONF_ELE_ACCEPT_PEERINGS(_iec) LE_BITS_TO_1BYTE(((u8 *)(_iec)) + 6, 0, 1)
|
||||
#define GET_MESH_CONF_ELE_MCCA_SUP(_iec) LE_BITS_TO_1BYTE(((u8 *)(_iec)) + 6, 1, 1)
|
||||
#define GET_MESH_CONF_ELE_MCCA_EN(_iec) LE_BITS_TO_1BYTE(((u8 *)(_iec)) + 6, 2, 1)
|
||||
#define GET_MESH_CONF_ELE_FORWARDING(_iec) LE_BITS_TO_1BYTE(((u8 *)(_iec)) + 6, 3, 1)
|
||||
#define GET_MESH_CONF_ELE_MBCA_EN(_iec) LE_BITS_TO_1BYTE(((u8 *)(_iec)) + 6, 4, 1)
|
||||
#define GET_MESH_CONF_ELE_TBTT_ADJ(_iec) LE_BITS_TO_1BYTE(((u8 *)(_iec)) + 6, 5, 1)
|
||||
#define GET_MESH_CONF_ELE_PS_LEVEL(_iec) LE_BITS_TO_1BYTE(((u8 *)(_iec)) + 6, 6, 1)
|
||||
|
||||
#define SET_MESH_CONF_ELE_PATH_SEL_PROTO_ID(_iec, _val) SET_BITS_TO_LE_1BYTE(((u8 *)(_iec)) + 0, 0, 8, _val)
|
||||
#define SET_MESH_CONF_ELE_PATH_SEL_METRIC_ID(_iec, _val) SET_BITS_TO_LE_1BYTE(((u8 *)(_iec)) + 1, 0, 8, _val)
|
||||
#define SET_MESH_CONF_ELE_CONGEST_CTRL_MODE_ID(_iec, _val) SET_BITS_TO_LE_1BYTE(((u8 *)(_iec)) + 2, 0, 8, _val)
|
||||
#define SET_MESH_CONF_ELE_SYNC_METHOD_ID(_iec, _val) SET_BITS_TO_LE_1BYTE(((u8 *)(_iec)) + 3, 0, 8, _val)
|
||||
#define SET_MESH_CONF_ELE_AUTH_PROTO_ID(_iec, _val) SET_BITS_TO_LE_1BYTE(((u8 *)(_iec)) + 4, 0, 8, _val)
|
||||
|
||||
#define SET_MESH_CONF_ELE_CTO_MGATE(_iec, _val) SET_BITS_TO_LE_1BYTE(((u8 *)(_iec)) + 5, 0, 1, _val)
|
||||
#define SET_MESH_CONF_ELE_NUM_OF_PEERINGS(_iec, _val) SET_BITS_TO_LE_1BYTE(((u8 *)(_iec)) + 5, 1, 6, _val)
|
||||
#define SET_MESH_CONF_ELE_CTO_AS(_iec, _val) SET_BITS_TO_LE_1BYTE(((u8 *)(_iec)) + 5, 7, 1, _val)
|
||||
|
||||
#define SET_MESH_CONF_ELE_ACCEPT_PEERINGS(_iec, _val) SET_BITS_TO_LE_1BYTE(((u8 *)(_iec)) + 6, 0, 1, _val)
|
||||
#define SET_MESH_CONF_ELE_MCCA_SUP(_iec, _val) SET_BITS_TO_LE_1BYTE(((u8 *)(_iec)) + 6, 1, 1, _val)
|
||||
#define SET_MESH_CONF_ELE_MCCA_EN(_iec, _val) SET_BITS_TO_LE_1BYTE(((u8 *)(_iec)) + 6, 2, 1, _val)
|
||||
#define SET_MESH_CONF_ELE_FORWARDING(_iec, _val) SET_BITS_TO_LE_1BYTE(((u8 *)(_iec)) + 6, 3, 1, _val)
|
||||
#define SET_MESH_CONF_ELE_MBCA_EN(_iec, _val) SET_BITS_TO_LE_1BYTE(((u8 *)(_iec)) + 6, 4, 1, _val)
|
||||
#define SET_MESH_CONF_ELE_TBTT_ADJ(_iec, _val) SET_BITS_TO_LE_1BYTE(((u8 *)(_iec)) + 6, 5, 1, _val)
|
||||
#define SET_MESH_CONF_ELE_PS_LEVEL(_iec, _val) SET_BITS_TO_LE_1BYTE(((u8 *)(_iec)) + 6, 6, 1, _val)
|
||||
|
||||
/* Mesh flags */
|
||||
#define MESH_FLAGS_AE 0x3 /* mask */
|
||||
#define MESH_FLAGS_AE_A4 0x1
|
||||
#define MESH_FLAGS_AE_A5_A6 0x2
|
||||
|
||||
/* Max number of paths */
|
||||
#define RTW_MESH_MAX_PATHS 1024
|
||||
|
||||
#define RTW_PREQ_Q_F_START 0x1
|
||||
#define RTW_PREQ_Q_F_REFRESH 0x2
|
||||
#define RTW_PREQ_Q_F_CHK 0x4
|
||||
#define RTW_PREQ_Q_F_PEER_AKA 0x8
|
||||
#define RTW_PREQ_Q_F_BCAST_PREQ 0x10 /* force path_dicover using broadcast */
|
||||
struct rtw_mesh_preq_queue {
|
||||
_list list;
|
||||
u8 dst[ETH_ALEN];
|
||||
u8 flags;
|
||||
};
|
||||
|
||||
extern const u8 ae_to_mesh_ctrl_len[];
|
||||
|
||||
enum mesh_frame_type {
|
||||
MESH_UCAST_DATA = 0x0,
|
||||
MESH_BMCAST_DATA = 0x1,
|
||||
MESH_UCAST_PX_DATA = 0x2,
|
||||
MESH_BMCAST_PX_DATA = 0x3,
|
||||
MESH_MHOP_UCAST_ACT = 0x4,
|
||||
MESH_MHOP_BMCAST_ACT = 0x5,
|
||||
};
|
||||
|
||||
enum mpath_sel_frame_type {
|
||||
MPATH_PREQ = 0,
|
||||
MPATH_PREP,
|
||||
MPATH_PERR,
|
||||
MPATH_RANN
|
||||
};
|
||||
|
||||
/**
|
||||
* enum rtw_mesh_deferred_task_flags - mesh deferred tasks
|
||||
*
|
||||
*
|
||||
*
|
||||
* @RTW_MESH_WORK_HOUSEKEEPING: run the periodic mesh housekeeping tasks
|
||||
* @RTW_MESH_WORK_ROOT: the mesh root station needs to send a frame
|
||||
* @RTW_MESH_WORK_DRIFT_ADJUST: time to compensate for clock drift relative to other
|
||||
* mesh nodes
|
||||
* @RTW_MESH_WORK_MBSS_CHANGED: rebuild beacon and notify driver of BSS changes
|
||||
*/
|
||||
enum rtw_mesh_deferred_task_flags {
|
||||
RTW_MESH_WORK_HOUSEKEEPING,
|
||||
RTW_MESH_WORK_ROOT,
|
||||
RTW_MESH_WORK_DRIFT_ADJUST,
|
||||
RTW_MESH_WORK_MBSS_CHANGED,
|
||||
};
|
||||
|
||||
#define RTW_MESH_MAX_PEER_CANDIDATES 15 /* aid consideration */
|
||||
#define RTW_MESH_MAX_PEER_LINKS 8
|
||||
#define RTW_MESH_PEER_LINK_TIMEOUT 20
|
||||
|
||||
#define RTW_MESH_PEER_CONF_DISABLED 0 /* special time value means no confirmation ongoing */
|
||||
#if CONFIG_RTW_MESH_PEER_BLACKLIST
|
||||
#define IS_PEER_CONF_DISABLED(plink) ((plink)->peer_conf_end_time == RTW_MESH_PEER_CONF_DISABLED)
|
||||
#define IS_PEER_CONF_TIMEOUT(plink)(!IS_PEER_CONF_DISABLED(plink) && rtw_time_after(rtw_get_current_time(), (plink)->peer_conf_end_time))
|
||||
#define SET_PEER_CONF_DISABLED(plink) (plink)->peer_conf_end_time = RTW_MESH_PEER_CONF_DISABLED
|
||||
#define SET_PEER_CONF_END_TIME(plink, timeout_ms) \
|
||||
do { \
|
||||
(plink)->peer_conf_end_time = rtw_get_current_time() + rtw_ms_to_systime(timeout_ms); \
|
||||
if ((plink)->peer_conf_end_time == RTW_MESH_PEER_CONF_DISABLED) \
|
||||
(plink)->peer_conf_end_time++; \
|
||||
} while (0)
|
||||
#else
|
||||
#define IS_PEER_CONF_DISABLED(plink) 1
|
||||
#define IS_PEER_CONF_TIMEOUT(plink) 0
|
||||
#define SET_PEER_CONF_DISABLED(plink) do {} while (0)
|
||||
#define SET_PEER_CONF_END_TIME(plink, timeout_ms) do {} while (0)
|
||||
#endif /* CONFIG_RTW_MESH_PEER_BLACKLIST */
|
||||
|
||||
#define RTW_MESH_CTO_MGATE_CONF_DISABLED 0 /* special time value means no confirmation ongoing */
|
||||
#if CONFIG_RTW_MESH_CTO_MGATE_BLACKLIST
|
||||
#define IS_CTO_MGATE_CONF_DISABLED(plink) ((plink)->cto_mgate_conf_end_time == RTW_MESH_CTO_MGATE_CONF_DISABLED)
|
||||
#define IS_CTO_MGATE_CONF_TIMEOUT(plink)(!IS_CTO_MGATE_CONF_DISABLED(plink) && rtw_time_after(rtw_get_current_time(), (plink)->cto_mgate_conf_end_time))
|
||||
#define SET_CTO_MGATE_CONF_DISABLED(plink) (plink)->cto_mgate_conf_end_time = RTW_MESH_CTO_MGATE_CONF_DISABLED
|
||||
#define SET_CTO_MGATE_CONF_END_TIME(plink, timeout_ms) \
|
||||
do { \
|
||||
(plink)->cto_mgate_conf_end_time = rtw_get_current_time() + rtw_ms_to_systime(timeout_ms); \
|
||||
if ((plink)->cto_mgate_conf_end_time == RTW_MESH_CTO_MGATE_CONF_DISABLED) \
|
||||
(plink)->cto_mgate_conf_end_time++; \
|
||||
} while (0)
|
||||
#else
|
||||
#define IS_CTO_MGATE_CONF_DISABLED(plink) 1
|
||||
#define IS_CTO_MGATE_CONF_TIMEOUT(plink) 0
|
||||
#define SET_CTO_MGATE_CONF_DISABLED(plink) do {} while (0)
|
||||
#define SET_CTO_MGATE_CONF_END_TIME(plink, timeout_ms) do {} while (0)
|
||||
#endif /* CONFIG_RTW_MESH_CTO_MGATE_BLACKLIST */
|
||||
|
||||
struct mesh_plink_ent {
|
||||
u8 valid;
|
||||
u8 addr[ETH_ALEN];
|
||||
u8 plink_state;
|
||||
|
||||
#ifdef CONFIG_RTW_MESH_AEK
|
||||
u8 aek_valid;
|
||||
u8 aek[32];
|
||||
#endif
|
||||
|
||||
u16 llid;
|
||||
u16 plid;
|
||||
#ifndef CONFIG_RTW_MESH_DRIVER_AID
|
||||
u16 aid; /* aid assigned from upper layer */
|
||||
#endif
|
||||
u16 peer_aid; /* aid assigned from peer */
|
||||
|
||||
u8 chosen_pmk[16];
|
||||
|
||||
#ifdef CONFIG_RTW_MESH_AEK
|
||||
u8 sel_pcs[4];
|
||||
u8 l_nonce[32];
|
||||
u8 p_nonce[32];
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_RTW_MESH_DRIVER_AID
|
||||
u8 *tx_conf_ies;
|
||||
u16 tx_conf_ies_len;
|
||||
#endif
|
||||
u8 *rx_conf_ies;
|
||||
u16 rx_conf_ies_len;
|
||||
|
||||
struct wlan_network *scanned;
|
||||
|
||||
#if CONFIG_RTW_MESH_PEER_BLACKLIST
|
||||
systime peer_conf_end_time;
|
||||
#endif
|
||||
#if CONFIG_RTW_MESH_CTO_MGATE_BLACKLIST
|
||||
systime cto_mgate_conf_end_time;
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifdef CONFIG_RTW_MESH_AEK
|
||||
#define MESH_PLINK_AEK_VALID(ent) ent->aek_valid
|
||||
#else
|
||||
#define MESH_PLINK_AEK_VALID(ent) 0
|
||||
#endif
|
||||
|
||||
struct mesh_plink_pool {
|
||||
_lock lock;
|
||||
u8 num; /* current ent being used */
|
||||
struct mesh_plink_ent ent[RTW_MESH_MAX_PEER_CANDIDATES];
|
||||
|
||||
#if CONFIG_RTW_MESH_ACNODE_PREVENT
|
||||
u8 acnode_rsvd;
|
||||
#endif
|
||||
|
||||
#if CONFIG_RTW_MESH_PEER_BLACKLIST
|
||||
_queue peer_blacklist;
|
||||
#endif
|
||||
#if CONFIG_RTW_MESH_CTO_MGATE_BLACKLIST
|
||||
_queue cto_mgate_blacklist;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct mesh_peer_sel_policy {
|
||||
u32 scanr_exp_ms;
|
||||
|
||||
#if CONFIG_RTW_MESH_ACNODE_PREVENT
|
||||
u8 acnode_prevent;
|
||||
u32 acnode_conf_timeout_ms;
|
||||
u32 acnode_notify_timeout_ms;
|
||||
#endif
|
||||
|
||||
#if CONFIG_RTW_MESH_OFFCH_CAND
|
||||
u8 offch_cand;
|
||||
u32 offch_find_int_ms; /* 0 means no offch find triggerred by driver self*/
|
||||
#endif
|
||||
|
||||
#if CONFIG_RTW_MESH_PEER_BLACKLIST
|
||||
u32 peer_conf_timeout_ms;
|
||||
u32 peer_blacklist_timeout_ms;
|
||||
#endif
|
||||
|
||||
#if CONFIG_RTW_MESH_CTO_MGATE_BLACKLIST
|
||||
u8 cto_mgate_require;
|
||||
u32 cto_mgate_conf_timeout_ms;
|
||||
u32 cto_mgate_blacklist_timeout_ms;
|
||||
#endif
|
||||
};
|
||||
|
||||
/* b2u flags */
|
||||
#define RTW_MESH_B2U_ALL BIT0
|
||||
#define RTW_MESH_B2U_GA_UCAST BIT1 /* Group addressed unicast frame, forward only */
|
||||
#define RTW_MESH_B2U_BCAST BIT2
|
||||
#define RTW_MESH_B2U_IP_MCAST BIT3
|
||||
|
||||
#define rtw_msrc_b2u_policy_chk(flags, mda) ( \
|
||||
(flags & RTW_MESH_B2U_ALL) \
|
||||
|| ((flags & RTW_MESH_B2U_BCAST) && is_broadcast_mac_addr(mda)) \
|
||||
|| ((flags & RTW_MESH_B2U_IP_MCAST) && (IP_MCAST_MAC(mda) || ICMPV6_MCAST_MAC(mda))) \
|
||||
)
|
||||
|
||||
#define rtw_mfwd_b2u_policy_chk(flags, mda, ucst) ( \
|
||||
(flags & RTW_MESH_B2U_ALL) \
|
||||
|| ((flags & RTW_MESH_B2U_GA_UCAST) && ucst) \
|
||||
|| ((flags & RTW_MESH_B2U_BCAST) && is_broadcast_mac_addr(mda)) \
|
||||
|| ((flags & RTW_MESH_B2U_IP_MCAST) && (IP_MCAST_MAC(mda) || ICMPV6_MCAST_MAC(mda))) \
|
||||
)
|
||||
|
||||
/**
|
||||
* @sane_metric_delta: Controlling if trigger additional path check mechanism
|
||||
* @max_root_add_chk_cnt: The retry cnt to send additional root confirmation
|
||||
* PREQ through old(last) path
|
||||
*/
|
||||
struct rtw_mesh_cfg {
|
||||
u8 max_peer_links; /* peering limit */
|
||||
u32 plink_timeout; /* seconds */
|
||||
|
||||
u8 dot11MeshTTL;
|
||||
u8 element_ttl;
|
||||
u32 path_refresh_time;
|
||||
u16 dot11MeshHWMPpreqMinInterval;
|
||||
u16 dot11MeshHWMPnetDiameterTraversalTime;
|
||||
u32 dot11MeshHWMPactivePathTimeout;
|
||||
u8 dot11MeshHWMPmaxPREQretries;
|
||||
u16 min_discovery_timeout;
|
||||
u16 dot11MeshHWMPconfirmationInterval;
|
||||
u16 dot11MeshHWMPperrMinInterval;
|
||||
u8 dot11MeshHWMPRootMode;
|
||||
BOOLEAN dot11MeshForwarding;
|
||||
s32 rssi_threshold; /* in dBm, 0: no specified */
|
||||
u16 dot11MeshHWMPRannInterval;
|
||||
BOOLEAN dot11MeshGateAnnouncementProtocol;
|
||||
u32 dot11MeshHWMPactivePathToRootTimeout;
|
||||
u16 dot11MeshHWMProotInterval;
|
||||
u8 path_gate_timeout_factor;
|
||||
#ifdef CONFIG_RTW_MESH_ADD_ROOT_CHK
|
||||
u16 sane_metric_delta;
|
||||
u8 max_root_add_chk_cnt;
|
||||
#endif
|
||||
|
||||
struct mesh_peer_sel_policy peer_sel_policy;
|
||||
|
||||
#if CONFIG_RTW_MESH_DATA_BMC_TO_UC
|
||||
u8 b2u_flags_msrc;
|
||||
u8 b2u_flags_mfwd;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct rtw_mesh_stats {
|
||||
u32 fwded_mcast; /* Mesh forwarded multicast frames */
|
||||
u32 fwded_unicast; /* Mesh forwarded unicast frames */
|
||||
u32 fwded_frames; /* Mesh total forwarded frames */
|
||||
u32 dropped_frames_ttl; /* Not transmitted since mesh_ttl == 0*/
|
||||
u32 dropped_frames_no_route; /* Not transmitted, no route found */
|
||||
u32 dropped_frames_congestion;/* Not forwarded due to congestion */
|
||||
u32 dropped_frames_duplicate;
|
||||
|
||||
u32 mrc_del_qlen; /* MRC entry deleted cause by queue length limit */
|
||||
};
|
||||
|
||||
struct rtw_mrc;
|
||||
|
||||
struct rtw_mesh_info {
|
||||
u8 mesh_id[NDIS_802_11_LENGTH_SSID];
|
||||
size_t mesh_id_len;
|
||||
/* Active Path Selection Protocol Identifier */
|
||||
u8 mesh_pp_id;
|
||||
/* Active Path Selection Metric Identifier */
|
||||
u8 mesh_pm_id;
|
||||
/* Congestion Control Mode Identifier */
|
||||
u8 mesh_cc_id;
|
||||
/* Synchronization Protocol Identifier */
|
||||
u8 mesh_sp_id;
|
||||
/* Authentication Protocol Identifier */
|
||||
u8 mesh_auth_id;
|
||||
|
||||
struct mesh_plink_pool plink_ctl;
|
||||
|
||||
u32 mesh_seqnum;
|
||||
/* MSTA's own hwmp sequence number */
|
||||
u32 sn;
|
||||
systime last_preq;
|
||||
systime last_sn_update;
|
||||
systime next_perr;
|
||||
/* Last used Path Discovery ID */
|
||||
u32 preq_id;
|
||||
|
||||
ATOMIC_T mpaths;
|
||||
struct rtw_mesh_table *mesh_paths;
|
||||
struct rtw_mesh_table *mpp_paths;
|
||||
int mesh_paths_generation;
|
||||
int mpp_paths_generation;
|
||||
|
||||
int num_gates;
|
||||
struct rtw_mesh_path *max_addr_gate;
|
||||
bool max_addr_gate_is_larger_than_self;
|
||||
|
||||
struct rtw_mesh_stats mshstats;
|
||||
|
||||
_queue mpath_tx_queue;
|
||||
u32 mpath_tx_queue_len;
|
||||
_tasklet mpath_tx_tasklet;
|
||||
|
||||
struct rtw_mrc *mrc;
|
||||
|
||||
_lock mesh_preq_queue_lock;
|
||||
struct rtw_mesh_preq_queue preq_queue;
|
||||
int preq_queue_len;
|
||||
};
|
||||
|
||||
extern const char *_action_self_protected_str[];
|
||||
#define action_self_protected_str(action) ((action < RTW_ACT_SELF_PROTECTED_NUM) ? _action_self_protected_str[action] : _action_self_protected_str[0])
|
||||
|
||||
u8 *rtw_set_ie_mesh_id(u8 *buf, u32 *buf_len, const char *mesh_id, u8 id_len);
|
||||
u8 *rtw_set_ie_mesh_config(u8 *buf, u32 *buf_len
|
||||
, u8 path_sel_proto, u8 path_sel_metric, u8 congest_ctl_mode, u8 sync_method, u8 auth_proto
|
||||
, u8 num_of_peerings, bool cto_mgate, bool cto_as
|
||||
, bool accept_peerings, bool mcca_sup, bool mcca_en, bool forwarding
|
||||
, bool mbca_en, bool tbtt_adj, bool ps_level);
|
||||
|
||||
int rtw_bss_is_same_mbss(WLAN_BSSID_EX *a, WLAN_BSSID_EX *b);
|
||||
int rtw_bss_is_candidate_mesh_peer(_adapter *adapter, WLAN_BSSID_EX *target, u8 ch, u8 add_peer);
|
||||
|
||||
void rtw_chk_candidate_peer_notify(_adapter *adapter, struct wlan_network *scanned);
|
||||
|
||||
void rtw_mesh_peer_status_chk(_adapter *adapter);
|
||||
|
||||
#if CONFIG_RTW_MESH_ACNODE_PREVENT
|
||||
void rtw_mesh_update_scanned_acnode_status(_adapter *adapter, struct wlan_network *scanned);
|
||||
bool rtw_mesh_scanned_is_acnode_confirmed(_adapter *adapter, struct wlan_network *scanned);
|
||||
bool rtw_mesh_acnode_prevent_allow_sacrifice(_adapter *adapter);
|
||||
struct sta_info *rtw_mesh_acnode_prevent_pick_sacrifice(_adapter *adapter);
|
||||
void dump_mesh_acnode_prevent_settings(void *sel, _adapter *adapter);
|
||||
#endif
|
||||
|
||||
#if CONFIG_RTW_MESH_OFFCH_CAND
|
||||
u8 rtw_mesh_offch_candidate_accepted(_adapter *adapter);
|
||||
u8 rtw_mesh_select_operating_ch(_adapter *adapter);
|
||||
void dump_mesh_offch_cand_settings(void *sel, _adapter *adapter);
|
||||
#endif
|
||||
|
||||
#if CONFIG_RTW_MESH_PEER_BLACKLIST
|
||||
int rtw_mesh_peer_blacklist_add(_adapter *adapter, const u8 *addr);
|
||||
int rtw_mesh_peer_blacklist_del(_adapter *adapter, const u8 *addr);
|
||||
int rtw_mesh_peer_blacklist_search(_adapter *adapter, const u8 *addr);
|
||||
void rtw_mesh_peer_blacklist_flush(_adapter *adapter);
|
||||
void dump_mesh_peer_blacklist(void *sel, _adapter *adapter);
|
||||
void dump_mesh_peer_blacklist_settings(void *sel, _adapter *adapter);
|
||||
#endif
|
||||
#if CONFIG_RTW_MESH_CTO_MGATE_BLACKLIST
|
||||
u8 rtw_mesh_cto_mgate_required(_adapter *adapter);
|
||||
u8 rtw_mesh_cto_mgate_network_filter(_adapter *adapter, struct wlan_network *scanned);
|
||||
int rtw_mesh_cto_mgate_blacklist_add(_adapter *adapter, const u8 *addr);
|
||||
int rtw_mesh_cto_mgate_blacklist_del(_adapter *adapter, const u8 *addr);
|
||||
int rtw_mesh_cto_mgate_blacklist_search(_adapter *adapter, const u8 *addr);
|
||||
void rtw_mesh_cto_mgate_blacklist_flush(_adapter *adapter);
|
||||
void dump_mesh_cto_mgate_blacklist(void *sel, _adapter *adapter);
|
||||
void dump_mesh_cto_mgate_blacklist_settings(void *sel, _adapter *adapter);
|
||||
#endif
|
||||
void dump_mesh_peer_sel_policy(void *sel, _adapter *adapter);
|
||||
void dump_mesh_networks(void *sel, _adapter *adapter);
|
||||
|
||||
void rtw_mesh_adjust_chbw(u8 req_ch, u8 *req_bw, u8 *req_offset);
|
||||
|
||||
void rtw_mesh_sae_check_frames(_adapter *adapter, const u8 *buf, u32 len, u8 tx, u16 alg, u16 seq, u16 status);
|
||||
int rtw_mesh_check_frames_tx(_adapter *adapter, const u8 **buf, size_t *len);
|
||||
int rtw_mesh_check_frames_rx(_adapter *adapter, const u8 *buf, size_t len);
|
||||
|
||||
int rtw_mesh_on_auth(_adapter *adapter, union recv_frame *rframe);
|
||||
unsigned int on_action_self_protected(_adapter *adapter, union recv_frame *rframe);
|
||||
|
||||
bool rtw_mesh_update_bss_peering_status(_adapter *adapter, WLAN_BSSID_EX *bss);
|
||||
bool rtw_mesh_update_bss_formation_info(_adapter *adapter, WLAN_BSSID_EX *bss);
|
||||
bool rtw_mesh_update_bss_forwarding_state(_adapter *adapter, WLAN_BSSID_EX *bss);
|
||||
|
||||
struct mesh_plink_ent *_rtw_mesh_plink_get(_adapter *adapter, const u8 *hwaddr);
|
||||
struct mesh_plink_ent *rtw_mesh_plink_get(_adapter *adapter, const u8 *hwaddr);
|
||||
struct mesh_plink_ent *rtw_mesh_plink_get_no_estab_by_idx(_adapter *adapter, u8 idx);
|
||||
int _rtw_mesh_plink_add(_adapter *adapter, const u8 *hwaddr);
|
||||
int rtw_mesh_plink_add(_adapter *adapter, const u8 *hwaddr);
|
||||
int rtw_mesh_plink_set_state(_adapter *adapter, const u8 *hwaddr, u8 state);
|
||||
#ifdef CONFIG_RTW_MESH_AEK
|
||||
int rtw_mesh_plink_set_aek(_adapter *adapter, const u8 *hwaddr, const u8 *aek);
|
||||
#endif
|
||||
#if CONFIG_RTW_MESH_PEER_BLACKLIST
|
||||
int rtw_mesh_plink_set_peer_conf_timeout(_adapter *adapter, const u8 *hwaddr);
|
||||
#endif
|
||||
void _rtw_mesh_plink_del_ent(_adapter *adapter, struct mesh_plink_ent *ent);
|
||||
int rtw_mesh_plink_del(_adapter *adapter, const u8 *hwaddr);
|
||||
void rtw_mesh_plink_ctl_init(_adapter *adapter);
|
||||
void rtw_mesh_plink_ctl_deinit(_adapter *adapter);
|
||||
void dump_mesh_plink_ctl(void *sel, _adapter *adapter);
|
||||
|
||||
u8 rtw_mesh_set_plink_state_cmd(_adapter *adapter, const u8 *mac, u8 plink_state);
|
||||
|
||||
void _rtw_mesh_expire_peer_ent(_adapter *adapter, struct mesh_plink_ent *plink);
|
||||
void rtw_mesh_expire_peer(_adapter *adapter, const u8 *peer_addr);
|
||||
u8 rtw_mesh_ps_annc(_adapter *adapter, u8 ps);
|
||||
|
||||
unsigned int on_action_mesh(_adapter *adapter, union recv_frame *rframe);
|
||||
|
||||
void rtw_mesh_cfg_init(_adapter *adapter);
|
||||
void rtw_mesh_cfg_init_max_peer_links(_adapter *adapter, u8 stack_conf);
|
||||
void rtw_mesh_cfg_init_plink_timeout(_adapter *adapter, u32 stack_conf);
|
||||
void rtw_mesh_init_mesh_info(_adapter *adapter);
|
||||
void rtw_mesh_deinit_mesh_info(_adapter *adapter);
|
||||
|
||||
#if CONFIG_RTW_MESH_DATA_BMC_TO_UC
|
||||
void dump_mesh_b2u_flags(void *sel, _adapter *adapter);
|
||||
#endif
|
||||
|
||||
int rtw_mesh_addr_resolve(_adapter *adapter, u16 os_qid, struct xmit_frame *xframe, _pkt *pkt, _list *b2u_list);
|
||||
|
||||
s8 rtw_mesh_tx_set_whdr_mctrl_len(u8 mesh_frame_mode, struct pkt_attrib *attrib);
|
||||
void rtw_mesh_tx_build_mctrl(_adapter *adapter, struct pkt_attrib *attrib, u8 *buf);
|
||||
u8 rtw_mesh_tx_build_whdr(_adapter *adapter, struct pkt_attrib *attrib
|
||||
, u16 *fctrl, struct rtw_ieee80211_hdr *whdr);
|
||||
|
||||
int rtw_mesh_rx_data_validate_hdr(_adapter *adapter, union recv_frame *rframe, struct sta_info **sta);
|
||||
int rtw_mesh_rx_data_validate_mctrl(_adapter *adapter, union recv_frame *rframe
|
||||
, const struct rtw_ieee80211s_hdr *mctrl, const u8 *mda, const u8 *msa
|
||||
, u8 *mctrl_len, const u8 **da, const u8 **sa);
|
||||
int rtw_mesh_rx_validate_mctrl_non_amsdu(_adapter *adapter, union recv_frame *rframe);
|
||||
|
||||
int rtw_mesh_rx_msdu_act_check(union recv_frame *rframe
|
||||
, const u8 *mda, const u8 *msa
|
||||
, const u8 *da, const u8 *sa
|
||||
, struct rtw_ieee80211s_hdr *mctrl
|
||||
, u8 *msdu, enum rtw_rx_llc_hdl llc_hdl
|
||||
, struct xmit_frame **fwd_frame, _list *b2u_list);
|
||||
|
||||
void dump_mesh_stats(void *sel, _adapter *adapter);
|
||||
|
||||
#if defined(PLATFORM_LINUX) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32))
|
||||
#define rtw_lockdep_assert_held(l) lockdep_assert_held(l)
|
||||
#define rtw_lockdep_is_held(l) lockdep_is_held(l)
|
||||
#else
|
||||
#error "TBD\n"
|
||||
#endif
|
||||
|
||||
#include "rtw_mesh_pathtbl.h"
|
||||
#include "rtw_mesh_hwmp.h"
|
||||
#endif /* __RTW_MESH_H_ */
|
||||
|
||||
1518
drivers/net/wireless/rtl8822cs/core/mesh/rtw_mesh_hwmp.c
Normal file
1518
drivers/net/wireless/rtl8822cs/core/mesh/rtw_mesh_hwmp.c
Normal file
File diff suppressed because it is too large
Load Diff
60
drivers/net/wireless/rtl8822cs/core/mesh/rtw_mesh_hwmp.h
Normal file
60
drivers/net/wireless/rtl8822cs/core/mesh/rtw_mesh_hwmp.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright(c) 2007 - 2017 Realtek Corporation.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of version 2 of the GNU General Public License as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*****************************************************************************/
|
||||
#ifndef __RTW_MESH_HWMP_H_
|
||||
#define __RTW_MESH_HWMP_H_
|
||||
|
||||
#ifndef DBG_RTW_HWMP
|
||||
#define DBG_RTW_HWMP 0
|
||||
#endif
|
||||
#if DBG_RTW_HWMP
|
||||
#define RTW_HWMP_DBG(fmt, arg...) RTW_PRINT(fmt, ##arg)
|
||||
#else
|
||||
#define RTW_HWMP_DBG(fmt, arg...) RTW_DBG(fmt, ##arg)
|
||||
#endif
|
||||
|
||||
#ifndef INFO_RTW_HWMP
|
||||
#define INFO_RTW_HWMP 0
|
||||
#endif
|
||||
#if INFO_RTW_HWMP
|
||||
#define RTW_HWMP_INFO(fmt, arg...) RTW_PRINT(fmt, ##arg)
|
||||
#else
|
||||
#define RTW_HWMP_INFO(fmt, arg...) RTW_INFO(fmt, ##arg)
|
||||
#endif
|
||||
|
||||
|
||||
void rtw_ewma_err_rate_init(struct rtw_ewma_err_rate *e);
|
||||
unsigned long rtw_ewma_err_rate_read(struct rtw_ewma_err_rate *e);
|
||||
void rtw_ewma_err_rate_add(struct rtw_ewma_err_rate *e, unsigned long val);
|
||||
int rtw_mesh_path_error_tx(_adapter *adapter,
|
||||
u8 ttl, const u8 *target, u32 target_sn,
|
||||
u16 target_rcode, const u8 *ra);
|
||||
void rtw_ieee80211s_update_metric(_adapter *adapter, u8 mac_id,
|
||||
u8 per, u8 rate,
|
||||
u8 bw, u8 total_pkt);
|
||||
void rtw_mesh_rx_path_sel_frame(_adapter *adapter, union recv_frame *rframe);
|
||||
void rtw_mesh_queue_preq(struct rtw_mesh_path *mpath, u8 flags);
|
||||
void rtw_mesh_path_start_discovery(_adapter *adapter);
|
||||
void rtw_mesh_path_timer(void *ctx);
|
||||
void rtw_mesh_path_tx_root_frame(_adapter *adapter);
|
||||
void rtw_mesh_work_hdl(_workitem *work);
|
||||
void rtw_ieee80211_mesh_path_timer(void *ctx);
|
||||
void rtw_ieee80211_mesh_path_root_timer(void *ctx);
|
||||
BOOLEAN rtw_ieee80211_mesh_root_setup(_adapter *adapter);
|
||||
void rtw_mesh_work(_workitem *work);
|
||||
void rtw_mesh_atlm_param_req_timer(void *ctx);
|
||||
|
||||
#endif /* __RTW_MESH_HWMP_H_ */
|
||||
|
||||
|
||||
1242
drivers/net/wireless/rtl8822cs/core/mesh/rtw_mesh_pathtbl.c
Normal file
1242
drivers/net/wireless/rtl8822cs/core/mesh/rtw_mesh_pathtbl.c
Normal file
File diff suppressed because it is too large
Load Diff
211
drivers/net/wireless/rtl8822cs/core/mesh/rtw_mesh_pathtbl.h
Normal file
211
drivers/net/wireless/rtl8822cs/core/mesh/rtw_mesh_pathtbl.h
Normal file
@@ -0,0 +1,211 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright(c) 2007 - 2017 Realtek Corporation.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of version 2 of the GNU General Public License as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*****************************************************************************/
|
||||
#ifndef __RTW_MESH_PATHTBL_H_
|
||||
#define __RTW_MESH_PATHTBL_H_
|
||||
|
||||
#ifndef DBG_RTW_MPATH
|
||||
#define DBG_RTW_MPATH 1
|
||||
#endif
|
||||
#if DBG_RTW_MPATH
|
||||
#define RTW_MPATH_DBG(fmt, arg...) RTW_PRINT(fmt, ##arg)
|
||||
#else
|
||||
#define RTW_MPATH_DBG(fmt, arg...) do {} while (0)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* enum rtw_mesh_path_flags - mesh path flags
|
||||
*
|
||||
* @RTW_MESH_PATH_ACTIVE: the mesh path can be used for forwarding
|
||||
* @RTW_MESH_PATH_RESOLVING: the discovery process is running for this mesh path
|
||||
* @RTW_MESH_PATH_SN_VALID: the mesh path contains a valid destination sequence
|
||||
* number
|
||||
* @RTW_MESH_PATH_FIXED: the mesh path has been manually set and should not be
|
||||
* modified
|
||||
* @RTW_MESH_PATH_RESOLVED: the mesh path can has been resolved
|
||||
* @RTW_MESH_PATH_REQ_QUEUED: there is an unsent path request for this destination
|
||||
* already queued up, waiting for the discovery process to start.
|
||||
* @RTW_MESH_PATH_DELETED: the mesh path has been deleted and should no longer
|
||||
* be used
|
||||
* @RTW_MESH_PATH_ROOT_ADD_CHK: root additional check in root mode.
|
||||
* With this flag, It will try the last used rann_snd_addr
|
||||
* @RTW_MESH_PATH_PEER_AKA: only used toward a peer, only used in active keep
|
||||
* alive mechanism. PREQ's da = path dst
|
||||
* @RTW_MESH_PATH_BCAST_PREQ: for re-checking next hop resolve toward root.
|
||||
* Use it to force path_discover sending broadcast PREQ for root.
|
||||
*
|
||||
* RTW_MESH_PATH_RESOLVED is used by the mesh path timer to
|
||||
* decide when to stop or cancel the mesh path discovery.
|
||||
*/
|
||||
enum rtw_mesh_path_flags {
|
||||
RTW_MESH_PATH_ACTIVE = BIT(0),
|
||||
RTW_MESH_PATH_RESOLVING = BIT(1),
|
||||
RTW_MESH_PATH_SN_VALID = BIT(2),
|
||||
RTW_MESH_PATH_FIXED = BIT(3),
|
||||
RTW_MESH_PATH_RESOLVED = BIT(4),
|
||||
RTW_MESH_PATH_REQ_QUEUED = BIT(5),
|
||||
RTW_MESH_PATH_DELETED = BIT(6),
|
||||
RTW_MESH_PATH_ROOT_ADD_CHK = BIT(7),
|
||||
RTW_MESH_PATH_PEER_AKA = BIT(8),
|
||||
RTW_MESH_PATH_BCAST_PREQ = BIT(9),
|
||||
};
|
||||
|
||||
/**
|
||||
* struct rtw_mesh_path - mesh path structure
|
||||
*
|
||||
* @dst: mesh path destination mac address
|
||||
* @mpp: mesh proxy mac address
|
||||
* @rhash: rhashtable list pointer
|
||||
* @gate_list: list pointer for known gates list
|
||||
* @sdata: mesh subif
|
||||
* @next_hop: mesh neighbor to which frames for this destination will be
|
||||
* forwarded
|
||||
* @timer: mesh path discovery timer
|
||||
* @frame_queue: pending queue for frames sent to this destination while the
|
||||
* path is unresolved
|
||||
* @rcu: rcu head for freeing mesh path
|
||||
* @sn: target sequence number
|
||||
* @metric: current metric to this destination
|
||||
* @hop_count: hops to destination
|
||||
* @exp_time: in jiffies, when the path will expire or when it expired
|
||||
* @discovery_timeout: timeout (lapse in jiffies) used for the last discovery
|
||||
* retry
|
||||
* @discovery_retries: number of discovery retries
|
||||
* @flags: mesh path flags, as specified on &enum rtw_mesh_path_flags
|
||||
* @state_lock: mesh path state lock used to protect changes to the
|
||||
* mpath itself. No need to take this lock when adding or removing
|
||||
* an mpath to a hash bucket on a path table.
|
||||
* @rann_snd_addr: the RANN sender address
|
||||
* @rann_metric: the aggregated path metric towards the root node
|
||||
* @last_preq_to_root: Timestamp of last PREQ sent to root
|
||||
* @is_root: the destination station of this path is a root node
|
||||
* @is_gate: the destination station of this path is a mesh gate
|
||||
*
|
||||
*
|
||||
* The dst address is unique in the mesh path table. Since the mesh_path is
|
||||
* protected by RCU, deleting the next_hop STA must remove / substitute the
|
||||
* mesh_path structure and wait until that is no longer reachable before
|
||||
* destroying the STA completely.
|
||||
*/
|
||||
struct rtw_mesh_path {
|
||||
u8 dst[ETH_ALEN];
|
||||
u8 mpp[ETH_ALEN]; /* used for MPP or MAP */
|
||||
rtw_rhash_head rhash;
|
||||
rtw_hlist_node gate_list;
|
||||
_adapter *adapter;
|
||||
struct sta_info __rcu *next_hop;
|
||||
_timer timer;
|
||||
_queue frame_queue;
|
||||
u32 frame_queue_len;
|
||||
rtw_rcu_head rcu;
|
||||
u32 sn;
|
||||
u32 metric;
|
||||
u8 hop_count;
|
||||
systime exp_time;
|
||||
systime discovery_timeout;
|
||||
systime gate_timeout;
|
||||
u32 gate_ann_int; /* gate announce interval */
|
||||
u8 discovery_retries;
|
||||
enum rtw_mesh_path_flags flags;
|
||||
_lock state_lock;
|
||||
u8 rann_snd_addr[ETH_ALEN];
|
||||
#ifdef CONFIG_RTW_MESH_ADD_ROOT_CHK
|
||||
u8 add_chk_rann_snd_addr[ETH_ALEN];
|
||||
#endif
|
||||
u32 rann_metric;
|
||||
unsigned long last_preq_to_root;
|
||||
bool is_root;
|
||||
bool is_gate;
|
||||
bool gate_asked;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct rtw_mesh_table
|
||||
*
|
||||
* @known_gates: list of known mesh gates and their mpaths by the station. The
|
||||
* gate's mpath may or may not be resolved and active.
|
||||
* @gates_lock: protects updates to known_gates
|
||||
* @rhead: the rhashtable containing struct mesh_paths, keyed by dest addr
|
||||
* @entries: number of entries in the table
|
||||
*/
|
||||
struct rtw_mesh_table {
|
||||
rtw_hlist_head known_gates;
|
||||
_lock gates_lock;
|
||||
rtw_rhashtable rhead;
|
||||
ATOMIC_T entries;
|
||||
};
|
||||
|
||||
#define RTW_MESH_PATH_EXPIRE (600 * HZ)
|
||||
|
||||
/* Maximum number of paths per interface */
|
||||
#define RTW_MESH_MAX_MPATHS 1024
|
||||
|
||||
/* Number of frames buffered per destination for unresolved destinations */
|
||||
#define RTW_MESH_FRAME_QUEUE_LEN 10
|
||||
|
||||
int rtw_mesh_nexthop_lookup(_adapter *adapter,
|
||||
const u8 *mda, const u8 *msa, u8 *ra);
|
||||
int rtw_mesh_nexthop_resolve(_adapter *adapter,
|
||||
struct xmit_frame *xframe);
|
||||
|
||||
struct rtw_mesh_path *rtw_mesh_path_lookup(_adapter *adapter,
|
||||
const u8 *dst);
|
||||
struct rtw_mesh_path *rtw_mpp_path_lookup(_adapter *adapter,
|
||||
const u8 *dst);
|
||||
int rtw_mpp_path_add(_adapter *adapter,
|
||||
const u8 *dst, const u8 *mpp);
|
||||
void dump_mpp(void *sel, _adapter *adapter);
|
||||
|
||||
struct rtw_mesh_path *
|
||||
rtw_mesh_path_lookup_by_idx(_adapter *adapter, int idx);
|
||||
void dump_mpath(void *sel, _adapter *adapter);
|
||||
|
||||
struct rtw_mesh_path *
|
||||
rtw_mpp_path_lookup_by_idx(_adapter *adapter, int idx);
|
||||
void rtw_mesh_path_fix_nexthop(struct rtw_mesh_path *mpath, struct sta_info *next_hop);
|
||||
void rtw_mesh_path_expire(_adapter *adapter);
|
||||
|
||||
struct rtw_mesh_path *
|
||||
rtw_mesh_path_add(_adapter *adapter, const u8 *dst);
|
||||
|
||||
int rtw_mesh_path_add_gate(struct rtw_mesh_path *mpath);
|
||||
void rtw_mesh_gate_del(struct rtw_mesh_table *tbl, struct rtw_mesh_path *mpath);
|
||||
bool rtw_mesh_gate_search(struct rtw_mesh_table *tbl, const u8 *addr);
|
||||
int rtw_mesh_path_send_to_gates(struct rtw_mesh_path *mpath);
|
||||
int rtw_mesh_gate_num(_adapter *adapter);
|
||||
bool rtw_mesh_is_primary_gate(_adapter *adapter);
|
||||
void dump_known_gates(void *sel, _adapter *adapter);
|
||||
|
||||
void rtw_mesh_plink_broken(struct sta_info *sta);
|
||||
|
||||
void rtw_mesh_path_assign_nexthop(struct rtw_mesh_path *mpath, struct sta_info *sta);
|
||||
void rtw_mesh_path_flush_pending(struct rtw_mesh_path *mpath);
|
||||
void rtw_mesh_path_tx_pending(struct rtw_mesh_path *mpath);
|
||||
int rtw_mesh_pathtbl_init(_adapter *adapter);
|
||||
void rtw_mesh_pathtbl_unregister(_adapter *adapter);
|
||||
int rtw_mesh_path_del(_adapter *adapter, const u8 *addr);
|
||||
|
||||
void rtw_mesh_path_flush_by_nexthop(struct sta_info *sta);
|
||||
void rtw_mesh_path_discard_frame(_adapter *adapter,
|
||||
struct xmit_frame *xframe);
|
||||
|
||||
static inline void rtw_mesh_path_activate(struct rtw_mesh_path *mpath)
|
||||
{
|
||||
mpath->flags |= RTW_MESH_PATH_ACTIVE | RTW_MESH_PATH_RESOLVED;
|
||||
}
|
||||
|
||||
void rtw_mesh_path_flush_by_iface(_adapter *adapter);
|
||||
|
||||
#endif /* __RTW_MESH_PATHTBL_H_ */
|
||||
|
||||
625
drivers/net/wireless/rtl8822cs/core/monitor/rtw_radiotap.c
Normal file
625
drivers/net/wireless/rtl8822cs/core/monitor/rtw_radiotap.c
Normal file
@@ -0,0 +1,625 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright(c) 2007 - 2017 Realtek Corporation.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of version 2 of the GNU General Public License as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*****************************************************************************/
|
||||
#define _RTW_RADIOTAP_C_
|
||||
|
||||
#ifdef CONFIG_WIFI_MONITOR
|
||||
|
||||
#include <drv_types.h>
|
||||
#include <hal_data.h>
|
||||
|
||||
#define CHAN2FREQ(a) ((a < 14) ? (2407+5*a) : (5000+5*a))
|
||||
|
||||
#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 20, 0))
|
||||
#define IEEE80211_RADIOTAP_ZERO_LEN_PSDU 26
|
||||
#define IEEE80211_RADIOTAP_LSIG 27
|
||||
#endif
|
||||
|
||||
#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0))
|
||||
#define IEEE80211_RADIOTAP_TIMESTAMP 22
|
||||
/* For IEEE80211_RADIOTAP_TIMESTAMP */
|
||||
#define IEEE80211_RADIOTAP_TIMESTAMP_UNIT_MASK 0x000F
|
||||
#define IEEE80211_RADIOTAP_TIMESTAMP_UNIT_MS 0x0000
|
||||
#define IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US 0x0001
|
||||
#define IEEE80211_RADIOTAP_TIMESTAMP_UNIT_NS 0x0003
|
||||
#define IEEE80211_RADIOTAP_TIMESTAMP_SPOS_MASK 0x00F0
|
||||
#define IEEE80211_RADIOTAP_TIMESTAMP_SPOS_BEGIN_MDPU 0x0000
|
||||
#define IEEE80211_RADIOTAP_TIMESTAMP_SPOS_EO_MPDU 0x0010
|
||||
#define IEEE80211_RADIOTAP_TIMESTAMP_SPOS_EO_PPDU 0x0020
|
||||
#define IEEE80211_RADIOTAP_TIMESTAMP_SPOS_PLCP_SIG_ACQ 0x0030
|
||||
#define IEEE80211_RADIOTAP_TIMESTAMP_SPOS_UNKNOWN 0x00F0
|
||||
|
||||
#define IEEE80211_RADIOTAP_TIMESTAMP_FLAG_64BIT 0x00
|
||||
#define IEEE80211_RADIOTAP_TIMESTAMP_FLAG_32BIT 0x01
|
||||
#define IEEE80211_RADIOTAP_TIMESTAMP_FLAG_ACCURACY 0x02
|
||||
#endif
|
||||
|
||||
#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 12, 0))
|
||||
/* for IEEE80211_RADIOTAP_CHANNEL */
|
||||
#define IEEE80211_CHAN_GSM 0x1000 /* GSM (900 MHz) */
|
||||
#define IEEE80211_CHAN_STURBO 0x2000 /* Static Turbo */
|
||||
#define IEEE80211_CHAN_HALF 0x4000 /* Half channel (10 MHz wide) */
|
||||
#define IEEE80211_CHAN_QUARTER 0x8000 /* Quarter channel (5 MHz wide) */
|
||||
#endif
|
||||
|
||||
#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 8, 0))
|
||||
#define IEEE80211_RADIOTAP_VHT 21
|
||||
/* For IEEE80211_RADIOTAP_VHT */
|
||||
#define IEEE80211_RADIOTAP_VHT_KNOWN_STBC 0x0001
|
||||
#define IEEE80211_RADIOTAP_VHT_KNOWN_TXOP_PS_NA 0x0002
|
||||
#define IEEE80211_RADIOTAP_VHT_KNOWN_GI 0x0004
|
||||
#define IEEE80211_RADIOTAP_VHT_KNOWN_SGI_NSYM_DIS 0x0008
|
||||
#define IEEE80211_RADIOTAP_VHT_KNOWN_LDPC_EXTRA_OFDM_SYM 0x0010
|
||||
#define IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED 0x0020
|
||||
#define IEEE80211_RADIOTAP_VHT_KNOWN_BANDWIDTH 0x0040
|
||||
#define IEEE80211_RADIOTAP_VHT_KNOWN_GROUP_ID 0x0080
|
||||
#define IEEE80211_RADIOTAP_VHT_KNOWN_PARTIAL_AID 0x0100
|
||||
|
||||
#define IEEE80211_RADIOTAP_VHT_FLAG_STBC 0x01
|
||||
#define IEEE80211_RADIOTAP_VHT_FLAG_TXOP_PS_NA 0x02
|
||||
#define IEEE80211_RADIOTAP_VHT_FLAG_SGI 0x04
|
||||
#define IEEE80211_RADIOTAP_VHT_FLAG_SGI_NSYM_M10_9 0x08
|
||||
#define IEEE80211_RADIOTAP_VHT_FLAG_LDPC_EXTRA_OFDM_SYM 0x10
|
||||
#define IEEE80211_RADIOTAP_VHT_FLAG_BEAMFORMED 0x20
|
||||
#elif (LINUX_VERSION_CODE < KERNEL_VERSION(3, 15, 0))
|
||||
#define IEEE80211_RADIOTAP_CODING_LDPC_USER0 0x01
|
||||
#define IEEE80211_RADIOTAP_CODING_LDPC_USER1 0x02
|
||||
#define IEEE80211_RADIOTAP_CODING_LDPC_USER2 0x04
|
||||
#define IEEE80211_RADIOTAP_CODING_LDPC_USER3 0x08
|
||||
#endif
|
||||
|
||||
#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
|
||||
#define IEEE80211_RADIOTAP_AMPDU_STATUS 20
|
||||
/* For IEEE80211_RADIOTAP_AMPDU_STATUS */
|
||||
#define IEEE80211_RADIOTAP_AMPDU_REPORT_ZEROLEN 0x0001
|
||||
#define IEEE80211_RADIOTAP_AMPDU_IS_ZEROLEN 0x0002
|
||||
#define IEEE80211_RADIOTAP_AMPDU_LAST_KNOWN 0x0004
|
||||
#define IEEE80211_RADIOTAP_AMPDU_IS_LAST 0x0008
|
||||
#define IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_ERR 0x0010
|
||||
#define IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_KNOWN 0x0020
|
||||
#elif (LINUX_VERSION_CODE < KERNEL_VERSION(4, 17, 0))
|
||||
#define IEEE80211_RADIOTAP_AMPDU_EOF 0x0040
|
||||
#define IEEE80211_RADIOTAP_AMPDU_EOF_KNOWN 0x0080
|
||||
#endif
|
||||
|
||||
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 22))
|
||||
/* For IEEE80211_RADIOTAP_TX_FLAGS */
|
||||
#define IEEE80211_RADIOTAP_F_TX_FAIL 0x0001 /* failed due to excessive
|
||||
* retries */
|
||||
#define IEEE80211_RADIOTAP_F_TX_CTS 0x0002 /* used cts 'protection' */
|
||||
#define IEEE80211_RADIOTAP_F_TX_RTS 0x0004 /* used rts/cts handshake */
|
||||
#elif (LINUX_VERSION_CODE < KERNEL_VERSION(3, 2, 0))
|
||||
#define IEEE80211_RADIOTAP_F_TX_NOACK 0x0008 /* don't expect an ack */
|
||||
#endif
|
||||
|
||||
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 39))
|
||||
#define IEEE80211_RADIOTAP_MCS 19
|
||||
/* For IEEE80211_RADIOTAP_MCS */
|
||||
#define IEEE80211_RADIOTAP_MCS_HAVE_BW 0x01
|
||||
#define IEEE80211_RADIOTAP_MCS_HAVE_MCS 0x02
|
||||
#define IEEE80211_RADIOTAP_MCS_HAVE_GI 0x04
|
||||
#define IEEE80211_RADIOTAP_MCS_HAVE_FMT 0x08
|
||||
#define IEEE80211_RADIOTAP_MCS_HAVE_FEC 0x10
|
||||
|
||||
#define IEEE80211_RADIOTAP_MCS_BW_MASK 0x03
|
||||
#define IEEE80211_RADIOTAP_MCS_BW_20 0
|
||||
#define IEEE80211_RADIOTAP_MCS_BW_40 1
|
||||
#define IEEE80211_RADIOTAP_MCS_BW_20L 2
|
||||
#define IEEE80211_RADIOTAP_MCS_BW_20U 3
|
||||
#define IEEE80211_RADIOTAP_MCS_SGI 0x04
|
||||
#define IEEE80211_RADIOTAP_MCS_FMT_GF 0x08
|
||||
#define IEEE80211_RADIOTAP_MCS_FEC_LDPC 0x10
|
||||
#elif (LINUX_VERSION_CODE < KERNEL_VERSION(3, 11, 0))
|
||||
#define IEEE80211_RADIOTAP_MCS_HAVE_STBC 0x20
|
||||
|
||||
#define IEEE80211_RADIOTAP_MCS_STBC_MASK 0x60
|
||||
#define IEEE80211_RADIOTAP_MCS_STBC_1 1
|
||||
#define IEEE80211_RADIOTAP_MCS_STBC_2 2
|
||||
#define IEEE80211_RADIOTAP_MCS_STBC_3 3
|
||||
#define IEEE80211_RADIOTAP_MCS_STBC_SHIFT 5
|
||||
#endif
|
||||
|
||||
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34))
|
||||
#define IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE 29
|
||||
#define IEEE80211_RADIOTAP_VENDOR_NAMESPACE 30
|
||||
#endif
|
||||
|
||||
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 30))
|
||||
#define IEEE80211_RADIOTAP_F_BADFCS 0x40
|
||||
#endif
|
||||
|
||||
static inline void _rtw_radiotap_fill_flags(struct rx_pkt_attrib *a, u8 *flags)
|
||||
{
|
||||
struct moinfo *moif = (struct moinfo *)&a->moif;
|
||||
|
||||
if (0)
|
||||
*flags |= IEEE80211_RADIOTAP_F_CFP;
|
||||
|
||||
if (0)
|
||||
*flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
|
||||
|
||||
if ((a->encrypt == 1) || (a->encrypt == 5))
|
||||
*flags |= IEEE80211_RADIOTAP_F_WEP;
|
||||
|
||||
if (a->mfrag)
|
||||
*flags |= IEEE80211_RADIOTAP_F_FRAG;
|
||||
|
||||
if (1)
|
||||
*flags |= IEEE80211_RADIOTAP_F_FCS;
|
||||
|
||||
if (0)
|
||||
*flags |= IEEE80211_RADIOTAP_F_DATAPAD;
|
||||
|
||||
if (a->crc_err)
|
||||
*flags |= IEEE80211_RADIOTAP_F_BADFCS;
|
||||
|
||||
/* Currently unspecified but used
|
||||
for short guard interval (HT) */
|
||||
if (moif->u.snif_info.sgi || a->sgi)
|
||||
*flags |= 0x80;
|
||||
|
||||
}
|
||||
|
||||
sint rtw_fill_radiotap_hdr(_adapter *padapter, struct rx_pkt_attrib *a, u8 *buf)
|
||||
{
|
||||
#define RTAP_HDR_MAX 64
|
||||
|
||||
sint ret = _SUCCESS;
|
||||
struct moinfo *moif = (struct moinfo *)&a->moif;
|
||||
|
||||
u8 rx_cnt = 0;
|
||||
|
||||
HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
|
||||
|
||||
int i = 0;
|
||||
u8 tmp_8bit = 0;
|
||||
u16 tmp_16bit = 0;
|
||||
u32 tmp_32bit = 0;
|
||||
u64 tmp_64bit = 0;
|
||||
|
||||
_pkt *pskb = NULL;
|
||||
|
||||
struct ieee80211_radiotap_header *rtap_hdr = NULL;
|
||||
u8 *ptr = NULL;
|
||||
|
||||
/*
|
||||
radiotap length (include header 8)
|
||||
11G length: 36 (0x0040002f)
|
||||
11N length:
|
||||
11AC length: 60 (0x0070002b)
|
||||
*/
|
||||
u8 hdr_buf[RTAP_HDR_MAX] = { 0 };
|
||||
u16 rt_len = 8;
|
||||
|
||||
/* create header */
|
||||
rtap_hdr = (struct ieee80211_radiotap_header *)&hdr_buf[0];
|
||||
rtap_hdr->it_version = PKTHDR_RADIOTAP_VERSION;
|
||||
|
||||
/* each antenna information */
|
||||
rx_cnt = rf_type_to_rf_rx_cnt(pHalData->rf_type);
|
||||
#if 0
|
||||
if (rx_cnt > 1) {
|
||||
rtap_hdr->it_present |= BIT(IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE) |
|
||||
BIT(IEEE80211_RADIOTAP_EXT);
|
||||
|
||||
for (i = 1; i < rx_cnt; i++) {
|
||||
tmp_32bit = (BIT(IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
|
||||
BIT(IEEE80211_RADIOTAP_LOCK_QUALITY) |
|
||||
BIT(IEEE80211_RADIOTAP_ANTENNA) |
|
||||
BIT(IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE) |
|
||||
BIT(IEEE80211_RADIOTAP_EXT));
|
||||
_rtw_memcpy(&hdr_buf[rt_len], &tmp_32bit, 4);
|
||||
rt_len += 4;
|
||||
}
|
||||
|
||||
tmp_32bit = (BIT(IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
|
||||
BIT(IEEE80211_RADIOTAP_LOCK_QUALITY) |
|
||||
BIT(IEEE80211_RADIOTAP_ANTENNA));
|
||||
_rtw_memcpy(&hdr_buf[rt_len], &tmp_32bit, 4);
|
||||
rt_len += 4;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* tsft, Required Alignment: 8 bytes */
|
||||
if (0) { //(a->free_cnt) {
|
||||
/* TSFT + free_cnt */
|
||||
rtap_hdr->it_present |= BIT(IEEE80211_RADIOTAP_TSFT);
|
||||
if (!IS_ALIGNED(rt_len, 8))
|
||||
rt_len = ((rt_len + 7) & 0xFFF8); /* Alignment */
|
||||
|
||||
tmp_64bit = cpu_to_le64(a->free_cnt);
|
||||
_rtw_memcpy(&hdr_buf[rt_len], &tmp_64bit, 8);
|
||||
rt_len += 8;
|
||||
}
|
||||
|
||||
/* flags */
|
||||
rtap_hdr->it_present |= BIT(IEEE80211_RADIOTAP_FLAGS);
|
||||
_rtw_radiotap_fill_flags(a, &hdr_buf[rt_len]);
|
||||
rt_len += 1;
|
||||
|
||||
/* rate */
|
||||
if (a->data_rate <= DESC_RATE54M) {
|
||||
rtap_hdr->it_present |= BIT(IEEE80211_RADIOTAP_RATE);
|
||||
hdr_buf[rt_len] = hw_rate_to_m_rate(a->data_rate);
|
||||
rt_len += 1;
|
||||
}
|
||||
|
||||
/* channel & flags, Required Alignment: 2 bytes */
|
||||
if (1) {
|
||||
rtap_hdr->it_present |= BIT(IEEE80211_RADIOTAP_CHANNEL);
|
||||
rt_len += (rt_len % 2); /* Alignment */
|
||||
|
||||
tmp_16bit = CHAN2FREQ(rtw_get_oper_ch(padapter));
|
||||
_rtw_memcpy(&hdr_buf[rt_len], &tmp_16bit, 2);
|
||||
rt_len += 2;
|
||||
|
||||
/* channel flags */
|
||||
tmp_16bit = 0;
|
||||
if (pHalData->current_band_type == 0)
|
||||
tmp_16bit |= cpu_to_le16(IEEE80211_CHAN_2GHZ);
|
||||
else
|
||||
tmp_16bit |= cpu_to_le16(IEEE80211_CHAN_5GHZ);
|
||||
|
||||
if (a->data_rate <= DESC_RATE11M) {
|
||||
/* CCK */
|
||||
tmp_16bit |= cpu_to_le16(IEEE80211_CHAN_CCK);
|
||||
} else {
|
||||
/* OFDM */
|
||||
tmp_16bit |= cpu_to_le16(IEEE80211_CHAN_OFDM);
|
||||
}
|
||||
|
||||
if (rtw_get_oper_bw(padapter) == CHANNEL_WIDTH_10) {
|
||||
/* 10Mhz Channel Width */
|
||||
tmp_16bit |= cpu_to_le16(IEEE80211_CHAN_HALF);
|
||||
}
|
||||
|
||||
if (rtw_get_oper_bw(padapter) == CHANNEL_WIDTH_5) {
|
||||
/* 5Mhz Channel Width */
|
||||
tmp_16bit |= cpu_to_le16(IEEE80211_CHAN_QUARTER);
|
||||
}
|
||||
_rtw_memcpy(&hdr_buf[rt_len], &tmp_16bit, 2);
|
||||
rt_len += 2;
|
||||
}
|
||||
|
||||
/* dBm Antenna Signal */
|
||||
rtap_hdr->it_present |= BIT(IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
|
||||
hdr_buf[rt_len] = a->phy_info.recv_signal_power;
|
||||
rt_len += 1;
|
||||
|
||||
#if 0
|
||||
/* dBm Antenna Noise */
|
||||
rtap_hdr->it_present |= BIT(IEEE80211_RADIOTAP_DBM_ANTNOISE);
|
||||
hdr_buf[rt_len] = 0;
|
||||
rt_len += 1;
|
||||
#endif
|
||||
#if 0
|
||||
/* Signal Quality, Required Alignment: 2 bytes */
|
||||
rtap_hdr->it_present |= BIT(IEEE80211_RADIOTAP_LOCK_QUALITY);
|
||||
if (!IS_ALIGNED(rt_len, 2))
|
||||
rt_len++;
|
||||
hdr_buf[rt_len] = a->phy_info.signal_quality;
|
||||
rt_len += 2;
|
||||
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
/* Antenna */
|
||||
rtap_hdr->it_present |= BIT(IEEE80211_RADIOTAP_ANTENNA);
|
||||
hdr_buf[rt_len] = 0; /* pHalData->rf_type; */
|
||||
rt_len += 1;
|
||||
#endif
|
||||
#if 0
|
||||
/* RX flags, Required Alignment: 2 bytes */
|
||||
rtap_hdr->it_present |= BIT(IEEE80211_RADIOTAP_RX_FLAGS);
|
||||
tmp_16bit = 0;
|
||||
_rtw_memcpy(&hdr_buf[rt_len], &tmp_16bit, 2);
|
||||
rt_len += 2;
|
||||
#endif
|
||||
|
||||
/* MCS information, Required Alignment: 1 bytes */
|
||||
if (a->data_rate >= DESC_RATEMCS0 && a->data_rate <= DESC_RATEMCS31) {
|
||||
rtap_hdr->it_present |= BIT(IEEE80211_RADIOTAP_MCS);
|
||||
/* Structure u8 known, u8 flags, u8 mcs */
|
||||
|
||||
/* known.bandwidth */
|
||||
hdr_buf[rt_len] |= IEEE80211_RADIOTAP_MCS_HAVE_BW;
|
||||
if (moif->u.snif_info.ofdm_bw)
|
||||
hdr_buf[rt_len + 1] |= IEEE80211_RADIOTAP_MCS_BW_40;
|
||||
if (a->bw == CHANNEL_WIDTH_40)
|
||||
hdr_buf[rt_len + 1] |= IEEE80211_RADIOTAP_MCS_BW_40;
|
||||
else
|
||||
hdr_buf[rt_len + 1] |= IEEE80211_RADIOTAP_MCS_BW_20;
|
||||
|
||||
|
||||
/* known.guard interval */
|
||||
hdr_buf[rt_len] |= IEEE80211_RADIOTAP_MCS_HAVE_GI;
|
||||
if (moif->u.snif_info.sgi) {
|
||||
hdr_buf[rt_len + 1] |= IEEE80211_RADIOTAP_MCS_SGI;
|
||||
} else {
|
||||
hdr_buf[rt_len + 1] |= ((a->sgi & 0x01) << 2);
|
||||
}
|
||||
|
||||
/* FEC Type */
|
||||
hdr_buf[rt_len] |= IEEE80211_RADIOTAP_MCS_HAVE_FEC;
|
||||
if (moif->u.snif_info.ldpc) {
|
||||
hdr_buf[rt_len + 1] |= ((moif->u.snif_info.ldpc & 0x01) << 4);
|
||||
} else {
|
||||
hdr_buf[rt_len + 1] |= ((a->ldpc & 0x01) << 4);
|
||||
}
|
||||
|
||||
/* STBC */
|
||||
hdr_buf[rt_len] |= IEEE80211_RADIOTAP_MCS_HAVE_STBC;
|
||||
if (moif->u.snif_info.stbc) {
|
||||
hdr_buf[rt_len + 1] |= ((moif->u.snif_info.stbc & 0x03) << 5);
|
||||
} else {
|
||||
hdr_buf[rt_len + 1] |= ((a->stbc & 0x03) << 5);
|
||||
}
|
||||
|
||||
/* known.MCS index */
|
||||
hdr_buf[rt_len] |= IEEE80211_RADIOTAP_MCS_HAVE_MCS;
|
||||
|
||||
/* u8 mcs */
|
||||
hdr_buf[rt_len + 2] = a->data_rate - DESC_RATEMCS0;
|
||||
|
||||
rt_len += 3;
|
||||
}
|
||||
|
||||
/* AMPDU, Required Alignment: 4 bytes */
|
||||
if (a->ampdu) {
|
||||
static u32 ref_num = 0x10000000;
|
||||
static u8 ppdu_cnt = 0;
|
||||
|
||||
/* Structure u32 reference number, u16 flags, u8 delimiter CRC value, u8 reserved */
|
||||
rtap_hdr->it_present |= BIT(IEEE80211_RADIOTAP_AMPDU_STATUS);
|
||||
if (!IS_ALIGNED(rt_len, 4))
|
||||
rt_len = ((rt_len + 3) & 0xFFFC); /* Alignment */
|
||||
|
||||
/* u32 reference number */
|
||||
if (a->ppdu_cnt != ppdu_cnt) {
|
||||
ppdu_cnt = a->ppdu_cnt;
|
||||
ref_num += 1;
|
||||
}
|
||||
tmp_32bit = cpu_to_le32(ref_num);
|
||||
_rtw_memcpy(&hdr_buf[rt_len], &tmp_32bit, 4);
|
||||
rt_len += 4;
|
||||
|
||||
/* u16 flags */
|
||||
tmp_16bit = 0;
|
||||
if (0) {
|
||||
tmp_16bit |= cpu_to_le16(IEEE80211_RADIOTAP_AMPDU_REPORT_ZEROLEN);
|
||||
tmp_16bit |= cpu_to_le16(IEEE80211_RADIOTAP_AMPDU_IS_ZEROLEN);
|
||||
}
|
||||
|
||||
if (0) {
|
||||
tmp_16bit |= cpu_to_le16(IEEE80211_RADIOTAP_AMPDU_IS_LAST);
|
||||
tmp_16bit |= cpu_to_le16(IEEE80211_RADIOTAP_AMPDU_LAST_KNOWN);
|
||||
}
|
||||
|
||||
if (0) {
|
||||
tmp_16bit |= cpu_to_le16(IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_ERR);
|
||||
tmp_16bit |= cpu_to_le16(IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_KNOWN);
|
||||
}
|
||||
|
||||
if (a->ampdu_eof) {
|
||||
tmp_16bit |= cpu_to_le16(IEEE80211_RADIOTAP_AMPDU_EOF_KNOWN);
|
||||
tmp_16bit |= cpu_to_le16(IEEE80211_RADIOTAP_AMPDU_EOF);
|
||||
}
|
||||
|
||||
_rtw_memcpy(&hdr_buf[rt_len], &tmp_16bit, 2);
|
||||
rt_len += 2;
|
||||
|
||||
/* u8 delimiter CRC value, u8 reserved */
|
||||
rt_len += 2;
|
||||
}
|
||||
|
||||
/* VHT, Required Alignment: 2 bytes */
|
||||
if (a->data_rate >= DESC_RATEVHTSS1MCS0 && a->data_rate <= DESC_RATEVHTSS4MCS9) {
|
||||
rtap_hdr->it_present |= BIT(IEEE80211_RADIOTAP_VHT);
|
||||
|
||||
rt_len += (rt_len % 2); /* Alignment */
|
||||
|
||||
/* Structure
|
||||
u16 known, u8 flags, u8 bandwidth, u8 mcs_nss[4],
|
||||
u8 coding, u8 group_id, u16 partial_aid */
|
||||
|
||||
tmp_16bit = 0;
|
||||
|
||||
/* STBC */
|
||||
tmp_16bit |= cpu_to_le16(IEEE80211_RADIOTAP_VHT_KNOWN_STBC);
|
||||
if (moif->u.snif_info.stbc) {
|
||||
hdr_buf[rt_len + 2] |= IEEE80211_RADIOTAP_VHT_FLAG_STBC;
|
||||
} else {
|
||||
hdr_buf[rt_len + 2] |= (a->stbc & 0x01);
|
||||
}
|
||||
|
||||
/* TXOP_PS_NOT_ALLOWED */
|
||||
tmp_16bit |= cpu_to_le16(IEEE80211_RADIOTAP_VHT_KNOWN_TXOP_PS_NA);
|
||||
if (moif->u.snif_info.vht_txop_not_allow) {
|
||||
hdr_buf[rt_len + 2] |= IEEE80211_RADIOTAP_VHT_FLAG_TXOP_PS_NA;
|
||||
}
|
||||
|
||||
|
||||
/* Guard interval */
|
||||
tmp_16bit |= cpu_to_le16(IEEE80211_RADIOTAP_VHT_KNOWN_GI);
|
||||
if (moif->u.snif_info.sgi) {
|
||||
hdr_buf[rt_len + 2] |= IEEE80211_RADIOTAP_VHT_FLAG_SGI;
|
||||
} else {
|
||||
hdr_buf[rt_len + 2] |= ((a->sgi & 0x01) << 2);
|
||||
}
|
||||
|
||||
/* Short GI NSYM */
|
||||
tmp_16bit |= cpu_to_le16(IEEE80211_RADIOTAP_VHT_KNOWN_SGI_NSYM_DIS);
|
||||
if (moif->u.snif_info.vht_nsym_dis) {
|
||||
hdr_buf[rt_len + 2] |= IEEE80211_RADIOTAP_VHT_FLAG_SGI_NSYM_M10_9;
|
||||
}
|
||||
|
||||
/* LDPC extra OFDM symbol */
|
||||
tmp_16bit |= cpu_to_le16(IEEE80211_RADIOTAP_VHT_KNOWN_LDPC_EXTRA_OFDM_SYM);
|
||||
if (moif->u.snif_info.vht_ldpc_extra) {
|
||||
hdr_buf[rt_len + 2] |= IEEE80211_RADIOTAP_VHT_FLAG_LDPC_EXTRA_OFDM_SYM;
|
||||
} else {
|
||||
hdr_buf[rt_len + 2] |= ((a->ldpc & 0x01) << 4);
|
||||
}
|
||||
|
||||
/* Short GI NSYM */
|
||||
tmp_16bit |= cpu_to_le16(IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED);
|
||||
if (moif->u.snif_info.vht_beamformed) {
|
||||
hdr_buf[rt_len + 2] |= IEEE80211_RADIOTAP_VHT_FLAG_BEAMFORMED;
|
||||
}
|
||||
|
||||
/* know.Bandwidth */
|
||||
tmp_16bit |= cpu_to_le16(IEEE80211_RADIOTAP_VHT_KNOWN_BANDWIDTH);
|
||||
|
||||
/* Group ID */
|
||||
tmp_16bit |= cpu_to_le16(IEEE80211_RADIOTAP_VHT_KNOWN_GROUP_ID);
|
||||
|
||||
/* Partial AID */
|
||||
tmp_16bit |= cpu_to_le16(IEEE80211_RADIOTAP_VHT_KNOWN_PARTIAL_AID);
|
||||
|
||||
_rtw_memcpy(&hdr_buf[rt_len], &tmp_16bit, 2);
|
||||
rt_len += 3;
|
||||
|
||||
/* u8 bandwidth */
|
||||
if (moif->u.snif_info.ofdm_bw)
|
||||
tmp_8bit = moif->u.snif_info.ofdm_bw;
|
||||
else
|
||||
tmp_8bit = a->bw;
|
||||
|
||||
switch (tmp_8bit) {
|
||||
case CHANNEL_WIDTH_20:
|
||||
hdr_buf[rt_len] |= 0;
|
||||
break;
|
||||
case CHANNEL_WIDTH_40:
|
||||
hdr_buf[rt_len] |= 1;
|
||||
break;
|
||||
case CHANNEL_WIDTH_80:
|
||||
hdr_buf[rt_len] |= 4;
|
||||
break;
|
||||
case CHANNEL_WIDTH_160:
|
||||
hdr_buf[rt_len] |= 11;
|
||||
break;
|
||||
default:
|
||||
hdr_buf[rt_len] |= 0;
|
||||
}
|
||||
rt_len += 1;
|
||||
|
||||
/* u8 mcs_nss[4] */
|
||||
if ((DESC_RATEVHTSS1MCS0 <= a->data_rate) &&
|
||||
(a->data_rate <= DESC_RATEVHTSS4MCS9)) {
|
||||
/* User 0 */
|
||||
/* MCS */
|
||||
hdr_buf[rt_len] = ((a->data_rate - DESC_RATEVHTSS1MCS0) % 10) << 4;
|
||||
/* NSS */
|
||||
hdr_buf[rt_len] |= (((a->data_rate - DESC_RATEVHTSS1MCS0) / 10) + 1);
|
||||
}
|
||||
rt_len += 4;
|
||||
|
||||
/* u8 coding, phystat? */
|
||||
hdr_buf[rt_len] = 0;
|
||||
rt_len += 1;
|
||||
|
||||
/* u8 group_id */
|
||||
hdr_buf[rt_len] = moif->u.snif_info.vht_group_id;
|
||||
rt_len += 1;
|
||||
|
||||
/* u16 partial_aid */
|
||||
tmp_16bit = cpu_to_le16(moif->u.snif_info.vht_nsts_aid);
|
||||
_rtw_memcpy(&hdr_buf[rt_len], &tmp_16bit, 2);
|
||||
rt_len += 2;
|
||||
}
|
||||
|
||||
/* frame timestamp, Required Alignment: 8 bytes */
|
||||
if (0) { //(a->free_cnt) {
|
||||
rtap_hdr->it_present |= BIT(IEEE80211_RADIOTAP_TIMESTAMP);
|
||||
if (!IS_ALIGNED(rt_len, 8))
|
||||
rt_len = ((rt_len + 7) & 0xFFF8); /* Alignment */
|
||||
|
||||
/* u64 timestamp */
|
||||
tmp_64bit = cpu_to_le64(a->free_cnt);
|
||||
_rtw_memcpy(&hdr_buf[rt_len], &tmp_64bit, 8);
|
||||
rt_len += 8;
|
||||
|
||||
/* u16 accuracy */
|
||||
tmp_16bit = cpu_to_le16(22);
|
||||
_rtw_memcpy(&hdr_buf[rt_len], &tmp_16bit, 2);
|
||||
rt_len += 2;
|
||||
|
||||
/* u8 unit/position */
|
||||
hdr_buf[rt_len] |= IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US;
|
||||
rt_len += 1;
|
||||
|
||||
/* u8 flags */
|
||||
hdr_buf[rt_len] |= IEEE80211_RADIOTAP_TIMESTAMP_FLAG_32BIT;
|
||||
hdr_buf[rt_len] |= IEEE80211_RADIOTAP_TIMESTAMP_FLAG_ACCURACY;
|
||||
rt_len += 1;
|
||||
}
|
||||
|
||||
/* each antenna information */
|
||||
#if 0
|
||||
if (rx_cnt > 1) {
|
||||
for (i = 0; i <= rx_cnt; i++) {
|
||||
/* dBm Antenna Signal */
|
||||
hdr_buf[rt_len] = a->phy_info.rx_mimo_signal_strength[i];
|
||||
rt_len += 1;
|
||||
|
||||
/* Signal Quality */
|
||||
if (!IS_ALIGNED(rt_len, 2))
|
||||
rt_len++;
|
||||
hdr_buf[rt_len] = cpu_to_le16(a->phy_info.rx_mimo_signal_quality[i]);
|
||||
rt_len += 2;
|
||||
|
||||
/* Antenna */
|
||||
hdr_buf[rt_len] = i; /* pHalData->rf_type; */
|
||||
rt_len += 1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* push to skb */
|
||||
pskb = (_pkt *)buf;
|
||||
if (skb_headroom(pskb) < rt_len) {
|
||||
RTW_INFO("%s:%d %s headroom is too small.\n", __FILE__, __LINE__, __func__);
|
||||
ret = _FAIL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
ptr = skb_push(pskb, rt_len);
|
||||
if (ptr) {
|
||||
rtap_hdr->it_len = cpu_to_le16(rt_len);
|
||||
rtap_hdr->it_present = cpu_to_le32(rtap_hdr->it_present);
|
||||
memcpy(ptr, rtap_hdr, rt_len);
|
||||
} else
|
||||
ret = _FAIL;
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
void rx_query_moinfo(struct rx_pkt_attrib *a, u8 *desc)
|
||||
{
|
||||
switch (a->drvinfo_sz) {
|
||||
case 40:
|
||||
_rtw_memcpy(a->moif, &desc[32], 8);
|
||||
break;
|
||||
case 48:
|
||||
_rtw_memcpy(a->moif, &desc[32], 12);
|
||||
break;
|
||||
case 32:
|
||||
/* passthrough */
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* CONFIG_WIFI_MONITOR */
|
||||
63
drivers/net/wireless/rtl8822cs/core/monitor/rtw_radiotap.h
Normal file
63
drivers/net/wireless/rtl8822cs/core/monitor/rtw_radiotap.h
Normal file
@@ -0,0 +1,63 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright(c) 2007 - 2017 Realtek Corporation.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of version 2 of the GNU General Public License as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*****************************************************************************/
|
||||
#ifndef __RTW_RADIOTAP_H_
|
||||
#define __RTW_RADIOTAP_H_
|
||||
|
||||
struct mon_reg_backup {
|
||||
/* flags */
|
||||
u8 known_rcr:1;
|
||||
u8 known_drvinfo:1;
|
||||
u8 known_rxfilter:1;
|
||||
u8 known_misc0:1;
|
||||
/* data */
|
||||
u8 drvinfo;
|
||||
u16 rxfilter0;
|
||||
u16 rxfilter1;
|
||||
u16 rxfilter2;
|
||||
u32 rcr;
|
||||
u32 misc0;
|
||||
};
|
||||
|
||||
struct moinfo {
|
||||
union {
|
||||
struct {
|
||||
u32 sgi:1;
|
||||
u32 ldpc:1;
|
||||
u32 stbc:2;
|
||||
u32 not_sounding:1;
|
||||
u32 ofdm_bw:2;
|
||||
u32 vht_group_id:2;
|
||||
u32 vht_nsts_aid:12;
|
||||
u32 vht_txop_not_allow:1;
|
||||
u32 vht_nsym_dis:1;
|
||||
u32 vht_ldpc_extra:1;
|
||||
u32 vht_su_mcs:12;
|
||||
u32 vht_beamformed:1;
|
||||
}snif_info;
|
||||
|
||||
struct {
|
||||
u32 A;
|
||||
u32 B;
|
||||
u32 C;
|
||||
}plcp_info;
|
||||
}u;
|
||||
};
|
||||
|
||||
sint rtw_fill_radiotap_hdr(_adapter *padapter, struct rx_pkt_attrib *a, u8 *buf);
|
||||
|
||||
void rx_query_moinfo(struct rx_pkt_attrib *a, u8 *desc);
|
||||
|
||||
#endif /* __RTW_RADIOTAP_H_ */
|
||||
|
||||
6324
drivers/net/wireless/rtl8822cs/core/rtw_ap.c
Normal file
6324
drivers/net/wireless/rtl8822cs/core/rtw_ap.c
Normal file
File diff suppressed because it is too large
Load Diff
2188
drivers/net/wireless/rtl8822cs/core/rtw_beamforming.c
Normal file
2188
drivers/net/wireless/rtl8822cs/core/rtw_beamforming.c
Normal file
File diff suppressed because it is too large
Load Diff
1590
drivers/net/wireless/rtl8822cs/core/rtw_br_ext.c
Normal file
1590
drivers/net/wireless/rtl8822cs/core/rtw_br_ext.c
Normal file
File diff suppressed because it is too large
Load Diff
1575
drivers/net/wireless/rtl8822cs/core/rtw_bt_mp.c
Normal file
1575
drivers/net/wireless/rtl8822cs/core/rtw_bt_mp.c
Normal file
File diff suppressed because it is too large
Load Diff
1823
drivers/net/wireless/rtl8822cs/core/rtw_btcoex.c
Normal file
1823
drivers/net/wireless/rtl8822cs/core/rtw_btcoex.c
Normal file
File diff suppressed because it is too large
Load Diff
47
drivers/net/wireless/rtl8822cs/core/rtw_btcoex_wifionly.c
Normal file
47
drivers/net/wireless/rtl8822cs/core/rtw_btcoex_wifionly.c
Normal file
@@ -0,0 +1,47 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright(c) 2013 - 2017 Realtek Corporation.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of version 2 of the GNU General Public License as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*****************************************************************************/
|
||||
#include <drv_types.h>
|
||||
#include <hal_btcoex_wifionly.h>
|
||||
#include <hal_data.h>
|
||||
|
||||
void rtw_btcoex_wifionly_switchband_notify(PADAPTER padapter)
|
||||
{
|
||||
hal_btcoex_wifionly_switchband_notify(padapter);
|
||||
}
|
||||
|
||||
void rtw_btcoex_wifionly_scan_notify(PADAPTER padapter)
|
||||
{
|
||||
hal_btcoex_wifionly_scan_notify(padapter);
|
||||
}
|
||||
|
||||
void rtw_btcoex_wifionly_connect_notify(PADAPTER padapter)
|
||||
{
|
||||
hal_btcoex_wifionly_connect_notify(padapter);
|
||||
}
|
||||
|
||||
void rtw_btcoex_wifionly_hw_config(PADAPTER padapter)
|
||||
{
|
||||
hal_btcoex_wifionly_hw_config(padapter);
|
||||
}
|
||||
|
||||
void rtw_btcoex_wifionly_initialize(PADAPTER padapter)
|
||||
{
|
||||
hal_btcoex_wifionly_initlizevariables(padapter);
|
||||
}
|
||||
|
||||
void rtw_btcoex_wifionly_AntInfoSetting(PADAPTER padapter)
|
||||
{
|
||||
hal_btcoex_wifionly_AntInfoSetting(padapter);
|
||||
}
|
||||
3854
drivers/net/wireless/rtl8822cs/core/rtw_chplan.c
Normal file
3854
drivers/net/wireless/rtl8822cs/core/rtw_chplan.c
Normal file
File diff suppressed because it is too large
Load Diff
525
drivers/net/wireless/rtl8822cs/core/rtw_chplan.h
Normal file
525
drivers/net/wireless/rtl8822cs/core/rtw_chplan.h
Normal file
@@ -0,0 +1,525 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright(c) 2007 - 2022 Realtek Corporation.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of version 2 of the GNU General Public License as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*****************************************************************************/
|
||||
#ifndef __RTW_CHPLAN_H__
|
||||
#define __RTW_CHPLAN_H__
|
||||
|
||||
#define RTW_CHPLAN_IOCTL_NULL 0xFFFE /* special value by ioctl: null(empty) chplan */
|
||||
#define RTW_CHPLAN_IOCTL_UNSPECIFIED 0xFFFF /* special value by ioctl: no change (keep original) */
|
||||
|
||||
#define RTW_CHPLAN_NULL 0x0A
|
||||
#define RTW_CHPLAN_WORLDWIDE 0x7F
|
||||
#define RTW_CHPLAN_UNSPECIFIED 0xFF
|
||||
#define RTW_CHPLAN_6G_NULL 0x00
|
||||
#define RTW_CHPLAN_6G_WORLDWIDE 0x7F
|
||||
#define RTW_CHPLAN_6G_UNSPECIFIED 0xFF
|
||||
|
||||
u8 rtw_chplan_get_default_regd_2g(u8 id);
|
||||
#if CONFIG_IEEE80211_BAND_5GHZ
|
||||
u8 rtw_chplan_get_default_regd_5g(u8 id);
|
||||
#endif
|
||||
bool rtw_is_channel_plan_valid(u8 id);
|
||||
|
||||
#if CONFIG_IEEE80211_BAND_6GHZ
|
||||
u8 rtw_chplan_get_default_regd_6g(u8 id);
|
||||
bool rtw_is_channel_plan_6g_valid(u8 id);
|
||||
#endif
|
||||
|
||||
void rtw_rfctl_addl_ch_disable_conf_init(struct rf_ctl_t *rfctl, struct registry_priv *regsty);
|
||||
|
||||
u8 rtw_chplan_is_bchbw_valid(u8 id, u8 id_6g, enum band_type band, u8 ch, u8 bw, u8 offset
|
||||
, bool allow_primary_passive, bool allow_passive, struct rf_ctl_t *rfctl);
|
||||
|
||||
enum regd_src_t {
|
||||
REGD_SRC_RTK_PRIV = 0, /* Regulatory settings from Realtek framework (Realtek defined or customized) */
|
||||
REGD_SRC_OS = 1, /* Regulatory settings from OS */
|
||||
REGD_SRC_NUM,
|
||||
};
|
||||
|
||||
#define regd_src_is_valid(src) ((src) < REGD_SRC_NUM)
|
||||
|
||||
extern const char *_regd_src_str[];
|
||||
#define regd_src_str(src) ((src) >= REGD_SRC_NUM ? _regd_src_str[REGD_SRC_NUM] : _regd_src_str[src])
|
||||
|
||||
void rtw_rfctl_chset_apply_regulatory(struct dvobj_priv *dvobj, bool req_lock);
|
||||
|
||||
bool rtw_rfctl_reg_allow_beacon_hint(struct rf_ctl_t *rfctl);
|
||||
bool rtw_chinfo_allow_beacon_hint(struct _RT_CHANNEL_INFO *chinfo);
|
||||
u8 rtw_process_beacon_hint(struct rf_ctl_t *rfctl, WLAN_BSSID_EX *bss);
|
||||
void rtw_beacon_hint_ch_change_notifier(struct rf_ctl_t *rfctl);
|
||||
|
||||
#define ALPHA2_FMT "%c%c"
|
||||
#define ALPHA2_ARG(a2) ((is_alpha(a2[0]) || is_decimal(a2[0])) ? a2[0] : '-'), ((is_alpha(a2[1]) || is_decimal(a2[1])) ? a2[1] : '-')
|
||||
|
||||
#define WORLDWIDE_ALPHA2 "00"
|
||||
#define UNSPEC_ALPHA2 "99"
|
||||
#define INTERSECTED_ALPHA2 "98"
|
||||
|
||||
#define IS_ALPHA2_WORLDWIDE(_alpha2) (strncmp(_alpha2, WORLDWIDE_ALPHA2, 2) == 0)
|
||||
#define IS_ALPHA2_UNSPEC(_alpha2) (strncmp(_alpha2, UNSPEC_ALPHA2, 2) == 0)
|
||||
#define IS_ALPHA2_INTERSECTED(_alpha2) (strncmp(_alpha2, INTERSECTED_ALPHA2, 2) == 0)
|
||||
#define SET_UNSPEC_ALPHA2(_alpha2) do { _rtw_memcpy(_alpha2, UNSPEC_ALPHA2, 2); } while (0)
|
||||
#define SET_INTERSECTEDC_ALPHA2(_alpha2) do { _rtw_memcpy(_alpha2, INTERSECTED_ALPHA2, 2); } while (0)
|
||||
|
||||
enum rtw_regd_inr {
|
||||
RTW_REGD_SET_BY_INIT = 0,
|
||||
RTW_REGD_SET_BY_USER = 1,
|
||||
RTW_REGD_SET_BY_COUNTRY_IE = 2,
|
||||
|
||||
/* below is not used for REGD_SRC_RTK_PRIV */
|
||||
RTW_REGD_SET_BY_DRIVER = 3,
|
||||
RTW_REGD_SET_BY_CORE = 4,
|
||||
|
||||
RTW_REGD_SET_BY_NUM,
|
||||
};
|
||||
|
||||
extern const char *const _regd_inr_str[];
|
||||
#define regd_inr_str(inr) (((inr) >= RTW_REGD_SET_BY_NUM) ? _regd_inr_str[RTW_REGD_SET_BY_NUM] : _regd_inr_str[(inr)])
|
||||
|
||||
enum rtw_regd {
|
||||
RTW_REGD_NA = 0,
|
||||
RTW_REGD_FCC = 1,
|
||||
RTW_REGD_MKK = 2,
|
||||
RTW_REGD_ETSI = 3,
|
||||
RTW_REGD_IC = 4,
|
||||
RTW_REGD_KCC = 5,
|
||||
RTW_REGD_NCC = 6,
|
||||
RTW_REGD_ACMA = 7,
|
||||
RTW_REGD_CHILE = 8,
|
||||
RTW_REGD_MEX = 9,
|
||||
RTW_REGD_WW,
|
||||
RTW_REGD_NUM,
|
||||
};
|
||||
|
||||
extern const char *const _regd_str[];
|
||||
#define regd_str(regd) (((regd) >= RTW_REGD_NUM) ? _regd_str[RTW_REGD_NA] : _regd_str[(regd)])
|
||||
|
||||
enum rtw_edcca_mode_t {
|
||||
RTW_EDCCA_NORM = 0, /* normal */
|
||||
RTW_EDCCA_CS = 1, /* carrier sense */
|
||||
RTW_EDCCA_ADAPT = 2, /* adaptivity */
|
||||
RTW_EDCCA_CBP = 3, /* contention based protocol */
|
||||
RTW_EDCCA_MODE_NUM,
|
||||
RTW_EDCCA_DEF = RTW_EDCCA_MODE_NUM, /* default (ref to domain code), used at country chplan map's override field */
|
||||
RTW_EDCCA_AUTO = 0xFF, /* follow channel plan */
|
||||
};
|
||||
|
||||
extern const char *const _rtw_edcca_mode_str[];
|
||||
#define rtw_edcca_mode_str(mode) (((mode) >= RTW_EDCCA_MODE_NUM) ? _rtw_edcca_mode_str[RTW_EDCCA_NORM] : _rtw_edcca_mode_str[(mode)])
|
||||
|
||||
enum rtw_dfs_regd {
|
||||
RTW_DFS_REGD_NONE = 0,
|
||||
RTW_DFS_REGD_FCC = 1,
|
||||
RTW_DFS_REGD_MKK = 2,
|
||||
RTW_DFS_REGD_ETSI = 3,
|
||||
RTW_DFS_REGD_KCC = 4,
|
||||
RTW_DFS_REGD_NUM,
|
||||
RTW_DFS_REGD_AUTO = 0xFF, /* follow channel plan */
|
||||
};
|
||||
|
||||
#define RTW_DFS_REGD_IS_UNKNOWN(regd) ((regd) == RTW_DFS_REGD_NONE || (regd) >= RTW_DFS_REGD_NUM)
|
||||
|
||||
extern const char *const _rtw_dfs_regd_str[];
|
||||
#define rtw_dfs_regd_str(region) (((region) >= RTW_DFS_REGD_NUM) ? _rtw_dfs_regd_str[RTW_DFS_REGD_NONE] : _rtw_dfs_regd_str[(region)])
|
||||
|
||||
typedef enum _REGULATION_TXPWR_LMT {
|
||||
TXPWR_LMT_NONE = 0, /* no limit */
|
||||
TXPWR_LMT_FCC = 1,
|
||||
TXPWR_LMT_MKK = 2,
|
||||
TXPWR_LMT_ETSI = 3,
|
||||
TXPWR_LMT_IC = 4,
|
||||
TXPWR_LMT_KCC = 5,
|
||||
TXPWR_LMT_NCC = 6,
|
||||
TXPWR_LMT_ACMA = 7,
|
||||
TXPWR_LMT_CHILE = 8,
|
||||
TXPWR_LMT_UKRAINE = 9,
|
||||
TXPWR_LMT_MEXICO = 10,
|
||||
TXPWR_LMT_CN = 11,
|
||||
TXPWR_LMT_QATAR = 12,
|
||||
TXPWR_LMT_UK = 13,
|
||||
TXPWR_LMT_WW, /* smallest of all available limit, keep last */
|
||||
|
||||
TXPWR_LMT_NUM,
|
||||
TXPWR_LMT_DEF = TXPWR_LMT_NUM, /* default (ref to domain code), used at country chplan map's override field */
|
||||
} REGULATION_TXPWR_LMT;
|
||||
|
||||
extern const char *const _txpwr_lmt_str[];
|
||||
#define txpwr_lmt_str(regd) (((regd) >= TXPWR_LMT_NUM) ? _txpwr_lmt_str[TXPWR_LMT_NUM] : _txpwr_lmt_str[(regd)])
|
||||
|
||||
extern const REGULATION_TXPWR_LMT _txpwr_lmt_alternate[];
|
||||
#define txpwr_lmt_alternate(ori) (((ori) > TXPWR_LMT_NUM) ? _txpwr_lmt_alternate[TXPWR_LMT_WW] : _txpwr_lmt_alternate[(ori)])
|
||||
|
||||
#define TXPWR_LMT_ALTERNATE_DEFINED(txpwr_lmt) (txpwr_lmt_alternate(txpwr_lmt) != txpwr_lmt)
|
||||
|
||||
extern const enum rtw_edcca_mode_t _rtw_regd_to_edcca_mode[RTW_REGD_NUM];
|
||||
#define rtw_regd_to_edcca_mode(regd) (((regd) >= RTW_REGD_NUM) ? RTW_EDCCA_NORM : _rtw_regd_to_edcca_mode[(regd)])
|
||||
|
||||
#if CONFIG_IEEE80211_BAND_6GHZ
|
||||
extern const enum rtw_edcca_mode_t _rtw_regd_to_edcca_mode_6g[RTW_REGD_NUM];
|
||||
#define rtw_regd_to_edcca_mode_6g(regd) (((regd) >= RTW_REGD_NUM) ? RTW_EDCCA_NORM : _rtw_regd_to_edcca_mode_6g[(regd)])
|
||||
#endif
|
||||
|
||||
extern const REGULATION_TXPWR_LMT _rtw_regd_to_txpwr_lmt[];
|
||||
#define rtw_regd_to_txpwr_lmt(regd) (((regd) >= RTW_REGD_NUM) ? TXPWR_LMT_WW : _rtw_regd_to_txpwr_lmt[(regd)])
|
||||
|
||||
#define REGD_INR_BMP_STR_LEN (33)
|
||||
char *rtw_get_regd_inr_bmp_str(char *buf, u8 bmp);
|
||||
|
||||
#define EDCCA_MODE_OF_BANDS_STR_LEN (((6 + 3 + 1) * BAND_MAX) + 1)
|
||||
char *rtw_get_edcca_mode_of_bands_str(char *buf, u8 mode_of_band[]);
|
||||
void rtw_edcca_mode_update(struct dvobj_priv *dvobj, bool req_lock);
|
||||
u8 rtw_get_edcca_mode(struct dvobj_priv *dvobj, enum band_type band);
|
||||
|
||||
#if CONFIG_TXPWR_LIMIT
|
||||
#define TXPWR_NAME_OF_BANDS_STR_LEN (((1 + 7 + 1) * BAND_MAX) + 1)
|
||||
char *rtw_get_txpwr_lmt_name_of_bands_str(char *buf, const char *name_of_band[], u8 unknown_bmp);
|
||||
void rtw_txpwr_update_cur_lmt_regs(struct dvobj_priv *dvobj, bool req_lock);
|
||||
#endif
|
||||
|
||||
#define CHPLAN_PROTO_EN_A BIT0
|
||||
#define CHPLAN_PROTO_EN_AC BIT1
|
||||
#define CHPLAN_PROTO_EN_AX BIT2
|
||||
#define CHPLAN_PROTO_EN_ALL 0xFF
|
||||
|
||||
struct country_chplan {
|
||||
char alpha2[2];
|
||||
|
||||
u8 domain_code;
|
||||
#if CONFIG_IEEE80211_BAND_6GHZ
|
||||
u8 domain_code_6g;
|
||||
#endif
|
||||
|
||||
/* will override edcca mode get by domain code (/6g) */
|
||||
u8 edcca_mode_2g_override:3;
|
||||
#if CONFIG_IEEE80211_BAND_5GHZ
|
||||
u8 edcca_mode_5g_override:3;
|
||||
#endif
|
||||
#if CONFIG_IEEE80211_BAND_6GHZ
|
||||
u8 edcca_mode_6g_override:3;
|
||||
#endif
|
||||
|
||||
/* will override txpwr_lmt get by domain code (/6g) */
|
||||
u8 txpwr_lmt_override;
|
||||
|
||||
#if defined(CONFIG_80211AX_HE) || defined(CONFIG_80211AC_VHT) || CONFIG_IEEE80211_BAND_5GHZ
|
||||
u8 proto_en;
|
||||
#endif
|
||||
};
|
||||
|
||||
#if CONFIG_IEEE80211_BAND_5GHZ
|
||||
#define COUNTRY_CHPLAN_ASSIGN_EDCCA_MODE_5G_OVERRIDE(_val) , .edcca_mode_5g_override = (_val)
|
||||
#else
|
||||
#define COUNTRY_CHPLAN_ASSIGN_EDCCA_MODE_5G_OVERRIDE(_val)
|
||||
#endif
|
||||
|
||||
#if CONFIG_IEEE80211_BAND_6GHZ
|
||||
#define COUNTRY_CHPLAN_ASSIGN_CHPLAN_6G(_val) , .domain_code_6g = (_val)
|
||||
#define COUNTRY_CHPLAN_ASSIGN_EDCCA_MODE_6G_OVERRIDE(_val) , .edcca_mode_6g_override = (_val)
|
||||
#else
|
||||
#define COUNTRY_CHPLAN_ASSIGN_CHPLAN_6G(_val)
|
||||
#define COUNTRY_CHPLAN_ASSIGN_EDCCA_MODE_6G_OVERRIDE(_val)
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_80211AX_HE) || defined(CONFIG_80211AC_VHT) || CONFIG_IEEE80211_BAND_5GHZ
|
||||
#define COUNTRY_CHPLAN_ASSIGN_PROTO_EN(_val) , .proto_en = (_val)
|
||||
#else
|
||||
#define COUNTRY_CHPLAN_ASSIGN_PROTO_EN(_val)
|
||||
#endif
|
||||
|
||||
#define COUNTRY_CHPLAN_ENT(_alpha2, _chplan, _chplan_6g, _txpwr_lmt_override, _en_11ax, _en_11ac, _en_11a) \
|
||||
{.alpha2 = (_alpha2), .domain_code = (_chplan) \
|
||||
COUNTRY_CHPLAN_ASSIGN_CHPLAN_6G(_chplan_6g) \
|
||||
, .edcca_mode_2g_override = RTW_EDCCA_DEF \
|
||||
COUNTRY_CHPLAN_ASSIGN_EDCCA_MODE_5G_OVERRIDE(RTW_EDCCA_DEF) \
|
||||
COUNTRY_CHPLAN_ASSIGN_EDCCA_MODE_6G_OVERRIDE(RTW_EDCCA_DEF) \
|
||||
, .txpwr_lmt_override = TXPWR_LMT_##_txpwr_lmt_override \
|
||||
COUNTRY_CHPLAN_ASSIGN_PROTO_EN((_en_11ax ? CHPLAN_PROTO_EN_AX : 0) | (_en_11ac ? CHPLAN_PROTO_EN_AC : 0) | (_en_11a ? CHPLAN_PROTO_EN_A : 0)) \
|
||||
}
|
||||
|
||||
#if CONFIG_IEEE80211_BAND_5GHZ
|
||||
#define COUNTRY_CHPLAN_EN_11A(_ent) (((_ent)->proto_en & CHPLAN_PROTO_EN_A) ? true : false)
|
||||
#else
|
||||
#define COUNTRY_CHPLAN_EN_11A(_ent) false
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_80211AC_VHT
|
||||
#define COUNTRY_CHPLAN_EN_11AC(_ent) (((_ent)->proto_en & CHPLAN_PROTO_EN_AC) ? true : false)
|
||||
#else
|
||||
#define COUNTRY_CHPLAN_EN_11AC(_ent) false
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_80211AX_HE
|
||||
#define COUNTRY_CHPLAN_EN_11AX(_ent) (((_ent)->proto_en & CHPLAN_PROTO_EN_AX) ? true : false)
|
||||
#else
|
||||
#define COUNTRY_CHPLAN_EN_11AX(_ent) false
|
||||
#endif
|
||||
|
||||
void rtw_get_chplan_worldwide(struct country_chplan *ent);
|
||||
bool rtw_get_chplan_from_country(const char *country_code, struct country_chplan *ent);
|
||||
|
||||
void rtw_chplan_ioctl_input_mapping(u16 *chplan, u16 *chplan_6g);
|
||||
bool rtw_chplan_ids_is_world_wide(u8 chplan, u8 chplan_6g);
|
||||
|
||||
u8 rtw_country_chplan_is_bchbw_valid(struct country_chplan *ent, enum band_type band, u8 ch, u8 bw, u8 offset
|
||||
, bool allow_primary_passive, bool allow_passive, struct rf_ctl_t *rfctl);
|
||||
|
||||
enum country_ie_slave_en_mode {
|
||||
CISEM_DISABLE = 0, /* disable */
|
||||
CISEM_ENABLE = 1, /* enable */
|
||||
CISEM_ENABLE_WW = 2, /* enable when INIT/USER set world wide mode */
|
||||
CISEM_NUM,
|
||||
};
|
||||
|
||||
#define CIS_EN_MODE_IS_VALID(mode) ((mode) < CISEM_NUM)
|
||||
|
||||
enum country_ie_slave_flags {
|
||||
CISF_INTERSECT = BIT0, /* if not set, choose effected one from received IEs */
|
||||
CISF_ENV_BSS = BIT1, /* if not set, consider IEs of associated BSSs only */
|
||||
};
|
||||
|
||||
enum country_ie_slave_status {
|
||||
COUNTRY_IE_SLAVE_NOCOUNTRY = 0,
|
||||
COUNTRY_IE_SLAVE_UNKNOWN = 1,
|
||||
COUNTRY_IE_SLAVE_OPCH_NOEXIST = 2,
|
||||
COUNTRY_IE_SLAVE_APPLICABLE = 3,
|
||||
|
||||
COUNTRY_IE_SLAVE_STATUS_NUM,
|
||||
};
|
||||
|
||||
struct country_ie_slave_record {
|
||||
char alpha2[2]; /* country code get from connected AP of STA ifaces, "\x00\x00" is not set */
|
||||
enum band_type band;
|
||||
u8 opch;
|
||||
enum country_ie_slave_status status;
|
||||
struct country_chplan chplan;
|
||||
};
|
||||
|
||||
#ifdef CONFIG_80211D
|
||||
extern const char *const _cis_status_str[];
|
||||
#define cis_status_str(s) (((s) >= COUNTRY_IE_SLAVE_STATUS_NUM) ? _cis_status_str[COUNTRY_IE_SLAVE_STATUS_NUM] : _cis_status_str[(s)])
|
||||
|
||||
void dump_country_ie_slave_records(void *sel, struct rf_ctl_t *rfctl, bool skip_noset);
|
||||
|
||||
enum country_ie_slave_status rtw_get_cisr_from_recv_country_ie(struct rf_ctl_t *rfctl
|
||||
, enum band_type band, u8 opch, const u8 *country_ie
|
||||
, struct country_ie_slave_record *cisr, const char *caller_msg);
|
||||
#endif
|
||||
|
||||
void dump_country_chplan(void *sel, const struct country_chplan *ent, bool regd_info);
|
||||
void dump_country_chplan_map(void *sel, bool regd_info);
|
||||
void dump_country_list(void *sel);
|
||||
void dump_chplan_id_list(void *sel);
|
||||
void dump_chplan_country_list(void *sel);
|
||||
#if CONFIG_IEEE80211_BAND_6GHZ
|
||||
void dump_chplan_6g_id_list(void *sel);
|
||||
void dump_chplan_6g_country_list(void *sel);
|
||||
#endif
|
||||
#ifdef CONFIG_RTW_DEBUG
|
||||
void dump_chplan_test(void *sel);
|
||||
#endif
|
||||
void dump_chplan_ver(void *sel);
|
||||
|
||||
struct regd_req_t {
|
||||
_list list;
|
||||
int ref_cnt; /* used by RTK_PRIV's COUNTRY_IE req */
|
||||
bool applied;
|
||||
|
||||
enum regd_src_t src;
|
||||
enum rtw_regd_inr inr;
|
||||
|
||||
struct country_chplan chplan;
|
||||
};
|
||||
|
||||
void rtw_regd_req_list_init(struct rf_ctl_t *rfctl, struct registry_priv *regsty);
|
||||
void rtw_regd_req_list_free(struct rf_ctl_t *rfctl);
|
||||
|
||||
void rtw_regd_watchdog_hdl(struct dvobj_priv *dvobj);
|
||||
|
||||
struct _ADAPTER_LINK;
|
||||
enum channel_width alink_adjust_linking_bw_by_regd(struct _ADAPTER_LINK *alink
|
||||
, enum band_type band, u8 ch, enum channel_width bw, enum chan_offset offset);
|
||||
enum channel_width adapter_adjust_linking_bw_by_regd(_adapter *adapter
|
||||
, enum band_type band, u8 ch, enum channel_width bw, enum chan_offset offset);
|
||||
|
||||
void rtw_rfctl_decide_init_chplan(struct rf_ctl_t *rfctl,
|
||||
const char *hw_alpha2, u8 hw_chplan, u8 hw_chplan_6g, u8 hw_force_chplan);
|
||||
|
||||
bool rtw_rfctl_is_disable_sw_channel_plan(struct dvobj_priv *dvobj);
|
||||
|
||||
enum chplan_confs_type {
|
||||
CHPLAN_CONFS_DIS_CH_FLAGS,
|
||||
CHPLAN_CONFS_EXCL_CHS,
|
||||
CHPLAN_CONFS_EXCL_CHS_6G,
|
||||
CHPLAN_CONFS_INIT_REGD_ALWAYS_APPLY,
|
||||
CHPLAN_CONFS_USER_REGD_ALWAYS_APPLY,
|
||||
CHPLAN_CONFS_BCN_HINT_VALID_MS,
|
||||
CHPLAN_CONFS_CIS_EN_MODE,
|
||||
CHPLAN_CONFS_CIS_FLAGS,
|
||||
CHPLAN_CONFS_CIS_EN_ROLE,
|
||||
CHPLAN_CONFS_CIS_EN_IFBMP,
|
||||
CHPLAN_CONFS_CIS_SCAN_INT_MS,
|
||||
CHPLAN_CONFS_NUM,
|
||||
};
|
||||
|
||||
struct chplan_confs {
|
||||
u16 set_types; /* bitmap of chplan_confs_type */
|
||||
u8 dis_ch_flags;
|
||||
u8 excl_chs[MAX_CHANNEL_NUM_2G_5G];
|
||||
#if CONFIG_IEEE80211_BAND_6GHZ
|
||||
u8 excl_chs_6g[MAX_CHANNEL_NUM_6G];
|
||||
#endif
|
||||
bool init_regd_always_apply;
|
||||
bool user_regd_always_apply;
|
||||
u32 bcn_hint_valid_ms;
|
||||
#ifdef CONFIG_80211D
|
||||
u8 cis_en_mode;
|
||||
u8 cis_flags;
|
||||
u8 cis_en_role;
|
||||
u8 cis_en_ifbmp;
|
||||
u32 cis_scan_int_ms;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct SetChannelPlan_param {
|
||||
enum regd_src_t regd_src;
|
||||
enum rtw_regd_inr inr;
|
||||
struct country_chplan country_ent;
|
||||
bool has_country;
|
||||
u8 channel_plan;
|
||||
#if CONFIG_IEEE80211_BAND_6GHZ
|
||||
u8 channel_plan_6g;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_80211D
|
||||
/* used for regd_src == RTK_PRIV and inr == COUNTRY_IE */
|
||||
struct country_ie_slave_record cisr;
|
||||
u8 cisr_alink_id;
|
||||
bool has_cisr;
|
||||
#endif
|
||||
|
||||
struct chplan_confs confs;
|
||||
|
||||
#ifdef PLATFORM_LINUX
|
||||
bool rtnl_lock_needed;
|
||||
#endif
|
||||
};
|
||||
|
||||
u8 rtw_set_chplan_hdl(_adapter *adapter, u8 *pbuf);
|
||||
|
||||
u8 rtw_set_chplan_cmd(_adapter *adapter, int flags, u8 chplan, u8 chplan_6g, enum rtw_regd_inr inr);
|
||||
u8 rtw_set_country_cmd(_adapter *adapter, int flags, const char *country_code, enum rtw_regd_inr inr);
|
||||
#ifdef CONFIG_80211D
|
||||
u8 rtw_alink_apply_recv_country_ie_cmd(struct _ADAPTER_LINK *alink, int flags, enum band_type band,u8 opch, const u8 *country_ie);
|
||||
u8 rtw_apply_recv_country_ie_cmd(_adapter *adapter, int flags, enum band_type band,u8 opch, const u8 *country_ie);
|
||||
u8 rtw_apply_scan_network_country_ie_cmd(_adapter *adapter, int flags);
|
||||
#endif
|
||||
#ifdef CONFIG_REGD_SRC_FROM_OS
|
||||
u8 rtw_sync_os_regd_cmd(_adapter *adapter, int flags, const char *country_code, u8 dfs_region, enum rtw_regd_inr inr);
|
||||
#endif
|
||||
u8 rtw_set_chplan_confs_cmd(_adapter *adapter, int flags, struct chplan_confs *confs);
|
||||
#ifdef CONFIG_PROC_DEBUG
|
||||
u16 rtw_parse_chplan_confs_cmd_str(struct chplan_confs *confs, char *str);
|
||||
#endif
|
||||
|
||||
struct get_chplan_resp {
|
||||
enum regd_src_t regd_src;
|
||||
u8 regd_inr_bmp;
|
||||
char alpha2[2];
|
||||
u8 channel_plan;
|
||||
#if CONFIG_IEEE80211_BAND_6GHZ
|
||||
u8 chplan_6g;
|
||||
#endif
|
||||
|
||||
#if CONFIG_TXPWR_LIMIT
|
||||
/* point to content of txpwr_lmt_names of specific band (after content of chset) */
|
||||
const char *txpwr_lmt_names[BAND_MAX];
|
||||
int txpwr_lmt_names_len[BAND_MAX];
|
||||
int txpwr_lmt_names_len_total; /* ease for free operation */
|
||||
#endif
|
||||
u8 edcca_mode_2g;
|
||||
#if CONFIG_IEEE80211_BAND_5GHZ
|
||||
u8 edcca_mode_5g;
|
||||
#endif
|
||||
#if CONFIG_IEEE80211_BAND_6GHZ
|
||||
u8 edcca_mode_6g;
|
||||
#endif
|
||||
#ifdef CONFIG_DFS_MASTER
|
||||
u8 dfs_domain;
|
||||
#endif
|
||||
u8 proto_en;
|
||||
|
||||
struct chplan_confs confs;
|
||||
|
||||
u8 chs_len;
|
||||
RT_CHANNEL_INFO chs[0];
|
||||
};
|
||||
|
||||
struct get_channel_plan_param {
|
||||
struct get_chplan_resp *chplan;
|
||||
};
|
||||
|
||||
u8 rtw_get_chplan_hdl(_adapter *adapter, u8 *pbuf);
|
||||
struct cmd_obj;
|
||||
void rtw_get_chplan_callback(_adapter *adapter, struct cmd_obj *cmdobj);
|
||||
|
||||
u8 rtw_get_chplan_cmd(_adapter *adapter, int flags, struct get_chplan_resp **chplan);
|
||||
void rtw_free_get_chplan_resp(struct get_chplan_resp *chplan);
|
||||
|
||||
#ifdef CONFIG_80211D
|
||||
void rtw_alink_joinbss_update_regulatory(struct _ADAPTER_LINK *alink, const WLAN_BSSID_EX *network);
|
||||
void rtw_alink_leavebss_update_regulatory(struct _ADAPTER_LINK * alink);
|
||||
void rtw_alink_csa_update_regulatory(struct _ADAPTER_LINK *alink, enum band_type req_band, u8 req_ch);
|
||||
void alink_process_country_ie(struct _ADAPTER_LINK *alink, u8 *ies, uint ies_len);
|
||||
|
||||
void rtw_joinbss_update_regulatory(_adapter *adapter, const WLAN_BSSID_EX *network);
|
||||
void rtw_leavebss_update_regulatory(_adapter *adapter);
|
||||
void rtw_csa_update_regulatory(_adapter *adapter, enum band_type req_band, u8 req_ch);
|
||||
void process_country_ie(_adapter *adapter, u8 *ies, uint ies_len);
|
||||
|
||||
bool rtw_update_scanned_network_cisr(struct rf_ctl_t *rfctl, struct wlan_network *network);
|
||||
|
||||
void rtw_rfctl_cis_init(struct rf_ctl_t *rfctl, struct registry_priv *regsty);
|
||||
void rtw_rfctl_cis_deinit(struct rf_ctl_t *rfctl);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_PROC_DEBUG
|
||||
void dump_cur_chplan_confs(void *sel, struct rf_ctl_t *rfctl);
|
||||
void dump_cur_country(void *sel, struct rf_ctl_t *rfctl);
|
||||
void dump_cur_chplan(void *sel, struct rf_ctl_t *rfctl);
|
||||
#endif
|
||||
|
||||
#define CHPLAN_VER_STR_BUF_LEN 16
|
||||
|
||||
struct rtw_regdb_ops {
|
||||
u8 (*get_default_regd_2g)(u8 id);
|
||||
#if CONFIG_IEEE80211_BAND_5GHZ
|
||||
u8 (*get_default_regd_5g)(u8 id);
|
||||
#endif
|
||||
bool (*is_domain_code_valid)(u8 id);
|
||||
bool (*domain_get_ch)(u8 id, u32 ch, u8 *flags);
|
||||
#if CONFIG_IEEE80211_BAND_6GHZ
|
||||
u8 (*get_default_regd_6g)(u8 id);
|
||||
bool (*is_domain_code_6g_valid)(u8 id);
|
||||
bool (*domain_6g_get_ch)(u8 id, u32 ch, u8 *flags);
|
||||
#endif
|
||||
|
||||
bool (*get_chplan_from_alpha2)(const char *alpha2, struct country_chplan *ent);
|
||||
|
||||
#ifdef CONFIG_RTW_DEBUG
|
||||
void (*dump_chplan_test)(void *sel);
|
||||
#endif
|
||||
void (*get_ver_str)(char *buf, size_t buf_len);
|
||||
};
|
||||
|
||||
#endif /* __RTW_CHPLAN_H__ */
|
||||
382
drivers/net/wireless/rtl8822cs/core/rtw_chset.c
Normal file
382
drivers/net/wireless/rtl8822cs/core/rtw_chset.c
Normal file
@@ -0,0 +1,382 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright(c) 2007 - 2022 Realtek Corporation.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of version 2 of the GNU General Public License as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*****************************************************************************/
|
||||
#define _RTW_CHSET_C_
|
||||
|
||||
#include <drv_types.h>
|
||||
|
||||
const char *const _rtw_ch_type_str[] = {
|
||||
[RTW_CHT_DIS] = "DIS",
|
||||
[RTW_CHT_NO_IR] = "NO_IR",
|
||||
[RTW_CHT_DFS] = "DFS",
|
||||
[RTW_CHT_NO_HT40U] = "NO_40M+",
|
||||
[RTW_CHT_NO_HT40L] = "NO_40M-",
|
||||
[RTW_CHT_NO_80MHZ] = "NO_80M",
|
||||
[RTW_CHT_NO_160MHZ] = "NO_160M",
|
||||
[RTW_CHT_NUM] = "UNKNOWN",
|
||||
};
|
||||
|
||||
enum rtw_ch_type get_ch_type_from_str(const char *str, size_t str_len)
|
||||
{
|
||||
u8 i;
|
||||
|
||||
for (i = 0; i < RTW_CHT_NUM; i++)
|
||||
if (str_len == strlen(rtw_ch_type_str(i))
|
||||
&& strncmp(str, rtw_ch_type_str(i), str_len) == 0)
|
||||
return i;
|
||||
return RTW_CHT_NUM;
|
||||
}
|
||||
|
||||
char *rtw_get_ch_flags_str(char *buf, u8 flags, char delim)
|
||||
{
|
||||
char *pos = buf;
|
||||
char d_str[2] = {delim, '\0'};
|
||||
int i;
|
||||
|
||||
for (i = 0; i < RTW_CHT_NUM; i++) {
|
||||
if (!(flags & BIT(i)))
|
||||
continue;
|
||||
pos += snprintf(pos, RTW_CH_FLAGS_STR_LEN - (pos - buf), "%s%s"
|
||||
, pos == buf ? "" : d_str, rtw_ch_type_str(i));
|
||||
if (pos >= buf + RTW_CH_FLAGS_STR_LEN - 1)
|
||||
break;
|
||||
}
|
||||
if (pos == buf)
|
||||
*buf = '\0';
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
int rtw_chset_init(struct rtw_chset *chset, u8 band_bmp)
|
||||
{
|
||||
u8 ch_num = 0;
|
||||
int band, i;
|
||||
|
||||
_rtw_memset(chset->chs, 0, sizeof(RT_CHANNEL_INFO) * MAX_CHANNEL_NUM);
|
||||
|
||||
for (band = 0; band < BAND_MAX; band++) {
|
||||
u8 center_ch_num;
|
||||
u8 (*center_chs)(u8, u8);
|
||||
|
||||
if (!(band_bmp & band_to_band_cap(band)))
|
||||
continue;
|
||||
|
||||
center_ch_num = center_chs_num_of_band[band](CHANNEL_WIDTH_20);
|
||||
center_chs = center_chs_of_band[band];
|
||||
|
||||
chset->chs_of_band[band] = &chset->chs[ch_num];
|
||||
chset->chs_len_of_band[band] = 0;
|
||||
|
||||
for (i = 0; i < center_ch_num; i++) {
|
||||
chset->chs[ch_num].band = band;
|
||||
chset->chs[ch_num].ChannelNum = center_chs(CHANNEL_WIDTH_20, i);
|
||||
chset->chs_len_of_band[band]++;;
|
||||
ch_num++;
|
||||
}
|
||||
}
|
||||
|
||||
chset->chs_len = ch_num;
|
||||
|
||||
return _SUCCESS;
|
||||
}
|
||||
|
||||
#if CONFIG_ALLOW_FUNC_2G_5G_ONLY
|
||||
/*
|
||||
* Search enabled channel with the @param ch in given @param ch_set
|
||||
* @ch_set: the given channel set
|
||||
* @ch: the given channel number
|
||||
*
|
||||
* return the index of channel_num in channel_set, -1 if not found
|
||||
*/
|
||||
RTW_FUNC_2G_5G_ONLY static int _rtw_chset_search_ch(const struct rtw_chset *chset, u32 ch, bool include_dis)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (ch == 0)
|
||||
return -1;
|
||||
|
||||
for (i = 0; i < chset->chs_len; i++) {
|
||||
if (ch == chset->chs[i].ChannelNum
|
||||
&& (include_dis || !(chset->chs[i].flags & RTW_CHF_DIS)))
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
RTW_FUNC_2G_5G_ONLY int rtw_chset_search_ch(const struct rtw_chset *chset, u32 ch)
|
||||
{
|
||||
return _rtw_chset_search_ch(chset, ch, false);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Search enabled channel with the @param ch of @param band in given @param ch_set
|
||||
* @ch_set: the given channel set
|
||||
* @band: the given band
|
||||
* @ch: the given channel number
|
||||
*
|
||||
* return the index of channel_num in channel_set, -1 if not found
|
||||
*/
|
||||
static int _rtw_chset_search_bch(const struct rtw_chset *chset, enum band_type band, u32 ch, bool include_dis)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (ch == 0)
|
||||
return -1;
|
||||
|
||||
for (i = 0; i < chset->chs_len; i++) {
|
||||
if (band == chset->chs[i].band && ch == chset->chs[i].ChannelNum
|
||||
&& (include_dis || !(chset->chs[i].flags & RTW_CHF_DIS)))
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int rtw_chset_search_bch(const struct rtw_chset *chset, enum band_type band, u32 ch)
|
||||
{
|
||||
return _rtw_chset_search_bch(chset, band, ch, false);
|
||||
}
|
||||
|
||||
RT_CHANNEL_INFO *rtw_chset_get_chinfo_by_bch(struct rtw_chset *chset, enum band_type band, u32 ch, bool include_dis)
|
||||
{
|
||||
int i = _rtw_chset_search_bch(chset, band, ch, include_dis);
|
||||
|
||||
return i >= 0 ? &chset->chs[i] : NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if the @param ch, bw, offset is valid for the given @param ch_set
|
||||
* @ch_set: the given channel set
|
||||
* @ch: the given channel number
|
||||
* @bw: the given bandwidth
|
||||
* @offset: the given channel offset
|
||||
*
|
||||
* return valid (1) or not (0)
|
||||
*/
|
||||
static u8 _rtw_chset_is_bchbw_valid(const struct rtw_chset *chset, enum band_type band, u8 ch, u8 bw, u8 offset
|
||||
, bool allow_primary_passive, bool allow_passive)
|
||||
{
|
||||
u8 cch;
|
||||
u8 *op_chs;
|
||||
u8 op_ch_num;
|
||||
u8 valid = 0;
|
||||
int i;
|
||||
int ch_idx;
|
||||
|
||||
cch = rtw_get_center_ch_by_band(band, ch, bw, offset);
|
||||
|
||||
if (!rtw_get_op_chs_by_bcch_bw(band, cch, bw, &op_chs, &op_ch_num))
|
||||
goto exit;
|
||||
|
||||
for (i = 0; i < op_ch_num; i++) {
|
||||
if (0)
|
||||
RTW_INFO("%u,%u,%u,%u - cch:%u, bw:%u, op_ch:%u\n", band, ch, bw, offset, cch, bw, *(op_chs + i));
|
||||
ch_idx = rtw_chset_search_bch(chset, band, *(op_chs + i));
|
||||
if (ch_idx == -1)
|
||||
break;
|
||||
if (!allow_passive && chset->chs[ch_idx].flags & RTW_CHF_NO_IR) {
|
||||
/* all sub chs are passive is not allowed and one of sub ch is NO_IR */
|
||||
if (!allow_primary_passive) /* even primary ch is not allow to be NO_IR */
|
||||
break;
|
||||
if (chset->chs[ch_idx].ChannelNum != ch) /* allow primary ch NO_IR, but this is not primary ch */
|
||||
break;
|
||||
}
|
||||
if (bw >= CHANNEL_WIDTH_40) {
|
||||
if ((chset->chs[ch_idx].flags & RTW_CHF_NO_HT40U) && i % 2 == 0)
|
||||
break;
|
||||
if ((chset->chs[ch_idx].flags & RTW_CHF_NO_HT40L) && i % 2 == 1)
|
||||
break;
|
||||
}
|
||||
if (bw >= CHANNEL_WIDTH_80 && (chset->chs[ch_idx].flags & RTW_CHF_NO_80MHZ))
|
||||
break;
|
||||
if (bw >= CHANNEL_WIDTH_160 && (chset->chs[ch_idx].flags & RTW_CHF_NO_160MHZ))
|
||||
break;
|
||||
}
|
||||
|
||||
if (op_ch_num != 0 && i == op_ch_num)
|
||||
valid = 1;
|
||||
|
||||
exit:
|
||||
return valid;
|
||||
}
|
||||
|
||||
#if CONFIG_ALLOW_FUNC_2G_5G_ONLY
|
||||
RTW_FUNC_2G_5G_ONLY u8 rtw_chset_is_chbw_valid(const struct rtw_chset *chset, u8 ch, u8 bw, u8 offset, bool allow_primary_passive, bool allow_passive)
|
||||
{
|
||||
return _rtw_chset_is_bchbw_valid(chset, rtw_is_2g_ch(ch) ? BAND_ON_24G : BAND_ON_5G, ch, bw, offset, allow_primary_passive, allow_passive);
|
||||
}
|
||||
#endif
|
||||
|
||||
u8 rtw_chset_is_bchbw_valid(const struct rtw_chset *chset, enum band_type band, u8 ch, u8 bw, u8 offset
|
||||
, bool allow_primary_passive, bool allow_passive)
|
||||
{
|
||||
return _rtw_chset_is_bchbw_valid(chset, band, ch, bw, offset, allow_primary_passive, allow_passive);
|
||||
}
|
||||
|
||||
/**
|
||||
* rtw_chset_sync_bchbw - obey g_ch, adjust g_bw, g_offset, bw, offset to fit in channel plan
|
||||
* @ch_set: channel plan to check
|
||||
* @req_ch: pointer of the request ch, may be modified further
|
||||
* @req_bw: pointer of the request bw, may be modified further
|
||||
* @req_offset: pointer of the request offset, may be modified further
|
||||
* @g_ch: pointer of the ongoing group ch
|
||||
* @g_bw: pointer of the ongoing group bw, may be modified further
|
||||
* @g_offset: pointer of the ongoing group offset, may be modified further
|
||||
* @allow_primary_passive: if allow passive primary ch when deciding chbw
|
||||
* @allow_passive: if allow passive ch (not primary) when deciding chbw
|
||||
*/
|
||||
void rtw_chset_sync_bchbw(const struct rtw_chset *chset, enum band_type *req_band, u8 *req_ch, u8 *req_bw, u8 *req_offset
|
||||
, enum band_type *g_band, u8 *g_ch, u8 *g_bw, u8 *g_offset, bool allow_primary_passive, bool allow_passive)
|
||||
{
|
||||
enum band_type r_band;
|
||||
u8 r_ch, r_bw, r_offset;
|
||||
enum band_type u_band;
|
||||
u8 u_ch, u_bw, u_offset;
|
||||
u8 cur_bw = *req_bw;
|
||||
|
||||
while (1) {
|
||||
r_band = *req_band;
|
||||
r_ch = *req_ch;
|
||||
r_bw = cur_bw;
|
||||
r_offset = *req_offset;
|
||||
u_band = *g_band;
|
||||
u_ch = *g_ch;
|
||||
u_bw = *g_bw;
|
||||
u_offset = *g_offset;
|
||||
|
||||
rtw_sync_bchbw(&r_band, &r_ch, &r_bw, &r_offset, &u_band, &u_ch, &u_bw, &u_offset);
|
||||
|
||||
if (rtw_chset_is_bchbw_valid(chset, r_band, r_ch, r_bw, r_offset, allow_primary_passive, allow_passive))
|
||||
break;
|
||||
if (cur_bw == CHANNEL_WIDTH_20) {
|
||||
rtw_warn_on(1);
|
||||
break;
|
||||
}
|
||||
cur_bw--;
|
||||
};
|
||||
|
||||
*req_band = r_band;
|
||||
*req_ch = r_ch;
|
||||
*req_bw = r_bw;
|
||||
*req_offset = r_offset;
|
||||
*g_band = u_band;
|
||||
*g_ch = u_ch;
|
||||
*g_bw = u_bw;
|
||||
*g_offset = u_offset;
|
||||
}
|
||||
|
||||
#if CONFIG_ALLOW_FUNC_2G_5G_ONLY
|
||||
RTW_FUNC_2G_5G_ONLY void rtw_chset_sync_chbw(const struct rtw_chset *chset, u8 *req_ch, u8 *req_bw, u8 *req_offset
|
||||
, u8 *g_ch, u8 *g_bw, u8 *g_offset, bool allow_primary_passive, bool allow_passive)
|
||||
{
|
||||
enum band_type band = rtw_is_2g_ch(*g_ch) ? BAND_ON_24G : BAND_ON_5G; /* follow g_ch's band */
|
||||
|
||||
rtw_chset_sync_bchbw(chset, &band, req_ch, req_bw, req_offset, &band, g_ch, g_bw, g_offset, allow_primary_passive, allow_passive);
|
||||
}
|
||||
#endif
|
||||
|
||||
u8 *rtw_chset_set_spt_chs_ie(struct rtw_chset *chset, u8 *buf_pos, uint *buf_len)
|
||||
{
|
||||
u8 i = 0;
|
||||
u8 fch = 0, lch = 0, ch;
|
||||
u8 *cont = buf_pos + 2;
|
||||
RT_CHANNEL_INFO *chinfo;
|
||||
|
||||
while (i < chset->chs_len) {
|
||||
chinfo = &chset->chs[i++];
|
||||
|
||||
if (chinfo->flags & RTW_CHF_DIS)
|
||||
continue;
|
||||
|
||||
#if CONFIG_IEEE80211_BAND_6GHZ
|
||||
/* don't appnd 6G chs now, how to distinguish 2G/5G chs with 6G? */
|
||||
if (chinfo->band == BAND_ON_6G)
|
||||
continue;
|
||||
#endif
|
||||
|
||||
ch = chinfo->ChannelNum;
|
||||
if (fch == 0) {
|
||||
fch = ch;
|
||||
lch = ch;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (lch + 1 != ch) {
|
||||
*cont = fch;
|
||||
*(cont + 1) = lch - fch + 1;
|
||||
cont += 2;
|
||||
fch = ch;
|
||||
}
|
||||
lch = ch;
|
||||
}
|
||||
if (fch) {
|
||||
/* last subband */
|
||||
*cont = fch;
|
||||
*(cont + 1) = lch - fch + 1;
|
||||
cont += 2;
|
||||
}
|
||||
|
||||
if (cont > buf_pos + 2) {
|
||||
*buf_pos = WLAN_EID_SUPPORTED_CHANNELS;
|
||||
*(buf_pos + 1) = cont - buf_pos - 2;
|
||||
*buf_len += cont - buf_pos;
|
||||
return cont;
|
||||
}
|
||||
return buf_pos;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_PROC_DEBUG
|
||||
void dump_chinfos(void *sel, const RT_CHANNEL_INFO *chinfos, u8 chinfo_num)
|
||||
{
|
||||
u32 bhint_sec;
|
||||
char bhint_buf[8];
|
||||
u16 non_ocp_sec;
|
||||
char non_ocp_buf[8];
|
||||
char flags_buf[RTW_CH_FLAGS_STR_LEN];
|
||||
u8 enable_ch_num = 0;
|
||||
u8 i;
|
||||
|
||||
RTW_PRINT_SEL(sel, "%-3s %-4s %-5s %-4s flags\n", "ch", "freq", "bhint", "nocp");
|
||||
|
||||
for (i = 0; i < chinfo_num; i++) {
|
||||
if (chinfos[i].flags & RTW_CHF_DIS)
|
||||
continue;
|
||||
enable_ch_num++;
|
||||
|
||||
bhint_sec = 0;
|
||||
if (CH_IS_BCN_HINT(&chinfos[i])) {
|
||||
bhint_sec = rtw_systime_to_ms(chinfos[i].bcn_hint_end_time - rtw_get_current_time()) / 1000;
|
||||
if (bhint_sec > 99999)
|
||||
bhint_sec = 99999;
|
||||
}
|
||||
snprintf(bhint_buf, 8, "%d", bhint_sec);
|
||||
|
||||
non_ocp_sec = 0;
|
||||
#ifdef CONFIG_DFS_MASTER
|
||||
if (CH_IS_NON_OCP(&chinfos[i]))
|
||||
non_ocp_sec = rtw_systime_to_ms(chinfos[i].non_ocp_end_time - rtw_get_current_time()) / 1000;
|
||||
#endif
|
||||
snprintf(non_ocp_buf, 8, "%d", non_ocp_sec);
|
||||
|
||||
RTW_PRINT_SEL(sel, "%3u %4u %5s %4s %s\n"
|
||||
, chinfos[i].ChannelNum, rtw_bch2freq(chinfos[i].band, chinfos[i].ChannelNum)
|
||||
, bhint_buf, non_ocp_buf, rtw_get_ch_flags_str(flags_buf, chinfos[i].flags, ' ')
|
||||
);
|
||||
}
|
||||
|
||||
RTW_PRINT_SEL(sel, "total ch number:%d\n", enable_ch_num);
|
||||
}
|
||||
#endif /* CONFIG_PROC_DEBUG */
|
||||
112
drivers/net/wireless/rtl8822cs/core/rtw_chset.h
Normal file
112
drivers/net/wireless/rtl8822cs/core/rtw_chset.h
Normal file
@@ -0,0 +1,112 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright(c) 2007 - 2022 Realtek Corporation.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of version 2 of the GNU General Public License as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*****************************************************************************/
|
||||
#ifndef __RTW_CHSET_H__
|
||||
#define __RTW_CHSET_H__
|
||||
|
||||
enum rtw_ch_type {
|
||||
RTW_CHT_DIS = 0,
|
||||
RTW_CHT_NO_IR = 1,
|
||||
RTW_CHT_DFS = 2,
|
||||
RTW_CHT_NO_HT40U = 3,
|
||||
RTW_CHT_NO_HT40L = 4,
|
||||
RTW_CHT_NO_80MHZ = 5,
|
||||
RTW_CHT_NO_160MHZ = 6,
|
||||
RTW_CHT_NUM,
|
||||
};
|
||||
|
||||
extern const char *const _rtw_ch_type_str[];
|
||||
#define rtw_ch_type_str(type) (((type) >= RTW_CHT_NUM) ? _rtw_ch_type_str[RTW_CHT_NUM] : _rtw_ch_type_str[(type)])
|
||||
|
||||
enum rtw_ch_type get_ch_type_from_str(const char *str, size_t str_len);
|
||||
|
||||
enum {
|
||||
RTW_CHF_DIS = BIT(RTW_CHT_DIS),
|
||||
RTW_CHF_NO_IR = BIT(RTW_CHT_NO_IR),
|
||||
RTW_CHF_DFS = BIT(RTW_CHT_DFS),
|
||||
RTW_CHF_NO_HT40U = BIT(RTW_CHT_NO_HT40U),
|
||||
RTW_CHF_NO_HT40L = BIT(RTW_CHT_NO_HT40L),
|
||||
RTW_CHF_NO_80MHZ = BIT(RTW_CHT_NO_80MHZ),
|
||||
RTW_CHF_NO_160MHZ = BIT(RTW_CHT_NO_160MHZ),
|
||||
};
|
||||
|
||||
#define RTW_CH_FLAGS_STR_LEN (45)
|
||||
char *rtw_get_ch_flags_str(char *buf, u8 flags, char delim);
|
||||
|
||||
/* The channel information about this channel including joining, scanning, and power constraints. */
|
||||
typedef struct _RT_CHANNEL_INFO {
|
||||
u8 band; /* enum band_type */
|
||||
u8 ChannelNum; /* The channel number. */
|
||||
|
||||
/*
|
||||
* Bitmap and its usage:
|
||||
* RTW_CHF_DIS, RTW_CHF_NO_IR, RTW_CHF_DFS: is used to check for status
|
||||
* RTW_CHF_NO_HT40U, RTW_CHF_NO_HT40L, RTW_CHF_NO_80MHZ, RTW_CHF_NO_160MHZ: extra bandwidth limitation (ex: from regulatory)
|
||||
*/
|
||||
u8 flags;
|
||||
|
||||
bool reg_no_ir;
|
||||
systime bcn_hint_end_time;
|
||||
|
||||
#ifdef CONFIG_FIND_BEST_CHANNEL
|
||||
u32 rx_count;
|
||||
#endif
|
||||
|
||||
#if CONFIG_IEEE80211_BAND_5GHZ && CONFIG_DFS
|
||||
#ifdef CONFIG_DFS_MASTER
|
||||
bool cac_done;
|
||||
systime non_ocp_end_time;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
u8 hidden_bss_cnt; /* per scan count */
|
||||
|
||||
#if defined(CONFIG_IOCTL_CFG80211) && !RTW_PER_ADAPTER_WIPHY
|
||||
void *os_chan;
|
||||
#endif
|
||||
} RT_CHANNEL_INFO, *PRT_CHANNEL_INFO;
|
||||
|
||||
#define RTW_BCN_HINT_STOPPED 0 /* used by bcn_hint_end_time time stamps */
|
||||
#define CH_IS_BCN_HINT_STOPPED(rt_ch_info) ((rt_ch_info)->bcn_hint_end_time == RTW_BCN_HINT_STOPPED)
|
||||
#define CH_IS_BCN_HINT(rt_ch_info) (!CH_IS_BCN_HINT_STOPPED(rt_ch_info) && rtw_time_after((rt_ch_info)->bcn_hint_end_time, rtw_get_current_time()))
|
||||
|
||||
struct rtw_chset {
|
||||
RT_CHANNEL_INFO chs[MAX_CHANNEL_NUM];
|
||||
u8 chs_len;
|
||||
RT_CHANNEL_INFO *chs_of_band[BAND_MAX];
|
||||
u8 chs_len_of_band[BAND_MAX];
|
||||
u8 enable_ch_num;
|
||||
};
|
||||
|
||||
int rtw_chset_init(struct rtw_chset *chset, u8 band_bmp);
|
||||
|
||||
RTW_FUNC_2G_5G_ONLY int rtw_chset_search_ch(const struct rtw_chset *chset, u32 ch);
|
||||
RTW_FUNC_2G_5G_ONLY u8 rtw_chset_is_chbw_valid(const struct rtw_chset *chset, u8 ch, u8 bw, u8 offset
|
||||
, bool allow_primary_passive, bool allow_passive);
|
||||
RTW_FUNC_2G_5G_ONLY void rtw_chset_sync_chbw(const struct rtw_chset *chset, u8 *req_ch, u8 *req_bw, u8 *req_offset
|
||||
, u8 *g_ch, u8 *g_bw, u8 *g_offset, bool allow_primary_passive, bool allow_passive);
|
||||
int rtw_chset_search_bch(const struct rtw_chset *chset, enum band_type band, u32 ch);
|
||||
RT_CHANNEL_INFO *rtw_chset_get_chinfo_by_bch(struct rtw_chset *chset, enum band_type band, u32 ch, bool include_dis);
|
||||
u8 rtw_chset_is_bchbw_valid(const struct rtw_chset *chset, enum band_type band, u8 ch, u8 bw, u8 offset
|
||||
, bool allow_primary_passive, bool allow_passive);
|
||||
void rtw_chset_sync_bchbw(const struct rtw_chset *chset, enum band_type *req_band, u8 *req_ch, u8 *req_bw, u8 *req_offset
|
||||
, enum band_type *g_band, u8 *g_ch, u8 *g_bw, u8 *g_offset, bool allow_primary_passive, bool allow_passive);
|
||||
|
||||
u8 *rtw_chset_set_spt_chs_ie(struct rtw_chset *chset, u8 *buf_pos, uint *buf_len);
|
||||
|
||||
#ifdef CONFIG_PROC_DEBUG
|
||||
void dump_chinfos(void *sel, const RT_CHANNEL_INFO *chinfos, u8 chinfo_num);
|
||||
#endif
|
||||
|
||||
#endif /* __RTW_CHSET_H__ */
|
||||
5215
drivers/net/wireless/rtl8822cs/core/rtw_cmd.c
Normal file
5215
drivers/net/wireless/rtl8822cs/core/rtw_cmd.c
Normal file
File diff suppressed because it is too large
Load Diff
9019
drivers/net/wireless/rtl8822cs/core/rtw_debug.c
Normal file
9019
drivers/net/wireless/rtl8822cs/core/rtw_debug.c
Normal file
File diff suppressed because it is too large
Load Diff
1612
drivers/net/wireless/rtl8822cs/core/rtw_dfs.c
Normal file
1612
drivers/net/wireless/rtl8822cs/core/rtw_dfs.c
Normal file
File diff suppressed because it is too large
Load Diff
95
drivers/net/wireless/rtl8822cs/core/rtw_dfs.h
Normal file
95
drivers/net/wireless/rtl8822cs/core/rtw_dfs.h
Normal file
@@ -0,0 +1,95 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright(c) 2007 - 2022 Realtek Corporation.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of version 2 of the GNU General Public License as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*****************************************************************************/
|
||||
#ifndef __RTW_DFS_H__
|
||||
#define __RTW_DFS_H__
|
||||
|
||||
#define CAC_TIME_MS (60*1000)
|
||||
#define CAC_TIME_CE_MS (10*60*1000)
|
||||
#define NON_OCP_TIME_MS (30*60*1000)
|
||||
|
||||
#define RTW_CAC_STOPPED 0 /* used by cac_start_time, cac_end_time time stamps */
|
||||
#define RTW_NON_OCP_STOPPED 0 /* used by non_ocp_end_time time stamps */
|
||||
|
||||
bool rtw_chset_is_dfs_range(const struct rtw_chset *chset, u32 hi, u32 lo);
|
||||
RTW_FUNC_2G_5G_ONLY bool rtw_chset_is_dfs_ch(const struct rtw_chset *chset, u8 ch);
|
||||
RTW_FUNC_2G_5G_ONLY bool rtw_chset_is_dfs_chbw(const struct rtw_chset *chset, u8 ch, u8 bw, u8 offset);
|
||||
bool rtw_chset_is_dfs_bch(const struct rtw_chset *chset, enum band_type band, u8 ch);
|
||||
bool rtw_chset_is_dfs_bchbw(const struct rtw_chset *chset, enum band_type band, u8 ch, u8 bw, u8 offset);
|
||||
|
||||
enum rtw_dfs_regd rtw_rfctl_get_dfs_domain(struct rf_ctl_t *rfctl);
|
||||
bool rtw_rfctl_radar_detect_supported(struct rf_ctl_t *rfctl);
|
||||
|
||||
#ifdef CONFIG_DFS_MASTER
|
||||
struct rf_ctl_t;
|
||||
enum phl_band_idx;
|
||||
|
||||
#define CH_IS_NON_OCP_STOPPED(rt_ch_info) ((rt_ch_info)->non_ocp_end_time == RTW_NON_OCP_STOPPED)
|
||||
#define CH_IS_NON_OCP(rt_ch_info) (!CH_IS_NON_OCP_STOPPED(rt_ch_info) && rtw_time_after((rt_ch_info)->non_ocp_end_time, rtw_get_current_time()))
|
||||
|
||||
bool rtw_rfctl_overlap_radar_detect_ch(struct rf_ctl_t *rfctl, enum band_type band, u8 ch, u8 bw, u8 offset);
|
||||
bool rtw_rfctl_hwband_is_tx_blocked_by_ch_waiting(struct rf_ctl_t *rfctl, enum phl_band_idx hwband);
|
||||
bool adapter_is_tx_blocked_by_ch_waiting(_adapter *adapter);
|
||||
bool alink_is_tx_blocked_by_ch_waiting(struct _ADAPTER_LINK *alink);
|
||||
|
||||
RTW_FUNC_2G_5G_ONLY bool rtw_chset_is_chbw_non_ocp(const struct rtw_chset *chset, u8 ch, u8 bw, u8 offset);
|
||||
RTW_FUNC_2G_5G_ONLY bool rtw_chset_is_ch_non_ocp(const struct rtw_chset *chset, u8 ch);
|
||||
bool rtw_chset_is_bchbw_non_ocp(const struct rtw_chset *chset, enum band_type band, u8 ch, u8 bw, u8 offset);
|
||||
bool rtw_chset_is_bch_non_ocp(const struct rtw_chset *chset, enum band_type band, u8 ch);
|
||||
|
||||
void rtw_rfctl_chset_chk_non_ocp_finish(struct rf_ctl_t *rfctl);
|
||||
|
||||
void rtw_rfctl_force_update_non_ocp_ms(struct rf_ctl_t *rfctl, enum band_type band, u8 ch, u8 bw, u8 offset, int ms);
|
||||
|
||||
u32 rtw_get_ch_waiting_ms(struct rf_ctl_t *rfctl, enum band_type band, u8 ch, u8 bw, u8 offset, u32 *r_non_ocp_ms, u32 *r_cac_ms);
|
||||
|
||||
u32 rtw_force_stop_cac(struct rf_ctl_t *rfctl, u32 timeout_ms);
|
||||
|
||||
u8 rtw_dfs_rd_hdl(struct dvobj_priv *dvobj, enum phl_band_idx hwband, u8 radar_cch, enum channel_width radar_bw);
|
||||
|
||||
void rtw_dfs_rd_en_dec_update(struct dvobj_priv *dvobj, enum phl_band_idx hwband);
|
||||
u8 rtw_dfs_rd_en_decision_cmd(struct dvobj_priv *dvobj, enum phl_band_idx hwband);
|
||||
|
||||
void rtw_indicate_cac_state_on_bss_start(_adapter *adapter);
|
||||
void rtw_indicate_cac_state_on_bss_stop(_adapter *adapter);
|
||||
|
||||
#else
|
||||
#define CH_IS_NON_OCP(rt_ch_info) 0
|
||||
#define rtw_rfctl_hwband_is_tx_blocked_by_ch_waiting(rfctl, hwband) false
|
||||
#define adapter_is_tx_blocked_by_ch_waiting(adapter) false
|
||||
#define alink_is_tx_blocked_by_ch_waiting(alink) false
|
||||
|
||||
RTW_FUNC_2G_5G_ONLY static inline bool rtw_chset_is_chbw_non_ocp(const struct rtw_chset *chset, u8 ch, u8 bw, u8 offset) { return false; }
|
||||
RTW_FUNC_2G_5G_ONLY static inline bool rtw_chset_is_ch_non_ocp(const struct rtw_chset *chset, u8 ch) { return false; }
|
||||
#define rtw_chset_is_bchbw_non_ocp(chset, band, ch, bw, offset) false
|
||||
#define rtw_chset_is_bch_non_ocp(chset, band, ch) false
|
||||
#endif /* CONFIG_DFS_MASTER */
|
||||
|
||||
#if CONFIG_DFS && CONFIG_IEEE80211_BAND_5GHZ
|
||||
void rtw_dfs_rd_en_dec_on_mlme_act(_adapter *adapter, struct _ADAPTER_LINK *alink, u8 mlme_act, u8 excl_ifbmp);
|
||||
void dump_radar_detect_status(void *sel, struct rf_ctl_t *rfctl, const char *title);
|
||||
#endif
|
||||
|
||||
bool rtw_rfctl_choose_bchbw(struct rf_ctl_t *rfctl
|
||||
, enum band_type sel_band, u8 sel_ch, u8 max_bw, enum chan_offset sel_offset
|
||||
, enum band_type cur_band, u8 cur_ch, enum chan_offset cur_offset
|
||||
, enum band_type *band, u8 *ch, u8 *bw, u8 *offset
|
||||
, bool by_int_info, u8 mesh_only, const char *caller);
|
||||
|
||||
RTW_FUNC_2G_5G_ONLY bool rtw_rfctl_choose_chbw(struct rf_ctl_t *rfctl, u8 sel_ch, u8 max_bw, enum chan_offset sel_offset
|
||||
, u8 cur_ch, enum chan_offset cur_offset, u8 *ch, u8 *bw, u8 *offset, bool by_int_info, u8 mesh_only, const char *caller);
|
||||
|
||||
void rtw_rfctl_dfs_init(struct rf_ctl_t *rfctl, struct registry_priv *regsty);
|
||||
|
||||
#endif /* __RTW_DFS_H__ */
|
||||
329
drivers/net/wireless/rtl8822cs/core/rtw_eeprom.c
Normal file
329
drivers/net/wireless/rtl8822cs/core/rtw_eeprom.c
Normal file
@@ -0,0 +1,329 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright(c) 2007 - 2017 Realtek Corporation.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of version 2 of the GNU General Public License as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*****************************************************************************/
|
||||
#define _RTW_EEPROM_C_
|
||||
|
||||
#include <drv_conf.h>
|
||||
#include <osdep_service.h>
|
||||
#include <drv_types.h>
|
||||
|
||||
void up_clk(_adapter *padapter, u16 *x)
|
||||
{
|
||||
*x = *x | _EESK;
|
||||
rtw_write8(padapter, EE_9346CR, (u8)*x);
|
||||
rtw_udelay_os(CLOCK_RATE);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void down_clk(_adapter *padapter, u16 *x)
|
||||
{
|
||||
*x = *x & ~_EESK;
|
||||
rtw_write8(padapter, EE_9346CR, (u8)*x);
|
||||
rtw_udelay_os(CLOCK_RATE);
|
||||
}
|
||||
|
||||
void shift_out_bits(_adapter *padapter, u16 data, u16 count)
|
||||
{
|
||||
u16 x, mask;
|
||||
|
||||
if (rtw_is_surprise_removed(padapter)) {
|
||||
goto out;
|
||||
}
|
||||
mask = 0x01 << (count - 1);
|
||||
x = rtw_read8(padapter, EE_9346CR);
|
||||
|
||||
x &= ~(_EEDO | _EEDI);
|
||||
|
||||
do {
|
||||
x &= ~_EEDI;
|
||||
if (data & mask)
|
||||
x |= _EEDI;
|
||||
if (rtw_is_surprise_removed(padapter)) {
|
||||
goto out;
|
||||
}
|
||||
rtw_write8(padapter, EE_9346CR, (u8)x);
|
||||
rtw_udelay_os(CLOCK_RATE);
|
||||
up_clk(padapter, &x);
|
||||
down_clk(padapter, &x);
|
||||
mask = mask >> 1;
|
||||
} while (mask);
|
||||
if (rtw_is_surprise_removed(padapter)) {
|
||||
goto out;
|
||||
}
|
||||
x &= ~_EEDI;
|
||||
rtw_write8(padapter, EE_9346CR, (u8)x);
|
||||
out:
|
||||
return;
|
||||
}
|
||||
|
||||
u16 shift_in_bits(_adapter *padapter)
|
||||
{
|
||||
u16 x, d = 0, i;
|
||||
if (rtw_is_surprise_removed(padapter)) {
|
||||
goto out;
|
||||
}
|
||||
x = rtw_read8(padapter, EE_9346CR);
|
||||
|
||||
x &= ~(_EEDO | _EEDI);
|
||||
d = 0;
|
||||
|
||||
for (i = 0; i < 16; i++) {
|
||||
d = d << 1;
|
||||
up_clk(padapter, &x);
|
||||
if (rtw_is_surprise_removed(padapter)) {
|
||||
goto out;
|
||||
}
|
||||
x = rtw_read8(padapter, EE_9346CR);
|
||||
|
||||
x &= ~(_EEDI);
|
||||
if (x & _EEDO)
|
||||
d |= 1;
|
||||
|
||||
down_clk(padapter, &x);
|
||||
}
|
||||
out:
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
void standby(_adapter *padapter)
|
||||
{
|
||||
u8 x;
|
||||
x = rtw_read8(padapter, EE_9346CR);
|
||||
|
||||
x &= ~(_EECS | _EESK);
|
||||
rtw_write8(padapter, EE_9346CR, x);
|
||||
|
||||
rtw_udelay_os(CLOCK_RATE);
|
||||
x |= _EECS;
|
||||
rtw_write8(padapter, EE_9346CR, x);
|
||||
rtw_udelay_os(CLOCK_RATE);
|
||||
}
|
||||
|
||||
u16 wait_eeprom_cmd_done(_adapter *padapter)
|
||||
{
|
||||
u8 x;
|
||||
u16 i, res = _FALSE;
|
||||
standby(padapter);
|
||||
for (i = 0; i < 200; i++) {
|
||||
x = rtw_read8(padapter, EE_9346CR);
|
||||
if (x & _EEDO) {
|
||||
res = _TRUE;
|
||||
goto exit;
|
||||
}
|
||||
rtw_udelay_os(CLOCK_RATE);
|
||||
}
|
||||
exit:
|
||||
return res;
|
||||
}
|
||||
|
||||
void eeprom_clean(_adapter *padapter)
|
||||
{
|
||||
u16 x;
|
||||
if (rtw_is_surprise_removed(padapter)) {
|
||||
goto out;
|
||||
}
|
||||
x = rtw_read8(padapter, EE_9346CR);
|
||||
if (rtw_is_surprise_removed(padapter)) {
|
||||
goto out;
|
||||
}
|
||||
x &= ~(_EECS | _EEDI);
|
||||
rtw_write8(padapter, EE_9346CR, (u8)x);
|
||||
if (rtw_is_surprise_removed(padapter)) {
|
||||
goto out;
|
||||
}
|
||||
up_clk(padapter, &x);
|
||||
if (rtw_is_surprise_removed(padapter)) {
|
||||
goto out;
|
||||
}
|
||||
down_clk(padapter, &x);
|
||||
out:
|
||||
return;
|
||||
}
|
||||
|
||||
void eeprom_write16(_adapter *padapter, u16 reg, u16 data)
|
||||
{
|
||||
u8 x;
|
||||
x = rtw_read8(padapter, EE_9346CR);
|
||||
|
||||
x &= ~(_EEDI | _EEDO | _EESK | _EEM0);
|
||||
x |= _EEM1 | _EECS;
|
||||
rtw_write8(padapter, EE_9346CR, x);
|
||||
|
||||
shift_out_bits(padapter, EEPROM_EWEN_OPCODE, 5);
|
||||
|
||||
if (padapter->EepromAddressSize == 8) /* CF+ and SDIO */
|
||||
shift_out_bits(padapter, 0, 6);
|
||||
else /* USB */
|
||||
shift_out_bits(padapter, 0, 4);
|
||||
|
||||
standby(padapter);
|
||||
|
||||
/* Commented out by rcnjko, 2004.0
|
||||
* Erase this particular word. Write the erase opcode and register
|
||||
* number in that order. The opcode is 3bits in length; reg is 6 bits long. */
|
||||
/* shift_out_bits(Adapter, EEPROM_ERASE_OPCODE, 3);
|
||||
* shift_out_bits(Adapter, reg, Adapter->EepromAddressSize);
|
||||
*
|
||||
* if (wait_eeprom_cmd_done(Adapter ) == FALSE)
|
||||
* {
|
||||
* return;
|
||||
* } */
|
||||
|
||||
|
||||
standby(padapter);
|
||||
|
||||
/* write the new word to the EEPROM */
|
||||
|
||||
/* send the write opcode the EEPORM */
|
||||
shift_out_bits(padapter, EEPROM_WRITE_OPCODE, 3);
|
||||
|
||||
/* select which word in the EEPROM that we are writing to. */
|
||||
shift_out_bits(padapter, reg, padapter->EepromAddressSize);
|
||||
|
||||
/* write the data to the selected EEPROM word. */
|
||||
shift_out_bits(padapter, data, 16);
|
||||
|
||||
if (wait_eeprom_cmd_done(padapter) == _FALSE)
|
||||
|
||||
goto exit;
|
||||
|
||||
standby(padapter);
|
||||
|
||||
shift_out_bits(padapter, EEPROM_EWDS_OPCODE, 5);
|
||||
shift_out_bits(padapter, reg, 4);
|
||||
|
||||
eeprom_clean(padapter);
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
|
||||
u16 eeprom_read16(_adapter *padapter, u16 reg) /* ReadEEprom */
|
||||
{
|
||||
|
||||
u16 x;
|
||||
u16 data = 0;
|
||||
|
||||
if (rtw_is_surprise_removed(padapter)) {
|
||||
goto out;
|
||||
}
|
||||
/* select EEPROM, reset bits, set _EECS */
|
||||
x = rtw_read8(padapter, EE_9346CR);
|
||||
|
||||
if (rtw_is_surprise_removed(padapter)) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
x &= ~(_EEDI | _EEDO | _EESK | _EEM0);
|
||||
x |= _EEM1 | _EECS;
|
||||
rtw_write8(padapter, EE_9346CR, (unsigned char)x);
|
||||
|
||||
/* write the read opcode and register number in that order */
|
||||
/* The opcode is 3bits in length, reg is 6 bits long */
|
||||
shift_out_bits(padapter, EEPROM_READ_OPCODE, 3);
|
||||
shift_out_bits(padapter, reg, padapter->EepromAddressSize);
|
||||
|
||||
/* Now read the data (16 bits) in from the selected EEPROM word */
|
||||
data = shift_in_bits(padapter);
|
||||
|
||||
eeprom_clean(padapter);
|
||||
out:
|
||||
|
||||
return data;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* From even offset */
|
||||
void eeprom_read_sz(_adapter *padapter, u16 reg, u8 *data, u32 sz)
|
||||
{
|
||||
|
||||
u16 x, data16;
|
||||
u32 i;
|
||||
if (rtw_is_surprise_removed(padapter)) {
|
||||
goto out;
|
||||
}
|
||||
/* select EEPROM, reset bits, set _EECS */
|
||||
x = rtw_read8(padapter, EE_9346CR);
|
||||
|
||||
if (rtw_is_surprise_removed(padapter)) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
x &= ~(_EEDI | _EEDO | _EESK | _EEM0);
|
||||
x |= _EEM1 | _EECS;
|
||||
rtw_write8(padapter, EE_9346CR, (unsigned char)x);
|
||||
|
||||
/* write the read opcode and register number in that order */
|
||||
/* The opcode is 3bits in length, reg is 6 bits long */
|
||||
shift_out_bits(padapter, EEPROM_READ_OPCODE, 3);
|
||||
shift_out_bits(padapter, reg, padapter->EepromAddressSize);
|
||||
|
||||
|
||||
for (i = 0; i < sz; i += 2) {
|
||||
data16 = shift_in_bits(padapter);
|
||||
data[i] = data16 & 0xff;
|
||||
data[i + 1] = data16 >> 8;
|
||||
}
|
||||
|
||||
eeprom_clean(padapter);
|
||||
out:
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/* addr_off : address offset of the entry in eeprom (not the tuple number of eeprom (reg); that is addr_off !=reg) */
|
||||
u8 eeprom_read(_adapter *padapter, u32 addr_off, u8 sz, u8 *rbuf)
|
||||
{
|
||||
u8 quotient, remainder, addr_2align_odd;
|
||||
u16 reg, stmp , i = 0, idx = 0;
|
||||
reg = (u16)(addr_off >> 1);
|
||||
addr_2align_odd = (u8)(addr_off & 0x1);
|
||||
|
||||
if (addr_2align_odd) { /* read that start at high part: e.g 1,3,5,7,9,... */
|
||||
stmp = eeprom_read16(padapter, reg);
|
||||
rbuf[idx++] = (u8)((stmp >> 8) & 0xff); /* return hogh-part of the short */
|
||||
reg++;
|
||||
sz--;
|
||||
}
|
||||
|
||||
quotient = sz >> 1;
|
||||
remainder = sz & 0x1;
|
||||
|
||||
for (i = 0 ; i < quotient; i++) {
|
||||
stmp = eeprom_read16(padapter, reg + i);
|
||||
rbuf[idx++] = (u8)(stmp & 0xff);
|
||||
rbuf[idx++] = (u8)((stmp >> 8) & 0xff);
|
||||
}
|
||||
|
||||
reg = reg + i;
|
||||
if (remainder) { /* end of read at lower part of short : 0,2,4,6,... */
|
||||
stmp = eeprom_read16(padapter, reg);
|
||||
rbuf[idx] = (u8)(stmp & 0xff);
|
||||
}
|
||||
return _TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void read_eeprom_content(_adapter *padapter)
|
||||
{
|
||||
|
||||
|
||||
|
||||
}
|
||||
934
drivers/net/wireless/rtl8822cs/core/rtw_ft.c
Normal file
934
drivers/net/wireless/rtl8822cs/core/rtw_ft.c
Normal file
@@ -0,0 +1,934 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright(c) 2007 - 2017 Realtek Corporation.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of version 2 of the GNU General Public License as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#include <drv_types.h>
|
||||
#include <hal_data.h>
|
||||
|
||||
#if defined(CONFIG_IOCTL_CFG80211) && defined(CONFIG_RTW_80211R)
|
||||
|
||||
#ifndef RTW_FT_DBG
|
||||
#define RTW_FT_DBG 0
|
||||
#endif
|
||||
#if RTW_FT_DBG
|
||||
#define RTW_FT_INFO(fmt, arg...) \
|
||||
RTW_INFO(fmt, arg)
|
||||
#define RTW_FT_DUMP(str, data, len) \
|
||||
RTW_INFO_DUMP(str, data, len)
|
||||
#else
|
||||
#define RTW_FT_INFO(fmt, arg...) do {} while (0)
|
||||
#define RTW_FT_DUMP(str, data, len) do {} while (0)
|
||||
#endif
|
||||
|
||||
void rtw_ft_info_init(struct ft_roam_info *pft)
|
||||
{
|
||||
_rtw_memset(pft, 0, sizeof(struct ft_roam_info));
|
||||
pft->ft_flags = 0
|
||||
| RTW_FT_EN
|
||||
| RTW_FT_OTD_EN
|
||||
#ifdef CONFIG_RTW_BTM_ROAM
|
||||
| RTW_FT_BTM_ROAM
|
||||
#endif
|
||||
;
|
||||
pft->ft_updated_bcn = _FALSE;
|
||||
RTW_FT_INFO("%s : ft_flags=0x%02x\n", __func__, pft->ft_flags);
|
||||
}
|
||||
|
||||
ssize_t rtw_ft_proc_flags_set(struct file *file,
|
||||
const char __user *buffer, size_t count, loff_t *pos, void *data)
|
||||
{
|
||||
struct net_device *dev = data;
|
||||
_adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
|
||||
|
||||
char tmp[32];
|
||||
u8 flags;
|
||||
|
||||
if (count < 1)
|
||||
return -EFAULT;
|
||||
|
||||
if (count > sizeof(tmp)) {
|
||||
rtw_warn_on(1);
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
if (buffer && !copy_from_user(tmp, buffer, count)) {
|
||||
int num = sscanf(tmp, "%hhx", &flags);
|
||||
if (num == 1)
|
||||
adapter->mlmepriv.ft_roam.ft_flags = flags;
|
||||
}
|
||||
|
||||
return count;
|
||||
|
||||
}
|
||||
|
||||
int rtw_ft_proc_flags_get(struct seq_file *m, void *v)
|
||||
{
|
||||
struct net_device *dev = m->private;
|
||||
_adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
|
||||
|
||||
RTW_PRINT_SEL(m, "0x%02x\n", adapter->mlmepriv.ft_roam.ft_flags);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
u8 rtw_ft_chk_roaming_candidate(
|
||||
_adapter *padapter, struct wlan_network *competitor)
|
||||
{
|
||||
u8 *pmdie;
|
||||
u32 mdie_len = 0;
|
||||
struct ft_roam_info *pft_roam = &(padapter->mlmepriv.ft_roam);
|
||||
|
||||
if (!(pmdie = rtw_get_ie(&competitor->network.IEs[12], _MDIE_,
|
||||
&mdie_len, competitor->network.IELength-12))) {
|
||||
RTW_INFO("FT : MDIE not foud in competitor!\n");
|
||||
return _FALSE;
|
||||
}
|
||||
|
||||
if (!_rtw_memcmp(&pft_roam->mdid, (pmdie+2), 2)) {
|
||||
RTW_INFO("FT : unmatched MDIE!\n");
|
||||
return _FALSE;
|
||||
}
|
||||
|
||||
/*The candidate don't support over-the-DS*/
|
||||
if (rtw_ft_valid_otd_candidate(padapter, pmdie)) {
|
||||
RTW_INFO("FT: ignore the candidate("
|
||||
MAC_FMT ") for over-the-DS\n",
|
||||
MAC_ARG(competitor->network.MacAddress));
|
||||
/* rtw_ft_clr_flags(padapter, RTW_FT_PEER_OTD_EN); */
|
||||
return _FALSE;
|
||||
}
|
||||
|
||||
if (rtw_ft_chk_flags(padapter, RTW_FT_TEST_RSSI_ROAM)) {
|
||||
if (!_rtw_memcmp(
|
||||
padapter->mlmepriv.cur_network.network.MacAddress,
|
||||
competitor->network.MacAddress, ETH_ALEN) ) {
|
||||
competitor->network.Rssi +=20;
|
||||
RTW_FT_INFO("%s : update "MAC_FMT
|
||||
" RSSI to %d for RTW_FT_TEST_RSSI_ROAM\n",
|
||||
__func__, MAC_ARG(competitor->network.MacAddress),
|
||||
(int)competitor->network.Rssi);
|
||||
rtw_ft_clr_flags(padapter, RTW_FT_TEST_RSSI_ROAM);
|
||||
}
|
||||
}
|
||||
|
||||
return _TRUE;
|
||||
}
|
||||
|
||||
void rtw_ft_update_stainfo(_adapter *padapter, WLAN_BSSID_EX *pnetwork)
|
||||
{
|
||||
struct sta_priv *pstapriv = &padapter->stapriv;
|
||||
struct sta_info *psta = NULL;
|
||||
|
||||
psta = rtw_get_stainfo(pstapriv, pnetwork->MacAddress);
|
||||
if (psta == NULL)
|
||||
psta = rtw_alloc_stainfo(pstapriv, pnetwork->MacAddress);
|
||||
|
||||
if (psta && (padapter->securitypriv.dot11AuthAlgrthm ==
|
||||
dot11AuthAlgrthm_8021X)) {
|
||||
padapter->securitypriv.binstallGrpkey = _FALSE;
|
||||
padapter->securitypriv.busetkipkey = _FALSE;
|
||||
padapter->securitypriv.bgrpkey_handshake = _FALSE;
|
||||
|
||||
psta->ieee8021x_blocked = _TRUE;
|
||||
psta->dot118021XPrivacy = \
|
||||
padapter->securitypriv.dot11PrivacyAlgrthm;
|
||||
_rtw_memset((u8 *)&psta->dot118021x_UncstKey,
|
||||
0, sizeof(union Keytype));
|
||||
_rtw_memset((u8 *)&psta->dot11tkiprxmickey,
|
||||
0, sizeof(union Keytype));
|
||||
_rtw_memset((u8 *)&psta->dot11tkiptxmickey,
|
||||
0, sizeof(union Keytype));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void rtw_ft_reassoc_event_callback(_adapter *padapter, u8 *pbuf)
|
||||
{
|
||||
struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
|
||||
struct stassoc_event *pstassoc = (struct stassoc_event *)pbuf;
|
||||
struct ft_roam_info *pft_roam = &(pmlmepriv->ft_roam);
|
||||
struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
|
||||
struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
|
||||
WLAN_BSSID_EX *pnetwork = (WLAN_BSSID_EX *)&(pmlmeinfo->network);
|
||||
struct cfg80211_ft_event_params ft_evt_parms;
|
||||
_irqL irqL;
|
||||
|
||||
_rtw_memset(&ft_evt_parms, 0, sizeof(ft_evt_parms));
|
||||
rtw_ft_update_stainfo(padapter, pnetwork);
|
||||
ft_evt_parms.ies_len = pft_roam->ft_event.ies_len;
|
||||
ft_evt_parms.ies = rtw_zmalloc(ft_evt_parms.ies_len);
|
||||
if (ft_evt_parms.ies) {
|
||||
_rtw_memcpy((void *)ft_evt_parms.ies,
|
||||
pft_roam->ft_event.ies, ft_evt_parms.ies_len);
|
||||
} else
|
||||
goto err_2;
|
||||
|
||||
ft_evt_parms.target_ap = rtw_zmalloc(ETH_ALEN);
|
||||
if (ft_evt_parms.target_ap) {
|
||||
_rtw_memcpy((void *)ft_evt_parms.target_ap,
|
||||
pstassoc->macaddr, ETH_ALEN);
|
||||
} else
|
||||
goto err_1;
|
||||
|
||||
ft_evt_parms.ric_ies = pft_roam->ft_event.ric_ies;
|
||||
ft_evt_parms.ric_ies_len = pft_roam->ft_event.ric_ies_len;
|
||||
|
||||
/* It's a KERNEL issue between v4.11 ~ v4.16,
|
||||
* <= v4.10, NLMSG_DEFAULT_SIZE is used for nlmsg_new().
|
||||
* v4.11 ~ v4.16, only used "100 + >ric_ies_len" for nlmsg_new()
|
||||
* even then DRIVER don't support RIC.
|
||||
* >= v4.17, issue should correct as "100 + ies_len + ric_ies_len".
|
||||
*/
|
||||
#if ((LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)) && \
|
||||
(LINUX_VERSION_CODE < KERNEL_VERSION(4, 17, 0)))
|
||||
if (!ft_evt_parms.ric_ies_len)
|
||||
ft_evt_parms.ric_ies_len = ft_evt_parms.ies_len;
|
||||
else
|
||||
ft_evt_parms.ric_ies_len += ft_evt_parms.ies_len;
|
||||
#endif
|
||||
|
||||
rtw_ft_lock_set_status(padapter, RTW_FT_AUTHENTICATED_STA, &irqL);
|
||||
rtw_cfg80211_ft_event(padapter, &ft_evt_parms);
|
||||
RTW_INFO("%s: to "MAC_FMT"\n", __func__,
|
||||
MAC_ARG(ft_evt_parms.target_ap));
|
||||
|
||||
rtw_mfree((u8 *)pft_roam->ft_event.target_ap, ETH_ALEN);
|
||||
err_1:
|
||||
rtw_mfree((u8 *)ft_evt_parms.ies, ft_evt_parms.ies_len);
|
||||
err_2:
|
||||
return;
|
||||
}
|
||||
|
||||
void rtw_ft_validate_akm_type(_adapter *padapter,
|
||||
WLAN_BSSID_EX *network)
|
||||
{
|
||||
struct security_priv *psecuritypriv = &(padapter->securitypriv);
|
||||
struct ft_roam_info *pft_roam = &(padapter->mlmepriv.ft_roam);
|
||||
u32 tmp_len;
|
||||
u8 *ptmp;
|
||||
|
||||
/*IEEE802.11-2012 Std. Table 8-101-AKM suite selectors*/
|
||||
if (rtw_ft_valid_akm(padapter, psecuritypriv->rsn_akm_suite_type)) {
|
||||
ptmp = rtw_get_ie(&network->IEs[12],
|
||||
_MDIE_, &tmp_len,
|
||||
(network->IELength-12));
|
||||
if (ptmp) {
|
||||
pft_roam->mdid = *(u16 *)(ptmp+2);
|
||||
pft_roam->ft_cap = *(ptmp+4);
|
||||
|
||||
RTW_INFO("FT: target "MAC_FMT
|
||||
" mdid=(0x%2x), capacity=(0x%2x)\n",
|
||||
MAC_ARG(network->MacAddress),
|
||||
pft_roam->mdid, pft_roam->ft_cap);
|
||||
|
||||
rtw_ft_set_flags(padapter, RTW_FT_PEER_EN);
|
||||
|
||||
RTW_FT_INFO("%s : peer support FTOTA(0x%02x),"
|
||||
" ft_roam_on_expired=0x%02x\n",
|
||||
__func__, pft_roam->ft_flags,
|
||||
pft_roam->ft_roam_on_expired);
|
||||
|
||||
if (rtw_ft_otd_roam_en(padapter)) {
|
||||
rtw_ft_set_flags(padapter, RTW_FT_PEER_OTD_EN);
|
||||
RTW_FT_INFO("%s : peer support FTOTD(0x%02x)\n",
|
||||
__func__, pft_roam->ft_flags);
|
||||
} else {
|
||||
pft_roam->ft_cap &= ~BIT(0);
|
||||
rtw_ft_clr_flags(padapter, RTW_FT_PEER_OTD_EN);
|
||||
RTW_FT_INFO("%s : update mdid=0x%02x, "
|
||||
"cap=0x%02x, flag=0x%02x\n",
|
||||
__func__, pft_roam->mdid,
|
||||
pft_roam->ft_cap,
|
||||
pft_roam->ft_flags);
|
||||
}
|
||||
} else {
|
||||
/* Don't use FT roaming if target AP cannot support FT */
|
||||
rtw_ft_clr_flags(padapter,
|
||||
(RTW_FT_PEER_EN|RTW_FT_PEER_OTD_EN));
|
||||
rtw_ft_reset_status(padapter);
|
||||
}
|
||||
} else {
|
||||
/* It could be a non-FT connection */
|
||||
rtw_ft_clr_flags(padapter,
|
||||
(RTW_FT_PEER_EN|RTW_FT_PEER_OTD_EN));
|
||||
rtw_ft_reset_status(padapter);
|
||||
}
|
||||
|
||||
RTW_FT_INFO("%s : ft_flags=0x%02x\n", __func__, pft_roam->ft_flags);
|
||||
}
|
||||
|
||||
void rtw_ft_update_bcn(_adapter *padapter, union recv_frame *precv_frame)
|
||||
{
|
||||
struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
|
||||
struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
|
||||
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
|
||||
u8 *pframe = precv_frame->u.hdr.rx_data;
|
||||
uint len = precv_frame->u.hdr.len;
|
||||
WLAN_BSSID_EX *pbss;
|
||||
|
||||
if (rtw_ft_chk_status(padapter,RTW_FT_ASSOCIATED_STA)
|
||||
&& (pmlmepriv->ft_roam.ft_updated_bcn == _FALSE)) {
|
||||
pbss = (WLAN_BSSID_EX*)rtw_malloc(sizeof(WLAN_BSSID_EX));
|
||||
if (pbss) {
|
||||
if (collect_bss_info(
|
||||
padapter, precv_frame, pbss) == _SUCCESS) {
|
||||
struct beacon_keys recv_beacon;
|
||||
|
||||
update_network(
|
||||
&(pmlmepriv->cur_network.network),
|
||||
pbss, padapter, _TRUE);
|
||||
|
||||
/* Move into rtw_get_bcn_keys */
|
||||
/* rtw_get_bcn_info(&(pmlmepriv->cur_network)); */
|
||||
|
||||
/* update bcn keys */
|
||||
if (rtw_get_bcn_keys(padapter, pframe, len,
|
||||
&recv_beacon) == _TRUE) {
|
||||
|
||||
RTW_FT_INFO("%s: beacon keys ready\n",
|
||||
__func__);
|
||||
|
||||
_rtw_memcpy(
|
||||
&pmlmepriv->cur_beacon_keys,
|
||||
&recv_beacon,
|
||||
sizeof(recv_beacon));
|
||||
|
||||
if (is_hidden_ssid(
|
||||
recv_beacon.ssid,
|
||||
recv_beacon.ssid_len)) {
|
||||
|
||||
_rtw_memcpy(
|
||||
pmlmepriv->cur_beacon_keys.ssid,
|
||||
pmlmeinfo->network.Ssid.Ssid,
|
||||
IW_ESSID_MAX_SIZE);
|
||||
|
||||
pmlmepriv->cur_beacon_keys.ssid_len = \
|
||||
pmlmeinfo->network.Ssid.SsidLength;
|
||||
}
|
||||
} else {
|
||||
RTW_ERR("%s: get beacon keys failed\n",
|
||||
__func__);
|
||||
_rtw_memset(
|
||||
&pmlmepriv->cur_beacon_keys,
|
||||
0, sizeof(recv_beacon));
|
||||
}
|
||||
#ifdef CONFIG_BCN_CNT_CONFIRM_HDL
|
||||
pmlmepriv->new_beacon_cnts = 0;
|
||||
#endif
|
||||
}
|
||||
rtw_mfree((u8*)pbss, sizeof(WLAN_BSSID_EX));
|
||||
}
|
||||
|
||||
/* check the vendor of the assoc AP */
|
||||
pmlmeinfo->assoc_AP_vendor =
|
||||
check_assoc_AP(
|
||||
pframe + sizeof(struct rtw_ieee80211_hdr_3addr),
|
||||
(len - sizeof(struct rtw_ieee80211_hdr_3addr))
|
||||
);
|
||||
|
||||
rtw_phydm_update_ap_vendor_ie(padapter);
|
||||
|
||||
/* update TSF Value */
|
||||
update_TSF(pmlmeext, pframe, len);
|
||||
pmlmeext->bcn_cnt = 0;
|
||||
pmlmeext->last_bcn_cnt = 0;
|
||||
pmlmepriv->ft_roam.ft_updated_bcn = _TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
void rtw_ft_start_clnt_join(_adapter *padapter)
|
||||
{
|
||||
struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
|
||||
struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
|
||||
struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
|
||||
struct ft_roam_info *pft_roam = &(pmlmepriv->ft_roam);
|
||||
|
||||
if (rtw_ft_otd_roam(padapter)) {
|
||||
pmlmeinfo->state = WIFI_FW_AUTH_SUCCESS | WIFI_FW_STATION_STATE;
|
||||
pft_roam->ft_event.ies =
|
||||
(pft_roam->ft_action + \
|
||||
sizeof(struct rtw_ieee80211_hdr_3addr) + 16);
|
||||
pft_roam->ft_event.ies_len =
|
||||
(pft_roam->ft_action_len - \
|
||||
sizeof(struct rtw_ieee80211_hdr_3addr));
|
||||
|
||||
/*Not support RIC*/
|
||||
pft_roam->ft_event.ric_ies = NULL;
|
||||
pft_roam->ft_event.ric_ies_len = 0;
|
||||
rtw_ft_report_evt(padapter);
|
||||
return;
|
||||
}
|
||||
|
||||
pmlmeinfo->state = WIFI_FW_AUTH_NULL | WIFI_FW_STATION_STATE;
|
||||
start_clnt_auth(padapter);
|
||||
}
|
||||
|
||||
u8 rtw_ft_update_rsnie(
|
||||
_adapter *padapter, u8 bwrite,
|
||||
struct pkt_attrib *pattrib, u8 **pframe)
|
||||
{
|
||||
struct ft_roam_info *pft_roam = &(padapter->mlmepriv.ft_roam);
|
||||
u8 *pie;
|
||||
u32 len;
|
||||
|
||||
pie = rtw_get_ie(pft_roam->updated_ft_ies, EID_WPA2, &len,
|
||||
pft_roam->updated_ft_ies_len);
|
||||
|
||||
if (!bwrite)
|
||||
return (pie)?_SUCCESS:_FAIL;
|
||||
|
||||
if (pie) {
|
||||
*pframe = rtw_set_ie(((u8 *)*pframe), EID_WPA2, len,
|
||||
pie+2, &(pattrib->pktlen));
|
||||
} else
|
||||
return _FAIL;
|
||||
|
||||
return _SUCCESS;
|
||||
}
|
||||
|
||||
static u8 rtw_ft_update_mdie(
|
||||
_adapter *padapter, struct pkt_attrib *pattrib, u8 **pframe)
|
||||
{
|
||||
struct ft_roam_info *pft_roam = &(padapter->mlmepriv.ft_roam);
|
||||
u8 *pie, mdie[3];
|
||||
u32 len = 3;
|
||||
|
||||
if (rtw_ft_roam(padapter)) {
|
||||
if ((pie = rtw_get_ie(pft_roam->updated_ft_ies, _MDIE_,
|
||||
&len, pft_roam->updated_ft_ies_len))) {
|
||||
pie = (pie + 2); /* ignore md-id & length */
|
||||
} else
|
||||
return _FAIL;
|
||||
} else {
|
||||
*((u16 *)&mdie[0]) = pft_roam->mdid;
|
||||
mdie[2] = pft_roam->ft_cap;
|
||||
pie = &mdie[0];
|
||||
}
|
||||
|
||||
*pframe = rtw_set_ie(((u8 *)*pframe), _MDIE_,
|
||||
len , pie, &(pattrib->pktlen));
|
||||
return _SUCCESS;
|
||||
}
|
||||
|
||||
static u8 rtw_ft_update_ftie(
|
||||
_adapter *padapter, struct pkt_attrib *pattrib, u8 **pframe)
|
||||
{
|
||||
struct ft_roam_info *pft_roam = &(padapter->mlmepriv.ft_roam);
|
||||
u8 *pie;
|
||||
u32 len;
|
||||
|
||||
if ((pie = rtw_get_ie(pft_roam->updated_ft_ies, _FTIE_, &len,
|
||||
pft_roam->updated_ft_ies_len)) != NULL) {
|
||||
*pframe = rtw_set_ie(*pframe, _FTIE_, len ,
|
||||
(pie+2), &(pattrib->pktlen));
|
||||
} else
|
||||
return _FAIL;
|
||||
|
||||
return _SUCCESS;
|
||||
}
|
||||
|
||||
void rtw_ft_build_auth_req_ies(_adapter *padapter,
|
||||
struct pkt_attrib *pattrib, u8 **pframe)
|
||||
{
|
||||
u8 ftie_append = _TRUE;
|
||||
|
||||
if (!pattrib || !(*pframe))
|
||||
return;
|
||||
|
||||
if (!rtw_ft_roam(padapter))
|
||||
return;
|
||||
|
||||
ftie_append = rtw_ft_update_rsnie(padapter, _TRUE, pattrib, pframe);
|
||||
rtw_ft_update_mdie(padapter, pattrib, pframe);
|
||||
if (ftie_append)
|
||||
rtw_ft_update_ftie(padapter, pattrib, pframe);
|
||||
}
|
||||
|
||||
void rtw_ft_build_assoc_req_ies(_adapter *padapter,
|
||||
u8 is_reassoc, struct pkt_attrib *pattrib, u8 **pframe)
|
||||
{
|
||||
if (!pattrib || !(*pframe))
|
||||
return;
|
||||
|
||||
if (rtw_ft_chk_flags(padapter, RTW_FT_PEER_EN))
|
||||
rtw_ft_update_mdie(padapter, pattrib, pframe);
|
||||
|
||||
if ((!is_reassoc) || (!rtw_ft_roam(padapter)))
|
||||
return;
|
||||
|
||||
if (rtw_ft_update_rsnie(padapter, _FALSE, pattrib, pframe))
|
||||
rtw_ft_update_ftie(padapter, pattrib, pframe);
|
||||
}
|
||||
|
||||
u8 rtw_ft_update_auth_rsp_ies(_adapter *padapter, u8 *pframe, u32 len)
|
||||
{
|
||||
u8 ret = _SUCCESS;
|
||||
u8 target_ap_addr[ETH_ALEN] = {0};
|
||||
struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
|
||||
struct ft_roam_info *pft_roam = &(pmlmepriv->ft_roam);
|
||||
|
||||
if (!rtw_ft_roam(padapter))
|
||||
return _FAIL;
|
||||
|
||||
/*rtw_ft_report_reassoc_evt already,
|
||||
* and waiting for cfg80211_rtw_update_ft_ies */
|
||||
if (rtw_ft_authed_sta(padapter))
|
||||
return ret;
|
||||
|
||||
if (!pframe || !len)
|
||||
return _FAIL;
|
||||
|
||||
rtw_buf_update(&pmlmepriv->auth_rsp,
|
||||
&pmlmepriv->auth_rsp_len, pframe, len);
|
||||
pft_roam->ft_event.ies =
|
||||
(pmlmepriv->auth_rsp + \
|
||||
sizeof(struct rtw_ieee80211_hdr_3addr) + 6);
|
||||
pft_roam->ft_event.ies_len =
|
||||
(pmlmepriv->auth_rsp_len - \
|
||||
sizeof(struct rtw_ieee80211_hdr_3addr) - 6);
|
||||
|
||||
/*Not support RIC*/
|
||||
pft_roam->ft_event.ric_ies = NULL;
|
||||
pft_roam->ft_event.ric_ies_len = 0;
|
||||
_rtw_memcpy(target_ap_addr, pmlmepriv->assoc_bssid, ETH_ALEN);
|
||||
rtw_ft_report_reassoc_evt(padapter, target_ap_addr);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void rtw_ft_start_clnt_action(_adapter *padapter, u8 *pTargetAddr)
|
||||
{
|
||||
struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
|
||||
|
||||
rtw_ft_set_status(padapter, RTW_FT_REQUESTING_STA);
|
||||
rtw_ft_issue_action_req(padapter, pTargetAddr);
|
||||
_set_timer(&pmlmeext->ft_link_timer, REASSOC_TO);
|
||||
}
|
||||
|
||||
void rtw_ft_start_roam(_adapter *padapter, u8 *pTargetAddr)
|
||||
{
|
||||
struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
|
||||
|
||||
if (rtw_ft_otd_roam(padapter)) {
|
||||
RTW_FT_INFO("%s : try OTD roaming\n", __func__);
|
||||
rtw_ft_start_clnt_action(padapter, pTargetAddr);
|
||||
} else {
|
||||
/* wait a little time to retrieve packets buffered
|
||||
in the current ap while scan*/
|
||||
RTW_FT_INFO("%s : start roaming timer\n", __func__);
|
||||
_set_timer(&pmlmeext->ft_roam_timer, 30);
|
||||
}
|
||||
}
|
||||
|
||||
void rtw_ft_issue_action_req(_adapter *padapter, u8 *pTargetAddr)
|
||||
{
|
||||
struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
|
||||
struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
|
||||
struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
|
||||
struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
|
||||
struct xmit_frame *pmgntframe;
|
||||
struct rtw_ieee80211_hdr *pwlanhdr;
|
||||
struct pkt_attrib *pattrib;
|
||||
u8 *pframe;
|
||||
u8 category = RTW_WLAN_CATEGORY_FT;
|
||||
u8 action = RTW_WLAN_ACTION_FT_REQ;
|
||||
|
||||
pmgntframe = alloc_mgtxmitframe(pxmitpriv);
|
||||
if (pmgntframe == NULL)
|
||||
return;
|
||||
|
||||
pattrib = &pmgntframe->attrib;
|
||||
update_mgntframe_attrib(padapter, pattrib);
|
||||
_rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
|
||||
|
||||
pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
|
||||
pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
|
||||
pwlanhdr->frame_ctl = 0;
|
||||
|
||||
_rtw_memcpy(pwlanhdr->addr1,
|
||||
get_my_bssid(&pmlmeinfo->network), ETH_ALEN);
|
||||
_rtw_memcpy(pwlanhdr->addr2, adapter_mac_addr(padapter), ETH_ALEN);
|
||||
_rtw_memcpy(pwlanhdr->addr3,
|
||||
get_my_bssid(&pmlmeinfo->network), ETH_ALEN);
|
||||
|
||||
SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
|
||||
pmlmeext->mgnt_seq++;
|
||||
set_frame_sub_type(pframe, WIFI_ACTION);
|
||||
|
||||
pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
|
||||
pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
|
||||
|
||||
pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
|
||||
pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
|
||||
|
||||
_rtw_memcpy(pframe, adapter_mac_addr(padapter), ETH_ALEN);
|
||||
pframe += ETH_ALEN;
|
||||
pattrib->pktlen += ETH_ALEN;
|
||||
|
||||
_rtw_memcpy(pframe, pTargetAddr, ETH_ALEN);
|
||||
pframe += ETH_ALEN;
|
||||
pattrib->pktlen += ETH_ALEN;
|
||||
|
||||
rtw_ft_update_mdie(padapter, pattrib, &pframe);
|
||||
if (rtw_ft_update_rsnie(padapter, _TRUE, pattrib, &pframe))
|
||||
rtw_ft_update_ftie(padapter, pattrib, &pframe);
|
||||
|
||||
RTW_INFO("FT : issue RTW_WLAN_ACTION_FT_REQ\n");
|
||||
pattrib->last_txcmdsz = pattrib->pktlen;
|
||||
dump_mgntframe(padapter, pmgntframe);
|
||||
}
|
||||
|
||||
void rtw_ft_report_evt(_adapter *padapter)
|
||||
{
|
||||
struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
|
||||
struct ft_roam_info *pft_roam = &(pmlmepriv->ft_roam);
|
||||
struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
|
||||
struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
|
||||
WLAN_BSSID_EX *pnetwork = (WLAN_BSSID_EX *)&(pmlmeinfo->network);
|
||||
struct cfg80211_ft_event_params ft_evt_parms;
|
||||
_irqL irqL;
|
||||
|
||||
_rtw_memset(&ft_evt_parms, 0, sizeof(ft_evt_parms));
|
||||
rtw_ft_update_stainfo(padapter, pnetwork);
|
||||
|
||||
if (!pnetwork)
|
||||
goto err_2;
|
||||
|
||||
ft_evt_parms.ies_len = pft_roam->ft_event.ies_len;
|
||||
ft_evt_parms.ies = rtw_zmalloc(ft_evt_parms.ies_len);
|
||||
if (ft_evt_parms.ies) {
|
||||
_rtw_memcpy((void *)ft_evt_parms.ies,
|
||||
pft_roam->ft_event.ies, ft_evt_parms.ies_len);
|
||||
} else
|
||||
goto err_2;
|
||||
|
||||
ft_evt_parms.target_ap = rtw_zmalloc(ETH_ALEN);
|
||||
if (ft_evt_parms.target_ap) {
|
||||
_rtw_memcpy((void *)ft_evt_parms.target_ap,
|
||||
pnetwork->MacAddress, ETH_ALEN);
|
||||
} else
|
||||
goto err_1;
|
||||
|
||||
ft_evt_parms.ric_ies = pft_roam->ft_event.ric_ies;
|
||||
ft_evt_parms.ric_ies_len = pft_roam->ft_event.ric_ies_len;
|
||||
|
||||
/* It's a KERNEL issue between v4.11 ~ v4.16,
|
||||
* <= v4.10, NLMSG_DEFAULT_SIZE is used for nlmsg_new().
|
||||
* v4.11 ~ v4.16, only used "100 + >ric_ies_len" for nlmsg_new()
|
||||
* even then DRIVER don't support RIC.
|
||||
* >= v4.17, issue should correct as "100 + ies_len + ric_ies_len".
|
||||
*/
|
||||
#if ((LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)) && \
|
||||
(LINUX_VERSION_CODE < KERNEL_VERSION(4, 17, 0)))
|
||||
ft_evt_parms.ric_ies_len = (ft_evt_parms.ies_len <= 100 )?
|
||||
(0):(ft_evt_parms.ies_len - 100);
|
||||
#endif
|
||||
|
||||
rtw_ft_lock_set_status(padapter, RTW_FT_AUTHENTICATED_STA, &irqL);
|
||||
rtw_cfg80211_ft_event(padapter, &ft_evt_parms);
|
||||
RTW_INFO("FT: rtw_ft_report_evt\n");
|
||||
rtw_mfree((u8 *)pft_roam->ft_event.target_ap, ETH_ALEN);
|
||||
err_1:
|
||||
rtw_mfree((u8 *)ft_evt_parms.ies, ft_evt_parms.ies_len);
|
||||
err_2:
|
||||
return;
|
||||
}
|
||||
|
||||
void rtw_ft_report_reassoc_evt(_adapter *padapter, u8 *pMacAddr)
|
||||
{
|
||||
struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
|
||||
struct cmd_priv *pcmdpriv = &(padapter->cmdpriv);
|
||||
struct cmd_obj *pcmd_obj = NULL;
|
||||
struct stassoc_event *passoc_sta_evt = NULL;
|
||||
struct rtw_evt_header *evt_hdr = NULL;
|
||||
u8 *pevtcmd = NULL;
|
||||
u32 cmdsz = 0;
|
||||
|
||||
pcmd_obj = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
|
||||
if (pcmd_obj == NULL)
|
||||
return;
|
||||
|
||||
cmdsz = (sizeof(struct stassoc_event) + sizeof(struct rtw_evt_header));
|
||||
pevtcmd = (u8 *)rtw_zmalloc(cmdsz);
|
||||
if (pevtcmd == NULL) {
|
||||
rtw_mfree((u8 *)pcmd_obj, sizeof(struct cmd_obj));
|
||||
return;
|
||||
}
|
||||
|
||||
_rtw_init_listhead(&pcmd_obj->list);
|
||||
pcmd_obj->cmdcode = CMD_SET_MLME_EVT;
|
||||
pcmd_obj->cmdsz = cmdsz;
|
||||
pcmd_obj->parmbuf = pevtcmd;
|
||||
pcmd_obj->rsp = NULL;
|
||||
pcmd_obj->rspsz = 0;
|
||||
|
||||
evt_hdr = (struct rtw_evt_header *)(pevtcmd);
|
||||
evt_hdr->len = sizeof(struct stassoc_event);
|
||||
evt_hdr->id = EVT_FT_REASSOC;
|
||||
evt_hdr->seq = ATOMIC_INC_RETURN(&pmlmeext->event_seq);
|
||||
|
||||
passoc_sta_evt = \
|
||||
(struct stassoc_event *)(pevtcmd + \
|
||||
sizeof(struct rtw_evt_header));
|
||||
_rtw_memcpy((unsigned char *)(&(passoc_sta_evt->macaddr)),
|
||||
pMacAddr, ETH_ALEN);
|
||||
rtw_enqueue_cmd(pcmdpriv, pcmd_obj);
|
||||
}
|
||||
|
||||
void rtw_ft_link_timer_hdl(void *ctx)
|
||||
{
|
||||
_adapter *padapter = (_adapter *)ctx;
|
||||
struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
|
||||
struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
|
||||
struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
|
||||
struct ft_roam_info *pft_roam = &(pmlmepriv->ft_roam);
|
||||
|
||||
if (rtw_ft_chk_status(padapter, RTW_FT_REQUESTING_STA)) {
|
||||
if (pft_roam->ft_req_retry_cnt < RTW_FT_ACTION_REQ_LMT) {
|
||||
pft_roam->ft_req_retry_cnt++;
|
||||
rtw_ft_issue_action_req(padapter,
|
||||
(u8 *)pmlmepriv->roam_network->network.MacAddress);
|
||||
_set_timer(&pmlmeext->ft_link_timer, REASSOC_TO);
|
||||
} else {
|
||||
pft_roam->ft_req_retry_cnt = 0;
|
||||
if (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) {
|
||||
rtw_ft_set_status(padapter,
|
||||
RTW_FT_ASSOCIATED_STA);
|
||||
} else
|
||||
rtw_ft_reset_status(padapter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void rtw_ft_roam_timer_hdl(void *ctx)
|
||||
{
|
||||
_adapter *padapter = (_adapter *)ctx;
|
||||
struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
|
||||
|
||||
RTW_FT_INFO("%s : try roaming\n", __func__);
|
||||
receive_disconnect(padapter,
|
||||
pmlmepriv->cur_network.network.MacAddress,
|
||||
WLAN_REASON_ACTIVE_ROAM, _FALSE);
|
||||
}
|
||||
|
||||
void rtw_ft_roam_status_reset(_adapter *padapter)
|
||||
{
|
||||
struct ft_roam_info *pft_roam = &(padapter->mlmepriv.ft_roam);
|
||||
|
||||
if ((rtw_to_roam(padapter) > 0) &&
|
||||
(!rtw_ft_chk_status(padapter, RTW_FT_REQUESTED_STA))) {
|
||||
rtw_ft_reset_status(padapter);
|
||||
}
|
||||
|
||||
padapter->mlmepriv.ft_roam.ft_updated_bcn = _FALSE;
|
||||
}
|
||||
|
||||
void rtw_ft_peer_info_init(struct sta_info *psta)
|
||||
{
|
||||
struct rtw_sta_ft_info_t *peer = &(psta->ft_peer);
|
||||
_rtw_memset(peer, 0, sizeof(struct rtw_sta_ft_info_t));
|
||||
}
|
||||
|
||||
void rtw_ft_peer_info_free(struct sta_info *psta)
|
||||
{
|
||||
struct rtw_sta_ft_info_t *peer = &(psta->ft_peer);
|
||||
|
||||
rtw_buf_free(&peer->md_ie, &peer->md_len);
|
||||
rtw_buf_free(&peer->rsn_ie, &peer->rsn_len);
|
||||
rtw_buf_free(&peer->ft_ie, &peer->ft_len);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_RTW_80211R_AP
|
||||
int rtw_ft_update_sta_ies(_adapter *padapter,
|
||||
struct cfg80211_update_ft_ies_params *ie)
|
||||
{
|
||||
struct security_priv *psecuritypriv = &(padapter->securitypriv);
|
||||
struct sta_priv *pstapriv = &(padapter->stapriv);
|
||||
struct sta_info *psta;
|
||||
struct rtw_sta_ft_info_t *peer_info;
|
||||
u8 *ptr, *paddr;
|
||||
u32 len;
|
||||
int ret = 0;
|
||||
|
||||
if (!CHECK_BIT(WLAN_AKM_TYPE_FT_PSK, psecuritypriv->akmp)
|
||||
&& !CHECK_BIT(WLAN_AKM_TYPE_FT_8021X, psecuritypriv->akmp)
|
||||
&& !CHECK_BIT(WLAN_AKM_TYPE_FT_OVER_SAE, psecuritypriv->akmp)) {
|
||||
RTW_FT_INFO("%s : AKM=0x%x\n", __func__, psecuritypriv->akmp);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if ((ie->ie_len == 0) ||
|
||||
(ie->ie_len >= RTW_FT_MAX_IE_SZ)) {
|
||||
ret = - EINVAL;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if ((ptr = rtw_get_ie(ie->ie, WLAN_EID_VENDOR_SPECIFIC,
|
||||
&len , ie->ie_len)) == NULL) {
|
||||
RTW_ERR("FT : no station mac address found in ies\n");
|
||||
ret = -EINVAL;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (len != ETH_ALEN) {
|
||||
RTW_ERR("FT : invalid station mac length(%u)\n", len);
|
||||
ret = -EINVAL;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
paddr = ptr + 2;
|
||||
if ((psta = rtw_get_stainfo(pstapriv, paddr)) == NULL) {
|
||||
RTW_ERR("FT : sta "MAC_FMT" not found!\n", MAC_ARG(paddr));
|
||||
ret = -EINVAL;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
RTW_FT_INFO("%s : update sta "MAC_FMT" ie, len=%lu\n",
|
||||
__func__, MAC_ARG(paddr), ie->ie_len);
|
||||
RTW_FT_DUMP("ie = ", ie->ie, ie->ie_len);
|
||||
|
||||
peer_info = &(psta->ft_peer);
|
||||
if ((ptr = rtw_get_ie(ie->ie, EID_WPA2, &len , ie->ie_len)) != NULL) {
|
||||
rtw_buf_update(&peer_info->rsn_ie,
|
||||
&peer_info->rsn_len, ptr + 2, len);
|
||||
RTW_FT_DUMP("rsn_ie = ", peer_info->rsn_ie,
|
||||
peer_info->rsn_len);
|
||||
}
|
||||
|
||||
if ((ptr = rtw_get_ie(ie->ie, _MDIE_, &len , ie->ie_len)) != NULL) {
|
||||
rtw_buf_update(&peer_info->md_ie,
|
||||
&peer_info->md_len, ptr + 2, len);
|
||||
RTW_FT_DUMP("md_ie = ",
|
||||
peer_info->md_ie, peer_info->md_len);
|
||||
}
|
||||
|
||||
if ((ptr = rtw_get_ie(ie->ie, _FTIE_, &len , ie->ie_len)) != NULL) {
|
||||
rtw_buf_update(&peer_info->ft_ie,
|
||||
&peer_info->ft_len, ptr + 2, len);
|
||||
RTW_FT_DUMP("ft_ie = ",
|
||||
peer_info->ft_ie, peer_info->ft_len);
|
||||
}
|
||||
|
||||
if (psta->authalg == WLAN_AUTH_FT)
|
||||
issue_asocrsp(padapter, 0, psta, WIFI_REASSOCRSP);
|
||||
exit:
|
||||
return ret;
|
||||
}
|
||||
|
||||
void rtw_ft_update_assocresp_ies(struct net_device *net,
|
||||
struct cfg80211_ap_settings *settings)
|
||||
{
|
||||
_adapter *padapter = (_adapter *)rtw_netdev_priv(net);
|
||||
struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
|
||||
struct ft_roam_info *pinfo = &(pmlmepriv->ft_roam);
|
||||
u8 *ie, *bcn_tail_ies, *assocrsp_ies;
|
||||
int ielen, bcn_tail_len, assocrsp_ies_len, ret = 0;
|
||||
|
||||
bcn_tail_ies = (u8 *)settings->beacon.tail;
|
||||
bcn_tail_len = (u32)settings->beacon.tail_len;
|
||||
assocrsp_ies = (u8 *)settings->beacon.assocresp_ies;
|
||||
assocrsp_ies_len = (u32)settings->beacon.assocresp_ies_len;
|
||||
|
||||
if ((bcn_tail_len > 0) &&
|
||||
((ie = rtw_get_ie(bcn_tail_ies, _MDIE_,
|
||||
&ielen , bcn_tail_len)) != NULL)) {
|
||||
pinfo->mdid = *(u16 *)(ie + 2);
|
||||
pinfo->ft_cap = *(ie + 4);
|
||||
RTW_FT_INFO("%s : mdid = 0x%04x, cap=0x%02x\n",
|
||||
__func__, pinfo->mdid, pinfo->ft_cap);
|
||||
}
|
||||
|
||||
if ((assocrsp_ies_len > 0) &&
|
||||
((ie = rtw_get_ie(assocrsp_ies, _FTIE_,
|
||||
&ielen , assocrsp_ies_len)) != NULL)) {
|
||||
_rtw_memset(pinfo->updated_ft_ies, 0, RTW_FT_MAX_IE_SZ);
|
||||
_rtw_memcpy(pinfo->updated_ft_ies, ie + 2, ielen);
|
||||
pinfo->updated_ft_ies_len = ielen;
|
||||
RTW_FT_DUMP("FT : ft ie = ", ie + 2, ielen);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void rtw_ft_process_ft_auth_rsp(_adapter *padapter, u8 *pframe, u32 len)
|
||||
{
|
||||
struct sta_priv *pstapriv = &(padapter->stapriv);
|
||||
struct sta_info *psta = NULL;
|
||||
_irqL irqL;
|
||||
/* u8 *ptr; */
|
||||
/* u32 plen; */
|
||||
|
||||
/* ptr = pframe + IEEE80211_3ADDR_LEN + _AUTH_IE_OFFSET_; */
|
||||
/* plen = len - IEEE80211_3ADDR_LEN - _AUTH_IE_OFFSET_; */
|
||||
|
||||
psta = rtw_get_stainfo(pstapriv, GetAddr1Ptr(pframe));
|
||||
if (psta) {
|
||||
_enter_critical_bh(&psta->lock, &irqL);
|
||||
psta->state &= ~WIFI_FW_AUTH_NULL;
|
||||
psta->state |= WIFI_FW_AUTH_SUCCESS;
|
||||
psta->expire_to = pstapriv->assoc_to;
|
||||
_exit_critical_bh(&psta->lock, &irqL);
|
||||
}
|
||||
}
|
||||
|
||||
void rtw_ft_build_assoc_rsp_ies(_adapter *padapter,
|
||||
struct sta_info *psta, struct pkt_attrib *pattrib, u8 **pframe)
|
||||
{
|
||||
struct ft_roam_info *prinfo = &(padapter->mlmepriv.ft_roam);
|
||||
struct rtw_sta_ft_info_t *peer_info;
|
||||
u8 *pie, mdie[3] = {0};
|
||||
u32 ielen;
|
||||
|
||||
if (psta == NULL)
|
||||
return;
|
||||
|
||||
if (psta->authalg != WLAN_AUTH_FT) {
|
||||
*((u16 *)&mdie[0]) = prinfo->mdid;
|
||||
mdie[2] = prinfo->ft_cap;
|
||||
pie = mdie;
|
||||
ielen = 3;
|
||||
|
||||
if (prinfo->mdid > 0) {
|
||||
*pframe = rtw_set_ie(((u8 *)*pframe),
|
||||
_MDIE_, ielen , pie, &(pattrib->pktlen));
|
||||
}
|
||||
|
||||
if (prinfo->updated_ft_ies_len > 0) {
|
||||
*pframe = rtw_set_ie(((u8 *)*pframe),
|
||||
_FTIE_, prinfo->updated_ft_ies_len,
|
||||
prinfo->updated_ft_ies, &(pattrib->pktlen));
|
||||
}
|
||||
} else {
|
||||
peer_info = &(psta->ft_peer);
|
||||
if (peer_info->rsn_len > 0) {
|
||||
*pframe = rtw_set_ie(((u8 *)*pframe), EID_WPA2,
|
||||
peer_info->rsn_len, peer_info->rsn_ie,
|
||||
&(pattrib->pktlen));
|
||||
}
|
||||
|
||||
if (peer_info->md_len > 0) {
|
||||
*pframe = rtw_set_ie(((u8 *)*pframe), _MDIE_,
|
||||
peer_info->md_len, peer_info->md_ie,
|
||||
&(pattrib->pktlen));
|
||||
}
|
||||
|
||||
if (peer_info->ft_len > 0) {
|
||||
*pframe = rtw_set_ie(((u8 *)*pframe), _FTIE_,
|
||||
peer_info->ft_len, peer_info->ft_ie,
|
||||
&(pattrib->pktlen));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
#endif /* CONFIG_RTW_80211R_AP */
|
||||
#endif /* CONFIG_IOCTL_CFG80211 && CONFIG_RTW_80211R */
|
||||
3429
drivers/net/wireless/rtl8822cs/core/rtw_ieee80211.c
Normal file
3429
drivers/net/wireless/rtl8822cs/core/rtw_ieee80211.c
Normal file
File diff suppressed because it is too large
Load Diff
958
drivers/net/wireless/rtl8822cs/core/rtw_io.c
Normal file
958
drivers/net/wireless/rtl8822cs/core/rtw_io.c
Normal file
@@ -0,0 +1,958 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright(c) 2007 - 2017 Realtek Corporation.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of version 2 of the GNU General Public License as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
|
||||
The purpose of rtw_io.c
|
||||
|
||||
a. provides the API
|
||||
|
||||
b. provides the protocol engine
|
||||
|
||||
c. provides the software interface between caller and the hardware interface
|
||||
|
||||
|
||||
Compiler Flag Option:
|
||||
|
||||
1. CONFIG_SDIO_HCI:
|
||||
a. USE_SYNC_IRP: Only sync operations are provided.
|
||||
b. USE_ASYNC_IRP:Both sync/async operations are provided.
|
||||
|
||||
2. CONFIG_USB_HCI:
|
||||
a. USE_ASYNC_IRP: Both sync/async operations are provided.
|
||||
|
||||
3. CONFIG_CFIO_HCI:
|
||||
b. USE_SYNC_IRP: Only sync operations are provided.
|
||||
|
||||
|
||||
Only sync read/rtw_write_mem operations are provided.
|
||||
|
||||
jackson@realtek.com.tw
|
||||
|
||||
*/
|
||||
|
||||
#define _RTW_IO_C_
|
||||
|
||||
#include <drv_types.h>
|
||||
#include <hal_data.h>
|
||||
|
||||
#if defined(CONFIG_SDIO_HCI) || defined(CONFIG_PLATFORM_RTL8197D)
|
||||
#define rtw_le16_to_cpu(val) val
|
||||
#define rtw_le32_to_cpu(val) val
|
||||
#define rtw_cpu_to_le16(val) val
|
||||
#define rtw_cpu_to_le32(val) val
|
||||
#else
|
||||
#define rtw_le16_to_cpu(val) le16_to_cpu(val)
|
||||
#define rtw_le32_to_cpu(val) le32_to_cpu(val)
|
||||
#define rtw_cpu_to_le16(val) cpu_to_le16(val)
|
||||
#define rtw_cpu_to_le32(val) cpu_to_le32(val)
|
||||
#endif
|
||||
|
||||
|
||||
u8 _rtw_read8(_adapter *adapter, u32 addr)
|
||||
{
|
||||
u8 r_val;
|
||||
/* struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue; */
|
||||
struct io_priv *pio_priv = &adapter->iopriv;
|
||||
struct intf_hdl *pintfhdl = &(pio_priv->intf);
|
||||
u8(*_read8)(struct intf_hdl *pintfhdl, u32 addr);
|
||||
_read8 = pintfhdl->io_ops._read8;
|
||||
|
||||
r_val = _read8(pintfhdl, addr);
|
||||
return r_val;
|
||||
}
|
||||
|
||||
u16 _rtw_read16(_adapter *adapter, u32 addr)
|
||||
{
|
||||
u16 r_val;
|
||||
/* struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue; */
|
||||
struct io_priv *pio_priv = &adapter->iopriv;
|
||||
struct intf_hdl *pintfhdl = &(pio_priv->intf);
|
||||
u16(*_read16)(struct intf_hdl *pintfhdl, u32 addr);
|
||||
_read16 = pintfhdl->io_ops._read16;
|
||||
|
||||
r_val = _read16(pintfhdl, addr);
|
||||
return rtw_le16_to_cpu(r_val);
|
||||
}
|
||||
|
||||
u32 _rtw_read32(_adapter *adapter, u32 addr)
|
||||
{
|
||||
u32 r_val;
|
||||
/* struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue; */
|
||||
struct io_priv *pio_priv = &adapter->iopriv;
|
||||
struct intf_hdl *pintfhdl = &(pio_priv->intf);
|
||||
u32(*_read32)(struct intf_hdl *pintfhdl, u32 addr);
|
||||
_read32 = pintfhdl->io_ops._read32;
|
||||
|
||||
r_val = _read32(pintfhdl, addr);
|
||||
return rtw_le32_to_cpu(r_val);
|
||||
|
||||
}
|
||||
|
||||
int _rtw_write8(_adapter *adapter, u32 addr, u8 val)
|
||||
{
|
||||
/* struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue; */
|
||||
struct io_priv *pio_priv = &adapter->iopriv;
|
||||
struct intf_hdl *pintfhdl = &(pio_priv->intf);
|
||||
int (*_write8)(struct intf_hdl *pintfhdl, u32 addr, u8 val);
|
||||
int ret;
|
||||
_write8 = pintfhdl->io_ops._write8;
|
||||
|
||||
ret = _write8(pintfhdl, addr, val);
|
||||
|
||||
return RTW_STATUS_CODE(ret);
|
||||
}
|
||||
int _rtw_write16(_adapter *adapter, u32 addr, u16 val)
|
||||
{
|
||||
/* struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue; */
|
||||
struct io_priv *pio_priv = &adapter->iopriv;
|
||||
struct intf_hdl *pintfhdl = &(pio_priv->intf);
|
||||
int (*_write16)(struct intf_hdl *pintfhdl, u32 addr, u16 val);
|
||||
int ret;
|
||||
_write16 = pintfhdl->io_ops._write16;
|
||||
|
||||
val = rtw_cpu_to_le16(val);
|
||||
ret = _write16(pintfhdl, addr, val);
|
||||
|
||||
return RTW_STATUS_CODE(ret);
|
||||
}
|
||||
int _rtw_write32(_adapter *adapter, u32 addr, u32 val)
|
||||
{
|
||||
/* struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue; */
|
||||
struct io_priv *pio_priv = &adapter->iopriv;
|
||||
struct intf_hdl *pintfhdl = &(pio_priv->intf);
|
||||
int (*_write32)(struct intf_hdl *pintfhdl, u32 addr, u32 val);
|
||||
int ret;
|
||||
_write32 = pintfhdl->io_ops._write32;
|
||||
|
||||
val = rtw_cpu_to_le32(val);
|
||||
ret = _write32(pintfhdl, addr, val);
|
||||
|
||||
return RTW_STATUS_CODE(ret);
|
||||
}
|
||||
|
||||
int _rtw_writeN(_adapter *adapter, u32 addr , u32 length , u8 *pdata)
|
||||
{
|
||||
/* struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue; */
|
||||
struct io_priv *pio_priv = &adapter->iopriv;
|
||||
struct intf_hdl *pintfhdl = (struct intf_hdl *)(&(pio_priv->intf));
|
||||
int (*_writeN)(struct intf_hdl *pintfhdl, u32 addr, u32 length, u8 *pdata);
|
||||
int ret;
|
||||
_writeN = pintfhdl->io_ops._writeN;
|
||||
|
||||
ret = _writeN(pintfhdl, addr, length, pdata);
|
||||
|
||||
return RTW_STATUS_CODE(ret);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_SDIO_HCI
|
||||
u8 _rtw_sd_f0_read8(_adapter *adapter, u32 addr)
|
||||
{
|
||||
u8 r_val = 0x00;
|
||||
struct io_priv *pio_priv = &adapter->iopriv;
|
||||
struct intf_hdl *pintfhdl = &(pio_priv->intf);
|
||||
u8(*_sd_f0_read8)(struct intf_hdl *pintfhdl, u32 addr);
|
||||
|
||||
_sd_f0_read8 = pintfhdl->io_ops._sd_f0_read8;
|
||||
|
||||
if (_sd_f0_read8)
|
||||
r_val = _sd_f0_read8(pintfhdl, addr);
|
||||
else
|
||||
RTW_WARN(FUNC_ADPT_FMT" _sd_f0_read8 callback is NULL\n", FUNC_ADPT_ARG(adapter));
|
||||
|
||||
return r_val;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_SDIO_INDIRECT_ACCESS
|
||||
u8 _rtw_sd_iread8(_adapter *adapter, u32 addr)
|
||||
{
|
||||
u8 r_val = 0x00;
|
||||
struct io_priv *pio_priv = &adapter->iopriv;
|
||||
struct intf_hdl *pintfhdl = &(pio_priv->intf);
|
||||
u8(*_sd_iread8)(struct intf_hdl *pintfhdl, u32 addr);
|
||||
|
||||
_sd_iread8 = pintfhdl->io_ops._sd_iread8;
|
||||
|
||||
if (_sd_iread8)
|
||||
r_val = _sd_iread8(pintfhdl, addr);
|
||||
else
|
||||
RTW_ERR(FUNC_ADPT_FMT" _sd_iread8 callback is NULL\n", FUNC_ADPT_ARG(adapter));
|
||||
|
||||
return r_val;
|
||||
}
|
||||
|
||||
u16 _rtw_sd_iread16(_adapter *adapter, u32 addr)
|
||||
{
|
||||
u16 r_val = 0x00;
|
||||
struct io_priv *pio_priv = &adapter->iopriv;
|
||||
struct intf_hdl *pintfhdl = &(pio_priv->intf);
|
||||
u16(*_sd_iread16)(struct intf_hdl *pintfhdl, u32 addr);
|
||||
|
||||
_sd_iread16 = pintfhdl->io_ops._sd_iread16;
|
||||
|
||||
if (_sd_iread16)
|
||||
r_val = _sd_iread16(pintfhdl, addr);
|
||||
else
|
||||
RTW_ERR(FUNC_ADPT_FMT" _sd_iread16 callback is NULL\n", FUNC_ADPT_ARG(adapter));
|
||||
|
||||
return r_val;
|
||||
}
|
||||
|
||||
u32 _rtw_sd_iread32(_adapter *adapter, u32 addr)
|
||||
{
|
||||
u32 r_val = 0x00;
|
||||
struct io_priv *pio_priv = &adapter->iopriv;
|
||||
struct intf_hdl *pintfhdl = &(pio_priv->intf);
|
||||
u32(*_sd_iread32)(struct intf_hdl *pintfhdl, u32 addr);
|
||||
|
||||
_sd_iread32 = pintfhdl->io_ops._sd_iread32;
|
||||
|
||||
if (_sd_iread32)
|
||||
r_val = _sd_iread32(pintfhdl, addr);
|
||||
else
|
||||
RTW_ERR(FUNC_ADPT_FMT" _sd_iread32 callback is NULL\n", FUNC_ADPT_ARG(adapter));
|
||||
|
||||
return r_val;
|
||||
}
|
||||
|
||||
int _rtw_sd_iwrite8(_adapter *adapter, u32 addr, u8 val)
|
||||
{
|
||||
struct io_priv *pio_priv = &adapter->iopriv;
|
||||
struct intf_hdl *pintfhdl = &(pio_priv->intf);
|
||||
int (*_sd_iwrite8)(struct intf_hdl *pintfhdl, u32 addr, u8 val);
|
||||
int ret = -1;
|
||||
|
||||
_sd_iwrite8 = pintfhdl->io_ops._sd_iwrite8;
|
||||
|
||||
if (_sd_iwrite8)
|
||||
ret = _sd_iwrite8(pintfhdl, addr, val);
|
||||
else
|
||||
RTW_ERR(FUNC_ADPT_FMT" _sd_iwrite8 callback is NULL\n", FUNC_ADPT_ARG(adapter));
|
||||
|
||||
return RTW_STATUS_CODE(ret);
|
||||
}
|
||||
|
||||
int _rtw_sd_iwrite16(_adapter *adapter, u32 addr, u16 val)
|
||||
{
|
||||
struct io_priv *pio_priv = &adapter->iopriv;
|
||||
struct intf_hdl *pintfhdl = &(pio_priv->intf);
|
||||
int (*_sd_iwrite16)(struct intf_hdl *pintfhdl, u32 addr, u16 val);
|
||||
int ret = -1;
|
||||
|
||||
_sd_iwrite16 = pintfhdl->io_ops._sd_iwrite16;
|
||||
|
||||
if (_sd_iwrite16)
|
||||
ret = _sd_iwrite16(pintfhdl, addr, val);
|
||||
else
|
||||
RTW_ERR(FUNC_ADPT_FMT" _sd_iwrite16 callback is NULL\n", FUNC_ADPT_ARG(adapter));
|
||||
|
||||
return RTW_STATUS_CODE(ret);
|
||||
}
|
||||
int _rtw_sd_iwrite32(_adapter *adapter, u32 addr, u32 val)
|
||||
{
|
||||
struct io_priv *pio_priv = &adapter->iopriv;
|
||||
struct intf_hdl *pintfhdl = &(pio_priv->intf);
|
||||
int (*_sd_iwrite32)(struct intf_hdl *pintfhdl, u32 addr, u32 val);
|
||||
int ret = -1;
|
||||
|
||||
_sd_iwrite32 = pintfhdl->io_ops._sd_iwrite32;
|
||||
|
||||
if (_sd_iwrite32)
|
||||
ret = _sd_iwrite32(pintfhdl, addr, val);
|
||||
else
|
||||
RTW_ERR(FUNC_ADPT_FMT" _sd_iwrite32 callback is NULL\n", FUNC_ADPT_ARG(adapter));
|
||||
|
||||
return RTW_STATUS_CODE(ret);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_SDIO_INDIRECT_ACCESS */
|
||||
|
||||
#endif /* CONFIG_SDIO_HCI */
|
||||
|
||||
int _rtw_write8_async(_adapter *adapter, u32 addr, u8 val)
|
||||
{
|
||||
/* struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue; */
|
||||
struct io_priv *pio_priv = &adapter->iopriv;
|
||||
struct intf_hdl *pintfhdl = &(pio_priv->intf);
|
||||
int (*_write8_async)(struct intf_hdl *pintfhdl, u32 addr, u8 val);
|
||||
int ret;
|
||||
_write8_async = pintfhdl->io_ops._write8_async;
|
||||
|
||||
ret = _write8_async(pintfhdl, addr, val);
|
||||
|
||||
return RTW_STATUS_CODE(ret);
|
||||
}
|
||||
int _rtw_write16_async(_adapter *adapter, u32 addr, u16 val)
|
||||
{
|
||||
/* struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue; */
|
||||
struct io_priv *pio_priv = &adapter->iopriv;
|
||||
struct intf_hdl *pintfhdl = &(pio_priv->intf);
|
||||
int (*_write16_async)(struct intf_hdl *pintfhdl, u32 addr, u16 val);
|
||||
int ret;
|
||||
_write16_async = pintfhdl->io_ops._write16_async;
|
||||
val = rtw_cpu_to_le16(val);
|
||||
ret = _write16_async(pintfhdl, addr, val);
|
||||
|
||||
return RTW_STATUS_CODE(ret);
|
||||
}
|
||||
int _rtw_write32_async(_adapter *adapter, u32 addr, u32 val)
|
||||
{
|
||||
/* struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue; */
|
||||
struct io_priv *pio_priv = &adapter->iopriv;
|
||||
struct intf_hdl *pintfhdl = &(pio_priv->intf);
|
||||
int (*_write32_async)(struct intf_hdl *pintfhdl, u32 addr, u32 val);
|
||||
int ret;
|
||||
_write32_async = pintfhdl->io_ops._write32_async;
|
||||
val = rtw_cpu_to_le32(val);
|
||||
ret = _write32_async(pintfhdl, addr, val);
|
||||
|
||||
return RTW_STATUS_CODE(ret);
|
||||
}
|
||||
|
||||
void _rtw_read_mem(_adapter *adapter, u32 addr, u32 cnt, u8 *pmem)
|
||||
{
|
||||
void (*_read_mem)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem);
|
||||
/* struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue; */
|
||||
struct io_priv *pio_priv = &adapter->iopriv;
|
||||
struct intf_hdl *pintfhdl = &(pio_priv->intf);
|
||||
|
||||
|
||||
if (RTW_CANNOT_RUN(adapter)) {
|
||||
return;
|
||||
}
|
||||
|
||||
_read_mem = pintfhdl->io_ops._read_mem;
|
||||
|
||||
_read_mem(pintfhdl, addr, cnt, pmem);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void _rtw_write_mem(_adapter *adapter, u32 addr, u32 cnt, u8 *pmem)
|
||||
{
|
||||
void (*_write_mem)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem);
|
||||
/* struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue; */
|
||||
struct io_priv *pio_priv = &adapter->iopriv;
|
||||
struct intf_hdl *pintfhdl = &(pio_priv->intf);
|
||||
|
||||
|
||||
_write_mem = pintfhdl->io_ops._write_mem;
|
||||
|
||||
_write_mem(pintfhdl, addr, cnt, pmem);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void _rtw_read_port(_adapter *adapter, u32 addr, u32 cnt, u8 *pmem)
|
||||
{
|
||||
u32(*_read_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem);
|
||||
/* struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue; */
|
||||
struct io_priv *pio_priv = &adapter->iopriv;
|
||||
struct intf_hdl *pintfhdl = &(pio_priv->intf);
|
||||
|
||||
|
||||
if (RTW_CANNOT_RUN(adapter)) {
|
||||
return;
|
||||
}
|
||||
|
||||
_read_port = pintfhdl->io_ops._read_port;
|
||||
|
||||
_read_port(pintfhdl, addr, cnt, pmem);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void _rtw_read_port_cancel(_adapter *adapter)
|
||||
{
|
||||
void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
|
||||
struct io_priv *pio_priv = &adapter->iopriv;
|
||||
struct intf_hdl *pintfhdl = &(pio_priv->intf);
|
||||
|
||||
_read_port_cancel = pintfhdl->io_ops._read_port_cancel;
|
||||
|
||||
RTW_DISABLE_FUNC(adapter, DF_RX_BIT);
|
||||
|
||||
if (_read_port_cancel)
|
||||
_read_port_cancel(pintfhdl);
|
||||
}
|
||||
|
||||
u32 _rtw_write_port(_adapter *adapter, u32 addr, u32 cnt, u8 *pmem)
|
||||
{
|
||||
u32(*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem);
|
||||
/* struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue; */
|
||||
struct io_priv *pio_priv = &adapter->iopriv;
|
||||
struct intf_hdl *pintfhdl = &(pio_priv->intf);
|
||||
u32 ret = _SUCCESS;
|
||||
|
||||
|
||||
_write_port = pintfhdl->io_ops._write_port;
|
||||
|
||||
ret = _write_port(pintfhdl, addr, cnt, pmem);
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
u32 _rtw_write_port_and_wait(_adapter *adapter, u32 addr, u32 cnt, u8 *pmem, int timeout_ms)
|
||||
{
|
||||
int ret = _SUCCESS;
|
||||
struct xmit_buf *pxmitbuf = (struct xmit_buf *)pmem;
|
||||
struct submit_ctx sctx;
|
||||
|
||||
rtw_sctx_init(&sctx, timeout_ms);
|
||||
pxmitbuf->sctx = &sctx;
|
||||
|
||||
ret = _rtw_write_port(adapter, addr, cnt, pmem);
|
||||
|
||||
if (ret == _SUCCESS) {
|
||||
ret = rtw_sctx_wait(&sctx, __func__);
|
||||
|
||||
if (ret != _SUCCESS)
|
||||
pxmitbuf->sctx = NULL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void _rtw_write_port_cancel(_adapter *adapter)
|
||||
{
|
||||
void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
|
||||
struct io_priv *pio_priv = &adapter->iopriv;
|
||||
struct intf_hdl *pintfhdl = &(pio_priv->intf);
|
||||
|
||||
_write_port_cancel = pintfhdl->io_ops._write_port_cancel;
|
||||
|
||||
RTW_DISABLE_FUNC(adapter, DF_TX_BIT);
|
||||
|
||||
if (_write_port_cancel)
|
||||
_write_port_cancel(pintfhdl);
|
||||
}
|
||||
int rtw_init_io_priv(_adapter *padapter, void (*set_intf_ops)(_adapter *padapter, struct _io_ops *pops))
|
||||
{
|
||||
struct io_priv *piopriv = &padapter->iopriv;
|
||||
struct intf_hdl *pintf = &piopriv->intf;
|
||||
|
||||
if (set_intf_ops == NULL)
|
||||
return _FAIL;
|
||||
|
||||
piopriv->padapter = padapter;
|
||||
pintf->padapter = padapter;
|
||||
pintf->pintf_dev = adapter_to_dvobj(padapter);
|
||||
|
||||
set_intf_ops(padapter, &pintf->io_ops);
|
||||
|
||||
return _SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
* Increase and check if the continual_io_error of this @param dvobjprive is larger than MAX_CONTINUAL_IO_ERR
|
||||
* @return _TRUE:
|
||||
* @return _FALSE:
|
||||
*/
|
||||
int rtw_inc_and_chk_continual_io_error(struct dvobj_priv *dvobj)
|
||||
{
|
||||
int ret = _FALSE;
|
||||
int value;
|
||||
|
||||
value = ATOMIC_INC_RETURN(&dvobj->continual_io_error);
|
||||
if (value > MAX_CONTINUAL_IO_ERR) {
|
||||
RTW_INFO("[dvobj:%p][ERROR] continual_io_error:%d > %d\n", dvobj, value, MAX_CONTINUAL_IO_ERR);
|
||||
ret = _TRUE;
|
||||
} else {
|
||||
/* RTW_INFO("[dvobj:%p] continual_io_error:%d\n", dvobj, value); */
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the continual_io_error of this @param dvobjprive to 0
|
||||
*/
|
||||
void rtw_reset_continual_io_error(struct dvobj_priv *dvobj)
|
||||
{
|
||||
ATOMIC_SET(&dvobj->continual_io_error, 0);
|
||||
}
|
||||
|
||||
#ifdef DBG_IO
|
||||
#define RTW_IO_SNIFF_TYPE_RANGE 0 /* specific address range is accessed */
|
||||
#define RTW_IO_SNIFF_TYPE_VALUE 1 /* value match for sniffed range */
|
||||
|
||||
struct rtw_io_sniff_ent {
|
||||
u8 chip;
|
||||
u8 hci;
|
||||
u32 addr;
|
||||
u8 type;
|
||||
union {
|
||||
u32 end_addr;
|
||||
struct {
|
||||
u32 mask;
|
||||
u32 val;
|
||||
bool equal;
|
||||
} vm; /* value match */
|
||||
} u;
|
||||
bool trace;
|
||||
char *tag;
|
||||
bool (*assert_protsel)(_adapter *adapter, u32 addr, u8 len);
|
||||
};
|
||||
|
||||
#define RTW_IO_SNIFF_RANGE_ENT(_chip, _hci, _addr, _end_addr, _trace, _tag) \
|
||||
{.chip = _chip, .hci = _hci, .addr = _addr, .u.end_addr = _end_addr, .trace = _trace, .tag = _tag, .type = RTW_IO_SNIFF_TYPE_RANGE,}
|
||||
|
||||
#define RTW_IO_SNIFF_RANGE_PROT_ENT(_chip, _hci, _addr, _end_addr, _assert_protsel, _tag) \
|
||||
{.chip = _chip, .hci = _hci, .addr = _addr, .u.end_addr = _end_addr, .trace = 1, .assert_protsel = _assert_protsel, .tag = _tag, .type = RTW_IO_SNIFF_TYPE_RANGE,}
|
||||
|
||||
#define RTW_IO_SNIFF_VALUE_ENT(_chip, _hci, _addr, _mask, _val, _equal, _trace, _tag) \
|
||||
{.chip = _chip, .hci = _hci, .addr = _addr, .u.vm.mask = _mask, .u.vm.val = _val, .u.vm.equal = _equal, .trace = _trace, .tag = _tag, .type = RTW_IO_SNIFF_TYPE_VALUE,}
|
||||
|
||||
/* part or all sniffed range is enabled (not all 0) */
|
||||
#define RTW_IO_SNIFF_EN_ENT(_chip, _hci, _addr, _mask, _trace, _tag) \
|
||||
{.chip = _chip, .hci = _hci, .addr = _addr, .u.vm.mask = _mask, .u.vm.val = 0, .u.vm.equal = 0, .trace = _trace, .tag = _tag, .type = RTW_IO_SNIFF_TYPE_VALUE,}
|
||||
|
||||
/* part or all sniffed range is disabled (not all 1) */
|
||||
#define RTW_IO_SNIFF_DIS_ENT(_chip, _hci, _addr, _mask, _trace, _tag) \
|
||||
{.chip = _chip, .hci = _hci, .addr = _addr, .u.vm.mask = _mask, .u.vm.val = 0xFFFFFFFF, .u.vm.equal = 0, .trace = _trace, .tag = _tag, .type = RTW_IO_SNIFF_TYPE_VALUE,}
|
||||
|
||||
const struct rtw_io_sniff_ent read_sniff[] = {
|
||||
#ifdef DBG_IO_HCI_EN_CHK
|
||||
RTW_IO_SNIFF_EN_ENT(MAX_CHIP_TYPE, RTW_SDIO, 0x02, 0x1FC, 1, "SDIO 0x02[8:2] not all 0"),
|
||||
RTW_IO_SNIFF_EN_ENT(MAX_CHIP_TYPE, RTW_USB, 0x02, 0x1E0, 1, "USB 0x02[8:5] not all 0"),
|
||||
RTW_IO_SNIFF_EN_ENT(MAX_CHIP_TYPE, RTW_PCIE, 0x02, 0x01C, 1, "PCI 0x02[4:2] not all 0"),
|
||||
#endif
|
||||
#ifdef DBG_IO_SNIFF_EXAMPLE
|
||||
RTW_IO_SNIFF_RANGE_ENT(MAX_CHIP_TYPE, 0, 0x522, 0x522, 0, "read TXPAUSE"),
|
||||
RTW_IO_SNIFF_DIS_ENT(MAX_CHIP_TYPE, 0, 0x02, 0x3, 0, "0x02[1:0] not all 1"),
|
||||
#endif
|
||||
#ifdef DBG_IO_PROT_SEL
|
||||
RTW_IO_SNIFF_RANGE_PROT_ENT(MAX_CHIP_TYPE, 0, 0x1501, 0x1513, rtw_assert_protsel_port, "protsel port"),
|
||||
RTW_IO_SNIFF_RANGE_PROT_ENT(MAX_CHIP_TYPE, 0, 0x153a, 0x153b, rtw_assert_protsel_atimdtim, "protsel atimdtim"),
|
||||
#endif
|
||||
};
|
||||
|
||||
const int read_sniff_num = sizeof(read_sniff) / sizeof(struct rtw_io_sniff_ent);
|
||||
|
||||
const struct rtw_io_sniff_ent write_sniff[] = {
|
||||
#ifdef DBG_IO_HCI_EN_CHK
|
||||
RTW_IO_SNIFF_EN_ENT(MAX_CHIP_TYPE, RTW_SDIO, 0x02, 0x1FC, 1, "SDIO 0x02[8:2] not all 0"),
|
||||
RTW_IO_SNIFF_EN_ENT(MAX_CHIP_TYPE, RTW_USB, 0x02, 0x1E0, 1, "USB 0x02[8:5] not all 0"),
|
||||
RTW_IO_SNIFF_EN_ENT(MAX_CHIP_TYPE, RTW_PCIE, 0x02, 0x01C, 1, "PCI 0x02[4:2] not all 0"),
|
||||
#endif
|
||||
#ifdef DBG_IO_SIFS_SETTING
|
||||
RTW_IO_SNIFF_RANGE_ENT(MAX_CHIP_TYPE, 0, 0x428, 0x429, 0, "SIFS"),
|
||||
RTW_IO_SNIFF_RANGE_ENT(MAX_CHIP_TYPE, 0, 0x514, 0x517, 0, "SIFS"),
|
||||
RTW_IO_SNIFF_RANGE_ENT(MAX_CHIP_TYPE, 0, 0x63a, 0x63b, 0, "SIFS"),
|
||||
RTW_IO_SNIFF_RANGE_ENT(MAX_CHIP_TYPE, 0, 0x63c, 0x63f, 0, "SIFS"),
|
||||
#endif
|
||||
#ifdef DBG_IO_8822C_1TX_PATH_EN
|
||||
RTW_IO_SNIFF_VALUE_ENT(RTL8822C, 0, 0x1a04, 0xc0000000, 0x02, 1, 0, "write tx_path_en_cck A enabled"),
|
||||
RTW_IO_SNIFF_VALUE_ENT(RTL8822C, 0, 0x1a04, 0xc0000000, 0x01, 1, 0, "write tx_path_en_cck B enabled"),
|
||||
RTW_IO_SNIFF_VALUE_ENT(RTL8822C, 0, 0x1a04, 0xc0000000, 0x03, 1, 1, "write tx_path_en_cck AB enabled"),
|
||||
RTW_IO_SNIFF_VALUE_ENT(RTL8822C, 0, 0x820, 0x03, 0x01, 1, 0, "write tx_path_en_ofdm_1sts A enabled"),
|
||||
RTW_IO_SNIFF_VALUE_ENT(RTL8822C, 0, 0x820, 0x03, 0x02, 1, 0, "write tx_path_en_ofdm_1sts B enabled"),
|
||||
RTW_IO_SNIFF_VALUE_ENT(RTL8822C, 0, 0x820, 0x03, 0x03, 1, 1, "write tx_path_en_ofdm_1sts AB enabled"),
|
||||
RTW_IO_SNIFF_VALUE_ENT(RTL8822C, 0, 0x820, 0x30, 0x01, 1, 0, "write tx_path_en_ofdm_2sts A enabled"),
|
||||
RTW_IO_SNIFF_VALUE_ENT(RTL8822C, 0, 0x820, 0x30, 0x02, 1, 0, "write tx_path_en_ofdm_2sts B enabled"),
|
||||
RTW_IO_SNIFF_VALUE_ENT(RTL8822C, 0, 0x820, 0x30, 0x03, 1, 1, "write tx_path_en_ofdm_2sts AB enabled"),
|
||||
#endif
|
||||
#ifdef DBG_IO_SNIFF_EXAMPLE
|
||||
RTW_IO_SNIFF_RANGE_ENT(MAX_CHIP_TYPE, 0, 0x522, 0x522, 0, "write TXPAUSE"),
|
||||
RTW_IO_SNIFF_DIS_ENT(MAX_CHIP_TYPE, 0, 0x02, 0x3, 0, "0x02[1:0] not all 1"),
|
||||
#endif
|
||||
};
|
||||
|
||||
const int write_sniff_num = sizeof(write_sniff) / sizeof(struct rtw_io_sniff_ent);
|
||||
|
||||
static bool match_io_sniff_ranges(_adapter *adapter
|
||||
, const struct rtw_io_sniff_ent *sniff, int i, u32 addr, u16 len)
|
||||
{
|
||||
|
||||
/* check if IO range after sniff end address */
|
||||
if (addr > sniff->u.end_addr)
|
||||
return 0;
|
||||
|
||||
if (sniff->assert_protsel &&
|
||||
sniff->assert_protsel(adapter, addr, len))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static bool match_io_sniff_value(_adapter *adapter
|
||||
, const struct rtw_io_sniff_ent *sniff, int i, u32 addr, u8 len, u32 val)
|
||||
{
|
||||
u8 sniff_len;
|
||||
s8 mask_shift;
|
||||
u32 mask;
|
||||
s8 value_shift;
|
||||
u32 value;
|
||||
bool ret = 0;
|
||||
|
||||
/* check if IO range after sniff end address */
|
||||
sniff_len = 4;
|
||||
while (!(sniff->u.vm.mask & (0xFF << ((sniff_len - 1) * 8)))) {
|
||||
sniff_len--;
|
||||
if (sniff_len == 0)
|
||||
goto exit;
|
||||
}
|
||||
if (sniff->addr + sniff_len <= addr)
|
||||
goto exit;
|
||||
|
||||
/* align to IO addr */
|
||||
mask_shift = (sniff->addr - addr) * 8;
|
||||
value_shift = mask_shift + bitshift(sniff->u.vm.mask);
|
||||
if (mask_shift > 0)
|
||||
mask = sniff->u.vm.mask << mask_shift;
|
||||
else if (mask_shift < 0)
|
||||
mask = sniff->u.vm.mask >> -mask_shift;
|
||||
else
|
||||
mask = sniff->u.vm.mask;
|
||||
|
||||
if (value_shift > 0)
|
||||
value = sniff->u.vm.val << value_shift;
|
||||
else if (mask_shift < 0)
|
||||
value = sniff->u.vm.val >> -value_shift;
|
||||
else
|
||||
value = sniff->u.vm.val;
|
||||
|
||||
if ((sniff->u.vm.equal && (mask & val) == (mask & value))
|
||||
|| (!sniff->u.vm.equal && (mask & val) != (mask & value))
|
||||
) {
|
||||
ret = 1;
|
||||
if (0)
|
||||
RTW_INFO(FUNC_ADPT_FMT" addr:0x%x len:%u val:0x%x (i:%d sniff_len:%u m_shift:%d mask:0x%x v_shifd:%d value:0x%x equal:%d)\n"
|
||||
, FUNC_ADPT_ARG(adapter), addr, len, val, i, sniff_len, mask_shift, mask, value_shift, value, sniff->u.vm.equal);
|
||||
}
|
||||
|
||||
exit:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static bool match_io_sniff(_adapter *adapter
|
||||
, const struct rtw_io_sniff_ent *sniff, int i, u32 addr, u8 len, u32 val)
|
||||
{
|
||||
bool ret = 0;
|
||||
|
||||
if (sniff->chip != MAX_CHIP_TYPE
|
||||
&& sniff->chip != rtw_get_chip_type(adapter))
|
||||
goto exit;
|
||||
if (sniff->hci
|
||||
&& !(sniff->hci & rtw_get_intf_type(adapter)))
|
||||
goto exit;
|
||||
if (sniff->addr >= addr + len) /* IO range below sniff start address */
|
||||
goto exit;
|
||||
|
||||
switch (sniff->type) {
|
||||
case RTW_IO_SNIFF_TYPE_RANGE:
|
||||
ret = match_io_sniff_ranges(adapter, sniff, i, addr, len);
|
||||
break;
|
||||
case RTW_IO_SNIFF_TYPE_VALUE:
|
||||
if (len == 1 || len == 2 || len == 4)
|
||||
ret = match_io_sniff_value(adapter, sniff, i, addr, len, val);
|
||||
break;
|
||||
default:
|
||||
rtw_warn_on(1);
|
||||
break;
|
||||
}
|
||||
|
||||
exit:
|
||||
return ret;
|
||||
}
|
||||
|
||||
u32 match_read_sniff(_adapter *adapter, u32 addr, u16 len, u32 val)
|
||||
{
|
||||
int i;
|
||||
bool trace = 0;
|
||||
u32 match = 0;
|
||||
|
||||
for (i = 0; i < read_sniff_num; i++) {
|
||||
if (match_io_sniff(adapter, &read_sniff[i], i, addr, len, val)) {
|
||||
match++;
|
||||
trace |= read_sniff[i].trace;
|
||||
if (read_sniff[i].tag)
|
||||
RTW_INFO("DBG_IO TAG %s\n", read_sniff[i].tag);
|
||||
}
|
||||
}
|
||||
|
||||
rtw_warn_on(trace);
|
||||
|
||||
return match;
|
||||
}
|
||||
|
||||
u32 match_write_sniff(_adapter *adapter, u32 addr, u16 len, u32 val)
|
||||
{
|
||||
int i;
|
||||
bool trace = 0;
|
||||
u32 match = 0;
|
||||
|
||||
for (i = 0; i < write_sniff_num; i++) {
|
||||
if (match_io_sniff(adapter, &write_sniff[i], i, addr, len, val)) {
|
||||
match++;
|
||||
trace |= write_sniff[i].trace;
|
||||
if (write_sniff[i].tag)
|
||||
RTW_INFO("DBG_IO TAG %s\n", write_sniff[i].tag);
|
||||
}
|
||||
}
|
||||
|
||||
rtw_warn_on(trace);
|
||||
|
||||
return match;
|
||||
}
|
||||
|
||||
struct rf_sniff_ent {
|
||||
u8 path;
|
||||
u16 reg;
|
||||
u32 mask;
|
||||
};
|
||||
|
||||
struct rf_sniff_ent rf_read_sniff_ranges[] = {
|
||||
/* example for all path addr 0x55 with all RF Reg mask */
|
||||
/* {MAX_RF_PATH, 0x55, bRFRegOffsetMask}, */
|
||||
};
|
||||
|
||||
struct rf_sniff_ent rf_write_sniff_ranges[] = {
|
||||
/* example for all path addr 0x55 with all RF Reg mask */
|
||||
/* {MAX_RF_PATH, 0x55, bRFRegOffsetMask}, */
|
||||
};
|
||||
|
||||
int rf_read_sniff_num = sizeof(rf_read_sniff_ranges) / sizeof(struct rf_sniff_ent);
|
||||
int rf_write_sniff_num = sizeof(rf_write_sniff_ranges) / sizeof(struct rf_sniff_ent);
|
||||
|
||||
bool match_rf_read_sniff_ranges(_adapter *adapter, u8 path, u32 addr, u32 mask)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < rf_read_sniff_num; i++) {
|
||||
if (rf_read_sniff_ranges[i].path == MAX_RF_PATH || rf_read_sniff_ranges[i].path == path)
|
||||
if (addr == rf_read_sniff_ranges[i].reg && (mask & rf_read_sniff_ranges[i].mask))
|
||||
return _TRUE;
|
||||
}
|
||||
|
||||
return _FALSE;
|
||||
}
|
||||
|
||||
bool match_rf_write_sniff_ranges(_adapter *adapter, u8 path, u32 addr, u32 mask)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < rf_write_sniff_num; i++) {
|
||||
if (rf_write_sniff_ranges[i].path == MAX_RF_PATH || rf_write_sniff_ranges[i].path == path)
|
||||
if (addr == rf_write_sniff_ranges[i].reg && (mask & rf_write_sniff_ranges[i].mask))
|
||||
return _TRUE;
|
||||
}
|
||||
|
||||
return _FALSE;
|
||||
}
|
||||
|
||||
void dbg_rtw_reg_read_monitor(_adapter *adapter, u32 addr, u32 len, u32 val, const char *caller, const int line)
|
||||
{
|
||||
if (match_read_sniff(adapter, addr, len, val)) {
|
||||
switch (len) {
|
||||
case 1:
|
||||
RTW_INFO("DBG_IO %s:%d read8(0x%04x) return 0x%02x\n"
|
||||
, caller, line, addr, val);
|
||||
break;
|
||||
case 2:
|
||||
RTW_INFO("DBG_IO %s:%d read16(0x%04x) return 0x%04x\n"
|
||||
, caller, line, addr, val);
|
||||
break;
|
||||
case 4:
|
||||
RTW_INFO("DBG_IO %s:%d read32(0x%04x) return 0x%08x\n"
|
||||
, caller, line, addr, val);
|
||||
break;
|
||||
default:
|
||||
RTW_INFO("DBG_IO %s:%d readN(0x%04x, %u)\n"
|
||||
, caller, line, addr, len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void dbg_rtw_reg_write_monitor(_adapter *adapter, u32 addr, u32 len, u32 val, const char *caller, const int line)
|
||||
{
|
||||
if (match_write_sniff(adapter, addr, len, val)) {
|
||||
switch (len) {
|
||||
case 1:
|
||||
RTW_INFO("DBG_IO %s:%d write8(0x%04x, 0x%02x)\n"
|
||||
, caller, line, addr, val);
|
||||
break;
|
||||
case 2:
|
||||
RTW_INFO("DBG_IO %s:%d write16(0x%04x, 0x%04x)\n"
|
||||
, caller, line, addr, val);
|
||||
break;
|
||||
case 4:
|
||||
RTW_INFO("DBG_IO %s:%d write32(0x%04x, 0x%08x)\n"
|
||||
, caller, line, addr, val);
|
||||
break;
|
||||
default:
|
||||
RTW_INFO("DBG_IO %s:%d rtw_writeN(0x%04x, %u)\n"
|
||||
, caller, line, addr, len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
u8 dbg_rtw_read8(_adapter *adapter, u32 addr, const char *caller, const int line)
|
||||
{
|
||||
u8 val = _rtw_read8(adapter, addr);
|
||||
|
||||
if (match_read_sniff(adapter, addr, 1, val)) {
|
||||
RTW_INFO("DBG_IO %s:%d rtw_read8(0x%04x) return 0x%02x\n"
|
||||
, caller, line, addr, val);
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
u16 dbg_rtw_read16(_adapter *adapter, u32 addr, const char *caller, const int line)
|
||||
{
|
||||
u16 val = _rtw_read16(adapter, addr);
|
||||
|
||||
if (match_read_sniff(adapter, addr, 2, val)) {
|
||||
RTW_INFO("DBG_IO %s:%d rtw_read16(0x%04x) return 0x%04x\n"
|
||||
, caller, line, addr, val);
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
u32 dbg_rtw_read32(_adapter *adapter, u32 addr, const char *caller, const int line)
|
||||
{
|
||||
u32 val = _rtw_read32(adapter, addr);
|
||||
|
||||
if (match_read_sniff(adapter, addr, 4, val)) {
|
||||
RTW_INFO("DBG_IO %s:%d rtw_read32(0x%04x) return 0x%08x\n"
|
||||
, caller, line, addr, val);
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
int dbg_rtw_write8(_adapter *adapter, u32 addr, u8 val, const char *caller, const int line)
|
||||
{
|
||||
if (match_write_sniff(adapter, addr, 1, val)) {
|
||||
RTW_INFO("DBG_IO %s:%d rtw_write8(0x%04x, 0x%02x)\n"
|
||||
, caller, line, addr, val);
|
||||
}
|
||||
|
||||
return _rtw_write8(adapter, addr, val);
|
||||
}
|
||||
int dbg_rtw_write16(_adapter *adapter, u32 addr, u16 val, const char *caller, const int line)
|
||||
{
|
||||
if (match_write_sniff(adapter, addr, 2, val)) {
|
||||
RTW_INFO("DBG_IO %s:%d rtw_write16(0x%04x, 0x%04x)\n"
|
||||
, caller, line, addr, val);
|
||||
}
|
||||
|
||||
return _rtw_write16(adapter, addr, val);
|
||||
}
|
||||
int dbg_rtw_write32(_adapter *adapter, u32 addr, u32 val, const char *caller, const int line)
|
||||
{
|
||||
if (match_write_sniff(adapter, addr, 4, val)) {
|
||||
RTW_INFO("DBG_IO %s:%d rtw_write32(0x%04x, 0x%08x)\n"
|
||||
, caller, line, addr, val);
|
||||
}
|
||||
|
||||
return _rtw_write32(adapter, addr, val);
|
||||
}
|
||||
int dbg_rtw_writeN(_adapter *adapter, u32 addr , u32 length , u8 *data, const char *caller, const int line)
|
||||
{
|
||||
if (match_write_sniff(adapter, addr, length, 0)) {
|
||||
RTW_INFO("DBG_IO %s:%d rtw_writeN(0x%04x, %u)\n"
|
||||
, caller, line, addr, length);
|
||||
}
|
||||
|
||||
return _rtw_writeN(adapter, addr, length, data);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_SDIO_HCI
|
||||
u8 dbg_rtw_sd_f0_read8(_adapter *adapter, u32 addr, const char *caller, const int line)
|
||||
{
|
||||
u8 val = _rtw_sd_f0_read8(adapter, addr);
|
||||
|
||||
#if 0
|
||||
if (match_read_sniff(adapter, addr, 1, val)) {
|
||||
RTW_INFO("DBG_IO %s:%d rtw_sd_f0_read8(0x%04x) return 0x%02x\n"
|
||||
, caller, line, addr, val);
|
||||
}
|
||||
#endif
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_SDIO_INDIRECT_ACCESS
|
||||
u8 dbg_rtw_sd_iread8(_adapter *adapter, u32 addr, const char *caller, const int line)
|
||||
{
|
||||
u8 val = rtw_sd_iread8(adapter, addr);
|
||||
|
||||
if (match_read_sniff(adapter, addr, 1, val)) {
|
||||
RTW_INFO("DBG_IO %s:%d rtw_sd_iread8(0x%04x) return 0x%02x\n"
|
||||
, caller, line, addr, val);
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
u16 dbg_rtw_sd_iread16(_adapter *adapter, u32 addr, const char *caller, const int line)
|
||||
{
|
||||
u16 val = _rtw_sd_iread16(adapter, addr);
|
||||
|
||||
if (match_read_sniff(adapter, addr, 2, val)) {
|
||||
RTW_INFO("DBG_IO %s:%d rtw_sd_iread16(0x%04x) return 0x%04x\n"
|
||||
, caller, line, addr, val);
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
u32 dbg_rtw_sd_iread32(_adapter *adapter, u32 addr, const char *caller, const int line)
|
||||
{
|
||||
u32 val = _rtw_sd_iread32(adapter, addr);
|
||||
|
||||
if (match_read_sniff(adapter, addr, 4, val)) {
|
||||
RTW_INFO("DBG_IO %s:%d rtw_sd_iread32(0x%04x) return 0x%08x\n"
|
||||
, caller, line, addr, val);
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
int dbg_rtw_sd_iwrite8(_adapter *adapter, u32 addr, u8 val, const char *caller, const int line)
|
||||
{
|
||||
if (match_write_sniff(adapter, addr, 1, val)) {
|
||||
RTW_INFO("DBG_IO %s:%d rtw_sd_iwrite8(0x%04x, 0x%02x)\n"
|
||||
, caller, line, addr, val);
|
||||
}
|
||||
|
||||
return _rtw_sd_iwrite8(adapter, addr, val);
|
||||
}
|
||||
int dbg_rtw_sd_iwrite16(_adapter *adapter, u32 addr, u16 val, const char *caller, const int line)
|
||||
{
|
||||
if (match_write_sniff(adapter, addr, 2, val)) {
|
||||
RTW_INFO("DBG_IO %s:%d rtw_sd_iwrite16(0x%04x, 0x%04x)\n"
|
||||
, caller, line, addr, val);
|
||||
}
|
||||
|
||||
return _rtw_sd_iwrite16(adapter, addr, val);
|
||||
}
|
||||
int dbg_rtw_sd_iwrite32(_adapter *adapter, u32 addr, u32 val, const char *caller, const int line)
|
||||
{
|
||||
if (match_write_sniff(adapter, addr, 4, val)) {
|
||||
RTW_INFO("DBG_IO %s:%d rtw_sd_iwrite32(0x%04x, 0x%08x)\n"
|
||||
, caller, line, addr, val);
|
||||
}
|
||||
|
||||
return _rtw_sd_iwrite32(adapter, addr, val);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_SDIO_INDIRECT_ACCESS */
|
||||
|
||||
#endif /* CONFIG_SDIO_HCI */
|
||||
|
||||
#endif
|
||||
19
drivers/net/wireless/rtl8822cs/core/rtw_ioctl_query.c
Normal file
19
drivers/net/wireless/rtl8822cs/core/rtw_ioctl_query.c
Normal file
@@ -0,0 +1,19 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright(c) 2007 - 2017 Realtek Corporation.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of version 2 of the GNU General Public License as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*****************************************************************************/
|
||||
#define _RTW_IOCTL_QUERY_C_
|
||||
|
||||
#include <drv_types.h>
|
||||
|
||||
|
||||
951
drivers/net/wireless/rtl8822cs/core/rtw_ioctl_set.c
Normal file
951
drivers/net/wireless/rtl8822cs/core/rtw_ioctl_set.c
Normal file
@@ -0,0 +1,951 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright(c) 2007 - 2021 Realtek Corporation.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of version 2 of the GNU General Public License as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*****************************************************************************/
|
||||
#define _RTW_IOCTL_SET_C_
|
||||
|
||||
#include <drv_types.h>
|
||||
#include <hal_data.h>
|
||||
|
||||
|
||||
extern void indicate_wx_scan_complete_event(_adapter *padapter);
|
||||
|
||||
#define IS_MAC_ADDRESS_BROADCAST(addr) \
|
||||
(\
|
||||
((addr[0] == 0xff) && (addr[1] == 0xff) && \
|
||||
(addr[2] == 0xff) && (addr[3] == 0xff) && \
|
||||
(addr[4] == 0xff) && (addr[5] == 0xff)) ? _TRUE : _FALSE \
|
||||
)
|
||||
|
||||
u8 rtw_validate_bssid(const u8 *bssid)
|
||||
{
|
||||
u8 ret = _TRUE;
|
||||
|
||||
if (is_zero_mac_addr(bssid)
|
||||
|| is_broadcast_mac_addr(bssid)
|
||||
|| is_multicast_mac_addr(bssid)
|
||||
)
|
||||
ret = _FALSE;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
u8 rtw_validate_ssid(NDIS_802_11_SSID *ssid)
|
||||
{
|
||||
#ifdef CONFIG_VALIDATE_SSID
|
||||
u8 i;
|
||||
#endif
|
||||
u8 ret = _TRUE;
|
||||
|
||||
|
||||
if (ssid->SsidLength > 32) {
|
||||
ret = _FALSE;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_VALIDATE_SSID
|
||||
for (i = 0; i < ssid->SsidLength; i++) {
|
||||
/* wifi, printable ascii code must be supported */
|
||||
if (!((ssid->Ssid[i] >= 0x20) && (ssid->Ssid[i] <= 0x7e))) {
|
||||
ret = _FALSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif /* CONFIG_VALIDATE_SSID */
|
||||
|
||||
exit:
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
u8 rtw_do_join(_adapter *padapter);
|
||||
u8 rtw_do_join(_adapter *padapter)
|
||||
{
|
||||
_irqL irqL;
|
||||
_list *plist, *phead;
|
||||
u8 *pibss = NULL;
|
||||
struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
|
||||
struct sitesurvey_parm *parm = NULL;
|
||||
_queue *queue = &(pmlmepriv->scanned_queue);
|
||||
u8 ret = _SUCCESS;
|
||||
|
||||
parm = (struct sitesurvey_parm *)rtw_zmalloc(sizeof(struct sitesurvey_parm));
|
||||
if (!parm)
|
||||
return _FAIL;
|
||||
_enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
|
||||
phead = get_list_head(queue);
|
||||
plist = get_next(phead);
|
||||
|
||||
|
||||
pmlmepriv->cur_network.join_res = -2;
|
||||
|
||||
set_fwstate(pmlmepriv, WIFI_UNDER_LINKING);
|
||||
|
||||
pmlmepriv->pscanned = plist;
|
||||
|
||||
pmlmepriv->to_join = _TRUE;
|
||||
|
||||
rtw_init_sitesurvey_parm(padapter, parm);
|
||||
_rtw_memcpy(&(parm->ssid[0]), &pmlmepriv->assoc_ssid, sizeof(NDIS_802_11_SSID));
|
||||
parm->ssid_num = 1;
|
||||
|
||||
if (pmlmepriv->assoc_ch) {
|
||||
parm->ch_num = 1;
|
||||
parm->ch[0].hw_value = pmlmepriv->assoc_ch;
|
||||
parm->ch[0].flags = 0;
|
||||
}
|
||||
|
||||
if (_rtw_queue_empty(queue) == _TRUE) {
|
||||
_exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
|
||||
_clr_fwstate_(pmlmepriv, WIFI_UNDER_LINKING);
|
||||
|
||||
/* when set_ssid/set_bssid for rtw_do_join(), but scanning queue is empty */
|
||||
/* we try to issue sitesurvey firstly */
|
||||
|
||||
if (pmlmepriv->LinkDetectInfo.bBusyTraffic == _FALSE
|
||||
|| rtw_to_roam(padapter) > 0
|
||||
) {
|
||||
u8 ssc_chk = rtw_sitesurvey_condition_check(padapter, _FALSE);
|
||||
|
||||
if ((ssc_chk == SS_ALLOW) || (ssc_chk == SS_DENY_BUSY_TRAFFIC) ){
|
||||
/* submit site_survey_cmd */
|
||||
ret = rtw_sitesurvey_cmd(padapter, parm);
|
||||
if (_SUCCESS != ret)
|
||||
pmlmepriv->to_join = _FALSE;
|
||||
} else {
|
||||
/*if (ssc_chk == SS_DENY_BUDDY_UNDER_SURVEY)*/
|
||||
pmlmepriv->to_join = _FALSE;
|
||||
ret = _FAIL;
|
||||
}
|
||||
} else {
|
||||
pmlmepriv->to_join = _FALSE;
|
||||
ret = _FAIL;
|
||||
}
|
||||
|
||||
goto exit;
|
||||
} else {
|
||||
int select_ret;
|
||||
_exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
|
||||
select_ret = rtw_select_and_join_from_scanned_queue(pmlmepriv);
|
||||
if (select_ret == _SUCCESS) {
|
||||
u32 join_timeout = MAX_JOIN_TIMEOUT;
|
||||
|
||||
#if defined(CONFIG_CONCURRENT_MODE) && defined(CONFIG_AP_MODE)
|
||||
struct rf_ctl_t *rfctl;
|
||||
rfctl = adapter_to_rfctl(padapter);
|
||||
if (rfctl->ap_csa_en == CSA_STA_JOINBSS)
|
||||
join_timeout += (rfctl->ap_csa_switch_cnt * 100);
|
||||
#endif
|
||||
|
||||
pmlmepriv->to_join = _FALSE;
|
||||
_set_timer(&pmlmepriv->assoc_timer, join_timeout);
|
||||
} else {
|
||||
if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == _TRUE) {
|
||||
#ifdef CONFIG_AP_MODE
|
||||
/* submit createbss_cmd to change to a ADHOC_MASTER */
|
||||
|
||||
/* pmlmepriv->lock has been acquired by caller... */
|
||||
WLAN_BSSID_EX *pdev_network = &(padapter->registrypriv.dev_network);
|
||||
|
||||
/*pmlmepriv->fw_state = WIFI_ADHOC_MASTER_STATE;*/
|
||||
init_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE);
|
||||
|
||||
pibss = padapter->registrypriv.dev_network.MacAddress;
|
||||
|
||||
_rtw_memset(&pdev_network->Ssid, 0, sizeof(NDIS_802_11_SSID));
|
||||
_rtw_memcpy(&pdev_network->Ssid, &pmlmepriv->assoc_ssid, sizeof(NDIS_802_11_SSID));
|
||||
|
||||
rtw_update_registrypriv_dev_network(padapter);
|
||||
|
||||
rtw_generate_random_ibss(pibss);
|
||||
|
||||
if (rtw_create_ibss_cmd(padapter, 0) != _SUCCESS) {
|
||||
ret = _FALSE;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
pmlmepriv->to_join = _FALSE;
|
||||
#endif /* CONFIG_AP_MODE */
|
||||
} else {
|
||||
/* can't associate ; reset under-linking */
|
||||
_clr_fwstate_(pmlmepriv, WIFI_UNDER_LINKING);
|
||||
|
||||
/* when set_ssid/set_bssid for rtw_do_join(), but there are no desired bss in scanning queue */
|
||||
/* we try to issue sitesurvey firstly */
|
||||
if (pmlmepriv->LinkDetectInfo.bBusyTraffic == _FALSE
|
||||
|| rtw_to_roam(padapter) > 0
|
||||
) {
|
||||
u8 ssc_chk = rtw_sitesurvey_condition_check(padapter, _FALSE);
|
||||
|
||||
if ((ssc_chk == SS_ALLOW) || (ssc_chk == SS_DENY_BUSY_TRAFFIC)){
|
||||
/* RTW_INFO(("rtw_do_join() when no desired bss in scanning queue\n"); */
|
||||
ret = rtw_sitesurvey_cmd(padapter, parm);
|
||||
if (_SUCCESS != ret)
|
||||
pmlmepriv->to_join = _FALSE;
|
||||
} else {
|
||||
/*if (ssc_chk == SS_DENY_BUDDY_UNDER_SURVEY) {
|
||||
} else {*/
|
||||
ret = _FAIL;
|
||||
pmlmepriv->to_join = _FALSE;
|
||||
}
|
||||
} else {
|
||||
ret = _FAIL;
|
||||
pmlmepriv->to_join = _FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
exit:
|
||||
if (parm)
|
||||
rtw_mfree(parm, sizeof(struct sitesurvey_parm));
|
||||
return ret;
|
||||
}
|
||||
|
||||
u8 rtw_set_802_11_bssid(_adapter *padapter, u8 *bssid)
|
||||
{
|
||||
_irqL irqL;
|
||||
u8 status = _SUCCESS;
|
||||
|
||||
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
|
||||
|
||||
|
||||
RTW_PRINT("set bssid:%pM\n", bssid);
|
||||
|
||||
if ((bssid[0] == 0x00 && bssid[1] == 0x00 && bssid[2] == 0x00 && bssid[3] == 0x00 && bssid[4] == 0x00 && bssid[5] == 0x00) ||
|
||||
(bssid[0] == 0xFF && bssid[1] == 0xFF && bssid[2] == 0xFF && bssid[3] == 0xFF && bssid[4] == 0xFF && bssid[5] == 0xFF)) {
|
||||
status = _FAIL;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
_enter_critical_bh(&pmlmepriv->lock, &irqL);
|
||||
|
||||
|
||||
RTW_INFO("Set BSSID under fw_state=0x%08x\n", get_fwstate(pmlmepriv));
|
||||
if (check_fwstate(pmlmepriv, WIFI_UNDER_SURVEY) == _TRUE)
|
||||
goto handle_tkip_countermeasure;
|
||||
else if (check_fwstate(pmlmepriv, WIFI_UNDER_LINKING) == _TRUE)
|
||||
goto release_mlme_lock;
|
||||
|
||||
if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE | WIFI_ADHOC_MASTER_STATE) == _TRUE) {
|
||||
|
||||
if (_rtw_memcmp(&pmlmepriv->cur_network.network.MacAddress, bssid, ETH_ALEN) == _TRUE) {
|
||||
if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) == _FALSE)
|
||||
goto release_mlme_lock;/* it means driver is in WIFI_ADHOC_MASTER_STATE, we needn't create bss again. */
|
||||
} else {
|
||||
|
||||
rtw_disassoc_cmd(padapter, 0, 0);
|
||||
|
||||
if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == _TRUE)
|
||||
rtw_indicate_disconnect(padapter, 0, _FALSE);
|
||||
|
||||
rtw_free_assoc_resources_cmd(padapter, _TRUE, 0);
|
||||
|
||||
if ((check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == _TRUE)) {
|
||||
_clr_fwstate_(pmlmepriv, WIFI_ADHOC_MASTER_STATE);
|
||||
set_fwstate(pmlmepriv, WIFI_ADHOC_STATE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
handle_tkip_countermeasure:
|
||||
if (rtw_handle_tkip_countermeasure(padapter, __func__) == _FAIL) {
|
||||
status = _FAIL;
|
||||
goto release_mlme_lock;
|
||||
}
|
||||
|
||||
_rtw_memset(&pmlmepriv->assoc_ssid, 0, sizeof(NDIS_802_11_SSID));
|
||||
_rtw_memcpy(&pmlmepriv->assoc_bssid, bssid, ETH_ALEN);
|
||||
pmlmepriv->assoc_ch = 0;
|
||||
pmlmepriv->assoc_by_bssid = _TRUE;
|
||||
|
||||
if (check_fwstate(pmlmepriv, WIFI_UNDER_SURVEY) == _TRUE)
|
||||
pmlmepriv->to_join = _TRUE;
|
||||
else
|
||||
status = rtw_do_join(padapter);
|
||||
|
||||
release_mlme_lock:
|
||||
_exit_critical_bh(&pmlmepriv->lock, &irqL);
|
||||
|
||||
exit:
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
u8 rtw_set_802_11_ssid(_adapter *padapter, NDIS_802_11_SSID *ssid)
|
||||
{
|
||||
_irqL irqL;
|
||||
u8 status = _SUCCESS;
|
||||
|
||||
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
|
||||
struct wlan_network *pnetwork = &pmlmepriv->cur_network;
|
||||
|
||||
|
||||
RTW_PRINT("set ssid [%s] fw_state=0x%08x\n",
|
||||
ssid->Ssid, get_fwstate(pmlmepriv));
|
||||
|
||||
if (!rtw_is_hw_init_completed(padapter)) {
|
||||
status = _FAIL;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
_enter_critical_bh(&pmlmepriv->lock, &irqL);
|
||||
|
||||
RTW_INFO("Set SSID under fw_state=0x%08x\n", get_fwstate(pmlmepriv));
|
||||
if (check_fwstate(pmlmepriv, WIFI_UNDER_SURVEY) == _TRUE)
|
||||
goto handle_tkip_countermeasure;
|
||||
else if (check_fwstate(pmlmepriv, WIFI_UNDER_LINKING) == _TRUE)
|
||||
goto release_mlme_lock;
|
||||
|
||||
if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE | WIFI_ADHOC_MASTER_STATE) == _TRUE) {
|
||||
|
||||
if ((pmlmepriv->assoc_ssid.SsidLength == ssid->SsidLength) &&
|
||||
(_rtw_memcmp(&pmlmepriv->assoc_ssid.Ssid, ssid->Ssid, ssid->SsidLength) == _TRUE)) {
|
||||
if ((check_fwstate(pmlmepriv, WIFI_STATION_STATE) == _FALSE)) {
|
||||
|
||||
if (rtw_is_same_ibss(padapter, pnetwork) == _FALSE) {
|
||||
/* if in WIFI_ADHOC_MASTER_STATE | WIFI_ADHOC_STATE, create bss or rejoin again */
|
||||
rtw_disassoc_cmd(padapter, 0, 0);
|
||||
|
||||
if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == _TRUE)
|
||||
rtw_indicate_disconnect(padapter, 0, _FALSE);
|
||||
|
||||
rtw_free_assoc_resources_cmd(padapter, _TRUE, 0);
|
||||
|
||||
if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == _TRUE) {
|
||||
_clr_fwstate_(pmlmepriv, WIFI_ADHOC_MASTER_STATE);
|
||||
set_fwstate(pmlmepriv, WIFI_ADHOC_STATE);
|
||||
}
|
||||
} else {
|
||||
goto release_mlme_lock;/* it means driver is in WIFI_ADHOC_MASTER_STATE, we needn't create bss again. */
|
||||
}
|
||||
}
|
||||
#ifdef CONFIG_LPS
|
||||
else
|
||||
rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_JOINBSS, 0);
|
||||
#endif
|
||||
} else {
|
||||
|
||||
rtw_disassoc_cmd(padapter, 0, 0);
|
||||
|
||||
if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == _TRUE)
|
||||
rtw_indicate_disconnect(padapter, 0, _FALSE);
|
||||
|
||||
rtw_free_assoc_resources_cmd(padapter, _TRUE, 0);
|
||||
|
||||
if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == _TRUE) {
|
||||
_clr_fwstate_(pmlmepriv, WIFI_ADHOC_MASTER_STATE);
|
||||
set_fwstate(pmlmepriv, WIFI_ADHOC_STATE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
handle_tkip_countermeasure:
|
||||
if (rtw_handle_tkip_countermeasure(padapter, __func__) == _FAIL) {
|
||||
status = _FAIL;
|
||||
goto release_mlme_lock;
|
||||
}
|
||||
|
||||
if (rtw_validate_ssid(ssid) == _FALSE) {
|
||||
status = _FAIL;
|
||||
goto release_mlme_lock;
|
||||
}
|
||||
|
||||
_rtw_memcpy(&pmlmepriv->assoc_ssid, ssid, sizeof(NDIS_802_11_SSID));
|
||||
pmlmepriv->assoc_ch = 0;
|
||||
pmlmepriv->assoc_by_bssid = _FALSE;
|
||||
|
||||
if (check_fwstate(pmlmepriv, WIFI_UNDER_SURVEY) == _TRUE)
|
||||
pmlmepriv->to_join = _TRUE;
|
||||
else
|
||||
status = rtw_do_join(padapter);
|
||||
|
||||
release_mlme_lock:
|
||||
_exit_critical_bh(&pmlmepriv->lock, &irqL);
|
||||
|
||||
exit:
|
||||
|
||||
|
||||
return status;
|
||||
|
||||
}
|
||||
|
||||
u8 rtw_set_802_11_connect(_adapter *padapter,
|
||||
const u8 *bssid, NDIS_802_11_SSID *ssid, u16 ch)
|
||||
{
|
||||
_irqL irqL;
|
||||
u8 status = _SUCCESS;
|
||||
bool bssid_valid = _TRUE;
|
||||
bool ssid_valid = _TRUE;
|
||||
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
|
||||
|
||||
|
||||
if (!ssid || rtw_validate_ssid(ssid) == _FALSE)
|
||||
ssid_valid = _FALSE;
|
||||
|
||||
if (!bssid || rtw_validate_bssid(bssid) == _FALSE)
|
||||
bssid_valid = _FALSE;
|
||||
|
||||
if (ssid_valid == _FALSE && bssid_valid == _FALSE) {
|
||||
RTW_INFO(FUNC_ADPT_FMT" ssid:%p, ssid_valid:%d, bssid:%p, bssid_valid:%d\n",
|
||||
FUNC_ADPT_ARG(padapter), ssid, ssid_valid, bssid, bssid_valid);
|
||||
status = _FAIL;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (!rtw_is_hw_init_completed(padapter)) {
|
||||
status = _FAIL;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
_enter_critical_bh(&pmlmepriv->lock, &irqL);
|
||||
|
||||
RTW_PRINT(FUNC_ADPT_FMT" fw_state=0x%08x\n",
|
||||
FUNC_ADPT_ARG(padapter), get_fwstate(pmlmepriv));
|
||||
|
||||
if (check_fwstate(pmlmepriv, WIFI_UNDER_SURVEY) == _TRUE)
|
||||
goto handle_tkip_countermeasure;
|
||||
else if (check_fwstate(pmlmepriv, WIFI_UNDER_LINKING) == _TRUE)
|
||||
goto release_mlme_lock;
|
||||
|
||||
handle_tkip_countermeasure:
|
||||
if (rtw_handle_tkip_countermeasure(padapter, __func__) == _FAIL) {
|
||||
status = _FAIL;
|
||||
goto release_mlme_lock;
|
||||
}
|
||||
|
||||
if (ssid && ssid_valid)
|
||||
_rtw_memcpy(&pmlmepriv->assoc_ssid, ssid, sizeof(NDIS_802_11_SSID));
|
||||
else
|
||||
_rtw_memset(&pmlmepriv->assoc_ssid, 0, sizeof(NDIS_802_11_SSID));
|
||||
|
||||
if (bssid && bssid_valid) {
|
||||
_rtw_memcpy(&pmlmepriv->assoc_bssid, bssid, ETH_ALEN);
|
||||
pmlmepriv->assoc_by_bssid = _TRUE;
|
||||
} else
|
||||
pmlmepriv->assoc_by_bssid = _FALSE;
|
||||
|
||||
pmlmepriv->assoc_ch = ch;
|
||||
|
||||
if (check_fwstate(pmlmepriv, WIFI_UNDER_SURVEY) == _TRUE)
|
||||
pmlmepriv->to_join = _TRUE;
|
||||
else
|
||||
status = rtw_do_join(padapter);
|
||||
|
||||
release_mlme_lock:
|
||||
_exit_critical_bh(&pmlmepriv->lock, &irqL);
|
||||
|
||||
exit:
|
||||
return status;
|
||||
}
|
||||
|
||||
u8 rtw_set_802_11_infrastructure_mode(_adapter *padapter,
|
||||
NDIS_802_11_NETWORK_INFRASTRUCTURE networktype, u8 flags)
|
||||
{
|
||||
_irqL irqL;
|
||||
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
|
||||
struct wlan_network *cur_network = &pmlmepriv->cur_network;
|
||||
NDIS_802_11_NETWORK_INFRASTRUCTURE *pold_state = &(cur_network->network.InfrastructureMode);
|
||||
u8 ap2sta_mode = _FALSE;
|
||||
u8 ret = _TRUE;
|
||||
u8 is_linked = _FALSE, is_adhoc_master = _FALSE;
|
||||
|
||||
if (*pold_state != networktype) {
|
||||
/* RTW_INFO("change mode, old_mode=%d, new_mode=%d, fw_state=0x%x\n", *pold_state, networktype, get_fwstate(pmlmepriv)); */
|
||||
|
||||
if (*pold_state == Ndis802_11APMode
|
||||
|| *pold_state == Ndis802_11_mesh
|
||||
) {
|
||||
/* change to other mode from Ndis802_11APMode/Ndis802_11_mesh */
|
||||
cur_network->join_res = -1;
|
||||
ap2sta_mode = _TRUE;
|
||||
#ifdef CONFIG_NATIVEAP_MLME
|
||||
stop_ap_mode(padapter);
|
||||
#endif
|
||||
}
|
||||
|
||||
_enter_critical_bh(&pmlmepriv->lock, &irqL);
|
||||
is_linked = check_fwstate(pmlmepriv, WIFI_ASOC_STATE);
|
||||
is_adhoc_master = check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE);
|
||||
|
||||
/* flags = 0, means enqueue cmd and no wait */
|
||||
if (flags != 0)
|
||||
_exit_critical_bh(&pmlmepriv->lock, &irqL);
|
||||
|
||||
if ((is_linked == _TRUE) || (*pold_state == Ndis802_11IBSS))
|
||||
rtw_disassoc_cmd(padapter, 0, flags);
|
||||
|
||||
if ((is_linked == _TRUE) ||
|
||||
(is_adhoc_master == _TRUE))
|
||||
rtw_free_assoc_resources_cmd(padapter, _TRUE, flags);
|
||||
|
||||
if ((*pold_state == Ndis802_11Infrastructure) || (*pold_state == Ndis802_11IBSS)) {
|
||||
if (is_linked == _TRUE) {
|
||||
rtw_indicate_disconnect(padapter, 0, _FALSE); /*will clr Linked_state; before this function, we must have checked whether issue dis-assoc_cmd or not*/
|
||||
}
|
||||
}
|
||||
|
||||
/* flags = 0, means enqueue cmd and no wait */
|
||||
if (flags != 0)
|
||||
_enter_critical_bh(&pmlmepriv->lock, &irqL);
|
||||
|
||||
*pold_state = networktype;
|
||||
|
||||
_clr_fwstate_(pmlmepriv, ~WIFI_NULL_STATE);
|
||||
|
||||
switch (networktype) {
|
||||
case Ndis802_11IBSS:
|
||||
set_fwstate(pmlmepriv, WIFI_ADHOC_STATE);
|
||||
break;
|
||||
|
||||
case Ndis802_11Infrastructure:
|
||||
set_fwstate(pmlmepriv, WIFI_STATION_STATE);
|
||||
|
||||
if (ap2sta_mode)
|
||||
rtw_init_bcmc_stainfo(padapter);
|
||||
break;
|
||||
|
||||
case Ndis802_11APMode:
|
||||
set_fwstate(pmlmepriv, WIFI_AP_STATE);
|
||||
#ifdef CONFIG_NATIVEAP_MLME
|
||||
start_ap_mode(padapter);
|
||||
/* rtw_indicate_connect(padapter); */
|
||||
#endif
|
||||
|
||||
break;
|
||||
|
||||
#ifdef CONFIG_RTW_MESH
|
||||
case Ndis802_11_mesh:
|
||||
set_fwstate(pmlmepriv, WIFI_MESH_STATE);
|
||||
start_ap_mode(padapter);
|
||||
break;
|
||||
#endif
|
||||
|
||||
case Ndis802_11AutoUnknown:
|
||||
case Ndis802_11InfrastructureMax:
|
||||
break;
|
||||
#ifdef CONFIG_WIFI_MONITOR
|
||||
case Ndis802_11Monitor:
|
||||
set_fwstate(pmlmepriv, WIFI_MONITOR_STATE);
|
||||
break;
|
||||
#endif /* CONFIG_WIFI_MONITOR */
|
||||
default:
|
||||
ret = _FALSE;
|
||||
rtw_warn_on(1);
|
||||
}
|
||||
|
||||
/* SecClearAllKeys(adapter); */
|
||||
|
||||
|
||||
_exit_critical_bh(&pmlmepriv->lock, &irqL);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
u8 rtw_set_802_11_disassociate(_adapter *padapter)
|
||||
{
|
||||
_irqL irqL;
|
||||
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
|
||||
|
||||
|
||||
_enter_critical_bh(&pmlmepriv->lock, &irqL);
|
||||
|
||||
if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == _TRUE) {
|
||||
|
||||
rtw_disassoc_cmd(padapter, 0, 0);
|
||||
rtw_indicate_disconnect(padapter, 0, _FALSE);
|
||||
/* modify for CONFIG_IEEE80211W, none 11w can use it */
|
||||
rtw_free_assoc_resources_cmd(padapter, _TRUE, 0);
|
||||
if (_FAIL == rtw_pwr_wakeup(padapter))
|
||||
RTW_INFO("%s(): rtw_pwr_wakeup fail !!!\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
_exit_critical_bh(&pmlmepriv->lock, &irqL);
|
||||
|
||||
|
||||
return _TRUE;
|
||||
}
|
||||
|
||||
#if 1
|
||||
u8 rtw_set_802_11_bssid_list_scan(_adapter *padapter, struct sitesurvey_parm *pparm)
|
||||
{
|
||||
_irqL irqL;
|
||||
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
|
||||
u8 res = _TRUE;
|
||||
|
||||
_enter_critical_bh(&pmlmepriv->lock, &irqL);
|
||||
res = rtw_sitesurvey_cmd(padapter, pparm);
|
||||
_exit_critical_bh(&pmlmepriv->lock, &irqL);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
#else
|
||||
u8 rtw_set_802_11_bssid_list_scan(_adapter *padapter, struct sitesurvey_parm *pparm)
|
||||
{
|
||||
_irqL irqL;
|
||||
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
|
||||
u8 res = _TRUE;
|
||||
|
||||
|
||||
|
||||
if (padapter == NULL) {
|
||||
res = _FALSE;
|
||||
goto exit;
|
||||
}
|
||||
if (!rtw_is_hw_init_completed(padapter)) {
|
||||
res = _FALSE;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if ((check_fwstate(pmlmepriv, WIFI_UNDER_SURVEY | WIFI_UNDER_LINKING) == _TRUE) ||
|
||||
(pmlmepriv->LinkDetectInfo.bBusyTraffic == _TRUE)) {
|
||||
/* Scan or linking is in progress, do nothing. */
|
||||
res = _TRUE;
|
||||
|
||||
|
||||
} else {
|
||||
if (rtw_is_scan_deny(padapter)) {
|
||||
RTW_INFO(FUNC_ADPT_FMT": scan deny\n", FUNC_ADPT_ARG(padapter));
|
||||
indicate_wx_scan_complete_event(padapter);
|
||||
return _SUCCESS;
|
||||
}
|
||||
|
||||
_enter_critical_bh(&pmlmepriv->lock, &irqL);
|
||||
|
||||
res = rtw_sitesurvey_cmd(padapter, pparm);
|
||||
|
||||
_exit_critical_bh(&pmlmepriv->lock, &irqL);
|
||||
}
|
||||
exit:
|
||||
|
||||
|
||||
return res;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_RTW_ACS
|
||||
u8 rtw_set_acs_sitesurvey(_adapter *adapter)
|
||||
{
|
||||
struct rf_ctl_t *rfctl = adapter_to_rfctl(adapter);
|
||||
struct sitesurvey_parm *parm = NULL;
|
||||
u8 uch;
|
||||
u8 ch_num = 0;
|
||||
int i;
|
||||
BAND_TYPE band;
|
||||
u8 (*center_chs_num)(u8) = NULL;
|
||||
u8 (*center_chs)(u8, u8) = NULL;
|
||||
u8 ret = _FAIL;
|
||||
|
||||
if (!rtw_mi_get_ch_setting_union(adapter, &uch, NULL, NULL))
|
||||
goto exit;
|
||||
|
||||
parm = (struct sitesurvey_parm *)rtw_zmalloc(sizeof(struct sitesurvey_parm));
|
||||
if (!parm)
|
||||
return ret;
|
||||
parm->scan_mode = SCAN_PASSIVE;
|
||||
parm->bw = CHANNEL_WIDTH_20;
|
||||
parm->acs = 1;
|
||||
|
||||
for (band = BAND_ON_2_4G; band < BAND_MAX; band++) {
|
||||
if (band == BAND_ON_2_4G) {
|
||||
center_chs_num = center_chs_2g_num;
|
||||
center_chs = center_chs_2g;
|
||||
} else
|
||||
#if CONFIG_IEEE80211_BAND_5GHZ
|
||||
if (band == BAND_ON_5G) {
|
||||
center_chs_num = center_chs_5g_num;
|
||||
center_chs = center_chs_5g;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
center_chs_num = NULL;
|
||||
center_chs = NULL;
|
||||
}
|
||||
|
||||
if (!center_chs_num || !center_chs)
|
||||
continue;
|
||||
|
||||
if (rfctl->ch_sel_within_same_band) {
|
||||
if (rtw_is_2g_ch(uch) && band != BAND_ON_2_4G)
|
||||
continue;
|
||||
#if CONFIG_IEEE80211_BAND_5GHZ
|
||||
if (rtw_is_5g_ch(uch) && band != BAND_ON_5G)
|
||||
continue;
|
||||
#endif
|
||||
}
|
||||
|
||||
ch_num = center_chs_num(CHANNEL_WIDTH_20);
|
||||
for (i = 0; i < ch_num && parm->ch_num < RTW_CHANNEL_SCAN_AMOUNT; i++) {
|
||||
parm->ch[parm->ch_num].hw_value = center_chs(CHANNEL_WIDTH_20, i);
|
||||
parm->ch[parm->ch_num].flags = RTW_IEEE80211_CHAN_PASSIVE_SCAN;
|
||||
parm->ch_num++;
|
||||
}
|
||||
}
|
||||
|
||||
ret = rtw_set_802_11_bssid_list_scan(adapter, parm);
|
||||
if (parm)
|
||||
rtw_mfree(parm, sizeof(struct sitesurvey_parm));
|
||||
exit:
|
||||
return ret;
|
||||
}
|
||||
#endif /* CONFIG_RTW_ACS */
|
||||
|
||||
u8 rtw_set_802_11_authentication_mode(_adapter *padapter, NDIS_802_11_AUTHENTICATION_MODE authmode)
|
||||
{
|
||||
struct security_priv *psecuritypriv = &padapter->securitypriv;
|
||||
int res;
|
||||
u8 ret;
|
||||
|
||||
|
||||
|
||||
psecuritypriv->ndisauthtype = authmode;
|
||||
|
||||
|
||||
if (psecuritypriv->ndisauthtype > 3)
|
||||
psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
|
||||
|
||||
#ifdef CONFIG_WAPI_SUPPORT
|
||||
if (psecuritypriv->ndisauthtype == 6)
|
||||
psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_WAPI;
|
||||
#endif
|
||||
|
||||
res = rtw_set_auth(padapter, psecuritypriv);
|
||||
|
||||
if (res == _SUCCESS)
|
||||
ret = _TRUE;
|
||||
else
|
||||
ret = _FALSE;
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
u8 rtw_set_802_11_add_wep(_adapter *padapter, NDIS_802_11_WEP *wep)
|
||||
{
|
||||
|
||||
/*u8 bdefaultkey;*/
|
||||
/*u8 btransmitkey;*/
|
||||
sint keyid, res;
|
||||
struct security_priv *psecuritypriv = &(padapter->securitypriv);
|
||||
u8 ret = _SUCCESS;
|
||||
|
||||
|
||||
/*bdefaultkey = (wep->KeyIndex & 0x40000000) > 0 ? _FALSE : _TRUE;*/
|
||||
/*btransmitkey = (wep->KeyIndex & 0x80000000) > 0 ? _TRUE : _FALSE;*/
|
||||
keyid = wep->KeyIndex & 0x3fffffff;
|
||||
|
||||
if (keyid >= 4) {
|
||||
ret = _FALSE;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
switch (wep->KeyLength) {
|
||||
case 5:
|
||||
psecuritypriv->dot11PrivacyAlgrthm = _WEP40_;
|
||||
break;
|
||||
case 13:
|
||||
psecuritypriv->dot11PrivacyAlgrthm = _WEP104_;
|
||||
break;
|
||||
default:
|
||||
psecuritypriv->dot11PrivacyAlgrthm = _NO_PRIVACY_;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
_rtw_memcpy(&(psecuritypriv->dot11DefKey[keyid].skey[0]), &(wep->KeyMaterial), wep->KeyLength);
|
||||
|
||||
psecuritypriv->dot11DefKeylen[keyid] = wep->KeyLength;
|
||||
|
||||
psecuritypriv->dot11PrivacyKeyIndex = keyid;
|
||||
|
||||
|
||||
res = rtw_set_key(padapter, psecuritypriv, keyid, 1, _TRUE);
|
||||
|
||||
if (res == _FAIL)
|
||||
ret = _FALSE;
|
||||
|
||||
exit:
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* rtw_get_cur_max_rate -
|
||||
* @adapter: pointer to _adapter structure
|
||||
*
|
||||
* Return 0 or 100Kbps
|
||||
*/
|
||||
u16 rtw_get_cur_max_rate(_adapter *adapter)
|
||||
{
|
||||
int j;
|
||||
int i = 0;
|
||||
u16 rate = 0, max_rate = 0;
|
||||
struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
|
||||
WLAN_BSSID_EX *pcur_bss = &pmlmepriv->cur_network.network;
|
||||
int sta_bssrate_len = 0;
|
||||
unsigned char sta_bssrate[NumRates];
|
||||
struct sta_info *psta = NULL;
|
||||
u8 short_GI = 0;
|
||||
|
||||
#ifdef CONFIG_MP_INCLUDED
|
||||
if (adapter->registrypriv.mp_mode == 1) {
|
||||
if (check_fwstate(pmlmepriv, WIFI_MP_STATE) == _TRUE)
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((check_fwstate(pmlmepriv, WIFI_ASOC_STATE) != _TRUE)
|
||||
&& (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) != _TRUE))
|
||||
return 0;
|
||||
|
||||
psta = rtw_get_stainfo(&adapter->stapriv, get_bssid(pmlmepriv));
|
||||
if (psta == NULL)
|
||||
return 0;
|
||||
|
||||
short_GI = query_ra_short_GI(psta, rtw_get_tx_bw_mode(adapter, psta));
|
||||
|
||||
#ifdef CONFIG_80211N_HT
|
||||
if (is_highest_support_ht(psta->wireless_mode)) {
|
||||
max_rate = rtw_ht_mcs_rate((psta->cmn.bw_mode == CHANNEL_WIDTH_40) ? 1 : 0
|
||||
, short_GI
|
||||
, psta->htpriv.ht_cap.supp_mcs_set
|
||||
);
|
||||
}
|
||||
#ifdef CONFIG_80211AC_VHT
|
||||
else if (is_highest_support_vht(psta->wireless_mode))
|
||||
max_rate = ((rtw_vht_mcs_to_data_rate(psta->cmn.bw_mode, short_GI, pmlmepriv->vhtpriv.vht_highest_rate) + 1) >> 1) * 10;
|
||||
#endif /* CONFIG_80211AC_VHT */
|
||||
else
|
||||
#endif /* CONFIG_80211N_HT */
|
||||
{
|
||||
/*station mode show :station && ap support rate; softap :show ap support rate*/
|
||||
if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) == _TRUE)
|
||||
get_rate_set(adapter, sta_bssrate, &sta_bssrate_len);/*get sta rate and length*/
|
||||
|
||||
|
||||
while ((pcur_bss->SupportedRates[i] != 0) && (pcur_bss->SupportedRates[i] != 0xFF)) {
|
||||
rate = pcur_bss->SupportedRates[i] & 0x7F;/*AP support rates*/
|
||||
/*RTW_INFO("%s rate=%02X \n", __func__, rate);*/
|
||||
|
||||
/*check STA support rate or not */
|
||||
if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) == _TRUE) {
|
||||
for (j = 0; j < sta_bssrate_len; j++) {
|
||||
/* Avoid the proprietary data rate (22Mbps) of Handlink WSG-4000 AP */
|
||||
if ((rate | IEEE80211_BASIC_RATE_MASK)
|
||||
== (sta_bssrate[j] | IEEE80211_BASIC_RATE_MASK)) {
|
||||
if (rate > max_rate) {
|
||||
max_rate = rate;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
if (rate > max_rate)
|
||||
max_rate = rate;
|
||||
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
max_rate = max_rate * 10 / 2;
|
||||
}
|
||||
return max_rate;
|
||||
}
|
||||
|
||||
/*
|
||||
* rtw_set_scan_mode -
|
||||
* @adapter: pointer to _adapter structure
|
||||
* @scan_mode:
|
||||
*
|
||||
* Return _SUCCESS or _FAIL
|
||||
*/
|
||||
int rtw_set_scan_mode(_adapter *adapter, RT_SCAN_TYPE scan_mode)
|
||||
{
|
||||
if (scan_mode != SCAN_ACTIVE && scan_mode != SCAN_PASSIVE)
|
||||
return _FAIL;
|
||||
|
||||
adapter->mlmepriv.scan_mode = scan_mode;
|
||||
|
||||
return _SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
* rtw_set_channel_plan -
|
||||
* @adapter: pointer to _adapter structure
|
||||
* @channel_plan:
|
||||
*
|
||||
* Return _SUCCESS or _FAIL
|
||||
*/
|
||||
int rtw_set_channel_plan(_adapter *adapter, u8 channel_plan, u8 chplan_6g, enum rtw_regd_inr inr)
|
||||
{
|
||||
struct registry_priv *regsty = adapter_to_regsty(adapter);
|
||||
|
||||
if (!REGSTY_REGD_SRC_FROM_OS(regsty))
|
||||
return rtw_set_chplan_cmd(adapter, RTW_CMDF_WAIT_ACK, channel_plan, chplan_6g, inr);
|
||||
RTW_WARN("%s(): not applied\n", __func__);
|
||||
return _SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
* rtw_set_country -
|
||||
* @adapter: pointer to _adapter structure
|
||||
* @country_code: string of country code
|
||||
*
|
||||
* Return _SUCCESS or _FAIL
|
||||
*/
|
||||
int rtw_set_country(_adapter *adapter, const char *country_code, enum rtw_regd_inr inr)
|
||||
{
|
||||
#ifdef CONFIG_RTW_IOCTL_SET_COUNTRY
|
||||
#if ((0 - CONFIG_RTW_IOCTL_SET_COUNTRY - 1) == 1) && ((CONFIG_RTW_IOCTL_SET_COUNTRY + 0) != -2) /* defined to empty */
|
||||
#undef CONFIG_RTW_IOCTL_SET_COUNTRY
|
||||
#define CONFIG_RTW_IOCTL_SET_COUNTRY 1
|
||||
#endif
|
||||
#else /* not defined */
|
||||
#define CONFIG_RTW_IOCTL_SET_COUNTRY 1
|
||||
#endif
|
||||
|
||||
#if CONFIG_RTW_IOCTL_SET_COUNTRY
|
||||
struct registry_priv *regsty = adapter_to_regsty(adapter);
|
||||
|
||||
if (!REGSTY_REGD_SRC_FROM_OS(regsty))
|
||||
return rtw_set_country_cmd(adapter, RTW_CMDF_WAIT_ACK, country_code, inr);
|
||||
#endif
|
||||
RTW_WARN("%s(): not applied\n", __func__);
|
||||
return _SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
* rtw_set_band -
|
||||
* @adapter: pointer to _adapter structure
|
||||
* @band: band to set
|
||||
*
|
||||
* Return _SUCCESS or _FAIL
|
||||
*/
|
||||
int rtw_set_band(_adapter *adapter, u8 band)
|
||||
{
|
||||
if (rtw_band_valid(band)) {
|
||||
RTW_INFO(FUNC_ADPT_FMT" band:%d\n", FUNC_ADPT_ARG(adapter), band);
|
||||
adapter->setband = band;
|
||||
return _SUCCESS;
|
||||
}
|
||||
|
||||
RTW_PRINT(FUNC_ADPT_FMT" band:%d fail\n", FUNC_ADPT_ARG(adapter), band);
|
||||
return _FAIL;
|
||||
}
|
||||
388
drivers/net/wireless/rtl8822cs/core/rtw_iol.c
Normal file
388
drivers/net/wireless/rtl8822cs/core/rtw_iol.c
Normal file
@@ -0,0 +1,388 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright(c) 2007 - 2017 Realtek Corporation.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of version 2 of the GNU General Public License as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#include <drv_types.h>
|
||||
|
||||
#ifdef CONFIG_IOL
|
||||
struct xmit_frame *rtw_IOL_accquire_xmit_frame(ADAPTER *adapter)
|
||||
{
|
||||
struct xmit_frame *xmit_frame;
|
||||
struct xmit_buf *xmitbuf;
|
||||
struct pkt_attrib *pattrib;
|
||||
struct xmit_priv *pxmitpriv = &(adapter->xmitpriv);
|
||||
|
||||
#if 1
|
||||
xmit_frame = rtw_alloc_xmitframe(pxmitpriv, 0);
|
||||
if (xmit_frame == NULL) {
|
||||
RTW_INFO("%s rtw_alloc_xmitframe return null\n", __FUNCTION__);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
xmitbuf = rtw_alloc_xmitbuf(pxmitpriv);
|
||||
if (xmitbuf == NULL) {
|
||||
RTW_INFO("%s rtw_alloc_xmitbuf return null\n", __FUNCTION__);
|
||||
rtw_free_xmitframe(pxmitpriv, xmit_frame);
|
||||
xmit_frame = NULL;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
xmit_frame->frame_tag = MGNT_FRAMETAG;
|
||||
xmit_frame->pxmitbuf = xmitbuf;
|
||||
xmit_frame->buf_addr = xmitbuf->pbuf;
|
||||
xmitbuf->priv_data = xmit_frame;
|
||||
|
||||
pattrib = &xmit_frame->attrib;
|
||||
update_mgntframe_attrib(adapter, pattrib);
|
||||
pattrib->qsel = QSLT_BEACON;/* Beacon */
|
||||
pattrib->subtype = WIFI_BEACON;
|
||||
pattrib->pktlen = pattrib->last_txcmdsz = 0;
|
||||
|
||||
#else
|
||||
xmit_frame = alloc_mgtxmitframe(pxmitpriv);
|
||||
if (xmit_frame == NULL)
|
||||
RTW_INFO("%s alloc_mgtxmitframe return null\n", __FUNCTION__);
|
||||
else {
|
||||
pattrib = &xmit_frame->attrib;
|
||||
update_mgntframe_attrib(adapter, pattrib);
|
||||
pattrib->qsel = QSLT_BEACON;
|
||||
pattrib->pktlen = pattrib->last_txcmdsz = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
exit:
|
||||
return xmit_frame;
|
||||
}
|
||||
|
||||
|
||||
int rtw_IOL_append_cmds(struct xmit_frame *xmit_frame, u8 *IOL_cmds, u32 cmd_len)
|
||||
{
|
||||
struct pkt_attrib *pattrib = &xmit_frame->attrib;
|
||||
u16 buf_offset;
|
||||
u32 ori_len;
|
||||
|
||||
buf_offset = TXDESC_OFFSET;
|
||||
ori_len = buf_offset + pattrib->pktlen;
|
||||
|
||||
/* check if the io_buf can accommodate new cmds */
|
||||
if (ori_len + cmd_len + 8 > MAX_XMITBUF_SZ) {
|
||||
RTW_INFO("%s %u is large than MAX_XMITBUF_SZ:%u, can't accommodate new cmds\n", __FUNCTION__
|
||||
, ori_len + cmd_len + 8, MAX_XMITBUF_SZ);
|
||||
return _FAIL;
|
||||
}
|
||||
|
||||
_rtw_memcpy(xmit_frame->buf_addr + buf_offset + pattrib->pktlen, IOL_cmds, cmd_len);
|
||||
pattrib->pktlen += cmd_len;
|
||||
pattrib->last_txcmdsz += cmd_len;
|
||||
|
||||
/* RTW_INFO("%s ori:%u + cmd_len:%u = %u\n", __FUNCTION__, ori_len, cmd_len, buf_offset+pattrib->pktlen); */
|
||||
|
||||
return _SUCCESS;
|
||||
}
|
||||
|
||||
bool rtw_IOL_applied(ADAPTER *adapter)
|
||||
{
|
||||
if (1 == adapter->registrypriv.fw_iol)
|
||||
return _TRUE;
|
||||
|
||||
#ifdef CONFIG_USB_HCI
|
||||
if ((2 == adapter->registrypriv.fw_iol) && (IS_FULL_SPEED_USB(adapter)))
|
||||
return _TRUE;
|
||||
#endif
|
||||
|
||||
return _FALSE;
|
||||
}
|
||||
|
||||
int rtw_IOL_exec_cmds_sync(ADAPTER *adapter, struct xmit_frame *xmit_frame, u32 max_wating_ms, u32 bndy_cnt)
|
||||
{
|
||||
return rtw_hal_iol_cmd(adapter, xmit_frame, max_wating_ms, bndy_cnt);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_IOL_NEW_GENERATION
|
||||
int rtw_IOL_append_LLT_cmd(struct xmit_frame *xmit_frame, u8 page_boundary)
|
||||
{
|
||||
return _SUCCESS;
|
||||
}
|
||||
int _rtw_IOL_append_WB_cmd(struct xmit_frame *xmit_frame, u16 addr, u8 value, u8 mask)
|
||||
{
|
||||
struct ioreg_cfg cmd = {8, IOREG_CMD_WB_REG, 0x0, 0x0, 0x0};
|
||||
|
||||
/* RTW_PUT_LE16((u8*)&cmd.address, addr); */
|
||||
/* RTW_PUT_LE32((u8*)&cmd.value, (u32)value); */
|
||||
cmd.address = cpu_to_le16(addr);
|
||||
cmd.data = cpu_to_le32(value);
|
||||
|
||||
if (mask != 0xFF) {
|
||||
cmd.length = 12;
|
||||
/* RTW_PUT_LE32((u8*)&cmd.mask, (u32)mask); */
|
||||
cmd.mask = cpu_to_le32(mask);
|
||||
}
|
||||
|
||||
/* RTW_INFO("%s addr:0x%04x,value:0x%08x,mask:0x%08x\n", __FUNCTION__, addr,value,mask); */
|
||||
|
||||
return rtw_IOL_append_cmds(xmit_frame, (u8 *)&cmd, cmd.length);
|
||||
|
||||
}
|
||||
int _rtw_IOL_append_WW_cmd(struct xmit_frame *xmit_frame, u16 addr, u16 value, u16 mask)
|
||||
{
|
||||
struct ioreg_cfg cmd = {8, IOREG_CMD_WW_REG, 0x0, 0x0, 0x0};
|
||||
|
||||
/* RTW_PUT_LE16((u8*)&cmd.address, addr); */
|
||||
/* RTW_PUT_LE32((u8*)&cmd.value, (u32)value); */
|
||||
cmd.address = cpu_to_le16(addr);
|
||||
cmd.data = cpu_to_le32(value);
|
||||
|
||||
if (mask != 0xFFFF) {
|
||||
cmd.length = 12;
|
||||
/* RTW_PUT_LE32((u8*)&cmd.mask, (u32)mask); */
|
||||
cmd.mask = cpu_to_le32(mask);
|
||||
}
|
||||
|
||||
/* RTW_INFO("%s addr:0x%04x,value:0x%08x,mask:0x%08x\n", __FUNCTION__, addr,value,mask); */
|
||||
|
||||
return rtw_IOL_append_cmds(xmit_frame, (u8 *)&cmd, cmd.length);
|
||||
|
||||
}
|
||||
int _rtw_IOL_append_WD_cmd(struct xmit_frame *xmit_frame, u16 addr, u32 value, u32 mask)
|
||||
{
|
||||
struct ioreg_cfg cmd = {8, IOREG_CMD_WD_REG, 0x0, 0x0, 0x0};
|
||||
|
||||
/* RTW_PUT_LE16((u8*)&cmd.address, addr); */
|
||||
/* RTW_PUT_LE32((u8*)&cmd.value, (u32)value); */
|
||||
cmd.address = cpu_to_le16(addr);
|
||||
cmd.data = cpu_to_le32(value);
|
||||
|
||||
if (mask != 0xFFFFFFFF) {
|
||||
cmd.length = 12;
|
||||
/* RTW_PUT_LE32((u8*)&cmd.mask, (u32)mask); */
|
||||
cmd.mask = cpu_to_le32(mask);
|
||||
}
|
||||
|
||||
/* RTW_INFO("%s addr:0x%04x,value:0x%08x,mask:0x%08x\n", __FU2NCTION__, addr,value,mask); */
|
||||
|
||||
return rtw_IOL_append_cmds(xmit_frame, (u8 *)&cmd, cmd.length);
|
||||
|
||||
}
|
||||
|
||||
int _rtw_IOL_append_WRF_cmd(struct xmit_frame *xmit_frame, u8 rf_path, u16 addr, u32 value, u32 mask)
|
||||
{
|
||||
struct ioreg_cfg cmd = {8, IOREG_CMD_W_RF, 0x0, 0x0, 0x0};
|
||||
|
||||
/* RTW_PUT_LE16((u8*)&cmd.address, addr); */
|
||||
/* RTW_PUT_LE32((u8*)&cmd.value, (u32)value); */
|
||||
cmd.address = (rf_path << 8) | ((addr) & 0xFF);
|
||||
cmd.data = cpu_to_le32(value);
|
||||
|
||||
if (mask != 0x000FFFFF) {
|
||||
cmd.length = 12;
|
||||
/* RTW_PUT_LE32((u8*)&cmd.mask, (u32)mask); */
|
||||
cmd.mask = cpu_to_le32(mask);
|
||||
}
|
||||
|
||||
/* RTW_INFO("%s rf_path:0x%02x addr:0x%04x,value:0x%08x,mask:0x%08x\n", __FU2NCTION__,rf_path, addr,value,mask); */
|
||||
|
||||
return rtw_IOL_append_cmds(xmit_frame, (u8 *)&cmd, cmd.length);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
int rtw_IOL_append_DELAY_US_cmd(struct xmit_frame *xmit_frame, u16 us)
|
||||
{
|
||||
struct ioreg_cfg cmd = {4, IOREG_CMD_DELAY_US, 0x0, 0x0, 0x0};
|
||||
/* RTW_PUT_LE16((u8*)&cmd.address, us); */
|
||||
cmd.address = cpu_to_le16(us);
|
||||
|
||||
/* RTW_INFO("%s %u\n", __FUNCTION__, us); */
|
||||
return rtw_IOL_append_cmds(xmit_frame, (u8 *)&cmd, 4);
|
||||
}
|
||||
|
||||
int rtw_IOL_append_DELAY_MS_cmd(struct xmit_frame *xmit_frame, u16 ms)
|
||||
{
|
||||
struct ioreg_cfg cmd = {4, IOREG_CMD_DELAY_US, 0x0, 0x0, 0x0};
|
||||
|
||||
/* RTW_PUT_LE16((u8*)&cmd.address, ms); */
|
||||
cmd.address = cpu_to_le16(ms);
|
||||
|
||||
/* RTW_INFO("%s %u\n", __FUNCTION__, ms); */
|
||||
return rtw_IOL_append_cmds(xmit_frame, (u8 *)&cmd, 4);
|
||||
}
|
||||
int rtw_IOL_append_END_cmd(struct xmit_frame *xmit_frame)
|
||||
{
|
||||
struct ioreg_cfg cmd = {4, IOREG_CMD_END, 0xFFFF, 0xFF, 0x0};
|
||||
return rtw_IOL_append_cmds(xmit_frame, (u8 *)&cmd, 4);
|
||||
|
||||
}
|
||||
|
||||
u8 rtw_IOL_cmd_boundary_handle(struct xmit_frame *pxmit_frame)
|
||||
{
|
||||
u8 is_cmd_bndy = _FALSE;
|
||||
if (((pxmit_frame->attrib.pktlen + 32) % 256) + 8 >= 256) {
|
||||
rtw_IOL_append_END_cmd(pxmit_frame);
|
||||
pxmit_frame->attrib.pktlen = ((((pxmit_frame->attrib.pktlen + 32) / 256) + 1) * 256);
|
||||
|
||||
/* printk("==> %s, pktlen(%d)\n",__FUNCTION__,pxmit_frame->attrib.pktlen); */
|
||||
pxmit_frame->attrib.last_txcmdsz = pxmit_frame->attrib.pktlen;
|
||||
is_cmd_bndy = _TRUE;
|
||||
}
|
||||
return is_cmd_bndy;
|
||||
}
|
||||
|
||||
void rtw_IOL_cmd_buf_dump(ADAPTER *Adapter, int buf_len, u8 *pbuf)
|
||||
{
|
||||
int i;
|
||||
int j = 1;
|
||||
|
||||
printk("###### %s ######\n", __FUNCTION__);
|
||||
for (i = 0; i < buf_len; i++) {
|
||||
printk("%02x-", *(pbuf + i));
|
||||
|
||||
if (j % 32 == 0)
|
||||
printk("\n");
|
||||
j++;
|
||||
}
|
||||
printk("\n");
|
||||
printk("============= ioreg_cmd len = %d ===============\n", buf_len);
|
||||
}
|
||||
|
||||
|
||||
#else /* CONFIG_IOL_NEW_GENERATION */
|
||||
int rtw_IOL_append_LLT_cmd(struct xmit_frame *xmit_frame, u8 page_boundary)
|
||||
{
|
||||
IOL_CMD cmd = {0x0, IOL_CMD_LLT, 0x0, 0x0};
|
||||
|
||||
RTW_PUT_BE32((u8 *)&cmd.value, (u32)page_boundary);
|
||||
|
||||
return rtw_IOL_append_cmds(xmit_frame, (u8 *)&cmd, 8);
|
||||
}
|
||||
|
||||
int _rtw_IOL_append_WB_cmd(struct xmit_frame *xmit_frame, u16 addr, u8 value)
|
||||
{
|
||||
IOL_CMD cmd = {0x0, IOL_CMD_WB_REG, 0x0, 0x0};
|
||||
|
||||
RTW_PUT_BE16((u8 *)&cmd.address, (u16)addr);
|
||||
RTW_PUT_BE32((u8 *)&cmd.value, (u32)value);
|
||||
|
||||
return rtw_IOL_append_cmds(xmit_frame, (u8 *)&cmd, 8);
|
||||
}
|
||||
|
||||
int _rtw_IOL_append_WW_cmd(struct xmit_frame *xmit_frame, u16 addr, u16 value)
|
||||
{
|
||||
IOL_CMD cmd = {0x0, IOL_CMD_WW_REG, 0x0, 0x0};
|
||||
|
||||
RTW_PUT_BE16((u8 *)&cmd.address, (u16)addr);
|
||||
RTW_PUT_BE32((u8 *)&cmd.value, (u32)value);
|
||||
|
||||
return rtw_IOL_append_cmds(xmit_frame, (u8 *)&cmd, 8);
|
||||
}
|
||||
|
||||
int _rtw_IOL_append_WD_cmd(struct xmit_frame *xmit_frame, u16 addr, u32 value)
|
||||
{
|
||||
IOL_CMD cmd = {0x0, IOL_CMD_WD_REG, 0x0, 0x0};
|
||||
u8 *pos = (u8 *)&cmd;
|
||||
|
||||
RTW_PUT_BE16((u8 *)&cmd.address, (u16)addr);
|
||||
RTW_PUT_BE32((u8 *)&cmd.value, (u32)value);
|
||||
|
||||
return rtw_IOL_append_cmds(xmit_frame, (u8 *)&cmd, 8);
|
||||
}
|
||||
|
||||
#ifdef DBG_IO
|
||||
int dbg_rtw_IOL_append_WB_cmd(struct xmit_frame *xmit_frame, u16 addr, u8 value, const char *caller, const int line)
|
||||
{
|
||||
if (match_write_sniff(xmit_frame->padapter, addr, 1, value)) {
|
||||
RTW_INFO("DBG_IO %s:%d IOL_WB(0x%04x, 0x%02x)\n"
|
||||
, caller, line, addr, value);
|
||||
}
|
||||
|
||||
return _rtw_IOL_append_WB_cmd(xmit_frame, addr, value);
|
||||
}
|
||||
|
||||
int dbg_rtw_IOL_append_WW_cmd(struct xmit_frame *xmit_frame, u16 addr, u16 value, const char *caller, const int line)
|
||||
{
|
||||
if (match_write_sniff(xmit_frame->padapter, addr, 2, value)) {
|
||||
RTW_INFO("DBG_IO %s:%d IOL_WW(0x%04x, 0x%04x)\n"
|
||||
, caller, line, addr, value);
|
||||
}
|
||||
|
||||
return _rtw_IOL_append_WW_cmd(xmit_frame, addr, value);
|
||||
}
|
||||
|
||||
int dbg_rtw_IOL_append_WD_cmd(struct xmit_frame *xmit_frame, u16 addr, u32 value, const char *caller, const int line)
|
||||
{
|
||||
if (match_write_sniff(xmit_frame->padapter, addr, 4, value)) {
|
||||
RTW_INFO("DBG_IO %s:%d IOL_WD(0x%04x, 0x%08x)\n"
|
||||
, caller, line, addr, value);
|
||||
}
|
||||
|
||||
return _rtw_IOL_append_WD_cmd(xmit_frame, addr, value);
|
||||
}
|
||||
#endif
|
||||
|
||||
int rtw_IOL_append_DELAY_US_cmd(struct xmit_frame *xmit_frame, u16 us)
|
||||
{
|
||||
IOL_CMD cmd = {0x0, IOL_CMD_DELAY_US, 0x0, 0x0};
|
||||
|
||||
RTW_PUT_BE32((u8 *)&cmd.value, (u32)us);
|
||||
|
||||
/* RTW_INFO("%s %u\n", __FUNCTION__, us); */
|
||||
|
||||
return rtw_IOL_append_cmds(xmit_frame, (u8 *)&cmd, 8);
|
||||
}
|
||||
|
||||
int rtw_IOL_append_DELAY_MS_cmd(struct xmit_frame *xmit_frame, u16 ms)
|
||||
{
|
||||
IOL_CMD cmd = {0x0, IOL_CMD_DELAY_MS, 0x0, 0x0};
|
||||
|
||||
RTW_PUT_BE32((u8 *)&cmd.value, (u32)ms);
|
||||
|
||||
/* RTW_INFO("%s %u\n", __FUNCTION__, ms); */
|
||||
|
||||
return rtw_IOL_append_cmds(xmit_frame, (u8 *)&cmd, 8);
|
||||
}
|
||||
|
||||
int rtw_IOL_append_END_cmd(struct xmit_frame *xmit_frame)
|
||||
{
|
||||
IOL_CMD end_cmd = {0x0, IOL_CMD_END, 0x0, 0x0};
|
||||
|
||||
|
||||
return rtw_IOL_append_cmds(xmit_frame, (u8 *)&end_cmd, 8);
|
||||
|
||||
}
|
||||
|
||||
int rtw_IOL_exec_cmd_array_sync(PADAPTER adapter, u8 *IOL_cmds, u32 cmd_num, u32 max_wating_ms)
|
||||
{
|
||||
struct xmit_frame *xmit_frame;
|
||||
|
||||
xmit_frame = rtw_IOL_accquire_xmit_frame(adapter);
|
||||
if (xmit_frame == NULL)
|
||||
return _FAIL;
|
||||
|
||||
if (rtw_IOL_append_cmds(xmit_frame, IOL_cmds, cmd_num << 3) == _FAIL)
|
||||
return _FAIL;
|
||||
|
||||
return rtw_IOL_exec_cmds_sync(adapter, xmit_frame, max_wating_ms, 0);
|
||||
}
|
||||
|
||||
int rtw_IOL_exec_empty_cmds_sync(ADAPTER *adapter, u32 max_wating_ms)
|
||||
{
|
||||
IOL_CMD end_cmd = {0x0, IOL_CMD_END, 0x0, 0x0};
|
||||
return rtw_IOL_exec_cmd_array_sync(adapter, (u8 *)&end_cmd, 1, max_wating_ms);
|
||||
}
|
||||
#endif /* CONFIG_IOL_NEW_GENERATION */
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* CONFIG_IOL */
|
||||
1528
drivers/net/wireless/rtl8822cs/core/rtw_mbo.c
Normal file
1528
drivers/net/wireless/rtl8822cs/core/rtw_mbo.c
Normal file
File diff suppressed because it is too large
Load Diff
40
drivers/net/wireless/rtl8822cs/core/rtw_mem.c
Normal file
40
drivers/net/wireless/rtl8822cs/core/rtw_mem.c
Normal file
@@ -0,0 +1,40 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright(c) 2016 - 2022 Realtek Corporation.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of version 2 of the GNU General Public License as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <drv_types.h>
|
||||
#include <rtw_mem.h>
|
||||
|
||||
extern int rtkm_prealloc_init(void);
|
||||
extern void rtkm_prealloc_destroy(void);
|
||||
|
||||
static int __init rtw_mem_init(void)
|
||||
{
|
||||
rtkm_prealloc_init();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void __exit rtw_mem_exit(void)
|
||||
{
|
||||
rtkm_prealloc_destroy();
|
||||
}
|
||||
|
||||
module_init(rtw_mem_init);
|
||||
module_exit(rtw_mem_exit);
|
||||
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_DESCRIPTION("Realtek Wireless Lan Driver");
|
||||
MODULE_AUTHOR("Realtek Semiconductor Corp.");
|
||||
MODULE_VERSION("DRIVERVERSION");
|
||||
1740
drivers/net/wireless/rtl8822cs/core/rtw_mi.c
Normal file
1740
drivers/net/wireless/rtl8822cs/core/rtw_mi.c
Normal file
File diff suppressed because it is too large
Load Diff
6030
drivers/net/wireless/rtl8822cs/core/rtw_mlme.c
Normal file
6030
drivers/net/wireless/rtl8822cs/core/rtw_mlme.c
Normal file
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user