mirror of
https://github.com/polyfractal/rustl8710.git
synced 2024-12-04 12:10:28 +00:00
Initial checkin
This commit is contained in:
parent
d4f581cea3
commit
34016a7bd3
1285 changed files with 536346 additions and 0 deletions
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
target
|
||||
Cargo.lock
|
||||
application
|
||||
*.o
|
33
Makefile
Normal file
33
Makefile
Normal file
|
@ -0,0 +1,33 @@
|
|||
all: ram_all
|
||||
|
||||
OS := $(shell uname)
|
||||
|
||||
|
||||
.PHONY: ram_all
|
||||
ram_all:
|
||||
@$(MAKE) -f rust.mk
|
||||
@$(MAKE) -f application.mk
|
||||
|
||||
.PHONY: mp
|
||||
mp:
|
||||
@$(MAKE) -f application.mk mp
|
||||
|
||||
.PHONY: clean clean_all
|
||||
clean:
|
||||
@$(MAKE) -f application.mk clean
|
||||
cd src/rust && cargo clean
|
||||
clean_all:
|
||||
@$(MAKE) -f application.mk clean_all
|
||||
|
||||
.PHONY: flash debug ramdebug setup
|
||||
setup:
|
||||
@$(MAKE) -f application.mk $(MAKECMDGOALS)
|
||||
|
||||
flash:
|
||||
@$(MAKE) -f application.mk flashburn
|
||||
|
||||
debug:
|
||||
@$(MAKE) -f application.mk debug
|
||||
|
||||
ramdebug:
|
||||
@$(MAKE) -f application.mk ramdebug
|
563
application.mk
Normal file
563
application.mk
Normal file
|
@ -0,0 +1,563 @@
|
|||
|
||||
# Initialize tool chain
|
||||
# -------------------------------------------------------------------
|
||||
#ARM_GCC_TOOLCHAIN = ../../../tools/arm-none-eabi-gcc/4.8.3-2014q1/
|
||||
AMEBA_TOOLDIR = component/soc/realtek/8195a/misc/iar_utility/common/tools/
|
||||
FLASH_TOOLDIR = component/soc/realtek/8195a/misc/gcc_utility
|
||||
|
||||
CROSS_COMPILE = arm-none-eabi-
|
||||
|
||||
# Compilation tools
|
||||
AR = $(CROSS_COMPILE)ar
|
||||
CC = $(CROSS_COMPILE)gcc
|
||||
AS = $(CROSS_COMPILE)as
|
||||
NM = $(CROSS_COMPILE)nm
|
||||
LD = $(CROSS_COMPILE)gcc
|
||||
GDB = $(CROSS_COMPILE)gdb
|
||||
OBJCOPY = $(CROSS_COMPILE)objcopy
|
||||
OBJDUMP = $(CROSS_COMPILE)objdump
|
||||
|
||||
OS := $(shell uname)
|
||||
|
||||
ifeq ($(findstring CYGWIN, $(OS)), CYGWIN)
|
||||
PICK = $(AMEBA_TOOLDIR)pick.exe
|
||||
PAD = $(AMEBA_TOOLDIR)padding.exe
|
||||
CHKSUM = $(AMEBA_TOOLDIR)checksum.exe
|
||||
else
|
||||
PICK = $(AMEBA_TOOLDIR)pick
|
||||
PAD = $(AMEBA_TOOLDIR)padding
|
||||
CHKSUM = $(AMEBA_TOOLDIR)checksum
|
||||
endif
|
||||
|
||||
# Initialize target name and target object files
|
||||
# -------------------------------------------------------------------
|
||||
|
||||
all: application manipulate_images
|
||||
|
||||
mp: application manipulate_images
|
||||
|
||||
TARGET=application
|
||||
|
||||
OBJ_DIR=$(TARGET)/Debug/obj
|
||||
BIN_DIR=$(TARGET)/Debug/bin
|
||||
|
||||
# Include folder list
|
||||
# -------------------------------------------------------------------
|
||||
|
||||
INCLUDES =
|
||||
INCLUDES += -Isrc/c/inc
|
||||
INCLUDES += -Icomponent/soc/realtek/common/bsp
|
||||
INCLUDES += -Icomponent/os/freertos
|
||||
INCLUDES += -Icomponent/os/freertos/freertos_v8.1.2/Source/include
|
||||
INCLUDES += -Icomponent/os/freertos/freertos_v8.1.2/Source/portable/GCC/ARM_CM3
|
||||
INCLUDES += -Icomponent/os/os_dep/include
|
||||
INCLUDES += -Icomponent/soc/realtek/8195a/misc/driver
|
||||
INCLUDES += -Icomponent/common/api/network/include
|
||||
INCLUDES += -Icomponent/common/api
|
||||
INCLUDES += -Icomponent/common/api/platform
|
||||
INCLUDES += -Icomponent/common/api/wifi
|
||||
INCLUDES += -Icomponent/common/api/wifi/rtw_wpa_supplicant/src
|
||||
INCLUDES += -Icomponent/common/application
|
||||
INCLUDES += -Icomponent/common/application/iotdemokit
|
||||
INCLUDES += -Icomponent/common/application/google
|
||||
INCLUDES += -Icomponent/common/media/framework
|
||||
INCLUDES += -Icomponent/common/example
|
||||
INCLUDES += -Icomponent/common/example/wlan_fast_connect
|
||||
INCLUDES += -Icomponent/common/mbed/api
|
||||
INCLUDES += -Icomponent/common/mbed/hal
|
||||
INCLUDES += -Icomponent/common/mbed/hal_ext
|
||||
INCLUDES += -Icomponent/common/mbed/targets/hal/rtl8195a
|
||||
INCLUDES += -Icomponent/common/network
|
||||
INCLUDES += -Icomponent/common/network/lwip/lwip_v1.4.1/port/realtek/freertos
|
||||
INCLUDES += -Icomponent/common/network/lwip/lwip_v1.4.1/src/include
|
||||
INCLUDES += -Icomponent/common/network/lwip/lwip_v1.4.1/src/include/lwip
|
||||
INCLUDES += -Icomponent/common/network/lwip/lwip_v1.4.1/src/include/ipv4
|
||||
INCLUDES += -Icomponent/common/network/lwip/lwip_v1.4.1/port/realtek
|
||||
INCLUDES += -Icomponent/common/test
|
||||
INCLUDES += -Icomponent/soc/realtek/8195a/cmsis
|
||||
INCLUDES += -Icomponent/soc/realtek/8195a/cmsis/device
|
||||
INCLUDES += -Icomponent/soc/realtek/8195a/fwlib
|
||||
INCLUDES += -Icomponent/soc/realtek/8195a/fwlib/rtl8195a
|
||||
INCLUDES += -Icomponent/soc/realtek/8195a/misc/rtl_std_lib/include
|
||||
INCLUDES += -Icomponent/common/drivers/wlan/realtek/include
|
||||
INCLUDES += -Icomponent/common/drivers/wlan/realtek/src/osdep
|
||||
INCLUDES += -Icomponent/common/drivers/wlan/realtek/src/hci
|
||||
INCLUDES += -Icomponent/common/drivers/wlan/realtek/src/hal
|
||||
INCLUDES += -Icomponent/common/drivers/wlan/realtek/src/hal/OUTSRC
|
||||
INCLUDES += -Icomponent/soc/realtek/8195a/fwlib/ram_lib/wlan/realtek/wlan_ram_map/rom
|
||||
INCLUDES += -Icomponent/common/network/ssl/polarssl-1.3.8/include
|
||||
INCLUDES += -Icomponent/common/network/ssl/ssl_ram_map/rom
|
||||
INCLUDES += -Icomponent/common/utilities
|
||||
INCLUDES += -Icomponent/soc/realtek/8195a/misc/rtl_std_lib/include
|
||||
INCLUDES += -Icomponent/common/application/apple/WACServer/External/Curve25519
|
||||
INCLUDES += -Icomponent/common/application/apple/WACServer/External/GladmanAES
|
||||
INCLUDES += -Icomponent/soc/realtek/8195a/fwlib/ram_lib/usb_otg/include
|
||||
INCLUDES += -Icomponent/common/video/v4l2/inc
|
||||
INCLUDES += -Icomponent/common/media/codec
|
||||
INCLUDES += -Icomponent/common/drivers/usb_class/host/uvc/inc
|
||||
INCLUDES += -Icomponent/common/drivers/usb_class/device
|
||||
INCLUDES += -Icomponent/common/drivers/usb_class/device/class
|
||||
INCLUDES += -Icomponent/common/file_system/fatfs
|
||||
INCLUDES += -Icomponent/common/file_system/fatfs/r0.10c/include
|
||||
INCLUDES += -Icomponent/common/drivers/sdio/realtek/sdio_host/inc
|
||||
INCLUDES += -Icomponent/common/audio
|
||||
INCLUDES += -Icomponent/common/drivers/i2s
|
||||
INCLUDES += -Icomponent/common/application/xmodem
|
||||
|
||||
# Source file list
|
||||
# -------------------------------------------------------------------
|
||||
|
||||
SRC_C =
|
||||
DRAM_C =
|
||||
#cmsis
|
||||
SRC_C += component/soc/realtek/8195a/cmsis/device/system_8195a.c
|
||||
|
||||
#console
|
||||
SRC_C += component/common/api/at_cmd/atcmd_ethernet.c
|
||||
SRC_C += component/common/api/at_cmd/atcmd_lwip.c
|
||||
SRC_C += component/common/api/at_cmd/atcmd_sys.c
|
||||
SRC_C += component/common/api/at_cmd/atcmd_wifi.c
|
||||
SRC_C += component/common/api/at_cmd/log_service.c
|
||||
SRC_C += component/soc/realtek/8195a/misc/driver/low_level_io.c
|
||||
SRC_C += component/soc/realtek/8195a/misc/driver/rtl_consol.c
|
||||
|
||||
#network - api
|
||||
SRC_C += component/common/api/wifi/rtw_wpa_supplicant/wpa_supplicant/wifi_eap_config.c
|
||||
SRC_C += component/common/api/wifi/rtw_wpa_supplicant/wpa_supplicant/wifi_p2p_config.c
|
||||
SRC_C += component/common/api/wifi/rtw_wpa_supplicant/wpa_supplicant/wifi_wps_config.c
|
||||
SRC_C += component/common/api/wifi/wifi_conf.c
|
||||
SRC_C += component/common/api/wifi/wifi_ind.c
|
||||
SRC_C += component/common/api/wifi/wifi_promisc.c
|
||||
SRC_C += component/common/api/wifi/wifi_simple_config.c
|
||||
SRC_C += component/common/api/wifi/wifi_util.c
|
||||
SRC_C += component/common/api/lwip_netconf.c
|
||||
|
||||
#network - app
|
||||
SRC_C += component/common/api/network/src/ping_test.c
|
||||
SRC_C += component/common/utilities/ssl_client.c
|
||||
SRC_C += component/common/utilities/ssl_client_ext.c
|
||||
SRC_C += component/common/utilities/tcptest.c
|
||||
SRC_C += component/common/application/uart_adapter/uart_adapter.c
|
||||
SRC_C += component/common/utilities/uart_ymodem.c
|
||||
SRC_C += component/common/utilities/update.c
|
||||
SRC_C += component/common/api/network/src/wlan_network.c
|
||||
|
||||
#network - lwip
|
||||
SRC_C += component/common/network/lwip/lwip_v1.4.1/src/api/api_lib.c
|
||||
SRC_C += component/common/network/lwip/lwip_v1.4.1/src/api/api_msg.c
|
||||
SRC_C += component/common/network/lwip/lwip_v1.4.1/src/api/err.c
|
||||
SRC_C += component/common/network/lwip/lwip_v1.4.1/src/api/netbuf.c
|
||||
SRC_C += component/common/network/lwip/lwip_v1.4.1/src/api/netdb.c
|
||||
SRC_C += component/common/network/lwip/lwip_v1.4.1/src/api/netifapi.c
|
||||
SRC_C += component/common/network/lwip/lwip_v1.4.1/src/api/sockets.c
|
||||
SRC_C += component/common/network/lwip/lwip_v1.4.1/src/api/tcpip.c
|
||||
SRC_C += component/common/network/lwip/lwip_v1.4.1/src/core/ipv4/autoip.c
|
||||
SRC_C += component/common/network/lwip/lwip_v1.4.1/src/core/ipv4/icmp.c
|
||||
SRC_C += component/common/network/lwip/lwip_v1.4.1/src/core/ipv4/igmp.c
|
||||
SRC_C += component/common/network/lwip/lwip_v1.4.1/src/core/ipv4/inet.c
|
||||
SRC_C += component/common/network/lwip/lwip_v1.4.1/src/core/ipv4/inet_chksum.c
|
||||
SRC_C += component/common/network/lwip/lwip_v1.4.1/src/core/ipv4/ip.c
|
||||
SRC_C += component/common/network/lwip/lwip_v1.4.1/src/core/ipv4/ip_addr.c
|
||||
SRC_C += component/common/network/lwip/lwip_v1.4.1/src/core/ipv4/ip_frag.c
|
||||
SRC_C += component/common/network/lwip/lwip_v1.4.1/src/core/def.c
|
||||
SRC_C += component/common/network/lwip/lwip_v1.4.1/src/core/dhcp.c
|
||||
SRC_C += component/common/network/lwip/lwip_v1.4.1/src/core/dns.c
|
||||
SRC_C += component/common/network/lwip/lwip_v1.4.1/src/core/init.c
|
||||
SRC_C += component/common/network/lwip/lwip_v1.4.1/src/core/lwip_timers.c
|
||||
SRC_C += component/common/network/lwip/lwip_v1.4.1/src/core/mem.c
|
||||
SRC_C += component/common/network/lwip/lwip_v1.4.1/src/core/memp.c
|
||||
SRC_C += component/common/network/lwip/lwip_v1.4.1/src/core/netif.c
|
||||
SRC_C += component/common/network/lwip/lwip_v1.4.1/src/core/pbuf.c
|
||||
SRC_C += component/common/network/lwip/lwip_v1.4.1/src/core/raw.c
|
||||
SRC_C += component/common/network/lwip/lwip_v1.4.1/src/core/stats.c
|
||||
SRC_C += component/common/network/lwip/lwip_v1.4.1/src/core/sys.c
|
||||
SRC_C += component/common/network/lwip/lwip_v1.4.1/src/core/tcp.c
|
||||
SRC_C += component/common/network/lwip/lwip_v1.4.1/src/core/tcp_in.c
|
||||
SRC_C += component/common/network/lwip/lwip_v1.4.1/src/core/tcp_out.c
|
||||
SRC_C += component/common/network/lwip/lwip_v1.4.1/src/core/udp.c
|
||||
SRC_C += component/common/network/lwip/lwip_v1.4.1/src/netif/etharp.c
|
||||
SRC_C += component/common/network/lwip/lwip_v1.4.1/port/realtek/freertos/ethernetif.c
|
||||
SRC_C += component/common/drivers/wlan/realtek/src/osdep/lwip_intf.c
|
||||
SRC_C += component/common/network/lwip/lwip_v1.4.1/port/realtek/freertos/sys_arch.c
|
||||
SRC_C += component/common/network/dhcp/dhcps.c
|
||||
SRC_C += component/common/network/sntp/sntp.c
|
||||
|
||||
#network - mdns
|
||||
SRC_C += component/common/network/mDNS/mDNSPlatform.c
|
||||
|
||||
|
||||
#os - freertos
|
||||
SRC_C += component/os/freertos/freertos_v8.1.2/Source/portable/MemMang/heap_5.c
|
||||
SRC_C += component/os/freertos/freertos_v8.1.2/Source/portable/GCC/ARM_CM3/port.c
|
||||
SRC_C += component/os/freertos/cmsis_os.c
|
||||
SRC_C += component/os/freertos/freertos_v8.1.2/Source/croutine.c
|
||||
SRC_C += component/os/freertos/freertos_v8.1.2/Source/event_groups.c
|
||||
SRC_C += component/os/freertos/freertos_v8.1.2/Source/list.c
|
||||
SRC_C += component/os/freertos/freertos_v8.1.2/Source/queue.c
|
||||
SRC_C += component/os/freertos/freertos_v8.1.2/Source/tasks.c
|
||||
SRC_C += component/os/freertos/freertos_v8.1.2/Source/timers.c
|
||||
|
||||
#os - osdep
|
||||
SRC_C += component/os/os_dep/device_lock.c
|
||||
SRC_C += component/os/freertos/freertos_service.c
|
||||
SRC_C += component/os/os_dep/mailbox.c
|
||||
SRC_C += component/os/os_dep/osdep_api.c
|
||||
SRC_C += component/os/os_dep/osdep_service.c
|
||||
SRC_C += component/os/os_dep/tcm_heap.c
|
||||
|
||||
#peripheral - api
|
||||
SRC_C += component/common/mbed/targets/hal/rtl8195a/analogin_api.c
|
||||
SRC_C += component/common/mbed/targets/hal/rtl8195a/dma_api.c
|
||||
SRC_C += component/common/mbed/targets/hal/rtl8195a/efuse_api.c
|
||||
SRC_C += component/common/mbed/targets/hal/rtl8195a/ethernet_api.c
|
||||
SRC_C += component/common/drivers/ethernet_mii/ethernet_mii.c
|
||||
SRC_C += component/common/mbed/targets/hal/rtl8195a/flash_api.c
|
||||
SRC_C += component/common/mbed/targets/hal/rtl8195a/gpio_api.c
|
||||
SRC_C += component/common/mbed/targets/hal/rtl8195a/gpio_irq_api.c
|
||||
SRC_C += component/common/mbed/targets/hal/rtl8195a/i2c_api.c
|
||||
SRC_C += component/common/mbed/targets/hal/rtl8195a/i2s_api.c
|
||||
SRC_C += component/common/mbed/targets/hal/rtl8195a/log_uart_api.c
|
||||
SRC_C += component/common/mbed/targets/hal/rtl8195a/nfc_api.c
|
||||
SRC_C += component/common/mbed/targets/hal/rtl8195a/pinmap.c
|
||||
SRC_C += component/common/mbed/targets/hal/rtl8195a/pinmap_common.c
|
||||
SRC_C += component/common/mbed/targets/hal/rtl8195a/port_api.c
|
||||
SRC_C += component/common/mbed/targets/hal/rtl8195a/pwmout_api.c
|
||||
SRC_C += component/common/mbed/targets/hal/rtl8195a/rtc_api.c
|
||||
SRC_C += component/common/mbed/targets/hal/rtl8195a/serial_api.c
|
||||
SRC_C += component/common/mbed/targets/hal/rtl8195a/sleep.c
|
||||
SRC_C += component/common/mbed/targets/hal/rtl8195a/spdio_api.c
|
||||
SRC_C += component/common/mbed/targets/hal/rtl8195a/spi_api.c
|
||||
SRC_C += component/common/mbed/targets/hal/rtl8195a/sys_api.c
|
||||
SRC_C += component/common/mbed/targets/hal/rtl8195a/timer_api.c
|
||||
SRC_C += component/common/mbed/targets/hal/rtl8195a/us_ticker.c
|
||||
SRC_C += component/common/mbed/common/us_ticker_api.c
|
||||
SRC_C += component/common/mbed/common/wait_api.c
|
||||
SRC_C += component/common/mbed/targets/hal/rtl8195a/wdt_api.c
|
||||
|
||||
#peripheral - hal
|
||||
SRC_C += component/soc/realtek/8195a/fwlib/src/hal_32k.c
|
||||
SRC_C += component/soc/realtek/8195a/fwlib/src/hal_adc.c
|
||||
SRC_C += component/soc/realtek/8195a/fwlib/src/hal_gdma.c
|
||||
SRC_C += component/soc/realtek/8195a/fwlib/src/hal_gpio.c
|
||||
SRC_C += component/soc/realtek/8195a/fwlib/src/hal_i2c.c
|
||||
SRC_C += component/soc/realtek/8195a/fwlib/src/hal_i2s.c
|
||||
SRC_C += component/soc/realtek/8195a/fwlib/src/hal_mii.c
|
||||
SRC_C += component/soc/realtek/8195a/fwlib/src/hal_nfc.c
|
||||
SRC_C += component/soc/realtek/8195a/fwlib/src/hal_pcm.c
|
||||
SRC_C += component/soc/realtek/8195a/fwlib/src/hal_pwm.c
|
||||
SRC_C += component/soc/realtek/8195a/fwlib/src/hal_sdr_controller.c
|
||||
SRC_C += component/soc/realtek/8195a/fwlib/src/hal_ssi.c
|
||||
SRC_C += component/soc/realtek/8195a/fwlib/src/hal_timer.c
|
||||
SRC_C += component/soc/realtek/8195a/fwlib/src/hal_uart.c
|
||||
|
||||
#peripheral - osdep
|
||||
SRC_C += component/os/freertos/freertos_pmu.c
|
||||
|
||||
#peripheral - rtl8195a
|
||||
SRC_C += component/soc/realtek/8195a/fwlib/rtl8195a/src/rtl8195a_adc.c
|
||||
SRC_C += component/soc/realtek/8195a/fwlib/rtl8195a/src/rtl8195a_gdma.c
|
||||
SRC_C += component/soc/realtek/8195a/fwlib/rtl8195a/src/rtl8195a_gpio.c
|
||||
SRC_C += component/soc/realtek/8195a/fwlib/rtl8195a/src/rtl8195a_i2c.c
|
||||
SRC_C += component/soc/realtek/8195a/fwlib/rtl8195a/src/rtl8195a_i2s.c
|
||||
SRC_C += component/soc/realtek/8195a/fwlib/rtl8195a/src/rtl8195a_mii.c
|
||||
SRC_C += component/soc/realtek/8195a/fwlib/rtl8195a/src/rtl8195a_nfc.c
|
||||
SRC_C += component/soc/realtek/8195a/fwlib/rtl8195a/src/rtl8195a_pwm.c
|
||||
SRC_C += component/soc/realtek/8195a/fwlib/rtl8195a/src/rtl8195a_ssi.c
|
||||
SRC_C += component/soc/realtek/8195a/fwlib/rtl8195a/src/rtl8195a_timer.c
|
||||
SRC_C += component/soc/realtek/8195a/fwlib/rtl8195a/src/rtl8195a_uart.c
|
||||
|
||||
#peripheral - wlan
|
||||
#all:SRC_C += component/common/drivers/wlan/realtek/src/core/option/rtw_opt_skbuf.c
|
||||
|
||||
#SDRAM
|
||||
DRAM_C += component/common/api/platform/stdlib_patch.c
|
||||
#SDRAM - polarssl
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/aes.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/aesni.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/arc4.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/asn1parse.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/asn1write.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/base64.c
|
||||
SRC_C += component/common/network/ssl/polarssl-1.3.8/library/bignum.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/blowfish.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/camellia.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/ccm.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/certs.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/cipher.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/cipher_wrap.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/ctr_drbg.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/debug.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/des.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/dhm.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/ecp.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/ecp_curves.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/ecdh.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/ecdsa.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/entropy.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/entropy_poll.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/error.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/gcm.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/havege.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/hmac_drbg.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/md.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/md_wrap.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/md2.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/md4.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/md5.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/memory_buffer_alloc.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/net.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/oid.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/padlock.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/pbkdf2.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/pem.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/pkcs5.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/pkcs11.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/pkcs12.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/pk.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/pk_wrap.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/pkparse.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/pkwrite.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/platform.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/ripemd160.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/rsa.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/sha1.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/sha256.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/sha512.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/ssl_cache.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/ssl_ciphersuites.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/ssl_cli.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/ssl_srv.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/ssl_tls.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/threading.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/timing.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/version.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/version_features.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/x509.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/x509_crt.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/x509_crl.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/x509_csr.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/x509_create.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/x509write_crt.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/x509write_csr.c
|
||||
DRAM_C += component/common/network/ssl/polarssl-1.3.8/library/xtea.c
|
||||
|
||||
#SDRAM - ssl_ram_map
|
||||
DRAM_C += component/common/network/ssl/ssl_ram_map/rom/rom_ssl_ram_map.c
|
||||
DRAM_C += component/common/network/ssl/ssl_ram_map/ssl_ram_map.c
|
||||
|
||||
#SDRAM - wigadget
|
||||
DRAM_C += component/common/application/wigadget/cloud_link.c
|
||||
DRAM_C += component/common/application/wigadget/shtc1.c
|
||||
DRAM_C += component/common/application/wigadget/wigadget.c
|
||||
|
||||
|
||||
#utilities
|
||||
SRC_C += component/common/utilities/cJSON.c
|
||||
SRC_C += component/common/utilities/http_client.c
|
||||
SRC_C += component/common/utilities/uart_socket.c
|
||||
SRC_C += component/common/utilities/webserver.c
|
||||
SRC_C += component/common/utilities/xml.c
|
||||
#utilities - example
|
||||
SRC_C += component/common/example/example_entry.c
|
||||
SRC_C += component/common/example/uart_atcmd/example_uart_atcmd.c
|
||||
|
||||
#utilities - FatFS
|
||||
SRC_C += component/common/file_system/fatfs/fatfs_ext/src/ff_driver.c
|
||||
SRC_C += component/common/file_system/fatfs/r0.10c/src/diskio.c
|
||||
SRC_C += component/common/file_system/fatfs/r0.10c/src/ff.c
|
||||
SRC_C += component/common/file_system/fatfs/r0.10c/src/option/ccsbcs.c
|
||||
SRC_C += component/common/file_system/fatfs/disk_if/src/sdcard.c
|
||||
|
||||
#utilities - xmodme update
|
||||
SRC_C += component/common/application/xmodem/uart_fw_update.c
|
||||
#user
|
||||
SRC_C += src/c/src/main.c
|
||||
|
||||
# Generate obj list
|
||||
# -------------------------------------------------------------------
|
||||
|
||||
SRC_O = $(patsubst %.c,%.o,$(SRC_C))
|
||||
DRAM_O = $(patsubst %.c,%.o,$(DRAM_C))
|
||||
|
||||
|
||||
SRC_C_LIST = $(notdir $(SRC_C)) $(notdir $(DRAM_C))
|
||||
OBJ_LIST = $(addprefix $(OBJ_DIR)/,$(patsubst %.c,%.o,$(SRC_C_LIST)))
|
||||
|
||||
# Rust lib
|
||||
OBJ_LIST += $(TARGET)/Debug/rust_obj/librustl8710.o
|
||||
|
||||
DEPENDENCY_LIST = $(addprefix $(OBJ_DIR)/,$(patsubst %.c,%.d,$(SRC_C_LIST)))
|
||||
|
||||
# Compile options
|
||||
# -------------------------------------------------------------------
|
||||
|
||||
CFLAGS =
|
||||
CFLAGS += -DM3 -DCONFIG_PLATFORM_8195A -DGCC_ARMCM3 -DARDUINO_SDK
|
||||
CFLAGS += -mcpu=cortex-m3 -mthumb -g2 -w -O2 -Wno-pointer-sign -fno-common -fmessage-length=0 -ffunction-sections -fdata-sections -fomit-frame-pointer -fno-short-enums -mcpu=cortex-m3 -DF_CPU=166000000L -std=gnu99 -fsigned-char
|
||||
|
||||
LFLAGS =
|
||||
LFLAGS += -mcpu=cortex-m3 -mthumb -g --specs=nano.specs -nostartfiles -Wl,-Map=$(BIN_DIR)/application.map -Os -Wl,--gc-sections -Wl,--cref -Wl,--entry=Reset_Handler -Wl,--no-enum-size-warning -Wl,--no-wchar-size-warning
|
||||
|
||||
LIBFLAGS =
|
||||
all: LIBFLAGS += -Lcomponent/soc/realtek/8195a/misc/bsp/lib/common/GCC/ -l_platform -l_wlan -l_p2p -l_wps -l_rtlstd -l_websocket -l_xmodem -lm -lc -lnosys -lgcc
|
||||
mp: LIBFLAGS += -Lcomponent/soc/realtek/8195a/misc/bsp/lib/common/GCC/ -l_platform -l_wlan_mp -l_p2p -l_wps -l_rtlstd -l_websocket -l_xmodem -lm -lc -lnosys -lgcc
|
||||
|
||||
RAMALL_BIN =
|
||||
OTA_BIN =
|
||||
all: RAMALL_BIN = ram_all.bin
|
||||
all: OTA_BIN = ota.bin
|
||||
mp: RAMALL_BIN = ram_all_mp.bin
|
||||
mp: OTA_BIN = ota_mp.bin
|
||||
|
||||
# Compile
|
||||
# -------------------------------------------------------------------
|
||||
|
||||
.PHONY: application
|
||||
application: prerequirement build_info $(SRC_O) $(DRAM_O)
|
||||
$(LD) $(LFLAGS) -o $(BIN_DIR)/$(TARGET).axf $(OBJ_LIST) $(OBJ_DIR)/ram_1.r.o $(LIBFLAGS) -T./util/rlx8195A-symbol-v02-img2.ld
|
||||
$(OBJDUMP) -d $(BIN_DIR)/$(TARGET).axf > $(BIN_DIR)/$(TARGET).asm
|
||||
|
||||
|
||||
# Manipulate Image
|
||||
# -------------------------------------------------------------------
|
||||
|
||||
.PHONY: manipulate_images
|
||||
manipulate_images:
|
||||
@echo ===========================================================
|
||||
@echo Image manipulating
|
||||
@echo ===========================================================
|
||||
$(NM) $(BIN_DIR)/$(TARGET).axf | sort > $(BIN_DIR)/$(TARGET).nmap
|
||||
$(OBJCOPY) -j .image2.start.table -j .ram_image2.text -j .ram_image2.rodata -j .ram.data -Obinary $(BIN_DIR)/$(TARGET).axf $(BIN_DIR)/ram_2.bin
|
||||
$(OBJCOPY) -j .sdr_text -j .sdr_rodata -j .sdr_data -Obinary $(BIN_DIR)/$(TARGET).axf $(BIN_DIR)/sdram.bin
|
||||
cp component/soc/realtek/8195a/misc/bsp/image/ram_1.p.bin $(BIN_DIR)/ram_1.p.bin
|
||||
chmod 777 $(BIN_DIR)/ram_1.p.bin
|
||||
chmod +rx $(PICK) $(CHKSUM) $(PAD)
|
||||
$(PICK) 0x`grep __ram_image2_text_start__ $(BIN_DIR)/$(TARGET).nmap | gawk '{print $$1}'` 0x`grep __ram_image2_text_end__ $(BIN_DIR)/$(TARGET).nmap | gawk '{print $$1}'` $(BIN_DIR)/ram_2.bin $(BIN_DIR)/ram_2.p.bin body+reset_offset+sig
|
||||
$(PICK) 0x`grep __ram_image2_text_start__ $(BIN_DIR)/$(TARGET).nmap | gawk '{print $$1}'` 0x`grep __ram_image2_text_end__ $(BIN_DIR)/$(TARGET).nmap | gawk '{print $$1}'` $(BIN_DIR)/ram_2.bin $(BIN_DIR)/ram_2.ns.bin body+reset_offset
|
||||
$(PICK) 0x`grep __sdram_data_start__ $(BIN_DIR)/$(TARGET).nmap | gawk '{print $$1}'` 0x`grep __sdram_data_end__ $(BIN_DIR)/$(TARGET).nmap | gawk '{print $$1}'` $(BIN_DIR)/sdram.bin $(BIN_DIR)/ram_3.p.bin body+reset_offset
|
||||
$(PAD) 44k 0xFF $(BIN_DIR)/ram_1.p.bin
|
||||
cat $(BIN_DIR)/ram_1.p.bin > $(BIN_DIR)/$(RAMALL_BIN)
|
||||
chmod 777 $(BIN_DIR)/$(RAMALL_BIN)
|
||||
cat $(BIN_DIR)/ram_2.p.bin >> $(BIN_DIR)/$(RAMALL_BIN)
|
||||
if [ -s $(BIN_DIR)/sdram.bin ]; then cat $(BIN_DIR)/ram_3.p.bin >> $(BIN_DIR)/$(RAMALL_BIN); fi
|
||||
cat $(BIN_DIR)/ram_2.ns.bin > $(BIN_DIR)/$(OTA_BIN)
|
||||
chmod 777 $(BIN_DIR)/$(OTA_BIN)
|
||||
if [ -s $(BIN_DIR)/sdram.bin ]; then cat $(BIN_DIR)/ram_3.p.bin >> $(BIN_DIR)/$(OTA_BIN); fi
|
||||
$(CHKSUM) $(BIN_DIR)/$(OTA_BIN) || true
|
||||
rm $(BIN_DIR)/ram_*.p.bin $(BIN_DIR)/ram_*.ns.bin
|
||||
|
||||
# Generate build info
|
||||
# -------------------------------------------------------------------
|
||||
|
||||
.PHONY: build_info
|
||||
build_info:
|
||||
@echo \#define UTS_VERSION \"`date +%Y/%m/%d-%T`\" > .ver
|
||||
@echo \#define RTL8195AFW_COMPILE_TIME \"`date +%Y/%m/%d-%T`\" >> .ver
|
||||
@echo \#define RTL8195AFW_COMPILE_DATE \"`date +%Y%m%d`\" >> .ver
|
||||
@echo \#define RTL8195AFW_COMPILE_BY \"`id -u -n`\" >> .ver
|
||||
@echo \#define RTL8195AFW_COMPILE_HOST \"`$(HOSTNAME_APP)`\" >> .ver
|
||||
@if [ -x /bin/dnsdomainname ]; then \
|
||||
echo \#define RTL8195AFW_COMPILE_DOMAIN \"`dnsdomainname`\"; \
|
||||
elif [ -x /bin/domainname ]; then \
|
||||
echo \#define RTL8195AFW_COMPILE_DOMAIN \"`domainname`\"; \
|
||||
else \
|
||||
echo \#define RTL8195AFW_COMPILE_DOMAIN ; \
|
||||
fi >> .ver
|
||||
|
||||
@echo \#define RTL195AFW_COMPILER \"gcc `$(CC) $(CFLAGS) -dumpversion | tr --delete '\r'`\" >> .ver
|
||||
@mv -f .ver src/c/inc/$@.h
|
||||
|
||||
|
||||
.PHONY: prerequirement
|
||||
prerequirement:
|
||||
@echo ===========================================================
|
||||
@echo Build $(TARGET)
|
||||
@echo ===========================================================
|
||||
mkdir -p $(OBJ_DIR)
|
||||
mkdir -p $(BIN_DIR)
|
||||
cp component/soc/realtek/8195a/misc/bsp/image/ram_1.r.bin $(OBJ_DIR)/ram_1.r.bin
|
||||
chmod 777 $(OBJ_DIR)/ram_1.r.bin
|
||||
$(OBJCOPY) --rename-section .data=.loader.data,contents,alloc,load,readonly,data -I binary -O elf32-littlearm -B arm $(OBJ_DIR)/ram_1.r.bin $(OBJ_DIR)/ram_1.r.o
|
||||
|
||||
$(SRC_O): %.o : %.c
|
||||
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
|
||||
$(CC) $(CFLAGS) $(INCLUDES) -c $< -MM -MT $@ -MF $(OBJ_DIR)/$(notdir $(patsubst %.o,%.d,$@))
|
||||
cp $@ $(OBJ_DIR)/$(notdir $@)
|
||||
chmod 777 $(OBJ_DIR)/$(notdir $@)
|
||||
|
||||
$(DRAM_O): %.o : %.c
|
||||
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
|
||||
$(OBJCOPY) --prefix-alloc-sections .sdram $@
|
||||
$(CC) $(CFLAGS) $(INCLUDES) -c $< -MM -MT $@ -MF $(OBJ_DIR)/$(notdir $(patsubst %.o,%.d,$@))
|
||||
cp $@ $(OBJ_DIR)/$(notdir $@)
|
||||
chmod 777 $(OBJ_DIR)/$(notdir $@)
|
||||
|
||||
-include $(DEPENDENCY_LIST)
|
||||
|
||||
# Generate build info
|
||||
# -------------------------------------------------------------------
|
||||
#ifeq (setup,$(firstword $(MAKECMDGOALS)))
|
||||
# # use the rest as arguments for "run"
|
||||
# RUN_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
|
||||
# # ...and turn them into do-nothing targets
|
||||
# $(eval $(RUN_ARGS):;@:)
|
||||
#endif
|
||||
.PHONY: setup
|
||||
setup:
|
||||
@echo "----------------"
|
||||
@echo Setup $(GDB_SERVER)
|
||||
@echo "----------------"
|
||||
ifeq ($(GDB_SERVER), openocd)
|
||||
cp -p $(FLASH_TOOLDIR)/rtl_gdb_debug_openocd.txt $(FLASH_TOOLDIR)/rtl_gdb_debug.txt
|
||||
cp -p $(FLASH_TOOLDIR)/rtl_gdb_ramdebug_openocd.txt $(FLASH_TOOLDIR)/rtl_gdb_ramdebug.txt
|
||||
cp -p $(FLASH_TOOLDIR)/rtl_gdb_flash_write_openocd.txt $(FLASH_TOOLDIR)/rtl_gdb_flash_write.txt
|
||||
else
|
||||
cp -p $(FLASH_TOOLDIR)/rtl_gdb_debug_jlink.txt $(FLASH_TOOLDIR)/rtl_gdb_debug.txt
|
||||
cp -p $(FLASH_TOOLDIR)/rtl_gdb_ramdebug_jlink.txt $(FLASH_TOOLDIR)/rtl_gdb_ramdebug.txt
|
||||
cp -p $(FLASH_TOOLDIR)/rtl_gdb_flash_write_jlink.txt $(FLASH_TOOLDIR)/rtl_gdb_flash_write.txt
|
||||
endif
|
||||
|
||||
.PHONY: flashburn
|
||||
flashburn:
|
||||
@if [ ! -f $(FLASH_TOOLDIR)/rtl_gdb_flash_write.txt ] ; then echo Please do \"make setup GDB_SERVER=[jlink or openocd]\" first; echo && false ; fi
|
||||
ifeq ($(findstring CYGWIN, $(OS)), CYGWIN)
|
||||
$(FLASH_TOOLDIR)/Check_Jtag.sh
|
||||
endif
|
||||
cp $(FLASH_TOOLDIR)/target_NORMALB.axf $(FLASH_TOOLDIR)/target_NORMAL.axf
|
||||
chmod 777 $(FLASH_TOOLDIR)/target_NORMAL.axf
|
||||
chmod +rx $(FLASH_TOOLDIR)/SetupGDB_NORMAL.sh
|
||||
$(FLASH_TOOLDIR)/SetupGDB_NORMAL.sh
|
||||
$(GDB) -x $(FLASH_TOOLDIR)/rtl_gdb_flash_write.txt
|
||||
|
||||
.PHONY: debug
|
||||
debug:
|
||||
@if [ ! -f $(FLASH_TOOLDIR)/rtl_gdb_debug.txt ] ; then echo Please do \"make setup GDB_SERVER=[jlink or openocd]\" first; echo && false ; fi
|
||||
ifeq ($(findstring CYGWIN, $(OS)), CYGWIN)
|
||||
$(FLASH_TOOLDIR)/Check_Jtag.sh
|
||||
cmd /c start $(GDB) -x $(FLASH_TOOLDIR)/rtl_gdb_debug.txt
|
||||
else
|
||||
$(GDB) -x $(FLASH_TOOLDIR)/rtl_gdb_debug.txt
|
||||
endif
|
||||
|
||||
.PHONY: ramdebug
|
||||
ramdebug:
|
||||
@if [ ! -f $(FLASH_TOOLDIR)/rtl_gdb_ramdebug.txt ] ; then echo Please do \"make setup GDB_SERVER=[jlink or openocd]\" first; echo && false ; fi
|
||||
ifeq ($(findstring CYGWIN, $(OS)), CYGWIN)
|
||||
$(FLASH_TOOLDIR)/Check_Jtag.sh
|
||||
cmd /c start $(GDB) -x $(FLASH_TOOLDIR)/rtl_gdb_ramdebug.txt
|
||||
else
|
||||
$(GDB) -x $(FLASH_TOOLDIR)/rtl_gdb_ramdebug.txt
|
||||
endif
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -rf $(TARGET)
|
||||
rm -f $(SRC_O) $(DRAM_O)
|
||||
rm -f $(patsubst %.o,%.d,$(SRC_O)) $(patsubst %.o,%.d,$(DRAM_O))
|
||||
|
||||
.PHONY: clean_all
|
||||
clean_all:
|
||||
#rm -rf $(ARM_GCC_TOOLCHAIN)
|
||||
rm -rf $(TARGET)
|
||||
rm -f $(SRC_O) $(DRAM_O)
|
||||
rm -f $(patsubst %.o,%.d,$(SRC_O)) $(patsubst %.o,%.d,$(DRAM_O))
|
92
component/common/api/at_cmd/atcmd_ethernet.c
Normal file
92
component/common/api/at_cmd/atcmd_ethernet.c
Normal file
|
@ -0,0 +1,92 @@
|
|||
#include <stdio.h>
|
||||
#include "log_service.h"
|
||||
#include "platform_opts.h"
|
||||
#include <lwip_netconf.h>
|
||||
#include "cmsis_os.h"
|
||||
#include <platform/platform_stdlib.h>
|
||||
#include <lwip/sockets.h>
|
||||
#include <lwip/tcpip.h>
|
||||
#include "wifi_conf.h"
|
||||
|
||||
|
||||
#define _AT_DHCP_ETHERNET_MII_ "ATE0"
|
||||
#define _AT_SET_DEFAULT_INTERFACE "ATE1"
|
||||
|
||||
#if CONFIG_ETHERNET
|
||||
extern int dhcp_ethernet_mii;
|
||||
extern int ethernet_if_default;
|
||||
extern struct netif xnetif[NET_IF_NUM];
|
||||
|
||||
void fATE0(void *arg)
|
||||
{
|
||||
int argc;
|
||||
char *argv[MAX_ARGC] = {0};
|
||||
printf("[ATE0]:DHCP configure for ethernet\n\r");
|
||||
if(!arg){
|
||||
printf("[ATE0]Usage to disable DHCP: ATE0=0\n");
|
||||
printf("[ATE0]Usage to enable DHCP: ATE0=1\n");
|
||||
return;
|
||||
}
|
||||
if('0' == *(char *)arg)
|
||||
{
|
||||
dhcp_ethernet_mii = 0;
|
||||
}
|
||||
|
||||
else if('1' == *(char *)arg)
|
||||
{
|
||||
dhcp_ethernet_mii = 1;
|
||||
LwIP_DHCP(NET_IF_NUM - 1, DHCP_START);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
printf("[ATE0]Usage to disable DHCP: ATE0=0\n");
|
||||
printf("[ATE0]Usage to enable DHCP: ATE0=1\n");
|
||||
}
|
||||
}
|
||||
|
||||
void fATE1(void *arg)
|
||||
{
|
||||
int argc;
|
||||
char *argv[MAX_ARGC] = {0};
|
||||
printf("[ATE1]:Set/check the default interface\n\r");
|
||||
if(!arg){
|
||||
if(ethernet_if_default)
|
||||
printf("Ethernet is the default interface\n");
|
||||
else
|
||||
printf("wlan is the default interface\n");
|
||||
return;
|
||||
}
|
||||
if('0' == *(char *)arg)
|
||||
{
|
||||
ethernet_if_default = 0;
|
||||
printf("wlan is set to the default interface\n");
|
||||
}
|
||||
|
||||
else if('1' == *(char *)arg)
|
||||
{
|
||||
ethernet_if_default = 1;
|
||||
printf("ethernet is set to the default interface\n");
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
printf("[ATE0]Usage to check the default interface: ATE1\n");
|
||||
printf("[ATE0]Usage to set ethernet as default interface: ATE1=1\n");
|
||||
printf("[ATE0]Usage to set wlan as default interface: ATE1=0\n");
|
||||
}
|
||||
}
|
||||
|
||||
log_item_t at_ethernet_items[ ] = {
|
||||
{"ATE0", fATE0,},
|
||||
{"ATE1", fATE1,}
|
||||
};
|
||||
|
||||
void at_ethernet_init(void)
|
||||
{
|
||||
log_service_add_table(at_ethernet_items, sizeof(at_ethernet_items)/sizeof(at_ethernet_items[0]));
|
||||
}
|
||||
|
||||
log_module_init(at_ethernet_init);
|
||||
|
||||
#endif
|
196
component/common/api/at_cmd/atcmd_google.c
Normal file
196
component/common/api/at_cmd/atcmd_google.c
Normal file
|
@ -0,0 +1,196 @@
|
|||
#include <lwip_netconf.h>
|
||||
#include <stdio.h>
|
||||
#include "log_service.h"
|
||||
#include "cmsis_os.h"
|
||||
#include <platform/platform_stdlib.h>
|
||||
#include <lwip/sockets.h>
|
||||
#include <lwip/tcpip.h>
|
||||
#include "wifi_conf.h"
|
||||
#include "google/google_nest.h"
|
||||
#include <cJSON.h>
|
||||
#include <platform_opts.h>
|
||||
|
||||
#define GN_PORT 443
|
||||
|
||||
|
||||
#define _AT_GOOGLE_NEST_ "ATG0"
|
||||
|
||||
//functions that using Google Nest's API
|
||||
void google_data_retrieve_cb(char *response_buf);
|
||||
|
||||
void googlenest_get(char *host_addr, char *host_file)
|
||||
{
|
||||
unsigned char buffer[512];
|
||||
googlenest_context googlenest;
|
||||
char *googlenest_host = host_addr;
|
||||
char *googlenest_uri = host_file;
|
||||
|
||||
|
||||
memset(&googlenest, 0, sizeof(googlenest_context));
|
||||
if(gn_connect(&googlenest, googlenest_host, GN_PORT) == 0) {
|
||||
if(gn_get(&googlenest, googlenest_uri, buffer, sizeof(buffer)) == 0)
|
||||
printf("\r\n\r\nGet data from googlenest: %s", buffer);
|
||||
gn_close(&googlenest);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void google_data_retrieve_cb(char *response_buf) {
|
||||
printf("\r\nResponse_buf:\r\n%s\r\n", response_buf);
|
||||
|
||||
}
|
||||
|
||||
void googlenest_stream(char *host_addr, char *host_file)
|
||||
{
|
||||
googlenest_context googlenest;
|
||||
char *googlenest_host = host_addr;
|
||||
char *googlenest_uri = host_file;
|
||||
|
||||
memset(&googlenest, 0, sizeof(googlenest_context));
|
||||
if(gn_connect(&googlenest, googlenest_host, GN_PORT) == 0) {
|
||||
google_retrieve_data_hook_callback(google_data_retrieve_cb);
|
||||
gn_stream(&googlenest, googlenest_uri);
|
||||
gn_close(&googlenest);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void googlenest_delete(char *host_addr, char *host_file)
|
||||
{
|
||||
googlenest_context googlenest;
|
||||
char *googlenest_host = host_addr;
|
||||
char *googlenest_uri = host_file;
|
||||
|
||||
|
||||
memset(&googlenest, 0, sizeof(googlenest_context));
|
||||
if(gn_connect(&googlenest, googlenest_host, GN_PORT) == 0) {
|
||||
if(gn_delete(&googlenest, googlenest_uri) == 0)
|
||||
printf("\r\n\r\nDelete the data is successful!");
|
||||
gn_close(&googlenest);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void googlenest_put(char *host_addr, char *host_file, char *data)
|
||||
{
|
||||
googlenest_context googlenest;
|
||||
char *googlenest_host = host_addr;
|
||||
char *googlenest_uri = host_file;
|
||||
|
||||
memset(&googlenest, 0, sizeof(googlenest_context));
|
||||
if(gn_connect(&googlenest, googlenest_host, GN_PORT) == 0) {
|
||||
if(gn_put(&googlenest, googlenest_uri, data) == 0)
|
||||
printf("\r\n\r\nSaving data in firebase is successful!");
|
||||
gn_close(&googlenest);
|
||||
}
|
||||
}
|
||||
|
||||
void googlenest_patch(char *host_addr, char *host_file, char *data)
|
||||
{
|
||||
googlenest_context googlenest;
|
||||
char *googlenest_host = host_addr;
|
||||
char *googlenest_uri = host_file;
|
||||
|
||||
memset(&googlenest, 0, sizeof(googlenest_context));
|
||||
if(gn_connect(&googlenest, googlenest_host, GN_PORT) == 0) {
|
||||
if(gn_patch(&googlenest, googlenest_uri, data) == 0)
|
||||
printf("\r\n\r\nUpdating data in firebase is successful!");
|
||||
gn_close(&googlenest);
|
||||
}
|
||||
}
|
||||
|
||||
void googlenest_post(char *host_addr, char *host_file, char *data)
|
||||
{
|
||||
googlenest_context googlenest;
|
||||
char *googlenest_host = host_addr;
|
||||
char *googlenest_uri = host_file;
|
||||
unsigned char buffer[64];
|
||||
|
||||
memset(&googlenest, 0, sizeof(googlenest_context));
|
||||
if(gn_connect(&googlenest, googlenest_host, GN_PORT) == 0) {
|
||||
if(gn_post(&googlenest, googlenest_uri, data, buffer, sizeof(buffer)) == 0)
|
||||
printf("\r\n\r\nInserting data to firebase is successful!\r\n\r\nThe unique name for this list of data is: %s", buffer);
|
||||
gn_close(&googlenest);
|
||||
}
|
||||
}
|
||||
|
||||
void cmd_googlenest(int argc, char **argv)
|
||||
{
|
||||
if(strcmp(argv[1], "get") == 0) {
|
||||
if(argc != 4)
|
||||
printf("\n\rUsage: gn get address file");
|
||||
else {
|
||||
googlenest_get(argv[2], argv[3]);
|
||||
}
|
||||
}
|
||||
else if(strcmp(argv[1], "delete") ==0){
|
||||
if(argc != 4)
|
||||
printf("\n\rUsage: gn delete address file");
|
||||
else {
|
||||
googlenest_delete(argv[2], argv[3]);
|
||||
}
|
||||
}
|
||||
else if(strcmp(argv[1], "put") ==0){
|
||||
if(argc != 5)
|
||||
printf("\n\rUsage: gn put address file data");
|
||||
else {
|
||||
googlenest_put(argv[2], argv[3], argv[4]);
|
||||
}
|
||||
}
|
||||
else if(strcmp(argv[1], "patch") ==0){
|
||||
if(argc != 5)
|
||||
printf("\n\rUsage: gn patch address file data");
|
||||
else {
|
||||
googlenest_patch(argv[2], argv[3], argv[4]);
|
||||
}
|
||||
}
|
||||
else if(strcmp(argv[1], "post") ==0){
|
||||
if(argc != 5)
|
||||
printf("\n\rUsage: gn post address file data");
|
||||
else {
|
||||
googlenest_post(argv[2], argv[3], argv[4]);
|
||||
}
|
||||
}
|
||||
else if(strcmp(argv[1], "stream") ==0){
|
||||
if(argc != 4)
|
||||
printf("\n\rUsage: gn stream address file");
|
||||
else {
|
||||
googlenest_stream(argv[2], argv[3]);
|
||||
}
|
||||
}
|
||||
else
|
||||
printf("\n\rUsage: gn method addr file (data)");
|
||||
}
|
||||
|
||||
//AT Command function
|
||||
|
||||
void fATG0(void *arg){
|
||||
int argc;
|
||||
char *argv[MAX_ARGC] = {0};
|
||||
printf("[ATG0]: _AT_WLAN_GOOGLENEST_\n\r");
|
||||
if(!arg){
|
||||
printf("[ATG0]Usage: ATWG=[method,address,file,data] or ATG0=[method,address,file]\n\r");
|
||||
return;
|
||||
}
|
||||
argv[0] = "gn";
|
||||
if((argc = parse_param(arg, argv)) > 1){
|
||||
cmd_googlenest(argc, argv);
|
||||
}
|
||||
else
|
||||
printf("[ATG0]Usage: ATG0=[method,address,file,data] or ATG0=[method,address,file]\n\r");
|
||||
}
|
||||
|
||||
#if CONFIG_GOOGLE_NEST
|
||||
log_item_t at_google_items[ ] = {
|
||||
|
||||
{"ATG0", fATG0,}
|
||||
|
||||
};
|
||||
|
||||
void at_google_init(void)
|
||||
{
|
||||
log_service_add_table(at_google_items, sizeof(at_google_items)/sizeof(at_google_items[0]));
|
||||
}
|
||||
|
||||
log_module_init(at_google_init);
|
||||
#endif
|
2136
component/common/api/at_cmd/atcmd_lwip.c
Normal file
2136
component/common/api/at_cmd/atcmd_lwip.c
Normal file
File diff suppressed because it is too large
Load diff
96
component/common/api/at_cmd/atcmd_lwip.h
Normal file
96
component/common/api/at_cmd/atcmd_lwip.h
Normal file
|
@ -0,0 +1,96 @@
|
|||
#ifndef __ATCMD_LWIP_H__
|
||||
#define __ATCMD_LWIP_H__
|
||||
|
||||
#include "main.h"
|
||||
#include <lwip/opt.h>
|
||||
#include "lwip/sockets.h"
|
||||
#include "lwip/api.h"
|
||||
#include "lwip/sys.h"
|
||||
#include "lwip/igmp.h"
|
||||
#include "lwip/inet.h"
|
||||
#include "lwip/tcp.h"
|
||||
#include "lwip/raw.h"
|
||||
#include "lwip/udp.h"
|
||||
#include "lwip/tcpip.h"
|
||||
#include "lwip/pbuf.h"
|
||||
#include "lwip/netdb.h"
|
||||
#include "lwip_netconf.h"
|
||||
|
||||
#define _AT_TRANSPORT_MODE_ "ATP1"
|
||||
#define _AT_TRANSPORT_LOCAL_PORT_ "ATP2"
|
||||
#define _AT_TRANSPORT_REMOTE_IP_ "ATP3"
|
||||
#define _AT_TRANSPORT_REMOTE_PORT_ "ATP4"
|
||||
#define _AT_TRANSPORT_START_SERVER_ "ATP5"
|
||||
#define _AT_TRANSPORT_START_CLIENT_ "ATP6"
|
||||
#define _AT_TRANSPORT_SHOW_SETTING_ "ATP?"
|
||||
#define _AT_TRANSPORT_RECEIVE_DATA_ "ATR0"
|
||||
#define _AT_TRANSPORT_RECEIVE_PACKET_SIZE_ "ATR1"
|
||||
#define _AT_TRANSPORT_WRITE_DATA_ "ATRA"
|
||||
#define _AT_TRANSPORT_WRITE_PACKET_SIZE_ "ATRB"
|
||||
|
||||
#define NODE_MODE_TCP 0
|
||||
#define NODE_MODE_UDP 1
|
||||
|
||||
#define NODE_ROLE_SERVER 0
|
||||
#define NODE_ROLE_CLIENT 1
|
||||
#define NODE_ROLE_SEED 2
|
||||
|
||||
#define INVALID_SOCKET_ID (-1)
|
||||
|
||||
//parameters
|
||||
#ifndef NET_IF_NUM
|
||||
#define NET_IF_NUM 2
|
||||
#endif
|
||||
|
||||
#define ATCMD_LWIP_TASK_PRIORITY (tskIDLE_PRIORITY + 1)
|
||||
|
||||
#if ATCMD_VER == ATVER_2
|
||||
|
||||
#define SERVER "127.0.0.1"
|
||||
|
||||
#define NUM_NS (MEMP_NUM_NETCONN) //maximum number of node and seed, same as NUM_SOCKETS
|
||||
|
||||
#define ETH_MAX_MTU 1500
|
||||
|
||||
#define INVALID_CON_ID (-1)
|
||||
|
||||
#define RECV_SELECT_TIMEOUT_SEC (0)
|
||||
#define RECV_SELECT_TIMEOUT_USEC (20000) //20ms
|
||||
|
||||
typedef struct ns
|
||||
{
|
||||
int con_id;
|
||||
int sockfd;
|
||||
s8_t role;
|
||||
int protocol;
|
||||
u32_t addr;
|
||||
u16_t port;
|
||||
u32_t local_addr;
|
||||
u16_t local_port;
|
||||
xTaskHandle handletask;
|
||||
struct ns* next;
|
||||
struct ns* nextseed;
|
||||
} node;
|
||||
|
||||
extern xTaskHandle atcmd_lwip_tt_task;
|
||||
extern xSemaphoreHandle atcmd_lwip_tt_sema;
|
||||
extern volatile int atcmd_lwip_tt_datasize;
|
||||
extern volatile int atcmd_lwip_tt_lasttickcnt;
|
||||
#define ATCMD_LWIP_TT_MAX_DELAY_TIME_MS (20) //transparent transmission interval
|
||||
|
||||
extern int atcmd_lwip_is_tt_mode(void);
|
||||
extern void atcmd_lwip_set_tt_mode(int enable);
|
||||
int atcmd_lwip_send_data(node *curnode, u8 *data, u16 data_sz, struct sockaddr_in cli_addr);
|
||||
int atcmd_lwip_receive_data(node *curnode, u8 *buffer, u16 buffer_size, int *recv_size,
|
||||
u8_t *udp_clientaddr, u16_t *udp_clientport);
|
||||
node* create_node(int mode, s8_t role);
|
||||
void init_node_pool(void);
|
||||
void delete_node(node *n);
|
||||
int hang_node(node* insert_node);
|
||||
int hang_seednode(node* main_node ,node* insert_node);
|
||||
node *seek_node(int con_id);
|
||||
node *tryget_node(int n);
|
||||
#endif
|
||||
|
||||
|
||||
#endif //#ifndef __ATCMD_LWIP_H__
|
1137
component/common/api/at_cmd/atcmd_sys.c
Normal file
1137
component/common/api/at_cmd/atcmd_sys.c
Normal file
File diff suppressed because it is too large
Load diff
5
component/common/api/at_cmd/atcmd_sys.h
Normal file
5
component/common/api/at_cmd/atcmd_sys.h
Normal file
|
@ -0,0 +1,5 @@
|
|||
#ifndef __ATCMD_SYS_H__
|
||||
#define __ATCMD_SYS_H__
|
||||
|
||||
|
||||
#endif
|
2690
component/common/api/at_cmd/atcmd_wifi.c
Normal file
2690
component/common/api/at_cmd/atcmd_wifi.c
Normal file
File diff suppressed because it is too large
Load diff
161
component/common/api/at_cmd/atcmd_wifi.h
Normal file
161
component/common/api/at_cmd/atcmd_wifi.h
Normal file
|
@ -0,0 +1,161 @@
|
|||
#ifndef __ATCMD_WIFI_H__
|
||||
#define __ATCMD_WIFI_H__
|
||||
#include "main.h"
|
||||
#include "lwip_netconf.h"
|
||||
|
||||
#ifndef WLAN0_NAME
|
||||
#define WLAN0_NAME "wlan0"
|
||||
#endif
|
||||
#ifndef WLAN1_NAME
|
||||
#define WLAN1_NAME "wlan1"
|
||||
#endif
|
||||
/* Give default value if not defined */
|
||||
#ifndef NET_IF_NUM
|
||||
#ifdef CONFIG_CONCURRENT_MODE
|
||||
#define NET_IF_NUM ((CONFIG_ETHERNET) + (CONFIG_WLAN) + 1)
|
||||
#else
|
||||
#define NET_IF_NUM ((CONFIG_ETHERNET) + (CONFIG_WLAN))
|
||||
#endif // end of CONFIG_CONCURRENT_MODE
|
||||
#endif // end of NET_IF_NUM
|
||||
|
||||
/*Static IP ADDRESS*/
|
||||
#ifndef IP_ADDR0
|
||||
#define IP_ADDR0 192
|
||||
#define IP_ADDR1 168
|
||||
#define IP_ADDR2 1
|
||||
#define IP_ADDR3 80
|
||||
#endif
|
||||
|
||||
/*NETMASK*/
|
||||
#ifndef NETMASK_ADDR0
|
||||
#define NETMASK_ADDR0 255
|
||||
#define NETMASK_ADDR1 255
|
||||
#define NETMASK_ADDR2 255
|
||||
#define NETMASK_ADDR3 0
|
||||
#endif
|
||||
|
||||
/*Gateway Address*/
|
||||
#ifndef GW_ADDR0
|
||||
#define GW_ADDR0 192
|
||||
#define GW_ADDR1 168
|
||||
#define GW_ADDR2 1
|
||||
#define GW_ADDR3 1
|
||||
#endif
|
||||
|
||||
/*Static IP ADDRESS*/
|
||||
#ifndef AP_IP_ADDR0
|
||||
#define AP_IP_ADDR0 192
|
||||
#define AP_IP_ADDR1 168
|
||||
#define AP_IP_ADDR2 43
|
||||
#define AP_IP_ADDR3 1
|
||||
#endif
|
||||
|
||||
/*NETMASK*/
|
||||
#ifndef AP_NETMASK_ADDR0
|
||||
#define AP_NETMASK_ADDR0 255
|
||||
#define AP_NETMASK_ADDR1 255
|
||||
#define AP_NETMASK_ADDR2 255
|
||||
#define AP_NETMASK_ADDR3 0
|
||||
#endif
|
||||
|
||||
/*Gateway Address*/
|
||||
#ifndef AP_GW_ADDR0
|
||||
#define AP_GW_ADDR0 192
|
||||
#define AP_GW_ADDR1 168
|
||||
#define AP_GW_ADDR2 43
|
||||
#define AP_GW_ADDR3 1
|
||||
#endif
|
||||
|
||||
#if CONFIG_EXAMPLE_UART_ATCMD
|
||||
#include "wifi_structures.h"
|
||||
#include <wlan_fast_connect/example_wlan_fast_connect.h>
|
||||
typedef struct _UART_LOG_CONF_{
|
||||
u32 BaudRate;
|
||||
u8 DataBits;
|
||||
u8 StopBits;
|
||||
u8 Parity;
|
||||
u8 FlowControl;
|
||||
}UART_LOG_CONF, *PUART_LOG_CONF;
|
||||
|
||||
#define ATCMD_WIFI_CONN_STORE_MAX_NUM (1)
|
||||
struct atcmd_wifi_conf{
|
||||
int32_t auto_enable;
|
||||
rtw_wifi_setting_t setting;
|
||||
int32_t reconn_num;
|
||||
int32_t reconn_last_index;
|
||||
struct wlan_fast_reconnect reconn[ATCMD_WIFI_CONN_STORE_MAX_NUM];
|
||||
};
|
||||
|
||||
#define ATCMD_LWIP_CONN_STORE_MAX_NUM (1)
|
||||
struct atcmd_lwip_conn_info{
|
||||
int32_t role; //client, server or seed
|
||||
uint32_t protocol; //tcp or udp
|
||||
uint32_t remote_addr; //remote ip
|
||||
uint32_t remote_port; //remote port
|
||||
uint32_t local_addr; //locale ip, not used yet
|
||||
uint32_t local_port; //locale port, not used yet
|
||||
uint32_t reserved; //reserve for further use
|
||||
};
|
||||
struct atcmd_lwip_conf {
|
||||
int32_t enable; //enable or not
|
||||
int32_t conn_num;
|
||||
int32_t last_index;
|
||||
int32_t reserved; //reserve for further use
|
||||
struct atcmd_lwip_conn_info conn[ATCMD_LWIP_CONN_STORE_MAX_NUM];
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
AT_PARTITION_ALL = 0,
|
||||
AT_PARTITION_UART = 1,
|
||||
AT_PARTITION_WIFI = 2,
|
||||
AT_PARTITION_LWIP = 3
|
||||
} AT_PARTITION;
|
||||
|
||||
typedef enum {
|
||||
AT_PARTITION_READ = 0,
|
||||
AT_PARTITION_WRITE = 1,
|
||||
AT_PARTITION_ERASE = 2
|
||||
} AT_PARTITION_OP;
|
||||
|
||||
//first segment for uart
|
||||
#define UART_SETTING_BACKUP_SECTOR (0x8000)
|
||||
#define UART_CONF_DATA_OFFSET (0)
|
||||
#define UART_CONF_DATA_SIZE ((((sizeof(UART_LOG_CONF)-1)>>2) + 1)<<2)
|
||||
|
||||
//second segment for wifi config
|
||||
#define WIFI_CONF_DATA_OFFSET (UART_CONF_DATA_OFFSET+UART_CONF_DATA_SIZE)
|
||||
#define WIFI_CONF_DATA_SIZE ((((sizeof(struct atcmd_wifi_conf)-1)>>2) + 1)<<2)
|
||||
|
||||
//fouth segment for lwip config
|
||||
#define LWIP_CONF_DATA_OFFSET (WIFI_CONF_DATA_OFFSET+WIFI_CONF_DATA_SIZE)
|
||||
#define LWIP_CONF_DATA_SIZE ((((sizeof(struct atcmd_lwip_conf)-1)>>2) + 1)<<2)
|
||||
|
||||
extern void atcmd_update_partition_info(AT_PARTITION id, AT_PARTITION_OP ops, u8 *data, u16 len);
|
||||
|
||||
#define ATSTRING_LEN (LOG_SERVICE_BUFLEN)
|
||||
extern char at_string[ATSTRING_LEN];
|
||||
|
||||
extern unsigned char gAT_Echo; // default echo on
|
||||
//extern void uart_at_lock(void);
|
||||
//extern void uart_at_unlock(void);
|
||||
extern void uart_at_send_string(char *str);
|
||||
extern void uart_at_send_buf(u8 *buf, u32 len);
|
||||
|
||||
#define at_printf(fmt, args...) do{\
|
||||
/*uart_at_lock();*/\
|
||||
snprintf(at_string, ATSTRING_LEN, fmt, ##args); \
|
||||
uart_at_send_string(at_string);\
|
||||
/*uart_at_unlock();*/\
|
||||
}while(0)
|
||||
#define at_print_data(data, size) do{\
|
||||
/*uart_at_lock();*/\
|
||||
uart_at_send_buf(data, size);\
|
||||
/*uart_at_unlock();*/\
|
||||
}while(0)
|
||||
|
||||
#else
|
||||
#define at_printf(fmt, args...) do{printf(fmt, ##args);}while(0)
|
||||
#define at_print_data(data, size) do{__rtl_memDump(data, size, NULL);}while(0)
|
||||
#endif//#if CONFIG_EXAMPLE_UART_ATCMD
|
||||
|
||||
#endif
|
473
component/common/api/at_cmd/log_service.c
Normal file
473
component/common/api/at_cmd/log_service.c
Normal file
|
@ -0,0 +1,473 @@
|
|||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "FreeRTOS.h"
|
||||
#if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1)
|
||||
#include "freertos_pmu.h"
|
||||
#endif
|
||||
#include "log_service.h"
|
||||
#include "task.h"
|
||||
#include "semphr.h"
|
||||
#include "main.h"
|
||||
//#include "wifi_util.h"
|
||||
#include "atcmd_wifi.h"
|
||||
#if CONFIG_EXAMPLE_UART_ATCMD
|
||||
#include "atcmd_lwip.h"
|
||||
#endif
|
||||
|
||||
#if SUPPORT_LOG_SERVICE
|
||||
//======================================================
|
||||
struct list_head log_hash[ATC_INDEX_NUM];
|
||||
|
||||
extern void at_wifi_init(void);
|
||||
extern void at_fs_init(void);
|
||||
extern void at_sys_init(void);
|
||||
extern void at_ethernet_init(void);
|
||||
extern void at_google_init(void);
|
||||
extern void at_transport_init(void);
|
||||
//extern void at_app_init(void);
|
||||
#if CONFIG_ALINK
|
||||
extern void at_cloud_init(void);
|
||||
#endif
|
||||
|
||||
|
||||
char log_buf[LOG_SERVICE_BUFLEN];
|
||||
#if CONFIG_LOG_HISTORY
|
||||
char log_history[LOG_HISTORY_LEN][LOG_SERVICE_BUFLEN];
|
||||
static unsigned int log_history_count = 0;
|
||||
#endif
|
||||
xSemaphoreHandle log_rx_interrupt_sema = NULL;
|
||||
#if CONFIG_LOG_SERVICE_LOCK
|
||||
xSemaphoreHandle log_service_sema = NULL;
|
||||
#endif
|
||||
extern xSemaphoreHandle uart_rx_interrupt_sema;
|
||||
|
||||
#if CONFIG_INIC_EN
|
||||
extern unsigned char inic_cmd_ioctl;
|
||||
#endif
|
||||
|
||||
#if defined (__ICCARM__)
|
||||
#pragma section=".data.log_init"
|
||||
|
||||
unsigned int __log_init_begin__;
|
||||
unsigned int __log_init_end__;
|
||||
#elif defined ( __CC_ARM ) || defined(__GNUC__)
|
||||
//#pragma section=".data.log_init"
|
||||
log_init_t* __log_init_begin__;
|
||||
log_init_t* __log_init_end__;
|
||||
log_init_t log_init_table[] = {
|
||||
at_wifi_init,
|
||||
// at_fs_init,
|
||||
at_sys_init,
|
||||
|
||||
#if CONFIG_ETHERNET
|
||||
at_ethernet_init
|
||||
#endif
|
||||
|
||||
#if CONFIG_GOOGLE_NEST
|
||||
at_google_init
|
||||
#endif
|
||||
|
||||
#if CONFIG_TRANSPORT
|
||||
at_transport_init
|
||||
#endif
|
||||
|
||||
#if CONFIG_ALINK
|
||||
at_cloud_init
|
||||
#endif
|
||||
|
||||
// at_app_init
|
||||
};
|
||||
#else
|
||||
#error "not implement, add to linker script"
|
||||
extern unsigned int __log_init_begin__;
|
||||
extern unsigned int __log_init_end__;
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#define USE_STRSEP
|
||||
#endif
|
||||
|
||||
//======================================================
|
||||
int hash_index(char *str)
|
||||
{
|
||||
unsigned int seed = 131; // 31 131 1313 13131 131313 etc..
|
||||
unsigned int hash = 0;
|
||||
|
||||
while (*str)
|
||||
{
|
||||
hash = hash * seed + (*str++);
|
||||
}
|
||||
|
||||
return (hash & 0x7FFFFFFF);
|
||||
}
|
||||
|
||||
void log_add_new_command(log_item_t *new)
|
||||
{
|
||||
int index = hash_index(new->log_cmd)%ATC_INDEX_NUM;
|
||||
|
||||
list_add(&new->node, &log_hash[index]);
|
||||
}
|
||||
void start_log_service(void);
|
||||
void log_service_init(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
#if defined (__ICCARM__)
|
||||
log_init_t *log_init_table;
|
||||
__log_init_begin__ = (unsigned int)__section_begin(".data.log_init");
|
||||
__log_init_end__ = (unsigned int)__section_end(".data.log_init");
|
||||
log_init_table = (log_init_t *)__log_init_begin__;
|
||||
#elif defined(__CC_ARM) || defined(__GNUC__)
|
||||
__log_init_begin__ = log_init_table;
|
||||
__log_init_end__ = log_init_table + sizeof(log_init_table);
|
||||
#else
|
||||
#error "not implement"
|
||||
#endif
|
||||
|
||||
|
||||
for(i=0;i<ATC_INDEX_NUM;i++)
|
||||
INIT_LIST_HEAD(&log_hash[i]);
|
||||
|
||||
for(i=0;i<(__log_init_end__-__log_init_begin__)/sizeof(log_init_t); i++)
|
||||
log_init_table[i]();
|
||||
|
||||
/* Initial uart rx swmaphore*/
|
||||
vSemaphoreCreateBinary(log_rx_interrupt_sema);
|
||||
xSemaphoreTake(log_rx_interrupt_sema, 1/portTICK_RATE_MS);
|
||||
#if CONFIG_LOG_SERVICE_LOCK
|
||||
log_service_lock_init();
|
||||
#endif
|
||||
start_log_service();
|
||||
}
|
||||
|
||||
//sizeof(log_items)/sizeof(log_items[0])
|
||||
void log_service_add_table(log_item_t *tbl, int len)
|
||||
{
|
||||
int i;
|
||||
for(i=0;i<len;i++)
|
||||
log_add_new_command(&tbl[i]);
|
||||
}
|
||||
|
||||
void* log_action(char *cmd)
|
||||
{
|
||||
int search_cnt=0;
|
||||
int index = hash_index(cmd)%ATC_INDEX_NUM;
|
||||
struct list_head *head = &log_hash[index];
|
||||
struct list_head *iterator;
|
||||
log_item_t *item;
|
||||
void *act = NULL;
|
||||
|
||||
list_for_each(iterator, head) {
|
||||
item = list_entry(iterator, log_item_t, node);
|
||||
search_cnt++;
|
||||
if( strcmp(item->log_cmd, cmd) == 0){
|
||||
//printf("%s match %s, search cnt %d\n\r", cmd, item->log_cmd, search_cnt);
|
||||
act = (void*)item->at_act;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return act;
|
||||
}
|
||||
|
||||
void* log_handler(char *cmd)
|
||||
{
|
||||
log_act_t action=NULL;
|
||||
char buf[LOG_SERVICE_BUFLEN] = {0};
|
||||
char *copy=buf;
|
||||
char *token = NULL;
|
||||
char *param = NULL;
|
||||
char tok[5] = {0};//'\0'
|
||||
#if CONFIG_LOG_HISTORY
|
||||
strcpy(log_history[((log_history_count++)%LOG_HISTORY_LEN)], log_buf);
|
||||
#endif
|
||||
strncpy(copy, cmd,LOG_SERVICE_BUFLEN-1);
|
||||
|
||||
#if defined(USE_STRSEP)
|
||||
token = _strsep(©, "=");
|
||||
param = copy;
|
||||
#else
|
||||
token = strtok(copy, "=");
|
||||
param = strtok(NULL, NULL);
|
||||
#endif
|
||||
if(token && (strlen(token) <= 4))
|
||||
strcpy(tok, token);
|
||||
else{
|
||||
//printf("\n\rAT Cmd format error!\n");
|
||||
return NULL;
|
||||
};
|
||||
//printf(" Command %s \n\r ", tok);
|
||||
//printf(" Param %s \n\r", param);
|
||||
action = (log_act_t)log_action(tok);
|
||||
|
||||
if(action){
|
||||
action(param);
|
||||
}
|
||||
return (void*)action;
|
||||
|
||||
}
|
||||
|
||||
int parse_param(char *buf, char **argv)
|
||||
{
|
||||
int argc = 1;
|
||||
char str_buf[LOG_SERVICE_BUFLEN] = "\0";
|
||||
int str_count = 0;
|
||||
int buf_cnt = 0;
|
||||
|
||||
if(buf == NULL)
|
||||
goto exit;
|
||||
|
||||
while((argc < MAX_ARGC) && (*buf != '\0')) {
|
||||
while((*buf == ',') || (*buf == '[') || (*buf == ']')){
|
||||
if((*buf == ',') && (*(buf+1) == ',')){
|
||||
argv[argc] = NULL;
|
||||
argc++;
|
||||
}
|
||||
*buf = '\0';
|
||||
buf++;
|
||||
}
|
||||
|
||||
if(*buf == '\0')
|
||||
break;
|
||||
else if(*buf == '"'){
|
||||
memset(str_buf,'\0',LOG_SERVICE_BUFLEN);
|
||||
str_count = 0;
|
||||
buf_cnt = 0;
|
||||
*buf = '\0';
|
||||
buf ++;
|
||||
if(*buf == '\0')
|
||||
break;
|
||||
argv[argc] = buf;
|
||||
while((*buf != '"')&&(*buf != '\0')){
|
||||
if(*buf == '\\'){
|
||||
buf ++;
|
||||
buf_cnt++;
|
||||
}
|
||||
str_buf[str_count] = *buf;
|
||||
str_count++;
|
||||
buf_cnt++;
|
||||
buf ++;
|
||||
}
|
||||
*buf = '\0';
|
||||
memcpy(buf-buf_cnt,str_buf,buf_cnt);
|
||||
}
|
||||
else{
|
||||
argv[argc] = buf;
|
||||
}
|
||||
argc++;
|
||||
buf++;
|
||||
|
||||
while( (*buf != ',')&&(*buf != '\0')&&(*buf != '[')&&(*buf != ']') )
|
||||
buf++;
|
||||
}
|
||||
exit:
|
||||
return argc;
|
||||
}
|
||||
|
||||
unsigned char gDbgLevel = AT_DBG_ERROR;
|
||||
unsigned int gDbgFlag = 0xFFFFFFFF;
|
||||
void at_set_debug_level(unsigned char newDbgLevel)
|
||||
{
|
||||
gDbgLevel = newDbgLevel;
|
||||
}
|
||||
|
||||
void at_set_debug_mask(unsigned int newDbgFlag)
|
||||
{
|
||||
gDbgFlag = newDbgFlag;
|
||||
}
|
||||
|
||||
#if SUPPORT_INTERACTIVE_MODE
|
||||
extern char uart_buf[64];
|
||||
void legency_interactive_handler(unsigned char argc, unsigned char **argv)
|
||||
{
|
||||
#if 0 //defined(CONFIG_PLATFORM_8195A)
|
||||
if(argc<1)
|
||||
{
|
||||
DiagPrintf("Wrong argument number!\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
DiagPrintf("Wlan Normal Mode\n");
|
||||
|
||||
WlanNormal( argc, argv);
|
||||
#else
|
||||
strncpy(uart_buf, log_buf, 63);//uart_buf[64]
|
||||
xSemaphoreGive(uart_rx_interrupt_sema);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CONFIG_WLAN
|
||||
#ifndef WLAN0_NAME
|
||||
#define WLAN0_NAME "wlan0"
|
||||
#endif
|
||||
#ifndef WLAN1_NAME
|
||||
#define WLAN1_NAME "wlan1"
|
||||
#endif
|
||||
int mp_commnad_handler(char *cmd)
|
||||
{
|
||||
char buf[64] = {0};
|
||||
char *token = NULL;
|
||||
|
||||
//strcpy(buf, cmd);
|
||||
strncpy(buf, cmd, (64-1));
|
||||
token = strtok(buf, " ");
|
||||
if(token && (strcmp(buf, "iwpriv") == 0)){
|
||||
token = strtok(NULL, "");
|
||||
wext_private_command(WLAN0_NAME, token, 1);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
void print_help_msg(void){
|
||||
#if CONFIG_WLAN
|
||||
extern void print_wlan_help(void);
|
||||
print_wlan_help();
|
||||
#endif
|
||||
//add other help message print here
|
||||
}
|
||||
|
||||
int print_help_handler(char *cmd){
|
||||
if(strcmp(cmd, "help") == 0){
|
||||
print_help_msg();
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if CONFIG_LOG_SERVICE_LOCK
|
||||
void log_service_lock(void)
|
||||
{
|
||||
RtlDownSema(&log_service_sema);
|
||||
}
|
||||
|
||||
u32 log_service_lock_timeout(u32 ms)
|
||||
{
|
||||
return RtlDownSemaWithTimeout(&log_service_sema, ms);
|
||||
}
|
||||
|
||||
void log_service_unlock(void)
|
||||
{
|
||||
RtlUpSema(&log_service_sema);
|
||||
}
|
||||
|
||||
void log_service_lock_init(void){
|
||||
RtlInitSema(&log_service_sema, 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
void log_service(void *param)
|
||||
{
|
||||
_AT_DBG_MSG(AT_FLAG_COMMON, AT_DBG_ALWAYS, "\n\rStart LOG SERVICE MODE\n\r");
|
||||
_AT_DBG_MSG(AT_FLAG_COMMON, AT_DBG_ALWAYS, "\n\r# ");
|
||||
while(1){
|
||||
while(xSemaphoreTake(log_rx_interrupt_sema, portMAX_DELAY) != pdTRUE);
|
||||
#if CONFIG_LOG_SERVICE_LOCK
|
||||
log_service_lock();
|
||||
#endif
|
||||
if(log_handler((char *)log_buf) == NULL){
|
||||
#if CONFIG_WLAN
|
||||
if(mp_commnad_handler((char *)log_buf) < 0)
|
||||
#endif
|
||||
{
|
||||
#if SUPPORT_INTERACTIVE_MODE
|
||||
print_help_handler((char *)log_buf);
|
||||
legency_interactive_handler(NULL, NULL);
|
||||
#if CONFIG_LOG_SERVICE_LOCK
|
||||
log_service_unlock();
|
||||
#endif
|
||||
continue;
|
||||
#else
|
||||
if(print_help_handler((char *)log_buf) < 0){
|
||||
at_printf("\r\nunknown command '%s'", log_buf);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
log_buf[0] = '\0';
|
||||
#if CONFIG_INIC_EN
|
||||
inic_cmd_ioctl = 0;
|
||||
#endif
|
||||
_AT_DBG_MSG(AT_FLAG_COMMON, AT_DBG_ALWAYS, "\n\r[MEM] After do cmd, available heap %d\n\r", xPortGetFreeHeapSize());
|
||||
_AT_DBG_MSG(AT_FLAG_COMMON, AT_DBG_ALWAYS, "\r\n\n# "); //"#" is needed for mp tool
|
||||
#if CONFIG_EXAMPLE_UART_ATCMD
|
||||
if(atcmd_lwip_is_tt_mode())
|
||||
at_printf(STR_END_OF_ATDATA_RET);
|
||||
else
|
||||
at_printf(STR_END_OF_ATCMD_RET);
|
||||
#endif
|
||||
#if CONFIG_LOG_SERVICE_LOCK
|
||||
log_service_unlock();
|
||||
#endif
|
||||
#if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1)
|
||||
release_wakelock(WAKELOCK_LOGUART);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#define STACKSIZE 1280
|
||||
void start_log_service(void)
|
||||
{
|
||||
xTaskHandle CreatedTask;
|
||||
int result;
|
||||
|
||||
#if CONFIG_USE_TCM_HEAP
|
||||
extern void *tcm_heap_malloc(int size);
|
||||
void *stack_addr = tcm_heap_malloc(STACKSIZE * sizeof(int));
|
||||
|
||||
if(stack_addr == NULL){
|
||||
}
|
||||
|
||||
result = xTaskGenericCreate(
|
||||
log_service,
|
||||
( signed portCHAR * ) "log_service",
|
||||
STACKSIZE,
|
||||
NULL,
|
||||
tskIDLE_PRIORITY + 5,
|
||||
&CreatedTask,
|
||||
stack_addr,
|
||||
NULL);
|
||||
#else
|
||||
result = xTaskCreate( log_service, ( signed portCHAR * ) "log_service", STACKSIZE, NULL, tskIDLE_PRIORITY + 5, &CreatedTask );
|
||||
#endif
|
||||
|
||||
if(result != pdPASS) {
|
||||
printf("\n\r%s xTaskCreate failed", __FUNCTION__);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void fAT_exit(void *arg){
|
||||
printf("\n\rLeave LOG SERVICE");
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
#if CONFIG_LOG_HISTORY
|
||||
void fAT_log(void *arg){
|
||||
int i = 0;
|
||||
printf("[AT]log history:\n\n\r");
|
||||
if(log_history_count > LOG_HISTORY_LEN){
|
||||
for(i=0; i<4; i++)
|
||||
printf(" %s\n\r", log_history[((log_history_count+i)%LOG_HISTORY_LEN)]);
|
||||
}
|
||||
else{
|
||||
for(i=0; i<(log_history_count-1); i++)
|
||||
printf(" %s\n\r", log_history[i]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
log_item_t at_log_items[ ] = {
|
||||
{"AT--", fAT_exit,},
|
||||
#if CONFIG_LOG_HISTORY
|
||||
{"AT??", fAT_log,},
|
||||
#endif
|
||||
{"ATxx", fAT_exit,}
|
||||
};
|
||||
void at_log_init(void)
|
||||
{
|
||||
log_service_add_table(at_log_items, sizeof(at_log_items)/sizeof(at_log_items[0]));
|
||||
}
|
||||
log_module_init(at_log_init);
|
||||
#endif
|
120
component/common/api/at_cmd/log_service.h
Normal file
120
component/common/api/at_cmd/log_service.h
Normal file
|
@ -0,0 +1,120 @@
|
|||
#ifndef LOG_SERVICE_H
|
||||
#define LOG_SERVICE_H
|
||||
|
||||
#include "dlist.h"
|
||||
/*
|
||||
* Include user defined options first. Anything not defined in these files
|
||||
* will be set to standard values. Override anything you dont like!
|
||||
*/
|
||||
#if defined(CONFIG_PLATFORM_8195A) || defined(CONFIG_PLATFORM_8711B)
|
||||
#include "platform_opts.h"
|
||||
#include "platform_stdlib.h"
|
||||
#endif
|
||||
|
||||
#ifdef __ICCARM__
|
||||
#define STRINGIFY(s) #s
|
||||
#define SECTION(_name) _Pragma( STRINGIFY(location=_name))
|
||||
#define log_module_init(fn) \
|
||||
SECTION(".data.log_init") __root static void* log_##fn = (void*)fn
|
||||
#elif defined(__CC_ARM)
|
||||
#define log_module_init(fn) \
|
||||
static void* log_##fn __attribute__((section(".data.log_init"))) = (void*)fn;
|
||||
#define DiagPrintf printf
|
||||
#elif defined(__GNUC__)
|
||||
#define log_module_init(fn) \
|
||||
static void* log_##fn __attribute__((section(".data.log_init"))) = (void*)fn;
|
||||
#else
|
||||
#error "not implement"
|
||||
#endif
|
||||
|
||||
#define ATC_INDEX_NUM 32
|
||||
|
||||
#ifndef SUPPORT_LOG_SERVICE
|
||||
#define SUPPORT_LOG_SERVICE 1
|
||||
#endif
|
||||
|
||||
//LOG_SERVICE_BUFLEN: default, only 63 bytes could be used for keeping input
|
||||
// cmd, the last byte is for string end ('\0').
|
||||
#ifndef LOG_SERVICE_BUFLEN
|
||||
#define LOG_SERVICE_BUFLEN 64
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_LOG_HISTORY
|
||||
#define CONFIG_LOG_HISTORY 0
|
||||
#if CONFIG_LOG_HISTORY
|
||||
#define LOG_HISTORY_LEN 5
|
||||
#endif
|
||||
#endif //#ifndef CONFIG_LOG_HISTORY
|
||||
|
||||
#ifndef MAX_ARGC
|
||||
#define MAX_ARGC 12
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_LOG_SERVICE_LOCK
|
||||
#define CONFIG_LOG_SERVICE_LOCK 0 // //to protect log_buf[], only one command processed per time
|
||||
#endif
|
||||
|
||||
#define AT_BIT(n) (1<<n)
|
||||
#define AT_FLAG_DUMP AT_BIT(0)
|
||||
#define AT_FLAG_EDIT AT_BIT(1)
|
||||
#define AT_FLAG_ADC AT_BIT(2)
|
||||
#define AT_FLAG_GPIO AT_BIT(3)
|
||||
#define AT_FLAG_OTA AT_BIT(4)
|
||||
#define AT_FLAG_NFC AT_BIT(5)
|
||||
#define AT_FLAG_OS AT_BIT(6)
|
||||
#define AT_FLAG_LWIP AT_BIT(7)
|
||||
#define AT_FLAG_COMMON AT_BIT(8)
|
||||
#define AT_FLAG_WIFI AT_BIT(9)
|
||||
|
||||
enum{
|
||||
AT_DBG_OFF = 0,
|
||||
AT_DBG_ALWAYS,
|
||||
AT_DBG_ERROR,
|
||||
AT_DBG_WARNING,
|
||||
AT_DBG_INFO
|
||||
};
|
||||
|
||||
extern unsigned char gDbgLevel;
|
||||
extern unsigned int gDbgFlag;
|
||||
|
||||
#define AT_PRINTK(fmt, args...) printf(fmt"\r\n",## args)
|
||||
#define _AT_PRINTK(fmt, args...) printf(fmt,## args)
|
||||
#define AT_DBG_MSG(flag, level, fmt, args...) \
|
||||
do{ \
|
||||
if(((flag) & gDbgFlag) && (level <= gDbgLevel)){ \
|
||||
AT_PRINTK(fmt,## args); \
|
||||
} \
|
||||
}while(0)
|
||||
#define _AT_DBG_MSG(flag, level, fmt, args...) \
|
||||
do{ \
|
||||
if(((flag) & gDbgFlag) && (level <= gDbgLevel)){ \
|
||||
_AT_PRINTK(fmt,## args); \
|
||||
} \
|
||||
}while(0)
|
||||
|
||||
#ifndef SUPPORT_INTERACTIVE_MODE
|
||||
#define SUPPORT_INTERACTIVE_MODE 0
|
||||
#endif //#ifndef SUPPORT_INTERACTIVE_MODE
|
||||
|
||||
typedef void (*log_init_t)(void);
|
||||
typedef void (*log_act_t)(void*);
|
||||
typedef struct _at_command_item_{
|
||||
char *log_cmd;
|
||||
log_act_t at_act;
|
||||
struct list_head node;
|
||||
}log_item_t;
|
||||
|
||||
void log_service_add_table(log_item_t *tbl, int len);
|
||||
int parse_param(char *buf, char **argv);
|
||||
#if CONFIG_LOG_SERVICE_LOCK
|
||||
void log_service_lock_init(void);
|
||||
void log_service_lock(void);
|
||||
u32 log_service_lock_timeout(u32 ms);
|
||||
void log_service_unlock(void);
|
||||
#endif
|
||||
|
||||
#define C_NUM_AT_CMD 4 //"ATxx", 4 characters
|
||||
#define C_NUM_AT_CMD_DLT 1 //"=", 1 charater
|
||||
#define STR_END_OF_ATCMD_RET "\r\n\n# " //each AT command response will end with this string
|
||||
#define STR_END_OF_ATDATA_RET "\r\n\n> " //data transparent transmission indicator
|
||||
#endif
|
418
component/common/api/lwip_netconf.c
Normal file
418
component/common/api/lwip_netconf.c
Normal file
|
@ -0,0 +1,418 @@
|
|||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "lwip/mem.h"
|
||||
#include "lwip/memp.h"
|
||||
#include "lwip/dhcp.h"
|
||||
#include "lwip/dns.h"
|
||||
#include "ethernetif.h"
|
||||
#include "main.h"
|
||||
#include "lwip_netconf.h"
|
||||
#if CONFIG_WLAN
|
||||
#include "wifi_ind.h"
|
||||
#endif
|
||||
#if defined(STM32F2XX)
|
||||
#include "stm322xg_eval_lcd.h"
|
||||
#elif defined(STM32F4XX)
|
||||
#include "stm324xg_eval_lcd.h"
|
||||
#endif
|
||||
#include <platform/platform_stdlib.h>
|
||||
|
||||
|
||||
/*Static IP ADDRESS*/
|
||||
#ifndef IP_ADDR0
|
||||
#define IP_ADDR0 192
|
||||
#define IP_ADDR1 168
|
||||
#define IP_ADDR2 1
|
||||
#define IP_ADDR3 80
|
||||
#endif
|
||||
|
||||
/*NETMASK*/
|
||||
#ifndef NETMASK_ADDR0
|
||||
#define NETMASK_ADDR0 255
|
||||
#define NETMASK_ADDR1 255
|
||||
#define NETMASK_ADDR2 255
|
||||
#define NETMASK_ADDR3 0
|
||||
#endif
|
||||
|
||||
/*Gateway Address*/
|
||||
#ifndef GW_ADDR0
|
||||
#define GW_ADDR0 192
|
||||
#define GW_ADDR1 168
|
||||
#define GW_ADDR2 1
|
||||
#define GW_ADDR3 1
|
||||
#endif
|
||||
|
||||
/*Static IP ADDRESS*/
|
||||
#ifndef AP_IP_ADDR0
|
||||
#define AP_IP_ADDR0 192
|
||||
#define AP_IP_ADDR1 168
|
||||
#define AP_IP_ADDR2 43
|
||||
#define AP_IP_ADDR3 1
|
||||
#endif
|
||||
|
||||
/*NETMASK*/
|
||||
#ifndef AP_NETMASK_ADDR0
|
||||
#define AP_NETMASK_ADDR0 255
|
||||
#define AP_NETMASK_ADDR1 255
|
||||
#define AP_NETMASK_ADDR2 255
|
||||
#define AP_NETMASK_ADDR3 0
|
||||
#endif
|
||||
|
||||
/*Gateway Address*/
|
||||
#ifndef AP_GW_ADDR0
|
||||
#define AP_GW_ADDR0 192
|
||||
#define AP_GW_ADDR1 168
|
||||
#define AP_GW_ADDR2 43
|
||||
#define AP_GW_ADDR3 1
|
||||
#endif
|
||||
|
||||
/*Static IP ADDRESS FOR ETHERNET*/
|
||||
#ifndef ETH_IP_ADDR0
|
||||
#define ETH_IP_ADDR0 192
|
||||
#define ETH_IP_ADDR1 168
|
||||
#define ETH_IP_ADDR2 0
|
||||
#define ETH_IP_ADDR3 80
|
||||
#endif
|
||||
|
||||
/*NETMASK FOR ETHERNET*/
|
||||
#ifndef ETH_NETMASK_ADDR0
|
||||
#define ETH_NETMASK_ADDR0 255
|
||||
#define ETH_NETMASK_ADDR1 255
|
||||
#define ETH_NETMASK_ADDR2 255
|
||||
#define ETH_NETMASK_ADDR3 0
|
||||
#endif
|
||||
|
||||
/*Gateway address for ethernet*/
|
||||
#ifndef ETH_GW_ADDR0
|
||||
#define ETH_GW_ADDR0 192
|
||||
#define ETH_GW_ADDR1 168
|
||||
#define ETH_GW_ADDR2 0
|
||||
#define ETH_GW_ADDR3 1
|
||||
#endif
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
#define MAX_DHCP_TRIES 5
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
|
||||
struct netif xnetif[NET_IF_NUM]; /* network interface structure */
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/**
|
||||
* @brief Initializes the lwIP stack
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
#if CONFIG_WLAN
|
||||
extern int error_flag;
|
||||
extern rtw_mode_t wifi_mode;
|
||||
#endif
|
||||
|
||||
int lwip_init_done = 0;
|
||||
|
||||
void LwIP_Init(void)
|
||||
{
|
||||
struct ip_addr ipaddr;
|
||||
struct ip_addr netmask;
|
||||
struct ip_addr gw;
|
||||
int8_t idx = 0;
|
||||
/* Create tcp_ip stack thread */
|
||||
tcpip_init( NULL, NULL );
|
||||
|
||||
/* - netif_add(struct netif *netif, struct ip_addr *ipaddr,
|
||||
struct ip_addr *netmask, struct ip_addr *gw,
|
||||
void *state, err_t (* init)(struct netif *netif),
|
||||
err_t (* input)(struct pbuf *p, struct netif *netif))
|
||||
|
||||
Adds your network interface to the netif_list. Allocate a struct
|
||||
netif and pass a pointer to this structure as the first argument.
|
||||
Give pointers to cleared ip_addr structures when using DHCP,
|
||||
or fill them with sane numbers otherwise. The state pointer may be NULL.
|
||||
|
||||
The init function pointer must point to a initialization function for
|
||||
your ethernet netif interface. The following code illustrates it's use.*/
|
||||
//printf("NET_IF_NUM:%d\n\r",NET_IF_NUM);
|
||||
for(idx=NET_IF_NUM - 1;idx>=0;idx--){
|
||||
if(idx==0){
|
||||
IP4_ADDR(&ipaddr, IP_ADDR0, IP_ADDR1, IP_ADDR2, IP_ADDR3);
|
||||
IP4_ADDR(&netmask, NETMASK_ADDR0, NETMASK_ADDR1 , NETMASK_ADDR2, NETMASK_ADDR3);
|
||||
IP4_ADDR(&gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);
|
||||
}
|
||||
else{
|
||||
IP4_ADDR(&ipaddr, AP_IP_ADDR0, AP_IP_ADDR1, AP_IP_ADDR2, AP_IP_ADDR3);
|
||||
IP4_ADDR(&netmask, AP_NETMASK_ADDR0, AP_NETMASK_ADDR1 , AP_NETMASK_ADDR2, AP_NETMASK_ADDR3);
|
||||
IP4_ADDR(&gw, AP_GW_ADDR0, AP_GW_ADDR1, AP_GW_ADDR2, AP_GW_ADDR3);
|
||||
}
|
||||
#if CONFIG_ETHERNET
|
||||
if(idx == NET_IF_NUM - 1)
|
||||
{
|
||||
IP4_ADDR(&ipaddr, ETH_IP_ADDR0, ETH_IP_ADDR1, ETH_IP_ADDR2, ETH_IP_ADDR3);
|
||||
IP4_ADDR(&netmask, ETH_NETMASK_ADDR0, ETH_NETMASK_ADDR1 , ETH_NETMASK_ADDR2, ETH_NETMASK_ADDR3);
|
||||
IP4_ADDR(&gw, ETH_GW_ADDR0, ETH_GW_ADDR1, ETH_GW_ADDR2, ETH_GW_ADDR3);
|
||||
}
|
||||
#endif
|
||||
xnetif[idx].name[0] = 'r';
|
||||
xnetif[idx].name[1] = '0'+idx;
|
||||
|
||||
#if CONFIG_ETHERNET
|
||||
if(idx == NET_IF_NUM - 1)
|
||||
netif_add(&xnetif[idx], &ipaddr, &netmask, &gw, NULL, ðernetif_mii_init, &tcpip_input);
|
||||
else
|
||||
netif_add(&xnetif[idx], &ipaddr, &netmask, &gw, NULL, ðernetif_init, &tcpip_input);
|
||||
#else
|
||||
netif_add(&xnetif[idx], &ipaddr, &netmask, &gw, NULL, ðernetif_init, &tcpip_input);
|
||||
#endif
|
||||
printf("interface %d is initialized\n", idx);
|
||||
|
||||
}
|
||||
|
||||
/* Registers the default network interface. */
|
||||
netif_set_default(&xnetif[0]);
|
||||
|
||||
/* When the netif is fully configured this function must be called.*/
|
||||
for(idx = 0;idx < NET_IF_NUM;idx++)
|
||||
netif_set_up(&xnetif[idx]);
|
||||
|
||||
lwip_init_done = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief LwIP_DHCP_Process_Handle
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
uint8_t LwIP_DHCP(uint8_t idx, uint8_t dhcp_state)
|
||||
{
|
||||
struct ip_addr ipaddr;
|
||||
struct ip_addr netmask;
|
||||
struct ip_addr gw;
|
||||
uint32_t IPaddress;
|
||||
uint8_t iptab[4];
|
||||
uint8_t DHCP_state;
|
||||
int mscnt = 0;
|
||||
struct netif *pnetif = NULL;
|
||||
|
||||
DHCP_state = dhcp_state;
|
||||
|
||||
#if !CONFIG_ETHERNET
|
||||
if(idx > 1)
|
||||
idx = 1;
|
||||
#endif
|
||||
|
||||
pnetif = &xnetif[idx];
|
||||
if(DHCP_state == 0){
|
||||
pnetif->ip_addr.addr = 0;
|
||||
pnetif->netmask.addr = 0;
|
||||
pnetif->gw.addr = 0;
|
||||
}
|
||||
|
||||
for (;;)
|
||||
{
|
||||
//printf("\n\r ========DHCP_state:%d============\n\r",DHCP_state);
|
||||
switch (DHCP_state)
|
||||
{
|
||||
case DHCP_START:
|
||||
{
|
||||
#if CONFIG_WLAN
|
||||
wifi_unreg_event_handler(WIFI_EVENT_BEACON_AFTER_DHCP, wifi_rx_beacon_hdl);
|
||||
#endif
|
||||
dhcp_start(pnetif);
|
||||
IPaddress = 0;
|
||||
DHCP_state = DHCP_WAIT_ADDRESS;
|
||||
}
|
||||
break;
|
||||
|
||||
case DHCP_WAIT_ADDRESS:
|
||||
{
|
||||
/* Read the new IP address */
|
||||
IPaddress = pnetif->ip_addr.addr;
|
||||
|
||||
if (IPaddress!=0)
|
||||
{
|
||||
DHCP_state = DHCP_ADDRESS_ASSIGNED;
|
||||
#if CONFIG_WLAN
|
||||
wifi_reg_event_handler(WIFI_EVENT_BEACON_AFTER_DHCP, wifi_rx_beacon_hdl, NULL);
|
||||
#endif
|
||||
|
||||
/* Stop DHCP */
|
||||
// dhcp_stop(pnetif); /* can not stop, need to renew, Robbie*/
|
||||
|
||||
iptab[0] = (uint8_t)(IPaddress >> 24);
|
||||
iptab[1] = (uint8_t)(IPaddress >> 16);
|
||||
iptab[2] = (uint8_t)(IPaddress >> 8);
|
||||
iptab[3] = (uint8_t)(IPaddress);
|
||||
printf("\n\rInterface %d IP address : %d.%d.%d.%d", idx, iptab[3], iptab[2], iptab[1], iptab[0]);
|
||||
#if CONFIG_WLAN
|
||||
error_flag = RTW_NO_ERROR;
|
||||
#endif
|
||||
return DHCP_ADDRESS_ASSIGNED;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* DHCP timeout */
|
||||
if (pnetif->dhcp->tries > MAX_DHCP_TRIES)
|
||||
{
|
||||
DHCP_state = DHCP_TIMEOUT;
|
||||
|
||||
/* Stop DHCP */
|
||||
dhcp_stop(pnetif);
|
||||
|
||||
/* Static address used */
|
||||
IP4_ADDR(&ipaddr, IP_ADDR0 ,IP_ADDR1 , IP_ADDR2 , IP_ADDR3 );
|
||||
IP4_ADDR(&netmask, NETMASK_ADDR0, NETMASK_ADDR1, NETMASK_ADDR2, NETMASK_ADDR3);
|
||||
IP4_ADDR(&gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);
|
||||
netif_set_addr(pnetif, &ipaddr , &netmask, &gw);
|
||||
|
||||
iptab[0] = IP_ADDR3;
|
||||
iptab[1] = IP_ADDR2;
|
||||
iptab[2] = IP_ADDR1;
|
||||
iptab[3] = IP_ADDR0;
|
||||
printf("\n\rInterface %d DHCP timeout",idx);
|
||||
printf("\n\rStatic IP address : %d.%d.%d.%d", iptab[3], iptab[2], iptab[1], iptab[0]);
|
||||
#if CONFIG_WLAN
|
||||
error_flag = RTW_DHCP_FAIL;
|
||||
#endif
|
||||
return DHCP_TIMEOUT;
|
||||
}else
|
||||
{
|
||||
//sys_msleep(DHCP_FINE_TIMER_MSECS);
|
||||
vTaskDelay(DHCP_FINE_TIMER_MSECS);
|
||||
dhcp_fine_tmr();
|
||||
mscnt += DHCP_FINE_TIMER_MSECS;
|
||||
if (mscnt >= DHCP_COARSE_TIMER_SECS*1000)
|
||||
{
|
||||
dhcp_coarse_tmr();
|
||||
mscnt = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case DHCP_RELEASE_IP:
|
||||
#if CONFIG_WLAN
|
||||
wifi_unreg_event_handler(WIFI_EVENT_BEACON_AFTER_DHCP, wifi_rx_beacon_hdl);
|
||||
#endif
|
||||
printf("\n\rLwIP_DHCP: Release ip");
|
||||
dhcp_release_unicast(pnetif);
|
||||
return DHCP_RELEASE_IP;
|
||||
case DHCP_STOP:
|
||||
#if CONFIG_WLAN
|
||||
wifi_unreg_event_handler(WIFI_EVENT_BEACON_AFTER_DHCP, wifi_rx_beacon_hdl);
|
||||
#endif
|
||||
printf("\n\rLwIP_DHCP: dhcp stop.");
|
||||
dhcp_stop(pnetif);
|
||||
return DHCP_STOP;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t* LwIP_GetMAC(struct netif *pnetif)
|
||||
{
|
||||
return (uint8_t *) (pnetif->hwaddr);
|
||||
}
|
||||
|
||||
uint8_t* LwIP_GetIP(struct netif *pnetif)
|
||||
{
|
||||
return (uint8_t *) &(pnetif->ip_addr);
|
||||
}
|
||||
|
||||
uint8_t* LwIP_GetGW(struct netif *pnetif)
|
||||
{
|
||||
return (uint8_t *) &(pnetif->gw);
|
||||
}
|
||||
|
||||
uint8_t* LwIP_GetMASK(struct netif *pnetif)
|
||||
{
|
||||
return (uint8_t *) &(pnetif->netmask);
|
||||
}
|
||||
|
||||
uint8_t* LwIP_GetBC(struct netif *pnetif)
|
||||
{
|
||||
return (uint8_t *) &(pnetif->dhcp->offered_bc_addr);
|
||||
}
|
||||
|
||||
#if LWIP_DNS
|
||||
void LwIP_GetDNS(struct ip_addr* dns)
|
||||
{
|
||||
*dns = dns_getserver(0);
|
||||
}
|
||||
|
||||
void LwIP_SetDNS(struct ip_addr* dns)
|
||||
{
|
||||
dns_setserver(0, dns);
|
||||
}
|
||||
#endif
|
||||
void LwIP_UseStaticIP(struct netif *pnetif)
|
||||
{
|
||||
struct ip_addr ipaddr;
|
||||
struct ip_addr netmask;
|
||||
struct ip_addr gw;
|
||||
|
||||
/* Static address used */
|
||||
if(pnetif->name[1] == '0'){
|
||||
#if CONFIG_WLAN
|
||||
if(wifi_mode == RTW_MODE_STA){
|
||||
IP4_ADDR(&ipaddr, IP_ADDR0 ,IP_ADDR1 , IP_ADDR2 , IP_ADDR3 );
|
||||
IP4_ADDR(&netmask, NETMASK_ADDR0, NETMASK_ADDR1, NETMASK_ADDR2, NETMASK_ADDR3);
|
||||
IP4_ADDR(&gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);
|
||||
}
|
||||
else if(wifi_mode == RTW_MODE_AP){
|
||||
IP4_ADDR(&ipaddr, AP_IP_ADDR0, AP_IP_ADDR1, AP_IP_ADDR2, AP_IP_ADDR3);
|
||||
IP4_ADDR(&netmask, AP_NETMASK_ADDR0, AP_NETMASK_ADDR1 , AP_NETMASK_ADDR2, AP_NETMASK_ADDR3);
|
||||
IP4_ADDR(&gw, AP_GW_ADDR0, AP_GW_ADDR1, AP_GW_ADDR2, AP_GW_ADDR3);
|
||||
}
|
||||
#endif
|
||||
}else{
|
||||
IP4_ADDR(&ipaddr, AP_IP_ADDR0, AP_IP_ADDR1, AP_IP_ADDR2, AP_IP_ADDR3);
|
||||
IP4_ADDR(&netmask, AP_NETMASK_ADDR0, AP_NETMASK_ADDR1 , AP_NETMASK_ADDR2, AP_NETMASK_ADDR3);
|
||||
IP4_ADDR(&gw, AP_GW_ADDR0, AP_GW_ADDR1, AP_GW_ADDR2, AP_GW_ADDR3);
|
||||
}
|
||||
|
||||
netif_set_addr(pnetif, &ipaddr , &netmask, &gw);
|
||||
}
|
||||
#if LWIP_AUTOIP
|
||||
#include <lwip/autoip.h>
|
||||
|
||||
void LwIP_AUTOIP(struct netif *pnetif)
|
||||
{
|
||||
uint8_t *ip = LwIP_GetIP(pnetif);
|
||||
|
||||
autoip_start(pnetif);
|
||||
|
||||
while((pnetif->autoip->state == AUTOIP_STATE_PROBING) || (pnetif->autoip->state == AUTOIP_STATE_ANNOUNCING)) {
|
||||
vTaskDelay(1000);
|
||||
}
|
||||
|
||||
if(*((uint32_t *) ip) == 0) {
|
||||
struct ip_addr ipaddr;
|
||||
struct ip_addr netmask;
|
||||
struct ip_addr gw;
|
||||
|
||||
printf("AUTOIP timeout\n");
|
||||
|
||||
/* Static address used */
|
||||
IP4_ADDR(&ipaddr, IP_ADDR0 ,IP_ADDR1 , IP_ADDR2 , IP_ADDR3 );
|
||||
IP4_ADDR(&netmask, NETMASK_ADDR0, NETMASK_ADDR1, NETMASK_ADDR2, NETMASK_ADDR3);
|
||||
IP4_ADDR(&gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);
|
||||
netif_set_addr(pnetif, &ipaddr , &netmask, &gw);
|
||||
printf("Static IP address : %d.%d.%d.%d\n", ip[0], ip[1], ip[2], ip[3]);
|
||||
}
|
||||
else {
|
||||
printf("\nLink-local address: %d.%d.%d.%d\n", ip[0], ip[1], ip[2], ip[3]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if LWIP_IPV6
|
||||
/* Get IPv6 address with lwip 1.5.0 */
|
||||
void LwIP_AUTOIP_IPv6(struct netif *pnetif)
|
||||
{
|
||||
uint8_t *ipv6 = (uint8_t *) &(pnetif->ip6_addr[0].addr[0]);
|
||||
|
||||
netif_create_ip6_linklocal_address(pnetif, 1);
|
||||
printf("\nIPv6 link-local address: %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x\n",
|
||||
ipv6[0], ipv6[1], ipv6[2], ipv6[3], ipv6[4], ipv6[5], ipv6[6], ipv6[7],
|
||||
ipv6[8], ipv6[9], ipv6[10], ipv6[11], ipv6[12], ipv6[13], ipv6[14], ipv6[15]);
|
||||
}
|
||||
#endif
|
91
component/common/api/lwip_netconf.h
Normal file
91
component/common/api/lwip_netconf.h
Normal file
|
@ -0,0 +1,91 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* @file netconf.h
|
||||
* @author MCD Application Team
|
||||
* @version V1.1.0
|
||||
* @date 07-October-2011
|
||||
* @brief This file contains all the functions prototypes for the netconf.c
|
||||
* file.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
|
||||
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
|
||||
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
|
||||
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
|
||||
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __NETCONF_H
|
||||
#define __NETCONF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "tcpip.h"
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <platform/platform_stdlib.h>
|
||||
#include "platform_opts.h"
|
||||
#include "autoconf.h"
|
||||
|
||||
// macros
|
||||
/* Give default value if not defined */
|
||||
#ifndef NET_IF_NUM
|
||||
#ifdef CONFIG_CONCURRENT_MODE
|
||||
#define NET_IF_NUM ((CONFIG_ETHERNET) + (CONFIG_WLAN) + 1)
|
||||
#else
|
||||
#define NET_IF_NUM ((CONFIG_ETHERNET) + (CONFIG_WLAN))
|
||||
#endif // end of CONFIG_CONCURRENT_MODE
|
||||
#endif // end of NET_IF_NUM
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
typedef enum
|
||||
{
|
||||
DHCP_START=0,
|
||||
DHCP_WAIT_ADDRESS,
|
||||
DHCP_ADDRESS_ASSIGNED,
|
||||
DHCP_RELEASE_IP,
|
||||
DHCP_STOP,
|
||||
DHCP_TIMEOUT
|
||||
} DHCP_State_TypeDef;
|
||||
|
||||
/* Extern functions ------------------------------------------------------------*/
|
||||
void wifi_rx_beacon_hdl( char* buf, int buf_len, int flags, void* userdata);
|
||||
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
void LwIP_Init(void);
|
||||
uint8_t LwIP_DHCP(uint8_t idx, uint8_t dhcp_state);
|
||||
unsigned char* LwIP_GetMAC(struct netif *pnetif);
|
||||
unsigned char* LwIP_GetIP(struct netif *pnetif);
|
||||
unsigned char* LwIP_GetGW(struct netif *pnetif);
|
||||
uint8_t* LwIP_GetMASK(struct netif *pnetif);
|
||||
uint8_t* LwIP_GetBC(struct netif *pnetif);
|
||||
#if LWIP_DNS
|
||||
void LwIP_GetDNS(struct ip_addr* dns);
|
||||
void LwIP_SetDNS(struct ip_addr* dns);
|
||||
#endif
|
||||
void LwIP_UseStaticIP(struct netif *pnetif);
|
||||
#if LWIP_AUTOIP
|
||||
void LwIP_AUTOIP(struct netif *pnetif);
|
||||
#endif
|
||||
#if LWIP_IPV6
|
||||
void LwIP_AUTOIP_IPv6(struct netif *pnetif);
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __NETCONF_H */
|
||||
|
||||
|
||||
/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
|
304
component/common/api/network/include/lwipopts.h
Normal file
304
component/common/api/network/include/lwipopts.h
Normal file
|
@ -0,0 +1,304 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* @file lwipopts.h
|
||||
* @author MCD Application Team
|
||||
* @version V1.1.0
|
||||
* @date 07-October-2011
|
||||
* @brief lwIP Options Configuration.
|
||||
* This file is based on Utilities\lwip_v1.3.2\src\include\lwip\opt.h
|
||||
* and contains the lwIP configuration for the STM32F2x7 demonstration.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
|
||||
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
|
||||
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
|
||||
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
|
||||
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __LWIPOPTS_H__
|
||||
#define __LWIPOPTS_H__
|
||||
|
||||
#include <platform/platform_stdlib.h>
|
||||
#include "platform_opts.h"
|
||||
#define WIFI_LOGO_CERTIFICATION_CONFIG 0 //for ping 10k test buffer setting
|
||||
|
||||
/**
|
||||
* SYS_LIGHTWEIGHT_PROT==1: if you want inter-task protection for certain
|
||||
* critical regions during buffer allocation, deallocation and memory
|
||||
* allocation and deallocation.
|
||||
*/
|
||||
#define SYS_LIGHTWEIGHT_PROT 1
|
||||
|
||||
/* Define LWIP_COMPAT_MUTEX if the port has no mutexes and binary semaphores
|
||||
should be used instead */
|
||||
#define LWIP_COMPAT_MUTEX 1
|
||||
|
||||
#define ETHARP_TRUST_IP_MAC 0
|
||||
#define IP_REASSEMBLY 1
|
||||
#define IP_FRAG 1
|
||||
#define ARP_QUEUEING 0
|
||||
|
||||
/**
|
||||
* NO_SYS==1: Provides VERY minimal functionality. Otherwise,
|
||||
* use lwIP facilities.
|
||||
*/
|
||||
#define NO_SYS 0
|
||||
|
||||
/* ---------- Memory options ---------- */
|
||||
/* MEM_ALIGNMENT: should be set to the alignment of the CPU for which
|
||||
lwIP is compiled. 4 byte alignment -> define MEM_ALIGNMENT to 4, 2
|
||||
byte alignment -> define MEM_ALIGNMENT to 2. */
|
||||
#define MEM_ALIGNMENT 4
|
||||
|
||||
/* MEM_SIZE: the size of the heap memory. If the application will send
|
||||
a lot of data that needs to be copied, this should be set high. */
|
||||
#if WIFI_LOGO_CERTIFICATION_CONFIG
|
||||
#define MEM_SIZE (10*1024) //for ping 10k test
|
||||
#else
|
||||
#define MEM_SIZE (5*1024)
|
||||
#endif
|
||||
|
||||
/* MEMP_NUM_PBUF: the number of memp struct pbufs. If the application
|
||||
sends a lot of data out of ROM (or other static memory), this
|
||||
should be set high. */
|
||||
#define MEMP_NUM_PBUF 100
|
||||
/* MEMP_NUM_UDP_PCB: the number of UDP protocol control blocks. One
|
||||
per active UDP "connection". */
|
||||
#define MEMP_NUM_UDP_PCB 6
|
||||
/* MEMP_NUM_TCP_PCB: the number of simulatenously active TCP
|
||||
connections. */
|
||||
#define MEMP_NUM_TCP_PCB 10
|
||||
/* MEMP_NUM_TCP_PCB_LISTEN: the number of listening TCP
|
||||
connections. */
|
||||
#define MEMP_NUM_TCP_PCB_LISTEN 5
|
||||
/* MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP
|
||||
segments. */
|
||||
#define MEMP_NUM_TCP_SEG 20
|
||||
/* MEMP_NUM_SYS_TIMEOUT: the number of simulateously active
|
||||
timeouts. */
|
||||
#define MEMP_NUM_SYS_TIMEOUT 10
|
||||
|
||||
|
||||
/* ---------- Pbuf options ---------- */
|
||||
/* PBUF_POOL_SIZE: the number of buffers in the pbuf pool. */
|
||||
#if WIFI_LOGO_CERTIFICATION_CONFIG
|
||||
#define PBUF_POOL_SIZE 30 //for ping 10k test
|
||||
#else
|
||||
#define PBUF_POOL_SIZE 20
|
||||
#endif
|
||||
|
||||
/* IP_REASS_MAX_PBUFS: Total maximum amount of pbufs waiting to be reassembled.*/
|
||||
#if WIFI_LOGO_CERTIFICATION_CONFIG
|
||||
#define IP_REASS_MAX_PBUFS 30 //for ping 10k test
|
||||
#else
|
||||
#define IP_REASS_MAX_PBUFS 10
|
||||
#endif
|
||||
|
||||
/* PBUF_POOL_BUFSIZE: the size of each pbuf in the pbuf pool. */
|
||||
#define PBUF_POOL_BUFSIZE 500
|
||||
|
||||
|
||||
/* ---------- TCP options ---------- */
|
||||
#define LWIP_TCP 1
|
||||
#define TCP_TTL 255
|
||||
|
||||
/* Controls if TCP should queue segments that arrive out of
|
||||
order. Define to 0 if your device is low on memory. */
|
||||
#define TCP_QUEUE_OOSEQ 1
|
||||
|
||||
/* TCP Maximum segment size. */
|
||||
#define TCP_MSS (1500 - 40) /* TCP_MSS = (Ethernet MTU - IP header size - TCP header size) */
|
||||
|
||||
/* TCP sender buffer space (bytes). */
|
||||
#define TCP_SND_BUF (5*TCP_MSS)
|
||||
|
||||
/* TCP_SND_QUEUELEN: TCP sender buffer space (pbufs). This must be at least
|
||||
as much as (2 * TCP_SND_BUF/TCP_MSS) for things to work. */
|
||||
|
||||
#define TCP_SND_QUEUELEN (4* TCP_SND_BUF/TCP_MSS)
|
||||
|
||||
/* TCP receive window. */
|
||||
#define TCP_WND (2*TCP_MSS)
|
||||
|
||||
|
||||
/* ---------- ICMP options ---------- */
|
||||
#define LWIP_ICMP 1
|
||||
|
||||
/* ---------- ARP options ----------- */
|
||||
#define LWIP_ARP 1
|
||||
|
||||
/* ---------- DHCP options ---------- */
|
||||
/* Define LWIP_DHCP to 1 if you want DHCP configuration of
|
||||
interfaces. DHCP is not implemented in lwIP 0.5.1, however, so
|
||||
turning this on does currently not work. */
|
||||
#define LWIP_DHCP 1
|
||||
|
||||
|
||||
/* ---------- UDP options ---------- */
|
||||
#define LWIP_UDP 1
|
||||
#define UDP_TTL 255
|
||||
/* ---------- DNS options ---------- */
|
||||
#define LWIP_DNS 1
|
||||
|
||||
/* ---------- UPNP options --------- */
|
||||
#define LWIP_UPNP 0
|
||||
|
||||
/* Support Multicast */
|
||||
#define LWIP_IGMP 1
|
||||
#define LWIP_RAND() rand()
|
||||
|
||||
/* Support TCP Keepalive */
|
||||
#define LWIP_TCP_KEEPALIVE 1
|
||||
|
||||
/*LWIP_UART_ADAPTER==1: Enable LWIP_UART_ADAPTER when CONFIG_GAGENT is enabled,
|
||||
because some GAGENT functions denpond on the following macro definitions.*/
|
||||
#define LWIP_UART_ADAPTER 0
|
||||
|
||||
#if LWIP_UART_ADAPTER
|
||||
#undef LWIP_SO_SNDTIMEO
|
||||
#define LWIP_SO_SNDTIMEO 1
|
||||
|
||||
#undef SO_REUSE
|
||||
#define SO_REUSE 1
|
||||
|
||||
#undef MEMP_NUM_NETCONN
|
||||
#define MEMP_NUM_NETCONN 10
|
||||
|
||||
#undef TCP_WND
|
||||
#define TCP_WND (4*TCP_MSS)
|
||||
|
||||
#define TCP_KEEPIDLE_DEFAULT 10000UL
|
||||
#define TCP_KEEPINTVL_DEFAULT 1000UL
|
||||
#define TCP_KEEPCNT_DEFAULT 10U
|
||||
#endif
|
||||
|
||||
#if CONFIG_EXAMPLE_UART_ATCMD
|
||||
#undef LWIP_SO_SNDTIMEO
|
||||
#define LWIP_SO_SNDTIMEO 1
|
||||
|
||||
#undef SO_REUSE
|
||||
#define SO_REUSE 1
|
||||
|
||||
#undef MEMP_NUM_NETCONN
|
||||
#define MEMP_NUM_NETCONN 10
|
||||
|
||||
#undef MEMP_NUM_TCP_PCB
|
||||
#define MEMP_NUM_TCP_PCB (MEMP_NUM_NETCONN)
|
||||
|
||||
#undef MEMP_NUM_UDP_PCB
|
||||
#define MEMP_NUM_UDP_PCB (MEMP_NUM_NETCONN)
|
||||
|
||||
#undef TCP_WND
|
||||
#define TCP_WND (4*TCP_MSS)
|
||||
|
||||
#define TCP_KEEPIDLE_DEFAULT 10000UL
|
||||
#define TCP_KEEPINTVL_DEFAULT 1000UL
|
||||
#define TCP_KEEPCNT_DEFAULT 10U
|
||||
|
||||
#define ERRNO 1
|
||||
#endif
|
||||
|
||||
/* ---------- Statistics options ---------- */
|
||||
#define LWIP_STATS 0
|
||||
#define LWIP_PROVIDE_ERRNO 1
|
||||
|
||||
|
||||
/*
|
||||
--------------------------------------
|
||||
---------- Checksum options ----------
|
||||
--------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
The STM32F2x7 allows computing and verifying the IP, UDP, TCP and ICMP checksums by hardware:
|
||||
- To use this feature let the following define uncommented.
|
||||
- To disable it and process by CPU comment the the checksum.
|
||||
*/
|
||||
//Do checksum by lwip - WLAN nic does not support Checksum offload
|
||||
//#define CHECKSUM_BY_HARDWARE
|
||||
|
||||
|
||||
#ifdef CHECKSUM_BY_HARDWARE
|
||||
/* CHECKSUM_GEN_IP==0: Generate checksums by hardware for outgoing IP packets.*/
|
||||
#define CHECKSUM_GEN_IP 0
|
||||
/* CHECKSUM_GEN_UDP==0: Generate checksums by hardware for outgoing UDP packets.*/
|
||||
#define CHECKSUM_GEN_UDP 0
|
||||
/* CHECKSUM_GEN_TCP==0: Generate checksums by hardware for outgoing TCP packets.*/
|
||||
#define CHECKSUM_GEN_TCP 0
|
||||
/* CHECKSUM_CHECK_IP==0: Check checksums by hardware for incoming IP packets.*/
|
||||
#define CHECKSUM_CHECK_IP 0
|
||||
/* CHECKSUM_CHECK_UDP==0: Check checksums by hardware for incoming UDP packets.*/
|
||||
#define CHECKSUM_CHECK_UDP 0
|
||||
/* CHECKSUM_CHECK_TCP==0: Check checksums by hardware for incoming TCP packets.*/
|
||||
#define CHECKSUM_CHECK_TCP 0
|
||||
#else
|
||||
/* CHECKSUM_GEN_IP==1: Generate checksums in software for outgoing IP packets.*/
|
||||
#define CHECKSUM_GEN_IP 1
|
||||
/* CHECKSUM_GEN_UDP==1: Generate checksums in software for outgoing UDP packets.*/
|
||||
#define CHECKSUM_GEN_UDP 1
|
||||
/* CHECKSUM_GEN_TCP==1: Generate checksums in software for outgoing TCP packets.*/
|
||||
#define CHECKSUM_GEN_TCP 1
|
||||
/* CHECKSUM_CHECK_IP==1: Check checksums in software for incoming IP packets.*/
|
||||
#define CHECKSUM_CHECK_IP 1
|
||||
/* CHECKSUM_CHECK_UDP==1: Check checksums in software for incoming UDP packets.*/
|
||||
#define CHECKSUM_CHECK_UDP 1
|
||||
/* CHECKSUM_CHECK_TCP==1: Check checksums in software for incoming TCP packets.*/
|
||||
#define CHECKSUM_CHECK_TCP 1
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
----------------------------------------------
|
||||
---------- Sequential layer options ----------
|
||||
----------------------------------------------
|
||||
*/
|
||||
/**
|
||||
* LWIP_NETCONN==1: Enable Netconn API (require to use api_lib.c)
|
||||
*/
|
||||
#define LWIP_NETCONN 1
|
||||
|
||||
/*
|
||||
------------------------------------
|
||||
---------- Socket options ----------
|
||||
------------------------------------
|
||||
*/
|
||||
/**
|
||||
* LWIP_SOCKET==1: Enable Socket API (require to use sockets.c)
|
||||
*/
|
||||
#define LWIP_SOCKET 1
|
||||
|
||||
/*
|
||||
-----------------------------------
|
||||
---------- DEBUG options ----------
|
||||
-----------------------------------
|
||||
*/
|
||||
|
||||
#define LWIP_DEBUG 0
|
||||
|
||||
|
||||
/*
|
||||
---------------------------------
|
||||
---------- OS options ----------
|
||||
---------------------------------
|
||||
*/
|
||||
|
||||
#define TCPIP_THREAD_STACKSIZE 1000
|
||||
#define TCPIP_MBOX_SIZE 6
|
||||
#define DEFAULT_UDP_RECVMBOX_SIZE 6
|
||||
#define DEFAULT_TCP_RECVMBOX_SIZE 6
|
||||
#define DEFAULT_RAW_RECVMBOX_SIZE 6
|
||||
#define DEFAULT_ACCEPTMBOX_SIZE 6
|
||||
#define DEFAULT_THREAD_STACKSIZE 500
|
||||
#define TCPIP_THREAD_PRIO (configMAX_PRIORITIES - 2)
|
||||
|
||||
|
||||
|
||||
#endif /* __LWIPOPTS_H__ */
|
||||
|
||||
/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
|
68
component/common/api/network/include/main.h
Normal file
68
component/common/api/network/include/main.h
Normal file
|
@ -0,0 +1,68 @@
|
|||
#ifndef MAIN_H
|
||||
#define MAIN_H
|
||||
|
||||
#include <autoconf.h>
|
||||
|
||||
#define CONFIG_WLAN 1
|
||||
|
||||
|
||||
/* Header file declaration*/
|
||||
void wlan_network();
|
||||
|
||||
|
||||
/* Interactive Mode */
|
||||
#define SERIAL_DEBUG_RX 1
|
||||
#if defined(__ICCARM__)
|
||||
static
|
||||
#endif
|
||||
char uart_buf[64];
|
||||
|
||||
|
||||
/* WLAN and Netork */
|
||||
#define STA_MODE_SSID "ap" /* Set SSID here */
|
||||
#define AP_MODE_SSID "wlan_ap_ssid" /* Set SSID here */
|
||||
#define AP_DEFAULT_CH 6
|
||||
#define WLAN0_NAME "wlan0"
|
||||
#define WLAN1_NAME "wlan1"
|
||||
#define WPA_PASSPHRASE "1234567890" /* Max 32 cahracters */
|
||||
#define WEP40_KEY {0x12, 0x34, 0x56, 0x78, 0x90}
|
||||
|
||||
/*Static IP ADDRESS*/
|
||||
#define IP_ADDR0 192
|
||||
#define IP_ADDR1 168
|
||||
#define IP_ADDR2 1
|
||||
#define IP_ADDR3 80
|
||||
|
||||
/*NETMASK*/
|
||||
#define NETMASK_ADDR0 255
|
||||
#define NETMASK_ADDR1 255
|
||||
#define NETMASK_ADDR2 255
|
||||
#define NETMASK_ADDR3 0
|
||||
|
||||
/*Gateway Address*/
|
||||
#define GW_ADDR0 192
|
||||
#define GW_ADDR1 168
|
||||
#define GW_ADDR2 1
|
||||
#define GW_ADDR3 1
|
||||
|
||||
/*******************************************/
|
||||
|
||||
/*Static IP ADDRESS*/
|
||||
#define AP_IP_ADDR0 192
|
||||
#define AP_IP_ADDR1 168
|
||||
#define AP_IP_ADDR2 43
|
||||
#define AP_IP_ADDR3 1
|
||||
|
||||
/*NETMASK*/
|
||||
#define AP_NETMASK_ADDR0 255
|
||||
#define AP_NETMASK_ADDR1 255
|
||||
#define AP_NETMASK_ADDR2 255
|
||||
#define AP_NETMASK_ADDR3 0
|
||||
|
||||
/*Gateway Address*/
|
||||
#define AP_GW_ADDR0 192
|
||||
#define AP_GW_ADDR1 168
|
||||
#define AP_GW_ADDR2 43
|
||||
#define AP_GW_ADDR3 1
|
||||
|
||||
#endif
|
21
component/common/api/network/include/main_test.h
Normal file
21
component/common/api/network/include/main_test.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
//----------------------------------------------------------------------------//
|
||||
#ifndef __MAIN_TEST_H
|
||||
#define __MAIN_TEST_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported test functions ------------------------------------------------------- */
|
||||
void do_ping_test(char *ip, int size, int count, int interval);
|
||||
void do_ping_call(char *ip, int loop, int count);
|
||||
void interactive_question(char *question, char *choice, char *buf, int buf_size);
|
||||
void start_interactive_mode(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __MAIN_TEST_H
|
||||
|
||||
//----------------------------------------------------------------------------//
|
50
component/common/api/network/include/netconf.h
Normal file
50
component/common/api/network/include/netconf.h
Normal file
|
@ -0,0 +1,50 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* @file netconf.h
|
||||
* @author MCD Application Team
|
||||
* @version V1.1.0
|
||||
* @date 07-October-2011
|
||||
* @brief This file contains all the functions prototypes for the netconf.c
|
||||
* file.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
|
||||
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
|
||||
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
|
||||
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
|
||||
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __NETCONF_H
|
||||
#define __NETCONF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// TODO: remove this file
|
||||
#include "lwip_netconf.h"
|
||||
#if 0
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
void LwIP_Init(void);
|
||||
void LwIP_DHCP(void);
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __NETCONF_H */
|
||||
|
||||
|
||||
/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
|
8
component/common/api/network/include/rtl8195a_it.h
Normal file
8
component/common/api/network/include/rtl8195a_it.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
|
||||
#ifndef __RTL8195A_IT_H_
|
||||
#define __RTL8195A_IT_H_
|
||||
|
||||
|
||||
int irq_alloc_wlan(void *contex);
|
||||
|
||||
#endif //__RTL8195A_IT_H_
|
46
component/common/api/network/include/util.h
Normal file
46
component/common/api/network/include/util.h
Normal file
|
@ -0,0 +1,46 @@
|
|||
#ifndef _UTIL_H
|
||||
#define _UTIL_H
|
||||
|
||||
#include <wireless.h>
|
||||
#include <wlan_intf.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "wifi_util.h"
|
||||
#if 0
|
||||
typedef enum _WIFI_EVENT_INDICATE{
|
||||
WIFI_EVENT_CONNECT = 0,
|
||||
WIFI_EVENT_DISCONNECT = 1,
|
||||
WIFI_EVENT_FOURWAY_HANDSHAKE_DONE = 2,
|
||||
}WIFI_EVENT_INDICATE;
|
||||
|
||||
int wext_get_ssid(const char *ifname, __u8 *ssid);
|
||||
int wext_set_ssid(const char *ifname, const __u8 *ssid, __u16 ssid_len);
|
||||
int wext_set_auth_param(const char *ifname, __u16 idx, __u32 value);
|
||||
int wext_set_key_ext(const char *ifname, __u16 alg, const __u8 *addr, int key_idx, int set_tx, const __u8 *seq, __u16 seq_len, __u8 *key, __u16 key_len);
|
||||
int wext_get_enc_ext(const char *ifname, __u16 *alg);
|
||||
int wext_set_passphrase(const char *ifname, const __u8 *passphrase, __u16 passphrase_len);
|
||||
int wext_get_passphrase(const char *ifname, __u8 *passphrase);
|
||||
int wext_set_mode(const char *ifname, int mode);
|
||||
int wext_get_mode(const char *ifname, int *mode);
|
||||
int wext_set_ap_ssid(const char *ifname, const __u8 *ssid, __u16 ssid_len);
|
||||
int wext_set_country(const char *ifname, char *country_code);
|
||||
int wext_get_rssi(const char *ifname, int *rssi);
|
||||
int wext_set_channel(const char *ifname, __u8 ch);
|
||||
int wext_get_channel(const char *ifname, __u8 *ch);
|
||||
int wext_set_scan(const char *ifname, char *buf, __u16 buf_len);
|
||||
int wext_get_scan(const char *ifname, char *buf, __u16 buf_len);
|
||||
int wext_mp_command(const char *ifname, char *cmd, int show_msg);
|
||||
int wext_wifi_priv(const char *ifname, int argc, char **argv);
|
||||
void wext_wlan_indicate(unsigned int cmd, union iwreq_data *wrqu, char *extra);
|
||||
#endif
|
||||
|
||||
#define wext_handshake_done rltk_wlan_handshake_done
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _UTIL_H */
|
220
component/common/api/network/src/ping_test.c
Normal file
220
component/common/api/network/src/ping_test.c
Normal file
|
@ -0,0 +1,220 @@
|
|||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "main.h"
|
||||
|
||||
#include <lwip/sockets.h>
|
||||
#include <lwip/raw.h>
|
||||
#include <lwip/icmp.h>
|
||||
#include <lwip/inet_chksum.h>
|
||||
#include <platform/platform_stdlib.h>
|
||||
|
||||
//#define PING_IP "192.168.0.1"
|
||||
#define PING_IP "192.168.159.1"
|
||||
#define PING_TO 1000
|
||||
#define PING_ID 0xABCD
|
||||
#define BUF_SIZE 10000
|
||||
#define STACKSIZE 1024
|
||||
|
||||
static unsigned short ping_seq = 0;
|
||||
static int infinite_loop, ping_count, data_size, ping_interval, ping_call;
|
||||
static char ping_ip[16];
|
||||
|
||||
static void generate_ping_echo(unsigned char *buf, int size)
|
||||
{
|
||||
int i;
|
||||
struct icmp_echo_hdr *pecho;
|
||||
|
||||
for(i = 0; i < size; i ++) {
|
||||
buf[sizeof(struct icmp_echo_hdr) + i] = (unsigned char) i;
|
||||
}
|
||||
|
||||
pecho = (struct icmp_echo_hdr *) buf;
|
||||
ICMPH_TYPE_SET(pecho, ICMP_ECHO);
|
||||
ICMPH_CODE_SET(pecho, 0);
|
||||
pecho->chksum = 0;
|
||||
pecho->id = PING_ID;
|
||||
pecho->seqno = htons(++ ping_seq);
|
||||
|
||||
//Checksum includes icmp header and data. Need to calculate after fill up icmp header
|
||||
pecho->chksum = inet_chksum(pecho, sizeof(struct icmp_echo_hdr) + size);
|
||||
}
|
||||
|
||||
void ping_test(void *param)
|
||||
//void ping_test()
|
||||
{
|
||||
int i, ping_socket;
|
||||
int pint_timeout = PING_TO;
|
||||
struct sockaddr_in to_addr, from_addr;
|
||||
int from_addr_len = sizeof(struct sockaddr);
|
||||
int ping_size, reply_size;
|
||||
unsigned char *ping_buf, *reply_buf;
|
||||
unsigned int ping_time, reply_time;
|
||||
struct ip_hdr *iphdr;
|
||||
struct icmp_echo_hdr *pecho;
|
||||
|
||||
if(data_size > BUF_SIZE){
|
||||
printf("\n\r[ERROR] %s: data size error, can't exceed %d",__func__,BUF_SIZE);
|
||||
return;
|
||||
}
|
||||
|
||||
//Ping size = icmp header(8 bytes) + data size
|
||||
ping_size = sizeof(struct icmp_echo_hdr) + data_size;
|
||||
|
||||
ping_buf = pvPortMalloc(ping_size);
|
||||
if(NULL == ping_buf){
|
||||
printf("\n\r[ERROR] %s: Allocate ping_buf failed",__func__);
|
||||
return;
|
||||
}
|
||||
|
||||
reply_buf = pvPortMalloc(ping_size);
|
||||
if(NULL == reply_buf){
|
||||
vPortFree(ping_buf);
|
||||
printf("\n\r[ERROR] %s: Allocate reply_buf failed",__func__);
|
||||
return;
|
||||
}
|
||||
|
||||
printf("\n\r[%s] PING %s %d(%d) bytes of data\n", __FUNCTION__, ping_ip, data_size, sizeof(struct ip_hdr) + sizeof(struct icmp_echo_hdr) + data_size);
|
||||
|
||||
for(i = 0; (i < ping_count) || (infinite_loop == 1); i ++) {
|
||||
ping_socket = socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP);
|
||||
#ifdef CONFIG_LWIP_1_5_0
|
||||
struct timeval timeout;
|
||||
timeout.tv_sec = pint_timeout / 1000;
|
||||
timeout.tv_usec = pint_timeout % 1000 * 1000;
|
||||
setsockopt(ping_socket, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
|
||||
#else
|
||||
setsockopt(ping_socket, SOL_SOCKET, SO_RCVTIMEO, &pint_timeout, sizeof(pint_timeout));
|
||||
#endif
|
||||
to_addr.sin_len = sizeof(to_addr);
|
||||
to_addr.sin_family = AF_INET;
|
||||
to_addr.sin_addr.s_addr = inet_addr(ping_ip);
|
||||
|
||||
generate_ping_echo(ping_buf, data_size);
|
||||
sendto(ping_socket, ping_buf, ping_size, 0, (struct sockaddr *) &to_addr, sizeof(to_addr));
|
||||
|
||||
ping_time = xTaskGetTickCount();
|
||||
if((reply_size = recvfrom(ping_socket, reply_buf, ping_size, 0, (struct sockaddr *) &from_addr, (socklen_t *) &from_addr_len))
|
||||
>= (int)(sizeof(struct ip_hdr) + sizeof(struct icmp_echo_hdr))) {
|
||||
|
||||
reply_time = xTaskGetTickCount();
|
||||
iphdr = (struct ip_hdr *)reply_buf;
|
||||
pecho = (struct icmp_echo_hdr *)(reply_buf + (IPH_HL(iphdr) * 4));
|
||||
|
||||
if((pecho->id == PING_ID) && (pecho->seqno == htons(ping_seq))) {
|
||||
printf("\n\r[%s] %d bytes from %s: icmp_seq=%d time=%d ms", __FUNCTION__, reply_size - sizeof(struct ip_hdr), inet_ntoa(from_addr.sin_addr), htons(pecho->seqno), (reply_time - ping_time) * portTICK_RATE_MS);
|
||||
}
|
||||
}
|
||||
else
|
||||
printf("\n\r[%s] Request timeout for icmp_seq %d\n", __FUNCTION__, ping_seq);
|
||||
|
||||
close(ping_socket);
|
||||
vTaskDelay(ping_interval * configTICK_RATE_HZ);
|
||||
}
|
||||
|
||||
vPortFree(ping_buf);
|
||||
vPortFree(reply_buf);
|
||||
|
||||
if(!ping_call)
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void do_ping_call(char *ip, int loop, int count)
|
||||
{
|
||||
ping_call = 1;
|
||||
ping_seq = 0;
|
||||
data_size = 120;
|
||||
ping_interval = 1;
|
||||
infinite_loop = loop;
|
||||
ping_count = count;
|
||||
strcpy(ping_ip, ip);
|
||||
ping_test(NULL);
|
||||
}
|
||||
|
||||
void cmd_ping(int argc, char **argv)
|
||||
{
|
||||
int argv_count = 2;
|
||||
|
||||
if(argc < 2)
|
||||
goto Exit;
|
||||
|
||||
//ping cmd default value
|
||||
infinite_loop = 0;
|
||||
ping_count = 4;
|
||||
data_size = 32;
|
||||
ping_interval = 1;
|
||||
ping_call = 1;
|
||||
ping_seq = 0;
|
||||
|
||||
while(argv_count<=argc){
|
||||
//first operation
|
||||
if(argv_count == 2){
|
||||
memset(ping_ip, 0, sizeof(ping_ip));
|
||||
strncpy(ping_ip, argv[argv_count-1], (strlen(argv[argv_count-1])>16)?16:strlen(argv[argv_count-1]));
|
||||
argv_count++;
|
||||
}
|
||||
else{
|
||||
if(strcmp(argv[argv_count-1], "-t") == 0){
|
||||
infinite_loop = 1;
|
||||
argv_count++;
|
||||
}
|
||||
else if(strcmp(argv[argv_count-1], "-n") == 0){
|
||||
if(argc < (argv_count+1))
|
||||
goto Exit;
|
||||
ping_count = (int) atoi(argv[argv_count]);
|
||||
argv_count+=2;
|
||||
}
|
||||
else if(strcmp(argv[argv_count-1], "-l") == 0){
|
||||
if(argc < (argv_count+1))
|
||||
goto Exit;
|
||||
data_size = (int) atoi(argv[argv_count]);
|
||||
argv_count+=2;
|
||||
}
|
||||
else{
|
||||
goto Exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ping_test(NULL);
|
||||
|
||||
return;
|
||||
|
||||
Exit:
|
||||
printf("\n\r[ATWI] Usage: ATWI=[host],[options]\n");
|
||||
printf("\n\r -t Ping the specified host until stopped\n");
|
||||
printf(" \r -n # Number of echo requests to send (default 4 times)\n");
|
||||
printf(" \r -l # Send buffer size (default 32 bytes)\n");
|
||||
printf("\n\r Example:\n");
|
||||
printf(" \r ATWI=192.168.1.2,-n,100,-l,5000\n");
|
||||
return;
|
||||
}
|
||||
|
||||
void do_ping_test(char *ip, int size, int count, int interval)
|
||||
{
|
||||
if((sizeof(struct icmp_echo_hdr) + size) > BUF_SIZE) {
|
||||
printf("\n\r%s BUF_SIZE(%d) is too small", __FUNCTION__, BUF_SIZE);
|
||||
return;
|
||||
}
|
||||
|
||||
if(ip == NULL)
|
||||
strcpy(ping_ip, PING_IP);
|
||||
else
|
||||
strcpy(ping_ip, ip);
|
||||
|
||||
ping_call = 0;
|
||||
ping_seq = 0;
|
||||
data_size = size;
|
||||
ping_interval = interval;
|
||||
|
||||
if(count == 0) {
|
||||
infinite_loop = 1;
|
||||
ping_count = 0;
|
||||
}
|
||||
else {
|
||||
infinite_loop = 0;
|
||||
ping_count = count;
|
||||
}
|
||||
|
||||
if(xTaskCreate(ping_test, ((const signed char*)"ping_test"), STACKSIZE, NULL, tskIDLE_PRIORITY + 1, NULL) != pdPASS)
|
||||
printf("\n\r%s xTaskCreate failed", __FUNCTION__);
|
||||
}
|
71
component/common/api/network/src/wlan_network.c
Normal file
71
component/common/api/network/src/wlan_network.c
Normal file
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Hello World
|
||||
*
|
||||
* Copyright (c) 2013 Realtek Semiconductor Corp.
|
||||
*
|
||||
* This module is a confidential and proprietary property of RealTek and
|
||||
* possession or use of this module requires written permission of RealTek.
|
||||
*/
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "semphr.h"
|
||||
|
||||
#include "main.h"
|
||||
#include "main_test.h"
|
||||
#if CONFIG_WLAN
|
||||
#include "wifi_conf.h"
|
||||
#include "wlan_intf.h"
|
||||
#include "wifi_constants.h"
|
||||
#endif
|
||||
#include "lwip_netconf.h"
|
||||
#include <platform/platform_stdlib.h>
|
||||
|
||||
#ifndef CONFIG_INIT_NET
|
||||
#define CONFIG_INIT_NET 1
|
||||
#endif
|
||||
#ifndef CONFIG_INTERACTIVE_MODE
|
||||
#define CONFIG_INTERACTIVE_MODE 1
|
||||
#endif
|
||||
|
||||
#define STACKSIZE (512 + 768)
|
||||
|
||||
xSemaphoreHandle uart_rx_interrupt_sema = NULL;
|
||||
|
||||
void init_thread(void *param)
|
||||
{
|
||||
|
||||
#if CONFIG_INIT_NET
|
||||
#if CONFIG_LWIP_LAYER
|
||||
/* Initilaize the LwIP stack */
|
||||
LwIP_Init();
|
||||
#endif
|
||||
#endif
|
||||
#if CONFIG_WIFI_IND_USE_THREAD
|
||||
wifi_manager_init();
|
||||
#endif
|
||||
#if CONFIG_WLAN
|
||||
wifi_on(RTW_MODE_STA);
|
||||
#if CONFIG_AUTO_RECONNECT
|
||||
//setup reconnection flag
|
||||
wifi_set_autoreconnect(1);
|
||||
#endif
|
||||
printf("\n\r%s(%d), Available heap 0x%x", __FUNCTION__, __LINE__, xPortGetFreeHeapSize());
|
||||
#endif
|
||||
|
||||
#if CONFIG_INTERACTIVE_MODE
|
||||
/* Initial uart rx swmaphore*/
|
||||
vSemaphoreCreateBinary(uart_rx_interrupt_sema);
|
||||
xSemaphoreTake(uart_rx_interrupt_sema, 1/portTICK_RATE_MS);
|
||||
start_interactive_mode();
|
||||
#endif
|
||||
|
||||
/* Kill init thread after all init tasks done */
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void wlan_network()
|
||||
{
|
||||
if(xTaskCreate(init_thread, ((const char*)"init"), STACKSIZE, NULL, tskIDLE_PRIORITY + 3 + PRIORITIE_OFFSET, NULL) != pdPASS)
|
||||
printf("\n\r%s xTaskCreate(init_thread) failed", __FUNCTION__);
|
||||
}
|
262
component/common/api/platform/dlist.h
Normal file
262
component/common/api/platform/dlist.h
Normal file
|
@ -0,0 +1,262 @@
|
|||
#ifndef __LIST_H
|
||||
#define __LIST_H
|
||||
|
||||
#if defined ( __CC_ARM )
|
||||
#ifndef inline
|
||||
#define inline __inline
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* This file is from Linux Kernel (include/linux/list.h)
|
||||
* and modified by simply removing hardware prefetching of list items.
|
||||
* Here by copyright, credits attributed to wherever they belong.
|
||||
* Kulesh Shanmugasundaram (kulesh [squiggly] isis.poly.edu)
|
||||
*/
|
||||
|
||||
/*
|
||||
* Simple doubly linked list implementation.
|
||||
*
|
||||
* Some of the internal functions ("__xxx") are useful when
|
||||
* manipulating whole lists rather than single entries, as
|
||||
* sometimes we already know the next/prev entries and we can
|
||||
* generate better code by using them directly rather than
|
||||
* using the generic single-entry routines.
|
||||
*/
|
||||
|
||||
struct list_head {
|
||||
struct list_head *next, *prev;
|
||||
};
|
||||
|
||||
#define LIST_HEAD_INIT(name) { &(name), &(name) }
|
||||
|
||||
#define LIST_HEAD(name) \
|
||||
struct list_head name = LIST_HEAD_INIT(name)
|
||||
|
||||
#define INIT_LIST_HEAD(ptr) do { \
|
||||
(ptr)->next = (ptr); (ptr)->prev = (ptr); \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* Insert a new entry between two known consecutive entries.
|
||||
*
|
||||
* This is only for internal list manipulation where we know
|
||||
* the prev/next entries already!
|
||||
*/
|
||||
static inline void __list_add(struct list_head *new,
|
||||
struct list_head *prev,
|
||||
struct list_head *next)
|
||||
{
|
||||
next->prev = new;
|
||||
new->next = next;
|
||||
new->prev = prev;
|
||||
prev->next = new;
|
||||
}
|
||||
|
||||
/**
|
||||
* list_add - add a new entry
|
||||
* @new: new entry to be added
|
||||
* @head: list head to add it after
|
||||
*
|
||||
* Insert a new entry after the specified head.
|
||||
* This is good for implementing stacks.
|
||||
*/
|
||||
static inline void list_add(struct list_head *new, struct list_head *head)
|
||||
{
|
||||
__list_add(new, head, head->next);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_add_tail - add a new entry
|
||||
* @new: new entry to be added
|
||||
* @head: list head to add it before
|
||||
*
|
||||
* Insert a new entry before the specified head.
|
||||
* This is useful for implementing queues.
|
||||
*/
|
||||
static inline void list_add_tail(struct list_head *new, struct list_head *head)
|
||||
{
|
||||
__list_add(new, head->prev, head);
|
||||
}
|
||||
|
||||
/*
|
||||
* Delete a list entry by making the prev/next entries
|
||||
* point to each other.
|
||||
*
|
||||
* This is only for internal list manipulation where we know
|
||||
* the prev/next entries already!
|
||||
*/
|
||||
static inline void __list_del(struct list_head *prev, struct list_head *next)
|
||||
{
|
||||
next->prev = prev;
|
||||
prev->next = next;
|
||||
}
|
||||
|
||||
/**
|
||||
* list_del - deletes entry from list.
|
||||
* @entry: the element to delete from the list.
|
||||
* Note: list_empty on entry does not return true after this, the entry is in an undefined state.
|
||||
*/
|
||||
static inline void list_del(struct list_head *entry)
|
||||
{
|
||||
__list_del(entry->prev, entry->next);
|
||||
entry->next = (void *) 0;
|
||||
entry->prev = (void *) 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* list_del_init - deletes entry from list and reinitialize it.
|
||||
* @entry: the element to delete from the list.
|
||||
*/
|
||||
static inline void list_del_init(struct list_head *entry)
|
||||
{
|
||||
__list_del(entry->prev, entry->next);
|
||||
INIT_LIST_HEAD(entry);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_move - delete from one list and add as another's head
|
||||
* @list: the entry to move
|
||||
* @head: the head that will precede our entry
|
||||
*/
|
||||
static inline void list_move(struct list_head *list, struct list_head *head)
|
||||
{
|
||||
__list_del(list->prev, list->next);
|
||||
list_add(list, head);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_move_tail - delete from one list and add as another's tail
|
||||
* @list: the entry to move
|
||||
* @head: the head that will follow our entry
|
||||
*/
|
||||
static inline void list_move_tail(struct list_head *list,
|
||||
struct list_head *head)
|
||||
{
|
||||
__list_del(list->prev, list->next);
|
||||
list_add_tail(list, head);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_empty - tests whether a list is empty
|
||||
* @head: the list to test.
|
||||
*/
|
||||
static inline int list_empty(struct list_head *head)
|
||||
{
|
||||
return head->next == head;
|
||||
}
|
||||
|
||||
static inline void __list_splice(struct list_head *list,
|
||||
struct list_head *head)
|
||||
{
|
||||
struct list_head *first = list->next;
|
||||
struct list_head *last = list->prev;
|
||||
struct list_head *at = head->next;
|
||||
|
||||
first->prev = head;
|
||||
head->next = first;
|
||||
|
||||
last->next = at;
|
||||
at->prev = last;
|
||||
}
|
||||
|
||||
/**
|
||||
* list_splice - join two lists
|
||||
* @list: the new list to add.
|
||||
* @head: the place to add it in the first list.
|
||||
*/
|
||||
static inline void list_splice(struct list_head *list, struct list_head *head)
|
||||
{
|
||||
if (!list_empty(list))
|
||||
__list_splice(list, head);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_splice_init - join two lists and reinitialise the emptied list.
|
||||
* @list: the new list to add.
|
||||
* @head: the place to add it in the first list.
|
||||
*
|
||||
* The list at @list is reinitialised
|
||||
*/
|
||||
static inline void list_splice_init(struct list_head *list,
|
||||
struct list_head *head)
|
||||
{
|
||||
if (!list_empty(list)) {
|
||||
__list_splice(list, head);
|
||||
INIT_LIST_HEAD(list);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* list_entry - get the struct for this entry
|
||||
* @ptr: the &struct list_head pointer.
|
||||
* @type: the type of the struct this is embedded in.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define list_entry(ptr, type, member) \
|
||||
((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
|
||||
|
||||
/**
|
||||
* list_first_entry - get the first element from a list
|
||||
* @ptr: the list head to take the element from.
|
||||
* @type: the type of the struct this is embedded in.
|
||||
* @member: the name of the list_head within the struct.
|
||||
*
|
||||
* Note, that list is expected to be not empty.
|
||||
*/
|
||||
|
||||
#define list_first_entry(ptr, type, member) \
|
||||
list_entry((ptr)->next, type, member)
|
||||
|
||||
|
||||
/**
|
||||
* list_for_each - iterate over a list
|
||||
* @pos: the &struct list_head to use as a loop counter.
|
||||
* @head: the head for your list.
|
||||
*/
|
||||
#define list_for_each(pos, head) \
|
||||
for (pos = (head)->next; pos != (head); \
|
||||
pos = pos->next)
|
||||
/**
|
||||
* list_for_each_prev - iterate over a list backwards
|
||||
* @pos: the &struct list_head to use as a loop counter.
|
||||
* @head: the head for your list.
|
||||
*/
|
||||
#define list_for_each_prev(pos, head) \
|
||||
for (pos = (head)->prev; pos != (head); \
|
||||
pos = pos->prev)
|
||||
|
||||
/**
|
||||
* list_for_each_safe - iterate over a list safe against removal of list entry
|
||||
* @pos: the &struct list_head to use as a loop counter.
|
||||
* @n: another &struct list_head to use as temporary storage
|
||||
* @head: the head for your list.
|
||||
*/
|
||||
#define list_for_each_safe(pos, n, head) \
|
||||
for (pos = (head)->next, n = pos->next; pos != (head); \
|
||||
pos = n, n = pos->next)
|
||||
|
||||
/**
|
||||
* list_for_each_entry - iterate over list of given type
|
||||
* @pos: the type * to use as a loop counter.
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define list_for_each_entry(pos, head, member, type) \
|
||||
for (pos = list_entry((head)->next, type, member); \
|
||||
&pos->member != (head); \
|
||||
pos = list_entry(pos->member.next, type, member))
|
||||
|
||||
/**
|
||||
* list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
|
||||
* @pos: the type * to use as a loop counter.
|
||||
* @n: another type * to use as temporary storage
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define list_for_each_entry_safe(pos, n, head, member, type) \
|
||||
for (pos = list_entry((head)->next, type, member), \
|
||||
n = list_entry(pos->member.next, type, member); \
|
||||
&pos->member != (head); \
|
||||
pos = n, n = list_entry(n->member.next, type, member))
|
||||
|
||||
#endif
|
244
component/common/api/platform/platform_stdlib.h
Normal file
244
component/common/api/platform/platform_stdlib.h
Normal file
|
@ -0,0 +1,244 @@
|
|||
/******************************************************************************
|
||||
*
|
||||
* Copyright(c) 2007 - 2014 Realtek Corporation. All rights reserved.
|
||||
*
|
||||
*
|
||||
******************************************************************************/
|
||||
#ifndef __PLATFORM_STDLIB_H__
|
||||
#define __PLATFORM_STDLIB_H__
|
||||
|
||||
#define USE_CLIB_PATCH 0
|
||||
#if defined (__GNUC__)
|
||||
#define USE_RTL_ROM_CLIB 1
|
||||
#else
|
||||
#define USE_RTL_ROM_CLIB 1
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_PLATFORM_8195A)
|
||||
#if defined (__IARSTDLIB__)
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include "diag.h"
|
||||
|
||||
#define strsep(str, delim) _strsep(str, delim)
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "diag.h"
|
||||
#include "strproc.h"
|
||||
#include "basic_types.h"
|
||||
#include "hal_misc.h"
|
||||
#if USE_RTL_ROM_CLIB
|
||||
#include "rtl_lib.h"
|
||||
#endif
|
||||
|
||||
#undef printf
|
||||
#undef sprintf
|
||||
#undef snprintf
|
||||
#undef atoi
|
||||
#undef memcmp
|
||||
#undef memcpy
|
||||
#undef memset
|
||||
#undef strcmp
|
||||
#undef strcpy
|
||||
#undef strlen
|
||||
#undef strncmp
|
||||
#undef strncpy
|
||||
#undef strsep
|
||||
#undef strtok
|
||||
#if USE_RTL_ROM_CLIB
|
||||
#undef memchr
|
||||
#undef memmove
|
||||
#undef strcat
|
||||
#undef strchr
|
||||
#undef strncat
|
||||
#undef strstr
|
||||
#endif
|
||||
|
||||
#if USE_RTL_ROM_CLIB
|
||||
#define printf rtl_printf
|
||||
#define sprintf rtl_sprintf
|
||||
#define snprintf rtl_snprintf
|
||||
#define memchr rtl_memchr
|
||||
#define memcmp rtl_memcmp
|
||||
#define memcpy rtl_memcpy
|
||||
#define memmove rtl_memmove
|
||||
#define memset rtl_memset
|
||||
#define strcat rtl_strcat
|
||||
#define strchr rtl_strchr
|
||||
#define strcmp(s1, s2) rtl_strcmp((const char *)s1, (const char *)s2)
|
||||
#define strcpy rtl_strcpy
|
||||
#define strlen(str) rtl_strlen((const char *)str)
|
||||
#define strncat rtl_strncat
|
||||
#define strncmp(s1, s2, n) rtl_strncmp((const char *)s1, (const char *)s2, n)
|
||||
#define strncpy rtl_strncpy
|
||||
#define strstr rtl_strstr
|
||||
#define strsep rtl_strsep
|
||||
#define strtok rtl_strtok
|
||||
#else
|
||||
#if USE_CLIB_PATCH
|
||||
extern int DiagSscanfPatch(const char *buf, const char *fmt, ...);
|
||||
extern char* DiagStrtokPatch(char *str, const char* delim);
|
||||
extern char* DiagStrstrPatch(char *string, char *substring);
|
||||
extern int DiagSnPrintfPatch(char *buf, size_t size, const char *fmt, ...);
|
||||
extern u32 DiagPrintfPatch(const char *fmt, ...);
|
||||
extern u32 DiagSPrintfPatch(u8 *buf, const char *fmt, ...);
|
||||
#define printf DiagPrintfPatch
|
||||
#define sprintf DiagSPrintfPatch
|
||||
#define snprintf DiagSnPrintfPatch
|
||||
#define strstr(a, b) DiagStrstrPatch((char *)(a), (char *)(b))
|
||||
#define strtok DiagStrtokPatch
|
||||
#else
|
||||
#define printf DiagPrintf
|
||||
#define sprintf(fmt, arg...) DiagSPrintf((u8*)fmt, ##arg)
|
||||
#if defined (__GNUC__)
|
||||
#define snprintf DiagSnPrintf // NULL function
|
||||
#define strstr(str1, str2) prvStrStr(str1, str2) // NULL function
|
||||
#endif
|
||||
#define strtok(str, delim) _strsep(str, delim)
|
||||
#endif
|
||||
#define memcmp(dst, src, sz) _memcmp(dst, src, sz)
|
||||
#define memcpy(dst, src, sz) _memcpy(dst, src, sz)
|
||||
#define memset(dst, val, sz) _memset(dst, val, sz)
|
||||
#define strchr(s, c) _strchr(s, c) // for B-cut ROM
|
||||
#define strcmp(str1, str2) prvStrCmp((const unsigned char *) str1, (const unsigned char *) str2)
|
||||
#define strcpy(dest, src) _strcpy(dest, src)
|
||||
#define strlen(str) prvStrLen((const unsigned char *) str)
|
||||
#define strncmp(str1, str2, cnt) _strncmp(str1, str2, cnt)
|
||||
#define strncpy(dest, src, count) _strncpy(dest, src, count)
|
||||
#define strsep(str, delim) _strsep(str, delim)
|
||||
#endif
|
||||
|
||||
#define atoi(str) prvAtoi(str)
|
||||
#define strpbrk(cs, ct) _strpbrk(cs, ct) // for B-cut ROM
|
||||
|
||||
#if USE_CLIB_PATCH
|
||||
#undef sscanf
|
||||
#define sscanf DiagSscanfPatch
|
||||
#else
|
||||
#if defined (__GNUC__)
|
||||
#undef sscanf //_sscanf
|
||||
//extern int DiagSscanfPatch(const char *buf, const char *fmt, ...);
|
||||
//#define sscanf DiagSscanfPatch
|
||||
#define sscanf sscanf // use libc sscanf
|
||||
#endif
|
||||
#endif
|
||||
#endif // defined (__IARSTDLIB__)
|
||||
|
||||
//
|
||||
// memory management
|
||||
//
|
||||
extern void *pvPortMalloc( size_t xWantedSize );
|
||||
extern void vPortFree( void *pv );
|
||||
#define malloc pvPortMalloc
|
||||
#define free vPortFree
|
||||
#elif defined (CONFIG_PLATFORM_8711B)
|
||||
#if defined (__IARSTDLIB__)
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include "diag.h"
|
||||
|
||||
#define strsep(str, delim) _strsep(str, delim)
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "diag.h"
|
||||
#include "strproc.h"
|
||||
#include "basic_types.h"
|
||||
#include "hal_misc.h"
|
||||
|
||||
#undef printf
|
||||
#undef sprintf
|
||||
#undef snprintf
|
||||
#undef atoi
|
||||
#undef memcmp
|
||||
#undef memcpy
|
||||
#undef memset
|
||||
#undef strcmp
|
||||
#undef strcpy
|
||||
#undef strlen
|
||||
#undef strncmp
|
||||
#undef strncpy
|
||||
#undef strsep
|
||||
#undef strtok
|
||||
|
||||
#if USE_RTL_ROM_CLIB
|
||||
#undef memchr
|
||||
#undef memmove
|
||||
#undef strcat
|
||||
#undef strchr
|
||||
#undef strncat
|
||||
#undef strstr
|
||||
|
||||
#define printf rtl_printf
|
||||
#define sprintf rtl_sprintf
|
||||
#define snprintf rtl_snprintf
|
||||
#define memchr rtl_memchr
|
||||
#define memcmp rtl_memcmp
|
||||
#define memcpy rtl_memcpy
|
||||
#define memmove rtl_memmove
|
||||
#define memset rtl_memset
|
||||
#define strcat rtl_strcat
|
||||
#define strchr rtl_strchr
|
||||
#define strcmp(s1, s2) rtl_strcmp((const char *)s1, (const char *)s2)
|
||||
#define strcpy rtl_strcpy
|
||||
#define strlen(str) rtl_strlen((const char *)str)
|
||||
#define strncat rtl_strncat
|
||||
#define strncmp(s1, s2, n) rtl_strncmp((const char *)s1, (const char *)s2, n)
|
||||
#define strncpy rtl_strncpy
|
||||
#define strstr rtl_strstr
|
||||
#define strsep rtl_strsep
|
||||
#define strtok rtl_strtok
|
||||
#else
|
||||
#define printf DiagPrintf
|
||||
#define sprintf(fmt, arg...) DiagSPrintf((u8*)fmt, ##arg)
|
||||
#if defined (__GNUC__)
|
||||
#define snprintf DiagSnPrintf // NULL function
|
||||
#define strstr(str1, str2) prvStrStr(str1, str2) // NULL function
|
||||
#endif
|
||||
#define strtok(str, delim) _strsep(str, delim)
|
||||
|
||||
#define memcmp(dst, src, sz) _memcmp(dst, src, sz)
|
||||
#define memcpy(dst, src, sz) _memcpy(dst, src, sz)
|
||||
#define memset(dst, val, sz) _memset(dst, val, sz)
|
||||
#define strchr(s, c) _strchr(s, c) // for B-cut ROM
|
||||
#define strcmp(str1, str2) prvStrCmp((const unsigned char *) str1, (const unsigned char *) str2)
|
||||
#define strcpy(dest, src) _strcpy(dest, src)
|
||||
#define strlen(str) prvStrLen((const unsigned char *) str)
|
||||
#define strncmp(str1, str2, cnt) _strncmp(str1, str2, cnt)
|
||||
#define strncpy(dest, src, count) _strncpy(dest, src, count)
|
||||
#define strsep(str, delim) _strsep(str, delim)
|
||||
|
||||
#define atoi(str) prvAtoi(str)
|
||||
#define strpbrk(cs, ct) _strpbrk(cs, ct) // for B-cut ROM
|
||||
|
||||
#if defined (__GNUC__)
|
||||
#undef sscanf
|
||||
#define sscanf _sscanf
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif // defined (__IARSTDLIB__)
|
||||
|
||||
//
|
||||
// memory management
|
||||
//
|
||||
extern void *pvPortMalloc( size_t xWantedSize );
|
||||
extern void vPortFree( void *pv );
|
||||
#define malloc pvPortMalloc
|
||||
#define free vPortFree
|
||||
#elif defined(USE_STM322xG_EVAL) || defined(USE_STM324xG_EVAL) || defined(STM32F10X_XL)
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
|
||||
#endif //__PLATFORM_STDLIB_H__
|
918
component/common/api/platform/stdlib_patch.c
Normal file
918
component/common/api/platform/stdlib_patch.c
Normal file
|
@ -0,0 +1,918 @@
|
|||
/*
|
||||
|
||||
this is the c lib patch, It can help when the clib provided by IAR
|
||||
does not work well.
|
||||
|
||||
How to use this:
|
||||
1.You must include platform_stdlib.h in you source file。
|
||||
2.There is a macro USE_CLIB_PATCH in platform_stdlib.h should be opened.
|
||||
|
||||
If there is some problems using this patch,
|
||||
You'd better check if you code runs into these functions:
|
||||
|
||||
DiagSscanfPatch
|
||||
DiagStrtokPatch
|
||||
DiagStrstrPatch
|
||||
DiagSnPrintfPatch
|
||||
DiagPrintfPatch
|
||||
DiagSPrintfPatch
|
||||
DiagPrintfPatch
|
||||
DiagSPrintfPatch
|
||||
DiagSnPrintfPatch
|
||||
DiagStrstrPatch
|
||||
DiagStrtokPatch
|
||||
|
||||
*/
|
||||
#ifndef CONFIG_PLATFORM_8711B
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#define DiagPutChar HalSerialPutcRtl8195a
|
||||
|
||||
#define IN
|
||||
#define NULL 0
|
||||
|
||||
typedef unsigned int size_t;
|
||||
typedef unsigned int SIZE_T;
|
||||
typedef unsigned long long u64;
|
||||
typedef unsigned int u32;
|
||||
typedef unsigned short int u16;
|
||||
typedef unsigned char u8;
|
||||
typedef signed long long s64;
|
||||
typedef signed int s32;
|
||||
typedef signed short int s16;
|
||||
typedef unsigned char bool;
|
||||
|
||||
|
||||
#define in_range(c, lo, up) ((u8)c >= lo && (u8)c <= up)
|
||||
#define isprint(c) in_range(c, 0x20, 0x7f)
|
||||
#define isdigit(c) in_range(c, '0', '9')
|
||||
#define isxdigit(c) (isdigit(c) || in_range(c, 'a', 'f') || in_range(c, 'A', 'F'))
|
||||
#define islower(c) in_range(c, 'a', 'z')
|
||||
#define isspace(c) (c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v' || c == ',')
|
||||
#define ULLONG_MAX (~0ULL)
|
||||
#define USHRT_MAX ((u16)(~0U))
|
||||
#define KSTRTOX_OVERFLOW (1U << 31)
|
||||
#define SHRT_MAX ((s16)(USHRT_MAX>>1))
|
||||
|
||||
static inline char _tolower(const char c)
|
||||
{
|
||||
return c | 0x20;
|
||||
}
|
||||
|
||||
|
||||
extern s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder);
|
||||
extern s64 div_s64(s64 dividend, s32 divisor);
|
||||
extern inline char _tolower(const char c);
|
||||
extern u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder);
|
||||
extern u64 div_u64(u64 dividend, u32 divisor);
|
||||
extern unsigned int _parse_integer(const char *s, unsigned int base, unsigned long long *p);
|
||||
extern const char *_parse_integer_fixup_radix(const char *s, unsigned int *base);
|
||||
extern char *skip_spaces(const char *str);
|
||||
extern int skip_atoi(const char **s);
|
||||
extern void HalSerialPutcRtl8195a(u8 c);
|
||||
|
||||
|
||||
static unsigned long long simple_strtoull_patch(const char *cp, char **endp, unsigned int base)
|
||||
{
|
||||
unsigned long long result;
|
||||
unsigned int rv;
|
||||
|
||||
cp = _parse_integer_fixup_radix(cp, &base);
|
||||
rv = _parse_integer(cp, base, &result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static long long simple_strtoll_patch(const char *cp, char **endp, unsigned int base)
|
||||
{
|
||||
if(*cp == '-')
|
||||
return -simple_strtoull_patch(cp + 1, endp, base);
|
||||
|
||||
return simple_strtoull_patch(cp, endp, base);
|
||||
}
|
||||
static unsigned long simple_strtoul_patch(const char *cp, char **endp, unsigned int base)
|
||||
{
|
||||
return simple_strtoull_patch(cp, endp, base);
|
||||
}
|
||||
|
||||
static long simple_strtol_patch(const char *cp, char **endp, unsigned int base)
|
||||
{
|
||||
if(*cp == '-')
|
||||
return -simple_strtoul_patch(cp + 1, endp, base);
|
||||
|
||||
return simple_strtoul_patch(cp, endp, base);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static int judge_digit_width(const char *str)
|
||||
{
|
||||
|
||||
int width = 0;
|
||||
|
||||
while(isdigit(*str)) {
|
||||
width++;
|
||||
str++;
|
||||
}
|
||||
|
||||
return width;
|
||||
}
|
||||
|
||||
|
||||
static int _vsscanf_patch(const char *buf, const char *fmt, va_list args)
|
||||
{
|
||||
const char *str = buf;
|
||||
char *next;
|
||||
char digit;
|
||||
int num = 0;
|
||||
int i =0;
|
||||
u8 qualifier;
|
||||
unsigned int base;
|
||||
union {
|
||||
long long s;
|
||||
unsigned long long u;
|
||||
} val;
|
||||
s16 field_width;
|
||||
bool is_sign;
|
||||
|
||||
char str_store[20] = {0};
|
||||
|
||||
|
||||
|
||||
while(*fmt) {
|
||||
/* skip any white space in format */
|
||||
/* white space in format matchs any amount of
|
||||
* white space, including none, in the input.
|
||||
*/
|
||||
if(isspace(*fmt)) {
|
||||
fmt = skip_spaces(++fmt);
|
||||
str = skip_spaces(str);
|
||||
}
|
||||
|
||||
/* anything that is not a conversion must match exactly */
|
||||
if(*fmt != '%' && *fmt) {
|
||||
if(*fmt++ != *str++) {
|
||||
break;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!*fmt) {
|
||||
break;
|
||||
}
|
||||
|
||||
++fmt;
|
||||
|
||||
/* skip this conversion.
|
||||
* advance both strings to next white space
|
||||
*/
|
||||
if(*fmt == '*') {
|
||||
if(!*str) {
|
||||
break;
|
||||
}
|
||||
|
||||
while(!isspace(*fmt) && *fmt != '%' && *fmt)
|
||||
fmt++;
|
||||
|
||||
while(!isspace(*str) && *str)
|
||||
str++;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
/* get field width */
|
||||
field_width = -1;
|
||||
|
||||
if(isdigit(*fmt)) {
|
||||
|
||||
field_width = skip_atoi(&fmt);
|
||||
|
||||
|
||||
|
||||
if(field_width <= 0) {
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* get conversion qualifier */
|
||||
qualifier = -1;
|
||||
|
||||
if(*fmt == 'h' || _tolower(*fmt) == 'l' ||
|
||||
_tolower(*fmt) == 'z') {
|
||||
qualifier = *fmt++;
|
||||
|
||||
if(qualifier == *fmt) {
|
||||
if(qualifier == 'h') {
|
||||
qualifier = 'H';
|
||||
fmt++;
|
||||
} else if(qualifier == 'l') {
|
||||
qualifier = 'L';
|
||||
fmt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!*fmt) {
|
||||
break;
|
||||
}
|
||||
|
||||
if(*fmt == 'n') {
|
||||
/* return number of characters read so far */
|
||||
*va_arg(args, int *) = str - buf;
|
||||
++fmt;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!*str) {
|
||||
break;
|
||||
}
|
||||
|
||||
base = 10;
|
||||
is_sign = 0;
|
||||
|
||||
switch(*fmt++) {
|
||||
case 'c': {
|
||||
char *s = (char *)va_arg(args, char*);
|
||||
|
||||
if(field_width == -1)
|
||||
field_width = 1;
|
||||
|
||||
do {
|
||||
*s++ = *str++;
|
||||
} while(--field_width > 0 && *str);
|
||||
|
||||
num++;
|
||||
}
|
||||
|
||||
continue;
|
||||
|
||||
case 's': {
|
||||
char *s = (char *)va_arg(args, char *);
|
||||
|
||||
if(field_width == -1)
|
||||
field_width = SHRT_MAX;
|
||||
|
||||
/* first, skip leading white space in buffer */
|
||||
str = skip_spaces(str);
|
||||
|
||||
/* now copy until next white space */
|
||||
while(*str && !isspace(*str) && field_width--) {
|
||||
*s++ = *str++;
|
||||
}
|
||||
|
||||
*s = '\0';
|
||||
num++;
|
||||
}
|
||||
|
||||
continue;
|
||||
|
||||
case 'o':
|
||||
base = 8;
|
||||
break;
|
||||
|
||||
case 'x':
|
||||
case 'X':
|
||||
base = 16;
|
||||
break;
|
||||
|
||||
case 'i':
|
||||
base = 0;
|
||||
|
||||
case 'd':
|
||||
is_sign = 1;
|
||||
|
||||
case 'u':
|
||||
break;
|
||||
|
||||
case '%':
|
||||
|
||||
/* looking for '%' in str */
|
||||
if(*str++ != '%') {
|
||||
return num;
|
||||
}
|
||||
|
||||
continue;
|
||||
|
||||
default:
|
||||
/* invalid format; stop here */
|
||||
return num;
|
||||
}
|
||||
|
||||
/* have some sort of integer conversion.
|
||||
* first, skip white space in buffer.
|
||||
*/
|
||||
str = skip_spaces(str);
|
||||
|
||||
digit = *str;
|
||||
|
||||
if(is_sign && digit == '-')
|
||||
digit = *(str + 1);
|
||||
|
||||
if(!digit
|
||||
|| (base == 16 && !isxdigit(digit))
|
||||
|| (base == 10 && !isdigit(digit))
|
||||
|| (base == 8 && (!isdigit(digit) || digit > '7'))
|
||||
|| (base == 0 && !isdigit(digit))) {
|
||||
break;
|
||||
}
|
||||
|
||||
//here problem *******************************************
|
||||
|
||||
|
||||
|
||||
//troy add ,fix support %2d, but not support %d
|
||||
if(field_width <= 0) {
|
||||
|
||||
field_width = judge_digit_width(str);
|
||||
}
|
||||
|
||||
|
||||
/////troy add, fix str passed inwidth wrong
|
||||
for(i = 0; i<field_width ; i++)
|
||||
str_store[i] = str[i];
|
||||
|
||||
next = (char*)str + field_width;
|
||||
|
||||
|
||||
|
||||
if(is_sign) {
|
||||
val.s = qualifier != 'L' ?
|
||||
simple_strtol_patch(str_store, &next, base) :
|
||||
simple_strtoll_patch(str_store, &next, base);
|
||||
} else {
|
||||
val.u = qualifier != 'L' ?
|
||||
simple_strtoul_patch(str_store, &next, base) :
|
||||
simple_strtoull_patch(str_store, &next, base);
|
||||
}
|
||||
|
||||
|
||||
////troy add
|
||||
for(i = 0; i<20 ; i++)
|
||||
str_store[i] = 0;
|
||||
|
||||
|
||||
//判断转换的字符串的宽度是否大于 %2d
|
||||
if(field_width > 0 && next - str > field_width) {
|
||||
if(base == 0)
|
||||
_parse_integer_fixup_radix(str, &base);
|
||||
|
||||
while(next - str > field_width) {
|
||||
if(is_sign) {
|
||||
val.s = div_s64(val.s, base);
|
||||
} else {
|
||||
val.u = div_u64(val.u, base);
|
||||
}
|
||||
|
||||
--next;
|
||||
}
|
||||
}
|
||||
|
||||
switch(qualifier) {
|
||||
case 'H': /* that's 'hh' in format */
|
||||
if(is_sign)
|
||||
*va_arg(args, signed char *) = val.s;
|
||||
else
|
||||
*va_arg(args, unsigned char *) = val.u;
|
||||
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
if(is_sign)
|
||||
*va_arg(args, short *) = val.s;
|
||||
else
|
||||
*va_arg(args, unsigned short *) = val.u;
|
||||
|
||||
break;
|
||||
|
||||
case 'l':
|
||||
if(is_sign)
|
||||
*va_arg(args, long *) = val.s;
|
||||
else
|
||||
*va_arg(args, unsigned long *) = val.u;
|
||||
|
||||
break;
|
||||
|
||||
case 'L':
|
||||
if(is_sign)
|
||||
*va_arg(args, long long *) = val.s;
|
||||
else
|
||||
*va_arg(args, unsigned long long *) = val.u;
|
||||
|
||||
break;
|
||||
|
||||
case 'Z':
|
||||
case 'z':
|
||||
*va_arg(args, size_t *) = val.u;
|
||||
break;
|
||||
|
||||
default:
|
||||
if(is_sign)
|
||||
*va_arg(args, int *) = val.s;
|
||||
else
|
||||
*va_arg(args, unsigned int *) = val.u;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
num++;
|
||||
|
||||
if(!next) {
|
||||
break;
|
||||
}
|
||||
|
||||
str = next;
|
||||
}
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
|
||||
int DiagSscanfPatch(const char *buf, const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
int i;
|
||||
|
||||
va_start(args, fmt);
|
||||
i = _vsscanf_patch(buf, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*********************************************************/
|
||||
|
||||
|
||||
|
||||
char* DiagStrtokPatch(char *str, const char* delim) {
|
||||
static char* _buffer;
|
||||
|
||||
if(str != NULL) _buffer = str;
|
||||
|
||||
if(_buffer[0] == '\0') return NULL;
|
||||
|
||||
char *ret = _buffer, *b;
|
||||
const char *d;
|
||||
|
||||
for(b = _buffer; *b !='\0'; b++) {
|
||||
for(d = delim; *d != '\0'; d++) {
|
||||
if(*b == *d) {
|
||||
*b = '\0';
|
||||
_buffer = b+1;
|
||||
|
||||
// skip the beginning delimiters
|
||||
if(b == ret) {
|
||||
ret++;
|
||||
continue;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*********************************************************/
|
||||
|
||||
|
||||
|
||||
char *DiagStrstrPatch(char *string, char *substring)
|
||||
{
|
||||
register char *a, *b;
|
||||
|
||||
/* First scan quickly through the two strings looking for a
|
||||
* single-character match. When it's found, then compare the
|
||||
* rest of the substring.
|
||||
*/
|
||||
|
||||
b = substring;
|
||||
|
||||
if(*b == 0) {
|
||||
return string;
|
||||
}
|
||||
|
||||
for(; *string != 0; string += 1) {
|
||||
if(*string != *b) {
|
||||
continue;
|
||||
}
|
||||
|
||||
a = string;
|
||||
|
||||
while(1) {
|
||||
if(*b == 0) {
|
||||
return string;
|
||||
}
|
||||
|
||||
if(*a++ != *b++) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
b = substring;
|
||||
}
|
||||
|
||||
return (char *) 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*********************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
int DiagSnPrintfPatch(char *buf, size_t size, const char *fmt, ...)
|
||||
{
|
||||
|
||||
va_list ap;
|
||||
char *p, *s, *buf_end = NULL;
|
||||
const int *dp = ((const int *)&fmt)+1;
|
||||
|
||||
if(buf == NULL)
|
||||
return 0;
|
||||
|
||||
|
||||
va_start(ap, fmt);
|
||||
s = buf;
|
||||
buf_end = size? (buf + size):(char*)~0;
|
||||
|
||||
for(; *fmt != '\0'; ++fmt) {
|
||||
|
||||
if(*fmt != '%') {
|
||||
*s++ = *fmt;
|
||||
|
||||
if(s >= buf_end) {
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if(*++fmt == 's') {
|
||||
for(p = (char *)*dp++; *p != '\0'; p++) {
|
||||
*s++ = *p;
|
||||
|
||||
if(s >= buf_end) {
|
||||
goto Exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
else { /* Length of item is bounded */
|
||||
char tmp[20], *q = tmp;
|
||||
int alt = 0;
|
||||
int shift = 0;// = 12;
|
||||
const long *lpforchk = (const long *)dp;
|
||||
|
||||
if((*lpforchk) < 0x10) {
|
||||
shift = 0;
|
||||
}
|
||||
else if(((*lpforchk) >= 0x10) && ((*lpforchk) < 0x100)) {
|
||||
shift = 4;
|
||||
}
|
||||
else if(((*lpforchk) >= 0x100) && ((*lpforchk) < 0x1000)) {
|
||||
shift = 8;
|
||||
}
|
||||
else if(((*lpforchk) >= 0x1000) && ((*lpforchk) < 0x10000)) {
|
||||
shift = 12;
|
||||
}
|
||||
else if(((*lpforchk) >= 0x10000) && ((*lpforchk) < 0x100000)) {
|
||||
shift = 16;
|
||||
}
|
||||
else if(((*lpforchk) >= 0x100000) && ((*lpforchk) < 0x1000000)) {
|
||||
shift = 20;
|
||||
}
|
||||
else if(((*lpforchk) >= 0x1000000) && ((*lpforchk) < 0x10000000)) {
|
||||
shift = 24;
|
||||
}
|
||||
else if((*lpforchk) >= 0x10000000) {
|
||||
shift = 28;
|
||||
}
|
||||
else {
|
||||
shift = 28;
|
||||
}
|
||||
|
||||
if((*fmt >= '0') && (*fmt <= '9'))
|
||||
{
|
||||
int width;
|
||||
unsigned char fch = *fmt;
|
||||
|
||||
for(width=0; (fch>='0') && (fch<='9'); fch=*++fmt)
|
||||
{ width = width * 10 + fch - '0';
|
||||
}
|
||||
|
||||
shift=(width-1)*4;
|
||||
}
|
||||
|
||||
/*
|
||||
* Before each format q points to tmp buffer
|
||||
* After each format q points past end of item
|
||||
*/
|
||||
if((*fmt == 'x')||(*fmt == 'X') || (*fmt == 'p') || (*fmt == 'P')) {
|
||||
/* With x86 gcc, sizeof(long) == sizeof(int) */
|
||||
const long *lp = (const long *)dp;
|
||||
long h = *lp++;
|
||||
int hex_count = 0;
|
||||
unsigned long h_back = h;
|
||||
int ncase = (*fmt & 0x20);
|
||||
dp = (const int *)lp;
|
||||
|
||||
if((*fmt == 'p') || (*fmt == 'P'))
|
||||
alt=1;
|
||||
|
||||
if(alt) {
|
||||
*q++ = '0';
|
||||
*q++ = 'X' | ncase;
|
||||
}
|
||||
|
||||
while(h_back) {
|
||||
hex_count += (h_back & 0xF) ? 1 : 0;
|
||||
h_back = h_back >> 4;
|
||||
}
|
||||
|
||||
if(shift < (hex_count - 1)*4)
|
||||
shift = (hex_count - 1)*4;
|
||||
|
||||
for(; shift >= 0; shift -= 4)
|
||||
*q++ = "0123456789ABCDEF"[(h >> shift) & 0xF] | ncase;
|
||||
}
|
||||
else if(*fmt == 'd') {
|
||||
int i = *dp++;
|
||||
char *r;
|
||||
int digit_space = 0;
|
||||
|
||||
|
||||
if(i < 0) {
|
||||
*q++ = '-';
|
||||
i = -i;
|
||||
digit_space++;
|
||||
}
|
||||
|
||||
p = q; /* save beginning of digits */
|
||||
|
||||
|
||||
do {
|
||||
*q++ = '0' + (i % 10);
|
||||
i /= 10;
|
||||
digit_space++;
|
||||
} while(i);
|
||||
|
||||
|
||||
for(; shift >= 0; shift -= 4) {
|
||||
|
||||
if(digit_space-- > 0) {
|
||||
; //do nothing
|
||||
} else {
|
||||
*q++ = '0';
|
||||
}
|
||||
}
|
||||
|
||||
/* reverse digits, stop in middle */
|
||||
r = q; /* don't alter q */
|
||||
|
||||
while(--r > p) {
|
||||
i = *r;
|
||||
*r = *p;
|
||||
*p++ = i;
|
||||
}
|
||||
}
|
||||
else if(*fmt == 'c')
|
||||
*q++ = *dp++;
|
||||
else
|
||||
*q++ = *fmt;
|
||||
|
||||
/* now output the saved string */
|
||||
for(p = tmp; p < q; ++p) {
|
||||
*s++ = *p;
|
||||
|
||||
if(s >= buf_end) {
|
||||
goto Exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Exit:
|
||||
|
||||
if(buf)
|
||||
*s = '\0';
|
||||
|
||||
va_end(ap);
|
||||
return(s-buf);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*********************************************************/
|
||||
|
||||
static int VSprintfPatch(char *buf, const char *fmt, const int *dp)
|
||||
{
|
||||
char *p, *s;
|
||||
s = buf;
|
||||
|
||||
for(; *fmt != '\0'; ++fmt) {
|
||||
if(*fmt != '%') {
|
||||
if(buf) {
|
||||
*s++ = *fmt;
|
||||
} else {
|
||||
DiagPutChar(*fmt);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if(*++fmt == 's') {
|
||||
for(p = (char *)*dp++; *p != '\0'; p++) {
|
||||
if(buf) {
|
||||
*s++ = *p;
|
||||
} else {
|
||||
DiagPutChar(*p);
|
||||
}
|
||||
}
|
||||
}
|
||||
else { /* Length of item is bounded */
|
||||
char tmp[20], *q = tmp;
|
||||
int alt = 0;
|
||||
int shift = 0;// = 12;
|
||||
const long *lpforchk = (const long *)dp;
|
||||
|
||||
if((*lpforchk) < 0x10) {
|
||||
shift = 0;
|
||||
}
|
||||
else if(((*lpforchk) >= 0x10) && ((*lpforchk) < 0x100)) {
|
||||
shift = 4;
|
||||
}
|
||||
else if(((*lpforchk) >= 0x100) && ((*lpforchk) < 0x1000)) {
|
||||
shift = 8;
|
||||
}
|
||||
else if(((*lpforchk) >= 0x1000) && ((*lpforchk) < 0x10000)) {
|
||||
shift = 12;
|
||||
}
|
||||
else if(((*lpforchk) >= 0x10000) && ((*lpforchk) < 0x100000)) {
|
||||
shift = 16;
|
||||
}
|
||||
else if(((*lpforchk) >= 0x100000) && ((*lpforchk) < 0x1000000)) {
|
||||
shift = 20;
|
||||
}
|
||||
else if(((*lpforchk) >= 0x1000000) && ((*lpforchk) < 0x10000000)) {
|
||||
shift = 24;
|
||||
}
|
||||
else if((*lpforchk) >= 0x10000000) {
|
||||
shift = 28;
|
||||
}
|
||||
else {
|
||||
shift = 28;
|
||||
}
|
||||
|
||||
#if 1 //wei patch for %02x
|
||||
|
||||
if((*fmt >= '0') && (*fmt <= '9'))
|
||||
{
|
||||
int width;
|
||||
unsigned char fch = *fmt;
|
||||
|
||||
for(width=0; (fch>='0') && (fch<='9'); fch=*++fmt)
|
||||
{ width = width * 10 + fch - '0';
|
||||
}
|
||||
|
||||
shift=(width-1)*4;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Before each format q points to tmp buffer
|
||||
* After each format q points past end of item
|
||||
*/
|
||||
|
||||
if((*fmt == 'x')||(*fmt == 'X') || (*fmt == 'p') || (*fmt == 'P')) {
|
||||
/* With x86 gcc, sizeof(long) == sizeof(int) */
|
||||
const long *lp = (const long *)dp;
|
||||
long h = *lp++;
|
||||
int hex_count = 0;
|
||||
unsigned long h_back = h;
|
||||
int ncase = (*fmt & 0x20);
|
||||
dp = (const int *)lp;
|
||||
|
||||
if((*fmt == 'p') || (*fmt == 'P'))
|
||||
alt=1;
|
||||
|
||||
if(alt) {
|
||||
*q++ = '0';
|
||||
*q++ = 'X' | ncase;
|
||||
}
|
||||
|
||||
//hback 是实际得到的数据,hex_count是统计数据的HEX字符个数
|
||||
while(h_back) {
|
||||
hex_count += (h_back & 0xF) ? 1 : 0;
|
||||
h_back = h_back >> 4;
|
||||
}
|
||||
|
||||
//这里修复 example: 字符有4个,但是用了%02x导致字符被截断的情况
|
||||
if(shift < (hex_count - 1)*4)
|
||||
shift = (hex_count - 1)*4;
|
||||
|
||||
//printf("(%d,%d)", hex_count, shift);
|
||||
|
||||
for(; shift >= 0; shift -= 4) {
|
||||
|
||||
*q++ = "0123456789ABCDEF"[(h >> shift) & 0xF] | ncase;
|
||||
}
|
||||
|
||||
}
|
||||
else if(*fmt == 'd') {
|
||||
int i = *dp++;
|
||||
char *r;
|
||||
int digit_space = 0;
|
||||
|
||||
if(i < 0) {
|
||||
*q++ = '-';
|
||||
i = -i;
|
||||
digit_space++;
|
||||
}
|
||||
|
||||
p = q; /* save beginning of digits */
|
||||
|
||||
do {
|
||||
*q++ = '0' + (i % 10);
|
||||
i /= 10;
|
||||
digit_space++;
|
||||
} while(i);
|
||||
|
||||
//这里修复 example:用了%08d后,在数字前面没有0的情况
|
||||
for(; shift >= 0; shift -= 4) {
|
||||
|
||||
if(digit_space-- > 0) {
|
||||
; //do nothing
|
||||
} else {
|
||||
*q++ = '0';
|
||||
}
|
||||
}
|
||||
|
||||
/* reverse digits, stop in middle */
|
||||
r = q; /* don't alter q */
|
||||
|
||||
while(--r > p) {
|
||||
i = *r;
|
||||
*r = *p;
|
||||
*p++ = i;
|
||||
}
|
||||
}
|
||||
else if(*fmt == 'c')
|
||||
*q++ = *dp++;
|
||||
else
|
||||
*q++ = *fmt;
|
||||
|
||||
/* now output the saved string */
|
||||
for(p = tmp; p < q; ++p) {
|
||||
if(buf) {
|
||||
*s++ = *p;
|
||||
} else {
|
||||
DiagPutChar(*p);
|
||||
}
|
||||
|
||||
if((*p) == '\n') {
|
||||
DiagPutChar('\r');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(buf)
|
||||
*s = '\0';
|
||||
|
||||
return (s - buf);
|
||||
}
|
||||
|
||||
|
||||
u32 DiagPrintfPatch(
|
||||
IN const char *fmt, ...
|
||||
)
|
||||
{
|
||||
(void)VSprintfPatch(0, fmt, ((const int *)&fmt)+1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
u32 DiagSPrintfPatch(
|
||||
IN u8 *buf,
|
||||
IN const char *fmt, ...
|
||||
)
|
||||
{
|
||||
(void)VSprintfPatch((char*)buf, fmt, ((const int *)&fmt)+1);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
149
component/common/api/wifi/rtw_wowlan/dev_wowlan.c
Normal file
149
component/common/api/wifi/rtw_wowlan/dev_wowlan.c
Normal file
|
@ -0,0 +1,149 @@
|
|||
#include <PinNames.h>
|
||||
#include <pinmap.h>
|
||||
#include <gpio_api.h>
|
||||
#include <wifi_wowlan.h>
|
||||
#include <freertos_pmu.h>
|
||||
#include <wifi_conf.h>
|
||||
|
||||
#define CONFIG_WOWLAN_DEV_NT96658 //build for Nova NT96658
|
||||
//#define CONFIG_WOWLAN_DEV_OV788 //build for OmniVision OV788
|
||||
|
||||
#if defined(CONFIG_WOWLAN_DEV_NT96658) && defined(CONFIG_WOWLAN_DEV_OV788)
|
||||
#error "CONFIG_WOWLAN_DEV_NT96658 and CONFIG_WOWLAN_DEV_OV788 are mutually exclusive. "
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_WOWLAN_DEV_NT96658
|
||||
#define WOW_WIFI_IN_PIN PE_4 //JTAG pin, so JTAG must be disable before using this pin as wakeup pin
|
||||
#define WOW_TRIGGER_INTERVAL 500
|
||||
#elif defined(CONFIG_WOWLAN_DEV_OV788)
|
||||
#define WOW_WIFI_IN_PIN PD_5
|
||||
#define WOW_WLAN_ON_PIN PB_3
|
||||
#define WOW_TRIGGER_INTERVAL 200
|
||||
#else
|
||||
#error "Either CONFIG_WOWLAN_DEV_NT96658 or CONFIG_WOWLAN_DEV_OV788 should be defined, but not both. "
|
||||
#endif
|
||||
|
||||
//pin assignment for SDIO, default pull high
|
||||
#define SD_D2 PA_0
|
||||
#define SD_D3 PA_1
|
||||
#define SD_CMD PA_2
|
||||
#define SD_CLK PA_3
|
||||
#define SD_D0 PA_4
|
||||
#define SD_D1 PA_5
|
||||
#define SD_CD PA_6
|
||||
|
||||
gpio_t wow_gpio_wifi_in; //WOWLAN WAKEUP TRIGGER PORT
|
||||
gpio_t wow_gpio_wlan_on; //RECORD WOWLAN STATUS: 1:OFF, 0:ON
|
||||
|
||||
int dev_wowlan_init(void){
|
||||
WOWLAN_PRINTK("WOWLAN: device init!");
|
||||
|
||||
#ifdef CONFIG_WOWLAN_DEV_OV788
|
||||
// Initial WLAN_ON pin
|
||||
gpio_init(&wow_gpio_wlan_on, WOW_WLAN_ON_PIN);
|
||||
gpio_dir(&wow_gpio_wlan_on, PIN_OUTPUT);
|
||||
gpio_mode(&wow_gpio_wlan_on, PullNone);
|
||||
gpio_write(&wow_gpio_wlan_on, 1);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int dev_wowlan_enable(void){
|
||||
WOWLAN_PRINTK("WOWLAN: device enable!");
|
||||
|
||||
// Init WIFI_IN pin (wakeup pin)
|
||||
gpio_init(&wow_gpio_wifi_in, WOW_WIFI_IN_PIN);
|
||||
gpio_dir(&wow_gpio_wifi_in, PIN_OUTPUT);
|
||||
gpio_mode(&wow_gpio_wifi_in, PullNone);
|
||||
gpio_write(&wow_gpio_wifi_in, 0);
|
||||
|
||||
#ifdef CONFIG_WOWLAN_DEV_OV788
|
||||
gpio_write(&wow_gpio_wlan_on, 0);
|
||||
#endif
|
||||
|
||||
#if CONFIG_WLAN
|
||||
wifi_set_power_mode(0xff, 1);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int dev_wowlan_wakeup_process(void){
|
||||
WOWLAN_PRINTK("WOWLAN: device wake up!");
|
||||
|
||||
#if defined(CONFIG_WOWLAN_DEV_NT96658) || defined(CONFIG_WOWLAN_DEV_OV788)
|
||||
#if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1)
|
||||
//acquire wakelock to keep system awake
|
||||
acquire_wakelock(WAKELOCK_SDIO_DEVICE);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_WOWLAN_DEV_OV788
|
||||
//record wowlan status
|
||||
gpio_write(&wow_gpio_wlan_on, 1);
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_WOWLAN_DEV_NT96658)
|
||||
//restore SDIO pin status for bus communication
|
||||
pin_mode(SD_D0, PullUp);
|
||||
pin_mode(SD_D1, PullUp);
|
||||
pin_mode(SD_D2, PullUp);
|
||||
pin_mode(SD_D3, PullUp);
|
||||
pin_mode(SD_CMD, PullUp);
|
||||
pin_mode(SD_CLK, PullDown);
|
||||
#endif
|
||||
|
||||
//send signal to awake host
|
||||
gpio_write(&wow_gpio_wifi_in, 0);
|
||||
wowlan_mdelay_os(WOW_TRIGGER_INTERVAL);
|
||||
gpio_write(&wow_gpio_wifi_in, 1);
|
||||
wowlan_mdelay_os(WOW_TRIGGER_INTERVAL);
|
||||
gpio_write(&wow_gpio_wifi_in, 0);
|
||||
wowlan_mdelay_os(WOW_TRIGGER_INTERVAL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int dev_wowlan_sleep_process(void){
|
||||
|
||||
#if defined(CONFIG_WOWLAN_DEV_NT96658)
|
||||
//pull control for SDIO pin only when host is already power off
|
||||
if(rtw_wowlan_is_enabled() && (rtw_wowlan_get_wk_reason() == 0)){
|
||||
WOWLAN_PRINTK("pull control");
|
||||
//configure SDIO pin status for avoiding current leakage
|
||||
pin_mode(SD_D0, PullNone);
|
||||
pin_mode(SD_D1, PullNone);
|
||||
pin_mode(SD_D2, PullNone);
|
||||
pin_mode(SD_D3, PullNone);
|
||||
pin_mode(SD_CMD, PullNone);
|
||||
pin_mode(SD_CLK, PullNone);
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int dev_wowlan_disable(void){
|
||||
WOWLAN_PRINTK("WOWLAN: device disable!");
|
||||
|
||||
#if CONFIG_WLAN
|
||||
wifi_set_power_mode(0xff, 0);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_WOWLAN_DEV_OV788
|
||||
gpio_write(&wow_gpio_wlan_on, 1);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dev_wowlan_ops_init(void *dev_ops){
|
||||
struct rtw_wowlan_ops *ops = (struct rtw_wowlan_ops *)dev_ops;
|
||||
WOWLAN_PRINTK("WOWLAN: device ops init!");
|
||||
ops->DevWowlanInit = dev_wowlan_init;
|
||||
ops->DevWowlanEnable = dev_wowlan_enable;
|
||||
ops->DevWowlanDisable = dev_wowlan_disable;
|
||||
ops->DevWowlanWakeUp = dev_wowlan_wakeup_process;
|
||||
ops->DevWowlanSleep = dev_wowlan_sleep_process;
|
||||
}
|
381
component/common/api/wifi/rtw_wowlan/wifi_wowlan.h
Normal file
381
component/common/api/wifi/rtw_wowlan/wifi_wowlan.h
Normal file
|
@ -0,0 +1,381 @@
|
|||
#ifndef _WIFI_WOWLAN_H_
|
||||
#define _WIFI_WOWLAN_H_
|
||||
|
||||
#include <platform_stdlib.h>
|
||||
#include <osdep_service.h>
|
||||
#include <FreeRTOS.h>
|
||||
#include <timers.h>
|
||||
|
||||
#define WOWLAN_DBG 1
|
||||
|
||||
enum{
|
||||
WOWLAN_DBG_OFF = 0,
|
||||
WOWLAN_DBG_ALWAYS,
|
||||
WOWLAN_DBG_ERROR,
|
||||
WOWLAN_DBG_WARNING,
|
||||
WOWLAN_DBG_INFO
|
||||
};
|
||||
|
||||
#if WOWLAN_DBG
|
||||
//#define WOWLAN_DUMP_MSG
|
||||
#define WOWLAN_DUMP_MSG_1 //dump packet when setting
|
||||
static unsigned char gWowlanDbgLevel = WOWLAN_DBG_ERROR;
|
||||
#define WOWLAN_PRINTK(fmt, args...) printf(fmt"\r\n",## args)
|
||||
#define _WOWLAN_PRINTK(fmt, args...) printf(fmt,## args)
|
||||
#define WOWLAN_DBG_MSG(level, fmt, args...) \
|
||||
do{ \
|
||||
if(level <= gWowlanDbgLevel){ \
|
||||
WOWLAN_PRINTK(fmt,## args); \
|
||||
} \
|
||||
}while(0)
|
||||
#else
|
||||
#define WOWLAN_PRINTK(fmt, args...)
|
||||
#define WOWLAN_DBG_MSG(level, fmt, args...)
|
||||
#endif
|
||||
|
||||
#ifndef u8
|
||||
typedef unsigned char u8;
|
||||
typedef unsigned short u16;
|
||||
typedef unsigned int u32;
|
||||
#endif
|
||||
|
||||
#ifndef BIT
|
||||
#define BIT(x) ((u32)1 << (x))
|
||||
#endif
|
||||
|
||||
#ifndef le16_to_cpu //need a general definition for the whole system
|
||||
#define cpu_to_le32(x) ((u32)(x))
|
||||
#define le32_to_cpu(x) ((u32)(x))
|
||||
#define cpu_to_le16(x) ((u16)(x))
|
||||
#define le16_to_cpu(x) ((u16)(x))
|
||||
#endif
|
||||
|
||||
#ifndef IP_FMT
|
||||
#define IP_FMT "%d.%d.%d.%d"
|
||||
#endif
|
||||
|
||||
#ifndef IP_ARG
|
||||
#define IP_ARG(x) ((u8*)(x))[0],((u8*)(x))[1],((u8*)(x))[2],((u8*)(x))[3]
|
||||
#endif
|
||||
|
||||
#ifndef MAC_FMT
|
||||
#define MAC_FMT "%02x:%02x:%02x:%02x:%02x:%02x"
|
||||
#endif
|
||||
|
||||
#ifndef MAC_ARG
|
||||
#define MAC_ARG(x) ((u8*)(x))[0],((u8*)(x))[1],((u8*)(x))[2],((u8*)(x))[3],((u8*)(x))[4],((u8*)(x))[5]
|
||||
#endif
|
||||
|
||||
#ifndef ETH_ALEN
|
||||
#define ETH_ALEN 6
|
||||
#endif
|
||||
|
||||
#ifndef ethhdr
|
||||
struct ethhdr
|
||||
{
|
||||
unsigned char h_dest[ETH_ALEN]; /* destination eth addr */
|
||||
unsigned char h_source[ETH_ALEN]; /* source ether addr */
|
||||
unsigned short h_proto; /* packet type ID field */
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifndef wowlan_memcpy
|
||||
#define wowlan_memcpy(d, s, n) rtw_memcpy((void*)(d), ((void*)(s)), (n))
|
||||
#endif
|
||||
|
||||
#ifndef wowlan_malloc
|
||||
#define wowlan_malloc(sz) rtw_malloc(sz)
|
||||
#endif
|
||||
|
||||
#ifndef wowlan_zmalloc
|
||||
#define wowlan_zmalloc(sz) rtw_zmalloc(sz)
|
||||
#endif
|
||||
|
||||
#ifndef wowlan_memset
|
||||
#define wowlan_memset(pbuf, c, sz) rtw_memset(pbuf, c, sz)
|
||||
#endif
|
||||
|
||||
#ifndef wowlan_mfree
|
||||
#define wowlan_mfree(p, sz) rtw_mfree(((u8*)(p)), (sz))
|
||||
#endif
|
||||
|
||||
#ifndef wowlan_memcmp
|
||||
#define wowlan_memcmp(s1, s2, n) rtw_memcmp(((void*)(s1)), ((void*)(s2)), (n))
|
||||
#endif
|
||||
|
||||
#ifndef wowlan_mdelay_os
|
||||
#define wowlan_mdelay_os(ms) rtw_mdelay_os(ms)
|
||||
#endif
|
||||
|
||||
/*Mutex services*/
|
||||
typedef _mutex _wowlock;
|
||||
|
||||
__inline static void _init_wowlock(_wowlock *plock)
|
||||
{
|
||||
rtw_mutex_init(plock);
|
||||
}
|
||||
|
||||
__inline static void _free_wowlock(_wowlock *plock)
|
||||
{
|
||||
rtw_mutex_free(plock);
|
||||
}
|
||||
|
||||
__inline static void _enter_wowlock(_wowlock *plock)
|
||||
{
|
||||
rtw_mutex_get(plock);
|
||||
}
|
||||
|
||||
__inline static void _exit_wowlock(_wowlock *plock)
|
||||
{
|
||||
rtw_mutex_put(plock);
|
||||
}
|
||||
|
||||
/*Timer services*/
|
||||
typedef TimerHandle_t _wowTimer;
|
||||
#define TMR_AUTO_RELOAD_EN _TRUE
|
||||
#define TMR_AUTO_RELOAD_DIS _FALSE
|
||||
|
||||
__inline static void
|
||||
_wowlan_init_timer(_wowTimer *ptimer, void *adapter, TIMER_FUN pfunc,void* cntx, const char *name, u32 auto_reload)
|
||||
{
|
||||
*ptimer = rtw_timerCreate(
|
||||
(signed const char *)name, // Just a text name, not used by the RTOS kernel.
|
||||
TIMER_MAX_DELAY, // Timer Period, not 0
|
||||
auto_reload, // Whether timer will auto-load themselves when expires
|
||||
cntx, // Uniq id used to identify which timer expire..
|
||||
pfunc // Timer callback
|
||||
);
|
||||
}
|
||||
|
||||
__inline static void
|
||||
_wowlan_set_timer(_wowTimer *ptimer, u32 delay_time_ms)
|
||||
{
|
||||
if(rtw_timerChangePeriod(*ptimer, rtw_ms_to_systime(delay_time_ms), TIMER_MAX_DELAY) == _FAIL)
|
||||
WOWLAN_PRINTK("Fail to set timer period");
|
||||
}
|
||||
|
||||
__inline static void
|
||||
_wowlan_cancel_timer(_wowTimer *ptimer)
|
||||
{
|
||||
rtw_timerStop(*ptimer, TIMER_MAX_DELAY);
|
||||
}
|
||||
|
||||
__inline static void
|
||||
_wowlan_del_timer(_wowTimer *ptimer)
|
||||
{
|
||||
rtw_timerDelete(*ptimer, TIMER_MAX_DELAY);
|
||||
}
|
||||
|
||||
__inline static void *
|
||||
_wowlan_get_timer_cntx(_wowTimer timer)
|
||||
{
|
||||
return pvTimerGetTimerID(timer);
|
||||
}
|
||||
|
||||
enum rtw_wowlan_wakeup_reason {
|
||||
RTW_WOWLAN_WAKEUP_BY_PATTERN = BIT(0),
|
||||
RTW_WOWLAN_WAKEUP_BY_DISCONNECTION = BIT(1),
|
||||
RTW_WOWLAN_WAKEUP_MAX = 0x7FFFFFFF
|
||||
};
|
||||
|
||||
enum rtw_wowlan_cmd_id{
|
||||
RTW_WOWLAN_CMD_ENABLE = 0x01, // enable wowlan service
|
||||
RTW_WOWLAN_CMD_PATTERNS = 0x02, // wowlan pattern setting
|
||||
RTW_WOWLAN_CMD_PROT_OFFLOAD_CONFIG = 0x03, //ARP offload setting
|
||||
RTW_WOWLAN_CMD_GET_STATUS = 0x04, // get rtw_wowlan_status
|
||||
RTW_WOWLAN_CMD_CLEAR_ALL = 0x05, //clear wowlan content
|
||||
RTW_WOWLAN_CMD_KEEPALIVE = 0x06, //for keep alive packet setting
|
||||
RTW_WOWLAN_CMD_MAX = 0xff
|
||||
};
|
||||
|
||||
#define RTW_WOWLAN_MAX_RX_FILTERS (5)
|
||||
#define RTW_WOWLAN_RX_FILTER_MAX_FIELDS (8)
|
||||
#define RTW_WOWLAN_ID_OFFSET (100) //to match some application, ID starts from 100
|
||||
#define RTW_WOWLAN_MIN_FILTERS_ID (RTW_WOWLAN_ID_OFFSET)
|
||||
#define RTW_WOWLAN_MAX_FILTERS_ID (RTW_WOWLAN_ID_OFFSET+RTW_WOWLAN_MAX_RX_FILTERS-1)
|
||||
|
||||
struct rtw_wowlan_rx_filter_field {
|
||||
u16 offset;
|
||||
u8 len;
|
||||
u8 flags;
|
||||
u8 *mask;
|
||||
u8 *pattern;
|
||||
};
|
||||
|
||||
struct rtw_wowlan_rx_filter {
|
||||
u8 action;
|
||||
u8 offset;
|
||||
u8 num_fields;
|
||||
struct rtw_wowlan_rx_filter_field fields[RTW_WOWLAN_RX_FILTER_MAX_FIELDS];
|
||||
};
|
||||
|
||||
#if defined(__IAR_SYSTEMS_ICC__)
|
||||
#pragma pack(1)
|
||||
#else
|
||||
#error "this structure needs to be packed!"
|
||||
#endif
|
||||
struct rtw_wowlan_status {
|
||||
u32 wakeup_reasons; //record wake up reason
|
||||
u32 filter_id; //record which pattern is matched
|
||||
};
|
||||
#if defined(__IAR_SYSTEMS_ICC__)
|
||||
#pragma pack()
|
||||
#else
|
||||
#error "this structure needs to be packed!"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* struct rtw_wowlan_keepalive_packet
|
||||
*
|
||||
* @payload_len: data payload length
|
||||
* @payload: data payload buffer
|
||||
* @data_interval: interval at which to send data packets
|
||||
**/
|
||||
#define RTW_WOWLAN_MAX_KPALIVE_PKT 3
|
||||
#define RTW_WOWLAN_MAX_KPALIVE_PKT_SZ 512
|
||||
struct rtw_wowlan_keepalive_packet{
|
||||
u8 packet_id;
|
||||
int payload_len;
|
||||
u8 *payload;
|
||||
u32 data_interval;
|
||||
_wowTimer keepalive_tmr;
|
||||
};
|
||||
|
||||
struct rtw_wowlan_ops {
|
||||
int (*DevWowlanInit)(void);
|
||||
int (*DevWowlanEnable)(void);
|
||||
int (*DevWowlanDisable)(void);
|
||||
int (*DevWowlanWakeUp)(void);
|
||||
int (*DevWowlanSleep)(void);
|
||||
};
|
||||
|
||||
/**
|
||||
* enum rtw_wowlan_proto_offloads - enabled protocol offloads
|
||||
* @RTW_WOWLAN_PROTO_OFFLOAD_ARP: ARP data is enabled
|
||||
*/
|
||||
enum rtw_wowlan_proto_offloads {
|
||||
RTW_WOWLAN_PROTO_OFFLOAD_ARP = BIT(0),
|
||||
RTW_WOWLAN_PROTO_OFFLOAD_MAX = 0x7FFFFFFF
|
||||
};
|
||||
|
||||
/**
|
||||
* struct rtw_wowlan_proto_offload_common - ARP/NS offload common part
|
||||
* @enabled: enable flags
|
||||
* @remote_ipv4_addr: remote address to answer to (or zero if all)
|
||||
* @host_ipv4_addr: our IPv4 address to respond to queries for
|
||||
* @arp_mac_addr: our MAC address for ARP responses
|
||||
* @reserved: unused
|
||||
*/
|
||||
struct rtw_wowlan_proto_offload_common{
|
||||
int proto_enabled;
|
||||
u32 remote_ipv4_addr;
|
||||
u32 host_ipv4_addr;
|
||||
u8 host_mac_addr[ETH_ALEN];
|
||||
u16 reserved;
|
||||
};
|
||||
|
||||
struct rtw_wowlan {
|
||||
_wowlock wow_mutex;
|
||||
bool enabled;
|
||||
struct rtw_wowlan_status status;
|
||||
struct rtw_wowlan_ops ops;
|
||||
struct rtw_wowlan_proto_offload_common proto;
|
||||
bool proto_offload_enabled;
|
||||
struct rtw_wowlan_rx_filter *rx_filter[RTW_WOWLAN_MAX_RX_FILTERS];
|
||||
bool rx_filter_enabled[RTW_WOWLAN_MAX_RX_FILTERS];/* RX Data filter rule state - enabled/disabled */
|
||||
struct rtw_wowlan_keepalive_packet *tx_keepalive[RTW_WOWLAN_MAX_KPALIVE_PKT];
|
||||
bool tx_keepalive_enabled[RTW_WOWLAN_MAX_KPALIVE_PKT];/* TX keep avlive rule state - enabled/disabled */
|
||||
};
|
||||
|
||||
#define eqMacAddr(a,b) ( ((a)[0]==(b)[0] && (a)[1]==(b)[1] && (a)[2]==(b)[2] && (a)[3]==(b)[3] && (a)[4]==(b)[4] && (a)[5]==(b)[5]) ? 1:0 )
|
||||
#define cpMacAddr(des,src) ((des)[0]=(src)[0],(des)[1]=(src)[1],(des)[2]=(src)[2],(des)[3]=(src)[3],(des)[4]=(src)[4],(des)[5]=(src)[5])
|
||||
#define cpIpAddr(des,src) ((des)[0]=(src)[0],(des)[1]=(src)[1],(des)[2]=(src)[2],(des)[3]=(src)[3])
|
||||
|
||||
#define RTW_WOWLAN_GET_ARP_PKT_OPERATION(__pHeader) ReadEF2Byte( ((u8*)(__pHeader)) + 6)
|
||||
#define RTW_WOWLAN_GET_ARP_PKT_SENDER_MAC_ADDR(__pHeader, _val) cpMacAddr((u8*)(_val), ((u8*)(__pHeader))+8)
|
||||
#define RTW_WOWLAN_GET_ARP_PKT_SENDER_IP_ADDR(__pHeader, _val) cpIpAddr((u8*)(_val), ((u8*)(__pHeader))+14)
|
||||
#define RTW_WOWLAN_GET_ARP_PKT_TARGET_MAC_ADDR(__pHeader, _val) cpMacAddr((u8*)(_val), ((u8*)(__pHeader))+18)
|
||||
#define RTW_WOWLAN_GET_ARP_PKT_TARGET_IP_ADDR(__pHeader, _val) cpIpAddr((u8*)(_val), ((u8*)(__pHeader))+24)
|
||||
|
||||
#define RTW_WOWLAN_SET_ARP_PKT_HW(__pHeader, __Value) WriteEF2Byte( ((u8*)(__pHeader)) + 0, __Value)
|
||||
#define RTW_WOWLAN_SET_ARP_PKT_PROTOCOL(__pHeader, __Value) WriteEF2Byte( ((u8*)(__pHeader)) + 2, __Value)
|
||||
#define RTW_WOWLAN_SET_ARP_PKT_HW_ADDR_LEN(__pHeader, __Value) WriteEF1Byte( ((u8*)(__pHeader)) + 4, __Value)
|
||||
#define RTW_WOWLAN_SET_ARP_PKT_PROTOCOL_ADDR_LEN(__pHeader, __Value) WriteEF1Byte( ((u8*)(__pHeader)) + 5, __Value)
|
||||
#define RTW_WOWLAN_SET_ARP_PKT_OPERATION(__pHeader, __Value) WriteEF2Byte( ((u8*)(__pHeader)) + 6, __Value)
|
||||
#define RTW_WOWLAN_SET_ARP_PKT_SENDER_MAC_ADDR(__pHeader, _val) cpMacAddr(((u8*)(__pHeader))+8, (u8*)(_val))
|
||||
#define RTW_WOWLAN_SET_ARP_PKT_SENDER_IP_ADDR(__pHeader, _val) cpIpAddr(((u8*)(__pHeader))+14, (u8*)(_val))
|
||||
#define RTW_WOWLAN_SET_ARP_PKT_TARGET_MAC_ADDR(__pHeader, _val) cpMacAddr(((u8*)(__pHeader))+18, (u8*)(_val))
|
||||
#define RTW_WOWLAN_SET_ARP_PKT_TARGET_IP_ADDR(__pHeader, _val) cpIpAddr(((u8*)(__pHeader))+24, (u8*)(_val))
|
||||
|
||||
#define RTW_WOWLAN_ARP_PKT_LEN 0x2A
|
||||
#define RTW_WOWLAN_ARP_PKT_OPERATION_REQ 0x0100 //arp request
|
||||
#define RTW_WOWLAN_ARP_PKT_OPERATION_RSP 0x0200 //arp response
|
||||
|
||||
extern u8 key_2char2num(u8 hch, u8 lch);
|
||||
extern _LONG_CALL_ void __rtl_memDump_v1_00(const u8 *start, u32 size, char * strHeader);
|
||||
#define rtw_wowlan_DumpForBytes(pData, Len) __rtl_memDump_v1_00(pData, Len, NULL)
|
||||
|
||||
#define PWOWLAN_TO_STATUS(pwowlan) (&pwowlan->status)
|
||||
#define PWOWLAN_TO_OPS(pwowlan) (&pwowlan->ops)
|
||||
#define PWOWLAN_TO_PROTO(pwowlan) (&pwowlan->proto)
|
||||
#define PWOWLAN_TO_RX_FILTER(pwowlan) (pwowlan->rx_filter)
|
||||
#define PWOWLAN_TO_TX_KEEPALIVE(pwowlan) (pwowlan->tx_keepalive)
|
||||
|
||||
/**
|
||||
* rtw_wowlan_init: initialize wowlan service
|
||||
* arg: None
|
||||
* return: _SUCCESS or _FAIL
|
||||
*/
|
||||
extern int rtw_wowlan_init(void);
|
||||
|
||||
/**
|
||||
* cmd_wowlan_service: input commands to configure wowlan service
|
||||
* arg:
|
||||
* @argc: number of input parameter
|
||||
* @argv: content of input string
|
||||
* return: None
|
||||
*/
|
||||
extern void cmd_wowlan_service(int argc, char **argv);
|
||||
|
||||
/**
|
||||
* rtw_wowlan_process_rx_packet: entry for packet process in wowlan service once it starts
|
||||
* arg:
|
||||
* @rx_pkt: receive packet from wlan/ethernet
|
||||
* @pkt_len: receive packet length
|
||||
* return: _SUCCESS or _FAIL
|
||||
*/
|
||||
extern int rtw_wowlan_process_rx_packet(char *rx_pkt, u16 pkt_len);
|
||||
|
||||
/**
|
||||
* rtw_wowlan_wakeup_process: wake up process once the reasons are matched,
|
||||
* refer to enum rtw_wowlan_wakeup_reason
|
||||
* arg:
|
||||
* @reason: wake up reason, refer to enum rtw_wowlan_wakeup_reason
|
||||
* return: None
|
||||
*/
|
||||
extern void rtw_wowlan_wakeup_process(int reason);
|
||||
|
||||
/**
|
||||
* rtw_wowlan_is_enabled: if wowlan service is already enabled
|
||||
* this function is called in rx path and wifi_inidication when wowlan service is running
|
||||
* arg: None
|
||||
* return: _True if enable or _False if disable
|
||||
*/
|
||||
extern int rtw_wowlan_is_enabled(void);
|
||||
|
||||
/**
|
||||
* rtw_wowlan_get_wk_reason: query wake up reason, refer to enum rtw_wowlan_wakeup_reason
|
||||
* arg: None
|
||||
* return: wakeup_reason
|
||||
*/
|
||||
extern int rtw_wowlan_get_wk_reason(void);
|
||||
|
||||
/**
|
||||
* rtw_wowlan_dev_sleep: sleep process on Ameba side, pull control for example
|
||||
* this function is linked to dev_wowlan_sleep_process() in dev_wowlan.c
|
||||
* arg: None
|
||||
* return: None
|
||||
*/
|
||||
extern void rtw_wowlan_dev_sleep(void);
|
||||
|
||||
#endif
|
593
component/common/api/wifi/rtw_wpa_supplicant/src/utils/os.h
Normal file
593
component/common/api/wifi/rtw_wpa_supplicant/src/utils/os.h
Normal file
|
@ -0,0 +1,593 @@
|
|||
/*
|
||||
* OS specific functions
|
||||
* Copyright (c) 2005-2009, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This software may be distributed under the terms of the BSD license.
|
||||
* See README for more details.
|
||||
*/
|
||||
|
||||
#ifndef OS_H
|
||||
#define OS_H
|
||||
|
||||
//#include "basic_types.h"
|
||||
#include <autoconf.h>
|
||||
#include "osdep_service.h"
|
||||
#include "freertos/wrapper.h"
|
||||
#include "utils/rom/rom_wps_os.h"
|
||||
|
||||
typedef void* xqueue_handle_t;
|
||||
|
||||
typedef long os_time_t;
|
||||
|
||||
typedef _timer os_timer;
|
||||
|
||||
/**
|
||||
* os_sleep - Sleep (sec, usec)
|
||||
* @sec: Number of seconds to sleep
|
||||
* @usec: Number of microseconds to sleep
|
||||
*/
|
||||
void os_sleep(os_time_t sec, os_time_t usec);
|
||||
|
||||
struct os_time {
|
||||
os_time_t sec;
|
||||
os_time_t usec;
|
||||
};
|
||||
|
||||
struct os_reltime {
|
||||
os_time_t sec;
|
||||
os_time_t usec;
|
||||
};
|
||||
|
||||
/**
|
||||
* os_get_time - Get current time (sec, usec)
|
||||
* @t: Pointer to buffer for the time
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*/
|
||||
int os_get_time(struct os_time *t);
|
||||
|
||||
int os_get_reltime(struct os_reltime *t);
|
||||
/* Helper macros for handling struct os_time */
|
||||
/* (&timeout->time, &tmp->time) */
|
||||
#define os_time_before(a, b) \
|
||||
((a)->sec < (b)->sec || \
|
||||
((a)->sec == (b)->sec && (a)->usec < (b)->usec))
|
||||
|
||||
#define os_time_sub(a, b, res) do { \
|
||||
(res)->sec = (a)->sec - (b)->sec; \
|
||||
(res)->usec = (a)->usec - (b)->usec; \
|
||||
if ((res)->usec < 0) { \
|
||||
(res)->sec--; \
|
||||
(res)->usec += 1000000; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
* os_mktime - Convert broken-down time into seconds since 1970-01-01
|
||||
* @year: Four digit year
|
||||
* @month: Month (1 .. 12)
|
||||
* @day: Day of month (1 .. 31)
|
||||
* @hour: Hour (0 .. 23)
|
||||
* @min: Minute (0 .. 59)
|
||||
* @sec: Second (0 .. 60)
|
||||
* @t: Buffer for returning calendar time representation (seconds since
|
||||
* 1970-01-01 00:00:00)
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*
|
||||
* Note: The result is in seconds from Epoch, i.e., in UTC, not in local time
|
||||
* which is used by POSIX mktime().
|
||||
*/
|
||||
int os_mktime(int year, int month, int day, int hour, int min, int sec,
|
||||
os_time_t *t);
|
||||
|
||||
struct os_tm {
|
||||
int sec; /* 0..59 or 60 for leap seconds */
|
||||
int min; /* 0..59 */
|
||||
int hour; /* 0..23 */
|
||||
int day; /* 1..31 */
|
||||
int month; /* 1..12 */
|
||||
int year; /* Four digit year */
|
||||
};
|
||||
|
||||
int os_gmtime(os_time_t t, struct os_tm *tm);
|
||||
|
||||
/* Helpers for handling struct os_time */
|
||||
|
||||
/* Helpers for handling struct os_reltime */
|
||||
|
||||
static inline int os_reltime_before(struct os_reltime *a,
|
||||
struct os_reltime *b)
|
||||
{
|
||||
return os_time_before(a,b);
|
||||
}
|
||||
|
||||
|
||||
static inline void os_reltime_sub(struct os_reltime *a, struct os_reltime *b,
|
||||
struct os_reltime *res)
|
||||
{
|
||||
os_time_sub(a,b,res);
|
||||
}
|
||||
|
||||
|
||||
static inline void os_reltime_age(struct os_reltime *start,
|
||||
struct os_reltime *age)
|
||||
{
|
||||
struct os_reltime now;
|
||||
|
||||
os_get_time((struct os_time *)&now);
|
||||
os_reltime_sub(&now, start, age);
|
||||
}
|
||||
|
||||
|
||||
static inline int os_reltime_expired(struct os_reltime *now,
|
||||
struct os_reltime *ts,
|
||||
os_time_t timeout_secs)
|
||||
{
|
||||
struct os_reltime age;
|
||||
|
||||
os_reltime_sub(now, ts, &age);
|
||||
return (age.sec > timeout_secs) ||
|
||||
(age.sec == timeout_secs && age.usec > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* os_daemonize - Run in the background (detach from the controlling terminal)
|
||||
* @pid_file: File name to write the process ID to or %NULL to skip this
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*/
|
||||
int os_daemonize(const char *pid_file);
|
||||
|
||||
/**
|
||||
* os_daemonize_terminate - Stop running in the background (remove pid file)
|
||||
* @pid_file: File name to write the process ID to or %NULL to skip this
|
||||
*/
|
||||
void os_daemonize_terminate(const char *pid_file);
|
||||
|
||||
/**
|
||||
* os_get_random - Get cryptographically strong pseudo random data
|
||||
* @buf: Buffer for pseudo random data
|
||||
* @len: Length of the buffer
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*/
|
||||
int os_get_random(unsigned char *buf, size_t len);
|
||||
|
||||
/**
|
||||
* os_random - Get pseudo random value (not necessarily very strong)
|
||||
* Returns: Pseudo random value
|
||||
*/
|
||||
unsigned long os_random(void);
|
||||
|
||||
/**
|
||||
* os_rel2abs_path - Get an absolute path for a file
|
||||
* @rel_path: Relative path to a file
|
||||
* Returns: Absolute path for the file or %NULL on failure
|
||||
*
|
||||
* This function tries to convert a relative path of a file to an absolute path
|
||||
* in order for the file to be found even if current working directory has
|
||||
* changed. The returned value is allocated and caller is responsible for
|
||||
* freeing it. It is acceptable to just return the same path in an allocated
|
||||
* buffer, e.g., return strdup(rel_path). This function is only used to find
|
||||
* configuration files when os_daemonize() may have changed the current working
|
||||
* directory and relative path would be pointing to a different location.
|
||||
*/
|
||||
char * os_rel2abs_path(const char *rel_path);
|
||||
|
||||
/**
|
||||
* os_program_init - Program initialization (called at start)
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*
|
||||
* This function is called when a programs starts. If there are any OS specific
|
||||
* processing that is needed, it can be placed here. It is also acceptable to
|
||||
* just return 0 if not special processing is needed.
|
||||
*/
|
||||
int os_program_init(void);
|
||||
|
||||
/**
|
||||
* os_program_deinit - Program deinitialization (called just before exit)
|
||||
*
|
||||
* This function is called just before a program exists. If there are any OS
|
||||
* specific processing, e.g., freeing resourced allocated in os_program_init(),
|
||||
* it should be done here. It is also acceptable for this function to do
|
||||
* nothing.
|
||||
*/
|
||||
void os_program_deinit(void);
|
||||
|
||||
/**
|
||||
* os_setenv - Set environment variable
|
||||
* @name: Name of the variable
|
||||
* @value: Value to set to the variable
|
||||
* @overwrite: Whether existing variable should be overwritten
|
||||
* Returns: 0 on success, -1 on error
|
||||
*
|
||||
* This function is only used for wpa_cli action scripts. OS wrapper does not
|
||||
* need to implement this if such functionality is not needed.
|
||||
*/
|
||||
int os_setenv(const char *name, const char *value, int overwrite);
|
||||
|
||||
/**
|
||||
* os_unsetenv - Delete environent variable
|
||||
* @name: Name of the variable
|
||||
* Returns: 0 on success, -1 on error
|
||||
*
|
||||
* This function is only used for wpa_cli action scripts. OS wrapper does not
|
||||
* need to implement this if such functionality is not needed.
|
||||
*/
|
||||
int os_unsetenv(const char *name);
|
||||
|
||||
/**
|
||||
* os_readfile - Read a file to an allocated memory buffer
|
||||
* @name: Name of the file to read
|
||||
* @len: For returning the length of the allocated buffer
|
||||
* Returns: Pointer to the allocated buffer or %NULL on failure
|
||||
*
|
||||
* This function allocates memory and reads the given file to this buffer. Both
|
||||
* binary and text files can be read with this function. The caller is
|
||||
* responsible for freeing the returned buffer with os_free().
|
||||
*/
|
||||
char * os_readfile(const char *name, size_t *len);
|
||||
|
||||
//#if 0
|
||||
/**
|
||||
* os_zalloc - Allocate and zero memory
|
||||
* @size: Number of bytes to allocate
|
||||
* Returns: Pointer to allocated and zeroed memory or %NULL on failure
|
||||
*
|
||||
* Caller is responsible for freeing the returned buffer with os_free().
|
||||
*/
|
||||
void * os_zalloc(size_t size);
|
||||
|
||||
/**
|
||||
* os_calloc - Allocate and zero memory for an array
|
||||
* @nmemb: Number of members in the array
|
||||
* @size: Number of bytes in each member
|
||||
* Returns: Pointer to allocated and zeroed memory or %NULL on failure
|
||||
*
|
||||
* This function can be used as a wrapper for os_zalloc(nmemb * size) when an
|
||||
* allocation is used for an array. The main benefit over os_zalloc() is in
|
||||
* having an extra check to catch integer overflows in multiplication.
|
||||
*
|
||||
* Caller is responsible for freeing the returned buffer with os_free().
|
||||
*/
|
||||
static inline void * os_calloc(size_t nmemb, size_t size)
|
||||
{
|
||||
if (size && nmemb > (~(size_t) 0) / size)
|
||||
return NULL;
|
||||
return os_zalloc(nmemb * size);
|
||||
}
|
||||
//#endif
|
||||
|
||||
|
||||
static inline 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;
|
||||
}
|
||||
|
||||
/*
|
||||
* The following functions are wrapper for standard ANSI C or POSIX functions.
|
||||
* By default, they are just defined to use the standard function name and no
|
||||
* os_*.c implementation is needed for them. This avoids extra function calls
|
||||
* by allowing the C pre-processor take care of the function name mapping.
|
||||
*
|
||||
* If the target system uses a C library that does not provide these functions,
|
||||
* build_config.h can be used to define the wrappers to use a different
|
||||
* function name. This can be done on function-by-function basis since the
|
||||
* defines here are only used if build_config.h does not define the os_* name.
|
||||
* If needed, os_*.c file can be used to implement the functions that are not
|
||||
* included in the C library on the target system. Alternatively,
|
||||
* OS_NO_C_LIB_DEFINES can be defined to skip all defines here in which case
|
||||
* these functions need to be implemented in os_*.c file for the target system.
|
||||
*/
|
||||
|
||||
#ifdef OS_NO_C_LIB_DEFINES
|
||||
|
||||
/**
|
||||
* os_malloc - Allocate dynamic memory
|
||||
* @size: Size of the buffer to allocate
|
||||
* Returns: Allocated buffer or %NULL on failure
|
||||
*
|
||||
* Caller is responsible for freeing the returned buffer with os_free().
|
||||
*/
|
||||
void * os_malloc(size_t size);
|
||||
|
||||
/**
|
||||
* os_realloc - Re-allocate dynamic memory
|
||||
* @ptr: Old buffer from os_malloc() or os_realloc()
|
||||
* @size: Size of the new buffer
|
||||
* Returns: Allocated buffer or %NULL on failure
|
||||
*
|
||||
* Caller is responsible for freeing the returned buffer with os_free().
|
||||
* If re-allocation fails, %NULL is returned and the original buffer (ptr) is
|
||||
* not freed and caller is still responsible for freeing it.
|
||||
*/
|
||||
void * os_realloc(void *ptr, size_t size);
|
||||
|
||||
/**
|
||||
* os_free - Free dynamic memory
|
||||
* @ptr: Old buffer from os_malloc() or os_realloc(); can be %NULL
|
||||
*/
|
||||
void os_free(void *ptr);
|
||||
|
||||
/**
|
||||
* os_memcpy - Copy memory area
|
||||
* @dest: Destination
|
||||
* @src: Source
|
||||
* @n: Number of bytes to copy
|
||||
* Returns: dest
|
||||
*
|
||||
* The memory areas src and dst must not overlap. os_memmove() can be used with
|
||||
* overlapping memory.
|
||||
*/
|
||||
void * os_memcpy(void *dest, const void *src, size_t n);
|
||||
|
||||
/**
|
||||
* os_memmove - Copy memory area
|
||||
* @dest: Destination
|
||||
* @src: Source
|
||||
* @n: Number of bytes to copy
|
||||
* Returns: dest
|
||||
*
|
||||
* The memory areas src and dst may overlap.
|
||||
*/
|
||||
void *os_memmove(void *dest, const void *src, size_t n);
|
||||
|
||||
/**
|
||||
* os_memset - Fill memory with a constant byte
|
||||
* @s: Memory area to be filled
|
||||
* @c: Constant byte
|
||||
* @n: Number of bytes started from s to fill with c
|
||||
* Returns: s
|
||||
*/
|
||||
void *os_memset(void *s, int c, size_t n);
|
||||
|
||||
/**
|
||||
* os_memcmp - Compare memory areas
|
||||
* @s1: First buffer
|
||||
* @s2: Second buffer
|
||||
* @n: Maximum numbers of octets to compare
|
||||
* Returns: An integer less than, equal to, or greater than zero if s1 is
|
||||
* found to be less than, to match, or be greater than s2. Only first n
|
||||
* characters will be compared.
|
||||
*/
|
||||
int os_memcmp(const void *s1, const void *s2, size_t n);
|
||||
|
||||
/**
|
||||
* os_strdup - Duplicate a string
|
||||
* @s: Source string
|
||||
* Returns: Allocated buffer with the string copied into it or %NULL on failure
|
||||
*
|
||||
* Caller is responsible for freeing the returned buffer with os_free().
|
||||
*/
|
||||
char *os_strdup(const char *s);
|
||||
|
||||
/**
|
||||
* os_strlen - Calculate the length of a string
|
||||
* @s: '\0' terminated string
|
||||
* Returns: Number of characters in s (not counting the '\0' terminator)
|
||||
*/
|
||||
size_t os_strlen(const char *s);
|
||||
|
||||
/**
|
||||
* os_strcasecmp - Compare two strings ignoring case
|
||||
* @s1: First string
|
||||
* @s2: Second string
|
||||
* Returns: An integer less than, equal to, or greater than zero if s1 is
|
||||
* found to be less than, to match, or be greatred than s2
|
||||
*/
|
||||
int os_strcasecmp(const char *s1, const char *s2);
|
||||
|
||||
/**
|
||||
* os_strncasecmp - Compare two strings ignoring case
|
||||
* @s1: First string
|
||||
* @s2: Second string
|
||||
* @n: Maximum numbers of characters to compare
|
||||
* Returns: An integer less than, equal to, or greater than zero if s1 is
|
||||
* found to be less than, to match, or be greater than s2. Only first n
|
||||
* characters will be compared.
|
||||
*/
|
||||
int os_strncasecmp(const char *s1, const char *s2, size_t n);
|
||||
|
||||
/**
|
||||
* os_strchr - Locate the first occurrence of a character in string
|
||||
* @s: String
|
||||
* @c: Character to search for
|
||||
* Returns: Pointer to the matched character or %NULL if not found
|
||||
*/
|
||||
char *os_strchr(const char *s, int c);
|
||||
|
||||
/**
|
||||
* os_strrchr - Locate the last occurrence of a character in string
|
||||
* @s: String
|
||||
* @c: Character to search for
|
||||
* Returns: Pointer to the matched character or %NULL if not found
|
||||
*/
|
||||
char *os_strrchr(const char *s, int c);
|
||||
|
||||
/**
|
||||
* os_strcmp - Compare two strings
|
||||
* @s1: First string
|
||||
* @s2: Second string
|
||||
* Returns: An integer less than, equal to, or greater than zero if s1 is
|
||||
* found to be less than, to match, or be greatred than s2
|
||||
*/
|
||||
int os_strcmp(const char *s1, const char *s2);
|
||||
|
||||
/**
|
||||
* os_strncmp - Compare two strings
|
||||
* @s1: First string
|
||||
* @s2: Second string
|
||||
* @n: Maximum numbers of characters to compare
|
||||
* Returns: An integer less than, equal to, or greater than zero if s1 is
|
||||
* found to be less than, to match, or be greater than s2. Only first n
|
||||
* characters will be compared.
|
||||
*/
|
||||
int os_strncmp(const char *s1, const char *s2, size_t n);
|
||||
|
||||
/**
|
||||
* os_strncpy - Copy a string
|
||||
* @dest: Destination
|
||||
* @src: Source
|
||||
* @n: Maximum number of characters to copy
|
||||
* Returns: dest
|
||||
*/
|
||||
char *os_strncpy(char *dest, const char *src, size_t n);
|
||||
|
||||
/**
|
||||
* os_strstr - Locate a substring
|
||||
* @haystack: String (haystack) to search from
|
||||
* @needle: Needle to search from haystack
|
||||
* Returns: Pointer to the beginning of the substring or %NULL if not found
|
||||
*/
|
||||
char *os_strstr(const char *haystack, const char *needle);
|
||||
|
||||
/**
|
||||
* os_snprintf - Print to a memory buffer
|
||||
* @str: Memory buffer to print into
|
||||
* @size: Maximum length of the str buffer
|
||||
* @format: printf format
|
||||
* Returns: Number of characters printed (not including trailing '\0').
|
||||
*
|
||||
* If the output buffer is truncated, number of characters which would have
|
||||
* been written is returned. Since some C libraries return -1 in such a case,
|
||||
* the caller must be prepared on that value, too, to indicate truncation.
|
||||
*
|
||||
* Note: Some C library implementations of snprintf() may not guarantee null
|
||||
* termination in case the output is truncated. The OS wrapper function of
|
||||
* os_snprintf() should provide this guarantee, i.e., to null terminate the
|
||||
* output buffer if a C library version of the function is used and if that
|
||||
* function does not guarantee null termination.
|
||||
*
|
||||
* If the target system does not include snprintf(), see, e.g.,
|
||||
* http://www.ijs.si/software/snprintf/ for an example of a portable
|
||||
* implementation of snprintf.
|
||||
*/
|
||||
int os_snprintf(char *str, size_t size, const char *format, ...);
|
||||
|
||||
#else /* OS_NO_C_LIB_DEFINES */
|
||||
|
||||
#if !defined(CONFIG_PLATFORM_8195A) && !defined(CONFIG_PLATFORM_8711B)
|
||||
#ifdef CONFIG_MEM_MONITOR
|
||||
u8* os_malloc(u32 sz);
|
||||
void os_mfree(u8 *pbuf, u32 sz);
|
||||
#ifndef os_free
|
||||
#define os_free(p, sz) os_mfree(((u8*)(p)), (sz))
|
||||
#endif
|
||||
#else
|
||||
#ifndef os_malloc
|
||||
#define os_malloc(sz) _rtw_malloc(sz)
|
||||
#endif
|
||||
#ifndef os_free
|
||||
#define os_free(p, sz) _rtw_mfree(((u8*)(p)), (sz))
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
extern void *os_zalloc(size_t size);
|
||||
extern char *os_strdup(const char *string_copy_from);
|
||||
|
||||
#ifndef os_sleep
|
||||
#define os_sleep(s, us) rtw_mdelay_os((s)*1000 + (us)/1000)
|
||||
#endif
|
||||
#ifndef os_memcpy
|
||||
#define os_memcpy(d, s, n) rtw_memcpy((void*)(d), ((void*)(s)), (n))
|
||||
#endif
|
||||
#ifndef os_memmove
|
||||
#define os_memmove(d, s, n) memmove((d), (s), (n))
|
||||
#endif
|
||||
#ifndef os_memset
|
||||
#define os_memset(pbuf, c, sz) rtw_memset(pbuf, c, sz)
|
||||
#endif
|
||||
#ifndef os_memcmp
|
||||
#define os_memcmp(s1, s2, n) rtw_memcmp(((void*)(s1)), ((void*)(s2)), (n))
|
||||
#endif
|
||||
#ifndef os_memcmp_p2p
|
||||
#define os_memcmp_p2p(s1, s2, n) memcmp((s1), (s2), (n))
|
||||
#endif
|
||||
#ifndef os_get_random_bytes
|
||||
#define os_get_random_bytes(d,sz) rtw_get_random_bytes(((void*)(d)), (sz))
|
||||
#endif
|
||||
#ifndef os_strlen
|
||||
#define os_strlen(s) strlen(s)
|
||||
#endif
|
||||
#ifndef os_strcasecmp
|
||||
#ifdef _MSC_VER
|
||||
#define os_strcasecmp(s1, s2) _stricmp((s1), (s2))
|
||||
#else
|
||||
#define os_strcasecmp(s1, s2) strcasecmp((s1), (s2))
|
||||
#endif
|
||||
#endif
|
||||
#ifndef os_strncasecmp
|
||||
#ifdef _MSC_VER
|
||||
#define os_strncasecmp(s1, s2, n) _strnicmp((s1), (s2), (n))
|
||||
#else
|
||||
#define os_strncasecmp(s1, s2, n) strncasecmp((s1), (s2), (n))
|
||||
#endif
|
||||
#endif
|
||||
#ifndef os_init_timer
|
||||
#define os_init_timer(t, p, f, x, n) rtw_init_timer((t), (p), (f), (x), (n))
|
||||
#endif
|
||||
#ifndef os_set_timer
|
||||
#define os_set_timer(t, d) rtw_set_timer((t), (d))
|
||||
#endif
|
||||
#ifndef os_cancel_timer
|
||||
#define os_cancel_timer(t) rtw_cancel_timer(t)
|
||||
#endif
|
||||
#ifndef os_del_timer
|
||||
#define os_del_timer(t) rtw_del_timer(t)
|
||||
#endif
|
||||
#ifndef os_atoi
|
||||
#define os_atoi(s) rtw_atoi(s)
|
||||
#endif
|
||||
|
||||
#ifndef os_strchr
|
||||
#define os_strchr(s, c) strchr((s), (c))
|
||||
#endif
|
||||
#ifndef os_strcmp
|
||||
#define os_strcmp(s1, s2) strcmp((s1), (s2))
|
||||
#endif
|
||||
#ifndef os_strncmp
|
||||
#define os_strncmp(s1, s2, n) strncmp((s1), (s2), (n))
|
||||
#endif
|
||||
#ifndef os_strncpy
|
||||
#define os_strncpy(d, s, n) strncpy((d), (s), (n))
|
||||
#endif
|
||||
#ifndef os_strrchr
|
||||
#define os_strrchr(s, c) strrchr((s), (c))
|
||||
#endif
|
||||
#ifndef os_strstr
|
||||
#define os_strstr(h, n) strstr((h), (n))
|
||||
#endif
|
||||
|
||||
#ifndef os_snprintf
|
||||
#ifdef _MSC_VER
|
||||
#define os_snprintf _snprintf
|
||||
#else
|
||||
#define os_snprintf snprintf
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /* OS_NO_C_LIB_DEFINES */
|
||||
|
||||
|
||||
static inline void * os_realloc_array(void *ptr, size_t nmemb, size_t size)
|
||||
{
|
||||
if (size && nmemb > (~(size_t) 0) / size)
|
||||
return NULL;
|
||||
return os_realloc(ptr, nmemb * size, nmemb * size);
|
||||
}
|
||||
|
||||
void *os_xqueue_create(unsigned long uxQueueLength, unsigned long uxItemSize) ;
|
||||
|
||||
int os_xqueue_receive(xqueue_handle_t xQueue, void * const pvBuffer, unsigned long xSecsToWait);
|
||||
|
||||
void os_xqueue_delete(xqueue_handle_t xQueue );
|
||||
|
||||
int os_xqueue_send(xqueue_handle_t xQueue, const void * const pvItemToQueue, unsigned long xSecsToWait);
|
||||
|
||||
|
||||
#endif /* OS_H */
|
|
@ -0,0 +1,119 @@
|
|||
/*
|
||||
* OS specific functions for UNIX/POSIX systems
|
||||
* Copyright (c) 2005-2009, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This software may be distributed under the terms of the BSD license.
|
||||
* See README for more details.
|
||||
*/
|
||||
#include "utils/os.h"
|
||||
|
||||
//#ifdef CONFIG_WPS
|
||||
|
||||
#if !defined(CONFIG_PLATFORM_8195A) && !defined(CONFIG_PLATFORM_8711B)
|
||||
#ifdef CONFIG_MEM_MONITOR
|
||||
#if CONFIG_MEM_MONITOR & MEM_MONITOR_LEAK
|
||||
_list wpa_mem_table;
|
||||
int wpa_mem_used_num;
|
||||
//int wpa_mem_used_size;
|
||||
#endif
|
||||
extern int min_free_heap_size;
|
||||
u8* os_malloc(u32 sz)
|
||||
{
|
||||
int free_heap_size = rtw_getFreeHeapSize();
|
||||
u8 *pbuf = _rtw_malloc(sz);
|
||||
#if CONFIG_MEM_MONITOR & MEM_MONITOR_LEAK
|
||||
add_mem_usage(&wpa_mem_table, pbuf, sz, &wpa_mem_used_num, MEM_MONITOR_FLAG_WPAS);
|
||||
#else
|
||||
add_mem_usage(NULL, pbuf, sz, NULL, MEM_MONITOR_FLAG_WPAS);
|
||||
#endif
|
||||
if(min_free_heap_size > free_heap_size)
|
||||
min_free_heap_size = free_heap_size;
|
||||
return pbuf;
|
||||
}
|
||||
|
||||
void os_mfree(u8 *pbuf, u32 sz)
|
||||
{
|
||||
_rtw_mfree(pbuf, sz);
|
||||
#if CONFIG_MEM_MONITOR & MEM_MONITOR_LEAK
|
||||
del_mem_usage(&wpa_mem_table, pbuf, &wpa_mem_used_num, MEM_MONITOR_FLAG_WPAS);
|
||||
#else
|
||||
del_mem_usage(NULL, pbuf, NULL, MEM_MONITOR_FLAG_WPAS);
|
||||
#endif
|
||||
}
|
||||
#endif//CONFIG_MEM_MONITOR
|
||||
|
||||
#endif// !defined(CONFIG_PLATFORM_8195A)
|
||||
|
||||
#ifndef OS_NO_C_LIB_DEFINES
|
||||
char *os_strdup(const char *string_copy_from)
|
||||
{
|
||||
char *string_copy_to = NULL;
|
||||
string_copy_to = os_zalloc(strlen(string_copy_from) + 1);
|
||||
os_memcpy((void *)string_copy_to, string_copy_from, strlen(string_copy_from));
|
||||
string_copy_to[strlen(string_copy_from)] = '\0';
|
||||
return string_copy_to;
|
||||
}
|
||||
#endif
|
||||
|
||||
int os_get_random(unsigned char *buf, size_t len)
|
||||
{
|
||||
//TODO implement it
|
||||
rtw_get_random_bytes(buf, len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int os_get_time(struct os_time *t){
|
||||
unsigned int tt = rtw_get_current_time();
|
||||
t->sec = (os_time_t) (tt / 1000);
|
||||
t->usec = (os_time_t) (tt % 1000)*1000;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int os_get_reltime(struct os_reltime *t){
|
||||
os_get_time((struct os_time *)t);
|
||||
return 0;
|
||||
}
|
||||
#if 0
|
||||
void *os_xqueue_create(unsigned long uxQueueLength, unsigned long uxItemSize)
|
||||
{
|
||||
return xQueueCreate( uxQueueLength, uxItemSize );
|
||||
}
|
||||
|
||||
int os_xqueue_receive(xqueue_handle_t xQueue, void * const pvBuffer, unsigned long xSecsToWait)
|
||||
{
|
||||
return xQueueReceive((xQueueHandle)xQueue, pvBuffer, (portTickType)(xSecsToWait*configTICK_RATE_HZ));
|
||||
}
|
||||
|
||||
void os_xqueue_delete(xqueue_handle_t xQueue )
|
||||
{
|
||||
vQueueDelete((xQueueHandle)xQueue);
|
||||
}
|
||||
|
||||
int os_xqueue_send(xqueue_handle_t xQueue, const void * const pvItemToQueue, unsigned long xSecsToWait)
|
||||
{
|
||||
return xQueueSendToBack((xQueueHandle)xQueue, pvItemToQueue, (portTickType)(xSecsToWait*configTICK_RATE_HZ));
|
||||
}
|
||||
#else
|
||||
void *os_xqueue_create(unsigned long uxQueueLength, unsigned long uxItemSize)
|
||||
{
|
||||
void* xQueue = NULL;
|
||||
rtw_init_xqueue(&xQueue, "queue", uxItemSize, uxQueueLength);
|
||||
return xQueue;
|
||||
}
|
||||
|
||||
int os_xqueue_receive(xqueue_handle_t xQueue, void * const pvBuffer, unsigned long xSecsToWait)
|
||||
{
|
||||
return rtw_pop_from_xqueue(&xQueue, pvBuffer, xSecsToWait*1000);
|
||||
}
|
||||
|
||||
void os_xqueue_delete(xqueue_handle_t xQueue )
|
||||
{
|
||||
rtw_deinit_xqueue(&xQueue);
|
||||
}
|
||||
|
||||
int os_xqueue_send(xqueue_handle_t xQueue, const void * const pvItemToQueue, unsigned long xSecsToWait)
|
||||
{
|
||||
return rtw_push_to_xqueue(&xQueue, (void*)pvItemToQueue, xSecsToWait*1000);
|
||||
}
|
||||
#endif
|
||||
//#endif
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* OS specific functions
|
||||
* Copyright (c) 2005-2009, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This software may be distributed under the terms of the BSD license.
|
||||
* See README for more details.
|
||||
*/
|
||||
|
||||
#ifndef ROM_WPS_OS_H
|
||||
#define ROM_WPS_OS_H
|
||||
|
||||
#if defined(CONFIG_PLATFORM_8195A) || defined(CONFIG_PLATFORM_8711B)
|
||||
|
||||
#include <rom_wlan_ram_map.h>
|
||||
extern struct _rom_wlan_ram_map rom_wlan_ram_map;
|
||||
#define os_malloc(sz) rom_wlan_ram_map.rtw_malloc(sz)
|
||||
#define os_free(p, sz) rom_wlan_ram_map.rtw_mfree(((u8*)(p)), (sz))
|
||||
|
||||
#endif
|
||||
|
||||
extern u8 *WPS_realloc(u8 *old_buf, u32 old_sz, u32 new_sz);
|
||||
#define os_realloc(p, os, ns) WPS_realloc(((u8*)(p)),(os),(ns))
|
||||
|
||||
#endif /* ROM_WPS_OS_H */
|
319
component/common/api/wifi/rtw_wpa_supplicant/src/wps/wps_defs.h
Normal file
319
component/common/api/wifi/rtw_wpa_supplicant/src/wps/wps_defs.h
Normal file
|
@ -0,0 +1,319 @@
|
|||
|
||||
/*
|
||||
* Wi-Fi Protected Setup - message definitions
|
||||
* Copyright (c) 2008, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This software may be distributed under the terms of the BSD license.
|
||||
* See README for more details.
|
||||
*/
|
||||
|
||||
#ifndef WPS_DEFS_H
|
||||
#define WPS_DEFS_H
|
||||
|
||||
|
||||
/* Diffie-Hellman 1536-bit MODP Group; RFC 3526, Group 5 */
|
||||
#define WPS_DH_GROUP (5)
|
||||
|
||||
#define WPS_UUID_LEN (16)
|
||||
#define WPS_NONCE_LEN (16)
|
||||
#define WPS_AUTHENTICATOR_LEN (8)
|
||||
#define WPS_AUTHKEY_LEN (32)
|
||||
#define WPS_KEYWRAPKEY_LEN (16)
|
||||
#define WPS_EMSK_LEN (32)
|
||||
#define WPS_PSK_LEN (16)
|
||||
#define WPS_SECRET_NONCE_LEN (16)
|
||||
#define WPS_HASH_LEN (32)
|
||||
#define WPS_KWA_LEN (8)
|
||||
#define WPS_MGMTAUTHKEY_LEN (32)
|
||||
#define WPS_MGMTENCKEY_LEN (16)
|
||||
#define WPS_MGMT_KEY_ID_LEN (16)
|
||||
#define WPS_OOB_DEVICE_PASSWORD_MIN_LEN (16)
|
||||
#define WPS_OOB_DEVICE_PASSWORD_LEN (32)
|
||||
#define WPS_OOB_PUBKEY_HASH_LEN (20)
|
||||
|
||||
/* Attribute Types */
|
||||
enum wps_attribute {
|
||||
ATTR_AP_CHANNEL = 0x1001,
|
||||
ATTR_ASSOC_STATE = 0x1002,
|
||||
ATTR_AUTH_TYPE = 0x1003,
|
||||
ATTR_AUTH_TYPE_FLAGS = 0x1004,
|
||||
ATTR_AUTHENTICATOR = 0x1005,
|
||||
ATTR_CONFIG_METHODS = 0x1008,
|
||||
ATTR_CONFIG_ERROR = 0x1009,
|
||||
ATTR_CONFIRM_URL4 = 0x100a,
|
||||
ATTR_CONFIRM_URL6 = 0x100b,
|
||||
ATTR_CONN_TYPE = 0x100c,
|
||||
ATTR_CONN_TYPE_FLAGS = 0x100d,
|
||||
ATTR_CRED = 0x100e,
|
||||
ATTR_ENCR_TYPE = 0x100f,
|
||||
ATTR_ENCR_TYPE_FLAGS = 0x1010,
|
||||
ATTR_DEV_NAME = 0x1011,
|
||||
ATTR_DEV_PASSWORD_ID = 0x1012,
|
||||
ATTR_E_HASH1 = 0x1014,
|
||||
ATTR_E_HASH2 = 0x1015,
|
||||
ATTR_E_SNONCE1 = 0x1016,
|
||||
ATTR_E_SNONCE2 = 0x1017,
|
||||
ATTR_ENCR_SETTINGS = 0x1018,
|
||||
ATTR_ENROLLEE_NONCE = 0x101a,
|
||||
ATTR_FEATURE_ID = 0x101b,
|
||||
ATTR_IDENTITY = 0x101c,
|
||||
ATTR_IDENTITY_PROOF = 0x101d,
|
||||
ATTR_KEY_WRAP_AUTH = 0x101e,
|
||||
ATTR_KEY_ID = 0x101f,
|
||||
ATTR_MAC_ADDR = 0x1020,
|
||||
ATTR_MANUFACTURER = 0x1021,
|
||||
ATTR_MSG_TYPE = 0x1022,
|
||||
ATTR_MODEL_NAME = 0x1023,
|
||||
ATTR_MODEL_NUMBER = 0x1024,
|
||||
ATTR_NETWORK_INDEX = 0x1026,
|
||||
ATTR_NETWORK_KEY = 0x1027,
|
||||
ATTR_NETWORK_KEY_INDEX = 0x1028,
|
||||
ATTR_NEW_DEVICE_NAME = 0x1029,
|
||||
ATTR_NEW_PASSWORD = 0x102a,
|
||||
ATTR_OOB_DEVICE_PASSWORD = 0x102c,
|
||||
ATTR_OS_VERSION = 0x102d,
|
||||
ATTR_POWER_LEVEL = 0x102f,
|
||||
ATTR_PSK_CURRENT = 0x1030,
|
||||
ATTR_PSK_MAX = 0x1031,
|
||||
ATTR_PUBLIC_KEY = 0x1032,
|
||||
ATTR_RADIO_ENABLE = 0x1033,
|
||||
ATTR_REBOOT = 0x1034,
|
||||
ATTR_REGISTRAR_CURRENT = 0x1035,
|
||||
ATTR_REGISTRAR_ESTABLISHED = 0x1036,
|
||||
ATTR_REGISTRAR_LIST = 0x1037,
|
||||
ATTR_REGISTRAR_MAX = 0x1038,
|
||||
ATTR_REGISTRAR_NONCE = 0x1039,
|
||||
ATTR_REQUEST_TYPE = 0x103a,
|
||||
ATTR_RESPONSE_TYPE = 0x103b,
|
||||
ATTR_RF_BANDS = 0x103c,
|
||||
ATTR_R_HASH1 = 0x103d,
|
||||
ATTR_R_HASH2 = 0x103e,
|
||||
ATTR_R_SNONCE1 = 0x103f,
|
||||
ATTR_R_SNONCE2 = 0x1040,
|
||||
ATTR_SELECTED_REGISTRAR = 0x1041,
|
||||
ATTR_SERIAL_NUMBER = 0x1042,
|
||||
ATTR_WPS_STATE = 0x1044,
|
||||
ATTR_SSID = 0x1045,
|
||||
ATTR_TOTAL_NETWORKS = 0x1046,
|
||||
ATTR_UUID_E = 0x1047,
|
||||
ATTR_UUID_R = 0x1048,
|
||||
ATTR_VENDOR_EXT = 0x1049,
|
||||
ATTR_VERSION = 0x104a,
|
||||
ATTR_X509_CERT_REQ = 0x104b,
|
||||
ATTR_X509_CERT = 0x104c,
|
||||
ATTR_EAP_IDENTITY = 0x104d,
|
||||
ATTR_MSG_COUNTER = 0x104e,
|
||||
ATTR_PUBKEY_HASH = 0x104f,
|
||||
ATTR_REKEY_KEY = 0x1050,
|
||||
ATTR_KEY_LIFETIME = 0x1051,
|
||||
ATTR_PERMITTED_CFG_METHODS = 0x1052,
|
||||
ATTR_SELECTED_REGISTRAR_CONFIG_METHODS = 0x1053,
|
||||
ATTR_PRIMARY_DEV_TYPE = 0x1054,
|
||||
ATTR_SECONDARY_DEV_TYPE_LIST = 0x1055,
|
||||
ATTR_PORTABLE_DEV = 0x1056,
|
||||
ATTR_AP_SETUP_LOCKED = 0x1057,
|
||||
ATTR_APPLICATION_EXT = 0x1058,
|
||||
ATTR_EAP_TYPE = 0x1059,
|
||||
ATTR_IV = 0x1060,
|
||||
ATTR_KEY_PROVIDED_AUTO = 0x1061,
|
||||
ATTR_802_1X_ENABLED = 0x1062,
|
||||
ATTR_APPSESSIONKEY = 0x1063,
|
||||
ATTR_WEPTRANSMITKEY = 0x1064,
|
||||
ATTR_REQUESTED_DEV_TYPE = 0x106a,
|
||||
ATTR_EXTENSIBILITY_TEST = 0x10fa /* _NOT_ defined in the spec */
|
||||
};
|
||||
|
||||
#define WPS_VENDOR_ID_WFA 14122
|
||||
|
||||
/* WFA Vendor Extension subelements */
|
||||
enum {
|
||||
WFA_ELEM_VERSION2 = 0x00,
|
||||
WFA_ELEM_AUTHORIZEDMACS = 0x01,
|
||||
WFA_ELEM_NETWORK_KEY_SHAREABLE = 0x02,
|
||||
WFA_ELEM_REQUEST_TO_ENROLL = 0x03,
|
||||
WFA_ELEM_SETTINGS_DELAY_TIME = 0x04
|
||||
};
|
||||
|
||||
/* Device Password ID */
|
||||
enum wps_dev_password_id {
|
||||
DEV_PW_DEFAULT = 0x0000,
|
||||
DEV_PW_USER_SPECIFIED = 0x0001,
|
||||
DEV_PW_MACHINE_SPECIFIED = 0x0002,
|
||||
DEV_PW_REKEY = 0x0003,
|
||||
DEV_PW_PUSHBUTTON = 0x0004,
|
||||
DEV_PW_REGISTRAR_SPECIFIED = 0x0005
|
||||
};
|
||||
|
||||
/* Message Type */
|
||||
enum wps_msg_type {
|
||||
WPS_START = 0x00,
|
||||
WPS_Beacon = 0x01,
|
||||
WPS_ProbeRequest = 0x02,
|
||||
WPS_ProbeResponse = 0x03,
|
||||
WPS_M1 = 0x04,
|
||||
WPS_M2 = 0x05,
|
||||
WPS_M2D = 0x06,
|
||||
WPS_M3 = 0x07,
|
||||
WPS_M4 = 0x08,
|
||||
WPS_M5 = 0x09,
|
||||
WPS_M6 = 0x0a,
|
||||
WPS_M7 = 0x0b,
|
||||
WPS_M8 = 0x0c,
|
||||
WPS_WSC_ACK = 0x0d,
|
||||
WPS_WSC_NACK = 0x0e,
|
||||
WPS_WSC_DONE = 0x0f
|
||||
};
|
||||
|
||||
/* Authentication Type Flags */
|
||||
#define WPS_AUTH_OPEN 0x0001
|
||||
#define WPS_AUTH_WPAPSK 0x0002
|
||||
#define WPS_AUTH_SHARED 0x0004
|
||||
#define WPS_AUTH_WPA 0x0008
|
||||
#define WPS_AUTH_WPA2 0x0010
|
||||
#define WPS_AUTH_WPA2PSK 0x0020
|
||||
#define WPS_AUTH_TYPES (WPS_AUTH_OPEN | WPS_AUTH_WPAPSK | WPS_AUTH_SHARED | \
|
||||
WPS_AUTH_WPA | WPS_AUTH_WPA2 | WPS_AUTH_WPA2PSK)
|
||||
|
||||
/* Encryption Type Flags */
|
||||
#define WPS_ENCR_NONE 0x0001
|
||||
#define WPS_ENCR_WEP 0x0002
|
||||
#define WPS_ENCR_TKIP 0x0004
|
||||
#define WPS_ENCR_AES 0x0008
|
||||
#define WPS_ENCR_TYPES (WPS_ENCR_NONE | WPS_ENCR_WEP | WPS_ENCR_TKIP | \
|
||||
WPS_ENCR_AES)
|
||||
|
||||
/* Configuration Error */
|
||||
enum wps_config_error {
|
||||
WPS_CFG_NO_ERROR = 0,
|
||||
WPS_CFG_OOB_IFACE_READ_ERROR = 1,
|
||||
WPS_CFG_DECRYPTION_CRC_FAILURE = 2,
|
||||
WPS_CFG_24_CHAN_NOT_SUPPORTED = 3,
|
||||
WPS_CFG_50_CHAN_NOT_SUPPORTED = 4,
|
||||
WPS_CFG_SIGNAL_TOO_WEAK = 5,
|
||||
WPS_CFG_NETWORK_AUTH_FAILURE = 6,
|
||||
WPS_CFG_NETWORK_ASSOC_FAILURE = 7,
|
||||
WPS_CFG_NO_DHCP_RESPONSE = 8,
|
||||
WPS_CFG_FAILED_DHCP_CONFIG = 9,
|
||||
WPS_CFG_IP_ADDR_CONFLICT = 10,
|
||||
WPS_CFG_NO_CONN_TO_REGISTRAR = 11,
|
||||
WPS_CFG_MULTIPLE_PBC_DETECTED = 12,
|
||||
WPS_CFG_ROGUE_SUSPECTED = 13,
|
||||
WPS_CFG_DEVICE_BUSY = 14,
|
||||
WPS_CFG_SETUP_LOCKED = 15,
|
||||
WPS_CFG_MSG_TIMEOUT = 16,
|
||||
WPS_CFG_REG_SESS_TIMEOUT = 17,
|
||||
WPS_CFG_DEV_PASSWORD_AUTH_FAILURE = 18
|
||||
};
|
||||
|
||||
/* RF Bands */
|
||||
#define WPS_RF_24GHZ (0x01)
|
||||
#define WPS_RF_50GHZ (0x02)
|
||||
|
||||
/* Config Methods */
|
||||
#define WPS_CONFIG_USBA (0x0001)
|
||||
#define WPS_CONFIG_ETHERNET (0x0002)
|
||||
#define WPS_CONFIG_LABEL (0x0004)
|
||||
#define WPS_CONFIG_DISPLAY (0x0008)
|
||||
#define WPS_CONFIG_EXT_NFC_TOKEN (0x0010)
|
||||
#define WPS_CONFIG_INT_NFC_TOKEN (0x0020)
|
||||
#define WPS_CONFIG_NFC_INTERFACE (0x0040)
|
||||
#define WPS_CONFIG_PUSHBUTTON (0x0080)
|
||||
#define WPS_CONFIG_KEYPAD (0x0100)
|
||||
|
||||
#ifdef CONFIG_WPS2
|
||||
#define WPS_CONFIG_VIRT_PUSHBUTTON (0x0280)
|
||||
#define WPS_CONFIG_PHY_PUSHBUTTON (0x0480)
|
||||
#define WPS_CONFIG_VIRT_DISPLAY (0x2008)
|
||||
#define WPS_CONFIG_PHY_DISPLAY (0x4008)
|
||||
#endif /* CONFIG_WPS2 */
|
||||
|
||||
/* Connection Type Flags */
|
||||
#define WPS_CONN_ESS (0x01)
|
||||
#define WPS_CONN_IBSS (0x02)
|
||||
|
||||
/* Wi-Fi Protected Setup State */
|
||||
enum wps_state {
|
||||
WPS_STATE_NOT_CONFIGURED = 1,
|
||||
WPS_STATE_CONFIGURED = 2
|
||||
};
|
||||
|
||||
/* Association State */
|
||||
enum wps_assoc_state {
|
||||
WPS_ASSOC_NOT_ASSOC = 0,
|
||||
WPS_ASSOC_CONN_SUCCESS = 1,
|
||||
WPS_ASSOC_CFG_FAILURE = 2,
|
||||
WPS_ASSOC_FAILURE = 3,
|
||||
WPS_ASSOC_IP_FAILURE = 4
|
||||
};
|
||||
|
||||
|
||||
#define WPS_DEV_OUI_WFA (0x0050f204)
|
||||
|
||||
enum wps_dev_categ {
|
||||
WPS_DEV_COMPUTER = 1,
|
||||
WPS_DEV_INPUT = 2,
|
||||
WPS_DEV_PRINTER = 3,
|
||||
WPS_DEV_CAMERA = 4,
|
||||
WPS_DEV_STORAGE = 5,
|
||||
WPS_DEV_NETWORK_INFRA = 6,
|
||||
WPS_DEV_DISPLAY = 7,
|
||||
WPS_DEV_MULTIMEDIA = 8,
|
||||
WPS_DEV_GAMING = 9,
|
||||
WPS_DEV_PHONE = 10
|
||||
};
|
||||
|
||||
enum wps_dev_subcateg {
|
||||
WPS_DEV_COMPUTER_PC = 1,
|
||||
WPS_DEV_COMPUTER_SERVER = 2,
|
||||
WPS_DEV_COMPUTER_MEDIA_CENTER = 3,
|
||||
|
||||
WPS_DEV_PRINTER_PRINTER = 1,
|
||||
WPS_DEV_PRINTER_SCANNER = 2,
|
||||
|
||||
WPS_DEV_CAMERA_DIGITAL_STILL_CAMERA = 1,
|
||||
|
||||
WPS_DEV_STORAGE_NAS = 1,
|
||||
|
||||
WPS_DEV_NETWORK_INFRA_AP = 1,
|
||||
WPS_DEV_NETWORK_INFRA_ROUTER = 2,
|
||||
WPS_DEV_NETWORK_INFRA_SWITCH = 3,
|
||||
|
||||
WPS_DEV_DISPLAY_TV = 1,
|
||||
WPS_DEV_DISPLAY_PICTURE_FRAME = 2,
|
||||
WPS_DEV_DISPLAY_PROJECTOR = 3,
|
||||
|
||||
WPS_DEV_MULTIMEDIA_DAR = 1,
|
||||
WPS_DEV_MULTIMEDIA_PVR = 2,
|
||||
WPS_DEV_MULTIMEDIA_MCX = 3,
|
||||
|
||||
WPS_DEV_GAMING_XBOX = 1,
|
||||
WPS_DEV_GAMING_XBOX360 = 2,
|
||||
WPS_DEV_GAMING_PLAYSTATION = 3,
|
||||
|
||||
WPS_DEV_PHONE_WINDOWS_MOBILE = 1
|
||||
};
|
||||
|
||||
|
||||
/* Request Type */
|
||||
enum wps_request_type {
|
||||
WPS_REQ_ENROLLEE_INFO = 0,
|
||||
WPS_REQ_ENROLLEE = 1,
|
||||
WPS_REQ_REGISTRAR = 2,
|
||||
WPS_REQ_WLAN_MANAGER_REGISTRAR = 3
|
||||
};
|
||||
|
||||
/* Response Type */
|
||||
enum wps_response_type {
|
||||
WPS_RESP_ENROLLEE_INFO = 0,
|
||||
WPS_RESP_ENROLLEE = 1,
|
||||
WPS_RESP_REGISTRAR = 2,
|
||||
WPS_RESP_AP = 3
|
||||
};
|
||||
|
||||
/* Walk Time for push button configuration (in seconds) */
|
||||
#define WPS_PBC_WALK_TIME (120)
|
||||
|
||||
#define WPS_MAX_AUTHORIZED_MACS (5)
|
||||
|
||||
#endif /* WPS_DEFS_H */
|
||||
|
|
@ -0,0 +1,450 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "main.h"
|
||||
#include "queue.h"
|
||||
#include "utils/os.h"
|
||||
#include <lwip_netconf.h>
|
||||
#include <lwip/netif.h>
|
||||
#include "wifi/wifi_conf.h"
|
||||
#include <platform/platform_stdlib.h>
|
||||
#include <polarssl/ssl.h>
|
||||
#include <polarssl/memory.h>
|
||||
|
||||
#define WLAN0_NAME "wlan0"
|
||||
#ifndef ENABLE
|
||||
#define ENABLE (1)
|
||||
#endif
|
||||
#ifndef DISABLE
|
||||
#define DISABLE (0)
|
||||
#endif
|
||||
|
||||
u8 eap_phase = 0;
|
||||
u8 eap_method = 0;
|
||||
|
||||
// eap config arguments
|
||||
char *eap_target_ssid = NULL;
|
||||
char *eap_identity = NULL;
|
||||
char *eap_password = NULL;
|
||||
// if set eap_ca_cert and defined(EAP_SSL_VERIFY_SERVER), client will verify server's cert
|
||||
const unsigned char *eap_ca_cert = NULL;
|
||||
// if set eap_client_cert, eap_client_key, and defined(EAP_SSL_VERIFY_CLIENT), client will send its cert to server
|
||||
const unsigned char *eap_client_cert = NULL;
|
||||
const unsigned char *eap_client_key = NULL;
|
||||
char *eap_client_key_pwd = NULL;
|
||||
|
||||
int max_buf_bio_size = SSL_BUFFER_LEN;
|
||||
|
||||
void eap_eapol_recvd_hdl(char *buf, int buf_len, int flags, void* handler_user_data);
|
||||
void eap_eapol_start_hdl(char *buf, int buf_len, int flags, void* handler_user_data);
|
||||
|
||||
void set_eap_phase(unsigned char is_trigger_eap){
|
||||
eap_phase = is_trigger_eap;
|
||||
}
|
||||
|
||||
int get_eap_phase(void){
|
||||
return eap_phase;
|
||||
}
|
||||
|
||||
int get_eap_method(void){
|
||||
return eap_method;
|
||||
}
|
||||
|
||||
void reset_config(void){
|
||||
eap_target_ssid = NULL;
|
||||
eap_identity = NULL;
|
||||
eap_password = NULL;
|
||||
eap_ca_cert = NULL;
|
||||
eap_client_cert = NULL;
|
||||
eap_client_key = NULL;
|
||||
eap_client_key_pwd = NULL;
|
||||
}
|
||||
|
||||
void judge_station_disconnect(void)
|
||||
{
|
||||
int mode = 0;
|
||||
unsigned char ssid[33];
|
||||
|
||||
wext_get_mode(WLAN0_NAME, &mode);
|
||||
|
||||
switch(mode) {
|
||||
case IW_MODE_MASTER: //In AP mode
|
||||
wifi_off();
|
||||
vTaskDelay(20);
|
||||
wifi_on(RTW_MODE_STA);
|
||||
break;
|
||||
case IW_MODE_INFRA: //In STA mode
|
||||
if(wext_get_ssid(WLAN0_NAME, ssid) > 0)
|
||||
wifi_disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
void eap_disconnected_hdl(char *buf, int buf_len, int flags, void* handler_user_data){
|
||||
// printf("disconnected\n");
|
||||
wifi_unreg_event_handler(WIFI_EVENT_EAPOL_RECVD, eap_eapol_recvd_hdl);
|
||||
wifi_unreg_event_handler(WIFI_EVENT_DISCONNECT, eap_disconnected_hdl);
|
||||
eap_peer_unregister_methods();
|
||||
eap_sm_deinit();
|
||||
//reset_config();
|
||||
}
|
||||
|
||||
/*
|
||||
void eap_config(void){
|
||||
eap_target_ssid = "Test_eap";
|
||||
eap_identity = "guest2";
|
||||
eap_password = "test2";
|
||||
|
||||
eap_client_cert = \
|
||||
"-----BEGIN CERTIFICATE-----\r\n" \
|
||||
"MIIC9zCCAd8CAQMwDQYJKoZIhvcNAQEEBQAwgZMxCzAJBgNVBAYTAkZSMQ8wDQYD\r\n" \
|
||||
"VQQIEwZSYWRpdXMxEjAQBgNVBAcTCVNvbWV3aGVyZTEVMBMGA1UEChMMRXhhbXBs\r\n" \
|
||||
"ZSBJbmMuMSAwHgYJKoZIhvcNAQkBFhFhZG1pbkBleGFtcGxlLmNvbTEmMCQGA1UE\r\n" \
|
||||
"AxMdRXhhbXBsZSBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkwHhcNMTYwMzE1MDgwNzEx\r\n" \
|
||||
"WhcNMTcwMzE1MDgwNzExWjBzMQswCQYDVQQGEwJGUjEPMA0GA1UECBMGUmFkaXVz\r\n" \
|
||||
"MRUwEwYDVQQKEwxFeGFtcGxlIEluYy4xGjAYBgNVBAMUEXVzZXIyQGV4YW1wbGUu\r\n" \
|
||||
"Y29tMSAwHgYJKoZIhvcNAQkBFhF1c2VyMkBleGFtcGxlLmNvbTCBnzANBgkqhkiG\r\n" \
|
||||
"9w0BAQEFAAOBjQAwgYkCgYEAqESlV4OYfBcIgZ+Cs8mWpiBjhvKoa0/kIe7saqhC\r\n" \
|
||||
"e5q4snox0jdkUpLcc4vOs3vQ7ZGnimqTltA9oF6XNUzTWW4vlJTKEfrCWK085l7c\r\n" \
|
||||
"DHFvHavH3E6vuP71lI7jq4PLXbo2TvZK+uBul4ozjzVWihaZBtz8eLHq446h/D/p\r\n" \
|
||||
"kzkCAwEAATANBgkqhkiG9w0BAQQFAAOCAQEAAfhVAIkNdeeUNJud720uUHVnIcxz\r\n" \
|
||||
"GXWI+Svi1qchuTEnRNhLwXmnE+A0WWSHyfdR6FvzdT3xtz3K50iOif8jY2gCGkSK\r\n" \
|
||||
"8RjKr97228SwbrGO9y9+dYIjH1uz9cBpoVKcpzdsWpKObrDPDYyReHSWo99jM2+O\r\n" \
|
||||
"vfJxnBw4PLiBj7Q0/dpd6o4JXyp7Cxa0mB4/+cZqjCzzuKfuK3WP7j6laMCV6mg4\r\n" \
|
||||
"wRZ528IdwDqB7OOqsDm1PVQM8vzny9PM6ikWUCRTVNQJN8RDLkrHR3FRjy15YLdt\r\n" \
|
||||
"yOfDqVnT/z0wGBaxnNziSJjqPGHPpRi4bJFGXwXOhtknKmciKzfj9/npoQ==\r\n" \
|
||||
"-----END CERTIFICATE-----\r\n";
|
||||
|
||||
eap_client_key = \
|
||||
"-----BEGIN RSA PRIVATE KEY-----\r\n" \
|
||||
"MIICXQIBAAKBgQCoRKVXg5h8FwiBn4KzyZamIGOG8qhrT+Qh7uxqqEJ7mriyejHS\r\n" \
|
||||
"N2RSktxzi86ze9DtkaeKapOW0D2gXpc1TNNZbi+UlMoR+sJYrTzmXtwMcW8dq8fc\r\n" \
|
||||
"Tq+4/vWUjuOrg8tdujZO9kr64G6XijOPNVaKFpkG3Px4serjjqH8P+mTOQIDAQAB\r\n" \
|
||||
"AoGARI+LyweshssfxSkIKVc3EcNaqi6PHwJzUrw2ChM624AkR1xwllXJg7ehKVdK\r\n" \
|
||||
"xmjprRLO8CASuL1qjsBb3fTKnBl+sIVxIFS0AI4Y3ri8VUKbangvSsI7pCzAFry7\r\n" \
|
||||
"p1gmy9WWRV2ZEa+dV8xcrjb3bloT7hcdeLehgBCvExJIQM0CQQDXlSAKdW3AhYyj\r\n" \
|
||||
"1A+pfyBSGxJbpSwNyyWgwHIHHjxendxmdUbrc8EbAu1eNKbP58TLgdCZsKcMonAv\r\n" \
|
||||
"MY1Y2/nnAkEAx9CrUaCU8pJqXTRypM5JtexLKnYMJhpnA9uUILBQOq4Oe0eruyF5\r\n" \
|
||||
"SaSxhyJYXY491ahWYPF0PTb3jkUhoN+l3wJBAJZthjgGDJlEFwjSFkOtYz4nib3N\r\n" \
|
||||
"GVpeoFj1MBvrazCScpJDz0LIOLzCZCNSFfwIu3dNk+NKMqZMSn+D0h9pD40CQQC5\r\n" \
|
||||
"K9n4NXaTLbjAU2CC9mE85JPr76XmkcUxwAWQHZTcLH1jJdIyAx1hb+zNLLjzSmRn\r\n" \
|
||||
"Yi9ae6ibKhtUjyBQ87HFAkA2Bb3z7NUx+AA2g2HZocFZFShBxylACyQkl8FAFZtf\r\n" \
|
||||
"osudmKdFQHyAWuBMex4tpz/OLTqJ1ecL1JQeC7OvlpEX\r\n" \
|
||||
"-----END RSA PRIVATE KEY-----\r\n";
|
||||
|
||||
eap_ca_cert = \
|
||||
"-----BEGIN CERTIFICATE-----\r\n" \
|
||||
"MIIEpzCCA4+gAwIBAgIJAPvZaozpdfjkMA0GCSqGSIb3DQEBCwUAMIGTMQswCQYD\r\n" \
|
||||
"VQQGEwJGUjEPMA0GA1UECBMGUmFkaXVzMRIwEAYDVQQHEwlTb21ld2hlcmUxFTAT\r\n" \
|
||||
"BgNVBAoTDEV4YW1wbGUgSW5jLjEgMB4GCSqGSIb3DQEJARYRYWRtaW5AZXhhbXBs\r\n" \
|
||||
"ZS5jb20xJjAkBgNVBAMTHUV4YW1wbGUgQ2VydGlmaWNhdGUgQXV0aG9yaXR5MB4X\r\n" \
|
||||
"DTE2MDMxNDExMjU0OVoXDTE2MDQxMzExMjU0OVowgZMxCzAJBgNVBAYTAkZSMQ8w\r\n" \
|
||||
"DQYDVQQIEwZSYWRpdXMxEjAQBgNVBAcTCVNvbWV3aGVyZTEVMBMGA1UEChMMRXhh\r\n" \
|
||||
"bXBsZSBJbmMuMSAwHgYJKoZIhvcNAQkBFhFhZG1pbkBleGFtcGxlLmNvbTEmMCQG\r\n" \
|
||||
"A1UEAxMdRXhhbXBsZSBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkwggEiMA0GCSqGSIb3\r\n" \
|
||||
"DQEBAQUAA4IBDwAwggEKAoIBAQC9pireu0aCDLNfMaGv3vId7RXjUhQwSK0jV2Oc\r\n" \
|
||||
"SyvlKWH3P/N+5kLrP2iL6SCzyETVDXZ0vOsAMjcBF0zHp16prXV0d51cTUqeWBb0\r\n" \
|
||||
"I5UnGxleIuuOfSg8zLUJoBWZPqLv++eZ5WgOKHt7SXocjvg7TU5t/TMB0Y8OCz3H\r\n" \
|
||||
"CW2vJ/XKMgMA9HDUu4g57cJu88i1JPRpyFaz/HIQBc7+UNb9z+q09uTZKWTmEMqi\r\n" \
|
||||
"E2U0EEIs7EtbxnOze1/8C4XNlmztrEdwvu6UEBU/TFkUoh9M646NkkBK7wP9n9pv\r\n" \
|
||||
"T0nPQRJiiCrICzVqUtlEi9lIKpbBSMbQ0KzrGF7lGTgm4rz9AgMBAAGjgfswgfgw\r\n" \
|
||||
"HQYDVR0OBBYEFIVyecka74kvOKIW0BjlTc/B+a2NMIHIBgNVHSMEgcAwgb2AFIVy\r\n" \
|
||||
"ecka74kvOKIW0BjlTc/B+a2NoYGZpIGWMIGTMQswCQYDVQQGEwJGUjEPMA0GA1UE\r\n" \
|
||||
"CBMGUmFkaXVzMRIwEAYDVQQHEwlTb21ld2hlcmUxFTATBgNVBAoTDEV4YW1wbGUg\r\n" \
|
||||
"SW5jLjEgMB4GCSqGSIb3DQEJARYRYWRtaW5AZXhhbXBsZS5jb20xJjAkBgNVBAMT\r\n" \
|
||||
"HUV4YW1wbGUgQ2VydGlmaWNhdGUgQXV0aG9yaXR5ggkA+9lqjOl1+OQwDAYDVR0T\r\n" \
|
||||
"BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAZYHM26sxbKOckVqJJ1QY0U2QFlGP\r\n" \
|
||||
"1GYd8v27znxdnRmSonDvv3GjFfhwoyDk0JUuxkK/33ikCxihrgoO/EQTY9BV2OpW\r\n" \
|
||||
"qkB1PDtb3i5ZRNvfjmW0pVA4p+GmdTGaEE5pTlcVnorzVrUeFKaZakb+IDFYzmeF\r\n" \
|
||||
"xp8B3Bb5wvinDligLOaJnSlgS8QeeIab9HZfaVTTuPmVK6zE6D54Y0dJPnykvDdE\r\n" \
|
||||
"cGN0FC+migfilFjJgkDJ0r78nwes55L8zjoofiZuO03rrHww6ARc3v1jYzAufddk\r\n" \
|
||||
"QTiZHgjlMQb2XXMmXLn8kBgoDnqkXFNe8j0h8uxIJSrjOoIyn1h1wvX5/w==\r\n" \
|
||||
"-----END CERTIFICATE-----\r\n";
|
||||
}
|
||||
*/
|
||||
|
||||
int eap_start(char *method){
|
||||
#ifdef CONFIG_ENABLE_EAP
|
||||
int ret = -1;
|
||||
|
||||
//unsigned long tick1 = xTaskGetTickCount();
|
||||
//unsigned long tick2;
|
||||
|
||||
if(rltk_wlan_running(WLAN1_IDX)){
|
||||
printf("\n\rNot support con-current mode!\n\r");
|
||||
return -1;
|
||||
}
|
||||
|
||||
judge_station_disconnect();
|
||||
|
||||
#if CONFIG_ENABLE_PEAP
|
||||
if(strcmp(method,"peap") == 0){
|
||||
ret = set_eap_peap_method();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CONFIG_ENABLE_TLS
|
||||
if(strcmp(method,"tls") == 0){
|
||||
ret = set_eap_tls_method();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CONFIG_ENABLE_TTLS
|
||||
if(strcmp(method,"ttls") == 0){
|
||||
ret = set_eap_ttls_method();
|
||||
}
|
||||
#endif
|
||||
|
||||
if(ret == -1){
|
||||
printf("\r\neap method %s not supported\r\n", method);
|
||||
return -1;
|
||||
}
|
||||
|
||||
eap_method = get_eap_ctx_method();
|
||||
|
||||
printf("\n==================== %s_start ====================\n", method);
|
||||
|
||||
//eap_config();
|
||||
|
||||
set_eap_phase(ENABLE);
|
||||
wifi_reg_event_handler(WIFI_EVENT_EAPOL_START, eap_eapol_start_hdl, NULL);
|
||||
wifi_reg_event_handler(WIFI_EVENT_EAPOL_RECVD, eap_eapol_recvd_hdl, NULL);
|
||||
|
||||
|
||||
|
||||
ret = connect_by_open_system(eap_target_ssid);
|
||||
|
||||
#if CONFIG_LWIP_LAYER
|
||||
/* Start DHCPClient */
|
||||
if(ret == 0)
|
||||
LwIP_DHCP(0, DHCP_START);
|
||||
#endif
|
||||
|
||||
wifi_unreg_event_handler(WIFI_EVENT_EAPOL_START, eap_eapol_start_hdl);
|
||||
|
||||
// for re-authentication when session timeout
|
||||
wifi_reg_event_handler(WIFI_EVENT_DISCONNECT, eap_disconnected_hdl, NULL);
|
||||
//wifi_unreg_event_handler(WIFI_EVENT_EAPOL_RECVD, eap_eapol_recvd_hdl);
|
||||
|
||||
set_eap_phase(DISABLE);
|
||||
|
||||
// eap failed, disconnect
|
||||
if(ret != 0){
|
||||
judge_station_disconnect();
|
||||
eap_disconnected_hdl(NULL, 0, 0, NULL);
|
||||
rtw_msleep_os(200); //wait handler done
|
||||
printf("\r\nERROR: connect to AP by %s failed\n", method);
|
||||
}
|
||||
|
||||
eap_sm_deinit();
|
||||
printf("\n==================== %s_finish ====================\n", method);
|
||||
|
||||
//tick2 = xTaskGetTickCount();
|
||||
//printf("\r\nConnected after %dms.\n", (tick2-tick1));
|
||||
|
||||
return ret;
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
static int connect_by_open_system(char *target_ssid)
|
||||
{
|
||||
int retry_count = 0, ret;
|
||||
|
||||
if (target_ssid != NULL) {
|
||||
while (1) {
|
||||
rtw_msleep_os(500); //wait scan complete.
|
||||
ret = wifi_connect(target_ssid,
|
||||
RTW_SECURITY_OPEN,
|
||||
NULL,
|
||||
strlen(target_ssid),
|
||||
0,
|
||||
0,
|
||||
NULL);
|
||||
if (ret == RTW_SUCCESS) {
|
||||
//printf("\r\n[EAP]Associate with AP success\n");
|
||||
break;
|
||||
}
|
||||
if (retry_count == 0) {
|
||||
//printf("\r\n[EAP]Associate with AP failed %d\n", ret);
|
||||
return -1;
|
||||
}
|
||||
retry_count --;
|
||||
printf("Retry connection...\n");
|
||||
|
||||
judge_station_disconnect();
|
||||
set_eap_phase(ENABLE);
|
||||
}
|
||||
} else {
|
||||
printf("\r\n[EAP]Target SSID is NULL\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void eap_autoreconnect_thread(void *method)
|
||||
{
|
||||
eap_start((char*)method);
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void eap_autoreconnect_hdl(u8 method_id){
|
||||
#ifdef CONFIG_ENABLE_EAP
|
||||
char *method;
|
||||
switch(method_id){
|
||||
case 25: // EAP_TYPE_PEAP
|
||||
method = "peap";
|
||||
break;
|
||||
case 13: // EAP_TYPE_TLS
|
||||
method = "tls";
|
||||
break;
|
||||
case 21: // EAP_TYPE_TTLS
|
||||
method = "ttls";
|
||||
break;
|
||||
default:
|
||||
printf("invalid eap method\n");
|
||||
return;
|
||||
}
|
||||
if(xTaskCreate(eap_autoreconnect_thread, ((const char*)"eap_autoreconnect_thread"), 1024, (void*) method, tskIDLE_PRIORITY + 1, NULL) != pdPASS)
|
||||
printf("\n\r%s xTaskCreate failed\n", __FUNCTION__);
|
||||
#endif
|
||||
}
|
||||
|
||||
// copy from ssl_client_ext.c
|
||||
#if ENABLE_EAP_SSL_VERIFY_CLIENT
|
||||
static x509_crt* _cli_crt = NULL;
|
||||
static pk_context* _clikey_rsa = NULL;
|
||||
#endif
|
||||
|
||||
#if ENABLE_EAP_SSL_VERIFY_SERVER
|
||||
static x509_crt* _ca_crt = NULL;
|
||||
|
||||
static int eap_verify(void *data, x509_crt *crt, int depth, int *flags)
|
||||
{
|
||||
|
||||
//char buf[1024];
|
||||
((void) data);
|
||||
|
||||
printf("\nVerify requested for (Depth %d):\n", depth);
|
||||
//x509_crt_info(buf, sizeof(buf) - 1, "", crt);
|
||||
//printf("%s", buf);
|
||||
|
||||
if(((*flags) & BADCERT_EXPIRED) != 0)
|
||||
printf("server certificate has expired\n");
|
||||
|
||||
if(((*flags) & BADCERT_REVOKED) != 0)
|
||||
printf(" ! server certificate has been revoked\n");
|
||||
|
||||
if(((*flags) & BADCERT_CN_MISMATCH) != 0)
|
||||
printf(" ! CN mismatch\n");
|
||||
|
||||
if(((*flags) & BADCERT_NOT_TRUSTED) != 0)
|
||||
printf(" ! self-signed or not signed by a trusted CA\n");
|
||||
|
||||
if(((*flags) & BADCRL_NOT_TRUSTED) != 0)
|
||||
printf(" ! CRL not trusted\n");
|
||||
|
||||
if(((*flags) & BADCRL_EXPIRED) != 0)
|
||||
printf(" ! CRL expired\n");
|
||||
|
||||
if(((*flags) & BADCERT_OTHER) != 0)
|
||||
printf(" ! other (unknown) flag\n");
|
||||
|
||||
if((*flags) == 0)
|
||||
printf(" Certificate verified without error flags\n");
|
||||
|
||||
return(0);
|
||||
}
|
||||
#endif
|
||||
|
||||
int eap_cert_init(void)
|
||||
{
|
||||
#if ENABLE_EAP_SSL_VERIFY_CLIENT
|
||||
if(eap_client_cert != NULL && eap_client_key != NULL){
|
||||
_cli_crt = polarssl_malloc(sizeof(x509_crt));
|
||||
|
||||
if(_cli_crt)
|
||||
x509_crt_init(_cli_crt);
|
||||
else
|
||||
return -1;
|
||||
|
||||
_clikey_rsa = polarssl_malloc(sizeof(pk_context));
|
||||
|
||||
if(_clikey_rsa)
|
||||
pk_init(_clikey_rsa);
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
#if ENABLE_EAP_SSL_VERIFY_SERVER
|
||||
if(eap_ca_cert != NULL){
|
||||
_ca_crt = polarssl_malloc(sizeof(x509_crt));
|
||||
|
||||
if(_ca_crt)
|
||||
x509_crt_init(_ca_crt);
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
void eap_client_cert_free(void)
|
||||
{
|
||||
#if ENABLE_EAP_SSL_VERIFY_CLIENT
|
||||
if(eap_client_cert != NULL && eap_client_key != NULL){
|
||||
if(_cli_crt) {
|
||||
x509_crt_free(_cli_crt);
|
||||
polarssl_free(_cli_crt);
|
||||
_cli_crt = NULL;
|
||||
}
|
||||
|
||||
if(_clikey_rsa) {
|
||||
pk_free(_clikey_rsa);
|
||||
polarssl_free(_clikey_rsa);
|
||||
_clikey_rsa = NULL;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void eap_server_cert_free(void)
|
||||
{
|
||||
#if ENABLE_EAP_SSL_VERIFY_SERVER
|
||||
if(eap_ca_cert != NULL){
|
||||
if(_ca_crt) {
|
||||
x509_crt_free(_ca_crt);
|
||||
polarssl_free(_ca_crt);
|
||||
_ca_crt = NULL;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int eap_cert_setup(ssl_context *ssl)
|
||||
{
|
||||
#if ENABLE_EAP_SSL_VERIFY_CLIENT
|
||||
if(eap_client_cert != NULL && eap_client_key != NULL){
|
||||
if(x509_crt_parse(_cli_crt, eap_client_cert, strlen(eap_client_cert)) != 0)
|
||||
return -1;
|
||||
|
||||
if(pk_parse_key(_clikey_rsa, eap_client_key, strlen(eap_client_key), eap_client_key_pwd, strlen(eap_client_key_pwd)) != 0)
|
||||
return -1;
|
||||
|
||||
ssl_set_own_cert(ssl, _cli_crt, _clikey_rsa);
|
||||
}
|
||||
#endif
|
||||
#if ENABLE_EAP_SSL_VERIFY_SERVER
|
||||
if(eap_ca_cert != NULL){
|
||||
if(x509_crt_parse(_ca_crt, eap_ca_cert, strlen(eap_ca_cert)) != 0)
|
||||
return -1;
|
||||
ssl_set_ca_chain(ssl, _ca_crt, NULL, NULL);
|
||||
ssl_set_authmode(ssl, SSL_VERIFY_REQUIRED);
|
||||
ssl_set_verify(ssl, eap_verify, NULL);
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,269 @@
|
|||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
|
||||
#include "utils/os.h"
|
||||
#include <lwip/netif.h>
|
||||
#include <wifi/wifi_conf.h>
|
||||
#include "wps/wps_defs.h"
|
||||
|
||||
#if CONFIG_ENABLE_P2P
|
||||
enum p2p_wps_method {
|
||||
WPS_NOT_READY, WPS_PIN_DISPLAY, WPS_PIN_KEYPAD, WPS_PBC
|
||||
};
|
||||
|
||||
/*NETMASK*/
|
||||
#define P2P_NETMASK_ADDR0 255
|
||||
#define P2P_NETMASK_ADDR1 255
|
||||
#define P2P_NETMASK_ADDR2 255
|
||||
#define P2P_NETMASK_ADDR3 0
|
||||
|
||||
/*Gateway Address*/
|
||||
#define P2P_GW_ADDR0 192
|
||||
#define P2P_GW_ADDR1 168
|
||||
#define P2P_GW_ADDR2 42
|
||||
#define P2P_GW_ADDR3 1
|
||||
|
||||
#define P2P_GO_NEGO_RESULT_SIZE 376//256
|
||||
|
||||
xqueue_handle_t queue_for_p2p_nego;
|
||||
|
||||
extern void dhcps_init(struct netif * pnetif);
|
||||
|
||||
static int hex2num(char c)
|
||||
{
|
||||
if (c >= '0' && c <= '9')
|
||||
return c - '0';
|
||||
if (c >= 'a' && c <= 'f')
|
||||
return c - 'a' + 10;
|
||||
if (c >= 'A' && c <= 'F')
|
||||
return c - 'A' + 10;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* hwaddr_aton - Convert ASCII string to MAC address (colon-delimited format)
|
||||
* @txt: MAC address as a string (e.g., "00:11:22:33:44:55")
|
||||
* @addr: Buffer for the MAC address (ETH_ALEN = 6 bytes)
|
||||
* Returns: 0 on success, -1 on failure (e.g., string not a MAC address)
|
||||
*/
|
||||
int hwaddr_aton(const char *txt, u8 *addr)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 6; i++) {
|
||||
int a, b;
|
||||
|
||||
a = hex2num(*txt++);
|
||||
if (a < 0)
|
||||
return -1;
|
||||
b = hex2num(*txt++);
|
||||
if (b < 0)
|
||||
return -1;
|
||||
*addr++ = (a << 4) | b;
|
||||
if (i < 5 && *txt++ != ':')
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int wifi_start_p2p_go(char *ssid, char *passphrase, u8 channel)
|
||||
{
|
||||
extern struct netif xnetif[NET_IF_NUM];
|
||||
struct netif * pnetif = &xnetif[0];
|
||||
struct ip_addr ipaddr;
|
||||
struct ip_addr netmask;
|
||||
struct ip_addr gw;
|
||||
|
||||
IP4_ADDR(&ipaddr, P2P_GW_ADDR0, P2P_GW_ADDR1, P2P_GW_ADDR2, P2P_GW_ADDR3);
|
||||
IP4_ADDR(&netmask, P2P_NETMASK_ADDR0, P2P_NETMASK_ADDR1 , P2P_NETMASK_ADDR2, P2P_NETMASK_ADDR3);
|
||||
IP4_ADDR(&gw, P2P_GW_ADDR0, P2P_GW_ADDR1, P2P_GW_ADDR2, P2P_GW_ADDR3);
|
||||
netif_set_addr(pnetif, &ipaddr, &netmask,&gw);
|
||||
|
||||
// start ap
|
||||
if(wifi_start_ap(ssid,
|
||||
RTW_SECURITY_WPA2_AES_PSK,
|
||||
passphrase,
|
||||
strlen(ssid),
|
||||
strlen(passphrase),
|
||||
channel
|
||||
) != RTW_SUCCESS) {
|
||||
printf("\n\rERROR: Operation failed!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
netif_set_default(pnetif);
|
||||
|
||||
// start dhcp server
|
||||
dhcps_init(pnetif);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void app_callback(char *msg)
|
||||
{
|
||||
//From Application
|
||||
}
|
||||
|
||||
void cmd_wifi_p2p_start(int argc, char **argv)
|
||||
{
|
||||
extern struct netif xnetif[NET_IF_NUM];
|
||||
int listen_ch = 1;
|
||||
int op_ch = 5;
|
||||
int go_intent = 1;
|
||||
#if 1
|
||||
u32 r = 0;
|
||||
os_get_random((u8 *) &r, sizeof(r));
|
||||
go_intent = r%15+1; /*1-15*/
|
||||
|
||||
os_get_random((u8 *) &r, sizeof(r));
|
||||
listen_ch = 1 + (r % 3) * 5;
|
||||
|
||||
os_get_random((u8 *) &r, sizeof(r));
|
||||
op_ch = 1 + (r % 3) * 5;
|
||||
#endif
|
||||
wifi_off();
|
||||
os_sleep(0, 20000);
|
||||
wifi_on(RTW_MODE_P2P);
|
||||
wifi_p2p_init(xnetif[0].hwaddr, go_intent, listen_ch, op_ch);
|
||||
}
|
||||
|
||||
int cmd_wifi_p2p_auto_go_start(int argc, char **argv)
|
||||
{
|
||||
u8 *passphrase = "12345678";
|
||||
u8 channel = 6; // 1, 6, 11
|
||||
const char *ssid_in = "DIRECT-34-Ameba";
|
||||
const char *dev_name = "Ameba1234"; // max strlen 32
|
||||
const char *manufacturer = "by customer"; // max strlen 64
|
||||
const char *model_name = "customer"; // max strlen 32
|
||||
const char *model_number = "v2.0"; // max strlen 32
|
||||
const char *serial_number = "9"; // max strlen 32
|
||||
const u8 pri_dev_type[8] = {0x00,0x0A,0x00,0x50,0xF2,0x04,0x00,0x01}; // category ID:0x00,0x0A; sub category ID:0x00,0x01
|
||||
u8 res[P2P_GO_NEGO_RESULT_SIZE];
|
||||
u16 config_methods = WPS_CONFIG_DISPLAY | WPS_CONFIG_KEYPAD | WPS_CONFIG_PUSHBUTTON;
|
||||
|
||||
if(!is_wifi_p2p_initialized())
|
||||
return -1;
|
||||
|
||||
wifi_p2p_set_dev_name(dev_name);
|
||||
wifi_p2p_set_manufacturer(manufacturer);
|
||||
wifi_p2p_set_model_name(model_name);
|
||||
wifi_p2p_set_model_number(model_number);
|
||||
wifi_p2p_set_serial_number(serial_number);
|
||||
wifi_p2p_set_pri_dev_type(pri_dev_type);
|
||||
wifi_p2p_set_ssid(ssid_in);
|
||||
wifi_p2p_set_config_methods(config_methods);
|
||||
wifi_p2p_init_auto_go_params(res, passphrase, channel);
|
||||
wifi_p2p_start_auto_go(res);
|
||||
return 0;
|
||||
}
|
||||
void cmd_wifi_p2p_stop(int argc, char **argv)
|
||||
{
|
||||
wifi_p2p_deinit();
|
||||
wifi_off();
|
||||
}
|
||||
|
||||
void cmd_p2p_listen(int argc, char **argv)
|
||||
{
|
||||
u32 timeout = 0;
|
||||
|
||||
if(argc == 2){
|
||||
timeout = os_atoi((u8*)argv[1]);
|
||||
printf("\r\n%s(): timeout=%d\n", __func__, timeout);
|
||||
if(timeout > 3600)
|
||||
timeout = 3600;
|
||||
}
|
||||
wifi_cmd_p2p_listen(timeout);
|
||||
}
|
||||
|
||||
void cmd_p2p_find(int argc, char **argv)
|
||||
{
|
||||
wifi_cmd_p2p_find();
|
||||
}
|
||||
|
||||
void cmd_p2p_peers(int argc, char **argv)
|
||||
{
|
||||
wifi_cmd_p2p_peers();
|
||||
}
|
||||
|
||||
void cmd_p2p_info(int argc, char **argv)
|
||||
{
|
||||
wifi_cmd_p2p_info();
|
||||
}
|
||||
|
||||
void cmd_p2p_disconnect(int argc, char **argv)
|
||||
{
|
||||
wifi_cmd_p2p_disconnect();
|
||||
}
|
||||
|
||||
void cmd_p2p_connect(int argc, char **argv)
|
||||
{
|
||||
enum p2p_wps_method config_method = WPS_PBC;
|
||||
char *pin = NULL;
|
||||
u8 dest[ETH_ALEN] = {0x44, 0x6d, 0x57, 0xd7, 0xce, 0x41};
|
||||
u8 res[P2P_GO_NEGO_RESULT_SIZE];
|
||||
int ret = 0;
|
||||
|
||||
#if 1
|
||||
if((argc != 2) && (argc != 3) && (argc != 4)) {
|
||||
printf("\n\rUsage: p2p_connect DEST_ADDR [pbc|pin] [pin code]\n");
|
||||
printf("\n\rExample: p2p_connect 00:e0:4c:87:00:15 pin 12345678\n");
|
||||
return;
|
||||
}
|
||||
if (hwaddr_aton(argv[1], dest)){
|
||||
printf("\r\nP2P_CONNECT: dest address is not correct!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
//printf("\r\nDEST: %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n", dest[0], dest[1], dest[2], dest[3], dest[4], dest[5]);
|
||||
config_method = WPS_PBC;
|
||||
if(argc == 3) {
|
||||
if(os_strncmp(argv[2], "pbc", 3) == 0)
|
||||
config_method = WPS_PBC;
|
||||
else if(os_strncmp(argv[2], "pin", 3) == 0){
|
||||
config_method = WPS_PIN_DISPLAY;
|
||||
}else{
|
||||
printf("\n\rUnknown config method!\n");
|
||||
printf("\n\rUsage: p2p_connect DEST_ADDR [pbc|pin] \n");
|
||||
printf("\n\rExample: p2p_connect 00:e0:4c:87:00:15 pin\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if(argc == 4) {
|
||||
if(os_strncmp(argv[2], "pin", 3) == 0){
|
||||
config_method = WPS_PIN_KEYPAD;
|
||||
pin = argv[3];
|
||||
}else{
|
||||
printf("\n\rUnknown config method!\n");
|
||||
printf("\n\rUsage: p2p_connect DEST_ADDR [pbc|pin] [pin code]\n");
|
||||
printf("\n\rExample: p2p_connect 00:e0:4c:87:00:15 pin 12345678\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
#else //For test
|
||||
u8 dest1[ETH_ALEN] = {0xea, 0x92, 0xa4, 0x9b, 0x61, 0xd6}; //NEXUS 4
|
||||
//u8 dest1[ETH_ALEN] = {0x0e, 0x37, 0xdc, 0xfc, 0xc4, 0x12}; //HUAWEI U9508_c001
|
||||
//u8 dest1[ETH_ALEN] = {0x42, 0xcb, 0xa8, 0xd3, 0x2c, 0x50}; //HUAWEI G610-T00
|
||||
os_memcpy(dest, dest1, ETH_ALEN);
|
||||
config_method = WPS_PBC;
|
||||
#endif
|
||||
|
||||
if (queue_for_p2p_nego!= NULL) {
|
||||
os_xqueue_delete(queue_for_p2p_nego);
|
||||
queue_for_p2p_nego = NULL;
|
||||
}
|
||||
queue_for_p2p_nego = os_xqueue_create(1, P2P_GO_NEGO_RESULT_SIZE);
|
||||
if(queue_for_p2p_nego != NULL) {
|
||||
ret = wifi_cmd_p2p_connect(dest, config_method, pin);
|
||||
if(ret == 0)
|
||||
os_xqueue_receive(queue_for_p2p_nego, res, 15);
|
||||
|
||||
os_xqueue_delete(queue_for_p2p_nego);
|
||||
queue_for_p2p_nego = NULL;
|
||||
|
||||
if(ret == 0)
|
||||
wifi_p2p_start_wps(res);
|
||||
}
|
||||
}
|
||||
|
||||
#endif //CONFIG_ENABLE_P2P
|
|
@ -0,0 +1,753 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "main.h"
|
||||
#include "queue.h"
|
||||
#include "utils/os.h"
|
||||
#include <lwip_netconf.h>
|
||||
#include <lwip/netif.h>
|
||||
#include "wifi/wifi_conf.h"
|
||||
#include "wps/wps_defs.h"
|
||||
#include <platform/platform_stdlib.h>
|
||||
|
||||
/*
|
||||
* @brief struct wps_credential - WPS Credential
|
||||
*/
|
||||
struct dev_credential {
|
||||
u8 ssid[32]; /**< SSID */
|
||||
size_t ssid_len; /**< Length of SSID */
|
||||
u16 auth_type; /**< Authentication Type (WPS_AUTH_OPEN, .. flags) */
|
||||
u16 encr_type; /**< Encryption Type (WPS_ENCR_NONE, .. flags) */
|
||||
u8 key_idx; /**< Key index */
|
||||
u8 key[65]; /**< Key */
|
||||
size_t key_len; /**< Key length in octets */
|
||||
u8 mac_addr[6]; /**< MAC address of the Credential receiver */
|
||||
const u8 *cred_attr; /**< Unparsed Credential attribute data (used only in cred_cb()).
|
||||
This may be NULL, if not used. */
|
||||
size_t cred_attr_len; /**< Length of cred_attr in octets */
|
||||
u16 ap_channel; /**< AP channel */
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
char *target_ssid;
|
||||
u16 config_method;
|
||||
_sema scan_sema;
|
||||
int isoverlap;
|
||||
} internal_wps_scan_handler_arg_t;
|
||||
|
||||
#define WLAN0_NAME "wlan0"
|
||||
#ifndef ENABLE
|
||||
#define ENABLE (1)
|
||||
#endif
|
||||
#ifndef DISABLE
|
||||
#define DISABLE (0)
|
||||
#endif
|
||||
#define STACKSIZE 512
|
||||
|
||||
|
||||
//static xSemaphoreHandle wps_reconnect_semaphore;
|
||||
//static struct _WIFI_NETWORK wifi_get_from_certificate = {0};
|
||||
|
||||
#define WPS_AUTH_TYPE_OPEN (0x0001)
|
||||
#define WPS_AUTH_TYPE_WPA_PERSONAL (0x0002)
|
||||
#define WPS_AUTH_TYPE_SHARED (0x0004)
|
||||
#define WPS_AUTH_TYPE_WPA_ENTERPRISE (0x0008)
|
||||
#define WPS_AUTH_TYPE_WPA2_PERSONAL (0x0010)
|
||||
#define WPS_AUTH_TYPE_WPA2_ENTERPRISE (0x0020)
|
||||
|
||||
#define WPS_ENCR_TYPE_NONE (0x0001)
|
||||
#define WPS_ENCR_TYPE_WEP (0x0002)
|
||||
#define WPS_ENCR_TYPE_TKIP (0x0004)
|
||||
#define WPS_ENCR_TYPE_AES (0x0008)
|
||||
|
||||
#define SCAN_BUFFER_LENGTH (4096)
|
||||
|
||||
#if CONFIG_ENABLE_P2P
|
||||
extern void _wifi_p2p_wps_success(const u8 *peer_addr, int registrar);
|
||||
extern void _wifi_p2p_wps_failed();
|
||||
#endif
|
||||
#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
|
||||
extern u32 _wps_registrar_process_msg(void *priv, u32 op_code, const void *pmsg);
|
||||
extern void * _wps_registrar_get_msg(void *priv, u32 *op_code);
|
||||
extern void * _wps_registrar_init(void *priv, const void* pcfg);
|
||||
extern void _wps_registrar_deinit(void *priv);
|
||||
extern void *_wps_registrar_alloc();
|
||||
extern int _wps_registrar_add_pin(void *priv, const u8 *addr,
|
||||
const u8 *uuid, const u8 *pin, size_t pin_len,
|
||||
int timeout);
|
||||
extern int _wps_registrar_button_pushed(void *priv,
|
||||
const u8 *p2p_dev_addr);
|
||||
extern int _wps_registrar_wps_cancel(void *priv);
|
||||
extern void _wpas_wsc_ap_send_eap_reqidentity(void *priv, u8 *rx_buf);
|
||||
extern void _wpas_wsc_ap_check_eap_rspidentity(void *priv, u8 *rx_buf);
|
||||
extern void _wpas_wsc_registrar_send_eap_fail(void *priv);
|
||||
extern void _wpas_wsc_registrar_handle_recvd(void *priv, u8 *rx_buf);
|
||||
extern void * _eap_wsc_server_process_hdl(void *priv, void* req, u8 id);
|
||||
extern void *_eap_wsc_server_reset(void *priv);
|
||||
#endif
|
||||
extern void wpas_wsc_sta_wps_start_hdl(char *buf, int buf_len, int flags, void *userdata);
|
||||
extern void wpas_wsc_wps_finish_hdl(char *buf, int buf_len, int flags, void *userdata);
|
||||
extern void wpas_wsc_eapol_recvd_hdl(char *buf, int buf_len, int flags, void *userdata);
|
||||
|
||||
void wifi_p2p_wps_success(const u8 *peer_addr, int registrar)
|
||||
{
|
||||
#if CONFIG_ENABLE_P2P
|
||||
_wifi_p2p_wps_success(peer_addr, registrar);
|
||||
#endif
|
||||
}
|
||||
|
||||
void wifi_p2p_wps_failed()
|
||||
{
|
||||
#if CONFIG_ENABLE_P2P
|
||||
_wifi_p2p_wps_failed();
|
||||
#endif
|
||||
}
|
||||
|
||||
void * wps_registrar_init(void *priv, void *pcfg)
|
||||
{
|
||||
#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
|
||||
return _wps_registrar_init(priv, pcfg);
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
void wps_registrar_deinit(void *priv)
|
||||
{
|
||||
#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
|
||||
_wps_registrar_deinit(priv);
|
||||
#endif
|
||||
}
|
||||
|
||||
void *wps_registrar_alloc()
|
||||
{
|
||||
#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
|
||||
return _wps_registrar_alloc();
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
u32 wps_registrar_process_msg(void *priv, u32 op_code, const void *pmsg)
|
||||
{
|
||||
#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
|
||||
return _wps_registrar_process_msg(priv, op_code, pmsg);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void * wps_registrar_get_msg(void *priv, u32 *op_code)
|
||||
{
|
||||
#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
|
||||
return _wps_registrar_get_msg(priv, op_code);
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int wps_registrar_add_pin(void *priv, const u8 *addr,
|
||||
const u8 *uuid, const u8 *pin, size_t pin_len,
|
||||
int timeout)
|
||||
{
|
||||
#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
|
||||
return _wps_registrar_add_pin(priv, NULL,NULL,pin,pin_len,0);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
int wps_registrar_button_pushed(void *priv,
|
||||
const u8 *p2p_dev_addr)
|
||||
{
|
||||
#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
|
||||
return _wps_registrar_button_pushed(priv, p2p_dev_addr);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
int wps_registrar_wps_cancel(void *priv)
|
||||
{
|
||||
#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
|
||||
return _wps_registrar_wps_cancel(priv);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void wpas_wsc_ap_send_eap_reqidentity(void *priv, u8 *rx_buf)
|
||||
{
|
||||
#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
|
||||
_wpas_wsc_ap_send_eap_reqidentity(priv, rx_buf);
|
||||
#endif
|
||||
}
|
||||
|
||||
void wpas_wsc_ap_check_eap_rspidentity(void *priv, u8 *rx_buf)
|
||||
{
|
||||
#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
|
||||
_wpas_wsc_ap_check_eap_rspidentity(priv, rx_buf);
|
||||
#endif
|
||||
}
|
||||
|
||||
void wpas_wsc_registrar_send_eap_fail(void *priv)
|
||||
{
|
||||
#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
|
||||
_wpas_wsc_registrar_send_eap_fail(priv);
|
||||
#endif
|
||||
}
|
||||
|
||||
void wpas_wsc_registrar_handle_recvd(void *priv, u8 *rx_buf)
|
||||
{
|
||||
#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
|
||||
_wpas_wsc_registrar_handle_recvd(priv, rx_buf);
|
||||
#endif
|
||||
}
|
||||
|
||||
void * eap_wsc_server_process_hdl(void *priv, void* req, u8 id)
|
||||
{
|
||||
#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
|
||||
return _eap_wsc_server_process_hdl(priv, req, id);
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
void eap_wsc_server_reset(void *priv)
|
||||
{
|
||||
#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
|
||||
_eap_wsc_server_reset(priv);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if CONFIG_ENABLE_WPS
|
||||
xqueue_handle_t queue_for_credential;
|
||||
char wps_pin_code[32];
|
||||
u16 config_method;
|
||||
u8 wps_password_id;
|
||||
static TaskHandle_t ap_wps_task = NULL;
|
||||
|
||||
void wps_check_and_show_connection_info(void)
|
||||
{
|
||||
rtw_wifi_setting_t setting;
|
||||
#if CONFIG_LWIP_LAYER
|
||||
/* Start DHCP Client */
|
||||
LwIP_DHCP(0, DHCP_START);
|
||||
#endif
|
||||
wifi_get_setting(WLAN0_NAME, &setting);
|
||||
wifi_show_setting(WLAN0_NAME, &setting);
|
||||
|
||||
#if CONFIG_INIC_CMD_RSP
|
||||
inic_c2h_wifi_info("ATWW", RTW_SUCCESS);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void wps_config_wifi_setting(rtw_network_info_t *wifi, struct dev_credential *dev_cred)
|
||||
{
|
||||
printf("\r\nwps_config_wifi_setting\n");
|
||||
//memcpy((void *)wifi->ssid, (void *)dev_cred->ssid, dev_cred->ssid_len);
|
||||
strcpy((char*)wifi->ssid.val, (char*)&dev_cred->ssid[0]);
|
||||
printf("\r\nwps_wifi.ssid = %s\n", wifi->ssid.val);
|
||||
wifi->ssid.len = dev_cred->ssid_len;
|
||||
printf("\r\nwps_wifi.ssid_len = %d\n", wifi->ssid.len);
|
||||
|
||||
switch(dev_cred->auth_type) {
|
||||
case WPS_AUTH_TYPE_OPEN :
|
||||
case WPS_AUTH_TYPE_SHARED :
|
||||
if(dev_cred->encr_type == WPS_ENCR_TYPE_WEP) {
|
||||
printf("\r\nsecurity_type = RTW_SECURITY_WEP_PSK\n");
|
||||
wifi->security_type = RTW_SECURITY_WEP_PSK;
|
||||
wifi->key_id = dev_cred->key_idx - 1;
|
||||
}
|
||||
else {
|
||||
printf("\r\nsecurity_type = RTW_SECURITY_OPEN\n");
|
||||
wifi->security_type = RTW_SECURITY_OPEN;
|
||||
}
|
||||
break;
|
||||
case WPS_AUTH_TYPE_WPA_PERSONAL :
|
||||
case WPS_AUTH_TYPE_WPA_ENTERPRISE :
|
||||
printf("\r\nsecurity_type = RTW_SECURITY_WPA_AES_PSK\n");
|
||||
wifi->security_type = RTW_SECURITY_WPA_AES_PSK;
|
||||
break;
|
||||
case WPS_AUTH_TYPE_WPA2_PERSONAL :
|
||||
case WPS_AUTH_TYPE_WPA2_ENTERPRISE :
|
||||
printf("\r\nsecurity_type = RTW_SECURITY_WPA2_AES_PSK\n");
|
||||
wifi->security_type = RTW_SECURITY_WPA2_AES_PSK;
|
||||
break;
|
||||
}
|
||||
|
||||
printf("\r\nwps_wifi.security_type = %d\n", wifi->security_type);
|
||||
|
||||
//memcpy(wifi->password, dev_cred->key, dev_cred->key_len);
|
||||
wifi->password = dev_cred->key;
|
||||
printf("\r\nwps_wifi.password = %s\n", wifi->password);
|
||||
wifi->password_len = dev_cred->key_len;
|
||||
printf("\r\nwps_wifi.password_len = %d", wifi->password_len);
|
||||
//xSemaphoreGive(wps_reconnect_semaphore);
|
||||
//printf("\r\nrelease wps_reconnect_semaphore");
|
||||
}
|
||||
|
||||
static int wps_connect_to_AP_by_certificate(rtw_network_info_t *wifi)
|
||||
{
|
||||
#define RETRY_COUNT 3
|
||||
int retry_count = RETRY_COUNT, ret;
|
||||
|
||||
printf("\r\n=============== wifi_certificate_info ===============\n");
|
||||
printf("\r\nwps_wifi.ssid = %s\n", wifi->ssid.val);
|
||||
printf("\r\nsecurity_type = %d\n", wifi->security_type);
|
||||
printf("\r\nwps_wifi.password = %s\n", wifi->password);
|
||||
printf("\r\nssid_len = %d\n", wifi->ssid.len);
|
||||
printf("\r\npassword_len = %d\n", wifi->password_len);
|
||||
while (1) {
|
||||
ret = wifi_connect((char*)wifi->ssid.val,
|
||||
wifi->security_type,
|
||||
(char*)wifi->password,
|
||||
wifi->ssid.len,
|
||||
wifi->password_len,
|
||||
wifi->key_id,
|
||||
NULL);
|
||||
if (ret == RTW_SUCCESS) {
|
||||
if(retry_count == RETRY_COUNT)
|
||||
rtw_msleep_os(1000); //When start wps with OPEN AP, AP will send a disassociate frame after STA connected, need reconnect here.
|
||||
if(RTW_SUCCESS == wifi_is_connected_to_ap( )){
|
||||
//printf("\r\n[WPS]Ready to tranceive!!\n");
|
||||
wps_check_and_show_connection_info();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (retry_count == 0) {
|
||||
printf("\r\n[WPS]Join bss failed\n");
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
retry_count --;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int wps_connect_to_AP_by_open_system(char *target_ssid)
|
||||
{
|
||||
int retry_count = 3, ret;
|
||||
|
||||
if (target_ssid != NULL) {
|
||||
rtw_msleep_os(500); //wait scan complete.
|
||||
while (1) {
|
||||
ret = wifi_connect(target_ssid,
|
||||
RTW_SECURITY_OPEN,
|
||||
NULL,
|
||||
strlen(target_ssid),
|
||||
0,
|
||||
0,
|
||||
NULL);
|
||||
if (ret == RTW_SUCCESS) {
|
||||
//wps_check_and_show_connection_info();
|
||||
break;
|
||||
}
|
||||
if (retry_count == 0) {
|
||||
printf("\r\n[WPS]Join bss failed\n");
|
||||
return -1;
|
||||
}
|
||||
retry_count --;
|
||||
}
|
||||
//
|
||||
} else {
|
||||
printf("\r\n[WPS]Target SSID is NULL\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void process_wps_scan_result( rtw_scan_result_t* record, void * user_data )
|
||||
{
|
||||
internal_wps_scan_handler_arg_t *wps_arg = (internal_wps_scan_handler_arg_t *)user_data;
|
||||
|
||||
if (record->wps_type != 0xff) {
|
||||
if (wps_arg->config_method == WPS_CONFIG_PUSHBUTTON) {
|
||||
if (record->wps_type == 0x04) {
|
||||
wps_password_id = record->wps_type;
|
||||
if (++wps_arg->isoverlap == 0) {
|
||||
memcpy(&wps_arg->target_ssid[0], record->SSID.val, record->SSID.len);
|
||||
wps_arg->target_ssid[record->SSID.len] = '\0';
|
||||
printf("\r\n[pbc]Record first triger wps AP = %s\n", wps_arg->target_ssid);
|
||||
}
|
||||
}
|
||||
} else if (wps_arg->config_method == WPS_CONFIG_DISPLAY || wps_arg->config_method == WPS_CONFIG_KEYPAD) {
|
||||
if (record->wps_type == 0x00) {
|
||||
wps_arg->isoverlap = 0;
|
||||
wps_password_id = record->wps_type;
|
||||
memcpy(&wps_arg->target_ssid[0], record->SSID.val, record->SSID.len);
|
||||
wps_arg->target_ssid[record->SSID.len] = '\0';
|
||||
printf("\r\n[pin]find out first triger wps AP = %s\n", wps_arg->target_ssid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static rtw_result_t wps_scan_result_handler( rtw_scan_handler_result_t* malloced_scan_result )
|
||||
{
|
||||
internal_wps_scan_handler_arg_t *wps_arg = (internal_wps_scan_handler_arg_t *)malloced_scan_result->user_data;
|
||||
if (malloced_scan_result->scan_complete != RTW_TRUE)
|
||||
{
|
||||
rtw_scan_result_t* record = &malloced_scan_result->ap_details;
|
||||
record->SSID.val[record->SSID.len] = 0; /* Ensure the SSID is null terminated */
|
||||
|
||||
process_wps_scan_result(record, malloced_scan_result->user_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("\r\nWPS scan done!\r\n");
|
||||
rtw_up_sema(&wps_arg->scan_sema);
|
||||
}
|
||||
return RTW_SUCCESS;
|
||||
}
|
||||
|
||||
extern void wifi_scan_each_report_hdl( char* buf, int buf_len, int flags, void* userdata);
|
||||
extern void wifi_scan_done_hdl( char* buf, int buf_len, int flags, void* userdata);
|
||||
|
||||
static int wps_find_out_triger_wps_AP(char *target_ssid, u16 config_method)
|
||||
{
|
||||
internal_wps_scan_handler_arg_t wps_arg = {0};
|
||||
|
||||
wps_password_id = 0xFF;
|
||||
|
||||
wps_arg.isoverlap = -1;
|
||||
wps_arg.config_method = config_method;
|
||||
wps_arg.target_ssid = target_ssid;
|
||||
rtw_init_sema(&wps_arg.scan_sema, 0);
|
||||
if(wps_arg.scan_sema == NULL) return RTW_ERROR;
|
||||
|
||||
if(wifi_scan_networks(wps_scan_result_handler, &wps_arg ) != RTW_SUCCESS){
|
||||
printf("\n\rERROR: wifi scan failed");
|
||||
goto exit;
|
||||
}
|
||||
if(rtw_down_timeout_sema(&wps_arg.scan_sema, SCAN_LONGEST_WAIT_TIME) == RTW_FALSE){
|
||||
printf("\r\nWPS scan done early!\r\n");
|
||||
}
|
||||
wifi_unreg_event_handler(WIFI_EVENT_SCAN_RESULT_REPORT, wifi_scan_each_report_hdl);
|
||||
wifi_unreg_event_handler(WIFI_EVENT_SCAN_DONE, wifi_scan_done_hdl);
|
||||
|
||||
exit:
|
||||
rtw_free_sema(&wps_arg.scan_sema);
|
||||
|
||||
return wps_arg.isoverlap;
|
||||
}
|
||||
|
||||
int wps_start(u16 wps_config, char *pin, u8 channel, char *ssid)
|
||||
{
|
||||
struct dev_credential dev_cred;
|
||||
rtw_network_info_t wifi = {0};
|
||||
char target_ssid[64];
|
||||
int is_overlap = -1;
|
||||
u32 start_time = rtw_get_current_time();
|
||||
int ret = 0;
|
||||
|
||||
memset(&dev_cred, 0, sizeof(struct dev_credential));
|
||||
memset(target_ssid, 0, 64);
|
||||
if((wps_config != WPS_CONFIG_PUSHBUTTON)
|
||||
&& (wps_config != WPS_CONFIG_DISPLAY)
|
||||
&& (wps_config != WPS_CONFIG_KEYPAD)){
|
||||
printf("\n\rWPS: Wps method(%d) is wrong. Not triger WPS.\n", wps_config);
|
||||
return -1;
|
||||
}
|
||||
config_method = wps_config;
|
||||
|
||||
if(wps_config == WPS_CONFIG_DISPLAY
|
||||
|| wps_config == WPS_CONFIG_KEYPAD) {
|
||||
if(pin)
|
||||
strcpy(wps_pin_code, pin);
|
||||
else{
|
||||
printf("\n\rWPS: PIN is NULL. Not triger WPS.\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if(!ssid) {
|
||||
while (1) {
|
||||
unsigned int current_time = rtw_get_current_time();
|
||||
if (rtw_systime_to_sec(current_time - start_time) < 120) {
|
||||
is_overlap = wps_find_out_triger_wps_AP(&target_ssid[0], wps_config);
|
||||
if ((is_overlap == 0) || (is_overlap > 0))
|
||||
break;
|
||||
} else {
|
||||
printf("\r\nWPS: WPS Walking Time Out\n");
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_overlap > 0) {
|
||||
printf("\r\nWPS: WPS session overlap. Not triger WPS.\n");
|
||||
return -2;
|
||||
}
|
||||
}else{
|
||||
rtw_memcpy(target_ssid, ssid, strlen(ssid));
|
||||
}
|
||||
|
||||
if (queue_for_credential != NULL) {
|
||||
os_xqueue_delete(queue_for_credential);
|
||||
queue_for_credential = NULL;
|
||||
}
|
||||
queue_for_credential = os_xqueue_create(1, sizeof(struct dev_credential));
|
||||
if(!queue_for_credential)
|
||||
return -1;
|
||||
|
||||
wifi_reg_event_handler(WIFI_EVENT_STA_WPS_START, wpas_wsc_sta_wps_start_hdl, NULL);
|
||||
wifi_reg_event_handler(WIFI_EVENT_WPS_FINISH, wpas_wsc_wps_finish_hdl, NULL);
|
||||
wifi_reg_event_handler(WIFI_EVENT_EAPOL_RECVD, wpas_wsc_eapol_recvd_hdl, NULL);
|
||||
|
||||
wifi_set_wps_phase(ENABLE);
|
||||
ret = wps_connect_to_AP_by_open_system(target_ssid);
|
||||
if(ret < 0){
|
||||
printf("\n\rWPS: WPS Fail!!\n");
|
||||
goto exit;
|
||||
}
|
||||
os_xqueue_receive(queue_for_credential, &dev_cred, 120);
|
||||
if (dev_cred.ssid[0] != 0 && dev_cred.ssid_len <= 32) {
|
||||
wps_config_wifi_setting(&wifi, &dev_cred);
|
||||
wifi_set_wps_phase(DISABLE);
|
||||
ret = wps_connect_to_AP_by_certificate(&wifi);
|
||||
goto exit1;
|
||||
} else {
|
||||
printf("\n\rWPS: WPS FAIL!!!\n");
|
||||
printf("\n\rWPS: WPS FAIL!!!\n");
|
||||
printf("\n\rWPS: WPS FAIL!!!\n");
|
||||
ret = -1;
|
||||
}
|
||||
exit:
|
||||
wifi_set_wps_phase(DISABLE);
|
||||
exit1:
|
||||
if (queue_for_credential != NULL) {
|
||||
os_xqueue_delete(queue_for_credential);
|
||||
queue_for_credential = NULL;
|
||||
}
|
||||
|
||||
wifi_unreg_event_handler(WIFI_EVENT_STA_WPS_START, wpas_wsc_sta_wps_start_hdl);
|
||||
wifi_unreg_event_handler(WIFI_EVENT_WPS_FINISH, wpas_wsc_wps_finish_hdl);
|
||||
wifi_unreg_event_handler(WIFI_EVENT_EAPOL_RECVD, wpas_wsc_eapol_recvd_hdl);
|
||||
|
||||
wpas_wps_deinit();
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
|
||||
static int ap_wps_start(u16 wps_config, char *pin)
|
||||
{
|
||||
u8 authorized_mac[ETH_ALEN];
|
||||
int ret = 0;
|
||||
u32 pin_val = 0;
|
||||
|
||||
if (queue_for_credential != NULL) {
|
||||
os_xqueue_delete(queue_for_credential);
|
||||
queue_for_credential = NULL;
|
||||
}
|
||||
|
||||
queue_for_credential = os_xqueue_create(1, sizeof(authorized_mac));
|
||||
if(!queue_for_credential)
|
||||
return -1;
|
||||
|
||||
wifi_reg_event_handler(WIFI_EVENT_STA_WPS_START, wpas_wsc_sta_wps_start_hdl, NULL);
|
||||
wifi_reg_event_handler(WIFI_EVENT_WPS_FINISH, wpas_wsc_wps_finish_hdl, NULL);
|
||||
wifi_reg_event_handler(WIFI_EVENT_EAPOL_RECVD, wpas_wsc_eapol_recvd_hdl, NULL);
|
||||
|
||||
wifi_set_wps_phase(ENABLE);
|
||||
|
||||
if(wps_config == WPS_CONFIG_KEYPAD)
|
||||
{
|
||||
pin_val = atoi(pin);
|
||||
if (!wps_pin_valid(pin_val)) {
|
||||
printf("\n\rWPS-AP: Enter pin code is unvalid.");
|
||||
goto exit;
|
||||
}
|
||||
ret = wpas_wps_registrar_add_pin((unsigned char const*)pin, strlen(pin));
|
||||
}
|
||||
else if(wps_config == WPS_CONFIG_DISPLAY)
|
||||
ret = wpas_wps_registrar_add_pin((unsigned char const*)pin, strlen(pin));
|
||||
else
|
||||
ret = wpas_wps_registrar_button_pushed();
|
||||
|
||||
if(ret<0)
|
||||
goto exit;
|
||||
|
||||
printf("\n\rWPS-AP: wait for STA connect!\n");
|
||||
os_xqueue_receive(queue_for_credential, authorized_mac, 120); //max wait 2min
|
||||
|
||||
if(!wpas_wps_registrar_check_done())
|
||||
{
|
||||
ret = -1;
|
||||
wpas_wps_registrar_wps_cancel();
|
||||
}
|
||||
|
||||
exit:
|
||||
wifi_set_wps_phase(0);
|
||||
os_xqueue_delete(queue_for_credential);
|
||||
queue_for_credential = NULL;
|
||||
printf("\n\rWPS-AP: Finished!\n");
|
||||
|
||||
wifi_unreg_event_handler(WIFI_EVENT_STA_WPS_START, wpas_wsc_sta_wps_start_hdl);
|
||||
wifi_unreg_event_handler(WIFI_EVENT_WPS_FINISH, wpas_wsc_wps_finish_hdl);
|
||||
wifi_unreg_event_handler(WIFI_EVENT_EAPOL_RECVD, wpas_wsc_eapol_recvd_hdl);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void wifi_start_ap_wps_thread_hdl( void *param)
|
||||
{
|
||||
ap_wps_start(config_method, wps_pin_code); //Not support WPS_CONFIG_KEYPAD
|
||||
|
||||
ap_wps_task = NULL;
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void wifi_start_ap_wps_thread(u16 config_methods, char *pin)
|
||||
{
|
||||
if((config_methods != WPS_CONFIG_PUSHBUTTON)
|
||||
&& (config_methods != WPS_CONFIG_DISPLAY)
|
||||
&& (config_methods != WPS_CONFIG_KEYPAD)){
|
||||
printf("\n\rWPS-AP: Wps method(%d) is wrong. Not triger WPS.\n", config_methods);
|
||||
return;
|
||||
}
|
||||
config_method = config_methods;
|
||||
if(config_methods == WPS_CONFIG_DISPLAY
|
||||
|| config_methods == WPS_CONFIG_KEYPAD) {
|
||||
if(pin)
|
||||
strcpy(wps_pin_code, pin);
|
||||
else{
|
||||
printf("\n\rWPS-AP: PIN is NULL. Not triger WPS.\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(ap_wps_task != NULL){ //push item to wait queue to finish last ap_wps task
|
||||
printf("\n\rWPS-AP: Wait for last ap_wps task exiting...\n");
|
||||
if(queue_for_credential)
|
||||
os_xqueue_send(queue_for_credential, NULL, 0);
|
||||
while(ap_wps_task != NULL)
|
||||
vTaskDelay(1);
|
||||
vTaskDelay(20);
|
||||
printf("\n\rLast ap_wps task completed.\n");
|
||||
}
|
||||
if(xTaskCreate(wifi_start_ap_wps_thread_hdl, ((const char*)"ap_wps"), 256, NULL, tskIDLE_PRIORITY + 3, &ap_wps_task) != pdPASS)
|
||||
printf("\n\r%s xTaskCreate(ap_wps thread) failed", __FUNCTION__);
|
||||
}
|
||||
|
||||
#endif //CONFIG_ENABLE_WPS_AP
|
||||
|
||||
void wps_judge_staion_disconnect(void)
|
||||
{
|
||||
int mode = 0;
|
||||
unsigned char ssid[33];
|
||||
|
||||
wext_get_mode(WLAN0_NAME, &mode);
|
||||
|
||||
switch(mode) {
|
||||
case IW_MODE_MASTER: //In AP mode
|
||||
// rltk_wlan_deinit();
|
||||
// rltk_wlan_init(0,RTW_MODE_STA);
|
||||
// rltk_wlan_start(0);
|
||||
//modified by Chris Yang for iNIC
|
||||
wifi_off();
|
||||
vTaskDelay(20);
|
||||
wifi_on(RTW_MODE_STA);
|
||||
break;
|
||||
case IW_MODE_INFRA: //In STA mode
|
||||
if(wext_get_ssid(WLAN0_NAME, ssid) > 0)
|
||||
wifi_disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
void cmd_wps(int argc, char **argv)
|
||||
{
|
||||
int ret = -1;
|
||||
wps_judge_staion_disconnect();
|
||||
|
||||
if((argc == 2 || argc == 3 ) && (argv[1] != NULL)){
|
||||
if(strcmp(argv[1],"pin") == 0){
|
||||
unsigned int pin_val = 0;
|
||||
/* start pin */
|
||||
if(argc == 2){
|
||||
char device_pin[10];
|
||||
pin_val = wps_generate_pin();
|
||||
sprintf(device_pin, "%08d", pin_val);
|
||||
/* Display PIN 3 times to prevent to be overwritten by logs from other tasks */
|
||||
printf("\n\rWPS: Start WPS PIN Display. PIN: [%s]\n\r", device_pin);
|
||||
printf("\n\rWPS: Start WPS PIN Display. PIN: [%s]\n\r", device_pin);
|
||||
printf("\n\rWPS: Start WPS PIN Display. PIN: [%s]\n\r", device_pin);
|
||||
ret = wps_start(WPS_CONFIG_DISPLAY, (char*)device_pin, 0, NULL);
|
||||
}else{
|
||||
pin_val = atoi(argv[2]);
|
||||
if (!wps_pin_valid(pin_val)) {
|
||||
printf("\n\rWPS: Device pin code is invalid. Not triger WPS.\n");
|
||||
goto exit;
|
||||
}
|
||||
printf("\n\rWPS: Start WPS PIN Keypad.\n\r");
|
||||
ret = wps_start(WPS_CONFIG_KEYPAD, argv[2], 0, NULL);
|
||||
}
|
||||
}else if(strcmp(argv[1],"pbc") == 0){
|
||||
/* start pbc */
|
||||
printf("\n\rWPS: Start WPS PBC.\n\r");
|
||||
ret = wps_start(WPS_CONFIG_PUSHBUTTON, NULL, 0, NULL);
|
||||
}else{
|
||||
printf("\n\rWPS: Wps Method is wrong. Not triger WPS.\n");
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
exit:
|
||||
#if CONFIG_INIC_CMD_RSP
|
||||
if(ret != 0)
|
||||
inic_c2h_msg("ATWW", ret, NULL, 0);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
|
||||
/*
|
||||
cmd_ap_wps for AP WSC setting. command style:
|
||||
cmd_ap_wps pbc or cmd_ap_wps pin 12345678
|
||||
*/
|
||||
void cmd_ap_wps(int argc, char **argv)
|
||||
{
|
||||
int mode = 0;
|
||||
if(rltk_wlan_running(WLAN1_IDX)){
|
||||
printf("\n\rNot support con-current softAP WSC!\n\r");
|
||||
return;
|
||||
}
|
||||
wext_get_mode(WLAN0_NAME, &mode);
|
||||
if(mode != IW_MODE_MASTER){
|
||||
printf("\n\rOnly valid for IW_MODE_MASTER!\n\r");
|
||||
return;
|
||||
}
|
||||
|
||||
if((argc == 2 || argc == 3) && (argv[1] != NULL)) {
|
||||
if (strcmp(argv[1],"pin") == 0 ) {
|
||||
unsigned int pin_val = 0;
|
||||
if(argc == 3){
|
||||
pin_val = atoi(argv[2]);
|
||||
if (!wps_pin_valid(pin_val)) {
|
||||
printf("\n\rWPS-AP: Device pin code is invalid. Not trigger WPS.\n\r");
|
||||
return;
|
||||
}
|
||||
printf("\n\rWPS-AP: Start AP WPS PIN Keypad.\n");
|
||||
wifi_start_ap_wps_thread(WPS_CONFIG_KEYPAD, argv[2]);
|
||||
}else{
|
||||
char device_pin[10];
|
||||
pin_val = wps_generate_pin();
|
||||
sprintf(device_pin, "%08d", pin_val);
|
||||
printf("\n\rWPS: Start WPS PIN Display. PIN: %s\n\r", device_pin);
|
||||
wifi_start_ap_wps_thread(WPS_CONFIG_DISPLAY, (char*)device_pin);
|
||||
}
|
||||
}else if (strcmp(argv[1],"pbc") == 0) {
|
||||
printf("\n\rWPS-AP: Start AP WPS PBC\n");
|
||||
wifi_start_ap_wps_thread(WPS_CONFIG_PUSHBUTTON, NULL);
|
||||
}else{
|
||||
printf("\n\rWPS-AP Usage:\"wifi_ap_wps pin [pin_code]\" or \"wifi_ap_wps pbc\"\n");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
printf("\n\rWPS-AP Usage:\"wifi_ap_wps pin [pin_code]\" or \"wifi_ap_wps pbc\"\n");
|
||||
}
|
||||
return;
|
||||
}
|
||||
#endif //CONFIG_ENABLE_P2P
|
||||
#endif //CONFIG_ENABLE_WPS
|
1859
component/common/api/wifi/wifi_conf.c
Normal file
1859
component/common/api/wifi/wifi_conf.c
Normal file
File diff suppressed because it is too large
Load diff
708
component/common/api/wifi/wifi_conf.h
Normal file
708
component/common/api/wifi/wifi_conf.h
Normal file
|
@ -0,0 +1,708 @@
|
|||
//----------------------------------------------------------------------------//
|
||||
#ifndef __WIFI_API_H
|
||||
#define __WIFI_API_H
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "wifi_constants.h"
|
||||
#include "wifi_structures.h"
|
||||
#include "wifi_util.h"
|
||||
#include "wifi_ind.h"
|
||||
#include <platform/platform_stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/******************************************************
|
||||
* Macros
|
||||
******************************************************/
|
||||
|
||||
#define RTW_ENABLE_API_INFO
|
||||
|
||||
#ifdef RTW_ENABLE_API_INFO
|
||||
#define RTW_API_INFO(args) do {printf args;} while(0)
|
||||
#else
|
||||
#define RTW_API_INFO(args)
|
||||
#endif
|
||||
|
||||
#define MAC_ARG(x) ((u8*)(x))[0],((u8*)(x))[1],((u8*)(x))[2],((u8*)(x))[3],((u8*)(x))[4],((u8*)(x))[5]
|
||||
#define CMP_MAC( a, b ) (((a[0])==(b[0]))&& \
|
||||
((a[1])==(b[1]))&& \
|
||||
((a[2])==(b[2]))&& \
|
||||
((a[3])==(b[3]))&& \
|
||||
((a[4])==(b[4]))&& \
|
||||
((a[5])==(b[5])))
|
||||
|
||||
/******************************************************
|
||||
* Constants
|
||||
******************************************************/
|
||||
#define SCAN_LONGEST_WAIT_TIME (4500)
|
||||
|
||||
|
||||
#define MAC_FMT "%02x:%02x:%02x:%02x:%02x:%02x"
|
||||
|
||||
#define PSCAN_ENABLE 0x01 //enable for partial channel scan
|
||||
#define PSCAN_FAST_SURVEY 0x02 //set to select scan time to FAST_SURVEY_TO, otherwise SURVEY_TO
|
||||
#define PSCAN_SIMPLE_CONFIG 0x04 //set to select scan time to FAST_SURVEY_TO and resend probe request
|
||||
|
||||
/******************************************************
|
||||
* Type Definitions
|
||||
******************************************************/
|
||||
|
||||
/** Scan result callback function pointer type
|
||||
*
|
||||
* @param result_ptr : A pointer to the pointer that indicates where to put the next scan result
|
||||
* @param user_data : User provided data
|
||||
*/
|
||||
typedef void (*rtw_scan_result_callback_t)( rtw_scan_result_t** result_ptr, void* user_data );
|
||||
typedef rtw_result_t (*rtw_scan_result_handler_t)( rtw_scan_handler_result_t* malloced_scan_result );
|
||||
|
||||
/******************************************************
|
||||
* Structures
|
||||
******************************************************/
|
||||
typedef struct {
|
||||
char *buf;
|
||||
int buf_len;
|
||||
} scan_buf_arg;
|
||||
|
||||
/******************************************************
|
||||
* Structures
|
||||
******************************************************/
|
||||
typedef struct internal_scan_handler{
|
||||
rtw_scan_result_t** pap_details;
|
||||
rtw_scan_result_t * ap_details;
|
||||
int scan_cnt;
|
||||
rtw_bool_t scan_complete;
|
||||
unsigned char max_ap_size;
|
||||
rtw_scan_result_handler_t gscan_result_handler;
|
||||
#if SCAN_USE_SEMAPHORE
|
||||
void *scan_semaphore;
|
||||
#else
|
||||
int scan_running;
|
||||
#endif
|
||||
void* user_data;
|
||||
unsigned int scan_start_time;
|
||||
} internal_scan_handler_t;
|
||||
|
||||
typedef struct {
|
||||
rtw_network_info_t network_info;
|
||||
void *join_sema;
|
||||
} internal_join_result_t;
|
||||
|
||||
/******************************************************
|
||||
* Function Declarations
|
||||
******************************************************/
|
||||
/**
|
||||
* Initialises Realtek WiFi API System
|
||||
*
|
||||
* - Initialises the required parts of the software platform
|
||||
* i.e. worker, event registering, semaphore, etc.
|
||||
*
|
||||
* - Initialises the RTW API thread which handles the asynchronous event
|
||||
*
|
||||
* @return RTW_SUCCESS if initialization is successful, RTW_ERROR otherwise
|
||||
*/
|
||||
int wifi_manager_init(void);
|
||||
|
||||
/** Joins a Wi-Fi network
|
||||
*
|
||||
* Scans for, associates and authenticates with a Wi-Fi network.
|
||||
* On successful return, the system is ready to send data packets.
|
||||
*
|
||||
* @param[in] ssid : A null terminated string containing the SSID name of the network to join
|
||||
* @param[in] security_type : Authentication type:
|
||||
* - RTW_SECURITY_OPEN - Open Security
|
||||
* - RTW_SECURITY_WEP_PSK - WEP Security with open authentication
|
||||
* - RTW_SECURITY_WEP_SHARED - WEP Security with shared authentication
|
||||
* - RTW_SECURITY_WPA_TKIP_PSK - WPA Security
|
||||
* - RTW_SECURITY_WPA2_AES_PSK - WPA2 Security using AES cipher
|
||||
* - RTW_SECURITY_WPA2_TKIP_PSK - WPA2 Security using TKIP cipher
|
||||
* - RTW_SECURITY_WPA2_MIXED_PSK - WPA2 Security using AES and/or TKIP ciphers
|
||||
* @param[in] password : A byte array containing either the
|
||||
* cleartext security key for WPA/WPA2
|
||||
* secured networks, or a pointer to
|
||||
* an array of rtw_wep_key_t
|
||||
* structures for WEP secured networks
|
||||
* @param[in] ssid_len : The length of the SSID in
|
||||
* bytes.
|
||||
* @param[in] password_len : The length of the security_key in
|
||||
* bytes.
|
||||
* @param[in] key_id : The index of the wep key.
|
||||
* @param[in] semaphore : A user provided semaphore that is flagged when the join is complete
|
||||
*
|
||||
* @return RTW_SUCCESS : when the system is joined and ready
|
||||
* to send data packets
|
||||
* RTW_ERROR : if an error occurred
|
||||
*/
|
||||
int wifi_connect(
|
||||
char *ssid,
|
||||
rtw_security_t security_type,
|
||||
char *password,
|
||||
int ssid_len,
|
||||
int password_len,
|
||||
int key_id,
|
||||
void *semaphore);
|
||||
|
||||
int wifi_connect_bssid(
|
||||
unsigned char bssid[ETH_ALEN],
|
||||
char *ssid,
|
||||
rtw_security_t security_type,
|
||||
char *password,
|
||||
int bssid_len,
|
||||
int ssid_len,
|
||||
int password_len,
|
||||
int key_id,
|
||||
void *semaphore);
|
||||
|
||||
/** Disassociates from a Wi-Fi network.
|
||||
*
|
||||
* @return RTW_SUCCESS : On successful disassociation from
|
||||
* the AP
|
||||
* RTW_ERROR : If an error occurred
|
||||
*/
|
||||
int wifi_disconnect(void);
|
||||
|
||||
/** Check if the interface specified is up.
|
||||
*
|
||||
* @return RTW_TRUE : If it's up
|
||||
* RTW_FALSE : If it's not
|
||||
*/
|
||||
int wifi_is_connected_to_ap(void);
|
||||
/*check if wifi has connected to AP before dhcp
|
||||
*
|
||||
* @return RTW_SUCCESS:if conneced
|
||||
RTW_ERROR :if not connect
|
||||
*/
|
||||
|
||||
|
||||
int wifi_is_up(rtw_interface_t interface);
|
||||
|
||||
/** Determines if a particular interface is ready to transceive ethernet packets
|
||||
*
|
||||
* @param Radio interface to check, options are
|
||||
* RTW_STA_INTERFACE, RTW_AP_INTERFACE
|
||||
* @return RTW_SUCCESS : if the interface is ready to
|
||||
* transceive ethernet packets
|
||||
* @return RTW_NOTFOUND : no AP with a matching SSID was
|
||||
* found
|
||||
* @return RTW_NOT_AUTHENTICATED: a matching AP was found but
|
||||
* it won't let you
|
||||
* authenticate. This can
|
||||
* occur if this device is
|
||||
* in the block list on the
|
||||
* AP.
|
||||
* @return RTW_NOT_KEYED: the device has authenticated and
|
||||
* associated but has not completed
|
||||
* the key exchange. This can occur
|
||||
* if the passphrase is incorrect.
|
||||
* @return RTW_ERROR : if the interface is not ready to
|
||||
* transceive ethernet packets
|
||||
*/
|
||||
int wifi_is_ready_to_transceive(rtw_interface_t interface);
|
||||
|
||||
/** ----------------------------------------------------------------------
|
||||
* WARNING : This function is for internal use only!
|
||||
* ----------------------------------------------------------------------
|
||||
* This function sets the current Media Access Control (MAC) address of the
|
||||
* 802.11 device.
|
||||
*
|
||||
* @param[in] mac Wi-Fi MAC address
|
||||
* @return RTW_SUCCESS or RTW_ERROR
|
||||
*/
|
||||
int wifi_set_mac_address(char * mac);
|
||||
|
||||
/** Retrieves the current Media Access Control (MAC) address
|
||||
* (or Ethernet hardware address) of the 802.11 device
|
||||
*
|
||||
* @param mac Pointer to a variable that the current MAC address will be written to
|
||||
* @return RTW_SUCCESS or RTW_ERROR
|
||||
*/
|
||||
int wifi_get_mac_address(char * mac);
|
||||
|
||||
/** Enables powersave mode
|
||||
*
|
||||
* @return @ref rtw_result_t
|
||||
*/
|
||||
int wifi_enable_powersave(void);
|
||||
|
||||
/** Disables 802.11 power save mode
|
||||
*
|
||||
* @return RTW_SUCCESS : if power save mode was successfully
|
||||
* disabled
|
||||
* RTW_ERROR : if power save mode was not successfully
|
||||
* disabled
|
||||
*/
|
||||
int wifi_disable_powersave(void);
|
||||
|
||||
/** Gets the tx power in index units
|
||||
*
|
||||
* @param dbm : The variable to receive the tx power in index.
|
||||
*
|
||||
* @return RTW_SUCCESS : if successful
|
||||
* RTW_ERROR : if not successful
|
||||
*/
|
||||
int wifi_get_txpower(int *poweridx);
|
||||
|
||||
/** Sets the tx power in index units
|
||||
*
|
||||
* @param dbm : The desired tx power in index.
|
||||
*
|
||||
* @return RTW_SUCCESS : if tx power was successfully set
|
||||
* RTW_ERROR : if tx power was not successfully set
|
||||
*/
|
||||
int wifi_set_txpower(int poweridx);
|
||||
|
||||
/** Get the associated clients with SoftAP
|
||||
*
|
||||
* @param client_list_buffer : the location where the client
|
||||
* list will be stored
|
||||
* @param buffer_length : the buffer length.
|
||||
*
|
||||
* @return RTW_SUCCESS : if result was successfully get
|
||||
* RTW_ERROR : if result was not successfully get
|
||||
*/
|
||||
int wifi_get_associated_client_list(void * client_list_buffer, unsigned short buffer_length);
|
||||
|
||||
/** Get the SoftAP information
|
||||
*
|
||||
* @param ap_info : the location where the AP info will be
|
||||
* stored
|
||||
* @param security : the security type.
|
||||
*
|
||||
* @return RTW_SUCCESS : if result was successfully get
|
||||
* RTW_ERROR : if result was not successfully get
|
||||
*/
|
||||
int wifi_get_ap_info(rtw_bss_info_t * ap_info, rtw_security_t* security);
|
||||
|
||||
/** Set the country code to driver to determine the channel set
|
||||
*
|
||||
* @param country_code : the country code.
|
||||
*
|
||||
* @return RTW_SUCCESS : if result was successfully set
|
||||
* RTW_ERROR : if result was not successfully set
|
||||
*/
|
||||
int wifi_set_country(rtw_country_code_t country_code);
|
||||
|
||||
/** Retrieve the latest RSSI value
|
||||
*
|
||||
* @param rssi: The location where the RSSI value will be stored
|
||||
*
|
||||
* @return RTW_SUCCESS : if the RSSI was succesfully retrieved
|
||||
* RTW_ERROR : if the RSSI was not retrieved
|
||||
*/
|
||||
int wifi_get_rssi(int *pRSSI);
|
||||
|
||||
/** Set the current channel on STA interface
|
||||
*
|
||||
* @param channel : The desired channel
|
||||
*
|
||||
* @return RTW_SUCCESS : if the channel was successfully set
|
||||
* RTW_ERROR : if the channel was not successfully
|
||||
* set
|
||||
*/
|
||||
int wifi_set_channel(int channel);
|
||||
|
||||
/** Get the current channel on STA interface
|
||||
*
|
||||
* @param channel : A pointer to the variable where the
|
||||
* channel value will be written
|
||||
*
|
||||
* @return RTW_SUCCESS : if the channel was successfully read
|
||||
* RTW_ERROR : if the channel was not successfully
|
||||
* read
|
||||
*/
|
||||
int wifi_get_channel(int *channel);
|
||||
|
||||
/** Registers interest in a multicast address
|
||||
* Once a multicast address has been registered, all packets detected on the
|
||||
* medium destined for that address are forwarded to the host.
|
||||
* Otherwise they are ignored.
|
||||
*
|
||||
* @param mac: Ethernet MAC address
|
||||
*
|
||||
* @return RTW_SUCCESS : if the address was registered
|
||||
* successfully
|
||||
* RTW_ERROR : if the address was not registered
|
||||
*/
|
||||
int wifi_register_multicast_address(rtw_mac_t *mac);
|
||||
|
||||
/** Unregisters interest in a multicast address
|
||||
* Once a multicast address has been unregistered, all packets detected on the
|
||||
* medium destined for that address are ignored.
|
||||
*
|
||||
* @param mac: Ethernet MAC address
|
||||
*
|
||||
* @return RTW_SUCCESS : if the address was unregistered
|
||||
* successfully
|
||||
* RTW_ERROR : if the address was not unregistered
|
||||
*/
|
||||
int wifi_unregister_multicast_address(rtw_mac_t *mac);
|
||||
|
||||
int wifi_rf_on(void);
|
||||
int wifi_rf_off(void);
|
||||
|
||||
/** Turn on the Wi-Fi device
|
||||
*
|
||||
* - Bring the Wireless interface "Up"
|
||||
* - Initialises the driver thread which arbitrates access
|
||||
* to the SDIO/SPI bus
|
||||
*
|
||||
* @param mode: wifi work mode
|
||||
*
|
||||
* @return RTW_SUCCESS : if the WiFi chip was initialised
|
||||
* successfully
|
||||
* RTW_ERROR : if the WiFi chip was not initialised
|
||||
* successfully
|
||||
*/
|
||||
int wifi_on(rtw_mode_t mode);
|
||||
|
||||
/**
|
||||
* Turn off the Wi-Fi device
|
||||
*
|
||||
* - Bring the Wireless interface "Down"
|
||||
* - De-Initialises the driver thread which arbitrates access
|
||||
* to the SDIO/SPI bus
|
||||
*
|
||||
* @return RTW_SUCCESS if deinitialization is successful,
|
||||
* RTW_ERROR otherwise
|
||||
*/
|
||||
int wifi_off(void);
|
||||
|
||||
/**
|
||||
* Set IPS/LPS mode
|
||||
*
|
||||
* @param[in] ips_mode : The desired IPS mode. It become effective when wlan enter ips.
|
||||
* @param[in] lps_mode : The desired LPS mode. It become effective when wlan enter lps.
|
||||
*
|
||||
* @return RTW_SUCCESS if setting LPS mode successful
|
||||
* RTW_ERROR otherwise
|
||||
*/
|
||||
int wifi_set_power_mode(unsigned char ips_mode, unsigned char lps_mode);
|
||||
|
||||
/**
|
||||
* Set TDMA parameters
|
||||
*
|
||||
* @param[in] slot_period : We separate TBTT into 2 or 3 slots.
|
||||
* If we separate TBTT into 2 slots, then slot_period should be larger or equal to 50ms.
|
||||
* It means 2 slot period is
|
||||
* slot_period, 100-slot_period
|
||||
* If we separate TBTT into 3 slots, then slot_period should be less or equal to 33ms.
|
||||
* It means 3 slot period is
|
||||
* 100 - 2 * slot_period, slot_period, slot_period
|
||||
* @param[in] rfon_period_len_1: rf on period of slot 1
|
||||
* @param[in] rfon_period_len_2: rf on period of slot 2
|
||||
* @param[in] rfon_period_len_3: rf on period of slot 3
|
||||
*
|
||||
* @return RTW_SUCCESS if setting TDMA parameters successful
|
||||
* RTW_ERROR otherwise
|
||||
*/
|
||||
int wifi_set_tdma_param(unsigned char slot_period, unsigned char rfon_period_len_1, unsigned char rfon_period_len_2, unsigned char rfon_period_len_3);
|
||||
|
||||
/**
|
||||
* Set LPS DTIM
|
||||
*
|
||||
* @param[in] dtim : In LPS, the package can be buffered at AP side.
|
||||
* STA leave LPS until dtim count of packages buffered at AP side.
|
||||
*
|
||||
* @return RTW_SUCCESS if setting LPS dtim successful
|
||||
* RTW_ERROR otherwise
|
||||
*/
|
||||
int wifi_set_lps_dtim(unsigned char dtim);
|
||||
|
||||
/**
|
||||
* Get LPS DTIM
|
||||
*
|
||||
* @param[out] dtim : In LPS, the package can be buffered at AP side.
|
||||
* STA leave LPS until dtim count of packages buffered at AP side.
|
||||
*
|
||||
* @return RTW_SUCCESS if getting LPS dtim successful
|
||||
* RTW_ERROR otherwise
|
||||
*/
|
||||
int wifi_get_lps_dtim(unsigned char *dtim);
|
||||
|
||||
/** Starts an infrastructure WiFi network
|
||||
*
|
||||
* @warning If a STA interface is active when this function is called, the softAP will\n
|
||||
* start on the same channel as the STA. It will NOT use the channel provided!
|
||||
*
|
||||
* @param[in] ssid : A null terminated string containing
|
||||
* the SSID name of the network to join
|
||||
* @param[in] security_type : Authentication type: \n
|
||||
* - RTW_SECURITY_OPEN - Open Security \n
|
||||
* - RTW_SECURITY_WPA_TKIP_PSK - WPA Security \n
|
||||
* - RTW_SECURITY_WPA2_AES_PSK - WPA2 Security using AES cipher \n
|
||||
* - RTW_SECURITY_WPA2_MIXED_PSK - WPA2 Security using AES and/or TKIP ciphers \n
|
||||
* - WEP security is NOT IMPLEMENTED. It is NOT SECURE! \n
|
||||
* @param[in] password : A byte array containing the cleartext
|
||||
* security key for the network
|
||||
* @param[in] ssid_len : The length of the SSID in
|
||||
* bytes.
|
||||
* @param[in] password_len : The length of the security_key in
|
||||
* bytes.
|
||||
* @param[in] channel : 802.11 channel number
|
||||
*
|
||||
* @return RTW_SUCCESS : if successfully creates an AP
|
||||
* RTW_ERROR : if an error occurred
|
||||
*/
|
||||
int wifi_start_ap(
|
||||
char *ssid,
|
||||
rtw_security_t security_type,
|
||||
char *password,
|
||||
int ssid_len,
|
||||
int password_len,
|
||||
int channel);
|
||||
|
||||
/** Starts an infrastructure WiFi network with hidden SSID
|
||||
*
|
||||
* @warning If a STA interface is active when this function is called, the softAP will\n
|
||||
* start on the same channel as the STA. It will NOT use the channel provided!
|
||||
*
|
||||
* @param[in] ssid : A null terminated string containing
|
||||
* the SSID name of the network to join
|
||||
* @param[in] security_type : Authentication type: \n
|
||||
* - RTW_SECURITY_OPEN - Open Security \n
|
||||
* - RTW_SECURITY_WPA_TKIP_PSK - WPA Security \n
|
||||
* - RTW_SECURITY_WPA2_AES_PSK - WPA2 Security using AES cipher \n
|
||||
* - RTW_SECURITY_WPA2_MIXED_PSK - WPA2 Security using AES and/or TKIP ciphers \n
|
||||
* - WEP security is NOT IMPLEMENTED. It is NOT SECURE! \n
|
||||
* @param[in] password : A byte array containing the cleartext
|
||||
* security key for the network
|
||||
* @param[in] ssid_len : The length of the SSID in
|
||||
* bytes.
|
||||
* @param[in] password_len : The length of the security_key in
|
||||
* bytes.
|
||||
* @param[in] channel : 802.11 channel number
|
||||
*
|
||||
* @return RTW_SUCCESS : if successfully creates an AP
|
||||
* RTW_ERROR : if an error occurred
|
||||
*/
|
||||
int wifi_start_ap_with_hidden_ssid(
|
||||
char *ssid,
|
||||
rtw_security_t security_type,
|
||||
char *password,
|
||||
int ssid_len,
|
||||
int password_len,
|
||||
int channel);
|
||||
|
||||
/** Initiates a scan to search for 802.11 networks.
|
||||
*
|
||||
* The scan progressively accumulates results over time, and
|
||||
* may take between 1 and 3 seconds to complete. The results of
|
||||
* the scan will be individually provided to the callback
|
||||
* function. Note: The callback function will be executed in
|
||||
* the context of the RTW thread.
|
||||
*
|
||||
* @param[in] scan_type : Specifies whether the scan should
|
||||
* be Active, Passive or scan
|
||||
* Prohibited channels
|
||||
* @param[in] bss_type : Specifies whether the scan should
|
||||
* search for Infrastructure
|
||||
* networks (those using an Access
|
||||
* Point), Ad-hoc networks, or both
|
||||
* types.
|
||||
* @param result_ptr[in] : Scan specific ssid. The first 4
|
||||
* bytes is ssid lenth, and ssid name
|
||||
* append after it.
|
||||
* If no specific ssid need to scan,
|
||||
* PLEASE CLEAN result_ptr before pass
|
||||
* it into parameter.
|
||||
* @param result_ptr[out] : a pointer to a pointer to a result
|
||||
* storage structure.
|
||||
*
|
||||
* @note : When scanning specific channels, devices with a
|
||||
* strong signal strength on nearby channels may be
|
||||
* detected
|
||||
*
|
||||
* @return RTW_SUCCESS or RTW_ERROR
|
||||
*/
|
||||
int wifi_scan(rtw_scan_type_t scan_type,
|
||||
rtw_bss_type_t bss_type,
|
||||
void* result_ptr);
|
||||
|
||||
/** Initiates a scan to search for 802.11 networks, a higher
|
||||
* level API based on wifi_scan to simplify the scan
|
||||
* operation.
|
||||
*
|
||||
* The scan results will be list by the order of RSSI.
|
||||
* It may demand hundreds bytes memory during scan
|
||||
* processing according to the quantity of AP nearby.
|
||||
*
|
||||
* @param results_handler[in] : the callback function which
|
||||
* will receive and process the result data.
|
||||
* @param user_data[in] : user specific data that will be
|
||||
* passed directly to the callback function
|
||||
*
|
||||
* @note : Callback must not use blocking functions, since it is
|
||||
* called from the context of the RTW thread.
|
||||
* @note : The callback, user_data variables will
|
||||
* be referenced after the function returns. Those
|
||||
* variables must remain valid until the scan is
|
||||
* complete.
|
||||
*
|
||||
* @return RTW_SUCCESS or RTW_ERROR
|
||||
*/
|
||||
int wifi_scan_networks(rtw_scan_result_handler_t results_handler, void* user_data);
|
||||
int wifi_scan_networks_with_ssid(int (results_handler)(char*, int, char *, void *), void* user_data, int scan_buflen, char* ssid, int ssid_len);
|
||||
|
||||
/** Set the partical scan
|
||||
*
|
||||
* @param channel_list[in] : the channel set the scan will
|
||||
* stay on
|
||||
* @param pscan_config[in] : the pscan_config of the channel set
|
||||
*
|
||||
* @param length[in] : the channel list length
|
||||
*
|
||||
* @return RTW_SUCCESS or RTW_ERROR
|
||||
*/
|
||||
int wifi_set_pscan_chan(__u8 * channel_list,__u8 * pscan_config, __u8 length);
|
||||
|
||||
/** Get the network information
|
||||
*
|
||||
* @param ifname[in] : the name of the interface we are care
|
||||
* @param pSetting[in] : the location where the network
|
||||
* information will be stored
|
||||
*
|
||||
* @return RTW_SUCCESS or RTW_ERROR
|
||||
*/
|
||||
int wifi_get_setting(const char *ifname,rtw_wifi_setting_t *pSetting);
|
||||
|
||||
/** Show the network information
|
||||
*
|
||||
* @param ifname[in] : the name of the interface we are care
|
||||
* @param pSetting[in] : the location where the network
|
||||
* information was stored
|
||||
*
|
||||
* @return RTW_SUCCESS or RTW_ERROR
|
||||
*/
|
||||
int wifi_show_setting(const char *ifname,rtw_wifi_setting_t *pSetting);
|
||||
|
||||
/** Set the network mode according to the data rate it's
|
||||
* supported
|
||||
*
|
||||
* @param mode[in] : the network mode
|
||||
*
|
||||
* @return RTW_SUCCESS or RTW_ERROR
|
||||
*/
|
||||
int wifi_set_network_mode(rtw_network_mode_t mode);
|
||||
|
||||
/** Set the chip to worke in the promisc mode
|
||||
*
|
||||
* @param enabled[in] : enabled can be set 0, 1 and 2. if enabled is zero, disable the promisc, else enable the promisc.
|
||||
* 0 means disable the promisc
|
||||
* 1 means enable the promisc
|
||||
* 2 means enable the promisc special for length is used
|
||||
* @param callback[in] : the callback function which will
|
||||
* receive and process the netowork data.
|
||||
* @param len_used[in] : specify if the the promisc length is
|
||||
* used.
|
||||
*
|
||||
* @return RTW_SUCCESS or RTW_ERROR
|
||||
*/
|
||||
int wifi_set_promisc(rtw_rcr_level_t enabled, void (*callback)(unsigned char*, unsigned int, void*), unsigned char len_used);
|
||||
|
||||
/** Set the wps phase
|
||||
*
|
||||
* @param is_trigger_wps[in] : to trigger wps function or not
|
||||
*
|
||||
* @return RTW_SUCCESS or RTW_ERROR
|
||||
*/
|
||||
int wifi_set_wps_phase(unsigned char is_trigger_wps);
|
||||
|
||||
/** Restarts an infrastructure WiFi network
|
||||
*
|
||||
* @warning If a STA interface is active when this function is called, the softAP will\n
|
||||
* start on the same channel as the STA. It will NOT use the channel provided!
|
||||
*
|
||||
* @param[in] ssid : A null terminated string containing
|
||||
* the SSID name of the network to join
|
||||
* @param[in] security_type : Authentication type: \n
|
||||
* - RTW_SECURITY_OPEN - Open Security \n
|
||||
* - RTW_SECURITY_WPA_TKIP_PSK - WPA Security \n
|
||||
* - RTW_SECURITY_WPA2_AES_PSK - WPA2 Security using AES cipher \n
|
||||
* - RTW_SECURITY_WPA2_MIXED_PSK - WPA2 Security using AES and/or TKIP ciphers \n
|
||||
* - WEP security is NOT IMPLEMENTED. It is NOT SECURE! \n
|
||||
* @param[in] password : A byte array containing the cleartext
|
||||
* security key for the network
|
||||
* @param[in] ssid_len : The length of the SSID in
|
||||
* bytes.
|
||||
* @param[in] password_len : The length of the security_key in
|
||||
* bytes.
|
||||
* @param[in] channel : 802.11 channel number
|
||||
*
|
||||
* @return RTW_SUCCESS : if successfully creates an AP
|
||||
* RTW_ERROR : if an error occurred
|
||||
*/
|
||||
int wifi_restart_ap(
|
||||
unsigned char *ssid,
|
||||
rtw_security_t security_type,
|
||||
unsigned char *password,
|
||||
int ssid_len,
|
||||
int password_len,
|
||||
int channel);
|
||||
|
||||
int wifi_config_autoreconnect(__u8 mode, __u8 retyr_times, __u16 timeout);
|
||||
int wifi_set_autoreconnect(__u8 mode);
|
||||
int wifi_get_autoreconnect(__u8 *mode);
|
||||
int wifi_get_last_error(void);
|
||||
/** Present device disconnect reason while connecting
|
||||
*
|
||||
*@return RTW_NO_ERROR = 0,
|
||||
* RTW_NONE_NETWORK = 1,
|
||||
* RTW_CONNECT_FAIL = 2,
|
||||
* RTW_WRONG_PASSWORD = 3 ,
|
||||
* RTW_DHCP_FAIL = 4,
|
||||
* RTW_UNKNOWN, initial status
|
||||
*/
|
||||
|
||||
|
||||
#ifdef CONFIG_CUSTOM_IE
|
||||
#ifndef BIT
|
||||
#define BIT(x) ((__u32)1 << (x))
|
||||
#endif
|
||||
|
||||
#ifndef _CUSTOM_IE_TYPE_
|
||||
#define _CUSTOM_IE_TYPE_
|
||||
enum CUSTOM_IE_TYPE{
|
||||
PROBE_REQ = BIT(0),
|
||||
PROBE_RSP = BIT(1),
|
||||
BEACON = BIT(2),
|
||||
};
|
||||
#endif /* _CUSTOM_IE_TYPE_ */
|
||||
|
||||
/* ie format
|
||||
* +-----------+--------+-----------------------+
|
||||
* |element ID | length | content in length byte|
|
||||
* +-----------+--------+-----------------------+
|
||||
*
|
||||
* type: refer to CUSTOM_IE_TYPE
|
||||
*/
|
||||
#ifndef _CUS_IE_
|
||||
#define _CUS_IE_
|
||||
typedef struct _cus_ie{
|
||||
__u8 *ie;
|
||||
__u8 type;
|
||||
}cus_ie, *p_cus_ie;
|
||||
#endif /* _CUS_IE_ */
|
||||
|
||||
int wifi_add_custom_ie(void *cus_ie, int ie_num);
|
||||
|
||||
int wifi_update_custom_ie(void *cus_ie, int ie_index);
|
||||
|
||||
int wifi_del_custom_ie(void);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_PROMISC
|
||||
void wifi_init_packet_filter(void);
|
||||
int wifi_add_packet_filter(unsigned char filter_id, rtw_packet_filter_pattern_t *patt, rtw_packet_filter_rule_e rule);
|
||||
int wifi_enable_packet_filter(unsigned char filter_id);
|
||||
int wifi_disable_packet_filter(unsigned char filter_id);
|
||||
int wifi_remove_packet_filter(unsigned char filter_id);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __WIFI_API_H
|
||||
|
||||
//----------------------------------------------------------------------------//
|
258
component/common/api/wifi/wifi_ind.c
Normal file
258
component/common/api/wifi/wifi_ind.c
Normal file
|
@ -0,0 +1,258 @@
|
|||
//----------------------------------------------------------------------------//
|
||||
#include "wifi/wifi_ind.h"
|
||||
#include "wifi/wifi_conf.h"
|
||||
#include "osdep_service.h"
|
||||
#include "platform_stdlib.h"
|
||||
|
||||
/******************************************************
|
||||
* Constants
|
||||
******************************************************/
|
||||
|
||||
#define WIFI_INDICATE_MSG 0
|
||||
#define WIFI_MANAGER_STACKSIZE 1300
|
||||
#define WIFI_MANAGER_PRIORITY (0) //Actual priority is 4 since calling rtw_create_task
|
||||
#define WIFI_MANAGER_Q_SZ 8
|
||||
|
||||
#define WIFI_EVENT_MAX_ROW 3
|
||||
/******************************************************
|
||||
* Globals
|
||||
******************************************************/
|
||||
|
||||
static event_list_elem_t event_callback_list[WIFI_EVENT_MAX][WIFI_EVENT_MAX_ROW];
|
||||
#if CONFIG_WIFI_IND_USE_THREAD
|
||||
static rtw_worker_thread_t wifi_worker_thread;
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------//
|
||||
#if CONFIG_WIFI_IND_USE_THREAD
|
||||
static rtw_result_t rtw_send_event_to_worker(int event_cmd, char *buf, int buf_len, int flags)
|
||||
{
|
||||
rtw_event_message_t message;
|
||||
int i;
|
||||
rtw_result_t ret = RTW_SUCCESS;
|
||||
char *local_buf = NULL;
|
||||
|
||||
if(event_cmd >= WIFI_EVENT_MAX)
|
||||
return RTW_BADARG;
|
||||
|
||||
for(i = 0; i < WIFI_EVENT_MAX_ROW; i++){
|
||||
if(event_callback_list[event_cmd][i].handler == NULL)
|
||||
continue;
|
||||
|
||||
message.function = (event_handler_t)event_callback_list[event_cmd][i].handler;
|
||||
message.buf_len = buf_len;
|
||||
if(buf_len){
|
||||
local_buf = (char*)pvPortMalloc(buf_len);
|
||||
if(local_buf == NULL)
|
||||
return RTW_NOMEM;
|
||||
memcpy(local_buf, buf, buf_len);
|
||||
//printf("\n!!!!!Allocate %p(%d) for evcmd %d\n", local_buf, buf_len, event_cmd);
|
||||
}
|
||||
message.buf = local_buf;
|
||||
message.flags = flags;
|
||||
message.user_data = event_callback_list[event_cmd][i].handler_user_data;
|
||||
|
||||
ret = rtw_push_to_xqueue(&wifi_worker_thread.event_queue, &message, 0);
|
||||
if(ret != RTW_SUCCESS){
|
||||
if(local_buf){
|
||||
printf("\r\nrtw_send_event_to_worker: enqueue cmd %d failed and free %p(%d)\n", event_cmd, local_buf, buf_len);
|
||||
vPortFree(local_buf);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
static rtw_result_t rtw_indicate_event_handle(int event_cmd, char *buf, int buf_len, int flags)
|
||||
{
|
||||
rtw_event_handler_t handle = NULL;
|
||||
int i;
|
||||
|
||||
if(event_cmd >= WIFI_EVENT_MAX)
|
||||
return RTW_BADARG;
|
||||
|
||||
for(i = 0; i < WIFI_EVENT_MAX_ROW; i++){
|
||||
handle = event_callback_list[event_cmd][i].handler;
|
||||
if(handle == NULL)
|
||||
continue;
|
||||
handle(buf, buf_len, flags, event_callback_list[event_cmd][i].handler_user_data);
|
||||
}
|
||||
|
||||
return RTW_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
|
||||
void wifi_indication( WIFI_EVENT_INDICATE event, char *buf, int buf_len, int flags)
|
||||
{
|
||||
//
|
||||
// If upper layer application triggers additional operations on receiving of wext_wlan_indicate,
|
||||
// please strictly check current stack size usage (by using uxTaskGetStackHighWaterMark() )
|
||||
// , and tries not to share the same stack with wlan driver if remaining stack space is
|
||||
// not available for the following operations.
|
||||
// ex: using semaphore to notice another thread.
|
||||
switch(event)
|
||||
{
|
||||
case WIFI_EVENT_DISCONNECT:
|
||||
#if(WIFI_INDICATE_MSG==1)
|
||||
printf("\n\r %s():Disconnection indication received", __FUNCTION__);
|
||||
#endif
|
||||
break;
|
||||
case WIFI_EVENT_CONNECT:
|
||||
// For WPA/WPA2 mode, indication of connection does not mean data can be
|
||||
// correctly transmitted or received. Data can be correctly transmitted or
|
||||
// received only when 4-way handshake is done.
|
||||
// Please check WIFI_EVENT_FOURWAY_HANDSHAKE_DONE event
|
||||
#if(WIFI_INDICATE_MSG==1)
|
||||
// Sample: return mac address
|
||||
if(buf != NULL && buf_len == 6)
|
||||
{
|
||||
printf("\n\r%s():Connect indication received: %02x:%02x:%02x:%02x:%02x:%02x", __FUNCTION__,
|
||||
buf[0],buf[1],buf[2],buf[3],buf[4],buf[5]);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
case WIFI_EVENT_FOURWAY_HANDSHAKE_DONE:
|
||||
#if(WIFI_INDICATE_MSG==1)
|
||||
if(buf != NULL)
|
||||
{
|
||||
if(buf_len == strlen(IW_EXT_STR_FOURWAY_DONE))
|
||||
printf("\n\r%s():%s", __FUNCTION__, buf);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
case WIFI_EVENT_SCAN_RESULT_REPORT:
|
||||
#if(WIFI_INDICATE_MSG==1)
|
||||
printf("\n\r%s(): WIFI_EVENT_SCAN_RESULT_REPORT\n", __func__);
|
||||
#endif
|
||||
break;
|
||||
case WIFI_EVENT_SCAN_DONE:
|
||||
#if(WIFI_INDICATE_MSG==1)
|
||||
printf("\n\r%s(): WIFI_EVENT_SCAN_DONE\n", __func__);
|
||||
#endif
|
||||
break;
|
||||
case WIFI_EVENT_RECONNECTION_FAIL:
|
||||
#if(WIFI_INDICATE_MSG==1)
|
||||
if(buf != NULL){
|
||||
if(buf_len == strlen(IW_EXT_STR_RECONNECTION_FAIL))
|
||||
printf("\n\r%s", buf);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
case WIFI_EVENT_NO_NETWORK:
|
||||
#if(WIFI_INDICATE_MSG==1)
|
||||
printf("\n\r%s(): WIFI_EVENT_NO_NETWORK\n", __func__);
|
||||
#endif
|
||||
break;
|
||||
#if CONFIG_ENABLE_P2P
|
||||
case WIFI_EVENT_SEND_ACTION_DONE:
|
||||
#if(WIFI_INDICATE_MSG==1)
|
||||
printf("\n\r%s(): WIFI_EVENT_SEND_ACTION_DONE\n", __func__);
|
||||
#endif
|
||||
break;
|
||||
case WIFI_EVENT_RX_MGNT:
|
||||
#if(WIFI_INDICATE_MSG==1)
|
||||
printf("\n\r%s(): WIFI_EVENT_RX_MGNT\n", __func__);
|
||||
#endif
|
||||
break;
|
||||
#endif //CONFIG_ENABLE_P2P
|
||||
case WIFI_EVENT_STA_ASSOC:
|
||||
#if(WIFI_INDICATE_MSG==1)
|
||||
printf("\n\r%s(): WIFI_EVENT_STA_ASSOC\n", __func__);
|
||||
#endif
|
||||
break;
|
||||
case WIFI_EVENT_STA_DISASSOC:
|
||||
#if(WIFI_INDICATE_MSG==1)
|
||||
printf("\n\r%s(): WIFI_EVENT_STA_DISASSOC\n", __func__);
|
||||
#endif
|
||||
break;
|
||||
#ifdef CONFIG_WPS
|
||||
case WIFI_EVENT_STA_WPS_START:
|
||||
#if(WIFI_INDICATE_MSG==1)
|
||||
printf("\n\r%s(): WIFI_EVENT_STA_WPS_START\n", __func__);
|
||||
#endif
|
||||
break;
|
||||
case WIFI_EVENT_WPS_FINISH:
|
||||
#if(WIFI_INDICATE_MSG==1)
|
||||
printf("\n\r%s(): WIFI_EVENT_WPS_FINISH\n", __func__);
|
||||
#endif
|
||||
break;
|
||||
case WIFI_EVENT_EAPOL_RECVD:
|
||||
#if(WIFI_INDICATE_MSG==1)
|
||||
printf("\n\r%s(): WIFI_EVENT_EAPOL_RECVD\n", __func__);
|
||||
#endif
|
||||
break;
|
||||
#endif
|
||||
case WIFI_EVENT_BEACON_AFTER_DHCP:
|
||||
#if(WIFI_INDICATE_MSG==1)
|
||||
printf("\n\r%s(): WIFI_EVENT_BEACON_AFTER_DHCP\n", __func__);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
#if CONFIG_INIC_EN
|
||||
inic_indicate_event(event, buf, buf_len, flags);
|
||||
#endif//CONFIG_INIC_EN
|
||||
|
||||
#if CONFIG_WIFI_IND_USE_THREAD
|
||||
rtw_send_event_to_worker(event, buf, buf_len, flags);
|
||||
#else
|
||||
rtw_indicate_event_handle(event, buf, buf_len, flags);
|
||||
#endif
|
||||
}
|
||||
|
||||
void wifi_reg_event_handler(unsigned int event_cmds, rtw_event_handler_t handler_func, void *handler_user_data)
|
||||
{
|
||||
int i = 0, j = 0;
|
||||
if(event_cmds < WIFI_EVENT_MAX){
|
||||
for(i=0; i < WIFI_EVENT_MAX_ROW; i++){
|
||||
if(event_callback_list[event_cmds][i].handler == NULL){
|
||||
for(j=0; j<WIFI_EVENT_MAX_ROW; j++){
|
||||
if(event_callback_list[event_cmds][j].handler == handler_func){
|
||||
return;
|
||||
}
|
||||
}
|
||||
event_callback_list[event_cmds][i].handler = handler_func;
|
||||
event_callback_list[event_cmds][i].handler_user_data = handler_user_data;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wifi_unreg_event_handler(unsigned int event_cmds, rtw_event_handler_t handler_func)
|
||||
{
|
||||
int i;
|
||||
if(event_cmds < WIFI_EVENT_MAX){
|
||||
for(i = 0; i < WIFI_EVENT_MAX_ROW; i++){
|
||||
if(event_callback_list[event_cmds][i].handler == handler_func){
|
||||
event_callback_list[event_cmds][i].handler = NULL;
|
||||
event_callback_list[event_cmds][i].handler_user_data = NULL;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void init_event_callback_list(){
|
||||
memset(event_callback_list, 0, sizeof(event_callback_list));
|
||||
}
|
||||
|
||||
int wifi_manager_init()
|
||||
{
|
||||
#if CONFIG_WIFI_IND_USE_THREAD
|
||||
rtw_create_worker_thread(&wifi_worker_thread,
|
||||
WIFI_MANAGER_PRIORITY,
|
||||
WIFI_MANAGER_STACKSIZE,
|
||||
WIFI_MANAGER_Q_SZ);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
void rtw_wifi_manager_deinit()
|
||||
{
|
||||
#if CONFIG_WIFI_IND_USE_THREAD
|
||||
rtw_delete_worker_thread(&wifi_worker_thread);
|
||||
#endif
|
||||
}
|
||||
|
34
component/common/api/wifi/wifi_ind.h
Normal file
34
component/common/api/wifi/wifi_ind.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
#ifndef _WIFI_INDICATE_H
|
||||
#define _WIFI_INDICATE_H
|
||||
#include "wifi_conf.h"
|
||||
|
||||
typedef void (*rtw_event_handler_t)(char *buf, int buf_len, int flags, void* handler_user_data );
|
||||
|
||||
typedef struct
|
||||
{
|
||||
// WIFI_EVENT_INDICATE event_cmd;
|
||||
rtw_event_handler_t handler;
|
||||
void* handler_user_data;
|
||||
} event_list_elem_t;
|
||||
|
||||
void init_event_callback_list(void);
|
||||
extern void wifi_indication( WIFI_EVENT_INDICATE event, char *buf, int buf_len, int flags);
|
||||
/** Register the event listener
|
||||
*
|
||||
* @param[in] event_cmds : The event command number indicated
|
||||
* @param[in] handler_func : the callback function which will
|
||||
* receive and process the event
|
||||
* @param[in] handler_user_data : user specific data that will be
|
||||
* passed directly to the callback function
|
||||
*
|
||||
* @note : Set the same event_cmds with empty handler_func will
|
||||
* unregister the event_cmds
|
||||
*
|
||||
* @return RTW_SUCCESS : if successfully registers the event
|
||||
* RTW_ERROR : if an error occurred
|
||||
*/
|
||||
extern void wifi_reg_event_handler(unsigned int event_cmds, rtw_event_handler_t handler_func, void *handler_user_data);
|
||||
extern void wifi_unreg_event_handler(unsigned int event_cmds, rtw_event_handler_t handler_func);
|
||||
|
||||
#endif //_WIFI_INDICATE_H
|
||||
|
461
component/common/api/wifi/wifi_promisc.c
Normal file
461
component/common/api/wifi/wifi_promisc.c
Normal file
|
@ -0,0 +1,461 @@
|
|||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "main.h"
|
||||
#include "tcpip.h"
|
||||
#include "wifi/wifi_conf.h"
|
||||
|
||||
#ifndef CONFIG_WLAN
|
||||
#define CONFIG_WLAN 1
|
||||
#endif
|
||||
|
||||
#if CONFIG_WLAN
|
||||
#include <platform/platform_stdlib.h>
|
||||
|
||||
// Add extra interfaces to make release sdk able to determine promisc API linking
|
||||
void promisc_deinit(void *padapter)
|
||||
{
|
||||
#ifdef CONFIG_PROMISC
|
||||
_promisc_deinit(padapter);
|
||||
#endif
|
||||
}
|
||||
|
||||
int promisc_recv_func(void *padapter, void *rframe)
|
||||
{
|
||||
// Never reach here if not define CONFIG_PROMISC
|
||||
#ifdef CONFIG_PROMISC
|
||||
return _promisc_recv_func(padapter, rframe);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
int promisc_set(rtw_rcr_level_t enabled, void (*callback)(unsigned char*, unsigned int, void*), unsigned char len_used)
|
||||
{
|
||||
#ifdef CONFIG_PROMISC
|
||||
return _promisc_set(enabled, callback, len_used);
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
unsigned char is_promisc_enabled(void)
|
||||
{
|
||||
#ifdef CONFIG_PROMISC
|
||||
return _is_promisc_enabled();
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
int promisc_get_fixed_channel(void *fixed_bssid, u8 *ssid, int *ssid_length)
|
||||
{
|
||||
#ifdef CONFIG_PROMISC
|
||||
return _promisc_get_fixed_channel(fixed_bssid, ssid, ssid_length);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
// End of Add extra interfaces
|
||||
|
||||
struct eth_frame {
|
||||
struct eth_frame *prev;
|
||||
struct eth_frame *next;
|
||||
unsigned char da[6];
|
||||
unsigned char sa[6];
|
||||
unsigned int len;
|
||||
unsigned char type;
|
||||
signed char rssi;
|
||||
};
|
||||
|
||||
#if CONFIG_INIC_CMD_RSP
|
||||
#if defined(__IAR_SYSTEMS_ICC__)
|
||||
#pragma pack(1)
|
||||
#endif
|
||||
struct inic_eth_frame {
|
||||
unsigned char da[6];
|
||||
unsigned char sa[6];
|
||||
unsigned int len;
|
||||
unsigned char type;
|
||||
};
|
||||
#if defined(__IAR_SYSTEMS_ICC__)
|
||||
#pragma pack()
|
||||
#endif
|
||||
|
||||
static struct inic_eth_frame *inic_frame, *inic_frame_tail = NULL;
|
||||
static int inic_frame_cnt = 0;
|
||||
#define MAX_INIC_FRAME_NUM 50 //maximum packets for each channel
|
||||
extern void inic_c2h_msg(const char *atcmd, char status, char *msg, u16 msg_len);
|
||||
#endif
|
||||
|
||||
struct eth_buffer {
|
||||
struct eth_frame *head;
|
||||
struct eth_frame *tail;
|
||||
};
|
||||
|
||||
static struct eth_buffer eth_buffer;
|
||||
|
||||
#ifdef CONFIG_PROMISC
|
||||
#define MAX_PACKET_FILTER_INFO 5
|
||||
#define FILTER_ID_INIT_VALUE 10
|
||||
rtw_packet_filter_info_t paff_array[MAX_PACKET_FILTER_INFO]={0, 0, 0, 0, 0};
|
||||
static u8 packet_filter_enable_num = 0;
|
||||
|
||||
void promisc_init_packet_filter()
|
||||
{
|
||||
int i = 0;
|
||||
for(i=0; i<MAX_PACKET_FILTER_INFO; i++){
|
||||
paff_array[i].filter_id = FILTER_ID_INIT_VALUE;
|
||||
paff_array[i].enable = 0;
|
||||
paff_array[i].patt.mask_size = 0;
|
||||
paff_array[i].rule = RTW_POSITIVE_MATCHING;
|
||||
paff_array[i].patt.mask = NULL;
|
||||
paff_array[i].patt.pattern = NULL;
|
||||
}
|
||||
packet_filter_enable_num = 0;
|
||||
}
|
||||
|
||||
int promisc_add_packet_filter(u8 filter_id, rtw_packet_filter_pattern_t *patt, rtw_packet_filter_rule_e rule)
|
||||
{
|
||||
int i = 0;
|
||||
while(i < MAX_PACKET_FILTER_INFO){
|
||||
if(paff_array[i].filter_id == FILTER_ID_INIT_VALUE){
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
if(i == MAX_PACKET_FILTER_INFO)
|
||||
return -1;
|
||||
|
||||
paff_array[i].filter_id = filter_id;
|
||||
|
||||
paff_array[i].patt.offset= patt->offset;
|
||||
paff_array[i].patt.mask_size = patt->mask_size;
|
||||
paff_array[i].patt.mask = pvPortMalloc(patt->mask_size);
|
||||
memcpy(paff_array[i].patt.mask, patt->mask, patt->mask_size);
|
||||
paff_array[i].patt.pattern= pvPortMalloc(patt->mask_size);
|
||||
memcpy(paff_array[i].patt.pattern, patt->pattern, patt->mask_size);
|
||||
|
||||
paff_array[i].rule = rule;
|
||||
paff_array[i].enable = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int promisc_enable_packet_filter(u8 filter_id)
|
||||
{
|
||||
int i = 0;
|
||||
while(i < MAX_PACKET_FILTER_INFO){
|
||||
if(paff_array[i].filter_id == filter_id)
|
||||
break;
|
||||
i++;
|
||||
}
|
||||
|
||||
if(i == MAX_PACKET_FILTER_INFO)
|
||||
return -1;
|
||||
|
||||
paff_array[i].enable = 1;
|
||||
packet_filter_enable_num++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int promisc_disable_packet_filter(u8 filter_id)
|
||||
{
|
||||
int i = 0;
|
||||
while(i < MAX_PACKET_FILTER_INFO){
|
||||
if(paff_array[i].filter_id == filter_id)
|
||||
break;
|
||||
i++;
|
||||
}
|
||||
|
||||
if(i == MAX_PACKET_FILTER_INFO)
|
||||
return -1;
|
||||
|
||||
paff_array[i].enable = 0;
|
||||
packet_filter_enable_num--;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int promisc_remove_packet_filter(u8 filter_id)
|
||||
{
|
||||
int i = 0;
|
||||
while(i < MAX_PACKET_FILTER_INFO){
|
||||
if(paff_array[i].filter_id == filter_id)
|
||||
break;
|
||||
i++;
|
||||
}
|
||||
|
||||
if(i == MAX_PACKET_FILTER_INFO)
|
||||
return -1;
|
||||
|
||||
paff_array[i].filter_id = FILTER_ID_INIT_VALUE;
|
||||
paff_array[i].enable = 0;
|
||||
paff_array[i].patt.mask_size = 0;
|
||||
paff_array[i].rule = 0;
|
||||
if(paff_array[i].patt.mask){
|
||||
vPortFree(paff_array[i].patt.mask);
|
||||
paff_array[i].patt.mask = NULL;
|
||||
}
|
||||
|
||||
if(paff_array[i].patt.pattern){
|
||||
vPortFree(paff_array[i].patt.pattern);
|
||||
paff_array[i].patt.pattern = NULL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Make callback simple to prevent latency to wlan rx when promiscuous mode */
|
||||
static void promisc_callback(unsigned char *buf, unsigned int len, void* userdata)
|
||||
{
|
||||
struct eth_frame *frame = (struct eth_frame *) pvPortMalloc(sizeof(struct eth_frame));
|
||||
|
||||
if(frame) {
|
||||
frame->prev = NULL;
|
||||
frame->next = NULL;
|
||||
memcpy(frame->da, buf, 6);
|
||||
memcpy(frame->sa, buf+6, 6);
|
||||
frame->len = len;
|
||||
frame->rssi = ((ieee80211_frame_info_t *)userdata)->rssi;
|
||||
taskENTER_CRITICAL();
|
||||
|
||||
if(eth_buffer.tail) {
|
||||
eth_buffer.tail->next = frame;
|
||||
frame->prev = eth_buffer.tail;
|
||||
eth_buffer.tail = frame;
|
||||
}
|
||||
else {
|
||||
eth_buffer.head = frame;
|
||||
eth_buffer.tail = frame;
|
||||
}
|
||||
|
||||
taskEXIT_CRITICAL();
|
||||
}
|
||||
}
|
||||
|
||||
struct eth_frame* retrieve_frame(void)
|
||||
{
|
||||
struct eth_frame *frame = NULL;
|
||||
|
||||
taskENTER_CRITICAL();
|
||||
|
||||
if(eth_buffer.head) {
|
||||
frame = eth_buffer.head;
|
||||
|
||||
if(eth_buffer.head->next) {
|
||||
eth_buffer.head = eth_buffer.head->next;
|
||||
eth_buffer.head->prev = NULL;
|
||||
}
|
||||
else {
|
||||
eth_buffer.head = NULL;
|
||||
eth_buffer.tail = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
taskEXIT_CRITICAL();
|
||||
|
||||
return frame;
|
||||
}
|
||||
|
||||
static void promisc_test(int duration, unsigned char len_used)
|
||||
{
|
||||
int ch;
|
||||
unsigned int start_time;
|
||||
struct eth_frame *frame;
|
||||
eth_buffer.head = NULL;
|
||||
eth_buffer.tail = NULL;
|
||||
|
||||
wifi_enter_promisc_mode();
|
||||
wifi_set_promisc(RTW_PROMISC_ENABLE, promisc_callback, len_used);
|
||||
|
||||
for(ch = 1; ch <= 13; ch ++) {
|
||||
if(wifi_set_channel(ch) == 0)
|
||||
printf("\n\n\rSwitch to channel(%d)", ch);
|
||||
|
||||
start_time = xTaskGetTickCount();
|
||||
|
||||
while(1) {
|
||||
unsigned int current_time = xTaskGetTickCount();
|
||||
|
||||
if((current_time - start_time) < (duration * configTICK_RATE_HZ)) {
|
||||
frame = retrieve_frame();
|
||||
|
||||
if(frame) {
|
||||
int i;
|
||||
printf("\n\rDA:");
|
||||
for(i = 0; i < 6; i ++)
|
||||
printf(" %02x", frame->da[i]);
|
||||
printf(", SA:");
|
||||
for(i = 0; i < 6; i ++)
|
||||
printf(" %02x", frame->sa[i]);
|
||||
printf(", len=%d", frame->len);
|
||||
printf(", RSSI=%d", frame->rssi);
|
||||
#if CONFIG_INIC_CMD_RSP
|
||||
if(inic_frame_tail){
|
||||
if(inic_frame_cnt < MAX_INIC_FRAME_NUM){
|
||||
memcpy(inic_frame_tail->da, frame->da, 6);
|
||||
memcpy(inic_frame_tail->sa, frame->sa, 6);
|
||||
inic_frame_tail->len = frame->len;
|
||||
inic_frame_tail++;
|
||||
inic_frame_cnt++;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
vPortFree((void *) frame);
|
||||
}
|
||||
else
|
||||
vTaskDelay(1); //delay 1 tick
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
#if CONFIG_INIC_CMD_RSP
|
||||
if(inic_frame){
|
||||
inic_c2h_msg("ATWM", RTW_SUCCESS, (char *)inic_frame, sizeof(struct inic_eth_frame)*inic_frame_cnt);
|
||||
memset(inic_frame, '\0', sizeof(struct inic_eth_frame)*MAX_INIC_FRAME_NUM);
|
||||
inic_frame_tail = inic_frame;
|
||||
inic_frame_cnt = 0;
|
||||
rtw_msleep_os(10);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
wifi_set_promisc(RTW_PROMISC_DISABLE, NULL, 0);
|
||||
|
||||
while((frame = retrieve_frame()) != NULL)
|
||||
vPortFree((void *) frame);
|
||||
}
|
||||
|
||||
static void promisc_callback_all(unsigned char *buf, unsigned int len, void* userdata)
|
||||
{
|
||||
struct eth_frame *frame = (struct eth_frame *) pvPortMalloc(sizeof(struct eth_frame));
|
||||
|
||||
if(frame) {
|
||||
frame->prev = NULL;
|
||||
frame->next = NULL;
|
||||
memcpy(frame->da, buf+4, 6);
|
||||
memcpy(frame->sa, buf+10, 6);
|
||||
frame->len = len;
|
||||
/*
|
||||
* type is the first byte of Frame Control Field of 802.11 frame
|
||||
* If the from/to ds information is needed, type could be reused as follows:
|
||||
* frame->type = ((((ieee80211_frame_info_t *)userdata)->i_fc & 0x0100) == 0x0100) ? 2 : 1;
|
||||
* 1: from ds; 2: to ds
|
||||
*/
|
||||
frame->type = *buf;
|
||||
frame->rssi = ((ieee80211_frame_info_t *)userdata)->rssi;
|
||||
|
||||
taskENTER_CRITICAL();
|
||||
|
||||
if(eth_buffer.tail) {
|
||||
eth_buffer.tail->next = frame;
|
||||
frame->prev = eth_buffer.tail;
|
||||
eth_buffer.tail = frame;
|
||||
}
|
||||
else {
|
||||
eth_buffer.head = frame;
|
||||
eth_buffer.tail = frame;
|
||||
}
|
||||
|
||||
taskEXIT_CRITICAL();
|
||||
}
|
||||
}
|
||||
static void promisc_test_all(int duration, unsigned char len_used)
|
||||
{
|
||||
int ch;
|
||||
unsigned int start_time;
|
||||
struct eth_frame *frame;
|
||||
eth_buffer.head = NULL;
|
||||
eth_buffer.tail = NULL;
|
||||
|
||||
wifi_enter_promisc_mode();
|
||||
wifi_set_promisc(RTW_PROMISC_ENABLE_2, promisc_callback_all, len_used);
|
||||
|
||||
for(ch = 1; ch <= 13; ch ++) {
|
||||
if(wifi_set_channel(ch) == 0)
|
||||
printf("\n\n\rSwitch to channel(%d)", ch);
|
||||
|
||||
start_time = xTaskGetTickCount();
|
||||
|
||||
while(1) {
|
||||
unsigned int current_time = xTaskGetTickCount();
|
||||
|
||||
if((current_time - start_time) < (duration * configTICK_RATE_HZ)) {
|
||||
frame = retrieve_frame();
|
||||
|
||||
if(frame) {
|
||||
int i;
|
||||
printf("\n\rTYPE: 0x%x, ", frame->type);
|
||||
printf("DA:");
|
||||
for(i = 0; i < 6; i ++)
|
||||
printf(" %02x", frame->da[i]);
|
||||
printf(", SA:");
|
||||
for(i = 0; i < 6; i ++)
|
||||
printf(" %02x", frame->sa[i]);
|
||||
printf(", len=%d", frame->len);
|
||||
printf(", RSSI=%d", frame->rssi);
|
||||
#if CONFIG_INIC_CMD_RSP
|
||||
if(inic_frame_tail){
|
||||
if(inic_frame_cnt < MAX_INIC_FRAME_NUM){
|
||||
memcpy(inic_frame_tail->da, frame->da, 6);
|
||||
memcpy(inic_frame_tail->sa, frame->sa, 6);
|
||||
inic_frame_tail->len = frame->len;
|
||||
inic_frame_tail->type = frame->type;
|
||||
inic_frame_tail++;
|
||||
inic_frame_cnt++;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
vPortFree((void *) frame);
|
||||
}
|
||||
else
|
||||
vTaskDelay(1); //delay 1 tick
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
#if CONFIG_INIC_CMD_RSP
|
||||
if(inic_frame){
|
||||
inic_c2h_msg("ATWM", RTW_SUCCESS, (char *)inic_frame, sizeof(struct inic_eth_frame)*inic_frame_cnt);
|
||||
memset(inic_frame, '\0', sizeof(struct inic_eth_frame)*MAX_INIC_FRAME_NUM);
|
||||
inic_frame_tail = inic_frame;
|
||||
inic_frame_cnt = 0;
|
||||
rtw_msleep_os(10);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
wifi_set_promisc(RTW_PROMISC_DISABLE, NULL, 0);
|
||||
|
||||
while((frame = retrieve_frame()) != NULL)
|
||||
vPortFree((void *) frame);
|
||||
}
|
||||
|
||||
void cmd_promisc(int argc, char **argv)
|
||||
{
|
||||
int duration;
|
||||
#if CONFIG_INIC_CMD_RSP
|
||||
inic_frame_tail = inic_frame = pvPortMalloc(sizeof(struct inic_eth_frame)*MAX_INIC_FRAME_NUM);
|
||||
if(inic_frame == NULL){
|
||||
inic_c2h_msg("ATWM", RTW_BUFFER_UNAVAILABLE_TEMPORARY, NULL, 0);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#ifdef CONFIG_PROMISC
|
||||
wifi_init_packet_filter();
|
||||
#endif
|
||||
if((argc == 2) && ((duration = atoi(argv[1])) > 0))
|
||||
//promisc_test(duration, 0);
|
||||
promisc_test_all(duration, 0);
|
||||
else if((argc == 3) && ((duration = atoi(argv[1])) > 0) && (strcmp(argv[2], "with_len") == 0))
|
||||
promisc_test(duration, 1);
|
||||
else
|
||||
printf("\n\rUsage: %s DURATION_SECONDS [with_len]", argv[0]);
|
||||
#if CONFIG_INIC_CMD_RSP
|
||||
if(inic_frame)
|
||||
vPortFree(inic_frame);
|
||||
inic_frame_tail = NULL;
|
||||
inic_frame_cnt = 0;
|
||||
#endif
|
||||
}
|
||||
#endif //#if CONFIG_WLAN
|
1077
component/common/api/wifi/wifi_simple_config.c
Normal file
1077
component/common/api/wifi/wifi_simple_config.c
Normal file
File diff suppressed because it is too large
Load diff
20
component/common/api/wifi/wifi_simple_config.h
Normal file
20
component/common/api/wifi/wifi_simple_config.h
Normal file
|
@ -0,0 +1,20 @@
|
|||
#ifndef __WIFI_SIMPLE_CONFIG_H
|
||||
#define __WIFI_SIMPLE_CONFIG_H
|
||||
/*****************************wifi_simple_config.h****************************/
|
||||
enum sc_result {
|
||||
SC_ERROR = -1, /* default error code*/
|
||||
SC_NO_CONTROLLER_FOUND = 1, /* cannot get sta(controller) in the air which starts a simple config session */
|
||||
SC_CONTROLLER_INFO_PARSE_FAIL, /* cannot parse the sta's info */
|
||||
SC_TARGET_CHANNEL_SCAN_FAIL, /* cannot scan the target channel */
|
||||
SC_JOIN_BSS_FAIL, /* fail to connect to target ap */
|
||||
SC_DHCP_FAIL, /* fail to get ip address from target ap */
|
||||
/* fail to create udp socket to send info to controller. note that client isolation
|
||||
must be turned off in ap. we cannot know if ap has configured this */
|
||||
SC_UDP_SOCKET_CREATE_FAIL,
|
||||
SC_TERMINATE,
|
||||
SC_SUCCESS, /* default success code */
|
||||
|
||||
};
|
||||
int SC_send_simple_config_ack(u8 round);
|
||||
|
||||
#endif //__WIFI_SIMPLE_CONFIG_H
|
99
component/common/api/wifi/wifi_simple_config_parser.h
Normal file
99
component/common/api/wifi/wifi_simple_config_parser.h
Normal file
|
@ -0,0 +1,99 @@
|
|||
#ifndef __SIMPLE_CONFIG_H__
|
||||
#define __SIMPLE_CONFIG_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* This macro means user take simple config
|
||||
* lib to another platform such as linux, and
|
||||
* have no rom crypto libs of simple config,
|
||||
* so we take simple_config_crypto as a sw lib
|
||||
* This macro is used by Realtek internal to generate simple config lib
|
||||
* Please delete this macro after generation.
|
||||
*/
|
||||
#define SIMPLE_CONFIG_PLATFORM_LIB 0
|
||||
|
||||
#include "platform_opts.h"
|
||||
#include "autoconf.h"
|
||||
|
||||
|
||||
|
||||
/* platform related settings */
|
||||
#if (defined(CONFIG_PLATFORM_8195A)|| defined(CONFIG_PLATFORM_8711B))
|
||||
#undef u32
|
||||
#undef s32
|
||||
#undef u8
|
||||
#undef s8
|
||||
#undef u16
|
||||
#undef s16
|
||||
typedef unsigned int u32;
|
||||
typedef signed int s32;
|
||||
typedef unsigned char u8;
|
||||
typedef char s8;
|
||||
typedef unsigned short int u16;
|
||||
typedef signed short int s16;
|
||||
#else
|
||||
#include "osdep_service.h"
|
||||
#endif
|
||||
|
||||
typedef int (*simple_config_printf_fn) (char const * fmt, ...);
|
||||
typedef void* (*simple_config_memset_fn) (void *dst0, s32 Val, u32 length);
|
||||
typedef void* (*simple_config_memcpy_fn) ( void *s1, const void *s2, u32 n );
|
||||
typedef u32 (*simple_config_strlen_fn) (const char *s);
|
||||
typedef char * (*simple_config_strcpy_fn) (char *dest, const char *src);
|
||||
typedef void (*simple_config_free_fn) (u8 *pbuf, u32 sz);
|
||||
typedef u8* (*simple_config_zmalloc_fn) (u32 sz);
|
||||
typedef u8* (*simple_config_malloc_fn) (u32 sz);
|
||||
typedef int (*simple_config_memcmp_fn) (const void *av, const void *bv, u32 len);
|
||||
typedef u32 (*simple_config_ntohl_fn)(u32 x);
|
||||
|
||||
|
||||
|
||||
struct simple_config_lib_config {
|
||||
simple_config_printf_fn printf;
|
||||
simple_config_memset_fn memset;
|
||||
simple_config_memcpy_fn memcpy;
|
||||
simple_config_strlen_fn strlen;
|
||||
simple_config_strcpy_fn strcpy;
|
||||
simple_config_free_fn free;
|
||||
simple_config_zmalloc_fn zmalloc;
|
||||
simple_config_malloc_fn malloc;
|
||||
simple_config_memcmp_fn memcmp;
|
||||
simple_config_ntohl_fn _ntohl;
|
||||
|
||||
|
||||
int *is_promisc_callback_unlock;
|
||||
|
||||
};
|
||||
|
||||
#pragma pack(1)
|
||||
struct rtk_test_sc {
|
||||
/* API exposed to user */
|
||||
unsigned char ssid[32];
|
||||
unsigned char password[65];
|
||||
unsigned int ip_addr;
|
||||
};
|
||||
|
||||
/* expose data */
|
||||
extern s32 is_promisc_callback_unlock;
|
||||
extern u8 g_bssid[6];
|
||||
extern u8 get_channel_flag;
|
||||
extern u8 g_security_mode;
|
||||
|
||||
/* expose API */
|
||||
extern s32 rtk_sc_init(char *custom_pin_code, struct simple_config_lib_config* config);
|
||||
extern s32 rtk_start_parse_packet(u8 *da, u8 *sa, s32 len, void * user_data, void *backup_sc);
|
||||
extern void rtk_restart_simple_config(void);
|
||||
extern void rtk_sc_deinit();
|
||||
extern void wifi_enter_promisc_mode();
|
||||
extern void whc_fix_channel();
|
||||
extern void whc_unfix_channel();
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __SIMPLE_CONFIG_H__*/
|
1323
component/common/api/wifi/wifi_util.c
Normal file
1323
component/common/api/wifi/wifi_util.c
Normal file
File diff suppressed because it is too large
Load diff
74
component/common/api/wifi/wifi_util.h
Normal file
74
component/common/api/wifi/wifi_util.h
Normal file
|
@ -0,0 +1,74 @@
|
|||
#ifndef _UTIL_H
|
||||
#define _UTIL_H
|
||||
|
||||
#include <wireless.h>
|
||||
#include <wlan_intf.h>
|
||||
#include <wifi_constants.h>
|
||||
#include "wifi_structures.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int wext_get_ssid(const char *ifname, __u8 *ssid);
|
||||
int wext_set_ssid(const char *ifname, const __u8 *ssid, __u16 ssid_len);
|
||||
int wext_set_auth_param(const char *ifname, __u16 idx, __u32 value);
|
||||
int wext_set_key_ext(const char *ifname, __u16 alg, const __u8 *addr, int key_idx, int set_tx, const __u8 *seq, __u16 seq_len, __u8 *key, __u16 key_len);
|
||||
int wext_get_enc_ext(const char *ifname, __u16 *alg, __u8 *key_idx, __u8 *passphrase);
|
||||
int wext_set_passphrase(const char *ifname, const __u8 *passphrase, __u16 passphrase_len);
|
||||
int wext_get_passphrase(const char *ifname, __u8 *passphrase);
|
||||
int wext_set_mode(const char *ifname, int mode);
|
||||
int wext_get_mode(const char *ifname, int *mode);
|
||||
int wext_set_ap_ssid(const char *ifname, const __u8 *ssid, __u16 ssid_len);
|
||||
int wext_set_country(const char *ifname, rtw_country_code_t country_code);
|
||||
int wext_get_rssi(const char *ifname, int *rssi);
|
||||
int wext_set_channel(const char *ifname, __u8 ch);
|
||||
int wext_get_channel(const char *ifname, __u8 *ch);
|
||||
int wext_register_multicast_address(const char *ifname, rtw_mac_t *mac);
|
||||
int wext_unregister_multicast_address(const char *ifname, rtw_mac_t *mac);
|
||||
int wext_set_scan(const char *ifname, char *buf, __u16 buf_len, __u16 flags);
|
||||
int wext_get_scan(const char *ifname, char *buf, __u16 buf_len);
|
||||
int wext_set_mac_address(const char *ifname, char * mac);
|
||||
int wext_get_mac_address(const char *ifname, char * mac);
|
||||
int wext_enable_powersave(const char *ifname, __u8 lps_mode, __u8 ips_mode);
|
||||
int wext_disable_powersave(const char *ifname);
|
||||
int wext_set_tdma_param(const char *ifname, __u8 slot_period, __u8 rfon_period_len_1, __u8 rfon_period_len_2, __u8 rfon_period_len_3);
|
||||
int wext_set_lps_dtim(const char *ifname, __u8 lps_dtim);
|
||||
int wext_get_lps_dtim(const char *ifname, __u8 *lps_dtim);
|
||||
int wext_get_tx_power(const char *ifname, __u8 *poweridx);
|
||||
int wext_set_txpower(const char *ifname, int poweridx);
|
||||
int wext_get_associated_client_list(const char *ifname, void * client_list_buffer, __u16 buffer_length);
|
||||
int wext_get_ap_info(const char *ifname, rtw_bss_info_t * ap_info, rtw_security_t* security);
|
||||
int wext_mp_command(const char *ifname, char *cmd, int show_msg);
|
||||
int wext_private_command(const char *ifname, char *cmd, int show_msg);
|
||||
int wext_private_command_with_retval(const char *ifname, char *cmd, char *ret_buf, int ret_len);
|
||||
void wext_wlan_indicate(unsigned int cmd, union iwreq_data *wrqu, char *extra);
|
||||
int wext_set_pscan_channel(const char *ifname, __u8 *ch, __u8 *pscan_config, __u8 length);
|
||||
int wext_set_autoreconnect(const char *ifname, __u8 mode, __u8 retyr_times, __u16 timeout);
|
||||
int wext_get_autoreconnect(const char *ifname, __u8 *mode);
|
||||
int wext_set_adaptivity(rtw_adaptivity_mode_t adaptivity_mode);
|
||||
int wext_set_adaptivity_th_l2h_ini(__u8 l2h_threshold);
|
||||
int wext_get_auto_chl(const char *ifname, unsigned char *channel_set, unsigned char channel_num);
|
||||
int wext_set_sta_num(unsigned char ap_sta_num);
|
||||
int wext_del_station(const char *ifname, unsigned char* hwaddr);
|
||||
int wext_init_mac_filter(void);
|
||||
int wext_deinit_mac_filter(void);
|
||||
int wext_add_mac_filter(unsigned char* hwaddr);
|
||||
int wext_del_mac_filter(unsigned char* hwaddr);
|
||||
#ifdef CONFIG_CUSTOM_IE
|
||||
int wext_add_custom_ie(const char *ifname, void * cus_ie, int ie_num);
|
||||
int wext_update_custom_ie(const char *ifname, void * cus_ie, int ie_index);
|
||||
int wext_del_custom_ie(const char *ifname);
|
||||
#endif
|
||||
|
||||
#define wext_handshake_done rltk_wlan_handshake_done
|
||||
|
||||
int wext_send_mgnt(const char *ifname, char *buf, __u16 buf_len, __u16 flags);
|
||||
int wext_send_eapol(const char *ifname, char *buf, __u16 buf_len, __u16 flags);
|
||||
int wext_set_gen_ie(const char *ifname, char *buf, __u16 buf_len, __u16 flags);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _UTIL_H */
|
247
component/common/drivers/ethernet_mii/ethernet_mii.c
Normal file
247
component/common/drivers/ethernet_mii/ethernet_mii.c
Normal file
|
@ -0,0 +1,247 @@
|
|||
#include "rtl8195a.h"
|
||||
#include "build_info.h"
|
||||
#ifdef PLATFORM_FREERTOS
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "semphr.h"
|
||||
#endif
|
||||
#include "osdep_service.h"
|
||||
#include "lwip_netconf.h"
|
||||
#include "ethernet_api.h"
|
||||
#include "lwip_intf.h"
|
||||
#include "ethernet_mii.h"
|
||||
#include "platform_opts.h"
|
||||
#include "ethernet_ex_api.h"
|
||||
|
||||
static _sema mii_rx_sema;
|
||||
static _mutex mii_tx_mutex;
|
||||
|
||||
extern struct netif xnetif[NET_IF_NUM];
|
||||
|
||||
static u8 TX_BUFFER[1518];
|
||||
static u8 RX_BUFFER[1518];
|
||||
|
||||
static u8 *pTmpTxDesc = NULL;
|
||||
static u8 *pTmpRxDesc = NULL;
|
||||
static u8 *pTmpTxPktBuf = NULL;
|
||||
static u8 *pTmpRxPktBuf = NULL;
|
||||
|
||||
|
||||
int dhcp_ethernet_mii = 1;
|
||||
int ethernet_if_default = 0;
|
||||
|
||||
extern int lwip_init_done;
|
||||
|
||||
static _sema mii_linkup_sema;
|
||||
|
||||
void mii_rx_thread(void* param){
|
||||
u32 len = 0;
|
||||
u8* pbuf = RX_BUFFER;
|
||||
while(1){
|
||||
if (rtw_down_sema(&mii_rx_sema) == _FAIL){
|
||||
DBG_8195A("%s, Take Semaphore Fail\n", __FUNCTION__);
|
||||
goto exit;
|
||||
}
|
||||
// continues read the rx ring until its empty
|
||||
while(1){
|
||||
len = ethernet_receive();
|
||||
if(len){
|
||||
//DBG_8195A("mii_recv len = %d\n\r", len);
|
||||
ethernet_read(pbuf, len);
|
||||
// calculate the time duration
|
||||
ethernetif_mii_recv(&xnetif[NET_IF_NUM - 1], len);
|
||||
//__rtl_memDump_v1_00(pbuf, len, "ethernet_receive Data:");
|
||||
//rtw_memset(pbuf, 0, len);
|
||||
}else if(len == 0){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
exit:
|
||||
rtw_free_sema(&mii_rx_sema);
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void dhcp_start_mii(void* param)
|
||||
{
|
||||
while(1)
|
||||
{
|
||||
if (rtw_down_sema(&mii_linkup_sema) == _FAIL){
|
||||
DBG_8195A("%s, Take Semaphore Fail\n", __FUNCTION__);
|
||||
break;
|
||||
}
|
||||
LwIP_DHCP(NET_IF_NUM - 1, DHCP_START);
|
||||
}
|
||||
rtw_free_sema(&mii_linkup_sema);
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
|
||||
void mii_intr_handler(u32 Event, u32 Data)
|
||||
{
|
||||
switch(Event)
|
||||
{
|
||||
case ETH_TXDONE:
|
||||
//DBG_8195A("TX Data = %d\n", Data);
|
||||
break;
|
||||
case ETH_RXDONE:
|
||||
//DBG_8195A("\r\nRX Data = %d\n", Data);
|
||||
// wake up rx thread to receive data
|
||||
rtw_up_sema_from_isr(&mii_rx_sema);
|
||||
break;
|
||||
case ETH_LINKUP:
|
||||
DBG_8195A("Link Up\n");
|
||||
|
||||
if(dhcp_ethernet_mii == 1)
|
||||
rtw_up_sema_from_isr(&mii_linkup_sema);
|
||||
|
||||
break;
|
||||
case ETH_LINKDOWN:
|
||||
DBG_8195A("Link Down\n");
|
||||
|
||||
break;
|
||||
default:
|
||||
DBG_8195A("Unknown event !!\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ethernet_demo(void* param){
|
||||
u8 mac[6];
|
||||
/* Initilaize the LwIP stack */
|
||||
// can not init twice
|
||||
if(!lwip_init_done)
|
||||
LwIP_Init();
|
||||
DBG_8195A("LWIP Init done\n");
|
||||
|
||||
ethernet_irq_hook(mii_intr_handler);
|
||||
|
||||
if(pTmpTxDesc)
|
||||
{
|
||||
free(pTmpTxDesc);
|
||||
pTmpTxDesc = NULL;
|
||||
}
|
||||
if(pTmpRxDesc)
|
||||
{
|
||||
free(pTmpRxDesc);
|
||||
pTmpRxDesc = NULL;
|
||||
}
|
||||
if(pTmpTxPktBuf)
|
||||
{
|
||||
free(pTmpTxPktBuf);
|
||||
pTmpTxPktBuf = NULL;
|
||||
}
|
||||
if(pTmpRxPktBuf)
|
||||
{
|
||||
free(pTmpRxPktBuf);
|
||||
pTmpRxPktBuf = NULL;
|
||||
}
|
||||
|
||||
pTmpTxDesc = (u8 *)malloc(/*MII_TX_DESC_CNT*/MII_TX_DESC_NO * ETH_TX_DESC_SIZE);
|
||||
pTmpRxDesc = (u8 *)malloc(/*MII_RX_DESC_CNT*/MII_RX_DESC_NO * ETH_RX_DESC_SIZE);
|
||||
pTmpTxPktBuf = (u8 *)malloc(/*MII_TX_DESC_CNT*/MII_TX_DESC_NO * ETH_PKT_BUF_SIZE);
|
||||
pTmpRxPktBuf = (u8 *)malloc(/*MII_RX_DESC_CNT*/MII_RX_DESC_NO * ETH_PKT_BUF_SIZE);
|
||||
if(pTmpTxDesc == NULL || pTmpRxDesc == NULL || pTmpTxPktBuf == NULL || pTmpRxPktBuf == NULL)
|
||||
{
|
||||
printf("TX/RX descriptor malloc fail\n");
|
||||
return;
|
||||
}
|
||||
memset(pTmpTxDesc, 0, MII_TX_DESC_NO * ETH_TX_DESC_SIZE);
|
||||
memset(pTmpRxDesc, 0, MII_RX_DESC_NO * ETH_RX_DESC_SIZE);
|
||||
memset(pTmpTxPktBuf, 0, MII_TX_DESC_NO * ETH_PKT_BUF_SIZE);
|
||||
memset(pTmpRxPktBuf, 0, MII_RX_DESC_NO * ETH_PKT_BUF_SIZE);
|
||||
//size 160 128 12288 12288
|
||||
|
||||
ethernet_set_descnum(MII_TX_DESC_NO, MII_RX_DESC_NO);
|
||||
printf("TRX descriptor number setting done\n");
|
||||
ethernet_trx_pre_setting(pTmpTxDesc, pTmpRxDesc, pTmpTxPktBuf, pTmpRxPktBuf);
|
||||
printf("TRX pre setting done\n");
|
||||
|
||||
ethernet_init();
|
||||
|
||||
DBG_INFO_MSG_OFF(_DBG_MII_);
|
||||
DBG_WARN_MSG_OFF(_DBG_MII_);
|
||||
DBG_ERR_MSG_ON(_DBG_MII_);
|
||||
|
||||
/*get mac*/
|
||||
ethernet_address(mac);
|
||||
memcpy((void*)xnetif[NET_IF_NUM - 1].hwaddr,(void*)mac, 6);
|
||||
|
||||
rtw_init_sema(&mii_rx_sema,0);
|
||||
rtw_mutex_init(&mii_tx_mutex);
|
||||
|
||||
if(xTaskCreate(mii_rx_thread, ((const char*)"mii_rx_thread"), 1024, NULL, tskIDLE_PRIORITY+5, NULL) != pdPASS)
|
||||
DBG_8195A("\n\r%s xTaskCreate(mii_rx_thread) failed", __FUNCTION__);
|
||||
|
||||
DBG_8195A("\nEthernet_mii Init done, interface %d",NET_IF_NUM - 1);
|
||||
|
||||
if(dhcp_ethernet_mii == 1)
|
||||
LwIP_DHCP(NET_IF_NUM - 1, DHCP_START);
|
||||
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void ethernet_mii_init()
|
||||
{
|
||||
printf("\ninitializing Ethernet_mii......\n");
|
||||
|
||||
// set the ethernet interface as default
|
||||
ethernet_if_default = 1;
|
||||
rtw_init_sema(&mii_linkup_sema,0);
|
||||
|
||||
if( xTaskCreate((TaskFunction_t)dhcp_start_mii, "DHCP_START_MII", 1024, NULL, 2, NULL) != pdPASS) {
|
||||
DBG_8195A("Cannot create demo task\n\r");
|
||||
}
|
||||
|
||||
if( xTaskCreate((TaskFunction_t)ethernet_demo, "ETHERNET DEMO", 1024, NULL, 2, NULL) != pdPASS) {
|
||||
DBG_8195A("Cannot create demo task\n\r");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void rltk_mii_recv(struct eth_drv_sg *sg_list, int sg_len){
|
||||
struct eth_drv_sg *last_sg;
|
||||
u8* pbuf = RX_BUFFER;
|
||||
|
||||
for (last_sg = &sg_list[sg_len]; sg_list < last_sg; ++sg_list) {
|
||||
if (sg_list->buf != 0) {
|
||||
rtw_memcpy((void *)(sg_list->buf), pbuf, sg_list->len);
|
||||
pbuf+=sg_list->len;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
s8 rltk_mii_send(struct eth_drv_sg *sg_list, int sg_len, int total_len){
|
||||
int ret =0;
|
||||
struct eth_drv_sg *last_sg;
|
||||
u8* pdata = TX_BUFFER;
|
||||
u8 retry_cnt = 0;
|
||||
u32 size = 0;
|
||||
for (last_sg = &sg_list[sg_len]; sg_list < last_sg; ++sg_list) {
|
||||
rtw_memcpy(pdata, (void *)(sg_list->buf), sg_list->len);
|
||||
pdata += sg_list->len;
|
||||
size += sg_list->len;
|
||||
}
|
||||
pdata = TX_BUFFER;
|
||||
//DBG_8195A("mii_send len= %d\n\r", size);
|
||||
rtw_mutex_get(&mii_tx_mutex);
|
||||
while(1){
|
||||
ret = ethernet_write(pdata, size);
|
||||
if(ret > 0){
|
||||
ethernet_send();
|
||||
ret = 0;
|
||||
break;
|
||||
}
|
||||
if(++retry_cnt > 3){
|
||||
DBG_8195A("TX drop\n\r");
|
||||
ret = -1;
|
||||
}
|
||||
else
|
||||
rtw_udelay_os(1);
|
||||
}
|
||||
rtw_mutex_put(&mii_tx_mutex);
|
||||
|
||||
return ret;
|
||||
}
|
9
component/common/drivers/ethernet_mii/ethernet_mii.h
Normal file
9
component/common/drivers/ethernet_mii/ethernet_mii.h
Normal file
|
@ -0,0 +1,9 @@
|
|||
#ifndef __MII_ETHERNETIF_H__
|
||||
#define __MII_ETHERNETIF_H__
|
||||
|
||||
#include "lwip_netconf.h"
|
||||
|
||||
#define MII_TX_DESC_CNT 4
|
||||
#define MII_RX_DESC_CNT 10
|
||||
|
||||
#endif // __MII_ETHERNETIF_H__
|
196
component/common/drivers/i2s/alc5651.c
Normal file
196
component/common/drivers/i2s/alc5651.c
Normal file
|
@ -0,0 +1,196 @@
|
|||
#include <stdio.h>
|
||||
#include "PinNames.h"
|
||||
#include "basic_types.h"
|
||||
#include "diag.h"
|
||||
#include <osdep_api.h>
|
||||
|
||||
#include "i2c_api.h"
|
||||
#include "pinmap.h"
|
||||
|
||||
//#define I2C_MTR_SDA PC_4//PB_3
|
||||
//#define I2C_MTR_SCL PC_5//PB_2
|
||||
#define I2C_MTR_SDA PB_3
|
||||
#define I2C_MTR_SCL PB_2
|
||||
#define I2C_BUS_CLK 100000 //hz
|
||||
|
||||
#define I2C_ALC5651_ADDR (0x34/2)
|
||||
|
||||
#define RT5651_PRIV_INDEX 0x6a
|
||||
#define RT5651_PRIV_DATA 0x6c
|
||||
|
||||
#if defined (__ICCARM__)
|
||||
i2c_t alc5651_i2c;
|
||||
#else
|
||||
volatile i2c_t alc5651_i2c;
|
||||
#define printf DBG_8195A
|
||||
#endif
|
||||
|
||||
static void alc5651_delay(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
i=10000;
|
||||
while (i) {
|
||||
i--;
|
||||
asm volatile ("nop\n\t");
|
||||
}
|
||||
}
|
||||
|
||||
void alc5651_reg_write(unsigned int reg, unsigned int value)
|
||||
{
|
||||
char buf[4];
|
||||
buf[0] = (char)reg;
|
||||
buf[1] = (char)(value>>8);
|
||||
buf[2] = (char)(value&0xff);
|
||||
|
||||
i2c_write(&alc5651_i2c, I2C_ALC5651_ADDR, &buf[0], 3, 1);
|
||||
alc5651_delay();
|
||||
}
|
||||
|
||||
void alc5651_reg_read(unsigned int reg, unsigned int *value)
|
||||
{
|
||||
int tmp;
|
||||
char *buf = (char*)&tmp;
|
||||
|
||||
buf[0] = (char)reg;
|
||||
i2c_write(&alc5651_i2c, I2C_ALC5651_ADDR, &buf[0], 1, 1);
|
||||
alc5651_delay();
|
||||
|
||||
buf[0] = 0xaa;
|
||||
buf[1] = 0xaa;
|
||||
|
||||
i2c_read(&alc5651_i2c, I2C_ALC5651_ADDR, &buf[0], 2, 1);
|
||||
alc5651_delay();
|
||||
|
||||
*value= ((buf[0]&0xFF)<<8)|(buf[1]&0xFF);
|
||||
}
|
||||
|
||||
void alc5651_index_write(unsigned int reg, unsigned int value)
|
||||
{
|
||||
alc5651_reg_write(RT5651_PRIV_INDEX, reg);
|
||||
alc5651_reg_write(RT5651_PRIV_DATA, value);
|
||||
}
|
||||
|
||||
void alc5651_index_read(unsigned int reg, unsigned int *value)
|
||||
{
|
||||
alc5651_reg_write(RT5651_PRIV_INDEX, reg);
|
||||
alc5651_reg_read(RT5651_PRIV_DATA, value);
|
||||
}
|
||||
|
||||
void alc5651_reg_dump(void)
|
||||
{
|
||||
int i;
|
||||
unsigned int value;
|
||||
|
||||
printf("alc5651 codec reg dump\n\r");
|
||||
printf("------------------------\n\r");
|
||||
for(i=0;i<=0xff;i++){
|
||||
alc5651_reg_read(i, &value);
|
||||
printf("%02x : %04x\n\r", i, (unsigned short)value);
|
||||
}
|
||||
printf("------------------------\n\r");
|
||||
}
|
||||
|
||||
void alc5651_index_dump(void)
|
||||
{
|
||||
int i;
|
||||
unsigned int value;
|
||||
|
||||
printf("alc5651 codec index dump\n\r");
|
||||
printf("------------------------\n\r");
|
||||
for(i=0;i<=0xff;i++){
|
||||
alc5651_index_read(i, &value);
|
||||
printf("%02x : %04x\n\r", i, (unsigned short)value);
|
||||
}
|
||||
printf("------------------------\n\r");
|
||||
}
|
||||
|
||||
void alc5651_init(void)
|
||||
{
|
||||
i2c_init(&alc5651_i2c, I2C_MTR_SDA, I2C_MTR_SCL);
|
||||
i2c_frequency(&alc5651_i2c, I2C_BUS_CLK);
|
||||
}
|
||||
|
||||
void alc5651_set_word_len(int len_idx) // interface2
|
||||
{
|
||||
// 0: 16 1: 20 2: 24 3: 8
|
||||
unsigned int val;
|
||||
alc5651_reg_read(0x71,&val);
|
||||
val &= (~(0x3<<2));
|
||||
val |= (len_idx<<2);
|
||||
alc5651_reg_write(0x71,val);
|
||||
alc5651_reg_read(0x70,&val);
|
||||
val &= (~(0x3<<2));
|
||||
val |= (len_idx<<2);
|
||||
alc5651_reg_write(0x70,val);
|
||||
|
||||
}
|
||||
|
||||
void alc5651_init_interface1(void)
|
||||
{
|
||||
alc5651_reg_write(0x00,0x0021);
|
||||
alc5651_reg_write(0x63,0xE8FE);
|
||||
alc5651_reg_write(0x61,0x5800);
|
||||
alc5651_reg_write(0x62,0x0C00);
|
||||
alc5651_reg_write(0x73,0x0000);
|
||||
alc5651_reg_write(0x2A,0x4242);
|
||||
alc5651_reg_write(0x45,0x2000);
|
||||
alc5651_reg_write(0x02,0x4848);
|
||||
alc5651_reg_write(0x8E,0x0019);
|
||||
alc5651_reg_write(0x8F,0x3100);
|
||||
alc5651_reg_write(0x91,0x0E00);
|
||||
alc5651_index_write(0x3D,0x3E00);
|
||||
alc5651_reg_write(0xFA,0x0011);
|
||||
alc5651_reg_write(0x83,0x0800);
|
||||
alc5651_reg_write(0x84,0xA000);
|
||||
alc5651_reg_write(0xFA,0x0C11);
|
||||
alc5651_reg_write(0x64,0x4010);
|
||||
alc5651_reg_write(0x65,0x0C00);
|
||||
alc5651_reg_write(0x61,0x5806);
|
||||
alc5651_reg_write(0x62,0xCC00);
|
||||
alc5651_reg_write(0x3C,0x004F);
|
||||
alc5651_reg_write(0x3E,0x004F);
|
||||
alc5651_reg_write(0x27,0x3820);
|
||||
alc5651_reg_write(0x77,0x0000);
|
||||
}
|
||||
|
||||
void alc5651_init_interface2(void)
|
||||
{
|
||||
int reg_value=0;
|
||||
alc5651_reg_write(0x00,0x0021);//reset all, device id 1
|
||||
alc5651_reg_write(0x63,0xE8FE);//Power managerment control 3:
|
||||
//VREF1&2 on, both slow VREF, MBIAS on, MBIAS bandcap power on, L & R HP Amp on, improve HP Amp driving enabled
|
||||
alc5651_reg_write(0x61,0x5800);//power managerment control 1:
|
||||
//I2S2 digital interface on, Analog DACL1 & DACR1 on.
|
||||
alc5651_reg_write(0x62,0x0C00);//stereo1 & 2 DAC filter power on
|
||||
alc5651_reg_write(0x73,0x0000);//ADC/DAC Clock control 1:
|
||||
//I2S Clock Pre-Divider 1 & 2: /1. Stereo DAC Over Sample Rate : 128Fs
|
||||
alc5651_reg_write(0x2A,0x4242);//Stereo DAC digital mixer control
|
||||
//Un-mute DACL2 to Stereo DAC Left & Right Mixer
|
||||
alc5651_reg_write(0x45,0x2000);//HPOMIX: Un-mute DAC1 to HPOMIX
|
||||
alc5651_reg_write(0x02,0x4848);//HP Output Control:
|
||||
//Unmute HPOL, HPOR
|
||||
// alc5651_reg_write(0x0F,0x1F1F);//INL & INR Volume Control
|
||||
// alc5651_reg_write(0x0D,0x0800);//IN1/2 Input Control
|
||||
// alc5651_reg_write(0x1C,0x7F7F);//Stereo1 ADC Digital Volume Control
|
||||
// alc5651_reg_write(0x1E,0xF000);// ADC Digital Boost Gain Control
|
||||
alc5651_reg_write(0x8E,0x0019);//HP Amp Control 1
|
||||
// Enable HP Output, Charge Pump Power On, HP Amp All Power On
|
||||
alc5651_reg_write(0x8F,0x3100);//HP Amp Control 2, HP Depop Mode 2
|
||||
alc5651_reg_write(0x91,0x0E00);//HP Amp Control 3, select HP capless power mode
|
||||
alc5651_index_write(0x3D,0x3E00);//unknown
|
||||
alc5651_reg_write(0xFA,0x0011);//enable input clock
|
||||
alc5651_reg_write(0x83,0x0800);//default ASRC control 1
|
||||
alc5651_reg_write(0x84,0xA000);//ASRC control 2: I2S1 enable ASRC mode, Sterol1 DAC filter ASRC mode.
|
||||
// alc5651_reg_write(0xFA,0x0C11);//? ? ? MX-FAh[15:4]reserved
|
||||
alc5651_reg_write(0x64,0x4010);//power managerment control 4:
|
||||
//MIC BST2 Power On; MIC2 SE Mode single-end mode or line-input mode
|
||||
alc5651_reg_write(0x65,0x0C00);//power managerment control 5: RECMIX L & R power on
|
||||
alc5651_reg_write(0x61,0x5806);//power managerment control 1:
|
||||
// I2S2 Digital Interface On, Analog DACL1, DACR1 power on; Analog ADCL, ADCR power on
|
||||
alc5651_reg_write(0x62,0xCC00);//power managerment control 2: Stereo1&2 ADC/DAC digital filter power on
|
||||
alc5651_reg_write(0x3C,0x004F);//RECMIXL
|
||||
alc5651_reg_write(0x3E,0x004F);//RECMIXR
|
||||
alc5651_reg_write(0x28,0x3030);//stereo2 ADC digital mixer control : Mute Stereo2 ADC L&R channel, ADCR
|
||||
alc5651_reg_write(0x2F,0x0080); //Interface DAC/ADC Data control: Select IF2 ADCDAT Data Source IF1_ADC2
|
||||
}
|
39
component/common/drivers/sdio/realtek/sdio_host/inc/sd.h
Normal file
39
component/common/drivers/sdio/realtek/sdio_host/inc/sd.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
#ifndef _SD_DRIVER_H
|
||||
#define _SD_DRIVER_H
|
||||
|
||||
#include "basic_types.h"
|
||||
|
||||
#define CONFIG_SD_SDIO 1
|
||||
#define CONFIG_SD_SPI 0
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SD_OK = 0,
|
||||
SD_NODISK,
|
||||
SD_INITERR,
|
||||
SD_PROTECTED,
|
||||
SD_ERROR,
|
||||
}SD_RESULT;
|
||||
|
||||
typedef enum{
|
||||
SD_CLK_LOW,
|
||||
SD_CLK_MID,
|
||||
SD_CLK_HIGH,
|
||||
SD_CLK_RSV,
|
||||
}SD_CLK;
|
||||
|
||||
SD_RESULT SD_WaitReady(void);
|
||||
SD_RESULT SD_Init(void);
|
||||
SD_RESULT SD_DeInit(void);
|
||||
SD_RESULT SD_SetCLK(SD_CLK CLK);
|
||||
|
||||
SD_RESULT SD_Status(void);
|
||||
|
||||
SD_RESULT SD_GetCID(u8 *cid_data); // read sd card CID
|
||||
SD_RESULT SD_GetCSD(u8 *csd_data); // read sd card CSD
|
||||
SD_RESULT SD_GetCapacity(u32* sector_count); // read sd card Capacity
|
||||
|
||||
SD_RESULT SD_ReadBlocks(u32 sector,u8 *data,u32 count); //read multi sector
|
||||
SD_RESULT SD_WriteBlocks(u32 sector,const u8 *data,u32 count); //write multi sector
|
||||
|
||||
#endif
|
|
@ -0,0 +1,32 @@
|
|||
#ifndef _SDIO_HOST_H
|
||||
#define _SDIO_HOST_H
|
||||
#include "basic_types.h"
|
||||
#include "rtl8195a_sdio_host.h"
|
||||
|
||||
typedef enum{
|
||||
SDIO_INIT_NONE = -1,
|
||||
SDIO_INIT_FAIL = 0,
|
||||
SDIO_INIT_OK = 1,
|
||||
SDIO_SD_NONE = 2,
|
||||
SDIO_SD_OK = 3,
|
||||
}_sdio_init_s;
|
||||
|
||||
|
||||
s8 sdio_init_host(void); // init sdio host interface
|
||||
void sdio_deinit_host(void);
|
||||
|
||||
s8 sdio_sd_init(void); // init sd card through sdio
|
||||
void sdio_sd_deinit(void); //de-init sd card through sdio
|
||||
s8 sdio_sd_status(void);
|
||||
u32 sdio_sd_getCapacity(void);
|
||||
s8 sdio_sd_getProtection(void);
|
||||
s8 sdio_sd_setProtection(bool protected);
|
||||
s8 sdio_sd_getCSD(u8* CSD);
|
||||
s8 sdio_sd_isReady();
|
||||
s8 sdio_sd_setClock(SD_CLK_FREQUENCY SDCLK);
|
||||
|
||||
|
||||
s8 sdio_read_blocks(u32 sector, u8 *buffer, u32 count);
|
||||
s8 sdio_write_blocks(u32 sector, const u8 *buffer, u32 count);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,183 @@
|
|||
#ifndef USBD_MSC_H
|
||||
#define USBD_MSC_H
|
||||
|
||||
#include "usb.h"
|
||||
#include "usb_gadget.h"
|
||||
#include "core/inc/usb_composite.h"
|
||||
#include "msc/inc/usbd_msc_config.h"
|
||||
|
||||
/* config usb msc device debug inforation */
|
||||
#define USBD_MSC_DEBUG 0
|
||||
|
||||
#if USBD_MSC_DEBUG
|
||||
#define USBD_PRINTF(fmt, args...) DBG_8195A("\n\r%s: " fmt, __FUNCTION__, ## args)
|
||||
#define USBD_ERROR(fmt, args...) DBG_8195A("\n\r%s: " fmt, __FUNCTION__, ## args)
|
||||
#define USBD_WARN(fmt, args...) DBG_8195A("\n\r%s: " fmt, __FUNCTION__, ## args)
|
||||
#define FUN_ENTER DBG_8195A("\n\r%s ==>\n", __func__)
|
||||
#define FUN_EXIT DBG_8195A("\n\r%s <==\n", __func__)
|
||||
#define FUN_TRACE DBG_8195A("\n\r%s:%d \n", __func__, __LINE__)
|
||||
#else
|
||||
#define USBD_PRINTF(fmt, args...)
|
||||
#define USBD_ERROR(fmt, args...) DBG_8195A("\n\r%s: " fmt, __FUNCTION__, ## args)
|
||||
#define USBD_WARN(fmt, args...)
|
||||
#define FUN_ENTER
|
||||
#define FUN_EXIT
|
||||
#define FUN_TRACE
|
||||
#endif
|
||||
|
||||
/* MSC Request Codes */
|
||||
#define MSC_REQUEST_RESET 0xFF
|
||||
#define MSC_REQUEST_GET_MAX_LUN 0xFE
|
||||
|
||||
/* MSC LUN */
|
||||
#define MSC_MAX_LOGIC_UNIT_NUMBER 1
|
||||
|
||||
enum data_direction{
|
||||
DATA_DIR_UNKNOWN = 0,
|
||||
DATA_DIR_FROM_HOST,
|
||||
DATA_DIR_TO_HOST,
|
||||
DATA_DIR_NONE
|
||||
};
|
||||
|
||||
typedef enum _disk_type{
|
||||
DISK_SDCARD,
|
||||
DISK_FLASH
|
||||
}disk_type;
|
||||
|
||||
//structure predefine
|
||||
struct msc_dev;
|
||||
struct msc_bufhd;
|
||||
|
||||
struct msc_opts{
|
||||
int (*disk_init)(void);
|
||||
int (*disk_deinit)(void);
|
||||
int (*disk_getcapacity)(u32* sectors);
|
||||
int (*disk_read)(u32 sector,u8 *buffer,u32 count);
|
||||
int (*disk_write)(u32 sector,const u8 *buffer,u32 count);
|
||||
};
|
||||
|
||||
struct msc_lun {
|
||||
unsigned int initially_ro:1;
|
||||
unsigned int ro:1;
|
||||
unsigned int removable:1;
|
||||
unsigned int cdrom:1;
|
||||
unsigned int prevent_medium_removal:1;
|
||||
unsigned int registered:1;
|
||||
unsigned int info_valid:1;
|
||||
unsigned int nofua:1;
|
||||
|
||||
u32 sense_data;
|
||||
u32 sense_data_info;
|
||||
u32 unit_attention_data;
|
||||
|
||||
u64 file_length;
|
||||
unsigned int num_sectors; /* */
|
||||
unsigned int blkbits; /* Bits of logical block size
|
||||
of bound block device */
|
||||
unsigned int blksize; /* logical block size of bound block device */
|
||||
const char *name; /* "lun.name" */
|
||||
|
||||
unsigned int lba; // the current read and write logical block address
|
||||
u8 is_open;
|
||||
_mutex lun_mutex;
|
||||
struct msc_opts *lun_opts;
|
||||
};
|
||||
|
||||
|
||||
struct msc_common{
|
||||
struct msc_dev *mscdev;
|
||||
|
||||
struct msc_lun **luns;
|
||||
struct msc_lun *curlun;
|
||||
|
||||
struct usb_gadget *gadget;
|
||||
struct usb_ep *ep0;
|
||||
struct usb_request *req0; /* for control responses */
|
||||
|
||||
/* scsi cbw relevant */
|
||||
enum data_direction data_dir;
|
||||
u32 data_size;
|
||||
u32 data_size_from_cmnd;
|
||||
u32 tag;
|
||||
u32 residue;
|
||||
u32 usb_amount_left;
|
||||
u8 scsi_cmnd[16]; // max command
|
||||
u8 cmnd_size;
|
||||
|
||||
u8 lun; /* current lun*/
|
||||
u8 nluns;
|
||||
|
||||
u8 nbufhd;
|
||||
u8 nbufhd_a;
|
||||
_list bufhd_pool;
|
||||
_mutex bufhd_mutex;
|
||||
/* bulk out cmd*/
|
||||
_list boc_list;
|
||||
_mutex boc_mutex;
|
||||
|
||||
/* bolk out data*/
|
||||
_mutex bod_mutex;
|
||||
_list bod_list;
|
||||
/**/
|
||||
struct msc_bufhd* curbh; // current buffer header
|
||||
struct msc_bufhd* cbw_bh; // buffer header for CBW
|
||||
struct msc_bufhd* csw_bh; // buffer header for CSW
|
||||
|
||||
unsigned int can_stall:1;
|
||||
unsigned int phase_error:1;
|
||||
unsigned int short_packet_received:1;
|
||||
unsigned int bad_lun_okay:1;
|
||||
unsigned int running:1;
|
||||
};
|
||||
|
||||
typedef enum _bufhd_type{
|
||||
BUFHD_CBW = 0,
|
||||
BUFHD_CSW,
|
||||
BUFHD_DATA,
|
||||
}bufhd_type;
|
||||
|
||||
struct msc_bufhd{
|
||||
u8* buf;
|
||||
int buf_size;
|
||||
bufhd_type type;
|
||||
_list list;
|
||||
struct usb_request *reqin; /* for bulkin responses */
|
||||
struct usb_request *reqout;
|
||||
};
|
||||
|
||||
struct msc_dev{
|
||||
struct msc_common *common;
|
||||
|
||||
u16 interface_number;
|
||||
u8 config;
|
||||
|
||||
struct usb_ep *in_ep;
|
||||
struct usb_ep *out_ep;
|
||||
unsigned int bulk_in_enabled:1;
|
||||
unsigned int bulk_out_enabled:1;
|
||||
|
||||
const struct usb_endpoint_descriptor
|
||||
*in, *out, *status;
|
||||
// lock is held when accessing usb
|
||||
struct task_struct msc_outCmdTask;
|
||||
struct task_struct msc_outDataTask;
|
||||
struct usb_function func;
|
||||
};
|
||||
|
||||
u32 min(u32 value1,u32 value2);
|
||||
|
||||
int usbd_msc_halt_bulk_in_endpoint(struct msc_dev *mscdev);
|
||||
void usbd_msc_put_bufhd(struct msc_common *common, struct msc_bufhd* bufhd);
|
||||
struct msc_bufhd* usbd_msc_get_bufhd(struct msc_common *common);
|
||||
int usbd_msc_bulk_in_transfer(struct msc_dev *mscdev, struct usb_request *req);
|
||||
int usbd_msc_bulk_out_transfer(struct msc_dev *mscdev, struct usb_request *req);
|
||||
|
||||
/*
|
||||
* N_bh : number of buffer header
|
||||
* Size_bh: buffer size per buffer
|
||||
* type:msc physical disk type
|
||||
*/
|
||||
int usbd_msc_init(int N_bh, int Size_bh, disk_type type);
|
||||
void usbd_msc_deinit(void);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,8 @@
|
|||
#ifndef _USBD_MSC_CONFIG_H
|
||||
#define _USBD_MSC_CONFIG_H
|
||||
|
||||
/* config usb MSC device buffer resource */
|
||||
#define MSC_NBR_BUFHD 2 /* number of buffer header for bulk in/out data*/
|
||||
#define MSC_BUFLEN (20*512)/* Default size of buffer length. Minmun of 512 byte*/
|
||||
|
||||
#endif
|
|
@ -0,0 +1,196 @@
|
|||
#include "usb_ch9.h"
|
||||
#include "usb_defs.h"
|
||||
#include "usb_gadget.h"
|
||||
|
||||
// <i> Enable high-speed functionality (if device supports it)
|
||||
#define USBD_HS_ENABLE 1
|
||||
|
||||
|
||||
// define string index
|
||||
#define STRING_MANUFACTURER 1
|
||||
#define STRING_PRODUCT 2
|
||||
#define STRING_SERIALNUMBER 3
|
||||
#define STRING_INTERFACE 4
|
||||
#define STRING_MSC 5
|
||||
|
||||
|
||||
#define DEV_CONFIG_VALUE 1
|
||||
|
||||
#define DRIVER_DESC "USB Mass Storage"
|
||||
#define DRIVER_VERSION "Feb 2016"
|
||||
|
||||
#define MANUFACTURER "Realtek Singapore Semiconductor"
|
||||
|
||||
static char string_manufacturer [50] = MANUFACTURER;
|
||||
static char string_product [40] = DRIVER_DESC;
|
||||
static char string_serial [20] = "0123456789";
|
||||
|
||||
struct usb_string
|
||||
usbd_msc_strings [] = {
|
||||
{ STRING_MANUFACTURER, string_manufacturer, },
|
||||
{ STRING_PRODUCT, string_product, },
|
||||
{ STRING_SERIALNUMBER, string_serial, },
|
||||
{ STRING_INTERFACE, "USB MSC Interface", },
|
||||
{ STRING_MSC, "USB MSC", },
|
||||
};
|
||||
|
||||
struct usb_gadget_strings msc_stringtab = {
|
||||
.language = 0x0409, /* en-us */
|
||||
.strings = usbd_msc_strings,
|
||||
};
|
||||
|
||||
struct usb_gadget_strings *dev_msc_strings[] = {
|
||||
&msc_stringtab,
|
||||
NULL,
|
||||
};
|
||||
|
||||
static struct usb_device_descriptor
|
||||
usbd_msc_device_desc = {
|
||||
.bLength = sizeof usbd_msc_device_desc,
|
||||
.bDescriptorType = USB_DT_DEVICE,
|
||||
|
||||
.bcdUSB = (0x0200),
|
||||
|
||||
.bDeviceClass = 0x00,// define in interface descriptor
|
||||
.bDeviceSubClass = 0x00,
|
||||
.bDeviceProtocol = 0x00,
|
||||
|
||||
.bMaxPacketSize0 = 64, // this will be set automatically depends on ep0 setting
|
||||
.idVendor = 0x0BDA,
|
||||
.idProduct = 0x8195,
|
||||
// .bcdDevice = ,
|
||||
.iManufacturer = STRING_MANUFACTURER,
|
||||
.iProduct = STRING_PRODUCT,
|
||||
.iSerialNumber = STRING_SERIALNUMBER,
|
||||
.bNumConfigurations=0x01,
|
||||
};
|
||||
#if 0
|
||||
struct usb_config_descriptor
|
||||
usbd_msc_config_desc = {
|
||||
.bLength = sizeof usbd_msc_config_desc,
|
||||
.bDescriptorType = USB_DT_CONFIG,
|
||||
|
||||
/* compute wTotalLength on the fly */
|
||||
.bNumInterfaces = 1,
|
||||
.bConfigurationValue = DEV_CONFIG_VALUE,
|
||||
.iConfiguration = STRING_MSC,
|
||||
.bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
|
||||
.bMaxPower = 0x32,
|
||||
};
|
||||
#endif
|
||||
|
||||
#if USBD_HS_ENABLE
|
||||
/* USB Device Qualifier Descriptor (for Full Speed) */
|
||||
static struct usb_qualifier_descriptor
|
||||
usbd_msc_qualifier_desc_FS = {
|
||||
.bLength = sizeof usbd_msc_qualifier_desc_FS,
|
||||
.bDescriptorType = USB_DT_DEVICE_QUALIFIER,
|
||||
.bcdUSB = 0x0200,
|
||||
.bDeviceClass = 0x00,
|
||||
.bDeviceSubClass = 0x00,
|
||||
.bDeviceProtocol = 0x00,
|
||||
.bMaxPacketSize0 = 64,
|
||||
.bNumConfigurations = 0x01,
|
||||
.bRESERVED = 0x00,
|
||||
};
|
||||
|
||||
/* USB Device Qualifier Descriptor for High Speed */
|
||||
static struct usb_qualifier_descriptor
|
||||
usbd_msc_qualifier_desc_HS = {
|
||||
.bLength = sizeof usbd_msc_qualifier_desc_HS,
|
||||
.bDescriptorType = USB_DT_DEVICE_QUALIFIER,
|
||||
.bcdUSB = 0x0200,
|
||||
.bDeviceClass = 0x00,
|
||||
.bDeviceSubClass = 0x00,
|
||||
.bDeviceProtocol = 0x00,
|
||||
.bMaxPacketSize0 = 64,
|
||||
.bNumConfigurations = 0x01,
|
||||
.bRESERVED = 0x00,
|
||||
};
|
||||
#else
|
||||
/* USB Device Qualifier Descriptor (for Full Speed) */
|
||||
static struct usb_qualifier_descriptor
|
||||
usbd_msc_qualifier_desc_FS = { 0 };
|
||||
|
||||
/* USB Device Qualifier Descriptor for High Speed */
|
||||
static struct usb_qualifier_descriptor
|
||||
usbd_msc_qualifier_desc_HS = { 0 };
|
||||
#endif
|
||||
|
||||
/* MSC Interface, Alternate Setting 0*/
|
||||
struct usb_interface_descriptor
|
||||
usbd_msc_intf_desc = {
|
||||
.bLength = sizeof usbd_msc_intf_desc,
|
||||
.bDescriptorType = USB_DT_INTERFACE,
|
||||
|
||||
.bInterfaceNumber = 0x00, // this will be assign automatically
|
||||
.bAlternateSetting =0x00,
|
||||
.bNumEndpoints = 0x02,
|
||||
.bInterfaceClass = USB_CLASS_MASS_STORAGE,
|
||||
.bInterfaceSubClass = US_SC_SCSI,
|
||||
.bInterfaceProtocol = US_PR_BULK,
|
||||
.iInterface = STRING_INTERFACE,
|
||||
};
|
||||
|
||||
/* MSC Endpoints for Low-speed/Full-speed */
|
||||
/* Endpoint, EP Bulk IN */
|
||||
struct usb_endpoint_descriptor
|
||||
usbd_msc_source_desc_FS = {
|
||||
.bLength = USB_DT_ENDPOINT_SIZE,
|
||||
.bDescriptorType = USB_DT_ENDPOINT,
|
||||
|
||||
.bEndpointAddress = USB_DIR_IN,
|
||||
.bmAttributes = USB_ENDPOINT_XFER_BULK,
|
||||
.wMaxPacketSize = (64),
|
||||
.bInterval = 0x00,
|
||||
|
||||
};
|
||||
/* Endpoint, EP Bulk OUT */
|
||||
struct usb_endpoint_descriptor
|
||||
usbd_msc_sink_desc_FS = {
|
||||
.bLength = USB_DT_ENDPOINT_SIZE,
|
||||
.bDescriptorType = USB_DT_ENDPOINT,
|
||||
|
||||
.bEndpointAddress = USB_DIR_OUT,
|
||||
.bmAttributes = USB_ENDPOINT_XFER_BULK,
|
||||
.wMaxPacketSize = (64),
|
||||
.bInterval = 0x00,
|
||||
};
|
||||
|
||||
/* MSC Endpoints for High-speed */
|
||||
/* Endpoint, EP Bulk IN */
|
||||
struct usb_endpoint_descriptor
|
||||
usbd_msc_source_desc_HS = {
|
||||
.bLength = USB_DT_ENDPOINT_SIZE,
|
||||
.bDescriptorType = USB_DT_ENDPOINT,
|
||||
.bEndpointAddress = USB_DIR_IN,
|
||||
.bmAttributes = USB_ENDPOINT_XFER_BULK,
|
||||
.wMaxPacketSize = (512),
|
||||
.bInterval = 0x00,
|
||||
};
|
||||
|
||||
/* Endpoint, EP Bulk OUT */
|
||||
struct usb_endpoint_descriptor
|
||||
usbd_msc_sink_desc_HS = {
|
||||
.bLength = USB_DT_ENDPOINT_SIZE,
|
||||
.bDescriptorType = USB_DT_ENDPOINT,
|
||||
.bEndpointAddress = USB_DIR_OUT,
|
||||
.bmAttributes = USB_ENDPOINT_XFER_BULK,
|
||||
.wMaxPacketSize = (512),
|
||||
.bInterval = 0x00,
|
||||
};
|
||||
|
||||
struct usb_descriptor_header *usbd_msc_descriptors_FS [] = {
|
||||
/* data interface has no altsetting */
|
||||
(struct usb_descriptor_header *) &usbd_msc_intf_desc,
|
||||
(struct usb_descriptor_header *) &usbd_msc_source_desc_FS,
|
||||
(struct usb_descriptor_header *) &usbd_msc_sink_desc_FS,
|
||||
NULL,
|
||||
};
|
||||
struct usb_descriptor_header *usbd_msc_descriptors_HS [] = {
|
||||
/* data interface has no altsetting */
|
||||
(struct usb_descriptor_header *) &usbd_msc_intf_desc,
|
||||
(struct usb_descriptor_header *) &usbd_msc_source_desc_HS,
|
||||
(struct usb_descriptor_header *) &usbd_msc_sink_desc_HS,
|
||||
NULL,
|
||||
};
|
|
@ -0,0 +1,110 @@
|
|||
#ifndef USBD_SCSI_H
|
||||
#define USBD_SCSI_H
|
||||
#include "basic_types.h"
|
||||
#include "msc/inc/usbd_msc.h"
|
||||
|
||||
#define MAX_COMMAND_SIZE 16
|
||||
#define MSC_MAX_LUNS 8
|
||||
|
||||
/* SCSI Commands */
|
||||
#define SCSI_FORMAT_UNIT 0x04
|
||||
#define SCSI_INQUIRY 0x12
|
||||
#define SCSI_MODE_SELECT6 0x15
|
||||
#define SCSI_MODE_SELECT10 0x55
|
||||
#define SCSI_MODE_SENSE6 0x1A
|
||||
#define SCSI_MODE_SENSE10 0x5A
|
||||
#define SCSI_ALLOW_MEDIUM_REMOVAL 0x1E
|
||||
#define SCSI_READ6 0x08
|
||||
#define SCSI_READ10 0x28
|
||||
#define SCSI_READ12 0xA8
|
||||
#define SCSI_READ16 0x88
|
||||
|
||||
#define SCSI_READ_CAPACITY10 0x25
|
||||
#define SCSI_READ_CAPACITY16 0x9E
|
||||
|
||||
#define SCSI_SYNCHRONIZE_CACHE 0x35
|
||||
#define SCSI_REQUEST_SENSE 0x03
|
||||
#define SCSI_START_STOP_UNIT 0x1B
|
||||
#define SCSI_TEST_UNIT_READY 0x00
|
||||
#define SCSI_WRITE6 0x0A
|
||||
#define SCSI_WRITE10 0x2A
|
||||
#define SCSI_WRITE12 0xAA
|
||||
#define SCSI_WRITE16 0x8A
|
||||
|
||||
#define SCSI_VERIFY10 0x2F
|
||||
#define SCSI_VERIFY12 0xAF
|
||||
#define SCSI_VERIFY16 0x8F
|
||||
|
||||
#define SCSI_SEND_DIAGNOSTIC 0x1D
|
||||
#define SCSI_READ_FORMAT_CAPACITIES 0x23
|
||||
|
||||
#define READ_FORMAT_CAPACITY_DATA_LEN 0x0C
|
||||
#define READ_CAPACITY10_DATA_LEN 0x08
|
||||
#define MODE_SENSE10_DATA_LEN 0x08
|
||||
#define MODE_SENSE6_DATA_LEN 0x04
|
||||
#define REQUEST_SENSE_DATA_LEN 0x12
|
||||
#define STANDARD_INQUIRY_DATA_LEN 0x24
|
||||
|
||||
/* SCSI Sense Key/Additional Sense Code/ASC Qualifier values */
|
||||
#define SS_NO_SENSE 0
|
||||
#define SS_COMMUNICATION_FAILURE 0x040800
|
||||
#define SS_INVALID_COMMAND 0x052000
|
||||
#define SS_INVALID_FIELD_IN_CDB 0x052400
|
||||
#define SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE 0x052100
|
||||
#define SS_LOGICAL_UNIT_NOT_SUPPORTED 0x052500
|
||||
#define SS_MEDIUM_NOT_PRESENT 0x023a00
|
||||
#define SS_MEDIUM_REMOVAL_PREVENTED 0x055302
|
||||
#define SS_NOT_READY_TO_READY_TRANSITION 0x062800
|
||||
#define SS_RESET_OCCURRED 0x062900
|
||||
#define SS_SAVING_PARAMETERS_NOT_SUPPORTED 0x053900
|
||||
#define SS_UNRECOVERED_READ_ERROR 0x031100
|
||||
#define SS_WRITE_ERROR 0x030c02
|
||||
#define SS_WRITE_PROTECTED 0x072700
|
||||
|
||||
|
||||
|
||||
#define SK(x) ((u8) ((x) >> 16)) /* Sense Key byte, etc. */
|
||||
#define ASC(x) ((u8) ((x) >> 8))
|
||||
#define ASCQ(x) ((u8) (x))
|
||||
|
||||
/*
|
||||
* Bulk only data structures
|
||||
*/
|
||||
|
||||
/* command block wrapper */
|
||||
struct bulk_cb_wrap {
|
||||
unsigned int Signature; /* contains 'USBC', denote bulk_cb_wrap */
|
||||
unsigned int Tag; /* unique per command id */
|
||||
unsigned int DataTransferLength; /* size of data for transfer */
|
||||
unsigned char Flags; /* data transfer direction */
|
||||
unsigned char Lun; /* LUN normally 0, (which command block is sent) */
|
||||
unsigned char Length; /* length of the CDB */
|
||||
unsigned char CDB[16]; /* max command */
|
||||
};
|
||||
|
||||
#define US_BULK_CB_WRAP_LEN 31
|
||||
#define US_BULK_CB_SIGN 0x43425355 /*spells out USBC */
|
||||
#define US_BULK_FLAG_IN (1 << 7)
|
||||
#define US_BULK_FLAG_OUT 0
|
||||
|
||||
/* command status wrapper */
|
||||
struct bulk_cs_wrap {
|
||||
unsigned int Signature; /* should = 'USBS' */
|
||||
unsigned int Tag; /* same as original command, echoed by the device as received */
|
||||
unsigned int Residue; /* amount not transferred */
|
||||
unsigned char Status; /* execute command status */
|
||||
};
|
||||
|
||||
#define US_BULK_CS_WRAP_LEN 13
|
||||
#define US_BULK_CS_SIGN 0x53425355 /* spells out 'USBS' */
|
||||
// execute command status
|
||||
#define US_BULK_STAT_OK 0
|
||||
#define US_BULK_STAT_FAIL 1
|
||||
#define US_BULK_STAT_PHASE 2
|
||||
|
||||
/* bulk-only class specific requests */
|
||||
#define US_BULK_RESET_REQUEST 0xff
|
||||
#define US_BULK_GET_MAX_LUN 0xfe
|
||||
|
||||
extern int usbd_msc_receive_cbw(struct msc_dev *mscdev, struct usb_request *req);
|
||||
#endif
|
|
@ -0,0 +1,24 @@
|
|||
#ifndef _GADEGT_DEBUG_H_
|
||||
#define _GADGET_DEBUG_H_
|
||||
|
||||
#include "diag.h"
|
||||
|
||||
#define GADGET_DEBUG 0
|
||||
|
||||
#if GADGET_DEBUG
|
||||
#define GADGET_PRINT(fmt, args...) DBG_8195A("\n\r[%s]: " fmt, __FUNCTION__, ## args)
|
||||
#define GADGET_ERROR(fmt, args...) DBG_8195A("\n\r[%s]: " fmt, __FUNCTION__, ## args)
|
||||
#define GADGET_WARN(fmt, args...) DBG_8195A("\n\r[%s]: " fmt, __FUNCTION__, ## args)
|
||||
#define FUN_ENTER DBG_8195A("\n\r[%s ==>]\n", __func__)
|
||||
#define FUN_EXIT DBG_8195A("\n\r[%s <==]\n", __func__)
|
||||
#define FUN_TRACE DBG_8195A("\n\r[%s]:%d \n", __func__, __LINE__)
|
||||
#else
|
||||
#define GADGET_PRINT(fmt, args...)
|
||||
#define GADGET_ERROR(fmt, args...) DBG_8195A("\n\r[%s]: " fmt, __FUNCTION__, ## args)
|
||||
#define GADGET_WARN(fmt, args...)
|
||||
#define FUN_ENTER
|
||||
#define FUN_EXIT
|
||||
#define FUN_TRACE
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,398 @@
|
|||
#ifndef _USB_COMPOSITE_H_
|
||||
#define _USB_COMPOSITE_H_
|
||||
|
||||
#include "usb_gadget.h"
|
||||
#include "usb.h"
|
||||
|
||||
/*
|
||||
* USB function drivers should return USB_GADGET_DELAYED_STATUS if they
|
||||
* wish to delay the data/status stages of the control transfer till they
|
||||
* are ready. The control transfer will then be kept from completing till
|
||||
* all the function drivers that requested for USB_GADGET_DELAYED_STAUS
|
||||
* invoke usb_composite_setup_continue().
|
||||
*/
|
||||
#define USB_GADGET_DELAYED_STATUS 0x7fff /* Impossibly large value */
|
||||
|
||||
|
||||
/* big enough to hold our biggest descriptor */
|
||||
#define USB_COMP_EP0_BUFSIZ 1024+24
|
||||
#define MAX_CONFIG_INTERFACES 16 /* arbitrary; max 255 */
|
||||
// predefine structure
|
||||
struct usb_composite_dev;
|
||||
struct usb_composite_driver;
|
||||
|
||||
enum control_request_return_codes {
|
||||
USBD_REQ_NOTSUPP = 0,
|
||||
USBD_REQ_HANDLED = 1,
|
||||
USBD_REQ_NEXT_CALLBACK = 2,
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* struct usb_composite_driver - groups configurations into a gadget
|
||||
* @name: For diagnostics, identifies the driver.
|
||||
* @dev: Template descriptor for the device, including default device
|
||||
* identifiers.
|
||||
* @strings: tables of strings, keyed by identifiers assigned during @bind
|
||||
* and language IDs provided in control requests. Note: The first entries
|
||||
* are predefined. The first entry that may be used is
|
||||
* USB_GADGET_FIRST_AVAIL_IDX
|
||||
* @max_speed: Highest speed the driver supports.
|
||||
* @needs_serial: set to 1 if the gadget needs userspace to provide
|
||||
* a serial number. If one is not provided, warning will be printed.
|
||||
* @bind: (REQUIRED) Used to allocate resources that are shared across the
|
||||
* whole device, such as string IDs, and add its configurations using
|
||||
* @usb_add_config(). This may fail by returning a negative errno
|
||||
* value; it should return zero on successful initialization.
|
||||
* @unbind: Reverses @bind; called as a side effect of unregistering
|
||||
* this driver.
|
||||
* @disconnect: optional driver disconnect method
|
||||
* @suspend: Notifies when the host stops sending USB traffic,
|
||||
* after function notifications
|
||||
* @resume: Notifies configuration when the host restarts USB traffic,
|
||||
* before function notifications
|
||||
* @gadget_driver: Gadget driver controlling this driver
|
||||
*
|
||||
* Devices default to reporting self powered operation. Devices which rely
|
||||
* on bus powered operation should report this in their @bind method.
|
||||
*
|
||||
* Before returning from @bind, various fields in the template descriptor
|
||||
* may be overridden. These include the idVendor/idProduct/bcdDevice values
|
||||
* normally to bind the appropriate host side driver, and the three strings
|
||||
* (iManufacturer, iProduct, iSerialNumber) normally used to provide user
|
||||
* meaningful device identifiers. (The strings will not be defined unless
|
||||
* they are defined in @dev and @strings.) The correct ep0 maxpacket size
|
||||
* is also reported, as defined by the underlying controller driver.
|
||||
*/
|
||||
|
||||
struct usb_composite_driver {
|
||||
const char *name;
|
||||
const struct usb_device_descriptor *dev;
|
||||
struct usb_gadget_strings **strings;
|
||||
enum usb_device_speed max_speed;
|
||||
unsigned needs_serial:1;
|
||||
|
||||
int (*bind)(struct usb_composite_dev *cdev);
|
||||
int (*unbind)(struct usb_composite_dev *);
|
||||
|
||||
void (*disconnect)(struct usb_composite_dev *);
|
||||
|
||||
/* global suspend hooks */
|
||||
void (*suspend)(struct usb_composite_dev *);
|
||||
void (*resume)(struct usb_composite_dev *);
|
||||
struct usb_gadget_driver gadget_driver;
|
||||
};
|
||||
/**
|
||||
* struct usb_composite_device - represents one composite usb gadget
|
||||
* @gadget: read-only, abstracts the gadget's usb peripheral controller
|
||||
* @req: used for control responses; buffer is pre-allocated
|
||||
* @os_desc_req: used for OS descriptors responses; buffer is pre-allocated
|
||||
* @config: the currently active configuration
|
||||
* @qw_sign: qwSignature part of the OS string
|
||||
* @b_vendor_code: bMS_VendorCode part of the OS string
|
||||
* @use_os_string: false by default, interested gadgets set it
|
||||
* @os_desc_config: the configuration to be used with OS descriptors
|
||||
*
|
||||
* One of these devices is allocated and initialized before the
|
||||
* associated device driver's bind() is called.
|
||||
*
|
||||
* OPEN ISSUE: it appears that some WUSB devices will need to be
|
||||
* built by combining a normal (wired) gadget with a wireless one.
|
||||
* This revision of the gadget framework should probably try to make
|
||||
* sure doing that won't hurt too much.
|
||||
*
|
||||
* One notion for how to handle Wireless USB devices involves:
|
||||
* (a) a second gadget here, discovery mechanism TBD, but likely
|
||||
* needing separate "register/unregister WUSB gadget" calls;
|
||||
* (b) updates to usb_gadget to include flags "is it wireless",
|
||||
* "is it wired", plus (presumably in a wrapper structure)
|
||||
* bandgroup and PHY info;
|
||||
* (c) presumably a wireless_ep wrapping a usb_ep, and reporting
|
||||
* wireless-specific parameters like maxburst and maxsequence;
|
||||
* (d) configurations that are specific to wireless links;
|
||||
* (e) function drivers that understand wireless configs and will
|
||||
* support wireless for (additional) function instances;
|
||||
* (f) a function to support association setup (like CBAF), not
|
||||
* necessarily requiring a wireless adapter;
|
||||
* (g) composite device setup that can create one or more wireless
|
||||
* configs, including appropriate association setup support;
|
||||
* (h) more, TBD.
|
||||
*/
|
||||
|
||||
#define MAX_USER_CONTROL_CALLBACK 2
|
||||
|
||||
typedef int (*user_control_callback)(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl);
|
||||
|
||||
struct usb_composite_dev {
|
||||
struct usb_gadget *gadget;
|
||||
struct usb_request *req;
|
||||
struct usb_request *os_desc_req;
|
||||
|
||||
struct usb_configuration *config;
|
||||
//
|
||||
// /* OS String is a custom (yet popular) extension to the USB standard. */
|
||||
// u8 qw_sign[OS_STRING_QW_SIGN_LEN];
|
||||
// u8 b_vendor_code;
|
||||
// struct usb_configuration *os_desc_config;
|
||||
// unsigned int use_os_string:1;
|
||||
//
|
||||
// /* private: */
|
||||
// /* internals */
|
||||
unsigned int suspended:1;
|
||||
struct usb_device_descriptor desc;
|
||||
|
||||
//_LIST config_list;
|
||||
dwc_list_link_t config_list; // by jimmy
|
||||
//_LIST gstring_list;
|
||||
dwc_list_link_t gstring_list;// by jimmy
|
||||
|
||||
struct usb_composite_driver *driver;
|
||||
// u8 next_string_id;
|
||||
// char *def_manufacturer;
|
||||
//
|
||||
// /* the gadget driver won't enable the data pullup
|
||||
// * while the deactivation count is nonzero.
|
||||
// */
|
||||
// unsigned deactivations;
|
||||
//
|
||||
// /* the composite driver won't complete the control transfer's
|
||||
// * data/status stages till delayed_status is zero.
|
||||
// */
|
||||
// int delayed_status;
|
||||
//
|
||||
// /* protects deactivations and delayed_status counts*/
|
||||
_Lock lock;
|
||||
/* for unstandard control request handler */
|
||||
|
||||
user_control_callback control_cb[MAX_USER_CONTROL_CALLBACK];
|
||||
};
|
||||
|
||||
|
||||
#if 0
|
||||
#define container_of(p,t,n) (t*)((p)-&(((t*)0)->n))
|
||||
|
||||
static inline struct usb_composite_driver *to_cdriver(
|
||||
struct usb_gadget_driver *gdrv)
|
||||
{
|
||||
return container_of(gdrv, struct usb_composite_driver, gadget_driver);
|
||||
}
|
||||
#endif
|
||||
#if 1
|
||||
/**
|
||||
* struct usb_configuration - represents one gadget configuration
|
||||
* @label: For diagnostics, describes the configuration.
|
||||
* @strings: Tables of strings, keyed by identifiers assigned during @bind()
|
||||
* and by language IDs provided in control requests.
|
||||
* @descriptors: Table of descriptors preceding all function descriptors.
|
||||
* Examples include OTG and vendor-specific descriptors.
|
||||
* @unbind: Reverses @bind; called as a side effect of unregistering the
|
||||
* driver which added this configuration.
|
||||
* @setup: Used to delegate control requests that aren't handled by standard
|
||||
* device infrastructure or directed at a specific interface.
|
||||
* @bConfigurationValue: Copied into configuration descriptor.
|
||||
* @iConfiguration: Copied into configuration descriptor.
|
||||
* @bmAttributes: Copied into configuration descriptor.
|
||||
* @MaxPower: Power consumtion in mA. Used to compute bMaxPower in the
|
||||
* configuration descriptor after considering the bus speed.
|
||||
* @cdev: assigned by @usb_add_config() before calling @bind(); this is
|
||||
* the device associated with this configuration.
|
||||
*
|
||||
* Configurations are building blocks for gadget drivers structured around
|
||||
* function drivers. Simple USB gadgets require only one function and one
|
||||
* configuration, and handle dual-speed hardware by always providing the same
|
||||
* functionality. Slightly more complex gadgets may have more than one
|
||||
* single-function configuration at a given speed; or have configurations
|
||||
* that only work at one speed.
|
||||
*
|
||||
* Composite devices are, by definition, ones with configurations which
|
||||
* include more than one function.
|
||||
*
|
||||
* The lifecycle of a usb_configuration includes allocation, initialization
|
||||
* of the fields described above, and calling @usb_add_config() to set up
|
||||
* internal data and bind it to a specific device. The configuration's
|
||||
* @bind() method is then used to initialize all the functions and then
|
||||
* call @usb_add_function() for them.
|
||||
*
|
||||
* Those functions would normally be independent of each other, but that's
|
||||
* not mandatory. CDC WMC devices are an example where functions often
|
||||
* depend on other functions, with some functions subsidiary to others.
|
||||
* Such interdependency may be managed in any way, so long as all of the
|
||||
* descriptors complete by the time the composite driver returns from
|
||||
* its bind() routine.
|
||||
*/
|
||||
struct usb_configuration {
|
||||
const char *label;
|
||||
struct usb_gadget_strings **strings;
|
||||
const struct usb_descriptor_header **descriptors;
|
||||
|
||||
/* REVISIT: bind() functions can be marked __init, which
|
||||
* makes trouble for section mismatch analysis. See if
|
||||
* we can't restructure things to avoid mismatching...
|
||||
*/
|
||||
|
||||
/* configuration management: unbind/setup */
|
||||
void (*unbind)(struct usb_configuration *);
|
||||
int (*setup)(struct usb_configuration *,
|
||||
const struct usb_ctrlrequest *);
|
||||
|
||||
/* fields in the config descriptor */
|
||||
u8 bConfigurationValue;
|
||||
u8 iConfiguration;
|
||||
u8 bmAttributes;
|
||||
u16 MaxPower;
|
||||
|
||||
struct usb_composite_dev *cdev;
|
||||
|
||||
/* private: */
|
||||
/* internals */
|
||||
//_LIST list;
|
||||
//_LIST function_lists;
|
||||
dwc_list_link_t list;
|
||||
dwc_list_link_t function_lists; // by jimmy
|
||||
|
||||
u8 next_interface_id;
|
||||
unsigned superspeed:1;
|
||||
unsigned highspeed:1;
|
||||
unsigned fullspeed:1;
|
||||
struct usb_function *interface[MAX_CONFIG_INTERFACES];
|
||||
};
|
||||
|
||||
_LONG_CALL_ int usb_interface_id(struct usb_configuration *config,
|
||||
struct usb_function *function);
|
||||
|
||||
_LONG_CALL_ int usb_add_config(struct usb_composite_dev *,
|
||||
struct usb_configuration *,
|
||||
int (*)(struct usb_configuration *));
|
||||
|
||||
_LONG_CALL_ void usb_remove_config(struct usb_composite_dev *,
|
||||
struct usb_configuration *);
|
||||
|
||||
/**
|
||||
* struct usb_function - describes one function of a configuration
|
||||
* @name: For diagnostics, identifies the function.
|
||||
* @strings: tables of strings, keyed by identifiers assigned during bind()
|
||||
* and by language IDs provided in control requests
|
||||
* @fs_descriptors: Table of full (or low) speed descriptors, using interface and
|
||||
* string identifiers assigned during @bind(). If this pointer is null,
|
||||
* the function will not be available at full speed (or at low speed).
|
||||
* @hs_descriptors: Table of high speed descriptors, using interface and
|
||||
* string identifiers assigned during @bind(). If this pointer is null,
|
||||
* the function will not be available at high speed.
|
||||
* @ss_descriptors: Table of super speed descriptors, using interface and
|
||||
* string identifiers assigned during @bind(). If this
|
||||
* pointer is null after initiation, the function will not
|
||||
* be available at super speed.
|
||||
* @config: assigned when @usb_add_function() is called; this is the
|
||||
* configuration with which this function is associated.
|
||||
* @os_desc_table: Table of (interface id, os descriptors) pairs. The function
|
||||
* can expose more than one interface. If an interface is a member of
|
||||
* an IAD, only the first interface of IAD has its entry in the table.
|
||||
* @os_desc_n: Number of entries in os_desc_table
|
||||
* @bind: Before the gadget can register, all of its functions bind() to the
|
||||
* available resources including string and interface identifiers used
|
||||
* in interface or class descriptors; endpoints; I/O buffers; and so on.
|
||||
* @unbind: Reverses @bind; called as a side effect of unregistering the
|
||||
* driver which added this function.
|
||||
* @free_func: free the struct usb_function.
|
||||
* @mod: (internal) points to the module that created this structure.
|
||||
* @set_alt: (REQUIRED) Reconfigures altsettings; function drivers may
|
||||
* initialize usb_ep.driver data at this time (when it is used).
|
||||
* Note that setting an interface to its current altsetting resets
|
||||
* interface state, and that all interfaces have a disabled state.
|
||||
* @get_alt: Returns the active altsetting. If this is not provided,
|
||||
* then only altsetting zero is supported.
|
||||
* @disable: (REQUIRED) Indicates the function should be disabled. Reasons
|
||||
* include host resetting or reconfiguring the gadget, and disconnection.
|
||||
* @setup: Used for interface-specific control requests.
|
||||
* @suspend: Notifies functions when the host stops sending USB traffic.
|
||||
* @resume: Notifies functions when the host restarts USB traffic.
|
||||
* @get_status: Returns function status as a reply to
|
||||
* GetStatus() request when the recipient is Interface.
|
||||
* @func_suspend: callback to be called when
|
||||
* SetFeature(FUNCTION_SUSPEND) is reseived
|
||||
*
|
||||
* A single USB function uses one or more interfaces, and should in most
|
||||
* cases support operation at both full and high speeds. Each function is
|
||||
* associated by @usb_add_function() with a one configuration; that function
|
||||
* causes @bind() to be called so resources can be allocated as part of
|
||||
* setting up a gadget driver. Those resources include endpoints, which
|
||||
* should be allocated using @usb_ep_autoconfig().
|
||||
*
|
||||
* To support dual speed operation, a function driver provides descriptors
|
||||
* for both high and full speed operation. Except in rare cases that don't
|
||||
* involve bulk endpoints, each speed needs different endpoint descriptors.
|
||||
*
|
||||
* Function drivers choose their own strategies for managing instance data.
|
||||
* The simplest strategy just declares it "static', which means the function
|
||||
* can only be activated once. If the function needs to be exposed in more
|
||||
* than one configuration at a given speed, it needs to support multiple
|
||||
* usb_function structures (one for each configuration).
|
||||
*
|
||||
* A more complex strategy might encapsulate a @usb_function structure inside
|
||||
* a driver-specific instance structure to allows multiple activations. An
|
||||
* example of multiple activations might be a CDC ACM function that supports
|
||||
* two or more distinct instances within the same configuration, providing
|
||||
* several independent logical data links to a USB host.
|
||||
*/
|
||||
|
||||
struct usb_function {
|
||||
const char *name;
|
||||
struct usb_gadget_strings **strings;
|
||||
struct usb_descriptor_header **fs_descriptors;
|
||||
struct usb_descriptor_header **hs_descriptors;
|
||||
// struct usb_descriptor_header **ss_descriptors;
|
||||
|
||||
struct usb_configuration *config;
|
||||
|
||||
// struct usb_os_desc_table *os_desc_table;
|
||||
// unsigned os_desc_n;
|
||||
|
||||
/* REVISIT: bind() functions can be marked __init, which
|
||||
* makes trouble for section mismatch analysis. See if
|
||||
* we can't restructure things to avoid mismatching.
|
||||
* Related: unbind() may kfree() but bind() won't...
|
||||
*/
|
||||
|
||||
/* configuration management: bind/unbind */
|
||||
int (*bind)(struct usb_configuration *,
|
||||
struct usb_function *);
|
||||
void (*unbind)(struct usb_configuration *,
|
||||
struct usb_function *);
|
||||
void (*free_func)(struct usb_function *f);
|
||||
struct module *mod;
|
||||
|
||||
/* runtime state management */
|
||||
int (*set_alt)(struct usb_function *,
|
||||
unsigned interface, unsigned alt);
|
||||
int (*get_alt)(struct usb_function *,
|
||||
unsigned interface);
|
||||
void (*disable)(struct usb_function *);
|
||||
int (*setup)(struct usb_function *,
|
||||
const struct usb_ctrlrequest *);
|
||||
void (*suspend)(struct usb_function *);
|
||||
void (*resume)(struct usb_function *);
|
||||
|
||||
/* USB 3.0 additions */
|
||||
int (*get_status)(struct usb_function *);
|
||||
int (*func_suspend)(struct usb_function *,
|
||||
u8 suspend_opt);
|
||||
/* private: */
|
||||
/* internals */
|
||||
//_LIST list;
|
||||
dwc_list_link_t list; // by jimmy
|
||||
// DECLARE_BITMAP(endpoints, 32);
|
||||
// const struct usb_function_instance *fi;
|
||||
};
|
||||
|
||||
#endif
|
||||
extern _LONG_CALL_ int usb_add_function(struct usb_configuration *, struct usb_function *);
|
||||
extern _LONG_CALL_ void usb_remove_function(struct usb_configuration *, struct usb_function *);
|
||||
extern _LONG_CALL_ void usb_put_function(struct usb_function *);
|
||||
extern _LONG_CALL_ int usb_function_deactivate(struct usb_function *);
|
||||
extern _LONG_CALL_ int usb_function_activate(struct usb_function *);
|
||||
|
||||
extern _LONG_CALL_ int usb_interface_id(struct usb_configuration *, struct usb_function *);
|
||||
extern _LONG_CALL_ int usb_composite_probe(struct usb_composite_driver *driver);
|
||||
extern _LONG_CALL_ int register_class_vendor_control_request_cb(struct usb_composite_dev *cdev, user_control_callback cb);
|
||||
extern _LONG_CALL_ void usb_composite_unregister(struct usb_composite_driver *driver);
|
||||
#endif
|
|
@ -0,0 +1,12 @@
|
|||
#ifndef _USB_CONFIG_H_
|
||||
#define _USB_CONFIG_H_
|
||||
|
||||
#include "core/inc/usb_composite.h"
|
||||
|
||||
extern _LONG_CALL_ int usb_assign_descriptors(struct usb_function *f,
|
||||
struct usb_descriptor_header **fs,
|
||||
struct usb_descriptor_header **hs,
|
||||
struct usb_descriptor_header **ss);
|
||||
|
||||
extern _LONG_CALL_ void usb_free_all_descriptors(struct usb_function *f);
|
||||
#endif
|
|
@ -0,0 +1,71 @@
|
|||
#ifndef __LINUX_UVCVIDEO_H_
|
||||
#define __LINUX_UVCVIDEO_H_
|
||||
#if 0
|
||||
#include <linux/ioctl.h>
|
||||
#include <linux/types.h>
|
||||
#endif
|
||||
#include "uvc_os_wrap_via_osdep_api.h"
|
||||
/*
|
||||
* Dynamic controls
|
||||
*/
|
||||
|
||||
/* Data types for UVC control data */
|
||||
#define UVC_CTRL_DATA_TYPE_RAW 0
|
||||
#define UVC_CTRL_DATA_TYPE_SIGNED 1
|
||||
#define UVC_CTRL_DATA_TYPE_UNSIGNED 2
|
||||
#define UVC_CTRL_DATA_TYPE_BOOLEAN 3
|
||||
#define UVC_CTRL_DATA_TYPE_ENUM 4
|
||||
#define UVC_CTRL_DATA_TYPE_BITMASK 5
|
||||
|
||||
/* Control flags */
|
||||
#define UVC_CTRL_FLAG_SET_CUR (1 << 0)
|
||||
#define UVC_CTRL_FLAG_GET_CUR (1 << 1)
|
||||
#define UVC_CTRL_FLAG_GET_MIN (1 << 2)
|
||||
#define UVC_CTRL_FLAG_GET_MAX (1 << 3)
|
||||
#define UVC_CTRL_FLAG_GET_RES (1 << 4)
|
||||
#define UVC_CTRL_FLAG_GET_DEF (1 << 5)
|
||||
/* Control should be saved at suspend and restored at resume. */
|
||||
#define UVC_CTRL_FLAG_RESTORE (1 << 6)
|
||||
/* Control can be updated by the camera. */
|
||||
#define UVC_CTRL_FLAG_AUTO_UPDATE (1 << 7)
|
||||
|
||||
#define UVC_CTRL_FLAG_GET_RANGE \
|
||||
(UVC_CTRL_FLAG_GET_CUR | UVC_CTRL_FLAG_GET_MIN | \
|
||||
UVC_CTRL_FLAG_GET_MAX | UVC_CTRL_FLAG_GET_RES | \
|
||||
UVC_CTRL_FLAG_GET_DEF)
|
||||
|
||||
struct uvc_menu_info {
|
||||
__u32 value;
|
||||
__u8 name[32];
|
||||
};
|
||||
|
||||
struct uvc_xu_control_mapping {
|
||||
__u32 id;
|
||||
__u8 name[32];
|
||||
__u8 entity[16];
|
||||
__u8 selector;
|
||||
|
||||
__u8 size;
|
||||
__u8 offset;
|
||||
__u32 v4l2_type;
|
||||
__u32 data_type;
|
||||
|
||||
struct uvc_menu_info __user *menu_info;
|
||||
__u32 menu_count;
|
||||
|
||||
__u32 reserved[4];
|
||||
};
|
||||
|
||||
struct uvc_xu_control_query {
|
||||
__u8 unit;
|
||||
__u8 selector;
|
||||
__u8 query; /* Video Class-Specific Request Code, */
|
||||
/* defined in linux/usb/video.h A.8. */
|
||||
__u16 size;
|
||||
__u8 __user *data;
|
||||
};
|
||||
|
||||
#define UVCIOC_CTRL_MAP _IOWR('u', 0x20, struct uvc_xu_control_mapping)
|
||||
#define UVCIOC_CTRL_QUERY _IOWR('u', 0x21, struct uvc_xu_control_query)
|
||||
|
||||
#endif
|
54
component/common/drivers/usb_class/host/uvc/inc/uvc_intf.h
Normal file
54
component/common/drivers/usb_class/host/uvc/inc/uvc_intf.h
Normal file
|
@ -0,0 +1,54 @@
|
|||
#ifndef _UVC_INTF_H_
|
||||
#define _UVC_INTF_H_
|
||||
|
||||
enum uvc_format_type{
|
||||
UVC_FORMAT_MJPEG = 1,
|
||||
UVC_FORMAT_H264 = 2,
|
||||
UVC_FORMAT_UNKNOWN = -1,
|
||||
};
|
||||
|
||||
typedef enum uvc_format_type uvc_fmt_t;
|
||||
|
||||
struct uvc_context
|
||||
{
|
||||
uvc_fmt_t fmt_type; //video format type
|
||||
int width;//video frame width
|
||||
int height;//video frame height
|
||||
int frame_rate;//video frame rate
|
||||
int compression_ratio;//compression format video compression ratio
|
||||
};
|
||||
|
||||
#define USER_CTRL_SATURATION 1
|
||||
|
||||
struct uvc_user_ctrl
|
||||
{
|
||||
u32 ctrl_id;
|
||||
s32 ctrl_value;
|
||||
};
|
||||
|
||||
struct uvc_buf_context
|
||||
{
|
||||
int index; //index of internal uvc buffer
|
||||
unsigned char *data; //address of uvc data
|
||||
int len; //length of uvc data
|
||||
u32 timestamp; //timestamp
|
||||
};
|
||||
|
||||
int uvc_stream_init(void); //entry function to start uvc
|
||||
void uvc_stream_free(void); // free streaming resources
|
||||
int uvc_is_stream_ready(void); // return true if uvc device is initialized successfully
|
||||
int uvc_is_stream_on(void); //return true if uvc device is streaming now
|
||||
int uvc_stream_on(void); //enable camera streaming
|
||||
void uvc_stream_off(void); //disable camera streaming
|
||||
int uvc_set_param(uvc_fmt_t fmt_type, int *width, int *height, int *frame_rate, int *compression_ratio);//set camera streaming video parameters:video format, resolution and frame rate.
|
||||
int uvc_get_user_ctrl(struct uvc_user_ctrl *user_ctrl);
|
||||
int uvc_set_user_ctrl(struct uvc_user_ctrl *user_ctrl);
|
||||
int uvc_buf_check(struct uvc_buf_context *b); //check if uvc_buf_context is legal (return 0 is legal otherwise -1)
|
||||
int uvc_dqbuf(struct uvc_buf_context *b); //dequeue internal buffer & get internal buffer info
|
||||
int uvc_qbuf(struct uvc_buf_context *b); //queue internal buffer
|
||||
int is_pure_thru_on(void); //return 1 if pure throughput test mode is on otherwise return 0
|
||||
void uvc_pure_thru_on(void); //turn on pure uvc throughput test mode (i.e. no decoding is involved)
|
||||
void uvc_dec_thru_on(void); //turn on uvc throughput test mode with uvc payload decoding
|
||||
void uvc_thru_off(void); //turn off uvc throughput log service
|
||||
|
||||
#endif
|
|
@ -0,0 +1,570 @@
|
|||
#ifndef _UVC_OSDEP_WRAP_H_
|
||||
#define _UVC_OSDEP_WRAP_H_
|
||||
|
||||
//#include "rtl_utility.h"
|
||||
#include "platform/platform_stdlib.h"
|
||||
#include "basic_types.h"
|
||||
#include "osdep_api.h"
|
||||
#include "usb_defs.h"
|
||||
|
||||
#include "errno.h"
|
||||
#include "dlist.h"
|
||||
|
||||
|
||||
|
||||
#define UVC_LAYER_DEBUG 0
|
||||
#if UVC_LAYER_DEBUG
|
||||
#define UVC_PRINTF(fmt, args...) printf("\n\r%s: " fmt, __FUNCTION__, ## args)
|
||||
#define UVC_ERROR(fmt, args...) printf("\n\r%s: " fmt, __FUNCTION__, ## args)
|
||||
#define FUN_ENTER //printf("\n\r%s ==>\n", __func__)
|
||||
#define FUN_EXIT //printf("\n\r%s <==\n", __func__)
|
||||
#define FUN_TRACE //printf("\n\r%s:%d \n", __func__, __LINE__)
|
||||
#else
|
||||
#define UVC_PRINTF(fmt, args...)
|
||||
#define UVC_ERROR(fmt, args...) printf("\n\r%s: " fmt, __FUNCTION__, ## args)
|
||||
#define FUN_ENTER
|
||||
#define FUN_EXIT
|
||||
#define FUN_TRACE
|
||||
#endif
|
||||
|
||||
/* add by Ian -- define uvc task priority */
|
||||
#define UVC_TASK_PRIORITY 2
|
||||
|
||||
#ifndef __u8
|
||||
#define __u8 u8
|
||||
#endif
|
||||
#ifndef __u16
|
||||
#define __u16 u16
|
||||
#endif
|
||||
#ifndef __u32
|
||||
#define __u32 u32
|
||||
#endif
|
||||
#ifndef __u64
|
||||
#define __u64 u64
|
||||
#endif
|
||||
#ifndef __s8
|
||||
#define __s8 s8
|
||||
#endif
|
||||
#ifndef __s16
|
||||
#define __s16 s16
|
||||
#endif
|
||||
#ifndef __s32
|
||||
#define __s32 s32
|
||||
#endif
|
||||
#ifndef __s64
|
||||
#define __s64 s64
|
||||
#endif
|
||||
|
||||
#ifndef gfp_t
|
||||
#define gfp_t u32
|
||||
#endif
|
||||
|
||||
#define ALIGN(x, a, type_of_x) (((x) + ((type_of_x)(a) - 1)) & ~((type_of_x)(a) - 1))
|
||||
|
||||
#ifndef IS_ALIGNED
|
||||
#define IS_ALIGNED(x, a, type_of_x) (((x) & ((type_of_x)(a) - 1)) == 0)
|
||||
#endif
|
||||
#ifndef ARRAY_SIZE
|
||||
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
|
||||
#endif
|
||||
|
||||
#ifndef BITS_PER_LONG
|
||||
#define BITS_PER_LONG (32)
|
||||
#endif
|
||||
#ifndef BITS_PER_LONG_LONG
|
||||
#define BITS_PER_LONG_LONG (32)
|
||||
#endif
|
||||
|
||||
/* Atomic integer operations */
|
||||
#ifndef atomic_set
|
||||
#define atomic_set(v, i) RTL_ATOMIC_SET((v), (i))
|
||||
#endif
|
||||
#ifndef atomic_read
|
||||
#define atomic_read(v) RTL_ATOMIC_READ((v))
|
||||
#endif
|
||||
#ifndef atomic_add
|
||||
#define atomic_add(v, i) RTL_ATOMIC_ADD((v), (i))
|
||||
#endif
|
||||
#ifndef atomic_sub
|
||||
#define atomic_sub(v, i) RTL_ATOMIC_SUB((v), (i))
|
||||
#endif
|
||||
#ifndef atomic_inc
|
||||
#define atomic_inc(v) RTL_ATOMIC_INC((v))
|
||||
#endif
|
||||
#ifndef atomic_dec
|
||||
#define atomic_dec(v) RTL_ATOMIC_DEC((v))
|
||||
#endif
|
||||
|
||||
#ifndef MEDIA_PAD_FL_SINK
|
||||
#define MEDIA_PAD_FL_SINK (1 << 0)
|
||||
#endif
|
||||
#ifndef MEDIA_PAD_FL_SOURCE
|
||||
#define MEDIA_PAD_FL_SOURCE (1 << 1)
|
||||
#endif
|
||||
#ifndef MEDIA_PAD_FL_MUST_CONNECT
|
||||
#define MEDIA_PAD_FL_MUST_CONNECT (1 << 2)
|
||||
#endif
|
||||
|
||||
static inline u16 __get_unaligned_le16(const u8 *p)
|
||||
{
|
||||
return p[0] | p[1] << 8;
|
||||
}
|
||||
|
||||
static inline u32 __get_unaligned_le32(const u8 *p)
|
||||
{
|
||||
return p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24;
|
||||
}
|
||||
|
||||
static inline u64 __get_unaligned_le64(const u8 *p)
|
||||
{
|
||||
return (u64)__get_unaligned_le32(p + 4) << 32 |
|
||||
__get_unaligned_le32(p);
|
||||
}
|
||||
|
||||
static inline void __put_unaligned_le16(u16 val, u8 *p)
|
||||
{
|
||||
*p++ = val;
|
||||
*p++ = val >> 8;
|
||||
}
|
||||
|
||||
static inline void __put_unaligned_le32(u32 val, u8 *p)
|
||||
{
|
||||
__put_unaligned_le16(val >> 16, p + 2);
|
||||
__put_unaligned_le16(val, p);
|
||||
}
|
||||
|
||||
static inline void __put_unaligned_le64(u64 val, u8 *p)
|
||||
{
|
||||
__put_unaligned_le32(val >> 32, p + 4);
|
||||
__put_unaligned_le32(val, p);
|
||||
}
|
||||
|
||||
static inline u16 get_unaligned_le16(const void *p)
|
||||
{
|
||||
return __get_unaligned_le16((const u8 *)p);
|
||||
}
|
||||
|
||||
static inline u32 get_unaligned_le32(const void *p)
|
||||
{
|
||||
return __get_unaligned_le32((const u8 *)p);
|
||||
}
|
||||
|
||||
static inline u64 get_unaligned_le64(const void *p)
|
||||
{
|
||||
return __get_unaligned_le64((const u8 *)p);
|
||||
}
|
||||
|
||||
static inline void put_unaligned_le16(u16 val, void *p)
|
||||
{
|
||||
__put_unaligned_le16(val, p);
|
||||
}
|
||||
|
||||
static inline void put_unaligned_le32(u32 val, void *p)
|
||||
{
|
||||
__put_unaligned_le32(val, p);
|
||||
}
|
||||
|
||||
static inline void put_unaligned_le64(u64 val, void *p)
|
||||
{
|
||||
__put_unaligned_le64(val, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* kmemdup - duplicate region of memory
|
||||
*
|
||||
* @src: memory region to duplicate
|
||||
* @len: memory region length
|
||||
* @gfp: GFP mask to use
|
||||
*/
|
||||
static inline void *kmemdup(const void *src, size_t len, gfp_t gfp)
|
||||
{
|
||||
void *p;
|
||||
|
||||
//p = kmalloc_track_caller(len, gfp);
|
||||
//p = kmalloc(len, gfp);
|
||||
p = malloc(len);
|
||||
if (p)
|
||||
memcpy(p, src, len);
|
||||
return p;
|
||||
}
|
||||
#ifndef __force
|
||||
#define __force __attribute__((force))
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
typedef __u16 __bitwise __le16;
|
||||
typedef __u16 __bitwise __be16;
|
||||
typedef __u32 __bitwise __le32;
|
||||
typedef __u32 __bitwise __be32;
|
||||
typedef __u64 __bitwise __le64;
|
||||
typedef __u64 __bitwise __be64;
|
||||
typedef __u16 __bitwise __sum16;
|
||||
typedef __u32 __bitwise __wsum;
|
||||
#endif
|
||||
//edit by Ian -- remove duplicated definitions
|
||||
#if 0
|
||||
typedef __u16 __le16;
|
||||
typedef __u16 __be16;
|
||||
typedef __u32 __le32;
|
||||
typedef __u32 __be32;
|
||||
typedef __u64 __le64;
|
||||
typedef __u64 __be64;
|
||||
typedef __u16 __sum16;
|
||||
typedef __u32 __wsum;
|
||||
#endif
|
||||
|
||||
#ifndef __le16
|
||||
#define __le16 __u16
|
||||
#endif
|
||||
#ifndef __be16
|
||||
#define __be16 __u16
|
||||
#endif
|
||||
#ifndef __le32
|
||||
#define __le32 __u32
|
||||
#endif
|
||||
#ifndef __be32
|
||||
#define __be32 __u32
|
||||
#endif
|
||||
static inline __u32 le32_to_cpup(const __le32 *p)
|
||||
{
|
||||
//return (__force __u32)*p;
|
||||
return (__u32)*p;
|
||||
}
|
||||
static inline __u16 le16_to_cpup(const __le16 *p)
|
||||
{
|
||||
//return (__force __u16)*p;
|
||||
return (__u16)*p;
|
||||
}
|
||||
|
||||
|
||||
/* Endian macros */
|
||||
#ifndef htonl
|
||||
#define htonl(x) rtk_cpu_to_be32(x)
|
||||
#endif
|
||||
|
||||
#ifndef ntohl
|
||||
#define ntohl(x) rtk_be32_to_cpu(x)
|
||||
#endif
|
||||
|
||||
#ifndef htons
|
||||
#define htons(x) rtk_cpu_to_be16(x)
|
||||
#endif
|
||||
|
||||
#ifndef ntohs
|
||||
#define ntohs(x) rtk_be16_to_cpu(x)
|
||||
#endif
|
||||
|
||||
#ifndef cpu_to_le32
|
||||
#define cpu_to_le32(x) rtk_cpu_to_le32(x)
|
||||
#endif
|
||||
|
||||
#ifndef le32_to_cpu
|
||||
#define le32_to_cpu(x) rtk_le32_to_cpu(x)
|
||||
#endif
|
||||
|
||||
#ifndef cpu_to_le16
|
||||
#define cpu_to_le16(x) rtk_cpu_to_le16(x)
|
||||
#endif
|
||||
|
||||
#ifndef le16_to_cpu
|
||||
#define le16_to_cpu(x) rtk_le16_to_cpu(x)
|
||||
#endif
|
||||
|
||||
#ifndef cpu_to_be32
|
||||
#define cpu_to_be32(x) rtk_cpu_to_be32(x)
|
||||
#endif
|
||||
|
||||
#ifndef be32_to_cpu
|
||||
#define be32_to_cpu(x) rtk_be32_to_cpu(x)
|
||||
#endif
|
||||
|
||||
#ifndef cpu_to_be16
|
||||
#define cpu_to_be16(x) rtk_cpu_to_be16(x)
|
||||
#endif
|
||||
|
||||
#ifndef be16_to_cpu
|
||||
#define be16_to_cpu(x) rtk_be16_to_cpu(x)
|
||||
#endif
|
||||
|
||||
/* Parameters used to convert the timespec values: */
|
||||
#ifndef MSEC_PER_SEC
|
||||
#define MSEC_PER_SEC 1000L
|
||||
#endif
|
||||
#ifndef USEC_PER_MSEC
|
||||
#define USEC_PER_MSEC 1000L
|
||||
#endif
|
||||
#ifndef NSEC_PER_USEC
|
||||
#define NSEC_PER_USEC 1000L
|
||||
#endif
|
||||
#ifndef NSEC_PER_MSEC
|
||||
#define NSEC_PER_MSEC 1000000L
|
||||
#endif
|
||||
#ifndef USEC_PER_SEC
|
||||
#define USEC_PER_SEC 1000000L
|
||||
#endif
|
||||
#ifndef NSEC_PER_SEC
|
||||
#define NSEC_PER_SEC 1000000000L
|
||||
#endif
|
||||
#ifndef FSEC_PER_SEC
|
||||
#define FSEC_PER_SEC 1000000000000000LL
|
||||
#endif
|
||||
#ifndef TIME_T_MAX
|
||||
#define TIME_T_MAX (time_t)((1UL << ((sizeof(time_t) << 3) - 1)) - 1)
|
||||
#endif
|
||||
|
||||
#ifndef __GFP_WAIT
|
||||
#define __GFP_WAIT (0x10u)
|
||||
#endif
|
||||
#ifndef __GFP_HIGH
|
||||
#define __GFP_HIGH (0x20u)
|
||||
#endif
|
||||
#ifndef __GFP_IO
|
||||
#define __GFP_IO (0x40u)
|
||||
#endif
|
||||
#ifndef __GFP_FS
|
||||
#define __GFP_FS (0x80u)
|
||||
#endif
|
||||
#ifndef GFP_NOIO
|
||||
#define GFP_NOIO (0x10u)
|
||||
#endif
|
||||
#ifndef __GFP_NOWARN
|
||||
#define __GFP_NOWARN (0x200u)
|
||||
#endif
|
||||
#ifndef GFP_KERNEL
|
||||
#define GFP_KERNEL (__GFP_WAIT | __GFP_IO | __GFP_FS)
|
||||
#endif
|
||||
|
||||
#ifndef copy_from_user
|
||||
#define copy_from_user(to, from, sz) RtlMemcpy((to), (from), (sz))
|
||||
#endif
|
||||
#ifndef copy_to_user
|
||||
#define copy_to_user(to, from, sz) RtlMemcpy((to), (from), (sz))
|
||||
#endif
|
||||
|
||||
typedef u32 compat_caddr_t; //used for compatibility in uvc_v4l2.c
|
||||
|
||||
/**
|
||||
* strlcpy - Copy a %NUL terminated string into a sized buffer
|
||||
* @dest: Where to copy the string to
|
||||
* @src: Where to copy the string from
|
||||
* @size: size of destination buffer
|
||||
*
|
||||
* Compatible with *BSD: the result is always a valid
|
||||
* NUL-terminated string that fits in the buffer (unless,
|
||||
* of course, the buffer size is zero). It does not pad
|
||||
* out the result like strncpy() does.
|
||||
*/
|
||||
static inline size_t strlcpy(char *dest, const char *src, size_t size)
|
||||
{
|
||||
size_t ret = _strlen(src);
|
||||
|
||||
if (size) {
|
||||
size_t len = (ret >= size) ? size - 1 : ret;
|
||||
memcpy(dest, src, len);
|
||||
dest[len] = '\0';
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* clamp - return a value clamped to a given range with strict typechecking
|
||||
* @val: current value
|
||||
* @min: minimum allowable value
|
||||
* @max: maximum allowable value
|
||||
*
|
||||
* This macro does strict typechecking of min/max to make sure they are of the
|
||||
* same type as val. See the unnecessary pointer comparisons.
|
||||
*/
|
||||
|
||||
#ifndef clamp
|
||||
#define clamp(new_val, val, min, max, type) do{ \
|
||||
type __val = (val); \
|
||||
type __min = (min); \
|
||||
type __max = (max); \
|
||||
(void) (&__val == &__min); \
|
||||
(void) (&__val == &__max); \
|
||||
__val = (__val < __min) ? __min: __val; \
|
||||
new_val = (__val > __max) ? __max: __val; }while(0)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Compile time versions of __arch_hweightN()
|
||||
*/
|
||||
#ifndef __const_hweight8
|
||||
#define __const_hweight8(w) \
|
||||
( (!!((w) & (1ULL << 0))) + \
|
||||
(!!((w) & (1ULL << 1))) + \
|
||||
(!!((w) & (1ULL << 2))) + \
|
||||
(!!((w) & (1ULL << 3))) + \
|
||||
(!!((w) & (1ULL << 4))) + \
|
||||
(!!((w) & (1ULL << 5))) + \
|
||||
(!!((w) & (1ULL << 6))) + \
|
||||
(!!((w) & (1ULL << 7))) )
|
||||
#endif
|
||||
#ifndef hweight8
|
||||
#define hweight8(w) __const_hweight8(w)
|
||||
#endif
|
||||
#ifndef BITMAP_LAST_WORD_MASK
|
||||
#define BITMAP_LAST_WORD_MASK(nbits) \
|
||||
( \
|
||||
((nbits) % BITS_PER_LONG) ? \
|
||||
(1UL<<((nbits) % BITS_PER_LONG))-1 : ~0UL \
|
||||
)
|
||||
#endif
|
||||
/**
|
||||
* hweightN - returns the hamming weight of a N-bit word
|
||||
* @x: the word to weigh
|
||||
*
|
||||
* The Hamming Weight of a number is the total number of bits set in it.
|
||||
*/
|
||||
static inline unsigned int hweight32(unsigned int w)
|
||||
{
|
||||
unsigned int res = w - ((w >> 1) & 0x55555555);
|
||||
res = (res & 0x33333333) + ((res >> 2) & 0x33333333);
|
||||
res = (res + (res >> 4)) & 0x0F0F0F0F;
|
||||
res = res + (res >> 8);
|
||||
return (res + (res >> 16)) & 0x000000FF;
|
||||
}
|
||||
|
||||
static inline unsigned long hweight64(__u64 w)
|
||||
{
|
||||
#if BITS_PER_LONG == 32
|
||||
return hweight32((unsigned int)(w >> 32)) + hweight32((unsigned int)w);
|
||||
#elif BITS_PER_LONG == 64
|
||||
__u64 res = w - ((w >> 1) & 0x5555555555555555ul);
|
||||
res = (res & 0x3333333333333333ul) + ((res >> 2) & 0x3333333333333333ul);
|
||||
res = (res + (res >> 4)) & 0x0F0F0F0F0F0F0F0Ful;
|
||||
res = res + (res >> 8);
|
||||
res = res + (res >> 16);
|
||||
return (res + (res >> 32)) & 0x00000000000000FFul;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static inline unsigned long hweight_long(unsigned long w)
|
||||
{
|
||||
return sizeof(w) == 4 ? hweight32(w) : hweight64(w);
|
||||
}
|
||||
|
||||
static inline int __bitmap_weight(const unsigned long *bitmap, int bits)
|
||||
{
|
||||
int k, w = 0, lim = bits/BITS_PER_LONG;
|
||||
|
||||
for (k = 0; k < lim; k++)
|
||||
w += hweight_long(bitmap[k]);
|
||||
|
||||
if (bits % BITS_PER_LONG)
|
||||
w += hweight_long(bitmap[k] & BITMAP_LAST_WORD_MASK(bits));
|
||||
|
||||
return w;
|
||||
}
|
||||
|
||||
static inline int bitmap_weight(const unsigned long *src, int nbits)
|
||||
{
|
||||
// if (small_const_nbits(nbits))
|
||||
// return hweight_long(*src & BITMAP_LAST_WORD_MASK(nbits));
|
||||
return __bitmap_weight(src, nbits);
|
||||
}
|
||||
|
||||
/**
|
||||
* memweight - count the total number of bits set in memory area
|
||||
* @ptr: pointer to the start of the area
|
||||
* @bytes: the size of the area
|
||||
*/
|
||||
static inline size_t memweight(const void *ptr, size_t bytes)
|
||||
{
|
||||
size_t ret = 0;
|
||||
size_t longs;
|
||||
const unsigned char *bitmap = ptr;
|
||||
|
||||
for (; bytes > 0 && ((unsigned long)bitmap) % sizeof(long);
|
||||
bytes--, bitmap++)
|
||||
ret += hweight8(*bitmap);
|
||||
|
||||
longs = bytes / sizeof(long);
|
||||
if (longs) {
|
||||
//BUG_ON(longs >= INT_MAX / BITS_PER_LONG);
|
||||
ret += bitmap_weight((unsigned long *)bitmap, longs * BITS_PER_LONG);
|
||||
bytes -= longs * sizeof(long);
|
||||
bitmap += longs * sizeof(long);
|
||||
}
|
||||
/*
|
||||
* The reason that this last loop is distinct from the preceding
|
||||
* bitmap_weight() call is to compute 1-bits in the last region smaller
|
||||
* than sizeof(long) properly on big-endian systems.
|
||||
*/
|
||||
for (; bytes > 0; bytes--, bitmap++)
|
||||
ret += hweight8(*bitmap);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* strlcat - Append a length-limited, %NUL-terminated string to another
|
||||
* @dest: The string to be appended to
|
||||
* @src: The string to append to it
|
||||
* @count: The size of the destination buffer.
|
||||
*/
|
||||
static inline size_t strlcat(char *dest, const char *src, size_t count)
|
||||
{
|
||||
size_t dsize = _strlen(dest);
|
||||
size_t len = _strlen(src);
|
||||
size_t res = dsize + len;
|
||||
|
||||
/* This would be a bug */
|
||||
//BUG_ON(dsize >= count);
|
||||
|
||||
dest += dsize;
|
||||
count -= dsize;
|
||||
if (len >= count)
|
||||
len = count-1;
|
||||
memcpy(dest, src, len);
|
||||
dest[len] = 0;
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* atomic_dec_and_test - decrement and test
|
||||
* @v: pointer of type atomic_t
|
||||
*
|
||||
* Atomically decrements @v by 1 and
|
||||
* returns true if the result is 0, or false for all other
|
||||
* cases.
|
||||
*/
|
||||
static inline int atomic_dec_and_test(atomic_t *v)
|
||||
{
|
||||
atomic_dec(v);
|
||||
if (v->counter == 0)
|
||||
return TRUE;
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* kcalloc - allocate memory for an array. The memory is set to zero.
|
||||
* @n: number of elements.
|
||||
* @size: element size.
|
||||
* @flags: the type of memory to allocate (see kmalloc).
|
||||
*/
|
||||
static inline void *kcalloc(size_t n, size_t size, gfp_t flags)
|
||||
{
|
||||
return RtlZmalloc(((n) * (size)));
|
||||
}
|
||||
|
||||
#ifndef GFP_ATOMIC
|
||||
#define GFP_ATOMIC GFP_KERNEL
|
||||
#endif
|
||||
#ifndef offsetof
|
||||
#define offsetof(s,m) (size_t)&(((s *)0)->m)
|
||||
#endif
|
||||
|
||||
//enum linux kernel version
|
||||
#ifndef KERNEL_VERSION
|
||||
#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
|
||||
#endif
|
||||
#ifndef LINUX_VERSION_CODE
|
||||
#define LINUX_VERSION_CODE KERNEL_VERSION(3, 12, 0)
|
||||
#endif
|
||||
|
||||
#endif //_UVC_OSDEP_WRAP_H_
|
774
component/common/drivers/usb_class/host/uvc/inc/uvcvideo.h
Normal file
774
component/common/drivers/usb_class/host/uvc/inc/uvcvideo.h
Normal file
|
@ -0,0 +1,774 @@
|
|||
#ifndef _USB_VIDEO_H_
|
||||
#define _USB_VIDEO_H_
|
||||
#if 0
|
||||
#ifndef __KERNEL__
|
||||
#error "The uvcvideo.h header is deprecated, use linux/uvcvideo.h instead."
|
||||
#endif /* __KERNEL__ */
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/poll.h>
|
||||
#endif
|
||||
|
||||
#include "usb.h"
|
||||
#include "video.h"
|
||||
#include "uvcvideo.h"
|
||||
|
||||
#include "videodev2.h"
|
||||
#include "media-device.h"
|
||||
#include "v4l2-device.h"
|
||||
#include "v4l2-event.h"
|
||||
#include "v4l2-fh.h"
|
||||
#include "videobuf2-core.h"
|
||||
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* UVC constants
|
||||
*/
|
||||
|
||||
#define UVC_TERM_INPUT 0x0000
|
||||
#define UVC_TERM_OUTPUT 0x8000
|
||||
#define UVC_TERM_DIRECTION(term) ((term)->type & 0x8000)
|
||||
|
||||
#define UVC_ENTITY_TYPE(entity) ((entity)->type & 0x7fff)
|
||||
#define UVC_ENTITY_IS_UNIT(entity) (((entity)->type & 0xff00) == 0)
|
||||
#define UVC_ENTITY_IS_TERM(entity) (((entity)->type & 0xff00) != 0)
|
||||
#define UVC_ENTITY_IS_ITERM(entity) \
|
||||
(UVC_ENTITY_IS_TERM(entity) && \
|
||||
((entity)->type & 0x8000) == UVC_TERM_INPUT)
|
||||
#define UVC_ENTITY_IS_OTERM(entity) \
|
||||
(UVC_ENTITY_IS_TERM(entity) && \
|
||||
((entity)->type & 0x8000) == UVC_TERM_OUTPUT)
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------
|
||||
* GUIDs
|
||||
*/
|
||||
#define UVC_GUID_UVC_CAMERA \
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}
|
||||
#define UVC_GUID_UVC_OUTPUT \
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}
|
||||
#define UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT \
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03}
|
||||
#define UVC_GUID_UVC_PROCESSING \
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01}
|
||||
#define UVC_GUID_UVC_SELECTOR \
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02}
|
||||
|
||||
#define UVC_GUID_FORMAT_MJPEG \
|
||||
{ 'M', 'J', 'P', 'G', 0x00, 0x00, 0x10, 0x00, \
|
||||
0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
|
||||
#define UVC_GUID_FORMAT_YUY2 \
|
||||
{ 'Y', 'U', 'Y', '2', 0x00, 0x00, 0x10, 0x00, \
|
||||
0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
|
||||
#define UVC_GUID_FORMAT_YUY2_ISIGHT \
|
||||
{ 'Y', 'U', 'Y', '2', 0x00, 0x00, 0x10, 0x00, \
|
||||
0x80, 0x00, 0x00, 0x00, 0x00, 0x38, 0x9b, 0x71}
|
||||
#define UVC_GUID_FORMAT_NV12 \
|
||||
{ 'N', 'V', '1', '2', 0x00, 0x00, 0x10, 0x00, \
|
||||
0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
|
||||
#define UVC_GUID_FORMAT_YV12 \
|
||||
{ 'Y', 'V', '1', '2', 0x00, 0x00, 0x10, 0x00, \
|
||||
0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
|
||||
#define UVC_GUID_FORMAT_I420 \
|
||||
{ 'I', '4', '2', '0', 0x00, 0x00, 0x10, 0x00, \
|
||||
0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
|
||||
#define UVC_GUID_FORMAT_UYVY \
|
||||
{ 'U', 'Y', 'V', 'Y', 0x00, 0x00, 0x10, 0x00, \
|
||||
0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
|
||||
#define UVC_GUID_FORMAT_Y800 \
|
||||
{ 'Y', '8', '0', '0', 0x00, 0x00, 0x10, 0x00, \
|
||||
0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
|
||||
#define UVC_GUID_FORMAT_Y8 \
|
||||
{ 'Y', '8', ' ', ' ', 0x00, 0x00, 0x10, 0x00, \
|
||||
0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
|
||||
#define UVC_GUID_FORMAT_Y10 \
|
||||
{ 'Y', '1', '0', ' ', 0x00, 0x00, 0x10, 0x00, \
|
||||
0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
|
||||
#define UVC_GUID_FORMAT_Y12 \
|
||||
{ 'Y', '1', '2', ' ', 0x00, 0x00, 0x10, 0x00, \
|
||||
0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
|
||||
#define UVC_GUID_FORMAT_Y16 \
|
||||
{ 'Y', '1', '6', ' ', 0x00, 0x00, 0x10, 0x00, \
|
||||
0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
|
||||
#define UVC_GUID_FORMAT_BY8 \
|
||||
{ 'B', 'Y', '8', ' ', 0x00, 0x00, 0x10, 0x00, \
|
||||
0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
|
||||
#define UVC_GUID_FORMAT_RGBP \
|
||||
{ 'R', 'G', 'B', 'P', 0x00, 0x00, 0x10, 0x00, \
|
||||
0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
|
||||
#define UVC_GUID_FORMAT_M420 \
|
||||
{ 'M', '4', '2', '0', 0x00, 0x00, 0x10, 0x00, \
|
||||
0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
|
||||
|
||||
#define UVC_GUID_FORMAT_H264 \
|
||||
{ 'H', '2', '6', '4', 0x00, 0x00, 0x10, 0x00, \
|
||||
0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
|
||||
/* edit by Ian -- patch for GEO add two new guids*/
|
||||
#define UVC_GUID_FORMAT_MPEG \
|
||||
{ 'M', 'P', 'E', 'G', 0x00, 0x00, 0x10, 0x00, \
|
||||
0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
|
||||
#define UVC_GUID_FORMAT_MUX \
|
||||
{ 'M', 'U', 'X', 0x00, 0x00, 0x00, 0x10, 0x00, \
|
||||
0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
|
||||
/* ------------------------------------------------------------------------
|
||||
* Driver specific constants.
|
||||
*/
|
||||
|
||||
#define DRIVER_VERSION "1.1.1"
|
||||
|
||||
/* Number of isochronous URBs. */
|
||||
#define UVC_URBS 2
|
||||
/* Maximum number of packets per URB. */
|
||||
#define UVC_MAX_PACKETS 32
|
||||
/* Maximum number of video buffers. */
|
||||
#define UVC_MAX_VIDEO_BUFFERS 8
|
||||
/* Maximum status buffer size in bytes of interrupt URB. */
|
||||
#define UVC_MAX_STATUS_SIZE 16
|
||||
|
||||
//modified by Ian
|
||||
#define UVC_REQBUF_SIZE (150000)
|
||||
|
||||
#define UVC_CTRL_CONTROL_TIMEOUT 300
|
||||
#define UVC_CTRL_STREAMING_TIMEOUT 5000
|
||||
|
||||
/* Maximum allowed number of control mappings per device */
|
||||
#define UVC_MAX_CONTROL_MAPPINGS 1024
|
||||
#define UVC_MAX_CONTROL_MENU_ENTRIES 32
|
||||
|
||||
/* Devices quirks */
|
||||
#define UVC_QUIRK_STATUS_INTERVAL 0x00000001
|
||||
#define UVC_QUIRK_PROBE_MINMAX 0x00000002
|
||||
#define UVC_QUIRK_PROBE_EXTRAFIELDS 0x00000004
|
||||
#define UVC_QUIRK_BUILTIN_ISIGHT 0x00000008
|
||||
#define UVC_QUIRK_STREAM_NO_FID 0x00000010
|
||||
#define UVC_QUIRK_IGNORE_SELECTOR_UNIT 0x00000020
|
||||
#define UVC_QUIRK_FIX_BANDWIDTH 0x00000080
|
||||
#define UVC_QUIRK_PROBE_DEF 0x00000100
|
||||
#define UVC_QUIRK_RESTRICT_FRAME_RATE 0x00000200
|
||||
|
||||
/* Format flags */
|
||||
#define UVC_FMT_FLAG_COMPRESSED 0x00000001
|
||||
#define UVC_FMT_FLAG_STREAM 0x00000002
|
||||
|
||||
/* ------------------------------------------------------------------------
|
||||
* Structures.
|
||||
*/
|
||||
|
||||
struct uvc_device;
|
||||
|
||||
/* TODO: Put the most frequently accessed fields at the beginning of
|
||||
* structures to maximize cache efficiency.
|
||||
*/
|
||||
struct uvc_control_info {
|
||||
struct list_head mappings;
|
||||
__u8 entity[16];
|
||||
__u8 index; /* Bit index in bmControls */
|
||||
__u8 selector;
|
||||
|
||||
__u16 size;
|
||||
__u32 flags;
|
||||
};
|
||||
|
||||
struct uvc_control_mapping {
|
||||
struct list_head list;
|
||||
struct list_head ev_subs;
|
||||
|
||||
__u32 id;
|
||||
__u8 name[32];
|
||||
__u8 entity[16];
|
||||
__u8 selector;
|
||||
|
||||
__u8 size;
|
||||
__u8 offset;
|
||||
enum v4l2_ctrl_type v4l2_type;
|
||||
__u32 data_type;
|
||||
|
||||
struct uvc_menu_info *menu_info;
|
||||
__u32 menu_count;
|
||||
|
||||
__u32 master_id;
|
||||
__s32 master_manual;
|
||||
__u32 slave_ids[2];
|
||||
|
||||
__s32 (*get) (struct uvc_control_mapping *mapping, __u8 query,
|
||||
const __u8 *data);
|
||||
void (*set) (struct uvc_control_mapping *mapping, __s32 value,
|
||||
__u8 *data);
|
||||
};
|
||||
|
||||
struct uvc_control {
|
||||
struct uvc_entity *entity;
|
||||
struct uvc_control_info info;
|
||||
|
||||
__u8 index; /* Used to match the uvc_control entry with a
|
||||
uvc_control_info. */
|
||||
__u8 dirty:1,
|
||||
loaded:1,
|
||||
modified:1,
|
||||
cached:1,
|
||||
initialized:1;
|
||||
|
||||
__u8 *uvc_data;
|
||||
};
|
||||
|
||||
struct uvc_format_desc {
|
||||
char *name;
|
||||
__u8 guid[16];
|
||||
__u32 fcc;
|
||||
};
|
||||
|
||||
/* The term 'entity' refers to both UVC units and UVC terminals.
|
||||
*
|
||||
* The type field is either the terminal type (wTerminalType in the terminal
|
||||
* descriptor), or the unit type (bDescriptorSubtype in the unit descriptor).
|
||||
* As the bDescriptorSubtype field is one byte long, the type value will
|
||||
* always have a null MSB for units. All terminal types defined by the UVC
|
||||
* specification have a non-null MSB, so it is safe to use the MSB to
|
||||
* differentiate between units and terminals as long as the descriptor parsing
|
||||
* code makes sure terminal types have a non-null MSB.
|
||||
*
|
||||
* For terminals, the type's most significant bit stores the terminal
|
||||
* direction (either UVC_TERM_INPUT or UVC_TERM_OUTPUT). The type field should
|
||||
* always be accessed with the UVC_ENTITY_* macros and never directly.
|
||||
*/
|
||||
|
||||
#define UVC_ENTITY_FLAG_DEFAULT (1 << 0)
|
||||
|
||||
struct uvc_entity {
|
||||
struct list_head list; /* Entity as part of a UVC device. */
|
||||
struct list_head chain; /* Entity as part of a video device
|
||||
* chain. */
|
||||
unsigned int flags;
|
||||
|
||||
__u8 id;
|
||||
__u16 type;
|
||||
char name[64];
|
||||
|
||||
/* Media controller-related fields. */
|
||||
struct video_device *vdev;
|
||||
struct v4l2_subdev subdev;
|
||||
unsigned int num_pads;
|
||||
unsigned int num_links;
|
||||
struct media_pad *pads;
|
||||
|
||||
union {
|
||||
struct {
|
||||
__u16 wObjectiveFocalLengthMin;
|
||||
__u16 wObjectiveFocalLengthMax;
|
||||
__u16 wOcularFocalLength;
|
||||
__u8 bControlSize;
|
||||
__u8 *bmControls;
|
||||
} camera;
|
||||
|
||||
struct {
|
||||
__u8 bControlSize;
|
||||
__u8 *bmControls;
|
||||
__u8 bTransportModeSize;
|
||||
__u8 *bmTransportModes;
|
||||
} media;
|
||||
#if 0
|
||||
struct {
|
||||
} output;
|
||||
#endif
|
||||
struct {
|
||||
__u16 wMaxMultiplier;
|
||||
__u8 bControlSize;
|
||||
__u8 *bmControls;
|
||||
__u8 bmVideoStandards;
|
||||
} processing;
|
||||
#if 0
|
||||
struct {
|
||||
} selector;
|
||||
#endif
|
||||
struct {
|
||||
__u8 guidExtensionCode[16];
|
||||
__u8 bNumControls;
|
||||
__u8 bControlSize;
|
||||
__u8 *bmControls;
|
||||
__u8 *bmControlsType;
|
||||
} extension;
|
||||
};
|
||||
|
||||
__u8 bNrInPins;
|
||||
__u8 *baSourceID;
|
||||
|
||||
unsigned int ncontrols;
|
||||
struct uvc_control *controls;
|
||||
};
|
||||
|
||||
// total (27)-> 28 Bytes
|
||||
struct uvc_frame {
|
||||
__u8 bFrameIndex;
|
||||
__u8 bmCapabilities;
|
||||
__u16 wWidth;
|
||||
__u16 wHeight;
|
||||
__u32 dwMinBitRate;
|
||||
__u32 dwMaxBitRate;
|
||||
__u32 dwMaxVideoFrameBufferSize;
|
||||
__u8 bFrameIntervalType;
|
||||
__u32 dwDefaultFrameInterval;
|
||||
__u32 *dwFrameInterval;
|
||||
};
|
||||
|
||||
// total 52 Bytes
|
||||
struct uvc_format {
|
||||
__u8 type;
|
||||
__u8 index;
|
||||
__u8 bpp;
|
||||
__u8 colorspace;
|
||||
__u32 fcc;
|
||||
__u32 flags;
|
||||
|
||||
char name[32];
|
||||
|
||||
unsigned int nframes;
|
||||
struct uvc_frame *frame;
|
||||
};
|
||||
|
||||
struct uvc_streaming_header {
|
||||
__u8 bNumFormats;
|
||||
__u8 bEndpointAddress;
|
||||
__u8 bTerminalLink;
|
||||
__u8 bControlSize;
|
||||
__u8 *bmaControls;
|
||||
/* The following fields are used by input headers only. */
|
||||
__u8 bmInfo;
|
||||
__u8 bStillCaptureMethod;
|
||||
__u8 bTriggerSupport;
|
||||
__u8 bTriggerUsage;
|
||||
};
|
||||
|
||||
enum uvc_buffer_state {
|
||||
UVC_BUF_STATE_IDLE = 0,
|
||||
UVC_BUF_STATE_QUEUED = 1,
|
||||
UVC_BUF_STATE_ACTIVE = 2,
|
||||
UVC_BUF_STATE_READY = 3,
|
||||
UVC_BUF_STATE_DONE = 4,
|
||||
UVC_BUF_STATE_ERROR = 5,
|
||||
};
|
||||
|
||||
struct uvc_buffer {
|
||||
struct vb2_buffer buf;
|
||||
struct list_head queue;
|
||||
_Mutex mutex;
|
||||
enum uvc_buffer_state state;
|
||||
unsigned int error;
|
||||
|
||||
void *mem;
|
||||
unsigned int length;
|
||||
unsigned int bytesused;
|
||||
|
||||
u32 pts;
|
||||
};
|
||||
|
||||
#define UVC_QUEUE_DISCONNECTED (1 << 0)
|
||||
#define UVC_QUEUE_DROP_CORRUPTED (1 << 1)
|
||||
|
||||
struct uvc_video_queue {
|
||||
struct vb2_queue queue;
|
||||
//struct mutex mutex; /* Protects queue */
|
||||
_Mutex mutex;
|
||||
unsigned int flags;
|
||||
unsigned int buf_used;
|
||||
|
||||
//spinlock_t irqlock; /* Protects irqqueue */
|
||||
//_LOCK_T irqlock;
|
||||
_Mutex irqlock;
|
||||
struct list_head irqqueue;
|
||||
};
|
||||
|
||||
struct uvc_video_chain {
|
||||
struct uvc_device *dev;
|
||||
struct list_head list;
|
||||
|
||||
struct list_head entities; /* All entities */
|
||||
struct uvc_entity *processing; /* Processing unit */
|
||||
struct uvc_entity *selector; /* Selector unit */
|
||||
|
||||
//struct mutex ctrl_mutex; /* Protects ctrl.info */
|
||||
_Mutex ctrl_mutex;
|
||||
|
||||
struct v4l2_prio_state prio; /* V4L2 priority state */
|
||||
u32 caps; /* V4L2 chain-wide caps */
|
||||
};
|
||||
|
||||
struct uvc_stats_frame {
|
||||
unsigned int size; /* Number of bytes captured */
|
||||
unsigned int first_data; /* Index of the first non-empty packet */
|
||||
|
||||
unsigned int nb_packets; /* Number of packets */
|
||||
unsigned int nb_empty; /* Number of empty packets */
|
||||
unsigned int nb_invalid; /* Number of packets with an invalid header */
|
||||
unsigned int nb_errors; /* Number of packets with the error bit set */
|
||||
|
||||
unsigned int nb_pts; /* Number of packets with a PTS timestamp */
|
||||
unsigned int nb_pts_diffs; /* Number of PTS differences inside a frame */
|
||||
unsigned int last_pts_diff; /* Index of the last PTS difference */
|
||||
bool has_initial_pts; /* Whether the first non-empty packet has a PTS */
|
||||
bool has_early_pts; /* Whether a PTS is present before the first non-empty packet */
|
||||
u32 pts; /* PTS of the last packet */
|
||||
|
||||
unsigned int nb_scr; /* Number of packets with a SCR timestamp */
|
||||
unsigned int nb_scr_diffs; /* Number of SCR.STC differences inside a frame */
|
||||
u16 scr_sof; /* SCR.SOF of the last packet */
|
||||
u32 scr_stc; /* SCR.STC of the last packet */
|
||||
};
|
||||
|
||||
struct uvc_stats_stream {
|
||||
//struct timespec start_ts; /* Stream start timestamp */
|
||||
//struct timespec stop_ts; /* Stream stop timestamp */
|
||||
u32 start_ts;
|
||||
u32 stop_ts;
|
||||
|
||||
|
||||
unsigned int nb_frames; /* Number of frames */
|
||||
|
||||
unsigned int nb_packets; /* Number of packets */
|
||||
unsigned int nb_empty; /* Number of empty packets */
|
||||
unsigned int nb_invalid; /* Number of packets with an invalid header */
|
||||
unsigned int nb_errors; /* Number of packets with the error bit set */
|
||||
|
||||
unsigned int nb_pts_constant; /* Number of frames with constant PTS */
|
||||
unsigned int nb_pts_early; /* Number of frames with early PTS */
|
||||
unsigned int nb_pts_initial; /* Number of frames with initial PTS */
|
||||
|
||||
unsigned int nb_scr_count_ok; /* Number of frames with at least one SCR per non empty packet */
|
||||
unsigned int nb_scr_diffs_ok; /* Number of frames with varying SCR.STC */
|
||||
unsigned int scr_sof_count; /* STC.SOF counter accumulated since stream start */
|
||||
unsigned int scr_sof; /* STC.SOF of the last packet */
|
||||
unsigned int min_sof; /* Minimum STC.SOF value */
|
||||
unsigned int max_sof; /* Maximum STC.SOF value */
|
||||
};
|
||||
|
||||
struct uvc_streaming {
|
||||
struct list_head list;
|
||||
struct uvc_device *dev;
|
||||
struct video_device *vdev;
|
||||
struct uvc_video_chain *chain;
|
||||
atomic_t active;
|
||||
|
||||
struct usb_interface *intf;
|
||||
int intfnum;
|
||||
__u16 maxpsize;
|
||||
|
||||
struct uvc_streaming_header header;
|
||||
enum v4l2_buf_type type;
|
||||
|
||||
unsigned int nformats;
|
||||
struct uvc_format *format;
|
||||
|
||||
struct uvc_streaming_control ctrl;
|
||||
struct uvc_format *def_format;
|
||||
struct uvc_format *cur_format;
|
||||
struct uvc_frame *cur_frame;
|
||||
/* Protect access to ctrl, cur_format, cur_frame and hardware video
|
||||
* probe control.
|
||||
*/
|
||||
//struct mutex mutex;
|
||||
_Mutex mutex;
|
||||
|
||||
/* Buffers queue. */
|
||||
unsigned int frozen : 1;
|
||||
struct uvc_video_queue queue;
|
||||
void (*decode) (struct urb *urb, struct uvc_streaming *video,
|
||||
struct uvc_buffer *buf);
|
||||
|
||||
/* Context data used by the bulk completion handler. */
|
||||
struct {
|
||||
__u8 header[256];
|
||||
unsigned int header_size;
|
||||
int skip_payload;
|
||||
__u32 payload_size;
|
||||
__u32 max_payload_size;
|
||||
} bulk;
|
||||
|
||||
struct urb *urb[UVC_URBS];
|
||||
char *urb_buffer[UVC_URBS];
|
||||
dma_addr_t urb_dma[UVC_URBS];
|
||||
unsigned int urb_size;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
__u32 sequence;
|
||||
__u8 last_fid;
|
||||
|
||||
/* debugfs */
|
||||
//struct dentry *debugfs_dir;
|
||||
struct {
|
||||
struct uvc_stats_frame frame;
|
||||
struct uvc_stats_stream stream;
|
||||
} stats;
|
||||
|
||||
/* Timestamps support. */
|
||||
struct uvc_clock {
|
||||
struct uvc_clock_sample {
|
||||
u32 dev_stc;
|
||||
u16 dev_sof;
|
||||
//struct timespec host_ts;
|
||||
u32 host_ts; //change to tick
|
||||
u16 host_sof;
|
||||
} *samples;
|
||||
|
||||
unsigned int head;
|
||||
unsigned int count;
|
||||
unsigned int size;
|
||||
|
||||
u16 last_sof;
|
||||
u16 sof_offset;
|
||||
|
||||
//spinlock_t lock;
|
||||
_Lock lock;
|
||||
} clock;
|
||||
};
|
||||
|
||||
enum uvc_device_state {
|
||||
UVC_DEV_DISCONNECTED = 1,
|
||||
};
|
||||
|
||||
struct uvc_device {
|
||||
struct usb_device *udev;
|
||||
struct usb_interface *intf;
|
||||
unsigned long warnings;
|
||||
__u32 quirks;
|
||||
int intfnum;
|
||||
char name[32];
|
||||
|
||||
enum uvc_device_state state;
|
||||
//struct mutex lock; /* Protects users */
|
||||
_Mutex lock;
|
||||
unsigned int users;
|
||||
atomic_t nmappings;
|
||||
|
||||
/* Video control interface */
|
||||
#ifdef CONFIG_MEDIA_CONTROLLER
|
||||
struct media_device mdev;
|
||||
#endif
|
||||
struct v4l2_device vdev;
|
||||
__u16 uvc_version;
|
||||
__u32 clock_frequency;
|
||||
|
||||
struct list_head entities; // VC_EXTENSION_UNIT ->VC_INPUT_TERMINAL ->VC_PROCESSING_UNIT ->VC_OUTPUT_TERMINAL
|
||||
struct list_head chains;
|
||||
|
||||
/* Video Streaming interfaces */
|
||||
struct list_head streams;
|
||||
atomic_t nstreams;
|
||||
|
||||
/* Status Interrupt Endpoint */
|
||||
struct usb_host_endpoint *int_ep;
|
||||
struct urb *int_urb;
|
||||
__u8 *status;
|
||||
//struct input_dev *input;
|
||||
char input_phys[64];
|
||||
};
|
||||
|
||||
enum uvc_handle_state {
|
||||
UVC_HANDLE_PASSIVE = 0,
|
||||
UVC_HANDLE_ACTIVE = 1,
|
||||
};
|
||||
|
||||
/* uvc file handle */
|
||||
struct uvc_fh {
|
||||
struct v4l2_fh vfh;
|
||||
struct uvc_video_chain *chain;
|
||||
struct uvc_streaming *stream;
|
||||
enum uvc_handle_state state;
|
||||
};
|
||||
#if 0
|
||||
/* uvc_driver = usb_driver for interface
|
||||
* - identifies USB interface driver to usbcore
|
||||
*/
|
||||
struct uvc_driver {
|
||||
struct usb_driver driver;
|
||||
};
|
||||
#endif
|
||||
|
||||
/* ------------------------------------------------------------------------
|
||||
* Debugging, printing and logging
|
||||
*/
|
||||
|
||||
#define UVC_TRACE_PROBE (1 << 0)
|
||||
#define UVC_TRACE_DESCR (1 << 1)
|
||||
#define UVC_TRACE_CONTROL (1 << 2)
|
||||
#define UVC_TRACE_FORMAT (1 << 3)
|
||||
#define UVC_TRACE_CAPTURE (1 << 4)
|
||||
#define UVC_TRACE_CALLS (1 << 5)
|
||||
#define UVC_TRACE_IOCTL (1 << 6)
|
||||
#define UVC_TRACE_FRAME (1 << 7)
|
||||
#define UVC_TRACE_SUSPEND (1 << 8)
|
||||
#define UVC_TRACE_STATUS (1 << 9)
|
||||
#define UVC_TRACE_VIDEO (1 << 10)
|
||||
#define UVC_TRACE_STATS (1 << 11)
|
||||
#define UVC_TRACE_CLOCK (1 << 12)
|
||||
|
||||
#define UVC_WARN_MINMAX 0
|
||||
#define UVC_WARN_PROBE_DEF 1
|
||||
#define UVC_WARN_XU_GET_RES 2
|
||||
|
||||
extern unsigned int uvc_clock_param;
|
||||
extern unsigned int uvc_no_drop_param;
|
||||
extern unsigned int uvc_trace_param;
|
||||
extern unsigned int uvc_timeout_param;
|
||||
|
||||
#if 0
|
||||
#define uvc_trace(flag, msg...) \
|
||||
do { \
|
||||
if (uvc_trace_param & flag) \
|
||||
printk(KERN_DEBUG "uvcvideo: " msg); \
|
||||
} while (0)
|
||||
|
||||
#define uvc_warn_once(dev, warn, msg...) \
|
||||
do { \
|
||||
if (!test_and_set_bit(warn, &dev->warnings)) \
|
||||
printk(KERN_INFO "uvcvideo: " msg); \
|
||||
} while (0)
|
||||
|
||||
#define uvc_printk(level, msg...) \
|
||||
printk(level "uvcvideo: " msg)
|
||||
#endif
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* Internal functions.
|
||||
*/
|
||||
|
||||
/* Core driver */
|
||||
extern struct uvc_driver uvc_driver;
|
||||
|
||||
extern struct uvc_entity *uvc_entity_by_id(struct uvc_device *dev, int id);
|
||||
|
||||
/* Video buffers queue management. */
|
||||
extern int uvc_queue_init(struct uvc_video_queue *queue,
|
||||
enum v4l2_buf_type type, int drop_corrupted);
|
||||
extern int uvc_alloc_buffers(struct uvc_video_queue *queue,
|
||||
struct v4l2_requestbuffers *rb);
|
||||
extern void uvc_free_buffers(struct uvc_video_queue *queue);
|
||||
extern int uvc_query_buffer(struct uvc_video_queue *queue,
|
||||
struct v4l2_buffer *v4l2_buf);
|
||||
extern int uvc_queue_buffer(struct uvc_video_queue *queue,
|
||||
struct v4l2_buffer *v4l2_buf);
|
||||
extern int uvc_dequeue_buffer(struct uvc_video_queue *queue,
|
||||
struct v4l2_buffer *v4l2_buf, int nonblocking);
|
||||
extern int uvc_queue_enable(struct uvc_video_queue *queue, int enable);
|
||||
extern void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect);
|
||||
extern struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue,
|
||||
struct uvc_buffer *buf);
|
||||
extern int uvc_queue_mmap(struct uvc_video_queue *queue);
|
||||
#if 0
|
||||
extern unsigned int uvc_queue_poll(struct uvc_video_queue *queue,
|
||||
struct file *file, poll_table *wait);
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_MMU
|
||||
extern unsigned long uvc_queue_get_unmapped_area(struct uvc_video_queue *queue,
|
||||
unsigned long pgoff);
|
||||
#endif
|
||||
|
||||
extern int uvc_queue_allocated(struct uvc_video_queue *queue);
|
||||
static inline int uvc_queue_streaming(struct uvc_video_queue *queue)
|
||||
{
|
||||
return vb2_is_streaming(&queue->queue);
|
||||
}
|
||||
|
||||
/* V4L2 interface */
|
||||
extern const struct v4l2_file_operations uvc_fops;
|
||||
|
||||
/* Media controller */
|
||||
extern int uvc_mc_register_entities(struct uvc_video_chain *chain);
|
||||
extern void uvc_mc_cleanup_entity(struct uvc_entity *entity);
|
||||
|
||||
/* Video */
|
||||
extern int uvc_video_init(struct uvc_streaming *stream);
|
||||
extern int uvc_video_suspend(struct uvc_streaming *stream);
|
||||
extern int uvc_video_resume(struct uvc_streaming *stream, int reset);
|
||||
extern int uvc_video_enable(struct uvc_streaming *stream, int enable);
|
||||
extern int uvc_probe_video(struct uvc_streaming *stream,
|
||||
struct uvc_streaming_control *probe);
|
||||
/* edit by Ian -- patch for GEO */
|
||||
extern int uvc_commit_video(struct uvc_streaming *stream,
|
||||
struct uvc_streaming_control *probe);
|
||||
|
||||
extern int uvc_query_ctrl(struct uvc_device *dev, __u8 query, __u8 unit,
|
||||
__u8 intfnum, __u8 cs, void *data, __u16 size);
|
||||
/* edit by Ian -- disable uvc clock api*/
|
||||
#if 0
|
||||
void uvc_video_clock_update(struct uvc_streaming *stream,
|
||||
struct v4l2_buffer *v4l2_buf,
|
||||
struct uvc_buffer *buf);
|
||||
#endif
|
||||
/* Status */
|
||||
//#define UVC_STATUS_EN
|
||||
#ifdef UVC_STATUS_EN
|
||||
extern int uvc_status_init(struct uvc_device *dev);
|
||||
extern void uvc_status_cleanup(struct uvc_device *dev);
|
||||
extern int uvc_status_start(struct uvc_device *dev, gfp_t flags);
|
||||
extern void uvc_status_stop(struct uvc_device *dev);
|
||||
#endif
|
||||
|
||||
/* Controls */
|
||||
extern const struct v4l2_subscribed_event_ops uvc_ctrl_sub_ev_ops;
|
||||
|
||||
extern int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain,
|
||||
struct v4l2_queryctrl *v4l2_ctrl);
|
||||
extern int uvc_query_v4l2_menu(struct uvc_video_chain *chain,
|
||||
struct v4l2_querymenu *query_menu);
|
||||
|
||||
extern int uvc_ctrl_add_mapping(struct uvc_video_chain *chain,
|
||||
const struct uvc_control_mapping *mapping);
|
||||
extern int uvc_ctrl_init_device(struct uvc_device *dev);
|
||||
extern void uvc_ctrl_cleanup_device(struct uvc_device *dev);
|
||||
extern int uvc_ctrl_resume_device(struct uvc_device *dev);
|
||||
extern int uvc_ctrl_begin(struct uvc_video_chain *chain);
|
||||
extern int __uvc_ctrl_commit(struct uvc_fh *handle, int rollback,
|
||||
const struct v4l2_ext_control *xctrls,
|
||||
unsigned int xctrls_count);
|
||||
static inline int uvc_ctrl_commit(struct uvc_fh *handle,
|
||||
const struct v4l2_ext_control *xctrls,
|
||||
unsigned int xctrls_count)
|
||||
{
|
||||
return __uvc_ctrl_commit(handle, 0, xctrls, xctrls_count);
|
||||
}
|
||||
static inline int uvc_ctrl_rollback(struct uvc_fh *handle)
|
||||
{
|
||||
return __uvc_ctrl_commit(handle, 1, NULL, 0);
|
||||
}
|
||||
|
||||
extern int uvc_ctrl_get(struct uvc_video_chain *chain,
|
||||
struct v4l2_ext_control *xctrl);
|
||||
extern int uvc_ctrl_set(struct uvc_video_chain *chain,
|
||||
struct v4l2_ext_control *xctrl);
|
||||
|
||||
//edit by Ian -- remove uvc_xu_ctrl_query declaration
|
||||
//extern int uvc_xu_ctrl_query(struct uvc_video_chain *chain, struct uvc_xu_control_query *xqry);
|
||||
|
||||
/* Utility functions */
|
||||
extern void uvc_simplify_fraction(uint32_t *numerator, uint32_t *denominator,
|
||||
unsigned int n_terms, unsigned int threshold);
|
||||
extern uint32_t uvc_fraction_to_interval(uint32_t numerator,
|
||||
uint32_t denominator);
|
||||
extern struct usb_host_endpoint *uvc_find_endpoint(
|
||||
struct usb_host_interface *alts, __u8 epaddr);
|
||||
|
||||
/* Quirks support */
|
||||
void uvc_video_decode_isight(struct urb *urb, struct uvc_streaming *stream,
|
||||
struct uvc_buffer *buf);
|
||||
|
||||
/* debugfs and statistics */
|
||||
#if 0
|
||||
int uvc_debugfs_init(void);
|
||||
void uvc_debugfs_cleanup(void);
|
||||
int uvc_debugfs_init_stream(struct uvc_streaming *stream);
|
||||
void uvc_debugfs_cleanup_stream(struct uvc_streaming *stream);
|
||||
|
||||
size_t uvc_video_stats_dump(struct uvc_streaming *stream, char *buf,
|
||||
size_t size);
|
||||
#endif
|
||||
#endif
|
726
component/common/drivers/usb_class/host/uvc/inc/video.h
Normal file
726
component/common/drivers/usb_class/host/uvc/inc/video.h
Normal file
|
@ -0,0 +1,726 @@
|
|||
/*
|
||||
* USB Video Class definitions.
|
||||
*
|
||||
* Copyright (C) 2009 Laurent Pinchart <laurent.pinchart@skynet.be>
|
||||
*
|
||||
* This file holds USB constants and structures defined by the USB Device
|
||||
* Class Definition for Video Devices. Unless otherwise stated, comments
|
||||
* below reference relevant sections of the USB Video Class 1.1 specification
|
||||
* available at
|
||||
*
|
||||
* http://www.usb.org/developers/devclass_docs/USB_Video_Class_1_1.zip
|
||||
*/
|
||||
|
||||
#ifndef __LINUX_USB_VIDEO_H
|
||||
#define __LINUX_USB_VIDEO_H
|
||||
#if 0
|
||||
#include <linux/types.h>
|
||||
#endif
|
||||
#include "uvc_os_wrap_via_osdep_api.h"
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* UVC constants
|
||||
*/
|
||||
|
||||
/* A.2. Video Interface Subclass Codes */
|
||||
#define UVC_SC_UNDEFINED 0x00
|
||||
#define UVC_SC_VIDEOCONTROL 0x01
|
||||
#define UVC_SC_VIDEOSTREAMING 0x02
|
||||
#define UVC_SC_VIDEO_INTERFACE_COLLECTION 0x03
|
||||
|
||||
/* A.3. Video Interface Protocol Codes */
|
||||
#define UVC_PC_PROTOCOL_UNDEFINED 0x00
|
||||
|
||||
/* A.5. Video Class-Specific VC Interface Descriptor Subtypes */
|
||||
#define UVC_VC_DESCRIPTOR_UNDEFINED 0x00
|
||||
#define UVC_VC_HEADER 0x01
|
||||
#define UVC_VC_INPUT_TERMINAL 0x02
|
||||
#define UVC_VC_OUTPUT_TERMINAL 0x03
|
||||
#define UVC_VC_SELECTOR_UNIT 0x04
|
||||
#define UVC_VC_PROCESSING_UNIT 0x05
|
||||
#define UVC_VC_EXTENSION_UNIT 0x06
|
||||
|
||||
/* A.6. Video Class-Specific VS Interface Descriptor Subtypes */
|
||||
#define UVC_VS_UNDEFINED 0x00
|
||||
#define UVC_VS_INPUT_HEADER 0x01
|
||||
#define UVC_VS_OUTPUT_HEADER 0x02
|
||||
#define UVC_VS_STILL_IMAGE_FRAME 0x03
|
||||
#define UVC_VS_FORMAT_UNCOMPRESSED 0x04
|
||||
#define UVC_VS_FRAME_UNCOMPRESSED 0x05
|
||||
#define UVC_VS_FORMAT_MJPEG 0x06
|
||||
#define UVC_VS_FRAME_MJPEG 0x07
|
||||
#define UVC_VS_FORMAT_MPEG2TS 0x0a
|
||||
#define UVC_VS_FORMAT_DV 0x0c
|
||||
#define UVC_VS_COLORFORMAT 0x0d
|
||||
#define UVC_VS_FORMAT_FRAME_BASED 0x10
|
||||
#define UVC_VS_FRAME_FRAME_BASED 0x11
|
||||
#define UVC_VS_FORMAT_STREAM_BASED 0x12
|
||||
|
||||
/* A.7. Video Class-Specific Endpoint Descriptor Subtypes */
|
||||
#define UVC_EP_UNDEFINED 0x00
|
||||
#define UVC_EP_GENERAL 0x01
|
||||
#define UVC_EP_ENDPOINT 0x02
|
||||
#define UVC_EP_INTERRUPT 0x03
|
||||
|
||||
/* A.8. Video Class-Specific Request Codes */
|
||||
#define UVC_RC_UNDEFINED 0x00
|
||||
#define UVC_SET_CUR 0x01
|
||||
#define UVC_GET_CUR 0x81
|
||||
#define UVC_GET_MIN 0x82
|
||||
#define UVC_GET_MAX 0x83
|
||||
#define UVC_GET_RES 0x84
|
||||
#define UVC_GET_LEN 0x85
|
||||
#define UVC_GET_INFO 0x86
|
||||
#define UVC_GET_DEF 0x87
|
||||
|
||||
/* A.9.1. VideoControl Interface Control Selectors */
|
||||
#define UVC_VC_CONTROL_UNDEFINED 0x00
|
||||
#define UVC_VC_VIDEO_POWER_MODE_CONTROL 0x01
|
||||
#define UVC_VC_REQUEST_ERROR_CODE_CONTROL 0x02
|
||||
|
||||
/* A.9.2. Terminal Control Selectors */
|
||||
#define UVC_TE_CONTROL_UNDEFINED 0x00
|
||||
|
||||
/* A.9.3. Selector Unit Control Selectors */
|
||||
#define UVC_SU_CONTROL_UNDEFINED 0x00
|
||||
#define UVC_SU_INPUT_SELECT_CONTROL 0x01
|
||||
|
||||
/* A.9.4. Camera Terminal Control Selectors */
|
||||
#define UVC_CT_CONTROL_UNDEFINED 0x00
|
||||
#define UVC_CT_SCANNING_MODE_CONTROL 0x01
|
||||
#define UVC_CT_AE_MODE_CONTROL 0x02
|
||||
#define UVC_CT_AE_PRIORITY_CONTROL 0x03
|
||||
#define UVC_CT_EXPOSURE_TIME_ABSOLUTE_CONTROL 0x04
|
||||
#define UVC_CT_EXPOSURE_TIME_RELATIVE_CONTROL 0x05
|
||||
#define UVC_CT_FOCUS_ABSOLUTE_CONTROL 0x06
|
||||
#define UVC_CT_FOCUS_RELATIVE_CONTROL 0x07
|
||||
#define UVC_CT_FOCUS_AUTO_CONTROL 0x08
|
||||
#define UVC_CT_IRIS_ABSOLUTE_CONTROL 0x09
|
||||
#define UVC_CT_IRIS_RELATIVE_CONTROL 0x0a
|
||||
#define UVC_CT_ZOOM_ABSOLUTE_CONTROL 0x0b
|
||||
#define UVC_CT_ZOOM_RELATIVE_CONTROL 0x0c
|
||||
#define UVC_CT_PANTILT_ABSOLUTE_CONTROL 0x0d
|
||||
#define UVC_CT_PANTILT_RELATIVE_CONTROL 0x0e
|
||||
#define UVC_CT_ROLL_ABSOLUTE_CONTROL 0x0f
|
||||
#define UVC_CT_ROLL_RELATIVE_CONTROL 0x10
|
||||
#define UVC_CT_PRIVACY_CONTROL 0x11
|
||||
|
||||
/* A.9.5. Processing Unit Control Selectors */
|
||||
#define UVC_PU_CONTROL_UNDEFINED 0x00
|
||||
#define UVC_PU_BACKLIGHT_COMPENSATION_CONTROL 0x01
|
||||
#define UVC_PU_BRIGHTNESS_CONTROL 0x02
|
||||
#define UVC_PU_CONTRAST_CONTROL 0x03
|
||||
#define UVC_PU_GAIN_CONTROL 0x04
|
||||
#define UVC_PU_POWER_LINE_FREQUENCY_CONTROL 0x05
|
||||
#define UVC_PU_HUE_CONTROL 0x06
|
||||
#define UVC_PU_SATURATION_CONTROL 0x07
|
||||
#define UVC_PU_SHARPNESS_CONTROL 0x08
|
||||
#define UVC_PU_GAMMA_CONTROL 0x09
|
||||
#define UVC_PU_WHITE_BALANCE_TEMPERATURE_CONTROL 0x0a
|
||||
#define UVC_PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL 0x0b
|
||||
#define UVC_PU_WHITE_BALANCE_COMPONENT_CONTROL 0x0c
|
||||
#define UVC_PU_WHITE_BALANCE_COMPONENT_AUTO_CONTROL 0x0d
|
||||
#define UVC_PU_DIGITAL_MULTIPLIER_CONTROL 0x0e
|
||||
#define UVC_PU_DIGITAL_MULTIPLIER_LIMIT_CONTROL 0x0f
|
||||
#define UVC_PU_HUE_AUTO_CONTROL 0x10
|
||||
#define UVC_PU_ANALOG_VIDEO_STANDARD_CONTROL 0x11
|
||||
#define UVC_PU_ANALOG_LOCK_STATUS_CONTROL 0x12
|
||||
|
||||
/* A.9.7. VideoStreaming Interface Control Selectors */
|
||||
#define UVC_VS_CONTROL_UNDEFINED 0x00
|
||||
#define UVC_VS_PROBE_CONTROL 0x01
|
||||
#define UVC_VS_COMMIT_CONTROL 0x02
|
||||
#define UVC_VS_STILL_PROBE_CONTROL 0x03
|
||||
#define UVC_VS_STILL_COMMIT_CONTROL 0x04
|
||||
#define UVC_VS_STILL_IMAGE_TRIGGER_CONTROL 0x05
|
||||
#define UVC_VS_STREAM_ERROR_CODE_CONTROL 0x06
|
||||
#define UVC_VS_GENERATE_KEY_FRAME_CONTROL 0x07
|
||||
#define UVC_VS_UPDATE_FRAME_SEGMENT_CONTROL 0x08
|
||||
#define UVC_VS_SYNC_DELAY_CONTROL 0x09
|
||||
|
||||
/* B.1. USB Terminal Types */
|
||||
#define UVC_TT_VENDOR_SPECIFIC 0x0100
|
||||
#define UVC_TT_STREAMING 0x0101
|
||||
|
||||
/* B.2. Input Terminal Types */
|
||||
#define UVC_ITT_VENDOR_SPECIFIC 0x0200
|
||||
#define UVC_ITT_CAMERA 0x0201
|
||||
#define UVC_ITT_MEDIA_TRANSPORT_INPUT 0x0202
|
||||
|
||||
/* B.3. Output Terminal Types */
|
||||
#define UVC_OTT_VENDOR_SPECIFIC 0x0300
|
||||
#define UVC_OTT_DISPLAY 0x0301
|
||||
#define UVC_OTT_MEDIA_TRANSPORT_OUTPUT 0x0302
|
||||
|
||||
/* B.4. External Terminal Types */
|
||||
#define UVC_EXTERNAL_VENDOR_SPECIFIC 0x0400
|
||||
#define UVC_COMPOSITE_CONNECTOR 0x0401
|
||||
#define UVC_SVIDEO_CONNECTOR 0x0402
|
||||
#define UVC_COMPONENT_CONNECTOR 0x0403
|
||||
|
||||
/* 2.4.2.2. Status Packet Type */
|
||||
#define UVC_STATUS_TYPE_CONTROL 1
|
||||
#define UVC_STATUS_TYPE_STREAMING 2
|
||||
|
||||
/* 2.4.3.3. Payload Header Information */
|
||||
#define UVC_STREAM_EOH (1 << 7)
|
||||
#define UVC_STREAM_ERR (1 << 6)
|
||||
#define UVC_STREAM_STI (1 << 5)
|
||||
#define UVC_STREAM_RES (1 << 4)
|
||||
#define UVC_STREAM_SCR (1 << 3)
|
||||
#define UVC_STREAM_PTS (1 << 2)
|
||||
#define UVC_STREAM_EOF (1 << 1)
|
||||
#define UVC_STREAM_FID (1 << 0)
|
||||
|
||||
/* 4.1.2. Control Capabilities */
|
||||
#define UVC_CONTROL_CAP_GET (1 << 0)
|
||||
#define UVC_CONTROL_CAP_SET (1 << 1)
|
||||
#define UVC_CONTROL_CAP_DISABLED (1 << 2)
|
||||
#define UVC_CONTROL_CAP_AUTOUPDATE (1 << 3)
|
||||
#define UVC_CONTROL_CAP_ASYNCHRONOUS (1 << 4)
|
||||
|
||||
/* ------------------------------------------------------------------------
|
||||
* UVC structures
|
||||
*/
|
||||
|
||||
/* All UVC descriptors have these 3 fields at the beginning */
|
||||
#ifdef RTW_PACK_STRUCT_USE_INCLUDES
|
||||
# include "pack_begin.h"
|
||||
#endif
|
||||
RTW_PACK_STRUCT_BEGIN
|
||||
struct uvc_descriptor_header {
|
||||
__u8 bLength;
|
||||
__u8 bDescriptorType;
|
||||
__u8 bDescriptorSubType;
|
||||
} //__attribute__((packed));
|
||||
RTW_PACK_STRUCT_STRUCT;
|
||||
RTW_PACK_STRUCT_END
|
||||
#ifdef RTW_PACK_STRUCT_USE_INCLUDES
|
||||
# include "pack_end.h"
|
||||
#endif
|
||||
|
||||
/* 3.7.2. Video Control Interface Header Descriptor */
|
||||
#ifdef RTW_PACK_STRUCT_USE_INCLUDES
|
||||
# include "pack_begin.h"
|
||||
#endif
|
||||
RTW_PACK_STRUCT_BEGIN
|
||||
struct uvc_header_descriptor {
|
||||
__u8 bLength;
|
||||
__u8 bDescriptorType;
|
||||
__u8 bDescriptorSubType;
|
||||
__u16 bcdUVC;
|
||||
__u16 wTotalLength;
|
||||
__u32 dwClockFrequency;
|
||||
__u8 bInCollection;
|
||||
__u8 baInterfaceNr[];
|
||||
} //__attribute__((__packed__));
|
||||
RTW_PACK_STRUCT_STRUCT;
|
||||
RTW_PACK_STRUCT_END
|
||||
#ifdef RTW_PACK_STRUCT_USE_INCLUDES
|
||||
# include "pack_end.h"
|
||||
#endif
|
||||
|
||||
#define UVC_DT_HEADER_SIZE(n) (12+(n))
|
||||
|
||||
#define UVC_HEADER_DESCRIPTOR(n) \
|
||||
uvc_header_descriptor_##n
|
||||
|
||||
#define DECLARE_UVC_HEADER_DESCRIPTOR(n) \
|
||||
struct UVC_HEADER_DESCRIPTOR(n) { \
|
||||
__u8 bLength; \
|
||||
__u8 bDescriptorType; \
|
||||
__u8 bDescriptorSubType; \
|
||||
__u16 bcdUVC; \
|
||||
__u16 wTotalLength; \
|
||||
__u32 dwClockFrequency; \
|
||||
__u8 bInCollection; \
|
||||
__u8 baInterfaceNr[n]; \
|
||||
} __attribute__ ((packed))
|
||||
|
||||
/* 3.7.2.1. Input Terminal Descriptor */
|
||||
#ifdef RTW_PACK_STRUCT_USE_INCLUDES
|
||||
# include "pack_begin.h"
|
||||
#endif
|
||||
RTW_PACK_STRUCT_BEGIN
|
||||
struct uvc_input_terminal_descriptor {
|
||||
__u8 bLength;
|
||||
__u8 bDescriptorType;
|
||||
__u8 bDescriptorSubType;
|
||||
__u8 bTerminalID;
|
||||
__u16 wTerminalType;
|
||||
__u8 bAssocTerminal;
|
||||
__u8 iTerminal;
|
||||
} //__attribute__((__packed__));
|
||||
RTW_PACK_STRUCT_STRUCT;
|
||||
RTW_PACK_STRUCT_END
|
||||
#ifdef RTW_PACK_STRUCT_USE_INCLUDES
|
||||
# include "pack_end.h"
|
||||
#endif
|
||||
|
||||
#define UVC_DT_INPUT_TERMINAL_SIZE 8
|
||||
|
||||
/* 3.7.2.2. Output Terminal Descriptor */
|
||||
#ifdef RTW_PACK_STRUCT_USE_INCLUDES
|
||||
# include "pack_begin.h"
|
||||
#endif
|
||||
RTW_PACK_STRUCT_BEGIN
|
||||
struct uvc_output_terminal_descriptor {
|
||||
__u8 bLength;
|
||||
__u8 bDescriptorType;
|
||||
__u8 bDescriptorSubType;
|
||||
__u8 bTerminalID;
|
||||
__u16 wTerminalType;
|
||||
__u8 bAssocTerminal;
|
||||
__u8 bSourceID;
|
||||
__u8 iTerminal;
|
||||
} //__attribute__((__packed__));
|
||||
RTW_PACK_STRUCT_STRUCT;
|
||||
RTW_PACK_STRUCT_END
|
||||
#ifdef RTW_PACK_STRUCT_USE_INCLUDES
|
||||
# include "pack_end.h"
|
||||
#endif
|
||||
|
||||
#define UVC_DT_OUTPUT_TERMINAL_SIZE 9
|
||||
|
||||
/* 3.7.2.3. Camera Terminal Descriptor */
|
||||
#ifdef RTW_PACK_STRUCT_USE_INCLUDES
|
||||
# include "pack_begin.h"
|
||||
#endif
|
||||
RTW_PACK_STRUCT_BEGIN
|
||||
struct uvc_camera_terminal_descriptor {
|
||||
__u8 bLength;
|
||||
__u8 bDescriptorType;
|
||||
__u8 bDescriptorSubType;
|
||||
__u8 bTerminalID;
|
||||
__u16 wTerminalType;
|
||||
__u8 bAssocTerminal;
|
||||
__u8 iTerminal;
|
||||
__u16 wObjectiveFocalLengthMin;
|
||||
__u16 wObjectiveFocalLengthMax;
|
||||
__u16 wOcularFocalLength;
|
||||
__u8 bControlSize;
|
||||
__u8 bmControls[3];
|
||||
} //__attribute__((__packed__));
|
||||
RTW_PACK_STRUCT_STRUCT;
|
||||
RTW_PACK_STRUCT_END
|
||||
#ifdef RTW_PACK_STRUCT_USE_INCLUDES
|
||||
# include "pack_end.h"
|
||||
#endif
|
||||
|
||||
#define UVC_DT_CAMERA_TERMINAL_SIZE(n) (15+(n))
|
||||
|
||||
/* 3.7.2.4. Selector Unit Descriptor */
|
||||
#ifdef RTW_PACK_STRUCT_USE_INCLUDES
|
||||
# include "pack_begin.h"
|
||||
#endif
|
||||
RTW_PACK_STRUCT_BEGIN
|
||||
struct uvc_selector_unit_descriptor {
|
||||
__u8 bLength;
|
||||
__u8 bDescriptorType;
|
||||
__u8 bDescriptorSubType;
|
||||
__u8 bUnitID;
|
||||
__u8 bNrInPins;
|
||||
// __u8 baSourceID[0];
|
||||
__u8 * baSourceID;
|
||||
__u8 iSelector;
|
||||
} //__attribute__((__packed__));
|
||||
RTW_PACK_STRUCT_STRUCT;
|
||||
RTW_PACK_STRUCT_END
|
||||
#ifdef RTW_PACK_STRUCT_USE_INCLUDES
|
||||
# include "pack_end.h"
|
||||
#endif
|
||||
|
||||
#define UVC_DT_SELECTOR_UNIT_SIZE(n) (6+(n))
|
||||
|
||||
#define UVC_SELECTOR_UNIT_DESCRIPTOR(n) \
|
||||
uvc_selector_unit_descriptor_##n
|
||||
|
||||
#define DECLARE_UVC_SELECTOR_UNIT_DESCRIPTOR(n) \
|
||||
struct UVC_SELECTOR_UNIT_DESCRIPTOR(n) { \
|
||||
__u8 bLength; \
|
||||
__u8 bDescriptorType; \
|
||||
__u8 bDescriptorSubType; \
|
||||
__u8 bUnitID; \
|
||||
__u8 bNrInPins; \
|
||||
__u8 baSourceID[n]; \
|
||||
__u8 iSelector; \
|
||||
} __attribute__ ((packed))
|
||||
|
||||
/* 3.7.2.5. Processing Unit Descriptor */
|
||||
#ifdef RTW_PACK_STRUCT_USE_INCLUDES
|
||||
# include "pack_begin.h"
|
||||
#endif
|
||||
RTW_PACK_STRUCT_BEGIN
|
||||
struct uvc_processing_unit_descriptor {
|
||||
__u8 bLength;
|
||||
__u8 bDescriptorType;
|
||||
__u8 bDescriptorSubType;
|
||||
__u8 bUnitID;
|
||||
__u8 bSourceID;
|
||||
__u16 wMaxMultiplier;
|
||||
__u8 bControlSize;
|
||||
__u8 bmControls[2];
|
||||
__u8 iProcessing;
|
||||
} //__attribute__((__packed__));
|
||||
RTW_PACK_STRUCT_STRUCT;
|
||||
RTW_PACK_STRUCT_END
|
||||
#ifdef RTW_PACK_STRUCT_USE_INCLUDES
|
||||
# include "pack_end.h"
|
||||
#endif
|
||||
|
||||
#define UVC_DT_PROCESSING_UNIT_SIZE(n) (9+(n))
|
||||
|
||||
/* 3.7.2.6. Extension Unit Descriptor */
|
||||
#ifdef RTW_PACK_STRUCT_USE_INCLUDES
|
||||
# include "pack_begin.h"
|
||||
#endif
|
||||
RTW_PACK_STRUCT_BEGIN
|
||||
struct uvc_extension_unit_descriptor {
|
||||
__u8 bLength;
|
||||
__u8 bDescriptorType;
|
||||
__u8 bDescriptorSubType;
|
||||
__u8 bUnitID;
|
||||
__u8 guidExtensionCode[16];
|
||||
__u8 bNumControls;
|
||||
__u8 bNrInPins;
|
||||
// __u8 baSourceID[0];
|
||||
__u8 * baSourceID;
|
||||
__u8 bControlSize;
|
||||
// __u8 bmControls[0];
|
||||
__u8 * bmControls;
|
||||
__u8 iExtension;
|
||||
} //__attribute__((__packed__));
|
||||
RTW_PACK_STRUCT_STRUCT;
|
||||
RTW_PACK_STRUCT_END
|
||||
#ifdef RTW_PACK_STRUCT_USE_INCLUDES
|
||||
# include "pack_end.h"
|
||||
#endif
|
||||
|
||||
#define UVC_DT_EXTENSION_UNIT_SIZE(p, n) (24+(p)+(n))
|
||||
|
||||
#define UVC_EXTENSION_UNIT_DESCRIPTOR(p, n) \
|
||||
uvc_extension_unit_descriptor_##p_##n
|
||||
|
||||
#define DECLARE_UVC_EXTENSION_UNIT_DESCRIPTOR(p, n) \
|
||||
struct UVC_EXTENSION_UNIT_DESCRIPTOR(p, n) { \
|
||||
__u8 bLength; \
|
||||
__u8 bDescriptorType; \
|
||||
__u8 bDescriptorSubType; \
|
||||
__u8 bUnitID; \
|
||||
__u8 guidExtensionCode[16]; \
|
||||
__u8 bNumControls; \
|
||||
__u8 bNrInPins; \
|
||||
__u8 baSourceID[p]; \
|
||||
__u8 bControlSize; \
|
||||
__u8 bmControls[n]; \
|
||||
__u8 iExtension; \
|
||||
} __attribute__ ((packed))
|
||||
|
||||
/* 3.8.2.2. Video Control Interrupt Endpoint Descriptor */
|
||||
#ifdef RTW_PACK_STRUCT_USE_INCLUDES
|
||||
# include "pack_begin.h"
|
||||
#endif
|
||||
RTW_PACK_STRUCT_BEGIN
|
||||
struct uvc_control_endpoint_descriptor {
|
||||
__u8 bLength;
|
||||
__u8 bDescriptorType;
|
||||
__u8 bDescriptorSubType;
|
||||
__u16 wMaxTransferSize;
|
||||
} //__attribute__((__packed__));
|
||||
RTW_PACK_STRUCT_STRUCT;
|
||||
RTW_PACK_STRUCT_END
|
||||
#ifdef RTW_PACK_STRUCT_USE_INCLUDES
|
||||
# include "pack_end.h"
|
||||
#endif
|
||||
|
||||
#define UVC_DT_CONTROL_ENDPOINT_SIZE 5
|
||||
|
||||
/* 3.9.2.1. Input Header Descriptor */
|
||||
#ifdef RTW_PACK_STRUCT_USE_INCLUDES
|
||||
# include "pack_begin.h"
|
||||
#endif
|
||||
RTW_PACK_STRUCT_BEGIN
|
||||
struct uvc_input_header_descriptor {
|
||||
__u8 bLength;
|
||||
__u8 bDescriptorType;
|
||||
__u8 bDescriptorSubType;
|
||||
__u8 bNumFormats;
|
||||
__u16 wTotalLength;
|
||||
__u8 bEndpointAddress;
|
||||
__u8 bmInfo;
|
||||
__u8 bTerminalLink;
|
||||
__u8 bStillCaptureMethod;
|
||||
__u8 bTriggerSupport;
|
||||
__u8 bTriggerUsage;
|
||||
__u8 bControlSize;
|
||||
__u8 bmaControls[];
|
||||
} //__attribute__((__packed__));
|
||||
RTW_PACK_STRUCT_STRUCT;
|
||||
RTW_PACK_STRUCT_END
|
||||
#ifdef RTW_PACK_STRUCT_USE_INCLUDES
|
||||
# include "pack_end.h"
|
||||
#endif
|
||||
|
||||
#define UVC_DT_INPUT_HEADER_SIZE(n, p) (13+(n*p))
|
||||
|
||||
#define UVC_INPUT_HEADER_DESCRIPTOR(n, p) \
|
||||
uvc_input_header_descriptor_##n_##p
|
||||
|
||||
#define DECLARE_UVC_INPUT_HEADER_DESCRIPTOR(n, p) \
|
||||
struct UVC_INPUT_HEADER_DESCRIPTOR(n, p) { \
|
||||
__u8 bLength; \
|
||||
__u8 bDescriptorType; \
|
||||
__u8 bDescriptorSubType; \
|
||||
__u8 bNumFormats; \
|
||||
__u16 wTotalLength; \
|
||||
__u8 bEndpointAddress; \
|
||||
__u8 bmInfo; \
|
||||
__u8 bTerminalLink; \
|
||||
__u8 bStillCaptureMethod; \
|
||||
__u8 bTriggerSupport; \
|
||||
__u8 bTriggerUsage; \
|
||||
__u8 bControlSize; \
|
||||
__u8 bmaControls[p][n]; \
|
||||
} __attribute__ ((packed))
|
||||
|
||||
/* 3.9.2.2. Output Header Descriptor */
|
||||
#ifdef RTW_PACK_STRUCT_USE_INCLUDES
|
||||
# include "pack_begin.h"
|
||||
#endif
|
||||
RTW_PACK_STRUCT_BEGIN
|
||||
struct uvc_output_header_descriptor {
|
||||
__u8 bLength;
|
||||
__u8 bDescriptorType;
|
||||
__u8 bDescriptorSubType;
|
||||
__u8 bNumFormats;
|
||||
__u16 wTotalLength;
|
||||
__u8 bEndpointAddress;
|
||||
__u8 bTerminalLink;
|
||||
__u8 bControlSize;
|
||||
__u8 bmaControls[];
|
||||
} //__attribute__((__packed__));
|
||||
RTW_PACK_STRUCT_STRUCT;
|
||||
RTW_PACK_STRUCT_END
|
||||
#ifdef RTW_PACK_STRUCT_USE_INCLUDES
|
||||
# include "pack_end.h"
|
||||
#endif
|
||||
|
||||
#define UVC_DT_OUTPUT_HEADER_SIZE(n, p) (9+(n*p))
|
||||
|
||||
#define UVC_OUTPUT_HEADER_DESCRIPTOR(n, p) \
|
||||
uvc_output_header_descriptor_##n_##p
|
||||
|
||||
#define DECLARE_UVC_OUTPUT_HEADER_DESCRIPTOR(n, p) \
|
||||
struct UVC_OUTPUT_HEADER_DESCRIPTOR(n, p) { \
|
||||
__u8 bLength; \
|
||||
__u8 bDescriptorType; \
|
||||
__u8 bDescriptorSubType; \
|
||||
__u8 bNumFormats; \
|
||||
__u16 wTotalLength; \
|
||||
__u8 bEndpointAddress; \
|
||||
__u8 bTerminalLink; \
|
||||
__u8 bControlSize; \
|
||||
__u8 bmaControls[p][n]; \
|
||||
} __attribute__ ((packed))
|
||||
|
||||
/* 3.9.2.6. Color matching descriptor */
|
||||
#ifdef RTW_PACK_STRUCT_USE_INCLUDES
|
||||
# include "pack_begin.h"
|
||||
#endif
|
||||
RTW_PACK_STRUCT_BEGIN
|
||||
struct uvc_color_matching_descriptor {
|
||||
__u8 bLength;
|
||||
__u8 bDescriptorType;
|
||||
__u8 bDescriptorSubType;
|
||||
__u8 bColorPrimaries;
|
||||
__u8 bTransferCharacteristics;
|
||||
__u8 bMatrixCoefficients;
|
||||
} //__attribute__((__packed__));
|
||||
RTW_PACK_STRUCT_STRUCT;
|
||||
RTW_PACK_STRUCT_END
|
||||
#ifdef RTW_PACK_STRUCT_USE_INCLUDES
|
||||
# include "pack_end.h"
|
||||
#endif
|
||||
|
||||
#define UVC_DT_COLOR_MATCHING_SIZE 6
|
||||
|
||||
/* 4.3.1.1. Video Probe and Commit Controls */
|
||||
#ifdef RTW_PACK_STRUCT_USE_INCLUDES
|
||||
# include "pack_begin.h"
|
||||
#endif
|
||||
RTW_PACK_STRUCT_BEGIN
|
||||
struct uvc_streaming_control {
|
||||
__u16 bmHint;
|
||||
__u8 bFormatIndex;
|
||||
__u8 bFrameIndex;
|
||||
__u32 dwFrameInterval;
|
||||
__u16 wKeyFrameRate;
|
||||
__u16 wPFrameRate;
|
||||
__u16 wCompQuality;
|
||||
__u16 wCompWindowSize;
|
||||
__u16 wDelay;
|
||||
__u32 dwMaxVideoFrameSize;
|
||||
__u32 dwMaxPayloadTransferSize;
|
||||
__u32 dwClockFrequency;
|
||||
__u8 bmFramingInfo;
|
||||
__u8 bPreferedVersion;
|
||||
__u8 bMinVersion;
|
||||
__u8 bMaxVersion;
|
||||
} //__attribute__((__packed__));
|
||||
RTW_PACK_STRUCT_STRUCT;
|
||||
RTW_PACK_STRUCT_END
|
||||
#ifdef RTW_PACK_STRUCT_USE_INCLUDES
|
||||
# include "pack_end.h"
|
||||
#endif
|
||||
|
||||
/* Uncompressed Payload - 3.1.1. Uncompressed Video Format Descriptor */
|
||||
#ifdef RTW_PACK_STRUCT_USE_INCLUDES
|
||||
# include "pack_begin.h"
|
||||
#endif
|
||||
RTW_PACK_STRUCT_BEGIN
|
||||
struct uvc_format_uncompressed {
|
||||
__u8 bLength;
|
||||
__u8 bDescriptorType;
|
||||
__u8 bDescriptorSubType;
|
||||
__u8 bFormatIndex;
|
||||
__u8 bNumFrameDescriptors;
|
||||
__u8 guidFormat[16];
|
||||
__u8 bBitsPerPixel;
|
||||
__u8 bDefaultFrameIndex;
|
||||
__u8 bAspectRatioX;
|
||||
__u8 bAspectRatioY;
|
||||
__u8 bmInterfaceFlags;
|
||||
__u8 bCopyProtect;
|
||||
} //__attribute__((__packed__));
|
||||
RTW_PACK_STRUCT_STRUCT;
|
||||
RTW_PACK_STRUCT_END
|
||||
#ifdef RTW_PACK_STRUCT_USE_INCLUDES
|
||||
# include "pack_end.h"
|
||||
#endif
|
||||
|
||||
#define UVC_DT_FORMAT_UNCOMPRESSED_SIZE 27
|
||||
|
||||
/* Uncompressed Payload - 3.1.2. Uncompressed Video Frame Descriptor */
|
||||
#ifdef RTW_PACK_STRUCT_USE_INCLUDES
|
||||
# include "pack_begin.h"
|
||||
#endif
|
||||
RTW_PACK_STRUCT_BEGIN
|
||||
struct uvc_frame_uncompressed {
|
||||
__u8 bLength;
|
||||
__u8 bDescriptorType;
|
||||
__u8 bDescriptorSubType;
|
||||
__u8 bFrameIndex;
|
||||
__u8 bmCapabilities;
|
||||
__u16 wWidth;
|
||||
__u16 wHeight;
|
||||
__u32 dwMinBitRate;
|
||||
__u32 dwMaxBitRate;
|
||||
__u32 dwMaxVideoFrameBufferSize;
|
||||
__u32 dwDefaultFrameInterval;
|
||||
__u8 bFrameIntervalType;
|
||||
__u32 dwFrameInterval[];
|
||||
} //__attribute__((__packed__));
|
||||
RTW_PACK_STRUCT_STRUCT;
|
||||
RTW_PACK_STRUCT_END
|
||||
#ifdef RTW_PACK_STRUCT_USE_INCLUDES
|
||||
# include "pack_end.h"
|
||||
#endif
|
||||
|
||||
#define UVC_DT_FRAME_UNCOMPRESSED_SIZE(n) (26+4*(n))
|
||||
|
||||
#define UVC_FRAME_UNCOMPRESSED(n) \
|
||||
uvc_frame_uncompressed_##n
|
||||
|
||||
#define DECLARE_UVC_FRAME_UNCOMPRESSED(n) \
|
||||
struct UVC_FRAME_UNCOMPRESSED(n) { \
|
||||
__u8 bLength; \
|
||||
__u8 bDescriptorType; \
|
||||
__u8 bDescriptorSubType; \
|
||||
__u8 bFrameIndex; \
|
||||
__u8 bmCapabilities; \
|
||||
__u16 wWidth; \
|
||||
__u16 wHeight; \
|
||||
__u32 dwMinBitRate; \
|
||||
__u32 dwMaxBitRate; \
|
||||
__u32 dwMaxVideoFrameBufferSize; \
|
||||
__u32 dwDefaultFrameInterval; \
|
||||
__u8 bFrameIntervalType; \
|
||||
__u32 dwFrameInterval[n]; \
|
||||
} __attribute__ ((packed))
|
||||
|
||||
/* MJPEG Payload - 3.1.1. MJPEG Video Format Descriptor */
|
||||
#ifdef RTW_PACK_STRUCT_USE_INCLUDES
|
||||
# include "pack_begin.h"
|
||||
#endif
|
||||
RTW_PACK_STRUCT_BEGIN
|
||||
struct uvc_format_mjpeg {
|
||||
__u8 bLength;
|
||||
__u8 bDescriptorType;
|
||||
__u8 bDescriptorSubType;
|
||||
__u8 bFormatIndex;
|
||||
__u8 bNumFrameDescriptors;
|
||||
__u8 bmFlags;
|
||||
__u8 bDefaultFrameIndex;
|
||||
__u8 bAspectRatioX;
|
||||
__u8 bAspectRatioY;
|
||||
__u8 bmInterfaceFlags;
|
||||
__u8 bCopyProtect;
|
||||
} //__attribute__((__packed__));
|
||||
RTW_PACK_STRUCT_STRUCT;
|
||||
RTW_PACK_STRUCT_END
|
||||
#ifdef RTW_PACK_STRUCT_USE_INCLUDES
|
||||
# include "pack_end.h"
|
||||
#endif
|
||||
|
||||
#define UVC_DT_FORMAT_MJPEG_SIZE 11
|
||||
#ifdef RTW_PACK_STRUCT_USE_INCLUDES
|
||||
# include "pack_begin.h"
|
||||
#endif
|
||||
RTW_PACK_STRUCT_BEGIN
|
||||
/* MJPEG Payload - 3.1.2. MJPEG Video Frame Descriptor */
|
||||
|
||||
struct uvc_frame_mjpeg {
|
||||
__u8 bLength;
|
||||
__u8 bDescriptorType;
|
||||
__u8 bDescriptorSubType;
|
||||
__u8 bFrameIndex;
|
||||
__u8 bmCapabilities;
|
||||
__u16 wWidth;
|
||||
__u16 wHeight;
|
||||
__u32 dwMinBitRate;
|
||||
__u32 dwMaxBitRate;
|
||||
__u32 dwMaxVideoFrameBufferSize;
|
||||
__u32 dwDefaultFrameInterval;
|
||||
__u8 bFrameIntervalType;
|
||||
__u32 dwFrameInterval[];
|
||||
} //__attribute__((__packed__));
|
||||
RTW_PACK_STRUCT_STRUCT;
|
||||
RTW_PACK_STRUCT_END
|
||||
#ifdef RTW_PACK_STRUCT_USE_INCLUDES
|
||||
# include "pack_end.h"
|
||||
#endif
|
||||
|
||||
#define UVC_DT_FRAME_MJPEG_SIZE(n) (26+4*(n))
|
||||
|
||||
#define UVC_FRAME_MJPEG(n) \
|
||||
uvc_frame_mjpeg_##n
|
||||
|
||||
#define DECLARE_UVC_FRAME_MJPEG(n) \
|
||||
struct UVC_FRAME_MJPEG(n) { \
|
||||
__u8 bLength; \
|
||||
__u8 bDescriptorType; \
|
||||
__u8 bDescriptorSubType; \
|
||||
__u8 bFrameIndex; \
|
||||
__u8 bmCapabilities; \
|
||||
__u16 wWidth; \
|
||||
__u16 wHeight; \
|
||||
__u32 dwMinBitRate; \
|
||||
__u32 dwMaxBitRate; \
|
||||
__u32 dwMaxVideoFrameBufferSize; \
|
||||
__u32 dwDefaultFrameInterval; \
|
||||
__u8 bFrameIntervalType; \
|
||||
__u32 dwFrameInterval[n]; \
|
||||
} __attribute__ ((packed))
|
||||
|
||||
#endif /* __LINUX_USB_VIDEO_H */
|
||||
|
476
component/common/drivers/wlan/realtek/include/autoconf.h
Normal file
476
component/common/drivers/wlan/realtek/include/autoconf.h
Normal file
|
@ -0,0 +1,476 @@
|
|||
#ifndef WLANCONFIG_H
|
||||
#define WLANCONFIG_H
|
||||
|
||||
/*
|
||||
* Include user defined options first. Anything not defined in these files
|
||||
* will be set to standard values. Override anything you dont like!
|
||||
*/
|
||||
#if defined(CONFIG_PLATFORM_8195A) || defined(CONFIG_PLATFORM_8711B) || defined(CONFIG_HARDWARE_8188F)
|
||||
#include "platform_opts.h"
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_PLATFORM_8195A) || defined(CONFIG_PLATFORM_8711B)
|
||||
#define CONFIG_PLATFORM_AMEBA_X
|
||||
#endif
|
||||
|
||||
#if !defined(CONFIG_PLATFORM_AMEBA_X)
|
||||
#define PLATFORM_FREERTOS 1
|
||||
#define CONFIG_GSPI_HCI
|
||||
#else
|
||||
#define CONFIG_LX_HCI
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_INIC_EN
|
||||
#define CONFIG_INIC_EN 0 //For iNIC project
|
||||
#if CONFIG_INIC_EN
|
||||
#define CONFIG_LWIP_LAYER 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define CONFIG_LITTLE_ENDIAN
|
||||
#define CONFIG_80211N_HT
|
||||
//#define CONFIG_RECV_REORDERING_CTRL
|
||||
#define RTW_NOTCH_FILTER 0
|
||||
#define CONFIG_EMBEDDED_FWIMG
|
||||
#define CONFIG_PHY_SETTING_WITH_ODM
|
||||
#if !defined(CONFIG_PLATFORM_AMEBA_X)
|
||||
#define CONFIG_ODM_REFRESH_RAMASK
|
||||
#define HAL_MAC_ENABLE 1
|
||||
#define HAL_BB_ENABLE 1
|
||||
#define HAL_RF_ENABLE 1
|
||||
#endif
|
||||
#if defined(CONFIG_PLATFORM_AMEBA_X)
|
||||
/* Patch when dynamic mechanism is not ready */
|
||||
//#define CONFIG_DM_PATCH
|
||||
#endif
|
||||
|
||||
//#define CONFIG_DEBUG
|
||||
//#define CONFIG_DEBUG_RTL871X
|
||||
#if defined(CONFIG_PLATFORM_AMEBA_X)
|
||||
#define CONFIG_MEM_MONITOR MEM_MONITOR_SIMPLE
|
||||
#define WLAN_INTF_DBG 0
|
||||
//#define CONFIG_DEBUG_DYNAMIC
|
||||
//#define DBG_TX 1
|
||||
//#define DBG_XMIT_BUF 1
|
||||
//#define DBG_XMIT_BUF_EXT 1
|
||||
#define DBG_TX_DROP_FRAME
|
||||
#else
|
||||
#define CONFIG_MEM_MONITOR MEM_MONITOR_LEAK
|
||||
//#define CONFIG_TRACE_SKB
|
||||
//#define WLAN_INTF_DBG
|
||||
#endif // CONFIG_PLATFORM_AMEBA_X
|
||||
|
||||
//#define CONFIG_DONT_CARE_TP
|
||||
//#define CONFIG_MEMORY_ACCESS_ALIGNED
|
||||
#define CONFIG_POWER_SAVING
|
||||
#ifdef CONFIG_POWER_SAVING
|
||||
#define CONFIG_IPS
|
||||
#define CONFIG_LPS
|
||||
//#define CONFIG_LPS_LCLK
|
||||
#define CONFIG_LPS_32K
|
||||
#define TDMA_POWER_SAVING
|
||||
#define CONFIG_WAIT_PS_ACK
|
||||
#endif
|
||||
|
||||
#define BAD_MIC_COUNTERMEASURE 1
|
||||
#define DEFRAGMENTATION 1
|
||||
|
||||
#define WIFI_LOGO_CERTIFICATION 0
|
||||
#if WIFI_LOGO_CERTIFICATION
|
||||
#define RX_AGGREGATION 1
|
||||
#define RX_AMSDU 1
|
||||
#else
|
||||
#define RX_AGGREGATION 0
|
||||
#define RX_AMSDU 0
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_PLATFORM_AMEBA_X)
|
||||
#if !defined(CONFIG_PLATFORM_8711B)
|
||||
#define CONFIG_USE_TCM_HEAP 1 /* USE TCM HEAP */
|
||||
#endif
|
||||
#define CONFIG_RECV_TASKLET_THREAD
|
||||
#define CONFIG_XMIT_TASKLET_THREAD
|
||||
#else
|
||||
#define CONFIG_XMIT_THREAD_MODE
|
||||
#endif // CONFIG_PLATFORM_AMEBA_X
|
||||
//#define CONFIG_RECV_THREAD_MODE /* Wlan IRQ Polling Mode*/
|
||||
//#define CONFIG_ISR_THREAD_MODE_POLLING /* Wlan IRQ Polling Mode*/
|
||||
|
||||
//1 Chris
|
||||
#ifndef CONFIG_SDIO_HCI
|
||||
#define CONFIG_ISR_THREAD_MODE_INTERRUPT /* Wlan IRQ Interrupt Mode*/
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_ISR_THREAD_MODE_POLLING) && defined(CONFIG_ISR_THREAD_MODE_INTERRUPT)
|
||||
#error "CONFIG_ISR_THREAD_MODE_POLLING and CONFIG_ISR_THREAD_MODE_INTERRUPT are mutually exclusive. "
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_PLATFORM_AMEBA_X)
|
||||
/* CRC DMEM optimized mode consume 1k less SRM memory consumption */
|
||||
#define CRC_IMPLEMENTATION_MODE CRC_IMPLEMENTATION_DMEM_OPTIMIZED
|
||||
#endif
|
||||
|
||||
/* AES DMEM optimized mode comsume 10k less memory compare to
|
||||
IMEM optimized mode AES_IMPLEMENTATION_IMEM_OPTIMIZED */
|
||||
#define AES_IMPLEMENTATION_MODE AES_IMPLEMENTATION_DMEM_OPTIMIZED
|
||||
|
||||
#define USE_SKB_AS_XMITBUF 1
|
||||
#if defined(CONFIG_PLATFORM_AMEBA_X)
|
||||
#define USE_XMIT_EXTBUFF 1
|
||||
#else
|
||||
#define USE_XMIT_EXTBUFF 0
|
||||
#endif
|
||||
#define USE_MUTEX_FOR_SPINLOCK 1
|
||||
|
||||
// remove function to reduce code
|
||||
#define NOT_SUPPORT_5G
|
||||
#define NOT_SUPPORT_RF_MULTIPATH
|
||||
#define NOT_SUPPORT_VHT
|
||||
#define NOT_SUPPORT_40M
|
||||
#define NOT_SUPPORT_80M
|
||||
#define NOT_SUPPORT_BBSWING
|
||||
#define NOT_SUPPORT_OLD_CHANNEL_PLAN
|
||||
#define NOT_SUPPORT_BT
|
||||
|
||||
#define CONFIG_WIFI_SPEC 0
|
||||
#define CONFIG_FAKE_EFUSE 0
|
||||
#if CONFIG_FAKE_EFUSE
|
||||
#define FAKE_CHIPID CHIPID_8711AN
|
||||
#endif
|
||||
|
||||
#define CONFIG_AUTO_RECONNECT 1
|
||||
#define ENABLE_HWPDN_PIN
|
||||
#define SUPPORT_SCAN_BUF 1
|
||||
#if !defined(CONFIG_PLATFORM_AMEBA_X)
|
||||
#define BE_I_CUT 1
|
||||
#endif
|
||||
|
||||
/* For WPA2 */
|
||||
#define CONFIG_INCLUDE_WPA_PSK
|
||||
#ifdef CONFIG_INCLUDE_WPA_PSK
|
||||
#define CONFIG_MULTIPLE_WPA_STA
|
||||
//#define CONFIG_WPA2_PREAUTH
|
||||
#define PSK_SUPPORT_TKIP 1
|
||||
#endif
|
||||
//#define AP_PSK_SUPPORT_TKIP
|
||||
|
||||
/* For promiscuous mode */
|
||||
#define CONFIG_PROMISC
|
||||
#ifdef CONFIG_PROMISC
|
||||
//#define CONFIG_PROMISC_SCAN_CONCURENT
|
||||
#endif
|
||||
|
||||
#define PROMISC_DENY_PAIRWISE 0
|
||||
|
||||
/* For Simple Link */
|
||||
#ifndef CONFIG_INCLUDE_SIMPLE_CONFIG
|
||||
//#define CONFIG_INCLUDE_SIMPLE_CONFIG 1
|
||||
#endif
|
||||
|
||||
// for probe request with custom vendor specific IE
|
||||
#define CONFIG_CUSTOM_IE
|
||||
|
||||
#if !defined(CONFIG_PLATFORM_AMEBA_X)
|
||||
/* For multicast */
|
||||
#define CONFIG_MULTICAST
|
||||
#endif
|
||||
|
||||
/* For STA+AP Concurrent MODE */
|
||||
#if !defined(CONFIG_PLATFORM_8711B)
|
||||
#define CONFIG_CONCURRENT_MODE
|
||||
#endif
|
||||
#ifdef CONFIG_CONCURRENT_MODE
|
||||
#if defined(CONFIG_PLATFORM_8195A)
|
||||
#define CONFIG_RUNTIME_PORT_SWITCH
|
||||
#endif
|
||||
#if defined(CONFIG_HARDWARE_8188F)
|
||||
#define NET_IF_NUM 2
|
||||
#else
|
||||
#define NET_IF_NUM ((CONFIG_ETHERNET) + (CONFIG_WLAN) + 1)
|
||||
#endif
|
||||
#else
|
||||
#if defined(CONFIG_HARDWARE_8188F)
|
||||
#define NET_IF_NUM 1
|
||||
#else
|
||||
#define NET_IF_NUM ((CONFIG_ETHERNET) + (CONFIG_WLAN))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/****************** For EAP auth configurations *******************/
|
||||
#define CONFIG_TLS 0
|
||||
#define CONFIG_PEAP 0
|
||||
#define CONFIG_TTLS 0
|
||||
|
||||
// DO NOT change the below config of EAP
|
||||
#ifdef PRE_CONFIG_EAP
|
||||
#define CONFIG_TLS 1
|
||||
#define CONFIG_PEAP 1
|
||||
#define CONFIG_TTLS 1
|
||||
#endif
|
||||
|
||||
// enable 1X code in lib_wlan as default (increase 380 bytes)
|
||||
#define CONFIG_EAP
|
||||
|
||||
#if CONFIG_TLS || CONFIG_PEAP || CONFIG_TTLS
|
||||
#define EAP_REMOVE_UNUSED_CODE 1
|
||||
#endif
|
||||
|
||||
#define EAP_SSL_VERIFY_SERVER
|
||||
|
||||
#if CONFIG_TLS
|
||||
#define EAP_SSL_VERIFY_CLIENT
|
||||
#endif
|
||||
|
||||
#if CONFIG_TTLS
|
||||
#define EAP_MSCHAPv2
|
||||
#define EAP_TTLS_MSCHAPv2
|
||||
//#define EAP_TTLS_EAP
|
||||
//#define EAP_TTLS_MSCHAP
|
||||
//#define EAP_TTLS_PAP
|
||||
//#define EAP_TTLS_CHAP
|
||||
#endif
|
||||
/****************** End of EAP configurations *******************/
|
||||
|
||||
/* For WPS and P2P */
|
||||
#define CONFIG_WPS
|
||||
#if 1
|
||||
#define CONFIG_WPS_AP
|
||||
#define CONFIG_P2P_NEW
|
||||
#if (!defined(SUPPORT_SCAN_BUF)||!defined(CONFIG_WPS_AP)) && defined(CONFIG_P2P_NEW)
|
||||
#error "If CONFIG_P2P_NEW, need to SUPPORT_SCAN_BUF"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define CONFIG_NEW_SIGNAL_STAT_PROCESS
|
||||
|
||||
/* For AP_MODE */
|
||||
#define CONFIG_AP_MODE
|
||||
extern unsigned char g_user_ap_sta_num;
|
||||
#define USER_AP_STA_NUM g_user_ap_sta_num
|
||||
#if defined(CONFIG_PLATFORM_AMEBA_X)
|
||||
#define AP_STA_NUM 3 //2014/10/27 modify to 3
|
||||
#define USE_DEDICATED_BCN_TX 0
|
||||
#if USE_DEDICATED_BCN_TX
|
||||
#error "WLAN driver for Ameba should not enable USE_DEDICATED_BCN_TX"
|
||||
#endif
|
||||
#else
|
||||
extern unsigned int g_ap_sta_num;
|
||||
#define AP_STA_NUM 3//g_ap_sta_num
|
||||
#endif
|
||||
#ifdef CONFIG_AP_MODE
|
||||
#define CONFIG_NATIVEAP_MLME
|
||||
#if defined(CONFIG_PLATFORM_AMEBA_X)
|
||||
#define CONFIG_INTERRUPT_BASED_TXBCN
|
||||
#endif
|
||||
#ifdef CONFIG_INTERRUPT_BASED_TXBCN
|
||||
//#define CONFIG_INTERRUPT_BASED_TXBCN_EARLY_INT
|
||||
#define CONFIG_INTERRUPT_BASED_TXBCN_BCN_OK_ERR
|
||||
#endif
|
||||
// #define CONFIG_GK_REKEY
|
||||
#if !defined(CONFIG_PLATFORM_AMEBA_X)
|
||||
#define USE_DEDICATED_BCN_TX 1
|
||||
#endif
|
||||
#if CONFIG_INIC_EN
|
||||
// #define REPORT_STA_EVENT //useless
|
||||
#endif
|
||||
#else
|
||||
#if !defined(CONFIG_PLATFORM_AMEBA_X)
|
||||
#define USE_DEDICATED_BCN_TX 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_AP_MODE) && defined(CONFIG_GK_REKEY) && !defined(CONFIG_MULTIPLE_WPA_STA)
|
||||
#error "If CONFIG_GK_REKEY when CONFIG_AP_MODE, need to CONFIG_MULTIPLE_WPA_STA"
|
||||
#endif
|
||||
|
||||
#if !defined(CONFIG_PLATFORM_AMEBA_X)
|
||||
#if !defined(CONFIG_AP_MODE) && defined(CONFIG_CONCURRENT_MODE)
|
||||
#error "If CONFIG_CONCURRENT_MODEE, need to CONFIG_AP_MODE"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* For efuse or flash config */
|
||||
#if defined(CONFIG_PLATFORM_AMEBA_X)
|
||||
#define CONFIG_RW_PHYSICAL_EFUSE 0 // Mask efuse user blocks
|
||||
#define CONFIG_HIDE_PROTECT_EFUSE 1
|
||||
#define CONFIG_ADAPTOR_INFO_CACHING_FLASH 1
|
||||
#define CHECK_FLASH_VALID_MASK 1
|
||||
#define CHECK_EFUSE_VALID_MASK 1
|
||||
/* For K-free */
|
||||
// #if !defined(CONFIG_PLATFORM_8711B)
|
||||
#define CONFIG_RF_GAIN_OFFSET
|
||||
// #endif
|
||||
#endif // CONFIG_PLATFORM_AMEBA_X
|
||||
|
||||
/* For MP_MODE */
|
||||
//#define CONFIG_MP_INCLUDED
|
||||
#ifdef CONFIG_MP_INCLUDED
|
||||
#define MP_DRIVER 1
|
||||
#define CONFIG_MP_IWPRIV_SUPPORT
|
||||
// #define HAL_EFUSE_MEMORY
|
||||
#if defined(CONFIG_PLATFORM_AMEBA_X)
|
||||
#define MP_REG_TEST
|
||||
#endif
|
||||
#else
|
||||
#define MP_DRIVER 0
|
||||
#if defined(CONFIG_PLATFORM_8195A)
|
||||
//Control wifi mcu function
|
||||
#define CONFIG_LITTLE_WIFI_MCU_FUNCTION_THREAD
|
||||
#define CONFIG_ODM_REFRESH_RAMASK
|
||||
#define CONFIG_ANTENNA_DIVERSITY
|
||||
#endif
|
||||
#endif // #ifdef CONFIG_MP_INCLUDED
|
||||
|
||||
#if defined(CONFIG_PLATFORM_AMEBA_X)
|
||||
#if defined(CONFIG_PLATFORM_8195A)
|
||||
#define CONFIG_RTL8195A
|
||||
#endif
|
||||
#if defined(CONFIG_PLATFORM_8711B)
|
||||
#ifndef CONFIG_RTL8711B
|
||||
#define CONFIG_RTL8711B
|
||||
#endif
|
||||
#endif
|
||||
#elif defined(CONFIG_HARDWARE_8188F)
|
||||
#define CONFIG_RTL8188F
|
||||
#else
|
||||
#define CONFIG_RTL8188E
|
||||
#endif
|
||||
#define RTL8192C_SUPPORT 0
|
||||
#define RTL8192CE_SUPPORT 0
|
||||
#define RTL8192CU_SUPPORT 0
|
||||
#define RTL8192D_SUPPORT 0
|
||||
#define RTL8192DE_SUPPORT 0
|
||||
#define RTL8192DU_SUPPORT 0
|
||||
#define RTL8723A_SUPPORT 0
|
||||
#define RTL8723AU_SUPPORT 0
|
||||
#define RTL8723AS_SUPPORT 0
|
||||
#define RTL8192E_SUPPORT 0
|
||||
#define RTL8812A_SUPPORT 0
|
||||
#define RTL8821A_SUPPORT 0
|
||||
#define RTL8723B_SUPPORT 0
|
||||
#define RTL8195A_SUPPORT 0
|
||||
#define RTL8188E_SUPPORT 0
|
||||
#define RTL8188F_SUPPORT 0
|
||||
#define RTL8711B_SUPPORT 0
|
||||
#if defined(CONFIG_PLATFORM_8195A)
|
||||
#undef RTL8195A_SUPPORT
|
||||
#define RTL8195A_SUPPORT 1
|
||||
#elif defined(CONFIG_PLATFORM_8711B)
|
||||
#undef RTL8711B_SUPPORT
|
||||
#define RTL8711B_SUPPORT 1
|
||||
#elif defined(CONFIG_HARDWARE_8188F)
|
||||
#undef RTL8188F_SUPPORT
|
||||
#define RTL8188F_SUPPORT 1
|
||||
#else
|
||||
#undef RTL8188E_SUPPORT
|
||||
#define RTL8188E_SUPPORT 1
|
||||
#endif
|
||||
|
||||
#define TEST_CHIP_SUPPORT 0
|
||||
|
||||
#define RTL8188E_FOR_TEST_CHIP 0
|
||||
#define RTL8188E_FPGA_TRUE_PHY_VERIFICATION 0
|
||||
|
||||
// for Debug message
|
||||
#define DBG 0
|
||||
#if defined(CONFIG_PLATFORM_AMEBA_X)
|
||||
#if(DBG == 0)
|
||||
#define ROM_E_RTW_MSG 1
|
||||
/* For DM debug*/
|
||||
// BB
|
||||
#define DBG_RX_INFO 1
|
||||
#define DBG_TX_RATE 1 // DebugComponents: bit9
|
||||
#define DBG_DM_RA 1 // DebugComponents: bit9
|
||||
#define DBG_DM_DIG 1 // DebugComponents: bit0
|
||||
#define DBG_DM_ANT_DIV 1 // DebugComponents: bit6
|
||||
#define DBG_DM_ADAPTIVITY 1 // DebugComponents: bit17
|
||||
// RF
|
||||
#define DBG_PWR_TRACKING 1 // DebugComponents: bit24
|
||||
#define DBG_RF_IQK 1 // DebugComponents: bit26
|
||||
// Common
|
||||
#define DBG_PWR_INDEX 1 // DebugComponents: bit30
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* For DM support */
|
||||
#if defined(CONFIG_RTL8188F)
|
||||
#define RATE_ADAPTIVE_SUPPORT 0
|
||||
#else
|
||||
#define RATE_ADAPTIVE_SUPPORT 1
|
||||
#endif
|
||||
// adaptivity
|
||||
#define RTW_ADAPTIVITY_EN_DISABLE 0
|
||||
#define RTW_ADAPTIVITY_EN_ENABLE 1
|
||||
#define CONFIG_RTW_ADAPTIVITY_EN RTW_ADAPTIVITY_EN_DISABLE
|
||||
#define RTW_ADAPTIVITY_MODE_NORMAL 0
|
||||
#define RTW_ADAPTIVITY_MODE_CARRIER_SENSE 1
|
||||
#define CONFIG_RTW_ADAPTIVITY_MODE RTW_ADAPTIVITY_MODE_CARRIER_SENSE
|
||||
#define CONFIG_RTW_ADAPTIVITY_DML 0
|
||||
|
||||
|
||||
#if defined(CONFIG_PLATFORM_AMEBA_X)
|
||||
#define CONFIG_POWER_TRAINING_WIL 0 // in RA
|
||||
#else
|
||||
#define POWER_BY_RATE_SUPPORT 0
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_PLATFORM_AMEBA_X)
|
||||
#define RTL8195A_FOR_TEST_CHIP 0
|
||||
|
||||
//#define CONFIG_WIFI_TEST 1
|
||||
//#define CONFIG_MAC_LOOPBACK_DRIVER 1
|
||||
//#define CONFIG_WLAN_HAL_TEST 1
|
||||
//#define SKB_PRE_ALLOCATE_TX 1
|
||||
#define SKB_PRE_ALLOCATE_RX 0
|
||||
#define TX_CHECK_DSEC_ALWAYS 1
|
||||
#define CONFIG_DBG_DISABLE_RDU_INTERRUPT
|
||||
//#define CONFIG_WLAN_HAL_RX_TASK
|
||||
#if (SKB_PRE_ALLOCATE_RX == 1)
|
||||
#define EXCHANGE_LXBUS_RX_SKB 0
|
||||
#endif
|
||||
#if defined(CONFIG_PLATFORM_8711B)
|
||||
//Enable mac loopback for test mode (Ameba)
|
||||
#define CONFIG_TWO_MAC_DRIVER // for test mode
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_MAC_LB_FOR_TEST_MODE
|
||||
#define CONFIG_SUDO_PHY_SETTING
|
||||
#define INT_HANDLE_IN_ISR 1
|
||||
#define CONFIG_LWIP_LAYER 0
|
||||
#define CONFIG_WLAN_HAL_TEST
|
||||
#define CONFIG_WLAN_HAL_RX_TASK
|
||||
#define CONFIG_MAC_LOOPBACK_DRIVER_RTL8711B 1
|
||||
#define HAL_MAC_ENABLE 1
|
||||
#define CONFIG_TWO_MAC_TEST_MODE
|
||||
#define DISABLE_BB_RF 1
|
||||
#else
|
||||
//#define CONFIG_TWO_MAC_DRIVER //for mornal driver; two mac
|
||||
#ifdef CONFIG_TWO_MAC_DRIVER
|
||||
#define CONFIG_SUDO_PHY_SETTING
|
||||
#define HAL_MAC_ENABLE 1
|
||||
#define DISABLE_BB_RF 1
|
||||
#else
|
||||
#define HAL_MAC_ENABLE 1
|
||||
#define HAL_BB_ENABLE 1
|
||||
#define HAL_RF_ENABLE 1
|
||||
#define DISABLE_BB_RF 0
|
||||
#endif
|
||||
//#define INT_HANDLE_IN_ISR 1
|
||||
#endif
|
||||
#endif // CONFIG_PLATFORM_AMEBA_X
|
||||
|
||||
#ifndef CONFIG_LWIP_LAYER
|
||||
#define CONFIG_LWIP_LAYER 1
|
||||
#endif
|
||||
#define CONFIG_MAC_ADDRESS 0
|
||||
//fast reconnection
|
||||
//#define CONFIG_FAST_RECONNECTION 1
|
||||
#if defined(CONFIG_INIC_EN)&&(CONFIG_INIC_EN==1)
|
||||
#define CONFIG_RECV_REORDERING_CTRL //enable reordering for iNIC high throughput
|
||||
#undef RX_AGGREGATION
|
||||
#define RX_AGGREGATION 1
|
||||
#undef NOT_SUPPORT_40M
|
||||
#undef CONFIG_CONCURRENT_MODE
|
||||
#endif
|
||||
#endif //WLANCONFIG_H
|
106
component/common/drivers/wlan/realtek/include/drv_conf.h
Normal file
106
component/common/drivers/wlan/realtek/include/drv_conf.h
Normal file
|
@ -0,0 +1,106 @@
|
|||
/******************************************************************************
|
||||
*
|
||||
* Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
|
||||
*
|
||||
*
|
||||
******************************************************************************/
|
||||
#ifndef __DRV_CONF_H__
|
||||
#define __DRV_CONF_H__
|
||||
|
||||
#include "autoconf.h"
|
||||
#if ((RTL8195A_SUPPORT==1) || (RTL8711B_SUPPORT==1))
|
||||
#include "platform_autoconf.h"
|
||||
#endif
|
||||
|
||||
#if defined (PLATFORM_LINUX) && defined (PLATFORM_WINDOWS)
|
||||
|
||||
#error "Shall be Linux or Windows, but not both!\n"
|
||||
|
||||
#endif
|
||||
|
||||
//Older Android kernel doesn't has CONFIG_ANDROID defined,
|
||||
//add this to force CONFIG_ANDROID defined
|
||||
#ifdef CONFIG_PLATFORM_ANDROID
|
||||
#define CONFIG_ANDROID
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ANDROID
|
||||
//Some Android build will restart the UI while non-printable ascii is passed
|
||||
//between java and c/c++ layer (JNI). We force CONFIG_VALIDATE_SSID
|
||||
//for Android here. If you are sure there is no risk on your system about this,
|
||||
//mask this macro define to support non-printable ascii ssid.
|
||||
//#define CONFIG_VALIDATE_SSID
|
||||
#ifdef CONFIG_PLATFORM_ARM_SUNxI
|
||||
#ifdef CONFIG_VALIDATE_SSID
|
||||
#undef CONFIG_VALIDATE_SSID
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//Android expect dbm as the rx signal strength unit
|
||||
#define CONFIG_SIGNAL_DISPLAY_DBM
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_HAS_EARLYSUSPEND) && defined (CONFIG_RESUME_IN_WORKQUEUE)
|
||||
#warning "You have CONFIG_HAS_EARLYSUSPEND enabled in your system, we disable CONFIG_RESUME_IN_WORKQUEUE automatically"
|
||||
#undef CONFIG_RESUME_IN_WORKQUEUE
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_ANDROID_POWER) && defined (CONFIG_RESUME_IN_WORKQUEUE)
|
||||
#warning "You have CONFIG_ANDROID_POWER enabled in your system, we disable CONFIG_RESUME_IN_WORKQUEUE automatically"
|
||||
#undef CONFIG_RESUME_IN_WORKQUEUE
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_RESUME_IN_WORKQUEUE //this can be removed, because there is no case for this...
|
||||
#if !defined( CONFIG_WAKELOCK) && !defined(CONFIG_ANDROID_POWER)
|
||||
#error "enable CONFIG_RESUME_IN_WORKQUEUE without CONFIG_WAKELOCK or CONFIG_ANDROID_POWER will suffer from the danger of wifi's unfunctionality..."
|
||||
#error "If you still want to enable CONFIG_RESUME_IN_WORKQUEUE in this case, mask this preprossor checking and GOOD LUCK..."
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//About USB VENDOR REQ
|
||||
#if defined(CONFIG_USB_VENDOR_REQ_BUFFER_PREALLOC) && !defined(CONFIG_USB_VENDOR_REQ_MUTEX)
|
||||
#warning "define CONFIG_USB_VENDOR_REQ_MUTEX for CONFIG_USB_VENDOR_REQ_BUFFER_PREALLOC automatically"
|
||||
#define CONFIG_USB_VENDOR_REQ_MUTEX
|
||||
#endif
|
||||
#if defined(CONFIG_VENDOR_REQ_RETRY) && !defined(CONFIG_USB_VENDOR_REQ_MUTEX)
|
||||
#warning "define CONFIG_USB_VENDOR_REQ_MUTEX for CONFIG_VENDOR_REQ_RETRY automatically"
|
||||
#define CONFIG_USB_VENDOR_REQ_MUTEX
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_RTW_ADAPTIVITY_EN
|
||||
#define CONFIG_RTW_ADAPTIVITY_EN 0
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_RTW_ADAPTIVITY_MODE
|
||||
#define CONFIG_RTW_ADAPTIVITY_MODE 0
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_RTW_ADAPTIVITY_DML
|
||||
#define CONFIG_RTW_ADAPTIVITY_DML 0
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_RTW_ADAPTIVITY_DC_BACKOFF
|
||||
#define CONFIG_RTW_ADAPTIVITY_DC_BACKOFF 4
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_RTW_NHM_EN
|
||||
#define CONFIG_RTW_NHM_EN 0
|
||||
#endif
|
||||
|
||||
//#include <rtl871x_byteorder.h>
|
||||
|
||||
#endif // __DRV_CONF_H__
|
||||
|
38
component/common/drivers/wlan/realtek/include/rom_aes.h
Normal file
38
component/common/drivers/wlan/realtek/include/rom_aes.h
Normal file
|
@ -0,0 +1,38 @@
|
|||
/******************************************************************************
|
||||
*
|
||||
* Copyright(c) 2007 - 2014 Realtek Corporation. All rights reserved.
|
||||
*
|
||||
* This is ROM code section.
|
||||
*
|
||||
*
|
||||
******************************************************************************/
|
||||
#ifndef ROM_AES_H
|
||||
#define ROM_AES_H
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u32 erk[64]; /* encryption round keys */
|
||||
u32 drk[64]; /* decryption round keys */
|
||||
int nr; /* number of rounds */
|
||||
}aes_context;
|
||||
|
||||
|
||||
#define AES_BLOCKSIZE8 8
|
||||
#define AES_BLK_SIZE 16 // # octets in an AES block
|
||||
typedef union _aes_block // AES cipher block
|
||||
{
|
||||
unsigned long x[AES_BLK_SIZE/4]; // access as 8-bit octets or 32-bit words
|
||||
unsigned char b[AES_BLK_SIZE];
|
||||
}aes_block;
|
||||
|
||||
|
||||
void AES_WRAP(unsigned char * plain, int plain_len,
|
||||
unsigned char * iv, int iv_len,
|
||||
unsigned char * kek, int kek_len,
|
||||
unsigned char *cipher, unsigned short *cipher_len);
|
||||
|
||||
void AES_UnWRAP(unsigned char * cipher, int cipher_len,
|
||||
unsigned char * kek, int kek_len,
|
||||
unsigned char * plain);
|
||||
|
||||
#endif
|
456
component/common/drivers/wlan/realtek/include/rtw_debug.h
Normal file
456
component/common/drivers/wlan/realtek/include/rtw_debug.h
Normal file
|
@ -0,0 +1,456 @@
|
|||
/******************************************************************************
|
||||
*
|
||||
* Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
|
||||
*
|
||||
*
|
||||
******************************************************************************/
|
||||
#ifndef __RTW_DEBUG_H__
|
||||
#define __RTW_DEBUG_H__
|
||||
|
||||
|
||||
#define _drv_always_ 1
|
||||
#define _drv_emerg_ 2
|
||||
#define _drv_alert_ 3
|
||||
#define _drv_crit_ 4
|
||||
#define _drv_err_ 5
|
||||
#define _drv_warning_ 6
|
||||
#define _drv_notice_ 7
|
||||
#define _drv_info_ 8
|
||||
#define _drv_dump_ 9
|
||||
#define _drv_debug_ 10
|
||||
|
||||
|
||||
#define _module_rtl871x_xmit_c_ BIT(0)
|
||||
#define _module_xmit_osdep_c_ BIT(1)
|
||||
#define _module_rtl871x_recv_c_ BIT(2)
|
||||
#define _module_recv_osdep_c_ BIT(3)
|
||||
#define _module_rtl871x_mlme_c_ BIT(4)
|
||||
#define _module_mlme_osdep_c_ BIT(5)
|
||||
#define _module_rtl871x_sta_mgt_c_ BIT(6)
|
||||
#define _module_rtl871x_cmd_c_ BIT(7)
|
||||
#define _module_cmd_osdep_c_ BIT(8)
|
||||
#define _module_rtl871x_io_c_ BIT(9)
|
||||
#define _module_io_osdep_c_ BIT(10)
|
||||
#define _module_os_intfs_c_ BIT(11)
|
||||
#define _module_rtl871x_security_c_ BIT(12)
|
||||
#define _module_rtl871x_eeprom_c_ BIT(13)
|
||||
#define _module_hal_init_c_ BIT(14)
|
||||
#define _module_hci_hal_init_c_ BIT(15)
|
||||
#define _module_rtl871x_ioctl_c_ BIT(16)
|
||||
#define _module_rtl871x_ioctl_set_c_ BIT(17)
|
||||
#define _module_rtl871x_ioctl_query_c_ BIT(18)
|
||||
#define _module_rtl871x_pwrctrl_c_ BIT(19)
|
||||
#define _module_hci_intfs_c_ BIT(20)
|
||||
#define _module_hci_ops_c_ BIT(21)
|
||||
#define _module_osdep_service_c_ BIT(22)
|
||||
#define _module_mp_ BIT(23)
|
||||
#define _module_hci_ops_os_c_ BIT(24)
|
||||
#define _module_rtl871x_ioctl_os_c BIT(25)
|
||||
#define _module_rtl8712_cmd_c_ BIT(26)
|
||||
#define _module_fwcmd_c_ BIT(27)
|
||||
#define _module_rtl8192c_xmit_c_ BIT(28)
|
||||
#define _module_hal_xmit_c_ BIT(28)
|
||||
#define _module_efuse_ BIT(29)
|
||||
#define _module_rtl8712_recv_c_ BIT(30)
|
||||
#define _module_rtl8712_led_c_ BIT(31)
|
||||
|
||||
#undef _MODULE_DEFINE_
|
||||
|
||||
#if defined _RTW_XMIT_C_
|
||||
#define _MODULE_DEFINE_ _module_rtl871x_xmit_c_
|
||||
#elif defined _XMIT_OSDEP_C_
|
||||
#define _MODULE_DEFINE_ _module_xmit_osdep_c_
|
||||
#elif defined _RTW_RECV_C_
|
||||
#define _MODULE_DEFINE_ _module_rtl871x_recv_c_
|
||||
#elif defined _RECV_OSDEP_C_
|
||||
#define _MODULE_DEFINE_ _module_recv_osdep_c_
|
||||
#elif defined _RTW_MLME_C_
|
||||
#define _MODULE_DEFINE_ _module_rtl871x_mlme_c_
|
||||
#elif defined _MLME_OSDEP_C_
|
||||
#define _MODULE_DEFINE_ _module_mlme_osdep_c_
|
||||
#elif defined _RTW_MLME_EXT_C_
|
||||
#define _MODULE_DEFINE_ 1
|
||||
#elif defined _RTW_STA_MGT_C_
|
||||
#define _MODULE_DEFINE_ _module_rtl871x_sta_mgt_c_
|
||||
#elif defined _RTW_CMD_C_
|
||||
#define _MODULE_DEFINE_ _module_rtl871x_cmd_c_
|
||||
#elif defined _CMD_OSDEP_C_
|
||||
#define _MODULE_DEFINE_ _module_cmd_osdep_c_
|
||||
#elif defined _RTW_IO_C_
|
||||
#define _MODULE_DEFINE_ _module_rtl871x_io_c_
|
||||
#elif defined _IO_OSDEP_C_
|
||||
#define _MODULE_DEFINE_ _module_io_osdep_c_
|
||||
#elif defined _OS_INTFS_C_
|
||||
#define _MODULE_DEFINE_ _module_os_intfs_c_
|
||||
#elif defined _RTW_SECURITY_C_
|
||||
#define _MODULE_DEFINE_ _module_rtl871x_security_c_
|
||||
#elif defined _RTW_EEPROM_C_
|
||||
#define _MODULE_DEFINE_ _module_rtl871x_eeprom_c_
|
||||
#elif defined _HAL_INTF_C_
|
||||
#define _MODULE_DEFINE_ _module_hal_init_c_
|
||||
#elif (defined _HCI_HAL_INIT_C_) || (defined _SDIO_HALINIT_C_)
|
||||
#define _MODULE_DEFINE_ _module_hci_hal_init_c_
|
||||
#elif defined _RTL871X_IOCTL_C_
|
||||
#define _MODULE_DEFINE_ _module_rtl871x_ioctl_c_
|
||||
#elif defined _RTL871X_IOCTL_SET_C_
|
||||
#define _MODULE_DEFINE_ _module_rtl871x_ioctl_set_c_
|
||||
#elif defined _RTL871X_IOCTL_QUERY_C_
|
||||
#define _MODULE_DEFINE_ _module_rtl871x_ioctl_query_c_
|
||||
#elif defined _RTL871X_PWRCTRL_C_
|
||||
#define _MODULE_DEFINE_ _module_rtl871x_pwrctrl_c_
|
||||
#elif defined _RTW_PWRCTRL_C_
|
||||
#define _MODULE_DEFINE_ 1
|
||||
#elif defined _HCI_INTF_C_
|
||||
#define _MODULE_DEFINE_ _module_hci_intfs_c_
|
||||
#elif defined _HCI_OPS_C_
|
||||
#define _MODULE_DEFINE_ _module_hci_ops_c_
|
||||
#elif defined _SDIO_OPS_C_
|
||||
#define _MODULE_DEFINE_ 1
|
||||
#elif defined _OSDEP_HCI_INTF_C_
|
||||
#define _MODULE_DEFINE_ _module_hci_intfs_c_
|
||||
#elif defined _OSDEP_SERVICE_C_
|
||||
#define _MODULE_DEFINE_ _module_osdep_service_c_
|
||||
#elif defined _HCI_OPS_OS_C_
|
||||
#define _MODULE_DEFINE_ _module_hci_ops_os_c_
|
||||
#elif defined _RTL871X_IOCTL_LINUX_C_
|
||||
#define _MODULE_DEFINE_ _module_rtl871x_ioctl_os_c
|
||||
#elif defined _RTL8712_CMD_C_
|
||||
#define _MODULE_DEFINE_ _module_rtl8712_cmd_c_
|
||||
#elif defined _RTL8192C_XMIT_C_
|
||||
#define _MODULE_DEFINE_ 1
|
||||
#elif defined _RTL8723AS_XMIT_C_
|
||||
#define _MODULE_DEFINE_ 1
|
||||
#elif defined _RTL8712_RECV_C_
|
||||
#define _MODULE_DEFINE_ _module_rtl8712_recv_c_
|
||||
#elif defined _RTL8192CU_RECV_C_
|
||||
#define _MODULE_DEFINE_ _module_rtl8712_recv_c_
|
||||
#elif defined _RTL871X_MLME_EXT_C_
|
||||
#define _MODULE_DEFINE_ _module_mlme_osdep_c_
|
||||
#elif defined _RTW_MP_C_
|
||||
#define _MODULE_DEFINE_ _module_mp_
|
||||
#elif defined _RTW_MP_IOCTL_C_
|
||||
#define _MODULE_DEFINE_ _module_mp_
|
||||
#elif defined _RTW_EFUSE_C_
|
||||
#define _MODULE_DEFINE_ _module_efuse_
|
||||
#endif
|
||||
|
||||
#ifdef PLATFORM_OS_CE
|
||||
extern void rtl871x_cedbg(const char *fmt, ...);
|
||||
#endif
|
||||
|
||||
#define RT_TRACE(_Comp, _Level, Fmt) do{}while(0)
|
||||
#define _func_enter_ do{}while(0)
|
||||
#define _func_exit_ do{}while(0)
|
||||
#define RT_PRINT_DATA(_Comp, _Level, _TitleString, _HexData, _HexDataLen) do{}while(0)
|
||||
|
||||
#ifdef PLATFORM_WINDOWS
|
||||
#define DBG_871X do {} while(0)
|
||||
#define MSG_8192C do {} while(0)
|
||||
#define DBG_8192C do {} while(0)
|
||||
#define DBG_871X_LEVEL do {} while(0)
|
||||
#else
|
||||
#define DBG_871X(x, ...) do {} while(0)
|
||||
#define MSG_8192C(x, ...) do {} while(0)
|
||||
#define DBG_8192C(x,...) do {} while(0)
|
||||
#define DBG_871X_LEVEL(x,...) do {} while(0)
|
||||
#endif
|
||||
|
||||
#undef _dbgdump
|
||||
#ifdef PLATFORM_WINDOWS
|
||||
|
||||
#ifdef PLATFORM_OS_XP
|
||||
#define _dbgdump DbgPrint
|
||||
#elif defined PLATFORM_OS_CE
|
||||
#define _dbgdump rtl871x_cedbg
|
||||
#endif
|
||||
|
||||
#elif defined PLATFORM_LINUX
|
||||
#define _dbgdump printk
|
||||
#elif defined PLATFORM_ECOS
|
||||
#define _dbgdump diag_printf
|
||||
#elif defined PLATFORM_FREERTOS
|
||||
#define _dbgdump printf("\n\r"); printf
|
||||
#elif defined PLATFORM_FREEBSD
|
||||
#define _dbgdump printf
|
||||
#endif
|
||||
|
||||
#if !defined(CONFIG_PLATFORM_8195A) && !defined(CONFIG_PLATFORM_8711B)
|
||||
#define DRIVER_PREFIX "RTL871X: "
|
||||
#endif
|
||||
|
||||
#define DEBUG_LEVEL (_drv_err_)
|
||||
#if defined (_dbgdump)
|
||||
#undef DBG_871X_LEVEL
|
||||
#if defined (__ICCARM__) || defined (__CC_ARM) || defined(CONFIG_PLATFORM_8195A) || defined(CONFIG_PLATFORM_8711B)
|
||||
#define DBG_871X_LEVEL(level, ...) \
|
||||
do {\
|
||||
_dbgdump(DRIVER_PREFIX __VA_ARGS__);\
|
||||
}while(0)
|
||||
#else
|
||||
#define DBG_871X_LEVEL(level, fmt, arg...) \
|
||||
do {\
|
||||
if (level <= DEBUG_LEVEL) {\
|
||||
if (level <= _drv_err_ && level > _drv_always_) {\
|
||||
_dbgdump(DRIVER_PREFIX"ERROR " fmt, ##arg);\
|
||||
} \
|
||||
else {\
|
||||
_dbgdump(DRIVER_PREFIX fmt, ##arg);\
|
||||
} \
|
||||
}\
|
||||
}while(0)
|
||||
#endif //#ifdef __CC_ARM
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_DEBUG
|
||||
#if defined (_dbgdump)
|
||||
#undef DBG_871X
|
||||
#define DBG_871X(...) do {\
|
||||
_dbgdump(DRIVER_PREFIX __VA_ARGS__);\
|
||||
}while(0)
|
||||
|
||||
#undef MSG_8192C
|
||||
#define MSG_8192C(...) do {\
|
||||
_dbgdump(DRIVER_PREFIX __VA_ARGS__);\
|
||||
}while(0)
|
||||
|
||||
#undef DBG_8192C
|
||||
#define DBG_8192C(...) do {\
|
||||
_dbgdump(DRIVER_PREFIX __VA_ARGS__);\
|
||||
}while(0)
|
||||
#endif
|
||||
#endif /* CONFIG_DEBUG */
|
||||
|
||||
#ifdef CONFIG_DEBUG_RTL871X
|
||||
#ifndef _RTL871X_DEBUG_C_
|
||||
extern u32 GlobalDebugLevel;
|
||||
extern u64 GlobalDebugComponents;
|
||||
#endif
|
||||
|
||||
#if defined (_dbgdump) && defined (_MODULE_DEFINE_)
|
||||
|
||||
#undef RT_TRACE
|
||||
#define RT_TRACE(_Comp, _Level, Fmt)\
|
||||
do {\
|
||||
if((_Comp & GlobalDebugComponents) && (_Level <= GlobalDebugLevel)) {\
|
||||
_dbgdump("%s [0x%08x,%d]", DRIVER_PREFIX, (unsigned int)_Comp, _Level);\
|
||||
_dbgdump Fmt;\
|
||||
}\
|
||||
}while(0)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if defined (_dbgdump)
|
||||
|
||||
#undef _func_enter_
|
||||
#define _func_enter_ \
|
||||
do { \
|
||||
if (GlobalDebugLevel >= _drv_debug_) \
|
||||
{ \
|
||||
_dbgdump("\n %s : %s enters at %d\n", DRIVER_PREFIX, __FUNCTION__, __LINE__);\
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#undef _func_exit_
|
||||
#define _func_exit_ \
|
||||
do { \
|
||||
if (GlobalDebugLevel >= _drv_debug_) \
|
||||
{ \
|
||||
_dbgdump("\n %s : %s exits at %d\n", DRIVER_PREFIX, __FUNCTION__, __LINE__); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#undef RT_PRINT_DATA
|
||||
#define RT_PRINT_DATA(_Comp, _Level, _TitleString, _HexData, _HexDataLen) \
|
||||
if(((_Comp) & GlobalDebugComponents) && (_Level <= GlobalDebugLevel)) \
|
||||
{ \
|
||||
int __i; \
|
||||
u8 *ptr = (u8 *)_HexData; \
|
||||
printf("\r\n%s", DRIVER_PREFIX); \
|
||||
printf(_TitleString "--------Len=%d\n\r", _HexDataLen); \
|
||||
for( __i=0; __i<(int)_HexDataLen; __i++ ) \
|
||||
{ \
|
||||
printf("%02X%s", ptr[__i], (((__i + 1) % 4) == 0)?" ":" "); \
|
||||
if (((__i + 1) % 16) == 0) printf("\n\r"); \
|
||||
} \
|
||||
printf("\n\r"); \
|
||||
}
|
||||
#endif
|
||||
#endif /* CONFIG_DEBUG_RTL871X */
|
||||
|
||||
|
||||
#ifdef CONFIG_PROC_DEBUG
|
||||
|
||||
int proc_get_drv_version(char *page, char **start,
|
||||
off_t offset, int count,
|
||||
int *eof, void *data);
|
||||
|
||||
int proc_get_write_reg(char *page, char **start,
|
||||
off_t offset, int count,
|
||||
int *eof, void *data);
|
||||
|
||||
int proc_set_write_reg(struct file *file, const char *buffer,
|
||||
unsigned long count, void *data);
|
||||
|
||||
int proc_get_read_reg(char *page, char **start,
|
||||
off_t offset, int count,
|
||||
int *eof, void *data);
|
||||
|
||||
int proc_set_read_reg(struct file *file, const char *buffer,
|
||||
unsigned long count, void *data);
|
||||
|
||||
|
||||
int proc_get_fwstate(char *page, char **start,
|
||||
off_t offset, int count,
|
||||
int *eof, void *data);
|
||||
|
||||
int proc_get_sec_info(char *page, char **start,
|
||||
off_t offset, int count,
|
||||
int *eof, void *data);
|
||||
|
||||
int proc_get_mlmext_state(char *page, char **start,
|
||||
off_t offset, int count,
|
||||
int *eof, void *data);
|
||||
|
||||
int proc_get_qos_option(char *page, char **start,
|
||||
off_t offset, int count,
|
||||
int *eof, void *data);
|
||||
|
||||
int proc_get_ht_option(char *page, char **start,
|
||||
off_t offset, int count,
|
||||
int *eof, void *data);
|
||||
|
||||
int proc_get_rf_info(char *page, char **start,
|
||||
off_t offset, int count,
|
||||
int *eof, void *data);
|
||||
|
||||
int proc_get_ap_info(char *page, char **start,
|
||||
off_t offset, int count,
|
||||
int *eof, void *data);
|
||||
|
||||
int proc_get_adapter_state(char *page, char **start,
|
||||
off_t offset, int count,
|
||||
int *eof, void *data);
|
||||
|
||||
int proc_get_trx_info(char *page, char **start,
|
||||
off_t offset, int count,
|
||||
int *eof, void *data);
|
||||
|
||||
int proc_get_mac_reg_dump1(char *page, char **start,
|
||||
off_t offset, int count,
|
||||
int *eof, void *data);
|
||||
|
||||
int proc_get_mac_reg_dump2(char *page, char **start,
|
||||
off_t offset, int count,
|
||||
int *eof, void *data);
|
||||
|
||||
int proc_get_mac_reg_dump3(char *page, char **start,
|
||||
off_t offset, int count,
|
||||
int *eof, void *data);
|
||||
|
||||
int proc_get_bb_reg_dump1(char *page, char **start,
|
||||
off_t offset, int count,
|
||||
int *eof, void *data);
|
||||
|
||||
int proc_get_bb_reg_dump2(char *page, char **start,
|
||||
off_t offset, int count,
|
||||
int *eof, void *data);
|
||||
|
||||
int proc_get_bb_reg_dump3(char *page, char **start,
|
||||
off_t offset, int count,
|
||||
int *eof, void *data);
|
||||
|
||||
int proc_get_rf_reg_dump1(char *page, char **start,
|
||||
off_t offset, int count,
|
||||
int *eof, void *data);
|
||||
|
||||
int proc_get_rf_reg_dump2(char *page, char **start,
|
||||
off_t offset, int count,
|
||||
int *eof, void *data);
|
||||
|
||||
int proc_get_rf_reg_dump3(char *page, char **start,
|
||||
off_t offset, int count,
|
||||
int *eof, void *data);
|
||||
|
||||
int proc_get_rf_reg_dump4(char *page, char **start,
|
||||
off_t offset, int count,
|
||||
int *eof, void *data);
|
||||
|
||||
#ifdef CONFIG_AP_MODE
|
||||
|
||||
int proc_get_all_sta_info(char *page, char **start,
|
||||
off_t offset, int count,
|
||||
int *eof, void *data);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef DBG_MEMORY_LEAK
|
||||
int proc_get_malloc_cnt(char *page, char **start,
|
||||
off_t offset, int count,
|
||||
int *eof, void *data);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_FIND_BEST_CHANNEL
|
||||
int proc_get_best_channel(char *page, char **start,
|
||||
off_t offset, int count,
|
||||
int *eof, void *data);
|
||||
#endif
|
||||
|
||||
int proc_get_rx_signal(char *page, char **start,
|
||||
off_t offset, int count,
|
||||
int *eof, void *data);
|
||||
|
||||
int proc_set_rx_signal(struct file *file, const char *buffer,
|
||||
unsigned long count, void *data);
|
||||
#ifdef CONFIG_80211N_HT
|
||||
int proc_get_cbw40_enable(char *page, char **start,
|
||||
off_t offset, int count,
|
||||
int *eof, void *data);
|
||||
|
||||
int proc_set_cbw40_enable(struct file *file, const char *buffer,
|
||||
unsigned long count, void *data);
|
||||
|
||||
int proc_get_ampdu_enable(char *page, char **start,
|
||||
off_t offset, int count,
|
||||
int *eof, void *data);
|
||||
|
||||
int proc_set_ampdu_enable(struct file *file, const char *buffer,
|
||||
unsigned long count, void *data);
|
||||
|
||||
int proc_get_rx_stbc(char *page, char **start,
|
||||
off_t offset, int count,
|
||||
int *eof, void *data);
|
||||
|
||||
int proc_set_rx_stbc(struct file *file, const char *buffer,
|
||||
unsigned long count, void *data);
|
||||
#endif //CONFIG_80211N_HT
|
||||
|
||||
int proc_get_two_path_rssi(char *page, char **start,
|
||||
off_t offset, int count,
|
||||
int *eof, void *data);
|
||||
|
||||
int proc_get_rssi_disp(char *page, char **start,
|
||||
off_t offset, int count,
|
||||
int *eof, void *data);
|
||||
|
||||
int proc_set_rssi_disp(struct file *file, const char *buffer,
|
||||
unsigned long count, void *data);
|
||||
|
||||
|
||||
#endif //CONFIG_PROC_DEBUG
|
||||
|
||||
#endif //__RTW_DEBUG_H__
|
||||
|
456
component/common/drivers/wlan/realtek/include/wifi_constants.h
Normal file
456
component/common/drivers/wlan/realtek/include/wifi_constants.h
Normal file
|
@ -0,0 +1,456 @@
|
|||
#ifndef _WIFI_CONSTANTS_H
|
||||
#define _WIFI_CONSTANTS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef WLAN0_NAME
|
||||
#define WLAN0_NAME "wlan0"
|
||||
#endif
|
||||
#ifndef WLAN1_NAME
|
||||
#define WLAN1_NAME "wlan1"
|
||||
#endif
|
||||
|
||||
#define WEP_ENABLED 0x0001
|
||||
#define TKIP_ENABLED 0x0002
|
||||
#define AES_ENABLED 0x0004
|
||||
#define WSEC_SWFLAG 0x0008
|
||||
|
||||
#define SHARED_ENABLED 0x00008000
|
||||
#define WPA_SECURITY 0x00200000
|
||||
#define WPA2_SECURITY 0x00400000
|
||||
#define WPS_ENABLED 0x10000000
|
||||
|
||||
#define RTW_MAX_PSK_LEN (64)
|
||||
#define RTW_MIN_PSK_LEN (8)
|
||||
|
||||
#define MCSSET_LEN 16
|
||||
|
||||
typedef enum
|
||||
{
|
||||
RTW_SUCCESS = 0, /**< Success */
|
||||
RTW_PENDING = 1, /**< Pending */
|
||||
RTW_TIMEOUT = 2, /**< Timeout */
|
||||
RTW_PARTIAL_RESULTS = 3, /**< Partial results */
|
||||
RTW_INVALID_KEY = 4, /**< Invalid key */
|
||||
RTW_DOES_NOT_EXIST = 5, /**< Does not exist */
|
||||
RTW_NOT_AUTHENTICATED = 6, /**< Not authenticated */
|
||||
RTW_NOT_KEYED = 7, /**< Not keyed */
|
||||
RTW_IOCTL_FAIL = 8, /**< IOCTL fail */
|
||||
RTW_BUFFER_UNAVAILABLE_TEMPORARY = 9, /**< Buffer unavailable temporarily */
|
||||
RTW_BUFFER_UNAVAILABLE_PERMANENT = 10, /**< Buffer unavailable permanently */
|
||||
RTW_WPS_PBC_OVERLAP = 11, /**< WPS PBC overlap */
|
||||
RTW_CONNECTION_LOST = 12, /**< Connection lost */
|
||||
|
||||
RTW_ERROR = -1, /**< Generic Error */
|
||||
RTW_BADARG = -2, /**< Bad Argument */
|
||||
RTW_BADOPTION = -3, /**< Bad option */
|
||||
RTW_NOTUP = -4, /**< Not up */
|
||||
RTW_NOTDOWN = -5, /**< Not down */
|
||||
RTW_NOTAP = -6, /**< Not AP */
|
||||
RTW_NOTSTA = -7, /**< Not STA */
|
||||
RTW_BADKEYIDX = -8, /**< BAD Key Index */
|
||||
RTW_RADIOOFF = -9, /**< Radio Off */
|
||||
RTW_NOTBANDLOCKED = -10, /**< Not band locked */
|
||||
RTW_NOCLK = -11, /**< No Clock */
|
||||
RTW_BADRATESET = -12, /**< BAD Rate valueset */
|
||||
RTW_BADBAND = -13, /**< BAD Band */
|
||||
RTW_BUFTOOSHORT = -14, /**< Buffer too short */
|
||||
RTW_BUFTOOLONG = -15, /**< Buffer too long */
|
||||
RTW_BUSY = -16, /**< Busy */
|
||||
RTW_NOTASSOCIATED = -17, /**< Not Associated */
|
||||
RTW_BADSSIDLEN = -18, /**< Bad SSID len */
|
||||
RTW_OUTOFRANGECHAN = -19, /**< Out of Range Channel */
|
||||
RTW_BADCHAN = -20, /**< Bad Channel */
|
||||
RTW_BADADDR = -21, /**< Bad Address */
|
||||
RTW_NORESOURCE = -22, /**< Not Enough Resources */
|
||||
RTW_UNSUPPORTED = -23, /**< Unsupported */
|
||||
RTW_BADLEN = -24, /**< Bad length */
|
||||
RTW_NOTREADY = -25, /**< Not Ready */
|
||||
RTW_EPERM = -26, /**< Not Permitted */
|
||||
RTW_NOMEM = -27, /**< No Memory */
|
||||
RTW_ASSOCIATED = -28, /**< Associated */
|
||||
RTW_RANGE = -29, /**< Not In Range */
|
||||
RTW_NOTFOUND = -30, /**< Not Found */
|
||||
RTW_WME_NOT_ENABLED = -31, /**< WME Not Enabled */
|
||||
RTW_TSPEC_NOTFOUND = -32, /**< TSPEC Not Found */
|
||||
RTW_ACM_NOTSUPPORTED = -33, /**< ACM Not Supported */
|
||||
RTW_NOT_WME_ASSOCIATION = -34, /**< Not WME Association */
|
||||
RTW_SDIO_ERROR = -35, /**< SDIO Bus Error */
|
||||
RTW_WLAN_DOWN = -36, /**< WLAN Not Accessible */
|
||||
RTW_BAD_VERSION = -37, /**< Incorrect version */
|
||||
RTW_TXFAIL = -38, /**< TX failure */
|
||||
RTW_RXFAIL = -39, /**< RX failure */
|
||||
RTW_NODEVICE = -40, /**< Device not present */
|
||||
RTW_UNFINISHED = -41, /**< To be finished */
|
||||
RTW_NONRESIDENT = -42, /**< access to nonresident overlay */
|
||||
RTW_DISABLED = -43 /**< Disabled in this build */
|
||||
} rtw_result_t;
|
||||
|
||||
typedef enum {
|
||||
RTW_SECURITY_OPEN = 0, /**< Open security */
|
||||
RTW_SECURITY_WEP_PSK = WEP_ENABLED, /**< WEP Security with open authentication */
|
||||
RTW_SECURITY_WEP_SHARED = ( WEP_ENABLED | SHARED_ENABLED ), /**< WEP Security with shared authentication */
|
||||
RTW_SECURITY_WPA_TKIP_PSK = ( WPA_SECURITY | TKIP_ENABLED ), /**< WPA Security with TKIP */
|
||||
RTW_SECURITY_WPA_AES_PSK = ( WPA_SECURITY | AES_ENABLED ), /**< WPA Security with AES */
|
||||
RTW_SECURITY_WPA2_AES_PSK = ( WPA2_SECURITY | AES_ENABLED ), /**< WPA2 Security with AES */
|
||||
RTW_SECURITY_WPA2_TKIP_PSK = ( WPA2_SECURITY | TKIP_ENABLED ), /**< WPA2 Security with TKIP */
|
||||
RTW_SECURITY_WPA2_MIXED_PSK = ( WPA2_SECURITY | AES_ENABLED | TKIP_ENABLED ), /**< WPA2 Security with AES & TKIP */
|
||||
RTW_SECURITY_WPA_WPA2_MIXED = ( WPA_SECURITY | WPA2_SECURITY ), /**< WPA/WPA2 Security */
|
||||
|
||||
RTW_SECURITY_WPS_OPEN = WPS_ENABLED, /**< WPS with open security */
|
||||
RTW_SECURITY_WPS_SECURE = (WPS_ENABLED | AES_ENABLED), /**< WPS with AES security */
|
||||
|
||||
RTW_SECURITY_UNKNOWN = -1, /**< May be returned by scan function if security is unknown. Do not pass this to the join function! */
|
||||
|
||||
RTW_SECURITY_FORCE_32_BIT = 0x7fffffff /**< Exists only to force rtw_security_t type to 32 bits */
|
||||
} rtw_security_t;
|
||||
|
||||
typedef enum {
|
||||
RTW_ENCRYPTION_UNKNOWN = 0,
|
||||
RTW_ENCRYPTION_OPEN = 1,
|
||||
RTW_ENCRYPTION_WEP40 = 2,
|
||||
RTW_ENCRYPTION_WPA_TKIP = 3,
|
||||
RTW_ENCRYPTION_WPA_AES = 4,
|
||||
RTW_ENCRYPTION_WPA2_TKIP = 5,
|
||||
RTW_ENCRYPTION_WPA2_AES = 6,
|
||||
RTW_ENCRYPTION_WPA2_MIXED = 7,
|
||||
RTW_ENCRYPTION_WEP104 = 9,
|
||||
RTW_ENCRYPTION_UNDEF = 0xFF,
|
||||
} rtw_encryption_t;
|
||||
|
||||
typedef enum {
|
||||
RTW_FALSE = 0,
|
||||
RTW_TRUE = 1
|
||||
} rtw_bool_t;
|
||||
|
||||
typedef enum {
|
||||
RTW_802_11_BAND_5GHZ = 0, /**< Denotes 5GHz radio band */
|
||||
RTW_802_11_BAND_2_4GHZ = 1 /**< Denotes 2.4GHz radio band */
|
||||
} rtw_802_11_band_t;
|
||||
|
||||
typedef enum {
|
||||
/* CHANNEL PLAN */
|
||||
RTW_COUNTRY_WORLD1, // 0x20
|
||||
RTW_COUNTRY_ETSI1, // 0x21
|
||||
RTW_COUNTRY_FCC1, // 0x22
|
||||
RTW_COUNTRY_MKK1, // 0x23
|
||||
RTW_COUNTRY_ETSI2, // 0x24
|
||||
RTW_COUNTRY_FCC2, // 0x2A
|
||||
RTW_COUNTRY_WORLD2, // 0x47
|
||||
RTW_COUNTRY_MKK2, // 0x58
|
||||
|
||||
/* SPECIAL */
|
||||
RTW_COUNTRY_WORLD, // WORLD1
|
||||
RTW_COUNTRY_EU, // ETSI1
|
||||
|
||||
/* JAPANESE */
|
||||
RTW_COUNTRY_JP, // MKK1
|
||||
|
||||
/* FCC , 19 countries*/
|
||||
RTW_COUNTRY_AS, // FCC2
|
||||
RTW_COUNTRY_BM,
|
||||
RTW_COUNTRY_CA,
|
||||
RTW_COUNTRY_DM,
|
||||
RTW_COUNTRY_DO,
|
||||
RTW_COUNTRY_FM,
|
||||
RTW_COUNTRY_GD,
|
||||
RTW_COUNTRY_GT,
|
||||
RTW_COUNTRY_GU,
|
||||
RTW_COUNTRY_HT,
|
||||
RTW_COUNTRY_MH,
|
||||
RTW_COUNTRY_MP,
|
||||
RTW_COUNTRY_NI,
|
||||
RTW_COUNTRY_PA,
|
||||
RTW_COUNTRY_PR,
|
||||
RTW_COUNTRY_PW,
|
||||
RTW_COUNTRY_TW,
|
||||
RTW_COUNTRY_US,
|
||||
RTW_COUNTRY_VI,
|
||||
|
||||
/* others, ETSI */
|
||||
RTW_COUNTRY_AD, // ETSI1
|
||||
RTW_COUNTRY_AE,
|
||||
RTW_COUNTRY_AF,
|
||||
RTW_COUNTRY_AI,
|
||||
RTW_COUNTRY_AL,
|
||||
RTW_COUNTRY_AM,
|
||||
RTW_COUNTRY_AN,
|
||||
RTW_COUNTRY_AR,
|
||||
RTW_COUNTRY_AT,
|
||||
RTW_COUNTRY_AU,
|
||||
RTW_COUNTRY_AW,
|
||||
RTW_COUNTRY_AZ,
|
||||
RTW_COUNTRY_BA,
|
||||
RTW_COUNTRY_BB,
|
||||
RTW_COUNTRY_BD,
|
||||
RTW_COUNTRY_BE,
|
||||
RTW_COUNTRY_BF,
|
||||
RTW_COUNTRY_BG,
|
||||
RTW_COUNTRY_BH,
|
||||
RTW_COUNTRY_BL,
|
||||
RTW_COUNTRY_BN,
|
||||
RTW_COUNTRY_BO,
|
||||
RTW_COUNTRY_BR,
|
||||
RTW_COUNTRY_BS,
|
||||
RTW_COUNTRY_BT,
|
||||
RTW_COUNTRY_BY,
|
||||
RTW_COUNTRY_BZ,
|
||||
RTW_COUNTRY_CF,
|
||||
RTW_COUNTRY_CH,
|
||||
RTW_COUNTRY_CI,
|
||||
RTW_COUNTRY_CL,
|
||||
RTW_COUNTRY_CN,
|
||||
RTW_COUNTRY_CO,
|
||||
RTW_COUNTRY_CR,
|
||||
RTW_COUNTRY_CX,
|
||||
RTW_COUNTRY_CY,
|
||||
RTW_COUNTRY_CZ,
|
||||
RTW_COUNTRY_DE,
|
||||
RTW_COUNTRY_DK,
|
||||
RTW_COUNTRY_DZ,
|
||||
RTW_COUNTRY_EC,
|
||||
RTW_COUNTRY_EE,
|
||||
RTW_COUNTRY_EG,
|
||||
RTW_COUNTRY_ES,
|
||||
RTW_COUNTRY_ET,
|
||||
RTW_COUNTRY_FI,
|
||||
RTW_COUNTRY_FR,
|
||||
RTW_COUNTRY_GB,
|
||||
RTW_COUNTRY_GE,
|
||||
RTW_COUNTRY_GF,
|
||||
RTW_COUNTRY_GH,
|
||||
RTW_COUNTRY_GL,
|
||||
RTW_COUNTRY_GP,
|
||||
RTW_COUNTRY_GR,
|
||||
RTW_COUNTRY_GY,
|
||||
RTW_COUNTRY_HK,
|
||||
RTW_COUNTRY_HN,
|
||||
RTW_COUNTRY_HR,
|
||||
RTW_COUNTRY_HU,
|
||||
RTW_COUNTRY_ID,
|
||||
RTW_COUNTRY_IE,
|
||||
RTW_COUNTRY_IL,
|
||||
RTW_COUNTRY_IN,
|
||||
RTW_COUNTRY_IQ,
|
||||
RTW_COUNTRY_IR,
|
||||
RTW_COUNTRY_IS,
|
||||
RTW_COUNTRY_IT,
|
||||
RTW_COUNTRY_JM,
|
||||
RTW_COUNTRY_JO,
|
||||
RTW_COUNTRY_KE,
|
||||
RTW_COUNTRY_KH,
|
||||
RTW_COUNTRY_KN,
|
||||
RTW_COUNTRY_KP,
|
||||
RTW_COUNTRY_KR,
|
||||
RTW_COUNTRY_KW,
|
||||
RTW_COUNTRY_KY,
|
||||
RTW_COUNTRY_KZ,
|
||||
RTW_COUNTRY_LA,
|
||||
RTW_COUNTRY_LB,
|
||||
RTW_COUNTRY_LC,
|
||||
RTW_COUNTRY_LI,
|
||||
RTW_COUNTRY_LK,
|
||||
RTW_COUNTRY_LR,
|
||||
RTW_COUNTRY_LS,
|
||||
RTW_COUNTRY_LT,
|
||||
RTW_COUNTRY_LU,
|
||||
RTW_COUNTRY_LV,
|
||||
RTW_COUNTRY_MA,
|
||||
RTW_COUNTRY_MC,
|
||||
RTW_COUNTRY_MD,
|
||||
RTW_COUNTRY_ME,
|
||||
RTW_COUNTRY_MF,
|
||||
RTW_COUNTRY_MK,
|
||||
RTW_COUNTRY_MN,
|
||||
RTW_COUNTRY_MO,
|
||||
RTW_COUNTRY_MQ,
|
||||
RTW_COUNTRY_MR,
|
||||
RTW_COUNTRY_MT,
|
||||
RTW_COUNTRY_MU,
|
||||
RTW_COUNTRY_MV,
|
||||
RTW_COUNTRY_MW,
|
||||
RTW_COUNTRY_MX,
|
||||
RTW_COUNTRY_MY,
|
||||
RTW_COUNTRY_NG,
|
||||
RTW_COUNTRY_NL,
|
||||
RTW_COUNTRY_NO,
|
||||
RTW_COUNTRY_NP,
|
||||
RTW_COUNTRY_NZ,
|
||||
RTW_COUNTRY_OM,
|
||||
RTW_COUNTRY_PE,
|
||||
RTW_COUNTRY_PF,
|
||||
RTW_COUNTRY_PG,
|
||||
RTW_COUNTRY_PH,
|
||||
RTW_COUNTRY_PK,
|
||||
RTW_COUNTRY_PL,
|
||||
RTW_COUNTRY_PM,
|
||||
RTW_COUNTRY_PT,
|
||||
RTW_COUNTRY_PY,
|
||||
RTW_COUNTRY_QA,
|
||||
RTW_COUNTRY_RS,
|
||||
RTW_COUNTRY_RU,
|
||||
RTW_COUNTRY_RW,
|
||||
RTW_COUNTRY_SA,
|
||||
RTW_COUNTRY_SE,
|
||||
RTW_COUNTRY_SG,
|
||||
RTW_COUNTRY_SI,
|
||||
RTW_COUNTRY_SK,
|
||||
RTW_COUNTRY_SN,
|
||||
RTW_COUNTRY_SR,
|
||||
RTW_COUNTRY_SV,
|
||||
RTW_COUNTRY_SY,
|
||||
RTW_COUNTRY_TC,
|
||||
RTW_COUNTRY_TD,
|
||||
RTW_COUNTRY_TG,
|
||||
RTW_COUNTRY_TH,
|
||||
RTW_COUNTRY_TN,
|
||||
RTW_COUNTRY_TR,
|
||||
RTW_COUNTRY_TT,
|
||||
RTW_COUNTRY_TZ,
|
||||
RTW_COUNTRY_UA,
|
||||
RTW_COUNTRY_UG,
|
||||
RTW_COUNTRY_UY,
|
||||
RTW_COUNTRY_UZ,
|
||||
RTW_COUNTRY_VC,
|
||||
RTW_COUNTRY_VE,
|
||||
RTW_COUNTRY_VN,
|
||||
RTW_COUNTRY_VU,
|
||||
RTW_COUNTRY_WF,
|
||||
RTW_COUNTRY_WS,
|
||||
RTW_COUNTRY_YE,
|
||||
RTW_COUNTRY_YT,
|
||||
RTW_COUNTRY_ZA,
|
||||
RTW_COUNTRY_ZW,
|
||||
|
||||
RTW_COUNTRY_MAX
|
||||
|
||||
}rtw_country_code_t;
|
||||
|
||||
typedef enum {
|
||||
RTW_ADAPTIVITY_DISABLE = 0,
|
||||
RTW_ADAPTIVITY_NORMAL, // CE
|
||||
RTW_ADAPTIVITY_CARRIER_SENSE // MKK
|
||||
} rtw_adaptivity_mode_t;
|
||||
|
||||
|
||||
typedef enum {
|
||||
RTW_MODE_NONE = 0,
|
||||
RTW_MODE_STA,
|
||||
RTW_MODE_AP,
|
||||
RTW_MODE_STA_AP,
|
||||
RTW_MODE_PROMISC,
|
||||
RTW_MODE_P2P
|
||||
}rtw_mode_t;
|
||||
|
||||
typedef enum {
|
||||
RTW_SCAN_FULL = 0,
|
||||
RTW_SCAN_SOCIAL,
|
||||
RTW_SCAN_ONE
|
||||
}rtw_scan_mode_t;
|
||||
|
||||
typedef enum {
|
||||
RTW_LINK_DISCONNECTED = 0,
|
||||
RTW_LINK_CONNECTED
|
||||
} rtw_link_status_t;
|
||||
|
||||
typedef enum {
|
||||
RTW_SCAN_TYPE_ACTIVE = 0x00, /**< Actively scan a network by sending 802.11 probe(s) */
|
||||
RTW_SCAN_TYPE_PASSIVE = 0x01, /**< Passively scan a network by listening for beacons from APs */
|
||||
RTW_SCAN_TYPE_PROHIBITED_CHANNELS = 0x04 /**< Passively scan on channels not enabled by the country code */
|
||||
} rtw_scan_type_t;
|
||||
|
||||
typedef enum {
|
||||
RTW_BSS_TYPE_INFRASTRUCTURE = 0, /**< Denotes infrastructure network */
|
||||
RTW_BSS_TYPE_ADHOC = 1, /**< Denotes an 802.11 ad-hoc IBSS network */
|
||||
RTW_BSS_TYPE_ANY = 2, /**< Denotes either infrastructure or ad-hoc network */
|
||||
|
||||
RTW_BSS_TYPE_UNKNOWN = -1 /**< May be returned by scan function if BSS type is unknown. Do not pass this to the Join function */
|
||||
} rtw_bss_type_t;
|
||||
|
||||
typedef enum {
|
||||
RTW_SCAN_COMMAMD = 0x01
|
||||
} rtw_scan_command_t;
|
||||
|
||||
typedef enum{
|
||||
COMMAND1 = 0x01
|
||||
}rtw_command_type;
|
||||
|
||||
typedef enum {
|
||||
RTW_WPS_TYPE_DEFAULT = 0x0000,
|
||||
RTW_WPS_TYPE_USER_SPECIFIED = 0x0001,
|
||||
RTW_WPS_TYPE_MACHINE_SPECIFIED = 0x0002,
|
||||
RTW_WPS_TYPE_REKEY = 0x0003,
|
||||
RTW_WPS_TYPE_PUSHBUTTON = 0x0004,
|
||||
RTW_WPS_TYPE_REGISTRAR_SPECIFIED = 0x0005,
|
||||
RTW_WPS_TYPE_NONE = 0x0006
|
||||
} rtw_wps_type_t;
|
||||
|
||||
typedef enum {
|
||||
RTW_NETWORK_B = 1,
|
||||
RTW_NETWORK_BG = 3,
|
||||
RTW_NETWORK_BGN = 11
|
||||
} rtw_network_mode_t;
|
||||
|
||||
typedef enum {
|
||||
RTW_STA_INTERFACE = 0, /**< STA or Client Interface */
|
||||
RTW_AP_INTERFACE = 1, /**< softAP Interface */
|
||||
} rtw_interface_t;
|
||||
|
||||
/**
|
||||
* Enumeration of packet filter rules
|
||||
*/
|
||||
typedef enum {
|
||||
RTW_POSITIVE_MATCHING = 0, /**< Specifies that a filter should match a given pattern */
|
||||
RTW_NEGATIVE_MATCHING = 1 /**< Specifies that a filter should NOT match a given pattern */
|
||||
} rtw_packet_filter_rule_e;
|
||||
|
||||
typedef enum {
|
||||
RTW_PROMISC_DISABLE = 0, /**< disable the promisc */
|
||||
RTW_PROMISC_ENABLE = 1, /**< fetch all ethernet packets */
|
||||
RTW_PROMISC_ENABLE_1 = 2, /**< fetch only B/M packets */
|
||||
RTW_PROMISC_ENABLE_2 = 3, /**< fetch all 802.11 packets*/
|
||||
RTW_PROMISC_ENABLE_3 = 4, /**< fetch only B/M 802.11 packets*/
|
||||
} rtw_rcr_level_t;
|
||||
|
||||
typedef enum{
|
||||
RTW_NO_ERROR = 0,
|
||||
RTW_NONE_NETWORK = 1,
|
||||
RTW_CONNECT_FAIL = 2,
|
||||
RTW_WRONG_PASSWORD = 3 ,
|
||||
RTW_DHCP_FAIL = 4,
|
||||
RTW_UNKNOWN,
|
||||
}rtw_connect_error_flag_t;
|
||||
|
||||
typedef enum {
|
||||
RTW_TX_PWR_PERCENTAGE_100 = 0, /* 100%, default target output power. */
|
||||
RTW_TX_PWR_PERCENTAGE_75 = 1, /* 75% */
|
||||
RTW_TX_PWR_PERCENTAGE_50 = 2, /* 50% */
|
||||
RTW_TX_PWR_PERCENTAGE_25 = 3, /* 25% */
|
||||
RTW_TX_PWR_PERCENTAGE_12_5 = 4, /* 12.5% */
|
||||
}rtw_tx_pwr_percentage_t;
|
||||
|
||||
typedef enum _WIFI_EVENT_INDICATE{
|
||||
WIFI_EVENT_CONNECT = 0,
|
||||
WIFI_EVENT_DISCONNECT = 1,
|
||||
WIFI_EVENT_FOURWAY_HANDSHAKE_DONE = 2,
|
||||
WIFI_EVENT_SCAN_RESULT_REPORT = 3,
|
||||
WIFI_EVENT_SCAN_DONE = 4,
|
||||
WIFI_EVENT_RECONNECTION_FAIL = 5,
|
||||
WIFI_EVENT_SEND_ACTION_DONE = 6,
|
||||
WIFI_EVENT_RX_MGNT = 7,
|
||||
WIFI_EVENT_STA_ASSOC = 8,
|
||||
WIFI_EVENT_STA_DISASSOC = 9,
|
||||
WIFI_EVENT_STA_WPS_START = 10,
|
||||
WIFI_EVENT_WPS_FINISH = 11,
|
||||
WIFI_EVENT_EAPOL_START = 12,
|
||||
WIFI_EVENT_EAPOL_RECVD = 13,
|
||||
WIFI_EVENT_NO_NETWORK = 14,
|
||||
WIFI_EVENT_BEACON_AFTER_DHCP = 15,
|
||||
WIFI_EVENT_MAX,
|
||||
}WIFI_EVENT_INDICATE;
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* _WIFI_CONSTANTS_H */
|
166
component/common/drivers/wlan/realtek/include/wifi_structures.h
Normal file
166
component/common/drivers/wlan/realtek/include/wifi_structures.h
Normal file
|
@ -0,0 +1,166 @@
|
|||
#ifndef _WIFI_STRUCTURES_H
|
||||
#define _WIFI_STRUCTURES_H
|
||||
|
||||
//#include <freertos/freertos_service.h>
|
||||
#include "wifi_constants.h"
|
||||
#include "dlist.h"
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if defined(__IAR_SYSTEMS_ICC__)
|
||||
#pragma pack(1)
|
||||
#endif
|
||||
typedef struct rtw_ssid {
|
||||
unsigned char len; /**< SSID length */
|
||||
unsigned char val[33]; /**< SSID name (AP name) */
|
||||
} rtw_ssid_t;
|
||||
#if defined(__IAR_SYSTEMS_ICC__)
|
||||
#pragma pack()
|
||||
#endif
|
||||
|
||||
#if defined(__IAR_SYSTEMS_ICC__)
|
||||
#pragma pack(1)
|
||||
#endif
|
||||
typedef struct rtw_mac {
|
||||
unsigned char octet[6]; /**< Unique 6-byte MAC address */
|
||||
} rtw_mac_t;
|
||||
#if defined(__IAR_SYSTEMS_ICC__)
|
||||
#pragma pack()
|
||||
#endif
|
||||
|
||||
typedef struct rtw_ap_info {
|
||||
rtw_ssid_t ssid;
|
||||
rtw_security_t security_type;
|
||||
unsigned char *password;
|
||||
int password_len;
|
||||
int channel;
|
||||
}rtw_ap_info_t;
|
||||
|
||||
typedef struct rtw_network_info {
|
||||
rtw_ssid_t ssid;
|
||||
rtw_mac_t bssid;
|
||||
rtw_security_t security_type;
|
||||
unsigned char *password;
|
||||
int password_len;
|
||||
int key_id;
|
||||
}rtw_network_info_t;
|
||||
|
||||
#if defined(__IAR_SYSTEMS_ICC__)
|
||||
#pragma pack(1)
|
||||
#endif
|
||||
typedef struct rtw_scan_result {
|
||||
rtw_ssid_t SSID; /**< Service Set Identification (i.e. Name of Access Point) */
|
||||
rtw_mac_t BSSID; /**< Basic Service Set Identification (i.e. MAC address of Access Point) */
|
||||
signed short signal_strength; /**< Receive Signal Strength Indication in dBm. <-90=Very poor, >-30=Excellent */
|
||||
rtw_bss_type_t bss_type; /**< Network type */
|
||||
rtw_security_t security; /**< Security type */
|
||||
rtw_wps_type_t wps_type; /**< WPS type */
|
||||
unsigned int channel; /**< Radio channel that the AP beacon was received on */
|
||||
rtw_802_11_band_t band; /**< Radio band */
|
||||
} rtw_scan_result_t;
|
||||
#if defined(__IAR_SYSTEMS_ICC__)
|
||||
#pragma pack()
|
||||
#endif
|
||||
|
||||
typedef struct rtw_scan_handler_result {
|
||||
rtw_scan_result_t ap_details;
|
||||
rtw_bool_t scan_complete;
|
||||
void* user_data;
|
||||
|
||||
} rtw_scan_handler_result_t;
|
||||
|
||||
#if defined(__IAR_SYSTEMS_ICC__)
|
||||
#pragma pack(1)
|
||||
#endif
|
||||
typedef struct rtw_wifi_setting {
|
||||
rtw_mode_t mode;
|
||||
unsigned char ssid[33];
|
||||
unsigned char channel;
|
||||
rtw_security_t security_type;
|
||||
unsigned char password[65];
|
||||
unsigned char key_idx;
|
||||
}rtw_wifi_setting_t;
|
||||
#if defined(__IAR_SYSTEMS_ICC__)
|
||||
#pragma pack()
|
||||
#endif
|
||||
|
||||
typedef struct rtw_wifi_config {
|
||||
unsigned int boot_mode;
|
||||
unsigned char ssid[32];
|
||||
unsigned char ssid_len;
|
||||
unsigned char security_type;
|
||||
unsigned char password[65];
|
||||
unsigned char password_len;
|
||||
unsigned char channel;
|
||||
} rtw_wifi_config_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned int count; /**< Number of MAC addresses in the list */
|
||||
rtw_mac_t mac_list[1]; /**< Variable length array of MAC addresses */
|
||||
} rtw_maclist_t;
|
||||
|
||||
typedef struct {
|
||||
unsigned int version; /* version field */
|
||||
unsigned int length; /* byte length of data in this record, */
|
||||
/* starting at version and including IEs */
|
||||
rtw_mac_t BSSID;
|
||||
unsigned short beacon_period; /* units are Kusec */
|
||||
unsigned short capability; /* Capability information */
|
||||
unsigned char SSID_len;
|
||||
unsigned char SSID[32];
|
||||
unsigned char channel;
|
||||
// struct {
|
||||
// uint32_t count; /* # rates in this set */
|
||||
// uint8_t rates[16]; /* rates in 500kbps units w/hi bit set if basic */
|
||||
// } rateset; /* supported rates */
|
||||
// rtw_chanspec_t chanspec; /* chanspec for bss */
|
||||
unsigned short atim_window; /* units are Kusec */
|
||||
unsigned char dtim_period; /* DTIM period */
|
||||
signed short RSSI; /* receive signal strength (in dBm) */
|
||||
|
||||
unsigned char n_cap; /* BSS is 802.11N Capable */
|
||||
unsigned int nbss_cap; /* 802.11N BSS Capabilities (based on HT_CAP_*) */
|
||||
unsigned char basic_mcs[MCSSET_LEN]; /* 802.11N BSS required MCS set */
|
||||
|
||||
unsigned short ie_offset; /* offset at which IEs start, from beginning */
|
||||
unsigned int ie_length; /* byte length of Information Elements */
|
||||
} rtw_bss_info_t;
|
||||
|
||||
typedef struct {
|
||||
unsigned short offset; /**< Offset in bytes to start filtering (referenced to the start of the ethernet packet) */
|
||||
unsigned short mask_size; /**< Size of the mask in bytes */
|
||||
unsigned char* mask; /**< Pattern mask bytes to be ANDed with the pattern eg. "\xff00" (must be in network byte order) */
|
||||
unsigned char* pattern; /**< Pattern bytes used to filter eg. "\x0800" (must be in network byte order) */
|
||||
} rtw_packet_filter_pattern_t;
|
||||
|
||||
typedef struct ieee80211_frame_info{
|
||||
unsigned short i_fc;
|
||||
unsigned short i_dur;
|
||||
unsigned char i_addr1[6];
|
||||
unsigned char i_addr2[6];
|
||||
unsigned char i_addr3[6];
|
||||
unsigned short i_seq;
|
||||
unsigned char bssid[6];
|
||||
unsigned char encrypt;
|
||||
signed char rssi;
|
||||
}ieee80211_frame_info_t;
|
||||
|
||||
typedef struct {
|
||||
char filter_id;
|
||||
rtw_packet_filter_pattern_t patt;
|
||||
rtw_packet_filter_rule_e rule;
|
||||
unsigned char enable;
|
||||
}rtw_packet_filter_info_t;
|
||||
|
||||
typedef struct rtw_mac_filter_list{
|
||||
struct list_head node;
|
||||
unsigned char mac_addr[6];
|
||||
}rtw_mac_filter_list_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _WIFI_STRUCTURES_H */
|
|
@ -0,0 +1,32 @@
|
|||
#include <section_config.h>
|
||||
#include <osdep_service.h>
|
||||
#include <skbuff.h>
|
||||
|
||||
#define MAX_SKB_BUF_SIZE 1650 // should >= the size in wlan driver
|
||||
#define MAX_SKB_BUF_NUM 8
|
||||
#define MAX_LOCAL_SKB_NUM (MAX_SKB_BUF_NUM + 2)
|
||||
|
||||
/* DO NOT modify skb_buf and skb_data structure */
|
||||
struct skb_buf {
|
||||
struct list_head list;
|
||||
struct sk_buff skb;
|
||||
};
|
||||
|
||||
struct skb_data {
|
||||
struct list_head list;
|
||||
unsigned char buf[MAX_SKB_BUF_SIZE];
|
||||
atomic_t ref;
|
||||
};
|
||||
|
||||
unsigned int nr_xmitframe = MAX_SKB_BUF_NUM;
|
||||
unsigned int nr_xmitbuff = MAX_SKB_BUF_NUM;
|
||||
int max_local_skb_num = MAX_LOCAL_SKB_NUM;
|
||||
int max_skb_buf_num = MAX_SKB_BUF_NUM;
|
||||
|
||||
/* DO NOT access skb_pool and skb_data_pool out of wlan driver */
|
||||
struct skb_buf skb_pool[MAX_LOCAL_SKB_NUM];
|
||||
|
||||
// SRAM_BD_DATA_SECTION default in SRAM. Can modify image2.icf to link to the end of SDRAM
|
||||
SRAM_BD_DATA_SECTION
|
||||
struct skb_data skb_data_pool[MAX_SKB_BUF_NUM];
|
||||
|
|
@ -0,0 +1,440 @@
|
|||
#ifndef __WRAPPER_H__
|
||||
#define __WRAPPER_H__
|
||||
/**************************************************************************
|
||||
* Wrapper provide a linux-like interface
|
||||
*
|
||||
* Copyright (c) 2013 Realtek Semiconductor Corp.
|
||||
************************************************************************/
|
||||
|
||||
//----- ------------------------------------------------------------------
|
||||
// Include Files
|
||||
//----- ------------------------------------------------------------------
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "wireless.h"
|
||||
#include <skbuff.h>
|
||||
#include "freertos_service.h"
|
||||
|
||||
#ifndef __LIST_H
|
||||
#warning "DLIST_NOT_DEFINE!!!!!!"
|
||||
//----- ------------------------------------------------------------------
|
||||
// Linled List
|
||||
//----- ------------------------------------------------------------------
|
||||
/*
|
||||
* Simple doubly linked list implementation.
|
||||
*
|
||||
* Some of the internal functions ("__xxx") are useful when
|
||||
* manipulating whole lists rather than single entries, as
|
||||
* sometimes we already know the next/prev entries and we can
|
||||
* generate better code by using them directly rather than
|
||||
* using the generic single-entry routines.
|
||||
*/
|
||||
// struct list_head {
|
||||
// struct list_head *next, *prev;
|
||||
// };
|
||||
|
||||
#define LIST_HEAD_INIT(name) { &(name), &(name) }
|
||||
|
||||
#define INIT_LIST_HEAD(ptr) do { \
|
||||
(ptr)->next = (ptr); (ptr)->prev = (ptr); \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* Insert a new entry between two known consecutive entries.
|
||||
*
|
||||
* This is only for internal list manipulation where we know
|
||||
* the prev/next entries already!
|
||||
*/
|
||||
static __inline void __list_add(struct list_head * new,
|
||||
struct list_head * prev,
|
||||
struct list_head * next)
|
||||
{
|
||||
next->prev = new;
|
||||
new->next = next;
|
||||
new->prev = prev;
|
||||
prev->next = new;
|
||||
}
|
||||
|
||||
/*
|
||||
* Delete a list entry by making the prev/next entries
|
||||
* point to each other.
|
||||
*
|
||||
* This is only for internal list manipulation where we know
|
||||
* the prev/next entries already!
|
||||
*/
|
||||
static __inline void __list_del(struct list_head * prev,
|
||||
struct list_head * next)
|
||||
{
|
||||
next->prev = prev;
|
||||
prev->next = next;
|
||||
}
|
||||
|
||||
/**
|
||||
* list_del - deletes entry from list.
|
||||
* @entry: the element to delete from the list.
|
||||
* Note: list_empty on entry does not return true after this, the entry is in an undefined state.
|
||||
*/
|
||||
static __inline void list_del(struct list_head *entry)
|
||||
{
|
||||
__list_del(entry->prev, entry->next);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_del_init - deletes entry from list and reinitialize it.
|
||||
* @entry: the element to delete from the list.
|
||||
*/
|
||||
static __inline void list_del_init(struct list_head *entry)
|
||||
{
|
||||
__list_del(entry->prev, entry->next);
|
||||
INIT_LIST_HEAD(entry);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_empty - tests whether a list is empty
|
||||
* @head: the list to test.
|
||||
*/
|
||||
static __inline int list_empty(struct list_head *head)
|
||||
{
|
||||
return head->next == head;
|
||||
}
|
||||
|
||||
/**
|
||||
* list_splice - join two lists
|
||||
* @list: the new list to add.
|
||||
* @head: the place to add it in the first list.
|
||||
*/
|
||||
static __inline void list_splice(struct list_head *list, struct list_head *head)
|
||||
{
|
||||
struct list_head *first = list->next;
|
||||
|
||||
if (first != list) {
|
||||
struct list_head *last = list->prev;
|
||||
struct list_head *at = head->next;
|
||||
|
||||
first->prev = head;
|
||||
head->next = first;
|
||||
|
||||
last->next = at;
|
||||
at->prev = last;
|
||||
}
|
||||
}
|
||||
|
||||
void list_add(struct list_head *new, struct list_head *head);
|
||||
void list_add_tail(struct list_head *new, struct list_head *head);
|
||||
#endif
|
||||
|
||||
extern void save_and_cli(void);
|
||||
extern void restore_flags(void);
|
||||
//----- ------------------------------------------------------------------
|
||||
// SKB Operation
|
||||
//----- ------------------------------------------------------------------
|
||||
|
||||
#define SMP_CACHE_BYTES 4
|
||||
#define SKB_DATA_ALIGN(X) (((X) + (SMP_CACHE_BYTES - 1)) & ~(SMP_CACHE_BYTES - 1))
|
||||
|
||||
// Consideration for SKB size
|
||||
// Tx: [INTF_CMD][TX_DESC][WLAN_HDR][QoS][IV][SNAP][Data][MIC][ICV][INTF_STATUS]
|
||||
// Since SKB is used to accept ethernet packet from upper layer, SKB length of WLAN_MAX_ETHFRM_LEN
|
||||
// (= 1514) is enough. But since SKB is also used to get spi receive packet, overall buffer space
|
||||
// should be taken into consideration.
|
||||
// RX: [INTF_CMD][RX_DESC][Drv_Info][WLAN_HDR][QoS][IV][SNAP][Data][MIC][ICV][CRC][INTF_STATUS]
|
||||
//
|
||||
// 32: Driver_Info that carry phy related information for each packets. Required only for receive case.
|
||||
// WLAN_MAX_ETHFRM_LEN : May not be required because WLAN_HEADER +SNAP can totally
|
||||
// cover ethernet header. Keep in only for safety.
|
||||
//
|
||||
// **Notes** SDIO requires 512 blocks r/w, so 512*4 = 2048 is required.
|
||||
// 2003/12/26. The value is reduced from 2048 to 1658 for GSPI
|
||||
// 2014/02/05. The value is 1650 for 8195A LX_BUS
|
||||
#define SKB_RESERVED_FOR_SAFETY 0
|
||||
#define SKB_WLAN_TX_EXTRA_LEN (TXDESC_SIZE + WLAN_HDR_A4_QOS_LEN + WLAN_MAX_IV_LEN + WLAN_SNAP_HEADER - WLAN_ETHHDR_LEN)
|
||||
#define RX_DRIVER_INFO 32
|
||||
|
||||
#if (defined CONFIG_GSPI_HCI || defined CONFIG_SDIO_HCI)
|
||||
#define HAL_INTERFACE_OVERHEAD_SKB_DATA 12 //HAL_INTERFACE_CMD (4) + HAL_INTERFACE_STATUS (8)
|
||||
#elif defined(CONFIG_LX_HCI)
|
||||
#define HAL_INTERFACE_OVERHEAD_SKB_DATA 0
|
||||
#endif
|
||||
|
||||
#if defined CONFIG_GSPI_HCI || defined CONFIG_SDIO_HCI || defined(CONFIG_LX_HCI)
|
||||
#if defined(CONFIG_RTL8195A) || defined(CONFIG_RTL8711B)
|
||||
#if defined(CONFIG_MP_INCLUDED)
|
||||
#ifdef CONFIG_DONT_CARE_TP
|
||||
#define MAX_RX_PKT_LIMIT ((WLAN_MAX_PROTOCOL_OVERHEAD + WLAN_MAX_RX_ETHFRM_LEN + 511) / 512) // 4, for lxbus
|
||||
#else
|
||||
#define MAX_RX_PKT_LIMIT ((WLAN_MAX_PROTOCOL_OVERHEAD + WLAN_MAX_ETHFRM_LEN + 511) / 512) // 4, for lxbus
|
||||
#endif
|
||||
#define MAX_RX_PKT_SIZE MAX_RX_PKT_LIMIT*512 // MAX_SKB_BUF_SIZE = 0+32+40+512*4+0 = 2120
|
||||
#else
|
||||
#ifdef CONFIG_DONT_CARE_TP
|
||||
#define MAX_RX_PKT_SIZE WLAN_MAX_PROTOCOL_OVERHEAD + WLAN_MAX_RX_ETHFRM_LEN
|
||||
#else
|
||||
#define MAX_RX_PKT_SIZE WLAN_MAX_PROTOCOL_OVERHEAD + WLAN_MAX_ETHFRM_LEN // MAX_RX_PKT_SIZE = 64+1514 = 1578
|
||||
#endif
|
||||
#define MAX_RX_PKT_LIMIT ((MAX_RX_PKT_SIZE + 511) / 512) // ((1578 + 512) / 512) = 4
|
||||
#endif
|
||||
#else
|
||||
#ifdef CONFIG_DONT_CARE_TP
|
||||
#define MAX_RX_PKT_SIZE WLAN_MAX_PROTOCOL_OVERHEAD + WLAN_MAX_RX_ETHFRM_LEN
|
||||
#else
|
||||
#define MAX_RX_PKT_SIZE WLAN_MAX_PROTOCOL_OVERHEAD + WLAN_MAX_ETHFRM_LEN
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_DONT_CARE_TP
|
||||
#define MAX_TX_SKB_BUF_SIZE (HAL_INTERFACE_OVERHEAD_SKB_DATA+RX_DRIVER_INFO+\
|
||||
((TXDESC_SIZE>RXDESC_SIZE)? TXDESC_SIZE:RXDESC_SIZE) +\
|
||||
WLAN_MAX_PROTOCOL_OVERHEAD + WLAN_MAX_TX_ETHFRM_LEN +\
|
||||
SKB_RESERVED_FOR_SAFETY)
|
||||
#define MAX_RX_SKB_BUF_SIZE (HAL_INTERFACE_OVERHEAD_SKB_DATA+RX_DRIVER_INFO+\
|
||||
((TXDESC_SIZE>RXDESC_SIZE)? TXDESC_SIZE:RXDESC_SIZE) +\
|
||||
MAX_RX_PKT_SIZE +\
|
||||
SKB_RESERVED_FOR_SAFETY)
|
||||
#else
|
||||
#define MAX_SKB_BUF_SIZE (HAL_INTERFACE_OVERHEAD_SKB_DATA+RX_DRIVER_INFO+\
|
||||
((TXDESC_SIZE>RXDESC_SIZE)? TXDESC_SIZE:RXDESC_SIZE) +\
|
||||
MAX_RX_PKT_SIZE +\
|
||||
SKB_RESERVED_FOR_SAFETY) // 0+32+40+1578+0 = 1650
|
||||
#endif
|
||||
#else
|
||||
#define MAX_SKB_BUF_SIZE 2048
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
struct sk_buff_head {
|
||||
struct list_head *next, *prev;
|
||||
u32 qlen;
|
||||
};
|
||||
|
||||
struct sk_buff {
|
||||
/* These two members must be first. */
|
||||
struct sk_buff *next; /* Next buffer in list */
|
||||
struct sk_buff *prev; /* Previous buffer in list */
|
||||
|
||||
struct sk_buff_head *list; /* List we are on */
|
||||
unsigned char *head; /* Head of buffer */
|
||||
unsigned char *data; /* Data head pointer */
|
||||
unsigned char *tail; /* Tail pointer */
|
||||
unsigned char *end; /* End pointer */
|
||||
struct net_device *dev; /* Device we arrived on/are leaving by */
|
||||
unsigned int len; /* Length of actual data */
|
||||
};
|
||||
|
||||
/**
|
||||
* skb_put - add data to a buffer
|
||||
* @skb: buffer to use
|
||||
* @len: amount of data to add
|
||||
*
|
||||
* This function extends the used data area of the buffer. If this would
|
||||
* exceed the total buffer size the kernel will panic. A pointer to the
|
||||
* first byte of the extra data is returned.
|
||||
*/
|
||||
|
||||
static __inline__ unsigned char *skb_put(struct sk_buff *skb, unsigned int len)
|
||||
{
|
||||
unsigned char *tmp=skb->tail;
|
||||
skb->tail+=len;
|
||||
skb->len+=len;
|
||||
if(skb->tail>skb->end) {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
static __inline__ unsigned char *__skb_pull(struct sk_buff *skb, unsigned int len)
|
||||
{
|
||||
skb->len-=len;
|
||||
skb->data = (unsigned char *)(((unsigned int)skb->data) + len);
|
||||
|
||||
return skb->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* skb_reserve - adjust headroom
|
||||
* @skb: buffer to alter
|
||||
* @len: bytes to move
|
||||
*
|
||||
* Increase the headroom of an empty &sk_buff by reducing the tail
|
||||
* room. This is only allowed for an empty buffer.
|
||||
*/
|
||||
|
||||
static __inline__ void skb_reserve(struct sk_buff *skb, unsigned int len)
|
||||
{
|
||||
skb->data+=len;
|
||||
skb->tail+=len;
|
||||
}
|
||||
|
||||
static __inline__ void skb_queue_head_init(struct sk_buff_head *list)
|
||||
{
|
||||
list->prev = (struct list_head *)list;
|
||||
list->next = (struct list_head *)list;
|
||||
list->qlen = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* __skb_queue_tail - queue a buffer at the list tail
|
||||
* @list: list to use
|
||||
* @newsk: buffer to queue
|
||||
*
|
||||
* Queue a buffer at the end of a list. This function takes no locks
|
||||
* and you must therefore hold required locks before calling it.
|
||||
*
|
||||
* A buffer cannot be placed on two lists at the same time.
|
||||
*/
|
||||
|
||||
static __inline__ void __skb_queue_tail(struct sk_buff_head *list, struct sk_buff *newsk)
|
||||
{
|
||||
struct sk_buff *prev, *next;
|
||||
|
||||
newsk->list = list;
|
||||
list->qlen++;
|
||||
next = (struct sk_buff *)list;
|
||||
prev = next->prev;
|
||||
newsk->next = next;
|
||||
newsk->prev = prev;
|
||||
next->prev = newsk;
|
||||
prev->next = newsk;
|
||||
}
|
||||
|
||||
/**
|
||||
* skb_queue_tail - queue a buffer at the list tail
|
||||
* @list: list to use
|
||||
* @newsk: buffer to queue
|
||||
*
|
||||
* Queue a buffer at the tail of the list. This function takes the
|
||||
* list lock and can be used safely with other locking &sk_buff functions
|
||||
* safely.
|
||||
*
|
||||
* A buffer cannot be placed on two lists at the same time.
|
||||
*/
|
||||
|
||||
static __inline__ void skb_queue_tail(struct sk_buff_head *list, struct sk_buff *newsk)
|
||||
{
|
||||
save_and_cli();
|
||||
__skb_queue_tail(list, newsk);
|
||||
restore_flags();
|
||||
}
|
||||
|
||||
static __inline__ void skb_assign_buf(struct sk_buff *skb, unsigned char *buf, unsigned int len)
|
||||
{
|
||||
skb->head = buf;
|
||||
skb->data = buf;
|
||||
skb->tail = buf;
|
||||
skb->end = buf + len;
|
||||
}
|
||||
|
||||
static __inline__ unsigned char *skb_tail_pointer(const struct sk_buff *skb)
|
||||
{
|
||||
return skb->tail;
|
||||
}
|
||||
|
||||
static __inline__ void skb_reset_tail_pointer(struct sk_buff *skb)
|
||||
{
|
||||
skb->tail = skb->data;
|
||||
}
|
||||
|
||||
static __inline__ void skb_set_tail_pointer(struct sk_buff *skb, const int offset)
|
||||
{
|
||||
skb->tail = skb->data + offset;
|
||||
}
|
||||
|
||||
static __inline__ unsigned char *skb_end_pointer(const struct sk_buff *skb)
|
||||
{
|
||||
return skb->end;
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
* External functions
|
||||
*/
|
||||
struct net_device;
|
||||
extern void kfree_skb_chk_key(struct sk_buff *skb, struct net_device *root_dev);
|
||||
#ifdef CONFIG_TRACE_SKB
|
||||
extern void show_skb(void);
|
||||
extern int _set_skb_list_flag(struct sk_buff *skb, unsigned int queueflag);
|
||||
extern void dump_skb_list(void);
|
||||
#define set_skb_list_flag(skb, queueflag) \
|
||||
(\
|
||||
_set_skb_list_flag((skb), queueflag), \
|
||||
(skb) ? (skb)->funcname[(skb)->list_idx] = __FUNCTION__:NULL \
|
||||
)
|
||||
extern int _clear_skb_list_flag(struct sk_buff *skb, unsigned int queueflag);
|
||||
#define clear_skb_list_flag(skb, queueflag) \
|
||||
(\
|
||||
_clear_skb_list_flag((skb), queueflag), \
|
||||
(skb) ? (skb)->funcname[(skb)->list_idx] = __FUNCTION__ : NULL \
|
||||
)
|
||||
#define dev_kfree_skb_any(trx, holder, skb) \
|
||||
do{\
|
||||
clear_skb_list_flag(skb, SKBLIST_##trx##holder##_MASK);\
|
||||
set_skb_list_flag(skb, SKBLIST_POOL);\
|
||||
kfree_skb_chk_key(skb, skb->dev);\
|
||||
}while (0)
|
||||
#else
|
||||
#define dev_kfree_skb_any(skb) kfree_skb_chk_key(skb, skb->dev)
|
||||
#endif
|
||||
extern struct sk_buff *dev_alloc_skb(unsigned int length, unsigned int reserve_len);
|
||||
extern struct sk_buff *skb_clone(struct sk_buff *skb, int gfp_mask);
|
||||
extern struct sk_buff *skb_copy(const struct sk_buff *skb, int gfp_mask, unsigned int reserve_len);
|
||||
extern unsigned char *skb_pull(struct sk_buff *skb, unsigned int len);
|
||||
|
||||
//----- ------------------------------------------------------------------
|
||||
// Device structure
|
||||
//----- ------------------------------------------------------------------
|
||||
struct net_device_stats {
|
||||
unsigned long rx_packets; /* total packets received */
|
||||
unsigned long tx_packets; /* total packets transmitted */
|
||||
unsigned long rx_dropped; /* no space in linux buffers */
|
||||
unsigned long tx_dropped; /* no space available in linux */
|
||||
unsigned long rx_bytes; /* total bytes received */
|
||||
unsigned long tx_bytes; /* total bytes transmitted */
|
||||
unsigned long rx_overflow; /* rx fifo overflow count */
|
||||
};
|
||||
|
||||
struct net_device {
|
||||
char name[16];
|
||||
void *priv; /* pointer to private data */
|
||||
unsigned char dev_addr[6]; /* set during bootup */
|
||||
int (*init)(void);
|
||||
int (*open)(struct net_device *dev);
|
||||
int (*stop)(struct net_device *dev);
|
||||
int (*hard_start_xmit)(struct sk_buff *skb, struct net_device *dev);
|
||||
int (*do_ioctl)(struct net_device *dev, struct iwreq *ifr, int cmd);
|
||||
struct net_device_stats* (*get_stats)(struct net_device *dev);
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
struct net_device *dev; /* Binding wlan driver netdev */
|
||||
void *skb; /* pending Rx packet */
|
||||
unsigned int tx_busy;
|
||||
unsigned int rx_busy;
|
||||
unsigned char enable;
|
||||
unsigned char mac[6];
|
||||
} Rltk_wlan_t;
|
||||
|
||||
#define netdev_priv(dev) dev->priv
|
||||
|
||||
extern struct net_device *alloc_etherdev(int sizeof_priv);
|
||||
void free_netdev(struct net_device *dev);
|
||||
int dev_alloc_name(struct net_device *net_dev, const char *ifname);
|
||||
|
||||
|
||||
//----- ------------------------------------------------------------------
|
||||
// Timer Operation
|
||||
//----- ------------------------------------------------------------------
|
||||
void init_timer(struct timer_list *timer);
|
||||
void mod_timer(struct timer_list *timer, u32 delay_time_ms);
|
||||
void cancel_timer_ex(struct timer_list * timer);
|
||||
void del_timer_sync(struct timer_list * timer);
|
||||
void init_timer_wrapper(void);
|
||||
void deinit_timer_wrapper(void);
|
||||
|
||||
void rtw_init_timer(_timer *ptimer, void *adapter, TIMER_FUN pfunc,void* cntx, const char *name);
|
||||
void rtw_set_timer(_timer *ptimer,u32 delay_time);
|
||||
u8 rtw_cancel_timer(_timer *ptimer);
|
||||
void rtw_del_timer(_timer *ptimer);
|
||||
|
||||
#endif //__WRAPPER_H__
|
||||
|
||||
|
||||
|
222
component/common/drivers/wlan/realtek/src/osdep/lwip_intf.c
Normal file
222
component/common/drivers/wlan/realtek/src/osdep/lwip_intf.c
Normal file
|
@ -0,0 +1,222 @@
|
|||
/******************************************************************************
|
||||
*
|
||||
* Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
|
||||
*
|
||||
*
|
||||
******************************************************************************/
|
||||
//#define _LWIP_INTF_C_
|
||||
|
||||
#include <autoconf.h>
|
||||
#include <lwip_intf.h>
|
||||
#include <lwip/netif.h>
|
||||
#include <lwip_netconf.h>
|
||||
#include <ethernetif.h>
|
||||
#include <osdep_service.h>
|
||||
#include <wifi/wifi_util.h>
|
||||
//----- ------------------------------------------------------------------
|
||||
// External Reference
|
||||
//----- ------------------------------------------------------------------
|
||||
#if (CONFIG_LWIP_LAYER == 1)
|
||||
extern struct netif xnetif[]; //LWIP netif
|
||||
#endif
|
||||
|
||||
/**
|
||||
* rltk_wlan_set_netif_info - set netif hw address and register dev pointer to netif device
|
||||
* @idx_wlan: netif index
|
||||
* 0 for STA only or SoftAP only or STA in STA+SoftAP concurrent mode,
|
||||
* 1 for SoftAP in STA+SoftAP concurrent mode
|
||||
* @dev: register netdev pointer to LWIP. Reserved.
|
||||
* @dev_addr: set netif hw address
|
||||
*
|
||||
* Return Value: None
|
||||
*/
|
||||
void rltk_wlan_set_netif_info(int idx_wlan, void * dev, unsigned char * dev_addr)
|
||||
{
|
||||
#if (CONFIG_LWIP_LAYER == 1)
|
||||
rtw_memcpy(xnetif[idx_wlan].hwaddr, dev_addr, 6);
|
||||
xnetif[idx_wlan].state = dev;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* rltk_wlan_send - send IP packets to WLAN. Called by low_level_output().
|
||||
* @idx: netif index
|
||||
* @sg_list: data buffer list
|
||||
* @sg_len: size of each data buffer
|
||||
* @total_len: total data len
|
||||
*
|
||||
* Return Value: None
|
||||
*/
|
||||
int rltk_wlan_send(int idx, struct eth_drv_sg *sg_list, int sg_len, int total_len)
|
||||
{
|
||||
struct eth_drv_sg *last_sg;
|
||||
struct sk_buff *skb = NULL;
|
||||
int ret = 0;
|
||||
|
||||
if(idx == -1){
|
||||
DBG_ERR("netif is DOWN");
|
||||
return -1;
|
||||
}
|
||||
DBG_TRACE("%s is called", __FUNCTION__);
|
||||
|
||||
save_and_cli();
|
||||
if(rltk_wlan_check_isup(idx))
|
||||
rltk_wlan_tx_inc(idx);
|
||||
else {
|
||||
DBG_ERR("netif is DOWN");
|
||||
restore_flags();
|
||||
return -1;
|
||||
}
|
||||
restore_flags();
|
||||
|
||||
skb = rltk_wlan_alloc_skb(total_len);
|
||||
if (skb == NULL) {
|
||||
//DBG_ERR("rltk_wlan_alloc_skb() for data len=%d failed!", total_len);
|
||||
ret = -1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
for (last_sg = &sg_list[sg_len]; sg_list < last_sg; ++sg_list) {
|
||||
rtw_memcpy(skb->tail, (void *)(sg_list->buf), sg_list->len);
|
||||
skb_put(skb, sg_list->len);
|
||||
}
|
||||
|
||||
rltk_wlan_send_skb(idx, skb);
|
||||
|
||||
exit:
|
||||
save_and_cli();
|
||||
rltk_wlan_tx_dec(idx);
|
||||
restore_flags();
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* rltk_wlan_recv - indicate packets to LWIP. Called by ethernetif_recv().
|
||||
* @idx: netif index
|
||||
* @sg_list: data buffer list
|
||||
* @sg_len: size of each data buffer
|
||||
*
|
||||
* Return Value: None
|
||||
*/
|
||||
void rltk_wlan_recv(int idx, struct eth_drv_sg *sg_list, int sg_len)
|
||||
{
|
||||
struct eth_drv_sg *last_sg;
|
||||
struct sk_buff *skb;
|
||||
|
||||
DBG_TRACE("%s is called", __FUNCTION__);
|
||||
if(idx == -1){
|
||||
DBG_ERR("skb is NULL");
|
||||
return;
|
||||
}
|
||||
skb = rltk_wlan_get_recv_skb(idx);
|
||||
DBG_ASSERT(skb, "No pending rx skb");
|
||||
|
||||
for (last_sg = &sg_list[sg_len]; sg_list < last_sg; ++sg_list) {
|
||||
if (sg_list->buf != 0) {
|
||||
rtw_memcpy((void *)(sg_list->buf), skb->data, sg_list->len);
|
||||
skb_pull(skb, sg_list->len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int netif_is_valid_IP(int idx, unsigned char *ip_dest)
|
||||
{
|
||||
#if CONFIG_LWIP_LAYER == 1
|
||||
struct netif * pnetif = &xnetif[idx];
|
||||
struct ip_addr addr = { 0 };
|
||||
#ifdef CONFIG_MEMORY_ACCESS_ALIGNED
|
||||
unsigned int temp;
|
||||
memcpy(&temp, ip_dest, sizeof(unsigned int));
|
||||
u32_t *ip_dest_addr = &temp;
|
||||
#else
|
||||
u32_t *ip_dest_addr = (u32_t*)ip_dest;
|
||||
#endif
|
||||
addr.addr = *ip_dest_addr;
|
||||
|
||||
if(pnetif->ip_addr.addr == 0)
|
||||
return 1;
|
||||
|
||||
if(ip_addr_ismulticast(&addr) || ip_addr_isbroadcast(&addr,pnetif)){
|
||||
return 1;
|
||||
}
|
||||
|
||||
//if(ip_addr_netcmp(&(pnetif->ip_addr), &addr, &(pnetif->netmask))) //addr&netmask
|
||||
// return 1;
|
||||
|
||||
if(ip_addr_cmp(&(pnetif->ip_addr),&addr))
|
||||
return 1;
|
||||
|
||||
DBG_TRACE("invalid IP: %d.%d.%d.%d ",ip_dest[0],ip_dest[1],ip_dest[2],ip_dest[3]);
|
||||
#endif
|
||||
#ifdef CONFIG_DONT_CARE_TP
|
||||
if(pnetif->flags & NETIF_FLAG_IPSWITCH)
|
||||
return 1;
|
||||
else
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
int netif_get_idx(struct netif* pnetif)
|
||||
{
|
||||
#if CONFIG_LWIP_LAYER == 1
|
||||
int idx = pnetif - xnetif;
|
||||
|
||||
switch(idx) {
|
||||
case 0:
|
||||
return 0;
|
||||
case 1:
|
||||
return 1;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
unsigned char *netif_get_hwaddr(int idx_wlan)
|
||||
{
|
||||
#if (CONFIG_LWIP_LAYER == 1)
|
||||
return xnetif[idx_wlan].hwaddr;
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
void netif_rx(int idx, unsigned int len)
|
||||
{
|
||||
#if (CONFIG_LWIP_LAYER == 1)
|
||||
ethernetif_recv(&xnetif[idx], len);
|
||||
#endif
|
||||
#if (CONFIG_INIC_EN == 1)
|
||||
inic_netif_rx(idx, len);
|
||||
#endif
|
||||
}
|
||||
|
||||
void netif_post_sleep_processing(void)
|
||||
{
|
||||
#if (CONFIG_LWIP_LAYER == 1)
|
||||
lwip_POST_SLEEP_PROCESSING(); //For FreeRTOS tickless to enable Lwip ARP timer when leaving IPS - Alex Fang
|
||||
#endif
|
||||
}
|
||||
|
||||
void netif_pre_sleep_processing(void)
|
||||
{
|
||||
#if (CONFIG_LWIP_LAYER == 1)
|
||||
lwip_PRE_SLEEP_PROCESSING();
|
||||
#endif
|
||||
}
|
||||
|
57
component/common/drivers/wlan/realtek/src/osdep/lwip_intf.h
Normal file
57
component/common/drivers/wlan/realtek/src/osdep/lwip_intf.h
Normal file
|
@ -0,0 +1,57 @@
|
|||
#ifndef __LWIP_INTF_H__
|
||||
#define __LWIP_INTF_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <wireless.h>
|
||||
#include <skbuff.h>
|
||||
#include "ethernetif.h"
|
||||
#if 0 // moved to ethernetif.h by jimmy 12/2/2015
|
||||
//----- ------------------------------------------------------------------
|
||||
// Ethernet Buffer
|
||||
//----- ------------------------------------------------------------------
|
||||
struct eth_drv_sg {
|
||||
unsigned int buf;
|
||||
unsigned int len;
|
||||
};
|
||||
|
||||
#define MAX_ETH_DRV_SG 32
|
||||
#define MAX_ETH_MSG 1540
|
||||
#endif
|
||||
//----- ------------------------------------------------------------------
|
||||
// Wlan Interface Provided
|
||||
//----- ------------------------------------------------------------------
|
||||
unsigned char rltk_wlan_check_isup(int idx);
|
||||
void rltk_wlan_tx_inc(int idx);
|
||||
void rltk_wlan_tx_dec(int idx);
|
||||
struct sk_buff * rltk_wlan_get_recv_skb(int idx);
|
||||
struct sk_buff * rltk_wlan_alloc_skb(unsigned int total_len);
|
||||
void rltk_wlan_set_netif_info(int idx_wlan, void * dev, unsigned char * dev_addr);
|
||||
void rltk_wlan_send_skb(int idx, struct sk_buff *skb); //struct sk_buff as defined above comment line
|
||||
int rltk_wlan_send(int idx, struct eth_drv_sg *sg_list, int sg_len, int total_len);
|
||||
void rltk_wlan_recv(int idx, struct eth_drv_sg *sg_list, int sg_len);
|
||||
unsigned char rltk_wlan_running(unsigned char idx); // interface is up. 0: interface is down
|
||||
|
||||
//----- ------------------------------------------------------------------
|
||||
// Network Interface provided
|
||||
//----- ------------------------------------------------------------------
|
||||
struct netif;
|
||||
int netif_is_valid_IP(int idx,unsigned char * ip_dest);
|
||||
int netif_get_idx(struct netif *pnetif);
|
||||
unsigned char *netif_get_hwaddr(int idx_wlan);
|
||||
void netif_rx(int idx, unsigned int len);
|
||||
void netif_post_sleep_processing(void);
|
||||
void netif_pre_sleep_processing(void);
|
||||
#if (CONFIG_LWIP_LAYER == 1)
|
||||
extern void ethernetif_recv(struct netif *netif, int total_len);
|
||||
extern void lwip_PRE_SLEEP_PROCESSING(void);
|
||||
extern void lwip_POST_SLEEP_PROCESSING(void);
|
||||
#endif //CONFIG_LWIP_LAYER == 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //#ifndef __LWIP_INTF_H__
|
57
component/common/drivers/wlan/realtek/src/osdep/skbuff.h
Normal file
57
component/common/drivers/wlan/realtek/src/osdep/skbuff.h
Normal file
|
@ -0,0 +1,57 @@
|
|||
#ifndef __SKBUFF_H__
|
||||
#define __SKBUFF_H__
|
||||
|
||||
struct sk_buff_head {
|
||||
struct list_head *next, *prev;
|
||||
unsigned int qlen;
|
||||
};
|
||||
|
||||
#ifdef CONFIG_TRACE_SKB
|
||||
#define TRACE_SKB_DEPTH 8
|
||||
#endif
|
||||
|
||||
struct sk_buff {
|
||||
/* These two members must be first. */
|
||||
struct sk_buff *next; /* Next buffer in list */
|
||||
struct sk_buff *prev; /* Previous buffer in list */
|
||||
|
||||
struct sk_buff_head *list; /* List we are on */
|
||||
unsigned char *head; /* Head of buffer */
|
||||
unsigned char *data; /* Data head pointer */
|
||||
unsigned char *tail; /* Tail pointer */
|
||||
unsigned char *end; /* End pointer */
|
||||
void *dev; /* Device we arrived on/are leaving by */
|
||||
unsigned int len; /* Length of actual data */
|
||||
#ifdef CONFIG_TRACE_SKB
|
||||
unsigned int liston[TRACE_SKB_DEPTH]; /* Trace the Lists we went through */
|
||||
const char *funcname[TRACE_SKB_DEPTH];
|
||||
unsigned int list_idx; /* Trace the List we are on */
|
||||
#endif
|
||||
#ifdef CONFIG_DONT_CARE_TP
|
||||
int dyalloc_flag;
|
||||
#endif
|
||||
};
|
||||
|
||||
unsigned char *skb_put(struct sk_buff *skb, unsigned int len);
|
||||
unsigned char *skb_pull(struct sk_buff *skb, unsigned int len);
|
||||
void skb_reserve(struct sk_buff *skb, unsigned int len);
|
||||
void skb_assign_buf(struct sk_buff *skb, unsigned char *buf, unsigned int len);
|
||||
unsigned char *skb_tail_pointer(const struct sk_buff *skb);
|
||||
void skb_set_tail_pointer(struct sk_buff *skb, const int offset);
|
||||
unsigned char *skb_end_pointer(const struct sk_buff *skb);
|
||||
|
||||
void init_skb_pool(void);
|
||||
void init_skb_data_pool(void);
|
||||
|
||||
#ifndef CONFIG_DONT_CARE_TP
|
||||
struct sk_buff *dev_alloc_skb(unsigned int length, unsigned int reserve_len);
|
||||
#else
|
||||
struct sk_buff *dev_alloc_tx_skb(unsigned int length, unsigned int reserve_len);
|
||||
struct sk_buff *dev_alloc_rx_skb(unsigned int length, unsigned int reserve_len);
|
||||
#define dev_alloc_skb dev_alloc_tx_skb
|
||||
#endif
|
||||
void kfree_skb(struct sk_buff *skb);
|
||||
|
||||
|
||||
#endif //__SKBUFF_H__
|
||||
|
1209
component/common/drivers/wlan/realtek/src/osdep/wireless.h
Normal file
1209
component/common/drivers/wlan/realtek/src/osdep/wireless.h
Normal file
File diff suppressed because it is too large
Load diff
65
component/common/drivers/wlan/realtek/src/osdep/wlan_intf.h
Normal file
65
component/common/drivers/wlan/realtek/src/osdep/wlan_intf.h
Normal file
|
@ -0,0 +1,65 @@
|
|||
#ifndef __WLAN_INTF_H__
|
||||
#define __WLAN_INTF_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include <autoconf.h>
|
||||
|
||||
#include <wireless.h>
|
||||
#include "wifi_constants.h"
|
||||
|
||||
#ifndef WLAN0_IDX
|
||||
#define WLAN0_IDX 0
|
||||
#endif
|
||||
#ifndef WLAN1_IDX
|
||||
#define WLAN1_IDX 1
|
||||
#endif
|
||||
#ifndef WLAN_UNDEF
|
||||
#define WLAN_UNDEF -1
|
||||
#endif
|
||||
|
||||
/***********************************************************/
|
||||
/*
|
||||
struct sk_buff {
|
||||
// These two members must be first.
|
||||
struct sk_buff *next; // Next buffer in list
|
||||
struct sk_buff *prev; // Previous buffer in list
|
||||
|
||||
struct sk_buff_head *list; // List we are on
|
||||
unsigned char *head; // Head of buffer
|
||||
unsigned char *data; // Data head pointer
|
||||
unsigned char *tail; // Tail pointer
|
||||
unsigned char *end; //End pointer
|
||||
struct net_device *dev; //Device we arrived on/are leaving by
|
||||
unsigned int len; // Length of actual data
|
||||
};
|
||||
*/
|
||||
/************************************************************/
|
||||
|
||||
//----- ------------------------------------------------------------------
|
||||
// Wlan Interface opened for upper layer
|
||||
//----- ------------------------------------------------------------------
|
||||
int rltk_wlan_init(int idx_wlan, rtw_mode_t mode); //return 0: success. -1:fail
|
||||
void rltk_wlan_deinit(void);
|
||||
void rltk_wlan_start(int idx_wlan);
|
||||
void rltk_wlan_statistic(unsigned char idx);
|
||||
unsigned char rltk_wlan_running(unsigned char idx); // interface is up. 0: interface is down
|
||||
int rltk_wlan_control(unsigned long cmd, void *data);
|
||||
int rltk_wlan_handshake_done(void);
|
||||
int rltk_wlan_rf_on(void);
|
||||
int rltk_wlan_rf_off(void);
|
||||
int rltk_wlan_check_bus(void);
|
||||
int rltk_wlan_wireless_mode(unsigned char mode);
|
||||
int rltk_wlan_set_wps_phase(unsigned char is_trigger_wps);
|
||||
int rtw_ps_enable(int enable);
|
||||
int rltk_wlan_is_connected_to_ap(void);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif //#ifndef __WLAN_INTF_H__
|
27
component/common/example/example_entry.c
Normal file
27
component/common/example/example_entry.c
Normal file
|
@ -0,0 +1,27 @@
|
|||
/******************************************************************************
|
||||
*
|
||||
* Copyright(c) 2007 - 2015 Realtek Corporation. All rights reserved.
|
||||
*
|
||||
*
|
||||
******************************************************************************/
|
||||
#include <platform_opts.h>
|
||||
#include "main.h"
|
||||
|
||||
/*
|
||||
Preprocessor of example
|
||||
*/
|
||||
void pre_example_entry(void)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/*
|
||||
All of the examples are disabled by default for code size consideration
|
||||
The configuration is enabled in platform_opts.h
|
||||
*/
|
||||
void example_entry(void)
|
||||
{
|
||||
#if CONFIG_EXAMPLE_UART_ATCMD
|
||||
example_uart_atcmd();
|
||||
#endif
|
||||
}
|
8
component/common/example/example_entry.h
Normal file
8
component/common/example/example_entry.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef __EXAMPLE_ENTRY_H__
|
||||
#define __EXAMPLE_ENTRY_H__
|
||||
|
||||
|
||||
void example_entry(void);
|
||||
void pre_example_entry(void);
|
||||
|
||||
#endif //#ifndef __EXAMPLE_ENTRY_H__
|
580
component/common/example/uart_atcmd/example_uart_atcmd.c
Normal file
580
component/common/example/uart_atcmd/example_uart_atcmd.c
Normal file
|
@ -0,0 +1,580 @@
|
|||
/******************************************************************************
|
||||
*
|
||||
* Copyright(c) 2007 - 2015 Realtek Corporation. All rights reserved.
|
||||
*
|
||||
*
|
||||
******************************************************************************/
|
||||
#include <platform_opts.h>
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include <platform/platform_stdlib.h>
|
||||
#include "semphr.h"
|
||||
#include "device.h"
|
||||
#include "serial_api.h"
|
||||
#include "at_cmd/log_service.h"
|
||||
#include "uart_atcmd/example_uart_atcmd.h"
|
||||
#include "flash_api.h"
|
||||
#include "device_lock.h"
|
||||
#if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1)
|
||||
#include "freertos_pmu.h"
|
||||
#endif
|
||||
#include "osdep_api.h"
|
||||
#include "osdep_service.h"
|
||||
#include "serial_ex_api.h"
|
||||
#include "at_cmd/atcmd_wifi.h"
|
||||
#include "at_cmd/atcmd_lwip.h"
|
||||
#include "pinmap.h"
|
||||
|
||||
#if CONFIG_EXAMPLE_UART_ATCMD
|
||||
|
||||
typedef int (*init_done_ptr)(void);
|
||||
extern init_done_ptr p_wlan_init_done_callback;
|
||||
extern char log_buf[LOG_SERVICE_BUFLEN];
|
||||
extern xSemaphoreHandle log_rx_interrupt_sema;
|
||||
extern void serial_rx_fifo_level(serial_t *obj, SerialFifoLevel FifoLv);
|
||||
extern int atcmd_wifi_restore_from_flash(void);
|
||||
extern int atcmd_lwip_restore_from_flash(void);
|
||||
|
||||
serial_t at_cmd_sobj;
|
||||
char at_string[ATSTRING_LEN];
|
||||
//xSemaphoreHandle at_printf_sema;
|
||||
_Sema uart_at_dma_tx_sema;
|
||||
unsigned char gAT_Echo = 1; // default echo on
|
||||
|
||||
#define UART_AT_MAX_DELAY_TIME_MS 20
|
||||
|
||||
#define UART_AT_DATA UART_SETTING_SECTOR
|
||||
#define BACKUP_SECTOR FLASH_SYSTEM_DATA_ADDR-0x1000
|
||||
|
||||
#define UART_AT_USE_DMA_TX 0
|
||||
|
||||
void atcmd_update_partition_info(AT_PARTITION id, AT_PARTITION_OP ops, u8 *data, u16 len){
|
||||
flash_t flash;
|
||||
int size, offset, i;
|
||||
u32 read_data;
|
||||
|
||||
switch(id){
|
||||
case AT_PARTITION_UART:
|
||||
size = UART_CONF_DATA_SIZE;
|
||||
offset = UART_CONF_DATA_OFFSET;
|
||||
break;
|
||||
case AT_PARTITION_WIFI:
|
||||
size = WIFI_CONF_DATA_SIZE;
|
||||
offset = WIFI_CONF_DATA_OFFSET;
|
||||
break;
|
||||
case AT_PARTITION_LWIP:
|
||||
size = LWIP_CONF_DATA_SIZE;
|
||||
offset = LWIP_CONF_DATA_OFFSET;
|
||||
break;
|
||||
case AT_PARTITION_ALL:
|
||||
size = 0x1000;
|
||||
offset = 0;
|
||||
break;
|
||||
default:
|
||||
printf("partition id is invalid!\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
device_mutex_lock(RT_DEV_LOCK_FLASH);
|
||||
|
||||
if(id == AT_PARTITION_ALL && ops == AT_PARTITION_ERASE){
|
||||
flash_erase_sector(&flash, UART_SETTING_SECTOR);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if(ops == AT_PARTITION_READ){
|
||||
flash_stream_read(&flash, UART_SETTING_SECTOR+offset, len, data);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
//erase BACKUP_SECTOR
|
||||
flash_erase_sector(&flash, UART_SETTING_BACKUP_SECTOR);
|
||||
|
||||
if(ops == AT_PARTITION_WRITE){
|
||||
// backup new data
|
||||
flash_stream_write(&flash, UART_SETTING_BACKUP_SECTOR+offset, len, data);
|
||||
}
|
||||
|
||||
//backup front data to backup sector
|
||||
for(i = 0; i < offset; i += sizeof(read_data)){
|
||||
flash_read_word(&flash, UART_SETTING_SECTOR + i, &read_data);
|
||||
flash_write_word(&flash, UART_SETTING_BACKUP_SECTOR + i,read_data);
|
||||
}
|
||||
|
||||
//backup rear data
|
||||
for(i = (offset + size); i < 0x1000; i += sizeof(read_data)){
|
||||
flash_read_word(&flash, UART_SETTING_SECTOR + i, &read_data);
|
||||
flash_write_word(&flash, UART_SETTING_BACKUP_SECTOR + i,read_data);
|
||||
}
|
||||
|
||||
//erase UART_SETTING_SECTOR
|
||||
flash_erase_sector(&flash, UART_SETTING_SECTOR);
|
||||
|
||||
//retore data to UART_SETTING_SECTOR from UART_SETTING_BACKUP_SECTOR
|
||||
for(i = 0; i < 0x1000; i+= sizeof(read_data)){
|
||||
flash_read_word(&flash, UART_SETTING_BACKUP_SECTOR + i, &read_data);
|
||||
flash_write_word(&flash, UART_SETTING_SECTOR + i,read_data);
|
||||
}
|
||||
|
||||
//erase BACKUP_SECTOR
|
||||
flash_erase_sector(&flash, UART_SETTING_BACKUP_SECTOR);
|
||||
|
||||
exit:
|
||||
device_mutex_unlock(RT_DEV_LOCK_FLASH);
|
||||
return;
|
||||
}
|
||||
|
||||
int read_uart_atcmd_setting_from_system_data(UART_LOG_CONF* uartconf)
|
||||
{
|
||||
// flash_t flash;
|
||||
UART_LOG_CONF conf;
|
||||
bool load_default = _TRUE;
|
||||
|
||||
// device_mutex_lock(RT_DEV_LOCK_FLASH);
|
||||
// flash_stream_read(&flash, UART_AT_DATA,sizeof(UART_LOG_CONF), (u8 *)&conf);
|
||||
atcmd_update_partition_info(AT_PARTITION_UART, AT_PARTITION_READ, (u8 *)&conf, sizeof(UART_LOG_CONF));
|
||||
do{
|
||||
if(conf.FlowControl != AUTOFLOW_DISABLE && conf.FlowControl != AUTOFLOW_ENABLE)
|
||||
break;
|
||||
|
||||
if(conf.DataBits != 5
|
||||
&& conf.DataBits != 6
|
||||
&& conf.DataBits != 7
|
||||
&& conf.DataBits != 8) //5, 6, 7, 8
|
||||
break;
|
||||
|
||||
if(conf.Parity != ParityNone && conf.Parity != ParityOdd && conf.Parity != ParityEven)
|
||||
break;
|
||||
|
||||
if(conf.StopBits != 1 && conf.StopBits != 2)
|
||||
break;
|
||||
|
||||
load_default = _FALSE;
|
||||
}while(0);
|
||||
|
||||
if(load_default == _TRUE){
|
||||
// load default setting
|
||||
uartconf->BaudRate = UART_BAUD_RATE_38400;
|
||||
uartconf->DataBits = 8;
|
||||
uartconf->Parity = ParityNone;
|
||||
uartconf->StopBits = 1;
|
||||
uartconf->FlowControl = AUTOFLOW_DISABLE;
|
||||
}
|
||||
else{
|
||||
uartconf->BaudRate = conf.BaudRate;
|
||||
uartconf->DataBits = conf.DataBits;
|
||||
uartconf->Parity = conf.Parity;
|
||||
uartconf->StopBits = conf.StopBits;
|
||||
uartconf->FlowControl = conf.FlowControl;
|
||||
}
|
||||
// device_mutex_unlock(RT_DEV_LOCK_FLASH);
|
||||
printf("\r\nAT_UART_CONF: %d,%d,%d,%d,%d\r\n",
|
||||
uartconf->BaudRate,
|
||||
uartconf->DataBits,
|
||||
uartconf->StopBits,
|
||||
uartconf->Parity,
|
||||
uartconf->FlowControl);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int write_uart_atcmd_setting_to_system_data(UART_LOG_CONF* uartconf)
|
||||
{
|
||||
#if 0
|
||||
flash_t flash;
|
||||
|
||||
u8 data1[sizeof(UART_LOG_CONF)];
|
||||
u8 data2[sizeof(UART_LOG_CONF)];
|
||||
|
||||
u32 data,i;
|
||||
|
||||
memset(data2, 0xFF, sizeof(UART_LOG_CONF));
|
||||
|
||||
//Get upgraded image 2 addr from offset
|
||||
device_mutex_lock(RT_DEV_LOCK_FLASH);
|
||||
flash_stream_read(&flash, UART_AT_DATA,sizeof(UART_LOG_CONF), data1);
|
||||
|
||||
if(memcmp(data1,data2,sizeof(UART_LOG_CONF)) == 0){
|
||||
flash_stream_write(&flash, UART_AT_DATA, sizeof(UART_LOG_CONF),(u8*)uartconf);
|
||||
}else{
|
||||
//erase backup sector
|
||||
flash_erase_sector(&flash, BACKUP_SECTOR);
|
||||
|
||||
// backup log uart configuration
|
||||
flash_stream_write(&flash, BACKUP_SECTOR, sizeof(UART_LOG_CONF),(u8*)uartconf);
|
||||
|
||||
//backup system data to backup sector
|
||||
for(i = sizeof(UART_LOG_CONF); i < 0x1000; i+= 4){
|
||||
flash_read_word(&flash, UART_AT_DATA + i, &data);
|
||||
flash_write_word(&flash, BACKUP_SECTOR + i,data);
|
||||
}
|
||||
//erase system data
|
||||
flash_erase_sector(&flash, UART_AT_DATA);
|
||||
//write data back to system data
|
||||
for(i = 0; i < 0x1000; i+= 4){
|
||||
flash_read_word(&flash, BACKUP_SECTOR + i, &data);
|
||||
flash_write_word(&flash, UART_AT_DATA + i,data);
|
||||
}
|
||||
//erase backup sector
|
||||
flash_erase_sector(&flash, BACKUP_SECTOR);
|
||||
}
|
||||
device_mutex_unlock(RT_DEV_LOCK_FLASH);
|
||||
#else
|
||||
atcmd_update_partition_info(AT_PARTITION_UART, AT_PARTITION_WRITE, (u8 *)uartconf, sizeof(UART_LOG_CONF));
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
int reset_uart_atcmd_setting(){
|
||||
#if 0
|
||||
flash_t flash;
|
||||
|
||||
u8 data1[sizeof(UART_LOG_CONF)];
|
||||
u8 data2[sizeof(UART_LOG_CONF)];
|
||||
|
||||
u32 data,i;
|
||||
|
||||
memset(data2, 0xFF, sizeof(UART_LOG_CONF));
|
||||
|
||||
//Get upgraded image 2 addr from offset
|
||||
device_mutex_lock(RT_DEV_LOCK_FLASH);
|
||||
flash_stream_read(&flash, UART_AT_DATA,sizeof(UART_LOG_CONF), data1);
|
||||
|
||||
if(memcmp(data1,data2,sizeof(UART_LOG_CONF)) == 0){
|
||||
;
|
||||
}else{
|
||||
//erase backup sector
|
||||
flash_erase_sector(&flash, BACKUP_SECTOR);
|
||||
|
||||
// erase uart configuration
|
||||
flash_stream_write(&flash, BACKUP_SECTOR, sizeof(UART_LOG_CONF),(u8*)data2);
|
||||
//backup system data to backup sector
|
||||
for(i = sizeof(UART_LOG_CONF); i < 0x1000; i+= 4){
|
||||
flash_read_word(&flash, UART_AT_DATA + i, &data);
|
||||
flash_write_word(&flash, BACKUP_SECTOR + i,data);
|
||||
}
|
||||
//erase system data
|
||||
flash_erase_sector(&flash, UART_AT_DATA);
|
||||
//write data back to system data
|
||||
for(i = 0; i < 0x1000; i+= 4){
|
||||
flash_read_word(&flash, BACKUP_SECTOR + i, &data);
|
||||
flash_write_word(&flash, UART_AT_DATA + i,data);
|
||||
}
|
||||
//erase backup sector
|
||||
flash_erase_sector(&flash, BACKUP_SECTOR);
|
||||
}
|
||||
device_mutex_unlock(RT_DEV_LOCK_FLASH);
|
||||
#else
|
||||
atcmd_update_partition_info(AT_PARTITION_ALL, AT_PARTITION_ERASE, NULL, 0);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1)
|
||||
#include "gpio_irq_api.h"
|
||||
#define UART_AT_RX_WAKE UART_RX
|
||||
void gpio_uart_at_rx_irq_callback (uint32_t id, gpio_irq_event event)
|
||||
{
|
||||
/* WAKELOCK_LOGUART is also handled in log service.
|
||||
* It is release after a complete command is sent.
|
||||
**/
|
||||
//acquire_wakelock(WAKELOCK_LOGUART);
|
||||
}
|
||||
|
||||
void uart_at_rx_wakeup()
|
||||
{
|
||||
gpio_irq_t gpio_rx_wake;
|
||||
gpio_irq_init(&gpio_rx_wake, UART_AT_RX_WAKE, gpio_uart_at_rx_irq_callback, NULL);
|
||||
gpio_irq_set(&gpio_rx_wake, IRQ_FALL, 1); // Falling Edge Trigger
|
||||
gpio_irq_enable(&gpio_rx_wake);
|
||||
}
|
||||
#endif
|
||||
|
||||
void uart_atcmd_reinit(UART_LOG_CONF* uartconf){
|
||||
serial_baud(&at_cmd_sobj,uartconf->BaudRate);
|
||||
serial_format(&at_cmd_sobj, uartconf->DataBits, (SerialParity)uartconf->Parity, uartconf->StopBits);
|
||||
|
||||
// set flow control, only support RTS and CTS concurrent mode
|
||||
// rxflow and tx flow is fixed by hardware
|
||||
#define rxflow UART_RTS
|
||||
#define txflow UART_CTS
|
||||
if(uartconf->FlowControl){
|
||||
pin_mode(txflow, PullDown); //init CTS in low
|
||||
serial_set_flow_control(&at_cmd_sobj, FlowControlRTSCTS, rxflow, txflow);
|
||||
}
|
||||
else
|
||||
serial_set_flow_control(&at_cmd_sobj, FlowControlNone, rxflow, txflow);
|
||||
}
|
||||
|
||||
void uart_at_send_string(char *str)
|
||||
{
|
||||
unsigned int i=0;
|
||||
while (str[i] != '\0') {
|
||||
serial_putc(&at_cmd_sobj, str[i]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
#if UART_AT_USE_DMA_TX
|
||||
static void uart_at_send_buf_done(uint32_t id)
|
||||
{
|
||||
//serial_t *sobj = (serial_t *)id;
|
||||
|
||||
RtlUpSemaFromISR(&uart_at_dma_tx_sema);
|
||||
}
|
||||
#endif
|
||||
|
||||
void uart_at_send_buf(u8 *buf, u32 len)
|
||||
{
|
||||
unsigned char *st_p=buf;
|
||||
if(!len || (!buf)){
|
||||
return;
|
||||
}
|
||||
#if UART_AT_USE_DMA_TX
|
||||
int ret;
|
||||
while(RtlDownSema(&uart_at_dma_tx_sema) == pdTRUE){
|
||||
ret = serial_send_stream_dma(&at_cmd_sobj, st_p, len);
|
||||
if(ret != HAL_OK){
|
||||
RtlUpSema(&uart_at_dma_tx_sema);
|
||||
return;
|
||||
}else{
|
||||
return;
|
||||
}
|
||||
}
|
||||
#else
|
||||
while(len){
|
||||
serial_putc(&at_cmd_sobj, *st_p);
|
||||
st_p++;
|
||||
len--;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
/*
|
||||
void uart_at_lock(void)
|
||||
{
|
||||
RtlDownSema(&at_printf_sema);
|
||||
}
|
||||
|
||||
void uart_at_unlock(void)
|
||||
{
|
||||
RtlUpSema(&at_printf_sema);
|
||||
}
|
||||
|
||||
void uart_at_lock_init(){
|
||||
RtlInitSema(&at_printf_sema, 1);
|
||||
}
|
||||
*/
|
||||
void uart_irq(uint32_t id, SerialIrq event)
|
||||
{
|
||||
serial_t *sobj = (serial_t *)id;
|
||||
unsigned char rc=0;
|
||||
static unsigned char temp_buf[LOG_SERVICE_BUFLEN] = "\0";
|
||||
static unsigned int buf_count = 0;
|
||||
static unsigned char combo_key = 0;
|
||||
static u32 last_tickcnt = 0; //to check if any data lost
|
||||
static bool is_data_cmd = _FALSE; // to mark if it's a data command
|
||||
static u32 data_sz = 0, data_cmd_sz =0; // command will send to log handler until "data_cmd_sz" characters are received
|
||||
|
||||
if(event == RxIrq) {
|
||||
rc = serial_getc(sobj);
|
||||
|
||||
if(atcmd_lwip_is_tt_mode()){
|
||||
log_buf[atcmd_lwip_tt_datasize++] = rc;
|
||||
atcmd_lwip_tt_lasttickcnt = xTaskGetTickCountFromISR();
|
||||
if(atcmd_lwip_tt_datasize == 1)
|
||||
RtlUpSemaFromISR((_Sema *)&atcmd_lwip_tt_sema);
|
||||
return;
|
||||
}
|
||||
|
||||
if(buf_count == 4){
|
||||
// if this is a data command with hex data, then '\n' should not be treated
|
||||
// as the end of command
|
||||
if(strncmp(temp_buf, "ATPT", C_NUM_AT_CMD)==0){
|
||||
is_data_cmd = _TRUE;
|
||||
}
|
||||
}
|
||||
if(buf_count > C_NUM_AT_CMD && is_data_cmd == _TRUE){
|
||||
if(data_cmd_sz == 0){
|
||||
if(data_sz == 0){
|
||||
if(rc == ','){
|
||||
//first delimeter, ATxx=[sz],....
|
||||
char str[10]={0};
|
||||
char size_pos = C_NUM_AT_CMD + C_NUM_AT_CMD_DLT;
|
||||
memcpy(str, &temp_buf[size_pos], buf_count-size_pos);
|
||||
data_sz = atoi(str); //get data size
|
||||
}
|
||||
}else{
|
||||
if(rc == ':'){ //data will start after this delimeter ':'
|
||||
strncpy(log_buf, (char *)temp_buf, buf_count);
|
||||
memset(temp_buf,'\0',buf_count);
|
||||
last_tickcnt = xTaskGetTickCountFromISR();
|
||||
data_cmd_sz = buf_count + 1 + data_sz;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(data_cmd_sz){
|
||||
if((!gAT_Echo) && (rtw_systime_to_ms(xTaskGetTickCountFromISR() - last_tickcnt) > UART_AT_MAX_DELAY_TIME_MS)){
|
||||
uart_at_send_string("\r\nERROR:data timeout\r\n\n# ");
|
||||
memset(log_buf, 0, buf_count);
|
||||
is_data_cmd = _FALSE;
|
||||
data_sz = 0;
|
||||
data_cmd_sz = 0;
|
||||
buf_count=0;
|
||||
last_tickcnt = 0;
|
||||
return;
|
||||
}
|
||||
last_tickcnt = xTaskGetTickCountFromISR();
|
||||
log_buf[buf_count++]=rc;
|
||||
if(gAT_Echo == 1){
|
||||
serial_putc(sobj, rc);
|
||||
}
|
||||
if(buf_count >= data_cmd_sz){
|
||||
log_buf[data_cmd_sz - data_sz - 1] = '\0'; //for log service handler parse to get command parameter, replace ":" with "\0"
|
||||
is_data_cmd = _FALSE;
|
||||
data_sz = 0;
|
||||
data_cmd_sz = 0;
|
||||
buf_count=0;
|
||||
last_tickcnt = 0;
|
||||
RtlUpSemaFromISR((_Sema *)&log_rx_interrupt_sema);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (rc == KEY_ESC) {
|
||||
combo_key = 1;
|
||||
}
|
||||
else if (combo_key == 1){
|
||||
if (rc == KEY_LBRKT) {
|
||||
combo_key = 2;
|
||||
}
|
||||
else{
|
||||
combo_key = 0;
|
||||
}
|
||||
}
|
||||
else if (combo_key == 2){
|
||||
//if ((rc=='A')|| rc=='B'){//up and down
|
||||
//}
|
||||
combo_key=0;
|
||||
}
|
||||
else if(rc == KEY_ENTER){
|
||||
if(buf_count>0){
|
||||
memset(log_buf,'\0',LOG_SERVICE_BUFLEN);
|
||||
strncpy(log_buf,(char *)&temp_buf[0],buf_count);
|
||||
RtlUpSemaFromISR((_Sema *)&log_rx_interrupt_sema);
|
||||
memset(temp_buf,'\0',buf_count);
|
||||
is_data_cmd = _FALSE;
|
||||
data_sz = 0;
|
||||
data_cmd_sz = 0;
|
||||
buf_count=0;
|
||||
last_tickcnt = 0;
|
||||
}else{
|
||||
uart_at_send_string(STR_END_OF_ATCMD_RET);
|
||||
}
|
||||
}
|
||||
else if(rc == KEY_BS){
|
||||
if(buf_count>0){
|
||||
buf_count--;
|
||||
temp_buf[buf_count] = '\0';
|
||||
if(gAT_Echo == 1){
|
||||
serial_putc(sobj, rc);
|
||||
serial_putc(sobj, ' ');
|
||||
serial_putc(sobj, rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
// skip characters until "A"
|
||||
if((buf_count == 0) && (rc != 'A')){
|
||||
if(gAT_Echo == 1){
|
||||
uart_at_send_string("\r\nERROR:command should start with 'A'"STR_END_OF_ATCMD_RET);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(buf_count < (LOG_SERVICE_BUFLEN - 1)){
|
||||
temp_buf[buf_count] = rc;
|
||||
buf_count++;
|
||||
if(gAT_Echo == 1){
|
||||
serial_putc(sobj, rc);
|
||||
}
|
||||
}
|
||||
else if(buf_count == (LOG_SERVICE_BUFLEN - 1)){
|
||||
temp_buf[buf_count] = '\0';
|
||||
if(gAT_Echo == 1){
|
||||
uart_at_send_string("\r\nERROR:exceed size limit"STR_END_OF_ATCMD_RET);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void uart_atcmd_main(void)
|
||||
{
|
||||
UART_LOG_CONF uartconf;
|
||||
|
||||
read_uart_atcmd_setting_from_system_data(&uartconf);
|
||||
|
||||
serial_init(&at_cmd_sobj,UART_TX,UART_RX);
|
||||
serial_baud(&at_cmd_sobj,uartconf.BaudRate);
|
||||
serial_format(&at_cmd_sobj, uartconf.DataBits, (SerialParity)uartconf.Parity, uartconf.StopBits);
|
||||
serial_rx_fifo_level(&at_cmd_sobj, FifoLvHalf);
|
||||
// set flow control, only support RTS and CTS concurrent mode
|
||||
// rxflow and tx flow is fixed by hardware
|
||||
#define rxflow UART_RTS
|
||||
#define txflow UART_CTS
|
||||
if(uartconf.FlowControl){
|
||||
pin_mode(txflow, PullDown); //init CTS in low
|
||||
serial_set_flow_control(&at_cmd_sobj, FlowControlRTSCTS, rxflow, txflow);
|
||||
}
|
||||
else
|
||||
serial_set_flow_control(&at_cmd_sobj, FlowControlNone, rxflow, txflow);
|
||||
|
||||
/*uart_at_lock_init();*/
|
||||
|
||||
#if UART_AT_USE_DMA_TX
|
||||
RtlInitSema(&uart_at_dma_tx_sema, 1);
|
||||
#endif
|
||||
|
||||
#if UART_AT_USE_DMA_TX
|
||||
serial_send_comp_handler(&at_cmd_sobj, (void*)uart_at_send_buf_done, (uint32_t)&at_cmd_sobj);
|
||||
#endif
|
||||
|
||||
serial_irq_handler(&at_cmd_sobj, uart_irq, (uint32_t)&at_cmd_sobj);
|
||||
serial_irq_set(&at_cmd_sobj, RxIrq, 1);
|
||||
|
||||
#if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1)
|
||||
uart_at_rx_wakeup();
|
||||
#endif
|
||||
}
|
||||
|
||||
static void uart_atcmd_thread(void *param)
|
||||
{
|
||||
p_wlan_init_done_callback = NULL;
|
||||
atcmd_wifi_restore_from_flash();
|
||||
atcmd_lwip_restore_from_flash();
|
||||
rtw_msleep_os(20);
|
||||
uart_atcmd_main();
|
||||
at_printf("\r\nAT COMMAND READY");
|
||||
if(atcmd_lwip_is_tt_mode())
|
||||
at_printf(STR_END_OF_ATDATA_RET);
|
||||
else
|
||||
at_printf(STR_END_OF_ATCMD_RET);
|
||||
_AT_DBG_MSG(AT_FLAG_COMMON, AT_DBG_ALWAYS, STR_END_OF_ATCMD_RET);
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
int uart_atcmd_module_init(void){
|
||||
if(xTaskCreate(uart_atcmd_thread, ((const char*)"uart_atcmd_thread"), 1024, NULL, tskIDLE_PRIORITY+1 , NULL) != pdPASS)
|
||||
printf("\n\r%s xTaskCreate(uart_atcmd_thread) failed", __FUNCTION__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void example_uart_atcmd(void)
|
||||
{
|
||||
//if(xTaskCreate(uart_atcmd_thread, ((const char*)"uart_atcmd_thread"), 1024, NULL, tskIDLE_PRIORITY + 1 , NULL) != pdPASS)
|
||||
// printf("\n\r%s xTaskCreate(uart_atcmd_thread) failed", __FUNCTION__);
|
||||
p_wlan_init_done_callback = uart_atcmd_module_init;
|
||||
return;
|
||||
}
|
||||
#endif
|
67
component/common/example/uart_atcmd/example_uart_atcmd.h
Normal file
67
component/common/example/uart_atcmd/example_uart_atcmd.h
Normal file
|
@ -0,0 +1,67 @@
|
|||
#ifndef __EXAMPLE_UART_ATCMD_H__
|
||||
#define __EXAMPLE_UART_ATCMD_H__
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright(c) 2007 - 2015 Realtek Corporation. All rights reserved.
|
||||
*
|
||||
*
|
||||
******************************************************************************/
|
||||
#if CONFIG_EXAMPLE_UART_ATCMD
|
||||
#include "FreeRTOS.h"
|
||||
#include "semphr.h"
|
||||
#include "osdep_api.h"
|
||||
|
||||
#define UART_TX PA_4
|
||||
#define UART_RX PA_0
|
||||
#define UART_RTS PA_2
|
||||
#define UART_CTS PA_1
|
||||
|
||||
#define KEY_ENTER 0xd
|
||||
#define KEY_BS 0x8
|
||||
#define KEY_ESC 0x1B
|
||||
#define KEY_LBRKT 0x5B
|
||||
|
||||
void uart_at_lock(void);
|
||||
void uart_at_unlock(void);
|
||||
void uart_at_send_string(char *str);
|
||||
void uart_at_send_buf(u8 *buf, u32 len);
|
||||
void example_uart_atcmd(void);
|
||||
extern u8 key_2char2num(u8 hch, u8 lch);
|
||||
static void at_hex2str(const u8 *start, u32 size, u8 *out, u32 out_size)
|
||||
{
|
||||
int index, index2;
|
||||
u8 *buf, *line;
|
||||
|
||||
if(!start ||(size==0)||(!out)||(out_size==0))
|
||||
return;
|
||||
|
||||
buf = (u8*)start;
|
||||
line = (u8*)out;
|
||||
for (index = 0, index2=0; (index < size)&&(index2<out_size); index++, index2+=2)
|
||||
{
|
||||
sprintf((char *)line+index2, "%02x", (u8) buf[index]);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
static void at_str2hex(const u8 *start, u32 size, u8 *out, u32 out_size)
|
||||
{
|
||||
int index, index2;
|
||||
u8 *buf, *line;
|
||||
|
||||
if(!start ||(size==0))
|
||||
return;
|
||||
|
||||
buf = (u8*)start;
|
||||
line = (u8*)out;
|
||||
|
||||
for (index=0, index2=0; index<size; index+=2, index2++){
|
||||
line[index2] = key_2char2num(buf[index], buf[index+1]);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#endif //#if CONFIG_EXAMPLE_UART_ATCMD
|
||||
#endif //#ifndef __EXAMPLE_UART_ATCMD_H__
|
|
@ -0,0 +1,155 @@
|
|||
/******************************************************************************
|
||||
*
|
||||
* Copyright(c) 2007 - 2015 Realtek Corporation. All rights reserved.
|
||||
*
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/** @file
|
||||
|
||||
This example demonstrate how to implement wifi fast reconnection
|
||||
**/
|
||||
#include <platform_opts.h>
|
||||
#include <wlan_fast_connect/example_wlan_fast_connect.h>
|
||||
|
||||
|
||||
#include "task.h"
|
||||
#include <platform/platform_stdlib.h>
|
||||
#include <wifi/wifi_conf.h>
|
||||
#include "flash_api.h"
|
||||
#include "device_lock.h"
|
||||
#include <lwip_netconf.h>
|
||||
|
||||
write_reconnect_ptr p_write_reconnect_ptr;
|
||||
|
||||
/*
|
||||
* Usage:
|
||||
* wifi connection indication trigger this function to save current
|
||||
* wifi profile in flash
|
||||
*
|
||||
* Condition:
|
||||
* CONFIG_EXAMPLE_WLAN_FAST_CONNECT flag is set
|
||||
*/
|
||||
|
||||
int wlan_wrtie_reconnect_data_to_flash(u8 *data, uint32_t len)
|
||||
{
|
||||
flash_t flash;
|
||||
struct wlan_fast_reconnect read_data = {0};
|
||||
if(!data)
|
||||
return -1;
|
||||
|
||||
device_mutex_lock(RT_DEV_LOCK_FLASH);
|
||||
flash_stream_read(&flash, FAST_RECONNECT_DATA, sizeof(struct wlan_fast_reconnect), (u8 *) &read_data);
|
||||
|
||||
#if ATCMD_VER == ATVER_2
|
||||
struct wlan_fast_reconnect *copy_data = (struct wlan_fast_reconnect *) data;
|
||||
copy_data->enable = read_data.enable;
|
||||
#endif
|
||||
|
||||
//wirte it to flash if different content: SSID, Passphrase, Channel, Security type
|
||||
if(memcmp(data, (u8 *) &read_data, sizeof(struct wlan_fast_reconnect)) != 0) {
|
||||
printf("\r\n %s():not the same ssid/passphrase/channel, write new profile to flash", __func__);
|
||||
flash_erase_sector(&flash, FAST_RECONNECT_DATA);
|
||||
flash_stream_write(&flash, FAST_RECONNECT_DATA, len, (uint8_t *) data);
|
||||
}
|
||||
device_mutex_unlock(RT_DEV_LOCK_FLASH);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Usage:
|
||||
* After wifi init done, waln driver call this function to check whether
|
||||
* auto-connect is required.
|
||||
*
|
||||
* This function read previous saved wlan profile in flash and execute connection.
|
||||
*
|
||||
* Condition:
|
||||
* CONFIG_EXAMPLE_WLAN_FAST_CONNECT flag is set
|
||||
*/
|
||||
int wlan_init_done_callback()
|
||||
{
|
||||
flash_t flash;
|
||||
struct wlan_fast_reconnect *data;
|
||||
uint32_t channel;
|
||||
uint32_t security_type;
|
||||
uint8_t pscan_config;
|
||||
char key_id[2] = {0};
|
||||
|
||||
rtw_network_info_t wifi = {
|
||||
{0}, // ssid
|
||||
{0}, // bssid
|
||||
0, // security
|
||||
NULL, // password
|
||||
0, // password len
|
||||
-1 // key id
|
||||
};
|
||||
|
||||
#if CONFIG_AUTO_RECONNECT
|
||||
//setup reconnection flag
|
||||
wifi_set_autoreconnect(1);
|
||||
#endif
|
||||
data = (struct wlan_fast_reconnect *)rtw_zmalloc(sizeof(struct wlan_fast_reconnect));
|
||||
if(data){
|
||||
device_mutex_lock(RT_DEV_LOCK_FLASH);
|
||||
flash_stream_read(&flash, FAST_RECONNECT_DATA, sizeof(struct wlan_fast_reconnect), (uint8_t *)data);
|
||||
device_mutex_unlock(RT_DEV_LOCK_FLASH);
|
||||
memcpy(psk_essid, data->psk_essid, sizeof(data->psk_essid));
|
||||
memcpy(psk_passphrase, data->psk_passphrase, sizeof(data->psk_passphrase));
|
||||
memcpy(wpa_global_PSK, data->wpa_global_PSK, sizeof(data->wpa_global_PSK));
|
||||
channel = data->channel;
|
||||
sprintf(key_id,"%d",(char) (channel>>28));
|
||||
channel &= 0xff;
|
||||
security_type = data->security_type;
|
||||
pscan_config = PSCAN_ENABLE | PSCAN_FAST_SURVEY;
|
||||
//set partial scan for entering to listen beacon quickly
|
||||
wifi_set_pscan_chan((uint8_t *)&channel, &pscan_config, 1);
|
||||
|
||||
wifi.security_type = security_type;
|
||||
//SSID
|
||||
strcpy((char *)wifi.ssid.val, (char*)psk_essid);
|
||||
wifi.ssid.len = strlen((char*)psk_essid);
|
||||
|
||||
switch(security_type){
|
||||
case RTW_SECURITY_WEP_PSK:
|
||||
wifi.password = (unsigned char*) psk_passphrase;
|
||||
wifi.password_len = strlen((char*)psk_passphrase);
|
||||
wifi.key_id = atoi((const char *)key_id);
|
||||
break;
|
||||
case RTW_SECURITY_WPA_TKIP_PSK:
|
||||
case RTW_SECURITY_WPA2_AES_PSK:
|
||||
wifi.password = (unsigned char*) psk_passphrase;
|
||||
wifi.password_len = strlen((char*)psk_passphrase);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
wifi_connect((char*)wifi.ssid.val, wifi.security_type, (char*)wifi.password, wifi.ssid.len,
|
||||
wifi.password_len, wifi.key_id, NULL);
|
||||
|
||||
LwIP_DHCP(0, DHCP_START);
|
||||
|
||||
rtw_mfree(data);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Erase_Fastconnect_data(){
|
||||
flash_t flash;
|
||||
|
||||
device_mutex_lock(RT_DEV_LOCK_FLASH);
|
||||
flash_erase_sector(&flash, FAST_RECONNECT_DATA);
|
||||
device_mutex_unlock(RT_DEV_LOCK_FLASH);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void example_wlan_fast_connect()
|
||||
{
|
||||
// Call back from wlan driver after wlan init done
|
||||
p_wlan_init_done_callback = wlan_init_done_callback;
|
||||
|
||||
// Call back from application layer after wifi_connection success
|
||||
p_write_reconnect_ptr = wlan_wrtie_reconnect_data_to_flash;
|
||||
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
#ifndef __EXAMPLE_FAST_RECONNECTION_H__
|
||||
#define __EXAMPLE_FAST_RECONNECTION_H__
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright(c) 2007 - 2015 Realtek Corporation. All rights reserved.
|
||||
*
|
||||
*
|
||||
******************************************************************************/
|
||||
#include "FreeRTOS.h"
|
||||
#include <autoconf.h>
|
||||
#include "main.h"
|
||||
|
||||
#define IW_PASSPHRASE_MAX_SIZE 64
|
||||
//#define FAST_RECONNECT_DATA (0x80000 - 0x1000)
|
||||
#define NDIS_802_11_LENGTH_SSID 32
|
||||
#define A_SHA_DIGEST_LEN 20
|
||||
|
||||
|
||||
struct wlan_fast_reconnect {
|
||||
unsigned char psk_essid[NDIS_802_11_LENGTH_SSID + 4];
|
||||
unsigned char psk_passphrase[IW_PASSPHRASE_MAX_SIZE + 1];
|
||||
unsigned char wpa_global_PSK[A_SHA_DIGEST_LEN * 2];
|
||||
uint32_t channel;
|
||||
uint32_t security_type;
|
||||
#if ATCMD_VER == ATVER_2
|
||||
uint32_t enable;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
|
||||
typedef int (*wlan_init_done_ptr)(void);
|
||||
typedef int (*write_reconnect_ptr)(uint8_t *data, uint32_t len);
|
||||
|
||||
|
||||
//Variable
|
||||
extern unsigned char psk_essid[NET_IF_NUM][NDIS_802_11_LENGTH_SSID+4];
|
||||
extern unsigned char psk_passphrase[NET_IF_NUM][IW_PASSPHRASE_MAX_SIZE + 1];
|
||||
extern unsigned char wpa_global_PSK[NET_IF_NUM][A_SHA_DIGEST_LEN * 2];
|
||||
extern unsigned char psk_passphrase64[IW_PASSPHRASE_MAX_SIZE + 1];
|
||||
|
||||
//Function
|
||||
extern wlan_init_done_ptr p_wlan_init_done_callback;
|
||||
extern write_reconnect_ptr p_write_reconnect_ptr;
|
||||
|
||||
void example_wlan_fast_connect(void);
|
||||
|
||||
#endif //#ifndef __EXAMPLE_FAST_RECONNECTION_H__
|
6
component/common/file_system/fatfs/disk_if/inc/sdcard.h
Normal file
6
component/common/file_system/fatfs/disk_if/inc/sdcard.h
Normal file
|
@ -0,0 +1,6 @@
|
|||
#ifndef _SDCARD_H_
|
||||
#define _SDCARD_H_
|
||||
#include "fatfs_ext/inc/ff_driver.h"
|
||||
|
||||
extern ll_diskio_drv SD_disk_Driver;
|
||||
#endif
|
8
component/common/file_system/fatfs/disk_if/inc/usbdisk.h
Normal file
8
component/common/file_system/fatfs/disk_if/inc/usbdisk.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef _USBDISK_H_
|
||||
#define _USBDISK_H_
|
||||
|
||||
#include "fatfs_ext/inc/ff_driver.h"
|
||||
|
||||
extern ll_diskio_drv USB_disk_Driver;
|
||||
#endif
|
||||
|
134
component/common/file_system/fatfs/disk_if/src/sdcard.c
Normal file
134
component/common/file_system/fatfs/disk_if/src/sdcard.c
Normal file
|
@ -0,0 +1,134 @@
|
|||
/*
|
||||
* Routines to associate SD card driver with FatFs
|
||||
*
|
||||
* Copyright (c) 2014 Realtek Semiconductor Corp.
|
||||
*
|
||||
* This module is a confidential and proprietary property of RealTek and
|
||||
* possession or use of this module requires written permission of RealTek.
|
||||
*/
|
||||
#include "integer.h"
|
||||
#include <disk_if/inc/sdcard.h>
|
||||
|
||||
#if FATFS_DISK_SD
|
||||
|
||||
#include "sd.h" // sd card driver with sdio interface
|
||||
|
||||
#define SD_BLOCK_SIZE 512
|
||||
|
||||
static int interpret_sd_result(SD_RESULT result){
|
||||
int ret = 0;
|
||||
if(result == SD_OK)
|
||||
ret = 0;
|
||||
else if(result == SD_NODISK)
|
||||
ret = STA_NODISK;
|
||||
else if(result == SD_INITERR)
|
||||
ret = STA_NOINIT;
|
||||
else if(result == SD_PROTECTED)
|
||||
ret = STA_PROTECT;
|
||||
return ret;
|
||||
}
|
||||
|
||||
DSTATUS SD_disk_status(void){
|
||||
SD_RESULT res;
|
||||
res = SD_Status();
|
||||
return interpret_sd_result(res);;
|
||||
}
|
||||
|
||||
DSTATUS SD_disk_initialize(void){
|
||||
SD_RESULT res;
|
||||
res = SD_Init();
|
||||
return interpret_sd_result(res);
|
||||
}
|
||||
|
||||
/* Read sector(s) --------------------------------------------*/
|
||||
DRESULT SD_disk_read(BYTE *buff, DWORD sector, UINT count){
|
||||
SD_RESULT res;
|
||||
|
||||
res = SD_ReadBlocks(sector, buff, count);
|
||||
|
||||
//__rtl_memDump_v1_00(buff, 512*count, "MMC_disk_read:");
|
||||
|
||||
return interpret_sd_result(res);
|
||||
}
|
||||
|
||||
/* Write sector(s) --------------------------------------------*/
|
||||
#if _USE_WRITE == 1
|
||||
DRESULT SD_disk_write(const BYTE *buff, DWORD sector, UINT count){
|
||||
SD_RESULT res;
|
||||
|
||||
res = SD_WriteBlocks(sector, buff, count);
|
||||
|
||||
return interpret_sd_result(res);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Write sector(s) --------------------------------------------*/
|
||||
#if _USE_IOCTL == 1
|
||||
DRESULT SD_disk_ioctl (BYTE cmd, void* buff){
|
||||
DRESULT res = RES_ERROR;
|
||||
SD_RESULT result;
|
||||
DWORD last_blk_addr, block_size;
|
||||
|
||||
switch(cmd){
|
||||
/* Generic command (used by FatFs) */
|
||||
|
||||
/* Make sure that no pending write process in the physical drive */
|
||||
case CTRL_SYNC: /* Flush disk cache (for write functions) */
|
||||
result = SD_WaitReady();
|
||||
res = interpret_sd_result(result);
|
||||
break;
|
||||
case GET_SECTOR_COUNT: /* Get media size (for only f_mkfs()) */
|
||||
result = SD_GetCapacity((unsigned long*) buff);
|
||||
res = interpret_sd_result(result);
|
||||
break;
|
||||
/* for case _MAX_SS != _MIN_SS */
|
||||
case GET_SECTOR_SIZE: /* Get sector size (for multiple sector size (_MAX_SS >= 1024)) */
|
||||
//*(DWORD*)buff = 1024;//2048;//4096;
|
||||
res = RES_OK;
|
||||
break;
|
||||
case GET_BLOCK_SIZE: /* Get erase block size (for only f_mkfs()) */
|
||||
*(DWORD*)buff = SD_BLOCK_SIZE;
|
||||
res = RES_OK;
|
||||
break;
|
||||
case CTRL_ERASE_SECTOR:/* Force erased a block of sectors (for only _USE_ERASE) */
|
||||
res = RES_OK;
|
||||
break;
|
||||
|
||||
/* MMC/SDC specific ioctl command */
|
||||
|
||||
case MMC_GET_TYPE: /* Get card type */
|
||||
res = RES_OK;
|
||||
break;
|
||||
case MMC_GET_CSD: /* Get CSD */
|
||||
res = RES_OK;
|
||||
break;
|
||||
case MMC_GET_CID: /* Get CID */
|
||||
res = RES_OK;
|
||||
break;
|
||||
case MMC_GET_OCR: /* Get OCR */
|
||||
res = RES_OK;
|
||||
break;
|
||||
case MMC_GET_SDSTAT:/* Get SD status */
|
||||
res = RES_OK;
|
||||
break;
|
||||
default:
|
||||
res = RES_PARERR;
|
||||
break;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
#endif
|
||||
|
||||
ll_diskio_drv SD_disk_Driver ={
|
||||
.disk_initialize = SD_disk_initialize,
|
||||
.disk_status = SD_disk_status,
|
||||
.disk_read = SD_disk_read,
|
||||
#if _USE_WRITE == 1
|
||||
.disk_write = SD_disk_write,
|
||||
#endif
|
||||
#if _USE_IOCTL == 1
|
||||
.disk_ioctl = SD_disk_ioctl,
|
||||
#endif
|
||||
.TAG = "SD"
|
||||
};
|
||||
#endif
|
122
component/common/file_system/fatfs/disk_if/src/usbdisk.c
Normal file
122
component/common/file_system/fatfs/disk_if/src/usbdisk.c
Normal file
|
@ -0,0 +1,122 @@
|
|||
/*
|
||||
* Routines to associate usb mass storage driver with FatFs
|
||||
*
|
||||
* Copyright (c) 2014 Realtek Semiconductor Corp.
|
||||
*
|
||||
* This module is a confidential and proprietary property of RealTek and
|
||||
* possession or use of this module requires written permission of RealTek.
|
||||
*/
|
||||
#include "integer.h"
|
||||
#include <disk_if/inc/usbdisk.h>
|
||||
|
||||
#if FATFS_DISK_USB
|
||||
#include "us_intf.h"
|
||||
|
||||
DSTATUS USB_disk_status(void){
|
||||
MSC_RESULT res;
|
||||
if(USB_STORAGE_READY){
|
||||
res = us_getStatus();
|
||||
if(res == MSC_W_PROTECT)
|
||||
return STA_PROTECT;
|
||||
else
|
||||
return 0; // every thing is ok
|
||||
}
|
||||
return STA_NOINIT;
|
||||
}
|
||||
|
||||
DSTATUS USB_disk_initialize(void){
|
||||
MSC_RESULT res;
|
||||
|
||||
if(USB_STORAGE_READY)
|
||||
return 0;
|
||||
|
||||
res = us_init();
|
||||
|
||||
if(res == MSC_OK)
|
||||
return 0;
|
||||
else
|
||||
return STA_NOINIT;
|
||||
}
|
||||
|
||||
/* Read sector(s) --------------------------------------------*/
|
||||
DRESULT USB_disk_read(BYTE *buff, DWORD sector, UINT count){
|
||||
if(!USB_STORAGE_READY)
|
||||
return RES_NOTRDY;
|
||||
|
||||
if(us_read_blocks(buff, sector, count) == MSC_OK)
|
||||
return RES_OK;
|
||||
else
|
||||
return RES_ERROR;
|
||||
}
|
||||
|
||||
/* Write sector(s) --------------------------------------------*/
|
||||
#if _USE_WRITE == 1
|
||||
DRESULT USB_disk_write(const BYTE *buff, DWORD sector, UINT count){
|
||||
if(!USB_STORAGE_READY)
|
||||
return RES_NOTRDY;
|
||||
|
||||
if(us_write_blocks(buff, sector, count) == MSC_OK)
|
||||
return RES_OK;
|
||||
else
|
||||
return RES_ERROR;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Write sector(s) --------------------------------------------*/
|
||||
#if _USE_IOCTL == 1
|
||||
DRESULT USB_disk_ioctl (BYTE cmd, void* buff){
|
||||
DRESULT res = RES_ERROR;
|
||||
DWORD last_blk_addr, block_size;
|
||||
|
||||
if(!USB_STORAGE_READY)
|
||||
return RES_NOTRDY;
|
||||
|
||||
switch(cmd){
|
||||
/* Generic command (used by FatFs) */
|
||||
|
||||
case CTRL_SYNC: /* Flush disk cache (for write functions) */
|
||||
res = RES_OK;
|
||||
break;
|
||||
case GET_SECTOR_COUNT: /* Get media size (for only f_mkfs()) */
|
||||
if(us_getcap(&last_blk_addr, &block_size) == MSC_OK){
|
||||
*(DWORD*)buff = last_blk_addr + 1;
|
||||
res = RES_OK;
|
||||
}else
|
||||
res = RES_ERROR;
|
||||
break;
|
||||
case GET_SECTOR_SIZE: /* Get sector size (for multiple sector size (_MAX_SS >= 1024)) */
|
||||
if(us_getcap(&last_blk_addr, &block_size) == MSC_OK){
|
||||
*(DWORD*)buff = block_size;
|
||||
res = RES_OK;
|
||||
}else
|
||||
res = RES_ERROR;
|
||||
break;
|
||||
case GET_BLOCK_SIZE: /* Get erase block size (for only f_mkfs()) */
|
||||
*(DWORD*)buff = 512;
|
||||
res = RES_OK;
|
||||
break;
|
||||
case CTRL_ERASE_SECTOR:/* Force erased a block of sectors (for only _USE_ERASE) */
|
||||
res = RES_OK;
|
||||
break;
|
||||
default:
|
||||
res = RES_PARERR;
|
||||
break;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
#endif
|
||||
|
||||
ll_diskio_drv USB_disk_Driver ={
|
||||
.disk_initialize = USB_disk_initialize,
|
||||
.disk_status = USB_disk_status,
|
||||
.disk_read = USB_disk_read,
|
||||
#if _USE_WRITE == 1
|
||||
.disk_write = USB_disk_write,
|
||||
#endif
|
||||
#if _USE_IOCTL == 1
|
||||
.disk_ioctl = USB_disk_ioctl,
|
||||
#endif
|
||||
.TAG = "USB"
|
||||
};
|
||||
|
||||
#endif
|
34
component/common/file_system/fatfs/fatfs_ext/inc/ff_driver.h
Normal file
34
component/common/file_system/fatfs/fatfs_ext/inc/ff_driver.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __FF_DRIVER_H
|
||||
#define __FF_DRIVER_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "diskio.h"
|
||||
#include "ff.h"
|
||||
#include "platform_opts.h"
|
||||
|
||||
typedef struct{
|
||||
DSTATUS (*disk_initialize) (void); /*!< Initialize Disk Drive */
|
||||
DSTATUS (*disk_status) (void); /*!< Get Disk Status */
|
||||
DRESULT (*disk_read) (BYTE*, DWORD, UINT); /*!< Read Sector(s) */
|
||||
#if _USE_WRITE == 1
|
||||
DRESULT (*disk_write) (const BYTE*, DWORD, UINT); /*!< Write Sector(s) when _USE_WRITE = 0 */
|
||||
#endif /* _USE_WRITE == 1 */
|
||||
#if _USE_IOCTL == 1
|
||||
DRESULT (*disk_ioctl) (BYTE, void*); /*!< I/O control operation when _USE_IOCTL = 1 */
|
||||
#endif /* _USE_IOCTL == 1 */
|
||||
unsigned char* TAG;
|
||||
unsigned char drv_num;
|
||||
}ll_diskio_drv;
|
||||
|
||||
typedef struct{
|
||||
ll_diskio_drv *drv[_VOLUMES];
|
||||
unsigned int nbr;
|
||||
}ff_disk_drv;
|
||||
extern ff_disk_drv disk;
|
||||
|
||||
int FATFS_RegisterDiskDriver(ll_diskio_drv *disk_drv);
|
||||
int FATFS_UnRegisterDiskDriver(unsigned char drv_num);
|
||||
int FATFS_getDrivernum(unsigned char* TAG);
|
||||
|
||||
#endif
|
54
component/common/file_system/fatfs/fatfs_ext/src/ff_driver.c
Normal file
54
component/common/file_system/fatfs/fatfs_ext/src/ff_driver.c
Normal file
|
@ -0,0 +1,54 @@
|
|||
#include <fatfs_ext/inc/ff_driver.h>
|
||||
|
||||
ff_disk_drv disk = {0};
|
||||
|
||||
// return drv_num assigned
|
||||
int FATFS_RegisterDiskDriver(ll_diskio_drv *drv){
|
||||
unsigned char drv_num = -1;
|
||||
|
||||
if(disk.nbr < _VOLUMES)
|
||||
{
|
||||
drv->drv_num = disk.nbr; // record driver number for a specific disk
|
||||
disk.drv[disk.nbr] = drv;
|
||||
disk.nbr++;
|
||||
drv_num = drv->drv_num;
|
||||
}
|
||||
return drv_num;
|
||||
}
|
||||
|
||||
int FATFS_UnRegisterDiskDriver(unsigned char drv_num){
|
||||
int index;
|
||||
|
||||
if(disk.nbr >= 1)
|
||||
{
|
||||
for(index=0;index<disk.nbr;index++){
|
||||
if(disk.drv[index]->drv_num == drv_num){
|
||||
disk.drv[index] = 0;
|
||||
disk.nbr--;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return -1; // fail
|
||||
}
|
||||
return -1; // no disk driver registered
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Gets number of linked drivers to the FatFs module.
|
||||
* @param None
|
||||
* @retval Number of attached drivers.
|
||||
*/
|
||||
int FATFS_getDrivernum(unsigned char* TAG)
|
||||
{
|
||||
ll_diskio_drv *drv;
|
||||
int index;
|
||||
|
||||
for(index=0;index<disk.nbr;index++){
|
||||
drv = disk.drv[index];
|
||||
if(!strcmp(drv->TAG, TAG)){
|
||||
return drv->drv_num;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
29
component/common/file_system/fatfs/r0.10c/Makefile
Normal file
29
component/common/file_system/fatfs/r0.10c/Makefile
Normal file
|
@ -0,0 +1,29 @@
|
|||
|
||||
include $(MAKE_INCLUDE_GEN)
|
||||
|
||||
.PHONY: all clean
|
||||
|
||||
#*****************************************************************************#
|
||||
# Object FILE LIST #
|
||||
#*****************************************************************************#
|
||||
OBJS =
|
||||
|
||||
|
||||
#*****************************************************************************#
|
||||
# Dependency #
|
||||
#*****************************************************************************#
|
||||
-include $(OBJS:.o=.d)
|
||||
|
||||
#*****************************************************************************#
|
||||
# RULES TO GENERATE TARGETS #
|
||||
#*****************************************************************************#
|
||||
|
||||
# Define the Rules to build the core targets
|
||||
all: CORE_TARGETS
|
||||
make -C src all
|
||||
|
||||
#*****************************************************************************#
|
||||
# GENERATE OBJECT FILE
|
||||
#*****************************************************************************#
|
||||
CORE_TARGETS: $(OBJS)
|
||||
|
80
component/common/file_system/fatfs/r0.10c/include/diskio.h
Normal file
80
component/common/file_system/fatfs/r0.10c/include/diskio.h
Normal file
|
@ -0,0 +1,80 @@
|
|||
/*-----------------------------------------------------------------------/
|
||||
/ Low level disk interface modlue include file (C)ChaN, 2013 /
|
||||
/-----------------------------------------------------------------------*/
|
||||
|
||||
#ifndef _DISKIO_DEFINED
|
||||
#define _DISKIO_DEFINED
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define _USE_WRITE 1 /* 1: Enable disk_write function */
|
||||
#define _USE_IOCTL 1 /* 1: Enable disk_ioctl fucntion */
|
||||
|
||||
#include "integer.h"
|
||||
|
||||
|
||||
/* Status of Disk Functions */
|
||||
typedef BYTE DSTATUS;
|
||||
|
||||
/* Results of Disk Functions */
|
||||
typedef enum {
|
||||
RES_OK = 0, /* 0: Successful */
|
||||
RES_ERROR, /* 1: R/W Error */
|
||||
RES_WRPRT, /* 2: Write Protected */
|
||||
RES_NOTRDY, /* 3: Not Ready */
|
||||
RES_PARERR /* 4: Invalid Parameter */
|
||||
} DRESULT;
|
||||
|
||||
|
||||
/*---------------------------------------*/
|
||||
/* Prototypes for disk control functions */
|
||||
|
||||
|
||||
DSTATUS disk_initialize (BYTE pdrv);
|
||||
DSTATUS disk_status (BYTE pdrv);
|
||||
DRESULT disk_read (BYTE pdrv, BYTE* buff, DWORD sector, UINT count);
|
||||
DRESULT disk_write (BYTE pdrv, const BYTE* buff, DWORD sector, UINT count);
|
||||
DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff);
|
||||
|
||||
|
||||
/* Disk Status Bits (DSTATUS) */
|
||||
|
||||
#define STA_NOINIT 0x01 /* Drive not initialized */
|
||||
#define STA_NODISK 0x02 /* No medium in the drive */
|
||||
#define STA_PROTECT 0x04 /* Write protected */
|
||||
|
||||
|
||||
/* Command code for disk_ioctrl fucntion */
|
||||
|
||||
/* Generic command (used by FatFs) */
|
||||
#define CTRL_SYNC 0 /* Flush disk cache (for write functions) */
|
||||
#define GET_SECTOR_COUNT 1 /* Get media size (for only f_mkfs()) */
|
||||
#define GET_SECTOR_SIZE 2 /* Get sector size (for multiple sector size (_MAX_SS >= 1024)) */
|
||||
#define GET_BLOCK_SIZE 3 /* Get erase block size (for only f_mkfs()) */
|
||||
#define CTRL_ERASE_SECTOR 4 /* Force erased a block of sectors (for only _USE_ERASE) */
|
||||
|
||||
/* Generic command (not used by FatFs) */
|
||||
#define CTRL_POWER 5 /* Get/Set power status */
|
||||
#define CTRL_LOCK 6 /* Lock/Unlock media removal */
|
||||
#define CTRL_EJECT 7 /* Eject media */
|
||||
#define CTRL_FORMAT 8 /* Create physical format on the media */
|
||||
|
||||
/* MMC/SDC specific ioctl command */
|
||||
#define MMC_GET_TYPE 10 /* Get card type */
|
||||
#define MMC_GET_CSD 11 /* Get CSD */
|
||||
#define MMC_GET_CID 12 /* Get CID */
|
||||
#define MMC_GET_OCR 13 /* Get OCR */
|
||||
#define MMC_GET_SDSTAT 14 /* Get SD status */
|
||||
|
||||
/* ATA/CF specific ioctl command */
|
||||
#define ATA_GET_REV 20 /* Get F/W revision */
|
||||
#define ATA_GET_MODEL 21 /* Get model name */
|
||||
#define ATA_GET_SN 22 /* Get serial number */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
342
component/common/file_system/fatfs/r0.10c/include/ff.h
Normal file
342
component/common/file_system/fatfs/r0.10c/include/ff.h
Normal file
|
@ -0,0 +1,342 @@
|
|||
/*---------------------------------------------------------------------------/
|
||||
/ FatFs - FAT file system module include file R0.10b (C)ChaN, 2014
|
||||
/----------------------------------------------------------------------------/
|
||||
/ FatFs module is a generic FAT file system module for small embedded systems.
|
||||
/ This is a free software that opened for education, research and commercial
|
||||
/ developments under license policy of following terms.
|
||||
/
|
||||
/ Copyright (C) 2014, ChaN, all right reserved.
|
||||
/
|
||||
/ * The FatFs module is a free software and there is NO WARRANTY.
|
||||
/ * No restriction on use. You can use, modify and redistribute it for
|
||||
/ personal, non-profit or commercial product UNDER YOUR RESPONSIBILITY.
|
||||
/ * Redistributions of source code must retain the above copyright notice.
|
||||
/
|
||||
/----------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef _FATFS
|
||||
#define _FATFS 8051 /* Revision ID */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "integer.h" /* Basic integer types */
|
||||
#include "ffconf.h" /* FatFs configuration options */
|
||||
|
||||
#if _FATFS != _FFCONF
|
||||
#error Wrong configuration file (ffconf.h).
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* Definitions of volume management */
|
||||
|
||||
#if _MULTI_PARTITION /* Multiple partition configuration */
|
||||
typedef struct {
|
||||
BYTE pd; /* Physical drive number */
|
||||
BYTE pt; /* Partition: 0:Auto detect, 1-4:Forced partition) */
|
||||
} PARTITION;
|
||||
extern PARTITION VolToPart[]; /* Volume - Partition resolution table */
|
||||
#define LD2PD(vol) (VolToPart[vol].pd) /* Get physical drive number */
|
||||
#define LD2PT(vol) (VolToPart[vol].pt) /* Get partition index */
|
||||
|
||||
#else /* Single partition configuration */
|
||||
#define LD2PD(vol) (BYTE)(vol) /* Each logical drive is bound to the same physical drive number */
|
||||
#define LD2PT(vol) 0 /* Find first valid partition or in SFD */
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* Type of path name strings on FatFs API */
|
||||
|
||||
#if _LFN_UNICODE /* Unicode string */
|
||||
#if !_USE_LFN
|
||||
#error _LFN_UNICODE must be 0 at non-LFN cfg.
|
||||
#endif
|
||||
#ifndef _INC_TCHAR
|
||||
typedef WCHAR TCHAR;
|
||||
#define _T(x) L ## x
|
||||
#define _TEXT(x) L ## x
|
||||
#endif
|
||||
|
||||
#else /* ANSI/OEM string */
|
||||
#ifndef _INC_TCHAR
|
||||
typedef char TCHAR;
|
||||
#define _T(x) x
|
||||
#define _TEXT(x) x
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* File system object structure (FATFS) */
|
||||
|
||||
typedef struct {
|
||||
BYTE fs_type; /* FAT sub-type (0:Not mounted) */
|
||||
BYTE drv; /* Physical drive number */
|
||||
BYTE csize; /* Sectors per cluster (1,2,4...128) */
|
||||
BYTE n_fats; /* Number of FAT copies (1 or 2) */
|
||||
BYTE wflag; /* win[] flag (b0:dirty) */
|
||||
BYTE fsi_flag; /* FSINFO flags (b7:disabled, b0:dirty) */
|
||||
WORD id; /* File system mount ID */
|
||||
WORD n_rootdir; /* Number of root directory entries (FAT12/16) */
|
||||
#if _MAX_SS != _MIN_SS
|
||||
WORD ssize; /* Bytes per sector (512, 1024, 2048 or 4096) */
|
||||
#endif
|
||||
#if _FS_REENTRANT
|
||||
_SYNC_t sobj; /* Identifier of sync object */
|
||||
#endif
|
||||
#if !_FS_READONLY
|
||||
DWORD last_clust; /* Last allocated cluster */
|
||||
DWORD free_clust; /* Number of free clusters */
|
||||
#endif
|
||||
#if _FS_RPATH
|
||||
DWORD cdir; /* Current directory start cluster (0:root) */
|
||||
#endif
|
||||
DWORD n_fatent; /* Number of FAT entries, = number of clusters + 2 */
|
||||
DWORD fsize; /* Sectors per FAT */
|
||||
DWORD volbase; /* Volume start sector */
|
||||
DWORD fatbase; /* FAT start sector */
|
||||
DWORD dirbase; /* Root directory start sector (FAT32:Cluster#) */
|
||||
DWORD database; /* Data start sector */
|
||||
DWORD winsect; /* Current sector appearing in the win[] */
|
||||
BYTE win[_MAX_SS]; /* Disk access window for Directory, FAT (and file data at tiny cfg) */
|
||||
} FATFS;
|
||||
|
||||
|
||||
|
||||
/* File object structure (FIL) */
|
||||
|
||||
typedef struct {
|
||||
FATFS* fs; /* Pointer to the related file system object (**do not change order**) */
|
||||
WORD id; /* Owner file system mount ID (**do not change order**) */
|
||||
BYTE flag; /* Status flags */
|
||||
BYTE err; /* Abort flag (error code) */
|
||||
DWORD fptr; /* File read/write pointer (Zeroed on file open) */
|
||||
DWORD fsize; /* File size */
|
||||
DWORD sclust; /* File start cluster (0:no cluster chain, always 0 when fsize is 0) */
|
||||
DWORD clust; /* Current cluster of fpter (not valid when fprt is 0) */
|
||||
DWORD dsect; /* Sector number appearing in buf[] (0:invalid) */
|
||||
#if !_FS_READONLY
|
||||
DWORD dir_sect; /* Sector number containing the directory entry */
|
||||
BYTE* dir_ptr; /* Pointer to the directory entry in the win[] */
|
||||
#endif
|
||||
#if _USE_FASTSEEK
|
||||
DWORD* cltbl; /* Pointer to the cluster link map table (Nulled on file open) */
|
||||
#endif
|
||||
#if _FS_LOCK
|
||||
UINT lockid; /* File lock ID origin from 1 (index of file semaphore table Files[]) */
|
||||
#endif
|
||||
#if !_FS_TINY
|
||||
BYTE buf[_MAX_SS]; /* File private data read/write window */
|
||||
#endif
|
||||
} FIL;
|
||||
|
||||
|
||||
|
||||
/* Directory object structure (DIR) */
|
||||
|
||||
typedef struct {
|
||||
FATFS* fs; /* Pointer to the owner file system object (**do not change order**) */
|
||||
WORD id; /* Owner file system mount ID (**do not change order**) */
|
||||
WORD index; /* Current read/write index number */
|
||||
DWORD sclust; /* Table start cluster (0:Root dir) */
|
||||
DWORD clust; /* Current cluster */
|
||||
DWORD sect; /* Current sector */
|
||||
BYTE* dir; /* Pointer to the current SFN entry in the win[] */
|
||||
BYTE* fn; /* Pointer to the SFN (in/out) {file[8],ext[3],status[1]} */
|
||||
#if _FS_LOCK
|
||||
UINT lockid; /* File lock ID (index of file semaphore table Files[]) */
|
||||
#endif
|
||||
#if _USE_LFN
|
||||
WCHAR* lfn; /* Pointer to the LFN working buffer */
|
||||
WORD lfn_idx; /* Last matched LFN index number (0xFFFF:No LFN) */
|
||||
#endif
|
||||
} DIR;
|
||||
|
||||
|
||||
|
||||
/* File status structure (FILINFO) */
|
||||
|
||||
typedef struct {
|
||||
DWORD fsize; /* File size */
|
||||
WORD fdate; /* Last modified date */
|
||||
WORD ftime; /* Last modified time */
|
||||
BYTE fattrib; /* Attribute */
|
||||
TCHAR fname[13]; /* Short file name (8.3 format) */
|
||||
#if _USE_LFN
|
||||
TCHAR* lfname; /* Pointer to the LFN buffer */
|
||||
UINT lfsize; /* Size of LFN buffer in TCHAR */
|
||||
#endif
|
||||
} FILINFO;
|
||||
|
||||
|
||||
|
||||
/* File function return code (FRESULT) */
|
||||
|
||||
typedef enum {
|
||||
FR_OK = 0, /* (0) Succeeded */
|
||||
FR_DISK_ERR, /* (1) A hard error occurred in the low level disk I/O layer */
|
||||
FR_INT_ERR, /* (2) Assertion failed */
|
||||
FR_NOT_READY, /* (3) The physical drive cannot work */
|
||||
FR_NO_FILE, /* (4) Could not find the file */
|
||||
FR_NO_PATH, /* (5) Could not find the path */
|
||||
FR_INVALID_NAME, /* (6) The path name format is invalid */
|
||||
FR_DENIED, /* (7) Access denied due to prohibited access or directory full */
|
||||
FR_EXIST, /* (8) Access denied due to prohibited access */
|
||||
FR_INVALID_OBJECT, /* (9) The file/directory object is invalid */
|
||||
FR_WRITE_PROTECTED, /* (10) The physical drive is write protected */
|
||||
FR_INVALID_DRIVE, /* (11) The logical drive number is invalid */
|
||||
FR_NOT_ENABLED, /* (12) The volume has no work area */
|
||||
FR_NO_FILESYSTEM, /* (13) There is no valid FAT volume */
|
||||
FR_MKFS_ABORTED, /* (14) The f_mkfs() aborted due to any parameter error */
|
||||
FR_TIMEOUT, /* (15) Could not get a grant to access the volume within defined period */
|
||||
FR_LOCKED, /* (16) The operation is rejected according to the file sharing policy */
|
||||
FR_NOT_ENOUGH_CORE, /* (17) LFN working buffer could not be allocated */
|
||||
FR_TOO_MANY_OPEN_FILES, /* (18) Number of open files > _FS_SHARE */
|
||||
FR_INVALID_PARAMETER /* (19) Given parameter is invalid */
|
||||
} FRESULT;
|
||||
|
||||
|
||||
|
||||
/*--------------------------------------------------------------*/
|
||||
/* FatFs module application interface */
|
||||
|
||||
FRESULT f_open (FIL* fp, const TCHAR* path, BYTE mode); /* Open or create a file */
|
||||
FRESULT f_close (FIL* fp); /* Close an open file object */
|
||||
FRESULT f_read (FIL* fp, void* buff, UINT btr, UINT* br); /* Read data from a file */
|
||||
FRESULT f_write (FIL* fp, const void* buff, UINT btw, UINT* bw); /* Write data to a file */
|
||||
FRESULT f_forward (FIL* fp, UINT(*func)(const BYTE*,UINT), UINT btf, UINT* bf); /* Forward data to the stream */
|
||||
FRESULT f_lseek (FIL* fp, DWORD ofs); /* Move file pointer of a file object */
|
||||
FRESULT f_truncate (FIL* fp); /* Truncate file */
|
||||
FRESULT f_sync (FIL* fp); /* Flush cached data of a writing file */
|
||||
FRESULT f_opendir (DIR* dp, const TCHAR* path); /* Open a directory */
|
||||
FRESULT f_closedir (DIR* dp); /* Close an open directory */
|
||||
FRESULT f_readdir (DIR* dp, FILINFO* fno); /* Read a directory item */
|
||||
FRESULT f_mkdir (const TCHAR* path); /* Create a sub directory */
|
||||
FRESULT f_unlink (const TCHAR* path); /* Delete an existing file or directory */
|
||||
FRESULT f_rename (const TCHAR* path_old, const TCHAR* path_new); /* Rename/Move a file or directory */
|
||||
FRESULT f_stat (const TCHAR* path, FILINFO* fno); /* Get file status */
|
||||
FRESULT f_chmod (const TCHAR* path, BYTE value, BYTE mask); /* Change attribute of the file/dir */
|
||||
FRESULT f_utime (const TCHAR* path, const FILINFO* fno); /* Change times-tamp of the file/dir */
|
||||
FRESULT f_chdir (const TCHAR* path); /* Change current directory */
|
||||
FRESULT f_chdrive (const TCHAR* path); /* Change current drive */
|
||||
FRESULT f_getcwd (TCHAR* buff, UINT len); /* Get current directory */
|
||||
FRESULT f_getfree (const TCHAR* path, DWORD* nclst, FATFS** fatfs); /* Get number of free clusters on the drive */
|
||||
FRESULT f_getlabel (const TCHAR* path, TCHAR* label, DWORD* vsn); /* Get volume label */
|
||||
FRESULT f_setlabel (const TCHAR* label); /* Set volume label */
|
||||
FRESULT f_mount (FATFS* fs, const TCHAR* path, BYTE opt); /* Mount/Unmount a logical drive */
|
||||
FRESULT f_mkfs (const TCHAR* path, BYTE sfd, UINT au); /* Create a file system on the volume */
|
||||
FRESULT f_fdisk (BYTE pdrv, const DWORD szt[], void* work); /* Divide a physical drive into some partitions */
|
||||
int f_putc (TCHAR c, FIL* fp); /* Put a character to the file */
|
||||
int f_puts (const TCHAR* str, FIL* cp); /* Put a string to the file */
|
||||
int f_printf (FIL* fp, const TCHAR* str, ...); /* Put a formatted string to the file */
|
||||
TCHAR* f_gets (TCHAR* buff, int len, FIL* fp); /* Get a string from the file */
|
||||
|
||||
#define f_eof(fp) (((fp)->fptr == (fp)->fsize) ? 1 : 0)
|
||||
#define f_error(fp) ((fp)->err)
|
||||
#define f_tell(fp) ((fp)->fptr)
|
||||
#define f_size(fp) ((fp)->fsize)
|
||||
|
||||
#ifndef EOF
|
||||
#define EOF (-1)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
/*--------------------------------------------------------------*/
|
||||
/* Additional user defined functions */
|
||||
|
||||
/* RTC function */
|
||||
#if !_FS_READONLY
|
||||
DWORD get_fattime (void);
|
||||
#endif
|
||||
|
||||
/* Unicode support functions */
|
||||
#if _USE_LFN /* Unicode - OEM code conversion */
|
||||
WCHAR ff_convert (WCHAR chr, UINT dir); /* OEM-Unicode bidirectional conversion */
|
||||
WCHAR ff_wtoupper (WCHAR chr); /* Unicode upper-case conversion */
|
||||
#if _USE_LFN == 3 /* Memory functions */
|
||||
void* ff_memalloc (UINT msize); /* Allocate memory block */
|
||||
void ff_memfree (void* mblock); /* Free memory block */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Sync functions */
|
||||
#if _FS_REENTRANT
|
||||
int ff_cre_syncobj (BYTE vol, _SYNC_t* sobj); /* Create a sync object */
|
||||
int ff_req_grant (_SYNC_t sobj); /* Lock sync object */
|
||||
void ff_rel_grant (_SYNC_t sobj); /* Unlock sync object */
|
||||
int ff_del_syncobj (_SYNC_t sobj); /* Delete a sync object */
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
/*--------------------------------------------------------------*/
|
||||
/* Flags and offset address */
|
||||
|
||||
|
||||
/* File access control and file status flags (FIL.flag) */
|
||||
|
||||
#define FA_READ 0x01
|
||||
#define FA_OPEN_EXISTING 0x00
|
||||
|
||||
#if !_FS_READONLY
|
||||
#define FA_WRITE 0x02
|
||||
#define FA_CREATE_NEW 0x04
|
||||
#define FA_CREATE_ALWAYS 0x08
|
||||
#define FA_OPEN_ALWAYS 0x10
|
||||
#define FA__WRITTEN 0x20
|
||||
#define FA__DIRTY 0x40
|
||||
#endif
|
||||
|
||||
|
||||
/* FAT sub type (FATFS.fs_type) */
|
||||
|
||||
#define FS_FAT12 1
|
||||
#define FS_FAT16 2
|
||||
#define FS_FAT32 3
|
||||
|
||||
|
||||
/* File attribute bits for directory entry */
|
||||
|
||||
#define AM_RDO 0x01 /* Read only */
|
||||
#define AM_HID 0x02 /* Hidden */
|
||||
#define AM_SYS 0x04 /* System */
|
||||
#define AM_VOL 0x08 /* Volume label */
|
||||
#define AM_LFN 0x0F /* LFN entry */
|
||||
#define AM_DIR 0x10 /* Directory */
|
||||
#define AM_ARC 0x20 /* Archive */
|
||||
#define AM_MASK 0x3F /* Mask of defined bits */
|
||||
|
||||
|
||||
/* Fast seek feature */
|
||||
#define CREATE_LINKMAP 0xFFFFFFFF
|
||||
|
||||
|
||||
|
||||
/*--------------------------------*/
|
||||
/* Multi-byte word access macros */
|
||||
|
||||
#if _WORD_ACCESS == 1 /* Enable word access to the FAT structure */
|
||||
#define LD_WORD(ptr) (WORD)(*(WORD*)(BYTE*)(ptr))
|
||||
#define LD_DWORD(ptr) (DWORD)(*(DWORD*)(BYTE*)(ptr))
|
||||
#define ST_WORD(ptr,val) *(WORD*)(BYTE*)(ptr)=(WORD)(val)
|
||||
#define ST_DWORD(ptr,val) *(DWORD*)(BYTE*)(ptr)=(DWORD)(val)
|
||||
#else /* Use byte-by-byte access to the FAT structure */
|
||||
#define LD_WORD(ptr) (WORD)(((WORD)*((BYTE*)(ptr)+1)<<8)|(WORD)*(BYTE*)(ptr))
|
||||
#define LD_DWORD(ptr) (DWORD)(((DWORD)*((BYTE*)(ptr)+3)<<24)|((DWORD)*((BYTE*)(ptr)+2)<<16)|((WORD)*((BYTE*)(ptr)+1)<<8)|*(BYTE*)(ptr))
|
||||
#define ST_WORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8)
|
||||
#define ST_DWORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8); *((BYTE*)(ptr)+2)=(BYTE)((DWORD)(val)>>16); *((BYTE*)(ptr)+3)=(BYTE)((DWORD)(val)>>24)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _FATFS */
|
228
component/common/file_system/fatfs/r0.10c/include/ffconf.h
Normal file
228
component/common/file_system/fatfs/r0.10c/include/ffconf.h
Normal file
|
@ -0,0 +1,228 @@
|
|||
/*---------------------------------------------------------------------------/
|
||||
/ FatFs - FAT file system module configuration file R0.10b (C)ChaN, 2014
|
||||
/---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef _FFCONF
|
||||
#define _FFCONF 8051 /* Revision ID */
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------/
|
||||
/ Functions and Buffer Configurations
|
||||
/---------------------------------------------------------------------------*/
|
||||
|
||||
#define _FS_TINY 0 /* 0:Normal or 1:Tiny */
|
||||
/* When _FS_TINY is set to 1, it reduces memory consumption _MAX_SS bytes each
|
||||
/ file object. For file data transfer, FatFs uses the common sector buffer in
|
||||
/ the file system object (FATFS) instead of private sector buffer eliminated
|
||||
/ from the file object (FIL). */
|
||||
|
||||
|
||||
#define _FS_READONLY 0 /* 0:Read/Write or 1:Read only */
|
||||
/* Setting _FS_READONLY to 1 defines read only configuration. This removes
|
||||
/ writing functions, f_write(), f_sync(), f_unlink(), f_mkdir(), f_chmod(),
|
||||
/ f_rename(), f_truncate() and useless f_getfree(). */
|
||||
|
||||
|
||||
#define _FS_MINIMIZE 0 /* 0 to 3 */
|
||||
/* The _FS_MINIMIZE option defines minimization level to remove API functions.
|
||||
/
|
||||
/ 0: All basic functions are enabled.
|
||||
/ 1: f_stat(), f_getfree(), f_unlink(), f_mkdir(), f_chmod(), f_utime(),
|
||||
/ f_truncate() and f_rename() function are removed.
|
||||
/ 2: f_opendir(), f_readdir() and f_closedir() are removed in addition to 1.
|
||||
/ 3: f_lseek() function is removed in addition to 2. */
|
||||
|
||||
|
||||
#define _USE_STRFUNC 0 /* 0:Disable or 1-2:Enable */
|
||||
/* To enable string functions, set _USE_STRFUNC to 1 or 2. */
|
||||
|
||||
|
||||
#define _USE_MKFS 0 /* 0:Disable or 1:Enable */
|
||||
/* To enable f_mkfs() function, set _USE_MKFS to 1 and set _FS_READONLY to 0 */
|
||||
|
||||
|
||||
#define _USE_FASTSEEK 0 /* 0:Disable or 1:Enable */
|
||||
/* To enable fast seek feature, set _USE_FASTSEEK to 1. */
|
||||
|
||||
|
||||
#define _USE_LABEL 0 /* 0:Disable or 1:Enable */
|
||||
/* To enable volume label functions, set _USE_LAVEL to 1 */
|
||||
|
||||
|
||||
#define _USE_FORWARD 0 /* 0:Disable or 1:Enable */
|
||||
/* To enable f_forward() function, set _USE_FORWARD to 1 and set _FS_TINY to 1. */
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------/
|
||||
/ Locale and Namespace Configurations
|
||||
/---------------------------------------------------------------------------*/
|
||||
|
||||
#define _CODE_PAGE 437
|
||||
/* The _CODE_PAGE specifies the OEM code page to be used on the target system.
|
||||
/ Incorrect setting of the code page can cause a file open failure.
|
||||
/
|
||||
/ 932 - Japanese Shift_JIS (DBCS, OEM, Windows)
|
||||
/ 936 - Simplified Chinese GBK (DBCS, OEM, Windows)
|
||||
/ 949 - Korean (DBCS, OEM, Windows)
|
||||
/ 950 - Traditional Chinese Big5 (DBCS, OEM, Windows)
|
||||
/ 1250 - Central Europe (Windows)
|
||||
/ 1251 - Cyrillic (Windows)
|
||||
/ 1252 - Latin 1 (Windows)
|
||||
/ 1253 - Greek (Windows)
|
||||
/ 1254 - Turkish (Windows)
|
||||
/ 1255 - Hebrew (Windows)
|
||||
/ 1256 - Arabic (Windows)
|
||||
/ 1257 - Baltic (Windows)
|
||||
/ 1258 - Vietnam (OEM, Windows)
|
||||
/ 437 - U.S. (OEM)
|
||||
/ 720 - Arabic (OEM)
|
||||
/ 737 - Greek (OEM)
|
||||
/ 775 - Baltic (OEM)
|
||||
/ 850 - Multilingual Latin 1 (OEM)
|
||||
/ 858 - Multilingual Latin 1 + Euro (OEM)
|
||||
/ 852 - Latin 2 (OEM)
|
||||
/ 855 - Cyrillic (OEM)
|
||||
/ 866 - Russian (OEM)
|
||||
/ 857 - Turkish (OEM)
|
||||
/ 862 - Hebrew (OEM)
|
||||
/ 874 - Thai (OEM, Windows)
|
||||
/ 1 - ASCII (Valid for only non-LFN configuration) */
|
||||
|
||||
|
||||
#define _USE_LFN 1 /* 0 to 3 */
|
||||
#define _MAX_LFN 255 /* Maximum LFN length to handle (12 to 255) */
|
||||
/* The _USE_LFN option switches the LFN feature.
|
||||
/
|
||||
/ 0: Disable LFN feature. _MAX_LFN has no effect.
|
||||
/ 1: Enable LFN with static working buffer on the BSS. Always NOT thread-safe.
|
||||
/ 2: Enable LFN with dynamic working buffer on the STACK.
|
||||
/ 3: Enable LFN with dynamic working buffer on the HEAP.
|
||||
/
|
||||
/ When enable LFN feature, Unicode handling functions ff_convert() and ff_wtoupper()
|
||||
/ function must be added to the project.
|
||||
/ The LFN working buffer occupies (_MAX_LFN + 1) * 2 bytes. When use stack for the
|
||||
/ working buffer, take care on stack overflow. When use heap memory for the working
|
||||
/ buffer, memory management functions, ff_memalloc() and ff_memfree(), must be added
|
||||
/ to the project. */
|
||||
|
||||
|
||||
#define _LFN_UNICODE 0 /* 0:ANSI/OEM or 1:Unicode */
|
||||
/* To switch the character encoding on the FatFs API (TCHAR) to Unicode, enable LFN
|
||||
/ feature and set _LFN_UNICODE to 1. This option affects behavior of string I/O
|
||||
/ functions. This option must be 0 when LFN feature is not enabled. */
|
||||
|
||||
|
||||
#define _STRF_ENCODE 3 /* 0:ANSI/OEM, 1:UTF-16LE, 2:UTF-16BE, 3:UTF-8 */
|
||||
/* When Unicode API is enabled by _LFN_UNICODE option, this option selects the character
|
||||
/ encoding on the file to be read/written via string I/O functions, f_gets(), f_putc(),
|
||||
/ f_puts and f_printf(). This option has no effect when _LFN_UNICODE == 0. Note that
|
||||
/ FatFs supports only BMP. */
|
||||
|
||||
|
||||
#define _FS_RPATH 0 /* 0 to 2 */
|
||||
/* The _FS_RPATH option configures relative path feature.
|
||||
/
|
||||
/ 0: Disable relative path feature and remove related functions.
|
||||
/ 1: Enable relative path. f_chdrive() and f_chdir() function are available.
|
||||
/ 2: f_getcwd() function is available in addition to 1.
|
||||
/
|
||||
/ Note that output of the f_readdir() fnction is affected by this option. */
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------/
|
||||
/ Drive/Volume Configurations
|
||||
/---------------------------------------------------------------------------*/
|
||||
|
||||
#define _VOLUMES 1
|
||||
/* Number of volumes (logical drives) to be used. */
|
||||
|
||||
|
||||
#define _STR_VOLUME_ID 0 /* 0:Use only 0-9 for drive ID, 1:Use strings for drive ID */
|
||||
#define _VOLUME_STRS "RAM","NAND","CF","SD1","SD2","USB1","USB2","USB3"
|
||||
/* When _STR_VOLUME_ID is set to 1, also pre-defined strings can be used as drive
|
||||
/ number in the path name. _VOLUME_STRS defines the drive ID strings for each logical
|
||||
/ drives. Number of items must be equal to _VOLUMES. Valid characters for the drive ID
|
||||
/ strings are: 0-9 and A-Z. */
|
||||
|
||||
|
||||
#define _MULTI_PARTITION 0 /* 0:Single partition, 1:Enable multiple partition */
|
||||
/* By default(0), each logical drive number is bound to the same physical drive number
|
||||
/ and only a FAT volume found on the physical drive is mounted. When it is set to 1,
|
||||
/ each logical drive number is bound to arbitrary drive/partition listed in VolToPart[].
|
||||
*/
|
||||
|
||||
|
||||
#define _MIN_SS 512
|
||||
#define _MAX_SS 512
|
||||
/* These options configure the range of sector size to be supported. (512, 1024, 2048 or
|
||||
/ 4096) Always set both 512 for most systems, all memory card and harddisk. But a larger
|
||||
/ value may be required for on-board flash memory and some type of optical media.
|
||||
/ When _MAX_SS is larger than _MIN_SS, FatFs is configured to variable sector size and
|
||||
/ GET_SECTOR_SIZE command must be implemented to the disk_ioctl() function. */
|
||||
|
||||
|
||||
#define _USE_ERASE 0 /* 0:Disable or 1:Enable */
|
||||
/* To enable sector erase feature, set _USE_ERASE to 1. Also CTRL_ERASE_SECTOR command
|
||||
/ should be added to the disk_ioctl() function. */
|
||||
|
||||
|
||||
#define _FS_NOFSINFO 0 /* 0 to 3 */
|
||||
/* If you need to know correct free space on the FAT32 volume, set bit 0 of this option
|
||||
/ and f_getfree() function at first time after volume mount will force a full FAT scan.
|
||||
/ Bit 1 controls the last allocated cluster number as bit 0.
|
||||
/
|
||||
/ bit0=0: Use free cluster count in the FSINFO if available.
|
||||
/ bit0=1: Do not trust free cluster count in the FSINFO.
|
||||
/ bit1=0: Use last allocated cluster number in the FSINFO if available.
|
||||
/ bit1=1: Do not trust last allocated cluster number in the FSINFO.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------/
|
||||
/ System Configurations
|
||||
/---------------------------------------------------------------------------*/
|
||||
|
||||
#define _FS_LOCK 0 /* 0:Disable or >=1:Enable */
|
||||
/* To enable file lock control feature, set _FS_LOCK to non-zero value.
|
||||
/ The value defines how many files/sub-directories can be opened simultaneously
|
||||
/ with file lock control. This feature uses bss _FS_LOCK * 12 bytes. */
|
||||
|
||||
|
||||
#define _FS_REENTRANT 0 /* 0:Disable or 1:Enable */
|
||||
#define _FS_TIMEOUT 1000 /* Timeout period in unit of time tick */
|
||||
#define _SYNC_t HANDLE /* O/S dependent sync object type. e.g. HANDLE, OS_EVENT*, ID, SemaphoreHandle_t and etc.. */
|
||||
/* The _FS_REENTRANT option switches the re-entrancy (thread safe) of the FatFs module.
|
||||
/
|
||||
/ 0: Disable re-entrancy. _FS_TIMEOUT and _SYNC_t have no effect.
|
||||
/ 1: Enable re-entrancy. Also user provided synchronization handlers,
|
||||
/ ff_req_grant(), ff_rel_grant(), ff_del_syncobj() and ff_cre_syncobj()
|
||||
/ function must be added to the project.
|
||||
*/
|
||||
|
||||
|
||||
#define _WORD_ACCESS 0 /* 0 or 1 */
|
||||
/* The _WORD_ACCESS option is an only platform dependent option. It defines
|
||||
/ which access method is used to the word data on the FAT volume.
|
||||
/
|
||||
/ 0: Byte-by-byte access. Always compatible with all platforms.
|
||||
/ 1: Word access. Do not choose this unless under both the following conditions.
|
||||
/
|
||||
/ * Address misaligned memory access is always allowed for ALL instructions.
|
||||
/ * Byte order on the memory is little-endian.
|
||||
/
|
||||
/ If it is the case, _WORD_ACCESS can also be set to 1 to improve performance and
|
||||
/ reduce code size. Following table shows an example of some processor types.
|
||||
/
|
||||
/ ARM7TDMI 0 ColdFire 0 V850E 0
|
||||
/ Cortex-M3 0 Z80 0/1 V850ES 0/1
|
||||
/ Cortex-M0 0 RX600(LE) 0/1 TLCS-870 0/1
|
||||
/ AVR 0/1 RX600(BE) 0 TLCS-900 0/1
|
||||
/ AVR32 0 RL78 0 R32C 0
|
||||
/ PIC18 0/1 SH-2 0 M16C 0/1
|
||||
/ PIC24 0 H8S 0 MSP430 0
|
||||
/ PIC32 0 H8/300H 0 x86 0/1
|
||||
*/
|
||||
|
||||
|
||||
#endif /* _FFCONF */
|
34
component/common/file_system/fatfs/r0.10c/include/integer.h
Normal file
34
component/common/file_system/fatfs/r0.10c/include/integer.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*-------------------------------------------*/
|
||||
/* Integer type definitions for FatFs module */
|
||||
/*-------------------------------------------*/
|
||||
|
||||
#ifndef _FF_INTEGER
|
||||
#define _FF_INTEGER
|
||||
|
||||
#ifdef _WIN32 /* FatFs development platform */
|
||||
|
||||
#include <windows.h>
|
||||
#include <tchar.h>
|
||||
|
||||
#else /* Embedded platform */
|
||||
|
||||
/* This type MUST be 8 bit */
|
||||
typedef unsigned char BYTE;
|
||||
|
||||
/* These types MUST be 16 bit */
|
||||
typedef short SHORT;
|
||||
typedef unsigned short WORD;
|
||||
typedef unsigned short WCHAR;
|
||||
|
||||
/* These types MUST be 16 bit or 32 bit */
|
||||
typedef int INT;
|
||||
#undef UINT
|
||||
typedef unsigned int UINT;
|
||||
|
||||
/* These types MUST be 32 bit */
|
||||
typedef long LONG;
|
||||
typedef unsigned long DWORD;
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
32
component/common/file_system/fatfs/r0.10c/src/Makefile
Normal file
32
component/common/file_system/fatfs/r0.10c/src/Makefile
Normal file
|
@ -0,0 +1,32 @@
|
|||
|
||||
include $(MAKE_INCLUDE_GEN)
|
||||
|
||||
.PHONY: all clean
|
||||
|
||||
RT_USB_OTG_DIR = $(HWLIBDIR)/usb_otg/realtek/v3_0
|
||||
|
||||
MODULE_IFLAGS = -I$(RT_USB_OTG_DIR)/include/umsc
|
||||
MODULE_IFLAGS += -I../include
|
||||
|
||||
#*****************************************************************************#
|
||||
# Object FILE LIST #
|
||||
#*****************************************************************************#
|
||||
OBJS = ff.o diskio.o ff_driver.o
|
||||
|
||||
|
||||
#*****************************************************************************#
|
||||
# Dependency #
|
||||
#*****************************************************************************#
|
||||
-include $(OBJS:.o=.d)
|
||||
|
||||
#*****************************************************************************#
|
||||
# RULES TO GENERATE TARGETS #
|
||||
#*****************************************************************************#
|
||||
|
||||
# Define the Rules to build the core targets
|
||||
all: CORE_TARGETS COPY_RAM_OBJS
|
||||
|
||||
#*****************************************************************************#
|
||||
# GENERATE OBJECT FILE
|
||||
#*****************************************************************************#
|
||||
CORE_TARGETS: $(OBJS)
|
142
component/common/file_system/fatfs/r0.10c/src/diskio.c
Normal file
142
component/common/file_system/fatfs/r0.10c/src/diskio.c
Normal file
|
@ -0,0 +1,142 @@
|
|||
/*-----------------------------------------------------------------------*/
|
||||
/* Low level disk I/O module skeleton for FatFs (C)ChaN, 2014 */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* If a working storage control module is available, it should be */
|
||||
/* attached to the FatFs via a glue function rather than modifying it. */
|
||||
/* This is an example of glue functions to attach various exsisting */
|
||||
/* storage control modules to the FatFs module with a defined API. */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
#include "diskio.h" /* FatFs lower layer API */
|
||||
#include "fatfs_ext/inc/ff_driver.h"
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Get Drive Status */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
DSTATUS disk_status (
|
||||
BYTE pdrv /* Physical drive nmuber to identify the drive */
|
||||
)
|
||||
{
|
||||
DSTATUS stat = STA_NODISK;
|
||||
|
||||
if (disk.nbr <= 0 || pdrv < 0 || pdrv >= disk.nbr)
|
||||
return stat;
|
||||
|
||||
stat = disk.drv[pdrv]->disk_status();
|
||||
|
||||
return stat;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Inidialize a Drive */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
DSTATUS disk_initialize (
|
||||
BYTE pdrv /* Physical drive nmuber to identify the drive */
|
||||
)
|
||||
{
|
||||
DSTATUS stat = STA_NOINIT;
|
||||
|
||||
if (disk.nbr <= 0 || pdrv < 0 || pdrv >= disk.nbr)
|
||||
return stat;
|
||||
|
||||
stat = disk.drv[pdrv]->disk_initialize();
|
||||
|
||||
return stat;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Read Sector(s) */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
DRESULT disk_read (
|
||||
BYTE pdrv, /* Physical drive nmuber to identify the drive */
|
||||
BYTE *buff, /* Data buffer to store read data */
|
||||
DWORD sector, /* Sector address in LBA */
|
||||
UINT count /* Number of sectors to read */
|
||||
)
|
||||
{
|
||||
DRESULT res = RES_PARERR;
|
||||
|
||||
if (pdrv < 0 || pdrv >= disk.nbr || buff == (void*)0 || count <= 0)
|
||||
return RES_PARERR; // Return if the parameter is invalid
|
||||
|
||||
if(disk.nbr <= 0)
|
||||
return RES_NOTRDY;
|
||||
|
||||
res = disk.drv[pdrv]->disk_read(buff, sector, count);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Write Sector(s) */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
#if _USE_WRITE
|
||||
DRESULT disk_write (
|
||||
BYTE pdrv, /* Physical drive nmuber to identify the drive */
|
||||
const BYTE *buff, /* Data to be written */
|
||||
DWORD sector, /* Sector address in LBA */
|
||||
UINT count /* Number of sectors to write */
|
||||
)
|
||||
{
|
||||
DRESULT res = RES_PARERR;
|
||||
int index = 0;
|
||||
|
||||
if (pdrv < 0 || pdrv >= disk.nbr || buff == (void*)0 || count <= 0)
|
||||
return RES_PARERR; // Return if the parameter is invalid
|
||||
|
||||
if(disk.nbr <= 0)
|
||||
return RES_NOTRDY;
|
||||
|
||||
res = disk.drv[pdrv]->disk_write(buff, sector, count);
|
||||
|
||||
return res;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Miscellaneous Functions */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
#if _USE_IOCTL
|
||||
DRESULT disk_ioctl (
|
||||
BYTE pdrv, /* Physical drive nmuber (0..) */
|
||||
BYTE cmd, /* Control code */
|
||||
void *buff /* Buffer to send/receive control data */
|
||||
)
|
||||
{
|
||||
DRESULT res = RES_PARERR;
|
||||
|
||||
if (pdrv < 0 || pdrv >= disk.nbr)
|
||||
return RES_PARERR; // Return if the parameter is invalid
|
||||
|
||||
if(disk.nbr <= 0)
|
||||
return RES_NOTRDY;
|
||||
|
||||
res = disk.drv[pdrv]->disk_ioctl(cmd, buff);
|
||||
|
||||
return res;
|
||||
}
|
||||
#endif
|
||||
|
||||
DWORD get_fattime (void)
|
||||
{
|
||||
DWORD time_abs;
|
||||
|
||||
time_abs = ((DWORD)(2016 - 1980) << 25) /* Fixed to Feb. 2, 2016 */
|
||||
| ((DWORD)2 << 21)
|
||||
| ((DWORD)2 << 16)
|
||||
| ((DWORD)0 << 11)
|
||||
| ((DWORD)0 << 5)
|
||||
| ((DWORD)0 >> 1);
|
||||
|
||||
return time_abs;
|
||||
}
|
4597
component/common/file_system/fatfs/r0.10c/src/ff.c
Normal file
4597
component/common/file_system/fatfs/r0.10c/src/ff.c
Normal file
File diff suppressed because it is too large
Load diff
3829
component/common/file_system/fatfs/r0.10c/src/option/cc932.c
Normal file
3829
component/common/file_system/fatfs/r0.10c/src/option/cc932.c
Normal file
File diff suppressed because it is too large
Load diff
11004
component/common/file_system/fatfs/r0.10c/src/option/cc936.c
Normal file
11004
component/common/file_system/fatfs/r0.10c/src/option/cc936.c
Normal file
File diff suppressed because it is too large
Load diff
8634
component/common/file_system/fatfs/r0.10c/src/option/cc949.c
Normal file
8634
component/common/file_system/fatfs/r0.10c/src/option/cc949.c
Normal file
File diff suppressed because it is too large
Load diff
6860
component/common/file_system/fatfs/r0.10c/src/option/cc950.c
Normal file
6860
component/common/file_system/fatfs/r0.10c/src/option/cc950.c
Normal file
File diff suppressed because it is too large
Load diff
348
component/common/file_system/fatfs/r0.10c/src/option/ccsbcs.c
Normal file
348
component/common/file_system/fatfs/r0.10c/src/option/ccsbcs.c
Normal file
|
@ -0,0 +1,348 @@
|
|||
/*------------------------------------------------------------------------*/
|
||||
/* Unicode - Local code bidirectional converter (C)ChaN, 2015 */
|
||||
/* (SBCS code pages) */
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* 437 U.S.
|
||||
/ 720 Arabic
|
||||
/ 737 Greek
|
||||
/ 771 KBL
|
||||
/ 775 Baltic
|
||||
/ 850 Latin 1
|
||||
/ 852 Latin 2
|
||||
/ 855 Cyrillic
|
||||
/ 857 Turkish
|
||||
/ 860 Portuguese
|
||||
/ 861 Icelandic
|
||||
/ 862 Hebrew
|
||||
/ 863 Canadian French
|
||||
/ 864 Arabic
|
||||
/ 865 Nordic
|
||||
/ 866 Russian
|
||||
/ 869 Greek 2
|
||||
*/
|
||||
|
||||
#include "../include/ff.h"
|
||||
|
||||
|
||||
#if _CODE_PAGE == 437
|
||||
#define _TBLDEF 1
|
||||
static
|
||||
const WCHAR Tbl[] = { /* CP437(0x80-0xFF) to Unicode conversion table */
|
||||
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7, 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5,
|
||||
0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9, 0x00FF, 0x00D6, 0x00DC, 0x00A2, 0x00A3, 0x00A5, 0x20A7, 0x0192,
|
||||
0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA, 0x00BF, 0x2310, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB,
|
||||
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
|
||||
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
|
||||
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
|
||||
0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4, 0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2229,
|
||||
0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
|
||||
};
|
||||
|
||||
#elif _CODE_PAGE == 720
|
||||
#define _TBLDEF 1
|
||||
static
|
||||
const WCHAR Tbl[] = { /* CP720(0x80-0xFF) to Unicode conversion table */
|
||||
0x0000, 0x0000, 0x00E9, 0x00E2, 0x0000, 0x00E0, 0x0000, 0x00E7, 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x0000, 0x0000, 0x0000,
|
||||
0x0000, 0x0651, 0x0652, 0x00F4, 0x00A4, 0x0640, 0x00FB, 0x00F9, 0x0621, 0x0622, 0x0623, 0x0624, 0x00A3, 0x0625, 0x0626, 0x0627,
|
||||
0x0628, 0x0629, 0x062A, 0x062B, 0x062C, 0x062D, 0x062E, 0x062F, 0x0630, 0x0631, 0x0632, 0x0633, 0x0634, 0x0635, 0x00AB, 0x00BB,
|
||||
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
|
||||
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
|
||||
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
|
||||
0x0636, 0x0637, 0x0638, 0x0639, 0x063A, 0x0641, 0x00B5, 0x0642, 0x0643, 0x0644, 0x0645, 0x0646, 0x0647, 0x0648, 0x0649, 0x064A,
|
||||
0x2261, 0x064B, 0x064C, 0x064D, 0x064E, 0x064F, 0x0650, 0x2248, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
|
||||
};
|
||||
|
||||
#elif _CODE_PAGE == 737
|
||||
#define _TBLDEF 1
|
||||
static
|
||||
const WCHAR Tbl[] = { /* CP737(0x80-0xFF) to Unicode conversion table */
|
||||
0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397, 0x0398, 0x0399, 0x039A, 0x039B, 0x039C, 0x039D, 0x039E, 0x039F, 0x03A0,
|
||||
0x03A1, 0x03A3, 0x03A4, 0x03A5, 0x03A6, 0x03A7, 0x03A8, 0x03A9, 0x03B1, 0x03B2, 0x03B3, 0x03B4, 0x03B5, 0x03B6, 0x03B7, 0x03B8,
|
||||
0x03B9, 0x03BA, 0x03BB, 0x03BC, 0x03BD, 0x03BE, 0x03BF, 0x03C0, 0x03C1, 0x03C3, 0x03C2, 0x03C4, 0x03C5, 0x03C6, 0x03C7, 0x03C8,
|
||||
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
|
||||
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
|
||||
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
|
||||
0x03C9, 0x03AC, 0x03AD, 0x03AE, 0x03CA, 0x03AF, 0x03CC, 0x03CD, 0x03CB, 0x03CE, 0x0386, 0x0388, 0x0389, 0x038A, 0x038C, 0x038E,
|
||||
0x038F, 0x00B1, 0x2265, 0x2264, 0x03AA, 0x03AB, 0x00F7, 0x2248, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
|
||||
};
|
||||
|
||||
#elif _CODE_PAGE == 771
|
||||
#define _TBLDEF 1
|
||||
static
|
||||
const WCHAR Tbl[] = { /* CP771(0x80-0xFF) to Unicode conversion table */
|
||||
0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417, 0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F,
|
||||
0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427, 0x0428, 0x0429, 0x042A, 0x042B, 0x042C, 0x042D, 0x042E, 0x042F,
|
||||
0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437, 0x0438, 0x0439, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E, 0x043F,
|
||||
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x2558, 0x2510,
|
||||
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
|
||||
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x0104, 0x0105, 0x010C, 0x010D,
|
||||
0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447, 0x0448, 0x0449, 0x044A, 0x044B, 0x044C, 0x044D, 0x044E, 0x044F,
|
||||
0x0118, 0x0119, 0x0116, 0x0117, 0x012E, 0x012F, 0x0160, 0x0161, 0x0172, 0x0173, 0x016A, 0x016B, 0x017D, 0x017E, 0x25A0, 0x00A0
|
||||
};
|
||||
|
||||
#elif _CODE_PAGE == 775
|
||||
#define _TBLDEF 1
|
||||
static
|
||||
const WCHAR Tbl[] = { /* CP775(0x80-0xFF) to Unicode conversion table */
|
||||
0x0106, 0x00FC, 0x00E9, 0x0101, 0x00E4, 0x0123, 0x00E5, 0x0107, 0x0142, 0x0113, 0x0156, 0x0157, 0x012B, 0x0179, 0x00C4, 0x00C5,
|
||||
0x00C9, 0x00E6, 0x00C6, 0x014D, 0x00F6, 0x0122, 0x00A2, 0x015A, 0x015B, 0x00D6, 0x00DC, 0x00F8, 0x00A3, 0x00D8, 0x00D7, 0x00A4,
|
||||
0x0100, 0x012A, 0x00F3, 0x017B, 0x017C, 0x017A, 0x201D, 0x00A6, 0x00A9, 0x00AE, 0x00AC, 0x00BD, 0x00BC, 0x0141, 0x00AB, 0x00BB,
|
||||
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x0104, 0x010C, 0x0118, 0x0116, 0x2563, 0x2551, 0x2557, 0x255D, 0x012E, 0x0160, 0x2510,
|
||||
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x0172, 0x016A, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x017D,
|
||||
0x0105, 0x010D, 0x0119, 0x0117, 0x012F, 0x0161, 0x0173, 0x016B, 0x017E, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
|
||||
0x00D3, 0x00DF, 0x014C, 0x0143, 0x00F5, 0x00D5, 0x00B5, 0x0144, 0x0136, 0x0137, 0x013B, 0x013C, 0x0146, 0x0112, 0x0145, 0x2019,
|
||||
0x00AD, 0x00B1, 0x201C, 0x00BE, 0x00B6, 0x00A7, 0x00F7, 0x201E, 0x00B0, 0x2219, 0x00B7, 0x00B9, 0x00B3, 0x00B2, 0x25A0, 0x00A0
|
||||
};
|
||||
|
||||
#elif _CODE_PAGE == 850
|
||||
#define _TBLDEF 1
|
||||
static
|
||||
const WCHAR Tbl[] = { /* CP850(0x80-0xFF) to Unicode conversion table */
|
||||
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7, 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5,
|
||||
0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9, 0x00FF, 0x00D6, 0x00DC, 0x00F8, 0x00A3, 0x00D8, 0x00D7, 0x0192,
|
||||
0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA, 0x00BF, 0x00AE, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB,
|
||||
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x00C1, 0x00C2, 0x00C0, 0x00A9, 0x2563, 0x2551, 0x2557, 0x255D, 0x00A2, 0x00A5, 0x2510,
|
||||
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x00E3, 0x00C3, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x00A4,
|
||||
0x00F0, 0x00D0, 0x00CA, 0x00CB, 0x00C8, 0x0131, 0x00CD, 0x00CE, 0x00CF, 0x2518, 0x250C, 0x2588, 0x2584, 0x00A6, 0x00CC, 0x2580,
|
||||
0x00D3, 0x00DF, 0x00D4, 0x00D2, 0x00F5, 0x00D5, 0x00B5, 0x00FE, 0x00DE, 0x00DA, 0x00DB, 0x00D9, 0x00FD, 0x00DD, 0x00AF, 0x00B4,
|
||||
0x00AD, 0x00B1, 0x2017, 0x00BE, 0x00B6, 0x00A7, 0x00F7, 0x00B8, 0x00B0, 0x00A8, 0x00B7, 0x00B9, 0x00B3, 0x00B2, 0x25A0, 0x00A0
|
||||
};
|
||||
|
||||
#elif _CODE_PAGE == 852
|
||||
#define _TBLDEF 1
|
||||
static
|
||||
const WCHAR Tbl[] = { /* CP852(0x80-0xFF) to Unicode conversion table */
|
||||
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x016F, 0x0107, 0x00E7, 0x0142, 0x00EB, 0x0150, 0x0151, 0x00EE, 0x0179, 0x00C4, 0x0106,
|
||||
0x00C9, 0x0139, 0x013A, 0x00F4, 0x00F6, 0x013D, 0x013E, 0x015A, 0x015B, 0x00D6, 0x00DC, 0x0164, 0x0165, 0x0141, 0x00D7, 0x010D,
|
||||
0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x0104, 0x0105, 0x017D, 0x017E, 0x0118, 0x0119, 0x00AC, 0x017A, 0x010C, 0x015F, 0x00AB, 0x00BB,
|
||||
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x00C1, 0x00C2, 0x011A, 0x015E, 0x2563, 0x2551, 0x2557, 0x255D, 0x017B, 0x017C, 0x2510,
|
||||
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x0102, 0x0103, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x00A4,
|
||||
0x0111, 0x0110, 0x010E, 0x00CB, 0x010F, 0x0147, 0x00CD, 0x00CE, 0x011B, 0x2518, 0x250C, 0x2588, 0x2584, 0x0162, 0x016E, 0x2580,
|
||||
0x00D3, 0x00DF, 0x00D4, 0x0143, 0x0144, 0x0148, 0x0160, 0x0161, 0x0154, 0x00DA, 0x0155, 0x0170, 0x00FD, 0x00DD, 0x0163, 0x00B4,
|
||||
0x00AD, 0x02DD, 0x02DB, 0x02C7, 0x02D8, 0x00A7, 0x00F7, 0x00B8, 0x00B0, 0x00A8, 0x02D9, 0x0171, 0x0158, 0x0159, 0x25A0, 0x00A0
|
||||
};
|
||||
|
||||
#elif _CODE_PAGE == 855
|
||||
#define _TBLDEF 1
|
||||
static
|
||||
const WCHAR Tbl[] = { /* CP855(0x80-0xFF) to Unicode conversion table */
|
||||
0x0452, 0x0402, 0x0453, 0x0403, 0x0451, 0x0401, 0x0454, 0x0404, 0x0455, 0x0405, 0x0456, 0x0406, 0x0457, 0x0407, 0x0458, 0x0408,
|
||||
0x0459, 0x0409, 0x045A, 0x040A, 0x045B, 0x040B, 0x045C, 0x040C, 0x045E, 0x040E, 0x045F, 0x040F, 0x044E, 0x042E, 0x044A, 0x042A,
|
||||
0x0430, 0x0410, 0x0431, 0x0411, 0x0446, 0x0426, 0x0434, 0x0414, 0x0435, 0x0415, 0x0444, 0x0424, 0x0433, 0x0413, 0x00AB, 0x00BB,
|
||||
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x0445, 0x0425, 0x0438, 0x0418, 0x2563, 0x2551, 0x2557, 0x255D, 0x0439, 0x0419, 0x2510,
|
||||
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x043A, 0x041A, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x00A4,
|
||||
0x043B, 0x041B, 0x043C, 0x041C, 0x043D, 0x041D, 0x043E, 0x041E, 0x043F, 0x2518, 0x250C, 0x2588, 0x2584, 0x041F, 0x044F, 0x2580,
|
||||
0x042F, 0x0440, 0x0420, 0x0441, 0x0421, 0x0442, 0x0422, 0x0443, 0x0423, 0x0436, 0x0416, 0x0432, 0x0412, 0x044C, 0x042C, 0x2116,
|
||||
0x00AD, 0x044B, 0x042B, 0x0437, 0x0417, 0x0448, 0x0428, 0x044D, 0x042D, 0x0449, 0x0429, 0x0447, 0x0427, 0x00A7, 0x25A0, 0x00A0
|
||||
};
|
||||
|
||||
#elif _CODE_PAGE == 857
|
||||
#define _TBLDEF 1
|
||||
static
|
||||
const WCHAR Tbl[] = { /* CP857(0x80-0xFF) to Unicode conversion table */
|
||||
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7, 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x0131, 0x00C4, 0x00C5,
|
||||
0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9, 0x0130, 0x00D6, 0x00DC, 0x00F8, 0x00A3, 0x00D8, 0x015E, 0x015F,
|
||||
0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x011E, 0x011F, 0x00BF, 0x00AE, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB,
|
||||
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x00C1, 0x00C2, 0x00C0, 0x00A9, 0x2563, 0x2551, 0x2557, 0x255D, 0x00A2, 0x00A5, 0x2510,
|
||||
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x00E3, 0x00C3, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x00A4,
|
||||
0x00BA, 0x00AA, 0x00CA, 0x00CB, 0x00C8, 0x0000, 0x00CD, 0x00CE, 0x00CF, 0x2518, 0x250C, 0x2588, 0x2584, 0x00A6, 0x00CC, 0x2580,
|
||||
0x00D3, 0x00DF, 0x00D4, 0x00D2, 0x00F5, 0x00D5, 0x00B5, 0x0000, 0x00D7, 0x00DA, 0x00DB, 0x00D9, 0x00EC, 0x00FF, 0x00AF, 0x00B4,
|
||||
0x00AD, 0x00B1, 0x0000, 0x00BE, 0x00B6, 0x00A7, 0x00F7, 0x00B8, 0x00B0, 0x00A8, 0x00B7, 0x00B9, 0x00B3, 0x00B2, 0x25A0, 0x00A0
|
||||
};
|
||||
|
||||
#elif _CODE_PAGE == 860
|
||||
#define _TBLDEF 1
|
||||
static
|
||||
const WCHAR Tbl[] = { /* CP860(0x80-0xFF) to Unicode conversion table */
|
||||
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E3, 0x00E0, 0x00C1, 0x00E7, 0x00EA, 0x00CA, 0x00E8, 0x00CD, 0x00D4, 0x00EC, 0x00C3, 0x00C2,
|
||||
0x00C9, 0x00C0, 0x00C8, 0x00F4, 0x00F5, 0x00F2, 0x00DA, 0x00F9, 0x00CC, 0x00D5, 0x00DC, 0x00A2, 0x00A3, 0x00D9, 0x20A7, 0x00D3,
|
||||
0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA, 0x00BF, 0x00D2, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB,
|
||||
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x2558, 0x2510,
|
||||
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
|
||||
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
|
||||
0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4, 0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2229,
|
||||
0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
|
||||
};
|
||||
|
||||
#elif _CODE_PAGE == 861
|
||||
#define _TBLDEF 1
|
||||
static
|
||||
const WCHAR Tbl[] = { /* CP861(0x80-0xFF) to Unicode conversion table */
|
||||
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E6, 0x00E7, 0x00EA, 0x00EB, 0x00E8, 0x00D0, 0x00F0, 0x00DE, 0x00C4, 0x00C5,
|
||||
0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00FE, 0x00FB, 0x00DD, 0x00FD, 0x00D6, 0x00DC, 0x00F8, 0x00A3, 0x00D8, 0x20A7, 0x0192,
|
||||
0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00C1, 0x00CD, 0x00D3, 0x00DA, 0x00BF, 0x2310, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB,
|
||||
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
|
||||
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
|
||||
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
|
||||
0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4, 0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2229,
|
||||
0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
|
||||
};
|
||||
|
||||
#elif _CODE_PAGE == 862
|
||||
#define _TBLDEF 1
|
||||
static
|
||||
const WCHAR Tbl[] = { /* CP862(0x80-0xFF) to Unicode conversion table */
|
||||
0x05D0, 0x05D1, 0x05D2, 0x05D3, 0x05D4, 0x05D5, 0x05D6, 0x05D7, 0x05D8, 0x05D9, 0x05DA, 0x05DB, 0x05DC, 0x05DD, 0x05DE, 0x05DF,
|
||||
0x05E0, 0x05E1, 0x05E2, 0x05E3, 0x05E4, 0x05E5, 0x05E6, 0x05E7, 0x05E8, 0x05E9, 0x05EA, 0x00A2, 0x00A3, 0x00A5, 0x20A7, 0x0192,
|
||||
0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA, 0x00BF, 0x2310, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB,
|
||||
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
|
||||
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
|
||||
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
|
||||
0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4, 0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2229,
|
||||
0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
|
||||
};
|
||||
|
||||
#elif _CODE_PAGE == 863
|
||||
#define _TBLDEF 1
|
||||
static
|
||||
const WCHAR Tbl[] = { /* CP863(0x80-0xFF) to Unicode conversion table */
|
||||
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00C2, 0x00E0, 0x00B6, 0x00E7, 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x2017, 0x00C0,
|
||||
0x00C9, 0x00C8, 0x00CA, 0x00F4, 0x00CB, 0x00CF, 0x00FB, 0x00F9, 0x00A4, 0x00D4, 0x00DC, 0x00A2, 0x00A3, 0x00D9, 0x00DB, 0x0192,
|
||||
0x00A6, 0x00B4, 0x00F3, 0x00FA, 0x00A8, 0x00BB, 0x00B3, 0x00AF, 0x00CE, 0x3210, 0x00AC, 0x00BD, 0x00BC, 0x00BE, 0x00AB, 0x00BB,
|
||||
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
|
||||
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
|
||||
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
|
||||
0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4, 0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2219,
|
||||
0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
|
||||
};
|
||||
|
||||
#elif _CODE_PAGE == 864
|
||||
#define _TBLDEF 1
|
||||
static
|
||||
const WCHAR Tbl[] = { /* CP864(0x80-0xFF) to Unicode conversion table */
|
||||
0x00B0, 0x00B7, 0x2219, 0x221A, 0x2592, 0x2500, 0x2502, 0x253C, 0x2524, 0x252C, 0x251C, 0x2534, 0x2510, 0x250C, 0x2514, 0x2518,
|
||||
0x03B2, 0x221E, 0x03C6, 0x00B1, 0x00BD, 0x00BC, 0x2248, 0x00AB, 0x00BB, 0xFEF7, 0xFEF8, 0x0000, 0x0000, 0xFEFB, 0xFEFC, 0x0000,
|
||||
0x00A0, 0x00AD, 0xFE82, 0x00A3, 0x00A4, 0xFE84, 0x0000, 0x20AC, 0xFE8E, 0xFE8F, 0xFE95, 0xFE99, 0x060C, 0xFE9D, 0xFEA1, 0xFEA5,
|
||||
0x0660, 0x0661, 0x0662, 0x0663, 0x0664, 0x0665, 0x0666, 0x0667, 0x0668, 0x0669, 0xFED1, 0x061B, 0xFEB1, 0xFEB5, 0xFEB9, 0x061F,
|
||||
0x00A2, 0xFE80, 0xFE81, 0xFE83, 0xFE85, 0xFECA, 0xFE8B, 0xFE8D, 0xFE91, 0xFE93, 0xFE97, 0xFE9B, 0xFE9F, 0xFEA3, 0xFEA7, 0xFEA9,
|
||||
0xFEAB, 0xFEAD, 0xFEAF, 0xFEB3, 0xFEB7, 0xFEBB, 0xFEBF, 0xFEC1, 0xFEC5, 0xFECB, 0xFECF, 0x00A6, 0x00AC, 0x00F7, 0x00D7, 0xFEC9,
|
||||
0x0640, 0xFED3, 0xFED7, 0xFEDB, 0xFEDF, 0xFEE3, 0xFEE7, 0xFEEB, 0xFEED, 0xFEEF, 0xFEF3, 0xFEBD, 0xFECC, 0xFECE, 0xFECD, 0xFEE1,
|
||||
0xFE7D, 0x0651, 0xFEE5, 0xFEE9, 0xFEEC, 0xFEF0, 0xFEF2, 0xFED0, 0xFED5, 0xFEF5, 0xFEF6, 0xFEDD, 0xFED9, 0xFEF1, 0x25A0, 0x0000
|
||||
};
|
||||
|
||||
#elif _CODE_PAGE == 865
|
||||
#define _TBLDEF 1
|
||||
static
|
||||
const WCHAR Tbl[] = { /* CP865(0x80-0xFF) to Unicode conversion table */
|
||||
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7, 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5,
|
||||
0x00C5, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9, 0x00FF, 0x00D6, 0x00DC, 0x00F8, 0x00A3, 0x00D8, 0x20A7, 0x0192,
|
||||
0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA, 0x00BF, 0x2310, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00A4,
|
||||
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x2558, 0x2510,
|
||||
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
|
||||
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
|
||||
0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4, 0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2229,
|
||||
0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
|
||||
};
|
||||
|
||||
#elif _CODE_PAGE == 866
|
||||
#define _TBLDEF 1
|
||||
static
|
||||
const WCHAR Tbl[] = { /* CP866(0x80-0xFF) to Unicode conversion table */
|
||||
0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417, 0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F,
|
||||
0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427, 0x0428, 0x0429, 0x042A, 0x042B, 0x042C, 0x042D, 0x042E, 0x042F,
|
||||
0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437, 0x0438, 0x0439, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E, 0x043F,
|
||||
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
|
||||
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
|
||||
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
|
||||
0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447, 0x0448, 0x0449, 0x044A, 0x044B, 0x044C, 0x044D, 0x044E, 0x044F,
|
||||
0x0401, 0x0451, 0x0404, 0x0454, 0x0407, 0x0457, 0x040E, 0x045E, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x2116, 0x00A4, 0x25A0, 0x00A0
|
||||
};
|
||||
|
||||
#elif _CODE_PAGE == 869
|
||||
#define _TBLDEF 1
|
||||
static
|
||||
const WCHAR Tbl[] = { /* CP869(0x80-0xFF) to Unicode conversion table */
|
||||
0x00B7, 0x00B7, 0x00B7, 0x00B7, 0x00B7, 0x00B7, 0x0386, 0x00B7, 0x00B7, 0x00AC, 0x00A6, 0x2018, 0x2019, 0x0388, 0x2015, 0x0389,
|
||||
0x038A, 0x03AA, 0x038C, 0x00B7, 0x00B7, 0x038E, 0x03AB, 0x00A9, 0x038F, 0x00B2, 0x00B3, 0x03AC, 0x00A3, 0x03AD, 0x03AE, 0x03AF,
|
||||
0x03CA, 0x0390, 0x03CC, 0x03CD, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397, 0x00BD, 0x0398, 0x0399, 0x00AB, 0x00BB,
|
||||
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x039A, 0x039B, 0x039C, 0x039D, 0x2563, 0x2551, 0x2557, 0x255D, 0x039E, 0x039F, 0x2510,
|
||||
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x0A30, 0x03A1, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x03A3,
|
||||
0x03A4, 0x03A5, 0x03A6, 0x03A7, 0x03A8, 0x03A9, 0x03B1, 0x03B2, 0x03B3, 0x2518, 0x250C, 0x2588, 0x2584, 0x03B4, 0x03B5, 0x2580,
|
||||
0x03B6, 0x03B7, 0x03B8, 0x03B9, 0x03BA, 0x03BB, 0x03BC, 0x03BD, 0x03BE, 0x03BF, 0x03C0, 0x03C1, 0x03C3, 0x03C2, 0x03C4, 0x0384,
|
||||
0x00AD, 0x00B1, 0x03C5, 0x03C6, 0x03C7, 0x00A7, 0x03C8, 0x0385, 0x00B0, 0x00A8, 0x03C9, 0x03CB, 0x03B0, 0x03CE, 0x25A0, 0x00A0
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if !_TBLDEF || !_USE_LFN
|
||||
#error This file is not needed at current configuration. Remove from the project.
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
WCHAR ff_convert ( /* Converted character, Returns zero on error */
|
||||
WCHAR chr, /* Character code to be converted */
|
||||
UINT dir /* 0: Unicode to OEM code, 1: OEM code to Unicode */
|
||||
)
|
||||
{
|
||||
WCHAR c;
|
||||
|
||||
|
||||
if (chr < 0x80) { /* ASCII */
|
||||
c = chr;
|
||||
|
||||
} else {
|
||||
if (dir) { /* OEM code to Unicode */
|
||||
c = (chr >= 0x100) ? 0 : Tbl[chr - 0x80];
|
||||
|
||||
} else { /* Unicode to OEM code */
|
||||
for (c = 0; c < 0x80; c++) {
|
||||
if (chr == Tbl[c]) break;
|
||||
}
|
||||
c = (c + 0x80) & 0xFF;
|
||||
}
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
WCHAR ff_wtoupper ( /* Returns upper converted character */
|
||||
WCHAR chr /* Unicode character to be upper converted */
|
||||
)
|
||||
{
|
||||
static const WCHAR lower[] = { /* Lower case characters to be converted */
|
||||
/* Latin Supplement */ 0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF,
|
||||
/* Latin Extended-A */ 0x101,0x103,0x105,0x107,0x109,0x10B,0x10D,0x10F,0x111,0x113,0x115,0x117,0x119,0x11B,0x11D,0x11F,0x121,0x123,0x125,0x127,0x129,0x12B,0x12D,0x12F,0x131,0x133,0x135,0x137,0x13A,0x13C,0x13E,0x140,0x142,0x144,0x146,0x148,0x14B,0x14D,0x14F,0x151,0x153,0x155,0x157,0x159,0x15B,0x15D,0x15F,0x161,0x163,0x165,0x167,0x169,0x16B,0x16D,0x16F,0x171,0x173,0x175,0x177,0x17A,0x17C,0x17E,
|
||||
/* Latin Extended-B */ 0x183,0x185,0x188,0x18C,0x192,0x199,0x1A1,0x1A3,0x1A8,0x1AD,0x1B0,0x1B4,0x1B6,0x1B9,0x1BD,0x1C6,0x1C9,0x1CC,0x1CE,0x1D0,0x1D2,0x1D4,0x1D6,0x1D8,0x1DA,0x1DC,0x1DD,0x1DF,0x1E1,0x1E3,0x1E5,0x1E7,0x1E9,0x1EB,0x1ED,0x1EF,0x1F3,0x1F5,0x1FB,0x1FD,0x1FF,0x201,0x203,0x205,0x207,0x209,0x20B,0x20D,0x20F,0x211,0x213,0x215,0x217,
|
||||
/* Greek, Coptic */ 0x3B1,0x3B2,0x3B3,0x3B4,0x3B5,0x3B6,0x3B7,0x3B8,0x3B9,0x3BA,0x3BB,0x3BC,0x3BD,0x3BE,0x3BF,0x3C0,0x3C1,0x3C3,0x3C4,0x3C5,0x3C6,0x3C7,0x3C8,0x3C9,0x3CA,0x3CB,0x3CC,0x3CD,0x3CE,0x3E3,0x3E5,0x3E7,0x3E9,0x3EB,
|
||||
/* Cyrillic */ 0x430,0x431,0x432,0x433,0x434,0x435,0x436,0x437,0x438,0x439,0x43A,0x43B,0x43C,0x43D,0x43E,0x43F,0x440,0x441,0x442,0x443,0x444,0x445,0x446,0x447,0x448,0x449,0x44A,0x44B,0x44C,0x44D,0x44E,0x44F,0x452,0x453,0x454,0x455,0x456,0x457,0x458,0x459,0x45A,0x45B,0x45C,0x45E,0x45F,0x461,0x463,0x465,0x467,0x469,0x46B,0x46D,0x46F,0x471,0x473,0x475,0x477,0x479,0x47B,0x47D,0x47F,0x481,0x491,0x493,0x495,0x497,0x499,0x49B,0x49D,0x49F,0x4A1,0x4A3,0x4A5,0x4A7,0x4A9,0x4AB,0x4AD,0x4AF,0x4B1,0x4B3,0x4B5,0x4B7,0x4B9,0x4BB,0x4BD,0x4BF,0x4C2,0x4C4,0x4C8,0x4D1,0x4D3,0x4D5,0x4D7,0x4D9,0x4DB,0x4DD,0x4DF,0x4E1,0x4E3,0x4E5,0x4E7,0x4E9,0x4EB,0x4ED,0x4EF,0x4F1,0x4F3,0x4F5,0x4F9,
|
||||
/* Armenian */ 0x561,0x562,0x563,0x564,0x565,0x566,0x567,0x568,0x569,0x56A,0x56B,0x56C,0x56D,0x56E,0x56F,0x570,0x571,0x572,0x573,0x574,0x575,0x576,0x577,0x578,0x579,0x57A,0x57B,0x57C,0x57D,0x57E,0x57F,0x580,0x581,0x582,0x583,0x584,0x585,0x586,
|
||||
/* Latin Extended Additional */ 0x1E01,0x1E03,0x1E05,0x1E07,0x1E09,0x1E0B,0x1E0D,0x1E0F,0x1E11,0x1E13,0x1E15,0x1E17,0x1E19,0x1E1B,0x1E1D,0x1E1F,0x1E21,0x1E23,0x1E25,0x1E27,0x1E29,0x1E2B,0x1E2D,0x1E2F,0x1E31,0x1E33,0x1E35,0x1E37,0x1E39,0x1E3B,0x1E3D,0x1E3F,0x1E41,0x1E43,0x1E45,0x1E47,0x1E49,0x1E4B,0x1E4D,0x1E4F,0x1E51,0x1E53,0x1E55,0x1E57,0x1E59,0x1E5B,0x1E5D,0x1E5F,0x1E61,0x1E63,0x1E65,0x1E67,0x1E69,0x1E6B,0x1E6D,0x1E6F,0x1E71,0x1E73,0x1E75,0x1E77,0x1E79,0x1E7B,0x1E7D,0x1E7F,0x1E81,0x1E83,0x1E85,0x1E87,0x1E89,0x1E8B,0x1E8D,0x1E8F,0x1E91,0x1E93,0x1E95,0x1E97,0x1E99,0x1E9B,0x1E9D,0x1E9F,0x1EA1,0x1EA3,0x1EA5,0x1EA7,0x1EA9,0x1EAB,0x1EAD,0x1EAF,0x1EB1,0x1EB3,0x1EB5,0x1EB7,0x1EB9,0x1EBB,0x1EBD,0x1EBF,0x1EC1,0x1EC3,0x1EC5,0x1EC7,0x1EC9,0x1ECB,0x1ECD,0x1ECF,0x1ED1,0x1ED3,0x1ED5,0x1ED7,0x1ED9,0x1EDB,0x1EDD,0x1EDF,0x1EE1,0x1EE3,0x1EE5,0x1EE7,0x1EE9,0x1EEB,0x1EED,0x1EEF,0x1EF1,0x1EF3,0x1EF5,0x1EF7,0x1EF9,
|
||||
/* Number forms */ 0x2170,0x2171,0x2172,0x2173,0x2174,0x2175,0x2176,0x2177,0x2178,0x2179,0x217A,0x217B,0x217C,0x217D,0x217E,0x217F,
|
||||
/* Full-width */ 0xFF41,0xFF42,0xFF43,0xFF44,0xFF45,0xFF46,0xFF47,0xFF48,0xFF49,0xFF4A,0xFF4B,0xFF4C,0xFF4D,0xFF4E,0xFF4F,0xFF50,0xFF51,0xFF52,0xFF53,0xFF54,0xFF55,0xFF56,0xFF57,0xFF58,0xFF59,0xFF5A
|
||||
};
|
||||
static const WCHAR upper[] = { /* Upper case characters correspond to lower[] */
|
||||
0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0x178,
|
||||
0x100,0x102,0x104,0x106,0x108,0x10A,0x10C,0x10E,0x110,0x112,0x114,0x116,0x118,0x11A,0x11C,0x11E,0x120,0x122,0x124,0x126,0x128,0x12A,0x12C,0x12E,0x130,0x132,0x134,0x136,0x139,0x13B,0x13D,0x13F,0x141,0x143,0x145,0x147,0x14A,0x14C,0x14E,0x150,0x152,0x154,0x156,0x158,0x15A,0x15C,0x15E,0x160,0x162,0x164,0x166,0x168,0x16A,0x16C,0x16E,0x170,0x172,0x174,0x176,0x179,0x17B,0x17D,
|
||||
0x182,0x184,0x187,0x18B,0x191,0x198,0x1A0,0x1A2,0x1A7,0x1AC,0x1AF,0x1B3,0x1B5,0x1B8,0x1BC,0x1C4,0x1C7,0x1CA,0x1CD,0x1CF,0x1D1,0x1D3,0x1D5,0x1D7,0x1D9,0x1DB,0x18E,0x1DE,0x1E0,0x1E2,0x1E4,0x1E6,0x1E8,0x1EA,0x1EC,0x1EE,0x1F1,0x1F4,0x1FA,0x1FC,0x1FE,0x200,0x202,0x204,0x206,0x208,0x20A,0x20C,0x20E,0x210,0x212,0x214,0x216,
|
||||
0x391,0x392,0x393,0x394,0x395,0x396,0x397,0x398,0x399,0x39A,0x39B,0x39C,0x39D,0x39E,0x39F,0x3A0,0x3A1,0x3A3,0x3A4,0x3A5,0x3A6,0x3A7,0x3A8,0x3A9,0x3AA,0x3AB,0x38C,0x38E,0x38F,0x3E2,0x3E4,0x3E6,0x3E8,0x3EA,
|
||||
0x410,0x411,0x412,0x413,0x414,0x415,0x416,0x417,0x418,0x419,0x41A,0x41B,0x41C,0x41D,0x41E,0x41F,0x420,0x421,0x422,0x423,0x424,0x425,0x426,0x427,0x428,0x429,0x42A,0x42B,0x42C,0x42D,0x42E,0x42F,0x402,0x403,0x404,0x405,0x406,0x407,0x408,0x409,0x40A,0x40B,0x40C,0x40E,0x40F,0x460,0x462,0x464,0x466,0x468,0x46A,0x46C,0x46E,0x470,0x472,0x474,0x476,0x478,0x47A,0x47C,0x47E,0x480,0x490,0x492,0x494,0x496,0x498,0x49A,0x49C,0x49E,0x4A0,0x4A2,0x4A4,0x4A6,0x4A8,0x4AA,0x4AC,0x4AE,0x4B0,0x4B2,0x4B4,0x4B6,0x4B8,0x4BA,0x4BC,0x4BE,0x4C1,0x4C3,0x5C7,0x4D0,0x4D2,0x4D4,0x4D6,0x4D8,0x4DA,0x4DC,0x4DE,0x4E0,0x4E2,0x4E4,0x4E6,0x4E8,0x4EA,0x4EC,0x4EE,0x4F0,0x4F2,0x4F4,0x4F8,
|
||||
0x531,0x532,0x533,0x534,0x535,0x536,0x537,0x538,0x539,0x53A,0x53B,0x53C,0x53D,0x53E,0x53F,0x540,0x541,0x542,0x543,0x544,0x545,0x546,0x547,0x548,0x549,0x54A,0x54B,0x54C,0x54D,0x54E,0x54F,0x550,0x551,0x552,0x553,0x554,0x555,0x556,
|
||||
0x1E00,0x1E02,0x1E04,0x1E06,0x1E08,0x1E0A,0x1E0C,0x1E0E,0x1E10,0x1E12,0x1E14,0x1E16,0x1E18,0x1E1A,0x1E1C,0x1E1E,0x1E20,0x1E22,0x1E24,0x1E26,0x1E28,0x1E2A,0x1E2C,0x1E2E,0x1E30,0x1E32,0x1E34,0x1E36,0x1E38,0x1E3A,0x1E3C,0x1E3E,0x1E40,0x1E42,0x1E44,0x1E46,0x1E48,0x1E4A,0x1E4C,0x1E4E,0x1E50,0x1E52,0x1E54,0x1E56,0x1E58,0x1E5A,0x1E5C,0x1E5E,0x1E60,0x1E62,0x1E64,0x1E66,0x1E68,0x1E6A,0x1E6C,0x1E6E,0x1E70,0x1E72,0x1E74,0x1E76,0x1E78,0x1E7A,0x1E7C,0x1E7E,0x1E80,0x1E82,0x1E84,0x1E86,0x1E88,0x1E8A,0x1E8C,0x1E8E,0x1E90,0x1E92,0x1E94,0x1E96,0x1E98,0x1E9A,0x1E9C,0x1E9E,0x1EA0,0x1EA2,0x1EA4,0x1EA6,0x1EA8,0x1EAA,0x1EAC,0x1EAE,0x1EB0,0x1EB2,0x1EB4,0x1EB6,0x1EB8,0x1EBA,0x1EBC,0x1EBE,0x1EC0,0x1EC2,0x1EC4,0x1EC6,0x1EC8,0x1ECA,0x1ECC,0x1ECE,0x1ED0,0x1ED2,0x1ED4,0x1ED6,0x1ED8,0x1EDA,0x1EDC,0x1EDE,0x1EE0,0x1EE2,0x1EE4,0x1EE6,0x1EE8,0x1EEA,0x1EEC,0x1EEE,0x1EF0,0x1EF2,0x1EF4,0x1EF6,0x1EF8,
|
||||
0x2160,0x2161,0x2162,0x2163,0x2164,0x2165,0x2166,0x2167,0x2168,0x2169,0x216A,0x216B,0x216C,0x216D,0x216E,0x216F,
|
||||
0xFF21,0xFF22,0xFF23,0xFF24,0xFF25,0xFF26,0xFF27,0xFF28,0xFF29,0xFF2A,0xFF2B,0xFF2C,0xFF2D,0xFF2E,0xFF2F,0xFF30,0xFF31,0xFF32,0xFF33,0xFF34,0xFF35,0xFF36,0xFF37,0xFF38,0xFF39,0xFF3A
|
||||
};
|
||||
UINT i, n, hi, li;
|
||||
|
||||
|
||||
if (chr < 0x80) { /* ASCII characters (acceleration) */
|
||||
if (chr >= 0x61 && chr <= 0x7A) chr -= 0x20;
|
||||
|
||||
} else { /* Non ASCII characters (table search) */
|
||||
n = 12; li = 0; hi = sizeof lower / sizeof lower[0];
|
||||
do {
|
||||
i = li + (hi - li) / 2;
|
||||
if (chr == lower[i]) break;
|
||||
if (chr > lower[i]) li = i; else hi = i;
|
||||
} while (--n);
|
||||
if (n) chr = upper[i];
|
||||
}
|
||||
|
||||
return chr;
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue