提交 d02c1c78 编写于 作者: M Me No Dev 提交者: GitHub

Update IDF, fix SS definition, add custom partitions and debug level selection (#174)

* Add build time partitions compilation

* Fix wrong definition of SS pin

* Add support for core debug level selection

* update idf libs
上级 ee8149e2
menu.UploadSpeed=Upload Speed
menu.FlashFreq=Flash Frequency
menu.DebugLevel=Core Debug Level
##############################################################
esp32.name=ESP32 Dev Module
esp32.upload.tool=esptool
......@@ -41,7 +43,62 @@ esp32.menu.UploadSpeed.460800.upload.speed=460800
esp32.menu.UploadSpeed.512000.windows=512000
esp32.menu.UploadSpeed.512000.upload.speed=512000
esp32.menu.DebugLevel.none=None
esp32.menu.DebugLevel.none.build.code_debug=0
esp32.menu.DebugLevel.error=Error
esp32.menu.DebugLevel.error.build.code_debug=1
esp32.menu.DebugLevel.warn=Warn
esp32.menu.DebugLevel.warn.build.code_debug=2
esp32.menu.DebugLevel.info=Info
esp32.menu.DebugLevel.info.build.code_debug=3
esp32.menu.DebugLevel.debug=Debug
esp32.menu.DebugLevel.debug.build.code_debug=4
esp32.menu.DebugLevel.verbose=Verbose
esp32.menu.DebugLevel.verbose.build.code_debug=5
##############################################################
esp32thing.name=SparkFun ESP32 Thing
esp32thing.upload.tool=esptool
esp32thing.upload.maximum_size=1044464
esp32thing.upload.maximum_data_size=294912
esp32thing.upload.wait_for_upload_port=true
esp32thing.serial.disableDTR=true
esp32thing.serial.disableRTS=true
esp32thing.build.mcu=esp32
esp32thing.build.core=esp32
esp32thing.build.variant=esp32thing
esp32thing.build.board=ESP32_THING
esp32thing.build.f_cpu=240000000L
esp32thing.build.flash_mode=dio
esp32thing.build.flash_size=4MB
esp32thing.menu.FlashFreq.80=80MHz
esp32thing.menu.FlashFreq.80.build.flash_freq=80m
esp32thing.menu.FlashFreq.40=40MHz
esp32thing.menu.FlashFreq.40.build.flash_freq=40m
esp32thing.menu.UploadSpeed.921600=921600
esp32thing.menu.UploadSpeed.921600.upload.speed=921600
esp32thing.menu.UploadSpeed.115200=115200
esp32thing.menu.UploadSpeed.115200.upload.speed=115200
esp32thing.menu.UploadSpeed.256000.windows=256000
esp32thing.menu.UploadSpeed.256000.upload.speed=256000
esp32thing.menu.UploadSpeed.230400.windows.upload.speed=256000
esp32thing.menu.UploadSpeed.230400=230400
esp32thing.menu.UploadSpeed.230400.upload.speed=230400
esp32thing.menu.UploadSpeed.460800.linux=460800
esp32thing.menu.UploadSpeed.460800.macosx=460800
esp32thing.menu.UploadSpeed.460800.upload.speed=460800
esp32thing.menu.UploadSpeed.512000.windows=512000
esp32thing.menu.UploadSpeed.512000.upload.speed=512000
##############################################################
esp320.name=Electronic SweetPeas - ESP320
esp320.upload.tool=esptool
......@@ -82,6 +139,7 @@ esp320.menu.UploadSpeed.512000.windows=512000
esp320.menu.UploadSpeed.512000.upload.speed=512000
##############################################################
nano32.name=Nano32
nano32.upload.tool=esptool
......@@ -122,6 +180,7 @@ nano32.menu.UploadSpeed.512000.windows=512000
nano32.menu.UploadSpeed.512000.upload.speed=512000
##############################################################
lolin32.name=WEMOS LoLin32
lolin32.upload.tool=esptool
......@@ -162,6 +221,7 @@ lolin32.menu.UploadSpeed.512000.windows=512000
lolin32.menu.UploadSpeed.512000.upload.speed=512000
##############################################################
espea32.name=ESPea32
espea32.upload.tool=esptool
......@@ -202,6 +262,7 @@ espea32.menu.UploadSpeed.512000.windows=512000
espea32.menu.UploadSpeed.512000.upload.speed=512000
##############################################################
quantum.name=Noduino Quantum
quantum.upload.tool=esptool
......@@ -242,6 +303,7 @@ quantum.menu.UploadSpeed.512000.windows=512000
quantum.menu.UploadSpeed.512000.upload.speed=512000
##############################################################
node32s.name=Node32s
node32s.upload.tool=esptool
......@@ -280,7 +342,9 @@ node32s.menu.UploadSpeed.460800.macosx=460800
node32s.menu.UploadSpeed.460800.upload.speed=460800
node32s.menu.UploadSpeed.512000.windows=512000
node32s.menu.UploadSpeed.512000.upload.speed=512000
##############################################################
hornbill32dev.name=Hornbill ESP32 Dev
hornbill32dev.upload.tool=esptool
......@@ -318,7 +382,9 @@ hornbill32dev.menu.UploadSpeed.460800.macosx=460800
hornbill32dev.menu.UploadSpeed.460800.upload.speed=460800
hornbill32dev.menu.UploadSpeed.512000.windows=512000
hornbill32dev.menu.UploadSpeed.512000.upload.speed=512000
##############################################################
hornbill32minima.name=Hornbill ESP32 Minima
hornbill32minima.upload.tool=esptool
......
......@@ -32,6 +32,12 @@ extern "C"
#define CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL ARDUHAL_LOG_LEVEL_NONE
#endif
#ifndef CORE_DEBUG_LEVEL
#define ARDUHAL_LOG_LEVEL CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL
#else
#define ARDUHAL_LOG_LEVEL CORE_DEBUG_LEVEL
#endif
#ifndef CONFIG_ARDUHAL_LOG_COLORS
#define CONFIG_ARDUHAL_LOG_COLORS 0
#endif
......@@ -71,31 +77,31 @@ int log_printf(const char *fmt, ...);
#define ARDUHAL_SHORT_LOG_FORMAT(letter, format) ARDUHAL_LOG_COLOR_ ## letter format ARDUHAL_LOG_RESET_COLOR "\r\n"
#define ARDUHAL_LOG_FORMAT(letter, format) ARDUHAL_LOG_COLOR_ ## letter "[" #letter "][%s:%u] %s(): " format ARDUHAL_LOG_RESET_COLOR "\r\n", pathToFileName(__FILE__), __LINE__, __FUNCTION__
#if CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL >= ARDUHAL_LOG_LEVEL_VERBOSE
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_VERBOSE
#define log_v(format, ...) log_printf(ARDUHAL_LOG_FORMAT(V, format), ##__VA_ARGS__)
#else
#define log_v(format, ...)
#endif
#if CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG
#define log_d(format, ...) log_printf(ARDUHAL_LOG_FORMAT(D, format), ##__VA_ARGS__)
#else
#define log_d(format, ...)
#endif
#if CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
#define log_i(format, ...) log_printf(ARDUHAL_LOG_FORMAT(I, format), ##__VA_ARGS__)
#else
#define log_i(format, ...)
#endif
#if CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL >= ARDUHAL_LOG_LEVEL_WARN
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_WARN
#define log_w(format, ...) log_printf(ARDUHAL_LOG_FORMAT(W, format), ##__VA_ARGS__)
#else
#define log_w(format, ...)
#endif
#if CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL >= ARDUHAL_LOG_LEVEL_ERROR
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_ERROR
#define log_e(format, ...) log_printf(ARDUHAL_LOG_FORMAT(E, format), ##__VA_ARGS__)
#else
#define log_e(format, ...)
......
......@@ -166,7 +166,7 @@ void WiFiGenericClass::removeEvent(WiFiEventCb cbEvent, system_event_id_t event)
* callback for WiFi events
* @param arg
*/
#if CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG
const char * system_event_names[] = { "WIFI_READY", "SCAN_DONE", "STA_START", "STA_STOP", "STA_CONNECTED", "STA_DISCONNECTED", "STA_AUTHMODE_CHANGE", "STA_GOT_IP", "STA_WPS_ER_SUCCESS", "STA_WPS_ER_FAILED", "STA_WPS_ER_TIMEOUT", "STA_WPS_ER_PIN", "AP_START", "AP_STOP", "AP_STACONNECTED", "AP_STADISCONNECTED", "AP_PROBEREQRECVED", "AP_STA_GOT_IP6", "ETH_START", "ETH_STOP", "ETH_CONNECTED", "ETH_DISCONNECTED", "ETH_GOT_IP", "MAX"};
const char * system_event_reasons[] = { "UNSPECIFIED", "AUTH_EXPIRE", "AUTH_LEAVE", "ASSOC_EXPIRE", "ASSOC_TOOMANY", "NOT_AUTHED", "NOT_ASSOCED", "ASSOC_LEAVE", "ASSOC_NOT_AUTHED", "DISASSOC_PWRCAP_BAD", "DISASSOC_SUPCHAN_BAD", "IE_INVALID", "MIC_FAILURE", "4WAY_HANDSHAKE_TIMEOUT", "GROUP_KEY_UPDATE_TIMEOUT", "IE_IN_4WAY_DIFFERS", "GROUP_CIPHER_INVALID", "PAIRWISE_CIPHER_INVALID", "AKMP_INVALID", "UNSUPP_RSN_IE_VERSION", "INVALID_RSN_IE_CAP", "802_1X_AUTH_FAILED", "CIPHER_SUITE_REJECTED", "BEACON_TIMEOUT", "NO_AP_FOUND", "AUTH_FAIL", "ASSOC_FAIL", "HANDSHAKE_TIMEOUT" };
#define reason2str(r) ((r>174)?system_event_reasons[r-174]:system_event_reasons[r-1])
......
......@@ -6,6 +6,9 @@ runtime.tools.xtensa-esp32-elf-gcc.path={runtime.platform.path}/tools/xtensa-esp
tools.esptool.cmd="{runtime.platform.path}/tools/esptool"
tools.esptool.cmd.windows="{runtime.platform.path}/tools/esptool.exe"
tools.gen_esp32part.cmd=python "{runtime.platform.path}/tools/gen_esp32part.py"
tools.gen_esp32part.cmd.windows="{runtime.platform.path}/tools/gen_esp32part.exe"
compiler.warning_flags=-w
compiler.warning_flags.none=-w
compiler.warning_flags.default=
......@@ -14,7 +17,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/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/log" "-I{compiler.sdk.path}/include/mdns" "-I{compiler.sdk.path}/include/vfs" "-I{compiler.sdk.path}/include/ulp" "-I{compiler.sdk.path}/include/newlib" "-I{compiler.sdk.path}/include/nvs_flash" "-I{compiler.sdk.path}/include/spi_flash" "-I{compiler.sdk.path}/include/sdmmc" "-I{compiler.sdk.path}/include/openssl" "-I{compiler.sdk.path}/include/app_update" "-I{compiler.sdk.path}/include/tcpip_adapter" "-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/mbedtls" "-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/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/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/vfs" "-I{compiler.sdk.path}/include/ulp" "-I{compiler.sdk.path}/include/newlib" "-I{compiler.sdk.path}/include/nvs_flash" "-I{compiler.sdk.path}/include/spi_flash" "-I{compiler.sdk.path}/include/sdmmc" "-I{compiler.sdk.path}/include/openssl" "-I{compiler.sdk.path}/include/app_update" "-I{compiler.sdk.path}/include/tcpip_adapter" "-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
......@@ -27,7 +30,7 @@ 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=-lapp_update -lbootloader_support -lbt -lbtdm_app -lc -lc_nano -lcoap -lcoexist -lcore -lcxx -ldriver -lesp32 -lethernet -lexpat -lfatfs -lfreertos -lhal -ljson -llog -llwip -lm -lmbedtls -lmdns -lmicro-ecc -lnet80211 -lnewlib -lnghttp -lnvs_flash -lopenssl -lphy -lpp -lrtc -lsdmmc -lsmartconfig -lspi_flash -ltcpip_adapter -lulp -lvfs -lwpa -lwpa2 -lwpa_supplicant -lwps -lxtensa-debug-module -lgcc -lstdc++
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 -ljson -llog -llwip -lm -lmbedtls -lmdns -lmicro-ecc -lnet80211 -lnewlib -lnghttp -lnvs_flash -lopenssl -lphy -lpp -lrtc -lsdmmc -lsmartconfig -lspi_flash -ltcpip_adapter -lulp -lvfs -lwpa -lwpa2 -lwpa_supplicant -lwps -lxtensa-debug-module
compiler.as.cmd=xtensa-esp32-elf-as
......@@ -37,7 +40,8 @@ compiler.ar.flags=cru
compiler.size.cmd=xtensa-esp32-elf-size
# This can be overriden in boards.txt
build.extra_flags=-DESP32
build.code_debug=0
build.extra_flags=-DESP32 -DCORE_DEBUG_LEVEL={build.code_debug}
# These can be overridden in platform.local.txt
compiler.c.extra_flags=
......@@ -64,7 +68,7 @@ recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compil
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} -Wl,--start-group {object_files} "{build.path}/arduino.ar" {compiler.c.elf.libs} -Wl,--end-group -Wl,-EL -o "{build.path}/{build.project_name}.elf"
## Create eeprom
recipe.objcopy.eep.pattern=
recipe.objcopy.eep.pattern={tools.gen_esp32part.cmd} -q "{runtime.platform.path}/tools/partitions/default.csv" "{build.path}/{build.project_name}.partitions.bin"
## Create hex
recipe.objcopy.hex.pattern={tools.esptool.cmd} --chip esp32 elf2image --flash_mode "{build.flash_mode}" --flash_freq "{build.flash_freq}" --flash_size "{build.flash_size}" -o "{build.path}/{build.project_name}.bin" "{build.path}/{build.project_name}.elf"
......@@ -83,4 +87,4 @@ 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} 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 "{runtime.platform.path}/tools/sdk/bin/partitions_singleapp.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_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" 0x10000 "{build.path}/{build.project_name}.bin"
此差异已折叠。
#!/usr/bin/env python
#
# ESP32 partition table generation tool
#
# Converts partition tables to/from CSV and binary formats.
#
# See the sdkng README.md file for details about how to use this tool.
import struct
import argparse
import sys
MAX_PARTITION_LENGTH = 0xC00 # 3K for partition data (96 entries) leaves 1K in a 4K sector for signature
__version__ = '1.0'
quiet = False
def status(msg):
""" Print status message to stderr """
if not quiet:
critical(msg)
def critical(msg):
""" Print critical message to stderr """
if not quiet:
sys.stderr.write(msg)
sys.stderr.write('\n')
class PartitionTable(list):
def __init__(self):
super(PartitionTable, self).__init__(self)
@classmethod
def from_csv(cls, csv_contents):
res = PartitionTable()
lines = csv_contents.split("\n")
for line_no in range(len(lines)):
line = lines[line_no].strip()
if line.startswith("#") or len(line) == 0:
continue
try:
res.append(PartitionDefinition.from_csv(line))
except InputError as e:
raise InputError("Error at line %d: %s" % (line_no+1, e))
except Exception:
critical("Unexpected error parsing line %d: %s" % (line_no+1, line))
raise
# fix up missing offsets & negative sizes
last_end = 0x5000 # first offset after partition table
for e in res:
if e.offset is None:
pad_to = 0x10000 if e.type == PartitionDefinition.APP_TYPE else 4
if last_end % pad_to != 0:
last_end += pad_to - (last_end % pad_to)
e.offset = last_end
if e.size < 0:
e.size = -e.size - e.offset
last_end = e.offset + e.size
return res
def __getitem__(self, item):
""" Allow partition table access via name as well as by
numeric index. """
if isinstance(item, str):
for x in self:
if x.name == item:
return x
raise ValueError("No partition entry named '%s'" % item)
else:
return super(PartitionTable, self).__getitem__(item)
def verify(self):
# verify each partition individually
for p in self:
p.verify()
# check for overlaps
last = None
for p in sorted(self):
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:
raise InputError("Partition at 0x%x overlaps 0x%x-0x%x" % (p.offset, last.offset, last.offset+last.size-1))
last = p
@classmethod
def from_binary(cls, b):
result = cls()
for o in range(0,len(b),32):
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:
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)
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
return result
def to_csv(self, simple_formatting=False):
rows = [ "# Espressif ESP32 Partition Table",
"# Name, Type, SubType, Offset, Size, Flags" ]
rows += [ x.to_csv(simple_formatting) for x in self ]
return "\n".join(rows) + "\n"
class PartitionDefinition(object):
APP_TYPE = 0x00
DATA_TYPE = 0x01
TYPES = {
"app" : APP_TYPE,
"data" : DATA_TYPE,
}
# Keep this map in sync with esp_partition_subtype_t enum in esp_partition.h
SUBTYPES = {
APP_TYPE : {
"factory" : 0x00,
"test" : 0x20,
},
DATA_TYPE : {
"ota" : 0x00,
"phy" : 0x01,
"nvs" : 0x02,
"coredump" : 0x03,
"esphttpd" : 0x80,
"fat" : 0x81,
"spiffs" : 0x82,
},
}
MAGIC_BYTES = "\xAA\x50"
ALIGNMENT = {
APP_TYPE : 0x1000,
DATA_TYPE : 0x04,
}
# dictionary maps flag name (as used in CSV flags list, property name)
# to bit set in flags words in binary format
FLAGS = {
"encrypted" : 0
}
# add subtypes for the 16 OTA slot values ("ota_XXX, etc.")
for ota_slot in range(16):
SUBTYPES[TYPES["app"]]["ota_%d" % ota_slot] = 0x10 + ota_slot
def __init__(self):
self.name = ""
self.type = None
self.subtype = None
self.offset = None
self.size = None
self.encrypted = False
@classmethod
def from_csv(cls, line):
""" Parse a line from the CSV """
line_w_defaults = line + ",,,," # lazy way to support default fields
fields = [ f.strip() for f in line_w_defaults.split(",") ]
res = PartitionDefinition()
res.name = fields[0]
res.type = res.parse_type(fields[1])
res.subtype = res.parse_subtype(fields[2])
res.offset = res.parse_address(fields[3])
res.size = res.parse_address(fields[4])
if res.size is None:
raise InputError("Size field can't be empty")
flags = fields[5].split(":")
for flag in flags:
if flag in cls.FLAGS:
setattr(res, flag, True)
elif len(flag) > 0:
raise InputError("CSV flag column contains unknown flag '%s'" % (flag))
return res
def __eq__(self, other):
return self.name == other.name and self.type == other.type \
and self.subtype == other.subtype and self.offset == other.offset \
and self.size == other.size
def __repr__(self):
def maybe_hex(x):
return "0x%x" % x if x is not None else "None"
return "PartitionDefinition('%s', 0x%x, 0x%x, %s, %s)" % (self.name, self.type, self.subtype or 0,
maybe_hex(self.offset), maybe_hex(self.size))
def __str__(self):
return "Part '%s' %d/%d @ 0x%x size 0x%x" % (self.name, self.type, self.subtype, self.offset or -1, self.size or -1)
def __cmp__(self, other):
return self.offset - other.offset
def parse_type(self, strval):
if strval == "":
raise InputError("Field 'type' can't be left empty.")
return parse_int(strval, self.TYPES)
def parse_subtype(self, strval):
if strval == "":
return 0 # default
return parse_int(strval, self.SUBTYPES.get(self.type, {}))
def parse_address(self, strval):
if strval == "":
return None # PartitionTable will fill in default
return parse_int(strval)
def verify(self):
if self.type is None:
raise ValidationError("Type field is not set")
if self.subtype is None:
raise ValidationError("Subtype field is not set")
if self.offset is None:
raise ValidationError("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))
if self.size is None:
raise ValidationError("Size field is not set")
STRUCT_FORMAT = "<2sBBLL16sL"
@classmethod
def from_binary(cls, b):
if len(b) != 32:
raise InputError("Partition definition length must be exactly 32 bytes. Got %d bytes." % len(b))
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 magic != cls.MAGIC_BYTES:
raise InputError("Invalid magic bytes (%r) for partition definition" % magic)
for flag,bit in cls.FLAGS.items():
if flags & (1<<bit):
setattr(res, flag, True)
flags &= ~(1<<bit)
if flags != 0:
critical("WARNING: Partition definition had unknown flag(s) 0x%08x. Newer binary format?" % flags)
return res
def get_flags_list(self):
return [ flag for flag in self.FLAGS.keys() if getattr(self, flag) ]
def to_binary(self):
flags = sum((1 << self.FLAGS[flag]) for flag in self.get_flags_list())
return struct.pack(self.STRUCT_FORMAT,
self.MAGIC_BYTES,
self.type, self.subtype,
self.offset, self.size,
self.name,
flags)
def to_csv(self, simple_formatting=False):
def addr_format(a, include_sizes):
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 "0x%x" % a
def lookup_keyword(t, keywords):
for k,v in keywords.items():
if simple_formatting == False and t == v:
return k
return "%d" % t
def generate_text_flags():
""" colon-delimited list of flags """
return ":".join(self.get_flags_list())
return ",".join([ self.name,
lookup_keyword(self.type, self.TYPES),
lookup_keyword(self.subtype, self.SUBTYPES.get(self.type, {})),
addr_format(self.offset, False),
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
k/m/K/M suffixes and 'keyword' value lookup.
"""
try:
for letter, multiplier in [ ("k",1024), ("m",1024*1024) ]:
if v.lower().endswith(letter):
return parse_int(v[:-1], keywords) * multiplier
return int(v, 0)
except ValueError:
if len(keywords) == 0:
raise InputError("Invalid field value %s" % v)
try:
return keywords[v.lower()]
except KeyError:
raise InputError("Value '%s' is not valid. Known keywords: %s" % (v, ", ".join(keywords)))
def main():
global quiet
parser = argparse.ArgumentParser(description='ESP32 partition table utility')
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('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='-')
args = parser.parse_args()
quiet = args.quiet
input = args.input.read()
input_is_binary = input[0:2] == PartitionDefinition.MAGIC_BYTES
if input_is_binary:
status("Parsing binary partition input...")
table = PartitionTable.from_binary(input)
else:
status("Parsing CSV input...")
table = PartitionTable.from_csv(input)
if args.verify:
status("Verifying table...")
table.verify()
if input_is_binary:
output = table.to_csv()
else:
output = table.to_binary()
with sys.stdout if args.output == '-' else open(args.output, 'w') as f:
f.write(output)
if __name__ == '__main__':
try:
main()
except InputError as e:
print(e)
sys.exit(2)
# Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 0x9000, 0x6000,
phy_init, data, phy, 0xf000, 0x1000,
factory, app, factory, 0x10000, 1M,
......@@ -50,6 +50,7 @@ env.Prepend(
CPPPATH=[
join(FRAMEWORK_DIR, "tools", "sdk", "include", "config"),
join(FRAMEWORK_DIR, "tools", "sdk", "include", "bluedroid"),
join(FRAMEWORK_DIR, "tools", "sdk", "include", "bt"),
join(FRAMEWORK_DIR, "tools", "sdk", "include", "driver"),
join(FRAMEWORK_DIR, "tools", "sdk", "include", "esp32"),
......@@ -58,6 +59,8 @@ env.Prepend(
join(FRAMEWORK_DIR, "tools", "sdk", "include", "freertos"),
join(FRAMEWORK_DIR, "tools", "sdk", "include", "log"),
join(FRAMEWORK_DIR, "tools", "sdk", "include", "mdns"),
join(FRAMEWORK_DIR, "tools", "sdk", "include", "mbedtls"),
join(FRAMEWORK_DIR, "tools", "sdk", "include", "mbedtls_port"),
join(FRAMEWORK_DIR, "tools", "sdk", "include", "vfs"),
join(FRAMEWORK_DIR, "tools", "sdk", "include", "ulp"),
join(FRAMEWORK_DIR, "tools", "sdk", "include", "newlib"),
......@@ -68,27 +71,21 @@ env.Prepend(
join(FRAMEWORK_DIR, "tools", "sdk", "include", "app_update"),
join(FRAMEWORK_DIR, "tools", "sdk", "include", "tcpip_adapter"),
join(FRAMEWORK_DIR, "tools", "sdk", "include", "xtensa-debug-module"),
join(FRAMEWORK_DIR, "tools", "sdk", "include", "newlib"),
join(FRAMEWORK_DIR, "tools", "sdk", "include", "coap"),
join(FRAMEWORK_DIR, "tools", "sdk", "include", "wpa_supplicant"),
join(FRAMEWORK_DIR, "tools", "sdk", "include", "expat"),
join(FRAMEWORK_DIR, "tools", "sdk", "include", "json"),
join(FRAMEWORK_DIR, "tools", "sdk", "include", "mbedtls"),
join(FRAMEWORK_DIR, "tools", "sdk", "include", "nghttp"),
join(FRAMEWORK_DIR, "tools", "sdk", "include", "lwip"),
join(FRAMEWORK_DIR, "cores", env.BoardConfig().get("build.core"))
],
LIBPATH=[
join(FRAMEWORK_DIR, "tools", "sdk", "lib"),
join(FRAMEWORK_DIR, "tools", "sdk", "ld"),
join(FRAMEWORK_DIR, "tools", "sdk", "ld")
],
LIBS=[
"app_update", "bootloader_support", "bt", "btdm_app", "c",
"c_nano", "coap", "coexist", "core", "cxx", "driver", "esp32",
"ethernet", "expat", "fatfs", "freertos", "hal", "json", "log",
"lwip", "m", "mbedtls", "mdns", "micro-ecc", "net80211", "newlib",
"nghttp", "nvs_flash", "openssl", "phy", "pp", "rtc", "sdmmc",
"smartconfig", "spi_flash", "tcpip_adapter", "ulp", "vfs", "wpa",
"wpa2", "wpa_supplicant", "wps", "xtensa-debug-module", "gcc", "stdc++"
"gcc", "stdc++", "app_update", "bootloader_support", "bt", "btdm_app", "c", "c_nano", "coap", "coexist", "core", "cxx", "driver", "esp32", "ethernet", "expat", "fatfs", "freertos", "hal", "json", "log", "lwip", "m", "mbedtls", "mdns", "micro-ecc", "net80211", "newlib", "nghttp", "nvs_flash", "openssl", "phy", "pp", "rtc", "sdmmc", "smartconfig", "spi_flash", "tcpip_adapter", "ulp", "vfs", "wpa", "wpa2", "wpa_supplicant", "wps", "xtensa-debug-module"
]
)
......
/*
---------------------------------------------------------------------------
Copyright (c) 1998-2008, Brian Gladman, Worcester, UK. All rights reserved.
LICENSE TERMS
The redistribution and use of this software (with or without changes)
is allowed without the payment of fees or royalties provided that:
1. source code distributions include the above copyright notice, this
list of conditions and the following disclaimer;
2. binary distributions include the above copyright notice, this list
of conditions and the following disclaimer in their documentation;
3. the name of the copyright holder is not used to endorse products
built using this software without specific written permission.
DISCLAIMER
This software is provided 'as is' with no explicit or implied warranties
in respect of its properties, including, but not limited to, correctness
and/or fitness for purpose.
---------------------------------------------------------------------------
Issue 09/09/2006
This is an AES implementation that uses only 8-bit byte operations on the
cipher state.
*/
#ifndef AES_H
#define AES_H
#if 1
# define AES_ENC_PREKEYED /* AES encryption with a precomputed key schedule */
#endif
#if 1
# define AES_DEC_PREKEYED /* AES decryption with a precomputed key schedule */
#endif
#if 1
# define AES_ENC_128_OTFK /* AES encryption with 'on the fly' 128 bit keying */
#endif
#if 1
# define AES_DEC_128_OTFK /* AES decryption with 'on the fly' 128 bit keying */
#endif
#if 1
# define AES_ENC_256_OTFK /* AES encryption with 'on the fly' 256 bit keying */
#endif
#if 1
# define AES_DEC_256_OTFK /* AES decryption with 'on the fly' 256 bit keying */
#endif
#define N_ROW 4
#define N_COL 4
#define N_BLOCK (N_ROW * N_COL)
#define N_MAX_ROUNDS 14
typedef unsigned char uint_8t;
typedef uint_8t return_type;
/* Warning: The key length for 256 bit keys overflows a byte
(see comment below)
*/
typedef uint_8t length_type;
typedef struct {
uint_8t ksch[(N_MAX_ROUNDS + 1) * N_BLOCK];
uint_8t rnd;
} aes_context;
/* The following calls are for a precomputed key schedule
NOTE: If the length_type used for the key length is an
unsigned 8-bit character, a key length of 256 bits must
be entered as a length in bytes (valid inputs are hence
128, 192, 16, 24 and 32).
*/
#if defined( AES_ENC_PREKEYED ) || defined( AES_DEC_PREKEYED )
return_type aes_set_key( const unsigned char key[],
length_type keylen,
aes_context ctx[1] );
#endif
#if defined( AES_ENC_PREKEYED )
return_type bluedroid_aes_encrypt( const unsigned char in[N_BLOCK],
unsigned char out[N_BLOCK],
const aes_context ctx[1] );
return_type aes_cbc_encrypt( const unsigned char *in,
unsigned char *out,
int n_block,
unsigned char iv[N_BLOCK],
const aes_context ctx[1] );
#endif
#if defined( AES_DEC_PREKEYED )
return_type bluedroid_aes_decrypt( const unsigned char in[N_BLOCK],
unsigned char out[N_BLOCK],
const aes_context ctx[1] );
return_type aes_cbc_decrypt( const unsigned char *in,
unsigned char *out,
int n_block,
unsigned char iv[N_BLOCK],
const aes_context ctx[1] );
#endif
/* The following calls are for 'on the fly' keying. In this case the
encryption and decryption keys are different.
The encryption subroutines take a key in an array of bytes in
key[L] where L is 16, 24 or 32 bytes for key lengths of 128,
192, and 256 bits respectively. They then encrypts the input
data, in[] with this key and put the reult in the output array
out[]. In addition, the second key array, o_key[L], is used
to output the key that is needed by the decryption subroutine
to reverse the encryption operation. The two key arrays can
be the same array but in this case the original key will be
overwritten.
In the same way, the decryption subroutines output keys that
can be used to reverse their effect when used for encryption.
Only 128 and 256 bit keys are supported in these 'on the fly'
modes.
*/
#if defined( AES_ENC_128_OTFK )
void bluedroid_aes_encrypt_128( const unsigned char in[N_BLOCK],
unsigned char out[N_BLOCK],
const unsigned char key[N_BLOCK],
uint_8t o_key[N_BLOCK] );
#endif
#if defined( AES_DEC_128_OTFK )
void bluedroid_aes_decrypt_128( const unsigned char in[N_BLOCK],
unsigned char out[N_BLOCK],
const unsigned char key[N_BLOCK],
unsigned char o_key[N_BLOCK] );
#endif
#if defined( AES_ENC_256_OTFK )
void bluedroid_aes_encrypt_256( const unsigned char in[N_BLOCK],
unsigned char out[N_BLOCK],
const unsigned char key[2 * N_BLOCK],
unsigned char o_key[2 * N_BLOCK] );
#endif
#if defined( AES_DEC_256_OTFK )
void bluedroid_aes_decrypt_256( const unsigned char in[N_BLOCK],
unsigned char out[N_BLOCK],
const unsigned char key[2 * N_BLOCK],
unsigned char o_key[2 * N_BLOCK] );
#endif
#endif
/******************************************************************************
*
* Copyright (C) 2014 Google, Inc.
*
* 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 _ALARM_H_
#define _ALARM_H_
#include <stdint.h>
#include <freertos/FreeRTOS.h>
#include <freertos/timers.h>
typedef uint32_t period_ms_t;
typedef void (*osi_alarm_callback_t)(void *data);
#define ALARM_CBS_NUM 20
#define ALARM_ID_BASE 1000
typedef struct alarm_t {
/* timer id point to here */
TimerHandle_t alarm_hdl;
osi_alarm_callback_t cb;
void *cb_data;
} osi_alarm_t;
void osi_alarm_init(void);
// Creates a new alarm object. The returned object must be freed by calling
// |alarm_free|. Returns NULL on failure.
osi_alarm_t *osi_alarm_new(char *alarm_name, osi_alarm_callback_t callback, void *data, period_ms_t timer_expire);
// Frees an alarm object created by |alarm_new|. |alarm| may be NULL. If the
// alarm is pending, it will be cancelled. It is not safe to call |alarm_free|
// from inside the callback of |alarm|.
int osi_alarm_free(osi_alarm_t *alarm);
// Sets an alarm to fire |cb| after the given |deadline|. Note that |deadline| is the
// number of milliseconds relative to the current time. |data| is a context variable
// for the callback and may be NULL. |cb| will be called back in the context of an
// unspecified thread (i.e. it will not be called back in the same thread as the caller).
// |alarm| and |cb| may not be NULL.
int osi_alarm_set(osi_alarm_t *alarm, period_ms_t timeout);
// This function cancels the |alarm| if it was previously set. When this call
// returns, the caller has a guarantee that the callback is not in progress and
// will not be called if it hasn't already been called. This function is idempotent.
// |alarm| may not be NULL.
int osi_alarm_cancel(osi_alarm_t *alarm);
period_ms_t osi_alarm_now(void);
// Figure out how much time until next expiration.
// Returns 0 if not armed. |alarm| may not be NULL.
// TODO: Remove this function once PM timers can be re-factored
period_ms_t osi_alarm_get_remaining_ms(const osi_alarm_t *alarm);
// Alarm-related state cleanup
//void alarm_cleanup(void);
// Compute time difference (t1-t2) considering tick counter wrap
// t1 and t2 should be no greater than the time of MAX ticks
period_ms_t osi_alarm_time_diff(period_ms_t t1, period_ms_t t2);
#endif /*_ALARM_H_*/
/******************************************************************************
*
* Copyright (C) 2014 Google, Inc.
*
* 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 _ALLOCATOR_H_
#define _ALLOCATOR_H_
#include <stddef.h>
//#include <stdlib.h>
typedef void *(*alloc_fn)(size_t size);
typedef void (*free_fn)(void *ptr);
typedef struct {
alloc_fn alloc;
free_fn free;
} allocator_t;
// allocator_t abstractions for the osi_*alloc and osi_free functions
extern const allocator_t allocator_malloc;
extern const allocator_t allocator_calloc;
char *osi_strdup(const char *str);
void *osi_malloc_func(size_t size);
void *osi_calloc_func(size_t size);
void osi_free_func(void *ptr);
#ifdef CONFIG_BLUEDROID_MEM_DEBUG
void osi_mem_dbg_init(void);
void osi_mem_dbg_record(void *p, int size, const char *func, int line);
void osi_mem_dbg_clean(void *p, const char *func, int line);
void osi_mem_dbg_show(void);
#define osi_malloc(size) \
({ \
void *p; \
\
p = calloc(1, (size)); \
osi_mem_dbg_record(p, size, __func__, __LINE__); \
(void *)p; \
})
#define osi_calloc(size) \
({ \
void *p; \
\
p = calloc(1, (size)); \
osi_mem_dbg_record(p, size, __func__, __LINE__); \
(void *)p; \
})
#define osi_free(ptr) \
({ \
osi_mem_dbg_clean(ptr, __func__, __LINE__); \
free((ptr)); \
})
#else
#define osi_malloc(size) calloc(1, (size))
#define osi_calloc(size) calloc(1, (size))
#define osi_free(p) free((p))
#endif /* CONFIG_BLUEDROID_MEM_DEBUG */
#endif /* _ALLOCATOR_H_ */
/******************************************************************************
*
* Copyright (C) 2003-2012 Broadcom Corporation
*
* 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 interface file contains the interface to the Audio Video Control
* Transport Protocol (AVCTP).
*
******************************************************************************/
#ifndef AVCT_API_H
#define AVCT_API_H
#include "bt_types.h"
#include "bt_target.h"
/*****************************************************************************
** Constants
*****************************************************************************/
/* API function return value result codes. */
#define AVCT_SUCCESS 0 /* Function successful */
#define AVCT_NO_RESOURCES 1 /* Not enough resources */
#define AVCT_BAD_HANDLE 2 /* Bad handle */
#define AVCT_PID_IN_USE 3 /* PID already in use */
#define AVCT_NOT_OPEN 4 /* Connection not open */
/* PSM for AVCT. */
#define AVCT_PSM 0x0017
#define AVCT_BR_PSM 0x001B
/* Protocol revision numbers */
#define AVCT_REV_1_0 0x0100
#define AVCT_REV_1_2 0x0102
#define AVCT_REV_1_3 0x0103
#define AVCT_REV_1_4 0x0104
/* the layer_specific settings */
#define AVCT_DATA_CTRL 0x0001 /* for the control channel */
#define AVCT_DATA_BROWSE 0x0002 /* for the browsing channel */
#define AVCT_DATA_PARTIAL 0x0100 /* Only have room for a partial message */
#define AVCT_MIN_CONTROL_MTU 48 /* Per the AVRC spec, minimum MTU for the control channel */
#define AVCT_MIN_BROWSE_MTU 335 /* Per the AVRC spec, minimum MTU for the browsing channel */
/* Message offset. The number of bytes needed by the protocol stack for the
** protocol headers of an AVCTP message packet.
*/
#define AVCT_MSG_OFFSET 15
#define AVCT_BROWSE_OFFSET 17 /* the default offset for browsing channel */
/* Connection role. */
#define AVCT_INT 0 /* Initiator connection */
#define AVCT_ACP 1 /* Acceptor connection */
/* Control role. */
#define AVCT_TARGET 1 /* target */
#define AVCT_CONTROL 2 /* controller */
#define AVCT_PASSIVE 4 /* If conflict, allow the other side to succeed */
/* Command/Response indicator. */
#define AVCT_CMD 0 /* Command message */
#define AVCT_RSP 2 /* Response message */
#define AVCT_REJ 3 /* Message rejected */
/* Control callback events. */
#define AVCT_CONNECT_CFM_EVT 0 /* Connection confirm */
#define AVCT_CONNECT_IND_EVT 1 /* Connection indication */
#define AVCT_DISCONNECT_CFM_EVT 2 /* Disconnect confirm */
#define AVCT_DISCONNECT_IND_EVT 3 /* Disconnect indication */
#define AVCT_CONG_IND_EVT 4 /* Congestion indication */
#define AVCT_UNCONG_IND_EVT 5 /* Uncongestion indication */
#define AVCT_BROWSE_CONN_CFM_EVT 6 /* Browse Connection confirm */
#define AVCT_BROWSE_CONN_IND_EVT 7 /* Browse Connection indication */
#define AVCT_BROWSE_DISCONN_CFM_EVT 8 /* Browse Disconnect confirm */
#define AVCT_BROWSE_DISCONN_IND_EVT 9 /* Browse Disconnect indication */
#define AVCT_BROWSE_CONG_IND_EVT 10 /* Congestion indication */
#define AVCT_BROWSE_UNCONG_IND_EVT 11 /* Uncongestion indication */
/* General purpose failure result code for callback events. */
#define AVCT_RESULT_FAIL 5
/*****************************************************************************
** Type Definitions
*****************************************************************************/
/* Control callback function. */
typedef void (tAVCT_CTRL_CBACK)(UINT8 handle, UINT8 event, UINT16 result,
BD_ADDR peer_addr);
/* Message callback function */
/* p_pkt->layer_specific is AVCT_DATA_CTRL or AVCT_DATA_BROWSE */
typedef void (tAVCT_MSG_CBACK)(UINT8 handle, UINT8 label, UINT8 cr,
BT_HDR *p_pkt);
/* Structure used by AVCT_CreateConn. */
typedef struct {
tAVCT_CTRL_CBACK *p_ctrl_cback; /* Control callback */
tAVCT_MSG_CBACK *p_msg_cback; /* Message callback */
UINT16 pid; /* Profile ID */
UINT8 role; /* Initiator/acceptor role */
UINT8 control; /* Control role (Control/Target) */
} tAVCT_CC;
/*****************************************************************************
** External Function Declarations
*****************************************************************************/
#ifdef __cplusplus
extern "C"
{
#endif
/*******************************************************************************
**
** Function AVCT_Register
**
** Description This is the system level registration function for the
** AVCTP protocol. This function initializes AVCTP and
** prepares the protocol stack for its use. This function
** must be called once by the system or platform using AVCTP
** before the other functions of the API an be used.
**
**
** Returns void
**
*******************************************************************************/
extern void AVCT_Register(UINT16 mtu, UINT16 mtu_br, UINT8 sec_mask);
/*******************************************************************************
**
** Function AVCT_Deregister
**
** Description This function is called to deregister use AVCTP protocol.
** It is called when AVCTP is no longer being used by any
** application in the system. Before this function can be
** called, all connections must be removed with
** AVCT_RemoveConn().
**
**
** Returns void
**
*******************************************************************************/
extern void AVCT_Deregister(void);
/*******************************************************************************
**
** Function AVCT_CreateConn
**
** Description Create an AVCTP connection. There are two types of
** connections, initiator and acceptor, as determined by
** the p_cc->role parameter. When this function is called to
** create an initiator connection, an AVCTP connection to
** the peer device is initiated if one does not already exist.
** If an acceptor connection is created, the connection waits
** passively for an incoming AVCTP connection from a peer device.
**
**
** Returns AVCT_SUCCESS if successful, otherwise error.
**
*******************************************************************************/
extern UINT16 AVCT_CreateConn(UINT8 *p_handle, tAVCT_CC *p_cc,
BD_ADDR peer_addr);
/*******************************************************************************
**
** Function AVCT_RemoveConn
**
** Description Remove an AVCTP connection. This function is called when
** the application is no longer using a connection. If this
** is the last connection to a peer the L2CAP channel for AVCTP
** will be closed.
**
**
** Returns AVCT_SUCCESS if successful, otherwise error.
**
*******************************************************************************/
extern UINT16 AVCT_RemoveConn(UINT8 handle);
/*******************************************************************************
**
** Function AVCT_CreateBrowse
**
** Description Create an AVCTP connection. There are two types of
** connections, initiator and acceptor, as determined by
** the p_cc->role parameter. When this function is called to
** create an initiator connection, an AVCTP connection to
** the peer device is initiated if one does not already exist.
** If an acceptor connection is created, the connection waits
** passively for an incoming AVCTP connection from a peer device.
**
**
** Returns AVCT_SUCCESS if successful, otherwise error.
**
*******************************************************************************/
extern UINT16 AVCT_CreateBrowse(UINT8 handle, UINT8 role);
/*******************************************************************************
**
** Function AVCT_RemoveBrowse
**
** Description Remove an AVCTP connection. This function is called when
** the application is no longer using a connection. If this
** is the last connection to a peer the L2CAP channel for AVCTP
** will be closed.
**
**
** Returns AVCT_SUCCESS if successful, otherwise error.
**
*******************************************************************************/
extern UINT16 AVCT_RemoveBrowse(UINT8 handle);
/*******************************************************************************
**
** Function AVCT_GetBrowseMtu
**
** Description Get the peer_mtu for the AVCTP Browse channel of the given
** connection.
**
** Returns the peer browsing channel MTU.
**
*******************************************************************************/
extern UINT16 AVCT_GetBrowseMtu (UINT8 handle);
/*******************************************************************************
**
** Function AVCT_GetPeerMtu
**
** Description Get the peer_mtu for the AVCTP channel of the given
** connection.
**
** Returns the peer MTU size.
**
*******************************************************************************/
extern UINT16 AVCT_GetPeerMtu (UINT8 handle);
/*******************************************************************************
**
** Function AVCT_MsgReq
**
** Description Send an AVCTP message to a peer device. In calling
** AVCT_MsgReq(), the application should keep track of the
** congestion state of AVCTP as communicated with events
** AVCT_CONG_IND_EVT and AVCT_UNCONG_IND_EVT. If the
** application calls AVCT_MsgReq() when AVCTP is congested
** the message may be discarded. The application may make its
** first call to AVCT_MsgReq() after it receives an
** AVCT_CONNECT_CFM_EVT or AVCT_CONNECT_IND_EVT on control channel or
** AVCT_BROWSE_CONN_CFM_EVT or AVCT_BROWSE_CONN_IND_EVT on browsing channel.
**
** p_msg->layer_specific must be set to
** AVCT_DATA_CTRL for control channel traffic;
** AVCT_DATA_BROWSE for for browse channel traffic.
**
** Returns AVCT_SUCCESS if successful, otherwise error.
**
*******************************************************************************/
extern UINT16 AVCT_MsgReq(UINT8 handle, UINT8 label, UINT8 cr, BT_HDR *p_msg);
#ifdef __cplusplus
}
#endif
#endif /* AVCT_API_H */
此差异已折叠。
/******************************************************************************
*
* Copyright (C) 2002-2012 Broadcom Corporation
*
* 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 contains constants definitions and other information from the AVDTP
* specification. This file is intended for use internal to AVDT only.
*
******************************************************************************/
#ifndef AVDT_DEFS_H
#define AVDT_DEFS_H
/*****************************************************************************
** constants
*****************************************************************************/
/* signalling packet type */
#define AVDT_PKT_TYPE_SINGLE 0 /* single packet */
#define AVDT_PKT_TYPE_START 1 /* start packet */
#define AVDT_PKT_TYPE_CONT 2 /* continue packet */
#define AVDT_PKT_TYPE_END 3 /* end packet */
/* signalling message type */
#define AVDT_MSG_TYPE_CMD 0 /* command */
#define AVDT_MSG_TYPE_GRJ 1 /* general reject */
#define AVDT_MSG_TYPE_RSP 2 /* response accept */
#define AVDT_MSG_TYPE_REJ 3 /* response reject */
/* signalling messages */
#define AVDT_SIG_DISCOVER 1 /* discover */
#define AVDT_SIG_GETCAP 2 /* get capabilities */
#define AVDT_SIG_SETCONFIG 3 /* set configuration */
#define AVDT_SIG_GETCONFIG 4 /* get configuration */
#define AVDT_SIG_RECONFIG 5 /* reconfigure */
#define AVDT_SIG_OPEN 6 /* open */
#define AVDT_SIG_START 7 /* start */
#define AVDT_SIG_CLOSE 8 /* close */
#define AVDT_SIG_SUSPEND 9 /* suspend */
#define AVDT_SIG_ABORT 10 /* abort */
#define AVDT_SIG_SECURITY 11 /* security control */
#define AVDT_SIG_GET_ALLCAP 12 /* get all capabilities */
#define AVDT_SIG_DELAY_RPT 13 /* delay report */
/* maximum signal value */
#define AVDT_SIG_MAX AVDT_SIG_DELAY_RPT
/* used for general reject */
#define AVDT_SIG_NONE 0
/* some maximum and minimum sizes of signalling messages */
#define AVDT_DISCOVER_REQ_MIN 1
#define AVDT_DISCOVER_REQ_MAX 124
/* service category information element field values */
#define AVDT_CAT_TRANS 1 /* Media Transport */
#define AVDT_CAT_REPORT 2 /* Reporting */
#define AVDT_CAT_RECOV 3 /* Recovery */
#define AVDT_CAT_PROTECT 4 /* Content Protection */
#define AVDT_CAT_HDRCMP 5 /* Header Compression */
#define AVDT_CAT_MUX 6 /* Multiplexing */
#define AVDT_CAT_CODEC 7 /* Media Codec */
#define AVDT_CAT_DELAY_RPT 8 /* Delay Reporting */
#define AVDT_CAT_MAX_CUR AVDT_CAT_DELAY_RPT
/* min/max lengths of service category information elements */
#define AVDT_LEN_TRANS_MIN 0
#define AVDT_LEN_REPORT_MIN 0
#define AVDT_LEN_RECOV_MIN 3
#define AVDT_LEN_PROTECT_MIN 2
#define AVDT_LEN_HDRCMP_MIN 1
#define AVDT_LEN_MUX_MIN 3
#define AVDT_LEN_CODEC_MIN 2
#define AVDT_LEN_DELAY_RPT_MIN 0
#define AVDT_LEN_TRANS_MAX 0
#define AVDT_LEN_REPORT_MAX 0
#define AVDT_LEN_RECOV_MAX 3
#define AVDT_LEN_PROTECT_MAX 255
#define AVDT_LEN_HDRCMP_MAX 1
#define AVDT_LEN_MUX_MAX 7
#define AVDT_LEN_CODEC_MAX 255
#define AVDT_LEN_DELAY_RPT_MAX 0
/* minimum possible size of configuration or capabilities data */
#define AVDT_LEN_CFG_MIN 2
/* minimum and maximum lengths for different message types */
#define AVDT_LEN_SINGLE 1
#define AVDT_LEN_SETCONFIG_MIN 2
#define AVDT_LEN_RECONFIG_MIN 1
#define AVDT_LEN_MULTI_MIN 1
#define AVDT_LEN_SECURITY_MIN 1
#define AVDT_LEN_DELAY_RPT 3
/* header lengths for different packet types */
#define AVDT_LEN_TYPE_SINGLE 2 /* single packet */
#define AVDT_LEN_TYPE_START 3 /* start packet */
#define AVDT_LEN_TYPE_CONT 1 /* continue packet */
#define AVDT_LEN_TYPE_END 1 /* end packet */
/* length of general reject message */
#define AVDT_LEN_GEN_REJ 2
/* recovery service capabilities information elements */
#define AVDT_RECOV_MRWS_MIN 0x01 /* min value for maximum recovery window */
#define AVDT_RECOV_MRWS_MAX 0x18 /* max value for maximum recovery window */
#define AVDT_RECOV_MNMP_MIN 0x01 /* min value for maximum number of media packets */
#define AVDT_RECOV_MNMP_MAX 0x18 /* max value for maximum number of media packets */
/* SEID value range */
#define AVDT_SEID_MIN 0x01
#define AVDT_SEID_MAX 0x3E
/* first byte of media packet header */
#define AVDT_MEDIA_OCTET1 0x80
/* for adaptation layer header */
#define AVDT_ALH_LCODE_MASK 0x03 /* coding of length field */
#define AVDT_ALH_LCODE_NONE 0x00 /* No length field present. Take length from l2cap */
#define AVDT_ALH_LCODE_16BIT 0x01 /* 16bit length field */
#define AVDT_ALH_LCODE_9BITM0 0x02 /* 9 bit length field, MSB = 0, 8 LSBs in 1 octet following */
#define AVDT_ALH_LCODE_9BITM1 0x03 /* 9 bit length field, MSB = 1, 8 LSBs in 1 octet following */
#define AVDT_ALH_FRAG_MASK 0x04 /* set this for continuation packet */
/*****************************************************************************
** message parsing and building macros
*****************************************************************************/
#define AVDT_MSG_PRS_HDR(p, lbl, pkt, msg) \
lbl = *(p) >> 4; \
pkt = (*(p) >> 2) & 0x03; \
msg = *(p)++ & 0x03;
#define AVDT_MSG_PRS_DISC(p, seid, in_use, type, tsep) \
seid = *(p) >> 2; \
in_use = (*(p)++ >> 1) & 0x01; \
type = *(p) >> 4; \
tsep = (*(p)++ >> 3) & 0x01;
#define AVDT_MSG_PRS_SIG(p, sig) \
sig = *(p)++ & 0x3F;
#define AVDT_MSG_PRS_SEID(p, seid) \
seid = *(p)++ >> 2;
#define AVDT_MSG_PRS_PKT_TYPE(p, pkt) \
pkt = (*(p) >> 2) & 0x03;
#define AVDT_MSG_PRS_OCTET1(p, o_v, o_p, o_x, o_cc) \
o_v = *(p) >> 6; \
o_p = (*(p) >> 5) & 0x01; \
o_x = (*(p) >> 4) & 0x01; \
o_cc = *(p)++ & 0x0F;
#define AVDT_MSG_PRS_RPT_OCTET1(p, o_v, o_p, o_cc) \
o_v = *(p) >> 6; \
o_p = (*(p) >> 5) & 0x01; \
o_cc = *(p)++ & 0x1F;
#define AVDT_MSG_PRS_M_PT(p, m_pt, marker) \
marker = *(p) >> 7; \
m_pt = *(p)++ & 0x7F;
#define AVDT_MSG_BLD_HDR(p, lbl, pkt, msg) \
*(p)++ = (UINT8) ((lbl) << 4) | ((pkt) << 2) | (msg);
#define AVDT_MSG_BLD_DISC(p, seid, in_use, type, tsep) \
*(p)++ = (UINT8) (((seid) << 2) | ((in_use) << 1)); \
*(p)++ = (UINT8) (((type) << 4) | ((tsep) << 3));
#define AVDT_MSG_BLD_SIG(p, sig) \
*(p)++ = (UINT8) (sig);
#define AVDT_MSG_BLD_SEID(p, seid) \
*(p)++ = (UINT8) ((seid) << 2);
#define AVDT_MSG_BLD_ERR(p, err) \
*(p)++ = (UINT8) (err);
#define AVDT_MSG_BLD_PARAM(p, param) \
*(p)++ = (UINT8) (param);
#define AVDT_MSG_BLD_NOSP(p, nosp) \
*(p)++ = (UINT8) (nosp);
#endif /* AVDT_DEFS_H */
/******************************************************************************
*
* Copyright (C) 2002-2012 Broadcom Corporation
*
* 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 interface file contains the interface AVDTP conformance API. These
* additional API functions and callback events are provided for
* conformance testing purposes only. They are not intended to be used by
* an application.
*
******************************************************************************/
#ifndef AVDT_CAPI_H
#define AVDT_CAPI_H
#include "avdt_api.h"
/* start AVDTC events here to distinguish from AVDT events */
#define AVDTC_EVT_BEGIN 0x80
#define AVDTC_DISCOVER_IND_EVT (0 + AVDTC_EVT_BEGIN) /* Discover indication */
#define AVDTC_GETCAP_IND_EVT (1 + AVDTC_EVT_BEGIN) /* Get capabilities indication */
#define AVDTC_SETCONFIG_CFM_EVT (2 + AVDTC_EVT_BEGIN) /* Set configuration confirm */
#define AVDTC_GETCONFIG_IND_EVT (3 + AVDTC_EVT_BEGIN) /* Get configuration indication */
#define AVDTC_GETCONFIG_CFM_EVT (4 + AVDTC_EVT_BEGIN) /* Get configuration confirm */
#define AVDTC_OPEN_IND_EVT (5 + AVDTC_EVT_BEGIN) /* Open indication */
#define AVDTC_START_IND_EVT (6 + AVDTC_EVT_BEGIN) /* Start indication */
#define AVDTC_CLOSE_IND_EVT (7 + AVDTC_EVT_BEGIN) /* Close indication */
#define AVDTC_SUSPEND_IND_EVT (8 + AVDTC_EVT_BEGIN) /* Suspend indication */
#define AVDTC_ABORT_IND_EVT (9 + AVDTC_EVT_BEGIN) /* Abort indication */
#define AVDTC_ABORT_CFM_EVT (10 + AVDTC_EVT_BEGIN) /* Abort confirm */
typedef struct {
tAVDT_EVT_HDR hdr; /* Event header */
UINT8 seid_list[AVDT_NUM_SEPS]; /* Array of SEID values */
UINT8 num_seps; /* Number of values in array */
} tAVDT_MULTI;
/* Union of all control callback event data structures */
typedef union {
tAVDT_EVT_HDR hdr;
tAVDT_CONFIG getconfig_cfm;
tAVDT_MULTI start_ind;
tAVDT_MULTI suspend_ind;
} tAVDTC_CTRL;
typedef void tAVDTC_CTRL_CBACK(UINT8 handle, BD_ADDR bd_addr, UINT8 event, tAVDTC_CTRL *p_data);
#ifdef __cplusplus
extern "C"
{
#endif
/*******************************************************************************
**
** Function AVDTC_Init
**
** Description This function is called to begin using the conformance API.
** It must be called after AVDT_Register() and before any
** other API or conformance API functions are called.
**
** Returns void
**
*******************************************************************************/
extern void AVDTC_Init(tAVDTC_CTRL_CBACK *p_cback);
/*******************************************************************************
**
** Function AVDTC_DiscoverRsp
**
** Description Send a discover response.
**
** Returns void
**
*******************************************************************************/
extern void AVDTC_DiscoverRsp(BD_ADDR bd_addr, UINT8 label,
tAVDT_SEP_INFO sep_info[], UINT8 num_seps);
/*******************************************************************************
**
** Function AVDTC_GetCapRsp
**
** Description Send a get capabilities response.
**
** Returns void
**
*******************************************************************************/
extern void AVDTC_GetCapRsp(BD_ADDR bd_addr, UINT8 label, tAVDT_CFG *p_cap);
/*******************************************************************************
**
** Function AVDTC_GetAllCapRsp
**
** Description Send a get all capabilities response.
**
** Returns void
**
*******************************************************************************/
extern void AVDTC_GetAllCapRsp(BD_ADDR bd_addr, UINT8 label, tAVDT_CFG *p_cap);
/*******************************************************************************
**
** Function AVDTC_GetConfigReq
**
** Description Send a get configuration request.
**
** Returns void
**
*******************************************************************************/
extern void AVDTC_GetConfigReq(UINT8 handle);
/*******************************************************************************
**
** Function AVDTC_GetConfigRsp
**
** Description Send a get configuration response.
**
** Returns void
**
*******************************************************************************/
extern void AVDTC_GetConfigRsp(UINT8 handle, UINT8 label, tAVDT_CFG *p_cfg);
/*******************************************************************************
**
** Function AVDTC_OpenReq
**
** Description Send an open request.
**
** Returns void
**
*******************************************************************************/
extern void AVDTC_OpenReq(UINT8 handle);
/*******************************************************************************
**
** Function AVDTC_OpenRsp
**
** Description Send an open response.
**
** Returns void
**
*******************************************************************************/
extern void AVDTC_OpenRsp(UINT8 handle, UINT8 label);
/*******************************************************************************
**
** Function AVDTC_StartRsp
**
** Description Send a start response.
**
** Returns void
**
*******************************************************************************/
extern void AVDTC_StartRsp(UINT8 *p_handles, UINT8 num_handles, UINT8 label);
/*******************************************************************************
**
** Function AVDTC_CloseRsp
**
** Description Send a close response.
**
** Returns void
**
*******************************************************************************/
extern void AVDTC_CloseRsp(UINT8 handle, UINT8 label);
/*******************************************************************************
**
** Function AVDTC_SuspendRsp
**
** Description Send a suspend response.
**
** Returns void
**
*******************************************************************************/
extern void AVDTC_SuspendRsp(UINT8 *p_handles, UINT8 num_handles, UINT8 label);
/*******************************************************************************
**
** Function AVDTC_AbortReq
**
** Description Send an abort request.
**
** Returns void
**
*******************************************************************************/
extern void AVDTC_AbortReq(UINT8 handle);
/*******************************************************************************
**
** Function AVDTC_AbortRsp
**
** Description Send an abort response.
**
** Returns void
**
*******************************************************************************/
extern void AVDTC_AbortRsp(UINT8 handle, UINT8 label);
/*******************************************************************************
**
** Function AVDTC_Rej
**
** Description Send a reject message.
**
** Returns void
**
*******************************************************************************/
extern void AVDTC_Rej(UINT8 handle, BD_ADDR bd_addr, UINT8 cmd, UINT8 label,
UINT8 err_code, UINT8 err_param);
#ifdef __cplusplus
}
#endif
#endif /* AVDT_CAPI_H */
此差异已折叠。
此差异已折叠。
/******************************************************************************
*
* Copyright (C) 2014 Google, Inc.
*
* 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 _BDADDR_H_
#define _BDADDR_H_
#include <stdbool.h>
#include <stddef.h>
#include "bt_defs.h"
#include "hash_map.h"
// Note: the string representation of a bdaddr is expected to have the format
// xx:xx:xx:xx:xx:xx
// where each 'x' is a hex digit. The API presented in this header will accept
// both uppercase and lowercase digits but will only ever produce lowercase
// digits.
// Returns true if |addr| is the empty address (00:00:00:00:00:00).
// |addr| may not be NULL.
bool bdaddr_is_empty(const bt_bdaddr_t *addr);
// Returns true if |first| and |second| refer to the same address. Neither
// may be NULL.
bool bdaddr_equals(const bt_bdaddr_t *first, const bt_bdaddr_t *second);
// Returns destination bdaddr |dest| after copying |src| to |dest|.
// |dest| and |src| must not be NULL.
bt_bdaddr_t *bdaddr_copy(bt_bdaddr_t *dest, const bt_bdaddr_t *src);
// Makes a string representation of |addr| and places it into |string|. |size|
// refers to the size of |string|'s buffer and must be >= 18. On success, this
// function returns |string|, otherwise it returns NULL. Neither |addr| nor |string|
// may be NULL.
const char *bdaddr_to_string(const bt_bdaddr_t *addr, char *string, size_t size);
// Returns true if |string| represents a Bluetooth address. |string| may not be NULL.
bool string_is_bdaddr(const char *string);
// Converts |string| to bt_bdaddr_t and places it in |addr|. If |string| does not
// represent a Bluetooth address, |addr| is not modified and this function returns
// false. Otherwise, it returns true. Neither |string| nor |addr| may be NULL.
bool string_to_bdaddr(const char *string, bt_bdaddr_t *addr);
// A hash function tailored for bdaddrs.
hash_index_t hash_function_bdaddr(const void *key);
#endif
// 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 __BLUFI_INT_H__
#define __BLUFI_INT_H__
#define BTC_BLUFI_GREAT_VER 0x01 //Version + Subversion
#define BTC_BLUFI_SUB_VER 0x00 //Version + Subversion
#define BTC_BLUFI_VERSION ((BTC_BLUFI_GREAT_VER<<8)|BTC_BLUFI_SUB_VER) //Version + Subversion
/* service engine control block */
typedef struct {
/* Protocol reference */
tGATT_IF gatt_if;
UINT8 srvc_inst;
UINT16 handle_srvc;
UINT16 handle_char_p2e;
UINT16 handle_char_e2p;
UINT16 handle_descr_e2p;
UINT16 conn_id;
BOOLEAN is_connected;
BD_ADDR remote_bda;
UINT32 trans_id;
UINT8 congest;
#define BLUFI_PREPAIR_BUF_MAX_SIZE 1024
uint8_t *prepare_buf;
int prepare_len;
/* Control reference */
esp_blufi_callbacks_t *cbs;
BOOLEAN enabled;
uint8_t send_seq;
uint8_t recv_seq;
uint8_t sec_mode;
uint8_t *aggr_buf;
uint16_t total_len;
uint16_t offset;
} tBLUFI_ENV;
/* BLUFI protocol */
struct blufi_hdr{
uint8_t type;
uint8_t fc;
uint8_t seq;
uint8_t data_len;
uint8_t data[0];
};
typedef struct blufi_hdr blufi_hd_t;
struct blufi_frag_hdr {
uint8_t type;
uint8_t fc;
uint8_t seq;
uint8_t data_len;
uint16_t total_len;
uint8_t content[0];
};
typedef struct blufi_frag_hdr blufi_frag_hdr_t;
#define BLUFI_DATA_SEC_MODE_CHECK_MASK 0x01
#define BLUFI_DATA_SEC_MODE_ENC_MASK 0x02
#define BLUFI_CTRL_SEC_MODE_CHECK_MASK 0x10
#define BLUFI_CTRL_SEC_MODE_ENC_MASK 0x20
// packet type
#define BLUFI_TYPE_MASK 0x03
#define BLUFI_TYPE_SHIFT 0
#define BLUFI_SUBTYPE_MASK 0xFC
#define BLUFI_SUBTYPE_SHIFT 2
#define BLUFI_GET_TYPE(type) ((type) & BLUFI_TYPE_MASK)
#define BLUFI_GET_SUBTYPE(type) (((type) & BLUFI_SUBTYPE_MASK) >>BLUFI_SUBTYPE_SHIFT)
#define BLUFI_BUILD_TYPE(type, subtype) (((type) & BLUFI_TYPE_MASK) | ((subtype)<<BLUFI_SUBTYPE_SHIFT))
#define BLUFI_TYPE_CTRL 0x0
#define BLUFI_TYPE_CTRL_SUBTYPE_ACK 0x00
#define BLUFI_TYPE_CTRL_SUBTYPE_SET_SEC_MODE 0x01
#define BLUFI_TYPE_CTRL_SUBTYPE_SET_WIFI_OPMODE 0x02
#define BLUFI_TYPE_CTRL_SUBTYPE_CONN_TO_AP 0x03
#define BLUFI_TYPE_CTRL_SUBTYPE_DISCONN_FROM_AP 0x04
#define BLUFI_TYPE_CTRL_SUBTYPE_GET_WIFI_STATUS 0x05
#define BLUFI_TYPE_CTRL_SUBTYPE_DEAUTHENTICATE_STA 0x06
#define BLUFI_TYPE_CTRL_SUBTYPE_GET_VERSION 0x07
#define BLUFI_TYPE_DATA 0x1
#define BLUFI_TYPE_DATA_SUBTYPE_NEG 0x00
#define BLUFI_TYPE_DATA_SUBTYPE_STA_BSSID 0x01
#define BLUFI_TYPE_DATA_SUBTYPE_STA_SSID 0x02
#define BLUFI_TYPE_DATA_SUBTYPE_STA_PASSWD 0x03
#define BLUFI_TYPE_DATA_SUBTYPE_SOFTAP_SSID 0x04
#define BLUFI_TYPE_DATA_SUBTYPE_SOFTAP_PASSWD 0x05
#define BLUFI_TYPE_DATA_SUBTYPE_SOFTAP_MAX_CONN_NUM 0x06
#define BLUFI_TYPE_DATA_SUBTYPE_SOFTAP_AUTH_MODE 0x07
#define BLUFI_TYPE_DATA_SUBTYPE_SOFTAP_CHANNEL 0x08
#define BLUFI_TYPE_DATA_SUBTYPE_USERNAME 0x09
#define BLUFI_TYPE_DATA_SUBTYPE_CA 0x0a
#define BLUFI_TYPE_DATA_SUBTYPE_CLIENT_CERT 0x0b
#define BLUFI_TYPE_DATA_SUBTYPE_SERVER_CERT 0x0c
#define BLUFI_TYPE_DATA_SUBTYPE_CLIENT_PRIV_KEY 0x0d
#define BLUFI_TYPE_DATA_SUBTYPE_SERVER_PRIV_KEY 0x0e
#define BLUFI_TYPE_DATA_SUBTYPE_WIFI_REP 0x0f
#define BLUFI_TYPE_DATA_SUBTYPE_REPLY_VERSION 0x10
#define BLUFI_TYPE_IS_CTRL(type) (BLUFI_GET_TYPE((type)) == BLUFI_TYPE_CTRL)
#define BLUFI_TYPE_IS_DATA(type) (BLUFI_GET_TYPE((type)) == BLUFI_TYPE_DATA)
#define BLUFI_TYPE_IS_CTRL_ACK(type) (BLUFI_TYPE_IS_CTRL((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_CTRL_SUBTYPE_ACK)
#define BLUFI_TYPE_IS_CTRL_START_NEG(type) (BLUFI_TYPE_IS_CTRL((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_CTRL_SUBTYPE_START_NEG)
#define BLUFI_TYPE_IS_CTRL_STOP_NEG(type) (BLUFI_TYPE_IS_CTRL((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_CTRL_SUBTYPE_STOP_NEG)
#define BLUFI_TYPE_IS_CTRL_SET_WIFI_OPMODE(type) (BLUFI_TYPE_IS_CTRL((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_CTRL_SUBTYPE_SET_WIFI_OPMODE)
#define BLUFI_TYPE_IS_CTRL_CONN_WIFI(type) (BLUFI_TYPE_IS_CTRL((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_CTRL_SUBTYPE_CONN_TO_AP)
#define BLUFI_TYPE_IS_CTRL_DISCONN_WIFI(type) (BLUFI_TYPE_IS_CTRL((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_CTRL_SUBTYPE_DISCONN_FROM_AP)
#define BLUFI_TYPE_IS_CTRL_GET_WIFI_STATUS(type) (BLUFI_TYPE_IS_CTRL((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_CTRL_SUBTYPE_GET_WIFI_STATUS)
#define BLUFI_TYPE_IS_CTRL_DEAUTHENTICATE_STA(type) (BLUFI_TYPE_IS_CTRL((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_CTRL_SUBTYPE_DEAUTHENTICATE_STA)
#define BLUFI_TYPE_IS_CTRL_GET_VERSION(type) (BLUFI_TYPE_IS_CTRL((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_CTRL_SUBTYPE_GET_VERSION)
#define BLUFI_TYPE_IS_DATA_NEG(type) (BLUFI_TYPE_IS_DATA((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_DATA_SUBTYPE_NEG)
#define BLUFI_TYPE_IS_DATA_STA_BSSID(type) (BLUFI_TYPE_IS_DATA((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_DATA_SUBTYPE_STA_BSSID)
#define BLUFI_TYPE_IS_DATA_STA_SSID(type) (BLUFI_TYPE_IS_DATA((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_DATA_SUBTYPE_STA_SSID)
#define BLUFI_TYPE_IS_DATA_STA_PASSWD(type) (BLUFI_TYPE_IS_DATA((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_DATA_SUBTYPE_STA_PASSWD)
#define BLUFI_TYPE_IS_DATA_SOFTAP_SSID(type) (BLUFI_TYPE_IS_DATA((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_DATA_SUBTYPE_SOFTAP_SSID)
#define BLUFI_TYPE_IS_DATA_SOFTAP_PASSWD(type) (BLUFI_TYPE_IS_DATA((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_DATA_SUBTYPE_SOFTAP_PASSWD)
#define BLUFI_TYPE_IS_DATA_SOFTAP_MAX_CONN_NUM(type) (BLUFI_TYPE_IS_DATA((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_DATA_SUBTYPE_SOFTAP_MAX_CONN_NUM)
#define BLUFI_TYPE_IS_DATA_SOFTAP_AUTH_MODE(type) (BLUFI_TYPE_IS_DATA((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_DATA_SUBTYPE_SOFTAP_AUTH_MODE)
#define BLUFI_TYPE_IS_DATA_SOFTAP_CHANNEL(type) (BLUFI_TYPE_IS_DATA((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_DATA_SUBTYPE_SOFTAP_CHANNEL)
#define BLUFI_TYPE_IS_DATA_USERNAME(type) (BLUFI_TYPE_IS_DATA((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_DATA_SUBTYPE_USERNAME)
#define BLUFI_TYPE_IS_DATA_CA(type) (BLUFI_TYPE_IS_DATA((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_DATA_SUBTYPE_CA)
#define BLUFI_TYPE_IS_DATA_CLEINT_CERT(type) (BLUFI_TYPE_IS_DATA((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_DATA_SUBTYPE_CLIENT_CERT)
#define BLUFI_TYPE_IS_DATA_SERVER_CERT(type) (BLUFI_TYPE_IS_DATA((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_DATA_SUBTYPE_SERVER_CERT)
#define BLUFI_TYPE_IS_DATA_CLIENT_PRIV_KEY(type) (BLUFI_TYPE_IS_DATA((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_DATA_SUBTYPE_CLIENT_PRIV_KEY)
#define BLUFI_TYPE_IS_DATA_SERVER_PRIV_KEY(type) (BLUFI_TYPE_IS_DATA((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_DATA_SUBTYPE_SERVER_PRIV_KEY)
// packet frame control
#define BLUFI_FC_ENC_MASK 0x01
#define BLUFI_FC_CHECK_MASK 0x02
#define BLUFI_FC_DIR_MASK 0x04
#define BLUFI_FC_REQ_ACK_MASK 0x08
#define BLUFI_FC_FRAG_MASK 0x10
#define BLUFI_FC_ENC 0x01
#define BLUFI_FC_CHECK 0x02
#define BLUFI_FC_DIR_P2E 0x00
#define BLUFI_FC_DIR_E2P 0x04
#define BLUFI_FC_REQ_ACK 0x08
#define BLUFI_FC_FRAG 0x10
#define BLUFI_FC_IS_ENC(fc) ((fc) & BLUFI_FC_ENC_MASK)
#define BLUFI_FC_IS_CHECK(fc) ((fc) & BLUFI_FC_CHECK_MASK)
#define BLUFI_FC_IS_DIR_P2E(fc) ((fc) & BLUFI_FC_DIR_P2E_MASK)
#define BLUFI_FC_IS_DIR_E2P(fc) (!((fc) & BLUFI_DIR_P2E_MASK))
#define BLUFI_FC_IS_REQ_ACK(fc) ((fc) & BLUFI_FC_REQ_ACK_MASK)
#define BLUFI_FC_IS_FRAG(fc) ((fc) & BLUFI_FC_FRAG_MASK)
#define BLUFI_FRAG_DATA_MAX_LEN 50
//function declare
void btc_blufi_protocol_handler(uint8_t type, uint8_t *data, int len);
void btc_blufi_send_encap(uint8_t type, uint8_t *data, int data_len);
void btc_blufi_set_callbacks(esp_blufi_callbacks_t *callbacks);
void btc_blufi_cb_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
void btc_blufi_cb_deep_free(btc_msg_t *msg);
#endif /* __BLUFI_INT_H__ */
// 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 _BT_COMMON_TYPES_H_
#define _BT_COMMON_TYPES_H_
#include "bt_defs.h"
#include "thread.h"
typedef void (* bluedroid_init_done_cb_t)(void);
typedef struct {
uint8_t client_if;
uint8_t filt_index;
uint8_t advertiser_state;
uint8_t advertiser_info_present;
uint8_t addr_type;
uint8_t tx_power;
int8_t rssi_value;
uint16_t time_stamp;
bt_bdaddr_t bd_addr;
uint8_t adv_pkt_len;
uint8_t *p_adv_pkt_data;
uint8_t scan_rsp_len;
uint8_t *p_scan_rsp_data;
} btgatt_track_adv_info_t;
#endif
// 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.
/**
* bt_defs.h Defines useful API for whole Bluedroid
*
*/
#ifndef _BT_DEFS_H_
#define _BT_DEFS_H_
#include <stdlib.h>
#include <stdint.h>
#include "bt_trace.h"
#include "osi_arch.h"
#define UNUSED(x) (void)(x)
#ifndef SIZE_MAX
#define SIZE_MAX 254
#endif
/*Timer Related Defination*/
#define alarm_timer_t uint32_t
#define alarm_timer_setfn(timer, cb, data) \
do { \
} while (0)
#define alarm_timer_arm(timer, to, periodic) \
do { \
} while (0)
#define alarm_timer_disarm(timer) \
do { \
} while (0)
#define alarm_timer_now() (0)
/*Thread and locker related defination*/
#define RTOS_SUPPORT
#ifdef RTOS_SUPPORT
#define pthread_mutex_t osi_mutex_t
#define pthread_mutex_init(mutex, a) osi_mutex_new(mutex)
#define pthread_mutex_destroy(mutex) osi_mutex_free(mutex)
#define pthread_mutex_lock osi_mutex_lock
#define pthread_mutex_unlock osi_mutex_unlock
#else
#define pthread_mutex_t uint8_t
#define pthread_mutex_init(x1, x2)
#define pthread_mutex_destroy(mutex)
#define pthread_mutex_lock(mutex)
#define pthread_mutex_unlock(mutex)
#endif
/*Bluetooth Address*/
typedef struct {
uint8_t address[6];
} __attribute__ ((__packed__)) bt_bdaddr_t;
/** Bluetooth 128-bit UUID */
typedef struct {
uint8_t uu[16];
} bt_uuid_t;
/** Bluetooth Error Status */
/** We need to build on this */
typedef enum {
BT_STATUS_SUCCESS,
BT_STATUS_FAIL,
BT_STATUS_NOT_READY,
BT_STATUS_NOMEM,
BT_STATUS_BUSY,
BT_STATUS_DONE, /* request already completed */
BT_STATUS_UNSUPPORTED,
BT_STATUS_PARM_INVALID,
BT_STATUS_UNHANDLED,
BT_STATUS_AUTH_FAILURE,
BT_STATUS_RMT_DEV_DOWN,
BT_STATUS_AUTH_REJECTED
} bt_status_t;
#ifndef CPU_LITTLE_ENDIAN
#define CPU_LITTLE_ENDIAN
#endif
inline uint16_t swap_byte_16(uint16_t x)
{
return (((x & 0x00ffU) << 8) |
((x & 0xff00U) >> 8));
}
inline uint32_t swap_byte_32(uint32_t x)
{
return (((x & 0x000000ffUL) << 24) |
((x & 0x0000ff00UL) << 8) |
((x & 0x00ff0000UL) >> 8) |
((x & 0xff000000UL) >> 24));
}
#ifndef ntohs
inline uint16_t ntohs(uint16_t x)
{
#ifdef CPU_LITTLE_ENDIAN
return swap_byte_16(x);
#else
return x;
#endif
}
#endif /* #ifndef ntohs */
#ifndef htons
inline uint16_t htons(uint16_t x)
{
#ifdef CPU_LITTLE_ENDIAN
return swap_byte_16(x);
#else
return x;
#endif
}
#endif /* #ifndef htons */
#ifndef ntohl
inline uint32_t ntohl(uint32_t x)
{
#ifdef CPU_LITTLE_ENDIAN
return swap_byte_32(x);
#else
return x;
#endif
}
#endif /* #ifndef ntohl*/
#ifndef htonl
inline uint32_t htonl(uint32_t x)
{
#ifdef CPU_LITTLE_ENDIAN
return swap_byte_32(x);
#else
return x;
#endif
}
#endif /* #ifndef htonl*/
#endif /* _BT_DEFS_H_ */
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
// 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 __BTC_BLUFI_PRF_H__
#define __BTC_BLUFI_PRF_H__
#include "bt_target.h"
#include "btc_task.h"
#include "esp_blufi_api.h"
typedef enum {
BTC_BLUFI_ACT_INIT = 0,
BTC_BLUFI_ACT_DEINIT,
BTC_BLUFI_ACT_SEND_CFG_REPORT,
} btc_blufi_act_t;
typedef union {
struct blufi_cfg_report {
wifi_mode_t opmode;
esp_blufi_sta_conn_state_t sta_conn_state;
uint8_t softap_conn_num;
esp_blufi_extra_info_t *extra_info;
int extra_info_len;
} wifi_conn_report;
} btc_blufi_args_t;
void btc_blufi_cb_handler(btc_msg_t *msg);
void btc_blufi_call_handler(btc_msg_t *msg);
void btc_blufi_set_callbacks(esp_blufi_callbacks_t *callbacks);
void btc_blufi_call_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
void btc_blufi_call_deep_free(btc_msg_t *msg);
uint16_t btc_blufi_get_version(void);
#endif /* __BTC_BLUFI_PRF_H__ */
此差异已折叠。
// 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 __BTC_GAP_BT_H__
#define __BTC_GAP_BT_H__
#define /* __BTC_GAP_BT_H__ */
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册