Update IDF libs to 9314bf0
This commit is contained in:
parent
b34d18f576
commit
ca7f6cc516
48
boards.txt
48
boards.txt
@ -1,5 +1,6 @@
|
||||
menu.UploadSpeed=Upload Speed
|
||||
menu.FlashFreq=Flash Frequency
|
||||
menu.FlashMode=Flash Mode
|
||||
menu.DebugLevel=Core Debug Level
|
||||
|
||||
##############################################################
|
||||
@ -20,8 +21,19 @@ esp32.build.variant=esp32
|
||||
esp32.build.board=ESP32_DEV
|
||||
|
||||
esp32.build.f_cpu=240000000L
|
||||
esp32.build.flash_mode=dio
|
||||
esp32.build.flash_size=4MB
|
||||
esp32.build.boot=bootloader
|
||||
|
||||
esp32.menu.FlashMode.qio=QIO
|
||||
esp32.menu.FlashMode.qio.build.flash_mode=dio
|
||||
esp32.menu.FlashMode.qio.build.boot=bootloader_qio
|
||||
esp32.menu.FlashMode.dio=DIO
|
||||
esp32.menu.FlashMode.dio.build.flash_mode=dio
|
||||
esp32.menu.FlashMode.qout=QOUT
|
||||
esp32.menu.FlashMode.qout.build.flash_mode=dout
|
||||
esp32.menu.FlashMode.qout.build.boot=bootloader_qio
|
||||
esp32.menu.FlashMode.dout=DOUT
|
||||
esp32.menu.FlashMode.dout.build.flash_mode=dout
|
||||
|
||||
esp32.menu.FlashFreq.80=80MHz
|
||||
esp32.menu.FlashFreq.80.build.flash_freq=80m
|
||||
@ -76,6 +88,7 @@ esp32thing.build.board=ESP32_THING
|
||||
esp32thing.build.f_cpu=240000000L
|
||||
esp32thing.build.flash_mode=dio
|
||||
esp32thing.build.flash_size=4MB
|
||||
esp32thing.build.boot=bootloader
|
||||
|
||||
esp32thing.menu.FlashFreq.80=80MHz
|
||||
esp32thing.menu.FlashFreq.80.build.flash_freq=80m
|
||||
@ -117,6 +130,7 @@ widora-air.build.board=WIDORA_AIR
|
||||
widora-air.build.f_cpu=240000000L
|
||||
widora-air.build.flash_mode=dio
|
||||
widora-air.build.flash_size=16MB
|
||||
widora-air.build.boot=bootloader
|
||||
|
||||
widora-air.menu.FlashFreq.80=80MHz
|
||||
widora-air.menu.FlashFreq.80.build.flash_freq=80m
|
||||
@ -158,6 +172,7 @@ esp320.build.board=ESP320
|
||||
esp320.build.f_cpu=240000000L
|
||||
esp320.build.flash_mode=qio
|
||||
esp320.build.flash_size=4MB
|
||||
esp320.build.boot=bootloader
|
||||
|
||||
esp320.menu.FlashFreq.80=80MHz
|
||||
esp320.menu.FlashFreq.80.build.flash_freq=80m
|
||||
@ -199,6 +214,7 @@ nano32.build.board=NANO32
|
||||
nano32.build.f_cpu=240000000L
|
||||
nano32.build.flash_mode=dio
|
||||
nano32.build.flash_size=4MB
|
||||
nano32.build.boot=bootloader
|
||||
|
||||
nano32.menu.FlashFreq.80=80MHz
|
||||
nano32.menu.FlashFreq.80.build.flash_freq=80m
|
||||
@ -240,6 +256,7 @@ lolin32.build.board=LOLIN32
|
||||
lolin32.build.f_cpu=240000000L
|
||||
lolin32.build.flash_mode=dio
|
||||
lolin32.build.flash_size=4MB
|
||||
lolin32.build.boot=bootloader
|
||||
|
||||
lolin32.menu.FlashFreq.80=80MHz
|
||||
lolin32.menu.FlashFreq.80.build.flash_freq=80m
|
||||
@ -281,6 +298,7 @@ espea32.build.board=ESPea32
|
||||
espea32.build.f_cpu=240000000L
|
||||
espea32.build.flash_mode=dio
|
||||
espea32.build.flash_size=4MB
|
||||
espea32.build.boot=bootloader
|
||||
|
||||
espea32.menu.FlashFreq.80=80MHz
|
||||
espea32.menu.FlashFreq.80.build.flash_freq=80m
|
||||
@ -322,6 +340,7 @@ quantum.build.board=QUANTUM
|
||||
quantum.build.f_cpu=240000000L
|
||||
quantum.build.flash_mode=qio
|
||||
quantum.build.flash_size=16MB
|
||||
quantum.build.boot=bootloader
|
||||
|
||||
quantum.menu.FlashFreq.80=80MHz
|
||||
quantum.menu.FlashFreq.80.build.flash_freq=80m
|
||||
@ -363,6 +382,7 @@ node32s.build.board=Node32s
|
||||
node32s.build.f_cpu=240000000L
|
||||
node32s.build.flash_mode=dio
|
||||
node32s.build.flash_size=4MB
|
||||
node32s.build.boot=bootloader
|
||||
|
||||
node32s.menu.FlashFreq.80=80MHz
|
||||
node32s.menu.FlashFreq.80.build.flash_freq=80m
|
||||
@ -400,9 +420,11 @@ hornbill32dev.build.mcu=esp32
|
||||
hornbill32dev.build.core=esp32
|
||||
hornbill32dev.build.variant=hornbill32dev
|
||||
hornbill32dev.build.board=HORNBILL_ESP32_DEV
|
||||
|
||||
hornbill32dev.build.f_cpu=240000000L
|
||||
hornbill32dev.build.flash_mode=dio
|
||||
hornbill32dev.build.flash_size=4MB
|
||||
hornbill32dev.build.boot=bootloader
|
||||
|
||||
hornbill32dev.menu.FlashFreq.80=80MHz
|
||||
hornbill32dev.menu.FlashFreq.80.build.flash_freq=80m
|
||||
@ -443,6 +465,7 @@ hornbill32minima.build.board=HORNBILL_ESP32_MINIMA
|
||||
hornbill32minima.build.f_cpu=240000000L
|
||||
hornbill32minima.build.flash_mode=dio
|
||||
hornbill32minima.build.flash_size=4MB
|
||||
hornbill32minima.build.boot=bootloader
|
||||
|
||||
hornbill32minima.menu.FlashFreq.80=80MHz
|
||||
hornbill32minima.menu.FlashFreq.80.build.flash_freq=80m
|
||||
@ -484,6 +507,7 @@ firebeetle32.build.board=ESP32_DEV
|
||||
firebeetle32.build.f_cpu=240000000L
|
||||
firebeetle32.build.flash_mode=dio
|
||||
firebeetle32.build.flash_size=4MB
|
||||
firebeetle32.build.boot=bootloader
|
||||
|
||||
firebeetle32.menu.FlashFreq.80=80MHz
|
||||
firebeetle32.menu.FlashFreq.80.build.flash_freq=80m
|
||||
@ -525,6 +549,7 @@ intorobot-fig.build.board=INTOROBOT_ESP32_DEV
|
||||
intorobot-fig.build.f_cpu=240000000L
|
||||
intorobot-fig.build.flash_mode=dio
|
||||
intorobot-fig.build.flash_size=4MB
|
||||
intorobot-fig.build.boot=bootloader
|
||||
|
||||
intorobot-fig.menu.FlashFreq.80=80MHz
|
||||
intorobot-fig.menu.FlashFreq.80.build.flash_freq=80m
|
||||
@ -566,6 +591,7 @@ onehorse32dev.build.board=ONEHORSE_ESP32_DEV
|
||||
onehorse32dev.build.f_cpu=240000000L
|
||||
onehorse32dev.build.flash_mode=dout
|
||||
onehorse32dev.build.flash_size=4MB
|
||||
onehorse32dev.build.boot=bootloader
|
||||
|
||||
onehorse32dev.menu.FlashFreq.80=80MHz
|
||||
onehorse32dev.menu.FlashFreq.80.build.flash_freq=80m
|
||||
@ -607,6 +633,7 @@ featheresp32.build.board=FEATHER_ESP32
|
||||
featheresp32.build.f_cpu=240000000L
|
||||
featheresp32.build.flash_mode=dio
|
||||
featheresp32.build.flash_size=4MB
|
||||
featheresp32.build.boot=bootloader
|
||||
|
||||
featheresp32.menu.FlashFreq.80=80MHz
|
||||
featheresp32.menu.FlashFreq.80.build.flash_freq=80m
|
||||
@ -628,6 +655,19 @@ featheresp32.menu.UploadSpeed.460800.upload.speed=460800
|
||||
featheresp32.menu.UploadSpeed.512000.windows=512000
|
||||
featheresp32.menu.UploadSpeed.512000.upload.speed=512000
|
||||
|
||||
featheresp32.menu.DebugLevel.none=None
|
||||
featheresp32.menu.DebugLevel.none.build.code_debug=0
|
||||
featheresp32.menu.DebugLevel.error=Error
|
||||
featheresp32.menu.DebugLevel.error.build.code_debug=1
|
||||
featheresp32.menu.DebugLevel.warn=Warn
|
||||
featheresp32.menu.DebugLevel.warn.build.code_debug=2
|
||||
featheresp32.menu.DebugLevel.info=Info
|
||||
featheresp32.menu.DebugLevel.info.build.code_debug=3
|
||||
featheresp32.menu.DebugLevel.debug=Debug
|
||||
featheresp32.menu.DebugLevel.debug.build.code_debug=4
|
||||
featheresp32.menu.DebugLevel.verbose=Verbose
|
||||
featheresp32.menu.DebugLevel.verbose.build.code_debug=5
|
||||
|
||||
##############################################################
|
||||
|
||||
nodemcu-32s.name=NodeMCU-32S
|
||||
@ -648,6 +688,7 @@ nodemcu-32s.build.board=NodeMCU-32S
|
||||
nodemcu-32s.build.f_cpu=240000000L
|
||||
nodemcu-32s.build.flash_mode=dio
|
||||
nodemcu-32s.build.flash_size=4MB
|
||||
nodemcu-32s.build.boot=bootloader
|
||||
|
||||
nodemcu-32s.menu.FlashFreq.80=80MHz
|
||||
nodemcu-32s.menu.FlashFreq.80.build.flash_freq=80m
|
||||
@ -689,6 +730,7 @@ esp32vn-iot-uno.build.board=esp32vn-iot-uno
|
||||
esp32vn-iot-uno.build.f_cpu=240000000L
|
||||
esp32vn-iot-uno.build.flash_mode=dio
|
||||
esp32vn-iot-uno.build.flash_size=4MB
|
||||
esp32vn-iot-uno.build.boot=bootloader
|
||||
|
||||
esp32vn-iot-uno.menu.FlashFreq.80=80MHz
|
||||
esp32vn-iot-uno.menu.FlashFreq.80.build.flash_freq=80m
|
||||
@ -730,6 +772,7 @@ esp32doit-devkit-v1.build.board=ESP32_DEV
|
||||
esp32doit-devkit-v1.build.f_cpu=240000000L
|
||||
esp32doit-devkit-v1.build.flash_mode=dio
|
||||
esp32doit-devkit-v1.build.flash_size=4MB
|
||||
esp32doit-devkit-v1.build.boot=bootloader
|
||||
|
||||
esp32doit-devkit-v1.menu.FlashFreq.80=80MHz
|
||||
esp32doit-devkit-v1.menu.FlashFreq.80.build.flash_freq=80m
|
||||
@ -782,6 +825,7 @@ esp32-evb.build.board=ESP32-EVB
|
||||
esp32-evb.build.f_cpu=240000000L
|
||||
esp32-evb.build.flash_mode=dio
|
||||
esp32-evb.build.flash_size=4MB
|
||||
esp32-evb.build.boot=bootloader
|
||||
|
||||
esp32-evb.menu.FlashFreq.80=80MHz
|
||||
esp32-evb.menu.FlashFreq.80.build.flash_freq=80m
|
||||
@ -812,6 +856,7 @@ esp32-gateway.build.board=ESP32-GATEWAY
|
||||
esp32-gateway.build.f_cpu=240000000L
|
||||
esp32-gateway.build.flash_mode=dio
|
||||
esp32-gateway.build.flash_size=4MB
|
||||
esp32-gateway.build.boot=bootloader
|
||||
|
||||
esp32-gateway.menu.FlashFreq.80=80MHz
|
||||
esp32-gateway.menu.FlashFreq.80.build.flash_freq=80m
|
||||
@ -842,6 +887,7 @@ espino32.build.board=ESPino32
|
||||
espino32.build.f_cpu=240000000L
|
||||
espino32.build.flash_mode=dio
|
||||
espino32.build.flash_size=4MB
|
||||
espino32.build.boot=bootloader
|
||||
|
||||
espino32.menu.FlashFreq.80=80MHz
|
||||
espino32.menu.FlashFreq.80.build.flash_freq=80m
|
||||
|
@ -38,7 +38,7 @@
|
||||
{
|
||||
"packager": "esp32",
|
||||
"name": "esptool",
|
||||
"version": "96698a3"
|
||||
"version": "a420774"
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -80,21 +80,21 @@
|
||||
},
|
||||
{
|
||||
"name": "esptool",
|
||||
"version": "96698a3",
|
||||
"version": "a420774",
|
||||
"systems": [
|
||||
{
|
||||
"host": "i686-mingw32",
|
||||
"url": "https://dl.espressif.com/dl/esptool-96698a3-windows.zip",
|
||||
"archiveFileName": "esptool-96698a3-windows.zip",
|
||||
"checksum": "SHA-256:12f026c84869f0bd2f6a863191ec84d27b91f21d17e2e2e9e11c79be50f2d0fc",
|
||||
"size": "3390935"
|
||||
"url": "https://dl.espressif.com/dl/esptool-a420774-windows.zip",
|
||||
"archiveFileName": "esptool-a420774-windows.zip",
|
||||
"checksum": "SHA-256:7778545baa30a85a37a956e47e42a236fa67227f21b160b2164ef83a5e20a41f",
|
||||
"size": "3394137"
|
||||
},
|
||||
{
|
||||
"host": "x86_64-apple-darwin",
|
||||
"url": "https://dl.espressif.com/dl/esptool-96698a3-macos.tar.gz",
|
||||
"archiveFileName": "esptool-96698a3-macos.tar.gz",
|
||||
"checksum": "SHA-256:e3154dbf32c3ba5e5ebd45e913178b167cf761e5ce0152b2bb069a2453f6839b",
|
||||
"size": "3805789"
|
||||
"url": "https://dl.espressif.com/dl/esptool-a420774-macos.tar.gz",
|
||||
"archiveFileName": "esptool-a420774-macos.tar.gz",
|
||||
"checksum": "SHA-256:1a6237b695fe299357bfd78a9727564464a00e020bc7c7a4cf6fad02250eb2a2",
|
||||
"size": "3808980"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ compiler.warning_flags.all=-Wall -Werror=all -Wextra
|
||||
|
||||
compiler.path={runtime.tools.xtensa-esp32-elf-gcc.path}/bin/
|
||||
compiler.sdk.path={runtime.platform.path}/tools/sdk
|
||||
compiler.cpreprocessor.flags=-DESP_PLATFORM -DMBEDTLS_CONFIG_FILE="mbedtls/esp_config.h" -DHAVE_CONFIG_H "-I{compiler.sdk.path}/include/config" "-I{compiler.sdk.path}/include/bluedroid" "-I{compiler.sdk.path}/include/app_update" "-I{compiler.sdk.path}/include/bootloader_support" "-I{compiler.sdk.path}/include/bt" "-I{compiler.sdk.path}/include/driver" "-I{compiler.sdk.path}/include/esp32" "-I{compiler.sdk.path}/include/ethernet" "-I{compiler.sdk.path}/include/fatfs" "-I{compiler.sdk.path}/include/freertos" "-I{compiler.sdk.path}/include/jsmn" "-I{compiler.sdk.path}/include/log" "-I{compiler.sdk.path}/include/mdns" "-I{compiler.sdk.path}/include/mbedtls" "-I{compiler.sdk.path}/include/mbedtls_port" "-I{compiler.sdk.path}/include/newlib" "-I{compiler.sdk.path}/include/nvs_flash" "-I{compiler.sdk.path}/include/openssl" "-I{compiler.sdk.path}/include/soc" "-I{compiler.sdk.path}/include/spi_flash" "-I{compiler.sdk.path}/include/sdmmc" "-I{compiler.sdk.path}/include/tcpip_adapter" "-I{compiler.sdk.path}/include/ulp" "-I{compiler.sdk.path}/include/vfs" "-I{compiler.sdk.path}/include/wear_levelling" "-I{compiler.sdk.path}/include/xtensa-debug-module" "-I{compiler.sdk.path}/include/newlib" "-I{compiler.sdk.path}/include/coap" "-I{compiler.sdk.path}/include/wpa_supplicant" "-I{compiler.sdk.path}/include/expat" "-I{compiler.sdk.path}/include/json" "-I{compiler.sdk.path}/include/nghttp" "-I{compiler.sdk.path}/include/lwip"
|
||||
compiler.cpreprocessor.flags=-DESP_PLATFORM -DMBEDTLS_CONFIG_FILE="mbedtls/esp_config.h" -DHAVE_CONFIG_H "-I{compiler.sdk.path}/include/config" "-I{compiler.sdk.path}/include/bluedroid" "-I{compiler.sdk.path}/include/app_trace" "-I{compiler.sdk.path}/include/app_update" "-I{compiler.sdk.path}/include/bootloader_support" "-I{compiler.sdk.path}/include/bt" "-I{compiler.sdk.path}/include/driver" "-I{compiler.sdk.path}/include/esp32" "-I{compiler.sdk.path}/include/ethernet" "-I{compiler.sdk.path}/include/fatfs" "-I{compiler.sdk.path}/include/freertos" "-I{compiler.sdk.path}/include/heap" "-I{compiler.sdk.path}/include/jsmn" "-I{compiler.sdk.path}/include/log" "-I{compiler.sdk.path}/include/mdns" "-I{compiler.sdk.path}/include/mbedtls" "-I{compiler.sdk.path}/include/mbedtls_port" "-I{compiler.sdk.path}/include/newlib" "-I{compiler.sdk.path}/include/nvs_flash" "-I{compiler.sdk.path}/include/openssl" "-I{compiler.sdk.path}/include/soc" "-I{compiler.sdk.path}/include/spi_flash" "-I{compiler.sdk.path}/include/sdmmc" "-I{compiler.sdk.path}/include/tcpip_adapter" "-I{compiler.sdk.path}/include/ulp" "-I{compiler.sdk.path}/include/vfs" "-I{compiler.sdk.path}/include/wear_levelling" "-I{compiler.sdk.path}/include/xtensa-debug-module" "-I{compiler.sdk.path}/include/newlib" "-I{compiler.sdk.path}/include/coap" "-I{compiler.sdk.path}/include/wpa_supplicant" "-I{compiler.sdk.path}/include/expat" "-I{compiler.sdk.path}/include/json" "-I{compiler.sdk.path}/include/nghttp" "-I{compiler.sdk.path}/include/lwip"
|
||||
|
||||
compiler.c.cmd=xtensa-esp32-elf-gcc
|
||||
compiler.c.flags=-std=gnu99 -Os -g3 -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -mlongcalls -nostdlib -Wpointer-arith {compiler.warning_flags} -Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wno-unused-parameter -Wno-sign-compare -Wno-old-style-declaration -MMD -c
|
||||
@ -33,8 +33,8 @@ compiler.S.cmd=xtensa-esp32-elf-gcc
|
||||
compiler.S.flags=-c -g3 -x assembler-with-cpp -MMD -mlongcalls
|
||||
|
||||
compiler.c.elf.cmd=xtensa-esp32-elf-gcc
|
||||
compiler.c.elf.flags=-nostdlib "-L{compiler.sdk.path}/lib" "-L{compiler.sdk.path}/ld" -T esp32_out.ld -T esp32.common.ld -T esp32.rom.ld -T esp32.peripherals.ld -u call_user_start_cpu0 -Wl,--gc-sections -Wl,-static -Wl,--undefined=uxTopUsedPriority
|
||||
compiler.c.elf.libs=-lgcc -lstdc++ -lapp_update -lbootloader_support -lbt -lbtdm_app -lc -lc_nano -lcoap -lcoexist -lcore -lcxx -ldriver -lesp32 -lethernet -lexpat -lfatfs -lfreertos -lhal -ljsmn -ljson -llog -llwip -lm -lmbedtls -lmdns -lmicro-ecc -lnet80211 -lnewlib -lnghttp -lnvs_flash -lopenssl -lphy -lpp -lrtc -lsdmmc -lsmartconfig -lsoc -lspi_flash -ltcpip_adapter -lulp -lvfs -lwear_levelling -lwpa -lwpa2 -lwpa_supplicant -lwps -lxtensa-debug-module
|
||||
compiler.c.elf.flags=-nostdlib "-L{compiler.sdk.path}/lib" "-L{compiler.sdk.path}/ld" -T esp32_out.ld -T esp32.common.ld -T esp32.rom.ld -T esp32.peripherals.ld -u ld_include_panic_highint_hdl -u call_user_start_cpu0 -Wl,--gc-sections -Wl,-static -Wl,--undefined=uxTopUsedPriority
|
||||
compiler.c.elf.libs=-lgcc -lstdc++ -lapp_trace -lapp_update -lbootloader_support -lbt -lbtdm_app -lc -lc_nano -lcoap -lcoexist -lcore -lcxx -ldriver -lesp32 -lethernet -lexpat -lfatfs -lfreertos -lhal -lheap -ljsmn -ljson -llibsodium -llog -llwip -lm -lmbedtls -lmdns -lmicro-ecc -lnet80211 -lnewlib -lnghttp -lnvs_flash -lopenssl -lphy -lpp -lrtc -lsdmmc -lsmartconfig -lsoc -lspi_flash -ltcpip_adapter -lulp -lvfs -lwear_levelling -lwpa -lwpa2 -lwpa_supplicant -lwps -lxtensa-debug-module
|
||||
|
||||
compiler.as.cmd=xtensa-esp32-elf-as
|
||||
|
||||
@ -44,6 +44,7 @@ compiler.ar.flags=cru
|
||||
compiler.size.cmd=xtensa-esp32-elf-size
|
||||
|
||||
# This can be overriden in boards.txt
|
||||
build.boot=bootloader
|
||||
build.code_debug=0
|
||||
build.extra_flags=-DESP32 -DCORE_DEBUG_LEVEL={build.code_debug}
|
||||
|
||||
@ -91,5 +92,5 @@ recipe.size.regex.data=^(?:\.dram0\.data|\.dram0\.bss)\s+([0-9]+).*
|
||||
tools.esptool.upload.protocol=esp32
|
||||
tools.esptool.upload.params.verbose=
|
||||
tools.esptool.upload.params.quiet=
|
||||
tools.esptool.upload.pattern={cmd} --chip esp32 --port "{serial.port}" --baud {upload.speed} --before default_reset --after hard_reset write_flash -z --flash_freq {build.flash_freq} --flash_mode {build.flash_mode} --flash_size {build.flash_size} 0x1000 "{runtime.platform.path}/tools/sdk/bin/bootloader.bin" 0x8000 "{build.path}/{build.project_name}.partitions.bin" 0xe000 "{runtime.platform.path}/tools/partitions/boot_app0.bin" 0x10000 "{build.path}/{build.project_name}.bin"
|
||||
tools.esptool.upload.pattern={cmd} --chip esp32 --port "{serial.port}" --baud {upload.speed} --before default_reset --after hard_reset write_flash -z --flash_mode {build.flash_mode} --flash_freq {build.flash_freq} --flash_size detect 0xe000 "{runtime.platform.path}/tools/partitions/boot_app0.bin" 0x1000 "{runtime.platform.path}/tools/sdk/bin/{build.boot}.bin" 0x10000 "{build.path}/{build.project_name}.bin" 0x8000 "{build.path}/{build.project_name}.partitions.bin"
|
||||
tools.esptool.upload.network_pattern={network_cmd} -i "{serial.port}" -p "{network.port}" "--auth={network.password}" -f "{build.path}/{build.project_name}.bin"
|
||||
|
350
tools/esptool.py
350
tools/esptool.py
@ -29,12 +29,23 @@ import time
|
||||
import base64
|
||||
import zlib
|
||||
import shlex
|
||||
import copy
|
||||
import io
|
||||
|
||||
__version__ = "2.0-beta3"
|
||||
__version__ = "2.1-beta1"
|
||||
|
||||
MAX_UINT32 = 0xffffffff
|
||||
MAX_UINT24 = 0xffffff
|
||||
|
||||
DEFAULT_TIMEOUT = 3 # timeout for most flash operations
|
||||
START_FLASH_TIMEOUT = 20 # timeout for starting flash (may perform erase)
|
||||
CHIP_ERASE_TIMEOUT = 120 # timeout for full chip erase
|
||||
SYNC_TIMEOUT = 0.1 # timeout for syncing with bootloader
|
||||
|
||||
|
||||
DETECTED_FLASH_SIZES = {0x12: '256KB', 0x13: '512KB', 0x14: '1MB',
|
||||
0x15: '2MB', 0x16: '4MB', 0x17: '8MB', 0x18: '16MB'}
|
||||
|
||||
|
||||
def check_supported_function(func, check_func):
|
||||
"""
|
||||
@ -169,7 +180,13 @@ class ESPLoader(object):
|
||||
# CH341 driver on some Linux versions (this opens at 9600 then
|
||||
# sets), shouldn't matter for other platforms/drivers. See
|
||||
# https://github.com/espressif/esptool/issues/44#issuecomment-107094446
|
||||
self._set_port_baudrate(baud)
|
||||
|
||||
def _set_port_baudrate(self, baud):
|
||||
try:
|
||||
self._port.baudrate = baud
|
||||
except IOError:
|
||||
raise FatalError("Failed to set baud rate %d. The driver may not support this rate." % baud)
|
||||
|
||||
@staticmethod
|
||||
def detect_chip(port=DEFAULT_PORT, baud=ESP_ROM_BAUD, connect_mode='default_reset'):
|
||||
@ -319,13 +336,13 @@ class ESPLoader(object):
|
||||
time.sleep(0.05)
|
||||
self._port.setDTR(False) # IO0=HIGH, done
|
||||
|
||||
self._port.timeout = 0.1
|
||||
self._port.timeout = SYNC_TIMEOUT
|
||||
for _ in range(5):
|
||||
try:
|
||||
self.flush_input()
|
||||
self._port.flushOutput()
|
||||
self.sync()
|
||||
self._port.timeout = 5
|
||||
self._port.timeout = DEFAULT_TIMEOUT
|
||||
return None
|
||||
except FatalError as e:
|
||||
if esp32r0_delay:
|
||||
@ -391,17 +408,16 @@ class ESPLoader(object):
|
||||
Returns number of blocks (of size self.FLASH_WRITE_SIZE) to write.
|
||||
"""
|
||||
def flash_begin(self, size, offset):
|
||||
old_tmo = self._port.timeout
|
||||
num_blocks = (size + self.FLASH_WRITE_SIZE - 1) // self.FLASH_WRITE_SIZE
|
||||
erase_size = self.get_erase_size(offset, size)
|
||||
|
||||
self._port.timeout = 20
|
||||
self._port.timeout = START_FLASH_TIMEOUT
|
||||
t = time.time()
|
||||
self.check_command("enter Flash download mode", self.ESP_FLASH_BEGIN,
|
||||
struct.pack('<IIII', erase_size, num_blocks, self.FLASH_WRITE_SIZE, offset))
|
||||
if size != 0 and not self.IS_STUB:
|
||||
print("Took %.2fs to erase flash block" % (time.time() - t))
|
||||
self._port.timeout = old_tmo
|
||||
self._port.timeout = DEFAULT_TIMEOUT
|
||||
return num_blocks
|
||||
|
||||
""" Write block to flash """
|
||||
@ -468,11 +484,10 @@ class ESPLoader(object):
|
||||
|
||||
Returns number of blocks (size self.FLASH_WRITE_SIZE) to write.
|
||||
"""
|
||||
old_tmo = self._port.timeout
|
||||
num_blocks = (compsize + self.FLASH_WRITE_SIZE - 1) // self.FLASH_WRITE_SIZE
|
||||
erase_blocks = (size + self.FLASH_WRITE_SIZE - 1) // self.FLASH_WRITE_SIZE
|
||||
|
||||
self._port.timeout = 20
|
||||
self._port.timeout = START_FLASH_TIMEOUT
|
||||
t = time.time()
|
||||
if self.IS_STUB:
|
||||
write_size = size # stub expects number of bytes here, manages erasing internally
|
||||
@ -484,7 +499,7 @@ class ESPLoader(object):
|
||||
if size != 0 and not self.IS_STUB:
|
||||
# (stub erases as it writes, but ROM loaders erase on begin)
|
||||
print("Took %.2fs to erase flash block" % (time.time() - t))
|
||||
self._port.timeout = old_tmo
|
||||
self._port.timeout = DEFAULT_TIMEOUT
|
||||
return num_blocks
|
||||
|
||||
""" Write block to flash, send compressed """
|
||||
@ -522,19 +537,18 @@ class ESPLoader(object):
|
||||
print("Changing baud rate to %d" % baud)
|
||||
self.command(self.ESP_CHANGE_BAUDRATE, struct.pack('<II', baud, 0))
|
||||
print("Changed.")
|
||||
self._port.baudrate = baud
|
||||
self._set_port_baudrate(baud)
|
||||
time.sleep(0.05) # get rid of crap sent during baud rate change
|
||||
self.flush_input()
|
||||
|
||||
@stub_function_only
|
||||
def erase_flash(self):
|
||||
oldtimeout = self._port.timeout
|
||||
# depending on flash chip model the erase may take this long (maybe longer!)
|
||||
self._port.timeout = 128
|
||||
self._port.timeout = CHIP_ERASE_TIMEOUT
|
||||
try:
|
||||
self.check_command("erase flash", self.ESP_ERASE_FLASH)
|
||||
finally:
|
||||
self._port.timeout = oldtimeout
|
||||
self._port.timeout = DEFAULT_TIMEOUT
|
||||
|
||||
@stub_function_only
|
||||
def erase_region(self, offset, size):
|
||||
@ -810,9 +824,14 @@ class ESP8266ROM(ESPLoader):
|
||||
'4MB':0x40,
|
||||
'2MB-c1': 0x50,
|
||||
'4MB-c1':0x60,
|
||||
'4MB-c2':0x70}
|
||||
'8MB':0x80,
|
||||
'16MB':0x90,
|
||||
}
|
||||
|
||||
FLASH_HEADER_OFFSET = 0
|
||||
BOOTLOADER_FLASH_OFFSET = 0
|
||||
|
||||
def get_chip_description(self):
|
||||
return "ESP8266"
|
||||
|
||||
def flash_spi_attach(self, hspi_arg):
|
||||
if self.IS_STUB:
|
||||
@ -897,7 +916,7 @@ class ESP32ROM(ESPLoader):
|
||||
IROM_MAP_START = 0x400d0000
|
||||
IROM_MAP_END = 0x40400000
|
||||
DROM_MAP_START = 0x3F400000
|
||||
DROM_MAP_END = 0x3F700000
|
||||
DROM_MAP_END = 0x3F800000
|
||||
|
||||
# ESP32 uses a 4 byte status reply
|
||||
STATUS_BYTES_LENGTH = 4
|
||||
@ -916,7 +935,25 @@ class ESP32ROM(ESPLoader):
|
||||
'16MB':0x40
|
||||
}
|
||||
|
||||
FLASH_HEADER_OFFSET = 0x1000
|
||||
BOOTLOADER_FLASH_OFFSET = 0x1000
|
||||
|
||||
def get_chip_description(self):
|
||||
blk3 = self.read_efuse(3)
|
||||
chip_version = (blk3 >> 12) & 0xF
|
||||
pkg_version = (blk3 >> 9) & 0x07
|
||||
|
||||
silicon_rev = {
|
||||
0: "0",
|
||||
8: "1"
|
||||
}.get(chip_version, "(unknown 0x%x)" % chip_version)
|
||||
|
||||
chip_name = {
|
||||
0: "ESP32D0WDQ6",
|
||||
1: "ESP32D0WDQ5",
|
||||
2: "ESP32D2WDQ5",
|
||||
}.get(pkg_version, "unknown ESP32")
|
||||
|
||||
return "%s (revision %s)" % (chip_name, silicon_rev)
|
||||
|
||||
def read_efuse(self, n):
|
||||
""" Read the nth word of the ESP3x EFUSE region. """
|
||||
@ -1001,6 +1038,18 @@ class ImageSegment(object):
|
||||
a new address. """
|
||||
return ImageSegment(new_addr, self.data, 0)
|
||||
|
||||
def split_image(self, split_len):
|
||||
""" Return a new ImageSegment which splits "split_len" bytes
|
||||
from the beginning of the data. Remaining bytes are kept in
|
||||
this segment object (and the start address is adjusted to match.) """
|
||||
result = copy.copy(self)
|
||||
result.data = self.data[:split_len]
|
||||
self.data = self.data[split_len:]
|
||||
self.addr += split_len
|
||||
self.file_offs = None
|
||||
result.file_offs = None
|
||||
return result
|
||||
|
||||
def __repr__(self):
|
||||
r = "len 0x%05x load 0x%08x" % (len(self.data), self.addr)
|
||||
if self.file_offs is not None:
|
||||
@ -1230,24 +1279,48 @@ class ESP32FirmwareImage(BaseFirmwareImage):
|
||||
|
||||
ROM_LOADER = ESP32ROM
|
||||
|
||||
# ROM bootloader will read the wp_pin field if SPI flash
|
||||
# pins are remapped via flash. IDF actually enables QIO only
|
||||
# from software bootloader, so this can be ignored. But needs
|
||||
# to be set to this value so ROM bootloader will skip it.
|
||||
WP_PIN_DISABLED = 0xEE
|
||||
|
||||
EXTENDED_HEADER_STRUCT_FMT = "B" * 16
|
||||
|
||||
def __init__(self, load_file=None):
|
||||
super(ESP32FirmwareImage, self).__init__()
|
||||
self.flash_mode = 0
|
||||
self.flash_size_freq = 0
|
||||
self.version = 1
|
||||
self.wp_pin = self.WP_PIN_DISABLED
|
||||
# SPI pin drive levels
|
||||
self.clk_drv = 0
|
||||
self.q_drv = 0
|
||||
self.d_drv = 0
|
||||
self.cs_drv = 0
|
||||
self.hd_drv = 0
|
||||
self.wp_drv = 0
|
||||
|
||||
self.append_digest = True
|
||||
|
||||
if load_file is not None:
|
||||
segments = self.load_common_header(load_file, ESPLoader.ESP_IMAGE_MAGIC)
|
||||
additional_header = list(struct.unpack("B" * 16, load_file.read(16)))
|
||||
start = load_file.tell()
|
||||
|
||||
# check these bytes are unused
|
||||
if additional_header != [0] * 16:
|
||||
print("WARNING: ESP32 image header contains unknown flags. Possibly this image is from a newer version of esptool.py")
|
||||
segments = self.load_common_header(load_file, ESPLoader.ESP_IMAGE_MAGIC)
|
||||
self.load_extended_header(load_file)
|
||||
|
||||
for _ in range(segments):
|
||||
self.load_segment(load_file)
|
||||
self.checksum = self.read_checksum(load_file)
|
||||
|
||||
if self.append_digest:
|
||||
end = load_file.tell()
|
||||
self.stored_digest = load_file.read(16)
|
||||
load_file.seek(start)
|
||||
calc_digest = hashlib.sha256()
|
||||
calc_digest.update(load_file.read(end - start))
|
||||
self.calc_digest = calc_digest.digest() # TODO: decide what to do here?
|
||||
|
||||
def is_flash_addr(self, addr):
|
||||
return (ESP32ROM.IROM_MAP_START <= addr < ESP32ROM.IROM_MAP_END) \
|
||||
or (ESP32ROM.DROM_MAP_START <= addr < ESP32ROM.DROM_MAP_END)
|
||||
@ -1260,70 +1333,144 @@ class ESP32FirmwareImage(BaseFirmwareImage):
|
||||
pass # TODO: add warnings for ESP32 segment offset/size combinations that are wrong
|
||||
|
||||
def save(self, filename):
|
||||
padding_segments = 0
|
||||
with open(filename, 'wb') as f:
|
||||
total_segments = 0
|
||||
with io.BytesIO() as f: # write file to memory first
|
||||
self.write_common_header(f, self.segments)
|
||||
|
||||
# first 4 bytes of header are read by ROM bootloader for SPI
|
||||
# config, but currently unused
|
||||
f.write(b'\x00' * 16)
|
||||
self.save_extended_header(f)
|
||||
|
||||
checksum = ESPLoader.ESP_CHECKSUM_MAGIC
|
||||
last_addr = None
|
||||
for segment in sorted(self.segments, key=lambda s:s.addr):
|
||||
# IROM/DROM segment flash mappings need to align on
|
||||
# 64kB boundaries.
|
||||
#
|
||||
# TODO: intelligently order segments to reduce wastage
|
||||
# by squeezing smaller DRAM/IRAM segments into the
|
||||
# 64kB padding space.
|
||||
|
||||
# split segments into flash-mapped vs ram-loaded, and take copies so we can mutate them
|
||||
flash_segments = [copy.deepcopy(s) for s in sorted(self.segments, key=lambda s:s.addr) if self.is_flash_addr(s.addr)]
|
||||
ram_segments = [copy.deepcopy(s) for s in sorted(self.segments, key=lambda s:s.addr) if not self.is_flash_addr(s.addr)]
|
||||
|
||||
IROM_ALIGN = 65536
|
||||
|
||||
# check for multiple ELF sections that live in the same flash mapping region.
|
||||
# check for multiple ELF sections that are mapped in the same flash mapping region.
|
||||
# this is usually a sign of a broken linker script, but if you have a legitimate
|
||||
# use case then let us know (we can merge segments here, but as a rule you probably
|
||||
# want to merge them in your linker script.)
|
||||
if last_addr is not None and self.is_flash_addr(last_addr) \
|
||||
and self.is_flash_addr(segment.addr) and segment.addr // IROM_ALIGN == last_addr // IROM_ALIGN:
|
||||
if len(flash_segments) > 0:
|
||||
last_addr = flash_segments[0].addr
|
||||
for segment in flash_segments[1:]:
|
||||
if segment.addr // IROM_ALIGN == last_addr // IROM_ALIGN:
|
||||
raise FatalError(("Segment loaded at 0x%08x lands in same 64KB flash mapping as segment loaded at 0x%08x. " +
|
||||
"Can't generate binary. Suggest changing linker script or ELF to merge sections.") %
|
||||
(segment.addr, last_addr))
|
||||
last_addr = segment.addr
|
||||
|
||||
if self.is_flash_addr(segment.addr):
|
||||
# Actual alignment required for the segment header: positioned so that
|
||||
def get_alignment_data_needed(segment):
|
||||
# Actual alignment (in data bytes) required for a segment header: positioned so that
|
||||
# after we write the next 8 byte header, file_offs % IROM_ALIGN == segment.addr % IROM_ALIGN
|
||||
#
|
||||
# (this is because the segment's vaddr may not be IROM_ALIGNed, more likely is aligned
|
||||
# IROM_ALIGN+0x10 to account for longest possible header.
|
||||
# IROM_ALIGN+0x18 to account for the binary file header
|
||||
align_past = (segment.addr % IROM_ALIGN) - self.SEG_HEADER_LEN
|
||||
assert (align_past + self.SEG_HEADER_LEN) == (segment.addr % IROM_ALIGN)
|
||||
pad_len = (IROM_ALIGN - (f.tell() % IROM_ALIGN)) + align_past
|
||||
if pad_len == 0 or pad_len == IROM_ALIGN:
|
||||
return 0 # already aligned
|
||||
|
||||
# subtract SEG_HEADER_LEN a second time, as the padding block has a header as well
|
||||
pad_len = (IROM_ALIGN - (f.tell() % IROM_ALIGN)) + align_past - self.SEG_HEADER_LEN
|
||||
pad_len -= self.SEG_HEADER_LEN
|
||||
if pad_len < 0:
|
||||
pad_len += IROM_ALIGN
|
||||
if pad_len > 0:
|
||||
null = ImageSegment(0, b'\x00' * pad_len, f.tell())
|
||||
checksum = self.save_segment(f, null, checksum)
|
||||
padding_segments += 1
|
||||
# verify that after the 8 byte header is added, were are at the correct offset relative to the segment's vaddr
|
||||
return pad_len
|
||||
|
||||
# try to fit each flash segment on a 64kB aligned boundary
|
||||
# by padding with parts of the non-flash segments...
|
||||
while len(flash_segments) > 0:
|
||||
segment = flash_segments[0]
|
||||
pad_len = get_alignment_data_needed(segment)
|
||||
if pad_len > 0: # need to pad
|
||||
if len(ram_segments) > 0 and pad_len > self.SEG_HEADER_LEN:
|
||||
pad_segment = ram_segments[0].split_image(pad_len)
|
||||
if len(ram_segments[0].data) == 0:
|
||||
ram_segments.pop(0)
|
||||
else:
|
||||
pad_segment = ImageSegment(0, b'\x00' * pad_len, f.tell())
|
||||
checksum = self.save_segment(f, pad_segment, checksum)
|
||||
total_segments += 1
|
||||
else:
|
||||
# write the flash segment
|
||||
assert (f.tell() + 8) % IROM_ALIGN == segment.addr % IROM_ALIGN
|
||||
checksum = self.save_segment(f, segment, checksum)
|
||||
flash_segments.pop(0)
|
||||
total_segments += 1
|
||||
|
||||
# flash segments all written, so write any remaining RAM segments
|
||||
for segment in ram_segments:
|
||||
checksum = self.save_segment(f, segment, checksum)
|
||||
total_segments += 1
|
||||
|
||||
# done writing segments
|
||||
self.append_checksum(f, checksum)
|
||||
# kinda hacky: go back to the initial header and write the new segment count
|
||||
# that includes padding segments. Luckily(?) this header is not checksummed
|
||||
# that includes padding segments. This header is not checksummed
|
||||
image_length = f.tell()
|
||||
f.seek(1)
|
||||
try:
|
||||
f.write(chr(len(self.segments) + padding_segments))
|
||||
f.write(chr(total_segments))
|
||||
except TypeError: # Python 3
|
||||
f.write(bytes([len(self.segments) + padding_segments]))
|
||||
f.write(bytes([total_segments]))
|
||||
|
||||
if self.append_digest:
|
||||
# calculate the SHA256 of the whole file and append it
|
||||
f.seek(0)
|
||||
digest = hashlib.sha256()
|
||||
digest.update(f.read(image_length))
|
||||
f.write(digest.digest())
|
||||
|
||||
with open(filename, 'wb') as real_file:
|
||||
real_file.write(f.getvalue())
|
||||
|
||||
def load_extended_header(self, load_file):
|
||||
def split_byte(n):
|
||||
return (n & 0x0F, (n >> 4) & 0x0F)
|
||||
|
||||
fields = list(struct.unpack(self.EXTENDED_HEADER_STRUCT_FMT, load_file.read(16)))
|
||||
|
||||
self.wp_pin = fields[0]
|
||||
|
||||
# SPI pin drive stengths are two per byte
|
||||
self.clk_drv, self.q_drv = split_byte(fields[1])
|
||||
self.d_drv, self.cs_drv = split_byte(fields[2])
|
||||
self.hd_drv, self.wp_drv = split_byte(fields[3])
|
||||
|
||||
if fields[15] in [0, 1]:
|
||||
self.append_digest = (fields[15] == 1)
|
||||
else:
|
||||
raise RuntimeError("Invalid value for append_digest field (0x%02x). Should be 0 or 1.", fields[15])
|
||||
|
||||
# remaining fields in the middle should all be zero
|
||||
if any(f for f in fields[4:15] if f != 0):
|
||||
print("Warning: some reserved header fields have non-zero values. This image may be from a newer esptool.py?")
|
||||
|
||||
def save_extended_header(self, save_file):
|
||||
def join_byte(ln,hn):
|
||||
return (ln & 0x0F) + ((hn & 0x0F) << 4)
|
||||
|
||||
append_digest = 1 if self.append_digest else 0
|
||||
|
||||
fields = [self.wp_pin,
|
||||
join_byte(self.clk_drv, self.q_drv),
|
||||
join_byte(self.d_drv, self.cs_drv),
|
||||
join_byte(self.hd_drv, self.wp_drv)]
|
||||
fields += [0] * 11
|
||||
fields += [append_digest]
|
||||
|
||||
packed = struct.pack(self.EXTENDED_HEADER_STRUCT_FMT, *fields)
|
||||
save_file.write(packed)
|
||||
|
||||
|
||||
class ELFFile(object):
|
||||
SEC_TYPE_PROGBITS = 0x01
|
||||
SEC_TYPE_STRTAB = 0x03
|
||||
|
||||
LEN_SEC_HEADER = 0x28
|
||||
|
||||
def __init__(self, name):
|
||||
# Load sections from the ELF file
|
||||
self.name = name
|
||||
@ -1342,8 +1489,8 @@ class ELFFile(object):
|
||||
try:
|
||||
(ident,_type,machine,_version,
|
||||
self.entrypoint,_phoff,shoff,_flags,
|
||||
_ehsize, _phentsize,_phnum,_shentsize,
|
||||
_shnum,shstrndx) = struct.unpack("<16sHHLLLLLHHHHHH", f.read(LEN_FILE_HEADER))
|
||||
_ehsize, _phentsize,_phnum, shentsize,
|
||||
shnum,shstrndx) = struct.unpack("<16sHHLLLLLHHHHHH", f.read(LEN_FILE_HEADER))
|
||||
except struct.error as e:
|
||||
raise FatalError("Failed to read a valid ELF header from %s: %s" % (self.name, e))
|
||||
|
||||
@ -1351,19 +1498,23 @@ class ELFFile(object):
|
||||
raise FatalError("%s has invalid ELF magic header" % self.name)
|
||||
if machine != 0x5e:
|
||||
raise FatalError("%s does not appear to be an Xtensa ELF file. e_machine=%04x" % (self.name, machine))
|
||||
self._read_sections(f, shoff, shstrndx)
|
||||
if shentsize != self.LEN_SEC_HEADER:
|
||||
raise FatalError("%s has unexpected section header entry size 0x%x (not 0x28)" % (self.name, shentsize, self.LEN_SEC_HEADER))
|
||||
if shnum == 0:
|
||||
raise FatalError("%s has 0 section headers" % (self.name))
|
||||
self._read_sections(f, shoff, shnum, shstrndx)
|
||||
|
||||
def _read_sections(self, f, section_header_offs, shstrndx):
|
||||
def _read_sections(self, f, section_header_offs, section_header_count, shstrndx):
|
||||
f.seek(section_header_offs)
|
||||
section_header = f.read()
|
||||
LEN_SEC_HEADER = 0x28
|
||||
len_bytes = section_header_count * self.LEN_SEC_HEADER
|
||||
section_header = f.read(len_bytes)
|
||||
if len(section_header) == 0:
|
||||
raise FatalError("No section header found at offset %04x in ELF file." % section_header_offs)
|
||||
if len(section_header) % LEN_SEC_HEADER != 0:
|
||||
print('WARNING: Unexpected ELF section header length %04x is not mod-%02x' % (len(section_header),LEN_SEC_HEADER))
|
||||
if len(section_header) != (len_bytes):
|
||||
raise FatalError("Only read 0x%x bytes from section header (expected 0x%x.) Truncated ELF file?" % (len(section_header), len_bytes))
|
||||
|
||||
# walk through the section header and extract all sections
|
||||
section_header_offsets = range(0, len(section_header), LEN_SEC_HEADER)
|
||||
section_header_offsets = range(0, len(section_header), self.LEN_SEC_HEADER)
|
||||
|
||||
def read_section_header(offs):
|
||||
name_offs,sec_type,_flags,lma,sec_offs,size = struct.unpack_from("<LLLLLL", section_header[offs:])
|
||||
@ -1372,9 +1523,9 @@ class ELFFile(object):
|
||||
prog_sections = [s for s in all_sections if s[1] == ELFFile.SEC_TYPE_PROGBITS]
|
||||
|
||||
# search for the string table section
|
||||
if not shstrndx * LEN_SEC_HEADER in section_header_offsets:
|
||||
if not (shstrndx * self.LEN_SEC_HEADER) in section_header_offsets:
|
||||
raise FatalError("ELF file has no STRTAB section at shstrndx %d" % shstrndx)
|
||||
_,sec_type,_,sec_size,sec_offs = read_section_header(shstrndx * LEN_SEC_HEADER)
|
||||
_,sec_type,_,sec_size,sec_offs = read_section_header(shstrndx * self.LEN_SEC_HEADER)
|
||||
if sec_type != ELFFile.SEC_TYPE_STRTAB:
|
||||
print('WARNING: ELF file has incorrect STRTAB section type 0x%02x' % sec_type)
|
||||
f.seek(sec_offs)
|
||||
@ -1573,7 +1724,7 @@ def detect_flash_size(esp, args):
|
||||
if args.flash_size == 'detect':
|
||||
flash_id = esp.flash_id()
|
||||
size_id = flash_id >> 16
|
||||
args.flash_size = {0x12: '256KB', 0x13: '512KB', 0x14: '1MB', 0x15: '2MB', 0x16: '4MB', 0x17: '8MB', 0x18: '16MB'}.get(size_id)
|
||||
args.flash_size = DETECTED_FLASH_SIZES.get(size_id)
|
||||
if args.flash_size is None:
|
||||
print('Warning: Could not auto-detect Flash size (FlashID=0x%x, SizeID=0x%x), defaulting to 4MB' % (flash_id, size_id))
|
||||
args.flash_size = '4MB'
|
||||
@ -1581,27 +1732,35 @@ def detect_flash_size(esp, args):
|
||||
print('Auto-detected Flash size:', args.flash_size)
|
||||
|
||||
|
||||
def _get_flash_params(esp, args):
|
||||
""" Return binary flash parameters (bitstring length 2) for args """
|
||||
detect_flash_size(esp, args)
|
||||
def _update_image_flash_params(esp, address, args, image):
|
||||
""" Modify the flash mode & size bytes if this looks like an executable bootloader image """
|
||||
if len(image) < 8:
|
||||
return image # not long enough to be a bootloader image
|
||||
|
||||
# unpack the (potential) image header
|
||||
magic, _, flash_mode, flash_size_freq = struct.unpack("BBBB", image[:4])
|
||||
if address != esp.BOOTLOADER_FLASH_OFFSET or magic != esp.ESP_IMAGE_MAGIC:
|
||||
return image # not flashing a bootloader, so don't modify this
|
||||
|
||||
if args.flash_mode != 'keep':
|
||||
flash_mode = {'qio':0, 'qout':1, 'dio':2, 'dout': 3}[args.flash_mode]
|
||||
flash_size_freq = esp.parse_flash_size_arg(args.flash_size)
|
||||
flash_size_freq += {'40m':0, '26m':1, '20m':2, '80m': 0xf}[args.flash_freq]
|
||||
return struct.pack(b'BB', flash_mode, flash_size_freq)
|
||||
|
||||
flash_freq = flash_size_freq & 0x0F
|
||||
if args.flash_freq != 'keep':
|
||||
flash_freq = {'40m':0, '26m':1, '20m':2, '80m': 0xf}[args.flash_freq]
|
||||
|
||||
def _update_image_flash_params(esp, address, flash_params, image):
|
||||
""" Modify the flash mode & size bytes if this looks like an executable image """
|
||||
if address == esp.FLASH_HEADER_OFFSET and (image[0] == '\xe9' or image[0] == 0xE9): # python 2/3 compat:
|
||||
flash_size = flash_size_freq & 0xF0
|
||||
if args.flash_size != 'keep':
|
||||
flash_size = esp.parse_flash_size_arg(args.flash_size)
|
||||
|
||||
flash_params = struct.pack(b'BB', flash_mode, flash_size + flash_freq)
|
||||
if flash_params != image[2:4]:
|
||||
print('Flash params set to 0x%04x' % struct.unpack(">H", flash_params))
|
||||
image = image[0:2] + flash_params + image[4:]
|
||||
return image
|
||||
|
||||
|
||||
def write_flash(esp, args):
|
||||
flash_params = _get_flash_params(esp, args)
|
||||
|
||||
# set args.compress based on default behaviour:
|
||||
# -> if either --compress or --no-compress is set, honour that
|
||||
# -> otherwise, set --compress unless --no-stub is set
|
||||
@ -1622,19 +1781,23 @@ def write_flash(esp, args):
|
||||
if args.no_stub:
|
||||
print('Erasing flash...')
|
||||
image = pad_to(argfile.read(), 4)
|
||||
image = _update_image_flash_params(esp, address, flash_params, image)
|
||||
image = _update_image_flash_params(esp, address, args, image)
|
||||
calcmd5 = hashlib.md5(image).hexdigest()
|
||||
uncsize = len(image)
|
||||
if args.compress:
|
||||
uncimage = image
|
||||
image = zlib.compress(uncimage, 9)
|
||||
ratio = uncsize / len(image)
|
||||
blocks = esp.flash_defl_begin(uncsize, len(image), address)
|
||||
else:
|
||||
ratio = 1.0
|
||||
blocks = esp.flash_begin(uncsize, address)
|
||||
argfile.seek(0) # in case we need it again
|
||||
seq = 0
|
||||
written = 0
|
||||
t = time.time()
|
||||
esp._port.timeout = min(DEFAULT_TIMEOUT * ratio,
|
||||
CHIP_ERASE_TIMEOUT * 2)
|
||||
while len(image) > 0:
|
||||
print('\rWriting at 0x%08x... (%d %%)' % (address + seq * esp.FLASH_WRITE_SIZE, 100 * (seq + 1) // blocks), end='')
|
||||
sys.stdout.flush()
|
||||
@ -1669,6 +1832,8 @@ def write_flash(esp, args):
|
||||
print('Hash of data verified.')
|
||||
except NotImplementedInROMError:
|
||||
pass
|
||||
esp._port.timeout = DEFAULT_TIMEOUT
|
||||
|
||||
print('\nLeaving...')
|
||||
|
||||
if esp.IS_STUB:
|
||||
@ -1683,7 +1848,7 @@ def write_flash(esp, args):
|
||||
if args.verify:
|
||||
print('Verifying just-written flash...')
|
||||
print('(This option is deprecated, flash contents are now always read back after flashing.)')
|
||||
_verify_flash(esp, args)
|
||||
verify_flash(esp, args)
|
||||
|
||||
|
||||
def image_info(args):
|
||||
@ -1771,7 +1936,9 @@ def run(esp, args):
|
||||
def flash_id(esp, args):
|
||||
flash_id = esp.flash_id()
|
||||
print('Manufacturer: %02x' % (flash_id & 0xff))
|
||||
print('Device: %02x%02x' % ((flash_id >> 8) & 0xff, (flash_id >> 16) & 0xff))
|
||||
flid_lowbyte = (flash_id >> 16) & 0xFF
|
||||
print('Device: %02x%02x' % ((flash_id >> 8) & 0xff, flid_lowbyte))
|
||||
print('Detected flash size: %s' % (DETECTED_FLASH_SIZES.get(flid_lowbyte, "Unknown")))
|
||||
|
||||
|
||||
def read_flash(esp, args):
|
||||
@ -1793,19 +1960,14 @@ def read_flash(esp, args):
|
||||
open(args.filename, 'wb').write(data)
|
||||
|
||||
|
||||
def verify_flash(esp, args, flash_params=None):
|
||||
_verify_flash(esp, args)
|
||||
|
||||
|
||||
def _verify_flash(esp, args):
|
||||
def verify_flash(esp, args):
|
||||
differences = False
|
||||
flash_params = _get_flash_params(esp, args)
|
||||
|
||||
for address, argfile in args.addr_filename:
|
||||
image = pad_to(argfile.read(), 4)
|
||||
argfile.seek(0) # rewind in case we need it again
|
||||
|
||||
image = _update_image_flash_params(esp, address, flash_params, image)
|
||||
image = _update_image_flash_params(esp, address, args, image)
|
||||
|
||||
image_size = len(image)
|
||||
print('Verifying 0x%x (%d) bytes @ 0x%08x in flash against %s...' % (image_size, image_size, address, argfile.name))
|
||||
@ -1926,16 +2088,19 @@ def main():
|
||||
parser_write_mem.add_argument('value', help='Value', type=arg_auto_int)
|
||||
parser_write_mem.add_argument('mask', help='Mask of bits to write', type=arg_auto_int)
|
||||
|
||||
def add_spi_flash_subparsers(parent, auto_detect=False):
|
||||
def add_spi_flash_subparsers(parent, is_elf2image):
|
||||
""" Add common parser arguments for SPI flash properties """
|
||||
extra_keep_args = [] if is_elf2image else ['keep']
|
||||
auto_detect = not is_elf2image
|
||||
|
||||
parent.add_argument('--flash_freq', '-ff', help='SPI Flash frequency',
|
||||
choices=['40m', '26m', '20m', '80m'],
|
||||
default=os.environ.get('ESPTOOL_FF', '40m'))
|
||||
choices=extra_keep_args + ['40m', '26m', '20m', '80m'],
|
||||
default=os.environ.get('ESPTOOL_FF', '40m' if is_elf2image else 'keep'))
|
||||
parent.add_argument('--flash_mode', '-fm', help='SPI Flash mode',
|
||||
choices=['qio', 'qout', 'dio', 'dout'],
|
||||
default=os.environ.get('ESPTOOL_FM', 'qio'))
|
||||
choices=extra_keep_args + ['qio', 'qout', 'dio', 'dout'],
|
||||
default=os.environ.get('ESPTOOL_FM', 'qio' if is_elf2image else 'keep'))
|
||||
parent.add_argument('--flash_size', '-fs', help='SPI Flash size in MegaBytes (1MB, 2MB, 4MB, 8MB, 16M)'
|
||||
' plus ESP8266-only (256KB, 512KB, 2MB-c1, 4MB-c1, 4MB-2)',
|
||||
' plus ESP8266-only (256KB, 512KB, 2MB-c1, 4MB-c1)',
|
||||
action=FlashSizeAction, auto_detect=auto_detect,
|
||||
default=os.environ.get('ESPTOOL_FS', 'detect' if auto_detect else '1MB'))
|
||||
add_spi_connection_arg(parent)
|
||||
@ -1945,7 +2110,7 @@ def main():
|
||||
help='Write a binary blob to flash')
|
||||
parser_write_flash.add_argument('addr_filename', metavar='<address> <filename>', help='Address followed by binary filename, separated by space',
|
||||
action=AddrFilenamePairAction)
|
||||
add_spi_flash_subparsers(parser_write_flash, auto_detect=True)
|
||||
add_spi_flash_subparsers(parser_write_flash, is_elf2image=False)
|
||||
parser_write_flash.add_argument('--no-progress', '-p', help='Suppress progress output', action="store_true")
|
||||
parser_write_flash.add_argument('--verify', help='Verify just-written data on flash ' +
|
||||
'(mostly superfluous, data is read back during flashing)', action='store_true')
|
||||
@ -1977,7 +2142,7 @@ def main():
|
||||
parser_elf2image.add_argument('--output', '-o', help='Output filename prefix (for version 1 image), or filename (for version 2 single image)', type=str)
|
||||
parser_elf2image.add_argument('--version', '-e', help='Output image version', choices=['1','2'], default='1')
|
||||
|
||||
add_spi_flash_subparsers(parser_elf2image)
|
||||
add_spi_flash_subparsers(parser_elf2image, is_elf2image=True)
|
||||
|
||||
subparsers.add_parser(
|
||||
'read_mac',
|
||||
@ -2024,7 +2189,7 @@ def main():
|
||||
action=AddrFilenamePairAction)
|
||||
parser_verify_flash.add_argument('--diff', '-d', help='Show differences',
|
||||
choices=['no', 'yes'], default='no')
|
||||
add_spi_flash_subparsers(parser_verify_flash, auto_detect=True)
|
||||
add_spi_flash_subparsers(parser_verify_flash, is_elf2image=False)
|
||||
|
||||
parser_erase_flash = subparsers.add_parser(
|
||||
'erase_flash',
|
||||
@ -2072,6 +2237,8 @@ def main():
|
||||
esp = chip_class(args.port, initial_baud)
|
||||
esp.connect(args.before)
|
||||
|
||||
print("Chip is %s" % (esp.get_chip_description()))
|
||||
|
||||
if not args.no_stub:
|
||||
esp = esp.run_stub()
|
||||
|
||||
@ -2155,7 +2322,6 @@ class FlashSizeAction(argparse.Action):
|
||||
'32m': '4MB',
|
||||
'16m-c1': '2MB-c1',
|
||||
'32m-c1': '4MB-c1',
|
||||
'32m-c2': '4MB-c2'
|
||||
}[values[0]]
|
||||
print("WARNING: Flash size arguments in megabits like '%s' are deprecated." % (values[0]))
|
||||
print("Please use the equivalent size '%s'." % (value))
|
||||
|
Binary file not shown.
@ -4,8 +4,23 @@
|
||||
#
|
||||
# Converts partition tables to/from CSV and binary formats.
|
||||
#
|
||||
# See http://esp-idf.readthedocs.io/en/latest/partition-tables.html for explanation of
|
||||
# partition table structure and uses.
|
||||
# See http://esp-idf.readthedocs.io/en/latest/api-guides/partition-tables.html
|
||||
# for explanation of partition table structure and uses.
|
||||
#
|
||||
# Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http:#www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
from __future__ import print_function, division
|
||||
import argparse
|
||||
import os
|
||||
import re
|
||||
@ -80,7 +95,7 @@ class PartitionTable(list):
|
||||
p.verify()
|
||||
# check for overlaps
|
||||
last = None
|
||||
for p in sorted(self):
|
||||
for p in sorted(self, key=lambda x:x.offset):
|
||||
if p.offset < 0x5000:
|
||||
raise InputError("Partition offset 0x%x is below 0x5000" % p.offset)
|
||||
if last is not None and p.offset < last.offset + last.size:
|
||||
@ -94,16 +109,16 @@ class PartitionTable(list):
|
||||
data = b[o:o+32]
|
||||
if len(data) != 32:
|
||||
raise InputError("Partition table length must be a multiple of 32 bytes")
|
||||
if data == '\xFF'*32:
|
||||
if data == b'\xFF'*32:
|
||||
return result # got end marker
|
||||
result.append(PartitionDefinition.from_binary(data))
|
||||
raise InputError("Partition table is missing an end-of-table marker")
|
||||
|
||||
def to_binary(self):
|
||||
result = "".join(e.to_binary() for e in self)
|
||||
result = b"".join(e.to_binary() for e in self)
|
||||
if len(result )>= MAX_PARTITION_LENGTH:
|
||||
raise InputError("Binary partition table length (%d) longer than max" % len(result))
|
||||
result += "\xFF" * (MAX_PARTITION_LENGTH - len(result)) # pad the sector, for signing
|
||||
result += b"\xFF" * (MAX_PARTITION_LENGTH - len(result)) # pad the sector, for signing
|
||||
return result
|
||||
|
||||
def to_csv(self, simple_formatting=False):
|
||||
@ -137,10 +152,10 @@ class PartitionDefinition(object):
|
||||
},
|
||||
}
|
||||
|
||||
MAGIC_BYTES = "\xAA\x50"
|
||||
MAGIC_BYTES = b"\xAA\x50"
|
||||
|
||||
ALIGNMENT = {
|
||||
APP_TYPE : 0x1000,
|
||||
APP_TYPE : 0x10000,
|
||||
DATA_TYPE : 0x04,
|
||||
}
|
||||
|
||||
@ -226,16 +241,16 @@ class PartitionDefinition(object):
|
||||
|
||||
def verify(self):
|
||||
if self.type is None:
|
||||
raise ValidationError("Type field is not set")
|
||||
raise ValidationError(self, "Type field is not set")
|
||||
if self.subtype is None:
|
||||
raise ValidationError("Subtype field is not set")
|
||||
raise ValidationError(self, "Subtype field is not set")
|
||||
if self.offset is None:
|
||||
raise ValidationError("Offset field is not set")
|
||||
raise ValidationError(self, "Offset field is not set")
|
||||
align = self.ALIGNMENT.get(self.type, 4)
|
||||
if self.offset % align:
|
||||
raise ValidationError("%s offset 0x%x is not aligned to 0x%x" % (self.name, self.offset, align))
|
||||
raise ValidationError(self, "Offset 0x%x is not aligned to 0x%x" % (self.offset, align))
|
||||
if self.size is None:
|
||||
raise ValidationError("Size field is not set")
|
||||
raise ValidationError(self, "Size field is not set")
|
||||
|
||||
STRUCT_FORMAT = "<2sBBLL16sL"
|
||||
|
||||
@ -246,8 +261,9 @@ class PartitionDefinition(object):
|
||||
res = cls()
|
||||
(magic, res.type, res.subtype, res.offset,
|
||||
res.size, res.name, flags) = struct.unpack(cls.STRUCT_FORMAT, b)
|
||||
if "\x00" in res.name: # strip null byte padding from name string
|
||||
res.name = res.name[:res.name.index("\x00")]
|
||||
if b"\x00" in res.name: # strip null byte padding from name string
|
||||
res.name = res.name[:res.name.index(b"\x00")]
|
||||
res.name = res.name.decode()
|
||||
if magic != cls.MAGIC_BYTES:
|
||||
raise InputError("Invalid magic bytes (%r) for partition definition" % magic)
|
||||
for flag,bit in cls.FLAGS.items():
|
||||
@ -267,7 +283,7 @@ class PartitionDefinition(object):
|
||||
self.MAGIC_BYTES,
|
||||
self.type, self.subtype,
|
||||
self.offset, self.size,
|
||||
self.name,
|
||||
self.name.encode(),
|
||||
flags)
|
||||
|
||||
def to_csv(self, simple_formatting=False):
|
||||
@ -275,7 +291,7 @@ class PartitionDefinition(object):
|
||||
if not simple_formatting and include_sizes:
|
||||
for (val, suffix) in [ (0x100000, "M"), (0x400, "K") ]:
|
||||
if a % val == 0:
|
||||
return "%d%s" % (a / val, suffix)
|
||||
return "%d%s" % (a // val, suffix)
|
||||
return "0x%x" % a
|
||||
|
||||
def lookup_keyword(t, keywords):
|
||||
@ -295,9 +311,6 @@ class PartitionDefinition(object):
|
||||
addr_format(self.size, True),
|
||||
generate_text_flags()])
|
||||
|
||||
class InputError(RuntimeError):
|
||||
def __init__(self, e):
|
||||
super(InputError, self).__init__(e)
|
||||
|
||||
def parse_int(v, keywords={}):
|
||||
"""Generic parser for integer fields - int(x,0) with provision for
|
||||
@ -323,7 +336,7 @@ def main():
|
||||
parser.add_argument('--verify', '-v', help='Verify partition table fields', default=True, action='store_false')
|
||||
parser.add_argument('--quiet', '-q', help="Don't print status messages to stderr", action='store_true')
|
||||
|
||||
parser.add_argument('input', help='Path to CSV or binary file to parse. Will use stdin if omitted.', type=argparse.FileType('r'), default=sys.stdin)
|
||||
parser.add_argument('input', help='Path to CSV or binary file to parse. Will use stdin if omitted.', type=argparse.FileType('rb'), default=sys.stdin)
|
||||
parser.add_argument('output', help='Path to output converted binary or CSV file. Will use stdout if omitted, unless the --display argument is also passed (in which case only the summary is printed.)',
|
||||
nargs='?',
|
||||
default='-')
|
||||
@ -337,6 +350,7 @@ def main():
|
||||
status("Parsing binary partition input...")
|
||||
table = PartitionTable.from_binary(input)
|
||||
else:
|
||||
input = input.decode()
|
||||
status("Parsing CSV input...")
|
||||
table = PartitionTable.from_csv(input)
|
||||
|
||||
@ -346,14 +360,28 @@ def main():
|
||||
|
||||
if input_is_binary:
|
||||
output = table.to_csv()
|
||||
else:
|
||||
output = table.to_binary()
|
||||
with sys.stdout if args.output == '-' else open(args.output, 'w') as f:
|
||||
f.write(output)
|
||||
else:
|
||||
output = table.to_binary()
|
||||
with sys.stdout.buffer if args.output == '-' else open(args.output, 'wb') as f:
|
||||
f.write(output)
|
||||
|
||||
|
||||
class InputError(RuntimeError):
|
||||
def __init__(self, e):
|
||||
super(InputError, self).__init__(e)
|
||||
|
||||
|
||||
class ValidationError(InputError):
|
||||
def __init__(self, partition, message):
|
||||
super(ValidationError, self).__init__(
|
||||
"Partition %s invalid: %s" % (partition.name, message))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
main()
|
||||
except InputError as e:
|
||||
print >>sys.stderr, e
|
||||
print(e, file=sys.stderr)
|
||||
sys.exit(2)
|
||||
|
@ -51,6 +51,7 @@ env.Prepend(
|
||||
CPPPATH=[
|
||||
join(FRAMEWORK_DIR, "tools", "sdk", "include", "config"),
|
||||
join(FRAMEWORK_DIR, "tools", "sdk", "include", "bluedroid"),
|
||||
join(FRAMEWORK_DIR, "tools", "sdk", "include", "app_trace"),
|
||||
join(FRAMEWORK_DIR, "tools", "sdk", "include", "app_update"),
|
||||
join(FRAMEWORK_DIR, "tools", "sdk", "include", "bootloader_support"),
|
||||
join(FRAMEWORK_DIR, "tools", "sdk", "include", "bt"),
|
||||
@ -59,6 +60,7 @@ env.Prepend(
|
||||
join(FRAMEWORK_DIR, "tools", "sdk", "include", "ethernet"),
|
||||
join(FRAMEWORK_DIR, "tools", "sdk", "include", "fatfs"),
|
||||
join(FRAMEWORK_DIR, "tools", "sdk", "include", "freertos"),
|
||||
join(FRAMEWORK_DIR, "tools", "sdk", "include", "heap"),
|
||||
join(FRAMEWORK_DIR, "tools", "sdk", "include", "jsmn"),
|
||||
join(FRAMEWORK_DIR, "tools", "sdk", "include", "log"),
|
||||
join(FRAMEWORK_DIR, "tools", "sdk", "include", "mdns"),
|
||||
@ -89,7 +91,7 @@ env.Prepend(
|
||||
join(FRAMEWORK_DIR, "tools", "sdk", "ld")
|
||||
],
|
||||
LIBS=[
|
||||
"gcc", "stdc++", "app_update", "bootloader_support", "bt", "btdm_app", "c", "c_nano", "coap", "coexist", "core", "cxx", "driver", "esp32", "ethernet", "expat", "fatfs", "freertos", "hal", "jsmn", "json", "log", "lwip", "m", "mbedtls", "mdns", "micro-ecc", "net80211", "newlib", "nghttp", "nvs_flash", "openssl", "phy", "pp", "rtc", "sdmmc", "smartconfig", "soc", "spi_flash", "tcpip_adapter", "ulp", "vfs", "wear_levelling", "wpa", "wpa2", "wpa_supplicant", "wps", "xtensa-debug-module"
|
||||
"gcc", "stdc++", "app_trace", "app_update", "bootloader_support", "bt", "btdm_app", "c", "c_nano", "coap", "coexist", "core", "cxx", "driver", "esp32", "ethernet", "expat", "fatfs", "freertos", "hal", "heap", "jsmn", "json", "libsodium", "log", "lwip", "m", "mbedtls", "mdns", "micro-ecc", "net80211", "newlib", "nghttp", "nvs_flash", "openssl", "phy", "pp", "rtc", "sdmmc", "smartconfig", "soc", "spi_flash", "tcpip_adapter", "ulp", "vfs", "wear_levelling", "wpa", "wpa2", "wpa_supplicant", "wps", "xtensa-debug-module"
|
||||
],
|
||||
|
||||
UPLOADERFLAGS=[
|
||||
|
Binary file not shown.
BIN
tools/sdk/bin/bootloader_qio.bin
Normal file
BIN
tools/sdk/bin/bootloader_qio.bin
Normal file
Binary file not shown.
168
tools/sdk/include/app_trace/esp_ota_ops.h
Executable file
168
tools/sdk/include/app_trace/esp_ota_ops.h
Executable file
@ -0,0 +1,168 @@
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef _OTA_OPS_H
|
||||
#define _OTA_OPS_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include "esp_err.h"
|
||||
#include "esp_partition.h"
|
||||
#include "esp_spi_flash.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#define OTA_SIZE_UNKNOWN 0xffffffff /*!< Used for esp_ota_begin() if new image size is unknown */
|
||||
|
||||
#define ESP_ERR_OTA_BASE 0x1500 /*!< Base error code for ota_ops api */
|
||||
#define ESP_ERR_OTA_PARTITION_CONFLICT (ESP_ERR_OTA_BASE + 0x01) /*!< Error if request was to write or erase the current running partition */
|
||||
#define ESP_ERR_OTA_SELECT_INFO_INVALID (ESP_ERR_OTA_BASE + 0x02) /*!< Error if OTA data partition contains invalid content */
|
||||
#define ESP_ERR_OTA_VALIDATE_FAILED (ESP_ERR_OTA_BASE + 0x03) /*!< Error if OTA app image is invalid */
|
||||
|
||||
/**
|
||||
* @brief Opaque handle for an application OTA update
|
||||
*
|
||||
* esp_ota_begin() returns a handle which is then used for subsequent
|
||||
* calls to esp_ota_write() and esp_ota_end().
|
||||
*/
|
||||
typedef uint32_t esp_ota_handle_t;
|
||||
|
||||
/**
|
||||
* @brief Commence an OTA update writing to the specified partition.
|
||||
|
||||
* The specified partition is erased to the specified image size.
|
||||
*
|
||||
* If image size is not yet known, pass OTA_SIZE_UNKNOWN which will
|
||||
* cause the entire partition to be erased.
|
||||
*
|
||||
* On success, this function allocates memory that remains in use
|
||||
* until esp_ota_end() is called with the returned handle.
|
||||
*
|
||||
* @param partition Pointer to info for partition which will receive the OTA update. Required.
|
||||
* @param image_size Size of new OTA app image. Partition will be erased in order to receive this size of image. If 0 or OTA_SIZE_UNKNOWN, the entire partition is erased.
|
||||
* @param out_handle On success, returns a handle which should be used for subsequent esp_ota_write() and esp_ota_end() calls.
|
||||
|
||||
* @return
|
||||
* - ESP_OK: OTA operation commenced successfully.
|
||||
* - ESP_ERR_INVALID_ARG: partition or out_handle arguments were NULL, or partition doesn't point to an OTA app partition.
|
||||
* - ESP_ERR_NO_MEM: Cannot allocate memory for OTA operation.
|
||||
* - ESP_ERR_OTA_PARTITION_CONFLICT: Partition holds the currently running firmware, cannot update in place.
|
||||
* - ESP_ERR_NOT_FOUND: Partition argument not found in partition table.
|
||||
* - ESP_ERR_OTA_SELECT_INFO_INVALID: The OTA data partition contains invalid data.
|
||||
* - ESP_ERR_INVALID_SIZE: Partition doesn't fit in configured flash size.
|
||||
* - ESP_ERR_FLASH_OP_TIMEOUT or ESP_ERR_FLASH_OP_FAIL: Flash write failed.
|
||||
*/
|
||||
esp_err_t esp_ota_begin(const esp_partition_t* partition, size_t image_size, esp_ota_handle_t* out_handle);
|
||||
|
||||
/**
|
||||
* @brief Write OTA update data to partition
|
||||
*
|
||||
* This function can be called multiple times as
|
||||
* data is received during the OTA operation. Data is written
|
||||
* sequentially to the partition.
|
||||
*
|
||||
* @param handle Handle obtained from esp_ota_begin
|
||||
* @param data Data buffer to write
|
||||
* @param size Size of data buffer in bytes.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Data was written to flash successfully.
|
||||
* - ESP_ERR_INVALID_ARG: handle is invalid.
|
||||
* - ESP_ERR_OTA_VALIDATE_FAILED: First byte of image contains invalid app image magic byte.
|
||||
* - ESP_ERR_FLASH_OP_TIMEOUT or ESP_ERR_FLASH_OP_FAIL: Flash write failed.
|
||||
* - ESP_ERR_OTA_SELECT_INFO_INVALID: OTA data partition has invalid contents
|
||||
*/
|
||||
esp_err_t esp_ota_write(esp_ota_handle_t handle, const void* data, size_t size);
|
||||
|
||||
/**
|
||||
* @brief Finish OTA update and validate newly written app image.
|
||||
*
|
||||
* @param handle Handle obtained from esp_ota_begin().
|
||||
*
|
||||
* @note After calling esp_ota_end(), the handle is no longer valid and any memory associated with it is freed (regardless of result).
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Newly written OTA app image is valid.
|
||||
* - ESP_ERR_NOT_FOUND: OTA handle was not found.
|
||||
* - ESP_ERR_INVALID_ARG: Handle was never written to.
|
||||
* - ESP_ERR_OTA_VALIDATE_FAILED: OTA image is invalid (either not a valid app image, or - if secure boot is enabled - signature failed to verify.)
|
||||
* - ESP_ERR_INVALID_STATE: If flash encryption is enabled, this result indicates an internal error writing the final encrypted bytes to flash.
|
||||
*/
|
||||
esp_err_t esp_ota_end(esp_ota_handle_t handle);
|
||||
|
||||
/**
|
||||
* @brief Configure OTA data for a new boot partition
|
||||
*
|
||||
* @note If this function returns ESP_OK, calling esp_restart() will boot the newly configured app partition.
|
||||
*
|
||||
* @param partition Pointer to info for partition containing app image to boot.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: OTA data updated, next reboot will use specified partition.
|
||||
* - ESP_ERR_INVALID_ARG: partition argument was NULL or didn't point to a valid OTA partition of type "app".
|
||||
* - ESP_ERR_OTA_VALIDATE_FAILED: Partition contained invalid app image. Also returned if secure boot is enabled and signature validation failed.
|
||||
* - ESP_ERR_NOT_FOUND: OTA data partition not found.
|
||||
* - ESP_ERR_FLASH_OP_TIMEOUT or ESP_ERR_FLASH_OP_FAIL: Flash erase or write failed.
|
||||
*/
|
||||
esp_err_t esp_ota_set_boot_partition(const esp_partition_t* partition);
|
||||
|
||||
/**
|
||||
* @brief Get partition info of currently configured boot app
|
||||
*
|
||||
* If esp_ota_set_boot_partition() has been called, the partition which was set by that function will be returned.
|
||||
*
|
||||
* If esp_ota_set_boot_partition() has not been called, the result is
|
||||
* equivalent to esp_ota_get_running_partition().
|
||||
*
|
||||
* @return Pointer to info for partition structure, or NULL if no partition is found or flash read operation failed. Returned pointer is valid for the lifetime of the application.
|
||||
*/
|
||||
const esp_partition_t* esp_ota_get_boot_partition(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get partition info of currently running app
|
||||
*
|
||||
* This function is different to esp_ota_get_boot_partition() in that
|
||||
* it ignores any change of selected boot partition caused by
|
||||
* esp_ota_set_boot_partition(). Only the app whose code is currently
|
||||
* running will have its partition information returned.
|
||||
*
|
||||
* @return Pointer to info for partition structure, or NULL if no partition is found or flash read operation failed. Returned pointer is valid for the lifetime of the application.
|
||||
*/
|
||||
const esp_partition_t* esp_ota_get_running_partition(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Return the next OTA app partition which should be written with a new firmware.
|
||||
*
|
||||
* Call this function to find an OTA app partition which can be passed to esp_ota_begin().
|
||||
*
|
||||
* Finds next partition round-robin, starting from the current running partition.
|
||||
*
|
||||
* @param start_from If set, treat this partition info as describing the current running partition. Can be NULL, in which case esp_ota_get_running_partition() is used to find the currently running partition. The result of this function is never the same as this argument.
|
||||
*
|
||||
* @return Pointer to info for partition which should be updated next. NULL result indicates invalid OTA data partition, or that no eligible OTA app slot partition was found.
|
||||
*
|
||||
*/
|
||||
const esp_partition_t* esp_ota_get_next_update_partition(const esp_partition_t *start_from);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* OTA_OPS_H */
|
@ -21,6 +21,7 @@
|
||||
|
||||
#include <stddef.h>
|
||||
//#include <stdlib.h>
|
||||
#include "sdkconfig.h"
|
||||
|
||||
typedef void *(*alloc_fn)(size_t size);
|
||||
typedef void (*free_fn)(void *ptr);
|
||||
|
@ -75,8 +75,9 @@ typedef struct {
|
||||
/** Bluetooth Error Status */
|
||||
/** We need to build on this */
|
||||
|
||||
/* relate to ESP_BT_STATUS_xxx in esp_bt_defs.h */
|
||||
typedef enum {
|
||||
BT_STATUS_SUCCESS,
|
||||
BT_STATUS_SUCCESS = 0,
|
||||
BT_STATUS_FAIL,
|
||||
BT_STATUS_NOT_READY,
|
||||
BT_STATUS_NOMEM,
|
||||
@ -87,7 +88,12 @@ typedef enum {
|
||||
BT_STATUS_UNHANDLED,
|
||||
BT_STATUS_AUTH_FAILURE,
|
||||
BT_STATUS_RMT_DEV_DOWN,
|
||||
BT_STATUS_AUTH_REJECTED
|
||||
BT_STATUS_AUTH_REJECTED,
|
||||
BT_STATUS_INVALID_STATIC_RAND_ADDR,
|
||||
BT_STATUS_PENDING,
|
||||
BT_STATUS_UNACCEPT_CONN_INTERVAL,
|
||||
BT_STATUS_PARAM_OUT_OF_RANGE,
|
||||
BT_STATUS_TIMEOUT,
|
||||
} bt_status_t;
|
||||
|
||||
#ifndef CPU_LITTLE_ENDIAN
|
||||
|
@ -577,7 +577,11 @@
|
||||
|
||||
/* The number of security records for peer devices. 100 AS Default*/
|
||||
#ifndef BTM_SEC_MAX_DEVICE_RECORDS
|
||||
#define BTM_SEC_MAX_DEVICE_RECORDS 8 // 100
|
||||
#if SMP_INCLUDED == TRUE
|
||||
#define BTM_SEC_MAX_DEVICE_RECORDS 15 // 100
|
||||
#else
|
||||
#define BTM_SEC_MAX_DEVICE_RECORDS 8
|
||||
#endif /* SMP_INCLUDED == TRUE */
|
||||
#endif
|
||||
|
||||
/* The number of security records for services. 32 AS Default*/
|
||||
@ -729,7 +733,7 @@
|
||||
#if (CLASSIC_BT_INCLUDED == TRUE)
|
||||
#define MAX_L2CAP_CHANNELS 8
|
||||
#else
|
||||
#define MAX_L2CAP_CHANNELS 2 //Not support to create l2cap channels in the BLE only mode in this bluedroid version(6.0)
|
||||
#define MAX_L2CAP_CHANNELS MAX_ACL_CONNECTIONS //This is used in the BLE client when start connected with the peer device
|
||||
#endif ///CLASSIC_BT_INCLUDED == TRUE
|
||||
#endif
|
||||
|
||||
@ -953,6 +957,13 @@
|
||||
#define BLE_LLT_INCLUDED TRUE
|
||||
#endif
|
||||
|
||||
/* Added this marco to fixed the android 7.0 will lead to update connection parameters
|
||||
collision when the slave sent the HCI_BLE_UPD_LL_CONN_PARAMS comment to the controller
|
||||
request the master to update connection parameters directly. */
|
||||
#ifndef BLE_SLAVE_UPD_CONN_PARAMS
|
||||
#define BLE_SLAVE_UPD_CONN_PARAMS FALSE
|
||||
#endif
|
||||
|
||||
#ifndef ATT_INCLUDED
|
||||
#define ATT_INCLUDED TRUE
|
||||
#endif
|
||||
|
@ -54,7 +54,7 @@ inline void trc_dump_buffer(const char *prefix, uint8_t *data, uint16_t len)
|
||||
}
|
||||
|
||||
#ifdef BTTRC_DUMP_BUFFER
|
||||
#define BTTRC_DUMP_BUFFER(_prefix, _data, _len) trc_dump_buffer(_data, _len)
|
||||
#define BTTRC_DUMP_BUFFER(_prefix, _data, _len) trc_dump_buffer(_prefix, _data, _len)
|
||||
#else
|
||||
#define BTTRC_DUMP_BUFFER(_prefix, _data, _len)
|
||||
#endif
|
||||
|
@ -58,6 +58,7 @@ typedef bool BOOLEAN;
|
||||
*/
|
||||
#define BT_EVT_MASK 0xFF00
|
||||
#define BT_SUB_EVT_MASK 0x00FF
|
||||
#define BT_STATIC_RAND_ADDR_MASK 0xC0
|
||||
/* To Bluetooth Upper Layers */
|
||||
/************************************/
|
||||
#define BT_EVT_TO_BTU_L2C_EVT 0x0900 /* L2CAP event */
|
||||
|
@ -402,6 +402,8 @@ typedef void (tBTA_SET_ADV_DATA_CMPL_CBACK) (tBTA_STATUS status);
|
||||
|
||||
typedef void (tBTA_START_ADV_CMPL_CBACK) (tBTA_STATUS status);
|
||||
|
||||
typedef tBTM_SET_PKT_DATA_LENGTH_CBACK tBTA_SET_PKT_DATA_LENGTH_CBACK;
|
||||
|
||||
/* advertising channel map */
|
||||
#define BTA_BLE_ADV_CHNL_37 BTM_BLE_ADV_CHNL_37
|
||||
#define BTA_BLE_ADV_CHNL_38 BTM_BLE_ADV_CHNL_38
|
||||
@ -718,6 +720,10 @@ typedef UINT8 tBTA_DM_BLE_CONN_TYPE;
|
||||
|
||||
typedef BOOLEAN (tBTA_DM_BLE_SEL_CBACK)(BD_ADDR random_bda, UINT8 *p_remote_name);
|
||||
|
||||
typedef tBTM_LE_UPDATE_CONN_PRAMS tBTA_LE_UPDATE_CONN_PRAMS;
|
||||
typedef tBTM_UPDATE_CONN_PARAM_CBACK tBTA_UPDATE_CONN_PARAM_CBACK;
|
||||
|
||||
|
||||
/* Structure associated with BTA_DM_BLE_SEC_REQ_EVT */
|
||||
typedef struct {
|
||||
BD_ADDR bd_addr; /* peer address */
|
||||
@ -1067,6 +1073,7 @@ typedef void (tBTA_DM_EXEC_CBACK) (void *p_param);
|
||||
/* Encryption callback*/
|
||||
typedef void (tBTA_DM_ENCRYPT_CBACK) (BD_ADDR bd_addr, tBTA_TRANSPORT transport, tBTA_STATUS result);
|
||||
|
||||
/* relate to ESP_BLE_SEC_xxx in esp_gatt_defs.h */
|
||||
#if BLE_INCLUDED == TRUE
|
||||
#define BTA_DM_BLE_SEC_NONE BTM_BLE_SEC_NONE
|
||||
#define BTA_DM_BLE_SEC_ENCRYPT BTM_BLE_SEC_ENCRYPT
|
||||
@ -2009,7 +2016,7 @@ extern void BTA_DmSetEncryption(BD_ADDR bd_addr, tBTA_TRANSPORT transport,
|
||||
** Returns void
|
||||
**
|
||||
*******************************************************************************/
|
||||
extern void BTA_DmBleObserve(BOOLEAN start, UINT8 duration,
|
||||
extern void BTA_DmBleObserve(BOOLEAN start, UINT32 duration,
|
||||
tBTA_DM_SEARCH_CBACK *p_results_cb,
|
||||
tBTA_START_STOP_SCAN_CMPL_CBACK *p_start_stop_scan_cb);
|
||||
|
||||
@ -2201,7 +2208,18 @@ extern void BTA_BleDisableAdvInstance(UINT8 inst_id);
|
||||
**
|
||||
*******************************************************************************/
|
||||
extern void BTA_DmBleUpdateConnectionParams(BD_ADDR bd_addr, UINT16 min_int,
|
||||
UINT16 max_int, UINT16 latency, UINT16 timeout);
|
||||
UINT16 max_int, UINT16 latency, UINT16 timeout, tBTA_UPDATE_CONN_PARAM_CBACK *update_conn_param_cb);
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function BTA_DmBleDisconnect
|
||||
**
|
||||
** Description This function is to disconnect the ble connection
|
||||
**
|
||||
** Returns void
|
||||
**
|
||||
*******************************************************************************/
|
||||
extern void BTA_DmBleDisconnect(BD_ADDR bd_addr);
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
@ -2212,7 +2230,7 @@ extern void BTA_DmBleUpdateConnectionParams(BD_ADDR bd_addr, UINT16 min_int,
|
||||
** Returns void
|
||||
**
|
||||
*******************************************************************************/
|
||||
extern void BTA_DmBleSetDataLength(BD_ADDR remote_device, UINT16 tx_data_length);
|
||||
extern void BTA_DmBleSetDataLength(BD_ADDR remote_device, UINT16 tx_data_length, tBTA_SET_PKT_DATA_LENGTH_CBACK *p_set_pkt_data_cback);
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
|
@ -55,6 +55,7 @@ typedef struct {
|
||||
UINT8 inst_id; /* instance ID */
|
||||
} __attribute__((packed)) tBTA_GATT_ID;
|
||||
|
||||
/* relate to ESP_GATT_xxx in esp_gatt_def.h */
|
||||
/* Success code and error codes */
|
||||
#define BTA_GATT_OK GATT_SUCCESS
|
||||
#define BTA_GATT_INVALID_HANDLE GATT_INVALID_HANDLE /* 0x0001 */
|
||||
@ -94,11 +95,16 @@ typedef struct {
|
||||
#define BTA_GATT_NOT_ENCRYPTED GATT_NOT_ENCRYPTED /* 0x8e */
|
||||
#define BTA_GATT_CONGESTED GATT_CONGESTED /* 0x8f */
|
||||
|
||||
#define BTA_GATT_DUP_REG 0x90 /* 0x90 */
|
||||
#define BTA_GATT_ALREADY_OPEN 0x91 /* 0x91 */
|
||||
#define BTA_GATT_CANCEL 0x92 /* 0x92 */
|
||||
#define BTA_GATT_DUP_REG GATT_DUP_REG /* 0x90 */
|
||||
#define BTA_GATT_ALREADY_OPEN GATT_ALREADY_OPEN /* 0x91 */
|
||||
#define BTA_GATT_CANCEL GATT_CANCEL /* 0x92 */
|
||||
|
||||
/* 0xE0 ~ 0xFC reserved for future use */
|
||||
#define BTA_GATT_STACK_RSP GATT_STACK_RSP /* 0xE0 */
|
||||
#define BTA_GATT_APP_RSP GATT_APP_RSP /* 0xE1 */
|
||||
//Error caused by customer application or stack bug
|
||||
#define BTA_GATT_UNKNOWN_ERROR GATT_UNKNOWN_ERROR /* 0XEF */
|
||||
|
||||
#define BTA_GATT_CCC_CFG_ERR GATT_CCC_CFG_ERR /* 0xFD Client Characteristic Configuration Descriptor Improperly Configured */
|
||||
#define BTA_GATT_PRC_IN_PROGRESS GATT_PRC_IN_PROGRESS /* 0xFE Procedure Already in progress */
|
||||
#define BTA_GATT_OUT_OF_RANGE GATT_OUT_OF_RANGE /* 0xFFAttribute value out of range */
|
||||
@ -144,6 +150,8 @@ typedef UINT8 tBTA_GATT_STATUS;
|
||||
#define BTA_GATTC_SCAN_FLT_PARAM_EVT 32 /* Param filter event */
|
||||
#define BTA_GATTC_SCAN_FLT_STATUS_EVT 33 /* Filter status event */
|
||||
#define BTA_GATTC_ADV_VSC_EVT 34 /* ADV VSC event */
|
||||
#define BTA_GATTC_CONNECT_EVT 35 /* GATTC CONNECT event */
|
||||
#define BTA_GATTC_DISCONNECT_EVT 36 /* GATTC DISCONNECT event */
|
||||
|
||||
typedef UINT8 tBTA_GATTC_EVT;
|
||||
|
||||
@ -188,6 +196,7 @@ typedef struct {
|
||||
#define BTA_GATTC_TYPE_WRITE_NO_RSP GATT_WRITE_NO_RSP
|
||||
typedef UINT8 tBTA_GATTC_WRITE_TYPE;
|
||||
|
||||
/* relate to ESP_GATT_CONN_xxx in esp_gatt_defs.h */
|
||||
#define BTA_GATT_CONN_UNKNOWN 0
|
||||
#define BTA_GATT_CONN_L2C_FAILURE GATT_CONN_L2C_FAILURE /* general l2cap resource failure */
|
||||
#define BTA_GATT_CONN_TIMEOUT GATT_CONN_TIMEOUT /* 0x08 connection timeout */
|
||||
@ -240,6 +249,7 @@ typedef struct {
|
||||
|
||||
} tBTA_GATTC_MULTI;
|
||||
|
||||
/* relate to ESP_GATT_xxx in esp_gatt_def.h */
|
||||
#define BTA_GATT_AUTH_REQ_NONE GATT_AUTH_REQ_NONE
|
||||
#define BTA_GATT_AUTH_REQ_NO_MITM GATT_AUTH_REQ_NO_MITM /* unauthenticated encryption */
|
||||
#define BTA_GATT_AUTH_REQ_MITM GATT_AUTH_REQ_MITM /* authenticated encryption */
|
||||
@ -371,6 +381,20 @@ typedef struct {
|
||||
BD_ADDR remote_bda;
|
||||
} tBTA_GATTC_ENC_CMPL_CB;
|
||||
|
||||
typedef struct {
|
||||
tBTA_GATT_STATUS status;
|
||||
UINT16 conn_id;
|
||||
tBTA_GATTC_IF client_if;
|
||||
BD_ADDR remote_bda;
|
||||
} tBTA_GATTC_CONNECT;
|
||||
|
||||
typedef struct {
|
||||
tBTA_GATT_STATUS status;
|
||||
UINT16 conn_id;
|
||||
tBTA_GATTC_IF client_if;
|
||||
BD_ADDR remote_bda;
|
||||
} tBTA_GATTC_DISCONNECT;
|
||||
|
||||
typedef union {
|
||||
tBTA_GATT_STATUS status;
|
||||
|
||||
@ -378,7 +402,9 @@ typedef union {
|
||||
tBTA_GATTC_SRVC_RES srvc_res; /* discovery result */
|
||||
tBTA_GATTC_REG reg_oper; /* registration data */
|
||||
tBTA_GATTC_OPEN open;
|
||||
tBTA_GATTC_CONNECT connect;
|
||||
tBTA_GATTC_CLOSE close;
|
||||
tBTA_GATTC_DISCONNECT disconnect;
|
||||
tBTA_GATTC_READ read; /* read attribute/descriptor data */
|
||||
tBTA_GATTC_WRITE write; /* write complete data */
|
||||
tBTA_GATTC_EXEC_CMPL exec_cmpl; /* execute complete */
|
||||
@ -418,7 +444,7 @@ typedef void (tBTA_GATTC_CBACK)(tBTA_GATTC_EVT event, tBTA_GATTC *p_data);
|
||||
#define BTA_GATTS_CLOSE_EVT 18
|
||||
#define BTA_GATTS_LISTEN_EVT 19
|
||||
#define BTA_GATTS_CONGEST_EVT 20
|
||||
#define BTA_GATTS_SET_ATTR_VAL_EVT 21
|
||||
#define BTA_GATTS_SET_ATTR_VAL_EVT 23
|
||||
|
||||
typedef UINT8 tBTA_GATTS_EVT;
|
||||
typedef tGATT_IF tBTA_GATTS_IF;
|
||||
@ -489,6 +515,7 @@ typedef tGATT_VALUE tBTA_GATT_VALUE;
|
||||
/* attribute response data */
|
||||
typedef tGATTS_RSP tBTA_GATTS_RSP;
|
||||
|
||||
/* relate to ESP_GATT_PREP_WRITE_xxx in esp_gatt_defs.h */
|
||||
/* attribute request data from the client */
|
||||
#define BTA_GATT_PREP_WRITE_CANCEL 0x00
|
||||
#define BTA_GATT_PREP_WRITE_EXEC 0x01
|
||||
@ -573,6 +600,21 @@ typedef struct {
|
||||
tBTA_GATT_STATUS status; /* notification/indication status */
|
||||
} tBTA_GATTS_CONF;
|
||||
|
||||
typedef struct {
|
||||
tBTA_GATT_STATUS status;
|
||||
UINT16 conn_id; /* connection ID */
|
||||
} tBTA_GATTS_CLOSE;
|
||||
|
||||
typedef struct {
|
||||
tBTA_GATT_STATUS status;
|
||||
tBTA_GATTS_IF server_if;
|
||||
} tBTA_GATTS_OPEN;
|
||||
|
||||
typedef struct {
|
||||
tBTA_GATT_STATUS status;
|
||||
tBTA_GATTS_IF server_if;
|
||||
} tBTA_GATTS_CANCEL_OPEN;
|
||||
|
||||
/* GATTS callback data */
|
||||
typedef union {
|
||||
tBTA_GATTS_REG_OPER reg_oper;
|
||||
@ -587,8 +629,20 @@ typedef union {
|
||||
tBTA_GATTS_CONN conn; /* BTA_GATTS_CONN_EVT */
|
||||
tBTA_GATTS_CONGEST congest; /* BTA_GATTS_CONGEST_EVT callback data */
|
||||
tBTA_GATTS_CONF confirm; /* BTA_GATTS_CONF_EVT callback data */
|
||||
tBTA_GATTS_CLOSE close; /* BTA_GATTS_CLOSE_EVT callback data */
|
||||
tBTA_GATTS_OPEN open; /* BTA_GATTS_OPEN_EVT callback data */
|
||||
tBTA_GATTS_CANCEL_OPEN cancel_open; /* tBTA_GATTS_CANCEL_OPEN callback data */
|
||||
|
||||
} tBTA_GATTS;
|
||||
|
||||
/* GATTC wait for service change ccc timer callback data */
|
||||
typedef struct {
|
||||
UINT16 conn_id;
|
||||
BD_ADDR remote_bda;
|
||||
UINT8 count;
|
||||
UINT8 last_status;
|
||||
}tBTA_GATTC_WAIT_CCC_TIMER;
|
||||
|
||||
/* GATTS enable callback function */
|
||||
typedef void (tBTA_GATTS_ENB_CBACK)(tBTA_GATT_STATUS status);
|
||||
|
||||
|
@ -29,7 +29,6 @@
|
||||
#include "bta_gatt_api.h"
|
||||
#include "bta_gattc_ci.h"
|
||||
#include "bta_gattc_co.h"
|
||||
|
||||
#include "gki.h"
|
||||
|
||||
/*****************************************************************************
|
||||
@ -82,7 +81,11 @@ typedef UINT16 tBTA_GATTC_INT_EVT;
|
||||
|
||||
/* max known devices GATTC can support */
|
||||
#ifndef BTA_GATTC_KNOWN_SR_MAX
|
||||
#define BTA_GATTC_KNOWN_SR_MAX 3 // 10
|
||||
#if (GATT_MAX_PHY_CHANNEL > 3)
|
||||
#define BTA_GATTC_KNOWN_SR_MAX GATT_MAX_PHY_CHANNEL
|
||||
#else
|
||||
#define BTA_GATTC_KNOWN_SR_MAX 3 // The origin value is 10
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define BTA_GATTC_CONN_MAX GATT_MAX_PHY_CHANNEL
|
||||
@ -380,6 +383,9 @@ typedef struct {
|
||||
typedef struct {
|
||||
BOOLEAN in_use;
|
||||
BD_ADDR remote_bda;
|
||||
TIMER_LIST_ENT service_change_ccc_timer; /* wait for discovering remote device's service change ccc handle */
|
||||
BOOLEAN ccc_timer_used; /* service_change_ccc_timer started */
|
||||
BOOLEAN service_change_ccc_written; /* has written remote device's service change ccc */
|
||||
} tBTA_GATTC_CONN;
|
||||
|
||||
enum {
|
||||
@ -404,6 +410,16 @@ typedef struct {
|
||||
UINT16 sdp_conn_id;
|
||||
} tBTA_GATTC_CB;
|
||||
|
||||
typedef enum {
|
||||
SERVICE_CHANGE_CCC_WRITTEN_SUCCESS = 0,
|
||||
SERVICE_CHANGE_CACHE_NOT_FOUND,
|
||||
SERVICE_CHANGE_SERVICE_NOT_FOUND,
|
||||
SERVICE_CHANGE_CHAR_NOT_FOUND,
|
||||
SERVICE_CHANGE_CCC_NOT_FOUND,
|
||||
SERVICE_CHANGE_WRITE_CCC_FAILED
|
||||
}tBTA_GATTC_FIND_SERVICE_CB;
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
** Global data
|
||||
*****************************************************************************/
|
||||
@ -441,7 +457,8 @@ extern void bta_gattc_cancel_open_ok(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p
|
||||
extern void bta_gattc_cancel_open_error(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data);
|
||||
|
||||
extern void bta_gattc_conn(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data);
|
||||
|
||||
extern void bta_gattc_conncback(tBTA_GATTC_RCB *p_rcb, tBTA_GATTC_DATA *p_data);
|
||||
extern void bta_gattc_disconncback(tBTA_GATTC_RCB *p_rcb, tBTA_GATTC_DATA *p_data);
|
||||
extern void bta_gattc_close(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data);
|
||||
extern void bta_gattc_close_fail(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data);
|
||||
extern void bta_gattc_disc_close(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data);
|
||||
@ -468,6 +485,10 @@ extern void bta_gattc_init_bk_conn(tBTA_GATTC_API_OPEN *p_data, tBTA_GATTC_RCB *
|
||||
extern void bta_gattc_cancel_bk_conn(tBTA_GATTC_API_CANCEL_OPEN *p_data);
|
||||
extern void bta_gattc_send_open_cback( tBTA_GATTC_RCB *p_clreg, tBTA_GATT_STATUS status,
|
||||
BD_ADDR remote_bda, UINT16 conn_id, tBTA_TRANSPORT transport, UINT16 mtu);
|
||||
extern void bta_gattc_send_connect_cback( tBTA_GATTC_RCB *p_clreg, tBTA_GATT_STATUS status,
|
||||
BD_ADDR remote_bda, UINT16 conn_id);
|
||||
extern void bta_gattc_send_disconnect_cback( tBTA_GATTC_RCB *p_clreg, tBTA_GATT_STATUS status,
|
||||
BD_ADDR remote_bda, UINT16 conn_id);
|
||||
extern void bta_gattc_process_api_refresh(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg);
|
||||
extern void bta_gattc_cfg_mtu(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data);
|
||||
#if BLE_INCLUDED == TRUE
|
||||
|
@ -89,6 +89,9 @@ bt_status_t btc_storage_add_ble_bonding_key( bt_bdaddr_t *remote_bd_addr,
|
||||
uint8_t key_type,
|
||||
uint8_t key_length);
|
||||
|
||||
bool btc_compare_le_key_value(const uint8_t key_type, const size_t key_len, const tBTA_LE_KEY_VALUE *key_vaule,
|
||||
bt_bdaddr_t bd_addr);
|
||||
|
||||
void btc_save_ble_bonding_keys(void);
|
||||
|
||||
bt_status_t btc_in_fetch_bonded_ble_device(const char *remote_bd_addr, int add,
|
||||
@ -99,6 +102,8 @@ bt_status_t btc_storage_get_ble_bonding_key(bt_bdaddr_t *remote_bd_addr,
|
||||
char *key_value,
|
||||
int key_length);
|
||||
|
||||
bool btc_storage_compare_address_key_value(uint8_t key_type, void *key_value, int key_length);
|
||||
|
||||
bt_status_t btc_storage_add_ble_local_key(char *key,
|
||||
uint8_t key_type,
|
||||
uint8_t key_length);
|
||||
|
@ -49,6 +49,7 @@ int btc_config_clear(void);
|
||||
|
||||
// TODO(zachoverflow): Eww...we need to move these out. These are peer specific, not config general.
|
||||
bool btc_get_address_type(const BD_ADDR bd_addr, int *p_addr_type);
|
||||
bool btc_compare_address_key_value(char *key_type, void *key_value, int key_length);
|
||||
bool btc_get_device_type(const BD_ADDR bd_addr, int *p_device_type);
|
||||
|
||||
#endif
|
||||
|
@ -39,6 +39,7 @@ typedef enum {
|
||||
BTC_GAP_BLE_SECURITY_RSP_EVT,
|
||||
BTC_GAP_BLE_PASSKEY_REPLY_EVT,
|
||||
BTC_GAP_BLE_CONFIRM_REPLY_EVT,
|
||||
BTC_GAP_BLE_DISCONNECT_EVT,
|
||||
} btc_gap_ble_act_t;
|
||||
|
||||
/* btc_ble_gap_args_t */
|
||||
@ -115,6 +116,12 @@ typedef union {
|
||||
esp_bd_addr_t bd_addr;
|
||||
bool accept;
|
||||
} enc_comfirm_replay;
|
||||
|
||||
//BTC_GAP_BLE_DISCONNECT_EVT
|
||||
struct disconnect_args {
|
||||
esp_bd_addr_t remote_device;
|
||||
} disconnect;
|
||||
|
||||
} btc_ble_gap_args_t;
|
||||
|
||||
void btc_gap_ble_call_handler(btc_msg_t *msg);
|
||||
|
@ -41,7 +41,8 @@ typedef enum {
|
||||
BTC_GATTC_ACT_PREPARE_WRITE_CHAR_DESCR,
|
||||
BTC_GATTC_ACT_EXECUTE_WRITE,
|
||||
BTC_GATTC_ACT_REG_FOR_NOTIFY,
|
||||
BTC_GATTC_ACT_UNREG_FOR_NOTIFY
|
||||
BTC_GATTC_ACT_UNREG_FOR_NOTIFY,
|
||||
BTC_GATTC_ACT_CACHE_REFRESH,
|
||||
} btc_gattc_act_t;
|
||||
|
||||
/* btc_ble_gattc_args_t */
|
||||
@ -186,6 +187,10 @@ typedef union {
|
||||
esp_gatt_srvc_id_t service_id;
|
||||
esp_gatt_id_t char_id;
|
||||
} unreg_for_notify;
|
||||
//BTC_GATTC_ACT_CACHE_REFRESH,
|
||||
struct cache_refresh_arg {
|
||||
esp_bd_addr_t remote_bda;
|
||||
} cache_refresh;
|
||||
} btc_ble_gattc_args_t;
|
||||
|
||||
void btc_gattc_call_handler(btc_msg_t *msg);
|
||||
|
@ -67,7 +67,9 @@ enum {
|
||||
BTM_SUCCESS_NO_SECURITY, /* 17 security passed, no security set */
|
||||
BTM_FAILED_ON_SECURITY, /* 18 security failed */
|
||||
BTM_REPEATED_ATTEMPTS, /* 19 repeated attempts for LE security requests */
|
||||
BTM_MODE4_LEVEL4_NOT_SUPPORTED /* 20 Secure Connections Only Mode can't be supported */
|
||||
BTM_MODE4_LEVEL4_NOT_SUPPORTED, /* 20 Secure Connections Only Mode can't be supported */
|
||||
BTM_PEER_LE_DATA_LEN_UNSUPPORTED, /* 21 peer setting data length is unsupported*/
|
||||
BTM_CONTROL_LE_DATA_LEN_UNSUPPORTED /* 22 controller setting data length is unsupported*/
|
||||
};
|
||||
|
||||
typedef uint8_t tBTM_STATUS;
|
||||
@ -129,6 +131,19 @@ enum {
|
||||
|
||||
typedef UINT8 tBTM_DEV_STATUS;
|
||||
|
||||
typedef struct {
|
||||
UINT16 rx_len;
|
||||
UINT16 tx_len;
|
||||
}tBTM_LE_SET_PKT_DATA_LENGTH_PARAMS;
|
||||
|
||||
typedef struct {
|
||||
UINT16 min_conn_int;
|
||||
UINT16 max_conn_int;
|
||||
UINT16 conn_int;
|
||||
UINT16 slave_latency;
|
||||
UINT16 supervision_tout;
|
||||
}tBTM_LE_UPDATE_CONN_PRAMS;
|
||||
|
||||
|
||||
typedef void (tBTM_DEV_STATUS_CB) (tBTM_DEV_STATUS status);
|
||||
|
||||
@ -156,6 +171,11 @@ typedef void (tBTM_VSC_CMPL_CB) (tBTM_VSC_CMPL *p1);
|
||||
*/
|
||||
typedef UINT8 (tBTM_FILTER_CB) (BD_ADDR bd_addr, DEV_CLASS dc);
|
||||
|
||||
typedef void (tBTM_UPDATE_CONN_PARAM_CBACK) (UINT8 status, BD_ADDR bd_addr, tBTM_LE_UPDATE_CONN_PRAMS *update_conn_params);
|
||||
|
||||
typedef void (tBTM_SET_PKT_DATA_LENGTH_CBACK) (UINT8 status, tBTM_LE_SET_PKT_DATA_LENGTH_PARAMS *data_length_params);
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
** DEVICE DISCOVERY - Inquiry, Remote Name, Discovery, Class of Device
|
||||
*****************************************************************************/
|
||||
@ -1350,6 +1370,7 @@ enum {
|
||||
};
|
||||
typedef UINT8 tBTM_SP_EVT;
|
||||
|
||||
/* relate to ESP_IO_CAP_xxx in esp_gap_ble_api.h */
|
||||
#define BTM_IO_CAP_OUT 0 /* DisplayOnly */
|
||||
#define BTM_IO_CAP_IO 1 /* DisplayYesNo */
|
||||
#define BTM_IO_CAP_IN 2 /* KeyboardOnly */
|
||||
@ -1531,6 +1552,7 @@ typedef void (tBTM_BOND_CANCEL_CMPL_CALLBACK) (tBTM_STATUS result);
|
||||
|
||||
/* LE related event and data structure
|
||||
*/
|
||||
/* relate to ESP_LE_KEY_xxx in esp_gap_ble_api.h */
|
||||
#if (SMP_INCLUDED == TRUE)
|
||||
#define BTM_LE_IO_REQ_EVT SMP_IO_CAP_REQ_EVT /* received IO_CAPABILITY_REQUEST event */
|
||||
#define BTM_LE_SEC_REQUEST_EVT SMP_SEC_REQUEST_EVT /* security request event */
|
||||
@ -1562,6 +1584,8 @@ typedef UINT8 tBTM_LE_EVT;
|
||||
#define BTM_LE_KEY_LCSRK (SMP_SEC_KEY_TYPE_CSRK << 4) /* local CSRK has been deliver to peer */
|
||||
#endif ///BLE_INCLUDED == TRUE && SMP_INCLUDED == TRUE
|
||||
typedef UINT8 tBTM_LE_KEY_TYPE;
|
||||
|
||||
/* relate to ESP_LE_AUTH_xxx in esp_gap_ble_api.h */
|
||||
#if (SMP_INCLUDED == TRUE)
|
||||
#define BTM_LE_AUTH_REQ_NO_BOND SMP_AUTH_NO_BOND /* 0 */
|
||||
#define BTM_LE_AUTH_REQ_BOND SMP_AUTH_GEN_BOND /* 1 << 0 */
|
||||
|
@ -179,7 +179,7 @@ typedef UINT8 tBTM_BLE_SFP;
|
||||
|
||||
/* default supervision timeout */
|
||||
#ifndef BTM_BLE_CONN_TIMEOUT_DEF
|
||||
#define BTM_BLE_CONN_TIMEOUT_DEF 2000
|
||||
#define BTM_BLE_CONN_TIMEOUT_DEF 600
|
||||
#endif
|
||||
|
||||
/* minimum acceptable connection interval */
|
||||
@ -310,6 +310,7 @@ typedef void (tBTM_RAND_ENC_CB) (tBTM_RAND_ENC *p1);
|
||||
|
||||
typedef UINT32 tBTM_BLE_AD_MASK;
|
||||
|
||||
/* relate to ESP_BLE_AD_TYPE_xxx in esp_gap_ble_api.h */
|
||||
#define BTM_BLE_AD_TYPE_FLAG HCI_EIR_FLAGS_TYPE /* 0x01 */
|
||||
#define BTM_BLE_AD_TYPE_16SRV_PART HCI_EIR_MORE_16BITS_UUID_TYPE /* 0x02 */
|
||||
#define BTM_BLE_AD_TYPE_16SRV_CMPL HCI_EIR_COMPLETE_16BITS_UUID_TYPE /* 0x03 */
|
||||
@ -1190,7 +1191,7 @@ tBTM_STATUS BTM_BleWriteScanRspRaw(UINT8 *p_raw_scan_rsp, UINT32 raw_scan_rsp_le
|
||||
**
|
||||
*******************************************************************************/
|
||||
//extern
|
||||
tBTM_STATUS BTM_BleObserve(BOOLEAN start, UINT8 duration,
|
||||
tBTM_STATUS BTM_BleObserve(BOOLEAN start, UINT32 duration,
|
||||
tBTM_INQ_RESULTS_CB *p_results_cb, tBTM_CMPL_CB *p_cmpl_cb);
|
||||
|
||||
|
||||
@ -1532,6 +1533,8 @@ UINT16 BTM_BleReadDiscoverability();
|
||||
//extern
|
||||
UINT16 BTM_BleReadConnectability ();
|
||||
|
||||
void BTM_Recovery_Pre_State(void);
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function BTM_ReadDevInfo
|
||||
|
@ -101,6 +101,15 @@ typedef UINT8 tBTM_BLE_SEC_REQ_ACT;
|
||||
#define BTM_VSC_CHIP_CAPABILITY_L_VERSION 55
|
||||
#define BTM_VSC_CHIP_CAPABILITY_M_VERSION 95
|
||||
|
||||
typedef enum {
|
||||
BTM_BLE_SCANNING,
|
||||
BTM_BLE_SCAN_PENDING,
|
||||
BTM_BLE_STOP_SCAN,
|
||||
BTM_BLE_ADVERTISING,
|
||||
BTM_BLE_ADV_PENDING,
|
||||
BTM_BLE_STOP_ADV,
|
||||
}tBTM_BLE_GAP_STATE;
|
||||
|
||||
typedef struct {
|
||||
UINT16 data_mask;
|
||||
UINT8 *p_flags;
|
||||
@ -155,7 +164,7 @@ typedef struct {
|
||||
|
||||
TIMER_LIST_ENT inq_timer_ent;
|
||||
BOOLEAN scan_rsp;
|
||||
UINT8 state; /* Current state that the inquiry process is in */
|
||||
tBTM_BLE_GAP_STATE state; /* Current state that the inquiry process is in */
|
||||
INT8 tx_power;
|
||||
} tBTM_BLE_INQ_CB;
|
||||
|
||||
|
@ -115,7 +115,9 @@ UINT8 conn_addr_type; /* local device address type for this co
|
||||
BD_ADDR active_remote_addr; /* remote address used on this connection */
|
||||
UINT8 active_remote_addr_type; /* local device address type for this connection */
|
||||
BD_FEATURES peer_le_features; /* Peer LE Used features mask for the device */
|
||||
|
||||
tBTM_UPDATE_CONN_PARAM_CBACK *update_conn_param_cb;
|
||||
tBTM_SET_PKT_DATA_LENGTH_CBACK *p_set_pkt_data_cback;
|
||||
tBTM_LE_SET_PKT_DATA_LENGTH_PARAMS data_length_params;
|
||||
#endif
|
||||
|
||||
} tACL_CONN;
|
||||
@ -847,8 +849,10 @@ typedef struct {
|
||||
TIMER_LIST_ENT pairing_tle; /* Timer for pairing process */
|
||||
UINT16 disc_handle; /* for legacy devices */
|
||||
UINT8 disc_reason; /* for legacy devices */
|
||||
tBTM_SEC_SERV_REC sec_serv_rec[BTM_SEC_MAX_SERVICE_RECORDS];
|
||||
#endif ///SMP_INCLUDED == TRUE
|
||||
#if SMP_INCLUDED == TRUE || CLASSIC_BT_INCLUDED == TRUE
|
||||
tBTM_SEC_SERV_REC sec_serv_rec[BTM_SEC_MAX_SERVICE_RECORDS];
|
||||
#endif // SMP_INCLUDED == TRUE || CLASSIC_BT_ENABLED == TRUE
|
||||
tBTM_SEC_DEV_REC sec_dev_rec[BTM_SEC_MAX_DEVICE_RECORDS];
|
||||
tBTM_SEC_SERV_REC *p_out_serv;
|
||||
tBTM_MKEY_CALLBACK *mkey_cback;
|
||||
@ -930,6 +934,7 @@ void btm_cont_rswitch (tACL_CONN *p,
|
||||
UINT8 hci_status);
|
||||
|
||||
UINT8 btm_handle_to_acl_index (UINT16 hci_handle);
|
||||
tACL_CONN *btm_handle_to_acl (UINT16 hci_handle);
|
||||
void btm_read_link_policy_complete (UINT8 *p);
|
||||
void btm_read_rssi_complete (UINT8 *p);
|
||||
void btm_read_tx_power_complete (UINT8 *p, BOOLEAN is_ble);
|
||||
|
@ -143,6 +143,8 @@ typedef void (*tBTU_EVENT_CALLBACK)(BT_HDR *p_hdr);
|
||||
/* eL2CAP Info Request and other proto cmds timer */
|
||||
#define BTU_TTYPE_L2CAP_FCR_ACK 78
|
||||
#define BTU_TTYPE_L2CAP_INFO 79
|
||||
/* L2CAP update connection parameters timer */
|
||||
#define BTU_TTYPE_L2CAP_UPDA_CONN_PARAMS 80
|
||||
|
||||
#define BTU_TTYPE_MCA_CCB_RSP 98
|
||||
|
||||
@ -161,6 +163,8 @@ typedef void (*tBTU_EVENT_CALLBACK)(BT_HDR *p_hdr);
|
||||
|
||||
#define BTU_TTYPE_UCD_TO 108
|
||||
|
||||
|
||||
|
||||
/* This is the inquiry response information held by BTU, and available
|
||||
** to applications.
|
||||
*/
|
||||
|
@ -66,6 +66,10 @@ bool config_has_section(const config_t *config, const char *section);
|
||||
// Returns false otherwise. |config|, |section|, and |key| must not be NULL.
|
||||
bool config_has_key(const config_t *config, const char *section, const char *key);
|
||||
|
||||
// Returns true if the config file has a key named |key| and the key_value.
|
||||
// Returns false otherwise. |config|, |key|, and |key_value| must not be NULL.
|
||||
bool config_has_key_in_section(config_t *config, char *key, char *key_value);
|
||||
|
||||
// Returns the integral value for a given |key| in |section|. If |section|
|
||||
// or |key| do not exist, or the value cannot be fully converted to an integer,
|
||||
// this function returns |def_value|. |config|, |section|, and |key| must not
|
||||
|
@ -22,14 +22,28 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* relate to BT_STATUS_xxx in bt_def.h */
|
||||
/// Status Return Value
|
||||
typedef enum {
|
||||
ESP_BT_STATUS_SUCCESS = 0, /* Successful operation. */
|
||||
ESP_BT_STATUS_FAILURE = 1, /* Generic failure. */
|
||||
ESP_BT_STATUS_PENDING = 2, /* API cannot be completed right now */
|
||||
ESP_BT_STATUS_BUSY = 3,
|
||||
ESP_BT_STATUS_NO_RESOURCES = 4,
|
||||
ESP_BT_STATUS_WRONG_MODE = 5,
|
||||
ESP_BT_STATUS_SUCCESS = 0, /* relate to BT_STATUS_SUCCESS in bt_def.h */
|
||||
ESP_BT_STATUS_FAIL, /* relate to BT_STATUS_FAIL in bt_def.h */
|
||||
ESP_BT_STATUS_NOT_READY, /* relate to BT_STATUS_NOT_READY in bt_def.h */
|
||||
ESP_BT_STATUS_NOMEM, /* relate to BT_STATUS_NOMEM in bt_def.h */
|
||||
ESP_BT_STATUS_BUSY, /* relate to BT_STATUS_BUSY in bt_def.h */
|
||||
ESP_BT_STATUS_DONE = 5, /* relate to BT_STATUS_DONE in bt_def.h */
|
||||
ESP_BT_STATUS_UNSUPPORTED, /* relate to BT_STATUS_UNSUPPORTED in bt_def.h */
|
||||
ESP_BT_STATUS_PARM_INVALID, /* relate to BT_STATUS_PARM_INVALID in bt_def.h */
|
||||
ESP_BT_STATUS_UNHANDLED, /* relate to BT_STATUS_UNHANDLED in bt_def.h */
|
||||
ESP_BT_STATUS_AUTH_FAILURE, /* relate to BT_STATUS_AUTH_FAILURE in bt_def.h */
|
||||
ESP_BT_STATUS_RMT_DEV_DOWN = 10, /* relate to BT_STATUS_RMT_DEV_DOWN in bt_def.h */
|
||||
ESP_BT_STATUS_AUTH_REJECTED, /* relate to BT_STATUS_AUTH_REJECTED in bt_def.h */
|
||||
ESP_BT_STATUS_INVALID_STATIC_RAND_ADDR, /* relate to BT_STATUS_INVALID_STATIC_RAND_ADDR in bt_def.h */
|
||||
ESP_BT_STATUS_PENDING, /* relate to BT_STATUS_PENDING in bt_def.h */
|
||||
ESP_BT_STATUS_UNACCEPT_CONN_INTERVAL, /* relate to BT_UNACCEPT_CONN_INTERVAL in bt_def.h */
|
||||
ESP_BT_STATUS_PARAM_OUT_OF_RANGE, /* relate to BT_PARAM_OUT_OF_RANGE in bt_def.h */
|
||||
ESP_BT_STATUS_TIMEOUT, /* relate to BT_STATUS_TIMEOUT in bt_def.h */
|
||||
ESP_BT_STATUS_PEER_LE_DATA_LEN_UNSUPPORTED, /* relate to BTM_PEER_LE_DATA_LEN_UNSUPPORTED in btm_api.h */
|
||||
ESP_BT_STATUS_CONTROL_LE_DATA_LEN_UNSUPPORTED,/* relate to BTM_CONTROL_LE_DATA_LEN_UNSUPPORTED in btm_api.h */
|
||||
} esp_bt_status_t;
|
||||
|
||||
|
||||
@ -86,13 +100,13 @@ typedef enum {
|
||||
} esp_ble_addr_type_t;
|
||||
|
||||
/// Used to exchange the encrytyption key in the init key & response key
|
||||
#define ESP_BLE_ENC_KEY_MASK (1 << 0)
|
||||
#define ESP_BLE_ENC_KEY_MASK (1 << 0) /* relate to BTM_BLE_ENC_KEY_MASK in btm_api.h */
|
||||
/// Used to exchange the IRK key in the init key & response key
|
||||
#define ESP_BLE_ID_KEY_MASK (1 << 1)
|
||||
#define ESP_BLE_ID_KEY_MASK (1 << 1) /* relate to BTM_BLE_ID_KEY_MASK in btm_api.h */
|
||||
/// Used to exchange the CSRK key in the init key & response key
|
||||
#define ESP_BLE_CSR_KEY_MASK (1 << 2)
|
||||
#define ESP_BLE_CSR_KEY_MASK (1 << 2) /* relate to BTM_BLE_CSR_KEY_MASK in btm_api.h */
|
||||
/// Used to exchange the link key(this key just used in the BLE & BR/EDR coexist mode) in the init key & response key
|
||||
#define ESP_BLE_LINK_KEY_MASK (1 << 3)
|
||||
#define ESP_BLE_LINK_KEY_MASK (1 << 3) /* relate to BTM_BLE_LINK_KEY_MASK in btm_api.h */
|
||||
|
||||
/// Minimum of the application id
|
||||
#define ESP_APP_ID_MIN 0x0000
|
||||
|
@ -38,31 +38,34 @@ extern "C" {
|
||||
* @}
|
||||
*/
|
||||
|
||||
#define ESP_LE_KEY_NONE 0
|
||||
#define ESP_LE_KEY_PENC (1 << 0) /*!< encryption key, encryption information of peer device */
|
||||
#define ESP_LE_KEY_PID (1 << 1) /*!< identity key of the peer device */
|
||||
#define ESP_LE_KEY_PCSRK (1 << 2) /*!< peer SRK */
|
||||
#define ESP_LE_KEY_PLK (1 << 3) /*!< Link key*/
|
||||
#define ESP_LE_KEY_LLK (ESP_LE_KEY_PLK << 4)
|
||||
#define ESP_LE_KEY_LENC (ESP_LE_KEY_PENC << 4) /*!< master role security information:div */
|
||||
#define ESP_LE_KEY_LID (ESP_LE_KEY_PID << 4) /*!< master device ID key */
|
||||
#define ESP_LE_KEY_LCSRK (ESP_LE_KEY_PCSRK << 4) /*!< local CSRK has been deliver to peer */
|
||||
/* relate to BTM_LE_KEY_xxx in btm_api.h */
|
||||
#define ESP_LE_KEY_NONE 0 /* relate to BTM_LE_KEY_NONE in btm_api.h */
|
||||
#define ESP_LE_KEY_PENC (1 << 0) /*!< encryption key, encryption information of peer device */ /* relate to BTM_LE_KEY_PENC in btm_api.h */
|
||||
#define ESP_LE_KEY_PID (1 << 1) /*!< identity key of the peer device */ /* relate to BTM_LE_KEY_PID in btm_api.h */
|
||||
#define ESP_LE_KEY_PCSRK (1 << 2) /*!< peer SRK */ /* relate to BTM_LE_KEY_PCSRK in btm_api.h */
|
||||
#define ESP_LE_KEY_PLK (1 << 3) /*!< Link key*/ /* relate to BTM_LE_KEY_PLK in btm_api.h */
|
||||
#define ESP_LE_KEY_LLK (ESP_LE_KEY_PLK << 4) /* relate to BTM_LE_KEY_LLK in btm_api.h */
|
||||
#define ESP_LE_KEY_LENC (ESP_LE_KEY_PENC << 4) /*!< master role security information:div */ /* relate to BTM_LE_KEY_LENC in btm_api.h */
|
||||
#define ESP_LE_KEY_LID (ESP_LE_KEY_PID << 4) /*!< master device ID key */ /* relate to BTM_LE_KEY_LID in btm_api.h */
|
||||
#define ESP_LE_KEY_LCSRK (ESP_LE_KEY_PCSRK << 4) /*!< local CSRK has been deliver to peer */ /* relate to BTM_LE_KEY_LCSRK in btm_api.h */
|
||||
typedef uint8_t esp_ble_key_type_t;
|
||||
|
||||
#define ESP_LE_AUTH_NO_BOND 0x00 /*!< 0*/
|
||||
#define ESP_LE_AUTH_BOND 0x01 /*!< 1 << 0 */
|
||||
#define ESP_LE_AUTH_REQ_MITM (1 << 2) /*!< 1 << 2 */
|
||||
#define ESP_LE_AUTH_REQ_SC_ONLY (1 << 3) /*!< 1 << 3 */
|
||||
#define ESP_LE_AUTH_REQ_SC_BOND (ESP_LE_AUTH_BOND | ESP_LE_AUTH_REQ_SC_ONLY) /*!< 1001 */
|
||||
#define ESP_LE_AUTH_REQ_SC_MITM (ESP_LE_AUTH_REQ_MITM | ESP_LE_AUTH_REQ_SC_ONLY) /*!< 1100 */
|
||||
#define ESP_LE_AUTH_REQ_SC_MITM_BOND (ESP_LE_AUTH_REQ_MITM | ESP_LE_AUTH_REQ_SC_ONLY | ESP_LE_AUTH_BOND) /*!< 1101 */
|
||||
/* relate to BTM_LE_AUTH_xxx in btm_api.h */
|
||||
#define ESP_LE_AUTH_NO_BOND 0x00 /*!< 0*/ /* relate to BTM_LE_AUTH_NO_BOND in btm_api.h */
|
||||
#define ESP_LE_AUTH_BOND 0x01 /*!< 1 << 0 */ /* relate to BTM_LE_AUTH_BOND in btm_api.h */
|
||||
#define ESP_LE_AUTH_REQ_MITM (1 << 2) /*!< 1 << 2 */ /* relate to BTM_LE_AUTH_REQ_MITM in btm_api.h */
|
||||
#define ESP_LE_AUTH_REQ_SC_ONLY (1 << 3) /*!< 1 << 3 */ /* relate to BTM_LE_AUTH_REQ_SC_ONLY in btm_api.h */
|
||||
#define ESP_LE_AUTH_REQ_SC_BOND (ESP_LE_AUTH_BOND | ESP_LE_AUTH_REQ_SC_ONLY) /*!< 1001 */ /* relate to BTM_LE_AUTH_REQ_SC_BOND in btm_api.h */
|
||||
#define ESP_LE_AUTH_REQ_SC_MITM (ESP_LE_AUTH_REQ_MITM | ESP_LE_AUTH_REQ_SC_ONLY) /*!< 1100 */ /* relate to BTM_LE_AUTH_REQ_SC_MITM in btm_api.h */
|
||||
#define ESP_LE_AUTH_REQ_SC_MITM_BOND (ESP_LE_AUTH_REQ_MITM | ESP_LE_AUTH_REQ_SC_ONLY | ESP_LE_AUTH_BOND) /*!< 1101 */ /* relate to BTM_LE_AUTH_REQ_SC_MITM_BOND in btm_api.h */
|
||||
typedef uint8_t esp_ble_auth_req_t; /*!< combination of the above bit pattern */
|
||||
|
||||
#define ESP_IO_CAP_OUT 0 /*!< DisplayOnly */
|
||||
#define ESP_IO_CAP_IO 1 /*!< DisplayYesNo */
|
||||
#define ESP_IO_CAP_IN 2 /*!< KeyboardOnly */
|
||||
#define ESP_IO_CAP_NONE 3 /*!< NoInputNoOutput */
|
||||
#define ESP_IO_CAP_KBDISP 4 /*!< Keyboard display */
|
||||
/* relate to BTM_IO_CAP_xxx in btm_api.h */
|
||||
#define ESP_IO_CAP_OUT 0 /*!< DisplayOnly */ /* relate to BTM_IO_CAP_OUT in btm_api.h */
|
||||
#define ESP_IO_CAP_IO 1 /*!< DisplayYesNo */ /* relate to BTM_IO_CAP_IO in btm_api.h */
|
||||
#define ESP_IO_CAP_IN 2 /*!< KeyboardOnly */ /* relate to BTM_IO_CAP_IN in btm_api.h */
|
||||
#define ESP_IO_CAP_NONE 3 /*!< NoInputNoOutput */ /* relate to BTM_IO_CAP_NONE in btm_api.h */
|
||||
#define ESP_IO_CAP_KBDISP 4 /*!< Keyboard display */ /* relate to BTM_IO_CAP_KBDISP in btm_api.h */
|
||||
typedef uint8_t esp_ble_io_cap_t; /*!< combination of the io capability */
|
||||
|
||||
|
||||
@ -87,6 +90,9 @@ typedef enum {
|
||||
ESP_GAP_BLE_NC_REQ_EVT, /* Numeric Comparison request event */
|
||||
ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT, /*!< When stop adv complete, the event comes */
|
||||
ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT, /*!< When stop scan complete, the event comes */
|
||||
ESP_GAP_BLE_SET_STATIC_RAND_ADDR_EVT, /*!< When set the static rand address complete, the event comes */
|
||||
ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT, /*!< When update connection parameters complete, the event comes */
|
||||
ESP_GAP_BLE_SET_PKT_LENGTH_COMPLETE_EVT, /*!< When set pkt lenght complete, the event comes */
|
||||
} esp_gap_ble_cb_event_t;
|
||||
|
||||
/// Advertising data maximum length
|
||||
@ -94,33 +100,45 @@ typedef enum {
|
||||
/// Scan response data maximum length
|
||||
#define ESP_BLE_SCAN_RSP_DATA_LEN_MAX 31
|
||||
|
||||
/* relate to BTM_BLE_AD_TYPE_xxx in btm_ble_api.h */
|
||||
/// The type of advertising data(not adv_type)
|
||||
typedef enum {
|
||||
ESP_BLE_AD_TYPE_FLAG = 0x01,
|
||||
ESP_BLE_AD_TYPE_16SRV_PART = 0x02,
|
||||
ESP_BLE_AD_TYPE_16SRV_CMPL = 0x03,
|
||||
ESP_BLE_AD_TYPE_32SRV_PART = 0x04,
|
||||
ESP_BLE_AD_TYPE_32SRV_CMPL = 0x05,
|
||||
ESP_BLE_AD_TYPE_128SRV_PART = 0x06,
|
||||
ESP_BLE_AD_TYPE_128SRV_CMPL = 0x07,
|
||||
ESP_BLE_AD_TYPE_NAME_SHORT = 0x08,
|
||||
ESP_BLE_AD_TYPE_NAME_CMPL = 0x09,
|
||||
ESP_BLE_AD_TYPE_TX_PWR = 0x0A,
|
||||
ESP_BLE_AD_TYPE_DEV_CLASS = 0x0D,
|
||||
ESP_BLE_AD_TYPE_SM_TK = 0x10,
|
||||
ESP_BLE_AD_TYPE_SM_OOB_FLAG = 0x11,
|
||||
ESP_BLE_AD_TYPE_INT_RANGE = 0x12,
|
||||
ESP_BLE_AD_TYPE_SOL_SRV_UUID = 0x14,
|
||||
ESP_BLE_AD_TYPE_128SOL_SRV_UUID = 0x15,
|
||||
ESP_BLE_AD_TYPE_SERVICE_DATA = 0x16,
|
||||
ESP_BLE_AD_TYPE_PUBLIC_TARGET = 0x17,
|
||||
ESP_BLE_AD_TYPE_RANDOM_TARGET = 0x18,
|
||||
ESP_BLE_AD_TYPE_APPEARANCE = 0x19,
|
||||
ESP_BLE_AD_TYPE_ADV_INT = 0x1A,
|
||||
ESP_BLE_AD_TYPE_32SOL_SRV_UUID = 0x1B,
|
||||
ESP_BLE_AD_TYPE_32SERVICE_DATA = 0x1C,
|
||||
ESP_BLE_AD_TYPE_128SERVICE_DATA = 0x1D,
|
||||
ESP_BLE_AD_MANUFACTURER_SPECIFIC_TYPE = 0xFF,
|
||||
ESP_BLE_AD_TYPE_FLAG = 0x01, /* relate to BTM_BLE_AD_TYPE_FLAG in btm_ble_api.h */
|
||||
ESP_BLE_AD_TYPE_16SRV_PART = 0x02, /* relate to BTM_BLE_AD_TYPE_16SRV_PART in btm_ble_api.h */
|
||||
ESP_BLE_AD_TYPE_16SRV_CMPL = 0x03, /* relate to BTM_BLE_AD_TYPE_16SRV_CMPL in btm_ble_api.h */
|
||||
ESP_BLE_AD_TYPE_32SRV_PART = 0x04, /* relate to BTM_BLE_AD_TYPE_32SRV_PART in btm_ble_api.h */
|
||||
ESP_BLE_AD_TYPE_32SRV_CMPL = 0x05, /* relate to BTM_BLE_AD_TYPE_32SRV_CMPL in btm_ble_api.h */
|
||||
ESP_BLE_AD_TYPE_128SRV_PART = 0x06, /* relate to BTM_BLE_AD_TYPE_128SRV_PART in btm_ble_api.h */
|
||||
ESP_BLE_AD_TYPE_128SRV_CMPL = 0x07, /* relate to BTM_BLE_AD_TYPE_128SRV_CMPL in btm_ble_api.h */
|
||||
ESP_BLE_AD_TYPE_NAME_SHORT = 0x08, /* relate to BTM_BLE_AD_TYPE_NAME_SHORT in btm_ble_api.h */
|
||||
ESP_BLE_AD_TYPE_NAME_CMPL = 0x09, /* relate to BTM_BLE_AD_TYPE_NAME_CMPL in btm_ble_api.h */
|
||||
ESP_BLE_AD_TYPE_TX_PWR = 0x0A, /* relate to BTM_BLE_AD_TYPE_TX_PWR in btm_ble_api.h */
|
||||
ESP_BLE_AD_TYPE_DEV_CLASS = 0x0D, /* relate to BTM_BLE_AD_TYPE_DEV_CLASS in btm_ble_api.h */
|
||||
ESP_BLE_AD_TYPE_SM_TK = 0x10, /* relate to BTM_BLE_AD_TYPE_SM_TK in btm_ble_api.h */
|
||||
ESP_BLE_AD_TYPE_SM_OOB_FLAG = 0x11, /* relate to BTM_BLE_AD_TYPE_SM_OOB_FLAG in btm_ble_api.h */
|
||||
ESP_BLE_AD_TYPE_INT_RANGE = 0x12, /* relate to BTM_BLE_AD_TYPE_INT_RANGE in btm_ble_api.h */
|
||||
ESP_BLE_AD_TYPE_SOL_SRV_UUID = 0x14, /* relate to BTM_BLE_AD_TYPE_SOL_SRV_UUID in btm_ble_api.h */
|
||||
ESP_BLE_AD_TYPE_128SOL_SRV_UUID = 0x15, /* relate to BTM_BLE_AD_TYPE_128SOL_SRV_UUID in btm_ble_api.h */
|
||||
ESP_BLE_AD_TYPE_SERVICE_DATA = 0x16, /* relate to BTM_BLE_AD_TYPE_SERVICE_DATA in btm_ble_api.h */
|
||||
ESP_BLE_AD_TYPE_PUBLIC_TARGET = 0x17, /* relate to BTM_BLE_AD_TYPE_PUBLIC_TARGET in btm_ble_api.h */
|
||||
ESP_BLE_AD_TYPE_RANDOM_TARGET = 0x18, /* relate to BTM_BLE_AD_TYPE_RANDOM_TARGET in btm_ble_api.h */
|
||||
ESP_BLE_AD_TYPE_APPEARANCE = 0x19, /* relate to BTM_BLE_AD_TYPE_APPEARANCE in btm_ble_api.h */
|
||||
ESP_BLE_AD_TYPE_ADV_INT = 0x1A, /* relate to BTM_BLE_AD_TYPE_ADV_INT in btm_ble_api.h */
|
||||
ESP_BLE_AD_TYPE_LE_DEV_ADDR = 0x1b, /* relate to BTM_BLE_AD_TYPE_LE_DEV_ADDR in btm_ble_api.h */
|
||||
ESP_BLE_AD_TYPE_LE_ROLE = 0x1c, /* relate to BTM_BLE_AD_TYPE_LE_ROLE in btm_ble_api.h */
|
||||
ESP_BLE_AD_TYPE_SPAIR_C256 = 0x1d, /* relate to BTM_BLE_AD_TYPE_SPAIR_C256 in btm_ble_api.h */
|
||||
ESP_BLE_AD_TYPE_SPAIR_R256 = 0x1e, /* relate to BTM_BLE_AD_TYPE_SPAIR_R256 in btm_ble_api.h */
|
||||
ESP_BLE_AD_TYPE_32SOL_SRV_UUID = 0x1f, /* relate to BTM_BLE_AD_TYPE_32SOL_SRV_UUID in btm_ble_api.h */
|
||||
ESP_BLE_AD_TYPE_32SERVICE_DATA = 0x20, /* relate to BTM_BLE_AD_TYPE_32SERVICE_DATA in btm_ble_api.h */
|
||||
ESP_BLE_AD_TYPE_128SERVICE_DATA = 0x21, /* relate to BTM_BLE_AD_TYPE_128SERVICE_DATA in btm_ble_api.h */
|
||||
ESP_BLE_AD_TYPE_LE_SECURE_CONFIRM = 0x22, /* relate to BTM_BLE_AD_TYPE_LE_SECURE_CONFIRM in btm_ble_api.h */
|
||||
ESP_BLE_AD_TYPE_LE_SECURE_RANDOM = 0x23, /* relate to BTM_BLE_AD_TYPE_LE_SECURE_RANDOM in btm_ble_api.h */
|
||||
ESP_BLE_AD_TYPE_URI = 0x24, /* relate to BTM_BLE_AD_TYPE_URI in btm_ble_api.h */
|
||||
ESP_BLE_AD_TYPE_INDOOR_POSITION = 0x25, /* relate to BTM_BLE_AD_TYPE_INDOOR_POSITION in btm_ble_api.h */
|
||||
ESP_BLE_AD_TYPE_TRANS_DISC_DATA = 0x26, /* relate to BTM_BLE_AD_TYPE_TRANS_DISC_DATA in btm_ble_api.h */
|
||||
ESP_BLE_AD_TYPE_LE_SUPPORT_FEATURE = 0x27, /* relate to BTM_BLE_AD_TYPE_LE_SUPPORT_FEATURE in btm_ble_api.h */
|
||||
ESP_BLE_AD_TYPE_CHAN_MAP_UPDATE = 0x28, /* relate to BTM_BLE_AD_TYPE_CHAN_MAP_UPDATE in btm_ble_api.h */
|
||||
ESP_BLE_AD_MANUFACTURER_SPECIFIC_TYPE = 0xFF, /* relate to BTM_BLE_AD_MANUFACTURER_SPECIFIC_TYPE in btm_ble_api.h */
|
||||
} esp_ble_adv_data_type;
|
||||
|
||||
/// Advertising mode
|
||||
@ -153,19 +171,20 @@ typedef enum {
|
||||
} esp_ble_adv_filter_t;
|
||||
|
||||
|
||||
/* relate to BTA_DM_BLE_SEC_xxx in bta_api.h */
|
||||
typedef enum {
|
||||
ESP_BLE_SEC_NONE,
|
||||
ESP_BLE_SEC_ENCRYPT,
|
||||
ESP_BLE_SEC_ENCRYPT_NO_MITM,
|
||||
ESP_BLE_SEC_ENCRYPT_MITM,
|
||||
ESP_BLE_SEC_NONE = 0, /* relate to BTA_DM_BLE_SEC_NONE in bta_api.h */
|
||||
ESP_BLE_SEC_ENCRYPT, /* relate to BTA_DM_BLE_SEC_ENCRYPT in bta_api.h */
|
||||
ESP_BLE_SEC_ENCRYPT_NO_MITM, /* relate to BTA_DM_BLE_SEC_ENCRYPT_NO_MITM in bta_api.h */
|
||||
ESP_BLE_SEC_ENCRYPT_MITM, /* relate to BTA_DM_BLE_SEC_ENCRYPT_MITM in bta_api.h */
|
||||
}esp_ble_sec_act_t;
|
||||
|
||||
typedef enum {
|
||||
ESP_BLE_SM_PASSKEY,
|
||||
ESP_BLE_SM_PASSKEY = 0,
|
||||
ESP_BLE_SM_AUTHEN_REQ_MODE,
|
||||
ESP_BLE_SM_IOCAP_MODE,
|
||||
ESP_BLE_SM_SET_INIT_KEY,
|
||||
ESP_BLE_SM_SET_RSP_KEK,
|
||||
ESP_BLE_SM_SET_RSP_KEY,
|
||||
ESP_BLE_SM_MAX_KEY_SIZE,
|
||||
} esp_ble_sm_param_t;
|
||||
|
||||
@ -255,6 +274,15 @@ typedef struct {
|
||||
Time Range: 100 msec to 32 seconds */
|
||||
} esp_ble_conn_update_params_t;
|
||||
|
||||
/**
|
||||
* @brief BLE pkt date length keys
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint16_t rx_len; /*!< pkt rx data length value */
|
||||
uint16_t tx_len; /*!< pkt tx data length value */
|
||||
}esp_ble_pkt_data_length_params_t;
|
||||
|
||||
/**
|
||||
* @brief BLE encryption keys
|
||||
*/
|
||||
@ -485,6 +513,32 @@ typedef union {
|
||||
struct ble_adv_stop_cmpl_evt_param {
|
||||
esp_bt_status_t status; /*!< Indicate adv stop operation success status */
|
||||
} adv_stop_cmpl; /*!< Event parameter of ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT */
|
||||
/**
|
||||
* @brief ESP_GAP_BLE_SET_STATIC_RAND_ADDR_EVT
|
||||
*/
|
||||
struct ble_set_rand_cmpl_evt_param {
|
||||
esp_bt_status_t status; /*!< Indicate set static rand address operation success status */
|
||||
} set_rand_addr_cmpl; /*!< Event parameter of ESP_GAP_BLE_SET_STATIC_RAND_ADDR_EVT */
|
||||
/**
|
||||
* @brief ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT
|
||||
*/
|
||||
struct ble_update_conn_params_evt_param {
|
||||
esp_bt_status_t status; /*!< Indicate update connection parameters success status */
|
||||
esp_bd_addr_t bda; /*!< Bluetooth device address */
|
||||
uint16_t min_int; /*!< Min connection interval */
|
||||
uint16_t max_int; /*!< Max connection interval */
|
||||
uint16_t latency; /*!< Slave latency for the connection in number of connection events. Range: 0x0000 to 0x01F3 */
|
||||
uint16_t conn_int; /*!< Current connection interval */
|
||||
uint16_t timeout; /*!< Supervision timeout for the LE Link. Range: 0x000A to 0x0C80.
|
||||
Mandatory Range: 0x000A to 0x0C80 Time = N * 10 msec */
|
||||
}update_conn_params; /*!< Event parameter of ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT */
|
||||
/**
|
||||
* @brief ESP_GAP_BLE_SET_PKT_LENGTH_COMPLETE_EVT
|
||||
*/
|
||||
struct ble_pkt_data_length_cmpl_evt_param {
|
||||
esp_bt_status_t status; /*!< Indicate the set pkt data length operation success status */
|
||||
esp_ble_pkt_data_length_params_t params; /*!< pkt data length value */
|
||||
} pkt_data_lenth_cmpl; /*!< Event parameter of ESP_GAP_BLE_SET_PKT_LENGTH_COMPLETE_EVT */
|
||||
} esp_ble_gap_cb_param_t;
|
||||
|
||||
/**
|
||||
@ -760,6 +814,17 @@ esp_err_t esp_ble_passkey_reply(esp_bd_addr_t bd_addr, bool accept, uint32_t pas
|
||||
*/
|
||||
esp_err_t esp_ble_confirm_reply(esp_bd_addr_t bd_addr, bool accept);
|
||||
|
||||
/**
|
||||
* @brief This function is to disconnect the physical connection of the peer device
|
||||
*
|
||||
* @param[in] remote_device : BD address of the peer device
|
||||
*
|
||||
* @return - ESP_OK : success
|
||||
* - other : failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gap_disconnect(esp_bd_addr_t remote_device);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -153,75 +153,81 @@ extern "C" {
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* relate to BTA_GATT_PREP_WRITE_xxx in bta_gatt_api.h */
|
||||
/// Attribute write data type from the client
|
||||
typedef enum {
|
||||
ESP_GATT_PREP_WRITE_CANCEL = 0x00, /*!< Prepare write cancel */
|
||||
ESP_GATT_PREP_WRITE_EXEC = 0x01, /*!< Prepare write execute */
|
||||
ESP_GATT_PREP_WRITE_CANCEL = 0x00, /*!< Prepare write cancel */ /* relate to BTA_GATT_PREP_WRITE_CANCEL in bta_gatt_api.h */
|
||||
ESP_GATT_PREP_WRITE_EXEC = 0x01, /*!< Prepare write execute */ /* relate to BTA_GATT_PREP_WRITE_EXEC in bta_gatt_api.h */
|
||||
} esp_gatt_prep_write_type;
|
||||
|
||||
/* relate to BTA_GATT_xxx in bta_gatt_api.h */
|
||||
/**
|
||||
* @brief GATT success code and error codes
|
||||
*/
|
||||
typedef enum {
|
||||
ESP_GATT_OK = 0x0,
|
||||
ESP_GATT_INVALID_HANDLE = 0x01, /* 0x0001 */
|
||||
ESP_GATT_READ_NOT_PERMIT = 0x02, /* 0x0002 */
|
||||
ESP_GATT_WRITE_NOT_PERMIT = 0x03, /* 0x0003 */
|
||||
ESP_GATT_INVALID_PDU = 0x04, /* 0x0004 */
|
||||
ESP_GATT_INSUF_AUTHENTICATION = 0x05, /* 0x0005 */
|
||||
ESP_GATT_REQ_NOT_SUPPORTED = 0x06, /* 0x0006 */
|
||||
ESP_GATT_INVALID_OFFSET = 0x07, /* 0x0007 */
|
||||
ESP_GATT_INSUF_AUTHORIZATION = 0x08, /* 0x0008 */
|
||||
ESP_GATT_PREPARE_Q_FULL = 0x09, /* 0x0009 */
|
||||
ESP_GATT_NOT_FOUND = 0x0a, /* 0x000a */
|
||||
ESP_GATT_NOT_LONG = 0x0b, /* 0x000b */
|
||||
ESP_GATT_INSUF_KEY_SIZE = 0x0c, /* 0x000c */
|
||||
ESP_GATT_INVALID_ATTR_LEN = 0x0d, /* 0x000d */
|
||||
ESP_GATT_ERR_UNLIKELY = 0x0e, /* 0x000e */
|
||||
ESP_GATT_INSUF_ENCRYPTION = 0x0f, /* 0x000f */
|
||||
ESP_GATT_UNSUPPORT_GRP_TYPE = 0x10, /* 0x0010 */
|
||||
ESP_GATT_INSUF_RESOURCE = 0x11, /* 0x0011 */
|
||||
|
||||
ESP_GATT_NO_RESOURCES = 0x80, /* 0x80 */
|
||||
ESP_GATT_INTERNAL_ERROR = 0x81, /* 0x81 */
|
||||
ESP_GATT_WRONG_STATE = 0x82, /* 0x82 */
|
||||
ESP_GATT_DB_FULL = 0x83, /* 0x83 */
|
||||
ESP_GATT_BUSY = 0x84, /* 0x84 */
|
||||
ESP_GATT_ERROR = 0x85, /* 0x85 */
|
||||
ESP_GATT_CMD_STARTED = 0x86, /* 0x86 */
|
||||
ESP_GATT_ILLEGAL_PARAMETER = 0x87, /* 0x87 */
|
||||
ESP_GATT_PENDING = 0x88, /* 0x88 */
|
||||
ESP_GATT_AUTH_FAIL = 0x89, /* 0x89 */
|
||||
ESP_GATT_MORE = 0x8a, /* 0x8a */
|
||||
ESP_GATT_INVALID_CFG = 0x8b, /* 0x8b */
|
||||
ESP_GATT_SERVICE_STARTED = 0x8c, /* 0x8c */
|
||||
ESP_GATT_ENCRYPED_MITM = ESP_GATT_OK,
|
||||
ESP_GATT_ENCRYPED_NO_MITM = 0x8d, /* 0x8d */
|
||||
ESP_GATT_NOT_ENCRYPTED = 0x8e, /* 0x8e */
|
||||
ESP_GATT_CONGESTED = 0x8f, /* 0x8f */
|
||||
ESP_GATT_DUP_REG = 0x90, /* 0x90 */
|
||||
ESP_GATT_ALREADY_OPEN = 0x91, /* 0x91 */
|
||||
ESP_GATT_CANCEL = 0x92, /* 0x92 */
|
||||
ESP_GATT_OK = 0x0, /* relate to BTA_GATT_OK in bta_gatt_api.h */
|
||||
ESP_GATT_INVALID_HANDLE = 0x01, /* 0x0001 */ /* relate to BTA_GATT_INVALID_HANDLE in bta_gatt_api.h */
|
||||
ESP_GATT_READ_NOT_PERMIT = 0x02, /* 0x0002 */ /* relate to BTA_GATT_READ_NOT_PERMIT in bta_gatt_api.h */
|
||||
ESP_GATT_WRITE_NOT_PERMIT = 0x03, /* 0x0003 */ /* relate to BTA_GATT_WRITE_NOT_PERMIT in bta_gatt_api.h */
|
||||
ESP_GATT_INVALID_PDU = 0x04, /* 0x0004 */ /* relate to BTA_GATT_INVALID_PDU in bta_gatt_api.h */
|
||||
ESP_GATT_INSUF_AUTHENTICATION = 0x05, /* 0x0005 */ /* relate to BTA_GATT_INSUF_AUTHENTICATION in bta_gatt_api.h */
|
||||
ESP_GATT_REQ_NOT_SUPPORTED = 0x06, /* 0x0006 */ /* relate to BTA_GATT_REQ_NOT_SUPPORTED in bta_gatt_api.h */
|
||||
ESP_GATT_INVALID_OFFSET = 0x07, /* 0x0007 */ /* relate to BTA_GATT_INVALID_OFFSET in bta_gatt_api.h */
|
||||
ESP_GATT_INSUF_AUTHORIZATION = 0x08, /* 0x0008 */ /* relate to BTA_GATT_INSUF_AUTHORIZATION in bta_gatt_api.h */
|
||||
ESP_GATT_PREPARE_Q_FULL = 0x09, /* 0x0009 */ /* relate to BTA_GATT_PREPARE_Q_FULL in bta_gatt_api.h */
|
||||
ESP_GATT_NOT_FOUND = 0x0a, /* 0x000a */ /* relate to BTA_GATT_NOT_FOUND in bta_gatt_api.h */
|
||||
ESP_GATT_NOT_LONG = 0x0b, /* 0x000b */ /* relate to BTA_GATT_NOT_LONG in bta_gatt_api.h */
|
||||
ESP_GATT_INSUF_KEY_SIZE = 0x0c, /* 0x000c */ /* relate to BTA_GATT_INSUF_KEY_SIZE in bta_gatt_api.h */
|
||||
ESP_GATT_INVALID_ATTR_LEN = 0x0d, /* 0x000d */ /* relate to BTA_GATT_INVALID_ATTR_LEN in bta_gatt_api.h */
|
||||
ESP_GATT_ERR_UNLIKELY = 0x0e, /* 0x000e */ /* relate to BTA_GATT_ERR_UNLIKELY in bta_gatt_api.h */
|
||||
ESP_GATT_INSUF_ENCRYPTION = 0x0f, /* 0x000f */ /* relate to BTA_GATT_INSUF_ENCRYPTION in bta_gatt_api.h */
|
||||
ESP_GATT_UNSUPPORT_GRP_TYPE = 0x10, /* 0x0010 */ /* relate to BTA_GATT_UNSUPPORT_GRP_TYPE in bta_gatt_api.h */
|
||||
ESP_GATT_INSUF_RESOURCE = 0x11, /* 0x0011 */ /* relate to BTA_GATT_INSUF_RESOURCE in bta_gatt_api.h */
|
||||
|
||||
ESP_GATT_NO_RESOURCES = 0x80, /* 0x80 */ /* relate to BTA_GATT_NO_RESOURCES in bta_gatt_api.h */
|
||||
ESP_GATT_INTERNAL_ERROR = 0x81, /* 0x81 */ /* relate to BTA_GATT_INTERNAL_ERROR in bta_gatt_api.h */
|
||||
ESP_GATT_WRONG_STATE = 0x82, /* 0x82 */ /* relate to BTA_GATT_WRONG_STATE in bta_gatt_api.h */
|
||||
ESP_GATT_DB_FULL = 0x83, /* 0x83 */ /* relate to BTA_GATT_DB_FULL in bta_gatt_api.h */
|
||||
ESP_GATT_BUSY = 0x84, /* 0x84 */ /* relate to BTA_GATT_BUSY in bta_gatt_api.h */
|
||||
ESP_GATT_ERROR = 0x85, /* 0x85 */ /* relate to BTA_GATT_ERROR in bta_gatt_api.h */
|
||||
ESP_GATT_CMD_STARTED = 0x86, /* 0x86 */ /* relate to BTA_GATT_CMD_STARTED in bta_gatt_api.h */
|
||||
ESP_GATT_ILLEGAL_PARAMETER = 0x87, /* 0x87 */ /* relate to BTA_GATT_ILLEGAL_PARAMETER in bta_gatt_api.h */
|
||||
ESP_GATT_PENDING = 0x88, /* 0x88 */ /* relate to BTA_GATT_PENDING in bta_gatt_api.h */
|
||||
ESP_GATT_AUTH_FAIL = 0x89, /* 0x89 */ /* relate to BTA_GATT_AUTH_FAIL in bta_gatt_api.h */
|
||||
ESP_GATT_MORE = 0x8a, /* 0x8a */ /* relate to BTA_GATT_MORE in bta_gatt_api.h */
|
||||
ESP_GATT_INVALID_CFG = 0x8b, /* 0x8b */ /* relate to BTA_GATT_INVALID_CFG in bta_gatt_api.h */
|
||||
ESP_GATT_SERVICE_STARTED = 0x8c, /* 0x8c */ /* relate to BTA_GATT_SERVICE_STARTED in bta_gatt_api.h */
|
||||
ESP_GATT_ENCRYPED_MITM = ESP_GATT_OK, /* relate to BTA_GATT_ENCRYPED_MITM in bta_gatt_api.h */
|
||||
ESP_GATT_ENCRYPED_NO_MITM = 0x8d, /* 0x8d */ /* relate to BTA_GATT_ENCRYPED_NO_MITM in bta_gatt_api.h */
|
||||
ESP_GATT_NOT_ENCRYPTED = 0x8e, /* 0x8e */ /* relate to BTA_GATT_NOT_ENCRYPTED in bta_gatt_api.h */
|
||||
ESP_GATT_CONGESTED = 0x8f, /* 0x8f */ /* relate to BTA_GATT_CONGESTED in bta_gatt_api.h */
|
||||
ESP_GATT_DUP_REG = 0x90, /* 0x90 */ /* relate to BTA_GATT_DUP_REG in bta_gatt_api.h */
|
||||
ESP_GATT_ALREADY_OPEN = 0x91, /* 0x91 */ /* relate to BTA_GATT_ALREADY_OPEN in bta_gatt_api.h */
|
||||
ESP_GATT_CANCEL = 0x92, /* 0x92 */ /* relate to BTA_GATT_CANCEL in bta_gatt_api.h */
|
||||
/* 0xE0 ~ 0xFC reserved for future use */
|
||||
ESP_GATT_CCC_CFG_ERR = 0xfd, /* 0xFD Client Characteristic Configuration Descriptor Improperly Configured */
|
||||
ESP_GATT_PRC_IN_PROGRESS = 0xfe, /* 0xFE Procedure Already in progress */
|
||||
ESP_GATT_OUT_OF_RANGE = 0xff, /* 0xFFAttribute value out of range */
|
||||
ESP_GATT_STACK_RSP = 0xe0, /* 0xe0 */ /* relate to BTA_GATT_STACK_RSP in bta_gatt_api.h */
|
||||
ESP_GATT_APP_RSP = 0xe1, /* 0xe1 */ /* relate to BTA_GATT_APP_RSP in bta_gatt_api.h */
|
||||
//Error caused by customer application or stack bug
|
||||
ESP_GATT_UNKNOWN_ERROR = 0xef, /* 0xef */ /* relate to BTA_GATT_UNKNOWN_ERROR in bta_gatt_api.h */
|
||||
ESP_GATT_CCC_CFG_ERR = 0xfd, /* 0xFD Client Characteristic Configuration Descriptor Improperly Configured */ /* relate to BTA_GATT_CCC_CFG_ERR in bta_gatt_api.h */
|
||||
ESP_GATT_PRC_IN_PROGRESS = 0xfe, /* 0xFE Procedure Already in progress */ /* relate to BTA_GATT_PRC_IN_PROGRESS in bta_gatt_api.h */
|
||||
ESP_GATT_OUT_OF_RANGE = 0xff, /* 0xFFAttribute value out of range */ /* relate to BTA_GATT_OUT_OF_RANGE in bta_gatt_api.h */
|
||||
} esp_gatt_status_t;
|
||||
|
||||
/* relate to BTA_GATT_CONN_xxx in bta_gatt_api.h */
|
||||
/**
|
||||
* @brief Gatt Connection reason enum
|
||||
*/
|
||||
typedef enum {
|
||||
ESP_GATT_CONN_UNKNOWN = 0, /*!< Gatt connection unknown */
|
||||
ESP_GATT_CONN_L2C_FAILURE = 1, /*!< General L2cap failure */
|
||||
ESP_GATT_CONN_TIMEOUT = 0x08, /*!< Connection timeout */
|
||||
ESP_GATT_CONN_TERMINATE_PEER_USER = 0x13, /*!< Connection terminate by peer user */
|
||||
ESP_GATT_CONN_TERMINATE_LOCAL_HOST = 0x16, /*!< Connectionterminated by local host */
|
||||
ESP_GATT_CONN_FAIL_ESTABLISH = 0x3e, /*!< Connection fail to establish */
|
||||
ESP_GATT_CONN_LMP_TIMEOUT = 0x22, /*!< Connection fail for LMP response tout */
|
||||
ESP_GATT_CONN_CONN_CANCEL = 0x0100, /*!< L2CAP connection cancelled */
|
||||
ESP_GATT_CONN_NONE = 0x0101 /*!< No connection to cancel */
|
||||
ESP_GATT_CONN_UNKNOWN = 0, /*!< Gatt connection unknown */ /* relate to BTA_GATT_CONN_UNKNOWN in bta_gatt_api.h */
|
||||
ESP_GATT_CONN_L2C_FAILURE = 1, /*!< General L2cap failure */ /* relate to BTA_GATT_CONN_L2C_FAILURE in bta_gatt_api.h */
|
||||
ESP_GATT_CONN_TIMEOUT = 0x08, /*!< Connection timeout */ /* relate to BTA_GATT_CONN_TIMEOUT in bta_gatt_api.h */
|
||||
ESP_GATT_CONN_TERMINATE_PEER_USER = 0x13, /*!< Connection terminate by peer user */ /* relate to BTA_GATT_CONN_TERMINATE_PEER_USER in bta_gatt_api.h */
|
||||
ESP_GATT_CONN_TERMINATE_LOCAL_HOST = 0x16, /*!< Connectionterminated by local host */ /* relate to BTA_GATT_CONN_TERMINATE_LOCAL_HOST in bta_gatt_api.h */
|
||||
ESP_GATT_CONN_FAIL_ESTABLISH = 0x3e, /*!< Connection fail to establish */ /* relate to BTA_GATT_CONN_FAIL_ESTABLISH in bta_gatt_api.h */
|
||||
ESP_GATT_CONN_LMP_TIMEOUT = 0x22, /*!< Connection fail for LMP response tout */ /* relate to BTA_GATT_CONN_LMP_TIMEOUT in bta_gatt_api.h */
|
||||
ESP_GATT_CONN_CONN_CANCEL = 0x0100, /*!< L2CAP connection cancelled */ /* relate to BTA_GATT_CONN_CONN_CANCEL in bta_gatt_api.h */
|
||||
ESP_GATT_CONN_NONE = 0x0101 /*!< No connection to cancel */ /* relate to BTA_GATT_CONN_NONE in bta_gatt_api.h */
|
||||
} esp_gatt_conn_reason_t;
|
||||
|
||||
/**
|
||||
@ -241,42 +247,43 @@ typedef struct {
|
||||
bool is_primary; /*!< This service is primary or not */
|
||||
} __attribute__((packed)) esp_gatt_srvc_id_t;
|
||||
|
||||
/* relate to BTA_GATT_AUTH_REQ_xxx in bta_gatt_api.h */
|
||||
/**
|
||||
* @brief Gatt authentication request type
|
||||
*/
|
||||
typedef enum {
|
||||
ESP_GATT_AUTH_REQ_NONE = 0,
|
||||
ESP_GATT_AUTH_REQ_NO_MITM = 1, /* unauthenticated encryption */
|
||||
ESP_GATT_AUTH_REQ_MITM = 2, /* authenticated encryption */
|
||||
ESP_GATT_AUTH_REQ_SIGNED_NO_MITM = 3,
|
||||
ESP_GATT_AUTH_REQ_SIGNED_MITM = 4,
|
||||
ESP_GATT_AUTH_REQ_NONE = 0, /* relate to BTA_GATT_AUTH_REQ_NONE in bta_gatt_api.h */
|
||||
ESP_GATT_AUTH_REQ_NO_MITM = 1, /* unauthenticated encryption */ /* relate to BTA_GATT_AUTH_REQ_NO_MITM in bta_gatt_api.h */
|
||||
ESP_GATT_AUTH_REQ_MITM = 2, /* authenticated encryption */ /* relate to BTA_GATT_AUTH_REQ_MITM in bta_gatt_api.h */
|
||||
ESP_GATT_AUTH_REQ_SIGNED_NO_MITM = 3, /* relate to BTA_GATT_AUTH_REQ_SIGNED_NO_MITM in bta_gatt_api.h */
|
||||
ESP_GATT_AUTH_REQ_SIGNED_MITM = 4, /* relate to BTA_GATT_AUTH_REQ_SIGNED_MITM in bta_gatt_api.h */
|
||||
} esp_gatt_auth_req_t;
|
||||
|
||||
/* relate to BTA_GATT_PERM_xxx in bta_gatt_api.h */
|
||||
/**
|
||||
* @brief Attribute permissions
|
||||
*/
|
||||
typedef enum {
|
||||
ESP_GATT_PERM_READ = (1 << 0), /* bit 0 - 0x0001 */
|
||||
ESP_GATT_PERM_READ_ENCRYPTED = (1 << 1), /* bit 1 - 0x0002 */
|
||||
ESP_GATT_PERM_READ_ENC_MITM = (1 << 2), /* bit 2 - 0x0004 */
|
||||
ESP_GATT_PERM_WRITE = (1 << 4), /* bit 4 - 0x0010 */
|
||||
ESP_GATT_PERM_WRITE_ENCRYPTED = (1 << 5), /* bit 5 - 0x0020 */
|
||||
ESP_GATT_PERM_WRITE_ENC_MITM = (1 << 6), /* bit 6 - 0x0040 */
|
||||
ESP_GATT_PERM_WRITE_SIGNED = (1 << 7), /* bit 7 - 0x0080 */
|
||||
ESP_GATT_PERM_WRITE_SIGNED_MITM = (1 << 8), /* bit 8 - 0x0100 */
|
||||
} esp_gatt_perm_t;
|
||||
#define ESP_GATT_PERM_READ (1 << 0) /* bit 0 - 0x0001 */ /* relate to BTA_GATT_PERM_READ in bta_gatt_api.h */
|
||||
#define ESP_GATT_PERM_READ_ENCRYPTED (1 << 1) /* bit 1 - 0x0002 */ /* relate to BTA_GATT_PERM_READ_ENCRYPTED in bta_gatt_api.h */
|
||||
#define ESP_GATT_PERM_READ_ENC_MITM (1 << 2) /* bit 2 - 0x0004 */ /* relate to BTA_GATT_PERM_READ_ENC_MITM in bta_gatt_api.h */
|
||||
#define ESP_GATT_PERM_WRITE (1 << 4) /* bit 4 - 0x0010 */ /* relate to BTA_GATT_PERM_WRITE in bta_gatt_api.h */
|
||||
#define ESP_GATT_PERM_WRITE_ENCRYPTED (1 << 5) /* bit 5 - 0x0020 */ /* relate to BTA_GATT_PERM_WRITE_ENCRYPTED in bta_gatt_api.h */
|
||||
#define ESP_GATT_PERM_WRITE_ENC_MITM (1 << 6) /* bit 6 - 0x0040 */ /* relate to BTA_GATT_PERM_WRITE_ENC_MITM in bta_gatt_api.h */
|
||||
#define ESP_GATT_PERM_WRITE_SIGNED (1 << 7) /* bit 7 - 0x0080 */ /* relate to BTA_GATT_PERM_WRITE_SIGNED in bta_gatt_api.h */
|
||||
#define ESP_GATT_PERM_WRITE_SIGNED_MITM (1 << 8) /* bit 8 - 0x0100 */ /* relate to BTA_GATT_PERM_WRITE_SIGNED_MITM in bta_gatt_api.h */
|
||||
typedef uint16_t esp_gatt_perm_t;
|
||||
|
||||
/* relate to BTA_GATT_CHAR_PROP_BIT_xxx in bta_gatt_api.h */
|
||||
/* definition of characteristic properties */
|
||||
typedef enum {
|
||||
ESP_GATT_CHAR_PROP_BIT_BROADCAST = (1 << 0), /* 0x01 */
|
||||
ESP_GATT_CHAR_PROP_BIT_READ = (1 << 1), /* 0x02 */
|
||||
ESP_GATT_CHAR_PROP_BIT_WRITE_NR = (1 << 2), /* 0x04 */
|
||||
ESP_GATT_CHAR_PROP_BIT_WRITE = (1 << 3), /* 0x08 */
|
||||
ESP_GATT_CHAR_PROP_BIT_NOTIFY = (1 << 4), /* 0x10 */
|
||||
ESP_GATT_CHAR_PROP_BIT_INDICATE = (1 << 5), /* 0x20 */
|
||||
ESP_GATT_CHAR_PROP_BIT_AUTH = (1 << 6), /* 0x40 */
|
||||
ESP_GATT_CHAR_PROP_BIT_EXT_PROP = (1 << 7), /* 0x80 */
|
||||
} esp_gatt_char_prop_t;
|
||||
#define ESP_GATT_CHAR_PROP_BIT_BROADCAST (1 << 0) /* 0x01 */ /* relate to BTA_GATT_CHAR_PROP_BIT_BROADCAST in bta_gatt_api.h */
|
||||
#define ESP_GATT_CHAR_PROP_BIT_READ (1 << 1) /* 0x02 */ /* relate to BTA_GATT_CHAR_PROP_BIT_READ in bta_gatt_api.h */
|
||||
#define ESP_GATT_CHAR_PROP_BIT_WRITE_NR (1 << 2) /* 0x04 */ /* relate to BTA_GATT_CHAR_PROP_BIT_WRITE_NR in bta_gatt_api.h */
|
||||
#define ESP_GATT_CHAR_PROP_BIT_WRITE (1 << 3) /* 0x08 */ /* relate to BTA_GATT_CHAR_PROP_BIT_WRITE in bta_gatt_api.h */
|
||||
#define ESP_GATT_CHAR_PROP_BIT_NOTIFY (1 << 4) /* 0x10 */ /* relate to BTA_GATT_CHAR_PROP_BIT_NOTIFY in bta_gatt_api.h */
|
||||
#define ESP_GATT_CHAR_PROP_BIT_INDICATE (1 << 5) /* 0x20 */ /* relate to BTA_GATT_CHAR_PROP_BIT_INDICATE in bta_gatt_api.h */
|
||||
#define ESP_GATT_CHAR_PROP_BIT_AUTH (1 << 6) /* 0x40 */ /* relate to BTA_GATT_CHAR_PROP_BIT_AUTH in bta_gatt_api.h */
|
||||
#define ESP_GATT_CHAR_PROP_BIT_EXT_PROP (1 << 7) /* 0x80 */ /* relate to BTA_GATT_CHAR_PROP_BIT_EXT_PROP in bta_gatt_api.h */
|
||||
typedef uint8_t esp_gatt_char_prop_t;
|
||||
|
||||
/// GATT maximum attribute length
|
||||
#define ESP_GATT_MAX_ATTR_LEN 600 //as same as GATT_MAX_ATTR_LEN
|
||||
|
@ -27,10 +27,10 @@ extern "C" {
|
||||
typedef enum {
|
||||
ESP_GATTC_REG_EVT = 0, /*!< When GATT client is registered, the event comes */
|
||||
ESP_GATTC_UNREG_EVT = 1, /*!< When GATT client is unregistered, the event comes */
|
||||
ESP_GATTC_OPEN_EVT = 2, /*!< When GATT connection is set up, the event comes */
|
||||
ESP_GATTC_OPEN_EVT = 2, /*!< When GATT virtual connection is set up, the event comes */
|
||||
ESP_GATTC_READ_CHAR_EVT = 3, /*!< When GATT characteristic is read, the event comes */
|
||||
ESP_GATTC_WRITE_CHAR_EVT = 4, /*!< When GATT characteristic write operation completes, the event comes */
|
||||
ESP_GATTC_CLOSE_EVT = 5, /*!< When GATT connection is closed, the event comes */
|
||||
ESP_GATTC_CLOSE_EVT = 5, /*!< When GATT virtual connection is closed, the event comes */
|
||||
ESP_GATTC_SEARCH_CMPL_EVT = 6, /*!< When GATT service discovery is completed, the event comes */
|
||||
ESP_GATTC_SEARCH_RES_EVT = 7, /*!< When GATT service discovery result is got, the event comes */
|
||||
ESP_GATTC_READ_DESCR_EVT = 8, /*!< When GATT characteristic descriptor read completes, the event comes */
|
||||
@ -64,6 +64,8 @@ typedef enum {
|
||||
ESP_GATTC_GET_INCL_SRVC_EVT = 37, /*!< When included service is got from GATT server, the event comes */
|
||||
ESP_GATTC_REG_FOR_NOTIFY_EVT = 38, /*!< When register for notification of a service completes, the event comes */
|
||||
ESP_GATTC_UNREG_FOR_NOTIFY_EVT = 39, /*!< When unregister for notification of a service completes, the event comes */
|
||||
ESP_GATTC_CONNECT_EVT = 40, /*!< When the ble physical connection is set up, the event comes */
|
||||
ESP_GATTC_DISCONNECT_EVT = 41, /*!< When the ble physical connection disconnected, the event comes */
|
||||
} esp_gattc_cb_event_t;
|
||||
|
||||
/// Maximum Transmission Unit used in GATT
|
||||
@ -133,13 +135,20 @@ typedef union {
|
||||
* @brief ESP_GATTC_READ_CHAR_EVT, ESP_GATTC_READ_DESCR_EVT
|
||||
*/
|
||||
struct gattc_read_char_evt_param {
|
||||
|
||||
esp_gatt_status_t status; /*!< Operation status */
|
||||
uint16_t conn_id; /*!< Connection id */
|
||||
esp_gatt_srvc_id_t srvc_id; /*!< Service id, include service uuid and other information */
|
||||
esp_gatt_id_t char_id; /*!< Characteristic id, include characteristic uuid and other information */
|
||||
esp_gatt_id_t descr_id; /*!< Descriptor id, include descriptor uuid and other information */
|
||||
uint8_t *value; /*!< Characteristic value */
|
||||
uint16_t value_type; /*!< Characteristic value type */
|
||||
uint16_t value_type; /*!< Characteristic value type, there is two value for this type:
|
||||
ESP_GATTC_READ_VALUE_TYPE_VALUE(0x0000) and
|
||||
ESP_GATTC_READ_VALUE_TYPE_AGG_FORMAT(0x2905).
|
||||
If the value is ESP_GATTC_READ_VALUE_TYPE_VALUE means it is a generally
|
||||
value type, and if is the type of ESP_GATTC_READ_VALUE_TYPE_AGG_FORMAT,
|
||||
the unit of the value will indicate in the Characteristic
|
||||
aggregate format descriptor */
|
||||
uint16_t value_len; /*!< Characteristic value length */
|
||||
} read; /*!< Gatt client callback param of ESP_GATTC_READ_CHAR_EVT */
|
||||
|
||||
@ -241,6 +250,23 @@ typedef union {
|
||||
esp_gatt_id_t char_id; /*!< Characteristic id, include characteristic uuid and other information */
|
||||
} unreg_for_notify; /*!< Gatt client callback param of ESP_GATTC_UNREG_FOR_NOTIFY_EVT */
|
||||
|
||||
/**
|
||||
* @brief ESP_GATTC_CONNECT_EVT
|
||||
*/
|
||||
struct gattc_connect_evt_param {
|
||||
esp_gatt_status_t status; /*!< Operation status */
|
||||
uint16_t conn_id; /*!< Connection id */
|
||||
esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */
|
||||
} connect; /*!< Gatt client callback param of ESP_GATTC_CONNECT_EVT */
|
||||
|
||||
/**
|
||||
* @brief ESP_GATTC_DISCONNECT_EVT
|
||||
*/
|
||||
struct gattc_disconnect_evt_param {
|
||||
esp_gatt_status_t status; /*!< Operation status */
|
||||
uint16_t conn_id; /*!< Connection id */
|
||||
esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */
|
||||
} disconnect; /*!< Gatt client callback param of ESP_GATTC_DISCONNECT_EVT */
|
||||
|
||||
} esp_ble_gattc_cb_param_t; /*!< GATT client callback parameter union type */
|
||||
|
||||
@ -311,7 +337,10 @@ esp_err_t esp_ble_gattc_open(esp_gatt_if_t gattc_if, esp_bd_addr_t remote_bda, b
|
||||
|
||||
|
||||
/**
|
||||
* @brief Close a connection to a GATT server.
|
||||
* @brief Close a virtual connection to a GATT server. gattc maybe have multiple virtual GATT server connections when multiple app_id registed,
|
||||
* this API only close one virtual GATT server connection. if there exist other virtual GATT server connections,
|
||||
* it does not disconnect the physical connection.
|
||||
* if you want to disconnect the physical connection directly, you can use esp_ble_gap_disconnect(esp_bd_addr_t remote_device).
|
||||
*
|
||||
* @param[in] gattc_if: Gatt client access interface.
|
||||
* @param[in] conn_id: connection ID to be closed.
|
||||
@ -629,6 +658,19 @@ esp_gatt_status_t esp_ble_gattc_unregister_for_notify (esp_gatt_if_t gattc_if,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Refresh the server cache store in the gattc stack of the remote device
|
||||
*
|
||||
* @param[in] remote_bda: remote device BD address.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: success
|
||||
* - other: failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gattc_cache_refresh(esp_bd_addr_t remote_bda);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -208,12 +208,25 @@ typedef union {
|
||||
/**
|
||||
* @brief ESP_GATTS_OPEN_EVT
|
||||
*/
|
||||
struct gatts_open_evt_param {
|
||||
esp_gatt_status_t status; /*!< Operation status */
|
||||
} open; /*!< Gatt server callback param of ESP_GATTS_OPEN_EVT */
|
||||
|
||||
/**
|
||||
* @brief ESP_GATTS_CANCEL_OPEN_EVT
|
||||
*/
|
||||
struct gatts_cancel_open_evt_param {
|
||||
esp_gatt_status_t status; /*!< Operation status */
|
||||
} cancel_open; /*!< Gatt server callback param of ESP_GATTS_CANCEL_OPEN_EVT */
|
||||
|
||||
/**
|
||||
* @brief ESP_GATTS_CLOSE_EVT
|
||||
*/
|
||||
struct gatts_close_evt_param {
|
||||
esp_gatt_status_t status; /*!< Operation status */
|
||||
uint16_t conn_id; /*!< Connection id */
|
||||
} close; /*!< Gatt server callback param of ESP_GATTS_CLOSE_EVT */
|
||||
|
||||
/**
|
||||
* @brief ESP_GATTS_LISTEN_EVT
|
||||
*/
|
||||
|
@ -46,7 +46,6 @@
|
||||
#define GATT_INSUF_RESOURCE 0x11
|
||||
|
||||
|
||||
#define GATT_ILLEGAL_PARAMETER 0x87
|
||||
#define GATT_NO_RESOURCES 0x80
|
||||
#define GATT_INTERNAL_ERROR 0x81
|
||||
#define GATT_WRONG_STATE 0x82
|
||||
@ -54,6 +53,7 @@
|
||||
#define GATT_BUSY 0x84
|
||||
#define GATT_ERROR 0x85
|
||||
#define GATT_CMD_STARTED 0x86
|
||||
#define GATT_ILLEGAL_PARAMETER 0x87
|
||||
#define GATT_PENDING 0x88
|
||||
#define GATT_AUTH_FAIL 0x89
|
||||
#define GATT_MORE 0x8a
|
||||
@ -63,15 +63,21 @@
|
||||
#define GATT_ENCRYPED_NO_MITM 0x8d
|
||||
#define GATT_NOT_ENCRYPTED 0x8e
|
||||
#define GATT_CONGESTED 0x8f
|
||||
#define GATT_STACK_RSP 0x90
|
||||
#define GATT_APP_RSP 0x91
|
||||
//Error caused by customer application or stack bug
|
||||
#define GATT_ESP_ERROR 0X9f
|
||||
|
||||
#define GATT_DUP_REG 0x90
|
||||
#define GATT_ALREADY_OPEN 0x91
|
||||
#define GATT_CANCEL 0x92
|
||||
|
||||
/* 0xE0 ~ 0xFC reserved for future use */
|
||||
#define GATT_STACK_RSP 0xE0
|
||||
#define GATT_APP_RSP 0xE1
|
||||
//Error caused by customer application or stack bug
|
||||
#define GATT_UNKNOWN_ERROR 0XEF
|
||||
|
||||
#define GATT_CCC_CFG_ERR 0xFD /* Client Characteristic Configuration Descriptor Improperly Configured */
|
||||
#define GATT_PRC_IN_PROGRESS 0xFE /* Procedure Already in progress */
|
||||
#define GATT_OUT_OF_RANGE 0xFF /* Attribute value out of range */
|
||||
|
||||
typedef UINT8 tGATT_STATUS;
|
||||
|
||||
|
||||
|
@ -54,6 +54,7 @@
|
||||
#define L2CAP_WAIT_INFO_RSP_TOUT 3 /* 3 seconds */
|
||||
#define L2CAP_WAIT_UNPARK_TOUT 2 /* 2 seconds */
|
||||
#define L2CAP_LINK_INFO_RESP_TOUT 2 /* 2 seconds */
|
||||
#define L2CAP_UPDATE_CONN_PARAM_TOUT 6 /* 6 seconds */
|
||||
#define L2CAP_BLE_LINK_CONNECT_TOUT 30 /* 30 seconds */
|
||||
#define L2CAP_BLE_CONN_PARAM_UPD_TOUT 30 /* 30 seconds */
|
||||
|
||||
@ -353,6 +354,7 @@ typedef struct t_l2c_linkcb {
|
||||
|
||||
tL2C_CCB *p_pending_ccb; /* ccb of waiting channel during link disconnect */
|
||||
TIMER_LIST_ENT info_timer_entry; /* Timer entry for info resp timeout evt */
|
||||
TIMER_LIST_ENT upda_con_timer; /* Timer entry for update connection parametr */
|
||||
BD_ADDR remote_bd_addr; /* The BD address of the remote */
|
||||
|
||||
UINT8 link_role; /* Master or slave */
|
||||
@ -404,6 +406,7 @@ typedef struct t_l2c_linkcb {
|
||||
|
||||
UINT16 min_interval; /* parameters as requested by peripheral */
|
||||
UINT16 max_interval;
|
||||
UINT16 conn_int;
|
||||
UINT16 latency;
|
||||
UINT16 timeout;
|
||||
|
||||
@ -728,7 +731,8 @@ extern void l2cble_conn_comp (UINT16 handle, UINT8 role, BD_ADDR bda, tBLE_ADDR_
|
||||
extern BOOLEAN l2cble_init_direct_conn (tL2C_LCB *p_lcb);
|
||||
extern void l2cble_notify_le_connection (BD_ADDR bda);
|
||||
extern void l2c_ble_link_adjust_allocation (void);
|
||||
extern void l2cble_process_conn_update_evt (UINT16 handle, UINT8 status);
|
||||
extern void l2cble_process_conn_update_evt (UINT16 handle, UINT8 status, UINT16 conn_interval,
|
||||
UINT16 conn_latency, UINT16 conn_timeout);
|
||||
|
||||
#if (defined BLE_LLT_INCLUDED) && (BLE_LLT_INCLUDED == TRUE)
|
||||
extern void l2cble_process_rc_param_request_evt(UINT16 handle, UINT16 int_min, UINT16 int_max,
|
||||
@ -738,6 +742,7 @@ extern void l2cble_process_rc_param_request_evt(UINT16 handle, UINT16 int_min, U
|
||||
extern void l2cble_update_data_length(tL2C_LCB *p_lcb);
|
||||
extern void l2cble_set_fixed_channel_tx_data_length(BD_ADDR remote_bda, UINT16 fix_cid,
|
||||
UINT16 tx_mtu);
|
||||
extern void l2c_send_update_conn_params_cb(tL2C_LCB *p_lcb, UINT8 status);
|
||||
extern void l2cble_process_data_length_change_event(UINT16 handle, UINT16 tx_data_len,
|
||||
UINT16 rx_data_len);
|
||||
|
||||
|
@ -62,11 +62,14 @@ enum {
|
||||
#define BTC_TASK_PRIO (configMAX_PRIORITIES - 6)
|
||||
#define BTC_TASK_QUEUE_NUM 60
|
||||
|
||||
void btu_task_post(uint32_t sig);
|
||||
void hci_host_task_post(void);
|
||||
void hci_hal_h4_task_post(void);
|
||||
void hci_drv_task_post(void);
|
||||
void bt_alarm_task_post(void);
|
||||
|
||||
#define TASK_POST_NON_BLOCKING (0)
|
||||
#define TASK_POST_BLOCKING (portMAX_DELAY)
|
||||
typedef uint32_t task_post_t; /* Timeout of task post return, unit TICK */
|
||||
|
||||
void btu_task_post(uint32_t sig, task_post_t timeout);
|
||||
void hci_host_task_post(task_post_t timeout);
|
||||
void hci_hal_h4_task_post(task_post_t timeout);
|
||||
|
||||
|
||||
#endif /* __THREAD_H__ */
|
||||
|
@ -11,11 +11,11 @@
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#ifndef __ESP32_IMAGE_FORMAT_H
|
||||
#define __ESP32_IMAGE_FORMAT_H
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <esp_err.h>
|
||||
#include "esp_flash_partitions.h"
|
||||
|
||||
#define ESP_ERR_IMAGE_BASE 0x2000
|
||||
#define ESP_ERR_IMAGE_FLASH_FAIL (ESP_ERR_IMAGE_BASE + 1)
|
||||
@ -59,13 +59,27 @@ typedef enum {
|
||||
typedef struct {
|
||||
uint8_t magic;
|
||||
uint8_t segment_count;
|
||||
uint8_t spi_mode; /* flash read mode (esp_image_spi_mode_t as uint8_t) */
|
||||
uint8_t spi_speed: 4; /* flash frequency (esp_image_spi_freq_t as uint8_t) */
|
||||
uint8_t spi_size: 4; /* flash chip size (esp_image_flash_size_t as uint8_t) */
|
||||
/* flash read mode (esp_image_spi_mode_t as uint8_t) */
|
||||
uint8_t spi_mode;
|
||||
/* flash frequency (esp_image_spi_freq_t as uint8_t) */
|
||||
uint8_t spi_speed: 4;
|
||||
/* flash chip size (esp_image_flash_size_t as uint8_t) */
|
||||
uint8_t spi_size: 4;
|
||||
uint32_t entry_addr;
|
||||
uint8_t encrypt_flag; /* encrypt flag */
|
||||
uint8_t extra_header[15]; /* ESP32 additional header, unused by second bootloader */
|
||||
} esp_image_header_t;
|
||||
/* WP pin when SPI pins set via efuse (read by ROM bootloader, the IDF bootloader uses software to configure the WP
|
||||
* pin and sets this field to 0xEE=disabled) */
|
||||
uint8_t wp_pin;
|
||||
/* Drive settings for the SPI flash pins (read by ROM bootloader) */
|
||||
uint8_t spi_pin_drv[3];
|
||||
/* Reserved bytes in ESP32 additional header space, currently unused */
|
||||
uint8_t reserved[11];
|
||||
/* If 1, a SHA256 digest "simple hash" (of the entire image) is appended after the checksum. Included in image length. This digest
|
||||
* is separate to secure boot and only used for detecting corruption. For secure boot signed images, the signature
|
||||
* is appended after this (and the simple hash is included in the signed data). */
|
||||
uint8_t hash_appended;
|
||||
} __attribute__((packed)) esp_image_header_t;
|
||||
|
||||
_Static_assert(sizeof(esp_image_header_t) == 24, "binary image header should be 24 bytes");
|
||||
|
||||
/* Header of binary image segment */
|
||||
typedef struct {
|
||||
@ -73,62 +87,60 @@ typedef struct {
|
||||
uint32_t data_len;
|
||||
} esp_image_segment_header_t;
|
||||
|
||||
#define ESP_IMAGE_MAX_SEGMENTS 16
|
||||
|
||||
/* Structure to hold on-flash image metadata */
|
||||
typedef struct {
|
||||
uint32_t start_addr; /* Start address of image */
|
||||
esp_image_header_t image; /* Header for entire image */
|
||||
esp_image_segment_header_t segments[ESP_IMAGE_MAX_SEGMENTS]; /* Per-segment header data */
|
||||
uint32_t segment_data[ESP_IMAGE_MAX_SEGMENTS]; /* Data offsets for each segment */
|
||||
uint32_t image_len; /* Length of image on flash, in bytes */
|
||||
} esp_image_metadata_t;
|
||||
|
||||
/* Mode selection for esp_image_load() */
|
||||
typedef enum {
|
||||
ESP_IMAGE_VERIFY, /* Verify image contents, load metadata. Print errorsors. */
|
||||
ESP_IMAGE_VERIFY_SILENT, /* Verify image contents, load metadata. Don't print errors. */
|
||||
#ifdef BOOTLOADER_BUILD
|
||||
ESP_IMAGE_LOAD, /* Verify image contents, load to memory. Print errors. */
|
||||
#endif
|
||||
} esp_image_load_mode_t;
|
||||
|
||||
/**
|
||||
* @brief Read an ESP image header from flash.
|
||||
* @brief Verify and (optionally, in bootloader mode) load an app image.
|
||||
*
|
||||
* If encryption is enabled, data will be transparently decrypted.
|
||||
*
|
||||
* @param src_addr Address in flash to load image header. Must be 4 byte aligned.
|
||||
* @param log_errors Log error output if image header appears invalid.
|
||||
* @param[out] image_header Pointer to an esp_image_header_t struture to be filled with data. If the function fails, contents are undefined.
|
||||
*
|
||||
* @return ESP_OK if image header was loaded, ESP_ERR_IMAGE_FLASH_FAIL
|
||||
* if a SPI flash error occurs, ESP_ERR_IMAGE_INVALID if the image header
|
||||
* appears invalid.
|
||||
*/
|
||||
esp_err_t esp_image_load_header(uint32_t src_addr, bool log_errors, esp_image_header_t *image_header);
|
||||
|
||||
/**
|
||||
* @brief Read the segment header and data offset of a segment in the image.
|
||||
*
|
||||
* If encryption is enabled, data will be transparently decrypted.
|
||||
*
|
||||
* @param index Index of the segment to load information for.
|
||||
* @param src_addr Base address in flash of the image.
|
||||
* @param[in] image_header Pointer to the flash image header, already loaded by @ref esp_image_load_header().
|
||||
* @param log_errors Log errors reading the segment header.
|
||||
* @param[out] segment_header Pointer to a segment header structure to be filled with data. If the function fails, contents are undefined.
|
||||
* @param[out] segment_data_offset Pointer to the data offset of the segment.
|
||||
*
|
||||
* @return ESP_OK if segment_header & segment_data_offset were loaded successfully, ESP_ERR_IMAGE_FLASH_FAIL if a SPI flash error occurs, ESP_ERR_IMAGE_INVALID if the image header appears invalid, ESP_ERR_INVALID_ARG if the index is invalid.
|
||||
*/
|
||||
esp_err_t esp_image_load_segment_header(uint8_t index, uint32_t src_addr, const esp_image_header_t *image_header, bool log_errors, esp_image_segment_header_t *segment_header, uint32_t *segment_data_offset);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Non-cryptographically validate app image integrity. On success, length of image is provided to caller.
|
||||
*
|
||||
* If the image has a secure boot signature appended, the signature is not checked and this length is not included in the
|
||||
* output value.
|
||||
* @param mode Mode of operation (verify, silent verify, or load).
|
||||
* @param part Partition to load the app from.
|
||||
* @param[inout] data Pointer to the image metadata structure which is be filled in by this function. 'start_addr' member should be set (to the start address of the image.) Other fields will all be initialised by this function.
|
||||
*
|
||||
* Image validation checks:
|
||||
* - Magic byte
|
||||
* - No single segment longer than 16MB
|
||||
* - Total image no longer than 16MB
|
||||
* - 8 bit image checksum is valid
|
||||
*
|
||||
* If flash encryption is enabled, the image will be tranpsarently decrypted.
|
||||
*
|
||||
* @param src_addr Offset of the start of the image in flash. Must be 4 byte aligned.
|
||||
* @param allow_decrypt If true and flash encryption is enabled, the image will be transparently decrypted.
|
||||
* @param log_errors Log errors verifying the image.
|
||||
* @param[out] length Length of the image, set to a value if the image is valid. Can be null.
|
||||
*
|
||||
* @return ESP_OK if image is valid, ESP_FAIL or ESP_ERR_IMAGE_INVALID on errors.
|
||||
* - Magic byte.
|
||||
* - Partition smaller than 16MB.
|
||||
* - All segments & image fit in partition.
|
||||
* - 8 bit image checksum is valid.
|
||||
* - SHA-256 of image is valid (if image has this appended).
|
||||
* - (Signature) if signature verification is enabled.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK if verify or load was successful
|
||||
* - ESP_ERR_IMAGE_FLASH_FAIL if a SPI flash error occurs
|
||||
* - ESP_ERR_IMAGE_INVALID if the image appears invalid.
|
||||
* - ESP_ERR_INVALID_ARG if the partition or data pointers are invalid.
|
||||
*/
|
||||
esp_err_t esp_image_basic_verify(uint32_t src_addr, bool log_errors, uint32_t *length);
|
||||
esp_err_t esp_image_load(esp_image_load_mode_t mode, const esp_partition_pos_t *part, esp_image_metadata_t *data);
|
||||
|
||||
/**
|
||||
* @brief Verify the bootloader image.
|
||||
*
|
||||
* @param[out] If result is ESP_OK and this pointer is non-NULL, it
|
||||
* will be set to the length of the bootloader image.
|
||||
*
|
||||
* @return As per esp_image_load_metadata().
|
||||
*/
|
||||
esp_err_t esp_image_verify_bootloader(uint32_t *length);
|
||||
|
||||
|
||||
typedef struct {
|
||||
@ -139,5 +151,3 @@ typedef struct {
|
||||
uint32_t irom_load_addr;
|
||||
uint32_t irom_size;
|
||||
} esp_image_flash_mapping_t;
|
||||
|
||||
#endif
|
||||
|
@ -11,13 +11,16 @@
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#ifndef __ESP32_SECUREBOOT_H
|
||||
#define __ESP32_SECUREBOOT_H
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <esp_err.h>
|
||||
#include "soc/efuse_reg.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Support functions for secure boot features.
|
||||
|
||||
Can be compiled as part of app or bootloader code.
|
||||
@ -74,12 +77,22 @@ esp_err_t esp_secure_boot_permanently_enable(void);
|
||||
*/
|
||||
esp_err_t esp_secure_boot_verify_signature(uint32_t src_addr, uint32_t length);
|
||||
|
||||
/** @brief Verify the secure boot signature block (deterministic ECDSA w/ SHA256) based on the SHA256 hash of some data.
|
||||
*
|
||||
* Similar to esp_secure_boot_verify_signature(), but can be used when the digest is precalculated.
|
||||
* @param sig_block Pointer to signature block data
|
||||
* @param image_digest Pointer to 32 byte buffer holding SHA-256 hash.
|
||||
*
|
||||
*/
|
||||
|
||||
/** @brief Secure boot verification block, on-flash data format. */
|
||||
typedef struct {
|
||||
uint32_t version;
|
||||
uint8_t signature[64];
|
||||
} esp_secure_boot_sig_block_t;
|
||||
|
||||
esp_err_t esp_secure_boot_verify_signature_block(const esp_secure_boot_sig_block_t *sig_block, const uint8_t *image_digest);
|
||||
|
||||
#define FLASH_OFFS_SECURE_BOOT_IV_DIGEST 0
|
||||
|
||||
/** @brief Secure boot IV+digest header */
|
||||
@ -88,4 +101,7 @@ typedef struct {
|
||||
uint8_t digest[64];
|
||||
} esp_secure_boot_iv_digest_t;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include <stdbool.h>
|
||||
#include "esp_err.h"
|
||||
#include "sdkconfig.h"
|
||||
#include "esp_task.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -30,6 +31,8 @@ extern "C" {
|
||||
* some options or parameters of some functions enabled by config mask.
|
||||
*/
|
||||
typedef struct {
|
||||
uint16_t controller_task_stack_size; /*!< Bluetooth controller task stack size */
|
||||
uint8_t controller_task_prio; /*!< Bluetooth controller task priority */
|
||||
uint8_t hci_uart_no; /*!< If use UART1/2 as HCI IO interface, indicate UART number */
|
||||
uint32_t hci_uart_baudrate; /*!< If use UART1/2 as HCI IO interface, indicate UART baudrate */
|
||||
} esp_bt_controller_config_t;
|
||||
@ -49,8 +52,10 @@ typedef struct {
|
||||
#endif /* BT_HCI_UART_BAUDRATE_DEFAULT */
|
||||
|
||||
#define BT_CONTROLLER_INIT_CONFIG_DEFAULT() { \
|
||||
.hci_uart_no = BT_HCI_UART_NO_DEFAULT,\
|
||||
.hci_uart_baudrate = BT_HCI_UART_BAUDRATE_DEFAULT,\
|
||||
.controller_task_stack_size = ESP_TASK_BT_CONTROLLER_STACK, \
|
||||
.controller_task_prio = ESP_TASK_BT_CONTROLLER_PRIO, \
|
||||
.hci_uart_no = BT_HCI_UART_NO_DEFAULT, \
|
||||
.hci_uart_baudrate = BT_HCI_UART_BAUDRATE_DEFAULT, \
|
||||
};
|
||||
#else
|
||||
#define BT_CONTROLLER_INIT_CONFIG_DEFAULT() {0}; _Static_assert(0, "please enable bluetooth in menuconfig to use bt.h");
|
||||
@ -76,6 +81,66 @@ typedef enum {
|
||||
ESP_BT_CONTROLLER_STATUS_NUM,
|
||||
} esp_bt_controller_status_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief BLE tx power type
|
||||
* ESP_BLE_PWR_TYPE_CONN_HDL0-9: for each connection, and only be set after connetion completed.
|
||||
* when disconnect, the correspond TX power is not effected.
|
||||
* ESP_BLE_PWR_TYPE_ADV : for advertising/scan response.
|
||||
* ESP_BLE_PWR_TYPE_SCAN : for scan.
|
||||
* ESP_BLE_PWR_TYPE_DEFAULT : if each connection's TX power is not set, it will use this default value.
|
||||
* if neither in scan mode nor in adv mode, it will use this default value.
|
||||
* If none of power type is set, system will use ESP_PWR_LVL_P1 as default for ADV/SCAN/CONN0-9.
|
||||
*/
|
||||
typedef enum {
|
||||
ESP_BLE_PWR_TYPE_CONN_HDL0 = 0, /*!< For connection handle 0 */
|
||||
ESP_BLE_PWR_TYPE_CONN_HDL1 = 1, /*!< For connection handle 1 */
|
||||
ESP_BLE_PWR_TYPE_CONN_HDL2 = 2, /*!< For connection handle 2 */
|
||||
ESP_BLE_PWR_TYPE_CONN_HDL3 = 3, /*!< For connection handle 3 */
|
||||
ESP_BLE_PWR_TYPE_CONN_HDL4 = 4, /*!< For connection handle 4 */
|
||||
ESP_BLE_PWR_TYPE_CONN_HDL5 = 5, /*!< For connection handle 5 */
|
||||
ESP_BLE_PWR_TYPE_CONN_HDL6 = 6, /*!< For connection handle 6 */
|
||||
ESP_BLE_PWR_TYPE_CONN_HDL7 = 7, /*!< For connection handle 7 */
|
||||
ESP_BLE_PWR_TYPE_CONN_HDL8 = 8, /*!< For connection handle 8 */
|
||||
ESP_BLE_PWR_TYPE_CONN_HDL9 = 9, /*!< For connection handle 9 */
|
||||
ESP_BLE_PWR_TYPE_ADV = 10, /*!< For advertising */
|
||||
ESP_BLE_PWR_TYPE_SCAN = 11, /*!< For scan */
|
||||
ESP_BLE_PWR_TYPE_DEFAULT = 12, /*!< For default, if not set other, it will use default value */
|
||||
ESP_BLE_PWR_TYPE_NUM = 13, /*!< TYPE numbers */
|
||||
} esp_ble_power_type_t;
|
||||
|
||||
/**
|
||||
* @brief Bluetooth TX power level(index), it's just a index corresponding to power(dbm).
|
||||
*/
|
||||
typedef enum {
|
||||
ESP_PWR_LVL_N14 = 0, /*!< Corresponding to -14dbm */
|
||||
ESP_PWR_LVL_N11 = 1, /*!< Corresponding to -11dbm */
|
||||
ESP_PWR_LVL_N8 = 2, /*!< Corresponding to -8dbm */
|
||||
ESP_PWR_LVL_N5 = 3, /*!< Corresponding to -5dbm */
|
||||
ESP_PWR_LVL_N2 = 4, /*!< Corresponding to -2dbm */
|
||||
ESP_PWR_LVL_P1 = 5, /*!< Corresponding to 1dbm */
|
||||
ESP_PWR_LVL_P4 = 6, /*!< Corresponding to 4dbm */
|
||||
ESP_PWR_LVL_P7 = 7, /*!< Corresponding to 7dbm */
|
||||
} esp_power_level_t;
|
||||
|
||||
/**
|
||||
* @brief Set BLE TX power
|
||||
* Connection Tx power should only be set after connection created.
|
||||
* @param power_type : The type of which tx power, could set Advertising/Connection/Default and etc
|
||||
* @param power_level: Power level(index) corresponding to absolute value(dbm)
|
||||
* @return ESP_OK - success, other - failed
|
||||
*/
|
||||
esp_err_t esp_ble_tx_power_set(esp_ble_power_type_t power_type, esp_power_level_t power_level);
|
||||
|
||||
/**
|
||||
* @brief Get BLE TX power
|
||||
* Connection Tx power should only be get after connection created.
|
||||
* @param power_type : The type of which tx power, could set Advertising/Connection/Default and etc
|
||||
* @return >= 0 - Power level, < 0 - Invalid
|
||||
*/
|
||||
esp_power_level_t esp_ble_tx_power_get(esp_ble_power_type_t power_type);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initialize BT controller to allocate task and other resource.
|
||||
* @param cfg: Initial configuration of BT controller.
|
||||
@ -89,8 +154,9 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg);
|
||||
*
|
||||
* This function should be called only once, after any other BT functions are called.
|
||||
* This function is not whole completed, esp_bt_controller_init cannot called after this function.
|
||||
* @return ESP_OK - success, other - failed
|
||||
*/
|
||||
void esp_bt_controller_deinit(void);
|
||||
esp_err_t esp_bt_controller_deinit(void);
|
||||
|
||||
/**
|
||||
* @brief Enable BT controller
|
||||
|
@ -9,12 +9,18 @@
|
||||
#define CONFIG_PHY_ENABLED 1
|
||||
#define CONFIG_TRACEMEM_RESERVE_DRAM 0x0
|
||||
#define CONFIG_FREERTOS_MAX_TASK_NAME_LEN 16
|
||||
#define CONFIG_BLE_SMP_ENABLE 1
|
||||
#define CONFIG_TCP_RECVMBOX_SIZE 6
|
||||
#define CONFIG_TCP_WND_DEFAULT 5744
|
||||
#define CONFIG_SW_COEXIST_ENABLE 1
|
||||
#define CONFIG_ESPTOOLPY_FLASHSIZE_4MB 1
|
||||
#define CONFIG_IPC_TASK_STACK_SIZE 1024
|
||||
#define CONFIG_ESPTOOLPY_FLASHFREQ "80m"
|
||||
#define CONFIG_NEWLIB_STDOUT_ADDCR 1
|
||||
#define CONFIG_UDP_RECVMBOX_SIZE 6
|
||||
#define CONFIG_TASK_WDT_CHECK_IDLE_TASK 1
|
||||
#define CONFIG_ESPTOOLPY_FLASHSIZE "4MB"
|
||||
#define CONFIG_BROWNOUT_DET_LVL_SEL_0 1
|
||||
#define CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER 1
|
||||
#define CONFIG_ETHERNET 1
|
||||
#define CONFIG_EMAC_L2_TO_L3_RX_BUF_MODE 1
|
||||
@ -27,17 +33,21 @@
|
||||
#define CONFIG_LWIP_MAX_SOCKETS 10
|
||||
#define CONFIG_EMAC_TASK_PRIORITY 20
|
||||
#define CONFIG_TIMER_TASK_STACK_DEPTH 2048
|
||||
#define CONFIG_TCP_MSS 1436
|
||||
#define CONFIG_FATFS_CODEPAGE 850
|
||||
#define CONFIG_ULP_COPROC_RESERVE_MEM 512
|
||||
#define CONFIG_ESPTOOLPY_BAUD 921600
|
||||
#define CONFIG_INT_WDT_CHECK_CPU1 1
|
||||
#define CONFIG_ESPTOOLPY_AFTER_RESET 1
|
||||
#define CONFIG_OPTIMIZATION_ASSERTIONS_ENABLED 1
|
||||
#define CONFIG_TOOLPREFIX "xtensa-esp32-elf-"
|
||||
#define CONFIG_FREERTOS_IDLE_TASK_STACKSIZE 1024
|
||||
#define CONFIG_FATFS_LFN_STACK 1
|
||||
#define CONFIG_ESP32_WIFI_AMPDU_ENABLED 1
|
||||
#define CONFIG_CONSOLE_UART_NUM 0
|
||||
#define CONFIG_ESP32_RTC_CLOCK_SOURCE_INTERNAL_RC 1
|
||||
#define CONFIG_LWIP_THREAD_LOCAL_STORAGE_INDEX 0
|
||||
#define CONFIG_TCP_OVERSIZE_MSS 1
|
||||
#define CONFIG_FOUR_UNIVERSAL_MAC_ADDRESS 1
|
||||
#define CONFIG_CONSOLE_UART_DEFAULT 1
|
||||
#define CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN 16384
|
||||
@ -45,7 +55,6 @@
|
||||
#define CONFIG_ESPTOOLPY_FLASHSIZE_DETECT 1
|
||||
#define CONFIG_AUTOSTART_ARDUINO 1
|
||||
#define CONFIG_LOG_DEFAULT_LEVEL_ERROR 1
|
||||
#define CONFIG_MBEDTLS_MPI_USE_INTERRUPT 1
|
||||
#define CONFIG_ESP32_ENABLE_COREDUMP_TO_NONE 1
|
||||
#define CONFIG_BTDM_CONTROLLER_RUN_CPU 0
|
||||
#define CONFIG_TCPIP_TASK_STACK_SIZE 2560
|
||||
@ -54,15 +63,17 @@
|
||||
#define CONFIG_MAIN_TASK_STACK_SIZE 4096
|
||||
#define CONFIG_TASK_WDT_TIMEOUT_S 5
|
||||
#define CONFIG_INT_WDT_TIMEOUT_MS 300
|
||||
#define CONFIG_ESPTOOLPY_FLASHMODE "dio"
|
||||
#define CONFIG_ESPTOOLPY_FLASHMODE "dout"
|
||||
#define CONFIG_BTC_TASK_STACK_SIZE 2048
|
||||
#define CONFIG_BLUEDROID_ENABLED 1
|
||||
#define CONFIG_ESPTOOLPY_BEFORE "default_reset"
|
||||
#define CONFIG_LOG_DEFAULT_LEVEL 1
|
||||
#define CONFIG_TIMER_QUEUE_LENGTH 10
|
||||
#define CONFIG_FLASHMODE_DOUT 1
|
||||
#define CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM 0
|
||||
#define CONFIG_ESP32_PHY_MAX_WIFI_TX_POWER 20
|
||||
#define CONFIG_ESP32_RTC_CLK_CAL_CYCLES 1024
|
||||
#define CONFIG_ESP32_WIFI_TX_BA_WIN 6
|
||||
#define CONFIG_ESP32_WIFI_NVS_ENABLED 1
|
||||
#define CONFIG_ULP_COPROC_ENABLED 1
|
||||
#define CONFIG_DMA_RX_BUF_NUM 10
|
||||
@ -71,21 +82,23 @@
|
||||
#define CONFIG_ESP32_TIME_SYSCALL_USE_RTC_FRC1 1
|
||||
#define CONFIG_ESPTOOLPY_COMPRESSED 1
|
||||
#define CONFIG_PARTITION_TABLE_FILENAME "partitions_singleapp.csv"
|
||||
#define CONFIG_TCP_SND_BUF_DEFAULT 5744
|
||||
#define CONFIG_LWIP_DHCP_MAX_NTP_SERVERS 1
|
||||
#define CONFIG_PARTITION_TABLE_SINGLE_APP 1
|
||||
#define CONFIG_ESP32_WIFI_RX_BA_WIN 6
|
||||
#define CONFIG_WIFI_ENABLED 1
|
||||
#define CONFIG_FLASHMODE_QIO 1
|
||||
#define CONFIG_ESPTOOLPY_FLASHFREQ_80M 1
|
||||
#define CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE 2048
|
||||
#define CONFIG_ESP32_DEEP_SLEEP_WAKEUP_DELAY 2000
|
||||
#define CONFIG_BROWNOUT_DET_LVL 0
|
||||
#define CONFIG_ESP32_APPTRACE_DEST_NONE 1
|
||||
#define CONFIG_PARTITION_TABLE_CUSTOM_APP_BIN_OFFSET 0x10000
|
||||
#define CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM 32
|
||||
#define CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ 240
|
||||
#define CONFIG_MBEDTLS_HARDWARE_AES 1
|
||||
#define CONFIG_FREERTOS_HZ 1000
|
||||
#define CONFIG_ESP32_PHY_CALIBRATION_AND_DATA_STORAGE 1
|
||||
#define CONFIG_FREERTOS_ASSERT_FAIL_ABORT 1
|
||||
#define CONFIG_BROWNOUT_DET 1
|
||||
#define CONFIG_ESP32_XTAL_FREQ 0
|
||||
#define CONFIG_MONITOR_BAUD_115200B 1
|
||||
#define CONFIG_LOG_BOOTLOADER_LEVEL 0
|
||||
@ -103,11 +116,11 @@
|
||||
#define CONFIG_TIMER_TASK_PRIORITY 1
|
||||
#define CONFIG_BT_ENABLED 1
|
||||
#define CONFIG_MONITOR_BAUD 115200
|
||||
#define CONFIG_MBEDTLS_HARDWARE_SHA 1
|
||||
#define CONFIG_FREERTOS_CORETIMER_0 1
|
||||
#define CONFIG_PARTITION_TABLE_CUSTOM_FILENAME "partitions.csv"
|
||||
#define CONFIG_MBEDTLS_HAVE_TIME 1
|
||||
#define CONFIG_FREERTOS_CHECK_STACKOVERFLOW_CANARY 1
|
||||
#define CONFIG_TCP_QUEUE_OOSEQ 1
|
||||
#define CONFIG_GATTS_ENABLE 1
|
||||
#define CONFIG_FREERTOS_ISR_STACKSIZE 1536
|
||||
#define CONFIG_CLASSIC_BT_ENABLED 1
|
||||
@ -123,8 +136,7 @@
|
||||
#define CONFIG_MEMMAP_SMP 1
|
||||
#define CONFIG_SPI_FLASH_ROM_DRIVER_PATCH 1
|
||||
#define CONFIG_LWIP_SO_RCVBUF 1
|
||||
#define CONFIG_MBEDTLS_HARDWARE_MPI 1
|
||||
#define CONFIG_MONITOR_BAUD_OTHER_VAL 115200
|
||||
#define CONFIG_ESPTOOLPY_PORT "/dev/cu.usbserial-0030121AB"
|
||||
#define CONFIG_ESPTOOLPY_PORT "/dev/cu.usbserial-DO00EAB0"
|
||||
#define CONFIG_ESP32_PANIC_PRINT_HALT 1
|
||||
#define CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL_ERROR 1
|
||||
|
@ -109,6 +109,17 @@ esp_err_t adc1_config_channel_atten(adc1_channel_t channel, adc_atten_t atten);
|
||||
*/
|
||||
int adc1_get_voltage(adc1_channel_t channel);
|
||||
|
||||
/**
|
||||
* @brief Configure ADC1 to be usable by the ULP
|
||||
*
|
||||
* This function reconfigures ADC1 to be controlled by the ULP.
|
||||
* Effect of this function can be reverted using adc1_get_voltage function.
|
||||
*
|
||||
* Note that adc1_config_channel_atten, adc1_config_width functions need
|
||||
* to be called to configure ADC1 channels, before ADC1 is used by the ULP.
|
||||
*/
|
||||
void adc1_ulp_enable();
|
||||
|
||||
/**
|
||||
* @brief Read Hall Sensor
|
||||
*
|
||||
|
@ -28,7 +28,7 @@ typedef enum {
|
||||
DAC_CHANNEL_MAX,
|
||||
} dac_channel_t;
|
||||
|
||||
|
||||
/** @cond */
|
||||
/**
|
||||
* @brief Set DAC output voltage.
|
||||
*
|
||||
@ -45,6 +45,7 @@ typedef enum {
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t dac_out_voltage(dac_channel_t channel, uint8_t dac_value) __attribute__ ((deprecated));
|
||||
/** @endcond */
|
||||
|
||||
/**
|
||||
* @brief Set DAC output voltage.
|
||||
|
@ -31,7 +31,13 @@ extern "C" {
|
||||
|
||||
#define GPIO_SEL_0 (BIT(0)) /*!< Pin 0 selected */
|
||||
#define GPIO_SEL_1 (BIT(1)) /*!< Pin 1 selected */
|
||||
#define GPIO_SEL_2 (BIT(2)) /*!< Pin 2 selected */
|
||||
#define GPIO_SEL_2 (BIT(2)) /*!< Pin 2 selected
|
||||
@note There are more macros
|
||||
like that up to pin 39,
|
||||
excluding pins 20, 24 and 28..31.
|
||||
They are not shown here
|
||||
to reduce redundant information. */
|
||||
/** @cond */
|
||||
#define GPIO_SEL_3 (BIT(3)) /*!< Pin 3 selected */
|
||||
#define GPIO_SEL_4 (BIT(4)) /*!< Pin 4 selected */
|
||||
#define GPIO_SEL_5 (BIT(5)) /*!< Pin 5 selected */
|
||||
@ -114,14 +120,21 @@ extern "C" {
|
||||
#define GPIO_MODE_DEF_OD (BIT2)
|
||||
|
||||
#define GPIO_PIN_COUNT 40
|
||||
/** @endcond */
|
||||
|
||||
extern const uint32_t GPIO_PIN_MUX_REG[GPIO_PIN_COUNT];
|
||||
#define GPIO_IS_VALID_GPIO(gpio_num) ((gpio_num < GPIO_PIN_COUNT && GPIO_PIN_MUX_REG[gpio_num] != 0)) //to decide whether it is a valid GPIO number
|
||||
#define GPIO_IS_VALID_OUTPUT_GPIO(gpio_num) ((GPIO_IS_VALID_GPIO(gpio_num)) && (gpio_num < 34)) //to decide whether it can be a valid GPIO number of output mode
|
||||
#define GPIO_IS_VALID_GPIO(gpio_num) ((gpio_num < GPIO_PIN_COUNT && GPIO_PIN_MUX_REG[gpio_num] != 0)) /*!< Check whether it is a valid GPIO number */
|
||||
#define GPIO_IS_VALID_OUTPUT_GPIO(gpio_num) ((GPIO_IS_VALID_GPIO(gpio_num)) && (gpio_num < 34)) /*!< Check whether it can be a valid GPIO number of output mode */
|
||||
|
||||
typedef enum {
|
||||
GPIO_NUM_0 = 0, /*!< GPIO0, input and output */
|
||||
GPIO_NUM_1 = 1, /*!< GPIO1, input and output */
|
||||
GPIO_NUM_2 = 2, /*!< GPIO2, input and output */
|
||||
GPIO_NUM_2 = 2, /*!< GPIO2, input and output
|
||||
@note There are more enumerations like that
|
||||
up to GPIO39, excluding GPIO20, GPIO24 and GPIO28..31.
|
||||
They are not shown here to reduce redundant information.
|
||||
@note GPIO34..39 are input mode only. */
|
||||
/** @cond */
|
||||
GPIO_NUM_3 = 3, /*!< GPIO3, input and output */
|
||||
GPIO_NUM_4 = 4, /*!< GPIO4, input and output */
|
||||
GPIO_NUM_5 = 5, /*!< GPIO5, input and output */
|
||||
@ -157,6 +170,7 @@ typedef enum {
|
||||
GPIO_NUM_38 = 38, /*!< GPIO38, input mode only */
|
||||
GPIO_NUM_39 = 39, /*!< GPIO39, input mode only */
|
||||
GPIO_NUM_MAX = 40,
|
||||
/** @endcond */
|
||||
} gpio_num_t;
|
||||
|
||||
typedef enum {
|
||||
@ -412,7 +426,7 @@ esp_err_t gpio_pulldown_dis(gpio_num_t gpio_num);
|
||||
/**
|
||||
* @brief Install the driver's GPIO ISR handler service, which allows per-pin GPIO interrupt handlers.
|
||||
*
|
||||
* This function is incompatible with gpio_isr_register() - if that function is used, a single global ISR is registered for all GPIO interrupts. If this function is used, the ISR service provides a global GPIO ISR and individual pin handlers are registered via the gpio_isr_register() function.
|
||||
* This function is incompatible with gpio_isr_register() - if that function is used, a single global ISR is registered for all GPIO interrupts. If this function is used, the ISR service provides a global GPIO ISR and individual pin handlers are registered via the gpio_isr_handler_add() function.
|
||||
*
|
||||
* @param intr_alloc_flags Flags used to allocate the interrupt. One or multiple (ORred)
|
||||
* ESP_INTR_FLAG_* values. See esp_intr_alloc.h for more info.
|
||||
|
48
tools/sdk/include/driver/driver/rtc_cntl.h
Normal file
48
tools/sdk/include/driver/driver/rtc_cntl.h
Normal file
@ -0,0 +1,48 @@
|
||||
// Copyright 2016-2017 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include "esp_err.h"
|
||||
#include "esp_intr_alloc.h"
|
||||
|
||||
/**
|
||||
* @brief Register a handler for specific RTC_CNTL interrupts
|
||||
*
|
||||
* Multiple handlers can be registered using this function. Whenever an
|
||||
* RTC interrupt happens, all handlers with matching rtc_intr_mask values
|
||||
* will be called.
|
||||
*
|
||||
* @param handler handler function to call
|
||||
* @param handler_arg argument to be passed to the handler
|
||||
* @param rtc_intr_mask combination of RTC_CNTL_*_INT_ENA bits indicating the
|
||||
* sources to call the handler for
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_NO_MEM not enough memory to allocate handler structure
|
||||
* - other errors returned by esp_intr_alloc
|
||||
*/
|
||||
esp_err_t rtc_isr_register(intr_handler_t handler, void* handler_arg,
|
||||
uint32_t rtc_intr_mask);
|
||||
/**
|
||||
* @brief Deregister the handler previously registered using rtc_isr_register
|
||||
* @param handler handler function to call (as passed to rtc_isr_register)
|
||||
* @param handler_arg argument of the handler (as passed to rtc_isr_register)
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_INVALID_STATE if a handler matching both handler and
|
||||
* handler_arg isn't registered
|
||||
*/
|
||||
esp_err_t rtc_isr_deregister(intr_handler_t handler, void* handler_arg);
|
@ -30,6 +30,7 @@
|
||||
#define MMC_SELECT_CARD 7 /* R1 */
|
||||
#define MMC_SEND_EXT_CSD 8 /* R1 */
|
||||
#define MMC_SEND_CSD 9 /* R2 */
|
||||
#define MMC_SEND_CID 10 /* R1 */
|
||||
#define MMC_STOP_TRANSMISSION 12 /* R1B */
|
||||
#define MMC_SEND_STATUS 13 /* R1 */
|
||||
#define MMC_SET_BLOCKLEN 16 /* R1 */
|
||||
@ -44,9 +45,12 @@
|
||||
#define SD_SEND_RELATIVE_ADDR 3 /* R6 */
|
||||
#define SD_SEND_SWITCH_FUNC 6 /* R1 */
|
||||
#define SD_SEND_IF_COND 8 /* R7 */
|
||||
#define SD_READ_OCR 58 /* R3 */
|
||||
#define SD_CRC_ON_OFF 59 /* R1 */
|
||||
|
||||
/* SD application commands */ /* response type */
|
||||
#define SD_APP_SET_BUS_WIDTH 6 /* R1 */
|
||||
#define SD_APP_SD_STATUS 13 /* R2 */
|
||||
#define SD_APP_OP_COND 41 /* R3 */
|
||||
#define SD_APP_SEND_SCR 51 /* R1 */
|
||||
|
||||
@ -76,16 +80,26 @@
|
||||
#define SD_OCR_SDHC_CAP (1<<30)
|
||||
#define SD_OCR_VOL_MASK 0xFF8000 /* bits 23:15 */
|
||||
|
||||
/* R1 response type bits */
|
||||
/* SD mode R1 response type bits */
|
||||
#define MMC_R1_READY_FOR_DATA (1<<8) /* ready for next transfer */
|
||||
#define MMC_R1_APP_CMD (1<<5) /* app. commands supported */
|
||||
|
||||
/* SPI mode R1 response type bits */
|
||||
#define SD_SPI_R1_IDLE_STATE (1<<0)
|
||||
#define SD_SPI_R1_CMD_CRC_ERR (1<<3)
|
||||
|
||||
/* 48-bit response decoding (32 bits w/o CRC) */
|
||||
#define MMC_R1(resp) ((resp)[0])
|
||||
#define MMC_R3(resp) ((resp)[0])
|
||||
#define SD_R6(resp) ((resp)[0])
|
||||
#define MMC_R1_CURRENT_STATE(resp) (((resp)[0] >> 9) & 0xf)
|
||||
|
||||
/* SPI mode response decoding */
|
||||
#define SD_SPI_R1(resp) ((resp)[0] & 0xff)
|
||||
#define SD_SPI_R2(resp) ((resp)[0] & 0xffff)
|
||||
#define SD_SPI_R3(resp) ((resp)[0])
|
||||
#define SD_SPI_R7(resp) ((resp)[0])
|
||||
|
||||
/* RCA argument and response */
|
||||
#define MMC_ARG_RCA(rca) ((rca) << 16)
|
||||
#define SD_R6_RCA(resp) (SD_R6((resp)) >> 16)
|
||||
|
@ -113,7 +113,7 @@ typedef struct {
|
||||
int max_freq_khz; /*!< max frequency supported by the host */
|
||||
#define SDMMC_FREQ_DEFAULT 20000 /*!< SD/MMC Default speed (limited by clock divider) */
|
||||
#define SDMMC_FREQ_HIGHSPEED 40000 /*!< SD High speed (limited by clock divider) */
|
||||
#define SDMMC_FREQ_PROBING 4000 /*!< SD/MMC probing speed */
|
||||
#define SDMMC_FREQ_PROBING 400 /*!< SD/MMC probing speed */
|
||||
float io_voltage; /*!< I/O voltage used by the controller (voltage switching is not supported) */
|
||||
esp_err_t (*init)(void); /*!< Host function to initialize the driver */
|
||||
esp_err_t (*set_bus_width)(int slot, size_t width); /*!< host function to set bus width */
|
||||
|
156
tools/sdk/include/driver/driver/sdspi_host.h
Normal file
156
tools/sdk/include/driver/driver/sdspi_host.h
Normal file
@ -0,0 +1,156 @@
|
||||
// Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include "esp_err.h"
|
||||
#include "sdmmc_types.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/spi_master.h"
|
||||
#include "driver/sdmmc_host.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Default sdmmc_host_t structure initializer for SD over SPI driver
|
||||
*
|
||||
* Uses SPI mode and max frequency set to 20MHz
|
||||
*
|
||||
* 'slot' can be set to one of HSPI_HOST, VSPI_HOST.
|
||||
*/
|
||||
#define SDSPI_HOST_DEFAULT() {\
|
||||
.flags = SDMMC_HOST_FLAG_SPI, \
|
||||
.slot = HSPI_HOST, \
|
||||
.max_freq_khz = SDMMC_FREQ_DEFAULT, \
|
||||
.io_voltage = 3.3f, \
|
||||
.init = &sdspi_host_init, \
|
||||
.set_bus_width = NULL, \
|
||||
.set_card_clk = &sdspi_host_set_card_clk, \
|
||||
.do_transaction = &sdspi_host_do_transaction, \
|
||||
.deinit = &sdspi_host_deinit, \
|
||||
}
|
||||
|
||||
/**
|
||||
* Extra configuration for SPI host
|
||||
*/
|
||||
typedef struct {
|
||||
gpio_num_t gpio_miso; ///< GPIO number of MISO signal
|
||||
gpio_num_t gpio_mosi; ///< GPIO number of MOSI signal
|
||||
gpio_num_t gpio_sck; ///< GPIO number of SCK signal
|
||||
gpio_num_t gpio_cs; ///< GPIO number of CS signal
|
||||
gpio_num_t gpio_cd; ///< GPIO number of card detect signal
|
||||
gpio_num_t gpio_wp; ///< GPIO number of write protect signal
|
||||
int dma_channel; ///< DMA channel to be used by SPI driver (1 or 2)
|
||||
} sdspi_slot_config_t;
|
||||
|
||||
#define SDSPI_SLOT_NO_CD ((gpio_num_t) -1) ///< indicates that card detect line is not used
|
||||
#define SDSPI_SLOT_NO_WP ((gpio_num_t) -1) ///< indicates that write protect line is not used
|
||||
|
||||
/**
|
||||
* Macro defining default configuration of SPI host
|
||||
*/
|
||||
#define SDSPI_SLOT_CONFIG_DEFAULT() {\
|
||||
.gpio_miso = GPIO_NUM_2, \
|
||||
.gpio_mosi = GPIO_NUM_15, \
|
||||
.gpio_sck = GPIO_NUM_14, \
|
||||
.gpio_cs = GPIO_NUM_13, \
|
||||
.gpio_cd = SDMMC_SLOT_NO_CD, \
|
||||
.gpio_wp = SDMMC_SLOT_NO_WP, \
|
||||
.dma_channel = 1 \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize SD SPI driver
|
||||
*
|
||||
* @note This function is not thread safe
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - other error codes may be returned in future versions
|
||||
*/
|
||||
esp_err_t sdspi_host_init();
|
||||
|
||||
/**
|
||||
* @brief Initialize SD SPI driver for the specific SPI controller
|
||||
*
|
||||
* @note This function is not thread safe
|
||||
*
|
||||
* @param slot SPI controller to use (HSPI_HOST or VSPI_HOST)
|
||||
* @param slot_config pointer to slot configuration structure
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_INVALID_ARG if sdspi_init_slot has invalid arguments
|
||||
* - ESP_ERR_NO_MEM if memory can not be allocated
|
||||
* - other errors from the underlying spi_master and gpio drivers
|
||||
*/
|
||||
esp_err_t sdspi_host_init_slot(int slot, const sdspi_slot_config_t* slot_config);
|
||||
|
||||
/**
|
||||
* @brief Send command to the card and get response
|
||||
*
|
||||
* This function returns when command is sent and response is received,
|
||||
* or data is transferred, or timeout occurs.
|
||||
*
|
||||
* @note This function is not thread safe w.r.t. init/deinit functions,
|
||||
* and bus width/clock speed configuration functions. Multiple tasks
|
||||
* can call sdspi_host_do_transaction as long as other sdspi_host_*
|
||||
* functions are not called.
|
||||
*
|
||||
* @param slot SPI controller (HSPI_HOST or VSPI_HOST)
|
||||
* @param cmdinfo pointer to structure describing command and data to transfer
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_TIMEOUT if response or data transfer has timed out
|
||||
* - ESP_ERR_INVALID_CRC if response or data transfer CRC check has failed
|
||||
* - ESP_ERR_INVALID_RESPONSE if the card has sent an invalid response
|
||||
*/
|
||||
esp_err_t sdspi_host_do_transaction(int slot, sdmmc_command_t *cmdinfo);
|
||||
|
||||
/**
|
||||
* @brief Set card clock frequency
|
||||
*
|
||||
* Currently only integer fractions of 40MHz clock can be used.
|
||||
* For High Speed cards, 40MHz can be used.
|
||||
* For Default Speed cards, 20MHz can be used.
|
||||
*
|
||||
* @note This function is not thread safe
|
||||
*
|
||||
* @param slot SPI controller (HSPI_HOST or VSPI_HOST)
|
||||
* @param freq_khz card clock frequency, in kHz
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - other error codes may be returned in the future
|
||||
*/
|
||||
esp_err_t sdspi_host_set_card_clk(int slot, uint32_t freq_khz);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Release resources allocated using sdspi_host_init
|
||||
*
|
||||
* @note This function is not thread safe
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_INVALID_STATE if sdspi_host_init function has not been called
|
||||
*/
|
||||
esp_err_t sdspi_host_deinit();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -48,6 +48,8 @@ typedef enum {
|
||||
* You can use this structure to specify the GPIO pins of the bus. Normally, the driver will use the
|
||||
* GPIO matrix to route the signals. An exception is made when all signals either can be routed through
|
||||
* the IO_MUX or are -1. In that case, the IO_MUX is used, allowing for >40MHz speeds.
|
||||
*
|
||||
* @note Be advised that the slave driver does not use the quadwp/quadhd lines and fields in spi_bus_config_t refering to these lines will be ignored and can thus safely be left uninitialized.
|
||||
*/
|
||||
typedef struct {
|
||||
int mosi_io_num; ///< GPIO pin for Master Out Slave In (=spi_d) signal, or -1 if not used.
|
||||
|
@ -62,7 +62,7 @@ typedef struct {
|
||||
|
||||
#define SPI_TRANS_MODE_DIO (1<<0) ///< Transmit/receive data in 2-bit mode
|
||||
#define SPI_TRANS_MODE_QIO (1<<1) ///< Transmit/receive data in 4-bit mode
|
||||
#define SPI_TRANS_MODE_DIOQIO_ADDR (1<<2) ///< Also transmit address in mode selected by SPI_MODE_DIO/SPI_MODE_QIO
|
||||
#define SPI_TRANS_MODE_DIOQIO_ADDR (1<<4) ///< Also transmit address in mode selected by SPI_MODE_DIO/SPI_MODE_QIO
|
||||
#define SPI_TRANS_USE_RXDATA (1<<2) ///< Receive into rx_data member of spi_transaction_t instead into memory at rx_buffer.
|
||||
#define SPI_TRANS_USE_TXDATA (1<<3) ///< Transmit tx_data member of spi_transaction_t instead of data at tx_buffer. Do not set tx_buffer when using this.
|
||||
|
||||
|
@ -129,8 +129,8 @@ typedef enum {
|
||||
UART_FRAME_ERR, /*!< UART RX frame error event*/
|
||||
UART_PARITY_ERR, /*!< UART RX parity event*/
|
||||
UART_DATA_BREAK, /*!< UART TX data and break event*/
|
||||
UART_EVENT_MAX, /*!< UART event max index*/
|
||||
UART_PATTERN_DET, /*!< UART pattern detected */
|
||||
UART_EVENT_MAX, /*!< UART event max index*/
|
||||
} uart_event_type_t;
|
||||
|
||||
/**
|
||||
@ -474,6 +474,8 @@ esp_err_t uart_intr_config(uart_port_t uart_num, const uart_intr_config_t *intr_
|
||||
* @param rx_buffer_size UART RX ring buffer size, rx_buffer_size should be greater than UART_FIFO_LEN.
|
||||
* @param tx_buffer_size UART TX ring buffer size.
|
||||
* If set to zero, driver will not use TX buffer, TX function will block task until all data have been sent out..
|
||||
* @note tx_buffer_size should be greater than UART_FIFO_LEN.
|
||||
*
|
||||
* @param queue_size UART event queue size/depth.
|
||||
* @param uart_queue UART event queue handle (out param). On success, a new queue handle is written here to provide
|
||||
* access to UART events. If set to NULL, driver will not use an event queue.
|
||||
|
@ -1,123 +0,0 @@
|
||||
// Copyright 2017 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#ifndef ESP_APP_TRACE_H_
|
||||
#define ESP_APP_TRACE_H_
|
||||
|
||||
#include <stdarg.h>
|
||||
#include "esp_err.h"
|
||||
|
||||
// infinite waiting timeout
|
||||
#define ESP_APPTRACE_TMO_INFINITE ((uint32_t)-1)
|
||||
|
||||
// Trace memory block size
|
||||
#define ESP_APPTRACE_TRAX_BLOCK_SIZE 0x4000UL
|
||||
|
||||
/**
|
||||
* Application trace data destinations bits.
|
||||
*/
|
||||
typedef enum {
|
||||
ESP_APPTRACE_DEST_TRAX = 0x1,
|
||||
ESP_APPTRACE_DEST_UART0 = 0x2,
|
||||
//ESP_APPTRACE_DEST_UART1 = 0x4,
|
||||
} esp_apptrace_dest_t;
|
||||
|
||||
/**
|
||||
* @brief Initializes application tracing module.
|
||||
*
|
||||
* @note Should be called before any esp_apptrace_xxx call.
|
||||
*
|
||||
* @return ESP_OK on success, otherwise \see esp_err_t
|
||||
*/
|
||||
esp_err_t esp_apptrace_init();
|
||||
|
||||
/**
|
||||
* @brief Allocates buffer for trace data.
|
||||
* After data in buffer are ready to be sent off esp_apptrace_buffer_put must be called to indicate it.
|
||||
*
|
||||
* @param dest Indicates HW interface to send data.
|
||||
* @param size Size of data to write to trace buffer.
|
||||
* @param tmo Timeout for operation (in us). Use ESP_APPTRACE_TMO_INFINITE to wait indefinetly.
|
||||
*
|
||||
* @return non-NULL on success, otherwise NULL.
|
||||
*/
|
||||
uint8_t *esp_apptrace_buffer_get(esp_apptrace_dest_t dest, size_t size, uint32_t tmo);
|
||||
|
||||
/**
|
||||
* @brief Indicates that the data in buffer are ready to be sent off.
|
||||
* This function is a counterpart of must be preceeded by esp_apptrace_buffer_get.
|
||||
*
|
||||
* @param dest Indicates HW interface to send data. Should be identical to the same parameter in call to esp_apptrace_buffer_get.
|
||||
* @param ptr Address of trace buffer to release. Should be the value returned by call to esp_apptrace_buffer_get.
|
||||
* @param tmo Timeout for operation (in us). Use ESP_APPTRACE_TMO_INFINITE to wait indefinetly.
|
||||
*
|
||||
* @return ESP_OK on success, otherwise \see esp_err_t
|
||||
*/
|
||||
esp_err_t esp_apptrace_buffer_put(esp_apptrace_dest_t dest, uint8_t *ptr, uint32_t tmo);
|
||||
|
||||
/**
|
||||
* @brief Writes data to trace buffer.
|
||||
*
|
||||
* @param dest Indicates HW interface to send data.
|
||||
* @param data Address of data to write to trace buffer.
|
||||
* @param size Size of data to write to trace buffer.
|
||||
* @param tmo Timeout for operation (in us). Use ESP_APPTRACE_TMO_INFINITE to wait indefinetly.
|
||||
*
|
||||
* @return ESP_OK on success, otherwise \see esp_err_t
|
||||
*/
|
||||
esp_err_t esp_apptrace_write(esp_apptrace_dest_t dest, void *data, size_t size, uint32_t tmo);
|
||||
|
||||
/**
|
||||
* @brief vprintf-like function to sent log messages to host via specified HW interface.
|
||||
*
|
||||
* @param dest Indicates HW interface to send data.
|
||||
* @param fmt Address of format string.
|
||||
* @param ap List of arguments.
|
||||
*
|
||||
* @return Number of bytes written.
|
||||
*/
|
||||
int esp_apptrace_vprintf_to(esp_apptrace_dest_t dest, uint32_t user_tmo, const char *fmt, va_list ap);
|
||||
|
||||
/**
|
||||
* @brief vprintf-like function to sent log messages to host.
|
||||
*
|
||||
* @param fmt Address of format string.
|
||||
* @param ap List of arguments.
|
||||
*
|
||||
* @return Number of bytes written.
|
||||
*/
|
||||
int esp_apptrace_vprintf(const char *fmt, va_list ap);
|
||||
|
||||
/**
|
||||
* @brief Flushes remaining data in trace buffer to host.
|
||||
*
|
||||
* @param dest Indicates HW interface to flush data on.
|
||||
* @param tmo Timeout for operation (in us). Use ESP_APPTRACE_TMO_INFINITE to wait indefinetly.
|
||||
*
|
||||
* @return ESP_OK on success, otherwise \see esp_err_t
|
||||
*/
|
||||
esp_err_t esp_apptrace_flush(esp_apptrace_dest_t dest, uint32_t tmo);
|
||||
|
||||
/**
|
||||
* @brief Flushes remaining data in trace buffer to host without locking internal data.
|
||||
This is special version of esp_apptrace_flush which should be called from panic handler.
|
||||
*
|
||||
* @param dest Indicates HW interface to flush data on.
|
||||
* @param min_sz Threshold for flushing data. If current filling level is above this value, data will be flushed. TRAX destinations only.
|
||||
* @param tmo Timeout for operation (in us). Use ESP_APPTRACE_TMO_INFINITE to wait indefinetly.
|
||||
*
|
||||
* @return ESP_OK on success, otherwise \see esp_err_t
|
||||
*/
|
||||
esp_err_t esp_apptrace_flush_nolock(esp_apptrace_dest_t dest, uint32_t min_sz, uint32_t tmo);
|
||||
|
||||
#endif
|
@ -33,7 +33,7 @@ void esp_clk_init(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get the cached calibration value of RTC slow clock
|
||||
* @brief Get the calibration value of RTC slow clock
|
||||
*
|
||||
* The value is in the same format as returned by rtc_clk_cal (microseconds,
|
||||
* in Q13.19 fixed-point format).
|
||||
@ -42,3 +42,15 @@ void esp_clk_init(void);
|
||||
*/
|
||||
uint32_t esp_clk_slowclk_cal_get();
|
||||
|
||||
|
||||
/**
|
||||
* @brief Update the calibration value of RTC slow clock
|
||||
*
|
||||
* The value has to be in the same format as returned by rtc_clk_cal (microseconds,
|
||||
* in Q13.19 fixed-point format).
|
||||
* This value is used by timekeeping functions (such as gettimeofday) to
|
||||
* calculate current time based on RTC counter value.
|
||||
* @param value calibration value obtained using rtc_clk_cal
|
||||
*/
|
||||
void esp_clk_slowclk_cal_set(uint32_t value);
|
||||
|
||||
|
@ -15,8 +15,25 @@
|
||||
#ifndef _ESP_DPORT_ACCESS_H_
|
||||
#define _ESP_DPORT_ACCESS_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void esp_dport_access_stall_other_cpu_start(void);
|
||||
void esp_dport_access_stall_other_cpu_end(void);
|
||||
void esp_dport_access_int_init(void);
|
||||
void esp_dport_access_int_deinit(void);
|
||||
|
||||
#if defined(BOOTLOADER_BUILD) || defined(CONFIG_FREERTOS_UNICORE) || !defined(ESP_PLATFORM)
|
||||
#define DPORT_STALL_OTHER_CPU_START()
|
||||
#define DPORT_STALL_OTHER_CPU_END()
|
||||
#else
|
||||
#define DPORT_STALL_OTHER_CPU_START() esp_dport_access_stall_other_cpu_start()
|
||||
#define DPORT_STALL_OTHER_CPU_END() esp_dport_access_stall_other_cpu_end()
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _ESP_DPORT_ACCESS_H_ */
|
||||
|
@ -53,6 +53,11 @@ typedef enum {
|
||||
SYSTEM_EVENT_MAX
|
||||
} system_event_id_t;
|
||||
|
||||
typedef enum {
|
||||
WPS_FAIL_REASON_NORMAL = 0, /**< ESP32 WPS normal fail reason */
|
||||
WPS_FAIL_REASON_RECV_M2D, /**< ESP32 WPS receive M2D frame */
|
||||
WPS_FAIL_REASON_MAX
|
||||
}system_event_sta_wps_fail_reason_t;
|
||||
typedef struct {
|
||||
uint32_t status; /**< status of scanning APs */
|
||||
uint8_t number;
|
||||
@ -113,6 +118,7 @@ typedef union {
|
||||
system_event_sta_authmode_change_t auth_change; /**< the auth mode of AP ESP32 station connected to changed */
|
||||
system_event_sta_got_ip_t got_ip; /**< ESP32 station got IP */
|
||||
system_event_sta_wps_er_pin_t sta_er_pin; /**< ESP32 station WPS enrollee mode PIN code received */
|
||||
system_event_sta_wps_fail_reason_t sta_er_fail_reason;/**< ESP32 station WPS enrollee mode failed reason code received */
|
||||
system_event_ap_staconnected_t sta_connected; /**< a station connected to ESP32 soft-AP */
|
||||
system_event_ap_stadisconnected_t sta_disconnected; /**< a station disconnected to ESP32 soft-AP */
|
||||
system_event_ap_probe_req_rx_t ap_probereqrecved; /**< ESP32 soft-AP receive probe request packet */
|
||||
|
@ -17,6 +17,6 @@
|
||||
#include <xtensa/config/core.h>
|
||||
#include "freertos/xtensa_api.h"
|
||||
|
||||
void esp_gdbstub_panic_handler(XtExcFrame *frame);
|
||||
void esp_gdbstub_panic_handler(XtExcFrame *frame) __attribute__((noreturn));
|
||||
|
||||
#endif
|
@ -1,103 +0,0 @@
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#ifndef HEAP_ALLOC_CAPS_H
|
||||
#define HEAP_ALLOC_CAPS_H
|
||||
|
||||
/**
|
||||
* @brief Flags to indicate the capabilities of the various memory systems
|
||||
*/
|
||||
#define MALLOC_CAP_EXEC (1<<0) ///< Memory must be able to run executable code
|
||||
#define MALLOC_CAP_32BIT (1<<1) ///< Memory must allow for aligned 32-bit data accesses
|
||||
#define MALLOC_CAP_8BIT (1<<2) ///< Memory must allow for 8/16/...-bit data accesses
|
||||
#define MALLOC_CAP_DMA (1<<3) ///< Memory must be able to accessed by DMA
|
||||
#define MALLOC_CAP_PID2 (1<<4) ///< Memory must be mapped to PID2 memory space
|
||||
#define MALLOC_CAP_PID3 (1<<5) ///< Memory must be mapped to PID3 memory space
|
||||
#define MALLOC_CAP_PID4 (1<<6) ///< Memory must be mapped to PID4 memory space
|
||||
#define MALLOC_CAP_PID5 (1<<7) ///< Memory must be mapped to PID5 memory space
|
||||
#define MALLOC_CAP_PID6 (1<<8) ///< Memory must be mapped to PID6 memory space
|
||||
#define MALLOC_CAP_PID7 (1<<9) ///< Memory must be mapped to PID7 memory space
|
||||
#define MALLOC_CAP_SPISRAM (1<<10) ///< Memory must be in SPI SRAM
|
||||
#define MALLOC_CAP_INVALID (1<<31) ///< Memory can't be used / list end marker
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initialize the capability-aware heap allocator.
|
||||
*
|
||||
* For the ESP32, this is called once in the startup code.
|
||||
*/
|
||||
void heap_alloc_caps_init();
|
||||
|
||||
/**
|
||||
* @brief Enable the memory region where the startup stacks are located for allocation
|
||||
*
|
||||
* On startup, the pro/app CPUs have a certain memory region they use as stack, so we
|
||||
* cannot do allocations in the regions these stack frames are. When FreeRTOS is
|
||||
* completely started, they do not use that memory anymore and allocation there can
|
||||
* be re-enabled.
|
||||
*/
|
||||
void heap_alloc_enable_nonos_stack_tag();
|
||||
|
||||
/**
|
||||
* @brief Allocate a chunk of memory which has the given capabilities
|
||||
*
|
||||
* @param xWantedSize Size, in bytes, of the amount of memory to allocate
|
||||
* @param caps Bitwise OR of MALLOC_CAP_* flags indicating the type
|
||||
* of memory to be returned
|
||||
*
|
||||
* @return A pointer to the memory allocated on success, NULL on failure
|
||||
*/
|
||||
void *pvPortMallocCaps(size_t xWantedSize, uint32_t caps);
|
||||
|
||||
/**
|
||||
* @brief Get the total free size of all the regions that have the given capabilities
|
||||
*
|
||||
* This function takes all regions capable of having the given capabilities allocated in them
|
||||
* and adds up the free space they have.
|
||||
*
|
||||
* @param caps Bitwise OR of MALLOC_CAP_* flags indicating the type
|
||||
* of memory
|
||||
*
|
||||
* @return Amount of free bytes in the regions
|
||||
*/
|
||||
size_t xPortGetFreeHeapSizeCaps( uint32_t caps );
|
||||
|
||||
/**
|
||||
* @brief Get the total minimum free memory of all regions with the given capabilities
|
||||
*
|
||||
* This adds all the lowmarks of the regions capable of delivering the memory with the
|
||||
* given capabilities
|
||||
*
|
||||
* @param caps Bitwise OR of MALLOC_CAP_* flags indicating the type
|
||||
* of memory
|
||||
*
|
||||
* @return Amount of free bytes in the regions
|
||||
*/
|
||||
size_t xPortGetMinimumEverFreeHeapSizeCaps( uint32_t caps );
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Convenience function to check if a pointer is DMA-capable.
|
||||
*
|
||||
* @param ptr Pointer to check
|
||||
*
|
||||
* @return True if DMA-capable, false if not.
|
||||
*/
|
||||
static inline bool esp_ptr_dma_capable( const void *ptr )
|
||||
{
|
||||
return ( (int)ptr >= 0x3FFAE000 && (int)ptr < 0x40000000 );
|
||||
}
|
||||
|
||||
|
||||
#endif
|
@ -77,6 +77,9 @@ extern "C" {
|
||||
|
||||
/**@}*/
|
||||
|
||||
// This is used to provide SystemView with positive IRQ IDs, otherwise sheduler events are not shown properly
|
||||
#define ETS_INTERNAL_INTR_SOURCE_OFF (-ETS_INTERNAL_PROFILING_INTR_SOURCE)
|
||||
|
||||
typedef void (*intr_handler_t)(void *arg);
|
||||
|
||||
|
||||
@ -221,7 +224,6 @@ int esp_intr_get_cpu(intr_handle_t handle);
|
||||
*/
|
||||
int esp_intr_get_intno(intr_handle_t handle);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Disable the interrupt associated with the handle
|
||||
*
|
||||
|
@ -17,6 +17,10 @@
|
||||
|
||||
#include <esp_err.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef void (*esp_ipc_func_t)(void* arg);
|
||||
|
||||
/**
|
||||
@ -53,6 +57,10 @@ void esp_ipc_init();
|
||||
*
|
||||
* In single-core mode, returns ESP_ERR_INVALID_ARG for cpu_id 1.
|
||||
*
|
||||
* For complex functions, you may need to increase the stack size of the "IPC task"
|
||||
* which runs the function must be sufficient. See the "Inter-Processor Call (IPC)
|
||||
* task stack size" setting in menuconfig.
|
||||
*
|
||||
* @param cpu_id CPU where function should be executed (0 or 1)
|
||||
* @param func pointer to a function which should be executed
|
||||
* @param arg arbitrary argument to be passed into function
|
||||
@ -84,5 +92,8 @@ esp_err_t esp_ipc_call(uint32_t cpu_id, esp_ipc_func_t func, void* arg);
|
||||
esp_err_t esp_ipc_call_blocking(uint32_t cpu_id, esp_ipc_func_t func, void* arg);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ESP_IPC_H__ */
|
||||
|
@ -59,6 +59,17 @@ void system_restore(void) __attribute__ ((deprecated));
|
||||
*/
|
||||
void esp_restart(void) __attribute__ ((noreturn));
|
||||
|
||||
/**
|
||||
* @brief Internal function to restart PRO and APP CPUs.
|
||||
*
|
||||
* @note This function should not be called from FreeRTOS applications.
|
||||
* Use esp_restart instead.
|
||||
*
|
||||
* This is an internal function called by esp_restart. It is called directly
|
||||
* by the panic handler and brownout detector interrupt.
|
||||
*/
|
||||
void esp_restart_noos() __attribute__ ((noreturn));
|
||||
|
||||
/**
|
||||
* @brief Restart system.
|
||||
*
|
||||
@ -95,10 +106,25 @@ uint32_t esp_get_free_heap_size(void);
|
||||
*/
|
||||
uint32_t system_get_free_heap_size(void) __attribute__ ((deprecated));
|
||||
|
||||
/**
|
||||
* @brief Get the minimum heap that has ever been available
|
||||
*
|
||||
* @return Minimum free heap ever available
|
||||
*/
|
||||
uint32_t esp_get_minimum_free_heap_size( void );
|
||||
|
||||
/**
|
||||
* @brief Get one random 32-bit word from hardware RNG
|
||||
*
|
||||
* @return random value between 0 and UINT32_MAX
|
||||
* The hardware RNG is fully functional whenever an RF subsystem is running (ie Bluetooth or WiFi is enabled). For secure
|
||||
* random values, call this function after WiFi or Bluetooth are started.
|
||||
*
|
||||
* When the app is running without an RF subsystem enabled, it should be considered a PRNG. To help improve this
|
||||
* situation, the RNG is pre-seeded with entropy while the IDF bootloader is running. However no new entropy is
|
||||
* available during the window of time between when the bootloader exits and an RF subsystem starts. It may be possible
|
||||
* to discern a non-random pattern in a very large amount of output captured during this window of time.
|
||||
*
|
||||
* @return Random value between 0 and UINT32_MAX
|
||||
*/
|
||||
uint32_t esp_random(void);
|
||||
|
||||
|
@ -104,6 +104,8 @@ typedef struct {
|
||||
int ampdu_enable; /**< WiFi AMPDU feature enable flag */
|
||||
int nvs_enable; /**< WiFi NVS flash enable flag */
|
||||
int nano_enable; /**< Nano option for printf/scan family enable flag */
|
||||
int tx_ba_win; /**< WiFi Block Ack TX window size */
|
||||
int rx_ba_win; /**< WiFi Block Ack RX window size */
|
||||
int magic; /**< WiFi init magic number, it should be the last field */
|
||||
} wifi_init_config_t;
|
||||
|
||||
@ -149,6 +151,8 @@ typedef struct {
|
||||
.ampdu_enable = WIFI_AMPDU_ENABLED,\
|
||||
.nvs_enable = WIFI_NVS_ENABLED,\
|
||||
.nano_enable = WIFI_NANO_FORMAT_ENABLED,\
|
||||
.tx_ba_win = CONFIG_ESP32_WIFI_TX_BA_WIN,\
|
||||
.rx_ba_win = CONFIG_ESP32_WIFI_RX_BA_WIN,\
|
||||
.magic = WIFI_INIT_CONFIG_MAGIC\
|
||||
};
|
||||
#else
|
||||
@ -196,7 +200,7 @@ esp_err_t esp_wifi_deinit(void);
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_WIFI_ARG: invalid argument
|
||||
* - others: refer to error code in esp_err.h
|
||||
*/
|
||||
@ -209,7 +213,7 @@ esp_err_t esp_wifi_set_mode(wifi_mode_t mode);
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_WIFI_ARG: invalid argument
|
||||
*/
|
||||
esp_err_t esp_wifi_get_mode(wifi_mode_t *mode);
|
||||
@ -222,7 +226,7 @@ esp_err_t esp_wifi_get_mode(wifi_mode_t *mode);
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_WIFI_ARG: invalid argument
|
||||
* - ESP_ERR_WIFI_NO_MEM: out of memory
|
||||
* - ESP_ERR_WIFI_CONN: WiFi internal error, station or soft-AP control block wrong
|
||||
@ -238,7 +242,7 @@ esp_err_t esp_wifi_start(void);
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
*/
|
||||
esp_err_t esp_wifi_stop(void);
|
||||
|
||||
@ -253,7 +257,7 @@ esp_err_t esp_wifi_stop(void);
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
*/
|
||||
esp_err_t esp_wifi_restore(void);
|
||||
|
||||
@ -265,7 +269,7 @@ esp_err_t esp_wifi_restore(void);
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_WIFI_NOT_START: WiFi is not started by esp_wifi_start
|
||||
* - ESP_ERR_WIFI_CONN: WiFi internal error, station or soft-AP control block wrong
|
||||
* - ESP_ERR_WIFI_SSID: SSID of AP which station connects is invalid
|
||||
@ -277,7 +281,7 @@ esp_err_t esp_wifi_connect(void);
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi was not initialized by eps_wifi_init
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi was not initialized by esp_wifi_init
|
||||
* - ESP_ERR_WIFI_NOT_STARTED: WiFi was not started by esp_wifi_start
|
||||
* - ESP_ERR_WIFI_FAIL: other WiFi internal errors
|
||||
*/
|
||||
@ -300,7 +304,7 @@ esp_err_t esp_wifi_clear_fast_connect(void);
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_WIFI_NOT_STARTED: WiFi was not started by esp_wifi_start
|
||||
* - ESP_ERR_WIFI_ARG: invalid argument
|
||||
* - ESP_ERR_WIFI_MODE: WiFi mode is wrong
|
||||
@ -311,7 +315,7 @@ esp_err_t esp_wifi_deauth_sta(uint16_t aid);
|
||||
* @brief Scan all available APs.
|
||||
*
|
||||
* @attention If this API is called, the found APs are stored in WiFi driver dynamic allocated memory and the
|
||||
* will be freed in esp_wifi_get_ap_list, so generally, call esp_wifi_get_ap_list to cause
|
||||
* will be freed in esp_wifi_scan_get_ap_records, so generally, call esp_wifi_scan_get_ap_records to cause
|
||||
* the memory to be freed once the scan is done
|
||||
* @attention The values of maximum active scan time and passive scan time per channel are limited to 1500 milliseconds.
|
||||
* Values above 1500ms may cause station to disconnect from AP and are not recommended.
|
||||
@ -322,7 +326,7 @@ esp_err_t esp_wifi_deauth_sta(uint16_t aid);
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_WIFI_NOT_STARTED: WiFi was not started by esp_wifi_start
|
||||
* - ESP_ERR_WIFI_TIMEOUT: blocking scan is timeout
|
||||
* - others: refer to error code in esp_err.h
|
||||
@ -334,7 +338,7 @@ esp_err_t esp_wifi_scan_start(wifi_scan_config_t *config, bool block);
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_WIFI_NOT_STARTED: WiFi is not started by esp_wifi_start
|
||||
*/
|
||||
esp_err_t esp_wifi_scan_stop(void);
|
||||
@ -348,7 +352,7 @@ esp_err_t esp_wifi_scan_stop(void);
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_WIFI_NOT_STARTED: WiFi is not started by esp_wifi_start
|
||||
* - ESP_ERR_WIFI_ARG: invalid argument
|
||||
*/
|
||||
@ -363,7 +367,7 @@ esp_err_t esp_wifi_scan_get_ap_num(uint16_t *number);
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_WIFI_NOT_STARTED: WiFi is not started by esp_wifi_start
|
||||
* - ESP_ERR_WIFI_ARG: invalid argument
|
||||
* - ESP_ERR_WIFI_NO_MEM: out of memory
|
||||
@ -415,7 +419,7 @@ esp_err_t esp_wifi_get_ps(wifi_ps_type_t *type);
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_WIFI_IF: invalid interface
|
||||
* - others: refer to error codes in esp_err.h
|
||||
*/
|
||||
@ -429,7 +433,7 @@ esp_err_t esp_wifi_set_protocol(wifi_interface_t ifx, uint8_t protocol_bitmap);
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_WIFI_IF: invalid interface
|
||||
* - ESP_ERR_WIFI_ARG: invalid argument
|
||||
* - others: refer to error codes in esp_err.h
|
||||
@ -447,7 +451,7 @@ esp_err_t esp_wifi_get_protocol(wifi_interface_t ifx, uint8_t *protocol_bitmap);
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_WIFI_IF: invalid interface
|
||||
* - ESP_ERR_WIFI_ARG: invalid argument
|
||||
* - others: refer to error codes in esp_err.h
|
||||
@ -464,7 +468,7 @@ esp_err_t esp_wifi_set_bandwidth(wifi_interface_t ifx, wifi_bandwidth_t bw);
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_WIFI_IF: invalid interface
|
||||
* - ESP_ERR_WIFI_ARG: invalid argument
|
||||
*/
|
||||
@ -481,7 +485,7 @@ esp_err_t esp_wifi_get_bandwidth(wifi_interface_t ifx, wifi_bandwidth_t *bw);
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_WIFI_IF: invalid interface
|
||||
* - ESP_ERR_WIFI_ARG: invalid argument
|
||||
*/
|
||||
@ -497,7 +501,7 @@ esp_err_t esp_wifi_set_channel(uint8_t primary, wifi_second_chan_t second);
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_WIFI_ARG: invalid argument
|
||||
*/
|
||||
esp_err_t esp_wifi_get_channel(uint8_t *primary, wifi_second_chan_t *second);
|
||||
@ -510,7 +514,7 @@ esp_err_t esp_wifi_get_channel(uint8_t *primary, wifi_second_chan_t *second);
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_WIFI_ARG: invalid argument
|
||||
* - others: refer to error code in esp_err.h
|
||||
*/
|
||||
@ -523,7 +527,7 @@ esp_err_t esp_wifi_set_country(wifi_country_t country);
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_WIFI_ARG: invalid argument
|
||||
*/
|
||||
esp_err_t esp_wifi_get_country(wifi_country_t *country);
|
||||
@ -541,7 +545,7 @@ esp_err_t esp_wifi_get_country(wifi_country_t *country);
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_WIFI_ARG: invalid argument
|
||||
* - ESP_ERR_WIFI_IF: invalid interface
|
||||
* - ESP_ERR_WIFI_MAC: invalid mac address
|
||||
@ -558,7 +562,7 @@ esp_err_t esp_wifi_set_mac(wifi_interface_t ifx, uint8_t mac[6]);
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_WIFI_ARG: invalid argument
|
||||
* - ESP_ERR_WIFI_IF: invalid interface
|
||||
*/
|
||||
@ -583,7 +587,7 @@ typedef void (* wifi_promiscuous_cb_t)(void *buf, wifi_promiscuous_pkt_type_t ty
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
*/
|
||||
esp_err_t esp_wifi_set_promiscuous_rx_cb(wifi_promiscuous_cb_t cb);
|
||||
|
||||
@ -594,7 +598,7 @@ esp_err_t esp_wifi_set_promiscuous_rx_cb(wifi_promiscuous_cb_t cb);
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
*/
|
||||
esp_err_t esp_wifi_set_promiscuous(bool en);
|
||||
|
||||
@ -605,11 +609,36 @@ esp_err_t esp_wifi_set_promiscuous(bool en);
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_WIFI_ARG: invalid argument
|
||||
*/
|
||||
esp_err_t esp_wifi_get_promiscuous(bool *en);
|
||||
|
||||
/**
|
||||
* @brief Enable the promiscuous filter.
|
||||
*
|
||||
* @attention 1. The default filter is to filter all packets except WIFI_PKT_MISC
|
||||
*
|
||||
* @param filter the packet type filtered by promisucous
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
*/
|
||||
esp_err_t esp_wifi_set_promiscuous_filter(const wifi_promiscuous_filter_t *filter);
|
||||
|
||||
/**
|
||||
* @brief Get the promiscuous filter.
|
||||
*
|
||||
* @param[out] filter store the current status of promiscuous filter
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_WIFI_ARG: invalid argument
|
||||
*/
|
||||
esp_err_t esp_wifi_get_promiscuous_filter(wifi_promiscuous_filter_t *filter);
|
||||
|
||||
/**
|
||||
* @brief Set the configuration of the ESP32 STA or AP
|
||||
*
|
||||
@ -623,7 +652,7 @@ esp_err_t esp_wifi_get_promiscuous(bool *en);
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_WIFI_ARG: invalid argument
|
||||
* - ESP_ERR_WIFI_IF: invalid interface
|
||||
* - ESP_ERR_WIFI_MODE: invalid mode
|
||||
@ -641,7 +670,7 @@ esp_err_t esp_wifi_set_config(wifi_interface_t ifx, wifi_config_t *conf);
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_WIFI_ARG: invalid argument
|
||||
* - ESP_ERR_WIFI_IF: invalid interface
|
||||
*/
|
||||
@ -656,7 +685,7 @@ esp_err_t esp_wifi_get_config(wifi_interface_t ifx, wifi_config_t *conf);
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_WIFI_ARG: invalid argument
|
||||
* - ESP_ERR_WIFI_MODE: WiFi mode is wrong
|
||||
* - ESP_ERR_WIFI_CONN: WiFi internal error, the station/soft-AP control block is invalid
|
||||
@ -673,7 +702,7 @@ esp_err_t esp_wifi_ap_get_sta_list(wifi_sta_list_t *sta);
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_WIFI_ARG: invalid argument
|
||||
*/
|
||||
esp_err_t esp_wifi_set_storage(wifi_storage_t storage);
|
||||
@ -686,7 +715,7 @@ esp_err_t esp_wifi_set_storage(wifi_storage_t storage);
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_WIFI_MODE: WiFi internal error, the station/soft-AP control block is invalid
|
||||
* - others: refer to error code in esp_err.h
|
||||
*/
|
||||
@ -699,49 +728,115 @@ esp_err_t esp_wifi_set_auto_connect(bool en);
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_WIFI_ARG: invalid argument
|
||||
*/
|
||||
esp_err_t esp_wifi_get_auto_connect(bool *en);
|
||||
|
||||
/**
|
||||
* @brief Set vendor specific element
|
||||
* @brief Set 802.11 Vendor-Specific Information Element
|
||||
*
|
||||
* @param enable enable or not
|
||||
* @param type information element type
|
||||
* @param idx information element index
|
||||
* @param vnd_ie pointer to a vendor specific element
|
||||
* @param enable If true, specified IE is enabled. If false, specified IE is removed.
|
||||
* @param type Information Element type. Determines the frame type to associate with the IE.
|
||||
* @param idx Index to set or clear. Each IE type can be associated with up to two elements (indices 0 & 1).
|
||||
* @param vnd_ie Pointer to vendor specific element data. First 6 bytes should be a header with fields matching vendor_ie_data_t.
|
||||
* If enable is false, this argument is ignored and can be NULL. Data does not need to remain valid after the function returns.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
|
||||
* - ESP_ERR_WIFI_ARG: invalid argument
|
||||
* - ESP_ERR_WIFI_NO_MEM: out of memory
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init()
|
||||
* - ESP_ERR_WIFI_ARG: Invalid argument, including if first byte of vnd_ie is not WIFI_VENDOR_IE_ELEMENT_ID (0xDD)
|
||||
* or second byte is an invalid length.
|
||||
* - ESP_ERR_WIFI_NO_MEM: Out of memory
|
||||
*/
|
||||
esp_err_t esp_wifi_set_vendor_ie(bool enable, wifi_vendor_ie_type_t type, wifi_vendor_ie_id_t idx, uint8_t *vnd_ie);
|
||||
esp_err_t esp_wifi_set_vendor_ie(bool enable, wifi_vendor_ie_type_t type, wifi_vendor_ie_id_t idx, const void *vnd_ie);
|
||||
|
||||
/**
|
||||
* @brief Define function pointer for vendor specific element callback
|
||||
* @param ctx reserved
|
||||
* @param type information element type
|
||||
* @param sa source address
|
||||
* @param vnd_ie pointer to a vendor specific element
|
||||
* @param rssi received signal strength indication
|
||||
* @brief Function signature for received Vendor-Specific Information Element callback.
|
||||
* @param ctx Context argument, as passed to esp_wifi_set_vendor_ie_cb() when registering callback.
|
||||
* @param type Information element type, based on frame type received.
|
||||
* @param sa Source 802.11 address.
|
||||
* @param vnd_ie Pointer to the vendor specific element data received.
|
||||
* @param rssi Received signal strength indication.
|
||||
*/
|
||||
typedef void (*esp_vendor_ie_cb_t) (void *ctx, wifi_vendor_ie_type_t type, const uint8_t sa[6], const uint8_t *vnd_ie, int rssi);
|
||||
typedef void (*esp_vendor_ie_cb_t) (void *ctx, wifi_vendor_ie_type_t type, const uint8_t sa[6], const vendor_ie_data_t *vnd_ie, int rssi);
|
||||
|
||||
/**
|
||||
* @brief Set vendor specific element callback
|
||||
* @brief Register Vendor-Specific Information Element monitoring callback.
|
||||
*
|
||||
* @param cb callback function
|
||||
* @param ctx reserved
|
||||
* @param cb Callback function
|
||||
* @param ctx Context argument, passed to callback function.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
*/
|
||||
esp_err_t esp_wifi_set_vendor_ie_cb(esp_vendor_ie_cb_t cb, void *ctx);
|
||||
|
||||
/**
|
||||
* @brief Set maximum WiFi transmiting power
|
||||
*
|
||||
* @attention WiFi transmiting power is divided to six levels in phy init data.
|
||||
* Level0 represents highest transmiting power and level5 represents lowest
|
||||
* transmiting power. Packets of different rates are transmitted in
|
||||
* different powers according to the configuration in phy init data.
|
||||
* This API only sets maximum WiFi transmiting power. If this API is called,
|
||||
* the transmiting power of every packet will be less than or equal to the
|
||||
* value set by this API. If this API is not called, the value of maximum
|
||||
* transmitting power set in phy_init_data.bin or menuconfig (depend on
|
||||
* whether to use phy init data in partition or not) will be used. Default
|
||||
* value is level0. Values passed in power are mapped to transmit power
|
||||
* levels as follows:
|
||||
* - [78, 127]: level0
|
||||
* - [76, 77]: level1
|
||||
* - [74, 75]: level2
|
||||
* - [68, 73]: level3
|
||||
* - [60, 67]: level4
|
||||
* - [52, 59]: level5
|
||||
* - [44, 51]: level5 - 2dBm
|
||||
* - [34, 43]: level5 - 4.5dBm
|
||||
* - [28, 33]: level5 - 6dBm
|
||||
* - [20, 27]: level5 - 8dBm
|
||||
* - [8, 19]: level5 - 11dBm
|
||||
* - [-128, 7]: level5 - 14dBm
|
||||
*
|
||||
* @param power Maximum WiFi transmiting power.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_WIFI_NOT_START: WiFi is not started by esp_wifi_start
|
||||
*/
|
||||
esp_err_t esp_wifi_set_max_tx_power(int8_t power);
|
||||
|
||||
/**
|
||||
* @brief Get maximum WiFi transmiting power
|
||||
*
|
||||
* @attention This API gets maximum WiFi transmiting power. Values got
|
||||
* from power are mapped to transmit power levels as follows:
|
||||
* - 78: 19.5dBm
|
||||
* - 76: 19dBm
|
||||
* - 74: 18.5dBm
|
||||
* - 68: 17dBm
|
||||
* - 60: 15dBm
|
||||
* - 52: 13dBm
|
||||
* - 44: 11dBm
|
||||
* - 34: 8.5dBm
|
||||
* - 28: 7dBm
|
||||
* - 20: 5dBm
|
||||
* - 8: 2dBm
|
||||
* - -4: -1dBm
|
||||
*
|
||||
* @param power Maximum WiFi transmiting power.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_WIFI_NOT_START: WiFi is not started by esp_wifi_start
|
||||
* - ESP_ERR_WIFI_ARG: invalid argument
|
||||
*/
|
||||
esp_err_t esp_wifi_get_max_tx_power(int8_t *power);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -188,8 +188,9 @@ typedef enum {
|
||||
} wifi_storage_t;
|
||||
|
||||
/**
|
||||
* @brief Vendor IE type
|
||||
* @brief Vendor Information Element type
|
||||
*
|
||||
* Determines the frame type that the IE will be associated with.
|
||||
*/
|
||||
typedef enum {
|
||||
WIFI_VND_IE_TYPE_BEACON,
|
||||
@ -200,14 +201,30 @@ typedef enum {
|
||||
} wifi_vendor_ie_type_t;
|
||||
|
||||
/**
|
||||
* @brief Vendor IE index
|
||||
* @brief Vendor Information Element index
|
||||
*
|
||||
* Each IE type can have up to two associated vendor ID elements.
|
||||
*/
|
||||
typedef enum {
|
||||
WIFI_VND_IE_ID_0,
|
||||
WIFI_VND_IE_ID_1,
|
||||
} wifi_vendor_ie_id_t;
|
||||
|
||||
#define WIFI_VENDOR_IE_ELEMENT_ID 0xDD
|
||||
|
||||
/**
|
||||
* @brief Vendor Information Element header
|
||||
*
|
||||
* The first bytes of the Information Element will match this header. Payload follows.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t element_id; /**< Should be set to WIFI_VENDOR_IE_ELEMENT_ID (0xDD) */
|
||||
uint8_t length; /**< Length of all bytes in the element data following this field. Minimum 4. */
|
||||
uint8_t vendor_oui[3]; /**< Vendor identifier (OUI). */
|
||||
uint8_t vendor_oui_type; /**< Vendor-specific OUI type. */
|
||||
uint8_t payload[0]; /**< Payload. Length is equal to value in 'length' field, minus 4. */
|
||||
} vendor_ie_data_t;
|
||||
|
||||
typedef struct {
|
||||
signed rssi:8; /**< signal intensity of packet */
|
||||
unsigned rate:5; /**< data rate */
|
||||
@ -246,12 +263,23 @@ typedef struct {
|
||||
*
|
||||
*/
|
||||
typedef enum {
|
||||
WIFI_PKT_CTRL, /**< control type, receive packet buf is wifi_pkt_rx_ctrl_t */
|
||||
WIFI_PKT_MGMT, /**< management type, receive packet buf is wifi_promiscuous_pkt_t */
|
||||
WIFI_PKT_DATA, /**< data type, receive packet buf is wifi_promiscuous_pkt_t */
|
||||
WIFI_PKT_MISC, /**< other type, receive packet buf is wifi_promiscuous_pkt_t */
|
||||
WIFI_PKT_MISC, /**< other type, such as MIMO etc, receive packet buf is wifi_promiscuous_pkt_t but the payload is NULL!!! */
|
||||
} wifi_promiscuous_pkt_type_t;
|
||||
|
||||
|
||||
#define WIFI_PROMIS_FILTER_MASK_ALL (0xFFFFFFFF) /**< filter all packets */
|
||||
#define WIFI_PROMIS_FILTER_MASK_MGMT (1) /**< filter the packets with type of WIFI_PKT_MGMT */
|
||||
#define WIFI_PROMIS_FILTER_MASK_DATA (1<<1) /**< filter the packets with type of WIFI_PKT_DATA */
|
||||
#define WIFI_PROMIS_FILTER_MASK_MISC (1<<2) /**< filter the packets with type of WIFI_PKT_MISC */
|
||||
#define WIFI_PROMIS_FILTER_MASK_DATA_MPDU (1<<3) /**< filter the MPDU which is a kind of WIFI_PKT_DATA */
|
||||
#define WIFI_PROMIS_FILTER_MASK_DATA_AMPDU (1<<4) /**< filter the AMPDU which is a kind of WIFI_PKT_DATA */
|
||||
|
||||
typedef struct {
|
||||
uint32_t filter_mask;
|
||||
} wifi_promiscuous_filter_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -1,3 +0,0 @@
|
||||
#pragma once
|
||||
#warning heap_alloc_caps.h has been renamed to esp_heap_alloc_caps.h. The old header file is deprecated and will be removed in v3.0.
|
||||
#include "esp_heap_alloc_caps.h"
|
@ -49,7 +49,7 @@ typedef enum {
|
||||
GPIO_PIN_INTR_DISABLE = 0,
|
||||
GPIO_PIN_INTR_POSEDGE = 1,
|
||||
GPIO_PIN_INTR_NEGEDGE = 2,
|
||||
GPIO_PIN_INTR_ANYEGDE = 3,
|
||||
GPIO_PIN_INTR_ANYEDGE = 3,
|
||||
GPIO_PIN_INTR_LOLEVEL = 4,
|
||||
GPIO_PIN_INTR_HILEVEL = 5
|
||||
} GPIO_INT_TYPE;
|
||||
|
@ -50,9 +50,9 @@ extern "C" {
|
||||
* 0x3ff80000(0x400c0000) Fast 8192 deep sleep entry code
|
||||
*
|
||||
*************************************************************************************
|
||||
* Rtc store registers usage
|
||||
* RTC_CNTL_STORE0_REG
|
||||
* RTC_CNTL_STORE1_REG
|
||||
* RTC store registers usage
|
||||
* RTC_CNTL_STORE0_REG Reserved
|
||||
* RTC_CNTL_STORE1_REG RTC_SLOW_CLK calibration value
|
||||
* RTC_CNTL_STORE2_REG Boot time, low word
|
||||
* RTC_CNTL_STORE3_REG Boot time, high word
|
||||
* RTC_CNTL_STORE4_REG External XTAL frequency
|
||||
@ -62,6 +62,7 @@ extern "C" {
|
||||
*************************************************************************************
|
||||
*/
|
||||
|
||||
#define RTC_SLOW_CLK_CAL_REG RTC_CNTL_STORE1_REG
|
||||
#define RTC_BOOT_TIME_LOW_REG RTC_CNTL_STORE2_REG
|
||||
#define RTC_BOOT_TIME_HIGH_REG RTC_CNTL_STORE3_REG
|
||||
#define RTC_XTAL_FREQ_REG RTC_CNTL_STORE4_REG
|
||||
|
@ -20,13 +20,13 @@ extern "C" {
|
||||
|
||||
#include "esp_eth.h"
|
||||
|
||||
/* Common PHY-management functions.
|
||||
/** Common PHY-management functions.
|
||||
|
||||
These are not enough to drive any particular Ethernet PHY, but they provide a common configuration structure and
|
||||
management functions.
|
||||
*/
|
||||
|
||||
/* Configure fixed pins for RMII data interface.
|
||||
/** Configure fixed pins for RMII data interface.
|
||||
|
||||
This configures GPIOs 0, 19, 22, 25, 26, 27 for use with RMII
|
||||
data interface. These pins cannot be changed, and must be wired to
|
||||
@ -38,7 +38,7 @@ extern "C" {
|
||||
*/
|
||||
void phy_rmii_configure_data_interface_pins(void);
|
||||
|
||||
/* Configure variable pins for SMI (MDIO) ethernet functions.
|
||||
/** Configure variable pins for SMI (MDIO) ethernet functions.
|
||||
|
||||
Calling this function along with mii_configure_default_pins() will
|
||||
fully configure the GPIOs for the ethernet PHY.
|
||||
@ -46,7 +46,7 @@ void phy_rmii_configure_data_interface_pins(void);
|
||||
void phy_rmii_smi_configure_pins(uint8_t mdc_gpio, uint8_t mdio_gpio);
|
||||
|
||||
|
||||
/* Enable flow control in standard PHY MII register.
|
||||
/** Enable flow control in standard PHY MII register.
|
||||
*/
|
||||
void phy_mii_enable_flow_ctrl(void);
|
||||
|
||||
|
@ -21,26 +21,26 @@ extern "C" {
|
||||
#include "phy.h"
|
||||
|
||||
|
||||
/* @brief Dump all LAN8720 PHY SMI configuration registers
|
||||
/** @brief Dump all LAN8720 PHY SMI configuration registers
|
||||
*
|
||||
* @note These registers are dumped at 'debug' level, so output
|
||||
* may not be visible depending on default log levels.
|
||||
*/
|
||||
void phy_lan8720_dump_registers();
|
||||
|
||||
/* @brief Default LAN8720 phy_check_init function.
|
||||
/** @brief Default LAN8720 phy_check_init function.
|
||||
*/
|
||||
void phy_lan8720_check_phy_init(void);
|
||||
|
||||
/* @brief Default LAN8720 phy_get_speed_mode function.
|
||||
/** @brief Default LAN8720 phy_get_speed_mode function.
|
||||
*/
|
||||
eth_speed_mode_t phy_lan8720_get_speed_mode(void);
|
||||
|
||||
/* @brief Default LAN8720 phy_get_duplex_mode function.
|
||||
/** @brief Default LAN8720 phy_get_duplex_mode function.
|
||||
*/
|
||||
eth_duplex_mode_t phy_lan8720_get_duplex_mode(void);
|
||||
|
||||
/* @brief Default LAN8720 phy_power_enable function.
|
||||
/** @brief Default LAN8720 phy_power_enable function.
|
||||
*
|
||||
* @note This function may need to be replaced with a custom function
|
||||
* if the PHY has a GPIO to enable power or start a clock.
|
||||
@ -49,11 +49,11 @@ eth_duplex_mode_t phy_lan8720_get_duplex_mode(void);
|
||||
*/
|
||||
void phy_lan8720_power_enable(bool);
|
||||
|
||||
/* @brief Default LAN8720 phy_init function.
|
||||
/** @brief Default LAN8720 phy_init function.
|
||||
*/
|
||||
void phy_lan8720_init(void);
|
||||
|
||||
/* @brief Default LAN8720 PHY configuration
|
||||
/** @brief Default LAN8720 PHY configuration
|
||||
*
|
||||
* This configuration is not suitable for use as-is, it will need
|
||||
* to be modified for your particular PHY hardware setup.
|
||||
|
@ -20,26 +20,26 @@ extern "C" {
|
||||
|
||||
#include "phy.h"
|
||||
|
||||
/* @brief Dump all TLK110 PHY SMI configuration registers
|
||||
/** @brief Dump all TLK110 PHY SMI configuration registers
|
||||
*
|
||||
* @note These registers are dumped at 'debug' level, so output
|
||||
* may not be visible depending on default log levels.
|
||||
*/
|
||||
void phy_tlk110_dump_registers();
|
||||
|
||||
/* @brief Default TLK110 phy_check_init function.
|
||||
/** @brief Default TLK110 phy_check_init function.
|
||||
*/
|
||||
void phy_tlk110_check_phy_init(void);
|
||||
|
||||
/* @brief Default TLK110 phy_get_speed_mode function.
|
||||
/** @brief Default TLK110 phy_get_speed_mode function.
|
||||
*/
|
||||
eth_speed_mode_t phy_tlk110_get_speed_mode(void);
|
||||
|
||||
/* @brief Default TLK110 phy_get_duplex_mode function.
|
||||
/** @brief Default TLK110 phy_get_duplex_mode function.
|
||||
*/
|
||||
eth_duplex_mode_t phy_tlk110_get_duplex_mode(void);
|
||||
|
||||
/* @brief Default TLK110 phy_power_enable function.
|
||||
/** @brief Default TLK110 phy_power_enable function.
|
||||
*
|
||||
* @note This function may need to be replaced with a custom function
|
||||
* if the PHY has a GPIO to enable power or start a clock.
|
||||
@ -48,11 +48,11 @@ eth_duplex_mode_t phy_tlk110_get_duplex_mode(void);
|
||||
*/
|
||||
void phy_tlk110_power_enable(bool);
|
||||
|
||||
/* @brief Default TLK110 phy_init function.
|
||||
/** @brief Default TLK110 phy_init function.
|
||||
*/
|
||||
void phy_tlk110_init(void);
|
||||
|
||||
/* @brief Default TLK110 PHY configuration
|
||||
/** @brief Default TLK110 PHY configuration
|
||||
*
|
||||
* This configuration is not suitable for use as-is, it will need
|
||||
* to be modified for your particular PHY hardware setup.
|
||||
|
@ -18,9 +18,14 @@
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/sdmmc_types.h"
|
||||
#include "driver/sdmmc_host.h"
|
||||
#include "driver/sdspi_host.h"
|
||||
#include "ff.h"
|
||||
#include "wear_levelling.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Register FATFS with VFS component
|
||||
*
|
||||
@ -94,9 +99,9 @@ typedef esp_vfs_fat_mount_config_t esp_vfs_fat_sdmmc_mount_config_t;
|
||||
* @brief Convenience function to get FAT filesystem on SD card registered in VFS
|
||||
*
|
||||
* This is an all-in-one function which does the following:
|
||||
* - initializes SD/MMC peripheral with configuration in host_config
|
||||
* - initializes SD/MMC card with configuration in slot_config
|
||||
* - mounts FAT partition on SD/MMC card using FATFS library, with configuration in mount_config
|
||||
* - initializes SDMMC driver or SPI driver with configuration in host_config
|
||||
* - initializes SD card with configuration in slot_config
|
||||
* - mounts FAT partition on SD card using FATFS library, with configuration in mount_config
|
||||
* - registers FATFS library with VFS, with prefix given by base_prefix variable
|
||||
*
|
||||
* This function is intended to make example code more compact.
|
||||
@ -105,8 +110,16 @@ typedef esp_vfs_fat_mount_config_t esp_vfs_fat_sdmmc_mount_config_t;
|
||||
* with proper error checking and handling of exceptional conditions.
|
||||
*
|
||||
* @param base_path path where partition should be registered (e.g. "/sdcard")
|
||||
* @param host_config pointer to structure describing SDMMC host
|
||||
* @param slot_config pointer to structure with extra SDMMC slot configuration
|
||||
* @param host_config Pointer to structure describing SDMMC host. When using
|
||||
* SDMMC peripheral, this structure can be initialized using
|
||||
* SDMMC_HOST_DEFAULT() macro. When using SPI peripheral,
|
||||
* this structure can be initialized using SDSPI_HOST_DEFAULT()
|
||||
* macro.
|
||||
* @param slot_config Pointer to structure with slot configuration.
|
||||
* For SDMMC peripheral, pass a pointer to sdmmc_slot_config_t
|
||||
* structure initialized using SDMMC_SLOT_CONFIG_DEFAULT.
|
||||
* For SPI peripheral, pass a pointer to sdspi_slot_config_t
|
||||
* structure initialized using SDSPI_SLOT_CONFIG_DEFAULT.
|
||||
* @param mount_config pointer to structure with extra parameters for mounting FATFS
|
||||
* @param[out] out_card if not NULL, pointer to the card information structure will be returned via this argument
|
||||
* @return
|
||||
@ -114,11 +127,11 @@ typedef esp_vfs_fat_mount_config_t esp_vfs_fat_sdmmc_mount_config_t;
|
||||
* - ESP_ERR_INVALID_STATE if esp_vfs_fat_sdmmc_mount was already called
|
||||
* - ESP_ERR_NO_MEM if memory can not be allocated
|
||||
* - ESP_FAIL if partition can not be mounted
|
||||
* - other error codes from SDMMC host, SDMMC protocol, or FATFS drivers
|
||||
* - other error codes from SDMMC or SPI drivers, SDMMC protocol, or FATFS drivers
|
||||
*/
|
||||
esp_err_t esp_vfs_fat_sdmmc_mount(const char* base_path,
|
||||
const sdmmc_host_t* host_config,
|
||||
const sdmmc_slot_config_t* slot_config,
|
||||
const void* slot_config,
|
||||
const esp_vfs_fat_mount_config_t* mount_config,
|
||||
sdmmc_card_t** out_card);
|
||||
|
||||
@ -173,3 +186,7 @@ esp_err_t esp_vfs_fat_spiflash_mount(const char* base_path,
|
||||
* - ESP_ERR_INVALID_STATE if esp_vfs_fat_spiflash_mount hasn't been called
|
||||
*/
|
||||
esp_err_t esp_vfs_fat_spiflash_unmount(const char* base_path, wl_handle_t wl_handle);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -204,6 +204,10 @@ extern "C" {
|
||||
#define INCLUDE_uxTaskGetStackHighWaterMark 0
|
||||
#endif
|
||||
|
||||
#ifndef INCLUDE_pxTaskGetStackStart
|
||||
#define INCLUDE_pxTaskGetStackStart 0
|
||||
#endif
|
||||
|
||||
#ifndef INCLUDE_eTaskGetState
|
||||
#define INCLUDE_eTaskGetState 0
|
||||
#endif
|
||||
@ -406,6 +410,22 @@ extern "C" {
|
||||
#define traceMOVED_TASK_TO_READY_STATE( pxTCB )
|
||||
#endif
|
||||
|
||||
#ifndef traceREADDED_TASK_TO_READY_STATE
|
||||
#define traceREADDED_TASK_TO_READY_STATE( pxTCB ) traceMOVED_TASK_TO_READY_STATE( pxTCB )
|
||||
#endif
|
||||
|
||||
#ifndef traceMOVED_TASK_TO_DELAYED_LIST
|
||||
#define traceMOVED_TASK_TO_DELAYED_LIST()
|
||||
#endif
|
||||
|
||||
#ifndef traceMOVED_TASK_TO_OVERFLOW_DELAYED_LIST
|
||||
#define traceMOVED_TASK_TO_OVERFLOW_DELAYED_LIST()
|
||||
#endif
|
||||
|
||||
#ifndef traceMOVED_TASK_TO_SUSPENDED_LIST
|
||||
#define traceMOVED_TASK_TO_SUSPENDED_LIST( pxTCB )
|
||||
#endif
|
||||
|
||||
#ifndef traceQUEUE_CREATE
|
||||
#define traceQUEUE_CREATE( pxNewQueue )
|
||||
#endif
|
||||
@ -618,6 +638,22 @@ extern "C" {
|
||||
#define traceQUEUE_REGISTRY_ADD(xQueue, pcQueueName)
|
||||
#endif
|
||||
|
||||
#ifndef traceTASK_NOTIFY_GIVE_FROM_ISR
|
||||
#define traceTASK_NOTIFY_GIVE_FROM_ISR()
|
||||
#endif
|
||||
|
||||
#ifndef traceISR_EXIT_TO_SCHEDULER
|
||||
#define traceISR_EXIT_TO_SCHEDULER()
|
||||
#endif
|
||||
|
||||
#ifndef traceISR_EXIT
|
||||
#define traceISR_EXIT()
|
||||
#endif
|
||||
|
||||
#ifndef traceISR_ENTER
|
||||
#define traceISR_ENTER(_n_)
|
||||
#endif
|
||||
|
||||
#ifndef configGENERATE_RUN_TIME_STATS
|
||||
#define configGENERATE_RUN_TIME_STATS 0
|
||||
#endif
|
||||
|
@ -163,14 +163,16 @@
|
||||
#define configMAX_PRIORITIES ( 25 )
|
||||
#endif
|
||||
|
||||
/* Minimal stack size. This may need to be increased for your application */
|
||||
/* NOTE: The FreeRTOS demos may not work reliably with stack size < 4KB. */
|
||||
/* The Xtensa-specific examples should be fine with XT_STACK_MIN_SIZE. */
|
||||
#if !(defined XT_STACK_MIN_SIZE)
|
||||
#error XT_STACK_MIN_SIZE not defined, did you include xtensa_config.h ?
|
||||
#ifndef CONFIG_ESP32_APPTRACE_ENABLE
|
||||
#define configMINIMAL_STACK_SIZE 768
|
||||
#else
|
||||
/* apptrace module requires at least 2KB of stack per task */
|
||||
#define configMINIMAL_STACK_SIZE 2048
|
||||
#endif
|
||||
|
||||
#define configMINIMAL_STACK_SIZE (XT_STACK_MIN_SIZE > 1024 ? XT_STACK_MIN_SIZE : 1024)
|
||||
#ifndef configIDLE_TASK_STACK_SIZE
|
||||
#define configIDLE_TASK_STACK_SIZE CONFIG_FREERTOS_IDLE_TASK_STACKSIZE
|
||||
#endif
|
||||
|
||||
/* The Xtensa port uses a separate interrupt stack. Adjust the stack size */
|
||||
/* to suit the needs of your specific application. */
|
||||
@ -227,6 +229,7 @@
|
||||
#define INCLUDE_vTaskDelay 1
|
||||
#define INCLUDE_uxTaskGetStackHighWaterMark 1
|
||||
#define INCLUDE_pcTaskGetTaskName 1
|
||||
#define INCLUDE_xTaskGetIdleTaskHandle 1
|
||||
|
||||
#if CONFIG_ENABLE_MEMORY_DEBUG
|
||||
#define configENABLE_MEMORY_DEBUG 1
|
||||
@ -276,6 +279,12 @@ extern void vPortCleanUpTCB ( void *pxTCB );
|
||||
#define configENABLE_TASK_SNAPSHOT 1
|
||||
#endif
|
||||
|
||||
#if CONFIG_SYSVIEW_ENABLE
|
||||
#ifndef __ASSEMBLER__
|
||||
#include "SEGGER_SYSVIEW_FreeRTOS.h"
|
||||
#undef INLINE // to avoid redefinition
|
||||
#endif /* def __ASSEMBLER__ */
|
||||
#endif
|
||||
|
||||
#endif /* FREERTOS_CONFIG_H */
|
||||
|
||||
|
@ -1,96 +0,0 @@
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#ifndef _HEAP_REGIONS_H
|
||||
#define _HEAP_REGIONS_H
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
|
||||
/* The maximum amount of tags in use */
|
||||
#define HEAPREGIONS_MAX_TAGCOUNT 16
|
||||
|
||||
/**
|
||||
* @brief Structure to define a memory region
|
||||
*/
|
||||
typedef struct HeapRegionTagged
|
||||
{
|
||||
uint8_t *pucStartAddress; ///< Start address of the region
|
||||
size_t xSizeInBytes; ///< Size of the region
|
||||
BaseType_t xTag; ///< Tag for the region
|
||||
uint32_t xExecAddr; ///< If non-zero, indicates the region also has an alias in IRAM.
|
||||
} HeapRegionTagged_t;
|
||||
|
||||
/**
|
||||
* @brief Initialize the heap allocator by feeding it the usable memory regions and their tags.
|
||||
*
|
||||
* This takes an array of heapRegionTagged_t structs, the last entry of which is a dummy entry
|
||||
* which has pucStartAddress set to NULL. It will initialize the heap allocator to serve memory
|
||||
* from these ranges.
|
||||
*
|
||||
* @param pxHeapRegions Array of region definitions
|
||||
*/
|
||||
|
||||
void vPortDefineHeapRegionsTagged( const HeapRegionTagged_t * const pxHeapRegions );
|
||||
|
||||
|
||||
/**
|
||||
* @brief Allocate memory from a region with a certain tag
|
||||
*
|
||||
* Like pvPortMalloc, this returns an allocated chunk of memory. This function,
|
||||
* however, forces the allocator to allocate from a region specified by a
|
||||
* specific tag.
|
||||
*
|
||||
* @param xWantedSize Size needed, in bytes
|
||||
* @param tag Tag of the memory region the allocation has to be from
|
||||
*
|
||||
* @return Pointer to allocated memory if succesful.
|
||||
* NULL if unsuccesful.
|
||||
*/
|
||||
void *pvPortMallocTagged( size_t xWantedSize, BaseType_t tag );
|
||||
|
||||
/**
|
||||
* @brief Free memory allocated with pvPortMallocTagged
|
||||
*
|
||||
* This is basically an implementation of free().
|
||||
*
|
||||
* @param pv Pointer to region allocated by pvPortMallocTagged
|
||||
*/
|
||||
void vPortFreeTagged( void *pv );
|
||||
|
||||
/**
|
||||
* @brief Get the lowest amount of memory free for a certain tag
|
||||
*
|
||||
* This function allows the user to see what the least amount of
|
||||
* free memory for a certain tag is.
|
||||
*
|
||||
* @param tag Tag of the memory region
|
||||
*
|
||||
* @return Minimum amount of free bytes available in the runtime of
|
||||
* the program
|
||||
*/
|
||||
size_t xPortGetMinimumEverFreeHeapSizeTagged( BaseType_t tag );
|
||||
|
||||
/**
|
||||
* @brief Get the amount of free bytes in a certain tagged region
|
||||
*
|
||||
* Works like xPortGetFreeHeapSize but allows the user to specify
|
||||
* a specific tag
|
||||
*
|
||||
* @param tag Tag of the memory region
|
||||
*
|
||||
* @return Remaining amount of free bytes in region
|
||||
*/
|
||||
size_t xPortGetFreeHeapSizeTagged( BaseType_t tag );
|
||||
|
||||
|
||||
#endif
|
@ -1,79 +0,0 @@
|
||||
#ifndef _HEAP_REGION_DEBUG_H
|
||||
#define _HEAP_REGION_DEBUG_H
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
|
||||
#if (configENABLE_MEMORY_DEBUG == 1)
|
||||
|
||||
#define DEBUG_DOG_VALUE 0x1a2b3c4d
|
||||
#define DEBUG_MAX_INFO_NUM 20
|
||||
#define DEBUG_TYPE_MALLOC 1
|
||||
#define DEBUG_TYPE_FREE 2
|
||||
|
||||
typedef struct {
|
||||
unsigned int dog;
|
||||
char task[4];
|
||||
unsigned int pc;
|
||||
}block_head_t;
|
||||
|
||||
typedef struct {
|
||||
unsigned int dog;
|
||||
}block_tail_t;
|
||||
|
||||
/* Please keep this definition same as BlockLink_t */
|
||||
typedef struct _os_block_t {
|
||||
struct _os_block_t *next; /*<< The next free block in the list. */
|
||||
int size: 24; /*<< The size of the free block. */
|
||||
int xtag: 7; /*<< Tag of this region */
|
||||
int xAllocated: 1; /*<< 1 if allocated */
|
||||
}os_block_t;
|
||||
|
||||
typedef struct {
|
||||
block_head_t head;
|
||||
os_block_t os_block;
|
||||
}debug_block_t;
|
||||
|
||||
typedef struct _mem_dbg_info{
|
||||
void *addr;
|
||||
char *task;
|
||||
uint32_t pc;
|
||||
uint32_t time;
|
||||
uint8_t type;
|
||||
}mem_dbg_info_t;
|
||||
|
||||
typedef struct _mem_dbg_ctl{
|
||||
mem_dbg_info_t info[DEBUG_MAX_INFO_NUM];
|
||||
uint32_t cnt;
|
||||
}mem_dbg_ctl_t;
|
||||
|
||||
#define BLOCK_HEAD_LEN sizeof(block_head_t)
|
||||
#define BLOCK_TAIL_LEN sizeof(block_tail_t)
|
||||
#define OS_BLOCK(_b) ((os_block_t*)((debug_block_t*)((char*)(_b) + BLOCK_HEAD_LEN)))
|
||||
#define DEBUG_BLOCK(_b) ((debug_block_t*)((char*)(_b) - BLOCK_HEAD_LEN))
|
||||
#define HEAD_DOG(_b) ((_b)->head.dog)
|
||||
#define TAIL_DOG(_b) (*(unsigned int*)((char*)(_b) + (((_b)->os_block.size ) - BLOCK_TAIL_LEN)))
|
||||
|
||||
#define DOG_ASSERT()\
|
||||
{\
|
||||
mem_debug_show();\
|
||||
abort();\
|
||||
}
|
||||
|
||||
extern void mem_check_block(void * data);
|
||||
extern void mem_init_dog(void *data);
|
||||
extern void mem_debug_init(size_t size, void *start, void *end, portMUX_TYPE *mutex);
|
||||
extern void mem_malloc_block(void *data);
|
||||
extern void mem_free_block(void *data);
|
||||
extern void mem_check_all(void* pv);
|
||||
|
||||
#else
|
||||
|
||||
#define mem_check_block(...)
|
||||
#define mem_init_dog(...)
|
||||
|
||||
#define BLOCK_HEAD_LEN 0
|
||||
#define BLOCK_TAIL_LEN 0
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
@ -136,29 +136,12 @@ extern "C" {
|
||||
StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters ) PRIVILEGED_FUNCTION;
|
||||
#endif
|
||||
|
||||
/* Used by heap_5.c. */
|
||||
typedef struct HeapRegion
|
||||
{
|
||||
uint8_t *pucStartAddress;
|
||||
size_t xSizeInBytes;
|
||||
} HeapRegion_t;
|
||||
|
||||
/*
|
||||
* Used to define multiple heap regions for use by heap_5.c. This function
|
||||
* must be called before any calls to pvPortMalloc() - not creating a task,
|
||||
* queue, semaphore, mutex, software timer, event group, etc. will result in
|
||||
* pvPortMalloc being called.
|
||||
*
|
||||
* pxHeapRegions passes in an array of HeapRegion_t structures - each of which
|
||||
* defines a region of memory that can be used as the heap. The array is
|
||||
* terminated by a HeapRegions_t structure that has a size of 0. The region
|
||||
* with the lowest start address must appear first in the array.
|
||||
*/
|
||||
void vPortDefineHeapRegions( const HeapRegion_t * const pxHeapRegions );
|
||||
|
||||
|
||||
/*
|
||||
* Map to the memory management routines required for the port.
|
||||
*
|
||||
* Note that libc standard malloc/free are also available for
|
||||
* non-FreeRTOS-specific code, and behave the same as
|
||||
* pvPortMalloc()/vPortFree().
|
||||
*/
|
||||
void *pvPortMalloc( size_t xSize ) PRIVILEGED_FUNCTION;
|
||||
void vPortFree( void *pv ) PRIVILEGED_FUNCTION;
|
||||
@ -209,7 +192,8 @@ BaseType_t xPortInIsrContext();
|
||||
*/
|
||||
#if( portUSING_MPU_WRAPPERS == 1 )
|
||||
struct xMEMORY_REGION;
|
||||
void vPortStoreTaskMPUSettings( xMPU_SETTINGS *xMPUSettings, const struct xMEMORY_REGION * const xRegions, StackType_t *pxBottomOfStack, uint16_t usStackDepth ) PRIVILEGED_FUNCTION;
|
||||
void vPortStoreTaskMPUSettings( xMPU_SETTINGS *xMPUSettings, const struct xMEMORY_REGION * const xRegions, StackType_t *pxBottomOfStack, uint32_t usStackDepth ) PRIVILEGED_FUNCTION;
|
||||
void vPortReleaseTaskMPUSettings( xMPU_SETTINGS *xMPUSettings );
|
||||
#endif
|
||||
|
||||
/* Multi-core: get current core ID */
|
||||
|
@ -172,6 +172,7 @@ typedef struct {
|
||||
#define portASSERT_IF_IN_ISR() vPortAssertIfInISR()
|
||||
void vPortAssertIfInISR();
|
||||
|
||||
|
||||
#define portCRITICAL_NESTING_IN_TCB 1
|
||||
|
||||
/*
|
||||
@ -193,6 +194,10 @@ do not disable the interrupts (because they already are).
|
||||
|
||||
This all assumes that interrupts are either entirely disabled or enabled. Interrupr priority levels
|
||||
will break this scheme.
|
||||
|
||||
Remark: For the ESP32, portENTER_CRITICAL and portENTER_CRITICAL_ISR both alias vTaskEnterCritical, meaning
|
||||
that either function can be called both from ISR as well as task context. This is not standard FreeRTOS
|
||||
behaviour; please keep this in mind if you need any compatibility with other FreeRTOS implementations.
|
||||
*/
|
||||
void vPortCPUInitializeMutex(portMUX_TYPE *mux);
|
||||
#ifdef CONFIG_FREERTOS_PORTMUX_DEBUG
|
||||
@ -202,8 +207,8 @@ void vTaskEnterCritical( portMUX_TYPE *mux, const char *function, int line );
|
||||
void vTaskExitCritical( portMUX_TYPE *mux, const char *function, int line );
|
||||
#define portENTER_CRITICAL(mux) vTaskEnterCritical(mux, __FUNCTION__, __LINE__)
|
||||
#define portEXIT_CRITICAL(mux) vTaskExitCritical(mux, __FUNCTION__, __LINE__)
|
||||
#define portENTER_CRITICAL_ISR(mux) vPortCPUAcquireMutex(mux, __FUNCTION__, __LINE__)
|
||||
#define portEXIT_CRITICAL_ISR(mux) vPortCPUReleaseMutex(mux, __FUNCTION__, __LINE__)
|
||||
#define portENTER_CRITICAL_ISR(mux) vTaskEnterCritical(mux, __FUNCTION__, __LINE__)
|
||||
#define portEXIT_CRITICAL_ISR(mux) vTaskExitCritical(mux, __FUNCTION__, __LINE__)
|
||||
#else
|
||||
void vTaskExitCritical( portMUX_TYPE *mux );
|
||||
void vTaskEnterCritical( portMUX_TYPE *mux );
|
||||
@ -211,13 +216,14 @@ void vPortCPUAcquireMutex(portMUX_TYPE *mux);
|
||||
portBASE_TYPE vPortCPUReleaseMutex(portMUX_TYPE *mux);
|
||||
#define portENTER_CRITICAL(mux) vTaskEnterCritical(mux)
|
||||
#define portEXIT_CRITICAL(mux) vTaskExitCritical(mux)
|
||||
#define portENTER_CRITICAL_ISR(mux) vPortCPUAcquireMutex(mux)
|
||||
#define portEXIT_CRITICAL_ISR(mux) vPortCPUReleaseMutex(mux)
|
||||
#define portENTER_CRITICAL_ISR(mux) vTaskEnterCritical(mux)
|
||||
#define portEXIT_CRITICAL_ISR(mux) vTaskExitCritical(mux)
|
||||
#endif
|
||||
|
||||
// Cleaner and preferred solution allows nested interrupts disabling and restoring via local registers or stack.
|
||||
// They can be called from interrupts too.
|
||||
//NOT SMP-COMPATIBLE! Use only if all you want is to disable the interrupts locally!
|
||||
// WARNING: This ONLY disables interrupt on the current CPU, meaning they cannot be used as a replacement for the vTaskExitCritical spinlock
|
||||
// on a multicore system. Only use if disabling interrupts on the current CPU only is indeed what you want.
|
||||
static inline unsigned portENTER_CRITICAL_NESTED() { unsigned state = XTOS_SET_INTLEVEL(XCHAL_EXCM_LEVEL); portbenchmarkINTERRUPT_DISABLE(); return state; }
|
||||
#define portEXIT_CRITICAL_NESTED(state) do { portbenchmarkINTERRUPT_RESTORE(state); XTOS_RESTORE_JUST_INTLEVEL(state); } while (0)
|
||||
|
||||
@ -262,7 +268,7 @@ static inline void uxPortCompareSet(volatile uint32_t *addr, uint32_t compare, u
|
||||
void vPortYield( void );
|
||||
void _frxt_setup_switch( void );
|
||||
#define portYIELD() vPortYield()
|
||||
#define portYIELD_FROM_ISR() _frxt_setup_switch()
|
||||
#define portYIELD_FROM_ISR() {traceISR_EXIT_TO_SCHEDULER(); _frxt_setup_switch();}
|
||||
|
||||
static inline uint32_t xPortGetCoreID();
|
||||
|
||||
@ -313,6 +319,10 @@ typedef struct {
|
||||
#define PRIVILEGED_DATA
|
||||
#endif
|
||||
|
||||
|
||||
void _xt_coproc_release(volatile void * coproc_sa_base);
|
||||
|
||||
|
||||
// porttrace
|
||||
#if configUSE_TRACE_FACILITY_2
|
||||
#include "porttrace.h"
|
||||
|
@ -159,7 +159,7 @@ typedef struct xTASK_PARAMETERS
|
||||
{
|
||||
TaskFunction_t pvTaskCode;
|
||||
const char * const pcName; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
|
||||
uint16_t usStackDepth;
|
||||
uint32_t usStackDepth;
|
||||
void *pvParameters;
|
||||
UBaseType_t uxPriority;
|
||||
StackType_t *puxStackBuffer;
|
||||
@ -178,7 +178,7 @@ typedef struct xTASK_STATUS
|
||||
UBaseType_t uxBasePriority; /* The priority to which the task will return if the task's current priority has been inherited to avoid unbounded priority inversion when obtaining a mutex. Only valid if configUSE_MUTEXES is defined as 1 in FreeRTOSConfig.h. */
|
||||
uint32_t ulRunTimeCounter; /* The total run time allocated to the task so far, as defined by the run time stats clock. See http://www.freertos.org/rtos-run-time-stats.html. Only valid when configGENERATE_RUN_TIME_STATS is defined as 1 in FreeRTOSConfig.h. */
|
||||
StackType_t *pxStackBase; /* Points to the lowest address of the task's stack area. */
|
||||
uint16_t usStackHighWaterMark; /* The minimum amount of stack space that has remained for the task since the task was created. The closer this value is to zero the closer the task has come to overflowing its stack. */
|
||||
uint32_t usStackHighWaterMark; /* The minimum amount of stack space that has remained for the task since the task was created. The closer this value is to zero the closer the task has come to overflowing its stack. */
|
||||
} TaskStatus_t;
|
||||
|
||||
/*
|
||||
@ -287,7 +287,7 @@ is used in assert() statements. */
|
||||
BaseType_t xTaskCreate(
|
||||
TaskFunction_t pvTaskCode,
|
||||
const char * const pcName,
|
||||
uint16_t usStackDepth,
|
||||
uint32_t usStackDepth,
|
||||
void *pvParameters,
|
||||
UBaseType_t uxPriority,
|
||||
TaskHandle_t *pvCreatedTask
|
||||
@ -377,7 +377,7 @@ is used in assert() statements. */
|
||||
#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
|
||||
BaseType_t xTaskCreatePinnedToCore( TaskFunction_t pxTaskCode,
|
||||
const char * const pcName,
|
||||
const uint16_t usStackDepth,
|
||||
const uint32_t usStackDepth,
|
||||
void * const pvParameters,
|
||||
UBaseType_t uxPriority,
|
||||
TaskHandle_t * const pxCreatedTask,
|
||||
@ -1250,7 +1250,7 @@ TickType_t xTaskGetTickCountFromISR( void ) PRIVILEGED_FUNCTION;
|
||||
|
||||
/**
|
||||
* task. h
|
||||
* <PRE>uint16_t uxTaskGetNumberOfTasks( void );</PRE>
|
||||
* <PRE>UBaseType_t uxTaskGetNumberOfTasks( void );</PRE>
|
||||
*
|
||||
* @return The number of tasks that the real time kernel is currently managing.
|
||||
* This includes all ready, blocked and suspended tasks. A task that
|
||||
@ -1297,6 +1297,25 @@ char *pcTaskGetTaskName( TaskHandle_t xTaskToQuery ) PRIVILEGED_FUNCTION; /*lint
|
||||
*/
|
||||
UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
|
||||
|
||||
/**
|
||||
* task.h
|
||||
* <PRE>uint8_t* pxTaskGetStackStart( TaskHandle_t xTask);</PRE>
|
||||
*
|
||||
* INCLUDE_pxTaskGetStackStart must be set to 1 in FreeRTOSConfig.h for
|
||||
* this function to be available.
|
||||
*
|
||||
* Returns the start of the stack associated with xTask. That is,
|
||||
* the highest stack memory address on architectures where the stack grows down
|
||||
* from high memory, and the lowest memory address on architectures where the
|
||||
* stack grows up from low memory.
|
||||
*
|
||||
* @param xTask Handle of the task associated with the stack returned.
|
||||
* Set xTask to NULL to return the stack of the calling task.
|
||||
*
|
||||
* @return A pointer to the start of the stack.
|
||||
*/
|
||||
uint8_t* pxTaskGetStackStart( TaskHandle_t xTask) PRIVILEGED_FUNCTION;
|
||||
|
||||
/* When using trace macros it is sometimes necessary to include task.h before
|
||||
FreeRTOS.h. When this is done TaskHookFunction_t will not yet have been defined,
|
||||
so the following two prototypes will cause a compilation error. This can be
|
||||
|
@ -117,6 +117,14 @@ static inline void xt_set_intclear(unsigned int arg)
|
||||
xthal_set_intclear(arg);
|
||||
}
|
||||
|
||||
/*
|
||||
-------------------------------------------------------------------------------
|
||||
Call this function to get handler's argument for the specified interrupt.
|
||||
|
||||
n - Interrupt number.
|
||||
-------------------------------------------------------------------------------
|
||||
*/
|
||||
extern void * xt_get_interrupt_handler_arg(int n);
|
||||
|
||||
#endif /* __XTENSA_API_H__ */
|
||||
|
||||
|
168
tools/sdk/include/heap/esp_ota_ops.h
Executable file
168
tools/sdk/include/heap/esp_ota_ops.h
Executable file
@ -0,0 +1,168 @@
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef _OTA_OPS_H
|
||||
#define _OTA_OPS_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include "esp_err.h"
|
||||
#include "esp_partition.h"
|
||||
#include "esp_spi_flash.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#define OTA_SIZE_UNKNOWN 0xffffffff /*!< Used for esp_ota_begin() if new image size is unknown */
|
||||
|
||||
#define ESP_ERR_OTA_BASE 0x1500 /*!< Base error code for ota_ops api */
|
||||
#define ESP_ERR_OTA_PARTITION_CONFLICT (ESP_ERR_OTA_BASE + 0x01) /*!< Error if request was to write or erase the current running partition */
|
||||
#define ESP_ERR_OTA_SELECT_INFO_INVALID (ESP_ERR_OTA_BASE + 0x02) /*!< Error if OTA data partition contains invalid content */
|
||||
#define ESP_ERR_OTA_VALIDATE_FAILED (ESP_ERR_OTA_BASE + 0x03) /*!< Error if OTA app image is invalid */
|
||||
|
||||
/**
|
||||
* @brief Opaque handle for an application OTA update
|
||||
*
|
||||
* esp_ota_begin() returns a handle which is then used for subsequent
|
||||
* calls to esp_ota_write() and esp_ota_end().
|
||||
*/
|
||||
typedef uint32_t esp_ota_handle_t;
|
||||
|
||||
/**
|
||||
* @brief Commence an OTA update writing to the specified partition.
|
||||
|
||||
* The specified partition is erased to the specified image size.
|
||||
*
|
||||
* If image size is not yet known, pass OTA_SIZE_UNKNOWN which will
|
||||
* cause the entire partition to be erased.
|
||||
*
|
||||
* On success, this function allocates memory that remains in use
|
||||
* until esp_ota_end() is called with the returned handle.
|
||||
*
|
||||
* @param partition Pointer to info for partition which will receive the OTA update. Required.
|
||||
* @param image_size Size of new OTA app image. Partition will be erased in order to receive this size of image. If 0 or OTA_SIZE_UNKNOWN, the entire partition is erased.
|
||||
* @param out_handle On success, returns a handle which should be used for subsequent esp_ota_write() and esp_ota_end() calls.
|
||||
|
||||
* @return
|
||||
* - ESP_OK: OTA operation commenced successfully.
|
||||
* - ESP_ERR_INVALID_ARG: partition or out_handle arguments were NULL, or partition doesn't point to an OTA app partition.
|
||||
* - ESP_ERR_NO_MEM: Cannot allocate memory for OTA operation.
|
||||
* - ESP_ERR_OTA_PARTITION_CONFLICT: Partition holds the currently running firmware, cannot update in place.
|
||||
* - ESP_ERR_NOT_FOUND: Partition argument not found in partition table.
|
||||
* - ESP_ERR_OTA_SELECT_INFO_INVALID: The OTA data partition contains invalid data.
|
||||
* - ESP_ERR_INVALID_SIZE: Partition doesn't fit in configured flash size.
|
||||
* - ESP_ERR_FLASH_OP_TIMEOUT or ESP_ERR_FLASH_OP_FAIL: Flash write failed.
|
||||
*/
|
||||
esp_err_t esp_ota_begin(const esp_partition_t* partition, size_t image_size, esp_ota_handle_t* out_handle);
|
||||
|
||||
/**
|
||||
* @brief Write OTA update data to partition
|
||||
*
|
||||
* This function can be called multiple times as
|
||||
* data is received during the OTA operation. Data is written
|
||||
* sequentially to the partition.
|
||||
*
|
||||
* @param handle Handle obtained from esp_ota_begin
|
||||
* @param data Data buffer to write
|
||||
* @param size Size of data buffer in bytes.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Data was written to flash successfully.
|
||||
* - ESP_ERR_INVALID_ARG: handle is invalid.
|
||||
* - ESP_ERR_OTA_VALIDATE_FAILED: First byte of image contains invalid app image magic byte.
|
||||
* - ESP_ERR_FLASH_OP_TIMEOUT or ESP_ERR_FLASH_OP_FAIL: Flash write failed.
|
||||
* - ESP_ERR_OTA_SELECT_INFO_INVALID: OTA data partition has invalid contents
|
||||
*/
|
||||
esp_err_t esp_ota_write(esp_ota_handle_t handle, const void* data, size_t size);
|
||||
|
||||
/**
|
||||
* @brief Finish OTA update and validate newly written app image.
|
||||
*
|
||||
* @param handle Handle obtained from esp_ota_begin().
|
||||
*
|
||||
* @note After calling esp_ota_end(), the handle is no longer valid and any memory associated with it is freed (regardless of result).
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Newly written OTA app image is valid.
|
||||
* - ESP_ERR_NOT_FOUND: OTA handle was not found.
|
||||
* - ESP_ERR_INVALID_ARG: Handle was never written to.
|
||||
* - ESP_ERR_OTA_VALIDATE_FAILED: OTA image is invalid (either not a valid app image, or - if secure boot is enabled - signature failed to verify.)
|
||||
* - ESP_ERR_INVALID_STATE: If flash encryption is enabled, this result indicates an internal error writing the final encrypted bytes to flash.
|
||||
*/
|
||||
esp_err_t esp_ota_end(esp_ota_handle_t handle);
|
||||
|
||||
/**
|
||||
* @brief Configure OTA data for a new boot partition
|
||||
*
|
||||
* @note If this function returns ESP_OK, calling esp_restart() will boot the newly configured app partition.
|
||||
*
|
||||
* @param partition Pointer to info for partition containing app image to boot.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: OTA data updated, next reboot will use specified partition.
|
||||
* - ESP_ERR_INVALID_ARG: partition argument was NULL or didn't point to a valid OTA partition of type "app".
|
||||
* - ESP_ERR_OTA_VALIDATE_FAILED: Partition contained invalid app image. Also returned if secure boot is enabled and signature validation failed.
|
||||
* - ESP_ERR_NOT_FOUND: OTA data partition not found.
|
||||
* - ESP_ERR_FLASH_OP_TIMEOUT or ESP_ERR_FLASH_OP_FAIL: Flash erase or write failed.
|
||||
*/
|
||||
esp_err_t esp_ota_set_boot_partition(const esp_partition_t* partition);
|
||||
|
||||
/**
|
||||
* @brief Get partition info of currently configured boot app
|
||||
*
|
||||
* If esp_ota_set_boot_partition() has been called, the partition which was set by that function will be returned.
|
||||
*
|
||||
* If esp_ota_set_boot_partition() has not been called, the result is
|
||||
* equivalent to esp_ota_get_running_partition().
|
||||
*
|
||||
* @return Pointer to info for partition structure, or NULL if no partition is found or flash read operation failed. Returned pointer is valid for the lifetime of the application.
|
||||
*/
|
||||
const esp_partition_t* esp_ota_get_boot_partition(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get partition info of currently running app
|
||||
*
|
||||
* This function is different to esp_ota_get_boot_partition() in that
|
||||
* it ignores any change of selected boot partition caused by
|
||||
* esp_ota_set_boot_partition(). Only the app whose code is currently
|
||||
* running will have its partition information returned.
|
||||
*
|
||||
* @return Pointer to info for partition structure, or NULL if no partition is found or flash read operation failed. Returned pointer is valid for the lifetime of the application.
|
||||
*/
|
||||
const esp_partition_t* esp_ota_get_running_partition(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Return the next OTA app partition which should be written with a new firmware.
|
||||
*
|
||||
* Call this function to find an OTA app partition which can be passed to esp_ota_begin().
|
||||
*
|
||||
* Finds next partition round-robin, starting from the current running partition.
|
||||
*
|
||||
* @param start_from If set, treat this partition info as describing the current running partition. Can be NULL, in which case esp_ota_get_running_partition() is used to find the currently running partition. The result of this function is never the same as this argument.
|
||||
*
|
||||
* @return Pointer to info for partition which should be updated next. NULL result indicates invalid OTA data partition, or that no eligible OTA app slot partition was found.
|
||||
*
|
||||
*/
|
||||
const esp_partition_t* esp_ota_get_next_update_partition(const esp_partition_t *start_from);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* OTA_OPS_H */
|
@ -95,6 +95,29 @@ uint32_t esp_log_early_timestamp(void);
|
||||
*/
|
||||
void esp_log_write(esp_log_level_t level, const char* tag, const char* format, ...) __attribute__ ((format (printf, 3, 4)));
|
||||
|
||||
/**
|
||||
* @brief Log a buffer of hex bytes at Info level
|
||||
*
|
||||
* @param tag description tag
|
||||
*
|
||||
* @param buffer Pointer to the buffer array
|
||||
*
|
||||
* @param buff_len length of buffer in bytes
|
||||
*
|
||||
*/
|
||||
void esp_log_buffer_hex(const char *tag, const void *buffer, uint16_t buff_len);
|
||||
|
||||
/**
|
||||
* @brief Log a buffer of characters at Info level. Buffer should contain only printable characters.
|
||||
*
|
||||
* @param tag description tag
|
||||
*
|
||||
* @param buffer Pointer to the buffer array
|
||||
*
|
||||
* @param buff_len length of buffer in bytes
|
||||
*
|
||||
*/
|
||||
void esp_log_buffer_char(const char *tag, const void *buffer, uint16_t buff_len);
|
||||
|
||||
#if CONFIG_LOG_COLORS
|
||||
#define LOG_COLOR_BLACK "30"
|
||||
|
@ -36,6 +36,8 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "arch/sys_arch.h"
|
||||
|
||||
@ -67,10 +69,26 @@ typedef int sys_prot_t;
|
||||
#include <stdio.h>
|
||||
|
||||
#define LWIP_PLATFORM_DIAG(x) do {printf x;} while(0)
|
||||
#define LWIP_PLATFORM_ASSERT(x) do {printf(x); sys_arch_assert(__FILE__, __LINE__);} while(0)
|
||||
// __assert_func is the assertion failure handler from newlib, defined in assert.h
|
||||
#define LWIP_PLATFORM_ASSERT(message) __assert_func(__FILE__, __LINE__, __ASSERT_FUNC, message)
|
||||
|
||||
//#define LWIP_DEBUG
|
||||
#ifdef NDEBUG
|
||||
#define LWIP_NOASSERT
|
||||
//#define LWIP_ERROR
|
||||
#else // Assertions enabled
|
||||
|
||||
// If assertions are on, the default LWIP_ERROR handler behaviour is to
|
||||
// abort w/ an assertion failure. Don't do this, instead just print the error (if LWIP_DEBUG is set)
|
||||
// and run the handler (same as the LWIP_ERROR behaviour if LWIP_NOASSERT is set).
|
||||
#ifdef LWIP_DEBUG
|
||||
#define LWIP_ERROR(message, expression, handler) do { if (!(expression)) { \
|
||||
puts(message); handler;}} while(0)
|
||||
#else
|
||||
// If LWIP_DEBUG is not set, return the error silently (default LWIP behaviour, also.)
|
||||
#define LWIP_ERROR(message, expression, handler) do { if (!(expression)) { \
|
||||
handler;}} while(0)
|
||||
#endif // LWIP_DEBUG
|
||||
|
||||
#endif /* NDEBUG */
|
||||
|
||||
|
||||
#endif /* __ARCH_CC_H__ */
|
||||
|
@ -67,7 +67,6 @@ typedef struct sys_mbox_s {
|
||||
#define sys_sem_valid( x ) ( ( ( *x ) == NULL) ? pdFALSE : pdTRUE )
|
||||
#define sys_sem_set_invalid( x ) ( ( *x ) = NULL )
|
||||
|
||||
void sys_arch_assert(const char *file, int line);
|
||||
uint32_t system_get_time(void);
|
||||
void sys_delay_ms(uint32_t ms);
|
||||
sys_sem_t* sys_thread_sem_init(void);
|
||||
|
@ -385,7 +385,7 @@ void netif_set_gw(struct netif *netif, const ip4_addr_t *gw);
|
||||
void netif_set_up(struct netif *netif);
|
||||
void netif_set_down(struct netif *netif);
|
||||
/** Ask if an interface is up */
|
||||
#define netif_is_up(netif) (((netif)->flags & NETIF_FLAG_UP) ? (u8_t)1 : (u8_t)0)
|
||||
#define netif_is_up(netif) ( ((netif) && ((netif)->flags & NETIF_FLAG_UP)) ? (u8_t)1 : (u8_t)0)
|
||||
|
||||
#if LWIP_NETIF_STATUS_CALLBACK
|
||||
void netif_set_status_callback(struct netif *netif, netif_status_callback_fn status_callback);
|
||||
|
@ -184,6 +184,10 @@
|
||||
----------------------------------
|
||||
*/
|
||||
|
||||
#define LWIP_BROADCAST_PING CONFIG_LWIP_BROADCAST_PING
|
||||
|
||||
#define LWIP_MULTICAST_PING CONFIG_LWIP_MULTICAST_PING
|
||||
|
||||
/*
|
||||
---------------------------------
|
||||
---------- RAW options ----------
|
||||
@ -280,7 +284,7 @@
|
||||
* TCP_QUEUE_OOSEQ==1: TCP will queue segments that arrive out of order.
|
||||
* Define to 0 if your device is low on memory.
|
||||
*/
|
||||
#define TCP_QUEUE_OOSEQ 1
|
||||
#define TCP_QUEUE_OOSEQ CONFIG_TCP_QUEUE_OOSEQ
|
||||
|
||||
/*
|
||||
* LWIP_EVENT_API==1: The user defines lwip_tcp_event() to receive all
|
||||
@ -288,7 +292,7 @@
|
||||
* LWIP_CALLBACK_API==1: The PCB callback function is called directly
|
||||
* for the event. This is the default.
|
||||
*/
|
||||
#define TCP_MSS 1460
|
||||
#define TCP_MSS CONFIG_TCP_MSS
|
||||
|
||||
/**
|
||||
* TCP_MAXRTX: Maximum number of retransmissions of data segments.
|
||||
@ -305,6 +309,24 @@
|
||||
*/
|
||||
#define TCP_LISTEN_BACKLOG 1
|
||||
|
||||
|
||||
/**
|
||||
* TCP_OVERSIZE: The maximum number of bytes that tcp_write may
|
||||
* allocate ahead of time
|
||||
*/
|
||||
#ifdef CONFIG_TCP_OVERSIZE_MSS
|
||||
#define TCP_OVERSIZE TCP_MSS
|
||||
#endif
|
||||
#ifdef CONFIG_TCP_OVERSIZE_QUARTER_MSS
|
||||
#define TCP_OVERSIZE (TCP_MSS/4)
|
||||
#endif
|
||||
#ifdef CONFIG_TCP_OVERSIZE_DISABLE
|
||||
#define TCP_OVERSIZE 0
|
||||
#endif
|
||||
#ifndef TCP_OVERSIZE
|
||||
#error "One of CONFIG_TCP_OVERSIZE_xxx options should be set by sdkconfig"
|
||||
#endif
|
||||
|
||||
/*
|
||||
----------------------------------
|
||||
---------- Pbuf options ----------
|
||||
@ -395,14 +417,14 @@
|
||||
* NETCONN_UDP. The queue size value itself is platform-dependent, but is passed
|
||||
* to sys_mbox_new() when the recvmbox is created.
|
||||
*/
|
||||
#define DEFAULT_UDP_RECVMBOX_SIZE 6
|
||||
#define DEFAULT_UDP_RECVMBOX_SIZE CONFIG_UDP_RECVMBOX_SIZE
|
||||
|
||||
/**
|
||||
* DEFAULT_TCP_RECVMBOX_SIZE: The mailbox size for the incoming packets on a
|
||||
* NETCONN_TCP. The queue size value itself is platform-dependent, but is passed
|
||||
* to sys_mbox_new() when the recvmbox is created.
|
||||
*/
|
||||
#define DEFAULT_TCP_RECVMBOX_SIZE 6
|
||||
#define DEFAULT_TCP_RECVMBOX_SIZE CONFIG_TCP_RECVMBOX_SIZE
|
||||
|
||||
/**
|
||||
* DEFAULT_ACCEPTMBOX_SIZE: The mailbox size for the incoming connections.
|
||||
@ -574,6 +596,7 @@
|
||||
---------- Hook options ---------------
|
||||
---------------------------------------
|
||||
*/
|
||||
#define LWIP_HOOK_IP4_ROUTE_SRC ip4_route_src_hook
|
||||
|
||||
/*
|
||||
---------------------------------------
|
||||
@ -669,8 +692,8 @@
|
||||
#define ESP_DHCP_TIMER 1
|
||||
#define ESP_LWIP_LOGI(...) ESP_LOGI("lwip", __VA_ARGS__)
|
||||
|
||||
#define TCP_WND_DEFAULT (4*TCP_MSS)
|
||||
#define TCP_SND_BUF_DEFAULT (4*TCP_MSS)
|
||||
#define TCP_WND_DEFAULT CONFIG_TCP_WND_DEFAULT
|
||||
#define TCP_SND_BUF_DEFAULT CONFIG_TCP_SND_BUF_DEFAULT
|
||||
|
||||
#if ESP_PERF
|
||||
#define DBG_PERF_PATH_SET(dir, point)
|
||||
|
@ -36,6 +36,8 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "arch/sys_arch.h"
|
||||
|
||||
@ -67,10 +69,26 @@ typedef int sys_prot_t;
|
||||
#include <stdio.h>
|
||||
|
||||
#define LWIP_PLATFORM_DIAG(x) do {printf x;} while(0)
|
||||
#define LWIP_PLATFORM_ASSERT(x) do {printf(x); sys_arch_assert(__FILE__, __LINE__);} while(0)
|
||||
// __assert_func is the assertion failure handler from newlib, defined in assert.h
|
||||
#define LWIP_PLATFORM_ASSERT(message) __assert_func(__FILE__, __LINE__, __ASSERT_FUNC, message)
|
||||
|
||||
//#define LWIP_DEBUG
|
||||
#ifdef NDEBUG
|
||||
#define LWIP_NOASSERT
|
||||
//#define LWIP_ERROR
|
||||
#else // Assertions enabled
|
||||
|
||||
// If assertions are on, the default LWIP_ERROR handler behaviour is to
|
||||
// abort w/ an assertion failure. Don't do this, instead just print the error (if LWIP_DEBUG is set)
|
||||
// and run the handler (same as the LWIP_ERROR behaviour if LWIP_NOASSERT is set).
|
||||
#ifdef LWIP_DEBUG
|
||||
#define LWIP_ERROR(message, expression, handler) do { if (!(expression)) { \
|
||||
puts(message); handler;}} while(0)
|
||||
#else
|
||||
// If LWIP_DEBUG is not set, return the error silently (default LWIP behaviour, also.)
|
||||
#define LWIP_ERROR(message, expression, handler) do { if (!(expression)) { \
|
||||
handler;}} while(0)
|
||||
#endif // LWIP_DEBUG
|
||||
|
||||
#endif /* NDEBUG */
|
||||
|
||||
|
||||
#endif /* __ARCH_CC_H__ */
|
||||
|
@ -67,7 +67,6 @@ typedef struct sys_mbox_s {
|
||||
#define sys_sem_valid( x ) ( ( ( *x ) == NULL) ? pdFALSE : pdTRUE )
|
||||
#define sys_sem_set_invalid( x ) ( ( *x ) = NULL )
|
||||
|
||||
void sys_arch_assert(const char *file, int line);
|
||||
uint32_t system_get_time(void);
|
||||
void sys_delay_ms(uint32_t ms);
|
||||
sys_sem_t* sys_thread_sem_init(void);
|
||||
|
@ -184,6 +184,10 @@
|
||||
----------------------------------
|
||||
*/
|
||||
|
||||
#define LWIP_BROADCAST_PING CONFIG_LWIP_BROADCAST_PING
|
||||
|
||||
#define LWIP_MULTICAST_PING CONFIG_LWIP_MULTICAST_PING
|
||||
|
||||
/*
|
||||
---------------------------------
|
||||
---------- RAW options ----------
|
||||
@ -280,7 +284,7 @@
|
||||
* TCP_QUEUE_OOSEQ==1: TCP will queue segments that arrive out of order.
|
||||
* Define to 0 if your device is low on memory.
|
||||
*/
|
||||
#define TCP_QUEUE_OOSEQ 1
|
||||
#define TCP_QUEUE_OOSEQ CONFIG_TCP_QUEUE_OOSEQ
|
||||
|
||||
/*
|
||||
* LWIP_EVENT_API==1: The user defines lwip_tcp_event() to receive all
|
||||
@ -288,7 +292,7 @@
|
||||
* LWIP_CALLBACK_API==1: The PCB callback function is called directly
|
||||
* for the event. This is the default.
|
||||
*/
|
||||
#define TCP_MSS 1460
|
||||
#define TCP_MSS CONFIG_TCP_MSS
|
||||
|
||||
/**
|
||||
* TCP_MAXRTX: Maximum number of retransmissions of data segments.
|
||||
@ -305,6 +309,24 @@
|
||||
*/
|
||||
#define TCP_LISTEN_BACKLOG 1
|
||||
|
||||
|
||||
/**
|
||||
* TCP_OVERSIZE: The maximum number of bytes that tcp_write may
|
||||
* allocate ahead of time
|
||||
*/
|
||||
#ifdef CONFIG_TCP_OVERSIZE_MSS
|
||||
#define TCP_OVERSIZE TCP_MSS
|
||||
#endif
|
||||
#ifdef CONFIG_TCP_OVERSIZE_QUARTER_MSS
|
||||
#define TCP_OVERSIZE (TCP_MSS/4)
|
||||
#endif
|
||||
#ifdef CONFIG_TCP_OVERSIZE_DISABLE
|
||||
#define TCP_OVERSIZE 0
|
||||
#endif
|
||||
#ifndef TCP_OVERSIZE
|
||||
#error "One of CONFIG_TCP_OVERSIZE_xxx options should be set by sdkconfig"
|
||||
#endif
|
||||
|
||||
/*
|
||||
----------------------------------
|
||||
---------- Pbuf options ----------
|
||||
@ -395,14 +417,14 @@
|
||||
* NETCONN_UDP. The queue size value itself is platform-dependent, but is passed
|
||||
* to sys_mbox_new() when the recvmbox is created.
|
||||
*/
|
||||
#define DEFAULT_UDP_RECVMBOX_SIZE 6
|
||||
#define DEFAULT_UDP_RECVMBOX_SIZE CONFIG_UDP_RECVMBOX_SIZE
|
||||
|
||||
/**
|
||||
* DEFAULT_TCP_RECVMBOX_SIZE: The mailbox size for the incoming packets on a
|
||||
* NETCONN_TCP. The queue size value itself is platform-dependent, but is passed
|
||||
* to sys_mbox_new() when the recvmbox is created.
|
||||
*/
|
||||
#define DEFAULT_TCP_RECVMBOX_SIZE 6
|
||||
#define DEFAULT_TCP_RECVMBOX_SIZE CONFIG_TCP_RECVMBOX_SIZE
|
||||
|
||||
/**
|
||||
* DEFAULT_ACCEPTMBOX_SIZE: The mailbox size for the incoming connections.
|
||||
@ -574,6 +596,7 @@
|
||||
---------- Hook options ---------------
|
||||
---------------------------------------
|
||||
*/
|
||||
#define LWIP_HOOK_IP4_ROUTE_SRC ip4_route_src_hook
|
||||
|
||||
/*
|
||||
---------------------------------------
|
||||
@ -669,8 +692,8 @@
|
||||
#define ESP_DHCP_TIMER 1
|
||||
#define ESP_LWIP_LOGI(...) ESP_LOGI("lwip", __VA_ARGS__)
|
||||
|
||||
#define TCP_WND_DEFAULT (4*TCP_MSS)
|
||||
#define TCP_SND_BUF_DEFAULT (4*TCP_MSS)
|
||||
#define TCP_WND_DEFAULT CONFIG_TCP_WND_DEFAULT
|
||||
#define TCP_SND_BUF_DEFAULT CONFIG_TCP_SND_BUF_DEFAULT
|
||||
|
||||
#if ESP_PERF
|
||||
#define DBG_PERF_PATH_SET(dir, point)
|
||||
|
@ -1,50 +1,28 @@
|
||||
/*
|
||||
assert.h
|
||||
// Copyright 2017 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
|
||||
/* This header file wraps newlib's own unmodified assert.h and adds
|
||||
support for silent assertion failure.
|
||||
*/
|
||||
#pragma once
|
||||
#include <sdkconfig.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "_ansi.h"
|
||||
#include_next <assert.h>
|
||||
|
||||
#if defined(CONFIG_OPTIMIZATION_ASSERTIONS_SILENT) && !defined(NDEBUG)
|
||||
#undef assert
|
||||
|
||||
#ifdef NDEBUG /* required by ANSI standard */
|
||||
# define assert(__e) ((void) sizeof(__e))
|
||||
#else
|
||||
# define assert(__e) ((__e) ? (void)0 : __assert_func (__FILE__, __LINE__, \
|
||||
__ASSERT_FUNC, #__e))
|
||||
|
||||
# ifndef __ASSERT_FUNC
|
||||
/* Use g++'s demangled names in C++. */
|
||||
# if defined __cplusplus && defined __GNUC__
|
||||
# define __ASSERT_FUNC __PRETTY_FUNCTION__
|
||||
|
||||
/* C99 requires the use of __func__. */
|
||||
# elif __STDC_VERSION__ >= 199901L
|
||||
# define __ASSERT_FUNC __func__
|
||||
|
||||
/* Older versions of gcc don't have __func__ but can use __FUNCTION__. */
|
||||
# elif __GNUC__ >= 2
|
||||
# define __ASSERT_FUNC __FUNCTION__
|
||||
|
||||
/* failed to detect __func__ support. */
|
||||
# else
|
||||
# define __ASSERT_FUNC ((char *) 0)
|
||||
# endif
|
||||
# endif /* !__ASSERT_FUNC */
|
||||
#endif /* !NDEBUG */
|
||||
|
||||
void _EXFUN(__assert, (const char *, int, const char *)
|
||||
_ATTRIBUTE ((__noreturn__)));
|
||||
void _EXFUN(__assert_func, (const char *, int, const char *, const char *)
|
||||
_ATTRIBUTE ((__noreturn__)));
|
||||
|
||||
#if __STDC_VERSION__ >= 201112L && !defined __cplusplus
|
||||
# define static_assert _Static_assert
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#define assert(__e) ((__e) ? (void)0 : abort())
|
||||
#endif
|
||||
|
151
tools/sdk/include/nghttp/nghttp2/asio_http2.h
Normal file
151
tools/sdk/include/nghttp/nghttp2/asio_http2.h
Normal file
@ -0,0 +1,151 @@
|
||||
/*
|
||||
* nghttp2 - HTTP/2 C Library
|
||||
*
|
||||
* Copyright (c) 2014 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef ASIO_HTTP2_H
|
||||
#define ASIO_HTTP2_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
|
||||
#include <boost/system/error_code.hpp>
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/asio/ssl.hpp>
|
||||
|
||||
#include <nghttp2/nghttp2.h>
|
||||
|
||||
namespace nghttp2 {
|
||||
|
||||
namespace asio_http2 {
|
||||
|
||||
struct header_value {
|
||||
// header field value
|
||||
std::string value;
|
||||
// true if the header field value is sensitive information, such as
|
||||
// authorization information or short length secret cookies. If
|
||||
// true, those header fields are not indexed by HPACK (but still
|
||||
// huffman-encoded), which results in lesser compression.
|
||||
bool sensitive;
|
||||
};
|
||||
|
||||
// header fields. The header field name must be lower-cased.
|
||||
using header_map = std::multimap<std::string, header_value>;
|
||||
|
||||
const boost::system::error_category &nghttp2_category() noexcept;
|
||||
|
||||
struct uri_ref {
|
||||
std::string scheme;
|
||||
std::string host;
|
||||
// form after percent-encoding decoded
|
||||
std::string path;
|
||||
// original path, percent-encoded
|
||||
std::string raw_path;
|
||||
// original query, percent-encoded
|
||||
std::string raw_query;
|
||||
std::string fragment;
|
||||
};
|
||||
|
||||
// Callback function when data is arrived. EOF is indicated by
|
||||
// passing 0 to the second parameter.
|
||||
typedef std::function<void(const uint8_t *, std::size_t)> data_cb;
|
||||
typedef std::function<void(void)> void_cb;
|
||||
typedef std::function<void(const boost::system::error_code &ec)> error_cb;
|
||||
// Callback function when request and response are finished. The
|
||||
// parameter indicates the cause of closure.
|
||||
typedef std::function<void(uint32_t)> close_cb;
|
||||
|
||||
// Callback function to generate response body. This function has the
|
||||
// same semantics with nghttp2_data_source_read_callback. Just source
|
||||
// and user_data parameters are removed.
|
||||
//
|
||||
// Basically, write at most |len| bytes to |data| and returns the
|
||||
// number of bytes written. If there is no data left to send, set
|
||||
// NGHTTP2_DATA_FLAG_EOF to *data_flags (e.g., *data_flags |=
|
||||
// NGHTTP2_DATA_FLAG_EOF). If there is still data to send but they
|
||||
// are not available right now, return NGHTTP2_ERR_DEFERRED. In case
|
||||
// of the error and request/response must be closed, return
|
||||
// NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE.
|
||||
typedef std::function<ssize_t(uint8_t *buf, std::size_t len,
|
||||
uint32_t *data_flags)>
|
||||
generator_cb;
|
||||
|
||||
// Convenient function to create function to read file denoted by
|
||||
// |path|. This can be passed to response::end().
|
||||
generator_cb file_generator(const std::string &path);
|
||||
|
||||
// Like file_generator(const std::string&), but it takes opened file
|
||||
// descriptor. The passed descriptor will be closed when returned
|
||||
// function object is destroyed.
|
||||
generator_cb file_generator_from_fd(int fd);
|
||||
|
||||
// Validates path so that it does not contain directory traversal
|
||||
// vector. Returns true if path is safe. The |path| must start with
|
||||
// "/" otherwise returns false. This function should be called after
|
||||
// percent-decode was performed.
|
||||
bool check_path(const std::string &path);
|
||||
|
||||
// Performs percent-decode against string |s|.
|
||||
std::string percent_decode(const std::string &s);
|
||||
|
||||
// Returns HTTP date representation of current posix time |t|.
|
||||
std::string http_date(int64_t t);
|
||||
|
||||
// Parses |uri| and extract scheme, host and service. The service is
|
||||
// port component of URI (e.g., "8443") if available, otherwise it is
|
||||
// scheme (e.g., "https").
|
||||
boost::system::error_code host_service_from_uri(boost::system::error_code &ec,
|
||||
std::string &scheme,
|
||||
std::string &host,
|
||||
std::string &service,
|
||||
const std::string &uri);
|
||||
|
||||
enum nghttp2_asio_error {
|
||||
NGHTTP2_ASIO_ERR_NO_ERROR = 0,
|
||||
NGHTTP2_ASIO_ERR_TLS_NO_APP_PROTO_NEGOTIATED = 1,
|
||||
};
|
||||
|
||||
} // namespace asio_http2
|
||||
|
||||
} // namespace nghttp2
|
||||
|
||||
namespace boost {
|
||||
|
||||
namespace system {
|
||||
|
||||
template <> struct is_error_code_enum<nghttp2_error> {
|
||||
BOOST_STATIC_CONSTANT(bool, value = true);
|
||||
};
|
||||
|
||||
template <> struct is_error_code_enum<nghttp2::asio_http2::nghttp2_asio_error> {
|
||||
BOOST_STATIC_CONSTANT(bool, value = true);
|
||||
};
|
||||
|
||||
} // namespace system
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // ASIO_HTTP2_H
|
241
tools/sdk/include/nghttp/nghttp2/asio_http2_client.h
Normal file
241
tools/sdk/include/nghttp/nghttp2/asio_http2_client.h
Normal file
@ -0,0 +1,241 @@
|
||||
/*
|
||||
* nghttp2 - HTTP/2 C Library
|
||||
*
|
||||
* Copyright (c) 2015 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef ASIO_HTTP2_CLIENT_H
|
||||
#define ASIO_HTTP2_CLIENT_H
|
||||
|
||||
#include <nghttp2/asio_http2.h>
|
||||
|
||||
namespace nghttp2 {
|
||||
|
||||
namespace asio_http2 {
|
||||
|
||||
namespace client {
|
||||
|
||||
class response_impl;
|
||||
|
||||
class response {
|
||||
public:
|
||||
// Application must not call this directly.
|
||||
response();
|
||||
~response();
|
||||
|
||||
// Sets callback which is invoked when chunk of response body is
|
||||
// received.
|
||||
void on_data(data_cb cb) const;
|
||||
|
||||
// Returns status code.
|
||||
int status_code() const;
|
||||
|
||||
// Returns content-length. -1 if it is unknown.
|
||||
int64_t content_length() const;
|
||||
|
||||
// Returns the response header fields. The pusedo header fields,
|
||||
// which start with colon (:), are exluced from this list.
|
||||
const header_map &header() const;
|
||||
|
||||
// Application must not call this directly.
|
||||
response_impl &impl() const;
|
||||
|
||||
private:
|
||||
std::unique_ptr<response_impl> impl_;
|
||||
};
|
||||
|
||||
class request;
|
||||
|
||||
using response_cb = std::function<void(const response &)>;
|
||||
using request_cb = std::function<void(const request &)>;
|
||||
using connect_cb =
|
||||
std::function<void(boost::asio::ip::tcp::resolver::iterator)>;
|
||||
|
||||
class request_impl;
|
||||
|
||||
class request {
|
||||
public:
|
||||
// Application must not call this directly.
|
||||
request();
|
||||
~request();
|
||||
|
||||
// Sets callback which is invoked when response header is received.
|
||||
void on_response(response_cb cb) const;
|
||||
|
||||
// Sets callback which is invoked when push request header is
|
||||
// received.
|
||||
void on_push(request_cb cb) const;
|
||||
|
||||
// Sets callback which is invoked when this request and response are
|
||||
// finished. After the invocation of this callback, the application
|
||||
// must not access request and response object.
|
||||
void on_close(close_cb cb) const;
|
||||
|
||||
// Write trailer part. This must be called after setting both
|
||||
// NGHTTP2_DATA_FLAG_EOF and NGHTTP2_DATA_FLAG_NO_END_STREAM set in
|
||||
// *data_flag parameter in generator_cb passed to session::submit()
|
||||
// function.
|
||||
void write_trailer(header_map h) const;
|
||||
|
||||
// Cancels this request and response with given error code.
|
||||
void cancel(uint32_t error_code = NGHTTP2_INTERNAL_ERROR) const;
|
||||
|
||||
// Resumes deferred uploading.
|
||||
void resume() const;
|
||||
|
||||
// Returns method (e.g., GET).
|
||||
const std::string &method() const;
|
||||
|
||||
// Returns request URI, split into components.
|
||||
const uri_ref &uri() const;
|
||||
|
||||
// Returns request header fields. The pusedo header fields, which
|
||||
// start with colon (:), are exluced from this list.
|
||||
const header_map &header() const;
|
||||
|
||||
// Application must not call this directly.
|
||||
request_impl &impl() const;
|
||||
|
||||
private:
|
||||
std::unique_ptr<request_impl> impl_;
|
||||
};
|
||||
|
||||
// Wrapper around an nghttp2_priority_spec.
|
||||
class priority_spec {
|
||||
public:
|
||||
// The default ctor is used only by sentinel values.
|
||||
priority_spec() = default;
|
||||
|
||||
// Create a priority spec with the given priority settings.
|
||||
explicit priority_spec(const int32_t stream_id, const int32_t weight,
|
||||
const bool exclusive = false);
|
||||
|
||||
// Return a pointer to a valid nghttp2 priority spec, or null.
|
||||
const nghttp2_priority_spec *get() const;
|
||||
|
||||
// Indicates whether or not this spec is valid (i.e. was constructed with
|
||||
// values).
|
||||
const bool valid() const;
|
||||
|
||||
private:
|
||||
nghttp2_priority_spec spec_;
|
||||
bool valid_ = false;
|
||||
};
|
||||
|
||||
class session_impl;
|
||||
|
||||
class session {
|
||||
public:
|
||||
// Starts HTTP/2 session by connecting to |host| and |service|
|
||||
// (e.g., "80") using clear text TCP connection with connect timeout
|
||||
// 60 seconds.
|
||||
session(boost::asio::io_service &io_service, const std::string &host,
|
||||
const std::string &service);
|
||||
|
||||
// Starts HTTP/2 session by connecting to |host| and |service|
|
||||
// (e.g., "80") using clear text TCP connection with given connect
|
||||
// timeout.
|
||||
session(boost::asio::io_service &io_service, const std::string &host,
|
||||
const std::string &service,
|
||||
const boost::posix_time::time_duration &connect_timeout);
|
||||
|
||||
// Starts HTTP/2 session by connecting to |host| and |service|
|
||||
// (e.g., "443") using encrypted SSL/TLS connection with connect
|
||||
// timeout 60 seconds.
|
||||
session(boost::asio::io_service &io_service,
|
||||
boost::asio::ssl::context &tls_context, const std::string &host,
|
||||
const std::string &service);
|
||||
|
||||
// Starts HTTP/2 session by connecting to |host| and |service|
|
||||
// (e.g., "443") using encrypted SSL/TLS connection with given
|
||||
// connect timeout.
|
||||
session(boost::asio::io_service &io_service,
|
||||
boost::asio::ssl::context &tls_context, const std::string &host,
|
||||
const std::string &service,
|
||||
const boost::posix_time::time_duration &connect_timeout);
|
||||
|
||||
~session();
|
||||
|
||||
session(session &&other) noexcept;
|
||||
session &operator=(session &&other) noexcept;
|
||||
|
||||
// Sets callback which is invoked after connection is established.
|
||||
void on_connect(connect_cb cb) const;
|
||||
|
||||
// Sets callback which is invoked there is connection level error
|
||||
// and session is terminated.
|
||||
void on_error(error_cb cb) const;
|
||||
|
||||
// Sets read timeout, which defaults to 60 seconds.
|
||||
void read_timeout(const boost::posix_time::time_duration &t);
|
||||
|
||||
// Shutdowns connection.
|
||||
void shutdown() const;
|
||||
|
||||
// Returns underlying io_service object.
|
||||
boost::asio::io_service &io_service() const;
|
||||
|
||||
// Submits request to server using |method| (e.g., "GET"), |uri|
|
||||
// (e.g., "http://localhost/") and optionally additional header
|
||||
// fields. This function returns pointer to request object if it
|
||||
// succeeds, or nullptr and |ec| contains error message.
|
||||
const request *submit(boost::system::error_code &ec,
|
||||
const std::string &method, const std::string &uri,
|
||||
header_map h = header_map{},
|
||||
priority_spec prio = priority_spec()) const;
|
||||
|
||||
// Submits request to server using |method| (e.g., "GET"), |uri|
|
||||
// (e.g., "http://localhost/") and optionally additional header
|
||||
// fields. The |data| is request body. This function returns
|
||||
// pointer to request object if it succeeds, or nullptr and |ec|
|
||||
// contains error message.
|
||||
const request *submit(boost::system::error_code &ec,
|
||||
const std::string &method, const std::string &uri,
|
||||
std::string data, header_map h = header_map{},
|
||||
priority_spec prio = priority_spec()) const;
|
||||
|
||||
// Submits request to server using |method| (e.g., "GET"), |uri|
|
||||
// (e.g., "http://localhost/") and optionally additional header
|
||||
// fields. The |cb| is used to generate request body. This
|
||||
// function returns pointer to request object if it succeeds, or
|
||||
// nullptr and |ec| contains error message.
|
||||
const request *submit(boost::system::error_code &ec,
|
||||
const std::string &method, const std::string &uri,
|
||||
generator_cb cb, header_map h = header_map{},
|
||||
priority_spec prio = priority_spec()) const;
|
||||
|
||||
private:
|
||||
std::shared_ptr<session_impl> impl_;
|
||||
};
|
||||
|
||||
// configure |tls_ctx| for client use. Currently, we just set NPN
|
||||
// callback for HTTP/2.
|
||||
boost::system::error_code
|
||||
configure_tls_context(boost::system::error_code &ec,
|
||||
boost::asio::ssl::context &tls_ctx);
|
||||
|
||||
} // namespace client
|
||||
|
||||
} // namespace asio_http2
|
||||
|
||||
} // namespace nghttp2
|
||||
|
||||
#endif // ASIO_HTTP2_CLIENT_H
|
242
tools/sdk/include/nghttp/nghttp2/asio_http2_server.h
Normal file
242
tools/sdk/include/nghttp/nghttp2/asio_http2_server.h
Normal file
@ -0,0 +1,242 @@
|
||||
/*
|
||||
* nghttp2 - HTTP/2 C Library
|
||||
*
|
||||
* Copyright (c) 2015 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef ASIO_HTTP2_SERVER_H
|
||||
#define ASIO_HTTP2_SERVER_H
|
||||
|
||||
#include <nghttp2/asio_http2.h>
|
||||
|
||||
namespace nghttp2 {
|
||||
|
||||
namespace asio_http2 {
|
||||
|
||||
namespace server {
|
||||
|
||||
class request_impl;
|
||||
class response_impl;
|
||||
|
||||
class request {
|
||||
public:
|
||||
// Application must not call this directly.
|
||||
request();
|
||||
~request();
|
||||
|
||||
// Returns request header fields. The pusedo header fields, which
|
||||
// start with colon (:), are exluced from this list.
|
||||
const header_map &header() const;
|
||||
|
||||
// Returns method (e.g., GET).
|
||||
const std::string &method() const;
|
||||
|
||||
// Returns request URI, split into components.
|
||||
const uri_ref &uri() const;
|
||||
|
||||
// Sets callback which is invoked when chunk of request body is
|
||||
// received.
|
||||
void on_data(data_cb cb) const;
|
||||
|
||||
// Application must not call this directly.
|
||||
request_impl &impl() const;
|
||||
|
||||
// Returns the remote endpoint of the request
|
||||
const boost::asio::ip::tcp::endpoint &remote_endpoint() const;
|
||||
|
||||
private:
|
||||
std::unique_ptr<request_impl> impl_;
|
||||
};
|
||||
|
||||
class response {
|
||||
public:
|
||||
// Application must not call this directly.
|
||||
response();
|
||||
~response();
|
||||
|
||||
// Write response header using |status_code| (e.g., 200) and
|
||||
// additional header fields in |h|.
|
||||
void write_head(unsigned int status_code, header_map h = header_map{}) const;
|
||||
|
||||
// Sends |data| as request body. No further call of end() is
|
||||
// allowed.
|
||||
void end(std::string data = "") const;
|
||||
|
||||
// Sets callback as a generator of the response body. No further
|
||||
// call of end() is allowed.
|
||||
void end(generator_cb cb) const;
|
||||
|
||||
// Write trailer part. This must be called after setting both
|
||||
// NGHTTP2_DATA_FLAG_EOF and NGHTTP2_DATA_FLAG_NO_END_STREAM set in
|
||||
// *data_flag parameter in generator_cb passed to end() function.
|
||||
void write_trailer(header_map h) const;
|
||||
|
||||
// Sets callback which is invoked when this request and response are
|
||||
// finished. After the invocation of this callback, the application
|
||||
// must not access request and response object.
|
||||
void on_close(close_cb cb) const;
|
||||
|
||||
// Cancels this request and response with given error code.
|
||||
void cancel(uint32_t error_code = NGHTTP2_INTERNAL_ERROR) const;
|
||||
|
||||
// Resumes deferred response.
|
||||
void resume() const;
|
||||
|
||||
// Pushes resource denoted by |raw_path_query| using |method|. The
|
||||
// additional header fields can be given in |h|. This function
|
||||
// returns pointer to response object for promised stream, otherwise
|
||||
// nullptr and error code is filled in |ec|. Be aware that the
|
||||
// header field name given in |h| must be lower-cased.
|
||||
const response *push(boost::system::error_code &ec, std::string method,
|
||||
std::string raw_path_query,
|
||||
header_map h = header_map{}) const;
|
||||
|
||||
// Returns status code.
|
||||
unsigned int status_code() const;
|
||||
|
||||
// Returns boost::asio::io_service this response is running on.
|
||||
boost::asio::io_service &io_service() const;
|
||||
|
||||
// Application must not call this directly.
|
||||
response_impl &impl() const;
|
||||
|
||||
private:
|
||||
std::unique_ptr<response_impl> impl_;
|
||||
};
|
||||
|
||||
// This is so called request callback. Called every time request is
|
||||
// received. The life time of |request| and |response| objects end
|
||||
// when callback set by response::on_close() is called. After that,
|
||||
// the application must not access to those objects.
|
||||
typedef std::function<void(const request &, const response &)> request_cb;
|
||||
|
||||
class http2_impl;
|
||||
|
||||
class http2 {
|
||||
public:
|
||||
http2();
|
||||
~http2();
|
||||
|
||||
http2(http2 &&other) noexcept;
|
||||
http2 &operator=(http2 &&other) noexcept;
|
||||
|
||||
// Starts listening connection on given address and port and serves
|
||||
// incoming requests in cleartext TCP connection. If |asynchronous|
|
||||
// is false, this function blocks forever unless there is an error.
|
||||
// If it is true, after server has started, this function returns
|
||||
// immediately, and the caller should call join() to shutdown server
|
||||
// gracefully.
|
||||
boost::system::error_code listen_and_serve(boost::system::error_code &ec,
|
||||
const std::string &address,
|
||||
const std::string &port,
|
||||
bool asynchronous = false);
|
||||
|
||||
// Starts listening connection on given address and port and serves
|
||||
// incoming requests in SSL/TLS encrypted connection. For
|
||||
// |asynchronous| parameter, see cleartext version
|
||||
// |listen_and_serve|.
|
||||
boost::system::error_code
|
||||
listen_and_serve(boost::system::error_code &ec,
|
||||
boost::asio::ssl::context &tls_context,
|
||||
const std::string &address, const std::string &port,
|
||||
bool asynchronous = false);
|
||||
|
||||
// Registers request handler |cb| with path pattern |pattern|. This
|
||||
// function will fail and returns false if same pattern has been
|
||||
// already registered or |pattern| is empty string. Otherwise
|
||||
// returns true. The pattern match rule is the same as
|
||||
// net/http/ServeMux in golang. Quoted from golang manual
|
||||
// (http://golang.org/pkg/net/http/#ServeMux):
|
||||
//
|
||||
// Patterns name fixed, rooted paths, like "/favicon.ico", or
|
||||
// rooted subtrees, like "/images/" (note the trailing
|
||||
// slash). Longer patterns take precedence over shorter ones, so
|
||||
// that if there are handlers registered for both "/images/" and
|
||||
// "/images/thumbnails/", the latter handler will be called for
|
||||
// paths beginning "/images/thumbnails/" and the former will
|
||||
// receive requests for any other paths in the "/images/" subtree.
|
||||
//
|
||||
// Note that since a pattern ending in a slash names a rooted
|
||||
// subtree, the pattern "/" matches all paths not matched by other
|
||||
// registered patterns, not just the URL with Path == "/".
|
||||
//
|
||||
// Patterns may optionally begin with a host name, restricting
|
||||
// matches to URLs on that host only. Host-specific patterns take
|
||||
// precedence over general patterns, so that a handler might
|
||||
// register for the two patterns "/codesearch" and
|
||||
// "codesearch.google.com/" without also taking over requests for
|
||||
// "http://www.google.com/".
|
||||
//
|
||||
// Just like ServeMux in golang, URL request path is sanitized and
|
||||
// if they contains . or .. elements, they are redirected to an
|
||||
// equivalent .- and ..-free URL.
|
||||
bool handle(std::string pattern, request_cb cb);
|
||||
|
||||
// Sets number of native threads to handle incoming HTTP request.
|
||||
// It defaults to 1.
|
||||
void num_threads(size_t num_threads);
|
||||
|
||||
// Sets the maximum length to which the queue of pending
|
||||
// connections.
|
||||
void backlog(int backlog);
|
||||
|
||||
// Sets TLS handshake timeout, which defaults to 60 seconds.
|
||||
void tls_handshake_timeout(const boost::posix_time::time_duration &t);
|
||||
|
||||
// Sets read timeout, which defaults to 60 seconds.
|
||||
void read_timeout(const boost::posix_time::time_duration &t);
|
||||
|
||||
// Gracefully stop http2 server
|
||||
void stop();
|
||||
|
||||
// Join on http2 server and wait for it to fully stop
|
||||
void join();
|
||||
|
||||
// Get access to the io_service objects.
|
||||
const std::vector<std::shared_ptr<boost::asio::io_service>> &
|
||||
io_services() const;
|
||||
|
||||
private:
|
||||
std::unique_ptr<http2_impl> impl_;
|
||||
};
|
||||
|
||||
// Configures |tls_context| for server use. This function sets couple
|
||||
// of OpenSSL options (disables SSLv2 and SSLv3 and compression) and
|
||||
// enables ECDHE ciphers. NPN callback is also configured.
|
||||
boost::system::error_code
|
||||
configure_tls_context_easy(boost::system::error_code &ec,
|
||||
boost::asio::ssl::context &tls_context);
|
||||
|
||||
// Returns request handler to do redirect to |uri| using
|
||||
// |status_code|. The |uri| appears in "location" header field as is.
|
||||
request_cb redirect_handler(int status_code, std::string uri);
|
||||
|
||||
// Returns request handler to reply with given |status_code| and HTML
|
||||
// including message about status code.
|
||||
request_cb status_handler(int status_code);
|
||||
|
||||
} // namespace server
|
||||
|
||||
} // namespace asio_http2
|
||||
|
||||
} // namespace nghttp2
|
||||
|
||||
#endif // ASIO_HTTP2_SERVER_H
|
File diff suppressed because it is too large
Load Diff
@ -29,7 +29,7 @@
|
||||
* @macro
|
||||
* Version number of the nghttp2 library release
|
||||
*/
|
||||
#define NGHTTP2_VERSION "@PACKAGE_VERSION@"
|
||||
#define NGHTTP2_VERSION "v1.22.0"
|
||||
|
||||
/**
|
||||
* @macro
|
||||
@ -37,6 +37,6 @@
|
||||
* release. This is a 24 bit number with 8 bits for major number, 8 bits
|
||||
* for minor and 8 bits for patch. Version 1.2.3 becomes 0x010203.
|
||||
*/
|
||||
#define NGHTTP2_VERSION_NUM 0x010203
|
||||
#define NGHTTP2_VERSION_NUM 0x012200
|
||||
|
||||
#endif /* NGHTTP2VER_H */
|
||||
|
@ -1,388 +0,0 @@
|
||||
/*
|
||||
* nghttp2 - HTTP/2 C Library
|
||||
*
|
||||
* Copyright (c) 2014 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef NGHTTP2_BUF_H
|
||||
#define NGHTTP2_BUF_H
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif /* HAVE_CONFIG_H */
|
||||
|
||||
#include <nghttp2/nghttp2.h>
|
||||
|
||||
#include "nghttp2_int.h"
|
||||
#include "nghttp2_mem.h"
|
||||
|
||||
typedef struct {
|
||||
/* This points to the beginning of the buffer. The effective range
|
||||
of buffer is [begin, end). */
|
||||
uint8_t *begin;
|
||||
/* This points to the memory one byte beyond the end of the
|
||||
buffer. */
|
||||
uint8_t *end;
|
||||
/* The position indicator for effective start of the buffer. pos <=
|
||||
last must be hold. */
|
||||
uint8_t *pos;
|
||||
/* The position indicator for effective one beyond of the end of the
|
||||
buffer. last <= end must be hold. */
|
||||
uint8_t *last;
|
||||
/* Mark arbitrary position in buffer [begin, end) */
|
||||
uint8_t *mark;
|
||||
} nghttp2_buf;
|
||||
|
||||
#define nghttp2_buf_len(BUF) ((size_t)((BUF)->last - (BUF)->pos))
|
||||
#define nghttp2_buf_avail(BUF) ((size_t)((BUF)->end - (BUF)->last))
|
||||
#define nghttp2_buf_mark_avail(BUF) ((size_t)((BUF)->mark - (BUF)->last))
|
||||
#define nghttp2_buf_cap(BUF) ((size_t)((BUF)->end - (BUF)->begin))
|
||||
|
||||
#define nghttp2_buf_pos_offset(BUF) ((size_t)((BUF)->pos - (BUF)->begin))
|
||||
#define nghttp2_buf_last_offset(BUF) ((size_t)((BUF)->last - (BUF)->begin))
|
||||
|
||||
#define nghttp2_buf_shift_right(BUF, AMT) \
|
||||
do { \
|
||||
(BUF)->pos += AMT; \
|
||||
(BUF)->last += AMT; \
|
||||
} while (0)
|
||||
|
||||
#define nghttp2_buf_shift_left(BUF, AMT) \
|
||||
do { \
|
||||
(BUF)->pos -= AMT; \
|
||||
(BUF)->last -= AMT; \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* Initializes the |buf|. No memory is allocated in this function. Use
|
||||
* nghttp2_buf_reserve() to allocate memory.
|
||||
*/
|
||||
void nghttp2_buf_init(nghttp2_buf *buf);
|
||||
|
||||
/*
|
||||
* Initializes the |buf| and allocates at least |initial| bytes of
|
||||
* memory.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* NGHTTP2_ERR_NOMEM
|
||||
* Out of memory
|
||||
*/
|
||||
int nghttp2_buf_init2(nghttp2_buf *buf, size_t initial, nghttp2_mem *mem);
|
||||
|
||||
/*
|
||||
* Frees buffer in |buf|.
|
||||
*/
|
||||
void nghttp2_buf_free(nghttp2_buf *buf, nghttp2_mem *mem);
|
||||
|
||||
/*
|
||||
* Extends buffer so that nghttp2_buf_cap() returns at least
|
||||
* |new_cap|. If extensions took place, buffer pointers in |buf| will
|
||||
* change.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or one of the followings
|
||||
* negative error codes:
|
||||
*
|
||||
* NGHTTP2_ERR_NOMEM
|
||||
* Out of memory
|
||||
*/
|
||||
int nghttp2_buf_reserve(nghttp2_buf *buf, size_t new_cap, nghttp2_mem *mem);
|
||||
|
||||
/*
|
||||
* Resets pos, last, mark member of |buf| to buf->begin.
|
||||
*/
|
||||
void nghttp2_buf_reset(nghttp2_buf *buf);
|
||||
|
||||
/*
|
||||
* Initializes |buf| using supplied buffer |begin| of length
|
||||
* |len|. Semantically, the application should not call *_reserve() or
|
||||
* nghttp2_free() functions for |buf|.
|
||||
*/
|
||||
void nghttp2_buf_wrap_init(nghttp2_buf *buf, uint8_t *begin, size_t len);
|
||||
|
||||
struct nghttp2_buf_chain;
|
||||
|
||||
typedef struct nghttp2_buf_chain nghttp2_buf_chain;
|
||||
|
||||
/* Chains 2 buffers */
|
||||
struct nghttp2_buf_chain {
|
||||
/* Points to the subsequent buffer. NULL if there is no such
|
||||
buffer. */
|
||||
nghttp2_buf_chain *next;
|
||||
nghttp2_buf buf;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
/* Points to the first buffer */
|
||||
nghttp2_buf_chain *head;
|
||||
/* Buffer pointer where write occurs. */
|
||||
nghttp2_buf_chain *cur;
|
||||
/* Memory allocator */
|
||||
nghttp2_mem *mem;
|
||||
/* The buffer capacity of each buf */
|
||||
size_t chunk_length;
|
||||
/* The maximum number of nghttp2_buf_chain */
|
||||
size_t max_chunk;
|
||||
/* The number of nghttp2_buf_chain allocated */
|
||||
size_t chunk_used;
|
||||
/* The number of nghttp2_buf_chain to keep on reset */
|
||||
size_t chunk_keep;
|
||||
/* pos offset from begin in each buffers. On initialization and
|
||||
reset, buf->pos and buf->last are positioned at buf->begin +
|
||||
offset. */
|
||||
size_t offset;
|
||||
} nghttp2_bufs;
|
||||
|
||||
/*
|
||||
* This is the same as calling nghttp2_bufs_init2 with the given
|
||||
* arguments and offset = 0.
|
||||
*/
|
||||
int nghttp2_bufs_init(nghttp2_bufs *bufs, size_t chunk_length, size_t max_chunk,
|
||||
nghttp2_mem *mem);
|
||||
|
||||
/*
|
||||
* This is the same as calling nghttp2_bufs_init3 with the given
|
||||
* arguments and chunk_keep = max_chunk.
|
||||
*/
|
||||
int nghttp2_bufs_init2(nghttp2_bufs *bufs, size_t chunk_length,
|
||||
size_t max_chunk, size_t offset, nghttp2_mem *mem);
|
||||
|
||||
/*
|
||||
* Initializes |bufs|. Each buffer size is given in the
|
||||
* |chunk_length|. The maximum number of buffers is given in the
|
||||
* |max_chunk|. On reset, first |chunk_keep| buffers are kept and
|
||||
* remaining buffers are deleted. Each buffer will have bufs->pos and
|
||||
* bufs->last shifted to left by |offset| bytes on creation and reset.
|
||||
*
|
||||
* This function allocates first buffer. bufs->head and bufs->cur
|
||||
* will point to the first buffer after this call.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* NGHTTP2_ERR_NOMEM
|
||||
* Out of memory.
|
||||
* NGHTTP2_ERR_INVALID_ARGUMENT
|
||||
* chunk_keep is 0; or max_chunk < chunk_keep; or offset is too
|
||||
* long.
|
||||
*/
|
||||
int nghttp2_bufs_init3(nghttp2_bufs *bufs, size_t chunk_length,
|
||||
size_t max_chunk, size_t chunk_keep, size_t offset,
|
||||
nghttp2_mem *mem);
|
||||
|
||||
/*
|
||||
* Frees any related resources to the |bufs|.
|
||||
*/
|
||||
void nghttp2_bufs_free(nghttp2_bufs *bufs);
|
||||
|
||||
/*
|
||||
* Initializes |bufs| using supplied buffer |begin| of length |len|.
|
||||
* The first buffer bufs->head uses buffer |begin|. The buffer size
|
||||
* is fixed and no allocate extra chunk buffer is allocated. In other
|
||||
* words, max_chunk = chunk_keep = 1. To free the resource allocated
|
||||
* for |bufs|, use nghttp2_bufs_wrap_free().
|
||||
*
|
||||
* This function returns 0 if it succeeds, or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* NGHTTP2_ERR_NOMEM
|
||||
* Out of memory.
|
||||
*/
|
||||
int nghttp2_bufs_wrap_init(nghttp2_bufs *bufs, uint8_t *begin, size_t len,
|
||||
nghttp2_mem *mem);
|
||||
|
||||
/*
|
||||
* Frees any related resource to the |bufs|. This function does not
|
||||
* free supplied buffer provided in nghttp2_bufs_wrap_init().
|
||||
*/
|
||||
void nghttp2_bufs_wrap_free(nghttp2_bufs *bufs);
|
||||
|
||||
/*
|
||||
* Reallocates internal buffer using |chunk_length|. The max_chunk,
|
||||
* chunk_keep and offset do not change. After successful allocation
|
||||
* of new buffer, previous buffers are deallocated without copying
|
||||
* anything into new buffers. chunk_used is reset to 1.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* NGHTTP2_ERR_NOMEM
|
||||
* Out of memory.
|
||||
* NGHTTP2_ERR_INVALID_ARGUMENT
|
||||
* chunk_length < offset
|
||||
*/
|
||||
int nghttp2_bufs_realloc(nghttp2_bufs *bufs, size_t chunk_length);
|
||||
|
||||
/*
|
||||
* Appends the |data| of length |len| to the |bufs|. The write starts
|
||||
* at bufs->cur->buf.last. A new buffers will be allocated to store
|
||||
* all data.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* NGHTTP2_ERR_NOMEM
|
||||
* Out of memory.
|
||||
* NGHTTP2_ERR_BUFFER_ERROR
|
||||
* Out of buffer space.
|
||||
*/
|
||||
int nghttp2_bufs_add(nghttp2_bufs *bufs, const void *data, size_t len);
|
||||
|
||||
/*
|
||||
* Appends a single byte |b| to the |bufs|. The write starts at
|
||||
* bufs->cur->buf.last. A new buffers will be allocated to store all
|
||||
* data.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* NGHTTP2_ERR_NOMEM
|
||||
* Out of memory.
|
||||
* NGHTTP2_ERR_BUFFER_ERROR
|
||||
* Out of buffer space.
|
||||
*/
|
||||
int nghttp2_bufs_addb(nghttp2_bufs *bufs, uint8_t b);
|
||||
|
||||
/*
|
||||
* Behaves like nghttp2_bufs_addb(), but this does not update
|
||||
* buf->last pointer.
|
||||
*/
|
||||
int nghttp2_bufs_addb_hold(nghttp2_bufs *bufs, uint8_t b);
|
||||
|
||||
#define nghttp2_bufs_fast_addb(BUFS, B) \
|
||||
do { \
|
||||
*(BUFS)->cur->buf.last++ = B; \
|
||||
} while (0)
|
||||
|
||||
#define nghttp2_bufs_fast_addb_hold(BUFS, B) \
|
||||
do { \
|
||||
*(BUFS)->cur->buf.last = B; \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* Performs bitwise-OR of |b| at bufs->cur->buf.last. A new buffers
|
||||
* will be allocated if necessary.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* NGHTTP2_ERR_NOMEM
|
||||
* Out of memory.
|
||||
* NGHTTP2_ERR_BUFFER_ERROR
|
||||
* Out of buffer space.
|
||||
*/
|
||||
int nghttp2_bufs_orb(nghttp2_bufs *bufs, uint8_t b);
|
||||
|
||||
/*
|
||||
* Behaves like nghttp2_bufs_orb(), but does not update buf->last
|
||||
* pointer.
|
||||
*/
|
||||
int nghttp2_bufs_orb_hold(nghttp2_bufs *bufs, uint8_t b);
|
||||
|
||||
#define nghttp2_bufs_fast_orb(BUFS, B) \
|
||||
do { \
|
||||
uint8_t **p = &(BUFS)->cur->buf.last; \
|
||||
**p = (uint8_t)(**p | (B)); \
|
||||
++(*p); \
|
||||
} while (0)
|
||||
|
||||
#define nghttp2_bufs_fast_orb_hold(BUFS, B) \
|
||||
do { \
|
||||
uint8_t *p = (BUFS)->cur->buf.last; \
|
||||
*p = (uint8_t)(*p | (B)); \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* Copies all data stored in |bufs| to the contiguous buffer. This
|
||||
* function allocates the contiguous memory to store all data in
|
||||
* |bufs| and assigns it to |*out|.
|
||||
*
|
||||
* The contents of |bufs| is left unchanged.
|
||||
*
|
||||
* This function returns the length of copied data and assigns the
|
||||
* pointer to copied data to |*out| if it succeeds, or one of the
|
||||
* following negative error codes:
|
||||
*
|
||||
* NGHTTP2_ERR_NOMEM
|
||||
* Out of memory
|
||||
*/
|
||||
ssize_t nghttp2_bufs_remove(nghttp2_bufs *bufs, uint8_t **out);
|
||||
|
||||
/*
|
||||
* Copies all data stored in |bufs| to |out|. This function assumes
|
||||
* that the buffer space pointed by |out| has at least
|
||||
* nghttp2_bufs(bufs) bytes.
|
||||
*
|
||||
* The contents of |bufs| is left unchanged.
|
||||
*
|
||||
* This function returns the length of copied data.
|
||||
*/
|
||||
size_t nghttp2_bufs_remove_copy(nghttp2_bufs *bufs, uint8_t *out);
|
||||
|
||||
/*
|
||||
* Resets |bufs| and makes the buffers empty.
|
||||
*/
|
||||
void nghttp2_bufs_reset(nghttp2_bufs *bufs);
|
||||
|
||||
/*
|
||||
* Moves bufs->cur to bufs->cur->next. If resulting bufs->cur is
|
||||
* NULL, this function allocates new buffers and bufs->cur points to
|
||||
* it.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* NGHTTP2_ERR_NOMEM
|
||||
* Out of memory
|
||||
* NGHTTP2_ERR_BUFFER_ERROR
|
||||
* Out of buffer space.
|
||||
*/
|
||||
int nghttp2_bufs_advance(nghttp2_bufs *bufs);
|
||||
|
||||
/* Sets bufs->cur to bufs->head */
|
||||
#define nghttp2_bufs_rewind(BUFS) \
|
||||
do { \
|
||||
(BUFS)->cur = (BUFS)->head; \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* Move bufs->cur, from the current position, using next member, to
|
||||
* the last buf which has nghttp2_buf_len(buf) > 0 without seeing buf
|
||||
* which satisfies nghttp2_buf_len(buf) == 0. If
|
||||
* nghttp2_buf_len(&bufs->cur->buf) == 0 or bufs->cur->next is NULL,
|
||||
* bufs->cur is unchanged.
|
||||
*/
|
||||
void nghttp2_bufs_seek_last_present(nghttp2_bufs *bufs);
|
||||
|
||||
/*
|
||||
* Returns nonzero if bufs->cur->next is not emtpy.
|
||||
*/
|
||||
int nghttp2_bufs_next_present(nghttp2_bufs *bufs);
|
||||
|
||||
#define nghttp2_bufs_cur_avail(BUFS) nghttp2_buf_avail(&(BUFS)->cur->buf)
|
||||
|
||||
/*
|
||||
* Returns the buffer length of |bufs|.
|
||||
*/
|
||||
size_t nghttp2_bufs_len(nghttp2_bufs *bufs);
|
||||
|
||||
#endif /* NGHTTP2_BUF_H */
|
@ -1,117 +0,0 @@
|
||||
/*
|
||||
* nghttp2 - HTTP/2 C Library
|
||||
*
|
||||
* Copyright (c) 2014 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef NGHTTP2_CALLBACKS_H
|
||||
#define NGHTTP2_CALLBACKS_H
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif /* HAVE_CONFIG_H */
|
||||
|
||||
#include <nghttp2/nghttp2.h>
|
||||
|
||||
/*
|
||||
* Callback functions.
|
||||
*/
|
||||
struct nghttp2_session_callbacks {
|
||||
/**
|
||||
* Callback function invoked when the session wants to send data to
|
||||
* the remote peer. This callback is not necessary if the
|
||||
* application uses solely `nghttp2_session_mem_send()` to serialize
|
||||
* data to transmit.
|
||||
*/
|
||||
nghttp2_send_callback send_callback;
|
||||
/**
|
||||
* Callback function invoked when the session wants to receive data
|
||||
* from the remote peer. This callback is not necessary if the
|
||||
* application uses solely `nghttp2_session_mem_recv()` to process
|
||||
* received data.
|
||||
*/
|
||||
nghttp2_recv_callback recv_callback;
|
||||
/**
|
||||
* Callback function invoked by `nghttp2_session_recv()` when a
|
||||
* frame is received.
|
||||
*/
|
||||
nghttp2_on_frame_recv_callback on_frame_recv_callback;
|
||||
/**
|
||||
* Callback function invoked by `nghttp2_session_recv()` when an
|
||||
* invalid non-DATA frame is received.
|
||||
*/
|
||||
nghttp2_on_invalid_frame_recv_callback on_invalid_frame_recv_callback;
|
||||
/**
|
||||
* Callback function invoked when a chunk of data in DATA frame is
|
||||
* received.
|
||||
*/
|
||||
nghttp2_on_data_chunk_recv_callback on_data_chunk_recv_callback;
|
||||
/**
|
||||
* Callback function invoked before a non-DATA frame is sent.
|
||||
*/
|
||||
nghttp2_before_frame_send_callback before_frame_send_callback;
|
||||
/**
|
||||
* Callback function invoked after a frame is sent.
|
||||
*/
|
||||
nghttp2_on_frame_send_callback on_frame_send_callback;
|
||||
/**
|
||||
* The callback function invoked when a non-DATA frame is not sent
|
||||
* because of an error.
|
||||
*/
|
||||
nghttp2_on_frame_not_send_callback on_frame_not_send_callback;
|
||||
/**
|
||||
* Callback function invoked when the stream is closed.
|
||||
*/
|
||||
nghttp2_on_stream_close_callback on_stream_close_callback;
|
||||
/**
|
||||
* Callback function invoked when the reception of header block in
|
||||
* HEADERS or PUSH_PROMISE is started.
|
||||
*/
|
||||
nghttp2_on_begin_headers_callback on_begin_headers_callback;
|
||||
/**
|
||||
* Callback function invoked when a header name/value pair is
|
||||
* received.
|
||||
*/
|
||||
nghttp2_on_header_callback on_header_callback;
|
||||
nghttp2_on_header_callback2 on_header_callback2;
|
||||
/**
|
||||
* Callback function invoked when the library asks application how
|
||||
* many padding bytes are required for the transmission of the given
|
||||
* frame.
|
||||
*/
|
||||
nghttp2_select_padding_callback select_padding_callback;
|
||||
/**
|
||||
* The callback function used to determine the length allowed in
|
||||
* `nghttp2_data_source_read_callback()`
|
||||
*/
|
||||
nghttp2_data_source_read_length_callback read_length_callback;
|
||||
/**
|
||||
* Sets callback function invoked when a frame header is received.
|
||||
*/
|
||||
nghttp2_on_begin_frame_callback on_begin_frame_callback;
|
||||
nghttp2_send_data_callback send_data_callback;
|
||||
nghttp2_pack_extension_callback pack_extension_callback;
|
||||
nghttp2_unpack_extension_callback unpack_extension_callback;
|
||||
nghttp2_on_extension_chunk_recv_callback on_extension_chunk_recv_callback;
|
||||
nghttp2_error_callback error_callback;
|
||||
};
|
||||
|
||||
#endif /* NGHTTP2_CALLBACKS_H */
|
@ -1,581 +0,0 @@
|
||||
/*
|
||||
* nghttp2 - HTTP/2 C Library
|
||||
*
|
||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef NGHTTP2_FRAME_H
|
||||
#define NGHTTP2_FRAME_H
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif /* HAVE_CONFIG_H */
|
||||
|
||||
#include <nghttp2/nghttp2.h>
|
||||
#include "nghttp2_hd.h"
|
||||
#include "nghttp2_buf.h"
|
||||
|
||||
#define NGHTTP2_STREAM_ID_MASK ((1u << 31) - 1)
|
||||
#define NGHTTP2_PRI_GROUP_ID_MASK ((1u << 31) - 1)
|
||||
#define NGHTTP2_PRIORITY_MASK ((1u << 31) - 1)
|
||||
#define NGHTTP2_WINDOW_SIZE_INCREMENT_MASK ((1u << 31) - 1)
|
||||
#define NGHTTP2_SETTINGS_ID_MASK ((1 << 24) - 1)
|
||||
|
||||
/* The number of bytes of frame header. */
|
||||
#define NGHTTP2_FRAME_HDLEN 9
|
||||
|
||||
#define NGHTTP2_MAX_FRAME_SIZE_MAX ((1 << 24) - 1)
|
||||
#define NGHTTP2_MAX_FRAME_SIZE_MIN (1 << 14)
|
||||
|
||||
#define NGHTTP2_MAX_PAYLOADLEN 8192//16384--LiuHan/0812
|
||||
/* The one frame buffer length for tranmission. We may use several of
|
||||
them to support CONTINUATION. To account for Pad Length field, we
|
||||
allocate extra 1 byte, which saves extra large memcopying. */
|
||||
#define NGHTTP2_FRAMEBUF_CHUNKLEN \
|
||||
(NGHTTP2_FRAME_HDLEN + 1 + NGHTTP2_MAX_PAYLOADLEN)
|
||||
|
||||
/* The default length of DATA frame payload. */
|
||||
#define NGHTTP2_DATA_PAYLOADLEN NGHTTP2_MAX_FRAME_SIZE_MIN
|
||||
|
||||
/* Maximum headers block size to send, calculated using
|
||||
nghttp2_hd_deflate_bound(). This is the default value, and can be
|
||||
overridden by nghttp2_option_set_max_send_header_block_size(). */
|
||||
#define NGHTTP2_MAX_HEADERSLEN 65536
|
||||
|
||||
/* The number of bytes for each SETTINGS entry */
|
||||
#define NGHTTP2_FRAME_SETTINGS_ENTRY_LENGTH 6
|
||||
|
||||
/* Length of priority related fields in HEADERS/PRIORITY frames */
|
||||
#define NGHTTP2_PRIORITY_SPECLEN 5
|
||||
|
||||
/* Maximum length of padding in bytes. */
|
||||
#define NGHTTP2_MAX_PADLEN 256
|
||||
|
||||
/* Union of extension frame payload */
|
||||
typedef union { nghttp2_ext_altsvc altsvc; } nghttp2_ext_frame_payload;
|
||||
|
||||
void nghttp2_frame_pack_frame_hd(uint8_t *buf, const nghttp2_frame_hd *hd);
|
||||
|
||||
void nghttp2_frame_unpack_frame_hd(nghttp2_frame_hd *hd, const uint8_t *buf);
|
||||
|
||||
/**
|
||||
* Initializes frame header |hd| with given parameters. Reserved bit
|
||||
* is set to 0.
|
||||
*/
|
||||
void nghttp2_frame_hd_init(nghttp2_frame_hd *hd, size_t length, uint8_t type,
|
||||
uint8_t flags, int32_t stream_id);
|
||||
|
||||
/**
|
||||
* Returns the number of priority field depending on the |flags|. If
|
||||
* |flags| has neither NGHTTP2_FLAG_PRIORITY_GROUP nor
|
||||
* NGHTTP2_FLAG_PRIORITY_DEPENDENCY set, return 0.
|
||||
*/
|
||||
size_t nghttp2_frame_priority_len(uint8_t flags);
|
||||
|
||||
/**
|
||||
* Packs the |pri_spec| in |buf|. This function assumes |buf| has
|
||||
* enough space for serialization.
|
||||
*/
|
||||
void nghttp2_frame_pack_priority_spec(uint8_t *buf,
|
||||
const nghttp2_priority_spec *pri_spec);
|
||||
|
||||
/**
|
||||
* Unpacks the priority specification from payload |payload| of length
|
||||
* |payloadlen| to |pri_spec|. The |flags| is used to determine what
|
||||
* kind of priority specification is in |payload|. This function
|
||||
* assumes the |payload| contains whole priority specification.
|
||||
*/
|
||||
void nghttp2_frame_unpack_priority_spec(nghttp2_priority_spec *pri_spec,
|
||||
uint8_t flags, const uint8_t *payload,
|
||||
size_t payloadlen);
|
||||
|
||||
/*
|
||||
* Returns the offset from the HEADERS frame payload where the
|
||||
* compressed header block starts. The frame payload does not include
|
||||
* frame header.
|
||||
*/
|
||||
size_t nghttp2_frame_headers_payload_nv_offset(nghttp2_headers *frame);
|
||||
|
||||
/*
|
||||
* Packs HEADERS frame |frame| in wire format and store it in |bufs|.
|
||||
* This function expands |bufs| as necessary to store frame.
|
||||
*
|
||||
* The caller must make sure that nghttp2_bufs_reset(bufs) is called
|
||||
* before calling this function.
|
||||
*
|
||||
* frame->hd.length is assigned after length is determined during
|
||||
* packing process. CONTINUATION frames are also serialized in this
|
||||
* function. This function does not handle padding.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or returns one of the
|
||||
* following negative error codes:
|
||||
*
|
||||
* NGHTTP2_ERR_HEADER_COMP
|
||||
* The deflate operation failed.
|
||||
* NGHTTP2_ERR_NOMEM
|
||||
* Out of memory.
|
||||
*/
|
||||
int nghttp2_frame_pack_headers(nghttp2_bufs *bufs, nghttp2_headers *frame,
|
||||
nghttp2_hd_deflater *deflater);
|
||||
|
||||
/*
|
||||
* Unpacks HEADERS frame byte sequence into |frame|. This function
|
||||
* only unapcks bytes that come before name/value header block and
|
||||
* after possible Pad Length field.
|
||||
*
|
||||
* This function always succeeds and returns 0.
|
||||
*/
|
||||
int nghttp2_frame_unpack_headers_payload(nghttp2_headers *frame,
|
||||
const uint8_t *payload,
|
||||
size_t payloadlen);
|
||||
|
||||
/*
|
||||
* Packs PRIORITY frame |frame| in wire format and store it in
|
||||
* |bufs|.
|
||||
*
|
||||
* The caller must make sure that nghttp2_bufs_reset(bufs) is called
|
||||
* before calling this function.
|
||||
*
|
||||
* This function always succeeds and returns 0.
|
||||
*/
|
||||
int nghttp2_frame_pack_priority(nghttp2_bufs *bufs, nghttp2_priority *frame);
|
||||
|
||||
/*
|
||||
* Unpacks PRIORITY wire format into |frame|.
|
||||
*/
|
||||
void nghttp2_frame_unpack_priority_payload(nghttp2_priority *frame,
|
||||
const uint8_t *payload,
|
||||
size_t payloadlen);
|
||||
|
||||
/*
|
||||
* Packs RST_STREAM frame |frame| in wire frame format and store it in
|
||||
* |bufs|.
|
||||
*
|
||||
* The caller must make sure that nghttp2_bufs_reset(bufs) is called
|
||||
* before calling this function.
|
||||
*
|
||||
* This function always succeeds and returns 0.
|
||||
*/
|
||||
int nghttp2_frame_pack_rst_stream(nghttp2_bufs *bufs,
|
||||
nghttp2_rst_stream *frame);
|
||||
|
||||
/*
|
||||
* Unpacks RST_STREAM frame byte sequence into |frame|.
|
||||
*/
|
||||
void nghttp2_frame_unpack_rst_stream_payload(nghttp2_rst_stream *frame,
|
||||
const uint8_t *payload,
|
||||
size_t payloadlen);
|
||||
|
||||
/*
|
||||
* Packs SETTINGS frame |frame| in wire format and store it in
|
||||
* |bufs|.
|
||||
*
|
||||
* The caller must make sure that nghttp2_bufs_reset(bufs) is called
|
||||
* before calling this function.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or returns one of the
|
||||
* following negative error codes:
|
||||
*
|
||||
* NGHTTP2_ERR_FRAME_SIZE_ERROR
|
||||
* The length of the frame is too large.
|
||||
*/
|
||||
int nghttp2_frame_pack_settings(nghttp2_bufs *bufs, nghttp2_settings *frame);
|
||||
|
||||
/*
|
||||
* Packs the |iv|, which includes |niv| entries, in the |buf|,
|
||||
* assuming the |buf| has at least 8 * |niv| bytes.
|
||||
*
|
||||
* Returns the number of bytes written into the |buf|.
|
||||
*/
|
||||
size_t nghttp2_frame_pack_settings_payload(uint8_t *buf,
|
||||
const nghttp2_settings_entry *iv,
|
||||
size_t niv);
|
||||
|
||||
void nghttp2_frame_unpack_settings_entry(nghttp2_settings_entry *iv,
|
||||
const uint8_t *payload);
|
||||
|
||||
/*
|
||||
* Initializes payload of frame->settings. The |frame| takes
|
||||
* ownership of |iv|.
|
||||
*/
|
||||
void nghttp2_frame_unpack_settings_payload(nghttp2_settings *frame,
|
||||
nghttp2_settings_entry *iv,
|
||||
size_t niv);
|
||||
|
||||
/*
|
||||
* Unpacks SETTINGS payload into |*iv_ptr|. The number of entries are
|
||||
* assigned to the |*niv_ptr|. This function allocates enough memory
|
||||
* to store the result in |*iv_ptr|. The caller is responsible to free
|
||||
* |*iv_ptr| after its use.
|
||||
*
|
||||
* This function returns 0 if it succeeds or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* NGHTTP2_ERR_NOMEM
|
||||
* Out of memory.
|
||||
*/
|
||||
int nghttp2_frame_unpack_settings_payload2(nghttp2_settings_entry **iv_ptr,
|
||||
size_t *niv_ptr,
|
||||
const uint8_t *payload,
|
||||
size_t payloadlen, nghttp2_mem *mem);
|
||||
|
||||
/*
|
||||
* Packs PUSH_PROMISE frame |frame| in wire format and store it in
|
||||
* |bufs|. This function expands |bufs| as necessary to store
|
||||
* frame.
|
||||
*
|
||||
* The caller must make sure that nghttp2_bufs_reset(bufs) is called
|
||||
* before calling this function.
|
||||
*
|
||||
* frame->hd.length is assigned after length is determined during
|
||||
* packing process. CONTINUATION frames are also serialized in this
|
||||
* function. This function does not handle padding.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or returns one of the
|
||||
* following negative error codes:
|
||||
*
|
||||
* NGHTTP2_ERR_HEADER_COMP
|
||||
* The deflate operation failed.
|
||||
* NGHTTP2_ERR_NOMEM
|
||||
* Out of memory.
|
||||
*/
|
||||
int nghttp2_frame_pack_push_promise(nghttp2_bufs *bufs,
|
||||
nghttp2_push_promise *frame,
|
||||
nghttp2_hd_deflater *deflater);
|
||||
|
||||
/*
|
||||
* Unpacks PUSH_PROMISE frame byte sequence into |frame|. This
|
||||
* function only unapcks bytes that come before name/value header
|
||||
* block and after possible Pad Length field.
|
||||
*
|
||||
* This function returns 0 if it succeeds or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* NGHTTP2_ERR_PROTO
|
||||
* TODO END_HEADERS flag is not set
|
||||
*/
|
||||
int nghttp2_frame_unpack_push_promise_payload(nghttp2_push_promise *frame,
|
||||
const uint8_t *payload,
|
||||
size_t payloadlen);
|
||||
|
||||
/*
|
||||
* Packs PING frame |frame| in wire format and store it in
|
||||
* |bufs|.
|
||||
*
|
||||
* The caller must make sure that nghttp2_bufs_reset(bufs) is called
|
||||
* before calling this function.
|
||||
*
|
||||
* This function always succeeds and returns 0.
|
||||
*/
|
||||
int nghttp2_frame_pack_ping(nghttp2_bufs *bufs, nghttp2_ping *frame);
|
||||
|
||||
/*
|
||||
* Unpacks PING wire format into |frame|.
|
||||
*/
|
||||
void nghttp2_frame_unpack_ping_payload(nghttp2_ping *frame,
|
||||
const uint8_t *payload,
|
||||
size_t payloadlen);
|
||||
|
||||
/*
|
||||
* Packs GOAWAY frame |frame| in wire format and store it in |bufs|.
|
||||
* This function expands |bufs| as necessary to store frame.
|
||||
*
|
||||
* The caller must make sure that nghttp2_bufs_reset(bufs) is called
|
||||
* before calling this function.
|
||||
*
|
||||
* This function returns 0 if it succeeds or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* NGHTTP2_ERR_NOMEM
|
||||
* Out of memory.
|
||||
* NGHTTP2_ERR_FRAME_SIZE_ERROR
|
||||
* The length of the frame is too large.
|
||||
*/
|
||||
int nghttp2_frame_pack_goaway(nghttp2_bufs *bufs, nghttp2_goaway *frame);
|
||||
|
||||
/*
|
||||
* Unpacks GOAWAY wire format into |frame|. The |payload| of length
|
||||
* |payloadlen| contains first 8 bytes of payload. The
|
||||
* |var_gift_payload| of length |var_gift_payloadlen| contains
|
||||
* remaining payload and its buffer is gifted to the function and then
|
||||
* |frame|. The |var_gift_payloadlen| must be freed by
|
||||
* nghttp2_frame_goaway_free().
|
||||
*/
|
||||
void nghttp2_frame_unpack_goaway_payload(nghttp2_goaway *frame,
|
||||
const uint8_t *payload,
|
||||
size_t payloadlen,
|
||||
uint8_t *var_gift_payload,
|
||||
size_t var_gift_payloadlen);
|
||||
|
||||
/*
|
||||
* Unpacks GOAWAY wire format into |frame|. This function only exists
|
||||
* for unit test. After allocating buffer for debug data, this
|
||||
* function internally calls nghttp2_frame_unpack_goaway_payload().
|
||||
*
|
||||
* This function returns 0 if it succeeds, or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* NGHTTP2_ERR_NOMEM
|
||||
* Out of memory.
|
||||
*/
|
||||
int nghttp2_frame_unpack_goaway_payload2(nghttp2_goaway *frame,
|
||||
const uint8_t *payload,
|
||||
size_t payloadlen, nghttp2_mem *mem);
|
||||
|
||||
/*
|
||||
* Packs WINDOW_UPDATE frame |frame| in wire frame format and store it
|
||||
* in |bufs|.
|
||||
*
|
||||
* The caller must make sure that nghttp2_bufs_reset(bufs) is called
|
||||
* before calling this function.
|
||||
*
|
||||
* This function always succeeds and returns 0.
|
||||
*/
|
||||
int nghttp2_frame_pack_window_update(nghttp2_bufs *bufs,
|
||||
nghttp2_window_update *frame);
|
||||
|
||||
/*
|
||||
* Unpacks WINDOW_UPDATE frame byte sequence into |frame|.
|
||||
*/
|
||||
void nghttp2_frame_unpack_window_update_payload(nghttp2_window_update *frame,
|
||||
const uint8_t *payload,
|
||||
size_t payloadlen);
|
||||
|
||||
/*
|
||||
* Packs ALTSVC frame |frame| in wire frame format and store it in
|
||||
* |bufs|.
|
||||
*
|
||||
* The caller must make sure that nghttp2_bufs_reset(bufs) is called
|
||||
* before calling this function.
|
||||
*
|
||||
* This function always succeeds and returns 0.
|
||||
*/
|
||||
int nghttp2_frame_pack_altsvc(nghttp2_bufs *bufs, nghttp2_extension *ext);
|
||||
|
||||
/*
|
||||
* Unpacks ALTSVC wire format into |frame|. The |payload| of
|
||||
* |payloadlen| bytes contains frame payload. This function assumes
|
||||
* that frame->payload points to the nghttp2_ext_altsvc object.
|
||||
*
|
||||
* This function always succeeds and returns 0.
|
||||
*/
|
||||
void nghttp2_frame_unpack_altsvc_payload(nghttp2_extension *frame,
|
||||
size_t origin_len, uint8_t *payload,
|
||||
size_t payloadlen);
|
||||
|
||||
/*
|
||||
* Unpacks ALTSVC wire format into |frame|. This function only exists
|
||||
* for unit test. After allocating buffer for fields, this function
|
||||
* internally calls nghttp2_frame_unpack_altsvc_payload().
|
||||
*
|
||||
* This function returns 0 if it succeeds, or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* NGHTTP2_ERR_NOMEM
|
||||
* Out of memory.
|
||||
* NGHTTP2_ERR_FRAME_SIZE_ERROR
|
||||
* The payload is too small.
|
||||
*/
|
||||
int nghttp2_frame_unpack_altsvc_payload2(nghttp2_extension *frame,
|
||||
const uint8_t *payload,
|
||||
size_t payloadlen, nghttp2_mem *mem);
|
||||
|
||||
/*
|
||||
* Initializes HEADERS frame |frame| with given values. |frame| takes
|
||||
* ownership of |nva|, so caller must not free it. If |stream_id| is
|
||||
* not assigned yet, it must be -1.
|
||||
*/
|
||||
void nghttp2_frame_headers_init(nghttp2_headers *frame, uint8_t flags,
|
||||
int32_t stream_id, nghttp2_headers_category cat,
|
||||
const nghttp2_priority_spec *pri_spec,
|
||||
nghttp2_nv *nva, size_t nvlen);
|
||||
|
||||
void nghttp2_frame_headers_free(nghttp2_headers *frame, nghttp2_mem *mem);
|
||||
|
||||
void nghttp2_frame_priority_init(nghttp2_priority *frame, int32_t stream_id,
|
||||
const nghttp2_priority_spec *pri_spec);
|
||||
|
||||
void nghttp2_frame_priority_free(nghttp2_priority *frame);
|
||||
|
||||
void nghttp2_frame_rst_stream_init(nghttp2_rst_stream *frame, int32_t stream_id,
|
||||
uint32_t error_code);
|
||||
|
||||
void nghttp2_frame_rst_stream_free(nghttp2_rst_stream *frame);
|
||||
|
||||
/*
|
||||
* Initializes PUSH_PROMISE frame |frame| with given values. |frame|
|
||||
* takes ownership of |nva|, so caller must not free it.
|
||||
*/
|
||||
void nghttp2_frame_push_promise_init(nghttp2_push_promise *frame, uint8_t flags,
|
||||
int32_t stream_id,
|
||||
int32_t promised_stream_id,
|
||||
nghttp2_nv *nva, size_t nvlen);
|
||||
|
||||
void nghttp2_frame_push_promise_free(nghttp2_push_promise *frame,
|
||||
nghttp2_mem *mem);
|
||||
|
||||
/*
|
||||
* Initializes SETTINGS frame |frame| with given values. |frame| takes
|
||||
* ownership of |iv|, so caller must not free it. The |flags| are
|
||||
* bitwise-OR of one or more of nghttp2_settings_flag.
|
||||
*/
|
||||
void nghttp2_frame_settings_init(nghttp2_settings *frame, uint8_t flags,
|
||||
nghttp2_settings_entry *iv, size_t niv);
|
||||
|
||||
void nghttp2_frame_settings_free(nghttp2_settings *frame, nghttp2_mem *mem);
|
||||
|
||||
/*
|
||||
* Initializes PING frame |frame| with given values. If the
|
||||
* |opqeue_data| is not NULL, it must point to 8 bytes memory region
|
||||
* of data. The data pointed by |opaque_data| is copied. It can be
|
||||
* NULL. In this case, 8 bytes NULL is used.
|
||||
*/
|
||||
void nghttp2_frame_ping_init(nghttp2_ping *frame, uint8_t flags,
|
||||
const uint8_t *opque_data);
|
||||
|
||||
void nghttp2_frame_ping_free(nghttp2_ping *frame);
|
||||
|
||||
/*
|
||||
* Initializes GOAWAY frame |frame| with given values. On success,
|
||||
* this function takes ownership of |opaque_data|, so caller must not
|
||||
* free it. If the |opaque_data_len| is 0, opaque_data could be NULL.
|
||||
*/
|
||||
void nghttp2_frame_goaway_init(nghttp2_goaway *frame, int32_t last_stream_id,
|
||||
uint32_t error_code, uint8_t *opaque_data,
|
||||
size_t opaque_data_len);
|
||||
|
||||
void nghttp2_frame_goaway_free(nghttp2_goaway *frame, nghttp2_mem *mem);
|
||||
|
||||
void nghttp2_frame_window_update_init(nghttp2_window_update *frame,
|
||||
uint8_t flags, int32_t stream_id,
|
||||
int32_t window_size_increment);
|
||||
|
||||
void nghttp2_frame_window_update_free(nghttp2_window_update *frame);
|
||||
|
||||
void nghttp2_frame_extension_init(nghttp2_extension *frame, uint8_t type,
|
||||
uint8_t flags, int32_t stream_id,
|
||||
void *payload);
|
||||
|
||||
void nghttp2_frame_extension_free(nghttp2_extension *frame);
|
||||
|
||||
/*
|
||||
* Initializes ALTSVC frame |frame| with given values. This function
|
||||
* assumes that frame->payload points to nghttp2_ext_altsvc object.
|
||||
* Also |origin| and |field_value| are allocated in single buffer,
|
||||
* starting |origin|. On success, this function takes ownership of
|
||||
* |origin|, so caller must not free it.
|
||||
*/
|
||||
void nghttp2_frame_altsvc_init(nghttp2_extension *frame, int32_t stream_id,
|
||||
uint8_t *origin, size_t origin_len,
|
||||
uint8_t *field_value, size_t field_value_len);
|
||||
|
||||
/*
|
||||
* Frees up resources under |frame|. This function does not free
|
||||
* nghttp2_ext_altsvc object pointed by frame->payload. This function
|
||||
* only frees origin pointed by nghttp2_ext_altsvc.origin. Therefore,
|
||||
* other fields must be allocated in the same buffer with origin.
|
||||
*/
|
||||
void nghttp2_frame_altsvc_free(nghttp2_extension *frame, nghttp2_mem *mem);
|
||||
|
||||
/*
|
||||
* Returns the number of padding bytes after payload. The total
|
||||
* padding length is given in the |padlen|. The returned value does
|
||||
* not include the Pad Length field. If |padlen| is 0, this function
|
||||
* returns 0, regardless of frame->hd.flags.
|
||||
*/
|
||||
size_t nghttp2_frame_trail_padlen(nghttp2_frame *frame, size_t padlen);
|
||||
|
||||
void nghttp2_frame_data_init(nghttp2_data *frame, uint8_t flags,
|
||||
int32_t stream_id);
|
||||
|
||||
void nghttp2_frame_data_free(nghttp2_data *frame);
|
||||
|
||||
/*
|
||||
* Makes copy of |iv| and return the copy. The |niv| is the number of
|
||||
* entries in |iv|. This function returns the pointer to the copy if
|
||||
* it succeeds, or NULL.
|
||||
*/
|
||||
nghttp2_settings_entry *nghttp2_frame_iv_copy(const nghttp2_settings_entry *iv,
|
||||
size_t niv, nghttp2_mem *mem);
|
||||
|
||||
/*
|
||||
* Sorts the |nva| in ascending order of name and value. If names are
|
||||
* equivalent, sort them by value.
|
||||
*/
|
||||
void nghttp2_nv_array_sort(nghttp2_nv *nva, size_t nvlen);
|
||||
|
||||
/*
|
||||
* Copies name/value pairs from |nva|, which contains |nvlen| pairs,
|
||||
* to |*nva_ptr|, which is dynamically allocated so that all items can
|
||||
* be stored. The resultant name and value in nghttp2_nv are
|
||||
* guaranteed to be NULL-terminated even if the input is not
|
||||
* null-terminated.
|
||||
*
|
||||
* The |*nva_ptr| must be freed using nghttp2_nv_array_del().
|
||||
*
|
||||
* This function returns 0 if it succeeds or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* NGHTTP2_ERR_NOMEM
|
||||
* Out of memory.
|
||||
*/
|
||||
int nghttp2_nv_array_copy(nghttp2_nv **nva_ptr, const nghttp2_nv *nva,
|
||||
size_t nvlen, nghttp2_mem *mem);
|
||||
|
||||
/*
|
||||
* Returns nonzero if the name/value pair |a| equals to |b|. The name
|
||||
* is compared in case-sensitive, because we ensure that this function
|
||||
* is called after the name is lower-cased.
|
||||
*/
|
||||
int nghttp2_nv_equal(const nghttp2_nv *a, const nghttp2_nv *b);
|
||||
|
||||
/*
|
||||
* Frees |nva|.
|
||||
*/
|
||||
void nghttp2_nv_array_del(nghttp2_nv *nva, nghttp2_mem *mem);
|
||||
|
||||
/*
|
||||
* Checks that the |iv|, which includes |niv| entries, does not have
|
||||
* invalid values.
|
||||
*
|
||||
* This function returns nonzero if it succeeds, or 0.
|
||||
*/
|
||||
int nghttp2_iv_check(const nghttp2_settings_entry *iv, size_t niv);
|
||||
|
||||
/*
|
||||
* Sets Pad Length field and flags and adjusts frame header position
|
||||
* of each buffers in |bufs|. The number of padding is given in the
|
||||
* |padlen| including Pad Length field. The |hd| is the frame header
|
||||
* for the serialized data. This function fills zeros padding region
|
||||
* unless framehd_only is nonzero.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* NGHTTP2_ERR_NOMEM
|
||||
* Out of memory.
|
||||
* NGHTTP2_ERR_FRAME_SIZE_ERROR
|
||||
* The length of the resulting frame is too large.
|
||||
*/
|
||||
int nghttp2_frame_add_pad(nghttp2_bufs *bufs, nghttp2_frame_hd *hd,
|
||||
size_t padlen, int framehd_only);
|
||||
|
||||
#endif /* NGHTTP2_FRAME_H */
|
@ -1,430 +0,0 @@
|
||||
/*
|
||||
* nghttp2 - HTTP/2 C Library
|
||||
*
|
||||
* Copyright (c) 2013 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef NGHTTP2_HD_H
|
||||
#define NGHTTP2_HD_H
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif /* HAVE_CONFIG_H */
|
||||
|
||||
#include <nghttp2/nghttp2.h>
|
||||
|
||||
#include "nghttp2_hd_huffman.h"
|
||||
#include "nghttp2_buf.h"
|
||||
#include "nghttp2_mem.h"
|
||||
#include "nghttp2_rcbuf.h"
|
||||
|
||||
#define NGHTTP2_HD_DEFAULT_MAX_BUFFER_SIZE NGHTTP2_DEFAULT_HEADER_TABLE_SIZE
|
||||
#define NGHTTP2_HD_ENTRY_OVERHEAD 32
|
||||
|
||||
/* The maximum length of one name/value pair. This is the sum of the
|
||||
length of name and value. This is not specified by the spec. We
|
||||
just chose the arbitrary size */
|
||||
#define NGHTTP2_HD_MAX_NV 65536
|
||||
|
||||
/* Default size of maximum table buffer size for encoder. Even if
|
||||
remote decoder notifies larger buffer size for its decoding,
|
||||
encoder only uses the memory up to this value. */
|
||||
#define NGHTTP2_HD_DEFAULT_MAX_DEFLATE_BUFFER_SIZE (1 << 12)
|
||||
|
||||
/* Exported for unit test */
|
||||
#define NGHTTP2_STATIC_TABLE_LENGTH 61
|
||||
|
||||
/* Generated by genlibtokenlookup.py */
|
||||
typedef enum {
|
||||
NGHTTP2_TOKEN__AUTHORITY = 0,
|
||||
NGHTTP2_TOKEN__METHOD = 1,
|
||||
NGHTTP2_TOKEN__PATH = 3,
|
||||
NGHTTP2_TOKEN__SCHEME = 5,
|
||||
NGHTTP2_TOKEN__STATUS = 7,
|
||||
NGHTTP2_TOKEN_ACCEPT_CHARSET = 14,
|
||||
NGHTTP2_TOKEN_ACCEPT_ENCODING = 15,
|
||||
NGHTTP2_TOKEN_ACCEPT_LANGUAGE = 16,
|
||||
NGHTTP2_TOKEN_ACCEPT_RANGES = 17,
|
||||
NGHTTP2_TOKEN_ACCEPT = 18,
|
||||
NGHTTP2_TOKEN_ACCESS_CONTROL_ALLOW_ORIGIN = 19,
|
||||
NGHTTP2_TOKEN_AGE = 20,
|
||||
NGHTTP2_TOKEN_ALLOW = 21,
|
||||
NGHTTP2_TOKEN_AUTHORIZATION = 22,
|
||||
NGHTTP2_TOKEN_CACHE_CONTROL = 23,
|
||||
NGHTTP2_TOKEN_CONTENT_DISPOSITION = 24,
|
||||
NGHTTP2_TOKEN_CONTENT_ENCODING = 25,
|
||||
NGHTTP2_TOKEN_CONTENT_LANGUAGE = 26,
|
||||
NGHTTP2_TOKEN_CONTENT_LENGTH = 27,
|
||||
NGHTTP2_TOKEN_CONTENT_LOCATION = 28,
|
||||
NGHTTP2_TOKEN_CONTENT_RANGE = 29,
|
||||
NGHTTP2_TOKEN_CONTENT_TYPE = 30,
|
||||
NGHTTP2_TOKEN_COOKIE = 31,
|
||||
NGHTTP2_TOKEN_DATE = 32,
|
||||
NGHTTP2_TOKEN_ETAG = 33,
|
||||
NGHTTP2_TOKEN_EXPECT = 34,
|
||||
NGHTTP2_TOKEN_EXPIRES = 35,
|
||||
NGHTTP2_TOKEN_FROM = 36,
|
||||
NGHTTP2_TOKEN_HOST = 37,
|
||||
NGHTTP2_TOKEN_IF_MATCH = 38,
|
||||
NGHTTP2_TOKEN_IF_MODIFIED_SINCE = 39,
|
||||
NGHTTP2_TOKEN_IF_NONE_MATCH = 40,
|
||||
NGHTTP2_TOKEN_IF_RANGE = 41,
|
||||
NGHTTP2_TOKEN_IF_UNMODIFIED_SINCE = 42,
|
||||
NGHTTP2_TOKEN_LAST_MODIFIED = 43,
|
||||
NGHTTP2_TOKEN_LINK = 44,
|
||||
NGHTTP2_TOKEN_LOCATION = 45,
|
||||
NGHTTP2_TOKEN_MAX_FORWARDS = 46,
|
||||
NGHTTP2_TOKEN_PROXY_AUTHENTICATE = 47,
|
||||
NGHTTP2_TOKEN_PROXY_AUTHORIZATION = 48,
|
||||
NGHTTP2_TOKEN_RANGE = 49,
|
||||
NGHTTP2_TOKEN_REFERER = 50,
|
||||
NGHTTP2_TOKEN_REFRESH = 51,
|
||||
NGHTTP2_TOKEN_RETRY_AFTER = 52,
|
||||
NGHTTP2_TOKEN_SERVER = 53,
|
||||
NGHTTP2_TOKEN_SET_COOKIE = 54,
|
||||
NGHTTP2_TOKEN_STRICT_TRANSPORT_SECURITY = 55,
|
||||
NGHTTP2_TOKEN_TRANSFER_ENCODING = 56,
|
||||
NGHTTP2_TOKEN_USER_AGENT = 57,
|
||||
NGHTTP2_TOKEN_VARY = 58,
|
||||
NGHTTP2_TOKEN_VIA = 59,
|
||||
NGHTTP2_TOKEN_WWW_AUTHENTICATE = 60,
|
||||
NGHTTP2_TOKEN_TE,
|
||||
NGHTTP2_TOKEN_CONNECTION,
|
||||
NGHTTP2_TOKEN_KEEP_ALIVE,
|
||||
NGHTTP2_TOKEN_PROXY_CONNECTION,
|
||||
NGHTTP2_TOKEN_UPGRADE,
|
||||
} nghttp2_token;
|
||||
|
||||
struct nghttp2_hd_entry;
|
||||
typedef struct nghttp2_hd_entry nghttp2_hd_entry;
|
||||
|
||||
typedef struct {
|
||||
/* The buffer containing header field name. NULL-termination is
|
||||
guaranteed. */
|
||||
nghttp2_rcbuf *name;
|
||||
/* The buffer containing header field value. NULL-termination is
|
||||
guaranteed. */
|
||||
nghttp2_rcbuf *value;
|
||||
/* nghttp2_token value for name. It could be -1 if we have no token
|
||||
for that header field name. */
|
||||
int32_t token;
|
||||
/* Bitwise OR of one or more of nghttp2_nv_flag. */
|
||||
uint8_t flags;
|
||||
} nghttp2_hd_nv;
|
||||
|
||||
struct nghttp2_hd_entry {
|
||||
/* The header field name/value pair */
|
||||
nghttp2_hd_nv nv;
|
||||
/* This is solely for nghttp2_hd_{deflate,inflate}_get_table_entry
|
||||
APIs to keep backward compatibility. */
|
||||
nghttp2_nv cnv;
|
||||
/* The next entry which shares same bucket in hash table. */
|
||||
nghttp2_hd_entry *next;
|
||||
/* The sequence number. We will increment it by one whenever we
|
||||
store nghttp2_hd_entry to dynamic header table. */
|
||||
uint32_t seq;
|
||||
/* The hash value for header name (nv.name). */
|
||||
uint32_t hash;
|
||||
};
|
||||
|
||||
/* The entry used for static header table. */
|
||||
typedef struct {
|
||||
nghttp2_rcbuf name;
|
||||
nghttp2_rcbuf value;
|
||||
nghttp2_nv cnv;
|
||||
int32_t token;
|
||||
uint32_t hash;
|
||||
} nghttp2_hd_static_entry;
|
||||
|
||||
typedef struct {
|
||||
nghttp2_hd_entry **buffer;
|
||||
size_t mask;
|
||||
size_t first;
|
||||
size_t len;
|
||||
} nghttp2_hd_ringbuf;
|
||||
|
||||
typedef enum {
|
||||
NGHTTP2_HD_OPCODE_NONE,
|
||||
NGHTTP2_HD_OPCODE_INDEXED,
|
||||
NGHTTP2_HD_OPCODE_NEWNAME,
|
||||
NGHTTP2_HD_OPCODE_INDNAME
|
||||
} nghttp2_hd_opcode;
|
||||
|
||||
typedef enum {
|
||||
NGHTTP2_HD_STATE_EXPECT_TABLE_SIZE,
|
||||
NGHTTP2_HD_STATE_INFLATE_START,
|
||||
NGHTTP2_HD_STATE_OPCODE,
|
||||
NGHTTP2_HD_STATE_READ_TABLE_SIZE,
|
||||
NGHTTP2_HD_STATE_READ_INDEX,
|
||||
NGHTTP2_HD_STATE_NEWNAME_CHECK_NAMELEN,
|
||||
NGHTTP2_HD_STATE_NEWNAME_READ_NAMELEN,
|
||||
NGHTTP2_HD_STATE_NEWNAME_READ_NAMEHUFF,
|
||||
NGHTTP2_HD_STATE_NEWNAME_READ_NAME,
|
||||
NGHTTP2_HD_STATE_CHECK_VALUELEN,
|
||||
NGHTTP2_HD_STATE_READ_VALUELEN,
|
||||
NGHTTP2_HD_STATE_READ_VALUEHUFF,
|
||||
NGHTTP2_HD_STATE_READ_VALUE
|
||||
} nghttp2_hd_inflate_state;
|
||||
|
||||
typedef enum {
|
||||
NGHTTP2_HD_WITH_INDEXING,
|
||||
NGHTTP2_HD_WITHOUT_INDEXING,
|
||||
NGHTTP2_HD_NEVER_INDEXING
|
||||
} nghttp2_hd_indexing_mode;
|
||||
|
||||
typedef struct {
|
||||
/* dynamic header table */
|
||||
nghttp2_hd_ringbuf hd_table;
|
||||
/* Memory allocator */
|
||||
nghttp2_mem *mem;
|
||||
/* Abstract buffer size of hd_table as described in the spec. This
|
||||
is the sum of length of name/value in hd_table +
|
||||
NGHTTP2_HD_ENTRY_OVERHEAD bytes overhead per each entry. */
|
||||
size_t hd_table_bufsize;
|
||||
/* The effective header table size. */
|
||||
size_t hd_table_bufsize_max;
|
||||
/* Next sequence number for nghttp2_hd_entry */
|
||||
uint32_t next_seq;
|
||||
/* If inflate/deflate error occurred, this value is set to 1 and
|
||||
further invocation of inflate/deflate will fail with
|
||||
NGHTTP2_ERR_HEADER_COMP. */
|
||||
uint8_t bad;
|
||||
} nghttp2_hd_context;
|
||||
|
||||
#define HD_MAP_SIZE 128
|
||||
|
||||
typedef struct { nghttp2_hd_entry *table[HD_MAP_SIZE]; } nghttp2_hd_map;
|
||||
|
||||
struct nghttp2_hd_deflater {
|
||||
nghttp2_hd_context ctx;
|
||||
nghttp2_hd_map map;
|
||||
/* The upper limit of the header table size the deflater accepts. */
|
||||
size_t deflate_hd_table_bufsize_max;
|
||||
/* Minimum header table size notified in the next context update */
|
||||
size_t min_hd_table_bufsize_max;
|
||||
/* If nonzero, send header table size using encoding context update
|
||||
in the next deflate process */
|
||||
uint8_t notify_table_size_change;
|
||||
};
|
||||
|
||||
struct nghttp2_hd_inflater {
|
||||
nghttp2_hd_context ctx;
|
||||
/* Stores current state of huffman decoding */
|
||||
nghttp2_hd_huff_decode_context huff_decode_ctx;
|
||||
/* header buffer */
|
||||
nghttp2_buf namebuf, valuebuf;
|
||||
nghttp2_rcbuf *namercbuf, *valuercbuf;
|
||||
/* Pointer to the name/value pair which are used in the current
|
||||
header emission. */
|
||||
nghttp2_rcbuf *nv_name_keep, *nv_value_keep;
|
||||
/* The number of bytes to read */
|
||||
size_t left;
|
||||
/* The index in indexed repr or indexed name */
|
||||
size_t index;
|
||||
/* The maximum header table size the inflater supports. This is the
|
||||
same value transmitted in SETTINGS_HEADER_TABLE_SIZE */
|
||||
size_t settings_hd_table_bufsize_max;
|
||||
/* Minimum header table size set by nghttp2_hd_inflate_change_table_size */
|
||||
size_t min_hd_table_bufsize_max;
|
||||
/* The number of next shift to decode integer */
|
||||
size_t shift;
|
||||
nghttp2_hd_opcode opcode;
|
||||
nghttp2_hd_inflate_state state;
|
||||
/* nonzero if string is huffman encoded */
|
||||
uint8_t huffman_encoded;
|
||||
/* nonzero if deflater requires that current entry is indexed */
|
||||
uint8_t index_required;
|
||||
/* nonzero if deflater requires that current entry must not be
|
||||
indexed */
|
||||
uint8_t no_index;
|
||||
};
|
||||
|
||||
/*
|
||||
* Initializes the |ent| members. The reference counts of nv->name
|
||||
* and nv->value are increased by one for each.
|
||||
*/
|
||||
void nghttp2_hd_entry_init(nghttp2_hd_entry *ent, nghttp2_hd_nv *nv);
|
||||
|
||||
/*
|
||||
* This function decreases the reference counts of nv->name and
|
||||
* nv->value.
|
||||
*/
|
||||
void nghttp2_hd_entry_free(nghttp2_hd_entry *ent);
|
||||
|
||||
/*
|
||||
* Initializes |deflater| for deflating name/values pairs.
|
||||
*
|
||||
* The encoder only uses up to
|
||||
* NGHTTP2_HD_DEFAULT_MAX_DEFLATE_BUFFER_SIZE bytes for header table
|
||||
* even if the larger value is specified later in
|
||||
* nghttp2_hd_change_table_size().
|
||||
*
|
||||
* This function returns 0 if it succeeds, or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* NGHTTP2_ERR_NOMEM
|
||||
* Out of memory.
|
||||
*/
|
||||
int nghttp2_hd_deflate_init(nghttp2_hd_deflater *deflater, nghttp2_mem *mem);
|
||||
|
||||
/*
|
||||
* Initializes |deflater| for deflating name/values pairs.
|
||||
*
|
||||
* The encoder only uses up to |deflate_hd_table_bufsize_max| bytes
|
||||
* for header table even if the larger value is specified later in
|
||||
* nghttp2_hd_change_table_size().
|
||||
*
|
||||
* This function returns 0 if it succeeds, or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* NGHTTP2_ERR_NOMEM
|
||||
* Out of memory.
|
||||
*/
|
||||
int nghttp2_hd_deflate_init2(nghttp2_hd_deflater *deflater,
|
||||
size_t deflate_hd_table_bufsize_max,
|
||||
nghttp2_mem *mem);
|
||||
|
||||
/*
|
||||
* Deallocates any resources allocated for |deflater|.
|
||||
*/
|
||||
void nghttp2_hd_deflate_free(nghttp2_hd_deflater *deflater);
|
||||
|
||||
/*
|
||||
* Deflates the |nva|, which has the |nvlen| name/value pairs, into
|
||||
* the |bufs|.
|
||||
*
|
||||
* This function expands |bufs| as necessary to store the result. If
|
||||
* buffers is full and the process still requires more space, this
|
||||
* funtion fails and returns NGHTTP2_ERR_HEADER_COMP.
|
||||
*
|
||||
* After this function returns, it is safe to delete the |nva|.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* NGHTTP2_ERR_NOMEM
|
||||
* Out of memory.
|
||||
* NGHTTP2_ERR_HEADER_COMP
|
||||
* Deflation process has failed.
|
||||
* NGHTTP2_ERR_BUFFER_ERROR
|
||||
* Out of buffer space.
|
||||
*/
|
||||
int nghttp2_hd_deflate_hd_bufs(nghttp2_hd_deflater *deflater,
|
||||
nghttp2_bufs *bufs, const nghttp2_nv *nva,
|
||||
size_t nvlen);
|
||||
|
||||
/*
|
||||
* Initializes |inflater| for inflating name/values pairs.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* :enum:`NGHTTP2_ERR_NOMEM`
|
||||
* Out of memory.
|
||||
*/
|
||||
int nghttp2_hd_inflate_init(nghttp2_hd_inflater *inflater, nghttp2_mem *mem);
|
||||
|
||||
/*
|
||||
* Deallocates any resources allocated for |inflater|.
|
||||
*/
|
||||
void nghttp2_hd_inflate_free(nghttp2_hd_inflater *inflater);
|
||||
|
||||
/*
|
||||
* Similar to nghttp2_hd_inflate_hd(), but this takes nghttp2_hd_nv
|
||||
* instead of nghttp2_nv as output parameter |nv_out|. Other than
|
||||
* that return values and semantics are the same as
|
||||
* nghttp2_hd_inflate_hd().
|
||||
*/
|
||||
ssize_t nghttp2_hd_inflate_hd_nv(nghttp2_hd_inflater *inflater,
|
||||
nghttp2_hd_nv *nv_out, int *inflate_flags,
|
||||
const uint8_t *in, size_t inlen, int in_final);
|
||||
|
||||
/* For unittesting purpose */
|
||||
int nghttp2_hd_emit_indname_block(nghttp2_bufs *bufs, size_t index,
|
||||
nghttp2_nv *nv, int indexing_mode);
|
||||
|
||||
/* For unittesting purpose */
|
||||
int nghttp2_hd_emit_newname_block(nghttp2_bufs *bufs, nghttp2_nv *nv,
|
||||
int indexing_mode);
|
||||
|
||||
/* For unittesting purpose */
|
||||
int nghttp2_hd_emit_table_size(nghttp2_bufs *bufs, size_t table_size);
|
||||
|
||||
/* For unittesting purpose */
|
||||
nghttp2_hd_nv nghttp2_hd_table_get(nghttp2_hd_context *context, size_t index);
|
||||
|
||||
/* For unittesting purpose */
|
||||
ssize_t nghttp2_hd_decode_length(uint32_t *res, size_t *shift_ptr, int *final,
|
||||
uint32_t initial, size_t shift, uint8_t *in,
|
||||
uint8_t *last, size_t prefix);
|
||||
|
||||
/* Huffman encoding/decoding functions */
|
||||
|
||||
/*
|
||||
* Counts the required bytes to encode |src| with length |len|.
|
||||
*
|
||||
* This function returns the number of required bytes to encode given
|
||||
* data, including padding of prefix of terminal symbol code. This
|
||||
* function always succeeds.
|
||||
*/
|
||||
size_t nghttp2_hd_huff_encode_count(const uint8_t *src, size_t len);
|
||||
|
||||
/*
|
||||
* Encodes the given data |src| with length |srclen| to the |bufs|.
|
||||
* This function expands extra buffers in |bufs| if necessary.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* NGHTTP2_ERR_NOMEM
|
||||
* Out of memory.
|
||||
* NGHTTP2_ERR_BUFFER_ERROR
|
||||
* Out of buffer space.
|
||||
*/
|
||||
int nghttp2_hd_huff_encode(nghttp2_bufs *bufs, const uint8_t *src,
|
||||
size_t srclen);
|
||||
|
||||
void nghttp2_hd_huff_decode_context_init(nghttp2_hd_huff_decode_context *ctx);
|
||||
|
||||
/*
|
||||
* Decodes the given data |src| with length |srclen|. The |ctx| must
|
||||
* be initialized by nghttp2_hd_huff_decode_context_init(). The result
|
||||
* will be written to |buf|. This function assumes that |buf| has the
|
||||
* enough room to store the decoded byte string.
|
||||
*
|
||||
* The caller must set the |final| to nonzero if the given input is
|
||||
* the final block.
|
||||
*
|
||||
* This function returns the number of read bytes from the |in|.
|
||||
*
|
||||
* If this function fails, it returns one of the following negative
|
||||
* return codes:
|
||||
*
|
||||
* NGHTTP2_ERR_NOMEM
|
||||
* Out of memory.
|
||||
* NGHTTP2_ERR_HEADER_COMP
|
||||
* Decoding process has failed.
|
||||
*/
|
||||
ssize_t nghttp2_hd_huff_decode(nghttp2_hd_huff_decode_context *ctx,
|
||||
nghttp2_buf *buf, const uint8_t *src,
|
||||
size_t srclen, int final);
|
||||
|
||||
#endif /* NGHTTP2_HD_H */
|
@ -1,77 +0,0 @@
|
||||
/*
|
||||
* nghttp2 - HTTP/2 C Library
|
||||
*
|
||||
* Copyright (c) 2013 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef NGHTTP2_HD_HUFFMAN_H
|
||||
#define NGHTTP2_HD_HUFFMAN_H
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif /* HAVE_CONFIG_H */
|
||||
|
||||
#include <nghttp2/nghttp2.h>
|
||||
|
||||
typedef enum {
|
||||
/* FSA accepts this state as the end of huffman encoding
|
||||
sequence. */
|
||||
NGHTTP2_HUFF_ACCEPTED = 1,
|
||||
/* This state emits symbol */
|
||||
NGHTTP2_HUFF_SYM = (1 << 1),
|
||||
/* If state machine reaches this state, decoding fails. */
|
||||
NGHTTP2_HUFF_FAIL = (1 << 2)
|
||||
} nghttp2_huff_decode_flag;
|
||||
|
||||
typedef struct {
|
||||
/* huffman decoding state, which is actually the node ID of internal
|
||||
huffman tree. We have 257 leaf nodes, but they are identical to
|
||||
root node other than emitting a symbol, so we have 256 internal
|
||||
nodes [1..255], inclusive. */
|
||||
uint8_t state;
|
||||
/* bitwise OR of zero or more of the nghttp2_huff_decode_flag */
|
||||
uint8_t flags;
|
||||
/* symbol if NGHTTP2_HUFF_SYM flag set */
|
||||
uint8_t sym;
|
||||
} nghttp2_huff_decode;
|
||||
|
||||
typedef nghttp2_huff_decode huff_decode_table_type[16];
|
||||
|
||||
typedef struct {
|
||||
/* Current huffman decoding state. We stripped leaf nodes, so the
|
||||
value range is [0..255], inclusive. */
|
||||
uint8_t state;
|
||||
/* nonzero if we can say that the decoding process succeeds at this
|
||||
state */
|
||||
uint8_t accept;
|
||||
} nghttp2_hd_huff_decode_context;
|
||||
|
||||
typedef struct {
|
||||
/* The number of bits in this code */
|
||||
uint32_t nbits;
|
||||
/* Huffman code aligned to LSB */
|
||||
uint32_t code;
|
||||
} nghttp2_huff_sym;
|
||||
|
||||
extern const nghttp2_huff_sym huff_sym_table[];
|
||||
extern const nghttp2_huff_decode huff_decode_table[][16];
|
||||
|
||||
#endif /* NGHTTP2_HD_HUFFMAN_H */
|
@ -1,122 +0,0 @@
|
||||
/*
|
||||
* nghttp2 - HTTP/2 C Library
|
||||
*
|
||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef NGHTTP2_HELPER_H
|
||||
#define NGHTTP2_HELPER_H
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif /* HAVE_CONFIG_H */
|
||||
|
||||
#include <string.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include <nghttp2/nghttp2.h>
|
||||
#include "nghttp2_mem.h"
|
||||
|
||||
#define nghttp2_min(A, B) ((A) < (B) ? (A) : (B))
|
||||
#define nghttp2_max(A, B) ((A) > (B) ? (A) : (B))
|
||||
|
||||
#define lstreq(A, B, N) ((sizeof((A)) - 1) == (N) && memcmp((A), (B), (N)) == 0)
|
||||
|
||||
#define nghttp2_struct_of(ptr, type, member) \
|
||||
((type *)(void *)((char *)(ptr)-offsetof(type, member)))
|
||||
|
||||
/*
|
||||
* Copies 2 byte unsigned integer |n| in host byte order to |buf| in
|
||||
* network byte order.
|
||||
*/
|
||||
void nghttp2_put_uint16be(uint8_t *buf, uint16_t n);
|
||||
|
||||
/*
|
||||
* Copies 4 byte unsigned integer |n| in host byte order to |buf| in
|
||||
* network byte order.
|
||||
*/
|
||||
void nghttp2_put_uint32be(uint8_t *buf, uint32_t n);
|
||||
|
||||
/*
|
||||
* Retrieves 2 byte unsigned integer stored in |data| in network byte
|
||||
* order and returns it in host byte order.
|
||||
*/
|
||||
uint16_t nghttp2_get_uint16(const uint8_t *data);
|
||||
|
||||
/*
|
||||
* Retrieves 4 byte unsigned integer stored in |data| in network byte
|
||||
* order and returns it in host byte order.
|
||||
*/
|
||||
uint32_t nghttp2_get_uint32(const uint8_t *data);
|
||||
|
||||
void nghttp2_downcase(uint8_t *s, size_t len);
|
||||
|
||||
/*
|
||||
* Adjusts |*local_window_size_ptr|, |*recv_window_size_ptr|,
|
||||
* |*recv_reduction_ptr| with |*delta_ptr| which is the
|
||||
* WINDOW_UPDATE's window_size_increment sent from local side. If
|
||||
* |delta| is strictly larger than |*recv_window_size_ptr|,
|
||||
* |*local_window_size_ptr| is increased by delta -
|
||||
* *recv_window_size_ptr. If |delta| is negative,
|
||||
* |*local_window_size_ptr| is decreased by delta.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* NGHTTP2_ERR_FLOW_CONTROL
|
||||
* local_window_size overflow or gets negative.
|
||||
*/
|
||||
int nghttp2_adjust_local_window_size(int32_t *local_window_size_ptr,
|
||||
int32_t *recv_window_size_ptr,
|
||||
int32_t *recv_reduction_ptr,
|
||||
int32_t *delta_ptr);
|
||||
|
||||
/*
|
||||
* This function works like nghttp2_adjust_local_window_size(). The
|
||||
* difference is that this function assumes *delta_ptr >= 0, and
|
||||
* *recv_window_size_ptr is not decreased by *delta_ptr.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* NGHTTP2_ERR_FLOW_CONTROL
|
||||
* local_window_size overflow or gets negative.
|
||||
*/
|
||||
int nghttp2_increase_local_window_size(int32_t *local_window_size_ptr,
|
||||
int32_t *recv_window_size_ptr,
|
||||
int32_t *recv_reduction_ptr,
|
||||
int32_t *delta_ptr);
|
||||
|
||||
/*
|
||||
* Returns non-zero if the function decided that WINDOW_UPDATE should
|
||||
* be sent.
|
||||
*/
|
||||
int nghttp2_should_send_window_update(int32_t local_window_size,
|
||||
int32_t recv_window_size);
|
||||
|
||||
/*
|
||||
* Copies the buffer |src| of length |len| to the destination pointed
|
||||
* by the |dest|, assuming that the |dest| is at lest |len| bytes long
|
||||
* . Returns dest + len.
|
||||
*/
|
||||
uint8_t *nghttp2_cpymem(uint8_t *dest, const void *src, size_t len);
|
||||
|
||||
#endif /* NGHTTP2_HELPER_H */
|
@ -1,97 +0,0 @@
|
||||
/*
|
||||
* nghttp2 - HTTP/2 C Library
|
||||
*
|
||||
* Copyright (c) 2015 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef NGHTTP2_HTTP_H
|
||||
#define NGHTTP2_HTTP_H
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif /* HAVE_CONFIG_H */
|
||||
|
||||
#include <nghttp2/nghttp2.h>
|
||||
#include "nghttp2_session.h"
|
||||
#include "nghttp2_stream.h"
|
||||
|
||||
/*
|
||||
* This function is called when HTTP header field |nv| in |frame| is
|
||||
* received for |stream|. This function will validate |nv| against
|
||||
* the current state of stream.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* NGHTTP2_ERR_HTTP_HEADER
|
||||
* Invalid HTTP header field was received.
|
||||
* NGHTTP2_ERR_IGN_HTTP_HEADER
|
||||
* Invalid HTTP header field was received but it can be treated as
|
||||
* if it was not received because of compatibility reasons.
|
||||
*/
|
||||
int nghttp2_http_on_header(nghttp2_session *session, nghttp2_stream *stream,
|
||||
nghttp2_frame *frame, nghttp2_hd_nv *nv,
|
||||
int trailer);
|
||||
|
||||
/*
|
||||
* This function is called when request header is received. This
|
||||
* function performs validation and returns 0 if it succeeds, or -1.
|
||||
*/
|
||||
int nghttp2_http_on_request_headers(nghttp2_stream *stream,
|
||||
nghttp2_frame *frame);
|
||||
|
||||
/*
|
||||
* This function is called when response header is received. This
|
||||
* function performs validation and returns 0 if it succeeds, or -1.
|
||||
*/
|
||||
int nghttp2_http_on_response_headers(nghttp2_stream *stream);
|
||||
|
||||
/*
|
||||
* This function is called trailer header (for both request and
|
||||
* response) is received. This function performs validation and
|
||||
* returns 0 if it succeeds, or -1.
|
||||
*/
|
||||
int nghttp2_http_on_trailer_headers(nghttp2_stream *stream,
|
||||
nghttp2_frame *frame);
|
||||
|
||||
/*
|
||||
* This function is called when END_STREAM flag is seen in incoming
|
||||
* frame. This function performs validation and returns 0 if it
|
||||
* succeeds, or -1.
|
||||
*/
|
||||
int nghttp2_http_on_remote_end_stream(nghttp2_stream *stream);
|
||||
|
||||
/*
|
||||
* This function is called when chunk of data is received. This
|
||||
* function performs validation and returns 0 if it succeeds, or -1.
|
||||
*/
|
||||
int nghttp2_http_on_data_chunk(nghttp2_stream *stream, size_t n);
|
||||
|
||||
/*
|
||||
* This function inspects header field in |frame| and records its
|
||||
* method in stream->http_flags. If frame->hd.type is neither
|
||||
* NGHTTP2_HEADERS nor NGHTTP2_PUSH_PROMISE, this function does
|
||||
* nothing.
|
||||
*/
|
||||
void nghttp2_http_record_request_method(nghttp2_stream *stream,
|
||||
nghttp2_frame *frame);
|
||||
|
||||
#endif /* NGHTTP2_HTTP_H */
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* nghttp2 - HTTP/2 C Library
|
||||
*
|
||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef NGHTTP2_INT_H
|
||||
#define NGHTTP2_INT_H
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif /* HAVE_CONFIG_H */
|
||||
|
||||
/* Macros, types and constants for internal use */
|
||||
|
||||
#ifdef DEBUGBUILD
|
||||
#define DEBUGF(x) x
|
||||
#else
|
||||
#define DEBUGF(x) \
|
||||
do { \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
/* "less" function, return nonzero if |lhs| is less than |rhs|. */
|
||||
typedef int (*nghttp2_less)(const void *lhs, const void *rhs);
|
||||
|
||||
/* Internal error code. They must be in the range [-499, -100],
|
||||
inclusive. */
|
||||
typedef enum {
|
||||
NGHTTP2_ERR_CREDENTIAL_PENDING = -101,
|
||||
NGHTTP2_ERR_IGN_HEADER_BLOCK = -103,
|
||||
NGHTTP2_ERR_IGN_PAYLOAD = -104,
|
||||
/*
|
||||
* Invalid HTTP header field was received but it can be treated as
|
||||
* if it was not received because of compatibility reasons.
|
||||
*/
|
||||
NGHTTP2_ERR_IGN_HTTP_HEADER = -105
|
||||
} nghttp2_internal_error;
|
||||
|
||||
#endif /* NGHTTP2_INT_H */
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user