diff --git a/boards.txt b/boards.txt index 95a77aad..c8eb59e3 100644 --- a/boards.txt +++ b/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 diff --git a/package/package_esp32_index.template.json b/package/package_esp32_index.template.json index cd341bf8..62cb662b 100644 --- a/package/package_esp32_index.template.json +++ b/package/package_esp32_index.template.json @@ -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" } ] } diff --git a/platform.txt b/platform.txt index 3a8b30b4..d770a19e 100644 --- a/platform.txt +++ b/platform.txt @@ -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" diff --git a/tools/esptool.py b/tools/esptool.py index c39fcd21..86e5ab19 100755 --- a/tools/esptool.py +++ b/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._port.baudrate = baud + 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('> 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. + + # 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 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 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 + + 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 # - # TODO: intelligently order segments to reduce wastage - # by squeezing smaller DRAM/IRAM segments into the - # 64kB padding space. - IROM_ALIGN = 65536 + # (this is because the segment's vaddr may not be IROM_ALIGNed, more likely is aligned + # IROM_ALIGN+0x18 to account for the binary file header + align_past = (segment.addr % IROM_ALIGN) - self.SEG_HEADER_LEN + pad_len = (IROM_ALIGN - (f.tell() % IROM_ALIGN)) + align_past + if pad_len == 0 or pad_len == IROM_ALIGN: + return 0 # already aligned - # check for multiple ELF sections that live 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: - 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 + # subtract SEG_HEADER_LEN a second time, as the padding block has a header as well + pad_len -= self.SEG_HEADER_LEN + if pad_len < 0: + pad_len += IROM_ALIGN + return pad_len - if self.is_flash_addr(segment.addr): - # Actual alignment required for the 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. - align_past = (segment.addr % IROM_ALIGN) - self.SEG_HEADER_LEN - assert (align_past + self.SEG_HEADER_LEN) == (segment.addr % IROM_ALIGN) - - # 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 - 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 + # 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("> 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 - 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) + # 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] -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_freq = flash_size_freq & 0x0F + if args.flash_freq != 'keep': + flash_freq = {'40m':0, '26m':1, '20m':2, '80m': 0xf}[args.flash_freq] + + 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='
', 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)) diff --git a/tools/gen_esp32part.exe b/tools/gen_esp32part.exe index 11764a55..6379500d 100644 Binary files a/tools/gen_esp32part.exe and b/tools/gen_esp32part.exe differ diff --git a/tools/gen_esp32part.py b/tools/gen_esp32part.py index d57059f4..2600ac21 100755 --- a/tools/gen_esp32part.py +++ b/tools/gen_esp32part.py @@ -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() + with sys.stdout if args.output == '-' else open(args.output, 'w') as f: + f.write(output) else: output = table.to_binary() - with sys.stdout if args.output == '-' else open(args.output, 'w') as f: - f.write(output) + 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) diff --git a/tools/platformio-build.py b/tools/platformio-build.py index 648aae77..a9117b6d 100644 --- a/tools/platformio-build.py +++ b/tools/platformio-build.py @@ -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=[ diff --git a/tools/sdk/bin/bootloader.bin b/tools/sdk/bin/bootloader.bin index e5275599..bd9688f2 100644 Binary files a/tools/sdk/bin/bootloader.bin and b/tools/sdk/bin/bootloader.bin differ diff --git a/tools/sdk/bin/bootloader_qio.bin b/tools/sdk/bin/bootloader_qio.bin new file mode 100644 index 00000000..e1e80b80 Binary files /dev/null and b/tools/sdk/bin/bootloader_qio.bin differ diff --git a/tools/sdk/include/app_trace/esp_ota_ops.h b/tools/sdk/include/app_trace/esp_ota_ops.h new file mode 100755 index 00000000..33c03030 --- /dev/null +++ b/tools/sdk/include/app_trace/esp_ota_ops.h @@ -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 +#include +#include +#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 */ diff --git a/tools/sdk/include/bluedroid/allocator.h b/tools/sdk/include/bluedroid/allocator.h index 17a3a246..82ef5b0e 100644 --- a/tools/sdk/include/bluedroid/allocator.h +++ b/tools/sdk/include/bluedroid/allocator.h @@ -21,6 +21,7 @@ #include //#include +#include "sdkconfig.h" typedef void *(*alloc_fn)(size_t size); typedef void (*free_fn)(void *ptr); diff --git a/tools/sdk/include/bluedroid/bt_defs.h b/tools/sdk/include/bluedroid/bt_defs.h index 3f12d578..5d0dd3d9 100644 --- a/tools/sdk/include/bluedroid/bt_defs.h +++ b/tools/sdk/include/bluedroid/bt_defs.h @@ -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 diff --git a/tools/sdk/include/bluedroid/bt_target.h b/tools/sdk/include/bluedroid/bt_target.h index 02c0486a..a426d69f 100644 --- a/tools/sdk/include/bluedroid/bt_target.h +++ b/tools/sdk/include/bluedroid/bt_target.h @@ -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 diff --git a/tools/sdk/include/bluedroid/bt_trace.h b/tools/sdk/include/bluedroid/bt_trace.h index 6324adf9..d6ded219 100644 --- a/tools/sdk/include/bluedroid/bt_trace.h +++ b/tools/sdk/include/bluedroid/bt_trace.h @@ -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 diff --git a/tools/sdk/include/bluedroid/bt_types.h b/tools/sdk/include/bluedroid/bt_types.h index fdcd1562..c60fd354 100644 --- a/tools/sdk/include/bluedroid/bt_types.h +++ b/tools/sdk/include/bluedroid/bt_types.h @@ -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 */ diff --git a/tools/sdk/include/bluedroid/bta_api.h b/tools/sdk/include/bluedroid/bta_api.h index 501b8a5a..f21803b1 100644 --- a/tools/sdk/include/bluedroid/bta_api.h +++ b/tools/sdk/include/bluedroid/bta_api.h @@ -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); /******************************************************************************* ** diff --git a/tools/sdk/include/bluedroid/bta_gatt_api.h b/tools/sdk/include/bluedroid/bta_gatt_api.h index c4e9ace6..349c7c6a 100644 --- a/tools/sdk/include/bluedroid/bta_gatt_api.h +++ b/tools/sdk/include/bluedroid/bta_gatt_api.h @@ -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,14 +95,19 @@ 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_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 */ +#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 */ typedef UINT8 tBTA_GATT_STATUS; @@ -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); diff --git a/tools/sdk/include/bluedroid/bta_gattc_int.h b/tools/sdk/include/bluedroid/bta_gattc_int.h index d04097b7..21cd4259 100644 --- a/tools/sdk/include/bluedroid/bta_gattc_int.h +++ b/tools/sdk/include/bluedroid/bta_gattc_int.h @@ -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 diff --git a/tools/sdk/include/bluedroid/btc_ble_storage.h b/tools/sdk/include/bluedroid/btc_ble_storage.h index 2884d6ac..cbb6229c 100644 --- a/tools/sdk/include/bluedroid/btc_ble_storage.h +++ b/tools/sdk/include/bluedroid/btc_ble_storage.h @@ -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); diff --git a/tools/sdk/include/bluedroid/btc_config.h b/tools/sdk/include/bluedroid/btc_config.h index 1472cc83..e0d6d6ec 100644 --- a/tools/sdk/include/bluedroid/btc_config.h +++ b/tools/sdk/include/bluedroid/btc_config.h @@ -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 diff --git a/tools/sdk/include/bluedroid/btc_gap_ble.h b/tools/sdk/include/bluedroid/btc_gap_ble.h index b26c2b80..78c2db02 100644 --- a/tools/sdk/include/bluedroid/btc_gap_ble.h +++ b/tools/sdk/include/bluedroid/btc_gap_ble.h @@ -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); diff --git a/tools/sdk/include/bluedroid/btc_gattc.h b/tools/sdk/include/bluedroid/btc_gattc.h index 25286683..1374dc0a 100644 --- a/tools/sdk/include/bluedroid/btc_gattc.h +++ b/tools/sdk/include/bluedroid/btc_gattc.h @@ -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); diff --git a/tools/sdk/include/bluedroid/btm_api.h b/tools/sdk/include/bluedroid/btm_api.h index 5a0d6fa4..2976e497 100644 --- a/tools/sdk/include/bluedroid/btm_api.h +++ b/tools/sdk/include/bluedroid/btm_api.h @@ -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 */ diff --git a/tools/sdk/include/bluedroid/btm_ble_api.h b/tools/sdk/include/bluedroid/btm_ble_api.h index 4d3f5f88..92781245 100644 --- a/tools/sdk/include/bluedroid/btm_ble_api.h +++ b/tools/sdk/include/bluedroid/btm_ble_api.h @@ -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 diff --git a/tools/sdk/include/bluedroid/btm_ble_int.h b/tools/sdk/include/bluedroid/btm_ble_int.h index 8345777c..055591d7 100644 --- a/tools/sdk/include/bluedroid/btm_ble_int.h +++ b/tools/sdk/include/bluedroid/btm_ble_int.h @@ -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; diff --git a/tools/sdk/include/bluedroid/btm_int.h b/tools/sdk/include/bluedroid/btm_int.h index c732edd1..4d263d57 100644 --- a/tools/sdk/include/bluedroid/btm_int.h +++ b/tools/sdk/include/bluedroid/btm_int.h @@ -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); diff --git a/tools/sdk/include/bluedroid/btu.h b/tools/sdk/include/bluedroid/btu.h index d82d96d7..b2d72364 100644 --- a/tools/sdk/include/bluedroid/btu.h +++ b/tools/sdk/include/bluedroid/btu.h @@ -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. */ diff --git a/tools/sdk/include/bluedroid/config.h b/tools/sdk/include/bluedroid/config.h index 4f0e2cd8..41f5ddb1 100644 --- a/tools/sdk/include/bluedroid/config.h +++ b/tools/sdk/include/bluedroid/config.h @@ -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 diff --git a/tools/sdk/include/bluedroid/esp_bt_defs.h b/tools/sdk/include/bluedroid/esp_bt_defs.h index 85b0aff9..e2b9553b 100644 --- a/tools/sdk/include/bluedroid/esp_bt_defs.h +++ b/tools/sdk/include/bluedroid/esp_bt_defs.h @@ -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 diff --git a/tools/sdk/include/bluedroid/esp_gap_ble_api.h b/tools/sdk/include/bluedroid/esp_gap_ble_api.h index 45c14b50..0492bd5d 100644 --- a/tools/sdk/include/bluedroid/esp_gap_ble_api.h +++ b/tools/sdk/include/bluedroid/esp_gap_ble_api.h @@ -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 */ -typedef uint8_t esp_ble_key_type_t; +/* 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 */ @@ -364,7 +392,7 @@ typedef struct { */ typedef struct { - esp_bd_addr_t bd_addr; /*!< BD address peer device. */ + esp_bd_addr_t bd_addr; /*!< BD address peer device. */ bool key_present; /*!< Valid link key value in key element */ esp_link_key key; /*!< Link key associated with peer device. */ uint8_t key_type; /*!< The type of Link Key */ @@ -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; /** @@ -699,7 +753,7 @@ esp_err_t esp_ble_gap_config_scan_rsp_data_raw(uint8_t *raw_data, uint32_t raw_d * @param[out] len : the length of the param value * * @return - ESP_OK : success -* - other : failed +* - other : failed * */ esp_err_t esp_ble_gap_set_security_param(esp_ble_sm_param_t param_type, @@ -724,8 +778,8 @@ esp_err_t esp_ble_gap_security_rsp(esp_bd_addr_t bd_addr, bool accept); * * @param[in] bd_addr : the address of the peer device need to encryption * @param[in] sec_act : This is the security action to indicate -* what kind of BLE security level is required for -* the BLE link if the BLE is supported +* what kind of BLE security level is required for +* the BLE link if the BLE is supported * * @return - ESP_OK : success * - other : failed @@ -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 diff --git a/tools/sdk/include/bluedroid/esp_gatt_defs.h b/tools/sdk/include/bluedroid/esp_gatt_defs.h index b092e2c8..d0f73dd3 100644 --- a/tools/sdk/include/bluedroid/esp_gatt_defs.h +++ b/tools/sdk/include/bluedroid/esp_gatt_defs.h @@ -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 diff --git a/tools/sdk/include/bluedroid/esp_gattc_api.h b/tools/sdk/include/bluedroid/esp_gattc_api.h index ae53bf57..6e6f9396 100644 --- a/tools/sdk/include/bluedroid/esp_gattc_api.h +++ b/tools/sdk/include/bluedroid/esp_gattc_api.h @@ -25,45 +25,47 @@ extern "C" { /// GATT Client callback function events 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_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_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 */ - ESP_GATTC_WRITE_DESCR_EVT = 9, /*!< When GATT characteristic descriptor write completes, the event comes */ - ESP_GATTC_NOTIFY_EVT = 10, /*!< When GATT notification or indication arrives, the event comes */ - ESP_GATTC_PREP_WRITE_EVT = 11, /*!< When GATT prepare-write operation completes, the event comes */ - ESP_GATTC_EXEC_EVT = 12, /*!< When write execution completes, the event comes */ - ESP_GATTC_ACL_EVT = 13, /*!< When ACL connection is up, the event comes */ - ESP_GATTC_CANCEL_OPEN_EVT = 14, /*!< When GATT client ongoing connection is cancelled, the event comes */ - ESP_GATTC_SRVC_CHG_EVT = 15, /*!< When "service changed" occurs, the event comes */ - ESP_GATTC_ENC_CMPL_CB_EVT = 17, /*!< When encryption procedure completes, the event comes */ - ESP_GATTC_CFG_MTU_EVT = 18, /*!< When configuration of MTU completes, the event comes */ - ESP_GATTC_ADV_DATA_EVT = 19, /*!< When advertising of data, the event comes */ - ESP_GATTC_MULT_ADV_ENB_EVT = 20, /*!< When multi-advertising is enabled, the event comes */ - ESP_GATTC_MULT_ADV_UPD_EVT = 21, /*!< When multi-advertising parameters are updated, the event comes */ - ESP_GATTC_MULT_ADV_DATA_EVT = 22, /*!< When multi-advertising data arrives, the event comes */ - ESP_GATTC_MULT_ADV_DIS_EVT = 23, /*!< When multi-advertising is disabled, the event comes */ - ESP_GATTC_CONGEST_EVT = 24, /*!< When GATT connection congestion comes, the event comes */ - ESP_GATTC_BTH_SCAN_ENB_EVT = 25, /*!< When batch scan is enabled, the event comes */ - ESP_GATTC_BTH_SCAN_CFG_EVT = 26, /*!< When batch scan storage is configured, the event comes */ - ESP_GATTC_BTH_SCAN_RD_EVT = 27, /*!< When Batch scan read event is reported, the event comes */ - ESP_GATTC_BTH_SCAN_THR_EVT = 28, /*!< When Batch scan threshold is set, the event comes */ - ESP_GATTC_BTH_SCAN_PARAM_EVT = 29, /*!< When Batch scan parameters are set, the event comes */ - ESP_GATTC_BTH_SCAN_DIS_EVT = 30, /*!< When Batch scan is disabled, the event comes */ - ESP_GATTC_SCAN_FLT_CFG_EVT = 31, /*!< When Scan filter configuration completes, the event comes */ - ESP_GATTC_SCAN_FLT_PARAM_EVT = 32, /*!< When Scan filter parameters are set, the event comes */ - ESP_GATTC_SCAN_FLT_STATUS_EVT = 33, /*!< When Scan filter status is reported, the event comes */ - ESP_GATTC_ADV_VSC_EVT = 34, /*!< When advertising vendor spec content event is reported, the event comes */ - ESP_GATTC_GET_CHAR_EVT = 35, /*!< When characteristic is got from GATT server, the event comes */ - ESP_GATTC_GET_DESCR_EVT = 36, /*!< When characteristic descriptor is got from GATT server, the event comes */ - 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_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 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 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 */ + ESP_GATTC_WRITE_DESCR_EVT = 9, /*!< When GATT characteristic descriptor write completes, the event comes */ + ESP_GATTC_NOTIFY_EVT = 10, /*!< When GATT notification or indication arrives, the event comes */ + ESP_GATTC_PREP_WRITE_EVT = 11, /*!< When GATT prepare-write operation completes, the event comes */ + ESP_GATTC_EXEC_EVT = 12, /*!< When write execution completes, the event comes */ + ESP_GATTC_ACL_EVT = 13, /*!< When ACL connection is up, the event comes */ + ESP_GATTC_CANCEL_OPEN_EVT = 14, /*!< When GATT client ongoing connection is cancelled, the event comes */ + ESP_GATTC_SRVC_CHG_EVT = 15, /*!< When "service changed" occurs, the event comes */ + ESP_GATTC_ENC_CMPL_CB_EVT = 17, /*!< When encryption procedure completes, the event comes */ + ESP_GATTC_CFG_MTU_EVT = 18, /*!< When configuration of MTU completes, the event comes */ + ESP_GATTC_ADV_DATA_EVT = 19, /*!< When advertising of data, the event comes */ + ESP_GATTC_MULT_ADV_ENB_EVT = 20, /*!< When multi-advertising is enabled, the event comes */ + ESP_GATTC_MULT_ADV_UPD_EVT = 21, /*!< When multi-advertising parameters are updated, the event comes */ + ESP_GATTC_MULT_ADV_DATA_EVT = 22, /*!< When multi-advertising data arrives, the event comes */ + ESP_GATTC_MULT_ADV_DIS_EVT = 23, /*!< When multi-advertising is disabled, the event comes */ + ESP_GATTC_CONGEST_EVT = 24, /*!< When GATT connection congestion comes, the event comes */ + ESP_GATTC_BTH_SCAN_ENB_EVT = 25, /*!< When batch scan is enabled, the event comes */ + ESP_GATTC_BTH_SCAN_CFG_EVT = 26, /*!< When batch scan storage is configured, the event comes */ + ESP_GATTC_BTH_SCAN_RD_EVT = 27, /*!< When Batch scan read event is reported, the event comes */ + ESP_GATTC_BTH_SCAN_THR_EVT = 28, /*!< When Batch scan threshold is set, the event comes */ + ESP_GATTC_BTH_SCAN_PARAM_EVT = 29, /*!< When Batch scan parameters are set, the event comes */ + ESP_GATTC_BTH_SCAN_DIS_EVT = 30, /*!< When Batch scan is disabled, the event comes */ + ESP_GATTC_SCAN_FLT_CFG_EVT = 31, /*!< When Scan filter configuration completes, the event comes */ + ESP_GATTC_SCAN_FLT_PARAM_EVT = 32, /*!< When Scan filter parameters are set, the event comes */ + ESP_GATTC_SCAN_FLT_STATUS_EVT = 33, /*!< When Scan filter status is reported, the event comes */ + ESP_GATTC_ADV_VSC_EVT = 34, /*!< When advertising vendor spec content event is reported, the event comes */ + ESP_GATTC_GET_CHAR_EVT = 35, /*!< When characteristic is got from GATT server, the event comes */ + ESP_GATTC_GET_DESCR_EVT = 36, /*!< When characteristic descriptor is got from GATT server, the event comes */ + 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,15 +135,22 @@ 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_len; /*!< Characteristic value length */ - } read; /*!< Gatt client callback param of ESP_GATTC_READ_CHAR_EVT */ + + 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, 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 */ /** * @brief ESP_GATTC_WRITE_CHAR_EVT, ESP_GATTC_PREP_WRITE_EVT, ESP_GATTC_WRITE_DESCR_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 diff --git a/tools/sdk/include/bluedroid/esp_gatts_api.h b/tools/sdk/include/bluedroid/esp_gatts_api.h index 777bbec3..6bbc370a 100644 --- a/tools/sdk/include/bluedroid/esp_gatts_api.h +++ b/tools/sdk/include/bluedroid/esp_gatts_api.h @@ -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 */ diff --git a/tools/sdk/include/bluedroid/gatt_api.h b/tools/sdk/include/bluedroid/gatt_api.h index 0017d0fa..76d8c465 100644 --- a/tools/sdk/include/bluedroid/gatt_api.h +++ b/tools/sdk/include/bluedroid/gatt_api.h @@ -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; diff --git a/tools/sdk/include/bluedroid/l2c_int.h b/tools/sdk/include/bluedroid/l2c_int.h index 56fdd0c9..b8865917 100644 --- a/tools/sdk/include/bluedroid/l2c_int.h +++ b/tools/sdk/include/bluedroid/l2c_int.h @@ -53,9 +53,10 @@ #define L2CAP_DELAY_CHECK_SM4 2 /* 2 seconds */ #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_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 */ +#define L2CAP_BLE_CONN_PARAM_UPD_TOUT 30 /* 30 seconds */ /* quick timer uses millisecond unit */ #define L2CAP_DEFAULT_RETRANS_TOUT 2000 /* 2000 milliseconds */ @@ -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); diff --git a/tools/sdk/include/bluedroid/thread.h b/tools/sdk/include/bluedroid/thread.h index c10f8c2a..4d2b4359 100644 --- a/tools/sdk/include/bluedroid/thread.h +++ b/tools/sdk/include/bluedroid/thread.h @@ -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__ */ diff --git a/tools/sdk/include/bootloader_support/esp_image_format.h b/tools/sdk/include/bootloader_support/esp_image_format.h index e0759c3c..25d81d83 100644 --- a/tools/sdk/include/bootloader_support/esp_image_format.h +++ b/tools/sdk/include/bootloader_support/esp_image_format.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 #include +#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 diff --git a/tools/sdk/include/bootloader_support/esp_secure_boot.h b/tools/sdk/include/bootloader_support/esp_secure_boot.h index 8e33a8b4..6aa4b628 100644 --- a/tools/sdk/include/bootloader_support/esp_secure_boot.h +++ b/tools/sdk/include/bootloader_support/esp_secure_boot.h @@ -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 #include #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 diff --git a/tools/sdk/include/bt/bt.h b/tools/sdk/include/bt/bt.h index 5a244e0c..e2d7d842 100644 --- a/tools/sdk/include/bt/bt.h +++ b/tools/sdk/include/bt/bt.h @@ -19,6 +19,7 @@ #include #include "esp_err.h" #include "sdkconfig.h" +#include "esp_task.h" #ifdef __cplusplus extern "C" { @@ -30,8 +31,10 @@ extern "C" { * some options or parameters of some functions enabled by config mask. */ typedef struct { - 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 */ + 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; #ifdef CONFIG_BT_ENABLED @@ -48,9 +51,11 @@ typedef struct { #define BT_HCI_UART_BAUDRATE_DEFAULT 921600 #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,\ +#define BT_CONTROLLER_INIT_CONFIG_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 diff --git a/tools/sdk/include/config/sdkconfig.h b/tools/sdk/include/config/sdkconfig.h index aba1f522..a4610695 100644 --- a/tools/sdk/include/config/sdkconfig.h +++ b/tools/sdk/include/config/sdkconfig.h @@ -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 diff --git a/tools/sdk/include/driver/driver/adc.h b/tools/sdk/include/driver/driver/adc.h index d81be4ff..19068a23 100644 --- a/tools/sdk/include/driver/driver/adc.h +++ b/tools/sdk/include/driver/driver/adc.h @@ -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 * diff --git a/tools/sdk/include/driver/driver/dac.h b/tools/sdk/include/driver/driver/dac.h index 07e1ff80..842894d0 100644 --- a/tools/sdk/include/driver/driver/dac.h +++ b/tools/sdk/include/driver/driver/dac.h @@ -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. diff --git a/tools/sdk/include/driver/driver/gpio.h b/tools/sdk/include/driver/driver/gpio.h index 6c79f7b8..af727a8d 100644 --- a/tools/sdk/include/driver/driver/gpio.h +++ b/tools/sdk/include/driver/driver/gpio.h @@ -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. diff --git a/tools/sdk/include/driver/driver/rtc_cntl.h b/tools/sdk/include/driver/driver/rtc_cntl.h new file mode 100644 index 00000000..a7974571 --- /dev/null +++ b/tools/sdk/include/driver/driver/rtc_cntl.h @@ -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 +#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); diff --git a/tools/sdk/include/driver/driver/sdmmc_defs.h b/tools/sdk/include/driver/driver/sdmmc_defs.h index 9913bfd1..455d1c7a 100644 --- a/tools/sdk/include/driver/driver/sdmmc_defs.h +++ b/tools/sdk/include/driver/driver/sdmmc_defs.h @@ -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) diff --git a/tools/sdk/include/driver/driver/sdmmc_types.h b/tools/sdk/include/driver/driver/sdmmc_types.h index dfbd2439..d9ffde3f 100644 --- a/tools/sdk/include/driver/driver/sdmmc_types.h +++ b/tools/sdk/include/driver/driver/sdmmc_types.h @@ -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 */ diff --git a/tools/sdk/include/driver/driver/sdspi_host.h b/tools/sdk/include/driver/driver/sdspi_host.h new file mode 100644 index 00000000..72bd9f38 --- /dev/null +++ b/tools/sdk/include/driver/driver/sdspi_host.h @@ -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 +#include +#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 diff --git a/tools/sdk/include/driver/driver/spi_common.h b/tools/sdk/include/driver/driver/spi_common.h index 5d4270fd..53cde6ff 100644 --- a/tools/sdk/include/driver/driver/spi_common.h +++ b/tools/sdk/include/driver/driver/spi_common.h @@ -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. @@ -230,4 +232,4 @@ void spicommon_dmaworkaround_transfer_active(int dmachan); } #endif -#endif \ No newline at end of file +#endif diff --git a/tools/sdk/include/driver/driver/spi_master.h b/tools/sdk/include/driver/driver/spi_master.h index 29b408af..79eb52d3 100644 --- a/tools/sdk/include/driver/driver/spi_master.h +++ b/tools/sdk/include/driver/driver/spi_master.h @@ -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. diff --git a/tools/sdk/include/driver/driver/uart.h b/tools/sdk/include/driver/driver/uart.h index 748735c5..9bd35e43 100644 --- a/tools/sdk/include/driver/driver/uart.h +++ b/tools/sdk/include/driver/driver/uart.h @@ -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_PATTERN_DET, /*!< UART pattern detected */ UART_EVENT_MAX, /*!< UART event max index*/ - UART_PATTERN_DET, /*!< UART pattern detected */ } 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. diff --git a/tools/sdk/include/esp32/esp_app_trace.h b/tools/sdk/include/esp32/esp_app_trace.h deleted file mode 100644 index bd33e589..00000000 --- a/tools/sdk/include/esp32/esp_app_trace.h +++ /dev/null @@ -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 -#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 diff --git a/tools/sdk/include/soc/esp_brownout.h b/tools/sdk/include/esp32/esp_brownout.h similarity index 100% rename from tools/sdk/include/soc/esp_brownout.h rename to tools/sdk/include/esp32/esp_brownout.h diff --git a/tools/sdk/include/esp32/esp_clk.h b/tools/sdk/include/esp32/esp_clk.h index 0cedf037..7b9c64c6 100644 --- a/tools/sdk/include/esp32/esp_clk.h +++ b/tools/sdk/include/esp32/esp_clk.h @@ -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); + diff --git a/tools/sdk/include/esp32/esp_dport_access.h b/tools/sdk/include/esp32/esp_dport_access.h index 14b589aa..8b081c5a 100644 --- a/tools/sdk/include/esp32/esp_dport_access.h +++ b/tools/sdk/include/esp32/esp_dport_access.h @@ -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_ */ diff --git a/tools/sdk/include/esp32/esp_event.h b/tools/sdk/include/esp32/esp_event.h index 8e6e1833..7b3a8573 100644 --- a/tools/sdk/include/esp32/esp_event.h +++ b/tools/sdk/include/esp32/esp_event.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 */ diff --git a/tools/sdk/include/esp32/esp_gdbstub.h b/tools/sdk/include/esp32/esp_gdbstub.h index bc26f294..9e7243aa 100644 --- a/tools/sdk/include/esp32/esp_gdbstub.h +++ b/tools/sdk/include/esp32/esp_gdbstub.h @@ -17,6 +17,6 @@ #include #include "freertos/xtensa_api.h" -void esp_gdbstub_panic_handler(XtExcFrame *frame); +void esp_gdbstub_panic_handler(XtExcFrame *frame) __attribute__((noreturn)); -#endif \ No newline at end of file +#endif diff --git a/tools/sdk/include/esp32/esp_heap_alloc_caps.h b/tools/sdk/include/esp32/esp_heap_alloc_caps.h deleted file mode 100644 index a0e40a7c..00000000 --- a/tools/sdk/include/esp32/esp_heap_alloc_caps.h +++ /dev/null @@ -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 \ No newline at end of file diff --git a/tools/sdk/include/esp32/esp_intr_alloc.h b/tools/sdk/include/esp32/esp_intr_alloc.h index 7195d07d..63555c20 100644 --- a/tools/sdk/include/esp32/esp_intr_alloc.h +++ b/tools/sdk/include/esp32/esp_intr_alloc.h @@ -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 * diff --git a/tools/sdk/include/esp32/esp_ipc.h b/tools/sdk/include/esp32/esp_ipc.h index a77b4932..28b17a9a 100644 --- a/tools/sdk/include/esp32/esp_ipc.h +++ b/tools/sdk/include/esp32/esp_ipc.h @@ -17,6 +17,10 @@ #include +#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__ */ diff --git a/tools/sdk/include/esp32/esp_system.h b/tools/sdk/include/esp32/esp_system.h index 63592081..3921dfb8 100644 --- a/tools/sdk/include/esp32/esp_system.h +++ b/tools/sdk/include/esp32/esp_system.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); diff --git a/tools/sdk/include/esp32/esp_wifi.h b/tools/sdk/include/esp32/esp_wifi.h index 10fd409c..2881eb1f 100755 --- a/tools/sdk/include/esp32/esp_wifi.h +++ b/tools/sdk/include/esp32/esp_wifi.h @@ -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 diff --git a/tools/sdk/include/esp32/esp_wifi_types.h b/tools/sdk/include/esp32/esp_wifi_types.h index 7dd2ee4e..2410b73c 100755 --- a/tools/sdk/include/esp32/esp_wifi_types.h +++ b/tools/sdk/include/esp32/esp_wifi_types.h @@ -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 diff --git a/tools/sdk/include/esp32/heap_alloc_caps.h b/tools/sdk/include/esp32/heap_alloc_caps.h deleted file mode 100644 index edab15d5..00000000 --- a/tools/sdk/include/esp32/heap_alloc_caps.h +++ /dev/null @@ -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" diff --git a/tools/sdk/include/esp32/rom/gpio.h b/tools/sdk/include/esp32/rom/gpio.h index b740a020..bd1777c6 100644 --- a/tools/sdk/include/esp32/rom/gpio.h +++ b/tools/sdk/include/esp32/rom/gpio.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; diff --git a/tools/sdk/include/esp32/rom/rtc.h b/tools/sdk/include/esp32/rom/rtc.h index 9ea3126a..3161fb27 100644 --- a/tools/sdk/include/esp32/rom/rtc.h +++ b/tools/sdk/include/esp32/rom/rtc.h @@ -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 diff --git a/tools/sdk/include/ethernet/eth_phy/phy.h b/tools/sdk/include/ethernet/eth_phy/phy.h index 44edd749..18b8f3f6 100644 --- a/tools/sdk/include/ethernet/eth_phy/phy.h +++ b/tools/sdk/include/ethernet/eth_phy/phy.h @@ -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); diff --git a/tools/sdk/include/ethernet/eth_phy/phy_lan8720.h b/tools/sdk/include/ethernet/eth_phy/phy_lan8720.h index 7bde42ec..8c579ef5 100644 --- a/tools/sdk/include/ethernet/eth_phy/phy_lan8720.h +++ b/tools/sdk/include/ethernet/eth_phy/phy_lan8720.h @@ -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. diff --git a/tools/sdk/include/ethernet/eth_phy/phy_tlk110.h b/tools/sdk/include/ethernet/eth_phy/phy_tlk110.h index 1019044e..ff61c322 100644 --- a/tools/sdk/include/ethernet/eth_phy/phy_tlk110.h +++ b/tools/sdk/include/ethernet/eth_phy/phy_tlk110.h @@ -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. diff --git a/tools/sdk/include/fatfs/esp_vfs_fat.h b/tools/sdk/include/fatfs/esp_vfs_fat.h index 140f8bdc..278e427c 100644 --- a/tools/sdk/include/fatfs/esp_vfs_fat.h +++ b/tools/sdk/include/fatfs/esp_vfs_fat.h @@ -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 diff --git a/tools/sdk/include/freertos/freertos/FreeRTOS.h b/tools/sdk/include/freertos/freertos/FreeRTOS.h index 0e93acf2..31b66fb8 100644 --- a/tools/sdk/include/freertos/freertos/FreeRTOS.h +++ b/tools/sdk/include/freertos/freertos/FreeRTOS.h @@ -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 diff --git a/tools/sdk/include/freertos/freertos/FreeRTOSConfig.h b/tools/sdk/include/freertos/freertos/FreeRTOSConfig.h index 250879f3..56d0e23d 100644 --- a/tools/sdk/include/freertos/freertos/FreeRTOSConfig.h +++ b/tools/sdk/include/freertos/freertos/FreeRTOSConfig.h @@ -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 */ diff --git a/tools/sdk/include/freertos/freertos/heap_regions.h b/tools/sdk/include/freertos/freertos/heap_regions.h deleted file mode 100644 index 090c5b9b..00000000 --- a/tools/sdk/include/freertos/freertos/heap_regions.h +++ /dev/null @@ -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 \ No newline at end of file diff --git a/tools/sdk/include/freertos/freertos/heap_regions_debug.h b/tools/sdk/include/freertos/freertos/heap_regions_debug.h deleted file mode 100644 index dca9531d..00000000 --- a/tools/sdk/include/freertos/freertos/heap_regions_debug.h +++ /dev/null @@ -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 diff --git a/tools/sdk/include/freertos/freertos/portable.h b/tools/sdk/include/freertos/freertos/portable.h index e46ec17f..45eaf739 100644 --- a/tools/sdk/include/freertos/freertos/portable.h +++ b/tools/sdk/include/freertos/freertos/portable.h @@ -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 */ diff --git a/tools/sdk/include/freertos/freertos/portmacro.h b/tools/sdk/include/freertos/freertos/portmacro.h index 157b9156..a909b329 100644 --- a/tools/sdk/include/freertos/freertos/portmacro.h +++ b/tools/sdk/include/freertos/freertos/portmacro.h @@ -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" diff --git a/tools/sdk/include/freertos/freertos/task.h b/tools/sdk/include/freertos/freertos/task.h index 590b07a2..2438d960 100644 --- a/tools/sdk/include/freertos/freertos/task.h +++ b/tools/sdk/include/freertos/freertos/task.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 - *
uint16_t uxTaskGetNumberOfTasks( void );
+ *
UBaseType_t uxTaskGetNumberOfTasks( void );
* * @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 + *
uint8_t* pxTaskGetStackStart( TaskHandle_t xTask);
+ * + * 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 diff --git a/tools/sdk/include/freertos/freertos/xtensa_api.h b/tools/sdk/include/freertos/freertos/xtensa_api.h index 87922691..19630ce5 100644 --- a/tools/sdk/include/freertos/freertos/xtensa_api.h +++ b/tools/sdk/include/freertos/freertos/xtensa_api.h @@ -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__ */ diff --git a/tools/sdk/include/heap/esp_ota_ops.h b/tools/sdk/include/heap/esp_ota_ops.h new file mode 100755 index 00000000..33c03030 --- /dev/null +++ b/tools/sdk/include/heap/esp_ota_ops.h @@ -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 +#include +#include +#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 */ diff --git a/tools/sdk/include/log/esp_log.h b/tools/sdk/include/log/esp_log.h index 6fda8d60..b3918a93 100644 --- a/tools/sdk/include/log/esp_log.h +++ b/tools/sdk/include/log/esp_log.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" diff --git a/tools/sdk/include/lwip/arch/cc.h b/tools/sdk/include/lwip/arch/cc.h index 6fc1da18..cba0b365 100644 --- a/tools/sdk/include/lwip/arch/cc.h +++ b/tools/sdk/include/lwip/arch/cc.h @@ -36,6 +36,8 @@ #include #include +#include +#include #include "arch/sys_arch.h" @@ -67,10 +69,26 @@ typedef int sys_prot_t; #include #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__ */ diff --git a/tools/sdk/include/lwip/arch/sys_arch.h b/tools/sdk/include/lwip/arch/sys_arch.h index a8633482..8d30ef17 100644 --- a/tools/sdk/include/lwip/arch/sys_arch.h +++ b/tools/sdk/include/lwip/arch/sys_arch.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); diff --git a/tools/sdk/include/lwip/lwip/netif.h b/tools/sdk/include/lwip/lwip/netif.h index 13cbb798..f5ca067e 100755 --- a/tools/sdk/include/lwip/lwip/netif.h +++ b/tools/sdk/include/lwip/lwip/netif.h @@ -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); diff --git a/tools/sdk/include/lwip/lwipopts.h b/tools/sdk/include/lwip/lwipopts.h index 3b8c5485..61a99382 100644 --- a/tools/sdk/include/lwip/lwipopts.h +++ b/tools/sdk/include/lwip/lwipopts.h @@ -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) diff --git a/tools/sdk/include/lwip/port/arch/cc.h b/tools/sdk/include/lwip/port/arch/cc.h index 6fc1da18..cba0b365 100644 --- a/tools/sdk/include/lwip/port/arch/cc.h +++ b/tools/sdk/include/lwip/port/arch/cc.h @@ -36,6 +36,8 @@ #include #include +#include +#include #include "arch/sys_arch.h" @@ -67,10 +69,26 @@ typedef int sys_prot_t; #include #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__ */ diff --git a/tools/sdk/include/lwip/port/arch/sys_arch.h b/tools/sdk/include/lwip/port/arch/sys_arch.h index a8633482..8d30ef17 100644 --- a/tools/sdk/include/lwip/port/arch/sys_arch.h +++ b/tools/sdk/include/lwip/port/arch/sys_arch.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); diff --git a/tools/sdk/include/lwip/port/lwipopts.h b/tools/sdk/include/lwip/port/lwipopts.h index 3b8c5485..61a99382 100644 --- a/tools/sdk/include/lwip/port/lwipopts.h +++ b/tools/sdk/include/lwip/port/lwipopts.h @@ -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) diff --git a/tools/sdk/include/newlib/assert.h b/tools/sdk/include/newlib/assert.h index df46c030..afbea986 100644 --- a/tools/sdk/include/newlib/assert.h +++ b/tools/sdk/include/newlib/assert.h @@ -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 +#include -#ifdef __cplusplus -extern "C" { -#endif - -#include "_ansi.h" +#include_next +#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 diff --git a/tools/sdk/include/nghttp/nghttp2/asio_http2.h b/tools/sdk/include/nghttp/nghttp2/asio_http2.h new file mode 100644 index 00000000..57e55e1f --- /dev/null +++ b/tools/sdk/include/nghttp/nghttp2/asio_http2.h @@ -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 +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +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; + +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 data_cb; +typedef std::function void_cb; +typedef std::function error_cb; +// Callback function when request and response are finished. The +// parameter indicates the cause of closure. +typedef std::function 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 + 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 { + BOOST_STATIC_CONSTANT(bool, value = true); +}; + +template <> struct is_error_code_enum { + BOOST_STATIC_CONSTANT(bool, value = true); +}; + +} // namespace system + +} // namespace boost + +#endif // ASIO_HTTP2_H diff --git a/tools/sdk/include/nghttp/nghttp2/asio_http2_client.h b/tools/sdk/include/nghttp/nghttp2/asio_http2_client.h new file mode 100644 index 00000000..c6c1947b --- /dev/null +++ b/tools/sdk/include/nghttp/nghttp2/asio_http2_client.h @@ -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 + +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 impl_; +}; + +class request; + +using response_cb = std::function; +using request_cb = std::function; +using connect_cb = + std::function; + +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 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 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 diff --git a/tools/sdk/include/nghttp/nghttp2/asio_http2_server.h b/tools/sdk/include/nghttp/nghttp2/asio_http2_server.h new file mode 100644 index 00000000..5818e301 --- /dev/null +++ b/tools/sdk/include/nghttp/nghttp2/asio_http2_server.h @@ -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 + +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 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 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 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> & + io_services() const; + +private: + std::unique_ptr 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 diff --git a/tools/sdk/include/nghttp/nghttp2/nghttp2.h b/tools/sdk/include/nghttp/nghttp2/nghttp2.h deleted file mode 100644 index 0ed36051..00000000 --- a/tools/sdk/include/nghttp/nghttp2/nghttp2.h +++ /dev/null @@ -1,5030 +0,0 @@ -/* - * nghttp2 - HTTP/2 C Library - * - * Copyright (c) 2013, 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_H -#define NGHTTP2_H - -/* Define WIN32 when build target is Win32 API (borrowed from - libcurl) */ -#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32) -#define WIN32 -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#if defined(_MSC_VER) && (_MSC_VER < 1800) -/* MSVC < 2013 does not have inttypes.h because it is not C99 - compliant. See compiler macros and version number in - https://sourceforge.net/p/predef/wiki/Compilers/ */ -#include -#else /* !defined(_MSC_VER) || (_MSC_VER >= 1800) */ -#include -#endif /* !defined(_MSC_VER) || (_MSC_VER >= 1800) */ -#include - -#include - -#ifdef NGHTTP2_STATICLIB -#define NGHTTP2_EXTERN -#elif defined(WIN32) -#ifdef BUILDING_NGHTTP2 -#define NGHTTP2_EXTERN __declspec(dllexport) -#else /* !BUILDING_NGHTTP2 */ -#define NGHTTP2_EXTERN __declspec(dllimport) -#endif /* !BUILDING_NGHTTP2 */ -#else /* !defined(WIN32) */ -#ifdef BUILDING_NGHTTP2 -#define NGHTTP2_EXTERN __attribute__((visibility("default"))) -#else /* !BUILDING_NGHTTP2 */ -#define NGHTTP2_EXTERN -#endif /* !BUILDING_NGHTTP2 */ -#endif /* !defined(WIN32) */ - -/** - * @macro - * - * The protocol version identification string of this library - * supports. This identifier is used if HTTP/2 is used over TLS. - */ -#define NGHTTP2_PROTO_VERSION_ID "h2" -/** - * @macro - * - * The length of :macro:`NGHTTP2_PROTO_VERSION_ID`. - */ -#define NGHTTP2_PROTO_VERSION_ID_LEN 2 - -/** - * @macro - * - * The serialized form of ALPN protocol identifier this library - * supports. Notice that first byte is the length of following - * protocol identifier. This is the same wire format of `TLS ALPN - * extension `_. This is useful - * to process incoming ALPN tokens in wire format. - */ -#define NGHTTP2_PROTO_ALPN "\x2h2" - -/** - * @macro - * - * The length of :macro:`NGHTTP2_PROTO_ALPN`. - */ -#define NGHTTP2_PROTO_ALPN_LEN (sizeof(NGHTTP2_PROTO_ALPN) - 1) - -/** - * @macro - * - * The protocol version identification string of this library - * supports. This identifier is used if HTTP/2 is used over cleartext - * TCP. - */ -#define NGHTTP2_CLEARTEXT_PROTO_VERSION_ID "h2c" - -/** - * @macro - * - * The length of :macro:`NGHTTP2_CLEARTEXT_PROTO_VERSION_ID`. - */ -#define NGHTTP2_CLEARTEXT_PROTO_VERSION_ID_LEN 3 - -struct nghttp2_session; -/** - * @struct - * - * The primary structure to hold the resources needed for a HTTP/2 - * session. The details of this structure are intentionally hidden - * from the public API. - */ -typedef struct nghttp2_session nghttp2_session; - -/** - * @macro - * - * The age of :type:`nghttp2_info` - */ -#define NGHTTP2_VERSION_AGE 1 - -/** - * @struct - * - * This struct is what `nghttp2_version()` returns. It holds - * information about the particular nghttp2 version. - */ -typedef struct { - /** - * Age of this struct. This instance of nghttp2 sets it to - * :macro:`NGHTTP2_VERSION_AGE` but a future version may bump it and - * add more struct fields at the bottom - */ - int age; - /** - * the :macro:`NGHTTP2_VERSION_NUM` number (since age ==1) - */ - int version_num; - /** - * points to the :macro:`NGHTTP2_VERSION` string (since age ==1) - */ - const char *version_str; - /** - * points to the :macro:`NGHTTP2_PROTO_VERSION_ID` string this - * instance implements (since age ==1) - */ - const char *proto_str; - /* -------- the above fields all exist when age == 1 */ -} nghttp2_info; - -/** - * @macro - * - * The default weight of stream dependency. - */ -#define NGHTTP2_DEFAULT_WEIGHT 16 - -/** - * @macro - * - * The maximum weight of stream dependency. - */ -#define NGHTTP2_MAX_WEIGHT 256 - -/** - * @macro - * - * The minimum weight of stream dependency. - */ -#define NGHTTP2_MIN_WEIGHT 1 - -/** - * @macro - * - * The maximum window size - */ -#define NGHTTP2_MAX_WINDOW_SIZE ((int32_t)((1U << 31) - 1)) - -/** - * @macro - * - * The initial window size for stream level flow control. - */ -#define NGHTTP2_INITIAL_WINDOW_SIZE ((1 << 16) - 1) -/** - * @macro - * - * The initial window size for connection level flow control. - */ -#define NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE ((1 << 16) - 1) - -/** - * @macro - * - * The default header table size. - */ -#define NGHTTP2_DEFAULT_HEADER_TABLE_SIZE (1 << 12) - -/** - * @macro - * - * The client magic string, which is the first 24 bytes byte string of - * client connection preface. - */ -#define NGHTTP2_CLIENT_MAGIC "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" - -/** - * @macro - * - * The length of :macro:`NGHTTP2_CLIENT_MAGIC`. - */ -#define NGHTTP2_CLIENT_MAGIC_LEN 24 - -/** - * @enum - * - * Error codes used in this library. The code range is [-999, -500], - * inclusive. The following values are defined: - */ -typedef enum { - /** - * Invalid argument passed. - */ - NGHTTP2_ERR_INVALID_ARGUMENT = -501, - /** - * Out of buffer space. - */ - NGHTTP2_ERR_BUFFER_ERROR = -502, - /** - * The specified protocol version is not supported. - */ - NGHTTP2_ERR_UNSUPPORTED_VERSION = -503, - /** - * Used as a return value from :type:`nghttp2_send_callback`, - * :type:`nghttp2_recv_callback` and - * :type:`nghttp2_send_data_callback` to indicate that the operation - * would block. - */ - NGHTTP2_ERR_WOULDBLOCK = -504, - /** - * General protocol error - */ - NGHTTP2_ERR_PROTO = -505, - /** - * The frame is invalid. - */ - NGHTTP2_ERR_INVALID_FRAME = -506, - /** - * The peer performed a shutdown on the connection. - */ - NGHTTP2_ERR_EOF = -507, - /** - * Used as a return value from - * :func:`nghttp2_data_source_read_callback` to indicate that data - * transfer is postponed. See - * :func:`nghttp2_data_source_read_callback` for details. - */ - NGHTTP2_ERR_DEFERRED = -508, - /** - * Stream ID has reached the maximum value. Therefore no stream ID - * is available. - */ - NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE = -509, - /** - * The stream is already closed; or the stream ID is invalid. - */ - NGHTTP2_ERR_STREAM_CLOSED = -510, - /** - * RST_STREAM has been added to the outbound queue. The stream is - * in closing state. - */ - NGHTTP2_ERR_STREAM_CLOSING = -511, - /** - * The transmission is not allowed for this stream (e.g., a frame - * with END_STREAM flag set has already sent). - */ - NGHTTP2_ERR_STREAM_SHUT_WR = -512, - /** - * The stream ID is invalid. - */ - NGHTTP2_ERR_INVALID_STREAM_ID = -513, - /** - * The state of the stream is not valid (e.g., DATA cannot be sent - * to the stream if response HEADERS has not been sent). - */ - NGHTTP2_ERR_INVALID_STREAM_STATE = -514, - /** - * Another DATA frame has already been deferred. - */ - NGHTTP2_ERR_DEFERRED_DATA_EXIST = -515, - /** - * Starting new stream is not allowed (e.g., GOAWAY has been sent - * and/or received). - */ - NGHTTP2_ERR_START_STREAM_NOT_ALLOWED = -516, - /** - * GOAWAY has already been sent. - */ - NGHTTP2_ERR_GOAWAY_ALREADY_SENT = -517, - /** - * The received frame contains the invalid header block (e.g., There - * are duplicate header names; or the header names are not encoded - * in US-ASCII character set and not lower cased; or the header name - * is zero-length string; or the header value contains multiple - * in-sequence NUL bytes). - */ - NGHTTP2_ERR_INVALID_HEADER_BLOCK = -518, - /** - * Indicates that the context is not suitable to perform the - * requested operation. - */ - NGHTTP2_ERR_INVALID_STATE = -519, - /** - * The user callback function failed due to the temporal error. - */ - NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE = -521, - /** - * The length of the frame is invalid, either too large or too small. - */ - NGHTTP2_ERR_FRAME_SIZE_ERROR = -522, - /** - * Header block inflate/deflate error. - */ - NGHTTP2_ERR_HEADER_COMP = -523, - /** - * Flow control error - */ - NGHTTP2_ERR_FLOW_CONTROL = -524, - /** - * Insufficient buffer size given to function. - */ - NGHTTP2_ERR_INSUFF_BUFSIZE = -525, - /** - * Callback was paused by the application - */ - NGHTTP2_ERR_PAUSE = -526, - /** - * There are too many in-flight SETTING frame and no more - * transmission of SETTINGS is allowed. - */ - NGHTTP2_ERR_TOO_MANY_INFLIGHT_SETTINGS = -527, - /** - * The server push is disabled. - */ - NGHTTP2_ERR_PUSH_DISABLED = -528, - /** - * DATA or HEADERS frame for a given stream has been already - * submitted and has not been fully processed yet. Application - * should wait for the transmission of the previously submitted - * frame before submitting another. - */ - NGHTTP2_ERR_DATA_EXIST = -529, - /** - * The current session is closing due to a connection error or - * `nghttp2_session_terminate_session()` is called. - */ - NGHTTP2_ERR_SESSION_CLOSING = -530, - /** - * Invalid HTTP header field was received and stream is going to be - * closed. - */ - NGHTTP2_ERR_HTTP_HEADER = -531, - /** - * Violation in HTTP messaging rule. - */ - NGHTTP2_ERR_HTTP_MESSAGING = -532, - /** - * Stream was refused. - */ - NGHTTP2_ERR_REFUSED_STREAM = -533, - /** - * Unexpected internal error, but recovered. - */ - NGHTTP2_ERR_INTERNAL = -534, - /** - * Indicates that a processing was canceled. - */ - NGHTTP2_ERR_CANCEL = -535, - /** - * The errors < :enum:`NGHTTP2_ERR_FATAL` mean that the library is - * under unexpected condition and processing was terminated (e.g., - * out of memory). If application receives this error code, it must - * stop using that :type:`nghttp2_session` object and only allowed - * operation for that object is deallocate it using - * `nghttp2_session_del()`. - */ - NGHTTP2_ERR_FATAL = -900, - /** - * Out of memory. This is a fatal error. - */ - NGHTTP2_ERR_NOMEM = -901, - /** - * The user callback function failed. This is a fatal error. - */ - NGHTTP2_ERR_CALLBACK_FAILURE = -902, - /** - * Invalid client magic (see :macro:`NGHTTP2_CLIENT_MAGIC`) was - * received and further processing is not possible. - */ - NGHTTP2_ERR_BAD_CLIENT_MAGIC = -903, - /** - * Possible flooding by peer was detected in this HTTP/2 session. - * Flooding is measured by how many PING and SETTINGS frames with - * ACK flag set are queued for transmission. These frames are - * response for the peer initiated frames, and peer can cause memory - * exhaustion on server side to send these frames forever and does - * not read network. - */ - NGHTTP2_ERR_FLOODED = -904 -} nghttp2_error; - -/** - * @struct - * - * The object representing single contiguous buffer. - */ -typedef struct { - /** - * The pointer to the buffer. - */ - uint8_t *base; - /** - * The length of the buffer. - */ - size_t len; -} nghttp2_vec; - -struct nghttp2_rcbuf; - -/** - * @struct - * - * The object representing reference counted buffer. The details of - * this structure are intentionally hidden from the public API. - */ -typedef struct nghttp2_rcbuf nghttp2_rcbuf; - -/** - * @function - * - * Increments the reference count of |rcbuf| by 1. - */ -NGHTTP2_EXTERN void nghttp2_rcbuf_incref(nghttp2_rcbuf *rcbuf); - -/** - * @function - * - * Decrements the reference count of |rcbuf| by 1. If the reference - * count becomes zero, the object pointed by |rcbuf| will be freed. - * In this case, application must not use |rcbuf| again. - */ -NGHTTP2_EXTERN void nghttp2_rcbuf_decref(nghttp2_rcbuf *rcbuf); - -/** - * @function - * - * Returns the underlying buffer managed by |rcbuf|. - */ -NGHTTP2_EXTERN nghttp2_vec nghttp2_rcbuf_get_buf(nghttp2_rcbuf *rcbuf); - -/** - * @enum - * - * The flags for header field name/value pair. - */ -typedef enum { - /** - * No flag set. - */ - NGHTTP2_NV_FLAG_NONE = 0, - /** - * Indicates that this name/value pair must not be indexed ("Literal - * Header Field never Indexed" representation must be used in HPACK - * encoding). Other implementation calls this bit as "sensitive". - */ - NGHTTP2_NV_FLAG_NO_INDEX = 0x01, - /** - * This flag is set solely by application. If this flag is set, the - * library does not make a copy of header field name. This could - * improve performance. - */ - NGHTTP2_NV_FLAG_NO_COPY_NAME = 0x02, - /** - * This flag is set solely by application. If this flag is set, the - * library does not make a copy of header field value. This could - * improve performance. - */ - NGHTTP2_NV_FLAG_NO_COPY_VALUE = 0x04 -} nghttp2_nv_flag; - -/** - * @struct - * - * The name/value pair, which mainly used to represent header fields. - */ -typedef struct { - /** - * The |name| byte string. If this struct is presented from library - * (e.g., :type:`nghttp2_on_frame_recv_callback`), |name| is - * guaranteed to be NULL-terminated. For some callbacks - * (:type:`nghttp2_before_frame_send_callback`, - * :type:`nghttp2_on_frame_send_callback`, and - * :type:`nghttp2_on_frame_not_send_callback`), it may not be - * NULL-terminated if header field is passed from application with - * the flag :enum:`NGHTTP2_NV_FLAG_NO_COPY_NAME`). When application - * is constructing this struct, |name| is not required to be - * NULL-terminated. - */ - uint8_t *name; - /** - * The |value| byte string. If this struct is presented from - * library (e.g., :type:`nghttp2_on_frame_recv_callback`), |value| - * is guaranteed to be NULL-terminated. For some callbacks - * (:type:`nghttp2_before_frame_send_callback`, - * :type:`nghttp2_on_frame_send_callback`, and - * :type:`nghttp2_on_frame_not_send_callback`), it may not be - * NULL-terminated if header field is passed from application with - * the flag :enum:`NGHTTP2_NV_FLAG_NO_COPY_VALUE`). When - * application is constructing this struct, |value| is not required - * to be NULL-terminated. - */ - uint8_t *value; - /** - * The length of the |name|, excluding terminating NULL. - */ - size_t namelen; - /** - * The length of the |value|, excluding terminating NULL. - */ - size_t valuelen; - /** - * Bitwise OR of one or more of :type:`nghttp2_nv_flag`. - */ - uint8_t flags; -} nghttp2_nv; - -/** - * @enum - * - * The frame types in HTTP/2 specification. - */ -typedef enum { - /** - * The DATA frame. - */ - NGHTTP2_DATA = 0, - /** - * The HEADERS frame. - */ - NGHTTP2_HEADERS = 0x01, - /** - * The PRIORITY frame. - */ - NGHTTP2_PRIORITY = 0x02, - /** - * The RST_STREAM frame. - */ - NGHTTP2_RST_STREAM = 0x03, - /** - * The SETTINGS frame. - */ - NGHTTP2_SETTINGS = 0x04, - /** - * The PUSH_PROMISE frame. - */ - NGHTTP2_PUSH_PROMISE = 0x05, - /** - * The PING frame. - */ - NGHTTP2_PING = 0x06, - /** - * The GOAWAY frame. - */ - NGHTTP2_GOAWAY = 0x07, - /** - * The WINDOW_UPDATE frame. - */ - NGHTTP2_WINDOW_UPDATE = 0x08, - /** - * The CONTINUATION frame. This frame type won't be passed to any - * callbacks because the library processes this frame type and its - * preceding HEADERS/PUSH_PROMISE as a single frame. - */ - NGHTTP2_CONTINUATION = 0x09, - /** - * The ALTSVC frame, which is defined in `RFC 7383 - * `_. - */ - NGHTTP2_ALTSVC = 0x0a -} nghttp2_frame_type; - -/** - * @enum - * - * The flags for HTTP/2 frames. This enum defines all flags for all - * frames. - */ -typedef enum { - /** - * No flag set. - */ - NGHTTP2_FLAG_NONE = 0, - /** - * The END_STREAM flag. - */ - NGHTTP2_FLAG_END_STREAM = 0x01, - /** - * The END_HEADERS flag. - */ - NGHTTP2_FLAG_END_HEADERS = 0x04, - /** - * The ACK flag. - */ - NGHTTP2_FLAG_ACK = 0x01, - /** - * The PADDED flag. - */ - NGHTTP2_FLAG_PADDED = 0x08, - /** - * The PRIORITY flag. - */ - NGHTTP2_FLAG_PRIORITY = 0x20 -} nghttp2_flag; - -/** - * @enum - * The SETTINGS ID. - */ -typedef enum { - /** - * SETTINGS_HEADER_TABLE_SIZE - */ - NGHTTP2_SETTINGS_HEADER_TABLE_SIZE = 0x01, - /** - * SETTINGS_ENABLE_PUSH - */ - NGHTTP2_SETTINGS_ENABLE_PUSH = 0x02, - /** - * SETTINGS_MAX_CONCURRENT_STREAMS - */ - NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS = 0x03, - /** - * SETTINGS_INITIAL_WINDOW_SIZE - */ - NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE = 0x04, - /** - * SETTINGS_MAX_FRAME_SIZE - */ - NGHTTP2_SETTINGS_MAX_FRAME_SIZE = 0x05, - /** - * SETTINGS_MAX_HEADER_LIST_SIZE - */ - NGHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE = 0x06 -} nghttp2_settings_id; -/* Note: If we add SETTINGS, update the capacity of - NGHTTP2_INBOUND_NUM_IV as well */ - -/** - * @macro - * - * .. warning:: - * - * Deprecated. The initial max concurrent streams is 0xffffffffu. - * - * Default maximum number of incoming concurrent streams. Use - * `nghttp2_submit_settings()` with - * :enum:`NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS` to change the - * maximum number of incoming concurrent streams. - * - * .. note:: - * - * The maximum number of outgoing concurrent streams is 100 by - * default. - */ -#define NGHTTP2_INITIAL_MAX_CONCURRENT_STREAMS ((1U << 31) - 1) - -/** - * @enum - * The status codes for the RST_STREAM and GOAWAY frames. - */ -typedef enum { - /** - * No errors. - */ - NGHTTP2_NO_ERROR = 0x00, - /** - * PROTOCOL_ERROR - */ - NGHTTP2_PROTOCOL_ERROR = 0x01, - /** - * INTERNAL_ERROR - */ - NGHTTP2_INTERNAL_ERROR = 0x02, - /** - * FLOW_CONTROL_ERROR - */ - NGHTTP2_FLOW_CONTROL_ERROR = 0x03, - /** - * SETTINGS_TIMEOUT - */ - NGHTTP2_SETTINGS_TIMEOUT = 0x04, - /** - * STREAM_CLOSED - */ - NGHTTP2_STREAM_CLOSED = 0x05, - /** - * FRAME_SIZE_ERROR - */ - NGHTTP2_FRAME_SIZE_ERROR = 0x06, - /** - * REFUSED_STREAM - */ - NGHTTP2_REFUSED_STREAM = 0x07, - /** - * CANCEL - */ - NGHTTP2_CANCEL = 0x08, - /** - * COMPRESSION_ERROR - */ - NGHTTP2_COMPRESSION_ERROR = 0x09, - /** - * CONNECT_ERROR - */ - NGHTTP2_CONNECT_ERROR = 0x0a, - /** - * ENHANCE_YOUR_CALM - */ - NGHTTP2_ENHANCE_YOUR_CALM = 0x0b, - /** - * INADEQUATE_SECURITY - */ - NGHTTP2_INADEQUATE_SECURITY = 0x0c, - /** - * HTTP_1_1_REQUIRED - */ - NGHTTP2_HTTP_1_1_REQUIRED = 0x0d -} nghttp2_error_code; - -/** - * @struct - * The frame header. - */ -typedef struct { - /** - * The length field of this frame, excluding frame header. - */ - size_t length; - /** - * The stream identifier (aka, stream ID) - */ - int32_t stream_id; - /** - * The type of this frame. See `nghttp2_frame_type`. - */ - uint8_t type; - /** - * The flags. - */ - uint8_t flags; - /** - * Reserved bit in frame header. Currently, this is always set to 0 - * and application should not expect something useful in here. - */ - uint8_t reserved; -} nghttp2_frame_hd; - -/** - * @union - * - * This union represents the some kind of data source passed to - * :type:`nghttp2_data_source_read_callback`. - */ -typedef union { - /** - * The integer field, suitable for a file descriptor. - */ - int fd; - /** - * The pointer to an arbitrary object. - */ - void *ptr; -} nghttp2_data_source; - -/** - * @enum - * - * The flags used to set in |data_flags| output parameter in - * :type:`nghttp2_data_source_read_callback`. - */ -typedef enum { - /** - * No flag set. - */ - NGHTTP2_DATA_FLAG_NONE = 0, - /** - * Indicates EOF was sensed. - */ - NGHTTP2_DATA_FLAG_EOF = 0x01, - /** - * Indicates that END_STREAM flag must not be set even if - * NGHTTP2_DATA_FLAG_EOF is set. Usually this flag is used to send - * trailer fields with `nghttp2_submit_request()` or - * `nghttp2_submit_response()`. - */ - NGHTTP2_DATA_FLAG_NO_END_STREAM = 0x02, - /** - * Indicates that application will send complete DATA frame in - * :type:`nghttp2_send_data_callback`. - */ - NGHTTP2_DATA_FLAG_NO_COPY = 0x04 -} nghttp2_data_flag; - -/** - * @functypedef - * - * Callback function invoked when the library wants to read data from - * the |source|. The read data is sent in the stream |stream_id|. - * The implementation of this function must read at most |length| - * bytes of data from |source| (or possibly other places) and store - * them in |buf| and return number of data stored in |buf|. If EOF is - * reached, set :enum:`NGHTTP2_DATA_FLAG_EOF` flag in |*data_flags|. - * - * Sometime it is desirable to avoid copying data into |buf| and let - * application to send data directly. To achieve this, set - * :enum:`NGHTTP2_DATA_FLAG_NO_COPY` to |*data_flags| (and possibly - * other flags, just like when we do copy), and return the number of - * bytes to send without copying data into |buf|. The library, seeing - * :enum:`NGHTTP2_DATA_FLAG_NO_COPY`, will invoke - * :type:`nghttp2_send_data_callback`. The application must send - * complete DATA frame in that callback. - * - * If this callback is set by `nghttp2_submit_request()`, - * `nghttp2_submit_response()` or `nghttp2_submit_headers()` and - * `nghttp2_submit_data()` with flag parameter - * :enum:`NGHTTP2_FLAG_END_STREAM` set, and - * :enum:`NGHTTP2_DATA_FLAG_EOF` flag is set to |*data_flags|, DATA - * frame will have END_STREAM flag set. Usually, this is expected - * behaviour and all are fine. One exception is send trailer fields. - * You cannot send trailer fields after sending frame with END_STREAM - * set. To avoid this problem, one can set - * :enum:`NGHTTP2_DATA_FLAG_NO_END_STREAM` along with - * :enum:`NGHTTP2_DATA_FLAG_EOF` to signal the library not to set - * END_STREAM in DATA frame. Then application can use - * `nghttp2_submit_trailer()` to send trailer fields. - * `nghttp2_submit_trailer()` can be called inside this callback. - * - * If the application wants to postpone DATA frames (e.g., - * asynchronous I/O, or reading data blocks for long time), it is - * achieved by returning :enum:`NGHTTP2_ERR_DEFERRED` without reading - * any data in this invocation. The library removes DATA frame from - * the outgoing queue temporarily. To move back deferred DATA frame - * to outgoing queue, call `nghttp2_session_resume_data()`. In case - * of error, there are 2 choices. Returning - * :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE` will close the stream - * by issuing RST_STREAM with :enum:`NGHTTP2_INTERNAL_ERROR`. If a - * different error code is desirable, use - * `nghttp2_submit_rst_stream()` with a desired error code and then - * return :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`. Returning - * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE` will signal the entire session - * failure. - */ -typedef ssize_t (*nghttp2_data_source_read_callback)( - nghttp2_session *session, int32_t stream_id, uint8_t *buf, size_t length, - uint32_t *data_flags, nghttp2_data_source *source, void *user_data); - -/** - * @struct - * - * This struct represents the data source and the way to read a chunk - * of data from it. - */ -typedef struct { - /** - * The data source. - */ - nghttp2_data_source source; - /** - * The callback function to read a chunk of data from the |source|. - */ - nghttp2_data_source_read_callback read_callback; -} nghttp2_data_provider; - -/** - * @struct - * - * The DATA frame. The received data is delivered via - * :type:`nghttp2_on_data_chunk_recv_callback`. - */ -typedef struct { - nghttp2_frame_hd hd; - /** - * The length of the padding in this frame. This includes PAD_HIGH - * and PAD_LOW. - */ - size_t padlen; -} nghttp2_data; - -/** - * @enum - * - * The category of HEADERS, which indicates the role of the frame. In - * HTTP/2 spec, request, response, push response and other arbitrary - * headers (e.g., trailer fields) are all called just HEADERS. To - * give the application the role of incoming HEADERS frame, we define - * several categories. - */ -typedef enum { - /** - * The HEADERS frame is opening new stream, which is analogous to - * SYN_STREAM in SPDY. - */ - NGHTTP2_HCAT_REQUEST = 0, - /** - * The HEADERS frame is the first response headers, which is - * analogous to SYN_REPLY in SPDY. - */ - NGHTTP2_HCAT_RESPONSE = 1, - /** - * The HEADERS frame is the first headers sent against reserved - * stream. - */ - NGHTTP2_HCAT_PUSH_RESPONSE = 2, - /** - * The HEADERS frame which does not apply for the above categories, - * which is analogous to HEADERS in SPDY. If non-final response - * (e.g., status 1xx) is used, final response HEADERS frame will be - * categorized here. - */ - NGHTTP2_HCAT_HEADERS = 3 -} nghttp2_headers_category; - -/** - * @struct - * - * The structure to specify stream dependency. - */ -typedef struct { - /** - * The stream ID of the stream to depend on. Specifying 0 makes - * stream not depend any other stream. - */ - int32_t stream_id; - /** - * The weight of this dependency. - */ - int32_t weight; - /** - * nonzero means exclusive dependency - */ - uint8_t exclusive; -} nghttp2_priority_spec; - -/** - * @struct - * - * The HEADERS frame. It has the following members: - */ -typedef struct { - /** - * The frame header. - */ - nghttp2_frame_hd hd; - /** - * The length of the padding in this frame. This includes PAD_HIGH - * and PAD_LOW. - */ - size_t padlen; - /** - * The priority specification - */ - nghttp2_priority_spec pri_spec; - /** - * The name/value pairs. - */ - nghttp2_nv *nva; - /** - * The number of name/value pairs in |nva|. - */ - size_t nvlen; - /** - * The category of this HEADERS frame. - */ - nghttp2_headers_category cat; -} nghttp2_headers; - -/** - * @struct - * - * The PRIORITY frame. It has the following members: - */ -typedef struct { - /** - * The frame header. - */ - nghttp2_frame_hd hd; - /** - * The priority specification. - */ - nghttp2_priority_spec pri_spec; -} nghttp2_priority; - -/** - * @struct - * - * The RST_STREAM frame. It has the following members: - */ -typedef struct { - /** - * The frame header. - */ - nghttp2_frame_hd hd; - /** - * The error code. See :type:`nghttp2_error_code`. - */ - uint32_t error_code; -} nghttp2_rst_stream; - -/** - * @struct - * - * The SETTINGS ID/Value pair. It has the following members: - */ -typedef struct { - /** - * The SETTINGS ID. See :type:`nghttp2_settings_id`. - */ - int32_t settings_id; - /** - * The value of this entry. - */ - uint32_t value; -} nghttp2_settings_entry; - -/** - * @struct - * - * The SETTINGS frame. It has the following members: - */ -typedef struct { - /** - * The frame header. - */ - nghttp2_frame_hd hd; - /** - * The number of SETTINGS ID/Value pairs in |iv|. - */ - size_t niv; - /** - * The pointer to the array of SETTINGS ID/Value pair. - */ - nghttp2_settings_entry *iv; -} nghttp2_settings; - -/** - * @struct - * - * The PUSH_PROMISE frame. It has the following members: - */ -typedef struct { - /** - * The frame header. - */ - nghttp2_frame_hd hd; - /** - * The length of the padding in this frame. This includes PAD_HIGH - * and PAD_LOW. - */ - size_t padlen; - /** - * The name/value pairs. - */ - nghttp2_nv *nva; - /** - * The number of name/value pairs in |nva|. - */ - size_t nvlen; - /** - * The promised stream ID - */ - int32_t promised_stream_id; - /** - * Reserved bit. Currently this is always set to 0 and application - * should not expect something useful in here. - */ - uint8_t reserved; -} nghttp2_push_promise; - -/** - * @struct - * - * The PING frame. It has the following members: - */ -typedef struct { - /** - * The frame header. - */ - nghttp2_frame_hd hd; - /** - * The opaque data - */ - uint8_t opaque_data[8]; -} nghttp2_ping; - -/** - * @struct - * - * The GOAWAY frame. It has the following members: - */ -typedef struct { - /** - * The frame header. - */ - nghttp2_frame_hd hd; - /** - * The last stream stream ID. - */ - int32_t last_stream_id; - /** - * The error code. See :type:`nghttp2_error_code`. - */ - uint32_t error_code; - /** - * The additional debug data - */ - uint8_t *opaque_data; - /** - * The length of |opaque_data| member. - */ - size_t opaque_data_len; - /** - * Reserved bit. Currently this is always set to 0 and application - * should not expect something useful in here. - */ - uint8_t reserved; -} nghttp2_goaway; - -/** - * @struct - * - * The WINDOW_UPDATE frame. It has the following members: - */ -typedef struct { - /** - * The frame header. - */ - nghttp2_frame_hd hd; - /** - * The window size increment. - */ - int32_t window_size_increment; - /** - * Reserved bit. Currently this is always set to 0 and application - * should not expect something useful in here. - */ - uint8_t reserved; -} nghttp2_window_update; - -/** - * @struct - * - * The extension frame. It has following members: - */ -typedef struct { - /** - * The frame header. - */ - nghttp2_frame_hd hd; - /** - * The pointer to extension payload. The exact pointer type is - * determined by hd.type. - * - * Currently, no extension is supported. This is a place holder for - * the future extensions. - */ - void *payload; -} nghttp2_extension; - -/** - * @union - * - * This union includes all frames to pass them to various function - * calls as nghttp2_frame type. The CONTINUATION frame is omitted - * from here because the library deals with it internally. - */ -typedef union { - /** - * The frame header, which is convenient to inspect frame header. - */ - nghttp2_frame_hd hd; - /** - * The DATA frame. - */ - nghttp2_data data; - /** - * The HEADERS frame. - */ - nghttp2_headers headers; - /** - * The PRIORITY frame. - */ - nghttp2_priority priority; - /** - * The RST_STREAM frame. - */ - nghttp2_rst_stream rst_stream; - /** - * The SETTINGS frame. - */ - nghttp2_settings settings; - /** - * The PUSH_PROMISE frame. - */ - nghttp2_push_promise push_promise; - /** - * The PING frame. - */ - nghttp2_ping ping; - /** - * The GOAWAY frame. - */ - nghttp2_goaway goaway; - /** - * The WINDOW_UPDATE frame. - */ - nghttp2_window_update window_update; - /** - * The extension frame. - */ - nghttp2_extension ext; -} nghttp2_frame; - -/** - * @functypedef - * - * Callback function invoked when |session| wants to send data to the - * remote peer. The implementation of this function must send at most - * |length| bytes of data stored in |data|. The |flags| is currently - * not used and always 0. It must return the number of bytes sent if - * it succeeds. If it cannot send any single byte without blocking, - * it must return :enum:`NGHTTP2_ERR_WOULDBLOCK`. For other errors, - * it must return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. The - * |user_data| pointer is the third argument passed in to the call to - * `nghttp2_session_client_new()` or `nghttp2_session_server_new()`. - * - * This callback is required if the application uses - * `nghttp2_session_send()` to send data to the remote endpoint. If - * the application uses solely `nghttp2_session_mem_send()` instead, - * this callback function is unnecessary. - * - * To set this callback to :type:`nghttp2_session_callbacks`, use - * `nghttp2_session_callbacks_set_send_callback()`. - * - * .. note:: - * - * The |length| may be very small. If that is the case, and - * application disables Nagle algorithm (``TCP_NODELAY``), then just - * writing |data| to the network stack leads to very small packet, - * and it is very inefficient. An application should be responsible - * to buffer up small chunks of data as necessary to avoid this - * situation. - */ -typedef ssize_t (*nghttp2_send_callback)(nghttp2_session *session, - const uint8_t *data, size_t length, - int flags, void *user_data); - -/** - * @functypedef - * - * Callback function invoked when :enum:`NGHTTP2_DATA_FLAG_NO_COPY` is - * used in :type:`nghttp2_data_source_read_callback` to send complete - * DATA frame. - * - * The |frame| is a DATA frame to send. The |framehd| is the - * serialized frame header (9 bytes). The |length| is the length of - * application data to send (this does not include padding). The - * |source| is the same pointer passed to - * :type:`nghttp2_data_source_read_callback`. - * - * The application first must send frame header |framehd| of length 9 - * bytes. If ``frame->data.padlen > 0``, send 1 byte of value - * ``frame->data.padlen - 1``. Then send exactly |length| bytes of - * application data. Finally, if ``frame->data.padlen > 1``, send - * ``frame->data.padlen - 1`` bytes of zero as padding. - * - * The application has to send complete DATA frame in this callback. - * If all data were written successfully, return 0. - * - * If it cannot send any data at all, just return - * :enum:`NGHTTP2_ERR_WOULDBLOCK`; the library will call this callback - * with the same parameters later (It is recommended to send complete - * DATA frame at once in this function to deal with error; if partial - * frame data has already sent, it is impossible to send another data - * in that state, and all we can do is tear down connection). When - * data is fully processed, but application wants to make - * `nghttp2_session_mem_send()` or `nghttp2_session_send()` return - * immediately without processing next frames, return - * :enum:`NGHTTP2_ERR_PAUSE`. If application decided to reset this - * stream, return :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`, then - * the library will send RST_STREAM with INTERNAL_ERROR as error code. - * The application can also return - * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`, which will result in - * connection closure. Returning any other value is treated as - * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE` is returned. - */ -typedef int (*nghttp2_send_data_callback)(nghttp2_session *session, - nghttp2_frame *frame, - const uint8_t *framehd, size_t length, - nghttp2_data_source *source, - void *user_data); - -/** - * @functypedef - * - * Callback function invoked when |session| wants to receive data from - * the remote peer. The implementation of this function must read at - * most |length| bytes of data and store it in |buf|. The |flags| is - * currently not used and always 0. It must return the number of - * bytes written in |buf| if it succeeds. If it cannot read any - * single byte without blocking, it must return - * :enum:`NGHTTP2_ERR_WOULDBLOCK`. If it gets EOF before it reads any - * single byte, it must return :enum:`NGHTTP2_ERR_EOF`. For other - * errors, it must return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. - * Returning 0 is treated as :enum:`NGHTTP2_ERR_WOULDBLOCK`. The - * |user_data| pointer is the third argument passed in to the call to - * `nghttp2_session_client_new()` or `nghttp2_session_server_new()`. - * - * This callback is required if the application uses - * `nghttp2_session_recv()` to receive data from the remote endpoint. - * If the application uses solely `nghttp2_session_mem_recv()` - * instead, this callback function is unnecessary. - * - * To set this callback to :type:`nghttp2_session_callbacks`, use - * `nghttp2_session_callbacks_set_recv_callback()`. - */ -typedef ssize_t (*nghttp2_recv_callback)(nghttp2_session *session, uint8_t *buf, - size_t length, int flags, - void *user_data); - -/** - * @functypedef - * - * Callback function invoked by `nghttp2_session_recv()` and - * `nghttp2_session_mem_recv()` when a frame is received. The - * |user_data| pointer is the third argument passed in to the call to - * `nghttp2_session_client_new()` or `nghttp2_session_server_new()`. - * - * If frame is HEADERS or PUSH_PROMISE, the ``nva`` and ``nvlen`` - * member of their data structure are always ``NULL`` and 0 - * respectively. The header name/value pairs are emitted via - * :type:`nghttp2_on_header_callback`. - * - * For HEADERS, PUSH_PROMISE and DATA frames, this callback may be - * called after stream is closed (see - * :type:`nghttp2_on_stream_close_callback`). The application should - * check that stream is still alive using its own stream management or - * :func:`nghttp2_session_get_stream_user_data()`. - * - * Only HEADERS and DATA frame can signal the end of incoming data. - * If ``frame->hd.flags & NGHTTP2_FLAG_END_STREAM`` is nonzero, the - * |frame| is the last frame from the remote peer in this stream. - * - * This callback won't be called for CONTINUATION frames. - * HEADERS/PUSH_PROMISE + CONTINUATIONs are treated as single frame. - * - * The implementation of this function must return 0 if it succeeds. - * If nonzero value is returned, it is treated as fatal error and - * `nghttp2_session_recv()` and `nghttp2_session_mem_recv()` functions - * immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. - * - * To set this callback to :type:`nghttp2_session_callbacks`, use - * `nghttp2_session_callbacks_set_on_frame_recv_callback()`. - */ -typedef int (*nghttp2_on_frame_recv_callback)(nghttp2_session *session, - const nghttp2_frame *frame, - void *user_data); - -/** - * @functypedef - * - * Callback function invoked by `nghttp2_session_recv()` and - * `nghttp2_session_mem_recv()` when an invalid non-DATA frame is - * received. The error is indicated by the |lib_error_code|, which is - * one of the values defined in :type:`nghttp2_error`. When this - * callback function is invoked, the library automatically submits - * either RST_STREAM or GOAWAY frame. The |user_data| pointer is the - * third argument passed in to the call to - * `nghttp2_session_client_new()` or `nghttp2_session_server_new()`. - * - * If frame is HEADERS or PUSH_PROMISE, the ``nva`` and ``nvlen`` - * member of their data structure are always ``NULL`` and 0 - * respectively. - * - * The implementation of this function must return 0 if it succeeds. - * If nonzero is returned, it is treated as fatal error and - * `nghttp2_session_recv()` and `nghttp2_session_mem_recv()` functions - * immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. - * - * To set this callback to :type:`nghttp2_session_callbacks`, use - * `nghttp2_session_callbacks_set_on_invalid_frame_recv_callback()`. - */ -typedef int (*nghttp2_on_invalid_frame_recv_callback)( - nghttp2_session *session, const nghttp2_frame *frame, int lib_error_code, - void *user_data); - -/** - * @functypedef - * - * Callback function invoked when a chunk of data in DATA frame is - * received. The |stream_id| is the stream ID this DATA frame belongs - * to. The |flags| is the flags of DATA frame which this data chunk - * is contained. ``(flags & NGHTTP2_FLAG_END_STREAM) != 0`` does not - * necessarily mean this chunk of data is the last one in the stream. - * You should use :type:`nghttp2_on_frame_recv_callback` to know all - * data frames are received. The |user_data| pointer is the third - * argument passed in to the call to `nghttp2_session_client_new()` or - * `nghttp2_session_server_new()`. - * - * If the application uses `nghttp2_session_mem_recv()`, it can return - * :enum:`NGHTTP2_ERR_PAUSE` to make `nghttp2_session_mem_recv()` - * return without processing further input bytes. The memory by - * pointed by the |data| is retained until - * `nghttp2_session_mem_recv()` or `nghttp2_session_recv()` is called. - * The application must retain the input bytes which was used to - * produce the |data| parameter, because it may refer to the memory - * region included in the input bytes. - * - * The implementation of this function must return 0 if it succeeds. - * If nonzero is returned, it is treated as fatal error, and - * `nghttp2_session_recv()` and `nghttp2_session_mem_recv()` functions - * immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. - * - * To set this callback to :type:`nghttp2_session_callbacks`, use - * `nghttp2_session_callbacks_set_on_data_chunk_recv_callback()`. - */ -typedef int (*nghttp2_on_data_chunk_recv_callback)(nghttp2_session *session, - uint8_t flags, - int32_t stream_id, - const uint8_t *data, - size_t len, void *user_data); - -/** - * @functypedef - * - * Callback function invoked just before the non-DATA frame |frame| is - * sent. The |user_data| pointer is the third argument passed in to - * the call to `nghttp2_session_client_new()` or - * `nghttp2_session_server_new()`. - * - * The implementation of this function must return 0 if it succeeds. - * It can also return :enum:`NGHTTP2_ERR_CANCEL` to cancel the - * transmission of the given frame. - * - * If there is a fatal error while executing this callback, the - * implementation should return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`, - * which makes `nghttp2_session_send()` and - * `nghttp2_session_mem_send()` functions immediately return - * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. - * - * If the other value is returned, it is treated as if - * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE` is returned. But the - * implementation should not rely on this since the library may define - * new return value to extend its capability. - * - * To set this callback to :type:`nghttp2_session_callbacks`, use - * `nghttp2_session_callbacks_set_before_frame_send_callback()`. - */ -typedef int (*nghttp2_before_frame_send_callback)(nghttp2_session *session, - const nghttp2_frame *frame, - void *user_data); - -/** - * @functypedef - * - * Callback function invoked after the frame |frame| is sent. The - * |user_data| pointer is the third argument passed in to the call to - * `nghttp2_session_client_new()` or `nghttp2_session_server_new()`. - * - * The implementation of this function must return 0 if it succeeds. - * If nonzero is returned, it is treated as fatal error and - * `nghttp2_session_send()` and `nghttp2_session_mem_send()` functions - * immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. - * - * To set this callback to :type:`nghttp2_session_callbacks`, use - * `nghttp2_session_callbacks_set_on_frame_send_callback()`. - */ -typedef int (*nghttp2_on_frame_send_callback)(nghttp2_session *session, - const nghttp2_frame *frame, - void *user_data); - -/** - * @functypedef - * - * Callback function invoked after the non-DATA frame |frame| is not - * sent because of the error. The error is indicated by the - * |lib_error_code|, which is one of the values defined in - * :type:`nghttp2_error`. The |user_data| pointer is the third - * argument passed in to the call to `nghttp2_session_client_new()` or - * `nghttp2_session_server_new()`. - * - * The implementation of this function must return 0 if it succeeds. - * If nonzero is returned, it is treated as fatal error and - * `nghttp2_session_send()` and `nghttp2_session_mem_send()` functions - * immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. - * - * `nghttp2_session_get_stream_user_data()` can be used to get - * associated data. - * - * To set this callback to :type:`nghttp2_session_callbacks`, use - * `nghttp2_session_callbacks_set_on_frame_not_send_callback()`. - */ -typedef int (*nghttp2_on_frame_not_send_callback)(nghttp2_session *session, - const nghttp2_frame *frame, - int lib_error_code, - void *user_data); - -/** - * @functypedef - * - * Callback function invoked when the stream |stream_id| is closed. - * The reason of closure is indicated by the |error_code|. The - * |error_code| is usually one of :enum:`nghttp2_error_code`, but that - * is not guaranteed. The stream_user_data, which was specified in - * `nghttp2_submit_request()` or `nghttp2_submit_headers()`, is still - * available in this function. The |user_data| pointer is the third - * argument passed in to the call to `nghttp2_session_client_new()` or - * `nghttp2_session_server_new()`. - * - * This function is also called for a stream in reserved state. - * - * The implementation of this function must return 0 if it succeeds. - * If nonzero is returned, it is treated as fatal error and - * `nghttp2_session_recv()`, `nghttp2_session_mem_recv()`, - * `nghttp2_session_send()`, and `nghttp2_session_mem_send()` - * functions immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. - * - * To set this callback to :type:`nghttp2_session_callbacks`, use - * `nghttp2_session_callbacks_set_on_stream_close_callback()`. - */ -typedef int (*nghttp2_on_stream_close_callback)(nghttp2_session *session, - int32_t stream_id, - uint32_t error_code, - void *user_data); - -/** - * @functypedef - * - * Callback function invoked when the reception of header block in - * HEADERS or PUSH_PROMISE is started. Each header name/value pair - * will be emitted by :type:`nghttp2_on_header_callback`. - * - * The ``frame->hd.flags`` may not have - * :enum:`NGHTTP2_FLAG_END_HEADERS` flag set, which indicates that one - * or more CONTINUATION frames are involved. But the application does - * not need to care about that because the header name/value pairs are - * emitted transparently regardless of CONTINUATION frames. - * - * The server applications probably create an object to store - * information about new stream if ``frame->hd.type == - * NGHTTP2_HEADERS`` and ``frame->headers.cat == - * NGHTTP2_HCAT_REQUEST``. If |session| is configured as server side, - * ``frame->headers.cat`` is either ``NGHTTP2_HCAT_REQUEST`` - * containing request headers or ``NGHTTP2_HCAT_HEADERS`` containing - * trailer fields and never get PUSH_PROMISE in this callback. - * - * For the client applications, ``frame->hd.type`` is either - * ``NGHTTP2_HEADERS`` or ``NGHTTP2_PUSH_PROMISE``. In case of - * ``NGHTTP2_HEADERS``, ``frame->headers.cat == - * NGHTTP2_HCAT_RESPONSE`` means that it is the first response - * headers, but it may be non-final response which is indicated by 1xx - * status code. In this case, there may be zero or more HEADERS frame - * with ``frame->headers.cat == NGHTTP2_HCAT_HEADERS`` which has - * non-final response code and finally client gets exactly one HEADERS - * frame with ``frame->headers.cat == NGHTTP2_HCAT_HEADERS`` - * containing final response headers (non-1xx status code). The - * trailer fields also has ``frame->headers.cat == - * NGHTTP2_HCAT_HEADERS`` which does not contain any status code. - * - * Returning :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE` will close - * the stream (promised stream if frame is PUSH_PROMISE) by issuing - * RST_STREAM with :enum:`NGHTTP2_INTERNAL_ERROR`. In this case, - * :type:`nghttp2_on_header_callback` and - * :type:`nghttp2_on_frame_recv_callback` will not be invoked. If a - * different error code is desirable, use - * `nghttp2_submit_rst_stream()` with a desired error code and then - * return :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`. Again, use - * ``frame->push_promise.promised_stream_id`` as stream_id parameter - * in `nghttp2_submit_rst_stream()` if frame is PUSH_PROMISE. - * - * The implementation of this function must return 0 if it succeeds. - * It can return :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE` to - * reset the stream (promised stream if frame is PUSH_PROMISE). For - * critical errors, it must return - * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. If the other value is - * returned, it is treated as if :enum:`NGHTTP2_ERR_CALLBACK_FAILURE` - * is returned. If :enum:`NGHTTP2_ERR_CALLBACK_FAILURE` is returned, - * `nghttp2_session_mem_recv()` function will immediately return - * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. - * - * To set this callback to :type:`nghttp2_session_callbacks`, use - * `nghttp2_session_callbacks_set_on_begin_headers_callback()`. - */ -typedef int (*nghttp2_on_begin_headers_callback)(nghttp2_session *session, - const nghttp2_frame *frame, - void *user_data); - -/** - * @functypedef - * - * Callback function invoked when a header name/value pair is received - * for the |frame|. The |name| of length |namelen| is header name. - * The |value| of length |valuelen| is header value. The |flags| is - * bitwise OR of one or more of :type:`nghttp2_nv_flag`. - * - * If :enum:`NGHTTP2_NV_FLAG_NO_INDEX` is set in |flags|, the receiver - * must not index this name/value pair when forwarding it to the next - * hop. More specifically, "Literal Header Field never Indexed" - * representation must be used in HPACK encoding. - * - * When this callback is invoked, ``frame->hd.type`` is either - * :enum:`NGHTTP2_HEADERS` or :enum:`NGHTTP2_PUSH_PROMISE`. After all - * header name/value pairs are processed with this callback, and no - * error has been detected, :type:`nghttp2_on_frame_recv_callback` - * will be invoked. If there is an error in decompression, - * :type:`nghttp2_on_frame_recv_callback` for the |frame| will not be - * invoked. - * - * Both |name| and |value| are guaranteed to be NULL-terminated. The - * |namelen| and |valuelen| do not include terminal NULL. If - * `nghttp2_option_set_no_http_messaging()` is used with nonzero - * value, NULL character may be included in |name| or |value| before - * terminating NULL. - * - * Please note that unless `nghttp2_option_set_no_http_messaging()` is - * used, nghttp2 library does perform validation against the |name| - * and the |value| using `nghttp2_check_header_name()` and - * `nghttp2_check_header_value()`. In addition to this, nghttp2 - * performs validation based on HTTP Messaging rule, which is briefly - * explained in :ref:`http-messaging` section. - * - * If the application uses `nghttp2_session_mem_recv()`, it can return - * :enum:`NGHTTP2_ERR_PAUSE` to make `nghttp2_session_mem_recv()` - * return without processing further input bytes. The memory pointed - * by |frame|, |name| and |value| parameters are retained until - * `nghttp2_session_mem_recv()` or `nghttp2_session_recv()` is called. - * The application must retain the input bytes which was used to - * produce these parameters, because it may refer to the memory region - * included in the input bytes. - * - * Returning :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE` will close - * the stream (promised stream if frame is PUSH_PROMISE) by issuing - * RST_STREAM with :enum:`NGHTTP2_INTERNAL_ERROR`. In this case, - * :type:`nghttp2_on_header_callback` and - * :type:`nghttp2_on_frame_recv_callback` will not be invoked. If a - * different error code is desirable, use - * `nghttp2_submit_rst_stream()` with a desired error code and then - * return :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`. Again, use - * ``frame->push_promise.promised_stream_id`` as stream_id parameter - * in `nghttp2_submit_rst_stream()` if frame is PUSH_PROMISE. - * - * The implementation of this function must return 0 if it succeeds. - * It may return :enum:`NGHTTP2_ERR_PAUSE` or - * :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`. For other critical - * failures, it must return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. If - * the other nonzero value is returned, it is treated as - * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. If - * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE` is returned, - * `nghttp2_session_recv()` and `nghttp2_session_mem_recv()` functions - * immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. - * - * To set this callback to :type:`nghttp2_session_callbacks`, use - * `nghttp2_session_callbacks_set_on_header_callback()`. - * - * .. warning:: - * - * Application should properly limit the total buffer size to store - * incoming header fields. Without it, peer may send large number - * of header fields or large header fields to cause out of memory in - * local endpoint. Due to how HPACK works, peer can do this - * effectively without using much memory on their own. - */ -typedef int (*nghttp2_on_header_callback)(nghttp2_session *session, - const nghttp2_frame *frame, - const uint8_t *name, size_t namelen, - const uint8_t *value, size_t valuelen, - uint8_t flags, void *user_data); - -/** - * @functypedef - * - * Callback function invoked when a header name/value pair is received - * for the |frame|. The |name| is header name. The |value| is header - * value. The |flags| is bitwise OR of one or more of - * :type:`nghttp2_nv_flag`. - * - * This callback behaves like :type:`nghttp2_on_header_callback`, - * except that |name| and |value| are stored in reference counted - * buffer. If application wishes to keep these references without - * copying them, use `nghttp2_rcbuf_incref()` to increment their - * reference count. It is the application's responsibility to call - * `nghttp2_rcbuf_decref()` if they called `nghttp2_rcbuf_incref()` so - * as not to leak memory. If the |session| is created by - * `nghttp2_session_server_new3()` or `nghttp2_session_client_new3()`, - * the function to free memory is the one belongs to the mem - * parameter. As long as this free function alives, |name| and - * |value| can live after |session| was destroyed. - */ -typedef int (*nghttp2_on_header_callback2)(nghttp2_session *session, - const nghttp2_frame *frame, - nghttp2_rcbuf *name, - nghttp2_rcbuf *value, uint8_t flags, - void *user_data); - -/** - * @functypedef - * - * Callback function invoked when the library asks application how - * many padding bytes are required for the transmission of the - * |frame|. The application must choose the total length of payload - * including padded bytes in range [frame->hd.length, max_payloadlen], - * inclusive. Choosing number not in this range will be treated as - * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. Returning - * ``frame->hd.length`` means no padding is added. Returning - * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE` will make - * `nghttp2_session_send()` and `nghttp2_session_mem_send()` functions - * immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. - * - * To set this callback to :type:`nghttp2_session_callbacks`, use - * `nghttp2_session_callbacks_set_select_padding_callback()`. - */ -typedef ssize_t (*nghttp2_select_padding_callback)(nghttp2_session *session, - const nghttp2_frame *frame, - size_t max_payloadlen, - void *user_data); - -/** - * @functypedef - * - * Callback function invoked when library wants to get max length of - * data to send data to the remote peer. The implementation of this - * function should return a value in the following range. [1, - * min(|session_remote_window_size|, |stream_remote_window_size|, - * |remote_max_frame_size|)]. If a value greater than this range is - * returned than the max allow value will be used. Returning a value - * smaller than this range is treated as - * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. The |frame_type| is provided - * for future extensibility and identifies the type of frame (see - * :type:`nghttp2_frame_type`) for which to get the length for. - * Currently supported frame types are: :enum:`NGHTTP2_DATA`. - * - * This callback can be used to control the length in bytes for which - * :type:`nghttp2_data_source_read_callback` is allowed to send to the - * remote endpoint. This callback is optional. Returning - * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE` will signal the entire session - * failure. - * - * To set this callback to :type:`nghttp2_session_callbacks`, use - * `nghttp2_session_callbacks_set_data_source_read_length_callback()`. - */ -typedef ssize_t (*nghttp2_data_source_read_length_callback)( - nghttp2_session *session, uint8_t frame_type, int32_t stream_id, - int32_t session_remote_window_size, int32_t stream_remote_window_size, - uint32_t remote_max_frame_size, void *user_data); - -/** - * @functypedef - * - * Callback function invoked when a frame header is received. The - * |hd| points to received frame header. - * - * Unlike :type:`nghttp2_on_frame_recv_callback`, this callback will - * also be called when frame header of CONTINUATION frame is received. - * - * If both :type:`nghttp2_on_begin_frame_callback` and - * :type:`nghttp2_on_begin_headers_callback` are set and HEADERS or - * PUSH_PROMISE is received, :type:`nghttp2_on_begin_frame_callback` - * will be called first. - * - * The implementation of this function must return 0 if it succeeds. - * If nonzero value is returned, it is treated as fatal error and - * `nghttp2_session_recv()` and `nghttp2_session_mem_recv()` functions - * immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. - * - * To set this callback to :type:`nghttp2_session_callbacks`, use - * `nghttp2_session_callbacks_set_on_begin_frame_callback()`. - */ -typedef int (*nghttp2_on_begin_frame_callback)(nghttp2_session *session, - const nghttp2_frame_hd *hd, - void *user_data); - -/** - * @functypedef - * - * Callback function invoked when chunk of extension frame payload is - * received. The |hd| points to frame header. The received - * chunk is |data| of length |len|. - * - * The implementation of this function must return 0 if it succeeds. - * - * To abort processing this extension frame, return - * :enum:`NGHTTP2_ERR_CANCEL`. - * - * If fatal error occurred, application should return - * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. In this case, - * `nghttp2_session_recv()` and `nghttp2_session_mem_recv()` functions - * immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. If the - * other values are returned, currently they are treated as - * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. - */ -typedef int (*nghttp2_on_extension_chunk_recv_callback)( - nghttp2_session *session, const nghttp2_frame_hd *hd, const uint8_t *data, - size_t len, void *user_data); - -/** - * @functypedef - * - * Callback function invoked when library asks the application to - * unpack extension payload from its wire format. The extension - * payload has been passed to the application using - * :type:`nghttp2_on_extension_chunk_recv_callback`. The frame header - * is already unpacked by the library and provided as |hd|. - * - * To receive extension frames, the application must tell desired - * extension frame type to the library using - * `nghttp2_option_set_user_recv_extension_type()`. - * - * The implementation of this function may store the pointer to the - * created object as a result of unpacking in |*payload|, and returns - * 0. The pointer stored in |*payload| is opaque to the library, and - * the library does not own its pointer. |*payload| is initialized as - * ``NULL``. The |*payload| is available as ``frame->ext.payload`` in - * :type:`nghttp2_on_frame_recv_callback`. Therefore if application - * can free that memory inside :type:`nghttp2_on_frame_recv_callback` - * callback. Of course, application has a liberty not ot use - * |*payload|, and do its own mechanism to process extension frames. - * - * To abort processing this extension frame, return - * :enum:`NGHTTP2_ERR_CANCEL`. - * - * If fatal error occurred, application should return - * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. In this case, - * `nghttp2_session_recv()` and `nghttp2_session_mem_recv()` functions - * immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. If the - * other values are returned, currently they are treated as - * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. - */ -typedef int (*nghttp2_unpack_extension_callback)(nghttp2_session *session, - void **payload, - const nghttp2_frame_hd *hd, - void *user_data); - -/** - * @functypedef - * - * Callback function invoked when library asks the application to pack - * extension payload in its wire format. The frame header will be - * packed by library. Application must pack payload only. - * ``frame->ext.payload`` is the object passed to - * `nghttp2_submit_extension()` as payload parameter. Application - * must pack extension payload to the |buf| of its capacity |len| - * bytes. The |len| is at least 16KiB. - * - * The implementation of this function should return the number of - * bytes written into |buf| when it succeeds. - * - * To abort processing this extension frame, return - * :enum:`NGHTTP2_ERR_CANCEL`, and - * :type:`nghttp2_on_frame_not_send_callback` will be invoked. - * - * If fatal error occurred, application should return - * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. In this case, - * `nghttp2_session_send()` and `nghttp2_session_mem_send()` functions - * immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. If the - * other values are returned, currently they are treated as - * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. If the return value is - * strictly larger than |len|, it is treated as - * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. - */ -typedef ssize_t (*nghttp2_pack_extension_callback)(nghttp2_session *session, - uint8_t *buf, size_t len, - const nghttp2_frame *frame, - void *user_data); - -/** - * @functypedef - * - * Callback function invoked when library provides the error message - * intended for human consumption. This callback is solely for - * debugging purpose. The |msg| is typically NULL-terminated string - * of length |len|. |len| does not include the sentinel NULL - * character. - * - * The format of error message may change between nghttp2 library - * versions. The application should not depend on the particular - * format. - * - * Normally, application should return 0 from this callback. If fatal - * error occurred while doing something in this callback, application - * should return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. In this case, - * library will return immediately with return value - * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. Currently, if nonzero value - * is returned from this callback, they are treated as - * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`, but application should not - * rely on this details. - */ -typedef int (*nghttp2_error_callback)(nghttp2_session *session, const char *msg, - size_t len, void *user_data); - -struct nghttp2_session_callbacks; - -/** - * @struct - * - * Callback functions for :type:`nghttp2_session`. The details of - * this structure are intentionally hidden from the public API. - */ -typedef struct nghttp2_session_callbacks nghttp2_session_callbacks; - -/** - * @function - * - * Initializes |*callbacks_ptr| with NULL values. - * - * The initialized object can be used when initializing multiple - * :type:`nghttp2_session` objects. - * - * When the application finished using this object, it can use - * `nghttp2_session_callbacks_del()` to free its memory. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP2_ERR_NOMEM` - * Out of memory. - */ -NGHTTP2_EXTERN int -nghttp2_session_callbacks_new(nghttp2_session_callbacks **callbacks_ptr); - -/** - * @function - * - * Frees any resources allocated for |callbacks|. If |callbacks| is - * ``NULL``, this function does nothing. - */ -NGHTTP2_EXTERN void -nghttp2_session_callbacks_del(nghttp2_session_callbacks *callbacks); - -/** - * @function - * - * Sets callback function invoked when a 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_EXTERN void nghttp2_session_callbacks_set_send_callback( - nghttp2_session_callbacks *cbs, nghttp2_send_callback send_callback); - -/** - * @function - * - * Sets callback function invoked when the a 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_EXTERN void nghttp2_session_callbacks_set_recv_callback( - nghttp2_session_callbacks *cbs, nghttp2_recv_callback recv_callback); - -/** - * @function - * - * Sets callback function invoked by `nghttp2_session_recv()` and - * `nghttp2_session_mem_recv()` when a frame is received. - */ -NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_frame_recv_callback( - nghttp2_session_callbacks *cbs, - nghttp2_on_frame_recv_callback on_frame_recv_callback); - -/** - * @function - * - * Sets callback function invoked by `nghttp2_session_recv()` and - * `nghttp2_session_mem_recv()` when an invalid non-DATA frame is - * received. - */ -NGHTTP2_EXTERN void -nghttp2_session_callbacks_set_on_invalid_frame_recv_callback( - nghttp2_session_callbacks *cbs, - nghttp2_on_invalid_frame_recv_callback on_invalid_frame_recv_callback); - -/** - * @function - * - * Sets callback function invoked when a chunk of data in DATA frame - * is received. - */ -NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_data_chunk_recv_callback( - nghttp2_session_callbacks *cbs, - nghttp2_on_data_chunk_recv_callback on_data_chunk_recv_callback); - -/** - * @function - * - * Sets callback function invoked before a non-DATA frame is sent. - */ -NGHTTP2_EXTERN void nghttp2_session_callbacks_set_before_frame_send_callback( - nghttp2_session_callbacks *cbs, - nghttp2_before_frame_send_callback before_frame_send_callback); - -/** - * @function - * - * Sets callback function invoked after a frame is sent. - */ -NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_frame_send_callback( - nghttp2_session_callbacks *cbs, - nghttp2_on_frame_send_callback on_frame_send_callback); - -/** - * @function - * - * Sets callback function invoked when a non-DATA frame is not sent - * because of an error. - */ -NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_frame_not_send_callback( - nghttp2_session_callbacks *cbs, - nghttp2_on_frame_not_send_callback on_frame_not_send_callback); - -/** - * @function - * - * Sets callback function invoked when the stream is closed. - */ -NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_stream_close_callback( - nghttp2_session_callbacks *cbs, - nghttp2_on_stream_close_callback on_stream_close_callback); - -/** - * @function - * - * Sets callback function invoked when the reception of header block - * in HEADERS or PUSH_PROMISE is started. - */ -NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_begin_headers_callback( - nghttp2_session_callbacks *cbs, - nghttp2_on_begin_headers_callback on_begin_headers_callback); - -/** - * @function - * - * Sets callback function invoked when a header name/value pair is - * received. If both - * `nghttp2_session_callbacks_set_on_header_callback()` and - * `nghttp2_session_callbacks_set_on_header_callback2()` are used to - * set callbacks, the latter has the precedence. - */ -NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_header_callback( - nghttp2_session_callbacks *cbs, - nghttp2_on_header_callback on_header_callback); - -/** - * @function - * - * Sets callback function invoked when a header name/value pair is - * received. - */ -NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_header_callback2( - nghttp2_session_callbacks *cbs, - nghttp2_on_header_callback2 on_header_callback2); - -/** - * @function - * - * Sets callback function invoked when the library asks application - * how many padding bytes are required for the transmission of the - * given frame. - */ -NGHTTP2_EXTERN void nghttp2_session_callbacks_set_select_padding_callback( - nghttp2_session_callbacks *cbs, - nghttp2_select_padding_callback select_padding_callback); - -/** - * @function - * - * Sets callback function determine the length allowed in - * :type:`nghttp2_data_source_read_callback`. - */ -NGHTTP2_EXTERN void -nghttp2_session_callbacks_set_data_source_read_length_callback( - nghttp2_session_callbacks *cbs, - nghttp2_data_source_read_length_callback data_source_read_length_callback); - -/** - * @function - * - * Sets callback function invoked when a frame header is received. - */ -NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_begin_frame_callback( - nghttp2_session_callbacks *cbs, - nghttp2_on_begin_frame_callback on_begin_frame_callback); - -/** - * @function - * - * Sets callback function invoked when - * :enum:`NGHTTP2_DATA_FLAG_NO_COPY` is used in - * :type:`nghttp2_data_source_read_callback` to avoid data copy. - */ -NGHTTP2_EXTERN void nghttp2_session_callbacks_set_send_data_callback( - nghttp2_session_callbacks *cbs, - nghttp2_send_data_callback send_data_callback); - -/** - * @function - * - * Sets callback function invoked when the library asks the - * application to pack extension frame payload in wire format. - */ -NGHTTP2_EXTERN void nghttp2_session_callbacks_set_pack_extension_callback( - nghttp2_session_callbacks *cbs, - nghttp2_pack_extension_callback pack_extension_callback); - -/** - * @function - * - * Sets callback function invoked when the library asks the - * application to unpack extension frame payload from wire format. - */ -NGHTTP2_EXTERN void nghttp2_session_callbacks_set_unpack_extension_callback( - nghttp2_session_callbacks *cbs, - nghttp2_unpack_extension_callback unpack_extension_callback); - -/** - * @function - * - * Sets callback function invoked when chunk of extension frame - * payload is received. - */ -NGHTTP2_EXTERN void -nghttp2_session_callbacks_set_on_extension_chunk_recv_callback( - nghttp2_session_callbacks *cbs, - nghttp2_on_extension_chunk_recv_callback on_extension_chunk_recv_callback); - -/** - * @function - * - * Sets callback function invoked when library tells error message to - * the application. - */ -NGHTTP2_EXTERN void nghttp2_session_callbacks_set_error_callback( - nghttp2_session_callbacks *cbs, nghttp2_error_callback error_callback); - -/** - * @functypedef - * - * Custom memory allocator to replace malloc(). The |mem_user_data| - * is the mem_user_data member of :type:`nghttp2_mem` structure. - */ -typedef void *(*nghttp2_malloc)(size_t size, void *mem_user_data); - -/** - * @functypedef - * - * Custom memory allocator to replace free(). The |mem_user_data| is - * the mem_user_data member of :type:`nghttp2_mem` structure. - */ -typedef void (*nghttp2_free)(void *ptr, void *mem_user_data); - -/** - * @functypedef - * - * Custom memory allocator to replace calloc(). The |mem_user_data| - * is the mem_user_data member of :type:`nghttp2_mem` structure. - */ -typedef void *(*nghttp2_calloc)(size_t nmemb, size_t size, void *mem_user_data); - -/** - * @functypedef - * - * Custom memory allocator to replace realloc(). The |mem_user_data| - * is the mem_user_data member of :type:`nghttp2_mem` structure. - */ -typedef void *(*nghttp2_realloc)(void *ptr, size_t size, void *mem_user_data); - -/** - * @struct - * - * Custom memory allocator functions and user defined pointer. The - * |mem_user_data| member is passed to each allocator function. This - * can be used, for example, to achieve per-session memory pool. - * - * In the following example code, ``my_malloc``, ``my_free``, - * ``my_calloc`` and ``my_realloc`` are the replacement of the - * standard allocators ``malloc``, ``free``, ``calloc`` and - * ``realloc`` respectively:: - * - * void *my_malloc_cb(size_t size, void *mem_user_data) { - * return my_malloc(size); - * } - * - * void my_free_cb(void *ptr, void *mem_user_data) { my_free(ptr); } - * - * void *my_calloc_cb(size_t nmemb, size_t size, void *mem_user_data) { - * return my_calloc(nmemb, size); - * } - * - * void *my_realloc_cb(void *ptr, size_t size, void *mem_user_data) { - * return my_realloc(ptr, size); - * } - * - * void session_new() { - * nghttp2_session *session; - * nghttp2_session_callbacks *callbacks; - * nghttp2_mem mem = {NULL, my_malloc_cb, my_free_cb, my_calloc_cb, - * my_realloc_cb}; - * - * ... - * - * nghttp2_session_client_new3(&session, callbacks, NULL, NULL, &mem); - * - * ... - * } - */ -typedef struct { - /** - * An arbitrary user supplied data. This is passed to each - * allocator function. - */ - void *mem_user_data; - /** - * Custom allocator function to replace malloc(). - */ - nghttp2_malloc malloc; - /** - * Custom allocator function to replace free(). - */ - nghttp2_free free; - /** - * Custom allocator function to replace calloc(). - */ - nghttp2_calloc calloc; - /** - * Custom allocator function to replace realloc(). - */ - nghttp2_realloc realloc; -} nghttp2_mem; - -struct nghttp2_option; - -/** - * @struct - * - * Configuration options for :type:`nghttp2_session`. The details of - * this structure are intentionally hidden from the public API. - */ -typedef struct nghttp2_option nghttp2_option; - -/** - * @function - * - * Initializes |*option_ptr| with default values. - * - * When the application finished using this object, it can use - * `nghttp2_option_del()` to free its memory. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP2_ERR_NOMEM` - * Out of memory. - */ -NGHTTP2_EXTERN int nghttp2_option_new(nghttp2_option **option_ptr); - -/** - * @function - * - * Frees any resources allocated for |option|. If |option| is - * ``NULL``, this function does nothing. - */ -NGHTTP2_EXTERN void nghttp2_option_del(nghttp2_option *option); - -/** - * @function - * - * This option prevents the library from sending WINDOW_UPDATE for a - * connection automatically. If this option is set to nonzero, the - * library won't send WINDOW_UPDATE for DATA until application calls - * `nghttp2_session_consume()` to indicate the consumed amount of - * data. Don't use `nghttp2_submit_window_update()` for this purpose. - * By default, this option is set to zero. - */ -NGHTTP2_EXTERN void -nghttp2_option_set_no_auto_window_update(nghttp2_option *option, int val); - -/** - * @function - * - * This option sets the SETTINGS_MAX_CONCURRENT_STREAMS value of - * remote endpoint as if it is received in SETTINGS frame. Without - * specifying this option, before the local endpoint receives - * SETTINGS_MAX_CONCURRENT_STREAMS in SETTINGS frame from remote - * endpoint, SETTINGS_MAX_CONCURRENT_STREAMS is unlimited. This may - * cause problem if local endpoint submits lots of requests initially - * and sending them at once to the remote peer may lead to the - * rejection of some requests. Specifying this option to the sensible - * value, say 100, may avoid this kind of issue. This value will be - * overwritten if the local endpoint receives - * SETTINGS_MAX_CONCURRENT_STREAMS from the remote endpoint. - */ -NGHTTP2_EXTERN void -nghttp2_option_set_peer_max_concurrent_streams(nghttp2_option *option, - uint32_t val); - -/** - * @function - * - * By default, nghttp2 library, if configured as server, requires - * first 24 bytes of client magic byte string (MAGIC). In most cases, - * this will simplify the implementation of server. But sometimes - * server may want to detect the application protocol based on first - * few bytes on clear text communication. - * - * If this option is used with nonzero |val|, nghttp2 library does not - * handle MAGIC. It still checks following SETTINGS frame. This - * means that applications should deal with MAGIC by themselves. - * - * If this option is not used or used with zero value, if MAGIC does - * not match :macro:`NGHTTP2_CLIENT_MAGIC`, `nghttp2_session_recv()` - * and `nghttp2_session_mem_recv()` will return error - * :enum:`NGHTTP2_ERR_BAD_CLIENT_MAGIC`, which is fatal error. - */ -NGHTTP2_EXTERN void -nghttp2_option_set_no_recv_client_magic(nghttp2_option *option, int val); - -/** - * @function - * - * By default, nghttp2 library enforces subset of HTTP Messaging rules - * described in `HTTP/2 specification, section 8 - * `_. See - * :ref:`http-messaging` section for details. For those applications - * who use nghttp2 library as non-HTTP use, give nonzero to |val| to - * disable this enforcement. - */ -NGHTTP2_EXTERN void nghttp2_option_set_no_http_messaging(nghttp2_option *option, - int val); - -/** - * @function - * - * RFC 7540 does not enforce any limit on the number of incoming - * reserved streams (in RFC 7540 terms, streams in reserved (remote) - * state). This only affects client side, since only server can push - * streams. Malicious server can push arbitrary number of streams, - * and make client's memory exhausted. This option can set the - * maximum number of such incoming streams to avoid possible memory - * exhaustion. If this option is set, and pushed streams are - * automatically closed on reception, without calling user provided - * callback, if they exceed the given limit. The default value is - * 200. If session is configured as server side, this option has no - * effect. Server can control the number of streams to push. - */ -NGHTTP2_EXTERN void -nghttp2_option_set_max_reserved_remote_streams(nghttp2_option *option, - uint32_t val); - -/** - * @function - * - * Sets extension frame type the application is willing to handle with - * user defined callbacks (see - * :type:`nghttp2_on_extension_chunk_recv_callback` and - * :type:`nghttp2_unpack_extension_callback`). The |type| is - * extension frame type, and must be strictly greater than 0x9. - * Otherwise, this function does nothing. The application can call - * this function multiple times to set more than one frame type to - * receive. The application does not have to call this function if it - * just sends extension frames. - */ -NGHTTP2_EXTERN void -nghttp2_option_set_user_recv_extension_type(nghttp2_option *option, - uint8_t type); - -/** - * @function - * - * Sets extension frame type the application is willing to receive - * using builtin handler. The |type| is the extension frame type to - * receive, and must be strictly greater than 0x9. Otherwise, this - * function does nothing. The application can call this function - * multiple times to set more than one frame type to receive. The - * application does not have to call this function if it just sends - * extension frames. - * - * If same frame type is passed to both - * `nghttp2_option_set_builtin_recv_extension_type()` and - * `nghttp2_option_set_user_recv_extension_type()`, the latter takes - * precedence. - */ -NGHTTP2_EXTERN void -nghttp2_option_set_builtin_recv_extension_type(nghttp2_option *option, - uint8_t type); - -/** - * @function - * - * This option prevents the library from sending PING frame with ACK - * flag set automatically when PING frame without ACK flag set is - * received. If this option is set to nonzero, the library won't send - * PING frame with ACK flag set in the response for incoming PING - * frame. The application can send PING frame with ACK flag set using - * `nghttp2_submit_ping()` with :enum:`NGHTTP2_FLAG_ACK` as flags - * parameter. - */ -NGHTTP2_EXTERN void nghttp2_option_set_no_auto_ping_ack(nghttp2_option *option, - int val); - -/** - * @function - * - * This option sets the maximum length of header block (a set of - * header fields per one HEADERS frame) to send. The length of a - * given set of header fields is calculated using - * `nghttp2_hd_deflate_bound()`. The default value is 64KiB. If - * application attempts to send header fields larger than this limit, - * the transmission of the frame fails with error code - * :enum:`NGHTTP2_ERR_FRAME_SIZE_ERROR`. - */ -NGHTTP2_EXTERN void -nghttp2_option_set_max_send_header_block_length(nghttp2_option *option, - size_t val); - -/** - * @function - * - * Initializes |*session_ptr| for client use. The all members of - * |callbacks| are copied to |*session_ptr|. Therefore |*session_ptr| - * does not store |callbacks|. The |user_data| is an arbitrary user - * supplied data, which will be passed to the callback functions. - * - * The :type:`nghttp2_send_callback` must be specified. If the - * application code uses `nghttp2_session_recv()`, the - * :type:`nghttp2_recv_callback` must be specified. The other members - * of |callbacks| can be ``NULL``. - * - * If this function fails, |*session_ptr| is left untouched. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP2_ERR_NOMEM` - * Out of memory. - */ -NGHTTP2_EXTERN int -nghttp2_session_client_new(nghttp2_session **session_ptr, - const nghttp2_session_callbacks *callbacks, - void *user_data); - -/** - * @function - * - * Initializes |*session_ptr| for server use. The all members of - * |callbacks| are copied to |*session_ptr|. Therefore |*session_ptr| - * does not store |callbacks|. The |user_data| is an arbitrary user - * supplied data, which will be passed to the callback functions. - * - * The :type:`nghttp2_send_callback` must be specified. If the - * application code uses `nghttp2_session_recv()`, the - * :type:`nghttp2_recv_callback` must be specified. The other members - * of |callbacks| can be ``NULL``. - * - * If this function fails, |*session_ptr| is left untouched. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP2_ERR_NOMEM` - * Out of memory. - */ -NGHTTP2_EXTERN int -nghttp2_session_server_new(nghttp2_session **session_ptr, - const nghttp2_session_callbacks *callbacks, - void *user_data); - -/** - * @function - * - * Like `nghttp2_session_client_new()`, but with additional options - * specified in the |option|. - * - * The |option| can be ``NULL`` and the call is equivalent to - * `nghttp2_session_client_new()`. - * - * This function does not take ownership |option|. The application is - * responsible for freeing |option| if it finishes using the object. - * - * The library code does not refer to |option| after this function - * returns. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP2_ERR_NOMEM` - * Out of memory. - */ -NGHTTP2_EXTERN int -nghttp2_session_client_new2(nghttp2_session **session_ptr, - const nghttp2_session_callbacks *callbacks, - void *user_data, const nghttp2_option *option); - -/** - * @function - * - * Like `nghttp2_session_server_new()`, but with additional options - * specified in the |option|. - * - * The |option| can be ``NULL`` and the call is equivalent to - * `nghttp2_session_server_new()`. - * - * This function does not take ownership |option|. The application is - * responsible for freeing |option| if it finishes using the object. - * - * The library code does not refer to |option| after this function - * returns. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP2_ERR_NOMEM` - * Out of memory. - */ -NGHTTP2_EXTERN int -nghttp2_session_server_new2(nghttp2_session **session_ptr, - const nghttp2_session_callbacks *callbacks, - void *user_data, const nghttp2_option *option); - -/** - * @function - * - * Like `nghttp2_session_client_new2()`, but with additional custom - * memory allocator specified in the |mem|. - * - * The |mem| can be ``NULL`` and the call is equivalent to - * `nghttp2_session_client_new2()`. - * - * This function does not take ownership |mem|. The application is - * responsible for freeing |mem|. - * - * The library code does not refer to |mem| pointer after this - * function returns, so the application can safely free it. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP2_ERR_NOMEM` - * Out of memory. - */ -NGHTTP2_EXTERN int nghttp2_session_client_new3( - nghttp2_session **session_ptr, const nghttp2_session_callbacks *callbacks, - void *user_data, const nghttp2_option *option, nghttp2_mem *mem); - -/** - * @function - * - * Like `nghttp2_session_server_new2()`, but with additional custom - * memory allocator specified in the |mem|. - * - * The |mem| can be ``NULL`` and the call is equivalent to - * `nghttp2_session_server_new2()`. - * - * This function does not take ownership |mem|. The application is - * responsible for freeing |mem|. - * - * The library code does not refer to |mem| pointer after this - * function returns, so the application can safely free it. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP2_ERR_NOMEM` - * Out of memory. - */ -NGHTTP2_EXTERN int nghttp2_session_server_new3( - nghttp2_session **session_ptr, const nghttp2_session_callbacks *callbacks, - void *user_data, const nghttp2_option *option, nghttp2_mem *mem); - -/** - * @function - * - * Frees any resources allocated for |session|. If |session| is - * ``NULL``, this function does nothing. - */ -NGHTTP2_EXTERN void nghttp2_session_del(nghttp2_session *session); - -/** - * @function - * - * Sends pending frames to the remote peer. - * - * This function retrieves the highest prioritized frame from the - * outbound queue and sends it to the remote peer. It does this as - * many as possible until the user callback - * :type:`nghttp2_send_callback` returns - * :enum:`NGHTTP2_ERR_WOULDBLOCK` or the outbound queue becomes empty. - * This function calls several callback functions which are passed - * when initializing the |session|. Here is the simple time chart - * which tells when each callback is invoked: - * - * 1. Get the next frame to send from outbound queue. - * - * 2. Prepare transmission of the frame. - * - * 3. If the control frame cannot be sent because some preconditions - * are not met (e.g., request HEADERS cannot be sent after GOAWAY), - * :type:`nghttp2_on_frame_not_send_callback` is invoked. Abort - * the following steps. - * - * 4. If the frame is HEADERS, PUSH_PROMISE or DATA, - * :type:`nghttp2_select_padding_callback` is invoked. - * - * 5. If the frame is request HEADERS, the stream is opened here. - * - * 6. :type:`nghttp2_before_frame_send_callback` is invoked. - * - * 7. If :enum:`NGHTTP2_ERR_CANCEL` is returned from - * :type:`nghttp2_before_frame_send_callback`, the current frame - * transmission is canceled, and - * :type:`nghttp2_on_frame_not_send_callback` is invoked. Abort - * the following steps. - * - * 8. :type:`nghttp2_send_callback` is invoked one or more times to - * send the frame. - * - * 9. :type:`nghttp2_on_frame_send_callback` is invoked. - * - * 10. If the transmission of the frame triggers closure of the - * stream, the stream is closed and - * :type:`nghttp2_on_stream_close_callback` is invoked. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP2_ERR_NOMEM` - * Out of memory. - * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE` - * The callback function failed. - */ -NGHTTP2_EXTERN int nghttp2_session_send(nghttp2_session *session); - -/** - * @function - * - * Returns the serialized data to send. - * - * This function behaves like `nghttp2_session_send()` except that it - * does not use :type:`nghttp2_send_callback` to transmit data. - * Instead, it assigns the pointer to the serialized data to the - * |*data_ptr| and returns its length. The other callbacks are called - * in the same way as they are in `nghttp2_session_send()`. - * - * If no data is available to send, this function returns 0. - * - * This function may not return all serialized data in one invocation. - * To get all data, call this function repeatedly until it returns 0 - * or one of negative error codes. - * - * The assigned |*data_ptr| is valid until the next call of - * `nghttp2_session_mem_send()` or `nghttp2_session_send()`. - * - * The caller must send all data before sending the next chunk of - * data. - * - * This function returns the length of the data pointed by the - * |*data_ptr| if it succeeds, or one of the following negative error - * codes: - * - * :enum:`NGHTTP2_ERR_NOMEM` - * Out of memory. - * - * .. note:: - * - * This function may produce very small byte string. If that is the - * case, and application disables Nagle algorithm (``TCP_NODELAY``), - * then writing this small chunk leads to very small packet, and it - * is very inefficient. An application should be responsible to - * buffer up small chunks of data as necessary to avoid this - * situation. - */ -NGHTTP2_EXTERN ssize_t -nghttp2_session_mem_send(nghttp2_session *session, const uint8_t **data_ptr); - -/** - * @function - * - * Receives frames from the remote peer. - * - * This function receives as many frames as possible until the user - * callback :type:`nghttp2_recv_callback` returns - * :enum:`NGHTTP2_ERR_WOULDBLOCK`. This function calls several - * callback functions which are passed when initializing the - * |session|. Here is the simple time chart which tells when each - * callback is invoked: - * - * 1. :type:`nghttp2_recv_callback` is invoked one or more times to - * receive frame header. - * - * 2. When frame header is received, - * :type:`nghttp2_on_begin_frame_callback` is invoked. - * - * 3. If the frame is DATA frame: - * - * 1. :type:`nghttp2_recv_callback` is invoked to receive DATA - * payload. For each chunk of data, - * :type:`nghttp2_on_data_chunk_recv_callback` is invoked. - * - * 2. If one DATA frame is completely received, - * :type:`nghttp2_on_frame_recv_callback` is invoked. If the - * reception of the frame triggers the closure of the stream, - * :type:`nghttp2_on_stream_close_callback` is invoked. - * - * 4. If the frame is the control frame: - * - * 1. :type:`nghttp2_recv_callback` is invoked one or more times to - * receive whole frame. - * - * 2. If the received frame is valid, then following actions are - * taken. If the frame is either HEADERS or PUSH_PROMISE, - * :type:`nghttp2_on_begin_headers_callback` is invoked. Then - * :type:`nghttp2_on_header_callback` is invoked for each header - * name/value pair. After all name/value pairs are emitted - * successfully, :type:`nghttp2_on_frame_recv_callback` is - * invoked. For other frames, - * :type:`nghttp2_on_frame_recv_callback` is invoked. If the - * reception of the frame triggers the closure of the stream, - * :type:`nghttp2_on_stream_close_callback` is invoked. - * - * 3. If the received frame is unpacked but is interpreted as - * invalid, :type:`nghttp2_on_invalid_frame_recv_callback` is - * invoked. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP2_ERR_EOF` - * The remote peer did shutdown on the connection. - * :enum:`NGHTTP2_ERR_NOMEM` - * Out of memory. - * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE` - * The callback function failed. - * :enum:`NGHTTP2_ERR_BAD_CLIENT_MAGIC` - * Invalid client magic was detected. This error only returns - * when |session| was configured as server and - * `nghttp2_option_set_no_recv_client_magic()` is not used with - * nonzero value. - * :enum:`NGHTTP2_ERR_FLOODED` - * Flooding was detected in this HTTP/2 session, and it must be - * closed. This is most likely caused by misbehaviour of peer. - */ -NGHTTP2_EXTERN int nghttp2_session_recv(nghttp2_session *session); - -/** - * @function - * - * Processes data |in| as an input from the remote endpoint. The - * |inlen| indicates the number of bytes in the |in|. - * - * This function behaves like `nghttp2_session_recv()` except that it - * does not use :type:`nghttp2_recv_callback` to receive data; the - * |in| is the only data for the invocation of this function. If all - * bytes are processed, this function returns. The other callbacks - * are called in the same way as they are in `nghttp2_session_recv()`. - * - * In the current implementation, this function always tries to - * processes all input data unless either an error occurs or - * :enum:`NGHTTP2_ERR_PAUSE` is returned from - * :type:`nghttp2_on_header_callback` or - * :type:`nghttp2_on_data_chunk_recv_callback`. If - * :enum:`NGHTTP2_ERR_PAUSE` is used, the return value includes the - * number of bytes which was used to produce the data or frame for the - * callback. - * - * This function returns the number of processed bytes, or one of the - * following negative error codes: - * - * :enum:`NGHTTP2_ERR_NOMEM` - * Out of memory. - * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE` - * The callback function failed. - * :enum:`NGHTTP2_ERR_BAD_CLIENT_MAGIC` - * Invalid client magic was detected. This error only returns - * when |session| was configured as server and - * `nghttp2_option_set_no_recv_client_magic()` is not used with - * nonzero value. - * :enum:`NGHTTP2_ERR_FLOODED` - * Flooding was detected in this HTTP/2 session, and it must be - * closed. This is most likely caused by misbehaviour of peer. - */ -NGHTTP2_EXTERN ssize_t nghttp2_session_mem_recv(nghttp2_session *session, - const uint8_t *in, - size_t inlen); - -/** - * @function - * - * Puts back previously deferred DATA frame in the stream |stream_id| - * to the outbound queue. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT` - * The stream does not exist; or no deferred data exist. - * :enum:`NGHTTP2_ERR_NOMEM` - * Out of memory. - */ -NGHTTP2_EXTERN int nghttp2_session_resume_data(nghttp2_session *session, - int32_t stream_id); - -/** - * @function - * - * Returns nonzero value if |session| wants to receive data from the - * remote peer. - * - * If both `nghttp2_session_want_read()` and - * `nghttp2_session_want_write()` return 0, the application should - * drop the connection. - */ -NGHTTP2_EXTERN int nghttp2_session_want_read(nghttp2_session *session); - -/** - * @function - * - * Returns nonzero value if |session| wants to send data to the remote - * peer. - * - * If both `nghttp2_session_want_read()` and - * `nghttp2_session_want_write()` return 0, the application should - * drop the connection. - */ -NGHTTP2_EXTERN int nghttp2_session_want_write(nghttp2_session *session); - -/** - * @function - * - * Returns stream_user_data for the stream |stream_id|. The - * stream_user_data is provided by `nghttp2_submit_request()`, - * `nghttp2_submit_headers()` or - * `nghttp2_session_set_stream_user_data()`. Unless it is set using - * `nghttp2_session_set_stream_user_data()`, if the stream is - * initiated by the remote endpoint, stream_user_data is always - * ``NULL``. If the stream does not exist, this function returns - * ``NULL``. - */ -NGHTTP2_EXTERN void * -nghttp2_session_get_stream_user_data(nghttp2_session *session, - int32_t stream_id); - -/** - * @function - * - * Sets the |stream_user_data| to the stream denoted by the - * |stream_id|. If a stream user data is already set to the stream, - * it is replaced with the |stream_user_data|. It is valid to specify - * ``NULL`` in the |stream_user_data|, which nullifies the associated - * data pointer. - * - * It is valid to set the |stream_user_data| to the stream reserved by - * PUSH_PROMISE frame. - * - * This function returns 0 if it succeeds, or one of following - * negative error codes: - * - * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT` - * The stream does not exist - */ -NGHTTP2_EXTERN int -nghttp2_session_set_stream_user_data(nghttp2_session *session, - int32_t stream_id, void *stream_user_data); - -/** - * @function - * - * Returns the number of frames in the outbound queue. This does not - * include the deferred DATA frames. - */ -NGHTTP2_EXTERN size_t -nghttp2_session_get_outbound_queue_size(nghttp2_session *session); - -/** - * @function - * - * Returns the number of DATA payload in bytes received without - * WINDOW_UPDATE transmission for the stream |stream_id|. The local - * (receive) window size can be adjusted by - * `nghttp2_submit_window_update()`. This function takes into account - * that and returns effective data length. In particular, if the - * local window size is reduced by submitting negative - * window_size_increment with `nghttp2_submit_window_update()`, this - * function returns the number of bytes less than actually received. - * - * This function returns -1 if it fails. - */ -NGHTTP2_EXTERN int32_t -nghttp2_session_get_stream_effective_recv_data_length(nghttp2_session *session, - int32_t stream_id); - -/** - * @function - * - * Returns the local (receive) window size for the stream |stream_id|. - * The local window size can be adjusted by - * `nghttp2_submit_window_update()`. This function takes into account - * that and returns effective window size. - * - * This function returns -1 if it fails. - */ -NGHTTP2_EXTERN int32_t -nghttp2_session_get_stream_effective_local_window_size(nghttp2_session *session, - int32_t stream_id); - -/** - * @function - * - * Returns the number of DATA payload in bytes received without - * WINDOW_UPDATE transmission for a connection. The local (receive) - * window size can be adjusted by `nghttp2_submit_window_update()`. - * This function takes into account that and returns effective data - * length. In particular, if the local window size is reduced by - * submitting negative window_size_increment with - * `nghttp2_submit_window_update()`, this function returns the number - * of bytes less than actually received. - * - * This function returns -1 if it fails. - */ -NGHTTP2_EXTERN int32_t -nghttp2_session_get_effective_recv_data_length(nghttp2_session *session); - -/** - * @function - * - * Returns the local (receive) window size for a connection. The - * local window size can be adjusted by - * `nghttp2_submit_window_update()`. This function takes into account - * that and returns effective window size. - * - * This function returns -1 if it fails. - */ -NGHTTP2_EXTERN int32_t -nghttp2_session_get_effective_local_window_size(nghttp2_session *session); - -/** - * @function - * - * Returns the remote window size for a given stream |stream_id|. - * - * This is the amount of flow-controlled payload (e.g., DATA) that the - * local endpoint can send without stream level WINDOW_UPDATE. There - * is also connection level flow control, so the effective size of - * payload that the local endpoint can actually send is - * min(`nghttp2_session_get_stream_remote_window_size()`, - * `nghttp2_session_get_remote_window_size()`). - * - * This function returns -1 if it fails. - */ -NGHTTP2_EXTERN int32_t -nghttp2_session_get_stream_remote_window_size(nghttp2_session *session, - int32_t stream_id); - -/** - * @function - * - * Returns the remote window size for a connection. - * - * This function always succeeds. - */ -NGHTTP2_EXTERN int32_t -nghttp2_session_get_remote_window_size(nghttp2_session *session); - -/** - * @function - * - * Returns 1 if local peer half closed the given stream |stream_id|. - * Returns 0 if it did not. Returns -1 if no such stream exists. - */ -NGHTTP2_EXTERN int -nghttp2_session_get_stream_local_close(nghttp2_session *session, - int32_t stream_id); - -/** - * @function - * - * Returns 1 if remote peer half closed the given stream |stream_id|. - * Returns 0 if it did not. Returns -1 if no such stream exists. - */ -NGHTTP2_EXTERN int -nghttp2_session_get_stream_remote_close(nghttp2_session *session, - int32_t stream_id); - -/** - * @function - * - * Signals the session so that the connection should be terminated. - * - * The last stream ID is the minimum value between the stream ID of a - * stream for which :type:`nghttp2_on_frame_recv_callback` was called - * most recently and the last stream ID we have sent to the peer - * previously. - * - * The |error_code| is the error code of this GOAWAY frame. The - * pre-defined error code is one of :enum:`nghttp2_error_code`. - * - * After the transmission, both `nghttp2_session_want_read()` and - * `nghttp2_session_want_write()` return 0. - * - * This function should be called when the connection should be - * terminated after sending GOAWAY. If the remaining streams should - * be processed after GOAWAY, use `nghttp2_submit_goaway()` instead. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP2_ERR_NOMEM` - * Out of memory. - */ -NGHTTP2_EXTERN int nghttp2_session_terminate_session(nghttp2_session *session, - uint32_t error_code); - -/** - * @function - * - * Signals the session so that the connection should be terminated. - * - * This function behaves like `nghttp2_session_terminate_session()`, - * but the last stream ID can be specified by the application for fine - * grained control of stream. The HTTP/2 specification does not allow - * last_stream_id to be increased. So the actual value sent as - * last_stream_id is the minimum value between the given - * |last_stream_id| and the last_stream_id we have previously sent to - * the peer. - * - * The |last_stream_id| is peer's stream ID or 0. So if |session| is - * initialized as client, |last_stream_id| must be even or 0. If - * |session| is initialized as server, |last_stream_id| must be odd or - * 0. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP2_ERR_NOMEM` - * Out of memory. - * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT` - * The |last_stream_id| is invalid. - */ -NGHTTP2_EXTERN int nghttp2_session_terminate_session2(nghttp2_session *session, - int32_t last_stream_id, - uint32_t error_code); - -/** - * @function - * - * Signals to the client that the server started graceful shutdown - * procedure. - * - * This function is only usable for server. If this function is - * called with client side session, this function returns - * :enum:`NGHTTP2_ERR_INVALID_STATE`. - * - * To gracefully shutdown HTTP/2 session, server should call this - * function to send GOAWAY with last_stream_id (1u << 31) - 1. And - * after some delay (e.g., 1 RTT), send another GOAWAY with the stream - * ID that the server has some processing using - * `nghttp2_submit_goaway()`. See also - * `nghttp2_session_get_last_proc_stream_id()`. - * - * Unlike `nghttp2_submit_goaway()`, this function just sends GOAWAY - * and does nothing more. This is a mere indication to the client - * that session shutdown is imminent. The application should call - * `nghttp2_submit_goaway()` with appropriate last_stream_id after - * this call. - * - * If one or more GOAWAY frame have been already sent by either - * `nghttp2_submit_goaway()` or `nghttp2_session_terminate_session()`, - * this function has no effect. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP2_ERR_NOMEM` - * Out of memory. - * :enum:`NGHTTP2_ERR_INVALID_STATE` - * The |session| is initialized as client. - */ -NGHTTP2_EXTERN int nghttp2_submit_shutdown_notice(nghttp2_session *session); - -/** - * @function - * - * Returns the value of SETTINGS |id| notified by a remote endpoint. - * The |id| must be one of values defined in - * :enum:`nghttp2_settings_id`. - */ -NGHTTP2_EXTERN uint32_t -nghttp2_session_get_remote_settings(nghttp2_session *session, - nghttp2_settings_id id); - -/** - * @function - * - * Tells the |session| that next stream ID is |next_stream_id|. The - * |next_stream_id| must be equal or greater than the value returned - * by `nghttp2_session_get_next_stream_id()`. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT` - * The |next_stream_id| is strictly less than the value - * `nghttp2_session_get_next_stream_id()` returns; or - * |next_stream_id| is invalid (e.g., even integer for client, or - * odd integer for server). - */ -NGHTTP2_EXTERN int nghttp2_session_set_next_stream_id(nghttp2_session *session, - int32_t next_stream_id); - -/** - * @function - * - * Returns the next outgoing stream ID. Notice that return type is - * uint32_t. If we run out of stream ID for this session, this - * function returns 1 << 31. - */ -NGHTTP2_EXTERN uint32_t -nghttp2_session_get_next_stream_id(nghttp2_session *session); - -/** - * @function - * - * Tells the |session| that |size| bytes for a stream denoted by - * |stream_id| were consumed by application and are ready to - * WINDOW_UPDATE. The consumed bytes are counted towards both - * connection and stream level WINDOW_UPDATE (see - * `nghttp2_session_consume_connection()` and - * `nghttp2_session_consume_stream()` to update consumption - * independently). This function is intended to be used without - * automatic window update (see - * `nghttp2_option_set_no_auto_window_update()`). - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP2_ERR_NOMEM` - * Out of memory. - * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT` - * The |stream_id| is 0. - * :enum:`NGHTTP2_ERR_INVALID_STATE` - * Automatic WINDOW_UPDATE is not disabled. - */ -NGHTTP2_EXTERN int nghttp2_session_consume(nghttp2_session *session, - int32_t stream_id, size_t size); - -/** - * @function - * - * Like `nghttp2_session_consume()`, but this only tells library that - * |size| bytes were consumed only for connection level. Note that - * HTTP/2 maintains connection and stream level flow control windows - * independently. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP2_ERR_NOMEM` - * Out of memory. - * :enum:`NGHTTP2_ERR_INVALID_STATE` - * Automatic WINDOW_UPDATE is not disabled. - */ -NGHTTP2_EXTERN int nghttp2_session_consume_connection(nghttp2_session *session, - size_t size); - -/** - * @function - * - * Like `nghttp2_session_consume()`, but this only tells library that - * |size| bytes were consumed only for stream denoted by |stream_id|. - * Note that HTTP/2 maintains connection and stream level flow control - * windows independently. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP2_ERR_NOMEM` - * Out of memory. - * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT` - * The |stream_id| is 0. - * :enum:`NGHTTP2_ERR_INVALID_STATE` - * Automatic WINDOW_UPDATE is not disabled. - */ -NGHTTP2_EXTERN int nghttp2_session_consume_stream(nghttp2_session *session, - int32_t stream_id, - size_t size); - -/** - * @function - * - * Changes priority of existing stream denoted by |stream_id|. The - * new priority specification is |pri_spec|. - * - * The priority is changed silently and instantly, and no PRIORITY - * frame will be sent to notify the peer of this change. This - * function may be useful for server to change the priority of pushed - * stream. - * - * If |session| is initialized as server, and ``pri_spec->stream_id`` - * points to the idle stream, the idle stream is created if it does - * not exist. The created idle stream will depend on root stream - * (stream 0) with weight 16. - * - * Otherwise, if stream denoted by ``pri_spec->stream_id`` is not - * found, we use default priority instead of given |pri_spec|. That - * is make stream depend on root stream with weight 16. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP2_ERR_NOMEM` - * Out of memory. - * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT` - * Attempted to depend on itself; or no stream exist for the given - * |stream_id|; or |stream_id| is 0 - */ -NGHTTP2_EXTERN int -nghttp2_session_change_stream_priority(nghttp2_session *session, - int32_t stream_id, - const nghttp2_priority_spec *pri_spec); - -/** - * @function - * - * Creates idle stream with the given |stream_id|, and priority - * |pri_spec|. - * - * The stream creation is done without sending PRIORITY frame, which - * means that peer does not know about the existence of this idle - * stream in the local endpoint. - * - * RFC 7540 does not disallow the use of creation of idle stream with - * odd or even stream ID regardless of client or server. So this - * function can create odd or even stream ID regardless of client or - * server. But probably it is a bit safer to use the stream ID the - * local endpoint can initiate (in other words, use odd stream ID for - * client, and even stream ID for server), to avoid potential - * collision from peer's instruction. Also we can use - * `nghttp2_session_set_next_stream_id()` to avoid to open created - * idle streams accidentally if we follow this recommendation. - * - * If |session| is initialized as server, and ``pri_spec->stream_id`` - * points to the idle stream, the idle stream is created if it does - * not exist. The created idle stream will depend on root stream - * (stream 0) with weight 16. - * - * Otherwise, if stream denoted by ``pri_spec->stream_id`` is not - * found, we use default priority instead of given |pri_spec|. That - * is make stream depend on root stream with weight 16. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP2_ERR_NOMEM` - * Out of memory. - * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT` - * Attempted to depend on itself; or stream denoted by |stream_id| - * already exists; or |stream_id| cannot be used to create idle - * stream (in other words, local endpoint has already opened - * stream ID greater than or equal to the given stream ID; or - * |stream_id| is 0 - */ -NGHTTP2_EXTERN int -nghttp2_session_create_idle_stream(nghttp2_session *session, int32_t stream_id, - const nghttp2_priority_spec *pri_spec); - -/** - * @function - * - * Performs post-process of HTTP Upgrade request. This function can - * be called from both client and server, but the behavior is very - * different in each other. - * - * .. warning:: - * - * This function is deprecated in favor of - * `nghttp2_session_upgrade2()`, because this function lacks the - * parameter to tell the library the request method used in the - * original HTTP request. This information is required for client - * to validate actual response body length against content-length - * header field (see `nghttp2_option_set_no_http_messaging()`). If - * HEAD is used in request, the length of response body must be 0 - * regardless of value included in content-length header field. - * - * If called from client side, the |settings_payload| must be the - * value sent in ``HTTP2-Settings`` header field and must be decoded - * by base64url decoder. The |settings_payloadlen| is the length of - * |settings_payload|. The |settings_payload| is unpacked and its - * setting values will be submitted using `nghttp2_submit_settings()`. - * This means that the client application code does not need to submit - * SETTINGS by itself. The stream with stream ID=1 is opened and the - * |stream_user_data| is used for its stream_user_data. The opened - * stream becomes half-closed (local) state. - * - * If called from server side, the |settings_payload| must be the - * value received in ``HTTP2-Settings`` header field and must be - * decoded by base64url decoder. The |settings_payloadlen| is the - * length of |settings_payload|. It is treated as if the SETTINGS - * frame with that payload is received. Thus, callback functions for - * the reception of SETTINGS frame will be invoked. The stream with - * stream ID=1 is opened. The |stream_user_data| is ignored. The - * opened stream becomes half-closed (remote). - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP2_ERR_NOMEM` - * Out of memory. - * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT` - * The |settings_payload| is badly formed. - * :enum:`NGHTTP2_ERR_PROTO` - * The stream ID 1 is already used or closed; or is not available. - */ -NGHTTP2_EXTERN int nghttp2_session_upgrade(nghttp2_session *session, - const uint8_t *settings_payload, - size_t settings_payloadlen, - void *stream_user_data); - -/** - * @function - * - * Performs post-process of HTTP Upgrade request. This function can - * be called from both client and server, but the behavior is very - * different in each other. - * - * If called from client side, the |settings_payload| must be the - * value sent in ``HTTP2-Settings`` header field and must be decoded - * by base64url decoder. The |settings_payloadlen| is the length of - * |settings_payload|. The |settings_payload| is unpacked and its - * setting values will be submitted using `nghttp2_submit_settings()`. - * This means that the client application code does not need to submit - * SETTINGS by itself. The stream with stream ID=1 is opened and the - * |stream_user_data| is used for its stream_user_data. The opened - * stream becomes half-closed (local) state. - * - * If called from server side, the |settings_payload| must be the - * value received in ``HTTP2-Settings`` header field and must be - * decoded by base64url decoder. The |settings_payloadlen| is the - * length of |settings_payload|. It is treated as if the SETTINGS - * frame with that payload is received. Thus, callback functions for - * the reception of SETTINGS frame will be invoked. The stream with - * stream ID=1 is opened. The |stream_user_data| is ignored. The - * opened stream becomes half-closed (remote). - * - * If the request method is HEAD, pass nonzero value to - * |head_request|. Otherwise, pass 0. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP2_ERR_NOMEM` - * Out of memory. - * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT` - * The |settings_payload| is badly formed. - * :enum:`NGHTTP2_ERR_PROTO` - * The stream ID 1 is already used or closed; or is not available. - */ -NGHTTP2_EXTERN int nghttp2_session_upgrade2(nghttp2_session *session, - const uint8_t *settings_payload, - size_t settings_payloadlen, - int head_request, - void *stream_user_data); - -/** - * @function - * - * Serializes the SETTINGS values |iv| in the |buf|. The size of the - * |buf| is specified by |buflen|. The number of entries in the |iv| - * array is given by |niv|. The required space in |buf| for the |niv| - * entries is ``8*niv`` bytes and if the given buffer is too small, an - * error is returned. This function is used mainly for creating a - * SETTINGS payload to be sent with the ``HTTP2-Settings`` header - * field in an HTTP Upgrade request. The data written in |buf| is NOT - * base64url encoded and the application is responsible for encoding. - * - * This function returns the number of bytes written in |buf|, or one - * of the following negative error codes: - * - * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT` - * The |iv| contains duplicate settings ID or invalid value. - * - * :enum:`NGHTTP2_ERR_INSUFF_BUFSIZE` - * The provided |buflen| size is too small to hold the output. - */ -NGHTTP2_EXTERN ssize_t -nghttp2_pack_settings_payload(uint8_t *buf, size_t buflen, - const nghttp2_settings_entry *iv, size_t niv); - -/** - * @function - * - * Returns string describing the |lib_error_code|. The - * |lib_error_code| must be one of the :enum:`nghttp2_error`. - */ -NGHTTP2_EXTERN const char *nghttp2_strerror(int lib_error_code); - -/** - * @function - * - * Returns string representation of HTTP/2 error code |error_code| - * (e.g., ``PROTOCOL_ERROR`` is returned if ``error_code == - * NGHTTP2_PROTOCOL_ERROR``). If string representation is unknown for - * given |error_code|, this function returns string ``unknown``. - */ -NGHTTP2_EXTERN const char *nghttp2_http2_strerror(uint32_t error_code); - -/** - * @function - * - * Initializes |pri_spec| with the |stream_id| of the stream to depend - * on with |weight| and its exclusive flag. If |exclusive| is - * nonzero, exclusive flag is set. - * - * The |weight| must be in [:enum:`NGHTTP2_MIN_WEIGHT`, - * :enum:`NGHTTP2_MAX_WEIGHT`], inclusive. - */ -NGHTTP2_EXTERN void nghttp2_priority_spec_init(nghttp2_priority_spec *pri_spec, - int32_t stream_id, - int32_t weight, int exclusive); - -/** - * @function - * - * Initializes |pri_spec| with the default values. The default values - * are: stream_id = 0, weight = :macro:`NGHTTP2_DEFAULT_WEIGHT` and - * exclusive = 0. - */ -NGHTTP2_EXTERN void -nghttp2_priority_spec_default_init(nghttp2_priority_spec *pri_spec); - -/** - * @function - * - * Returns nonzero if the |pri_spec| is filled with default values. - */ -NGHTTP2_EXTERN int -nghttp2_priority_spec_check_default(const nghttp2_priority_spec *pri_spec); - -/** - * @function - * - * Submits HEADERS frame and optionally one or more DATA frames. - * - * The |pri_spec| is priority specification of this request. ``NULL`` - * means the default priority (see - * `nghttp2_priority_spec_default_init()`). To specify the priority, - * use `nghttp2_priority_spec_init()`. If |pri_spec| is not ``NULL``, - * this function will copy its data members. - * - * The ``pri_spec->weight`` must be in [:enum:`NGHTTP2_MIN_WEIGHT`, - * :enum:`NGHTTP2_MAX_WEIGHT`], inclusive. If ``pri_spec->weight`` is - * strictly less than :enum:`NGHTTP2_MIN_WEIGHT`, it becomes - * :enum:`NGHTTP2_MIN_WEIGHT`. If it is strictly greater than - * :enum:`NGHTTP2_MAX_WEIGHT`, it becomes :enum:`NGHTTP2_MAX_WEIGHT`. - * - * The |nva| is an array of name/value pair :type:`nghttp2_nv` with - * |nvlen| elements. The application is responsible to include - * required pseudo-header fields (header field whose name starts with - * ":") in |nva| and must place pseudo-headers before regular header - * fields. - * - * This function creates copies of all name/value pairs in |nva|. It - * also lower-cases all names in |nva|. The order of elements in - * |nva| is preserved. For header fields with - * :enum:`NGHTTP2_NV_FLAG_NO_COPY_NAME` and - * :enum:`NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set, header field name - * and value are not copied respectively. With - * :enum:`NGHTTP2_NV_FLAG_NO_COPY_NAME`, application is responsible to - * pass header field name in lowercase. The application should - * maintain the references to them until - * :type:`nghttp2_on_frame_send_callback` or - * :type:`nghttp2_on_frame_not_send_callback` is called. - * - * HTTP/2 specification has requirement about header fields in the - * request HEADERS. See the specification for more details. - * - * If |data_prd| is not ``NULL``, it provides data which will be sent - * in subsequent DATA frames. In this case, a method that allows - * request message bodies - * (https://tools.ietf.org/html/rfc7231#section-4) must be specified - * with ``:method`` key in |nva| (e.g. ``POST``). This function does - * not take ownership of the |data_prd|. The function copies the - * members of the |data_prd|. If |data_prd| is ``NULL``, HEADERS have - * END_STREAM set. The |stream_user_data| is data associated to the - * stream opened by this request and can be an arbitrary pointer, - * which can be retrieved later by - * `nghttp2_session_get_stream_user_data()`. - * - * This function returns assigned stream ID if it succeeds, or one of - * the following negative error codes: - * - * :enum:`NGHTTP2_ERR_NOMEM` - * Out of memory. - * :enum:`NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE` - * No stream ID is available because maximum stream ID was - * reached. - * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT` - * Trying to depend on itself (new stream ID equals - * ``pri_spec->stream_id``). - * :enum:`NGHTTP2_ERR_PROTO` - * The |session| is server session. - * - * .. warning:: - * - * This function returns assigned stream ID if it succeeds. But - * that stream is not opened yet. The application must not submit - * frame to that stream ID before - * :type:`nghttp2_before_frame_send_callback` is called for this - * frame. - * - */ -NGHTTP2_EXTERN int32_t -nghttp2_submit_request(nghttp2_session *session, - const nghttp2_priority_spec *pri_spec, - const nghttp2_nv *nva, size_t nvlen, - const nghttp2_data_provider *data_prd, - void *stream_user_data); - -/** - * @function - * - * Submits response HEADERS frame and optionally one or more DATA - * frames against the stream |stream_id|. - * - * The |nva| is an array of name/value pair :type:`nghttp2_nv` with - * |nvlen| elements. The application is responsible to include - * required pseudo-header fields (header field whose name starts with - * ":") in |nva| and must place pseudo-headers before regular header - * fields. - * - * This function creates copies of all name/value pairs in |nva|. It - * also lower-cases all names in |nva|. The order of elements in - * |nva| is preserved. For header fields with - * :enum:`NGHTTP2_NV_FLAG_NO_COPY_NAME` and - * :enum:`NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set, header field name - * and value are not copied respectively. With - * :enum:`NGHTTP2_NV_FLAG_NO_COPY_NAME`, application is responsible to - * pass header field name in lowercase. The application should - * maintain the references to them until - * :type:`nghttp2_on_frame_send_callback` or - * :type:`nghttp2_on_frame_not_send_callback` is called. - * - * HTTP/2 specification has requirement about header fields in the - * response HEADERS. See the specification for more details. - * - * If |data_prd| is not ``NULL``, it provides data which will be sent - * in subsequent DATA frames. This function does not take ownership - * of the |data_prd|. The function copies the members of the - * |data_prd|. If |data_prd| is ``NULL``, HEADERS will have - * END_STREAM flag set. - * - * This method can be used as normal HTTP response and push response. - * When pushing a resource using this function, the |session| must be - * configured using `nghttp2_session_server_new()` or its variants and - * the target stream denoted by the |stream_id| must be reserved using - * `nghttp2_submit_push_promise()`. - * - * To send non-final response headers (e.g., HTTP status 101), don't - * use this function because this function half-closes the outbound - * stream. Instead, use `nghttp2_submit_headers()` for this purpose. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP2_ERR_NOMEM` - * Out of memory. - * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT` - * The |stream_id| is 0. - * :enum:`NGHTTP2_ERR_DATA_EXIST` - * DATA or HEADERS has been already submitted and not fully - * processed yet. Normally, this does not happen, but when - * application wrongly calls `nghttp2_submit_response()` twice, - * this may happen. - * :enum:`NGHTTP2_ERR_PROTO` - * The |session| is client session. - * - * .. warning:: - * - * Calling this function twice for the same stream ID may lead to - * program crash. It is generally considered to a programming error - * to commit response twice. - */ -NGHTTP2_EXTERN int -nghttp2_submit_response(nghttp2_session *session, int32_t stream_id, - const nghttp2_nv *nva, size_t nvlen, - const nghttp2_data_provider *data_prd); - -/** - * @function - * - * Submits trailer fields HEADERS against the stream |stream_id|. - * - * The |nva| is an array of name/value pair :type:`nghttp2_nv` with - * |nvlen| elements. The application is responsible not to include - * pseudo-header fields (header field whose name starts with ":") in - * |nva|. - * - * This function creates copies of all name/value pairs in |nva|. It - * also lower-cases all names in |nva|. The order of elements in - * |nva| is preserved. For header fields with - * :enum:`NGHTTP2_NV_FLAG_NO_COPY_NAME` and - * :enum:`NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set, header field name - * and value are not copied respectively. With - * :enum:`NGHTTP2_NV_FLAG_NO_COPY_NAME`, application is responsible to - * pass header field name in lowercase. The application should - * maintain the references to them until - * :type:`nghttp2_on_frame_send_callback` or - * :type:`nghttp2_on_frame_not_send_callback` is called. - * - * For server, trailer fields must follow response HEADERS or response - * DATA without END_STREAM flat set. The library does not enforce - * this requirement, and applications should do this for themselves. - * If `nghttp2_submit_trailer()` is called before any response HEADERS - * submission (usually by `nghttp2_submit_response()`), the content of - * |nva| will be sent as response headers, which will result in error. - * - * This function has the same effect with `nghttp2_submit_headers()`, - * with flags = :enum:`NGHTTP2_FLAG_END_STREAM` and both pri_spec and - * stream_user_data to NULL. - * - * To submit trailer fields after `nghttp2_submit_response()` is - * called, the application has to specify - * :type:`nghttp2_data_provider` to `nghttp2_submit_response()`. - * Inside of :type:`nghttp2_data_source_read_callback`, when setting - * :enum:`NGHTTP2_DATA_FLAG_EOF`, also set - * :enum:`NGHTTP2_DATA_FLAG_NO_END_STREAM`. After that, the - * application can send trailer fields using - * `nghttp2_submit_trailer()`. `nghttp2_submit_trailer()` can be used - * inside :type:`nghttp2_data_source_read_callback`. - * - * This function returns 0 if it succeeds and |stream_id| is -1. - * Otherwise, this function returns 0 if it succeeds, or one of the - * following negative error codes: - * - * :enum:`NGHTTP2_ERR_NOMEM` - * Out of memory. - * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT` - * The |stream_id| is 0. - */ -NGHTTP2_EXTERN int nghttp2_submit_trailer(nghttp2_session *session, - int32_t stream_id, - const nghttp2_nv *nva, size_t nvlen); - -/** - * @function - * - * Submits HEADERS frame. The |flags| is bitwise OR of the - * following values: - * - * * :enum:`NGHTTP2_FLAG_END_STREAM` - * - * If |flags| includes :enum:`NGHTTP2_FLAG_END_STREAM`, this frame has - * END_STREAM flag set. - * - * The library handles the CONTINUATION frame internally and it - * correctly sets END_HEADERS to the last sequence of the PUSH_PROMISE - * or CONTINUATION frame. - * - * If the |stream_id| is -1, this frame is assumed as request (i.e., - * request HEADERS frame which opens new stream). In this case, the - * assigned stream ID will be returned. Otherwise, specify stream ID - * in |stream_id|. - * - * The |pri_spec| is priority specification of this request. ``NULL`` - * means the default priority (see - * `nghttp2_priority_spec_default_init()`). To specify the priority, - * use `nghttp2_priority_spec_init()`. If |pri_spec| is not ``NULL``, - * this function will copy its data members. - * - * The ``pri_spec->weight`` must be in [:enum:`NGHTTP2_MIN_WEIGHT`, - * :enum:`NGHTTP2_MAX_WEIGHT`], inclusive. If ``pri_spec->weight`` is - * strictly less than :enum:`NGHTTP2_MIN_WEIGHT`, it becomes - * :enum:`NGHTTP2_MIN_WEIGHT`. If it is strictly greater than - * :enum:`NGHTTP2_MAX_WEIGHT`, it becomes :enum:`NGHTTP2_MAX_WEIGHT`. - * - * The |nva| is an array of name/value pair :type:`nghttp2_nv` with - * |nvlen| elements. The application is responsible to include - * required pseudo-header fields (header field whose name starts with - * ":") in |nva| and must place pseudo-headers before regular header - * fields. - * - * This function creates copies of all name/value pairs in |nva|. It - * also lower-cases all names in |nva|. The order of elements in - * |nva| is preserved. For header fields with - * :enum:`NGHTTP2_NV_FLAG_NO_COPY_NAME` and - * :enum:`NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set, header field name - * and value are not copied respectively. With - * :enum:`NGHTTP2_NV_FLAG_NO_COPY_NAME`, application is responsible to - * pass header field name in lowercase. The application should - * maintain the references to them until - * :type:`nghttp2_on_frame_send_callback` or - * :type:`nghttp2_on_frame_not_send_callback` is called. - * - * The |stream_user_data| is a pointer to an arbitrary data which is - * associated to the stream this frame will open. Therefore it is - * only used if this frame opens streams, in other words, it changes - * stream state from idle or reserved to open. - * - * This function is low-level in a sense that the application code can - * specify flags directly. For usual HTTP request, - * `nghttp2_submit_request()` is useful. Likewise, for HTTP response, - * prefer `nghttp2_submit_response()`. - * - * This function returns newly assigned stream ID if it succeeds and - * |stream_id| is -1. Otherwise, this function returns 0 if it - * succeeds, or one of the following negative error codes: - * - * :enum:`NGHTTP2_ERR_NOMEM` - * Out of memory. - * :enum:`NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE` - * No stream ID is available because maximum stream ID was - * reached. - * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT` - * The |stream_id| is 0; or trying to depend on itself (stream ID - * equals ``pri_spec->stream_id``). - * :enum:`NGHTTP2_ERR_DATA_EXIST` - * DATA or HEADERS has been already submitted and not fully - * processed yet. This happens if stream denoted by |stream_id| - * is in reserved state. - * :enum:`NGHTTP2_ERR_PROTO` - * The |stream_id| is -1, and |session| is server session. - * - * .. warning:: - * - * This function returns assigned stream ID if it succeeds and - * |stream_id| is -1. But that stream is not opened yet. The - * application must not submit frame to that stream ID before - * :type:`nghttp2_before_frame_send_callback` is called for this - * frame. - * - */ -NGHTTP2_EXTERN int32_t -nghttp2_submit_headers(nghttp2_session *session, uint8_t flags, - int32_t stream_id, const nghttp2_priority_spec *pri_spec, - const nghttp2_nv *nva, size_t nvlen, - void *stream_user_data); - -/** - * @function - * - * Submits one or more DATA frames to the stream |stream_id|. The - * data to be sent are provided by |data_prd|. If |flags| contains - * :enum:`NGHTTP2_FLAG_END_STREAM`, the last DATA frame has END_STREAM - * flag set. - * - * This function does not take ownership of the |data_prd|. The - * function copies the members of the |data_prd|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP2_ERR_NOMEM` - * Out of memory. - * :enum:`NGHTTP2_ERR_DATA_EXIST` - * DATA or HEADERS has been already submitted and not fully - * processed yet. - * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT` - * The |stream_id| is 0. - * :enum:`NGHTTP2_ERR_STREAM_CLOSED` - * The stream was already closed; or the |stream_id| is invalid. - * - * .. note:: - * - * Currently, only one DATA or HEADERS is allowed for a stream at a - * time. Submitting these frames more than once before first DATA - * or HEADERS is finished results in :enum:`NGHTTP2_ERR_DATA_EXIST` - * error code. The earliest callback which tells that previous - * frame is done is :type:`nghttp2_on_frame_send_callback`. In side - * that callback, new data can be submitted using - * `nghttp2_submit_data()`. Of course, all data except for last one - * must not have :enum:`NGHTTP2_FLAG_END_STREAM` flag set in - * |flags|. This sounds a bit complicated, and we recommend to use - * `nghttp2_submit_request()` and `nghttp2_submit_response()` to - * avoid this cascading issue. The experience shows that for HTTP - * use, these two functions are enough to implement both client and - * server. - */ -NGHTTP2_EXTERN int nghttp2_submit_data(nghttp2_session *session, uint8_t flags, - int32_t stream_id, - const nghttp2_data_provider *data_prd); - -/** - * @function - * - * Submits PRIORITY frame to change the priority of stream |stream_id| - * to the priority specification |pri_spec|. - * - * The |flags| is currently ignored and should be - * :enum:`NGHTTP2_FLAG_NONE`. - * - * The |pri_spec| is priority specification of this request. ``NULL`` - * is not allowed for this function. To specify the priority, use - * `nghttp2_priority_spec_init()`. This function will copy its data - * members. - * - * The ``pri_spec->weight`` must be in [:enum:`NGHTTP2_MIN_WEIGHT`, - * :enum:`NGHTTP2_MAX_WEIGHT`], inclusive. If ``pri_spec->weight`` is - * strictly less than :enum:`NGHTTP2_MIN_WEIGHT`, it becomes - * :enum:`NGHTTP2_MIN_WEIGHT`. If it is strictly greater than - * :enum:`NGHTTP2_MAX_WEIGHT`, it becomes :enum:`NGHTTP2_MAX_WEIGHT`. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP2_ERR_NOMEM` - * Out of memory. - * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT` - * The |stream_id| is 0; or the |pri_spec| is NULL; or trying to - * depend on itself. - */ -NGHTTP2_EXTERN int -nghttp2_submit_priority(nghttp2_session *session, uint8_t flags, - int32_t stream_id, - const nghttp2_priority_spec *pri_spec); - -/** - * @function - * - * Submits RST_STREAM frame to cancel/reject the stream |stream_id| - * with the error code |error_code|. - * - * The pre-defined error code is one of :enum:`nghttp2_error_code`. - * - * The |flags| is currently ignored and should be - * :enum:`NGHTTP2_FLAG_NONE`. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP2_ERR_NOMEM` - * Out of memory. - * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT` - * The |stream_id| is 0. - */ -NGHTTP2_EXTERN int nghttp2_submit_rst_stream(nghttp2_session *session, - uint8_t flags, int32_t stream_id, - uint32_t error_code); - -/** - * @function - * - * Stores local settings and submits SETTINGS frame. The |iv| is the - * pointer to the array of :type:`nghttp2_settings_entry`. The |niv| - * indicates the number of :type:`nghttp2_settings_entry`. - * - * The |flags| is currently ignored and should be - * :enum:`NGHTTP2_FLAG_NONE`. - * - * This function does not take ownership of the |iv|. This function - * copies all the elements in the |iv|. - * - * While updating individual stream's local window size, if the window - * size becomes strictly larger than NGHTTP2_MAX_WINDOW_SIZE, - * RST_STREAM is issued against such a stream. - * - * SETTINGS with :enum:`NGHTTP2_FLAG_ACK` is automatically submitted - * by the library and application could not send it at its will. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT` - * The |iv| contains invalid value (e.g., initial window size - * strictly greater than (1 << 31) - 1. - * :enum:`NGHTTP2_ERR_NOMEM` - * Out of memory. - */ -NGHTTP2_EXTERN int nghttp2_submit_settings(nghttp2_session *session, - uint8_t flags, - const nghttp2_settings_entry *iv, - size_t niv); - -/** - * @function - * - * Submits PUSH_PROMISE frame. - * - * The |flags| is currently ignored. The library handles the - * CONTINUATION frame internally and it correctly sets END_HEADERS to - * the last sequence of the PUSH_PROMISE or CONTINUATION frame. - * - * The |stream_id| must be client initiated stream ID. - * - * The |nva| is an array of name/value pair :type:`nghttp2_nv` with - * |nvlen| elements. The application is responsible to include - * required pseudo-header fields (header field whose name starts with - * ":") in |nva| and must place pseudo-headers before regular header - * fields. - * - * This function creates copies of all name/value pairs in |nva|. It - * also lower-cases all names in |nva|. The order of elements in - * |nva| is preserved. For header fields with - * :enum:`NGHTTP2_NV_FLAG_NO_COPY_NAME` and - * :enum:`NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set, header field name - * and value are not copied respectively. With - * :enum:`NGHTTP2_NV_FLAG_NO_COPY_NAME`, application is responsible to - * pass header field name in lowercase. The application should - * maintain the references to them until - * :type:`nghttp2_on_frame_send_callback` or - * :type:`nghttp2_on_frame_not_send_callback` is called. - * - * The |promised_stream_user_data| is a pointer to an arbitrary data - * which is associated to the promised stream this frame will open and - * make it in reserved state. It is available using - * `nghttp2_session_get_stream_user_data()`. The application can - * access it in :type:`nghttp2_before_frame_send_callback` and - * :type:`nghttp2_on_frame_send_callback` of this frame. - * - * The client side is not allowed to use this function. - * - * To submit response headers and data, use - * `nghttp2_submit_response()`. - * - * This function returns assigned promised stream ID if it succeeds, - * or one of the following negative error codes: - * - * :enum:`NGHTTP2_ERR_NOMEM` - * Out of memory. - * :enum:`NGHTTP2_ERR_PROTO` - * This function was invoked when |session| is initialized as - * client. - * :enum:`NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE` - * No stream ID is available because maximum stream ID was - * reached. - * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT` - * The |stream_id| is 0; The |stream_id| does not designate stream - * that peer initiated. - * :enum:`NGHTTP2_ERR_STREAM_CLOSED` - * The stream was already closed; or the |stream_id| is invalid. - * - * .. warning:: - * - * This function returns assigned promised stream ID if it succeeds. - * As of 1.16.0, stream object for pushed resource is created when - * this function succeeds. In that case, the application can submit - * push response for the promised frame. - * - * In 1.15.0 or prior versions, pushed stream is not opened yet when - * this function succeeds. The application must not submit frame to - * that stream ID before :type:`nghttp2_before_frame_send_callback` - * is called for this frame. - * - */ -NGHTTP2_EXTERN int32_t -nghttp2_submit_push_promise(nghttp2_session *session, uint8_t flags, - int32_t stream_id, const nghttp2_nv *nva, - size_t nvlen, void *promised_stream_user_data); - -/** - * @function - * - * Submits PING frame. You don't have to send PING back when you - * received PING frame. The library automatically submits PING frame - * in this case. - * - * The |flags| is bitwise OR of 0 or more of the following value. - * - * * :enum:`NGHTTP2_FLAG_ACK` - * - * Unless `nghttp2_option_set_no_auto_ping_ack()` is used, the |flags| - * should be :enum:`NGHTTP2_FLAG_NONE`. - * - * If the |opaque_data| is non ``NULL``, then it should point to the 8 - * bytes array of memory to specify opaque data to send with PING - * frame. If the |opaque_data| is ``NULL``, zero-cleared 8 bytes will - * be sent as opaque data. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP2_ERR_NOMEM` - * Out of memory. - */ -NGHTTP2_EXTERN int nghttp2_submit_ping(nghttp2_session *session, uint8_t flags, - const uint8_t *opaque_data); - -/** - * @function - * - * Submits GOAWAY frame with the last stream ID |last_stream_id| and - * the error code |error_code|. - * - * The pre-defined error code is one of :enum:`nghttp2_error_code`. - * - * The |flags| is currently ignored and should be - * :enum:`NGHTTP2_FLAG_NONE`. - * - * The |last_stream_id| is peer's stream ID or 0. So if |session| is - * initialized as client, |last_stream_id| must be even or 0. If - * |session| is initialized as server, |last_stream_id| must be odd or - * 0. - * - * The HTTP/2 specification says last_stream_id must not be increased - * from the value previously sent. So the actual value sent as - * last_stream_id is the minimum value between the given - * |last_stream_id| and the last_stream_id previously sent to the - * peer. - * - * If the |opaque_data| is not ``NULL`` and |opaque_data_len| is not - * zero, those data will be sent as additional debug data. The - * library makes a copy of the memory region pointed by |opaque_data| - * with the length |opaque_data_len|, so the caller does not need to - * keep this memory after the return of this function. If the - * |opaque_data_len| is 0, the |opaque_data| could be ``NULL``. - * - * After successful transmission of GOAWAY, following things happen. - * All incoming streams having strictly more than |last_stream_id| are - * closed. All incoming HEADERS which starts new stream are simply - * ignored. After all active streams are handled, both - * `nghttp2_session_want_read()` and `nghttp2_session_want_write()` - * return 0 and the application can close session. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP2_ERR_NOMEM` - * Out of memory. - * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT` - * The |opaque_data_len| is too large; the |last_stream_id| is - * invalid. - */ -NGHTTP2_EXTERN int nghttp2_submit_goaway(nghttp2_session *session, - uint8_t flags, int32_t last_stream_id, - uint32_t error_code, - const uint8_t *opaque_data, - size_t opaque_data_len); - -/** - * @function - * - * Returns the last stream ID of a stream for which - * :type:`nghttp2_on_frame_recv_callback` was invoked most recently. - * The returned value can be used as last_stream_id parameter for - * `nghttp2_submit_goaway()` and - * `nghttp2_session_terminate_session2()`. - * - * This function always succeeds. - */ -NGHTTP2_EXTERN int32_t -nghttp2_session_get_last_proc_stream_id(nghttp2_session *session); - -/** - * @function - * - * Returns nonzero if new request can be sent from local endpoint. - * - * This function return 0 if request is not allowed for this session. - * There are several reasons why request is not allowed. Some of the - * reasons are: session is server; stream ID has been spent; GOAWAY - * has been sent or received. - * - * The application can call `nghttp2_submit_request()` without - * consulting this function. In that case, `nghttp2_submit_request()` - * may return error. Or, request is failed to sent, and - * :type:`nghttp2_on_stream_close_callback` is called. - */ -NGHTTP2_EXTERN int -nghttp2_session_check_request_allowed(nghttp2_session *session); - -/** - * @function - * - * Returns nonzero if |session| is initialized as server side session. - */ -NGHTTP2_EXTERN int -nghttp2_session_check_server_session(nghttp2_session *session); - -/** - * @function - * - * Submits WINDOW_UPDATE frame. - * - * The |flags| is currently ignored and should be - * :enum:`NGHTTP2_FLAG_NONE`. - * - * The |stream_id| is the stream ID to send this WINDOW_UPDATE. To - * send connection level WINDOW_UPDATE, specify 0 to |stream_id|. - * - * If the |window_size_increment| is positive, the WINDOW_UPDATE with - * that value as window_size_increment is queued. If the - * |window_size_increment| is larger than the received bytes from the - * remote endpoint, the local window size is increased by that - * difference. If the sole purpose is to increase the local window - * size, consider to use `nghttp2_session_set_local_window_size()`. - * - * If the |window_size_increment| is negative, the local window size - * is decreased by -|window_size_increment|. If automatic - * WINDOW_UPDATE is enabled - * (`nghttp2_option_set_no_auto_window_update()`), and the library - * decided that the WINDOW_UPDATE should be submitted, then - * WINDOW_UPDATE is queued with the current received bytes count. If - * the sole purpose is to decrease the local window size, consider to - * use `nghttp2_session_set_local_window_size()`. - * - * If the |window_size_increment| is 0, the function does nothing and - * returns 0. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP2_ERR_FLOW_CONTROL` - * The local window size overflow or gets negative. - * :enum:`NGHTTP2_ERR_NOMEM` - * Out of memory. - */ -NGHTTP2_EXTERN int nghttp2_submit_window_update(nghttp2_session *session, - uint8_t flags, - int32_t stream_id, - int32_t window_size_increment); - -/** - * @function - * - * Set local window size (local endpoints's window size) to the given - * |window_size| for the given stream denoted by |stream_id|. To - * change connection level window size, specify 0 to |stream_id|. To - * increase window size, this function may submit WINDOW_UPDATE frame - * to transmission queue. - * - * The |flags| is currently ignored and should be - * :enum:`NGHTTP2_FLAG_NONE`. - * - * This sounds similar to `nghttp2_submit_window_update()`, but there - * are 2 differences. The first difference is that this function - * takes the absolute value of window size to set, rather than the - * delta. To change the window size, this may be easier to use since - * the application just declares the intended window size, rather than - * calculating delta. The second difference is that - * `nghttp2_submit_window_update()` affects the received bytes count - * which has not acked yet. By the specification of - * `nghttp2_submit_window_update()`, to strictly increase the local - * window size, we have to submit delta including all received bytes - * count, which might not be desirable in some cases. On the other - * hand, this function does not affect the received bytes count. It - * just sets the local window size to the given value. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT` - * The |stream_id| is negative. - * :enum:`NGHTTP2_ERR_NOMEM` - * Out of memory. - */ -NGHTTP2_EXTERN int -nghttp2_session_set_local_window_size(nghttp2_session *session, uint8_t flags, - int32_t stream_id, int32_t window_size); - -/** - * @function - * - * Submits extension frame. - * - * Application can pass arbitrary frame flags and stream ID in |flags| - * and |stream_id| respectively. The |payload| is opaque pointer, and - * it can be accessible though ``frame->ext.payload`` in - * :type:`nghttp2_pack_extension_callback`. The library will not own - * passed |payload| pointer. - * - * The application must set :type:`nghttp2_pack_extension_callback` - * using `nghttp2_session_callbacks_set_pack_extension_callback()`. - * - * The application should retain the memory pointed by |payload| until - * the transmission of extension frame is done (which is indicated by - * :type:`nghttp2_on_frame_send_callback`), or transmission fails - * (which is indicated by :type:`nghttp2_on_frame_not_send_callback`). - * If application does not touch this memory region after packing it - * into a wire format, application can free it inside - * :type:`nghttp2_pack_extension_callback`. - * - * The standard HTTP/2 frame cannot be sent with this function, so - * |type| must be strictly grater than 0x9. Otherwise, this function - * will fail with error code :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP2_ERR_INVALID_STATE` - * If :type:`nghttp2_pack_extension_callback` is not set. - * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT` - * If |type| specifies standard HTTP/2 frame type. The frame - * types in the rage [0x0, 0x9], both inclusive, are standard - * HTTP/2 frame type, and cannot be sent using this function. - * :enum:`NGHTTP2_ERR_NOMEM` - * Out of memory - */ -NGHTTP2_EXTERN int nghttp2_submit_extension(nghttp2_session *session, - uint8_t type, uint8_t flags, - int32_t stream_id, void *payload); - -/** - * @struct - * - * The payload of ALTSVC frame. ALTSVC frame is a non-critical - * extension to HTTP/2. If this frame is received, and - * `nghttp2_option_set_user_recv_extension_type()` is not set, and - * `nghttp2_option_set_builtin_recv_extension_type()` is set for - * :enum:`NGHTTP2_ALTSVC`, ``nghttp2_extension.payload`` will point to - * this struct. - * - * It has the following members: - */ -typedef struct { - /** - * The pointer to origin which this alternative service is - * associated with. This is not necessarily NULL-terminated. - */ - uint8_t *origin; - /** - * The length of the |origin|. - */ - size_t origin_len; - /** - * The pointer to Alt-Svc field value contained in ALTSVC frame. - * This is not necessarily NULL-terminated. - */ - uint8_t *field_value; - /** - * The length of the |field_value|. - */ - size_t field_value_len; -} nghttp2_ext_altsvc; - -/** - * @function - * - * Submits ALTSVC frame. - * - * ALTSVC frame is a non-critical extension to HTTP/2, and defined in - * is defined in `RFC 7383 - * `_. - * - * The |flags| is currently ignored and should be - * :enum:`NGHTTP2_FLAG_NONE`. - * - * The |origin| points to the origin this alternative service is - * associated with. The |origin_len| is the length of the origin. If - * |stream_id| is 0, the origin must be specified. If |stream_id| is - * not zero, the origin must be empty (in other words, |origin_len| - * must be 0). - * - * The ALTSVC frame is only usable from server side. If this function - * is invoked with client side session, this function returns - * :enum:`NGHTTP2_ERR_INVALID_STATE`. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP2_ERR_NOMEM` - * Out of memory - * :enum:`NGHTTP2_ERR_INVALID_STATE` - * The function is called from client side session - * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT` - * The sum of |origin_len| and |field_value_len| is larger than - * 16382; or |origin_len| is 0 while |stream_id| is 0; or - * |origin_len| is not 0 while |stream_id| is not 0. - */ -NGHTTP2_EXTERN int nghttp2_submit_altsvc(nghttp2_session *session, - uint8_t flags, int32_t stream_id, - const uint8_t *origin, - size_t origin_len, - const uint8_t *field_value, - size_t field_value_len); - -/** - * @function - * - * Compares ``lhs->name`` of length ``lhs->namelen`` bytes and - * ``rhs->name`` of length ``rhs->namelen`` bytes. Returns negative - * integer if ``lhs->name`` is found to be less than ``rhs->name``; or - * returns positive integer if ``lhs->name`` is found to be greater - * than ``rhs->name``; or returns 0 otherwise. - */ -NGHTTP2_EXTERN int nghttp2_nv_compare_name(const nghttp2_nv *lhs, - const nghttp2_nv *rhs); - -/** - * @function - * - * A helper function for dealing with NPN in client side or ALPN in - * server side. The |in| contains peer's protocol list in preferable - * order. The format of |in| is length-prefixed and not - * null-terminated. For example, ``h2`` and - * ``http/1.1`` stored in |in| like this:: - * - * in[0] = 2 - * in[1..2] = "h2" - * in[3] = 8 - * in[4..11] = "http/1.1" - * inlen = 12 - * - * The selection algorithm is as follows: - * - * 1. If peer's list contains HTTP/2 protocol the library supports, - * it is selected and returns 1. The following step is not taken. - * - * 2. If peer's list contains ``http/1.1``, this function selects - * ``http/1.1`` and returns 0. The following step is not taken. - * - * 3. This function selects nothing and returns -1 (So called - * non-overlap case). In this case, |out| and |outlen| are left - * untouched. - * - * Selecting ``h2`` means that ``h2`` is written into |*out| and its - * length (which is 2) is assigned to |*outlen|. - * - * For ALPN, refer to https://tools.ietf.org/html/rfc7301 - * - * See http://technotes.googlecode.com/git/nextprotoneg.html for more - * details about NPN. - * - * For NPN, to use this method you should do something like:: - * - * static int select_next_proto_cb(SSL* ssl, - * unsigned char **out, - * unsigned char *outlen, - * const unsigned char *in, - * unsigned int inlen, - * void *arg) - * { - * int rv; - * rv = nghttp2_select_next_protocol(out, outlen, in, inlen); - * if (rv == -1) { - * return SSL_TLSEXT_ERR_NOACK; - * } - * if (rv == 1) { - * ((MyType*)arg)->http2_selected = 1; - * } - * return SSL_TLSEXT_ERR_OK; - * } - * ... - * SSL_CTX_set_next_proto_select_cb(ssl_ctx, select_next_proto_cb, my_obj); - * - */ -NGHTTP2_EXTERN int nghttp2_select_next_protocol(unsigned char **out, - unsigned char *outlen, - const unsigned char *in, - unsigned int inlen); - -/** - * @function - * - * Returns a pointer to a nghttp2_info struct with version information - * about the run-time library in use. The |least_version| argument - * can be set to a 24 bit numerical value for the least accepted - * version number and if the condition is not met, this function will - * return a ``NULL``. Pass in 0 to skip the version checking. - */ -NGHTTP2_EXTERN nghttp2_info *nghttp2_version(int least_version); - -/** - * @function - * - * Returns nonzero if the :type:`nghttp2_error` library error code - * |lib_error| is fatal. - */ -NGHTTP2_EXTERN int nghttp2_is_fatal(int lib_error_code); - -/** - * @function - * - * Returns nonzero if HTTP header field name |name| of length |len| is - * valid according to http://tools.ietf.org/html/rfc7230#section-3.2 - * - * Because this is a header field name in HTTP2, the upper cased alphabet - * is treated as error. - */ -NGHTTP2_EXTERN int nghttp2_check_header_name(const uint8_t *name, size_t len); - -/** - * @function - * - * Returns nonzero if HTTP header field value |value| of length |len| - * is valid according to - * http://tools.ietf.org/html/rfc7230#section-3.2 - */ -NGHTTP2_EXTERN int nghttp2_check_header_value(const uint8_t *value, size_t len); - -/* HPACK API */ - -struct nghttp2_hd_deflater; - -/** - * @struct - * - * HPACK deflater object. - */ -typedef struct nghttp2_hd_deflater nghttp2_hd_deflater; - -/** - * @function - * - * Initializes |*deflater_ptr| for deflating name/values pairs. - * - * The |deflate_hd_table_bufsize_max| is the upper bound of header - * table size the deflater will use. - * - * If this function fails, |*deflater_ptr| is left untouched. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP2_ERR_NOMEM` - * Out of memory. - */ -NGHTTP2_EXTERN int nghttp2_hd_deflate_new(nghttp2_hd_deflater **deflater_ptr, - size_t deflate_hd_table_bufsize_max); - -/** - * @function - * - * Like `nghttp2_hd_deflate_new()`, but with additional custom memory - * allocator specified in the |mem|. - * - * The |mem| can be ``NULL`` and the call is equivalent to - * `nghttp2_hd_deflate_new()`. - * - * This function does not take ownership |mem|. The application is - * responsible for freeing |mem|. - * - * The library code does not refer to |mem| pointer after this - * function returns, so the application can safely free it. - */ -NGHTTP2_EXTERN int nghttp2_hd_deflate_new2(nghttp2_hd_deflater **deflater_ptr, - size_t deflate_hd_table_bufsize_max, - nghttp2_mem *mem); - -/** - * @function - * - * Deallocates any resources allocated for |deflater|. - */ -NGHTTP2_EXTERN void nghttp2_hd_deflate_del(nghttp2_hd_deflater *deflater); - -/** - * @function - * - * Changes header table size of the |deflater| to - * |settings_hd_table_bufsize_max| bytes. This may trigger eviction - * in the dynamic table. - * - * The |settings_hd_table_bufsize_max| should be the value received in - * SETTINGS_HEADER_TABLE_SIZE. - * - * The deflater never uses more memory than - * ``deflate_hd_table_bufsize_max`` bytes specified in - * `nghttp2_hd_deflate_new()`. Therefore, if - * |settings_hd_table_bufsize_max| > ``deflate_hd_table_bufsize_max``, - * resulting maximum table size becomes - * ``deflate_hd_table_bufsize_max``. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP2_ERR_NOMEM` - * Out of memory. - */ -NGHTTP2_EXTERN int -nghttp2_hd_deflate_change_table_size(nghttp2_hd_deflater *deflater, - size_t settings_hd_table_bufsize_max); - -/** - * @function - * - * Deflates the |nva|, which has the |nvlen| name/value pairs, into - * the |buf| of length |buflen|. - * - * If |buf| is not large enough to store the deflated header block, - * this function fails with :enum:`NGHTTP2_ERR_INSUFF_BUFSIZE`. The - * caller should use `nghttp2_hd_deflate_bound()` to know the upper - * bound of buffer size required to deflate given header name/value - * pairs. - * - * Once this function fails, subsequent call of this function always - * returns :enum:`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: - * - * :enum:`NGHTTP2_ERR_NOMEM` - * Out of memory. - * :enum:`NGHTTP2_ERR_HEADER_COMP` - * Deflation process has failed. - * :enum:`NGHTTP2_ERR_INSUFF_BUFSIZE` - * The provided |buflen| size is too small to hold the output. - */ -NGHTTP2_EXTERN ssize_t -nghttp2_hd_deflate_hd(nghttp2_hd_deflater *deflater, uint8_t *buf, - size_t buflen, const nghttp2_nv *nva, size_t nvlen); - -/** - * @function - * - * Returns an upper bound on the compressed size after deflation of - * |nva| of length |nvlen|. - */ -NGHTTP2_EXTERN size_t nghttp2_hd_deflate_bound(nghttp2_hd_deflater *deflater, - const nghttp2_nv *nva, - size_t nvlen); - -/** - * @function - * - * Returns the number of entries that header table of |deflater| - * contains. This is the sum of the number of static table and - * dynamic table, so the return value is at least 61. - */ -NGHTTP2_EXTERN -size_t nghttp2_hd_deflate_get_num_table_entries(nghttp2_hd_deflater *deflater); - -/** - * @function - * - * Returns the table entry denoted by |idx| from header table of - * |deflater|. The |idx| is 1-based, and idx=1 returns first entry of - * static table. idx=62 returns first entry of dynamic table if it - * exists. Specifying idx=0 is error, and this function returns NULL. - * If |idx| is strictly greater than the number of entries the tables - * contain, this function returns NULL. - */ -NGHTTP2_EXTERN -const nghttp2_nv * -nghttp2_hd_deflate_get_table_entry(nghttp2_hd_deflater *deflater, size_t idx); - -/** - * @function - * - * Returns the used dynamic table size, including the overhead 32 - * bytes per entry described in RFC 7541. - */ -NGHTTP2_EXTERN -size_t nghttp2_hd_deflate_get_dynamic_table_size(nghttp2_hd_deflater *deflater); - -/** - * @function - * - * Returns the maximum dynamic table size. - */ -NGHTTP2_EXTERN -size_t -nghttp2_hd_deflate_get_max_dynamic_table_size(nghttp2_hd_deflater *deflater); - -struct nghttp2_hd_inflater; - -/** - * @struct - * - * HPACK inflater object. - */ -typedef struct nghttp2_hd_inflater nghttp2_hd_inflater; - -/** - * @function - * - * Initializes |*inflater_ptr| for inflating name/values pairs. - * - * If this function fails, |*inflater_ptr| is left untouched. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP2_ERR_NOMEM` - * Out of memory. - */ -NGHTTP2_EXTERN int nghttp2_hd_inflate_new(nghttp2_hd_inflater **inflater_ptr); - -/** - * @function - * - * Like `nghttp2_hd_inflate_new()`, but with additional custom memory - * allocator specified in the |mem|. - * - * The |mem| can be ``NULL`` and the call is equivalent to - * `nghttp2_hd_inflate_new()`. - * - * This function does not take ownership |mem|. The application is - * responsible for freeing |mem|. - * - * The library code does not refer to |mem| pointer after this - * function returns, so the application can safely free it. - */ -NGHTTP2_EXTERN int nghttp2_hd_inflate_new2(nghttp2_hd_inflater **inflater_ptr, - nghttp2_mem *mem); - -/** - * @function - * - * Deallocates any resources allocated for |inflater|. - */ -NGHTTP2_EXTERN void nghttp2_hd_inflate_del(nghttp2_hd_inflater *inflater); - -/** - * @function - * - * Changes header table size in the |inflater|. This may trigger - * eviction in the dynamic table. - * - * The |settings_hd_table_bufsize_max| should be the value transmitted - * in SETTINGS_HEADER_TABLE_SIZE. - * - * This function must not be called while header block is being - * inflated. In other words, this function must be called after - * initialization of |inflater|, but before calling - * `nghttp2_hd_inflate_hd2()`, or after - * `nghttp2_hd_inflate_end_headers()`. Otherwise, - * `NGHTTP2_ERR_INVALID_STATE` was returned. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP2_ERR_NOMEM` - * Out of memory. - * :enum:`NGHTTP2_ERR_INVALID_STATE` - * The function is called while header block is being inflated. - * Probably, application missed to call - * `nghttp2_hd_inflate_end_headers()`. - */ -NGHTTP2_EXTERN int -nghttp2_hd_inflate_change_table_size(nghttp2_hd_inflater *inflater, - size_t settings_hd_table_bufsize_max); - -/** - * @enum - * - * The flags for header inflation. - */ -typedef enum { - /** - * No flag set. - */ - NGHTTP2_HD_INFLATE_NONE = 0, - /** - * Indicates all headers were inflated. - */ - NGHTTP2_HD_INFLATE_FINAL = 0x01, - /** - * Indicates a header was emitted. - */ - NGHTTP2_HD_INFLATE_EMIT = 0x02 -} nghttp2_hd_inflate_flag; - -/** - * @function - * - * .. warning:: - * - * Deprecated. Use `nghttp2_hd_inflate_hd2()` instead. - * - * Inflates name/value block stored in |in| with length |inlen|. This - * function performs decompression. For each successful emission of - * header name/value pair, :enum:`NGHTTP2_HD_INFLATE_EMIT` is set in - * |*inflate_flags| and name/value pair is assigned to the |nv_out| - * and the function returns. The caller must not free the members of - * |nv_out|. - * - * The |nv_out| may include pointers to the memory region in the |in|. - * The caller must retain the |in| while the |nv_out| is used. - * - * The application should call this function repeatedly until the - * ``(*inflate_flags) & NGHTTP2_HD_INFLATE_FINAL`` is nonzero and - * return value is non-negative. This means the all input values are - * processed successfully. Then the application must call - * `nghttp2_hd_inflate_end_headers()` to prepare for the next header - * block input. - * - * The caller can feed complete compressed header block. It also can - * feed it in several chunks. The caller must set |in_final| to - * nonzero if the given input is the last block of the compressed - * header. - * - * This function returns the number of bytes processed if it succeeds, - * or one of the following negative error codes: - * - * :enum:`NGHTTP2_ERR_NOMEM` - * Out of memory. - * :enum:`NGHTTP2_ERR_HEADER_COMP` - * Inflation process has failed. - * :enum:`NGHTTP2_ERR_BUFFER_ERROR` - * The header field name or value is too large. - * - * Example follows:: - * - * int inflate_header_block(nghttp2_hd_inflater *hd_inflater, - * uint8_t *in, size_t inlen, int final) - * { - * ssize_t rv; - * - * for(;;) { - * nghttp2_nv nv; - * int inflate_flags = 0; - * - * rv = nghttp2_hd_inflate_hd(hd_inflater, &nv, &inflate_flags, - * in, inlen, final); - * - * if(rv < 0) { - * fprintf(stderr, "inflate failed with error code %zd", rv); - * return -1; - * } - * - * in += rv; - * inlen -= rv; - * - * if(inflate_flags & NGHTTP2_HD_INFLATE_EMIT) { - * fwrite(nv.name, nv.namelen, 1, stderr); - * fprintf(stderr, ": "); - * fwrite(nv.value, nv.valuelen, 1, stderr); - * fprintf(stderr, "\n"); - * } - * if(inflate_flags & NGHTTP2_HD_INFLATE_FINAL) { - * nghttp2_hd_inflate_end_headers(hd_inflater); - * break; - * } - * if((inflate_flags & NGHTTP2_HD_INFLATE_EMIT) == 0 && - * inlen == 0) { - * break; - * } - * } - * - * return 0; - * } - * - */ -NGHTTP2_EXTERN ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_inflater *inflater, - nghttp2_nv *nv_out, - int *inflate_flags, uint8_t *in, - size_t inlen, int in_final); - -/** - * @function - * - * Inflates name/value block stored in |in| with length |inlen|. This - * function performs decompression. For each successful emission of - * header name/value pair, :enum:`NGHTTP2_HD_INFLATE_EMIT` is set in - * |*inflate_flags| and name/value pair is assigned to the |nv_out| - * and the function returns. The caller must not free the members of - * |nv_out|. - * - * The |nv_out| may include pointers to the memory region in the |in|. - * The caller must retain the |in| while the |nv_out| is used. - * - * The application should call this function repeatedly until the - * ``(*inflate_flags) & NGHTTP2_HD_INFLATE_FINAL`` is nonzero and - * return value is non-negative. This means the all input values are - * processed successfully. Then the application must call - * `nghttp2_hd_inflate_end_headers()` to prepare for the next header - * block input. - * - * The caller can feed complete compressed header block. It also can - * feed it in several chunks. The caller must set |in_final| to - * nonzero if the given input is the last block of the compressed - * header. - * - * This function returns the number of bytes processed if it succeeds, - * or one of the following negative error codes: - * - * :enum:`NGHTTP2_ERR_NOMEM` - * Out of memory. - * :enum:`NGHTTP2_ERR_HEADER_COMP` - * Inflation process has failed. - * :enum:`NGHTTP2_ERR_BUFFER_ERROR` - * The header field name or value is too large. - * - * Example follows:: - * - * int inflate_header_block(nghttp2_hd_inflater *hd_inflater, - * uint8_t *in, size_t inlen, int final) - * { - * ssize_t rv; - * - * for(;;) { - * nghttp2_nv nv; - * int inflate_flags = 0; - * - * rv = nghttp2_hd_inflate_hd2(hd_inflater, &nv, &inflate_flags, - * in, inlen, final); - * - * if(rv < 0) { - * fprintf(stderr, "inflate failed with error code %zd", rv); - * return -1; - * } - * - * in += rv; - * inlen -= rv; - * - * if(inflate_flags & NGHTTP2_HD_INFLATE_EMIT) { - * fwrite(nv.name, nv.namelen, 1, stderr); - * fprintf(stderr, ": "); - * fwrite(nv.value, nv.valuelen, 1, stderr); - * fprintf(stderr, "\n"); - * } - * if(inflate_flags & NGHTTP2_HD_INFLATE_FINAL) { - * nghttp2_hd_inflate_end_headers(hd_inflater); - * break; - * } - * if((inflate_flags & NGHTTP2_HD_INFLATE_EMIT) == 0 && - * inlen == 0) { - * break; - * } - * } - * - * return 0; - * } - * - */ -NGHTTP2_EXTERN ssize_t -nghttp2_hd_inflate_hd2(nghttp2_hd_inflater *inflater, nghttp2_nv *nv_out, - int *inflate_flags, const uint8_t *in, size_t inlen, - int in_final); - -/** - * @function - * - * Signals the end of decompression for one header block. - * - * This function returns 0 if it succeeds. Currently this function - * always succeeds. - */ -NGHTTP2_EXTERN int -nghttp2_hd_inflate_end_headers(nghttp2_hd_inflater *inflater); - -/** - * @function - * - * Returns the number of entries that header table of |inflater| - * contains. This is the sum of the number of static table and - * dynamic table, so the return value is at least 61. - */ -NGHTTP2_EXTERN -size_t nghttp2_hd_inflate_get_num_table_entries(nghttp2_hd_inflater *inflater); - -/** - * @function - * - * Returns the table entry denoted by |idx| from header table of - * |inflater|. The |idx| is 1-based, and idx=1 returns first entry of - * static table. idx=62 returns first entry of dynamic table if it - * exists. Specifying idx=0 is error, and this function returns NULL. - * If |idx| is strictly greater than the number of entries the tables - * contain, this function returns NULL. - */ -NGHTTP2_EXTERN -const nghttp2_nv * -nghttp2_hd_inflate_get_table_entry(nghttp2_hd_inflater *inflater, size_t idx); - -/** - * @function - * - * Returns the used dynamic table size, including the overhead 32 - * bytes per entry described in RFC 7541. - */ -NGHTTP2_EXTERN -size_t nghttp2_hd_inflate_get_dynamic_table_size(nghttp2_hd_inflater *inflater); - -/** - * @function - * - * Returns the maximum dynamic table size. - */ -NGHTTP2_EXTERN -size_t -nghttp2_hd_inflate_get_max_dynamic_table_size(nghttp2_hd_inflater *inflater); - -struct nghttp2_stream; - -/** - * @struct - * - * The structure to represent HTTP/2 stream. The details of this - * structure are intentionally hidden from the public API. - */ -typedef struct nghttp2_stream nghttp2_stream; - -/** - * @function - * - * Returns pointer to :type:`nghttp2_stream` object denoted by - * |stream_id|. If stream was not found, returns NULL. - * - * Returns imaginary root stream (see - * `nghttp2_session_get_root_stream()`) if 0 is given in |stream_id|. - * - * Unless |stream_id| == 0, the returned pointer is valid until next - * call of `nghttp2_session_send()`, `nghttp2_session_mem_send()`, - * `nghttp2_session_recv()`, and `nghttp2_session_mem_recv()`. - */ -NGHTTP2_EXTERN nghttp2_stream * -nghttp2_session_find_stream(nghttp2_session *session, int32_t stream_id); - -/** - * @enum - * - * State of stream as described in RFC 7540. - */ -typedef enum { - /** - * idle state. - */ - NGHTTP2_STREAM_STATE_IDLE = 1, - /** - * open state. - */ - NGHTTP2_STREAM_STATE_OPEN, - /** - * reserved (local) state. - */ - NGHTTP2_STREAM_STATE_RESERVED_LOCAL, - /** - * reserved (remote) state. - */ - NGHTTP2_STREAM_STATE_RESERVED_REMOTE, - /** - * half closed (local) state. - */ - NGHTTP2_STREAM_STATE_HALF_CLOSED_LOCAL, - /** - * half closed (remote) state. - */ - NGHTTP2_STREAM_STATE_HALF_CLOSED_REMOTE, - /** - * closed state. - */ - NGHTTP2_STREAM_STATE_CLOSED -} nghttp2_stream_proto_state; - -/** - * @function - * - * Returns state of |stream|. The root stream retrieved by - * `nghttp2_session_get_root_stream()` will have stream state - * :enum:`NGHTTP2_STREAM_STATE_IDLE`. - */ -NGHTTP2_EXTERN nghttp2_stream_proto_state -nghttp2_stream_get_state(nghttp2_stream *stream); - -/** - * @function - * - * Returns root of dependency tree, which is imaginary stream with - * stream ID 0. The returned pointer is valid until |session| is - * freed by `nghttp2_session_del()`. - */ -NGHTTP2_EXTERN nghttp2_stream * -nghttp2_session_get_root_stream(nghttp2_session *session); - -/** - * @function - * - * Returns the parent stream of |stream| in dependency tree. Returns - * NULL if there is no such stream. - */ -NGHTTP2_EXTERN nghttp2_stream * -nghttp2_stream_get_parent(nghttp2_stream *stream); - -NGHTTP2_EXTERN int32_t nghttp2_stream_get_stream_id(nghttp2_stream *stream); - -/** - * @function - * - * Returns the next sibling stream of |stream| in dependency tree. - * Returns NULL if there is no such stream. - */ -NGHTTP2_EXTERN nghttp2_stream * -nghttp2_stream_get_next_sibling(nghttp2_stream *stream); - -/** - * @function - * - * Returns the previous sibling stream of |stream| in dependency tree. - * Returns NULL if there is no such stream. - */ -NGHTTP2_EXTERN nghttp2_stream * -nghttp2_stream_get_previous_sibling(nghttp2_stream *stream); - -/** - * @function - * - * Returns the first child stream of |stream| in dependency tree. - * Returns NULL if there is no such stream. - */ -NGHTTP2_EXTERN nghttp2_stream * -nghttp2_stream_get_first_child(nghttp2_stream *stream); - -/** - * @function - * - * Returns dependency weight to the parent stream of |stream|. - */ -NGHTTP2_EXTERN int32_t nghttp2_stream_get_weight(nghttp2_stream *stream); - -/** - * @function - * - * Returns the sum of the weight for |stream|'s children. - */ -NGHTTP2_EXTERN int32_t -nghttp2_stream_get_sum_dependency_weight(nghttp2_stream *stream); - -#ifdef __cplusplus -} -#endif - -#endif /* NGHTTP2_H */ diff --git a/tools/sdk/include/nghttp/nghttp2/nghttp2ver.h b/tools/sdk/include/nghttp/nghttp2/nghttp2ver.h index a12cb708..ccbbfb3f 100644 --- a/tools/sdk/include/nghttp/nghttp2/nghttp2ver.h +++ b/tools/sdk/include/nghttp/nghttp2/nghttp2ver.h @@ -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 */ diff --git a/tools/sdk/include/nghttp/nghttp2_buf.h b/tools/sdk/include/nghttp/nghttp2_buf.h deleted file mode 100644 index 6770d6f3..00000000 --- a/tools/sdk/include/nghttp/nghttp2_buf.h +++ /dev/null @@ -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 -#endif /* HAVE_CONFIG_H */ - -#include - -#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 */ diff --git a/tools/sdk/include/nghttp/nghttp2_callbacks.h b/tools/sdk/include/nghttp/nghttp2_callbacks.h deleted file mode 100644 index 5f08474a..00000000 --- a/tools/sdk/include/nghttp/nghttp2_callbacks.h +++ /dev/null @@ -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 -#endif /* HAVE_CONFIG_H */ - -#include - -/* - * 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 */ diff --git a/tools/sdk/include/nghttp/nghttp2_frame.h b/tools/sdk/include/nghttp/nghttp2_frame.h deleted file mode 100644 index 6493465a..00000000 --- a/tools/sdk/include/nghttp/nghttp2_frame.h +++ /dev/null @@ -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 -#endif /* HAVE_CONFIG_H */ - -#include -#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 */ diff --git a/tools/sdk/include/nghttp/nghttp2_hd.h b/tools/sdk/include/nghttp/nghttp2_hd.h deleted file mode 100644 index 1da9eb58..00000000 --- a/tools/sdk/include/nghttp/nghttp2_hd.h +++ /dev/null @@ -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 -#endif /* HAVE_CONFIG_H */ - -#include - -#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 */ diff --git a/tools/sdk/include/nghttp/nghttp2_hd_huffman.h b/tools/sdk/include/nghttp/nghttp2_hd_huffman.h deleted file mode 100644 index 83323400..00000000 --- a/tools/sdk/include/nghttp/nghttp2_hd_huffman.h +++ /dev/null @@ -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 -#endif /* HAVE_CONFIG_H */ - -#include - -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 */ diff --git a/tools/sdk/include/nghttp/nghttp2_helper.h b/tools/sdk/include/nghttp/nghttp2_helper.h deleted file mode 100644 index 4a32564f..00000000 --- a/tools/sdk/include/nghttp/nghttp2_helper.h +++ /dev/null @@ -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 -#endif /* HAVE_CONFIG_H */ - -#include -#include - -#include -#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 */ diff --git a/tools/sdk/include/nghttp/nghttp2_http.h b/tools/sdk/include/nghttp/nghttp2_http.h deleted file mode 100644 index ac684c4d..00000000 --- a/tools/sdk/include/nghttp/nghttp2_http.h +++ /dev/null @@ -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 -#endif /* HAVE_CONFIG_H */ - -#include -#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 */ diff --git a/tools/sdk/include/nghttp/nghttp2_int.h b/tools/sdk/include/nghttp/nghttp2_int.h deleted file mode 100644 index c26c8e99..00000000 --- a/tools/sdk/include/nghttp/nghttp2_int.h +++ /dev/null @@ -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 -#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 */ diff --git a/tools/sdk/include/nghttp/nghttp2_map.h b/tools/sdk/include/nghttp/nghttp2_map.h deleted file mode 100644 index 21262488..00000000 --- a/tools/sdk/include/nghttp/nghttp2_map.h +++ /dev/null @@ -1,144 +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_MAP_H -#define NGHTTP2_MAP_H - -#ifdef HAVE_CONFIG_H -#include -#endif /* HAVE_CONFIG_H */ - -#include -#include "nghttp2_int.h" -#include "nghttp2_mem.h" - -/* Implementation of unordered map */ - -typedef int32_t key_type; - -typedef struct nghttp2_map_entry { - struct nghttp2_map_entry *next; - key_type key; -#if SIZEOF_INT_P == 4 - /* we requires 8 bytes aligment */ - int64_t pad; -#endif -} nghttp2_map_entry; - -typedef struct { - nghttp2_map_entry **table; - nghttp2_mem *mem; - size_t size; - uint32_t tablelen; -} nghttp2_map; - -/* - * Initializes the map |map|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP2_ERR_NOMEM - * Out of memory - */ -int nghttp2_map_init(nghttp2_map *map, nghttp2_mem *mem); - -/* - * Deallocates any resources allocated for |map|. The stored entries - * are not freed by this function. Use nghttp2_map_each_free() to free - * each entries. - */ -void nghttp2_map_free(nghttp2_map *map); - -/* - * Deallocates each entries using |func| function and any resources - * allocated for |map|. The |func| function is responsible for freeing - * given the |entry| object. The |ptr| will be passed to the |func| as - * send argument. The return value of the |func| will be ignored. - */ -void nghttp2_map_each_free(nghttp2_map *map, - int (*func)(nghttp2_map_entry *entry, void *ptr), - void *ptr); - -/* - * Initializes the |entry| with the |key|. All entries to be inserted - * to the map must be initialized with this function. - */ -void nghttp2_map_entry_init(nghttp2_map_entry *entry, key_type key); - -/* - * Inserts the new |entry| with the key |entry->key| to the map |map|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP2_ERR_INVALID_ARGUMENT - * The item associated by |key| already exists. - * NGHTTP2_ERR_NOMEM - * Out of memory - */ -int nghttp2_map_insert(nghttp2_map *map, nghttp2_map_entry *entry); - -/* - * Returns the entry associated by the key |key|. If there is no such - * entry, this function returns NULL. - */ -nghttp2_map_entry *nghttp2_map_find(nghttp2_map *map, key_type key); - -/* - * Removes the entry associated by the key |key| from the |map|. The - * removed entry is not freed by this function. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP2_ERR_INVALID_ARGUMENT - * The entry associated by |key| does not exist. - */ -int nghttp2_map_remove(nghttp2_map *map, key_type key); - -/* - * Returns the number of items stored in the map |map|. - */ -size_t nghttp2_map_size(nghttp2_map *map); - -/* - * Applies the function |func| to each entry in the |map| with the - * optional user supplied pointer |ptr|. - * - * If the |func| returns 0, this function calls the |func| with the - * next entry. If the |func| returns nonzero, it will not call the - * |func| for further entries and return the return value of the - * |func| immediately. Thus, this function returns 0 if all the - * invocations of the |func| return 0, or nonzero value which the last - * invocation of |func| returns. - * - * Don't use this function to free each entry. Use - * nghttp2_map_each_free() instead. - */ -int nghttp2_map_each(nghttp2_map *map, - int (*func)(nghttp2_map_entry *entry, void *ptr), - void *ptr); - -#endif /* NGHTTP2_MAP_H */ diff --git a/tools/sdk/include/nghttp/nghttp2_mem.h b/tools/sdk/include/nghttp/nghttp2_mem.h deleted file mode 100644 index 2d1bd6a0..00000000 --- a/tools/sdk/include/nghttp/nghttp2_mem.h +++ /dev/null @@ -1,45 +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_MEM_H -#define NGHTTP2_MEM_H - -#ifdef HAVE_CONFIG_H -#include -#endif /* HAVE_CONFIG_H */ - -#include - -/* The default, system standard memory allocator */ -nghttp2_mem *nghttp2_mem_default(void); - -/* Convenient wrapper functions to call allocator function in - |mem|. */ -void *nghttp2_mem_malloc(nghttp2_mem *mem, size_t size); -void nghttp2_mem_free(nghttp2_mem *mem, void *ptr); -void nghttp2_mem_free2(nghttp2_free free_func, void *ptr, void *mem_user_data); -void *nghttp2_mem_calloc(nghttp2_mem *mem, size_t nmemb, size_t size); -void *nghttp2_mem_realloc(nghttp2_mem *mem, void *ptr, size_t size); - -#endif /* NGHTTP2_MEM_H */ diff --git a/tools/sdk/include/nghttp/nghttp2_net.h b/tools/sdk/include/nghttp/nghttp2_net.h deleted file mode 100644 index 587f4189..00000000 --- a/tools/sdk/include/nghttp/nghttp2_net.h +++ /dev/null @@ -1,91 +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_NET_H -#define NGHTTP2_NET_H - -#ifdef HAVE_CONFIG_H -#include -#endif /* HAVE_CONFIG_H */ - -#ifdef HAVE_ARPA_INET_H -#include -#endif /* HAVE_ARPA_INET_H */ - -#ifdef HAVE_NETINET_IN_H -#include -#endif /* HAVE_NETINET_IN_H */ - -#include - -#if defined(WIN32) -/* Windows requires ws2_32 library for ntonl family functions. We - define inline functions for those function so that we don't have - dependeny on that lib. */ - -#ifdef _MSC_VER -#define STIN static __inline -#else -#define STIN static inline -#endif - -STIN uint32_t htonl(uint32_t hostlong) { - uint32_t res; - unsigned char *p = (unsigned char *)&res; - *p++ = hostlong >> 24; - *p++ = (hostlong >> 16) & 0xffu; - *p++ = (hostlong >> 8) & 0xffu; - *p = hostlong & 0xffu; - return res; -} - -STIN uint16_t htons(uint16_t hostshort) { - uint16_t res; - unsigned char *p = (unsigned char *)&res; - *p++ = hostshort >> 8; - *p = hostshort & 0xffu; - return res; -} - -STIN uint32_t ntohl(uint32_t netlong) { - uint32_t res; - unsigned char *p = (unsigned char *)&netlong; - res = *p++ << 24; - res += *p++ << 16; - res += *p++ << 8; - res += *p; - return res; -} - -STIN uint16_t ntohs(uint16_t netshort) { - uint16_t res; - unsigned char *p = (unsigned char *)&netshort; - res = *p++ << 8; - res += *p; - return res; -} - -#endif /* WIN32 */ - -#endif /* NGHTTP2_NET_H */ diff --git a/tools/sdk/include/nghttp/nghttp2_npn.h b/tools/sdk/include/nghttp/nghttp2_npn.h deleted file mode 100644 index a481bde3..00000000 --- a/tools/sdk/include/nghttp/nghttp2_npn.h +++ /dev/null @@ -1,34 +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_NPN_H -#define NGHTTP2_NPN_H - -#ifdef HAVE_CONFIG_H -#include -#endif /* HAVE_CONFIG_H */ - -#include - -#endif /* NGHTTP2_NPN_H */ diff --git a/tools/sdk/include/nghttp/nghttp2_option.h b/tools/sdk/include/nghttp/nghttp2_option.h deleted file mode 100644 index fb79b920..00000000 --- a/tools/sdk/include/nghttp/nghttp2_option.h +++ /dev/null @@ -1,116 +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_OPTION_H -#define NGHTTP2_OPTION_H - -#ifdef HAVE_CONFIG_H -#include -#endif /* HAVE_CONFIG_H */ - -#include - -/** - * Configuration options - */ -typedef enum { - /** - * This option prevents the library from sending WINDOW_UPDATE for a - * connection automatically. If this option is set to nonzero, the - * library won't send WINDOW_UPDATE for DATA until application calls - * nghttp2_session_consume() to indicate the amount of consumed - * DATA. By default, this option is set to zero. - */ - NGHTTP2_OPT_NO_AUTO_WINDOW_UPDATE = 1, - /** - * This option sets the SETTINGS_MAX_CONCURRENT_STREAMS value of - * remote endpoint as if it is received in SETTINGS frame. Without - * specifying this option, before the local endpoint receives - * SETTINGS_MAX_CONCURRENT_STREAMS in SETTINGS frame from remote - * endpoint, SETTINGS_MAX_CONCURRENT_STREAMS is unlimited. This may - * cause problem if local endpoint submits lots of requests - * initially and sending them at once to the remote peer may lead to - * the rejection of some requests. Specifying this option to the - * sensible value, say 100, may avoid this kind of issue. This value - * will be overwritten if the local endpoint receives - * SETTINGS_MAX_CONCURRENT_STREAMS from the remote endpoint. - */ - NGHTTP2_OPT_PEER_MAX_CONCURRENT_STREAMS = 1 << 1, - NGHTTP2_OPT_NO_RECV_CLIENT_MAGIC = 1 << 2, - NGHTTP2_OPT_NO_HTTP_MESSAGING = 1 << 3, - NGHTTP2_OPT_MAX_RESERVED_REMOTE_STREAMS = 1 << 4, - NGHTTP2_OPT_USER_RECV_EXT_TYPES = 1 << 5, - NGHTTP2_OPT_NO_AUTO_PING_ACK = 1 << 6, - NGHTTP2_OPT_BUILTIN_RECV_EXT_TYPES = 1 << 7, - NGHTTP2_OPT_MAX_SEND_HEADER_BLOCK_LENGTH = 1 << 8, -} nghttp2_option_flag; - -/** - * Struct to store option values for nghttp2_session. - */ -struct nghttp2_option { - /** - * NGHTTP2_OPT_MAX_SEND_HEADER_BLOCK_LENGTH - */ - size_t max_send_header_block_length; - /** - * Bitwise OR of nghttp2_option_flag to determine that which fields - * are specified. - */ - uint32_t opt_set_mask; - /** - * NGHTTP2_OPT_PEER_MAX_CONCURRENT_STREAMS - */ - uint32_t peer_max_concurrent_streams; - /** - * NGHTTP2_OPT_MAX_RESERVED_REMOTE_STREAMS - */ - uint32_t max_reserved_remote_streams; - /** - * NGHTTP2_OPT_BUILTIN_RECV_EXT_TYPES - */ - uint32_t builtin_recv_ext_types; - /** - * NGHTTP2_OPT_NO_AUTO_WINDOW_UPDATE - */ - int no_auto_window_update; - /** - * NGHTTP2_OPT_NO_RECV_CLIENT_MAGIC - */ - int no_recv_client_magic; - /** - * NGHTTP2_OPT_NO_HTTP_MESSAGING - */ - int no_http_messaging; - /** - * NGHTTP2_OPT_NO_AUTO_PING_ACK - */ - int no_auto_ping_ack; - /** - * NGHTTP2_OPT_USER_RECV_EXT_TYPES - */ - uint8_t user_recv_ext_types[32]; -}; - -#endif /* NGHTTP2_OPTION_H */ diff --git a/tools/sdk/include/nghttp/nghttp2_outbound_item.h b/tools/sdk/include/nghttp/nghttp2_outbound_item.h deleted file mode 100644 index 8bda776b..00000000 --- a/tools/sdk/include/nghttp/nghttp2_outbound_item.h +++ /dev/null @@ -1,166 +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_OUTBOUND_ITEM_H -#define NGHTTP2_OUTBOUND_ITEM_H - -#ifdef HAVE_CONFIG_H -#include -#endif /* HAVE_CONFIG_H */ - -#include -#include "nghttp2_frame.h" -#include "nghttp2_mem.h" - -/* struct used for HEADERS and PUSH_PROMISE frame */ -typedef struct { - nghttp2_data_provider data_prd; - void *stream_user_data; - /* error code when request HEADERS is canceled by RST_STREAM while - it is in queue. */ - uint32_t error_code; - /* nonzero if request HEADERS is canceled. The error code is stored - in |error_code|. */ - uint8_t canceled; -} nghttp2_headers_aux_data; - -/* struct used for DATA frame */ -typedef struct { - /** - * The data to be sent for this DATA frame. - */ - nghttp2_data_provider data_prd; - /** - * The flags of DATA frame. We use separate flags here and - * nghttp2_data frame. The latter contains flags actually sent to - * peer. This |flags| may contain NGHTTP2_FLAG_END_STREAM and only - * when |eof| becomes nonzero, flags in nghttp2_data has - * NGHTTP2_FLAG_END_STREAM set. - */ - uint8_t flags; - /** - * The flag to indicate whether EOF was reached or not. Initially - * |eof| is 0. It becomes 1 after all data were read. - */ - uint8_t eof; - /** - * The flag to indicate that NGHTTP2_DATA_FLAG_NO_COPY is used. - */ - uint8_t no_copy; -} nghttp2_data_aux_data; - -typedef enum { - NGHTTP2_GOAWAY_AUX_NONE = 0x0, - /* indicates that session should be terminated after the - transmission of this frame. */ - NGHTTP2_GOAWAY_AUX_TERM_ON_SEND = 0x1, - /* indicates that this GOAWAY is just a notification for graceful - shutdown. No nghttp2_session.goaway_flags should be updated on - the reaction to this frame. */ - NGHTTP2_GOAWAY_AUX_SHUTDOWN_NOTICE = 0x2 -} nghttp2_goaway_aux_flag; - -/* struct used for GOAWAY frame */ -typedef struct { - /* bitwise-OR of one or more of nghttp2_goaway_aux_flag. */ - uint8_t flags; -} nghttp2_goaway_aux_data; - -/* struct used for extension frame */ -typedef struct { - /* nonzero if this extension frame is serialized by library - function, instead of user-defined callbacks. */ - uint8_t builtin; -} nghttp2_ext_aux_data; - -/* Additional data which cannot be stored in nghttp2_frame struct */ -typedef union { - nghttp2_data_aux_data data; - nghttp2_headers_aux_data headers; - nghttp2_goaway_aux_data goaway; - nghttp2_ext_aux_data ext; -} nghttp2_aux_data; - -struct nghttp2_outbound_item; -typedef struct nghttp2_outbound_item nghttp2_outbound_item; - -struct nghttp2_outbound_item { - nghttp2_frame frame; - /* Storage for extension frame payload. frame->ext.payload points - to this structure to avoid frequent memory allocation. */ - nghttp2_ext_frame_payload ext_frame_payload; - nghttp2_aux_data aux_data; - /* The priority used in priority comparion. Smaller is served - ealier. For PING, SETTINGS and non-DATA frames (excluding - response HEADERS frame) have dedicated cycle value defined above. - For DATA frame, cycle is computed by taking into account of - effective weight and frame payload length previously sent, so - that the amount of transmission is distributed across streams - proportional to effective weight (inside a tree). */ - uint64_t cycle; - nghttp2_outbound_item *qnext; - /* nonzero if this object is queued, except for DATA or HEADERS - which are attached to stream as item. */ - uint8_t queued; -}; - -/* - * Initializes |item|. No memory allocation is done in this function. - * Don't call nghttp2_outbound_item_free() until frame member is - * initialized. - */ -void nghttp2_outbound_item_init(nghttp2_outbound_item *item); - -/* - * Deallocates resource for |item|. If |item| is NULL, this function - * does nothing. - */ -void nghttp2_outbound_item_free(nghttp2_outbound_item *item, nghttp2_mem *mem); - -/* - * queue for nghttp2_outbound_item. - */ -typedef struct { - nghttp2_outbound_item *head, *tail; - /* number of items in this queue. */ - size_t n; -} nghttp2_outbound_queue; - -void nghttp2_outbound_queue_init(nghttp2_outbound_queue *q); - -/* Pushes |item| into |q| */ -void nghttp2_outbound_queue_push(nghttp2_outbound_queue *q, - nghttp2_outbound_item *item); - -/* Pops |item| at the top from |q|. If |q| is empty, nothing - happens. */ -void nghttp2_outbound_queue_pop(nghttp2_outbound_queue *q); - -/* Returns the top item. */ -#define nghttp2_outbound_queue_top(Q) ((Q)->head) - -/* Returns the size of the queue */ -#define nghttp2_outbound_queue_size(Q) ((Q)->n) - -#endif /* NGHTTP2_OUTBOUND_ITEM_H */ diff --git a/tools/sdk/include/nghttp/nghttp2_pq.h b/tools/sdk/include/nghttp/nghttp2_pq.h deleted file mode 100644 index 6b0ecfb4..00000000 --- a/tools/sdk/include/nghttp/nghttp2_pq.h +++ /dev/null @@ -1,128 +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_PQ_H -#define NGHTTP2_PQ_H - -#ifdef HAVE_CONFIG_H -#include -#endif /* HAVE_CONFIG_H */ - -#include -#include "nghttp2_int.h" -#include "nghttp2_mem.h" - -/* Implementation of priority queue */ - -typedef struct { size_t index; } nghttp2_pq_entry; - -typedef struct { - /* The pointer to the pointer to the item stored */ - nghttp2_pq_entry **q; - /* Memory allocator */ - nghttp2_mem *mem; - /* The number of items sotred */ - size_t length; - /* The maximum number of items this pq can store. This is - automatically extended when length is reached to this value. */ - size_t capacity; - /* The less function between items */ - nghttp2_less less; -} nghttp2_pq; - -/* - * Initializes priority queue |pq| with compare function |cmp|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP2_ERR_NOMEM - * Out of memory. - */ -int nghttp2_pq_init(nghttp2_pq *pq, nghttp2_less less, nghttp2_mem *mem); - -/* - * Deallocates any resources allocated for |pq|. The stored items are - * not freed by this function. - */ -void nghttp2_pq_free(nghttp2_pq *pq); - -/* - * Adds |item| to the priority queue |pq|. - * - * This function returns 0 if it succeds, or one of the following - * negative error codes: - * - * NGHTTP2_ERR_NOMEM - * Out of memory. - */ -int nghttp2_pq_push(nghttp2_pq *pq, nghttp2_pq_entry *item); - -/* - * Returns item at the top of the queue |pq|. If the queue is empty, - * this function returns NULL. - */ -nghttp2_pq_entry *nghttp2_pq_top(nghttp2_pq *pq); - -/* - * Pops item at the top of the queue |pq|. The popped item is not - * freed by this function. - */ -void nghttp2_pq_pop(nghttp2_pq *pq); - -/* - * Returns nonzero if the queue |pq| is empty. - */ -int nghttp2_pq_empty(nghttp2_pq *pq); - -/* - * Returns the number of items in the queue |pq|. - */ -size_t nghttp2_pq_size(nghttp2_pq *pq); - -typedef int (*nghttp2_pq_item_cb)(nghttp2_pq_entry *item, void *arg); - -/* - * Updates each item in |pq| using function |fun| and re-construct - * priority queue. The |fun| must return non-zero if it modifies the - * item in a way that it affects ordering in the priority queue. The - * |arg| is passed to the 2nd parameter of |fun|. - */ -void nghttp2_pq_update(nghttp2_pq *pq, nghttp2_pq_item_cb fun, void *arg); - -/* - * Applys |fun| to each item in |pq|. The |arg| is passed as arg - * parameter to callback function. This function must not change the - * ordering key. If the return value from callback is nonzero, this - * function returns 1 immediately without iterating remaining items. - * Otherwise this function returns 0. - */ -int nghttp2_pq_each(nghttp2_pq *pq, nghttp2_pq_item_cb fun, void *arg); - -/* - * Removes |item| from priority queue. - */ -void nghttp2_pq_remove(nghttp2_pq *pq, nghttp2_pq_entry *item); - -#endif /* NGHTTP2_PQ_H */ diff --git a/tools/sdk/include/nghttp/nghttp2_priority_spec.h b/tools/sdk/include/nghttp/nghttp2_priority_spec.h deleted file mode 100644 index 98fac210..00000000 --- a/tools/sdk/include/nghttp/nghttp2_priority_spec.h +++ /dev/null @@ -1,42 +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_PRIORITY_SPEC_H -#define NGHTTP2_PRIORITY_SPEC_H - -#ifdef HAVE_CONFIG_H -#include -#endif /* HAVE_CONFIG_H */ - -#include - -/* - * This function normalizes pri_spec->weight if it is out of range. - * If pri_spec->weight is less than NGHTTP2_MIN_WEIGHT, it is set to - * NGHTTP2_MIN_WEIGHT. If pri_spec->weight is larger than - * NGHTTP2_MAX_WEIGHT, it is set to NGHTTP2_MAX_WEIGHT. - */ -void nghttp2_priority_spec_normalize_weight(nghttp2_priority_spec *pri_spec); - -#endif /* NGHTTP2_PRIORITY_SPEC_H */ diff --git a/tools/sdk/include/nghttp/nghttp2_queue.h b/tools/sdk/include/nghttp/nghttp2_queue.h deleted file mode 100644 index d872b07b..00000000 --- a/tools/sdk/include/nghttp/nghttp2_queue.h +++ /dev/null @@ -1,49 +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_QUEUE_H -#define NGHTTP2_QUEUE_H - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif /* HAVE_CONFIG_H */ - -#include - -typedef struct nghttp2_queue_cell { - void *data; - struct nghttp2_queue_cell *next; -} nghttp2_queue_cell; - -typedef struct { nghttp2_queue_cell *front, *back; } nghttp2_queue; - -void nghttp2_queue_init(nghttp2_queue *queue); -void nghttp2_queue_free(nghttp2_queue *queue); -int nghttp2_queue_push(nghttp2_queue *queue, void *data); -void nghttp2_queue_pop(nghttp2_queue *queue); -void *nghttp2_queue_front(nghttp2_queue *queue); -void *nghttp2_queue_back(nghttp2_queue *queue); -int nghttp2_queue_empty(nghttp2_queue *queue); - -#endif /* NGHTTP2_QUEUE_H */ diff --git a/tools/sdk/include/nghttp/nghttp2_rcbuf.h b/tools/sdk/include/nghttp/nghttp2_rcbuf.h deleted file mode 100644 index 29d1543e..00000000 --- a/tools/sdk/include/nghttp/nghttp2_rcbuf.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * nghttp2 - HTTP/2 C Library - * - * Copyright (c) 2016 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_RCBUF_H -#define NGHTTP2_RCBUF_H - -#ifdef HAVE_CONFIG_H -#include -#endif /* HAVE_CONFIG_H */ - -#include - -struct nghttp2_rcbuf { - /* custom memory allocator belongs to the mem parameter when - creating this object. */ - void *mem_user_data; - nghttp2_free free; - /* The pointer to the underlying buffer */ - uint8_t *base; - /* Size of buffer pointed by |base|. */ - size_t len; - /* Reference count */ - int32_t ref; -}; - -/* - * Allocates nghttp2_rcbuf object with |size| as initial buffer size. - * When the function succeeds, the reference count becomes 1. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP2_ERR_NOMEM: - * Out of memory. - */ -int nghttp2_rcbuf_new(nghttp2_rcbuf **rcbuf_ptr, size_t size, nghttp2_mem *mem); - -/* - * Like nghttp2_rcbuf_new(), but initializes the buffer with |src| of - * length |srclen|. This function allocates additional byte at the - * end and puts '\0' into it, so that the resulting buffer could be - * used as NULL-terminated string. Still (*rcbuf_ptr)->len equals to - * |srclen|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP2_ERR_NOMEM: - * Out of memory. - */ -int nghttp2_rcbuf_new2(nghttp2_rcbuf **rcbuf_ptr, const uint8_t *src, - size_t srclen, nghttp2_mem *mem); - -/* - * Frees |rcbuf| itself, regardless of its reference cout. - */ -void nghttp2_rcbuf_del(nghttp2_rcbuf *rcbuf); - -#endif /* NGHTTP2_RCBUF_H */ diff --git a/tools/sdk/include/nghttp/nghttp2_session.h b/tools/sdk/include/nghttp/nghttp2_session.h deleted file mode 100644 index 53470028..00000000 --- a/tools/sdk/include/nghttp/nghttp2_session.h +++ /dev/null @@ -1,878 +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_SESSION_H -#define NGHTTP2_SESSION_H - -#ifdef HAVE_CONFIG_H -#include -#endif /* HAVE_CONFIG_H */ - -#include -#include "nghttp2_map.h" -#include "nghttp2_frame.h" -#include "nghttp2_hd.h" -#include "nghttp2_stream.h" -#include "nghttp2_outbound_item.h" -#include "nghttp2_int.h" -#include "nghttp2_buf.h" -#include "nghttp2_callbacks.h" -#include "nghttp2_mem.h" - -/* The global variable for tests where we want to disable strict - preface handling. */ -extern int nghttp2_enable_strict_preface; - -/* - * Option flags. - */ -typedef enum { - NGHTTP2_OPTMASK_NO_AUTO_WINDOW_UPDATE = 1 << 0, - NGHTTP2_OPTMASK_NO_RECV_CLIENT_MAGIC = 1 << 1, - NGHTTP2_OPTMASK_NO_HTTP_MESSAGING = 1 << 2, - NGHTTP2_OPTMASK_NO_AUTO_PING_ACK = 1 << 3 -} nghttp2_optmask; - -/* - * bitmask for built-in type to enable the default handling for that - * type of the frame. - */ -typedef enum { - NGHTTP2_TYPEMASK_NONE = 0, - NGHTTP2_TYPEMASK_ALTSVC = 1 << 0 -} nghttp2_typemask; - -typedef enum { - NGHTTP2_OB_POP_ITEM, - NGHTTP2_OB_SEND_DATA, - NGHTTP2_OB_SEND_NO_COPY, - NGHTTP2_OB_SEND_CLIENT_MAGIC -} nghttp2_outbound_state; - -typedef struct { - nghttp2_outbound_item *item; - nghttp2_bufs framebufs; - nghttp2_outbound_state state; -} nghttp2_active_outbound_item; - -/* Buffer length for inbound raw byte stream used in - nghttp2_session_recv(). */ -#define NGHTTP2_INBOUND_BUFFER_LENGTH 3072//16384--LiuHan/08.12 - -/* The default maximum number of incoming reserved streams */ -#define NGHTTP2_MAX_INCOMING_RESERVED_STREAMS 200 - -/* Even if we have less SETTINGS_MAX_CONCURRENT_STREAMS than this - number, we keep NGHTTP2_MIN_IDLE_STREAMS streams in idle state */ -#define NGHTTP2_MIN_IDLE_STREAMS 16 - -/* The maximum number of items in outbound queue, which is considered - as flooding caused by peer. All frames are not considered here. - We only consider PING + ACK and SETTINGS + ACK. This is because - they both are response to the frame initiated by peer and peer can - send as many of them as they want. If peer does not read network, - response frames are stacked up, which leads to memory exhaustion. - The value selected here is arbitrary, but safe value and if we have - these frames in this number, it is considered suspicious. */ -#define NGHTTP2_MAX_OBQ_FLOOD_ITEM 10000 - -/* The default value of maximum number of concurrent streams. */ -#define NGHTTP2_DEFAULT_MAX_CONCURRENT_STREAMS 0xffffffffu - -/* Internal state when receiving incoming frame */ -typedef enum { - /* Receiving frame header */ - NGHTTP2_IB_READ_CLIENT_MAGIC, - NGHTTP2_IB_READ_FIRST_SETTINGS, - NGHTTP2_IB_READ_HEAD, - NGHTTP2_IB_READ_NBYTE, - NGHTTP2_IB_READ_HEADER_BLOCK, - NGHTTP2_IB_IGN_HEADER_BLOCK, - NGHTTP2_IB_IGN_PAYLOAD, - NGHTTP2_IB_FRAME_SIZE_ERROR, - NGHTTP2_IB_READ_SETTINGS, - NGHTTP2_IB_READ_GOAWAY_DEBUG, - NGHTTP2_IB_EXPECT_CONTINUATION, - NGHTTP2_IB_IGN_CONTINUATION, - NGHTTP2_IB_READ_PAD_DATA, - NGHTTP2_IB_READ_DATA, - NGHTTP2_IB_IGN_DATA, - NGHTTP2_IB_IGN_ALL, - NGHTTP2_IB_READ_ALTSVC_PAYLOAD, - NGHTTP2_IB_READ_EXTENSION_PAYLOAD -} nghttp2_inbound_state; - -typedef struct { - nghttp2_frame frame; - /* Storage for extension frame payload. frame->ext.payload points - to this structure to avoid frequent memory allocation. */ - nghttp2_ext_frame_payload ext_frame_payload; - /* The received SETTINGS entry. For the standard settings entries, - we only keep the last seen value. For - SETTINGS_HEADER_TABLE_SIZE, we also keep minimum value in the - last index. */ - nghttp2_settings_entry *iv; - /* buffer pointers to small buffer, raw_sbuf */ - nghttp2_buf sbuf; - /* buffer pointers to large buffer, raw_lbuf */ - nghttp2_buf lbuf; - /* Large buffer, malloced on demand */ - uint8_t *raw_lbuf; - /* The number of entry filled in |iv| */ - size_t niv; - /* The number of entries |iv| can store. */ - size_t max_niv; - /* How many bytes we still need to receive for current frame */ - size_t payloadleft; - /* padding length for the current frame */ - size_t padlen; - nghttp2_inbound_state state; - /* Small buffer. Currently the largest contiguous chunk to buffer - is frame header. We buffer part of payload, but they are smaller - than frame header. */ - uint8_t raw_sbuf[NGHTTP2_FRAME_HDLEN]; -} nghttp2_inbound_frame; - -typedef struct { - uint32_t header_table_size; - uint32_t enable_push; - uint32_t max_concurrent_streams; - uint32_t initial_window_size; - uint32_t max_frame_size; - uint32_t max_header_list_size; -} nghttp2_settings_storage; - -typedef enum { - NGHTTP2_GOAWAY_NONE = 0, - /* Flag means that connection should be terminated after sending GOAWAY. */ - NGHTTP2_GOAWAY_TERM_ON_SEND = 0x1, - /* Flag means GOAWAY to terminate session has been sent */ - NGHTTP2_GOAWAY_TERM_SENT = 0x2, - /* Flag means GOAWAY was sent */ - NGHTTP2_GOAWAY_SENT = 0x4, - /* Flag means GOAWAY was received */ - NGHTTP2_GOAWAY_RECV = 0x8 -} nghttp2_goaway_flag; - -/* nghttp2_inflight_settings stores the SETTINGS entries which local - endpoint has sent to the remote endpoint, and has not received ACK - yet. */ -struct nghttp2_inflight_settings { - struct nghttp2_inflight_settings *next; - nghttp2_settings_entry *iv; - size_t niv; -}; - -typedef struct nghttp2_inflight_settings nghttp2_inflight_settings; - -struct nghttp2_session { - nghttp2_map /* */ streams; - /* root of dependency tree*/ - nghttp2_stream root; - /* Queue for outbound urgent frames (PING and SETTINGS) */ - nghttp2_outbound_queue ob_urgent; - /* Queue for non-DATA frames */ - nghttp2_outbound_queue ob_reg; - /* Queue for outbound stream-creating HEADERS (request or push - response) frame, which are subject to - SETTINGS_MAX_CONCURRENT_STREAMS limit. */ - nghttp2_outbound_queue ob_syn; - nghttp2_active_outbound_item aob; - nghttp2_inbound_frame iframe; - nghttp2_hd_deflater hd_deflater; - nghttp2_hd_inflater hd_inflater; - nghttp2_session_callbacks callbacks; - /* Memory allocator */ - nghttp2_mem mem; - /* Base value when we schedule next DATA frame write. This is - updated when one frame was written. */ - uint64_t last_cycle; - void *user_data; - /* Points to the latest incoming closed stream. NULL if there is no - closed stream. Only used when session is initialized as - server. */ - nghttp2_stream *closed_stream_head; - /* Points to the oldest incoming closed stream. NULL if there is no - closed stream. Only used when session is initialized as - server. */ - nghttp2_stream *closed_stream_tail; - /* Points to the latest idle stream. NULL if there is no idle - stream. Only used when session is initialized as server .*/ - nghttp2_stream *idle_stream_head; - /* Points to the oldest idle stream. NULL if there is no idle - stream. Only used when session is initialized as erver. */ - nghttp2_stream *idle_stream_tail; - /* Queue of In-flight SETTINGS values. SETTINGS bearing ACK is not - considered as in-flight. */ - nghttp2_inflight_settings *inflight_settings_head; - /* The number of outgoing streams. This will be capped by - remote_settings.max_concurrent_streams. */ - size_t num_outgoing_streams; - /* The number of incoming streams. This will be capped by - local_settings.max_concurrent_streams. */ - size_t num_incoming_streams; - /* The number of incoming reserved streams. This is the number of - streams in reserved (remote) state. RFC 7540 does not limit this - number. nghttp2 offers - nghttp2_option_set_max_reserved_remote_streams() to achieve this. - If it is used, num_incoming_streams is capped by - max_incoming_reserved_streams. Client application should - consider to set this because without that server can send - arbitrary number of PUSH_PROMISE, and exhaust client's memory. */ - size_t num_incoming_reserved_streams; - /* The maximum number of incoming reserved streams (reserved - (remote) state). RST_STREAM will be sent for the pushed stream - which exceeds this limit. */ - size_t max_incoming_reserved_streams; - /* The number of closed streams still kept in |streams| hash. The - closed streams can be accessed through single linked list - |closed_stream_head|. The current implementation only keeps - incoming streams and session is initialized as server. */ - size_t num_closed_streams; - /* The number of idle streams kept in |streams| hash. The idle - streams can be accessed through doubly linked list - |idle_stream_head|. The current implementation only keeps idle - streams if session is initialized as server. */ - size_t num_idle_streams; - /* The number of bytes allocated for nvbuf */ - size_t nvbuflen; - /* Counter for detecting flooding in outbound queue */ - size_t obq_flood_counter_; - /* The maximum length of header block to send. Calculated by the - same way as nghttp2_hd_deflate_bound() does. */ - size_t max_send_header_block_length; - /* Next Stream ID. Made unsigned int to detect >= (1 << 31). */ - uint32_t next_stream_id; - /* The last stream ID this session initiated. For client session, - this is the last stream ID it has sent. For server session, it - is the last promised stream ID sent in PUSH_PROMISE. */ - int32_t last_sent_stream_id; - /* The largest stream ID received so far */ - int32_t last_recv_stream_id; - /* The largest stream ID which has been processed in some way. This - value will be used as last-stream-id when sending GOAWAY - frame. */ - int32_t last_proc_stream_id; - /* Counter of unique ID of PING. Wraps when it exceeds - NGHTTP2_MAX_UNIQUE_ID */ - uint32_t next_unique_id; - /* This is the last-stream-ID we have sent in GOAWAY */ - int32_t local_last_stream_id; - /* This is the value in GOAWAY frame received from remote endpoint. */ - int32_t remote_last_stream_id; - /* Current sender window size. This value is computed against the - current initial window size of remote endpoint. */ - int32_t remote_window_size; - /* Keep track of the number of bytes received without - WINDOW_UPDATE. This could be negative after submitting negative - value to WINDOW_UPDATE. */ - int32_t recv_window_size; - /* The number of bytes consumed by the application and now is - subject to WINDOW_UPDATE. This is only used when auto - WINDOW_UPDATE is turned off. */ - int32_t consumed_size; - /* The amount of recv_window_size cut using submitting negative - value to WINDOW_UPDATE */ - int32_t recv_reduction; - /* window size for local flow control. It is initially set to - NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE and could be - increased/decreased by submitting WINDOW_UPDATE. See - nghttp2_submit_window_update(). */ - int32_t local_window_size; - /* Settings value received from the remote endpoint. We just use ID - as index. The index = 0 is unused. */ - nghttp2_settings_storage remote_settings; - /* Settings value of the local endpoint. */ - nghttp2_settings_storage local_settings; - /* Option flags. This is bitwise-OR of 0 or more of nghttp2_optmask. */ - uint32_t opt_flags; - /* Unacked local SETTINGS_MAX_CONCURRENT_STREAMS value. We use this - to refuse the incoming stream if it exceeds this value. */ - uint32_t pending_local_max_concurrent_stream; - /* The bitwose OR of zero or more of nghttp2_typemask to indicate - that the default handling of extension frame is enabled. */ - uint32_t builtin_recv_ext_types; - /* Unacked local ENABLE_PUSH value. We use this to refuse - PUSH_PROMISE before SETTINGS ACK is received. */ - uint8_t pending_enable_push; - /* Nonzero if the session is server side. */ - uint8_t server; - /* Flags indicating GOAWAY is sent and/or recieved. The flags are - composed by bitwise OR-ing nghttp2_goaway_flag. */ - uint8_t goaway_flags; - /* This flag is used to reduce excessive queuing of WINDOW_UPDATE to - this session. The nonzero does not necessarily mean - WINDOW_UPDATE is not queued. */ - uint8_t window_update_queued; - /* Bitfield of extension frame types that application is willing to - receive. To designate the bit of given frame type i, use - user_recv_ext_types[i / 8] & (1 << (i & 0x7)). First 10 frame - types are standard frame types and not used in this bitfield. If - bit is set, it indicates that incoming frame with that type is - passed to user defined callbacks, otherwise they are ignored. */ - uint8_t user_recv_ext_types[32]; -}; - -/* Struct used when updating initial window size of each active - stream. */ -typedef struct { - nghttp2_session *session; - int32_t new_window_size, old_window_size; -} nghttp2_update_window_size_arg; - -typedef struct { - nghttp2_session *session; - /* linked list of streams to close */ - nghttp2_stream *head; - int32_t last_stream_id; - /* nonzero if GOAWAY is sent to peer, which means we are going to - close incoming streams. zero if GOAWAY is received from peer and - we are going to close outgoing streams. */ - int incoming; -} nghttp2_close_stream_on_goaway_arg; - -/* TODO stream timeout etc */ - -/* - * Returns nonzero value if |stream_id| is initiated by local - * endpoint. - */ -int nghttp2_session_is_my_stream_id(nghttp2_session *session, - int32_t stream_id); - -/* - * Adds |item| to the outbound queue in |session|. When this function - * succeeds, it takes ownership of |item|. So caller must not free it - * on success. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP2_ERR_NOMEM - * Out of memory. - * NGHTTP2_ERR_STREAM_CLOSED - * Stream already closed (DATA and PUSH_PROMISE frame only) - */ -int nghttp2_session_add_item(nghttp2_session *session, - nghttp2_outbound_item *item); - -/* - * Adds RST_STREAM frame for the stream |stream_id| with the error - * code |error_code|. This is a convenient function built on top of - * nghttp2_session_add_frame() to add RST_STREAM easily. - * - * This function simply returns 0 without adding RST_STREAM frame if - * given stream is in NGHTTP2_STREAM_CLOSING state, because multiple - * RST_STREAM for a stream is redundant. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP2_ERR_NOMEM - * Out of memory. - */ -int nghttp2_session_add_rst_stream(nghttp2_session *session, int32_t stream_id, - uint32_t error_code); - -/* - * Adds PING frame. This is a convenient functin built on top of - * nghttp2_session_add_frame() to add PING easily. - * - * If the |opaque_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. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP2_ERR_NOMEM - * Out of memory. - * NGHTTP2_ERR_FLOODED - * There are too many items in outbound queue; this only happens - * if NGHTTP2_FLAG_ACK is set in |flags| - */ -int nghttp2_session_add_ping(nghttp2_session *session, uint8_t flags, - const uint8_t *opaque_data); - -/* - * Adds GOAWAY frame with the last-stream-ID |last_stream_id| and the - * error code |error_code|. This is a convenient function built on top - * of nghttp2_session_add_frame() to add GOAWAY easily. The - * |aux_flags| are bitwise-OR of one or more of - * nghttp2_goaway_aux_flag. - * - * 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 - * The |opaque_data_len| is too large. - */ -int nghttp2_session_add_goaway(nghttp2_session *session, int32_t last_stream_id, - uint32_t error_code, const uint8_t *opaque_data, - size_t opaque_data_len, uint8_t aux_flags); - -/* - * Adds WINDOW_UPDATE frame with stream ID |stream_id| and - * window-size-increment |window_size_increment|. This is a convenient - * function built on top of nghttp2_session_add_frame() to add - * WINDOW_UPDATE easily. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP2_ERR_NOMEM - * Out of memory. - */ -int nghttp2_session_add_window_update(nghttp2_session *session, uint8_t flags, - int32_t stream_id, - int32_t window_size_increment); - -/* - * Adds SETTINGS frame. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP2_ERR_NOMEM - * Out of memory. - * NGHTTP2_ERR_FLOODED - * There are too many items in outbound queue; this only happens - * if NGHTTP2_FLAG_ACK is set in |flags| - */ -int nghttp2_session_add_settings(nghttp2_session *session, uint8_t flags, - const nghttp2_settings_entry *iv, size_t niv); - -/* - * Creates new stream in |session| with stream ID |stream_id|, - * priority |pri_spec| and flags |flags|. The |flags| is bitwise OR - * of nghttp2_stream_flag. Since this function is called when initial - * HEADERS is sent or received, these flags are taken from it. The - * state of stream is set to |initial_state|. The |stream_user_data| - * is a pointer to the arbitrary user supplied data to be associated - * to this stream. - * - * If |initial_state| is NGHTTP2_STREAM_RESERVED, this function sets - * NGHTTP2_STREAM_FLAG_PUSH flag set. - * - * This function returns a pointer to created new stream object, or - * NULL. - * - * This function adjusts neither the number of closed streams or idle - * streams. The caller should manually call - * nghttp2_session_adjust_closed_stream() or - * nghttp2_session_adjust_idle_stream() respectively. - */ -nghttp2_stream *nghttp2_session_open_stream(nghttp2_session *session, - int32_t stream_id, uint8_t flags, - nghttp2_priority_spec *pri_spec, - nghttp2_stream_state initial_state, - void *stream_user_data); - -/* - * Closes stream whose stream ID is |stream_id|. The reason of closure - * is indicated by the |error_code|. When closing the stream, - * on_stream_close_callback will be called. - * - * If the session is initialized as server and |stream| is incoming - * stream, stream is just marked closed and this function calls - * nghttp2_session_keep_closed_stream() with |stream|. Otherwise, - * |stream| will be deleted from memory. - * - * This function returns 0 if it succeeds, or one the following - * negative error codes: - * - * NGHTTP2_ERR_NOMEM - * Out of memory - * NGHTTP2_ERR_INVALID_ARGUMENT - * The specified stream does not exist. - * NGHTTP2_ERR_CALLBACK_FAILURE - * The callback function failed. - */ -int nghttp2_session_close_stream(nghttp2_session *session, int32_t stream_id, - uint32_t error_code); - -/* - * Deletes |stream| from memory. After this function returns, stream - * cannot be accessed. - * - * This function returns 0 if it succeeds, or one the following - * negative error codes: - * - * NGHTTP2_ERR_NOMEM - * Out of memory - */ -int nghttp2_session_destroy_stream(nghttp2_session *session, - nghttp2_stream *stream); - -/* - * Tries to keep incoming closed stream |stream|. Due to the - * limitation of maximum number of streams in memory, |stream| is not - * closed and just deleted from memory (see - * nghttp2_session_destroy_stream). - */ -void nghttp2_session_keep_closed_stream(nghttp2_session *session, - nghttp2_stream *stream); - -/* - * Appends |stream| to linked list |session->idle_stream_head|. We - * apply fixed limit for list size. To fit into that limit, one or - * more oldest streams are removed from list as necessary. - */ -void nghttp2_session_keep_idle_stream(nghttp2_session *session, - nghttp2_stream *stream); - -/* - * Detaches |stream| from idle streams linked list. - */ -void nghttp2_session_detach_idle_stream(nghttp2_session *session, - nghttp2_stream *stream); - -/* - * Deletes closed stream to ensure that number of incoming streams - * including active and closed is in the maximum number of allowed - * stream. - * - * This function returns 0 if it succeeds, or one the following - * negative error codes: - * - * NGHTTP2_ERR_NOMEM - * Out of memory - */ -int nghttp2_session_adjust_closed_stream(nghttp2_session *session); - -/* - * Deletes idle stream to ensure that number of idle streams is in - * certain limit. - * - * This function returns 0 if it succeeds, or one the following - * negative error codes: - * - * NGHTTP2_ERR_NOMEM - * Out of memory - */ -int nghttp2_session_adjust_idle_stream(nghttp2_session *session); - -/* - * If further receptions and transmissions over the stream |stream_id| - * are disallowed, close the stream with error code NGHTTP2_NO_ERROR. - * - * This function returns 0 if it - * succeeds, or one of the following negative error codes: - * - * NGHTTP2_ERR_INVALID_ARGUMENT - * The specified stream does not exist. - */ -int nghttp2_session_close_stream_if_shut_rdwr(nghttp2_session *session, - nghttp2_stream *stream); - -int nghttp2_session_on_request_headers_received(nghttp2_session *session, - nghttp2_frame *frame); - -int nghttp2_session_on_response_headers_received(nghttp2_session *session, - nghttp2_frame *frame, - nghttp2_stream *stream); - -int nghttp2_session_on_push_response_headers_received(nghttp2_session *session, - nghttp2_frame *frame, - nghttp2_stream *stream); - -/* - * Called when HEADERS is received, assuming |frame| is properly - * initialized. This function does first validate received frame and - * then open stream and call callback functions. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP2_ERR_NOMEM - * Out of memory. - * NGHTTP2_ERR_IGN_HEADER_BLOCK - * Frame was rejected and header block must be decoded but - * result must be ignored. - * NGHTTP2_ERR_CALLBACK_FAILURE - * The read_callback failed - */ -int nghttp2_session_on_headers_received(nghttp2_session *session, - nghttp2_frame *frame, - nghttp2_stream *stream); - -/* - * Called when PRIORITY is received, assuming |frame| is properly - * initialized. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP2_ERR_NOMEM - * Out of memory. - * NGHTTP2_ERR_CALLBACK_FAILURE - * The read_callback failed - */ -int nghttp2_session_on_priority_received(nghttp2_session *session, - nghttp2_frame *frame); - -/* - * Called when RST_STREAM is received, assuming |frame| is properly - * initialized. - * - * This function returns 0 if it succeeds, or one the following - * negative error codes: - * - * NGHTTP2_ERR_NOMEM - * Out of memory - * NGHTTP2_ERR_CALLBACK_FAILURE - * The read_callback failed - */ -int nghttp2_session_on_rst_stream_received(nghttp2_session *session, - nghttp2_frame *frame); - -/* - * Called when SETTINGS is received, assuming |frame| is properly - * initialized. If |noack| is non-zero, SETTINGS with ACK will not be - * submitted. If |frame| has NGHTTP2_FLAG_ACK flag set, no SETTINGS - * with ACK will not be submitted regardless of |noack|. - * - * This function returns 0 if it succeeds, or one the following - * negative error codes: - * - * NGHTTP2_ERR_NOMEM - * Out of memory - * NGHTTP2_ERR_CALLBACK_FAILURE - * The read_callback failed - * NGHTTP2_ERR_FLOODED - * There are too many items in outbound queue, and this is most - * likely caused by misbehaviour of peer. - */ -int nghttp2_session_on_settings_received(nghttp2_session *session, - nghttp2_frame *frame, int noack); - -/* - * Called when PUSH_PROMISE is received, assuming |frame| is properly - * initialized. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP2_ERR_NOMEM - * Out of memory. - * NGHTTP2_ERR_IGN_HEADER_BLOCK - * Frame was rejected and header block must be decoded but - * result must be ignored. - * NGHTTP2_ERR_CALLBACK_FAILURE - * The read_callback failed - */ -int nghttp2_session_on_push_promise_received(nghttp2_session *session, - nghttp2_frame *frame); - -/* - * Called when PING is received, assuming |frame| is properly - * initialized. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP2_ERR_NOMEM - * Out of memory. - * NGHTTP2_ERR_CALLBACK_FAILURE - * The callback function failed. - * NGHTTP2_ERR_FLOODED - * There are too many items in outbound queue, and this is most - * likely caused by misbehaviour of peer. - */ -int nghttp2_session_on_ping_received(nghttp2_session *session, - nghttp2_frame *frame); - -/* - * Called when GOAWAY is received, assuming |frame| is properly - * initialized. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP2_ERR_NOMEM - * Out of memory. - * NGHTTP2_ERR_CALLBACK_FAILURE - * The callback function failed. - */ -int nghttp2_session_on_goaway_received(nghttp2_session *session, - nghttp2_frame *frame); - -/* - * Called when WINDOW_UPDATE is recieved, assuming |frame| is properly - * initialized. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP2_ERR_NOMEM - * Out of memory. - * NGHTTP2_ERR_CALLBACK_FAILURE - * The callback function failed. - */ -int nghttp2_session_on_window_update_received(nghttp2_session *session, - nghttp2_frame *frame); - -/* - * Called when ALTSVC is recieved, assuming |frame| is properly - * initialized. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP2_ERR_CALLBACK_FAILURE - * The callback function failed. - */ -int nghttp2_session_on_altsvc_received(nghttp2_session *session, - nghttp2_frame *frame); - -/* - * Called when DATA is received, assuming |frame| is properly - * initialized. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP2_ERR_NOMEM - * Out of memory. - * NGHTTP2_ERR_CALLBACK_FAILURE - * The callback function failed. - */ -int nghttp2_session_on_data_received(nghttp2_session *session, - nghttp2_frame *frame); - -/* - * Returns nghttp2_stream* object whose stream ID is |stream_id|. It - * could be NULL if such stream does not exist. This function returns - * NULL if stream is marked as closed. - */ -nghttp2_stream *nghttp2_session_get_stream(nghttp2_session *session, - int32_t stream_id); - -/* - * This function behaves like nghttp2_session_get_stream(), but it - * returns stream object even if it is marked as closed or in - * NGHTTP2_STREAM_IDLE state. - */ -nghttp2_stream *nghttp2_session_get_stream_raw(nghttp2_session *session, - int32_t stream_id); - -/* - * Packs DATA frame |frame| in wire frame format and stores it in - * |bufs|. Payload will be read using |aux_data->data_prd|. The - * length of payload is at most |datamax| bytes. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP2_ERR_DEFERRED - * The DATA frame is postponed. - * NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE - * The read_callback failed (stream error). - * NGHTTP2_ERR_NOMEM - * Out of memory. - * NGHTTP2_ERR_CALLBACK_FAILURE - * The read_callback failed (session error). - */ -int nghttp2_session_pack_data(nghttp2_session *session, nghttp2_bufs *bufs, - size_t datamax, nghttp2_frame *frame, - nghttp2_data_aux_data *aux_data, - nghttp2_stream *stream); - -/* - * Pops and returns next item to send. If there is no such item, - * returns NULL. This function takes into account max concurrent - * streams. That means if session->ob_syn has item and max concurrent - * streams is reached, the even if other queues contain items, then - * this function returns NULL. - */ -nghttp2_outbound_item * -nghttp2_session_pop_next_ob_item(nghttp2_session *session); - -/* - * Returns next item to send. If there is no such item, this function - * returns NULL. This function takes into account max concurrent - * streams. That means if session->ob_syn has item and max concurrent - * streams is reached, the even if other queues contain items, then - * this function returns NULL. - */ -nghttp2_outbound_item * -nghttp2_session_get_next_ob_item(nghttp2_session *session); - -/* - * Updates local settings with the |iv|. The number of elements in the - * array pointed by the |iv| is given by the |niv|. This function - * assumes that the all settings_id member in |iv| are in range 1 to - * NGHTTP2_SETTINGS_MAX, inclusive. - * - * While updating individual stream's local window size, if the window - * size becomes strictly larger than NGHTTP2_MAX_WINDOW_SIZE, - * RST_STREAM is issued against such a stream. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP2_ERR_NOMEM - * Out of memory - */ -int nghttp2_session_update_local_settings(nghttp2_session *session, - nghttp2_settings_entry *iv, - size_t niv); - -/* - * Re-prioritize |stream|. The new priority specification is - * |pri_spec|. Caller must ensure that stream->hd.stream_id != - * pri_spec->stream_id. - * - * This function does not adjust the number of idle streams. The - * caller should call nghttp2_session_adjust_idle_stream() later. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP2_ERR_NOMEM - * Out of memory - */ -int nghttp2_session_reprioritize_stream(nghttp2_session *session, - nghttp2_stream *stream, - const nghttp2_priority_spec *pri_spec); - -/* - * Terminates current |session| with the |error_code|. The |reason| - * is NULL-terminated debug string. - * - * 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 - * The |reason| is too long. - */ -int nghttp2_session_terminate_session_with_reason(nghttp2_session *session, - uint32_t error_code, - const char *reason); - -#endif /* NGHTTP2_SESSION_H */ diff --git a/tools/sdk/include/nghttp/nghttp2_stream.h b/tools/sdk/include/nghttp/nghttp2_stream.h deleted file mode 100644 index da0e5d53..00000000 --- a/tools/sdk/include/nghttp/nghttp2_stream.h +++ /dev/null @@ -1,436 +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_STREAM_H -#define NGHTTP2_STREAM_H - -#ifdef HAVE_CONFIG_H -#include -#endif /* HAVE_CONFIG_H */ - -#include -#include "nghttp2_outbound_item.h" -#include "nghttp2_map.h" -#include "nghttp2_pq.h" -#include "nghttp2_int.h" - -/* - * If local peer is stream initiator: - * NGHTTP2_STREAM_OPENING : upon sending request HEADERS - * NGHTTP2_STREAM_OPENED : upon receiving response HEADERS - * NGHTTP2_STREAM_CLOSING : upon queuing RST_STREAM - * - * If remote peer is stream initiator: - * NGHTTP2_STREAM_OPENING : upon receiving request HEADERS - * NGHTTP2_STREAM_OPENED : upon sending response HEADERS - * NGHTTP2_STREAM_CLOSING : upon queuing RST_STREAM - */ -typedef enum { - /* Initial state */ - NGHTTP2_STREAM_INITIAL, - /* For stream initiator: request HEADERS has been sent, but response - HEADERS has not been received yet. For receiver: request HEADERS - has been received, but it does not send response HEADERS yet. */ - NGHTTP2_STREAM_OPENING, - /* For stream initiator: response HEADERS is received. For receiver: - response HEADERS is sent. */ - NGHTTP2_STREAM_OPENED, - /* RST_STREAM is received, but somehow we need to keep stream in - memory. */ - NGHTTP2_STREAM_CLOSING, - /* PUSH_PROMISE is received or sent */ - NGHTTP2_STREAM_RESERVED, - /* Stream is created in this state if it is used as anchor in - dependency tree. */ - NGHTTP2_STREAM_IDLE -} nghttp2_stream_state; - -typedef enum { - NGHTTP2_SHUT_NONE = 0, - /* Indicates further receptions will be disallowed. */ - NGHTTP2_SHUT_RD = 0x01, - /* Indicates further transmissions will be disallowed. */ - NGHTTP2_SHUT_WR = 0x02, - /* Indicates both further receptions and transmissions will be - disallowed. */ - NGHTTP2_SHUT_RDWR = NGHTTP2_SHUT_RD | NGHTTP2_SHUT_WR -} nghttp2_shut_flag; - -typedef enum { - NGHTTP2_STREAM_FLAG_NONE = 0, - /* Indicates that this stream is pushed stream and not opened - yet. */ - NGHTTP2_STREAM_FLAG_PUSH = 0x01, - /* Indicates that this stream was closed */ - NGHTTP2_STREAM_FLAG_CLOSED = 0x02, - /* Indicates the item is deferred due to flow control. */ - NGHTTP2_STREAM_FLAG_DEFERRED_FLOW_CONTROL = 0x04, - /* Indicates the item is deferred by user callback */ - NGHTTP2_STREAM_FLAG_DEFERRED_USER = 0x08, - /* bitwise OR of NGHTTP2_STREAM_FLAG_DEFERRED_FLOW_CONTROL and - NGHTTP2_STREAM_FLAG_DEFERRED_USER. */ - NGHTTP2_STREAM_FLAG_DEFERRED_ALL = 0x0c - -} nghttp2_stream_flag; - -/* HTTP related flags to enforce HTTP semantics */ -typedef enum { - NGHTTP2_HTTP_FLAG_NONE = 0, - /* header field seen so far */ - NGHTTP2_HTTP_FLAG__AUTHORITY = 1, - NGHTTP2_HTTP_FLAG__PATH = 1 << 1, - NGHTTP2_HTTP_FLAG__METHOD = 1 << 2, - NGHTTP2_HTTP_FLAG__SCHEME = 1 << 3, - /* host is not pseudo header, but we require either host or - :authority */ - NGHTTP2_HTTP_FLAG_HOST = 1 << 4, - NGHTTP2_HTTP_FLAG__STATUS = 1 << 5, - /* required header fields for HTTP request except for CONNECT - method. */ - NGHTTP2_HTTP_FLAG_REQ_HEADERS = NGHTTP2_HTTP_FLAG__METHOD | - NGHTTP2_HTTP_FLAG__PATH | - NGHTTP2_HTTP_FLAG__SCHEME, - NGHTTP2_HTTP_FLAG_PSEUDO_HEADER_DISALLOWED = 1 << 6, - /* HTTP method flags */ - NGHTTP2_HTTP_FLAG_METH_CONNECT = 1 << 7, - NGHTTP2_HTTP_FLAG_METH_HEAD = 1 << 8, - NGHTTP2_HTTP_FLAG_METH_OPTIONS = 1 << 9, - NGHTTP2_HTTP_FLAG_METH_UPGRADE_WORKAROUND = 1 << 10, - NGHTTP2_HTTP_FLAG_METH_ALL = NGHTTP2_HTTP_FLAG_METH_CONNECT | - NGHTTP2_HTTP_FLAG_METH_HEAD | - NGHTTP2_HTTP_FLAG_METH_OPTIONS | - NGHTTP2_HTTP_FLAG_METH_UPGRADE_WORKAROUND, - /* :path category */ - /* path starts with "/" */ - NGHTTP2_HTTP_FLAG_PATH_REGULAR = 1 << 11, - /* path "*" */ - NGHTTP2_HTTP_FLAG_PATH_ASTERISK = 1 << 12, - /* scheme */ - /* "http" or "https" scheme */ - NGHTTP2_HTTP_FLAG_SCHEME_HTTP = 1 << 13, - /* set if final response is expected */ - NGHTTP2_HTTP_FLAG_EXPECT_FINAL_RESPONSE = 1 << 14 -} nghttp2_http_flag; - -struct nghttp2_stream { - /* Intrusive Map */ - nghttp2_map_entry map_entry; - /* Entry for dep_prev->obq */ - nghttp2_pq_entry pq_entry; - /* Priority Queue storing direct descendant (nghttp2_stream). Only - streams which itself has some data to send, or has a descendant - which has some data to sent. */ - nghttp2_pq obq; - /* Content-Length of request/response body. -1 if unknown. */ - int64_t content_length; - /* Received body so far */ - int64_t recv_content_length; - /* Base last_cycle for direct descendent streams. */ - uint32_t descendant_last_cycle; - /* Next scheduled time to sent item */ - uint32_t cycle; - /* Next seq used for direct descendant streams */ - uint64_t descendant_next_seq; - /* Secondary key for prioritization to break a tie for cycle. This - value is monotonically increased for single parent stream. */ - uint64_t seq; - /* pointers to form dependency tree. If multiple streams depend on - a stream, only one stream (left most) has non-NULL dep_prev which - points to the stream it depends on. The remaining streams are - linked using sib_prev and sib_next. The stream which has - non-NULL dep_prev always NULL sib_prev. The right most stream - has NULL sib_next. If this stream is a root of dependency tree, - dep_prev and sib_prev are NULL. */ - nghttp2_stream *dep_prev, *dep_next; - nghttp2_stream *sib_prev, *sib_next; - /* When stream is kept after closure, it may be kept in doubly - linked list pointed by nghttp2_session closed_stream_head. - closed_next points to the next stream object if it is the element - of the list. */ - nghttp2_stream *closed_prev, *closed_next; - /* The arbitrary data provided by user for this stream. */ - void *stream_user_data; - /* Item to send */ - nghttp2_outbound_item *item; - /* Last written length of frame payload */ - size_t last_writelen; - /* stream ID */ - int32_t stream_id; - /* Current remote window size. This value is computed against the - current initial window size of remote endpoint. */ - int32_t remote_window_size; - /* Keep track of the number of bytes received without - WINDOW_UPDATE. This could be negative after submitting negative - value to WINDOW_UPDATE */ - int32_t recv_window_size; - /* The number of bytes consumed by the application and now is - subject to WINDOW_UPDATE. This is only used when auto - WINDOW_UPDATE is turned off. */ - int32_t consumed_size; - /* The amount of recv_window_size cut using submitting negative - value to WINDOW_UPDATE */ - int32_t recv_reduction; - /* window size for local flow control. It is initially set to - NGHTTP2_INITIAL_WINDOW_SIZE and could be increased/decreased by - submitting WINDOW_UPDATE. See nghttp2_submit_window_update(). */ - int32_t local_window_size; - /* weight of this stream */ - int32_t weight; - /* This is unpaid penalty (offset) when calculating cycle. */ - uint32_t pending_penalty; - /* sum of weight of direct descendants */ - int32_t sum_dep_weight; - nghttp2_stream_state state; - /* status code from remote server */ - int16_t status_code; - /* Bitwise OR of zero or more nghttp2_http_flag values */ - uint16_t http_flags; - /* This is bitwise-OR of 0 or more of nghttp2_stream_flag. */ - uint8_t flags; - /* Bitwise OR of zero or more nghttp2_shut_flag values */ - uint8_t shut_flags; - /* Nonzero if this stream has been queued to stream pointed by - dep_prev. We maintain the invariant that if a stream is queued, - then its ancestors, except for root, are also queued. This - invariant may break in fatal error condition. */ - uint8_t queued; - /* This flag is used to reduce excessive queuing of WINDOW_UPDATE to - this stream. The nonzero does not necessarily mean WINDOW_UPDATE - is not queued. */ - uint8_t window_update_queued; -}; - -void nghttp2_stream_init(nghttp2_stream *stream, int32_t stream_id, - uint8_t flags, nghttp2_stream_state initial_state, - int32_t weight, int32_t remote_initial_window_size, - int32_t local_initial_window_size, - void *stream_user_data, nghttp2_mem *mem); - -void nghttp2_stream_free(nghttp2_stream *stream); - -/* - * Disallow either further receptions or transmissions, or both. - * |flag| is bitwise OR of one or more of nghttp2_shut_flag. - */ -void nghttp2_stream_shutdown(nghttp2_stream *stream, nghttp2_shut_flag flag); - -/* - * Defer |stream->item|. We won't call this function in the situation - * where |stream->item| == NULL. The |flags| is bitwise OR of zero or - * more of NGHTTP2_STREAM_FLAG_DEFERRED_USER and - * NGHTTP2_STREAM_FLAG_DEFERRED_FLOW_CONTROL. The |flags| indicates - * the reason of this action. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP2_ERR_NOMEM - * Out of memory - */ -int nghttp2_stream_defer_item(nghttp2_stream *stream, uint8_t flags); - -/* - * Put back deferred data in this stream to active state. The |flags| - * are one or more of bitwise OR of the following values: - * NGHTTP2_STREAM_FLAG_DEFERRED_USER and - * NGHTTP2_STREAM_FLAG_DEFERRED_FLOW_CONTROL and given masks are - * cleared if they are set. So even if this function is called, if - * one of flag is still set, data does not become active. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP2_ERR_NOMEM - * Out of memory - */ -int nghttp2_stream_resume_deferred_item(nghttp2_stream *stream, uint8_t flags); - -/* - * Returns nonzero if item is deferred by whatever reason. - */ -int nghttp2_stream_check_deferred_item(nghttp2_stream *stream); - -/* - * Returns nonzero if item is deferred by flow control. - */ -int nghttp2_stream_check_deferred_by_flow_control(nghttp2_stream *stream); - -/* - * Updates the remote window size with the new value - * |new_initial_window_size|. The |old_initial_window_size| is used to - * calculate the current window size. - * - * This function returns 0 if it succeeds or -1. The failure is due to - * overflow. - */ -int nghttp2_stream_update_remote_initial_window_size( - nghttp2_stream *stream, int32_t new_initial_window_size, - int32_t old_initial_window_size); - -/* - * Updates the local window size with the new value - * |new_initial_window_size|. The |old_initial_window_size| is used to - * calculate the current window size. - * - * This function returns 0 if it succeeds or -1. The failure is due to - * overflow. - */ -int nghttp2_stream_update_local_initial_window_size( - nghttp2_stream *stream, int32_t new_initial_window_size, - int32_t old_initial_window_size); - -/* - * Call this function if promised stream |stream| is replied with - * HEADERS. This function makes the state of the |stream| to - * NGHTTP2_STREAM_OPENED. - */ -void nghttp2_stream_promise_fulfilled(nghttp2_stream *stream); - -/* - * Returns nonzero if |target| is an ancestor of |stream|. - */ -int nghttp2_stream_dep_find_ancestor(nghttp2_stream *stream, - nghttp2_stream *target); - -/* - * Computes distributed weight of a stream of the |weight| under the - * |stream| if |stream| is removed from a dependency tree. - */ -int32_t nghttp2_stream_dep_distributed_weight(nghttp2_stream *stream, - int32_t weight); - -/* - * Makes the |stream| depend on the |dep_stream|. This dependency is - * exclusive. All existing direct descendants of |dep_stream| become - * the descendants of the |stream|. This function assumes - * |stream->item| is NULL. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP2_ERR_NOMEM - * Out of memory - */ -int nghttp2_stream_dep_insert(nghttp2_stream *dep_stream, - nghttp2_stream *stream); - -/* - * Makes the |stream| depend on the |dep_stream|. This dependency is - * not exclusive. This function assumes |stream->item| is NULL. - */ -void nghttp2_stream_dep_add(nghttp2_stream *dep_stream, nghttp2_stream *stream); - -/* - * Removes the |stream| from the current dependency tree. This - * function assumes |stream->item| is NULL. - */ -int nghttp2_stream_dep_remove(nghttp2_stream *stream); - -/* - * Attaches |item| to |stream|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP2_ERR_NOMEM - * Out of memory - */ -int nghttp2_stream_attach_item(nghttp2_stream *stream, - nghttp2_outbound_item *item); - -/* - * Detaches |stream->item|. This function does not free - * |stream->item|. The caller must free it. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP2_ERR_NOMEM - * Out of memory - */ -int nghttp2_stream_detach_item(nghttp2_stream *stream); - -/* - * Makes the |stream| depend on the |dep_stream|. This dependency is - * exclusive. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP2_ERR_NOMEM - * Out of memory - */ -int nghttp2_stream_dep_insert_subtree(nghttp2_stream *dep_stream, - nghttp2_stream *stream); - -/* - * Makes the |stream| depend on the |dep_stream|. This dependency is - * not exclusive. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP2_ERR_NOMEM - * Out of memory - */ -int nghttp2_stream_dep_add_subtree(nghttp2_stream *dep_stream, - nghttp2_stream *stream); - -/* - * Removes subtree whose root stream is |stream|. The - * effective_weight of streams in removed subtree is not updated. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP2_ERR_NOMEM - * Out of memory - */ -void nghttp2_stream_dep_remove_subtree(nghttp2_stream *stream); - -/* - * Returns nonzero if |stream| is in any dependency tree. - */ -int nghttp2_stream_in_dep_tree(nghttp2_stream *stream); - -/* - * Schedules transmission of |stream|'s item, assuming stream->item is - * attached, and stream->last_writelen was updated. - */ -void nghttp2_stream_reschedule(nghttp2_stream *stream); - -/* - * Changes |stream|'s weight to |weight|. If |stream| is queued, it - * will be rescheduled based on new weight. - */ -void nghttp2_stream_change_weight(nghttp2_stream *stream, int32_t weight); - -/* - * Returns a stream which has highest priority, updating - * descendant_last_cycle of selected stream's ancestors. - */ -nghttp2_outbound_item * -nghttp2_stream_next_outbound_item(nghttp2_stream *stream); - -#endif /* NGHTTP2_STREAM */ diff --git a/tools/sdk/include/nghttp/nghttp2_submit.h b/tools/sdk/include/nghttp/nghttp2_submit.h deleted file mode 100644 index 545388cf..00000000 --- a/tools/sdk/include/nghttp/nghttp2_submit.h +++ /dev/null @@ -1,34 +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_SUBMIT_H -#define NGHTTP2_SUBMIT_H - -#ifdef HAVE_CONFIG_H -#include -#endif /* HAVE_CONFIG_H */ - -#include - -#endif /* NGHTTP2_SUBMIT_H */ diff --git a/tools/sdk/include/nvs_flash/nvs.h b/tools/sdk/include/nvs_flash/nvs.h index 6e5af231..5b469f76 100644 --- a/tools/sdk/include/nvs_flash/nvs.h +++ b/tools/sdk/include/nvs_flash/nvs.h @@ -42,6 +42,7 @@ typedef uint32_t nvs_handle; #define ESP_ERR_NVS_INVALID_STATE (ESP_ERR_NVS_BASE + 0x0b) /*!< NVS is in an inconsistent state due to a previous error. Call nvs_flash_init and nvs_open again, then retry. */ #define ESP_ERR_NVS_INVALID_LENGTH (ESP_ERR_NVS_BASE + 0x0c) /*!< String or blob length is not sufficient to store data */ #define ESP_ERR_NVS_NO_FREE_PAGES (ESP_ERR_NVS_BASE + 0x0d) /*!< NVS partition doesn't contain any empty pages. This may happen if NVS partition was truncated. Erase the whole partition and call nvs_flash_init again. */ +#define ESP_ERR_NVS_VALUE_TOO_LONG (ESP_ERR_NVS_BASE + 0x0e) /*!< String or blob length is longer than supported by the implementation */ /** * @brief Mode of opening the non-volatile storage @@ -61,7 +62,7 @@ typedef enum { * * @param[in] name Namespace name. Maximal length is determined by the * underlying implementation, but is guaranteed to be - * at least 16 characters. Shouldn't be empty. + * at least 15 characters. Shouldn't be empty. * @param[in] open_mode NVS_READWRITE or NVS_READONLY. If NVS_READONLY, will * open a handle for reading only. All write requests will * be rejected for this handle. @@ -89,8 +90,10 @@ esp_err_t nvs_open(const char* name, nvs_open_mode open_mode, nvs_handle *out_ha * Handles that were opened read only cannot be used. * @param[in] key Key name. Maximal length is determined by the underlying * implementation, but is guaranteed to be at least - * 16 characters. Shouldn't be empty. + * 15 characters. Shouldn't be empty. * @param[in] value The value to set. + * For strings, the maximum length (including null character) is + * 1984 bytes. * * @return * - ESP_OK if value was set successfully @@ -103,6 +106,7 @@ esp_err_t nvs_open(const char* name, nvs_open_mode open_mode, nvs_handle *out_ha * write operation has failed. The value was written however, and * update will be finished after re-initialization of nvs, provided that * flash operation doesn't fail again. + * - ESP_ERR_NVS_VALUE_TOO_LONG if the string value is too long */ esp_err_t nvs_set_i8 (nvs_handle handle, const char* key, int8_t value); esp_err_t nvs_set_u8 (nvs_handle handle, const char* key, uint8_t value); @@ -123,11 +127,10 @@ esp_err_t nvs_set_str (nvs_handle handle, const char* key, const char* value); * * @param[in] handle Handle obtained from nvs_open function. * Handles that were opened read only cannot be used. - * @param[in] key Key name. Maximal length is determined by the underlying - * implementation, but is guaranteed to be at least - * 16 characters. Shouldn't be empty. + * @param[in] key Key name. Maximal length is 15 characters. Shouldn't be empty. * @param[in] value The value to set. - * @param[in] length length of binary value to set, in bytes. + * @param[in] length length of binary value to set, in bytes; Maximum length is + * 1984 bytes. * * @return * - ESP_OK if value was set successfully @@ -140,6 +143,7 @@ esp_err_t nvs_set_str (nvs_handle handle, const char* key, const char* value); * write operation has failed. The value was written however, and * update will be finished after re-initialization of nvs, provided that * flash operation doesn't fail again. + * - ESP_ERR_NVS_VALUE_TOO_LONG if the value is too long */ esp_err_t nvs_set_blob(nvs_handle handle, const char* key, const void* value, size_t length); @@ -169,7 +173,7 @@ esp_err_t nvs_set_blob(nvs_handle handle, const char* key, const void* value, si * @param[in] handle Handle obtained from nvs_open function. * @param[in] key Key name. Maximal length is determined by the underlying * implementation, but is guaranteed to be at least - * 16 characters. Shouldn't be empty. + * 15 characters. Shouldn't be empty. * @param out_value Pointer to the output value. * May be NULL for nvs_get_str and nvs_get_blob, in this * case required length will be returned in length argument. @@ -230,7 +234,7 @@ esp_err_t nvs_get_u64 (nvs_handle handle, const char* key, uint64_t* out_value); * @param[in] handle Handle obtained from nvs_open function. * @param[in] key Key name. Maximal length is determined by the underlying * implementation, but is guaranteed to be at least - * 16 characters. Shouldn't be empty. + * 15 characters. Shouldn't be empty. * @param out_value Pointer to the output value. * May be NULL for nvs_get_str and nvs_get_blob, in this * case required length will be returned in length argument. @@ -262,7 +266,7 @@ esp_err_t nvs_get_blob(nvs_handle handle, const char* key, void* out_value, size * * @param[in] key Key name. Maximal length is determined by the underlying * implementation, but is guaranteed to be at least - * 16 characters. Shouldn't be empty. + * 15 characters. Shouldn't be empty. * * @return * - ESP_OK if erase operation was successful diff --git a/tools/sdk/include/nvs_flash/nvs_flash.h b/tools/sdk/include/nvs_flash/nvs_flash.h index 8307fe35..9220f0d3 100644 --- a/tools/sdk/include/nvs_flash/nvs_flash.h +++ b/tools/sdk/include/nvs_flash/nvs_flash.h @@ -18,6 +18,8 @@ extern "C" { #endif +#include "nvs.h" + /** * @brief Initialize NVS flash storage with layout given in the partition table. * @@ -30,6 +32,17 @@ extern "C" { esp_err_t nvs_flash_init(void); +/** + * @brief Erase NVS partition + * + * This function erases all contents of NVS partition + * + * @return + * - ESP_OK on success + * - ESP_ERR_NOT_FOUND if there is no NVS partition in the partition table + */ +esp_err_t nvs_flash_erase(void); + #ifdef __cplusplus } #endif diff --git a/tools/sdk/include/soc/soc/dport_access.h b/tools/sdk/include/soc/soc/dport_access.h index 3371b71e..d1d264cb 100644 --- a/tools/sdk/include/soc/soc/dport_access.h +++ b/tools/sdk/include/soc/soc/dport_access.h @@ -17,25 +17,20 @@ #include #include "esp_attr.h" +#include "esp_dport_access.h" -void esp_dport_access_stall_other_cpu_start(void); -void esp_dport_access_stall_other_cpu_end(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() +#ifdef __cplusplus +extern "C" { #endif //Registers Operation {{ -//Origin access operation for the base and some special scene + +//Register read macros with an underscore prefix access DPORT memory directly. In IDF apps, use the non-underscore versions to be SMP-safe. #define _DPORT_REG_READ(_r) (*(volatile uint32_t *)(_r)) #define _DPORT_REG_WRITE(_r, _v) (*(volatile uint32_t *)(_r)) = (_v) //write value to register -#define DPORT_REG_WRITE(_r, _v) _DPORT_REG_WRITE(_r, _v) +#define DPORT_REG_WRITE(_r, _v) _DPORT_REG_WRITE((_r), (_v)) //read value from register static inline uint32_t IRAM_ATTR DPORT_REG_READ(uint32_t reg) @@ -65,7 +60,7 @@ static inline uint32_t IRAM_ATTR DPORT_REG_READ(uint32_t reg) #define DPORT_REG_GET_FIELD(_r, _f) ((DPORT_REG_READ(_r) >> (_f##_S)) & (_f##_V)) //set field to register, used when _f is not left shifted by _f##_S -#define DPORT_REG_SET_FIELD(_r, _f, _v) DPORT_REG_WRITE((_r), ((DPORT_REG_READ(_r) & (~((_f) << (_f##_S))))|(((_v) & (_f))<<(_f##_S)))) +#define DPORT_REG_SET_FIELD(_r, _f, _v) DPORT_REG_WRITE((_r), ((DPORT_REG_READ(_r) & (~((_f##_V) << (_f##_S))))|(((_v) & (_f##_V))<<(_f##_S)))) //get field value from a variable, used when _f is not left shifted by _f##_S #define DPORT_VALUE_GET_FIELD(_r, _f) (((_r) >> (_f##_S)) & (_f)) @@ -85,8 +80,9 @@ static inline uint32_t IRAM_ATTR DPORT_REG_READ(uint32_t reg) //generate a value from a field value, used when _f is left shifted by _f##_S #define DPORT_FIELD_TO_VALUE2(_f, _v) (((_v)<<_f##_S) & (_f)) -#define _READ_PERI_REG(addr) (*((volatile uint32_t *)(addr))) -#define _WRITE_PERI_REG(addr, val) (*((volatile uint32_t *)(addr))) = (uint32_t)(val) +//Register read macros with an underscore prefix access DPORT memory directly. In IDF apps, use the non-underscore versions to be SMP-safe. +#define _DPORT_READ_PERI_REG(addr) (*((volatile uint32_t *)(addr))) +#define _DPORT_WRITE_PERI_REG(addr, val) (*((volatile uint32_t *)(addr))) = (uint32_t)(val) //read value from register static inline uint32_t IRAM_ATTR DPORT_READ_PERI_REG(uint32_t addr) @@ -94,14 +90,14 @@ static inline uint32_t IRAM_ATTR DPORT_READ_PERI_REG(uint32_t addr) uint32_t val; DPORT_STALL_OTHER_CPU_START(); - val = _READ_PERI_REG(addr); + val = _DPORT_READ_PERI_REG(addr); DPORT_STALL_OTHER_CPU_END(); return val; } //write value to register -#define DPORT_WRITE_PERI_REG(addr, val) _WRITE_PERI_REG(addr, val) +#define DPORT_WRITE_PERI_REG(addr, val) _DPORT_WRITE_PERI_REG((addr), (val)) //clear bits of register controlled by mask #define DPORT_CLEAR_PERI_REG_MASK(reg, mask) DPORT_WRITE_PERI_REG((reg), (DPORT_READ_PERI_REG(reg)&(~(mask)))) @@ -116,11 +112,14 @@ static inline uint32_t IRAM_ATTR DPORT_READ_PERI_REG(uint32_t addr) #define DPORT_GET_PERI_REG_BITS(reg, hipos,lowpos) ((DPORT_READ_PERI_REG(reg)>>(lowpos))&((1<<((hipos)-(lowpos)+1))-1)) //set bits of register controlled by mask and shift -#define DPORT_SET_PERI_REG_BITS(reg,bit_map,value,shift) DPORT_WRITE_PERI_REG((reg),(DPORT_READ_PERI_REG(reg)&(~((bit_map)<<(shift))))|(((value) & bit_map)<<(shift))) +#define DPORT_SET_PERI_REG_BITS(reg,bit_map,value,shift) DPORT_WRITE_PERI_REG((reg), ((DPORT_READ_PERI_REG(reg)&(~((bit_map)<<(shift))))|(((value) & bit_map)<<(shift)))) //get field of register #define DPORT_GET_PERI_REG_BITS2(reg, mask,shift) ((DPORT_READ_PERI_REG(reg)>>(shift))&(mask)) //}} +#ifdef __cplusplus +} +#endif #endif /* _DPORT_ACCESS_H_ */ diff --git a/tools/sdk/include/soc/soc/dport_reg.h b/tools/sdk/include/soc/soc/dport_reg.h index 4e17363b..56e18246 100644 --- a/tools/sdk/include/soc/soc/dport_reg.h +++ b/tools/sdk/include/soc/soc/dport_reg.h @@ -958,7 +958,7 @@ #define DPORT_CAN_CLK_EN (BIT(19)) #define DPORT_I2C_EXT1_CLK_EN (BIT(18)) #define DPORT_PWM0_CLK_EN (BIT(17)) -#define DPORT_SPI_CLK_EN (BIT(16)) +#define DPORT_SPI_CLK_EN_2 (BIT(16)) #define DPORT_TIMERGROUP1_CLK_EN (BIT(15)) #define DPORT_EFUSE_CLK_EN (BIT(14)) #define DPORT_TIMERGROUP_CLK_EN (BIT(13)) @@ -968,7 +968,7 @@ #define DPORT_RMT_CLK_EN (BIT(9)) #define DPORT_UHCI0_CLK_EN (BIT(8)) #define DPORT_I2C_EXT0_CLK_EN (BIT(7)) -#define DPORT_SPI_CLK_EN_2 (BIT(6)) +#define DPORT_SPI_CLK_EN (BIT(6)) #define DPORT_UART1_CLK_EN (BIT(5)) #define DPORT_I2S0_CLK_EN (BIT(4)) #define DPORT_WDG_CLK_EN (BIT(3)) @@ -992,7 +992,7 @@ #define DPORT_CAN_RST (BIT(19)) #define DPORT_I2C_EXT1_RST (BIT(18)) #define DPORT_PWM0_RST (BIT(17)) -#define DPORT_SPI_RST (BIT(16)) +#define DPORT_SPI_RST_2 (BIT(16)) #define DPORT_TIMERGROUP1_RST (BIT(15)) #define DPORT_EFUSE_RST (BIT(14)) #define DPORT_TIMERGROUP_RST (BIT(13)) @@ -1002,7 +1002,7 @@ #define DPORT_RMT_RST (BIT(9)) #define DPORT_UHCI0_RST (BIT(8)) #define DPORT_I2C_EXT0_RST (BIT(7)) -#define DPORT_SPI_RST_2 (BIT(6)) +#define DPORT_SPI_RST (BIT(6)) #define DPORT_UART1_RST (BIT(5)) #define DPORT_I2S0_RST (BIT(4)) #define DPORT_WDG_RST (BIT(3)) @@ -4261,7 +4261,9 @@ /* Flash MMU table for APP CPU */ #define DPORT_APP_FLASH_MMU_TABLE ((volatile uint32_t*) 0x3FF12000) +#define DPORT_FLASH_MMU_TABLE_SIZE 0x100 +#define DPORT_FLASH_MMU_TABLE_INVALID_VAL 0x100 #endif /*_SOC_DPORT_REG_H_ */ diff --git a/tools/sdk/include/soc/soc/rtc_cntl_reg.h b/tools/sdk/include/soc/soc/rtc_cntl_reg.h index efb53ec1..ffcbb3c0 100644 --- a/tools/sdk/include/soc/soc/rtc_cntl_reg.h +++ b/tools/sdk/include/soc/soc/rtc_cntl_reg.h @@ -432,6 +432,7 @@ #define RTC_CNTL_MIN_SLP_VAL_M ((RTC_CNTL_MIN_SLP_VAL_V)<<(RTC_CNTL_MIN_SLP_VAL_S)) #define RTC_CNTL_MIN_SLP_VAL_V 0xFF #define RTC_CNTL_MIN_SLP_VAL_S 8 +#define RTC_CNTL_MIN_SLP_VAL_MIN 2 /* RTC_CNTL_ULP_CP_SUBTIMER_PREDIV : R/W ;bitpos:[7:0] ;default: 8'd1 ; */ /*description: */ #define RTC_CNTL_ULP_CP_SUBTIMER_PREDIV 0x000000FF @@ -1717,6 +1718,7 @@ #define RTC_WDT_STG_SEL_INT 1 #define RTC_WDT_STG_SEL_RESET_CPU 2 #define RTC_WDT_STG_SEL_RESET_SYSTEM 3 +#define RTC_WDT_STG_SEL_RESET_RTC 4 #define RTC_CNTL_WDTCONFIG1_REG (DR_REG_RTCCNTL_BASE + 0x90) /* RTC_CNTL_WDT_STG0_HOLD : R/W ;bitpos:[31:0] ;default: 32'd128000 ; */ diff --git a/tools/sdk/include/soc/soc/soc.h b/tools/sdk/include/soc/soc/soc.h index 218cdf96..3b1e85f2 100644 --- a/tools/sdk/include/soc/soc/soc.h +++ b/tools/sdk/include/soc/soc/soc.h @@ -142,14 +142,14 @@ //write value to register #define REG_WRITE(_r, _v) ({ \ - ASSERT_IF_DPORT_REG(_r, REG_WRITE); \ + ASSERT_IF_DPORT_REG((_r), REG_WRITE); \ (*(volatile uint32_t *)(_r)) = (_v); \ }) //read value from register #define REG_READ(_r) ({ \ ASSERT_IF_DPORT_REG((_r), REG_READ); \ - (*(volatile uint32_t *)_r); \ + (*(volatile uint32_t *)(_r)); \ }) //get bit or get bits from register @@ -269,6 +269,28 @@ #define TICKS_PER_US_ROM 26 // CPU is 80MHz //}} +/* Overall memory map */ +#define SOC_IROM_LOW 0x400D0000 +#define SOC_IROM_HIGH 0x40400000 +#define SOC_IRAM_LOW 0x40080000 +#define SOC_IRAM_HIGH 0x400A0000 +#define SOC_DROM_LOW 0x3F400000 +#define SOC_DROM_HIGH 0x3F800000 +#define SOC_RTC_IRAM_LOW 0x400C0000 +#define SOC_RTC_IRAM_HIGH 0x400C2000 +#define SOC_RTC_DATA_LOW 0x50000000 +#define SOC_RTC_DATA_HIGH 0x50002000 + +//First and last words of the D/IRAM region, for both the DRAM address as well as the IRAM alias. +#define SOC_DIRAM_IRAM_LOW 0x400A0000 +#define SOC_DIRAM_IRAM_HIGH 0x400BFFFC +#define SOC_DIRAM_DRAM_LOW 0x3FFE0000 +#define SOC_DIRAM_DRAM_HIGH 0x3FFFFFFC + +// Region of memory accessible via DMA. See esp_ptr_dma_capable(). +#define SOC_DMA_LOW 0x3FFAE000 +#define SOC_DMA_HIGH 0x40000000 + //Interrupt hardware source table //This table is decided by hardware, don't touch this. #define ETS_WIFI_MAC_INTR_SOURCE 0/**< interrupt of WiFi MAC, level*/ @@ -370,12 +392,12 @@ * 23 3 extern level * 24 4 extern level TG1_WDT * 25 4 extern level CACHEERR - * 26 5 extern level Reserved Reserved + * 26 5 extern level * 27 3 extern level Reserved Reserved - * 28 4 extern edge + * 28 4 extern edge DPORT ACCESS DPORT ACCESS * 29 3 software Reserved Reserved * 30 4 extern edge Reserved Reserved - * 31 5 extern level DPORT ACCESS DPORT ACCESS + * 31 5 extern level ************************************************************************************************************* */ @@ -387,7 +409,7 @@ #define ETS_FRC1_INUM 22 #define ETS_T1_WDT_INUM 24 #define ETS_CACHEERR_INUM 25 -#define ETS_DPORT_INUM 31 +#define ETS_DPORT_INUM 28 //CPU0 Interrupt number used in ROM, should be cancelled in SDK #define ETS_SLC_INUM 1 @@ -395,5 +417,7 @@ #define ETS_UART1_INUM 5 //Other interrupt number should be managed by the user +//Invalid interrupt for number interrupt matrix +#define ETS_INVALID_INUM 6 #endif /* _ESP32_SOC_H_ */ diff --git a/tools/sdk/include/soc/soc/uart_reg.h b/tools/sdk/include/soc/soc/uart_reg.h index df614a88..9d5ba2fb 100644 --- a/tools/sdk/include/soc/soc/uart_reg.h +++ b/tools/sdk/include/soc/soc/uart_reg.h @@ -17,8 +17,8 @@ #include "soc.h" -#define REG_UART_BASE( i ) (DR_REG_UART_BASE + (i) * 0x10000 + ( i > 1 ? 0xe000 : 0 ) ) -#define REG_UART_AHB_BASE(i) (0x60000000 + (i) * 0x10000 + ( i > 1 ? 0xe000 : 0 ) ) +#define REG_UART_BASE( i ) (DR_REG_UART_BASE + (i) * 0x10000 + ( (i) > 1 ? 0xe000 : 0 ) ) +#define REG_UART_AHB_BASE(i) (0x60000000 + (i) * 0x10000 + ( (i) > 1 ? 0xe000 : 0 ) ) #define UART_FIFO_AHB_REG(i) (REG_UART_AHB_BASE(i) + 0x0) #define UART_FIFO_REG(i) (REG_UART_BASE(i) + 0x0) diff --git a/tools/sdk/include/spi_flash/esp_spi_flash.h b/tools/sdk/include/spi_flash/esp_spi_flash.h index 00797b8d..fc48fd23 100644 --- a/tools/sdk/include/spi_flash/esp_spi_flash.h +++ b/tools/sdk/include/spi_flash/esp_spi_flash.h @@ -176,6 +176,29 @@ typedef uint32_t spi_flash_mmap_handle_t; esp_err_t spi_flash_mmap(size_t src_addr, size_t size, spi_flash_mmap_memory_t memory, const void** out_ptr, spi_flash_mmap_handle_t* out_handle); +/** + * @brief Map sequences of pages of flash memory into data or instruction address space + * + * This function allocates sufficient number of 64k MMU pages and configures + * them to map the indicated pages of flash memory contiguously into data address + * space or into instruction address space. In this respect, it works in a similar + * way as spi_flash_mmap but it allows mapping a (maybe non-contiguous) set of pages + * into a contiguous region of memory. + * + * @param pages An array of numbers indicating the 64K pages in flash to be mapped + * contiguously into memory. These indicate the indexes of the 64K pages, + * not the byte-size addresses as used in other functions. + * @param pagecount Size of the pages array + * @param memory Memory space where the region should be mapped + * @param out_ptr Output, pointer to the mapped memory region + * @param out_handle Output, handle which should be used for spi_flash_munmap call + * + * @return ESP_OK on success, ESP_ERR_NO_MEM if pages can not be allocated + */ +esp_err_t spi_flash_mmap_pages(int *pages, size_t pagecount, spi_flash_mmap_memory_t memory, + const void** out_ptr, spi_flash_mmap_handle_t* out_handle); + + /** * @brief Release region previously obtained using spi_flash_mmap * diff --git a/tools/sdk/include/ulp/esp32/ulp.h b/tools/sdk/include/ulp/esp32/ulp.h index 818a7962..302a47a0 100644 --- a/tools/sdk/include/ulp/esp32/ulp.h +++ b/tools/sdk/include/ulp/esp32/ulp.h @@ -882,6 +882,23 @@ esp_err_t ulp_load_binary(uint32_t load_addr, const uint8_t* program_binary, siz */ esp_err_t ulp_run(uint32_t entry_point); +/** + * @brief Set one of ULP wakeup period values + * + * ULP coprocessor starts running the program when the wakeup timer counts up + * to a given value (called period). There are 5 period values which can be + * programmed into SENS_ULP_CP_SLEEP_CYCx_REG registers, x = 0..4. + * By default, wakeup timer will use the period set into SENS_ULP_CP_SLEEP_CYC0_REG, + * i.e. period number 0. ULP program code can use SLEEP instruction to select + * which of the SENS_ULP_CP_SLEEP_CYCx_REG should be used for subsequent wakeups. + * + * @param period_index wakeup period setting number (0 - 4) + * @param period_us wakeup period, us + * @return + * - ESP_OK on success + * - ESP_ERR_INVALID_ARG if period_index is out of range + */ +esp_err_t ulp_set_wakeup_period(size_t period_index, uint32_t period_us); #ifdef __cplusplus } diff --git a/tools/sdk/include/vfs/esp_vfs.h b/tools/sdk/include/vfs/esp_vfs.h index 304750aa..a3ce6b95 100644 --- a/tools/sdk/include/vfs/esp_vfs.h +++ b/tools/sdk/include/vfs/esp_vfs.h @@ -69,8 +69,8 @@ typedef struct int fd_offset; /*!< file descriptor offset, determined by the FS driver */ int flags; /*!< ESP_VFS_FLAG_CONTEXT_PTR or ESP_VFS_FLAG_DEFAULT */ union { - size_t (*write_p)(void* p, int fd, const void * data, size_t size); - size_t (*write)(int fd, const void * data, size_t size); + ssize_t (*write_p)(void* p, int fd, const void * data, size_t size); + ssize_t (*write)(int fd, const void * data, size_t size); }; union { off_t (*lseek_p)(void* p, int fd, off_t size, int mode); diff --git a/tools/sdk/ld/esp32.common.ld b/tools/sdk/ld/esp32.common.ld index 48e31d1e..883dd29d 100644 --- a/tools/sdk/ld/esp32.common.ld +++ b/tools/sdk/ld/esp32.common.ld @@ -83,9 +83,11 @@ SECTIONS _iram_text_start = ABSOLUTE(.); *(.iram1 .iram1.*) *libfreertos.a:(.literal .text .literal.* .text.*) + *libheap.a:multi_heap.o(.literal .text .literal.* .text.*) *libesp32.a:panic.o(.literal .text .literal.* .text.*) *libesp32.a:core_dump.o(.literal .text .literal.* .text.*) - *libesp32.a:heap_alloc_caps.o(.literal .text .literal.* .text.*) + *libapp_trace.a:(.literal .text .literal.* .text.*) + *libxtensa-debug-module.a:eri.o(.literal .text .literal.* .text.*) *libesp32.a:app_trace.o(.literal .text .literal.* .text.*) *libphy.a:(.literal .text .literal.* .text.*) *librtc.a:(.literal .text .literal.* .text.*) @@ -98,21 +100,22 @@ SECTIONS .dram0.data : { _data_start = ABSOLUTE(.); - KEEP(*(.data)) - KEEP(*(.data.*)) - KEEP(*(.gnu.linkonce.d.*)) - KEEP(*(.data1)) - KEEP(*(.sdata)) - KEEP(*(.sdata.*)) - KEEP(*(.gnu.linkonce.s.*)) - KEEP(*(.sdata2)) - KEEP(*(.sdata2.*)) - KEEP(*(.gnu.linkonce.s2.*)) - KEEP(*(.jcr)) + *(.data) + *(.data.*) + *(.gnu.linkonce.d.*) + *(.data1) + *(.sdata) + *(.sdata.*) + *(.gnu.linkonce.s.*) + *(.sdata2) + *(.sdata2.*) + *(.gnu.linkonce.s2.*) + *(.jcr) *(.dram1 .dram1.*) *libesp32.a:panic.o(.rodata .rodata.*) - *libesp32.a:app_trace.o(.rodata .rodata.*) *libphy.a:(.rodata .rodata.*) + *libapp_trace.a:(.rodata .rodata.*) + *libheap.a:multi_heap.o(.rodata .rodata.*) _data_end = ABSOLUTE(.); . = ALIGN(4); } >dram0_0_seg diff --git a/tools/sdk/ld/esp32.ld b/tools/sdk/ld/esp32.ld index d6b0ac42..b27a49ee 100644 --- a/tools/sdk/ld/esp32.ld +++ b/tools/sdk/ld/esp32.ld @@ -25,8 +25,16 @@ MEMORY /* IRAM for PRO cpu. Not sure if happy with this, this is MMU area... */ iram0_0_seg (RX) : org = 0x40080000, len = 0x20000 - /* Even though the segment name is iram, it is actually mapped to flash */ - iram0_2_seg (RX) : org = 0x400D0018, len = 0x330000 + /* Even though the segment name is iram, it is actually mapped to flash + */ + iram0_2_seg (RX) : org = 0x400D0018, len = 0x330000-0x18 + + /* + (0x18 offset above is a convenience for the app binary image generation. Flash cache has 64KB pages. The .bin file + which is flashed to the chip has a 0x18 byte file header. Setting this offset makes it simple to meet the flash + cache MMU's constraint that (paddr % 64KB == vaddr % 64KB).) + */ + /* Shared data RAM, excluding memory reserved for ROM bss/data/stack. @@ -37,7 +45,9 @@ MEMORY len = 0x50000 - CONFIG_TRACEMEM_RESERVE_DRAM - CONFIG_BT_RESERVE_DRAM /* Flash mapped constant data */ - drom0_0_seg (R) : org = 0x3F400010, len = 0x800000 + drom0_0_seg (R) : org = 0x3F400018, len = 0x400000-0x18 + + /* (See iram0_2_seg for meaning of 0x18 offset in the above.) */ /* RTC fast memory (executable). Persists over deep sleep. */ diff --git a/tools/sdk/ld/esp32.rom.ld b/tools/sdk/ld/esp32.rom.ld index 9981e59f..6961854b 100644 --- a/tools/sdk/ld/esp32.rom.ld +++ b/tools/sdk/ld/esp32.rom.ld @@ -830,6 +830,7 @@ PROVIDE ( lmp_io_cap_req_handler = 0x4002c7a4 ); PROVIDE ( ld_acl_tx_packet_type_select = 0x4002fb40 ); PROVIDE ( ld_acl_sched = 0x40033268 ); PROVIDE ( ld_acl_sniff_sched = 0x4003340c ); +PROVIDE ( lm_cmd_cmp_send = 0x40051838 ); PROVIDE ( r_ld_acl_active_hop_types_get = 0x40036e10 ); PROVIDE ( r_ld_acl_afh_confirm = 0x40036d40 ); PROVIDE ( r_ld_acl_afh_prepare = 0x40036c84 ); @@ -1249,6 +1250,13 @@ PROVIDE ( r_lm_num_clk_adj_ack_pending_set = 0x4004f500 ); PROVIDE ( r_lm_oob_f1 = 0x40012e54 ); PROVIDE ( r_lm_pca_sscan_link_get = 0x4004f560 ); PROVIDE ( r_lm_pca_sscan_link_set = 0x4004f550 ); +PROVIDE ( nvds_null_read = 0x400542a0 ); +PROVIDE ( nvds_null_write = 0x400542a8 ); +PROVIDE ( nvds_null_erase = 0x400542b0 ); +PROVIDE ( nvds_read = 0x400542c4 ); +PROVIDE ( nvds_write = 0x400542fc ); +PROVIDE ( nvds_erase = 0x40054334 ); +PROVIDE ( nvds_init_memory = 0x40054358 ); PROVIDE ( r_lmp_pack = 0x4001135c ); PROVIDE ( r_lmp_unpack = 0x4001149c ); PROVIDE ( r_lm_read_features = 0x4004f0d8 ); @@ -1625,6 +1633,8 @@ PROVIDE ( esp_rom_spiflash_write_encrypted_disable = 0x40062e60 ); PROVIDE ( esp_rom_spiflash_write_encrypted_enable = 0x40062df4 ); PROVIDE ( esp_rom_spiflash_prepare_encrypted_data = 0x40062e1c ); PROVIDE ( esp_rom_spiflash_select_qio_pins = 0x40061ddc ); +PROVIDE ( esp_rom_spiflash_attach = 0x40062a6c ); +PROVIDE ( esp_rom_spiflash_config_clk = 0x40062bc8 ); PROVIDE ( g_rom_spiflash_chip = 0x3ffae270 ); /* @@ -1803,6 +1813,7 @@ PROVIDE ( ets_set_user_start = 0x4000687c ); PROVIDE ( ets_unpack_flash_code = 0x40007018 ); PROVIDE ( ets_unpack_flash_code_legacy = 0x4000694c ); PROVIDE ( rom_main = 0x400076c4 ); +PROVIDE ( ets_write_char_uart = 0x40007cf8 ); PROVIDE ( ets_install_putc1 = 0x40007d18 ); PROVIDE ( ets_install_putc2 = 0x40007d38 ); PROVIDE ( ets_install_uart_printf = 0x40007d28 ); @@ -1842,6 +1853,7 @@ PROVIDE ( ets_timer_setfn = 0x40008350 ); PROVIDE ( ets_update_cpu_frequency_rom = 0x40008550 ); /* Updates g_ticks_per_us on the current CPU only; not on the other core */ /* Following are static data, but can be used, not generated by script <<<<< btdm data */ +PROVIDE ( hci_tl_env = 0x3ffb8154 ); PROVIDE ( ld_acl_env = 0x3ffb8258 ); PROVIDE ( ld_active_ch_map = 0x3ffb8334 ); PROVIDE ( ld_bcst_acl_env = 0x3ffb8274 ); @@ -1862,5 +1874,7 @@ PROVIDE ( ld_strain_env = 0x3ffb8330 ); PROVIDE ( LM_Sniff = 0x3ffb8230 ); PROVIDE ( LM_SniffSubRate = 0x3ffb8214 ); PROVIDE ( prbs_64bytes = 0x3ff98992 ); +PROVIDE ( nvds_env = 0x3ffb8364 ); +PROVIDE ( nvds_magic_number = 0x3ff9912a ); /* Above are static data, but can be used, not generated by script >>>>> btdm data */ diff --git a/tools/sdk/ld/esp32_out.ld b/tools/sdk/ld/esp32_out.ld index bf93aca2..31bc1ef7 100644 --- a/tools/sdk/ld/esp32_out.ld +++ b/tools/sdk/ld/esp32_out.ld @@ -27,8 +27,14 @@ MEMORY are connected to the data port of the CPU and eg allow bytewise access. */ /* IRAM for PRO cpu. Not sure if happy with this, this is MMU area... */ iram0_0_seg (RX) : org = 0x40080000, len = 0x20000 - /* Even though the segment name is iram, it is actually mapped to flash */ - iram0_2_seg (RX) : org = 0x400D0018, len = 0x330000 + /* Even though the segment name is iram, it is actually mapped to flash + */ + iram0_2_seg (RX) : org = 0x400D0018, len = 0x330000-0x18 + /* + (0x18 offset above is a convenience for the app binary image generation. Flash cache has 64KB pages. The .bin file + which is flashed to the chip has a 0x18 byte file header. Setting this offset makes it simple to meet the flash + cache MMU's constraint that (paddr % 64KB == vaddr % 64KB).) + */ /* Shared data RAM, excluding memory reserved for ROM bss/data/stack. Enabling Bluetooth & Trace Memory features in menuconfig will decrease @@ -37,7 +43,8 @@ MEMORY dram0_0_seg (RW) : org = 0x3FFB0000 + 0x10000, len = 0x50000 - 0x0 - 0x10000 /* Flash mapped constant data */ - drom0_0_seg (R) : org = 0x3F400010, len = 0x800000 + drom0_0_seg (R) : org = 0x3F400018, len = 0x400000-0x18 + /* (See iram0_2_seg for meaning of 0x18 offset in the above.) */ /* RTC fast memory (executable). Persists over deep sleep. */ rtc_iram_seg(RWX) : org = 0x400C0000, len = 0x2000 diff --git a/tools/sdk/lib/libapp_trace.a b/tools/sdk/lib/libapp_trace.a new file mode 100644 index 00000000..72d6f770 Binary files /dev/null and b/tools/sdk/lib/libapp_trace.a differ diff --git a/tools/sdk/lib/libapp_update.a b/tools/sdk/lib/libapp_update.a index 2348b05e..4a7203bc 100644 Binary files a/tools/sdk/lib/libapp_update.a and b/tools/sdk/lib/libapp_update.a differ diff --git a/tools/sdk/lib/libbootloader_support.a b/tools/sdk/lib/libbootloader_support.a index 87dcda60..494ff003 100644 Binary files a/tools/sdk/lib/libbootloader_support.a and b/tools/sdk/lib/libbootloader_support.a differ diff --git a/tools/sdk/lib/libbt.a b/tools/sdk/lib/libbt.a index 4ddbd30e..1ac70505 100644 Binary files a/tools/sdk/lib/libbt.a and b/tools/sdk/lib/libbt.a differ diff --git a/tools/sdk/lib/libbtdm_app.a b/tools/sdk/lib/libbtdm_app.a index 422b169c..df3a38fb 100644 Binary files a/tools/sdk/lib/libbtdm_app.a and b/tools/sdk/lib/libbtdm_app.a differ diff --git a/tools/sdk/lib/libcoap.a b/tools/sdk/lib/libcoap.a index 26ac7f9f..e55f6740 100644 Binary files a/tools/sdk/lib/libcoap.a and b/tools/sdk/lib/libcoap.a differ diff --git a/tools/sdk/lib/libcoexist.a b/tools/sdk/lib/libcoexist.a index dd6bc566..bc916d77 100644 Binary files a/tools/sdk/lib/libcoexist.a and b/tools/sdk/lib/libcoexist.a differ diff --git a/tools/sdk/lib/libcore.a b/tools/sdk/lib/libcore.a index b078ac68..e9ac8145 100644 Binary files a/tools/sdk/lib/libcore.a and b/tools/sdk/lib/libcore.a differ diff --git a/tools/sdk/lib/libcxx.a b/tools/sdk/lib/libcxx.a index ed6dc3fb..801fdc18 100644 Binary files a/tools/sdk/lib/libcxx.a and b/tools/sdk/lib/libcxx.a differ diff --git a/tools/sdk/lib/libdriver.a b/tools/sdk/lib/libdriver.a index 723f96c3..c78625a2 100644 Binary files a/tools/sdk/lib/libdriver.a and b/tools/sdk/lib/libdriver.a differ diff --git a/tools/sdk/lib/libesp32.a b/tools/sdk/lib/libesp32.a index e52934d3..d2ce1f0e 100644 Binary files a/tools/sdk/lib/libesp32.a and b/tools/sdk/lib/libesp32.a differ diff --git a/tools/sdk/lib/libethernet.a b/tools/sdk/lib/libethernet.a index 4fda0261..3c21b9eb 100644 Binary files a/tools/sdk/lib/libethernet.a and b/tools/sdk/lib/libethernet.a differ diff --git a/tools/sdk/lib/libexpat.a b/tools/sdk/lib/libexpat.a index 11592674..d9766e67 100644 Binary files a/tools/sdk/lib/libexpat.a and b/tools/sdk/lib/libexpat.a differ diff --git a/tools/sdk/lib/libfatfs.a b/tools/sdk/lib/libfatfs.a index 0ca4c761..5f3900fe 100644 Binary files a/tools/sdk/lib/libfatfs.a and b/tools/sdk/lib/libfatfs.a differ diff --git a/tools/sdk/lib/libfreertos.a b/tools/sdk/lib/libfreertos.a index f307a7ec..46a14b31 100644 Binary files a/tools/sdk/lib/libfreertos.a and b/tools/sdk/lib/libfreertos.a differ diff --git a/tools/sdk/lib/libheap.a b/tools/sdk/lib/libheap.a new file mode 100644 index 00000000..4f27c753 Binary files /dev/null and b/tools/sdk/lib/libheap.a differ diff --git a/tools/sdk/lib/libjsmn.a b/tools/sdk/lib/libjsmn.a index 9c03476d..37a9efe2 100644 Binary files a/tools/sdk/lib/libjsmn.a and b/tools/sdk/lib/libjsmn.a differ diff --git a/tools/sdk/lib/libjson.a b/tools/sdk/lib/libjson.a index 63849d62..07dd5d0e 100644 Binary files a/tools/sdk/lib/libjson.a and b/tools/sdk/lib/libjson.a differ diff --git a/tools/sdk/lib/liblibsodium.a b/tools/sdk/lib/liblibsodium.a new file mode 100644 index 00000000..d0dbcfed Binary files /dev/null and b/tools/sdk/lib/liblibsodium.a differ diff --git a/tools/sdk/lib/liblog.a b/tools/sdk/lib/liblog.a index a08dabc8..4166488a 100644 Binary files a/tools/sdk/lib/liblog.a and b/tools/sdk/lib/liblog.a differ diff --git a/tools/sdk/lib/liblwip.a b/tools/sdk/lib/liblwip.a index 7ecc904e..1210767e 100644 Binary files a/tools/sdk/lib/liblwip.a and b/tools/sdk/lib/liblwip.a differ diff --git a/tools/sdk/lib/libmbedtls.a b/tools/sdk/lib/libmbedtls.a index 6e9783f1..16aea0fd 100644 Binary files a/tools/sdk/lib/libmbedtls.a and b/tools/sdk/lib/libmbedtls.a differ diff --git a/tools/sdk/lib/libmdns.a b/tools/sdk/lib/libmdns.a index 3137b1f4..f449c626 100644 Binary files a/tools/sdk/lib/libmdns.a and b/tools/sdk/lib/libmdns.a differ diff --git a/tools/sdk/lib/libmicro-ecc.a b/tools/sdk/lib/libmicro-ecc.a index a35d5a00..5c57e8a9 100644 Binary files a/tools/sdk/lib/libmicro-ecc.a and b/tools/sdk/lib/libmicro-ecc.a differ diff --git a/tools/sdk/lib/libnet80211.a b/tools/sdk/lib/libnet80211.a index 96b78dff..0be63952 100644 Binary files a/tools/sdk/lib/libnet80211.a and b/tools/sdk/lib/libnet80211.a differ diff --git a/tools/sdk/lib/libnewlib.a b/tools/sdk/lib/libnewlib.a index 91ae9e09..0a1182fc 100644 Binary files a/tools/sdk/lib/libnewlib.a and b/tools/sdk/lib/libnewlib.a differ diff --git a/tools/sdk/lib/libnghttp.a b/tools/sdk/lib/libnghttp.a index d3624ada..a7f39ae1 100644 Binary files a/tools/sdk/lib/libnghttp.a and b/tools/sdk/lib/libnghttp.a differ diff --git a/tools/sdk/lib/libnvs_flash.a b/tools/sdk/lib/libnvs_flash.a index 8706a1c4..cfb09177 100644 Binary files a/tools/sdk/lib/libnvs_flash.a and b/tools/sdk/lib/libnvs_flash.a differ diff --git a/tools/sdk/lib/libopenssl.a b/tools/sdk/lib/libopenssl.a index ec3058d1..ec8c08f1 100644 Binary files a/tools/sdk/lib/libopenssl.a and b/tools/sdk/lib/libopenssl.a differ diff --git a/tools/sdk/lib/libphy.a b/tools/sdk/lib/libphy.a old mode 100755 new mode 100644 index c3060066..64601102 Binary files a/tools/sdk/lib/libphy.a and b/tools/sdk/lib/libphy.a differ diff --git a/tools/sdk/lib/libpp.a b/tools/sdk/lib/libpp.a index 9b5f99b6..b50eadd0 100644 Binary files a/tools/sdk/lib/libpp.a and b/tools/sdk/lib/libpp.a differ diff --git a/tools/sdk/lib/libsdmmc.a b/tools/sdk/lib/libsdmmc.a index cacff359..0db995d4 100644 Binary files a/tools/sdk/lib/libsdmmc.a and b/tools/sdk/lib/libsdmmc.a differ diff --git a/tools/sdk/lib/libsmartconfig.a b/tools/sdk/lib/libsmartconfig.a index 077fed62..2bbd0b4e 100644 Binary files a/tools/sdk/lib/libsmartconfig.a and b/tools/sdk/lib/libsmartconfig.a differ diff --git a/tools/sdk/lib/libsoc.a b/tools/sdk/lib/libsoc.a index c475c188..8134e8ff 100644 Binary files a/tools/sdk/lib/libsoc.a and b/tools/sdk/lib/libsoc.a differ diff --git a/tools/sdk/lib/libspi_flash.a b/tools/sdk/lib/libspi_flash.a index be5ac22a..12c7ca44 100644 Binary files a/tools/sdk/lib/libspi_flash.a and b/tools/sdk/lib/libspi_flash.a differ diff --git a/tools/sdk/lib/libtcpip_adapter.a b/tools/sdk/lib/libtcpip_adapter.a index 0576944c..622cb6a3 100644 Binary files a/tools/sdk/lib/libtcpip_adapter.a and b/tools/sdk/lib/libtcpip_adapter.a differ diff --git a/tools/sdk/lib/libulp.a b/tools/sdk/lib/libulp.a index e8a7722e..6d3a0c8c 100644 Binary files a/tools/sdk/lib/libulp.a and b/tools/sdk/lib/libulp.a differ diff --git a/tools/sdk/lib/libvfs.a b/tools/sdk/lib/libvfs.a index 340f4de5..e020aa51 100644 Binary files a/tools/sdk/lib/libvfs.a and b/tools/sdk/lib/libvfs.a differ diff --git a/tools/sdk/lib/libwear_levelling.a b/tools/sdk/lib/libwear_levelling.a index a6e75864..180e1901 100644 Binary files a/tools/sdk/lib/libwear_levelling.a and b/tools/sdk/lib/libwear_levelling.a differ diff --git a/tools/sdk/lib/libwpa.a b/tools/sdk/lib/libwpa.a index b8287326..5c9e9d44 100644 Binary files a/tools/sdk/lib/libwpa.a and b/tools/sdk/lib/libwpa.a differ diff --git a/tools/sdk/lib/libwpa2.a b/tools/sdk/lib/libwpa2.a index 7c6dedce..a720e6ed 100644 Binary files a/tools/sdk/lib/libwpa2.a and b/tools/sdk/lib/libwpa2.a differ diff --git a/tools/sdk/lib/libwpa_supplicant.a b/tools/sdk/lib/libwpa_supplicant.a index 3d0e1abb..9f3f1d3d 100644 Binary files a/tools/sdk/lib/libwpa_supplicant.a and b/tools/sdk/lib/libwpa_supplicant.a differ diff --git a/tools/sdk/lib/libwps.a b/tools/sdk/lib/libwps.a index c522d610..c15854cc 100644 Binary files a/tools/sdk/lib/libwps.a and b/tools/sdk/lib/libwps.a differ diff --git a/tools/sdk/lib/libxtensa-debug-module.a b/tools/sdk/lib/libxtensa-debug-module.a index 0ec7c082..24215ff6 100644 Binary files a/tools/sdk/lib/libxtensa-debug-module.a and b/tools/sdk/lib/libxtensa-debug-module.a differ