diff --git a/boards.txt b/boards.txt index 56b51a96..d53855a8 100644 --- a/boards.txt +++ b/boards.txt @@ -1,7 +1,9 @@ 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 diff --git a/cores/esp32/esp32-hal-log.h b/cores/esp32/esp32-hal-log.h index bd42b79b..0456fc0f 100644 --- a/cores/esp32/esp32-hal-log.h +++ b/cores/esp32/esp32-hal-log.h @@ -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, ...) diff --git a/libraries/WiFi/src/WiFiGeneric.cpp b/libraries/WiFi/src/WiFiGeneric.cpp index 1d85f688..b10933cd 100644 --- a/libraries/WiFi/src/WiFiGeneric.cpp +++ b/libraries/WiFi/src/WiFiGeneric.cpp @@ -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]) diff --git a/platform.txt b/platform.txt index d112108e..81045758 100644 --- a/platform.txt +++ b/platform.txt @@ -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" diff --git a/tools/esptool.py b/tools/esptool.py index 026d22ca..e311634f 100755 --- a/tools/esptool.py +++ b/tools/esptool.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# NB: Before sending a PR to change the above line to '#!/usr/bin/env python2', please read https://github.com/espressif/esptool/issues/21 # # ESP8266 & ESP32 ROM Bootloader Utility # Copyright (C) 2014-2016 Fredrik Ahlberg, Angus Gratton, Espressif Systems (Shanghai) PTE LTD, other contributors as noted. @@ -17,6 +16,8 @@ # this program; if not, write to the Free Software Foundation, Inc., 51 Franklin # Street, Fifth Floor, Boston, MA 02110-1301 USA. +from __future__ import print_function, division + import argparse import hashlib import inspect @@ -29,7 +30,7 @@ import base64 import zlib import shlex -__version__ = "2.0-dev" +__version__ = "2.0-beta1" MAX_UINT32 = 0xffffffff MAX_UINT24 = 0xffffff @@ -64,6 +65,18 @@ def stub_and_esp32_function_only(func): return check_supported_function(func, lambda o: o.IS_STUB or o.CHIP_NAME == "ESP32") +PYTHON2 = sys.version_info[0] < 3 # True if on pre-Python 3 + +# Function to return nth byte of a bitstring +# Different behaviour on Python 2 vs 3 +if PYTHON2: + def byte(bitstr, index): + return ord(bitstr[index]) +else: + def byte(bitstr, index): + return bitstr[index] + + def esp8266_function_only(func): """ Attribute for a function only supported on ESP8266 """ return check_supported_function(func, lambda o: o.CHIP_NAME == "ESP8266") @@ -172,41 +185,45 @@ class ESPLoader(object): """ detect_port = ESPLoader(port, baud) detect_port.connect(connect_mode) - sys.stdout.write('Detecting chip type... ') + print('Detecting chip type...', end='') + sys.stdout.flush() date_reg = detect_port.read_reg(ESPLoader.UART_DATA_REG_ADDR) for cls in [ESP8266ROM, ESP32ROM]: if date_reg == cls.DATE_REG_VALUE: # don't connect a second time inst = cls(detect_port._port, baud) - print '%s' % inst.CHIP_NAME + print(' %s' % inst.CHIP_NAME) return inst - print '' + print('') raise FatalError("Unexpected UART datecode value 0x%08x. Failed to autodetect chip type." % date_reg) """ Read a SLIP packet from the serial port """ def read(self): - r = self._slip_reader.next() - return r + return next(self._slip_reader) """ Write bytes to the serial port while performing SLIP escaping """ def write(self, packet): - buf = '\xc0' \ - + (packet.replace('\xdb','\xdb\xdd').replace('\xc0','\xdb\xdc')) \ - + '\xc0' + buf = b'\xc0' \ + + (packet.replace(b'\xdb',b'\xdb\xdd').replace(b'\xc0',b'\xdb\xdc')) \ + + b'\xc0' self._port.write(buf) """ Calculate checksum of a blob, as it is defined by the ROM """ @staticmethod def checksum(data, state=ESP_CHECKSUM_MAGIC): for b in data: - state ^= ord(b) + if type(b) is int: # python 2/3 compat + state ^= b + else: + state ^= ord(b) + return state """ Send a request and read the response """ - def command(self, op=None, data="", chk=0, wait_response=True): + def command(self, op=None, data=b"", chk=0, wait_response=True): if op is not None: - pkt = struct.pack('II", *words) - return tuple(ord(b) for b in bitstring[:6]) # trim 2 byte CRC + bitstring = bitstring[:6] # trim 2 byte CRC + try: + return tuple(ord(b) for b in bitstring) # trim 2 byte CRC + except TypeError: # Python 3, bitstring elements are already bytes + return tuple(bitstring) def get_erase_size(self, offset, size): return size @@ -936,7 +966,7 @@ class ImageSegment(object): # pad all ImageSegments to at least 4 bytes length pad_mod = len(data) % 4 if pad_mod != 0: - data += "\x00" * (4 - pad_mod) + data += b"\x00" * (4 - pad_mod) self.data = data self.file_offs = file_offs self.include_in_checksum = True @@ -958,7 +988,7 @@ class ELFSection(ImageSegment): name as well as the common properties of an ImageSegment. """ def __init__(self, name, addr, data): super(ELFSection, self).__init__(addr, data) - self.name = name + self.name = name.decode("utf-8") def __repr__(self): return "%s %s" % (self.name, super(ELFSection, self).__repr__()) @@ -1023,7 +1053,7 @@ class BaseFirmwareImage(object): def append_checksum(self, f, checksum): """ Append ESPLoader checksum to the just-written image """ align_file_position(f, 16) - f.write(struct.pack('B', checksum)) + f.write(struct.pack(b'B', checksum)) def write_common_header(self, f, segments): f.write(struct.pack(' 0: - null = ImageSegment(0, '\x00' * pad_len, f.tell()) + 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 @@ -1261,7 +1291,10 @@ class ESP32FirmwareImage(BaseFirmwareImage): # kinda hacky: go back to the initial header and write the new segment count # that includes padding segments. Luckily(?) this header is not checksummed f.seek(1) - f.write(chr(len(self.segments) + padding_segments)) + try: + f.write(chr(len(self.segments) + padding_segments)) + except TypeError: # Python 3 + f.write(bytes([len(self.segments) + padding_segments])) class ELFFile(object): @@ -1291,7 +1324,7 @@ class ELFFile(object): except struct.error as e: raise FatalError("Failed to read a valid ELF header from %s: %s" % (self.name, e)) - if ident[0] != '\x7f' or ident[1:4] != 'ELF': + if byte(ident, 0) != 0x7f or ident[1:4] != b'ELF': 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)) @@ -1304,7 +1337,7 @@ class ELFFile(object): 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) + print('WARNING: Unexpected ELF section header length %04x is not mod-%02x' % (len(section_header),LEN_SEC_HEADER)) # walk through the section header and extract all sections section_header_offsets = range(0, len(section_header), LEN_SEC_HEADER) @@ -1320,7 +1353,7 @@ class ELFFile(object): raise FatalError("ELF file has no STRTAB section at shstrndx %d" % shstrndx) _,sec_type,_,sec_size,sec_offs = read_section_header(shstrndx * LEN_SEC_HEADER) if sec_type != ELFFile.SEC_TYPE_STRTAB: - print 'WARNING: ELF file has incorrect STRTAB section type 0x%02x' % sec_type + print('WARNING: ELF file has incorrect STRTAB section type 0x%02x' % sec_type) f.seek(sec_offs) string_table = f.read(sec_size) @@ -1328,7 +1361,7 @@ class ELFFile(object): # string table section, and actual data for each section from the ELF file itself def lookup_string(offs): raw = string_table[offs:] - return raw[:raw.index('\x00')] + return raw[:raw.index(b'\x00')] def read_data(offs,size): f.seek(offs) @@ -1351,25 +1384,29 @@ def slip_reader(port): while True: waiting = port.inWaiting() read_bytes = port.read(1 if waiting == 0 else waiting) - if read_bytes == '': + if read_bytes == b'': raise FatalError("Timed out waiting for packet %s" % ("header" if partial_packet is None else "content")) for b in read_bytes: + + if type(b) is int: + b = bytes([b]) # python 2/3 compat + if partial_packet is None: # waiting for packet header - if b == '\xc0': - partial_packet = "" + if b == b'\xc0': + partial_packet = b"" else: raise FatalError('Invalid head of packet (%r)' % b) elif in_escape: # part-way through escape sequence in_escape = False - if b == '\xdc': - partial_packet += '\xc0' - elif b == '\xdd': - partial_packet += '\xdb' + if b == b'\xdc': + partial_packet += b'\xc0' + elif b == b'\xdd': + partial_packet += b'\xdb' else: - raise FatalError('Invalid SLIP escape (%r%r)' % ('\xdb', b)) - elif b == '\xdb': # start of escape sequence + raise FatalError('Invalid SLIP escape (%r%r)' % (b'\xdb', b)) + elif b == b'\xdb': # start of escape sequence in_escape = True - elif b == '\xc0': # end of packet + elif b == b'\xc0': # end of packet yield partial_packet partial_packet = None else: # normal byte in packet @@ -1385,7 +1422,7 @@ def div_roundup(a, b): equivalent result to int(math.ceil(float(int(a)) / float(int(b))), only without possible floating point accuracy errors. """ - return (int(a) + int(b) - 1) / int(b) + return (int(a) + int(b) - 1) // int(b) def align_file_position(f, size): @@ -1407,13 +1444,23 @@ def flash_size_bytes(size): def hexify(s): - return ''.join('%02X' % ord(c) for c in s) + if not PYTHON2: + return ''.join('%02X' % c for c in s) + else: + return ''.join('%02X' % ord(c) for c in s) def unhexify(hs): - s = '' + s = bytes() + for i in range(0, len(hs) - 1, 2): - s += chr(int(hs[i] + hs[i + 1], 16)) + hex_string = hs[i:i + 2] + + if not PYTHON2: + s += bytes([int(hex_string, 16)]) + else: + s += chr(int(hex_string, 16)) + return s @@ -1431,7 +1478,7 @@ class FatalError(RuntimeError): Return a fatal error object that appends the hex values of 'result' as a string formatted argument. """ - message += " (result was %s)" % ", ".join(hex(ord(x)) for x in result) + message += " (result was %s)" % hexify(result) return FatalError(message) @@ -1441,7 +1488,7 @@ class NotImplementedInROMError(FatalError): is not implemented in the ROM bootloader. """ def __init__(self, bootloader, func): - FatalError.__init__(self, "%s ROM does not support function %s." % (bootloader.CHIP_NAME, func.func_name)) + FatalError.__init__(self, "%s ROM does not support function %s." % (bootloader.CHIP_NAME, func.__name__)) # "Operation" commands, executable at command line. One function each # @@ -1452,9 +1499,9 @@ class NotImplementedInROMError(FatalError): def load_ram(esp, args): image = LoadFirmwareImage(esp, args.filename) - print 'RAM boot...' + print('RAM boot...') for (offset, size, data) in image.segments: - print 'Downloading %d bytes at %08x...' % (size, offset), + print('Downloading %d bytes at %08x...' % (size, offset), end=' ') sys.stdout.flush() esp.mem_begin(size, div_roundup(size, esp.ESP_RAM_BLOCK), esp.ESP_RAM_BLOCK, offset) @@ -1463,31 +1510,32 @@ def load_ram(esp, args): esp.mem_block(data[0:esp.ESP_RAM_BLOCK], seq) data = data[esp.ESP_RAM_BLOCK:] seq += 1 - print 'done!' + print('done!') - print 'All segments done, executing at %08x' % image.entrypoint + print('All segments done, executing at %08x' % image.entrypoint) esp.mem_finish(image.entrypoint) def read_mem(esp, args): - print '0x%08x = 0x%08x' % (args.address, esp.read_reg(args.address)) + print('0x%08x = 0x%08x' % (args.address, esp.read_reg(args.address))) def write_mem(esp, args): esp.write_reg(args.address, args.value, args.mask, 0) - print 'Wrote %08x, mask %08x to %08x' % (args.value, args.mask, args.address) + print('Wrote %08x, mask %08x to %08x' % (args.value, args.mask, args.address)) def dump_mem(esp, args): - f = file(args.filename, 'wb') - for i in xrange(args.size / 4): + f = open(args.filename, 'wb') + for i in range(args.size // 4): d = esp.read_reg(args.address + (i * 4)) - f.write(struct.pack('> 16 args.flash_size = {0x12: '256KB', 0x13: '512KB', 0x14: '1MB', 0x15: '2MB', 0x16: '4MB', 0x17: '8MB', 0x18: '16MB'}.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 4m' % (flash_id, size_id) - args.flash_size = '4m' + 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' else: - print 'Auto-detected Flash size:', args.flash_size + print('Auto-detected Flash size:', args.flash_size) -def write_flash(esp, args): - """Write data to flash - """ +def _get_flash_params(esp, args): + """ Return binary flash parameters (bitstring length 2) for args """ detect_flash_size(esp, args) 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] - flash_info = struct.pack('BB', flash_mode, flash_size_freq) + return struct.pack(b'BB', flash_mode, flash_size_freq) + + +def _update_image_flash_params(esp, address, flash_params, image): + """ Modify the flash mode & size bytes if this looks like an executable image """ + if address == esp.FLASH_HEADER_OFFSET and (image[0] == '\xe9' or image[0] == 0xE9): # python 2/3 compat: + 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 + if args.compress is None and not args.no_compress: + args.compress = not args.no_stub # verify file sizes fit in flash flash_end = flash_size_bytes(args.flash_size) @@ -1524,11 +1589,9 @@ def write_flash(esp, args): for address, argfile in args.addr_filename: if args.no_stub: - print 'Erasing flash...' + print('Erasing flash...') image = argfile.read() - # Update header with flash parameters - if address == esp.FLASH_HEADER_OFFSET and image[0] == '\xe9': - image = image[0:2] + flash_info + image[4:] + image = _update_image_flash_params(esp, address, flash_params, image) calcmd5 = hashlib.md5(image).hexdigest() uncsize = len(image) if args.compress: @@ -1541,16 +1604,15 @@ def write_flash(esp, args): seq = 0 written = 0 t = time.time() - header_block = None while len(image) > 0: - print '\rWriting at 0x%08x... (%d %%)' % (address + seq * esp.FLASH_WRITE_SIZE, 100 * (seq + 1) / blocks), + print('\rWriting at 0x%08x... (%d %%)' % (address + seq * esp.FLASH_WRITE_SIZE, 100 * (seq + 1) // blocks), end='') sys.stdout.flush() block = image[0:esp.FLASH_WRITE_SIZE] if args.compress: esp.flash_defl_block(block, seq) else: # Pad the last block - block = block + '\xff' * (esp.FLASH_WRITE_SIZE - len(block)) + block = block + b'\xff' * (esp.FLASH_WRITE_SIZE - len(block)) esp.flash_block(block, seq) image = image[esp.FLASH_WRITE_SIZE:] seq += 1 @@ -1560,23 +1622,23 @@ def write_flash(esp, args): if args.compress: if t > 0.0: speed_msg = " (effective %.1f kbit/s)" % (uncsize / t * 8 / 1000) - print '\rWrote %d bytes (%d compressed) at 0x%08x in %.1f seconds%s...' % (uncsize, written, address, t, speed_msg) + print('\rWrote %d bytes (%d compressed) at 0x%08x in %.1f seconds%s...' % (uncsize, written, address, t, speed_msg)) else: if t > 0.0: speed_msg = " (%.1f kbit/s)" % (written / t * 8 / 1000) - print '\rWrote %d bytes at 0x%08x in %.1f seconds%s...' % (written, address, t, speed_msg) + print('\rWrote %d bytes at 0x%08x in %.1f seconds%s...' % (written, address, t, speed_msg)) try: res = esp.flash_md5sum(address, uncsize) if res != calcmd5: - print 'File md5: %s' % calcmd5 - print 'Flash md5: %s' % res - print 'MD5 of 0xFF is %s' % (hashlib.md5(b'\xFF' * uncsize).hexdigest()) + print('File md5: %s' % calcmd5) + print('Flash md5: %s' % res) + print('MD5 of 0xFF is %s' % (hashlib.md5(b'\xFF' * uncsize).hexdigest())) raise FatalError("MD5 of file does not match data in flash!") else: - print 'Hash of data verified.' + print('Hash of data verified.') except NotImplementedInROMError: pass - print '\nLeaving...' + print('\nLeaving...') if esp.IS_STUB: # skip sending flash_finish to ROM loader here, @@ -1588,23 +1650,24 @@ def write_flash(esp, args): esp.flash_finish(False) if args.verify: - print 'Verifying just-written flash...' - verify_flash(esp, args, header_block) + print('Verifying just-written flash...') + print('(This option is deprecated, flash contents are now always read back after flashing.)') + _verify_flash(esp, args) def image_info(args): image = LoadFirmwareImage(args.chip, args.filename) print('Image version: %d' % image.version) - print('Entry point: %08x' % image.entrypoint) if image.entrypoint != 0 else 'Entry point not set' - print '%d segments' % len(image.segments) + print('Entry point: %08x' % image.entrypoint if image.entrypoint != 0 else 'Entry point not set') + print('%d segments' % len(image.segments)) print idx = 0 for seg in image.segments: idx += 1 - print 'Segment %d: %r' % (idx, seg) + print('Segment %d: %r' % (idx, seg)) calc_checksum = image.calculate_checksum() - print 'Checksum: %02x (%s)' % (image.checksum, - 'valid' if image.checksum == calc_checksum else 'invalid - calculated %02x' % calc_checksum) + print('Checksum: %02x (%s)' % (image.checksum, + 'valid' if image.checksum == calc_checksum else 'invalid - calculated %02x' % calc_checksum)) def make_image(args): @@ -1614,7 +1677,7 @@ def make_image(args): if len(args.segfile) != len(args.segaddr): raise FatalError('Number of specified files does not match number of specified addresses') for (seg, addr) in zip(args.segfile, args.segaddr): - data = file(seg, 'rb').read() + data = open(seg, 'rb').read() image.segments.append(ImageSegment(addr, data)) image.entrypoint = args.entrypoint image.save(args.output) @@ -1623,7 +1686,7 @@ def make_image(args): def elf2image(args): e = ELFFile(args.input) if args.chip == 'auto': # Default to ESP8266 for backwards compatibility - print "Creating image for ESP8266..." + print("Creating image for ESP8266...") args.chip == 'esp8266' if args.chip != 'esp32': @@ -1652,27 +1715,27 @@ def read_mac(esp, args): mac = esp.read_mac() def print_mac(label, mac): - print '%s: %s' % (label, ':'.join(map(lambda x: '%02x' % x, mac))) + print('%s: %s' % (label, ':'.join(map(lambda x: '%02x' % x, mac)))) print_mac("MAC", mac) def chip_id(esp, args): chipid = esp.chip_id() - print 'Chip ID: 0x%08x' % chipid + print('Chip ID: 0x%08x' % chipid) def erase_flash(esp, args): - print 'Erasing flash (this may take a while)...' + print('Erasing flash (this may take a while)...') t = time.time() esp.erase_flash() - print 'Chip erase completed successfully in %.1fs' % (time.time() - t) + print('Chip erase completed successfully in %.1fs' % (time.time() - t)) def erase_region(esp, args): - print 'Erasing region (may be slow depending on size)...' + print('Erasing region (may be slow depending on size)...') t = time.time() esp.erase_region(args.address, args.size) - print 'Erase completed successfully in %.1f seconds.' % (time.time() - t) + print('Erase completed successfully in %.1f seconds.' % (time.time() - t)) def run(esp, args): @@ -1681,8 +1744,8 @@ 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) + print('Manufacturer: %02x' % (flash_id & 0xff)) + print('Device: %02x%02x' % ((flash_id >> 8) & 0xff, (flash_id >> 16) & 0xff)) def read_flash(esp, args): @@ -1699,57 +1762,69 @@ def read_flash(esp, args): t = time.time() data = esp.read_flash(args.address, args.size, flash_progress) t = time.time() - t - print ('\rRead %d bytes at 0x%x in %.1f seconds (%.1f kbit/s)...' - % (len(data), args.address, t, len(data) / t * 8 / 1000)) - file(args.filename, 'wb').write(data) + print('\rRead %d bytes at 0x%x in %.1f seconds (%.1f kbit/s)...' + % (len(data), args.address, t, len(data) / t * 8 / 1000)) + open(args.filename, 'wb').write(data) def verify_flash(esp, args, flash_params=None): + _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 = argfile.read() argfile.seek(0) # rewind in case we need it again - if address == 0 and image[0] == '\xe9' and flash_params is not None: - image = image[0:2] + flash_params + image[4:] + + image = _update_image_flash_params(esp, address, flash_params, image) + image_size = len(image) - print 'Verifying 0x%x (%d) bytes @ 0x%08x in flash against %s...' % (image_size, image_size, address, argfile.name) + print('Verifying 0x%x (%d) bytes @ 0x%08x in flash against %s...' % (image_size, image_size, address, argfile.name)) # Try digest first, only read if there are differences. digest = esp.flash_md5sum(address, image_size) expected_digest = hashlib.md5(image).hexdigest() if digest == expected_digest: - print '-- verify OK (digest matched)' + print('-- verify OK (digest matched)') continue else: differences = True if getattr(args, 'diff', 'no') != 'yes': - print '-- verify FAILED (digest mismatch)' + print('-- verify FAILED (digest mismatch)') continue flash = esp.read_flash(address, image_size) assert flash != image - diff = [i for i in xrange(image_size) if flash[i] != image[i]] - print '-- verify FAILED: %d differences, first @ 0x%08x' % (len(diff), address + diff[0]) + diff = [i for i in range(image_size) if flash[i] != image[i]] + print('-- verify FAILED: %d differences, first @ 0x%08x' % (len(diff), address + diff[0])) for d in diff: - print ' %08x %02x %02x' % (address + d, ord(flash[d]), ord(image[d])) + flash_byte = flash[d] + image_byte = image[d] + if PYTHON2: + flash_byte = ord(flash_byte) + image_byte = ord(image_byte) + print(' %08x %02x %02x' % (address + d, flash_byte, image_byte)) if differences: raise FatalError("Verify failed.") def read_flash_status(esp, args): - print ('Status value: 0x%04x' % esp.read_status(args.bytes)) + print('Status value: 0x%04x' % esp.read_status(args.bytes)) def write_flash_status(esp, args): fmt = "0x%%0%dx" % (args.bytes * 2) args.value = args.value & ((1 << (args.bytes * 8)) - 1) - print (('Initial flash status: ' + fmt) % esp.read_status(args.bytes)) - print (('Setting flash status: ' + fmt) % args.value) + print(('Initial flash status: ' + fmt) % esp.read_status(args.bytes)) + print(('Setting flash status: ' + fmt) % args.value) esp.write_status(args.value, args.bytes, args.non_volatile) - print (('After flash status: ' + fmt) % esp.read_status(args.bytes)) + print(('After flash status: ' + fmt) % esp.read_status(args.bytes)) def version(args): - print __version__ + print(__version__) # # End of operations functions @@ -1761,7 +1836,7 @@ def main(): parser.add_argument('--chip', '-c', help='Target chip type', - choices=['auto', 'esp8266', 'esp31', 'esp32'], + choices=['auto', 'esp8266', 'esp32'], default=os.environ.get('ESPTOOL_CHIP', 'auto')) parser.add_argument( @@ -1842,8 +1917,11 @@ def main(): action=AddrFilenamePairAction) add_spi_flash_subparsers(parser_write_flash, auto_detect=True) 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 (only necessary if very cautious, data is already CRCed', action='store_true') - parser_write_flash.add_argument('--compress', '-z', help='Compress data in transfer',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') + compress_args = parser_write_flash.add_mutually_exclusive_group(required=False) + compress_args.add_argument('--compress', '-z', help='Compress data in transfer (default unless --no-stub is specified)',action="store_true", default=None) + compress_args.add_argument('--no-compress', '-u', help='Disable data compression during transfer (default if --no-stub is specified)',action="store_true") subparsers.add_parser( 'run', @@ -1913,6 +1991,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) subparsers.add_parser( 'erase_flash', @@ -1935,11 +2014,15 @@ def main(): args = parser.parse_args() - print 'esptool.py v%s' % __version__ + print('esptool.py v%s' % __version__) # operation function can take 1 arg (args), 2 args (esp, arg) # or be a member function of the ESPLoader class. + if args.operation is None: + parser.print_help() + sys.exit(1) + operation_func = globals()[args.operation] operation_args,_,_,_ = inspect.getargspec(operation_func) if operation_args[0] == 'esp': # operation function takes an ESPLoader connection object @@ -1961,16 +2044,16 @@ def main(): try: esp.change_baud(args.baud) except NotImplementedInROMError: - print "WARNING: ROM doesn't support changing baud rate. Keeping initial baud rate %d" % initial_baud + print("WARNING: ROM doesn't support changing baud rate. Keeping initial baud rate %d" % initial_baud) # override common SPI flash parameter stuff as required if hasattr(args, "ucIsHspi"): - print "Attaching SPI flash..." + print("Attaching SPI flash...") esp.flash_spi_attach(args.ucIsHspi,args.ucIsLegacy) else: esp.flash_spi_attach(0, 0) if hasattr(args, "flash_size"): - print "Configuring flash size..." + print("Configuring flash size...") detect_flash_size(esp, args) esp.flash_set_parameters(flash_size_bytes(args.flash_size)) @@ -1978,14 +2061,14 @@ def main(): # finish execution based on args.after if args.after == 'hard_reset': - print 'Hard resetting...' + print('Hard resetting...') esp.hard_reset() elif args.after == 'soft_reset': - print 'Soft resetting...' + print('Soft resetting...') # flash_finish will trigger a soft reset esp.soft_reset(False) else: - print 'Staying in bootloader.' + print('Staying in bootloader.') if esp.IS_STUB: esp.soft_reset(True) # exit stub back to ROM loader @@ -2009,7 +2092,7 @@ def expand_file_arguments(): else: new_args.append(arg) if expanded: - print "esptool.py %s" % (" ".join(new_args[1:])) + print("esptool.py %s" % (" ".join(new_args[1:]))) sys.argv = new_args @@ -2074,107 +2157,108 @@ class AddrFilenamePairAction(argparse.Action): # Binary stub code (see flasher_stub dir for source & details) ESP8266ROM.STUB_CODE = eval(zlib.decompress(base64.b64decode(b""" -eNrNPWtj00a2f8VSQkhMaDWSrEcIxXaCSSlsA5QUet020kiCsoVNjHdDWfrfr85rZiQ7BNrt3vsh1CONZs6c9zlzZvrv68v63fL63uD6/F2Rzd+pYP4uCMbtP2r+rmngb3YIj7p/WfvX1He+PZp83X4Xt38ldL3T\ -vtXcqO9Qt8z5rGx7qhxmGVNPenHam0Ct/62cPgSaA5DuzkQz9KC2H43XLmf+Ltc3eB1FIL/aaa+73f9Jawii3sp7Dfm87GCng5DBjgNbi/ysQjCeOQABTczXOTRqp5EbRMfOG/hYlXboIpgvesjIDAjzpfw8bv+p\ -nYYKnSG0A0YZOA3VmEXst49zBihwQQXiFJUDXeBAF3ReaprLzKNGDopUl+ZB4LAaNmT2ElhLCJ1lTqOwjWf41Xj3Af4nuIX/eXdk2OM+/yrjr/mX1l/wL9VOUIfcqLIcf700z9pBKpkxbwGrkYvHD7YEJB7Sa0ev\ -aFF5+2WhiMnhE9X+1oFfbPhIQFpwWBy0T8Ni2o4fFhOYr2iHa8LiDolKndJo2qAIpojgoSJWRAQCetrfQeIKGIAUfuOnITAjz5rpoQf9D+4SOQLVNgsWI62ExkoeDndh7gENqQEt4VTgl4WMaNKqWANqgQ8ZFYEy\ -gwFVwiAemAc49C78w6PF/dEuew6wIkIm8uMRyW7TnMsPRlFYMiA8mG7WDYZc2cKeA/c1e6GBcZuUhEoW8pkgJqM3NIl5sWOfqiicAJuE3En5jw7wycgvfOAWGBeIhG+j0I6VAZ6VCvxBM50vt3c70ITt10wGzWsq\ -y/6ahPSgq6GRwbAFa42spV7BOG9k2sh356fxlBrAj4FHAoiqt2XOsu2i0rugaXFZNHJdMzDqEmAE2qJZJbNuubiqmG8IW/TfKgTFDahCJCcEfRCk4aNGoG0f5qz0muTtRoOdZz/Kk4P5m2ZDuj7gOeGbylVDzQF+\ -dY6/nzjTRRbCPOuqvLwDXJC8J8gAy81bZwixUAl3Dhr5avbOjlY6o81ew/NZ+w3rSqV7iMhpru2GdAOtbiyd4UELyBsauenB+YVFQpbaT5QLwFSe+87D5wJV6NC1UtBDRbvthEt5FtAz4HCA9vceL3TJmiXX3HdR\ -9x0jYeTiSlWgycFywejPWSMlxg42/FE4+0HenbtK5bdVFqxbtVVXxNQKJ35tDOzuBD76V/+jE1L5qsAFEQPj4r+gXpl+OAAWjE+egFFjfRmCLfmKVVTCWtz6EyByqF7frEz3mNBZBzSXxrm+5B/pV7QGmANN2OrQ\ -tIzmsmUka5dxwqa9Bkx/b0kAfkYVimhvGYQ/E2b/mTEvBCkboeiPQpNbK6/26ZVO/uYSe0u6zB7C4+yBN3RUvAtIKHzniPss4/lgrJinU2E7yuanjTITFZDSQIChIJ5NXOR6xIx2uJClLXDGTci6WylG9yXbBf/j\ -MbEG2idgGjAj2upOHiYHO4GcL+a9bmZ2pro4mFqygwNZ12Mfhku/gPEfM3SjUjyIKf9APfUUdL5o4PT0KRqdQ3h4fDiADgC4GkcDgEuLTdFK1jxA6W2BnN1w8AJjA14sGhzcqCSaL0GfmLfZCau0LGQlhMjRycCq\ -qoz0B/EEqQOhMPq/yDWzwao68IT1SGw73BckvnBfL4AJmm+FF7zuTFYCSFWptPOZ4VviDjM1Dj5hStcu5d8R+bROu3zT6H8oMrKNO23+khyOJk124fMBsHgXrNxwDPnmOWvVAEFtBQlcX3Sws298agWj4fcD6qWR\ -eUBnNc8JNOwQzTDoGBnM8vKVI2qVRdMqRklJiVcs8CKbBIPl3QX7wu1vGHHhOBraCSlXFBm44roUX0bJFOC2qLBlmghVwFQI3nZGWW5K+wRgCeKtkOh2HcNnS1ilN1LCIVIVyBTEoVg1nOY2m9Mo5QAMB/YY2hUm\ -8ciZbGrrkaGyNR2yXY8maupgMhluMmqafr/bMNXNuaCu6r/3yVmuM+6Q9zswc8ZuiOajg45uejSFf+Nn8zl4Yf+EUWYUiVH39a5khH5kNAAuBEZF1YHsePcHJmQCvNSNCj/uFvuoo0l6rD4sbjDj1Y6vFXscjUL8\ -pnnJZegz3ykJP0vmlMhHX3Hh3SiLaxQwsa29nrJmFVkKsUNYAL+PHrD3G3qjcw5KauAT78bZN2yhi0OKmsErr4q/l8UODrI7fsYhY0HOMQipQjX0K8x4QQ4+GYxfCQbwRGu92KUPMyCPGm3/ChMWW4tiEwce7j8B\ -3fkBRA06xC9BjQBHl5Fld8yDxIrQ1XIYStk2vUeMhMykmTCpq2Qj4iOQB/hvFuYgBjkFGEV6J8f4dvM1fdL+3GL/BWxFix1w/PRGgPmkdo6UmRqcsFziqPjr8kfCHAprg9R9Q4goUlKxNYZZyELebzQGWD/d5OSt\ -ogIacdSJD3go6yaZAXqfrsCP5r+Gufd3Zk4MgyMuaEnXjlNc0mu7HhU9p3XMvnByHwL/yML/sgd/HhoLL9IQeLXTSWMnT/Mj+G8ECajwJWv74BoIzit/WgSPi7gsvgT6AI8y9ypiuhVtgFBPveCxF5cefuRFxOMk\ -dDWF74OG+FDrfx0PYhHObIDh0/F3EPOWT3m48Pw5sxFmhjBiwRD9RWrxH4zGY0i7iGORjEFsoqABptEzHipZQb53D8bePcgZ0eSOBJGrWZiVmuT2mEjIzOG+NHzGDOoPtllENS0u0JG3D3PlpTApDaMlqyh0DYWQ\ -viyP57CJG9/mUYmc/Lsai9aGOLwGiclKZr+EDQCOeM4mo7WWm+1yynTgTXbIZICs1dGErBosq6lOgAobaGc3URlUtxARmx9BRG4QscM5XP3khKxbU7A7Efc4Olu/8pnrCfyBpWedpfMyOLU25gUDpdQHoN+APlKB\ -dXNV8pB0QQP8WeW4+I1LF7+QlWNMgOPoEzbT8ezT1/0nKQ7LRnsHaaogY4MG/lZTv/L3fGC1KRkmQ2qOFetsIivvJV7T/cmncz9MVdFfriVztNjRNEJZE0msQgaHB+xtNWEXtTYq7pV/3xcsEdQ8tfVLJ+wYV6+i\ -+5F/AH0Msj1GBYwM7NdURi/CyIIHQa0CeJpk1nXxMGGrwFsC47/M/TYMAVVJea+m9TGWt8L5cs/1OyAZiUAFPiY48oQjp4STLl0U7r6dSTpZklHAcfuI+WufynH70QmZ0zrhT+I+GRnlyV+ma5rAClyN+x9LdDG2\ -HA6zbOcEpEGwfzCjhQfhqlJptUkO0IM0BgsPcutls7grAD61zh/ZoofUqIID8A9ON9BLuE4uFaSykBBVL0sXARXKNQBkCEBmAGBEsXdudN4u+ExLdPjfWyd+DeF2wUi1k5XZGmlCKkFGs6XvzjEArTGYeQ//XFBW\ -NVCQKAuhlUgruQnaCnx7DatPyYAv0L/q2fAqJ/G0NnzhhWK7yWqDBYcZ9funZw2nd4A4TcbpCUR3K9uLWT9i660H93wiTowia2zZcIfiZOYn/wWIz64446AKqukLCsh4O+Eji9LxmkVJ7iMbXihynKGLXWK74nbd\ -gLlU9i6y6YGwVXTB3i7EtTo8o107ydvn8VSSn6XPsV6T+rKNIHs8QGO97Ie20yPzKUlYlskQ4OHBVkud7XG8DYmMVMZrhkeLQ/sxe+mYCsRMpHJSb4BdyIO32hH2AljYHFt+7XOcGkw+i5LR+v9MyWByo/HeEjFJ\ -4J31Tc75BQwV4lDgaKnxjCkM+Kox3gwGNkO6xjM4Ilacw3j3o8EWfA/7RGBN0ViUSYJ4emFBaaNfhPsxbhH3neekz6NCqJYLXbd5xozjbmgnt/evpNka/wv8uhMyLzr8f2AYvG/RIn/V58oW58HmcHPygFBk/VBr\ -qI2T2iLfS9Ge+5g/ScjEKh0heSKcEzby1fmhS5qzBZALJX189g7M0wLc32cQiqhDCXlae6Vc2i0KGut/VhXM/PpkD57Suofz606uKlAn/Q88pn9LJhwSgRruTGkvEvd/1KNVFmk5TLUMsg0JINTRWGvBU2UhiKfy\ -i5sI+RfWFLpRWJa4WXYBfoibUJGrilBWgumGcPnhVNPPFogvyAhiEB/LPMBoCrYz1UPXArP9x6zOAtHbtgoy43kGZhJaGWpln9M9NGO0Q9TOi0PetKpHdrnoXiabbD4MunkLmUm93PMFjgGpcPgDrOWYQfhAbin4\ -uU3OMeklpjoCJxLiQA0hHG7TZTI5EjEvMt7oEjwmLLwY7UJtBG5pyx5wOi1QzA5hDz5aFNlZOuA0vlJhkYZeMvVSBCVeeElYbI+jwdTLzs6R8Q8XRTItsnuU26kSNrDg06RpcHZEWMyDQ5uTH4/VtNi28ScCmfEe\ -IFaTYH4OwZ+2axq/hQGm3jbQKJp+D62FbKCDqkjJT0InqpGvgjMwieML/JbpjLF+5eMIyB0S89dBPhF8MO6xTCRsV34GKz87BBEAOqXje8ir8ARHruL5sl0PzBFLPgEEqAXY/w6V+tQk/uqFh8i+aLHW/gzUpMUw\ -SL429ixl17JceCnMl50h6jG5HgRZwMKZIxBjZKOziNaWh0+sJsxzV0YwW8bq1pZ9eDe3dmwSvEjtfm9WWWsAqrri/XPqK3vLkIUHyIvEl1c7khoeYdIOtCgg5pz3z/Vw48xnxJkdG2YLEJhc8p9q/LUSmblHMMve\ -ulu+gB3SMe28pvwMo6VrdjGm5EeTr0CL2aFEDTi9jf5ArqRjdDGPA+KiA8jpBPF9wHIREbJDm+cDnq8jjlTL6Y3WBwKvF724mG1sIkEmZCu6pS8fD9oxOotOYLrRfy9ot1QPneAzdYIIsxNgaDi1BRBZebMzR2RL\ -WdgB2sRZNwY08Q2CSkwsZlRBllz++d1lntBlHlRUwUCYB613kCsYO6NCozfWzuSSMtTMDjFTXpXihMSW/OBpGvL7aBoIAJ8nQvLD5iSqE44qmlR8Cx8CzVYIt0w9A00Rddw6Z1sc3Wql0IHT6gz+pSQJeglKkgKa\ -dqBRhLf6seaU9wsCjMlAeWbRaSjykZLORb7KXovlKLauCpuUNo7MHN3dfxASCYIca3tob8O4UH7Bebo7V+Tp1nD9BmfpsnjVRTTMn16RqXM4X3OIEJDnsLkqA5b/gszIQ3obpvL+h9ZKlMzpc037YVnBWzIqx7Eu\ -YKxVXABcF0DwC1jh8MK7C0Ois6aHW/dpjGWHLUinE2fwgEqLBmxQcS3Bx2lZ5HDvMCQcqSuC7Z9pJdaba/03CrbfNz2HvxsQnG/Bl1OkkMIwT4VDom8ilT9N84LlgvNLtPYVTnoCWtHH4j1UvpDNaPRqhn9B1V73\ -+zC3AHvgBnG9g5oyONF78I5gG63RvG2HGFMH/RFWY24PM2qwoYl58jLK6Rd4hJh319u03wnqHuAq0Yt9YsXGWMM6mbKG1GQZ0N5EXFeZjIzo7hznYj83RM9+azc0G65SNNZVJ9uYNueSthIz56AdOya1/ItMaiYm\ -VV9qUoesTLGgNOayzT9oUhGktGNSR2tMKueDr32OcnnLe5XsD2HdZbXOuib/Heuq/yLrytokXDWwEy7bsCw0FrtmWQgjoMEpsxA6UsFgR52ect4yMfXbmFL7QJYvc2ivyo2OxUO9dvoCPVk0tXuQ1ymaMXijgNc8\ -EQaYmcqAvlFdSYsMHC1JxRgvxFmdfW3FyVTuaIoDMW0Yr080ddKrpZvXlZSJcY5h4ziFoC23BbOWJ6SOYGNwGV+s0IZjyDIwtJlweXm553fIFDhkClRLGtZOkRVkoIQqNz9wKrvn32AhiZHFhSUcWh/Qo+V7lM1V\ -AX0iTo/QZyT0ee3sXF5CKK7fNOVkm/1gA2xdPl2LT1Rsg81Px+d0BZ/nJItNed+/NBiBxwrrEtoo62vGbJM7mE1N3kSV9z443l2Kiz4TG44lZ2cYRb736SGWC5QG3++NT2kdSx+TPBWaEvTkYM+uwRIXv500vOsY\ -6LiD5XEPy1IvUT59bcnF2/IykrrxdPZCCEgC3sjuB2wMFIJkTHUOYS8Pxib90dAmPRd5b0qOt3xVwqOkBHdJJeCnJiCY1SHDITsLAQp7dpnm3kArwJvYBdv0PIKSuKb6mFcY9pS2zXiHfaVt3J2bvDHWdxFZyZIK\ -DzruYdFxCaOONyi62Unxum7dGq9PMkWu30BEi8XN2Os5DToZoltwJATBiMkYVSwlaCQPqbm+T6nTMWt2YMJAnf4izkH8gp0De36i6yWo9BSrQe9ZGc6QvuucA7OOISzve4DRDbbJMJwi4x7BwoD7gvjVISbcTJIl\ -j0XxHIpboG9E6W3ZY0r6XsEKj7mm9Uo2y5jNCtyD43jRcFj+H+CwPm8F65wExJ1zhqAafdRJKF0n4eGlTkI85nL4Akti12vNc05HXspQU5ehut4mnT1otaYk9KyrkKshDYq8kZjgW9CTWHYgR5HZ4VJH8UCIHa/x\ -Ey5RjBOueS5FKNXeIe6tTIvNCW3EwjtQAnsxnpfBHWOVvLSHD8pq+ukstlIy1uWykrNHZfIfZ7Tyaj32ApSYXqxosLTzASUaHD0mm4HW4gmezxwDhIjL5XRYUWIADb2gEqsN5KC0H5ywpjjFWOgMx8a4ICyGwcHg\ -e1GBx3cH5JoND+9ld7kgVWr8UDCK3SeUE8cznftPPC6YAOOlN/Ny9vN6wjib+XW+gBJ9E+jvYpYe97wVVV3CaOSABcMNJ7xX5YWPNnlRDNHYipyXpRQctSGGOQs5FSep5FRBNb3rPlfYVNIMb0X4ILz1FMQmkfyi\ -qL1UIkVO92NYguMTUA0QbyQPFT5Ur56yt66s6sZDcHX/AB9k69GhTrkuJOTdXeBWW4/1FYZiuJP0ySnOXYKJ4rHZ3znRclnGZ/SXBGTabOL+4dIsKciWWpnbiIqtT9/O3uU9IcLDySoergpK/2x9mu7Vp1EJ+5qa\ -rJk18J+3+7tL3oANvTEt85+Ku9W/SThV2RzxRGyWcHrcLUJHM+V0dilr7UDt/RM1yUZe2rOq2eXcDAYs9iBRW2AZEDmO7cKHUNayAHEBzyv+DX79QkFCho8wBQQ/Rh+4ZAw4j7NUEKzoEaeTUnZ/EGdIwGdAGMV+\ -dnFMpGlQI+jjYwjGqGLW3esHrQv4sUmw39l1k+1o/RuVzHIGcLu3Ke9sKeKZs8J5pn74iXQHiJF5CvuyxdM1L6LLXsSXvRhd9iK57EXae4GNDN3QIrpAH/psYwKo9gnfeLQ8OO0UgbkHfkp/z4w03BMX+QLW0qDL\ -ADveQd1iHvOWtGvfWrEviQqPyc1+3adCi3CFKXU+xwdHIfig8i/9vguP9nm5YP+MTDAdlvG+PP8O+rc0/JEJq1/eJl4t4XyvlpNckTA+HpuCHUKcu3j6nOS9Zk1Wcf4ANpmK8AOpflQCwpm87Q+KCz/KWEKjXvZY\ -VFnQK3yWM2mw/VbV6h65CDe2scq3kZOCvpxD4HM2ClLRxc5GNl9gVhpQBH/R2b7dSFWjUs5VYI1MhQrh9Bp7p+VPxz8Njvmon87ni2MfdKFeMGTpTWKhbBSZA+VYrOHdoINjKuKZ9RHlBrJaDpbgF9v7YBamjl2u\ -RYRrci+1SfHKAaF0BxhBOxjEqqYaxtJGa4LeKuSTjDFrOBb6shH52e2Yt2PD2WL0hgI4m829YG+j8Nh2wUt1s892fCKp/1AnJ2a8DoTfOX0RsNkT6bh2/AFdWSBJuYLnqumA4T4w2s0B7OfBHl1mzrkyERiVeBa+\ -2N6F/q3qnDvhaNi/jsM5HATkH/VOc9kzBOZgoDhzHLyQcsDvfb4JoOKzRlQY+CUXgYCoNHkrk+I14AEmjVHUDTARG4O/0cozKUbGNRw9eDafv/z13QeEhI9GCYk6x38rJ2vP8lmFFmQsfS6cO1XylXKvBfdMLXcg\ -Ep3bDpyDg3yIJJBouxA3Oz+az7NdvMnBw5PU7aPc5p8oNIfEc82JNBTNZ845NJ1B9QCkO0Gem/w4ZGnFU3n4jlcnCKsF5tA76N5joUMPb6rw8KYKD2+q8O5QzaWi8mnn9hNikVP26kL3Yphw3S0xsCvU6M7VCnjj\ -wmCweTLlWymwiLyZ2H0c96oFzzrt/Pjrzn0MeOnEybLTw7m5QYUU3w42ArOUzLnSRq2/3wbianM5TBa798GMzbU0D6iaBi8zUZ1PM/rUgR3lXbHvksvNIQM5/opLWuIBNtywi/qXUch5NiopXoLK/IAfNKrTFQ+3\ -mdODzQBc02z0rdS1yukruO0iiDi+bfKJ/Gj7jw9otTzgM2a0Gu+HuB9JNgPx0GDSvILUQxObT0pMed+/a4E65PnpS4/uWmkaZKqY9s/2PfDuMHJAeNBRcy/qwHOwj8jYtguW4nxO8jTNCutYgJ7TeVaj35zHcZfb\ -lBwd2PNtJo874NlqvhcHT4jgqUPewMWkdyPi3DDnWwpLVVHmEbmxYo55QgWulLnXHXWV8dgu0yZuXJF0eEyHBc+ofpV0fIGnH3d5/5vtRwD3fNTs4ivZkNUj8lvpIdc3w/KKTIQ27iA87wgl8vMJ1Pk22w+4pCOa\ -X9+wu70qnHzPcBkrvr07GMRy8qaeOBCQAtwtuBK8GT/tSFCIKdUg2DyRS3TQmjTotxnj0nT5QXHpjH081R32wNo/0izZgwHyQf4g293zd3aFvEDNy6j4QK4mkg41ehdgldRdWnqVPzoCo93y+/Icud+aKTQfsKuM\ -5TYQXVdws47CuxVizgZqOR7Ddbp60vUfMeyJhAw1JYLe0POq6ZO37yGx/3Od9EbN4WBjwkEIxzU4zvVDcyZZr967kWmp5tdx61vhV8ObEOhq8IYqtlToueZwPUR2DqiFmy6yR3z0pMmMvAwEzQiEOVMM5+GwJNQK\ -AetTcXMfoxYK5vPJ881HYmzgi3gnpnvPfvCN2Gu8S0Pn3+3AV1BQvuIPZOo2V0bi2kbBLntmH+MKF0C5DqVESAN1pz+JdMBU9f5aED5tpnYCc1+AHG4f3WXGkTOyIzESCJN0w7Pk0WWQYWWE+mzIetARldgsItVQ\ -CPaYMT6WsaINNI53Uj64FrvyebW2XRXQyiVsi73zsLAXTKkV5zBjZx2A0wag3m0GqlyHJmH1Hm9Th2euX/HSbZy5jaXbeOc2PnTv48t69/Pl/bZ7CRtWcmfmKrVv8FdsnlW3nCv68lzuUTPunItWvhQHFQPgFxQe\ -ajvQeq0SdC9Tg2s78LY6OAIjuUYMA9hfVYWPxkZuQGg4rFCYuHICE4rOHzPDNOGvfCPIWjUFhbglZ+86FbwPZIdAO5cq9D/FM4PgwVLKYPgIpjoU/wLvvMGuhVyChat8aU9YVIlc8kOxDSbRMYCQU1+NdX1gqXJt\ -WfH0N9nZU0YLVyvLK2zdTDvxO06Ia3tJzK+cm03ESZuIJ3ST2bc4hJni23M4vUfeJaKlN3XYn/oR337R2MREC/UzTmoU9SOWGXr+Czwv+DYMB1qPL5fAR7SDjql0KO+DSAY1SXP2pbBQlIn5DG3ddlXbXcFakCrn\ -WtvJp7VzjVy4BoelWUDDGRzQP3TZyyOukG7s7lA75BGts8TdWHMcDuvjR4OnASZWYr51KMBMoeWP+4lvTrQduueiIcMUsYIu861DCBkKdEBv8+RYa7n2rjY5oCduFYIJ2xzkIzm39ZXsZfSuccP9SbyYojAnOy7k\ -GhyzwAmXxTQ24G45aIq7BfdSR70GwWCDtVBaOqSK+VqWujIneekmzcaEpp/sKeC3qq+VPkkZ1WIKRP1oOUjojOliqFH/MIcteStXdqk1Z+2NcKMA1V0BytZ4UA1i0ABxm4cIHg74m3z1m4qzuZUkx4ITPKDlvedL\ -+Bx9yqOMVnjlYoVRSFhJl9zsJyyRpFBzopZ/jFDWP3gsxhO98O/ZGSktN+VwNNMcZAoiyrriOFt8Wma0tcknoEypxVTcGziGEw5xz2VHosPOuT3pqbHnfCkzY29KPHeAlv7Vuv7W0zPfUB0UNq/vDq5XxbL4+e2y\ -WMA1vypIozRspSnjN+0z372uFrXFyNn6c3L5VCzCf7ho3maE23bn9iftZlLjZy4VwWtPlWyNjrlkWd4ggvD64fFP5lfng0fzJT9s2U5+Zg2EHKtjO40bBOpqH1xgLWM2TkOlclDrI+MSt67vpvkMUtv4O3uIOAlz\ -JaEoYkUejD/wcYCPT3d5oyjpzp/+mzPz6wmzTDDecZDeRGbiC4NSdIkJ/2/MQ7wahmY4+nz4/nSjbgxM1wSmpbPm/u1gK8nmqNfunXXtHoJ0y3qoOKzT6l2lrHpz4yEv1yQG7mWxttG5ALDo5Wd6Y2q15oJs1evf\ -vzQ77LWjXjvutZNeO+u1dbetevB0jiargdvo9HRv3lanq3d0/2V/6op2+Jk8dBVPXcVj/XZyRTu9op19tL38SOvNR1rdq7rXtfVH24uPyc6Vf58rt8ln4Wj5GevuQ95coQV6kKseJKqHRdUZb8Nt3HAbnWFvuY0D\ -t/HEbXQI8ranaXpwFr227rXraI2UqP+iFP/VWuDPaok/q0X+rJb5s1roqvZn/qnAZsiMBKYoeXQkdMSSFps9kQVjjVMVRtLU5f9jiNWV+q13C/9jC9fvjdM8iIOgfVO/WS5+cx/Gv/8vm4YKHA==\ +eNrNPWtj00a2f8VSQkhMaDWSrEcIxXaCSSlsA5QUet020kiCsoVNjHdDWfrfr85rZiQ7BNrt3vsh1CONZs6cc+a8Z/rv68v63fLnt8tisby+N1BBGqd5EAfB7uB6VSwL902UhkEYZu0b+KZ9Vl6fvyuy+TsVzN8F\ +wbj9R83fNQ38zQ7hUfcva/+a+s63R5Ov2+/i9q+Ernfat5ob9R3qljmflW1PlcMsY+pJL057E6j1v5XTh0BzANLdmWiGHtT2o/Ha5czf5foGr6MI5Fc77XW3+z9pDUHUW3mvIZ+XHex0EDLYcWBrkZ9VCMYzByCg\ +ifk6h0btNHKD6Nh5Ax+r0g5dBPNFDxmZAWG+lJ/H7T+101ChM4R2wCgDp6Eas4j99nHOAAUuqECconKgCxzogs5LTXOZedTIQZHq0jwIHFbDhsxeAmsJobPMaRS28Qy/Gu8+wP8Et/A/744Me9znX2X8Nf/S+gv+\ +pdoJ6pAbVZbjr5fmWTtIJTPmLWA1cvH4wZaAxEN67egVLSpvvywUMTl8otrfOvCLDR8JSAsOi4P2aVhM2/HDYgLzFe1wTVjcoa1SpzSaNiiCKSJ4qIgVEYGAnvZ3kLgbDEAKv/HTEJiRZ8300IP+B3eJHIFqmwVv\ +I62ExkoeDndh7gENqQEt4VTgl4WMaNKqWANqgQ8ZFYEygwFVwiAemAc49C78w6PF/dEuew6wIkIm8uMR7d2mOZcfjKKwZEB4MN2sGwy5soU9B+5r9kID4zYJCZUs5DNBTEZvaBLzYsc+VVE4ATYJuZPyHx3gk5Ff\ ++MAtMC4QCd9GoR0rAzwrFfiDZjpfbu92oAnbr5kMmtdUlv01CelBVkMjg2ELlhpZS72Ccd7ItJHvzk/jKTWAHwOPNiCK3pY5y7aLSu+CpMVl0ch1zcCoS4ARaItmlcy65eKqYr4hbNF/qxAEN6AKkZwQ9EGQho8a\ +gbZ9mLPQa5K3Gw12nv0oTw7mb5oN6fqA54RvKlcMNQf41Tn+fuJMF1kI86wr8vIOcEHyniADLDdvnSFEQyXcOWjkq9k7O1rpjDZ7Dc9n7TcsK5XuISKnubYbkg20urF0hgctIG9o5KYH5xcWCVlqP1EuAFN57jsP\ +nwtUoUPXSkEPFe22Ey7lWUDPgMMB2t97vNAla5Zcc99F3XeMhJGLK1WBJAfNBaM/Z4mUGD3Y8Efh7Ad5d+4Kld9WWbBuxVZdEVMrnPi1UbC7E/joX/2PTkjkqwIXRAyMi/+CemX64QBYMD55AkqN5WUIuuQrFlEJ\ +S3FrT8CWQ/H6ZmW6x4TOOqC5NM71Jf9Iv6I1wByowlaHpmU0ly0jWbuME1btNWD6e0sCsDOqULb2lkH4M2H2nxnzQpCyEYr+KDS5tfJqn17p5G8usbeky+whPM4eeENHxLuAhMJ3znafZTwfjBXzdCpsR9n8tFFm\ +IgJSGggwFMSziYtcj5jRDhfybguccRPS7nYXo/mS7YL98ZhYA/UTMA2oEW1lJw+Tg55Azhf1XjczO1NdHEwt2cGArOuxD8OlX8D4jxm6USkWxJR/oJx6CjJfJHB6+hSVziE8PD4cQAcAXI2jAcClRadoJWse4O5t\ +gZzdcPACYwNeLBoc3Kgkmi9Bnpi32QmLtCxkIYTI0cnAiqqM5AfxBIkDoTDav8g1s8GqOPCE9WjbdrgvSHzhvp4DEzTfCi943ZnsDiBRpdLOZ4ZviTvM1Dj4hCldu5R/R+TTOu3yTaP/oUjJNu60+UsyOJo02YXP\ +B8DiXbBywzFkm+csVQMEtd1IYPqigZ1941MrGA2/H1AvjcwDMqt5TqBhh2iGTsfIYJaXr5ytVlk0rWKUhJRYxQIvskkwWN5dsC3c/oYRF46hoR2XckWQgSmuS7FllEwBZosKW6aJUARMheBtZ9zLTWmfACxBvBUS\ +3a6j+2wJq/RGSjhEqgKZgjgUrYbT3GZ1GqXsgOHAHkO7wiQeGZNNbS0yFLamQ7br0URNHUwmw01GTdPvdxumujkX1FX99z4Zy3XGHfJ+B2bO2HXRfDTQ0UyPpvBv/Gw+ByvsnzDKjDwx6r7elIzQjowGwIXAqCg6\ +kB3v/sCETICXul7hx81iH2U07R4rD4sbzHi1Y2vFHnuj4L9pXnIZ+sx3StzPkjkl8tFWXHg3yuIaOUysa6+nLFllL4XYISyA30cP2PoNvdE5OyU18Il34+wb1tDFIXnNYJVXxd/LYgcH2R0/Y5exIOMYNqlCMfQr\ +zHhBBj4pjF8JBrBEa73YpQ8zII8abf8KExZbi2ITBx7uPwHZ+QG2GnSIX4IYAY4uI8vuGAeJFaGr5TDcZdv0HjESMpNmwqSukI2Ij2A/wH+zMIdtkJODUaR3cvRvN1/TJ+3PLbZfQFe02AHDT28EGE9q50iZqcEI\ +y8WPir8ufyTM4WZtkLpvCBFFSiK2RjcLWcj7jcYA7aebnKxVFEAj9jrxAQ9lzSQzQO/TFfhR/dcw9/7OzPFhcMQFLenacYpLem3Xo6LntI7ZF07sQ+AfWfhf9uDPQ6PhZTcEXu100tjJ0/wI/htBACp8ydI+uAYb\ +55U/LYLHRVwWXwJ9gEeZexUx3Yo0QKinXvDYi0sPP/Ii4nHadDW574OG+FDrfx0PYtmc2QDdp+PvwOctn/Jw4flzZiOMDKHHgi76i9TiPxiNxxB2EcMiGcO2iYIGmEbPeKhkBfnePRh79yBnRJM5EkSuZGFWapLb\ +YyIhM4f70vAZM6g/2OYtqmlxgY68fZgrL4VJaRgtUUWhayiE9GV5PIcN3Pg2jkrk5N/VWKQ2+OE17JisZPZLWAHgiOesMlptudkup0wH3mSHVAbstTqakFaDZTXVCVBhA/XsJgqD6hYiYvMjiMgNInY4hqufnJB2\ +awo2J+IeR2frVz5zLYE/sPSss3ReBofWxrxgoJT6APQb0EcqsGauSh6SLGiAP6scF79x6eIXsnL0CXAcfcJqOp59+rr/JMVh2ajvIEwVZKzQwN5q6lf+ng+sNiXFZEjNvmKdTWTlvcBruj/5dO6HqSr6y7VEjhY7\ +mkYoayKJFchg8IC+rSZsotZGxL3y7/uCJYKap7Z26YQN4+pVdD/yD6CPQbbHqICRgf2ayshFGFnwIKhVAE+TzLomHgZsFVhLoPyXud+6ISAqKe7VtDbG8lY4X+65dgcEIxGowMcAR56w55Rw0KWLwt23MwknSzAK\ +OG4fMX/tUzluPzohdVon/EncJyOjPPnLZE0T2A1XY/5jiSbGlsNhlu0chzQI9g9mtPAgXBUqrTTJAXrYjcHCg9h62SzuCoBPrfFHuughNargAOyD0w20Eq6TSQWhLCRE1YvSRUCFcg0AGQKQGQAYUWydG5m3CzbT\ +Eg3+99aIX0O4XVBS7WRltmY3IZUgotnSd+cYgNbozLyHfy4oqhooCJSF0EqkldwEaQW2vYbVp6TAF2hf9XR4ldP2tDp84YWiu0lrgwaHGfX7p2cNh3eAOE3G4QlEd7u3F7O+x9ZbD+Z8Ig6MImtsWXeH/GTmJ/8F\ +bJ9dMcZBFFTTF+SQcTrhI4vS8ZpFSewjG14oMpyhi11iu+J23YC5VHIX2fRA2Cq6YGsX/FodnlHWTuL2eTyV4Gfps6/XpL6kESTHAzTWy75rOz0yn9IOyzIZAiw8SLXU2R772xDISGW8Zni0OLQfs5WOoUCMRCon\ +9AbYhTh4Kx0hF8CbzdHl1z7HqMHgswgZrf/PhAwGNxrvLRGTNryzvsk5v4ChQhwKDC01njGFAV81+pvBwEZI11gGR8SKcxjvfjTYgu8hTwTaFJVFmSSIpxcWlNb7RbgfY4q4bzwnfR4VQrVc6JrNM2YcN6Gd3N6/\ +kmZr7C+w605Ivejw/4Fi8L5FjfxVnytbnAebw83JA0KRtUOtojZGaot8L0V97mP8JCEVq3SE5IlwTkjkq/NDlzRnCyAX7vTx2TtQTwswf5+BK6IOxeVp9ZVyabcoaKz/WRUw8+uTPXhK6x7OrzuxqkCd9D/wmP4t\ +mXBIBGq4M6VcJOZ/1KNVFmk5TLUMsg0BIJTRWGvBU2UhbE/lFzcR8i+sKnS9sCxxo+wC/BCTUJErinCvBNMN4fLDqaafLRBfkBJEJz6WeYDRFKQz1UNXA7P+x6jOAtHbtgpS43kGahJaGUpln8M9NGO0Q9TOi0NO\ +WtUju1w0L5NNVh8G3ZxCZlIv93yBY0AiHP4AazlGED6QWQp2bpOzT3qJqo7AiAQ/UIMLh2m6TCZHIuZFxokuwWPCmxe9XaiNwJS25IDTaYHb7BBy8NGiyM7SAYfxlQqLNPSSqZciKPHCS8JiexwNpl52do6Mf7go\ +kmmR3aPYTpWwggWbJk2DsyPCYh4c2pj8eKymxbb1PxHIjHOAWE2C8TkEf9quafwWBph620CjaPo9tBaSQAdRkZKdhEZUI18FZ6ASxxf4LdMZff3KxxGQO8Tnr4N8Ivhg3GOZSNiu/AxWfnYIWwDolI7vIa/CExy5\ +iufLdj0wRyzxBNhALcD+dyjUpybwVy88RPZFi7X2Z6AmLYZh52ujz1I2LcuFl8J82RmiHoPrQZAFvDlzBGKMbHQW0dry8ImVhHnu7hGMlrG4tWUf3s2tHRsEL1Kb780qqw1AVFecP6e+kluGKDxAXiS+vNqR0PAI\ +g3YgRQEx55w/18ONM58RZzI2zBawYXKJf6rx10r2zD2CWXLrbvkCdkjHlHlN+Rl6S9fsYkzJjyZbgRazQ4EaMHob/YFMSUfpYhwHtosOIKYTxPcBy0VEyA5tnA94vo7YUy2nN1obCKxetOJi1rGJOJkQreiWvnzc\ +aUfvLDqB6Ub/PafdUj10nM/UcSJMJsDQcGoLILLyZmeOyJaysAG0ibNuDGjiGwSVqFiMqMJecvnnd5d5Qpd5UFAFA2Ee1N5BrmDsjAqN3lg9k0vIUDM7xEx5VYoRElvyg6VpyO+jaiAAfJ4IyQ/JSRQn7FU0qdgW\ +Pjia7SbcMvUMNEXUMeuctDia1UqhAafVGfxLQRK0EpQEBTRloHELb/V9zSnnCwL0yUB4ZtFpKPsjJZmLfJW9Fs1RbF3lNiltDJk5mrv/ICQSBDnW9lBuw5hQfsFxujtXxOnWcP0GR+myeNVENMyfXhGpczhfs4sQ\ +kOWwuboHLP8FmdkP6W2YyvsfWitRMqfPNeXDsoJTMirHsS5grFVcAFwXQPALWOHwwrsLQ6Kxpodb92mMZYctSKYTZ/CASosEbFBwLcHGaVnkcO8wJBypK5ztn2kl1ppr7Tdytt83PYO/6xCcb8GXU6SQQjdPhUOi\ +byKVP03zgvcFx5do7Suc9ASkoo/Feyh8IZrR6NUI/4Kqve73YW4B9sAM4noHNWVwovdgHUEardGctkOMqYP+CKs+t4cRNUhoYpy8jHL6BRYhxt31NuU7QdwDXCVasU/stjHasE6mLCE1aQbUNxHXVSYjs3V3jnPR\ +nxsiZ7+1Cc2GqxSNdtXJNobNuaStxMg5SMeOSi3/IpWaiUrVl6rUIQtTLCiNuWzzD6pUBCntqNTRGpXK8eBrnyNc3nKuku0hrLus1mnX5L+jXfVfpF1ZmoSrCnbCZRuWhcai1ywLoQc0OGUWQkMqGOyo01OOWyam\ +fhtDah9I82UO7VW50dF4KNdOX6Ali6p2D+I6RTMGaxTwmifCADNTGdBXqithkYEjJakY44UYq7Ov7XYylTua/EAMG8brA02d8GrpxnUlZGKMY0gcp+C05bZg1vKE1BFsDC7jixXasA9ZBoY2Ey4vL/f8DpkCh0yB\ +aknD0imyGxkoocrNDxzK7tk3WEhi9uLCEg61D8jR8j3uzdUN+kSMHqHPSOjz2slcXkIort805WSbfWcDdF0+XYtPFGyDzU/H53QFn+e0F5vyvn+pMwKPFdYltF7W14zZJncwm5q4iSrvfXCsuxQXfSY6HEvOztCL\ +fO/TQywXKA2+3xub0hqWPgZ5KlQlaMlBzq7BEhe/nTS86yjouIPlcQ/LUi9RPn1tycVpeRlJ3Xg6eyEEpA3eSPYDEgOFIBlDnUPI5cHYJD8aStJzkfemxHjLVyU8Skowl1QCdmoCG7M6ZDgksxDgZs8uk9wbqAU4\ +iV2wTs8jKIlrqo9ZhWFPaNuId9gX2sbcucmJsb6JyEKWRHjQMQ+LjkkYdaxBkc1OiNc169ZYfRIpcu0GIlosZsZez2jQyRDNgiMhCHpMRqliKUEjcUjN9X1KnY5ZsgMTBur0FzEO4hdsHNjzE10rQaWnWA16z+7h\ +DOm7zjgw6xjC8r4HGF1nmxTDKTLuESwMuC+IXx1iwM0EWfJYBM+hmAX6RpTelhxT0rcKVnjMVa1XslnGbFZgDo79RcNh+X+Aw/q8FawzEhB3zhmCavRRI6F0jYSHlxoJ8ZjL4QssiV0vNc85HHkpQ01dhupam3T2\ +oJWaEtCzpkKuhjQo8kZinG9BT2LZgQxFZodLDcUDIXa8xk64RDBOuOa5lE2p9g4xtzItNieUiIV3IAT2Yjwvgxljlby0hw/KavrpLLZSMtblspKjR2XyH2e08mo59gKEmF6sSLC08wEFGhw5JslAq/EEz2eOAkLE\ +5XI6rCjRgYZeUInVOnJQ2g9GWFOcoi90hmOjXxAWw+Bg8L2IwOO7AzLNhof3srtckCo1frgxit0nFBPHM537TzwumADlpTfzcvbzesI4yfw6X0CJvnH0dzFKjzlvRVWXMBoZYMFww3HvVXnho05eFENUtrLPy1IK\ +jloXw5yFnIqRVHKooJredZ8rbCpphrcifBDeegrbJpH4ooi9VDxFDvejW4LjE1ANEG8kDxU+VK+esrWurOjGQ3B1/wAfROvRoE65LiTk7C5wq63H+gpdMcwkfXKIc5dgIn9s9ncOtFwW8Rn9JQ6ZNkncP1yaJQXZ\ +UitzG1Gx9enp7F3OCREeTlbxcJVT+mfr03SvPo1K2NfUZM2sgv+87O8uWQPW9cawzH/K71b/ps2pyuaIJ2K1hNNjtggNzZTD2aWstQO190+UJBt5ac+qZpdzMyiw2INAbYFlQGQ4tgsfQlnLArYLWF7xb/DrF3IS\ +MnyEISD4MfrAJWPAeRylAmdFjziclLL5gzhDAj4Dwii2s4tjIk2DEkEfH4MzRhWzbq4fpC7gxwbBfmfTTdLR+jcqmeUI4HYvKe+kFPHMWeE8Uz/8RLIDtpF5CnnZ4umaF9FlL+LLXowue5Fc9iLtvcBGhmZoEV2g\ +DX22MQFU+4RvPFoenHaKwNwDP6W/Z0Ya7omJfAFradBkgIx3ULeYx7glZe1bLfYlUeExmdmv+1RoEa4wpM7n+OAoBB9U/qXfd+FRnpcL9s9IBdNhGe/L8++gf0vDH5mw+uVt4tUSzvdqOckVCePjsSnIEOLcxdPn\ +tN9rlmQVxw8gyVSEH0j0oxAQzuS0Pwgu/CjjHRr1osciyoJe4bOcSYP0W1Wre2Qi3NjGKt9GTgr6cg6Bz9koCEUXOxvZfIFRaUAR/EVn+zaRqkalnKvAGpkKBcLpNbZOy5+Ofxoc81E/nc8Xxz7IQr1gyNKbxELZ\ +KDIHyrFYw7tBB8dUxDPrI4oNZLUcLMEvtvdBLUwdvVzLFq7JvNQmxCsHhNIdYATtYBCrmmoYSxupCXKrkE8yxqzhWOjLSuRnt2Pejg1ni9EaCuBsNveC3Ebhse6Cl+pmn+34RFL/oU5OzHgdCL9z+iJgsyfSce34\ +A7qyQIJyBc9V0wHDfWC0mwPI50GOLjPnXJkIjEo8C19s70L/VnTOHXc07F/H4RwOAvKPeqe57BkCczBQjDl2Xkg44Pc+3wRQ8VkjKgz8kotAYKs0ebsnxWrAA0wavagboCI2Bn+jlWdSjIxrOHrwbD5/+eu7DwgJ\ +H40SEnWO/1ZO1J73ZxVakLH0uXDuVMlXyr0W3DO13IFIdG47cA4O8iGSQLztQszs/Gg+z3bxJgcPT1K3j3IbfyLXHALPNQfScGs+c86h6QyqByDcCfu5yY9D3q14Kg/f8eoEYbXAHHoH3XssdOjhTRUe3lTh4U0V\ +3h2quVRUPu3cfkIscspWXeheDBOuuyUGskKN7lytgDcuDAabJ1O+lQKLyJuJzeO4Vy141mjnx1937mPASydOlp0ezs0NKiT/drARmKVkzpU2av39NuBXm8thsti9D2ZsrqV5QNU0eJmJ6nya0acO7LjfFdsuudwc\ +MpDjr7ikJR5gw4Rd1L+MQs6zUUnxEkTmB/ygUZ2ueLjNnB5sBmCaZqNvpa5VTl/BbRdBxP5tk0/kR9t/fECr5QGfMaPVeD/E/UiiGYiHBoPmFYQemth8UmLI+/5dC9Qhz09fenTXStMgU8WUP9v3wLpDzwHhQUPN\ +vagDz8E+ImXbLliK8znI0zQrrGMBek7nWY18cx7HXW5TcnRgz7eRPO6AZ6v5Xhw8IYKnDjmBi0HvRrZzw5xvKSxVRZlH5MaKOeYJFbi7zL3uqCuMx3aZNnDjbkmHx3RY8IzqVwnHF3j6cZfz36w/Arjno2YTX0lC\ +Vo/IbqWHXN8Myysy2bRxB+F5Z1MiP59AnW+z/YBLOqL59Q2b7VXh5HuGy2jx7d3BIJaTN/XEgYAE4G7BleDN+GlnB4UYUg2CzRO5RAe1SYN2m1EuTZcfFJfO2MdT3WEPrP0jyZI9GCAf5A+y3T1/Z1fIC9S8jIoP\ +5Goi6VCjdQFaSd2lpVf5oyNQ2i2/L8+R+62aQvUBWWUstwHvuoKbdRTerRBzNFDL8Riu09WTrv2Ibk8kZKgpEPSGnldNn7x9C4ntn+skN2p2BxvjDoI7rsFwrh+aM8l69d6NTEs1v45b2wq/Gt4ER1eDNVSxpkLL\ +NYfrIbJzQC3cdJE94qMnTWb2y0DQjECYM8VwHg5LQu0mYHkqZu5jlELBfD55vvlIlA18Ee/EdO/ZD77Z9hrv0tD5dzvwFRSUr9gDmbrNlZG4tlGwy5bZx7jCBVCuQykR0kDd6U8iHTBUvb8WhE+bqZ3A3Bcgh9tH\ +d5lx5IzsSJQEwiTd8Cx5dBlkWBmhPhuyHnREJVaLSDXcBHvMGB+LWFECjf2dlA+uxe7+vFrarm7QyiVsi73zsLAXTKkV4zBjYx2A0wag3m0GqlyHJmH1Hm9Th2euXfHSbZy5jaXbeOc2PnTv48t69/Pl/bZ7CRtW\ +cmfmKrVv8FdsnlW3nCv68lzuUTPmnItWvhQHBQPgFwQeSjuQeq0QdC9Tg2s78LY6OAIjsUZ0A9heVYWPykZuQGjYrVAYuHIcE/LOHzPDNOGvfCPIWjEFhbglR+86FbwPJEOgnUsV+p/imUGwYClkMHwEUx2KfYF3\ +3mDXQi7BwlW+tCcsqkQu+SHfBoPo6EDIqa/Gmj6wVLm2rHj6m2T2lJHC1cryCls30078jgPi2l4S8yvHZhMx0iZiCd1k9i0OYab49hxO75F1iWjpTR32p37Et180NjDRQv2MgxpF/Yj3DD3/BZ4XfBuGA63Hl0vg\ +I8qgYygdyvvAk0FJ0px9KSwUZaI+Q1u3XdU2K1gLUuVcazv5tHaukQvX4LA0C2g4ggPyhy57ecQV0o3NDrVDHtE6S8zGmuNwWB8/GjwNMLAS861DAUYKLX/cT3xzou3QPRcNEaaIBXSZbx2Cy1CgAXqbJ8day7V3\ +tckBPTGrEExIc5CN5NzWV7KV0bvGDfOTeDFFYU52XMg1OGaBEy6LaazD3XLQFLMF91JHvAbBYIOlUFo6pIr5Wpa6Mid56SbNxrimn2wp4LeqL5U+SRjVogpE/Gg5SOiM6WKoUf8why05lStZas1Re7O5cQPV3Q2U\ +rbGgGsSgAeI2DxE8HPA3+eo3FUdzKwmOBSd4QMt7z5fwOfKURxmt8MrFCqPQZiVZcrMfsESSQs2JWv4xQln74LEoT7TCv2djpLTclMPRTHOQKYgo6orjbPFpmdHWJp+AMqUWUzFv4BhOOMScy454h51ze9JTY8/5\ +UmbG3hR47gAt/at1/a2lZ76hOihsXue7f+GGX9+9lRaFwsjJ8Dkhe6oJ4T9cG2cT4VLduf1JSUtq/MwVIXi7qZIM6Jgrk+UN4gFvGR7/ZH51Png0X/LDlrvkZ9aAZ7E6ttO4QaCu9sEF1jJm4zRUKuexPjIuMeX6\ +bpqPGrWNv7MhiJMw8xGKIpbXwfgDV/1/fLrLG0VJV/v035yZX0+YM4LxjoP0JjITXxiUouVL+H9jHuINMDTD0efD96cbdWNguiYwLZ019y8BW4kpR71270hr96yjW71DNWCdVu/GZNWbG89yuZovcO+EtY3OPX9F\ +LwzTG1OrNfdgq17//t3YYa8d9dpxr5302lmvrbtt1YOncwJZDdxGp6d7wbY6Xb2K+y/7U1e0w8/koat46ioe67eTK9rpFe3so+3lR1pvPtLq3si9rq0/2l58bO9c+fe5+zb5LBwtP2PdfcibK6RAD3LVg0T1sKg6\ +4224jRtuozPsLbdx4DaeuI0OQd72JE0PzqLX1r12Ha3ZJeq/uIv/ainwZ6XEn5Uif1bK/FkpdFX7M/9UYANhZgemuPPo5OeId1psUh8LxhpHJMxOU5f//x9WV+q35m39Zrn4zf3/XcS//y+/HArg\ """))) ESP32ROM.STUB_CODE = eval(zlib.decompress(base64.b64decode(b""" -eNqNWmlz3DYS/SsjyrpseQOQMySoTVZH4rF8pNanLLsmtQFBMnIqmbWVSUnyKvvbF30RIIdy7QdKJIij0eh+/bo5/9lZNdernYPJzuK6NRP/Z3oIdwrv8uPFtfK3pfaPtb/axbVTE2o0ZrHyf+FO3Ts7pbfY0/4/\ -PTXMp6iDXFqJBCq6iy4jEjUz/9pFa1Z0r3ybSru193DhTqaNNeGSC5qPH3dhjbPLXpddmAPm1WYCDVPYRqLGd6DUEYnYBPl07mXkZUGWpo7kdgNdlSWIEDcYlOnmbq11lw73ptMY/W/dIU0gF76cTqJj3hBp0oR2\ -CXKbzN/PYDNGNnMfWhbXdiZal/6go3Za+FfwkJvkKIMj9ZM4xxrM/EqtZglyETlq1NAzO0+2/GMWVAZbbtujt76Dps2VM54bFNreoUR4Wevey5P+gZ+iclfQ5fRE/QDtT05Ok6dZmQyULYoEm0Qp1cBA8aF0D8BV\ -oI9Xgq1Y8yY+Erifxs9HR3L3xm9Gxuh4Xqto3nBUU5D5OBwMb+gc7B/ew/G0T09s0C33gI3kSq3gLN1i5Ts0DXWoxnRpDR2VhXsYZfnwUdH+RWXZKTQLz6bdsGl3A8EHyti0K8QF7FvyOItocV2m4G68Bl+wY+3n\ -dyVMQRe0ddO59DwaUZGGwz7SJ/w2mhtlTnntaB1TgBEdDtUgu9RhlzXpa4dk1yB/ThCk1K3vamgyeAGb9C9X657bodXA9cGMp3OZ7m6U2Auy1WkHhAB9IE8aDxQdqSo78ycAPpaTzHXOEFmrngm8p/X7yLNPeuzg\ -jpaxfCy2pjGoxpSc1vL7umKXZlNpIufq+rg5Q8pAUSaehCcXR2/zr0xYc5/peh/aGG3jIGVcSsOaMIc86yrh2IPSswRomT31iFJspBS0HDsiIyoL3CGbNCHOrg3N7xI9jp9yfx4/eDuswUlnHmdq8zfY4hFAVdQM\ -iAZK9Q/5xgatDsgpENuOCC62/DLonvby4ns/W1UTvLs6GOfYEfmYs+yvRyO9UA7iE47LhuOeYnBx6uw1acxGgFNFc4HfWcsabEaUH4EPonolY7ZE3IcQkUTXCRyKG2r+Itb2p/hhFT9cDw5FR0fXul/QnSh6sm+B\ -nBfsZRs2YD3qRAKybRl3zBM2XthHUYkS9hdLcGFzKf3uOIiAHo8RmsmD828jK837GBNGe3N3CIQvhd48pa7a+phtSqIMJv8mgl2U3yurzMjINWO/MTRrByLqyR3m5MqRXTjyMhfhNGFhmSJ9+QnuHfdAdVWRr/Mq\ -Fa8CcU7ommhg3TydWjfPp1ceHCp/1dNj8Dro8cILUchmfwDqMX3st2AdTdwRIzmMXE6YlOJiVpOPHIFQHT85eME9aN6i/t2cKvBkXUVzs9Kr/BGzMnSGW/YuhFBFwyHigW785i4Xyw/+xoH/PhOEfLu+G/BIMNO2\ -IZ1AqKzq7UcJOaBFVP4ZVp+QV6DLssg2H3dbq8fcls8M2c8+IAsekL4LO19t00DUh31H4vH+l9xcFrOubcU8wbL3Fh/BSOeEpBg088ChAki8eIigS2HhmGRGRyYimDkiY16vANzTD69fLBbHNFkIfw010LgfKCJ4\ -IrP0R1y1I6nGII5RJnaPAicqqeCTqsJJAc0B5lqx86G7ZTEJH7rbQcJxarr3ZhcG39/cg3+7U8rDymFwNP3M7ogxE2mYPTy9x+EJsRZ0ZnnvcDKdH2oWyQ1F+q47tpQiQsOsE4ekHM6ZjgMwaf6v9BaZcgewaZSm\ -ZWOs2IgxTHoM6yIKLa2EpI3gg2N6tGqTkq1hSMeDaYe8ogtnDcUKy+lfmQKqoBjuWGRJ47QcW/SeQbeESGOTg2Syf8wen+2dludyonHed6eAqhfEDv95evwEPJrSFdL76ohnH6ZMkrH2klIGcdPjNUe9FHt05cAY\ -JX3aiYCdBZrEPbDNHd5e8KQNx+Df7qPlmZRN0bl9vHtO/8BlZzwEA5Y8QJpbkoSKzt7TqfMumj8nA8Suekpz5RyHIKVrsg6blwlYvTnhkx3kucFwgK0jqwmZSJRXwwWcIH2WFCkdJVi/06AF94xQgIKoX66Gm2aD\ -oayhdLAuo7qKu78Nfz901v6RI7QOwvdlQxhOyRcweoesO/XojAUIbksr2eijdfcgNAZdVJaDbj2SP1QSLhpSq+M+SITYtduonaZtRED1ldgKimubVxDPH2xArgmPWhD54LJXQoKELx9WkbCZnKxrLUOrLi4hMKhL\ -Rm2dvlyssEmXL1tiDrqQXCSTbkiQwC31p2zSfg8Sm6SX62fly5FsoiAtDZMlx7wZJDIVWUgHiuOLkxNoyPEqxZzOAMhDnIEEUxf99SE4d2DO7QBmdqRd5K3dUN65WHynMJK6zgpSFoafXHzuKnvZ/iKcloIkAkF+\ -tdkW0v5BGh8vlpjT48T5U86+c44kHe4AU6aRS3x8FxYo2i5Jui7jTBYwoi/iFckHG2uvpPGW92hwnlb6z/8M01TxNCb/ld/kdHKImy50mRe0zG7LJCed/0N6wZl6AThyttGg/bB1k4buur/0obzZ7DWfiUT/RQdn\ -HqnRkB/69VbShA5TUFnG5DeiLXmd9mZN4lfDwwZOi5aQr4KiNBhhflEwd8iQI5j836xZY+Sgmdzihn9jp5hJvvPlD8yZl/NfJWQDdT8G+7wdAsYZoagG5K8BGXEAc3/jvqfRVGU/OyfTtpAHIOPLorjFF5TzjP7z\ -rnWKT4gpnxHXFIGgU0UBjn7whblgtib37+vzLUFV61L7hWxGcpr8bVCtKnoKfCcn/t2gC+WT8zdo1Qes+CpSvEMfmf8Yn9p26OLyZ1IOPwHJX0VhqRCs4IqTLmXa58F6q7bvg7pkAYAnWpr0+dcmtSLIo+DYVUOU\ -cxU5AVAtzdSMZkI0W0VWiy5f2oH3WJOY91yuM8SxDKdCTgWah/U1CByQNyNkcz1TOjRr3P8LFWkhC5NkV1dXBNclEBa/wR0ivF2xa8b9U06303BUIpXWAr0FzWVt+OBDNT8loUBdMQNXV5NPVL90cdFQB2WVyKvB\ -nvFTg/pM0rRNpz0Wp+Ct5FRMwNTYdOdmzi64LX2MofAdqUW3AcYMwocJqG2nsd0G9FD5JDbMzubnnAkw7qLlqTHT51QL8ad7uX1ad4c6l6J0GxdfuDiAb6OvO8BWdBmistiL/78EGvptpKrWXbBRFkLGFLE+Kr+b\ -4u/7cC5QtppGNlZHpgV8HFAWzapgk4K6COq9eXZFRTSVffn2E30EwMNF/GlL5FjlYuU3UbY9zO1aIk2z5t0we42dsktvqeBWTOQTA1AL45iEdF8rjBsjFWrIKM4I9ZyLGIUYKMqMUUpfYYpMoX/+GvfzizgHFNrU\ -dhePIL9o56T6sQD54zDK6eK7KMDqruNWKC7IXGIHWGdpoiptb0+7Cb8p1/me6/x48vn4C1PrqqJjt3HiPxsnixARGqm+6/U+hgoUvdTO4tfCFNAlYSos3w9r82qLyFK316xfQyL2mfbZJ0issW5cTfqICEOQ6jPp\ -tNPOdC77UqmOdmcR1qUMXJqBq5sa2H7BabAjV0Rx0bshlZpyKoWOKX6S33wG/SA737O7WzC4XOyEghNOBNBYc1Xa6a2PXIQw0AozcmiBGR1XwRyT44rPDL8OaRLWcepTc0GnlTYpJGbr51bW4LKV2QJ0+0xBAwDD\ -srbBcKoS3oJ2nGLEArQCk7CGQ5YrJ2RhMKgqGUZlBsDzmr/SRdW2mse2BPsNV2Wh9EDMZcJ4ZEOJuNPZjD78BY3tMbtwjymvo0rPXNjQLn7mPmF4yGPuQCoTS6TiiRRGir03c0wKzj4Cgdjlj+Wwo6qQTmaYiuPv\ -DQR+997wV7eKqQIxgDP6Zldxpb2ajnie5o/v7PS2GfE8TcnwsB23hXPupiQz+Aisgr1SSawEU0oyFlymHllGjFDRASElqfl9zjwI3ew6MSnkhdkkfAyvpmekpgYCga4HQAFpbAW+2Myuw0EMK5ojmAJlq7KOgl0X\ -X4CKIcXImMmkUk5NuwVfTQJ/kf2XqQXEsJ156Z/Ir0UBZGw3DonzAxi4SUtj1EQuI4ltty0HpNNjHvgyTAqoIuUBULjJR84Pf4byFxVDmCaZ/M9oaomfHVy635mDUuYJTI1lIrj4GQx/IllM06+l4kiTIwhdp1Fh\ -4YY9yPW6wBu9ZNsxr64TdrhM/waN8SA8ARt/8Pi1z5npdy838smjjRkgFl5xF/ye9EJM1reC4Gb+HmYX3wRdQJEBjr1k74m//PphCCZJoAgoQYaf9g0zZ64r46fTUn5tBBiT3ZL705TbDCRmG0rhs3n/I5NcZfwx\ -W+1ukrWUZhMmTvbYEnKGkXiAk66EkbR70XXvUyWimOxAFEUSJ2F1GnBL0YEedvYnO7Vd2X/9sbKX8AMxrYpsNsszY/gN/WhMiqjQH35KFvefZpnOp9C/Wa4ub7rGTOXTv/4HMdHC5A==\ +eNqNWmlz3DYS/SsjyrpseQOQMySoTVZH4rF8pNanLLsmtQFBMnIqmbWVSUnyKvvbF30RIIdy7QdKJIij0eh+/bo5/9lZNderf/2xspernYOJVsU0y3Q+NfuTndqubPwmm83yzMAbGOPbqp3FdWsm/s/0EO4U3uXH\ +i2vlb0vtH2t/tYtrpybUaMxi5f/Cnbp3dkpvsaf9f3pqmE9RB7m0EglUdBddRiRqZv61i9as6F75NpV2a+/hwp1MG2vCJRc0Hz/uwhpnl70uuzAHzKvNBBqmsI1Eje9AqSMSsQny6dzLyMuCLE0dye0GuipLECFu\ +MCjTzd1a6y4d7k2nMfrfukOaQC58OZ1Ex7wh0qQJ7RLkNpm/n8FmjGzmPrQsru1MtC79QUfttPCv4CE3yVEGR+oncY41mPmVWs0S5CJy1KihZ3aebPnHLKgMtty2R299B02bK2c8Nyi0vUOJ8LLWvZcn/QM/ReWu\ +oMvpifoB2p+cnCZPszIZKFsUCTaJUqqBgeJD6R6Aq0AfrwRbseZNfCRwP42fj47k7o3fjIzR8bxW0bzhqKYg83E4GN7QOdg/vIfjaZ+e2KBb7gEbyZVawVm6xcp3aBrqUI3p0ho6Kgv3MMry4aOi/YvKslNoFp5N\ +u2HT7gaCD5SxaVeIC9i35HEW0eK6TMHdeA2+YMfaz+9KmIIuaOumc+l5NKIiDYd9pE/4bTQ3ypzy2tE6pgAjOhyqQXapwy5r0tcOya5B/pwgSKlb39XQZPACNulfrtY9t0OrgeuDGU/nMt3dKLEXZKvTDggB+kCe\ +NB4oOlJVduZPAHwsJ5nrnCGyVj0TeE/r95Fnn/TYwR0tY/lYbE1jUI0pOa3l93XFLs2m0kTO1fVxc4aUgaJMPAlPLo7e5l+ZsOY+0/U+tDHaxkHKuJSGNWEOedZVwrEHpWcJ0DJ76hGl2EgpaDl2REZUFrhDNmlC\ +nF0bmt8lehw/5f48fvB2WIOTzjzO1OZvsMUjgKqoGRANlOof8o0NWh2QUyC2HRFcbPll0D3t5cX3fraqJnh3dTDOsSPyMWfZX49GeqEcxCcclw3HPcXg4tTZa9KYjQCniuYCv7OWNdiMKD8CH0T1SsZsibgPISKJ\ +rhM4FDfU/EWs7U/xwyp+uB4cio6OrnW/oDtR9GTfAjkv2Ms2bMB61IkEZNsy7pgnbLywj6ISJewvluDC5lL63XEQAT0eIzSTB+ffRlaa9zEmjPbm7hAIXwq9eUpdtfUx25REGUz+TQS7KL9XVpmRkWvGfmNo1g5E\ +1JM7zMmVI7tw5GUuwmnCwjJF+vIT3DvugeqqIl/nVSpeBeKc0DXRwLp5OrVunk+vPDhU/qqnx+B10OOFF6KQzf4A1GP62G/BOpq4I0ZyGLmcMCnFxawmHzkCoTp+cvCCe9C8Rf27OVXgybqK5malV/kjZmXoDLfs\ +XQihioZDxAPd+M1dLpYf/I0D/30mCPl2fTfgkWCmbUM6gVBZ1duPEnJAi6j8M6w+Ia9Al2WRbT7utlaPuS2fGbKffUAWPCB9F3a+2qaBqA/7jsTj/S+5uSxmXduKeYJl7y0+gpHOCUkxaOaBQwWQePEQQZfCwjHJ\ +jI5MRDBzRMa8XgG4px9ev1gsjmmyEP4aaqBxP1BE8ERm6Y+4akdSjUEco0zsHgVOVFLBJ1WFkwKaA8y1YudDd8tiEj50t4OE49R0780uDL6/uQf/dqeUh5XD4Gj6md0RYybSMHt4eo/DE2It6Mzy3uFkOj/ULJIb\ +ivRdd2wpRYSGWScOSTmcMx0HYNL8X+ktMuUOYNMoTcvGWLERY5j0GNZFFFpaCUkbwQfH9GjVJiVbw5COB9MOeUUXzhqKFZbTvzIFVEEx3LHIksZpObboPYNuCZHGJgfJZP+YPT7bOy3P5UTjvO9OAVUviB3+8/T4\ +CXg0pSuk99URzz5MmSRj7SWlDOKmx2uOein26MqBMUr6tBMBOws0iXtgmzu8veBJG47Bv91HyzMpm6Jz+3j3nP6By854CAYseYA0tyQJFZ29p1PnXTR/TgaIXfWU5so5DkFK12QdNi8TsHpzwic7yHOD4QBbR1YT\ +MpEor4YLOEH6LClSOkqwfqdBC+4ZoQAFUb9cDTfNBkNZQ+lgXUZ1FXd/G/5+6Kz9I0doHYTvy4YwnJIvYPQOWXfq0RkLENyWVrLRR+vuQWgMuqgsB916JH+oJFw0pFbHfZAIsWu3UTtN24iA6iuxFRTXNq8gnj/Y\ +gFwTHrUg8sFlr4QECV8+rCJhMzlZ11qGVl1cQmBQl4zaOn25WGGTLl+2xBx0IblIJt2QIIFb6k/ZpP0eJDZJL9fPypcj2URBWhomS455M0hkKrKQDhTHFycn0JDjVYo5nQGQhzgDCaYu+utDcO7AnNsBzOxIu8hb\ +u6G8c7H4TmEkdZ0VpCwMP7n43FX2sv1FOC0FSQSC/GqzLaT9gzQ+Xiwxp8eJ86ecfeccSTrcAaZMI5f4+C4sULRdknRdxpksYERfxCuSDzbWXknjLe/R4Dyt9J//Gaap4mlM/iu/yenkEDdd6DIvaJndlklOOv+H\ +9IIz9QJw5GyjQfth6yYN3XV/6UN5s9lrPhOJ/osOzjxSoyE/9OutpAkdpqCyjMlvRFvyOu3NmsSvhocNnBYtIV8FRWkwwvyiYO6QIUcw+b9Zs8bIQTO5xQ3/xk4xk3znyx+YMy/nv0rIBup+DPZ5OwSMM0JRDchf\ +AzLiAOb+xn1Po6nKfnZOpm0hD0DGl0Vxiy8o5xn9513rFJ8QUz4jrikCQaeKAhz94AtzwWxN7t/X51uCqtal9gvZjOQ0+dugWlX0FPhOTvy7QRfKJ+dv0KoPWPFVpHiHPjL/MT617dDF5c+kHH4Ckr+KwlIhWMEV\ +J13KtM+D9VZt3wd1yQIAT7Q06fOvTWpFkEfBsauGKOcqcgKgWpqpGc2EaLaKrBZdvrQD77EmMe+5XGeIYxlOhZwKNA/raxA4IG9GyOZ6pnRo1rj/FyrSQhYmya6urgiuSyAsfoM7RHi7YteM+6ecbqfhqEQqrQV6\ +C5rL2vDBh2p+SkKBumIGrq4mn6h+6eKioQ7KKpFXgz3jpwb1maRpm057LE7BW8mpmICpsenOzZxdcFv6GEPhO1KLbgOMGYQPE1DbTmO7Deih8klsmJ3NzzkTYNxFy1Njps+pFuJP93L7tO4OdS5F6TYuvnBxAN9G\ +X3eAregyRGWxF/9/CTT020hVrbtgoyyEjClifVR+N8Xf9+FcoGw1jWysjkwL+DigLJpVwSYFdRHUe/PsiopoKvvy7Sf6CICHi/jTlsixysXKb6Jse5jbtUSaZs27YfYaO2WX3lLBrZjIJwagFsYxCem+Vhg3RirU\ +kFGcEeo5FzEKMVCUGaOUvsIUmUL//DXu5xdxDii0qe0uHkF+0c5J9WMB8sdhlNPFd1GA1V3HrVBckLnEDrDO0kRV2t6edhN+U67zPdf58eTz8Rem1lVFx27jxH82ThYhIjRSfdfrfQwVKHqpncWvhSmgS8JUWL4f\ +1ubVFpGlbq9Zv4ZE7DPts0+QWGPduJr0ERGGINVn0mmnnelc9qVSHe3OIqxLGbg0A1c3NbD9gtNgR66I4qJ3Qyo15VQKHVP8JL/5DPpBdr5nd7dgcLnYCQUnnAigseaqtNNbH7kIYaAVZuTQAjM6roI5JscVnxl+\ +HdIkrOPUp+aCTittUkjM1s+trMFlK7MF6PaZggYAhmVtg+FUJbwF7TjFiAVoBSZhDYcsV07IwmBQVTKMygyA5zV/pYuqbTWPbQn2G67KQumBmMuE8ciGEnGnsxl9+Asa22N24R5TXkeVnrmwoV38zH3C8JDH3IFU\ +JpZIxRMpjBR7b+aYFJx9BAKxyx/LYUdVIZ3MMBXH3xsI/O694a9uFVMFYgBn9M2u4kp7NR3xPM0f39npbTPieZqS4WE7bgvn3E1JZvARWAV7pZJYCaaUZCy4TD2yjBihogNCSlLz+5x5ELrZdWJSyAuzSfgYXk3P\ +SE0NBAJdD4AC0tgKfLGZXYeDGFY0RzAFylZlHQW7Lr4AFUOKkTGTSaWcmnYLvpoE/iL7L1MLiGE789I/kV+LAsjYbhwS5wcwcJOWxqiJXEYS225bDkinxzzwZZgUUEXKA6Bwk4+cH/4M5S8qhjBNMvmf0dQSPzu4\ +dL8zB6XME5gay0Rw8TMY/kSymKZfS8WRJkcQuk6jwsINe5DrdYE3esm2Y15dJ+xwmf4NGuNBeAI2/uDxa58z0+9ebuSTRxszQCy84i74PemFmKxvBcHN/D3MLr4JuoAiAxx7yd4Tf/n1wxBMkkARUIIMP+0bZs5c\ +V8ZPp6X82ggwJrsl96cptxlIzDaUwmfz/kcmucr4Y7ba3SRrKc0mTJzssSXkDCPxACddCSNp96Lr3qdKRDHZgSiKJE7C6jTglqIDPezwr8b4t2FSK4XmZrm6vOl+YZapfPrX/wBWdMOo\ """))) + if __name__ == '__main__': try: main() except FatalError as e: - print '\nA fatal error occurred: %s' % e + print('\nA fatal error occurred: %s' % e) sys.exit(2) diff --git a/tools/gen_esp32part.exe b/tools/gen_esp32part.exe new file mode 100644 index 00000000..6123e17c Binary files /dev/null and b/tools/gen_esp32part.exe differ diff --git a/tools/gen_esp32part.py b/tools/gen_esp32part.py new file mode 100755 index 00000000..56bfe29f --- /dev/null +++ b/tools/gen_esp32part.py @@ -0,0 +1,350 @@ +#!/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< +#include +#include + +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_*/ diff --git a/tools/sdk/include/bluedroid/allocator.h b/tools/sdk/include/bluedroid/allocator.h new file mode 100644 index 00000000..17a3a246 --- /dev/null +++ b/tools/sdk/include/bluedroid/allocator.h @@ -0,0 +1,82 @@ +/****************************************************************************** + * + * 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 +//#include + +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_ */ diff --git a/tools/sdk/include/bluedroid/avct_api.h b/tools/sdk/include/bluedroid/avct_api.h new file mode 100755 index 00000000..c2713fdb --- /dev/null +++ b/tools/sdk/include/bluedroid/avct_api.h @@ -0,0 +1,279 @@ +/****************************************************************************** + * + * 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 */ diff --git a/tools/sdk/include/bluedroid/avdt_api.h b/tools/sdk/include/bluedroid/avdt_api.h new file mode 100644 index 00000000..59a9db77 --- /dev/null +++ b/tools/sdk/include/bluedroid/avdt_api.h @@ -0,0 +1,985 @@ +/****************************************************************************** + * + * 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 to the Audio Video + * Distribution Transport Protocol (AVDTP). + * + ******************************************************************************/ +#ifndef AVDT_API_H +#define AVDT_API_H + +#include "bt_types.h" +#include "bt_target.h" + +/***************************************************************************** +** Constants +*****************************************************************************/ +#ifndef AVDT_VERSION +#define AVDT_VERSION 0x0102 +#endif +#define AVDT_VERSION_SYNC 0x0103 + +/* API function return value result codes. */ +#define AVDT_SUCCESS 0 /* Function successful */ +#define AVDT_BAD_PARAMS 1 /* Invalid parameters */ +#define AVDT_NO_RESOURCES 2 /* Not enough resources */ +#define AVDT_BAD_HANDLE 3 /* Bad handle */ +#define AVDT_BUSY 4 /* A procedure is already in progress */ +#define AVDT_WRITE_FAIL 5 /* Write failed */ + +/* The index to access the codec type in codec_info[]. */ +#define AVDT_CODEC_TYPE_INDEX 2 + +/* The size in bytes of a Adaptation Layer header. */ +#define AVDT_AL_HDR_SIZE 3 + +/* The size in bytes of a media packet header. */ +#define AVDT_MEDIA_HDR_SIZE 12 + +/* AVDTP 7.5.3 Adaptation Layer Fragmentation + * original length of the un-fragmented transport packet should be specified by + * two bytes length field of Adaptation Layer Header */ +#define AVDT_MAX_MEDIA_SIZE (0xFFFF - AVDT_MEDIA_HDR_SIZE) + +/* The handle is used when reporting MULTI_AV specific events */ +#define AVDT_MULTI_AV_HANDLE 0xFF + +/* The number of bytes needed by the protocol stack for the protocol headers +** of a media packet. This is the size of the media packet header, the +** L2CAP packet header and HCI header. +*/ +#define AVDT_MEDIA_OFFSET 23 + +/* The marker bit is used by the application to mark significant events such +** as frame boundaries in the data stream. This constant is used to check or +** set the marker bit in the m_pt parameter of an AVDT_WriteReq() +** or AVDT_DATA_IND_EVT. +*/ +#define AVDT_MARKER_SET 0x80 + +/* SEP Type. This indicates the stream endpoint type. */ +#define AVDT_TSEP_SRC 0 /* Source SEP */ +#define AVDT_TSEP_SNK 1 /* Sink SEP */ + +/* initiator/acceptor role for adaption */ +#define AVDT_INT 0 /* initiator */ +#define AVDT_ACP 1 /* acceptor */ + +/* Media Type. This indicates the media type of the stream endpoint. */ +#define AVDT_MEDIA_AUDIO 0 /* Audio SEP */ +#define AVDT_MEDIA_VIDEO 1 /* Video SEP */ +#define AVDT_MEDIA_MULTI 2 /* Multimedia SEP */ + +/* for reporting packets */ +#define AVDT_RTCP_PT_SR 200 /* the packet type - SR (Sender Report) */ +#define AVDT_RTCP_PT_RR 201 /* the packet type - RR (Receiver Report) */ +#define AVDT_RTCP_PT_SDES 202 /* the packet type - SDES (Source Description) */ +typedef UINT8 AVDT_REPORT_TYPE; + +#define AVDT_RTCP_SDES_CNAME 1 /* SDES item CNAME */ +#ifndef AVDT_MAX_CNAME_SIZE +#define AVDT_MAX_CNAME_SIZE 28 +#endif + +/* Protocol service capabilities. This indicates the protocol service +** capabilities of a stream endpoint. This value is a mask. +** Multiple values can be combined with a bitwise OR. +*/ +#define AVDT_PSC_TRANS (1<<1) /* Media transport */ +#define AVDT_PSC_REPORT (1<<2) /* Reporting */ +#define AVDT_PSC_RECOV (1<<3) /* Recovery */ +#define AVDT_PSC_HDRCMP (1<<5) /* Header compression */ +#define AVDT_PSC_MUX (1<<6) /* Multiplexing */ +#define AVDT_PSC_DELAY_RPT (1<<8) /* Delay Report */ + +/* Recovery type. This indicates the recovery type. */ +#define AVDT_RECOV_RFC2733 1 /* RFC2733 recovery */ + +/* Header compression capabilities. This indicates the header compression +** capabilities. This value is a mask. Multiple values can be combined +** with a bitwise OR. +*/ +#define AVDT_HDRCMP_MEDIA (1<<5) /* Available for media packets */ +#define AVDT_HDRCMP_RECOV (1<<6) /* Available for recovery packets */ +#define AVDT_HDRCMP_BACKCH (1<<7) /* Back channel supported */ + +/* Multiplexing capabilities mask. */ +#define AVDT_MUX_FRAG (1<<7) /* Allow Adaptation Layer Fragmentation */ + +/* Application service category. This indicates the application +** service category. +*/ +#define AVDT_ASC_PROTECT 4 /* Content protection */ +#define AVDT_ASC_CODEC 7 /* Codec */ + +/* Error codes. The following are error codes defined in the AVDTP and GAVDP +** specifications. These error codes communicate protocol errors between +** AVDTP and the application. More detailed descriptions of the error codes +** and their appropriate use can be found in the AVDTP and GAVDP specifications. +** These error codes are unrelated to the result values returned by the +** AVDTP API functions. +*/ +#define AVDT_ERR_HEADER 0x01 /* Bad packet header format */ +#define AVDT_ERR_LENGTH 0x11 /* Bad packet length */ +#define AVDT_ERR_SEID 0x12 /* Invalid SEID */ +#define AVDT_ERR_IN_USE 0x13 /* The SEP is in use */ +#define AVDT_ERR_NOT_IN_USE 0x14 /* The SEP is not in use */ +#define AVDT_ERR_CATEGORY 0x17 /* Bad service category */ +#define AVDT_ERR_PAYLOAD 0x18 /* Bad payload format */ +#define AVDT_ERR_NSC 0x19 /* Requested command not supported */ +#define AVDT_ERR_INVALID_CAP 0x1A /* Reconfigure attempted invalid capabilities */ +#define AVDT_ERR_RECOV_TYPE 0x22 /* Requested recovery type not defined */ +#define AVDT_ERR_MEDIA_TRANS 0x23 /* Media transport capability not correct */ +#define AVDT_ERR_RECOV_FMT 0x25 /* Recovery service capability not correct */ +#define AVDT_ERR_ROHC_FMT 0x26 /* Header compression service capability not correct */ +#define AVDT_ERR_CP_FMT 0x27 /* Content protection service capability not correct */ +#define AVDT_ERR_MUX_FMT 0x28 /* Multiplexing service capability not correct */ +#define AVDT_ERR_UNSUP_CFG 0x29 /* Configuration not supported */ +#define AVDT_ERR_BAD_STATE 0x31 /* Message cannot be processed in this state */ +#define AVDT_ERR_REPORT_FMT 0x65 /* Report service capability not correct */ +#define AVDT_ERR_SERVICE 0x80 /* Invalid service category */ +#define AVDT_ERR_RESOURCE 0x81 /* Insufficient resources */ +#define AVDT_ERR_INVALID_MCT 0xC1 /* Invalid Media Codec Type */ +#define AVDT_ERR_UNSUP_MCT 0xC2 /* Unsupported Media Codec Type */ +#define AVDT_ERR_INVALID_LEVEL 0xC3 /* Invalid Level */ +#define AVDT_ERR_UNSUP_LEVEL 0xC4 /* Unsupported Level */ +#define AVDT_ERR_INVALID_CP 0xE0 /* Invalid Content Protection Type */ +#define AVDT_ERR_INVALID_FORMAT 0xE1 /* Invalid Content Protection format */ + +/* Additional error codes. This indicates error codes used by AVDTP +** in addition to the ones defined in the specifications. +*/ +#define AVDT_ERR_CONNECT 0x07 /* Connection failed. */ +#define AVDT_ERR_TIMEOUT 0x08 /* Response timeout. */ + +/* Control callback events. */ +#define AVDT_DISCOVER_CFM_EVT 0 /* Discover confirm */ +#define AVDT_GETCAP_CFM_EVT 1 /* Get capabilities confirm */ +#define AVDT_OPEN_CFM_EVT 2 /* Open confirm */ +#define AVDT_OPEN_IND_EVT 3 /* Open indication */ +#define AVDT_CONFIG_IND_EVT 4 /* Configuration indication */ +#define AVDT_START_CFM_EVT 5 /* Start confirm */ +#define AVDT_START_IND_EVT 6 /* Start indication */ +#define AVDT_SUSPEND_CFM_EVT 7 /* Suspend confirm */ +#define AVDT_SUSPEND_IND_EVT 8 /* Suspend indication */ +#define AVDT_CLOSE_CFM_EVT 9 /* Close confirm */ +#define AVDT_CLOSE_IND_EVT 10 /* Close indication */ +#define AVDT_RECONFIG_CFM_EVT 11 /* Reconfiguration confirm */ +#define AVDT_RECONFIG_IND_EVT 12 /* Reconfiguration indication */ +#define AVDT_SECURITY_CFM_EVT 13 /* Security confirm */ +#define AVDT_SECURITY_IND_EVT 14 /* Security indication */ +#define AVDT_WRITE_CFM_EVT 15 /* Write confirm */ +#define AVDT_CONNECT_IND_EVT 16 /* Signaling channel connected */ +#define AVDT_DISCONNECT_IND_EVT 17 /* Signaling channel disconnected */ +#define AVDT_REPORT_CONN_EVT 18 /* Reporting channel connected */ +#define AVDT_REPORT_DISCONN_EVT 19 /* Reporting channel disconnected */ +#define AVDT_DELAY_REPORT_EVT 20 /* Delay report received */ +#define AVDT_DELAY_REPORT_CFM_EVT 21 /* Delay report response received */ + +#define AVDT_MAX_EVT (AVDT_DELAY_REPORT_CFM_EVT) + +/* PSM for AVDT */ +#define AVDT_PSM 0x0019 + +/* Nonsupported protocol command messages. This value is used in tAVDT_CS */ +#define AVDT_NSC_SUSPEND 0x01 /* Suspend command not supported */ +#define AVDT_NSC_RECONFIG 0x02 /* Reconfigure command not supported */ +#define AVDT_NSC_SECURITY 0x04 /* Security command not supported */ + +/***************************************************************************** +** Type Definitions +*****************************************************************************/ + +typedef struct { + UINT32 ntp_sec; /* NTP time: seconds relative to 0h UTC on 1 January 1900 */ + UINT32 ntp_frac; /* NTP time: the fractional part */ + UINT32 rtp_time; /* timestamp in RTP header */ + UINT32 pkt_count; /* sender's packet count: since starting transmission + * up until the time this SR packet was generated. */ + UINT32 octet_count; /* sender's octet count: same comment */ +} tAVDT_SENDER_INFO; + +typedef struct { + UINT8 frag_lost; /* fraction lost since last RR */ + UINT32 packet_lost; /* cumulative number of packets lost since the beginning */ + UINT32 seq_num_rcvd; /* extended highest sequence number received */ + UINT32 jitter; /* interarrival jitter */ + UINT32 lsr; /* last SR timestamp */ + UINT32 dlsr; /* delay since last SR */ +} tAVDT_REPORT_BLK; + +typedef union { + tAVDT_SENDER_INFO sr; + tAVDT_REPORT_BLK rr; + UINT8 cname[AVDT_MAX_CNAME_SIZE + 1]; +} tAVDT_REPORT_DATA; + +/* This structure contains parameters which are set at registration. */ +typedef struct { + UINT16 ctrl_mtu; /* L2CAP MTU of the AVDTP signaling channel */ + UINT8 ret_tout; /* AVDTP signaling retransmission timeout */ + UINT8 sig_tout; /* AVDTP signaling message timeout */ + UINT8 idle_tout; /* AVDTP idle signaling channel timeout */ + UINT8 sec_mask; /* Security mask for BTM_SetSecurityLevel() */ +} tAVDT_REG; + +/* This structure contains the SEP information. This information is +** transferred during the discovery procedure. +*/ +typedef struct { + BOOLEAN in_use; /* TRUE if stream is currently in use */ + UINT8 seid; /* Stream endpoint identifier */ + UINT8 media_type; /* Media type */ + UINT8 tsep; /* SEP type */ +} tAVDT_SEP_INFO; + +/* This structure contains the SEP configuration. */ +typedef struct { + UINT8 codec_info[AVDT_CODEC_SIZE]; /* Codec capabilities array */ + UINT8 protect_info[AVDT_PROTECT_SIZE]; /* Content protection capabilities */ + UINT8 num_codec; /* Number of media codec information elements */ + UINT8 num_protect; /* Number of content protection information elements */ + UINT16 psc_mask; /* Protocol service capabilities mask */ + UINT8 recov_type; /* Recovery type */ + UINT8 recov_mrws; /* Maximum recovery window size */ + UINT8 recov_mnmp; /* Recovery maximum number of media packets */ + UINT8 hdrcmp_mask; /* Header compression capabilities */ +#if AVDT_MULTIPLEXING == TRUE + UINT8 mux_mask; /* Multiplexing capabilities. AVDT_MUX_XXX bits can be combined with a bitwise OR */ + UINT8 mux_tsid_media; /* TSID for media transport session */ + UINT8 mux_tcid_media; /* TCID for media transport session */ + UINT8 mux_tsid_report; /* TSID for reporting transport session */ + UINT8 mux_tcid_report; /* TCID for reporting transport session */ + UINT8 mux_tsid_recov; /* TSID for recovery transport session */ + UINT8 mux_tcid_recov; /* TCID for recovery transport session */ +#endif +} tAVDT_CFG; + +/* Header structure for callback event parameters. */ +typedef struct { + UINT8 err_code; /* Zero if operation succeeded; nonzero if operation failed */ + UINT8 err_param; /* Error parameter included for some events */ + UINT8 label; /* Transaction label */ + UINT8 seid; /* For internal use only */ + UINT8 sig_id; /* For internal use only */ + UINT8 ccb_idx; /* For internal use only */ +} tAVDT_EVT_HDR; + +/* This data structure is associated with the AVDT_GETCAP_CFM_EVT, +** AVDT_RECONFIG_IND_EVT, and AVDT_RECONFIG_CFM_EVT. +*/ +typedef struct { + tAVDT_EVT_HDR hdr; /* Event header */ + tAVDT_CFG *p_cfg; /* Pointer to configuration for this SEP */ +} tAVDT_CONFIG; + +/* This data structure is associated with the AVDT_CONFIG_IND_EVT. */ +typedef struct { + tAVDT_EVT_HDR hdr; /* Event header */ + tAVDT_CFG *p_cfg; /* Pointer to configuration for this SEP */ + UINT8 int_seid; /* Stream endpoint ID of stream initiating the operation */ +} tAVDT_SETCONFIG; + +/* This data structure is associated with the AVDT_OPEN_IND_EVT and AVDT_OPEN_CFM_EVT. */ +typedef struct { + tAVDT_EVT_HDR hdr; /* Event header */ + UINT16 peer_mtu; /* Transport channel L2CAP MTU of the peer */ + UINT16 lcid; /* L2CAP LCID for media channel */ +} tAVDT_OPEN; + +/* This data structure is associated with the AVDT_SECURITY_IND_EVT +** and AVDT_SECURITY_CFM_EVT. +*/ +typedef struct { + tAVDT_EVT_HDR hdr; /* Event header */ + UINT8 *p_data; /* Pointer to security data */ + UINT16 len; /* Length in bytes of the security data */ +} tAVDT_SECURITY; + +/* This data structure is associated with the AVDT_DISCOVER_CFM_EVT. */ +typedef struct { + tAVDT_EVT_HDR hdr; /* Event header */ + tAVDT_SEP_INFO *p_sep_info; /* Pointer to SEP information */ + UINT8 num_seps; /* Number of stream endpoints */ +} tAVDT_DISCOVER; + +/* This data structure is associated with the AVDT_DELAY_REPORT_EVT. */ +typedef struct { + tAVDT_EVT_HDR hdr; /* Event header */ + UINT16 delay; /* Delay value */ +} tAVDT_DELAY_RPT; + +/* Union of all control callback event data structures */ +typedef union { + tAVDT_EVT_HDR hdr; + tAVDT_DISCOVER discover_cfm; + tAVDT_CONFIG getcap_cfm; + tAVDT_OPEN open_cfm; + tAVDT_OPEN open_ind; + tAVDT_SETCONFIG config_ind; + tAVDT_EVT_HDR start_cfm; + tAVDT_EVT_HDR suspend_cfm; + tAVDT_EVT_HDR close_cfm; + tAVDT_CONFIG reconfig_cfm; + tAVDT_CONFIG reconfig_ind; + tAVDT_SECURITY security_cfm; + tAVDT_SECURITY security_ind; + tAVDT_EVT_HDR connect_ind; + tAVDT_EVT_HDR disconnect_ind; + tAVDT_EVT_HDR report_conn; + tAVDT_DELAY_RPT delay_rpt_cmd; +} tAVDT_CTRL; + +/* This is the control callback function. This function passes control events +** to the application. This function is required for all registered stream +** endpoints and for the AVDT_DiscoverReq() and AVDT_GetCapReq() functions. +** +*/ +typedef void (tAVDT_CTRL_CBACK)(UINT8 handle, BD_ADDR bd_addr, UINT8 event, + tAVDT_CTRL *p_data); + +/* This is the data callback function. It is executed when AVDTP has a media +** packet ready for the application. This function is required for SNK +** endpoints and not applicable for SRC endpoints. +*/ +typedef void (tAVDT_DATA_CBACK)(UINT8 handle, BT_HDR *p_pkt, UINT32 time_stamp, + UINT8 m_pt); + +#if AVDT_MULTIPLEXING == TRUE +/* This is the second version of the data callback function. This version uses +** application buffer assigned by AVDT_SetMediaBuf. Caller can assign different +** buffer during callback or can leave the current buffer for further using. +** This callback is called when AVDTP has a media packet ready for the application. +** This function is required for SNK endpoints and not applicable for SRC endpoints. +*/ +typedef void (tAVDT_MEDIA_CBACK)(UINT8 handle, UINT8 *p_payload, UINT32 payload_len, + UINT32 time_stamp, UINT16 seq_num, UINT8 m_pt, UINT8 marker); +#endif + +#if AVDT_REPORTING == TRUE +/* This is the report callback function. It is executed when AVDTP has a reporting +** packet ready for the application. This function is required for streams +** created with AVDT_PSC_REPORT. +*/ +typedef void (tAVDT_REPORT_CBACK)(UINT8 handle, AVDT_REPORT_TYPE type, + tAVDT_REPORT_DATA *p_data); +#endif + +typedef UINT16 (tAVDT_GETCAP_REQ) (BD_ADDR bd_addr, UINT8 seid, tAVDT_CFG *p_cfg, tAVDT_CTRL_CBACK *p_cback); + +/* This structure contains information required when a stream is created. +** It is passed to the AVDT_CreateStream() function. +*/ +typedef struct { + tAVDT_CFG cfg; /* SEP configuration */ + tAVDT_CTRL_CBACK *p_ctrl_cback; /* Control callback function */ + tAVDT_DATA_CBACK *p_data_cback; /* Data callback function */ +#if AVDT_MULTIPLEXING == TRUE + tAVDT_MEDIA_CBACK *p_media_cback; /* Media callback function. It will be called only if p_data_cback is NULL */ +#endif +#if AVDT_REPORTING == TRUE + tAVDT_REPORT_CBACK *p_report_cback;/* Report callback function. */ +#endif + UINT16 mtu; /* The L2CAP MTU of the transport channel */ + UINT16 flush_to; /* The L2CAP flush timeout of the transport channel */ + UINT8 tsep; /* SEP type */ + UINT8 media_type; /* Media type */ + UINT16 nsc_mask; /* Nonsupported protocol command messages */ +} tAVDT_CS; + +/* AVDT data option mask is used in the write request */ +#define AVDT_DATA_OPT_NONE 0x00 /* No option still add RTP header */ +#define AVDT_DATA_OPT_NO_RTP (0x01 << 0) /* Skip adding RTP header */ + +typedef UINT8 tAVDT_DATA_OPT_MASK; + + + +/***************************************************************************** +** External Function Declarations +*****************************************************************************/ +#ifdef __cplusplus +extern "C" +{ +#endif + +/******************************************************************************* +** +** Function AVDT_Register +** +** Description This is the system level registration function for the +** AVDTP protocol. This function initializes AVDTP and +** prepares the protocol stack for its use. This function +** must be called once by the system or platform using AVDTP +** before the other functions of the API an be used. +** +** +** Returns void +** +*******************************************************************************/ +extern void AVDT_Register(tAVDT_REG *p_reg, tAVDT_CTRL_CBACK *p_cback); + +/******************************************************************************* +** +** Function AVDT_Deregister +** +** Description This function is called to deregister use AVDTP protocol. +** It is called when AVDTP is no longer being used by any +** application in the system. Before this function can be +** called, all streams must be removed with AVDT_RemoveStream(). +** +** +** Returns void +** +*******************************************************************************/ +extern void AVDT_Deregister(void); + + +/******************************************************************************* +** +** Function AVDT_SINK_Activate +** +** Description Activate SEP of A2DP Sink. In Use parameter is adjusted. +** In Use will be made false in case of activation. A2DP SRC +** will receive in_use as false and can open A2DP Sink +** connection +** +** Returns void +** +*******************************************************************************/ +extern void AVDT_SINK_Activate(void); + +/******************************************************************************* +** +** Function AVDT_SINK_Deactivate +** +** Description Deactivate SEP of A2DP Sink. In Use parameter is adjusted. +** In Use will be made TRUE in case of activation. A2DP SRC +** will receive in_use as true and will not open A2DP Sink +** connection +** +** Returns void. +** +*******************************************************************************/ +extern void AVDT_SINK_Deactivate(void); + +/******************************************************************************* +** +** Function AVDT_AbortReq +** +** Description Trigger Abort request to pass AVDTP Abort related mandatory +** PTS Test case. +** +** Returns void. +** +*******************************************************************************/ +extern void AVDT_AbortReq(UINT8 handle); + +/******************************************************************************* +** +** Function AVDT_CreateStream +** +** Description Create a stream endpoint. After a stream endpoint is +** created an application can initiate a connection between +** this endpoint and an endpoint on a peer device. In +** addition, a peer device can discover, get the capabilities, +** and connect to this endpoint. +** +** +** Returns AVDT_SUCCESS if successful, otherwise error. +** +*******************************************************************************/ +extern UINT16 AVDT_CreateStream(UINT8 *p_handle, tAVDT_CS *p_cs); + +/******************************************************************************* +** +** Function AVDT_RemoveStream +** +** Description Remove a stream endpoint. This function is called when +** the application is no longer using a stream endpoint. +** If this function is called when the endpoint is connected +** the connection is closed and then the stream endpoint +** is removed. +** +** +** Returns AVDT_SUCCESS if successful, otherwise error. +** +*******************************************************************************/ +extern UINT16 AVDT_RemoveStream(UINT8 handle); + +/******************************************************************************* +** +** Function AVDT_DiscoverReq +** +** Description This function initiates a connection to the AVDTP service +** on the peer device, if not already present, and discovers +** the stream endpoints on the peer device. (Please note +** that AVDTP discovery is unrelated to SDP discovery). +** This function can be called at any time regardless of whether +** there is an AVDTP connection to the peer device. +** +** When discovery is complete, an AVDT_DISCOVER_CFM_EVT +** is sent to the application via its callback function. +** The application must not call AVDT_GetCapReq() or +** AVDT_DiscoverReq() again to the same device until +** discovery is complete. +** +** The memory addressed by sep_info is allocated by the +** application. This memory is written to by AVDTP as part +** of the discovery procedure. This memory must remain +** accessible until the application receives the +** AVDT_DISCOVER_CFM_EVT. +** +** Returns AVDT_SUCCESS if successful, otherwise error. +** +*******************************************************************************/ +extern UINT16 AVDT_DiscoverReq(BD_ADDR bd_addr, tAVDT_SEP_INFO *p_sep_info, + UINT8 max_seps, tAVDT_CTRL_CBACK *p_cback); + + +/******************************************************************************* +** +** Function AVDT_GetCapReq +** +** Description This function initiates a connection to the AVDTP service +** on the peer device, if not already present, and gets the +** capabilities of a stream endpoint on the peer device. +** This function can be called at any time regardless of +** whether there is an AVDTP connection to the peer device. +** +** When the procedure is complete, an AVDT_GETCAP_CFM_EVT is +** sent to the application via its callback function. The +** application must not call AVDT_GetCapReq() or +** AVDT_DiscoverReq() again until the procedure is complete. +** +** The memory pointed to by p_cfg is allocated by the +** application. This memory is written to by AVDTP as part +** of the get capabilities procedure. This memory must +** remain accessible until the application receives +** the AVDT_GETCAP_CFM_EVT. +** +** Returns AVDT_SUCCESS if successful, otherwise error. +** +*******************************************************************************/ +extern UINT16 AVDT_GetCapReq(BD_ADDR bd_addr, UINT8 seid, tAVDT_CFG *p_cfg, + tAVDT_CTRL_CBACK *p_cback); + +/******************************************************************************* +** +** Function AVDT_GetAllCapReq +** +** Description This function initiates a connection to the AVDTP service +** on the peer device, if not already present, and gets the +** capabilities of a stream endpoint on the peer device. +** This function can be called at any time regardless of +** whether there is an AVDTP connection to the peer device. +** +** When the procedure is complete, an AVDT_GETCAP_CFM_EVT is +** sent to the application via its callback function. The +** application must not call AVDT_GetCapReq() or +** AVDT_DiscoverReq() again until the procedure is complete. +** +** The memory pointed to by p_cfg is allocated by the +** application. This memory is written to by AVDTP as part +** of the get capabilities procedure. This memory must +** remain accessible until the application receives +** the AVDT_GETCAP_CFM_EVT. +** +** Returns AVDT_SUCCESS if successful, otherwise error. +** +*******************************************************************************/ +extern UINT16 AVDT_GetAllCapReq(BD_ADDR bd_addr, UINT8 seid, tAVDT_CFG *p_cfg, + tAVDT_CTRL_CBACK *p_cback); + +/******************************************************************************* +** +** Function AVDT_DelayReport +** +** Description This functions sends a Delay Report to the peer device +** that is associated with a particular SEID. +** This function is called by SNK device. +** +** Returns AVDT_SUCCESS if successful, otherwise error. +** +*******************************************************************************/ +extern UINT16 AVDT_DelayReport(UINT8 handle, UINT8 seid, UINT16 delay); + +/******************************************************************************* +** +** Function AVDT_OpenReq +** +** Description This function initiates a connection to the AVDTP service +** on the peer device, if not already present, and connects +** to a stream endpoint on a peer device. When the connection +** is completed, an AVDT_OPEN_CFM_EVT is sent to the +** application via the control callback function for this handle. +** +** Returns AVDT_SUCCESS if successful, otherwise error. +** +*******************************************************************************/ +extern UINT16 AVDT_OpenReq(UINT8 handle, BD_ADDR bd_addr, UINT8 seid, + tAVDT_CFG *p_cfg); + + +/******************************************************************************* +** +** Function AVDT_ConfigRsp +** +** Description Respond to a configure request from the peer device. This +** function must be called if the application receives an +** AVDT_CONFIG_IND_EVT through its control callback. +** +** +** Returns AVDT_SUCCESS if successful, otherwise error. +** +*******************************************************************************/ +extern UINT16 AVDT_ConfigRsp(UINT8 handle, UINT8 label, UINT8 error_code, + UINT8 category); + +/******************************************************************************* +** +** Function AVDT_StartReq +** +** Description Start one or more stream endpoints. This initiates the +** transfer of media packets for the streams. All stream +** endpoints must previously be opened. When the streams +** are started, an AVDT_START_CFM_EVT is sent to the +** application via the control callback function for each stream. +** +** +** Returns AVDT_SUCCESS if successful, otherwise error. +** +*******************************************************************************/ +extern UINT16 AVDT_StartReq(UINT8 *p_handles, UINT8 num_handles); + +/******************************************************************************* +** +** Function AVDT_SuspendReq +** +** Description Suspend one or more stream endpoints. This suspends the +** transfer of media packets for the streams. All stream +** endpoints must previously be open and started. When the +** streams are suspended, an AVDT_SUSPEND_CFM_EVT is sent to +** the application via the control callback function for +** each stream. +** +** +** Returns AVDT_SUCCESS if successful, otherwise error. +** +*******************************************************************************/ +extern UINT16 AVDT_SuspendReq(UINT8 *p_handles, UINT8 num_handles); + +/******************************************************************************* +** +** Function AVDT_CloseReq +** +** Description Close a stream endpoint. This stops the transfer of media +** packets and closes the transport channel associated with +** this stream endpoint. When the stream is closed, an +** AVDT_CLOSE_CFM_EVT is sent to the application via the +** control callback function for this handle. +** +** +** Returns AVDT_SUCCESS if successful, otherwise error. +** +*******************************************************************************/ +extern UINT16 AVDT_CloseReq(UINT8 handle); + +/******************************************************************************* +** +** Function AVDT_ReconfigReq +** +** Description Reconfigure a stream endpoint. This allows the application +** to change the codec or content protection capabilities of +** a stream endpoint after it has been opened. This function +** can only be called if the stream is opened but not started +** or if the stream has been suspended. When the procedure +** is completed, an AVDT_RECONFIG_CFM_EVT is sent to the +** application via the control callback function for this handle. +** +** +** Returns AVDT_SUCCESS if successful, otherwise error. +** +*******************************************************************************/ +extern UINT16 AVDT_ReconfigReq(UINT8 handle, tAVDT_CFG *p_cfg); + +/******************************************************************************* +** +** Function AVDT_ReconfigRsp +** +** Description Respond to a reconfigure request from the peer device. +** This function must be called if the application receives +** an AVDT_RECONFIG_IND_EVT through its control callback. +** +** +** Returns AVDT_SUCCESS if successful, otherwise error. +** +*******************************************************************************/ +extern UINT16 AVDT_ReconfigRsp(UINT8 handle, UINT8 label, UINT8 error_code, + UINT8 category); + +/******************************************************************************* +** +** Function AVDT_SecurityReq +** +** Description Send a security request to the peer device. When the +** security procedure is completed, an AVDT_SECURITY_CFM_EVT +** is sent to the application via the control callback function +** for this handle. (Please note that AVDTP security procedures +** are unrelated to Bluetooth link level security.) +** +** +** Returns AVDT_SUCCESS if successful, otherwise error. +** +*******************************************************************************/ +extern UINT16 AVDT_SecurityReq(UINT8 handle, UINT8 *p_data, UINT16 len); + +/******************************************************************************* +** +** Function AVDT_SecurityRsp +** +** Description Respond to a security request from the peer device. +** This function must be called if the application receives +** an AVDT_SECURITY_IND_EVT through its control callback. +** (Please note that AVDTP security procedures are unrelated +** to Bluetooth link level security.) +** +** +** Returns AVDT_SUCCESS if successful, otherwise error. +** +*******************************************************************************/ +extern UINT16 AVDT_SecurityRsp(UINT8 handle, UINT8 label, UINT8 error_code, + UINT8 *p_data, UINT16 len); + +/******************************************************************************* +** +** Function AVDT_WriteReq +** +** Description Send a media packet to the peer device. The stream must +** be started before this function is called. Also, this +** function can only be called if the stream is a SRC. +** +** When AVDTP has sent the media packet and is ready for the +** next packet, an AVDT_WRITE_CFM_EVT is sent to the +** application via the control callback. The application must +** wait for the AVDT_WRITE_CFM_EVT before it makes the next +** call to AVDT_WriteReq(). If the applications calls +** AVDT_WriteReq() before it receives the event the packet +** will not be sent. The application may make its first call +** to AVDT_WriteReq() after it receives an AVDT_START_CFM_EVT +** or AVDT_START_IND_EVT. +** +** The application passes the packet using the BT_HDR structure. +** This structure is described in section 2.1. The offset +** field must be equal to or greater than AVDT_MEDIA_OFFSET. +** This allows enough space in the buffer for the L2CAP and +** AVDTP headers. +** +** The memory pointed to by p_pkt must be a GKI buffer +** allocated by the application. This buffer will be freed +** by the protocol stack; the application must not free +** this buffer. +** +** +** Returns AVDT_SUCCESS if successful, otherwise error. +** +*******************************************************************************/ +extern UINT16 AVDT_WriteReq(UINT8 handle, BT_HDR *p_pkt, UINT32 time_stamp, + UINT8 m_pt); +/******************************************************************************* +** +** Function AVDT_WriteReqOpt +** +** Description Send a media packet to the peer device. The stream must +** be started before this function is called. Also, this +** function can only be called if the stream is a SRC +** +** When AVDTP has sent the media packet and is ready for the +** next packet, an AVDT_WRITE_CFM_EVT is sent to the +** application via the control callback. The application must +** wait for the AVDT_WRITE_CFM_EVT before it makes the next +** call to AVDT_WriteReq(). If the applications calls +** AVDT_WriteReq() before it receives the event the packet +** will not be sent. The application may make its first call +** to AVDT_WriteReq() after it receives an AVDT_START_CFM_EVT +** or AVDT_START_IND_EVT. +** +** The application passes the packet using the BT_HDR structure +** This structure is described in section 2.1. The offset +** field must be equal to or greater than AVDT_MEDIA_OFFSET +** (if NO_RTP is specified, L2CAP_MIN_OFFSET can be used) +** This allows enough space in the buffer for the L2CAP and +** AVDTP headers. +** +** The memory pointed to by p_pkt must be a GKI buffer +** allocated by the application. This buffer will be freed +** by the protocol stack; the application must not free +** this buffer. +** +** The opt parameter allows passing specific options like: +** - NO_RTP : do not add the RTP header to buffer +** +** Returns AVDT_SUCCESS if successful, otherwise error. +** +*******************************************************************************/ +extern UINT16 AVDT_WriteReqOpt(UINT8 handle, BT_HDR *p_pkt, UINT32 time_stamp, + UINT8 m_pt, tAVDT_DATA_OPT_MASK opt); + +/******************************************************************************* +** +** Function AVDT_ConnectReq +** +** Description This function initiates an AVDTP signaling connection +** to the peer device. When the connection is completed, an +** AVDT_CONNECT_IND_EVT is sent to the application via its +** control callback function. If the connection attempt fails +** an AVDT_DISCONNECT_IND_EVT is sent. The security mask +** parameter overrides the outgoing security mask set in +** AVDT_Register(). +** +** Returns AVDT_SUCCESS if successful, otherwise error. +** +*******************************************************************************/ +extern UINT16 AVDT_ConnectReq(BD_ADDR bd_addr, UINT8 sec_mask, + tAVDT_CTRL_CBACK *p_cback); + +/******************************************************************************* +** +** Function AVDT_DisconnectReq +** +** Description This function disconnect an AVDTP signaling connection +** to the peer device. When disconnected an +** AVDT_DISCONNECT_IND_EVT is sent to the application via its +** control callback function. +** +** Returns AVDT_SUCCESS if successful, otherwise error. +** +*******************************************************************************/ +extern UINT16 AVDT_DisconnectReq(BD_ADDR bd_addr, tAVDT_CTRL_CBACK *p_cback); + +/******************************************************************************* +** +** Function AVDT_GetL2CapChannel +** +** Description Get the L2CAP CID used by the handle. +** +** Returns CID if successful, otherwise 0. +** +*******************************************************************************/ +extern UINT16 AVDT_GetL2CapChannel(UINT8 handle); + +/******************************************************************************* +** +** Function AVDT_GetSignalChannel +** +** Description Get the L2CAP CID used by the signal channel of the given handle. +** +** Returns CID if successful, otherwise 0. +** +*******************************************************************************/ +extern UINT16 AVDT_GetSignalChannel(UINT8 handle, BD_ADDR bd_addr); + +/******************************************************************************* +** +** Function AVDT_WriteDataReq +** +** Description Send a media packet to the peer device. The stream must +** be started before this function is called. Also, this +** function can only be called if the stream is a SRC. +** +** When AVDTP has sent the media packet and is ready for the +** next packet, an AVDT_WRITE_CFM_EVT is sent to the +** application via the control callback. The application must +** wait for the AVDT_WRITE_CFM_EVT before it makes the next +** call to AVDT_WriteDataReq(). If the applications calls +** AVDT_WriteDataReq() before it receives the event the packet +** will not be sent. The application may make its first call +** to AVDT_WriteDataReq() after it receives an +** AVDT_START_CFM_EVT or AVDT_START_IND_EVT. +** +** Returns AVDT_SUCCESS if successful, otherwise error. +** +*******************************************************************************/ +extern UINT16 AVDT_WriteDataReq(UINT8 handle, UINT8 *p_data, UINT32 data_len, + UINT32 time_stamp, UINT8 m_pt, UINT8 marker); + +/******************************************************************************* +** +** Function AVDT_SetMediaBuf +** +** Description Assigns buffer for media packets or forbids using of assigned +** buffer if argument p_buf is NULL. This function can only +** be called if the stream is a SNK. +** +** AVDTP uses this buffer to reassemble fragmented media packets. +** When AVDTP receives a complete media packet, it calls the +** p_media_cback assigned by AVDT_CreateStream(). +** This function can be called during callback to assign a +** different buffer for next media packet or can leave the current +** buffer for next packet. +** +** Returns AVDT_SUCCESS if successful, otherwise error. +** +*******************************************************************************/ +extern UINT16 AVDT_SetMediaBuf(UINT8 handle, UINT8 *p_buf, UINT32 buf_len); + +/******************************************************************************* +** +** Function AVDT_SendReport +** +** Description +** +** +** +** Returns +** +*******************************************************************************/ +extern UINT16 AVDT_SendReport(UINT8 handle, AVDT_REPORT_TYPE type, + tAVDT_REPORT_DATA *p_data); + +/****************************************************************************** +** +** Function AVDT_SetTraceLevel +** +** Description Sets the trace level for AVDT. If 0xff is passed, the +** current trace level is returned. +** +** Input Parameters: +** new_level: The level to set the AVDT tracing to: +** 0xff-returns the current setting. +** 0-turns off tracing. +** >= 1-Errors. +** >= 2-Warnings. +** >= 3-APIs. +** >= 4-Events. +** >= 5-Debug. +** +** Returns The new trace level or current trace level if +** the input parameter is 0xff. +** +******************************************************************************/ +extern UINT8 AVDT_SetTraceLevel (UINT8 new_level); + +#ifdef __cplusplus +} +#endif + + +#endif /* AVDT_API_H */ diff --git a/tools/sdk/include/bluedroid/avdt_defs.h b/tools/sdk/include/bluedroid/avdt_defs.h new file mode 100755 index 00000000..b6dbbc4f --- /dev/null +++ b/tools/sdk/include/bluedroid/avdt_defs.h @@ -0,0 +1,203 @@ +/****************************************************************************** + * + * 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 */ + diff --git a/tools/sdk/include/bluedroid/avdtc_api.h b/tools/sdk/include/bluedroid/avdtc_api.h new file mode 100755 index 00000000..96b20e77 --- /dev/null +++ b/tools/sdk/include/bluedroid/avdtc_api.h @@ -0,0 +1,230 @@ +/****************************************************************************** + * + * 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 */ diff --git a/tools/sdk/include/bluedroid/avrc_api.h b/tools/sdk/include/bluedroid/avrc_api.h new file mode 100644 index 00000000..dad8b3bd --- /dev/null +++ b/tools/sdk/include/bluedroid/avrc_api.h @@ -0,0 +1,637 @@ +/****************************************************************************** + * + * Copyright (C) 2006-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. + * + ******************************************************************************/ + +/****************************************************************************** + * + * nterface to AVRCP Application Programming Interface + * + ******************************************************************************/ +#ifndef AVRC_API_H +#define AVRC_API_H +#include "bt_target.h" +#include "avct_api.h" +#include "sdp_api.h" +#include "avrc_defs.h" + +/***************************************************************************** +** constants +*****************************************************************************/ + +/* API function return value result codes. */ +#define AVRC_SUCCESS AVCT_SUCCESS /* 0 Function successful */ +#define AVRC_NO_RESOURCES AVCT_NO_RESOURCES /* 1 Not enough resources */ +#define AVRC_BAD_HANDLE AVCT_BAD_HANDLE /* 2 Bad handle */ +#define AVRC_PID_IN_USE AVCT_PID_IN_USE /* 3 PID already in use */ +#define AVRC_NOT_OPEN AVCT_NOT_OPEN /* 4 Connection not open */ +#define AVRC_MSG_TOO_BIG 5 /* 5 the message length exceed the MTU of the browsing channel */ +#define AVRC_FAIL 0x10 /* 0x10 generic failure */ +#define AVRC_BAD_PARAM 0x11 /* 0x11 bad parameter */ + +/* Control role - same as AVCT_TARGET/AVCT_CONTROL */ +#define AVRC_CT_TARGET 1 /* target */ +#define AVRC_CT_CONTROL 2 /* controller */ +#define AVRC_CT_PASSIVE 4 /* If conflict, allow the other side to succeed */ + +/* Connection role */ +#define AVRC_CONN_INT AVCT_INT /* initiator */ +#define AVRC_CONN_ACP AVCT_ACP /* Acceptor */ + + +/* AVRC CTRL events */ +/* AVRC_OPEN_IND_EVT event is sent when the connection is successfully opened. + * This eventis sent in response to an AVRC_Open(). */ +#define AVRC_OPEN_IND_EVT 0 + +/* AVRC_CLOSE_IND_EVT event is sent when a connection is closed. + * This event can result from a call to AVRC_Close() or when the peer closes + * the connection. It is also sent when a connection attempted through + * AVRC_Open() fails. */ +#define AVRC_CLOSE_IND_EVT 1 + +/* AVRC_CONG_IND_EVT event indicates that AVCTP is congested and cannot send + * any more messages. */ +#define AVRC_CONG_IND_EVT 2 + +/* AVRC_UNCONG_IND_EVT event indicates that AVCTP is uncongested and ready to + * send messages. */ +#define AVRC_UNCONG_IND_EVT 3 + +/* AVRC_BROWSE_OPEN_IND_EVT event is sent when the browse channel is successfully opened. +* This eventis sent in response to an AVRC_Open() or AVRC_OpenBrowse() . */ +#define AVRC_BROWSE_OPEN_IND_EVT 4 + +/* AVRC_BROWSE_CLOSE_IND_EVT event is sent when a browse channel is closed. + * This event can result from a call to AVRC_Close(), AVRC_CloseBrowse() or when the peer closes + * the connection. It is also sent when a connection attempted through + * AVRC_OpenBrowse() fails. */ +#define AVRC_BROWSE_CLOSE_IND_EVT 5 + +/* AVRC_BROWSE_CONG_IND_EVT event indicates that AVCTP browse channel is congested and cannot send + * any more messages. */ +#define AVRC_BROWSE_CONG_IND_EVT 6 + +/* AVRC_BROWSE_UNCONG_IND_EVT event indicates that AVCTP browse channel is uncongested and ready to + * send messages. */ +#define AVRC_BROWSE_UNCONG_IND_EVT 7 + +/* AVRC_CMD_TIMEOUT_EVT event indicates timeout waiting for AVRC command response from the peer */ +#define AVRC_CMD_TIMEOUT_EVT 8 + +/* Supported categories */ +#define AVRC_SUPF_CT_CAT1 0x0001 /* Category 1 */ +#define AVRC_SUPF_CT_CAT2 0x0002 /* Category 2 */ +#define AVRC_SUPF_CT_CAT3 0x0004 /* Category 3 */ +#define AVRC_SUPF_CT_CAT4 0x0008 /* Category 4 */ +#define AVRC_SUPF_CT_BROWSE 0x0040 /* Browsing */ + +#define AVRC_SUPF_TG_CAT1 0x0001 /* Category 1 */ +#define AVRC_SUPF_TG_CAT2 0x0002 /* Category 2 */ +#define AVRC_SUPF_TG_CAT3 0x0004 /* Category 3 */ +#define AVRC_SUPF_TG_CAT4 0x0008 /* Category 4 */ +#define AVRC_SUPF_TG_APP_SETTINGS 0x0010 /* Player Application Settings */ +#define AVRC_SUPF_TG_GROUP_NAVI 0x0020 /* Group Navigation */ +#define AVRC_SUPF_TG_BROWSE 0x0040 /* Browsing */ +#define AVRC_SUPF_TG_MULTI_PLAYER 0x0080 /* Muliple Media Player */ + +#define AVRC_META_SUCCESS AVRC_SUCCESS +#define AVRC_META_FAIL AVRC_FAIL +#define AVRC_METADATA_CMD 0x0000 +#define AVRC_METADATA_RESP 0x0001 + + + +/***************************************************************************** +** data type definitions +*****************************************************************************/ + +/* This data type is used in AVRC_FindService() to initialize the SDP database + * to hold the result service search. */ +typedef struct { + UINT32 db_len; /* Length, in bytes, of the discovery database */ + tSDP_DISCOVERY_DB *p_db; /* Pointer to the discovery database */ + UINT16 num_attr;/* The number of attributes in p_attrs */ + UINT16 *p_attrs; /* The attributes filter. If NULL, AVRCP API sets the attribute filter + * to be ATTR_ID_SERVICE_CLASS_ID_LIST, ATTR_ID_BT_PROFILE_DESC_LIST, + * ATTR_ID_SUPPORTED_FEATURES, ATTR_ID_SERVICE_NAME and ATTR_ID_PROVIDER_NAME. + * If not NULL, the input is taken as the filter. */ +} tAVRC_SDP_DB_PARAMS; + +/* This callback function returns service discovery information to the + * application after the AVRC_FindService() API function is called. The + * implementation of this callback function must copy the p_service_name + * and p_provider_name parameters passed to it as they are not guaranteed + * to remain after the callback function exits. */ +typedef void (tAVRC_FIND_CBACK) (UINT16 status); + + +/* This is the control callback function. This function passes events + * listed in Table 20 to the application. */ +typedef void (tAVRC_CTRL_CBACK) (UINT8 handle, UINT8 event, UINT16 result, + BD_ADDR peer_addr); + + +/* This is the message callback function. It is executed when AVCTP has + * a message packet ready for the application. The implementation of this + * callback function must copy the tAVRC_MSG structure passed to it as it + * is not guaranteed to remain after the callback function exits. */ +typedef void (tAVRC_MSG_CBACK) (UINT8 handle, UINT8 label, UINT8 opcode, + tAVRC_MSG *p_msg); + +typedef struct { + tAVRC_CTRL_CBACK *p_ctrl_cback; /* pointer to application control callback */ + tAVRC_MSG_CBACK *p_msg_cback; /* pointer to application message callback */ + UINT32 company_id; /* the company ID */ + UINT8 conn; /* Connection role (Initiator/acceptor) */ + UINT8 control; /* Control role (Control/Target) */ +} tAVRC_CONN_CB; + + + +/***************************************************************************** +** external function declarations +*****************************************************************************/ +#ifdef __cplusplus +extern "C" +{ +#endif + +/****************************************************************************** +** +** Function AVRC_AddRecord +** +** Description This function is called to build an AVRCP SDP record. +** Prior to calling this function the application must +** call SDP_CreateRecord() to create an SDP record. +** +** Input Parameters: +** service_uuid: Indicates TG(UUID_SERVCLASS_AV_REM_CTRL_TARGET) +** or CT(UUID_SERVCLASS_AV_REMOTE_CONTROL) +** +** p_service_name: Pointer to a null-terminated character +** string containing the service name. +** If service name is not used set this to NULL. +** +** p_provider_name: Pointer to a null-terminated character +** string containing the provider name. +** If provider name is not used set this to NULL. +** +** categories: Supported categories. +** +** sdp_handle: SDP handle returned by SDP_CreateRecord(). +** +** Output Parameters: +** None. +** +** Returns AVRC_SUCCESS if successful. +** AVRC_NO_RESOURCES if not enough resources to build the SDP record. +** +******************************************************************************/ +extern UINT16 AVRC_AddRecord(UINT16 service_uuid, char *p_service_name, + char *p_provider_name, UINT16 categories, UINT32 sdp_handle); + +/****************************************************************************** +** +** Function AVRC_FindService +** +** Description This function is called by the application to perform service +** discovery and retrieve AVRCP SDP record information from a +** peer device. Information is returned for the first service +** record found on the server that matches the service UUID. +** The callback function will be executed when service discovery +** is complete. There can only be one outstanding call to +** AVRC_FindService() at a time; the application must wait for +** the callback before it makes another call to the function. +** The application is responsible for allocating memory for the +** discovery database. It is recommended that the size of the +** discovery database be at least 300 bytes. The application +** can deallocate the memory after the callback function has +** executed. +** +** Input Parameters: +** service_uuid: Indicates TG(UUID_SERVCLASS_AV_REM_CTRL_TARGET) +** or CT(UUID_SERVCLASS_AV_REMOTE_CONTROL) +** +** bd_addr: BD address of the peer device. +** +** p_db: SDP discovery database parameters. +** +** p_cback: Pointer to the callback function. +** +** Output Parameters: +** None. +** +** Returns AVRC_SUCCESS if successful. +** AVRC_BAD_PARAMS if discovery database parameters are invalid. +** AVRC_NO_RESOURCES if there are not enough resources to +** perform the service search. +** +******************************************************************************/ +extern UINT16 AVRC_FindService(UINT16 service_uuid, BD_ADDR bd_addr, + tAVRC_SDP_DB_PARAMS *p_db, tAVRC_FIND_CBACK *p_cback); + +/****************************************************************************** +** +** Function AVRC_Open +** +** Description This function is called to open a connection to AVCTP. +** The connection can be either an initiator or acceptor, as +** determined by the p_ccb->stream parameter. +** The connection can be a target, a controller or for both role, +** as determined by the p_ccb->control parameter. +** By definition, a target connection is an acceptor connection +** that waits for an incoming AVCTP connection from the peer. +** The connection remains available to the application until +** the application closes it by calling AVRC_Close(). The +** application does not need to reopen the connection after an +** AVRC_CLOSE_IND_EVT is received. +** +** Input Parameters: +** p_ccb->company_id: Company Identifier. +** +** p_ccb->p_ctrl_cback: Pointer to control callback function. +** +** p_ccb->p_msg_cback: Pointer to message callback function. +** +** p_ccb->conn: AVCTP connection role. This is set to +** AVCTP_INT for initiator connections and AVCTP_ACP +** for acceptor connections. +** +** p_ccb->control: Control role. This is set to +** AVRC_CT_TARGET for target connections, AVRC_CT_CONTROL +** for control connections or (AVRC_CT_TARGET|AVRC_CT_CONTROL) +** for connections that support both roles. +** +** peer_addr: BD address of peer device. This value is +** only used for initiator connections; for acceptor +** connections it can be set to NULL. +** +** Output Parameters: +** p_handle: Pointer to handle. This parameter is only +** valid if AVRC_SUCCESS is returned. +** +** Returns AVRC_SUCCESS if successful. +** AVRC_NO_RESOURCES if there are not enough resources to open +** the connection. +** +******************************************************************************/ +extern UINT16 AVRC_Open(UINT8 *p_handle, tAVRC_CONN_CB *p_ccb, + BD_ADDR_PTR peer_addr); + +/****************************************************************************** +** +** Function AVRC_Close +** +** Description Close a connection opened with AVRC_Open(). +** This function is called when the +** application is no longer using a connection. +** +** Input Parameters: +** handle: Handle of this connection. +** +** Output Parameters: +** None. +** +** Returns AVRC_SUCCESS if successful. +** AVRC_BAD_HANDLE if handle is invalid. +** +******************************************************************************/ +extern UINT16 AVRC_Close(UINT8 handle); + +/****************************************************************************** +** +** Function AVRC_OpenBrowse +** +** Description This function is called to open a browsing connection to AVCTP. +** The connection can be either an initiator or acceptor, as +** determined by the conn_role. +** The handle is returned by a previous call to AVRC_Open. +** +** Returns AVRC_SUCCESS if successful. +** AVRC_NO_RESOURCES if there are not enough resources to open +** the connection. +** +******************************************************************************/ +extern UINT16 AVRC_OpenBrowse(UINT8 handle, UINT8 conn_role); + +/****************************************************************************** +** +** Function AVRC_CloseBrowse +** +** Description Close a connection opened with AVRC_OpenBrowse(). +** This function is called when the +** application is no longer using a connection. +** +** Returns AVRC_SUCCESS if successful. +** AVRC_BAD_HANDLE if handle is invalid. +** +******************************************************************************/ +extern UINT16 AVRC_CloseBrowse(UINT8 handle); + +/****************************************************************************** +** +** Function AVRC_MsgReq +** +** Description This function is used to send the AVRCP byte stream in p_pkt +** down to AVCTP. +** +** It is expected that p_pkt->offset is at least AVCT_MSG_OFFSET +** p_pkt->layer_specific is AVCT_DATA_CTRL or AVCT_DATA_BROWSE +** p_pkt->event is AVRC_OP_VENDOR, AVRC_OP_PASS_THRU or AVRC_OP_BROWSING +** The above BT_HDR settings are set by the AVRC_Bld* functions. +** +** Returns AVRC_SUCCESS if successful. +** AVRC_BAD_HANDLE if handle is invalid. +** +******************************************************************************/ +extern UINT16 AVRC_MsgReq (UINT8 handle, UINT8 label, UINT8 ctype, BT_HDR *p_pkt); + +/****************************************************************************** +** +** Function AVRC_UnitCmd +** +** Description Send a UNIT INFO command to the peer device. This +** function can only be called for controller role connections. +** Any response message from the peer is passed back through +** the tAVRC_MSG_CBACK callback function. +** +** Input Parameters: +** handle: Handle of this connection. +** +** label: Transaction label. +** +** Output Parameters: +** None. +** +** Returns AVRC_SUCCESS if successful. +** AVRC_BAD_HANDLE if handle is invalid. +** +******************************************************************************/ +extern UINT16 AVRC_UnitCmd(UINT8 handle, UINT8 label); + +/****************************************************************************** +** +** Function AVRC_SubCmd +** +** Description Send a SUBUNIT INFO command to the peer device. This +** function can only be called for controller role connections. +** Any response message from the peer is passed back through +** the tAVRC_MSG_CBACK callback function. +** +** Input Parameters: +** handle: Handle of this connection. +** +** label: Transaction label. +** +** page: Specifies which part of the subunit type table +** is requested. For AVRCP it is typically zero. +** Value range is 0-7. +** +** Output Parameters: +** None. +** +** Returns AVRC_SUCCESS if successful. +** AVRC_BAD_HANDLE if handle is invalid. +** +******************************************************************************/ +extern UINT16 AVRC_SubCmd(UINT8 handle, UINT8 label, UINT8 page); + + +/****************************************************************************** +** +** Function AVRC_PassCmd +** +** Description Send a PASS THROUGH command to the peer device. This +** function can only be called for controller role connections. +** Any response message from the peer is passed back through +** the tAVRC_MSG_CBACK callback function. +** +** Input Parameters: +** handle: Handle of this connection. +** +** label: Transaction label. +** +** p_msg: Pointer to PASS THROUGH message structure. +** +** Output Parameters: +** None. +** +** Returns AVRC_SUCCESS if successful. +** AVRC_BAD_HANDLE if handle is invalid. +** +******************************************************************************/ +extern UINT16 AVRC_PassCmd(UINT8 handle, UINT8 label, tAVRC_MSG_PASS *p_msg); + +/****************************************************************************** +** +** Function AVRC_PassRsp +** +** Description Send a PASS THROUGH response to the peer device. This +** function can only be called for target role connections. +** This function must be called when a PASS THROUGH command +** message is received from the peer through the +** tAVRC_MSG_CBACK callback function. +** +** Input Parameters: +** handle: Handle of this connection. +** +** label: Transaction label. Must be the same value as +** passed with the command message in the callback function. +** +** p_msg: Pointer to PASS THROUGH message structure. +** +** Output Parameters: +** None. +** +** Returns AVRC_SUCCESS if successful. +** AVRC_BAD_HANDLE if handle is invalid. +** +******************************************************************************/ +extern UINT16 AVRC_PassRsp(UINT8 handle, UINT8 label, tAVRC_MSG_PASS *p_msg); + + +/****************************************************************************** +** +** Function AVRC_VendorCmd +** +** Description Send a VENDOR DEPENDENT command to the peer device. This +** function can only be called for controller role connections. +** Any response message from the peer is passed back through +** the tAVRC_MSG_CBACK callback function. +** +** Input Parameters: +** handle: Handle of this connection. +** +** label: Transaction label. +** +** p_msg: Pointer to VENDOR DEPENDENT message structure. +** +** Output Parameters: +** None. +** +** Returns AVRC_SUCCESS if successful. +** AVRC_BAD_HANDLE if handle is invalid. +** +******************************************************************************/ +extern UINT16 AVRC_VendorCmd(UINT8 handle, UINT8 label, tAVRC_MSG_VENDOR *p_msg); + + +/****************************************************************************** +** +** Function AVRC_VendorRsp +** +** Description Send a VENDOR DEPENDENT response to the peer device. This +** function can only be called for target role connections. +** This function must be called when a VENDOR DEPENDENT +** command message is received from the peer through the +** tAVRC_MSG_CBACK callback function. +** +** Input Parameters: +** handle: Handle of this connection. +** +** label: Transaction label. Must be the same value as +** passed with the command message in the callback function. +** +** p_msg: Pointer to VENDOR DEPENDENT message structure. +** +** Output Parameters: +** None. +** +** Returns AVRC_SUCCESS if successful. +** AVRC_BAD_HANDLE if handle is invalid. +** +******************************************************************************/ +extern UINT16 AVRC_VendorRsp(UINT8 handle, UINT8 label, tAVRC_MSG_VENDOR *p_msg); + + +/****************************************************************************** +** +** Function AVRC_SetTraceLevel +** +** Description Sets the trace level for AVRC. If 0xff is passed, the +** current trace level is returned. +** +** Input Parameters: +** new_level: The level to set the AVRC tracing to: +** 0xff-returns the current setting. +** 0-turns off tracing. +** >= 1-Errors. +** >= 2-Warnings. +** >= 3-APIs. +** >= 4-Events. +** >= 5-Debug. +** +** Returns The new trace level or current trace level if +** the input parameter is 0xff. +** +******************************************************************************/ +extern UINT8 AVRC_SetTraceLevel (UINT8 new_level); + +/******************************************************************************* +** +** Function AVRC_Init +** +** Description This function is called at stack startup to allocate the +** control block (if using dynamic memory), and initializes the +** control block and tracing level. +** +** Returns void +** +*******************************************************************************/ +extern void AVRC_Init(void); + +/******************************************************************************* +** +** Function AVRC_ParsCommand +** +** Description This function is used to parse the received command. +** +** Returns AVRC_STS_NO_ERROR, if the message in p_data is parsed successfully. +** Otherwise, the error code defined by AVRCP 1.4 +** +*******************************************************************************/ +extern tAVRC_STS AVRC_ParsCommand (tAVRC_MSG *p_msg, tAVRC_COMMAND *p_result, + UINT8 *p_buf, UINT16 buf_len); + +/******************************************************************************* +** +** Function AVRC_ParsResponse +** +** Description This function is used to parse the received response. +** +** Returns AVRC_STS_NO_ERROR, if the message in p_data is parsed successfully. +** Otherwise, the error code defined by AVRCP 1.4 +** +*******************************************************************************/ +extern tAVRC_STS AVRC_ParsResponse (tAVRC_MSG *p_msg, tAVRC_RESPONSE *p_result, + UINT8 *p_buf, UINT16 buf_len); + +/******************************************************************************* +** +** Function AVRC_BldCommand +** +** Description This function builds the given AVRCP command to the given +** GKI buffer +** +** Returns AVRC_STS_NO_ERROR, if the command is built successfully +** Otherwise, the error code. +** +*******************************************************************************/ +extern tAVRC_STS AVRC_BldCommand( tAVRC_COMMAND *p_cmd, BT_HDR **pp_pkt); + +/******************************************************************************* +** +** Function AVRC_BldResponse +** +** Description This function builds the given AVRCP response to the given +** GKI buffer +** +** Returns AVRC_STS_NO_ERROR, if the response is built successfully +** Otherwise, the error code. +** +*******************************************************************************/ +extern tAVRC_STS AVRC_BldResponse( UINT8 handle, tAVRC_RESPONSE *p_rsp, BT_HDR **pp_pkt); + +/************************************************************************** +** +** Function AVRC_IsValidAvcType +** +** Description Check if correct AVC type is specified +** +** Returns returns TRUE if it is valid +** +** +*******************************************************************************/ +extern BOOLEAN AVRC_IsValidAvcType(UINT8 pdu_id, UINT8 avc_type); + +/******************************************************************************* +** +** Function AVRC_IsValidPlayerAttr +** +** Description Check if the given attrib value is a valid one +** +** +** Returns returns TRUE if it is valid +** +*******************************************************************************/ +extern BOOLEAN AVRC_IsValidPlayerAttr(UINT8 attr); + +#ifdef __cplusplus +} +#endif + +#endif /* AVRC_API_H */ diff --git a/tools/sdk/include/bluedroid/avrc_defs.h b/tools/sdk/include/bluedroid/avrc_defs.h new file mode 100644 index 00000000..fe261a74 --- /dev/null +++ b/tools/sdk/include/bluedroid/avrc_defs.h @@ -0,0 +1,1360 @@ +/****************************************************************************** + * + * Copyright (C) 2006-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. + * + ******************************************************************************/ + +/****************************************************************************** + * + * AVRCP definition and data types + * + ******************************************************************************/ +#ifndef _AVRC_DEFS_H +#define _AVRC_DEFS_H + +/***************************************************************************** +** constants +*****************************************************************************/ + +/* Profile revision numbers */ +#define AVRC_REV_1_0 0x0100 +#define AVRC_REV_1_3 0x0103 +#define AVRC_REV_1_4 0x0104 + +#define AVRC_PACKET_LEN 512 /* Per the spec, you must support 512 byte RC packets */ + +#define AVRC_MIN_CONTROL_MTU 48 /* Per the spec, minimum MTU for the control channel */ +#define AVRC_MIN_BROWSE_MTU 335 /* Per the spec, minimum MTU for the browsing channel */ + +#define AVRC_META_PDU_OFFSET 4 +#define AVRC_SUB_TYPE_LEN 4 +#define AVRC_UID_SIZE 8 +#define AVRC_FEATURE_MASK_SIZE 16 + +/* command type codes */ +#define AVRC_CMD_CTRL 0 /* Instruct a target to perform an operation */ +#define AVRC_CMD_STATUS 1 /* Check a device’s current status */ +#define AVRC_CMD_SPEC_INQ 2 /* Check whether a target supports a particular + control command; all operands are included */ +#define AVRC_CMD_NOTIF 3 /* Used for receiving notification of a change in a device’s state */ +#define AVRC_CMD_GEN_INQ 4 /* Check whether a target supports a particular + control command; operands are not included */ + +/* response type codes */ +#define AVRC_RSP_NOT_IMPL 8 /* The target does not implement the command specified + by the opcode and operand, + or doesn’t implement the specified subunit */ +#define AVRC_RSP_ACCEPT 9 /* The target executed or is executing the command */ +#define AVRC_RSP_REJ 10 /* The target implements the command specified by the + opcode but cannot respond because the current state + of the target doesn’t allow it */ +#define AVRC_RSP_IN_TRANS 11 /* The target implements the status command but it is + in a state of transition; the status command may + be retried at a future time */ +#define AVRC_RSP_IMPL_STBL 12 /* For specific inquiry or general inquiy commands, + the target implements the command; for status + commands, the target returns stable and includes + the status results */ +#define AVRC_RSP_CHANGED 13 /* The response frame contains a notification that the + target device’s state has changed */ +#define AVRC_RSP_INTERIM 15 /* For control commands, the target has accepted the + request but cannot return information within 100 + milliseconds; for notify commands, the target accepted + the command, and will notify the controller of a change + of target state at a future time */ + +/* subunit type */ +#define AVRC_SUB_MONITOR 0x00 /* Monitor */ +#define AVRC_SUB_AUDIO 0x01 /* Audio */ +#define AVRC_SUB_PRINTER 0x02 /* Printer */ +#define AVRC_SUB_DISC 0x03 /* Disc */ +#define AVRC_SUB_TAPE 0x04 /* Tape recorder/player */ +#define AVRC_SUB_TUNER 0x05 /* Tuner */ +#define AVRC_SUB_CA 0x06 /* CA */ +#define AVRC_SUB_CAMERA 0x07 /* Camera */ +#define AVRC_SUB_PANEL 0x09 /* Panel */ +#define AVRC_SUB_BB 0x0A /* Bulletin Board */ +#define AVRC_SUB_CAM_STOR 0x0B /* Camera Storage */ +#define AVRC_SUB_VENDOR 0x1C /* Vendor unique */ +#define AVRC_SUB_EXT 0x1E /* Subunit type extended to next byte */ +#define AVRC_SUB_UNIT 0x1F /* Unit */ + +/* opcodes - defined by 1394ta */ +#define AVRC_OP_UNIT_INFO 0x30 /* Report unit information */ +#define AVRC_OP_SUB_INFO 0x31 /* Report subunit information */ +#define AVRC_OP_VENDOR 0x00 /* Vendor-dependent commands */ +#define AVRC_OP_PASS_THRU 0x7C /* panel subunit opcode */ +/* opcodes 80-9F and E0-FF are not used by 1394ta.Sneak one for the browsing channel */ +#define AVRC_OP_BROWSE 0xFF /* Browsing */ +#define AVRC_OP_INVALID 0xFE /* invalid one */ + +/* Company ID's +*/ +#define AVRC_CO_BLUETOOTH_SIG 0x00FFFFFF +#define AVRC_CO_WIDCOMM 0x00000361 +#define AVRC_CO_BROADCOM 0x00001018 +#define AVRC_CO_METADATA 0x00001958 /* Unique COMPANY ID for Metadata messages */ + +/* State flag for Passthrough commands +*/ +#define AVRC_STATE_PRESS 0 +#define AVRC_STATE_RELEASE 1 + +/* Operation ID list for Passthrough commands +*/ +#define AVRC_ID_SELECT 0x00 /* select */ +#define AVRC_ID_UP 0x01 /* up */ +#define AVRC_ID_DOWN 0x02 /* down */ +#define AVRC_ID_LEFT 0x03 /* left */ +#define AVRC_ID_RIGHT 0x04 /* right */ +#define AVRC_ID_RIGHT_UP 0x05 /* right-up */ +#define AVRC_ID_RIGHT_DOWN 0x06 /* right-down */ +#define AVRC_ID_LEFT_UP 0x07 /* left-up */ +#define AVRC_ID_LEFT_DOWN 0x08 /* left-down */ +#define AVRC_ID_ROOT_MENU 0x09 /* root menu */ +#define AVRC_ID_SETUP_MENU 0x0A /* setup menu */ +#define AVRC_ID_CONT_MENU 0x0B /* contents menu */ +#define AVRC_ID_FAV_MENU 0x0C /* favorite menu */ +#define AVRC_ID_EXIT 0x0D /* exit */ +#define AVRC_ID_0 0x20 /* 0 */ +#define AVRC_ID_1 0x21 /* 1 */ +#define AVRC_ID_2 0x22 /* 2 */ +#define AVRC_ID_3 0x23 /* 3 */ +#define AVRC_ID_4 0x24 /* 4 */ +#define AVRC_ID_5 0x25 /* 5 */ +#define AVRC_ID_6 0x26 /* 6 */ +#define AVRC_ID_7 0x27 /* 7 */ +#define AVRC_ID_8 0x28 /* 8 */ +#define AVRC_ID_9 0x29 /* 9 */ +#define AVRC_ID_DOT 0x2A /* dot */ +#define AVRC_ID_ENTER 0x2B /* enter */ +#define AVRC_ID_CLEAR 0x2C /* clear */ +#define AVRC_ID_CHAN_UP 0x30 /* channel up */ +#define AVRC_ID_CHAN_DOWN 0x31 /* channel down */ +#define AVRC_ID_PREV_CHAN 0x32 /* previous channel */ +#define AVRC_ID_SOUND_SEL 0x33 /* sound select */ +#define AVRC_ID_INPUT_SEL 0x34 /* input select */ +#define AVRC_ID_DISP_INFO 0x35 /* display information */ +#define AVRC_ID_HELP 0x36 /* help */ +#define AVRC_ID_PAGE_UP 0x37 /* page up */ +#define AVRC_ID_PAGE_DOWN 0x38 /* page down */ +#define AVRC_ID_POWER 0x40 /* power */ +#define AVRC_ID_VOL_UP 0x41 /* volume up */ +#define AVRC_ID_VOL_DOWN 0x42 /* volume down */ +#define AVRC_ID_MUTE 0x43 /* mute */ +#define AVRC_ID_PLAY 0x44 /* play */ +#define AVRC_ID_STOP 0x45 /* stop */ +#define AVRC_ID_PAUSE 0x46 /* pause */ +#define AVRC_ID_RECORD 0x47 /* record */ +#define AVRC_ID_REWIND 0x48 /* rewind */ +#define AVRC_ID_FAST_FOR 0x49 /* fast forward */ +#define AVRC_ID_EJECT 0x4A /* eject */ +#define AVRC_ID_FORWARD 0x4B /* forward */ +#define AVRC_ID_BACKWARD 0x4C /* backward */ +#define AVRC_ID_ANGLE 0x50 /* angle */ +#define AVRC_ID_SUBPICT 0x51 /* subpicture */ +#define AVRC_ID_F1 0x71 /* F1 */ +#define AVRC_ID_F2 0x72 /* F2 */ +#define AVRC_ID_F3 0x73 /* F3 */ +#define AVRC_ID_F4 0x74 /* F4 */ +#define AVRC_ID_F5 0x75 /* F5 */ +#define AVRC_ID_VENDOR 0x7E /* vendor unique */ +#define AVRC_KEYPRESSED_RELEASE 0x80 + +/***************************************************************************** +** Metadata transfer definitions +*****************************************************************************/ + +/* Define the Metadata Packet types +*/ +#define AVRC_PKT_SINGLE 0 +#define AVRC_PKT_START 1 +#define AVRC_PKT_CONTINUE 2 +#define AVRC_PKT_END 3 +#define AVRC_PKT_TYPE_MASK 3 + +/* Define the PDUs carried in the vendor dependant data +*/ +#define AVRC_PDU_GET_CAPABILITIES 0x10 +#define AVRC_PDU_LIST_PLAYER_APP_ATTR 0x11 +#define AVRC_PDU_LIST_PLAYER_APP_VALUES 0x12 +#define AVRC_PDU_GET_CUR_PLAYER_APP_VALUE 0x13 +#define AVRC_PDU_SET_PLAYER_APP_VALUE 0x14 +#define AVRC_PDU_GET_PLAYER_APP_ATTR_TEXT 0x15 +#define AVRC_PDU_GET_PLAYER_APP_VALUE_TEXT 0x16 +#define AVRC_PDU_INFORM_DISPLAY_CHARSET 0x17 +#define AVRC_PDU_INFORM_BATTERY_STAT_OF_CT 0x18 +#define AVRC_PDU_GET_ELEMENT_ATTR 0x20 +#define AVRC_PDU_GET_PLAY_STATUS 0x30 +#define AVRC_PDU_REGISTER_NOTIFICATION 0x31 +#define AVRC_PDU_REQUEST_CONTINUATION_RSP 0x40 +#define AVRC_PDU_ABORT_CONTINUATION_RSP 0x41 +/* added in 1.4 */ +#define AVRC_PDU_SET_ABSOLUTE_VOLUME 0x50 +#define AVRC_PDU_SET_ADDRESSED_PLAYER 0x60 +#define AVRC_PDU_SET_BROWSED_PLAYER 0x70 +#define AVRC_PDU_GET_FOLDER_ITEMS 0x71 +#define AVRC_PDU_CHANGE_PATH 0x72 +#define AVRC_PDU_GET_ITEM_ATTRIBUTES 0x73 +#define AVRC_PDU_PLAY_ITEM 0x74 +#define AVRC_PDU_SEARCH 0x80 +#define AVRC_PDU_ADD_TO_NOW_PLAYING 0x90 +#define AVRC_PDU_GENERAL_REJECT 0xA0 + +/* Define the vendor unique id carried in the pass through data +*/ +#define AVRC_PDU_NEXT_GROUP 0x00 +#define AVRC_PDU_PREV_GROUP 0x01 +/* the only pass through vendor unique commands defined by AVRC is the group navigation commands + * The len for vendor unique data is 5 */ +#define AVRC_PASS_THRU_GROUP_LEN 5 + +#define AVRC_PDU_INVALID 0xff +/* 6.15.3 error status code for general reject */ +#define AVRC_STS_BAD_CMD 0x00 /* Invalid command, sent if TG received a PDU that it did not understand. */ +#define AVRC_STS_BAD_PARAM 0x01 /* Invalid parameter, sent if the TG received a PDU with a parameter ID that it did not understand. Sent if there is only one parameter ID in the PDU. */ +#define AVRC_STS_NOT_FOUND 0x02 /* Specified parameter not found., sent if the parameter ID is understood, but content is wrong or corrupted. */ +#define AVRC_STS_INTERNAL_ERR 0x03 /* Internal Error, sent if there are error conditions not covered by a more specific error code. */ +#define AVRC_STS_NO_ERROR 0x04 /* Operation completed without error. This is the status that should be returned if the operation was successful. */ +#define AVRC_STS_UID_CHANGED 0x05 /* UID Changed - The UIDs on the device have changed */ +/* #define AVRC_STS_GEN_ERROR 0x06 Unknown Error - this is changed to "reserved" */ +#define AVRC_STS_BAD_DIR 0x07 /* Invalid Direction - The Direction parameter is invalid - Change Path*/ +#define AVRC_STS_NOT_DIR 0x08 /* Not a Directory - The UID provided does not refer to a folder item Change Path*/ +#define AVRC_STS_NOT_EXIST 0x09 /* Does Not Exist - The UID provided does not refer to any item Change Path, PlayItem, AddToNowPlaying, GetItemAttributes*/ +#define AVRC_STS_BAD_SCOPE 0x0a /* Invalid Scope - The scope parameter is invalid GetFolderItems, PlayItem, AddToNowPlayer, GetItemAttributes, */ +#define AVRC_STS_BAD_RANGE 0x0b /* Range Out of Bounds - The start of range provided is not valid GetFolderItems*/ +#define AVRC_STS_UID_IS_DIR 0x0c /* UID is a Directory - The UID provided refers to a directory, which cannot be handled by this media player PlayItem, AddToNowPlaying */ +#define AVRC_STS_IN_USE 0x0d /* Media in Use - The media is not able to be used for this operation at this time PlayItem, AddToNowPlaying */ +#define AVRC_STS_NOW_LIST_FULL 0x0e /* Now Playing List Full - No more items can be added to the Now Playing List AddToNowPlaying*/ +#define AVRC_STS_SEARCH_NOT_SUP 0x0f /* Search Not Supported - The Browsed Media Player does not support search Search */ +#define AVRC_STS_SEARCH_BUSY 0x10 /* Search in Progress - A search operation is already in progress Search*/ +#define AVRC_STS_BAD_PLAYER_ID 0x11 /* Invalid Player Id - The specified Player Id does not refer to a valid player SetAddressedPlayer, SetBrowsedPlayer*/ +#define AVRC_STS_PLAYER_N_BR 0x12 /* Player Not Browsable - The Player Id supplied refers to a Media Player which does not support browsing. SetBrowsedPlayer */ +#define AVRC_STS_PLAYER_N_ADDR 0x13 /* Player Not Addressed. The Player Id supplied refers to a player which is not currently addressed, and the command is not able to be performed if the player is not set as addressed. Search, SetBrowsedPlayer*/ +#define AVRC_STS_BAD_SEARCH_RES 0x14 /* No valid Search Results - The Search result list does not contain valid entries, e.g. after being invalidated due to change of browsed player GetFolderItems */ +#define AVRC_STS_NO_AVAL_PLAYER 0x15 /* No available players ALL */ +#define AVRC_STS_ADDR_PLAYER_CHG 0x16 /* Addressed Player Changed - Register Notification */ +typedef UINT8 tAVRC_STS; + + +/* Define the Capability IDs +*/ +#define AVRC_CAP_COMPANY_ID 0x02 +#define AVRC_CAP_EVENTS_SUPPORTED 0x03 +#define AVRC_COMPANY_ID_LEN 3 +#define AVRC_CAPABILITY_OFFSET 2 + +/* Define the Player Application Settings IDs +*/ +#define AVRC_PLAYER_SETTING_EQUALIZER 0x01 +#define AVRC_PLAYER_SETTING_REPEAT 0x02 +#define AVRC_PLAYER_SETTING_SHUFFLE 0x03 +#define AVRC_PLAYER_SETTING_SCAN 0x04 +#define AVRC_PLAYER_SETTING_LOW_MENU_EXT 0x80 +#define AVRC_PLAYER_SETTING_HIGH_MENU_EXT 0xff + +/* Define the possible values of the Player Application Settings +*/ +#define AVRC_PLAYER_VAL_OFF 0x01 +#define AVRC_PLAYER_VAL_ON 0x02 +#define AVRC_PLAYER_VAL_SINGLE_REPEAT 0x02 +#define AVRC_PLAYER_VAL_ALL_REPEAT 0x03 +#define AVRC_PLAYER_VAL_GROUP_REPEAT 0x04 +#define AVRC_PLAYER_VAL_ALL_SHUFFLE 0x02 +#define AVRC_PLAYER_VAL_GROUP_SHUFFLE 0x03 +#define AVRC_PLAYER_VAL_ALL_SCAN 0x02 +#define AVRC_PLAYER_VAL_GROUP_SCAN 0x03 + +/* Define the possible values of Battery Status PDU +*/ +#define AVRC_BATTERY_STATUS_NORMAL 0x00 +#define AVRC_BATTERY_STATUS_WARNING 0x01 +#define AVRC_BATTERY_STATUS_CRITICAL 0x02 +#define AVRC_BATTERY_STATUS_EXTERNAL 0x03 +#define AVRC_BATTERY_STATUS_FULL_CHARGE 0x04 +typedef UINT8 tAVRC_BATTERY_STATUS; + +/* Define character set */ +#define AVRC_CHAR_SET_SIZE 2 + +/* Define the Media Attribute IDs +*/ +#define AVRC_MEDIA_ATTR_ID_TITLE 0x00000001 +#define AVRC_MEDIA_ATTR_ID_ARTIST 0x00000002 +#define AVRC_MEDIA_ATTR_ID_ALBUM 0x00000003 +#define AVRC_MEDIA_ATTR_ID_TRACK_NUM 0x00000004 +#define AVRC_MEDIA_ATTR_ID_NUM_TRACKS 0x00000005 +#define AVRC_MEDIA_ATTR_ID_GENRE 0x00000006 +#define AVRC_MEDIA_ATTR_ID_PLAYING_TIME 0x00000007 /* in miliseconds */ +#define AVRC_MAX_NUM_MEDIA_ATTR_ID 7 + +/* Define the possible values of play state +*/ +#define AVRC_PLAYSTATE_RESP_MSG_SIZE 9 +#define AVRC_PLAYSTATE_STOPPED 0x00 /* Stopped */ +#define AVRC_PLAYSTATE_PLAYING 0x01 /* Playing */ +#define AVRC_PLAYSTATE_PAUSED 0x02 /* Paused */ +#define AVRC_PLAYSTATE_FWD_SEEK 0x03 /* Fwd Seek*/ +#define AVRC_PLAYSTATE_REV_SEEK 0x04 /* Rev Seek*/ +#define AVRC_PLAYSTATE_ERROR 0xFF /* Error */ +typedef UINT8 tAVRC_PLAYSTATE; + +/* Define the events that can be registered for notifications +*/ +#define AVRC_EVT_PLAY_STATUS_CHANGE 0x01 +#define AVRC_EVT_TRACK_CHANGE 0x02 +#define AVRC_EVT_TRACK_REACHED_END 0x03 +#define AVRC_EVT_TRACK_REACHED_START 0x04 +#define AVRC_EVT_PLAY_POS_CHANGED 0x05 +#define AVRC_EVT_BATTERY_STATUS_CHANGE 0x06 +#define AVRC_EVT_SYSTEM_STATUS_CHANGE 0x07 +#define AVRC_EVT_APP_SETTING_CHANGE 0x08 +/* added in AVRCP 1.4 */ +#define AVRC_EVT_NOW_PLAYING_CHANGE 0x09 +#define AVRC_EVT_AVAL_PLAYERS_CHANGE 0x0a +#define AVRC_EVT_ADDR_PLAYER_CHANGE 0x0b +#define AVRC_EVT_UIDS_CHANGE 0x0c +#define AVRC_EVT_VOLUME_CHANGE 0x0d + +/* the number of events that can be registered for notifications */ +#define AVRC_NUM_NOTIF_EVENTS 0x0d + +#define AVRC_EVT_MSG_LEN_1 0x01 +#define AVRC_EVT_MSG_LEN_2 0x02 +#define AVRC_EVT_MSG_LEN_5 0x05 +#define AVRC_EVT_MSG_LEN_9 0x09 + +#define AVRC_MAX_VOLUME 0x7F + +/* Define the possible values of system status +*/ +#define AVRC_SYSTEMSTATE_PWR_ON 0x00 +#define AVRC_SYSTEMSTATE_PWR_OFF 0x01 +#define AVRC_SYSTEMSTATE_PWR_UNPLUGGED 0x02 +typedef UINT8 tAVRC_SYSTEMSTATE; + +/* the frequently used character set ids */ +#define AVRC_CHARSET_ID_ASCII ((UINT16) 0x0003) /* ASCII */ +#define AVRC_CHARSET_ID_UTF8 ((UINT16) 0x006a) /* UTF-8 */ +#define AVRC_CHARSET_ID_UTF16 ((UINT16) 0x03f7) /* 1015 */ +#define AVRC_CHARSET_ID_UTF32 ((UINT16) 0x03f9) /* 1017 */ + +/***************************************************************************** +** Advanced Control +*****************************************************************************/ +#define AVRC_ITEM_PLAYER 0x01 +#define AVRC_ITEM_FOLDER 0x02 +#define AVRC_ITEM_MEDIA 0x03 + +#define AVRC_SCOPE_PLAYER_LIST 0x00 /* Media Player Item - Contains all available media players */ +#define AVRC_SCOPE_FILE_SYSTEM 0x01 /* Folder Item, Media Element Item + - The virtual filesystem containing the media content of the browsed player */ +#define AVRC_SCOPE_SEARCH 0x02 /* Media Element Item The results of a search operation on the browsed player */ +#define AVRC_SCOPE_NOW_PLAYING 0x03 /* Media Element Item The Now Playing list (or queue) of the addressed player */ + +#define AVRC_FOLDER_ITEM_COUNT_NONE 0xFF + +/* folder type */ +#define AVRC_FOLDER_TYPE_MIXED 0x00 +#define AVRC_FOLDER_TYPE_TITLES 0x01 +#define AVRC_FOLDER_TYPE_ALNUMS 0x02 +#define AVRC_FOLDER_TYPE_ARTISTS 0x03 +#define AVRC_FOLDER_TYPE_GENRES 0x04 +#define AVRC_FOLDER_TYPE_PLAYLISTS 0x05 +#define AVRC_FOLDER_TYPE_YEARS 0x06 + +/* major player type */ +#define AVRC_MJ_TYPE_AUDIO 0x01 /* Audio */ +#define AVRC_MJ_TYPE_VIDEO 0x02 /* Video */ +#define AVRC_MJ_TYPE_BC_AUDIO 0x04 /* Broadcasting Audio */ +#define AVRC_MJ_TYPE_BC_VIDEO 0x08 /* Broadcasting Video */ +#define AVRC_MJ_TYPE_INVALID 0xF0 + +/* player sub type */ +#define AVRC_SUB_TYPE_NONE 0x00 +#define AVRC_SUB_TYPE_AUDIO_BOOK 0x01 /* Audio Book */ +#define AVRC_SUB_TYPE_PODCAST 0x02 /* Podcast */ +#define AVRC_SUB_TYPE_INVALID 0xFC + +/* media item - media type */ +#define AVRC_MEDIA_TYPE_AUDIO 0x00 +#define AVRC_MEDIA_TYPE_VIDEO 0x01 + +#define AVRC_DIR_UP 0x00 /* Folder Up */ +#define AVRC_DIR_DOWN 0x01 /* Folder Down */ + +#define AVRC_UID_SIZE 8 +typedef UINT8 tAVRC_UID[AVRC_UID_SIZE]; + +/***************************************************************************** +** player attribute - supported features +*****************************************************************************/ +#define AVRC_PF_SELECT_BIT_NO 0 +#define AVRC_PF_SELECT_MASK 0x01 +#define AVRC_PF_SELECT_OFF 0 +#define AVRC_PF_SELECT_SUPPORTED(x) ((x)[AVRC_PF_SELECT_OFF] & AVRC_PF_SELECT_MASK) + +#define AVRC_PF_UP_BIT_NO 1 +#define AVRC_PF_UP_MASK 0x02 +#define AVRC_PF_UP_OFF 0 +#define AVRC_PF_UP_SUPPORTED(x) ((x)[AVRC_PF_UP_OFF] & AVRC_PF_UP_MASK) + +#define AVRC_PF_DOWN_BIT_NO 2 +#define AVRC_PF_DOWN_MASK 0x04 +#define AVRC_PF_DOWN_OFF 0 +#define AVRC_PF_DOWN_SUPPORTED(x) ((x)[AVRC_PF_DOWN_OFF] & AVRC_PF_DOWN_MASK) + +#define AVRC_PF_LEFT_BIT_NO 3 +#define AVRC_PF_LEFT_MASK 0x08 +#define AVRC_PF_LEFT_OFF 0 +#define AVRC_PF_LEFT_SUPPORTED(x) ((x)[AVRC_PF_LEFT_OFF] & AVRC_PF_LEFT_MASK) + +#define AVRC_PF_RIGHT_BIT_NO 4 +#define AVRC_PF_RIGHT_MASK 0x10 +#define AVRC_PF_RIGHT_OFF 0 +#define AVRC_PF_RIGHT_SUPPORTED(x) ((x)[AVRC_PF_RIGHT_OFF] & AVRC_PF_RIGHT_MASK) + +#define AVRC_PF_RIGHTUP_BIT_NO 5 +#define AVRC_PF_RIGHTUP_MASK 0x20 +#define AVRC_PF_RIGHTUP_OFF 0 +#define AVRC_PF_RIGHTUP_SUPPORTED(x) ((x)[AVRC_PF_RIGHTUP_OFF] & AVRC_PF_RIGHTUP_MASK) + +#define AVRC_PF_RIGHTDOWN_BIT_NO 6 +#define AVRC_PF_RIGHTDOWN_MASK 0x40 +#define AVRC_PF_RIGHTDOWN_OFF 0 +#define AVRC_PF_RIGHTDOWN_SUPPORTED(x) ((x)[AVRC_PF_RIGHTDOWN_OFF] & AVRC_PF_RIGHTDOWN_MASK) + +#define AVRC_PF_LEFTUP_BIT_NO 7 +#define AVRC_PF_LEFTUP_MASK 0x80 +#define AVRC_PF_LEFTUP_OFF 0 +#define AVRC_PF_LEFTUP_SUPPORTED(x) ((x)[AVRC_PF_LEFTUP_OFF] & AVRC_PF_LEFTUP_MASK) + +#define AVRC_PF_LEFTDOWN_BIT_NO 8 +#define AVRC_PF_LEFTDOWN_MASK 0x01 +#define AVRC_PF_LEFTDOWN_OFF 1 +#define AVRC_PF_LEFTDOWN_SUPPORTED(x) ((x)[AVRC_PF_LEFTDOWN_OFF] & AVRC_PF_LEFTDOWN_MASK) + +#define AVRC_PF_ROOT_MENU_BIT_NO 9 +#define AVRC_PF_ROOT_MENU_MASK 0x02 +#define AVRC_PF_ROOT_MENU_OFF 1 +#define AVRC_PF_ROOT_MENU_SUPPORTED(x) ((x)[AVRC_PF_ROOT_MENU_OFF] & AVRC_PF_ROOT_MENU_MASK) + +#define AVRC_PF_SETUP_MENU_BIT_NO 10 +#define AVRC_PF_SETUP_MENU_MASK 0x04 +#define AVRC_PF_SETUP_MENU_OFF 1 +#define AVRC_PF_SETUP_MENU_SUPPORTED(x) ((x)[AVRC_PF_SETUP_MENU_OFF] & AVRC_PF_SETUP_MENU_MASK) + +#define AVRC_PF_CONTENTS_MENU_BIT_NO 11 +#define AVRC_PF_CONTENTS_MENU_MASK 0x08 +#define AVRC_PF_CONTENTS_MENU_OFF 1 +#define AVRC_PF_CONTENTS_MENU_SUPPORTED(x) ((x)[AVRC_PF_CONTENTS_MENU_OFF] & AVRC_PF_CONTENTS_MENU_MASK) + +#define AVRC_PF_FAVORITE_MENU_BIT_NO 12 +#define AVRC_PF_FAVORITE_MENU_MASK 0x10 +#define AVRC_PF_FAVORITE_MENU_OFF 1 +#define AVRC_PF_FAVORITE_MENU_SUPPORTED(x) ((x)[AVRC_PF_FAVORITE_MENU_OFF] & AVRC_PF_FAVORITE_MENU_MASK) + +#define AVRC_PF_EXIT_BIT_NO 13 +#define AVRC_PF_EXIT_MASK 0x20 +#define AVRC_PF_EXIT_OFF 1 +#define AVRC_PF_EXIT_SUPPORTED(x) ((x)[AVRC_PF_EXIT_OFF] & AVRC_PF_EXIT_MASK) + +#define AVRC_PF_0_BIT_NO 14 +#define AVRC_PF_0_MASK 0x40 +#define AVRC_PF_0_OFF 1 +#define AVRC_PF_0_SUPPORTED(x) ((x)[AVRC_PF_0_OFF] & AVRC_PF_0_MASK) + +#define AVRC_PF_1_BIT_NO 15 +#define AVRC_PF_1_MASK 0x80 +#define AVRC_PF_1_OFF 1 +#define AVRC_PF_1_SUPPORTED(x) ((x)[AVRC_PF_1_OFF] & AVRC_PF_1_MASK) + +#define AVRC_PF_2_BIT_NO 16 +#define AVRC_PF_2_MASK 0x01 +#define AVRC_PF_2_OFF 2 +#define AVRC_PF_2_SUPPORTED(x) ((x)[AVRC_PF_2_OFF] & AVRC_PF_2_MASK) + +#define AVRC_PF_3_BIT_NO 17 +#define AVRC_PF_3_MASK 0x02 +#define AVRC_PF_3_OFF 2 +#define AVRC_PF_3_SUPPORTED(x) ((x)[AVRC_PF_3_OFF] & AVRC_PF_3_MASK) + +#define AVRC_PF_4_BIT_NO 18 +#define AVRC_PF_4_MASK 0x04 +#define AVRC_PF_4_OFF 2 +#define AVRC_PF_4_SUPPORTED(x) ((x)[AVRC_PF_4_OFF] & AVRC_PF_4_MASK) + +#define AVRC_PF_5_BIT_NO 19 +#define AVRC_PF_5_MASK 0x08 +#define AVRC_PF_5_OFF 2 +#define AVRC_PF_5_SUPPORTED(x) ((x)[AVRC_PF_5_OFF] & AVRC_PF_5_MASK) + +#define AVRC_PF_6_BIT_NO 20 +#define AVRC_PF_6_MASK 0x10 +#define AVRC_PF_6_OFF 2 +#define AVRC_PF_6_SUPPORTED(x) ((x)[AVRC_PF_6_OFF] & AVRC_PF_6_MASK) + +#define AVRC_PF_7_BIT_NO 21 +#define AVRC_PF_7_MASK 0x20 +#define AVRC_PF_7_OFF 2 +#define AVRC_PF_7_SUPPORTED(x) ((x)[AVRC_PF_7_OFF] & AVRC_PF_7_MASK) + +#define AVRC_PF_8_BIT_NO 22 +#define AVRC_PF_8_MASK 0x40 +#define AVRC_PF_8_OFF 2 +#define AVRC_PF_8_SUPPORTED(x) ((x)[AVRC_PF_8_OFF] & AVRC_PF_8_MASK) + +#define AVRC_PF_9_BIT_NO 23 +#define AVRC_PF_9_MASK 0x80 +#define AVRC_PF_9_OFF 2 +#define AVRC_PF_9_SUPPORTED(x) ((x)[AVRC_PF_9_OFF] & AVRC_PF_9_MASK) + +#define AVRC_PF_DOT_BIT_NO 24 +#define AVRC_PF_DOT_MASK 0x01 +#define AVRC_PF_DOT_OFF 3 +#define AVRC_PF_DOT_SUPPORTED(x) ((x)[AVRC_PF_DOT_OFF] & AVRC_PF_DOT_MASK) + +#define AVRC_PF_ENTER_BIT_NO 25 +#define AVRC_PF_ENTER_MASK 0x02 +#define AVRC_PF_ENTER_OFF 3 +#define AVRC_PF_ENTER_SUPPORTED(x) ((x)[AVRC_PF_ENTER_OFF] & AVRC_PF_ENTER_MASK) + +#define AVRC_PF_CLEAR_BIT_NO 26 +#define AVRC_PF_CLEAR_MASK 0x04 +#define AVRC_PF_CLEAR_OFF 3 +#define AVRC_PF_CLEAR_SUPPORTED(x) ((x)[AVRC_PF_CLEAR_OFF] & AVRC_PF_CLEAR_MASK) + +#define AVRC_PF_CHNL_UP_BIT_NO 27 +#define AVRC_PF_CHNL_UP_MASK 0x08 +#define AVRC_PF_CHNL_UP_OFF 3 +#define AVRC_PF_CHNL_UP_SUPPORTED(x) ((x)[AVRC_PF_CHNL_UP_OFF] & AVRC_PF_CHNL_UP_MASK) + +#define AVRC_PF_CHNL_DOWN_BIT_NO 28 +#define AVRC_PF_CHNL_DOWN_MASK 0x10 +#define AVRC_PF_CHNL_DOWN_OFF 3 +#define AVRC_PF_CHNL_DOWN_SUPPORTED(x) ((x)[AVRC_PF_CHNL_DOWN_OFF] & AVRC_PF_CHNL_DOWN_MASK) + +#define AVRC_PF_PREV_CHNL_BIT_NO 29 +#define AVRC_PF_PREV_CHNL_MASK 0x20 +#define AVRC_PF_PREV_CHNL_OFF 3 +#define AVRC_PF_PREV_CHNL_SUPPORTED(x) ((x)[AVRC_PF_PREV_CHNL_OFF] & AVRC_PF_PREV_CHNL_MASK) + +#define AVRC_PF_SOUND_SEL_BIT_NO 30 +#define AVRC_PF_SOUND_SEL_MASK 0x40 +#define AVRC_PF_SOUND_SEL_OFF 3 +#define AVRC_PF_SOUND_SEL_SUPPORTED(x) ((x)[AVRC_PF_SOUND_SEL_OFF] & AVRC_PF_SOUND_SEL_MASK) + +#define AVRC_PF_INPUT_SEL_BIT_NO 31 +#define AVRC_PF_INPUT_SEL_MASK 0x80 +#define AVRC_PF_INPUT_SEL_OFF 3 +#define AVRC_PF_INPUT_SEL_SUPPORTED(x) ((x)[AVRC_PF_INPUT_SEL_OFF] & AVRC_PF_INPUT_SEL_MASK) + +#define AVRC_PF_DISP_INFO_BIT_NO 32 +#define AVRC_PF_DISP_INFO_MASK 0x01 +#define AVRC_PF_DISP_INFO_OFF 4 +#define AVRC_PF_DISP_INFO_SUPPORTED(x) ((x)[AVRC_PF_DISP_INFO_OFF] & AVRC_PF_DISP_INFO_MASK) + +#define AVRC_PF_HELP_BIT_NO 33 +#define AVRC_PF_HELP_MASK 0x02 +#define AVRC_PF_HELP_OFF 4 +#define AVRC_PF_HELP_SUPPORTED(x) ((x)[AVRC_PF_HELP_OFF] & AVRC_PF_HELP_MASK) + +#define AVRC_PF_PAGE_UP_BIT_NO 34 +#define AVRC_PF_PAGE_UP_MASK 0x04 +#define AVRC_PF_PAGE_UP_OFF 4 +#define AVRC_PF_PAGE_UP_SUPPORTED(x) ((x)[AVRC_PF_PAGE_UP_OFF] & AVRC_PF_PAGE_UP_MASK) + +#define AVRC_PF_PAGE_DOWN_BIT_NO 35 +#define AVRC_PF_PAGE_DOWN_MASK 0x08 +#define AVRC_PF_PAGE_DOWN_OFF 4 +#define AVRC_PF_PAGE_DOWN_SUPPORTED(x) ((x)[AVRC_PF_PAGE_DOWN_OFF] & AVRC_PF_PAGE_DOWN_MASK) + +#define AVRC_PF_POWER_BIT_NO 36 +#define AVRC_PF_POWER_MASK 0x10 +#define AVRC_PF_POWER_OFF 4 +#define AVRC_PF_POWER_SUPPORTED(x) ((x)[AVRC_PF_POWER_OFF] & AVRC_PF_POWER_MASK) + +#define AVRC_PF_VOL_UP_BIT_NO 37 +#define AVRC_PF_VOL_UP_MASK 0x20 +#define AVRC_PF_VOL_UP_OFF 4 +#define AVRC_PF_VOL_UP_SUPPORTED(x) ((x)[AVRC_PF_VOL_UP_OFF] & AVRC_PF_VOL_UP_MASK) + +#define AVRC_PF_VOL_DOWN_BIT_NO 38 +#define AVRC_PF_VOL_DOWN_MASK 0x40 +#define AVRC_PF_VOL_DOWN_OFF 4 +#define AVRC_PF_VOL_DOWN_SUPPORTED(x) ((x)[AVRC_PF_VOL_DOWN_OFF] & AVRC_PF_VOL_DOWN_MASK) + +#define AVRC_PF_MUTE_BIT_NO 39 +#define AVRC_PF_MUTE_MASK 0x80 +#define AVRC_PF_MUTE_OFF 4 +#define AVRC_PF_MUTE_SUPPORTED(x) ((x)[AVRC_PF_MUTE_OFF] & AVRC_PF_MUTE_MASK) + +#define AVRC_PF_PLAY_BIT_NO 40 +#define AVRC_PF_PLAY_MASK 0x01 +#define AVRC_PF_PLAY_OFF 5 +#define AVRC_PF_PLAY_SUPPORTED(x) ((x)[AVRC_PF_PLAY_OFF] & AVRC_PF_PLAY_MASK) + +#define AVRC_PF_STOP_BIT_NO 41 +#define AVRC_PF_STOP_MASK 0x02 +#define AVRC_PF_STOP_OFF 5 +#define AVRC_PF_STOP_SUPPORTED(x) ((x)[AVRC_PF_STOP_OFF] & AVRC_PF_STOP_MASK) + +#define AVRC_PF_PAUSE_BIT_NO 42 +#define AVRC_PF_PAUSE_MASK 0x04 +#define AVRC_PF_PAUSE_OFF 5 +#define AVRC_PF_PAUSE_SUPPORTED(x) ((x)[AVRC_PF_PAUSE_OFF] & AVRC_PF_PAUSE_MASK) + +#define AVRC_PF_RECORD_BIT_NO 43 +#define AVRC_PF_RECORD_MASK 0x08 +#define AVRC_PF_RECORD_OFF 5 +#define AVRC_PF_RECORD_SUPPORTED(x) ((x)[AVRC_PF_RECORD_OFF] & AVRC_PF_RECORD_MASK) + +#define AVRC_PF_REWIND_BIT_NO 44 +#define AVRC_PF_REWIND_MASK 0x10 +#define AVRC_PF_REWIND_OFF 5 +#define AVRC_PF_REWIND_SUPPORTED(x) ((x)[AVRC_PF_REWIND_OFF] & AVRC_PF_REWIND_MASK) + +#define AVRC_PF_FAST_FWD_BIT_NO 45 +#define AVRC_PF_FAST_FWD_MASK 0x20 +#define AVRC_PF_FAST_FWD_OFF 5 +#define AVRC_PF_FAST_FWD_SUPPORTED(x) ((x)[AVRC_PF_FAST_FWD_OFF] & AVRC_PF_FAST_FWD_MASK) + +#define AVRC_PF_EJECT_BIT_NO 46 +#define AVRC_PF_EJECT_MASK 0x40 +#define AVRC_PF_EJECT_OFF 5 +#define AVRC_PF_EJECT_SUPPORTED(x) ((x)[AVRC_PF_EJECT_OFF] & AVRC_PF_EJECT_MASK) + +#define AVRC_PF_FORWARD_BIT_NO 47 +#define AVRC_PF_FORWARD_MASK 0x80 +#define AVRC_PF_FORWARD_OFF 5 +#define AVRC_PF_FORWARD_SUPPORTED(x) ((x)[AVRC_PF_FORWARD_OFF] & AVRC_PF_FORWARD_MASK) + +#define AVRC_PF_BACKWARD_BIT_NO 48 +#define AVRC_PF_BACKWARD_MASK 0x01 +#define AVRC_PF_BACKWARD_OFF 6 +#define AVRC_PF_BACKWARD_SUPPORTED(x) ((x)[AVRC_PF_BACKWARD_OFF] & AVRC_PF_BACKWARD_MASK) + +#define AVRC_PF_ANGLE_BIT_NO 49 +#define AVRC_PF_ANGLE_MASK 0x02 +#define AVRC_PF_ANGLE_OFF 6 +#define AVRC_PF_ANGLE_SUPPORTED(x) ((x)[AVRC_PF_ANGLE_OFF] & AVRC_PF_ANGLE_MASK) + +#define AVRC_PF_SUBPICTURE_BIT_NO 50 +#define AVRC_PF_SUBPICTURE_MASK 0x04 +#define AVRC_PF_SUBPICTURE_OFF 6 +#define AVRC_PF_SUBPICTURE_SUPPORTED(x) ((x)[AVRC_PF_SUBPICTURE_OFF] & AVRC_PF_SUBPICTURE_MASK) + +#define AVRC_PF_F1_BIT_NO 51 +#define AVRC_PF_F1_MASK 0x08 +#define AVRC_PF_F1_OFF 6 +#define AVRC_PF_F1_SUPPORTED(x) ((x)[AVRC_PF_F1_OFF] & AVRC_PF_F1_MASK) + +#define AVRC_PF_F2_BIT_NO 52 +#define AVRC_PF_F2_MASK 0x10 +#define AVRC_PF_F2_OFF 6 +#define AVRC_PF_F2_SUPPORTED(x) ((x)[AVRC_PF_F2_OFF] & AVRC_PF_F2_MASK) + +#define AVRC_PF_F3_BIT_NO 53 +#define AVRC_PF_F3_MASK 0x20 +#define AVRC_PF_F3_OFF 6 +#define AVRC_PF_F3_SUPPORTED(x) ((x)[AVRC_PF_F3_OFF] & AVRC_PF_F3_MASK) + +#define AVRC_PF_F4_BIT_NO 54 +#define AVRC_PF_F4_MASK 0x40 +#define AVRC_PF_F4_OFF 6 +#define AVRC_PF_F4_SUPPORTED(x) ((x)[AVRC_PF_F4_OFF] & AVRC_PF_F4_MASK) + +#define AVRC_PF_F5_BIT_NO 55 +#define AVRC_PF_F5_MASK 0x80 +#define AVRC_PF_F5_OFF 6 +#define AVRC_PF_F5_SUPPORTED(x) ((x)[AVRC_PF_F5_OFF] & AVRC_PF_F5_MASK) + +/* Vendor unique. This PASSTHROUGH command is supported. */ +#define AVRC_PF_VENDOR_BIT_NO 56 +#define AVRC_PF_VENDOR_MASK 0x01 +#define AVRC_PF_VENDOR_OFF 7 +#define AVRC_PF_VENDOR_SUPPORTED(x) ((x)[AVRC_PF_VENDOR_OFF] & AVRC_PF_VENDOR_MASK) + +/* Basic Group Navigation. This overrules the SDP entry as it is set per player.7 */ +#define AVRC_PF_GROUP_NAVI_BIT_NO 57 +#define AVRC_PF_GROUP_NAVI_MASK 0x02 +#define AVRC_PF_GROUP_NAVI_OFF 7 +#define AVRC_PF_GROUP_NAVI_SUPPORTED(x) ((x)[AVRC_PF_GROUP_NAVI_OFF] & AVRC_PF_GROUP_NAVI_MASK) + +/* Advanced Control Player. This bit is set if the player supports at least AVRCP 1.4. */ +#define AVRC_PF_ADV_CTRL_BIT_NO 58 +#define AVRC_PF_ADV_CTRL_MASK 0x04 +#define AVRC_PF_ADV_CTRL_OFF 7 +#define AVRC_PF_ADV_CTRL_SUPPORTED(x) ((x)[AVRC_PF_ADV_CTRL_OFF] & AVRC_PF_ADV_CTRL_MASK) + +/* Browsing. This bit is set if the player supports browsing. */ +#define AVRC_PF_BROWSE_BIT_NO 59 +#define AVRC_PF_BROWSE_MASK 0x08 +#define AVRC_PF_BROWSE_OFF 7 +#define AVRC_PF_BROWSE_SUPPORTED(x) ((x)[AVRC_PF_BROWSE_OFF] & AVRC_PF_BROWSE_MASK) + +/* Searching. This bit is set if the player supports searching. */ +#define AVRC_PF_SEARCH_BIT_NO 60 +#define AVRC_PF_SEARCH_MASK 0x10 +#define AVRC_PF_SEARCH_OFF 7 +#define AVRC_PF_SEARCH_SUPPORTED(x) ((x)[AVRC_PF_SEARCH_OFF] & AVRC_PF_SEARCH_MASK) + +/* AddToNowPlaying. This bit is set if the player supports the AddToNowPlaying command. */ +#define AVRC_PF_ADD2NOWPLAY_BIT_NO 61 +#define AVRC_PF_ADD2NOWPLAY_MASK 0x20 +#define AVRC_PF_ADD2NOWPLAY_OFF 7 +#define AVRC_PF_ADD2NOWPLAY_SUPPORTED(x) ((x)[AVRC_PF_ADD2NOWPLAY_OFF] & AVRC_PF_ADD2NOWPLAY_MASK) + +/* UIDs unique in player browse tree. This bit is set if the player is able to maintain unique UIDs across the player browse tree. */ +#define AVRC_PF_UID_UNIQUE_BIT_NO 62 +#define AVRC_PF_UID_UNIQUE_MASK 0x40 +#define AVRC_PF_UID_UNIQUE_OFF 7 +#define AVRC_PF_UID_UNIQUE_SUPPORTED(x) ((x)[AVRC_PF_UID_UNIQUE_OFF] & AVRC_PF_UID_UNIQUE_MASK) + +/* OnlyBrowsableWhenAddressed. This bit is set if the player is only able to be browsed when it is set as the Addressed Player. */ +#define AVRC_PF_BR_WH_ADDR_BIT_NO 63 +#define AVRC_PF_BR_WH_ADDR_MASK 0x80 +#define AVRC_PF_BR_WH_ADDR_OFF 7 +#define AVRC_PF_BR_WH_ADDR_SUPPORTED(x) ((x)[AVRC_PF_BR_WH_ADDR_OFF] & AVRC_PF_BR_WH_ADDR_MASK) + +/* OnlySearchableWhenAddressed. This bit is set if the player is only able to be searched when it is set as the Addressed player. */ +#define AVRC_PF_SEARCH_WH_ADDR_BIT_NO 64 +#define AVRC_PF_SEARCH_WH_ADDR_MASK 0x01 +#define AVRC_PF_SEARCH_WH_ADDR_OFF 8 +#define AVRC_PF_SEARCH_WH_ADDR_SUPPORTED(x) ((x)[AVRC_PF_SEARCH_WH_ADDR_OFF] & AVRC_PF_SEARCH_WH_ADDR_MASK) + +/* NowPlaying. This bit is set if the player supports the NowPlaying folder. Note that for all players that support browsing this bit shall be set */ +#define AVRC_PF_NOW_PLAY_BIT_NO 65 +#define AVRC_PF_NOW_PLAY_MASK 0x02 +#define AVRC_PF_NOW_PLAY_OFF 8 +#define AVRC_PF_NOW_PLAY_SUPPORTED(x) ((x)[AVRC_PF_NOW_PLAY_OFF] & AVRC_PF_NOW_PLAY_MASK) + +/* UIDPersistency. This bit is set if the Player is able to persist UID values between AVRCP Browse Reconnect */ +#define AVRC_PF_UID_PERSIST_BIT_NO 66 +#define AVRC_PF_UID_PERSIST_MASK 0x04 +#define AVRC_PF_UID_PERSIST_OFF 8 +#define AVRC_PF_UID_PERSIST_SUPPORTED(x) ((x)[AVRC_PF_UID_PERSIST_OFF] & AVRC_PF_UID_PERSIST_MASK) + +/***************************************************************************** +** data type definitions +*****************************************************************************/ + +/* +This structure contains the header parameters of an AV/C message. +*/ +typedef struct { + UINT8 ctype; /* Command type. */ + UINT8 subunit_type; /* Subunit type. */ + UINT8 subunit_id; /* Subunit ID. This value is typically ignored in AVRCP, + * except for VENDOR DEPENDENT messages when the value is + * vendor-dependent. Value range is 0-7. */ + UINT8 opcode; /* Op Code (passthrough, vendor, etc) */ +} tAVRC_HDR; + +/* This structure contains a UNIT INFO message. */ +typedef struct { + tAVRC_HDR hdr; /* Message header. */ + UINT32 company_id; /* Company identifier. */ + UINT8 unit_type; /* Unit type. Uses the same values as subunit type. */ + UINT8 unit; /* This value is vendor dependent and typically zero. */ +} tAVRC_MSG_UNIT; + +/* This structure contains a SUBUNIT INFO message. */ +typedef struct { + tAVRC_HDR hdr; /* Message header. */ + UINT8 subunit_type[AVRC_SUB_TYPE_LEN]; + /* Array containing subunit type values. */ + BOOLEAN panel; /* TRUE if the panel subunit type is in the + * subunit_type array, FALSE otherwise. */ + UINT8 page; /* Specifies which part of the subunit type table is + * returned. For AVRCP it is typically zero. + * Value range is 0-7. */ +} tAVRC_MSG_SUB; + +/* This structure contains a VENDOR DEPENDENT message. */ +typedef struct { + tAVRC_HDR hdr; /* Message header. */ + UINT32 company_id; /* Company identifier. */ + UINT8 *p_vendor_data;/* Pointer to vendor dependent data. */ + UINT16 vendor_len; /* Length in bytes of vendor dependent data. */ +} tAVRC_MSG_VENDOR; + +/* PASS THROUGH message structure */ +typedef struct { + tAVRC_HDR hdr; /* hdr.ctype Unused. + * hdr.subunit_type Unused. + * hdr.subunit_id Unused. */ + UINT8 op_id; /* Operation ID. */ + UINT8 state; /* Keypress state. */ + UINT8 *p_pass_data;/* Pointer to data. This parameter is only valid + * when the op_id is AVRC_ID_VENDOR.*/ + UINT8 pass_len; /* Length in bytes of data. This parameter is only + * valid when the op_id is AVRC_ID_VENDOR.*/ +} tAVRC_MSG_PASS; + +/* Command/Response indicator. */ +#define AVRC_CMD AVCT_CMD /* Command message */ +#define AVRC_RSP AVCT_RSP /* Response message */ + +/* Browsing channel message structure */ +typedef struct { + tAVRC_HDR hdr; /* hdr.ctype AVRC_CMD or AVRC_RSP. + * hdr.subunit_type Unused. + * hdr.subunit_id Unused. */ + UINT8 *p_browse_data; /* Pointer to data. */ + UINT16 browse_len; /* Length in bytes of data. */ + BT_HDR *p_browse_pkt; /* The GKI buffer received. Set to NULL, if the callback function wants to keep the buffer */ +} tAVRC_MSG_BROWSE; + +/* This is a union of all message type structures. */ +typedef union { + tAVRC_HDR hdr; /* Message header. */ + tAVRC_MSG_UNIT unit; /* UNIT INFO message. */ + tAVRC_MSG_SUB sub; /* SUBUNIT INFO message. */ + tAVRC_MSG_VENDOR vendor; /* VENDOR DEPENDENT message. */ + tAVRC_MSG_PASS pass; /* PASS THROUGH message. */ + tAVRC_MSG_BROWSE browse; /* messages thru browsing channel */ +} tAVRC_MSG; + +/* macros */ +#define AVRC_IS_VALID_CAP_ID(a) (((a == AVRC_CAP_COMPANY_ID) || (a == AVRC_CAP_EVENTS_SUPPORTED)) ? TRUE : FALSE) + +#define AVRC_IS_VALID_EVENT_ID(a) (((a >= AVRC_EVT_PLAY_STATUS_CHANGE) && \ + (a <= AVRC_EVT_APP_SETTING_CHANGE)) ? TRUE : FALSE) + +#define AVRC_IS_VALID_ATTRIBUTE(a) (((((a > 0) && a <= AVRC_PLAYER_SETTING_SCAN)) || \ + (a >= AVRC_PLAYER_SETTING_LOW_MENU_EXT)) ? TRUE : FALSE) + +#define AVRC_IS_VALID_MEDIA_ATTRIBUTE(a) ((a >= AVRC_MEDIA_ATTR_ID_TITLE) && \ + (a <= AVRC_MEDIA_ATTR_ID_PLAYING_TIME) ? TRUE : FALSE) + +#define AVRC_IS_VALID_BATTERY_STATUS(a) ((a <= AVRC_BATTERY_STATUS_FULL_CHARGE) ? TRUE : FALSE) + +#define AVRC_IS_VALID_SYSTEM_STATUS(a) ((a <= AVRC_SYSTEMSTATE_PWR_UNPLUGGED) ? TRUE : FALSE) + +#define AVRC_IS_VALID_GROUP(a) ((a <= AVRC_PDU_PREV_GROUP) ? TRUE : FALSE) + +/* Company ID is 24-bit integer We can not use the macros in bt_types.h */ +#define AVRC_CO_ID_TO_BE_STREAM(p, u32) {*(p)++ = (UINT8)((u32) >> 16); *(p)++ = (UINT8)((u32) >> 8); *(p)++ = (UINT8)(u32); } +#define AVRC_BE_STREAM_TO_CO_ID(u32, p) {u32 = (((UINT32)(*((p) + 2))) + (((UINT32)(*((p) + 1))) << 8) + (((UINT32)(*(p))) << 16)); (p) += 3;} + +/***************************************************************************** +** data type definitions +*****************************************************************************/ +#define AVRC_MAX_APP_ATTR_SIZE 16 +#define AVRC_MAX_CHARSET_SIZE 16 +#define AVRC_MAX_ELEM_ATTR_SIZE 8 + + +/***************************************************************************** +** Metadata transfer Building/Parsing definitions +*****************************************************************************/ + +typedef struct { + UINT16 charset_id; + UINT16 str_len; + UINT8 *p_str; +} tAVRC_FULL_NAME; + +typedef struct { + UINT16 str_len; + UINT8 *p_str; +} tAVRC_NAME; + + +#ifndef AVRC_CAP_MAX_NUM_COMP_ID +#define AVRC_CAP_MAX_NUM_COMP_ID 4 +#endif + +#ifndef AVRC_CAP_MAX_NUM_EVT_ID +#define AVRC_CAP_MAX_NUM_EVT_ID 16 +#endif + +typedef union { + UINT32 company_id[AVRC_CAP_MAX_NUM_COMP_ID]; + UINT8 event_id[AVRC_CAP_MAX_NUM_EVT_ID]; +} tAVRC_CAPS_PARAM; + +typedef struct { + UINT8 attr_id; + UINT8 attr_val; +} tAVRC_APP_SETTING; + +typedef struct { + UINT8 attr_id; + UINT16 charset_id; + UINT8 str_len; + UINT8 *p_str; +} tAVRC_APP_SETTING_TEXT; + +typedef UINT8 tAVRC_FEATURE_MASK[AVRC_FEATURE_MASK_SIZE]; + +typedef struct { + UINT16 player_id; /* A unique identifier for this media player.*/ + UINT8 major_type; /* Use AVRC_MJ_TYPE_AUDIO, AVRC_MJ_TYPE_VIDEO, AVRC_MJ_TYPE_BC_AUDIO, or AVRC_MJ_TYPE_BC_VIDEO.*/ + UINT32 sub_type; /* Use AVRC_SUB_TYPE_NONE, AVRC_SUB_TYPE_AUDIO_BOOK, or AVRC_SUB_TYPE_PODCAST*/ + UINT8 play_status; /* Use AVRC_PLAYSTATE_STOPPED, AVRC_PLAYSTATE_PLAYING, AVRC_PLAYSTATE_PAUSED, AVRC_PLAYSTATE_FWD_SEEK, + AVRC_PLAYSTATE_REV_SEEK, or AVRC_PLAYSTATE_ERROR*/ + tAVRC_FEATURE_MASK features; /* Supported feature bit mask*/ + tAVRC_FULL_NAME name; /* The player name, name length and character set id.*/ +} tAVRC_ITEM_PLAYER; + +typedef struct { + tAVRC_UID uid; /* The uid of this folder */ + UINT8 type; /* Use AVRC_FOLDER_TYPE_MIXED, AVRC_FOLDER_TYPE_TITLES, + AVRC_FOLDER_TYPE_ALNUMS, AVRC_FOLDER_TYPE_ARTISTS, AVRC_FOLDER_TYPE_GENRES, + AVRC_FOLDER_TYPE_PLAYLISTS, or AVRC_FOLDER_TYPE_YEARS.*/ + BOOLEAN playable; /* TRUE, if the folder can be played. */ + tAVRC_FULL_NAME name; /* The folder name, name length and character set id. */ +} tAVRC_ITEM_FOLDER; + +typedef struct { + UINT32 attr_id; /* Use AVRC_MEDIA_ATTR_ID_TITLE, AVRC_MEDIA_ATTR_ID_ARTIST, AVRC_MEDIA_ATTR_ID_ALBUM, + AVRC_MEDIA_ATTR_ID_TRACK_NUM, AVRC_MEDIA_ATTR_ID_NUM_TRACKS, + AVRC_MEDIA_ATTR_ID_GENRE, AVRC_MEDIA_ATTR_ID_PLAYING_TIME */ + tAVRC_FULL_NAME name; /* The attribute value, value length and character set id. */ +} tAVRC_ATTR_ENTRY; + +typedef struct { + tAVRC_UID uid; /* The uid of this media element item */ + UINT8 type; /* Use AVRC_MEDIA_TYPE_AUDIO or AVRC_MEDIA_TYPE_VIDEO. */ + tAVRC_FULL_NAME name; /* The media name, name length and character set id. */ + UINT8 attr_count; /* The number of attributes in p_attr_list */ + tAVRC_ATTR_ENTRY *p_attr_list; /* Attribute entry list. */ +} tAVRC_ITEM_MEDIA; + +typedef struct { + UINT8 item_type; /* AVRC_ITEM_PLAYER, AVRC_ITEM_FOLDER, or AVRC_ITEM_MEDIA */ + union { + tAVRC_ITEM_PLAYER player; /* The properties of a media player item.*/ + tAVRC_ITEM_FOLDER folder; /* The properties of a folder item.*/ + tAVRC_ITEM_MEDIA media; /* The properties of a media item.*/ + } u; +} tAVRC_ITEM; + +/* GetCapability */ +typedef struct { + UINT8 pdu; + tAVRC_STS status; + UINT8 opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ + UINT8 capability_id; +} tAVRC_GET_CAPS_CMD; + +/* ListPlayerAppValues */ +typedef struct { + UINT8 pdu; + tAVRC_STS status; + UINT8 opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ + UINT8 attr_id; +} tAVRC_LIST_APP_VALUES_CMD; + +/* GetCurAppValue */ +typedef struct { + UINT8 pdu; + tAVRC_STS status; + UINT8 opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ + UINT8 num_attr; + UINT8 attrs[AVRC_MAX_APP_ATTR_SIZE]; +} tAVRC_GET_CUR_APP_VALUE_CMD; + +/* SetAppValue */ +typedef struct { + UINT8 pdu; + tAVRC_STS status; + UINT8 opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ + UINT8 num_val; + tAVRC_APP_SETTING *p_vals; +} tAVRC_SET_APP_VALUE_CMD; + +/* GetAppAttrTxt */ +typedef struct { + UINT8 pdu; + tAVRC_STS status; + UINT8 opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ + UINT8 num_attr; + UINT8 attrs[AVRC_MAX_APP_ATTR_SIZE]; +} tAVRC_GET_APP_ATTR_TXT_CMD; + +/* GetAppValueTxt */ +typedef struct { + UINT8 pdu; + tAVRC_STS status; + UINT8 opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ + UINT8 attr_id; + UINT8 num_val; + UINT8 vals[AVRC_MAX_APP_ATTR_SIZE]; +} tAVRC_GET_APP_VAL_TXT_CMD; + +/* InformCharset */ +typedef struct { + UINT8 pdu; + tAVRC_STS status; + UINT8 opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ + UINT8 num_id; + UINT16 charsets[AVRC_MAX_CHARSET_SIZE]; +} tAVRC_INFORM_CHARSET_CMD; + +/* InformBatteryStatus */ +typedef struct { + UINT8 pdu; + tAVRC_STS status; + UINT8 opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ + UINT8 battery_status; +} tAVRC_BATTERY_STATUS_CMD; + +/* GetElemAttrs */ +typedef struct { + UINT8 pdu; + tAVRC_STS status; + UINT8 opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ + UINT8 num_attr; + UINT32 attrs[AVRC_MAX_ELEM_ATTR_SIZE]; +} tAVRC_GET_ELEM_ATTRS_CMD; + +/* RegNotify */ +typedef struct { + UINT8 pdu; + tAVRC_STS status; + UINT8 opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ + UINT8 event_id; + UINT32 param; +} tAVRC_REG_NOTIF_CMD; + +/* SetAddrPlayer */ +typedef struct { + UINT8 pdu; + tAVRC_STS status; + UINT8 opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ + UINT16 player_id; +} tAVRC_SET_ADDR_PLAYER_CMD; + +/* SetBrowsedPlayer */ +typedef struct { + UINT8 pdu; + tAVRC_STS status; + UINT8 opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ + UINT16 player_id; +} tAVRC_SET_BR_PLAYER_CMD; + +/* SetAbsVolume */ +typedef struct { + UINT8 pdu; + tAVRC_STS status; + UINT8 opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ + UINT8 volume; +} tAVRC_SET_VOLUME_CMD; + +/* GetFolderItems */ +typedef struct { + UINT8 pdu; + tAVRC_STS status; + UINT8 opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ + UINT8 scope; + UINT32 start_item; + UINT32 end_item; + UINT8 attr_count; + UINT32 *p_attr_list; +} tAVRC_GET_ITEMS_CMD; + +/* ChangePath */ +typedef struct { + UINT8 pdu; + tAVRC_STS status; + UINT8 opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ + UINT16 uid_counter; + UINT8 direction; + tAVRC_UID folder_uid; +} tAVRC_CHG_PATH_CMD; + +/* GetItemAttrs */ +typedef struct { + UINT8 pdu; + tAVRC_STS status; + UINT8 opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ + UINT8 scope; + tAVRC_UID uid; + UINT16 uid_counter; + UINT8 attr_count; + UINT32 *p_attr_list; +} tAVRC_GET_ATTRS_CMD; + +/* Search */ +typedef struct { + UINT8 pdu; + tAVRC_STS status; + UINT8 opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ + tAVRC_FULL_NAME string; +} tAVRC_SEARCH_CMD; + +/* PlayItem */ +typedef struct { + UINT8 pdu; + tAVRC_STS status; + UINT8 opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ + UINT8 scope; + tAVRC_UID uid; + UINT16 uid_counter; +} tAVRC_PLAY_ITEM_CMD; + +/* AddToNowPlaying */ +typedef struct { + UINT8 pdu; + tAVRC_STS status; + UINT8 opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ + UINT8 scope; + tAVRC_UID uid; + UINT16 uid_counter; +} tAVRC_ADD_TO_PLAY_CMD; + +typedef struct { + UINT8 pdu; + tAVRC_STS status; + UINT8 opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ +} tAVRC_CMD; + +/* Continue and Abort */ +typedef struct { + UINT8 pdu; + tAVRC_STS status; + UINT8 opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ + UINT8 target_pdu; +} tAVRC_NEXT_CMD; + +typedef union { + UINT8 pdu; + tAVRC_CMD cmd; + tAVRC_GET_CAPS_CMD get_caps; /* GetCapability */ + tAVRC_CMD list_app_attr; /* ListPlayerAppAttr */ + tAVRC_LIST_APP_VALUES_CMD list_app_values; /* ListPlayerAppValues */ + tAVRC_GET_CUR_APP_VALUE_CMD get_cur_app_val; /* GetCurAppValue */ + tAVRC_SET_APP_VALUE_CMD set_app_val; /* SetAppValue */ + tAVRC_GET_APP_ATTR_TXT_CMD get_app_attr_txt; /* GetAppAttrTxt */ + tAVRC_GET_APP_VAL_TXT_CMD get_app_val_txt; /* GetAppValueTxt */ + tAVRC_INFORM_CHARSET_CMD inform_charset; /* InformCharset */ + tAVRC_BATTERY_STATUS_CMD inform_battery_status; /* InformBatteryStatus */ + tAVRC_GET_ELEM_ATTRS_CMD get_elem_attrs; /* GetElemAttrs */ + tAVRC_CMD get_play_status; /* GetPlayStatus */ + tAVRC_REG_NOTIF_CMD reg_notif; /* RegNotify */ + tAVRC_NEXT_CMD continu; /* Continue */ + tAVRC_NEXT_CMD abort; /* Abort */ + + tAVRC_SET_ADDR_PLAYER_CMD addr_player; /* SetAddrPlayer */ + tAVRC_SET_VOLUME_CMD volume; /* SetAbsVolume */ + tAVRC_SET_BR_PLAYER_CMD br_player; /* SetBrowsedPlayer */ + tAVRC_GET_ITEMS_CMD get_items; /* GetFolderItems */ + tAVRC_CHG_PATH_CMD chg_path; /* ChangePath */ + tAVRC_GET_ATTRS_CMD get_attrs; /* GetItemAttrs */ + tAVRC_SEARCH_CMD search; /* Search */ + tAVRC_PLAY_ITEM_CMD play_item; /* PlayItem */ + tAVRC_ADD_TO_PLAY_CMD add_to_play; /* AddToNowPlaying */ +} tAVRC_COMMAND; + +/* GetCapability */ +typedef struct { + UINT8 pdu; + tAVRC_STS status; + UINT8 opcode; /* Op Code (copied from avrc_cmd.opcode by AVRC_BldResponse user. invalid one to generate according to pdu) */ + UINT8 capability_id; + UINT8 count; + tAVRC_CAPS_PARAM param; +} tAVRC_GET_CAPS_RSP; + +/* ListPlayerAppAttr */ +typedef struct { + UINT8 pdu; + tAVRC_STS status; + UINT8 opcode; /* Op Code (copied from avrc_cmd.opcode by AVRC_BldResponse user. invalid one to generate according to pdu) */ + UINT8 num_attr; + UINT8 attrs[AVRC_MAX_APP_ATTR_SIZE]; +} tAVRC_LIST_APP_ATTR_RSP; + +/* ListPlayerAppValues */ +typedef struct { + UINT8 pdu; + tAVRC_STS status; + UINT8 opcode; /* Op Code (copied from avrc_cmd.opcode by AVRC_BldResponse user. invalid one to generate according to pdu) */ + UINT8 num_val; + UINT8 vals[AVRC_MAX_APP_ATTR_SIZE]; +} tAVRC_LIST_APP_VALUES_RSP; + +/* GetCurAppValue */ +typedef struct { + UINT8 pdu; + tAVRC_STS status; + UINT8 opcode; /* Op Code (copied from avrc_cmd.opcode by AVRC_BldResponse user. invalid one to generate according to pdu) */ + UINT8 num_val; + tAVRC_APP_SETTING *p_vals; +} tAVRC_GET_CUR_APP_VALUE_RSP; + +/* GetAppAttrTxt */ +typedef struct { + UINT8 pdu; + tAVRC_STS status; + UINT8 opcode; /* Op Code (copied from avrc_cmd.opcode by AVRC_BldResponse user. invalid one to generate according to pdu) */ + UINT8 num_attr; + tAVRC_APP_SETTING_TEXT *p_attrs; +} tAVRC_GET_APP_ATTR_TXT_RSP; + +/* GetElemAttrs */ +typedef struct { + UINT8 pdu; + tAVRC_STS status; + UINT8 opcode; /* Op Code (copied from avrc_cmd.opcode by AVRC_BldResponse user. invalid one to generate according to pdu) */ + UINT8 num_attr; + tAVRC_ATTR_ENTRY *p_attrs; +} tAVRC_GET_ELEM_ATTRS_RSP; + +/* GetPlayStatus */ +typedef struct { + UINT8 pdu; + tAVRC_STS status; + UINT8 opcode; /* Op Code (copied from avrc_cmd.opcode by AVRC_BldResponse user. invalid one to generate according to pdu) */ + UINT32 song_len; + UINT32 song_pos; + UINT8 play_status; +} tAVRC_GET_PLAY_STATUS_RSP; + +/* notification event parameter for AddressedPlayer change */ +typedef struct { + UINT16 player_id; + UINT16 uid_counter; +} tAVRC_ADDR_PLAYER_PARAM; + +#ifndef AVRC_MAX_APP_SETTINGS +#define AVRC_MAX_APP_SETTINGS 8 +#endif + +/* notification event parameter for Player Application setting change */ +typedef struct { + UINT8 num_attr; + UINT8 attr_id[AVRC_MAX_APP_SETTINGS]; + UINT8 attr_value[AVRC_MAX_APP_SETTINGS]; +} tAVRC_PLAYER_APP_PARAM; + +typedef union { + tAVRC_PLAYSTATE play_status; + tAVRC_UID track; + UINT32 play_pos; + tAVRC_BATTERY_STATUS battery_status; + tAVRC_SYSTEMSTATE system_status; + tAVRC_PLAYER_APP_PARAM player_setting; + tAVRC_ADDR_PLAYER_PARAM addr_player; + UINT16 uid_counter; + UINT8 volume; +} tAVRC_NOTIF_RSP_PARAM; + +/* RegNotify */ +typedef struct { + UINT8 pdu; + tAVRC_STS status; + UINT8 opcode; /* Op Code (copied from avrc_cmd.opcode by AVRC_BldResponse user. invalid one to generate according to pdu) */ + UINT8 event_id; + tAVRC_NOTIF_RSP_PARAM param; +} tAVRC_REG_NOTIF_RSP; + +/* SetAbsVolume */ +typedef struct { + UINT8 pdu; + tAVRC_STS status; + UINT8 opcode; /* Op Code (copied from avrc_cmd.opcode by AVRC_BldResponse user. invalid one to generate according to pdu) */ + UINT8 volume; +} tAVRC_SET_VOLUME_RSP; + +/* SetBrowsedPlayer */ +typedef struct { + UINT8 pdu; + tAVRC_STS status; + UINT8 opcode; /* Op Code (copied from avrc_cmd.opcode by AVRC_BldResponse user. invalid one to generate according to pdu) */ + UINT16 uid_counter; + UINT32 num_items; + UINT16 charset_id; + UINT8 folder_depth; + tAVRC_NAME *p_folders; +} tAVRC_SET_BR_PLAYER_RSP; + +/* GetFolderItems */ +typedef struct { + UINT8 pdu; + tAVRC_STS status; + UINT8 opcode; /* Op Code (copied from avrc_cmd.opcode by AVRC_BldResponse user. invalid one to generate according to pdu) */ + UINT16 uid_counter; + UINT16 item_count; + tAVRC_ITEM *p_item_list; +} tAVRC_GET_ITEMS_RSP; + +/* ChangePath */ +typedef struct { + UINT8 pdu; + tAVRC_STS status; + UINT8 opcode; /* Op Code (copied from avrc_cmd.opcode by AVRC_BldResponse user. invalid one to generate according to pdu) */ + UINT32 num_items; +} tAVRC_CHG_PATH_RSP; + +/* GetItemAttrs */ +typedef struct { + UINT8 pdu; + tAVRC_STS status; + UINT8 opcode; /* Op Code (copied from avrc_cmd.opcode by AVRC_BldResponse user. invalid one to generate according to pdu) */ + UINT8 attr_count; + tAVRC_ATTR_ENTRY *p_attr_list; +} tAVRC_GET_ATTRS_RSP; + +/* Search */ +typedef struct { + UINT8 pdu; + tAVRC_STS status; + UINT8 opcode; /* Op Code (copied from avrc_cmd.opcode by AVRC_BldResponse user. invalid one to generate according to pdu) */ + UINT16 uid_counter; + UINT32 num_items; +} tAVRC_SEARCH_RSP; + + +typedef struct { + UINT8 pdu; + tAVRC_STS status; + UINT8 opcode; /* Op Code (copied from avrc_cmd.opcode by AVRC_BldResponse user. invalid one to generate according to pdu) */ +} tAVRC_RSP; + +typedef union { + UINT8 pdu; + tAVRC_RSP rsp; + tAVRC_GET_CAPS_RSP get_caps; /* GetCapability */ + tAVRC_LIST_APP_ATTR_RSP list_app_attr; /* ListPlayerAppAttr */ + tAVRC_LIST_APP_VALUES_RSP list_app_values; /* ListPlayerAppValues */ + tAVRC_GET_CUR_APP_VALUE_RSP get_cur_app_val; /* GetCurAppValue */ + tAVRC_RSP set_app_val; /* SetAppValue */ + tAVRC_GET_APP_ATTR_TXT_RSP get_app_attr_txt; /* GetAppAttrTxt */ + tAVRC_GET_APP_ATTR_TXT_RSP get_app_val_txt; /* GetAppValueTxt */ + tAVRC_RSP inform_charset; /* InformCharset */ + tAVRC_RSP inform_battery_status; /* InformBatteryStatus */ + tAVRC_GET_ELEM_ATTRS_RSP get_elem_attrs; /* GetElemAttrs */ + tAVRC_GET_PLAY_STATUS_RSP get_play_status; /* GetPlayStatus */ + tAVRC_REG_NOTIF_RSP reg_notif; /* RegNotify */ + tAVRC_RSP continu; /* Continue */ + tAVRC_RSP abort; /* Abort */ + + tAVRC_RSP addr_player; /* SetAddrPlayer */ + tAVRC_SET_VOLUME_RSP volume; /* SetAbsVolume */ + tAVRC_SET_BR_PLAYER_RSP br_player; /* SetBrowsedPlayer */ + tAVRC_GET_ITEMS_RSP get_items; /* GetFolderItems */ + tAVRC_CHG_PATH_RSP chg_path; /* ChangePath */ + tAVRC_GET_ATTRS_RSP get_attrs; /* GetItemAttrs */ + tAVRC_SEARCH_RSP search; /* Search */ + tAVRC_RSP play_item; /* PlayItem */ + tAVRC_RSP add_to_play; /* AddToNowPlaying */ +} tAVRC_RESPONSE; + + +#endif diff --git a/tools/sdk/include/bluedroid/bdaddr.h b/tools/sdk/include/bluedroid/bdaddr.h new file mode 100755 index 00000000..87acad2e --- /dev/null +++ b/tools/sdk/include/bluedroid/bdaddr.h @@ -0,0 +1,63 @@ +/****************************************************************************** + * + * 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 +#include + +#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 diff --git a/tools/sdk/include/bluedroid/blufi_int.h b/tools/sdk/include/bluedroid/blufi_int.h new file mode 100644 index 00000000..c21b41c4 --- /dev/null +++ b/tools/sdk/include/bluedroid/blufi_int.h @@ -0,0 +1,176 @@ +// 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)< +#include +#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_ */ diff --git a/tools/sdk/include/bluedroid/bt_sdp.h b/tools/sdk/include/bluedroid/bt_sdp.h new file mode 100755 index 00000000..da7f7744 --- /dev/null +++ b/tools/sdk/include/bluedroid/bt_sdp.h @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * 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_SDP_H__ +#define __BT_SDP_H__ + +#include +// #include "bluetooth.h" +#include "bt_defs.h" + +#define SDP_OPP_SUPPORTED_FORMATS_MAX_LENGTH 15 + +/** + * These events are handled by the state machine + */ +typedef enum { + SDP_TYPE_RAW, // Used to carry raw SDP search data for unknown UUIDs + SDP_TYPE_MAP_MAS, // Message Access Profile - Server + SDP_TYPE_MAP_MNS, // Message Access Profile - Client (Notification Server) + SDP_TYPE_PBAP_PSE, // Phone Book Profile - Server + SDP_TYPE_PBAP_PCE, // Phone Book Profile - Client + SDP_TYPE_OPP_SERVER, // Object Push Profile + SDP_TYPE_SAP_SERVER // SIM Access Profile +} bluetooth_sdp_types; + +typedef struct _bluetooth_sdp_hdr { + bluetooth_sdp_types type; + bt_uuid_t uuid; + uint32_t service_name_length; + char *service_name; + int32_t rfcomm_channel_number; + int32_t l2cap_psm; + int32_t profile_version; +} bluetooth_sdp_hdr; + +/** + * Some signals need additional pointers, hence we introduce a + * generic way to handle these pointers. + */ +typedef struct _bluetooth_sdp_hdr_overlay { + bluetooth_sdp_types type; + bt_uuid_t uuid; + uint32_t service_name_length; + char *service_name; + int32_t rfcomm_channel_number; + int32_t l2cap_psm; + int32_t profile_version; + + // User pointers, only used for some signals - see bluetooth_sdp_ops_record + int user1_ptr_len; + uint8_t *user1_ptr; + int user2_ptr_len; + uint8_t *user2_ptr; +} bluetooth_sdp_hdr_overlay; + +typedef struct _bluetooth_sdp_mas_record { + bluetooth_sdp_hdr_overlay hdr; + uint32_t mas_instance_id; + uint32_t supported_features; + uint32_t supported_message_types; +} bluetooth_sdp_mas_record; + +typedef struct _bluetooth_sdp_mns_record { + bluetooth_sdp_hdr_overlay hdr; + uint32_t supported_features; +} bluetooth_sdp_mns_record; + +typedef struct _bluetooth_sdp_pse_record { + bluetooth_sdp_hdr_overlay hdr; + uint32_t supported_features; + uint32_t supported_repositories; +} bluetooth_sdp_pse_record; + +typedef struct _bluetooth_sdp_pce_record { + bluetooth_sdp_hdr_overlay hdr; +} bluetooth_sdp_pce_record; + +typedef struct _bluetooth_sdp_ops_record { + bluetooth_sdp_hdr_overlay hdr; + int supported_formats_list_len; + uint8_t supported_formats_list[SDP_OPP_SUPPORTED_FORMATS_MAX_LENGTH]; +} bluetooth_sdp_ops_record; + +typedef struct _bluetooth_sdp_sap_record { + bluetooth_sdp_hdr_overlay hdr; +} bluetooth_sdp_sap_record; + +typedef union { + bluetooth_sdp_hdr_overlay hdr; + bluetooth_sdp_mas_record mas; + bluetooth_sdp_mns_record mns; + bluetooth_sdp_pse_record pse; + bluetooth_sdp_pce_record pce; + bluetooth_sdp_ops_record ops; + bluetooth_sdp_sap_record sap; +} bluetooth_sdp_record; + +#endif /* __BT_SDP_H__ */ diff --git a/tools/sdk/include/bluedroid/bt_target.h b/tools/sdk/include/bluedroid/bt_target.h new file mode 100644 index 00000000..9d042a2b --- /dev/null +++ b/tools/sdk/include/bluedroid/bt_target.h @@ -0,0 +1,1801 @@ +/****************************************************************************** + * + * Copyright (c) 2014 The Android Open Source Project + * Copyright (C) 1999-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. + * + ******************************************************************************/ + +#ifndef BT_TARGET_H +#define BT_TARGET_H + +#ifndef BUILDCFG +#define BUILDCFG +#endif + +/* +#if !defined(HAS_BDROID_BUILDCFG) && !defined(HAS_NO_BDROID_BUILDCFG) +#error "An Android.mk file did not include bdroid_CFLAGS and possibly not bdorid_C_INCLUDES" +#endif +*/ + +#ifdef HAS_BDROID_BUILDCFG +#include "bdroid_buildcfg.h" +#endif + +#include "bt_types.h" /* This must be defined AFTER buildcfg.h */ + +/* Include common GKI definitions used by this platform */ +#include "gki_target.h" +#include "dyn_mem.h" /* defines static and/or dynamic memory for components */ + + +#ifndef CLASSIC_BT_INCLUDED +#define CLASSIC_BT_INCLUDED TRUE +#endif ///CLASSIC_BT_INCLUDED + +//------------------Added from bdroid_buildcfg.h--------------------- +#ifndef L2CAP_EXTFEA_SUPPORTED_MASK +#define L2CAP_EXTFEA_SUPPORTED_MASK (L2CAP_EXTFEA_ENH_RETRANS | L2CAP_EXTFEA_STREAM_MODE | L2CAP_EXTFEA_NO_CRC | L2CAP_EXTFEA_FIXED_CHNLS) +#endif + +#ifndef BTUI_OPS_FORMATS +#define BTUI_OPS_FORMATS (BTA_OP_VCARD21_MASK | BTA_OP_ANY_MASK) +#endif + +#ifndef BTA_RFC_MTU_SIZE +#define BTA_RFC_MTU_SIZE (L2CAP_MTU_SIZE-L2CAP_MIN_OFFSET-RFCOMM_DATA_OVERHEAD) +#endif + +#ifndef SBC_NO_PCM_CPY_OPTION +#define SBC_NO_PCM_CPY_OPTION FALSE +#endif + +#ifndef BT_APP_DEMO +#define BT_APP_DEMO TRUE +#endif + +#ifndef BTIF_INCLUDED +#define BTIF_INCLUDED FALSE +#endif + +#ifndef BTA_INCLUDED +#define BTA_INCLUDED TRUE +#endif + +#ifndef BTA_PAN_INCLUDED +#define BTA_PAN_INCLUDED FALSE//TRUE +#endif + +#ifndef BTA_HH_INCLUDED +#define BTA_HH_INCLUDED FALSE//TRUE +#endif + +#ifndef BTA_HH_ROLE +#define BTA_HH_ROLE BTA_MASTER_ROLE_PREF +#endif + +#ifndef BTA_HH_LE_INCLUDED +#define BTA_HH_LE_INCLUDED FALSE//TRUE +#endif + +#ifndef BTA_AR_INCLUDED +#define BTA_AR_INCLUDED FALSE//TRUE +#endif + +#ifndef BTA_AV_INCLUDED +#define BTA_AV_INCLUDED FALSE//TRUE +#endif + +#ifndef BTA_AV_SINK_INCLUDED +#define BTA_AV_SINK_INCLUDED FALSE//FALSE +#endif + +#ifndef BTA_DISABLE_DELAY +#define BTA_DISABLE_DELAY 200 /* in milliseconds */ +#endif + +// If the next wakeup time is less than this threshold, we should acquire +// a wakelock instead of setting a wake alarm so we're not bouncing in +// and out of suspend frequently. +// in millisecond +// TODO(zachoverflow): reinstate in alarm code +#ifndef GKI_TIMER_INTERVAL_FOR_WAKELOCK +#define GKI_TIMER_INTERVAL_FOR_WAKELOCK 3000 +#endif + +#ifndef BTA_SYS_TIMER_PERIOD +#define BTA_SYS_TIMER_PERIOD 100 +#endif + +#ifndef SBC_FOR_EMBEDDED_LINUX +#define SBC_FOR_EMBEDDED_LINUX TRUE +#endif + +#ifndef AVDT_VERSION +#define AVDT_VERSION 0x0102 +#endif + +#ifndef BTA_AG_AT_MAX_LEN +#define BTA_AG_AT_MAX_LEN 512 +#endif + +#ifndef BTA_AVRCP_FF_RW_SUPPORT +#define BTA_AVRCP_FF_RW_SUPPORT FALSE//TRUE +#endif + +#ifndef BTA_AG_SCO_PKT_TYPES +#define BTA_AG_SCO_PKT_TYPES (BTM_SCO_LINK_ONLY_MASK | BTM_SCO_PKT_TYPES_MASK_EV3 | BTM_SCO_PKT_TYPES_MASK_NO_3_EV3 | BTM_SCO_PKT_TYPES_MASK_NO_2_EV5 | BTM_SCO_PKT_TYPES_MASK_NO_3_EV5) +#endif + +#ifndef BTA_AV_RET_TOUT +#define BTA_AV_RET_TOUT 15 +#endif + +#ifndef PORCHE_PAIRING_CONFLICT +#define PORCHE_PAIRING_CONFLICT TRUE +#endif + +#ifndef BTA_AV_CO_CP_SCMS_T +#define BTA_AV_CO_CP_SCMS_T FALSE//FALSE +#endif + +/* This feature is used to eanble interleaved scan*/ +#ifndef BTA_HOST_INTERLEAVE_SEARCH +#define BTA_HOST_INTERLEAVE_SEARCH FALSE//FALSE +#endif + +#ifndef BT_USE_TRACES +#define BT_USE_TRACES TRUE +#endif + +#ifndef BT_TRACE_BTIF +#define BT_TRACE_BTIF TRUE +#endif + +#ifndef BT_TRACE_VERBOSE +#define BT_TRACE_VERBOSE FALSE +#endif + +#ifndef BTA_DM_SDP_DB_SIZE +#define BTA_DM_SDP_DB_SIZE 8000 +#endif + +#ifndef HL_INCLUDED +#define HL_INCLUDED TRUE +#endif + +#ifndef AG_VOICE_SETTINGS +#define AG_VOICE_SETTINGS HCI_DEFAULT_VOICE_SETTINGS +#endif + +#ifndef BTIF_DM_OOB_TEST +#define BTIF_DM_OOB_TEST FALSE//TRUE +#endif + +// How long to wait before activating sniff mode after entering the +// idle state for FTS, OPS connections +#ifndef BTA_FTS_OPS_IDLE_TO_SNIFF_DELAY_MS +#define BTA_FTS_OPS_IDLE_TO_SNIFF_DELAY_MS 7000 +#endif + +//------------------End added from bdroid_buildcfg.h--------------------- + + +/****************************************************************************** +** +** GKI Buffer Pools +** +******************************************************************************/ + +/* Receives HCI events from the lower-layer. */ +#ifndef HCI_CMD_POOL_ID +#define HCI_CMD_POOL_ID GKI_POOL_ID_2 +#endif + +#ifndef HCI_CMD_POOL_BUF_SIZE +#define HCI_CMD_POOL_BUF_SIZE GKI_BUF2_SIZE +#endif + +/* Receives ACL data packets from thelower-layer. */ +#ifndef HCI_ACL_POOL_ID +#define HCI_ACL_POOL_ID GKI_POOL_ID_3 +#endif + +/* Maximum number of buffers available for ACL receive data. */ +#ifndef HCI_ACL_BUF_MAX +#define HCI_ACL_BUF_MAX GKI_BUF3_MAX +#endif + +/* Receives SCO data packets from the lower-layer. */ +#ifndef HCI_SCO_POOL_ID +#define HCI_SCO_POOL_ID GKI_POOL_ID_6 +#endif + +/* Sends SDP data packets. */ +#ifndef SDP_POOL_ID +#define SDP_POOL_ID 3 +#endif + +/* Sends RFCOMM command packets. */ +#ifndef RFCOMM_CMD_POOL_ID +#define RFCOMM_CMD_POOL_ID GKI_POOL_ID_2 +#endif + +/* Sends RFCOMM data packets. */ +#ifndef RFCOMM_DATA_POOL_ID +#define RFCOMM_DATA_POOL_ID GKI_POOL_ID_3 +#endif + +#ifndef RFCOMM_DATA_POOL_BUF_SIZE +#define RFCOMM_DATA_POOL_BUF_SIZE GKI_BUF3_SIZE +#endif + +/* Sends L2CAP packets to the peer and HCI messages to the controller. */ +#ifndef L2CAP_CMD_POOL_ID +#define L2CAP_CMD_POOL_ID GKI_POOL_ID_2 +#endif + +/* Sends L2CAP segmented packets in ERTM mode */ +#ifndef L2CAP_FCR_TX_POOL_ID +#define L2CAP_FCR_TX_POOL_ID HCI_ACL_POOL_ID +#endif + +/* Receives L2CAP segmented packets in ERTM mode */ +#ifndef L2CAP_FCR_RX_POOL_ID +#define L2CAP_FCR_RX_POOL_ID HCI_ACL_POOL_ID +#endif + +/* Number of ACL buffers to assign to LE + if the HCI buffer pool is shared with BR/EDR */ +#ifndef L2C_DEF_NUM_BLE_BUF_SHARED +#define L2C_DEF_NUM_BLE_BUF_SHARED 1 +#endif + +/* Used by BTM when it sends HCI commands to the controller. */ +#ifndef BTM_CMD_POOL_ID +#define BTM_CMD_POOL_ID GKI_POOL_ID_2 +#endif + +#ifndef OBX_LRG_DATA_POOL_SIZE +#define OBX_LRG_DATA_POOL_SIZE GKI_BUF4_SIZE +#endif + +#ifndef OBX_LRG_DATA_POOL_ID +#define OBX_LRG_DATA_POOL_ID GKI_POOL_ID_4 +#endif +/* Used to send data to L2CAP. */ +#ifndef GAP_DATA_POOL_ID +#define GAP_DATA_POOL_ID GKI_POOL_ID_3 +#endif + +#ifndef SPP_DB_SIZE +#define SPP_DB_SIZE GKI_BUF3_SIZE +#endif + +/* BNEP data and protocol messages. */ +#ifndef BNEP_POOL_ID +#define BNEP_POOL_ID GKI_POOL_ID_3 +#endif + +/* RPC pool for temporary trace message buffers. */ +#ifndef RPC_SCRATCH_POOL_ID +#define RPC_SCRATCH_POOL_ID GKI_POOL_ID_2 +#endif + +/* AVDTP pool for protocol messages */ +#ifndef AVDT_CMD_POOL_ID +#define AVDT_CMD_POOL_ID GKI_POOL_ID_2 +#endif + +/* AVDTP pool size for media packets in case of fragmentation */ +#ifndef AVDT_DATA_POOL_SIZE +#define AVDT_DATA_POOL_SIZE GKI_BUF3_SIZE +#endif + +#ifndef PAN_POOL_ID +#define PAN_POOL_ID GKI_POOL_ID_3 +/* Maximum amount of the shared buffer to allocate for PAN */ +#define PAN_POOL_MAX (GKI_BUF3_MAX / 4) +#endif + +/* AVCTP pool for protocol messages */ +#ifndef AVCT_CMD_POOL_ID +#define AVCT_CMD_POOL_ID GKI_POOL_ID_1 +#endif + +/* AVRCP pool for protocol messages */ +#ifndef AVRC_CMD_POOL_ID +#define AVRC_CMD_POOL_ID GKI_POOL_ID_1 +#endif + +/* AVRCP pool size for protocol messages */ +#ifndef AVRC_CMD_POOL_SIZE +#define AVRC_CMD_POOL_SIZE GKI_BUF1_SIZE +#endif + +/* AVRCP Metadata pool for protocol messages */ +#ifndef AVRC_META_CMD_POOL_ID +#define AVRC_META_CMD_POOL_ID GKI_POOL_ID_2 +#endif + +/* AVRCP Metadata pool size for protocol messages */ +#ifndef AVRC_META_CMD_POOL_SIZE +#define AVRC_META_CMD_POOL_SIZE GKI_BUF2_SIZE +#endif + + +/* AVRCP buffer size for browsing channel messages */ +#ifndef AVRC_BROWSE_POOL_SIZE +#define AVRC_BROWSE_POOL_SIZE GKI_MAX_BUF_SIZE +#endif + +#ifndef BTA_HL_LRG_DATA_POOL_ID +#define BTA_HL_LRG_DATA_POOL_ID GKI_POOL_ID_7 +#endif + +/* GATT Server Database pool ID */ +#ifndef GATT_DB_POOL_ID +#define GATT_DB_POOL_ID GKI_POOL_ID_8 +#endif + +/* GATT Data sending buffer pool ID, use default ACL pool for fix channel data */ +#ifndef GATT_BUF_POOL_ID +#define GATT_BUF_POOL_ID HCI_ACL_POOL_ID +#endif + +/****************************************************************************** +** +** Lower Layer Interface +** +******************************************************************************/ + +/* Macro for allocating buffer for HCI commands */ +#ifndef HCI_GET_CMD_BUF +#if (!defined(HCI_USE_VARIABLE_SIZE_CMD_BUF) || (HCI_USE_VARIABLE_SIZE_CMD_BUF == FALSE)) +/* Allocate fixed-size buffer from HCI_CMD_POOL (default case) */ +#define HCI_GET_CMD_BUF(paramlen) ((BT_HDR *)GKI_getpoolbuf (HCI_CMD_POOL_ID)) +#else +/* Allocate smallest possible buffer (for platforms with limited RAM) */ +#define HCI_GET_CMD_BUF(paramlen) ((BT_HDR *)GKI_getbuf ((UINT16)(BT_HDR_SIZE + HCIC_PREAMBLE_SIZE + (paramlen)))) +#endif +#endif /* HCI_GET_CMD_BUF */ + +/****************************************************************************** +** +** HCI Services (H4) +** +******************************************************************************/ + +/* Use 2 second for low-resolution systems, override to 1 for high-resolution systems */ +#ifndef BT_1SEC_TIMEOUT +#define BT_1SEC_TIMEOUT (2) +#endif + +/* Quick Timer */ +/* if L2CAP_FCR_INCLUDED is TRUE then it should have 100 millisecond resolution */ +/* if none of them is included then QUICK_TIMER_TICKS_PER_SEC is set to 0 to exclude quick timer */ +#ifndef QUICK_TIMER_TICKS_PER_SEC +#define QUICK_TIMER_TICKS_PER_SEC 10 /* 100ms timer */ +#endif + +/****************************************************************************** +** +** BTM +** +******************************************************************************/ + +/* Cancel Inquiry on incoming SSP */ +#ifndef BTM_NO_SSP_ON_INQUIRY +#define BTM_NO_SSP_ON_INQUIRY FALSE +#endif + +/* Includes SCO if TRUE */ +#ifndef BTM_SCO_INCLUDED +#define BTM_SCO_INCLUDED FALSE //TRUE /* TRUE includes SCO code */ +#endif + +/* Includes SCO if TRUE */ +#ifndef BTM_SCO_HCI_INCLUDED +#define BTM_SCO_HCI_INCLUDED FALSE /* TRUE includes SCO over HCI code */ +#endif + +/* Includes WBS if TRUE */ +#ifndef BTM_WBS_INCLUDED +#define BTM_WBS_INCLUDED FALSE /* TRUE includes WBS code */ +#endif + +/* This is used to work around a controller bug that doesn't like Disconnect +** issued while there is a role switch in progress +*/ +#ifndef BTM_DISC_DURING_RS +#define BTM_DISC_DURING_RS TRUE +#endif + +/************************** +** Initial SCO TX credit +*************************/ +/* max TX SCO data packet size */ +#ifndef BTM_SCO_DATA_SIZE_MAX +#define BTM_SCO_DATA_SIZE_MAX 240 +#endif + +/* The size in bytes of the BTM inquiry database. 40 As Default */ +#ifndef BTM_INQ_DB_SIZE +#define BTM_INQ_DB_SIZE 32 +#endif + +/* The default scan mode */ +#ifndef BTM_DEFAULT_SCAN_TYPE +#define BTM_DEFAULT_SCAN_TYPE BTM_SCAN_TYPE_INTERLACED +#endif + +/* Should connections to unknown devices be allowed when not discoverable? */ +#ifndef BTM_ALLOW_CONN_IF_NONDISCOVER +#define BTM_ALLOW_CONN_IF_NONDISCOVER TRUE +#endif + +/* Sets the Page_Scan_Window: the length of time that the device is performing a page scan. */ +#ifndef BTM_DEFAULT_CONN_WINDOW +#define BTM_DEFAULT_CONN_WINDOW 0x0012 +#endif + +/* Sets the Page_Scan_Activity: the interval between the start of two consecutive page scans. */ +#ifndef BTM_DEFAULT_CONN_INTERVAL +#define BTM_DEFAULT_CONN_INTERVAL 0x0800 +#endif + +/* When automatic inquiry scan is enabled, this sets the inquiry scan window. */ +#ifndef BTM_DEFAULT_DISC_WINDOW +#define BTM_DEFAULT_DISC_WINDOW 0x0012 +#endif + +/* When automatic inquiry scan is enabled, this sets the inquiry scan interval. */ +#ifndef BTM_DEFAULT_DISC_INTERVAL +#define BTM_DEFAULT_DISC_INTERVAL 0x0800 +#endif + +/* Default class of device +* {SERVICE_CLASS, MAJOR_CLASS, MINOR_CLASS} +* +* SERVICE_CLASS:0x5A (Bit17 -Networking,Bit19 - Capturing,Bit20 -Object Transfer,Bit22 -Telephony) +* MAJOR_CLASS:0x02 - PHONE +* MINOR_CLASS:0x0C - SMART_PHONE +* +*/ +#ifndef BTA_DM_COD +#define BTA_DM_COD {0x5A, 0x02, 0x0C} +#endif + +/* The number of SCO links. */ +#ifndef BTM_MAX_SCO_LINKS +#define BTM_MAX_SCO_LINKS 1 //3 +#endif + +/* The preferred type of SCO links (2-eSCO, 0-SCO). */ +#ifndef BTM_DEFAULT_SCO_MODE +#define BTM_DEFAULT_SCO_MODE 2 +#endif + +/* 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 +#endif + +/* The number of security records for services. 32 AS Default*/ +#ifndef BTM_SEC_MAX_SERVICE_RECORDS +#define BTM_SEC_MAX_SERVICE_RECORDS 8 // 32 +#endif + +/* If True, force a retrieval of remote device name for each bond in case it's changed */ +#ifndef BTM_SEC_FORCE_RNR_FOR_DBOND +#define BTM_SEC_FORCE_RNR_FOR_DBOND FALSE +#endif + +/* Maximum device name length used in btm database. Up to 248*/ +#ifndef BTM_MAX_REM_BD_NAME_LEN +#define BTM_MAX_REM_BD_NAME_LEN 64 +#endif + +/* Maximum local device name length stored btm database. + '0' disables storage of the local name in BTM */ +#ifndef BTM_MAX_LOC_BD_NAME_LEN +#define BTM_MAX_LOC_BD_NAME_LEN 64 +#endif + +/* Fixed Default String. When this is defined as null string, the device's + * product model name is used as the default local name. + */ +#ifndef BTM_DEF_LOCAL_NAME +#define BTM_DEF_LOCAL_NAME "" +#endif + +/* Maximum service name stored with security authorization (0 if not needed) */ +#ifndef BTM_SEC_SERVICE_NAME_LEN +#define BTM_SEC_SERVICE_NAME_LEN BT_MAX_SERVICE_NAME_LEN +#endif + +/* Maximum length of the service name. */ +#ifndef BT_MAX_SERVICE_NAME_LEN +#define BT_MAX_SERVICE_NAME_LEN 21 +#endif + +/* ACL buffer size in HCI Host Buffer Size command. */ +#ifndef BTM_ACL_BUF_SIZE +#define BTM_ACL_BUF_SIZE 0 +#endif + +/* The maximum number of clients that can register with the power manager. */ +#ifndef BTM_MAX_PM_RECORDS +#define BTM_MAX_PM_RECORDS 2 +#endif + +/* This is set to show debug trace messages for the power manager. */ +#ifndef BTM_PM_DEBUG +#define BTM_PM_DEBUG FALSE +#endif + +/* This is set to TRUE if link is to be unparked due to BTM_CreateSCO API. */ +#ifndef BTM_SCO_WAKE_PARKED_LINK +#define BTM_SCO_WAKE_PARKED_LINK TRUE +#endif + +/* If the user does not respond to security process requests within this many seconds, + * a negative response would be sent automatically. + * 30 is LMP response timeout value */ +#ifndef BTM_SEC_TIMEOUT_VALUE +#define BTM_SEC_TIMEOUT_VALUE 35 +#endif + +/* Maximum number of callbacks that can be registered using BTM_RegisterForVSEvents */ +#ifndef BTM_MAX_VSE_CALLBACKS +#define BTM_MAX_VSE_CALLBACKS 3 +#endif + +/****************************************** +** Lisbon Features +*******************************************/ +/* This is set to TRUE if the FEC is required for EIR packet. */ +#ifndef BTM_EIR_DEFAULT_FEC_REQUIRED +#define BTM_EIR_DEFAULT_FEC_REQUIRED TRUE +#endif + +/* The IO capability of the local device (for Simple Pairing) */ +#ifndef BTM_LOCAL_IO_CAPS +#define BTM_LOCAL_IO_CAPS BTM_IO_CAP_IO +#endif + +#ifndef BTM_LOCAL_IO_CAPS_BLE +#define BTM_LOCAL_IO_CAPS_BLE BTM_IO_CAP_KBDISP +#endif + +/* The default MITM Protection Requirement (for Simple Pairing) + * Possible values are BTM_AUTH_SP_YES or BTM_AUTH_SP_NO */ +#ifndef BTM_DEFAULT_AUTH_REQ +#define BTM_DEFAULT_AUTH_REQ BTM_AUTH_SP_NO +#endif + +/* The default MITM Protection Requirement for dedicated bonding using Simple Pairing + * Possible values are BTM_AUTH_AP_YES or BTM_AUTH_AP_NO */ +#ifndef BTM_DEFAULT_DD_AUTH_REQ +#define BTM_DEFAULT_DD_AUTH_REQ BTM_AUTH_AP_YES +#endif + +/* Include Out-of-Band implementation for Simple Pairing */ +#ifndef BTM_OOB_INCLUDED +#define BTM_OOB_INCLUDED TRUE +#endif + +/* TRUE to include Sniff Subrating */ +#ifndef BTM_SSR_INCLUDED +#define BTM_SSR_INCLUDED TRUE +#endif + +/************************* +** End of Lisbon Features +**************************/ + +/* 4.1/4.2 secure connections feature */ +#ifndef SC_MODE_INCLUDED +#define SC_MODE_INCLUDED TRUE +#endif + +/* Used for conformance testing ONLY */ +#ifndef BTM_BLE_CONFORMANCE_TESTING +#define BTM_BLE_CONFORMANCE_TESTING FALSE +#endif + +/****************************************************************************** +** +** L2CAP +** +******************************************************************************/ + +#ifndef L2CAP_CLIENT_INCLUDED +#define L2CAP_CLIENT_INCLUDED FALSE +#endif + + +/* The maximum number of simultaneous links that L2CAP can support. Up to 7*/ +#ifndef MAX_ACL_CONNECTIONS +#define MAX_L2CAP_LINKS 3 +#else +#define MAX_L2CAP_LINKS MAX_ACL_CONNECTIONS +#endif + +/* The maximum number of simultaneous channels that L2CAP can support. Up to 16*/ +#ifndef MAX_L2CAP_CHANNELS +#define MAX_L2CAP_CHANNELS 8 +#endif + +/* The maximum number of simultaneous applications that can register with L2CAP. */ +#ifndef MAX_L2CAP_CLIENTS +#define MAX_L2CAP_CLIENTS 8 +#endif + +/* The number of seconds of link inactivity before a link is disconnected. */ +#ifndef L2CAP_LINK_INACTIVITY_TOUT +#define L2CAP_LINK_INACTIVITY_TOUT 4 +#endif + +/* The number of seconds of link inactivity after bonding before a link is disconnected. */ +#ifndef L2CAP_BONDING_TIMEOUT +#define L2CAP_BONDING_TIMEOUT 3 +#endif + +/* The time from the HCI connection complete to disconnect if no channel is established. */ +#ifndef L2CAP_LINK_STARTUP_TOUT +#define L2CAP_LINK_STARTUP_TOUT 60 +#endif + +/* The L2CAP MTU; must be in accord with the HCI ACL pool size. */ +#ifndef L2CAP_MTU_SIZE +#define L2CAP_MTU_SIZE 1691 +#endif + +/* The L2CAP MPS over Bluetooth; must be in accord with the FCR tx pool size and ACL down buffer size. */ +#ifndef L2CAP_MPS_OVER_BR_EDR +#define L2CAP_MPS_OVER_BR_EDR 1010 +#endif + +/* If host flow control enabled, this is the number of buffers the controller can have unacknowledged. */ +#ifndef L2CAP_HOST_FC_ACL_BUFS +#define L2CAP_HOST_FC_ACL_BUFS 20 +#endif + +/* This is set to enable L2CAP to take the ACL link out of park mode when ACL data is to be sent. */ +#ifndef L2CAP_WAKE_PARKED_LINK +#define L2CAP_WAKE_PARKED_LINK TRUE +#endif + +/* Whether link wants to be the master or the slave. */ +#ifndef L2CAP_DESIRED_LINK_ROLE +#define L2CAP_DESIRED_LINK_ROLE HCI_ROLE_SLAVE +#endif + +/* Include Non-Flushable Packet Boundary Flag feature of Lisbon */ +#ifndef L2CAP_NON_FLUSHABLE_PB_INCLUDED +#define L2CAP_NON_FLUSHABLE_PB_INCLUDED TRUE +#endif + +/* Minimum number of ACL credit for high priority link */ +#ifndef L2CAP_HIGH_PRI_MIN_XMIT_QUOTA +#define L2CAP_HIGH_PRI_MIN_XMIT_QUOTA 5 +#endif + +/* used for monitoring HCI ACL credit management */ +#ifndef L2CAP_HCI_FLOW_CONTROL_DEBUG +#define L2CAP_HCI_FLOW_CONTROL_DEBUG TRUE +#endif + +/* Used for calculating transmit buffers off of */ +#ifndef L2CAP_NUM_XMIT_BUFFS +#define L2CAP_NUM_XMIT_BUFFS HCI_ACL_BUF_MAX +#endif + +/* Unicast Connectionless Data */ +#ifndef L2CAP_UCD_INCLUDED +#define L2CAP_UCD_INCLUDED FALSE +#endif + +/* Unicast Connectionless Data MTU */ +#ifndef L2CAP_UCD_MTU +#define L2CAP_UCD_MTU L2CAP_MTU_SIZE +#endif + +/* Unicast Connectionless Data Idle Timeout */ +#ifndef L2CAP_UCD_IDLE_TIMEOUT +#define L2CAP_UCD_IDLE_TIMEOUT 2 +#endif + +/* Unicast Connectionless Data Idle Timeout */ +#ifndef L2CAP_UCD_CH_PRIORITY +#define L2CAP_UCD_CH_PRIORITY L2CAP_CHNL_PRIORITY_MEDIUM +#endif + +/* Used for features using fixed channels; set to zero if no fixed channels supported (BLE, etc.) */ +/* Excluding L2CAP signaling channel and UCD */ +#ifndef L2CAP_NUM_FIXED_CHNLS +#define L2CAP_NUM_FIXED_CHNLS 32 +#endif + +/* First fixed channel supported */ +#ifndef L2CAP_FIRST_FIXED_CHNL +#define L2CAP_FIRST_FIXED_CHNL 4 +#endif + +#ifndef L2CAP_LAST_FIXED_CHNL +#define L2CAP_LAST_FIXED_CHNL (L2CAP_FIRST_FIXED_CHNL + L2CAP_NUM_FIXED_CHNLS - 1) +#endif + +/* Round Robin service channels in link */ +#ifndef L2CAP_ROUND_ROBIN_CHANNEL_SERVICE +#define L2CAP_ROUND_ROBIN_CHANNEL_SERVICE TRUE +#endif + +/* Used for calculating transmit buffers off of */ +#ifndef L2CAP_NUM_XMIT_BUFFS +#define L2CAP_NUM_XMIT_BUFFS HCI_ACL_BUF_MAX +#endif + +/* used for monitoring eL2CAP data flow */ +#ifndef L2CAP_ERTM_STATS +#define L2CAP_ERTM_STATS FALSE +#endif + +/* Used for conformance testing ONLY: When TRUE lets scriptwrapper overwrite info response */ +#ifndef L2CAP_CONFORMANCE_TESTING +#define L2CAP_CONFORMANCE_TESTING FALSE +#endif + +/* + * Max bytes per connection to buffer locally before dropping the + * connection if local client does not receive it - default is 1MB + */ +#ifndef L2CAP_MAX_RX_BUFFER +#define L2CAP_MAX_RX_BUFFER 0x100000 +#endif + + +#ifndef TIMER_PARAM_TYPE +#define TIMER_PARAM_TYPE UINT32 +#endif + +/****************************************************************************** +** +** BLE +** +******************************************************************************/ + +#ifndef BLE_INCLUDED +#define BLE_INCLUDED TRUE +#endif + +#ifndef BLE_ANDROID_CONTROLLER_SCAN_FILTER +#define BLE_ANDROID_CONTROLLER_SCAN_FILTER TRUE +#endif + +#ifndef LOCAL_BLE_CONTROLLER_ID +#define LOCAL_BLE_CONTROLLER_ID (1) +#endif + +/* + * Toggles support for general LE privacy features such as remote address + * resolution, local address rotation etc. + */ +#ifndef BLE_PRIVACY_SPT +#define BLE_PRIVACY_SPT TRUE +#endif + +/* + * Enables or disables support for local privacy (ex. address rotation) + */ +#ifndef BLE_LOCAL_PRIVACY_ENABLED +#define BLE_LOCAL_PRIVACY_ENABLED TRUE +#endif + +/* + * Toggles support for vendor specific extensions such as RPA offloading, + * feature discovery, multi-adv etc. + */ +#ifndef BLE_VND_INCLUDED +#define BLE_VND_INCLUDED FALSE +#endif + +#ifndef BTM_BLE_ADV_TX_POWER +#define BTM_BLE_ADV_TX_POWER {-21, -15, -7, 1, 9} +#endif + + +#ifndef BLE_BATCH_SCAN_INCLUDED +#define BLE_BATCH_SCAN_INCLUDED TRUE +#endif + +/****************************************************************************** +** +** ATT/GATT Protocol/Profile Settings +** +******************************************************************************/ +#ifndef GATT_INCLUDED +#if BLE_INCLUDED == TRUE +#define GATT_INCLUDED TRUE +#else +#define GATT_INCLUDED FALSE +#endif +#endif + +#ifndef BTA_GATT_INCLUDED +#if BLE_INCLUDED == TRUE +#define BTA_GATT_INCLUDED TRUE +#else +#define BTA_GATT_INCLUDED FALSE +#endif +#endif + +#if BTA_GATT_INCLUDED == TRUE && BLE_INCLUDED == FALSE +#error "can't have GATT without BLE" +#endif + +#ifndef BLE_LLT_INCLUDED +#define BLE_LLT_INCLUDED TRUE +#endif + +#ifndef ATT_INCLUDED +#define ATT_INCLUDED TRUE +#endif + +#ifndef ATT_DEBUG +#define ATT_DEBUG FALSE//TRUE +#endif + +#ifndef BLE_PERIPHERAL_MODE_SUPPORT +#define BLE_PERIPHERAL_MODE_SUPPORT TRUE +#endif + +#ifndef BLE_DELAY_REQUEST_ENC +/* This flag is to work around IPHONE problem, We need to wait for iPhone ready + before send encryption request to iPhone */ +#define BLE_DELAY_REQUEST_ENC FALSE +#endif + +#ifndef GAP_TRANSPORT_SUPPORTED +#define GAP_TRANSPORT_SUPPORTED GATT_TRANSPORT_LE_BR_EDR +#endif + +#ifndef GATTP_TRANSPORT_SUPPORTED +#define GATTP_TRANSPORT_SUPPORTED GATT_TRANSPORT_LE_BR_EDR +#endif + +#ifndef GATT_MAX_SR_PROFILES +#define GATT_MAX_SR_PROFILES 8 /* max is 32 */ +#endif + +#ifndef GATT_MAX_APPS +#define GATT_MAX_APPS 8 /* MAX is 32 note: 2 apps used internally GATT and GAP */ +#endif + +#ifndef GATT_MAX_PHY_CHANNEL +#define GATT_MAX_PHY_CHANNEL 7 +#endif + +/* Used for conformance testing ONLY */ +#ifndef GATT_CONFORMANCE_TESTING +#define GATT_CONFORMANCE_TESTING FALSE +#endif + +/* number of background connection device allowence, ideally to be the same as WL size +*/ +#ifndef GATT_MAX_BG_CONN_DEV +#define GATT_MAX_BG_CONN_DEV 8 /*MAX is 32*/ +#endif + +/****************************************************************************** +** +** GATT +** +******************************************************************************/ +#ifndef GATTC_INCLUDED +#if BLE_INCLUDED == TRUE +#define GATTC_INCLUDED TRUE +#else +#define GATTC_INCLUDED FALSE +#endif +#endif + +#ifndef GATTS_INCLUDED +#if BLE_INCLUDED == TRUE +#define GATTS_INCLUDED TRUE +#else +#define GATTS_INCLUDED FALSE +#endif +#endif + + +#if SMP_INCLUDED == TRUE && BLE_INCLUDED == FALSE +#error "can't have SMP without BLE" +#endif + + +/****************************************************************************** +** +** SMP +** +******************************************************************************/ +#ifndef SMP_INCLUDED +#if BLE_INCLUDED == TRUE +#define SMP_INCLUDED TRUE +#else +#define SMP_INCLUDED FALSE +#endif +#endif + +#if SMP_INCLUDED == TRUE && BLE_INCLUDED == FALSE +#error "can't have SMP without BLE" +#endif + +#ifndef SMP_DEBUG +#define SMP_DEBUG FALSE +#endif + +#ifndef SMP_DEFAULT_AUTH_REQ +#define SMP_DEFAULT_AUTH_REQ SMP_AUTH_NB_ENC_ONLY +#endif + +#ifndef SMP_MAX_ENC_KEY_SIZE +#define SMP_MAX_ENC_KEY_SIZE 16 +#endif + +#ifndef SMP_MIN_ENC_KEY_SIZE +#define SMP_MIN_ENC_KEY_SIZE 7 +#endif + +/* minimum link timeout after SMP pairing is done, leave room for key exchange + and racing condition for the following service connection. + Prefer greater than 0 second, and no less than default inactivity link idle + timer(L2CAP_LINK_INACTIVITY_TOUT) in l2cap) */ +#ifndef SMP_LINK_TOUT_MIN +#if (L2CAP_LINK_INACTIVITY_TOUT > 0) +#define SMP_LINK_TOUT_MIN L2CAP_LINK_INACTIVITY_TOUT +#else +#define SMP_LINK_TOUT_MIN 2 +#endif +#endif +/****************************************************************************** +** +** SDP +** +******************************************************************************/ + +#ifndef SDP_INCLUDED +#define SDP_INCLUDED FALSE //TRUE +#endif + +/* This is set to enable SDP server functionality. */ +#ifndef SDP_SERVER_ENABLED +#if SDP_INCLUDED == TRUE +#define SDP_SERVER_ENABLED TRUE +#else +#define SDP_SERVER_ENABLED FALSE +#endif +#endif + +/* This is set to enable SDP client functionality. */ +#ifndef SDP_CLIENT_ENABLED +#if SDP_INCLUDED == TRUE +#define SDP_CLIENT_ENABLED TRUE +#else +#define SDP_CLIENT_ENABLED FALSE +#endif +#endif + +/* The maximum number of SDP records the server can support. */ +#ifndef SDP_MAX_RECORDS +#define SDP_MAX_RECORDS 15 /*max is 30*/ +#endif + +/* The maximum number of attributes in each record. */ +#ifndef SDP_MAX_REC_ATTR +#define SDP_MAX_REC_ATTR 25 +#endif + +#ifndef SDP_MAX_PAD_LEN +#define SDP_MAX_PAD_LEN 600 +#endif + +/* The maximum length, in bytes, of an attribute. */ +#ifndef SDP_MAX_ATTR_LEN +#define SDP_MAX_ATTR_LEN 400 +#endif + +/* The maximum number of attribute filters supported by SDP databases. */ +#ifndef SDP_MAX_ATTR_FILTERS +#define SDP_MAX_ATTR_FILTERS 15 +#endif + +/* The maximum number of UUID filters supported by SDP databases. */ +#ifndef SDP_MAX_UUID_FILTERS +#define SDP_MAX_UUID_FILTERS 3 +#endif + +/* The maximum number of record handles retrieved in a search. */ +#ifndef SDP_MAX_DISC_SERVER_RECS +#define SDP_MAX_DISC_SERVER_RECS 21 +#endif + +/* The size of a scratchpad buffer, in bytes, for storing the response to an attribute request. */ +#ifndef SDP_MAX_LIST_BYTE_COUNT +#define SDP_MAX_LIST_BYTE_COUNT 4096 +#endif + +/* The maximum number of parameters in an SDP protocol element. */ +#ifndef SDP_MAX_PROTOCOL_PARAMS +#define SDP_MAX_PROTOCOL_PARAMS 2 +#endif + +/* The maximum number of simultaneous client and server connections. */ +#ifndef SDP_MAX_CONNECTIONS +#define SDP_MAX_CONNECTIONS 2 // 4 +#endif + +/* The MTU size for the L2CAP configuration. */ +#ifndef SDP_MTU_SIZE +#define SDP_MTU_SIZE 672 +#endif + +/* The flush timeout for the L2CAP configuration. */ +#ifndef SDP_FLUSH_TO +#define SDP_FLUSH_TO 0xFFFF +#endif + +/* The name for security authorization. */ +#ifndef SDP_SERVICE_NAME +#define SDP_SERVICE_NAME "Service Discovery" +#endif + +/* The security level for BTM. */ +#ifndef SDP_SECURITY_LEVEL +#define SDP_SECURITY_LEVEL BTM_SEC_NONE +#endif + +/****************************************************************************** +** +** RFCOMM +** +******************************************************************************/ +#ifndef RFCOMM_INCLUDED +#define RFCOMM_INCLUDED FALSE +#endif + +/* The maximum number of ports supported. */ +#ifndef MAX_RFC_PORTS +#define MAX_RFC_PORTS 16 /*max is 30*/ +#endif + +/* The maximum simultaneous links to different devices. */ +#ifndef MAX_ACL_CONNECTIONS +#define MAX_BD_CONNECTIONS 3 /*max is 7*/ +#else +#define MAX_BD_CONNECTIONS MAX_ACL_CONNECTIONS +#endif + +/* The port receive queue low watermark level, in bytes. */ +#ifndef PORT_RX_LOW_WM +#define PORT_RX_LOW_WM (BTA_RFC_MTU_SIZE * PORT_RX_BUF_LOW_WM) +#endif + +/* The port receive queue high watermark level, in bytes. */ +#ifndef PORT_RX_HIGH_WM +#define PORT_RX_HIGH_WM (BTA_RFC_MTU_SIZE * PORT_RX_BUF_HIGH_WM) +#endif + +/* The port receive queue critical watermark level, in bytes. */ +#ifndef PORT_RX_CRITICAL_WM +#define PORT_RX_CRITICAL_WM (BTA_RFC_MTU_SIZE * PORT_RX_BUF_CRITICAL_WM) +#endif + +/* The port receive queue low watermark level, in number of buffers. */ +#ifndef PORT_RX_BUF_LOW_WM +#define PORT_RX_BUF_LOW_WM 4 +#endif + +/* The port receive queue high watermark level, in number of buffers. */ +#ifndef PORT_RX_BUF_HIGH_WM +#define PORT_RX_BUF_HIGH_WM 10 +#endif + +/* The port receive queue critical watermark level, in number of buffers. */ +#ifndef PORT_RX_BUF_CRITICAL_WM +#define PORT_RX_BUF_CRITICAL_WM 15 +#endif + +/* The port transmit queue high watermark level, in bytes. */ +#ifndef PORT_TX_HIGH_WM +#define PORT_TX_HIGH_WM (BTA_RFC_MTU_SIZE * PORT_TX_BUF_HIGH_WM) +#endif + +/* The port transmit queue critical watermark level, in bytes. */ +#ifndef PORT_TX_CRITICAL_WM +#define PORT_TX_CRITICAL_WM (BTA_RFC_MTU_SIZE * PORT_TX_BUF_CRITICAL_WM) +#endif + +/* The port transmit queue high watermark level, in number of buffers. */ +#ifndef PORT_TX_BUF_HIGH_WM +#define PORT_TX_BUF_HIGH_WM 10 +#endif + +/* The port transmit queue high watermark level, in number of buffers. */ +#ifndef PORT_TX_BUF_CRITICAL_WM +#define PORT_TX_BUF_CRITICAL_WM 15 +#endif + +/* The RFCOMM multiplexer preferred flow control mechanism. */ +#ifndef PORT_FC_DEFAULT +#define PORT_FC_DEFAULT PORT_FC_CREDIT +#endif + +/* The maximum number of credits receiver sends to peer when using credit-based flow control. */ +#ifndef PORT_CREDIT_RX_MAX +#define PORT_CREDIT_RX_MAX 16 +#endif + +/* The credit low watermark level. */ +#ifndef PORT_CREDIT_RX_LOW +#define PORT_CREDIT_RX_LOW 8 +#endif + +/* if application like BTA, Java or script test engine is running on other than BTU thread, */ +/* PORT_SCHEDULE_LOCK shall be defined as GKI_sched_lock() or GKI_disable() */ +#ifndef PORT_SCHEDULE_LOCK +#define PORT_SCHEDULE_LOCK GKI_disable() +#endif + +/* if application like BTA, Java or script test engine is running on other than BTU thread, */ +/* PORT_SCHEDULE_LOCK shall be defined as GKI_sched_unlock() or GKI_enable() */ +#ifndef PORT_SCHEDULE_UNLOCK +#define PORT_SCHEDULE_UNLOCK GKI_enable() +#endif + +/****************************************************************************** +** +** OBEX +** +******************************************************************************/ +#define OBX_14_INCLUDED FALSE + +/* The maximum number of registered servers. */ +#ifndef OBX_NUM_SERVERS +#define OBX_NUM_SERVERS 12 +#endif + +/* The maximum number of active clients. */ +#ifndef OBX_NUM_CLIENTS +#define OBX_NUM_CLIENTS 8 +#endif + +/* This option is application when OBX_14_INCLUDED=TRUE + Pool ID where to reassemble the SDU. + This Pool will allow buffers to be used that are larger than + the L2CAP_MAX_MTU. */ +#ifndef OBX_USER_RX_POOL_ID +#define OBX_USER_RX_POOL_ID OBX_LRG_DATA_POOL_ID +#endif + +/* This option is application when OBX_14_INCLUDED=TRUE + Pool ID where to hold the SDU. + This Pool will allow buffers to be used that are larger than + the L2CAP_MAX_MTU. */ +#ifndef OBX_USER_TX_POOL_ID +#define OBX_USER_TX_POOL_ID OBX_LRG_DATA_POOL_ID +#endif + +/* This option is application when OBX_14_INCLUDED=TRUE +GKI Buffer Pool ID used to hold MPS segments during SDU reassembly +*/ +#ifndef OBX_FCR_RX_POOL_ID +#define OBX_FCR_RX_POOL_ID HCI_ACL_POOL_ID +#endif + +/* This option is application when OBX_14_INCLUDED=TRUE +GKI Buffer Pool ID used to hold MPS segments used in (re)transmissions. +L2CAP_DEFAULT_ERM_POOL_ID is specified to use the HCI ACL data pool. +Note: This pool needs to have enough buffers to hold two times the window size negotiated + in the L2CA_SetFCROptions (2 * tx_win_size) to allow for retransmissions. + The size of each buffer must be able to hold the maximum MPS segment size passed in + L2CA_SetFCROptions plus BT_HDR (8) + HCI preamble (4) + L2CAP_MIN_OFFSET (11 - as of BT 2.1 + EDR Spec). +*/ +#ifndef OBX_FCR_TX_POOL_ID +#define OBX_FCR_TX_POOL_ID HCI_ACL_POOL_ID +#endif + +/* This option is application when OBX_14_INCLUDED=TRUE +Size of the transmission window when using enhanced retransmission mode. Not used +in basic and streaming modes. Range: 1 - 63 +*/ +#ifndef OBX_FCR_OPT_TX_WINDOW_SIZE_BR_EDR +#define OBX_FCR_OPT_TX_WINDOW_SIZE_BR_EDR 20 +#endif + +/* This option is application when OBX_14_INCLUDED=TRUE +Number of transmission attempts for a single I-Frame before taking +Down the connection. Used In ERTM mode only. Value is Ignored in basic and +Streaming modes. +Range: 0, 1-0xFF +0 - infinite retransmissions +1 - single transmission +*/ +#ifndef OBX_FCR_OPT_MAX_TX_B4_DISCNT +#define OBX_FCR_OPT_MAX_TX_B4_DISCNT 20 +#endif + +/* This option is application when OBX_14_INCLUDED=TRUE +Retransmission Timeout +Range: Minimum 2000 (2 secs) on BR/EDR when supporting PBF. + */ +#ifndef OBX_FCR_OPT_RETX_TOUT +#define OBX_FCR_OPT_RETX_TOUT 2000 +#endif + +/* This option is application when OBX_14_INCLUDED=TRUE +Monitor Timeout +Range: Minimum 12000 (12 secs) on BR/EDR when supporting PBF. +*/ +#ifndef OBX_FCR_OPT_MONITOR_TOUT +#define OBX_FCR_OPT_MONITOR_TOUT 12000 +#endif + +/* This option is application when OBX_14_INCLUDED=TRUE +Maximum PDU payload size. +Suggestion: The maximum amount of data that will fit into a 3-DH5 packet. +Range: 2 octets +*/ +#ifndef OBX_FCR_OPT_MAX_PDU_SIZE +#define OBX_FCR_OPT_MAX_PDU_SIZE L2CAP_MPS_OVER_BR_EDR +#endif + + +/****************************************************************************** +** +** BNEP +** +******************************************************************************/ + +#ifndef BNEP_INCLUDED +#define BNEP_INCLUDED FALSE//TRUE +#endif + +/* BNEP status API call is used mainly to get the L2CAP handle */ +#ifndef BNEP_SUPPORTS_STATUS_API +#define BNEP_SUPPORTS_STATUS_API FALSE//TRUE +#endif + +/* +** When BNEP connection changes roles after the connection is established +** we will do an authentication check again on the new role +*/ +#ifndef BNEP_DO_AUTH_FOR_ROLE_SWITCH +#define BNEP_DO_AUTH_FOR_ROLE_SWITCH FALSE//TRUE +#endif + + +/* Maximum number of protocol filters supported. */ +#ifndef BNEP_MAX_PROT_FILTERS +#define BNEP_MAX_PROT_FILTERS 5 +#endif + +/* Maximum number of multicast filters supported. */ +#ifndef BNEP_MAX_MULTI_FILTERS +#define BNEP_MAX_MULTI_FILTERS 5 +#endif + +/* Minimum MTU size. */ +#ifndef BNEP_MIN_MTU_SIZE +#define BNEP_MIN_MTU_SIZE L2CAP_MTU_SIZE +#endif + +/* Preferred MTU size. */ +#ifndef BNEP_MTU_SIZE +#define BNEP_MTU_SIZE BNEP_MIN_MTU_SIZE +#endif + +/* Maximum number of buffers allowed in transmit data queue. */ +#ifndef BNEP_MAX_XMITQ_DEPTH +#define BNEP_MAX_XMITQ_DEPTH 20 +#endif + +/* Maximum number BNEP of connections supported. */ +#ifndef BNEP_MAX_CONNECTIONS +#define BNEP_MAX_CONNECTIONS 7 +#endif + + +/****************************************************************************** +** +** AVDTP +** +******************************************************************************/ + +#ifndef AVDT_INCLUDED +#define AVDT_INCLUDED FALSE//TRUE +#endif + +/* Include reporting capability in AVDTP */ +#ifndef AVDT_REPORTING +#define AVDT_REPORTING FALSE//TRUE +#endif + +/* Include multiplexing capability in AVDTP */ +#ifndef AVDT_MULTIPLEXING +#define AVDT_MULTIPLEXING FALSE//TRUE +#endif + +/* Number of simultaneous links to different peer devices. */ +#ifndef AVDT_NUM_LINKS +#define AVDT_NUM_LINKS 2 +#endif + +/* Number of simultaneous stream endpoints. */ +#ifndef AVDT_NUM_SEPS +#define AVDT_NUM_SEPS 3 +#endif + +/* Number of transport channels setup per media stream(audio or video) */ +#ifndef AVDT_NUM_CHANNELS + +#if AVDT_REPORTING == TRUE +/* signaling, media and reporting channels */ +#define AVDT_NUM_CHANNELS 3 +#else +/* signaling and media channels */ +#define AVDT_NUM_CHANNELS 2 +#endif // AVDT_REPORTING + +#endif // AVDT_NUM_CHANNELS + +/* Number of transport channels setup by AVDT for all media streams + * AVDT_NUM_CHANNELS * Number of simultaneous streams. + */ +#ifndef AVDT_NUM_TC_TBL +#define AVDT_NUM_TC_TBL 6 +#endif + +/* Maximum size in bytes of the codec capabilities information element. */ +#ifndef AVDT_CODEC_SIZE +#define AVDT_CODEC_SIZE 10 +#endif + +/* Maximum size in bytes of the content protection information element. */ +#ifndef AVDT_PROTECT_SIZE +#define AVDT_PROTECT_SIZE 90 +#endif + +/* Maximum number of GKI buffers in the fragment queue (for video frames). + * Must be less than the number of buffers in the buffer pool of size AVDT_DATA_POOL_SIZE */ +#ifndef AVDT_MAX_FRAG_COUNT +#define AVDT_MAX_FRAG_COUNT 15 +#endif + +/****************************************************************************** +** +** PAN +** +******************************************************************************/ + +#ifndef PAN_INCLUDED +#define PAN_INCLUDED FALSE//TRUE +#endif + +/* This will enable the PANU role */ +#ifndef PAN_SUPPORTS_ROLE_PANU +#define PAN_SUPPORTS_ROLE_PANU FALSE//TRUE +#endif + +/* This will enable the GN role */ +#ifndef PAN_SUPPORTS_ROLE_GN +#define PAN_SUPPORTS_ROLE_GN FALSE//TRUE +#endif + +/* This will enable the NAP role */ +#ifndef PAN_SUPPORTS_ROLE_NAP +#define PAN_SUPPORTS_ROLE_NAP FALSE//TRUE +#endif + +/* This is just for debugging purposes */ +#ifndef PAN_SUPPORTS_DEBUG_DUMP +#define PAN_SUPPORTS_DEBUG_DUMP FALSE//TRUE +#endif + +/* Maximum number of PAN connections allowed */ +#ifndef MAX_PAN_CONNS +#define MAX_PAN_CONNS 7 +#endif + +/* Default service name for NAP role */ +#ifndef PAN_NAP_DEFAULT_SERVICE_NAME +#define PAN_NAP_DEFAULT_SERVICE_NAME "Network Access Point Service" +#endif + +/* Default service name for GN role */ +#ifndef PAN_GN_DEFAULT_SERVICE_NAME +#define PAN_GN_DEFAULT_SERVICE_NAME "Group Network Service" +#endif + +/* Default service name for PANU role */ +#ifndef PAN_PANU_DEFAULT_SERVICE_NAME +#define PAN_PANU_DEFAULT_SERVICE_NAME "PAN User Service" +#endif + +/* Default description for NAP role service */ +#ifndef PAN_NAP_DEFAULT_DESCRIPTION +#define PAN_NAP_DEFAULT_DESCRIPTION "NAP" +#endif + +/* Default description for GN role service */ +#ifndef PAN_GN_DEFAULT_DESCRIPTION +#define PAN_GN_DEFAULT_DESCRIPTION "GN" +#endif + +/* Default description for PANU role service */ +#ifndef PAN_PANU_DEFAULT_DESCRIPTION +#define PAN_PANU_DEFAULT_DESCRIPTION "PANU" +#endif + +/* Default Security level for PANU role. */ +#ifndef PAN_PANU_SECURITY_LEVEL +#define PAN_PANU_SECURITY_LEVEL 0 +#endif + +/* Default Security level for GN role. */ +#ifndef PAN_GN_SECURITY_LEVEL +#define PAN_GN_SECURITY_LEVEL 0 +#endif + +/* Default Security level for NAP role. */ +#ifndef PAN_NAP_SECURITY_LEVEL +#define PAN_NAP_SECURITY_LEVEL 0 +#endif + +/****************************************************************************** +** +** GAP +** +******************************************************************************/ + +#ifndef GAP_INCLUDED +#define GAP_INCLUDED TRUE +#endif + +/* This is set to enable use of GAP L2CAP connections. */ +#ifndef GAP_CONN_INCLUDED +#if GAP_INCLUDED == TRUE +#define GAP_CONN_INCLUDED TRUE +#else +#define GAP_CONN_INCLUDED FALSE +#endif +#endif + +/* This is set to enable posting event for data write */ +#ifndef GAP_CONN_POST_EVT_INCLUDED +#define GAP_CONN_POST_EVT_INCLUDED FALSE +#endif + +/* The maximum number of simultaneous GAP L2CAP connections. */ +#ifndef GAP_MAX_CONNECTIONS +#define GAP_MAX_CONNECTIONS 10 // 30 +#endif + +/* keep the raw data received from SDP server in database. */ +#ifndef SDP_RAW_DATA_INCLUDED +#define SDP_RAW_DATA_INCLUDED TRUE +#endif + +/* Inquiry duration in 1.28 second units. */ +#ifndef SDP_DEBUG +#define SDP_DEBUG TRUE +#endif + +/****************************************************************************** +** +** HID +** +******************************************************************************/ + +#ifndef HID_DEV_SUBCLASS +#define HID_DEV_SUBCLASS COD_MINOR_POINTING +#endif + +#ifndef HID_CONTROL_POOL_ID +#define HID_CONTROL_POOL_ID 2 +#endif + +#ifndef HID_INTERRUPT_POOL_ID +#define HID_INTERRUPT_POOL_ID 2 +#endif + +/************************************************************************* +** Definitions for Both HID-Host & Device +*/ +#ifndef HID_MAX_SVC_NAME_LEN +#define HID_MAX_SVC_NAME_LEN 32 +#endif + +#ifndef HID_MAX_SVC_DESCR_LEN +#define HID_MAX_SVC_DESCR_LEN 32 +#endif + +#ifndef HID_MAX_PROV_NAME_LEN +#define HID_MAX_PROV_NAME_LEN 32 +#endif + +/************************************************************************* +** Definitions for HID-Host +*/ +#ifndef HID_HOST_INCLUDED +#define HID_HOST_INCLUDED FALSE//TRUE +#endif + +#ifndef HID_HOST_MAX_DEVICES +#define HID_HOST_MAX_DEVICES 7 +#endif + +#ifndef HID_HOST_MTU +#define HID_HOST_MTU 640 +#endif + +#ifndef HID_HOST_FLUSH_TO +#define HID_HOST_FLUSH_TO 0xffff +#endif + +#ifndef HID_HOST_MAX_CONN_RETRY +#define HID_HOST_MAX_CONN_RETRY (3) +#endif + +#ifndef HID_HOST_REPAGE_WIN +#define HID_HOST_REPAGE_WIN (2) +#endif + +/************************************************************************* + * A2DP Definitions + */ +#ifndef A2D_INCLUDED +#define A2D_INCLUDED FALSE//TRUE +#endif + +/****************************************************************************** +** +** AVCTP +** +******************************************************************************/ + +/* Number of simultaneous ACL links to different peer devices. */ +#ifndef AVCT_NUM_LINKS +#define AVCT_NUM_LINKS 2 +#endif + +/* Number of simultaneous AVCTP connections. */ +#ifndef AVCT_NUM_CONN +#define AVCT_NUM_CONN 3 +#endif + +/****************************************************************************** +** +** AVRCP +** +******************************************************************************/ +#ifndef AVRC_INCLUDED +#define AVRC_INCLUDED FALSE +#endif + +#ifndef AVRC_METADATA_INCLUDED +#if AVRC_INCLUDED == TRUE +#define AVRC_METADATA_INCLUDED TRUE +#else +#define AVRC_METADATA_INCLUDED FALSE +#endif +#endif + +#ifndef AVRC_ADV_CTRL_INCLUDED +#if AVRC_INCLUDED == TRUE +#define AVRC_ADV_CTRL_INCLUDED TRUE +#else +#define AVRC_ADV_CTRL_INCLUDED FALSE +#endif +#endif + +#ifndef AVRC_CTLR_INCLUDED +#if AVRC_INCLUDED == TRUE +#define AVRC_CTLR_INCLUDED TRUE +#else +#define AVRC_CTLR_INCLUDED FALSE +#endif +#endif + +/****************************************************************************** +** +** MCAP +** +******************************************************************************/ +#ifndef MCA_INCLUDED +#define MCA_INCLUDED FALSE +#endif + +/* The MTU size for the L2CAP configuration on control channel. 48 is the minimal */ +#ifndef MCA_CTRL_MTU +#define MCA_CTRL_MTU 60 +#endif + +/* The maximum number of registered MCAP instances. */ +#ifndef MCA_NUM_REGS +#define MCA_NUM_REGS 12 +#endif + +/* The maximum number of control channels (to difference devices) per registered MCAP instances. */ +#ifndef MCA_NUM_LINKS +#define MCA_NUM_LINKS 3 +#endif + +/* The maximum number of MDEP (including HDP echo) per registered MCAP instances. */ +#ifndef MCA_NUM_DEPS +#define MCA_NUM_DEPS 13 +#endif + +/* The maximum number of MDL link per control channel. */ +#ifndef MCA_NUM_MDLS +#define MCA_NUM_MDLS 4 +#endif + +/* Pool ID where to reassemble the SDU. */ +#ifndef MCA_USER_RX_POOL_ID +#define MCA_USER_RX_POOL_ID HCI_ACL_POOL_ID +#endif + +/* Pool ID where to hold the SDU. */ +#ifndef MCA_USER_TX_POOL_ID +#define MCA_USER_TX_POOL_ID HCI_ACL_POOL_ID +#endif + +/* +GKI Buffer Pool ID used to hold MPS segments during SDU reassembly +*/ +#ifndef MCA_FCR_RX_POOL_ID +#define MCA_FCR_RX_POOL_ID HCI_ACL_POOL_ID +#endif + +/* +GKI Buffer Pool ID used to hold MPS segments used in (re)transmissions. +L2CAP_DEFAULT_ERM_POOL_ID is specified to use the HCI ACL data pool. +Note: This pool needs to have enough buffers to hold two times the window size negotiated + in the tL2CAP_FCR_OPTIONS (2 * tx_win_size) to allow for retransmissions. + The size of each buffer must be able to hold the maximum MPS segment size passed in + tL2CAP_FCR_OPTIONS plus BT_HDR (8) + HCI preamble (4) + L2CAP_MIN_OFFSET (11 - as of BT 2.1 + EDR Spec). +*/ +#ifndef MCA_FCR_TX_POOL_ID +#define MCA_FCR_TX_POOL_ID HCI_ACL_POOL_ID +#endif + +/* MCAP control channel FCR Option: +Size of the transmission window when using enhanced retransmission mode. +1 is defined by HDP specification for control channel. +*/ +#ifndef MCA_FCR_OPT_TX_WINDOW_SIZE +#define MCA_FCR_OPT_TX_WINDOW_SIZE 1 +#endif + +/* MCAP control channel FCR Option: +Number of transmission attempts for a single I-Frame before taking +Down the connection. Used In ERTM mode only. Value is Ignored in basic and +Streaming modes. +Range: 0, 1-0xFF +0 - infinite retransmissions +1 - single transmission +*/ +#ifndef MCA_FCR_OPT_MAX_TX_B4_DISCNT +#define MCA_FCR_OPT_MAX_TX_B4_DISCNT 20 +#endif + +/* MCAP control channel FCR Option: Retransmission Timeout +The AVRCP specification set a value in the range of 300 - 2000 ms +Timeout (in msecs) to detect Lost I-Frames. Only used in Enhanced retransmission mode. +Range: Minimum 2000 (2 secs) when supporting PBF. + */ +#ifndef MCA_FCR_OPT_RETX_TOUT +#define MCA_FCR_OPT_RETX_TOUT 2000 +#endif + +/* MCAP control channel FCR Option: Monitor Timeout +The AVRCP specification set a value in the range of 300 - 2000 ms +Timeout (in msecs) to detect Lost S-Frames. Only used in Enhanced retransmission mode. +Range: Minimum 12000 (12 secs) when supporting PBF. +*/ +#ifndef MCA_FCR_OPT_MONITOR_TOUT +#define MCA_FCR_OPT_MONITOR_TOUT 12000 +#endif + +/* MCAP control channel FCR Option: Maximum PDU payload size. +The maximum number of payload octets that the local device can receive in a single PDU. +*/ +#ifndef MCA_FCR_OPT_MPS_SIZE +#define MCA_FCR_OPT_MPS_SIZE 1000 +#endif + +/* Shared transport */ +#ifndef NFC_SHARED_TRANSPORT_ENABLED +#define NFC_SHARED_TRANSPORT_ENABLED FALSE +#endif + +/****************************************************************************** +** +** Sleep Mode (Low Power Mode) +** +******************************************************************************/ + +#ifndef HCILP_INCLUDED +#define HCILP_INCLUDED FALSE//TRUE +#endif + +/****************************************************************************** +** +** APPL - Application Task +** +******************************************************************************/ + +#define L2CAP_FEATURE_REQ_ID 73 +#define L2CAP_FEATURE_RSP_ID 173 + +/****************************************************************************** +** +** BTA +** +******************************************************************************/ +/* BTA EIR canned UUID list (default is dynamic) */ +#ifndef BTA_EIR_CANNED_UUID_LIST +#define BTA_EIR_CANNED_UUID_LIST FALSE +#endif + +/* Number of supported customer UUID in EIR */ +#ifndef BTA_EIR_SERVER_NUM_CUSTOM_UUID +#define BTA_EIR_SERVER_NUM_CUSTOM_UUID 8 +#endif + +/* CHLD override for bluedroid */ +#ifndef BTA_AG_CHLD_VAL_ECC +#define BTA_AG_CHLD_VAL_ECC "(0,1,1x,2,2x,3)" +#endif + +#ifndef BTA_AG_CHLD_VAL +#define BTA_AG_CHLD_VAL "(0,1,2,3)" +#endif + +/* Set the CIND to match HFP 1.5 */ +#ifndef BTA_AG_CIND_INFO +#define BTA_AG_CIND_INFO "(\"call\",(0,1)),(\"callsetup\",(0-3)),(\"service\",(0-1)),(\"signal\",(0-5)),(\"roam\",(0,1)),(\"battchg\",(0-5)),(\"callheld\",(0-2))" +#endif + +#ifndef BTA_DM_AVOID_A2DP_ROLESWITCH_ON_INQUIRY +#define BTA_DM_AVOID_A2DP_ROLESWITCH_ON_INQUIRY FALSE//TRUE +#endif + +/****************************************************************************** +** +** Tracing: Include trace header file here. +** +******************************************************************************/ + +/* Enable/disable BTSnoop memory logging */ +#ifndef BTSNOOP_MEM +#define BTSNOOP_MEM FALSE//TRUE +#endif + +#include "bt_trace.h" + +#endif /* BT_TARGET_H */ diff --git a/tools/sdk/include/bluedroid/bt_trace.h b/tools/sdk/include/bluedroid/bt_trace.h new file mode 100644 index 00000000..787c4c8a --- /dev/null +++ b/tools/sdk/include/bluedroid/bt_trace.h @@ -0,0 +1,470 @@ +/****************************************************************************** + * + * Copyright (C) 1999-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. + * + ******************************************************************************/ + +#ifndef _BT_TRACE_H_ +#define _BT_TRACE_H_ + +#include +#include "bt_types.h" + +#include "esp_log.h" + +#define TAG "BT" + +#define BT_PRINTF(fmt, ...) ESP_LOGE(TAG, fmt, ##__VA_ARGS__) + +#ifndef assert +#define assert(x) do { if (!(x)) BT_PRINTF("bt host error %s %u\n", __FILE__, __LINE__); } while (0) +#endif + +inline void trc_dump_buffer(const char *prefix, uint8_t *data, uint16_t len) +{ + uint16_t i; + + if (!data || !len) { + return; + } + + if (prefix) { + BT_PRINTF("%s: len %d\n", prefix, len); + } + + for (i = 0; i < len; i+=16) { + BT_PRINTF("%02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x\n", + *(data + i), *(data + i + 1), *(data + i + 2), *(data + i + 3), *(data + i + 4), *(data + i + 5), *(data + i + 6), *(data + i + 7), + *(data + i + 8), *(data + i + 9), *(data + i + 10), *(data + i + 11), *(data + i + 12), *(data + i + 13), *(data + i + 14), *(data + i + 15)); + } + BT_PRINTF("\n"); +} + +#ifdef BTTRC_DUMP_BUFFER +#define BTTRC_DUMP_BUFFER(_prefix, _data, _len) trc_dump_buffer(_data, _len) +#else +#define BTTRC_DUMP_BUFFER(_prefix, _data, _len) +#endif + +//static const char BTE_LOGMSG_MODULE[] = "bte_logmsg_module"; + +/* BTrgs);E tracing IDs for debug purposes */ +/* LayerIDs for stack */ +#define BTTRC_ID_STK_GKI 1 +#define BTTRC_ID_STK_BTU 2 +#define BTTRC_ID_STK_HCI 3 +#define BTTRC_ID_STK_L2CAP 4 +#define BTTRC_ID_STK_RFCM_MX 5 +#define BTTRC_ID_STK_RFCM_PRT 6 +#define BTTRC_ID_STK_OBEX_C 7 +#define BTTRC_ID_STK_OBEX_S 8 +#define BTTRC_ID_STK_AVCT 9 +#define BTTRC_ID_STK_AVDT 10 +#define BTTRC_ID_STK_AVRC 11 +#define BTTRC_ID_STK_BIC 12 +#define BTTRC_ID_STK_BIS 13 +#define BTTRC_ID_STK_BNEP 14 +#define BTTRC_ID_STK_BPP 15 +#define BTTRC_ID_STK_BTM_ACL 16 +#define BTTRC_ID_STK_BTM_PM 17 +#define BTTRC_ID_STK_BTM_DEV_CTRL 18 +#define BTTRC_ID_STK_BTM_SVC_DSC 19 +#define BTTRC_ID_STK_BTM_INQ 20 +#define BTTRC_ID_STK_BTM_SCO 21 +#define BTTRC_ID_STK_BTM_SEC 22 +#define BTTRC_ID_STK_HID 24 +#define BTTRC_ID_STK_HSP2 25 +#define BTTRC_ID_STK_CTP 26 +#define BTTRC_ID_STK_FTC 27 +#define BTTRC_ID_STK_FTS 28 +#define BTTRC_ID_STK_GAP 29 +#define BTTRC_ID_STK_HCRP 31 +#define BTTRC_ID_STK_ICP 32 +#define BTTRC_ID_STK_OPC 33 +#define BTTRC_ID_STK_OPS 34 +#define BTTRC_ID_STK_PAN 35 +#define BTTRC_ID_STK_SAP 36 +#define BTTRC_ID_STK_SDP 37 +#define BTTRC_ID_STK_SLIP 38 +#define BTTRC_ID_STK_SPP 39 +#define BTTRC_ID_STK_TCS 40 +#define BTTRC_ID_STK_VDP 41 +#define BTTRC_ID_STK_MCAP 42 +#define BTTRC_ID_STK_GATT 43 +#define BTTRC_ID_STK_SMP 44 +#define BTTRC_ID_STK_NFC 45 +#define BTTRC_ID_STK_NCI 46 +#define BTTRC_ID_STK_IDEP 47 +#define BTTRC_ID_STK_NDEP 48 +#define BTTRC_ID_STK_LLCP 49 +#define BTTRC_ID_STK_RW 50 +#define BTTRC_ID_STK_CE 51 +#define BTTRC_ID_STK_SNEP 52 +#define BTTRC_ID_STK_NDEF 53 + +/* LayerIDs for BTA */ +#define BTTRC_ID_BTA_ACC 55 /* Advanced Camera Client */ +#define BTTRC_ID_BTA_AG 56 /* audio gateway */ +#define BTTRC_ID_BTA_AV 57 /* Advanced audio */ +#define BTTRC_ID_BTA_BIC 58 /* Basic Imaging Client */ +#define BTTRC_ID_BTA_BIS 59 /* Basic Imaging Server */ +#define BTTRC_ID_BTA_BP 60 /* Basic Printing Client */ +#define BTTRC_ID_BTA_CG 61 +#define BTTRC_ID_BTA_CT 62 /* cordless telephony terminal */ +#define BTTRC_ID_BTA_DG 63 /* data gateway */ +#define BTTRC_ID_BTA_DM 64 /* device manager */ +#define BTTRC_ID_BTA_DM_SRCH 65 /* device manager search */ +#define BTTRC_ID_BTA_DM_SEC 66 /* device manager security */ +#define BTTRC_ID_BTA_FM 67 +#define BTTRC_ID_BTA_FTC 68 /* file transfer client */ +#define BTTRC_ID_BTA_FTS 69 /* file transfer server */ +#define BTTRC_ID_BTA_HIDH 70 +#define BTTRC_ID_BTA_HIDD 71 +#define BTTRC_ID_BTA_JV 72 +#define BTTRC_ID_BTA_OPC 73 /* object push client */ +#define BTTRC_ID_BTA_OPS 74 /* object push server */ +#define BTTRC_ID_BTA_PAN 75 /* Personal Area Networking */ +#define BTTRC_ID_BTA_PR 76 /* Printer client */ +#define BTTRC_ID_BTA_SC 77 /* SIM Card Access server */ +#define BTTRC_ID_BTA_SS 78 /* synchronization server */ +#define BTTRC_ID_BTA_SYS 79 /* system manager */ +#define BTTRC_ID_AVDT_SCB 80 /* avdt scb */ +#define BTTRC_ID_AVDT_CCB 81 /* avdt ccb */ + +// btla-specific ++ +/* LayerIDs added for BTL-A. Probably should modify bte_logmsg.c in future. */ +#define BTTRC_ID_STK_RFCOMM 82 +#define BTTRC_ID_STK_RFCOMM_DATA 83 +#define BTTRC_ID_STK_OBEX 84 +#define BTTRC_ID_STK_A2D 85 +#define BTTRC_ID_STK_BIP 86 + +/* LayerIDs for BT APP */ +#define BTTRC_ID_BTAPP 87 +#define BTTRC_ID_BT_PROTOCOL 88 /* this is a temporary solution to allow dynamic + enable/disable of BT_PROTOCOL_TRACE */ +#define BTTRC_ID_MAX_ID BTTRC_ID_BT_PROTOCOL +// btla-specific -- +#define BTTRC_ID_ALL_LAYERS 0xFF /* all trace layers */ +/* Parameter datatypes used in Trace APIs */ +#define BTTRC_PARAM_UINT8 1 +#define BTTRC_PARAM_UINT16 2 +#define BTTRC_PARAM_UINT32 3 + +/* Enables or disables verbose trace information. */ +#ifndef BT_TRACE_VERBOSE +#define BT_TRACE_VERBOSE FALSE +#endif + +/* Enables or disables all trace messages. */ +#ifndef BT_USE_TRACES +#define BT_USE_TRACES TRUE +#endif + +/****************************************************************************** +** +** Trace Levels +** +** The following values may be used for different levels: +** BT_TRACE_LEVEL_NONE 0 * No trace messages to be generated +** BT_TRACE_LEVEL_ERROR 1 * Error condition trace messages +** BT_TRACE_LEVEL_WARNING 2 * Warning condition trace messages +** BT_TRACE_LEVEL_API 3 * API traces +** BT_TRACE_LEVEL_EVENT 4 * Debug messages for events +** BT_TRACE_LEVEL_DEBUG 5 * Debug messages (general) +******************************************************************************/ + +// btla-specific ++ +/* Core Stack default trace levels */ +#ifndef HCI_INITIAL_TRACE_LEVEL +#define HCI_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING +#endif + +#ifndef BTM_INITIAL_TRACE_LEVEL +#define BTM_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING +#endif + +#ifndef L2CAP_INITIAL_TRACE_LEVEL +#define L2CAP_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING +#endif + +#ifndef RFCOMM_INITIAL_TRACE_LEVEL +#define RFCOMM_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING +#endif + +#ifndef SDP_INITIAL_TRACE_LEVEL +#define SDP_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING +#endif + +#ifndef GAP_INITIAL_TRACE_LEVEL +#define GAP_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING +#endif + +#ifndef BNEP_INITIAL_TRACE_LEVEL +#define BNEP_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING +#endif + +#ifndef PAN_INITIAL_TRACE_LEVEL +#define PAN_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING +#endif + +#ifndef A2D_INITIAL_TRACE_LEVEL +#define A2D_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING +#endif + +#ifndef AVDT_INITIAL_TRACE_LEVEL +#define AVDT_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING +#endif + +#ifndef AVCT_INITIAL_TRACE_LEVEL +#define AVCT_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING +#endif + +#ifndef AVRC_INITIAL_TRACE_LEVEL +#define AVRC_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING +#endif + +#ifndef MCA_INITIAL_TRACE_LEVEL +#define MCA_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING +#endif + +#ifndef HID_INITIAL_TRACE_LEVEL +#define HID_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING +#endif + +#ifndef APPL_INITIAL_TRACE_LEVEL +#define APPL_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING +#endif + +#ifndef BT_TRACE_APPL +#define BT_TRACE_APPL BT_USE_TRACES +#endif + +#ifndef GATT_INITIAL_TRACE_LEVEL +#define GATT_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING +#endif + +#ifndef SMP_INITIAL_TRACE_LEVEL +#define SMP_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING +#endif +// btla-specific -- + +/* Define common tracing for all */ +#define LOG_LEVEL_ERROR 1 +#define LOG_LEVEL_WARN 2 +#define LOG_LEVEL_INFO 3 +#define LOG_LEVEL_DEBUG 4 +#define LOG_LEVEL_VERBOSE 5 +#ifndef LOG_LEVEL +#define LOG_LEVEL LOG_LEVEL_INFO +#endif +#define LOG_ERROR(fmt, args...) do {if (LOG_LEVEL >= LOG_LEVEL_ERROR) BT_PRINTF(fmt,## args);} while(0) +#define LOG_WARN(fmt, args...) do {if (LOG_LEVEL >= LOG_LEVEL_WARN) BT_PRINTF(fmt,## args);} while(0) +#define LOG_INFO(fmt, args...) do {if (LOG_LEVEL >= LOG_LEVEL_INFO) BT_PRINTF(fmt,## args);} while(0) +#define LOG_DEBUG(fmt, args...) do {if (LOG_LEVEL >= LOG_LEVEL_DEBUG) BT_PRINTF(fmt,## args);} while(0) +#define LOG_VERBOSE(fmt, args...) do {if (LOG_LEVEL >= LOG_LEVEL_VERBOSE) BT_PRINTF(fmt,## args);} while(0) + +/* Define tracing for the HCI unit +*/ +#define HCI_TRACE_ERROR(fmt, args...) {if (btu_cb.trace_level >= BT_TRACE_LEVEL_ERROR) BT_PRINTF(fmt,## args);} +#define HCI_TRACE_WARNING(fmt, args...) {if (btu_cb.trace_level >= BT_TRACE_LEVEL_WARNING) BT_PRINTF(fmt,## args);} +#define HCI_TRACE_EVENT(fmt, args...) {if (btu_cb.trace_level >= BT_TRACE_LEVEL_EVENT) BT_PRINTF(fmt,## args);} +#define HCI_TRACE_DEBUG(fmt, args...) {if (btu_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) BT_PRINTF(fmt,## args);} + +/* Define tracing for BTM +*/ +#define BTM_TRACE_ERROR(fmt, args...) {if (btm_cb.trace_level >= BT_TRACE_LEVEL_ERROR) BT_PRINTF(fmt, ## args);} +#define BTM_TRACE_WARNING(fmt, args...) {if (btm_cb.trace_level >= BT_TRACE_LEVEL_WARNING) BT_PRINTF(fmt, ## args);} +#define BTM_TRACE_API(fmt, args...) {if (btm_cb.trace_level >= BT_TRACE_LEVEL_API) BT_PRINTF(fmt, ## args);} +#define BTM_TRACE_EVENT(fmt, args...) {if (btm_cb.trace_level >= BT_TRACE_LEVEL_EVENT) BT_PRINTF(fmt, ## args);} +#define BTM_TRACE_DEBUG(fmt, args...) {if (btm_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) BT_PRINTF(fmt, ## args);} + +/* Define tracing for the L2CAP unit +*/ +#define L2CAP_TRACE_ERROR(fmt, args...) {if (l2cb.l2cap_trace_level >= BT_TRACE_LEVEL_ERROR) BT_PRINTF(fmt, ## args);} +#define L2CAP_TRACE_WARNING(fmt, args...) {if (l2cb.l2cap_trace_level >= BT_TRACE_LEVEL_WARNING) BT_PRINTF(fmt, ## args);} +#define L2CAP_TRACE_API(fmt, args...) {if (l2cb.l2cap_trace_level >= BT_TRACE_LEVEL_API) BT_PRINTF(fmt, ## args);} +#define L2CAP_TRACE_EVENT(fmt, args...) {if (l2cb.l2cap_trace_level >= BT_TRACE_LEVEL_EVENT) BT_PRINTF(fmt, ## args);} +#define L2CAP_TRACE_DEBUG(fmt, args...) {if (l2cb.l2cap_trace_level >= BT_TRACE_LEVEL_DEBUG) BT_PRINTF(fmt, ## args);} + +/* Define tracing for the SDP unit +*/ +#define SDP_TRACE_ERROR(fmt, args...) {if (sdp_cb.trace_level >= BT_TRACE_LEVEL_ERROR) BT_PRINTF(fmt, ## args);} +#define SDP_TRACE_WARNING(fmt, args...) {if (sdp_cb.trace_level >= BT_TRACE_LEVEL_WARNING) BT_PRINTF(fmt, ## args);} +#define SDP_TRACE_API(fmt, args...) {if (sdp_cb.trace_level >= BT_TRACE_LEVEL_API) BT_PRINTF(fmt, ## args);} +#define SDP_TRACE_EVENT(fmt, args...) {if (sdp_cb.trace_level >= BT_TRACE_LEVEL_EVENT) BT_PRINTF(fmt, ## args);} +#define SDP_TRACE_DEBUG(fmt, args...) {if (sdp_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) BT_PRINTF(fmt, ## args);} + +/* Define tracing for the RFCOMM unit +*/ +#define RFCOMM_TRACE_ERROR(fmt, args...) {if (rfc_cb.trace_level >= BT_TRACE_LEVEL_ERROR) BT_PRINTF(fmt, ## args);} +#define RFCOMM_TRACE_WARNING(fmt, args...) {if (rfc_cb.trace_level >= BT_TRACE_LEVEL_WARNING) BT_PRINTF(fmt, ## args);} +#define RFCOMM_TRACE_API(fmt, args...) {if (rfc_cb.trace_level >= BT_TRACE_LEVEL_API) BT_PRINTF(fmt, ## args);} +#define RFCOMM_TRACE_EVENT(fmt, args...) {if (rfc_cb.trace_level >= BT_TRACE_LEVEL_EVENT) BT_PRINTF(fmt, ## args);} +#define RFCOMM_TRACE_DEBUG(fmt, args...) {if (rfc_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) BT_PRINTF(fmt, ## args);} + +/* Generic Access Profile traces */ +#define GAP_TRACE_ERROR(fmt, args...) {if (gap_cb.trace_level >= BT_TRACE_LEVEL_ERROR) BT_PRINTF(fmt, ## args);} +#define GAP_TRACE_EVENT(fmt, args...) {if (gap_cb.trace_level >= BT_TRACE_LEVEL_EVENT) BT_PRINTF(fmt, ## args);} +#define GAP_TRACE_API(fmt, args...) {if (gap_cb.trace_level >= BT_TRACE_LEVEL_API) BT_PRINTF(fmt, ## args);} +#define GAP_TRACE_WARNING(fmt, args...) {if (gap_cb.trace_level >= BT_TRACE_LEVEL_WARNING) BT_PRINTF(fmt, ## args);} + +/* define traces for HID Host */ +#define HIDH_TRACE_ERROR(fmt, args...) {if (hh_cb.trace_level >= BT_TRACE_LEVEL_ERROR) BT_PRINTF(fmt, ## args);} +#define HIDH_TRACE_WARNING(fmt, args...) {if (hh_cb.trace_level >= BT_TRACE_LEVEL_WARNING) BT_PRINTF(fmt, ## args);} +#define HIDH_TRACE_API(fmt, args...) {if (hh_cb.trace_level >= BT_TRACE_LEVEL_API) BT_PRINTF(fmt, ## args);} +#define HIDH_TRACE_EVENT(fmt, args...) {if (hh_cb.trace_level >= BT_TRACE_LEVEL_EVENT) BT_PRINTF(fmt, ## args);} +#define HIDH_TRACE_DEBUG(fmt, args...) {if (hh_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) BT_PRINTF(fmt, ## args);} + +/* define traces for BNEP */ + +#define BNEP_TRACE_ERROR(fmt, args...) {if (bnep_cb.trace_level >= BT_TRACE_LEVEL_ERROR) BT_PRINTF(fmt, ## args);} +#define BNEP_TRACE_WARNING(fmt, args...) {if (bnep_cb.trace_level >= BT_TRACE_LEVEL_WARNING) BT_PRINTF(fmt, ## args);} +#define BNEP_TRACE_API(fmt, args...) {if (bnep_cb.trace_level >= BT_TRACE_LEVEL_API) BT_PRINTF(fmt, ## args);} +#define BNEP_TRACE_EVENT(fmt, args...) {if (bnep_cb.trace_level >= BT_TRACE_LEVEL_EVENT) BT_PRINTF(fmt, ## args);} +#define BNEP_TRACE_DEBUG(fmt, args...) {if (bnep_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) BT_PRINTF(fmt, ## args);} + +/* define traces for PAN */ + +#define PAN_TRACE_ERROR(fmt, args...) {if (pan_cb.trace_level >= BT_TRACE_LEVEL_ERROR) BT_PRINTF(fmt, ## args);} +#define PAN_TRACE_WARNING(fmt, args...) {if (pan_cb.trace_level >= BT_TRACE_LEVEL_WARNING) BT_PRINTF(fmt, ## args);} +#define PAN_TRACE_API(fmt, args...) {if (pan_cb.trace_level >= BT_TRACE_LEVEL_API) BT_PRINTF(fmt, ## args);} +#define PAN_TRACE_EVENT(fmt, args...) {if (pan_cb.trace_level >= BT_TRACE_LEVEL_EVENT) BT_PRINTF(fmt, ## args);} +#define PAN_TRACE_DEBUG(fmt, args...) {if (pan_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) BT_PRINTF(fmt, ## args);} + +/* Define tracing for the A2DP profile +*/ +#define A2D_TRACE_ERROR(fmt, args...) {if (a2d_cb.trace_level >= BT_TRACE_LEVEL_ERROR) BT_PRINTF(fmt, ## args);} +#define A2D_TRACE_WARNING(fmt, args...) {if (a2d_cb.trace_level >= BT_TRACE_LEVEL_WARNING) BT_PRINTF(fmt, ## args);} +#define A2D_TRACE_EVENT(fmt, args...) {if (a2d_cb.trace_level >= BT_TRACE_LEVEL_EVENT) BT_PRINTF(fmt, ## args);} +#define A2D_TRACE_DEBUG(fmt, args...) {if (a2d_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) BT_PRINTF(fmt, ## args);} +#define A2D_TRACE_API(fmt, args...) {if (a2d_cb.trace_level >= BT_TRACE_LEVEL_API) BT_PRINTF(fmt, ## args);} + +/* AVDTP +*/ +#define AVDT_TRACE_ERROR(fmt, args...) {if (avdt_cb.trace_level >= BT_TRACE_LEVEL_ERROR) BT_PRINTF(fmt, ## args);} +#define AVDT_TRACE_WARNING(fmt, args...) {if (avdt_cb.trace_level >= BT_TRACE_LEVEL_WARNING) BT_PRINTF(fmt, ## args);} +#define AVDT_TRACE_EVENT(fmt, args...) {if (avdt_cb.trace_level >= BT_TRACE_LEVEL_EVENT) BT_PRINTF(fmt, ## args);} +#define AVDT_TRACE_DEBUG(fmt, args...) {if (avdt_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) BT_PRINTF(fmt, ## args);} +#define AVDT_TRACE_API(fmt, args...) {if (avdt_cb.trace_level >= BT_TRACE_LEVEL_API) BT_PRINTF(fmt, ## args);} + +/* Define tracing for the AVCTP protocol +*/ +#define AVCT_TRACE_ERROR(fmt, args...) {if (avct_cb.trace_level >= BT_TRACE_LEVEL_ERROR) BT_PRINTF(fmt, ## args);} +#define AVCT_TRACE_WARNING(fmt, args...) {if (avct_cb.trace_level >= BT_TRACE_LEVEL_WARNING) BT_PRINTF(fmt, ## args);} +#define AVCT_TRACE_EVENT(fmt, args...) {if (avct_cb.trace_level >= BT_TRACE_LEVEL_EVENT) BT_PRINTF(fmt, ## args);} +#define AVCT_TRACE_DEBUG(fmt, args...) {if (avct_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) BT_PRINTF(fmt, ## args);} +#define AVCT_TRACE_API(fmt, args...) {if (avct_cb.trace_level >= BT_TRACE_LEVEL_API) BT_PRINTF(fmt, ## args);} + +/* Define tracing for the AVRCP profile +*/ +#define AVRC_TRACE_ERROR(fmt, args...) {if (avrc_cb.trace_level >= BT_TRACE_LEVEL_ERROR) BT_PRINTF(fmt, ## args);} +#define AVRC_TRACE_WARNING(fmt, args...) {if (avrc_cb.trace_level >= BT_TRACE_LEVEL_WARNING) BT_PRINTF(fmt, ## args);} +#define AVRC_TRACE_EVENT(fmt, args...) {if (avrc_cb.trace_level >= BT_TRACE_LEVEL_EVENT) BT_PRINTF(fmt, ## args);} +#define AVRC_TRACE_DEBUG(fmt, args...) {if (avrc_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) BT_PRINTF(fmt, ## args);} +#define AVRC_TRACE_API(fmt, args...) {if (avrc_cb.trace_level >= BT_TRACE_LEVEL_API) BT_PRINTF(fmt, ## args);} + +/* MCAP +*/ +#define MCA_TRACE_ERROR(fmt, args...) {if (mca_cb.trace_level >= BT_TRACE_LEVEL_ERROR) BT_PRINTF(fmt, ## args);} +#define MCA_TRACE_WARNING(fmt, args...) {if (mca_cb.trace_level >= BT_TRACE_LEVEL_WARNING) BT_PRINTF(fmt, ## args);} +#define MCA_TRACE_EVENT(fmt, args...) {if (mca_cb.trace_level >= BT_TRACE_LEVEL_EVENT) BT_PRINTF(fmt, ## args);} +#define MCA_TRACE_DEBUG(fmt, args...) {if (mca_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) BT_PRINTF(fmt, ## args);} +#define MCA_TRACE_API(fmt, args...) {if (mca_cb.trace_level >= BT_TRACE_LEVEL_API) BT_PRINTF(fmt, ## args);} + +/* Define tracing for the ATT/GATT unit +*/ +#define GATT_TRACE_ERROR(fmt, args...) {if (gatt_cb.trace_level >= BT_TRACE_LEVEL_ERROR) BT_PRINTF(fmt, ## args);} +#define GATT_TRACE_WARNING(fmt, args...) {if (gatt_cb.trace_level >= BT_TRACE_LEVEL_WARNING) BT_PRINTF(fmt, ## args);} +#define GATT_TRACE_API(fmt, args...) {if (gatt_cb.trace_level >= BT_TRACE_LEVEL_API) BT_PRINTF(fmt, ## args);} +#define GATT_TRACE_EVENT(fmt, args...) {if (gatt_cb.trace_level >= BT_TRACE_LEVEL_EVENT) BT_PRINTF(fmt, ## args);} +#define GATT_TRACE_DEBUG(fmt, args...) {if (gatt_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) BT_PRINTF(fmt, ## args);} + +/* Define tracing for the SMP unit +*/ +#define SMP_TRACE_ERROR(fmt, args...) {if (smp_cb.trace_level >= BT_TRACE_LEVEL_ERROR) BT_PRINTF(fmt, ## args);} +#define SMP_TRACE_WARNING(fmt, args...) {if (smp_cb.trace_level >= BT_TRACE_LEVEL_WARNING) BT_PRINTF(fmt, ## args);} +#define SMP_TRACE_API(fmt, args...) {if (smp_cb.trace_level >= BT_TRACE_LEVEL_API) BT_PRINTF(fmt, ## args);} +#define SMP_TRACE_EVENT(fmt, args...) {if (smp_cb.trace_level >= BT_TRACE_LEVEL_EVENT) BT_PRINTF(fmt, ## args);} +#define SMP_TRACE_DEBUG(fmt, args...) {if (smp_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) BT_PRINTF(fmt, ## args);} + +extern UINT8 btif_trace_level; + +// define traces for application +#define BTIF_TRACE_ERROR(fmt, args...) {if (btif_trace_level >= BT_TRACE_LEVEL_ERROR) BT_PRINTF(fmt, ## args);} +#define BTIF_TRACE_WARNING(fmt, args...) {if (btif_trace_level >= BT_TRACE_LEVEL_WARNING) BT_PRINTF(fmt, ## args);} +#define BTIF_TRACE_API(fmt, args...) {if (btif_trace_level >= BT_TRACE_LEVEL_API) BT_PRINTF(fmt, ## args);} +#define BTIF_TRACE_EVENT(fmt, args...) {if (btif_trace_level >= BT_TRACE_LEVEL_EVENT) BT_PRINTF(fmt, ## args);} +#define BTIF_TRACE_DEBUG(fmt, args...) {if (btif_trace_level >= BT_TRACE_LEVEL_DEBUG) BT_PRINTF(fmt, ## args);} +#define BTIF_TRACE_VERBOSE(fmt, args...) {if (btif_trace_level >= BT_TRACE_LEVEL_VERBOSE)BT_PRINTF(fmt, ## args);} + +/* define traces for application */ + +#define APPL_TRACE_ERROR(fmt, args...) {if (appl_trace_level >= BT_TRACE_LEVEL_ERROR) BT_PRINTF(fmt, ## args);} +#define APPL_TRACE_WARNING(fmt, args...) {if (appl_trace_level >= BT_TRACE_LEVEL_WARNING) BT_PRINTF(fmt, ## args);} +#define APPL_TRACE_API(fmt, args...) {if (appl_trace_level >= BT_TRACE_LEVEL_API) BT_PRINTF(fmt, ## args);} +#define APPL_TRACE_EVENT(fmt, args...) {if (appl_trace_level >= BT_TRACE_LEVEL_EVENT) BT_PRINTF(fmt, ## args);} +#define APPL_TRACE_DEBUG(fmt, args...) {if (appl_trace_level >= BT_TRACE_LEVEL_DEBUG) BT_PRINTF(fmt, ## args);} +#define APPL_TRACE_VERBOSE(fmt, args...) {if (appl_trace_level >= BT_TRACE_LEVEL_VERBOSE) BT_PRINTF(fmt, ## args);} + +/* Simplified Trace Helper Macro +*/ +#define bdld(fmt, args...) \ + do{\ + if((MY_LOG_LEVEL) >= BT_TRACE_LEVEL_DEBUG) \ + BT_PRINTF(fmt, ## args); \ + }while(0) + +#define bdlw(fmt, args...) \ + do{\ + if((MY_LOG_LEVEL) >= BT_TRACE_LEVEL_DEBUG) \ + BT_PRINTF(fmt, ## args); \ + }while(0) + +#define bdle(fmt, args...) \ + do{\ + if((MY_LOG_LEVEL) >= BT_TRACE_LEVEL_DEBUG) \ + BT_PRINTF(fmt, ## args); \ + }while(0) + +#define bdla(assert_if) \ + do{\ + if(((MY_LOG_LEVEL) >= BT_TRACE_LEVEL_ERROR) && !(assert_if)) \ + BT_PRINTF("%s: assert failed\n", #assert_if); \ + }while(0) + +typedef UINT8 tBTTRC_PARAM_TYPE; +typedef UINT8 tBTTRC_LAYER_ID; +typedef UINT8 tBTTRC_TYPE; + +typedef struct { + tBTTRC_LAYER_ID layer_id; + tBTTRC_TYPE type; /* TODO: use tBTTRC_TYPE instead of "classical level 0-5" */ +} tBTTRC_LEVEL; + +typedef UINT8 (tBTTRC_SET_TRACE_LEVEL)( UINT8 ); + +typedef struct { + const tBTTRC_LAYER_ID layer_id_start; + const tBTTRC_LAYER_ID layer_id_end; + tBTTRC_SET_TRACE_LEVEL *p_f; + const char *trc_name; + UINT8 trace_level; +} tBTTRC_FUNC_MAP; + +/* External declaration for appl_trace_level here to avoid to add the declaration in all the files using APPL_TRACExxx macros */ +extern UINT8 appl_trace_level; + +#endif /*_BT_TRACE_H_*/ diff --git a/tools/sdk/include/bluedroid/bt_types.h b/tools/sdk/include/bluedroid/bt_types.h new file mode 100644 index 00000000..f2110150 --- /dev/null +++ b/tools/sdk/include/bluedroid/bt_types.h @@ -0,0 +1,789 @@ +/****************************************************************************** + * + * Copyright (C) 1999-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. + * + ******************************************************************************/ + +#ifndef BT_TYPES_H +#define BT_TYPES_H + +#include +#include + +#ifndef FALSE +# define FALSE false +#endif + +#ifndef TRUE +# define TRUE true +#endif + +typedef uint8_t UINT8; +typedef uint16_t UINT16; +typedef uint32_t UINT32; +typedef uint64_t UINT64; + +typedef int8_t INT8; +typedef int16_t INT16; +typedef int32_t INT32; +typedef bool BOOLEAN; + +#define PACKED __packed +#define INLINE __inline + +#define BCM_STRCPY_S(x1,x2,x3) strcpy((x1),(x3)) +#define BCM_STRNCPY_S(x1,x2,x3,x4) strncpy((x1),(x3),(x4)) + +/* READ WELL !! +** +** This section defines global events. These are events that cross layers. +** Any event that passes between layers MUST be one of these events. Tasks +** can use their own events internally, but a FUNDAMENTAL design issue is +** that global events MUST be one of these events defined below. +** +** The convention used is the the event name contains the layer that the +** event is going to. +*/ +#define BT_EVT_MASK 0xFF00 +#define BT_SUB_EVT_MASK 0x00FF +/* To Bluetooth Upper Layers */ +/************************************/ +#define BT_EVT_TO_BTU_L2C_EVT 0x0900 /* L2CAP event */ +#define BT_EVT_TO_BTU_HCI_EVT 0x1000 /* HCI Event */ +#define BT_EVT_TO_BTU_HCI_BR_EDR_EVT (0x0000 | BT_EVT_TO_BTU_HCI_EVT) /* event from BR/EDR controller */ +#define BT_EVT_TO_BTU_HCI_AMP1_EVT (0x0001 | BT_EVT_TO_BTU_HCI_EVT) /* event from local AMP 1 controller */ +#define BT_EVT_TO_BTU_HCI_AMP2_EVT (0x0002 | BT_EVT_TO_BTU_HCI_EVT) /* event from local AMP 2 controller */ +#define BT_EVT_TO_BTU_HCI_AMP3_EVT (0x0003 | BT_EVT_TO_BTU_HCI_EVT) /* event from local AMP 3 controller */ + +#define BT_EVT_TO_BTU_HCI_ACL 0x1100 /* ACL Data from HCI */ +#define BT_EVT_TO_BTU_HCI_SCO 0x1200 /* SCO Data from HCI */ +#define BT_EVT_TO_BTU_HCIT_ERR 0x1300 /* HCI Transport Error */ + +#define BT_EVT_TO_BTU_SP_EVT 0x1400 /* Serial Port Event */ +#define BT_EVT_TO_BTU_SP_DATA 0x1500 /* Serial Port Data */ + +#define BT_EVT_TO_BTU_HCI_CMD 0x1600 /* HCI command from upper layer */ + + +#define BT_EVT_TO_BTU_L2C_SEG_XMIT 0x1900 /* L2CAP segment(s) transmitted */ + +#define BT_EVT_PROXY_INCOMING_MSG 0x1A00 /* BlueStackTester event: incoming message from target */ + +#define BT_EVT_BTSIM 0x1B00 /* Insight BTSIM event */ +#define BT_EVT_BTISE 0x1C00 /* Insight Script Engine event */ + +/* To LM */ +/************************************/ +#define BT_EVT_TO_LM_HCI_CMD 0x2000 /* HCI Command */ +#define BT_EVT_TO_LM_HCI_ACL 0x2100 /* HCI ACL Data */ +#define BT_EVT_TO_LM_HCI_SCO 0x2200 /* HCI SCO Data */ +#define BT_EVT_TO_LM_HCIT_ERR 0x2300 /* HCI Transport Error */ +#define BT_EVT_TO_LM_LC_EVT 0x2400 /* LC event */ +#define BT_EVT_TO_LM_LC_LMP 0x2500 /* LC Received LMP command frame */ +#define BT_EVT_TO_LM_LC_ACL 0x2600 /* LC Received ACL data */ +#define BT_EVT_TO_LM_LC_SCO 0x2700 /* LC Received SCO data (not used) */ +#define BT_EVT_TO_LM_LC_ACL_TX 0x2800 /* LMP data transmit complete */ +#define BT_EVT_TO_LM_LC_LMPC_TX 0x2900 /* LMP Command transmit complete */ +#define BT_EVT_TO_LM_LOCAL_ACL_LB 0x2a00 /* Data to be locally loopbacked */ +#define BT_EVT_TO_LM_HCI_ACL_ACK 0x2b00 /* HCI ACL Data ack (not used) */ +#define BT_EVT_TO_LM_DIAG 0x2c00 /* LM Diagnostics commands */ + + +#define BT_EVT_TO_BTM_CMDS 0x2f00 +#define BT_EVT_TO_BTM_PM_MDCHG_EVT (0x0001 | BT_EVT_TO_BTM_CMDS) + +#define BT_EVT_TO_TCS_CMDS 0x3000 + +#define BT_EVT_TO_CTP_CMDS 0x3300 + +/* ftp events */ +#define BT_EVT_TO_FTP_SRVR_CMDS 0x3600 +#define BT_EVT_TO_FTP_CLNT_CMDS 0x3700 + +#define BT_EVT_TO_BTU_SAP 0x3800 /* SIM Access Profile events */ + +/* opp events */ +#define BT_EVT_TO_OPP_SRVR_CMDS 0x3900 +#define BT_EVT_TO_OPP_CLNT_CMDS 0x3a00 + +/* gap events */ +#define BT_EVT_TO_GAP_MSG 0x3b00 + +/* for NFC */ +/************************************/ +#define BT_EVT_TO_NFC_NCI 0x4000 /* NCI Command, Notification or Data*/ +#define BT_EVT_TO_NFC_INIT 0x4100 /* Initialization message */ +#define BT_EVT_TO_NCI_LP 0x4200 /* Low power */ +#define BT_EVT_TO_NFC_ERR 0x4300 /* Error notification to NFC Task */ + +#define BT_EVT_TO_NFCCSIM_NCI 0x4a00 /* events to NFCC simulation (NCI packets) */ + +/* HCISU Events */ + +#define BT_EVT_HCISU 0x5000 + +// btla-specific ++ +#define BT_EVT_TO_HCISU_RECONFIG_EVT (0x0001 | BT_EVT_HCISU) +#define BT_EVT_TO_HCISU_UPDATE_BAUDRATE_EVT (0x0002 | BT_EVT_HCISU) +#define BT_EVT_TO_HCISU_LP_ENABLE_EVT (0x0003 | BT_EVT_HCISU) +#define BT_EVT_TO_HCISU_LP_DISABLE_EVT (0x0004 | BT_EVT_HCISU) +// btla-specific -- +#define BT_EVT_TO_HCISU_LP_APP_SLEEPING_EVT (0x0005 | BT_EVT_HCISU) +#define BT_EVT_TO_HCISU_LP_ALLOW_BT_SLEEP_EVT (0x0006 | BT_EVT_HCISU) +#define BT_EVT_TO_HCISU_LP_WAKEUP_HOST_EVT (0x0007 | BT_EVT_HCISU) +#define BT_EVT_TO_HCISU_LP_RCV_H4IBSS_EVT (0x0008 | BT_EVT_HCISU) +#define BT_EVT_TO_HCISU_H5_RESET_EVT (0x0009 | BT_EVT_HCISU) +#define BT_EVT_HCISU_START_QUICK_TIMER (0x000a | BT_EVT_HCISU) + +#define BT_EVT_DATA_TO_AMP_1 0x5100 +#define BT_EVT_DATA_TO_AMP_15 0x5f00 + +/* HSP Events */ + +#define BT_EVT_BTU_HSP2 0x6000 + +#define BT_EVT_TO_BTU_HSP2_EVT (0x0001 | BT_EVT_BTU_HSP2) + +/* BPP Events */ +#define BT_EVT_TO_BPP_PR_CMDS 0x6100 /* Printer Events */ +#define BT_EVT_TO_BPP_SND_CMDS 0x6200 /* BPP Sender Events */ + +/* BIP Events */ +#define BT_EVT_TO_BIP_CMDS 0x6300 + +/* HCRP Events */ + +#define BT_EVT_BTU_HCRP 0x7000 + +#define BT_EVT_TO_BTU_HCRP_EVT (0x0001 | BT_EVT_BTU_HCRP) +#define BT_EVT_TO_BTU_HCRPM_EVT (0x0002 | BT_EVT_BTU_HCRP) + + +#define BT_EVT_BTU_HFP 0x8000 +#define BT_EVT_TO_BTU_HFP_EVT (0x0001 | BT_EVT_BTU_HFP) + +#define BT_EVT_BTU_IPC_EVT 0x9000 +#define BT_EVT_BTU_IPC_LOGMSG_EVT (0x0000 | BT_EVT_BTU_IPC_EVT) +#define BT_EVT_BTU_IPC_ACL_EVT (0x0001 | BT_EVT_BTU_IPC_EVT) +#define BT_EVT_BTU_IPC_BTU_EVT (0x0002 | BT_EVT_BTU_IPC_EVT) +#define BT_EVT_BTU_IPC_L2C_EVT (0x0003 | BT_EVT_BTU_IPC_EVT) +#define BT_EVT_BTU_IPC_L2C_MSG_EVT (0x0004 | BT_EVT_BTU_IPC_EVT) +#define BT_EVT_BTU_IPC_BTM_EVT (0x0005 | BT_EVT_BTU_IPC_EVT) +#define BT_EVT_BTU_IPC_AVDT_EVT (0x0006 | BT_EVT_BTU_IPC_EVT) +#define BT_EVT_BTU_IPC_SLIP_EVT (0x0007 | BT_EVT_BTU_IPC_EVT) +#define BT_EVT_BTU_IPC_MGMT_EVT (0x0008 | BT_EVT_BTU_IPC_EVT) +#define BT_EVT_BTU_IPC_BTTRC_EVT (0x0009 | BT_EVT_BTU_IPC_EVT) +#define BT_EVT_BTU_IPC_BURST_EVT (0x000A | BT_EVT_BTU_IPC_EVT) + + +/* BTIF Events */ +#define BT_EVT_BTIF 0xA000 +#define BT_EVT_CONTEXT_SWITCH_EVT (0x0001 | BT_EVT_BTIF) + +/* Define the header of each buffer used in the Bluetooth stack. +*/ +typedef struct { + uint16_t event; + uint16_t len; + uint16_t offset; + uint16_t layer_specific; + uint8_t data[]; +} BT_HDR; + +#define BT_HDR_SIZE (sizeof (BT_HDR)) + +#define BT_PSM_SDP 0x0001 +#define BT_PSM_RFCOMM 0x0003 +#define BT_PSM_TCS 0x0005 +#define BT_PSM_CTP 0x0007 +#define BT_PSM_BNEP 0x000F +#define BT_PSM_HIDC 0x0011 +#define BT_PSM_HIDI 0x0013 +#define BT_PSM_UPNP 0x0015 +#define BT_PSM_AVCTP 0x0017 +#define BT_PSM_AVDTP 0x0019 +#define BT_PSM_AVCTP_13 0x001B /* Advanced Control - Browsing */ +#define BT_PSM_UDI_CP 0x001D /* Unrestricted Digital Information Profile C-Plane */ +#define BT_PSM_ATT 0x001F /* Attribute Protocol */ + + +/* These macros extract the HCI opcodes from a buffer +*/ +#define HCI_GET_CMD_HDR_OPCODE(p) (UINT16)((*((UINT8 *)((p) + 1) + p->offset) + \ + (*((UINT8 *)((p) + 1) + p->offset + 1) << 8))) +#define HCI_GET_CMD_HDR_PARAM_LEN(p) (UINT8) (*((UINT8 *)((p) + 1) + p->offset + 2)) + +#define HCI_GET_EVT_HDR_OPCODE(p) (UINT8)(*((UINT8 *)((p) + 1) + p->offset)) +#define HCI_GET_EVT_HDR_PARAM_LEN(p) (UINT8) (*((UINT8 *)((p) + 1) + p->offset + 1)) + + +/******************************************************************************** +** Macros to get and put bytes to and from a stream (Little Endian format). +*/ +#define UINT32_TO_STREAM(p, u32) {*(p)++ = (UINT8)(u32); *(p)++ = (UINT8)((u32) >> 8); *(p)++ = (UINT8)((u32) >> 16); *(p)++ = (UINT8)((u32) >> 24);} +#define UINT24_TO_STREAM(p, u24) {*(p)++ = (UINT8)(u24); *(p)++ = (UINT8)((u24) >> 8); *(p)++ = (UINT8)((u24) >> 16);} +#define UINT16_TO_STREAM(p, u16) {*(p)++ = (UINT8)(u16); *(p)++ = (UINT8)((u16) >> 8);} +#define UINT8_TO_STREAM(p, u8) {*(p)++ = (UINT8)(u8);} +#define INT8_TO_STREAM(p, u8) {*(p)++ = (INT8)(u8);} +#define ARRAY32_TO_STREAM(p, a) {register int ijk; for (ijk = 0; ijk < 32; ijk++) *(p)++ = (UINT8) a[31 - ijk];} +#define ARRAY16_TO_STREAM(p, a) {register int ijk; for (ijk = 0; ijk < 16; ijk++) *(p)++ = (UINT8) a[15 - ijk];} +#define ARRAY8_TO_STREAM(p, a) {register int ijk; for (ijk = 0; ijk < 8; ijk++) *(p)++ = (UINT8) a[7 - ijk];} +#define BDADDR_TO_STREAM(p, a) {register int ijk; for (ijk = 0; ijk < BD_ADDR_LEN; ijk++) *(p)++ = (UINT8) a[BD_ADDR_LEN - 1 - ijk];} +#define LAP_TO_STREAM(p, a) {register int ijk; for (ijk = 0; ijk < LAP_LEN; ijk++) *(p)++ = (UINT8) a[LAP_LEN - 1 - ijk];} +#define DEVCLASS_TO_STREAM(p, a) {register int ijk; for (ijk = 0; ijk < DEV_CLASS_LEN;ijk++) *(p)++ = (UINT8) a[DEV_CLASS_LEN - 1 - ijk];} +#define ARRAY_TO_STREAM(p, a, len) {register int ijk; for (ijk = 0; ijk < len; ijk++) *(p)++ = (UINT8) a[ijk];} +#define REVERSE_ARRAY_TO_STREAM(p, a, len) {register int ijk; for (ijk = 0; ijk < len; ijk++) *(p)++ = (UINT8) a[len - 1 - ijk];} + +#define STREAM_TO_UINT8(u8, p) {u8 = (UINT8)(*(p)); (p) += 1;} +#define STREAM_TO_UINT16(u16, p) {u16 = ((UINT16)(*(p)) + (((UINT16)(*((p) + 1))) << 8)); (p) += 2;} +#define STREAM_TO_UINT24(u32, p) {u32 = (((UINT32)(*(p))) + ((((UINT32)(*((p) + 1)))) << 8) + ((((UINT32)(*((p) + 2)))) << 16) ); (p) += 3;} +#define STREAM_TO_UINT32(u32, p) {u32 = (((UINT32)(*(p))) + ((((UINT32)(*((p) + 1)))) << 8) + ((((UINT32)(*((p) + 2)))) << 16) + ((((UINT32)(*((p) + 3)))) << 24)); (p) += 4;} +#define STREAM_TO_BDADDR(a, p) {register int ijk; register UINT8 *pbda = (UINT8 *)a + BD_ADDR_LEN - 1; for (ijk = 0; ijk < BD_ADDR_LEN; ijk++) *pbda-- = *p++;} +#define STREAM_TO_ARRAY32(a, p) {register int ijk; register UINT8 *_pa = (UINT8 *)a + 31; for (ijk = 0; ijk < 32; ijk++) *_pa-- = *p++;} +#define STREAM_TO_ARRAY16(a, p) {register int ijk; register UINT8 *_pa = (UINT8 *)a + 15; for (ijk = 0; ijk < 16; ijk++) *_pa-- = *p++;} +#define STREAM_TO_ARRAY8(a, p) {register int ijk; register UINT8 *_pa = (UINT8 *)a + 7; for (ijk = 0; ijk < 8; ijk++) *_pa-- = *p++;} +#define STREAM_TO_DEVCLASS(a, p) {register int ijk; register UINT8 *_pa = (UINT8 *)a + DEV_CLASS_LEN - 1; for (ijk = 0; ijk < DEV_CLASS_LEN; ijk++) *_pa-- = *p++;} +#define STREAM_TO_LAP(a, p) {register int ijk; register UINT8 *plap = (UINT8 *)a + LAP_LEN - 1; for (ijk = 0; ijk < LAP_LEN; ijk++) *plap-- = *p++;} +#define STREAM_TO_ARRAY(a, p, len) {register int ijk; for (ijk = 0; ijk < len; ijk++) ((UINT8 *) a)[ijk] = *p++;} +#define REVERSE_STREAM_TO_ARRAY(a, p, len) {register int ijk; register UINT8 *_pa = (UINT8 *)a + len - 1; for (ijk = 0; ijk < len; ijk++) *_pa-- = *p++;} + +#define STREAM_SKIP_UINT8(p) do { (p) += 1; } while (0) +#define STREAM_SKIP_UINT16(p) do { (p) += 2; } while (0) + +/******************************************************************************** +** Macros to get and put bytes to and from a field (Little Endian format). +** These are the same as to stream, except the pointer is not incremented. +*/ +#define UINT32_TO_FIELD(p, u32) {*(UINT8 *)(p) = (UINT8)(u32); *((UINT8 *)(p)+1) = (UINT8)((u32) >> 8); *((UINT8 *)(p)+2) = (UINT8)((u32) >> 16); *((UINT8 *)(p)+3) = (UINT8)((u32) >> 24);} +#define UINT24_TO_FIELD(p, u24) {*(UINT8 *)(p) = (UINT8)(u24); *((UINT8 *)(p)+1) = (UINT8)((u24) >> 8); *((UINT8 *)(p)+2) = (UINT8)((u24) >> 16);} +#define UINT16_TO_FIELD(p, u16) {*(UINT8 *)(p) = (UINT8)(u16); *((UINT8 *)(p)+1) = (UINT8)((u16) >> 8);} +#define UINT8_TO_FIELD(p, u8) {*(UINT8 *)(p) = (UINT8)(u8);} + + +/******************************************************************************** +** Macros to get and put bytes to and from a stream (Big Endian format) +*/ +#define UINT32_TO_BE_STREAM(p, u32) {*(p)++ = (UINT8)((u32) >> 24); *(p)++ = (UINT8)((u32) >> 16); *(p)++ = (UINT8)((u32) >> 8); *(p)++ = (UINT8)(u32); } +#define UINT24_TO_BE_STREAM(p, u24) {*(p)++ = (UINT8)((u24) >> 16); *(p)++ = (UINT8)((u24) >> 8); *(p)++ = (UINT8)(u24);} +#define UINT16_TO_BE_STREAM(p, u16) {*(p)++ = (UINT8)((u16) >> 8); *(p)++ = (UINT8)(u16);} +#define UINT8_TO_BE_STREAM(p, u8) {*(p)++ = (UINT8)(u8);} +#define ARRAY_TO_BE_STREAM(p, a, len) {register int ijk; for (ijk = 0; ijk < len; ijk++) *(p)++ = (UINT8) a[ijk];} +#define ARRAY_TO_BE_STREAM_REVERSE(p, a, len) {register int ijk; for (ijk = 0; ijk < len; ijk++) *(p)++ = (UINT8) a[len - ijk - 1];} + +#define BE_STREAM_TO_UINT8(u8, p) {u8 = (UINT8)(*(p)); (p) += 1;} +#define BE_STREAM_TO_UINT16(u16, p) {u16 = (UINT16)(((UINT16)(*(p)) << 8) + (UINT16)(*((p) + 1))); (p) += 2;} +#define BE_STREAM_TO_UINT24(u32, p) {u32 = (((UINT32)(*((p) + 2))) + ((UINT32)(*((p) + 1)) << 8) + ((UINT32)(*(p)) << 16)); (p) += 3;} +#define BE_STREAM_TO_UINT32(u32, p) {u32 = ((UINT32)(*((p) + 3)) + ((UINT32)(*((p) + 2)) << 8) + ((UINT32)(*((p) + 1)) << 16) + ((UINT32)(*(p)) << 24)); (p) += 4;} +#define BE_STREAM_TO_ARRAY(p, a, len) {register int ijk; for (ijk = 0; ijk < len; ijk++) ((UINT8 *) a)[ijk] = *p++;} + + +/******************************************************************************** +** Macros to get and put bytes to and from a field (Big Endian format). +** These are the same as to stream, except the pointer is not incremented. +*/ +#define UINT32_TO_BE_FIELD(p, u32) {*(UINT8 *)(p) = (UINT8)((u32) >> 24); *((UINT8 *)(p)+1) = (UINT8)((u32) >> 16); *((UINT8 *)(p)+2) = (UINT8)((u32) >> 8); *((UINT8 *)(p)+3) = (UINT8)(u32); } +#define UINT24_TO_BE_FIELD(p, u24) {*(UINT8 *)(p) = (UINT8)((u24) >> 16); *((UINT8 *)(p)+1) = (UINT8)((u24) >> 8); *((UINT8 *)(p)+2) = (UINT8)(u24);} +#define UINT16_TO_BE_FIELD(p, u16) {*(UINT8 *)(p) = (UINT8)((u16) >> 8); *((UINT8 *)(p)+1) = (UINT8)(u16);} +#define UINT8_TO_BE_FIELD(p, u8) {*(UINT8 *)(p) = (UINT8)(u8);} + + +/* Common Bluetooth field definitions */ +#define BD_ADDR_LEN 6 /* Device address length */ +typedef UINT8 BD_ADDR[BD_ADDR_LEN]; /* Device address */ +typedef UINT8 *BD_ADDR_PTR; /* Pointer to Device Address */ + +#define AMP_KEY_TYPE_GAMP 0 +#define AMP_KEY_TYPE_WIFI 1 +#define AMP_KEY_TYPE_UWB 2 +typedef UINT8 tAMP_KEY_TYPE; + +#define BT_OCTET8_LEN 8 +typedef UINT8 BT_OCTET8[BT_OCTET8_LEN]; /* octet array: size 16 */ + +#define LINK_KEY_LEN 16 +typedef UINT8 LINK_KEY[LINK_KEY_LEN]; /* Link Key */ + +#define AMP_LINK_KEY_LEN 32 +typedef UINT8 AMP_LINK_KEY[AMP_LINK_KEY_LEN]; /* Dedicated AMP and GAMP Link Keys */ + +#define BT_OCTET16_LEN 16 +typedef UINT8 BT_OCTET16[BT_OCTET16_LEN]; /* octet array: size 16 */ + +#define PIN_CODE_LEN 16 +typedef UINT8 PIN_CODE[PIN_CODE_LEN]; /* Pin Code (upto 128 bits) MSB is 0 */ +typedef UINT8 *PIN_CODE_PTR; /* Pointer to Pin Code */ + +#define BT_OCTET32_LEN 32 +typedef UINT8 BT_OCTET32[BT_OCTET32_LEN]; /* octet array: size 32 */ + +#define DEV_CLASS_LEN 3 +typedef UINT8 DEV_CLASS[DEV_CLASS_LEN]; /* Device class */ +typedef UINT8 *DEV_CLASS_PTR; /* Pointer to Device class */ + +#define EXT_INQ_RESP_LEN 3 +typedef UINT8 EXT_INQ_RESP[EXT_INQ_RESP_LEN];/* Extended Inquiry Response */ +typedef UINT8 *EXT_INQ_RESP_PTR; /* Pointer to Extended Inquiry Response */ + +#define BD_NAME_LEN 248 +typedef UINT8 BD_NAME[BD_NAME_LEN + 1]; /* Device name */ +typedef UINT8 *BD_NAME_PTR; /* Pointer to Device name */ + +#define BD_FEATURES_LEN 8 +typedef UINT8 BD_FEATURES[BD_FEATURES_LEN]; /* LMP features supported by device */ + +#define BT_EVENT_MASK_LEN 8 +typedef UINT8 BT_EVENT_MASK[BT_EVENT_MASK_LEN]; /* Event Mask */ + +#define LAP_LEN 3 +typedef UINT8 LAP[LAP_LEN]; /* IAC as passed to Inquiry (LAP) */ +typedef UINT8 INQ_LAP[LAP_LEN]; /* IAC as passed to Inquiry (LAP) */ + +#define RAND_NUM_LEN 16 +typedef UINT8 RAND_NUM[RAND_NUM_LEN]; + +#define ACO_LEN 12 +typedef UINT8 ACO[ACO_LEN]; /* Authenticated ciphering offset */ + +#define COF_LEN 12 +typedef UINT8 COF[COF_LEN]; /* ciphering offset number */ + +typedef struct { + UINT8 qos_flags; /* TBD */ + UINT8 service_type; /* see below */ + UINT32 token_rate; /* bytes/second */ + UINT32 token_bucket_size; /* bytes */ + UINT32 peak_bandwidth; /* bytes/second */ + UINT32 latency; /* microseconds */ + UINT32 delay_variation; /* microseconds */ +} FLOW_SPEC; + +/* Values for service_type */ +#define NO_TRAFFIC 0 +#define BEST_EFFORT 1 +#define GUARANTEED 2 + +/* Service class of the CoD */ +#define SERV_CLASS_NETWORKING (1 << 1) +#define SERV_CLASS_RENDERING (1 << 2) +#define SERV_CLASS_CAPTURING (1 << 3) +#define SERV_CLASS_OBJECT_TRANSFER (1 << 4) +#define SERV_CLASS_OBJECT_AUDIO (1 << 5) +#define SERV_CLASS_OBJECT_TELEPHONY (1 << 6) +#define SERV_CLASS_OBJECT_INFORMATION (1 << 7) + +/* Second byte */ +#define SERV_CLASS_LIMITED_DISC_MODE (0x20) + +/* Field size definitions. Note that byte lengths are rounded up. */ +#define ACCESS_CODE_BIT_LEN 72 +#define ACCESS_CODE_BYTE_LEN 9 +#define SHORTENED_ACCESS_CODE_BIT_LEN 68 + +typedef UINT8 ACCESS_CODE[ACCESS_CODE_BYTE_LEN]; + +#define SYNTH_TX 1 /* want synth code to TRANSMIT at this freq */ +#define SYNTH_RX 2 /* want synth code to RECEIVE at this freq */ + +#define SYNC_REPS 1 /* repeats of sync word transmitted to start of burst */ + +/* Bluetooth CLK27 */ +#define BT_CLK27 (2 << 26) + +/* Bluetooth CLK12 is 1.28 sec */ +#define BT_CLK12_TO_MS(x) ((x) * 1280) +#define BT_MS_TO_CLK12(x) ((x) / 1280) +#define BT_CLK12_TO_SLOTS(x) ((x) << 11) + +/* Bluetooth CLK is 0.625 msec */ +#define BT_CLK_TO_MS(x) (((x) * 5 + 3) / 8) +#define BT_MS_TO_CLK(x) (((x) * 8 + 2) / 5) + +#define BT_CLK_TO_MICROSECS(x) (((x) * 5000 + 3) / 8) +#define BT_MICROSECS_TO_CLK(x) (((x) * 8 + 2499) / 5000) + +/* Maximum UUID size - 16 bytes, and structure to hold any type of UUID. */ +#define MAX_UUID_SIZE 16 +typedef struct { +#define LEN_UUID_16 2 +#define LEN_UUID_32 4 +#define LEN_UUID_128 16 + + UINT16 len; + + union { + UINT16 uuid16; + UINT32 uuid32; + UINT8 uuid128[MAX_UUID_SIZE]; + } uu; + +} tBT_UUID; + +#define BT_EIR_FLAGS_TYPE 0x01 +#define BT_EIR_MORE_16BITS_UUID_TYPE 0x02 +#define BT_EIR_COMPLETE_16BITS_UUID_TYPE 0x03 +#define BT_EIR_MORE_32BITS_UUID_TYPE 0x04 +#define BT_EIR_COMPLETE_32BITS_UUID_TYPE 0x05 +#define BT_EIR_MORE_128BITS_UUID_TYPE 0x06 +#define BT_EIR_COMPLETE_128BITS_UUID_TYPE 0x07 +#define BT_EIR_SHORTENED_LOCAL_NAME_TYPE 0x08 +#define BT_EIR_COMPLETE_LOCAL_NAME_TYPE 0x09 +#define BT_EIR_TX_POWER_LEVEL_TYPE 0x0A +#define BT_EIR_OOB_BD_ADDR_TYPE 0x0C +#define BT_EIR_OOB_COD_TYPE 0x0D +#define BT_EIR_OOB_SSP_HASH_C_TYPE 0x0E +#define BT_EIR_OOB_SSP_RAND_R_TYPE 0x0F +#define BT_EIR_MANUFACTURER_SPECIFIC_TYPE 0xFF + +#define BT_OOB_COD_SIZE 3 +#define BT_OOB_HASH_C_SIZE 16 +#define BT_OOB_RAND_R_SIZE 16 + +/* Broadcom proprietary UUIDs and reserved PSMs +** +** The lowest 4 bytes byte of the UUID or GUID depends on the feature. Typically, +** the value of those bytes will be the PSM or SCN, but it is up to the features. +*/ +#define BRCM_PROPRIETARY_UUID_BASE 0xDA, 0x23, 0x41, 0x02, 0xA3, 0xBB, 0xC1, 0x71, 0xBA, 0x09, 0x6f, 0x21 +#define BRCM_PROPRIETARY_GUID_BASE 0xda23, 0x4102, 0xa3, 0xbb, 0xc1, 0x71, 0xba, 0x09, 0x6f, 0x21 + +/* We will not allocate a PSM in the reserved range to 3rd party apps +*/ +#define BRCM_RESERVED_PSM_START 0x5AE1 +#define BRCM_RESERVED_PSM_END 0x5AFF + +#define BRCM_UTILITY_SERVICE_PSM 0x5AE1 +#define BRCM_MATCHER_PSM 0x5AE3 + +/* Connection statistics +*/ + +/* Structure to hold connection stats */ +#ifndef BT_CONN_STATS_DEFINED +#define BT_CONN_STATS_DEFINED + +/* These bits are used in the bIsConnected field */ +#define BT_CONNECTED_USING_BREDR 1 +#define BT_CONNECTED_USING_AMP 2 + +typedef struct { + UINT32 is_connected; + INT32 rssi; + UINT32 bytes_sent; + UINT32 bytes_rcvd; + UINT32 duration; +} tBT_CONN_STATS; + +#endif + + +/***************************************************************************** +** Low Energy definitions +** +** Address types +*/ +#define BLE_ADDR_PUBLIC 0x00 +#define BLE_ADDR_RANDOM 0x01 +#define BLE_ADDR_PUBLIC_ID 0x02 +#define BLE_ADDR_RANDOM_ID 0x03 +typedef UINT8 tBLE_ADDR_TYPE; +#define BLE_ADDR_TYPE_MASK (BLE_ADDR_RANDOM | BLE_ADDR_PUBLIC) + +#define BT_TRANSPORT_INVALID 0 +#define BT_TRANSPORT_BR_EDR 1 +#define BT_TRANSPORT_LE 2 +typedef UINT8 tBT_TRANSPORT; + +#define BLE_ADDR_IS_STATIC(x) ((x[0] & 0xC0) == 0xC0) + +typedef struct { + tBLE_ADDR_TYPE type; + BD_ADDR bda; +} tBLE_BD_ADDR; + +/* Device Types +*/ +#define BT_DEVICE_TYPE_BREDR 0x01 +#define BT_DEVICE_TYPE_BLE 0x02 +#define BT_DEVICE_TYPE_DUMO 0x03 +typedef UINT8 tBT_DEVICE_TYPE; +/*****************************************************************************/ + + +/* Define trace levels */ +#define BT_TRACE_LEVEL_NONE 0 /* No trace messages to be generated */ +#define BT_TRACE_LEVEL_ERROR 1 /* Error condition trace messages */ +#define BT_TRACE_LEVEL_WARNING 2 /* Warning condition trace messages */ +#define BT_TRACE_LEVEL_API 3 /* API traces */ +#define BT_TRACE_LEVEL_EVENT 4 /* Debug messages for events */ +#define BT_TRACE_LEVEL_DEBUG 5 /* Full debug messages */ +#define BT_TRACE_LEVEL_VERBOSE 6 /* Verbose debug messages */ + +#define MAX_TRACE_LEVEL 6 + + +/* Define New Trace Type Definition */ +/* TRACE_CTRL_TYPE 0x^^000000*/ +#define TRACE_CTRL_MASK 0xff000000 +#define TRACE_GET_CTRL(x) ((((UINT32)(x)) & TRACE_CTRL_MASK) >> 24) + +#define TRACE_CTRL_GENERAL 0x00000000 +#define TRACE_CTRL_STR_RESOURCE 0x01000000 +#define TRACE_CTRL_SEQ_FLOW 0x02000000 +#define TRACE_CTRL_MAX_NUM 3 + +/* LAYER SPECIFIC 0x00^^0000*/ +#define TRACE_LAYER_MASK 0x00ff0000 +#define TRACE_GET_LAYER(x) ((((UINT32)(x)) & TRACE_LAYER_MASK) >> 16) + +#define TRACE_LAYER_NONE 0x00000000 +#define TRACE_LAYER_USB 0x00010000 +#define TRACE_LAYER_SERIAL 0x00020000 +#define TRACE_LAYER_SOCKET 0x00030000 +#define TRACE_LAYER_RS232 0x00040000 +#define TRACE_LAYER_TRANS_MAX_NUM 5 +#define TRACE_LAYER_TRANS_ALL 0x007f0000 +#define TRACE_LAYER_LC 0x00050000 +#define TRACE_LAYER_LM 0x00060000 +#define TRACE_LAYER_HCI 0x00070000 +#define TRACE_LAYER_L2CAP 0x00080000 +#define TRACE_LAYER_RFCOMM 0x00090000 +#define TRACE_LAYER_SDP 0x000a0000 +#define TRACE_LAYER_TCS 0x000b0000 +#define TRACE_LAYER_OBEX 0x000c0000 +#define TRACE_LAYER_BTM 0x000d0000 +#define TRACE_LAYER_GAP 0x000e0000 +#define TRACE_LAYER_ICP 0x00110000 +#define TRACE_LAYER_HSP2 0x00120000 +#define TRACE_LAYER_SPP 0x00130000 +#define TRACE_LAYER_CTP 0x00140000 +#define TRACE_LAYER_BPP 0x00150000 +#define TRACE_LAYER_HCRP 0x00160000 +#define TRACE_LAYER_FTP 0x00170000 +#define TRACE_LAYER_OPP 0x00180000 +#define TRACE_LAYER_BTU 0x00190000 +#define TRACE_LAYER_GKI 0x001a0000 +#define TRACE_LAYER_BNEP 0x001b0000 +#define TRACE_LAYER_PAN 0x001c0000 +#define TRACE_LAYER_HFP 0x001d0000 +#define TRACE_LAYER_HID 0x001e0000 +#define TRACE_LAYER_BIP 0x001f0000 +#define TRACE_LAYER_AVP 0x00200000 +#define TRACE_LAYER_A2D 0x00210000 +#define TRACE_LAYER_SAP 0x00220000 +#define TRACE_LAYER_AMP 0x00230000 +#define TRACE_LAYER_MCA 0x00240000 +#define TRACE_LAYER_ATT 0x00250000 +#define TRACE_LAYER_SMP 0x00260000 +#define TRACE_LAYER_NFC 0x00270000 +#define TRACE_LAYER_NCI 0x00280000 +#define TRACE_LAYER_LLCP 0x00290000 +#define TRACE_LAYER_NDEF 0x002a0000 +#define TRACE_LAYER_RW 0x002b0000 +#define TRACE_LAYER_CE 0x002c0000 +#define TRACE_LAYER_P2P 0x002d0000 +#define TRACE_LAYER_SNEP 0x002e0000 +#define TRACE_LAYER_CHO 0x002f0000 +#define TRACE_LAYER_NFA 0x00300000 + +#define TRACE_LAYER_MAX_NUM 0x0031 + + +/* TRACE_ORIGINATOR 0x0000^^00*/ +#define TRACE_ORG_MASK 0x0000ff00 +#define TRACE_GET_ORG(x) ((((UINT32)(x)) & TRACE_ORG_MASK) >> 8) + +#define TRACE_ORG_STACK 0x00000000 +#define TRACE_ORG_HCI_TRANS 0x00000100 +#define TRACE_ORG_PROTO_DISP 0x00000200 +#define TRACE_ORG_RPC 0x00000300 +#define TRACE_ORG_GKI 0x00000400 +#define TRACE_ORG_APPL 0x00000500 +#define TRACE_ORG_SCR_WRAPPER 0x00000600 +#define TRACE_ORG_SCR_ENGINE 0x00000700 +#define TRACE_ORG_USER_SCR 0x00000800 +#define TRACE_ORG_TESTER 0x00000900 +#define TRACE_ORG_MAX_NUM 10 /* 32-bit mask; must be < 32 */ +#define TRACE_LITE_ORG_MAX_NUM 6 +#define TRACE_ORG_ALL 0x03ff +#define TRACE_ORG_RPC_TRANS 0x04 + +#define TRACE_ORG_REG 0x00000909 +#define TRACE_ORG_REG_SUCCESS 0x0000090a + +/* TRACE_TYPE 0x000000^^*/ +#define TRACE_TYPE_MASK 0x000000ff +#define TRACE_GET_TYPE(x) (((UINT32)(x)) & TRACE_TYPE_MASK) + +#define TRACE_TYPE_ERROR 0x00000000 +#define TRACE_TYPE_WARNING 0x00000001 +#define TRACE_TYPE_API 0x00000002 +#define TRACE_TYPE_EVENT 0x00000003 +#define TRACE_TYPE_DEBUG 0x00000004 +#define TRACE_TYPE_STACK_ONLY_MAX TRACE_TYPE_DEBUG +#define TRACE_TYPE_TX 0x00000005 +#define TRACE_TYPE_RX 0x00000006 +#define TRACE_TYPE_DEBUG_ASSERT 0x00000007 +#define TRACE_TYPE_GENERIC 0x00000008 +#define TRACE_TYPE_REG 0x00000009 +#define TRACE_TYPE_REG_SUCCESS 0x0000000a +#define TRACE_TYPE_CMD_TX 0x0000000b +#define TRACE_TYPE_EVT_TX 0x0000000c +#define TRACE_TYPE_ACL_TX 0x0000000d +#define TRACE_TYPE_CMD_RX 0x0000000e +#define TRACE_TYPE_EVT_RX 0x0000000f +#define TRACE_TYPE_ACL_RX 0x00000010 +#define TRACE_TYPE_TARGET_TRACE 0x00000011 +#define TRACE_TYPE_SCO_TX 0x00000012 +#define TRACE_TYPE_SCO_RX 0x00000013 + + +#define TRACE_TYPE_MAX_NUM 20 +#define TRACE_TYPE_ALL 0xffff + +/* Define color for script type */ +#define SCR_COLOR_DEFAULT 0 +#define SCR_COLOR_TYPE_COMMENT 1 +#define SCR_COLOR_TYPE_COMMAND 2 +#define SCR_COLOR_TYPE_EVENT 3 +#define SCR_COLOR_TYPE_SELECT 4 + +/* Define protocol trace flag values */ +#define SCR_PROTO_TRACE_HCI_SUMMARY 0x00000001 +#define SCR_PROTO_TRACE_HCI_DATA 0x00000002 +#define SCR_PROTO_TRACE_L2CAP 0x00000004 +#define SCR_PROTO_TRACE_RFCOMM 0x00000008 +#define SCR_PROTO_TRACE_SDP 0x00000010 +#define SCR_PROTO_TRACE_TCS 0x00000020 +#define SCR_PROTO_TRACE_OBEX 0x00000040 +#define SCR_PROTO_TRACE_OAPP 0x00000080 /* OBEX Application Profile */ +#define SCR_PROTO_TRACE_AMP 0x00000100 +#define SCR_PROTO_TRACE_BNEP 0x00000200 +#define SCR_PROTO_TRACE_AVP 0x00000400 +#define SCR_PROTO_TRACE_MCA 0x00000800 +#define SCR_PROTO_TRACE_ATT 0x00001000 +#define SCR_PROTO_TRACE_SMP 0x00002000 +#define SCR_PROTO_TRACE_NCI 0x00004000 +#define SCR_PROTO_TRACE_LLCP 0x00008000 +#define SCR_PROTO_TRACE_NDEF 0x00010000 +#define SCR_PROTO_TRACE_RW 0x00020000 +#define SCR_PROTO_TRACE_CE 0x00040000 +#define SCR_PROTO_TRACE_SNEP 0x00080000 +#define SCR_PROTO_TRACE_CHO 0x00100000 +#define SCR_PROTO_TRACE_ALL 0x001fffff +#define SCR_PROTO_TRACE_HCI_LOGGING_VSE 0x0800 /* Brcm vs event for logmsg and protocol traces */ + +#define MAX_SCRIPT_TYPE 5 + +#define TCS_PSM_INTERCOM 5 +#define TCS_PSM_CORDLESS 7 +#define BT_PSM_BNEP 0x000F +/* Define PSMs HID uses */ +#define HID_PSM_CONTROL 0x0011 +#define HID_PSM_INTERRUPT 0x0013 + +/* Define a function for logging */ +typedef void (BT_LOG_FUNC) (int trace_type, const char *fmt_str, ...); + +/* bd addr length and type */ +#ifndef BD_ADDR_LEN +#define BD_ADDR_LEN 6 +typedef uint8_t BD_ADDR[BD_ADDR_LEN]; +#endif + +// From bd.c + +/***************************************************************************** +** Constants +*****************************************************************************/ + +/* global constant for "any" bd addr */ +static const BD_ADDR bd_addr_any = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; +static const BD_ADDR bd_addr_null = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + +/***************************************************************************** +** Functions +*****************************************************************************/ + +/******************************************************************************* +** +** Function bdcpy +** +** Description Copy bd addr b to a. +** +** +** Returns void +** +*******************************************************************************/ +static inline void bdcpy(BD_ADDR a, const BD_ADDR b) +{ + int i; + + for (i = BD_ADDR_LEN; i != 0; i--) { + *a++ = *b++; + } +} + +/******************************************************************************* +** +** Function bdcmp +** +** Description Compare bd addr b to a. +** +** +** Returns Zero if b==a, nonzero otherwise (like memcmp). +** +*******************************************************************************/ +static inline int bdcmp(const BD_ADDR a, const BD_ADDR b) +{ + int i; + + for (i = BD_ADDR_LEN; i != 0; i--) { + if (*a++ != *b++) { + return -1; + } + } + return 0; +} + +/******************************************************************************* +** +** Function bdcmpany +** +** Description Compare bd addr to "any" bd addr. +** +** +** Returns Zero if a equals bd_addr_any. +** +*******************************************************************************/ +static inline int bdcmpany(const BD_ADDR a) +{ + return bdcmp(a, bd_addr_any); +} + +/******************************************************************************* +** +** Function bdsetany +** +** Description Set bd addr to "any" bd addr. +** +** +** Returns void +** +*******************************************************************************/ +static inline void bdsetany(BD_ADDR a) +{ + bdcpy(a, bd_addr_any); +} +#endif diff --git a/tools/sdk/include/bluedroid/bt_vendor_lib.h b/tools/sdk/include/bluedroid/bt_vendor_lib.h new file mode 100644 index 00000000..e3a8ec8d --- /dev/null +++ b/tools/sdk/include/bluedroid/bt_vendor_lib.h @@ -0,0 +1,362 @@ +/****************************************************************************** + * + * Copyright (C) 2009-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. + * + ******************************************************************************/ + +#ifndef BT_VENDOR_LIB_H +#define BT_VENDOR_LIB_H + +#include +//#include +//#include + +/** Struct types */ + + +/** Typedefs and defines */ + +/** Vendor specific operations OPCODE */ +typedef enum { + /* [operation] + * Power on or off the BT Controller. + * [input param] + * A pointer to int type with content of bt_vendor_power_state_t. + * Typecasting conversion: (int *) param. + * [return] + * 0 - default, don't care. + * [callback] + * None. + */ + BT_VND_OP_POWER_CTRL, + + /* [operation] + * Perform any vendor specific initialization or configuration + * on the BT Controller. This is called before stack initialization. + * [input param] + * None. + * [return] + * 0 - default, don't care. + * [callback] + * Must call fwcfg_cb to notify the stack of the completion of vendor + * specific initialization once it has been done. + */ + BT_VND_OP_FW_CFG, + + /* [operation] + * Perform any vendor specific SCO/PCM configuration on the BT Controller. + * This is called after stack initialization. + * [input param] + * None. + * [return] + * 0 - default, don't care. + * [callback] + * Must call scocfg_cb to notify the stack of the completion of vendor + * specific SCO configuration once it has been done. + */ + BT_VND_OP_SCO_CFG, + + /* [operation] + * Open UART port on where the BT Controller is attached. + * This is called before stack initialization. + * [input param] + * A pointer to int array type for open file descriptors. + * The mapping of HCI channel to fd slot in the int array is given in + * bt_vendor_hci_channels_t. + * And, it requires the vendor lib to fill up the content before returning + * the call. + * Typecasting conversion: (int (*)[]) param. + * [return] + * Numbers of opened file descriptors. + * Valid number: + * 1 - CMD/EVT/ACL-In/ACL-Out via the same fd (e.g. UART) + * 2 - CMD/EVT on one fd, and ACL-In/ACL-Out on the other fd + * 4 - CMD, EVT, ACL-In, ACL-Out are on their individual fd + * [callback] + * None. + */ + BT_VND_OP_USERIAL_OPEN, + + /* [operation] + * Close the previously opened UART port. + * [input param] + * None. + * [return] + * 0 - default, don't care. + * [callback] + * None. + */ + BT_VND_OP_USERIAL_CLOSE, + + /* [operation] + * Get the LPM idle timeout in milliseconds. + * The stack uses this information to launch a timer delay before it + * attempts to de-assert LPM WAKE signal once downstream HCI packet + * has been delivered. + * [input param] + * A pointer to uint32_t type which is passed in by the stack. And, it + * requires the vendor lib to fill up the content before returning + * the call. + * Typecasting conversion: (uint32_t *) param. + * [return] + * 0 - default, don't care. + * [callback] + * None. + */ + BT_VND_OP_GET_LPM_IDLE_TIMEOUT, + + /* [operation] + * Enable or disable LPM mode on BT Controller. + * [input param] + * A pointer to uint8_t type with content of bt_vendor_lpm_mode_t. + * Typecasting conversion: (uint8_t *) param. + * [return] + * 0 - default, don't care. + * [callback] + * Must call lpm_cb to notify the stack of the completion of LPM + * disable/enable process once it has been done. + */ + BT_VND_OP_LPM_SET_MODE, + + /* [operation] + * Assert or Deassert LPM WAKE on BT Controller. + * [input param] + * A pointer to uint8_t type with content of bt_vendor_lpm_wake_state_t. + * Typecasting conversion: (uint8_t *) param. + * [return] + * 0 - default, don't care. + * [callback] + * None. + */ + BT_VND_OP_LPM_WAKE_SET_STATE, + + /* [operation] + * Perform any vendor specific commands related to audio state changes. + * [input param] + * a pointer to bt_vendor_op_audio_state_t indicating what audio state is + * set. + * [return] + * 0 - default, don't care. + * [callback] + * None. + */ + BT_VND_OP_SET_AUDIO_STATE, + + /* [operation] + * The epilog call to the vendor module so that it can perform any + * vendor-specific processes (e.g. send a HCI_RESET to BT Controller) + * before the caller calls for cleanup(). + * [input param] + * None. + * [return] + * 0 - default, don't care. + * [callback] + * Must call epilog_cb to notify the stack of the completion of vendor + * specific epilog process once it has been done. + */ + BT_VND_OP_EPILOG, +} bt_vendor_opcode_t; + +/** Power on/off control states */ +typedef enum { + BT_VND_PWR_OFF, + BT_VND_PWR_ON, +} bt_vendor_power_state_t; + +/** Define HCI channel identifier in the file descriptors array + used in BT_VND_OP_USERIAL_OPEN operation. + */ +typedef enum { + CH_CMD, // HCI Command channel + CH_EVT, // HCI Event channel + CH_ACL_OUT, // HCI ACL downstream channel + CH_ACL_IN, // HCI ACL upstream channel + + CH_MAX // Total channels +} bt_vendor_hci_channels_t; + +/** LPM disable/enable request */ +typedef enum { + BT_VND_LPM_DISABLE, + BT_VND_LPM_ENABLE, +} bt_vendor_lpm_mode_t; + +/** LPM WAKE set state request */ +typedef enum { + BT_VND_LPM_WAKE_ASSERT, + BT_VND_LPM_WAKE_DEASSERT, +} bt_vendor_lpm_wake_state_t; + +/** Callback result values */ +typedef enum { + BT_VND_OP_RESULT_SUCCESS, + BT_VND_OP_RESULT_FAIL, +} bt_vendor_op_result_t; + +/** audio (SCO) state changes triggering VS commands for configuration */ +typedef struct { + uint16_t handle; + uint16_t peer_codec; + uint16_t state; +} bt_vendor_op_audio_state_t; + +/* + * Bluetooth Host/Controller Vendor callback structure. + */ + +/* vendor initialization/configuration callback */ +typedef void (*cfg_result_cb)(bt_vendor_op_result_t result); + +/* datapath buffer allocation callback (callout) + * + * Vendor lib needs to request a buffer through the alloc callout function + * from HCI lib if the buffer is for constructing a HCI Command packet which + * will be sent through xmit_cb to BT Controller. + * + * For each buffer allocation, the requested size needs to be big enough to + * accommodate the below header plus a complete HCI packet -- + * typedef struct + * { + * uint16_t event; + * uint16_t len; + * uint16_t offset; + * uint16_t layer_specific; + * } HC_BT_HDR; + * + * HCI lib returns a pointer to the buffer where Vendor lib should use to + * construct a HCI command packet as below format: + * + * -------------------------------------------- + * | HC_BT_HDR | HCI command | + * -------------------------------------------- + * where + * HC_BT_HDR.event = 0x2000; + * HC_BT_HDR.len = Length of HCI command; + * HC_BT_HDR.offset = 0; + * HC_BT_HDR.layer_specific = 0; + * + * For example, a HCI_RESET Command will be formed as + * ------------------------ + * | HC_BT_HDR |03|0c|00| + * ------------------------ + * with + * HC_BT_HDR.event = 0x2000; + * HC_BT_HDR.len = 3; + * HC_BT_HDR.offset = 0; + * HC_BT_HDR.layer_specific = 0; + */ +typedef void *(*malloc_cb)(int size); + +/* datapath buffer deallocation callback (callout) */ +typedef void (*mdealloc_cb)(void *p_buf); + +/* define callback of the cmd_xmit_cb + * + * The callback function which HCI lib will call with the return of command + * complete packet. Vendor lib is responsible for releasing the buffer passed + * in at the p_mem parameter by calling dealloc callout function. + */ +typedef void (*tINT_CMD_CBACK)(void *p_mem); + +/* hci command packet transmit callback (callout) + * + * Vendor lib calls xmit_cb callout function in order to send a HCI Command + * packet to BT Controller. The buffer carrying HCI Command packet content + * needs to be first allocated through the alloc callout function. + * HCI lib will release the buffer for Vendor lib once it has delivered the + * packet content to BT Controller. + * + * Vendor lib needs also provide a callback function (p_cback) which HCI lib + * will call with the return of command complete packet. + * + * The opcode parameter gives the HCI OpCode (combination of OGF and OCF) of + * HCI Command packet. For example, opcode = 0x0c03 for the HCI_RESET command + * packet. + */ +typedef uint8_t (*cmd_xmit_cb)(uint16_t opcode, void *p_buf, tINT_CMD_CBACK p_cback); + +typedef struct { + /** set to sizeof(bt_vendor_callbacks_t) */ + size_t size; + + /* + * Callback and callout functions have implemented in HCI libray + * (libbt-hci.so). + */ + + /* notifies caller result of firmware configuration request */ + cfg_result_cb fwcfg_cb; + + /* notifies caller result of sco configuration request */ + cfg_result_cb scocfg_cb; + + /* notifies caller result of lpm enable/disable */ + cfg_result_cb lpm_cb; + + /* notifies the result of codec setting */ + cfg_result_cb audio_state_cb; + + /* buffer allocation request */ + malloc_cb alloc; + + /* buffer deallocation request */ + mdealloc_cb dealloc; + + /* hci command packet transmit request */ + cmd_xmit_cb xmit_cb; + + /* notifies caller completion of epilog process */ + cfg_result_cb epilog_cb; +} bt_vendor_callbacks_t; + +/* + * Bluetooth Host/Controller VENDOR Interface + */ +typedef struct { + /** Set to sizeof(bt_vndor_interface_t) */ + size_t size; + + /* + * Functions need to be implemented in Vendor libray (libbt-vendor.so). + */ + + /** + * Caller will open the interface and pass in the callback routines + * to the implemenation of this interface. + */ + int (*init)(const bt_vendor_callbacks_t *p_cb, unsigned char *local_bdaddr); + + /** Vendor specific operations */ + int (*op)(bt_vendor_opcode_t opcode, void *param); + + /** Closes the interface */ + void (*cleanup)(void); +} bt_vendor_interface_t; + + +/* + * External shared lib functions/data + */ + +/* Entry point of DLib -- + * Vendor library needs to implement the body of bt_vendor_interface_t + * structure and uses the below name as the variable name. HCI library + * will use this symbol name to get address of the object through the + * dlsym call. + */ +//extern const bt_vendor_interface_t BLUETOOTH_VENDOR_LIB_INTERFACE; + +#endif /* BT_VENDOR_LIB_H */ + diff --git a/tools/sdk/include/bluedroid/bta_api.h b/tools/sdk/include/bluedroid/bta_api.h new file mode 100644 index 00000000..1b97dc4f --- /dev/null +++ b/tools/sdk/include/bluedroid/bta_api.h @@ -0,0 +1,2399 @@ +/****************************************************************************** + * + * Copyright (C) 2003-2014 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 is the public interface file for BTA, Broadcom's Bluetooth + * application layer for mobile phones. + * + ******************************************************************************/ +#ifndef BTA_API_H +#define BTA_API_H + +#include "bt_target.h" +#include "bt_types.h" +#include "btm_api.h" +// #include "uipc_msg.h" +#include "sdp_api.h" + +#if BLE_INCLUDED == TRUE +#include "btm_ble_api.h" +#endif + +/***************************************************************************** +** Constants and data types +*****************************************************************************/ + +/* Status Return Value */ +#define BTA_SUCCESS 0 /* Successful operation. */ +#define BTA_FAILURE 1 /* Generic failure. */ +#define BTA_PENDING 2 /* API cannot be completed right now */ +#define BTA_BUSY 3 +#define BTA_NO_RESOURCES 4 +#define BTA_WRONG_MODE 5 + +typedef UINT8 tBTA_STATUS; + +/* + * Service ID + * + * NOTES: When you add a new Service ID for BTA AND require to change the value of BTA_MAX_SERVICE_ID, + * make sure that the correct security ID of the new service from Security service definitions (btm_api.h) + * should be added to bta_service_id_to_btm_srv_id_lkup_tbl table in bta_dm_act.c. + */ + +#define BTA_RES_SERVICE_ID 0 /* Reserved */ +#define BTA_SPP_SERVICE_ID 1 /* Serial port profile. */ +#define BTA_DUN_SERVICE_ID 2 /* Dial-up networking profile. */ +#define BTA_A2DP_SOURCE_SERVICE_ID 3 /* A2DP Source profile. */ +#define BTA_LAP_SERVICE_ID 4 /* LAN access profile. */ +#define BTA_HSP_SERVICE_ID 5 /* Headset profile. */ +#define BTA_HFP_SERVICE_ID 6 /* Hands-free profile. */ +#define BTA_OPP_SERVICE_ID 7 /* Object push */ +#define BTA_FTP_SERVICE_ID 8 /* File transfer */ +#define BTA_CTP_SERVICE_ID 9 /* Cordless Terminal */ +#define BTA_ICP_SERVICE_ID 10 /* Intercom Terminal */ +#define BTA_SYNC_SERVICE_ID 11 /* Synchronization */ +#define BTA_BPP_SERVICE_ID 12 /* Basic printing profile */ +#define BTA_BIP_SERVICE_ID 13 /* Basic Imaging profile */ +#define BTA_PANU_SERVICE_ID 14 /* PAN User */ +#define BTA_NAP_SERVICE_ID 15 /* PAN Network access point */ +#define BTA_GN_SERVICE_ID 16 /* PAN Group Ad-hoc networks */ +#define BTA_SAP_SERVICE_ID 17 /* SIM Access profile */ +#define BTA_A2DP_SINK_SERVICE_ID 18 /* A2DP Sink */ +#define BTA_AVRCP_SERVICE_ID 19 /* A/V remote control */ +#define BTA_HID_SERVICE_ID 20 /* HID */ +#define BTA_VDP_SERVICE_ID 21 /* Video distribution */ +#define BTA_PBAP_SERVICE_ID 22 /* PhoneBook Access Server*/ +#define BTA_HSP_HS_SERVICE_ID 23 /* HFP HS role */ +#define BTA_HFP_HS_SERVICE_ID 24 /* HSP HS role */ +#define BTA_MAP_SERVICE_ID 25 /* Message Access Profile */ +#define BTA_MN_SERVICE_ID 26 /* Message Notification Service */ +#define BTA_HDP_SERVICE_ID 27 /* Health Device Profile */ +#define BTA_PCE_SERVICE_ID 28 /* PhoneBook Access Client*/ +#define BTA_SDP_SERVICE_ID 29 /* SDP Search*/ +#if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE +/* BLE profile service ID */ +#define BTA_BLE_SERVICE_ID 30 /* GATT profile */ + +// btla-specific ++ +#define BTA_USER_SERVICE_ID 31 /* User requested UUID */ + +#define BTA_MAX_SERVICE_ID 32 +// btla-specific -- +#else +#define BTA_USER_SERVICE_ID 30 /* User requested UUID */ +#define BTA_MAX_SERVICE_ID 31 +#endif +/* service IDs (BTM_SEC_SERVICE_FIRST_EMPTY + 1) to (BTM_SEC_MAX_SERVICES - 1) + * are used by BTA JV */ +#define BTA_FIRST_JV_SERVICE_ID (BTM_SEC_SERVICE_FIRST_EMPTY + 1) +#define BTA_LAST_JV_SERVICE_ID (BTM_SEC_MAX_SERVICES - 1) + +typedef UINT8 tBTA_SERVICE_ID; + +/* Service ID Mask */ +#define BTA_RES_SERVICE_MASK 0x00000001 /* Reserved */ +#define BTA_SPP_SERVICE_MASK 0x00000002 /* Serial port profile. */ +#define BTA_DUN_SERVICE_MASK 0x00000004 /* Dial-up networking profile. */ +#define BTA_FAX_SERVICE_MASK 0x00000008 /* Fax profile. */ +#define BTA_LAP_SERVICE_MASK 0x00000010 /* LAN access profile. */ +#define BTA_HSP_SERVICE_MASK 0x00000020 /* HSP AG role. */ +#define BTA_HFP_SERVICE_MASK 0x00000040 /* HFP AG role */ +#define BTA_OPP_SERVICE_MASK 0x00000080 /* Object push */ +#define BTA_FTP_SERVICE_MASK 0x00000100 /* File transfer */ +#define BTA_CTP_SERVICE_MASK 0x00000200 /* Cordless Terminal */ +#define BTA_ICP_SERVICE_MASK 0x00000400 /* Intercom Terminal */ +#define BTA_SYNC_SERVICE_MASK 0x00000800 /* Synchronization */ +#define BTA_BPP_SERVICE_MASK 0x00001000 /* Print server */ +#define BTA_BIP_SERVICE_MASK 0x00002000 /* Basic Imaging */ +#define BTA_PANU_SERVICE_MASK 0x00004000 /* PAN User */ +#define BTA_NAP_SERVICE_MASK 0x00008000 /* PAN Network access point */ +#define BTA_GN_SERVICE_MASK 0x00010000 /* PAN Group Ad-hoc networks */ +#define BTA_SAP_SERVICE_MASK 0x00020000 /* PAN Group Ad-hoc networks */ +#define BTA_A2DP_SERVICE_MASK 0x00040000 /* Advanced audio distribution */ +#define BTA_AVRCP_SERVICE_MASK 0x00080000 /* A/V remote control */ +#define BTA_HID_SERVICE_MASK 0x00100000 /* HID */ +#define BTA_VDP_SERVICE_MASK 0x00200000 /* Video distribution */ +#define BTA_PBAP_SERVICE_MASK 0x00400000 /* Phone Book Server */ +#define BTA_HSP_HS_SERVICE_MASK 0x00800000 /* HFP HS role */ +#define BTA_HFP_HS_SERVICE_MASK 0x01000000 /* HSP HS role */ +#define BTA_MAS_SERVICE_MASK 0x02000000 /* Message Access Profile */ +#define BTA_MN_SERVICE_MASK 0x04000000 /* Message Notification Profile */ +#define BTA_HL_SERVICE_MASK 0x08000000 /* Health Device Profile */ +#define BTA_PCE_SERVICE_MASK 0x10000000 /* Phone Book Client */ + +#if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE +#define BTA_BLE_SERVICE_MASK 0x20000000 /* GATT based service */ +// btla-specific ++ +#define BTA_USER_SERVICE_MASK 0x40000000 /* Message Notification Profile */ +// btla-specific -- +#else +// btla-specific ++ +#define BTA_USER_SERVICE_MASK 0x20000000 /* Message Notification Profile */ +// btla-specific -- +#endif + +#if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE +#define BTA_ALL_SERVICE_MASK 0x3FFFFFFF /* All services supported by BTA. */ +#else +#define BTA_ALL_SERVICE_MASK 0x1FFFFFFF /* All services supported by BTA. */ +#endif + +typedef UINT32 tBTA_SERVICE_MASK; + +/* extended service mask, including mask with one or more GATT UUID */ +typedef struct { + tBTA_SERVICE_MASK srvc_mask; + UINT8 num_uuid; + tBT_UUID *p_uuid; +} tBTA_SERVICE_MASK_EXT; + +/* Security Setting Mask */ +#define BTA_SEC_NONE BTM_SEC_NONE /* No security. */ +#define BTA_SEC_AUTHORIZE (BTM_SEC_IN_AUTHORIZE ) /* Authorization required (only needed for out going connection )*/ +#define BTA_SEC_AUTHENTICATE (BTM_SEC_IN_AUTHENTICATE | BTM_SEC_OUT_AUTHENTICATE) /* Authentication required. */ +#define BTA_SEC_ENCRYPT (BTM_SEC_IN_ENCRYPT | BTM_SEC_OUT_ENCRYPT) /* Encryption required. */ +#define BTA_SEC_MODE4_LEVEL4 (BTM_SEC_MODE4_LEVEL4) /* Mode 4 level 4 service, i.e. incoming/outgoing MITM and P-256 encryption */ +#define BTA_SEC_MITM (BTM_SEC_IN_MITM | BTM_SEC_OUT_MITM) /* Man-In-The_Middle protection */ +#define BTA_SEC_IN_16_DIGITS (BTM_SEC_IN_MIN_16_DIGIT_PIN) /* Min 16 digit for pin code */ + +typedef UINT16 tBTA_SEC; + +/* Ignore for Discoverable, Connectable, Pairable and Connectable Paired only device modes */ +#define BTA_DM_IGNORE 0x00FF + +/* Ignore for Discoverable, Connectable only for LE modes */ +#define BTA_DM_LE_IGNORE 0xFF00 + +#define BTA_APP_ID_PAN_MULTI 0xFE /* app id for pan multiple connection */ +#define BTA_ALL_APP_ID 0xFF + +/* Discoverable Modes */ +#define BTA_DM_NON_DISC BTM_NON_DISCOVERABLE /* Device is not discoverable. */ +#define BTA_DM_GENERAL_DISC BTM_GENERAL_DISCOVERABLE /* General discoverable. */ +#define BTA_DM_LIMITED_DISC BTM_LIMITED_DISCOVERABLE /* Limited discoverable. */ +#if ((defined BLE_INCLUDED) && (BLE_INCLUDED == TRUE)) +#define BTA_DM_BLE_NON_DISCOVERABLE BTM_BLE_NON_DISCOVERABLE /* Device is not LE discoverable */ +#define BTA_DM_BLE_GENERAL_DISCOVERABLE BTM_BLE_GENERAL_DISCOVERABLE /* Device is LE General discoverable */ +#define BTA_DM_BLE_LIMITED_DISCOVERABLE BTM_BLE_LIMITED_DISCOVERABLE /* Device is LE Limited discoverable */ +#endif +typedef UINT16 tBTA_DM_DISC; /* this discoverability mode is a bit mask among BR mode and LE mode */ + +/* Connectable Modes */ +#define BTA_DM_NON_CONN BTM_NON_CONNECTABLE /* Device is not connectable. */ +#define BTA_DM_CONN BTM_CONNECTABLE /* Device is connectable. */ +#if ((defined BLE_INCLUDED) && (BLE_INCLUDED == TRUE)) +#define BTA_DM_BLE_NON_CONNECTABLE BTM_BLE_NON_CONNECTABLE /* Device is LE non-connectable. */ +#define BTA_DM_BLE_CONNECTABLE BTM_BLE_CONNECTABLE /* Device is LE connectable. */ +#endif + +// btla-specific ++ +typedef UINT16 tBTA_DM_CONN; + +#define BTA_TRANSPORT_UNKNOWN 0 +#define BTA_TRANSPORT_BR_EDR BT_TRANSPORT_BR_EDR +#define BTA_TRANSPORT_LE BT_TRANSPORT_LE +typedef tBT_TRANSPORT tBTA_TRANSPORT; + +/* Pairable Modes */ +#define BTA_DM_PAIRABLE 1 +#define BTA_DM_NON_PAIRABLE 0 + +/* Connectable Paired Only Mode */ +#define BTA_DM_CONN_ALL 0 +#define BTA_DM_CONN_PAIRED 1 + +/* Inquiry Modes */ +#define BTA_DM_INQUIRY_NONE BTM_INQUIRY_NONE /*No BR inquiry. */ +#define BTA_DM_GENERAL_INQUIRY BTM_GENERAL_INQUIRY /* Perform general inquiry. */ +#define BTA_DM_LIMITED_INQUIRY BTM_LIMITED_INQUIRY /* Perform limited inquiry. */ + +#if ((defined BLE_INCLUDED) && (BLE_INCLUDED == TRUE)) +#define BTA_BLE_INQUIRY_NONE BTM_BLE_INQUIRY_NONE +#define BTA_BLE_GENERAL_INQUIRY BTM_BLE_GENERAL_INQUIRY /* Perform LE general inquiry. */ +#define BTA_BLE_LIMITED_INQUIRY BTM_BLE_LIMITED_INQUIRY /* Perform LE limited inquiry. */ +#endif +typedef UINT8 tBTA_DM_INQ_MODE; + +/* Inquiry Filter Type */ +#define BTA_DM_INQ_CLR BTM_CLR_INQUIRY_FILTER /* Clear inquiry filter. */ +#define BTA_DM_INQ_DEV_CLASS BTM_FILTER_COND_DEVICE_CLASS /* Filter on device class. */ +#define BTA_DM_INQ_BD_ADDR BTM_FILTER_COND_BD_ADDR /* Filter on a specific BD address. */ + +typedef UINT8 tBTA_DM_INQ_FILT; + +/* Authorize Response */ +#define BTA_DM_AUTH_PERM 0 /* Authorized for future connections to the service */ +#define BTA_DM_AUTH_TEMP 1 /* Authorized for current connection only */ +#define BTA_DM_NOT_AUTH 2 /* Not authorized for the service */ + +typedef UINT8 tBTA_AUTH_RESP; + +/* M/S preferred roles */ +#define BTA_ANY_ROLE 0x00 +#define BTA_MASTER_ROLE_PREF 0x01 +#define BTA_MASTER_ROLE_ONLY 0x02 +#define BTA_SLAVE_ROLE_ONLY 0x03 /* Used for PANU only, skip role switch to master */ + +typedef UINT8 tBTA_PREF_ROLES; + +enum { + + BTA_DM_NO_SCATTERNET, /* Device doesn't support scatternet, it might + support "role switch during connection" for + an incoming connection, when it already has + another connection in master role */ + BTA_DM_PARTIAL_SCATTERNET, /* Device supports partial scatternet. It can have + simulateous connection in Master and Slave roles + for short period of time */ + BTA_DM_FULL_SCATTERNET /* Device can have simultaneous connection in master + and slave roles */ + +}; + + +/* Inquiry filter device class condition */ +typedef struct { + DEV_CLASS dev_class; /* device class of interest */ + DEV_CLASS dev_class_mask; /* mask to determine the bits of device class of interest */ +} tBTA_DM_COD_COND; + + +/* Inquiry Filter Condition */ +typedef union { + BD_ADDR bd_addr; /* BD address of device to filter. */ + tBTA_DM_COD_COND dev_class_cond; /* Device class filter condition */ +} tBTA_DM_INQ_COND; + +/* Inquiry Parameters */ +typedef struct { + tBTA_DM_INQ_MODE mode; /* Inquiry mode, limited or general. */ + UINT8 duration; /* Inquiry duration in 1.28 sec units. */ + UINT8 max_resps; /* Maximum inquiry responses. Set to zero for unlimited responses. */ + BOOLEAN report_dup; /* report duplicated inquiry response with higher RSSI value */ + tBTA_DM_INQ_FILT filter_type; /* Filter condition type. */ + tBTA_DM_INQ_COND filter_cond; /* Filter condition data. */ +#if (defined(BTA_HOST_INTERLEAVE_SEARCH) && BTA_HOST_INTERLEAVE_SEARCH == TRUE) + UINT8 intl_duration[4];/*duration array storing the interleave scan's time portions*/ +#endif +} tBTA_DM_INQ; + +typedef struct { + UINT8 bta_dm_eir_min_name_len; /* minimum length of local name when it is shortened */ +#if (BTA_EIR_CANNED_UUID_LIST == TRUE) + UINT8 bta_dm_eir_uuid16_len; /* length of 16-bit UUIDs */ + UINT8 *bta_dm_eir_uuid16; /* 16-bit UUIDs */ +#else + UINT32 uuid_mask[BTM_EIR_SERVICE_ARRAY_SIZE]; /* mask of UUID list in EIR */ +#endif + INT8 *bta_dm_eir_inq_tx_power; /* Inquiry TX power */ + UINT8 bta_dm_eir_flag_len; /* length of flags in bytes */ + UINT8 *bta_dm_eir_flags; /* flags for EIR */ + UINT8 bta_dm_eir_manufac_spec_len; /* length of manufacturer specific in bytes */ + UINT8 *bta_dm_eir_manufac_spec; /* manufacturer specific */ + UINT8 bta_dm_eir_additional_len; /* length of additional data in bytes */ + UINT8 *bta_dm_eir_additional; /* additional data */ +} tBTA_DM_EIR_CONF; + +#if BLE_INCLUDED == TRUE +/* ADV data flag bit definition used for BTM_BLE_AD_TYPE_FLAG */ +#define BTA_BLE_LIMIT_DISC_FLAG BTM_BLE_LIMIT_DISC_FLAG +#define BTA_BLE_GEN_DISC_FLAG BTM_BLE_GEN_DISC_FLAG +#define BTA_BLE_BREDR_NOT_SPT BTM_BLE_BREDR_NOT_SPT +#define BTA_BLE_DMT_CONTROLLER_SPT BTM_BLE_DMT_CONTROLLER_SPT +#define BTA_BLE_DMT_HOST_SPT BTM_BLE_DMT_HOST_SPT +#define BTA_BLE_NON_LIMIT_DISC_FLAG BTM_BLE_NON_LIMIT_DISC_FLAG +#define BTA_BLE_ADV_FLAG_MASK BTM_BLE_ADV_FLAG_MASK +#define BTA_BLE_LIMIT_DISC_MASK BTM_BLE_LIMIT_DISC_MASK + +/* ADV data bit mask */ +#define BTA_BLE_AD_BIT_DEV_NAME BTM_BLE_AD_BIT_DEV_NAME +#define BTA_BLE_AD_BIT_FLAGS BTM_BLE_AD_BIT_FLAGS +#define BTA_BLE_AD_BIT_MANU BTM_BLE_AD_BIT_MANU +#define BTA_BLE_AD_BIT_TX_PWR BTM_BLE_AD_BIT_TX_PWR +#define BTA_BLE_AD_BIT_INT_RANGE BTM_BLE_AD_BIT_INT_RANGE +#define BTA_BLE_AD_BIT_SERVICE BTM_BLE_AD_BIT_SERVICE +#define BTA_BLE_AD_BIT_APPEARANCE BTM_BLE_AD_BIT_APPEARANCE +#define BTA_BLE_AD_BIT_PROPRIETARY BTM_BLE_AD_BIT_PROPRIETARY +#define BTA_DM_BLE_AD_BIT_SERVICE_SOL BTM_BLE_AD_BIT_SERVICE_SOL +#define BTA_DM_BLE_AD_BIT_SERVICE_DATA BTM_BLE_AD_BIT_SERVICE_DATA +#define BTA_DM_BLE_AD_BIT_SIGN_DATA BTM_BLE_AD_BIT_SIGN_DATA +#define BTA_DM_BLE_AD_BIT_SERVICE_128SOL BTM_BLE_AD_BIT_SERVICE_128SOL +#define BTA_DM_BLE_AD_BIT_PUBLIC_ADDR BTM_BLE_AD_BIT_PUBLIC_ADDR +#define BTA_DM_BLE_AD_BIT_RANDOM_ADDR BTM_BLE_AD_BIT_RANDOM_ADDR +#define BTA_DM_BLE_AD_BIT_SERVICE_128 BTM_BLE_AD_BIT_SERVICE_128 /*128-bit Service UUIDs*/ + +typedef tBTM_BLE_AD_MASK tBTA_BLE_AD_MASK; + +/* slave preferred connection interval range */ +typedef struct { + UINT16 low; + UINT16 hi; + +} tBTA_BLE_INT_RANGE; + +/* Service tag supported in the device */ +typedef struct { + UINT8 num_service; + BOOLEAN list_cmpl; + UINT16 *p_uuid; +} tBTA_BLE_SERVICE; + + +typedef struct { + UINT8 len; + UINT8 *p_val; +} tBTA_BLE_MANU; + +typedef struct { + UINT8 adv_type; + UINT8 len; + UINT8 *p_val; /* number of len byte */ +} tBTA_BLE_PROP_ELEM; + +/* vendor proprietary adv type */ +typedef struct { + UINT8 num_elem; + tBTA_BLE_PROP_ELEM *p_elem; +} tBTA_BLE_PROPRIETARY; + +typedef struct { + tBT_UUID service_uuid; + UINT8 len; + UINT8 *p_val; +} tBTA_BLE_SERVICE_DATA; + +typedef tBTM_BLE_128SERVICE tBTA_BLE_128SERVICE; +typedef tBTM_BLE_32SERVICE tBTA_BLE_32SERVICE; + +typedef struct { + tBTA_BLE_INT_RANGE int_range; /* slave prefered conn interval range */ + tBTA_BLE_MANU *p_manu; /* manufacturer data */ + tBTA_BLE_SERVICE *p_services; /* 16 bits services */ + tBTA_BLE_128SERVICE *p_services_128b; /* 128 bits service */ + tBTA_BLE_32SERVICE *p_service_32b; /* 32 bits Service UUID */ + tBTA_BLE_SERVICE *p_sol_services; /* 16 bits services Solicitation UUIDs */ + tBTA_BLE_32SERVICE *p_sol_service_32b; /* List of 32 bit Service Solicitation UUIDs */ + tBTA_BLE_128SERVICE *p_sol_service_128b;/* List of 128 bit Service Solicitation UUIDs */ + tBTA_BLE_PROPRIETARY *p_proprietary; /* proprietary data */ + tBTA_BLE_SERVICE_DATA *p_service_data; /* service data */ + UINT16 appearance; /* appearance data */ + UINT8 flag; + UINT8 tx_power; +} tBTA_BLE_ADV_DATA; + +typedef void (tBTA_SET_ADV_DATA_CMPL_CBACK) (tBTA_STATUS status); + +/* 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 +#define BTA_BLE_ADV_CHNL_39 BTM_BLE_ADV_CHNL_39 +typedef tBTM_BLE_ADV_CHNL_MAP tBTA_BLE_ADV_CHNL_MAP; /* use as a bit mask */ + +/* advertising filter policy */ +typedef tBTM_BLE_AFP tBTA_BLE_AFP; + +/* adv event type */ +#define BTA_BLE_CONNECT_EVT BTM_BLE_CONNECT_EVT /* Connectable undirected advertising */ +#define BTA_BLE_CONNECT_DIR_EVT BTM_BLE_CONNECT_DIR_EVT /* Connectable directed advertising */ +#define BTA_BLE_DISCOVER_EVT BTM_BLE_DISCOVER_EVT /* Scannable undirected advertising */ +#define BTA_BLE_NON_CONNECT_EVT BTM_BLE_NON_CONNECT_EVT /* Non connectable undirected advertising */ +typedef UINT8 tBTA_BLE_ADV_EVT; + +/* adv tx power level */ +#define BTA_BLE_ADV_TX_POWER_MIN 0 /* minimum tx power */ +#define BTA_BLE_ADV_TX_POWER_LOW 1 /* low tx power */ +#define BTA_BLE_ADV_TX_POWER_MID 2 /* middle tx power */ +#define BTA_BLE_ADV_TX_POWER_UPPER 3 /* upper tx power */ +#define BTA_BLE_ADV_TX_POWER_MAX 4 /* maximum tx power */ +typedef UINT8 tBTA_BLE_ADV_TX_POWER; + +/* advertising instance parameters */ +typedef struct { + UINT16 adv_int_min; /* minimum adv interval */ + UINT16 adv_int_max; /* maximum adv interval */ + tBTA_BLE_ADV_EVT adv_type; /* adv event type */ + tBTA_BLE_ADV_CHNL_MAP channel_map; /* adv channel map */ + tBTA_BLE_AFP adv_filter_policy; /* advertising filter policy */ + tBTA_BLE_ADV_TX_POWER tx_power; /* adv tx power */ +} tBTA_BLE_ADV_PARAMS; + +/* These are the fields returned in each device adv packet. It +** is returned in the results callback if registered. +*/ +typedef struct { + UINT8 conn_mode; + tBTA_BLE_AD_MASK ad_mask; /* mask of the valid adv data field */ + UINT8 flag; + UINT8 tx_power_level; + UINT8 remote_name_len; + UINT8 *p_remote_name; + tBTA_BLE_SERVICE service; +} tBTA_BLE_INQ_DATA; + +enum { + BTA_BLE_BATCH_SCAN_MODE_PASS = 1, + BTA_BLE_BATCH_SCAN_MODE_ACTI = 2, + BTA_BLE_BATCH_SCAN_MODE_PASS_ACTI = 3 +}; +typedef UINT8 tBTA_BLE_BATCH_SCAN_MODE; + +enum { + BTA_BLE_DISCARD_OLD_ITEMS = 0, + BTA_BLE_DISCARD_LOWER_RSSI_ITEMS = 1 +}; +typedef UINT8 tBTA_BLE_DISCARD_RULE; + +enum { + BTA_BLE_ADV_SEEN_FIRST_TIME = 0, + BTA_BLE_ADV_TRACKING_TIMEOUT = 1 +}; +typedef UINT8 tBTA_BLE_ADV_CHANGE_REASON; + +enum { + BTA_BLE_BATCH_SCAN_ENB_EVT = 1, + BTA_BLE_BATCH_SCAN_CFG_STRG_EVT = 2, + BTA_BLE_BATCH_SCAN_DATA_EVT = 3, + BTA_BLE_BATCH_SCAN_THRES_EVT = 4, + BTA_BLE_BATCH_SCAN_PARAM_EVT = 5, + BTA_BLE_BATCH_SCAN_DIS_EVT = 6 +}; +typedef tBTM_BLE_BATCH_SCAN_EVT tBTA_BLE_BATCH_SCAN_EVT; + +typedef tBTM_BLE_TRACK_ADV_ACTION tBTA_BLE_TRACK_ADV_ACTION; +#endif + +/* BLE customer specific feature function type definitions */ +/* data type used on customer specific feature for RSSI monitoring */ +#define BTA_BLE_RSSI_ALERT_HI 0 +#define BTA_BLE_RSSI_ALERT_RANGE 1 +#define BTA_BLE_RSSI_ALERT_LO 2 +typedef UINT8 tBTA_DM_BLE_RSSI_ALERT_TYPE; + +#define BTA_BLE_RSSI_ALERT_NONE BTM_BLE_RSSI_ALERT_NONE /* (0) */ +#define BTA_BLE_RSSI_ALERT_HI_BIT BTM_BLE_RSSI_ALERT_HI_BIT /* (1) */ +#define BTA_BLE_RSSI_ALERT_RANGE_BIT BTM_BLE_RSSI_ALERT_RANGE_BIT /* (1 << 1) */ +#define BTA_BLE_RSSI_ALERT_LO_BIT BTM_BLE_RSSI_ALERT_LO_BIT /* (1 << 2) */ +typedef UINT8 tBTA_DM_BLE_RSSI_ALERT_MASK; + + +typedef void (tBTA_DM_BLE_RSSI_CBACK) (BD_ADDR bd_addr, tBTA_DM_BLE_RSSI_ALERT_TYPE alert_type, INT8 rssi); + +/* max number of filter spot for different filter type */ +#define BTA_DM_BLE_MAX_UUID_FILTER BTM_BLE_MAX_UUID_FILTER /* 8 */ +#define BTA_DM_BLE_MAX_ADDR_FILTER BTM_BLE_MAX_ADDR_FILTER /* 8 */ +#define BTA_DM_BLE_PF_STR_COND_MAX BTM_BLE_PF_STR_COND_MAX /* 4 apply to manu data , or local name */ +#define BTA_DM_BLE_PF_STR_LEN_MAX BTM_BLE_PF_STR_LEN_MAX /* match for first 20 bytes */ + +#define BTA_DM_BLE_PF_LOGIC_OR 0 +#define BTA_DM_BLE_PF_LOGIC_AND 1 +typedef UINT8 tBTA_DM_BLE_PF_LOGIC_TYPE; + +enum { + BTA_DM_BLE_SCAN_COND_ADD, + BTA_DM_BLE_SCAN_COND_DELETE, + BTA_DM_BLE_SCAN_COND_CLEAR = 2 +}; +typedef UINT8 tBTA_DM_BLE_SCAN_COND_OP; + +/* ADV payload filtering vendor specific call event */ +enum { + BTA_BLE_SCAN_PF_ENABLE_EVT = 7, + BTA_BLE_SCAN_PF_COND_EVT +}; + +/* filter selection bit index */ +#define BTA_DM_BLE_PF_ADDR_FILTER BTM_BLE_PF_ADDR_FILTER +#define BTA_DM_BLE_PF_SRVC_DATA BTM_BLE_PF_SRVC_DATA +#define BTA_DM_BLE_PF_SRVC_UUID BTM_BLE_PF_SRVC_UUID +#define BTA_DM_BLE_PF_SRVC_SOL_UUID BTM_BLE_PF_SRVC_SOL_UUID +#define BTA_DM_BLE_PF_LOCAL_NAME BTM_BLE_PF_LOCAL_NAME +#define BTA_DM_BLE_PF_MANU_DATA BTM_BLE_PF_MANU_DATA +#define BTA_DM_BLE_PF_SRVC_DATA_PATTERN BTM_BLE_PF_SRVC_DATA_PATTERN +#define BTA_DM_BLE_PF_TYPE_ALL BTM_BLE_PF_TYPE_ALL +#define BTA_DM_BLE_PF_TYPE_MAX BTM_BLE_PF_TYPE_MAX +typedef UINT8 tBTA_DM_BLE_PF_COND_TYPE; + +typedef union { + UINT16 uuid16_mask; + UINT32 uuid32_mask; + UINT8 uuid128_mask[LEN_UUID_128]; +} tBTA_DM_BLE_PF_COND_MASK; + +typedef struct { + tBLE_BD_ADDR *p_target_addr; /* target address, if NULL, generic UUID filter */ + tBT_UUID uuid; /* UUID condition */ + tBTA_DM_BLE_PF_LOGIC_TYPE cond_logic; /* AND/OR */ + tBTA_DM_BLE_PF_COND_MASK *p_uuid_mask; /* UUID condition mask, if NULL, match exact as UUID condition */ +} tBTA_DM_BLE_PF_UUID_COND; + +typedef struct { + UINT8 data_len; /* <= 20 bytes */ + UINT8 *p_data; +} tBTA_DM_BLE_PF_LOCAL_NAME_COND; + +typedef struct { + UINT16 company_id; /* company ID */ + UINT8 data_len; /* <= 20 bytes */ + UINT8 *p_pattern; + UINT16 company_id_mask; /* UUID value mask */ + UINT8 *p_pattern_mask; /* Manufacturer data matching mask, same length + as data pattern, set to all 0xff, match exact data */ +} tBTA_DM_BLE_PF_MANU_COND; + +typedef struct { + UINT16 uuid; /* service ID */ + UINT8 data_len; /* <= 20 bytes */ + UINT8 *p_pattern; + UINT8 *p_pattern_mask; /* Service data matching mask, same length + as data pattern, set to all 0xff, match exact data */ +} tBTA_DM_BLE_PF_SRVC_PATTERN_COND; + +typedef union { + tBLE_BD_ADDR target_addr; + tBTA_DM_BLE_PF_LOCAL_NAME_COND local_name; /* lcoal name filtering */ + tBTA_DM_BLE_PF_MANU_COND manu_data; /* manufactuer data filtering */ + tBTA_DM_BLE_PF_UUID_COND srvc_uuid; /* service UUID filtering */ + tBTA_DM_BLE_PF_UUID_COND solicitate_uuid; /* solicitated service UUID filtering */ + tBTA_DM_BLE_PF_SRVC_PATTERN_COND srvc_data; /* service data pattern */ +} tBTA_DM_BLE_PF_COND_PARAM; + +typedef UINT8 tBTA_DM_BLE_PF_FILT_INDEX; +typedef UINT8 tBTA_DM_BLE_PF_AVBL_SPACE; + +typedef INT8 tBTA_DM_RSSI_VALUE; +typedef UINT8 tBTA_DM_LINK_QUALITY_VALUE; + + +typedef UINT8 tBTA_SIG_STRENGTH_MASK; + + +/* Security Callback Events */ +#define BTA_DM_ENABLE_EVT 0 /* Enable Event */ +#define BTA_DM_DISABLE_EVT 1 /* Disable Event */ +#define BTA_DM_PIN_REQ_EVT 2 /* PIN request. */ +#define BTA_DM_AUTH_CMPL_EVT 3 /* Authentication complete indication. */ +#define BTA_DM_AUTHORIZE_EVT 4 /* Authorization request. */ +#define BTA_DM_LINK_UP_EVT 5 /* Connection UP event */ +#define BTA_DM_LINK_DOWN_EVT 6 /* Connection DOWN event */ +#define BTA_DM_SIG_STRENGTH_EVT 7 /* Signal strength for bluetooth connection */ +#define BTA_DM_BUSY_LEVEL_EVT 8 /* System busy level */ +#define BTA_DM_BOND_CANCEL_CMPL_EVT 9 /* Bond cancel complete indication */ +#define BTA_DM_SP_CFM_REQ_EVT 10 /* Simple Pairing User Confirmation request. */ +#define BTA_DM_SP_KEY_NOTIF_EVT 11 /* Simple Pairing Passkey Notification */ +#define BTA_DM_SP_RMT_OOB_EVT 12 /* Simple Pairing Remote OOB Data request. */ +#define BTA_DM_SP_KEYPRESS_EVT 13 /* Key press notification event. */ +#define BTA_DM_ROLE_CHG_EVT 14 /* Role Change event. */ +#define BTA_DM_BLE_KEY_EVT 15 /* BLE SMP key event for peer device keys */ +#define BTA_DM_BLE_SEC_REQ_EVT 16 /* BLE SMP security request */ +#define BTA_DM_BLE_PASSKEY_NOTIF_EVT 17 /* SMP passkey notification event */ +#define BTA_DM_BLE_PASSKEY_REQ_EVT 18 /* SMP passkey request event */ +#define BTA_DM_BLE_OOB_REQ_EVT 19 /* SMP OOB request event */ +#define BTA_DM_BLE_LOCAL_IR_EVT 20 /* BLE local IR event */ +#define BTA_DM_BLE_LOCAL_ER_EVT 21 /* BLE local ER event */ +#define BTA_DM_BLE_NC_REQ_EVT 22 /* SMP Numeric Comparison request event */ +// btla-specific ++ +#define BTA_DM_SP_RMT_OOB_EXT_EVT 23 /* Simple Pairing Remote OOB Extended Data request. */ +#define BTA_DM_BLE_AUTH_CMPL_EVT 24 /* BLE Auth complete */ +// btla-specific -- +#define BTA_DM_DEV_UNPAIRED_EVT 25 +#define BTA_DM_HW_ERROR_EVT 26 /* BT Chip H/W error */ +#define BTA_DM_LE_FEATURES_READ 27 /* Cotroller specific LE features are read */ +#define BTA_DM_ENER_INFO_READ 28 /* Energy info read */ +typedef UINT8 tBTA_DM_SEC_EVT; + +/* Structure associated with BTA_DM_ENABLE_EVT */ +typedef struct { + tBTA_STATUS status; +} tBTA_DM_ENABLE; + +/* Structure associated with BTA_DM_PIN_REQ_EVT */ +typedef struct { + /* Note: First 3 data members must be, bd_addr, dev_class, and bd_name in order */ + BD_ADDR bd_addr; /* BD address peer device. */ + DEV_CLASS dev_class; /* Class of Device */ + BD_NAME bd_name; /* Name of peer device. */ + BOOLEAN min_16_digit; /* TRUE if the pin returned must be at least 16 digits */ +} tBTA_DM_PIN_REQ; + +/* BLE related definition */ + +#define BTA_DM_AUTH_FAIL_BASE (HCI_ERR_MAX_ERR + 10) +#define BTA_DM_AUTH_CONVERT_SMP_CODE(x) (BTA_DM_AUTH_FAIL_BASE + (x)) +#define BTA_DM_AUTH_SMP_PASSKEY_FAIL BTA_DM_AUTH_CONVERT_SMP_CODE (SMP_PASSKEY_ENTRY_FAIL) +#define BTA_DM_AUTH_SMP_OOB_FAIL (BTA_DM_AUTH_FAIL_BASE + SMP_OOB_FAIL) +#define BTA_DM_AUTH_SMP_PAIR_AUTH_FAIL (BTA_DM_AUTH_FAIL_BASE + SMP_PAIR_AUTH_FAIL) +#define BTA_DM_AUTH_SMP_CONFIRM_VALUE_FAIL (BTA_DM_AUTH_FAIL_BASE + SMP_CONFIRM_VALUE_ERR) +#define BTA_DM_AUTH_SMP_PAIR_NOT_SUPPORT (BTA_DM_AUTH_FAIL_BASE + SMP_PAIR_NOT_SUPPORT) +#define BTA_DM_AUTH_SMP_ENC_KEY_SIZE (BTA_DM_AUTH_FAIL_BASE + SMP_ENC_KEY_SIZE) +#define BTA_DM_AUTH_SMP_INVALID_CMD (BTA_DM_AUTH_FAIL_BASE + SMP_INVALID_CMD) +#define BTA_DM_AUTH_SMP_UNKNOWN_ERR (BTA_DM_AUTH_FAIL_BASE + SMP_PAIR_FAIL_UNKNOWN) +#define BTA_DM_AUTH_SMP_REPEATED_ATTEMPT (BTA_DM_AUTH_FAIL_BASE + SMP_REPEATED_ATTEMPTS) +#define BTA_DM_AUTH_SMP_INVALID_PARAMETERS (BTA_DM_AUTH_FAIL_BASE + SMP_INVALID_PARAMETERS) +#define BTA_DM_AUTH_SMP_INTERNAL_ERR (BTA_DM_AUTH_FAIL_BASE + SMP_PAIR_INTERNAL_ERR) +#define BTA_DM_AUTH_SMP_UNKNOWN_IO (BTA_DM_AUTH_FAIL_BASE + SMP_UNKNOWN_IO_CAP) +#define BTA_DM_AUTH_SMP_INIT_FAIL (BTA_DM_AUTH_FAIL_BASE + SMP_INIT_FAIL) +#define BTA_DM_AUTH_SMP_CONFIRM_FAIL (BTA_DM_AUTH_FAIL_BASE + SMP_CONFIRM_FAIL) +#define BTA_DM_AUTH_SMP_BUSY (BTA_DM_AUTH_FAIL_BASE + SMP_BUSY) +#define BTA_DM_AUTH_SMP_ENC_FAIL (BTA_DM_AUTH_FAIL_BASE + SMP_ENC_FAIL) +#define BTA_DM_AUTH_SMP_RSP_TIMEOUT (BTA_DM_AUTH_FAIL_BASE + SMP_RSP_TIMEOUT) + +/* connection parameter boundary value and dummy value */ +#define BTA_DM_BLE_SCAN_INT_MIN BTM_BLE_SCAN_INT_MIN +#define BTA_DM_BLE_SCAN_INT_MAX BTM_BLE_SCAN_INT_MAX +#define BTA_DM_BLE_SCAN_WIN_MIN BTM_BLE_SCAN_WIN_MIN +#define BTA_DM_BLE_SCAN_WIN_MAX BTM_BLE_SCAN_WIN_MAX +#define BTA_DM_BLE_CONN_INT_MIN BTM_BLE_CONN_INT_MIN +#define BTA_DM_BLE_CONN_INT_MAX BTM_BLE_CONN_INT_MAX +#define BTA_DM_BLE_CONN_LATENCY_MAX BTM_BLE_CONN_LATENCY_MAX +#define BTA_DM_BLE_CONN_SUP_TOUT_MIN BTM_BLE_CONN_SUP_TOUT_MIN +#define BTA_DM_BLE_CONN_SUP_TOUT_MAX BTM_BLE_CONN_SUP_TOUT_MAX +#define BTA_DM_BLE_CONN_PARAM_UNDEF BTM_BLE_CONN_PARAM_UNDEF /* use this value when a specific value not to be overwritten */ + + +#define BTA_LE_KEY_PENC BTM_LE_KEY_PENC /* encryption information of peer device */ +#define BTA_LE_KEY_PID BTM_LE_KEY_PID /* identity key of the peer device */ +#define BTA_LE_KEY_PCSRK BTM_LE_KEY_PCSRK /* peer SRK */ +#define BTA_LE_KEY_LENC BTM_LE_KEY_LENC /* master role security information:div */ +#define BTA_LE_KEY_LID BTM_LE_KEY_LID /* master device ID key */ +#define BTA_LE_KEY_LCSRK BTM_LE_KEY_LCSRK /* local CSRK has been deliver to peer */ +typedef UINT8 tBTA_LE_KEY_TYPE; /* can be used as a bit mask */ + + +typedef tBTM_LE_PENC_KEYS tBTA_LE_PENC_KEYS ; +typedef tBTM_LE_PCSRK_KEYS tBTA_LE_PCSRK_KEYS; +typedef tBTM_LE_LENC_KEYS tBTA_LE_LENC_KEYS ; +typedef tBTM_LE_LCSRK_KEYS tBTA_LE_LCSRK_KEYS ; +typedef tBTM_LE_PID_KEYS tBTA_LE_PID_KEYS ; + +typedef union { + tBTA_LE_PENC_KEYS penc_key; /* received peer encryption key */ + tBTA_LE_PCSRK_KEYS psrk_key; /* received peer device SRK */ + tBTA_LE_PID_KEYS pid_key; /* peer device ID key */ + tBTA_LE_LENC_KEYS lenc_key; /* local encryption reproduction keys LTK = = d1(ER,DIV,0)*/ + tBTA_LE_LCSRK_KEYS lcsrk_key; /* local device CSRK = d1(ER,DIV,1)*/ + tBTA_LE_PID_KEYS lid_key; /* local device ID key for the particular remote */ +} tBTA_LE_KEY_VALUE; + +#define BTA_BLE_LOCAL_KEY_TYPE_ID 1 +#define BTA_BLE_LOCAL_KEY_TYPE_ER 2 +typedef UINT8 tBTA_DM_BLE_LOCAL_KEY_MASK; + +typedef struct { + BT_OCTET16 ir; + BT_OCTET16 irk; + BT_OCTET16 dhk; +} tBTA_BLE_LOCAL_ID_KEYS; + +#define BTA_DM_SEC_GRANTED BTA_SUCCESS +#define BTA_DM_SEC_PAIR_NOT_SPT BTA_DM_AUTH_SMP_PAIR_NOT_SUPPORT +#define BTA_DM_SEC_REP_ATTEMPTS BTA_DM_AUTH_SMP_REPEATED_ATTEMPT +typedef UINT8 tBTA_DM_BLE_SEC_GRANT; + + +#define BTA_DM_BLE_ONN_NONE BTM_BLE_CONN_NONE +#define BTA_DM_BLE_CONN_AUTO BTM_BLE_CONN_AUTO +#define BTA_DM_BLE_CONN_SELECTIVE BTM_BLE_CONN_SELECTIVE +typedef UINT8 tBTA_DM_BLE_CONN_TYPE; + +typedef BOOLEAN (tBTA_DM_BLE_SEL_CBACK)(BD_ADDR random_bda, UINT8 *p_remote_name); + +/* Structure associated with BTA_DM_BLE_SEC_REQ_EVT */ +typedef struct { + BD_ADDR bd_addr; /* peer address */ + BD_NAME bd_name; /* peer device name */ +} tBTA_DM_BLE_SEC_REQ; + +typedef struct { + BD_ADDR bd_addr; /* peer address */ + tBTM_LE_KEY_TYPE key_type; + tBTM_LE_KEY_VALUE *p_key_value; +} tBTA_DM_BLE_KEY; + +/* Structure associated with BTA_DM_AUTH_CMPL_EVT */ +typedef struct { + BD_ADDR bd_addr; /* BD address peer device. */ + BD_NAME bd_name; /* Name of peer device. */ + BOOLEAN key_present; /* Valid link key value in key element */ + LINK_KEY key; /* Link key associated with peer device. */ + UINT8 key_type; /* The type of Link Key */ + BOOLEAN success; /* TRUE of authentication succeeded, FALSE if failed. */ + UINT8 fail_reason; /* The HCI reason/error code for when success=FALSE */ + tBLE_ADDR_TYPE addr_type; /* Peer device address type */ + tBT_DEVICE_TYPE dev_type; +} tBTA_DM_AUTH_CMPL; + + +/* Structure associated with BTA_DM_AUTHORIZE_EVT */ +typedef struct { + BD_ADDR bd_addr; /* BD address peer device. */ + BD_NAME bd_name; /* Name of peer device. */ + tBTA_SERVICE_ID service; /* Service ID to authorize. */ +// btla-specific ++ + DEV_CLASS dev_class; +// btla-specific -- +} tBTA_DM_AUTHORIZE; + +/* Structure associated with BTA_DM_LINK_UP_EVT */ +typedef struct { + BD_ADDR bd_addr; /* BD address peer device. */ +#if BLE_INCLUDED == TRUE + tBTA_TRANSPORT link_type; +#endif +} tBTA_DM_LINK_UP; + +/* Structure associated with BTA_DM_LINK_DOWN_EVT */ +typedef struct { + BD_ADDR bd_addr; /* BD address peer device. */ + UINT8 status; /* connection open/closed */ + BOOLEAN is_removed; /* TRUE if device is removed when link is down */ +#if BLE_INCLUDED == TRUE + tBTA_TRANSPORT link_type; +#endif +} tBTA_DM_LINK_DOWN; + +/* Structure associated with BTA_DM_ROLE_CHG_EVT */ +typedef struct { + BD_ADDR bd_addr; /* BD address peer device. */ + UINT8 new_role; /* the new connection role */ +} tBTA_DM_ROLE_CHG; + +/* Structure associated with BTA_DM_BUSY_LEVEL_EVT */ +typedef struct { + UINT8 level; /* when paging or inquiring, level is 10. + Otherwise, the number of ACL links */ + UINT8 level_flags; /* indicates individual flags */ +} tBTA_DM_BUSY_LEVEL; + +#define BTA_IO_CAP_OUT BTM_IO_CAP_OUT /* 0 DisplayOnly */ +#define BTA_IO_CAP_IO BTM_IO_CAP_IO /* 1 DisplayYesNo */ +#define BTA_IO_CAP_IN BTM_IO_CAP_IN /* 2 KeyboardOnly */ +#define BTA_IO_CAP_NONE BTM_IO_CAP_NONE /* 3 NoInputNoOutput */ +#if BLE_INCLUDED == TRUE && SMP_INCLUDED == TRUE +#define BTA_IO_CAP_KBDISP BTM_IO_CAP_KBDISP /* 4 Keyboard display */ +#endif +typedef tBTM_IO_CAP tBTA_IO_CAP; + +#define BTA_AUTH_SP_NO BTM_AUTH_SP_NO /* 0 MITM Protection Not Required - Single Profile/non-bonding + Numeric comparison with automatic accept allowed */ +#define BTA_AUTH_SP_YES BTM_AUTH_SP_YES /* 1 MITM Protection Required - Single Profile/non-bonding + Use IO Capabilities to determine authentication procedure */ +#define BTA_AUTH_AP_NO BTM_AUTH_AP_NO /* 2 MITM Protection Not Required - All Profiles/dedicated bonding + Numeric comparison with automatic accept allowed */ +#define BTA_AUTH_AP_YES BTM_AUTH_AP_YES /* 3 MITM Protection Required - All Profiles/dedicated bonding + Use IO Capabilities to determine authentication procedure */ +#define BTA_AUTH_SPGB_NO BTM_AUTH_SPGB_NO /* 4 MITM Protection Not Required - Single Profiles/general bonding + Numeric comparison with automatic accept allowed */ +#define BTA_AUTH_SPGB_YES BTM_AUTH_SPGB_YES /* 5 MITM Protection Required - Single Profiles/general bonding + Use IO Capabilities to determine authentication procedure */ +typedef tBTM_AUTH_REQ tBTA_AUTH_REQ; + +#define BTA_AUTH_DD_BOND BTM_AUTH_DD_BOND /* 2 this bit is set for dedicated bonding */ +#define BTA_AUTH_GEN_BOND BTM_AUTH_SPGB_NO /* 4 this bit is set for general bonding */ +#define BTA_AUTH_BONDS BTM_AUTH_BONDS /* 6 the general/dedicated bonding bits */ + +#define BTA_LE_AUTH_NO_BOND BTM_LE_AUTH_REQ_NO_BOND /* 0*/ +#define BTA_LE_AUTH_BOND BTM_LE_AUTH_REQ_BOND /* 1 << 0 */ +#define BTA_LE_AUTH_REQ_MITM BTM_LE_AUTH_REQ_MITM /* 1 << 2 */ + +#define BTA_LE_AUTH_REQ_SC_ONLY BTM_LE_AUTH_REQ_SC_ONLY /* 1 << 3 */ +#define BTA_LE_AUTH_REQ_SC_BOND BTM_LE_AUTH_REQ_SC_BOND /* 1001 */ +#define BTA_LE_AUTH_REQ_SC_MITM BTM_LE_AUTH_REQ_SC_MITM /* 1100 */ +#define BTA_LE_AUTH_REQ_SC_MITM_BOND BTM_LE_AUTH_REQ_SC_MITM_BOND /* 1101 */ +typedef tBTM_LE_AUTH_REQ tBTA_LE_AUTH_REQ; /* combination of the above bit pattern */ + +#define BTA_OOB_NONE BTM_OOB_NONE +#define BTA_OOB_PRESENT BTM_OOB_PRESENT +#if BTM_OOB_INCLUDED == TRUE +#define BTA_OOB_UNKNOWN BTM_OOB_UNKNOWN +#endif +typedef tBTM_OOB_DATA tBTA_OOB_DATA; + +/* Structure associated with BTA_DM_SP_CFM_REQ_EVT */ +typedef struct { + /* Note: First 3 data members must be, bd_addr, dev_class, and bd_name in order */ + BD_ADDR bd_addr; /* peer address */ + DEV_CLASS dev_class; /* peer CoD */ + BD_NAME bd_name; /* peer device name */ + UINT32 num_val; /* the numeric value for comparison. If just_works, do not show this number to UI */ + BOOLEAN just_works; /* TRUE, if "Just Works" association model */ + tBTA_AUTH_REQ loc_auth_req; /* Authentication required for local device */ + tBTA_AUTH_REQ rmt_auth_req; /* Authentication required for peer device */ + tBTA_IO_CAP loc_io_caps; /* IO Capabilities of local device */ + tBTA_AUTH_REQ rmt_io_caps; /* IO Capabilities of remote device */ +} tBTA_DM_SP_CFM_REQ; + +enum { + BTA_SP_KEY_STARTED, /* passkey entry started */ + BTA_SP_KEY_ENTERED, /* passkey digit entered */ + BTA_SP_KEY_ERASED, /* passkey digit erased */ + BTA_SP_KEY_CLEARED, /* passkey cleared */ + BTA_SP_KEY_COMPLT /* passkey entry completed */ +}; +typedef UINT8 tBTA_SP_KEY_TYPE; + +/* Structure associated with BTA_DM_SP_KEYPRESS_EVT */ +typedef struct { + BD_ADDR bd_addr; /* peer address */ + tBTA_SP_KEY_TYPE notif_type; +} tBTA_DM_SP_KEY_PRESS; + +/* Structure associated with BTA_DM_SP_KEY_NOTIF_EVT */ +typedef struct { + /* Note: First 3 data members must be, bd_addr, dev_class, and bd_name in order */ + BD_ADDR bd_addr; /* peer address */ + DEV_CLASS dev_class; /* peer CoD */ + BD_NAME bd_name; /* peer device name */ + UINT32 passkey; /* the numeric value for comparison. If just_works, do not show this number to UI */ +} tBTA_DM_SP_KEY_NOTIF; + +/* Structure associated with BTA_DM_SP_RMT_OOB_EVT */ +typedef struct { + /* Note: First 3 data members must be, bd_addr, dev_class, and bd_name in order */ + BD_ADDR bd_addr; /* peer address */ + DEV_CLASS dev_class; /* peer CoD */ + BD_NAME bd_name; /* peer device name */ +} tBTA_DM_SP_RMT_OOB; + +/* Structure associated with BTA_DM_BOND_CANCEL_CMPL_EVT */ +typedef struct { + tBTA_STATUS result; /* TRUE of bond cancel succeeded, FALSE if failed. */ +} tBTA_DM_BOND_CANCEL_CMPL; + +/* Union of all security callback structures */ +typedef union { + tBTA_DM_ENABLE enable; /* BTA enabled */ + tBTA_DM_PIN_REQ pin_req; /* PIN request. */ + tBTA_DM_AUTH_CMPL auth_cmpl; /* Authentication complete indication. */ + tBTA_DM_AUTHORIZE authorize; /* Authorization request. */ + tBTA_DM_LINK_UP link_up; /* ACL connection down event */ + tBTA_DM_LINK_DOWN link_down; /* ACL connection down event */ + tBTA_DM_BUSY_LEVEL busy_level; /* System busy level */ + tBTA_DM_SP_CFM_REQ cfm_req; /* user confirm request */ + tBTA_DM_SP_KEY_NOTIF key_notif; /* passkey notification */ + tBTA_DM_SP_RMT_OOB rmt_oob; /* remote oob */ + tBTA_DM_BOND_CANCEL_CMPL bond_cancel_cmpl; /* Bond Cancel Complete indication */ + tBTA_DM_SP_KEY_PRESS key_press; /* key press notification event */ + tBTA_DM_ROLE_CHG role_chg; /* role change event */ + tBTA_DM_BLE_SEC_REQ ble_req; /* BLE SMP related request */ + tBTA_DM_BLE_KEY ble_key; /* BLE SMP keys used when pairing */ + tBTA_BLE_LOCAL_ID_KEYS ble_id_keys; /* IR event */ + BT_OCTET16 ble_er; /* ER event data */ +} tBTA_DM_SEC; + +/* Security callback */ +typedef void (tBTA_DM_SEC_CBACK)(tBTA_DM_SEC_EVT event, tBTA_DM_SEC *p_data); + +#define BTA_BLE_MULTI_ADV_ILLEGAL 0 + +/* multi adv callback event */ +#define BTA_BLE_MULTI_ADV_ENB_EVT 1 +#define BTA_BLE_MULTI_ADV_DISABLE_EVT 2 +#define BTA_BLE_MULTI_ADV_PARAM_EVT 3 +#define BTA_BLE_MULTI_ADV_DATA_EVT 4 + +typedef UINT8 tBTA_BLE_MULTI_ADV_EVT; + +/* multi adv callback */ +typedef void (tBTA_BLE_MULTI_ADV_CBACK)(tBTA_BLE_MULTI_ADV_EVT event, + UINT8 inst_id, void *p_ref, tBTA_STATUS status); +typedef UINT32 tBTA_DM_BLE_REF_VALUE; + +#define BTA_DM_BLE_PF_ENABLE_EVT BTM_BLE_PF_ENABLE +#define BTA_DM_BLE_PF_CONFIG_EVT BTM_BLE_PF_CONFIG +typedef UINT8 tBTA_DM_BLE_PF_EVT; + +#define BTA_DM_BLE_PF_ENABLE 1 +#define BTA_DM_BLE_PF_CONFIG 2 +typedef UINT8 tBTA_DM_BLE_PF_ACTION; + +/* Config callback */ +typedef void (tBTA_DM_BLE_PF_CFG_CBACK) (tBTA_DM_BLE_PF_ACTION action, + tBTA_DM_BLE_PF_COND_TYPE cfg_cond, + tBTA_DM_BLE_PF_AVBL_SPACE avbl_space, tBTA_STATUS status, + tBTA_DM_BLE_REF_VALUE ref_value); +/* Param callback */ +typedef void (tBTA_DM_BLE_PF_PARAM_CBACK) (UINT8 action_type, tBTA_DM_BLE_PF_AVBL_SPACE avbl_space, + tBTA_DM_BLE_REF_VALUE ref_value, tBTA_STATUS status); + +/* Status callback */ +typedef void (tBTA_DM_BLE_PF_STATUS_CBACK) (UINT8 action, tBTA_STATUS status, + tBTA_DM_BLE_REF_VALUE ref_value); + + +#define BTA_DM_BLE_PF_BRDCAST_ADDR_FILT 1 +#define BTA_DM_BLE_PF_SERV_DATA_CHG_FILT 2 +#define BTA_DM_BLE_PF_SERV_UUID 4 +#define BTA_DM_BLE_PF_SERV_SOLC_UUID 8 +#define BTA_DM_BLE_PF_LOC_NAME_CHECK 16 +#define BTA_DM_BLE_PF_MANUF_NAME_CHECK 32 +#define BTA_DM_BLE_PF_SERV_DATA_CHECK 64 +typedef UINT16 tBTA_DM_BLE_PF_FEAT_SEL; + +#define BTA_DM_BLE_PF_LIST_LOGIC_OR 1 +#define BTA_DM_BLE_PF_LIST_LOGIC_AND 2 +typedef UINT16 tBTA_DM_BLE_PF_LIST_LOGIC_TYPE; + +#define BTA_DM_BLE_PF_FILT_LOGIC_OR 0 +#define BTA_DM_BLE_PF_FILT_LOGIC_AND 1 +typedef UINT16 tBTA_DM_BLE_PF_FILT_LOGIC_TYPE; + +typedef UINT8 tBTA_DM_BLE_PF_RSSI_THRESHOLD; +typedef UINT8 tBTA_DM_BLE_PF_DELIVERY_MODE; +typedef UINT16 tBTA_DM_BLE_PF_TIMEOUT; +typedef UINT8 tBTA_DM_BLE_PF_TIMEOUT_CNT; +typedef UINT16 tBTA_DM_BLE_PF_ADV_TRACK_ENTRIES; + +typedef struct { + tBTA_DM_BLE_PF_FEAT_SEL feat_seln; + tBTA_DM_BLE_PF_LIST_LOGIC_TYPE list_logic_type; + tBTA_DM_BLE_PF_FILT_LOGIC_TYPE filt_logic_type; + tBTA_DM_BLE_PF_RSSI_THRESHOLD rssi_high_thres; + tBTA_DM_BLE_PF_RSSI_THRESHOLD rssi_low_thres; + tBTA_DM_BLE_PF_DELIVERY_MODE dely_mode; + tBTA_DM_BLE_PF_TIMEOUT found_timeout; + tBTA_DM_BLE_PF_TIMEOUT lost_timeout; + tBTA_DM_BLE_PF_TIMEOUT_CNT found_timeout_cnt; + tBTA_DM_BLE_PF_ADV_TRACK_ENTRIES num_of_tracking_entries; +} tBTA_DM_BLE_PF_FILT_PARAMS; + +/* Search callback events */ +#define BTA_DM_INQ_RES_EVT 0 /* Inquiry result for a peer device. */ +#define BTA_DM_INQ_CMPL_EVT 1 /* Inquiry complete. */ +#define BTA_DM_DISC_RES_EVT 2 /* Discovery result for a peer device. */ +#define BTA_DM_DISC_BLE_RES_EVT 3 /* Discovery result for BLE GATT based servoce on a peer device. */ +#define BTA_DM_DISC_CMPL_EVT 4 /* Discovery complete. */ +#define BTA_DM_DI_DISC_CMPL_EVT 5 /* Discovery complete. */ +#define BTA_DM_SEARCH_CANCEL_CMPL_EVT 6 /* Search cancelled */ + +typedef UINT8 tBTA_DM_SEARCH_EVT; + +#define BTA_DM_INQ_RES_IGNORE_RSSI BTM_INQ_RES_IGNORE_RSSI /* 0x7f RSSI value not supplied (ignore it) */ + +/* Structure associated with BTA_DM_INQ_RES_EVT */ +typedef struct { + BD_ADDR bd_addr; /* BD address peer device. */ + DEV_CLASS dev_class; /* Device class of peer device. */ + BOOLEAN remt_name_not_required; /* Application sets this flag if it already knows the name of the device */ + /* If the device name is known to application BTA skips the remote name request */ + BOOLEAN is_limited; /* TRUE, if the limited inquiry bit is set in the CoD */ + INT8 rssi; /* The rssi value */ + UINT8 *p_eir; /* received EIR */ +#if (BLE_INCLUDED == TRUE) + UINT8 inq_result_type; + UINT8 ble_addr_type; + tBTM_BLE_EVT_TYPE ble_evt_type; + tBT_DEVICE_TYPE device_type; + UINT8 flag; +#endif + +} tBTA_DM_INQ_RES; + +/* Structure associated with BTA_DM_INQ_CMPL_EVT */ +typedef struct { + UINT8 num_resps; /* Number of inquiry responses. */ +} tBTA_DM_INQ_CMPL; + +/* Structure associated with BTA_DM_DI_DISC_CMPL_EVT */ +typedef struct { + BD_ADDR bd_addr; /* BD address peer device. */ + UINT8 num_record; /* Number of DI record */ + tBTA_STATUS result; +} tBTA_DM_DI_DISC_CMPL; + +/* Structure associated with BTA_DM_DISC_RES_EVT */ +typedef struct { + BD_ADDR bd_addr; /* BD address peer device. */ + BD_NAME bd_name; /* Name of peer device. */ + tBTA_SERVICE_MASK services; /* Services found on peer device. */ +// btla-specific ++ + UINT8 *p_raw_data; /* Raw data for discovery DB */ + UINT32 raw_data_size; /* size of raw data */ + tBT_DEVICE_TYPE device_type; /* device type in case it is BLE device */ + UINT32 num_uuids; + UINT8 *p_uuid_list; +// btla-specific -- + tBTA_STATUS result; +} tBTA_DM_DISC_RES; + +/* Structure associated with tBTA_DM_DISC_BLE_RES */ +typedef struct { + BD_ADDR bd_addr; /* BD address peer device. */ + BD_NAME bd_name; /* Name of peer device. */ + tBT_UUID service; /* GATT based Services UUID found on peer device. */ +} tBTA_DM_DISC_BLE_RES; + + +/* Union of all search callback structures */ +typedef union { + tBTA_DM_INQ_RES inq_res; /* Inquiry result for a peer device. */ + tBTA_DM_INQ_CMPL inq_cmpl; /* Inquiry complete. */ + tBTA_DM_DISC_RES disc_res; /* Discovery result for a peer device. */ + tBTA_DM_DISC_BLE_RES disc_ble_res; /* discovery result for GATT based service */ + tBTA_DM_DI_DISC_CMPL di_disc; /* DI discovery result for a peer device */ + +} tBTA_DM_SEARCH; + +/* Search callback */ +typedef void (tBTA_DM_SEARCH_CBACK)(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data); + +/* Execute call back */ +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); + +#if BLE_INCLUDED == TRUE +#define BTA_DM_BLE_SEC_NONE BTM_BLE_SEC_NONE +#define BTA_DM_BLE_SEC_ENCRYPT BTM_BLE_SEC_ENCRYPT +#define BTA_DM_BLE_SEC_NO_MITM BTM_BLE_SEC_ENCRYPT_NO_MITM +#define BTA_DM_BLE_SEC_MITM BTM_BLE_SEC_ENCRYPT_MITM +typedef tBTM_BLE_SEC_ACT tBTA_DM_BLE_SEC_ACT; + +typedef tBTM_BLE_TX_TIME_MS tBTA_DM_BLE_TX_TIME_MS; +typedef tBTM_BLE_RX_TIME_MS tBTA_DM_BLE_RX_TIME_MS; +typedef tBTM_BLE_IDLE_TIME_MS tBTA_DM_BLE_IDLE_TIME_MS; +typedef tBTM_BLE_ENERGY_USED tBTA_DM_BLE_ENERGY_USED; + +#define BTA_DM_CONTRL_UNKNOWN 0 /* Unknown state */ +#define BTA_DM_CONTRL_ACTIVE 1 /* ACL link on, SCO link ongoing, sniff mode */ +#define BTA_DM_CONTRL_SCAN 2 /* Scan state - paging/inquiry/trying to connect*/ +#define BTA_DM_CONTRL_IDLE 3 /* Idle state - page scan, LE advt, inquiry scan */ + +typedef UINT8 tBTA_DM_CONTRL_STATE; + +typedef UINT8 tBTA_DM_BLE_ADV_STATE; +typedef UINT8 tBTA_DM_BLE_ADV_INFO_PRESENT; +typedef UINT8 tBTA_DM_BLE_RSSI_VALUE; +typedef UINT16 tBTA_DM_BLE_ADV_INFO_TIMESTAMP; + +typedef tBTM_BLE_TRACK_ADV_DATA tBTA_DM_BLE_TRACK_ADV_DATA; + +typedef void (tBTA_BLE_SCAN_THRESHOLD_CBACK)(tBTA_DM_BLE_REF_VALUE ref_value); + +typedef void (tBTA_BLE_SCAN_REP_CBACK) (tBTA_DM_BLE_REF_VALUE ref_value, UINT8 report_format, + UINT8 num_records, UINT16 data_len, + UINT8 *p_rep_data, tBTA_STATUS status); + +typedef void (tBTA_BLE_SCAN_SETUP_CBACK) (tBTA_BLE_BATCH_SCAN_EVT evt, + tBTA_DM_BLE_REF_VALUE ref_value, + tBTA_STATUS status); + +typedef void (tBTA_BLE_TRACK_ADV_CMPL_CBACK)(int action, tBTA_STATUS status, + tBTA_DM_BLE_PF_AVBL_SPACE avbl_space, + tBTA_DM_BLE_REF_VALUE ref_value); + +typedef void (tBTA_BLE_TRACK_ADV_CBACK)(tBTA_DM_BLE_TRACK_ADV_DATA *p_adv_data); + +typedef void (tBTA_BLE_ENERGY_INFO_CBACK)(tBTA_DM_BLE_TX_TIME_MS tx_time, + tBTA_DM_BLE_RX_TIME_MS rx_time, + tBTA_DM_BLE_IDLE_TIME_MS idle_time, + tBTA_DM_BLE_ENERGY_USED energy_used, + tBTA_DM_CONTRL_STATE ctrl_state, + tBTA_STATUS status); + +#else +typedef UINT8 tBTA_DM_BLE_SEC_ACT; +#endif + +/* Maximum service name length */ +#define BTA_SERVICE_NAME_LEN 35 +#define BTA_SERVICE_DESP_LEN BTA_SERVICE_NAME_LEN +#define BTA_PROVIDER_NAME_LEN BTA_SERVICE_NAME_LEN + + +/* link policy masks */ +#define BTA_DM_LP_SWITCH HCI_ENABLE_MASTER_SLAVE_SWITCH +#define BTA_DM_LP_HOLD HCI_ENABLE_HOLD_MODE +#define BTA_DM_LP_SNIFF HCI_ENABLE_SNIFF_MODE +#define BTA_DM_LP_PARK HCI_ENABLE_PARK_MODE +typedef UINT16 tBTA_DM_LP_MASK; + +/* power mode actions */ +#define BTA_DM_PM_NO_ACTION 0x00 /* no change to the current pm setting */ +#define BTA_DM_PM_PARK 0x10 /* prefers park mode */ +#define BTA_DM_PM_SNIFF 0x20 /* prefers sniff mode */ +#define BTA_DM_PM_SNIFF1 0x21 /* prefers sniff1 mode */ +#define BTA_DM_PM_SNIFF2 0x22 /* prefers sniff2 mode */ +#define BTA_DM_PM_SNIFF3 0x23 /* prefers sniff3 mode */ +#define BTA_DM_PM_SNIFF4 0x24 /* prefers sniff4 mode */ +#define BTA_DM_PM_SNIFF5 0x25 /* prefers sniff5 mode */ +#define BTA_DM_PM_SNIFF6 0x26 /* prefers sniff6 mode */ +#define BTA_DM_PM_SNIFF7 0x27 /* prefers sniff7 mode */ +#define BTA_DM_PM_SNIFF_USER0 0x28 /* prefers user-defined sniff0 mode (testtool only) */ +#define BTA_DM_PM_SNIFF_USER1 0x29 /* prefers user-defined sniff1 mode (testtool only) */ +#define BTA_DM_PM_ACTIVE 0x40 /* prefers active mode */ +#define BTA_DM_PM_RETRY 0x80 /* retry power mode based on current settings */ +#define BTA_DM_PM_SUSPEND 0x04 /* prefers suspend mode */ +#define BTA_DM_PM_NO_PREF 0x01 /* service has no prefernce on power mode setting. eg. connection to service got closed */ + +typedef UINT8 tBTA_DM_PM_ACTION; + +/* index to bta_dm_ssr_spec */ +#define BTA_DM_PM_SSR0 0 +#define BTA_DM_PM_SSR1 1 /* BTA_DM_PM_SSR1 will be dedicated for + HH SSR setting entry, no other profile can use it */ +#define BTA_DM_PM_SSR2 2 +#define BTA_DM_PM_SSR3 3 +#define BTA_DM_PM_SSR4 4 +#define BTA_DM_PM_SSR5 5 +#define BTA_DM_PM_SSR6 6 + +#define BTA_DM_PM_NUM_EVTS 9 + +#ifndef BTA_DM_PM_PARK_IDX +#define BTA_DM_PM_PARK_IDX 5 /* the actual index to bta_dm_pm_md[] for PARK mode */ +#endif + +#ifndef BTA_DM_PM_SNIFF_A2DP_IDX +#define BTA_DM_PM_SNIFF_A2DP_IDX BTA_DM_PM_SNIFF +#endif + +#ifndef BTA_DM_PM_SNIFF_HD_IDLE_IDX +#define BTA_DM_PM_SNIFF_HD_IDLE_IDX BTA_DM_PM_SNIFF2 +#endif + +#ifndef BTA_DM_PM_SNIFF_SCO_OPEN_IDX +#define BTA_DM_PM_SNIFF_SCO_OPEN_IDX BTA_DM_PM_SNIFF3 +#endif + +#ifndef BTA_DM_PM_SNIFF_HD_ACTIVE_IDX +#define BTA_DM_PM_SNIFF_HD_ACTIVE_IDX BTA_DM_PM_SNIFF4 +#endif + +#ifndef BTA_DM_PM_SNIFF_HH_OPEN_IDX +#define BTA_DM_PM_SNIFF_HH_OPEN_IDX BTA_DM_PM_SNIFF2 +#endif + +#ifndef BTA_DM_PM_SNIFF_HH_ACTIVE_IDX +#define BTA_DM_PM_SNIFF_HH_ACTIVE_IDX BTA_DM_PM_SNIFF2 +#endif + +#ifndef BTA_DM_PM_SNIFF_HH_IDLE_IDX +#define BTA_DM_PM_SNIFF_HH_IDLE_IDX BTA_DM_PM_SNIFF2 +#endif + + +#ifndef BTA_DM_PM_HH_OPEN_DELAY +#define BTA_DM_PM_HH_OPEN_DELAY 30000 +#endif + +#ifndef BTA_DM_PM_HH_ACTIVE_DELAY +#define BTA_DM_PM_HH_ACTIVE_DELAY 30000 +#endif + +#ifndef BTA_DM_PM_HH_IDLE_DELAY +#define BTA_DM_PM_HH_IDLE_DELAY 30000 +#endif + +/* The Sniff Parameters defined below must be ordered from highest + * latency (biggest interval) to lowest latency. If there is a conflict + * among the connected services the setting with the lowest latency will + * be selected. If a device should override a sniff parameter then it + * must insure that order is maintained. + */ +#ifndef BTA_DM_PM_SNIFF_MAX +#define BTA_DM_PM_SNIFF_MAX 800 +#define BTA_DM_PM_SNIFF_MIN 400 +#define BTA_DM_PM_SNIFF_ATTEMPT 4 +#define BTA_DM_PM_SNIFF_TIMEOUT 1 +#endif + +#ifndef BTA_DM_PM_SNIFF1_MAX +#define BTA_DM_PM_SNIFF1_MAX 400 +#define BTA_DM_PM_SNIFF1_MIN 200 +#define BTA_DM_PM_SNIFF1_ATTEMPT 4 +#define BTA_DM_PM_SNIFF1_TIMEOUT 1 +#endif + +#ifndef BTA_DM_PM_SNIFF2_MAX +#define BTA_DM_PM_SNIFF2_MAX 180 +#define BTA_DM_PM_SNIFF2_MIN 150 +#define BTA_DM_PM_SNIFF2_ATTEMPT 4 +#define BTA_DM_PM_SNIFF2_TIMEOUT 1 +#endif + +#ifndef BTA_DM_PM_SNIFF3_MAX +#define BTA_DM_PM_SNIFF3_MAX 150 +#define BTA_DM_PM_SNIFF3_MIN 50 +#define BTA_DM_PM_SNIFF3_ATTEMPT 4 +#define BTA_DM_PM_SNIFF3_TIMEOUT 1 +#endif + +#ifndef BTA_DM_PM_SNIFF4_MAX +#define BTA_DM_PM_SNIFF4_MAX 54 +#define BTA_DM_PM_SNIFF4_MIN 30 +#define BTA_DM_PM_SNIFF4_ATTEMPT 4 +#define BTA_DM_PM_SNIFF4_TIMEOUT 1 +#endif + +#ifndef BTA_DM_PM_SNIFF5_MAX +#define BTA_DM_PM_SNIFF5_MAX 36 +#define BTA_DM_PM_SNIFF5_MIN 30 +#define BTA_DM_PM_SNIFF5_ATTEMPT 2 +#define BTA_DM_PM_SNIFF5_TIMEOUT 0 +#endif + +#ifndef BTA_DM_PM_PARK_MAX +#define BTA_DM_PM_PARK_MAX 800 +#define BTA_DM_PM_PARK_MIN 400 +#define BTA_DM_PM_PARK_ATTEMPT 0 +#define BTA_DM_PM_PARK_TIMEOUT 0 +#endif + + +/* Switch callback events */ +#define BTA_DM_SWITCH_CMPL_EVT 0 /* Completion of the Switch API */ + +typedef UINT8 tBTA_DM_SWITCH_EVT; +typedef void (tBTA_DM_SWITCH_CBACK)(tBTA_DM_SWITCH_EVT event, tBTA_STATUS status); + +/* Audio routing out configuration */ +#define BTA_DM_ROUTE_NONE 0x00 /* No Audio output */ +#define BTA_DM_ROUTE_DAC 0x01 /* routing over analog output */ +#define BTA_DM_ROUTE_I2S 0x02 /* routing over digital (I2S) output */ +#define BTA_DM_ROUTE_BT_MONO 0x04 /* routing over SCO */ +#define BTA_DM_ROUTE_BT_STEREO 0x08 /* routing over BT Stereo */ +#define BTA_DM_ROUTE_HOST 0x10 /* routing over Host */ +#define BTA_DM_ROUTE_FMTX 0x20 /* routing over FMTX */ +#define BTA_DM_ROUTE_FMRX 0x40 /* routing over FMRX */ +#define BTA_DM_ROUTE_BTSNK 0x80 /* routing over BT SNK */ + +typedef UINT8 tBTA_DM_ROUTE_PATH; + + +/* Device Identification (DI) data structure +*/ +/* Used to set the DI record */ +typedef tSDP_DI_RECORD tBTA_DI_RECORD; +/* Used to get the DI record */ +typedef tSDP_DI_GET_RECORD tBTA_DI_GET_RECORD; +/* SDP discovery database */ +typedef tSDP_DISCOVERY_DB tBTA_DISCOVERY_DB; + +#ifndef BTA_DI_NUM_MAX +#define BTA_DI_NUM_MAX 3 +#endif + +/* Device features mask definitions */ +#define BTA_FEATURE_BYTES_PER_PAGE BTM_FEATURE_BYTES_PER_PAGE +#define BTA_EXT_FEATURES_PAGE_MAX BTM_EXT_FEATURES_PAGE_MAX +/* ACL type +*/ +#define BTA_DM_LINK_TYPE_BR_EDR 0x01 +#define BTA_DM_LINK_TYPE_LE 0x02 +#define BTA_DM_LINK_TYPE_ALL 0xFF +typedef UINT8 tBTA_DM_LINK_TYPE; + +#define IMMEDIATE_DELY_MODE 0x00 +#define ONFOUND_DELY_MODE 0x01 +#define BATCH_DELY_MODE 0x02 +#define ALLOW_ALL_FILTER 0x00 +#define LOWEST_RSSI_VALUE 129 + +/***************************************************************************** +** External Function Declarations +*****************************************************************************/ +#ifdef __cplusplus +extern "C" +{ +#endif + +/******************************************************************************* +** +** Function BTA_EnableBluetooth +** +** Description This function initializes BTA and prepares BTA and the +** Bluetooth protocol stack for use. This function is +** typically called at startup or when Bluetooth services +** are required by the phone. This function must be called +** before calling any other API function. +** +** +** Returns BTA_SUCCESS if successful. +** BTA_FAIL if internal failure. +** +*******************************************************************************/ +extern tBTA_STATUS BTA_EnableBluetooth(tBTA_DM_SEC_CBACK *p_cback); + +/******************************************************************************* +** +** Function BTA_DisableBluetooth +** +** Description This function disables BTA and the Bluetooth protocol +** stack. It is called when BTA is no longer being used +** by any application in the system. +** +** +** Returns void +** +*******************************************************************************/ +extern tBTA_STATUS BTA_DisableBluetooth(void); + +/******************************************************************************* +** +** Function BTA_EnableTestMode +** +** Description Enables bluetooth device under test mode +** +** +** Returns tBTA_STATUS +** +*******************************************************************************/ +extern tBTA_STATUS BTA_EnableTestMode(void); + +/******************************************************************************* +** +** Function BTA_DisableTestMode +** +** Description Disable bluetooth device under test mode +** +** +** Returns None +** +*******************************************************************************/ +extern void BTA_DisableTestMode(void); + +/******************************************************************************* +** +** Function BTA_DmSetDeviceName +** +** Description This function sets the Bluetooth name of the local device. +** +** +** Returns void +** +*******************************************************************************/ +extern void BTA_DmSetDeviceName(char *p_name); + +/******************************************************************************* +** +** Function BTA_DmSetVisibility +** +** Description This function sets the Bluetooth connectable,discoverable, +** pairable and conn paired only modesmodes of the local device. +** This controls whether other Bluetooth devices can find and connect to +** the local device. +** +** +** Returns void +** +*******************************************************************************/ +extern void BTA_DmSetVisibility(tBTA_DM_DISC disc_mode, tBTA_DM_CONN conn_mode, UINT8 pairable_mode, UINT8 conn_filter); + +/******************************************************************************* +** +** Function BTA_DmSearch +** +** Description This function searches for peer Bluetooth devices. It +** first performs an inquiry; for each device found from the +** inquiry it gets the remote name of the device. If +** parameter services is nonzero, service discovery will be +** performed on each device for the services specified. +** +** +** Returns void +** +*******************************************************************************/ +extern void BTA_DmSearch(tBTA_DM_INQ *p_dm_inq, tBTA_SERVICE_MASK services, + tBTA_DM_SEARCH_CBACK *p_cback); + +/******************************************************************************* +** +** Function BTA_DmSearchCancel +** +** Description This function cancels a search that has been initiated +** by calling BTA_DmSearch(). +** +** +** Returns void +** +*******************************************************************************/ +extern void BTA_DmSearchCancel(void); + +/******************************************************************************* +** +** Function BTA_DmDiscover +** +** Description This function performs service discovery for the services +** of a particular peer device. +** +** +** Returns void +** +*******************************************************************************/ +extern void BTA_DmDiscover(BD_ADDR bd_addr, tBTA_SERVICE_MASK services, + tBTA_DM_SEARCH_CBACK *p_cback, BOOLEAN sdp_search); + +// btla-specific ++ +/******************************************************************************* +** +** Function BTA_DmDiscoverUUID +** +** Description This function performs service discovery for the services +** of a particular peer device. +** +** +** Returns void +** +*******************************************************************************/ +extern void BTA_DmDiscoverUUID(BD_ADDR bd_addr, tSDP_UUID *uuid, + tBTA_DM_SEARCH_CBACK *p_cback, BOOLEAN sdp_search); + +/******************************************************************************* +** +** Function BTA_DmGetCachedRemoteName +** +** Description Retieve cached remote name if available +** +** Returns BTA_SUCCESS if cached name was retrieved +** BTA_FAILURE if cached name is not available +** +*******************************************************************************/ +tBTA_STATUS BTA_DmGetCachedRemoteName(BD_ADDR remote_device, UINT8 **pp_cached_name); +// btla-specific -- + +/******************************************************************************* +** +** Function BTA_DmBond +** +** Description This function initiates a bonding procedure with a peer +** device. The bonding procedure enables authentication +** and optionally encryption on the Bluetooth link. +** +** +** Returns void +** +*******************************************************************************/ +extern void BTA_DmBond(BD_ADDR bd_addr); + +/******************************************************************************* +** +** Function BTA_DmBondByTransport +** +** Description This function initiates a bonding procedure with a peer +** device by designated transport. The bonding procedure enables +** authentication and optionally encryption on the Bluetooth link. +** +** +** Returns void +** +*******************************************************************************/ +extern void BTA_DmBondByTransport(BD_ADDR bd_addr, tBTA_TRANSPORT transport); + + +/******************************************************************************* +** +** Function BTA_DmBondCancel +** +** Description This function cancels a bonding procedure with a peer +** device. +** +** +** Returns void +** +*******************************************************************************/ +extern void BTA_DmBondCancel(BD_ADDR bd_addr); + +/******************************************************************************* +** +** Function BTA_DmPinReply +** +** Description This function provides a PIN when one is requested by DM +** during a bonding procedure. The application should call +** this function after the security callback is called with +** a BTA_DM_PIN_REQ_EVT. +** +** +** Returns void +** +*******************************************************************************/ +extern void BTA_DmPinReply(BD_ADDR bd_addr, BOOLEAN accept, UINT8 pin_len, + UINT8 *p_pin); + +#if (BTM_OOB_INCLUDED == TRUE) +/******************************************************************************* +** +** Function BTA_DmLocalOob +** +** Description This function retrieves the OOB data from local controller. +** The result is reported by bta_dm_co_loc_oob(). +** +** Returns void +** +*******************************************************************************/ +extern void BTA_DmLocalOob(void); +#endif /* BTM_OOB_INCLUDED */ + +/******************************************************************************* +** +** Function BTA_DmConfirm +** +** Description This function accepts or rejects the numerical value of the +** Simple Pairing process on BTA_DM_SP_CFM_REQ_EVT +** +** Returns void +** +*******************************************************************************/ +extern void BTA_DmConfirm(BD_ADDR bd_addr, BOOLEAN accept); + +/******************************************************************************* +** +** Function BTA_DmAddDevice +** +** Description This function adds a device to the security database list +** of peer devices. This function would typically be called +** at system startup to initialize the security database with +** known peer devices. This is a direct execution function +** that may lock task scheduling on some platforms. +** +** Returns void +** +*******************************************************************************/ +extern void BTA_DmAddDevice(BD_ADDR bd_addr, DEV_CLASS dev_class, + LINK_KEY link_key, tBTA_SERVICE_MASK trusted_mask, + BOOLEAN is_trusted, UINT8 key_type, + tBTA_IO_CAP io_cap, UINT8 pin_length); + +/******************************************************************************* +** +** Function BTA_DmRemoveDevice +** +** Description This function removes a device from the security database. +** This is a direct execution function that may lock task +** scheduling on some platforms. +** +** +** Returns BTA_SUCCESS if successful. +** BTA_FAIL if operation failed. +** +*******************************************************************************/ +extern tBTA_STATUS BTA_DmRemoveDevice(BD_ADDR bd_addr); + +/******************************************************************************* +** +** Function BTA_GetEirService +** +** Description This function is called to get BTA service mask from EIR. +** +** Parameters p_eir - pointer of EIR significant part +** p_services - return the BTA service mask +** +** Returns None +** +*******************************************************************************/ +extern void BTA_GetEirService( UINT8 *p_eir, tBTA_SERVICE_MASK *p_services ); + +/******************************************************************************* +** +** Function BTA_DmGetConnectionState +** +** Description Returns whether the remote device is currently connected. +** +** Returns 0 if the device is NOT connected. +** +*******************************************************************************/ +extern UINT16 BTA_DmGetConnectionState( BD_ADDR bd_addr ); + + +/******************************************************************************* +** +** Function BTA_DmSetLocalDiRecord +** +** Description This function adds a DI record to the local SDP database. +** +** Returns BTA_SUCCESS if record set sucessfully, otherwise error code. +** +*******************************************************************************/ +extern tBTA_STATUS BTA_DmSetLocalDiRecord( tBTA_DI_RECORD *p_device_info, + UINT32 *p_handle ); + +/******************************************************************************* +** +** +** Function BTA_DmCloseACL +** +** Description This function force to close an ACL connection and remove the +** device from the security database list of known devices. +** +** Parameters: bd_addr - Address of the peer device +** remove_dev - remove device or not after link down +** transport - which transport to close + +** +** Returns void. +** +*******************************************************************************/ +extern void BTA_DmCloseACL(BD_ADDR bd_addr, BOOLEAN remove_dev, tBTA_TRANSPORT transport); + +/******************************************************************************* +** +** Function bta_dmexecutecallback +** +** Description This function will request BTA to execute a call back in the context of BTU task +** This API was named in lower case because it is only intended +** for the internal customers(like BTIF). +** +** Returns void +** +*******************************************************************************/ +extern void bta_dmexecutecallback (tBTA_DM_EXEC_CBACK *p_callback, void *p_param); + +#if (BTM_SCO_HCI_INCLUDED == TRUE) +/******************************************************************************* +** +** Function BTA_DmPcmInitSamples +** +** Description initialize the down sample converter. +** +** src_sps: original samples per second (source audio data) +** (ex. 44100, 48000) +** bits: number of bits per pcm sample (16) +** n_channels: number of channels (i.e. mono(1), stereo(2)...) +** +** Returns none +** +*******************************************************************************/ +extern void BTA_DmPcmInitSamples (UINT32 src_sps, UINT32 bits, UINT32 n_channels); + +/************************************************************************************** +** Function BTA_DmPcmResample +** +** Description Down sampling utility to convert higher sampling rate into 8K/16bits +** PCM samples. +** +** Parameters p_src: pointer to the buffer where the original sampling PCM +** are stored. +** in_bytes: Length of the input PCM sample buffer in byte. +** p_dst: pointer to the buffer which is to be used to store +** the converted PCM samples. +** +** +** Returns INT32: number of samples converted. +** +**************************************************************************************/ +extern INT32 BTA_DmPcmResample (void *p_src, UINT32 in_bytes, void *p_dst); +#endif + +#if ((defined BLE_INCLUDED) && (BLE_INCLUDED == TRUE)) +/* BLE related API functions */ +/******************************************************************************* +** +** Function BTA_DmBleSecurityGrant +** +** Description Grant security request access. +** +** Parameters: bd_addr - BD address of the peer +** res - security grant status. +** +** Returns void +** +*******************************************************************************/ +extern void BTA_DmBleSecurityGrant(BD_ADDR bd_addr, tBTA_DM_BLE_SEC_GRANT res); + + + +/******************************************************************************* +** +** Function BTA_DmBleSetBgConnType +** +** Description This function is called to set BLE connectable mode for a +** peripheral device. +** +** Parameters bg_conn_type: it can be auto connection, or selective connection. +** p_select_cback: callback function when selective connection procedure +** is being used. +** +** Returns void +** +*******************************************************************************/ +extern void BTA_DmBleSetBgConnType(tBTA_DM_BLE_CONN_TYPE bg_conn_type, tBTA_DM_BLE_SEL_CBACK *p_select_cback); + +/******************************************************************************* +** +** Function BTA_DmBlePasskeyReply +** +** Description Send BLE SMP passkey reply. +** +** Parameters: bd_addr - BD address of the peer +** accept - passkey entry sucessful or declined. +** passkey - passkey value, must be a 6 digit number, +** can be lead by 0. +** +** Returns void +** +*******************************************************************************/ +extern void BTA_DmBlePasskeyReply(BD_ADDR bd_addr, BOOLEAN accept, UINT32 passkey); + +/******************************************************************************* +** +** Function BTA_DmBleConfirmReply +** +** Description Send BLE SMP SC user confirmation reply. +** +** Parameters: bd_addr - BD address of the peer +** accept - numbers to compare are the same or different. +** +** Returns void +** +*******************************************************************************/ +extern void BTA_DmBleConfirmReply(BD_ADDR bd_addr, BOOLEAN accept); + +/******************************************************************************* +** +** Function BTA_DmAddBleDevice +** +** Description Add a BLE device. This function will be normally called +** during host startup to restore all required information +** for a LE device stored in the NVRAM. +** +** Parameters: bd_addr - BD address of the peer +** dev_type - Remote device's device type. +** addr_type - LE device address type. +** +** Returns void +** +*******************************************************************************/ +extern void BTA_DmAddBleDevice(BD_ADDR bd_addr, tBLE_ADDR_TYPE addr_type, + tBT_DEVICE_TYPE dev_type); + + +/******************************************************************************* +** +** Function BTA_DmAddBleKey +** +** Description Add/modify LE device information. This function will be +** normally called during host startup to restore all required +** information stored in the NVRAM. +** +** Parameters: bd_addr - BD address of the peer +** p_le_key - LE key values. +** key_type - LE SMP key type. +** +** Returns void +** +*******************************************************************************/ +extern void BTA_DmAddBleKey (BD_ADDR bd_addr, + tBTA_LE_KEY_VALUE *p_le_key, + tBTA_LE_KEY_TYPE key_type); + +/******************************************************************************* +** +** Function BTA_DmSetBlePrefConnParams +** +** Description This function is called to set the preferred connection +** parameters when default connection parameter is not desired. +** +** Parameters: bd_addr - BD address of the peripheral +** min_conn_int - minimum preferred connection interval +** max_conn_int - maximum preferred connection interval +** slave_latency - preferred slave latency +** supervision_tout - preferred supervision timeout +** +** +** Returns void +** +*******************************************************************************/ +extern void BTA_DmSetBlePrefConnParams(BD_ADDR bd_addr, + UINT16 min_conn_int, UINT16 max_conn_int, + UINT16 slave_latency, UINT16 supervision_tout ); + +/******************************************************************************* +** +** Function BTA_DmSetBleConnScanParams +** +** Description This function is called to set scan parameters used in +** BLE connection request +** +** Parameters: scan_interval - scan interval +** scan_window - scan window +** +** Returns void +** +*******************************************************************************/ +extern void BTA_DmSetBleConnScanParams(UINT32 scan_interval, + UINT32 scan_window); + +/******************************************************************************* +** +** Function BTA_DmSetBleScanParams +** +** Description This function is called to set scan parameters +** +** Parameters: client_if - Client IF +** scan_interval - scan interval +** scan_window - scan window +** scan_mode - scan mode +** scan_param_setup_status_cback - Set scan param status callback +** +** Returns void +** +*******************************************************************************/ +extern void BTA_DmSetBleScanParams(tGATT_IF client_if, UINT32 scan_interval, + UINT32 scan_window, tBLE_SCAN_MODE scan_mode, + tBLE_SCAN_PARAM_SETUP_CBACK scan_param_setup_status_cback); + + +/******************************************************************************* +** +** Function BTA_DmSetBleScanFilterParams +** +** Description This function is called to set scan parameters +** +** Parameters: client_if - Client IF +** scan_interval - scan interval +** scan_window - scan window +** scan_mode - scan mode +** scan_param_setup_status_cback - Set scan param status callback +** +** Returns void +** +*******************************************************************************/ +extern void BTA_DmSetBleScanFilterParams(tGATT_IF client_if, UINT32 scan_interval, + UINT32 scan_window, tBLE_SCAN_MODE scan_mode, UINT8 scan_fil_poilcy, + UINT8 addr_type_own, tBLE_SCAN_PARAM_SETUP_CBACK scan_param_setup_cback); + + +/******************************************************************************* +** +** Function BTA_DmSetBleAdvParams +** +** Description This function sets the advertising parameters BLE functionality. +** It is to be called when device act in peripheral or broadcaster +** role. +** +** Parameters: adv_int_min - adv interval minimum +** adv_int_max - adv interval max +** p_dir_bda - directed adv initator address +** +** Returns void +** +*******************************************************************************/ +extern void BTA_DmSetBleAdvParams (UINT16 adv_int_min, UINT16 adv_int_max, + tBLE_BD_ADDR *p_dir_bda); + +extern void BTA_DmSetBleAdvParamsAll (UINT16 adv_int_min, UINT16 adv_int_max, + UINT8 adv_type, tBLE_ADDR_TYPE addr_type_own, + tBTM_BLE_ADV_CHNL_MAP chnl_map, tBTM_BLE_AFP adv_fil_pol, + tBLE_BD_ADDR *p_dir_bda); + + +/******************************************************************************* +** +** Function BTA_DmSearchExt +** +** Description This function searches for peer Bluetooth devices. It performs +** an inquiry and gets the remote name for devices. Service +** discovery is done if services is non zero +** +** Parameters p_dm_inq: inquiry conditions +** services: if service is not empty, service discovery will be done. +** for all GATT based service condition, put num_uuid, and +** p_uuid is the pointer to the list of UUID values. +** p_cback: callback functino when search is completed. +** +** +** +** Returns void +** +*******************************************************************************/ +extern void BTA_DmSearchExt(tBTA_DM_INQ *p_dm_inq, tBTA_SERVICE_MASK_EXT *p_services, + tBTA_DM_SEARCH_CBACK *p_cback); + +/******************************************************************************* +** +** Function BTA_DmDiscoverExt +** +** Description This function does service discovery for services of a +** peer device. When services.num_uuid is 0, it indicates all +** GATT based services are to be searched; other wise a list of +** UUID of interested services should be provided through +** services.p_uuid. +** +** +** +** Returns void +** +*******************************************************************************/ +extern void BTA_DmDiscoverExt(BD_ADDR bd_addr, tBTA_SERVICE_MASK_EXT *p_services, + tBTA_DM_SEARCH_CBACK *p_cback, BOOLEAN sdp_search); + +/******************************************************************************* +** +** Function BTA_DmDiscoverByTransport +** +** Description This function does service discovery on particular transport +** for services of a +** peer device. When services.num_uuid is 0, it indicates all +** GATT based services are to be searched; other wise a list of +** UUID of interested services should be provided through +** p_services->p_uuid. +** +** +** +** Returns void +** +*******************************************************************************/ +extern void BTA_DmDiscoverByTransport(BD_ADDR bd_addr, tBTA_SERVICE_MASK_EXT *p_services, + tBTA_DM_SEARCH_CBACK *p_cback, BOOLEAN sdp_search, + tBTA_TRANSPORT transport); + +/******************************************************************************* +** +** Function BTA_DmSetEncryption +** +** Description This function is called to ensure that connection is +** encrypted. Should be called only on an open connection. +** Typically only needed for connections that first want to +** bring up unencrypted links, then later encrypt them. +** +** Parameters: bd_addr - Address of the peer device +** transport - transport of the link to be encruypted +** p_callback - Pointer to callback function to indicat the +** link encryption status +** sec_act - This is the security action to indicate +** what knid of BLE security level is required for +** the BLE link if the BLE is supported +** Note: This parameter is ignored for the BR/EDR link +** or the BLE is not supported +** +** Returns void +** +** +*******************************************************************************/ +extern void BTA_DmSetEncryption(BD_ADDR bd_addr, tBTA_TRANSPORT transport, + tBTA_DM_ENCRYPT_CBACK *p_callback, + tBTA_DM_BLE_SEC_ACT sec_act); + + +/******************************************************************************* +** +** Function BTA_DmBleObserve +** +** Description This procedure keep the device listening for advertising +** events from a broadcast device. +** +** Parameters start: start or stop observe. +** duration : Duration of the scan. Continuous scan if 0 is passed +** p_results_cb: Callback to be called with scan results +** +** Returns void +** +*******************************************************************************/ +extern void BTA_DmBleObserve(BOOLEAN start, UINT8 duration, + tBTA_DM_SEARCH_CBACK *p_results_cb); + +extern void BTA_DmBleStopAdvertising(void); + +extern void BTA_DmSetRandAddress(BD_ADDR rand_addr); + +#endif + +#if BLE_INCLUDED == TRUE +// btla-specific -- +/******************************************************************************* +** +** Function BTA_DmBleConfigLocalPrivacy +** +** Description Enable/disable privacy on the local device +** +** Parameters: privacy_enable - enable/disabe privacy on remote device. +** +** Returns void +** +*******************************************************************************/ +extern void BTA_DmBleConfigLocalPrivacy(BOOLEAN privacy_enable); + +/******************************************************************************* +** +** Function BTA_DmBleEnableRemotePrivacy +** +** Description Enable/disable privacy on a remote device +** +** Parameters: bd_addr - BD address of the peer +** privacy_enable - enable/disabe privacy on remote device. +** +** Returns void +** +*******************************************************************************/ +extern void BTA_DmBleEnableRemotePrivacy(BD_ADDR bd_addr, BOOLEAN privacy_enable); + + +/******************************************************************************* +** +** Function BTA_DmBleSetAdvConfig +** +** Description This function is called to override the BTA default ADV parameters. +** +** Parameters Pointer to User defined ADV data structure +** +** Returns None +** +*******************************************************************************/ +extern void BTA_DmBleSetAdvConfig (tBTA_BLE_AD_MASK data_mask, + tBTA_BLE_ADV_DATA *p_adv_cfg, + tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback); + +/******************************************************************************* +** +** Function BTA_DmBleSetAdvConfigRaw +** +** Description This function is called to set raw Advertising data +** +** Parameters p_raw_adv : raw advertising data. +** raw_adv_len : raw advertising data length. +** p_adv_data_cback : set adv data complete callback. +** +** Returns None +** +*******************************************************************************/ +extern void BTA_DmBleSetAdvConfigRaw (UINT8 *p_raw_adv, UINT32 raw_adv_len, + tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback); + +/******************************************************************************* +** +** Function BTA_DmBleSetScanRsp +** +** Description This function is called to override the BTA scan response. +** +** Parameters Pointer to User defined ADV data structure +** +** Returns None +** +*******************************************************************************/ +extern void BTA_DmBleSetScanRsp (tBTA_BLE_AD_MASK data_mask, + tBTA_BLE_ADV_DATA *p_adv_cfg, + tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback); + +/******************************************************************************* +** +** Function BTA_DmBleSetScanRspRaw +** +** Description This function is called to set raw scan response data +** +** Parameters p_raw_scan_rsp : raw scan_rspertising data. +** raw_scan_rsp_len : raw scan_rspertising data length. +** p_scan_rsp_data_cback : set scan_rsp data complete callback. +** +** Returns None +** +*******************************************************************************/ +extern void BTA_DmBleSetScanRspRaw (UINT8 *p_raw_scan_rsp, UINT32 raw_scan_rsp_len, + tBTA_SET_ADV_DATA_CMPL_CBACK *p_scan_rsp_data_cback); + +/******************************************************************************* +** +** Function BTA_DmBleBroadcast +** +** Description This function starts or stops LE broadcasting. +** +** Parameters start: start or stop broadcast. +** +** Returns None +** +*******************************************************************************/ +extern void BTA_DmBleBroadcast (BOOLEAN start); + + +/******************************************************************************* +** +** Function BTA_BleEnableAdvInstance +** +** Description This function enables the Multi ADV instance feature +** +** Parameters p_params Pointer to ADV param user defined structure +** p_cback Pointer to Multi ADV callback structure +** p_ref - Reference pointer +** +** Returns None +** +*******************************************************************************/ +extern void BTA_BleEnableAdvInstance (tBTA_BLE_ADV_PARAMS *p_params, + tBTA_BLE_MULTI_ADV_CBACK *p_cback, void *p_ref); + +/******************************************************************************* +** +** Function BTA_BleUpdateAdvInstParam +** +** Description This function updates the Multi ADV instance params +** +** Parameters inst_id Instance ID +** p_params Pointer to ADV param user defined structure +** +** Returns None +** +*******************************************************************************/ +extern void BTA_BleUpdateAdvInstParam (UINT8 inst_id, + tBTA_BLE_ADV_PARAMS *p_params); + +/******************************************************************************* +** +** Function BTA_BleCfgAdvInstData +** +** Description This function is called to configure the ADV instance data +** +** Parameters inst_id - Instance ID +** is_scan_rsp - Boolean value Scan response +** Pointer to User defined ADV data structure +** Returns None +** +*******************************************************************************/ +extern void BTA_BleCfgAdvInstData (UINT8 inst_id, BOOLEAN is_scan_rsp, + tBTA_BLE_AD_MASK data_mask, tBTA_BLE_ADV_DATA *p_data); + +/******************************************************************************* +** +** Function BTA_BleDisableAdvInstance +** +** Description This function is called to disable the ADV instance +** +** Parameters inst_id - Instance ID to be disabled +** +** Returns None +** +*******************************************************************************/ +extern void BTA_BleDisableAdvInstance(UINT8 inst_id); + +/******************************************************************************* +** +** Function BTA_DmBleUpdateConnectionParams +** +** Description Update connection parameters, can only be used when connection is up. +** +** Parameters: bd_addr - BD address of the peer +** min_int - minimum connection interval, [0x0004~ 0x4000] +** max_int - maximum connection interval, [0x0004~ 0x4000] +** latency - slave latency [0 ~ 500] +** timeout - supervision timeout [0x000a ~ 0xc80] +** +** Returns void +** +*******************************************************************************/ +extern void BTA_DmBleUpdateConnectionParams(BD_ADDR bd_addr, UINT16 min_int, + UINT16 max_int, UINT16 latency, UINT16 timeout); + +/******************************************************************************* +** +** Function BTA_DmBleSetDataLength +** +** Description This function is to set maximum LE data packet size +** +** Returns void +** +*******************************************************************************/ +extern void BTA_DmBleSetDataLength(BD_ADDR remote_device, UINT16 tx_data_length); + +/******************************************************************************* +** +** Function BTA_DmBleSetStorageParams +** +** Description This function is called to set the storage parameters +** +** Parameters batch_scan_full_max -Max storage space (in %) allocated to full scanning +** batch_scan_trunc_max -Max storage space (in %) allocated to truncated scanning +** batch_scan_notify_threshold - Setup notification level based on total space +** consumed by both pools. Setting it to 0 will disable threshold notification +** p_setup_cback - Setup callback +** p_thres_cback - Threshold callback +** p_rep_cback - Reports callback +** ref_value - Reference value +** +** Returns None +** +*******************************************************************************/ +extern void BTA_DmBleSetStorageParams(UINT8 batch_scan_full_max, + UINT8 batch_scan_trunc_max, + UINT8 batch_scan_notify_threshold, + tBTA_BLE_SCAN_SETUP_CBACK *p_setup_cback, + tBTA_BLE_SCAN_THRESHOLD_CBACK *p_thres_cback, + tBTA_BLE_SCAN_REP_CBACK *p_rep_cback, + tBTA_DM_BLE_REF_VALUE ref_value); + +/******************************************************************************* +** +** Function BTA_DmBleEnableBatchScan +** +** Description This function is called to enable the batch scan +** +** Parameters scan_mode -Batch scan mode +** scan_interval - Scan interval +** scan_window - Scan window +** discard_rule -Discard rules +** addr_type - Address type +** ref_value - Reference value +** +** Returns None +** +*******************************************************************************/ +extern void BTA_DmBleEnableBatchScan(tBTA_BLE_BATCH_SCAN_MODE scan_mode, + UINT32 scan_interval, UINT32 scan_window, + tBTA_BLE_DISCARD_RULE discard_rule, + tBLE_ADDR_TYPE addr_type, + tBTA_DM_BLE_REF_VALUE ref_value); + +/******************************************************************************* +** +** Function BTA_DmBleReadScanReports +** +** Description This function is called to read the batch scan reports +** +** Parameters scan_mode -Batch scan mode +** ref_value - Reference value +** +** Returns None +** +*******************************************************************************/ +extern void BTA_DmBleReadScanReports(tBTA_BLE_BATCH_SCAN_MODE scan_type, + tBTA_DM_BLE_REF_VALUE ref_value); + +/******************************************************************************* +** +** Function BTA_DmBleDisableBatchScan +** +** Description This function is called to disable the batch scanning +** +** Parameters ref_value - Reference value +** +** Returns None +** +*******************************************************************************/ +extern void BTA_DmBleDisableBatchScan(tBTA_DM_BLE_REF_VALUE ref_value); + +/******************************************************************************* +** +** Function BTA_DmEnableScanFilter +** +** Description This function is called to enable the adv data payload filter +** +** Parameters action - enable or disable the APCF feature +** p_cmpl_cback - Command completed callback +** ref_value - Reference value +** +** Returns void +** +*******************************************************************************/ +extern void BTA_DmEnableScanFilter(UINT8 action, + tBTA_DM_BLE_PF_STATUS_CBACK *p_cmpl_cback, + tBTA_DM_BLE_REF_VALUE ref_value); + +/******************************************************************************* +** +** Function BTA_DmBleScanFilterSetup +** +** Description This function is called to setup the filter params +** +** Parameters p_target: enable the filter condition on a target device; if NULL +** filt_index - Filter index +** p_filt_params -Filter parameters +** ref_value - Reference value +** action - Add, delete or clear +** p_cmpl_back - Command completed callback +** +** Returns void +** +*******************************************************************************/ +extern void BTA_DmBleScanFilterSetup(UINT8 action, + tBTA_DM_BLE_PF_FILT_INDEX filt_index, + tBTA_DM_BLE_PF_FILT_PARAMS *p_filt_params, + tBLE_BD_ADDR *p_target, + tBTA_DM_BLE_PF_PARAM_CBACK *p_cmpl_cback, + tBTA_DM_BLE_REF_VALUE ref_value); + +/******************************************************************************* +** +** Function BTA_DmBleCfgFilterCondition +** +** Description This function is called to configure the adv data payload filter +** condition. +** +** Parameters action: to read/write/clear +** cond_type: filter condition type +** filt_index - Filter index +** p_cond: filter condition parameter +** p_cmpl_back - Command completed callback +** ref_value - Reference value +** +** Returns void +** +*******************************************************************************/ +extern void BTA_DmBleCfgFilterCondition(tBTA_DM_BLE_SCAN_COND_OP action, + tBTA_DM_BLE_PF_COND_TYPE cond_type, + tBTA_DM_BLE_PF_FILT_INDEX filt_index, + tBTA_DM_BLE_PF_COND_PARAM *p_cond, + tBTA_DM_BLE_PF_CFG_CBACK *p_cmpl_cback, + tBTA_DM_BLE_REF_VALUE ref_value); + + +/******************************************************************************* +** +** Function BTA_DmBleTrackAdvertiser +** +** Description This function is called to track the advertiser +** +** Parameters ref_value - Reference value +** p_track_adv_cback - ADV callback +** +** Returns None +** +*******************************************************************************/ +extern void BTA_DmBleTrackAdvertiser(tBTA_DM_BLE_REF_VALUE ref_value, + tBTA_BLE_TRACK_ADV_CBACK *p_track_adv_cback); + +/******************************************************************************* +** +** Function BTA_DmBleGetEnergyInfo +** +** Description This function is called to obtain the energy info +** +** Parameters p_cmpl_cback - Command complete callback +** +** Returns void +** +*******************************************************************************/ +extern void BTA_DmBleGetEnergyInfo(tBTA_BLE_ENERGY_INFO_CBACK *p_cmpl_cback); + +/******************************************************************************* +** +** Function BTA_BrcmInit +** +** Description This function initializes Broadcom specific VS handler in BTA +** +** Returns void +** +*******************************************************************************/ +extern void BTA_VendorInit (void); + +/******************************************************************************* +** +** Function BTA_BrcmCleanup +** +** Description This function frees up Broadcom specific VS specific dynamic memory +** +** Returns void +** +*******************************************************************************/ +extern void BTA_VendorCleanup (void); + +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* BTA_API_H */ diff --git a/tools/sdk/include/bluedroid/bta_dm_ci.h b/tools/sdk/include/bluedroid/bta_dm_ci.h new file mode 100644 index 00000000..9f8a8743 --- /dev/null +++ b/tools/sdk/include/bluedroid/bta_dm_ci.h @@ -0,0 +1,80 @@ +/****************************************************************************** + * + * Copyright (C) 2006-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 is the interface file for device mananger call-in functions. + * + ******************************************************************************/ +#ifndef BTA_DM_CI_H +#define BTA_DM_CI_H + +#include "bta_api.h" + +/***************************************************************************** +** Function Declarations +*****************************************************************************/ +#ifdef __cplusplus +extern "C" +{ +#endif + +/******************************************************************************* +** +** Function bta_dm_ci_io_req +** +** Description This function must be called in response to function +** bta_dm_co_io_req(), if *p_oob_data is set to BTA_OOB_UNKNOWN +** by bta_dm_co_io_req(). +** +** Returns void +** +*******************************************************************************/ +extern void bta_dm_ci_io_req(BD_ADDR bd_addr, tBTA_IO_CAP io_cap, + tBTA_OOB_DATA oob_data, tBTA_AUTH_REQ auth_req); + +/******************************************************************************* +** +** Function bta_dm_ci_rmt_oob +** +** Description This function must be called in response to function +** bta_dm_co_rmt_oob() to provide the OOB data associated +** with the remote device. +** +** Returns void +** +*******************************************************************************/ +extern void bta_dm_ci_rmt_oob(BOOLEAN accept, BD_ADDR bd_addr, + BT_OCTET16 c, BT_OCTET16 r); +/******************************************************************************* +** +** Function bta_dm_sco_ci_data_ready +** +** Description This function sends an event to indicating that the phone +** has SCO data ready.. +** +** Returns void +** +*******************************************************************************/ +extern void bta_dm_sco_ci_data_ready(UINT16 event, UINT16 sco_handle); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/tools/sdk/include/bluedroid/bta_dm_co.h b/tools/sdk/include/bluedroid/bta_dm_co.h new file mode 100644 index 00000000..c3202496 --- /dev/null +++ b/tools/sdk/include/bluedroid/bta_dm_co.h @@ -0,0 +1,273 @@ +/****************************************************************************** + * + * Copyright (C) 2006-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 is the interface file for device mananger callout functions. + * + ******************************************************************************/ +#ifndef BTA_DM_CO_H +#define BTA_DM_CO_H + +#include "bta_sys.h" + + +#ifndef BTA_SCO_OUT_PKT_SIZE +#define BTA_SCO_OUT_PKT_SIZE BTM_SCO_DATA_SIZE_MAX +#endif + +#define BTA_SCO_CODEC_PCM 0 /* used for regular SCO */ +#define BTA_SCO_CODEC_SBC 1 /* used for WBS */ +typedef UINT8 tBTA_SCO_CODEC_TYPE; + +#define BTA_DM_SCO_SAMP_RATE_8K 8000 +#define BTA_DM_SCO_SAMP_RATE_16K 16000 + +/* SCO codec information */ +typedef struct { + tBTA_SCO_CODEC_TYPE codec_type; +} tBTA_CODEC_INFO; + +#define BTA_DM_SCO_ROUTE_PCM BTM_SCO_ROUTE_PCM +#define BTA_DM_SCO_ROUTE_HCI BTM_SCO_ROUTE_HCI + +typedef tBTM_SCO_ROUTE_TYPE tBTA_DM_SCO_ROUTE_TYPE; + + +/***************************************************************************** +** Function Declarations +*****************************************************************************/ + +/******************************************************************************* +** +** Function bta_dm_co_io_req +** +** Description This callout function is executed by DM to get IO capabilities +** of the local device for the Simple Pairing process +** +** Parameters bd_addr - The peer device +** *p_io_cap - The local Input/Output capabilities +** *p_oob_data - TRUE, if OOB data is available for the peer device. +** *p_auth_req - TRUE, if MITM protection is required. +** +** Returns void. +** +*******************************************************************************/ +extern void bta_dm_co_io_req(BD_ADDR bd_addr, tBTA_IO_CAP *p_io_cap, + tBTA_OOB_DATA *p_oob_data, tBTA_AUTH_REQ *p_auth_req, + BOOLEAN is_orig); + +/******************************************************************************* +** +** Function bta_dm_co_io_rsp +** +** Description This callout function is executed by DM to report IO capabilities +** of the peer device for the Simple Pairing process +** +** Parameters bd_addr - The peer device +** io_cap - The remote Input/Output capabilities +** oob_data - TRUE, if OOB data is available for the peer device. +** auth_req - TRUE, if MITM protection is required. +** +** Returns void. +** +*******************************************************************************/ +extern void bta_dm_co_io_rsp(BD_ADDR bd_addr, tBTA_IO_CAP io_cap, + tBTA_OOB_DATA oob_data, tBTA_AUTH_REQ auth_req); + +/******************************************************************************* +** +** Function bta_dm_co_lk_upgrade +** +** Description This callout function is executed by DM to check if the +** platform wants allow link key upgrade +** +** Parameters bd_addr - The peer device +** *p_upgrade - TRUE, if link key upgrade is desired. +** +** Returns void. +** +*******************************************************************************/ +extern void bta_dm_co_lk_upgrade(BD_ADDR bd_addr, BOOLEAN *p_upgrade ); + +/******************************************************************************* +** +** Function bta_dm_co_loc_oob +** +** Description This callout function is executed by DM to report the OOB +** data of the local device for the Simple Pairing process +** +** Parameters valid - TRUE, if the local OOB data is retrieved from LM +** c - Simple Pairing Hash C +** r - Simple Pairing Randomnizer R +** +** Returns void. +** +*******************************************************************************/ +extern void bta_dm_co_loc_oob(BOOLEAN valid, BT_OCTET16 c, BT_OCTET16 r); + +/******************************************************************************* +** +** Function bta_dm_co_rmt_oob +** +** Description This callout function is executed by DM to request the OOB +** data for the remote device for the Simple Pairing process +** +** Parameters bd_addr - The peer device +** +** Returns void. +** +*******************************************************************************/ +extern void bta_dm_co_rmt_oob(BD_ADDR bd_addr); + +/***************************************************************************** +** SCO over HCI Function Declarations +*****************************************************************************/ +/******************************************************************************* +** +** Function bta_dm_sco_co_init +** +** Description This function can be used by the phone to initialize audio +** codec or for other initialization purposes before SCO connection +** is opened. +** +** +** Returns Void. +** +*******************************************************************************/ +extern tBTA_DM_SCO_ROUTE_TYPE bta_dm_sco_co_init(UINT32 rx_bw, UINT32 tx_bw, + tBTA_CODEC_INFO *p_codec_info, UINT8 app_id); + + +/******************************************************************************* +** +** Function bta_dm_sco_co_open +** +** Description This function is executed when a SCO connection is open. +** +** +** Returns void +** +*******************************************************************************/ +extern void bta_dm_sco_co_open(UINT16 handle, UINT8 pkt_size, UINT16 event); + +/******************************************************************************* +** +** Function bta_dm_sco_co_close +** +** Description This function is called when a SCO connection is closed +** +** +** Returns void +** +*******************************************************************************/ +extern void bta_dm_sco_co_close(void); + +/******************************************************************************* +** +** Function bta_dm_sco_co_out_data +** +** Description This function is called to send SCO data over HCI. +** +** Returns void +** +*******************************************************************************/ +extern void bta_dm_sco_co_out_data(BT_HDR **p_buf); + +/******************************************************************************* +** +** Function bta_dm_sco_co_in_data +** +** Description This function is called to send incoming SCO data to application. +** +** Returns void +** +*******************************************************************************/ +extern void bta_dm_sco_co_in_data(BT_HDR *p_buf, tBTM_SCO_DATA_FLAG status); + + + +/******************************************************************************* +** +** Function bta_dm_co_ble_io_req +** +** Description This callout function is executed by DM to get BLE IO capabilities +** before SMP pairing gets going. +** +** Parameters bd_addr - The peer device +** *p_io_cap - The local Input/Output capabilities +** *p_oob_data - TRUE, if OOB data is available for the peer device. +** *p_auth_req - Auth request setting (Bonding and MITM required or not) +** *p_max_key_size - max key size local device supported. +** *p_init_key - initiator keys. +** *p_resp_key - responder keys. +** +** Returns void. +** +*******************************************************************************/ +extern void bta_dm_co_ble_io_req(BD_ADDR bd_addr, tBTA_IO_CAP *p_io_cap, + tBTA_OOB_DATA *p_oob_data, + tBTA_LE_AUTH_REQ *p_auth_req, + UINT8 *p_max_key_size, + tBTA_LE_KEY_TYPE *p_init_key, + tBTA_LE_KEY_TYPE *p_resp_key ); + + +/******************************************************************************* +** +** Function bta_dm_co_ble_local_key_reload +** +** Description This callout function is to load the local BLE keys if available +** on the device. +** +** Parameters none +** +** Returns void. +** +*******************************************************************************/ +extern void bta_dm_co_ble_load_local_keys (tBTA_DM_BLE_LOCAL_KEY_MASK *p_key_mask, BT_OCTET16 er, + tBTA_BLE_LOCAL_ID_KEYS *p_id_keys); + +// btla-specific ++ +/******************************************************************************* +** +** Function bta_dm_co_ble_io_req +** +** Description This callout function is executed by DM to get BLE IO capabilities +** before SMP pairing gets going. +** +** Parameters bd_addr - The peer device +** *p_io_cap - The local Input/Output capabilities +** *p_oob_data - TRUE, if OOB data is available for the peer device. +** *p_auth_req - Auth request setting (Bonding and MITM required or not) +** *p_max_key_size - max key size local device supported. +** *p_init_key - initiator keys. +** *p_resp_key - responder keys. +** +** Returns void. +** +*******************************************************************************/ +extern void bta_dm_co_ble_io_req(BD_ADDR bd_addr, tBTA_IO_CAP *p_io_cap, + tBTA_OOB_DATA *p_oob_data, + tBTA_LE_AUTH_REQ *p_auth_req, + UINT8 *p_max_key_size, + tBTA_LE_KEY_TYPE *p_init_key, + tBTA_LE_KEY_TYPE *p_resp_key ); +// btla-specific -- + +#endif diff --git a/tools/sdk/include/bluedroid/bta_gatt_api.h b/tools/sdk/include/bluedroid/bta_gatt_api.h new file mode 100644 index 00000000..f4c0e06f --- /dev/null +++ b/tools/sdk/include/bluedroid/bta_gatt_api.h @@ -0,0 +1,1416 @@ +/****************************************************************************** + * + * Copyright (C) 2003-2013 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 is the public interface file for BTA GATT. + * + ******************************************************************************/ + +#ifndef BTA_GATT_API_H +#define BTA_GATT_API_H + +#include "bta_api.h" +#include "gatt_api.h" + +#ifndef BTA_GATT_INCLUDED +#warning BTA_GATT_INCLUDED not defined +#define BTA_GATT_INCLUDED FALSE +#endif + +#if ((BLE_INCLUDED == FALSE) && (BTA_GATT_INCLUDED == TRUE)) +#undef BTA_GATT_INCLUDED +#define BTA_GATT_INCLUDED FALSE +#endif + + +#ifndef BTA_GATT_DEBUG +#define BTA_GATT_DEBUG FALSE +#endif + +/***************************************************************************** +** Constants and data types +*****************************************************************************/ +/************************** +** Common Definitions +***************************/ +/* GATT ID */ +typedef struct { + tBT_UUID uuid; /* uuid of the attribute */ + UINT8 inst_id; /* instance ID */ +} __attribute__((packed)) tBTA_GATT_ID; + +/* Success code and error codes */ +#define BTA_GATT_OK GATT_SUCCESS +#define BTA_GATT_INVALID_HANDLE GATT_INVALID_HANDLE /* 0x0001 */ +#define BTA_GATT_READ_NOT_PERMIT GATT_READ_NOT_PERMIT /* 0x0002 */ +#define BTA_GATT_WRITE_NOT_PERMIT GATT_WRITE_NOT_PERMIT /* 0x0003 */ +#define BTA_GATT_INVALID_PDU GATT_INVALID_PDU /* 0x0004 */ +#define BTA_GATT_INSUF_AUTHENTICATION GATT_INSUF_AUTHENTICATION /* 0x0005 */ +#define BTA_GATT_REQ_NOT_SUPPORTED GATT_REQ_NOT_SUPPORTED /* 0x0006 */ +#define BTA_GATT_INVALID_OFFSET GATT_INVALID_OFFSET /* 0x0007 */ +#define BTA_GATT_INSUF_AUTHORIZATION GATT_INSUF_AUTHORIZATION /* 0x0008 */ +#define BTA_GATT_PREPARE_Q_FULL GATT_PREPARE_Q_FULL /* 0x0009 */ +#define BTA_GATT_NOT_FOUND GATT_NOT_FOUND /* 0x000a */ +#define BTA_GATT_NOT_LONG GATT_NOT_LONG /* 0x000b */ +#define BTA_GATT_INSUF_KEY_SIZE GATT_INSUF_KEY_SIZE /* 0x000c */ +#define BTA_GATT_INVALID_ATTR_LEN GATT_INVALID_ATTR_LEN /* 0x000d */ +#define BTA_GATT_ERR_UNLIKELY GATT_ERR_UNLIKELY /* 0x000e */ +#define BTA_GATT_INSUF_ENCRYPTION GATT_INSUF_ENCRYPTION /* 0x000f */ +#define BTA_GATT_UNSUPPORT_GRP_TYPE GATT_UNSUPPORT_GRP_TYPE /* 0x0010 */ +#define BTA_GATT_INSUF_RESOURCE GATT_INSUF_RESOURCE /* 0x0011 */ + + +#define BTA_GATT_NO_RESOURCES GATT_NO_RESOURCES /* 0x80 */ +#define BTA_GATT_INTERNAL_ERROR GATT_INTERNAL_ERROR /* 0x81 */ +#define BTA_GATT_WRONG_STATE GATT_WRONG_STATE /* 0x82 */ +#define BTA_GATT_DB_FULL GATT_DB_FULL /* 0x83 */ +#define BTA_GATT_BUSY GATT_BUSY /* 0x84 */ +#define BTA_GATT_ERROR GATT_ERROR /* 0x85 */ +#define BTA_GATT_CMD_STARTED GATT_CMD_STARTED /* 0x86 */ +#define BTA_GATT_ILLEGAL_PARAMETER GATT_ILLEGAL_PARAMETER /* 0x87 */ +#define BTA_GATT_PENDING GATT_PENDING /* 0x88 */ +#define BTA_GATT_AUTH_FAIL GATT_AUTH_FAIL /* 0x89 */ +#define BTA_GATT_MORE GATT_MORE /* 0x8a */ +#define BTA_GATT_INVALID_CFG GATT_INVALID_CFG /* 0x8b */ +#define BTA_GATT_SERVICE_STARTED GATT_SERVICE_STARTED /* 0x8c */ +#define BTA_GATT_ENCRYPED_MITM GATT_ENCRYPED_MITM /* GATT_SUCCESS */ +#define BTA_GATT_ENCRYPED_NO_MITM GATT_ENCRYPED_NO_MITM /* 0x8d */ +#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 */ + +/* 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 */ + +typedef UINT8 tBTA_GATT_STATUS; + +#define BTA_GATT_INVALID_CONN_ID GATT_INVALID_CONN_ID + + +/* Client callback function events */ +#define BTA_GATTC_REG_EVT 0 /* GATT client is registered. */ +#define BTA_GATTC_DEREG_EVT 1 /* GATT client deregistered event */ +#define BTA_GATTC_OPEN_EVT 2 /* GATTC open request status event */ +#define BTA_GATTC_READ_CHAR_EVT 3 /* GATT read characteristic event */ +#define BTA_GATTC_WRITE_CHAR_EVT 4 /* GATT write characteristic or char descriptor event */ +#define BTA_GATTC_CLOSE_EVT 5 /* GATTC close request status event */ +#define BTA_GATTC_SEARCH_CMPL_EVT 6 /* GATT discovery complete event */ +#define BTA_GATTC_SEARCH_RES_EVT 7 /* GATT discovery result event */ +#define BTA_GATTC_READ_DESCR_EVT 8 /* GATT read characterisitc descriptor event */ +#define BTA_GATTC_WRITE_DESCR_EVT 9 /* GATT write characteristic descriptor event */ +#define BTA_GATTC_NOTIF_EVT 10 /* GATT attribute notification event */ +#define BTA_GATTC_PREP_WRITE_EVT 11 /* GATT prepare write event */ +#define BTA_GATTC_EXEC_EVT 12 /* execute write complete event */ +#define BTA_GATTC_ACL_EVT 13 /* ACL up event */ +#define BTA_GATTC_CANCEL_OPEN_EVT 14 /* cancel open event */ +#define BTA_GATTC_SRVC_CHG_EVT 15 /* service change event */ +#define BTA_GATTC_LISTEN_EVT 16 /* listen event */ +#define BTA_GATTC_ENC_CMPL_CB_EVT 17 /* encryption complete callback event */ +#define BTA_GATTC_CFG_MTU_EVT 18 /* configure MTU complete event */ +#define BTA_GATTC_ADV_DATA_EVT 19 /* ADV data event */ +#define BTA_GATTC_MULT_ADV_ENB_EVT 20 /* Enable Multi ADV event */ +#define BTA_GATTC_MULT_ADV_UPD_EVT 21 /* Update parameter event */ +#define BTA_GATTC_MULT_ADV_DATA_EVT 22 /* Multi ADV data event */ +#define BTA_GATTC_MULT_ADV_DIS_EVT 23 /* Disable Multi ADV event */ +#define BTA_GATTC_CONGEST_EVT 24 /* Congestion event */ +#define BTA_GATTC_BTH_SCAN_ENB_EVT 25 /* Enable batch scan event */ +#define BTA_GATTC_BTH_SCAN_CFG_EVT 26 /* Config storage event */ +#define BTA_GATTC_BTH_SCAN_RD_EVT 27 /* Batch scan reports read event */ +#define BTA_GATTC_BTH_SCAN_THR_EVT 28 /* Batch scan threshold event */ +#define BTA_GATTC_BTH_SCAN_PARAM_EVT 29 /* Batch scan param event */ +#define BTA_GATTC_BTH_SCAN_DIS_EVT 30 /* Disable batch scan event */ +#define BTA_GATTC_SCAN_FLT_CFG_EVT 31 /* Scan filter config event */ +#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 */ + +typedef UINT8 tBTA_GATTC_EVT; + +typedef tGATT_IF tBTA_GATTC_IF; + +typedef struct { + UINT16 unit; /* as UUIUD defined by SIG */ + UINT16 descr; /* as UUID as defined by SIG */ + tGATT_FORMAT format; + INT8 exp; + UINT8 name_spc; /* The name space of the description */ +} tBTA_GATT_CHAR_PRES; + +#define BTA_GATT_CLT_CONFIG_NONE GATT_CLT_CONFIG_NONE /* 0x0000 */ +#define BTA_GATT_CLT_CONFIG_NOTIFICATION GATT_CLT_CONFIG_NOTIFICATION /* 0x0001 */ +#define BTA_GATT_CLT_CONFIG_INDICATION GATT_CLT_CONFIG_INDICATION /* 0x0002 */ +typedef UINT16 tBTA_GATT_CLT_CHAR_CONFIG; + +/* characteristic descriptor: server configuration value +*/ +#define BTA_GATT_SVR_CONFIG_NONE GATT_SVR_CONFIG_NONE /* 0x0000 */ +#define BTA_GATT_SVR_CONFIG_BROADCAST GATT_SVR_CONFIG_BROADCAST /* 0x0001 */ +typedef UINT16 tBTA_GATT_SVR_CHAR_CONFIG; + +/* Characteristic Aggregate Format attribute value +*/ +#define BTA_GATT_AGGR_HANDLE_NUM_MAX 10 +typedef struct { + UINT8 num_handle; + UINT16 handle_list[BTA_GATT_AGGR_HANDLE_NUM_MAX]; +} tBTA_GATT_CHAR_AGGRE; +typedef tGATT_VALID_RANGE tBTA_GATT_VALID_RANGE; + +typedef struct { + UINT16 len; + UINT8 *p_value; +} tBTA_GATT_UNFMT; + +#define BTA_GATT_MAX_ATTR_LEN GATT_MAX_ATTR_LEN + +#define BTA_GATTC_TYPE_WRITE GATT_WRITE +#define BTA_GATTC_TYPE_WRITE_NO_RSP GATT_WRITE_NO_RSP +typedef UINT8 tBTA_GATTC_WRITE_TYPE; + +#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 */ +#define BTA_GATT_CONN_TERMINATE_PEER_USER GATT_CONN_TERMINATE_PEER_USER /* 0x13 connection terminate by peer user */ +#define BTA_GATT_CONN_TERMINATE_LOCAL_HOST GATT_CONN_TERMINATE_LOCAL_HOST/* 0x16 connectionterminated by local host */ +#define BTA_GATT_CONN_FAIL_ESTABLISH GATT_CONN_FAIL_ESTABLISH /* 0x03E connection fail to establish */ +#define BTA_GATT_CONN_LMP_TIMEOUT GATT_CONN_LMP_TIMEOUT /* 0x22 connection fail for LMP response tout */ +#define BTA_GATT_CONN_CANCEL GATT_CONN_CANCEL /* 0x0100 L2CAP connection cancelled */ +#define BTA_GATT_CONN_NONE 0x0101 /* 0x0101 no connection to cancel */ +typedef UINT16 tBTA_GATT_REASON; + +typedef struct { + tBTA_GATT_ID id; + BOOLEAN is_primary; +} tBTA_GATT_SRVC_ID; + +typedef struct { + tBTA_GATT_SRVC_ID srvc_id; + tBTA_GATT_ID char_id; +} tBTA_GATTC_CHAR_ID; + +typedef struct { + tBTA_GATTC_CHAR_ID char_id; + tBTA_GATT_ID descr_id; +} tBTA_GATTC_CHAR_DESCR_ID; + +typedef struct { + tBTA_GATT_SRVC_ID srvc_id; + tBTA_GATT_SRVC_ID incl_svc_id; +} tBTA_GATTC_INCL_SVC_ID; + +#define BTA_GATT_TYPE_CHAR 0 +#define BTA_GATT_TYPE_CHAR_DESCR 1 +typedef UINT8 tBTA_GATT_ID_TYPE; + +typedef struct { + tBTA_GATT_ID_TYPE id_type; + union { + tBTA_GATTC_CHAR_ID char_id; + tBTA_GATTC_CHAR_DESCR_ID char_descr_id; + + } id_value; +} tBTA_GATTC_ATTR_ID; + +#define BTA_GATTC_MULTI_MAX GATT_MAX_READ_MULTI_HANDLES + +typedef struct { + UINT8 num_attr; + tBTA_GATTC_ATTR_ID id_list[BTA_GATTC_MULTI_MAX]; + +} tBTA_GATTC_MULTI; + +#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 */ +#define BTA_GATT_AUTH_REQ_SIGNED_NO_MITM GATT_AUTH_REQ_SIGNED_NO_MITM +#define BTA_GATT_AUTH_REQ_SIGNED_MITM GATT_AUTH_REQ_SIGNED_MITM + +typedef tGATT_AUTH_REQ tBTA_GATT_AUTH_REQ; + +enum { + BTA_GATTC_ATTR_TYPE_INCL_SRVC, + BTA_GATTC_ATTR_TYPE_CHAR, + BTA_GATTC_ATTR_TYPE_CHAR_DESCR, + BTA_GATTC_ATTR_TYPE_SRVC +}; +typedef UINT8 tBTA_GATTC_ATTR_TYPE; + + +typedef struct { + tBT_UUID uuid; + UINT16 s_handle; + UINT16 e_handle; /* used for service only */ + UINT8 attr_type; + UINT8 id; + UINT8 prop; /* used when attribute type is characteristic */ + BOOLEAN is_primary; /* used when attribute type is service */ +} tBTA_GATTC_NV_ATTR; + +/* callback data structure */ +typedef struct { + tBTA_GATT_STATUS status; + tBTA_GATTC_IF client_if; +// btla-specific ++ + tBT_UUID app_uuid; +// btla-specific -- +} tBTA_GATTC_REG; + +typedef struct { + UINT8 num_pres_fmt; /* number of presentation format aggregated*/ + tBTA_GATTC_CHAR_DESCR_ID pre_format[BTA_GATTC_MULTI_MAX]; +} tBTA_GATT_CHAR_AGGRE_VALUE; + +typedef union { + tBTA_GATT_CHAR_AGGRE_VALUE aggre_value; + tBTA_GATT_UNFMT unformat; + +} tBTA_GATT_READ_VAL; + +typedef struct { + UINT16 conn_id; + tBTA_GATT_STATUS status; + tBTA_GATT_SRVC_ID srvc_id; + tBTA_GATT_ID char_id; + tBTA_GATT_ID descr_type; + tBTA_GATT_READ_VAL *p_value; +} tBTA_GATTC_READ; + +typedef struct { + UINT16 conn_id; + tBTA_GATT_STATUS status; + tBTA_GATT_SRVC_ID srvc_id; + tBTA_GATT_ID char_id; + tBTA_GATT_ID descr_type; +} tBTA_GATTC_WRITE; + +typedef struct { + UINT16 conn_id; + tBTA_GATT_STATUS status; +} tBTA_GATTC_EXEC_CMPL; + +typedef struct { + UINT16 conn_id; + tBTA_GATT_STATUS status; +} tBTA_GATTC_SEARCH_CMPL; + +typedef struct { + UINT16 conn_id; + tBTA_GATT_SRVC_ID service_uuid; +} tBTA_GATTC_SRVC_RES; + +typedef struct { + UINT16 conn_id; + tBTA_GATT_STATUS status; + UINT16 mtu; +} tBTA_GATTC_CFG_MTU; + +typedef struct { + tBTA_GATT_STATUS status; + UINT16 conn_id; + tBTA_GATTC_IF client_if; + BD_ADDR remote_bda; + tBTA_TRANSPORT transport; + UINT16 mtu; +} tBTA_GATTC_OPEN; + +typedef struct { + tBTA_GATT_STATUS status; + UINT16 conn_id; + tBTA_GATTC_IF client_if; + BD_ADDR remote_bda; + tBTA_GATT_REASON reason; /* disconnect reason code, not useful when connect event is reported */ +} tBTA_GATTC_CLOSE; + +typedef struct { + UINT16 conn_id; + BD_ADDR bda; + tBTA_GATTC_CHAR_ID char_id; + tBTA_GATT_ID descr_type; + UINT16 len; + UINT8 value[BTA_GATT_MAX_ATTR_LEN]; + BOOLEAN is_notify; +} tBTA_GATTC_NOTIFY; + +typedef struct { + UINT16 conn_id; + BOOLEAN congested; /* congestion indicator */ +} tBTA_GATTC_CONGEST; + +// btla-specific ++ +typedef struct { + tBTA_GATT_STATUS status; + tBTA_GATTC_IF client_if; + UINT16 conn_id; + BD_ADDR remote_bda; +} tBTA_GATTC_OPEN_CLOSE; +// btla-specific -- + +typedef struct { + tBTA_GATTC_IF client_if; + BD_ADDR remote_bda; +} tBTA_GATTC_ENC_CMPL_CB; + +typedef union { + tBTA_GATT_STATUS status; + + tBTA_GATTC_SEARCH_CMPL search_cmpl; /* discovery complete */ + tBTA_GATTC_SRVC_RES srvc_res; /* discovery result */ + tBTA_GATTC_REG reg_oper; /* registration data */ + tBTA_GATTC_OPEN open; + tBTA_GATTC_CLOSE close; + tBTA_GATTC_READ read; /* read attribute/descriptor data */ + tBTA_GATTC_WRITE write; /* write complete data */ + tBTA_GATTC_EXEC_CMPL exec_cmpl; /* execute complete */ + tBTA_GATTC_NOTIFY notify; /* notification/indication event data */ + tBTA_GATTC_ENC_CMPL_CB enc_cmpl; + BD_ADDR remote_bda; /* service change event */ + tBTA_GATTC_CFG_MTU cfg_mtu; /* configure MTU operation */ + tBTA_GATTC_CONGEST congest; +} tBTA_GATTC; + +/* GATTC enable callback function */ +typedef void (tBTA_GATTC_ENB_CBACK)(tBTA_GATT_STATUS status); + +/* Client callback function */ +typedef void (tBTA_GATTC_CBACK)(tBTA_GATTC_EVT event, tBTA_GATTC *p_data); + +/* GATT Server Data Structure */ +/* Server callback function events */ +#define BTA_GATTS_REG_EVT 0 +#define BTA_GATTS_READ_EVT GATTS_REQ_TYPE_READ /* 1 */ +#define BTA_GATTS_WRITE_EVT GATTS_REQ_TYPE_WRITE /* 2 */ +#define BTA_GATTS_EXEC_WRITE_EVT GATTS_REQ_TYPE_WRITE_EXEC /* 3 */ +#define BTA_GATTS_MTU_EVT GATTS_REQ_TYPE_MTU /* 4 */ +#define BTA_GATTS_CONF_EVT GATTS_REQ_TYPE_CONF /* 5 */ +#define BTA_GATTS_DEREG_EVT 6 +#define BTA_GATTS_CREATE_EVT 7 +#define BTA_GATTS_ADD_INCL_SRVC_EVT 8 +#define BTA_GATTS_ADD_CHAR_EVT 9 +#define BTA_GATTS_ADD_CHAR_DESCR_EVT 10 +#define BTA_GATTS_DELELTE_EVT 11 +#define BTA_GATTS_START_EVT 12 +#define BTA_GATTS_STOP_EVT 13 +#define BTA_GATTS_CONNECT_EVT 14 +#define BTA_GATTS_DISCONNECT_EVT 15 +#define BTA_GATTS_OPEN_EVT 16 +#define BTA_GATTS_CANCEL_OPEN_EVT 17 +#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 + +typedef UINT8 tBTA_GATTS_EVT; +typedef tGATT_IF tBTA_GATTS_IF; + +/* Attribute permissions +*/ +#define BTA_GATT_PERM_READ GATT_PERM_READ /* bit 0 - 0x0001 */ +#define BTA_GATT_PERM_READ_ENCRYPTED GATT_PERM_READ_ENCRYPTED /* bit 1 - 0x0002 */ +#define BTA_GATT_PERM_READ_ENC_MITM GATT_PERM_READ_ENC_MITM /* bit 2 - 0x0004 */ +#define BTA_GATT_PERM_WRITE GATT_PERM_WRITE /* bit 4 - 0x0010 */ +#define BTA_GATT_PERM_WRITE_ENCRYPTED GATT_PERM_WRITE_ENCRYPTED /* bit 5 - 0x0020 */ +#define BTA_GATT_PERM_WRITE_ENC_MITM GATT_PERM_WRITE_ENC_MITM /* bit 6 - 0x0040 */ +#define BTA_GATT_PERM_WRITE_SIGNED GATT_PERM_WRITE_SIGNED /* bit 7 - 0x0080 */ +#define BTA_GATT_PERM_WRITE_SIGNED_MITM GATT_PERM_WRITE_SIGNED_MITM /* bit 8 - 0x0100 */ +typedef UINT16 tBTA_GATT_PERM; +typedef tGATT_ATTR_VAL tBTA_GATT_ATTR_VAL; +typedef tGATTS_ATTR_CONTROL tBTA_GATTS_ATTR_CONTROL; + +#define BTA_GATTS_INVALID_APP 0xff + +#define BTA_GATTS_INVALID_IF 0 + +/* definition of characteristic properties */ +#define BTA_GATT_CHAR_PROP_BIT_BROADCAST GATT_CHAR_PROP_BIT_BROADCAST /* 0x01 */ +#define BTA_GATT_CHAR_PROP_BIT_READ GATT_CHAR_PROP_BIT_READ /* 0x02 */ +#define BTA_GATT_CHAR_PROP_BIT_WRITE_NR GATT_CHAR_PROP_BIT_WRITE_NR /* 0x04 */ +#define BTA_GATT_CHAR_PROP_BIT_WRITE GATT_CHAR_PROP_BIT_WRITE /* 0x08 */ +#define BTA_GATT_CHAR_PROP_BIT_NOTIFY GATT_CHAR_PROP_BIT_NOTIFY /* 0x10 */ +#define BTA_GATT_CHAR_PROP_BIT_INDICATE GATT_CHAR_PROP_BIT_INDICATE /* 0x20 */ +#define BTA_GATT_CHAR_PROP_BIT_AUTH GATT_CHAR_PROP_BIT_AUTH /* 0x40 */ +#define BTA_GATT_CHAR_PROP_BIT_EXT_PROP GATT_CHAR_PROP_BIT_EXT_PROP /* 0x80 */ +typedef UINT8 tBTA_GATT_CHAR_PROP; + +#ifndef BTA_GATTC_CHAR_DESCR_MAX +#define BTA_GATTC_CHAR_DESCR_MAX 7 +#endif + +/*********************** NV callback Data Definitions ********************** +*/ +typedef struct { + tBT_UUID app_uuid128; + tBT_UUID svc_uuid; + UINT16 svc_inst; + UINT16 s_handle; + UINT16 e_handle; + BOOLEAN is_primary; /* primary service or secondary */ +} tBTA_GATTS_HNDL_RANGE; + +#define BTA_GATTS_SRV_CHG_CMD_ADD_CLIENT GATTS_SRV_CHG_CMD_ADD_CLIENT +#define BTA_GATTS_SRV_CHG_CMD_UPDATE_CLIENT GATTS_SRV_CHG_CMD_UPDATE_CLIENT +#define BTA_GATTS_SRV_CHG_CMD_REMOVE_CLIENT GATTS_SRV_CHG_CMD_REMOVE_CLIENT +#define BTA_GATTS_SRV_CHG_CMD_READ_NUM_CLENTS GATTS_SRV_CHG_CMD_READ_NUM_CLENTS +#define BTA_GATTS_SRV_CHG_CMD_READ_CLENT GATTS_SRV_CHG_CMD_READ_CLENT +typedef tGATTS_SRV_CHG_CMD tBTA_GATTS_SRV_CHG_CMD; + +typedef tGATTS_SRV_CHG tBTA_GATTS_SRV_CHG; +typedef tGATTS_SRV_CHG_REQ tBTA_GATTS_SRV_CHG_REQ; +typedef tGATTS_SRV_CHG_RSP tBTA_GATTS_SRV_CHG_RSP; + +#define BTA_GATT_TRANSPORT_LE GATT_TRANSPORT_LE +#define BTA_GATT_TRANSPORT_BR_EDR GATT_TRANSPORT_BR_EDR +#define BTA_GATT_TRANSPORT_LE_BR_EDR GATT_TRANSPORT_LE_BR_EDR +typedef UINT8 tBTA_GATT_TRANSPORT; + +/* attribute value */ +typedef tGATT_VALUE tBTA_GATT_VALUE; + +/* attribute response data */ +typedef tGATTS_RSP tBTA_GATTS_RSP; + +/* attribute request data from the client */ +#define BTA_GATT_PREP_WRITE_CANCEL 0x00 +#define BTA_GATT_PREP_WRITE_EXEC 0x01 +typedef tGATT_EXEC_FLAG tBTA_GATT_EXEC_FLAG; + +/* read request always based on UUID */ +typedef tGATT_READ_REQ tBTA_GATT_READ_REQ; + +/* write request data */ +typedef tGATT_WRITE_REQ tBTA_GATT_WRITE_REQ; + +/* callback data for server access request from client */ +typedef tGATTS_DATA tBTA_GATTS_REQ_DATA; + +typedef struct { + tBTA_GATT_STATUS status; + BD_ADDR remote_bda; + UINT32 trans_id; + UINT16 conn_id; + tBTA_GATTS_REQ_DATA *p_data; +} tBTA_GATTS_REQ; + +typedef struct { + tBTA_GATTS_IF server_if; + tBTA_GATT_STATUS status; +// btla-specific ++ + tBT_UUID uuid; +// btla-specific -- +} tBTA_GATTS_REG_OPER; + + +typedef struct { + tBTA_GATTS_IF server_if; + UINT16 service_id; +// btla-specific ++ + UINT16 svc_instance; + BOOLEAN is_primary; + tBTA_GATT_STATUS status; + tBT_UUID uuid; +// btla-specific -- +} tBTA_GATTS_CREATE; + +typedef struct { + tBTA_GATTS_IF server_if; + UINT16 service_id; + UINT16 attr_id; + tBTA_GATT_STATUS status; +// btla-specific ++ + tBT_UUID char_uuid; +// btla-specific -- +} tBTA_GATTS_ADD_RESULT; + +typedef struct{ + tBTA_GATTS_IF server_if; + UINT16 service_id; + UINT16 attr_id; + tBTA_GATT_STATUS status; +}tBAT_GATTS_ATTR_VAL_RESULT; + +typedef struct { + tBTA_GATTS_IF server_if; + UINT16 service_id; + tBTA_GATT_STATUS status; +} tBTA_GATTS_SRVC_OPER; + + +typedef struct { + tBTA_GATTS_IF server_if; + BD_ADDR remote_bda; + UINT16 conn_id; + tBTA_GATT_REASON reason; /* report disconnect reason */ + tBTA_GATT_TRANSPORT transport; +} tBTA_GATTS_CONN; + +typedef struct { + UINT16 conn_id; + BOOLEAN congested; /* report channel congestion indicator */ +} tBTA_GATTS_CONGEST; + +typedef struct { + UINT16 conn_id; /* connection ID */ + tBTA_GATT_STATUS status; /* notification/indication status */ +} tBTA_GATTS_CONF; + +/* GATTS callback data */ +typedef union { + tBTA_GATTS_REG_OPER reg_oper; + tBTA_GATTS_CREATE create; + tBTA_GATTS_SRVC_OPER srvc_oper; + tBTA_GATT_STATUS status; /* BTA_GATTS_LISTEN_EVT */ + tBTA_GATTS_ADD_RESULT add_result; /* add included service: BTA_GATTS_ADD_INCL_SRVC_EVT + add char : BTA_GATTS_ADD_CHAR_EVT + add char descriptor: BTA_GATTS_ADD_CHAR_DESCR_EVT */ + tBAT_GATTS_ATTR_VAL_RESULT attr_val; + tBTA_GATTS_REQ req_data; + 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; + +/* GATTS enable callback function */ +typedef void (tBTA_GATTS_ENB_CBACK)(tBTA_GATT_STATUS status); + +/* Server callback function */ +typedef void (tBTA_GATTS_CBACK)(tBTA_GATTS_EVT event, tBTA_GATTS *p_data); + +/***************************************************************************** +** External Function Declarations +*****************************************************************************/ + +#ifdef __cplusplus +extern "C" +{ +#endif + +/************************** +** Client Functions +***************************/ + +/******************************************************************************* +** +** Function BTA_GATTC_Disable +** +** Description This function is called to disable the GATTC module +** +** Parameters None. +** +** Returns None +** +*******************************************************************************/ +extern void BTA_GATTC_Disable(void); + +/******************************************************************************* +** +** Function BTA_GATTC_AppRegister +** +** Description This function is called to register application callbacks +** with BTA GATTC module. +** +** Parameters p_app_uuid - applicaiton UUID +** p_client_cb - pointer to the application callback function. +** +** Returns None +** +*******************************************************************************/ +extern void BTA_GATTC_AppRegister(tBT_UUID *p_app_uuid, tBTA_GATTC_CBACK *p_client_cb); + +/******************************************************************************* +** +** Function BTA_GATTC_AppDeregister +** +** Description This function is called to deregister an application +** from BTA GATTC module. +** +** Parameters client_if - client interface identifier. +** +** Returns None +** +*******************************************************************************/ +extern void BTA_GATTC_AppDeregister (tBTA_GATTC_IF client_if); + +/******************************************************************************* +** +** Function BTA_GATTC_Open +** +** Description Open a direct connection or add a background auto connection +** bd address +** +** Parameters client_if: server interface. +** remote_bda: remote device BD address. +** is_direct: direct connection or background auto connection +** +** Returns void +** +*******************************************************************************/ +extern void BTA_GATTC_Open(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, + BOOLEAN is_direct, tBTA_GATT_TRANSPORT transport); + +/******************************************************************************* +** +** Function BTA_GATTC_CancelOpen +** +** Description Open a direct connection or add a background auto connection +** bd address +** +** Parameters client_if: server interface. +** remote_bda: remote device BD address. +** is_direct: direct connection or background auto connection +** +** Returns void +** +*******************************************************************************/ +extern void BTA_GATTC_CancelOpen(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, BOOLEAN is_direct); + +/******************************************************************************* +** +** Function BTA_GATTC_Close +** +** Description Close a connection to a GATT server. +** +** Parameters conn_id: connection ID to be closed. +** +** Returns void +** +*******************************************************************************/ +extern void BTA_GATTC_Close(UINT16 conn_id); + +/******************************************************************************* +** +** Function BTA_GATTC_ServiceSearchRequest +** +** Description This function is called to request a GATT service discovery +** on a GATT server. This function report service search result +** by a callback event, and followed by a service search complete +** event. +** +** Parameters conn_id: connection ID. +** p_srvc_uuid: a UUID of the service application is interested in. +** If Null, discover for all services. +** +** Returns None +** +*******************************************************************************/ +extern void BTA_GATTC_ServiceSearchRequest(UINT16 conn_id, tBT_UUID *p_srvc_uuid); + +/******************************************************************************* +** +** Function BTA_GATTC_GetFirstChar +** +** Description This function is called to find the first charatceristic of the +** service on the given server. +** +** Parameters conn_id: connection ID which identify the server. +** p_srvc_id: the service ID of which the characteristic is belonged to. +** p_char_uuid_cond: Characteristic UUID, if NULL find the first available +** characteristic. +** p_char_result: output parameter which will store the GATT +** characteristic ID. +** p_property: output parameter to carry the characteristic property. +** +** Returns returns status. +** +*******************************************************************************/ +extern tBTA_GATT_STATUS BTA_GATTC_GetFirstChar (UINT16 conn_id, + tBTA_GATT_SRVC_ID *p_srvc_id, + tBT_UUID *p_char_uuid_cond, + tBTA_GATTC_CHAR_ID *p_char_result, + tBTA_GATT_CHAR_PROP *p_property); + +/******************************************************************************* +** +** Function BTA_GATTC_GetNextChar +** +** Description This function is called to find the next charatceristic of the +** service on the given server. +** +** Parameters conn_id: connection ID which identify the server. +** p_start_char_id: start the characteristic search from the next record +** after the one identified by char_id. +** p_char_uuid_cond: Characteristic UUID, if NULL find the first available +** characteristic. +** p_char_result: output parameter which will store the GATT +** characteristic ID. +** p_property: output parameter, characteristic property. +** +** Returns returns status. +** +*******************************************************************************/ +extern tBTA_GATT_STATUS BTA_GATTC_GetNextChar (UINT16 conn_id, + tBTA_GATTC_CHAR_ID *p_start_char_id, + tBT_UUID *p_char_uuid_cond, + tBTA_GATTC_CHAR_ID *p_char_result, + tBTA_GATT_CHAR_PROP *p_property); + +/******************************************************************************* +** +** Function BTA_GATTC_GetFirstCharDescr +** +** Description This function is called to find the first charatceristic descriptor of the +** charatceristic on the given server. +** +** Parameters conn_id: connection ID which identify the server. +** p_char_id: the characteristic ID of which the descriptor is belonged to. +** p_descr_uuid_cond: Characteristic Descr UUID, if NULL find the first available +** characteristic. +** p_descr_result: output parameter which will store the GATT +** characteristic descriptor ID. +** +** Returns returns status. +** +*******************************************************************************/ +extern tBTA_GATT_STATUS BTA_GATTC_GetFirstCharDescr (UINT16 conn_id, tBTA_GATTC_CHAR_ID *p_char_id, + tBT_UUID *p_descr_uuid_cond, + tBTA_GATTC_CHAR_DESCR_ID *p_descr_result); + +/******************************************************************************* +** +** Function BTA_GATTC_GetNextCharDescr +** +** Description This function is called to find the next charatceristic of the +** service on the given server. +** +** Parameters conn_id: connection ID which identify the server. +** p_start_descr_id: start the characteristic search from the next record +** after the one identified by p_start_descr_id. +** p_descr_uuid_cond: Characteristic descriptor UUID, if NULL find +** the first available characteristic descriptor. +** p_descr_result: output parameter which will store the GATT +** characteristic descriptor ID. +** +** Returns returns status. +** +*******************************************************************************/ +extern tBTA_GATT_STATUS BTA_GATTC_GetNextCharDescr (UINT16 conn_id, + tBTA_GATTC_CHAR_DESCR_ID *p_start_descr_id, + tBT_UUID *p_descr_uuid_cond, + tBTA_GATTC_CHAR_DESCR_ID *p_descr_result); + + +/******************************************************************************* +** +** Function BTA_GATTC_GetFirstIncludedService +** +** Description This function is called to find the first included service of the +** service on the given server. +** +** Parameters conn_id: connection ID which identify the server. +** p_srvc_id: the service ID of which the included service is belonged to. +** p_uuid_cond: include service UUID, if NULL find the first available +** included service. +** p_result: output parameter which will store the GATT ID +** of the included service found. +** +** Returns returns status. +** +*******************************************************************************/ +extern tBTA_GATT_STATUS BTA_GATTC_GetFirstIncludedService(UINT16 conn_id, + tBTA_GATT_SRVC_ID *p_srvc_id, + tBT_UUID *p_uuid_cond, + tBTA_GATTC_INCL_SVC_ID *p_result); + +/******************************************************************************* +** +** Function BTA_GATTC_GetNextIncludedService +** +** Description This function is called to find the next included service of the +** service on the given server. +** +** Parameters conn_id: connection ID which identify the server. +** p_start_id: start the search from the next record +** after the one identified by p_start_id. +** p_uuid_cond: Included service UUID, if NULL find the first available +** included service. +** p_result: output parameter which will store the GATT ID +** of the included service found. +** +** Returns returns status. +** +*******************************************************************************/ +extern tBTA_GATT_STATUS BTA_GATTC_GetNextIncludedService(UINT16 conn_id, + tBTA_GATTC_INCL_SVC_ID *p_start_id, + tBT_UUID *p_uuid_cond, + tBTA_GATTC_INCL_SVC_ID *p_result); + +/******************************************************************************* +** +** Function BTA_GATTC_ReadCharacteristic +** +** Description This function is called to read a service's characteristics of +** the given characteritisc ID. +** +** Parameters conn_id - connection ID. +** p_char_id - characteritic ID to read. +** +** Returns None +** +*******************************************************************************/ +extern void BTA_GATTC_ReadCharacteristic (UINT16 conn_id, + tBTA_GATTC_CHAR_ID *p_char_id, + tBTA_GATT_AUTH_REQ auth_req); + +/******************************************************************************* +** +** Function BTA_GATTC_ReadCharDescr +** +** Description This function is called to read a characteristics descriptor. +** +** Parameters conn_id - connection ID. +** p_char_descr_id - characteritic descriptor ID to read. +** +** Returns None +** +*******************************************************************************/ +extern void BTA_GATTC_ReadCharDescr (UINT16 conn_id, + tBTA_GATTC_CHAR_DESCR_ID *p_char_descr_id, + tBTA_GATT_AUTH_REQ auth_req); + +/******************************************************************************* +** +** Function BTA_GATTC_WriteCharValue +** +** Description This function is called to write characteristic value. +** +** Parameters conn_id - connection ID. +** p_char_id - characteristic ID to write. +** write_type - type of write. +** len: length of the data to be written. +** p_value - the value to be written. +** +** Returns None +** +*******************************************************************************/ +extern void BTA_GATTC_WriteCharValue (UINT16 conn_id, + tBTA_GATTC_CHAR_ID *p_char_id, + tBTA_GATTC_WRITE_TYPE write_type, + UINT16 len, + UINT8 *p_value, + tBTA_GATT_AUTH_REQ auth_req); + +/******************************************************************************* +** +** Function BTA_GATTC_WriteCharDescr +** +** Description This function is called to write characteristic descriptor value. +** +** Parameters conn_id - connection ID +** p_char_descr_id - characteristic descriptor ID to write. +** write_type - type of write. +** p_value - the value to be written. +** +** Returns None +** +*******************************************************************************/ +extern void BTA_GATTC_WriteCharDescr (UINT16 conn_id, + tBTA_GATTC_CHAR_DESCR_ID *p_char_descr_id, + tBTA_GATTC_WRITE_TYPE write_type, + tBTA_GATT_UNFMT *p_data, + tBTA_GATT_AUTH_REQ auth_req); + +/******************************************************************************* +** +** Function BTA_GATTC_SendIndConfirm +** +** Description This function is called to send handle value confirmation. +** +** Parameters conn_id - connection ID. +** p_char_id - characteristic ID to confrim. +** +** Returns None +** +*******************************************************************************/ +extern void BTA_GATTC_SendIndConfirm (UINT16 conn_id, tBTA_GATTC_CHAR_ID *p_char_id); + +/******************************************************************************* +** +** Function BTA_GATTC_RegisterForNotifications +** +** Description This function is called to register for notification of a service. +** +** Parameters client_if - client interface. +** remote_bda - target GATT server. +** p_char_id - pointer to GATT characteristic ID. +** +** Returns OK if registration succeed, otherwise failed. +** +*******************************************************************************/ +extern tBTA_GATT_STATUS BTA_GATTC_RegisterForNotifications (tBTA_GATTC_IF client_if, + BD_ADDR remote_bda, + tBTA_GATTC_CHAR_ID *p_char_id); + + +/******************************************************************************* +** +** Function BTA_GATTC_DeregisterForNotifications +** +** Description This function is called to de-register for notification of a servbice. +** +** Parameters client_if - client interface. +** remote_bda - target GATT server. +** p_char_id - pointer to a GATT characteristic ID. +** +** Returns OK if deregistration succeed, otherwise failed. +** +*******************************************************************************/ +extern tBTA_GATT_STATUS BTA_GATTC_DeregisterForNotifications (tBTA_GATTC_IF client_if, + BD_ADDR remote_bda, + tBTA_GATTC_CHAR_ID *p_char_id); + +/******************************************************************************* +** +** Function BTA_GATTC_PrepareWrite +** +** Description This function is called to prepare write a characteristic value. +** +** Parameters conn_id - connection ID. +** p_char_id - GATT characteritic ID of the service. +** offset - offset of the write value. +** len: length of the data to be written. +** p_value - the value to be written. +** +** Returns None +** +*******************************************************************************/ +extern void BTA_GATTC_PrepareWrite (UINT16 conn_id, + tBTA_GATTC_CHAR_ID *p_char_id, + UINT16 offset, + UINT16 len, + UINT8 *p_value, + tBTA_GATT_AUTH_REQ auth_req); + +/******************************************************************************* +** +** Function BTA_GATTC_ExecuteWrite +** +** Description This function is called to execute write a prepare write sequence. +** +** Parameters conn_id - connection ID. +** is_execute - execute or cancel. +** +** Returns None +** +*******************************************************************************/ +extern void BTA_GATTC_ExecuteWrite (UINT16 conn_id, BOOLEAN is_execute); + +/******************************************************************************* +** +** Function BTA_GATTC_ReadMultiple +** +** Description This function is called to read multiple characteristic or +** characteristic descriptors. +** +** Parameters conn_id - connection ID. +** p_read_multi - read multiple parameters. +** +** Returns None +** +*******************************************************************************/ +extern void BTA_GATTC_ReadMultiple(UINT16 conn_id, tBTA_GATTC_MULTI *p_read_multi, + tBTA_GATT_AUTH_REQ auth_req); + + +/******************************************************************************* +** +** Function BTA_GATTC_Refresh +** +** Description Refresh the server cache of the remote device +** +** Parameters remote_bda: remote device BD address. +** +** Returns void +** +*******************************************************************************/ +extern void BTA_GATTC_Refresh(BD_ADDR remote_bda); + + +/******************************************************************************* +** +** Function BTA_GATTC_Listen +** +** Description Start advertisement to listen for connection request. +** +** Parameters client_if: server interface. +** start: to start or stop listening for connection +** remote_bda: remote device BD address, if listen to all device +** use NULL. +** +** Returns void +** +*******************************************************************************/ +extern void BTA_GATTC_Listen(tBTA_GATTC_IF client_if, BOOLEAN start, BD_ADDR_PTR target_bda); + +/******************************************************************************* +** +** Function BTA_GATTC_Broadcast +** +** Description Start broadcasting (non-connectable advertisements) +** +** Parameters client_if: client interface. +** start: to start or stop listening for connection +** +** Returns void +** +*******************************************************************************/ +extern void BTA_GATTC_Broadcast(tBTA_GATTC_IF client_if, BOOLEAN start); + + +/******************************************************************************* +** +** Function BTA_GATTC_ConfigureMTU +** +** Description Configure the MTU size in the GATT channel. This can be done +** only once per connection. +** +** Parameters conn_id: connection ID. +** mtu: desired MTU size to use. +** +** Returns void +** +*******************************************************************************/ +extern void BTA_GATTC_ConfigureMTU (UINT16 conn_id, UINT16 mtu); + +/******************************************************************************* +** BTA GATT Server API +********************************************************************************/ + +/******************************************************************************* +** +** Function BTA_GATTS_Init +** +** Description This function is called to initalize GATTS module +** +** Parameters None +** +** Returns None +** +*******************************************************************************/ +extern void BTA_GATTS_Init(); + +/******************************************************************************* +** +** Function BTA_GATTS_Disable +** +** Description This function is called to disable GATTS module +** +** Parameters None. +** +** Returns None +** +*******************************************************************************/ +extern void BTA_GATTS_Disable(void); + +/******************************************************************************* +** +** Function BTA_GATTS_AppRegister +** +** Description This function is called to register application callbacks +** with BTA GATTS module. +** +** Parameters p_app_uuid - applicaiton UUID +** p_cback - pointer to the application callback function. +** +** Returns None +** +*******************************************************************************/ +extern void BTA_GATTS_AppRegister(tBT_UUID *p_app_uuid, tBTA_GATTS_CBACK *p_cback); + + +/******************************************************************************* +** +** Function BTA_GATTS_AppDeregister +** +** Description De-register with BTA GATT Server. +** +** Parameters server_if: server interface +** +** Returns void +** +*******************************************************************************/ +extern void BTA_GATTS_AppDeregister(tBTA_GATTS_IF server_if); + +/******************************************************************************* +** +** Function BTA_GATTS_CreateService +** +** Description Create a service. When service creation is done, a callback +** event BTA_GATTS_CREATE_SRVC_EVT is called to report status +** and service ID to the profile. The service ID obtained in +** the callback function needs to be used when adding included +** service and characteristics/descriptors into the service. +** +** Parameters server_if: server interface. +** p_service_uuid: service UUID. +** inst: instance ID number of this service. +** num_handle: numble of handle requessted for this service. +** is_primary: is this service a primary one or not. +** +** Returns void +** +*******************************************************************************/ +extern void BTA_GATTS_CreateService(tBTA_GATTS_IF server_if, tBT_UUID *p_service_uuid, + UINT8 inst, UINT16 num_handle, BOOLEAN is_primary); + +/******************************************************************************* +** +** Function BTA_GATTS_AddIncludeService +** +** Description This function is called to add an included service. After included +** service is included, a callback event BTA_GATTS_ADD_INCL_SRVC_EVT +** is reported the included service ID. +** +** Parameters service_id: service ID to which this included service is to +** be added. +** included_service_id: the service ID to be included. +** +** Returns void +** +*******************************************************************************/ +extern void BTA_GATTS_AddIncludeService(UINT16 service_id, UINT16 included_service_id); + +/******************************************************************************* +** +** Function BTA_GATTS_AddCharacteristic +** +** Description This function is called to add a characteristic into a service. +** +** Parameters service_id: service ID to which this included service is to +** be added. +** p_char_uuid : Characteristic UUID. +** perm : Characteristic value declaration attribute permission. +** property : Characteristic Properties +** +** Returns None +** +*******************************************************************************/ +extern void BTA_GATTS_AddCharacteristic (UINT16 service_id, tBT_UUID *p_char_uuid, + tBTA_GATT_PERM perm, tBTA_GATT_CHAR_PROP property, tGATT_ATTR_VAL *attr_val, + tBTA_GATTS_ATTR_CONTROL *control); + +/******************************************************************************* +** +** Function BTA_GATTS_AddCharDescriptor +** +** Description This function is called to add characteristic descriptor. When +** it's done, a callback event BTA_GATTS_ADD_DESCR_EVT is called +** to report the status and an ID number for this descriptor. +** +** Parameters service_id: service ID to which this charatceristic descriptor is to +** be added. +** perm: descriptor access permission. +** p_descr_uuid: descriptor UUID. +** p_descr_params: descriptor value if it's read only descriptor. +** +** Returns returns status. +** +*******************************************************************************/ +extern void BTA_GATTS_AddCharDescriptor (UINT16 service_id, + tBTA_GATT_PERM perm, + tBT_UUID *p_descr_uuid, tBTA_GATT_ATTR_VAL *attr_val, + tBTA_GATTS_ATTR_CONTROL *control); + +/******************************************************************************* +** +** Function BTA_GATTS_DeleteService +** +** Description This function is called to delete a service. When this is done, +** a callback event BTA_GATTS_DELETE_EVT is report with the status. +** +** Parameters service_id: service_id to be deleted. +** +** Returns returns none. +** +*******************************************************************************/ +extern void BTA_GATTS_DeleteService(UINT16 service_id); + +/******************************************************************************* +** +** Function BTA_GATTS_StartService +** +** Description This function is called to start a service. +** +** Parameters service_id: the service ID to be started. +** sup_transport: supported trasnport. +** +** Returns None. +** +*******************************************************************************/ +extern void BTA_GATTS_StartService(UINT16 service_id, tBTA_GATT_TRANSPORT sup_transport); + +/******************************************************************************* +** +** Function BTA_GATTS_StopService +** +** Description This function is called to stop a service. +** +** Parameters service_id - service to be topped. +** +** Returns None +** +*******************************************************************************/ +extern void BTA_GATTS_StopService(UINT16 service_id); + +/******************************************************************************* +** +** Function BTA_GATTS_HandleValueIndication +** +** Description This function is called to read a characteristics descriptor. +** +** Parameters conn_id - connection identifier. +** attr_id - attribute ID to indicate. +** data_len - indicate data length. +** p_data: data to indicate. +** need_confirm - if this indication expects a confirmation or not. +** +** Returns None +** +*******************************************************************************/ +extern void BTA_GATTS_HandleValueIndication (UINT16 conn_id, UINT16 attr_id, + UINT16 data_len, + UINT8 *p_data, + BOOLEAN need_confirm); + +/******************************************************************************* +** +** Function BTA_GATTS_SendRsp +** +** Description This function is called to send a response to a request. +** +** Parameters conn_id - connection identifier. +** trans_id - transaction ID. +** status - response status +** p_msg - response data. +** +** Returns None +** +*******************************************************************************/ +extern void BTA_GATTS_SendRsp (UINT16 conn_id, UINT32 trans_id, + tBTA_GATT_STATUS status, tBTA_GATTS_RSP *p_msg); + + + +/******************************************************************************* +** +** Function BTA_SetAttributeValue +** +** Description This function is called to set the attribute value in the gatt database +** +** Parameters attr_handle - the attribute value handle. +** length - the value length which has been set to the attribute. +** value - the pointer to the value +** +** Returns None +** +*******************************************************************************/ +extern void BTA_SetAttributeValue(UINT16 attr_handle, UINT16 length, UINT8 *value); + + +/******************************************************************************* +** +** Function BTA_GetAttributeValue +** +** Description This function is called to get the attribute value in the gatt database +** +** Parameters attr_handle - the attribute value handle. +** length - the value length which has been set to the attribute. +** value - the pointer to the value +** +** Returns None +** +*******************************************************************************/ +extern void BTA_GetAttributeValue(UINT16 attr_handle, UINT16 *length, UINT8 **value); + +/******************************************************************************* +** +** Function BTA_GATTS_Open +** +** Description Open a direct open connection or add a background auto connection +** bd address +** +** Parameters server_if: server interface. +** remote_bda: remote device BD address. +** is_direct: direct connection or background auto connection +** +** Returns void +** +*******************************************************************************/ +extern void BTA_GATTS_Open(tBTA_GATTS_IF server_if, BD_ADDR remote_bda, + BOOLEAN is_direct, tBTA_GATT_TRANSPORT transport); + + +/******************************************************************************* +** +** Function BTA_GATTS_CancelOpen +** +** Description Cancel a direct open connection or remove a background auto connection +** bd address +** +** Parameters server_if: server interface. +** remote_bda: remote device BD address. +** is_direct: direct connection or background auto connection +** +** Returns void +** +*******************************************************************************/ +extern void BTA_GATTS_CancelOpen(tBTA_GATTS_IF server_if, BD_ADDR remote_bda, BOOLEAN is_direct); + + +/******************************************************************************* +** +** Function BTA_GATTS_Close +** +** Description Close a connection a remote device. +** +** Parameters conn_id: connection ID to be closed. +** +** Returns void +** +*******************************************************************************/ +extern void BTA_GATTS_Close(UINT16 conn_id); + +/******************************************************************************* +** +** Function BTA_GATTS_Listen +** +** Description Start advertisement to listen for connection request for a +** GATT server +** +** Parameters server_if: server interface. +** start: to start or stop listening for connection +** remote_bda: remote device BD address, if listen to all device +** use NULL. +** +** Returns void +** +*******************************************************************************/ +extern void BTA_GATTS_Listen(tBTA_GATTS_IF server_if, BOOLEAN start, + BD_ADDR_PTR target_bda); + + +#ifdef __cplusplus + +} +#endif + + +#endif /* BTA_GATT_API_H */ diff --git a/tools/sdk/include/bluedroid/bta_gattc_ci.h b/tools/sdk/include/bluedroid/bta_gattc_ci.h new file mode 100644 index 00000000..12b3a421 --- /dev/null +++ b/tools/sdk/include/bluedroid/bta_gattc_ci.h @@ -0,0 +1,117 @@ +/****************************************************************************** + * + * 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 is the interface file for GATT call-in functions. + * + ******************************************************************************/ +#ifndef BTA_GATTC_CI_H +#define BTA_GATTC_CI_H + +#include "bta_gatt_api.h" + +/***************************************************************************** +** Constants and data types +*****************************************************************************/ + +/* Open Complete Event */ +typedef struct { + BT_HDR hdr; + tBTA_GATT_STATUS status; +} tBTA_GATTC_CI_EVT; + +#define BTA_GATTC_NV_LOAD_MAX 10 + +/* Read Ready Event */ +typedef struct { + BT_HDR hdr; + tBTA_GATT_STATUS status; + UINT16 num_attr; + tBTA_GATTC_NV_ATTR attr[BTA_GATTC_NV_LOAD_MAX]; +} tBTA_GATTC_CI_LOAD; + + +/***************************************************************************** +** Function Declarations +*****************************************************************************/ +#ifdef __cplusplus +extern "C" +{ +#endif + +/******************************************************************************* +** +** Function bta_gattc_ci_cache_open +** +** Description This function sends an event to indicate server cache open +** completed. +** +** Parameters server_bda - server BDA of this cache. +** status - BTA_GATT_OK if full buffer of data, +** BTA_GATT_FAIL if an error has occurred. +** +** Returns void +** +*******************************************************************************/ +extern void bta_gattc_ci_cache_open(BD_ADDR server_bda, UINT16 evt, + tBTA_GATT_STATUS status, UINT16 conn_id); + +/******************************************************************************* +** +** Function bta_gattc_ci_cache_load +** +** Description This function sends an event to BTA indicating the phone has +** load the servere cache and ready to send it to the stack. +** +** Parameters server_bda - server BDA of this cache. +** num_bytes_read - number of bytes read into the buffer +** specified in the read callout-function. +** status - BTA_GATT_OK if full buffer of data, +** BTA_GATT_FAIL if an error has occurred. +** +** Returns void +** +*******************************************************************************/ +extern void bta_gattc_ci_cache_load(BD_ADDR server_bda, UINT16 evt, + UINT16 num_attr, tBTA_GATTC_NV_ATTR *p_atrr, + tBTA_GATT_STATUS status, UINT16 conn_id); + +/******************************************************************************* +** +** Function bta_gattc_ci_save +** +** Description This function sends an event to BTA indicating the phone has +** save the server cache. +** +** Parameters server_bda - server BDA of this cache. +** status - BTA_GATT_OK if full buffer of data, +** BTA_GATT_FAIL if an error has occurred. +** +** Returns void +** +*******************************************************************************/ +extern void bta_gattc_ci_cache_save(BD_ADDR server_bda, UINT16 evt, + tBTA_GATT_STATUS status, UINT16 conn_id); + + +#ifdef __cplusplus +} +#endif + +#endif /* BTA_GATTC_CI_H */ diff --git a/tools/sdk/include/bluedroid/bta_gattc_co.h b/tools/sdk/include/bluedroid/bta_gattc_co.h new file mode 100644 index 00000000..f84f9d35 --- /dev/null +++ b/tools/sdk/include/bluedroid/bta_gattc_co.h @@ -0,0 +1,114 @@ +/****************************************************************************** + * + * Copyright (C) 2009-2013 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 is the interface file for BTA GATT client call-out functions. + * + ******************************************************************************/ +#ifndef BTA_GATTC_CO_H +#define BTA_GATTC_CO_H + +#include "bta_gatt_api.h" + +/******************************************************************************* +** +** Function bta_gattc_co_cache_open +** +** Description This callout function is executed by GATTC when a GATT server +** cache is ready to be sent. +** +** Parameter server_bda: server bd address of this cache belongs to +** evt: call in event to be passed in when cache open is done. +** conn_id: connection ID of this cache operation attach to. +** to_save: open cache to save or to load. +** +** Returns void. +** +*******************************************************************************/ +extern void bta_gattc_co_cache_open(BD_ADDR server_bda, UINT16 evt, + UINT16 conn_id, BOOLEAN to_save); + +/******************************************************************************* +** +** Function bta_gattc_co_cache_close +** +** Description This callout function is executed by GATTC when a GATT server +** cache is written completely. +** +** Parameter server_bda: server bd address of this cache belongs to +** conn_id: connection ID of this cache operation attach to. +** +** Returns void. +** +*******************************************************************************/ +extern void bta_gattc_co_cache_close(BD_ADDR server_bda, UINT16 conn_id); + +/******************************************************************************* +** +** Function bta_gattc_co_cache_save +** +** Description This callout function is executed by GATT when a server cache +** is available to save. +** +** Parameter server_bda: server bd address of this cache belongs to +** evt: call in event to be passed in when cache save is done. +** num_attr: number of attribute to be save. +** p_attr: pointer to the list of attributes to save. +** attr_index: starting attribute index of the save operation. +** conn_id: connection ID of this cache operation attach to. +** Returns +** +*******************************************************************************/ +extern void bta_gattc_co_cache_save(BD_ADDR server_bda, UINT16 evt, + UINT16 num_attr, tBTA_GATTC_NV_ATTR *p_attr, + UINT16 attr_index, UINT16 conn_id); + +/******************************************************************************* +** +** Function bta_gattc_co_cache_load +** +** Description This callout function is executed by GATT when server cache +** is required to load. +** +** Parameter server_bda: server bd address of this cache belongs to +** evt: call in event to be passed in when cache save is done. +** num_attr: number of attribute to be save. +** attr_index: starting attribute index of the save operation. +** conn_id: connection ID of this cache operation attach to. +** Returns +** +*******************************************************************************/ +extern void bta_gattc_co_cache_load(BD_ADDR server_bda, UINT16 evt, + UINT16 start_index, UINT16 conn_id); + +/******************************************************************************* +** +** Function bta_gattc_co_cache_reset +** +** Description This callout function is executed by GATTC to reset cache in +** application +** +** Parameter server_bda: server bd address of this cache belongs to +** +** Returns void. +** +*******************************************************************************/ +extern void bta_gattc_co_cache_reset(BD_ADDR server_bda); + +#endif /* BTA_GATT_CO_H */ diff --git a/tools/sdk/include/bluedroid/bta_gattc_int.h b/tools/sdk/include/bluedroid/bta_gattc_int.h new file mode 100644 index 00000000..d50c6622 --- /dev/null +++ b/tools/sdk/include/bluedroid/bta_gattc_int.h @@ -0,0 +1,525 @@ +/****************************************************************************** + * + * 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 is the private file for the file transfer client (FTC). + * + ******************************************************************************/ +#ifndef BTA_GATTC_INT_H +#define BTA_GATTC_INT_H + +#include "bt_target.h" +#include "bta_sys.h" +#include "bta_gatt_api.h" +#include "bta_gattc_ci.h" +#include "bta_gattc_co.h" + +#include "gki.h" + +/***************************************************************************** +** Constants and data types +*****************************************************************************/ +enum { + BTA_GATTC_API_OPEN_EVT = BTA_SYS_EVT_START(BTA_ID_GATTC), + BTA_GATTC_INT_OPEN_FAIL_EVT, + BTA_GATTC_API_CANCEL_OPEN_EVT, + BTA_GATTC_INT_CANCEL_OPEN_OK_EVT, + + BTA_GATTC_API_READ_EVT, + BTA_GATTC_API_WRITE_EVT, + BTA_GATTC_API_EXEC_EVT, + BTA_GATTC_API_CFG_MTU_EVT, + + BTA_GATTC_API_CLOSE_EVT, + + BTA_GATTC_API_SEARCH_EVT, + BTA_GATTC_API_CONFIRM_EVT, + BTA_GATTC_API_READ_MULTI_EVT, + BTA_GATTC_API_REFRESH_EVT, + + BTA_GATTC_INT_CONN_EVT, + BTA_GATTC_INT_DISCOVER_EVT, + BTA_GATTC_DISCOVER_CMPL_EVT, + BTA_GATTC_OP_CMPL_EVT, + BTA_GATTC_INT_DISCONN_EVT, + + /* for cache loading/saving */ + BTA_GATTC_START_CACHE_EVT, + BTA_GATTC_CI_CACHE_OPEN_EVT, + BTA_GATTC_CI_CACHE_LOAD_EVT, + BTA_GATTC_CI_CACHE_SAVE_EVT, + + BTA_GATTC_INT_START_IF_EVT, + BTA_GATTC_API_REG_EVT, + BTA_GATTC_API_DEREG_EVT, + BTA_GATTC_API_LISTEN_EVT, + BTA_GATTC_API_BROADCAST_EVT, + BTA_GATTC_API_DISABLE_EVT, + BTA_GATTC_ENC_CMPL_EVT +}; +typedef UINT16 tBTA_GATTC_INT_EVT; + +/* max client application GATTC can support */ +#ifndef BTA_GATTC_CL_MAX +#define BTA_GATTC_CL_MAX 3 // 32 +#endif + +/* max known devices GATTC can support */ +#ifndef BTA_GATTC_KNOWN_SR_MAX +#define BTA_GATTC_KNOWN_SR_MAX 3 // 10 +#endif + +#define BTA_GATTC_CONN_MAX GATT_MAX_PHY_CHANNEL + +#ifndef BTA_GATTC_CLCB_MAX +#define BTA_GATTC_CLCB_MAX GATT_CL_MAX_LCB +#endif + +#define BTA_GATTC_WRITE_PREPARE GATT_WRITE_PREPARE + + +/* internal strucutre for GATTC register API */ +typedef struct { + BT_HDR hdr; + tBT_UUID app_uuid; + tBTA_GATTC_CBACK *p_cback; +} tBTA_GATTC_API_REG; + +typedef struct { + BT_HDR hdr; + tBTA_GATTC_IF client_if; +} tBTA_GATTC_INT_START_IF; + +typedef tBTA_GATTC_INT_START_IF tBTA_GATTC_API_DEREG; +typedef tBTA_GATTC_INT_START_IF tBTA_GATTC_INT_DEREG; + +typedef struct { + BT_HDR hdr; + BD_ADDR remote_bda; + tBTA_GATTC_IF client_if; + BOOLEAN is_direct; + tBTA_TRANSPORT transport; +} tBTA_GATTC_API_OPEN; + +typedef tBTA_GATTC_API_OPEN tBTA_GATTC_API_CANCEL_OPEN; + +typedef struct { + BT_HDR hdr; + tBTA_GATT_AUTH_REQ auth_req; + tBTA_GATT_SRVC_ID srvc_id; + tBTA_GATT_ID char_id; + tBTA_GATT_ID *p_descr_type; +} tBTA_GATTC_API_READ; + +typedef struct { + BT_HDR hdr; + tBTA_GATT_AUTH_REQ auth_req; + tBTA_GATT_SRVC_ID srvc_id; + tBTA_GATT_ID char_id; + tBTA_GATT_ID *p_descr_type; + tBTA_GATTC_WRITE_TYPE write_type; + UINT16 offset; + UINT16 len; + UINT8 *p_value; +} tBTA_GATTC_API_WRITE; + +typedef struct { + BT_HDR hdr; + BOOLEAN is_execute; +} tBTA_GATTC_API_EXEC; + +typedef struct { + BT_HDR hdr; + tBTA_GATT_SRVC_ID srvc_id; + tBTA_GATT_ID char_id; +} tBTA_GATTC_API_CONFIRM; + +typedef tGATT_CL_COMPLETE tBTA_GATTC_CMPL; + +typedef struct { + BT_HDR hdr; + UINT8 op_code; + tGATT_STATUS status; + tBTA_GATTC_CMPL *p_cmpl; +} tBTA_GATTC_OP_CMPL; + +typedef struct { + BT_HDR hdr; + tBT_UUID *p_srvc_uuid; +} tBTA_GATTC_API_SEARCH; + +typedef struct { + BT_HDR hdr; + tBTA_GATT_AUTH_REQ auth_req; + UINT8 num_attr; + tBTA_GATTC_ATTR_ID *p_id_list; +} tBTA_GATTC_API_READ_MULTI; + +typedef struct { + BT_HDR hdr; + BD_ADDR_PTR remote_bda; + tBTA_GATTC_IF client_if; + BOOLEAN start; +} tBTA_GATTC_API_LISTEN; + + +typedef struct { + BT_HDR hdr; + UINT16 mtu; +} tBTA_GATTC_API_CFG_MTU; + +typedef struct { + BT_HDR hdr; + BD_ADDR remote_bda; + tBTA_GATTC_IF client_if; + UINT8 role; + tBT_TRANSPORT transport; + tGATT_DISCONN_REASON reason; +} tBTA_GATTC_INT_CONN; + +typedef struct { + BT_HDR hdr; + BD_ADDR remote_bda; + tBTA_GATTC_IF client_if; +} tBTA_GATTC_ENC_CMPL; + +typedef union { + BT_HDR hdr; + tBTA_GATTC_API_REG api_reg; + tBTA_GATTC_API_DEREG api_dereg; + tBTA_GATTC_API_OPEN api_conn; + tBTA_GATTC_API_CANCEL_OPEN api_cancel_conn; + tBTA_GATTC_API_READ api_read; + tBTA_GATTC_API_SEARCH api_search; + tBTA_GATTC_API_WRITE api_write; + tBTA_GATTC_API_CONFIRM api_confirm; + tBTA_GATTC_API_EXEC api_exec; + tBTA_GATTC_API_READ_MULTI api_read_multi; + tBTA_GATTC_API_CFG_MTU api_mtu; + tBTA_GATTC_OP_CMPL op_cmpl; + tBTA_GATTC_CI_EVT ci_open; + tBTA_GATTC_CI_EVT ci_save; + tBTA_GATTC_CI_LOAD ci_load; + tBTA_GATTC_INT_CONN int_conn; + tBTA_GATTC_ENC_CMPL enc_cmpl; + + tBTA_GATTC_INT_START_IF int_start_if; + tBTA_GATTC_INT_DEREG int_dereg; + /* if peripheral role is supported */ + tBTA_GATTC_API_LISTEN api_listen; + +} tBTA_GATTC_DATA; + + +/* GATT server cache on the client */ +typedef union { + UINT8 uuid128[LEN_UUID_128]; + UINT16 uuid16; +} tBTA_GATTC_UUID; + +typedef struct gattc_attr_cache { + tBTA_GATTC_UUID *p_uuid; + struct gattc_attr_cache *p_next; + UINT16 uuid_len; + UINT16 attr_handle; + UINT8 inst_id; + tBTA_GATT_CHAR_PROP property; /* if characteristic, it is char property; + if included service, flag primary, + if descriptor, not used */ + tBTA_GATTC_ATTR_TYPE attr_type; +// btla-specific ++ +} __attribute__((packed)) tBTA_GATTC_CACHE_ATTR; +// btla-specific -- + +typedef struct gattc_svc_cache { + tBTA_GATT_SRVC_ID service_uuid; + tBTA_GATTC_CACHE_ATTR *p_attr; + tBTA_GATTC_CACHE_ATTR *p_last_attr; + UINT16 s_handle; + UINT16 e_handle; + struct gattc_svc_cache *p_next; + tBTA_GATTC_CACHE_ATTR *p_cur_char; +// btla-specific ++ +} __attribute__((packed)) tBTA_GATTC_CACHE; +// btla-specific -- + +typedef struct { + tBT_UUID uuid; + UINT16 s_handle; + UINT16 e_handle; + BOOLEAN is_primary; + UINT8 srvc_inst_id; + tBTA_GATT_CHAR_PROP property; +} tBTA_GATTC_ATTR_REC; + + +#define BTA_GATTC_MAX_CACHE_CHAR 40 +#define BTA_GATTC_ATTR_LIST_SIZE (BTA_GATTC_MAX_CACHE_CHAR * sizeof(tBTA_GATTC_ATTR_REC)) + +#ifndef BTA_GATTC_CACHE_SRVR_SIZE +#define BTA_GATTC_CACHE_SRVR_SIZE 600 +#endif + +enum { + BTA_GATTC_IDLE_ST = 0, /* Idle */ + BTA_GATTC_W4_CONN_ST, /* Wait for connection - (optional) */ + BTA_GATTC_CONN_ST, /* connected state */ + BTA_GATTC_DISCOVER_ST /* discover is in progress */ +}; +typedef UINT8 tBTA_GATTC_STATE; + +typedef struct { + BOOLEAN in_use; + BD_ADDR server_bda; + BOOLEAN connected; + +#define BTA_GATTC_SERV_IDLE 0 +#define BTA_GATTC_SERV_LOAD 1 +#define BTA_GATTC_SERV_SAVE 2 +#define BTA_GATTC_SERV_DISC 3 +#define BTA_GATTC_SERV_DISC_ACT 4 + + UINT8 state; + + tBTA_GATTC_CACHE *p_srvc_cache; + tBTA_GATTC_CACHE *p_cur_srvc; + BUFFER_Q cache_buffer; /* buffer queue used for storing the cache data */ + UINT8 *p_free; /* starting point to next available byte */ + UINT16 free_byte; /* number of available bytes in server cache buffer */ + UINT8 update_count; /* indication received */ + UINT8 num_clcb; /* number of associated CLCB */ + + + tBTA_GATTC_ATTR_REC *p_srvc_list; + UINT8 cur_srvc_idx; + UINT8 cur_char_idx; + UINT8 next_avail_idx; + UINT8 total_srvc; + UINT8 total_char; + + UINT8 srvc_hdl_chg; /* service handle change indication pending */ + UINT16 attr_index; /* cahce NV saving/loading attribute index */ + + UINT16 mtu; +} tBTA_GATTC_SERV; + +#ifndef BTA_GATTC_NOTIF_REG_MAX +#define BTA_GATTC_NOTIF_REG_MAX 15 +#endif + +typedef struct { + BOOLEAN in_use; + BD_ADDR remote_bda; + tBTA_GATTC_CHAR_ID char_id; +} tBTA_GATTC_NOTIF_REG; + +typedef struct { + tBTA_GATTC_CBACK *p_cback; + BOOLEAN in_use; + tBTA_GATTC_IF client_if; /* client interface with BTE stack for this application */ + UINT8 num_clcb; /* number of associated CLCB */ + BOOLEAN dereg_pending; + tBT_UUID app_uuid; + tBTA_GATTC_NOTIF_REG notif_reg[BTA_GATTC_NOTIF_REG_MAX]; +} tBTA_GATTC_RCB; + +/* client channel is a mapping between a BTA client(cl_id) and a remote BD address */ +typedef struct { + UINT16 bta_conn_id; /* client channel ID, unique for clcb */ + BD_ADDR bda; + tBTA_TRANSPORT transport; /* channel transport */ + tBTA_GATTC_RCB *p_rcb; /* pointer to the registration CB */ + tBTA_GATTC_SERV *p_srcb; /* server cache CB */ + tBTA_GATTC_DATA *p_q_cmd; /* command in queue waiting for execution */ + +#define BTA_GATTC_NO_SCHEDULE 0 +#define BTA_GATTC_DISC_WAITING 0x01 +#define BTA_GATTC_REQ_WAITING 0x10 + + UINT8 auto_update; /* auto update is waiting */ + BOOLEAN disc_active; + BOOLEAN in_use; + tBTA_GATTC_STATE state; + tBTA_GATT_STATUS status; + UINT16 reason; +} tBTA_GATTC_CLCB; + +/* back ground connection tracking information */ +#if GATT_MAX_APPS <= 8 +typedef UINT8 tBTA_GATTC_CIF_MASK ; +#elif GATT_MAX_APPS <= 16 +typedef UINT16 tBTA_GATTC_CIF_MASK; +#elif GATT_MAX_APPS <= 32 +typedef UINT32 tBTA_GATTC_CIF_MASK; +#endif + +typedef struct { + BOOLEAN in_use; + BD_ADDR remote_bda; + tBTA_GATTC_CIF_MASK cif_mask; + tBTA_GATTC_CIF_MASK cif_adv_mask; + +} tBTA_GATTC_BG_TCK; + +typedef struct { + BOOLEAN in_use; + BD_ADDR remote_bda; +} tBTA_GATTC_CONN; + +enum { + BTA_GATTC_STATE_DISABLED, + BTA_GATTC_STATE_ENABLING, + BTA_GATTC_STATE_ENABLED, + BTA_GATTC_STATE_DISABLING +}; + +typedef struct { + UINT8 state; + + tBTA_GATTC_CONN conn_track[BTA_GATTC_CONN_MAX]; + tBTA_GATTC_BG_TCK bg_track[BTA_GATTC_KNOWN_SR_MAX]; + tBTA_GATTC_RCB cl_rcb[BTA_GATTC_CL_MAX]; + + tBTA_GATTC_CLCB clcb[BTA_GATTC_CLCB_MAX]; + tBTA_GATTC_SERV known_server[BTA_GATTC_KNOWN_SR_MAX]; + + tSDP_DISCOVERY_DB *p_sdp_db; + UINT16 sdp_conn_id; +} tBTA_GATTC_CB; + +/***************************************************************************** +** Global data +*****************************************************************************/ + +/* GATTC control block */ +#if BTA_DYNAMIC_MEMORY == FALSE +extern tBTA_GATTC_CB bta_gattc_cb; +#else +extern tBTA_GATTC_CB *bta_gattc_cb_ptr; +#define bta_gattc_cb (*bta_gattc_cb_ptr) +#endif + +/***************************************************************************** +** Function prototypes +*****************************************************************************/ +extern BOOLEAN bta_gattc_hdl_event(BT_HDR *p_msg); +extern BOOLEAN bta_gattc_sm_execute(tBTA_GATTC_CLCB *p_clcb, UINT16 event, tBTA_GATTC_DATA *p_data); + +/* function processed outside SM */ +extern void bta_gattc_disable(tBTA_GATTC_CB *p_cb); +extern void bta_gattc_register(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_data); +extern void bta_gattc_start_if(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_data); +extern void bta_gattc_process_api_open (tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg); +extern void bta_gattc_process_api_open_cancel (tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg); +extern void bta_gattc_deregister(tBTA_GATTC_CB *p_cb, tBTA_GATTC_RCB *p_clreg); +extern void bta_gattc_process_enc_cmpl(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg); + +/* function within state machine */ +extern void bta_gattc_open(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data); +extern void bta_gattc_open_fail(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data); +extern void bta_gattc_open_error(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data); + +extern void bta_gattc_cancel_open(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data); +extern void bta_gattc_cancel_open_ok(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data); +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_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); + +extern void bta_gattc_start_discover(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data); +extern void bta_gattc_disc_cmpl(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data); +extern void bta_gattc_read(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data); +extern void bta_gattc_write(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data); +extern void bta_gattc_op_cmpl(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data); +extern void bta_gattc_q_cmd(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data); +extern void bta_gattc_search(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data); +extern void bta_gattc_fail(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data); +extern void bta_gattc_confirm(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data); +extern void bta_gattc_execute(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data); +extern void bta_gattc_read_multi(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data); +extern void bta_gattc_ci_open(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data); +extern void bta_gattc_ci_load(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data); +extern void bta_gattc_ci_close(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data); +extern void bta_gattc_ci_save(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data); +extern void bta_gattc_cache_open(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data); +extern void bta_gattc_ignore_op_cmpl(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data); +extern void bta_gattc_restart_discover(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_msg); +extern void bta_gattc_init_bk_conn(tBTA_GATTC_API_OPEN *p_data, tBTA_GATTC_RCB *p_clreg); +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_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 +extern void bta_gattc_listen(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg); +extern void bta_gattc_broadcast(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg); +#endif +/* utility functions */ +extern tBTA_GATTC_CLCB *bta_gattc_find_clcb_by_cif (UINT8 client_if, BD_ADDR remote_bda, tBTA_TRANSPORT transport); +extern tBTA_GATTC_CLCB *bta_gattc_find_clcb_by_conn_id (UINT16 conn_id); +extern tBTA_GATTC_CLCB *bta_gattc_clcb_alloc(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, tBTA_TRANSPORT transport); +extern void bta_gattc_clcb_dealloc(tBTA_GATTC_CLCB *p_clcb); +extern tBTA_GATTC_CLCB *bta_gattc_find_alloc_clcb(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, tBTA_TRANSPORT transport); +extern tBTA_GATTC_RCB *bta_gattc_cl_get_regcb(UINT8 client_if); +extern tBTA_GATTC_SERV *bta_gattc_find_srcb(BD_ADDR bda); +extern tBTA_GATTC_SERV *bta_gattc_srcb_alloc(BD_ADDR bda); +extern tBTA_GATTC_SERV *bta_gattc_find_scb_by_cid (UINT16 conn_id); +extern tBTA_GATTC_CLCB *bta_gattc_find_int_conn_clcb(tBTA_GATTC_DATA *p_msg); +extern tBTA_GATTC_CLCB *bta_gattc_find_int_disconn_clcb(tBTA_GATTC_DATA *p_msg); + +extern BOOLEAN bta_gattc_enqueue(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data); + +extern UINT16 bta_gattc_id2handle(tBTA_GATTC_SERV *p_srcb, tBTA_GATT_SRVC_ID *p_service_id, tBTA_GATT_ID *p_char_id, tBTA_GATT_ID *p_descr_uuid); +extern BOOLEAN bta_gattc_handle2id(tBTA_GATTC_SERV *p_srcb, UINT16 handle, tBTA_GATT_SRVC_ID *service_id, tBTA_GATT_ID *char_id, tBTA_GATT_ID *p_type); +extern BOOLEAN bta_gattc_uuid_compare (tBT_UUID *p_src, tBT_UUID *p_tar, BOOLEAN is_precise); +extern void bta_gattc_pack_attr_uuid(tBTA_GATTC_CACHE_ATTR *p_attr, tBT_UUID *p_uuid); +extern BOOLEAN bta_gattc_check_notif_registry(tBTA_GATTC_RCB *p_clreg, tBTA_GATTC_SERV *p_srcb, tBTA_GATTC_NOTIFY *p_notify); +extern tBTA_GATT_STATUS bta_gattc_pack_read_cb_data(tBTA_GATTC_SERV *p_srcb, tBT_UUID *p_descr_uuid, tGATT_VALUE *p_attr, tBTA_GATT_READ_VAL *p_value); +extern BOOLEAN bta_gattc_mark_bg_conn (tBTA_GATTC_IF client_if, BD_ADDR_PTR remote_bda, BOOLEAN add, BOOLEAN is_listen); +extern BOOLEAN bta_gattc_check_bg_conn (tBTA_GATTC_IF client_if, BD_ADDR remote_bda, UINT8 role); +extern UINT8 bta_gattc_num_reg_app(void); +extern void bta_gattc_clear_notif_registration(UINT16 conn_id); +extern tBTA_GATTC_SERV *bta_gattc_find_srvr_cache(BD_ADDR bda); +extern BOOLEAN bta_gattc_charid_compare(tBTA_GATTC_CHAR_ID *p_src, tBTA_GATTC_CHAR_ID *p_tar); +extern BOOLEAN bta_gattc_srvcid_compare(tBTA_GATT_SRVC_ID *p_src, tBTA_GATT_SRVC_ID *p_tar); +extern void bta_gattc_cpygattid(tBTA_GATT_ID *p_des, tBTA_GATT_ID *p_src); + +/* discovery functions */ +extern void bta_gattc_disc_res_cback (UINT16 conn_id, tGATT_DISC_TYPE disc_type, tGATT_DISC_RES *p_data); +extern void bta_gattc_disc_cmpl_cback (UINT16 conn_id, tGATT_DISC_TYPE disc_type, tGATT_STATUS status); +extern tBTA_GATT_STATUS bta_gattc_discover_procedure(UINT16 conn_id, tBTA_GATTC_SERV *p_server_cb, UINT8 disc_type); +extern tBTA_GATT_STATUS bta_gattc_discover_pri_service(UINT16 conn_id, tBTA_GATTC_SERV *p_server_cb, UINT8 disc_type); +extern void bta_gattc_search_service(tBTA_GATTC_CLCB *p_clcb, tBT_UUID *p_uuid); +extern tBTA_GATT_STATUS bta_gattc_query_cache(UINT16 conn_id, UINT8 query_type, tBTA_GATT_SRVC_ID *p_srvc_id, + tBTA_GATT_ID *p_start_rec, tBT_UUID *p_uuid_cond, + tBTA_GATT_ID *p_output, void *p_param); +extern tBTA_GATT_STATUS bta_gattc_init_cache(tBTA_GATTC_SERV *p_srvc_cb); +extern void bta_gattc_rebuild_cache(tBTA_GATTC_SERV *p_srcv, UINT16 num_attr, tBTA_GATTC_NV_ATTR *p_attr, UINT16 attr_index); +extern BOOLEAN bta_gattc_cache_save(tBTA_GATTC_SERV *p_srvc_cb, UINT16 conn_id); + + +extern tBTA_GATTC_CONN *bta_gattc_conn_alloc(BD_ADDR remote_bda); +extern tBTA_GATTC_CONN *bta_gattc_conn_find(BD_ADDR remote_bda); +extern tBTA_GATTC_CONN *bta_gattc_conn_find_alloc(BD_ADDR remote_bda); +extern BOOLEAN bta_gattc_conn_dealloc(BD_ADDR remote_bda); + +#endif /* BTA_GATTC_INT_H */ diff --git a/tools/sdk/include/bluedroid/bta_gatts_co.h b/tools/sdk/include/bluedroid/bta_gatts_co.h new file mode 100644 index 00000000..78e001b7 --- /dev/null +++ b/tools/sdk/include/bluedroid/bta_gatts_co.h @@ -0,0 +1,81 @@ +/****************************************************************************** + * + * Copyright (C) 2010-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 is the interface file for BTA GATT server call-out functions. + * + ******************************************************************************/ +#ifndef BTA_GATTS_CO_H +#define BTA_GATTS_CO_H + +#include "bta_gatt_api.h" + +/******************************************************************************* +** +** Function bta_gatts_co_update_handle_range +** +** Description This callout function is executed by GATTS when a GATT server +** handle range ios to be added or removed. +** +** Parameter is_add: true is to add a handle range; otherwise is to delete. +** p_hndl_range: handle range. +** +** Returns void. +** +*******************************************************************************/ +extern void bta_gatts_co_update_handle_range(BOOLEAN is_add, tBTA_GATTS_HNDL_RANGE *p_hndl_range); + +/******************************************************************************* +** +** Function bta_gatts_co_srv_chg +** +** Description This call-out is to read/write/remove service change related +** informaiton. The request consists of the cmd and p_req and the +** response is returned in p_rsp +** +** Parameter cmd - request command +** p_req - request paramters +** p_rsp - response data for the request +** +** Returns TRUE - if the request is processed successfully and +** the response is returned in p_rsp. +** FASLE - if the request can not be processed +** +*******************************************************************************/ +extern BOOLEAN bta_gatts_co_srv_chg(tBTA_GATTS_SRV_CHG_CMD cmd, + tBTA_GATTS_SRV_CHG_REQ *p_req, + tBTA_GATTS_SRV_CHG_RSP *p_rsp); + +/******************************************************************************* +** +** Function bta_gatts_co_load_handle_range +** +** Description This callout function is executed by GATTS when a GATT server +** handle range is requested to be loaded from NV. +** +** Parameter +** +** Returns void. +** +*******************************************************************************/ +extern BOOLEAN bta_gatts_co_load_handle_range(UINT8 index, + tBTA_GATTS_HNDL_RANGE *p_handle); + + +#endif /* BTA_GATTS_CO_H */ diff --git a/tools/sdk/include/bluedroid/bta_gatts_int.h b/tools/sdk/include/bluedroid/bta_gatts_int.h new file mode 100644 index 00000000..0f9e689a --- /dev/null +++ b/tools/sdk/include/bluedroid/bta_gatts_int.h @@ -0,0 +1,256 @@ +/****************************************************************************** + * + * 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 is the private file for the BTA GATT server. + * + ******************************************************************************/ +#ifndef BTA_GATTS_INT_H +#define BTA_GATTS_INT_H + +#include "bt_target.h" +#include "bta_sys.h" +#include "bta_gatt_api.h" +#include "gatt_api.h" + +#include "gki.h" + +/***************************************************************************** +** Constants and data types +*****************************************************************************/ +enum { + BTA_GATTS_API_REG_EVT = BTA_SYS_EVT_START(BTA_ID_GATTS), + BTA_GATTS_INT_START_IF_EVT, + BTA_GATTS_API_DEREG_EVT, + BTA_GATTS_API_CREATE_SRVC_EVT, + BTA_GATTS_API_INDICATION_EVT, + + BTA_GATTS_API_ADD_INCL_SRVC_EVT, + BTA_GATTS_API_ADD_CHAR_EVT, + BTA_GATTS_API_ADD_DESCR_EVT, + BTA_GATTS_API_DEL_SRVC_EVT, + BTA_GATTS_API_START_SRVC_EVT, + BTA_GATTS_API_STOP_SRVC_EVT, + BTA_GATTS_API_RSP_EVT, + BTA_GATTS_API_SET_ATTR_VAL_EVT, + BTA_GATTS_API_OPEN_EVT, + BTA_GATTS_API_CANCEL_OPEN_EVT, + BTA_GATTS_API_CLOSE_EVT, + BTA_GATTS_API_LISTEN_EVT, + BTA_GATTS_API_DISABLE_EVT +}; +typedef UINT16 tBTA_GATTS_INT_EVT; + +/* max number of application allowed on device */ +#define BTA_GATTS_MAX_APP_NUM GATT_MAX_SR_PROFILES + +/* max number of services allowed in the device */ +#define BTA_GATTS_MAX_SRVC_NUM GATT_MAX_SR_PROFILES + +/* internal strucutre for GATTC register API */ +typedef struct { + BT_HDR hdr; + tBT_UUID app_uuid; + tBTA_GATTS_CBACK *p_cback; +} tBTA_GATTS_API_REG; + +typedef struct { + BT_HDR hdr; + tBTA_GATTS_IF server_if; +} tBTA_GATTS_INT_START_IF; + +typedef tBTA_GATTS_INT_START_IF tBTA_GATTS_API_DEREG; + +typedef struct { + BT_HDR hdr; + tBTA_GATTS_IF server_if; + tBT_UUID service_uuid; + UINT16 num_handle; + UINT8 inst; + BOOLEAN is_pri; + +} tBTA_GATTS_API_CREATE_SRVC; + +typedef struct { + BT_HDR hdr; + tBT_UUID char_uuid; + tBTA_GATT_PERM perm; + tBTA_GATT_CHAR_PROP property; + tBTA_GATTS_ATTR_CONTROL control; + tBTA_GATT_ATTR_VAL attr_val; +} tBTA_GATTS_API_ADD_CHAR; + +typedef struct { + BT_HDR hdr; + UINT16 included_service_id; +} tBTA_GATTS_API_ADD_INCL_SRVC; + +typedef struct { + BT_HDR hdr; + tBT_UUID descr_uuid; + tBTA_GATT_PERM perm; + tBTA_GATTS_ATTR_CONTROL control; + tBTA_GATT_ATTR_VAL attr_val; +} tBTA_GATTS_API_ADD_DESCR; + +typedef struct { + BT_HDR hdr; + UINT16 attr_id; + UINT16 len; + BOOLEAN need_confirm; + UINT8 value[BTA_GATT_MAX_ATTR_LEN]; +} tBTA_GATTS_API_INDICATION; + +typedef struct { + BT_HDR hdr; + UINT32 trans_id; + tBTA_GATT_STATUS status; + tBTA_GATTS_RSP *p_rsp; +} tBTA_GATTS_API_RSP; + +typedef struct{ + BT_HDR hdr; + UINT16 length; + UINT8 *value; +}tBTA_GATTS_API_SET_ATTR_VAL; + +typedef struct { + BT_HDR hdr; + tBTA_GATT_TRANSPORT transport; +} tBTA_GATTS_API_START; + + +typedef struct { + BT_HDR hdr; + BD_ADDR remote_bda; + tBTA_GATTS_IF server_if; + BOOLEAN is_direct; + tBTA_GATT_TRANSPORT transport; + +} tBTA_GATTS_API_OPEN; + +typedef tBTA_GATTS_API_OPEN tBTA_GATTS_API_CANCEL_OPEN; + +typedef struct { + BT_HDR hdr; + BD_ADDR_PTR remote_bda; + tBTA_GATTS_IF server_if; + BOOLEAN start; +} tBTA_GATTS_API_LISTEN; + +typedef union { + BT_HDR hdr; + tBTA_GATTS_API_REG api_reg; + tBTA_GATTS_API_DEREG api_dereg; + tBTA_GATTS_API_CREATE_SRVC api_create_svc; + tBTA_GATTS_API_ADD_INCL_SRVC api_add_incl_srvc; + tBTA_GATTS_API_ADD_CHAR api_add_char; + tBTA_GATTS_API_ADD_DESCR api_add_char_descr; + tBTA_GATTS_API_START api_start; + tBTA_GATTS_API_INDICATION api_indicate; + tBTA_GATTS_API_RSP api_rsp; + tBTA_GATTS_API_SET_ATTR_VAL api_set_val; + tBTA_GATTS_API_OPEN api_open; + tBTA_GATTS_API_CANCEL_OPEN api_cancel_open; + + tBTA_GATTS_INT_START_IF int_start_if; + /* if peripheral role is supported */ + tBTA_GATTS_API_LISTEN api_listen; +} tBTA_GATTS_DATA; + +/* application registration control block */ +typedef struct { + BOOLEAN in_use; + tBT_UUID app_uuid; + tBTA_GATTS_CBACK *p_cback; + tBTA_GATTS_IF gatt_if; +} tBTA_GATTS_RCB; + +/* service registration control block */ +typedef struct { + tBT_UUID service_uuid; /* service UUID */ + UINT16 service_id; /* service handle */ + UINT8 inst_num; /* instance ID */ + UINT8 rcb_idx; + UINT8 idx; /* self index of serviec CB */ + BOOLEAN in_use; + +} tBTA_GATTS_SRVC_CB; + + +/* GATT server control block */ +typedef struct { + BOOLEAN enabled; + tBTA_GATTS_RCB rcb[BTA_GATTS_MAX_APP_NUM]; + tBTA_GATTS_SRVC_CB srvc_cb[BTA_GATTS_MAX_SRVC_NUM]; +} tBTA_GATTS_CB; + + + +/***************************************************************************** +** Global data +*****************************************************************************/ + +/* GATTC control block */ +#if BTA_DYNAMIC_MEMORY == FALSE +extern tBTA_GATTS_CB bta_gatts_cb; +#else +extern tBTA_GATTS_CB *bta_gatts_cb_ptr; +#define bta_gatts_cb (*bta_gatts_cb_ptr) +#endif + +/***************************************************************************** +** Function prototypes +*****************************************************************************/ +extern BOOLEAN bta_gatts_hdl_event(BT_HDR *p_msg); + +extern void bta_gatts_api_disable(tBTA_GATTS_CB *p_cb); +extern void bta_gatts_api_enable(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_data); +extern void bta_gatts_register(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg); +extern void bta_gatts_start_if(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg); +extern void bta_gatts_deregister(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg); +extern void bta_gatts_create_srvc(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg); +extern void bta_gatts_add_include_srvc(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_msg); +extern void bta_gatts_add_char(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_msg); +extern void bta_gatts_add_char_descr(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_msg); +extern void bta_gatts_set_attr_value(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_msg); +extern void bta_gatts_get_attr_value(UINT16 attr_handle, UINT16 *length, UINT8 **value); +extern void bta_gatts_delete_service(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_msg); +extern void bta_gatts_start_service(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_msg); +extern void bta_gatts_stop_service(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_msg); + +extern void bta_gatts_send_rsp(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg); +extern void bta_gatts_indicate_handle (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg); + + +extern void bta_gatts_open (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg); +extern void bta_gatts_cancel_open (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg); +extern void bta_gatts_close (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg); +extern void bta_gatts_listen(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg); + +extern BOOLEAN bta_gatts_uuid_compare(tBT_UUID tar, tBT_UUID src); +extern tBTA_GATTS_RCB *bta_gatts_find_app_rcb_by_app_if(tBTA_GATTS_IF server_if); +extern UINT8 bta_gatts_find_app_rcb_idx_by_app_if(tBTA_GATTS_CB *p_cb, tBTA_GATTS_IF server_if); +extern UINT8 bta_gatts_alloc_srvc_cb(tBTA_GATTS_CB *p_cb, UINT8 rcb_idx); +extern tBTA_GATTS_SRVC_CB *bta_gatts_find_srvc_cb_by_srvc_id(tBTA_GATTS_CB *p_cb, UINT16 service_id); +extern tBTA_GATTS_SRVC_CB *bta_gatts_find_srvc_cb_by_attr_id(tBTA_GATTS_CB *p_cb, UINT16 attr_id); + + +#endif /* BTA_GATTS_INT_H */ + diff --git a/tools/sdk/include/bluedroid/bta_hh_api.h b/tools/sdk/include/bluedroid/bta_hh_api.h new file mode 100644 index 00000000..d6b31740 --- /dev/null +++ b/tools/sdk/include/bluedroid/bta_hh_api.h @@ -0,0 +1,541 @@ +/****************************************************************************** + * + * 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. + * + ******************************************************************************/ +#ifndef BTA_HH_API_H +#define BTA_HH_API_H + +#include "bta_api.h" +#include "hidh_api.h" + +#if (defined BTA_HH_LE_INCLUDED && BTA_HH_LE_INCLUDED == TRUE) +#include "gatt_api.h" +#endif + +/***************************************************************************** +** Constants and Type Definitions +*****************************************************************************/ +#ifndef BTA_HH_DEBUG +#define BTA_HH_DEBUG TRUE +#endif + +#ifndef BTA_HH_SSR_MAX_LATENCY_DEF +#define BTA_HH_SSR_MAX_LATENCY_DEF 800 /* 500 ms*/ +#endif + +#ifndef BTA_HH_SSR_MIN_TOUT_DEF +#define BTA_HH_SSR_MIN_TOUT_DEF 2 +#endif + +/* BTA HID Host callback events */ +#define BTA_HH_ENABLE_EVT 0 /* HH enabled */ +#define BTA_HH_DISABLE_EVT 1 /* HH disabled */ +#define BTA_HH_OPEN_EVT 2 /* connection opened */ +#define BTA_HH_CLOSE_EVT 3 /* connection closed */ +#define BTA_HH_GET_RPT_EVT 4 /* BTA_HhGetReport callback */ +#define BTA_HH_SET_RPT_EVT 5 /* BTA_HhSetReport callback */ +#define BTA_HH_GET_PROTO_EVT 6 /* BTA_GetProtoMode callback */ +#define BTA_HH_SET_PROTO_EVT 7 /* BTA_HhSetProtoMode callback */ +#define BTA_HH_GET_IDLE_EVT 8 /* BTA_HhGetIdle comes callback */ +#define BTA_HH_SET_IDLE_EVT 9 /* BTA_HhSetIdle finish callback */ +#define BTA_HH_GET_DSCP_EVT 10 /* Get report descriptor */ +#define BTA_HH_ADD_DEV_EVT 11 /* Add Device callback */ +#define BTA_HH_RMV_DEV_EVT 12 /* remove device finished */ +#define BTA_HH_VC_UNPLUG_EVT 13 /* virtually unplugged */ +#define BTA_HH_DATA_EVT 15 +#define BTA_HH_API_ERR_EVT 16 /* API error is caught */ +#define BTA_HH_UPDATE_SCPP_EVT 17 /* update scan paramter complete */ + +typedef UINT16 tBTA_HH_EVT; + +/* application ID(none-zero) for each type of device */ +#define BTA_HH_APP_ID_MI 1 +#define BTA_HH_APP_ID_KB 2 +#define BTA_HH_APP_ID_RMC 3 +#define BTA_HH_APP_ID_3DSG 4 +#define BTA_HH_APP_ID_JOY 5 +#define BTA_HH_APP_ID_GPAD 6 +#define BTA_HH_APP_ID_LE 0xff + +/* defined the minimum offset */ +#define BTA_HH_MIN_OFFSET L2CAP_MIN_OFFSET+1 + +/* HID_HOST_MAX_DEVICES can not exceed 15 for th design of BTA HH */ +#define BTA_HH_IDX_INVALID 0xff +#define BTA_HH_MAX_KNOWN HID_HOST_MAX_DEVICES + +#if (defined BTA_HH_LE_INCLUDED && BTA_HH_LE_INCLUDED == TRUE) +/* GATT_MAX_PHY_CHANNEL can not exceed 14 for the design of BTA HH */ +#define BTA_HH_LE_MAX_KNOWN GATT_MAX_PHY_CHANNEL +#define BTA_HH_MAX_DEVICE (HID_HOST_MAX_DEVICES + GATT_MAX_PHY_CHANNEL) +#else +#define BTA_HH_MAX_DEVICE HID_HOST_MAX_DEVICES +#endif +/* invalid device handle */ +#define BTA_HH_INVALID_HANDLE 0xff + +/* type of protocol mode */ +#define BTA_HH_PROTO_RPT_MODE (0x00) +#define BTA_HH_PROTO_BOOT_MODE (0x01) +#define BTA_HH_PROTO_UNKNOWN (0xff) +typedef UINT8 tBTA_HH_PROTO_MODE; + +enum { + BTA_HH_KEYBD_RPT_ID = 1, + BTA_HH_MOUSE_RPT_ID +}; +typedef UINT8 tBTA_HH_BOOT_RPT_ID; + +/* type of devices, bit mask */ +#define BTA_HH_DEVT_UNKNOWN 0x00 +#define BTA_HH_DEVT_JOS 0x01 /* joy stick */ +#define BTA_HH_DEVT_GPD 0x02 /* game pad */ +#define BTA_HH_DEVT_RMC 0x03 /* remote control */ +#define BTA_HH_DEVT_SED 0x04 /* sensing device */ +#define BTA_HH_DEVT_DGT 0x05 /* Digitizer tablet */ +#define BTA_HH_DEVT_CDR 0x06 /* card reader */ +#define BTA_HH_DEVT_KBD 0x10 /* keyboard */ +#define BTA_HH_DEVT_MIC 0x20 /* pointing device */ +#define BTA_HH_DEVT_COM 0x30 /* Combo keyboard/pointing */ +#define BTA_HH_DEVT_OTHER 0x80 +typedef UINT8 tBTA_HH_DEVT; + +enum { + BTA_HH_OK, + BTA_HH_HS_HID_NOT_READY, /* handshake error : device not ready */ + BTA_HH_HS_INVALID_RPT_ID, /* handshake error : invalid report ID */ + BTA_HH_HS_TRANS_NOT_SPT, /* handshake error : transaction not spt */ + BTA_HH_HS_INVALID_PARAM, /* handshake error : invalid paremter */ + BTA_HH_HS_ERROR, /* handshake error : unspecified HS error */ + BTA_HH_ERR, /* general BTA HH error */ + BTA_HH_ERR_SDP, /* SDP error */ + BTA_HH_ERR_PROTO, /* SET_Protocol error, + only used in BTA_HH_OPEN_EVT callback */ + + BTA_HH_ERR_DB_FULL, /* device database full error, used in + BTA_HH_OPEN_EVT/BTA_HH_ADD_DEV_EVT */ + BTA_HH_ERR_TOD_UNSPT, /* type of device not supported */ + BTA_HH_ERR_NO_RES, /* out of system resources */ + BTA_HH_ERR_AUTH_FAILED, /* authentication fail */ + BTA_HH_ERR_HDL, + BTA_HH_ERR_SEC +}; +typedef UINT8 tBTA_HH_STATUS; + + +#define BTA_HH_VIRTUAL_CABLE HID_VIRTUAL_CABLE +#define BTA_HH_NORMALLY_CONNECTABLE HID_NORMALLY_CONNECTABLE +#define BTA_HH_RECONN_INIT HID_RECONN_INIT +#define BTA_HH_SDP_DISABLE HID_SDP_DISABLE +#define BTA_HH_BATTERY_POWER HID_BATTERY_POWER +#define BTA_HH_REMOTE_WAKE HID_REMOTE_WAKE +#define BTA_HH_SUP_TOUT_AVLBL HID_SUP_TOUT_AVLBL +#define BTA_HH_SEC_REQUIRED HID_SEC_REQUIRED +typedef UINT16 tBTA_HH_ATTR_MASK; + +/* supported type of device and corresponding application ID */ +typedef struct { + tBTA_HH_DEVT tod; /* type of device */ + UINT8 app_id; /* corresponding application ID */ +} tBTA_HH_SPT_TOD; + +/* configuration struct */ +typedef struct { + UINT8 max_devt_spt; /* max number of types of devices spt */ + tBTA_HH_SPT_TOD *p_devt_list; /* supported types of device list */ + UINT16 sdp_db_size; +} tBTA_HH_CFG; + +enum { + BTA_HH_RPTT_RESRV, /* reserved */ + BTA_HH_RPTT_INPUT, /* input report */ + BTA_HH_RPTT_OUTPUT, /* output report */ + BTA_HH_RPTT_FEATURE /* feature report */ +}; +typedef UINT8 tBTA_HH_RPT_TYPE; + +/* HID_CONTROL operation code used in BTA_HhSendCtrl() +*/ +enum { + BTA_HH_CTRL_NOP = 0 + HID_PAR_CONTROL_NOP ,/* mapping from BTE */ + BTA_HH_CTRL_HARD_RESET, /* hard reset */ + BTA_HH_CTRL_SOFT_RESET, /* soft reset */ + BTA_HH_CTRL_SUSPEND, /* enter suspend */ + BTA_HH_CTRL_EXIT_SUSPEND, /* exit suspend */ + BTA_HH_CTRL_VIRTUAL_CABLE_UNPLUG /* virtual unplug */ +}; +typedef UINT8 tBTA_HH_TRANS_CTRL_TYPE; + +typedef tHID_DEV_DSCP_INFO tBTA_HH_DEV_DESCR; + +#define BTA_HH_SSR_PARAM_INVALID HID_SSR_PARAM_INVALID + +/* id DI is not existing in remote device, vendor_id in tBTA_HH_DEV_DSCP_INFO will be set to 0xffff */ +#define BTA_HH_VENDOR_ID_INVALID 0xffff + + +/* report descriptor information */ +typedef struct { + UINT16 vendor_id; /* vendor ID */ + UINT16 product_id; /* product ID */ + UINT16 version; /* version */ + UINT16 ssr_max_latency; /* SSR max latency, BTA_HH_SSR_PARAM_INVALID if unknown */ + UINT16 ssr_min_tout; /* SSR min timeout, BTA_HH_SSR_PARAM_INVALID if unknown */ + UINT8 ctry_code; /*Country Code.*/ +#if (defined BTA_HH_LE_INCLUDED && BTA_HH_LE_INCLUDED == TRUE) +#define BTA_HH_LE_REMOTE_WAKE 0x01 +#define BTA_HH_LE_NORMAL_CONN 0x02 + + UINT8 flag; +#endif + tBTA_HH_DEV_DESCR descriptor; +} tBTA_HH_DEV_DSCP_INFO; + +/* callback event data for BTA_HH_OPEN_EVT */ +typedef struct { + BD_ADDR bda; /* HID device bd address */ + tBTA_HH_STATUS status; /* operation status */ + UINT8 handle; /* device handle */ +#if (defined BTA_HH_LE_INCLUDED && BTA_HH_LE_INCLUDED == TRUE) + BOOLEAN le_hid; /* is LE devices? */ + BOOLEAN scps_supported; /* scan parameter service supported */ +#endif + +} tBTA_HH_CONN; + +typedef tBTA_HH_CONN tBTA_HH_DEV_INFO; + +/* callback event data */ +typedef struct { + tBTA_HH_STATUS status; /* operation status */ + UINT8 handle; /* device handle */ +} tBTA_HH_CBDATA; + +enum { + BTA_HH_MOD_CTRL_KEY, + BTA_HH_MOD_SHFT_KEY, + BTA_HH_MOD_ALT_KEY, + BTA_HH_MOD_GUI_KEY, + BTA_HH_MOD_MAX_KEY +}; + +/* parsed boot mode keyboard report */ +typedef struct { + UINT8 this_char[6]; /* virtual key code */ + BOOLEAN mod_key[BTA_HH_MOD_MAX_KEY]; + /* ctrl, shift, Alt, GUI */ + /* modifier key: is Shift key pressed */ + /* modifier key: is Ctrl key pressed */ + /* modifier key: is Alt key pressed */ + /* modifier key: GUI up/down */ + BOOLEAN caps_lock; /* is caps locked */ + BOOLEAN num_lock; /* is Num key pressed */ +} tBTA_HH_KEYBD_RPT; + +/* parsed boot mode mouse report */ +typedef struct { + UINT8 mouse_button; /* mouse button is clicked */ + INT8 delta_x; /* displacement x */ + INT8 delta_y; /* displacement y */ +} tBTA_HH_MICE_RPT; + +/* parsed Boot report */ +typedef struct { + tBTA_HH_BOOT_RPT_ID dev_type; /* type of device report */ + union { + tBTA_HH_KEYBD_RPT keybd_rpt; /* keyboard report */ + tBTA_HH_MICE_RPT mice_rpt; /* mouse report */ + } data_rpt; +} tBTA_HH_BOOT_RPT; + +/* handshake data */ +typedef struct { + tBTA_HH_STATUS status; /* handshake status */ + UINT8 handle; /* device handle */ + union { + tBTA_HH_PROTO_MODE proto_mode; /* GET_PROTO_EVT :protocol mode */ + BT_HDR *p_rpt_data; /* GET_RPT_EVT : report data */ + UINT8 idle_rate; /* GET_IDLE_EVT : idle rate */ + } rsp_data; + +} tBTA_HH_HSDATA; + +/* union of data associated with HD callback */ +typedef union { + tBTA_HH_DEV_INFO dev_info; /* BTA_HH_ADD_DEV_EVT, BTA_HH_RMV_DEV_EVT */ + tBTA_HH_CONN conn; /* BTA_HH_OPEN_EVT */ + tBTA_HH_CBDATA dev_status; /* BTA_HH_CLOSE_EVT, + BTA_HH_SET_PROTO_EVT + BTA_HH_SET_RPT_EVT + BTA_HH_SET_IDLE_EVT + BTA_HH_UPDATE_SCPP_EVT */ + + tBTA_HH_STATUS status; /* BTA_HH_ENABLE_EVT */ + tBTA_HH_DEV_DSCP_INFO dscp_info; /* BTA_HH_GET_DSCP_EVT */ + tBTA_HH_HSDATA hs_data; /* GET_ transaction callback + BTA_HH_GET_RPT_EVT + BTA_HH_GET_PROTO_EVT + BTA_HH_GET_IDLE_EVT */ +} tBTA_HH; + +/* BTA HH callback function */ +typedef void (tBTA_HH_CBACK) (tBTA_HH_EVT event, tBTA_HH *p_data); + + +/***************************************************************************** +** External Function Declarations +*****************************************************************************/ +#ifdef __cplusplus +extern "C" +{ +#endif + +/******************************************************************************* +** +** Function BTA_HhRegister +** +** Description This function enable HID host and registers HID-Host with +** lower layers. +** +** Returns void +** +*******************************************************************************/ +extern void BTA_HhEnable(tBTA_SEC sec_mask, tBTA_HH_CBACK *p_cback); + +/******************************************************************************* +** +** Function BTA_HhDeregister +** +** Description This function is called when the host is about power down. +** +** Returns void +** +*******************************************************************************/ +extern void BTA_HhDisable(void); + +/******************************************************************************* +** +** Function BTA_HhOpen +** +** Description This function is called to start an inquiry and read SDP +** record of responding devices; connect to a device if only +** one active HID device is found. +** +** Returns void +** +*******************************************************************************/ +extern void BTA_HhOpen (BD_ADDR dev_bda, tBTA_HH_PROTO_MODE mode, + tBTA_SEC sec_mask); + +/******************************************************************************* +** +** Function BTA_HhClose +** +** Description This function disconnects the device. +** +** Returns void +** +*******************************************************************************/ +extern void BTA_HhClose(UINT8 dev_handle); + +/******************************************************************************* +** +** Function BTA_HhSetProtoMode +** +** Description This function set the protocol mode at specified HID handle +** +** Returns void +** +*******************************************************************************/ +extern void BTA_HhSetProtoMode(UINT8 handle, tBTA_HH_PROTO_MODE t_type); + +/******************************************************************************* +** +** Function BTA_HhGetProtoMode +** +** Description This function get the protocol mode of a specified HID device. +** +** Returns void +** +*******************************************************************************/ +extern void BTA_HhGetProtoMode(UINT8 dev_handle); +/******************************************************************************* +** +** Function BTA_HhSetReport +** +** Description send SET_REPORT to device. +** +** Returns void +** +*******************************************************************************/ +extern void BTA_HhSetReport(UINT8 dev_handle, tBTA_HH_RPT_TYPE r_type, + BT_HDR *p_data); + +/******************************************************************************* +** +** Function BTA_HhGetReport +** +** Description Send a GET_REPORT to HID device. +** +** Returns void +** +*******************************************************************************/ +extern void BTA_HhGetReport(UINT8 dev_handle, tBTA_HH_RPT_TYPE r_type, + UINT8 rpt_id, UINT16 buf_size); +/******************************************************************************* +** +** Function BTA_HhSetIdle +** +** Description send SET_IDLE to device. +** +** Returns void +** +*******************************************************************************/ +extern void BTA_HhSetIdle(UINT8 dev_handle, UINT16 idle_rate); + +/******************************************************************************* +** +** Function BTA_HhGetIdle +** +** Description Send a GET_IDLE to HID device. +** +** Returns void +** +*******************************************************************************/ +extern void BTA_HhGetIdle(UINT8 dev_handle); + +/******************************************************************************* +** +** Function BTA_HhSendCtrl +** +** Description Send HID_CONTROL request to a HID device. +** +** Returns void +** +*******************************************************************************/ +extern void BTA_HhSendCtrl(UINT8 dev_handle, + tBTA_HH_TRANS_CTRL_TYPE c_type); + +/******************************************************************************* +** +** Function BTA_HhSetIdle +** +** Description send SET_IDLE to device. +** +** Returns void +** +*******************************************************************************/ +extern void BTA_HhSetIdle(UINT8 dev_handle, UINT16 idle_rate); + + +/******************************************************************************* +** +** Function BTA_HhGetIdle +** +** Description Send a GET_IDLE from HID device. +** +** Returns void +** +*******************************************************************************/ +extern void BTA_HhGetIdle(UINT8 dev_handle); + +/******************************************************************************* +** +** Function BTA_HhSendData +** +** Description Send DATA transaction to a HID device. +** +** Returns void +** +*******************************************************************************/ +extern void BTA_HhSendData(UINT8 dev_handle, BD_ADDR dev_bda, BT_HDR *p_buf); + +/******************************************************************************* +** +** Function BTA_HhGetDscpInfo +** +** Description Get report descriptor of the device +** +** Returns void +** +*******************************************************************************/ +extern void BTA_HhGetDscpInfo(UINT8 dev_handle); + +/******************************************************************************* +** Function BTA_HhAddDev +** +** Description Add a virtually cabled device into HID-Host device list +** to manage and assign a device handle for future API call, +** host applciation call this API at start-up to initialize its +** virtually cabled devices. +** +** Returns void +** +*******************************************************************************/ +extern void BTA_HhAddDev(BD_ADDR bda, tBTA_HH_ATTR_MASK attr_mask, + UINT8 sub_class, UINT8 app_id, + tBTA_HH_DEV_DSCP_INFO dscp_info); +/******************************************************************************* +** +** Function BTA_HhRemoveDev +** +** Description Remove a device from the HID host devices list. +** +** Returns void +** +*******************************************************************************/ +extern void BTA_HhRemoveDev(UINT8 dev_handle ); + +/******************************************************************************* +** +** Parsing Utility Functions +** +*******************************************************************************/ +/******************************************************************************* +** +** Function BTA_HhParseBootRpt +** +** Description This utility function parse a boot mode report. +** +** Returns void +** +*******************************************************************************/ +extern void BTA_HhParseBootRpt(tBTA_HH_BOOT_RPT *p_data, UINT8 *p_report, + UINT16 report_len); + +#if BTA_HH_LE_INCLUDED == TRUE +/******************************************************************************* +** +** Function BTA_HhUpdateLeScanParam +** +** Description Update the scan paramteters if connected to a LE hid device as +** report host. +** +** Returns void +** +*******************************************************************************/ +extern void BTA_HhUpdateLeScanParam(UINT8 dev_handle, UINT16 scan_int, UINT16 scan_win); +#endif +/* test commands */ +extern void bta_hh_le_hid_read_rpt_clt_cfg(BD_ADDR bd_addr, UINT8 rpt_id); + + + +#ifdef __cplusplus +} +#endif + +#endif /* BTA_HH_API_H */ diff --git a/tools/sdk/include/bluedroid/bta_hh_co.h b/tools/sdk/include/bluedroid/bta_hh_co.h new file mode 100644 index 00000000..9cbb1550 --- /dev/null +++ b/tools/sdk/include/bluedroid/bta_hh_co.h @@ -0,0 +1,132 @@ +/****************************************************************************** + * + * Copyright (C) 2005-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 is the interface file for hid host call-out functions. + * + ******************************************************************************/ +#ifndef BTA_HH_CO_H +#define BTA_HH_CO_H + +#include "bta_hh_api.h" + +typedef struct { + UINT16 rpt_uuid; + UINT8 rpt_id; + tBTA_HH_RPT_TYPE rpt_type; + UINT8 inst_id; + UINT8 prop; +} tBTA_HH_RPT_CACHE_ENTRY; + +/******************************************************************************* +** +** Function bta_hh_co_data +** +** Description This callout function is executed by HH when data is received +** in interupt channel. +** +** +** Returns void. +** +*******************************************************************************/ +extern void bta_hh_co_data(UINT8 dev_handle, UINT8 *p_rpt, UINT16 len, + tBTA_HH_PROTO_MODE mode, UINT8 sub_class, + UINT8 ctry_code, BD_ADDR peer_addr, UINT8 app_id); + +/******************************************************************************* +** +** Function bta_hh_co_open +** +** Description This callout function is executed by HH when connection is +** opened, and application may do some device specific +** initialization. +** +** Returns void. +** +*******************************************************************************/ +extern void bta_hh_co_open(UINT8 dev_handle, UINT8 sub_class, + UINT16 attr_mask, UINT8 app_id); + +/******************************************************************************* +** +** Function bta_hh_co_close +** +** Description This callout function is executed by HH when connection is +** closed, and device specific finalizatio nmay be needed. +** +** Returns void. +** +*******************************************************************************/ +extern void bta_hh_co_close(UINT8 dev_handle, UINT8 app_id); + +#if (BLE_INCLUDED == TRUE && BTA_HH_LE_INCLUDED == TRUE) +/******************************************************************************* +** +** Function bta_hh_le_co_rpt_info +** +** Description This callout function is to convey the report information on +** a HOGP device to the application. Application can save this +** information in NV if device is bonded and load it back when +** stack reboot. +** +** Parameters remote_bda - remote device address +** p_entry - report entry pointer +** app_id - application id +** +** Returns void. +** +*******************************************************************************/ +extern void bta_hh_le_co_rpt_info(BD_ADDR remote_bda, + tBTA_HH_RPT_CACHE_ENTRY *p_entry, + UINT8 app_id); + +/******************************************************************************* +** +** Function bta_hh_le_co_cache_load +** +** Description This callout function is to request the application to load the +** cached HOGP report if there is any. When cache reading is completed, +** bta_hh_le_ci_cache_load() is called by the application. +** +** Parameters remote_bda - remote device address +** p_num_rpt: number of cached report +** app_id - application id +** +** Returns the acched report array +** +*******************************************************************************/ +extern tBTA_HH_RPT_CACHE_ENTRY *bta_hh_le_co_cache_load (BD_ADDR remote_bda, + UINT8 *p_num_rpt, + UINT8 app_id); + +/******************************************************************************* +** +** Function bta_hh_le_co_reset_rpt_cache +** +** Description This callout function is to reset the HOGP device cache. +** +** Parameters remote_bda - remote device address +** +** Returns none +** +*******************************************************************************/ +extern void bta_hh_le_co_reset_rpt_cache (BD_ADDR remote_bda, UINT8 app_id); + +#endif /* #if (BLE_INCLUDED == TRUE && BTA_HH_LE_INCLUDED == TRUE) */ +#endif /* BTA_HH_CO_H */ diff --git a/tools/sdk/include/bluedroid/bta_sdp_api.h b/tools/sdk/include/bluedroid/bta_sdp_api.h new file mode 100644 index 00000000..c2df4bb9 --- /dev/null +++ b/tools/sdk/include/bluedroid/bta_sdp_api.h @@ -0,0 +1,142 @@ +/****************************************************************************** + * + * Copyright (C) 2015 The Android Open Source Project + * + * 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 is the public interface file for the BTA SDP I/F + * + ******************************************************************************/ +#ifndef BTA_SDP_API_H +#define BTA_SDP_API_H + +#include "bt_sdp.h" +#include "bt_target.h" +#include "bt_types.h" +#include "bta_api.h" +#include "btm_api.h" + +/* status values */ +#define BTA_SDP_SUCCESS 0 /* Successful operation. */ +#define BTA_SDP_FAILURE 1 /* Generic failure. */ +#define BTA_SDP_BUSY 2 /* Temporarily can not handle this request. */ + +typedef UINT8 tBTA_SDP_STATUS; + +/* SDP I/F callback events */ +/* events received by tBTA_SDP_DM_CBACK */ +#define BTA_SDP_ENABLE_EVT 0 /* SDP service i/f enabled*/ +#define BTA_SDP_SEARCH_EVT 1 /* SDP Service started */ +#define BTA_SDP_SEARCH_COMP_EVT 2 /* SDP search complete */ +#define BTA_SDP_CREATE_RECORD_USER_EVT 3 /* SDP search complete */ +#define BTA_SDP_REMOVE_RECORD_USER_EVT 4 /* SDP search complete */ +#define BTA_SDP_MAX_EVT 5 /* max number of SDP events */ + +#define BTA_SDP_MAX_RECORDS 15 + +typedef UINT16 tBTA_SDP_EVT; + +/* data associated with BTA_SDP_DISCOVERY_COMP_EVT */ +typedef struct { + tBTA_SDP_STATUS status; + BD_ADDR remote_addr; + tBT_UUID uuid; + int record_count; + bluetooth_sdp_record records[BTA_SDP_MAX_RECORDS]; +} tBTA_SDP_SEARCH_COMP; + +typedef union { + tBTA_SDP_STATUS status; /* BTA_SDP_SEARCH_EVT */ + tBTA_SDP_SEARCH_COMP sdp_search_comp; /* BTA_SDP_SEARCH_COMP_EVT */ +} tBTA_SDP; + +/* SDP DM Interface callback */ +typedef void (tBTA_SDP_DM_CBACK)(tBTA_SDP_EVT event, tBTA_SDP *p_data, void *user_data); + +/* MCE configuration structure */ +typedef struct { + UINT16 sdp_db_size; /* The size of p_sdp_db */ + tSDP_DISCOVERY_DB *p_sdp_db; /* The data buffer to keep SDP database */ +} tBTA_SDP_CFG; + +#ifdef __cplusplus +extern "C" +{ +#endif +/******************************************************************************* +** +** Function BTA_SdpEnable +** +** Description Enable the SDP I/F service. When the enable +** operation is complete the callback function will be +** called with a BTA_SDP_ENABLE_EVT. This function must +** be called before other functions in the MCE API are +** called. +** +** Returns BTA_SDP_SUCCESS if successful. +** BTA_SDP_FAIL if internal failure. +** +*******************************************************************************/ +extern tBTA_SDP_STATUS BTA_SdpEnable(tBTA_SDP_DM_CBACK *p_cback); + +/******************************************************************************* +** +** Function BTA_SdpSearch +** +** Description Start a search for sdp records for a specific BD_ADDR with a +** specific profile uuid. +** When the search operation is completed, the callback function +** will be called with a BTA_SDP_SEARCH_EVT. +** Returns BTA_SDP_SUCCESS if successful. +** BTA_SDP_FAIL if internal failure. +** +*******************************************************************************/ +extern tBTA_SDP_STATUS BTA_SdpSearch(BD_ADDR bd_addr, tSDP_UUID *uuid); + +/******************************************************************************* +** +** Function BTA_SdpCreateRecordByUser +** +** Description This function is used to request a callback to create a SDP +** record. The registered callback will be called with event +** BTA_SDP_CREATE_RECORD_USER_EVT. +** +** Returns BTA_SDP_SUCCESS, if the request is being processed. +** BTA_SDP_FAILURE, otherwise. +** +*******************************************************************************/ +extern tBTA_SDP_STATUS BTA_SdpCreateRecordByUser(void *user_data); + +/******************************************************************************* +** +** Function BTA_SdpRemoveRecordByUser +** +** Description This function is used to request a callback to remove a SDP +** record. The registered callback will be called with event +** BTA_SDP_REMOVE_RECORD_USER_EVT. +** +** Returns BTA_SDP_SUCCESS, if the request is being processed. +** BTA_SDP_FAILURE, otherwise. +** +*******************************************************************************/ +extern tBTA_SDP_STATUS BTA_SdpRemoveRecordByUser(void *user_data); + +#ifdef __cplusplus +} +#endif + +#endif /* BTA_SDP_API_H */ diff --git a/tools/sdk/include/bluedroid/bta_sys.h b/tools/sdk/include/bluedroid/bta_sys.h new file mode 100644 index 00000000..808edbb4 --- /dev/null +++ b/tools/sdk/include/bluedroid/bta_sys.h @@ -0,0 +1,282 @@ +/****************************************************************************** + * + * 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 is the public interface file for the BTA system manager. + * + ******************************************************************************/ +#ifndef BTA_SYS_H +#define BTA_SYS_H + +#include "bt_target.h" +#include "gki.h" + +/***************************************************************************** +** Constants and data types +*****************************************************************************/ + +/* vendor specific event handler function type */ +typedef BOOLEAN (tBTA_SYS_VS_EVT_HDLR)(UINT16 evt, void *p); + +/* event handler function type */ +typedef BOOLEAN (tBTA_SYS_EVT_HDLR)(BT_HDR *p_msg); + +/* disable function type */ +typedef void (tBTA_SYS_DISABLE)(void); + + +/* HW modules */ +enum { + BTA_SYS_HW_BLUETOOTH, + BTA_SYS_HW_RT, + + BTA_SYS_MAX_HW_MODULES +}; + +typedef UINT16 tBTA_SYS_HW_MODULE; + +#ifndef BTA_DM_NUM_JV_ID +#define BTA_DM_NUM_JV_ID 2 +#endif + +/* SW sub-systems */ +#define BTA_ID_SYS 0 /* system manager */ +/* BLUETOOTH PART - from 0 to BTA_ID_BLUETOOTH_MAX */ +#define BTA_ID_DM 1 /* device manager */ +#define BTA_ID_DM_SEARCH 2 /* device manager search */ +#define BTA_ID_DM_SEC 3 /* device manager security */ +#define BTA_ID_DG 4 /* data gateway */ +#define BTA_ID_AG 5 /* audio gateway */ +#define BTA_ID_OPC 6 /* object push client */ +#define BTA_ID_OPS 7 /* object push server */ +#define BTA_ID_FTS 8 /* file transfer server */ +#define BTA_ID_CT 9 /* cordless telephony terminal */ +#define BTA_ID_FTC 10 /* file transfer client */ +#define BTA_ID_SS 11 /* synchronization server */ +#define BTA_ID_PR 12 /* Printer client */ +#define BTA_ID_BIC 13 /* Basic Imaging Client */ +#define BTA_ID_PAN 14 /* Personal Area Networking */ +#define BTA_ID_BIS 15 /* Basic Imaging Server */ +#define BTA_ID_ACC 16 /* Advanced Camera Client */ +#define BTA_ID_SC 17 /* SIM Card Access server */ +#define BTA_ID_AV 18 /* Advanced audio/video */ +#define BTA_ID_AVK 19 /* Audio/video sink */ +#define BTA_ID_HD 20 /* HID Device */ +#define BTA_ID_CG 21 /* Cordless Gateway */ +#define BTA_ID_BP 22 /* Basic Printing Client */ +#define BTA_ID_HH 23 /* Human Interface Device Host */ +#define BTA_ID_PBS 24 /* Phone Book Access Server */ +#define BTA_ID_PBC 25 /* Phone Book Access Client */ +#define BTA_ID_JV 26 /* Java */ +#define BTA_ID_HS 27 /* Headset */ +#define BTA_ID_MSE 28 /* Message Server Equipment */ +#define BTA_ID_MCE 29 /* Message Client Equipment */ +#define BTA_ID_HL 30 /* Health Device Profile*/ +#define BTA_ID_GATTC 31 /* GATT Client */ +#define BTA_ID_GATTS 32 /* GATT Client */ +#define BTA_ID_SDP 33 /* SDP Client */ +#define BTA_ID_BLUETOOTH_MAX 34 /* last BT profile */ + +/* GENERIC */ +#define BTA_ID_PRM 38 +#define BTA_ID_SYSTEM 39 /* platform-specific */ +#define BTA_ID_SWRAP 40 /* Insight script wrapper */ +#define BTA_ID_MIP 41 /* Multicase Individual Polling */ +#define BTA_ID_RT 42 /* Audio Routing module: This module is always on. */ + + +/* JV */ +#define BTA_ID_JV1 44 /* JV1 */ +#define BTA_ID_JV2 45 /* JV2 */ + +#define BTA_ID_MAX (44 + BTA_DM_NUM_JV_ID) + +typedef UINT8 tBTA_SYS_ID; + + +#define BTA_SYS_CONN_OPEN 0x00 +#define BTA_SYS_CONN_CLOSE 0x01 +#define BTA_SYS_APP_OPEN 0x02 +#define BTA_SYS_APP_CLOSE 0x03 +#define BTA_SYS_SCO_OPEN 0x04 +#define BTA_SYS_SCO_CLOSE 0x05 +#define BTA_SYS_CONN_IDLE 0x06 +#define BTA_SYS_CONN_BUSY 0x07 + +/* for link policy */ +#define BTA_SYS_PLCY_SET 0x10 /* set the link policy to the given addr */ +#define BTA_SYS_PLCY_CLR 0x11 /* clear the link policy to the given addr */ +#define BTA_SYS_PLCY_DEF_SET 0x12 /* set the default link policy */ +#define BTA_SYS_PLCY_DEF_CLR 0x13 /* clear the default link policy */ +#define BTA_SYS_ROLE_CHANGE 0x14 /* role change */ + +typedef UINT8 tBTA_SYS_CONN_STATUS; + +/* Bitmask of sys features */ +#define BTA_SYS_FEAT_PCM2 0x0001 +#define BTA_SYS_FEAT_PCM2_MASTER 0x0002 + +/* tBTA_PREF_ROLES */ +typedef UINT8 tBTA_SYS_PREF_ROLES; + +/* conn callback for role / low power manager*/ +typedef void (tBTA_SYS_CONN_CBACK)(tBTA_SYS_CONN_STATUS status, UINT8 id, UINT8 app_id, BD_ADDR peer_addr); + +/* conn callback for role / low power manager*/ +typedef void (tBTA_SYS_SSR_CFG_CBACK)(UINT8 id, UINT8 app_id, UINT16 latency, UINT16 tout); + +#if (BTA_EIR_CANNED_UUID_LIST != TRUE) +/* eir callback for adding/removeing UUID */ +typedef void (tBTA_SYS_EIR_CBACK)(UINT16 uuid16, BOOLEAN adding); +#endif + +/* registration structure */ +typedef struct { + tBTA_SYS_EVT_HDLR *evt_hdlr; + tBTA_SYS_DISABLE *disable; +} tBTA_SYS_REG; + +/* data type to send events to BTA SYS HW manager */ +typedef struct { + BT_HDR hdr; + tBTA_SYS_HW_MODULE hw_module; +} tBTA_SYS_HW_MSG; + +/***************************************************************************** +** Global data +*****************************************************************************/ + +/* trace level */ +extern UINT8 appl_trace_level; + +/***************************************************************************** +** Macros +*****************************************************************************/ + +/* Calculate start of event enumeration; id is top 8 bits of event */ +#define BTA_SYS_EVT_START(id) ((id) << 8) + +/***************************************************************************** +** events for BTA SYS HW manager +*****************************************************************************/ + +/* events sent to SYS HW manager - must be kept synchronized with tables in bta_sys_main.c */ +enum { + /* device manager local device API events */ + BTA_SYS_API_ENABLE_EVT = BTA_SYS_EVT_START(BTA_ID_SYS), + BTA_SYS_EVT_ENABLED_EVT, + BTA_SYS_EVT_STACK_ENABLED_EVT, + BTA_SYS_API_DISABLE_EVT, + BTA_SYS_EVT_DISABLED_EVT, + BTA_SYS_ERROR_EVT, + + BTA_SYS_MAX_EVT +}; + + + +/* SYS HW status events - returned by SYS HW manager to other modules. */ +enum { + BTA_SYS_HW_OFF_EVT, + BTA_SYS_HW_ON_EVT, + BTA_SYS_HW_STARTING_EVT, + BTA_SYS_HW_STOPPING_EVT, + BTA_SYS_HW_ERROR_EVT + +}; +typedef UINT8 tBTA_SYS_HW_EVT; + +/* HW enable callback type */ +typedef void (tBTA_SYS_HW_CBACK)(tBTA_SYS_HW_EVT status); + +/***************************************************************************** +** Function declarations +*****************************************************************************/ + +#ifdef __cplusplus +extern "C" { +#endif + +extern void bta_sys_init(void); +extern void bta_sys_free(void); +extern void bta_sys_event(BT_HDR *p_msg); +extern void bta_sys_set_trace_level(UINT8 level); +extern void bta_sys_register(UINT8 id, const tBTA_SYS_REG *p_reg); +extern void bta_sys_deregister(UINT8 id); +extern BOOLEAN bta_sys_is_register(UINT8 id); +extern UINT16 bta_sys_get_sys_features(void); +extern void bta_sys_sendmsg(void *p_msg); +extern void bta_sys_start_timer(TIMER_LIST_ENT *p_tle, UINT16 type, INT32 timeout_ms); +extern void bta_sys_stop_timer(TIMER_LIST_ENT *p_tle); +extern void bta_sys_disable(tBTA_SYS_HW_MODULE module); +extern UINT32 bta_sys_get_remaining_ticks(TIMER_LIST_ENT *p_target_tle); + +extern void bta_sys_hw_register( tBTA_SYS_HW_MODULE module, tBTA_SYS_HW_CBACK *cback); +extern void bta_sys_hw_unregister( tBTA_SYS_HW_MODULE module ); + + +extern void bta_sys_rm_register(tBTA_SYS_CONN_CBACK *p_cback); +extern void bta_sys_pm_register(tBTA_SYS_CONN_CBACK *p_cback); + +extern void bta_sys_policy_register(tBTA_SYS_CONN_CBACK *p_cback); +extern void bta_sys_sco_register(tBTA_SYS_CONN_CBACK *p_cback); + + +extern void bta_sys_conn_open(UINT8 id, UINT8 app_id, BD_ADDR peer_addr); +extern void bta_sys_conn_close(UINT8 id, UINT8 app_id, BD_ADDR peer_addr); +extern void bta_sys_app_open(UINT8 id, UINT8 app_id, BD_ADDR peer_addr); +extern void bta_sys_app_close(UINT8 id, UINT8 app_id, BD_ADDR peer_addr); +extern void bta_sys_sco_open(UINT8 id, UINT8 app_id, BD_ADDR peer_addr); +extern void bta_sys_sco_close(UINT8 id, UINT8 app_id, BD_ADDR peer_addr); +extern void bta_sys_sco_use(UINT8 id, UINT8 app_id, BD_ADDR peer_addr); +extern void bta_sys_sco_unuse(UINT8 id, UINT8 app_id, BD_ADDR peer_addr); +extern void bta_sys_idle(UINT8 id, UINT8 app_id, BD_ADDR peer_addr); +extern void bta_sys_busy(UINT8 id, UINT8 app_id, BD_ADDR peer_addr); + +#if (BTM_SSR_INCLUDED == TRUE) +extern void bta_sys_ssr_cfg_register(tBTA_SYS_SSR_CFG_CBACK *p_cback); +extern void bta_sys_chg_ssr_config (UINT8 id, UINT8 app_id, UINT16 max_latency, UINT16 min_tout); +#endif + +extern void bta_sys_role_chg_register(tBTA_SYS_CONN_CBACK *p_cback); +extern void bta_sys_notify_role_chg(BD_ADDR_PTR p_bda, UINT8 new_role, UINT8 hci_status); +extern void bta_sys_collision_register(UINT8 bta_id, tBTA_SYS_CONN_CBACK *p_cback); +extern void bta_sys_notify_collision (BD_ADDR_PTR p_bda); + +#if (BTA_EIR_CANNED_UUID_LIST != TRUE) +extern void bta_sys_eir_register(tBTA_SYS_EIR_CBACK *p_cback); +extern void bta_sys_add_uuid(UINT16 uuid16); +extern void bta_sys_remove_uuid(UINT16 uuid16); +#else +#define bta_sys_eir_register(ut) +#define bta_sys_add_uuid(ut) +#define bta_sys_remove_uuid(ut) +#endif + +extern void bta_sys_set_policy (UINT8 id, UINT8 policy, BD_ADDR peer_addr); +extern void bta_sys_clear_policy (UINT8 id, UINT8 policy, BD_ADDR peer_addr); +extern void bta_sys_set_default_policy (UINT8 id, UINT8 policy); +extern void bta_sys_clear_default_policy (UINT8 id, UINT8 policy); +extern BOOLEAN bta_sys_vs_hdl(UINT16 evt, void *p); + +#ifdef __cplusplus +} +#endif + +#endif /* BTA_SYS_H */ diff --git a/tools/sdk/include/bluedroid/bta_sys_int.h b/tools/sdk/include/bluedroid/bta_sys_int.h new file mode 100644 index 00000000..aa2596d9 --- /dev/null +++ b/tools/sdk/include/bluedroid/bta_sys_int.h @@ -0,0 +1,101 @@ +/****************************************************************************** + * + * 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 is the private interface file for the BTA system manager. + * + ******************************************************************************/ +#ifndef BTA_SYS_INT_H +#define BTA_SYS_INT_H + +/***************************************************************************** +** Constants and data types +*****************************************************************************/ + +/***************************************************************************** +** state table +*****************************************************************************/ + +/* SYS HW state */ +enum { + BTA_SYS_HW_OFF, + BTA_SYS_HW_STARTING, + BTA_SYS_HW_ON, + BTA_SYS_HW_STOPPING +}; +typedef UINT8 tBTA_SYS_HW_STATE; + +/* Collision callback */ +#define MAX_COLLISION_REG 5 + +typedef struct { + UINT8 id[MAX_COLLISION_REG]; + tBTA_SYS_CONN_CBACK *p_coll_cback[MAX_COLLISION_REG]; +} tBTA_SYS_COLLISION; + +/* system manager control block */ +typedef struct { + tBTA_SYS_REG *reg[BTA_ID_MAX]; /* registration structures */ + BOOLEAN is_reg[BTA_ID_MAX]; /* registration structures */ + tBTA_SYS_HW_STATE state; + tBTA_SYS_HW_CBACK *sys_hw_cback[BTA_SYS_MAX_HW_MODULES]; /* enable callback for each HW modules */ + UINT32 sys_hw_module_active; /* bitmask of all active modules */ + UINT16 sys_features; /* Bitmask of sys features */ + + tBTA_SYS_CONN_CBACK *prm_cb; /* role management callback registered by DM */ + tBTA_SYS_CONN_CBACK *ppm_cb; /* low power management callback registered by DM */ + tBTA_SYS_CONN_CBACK *p_policy_cb; /* link policy change callback registered by DM */ + tBTA_SYS_CONN_CBACK *p_sco_cb; /* SCO connection change callback registered by AV */ + tBTA_SYS_CONN_CBACK *p_role_cb; /* role change callback registered by AV */ + tBTA_SYS_COLLISION colli_reg; /* collision handling module */ +#if (BTA_EIR_CANNED_UUID_LIST != TRUE) + tBTA_SYS_EIR_CBACK *eir_cb; /* add/remove UUID into EIR */ +#endif +#if (BTM_SSR_INCLUDED == TRUE) + tBTA_SYS_SSR_CFG_CBACK *p_ssr_cb; +#endif + /* VS event handler */ + tBTA_SYS_VS_EVT_HDLR *p_vs_evt_hdlr; + +} tBTA_SYS_CB; + +/***************************************************************************** +** Global variables +*****************************************************************************/ + +/* system manager control block */ +#if BTA_DYNAMIC_MEMORY == FALSE +extern tBTA_SYS_CB bta_sys_cb; +#else +extern tBTA_SYS_CB *bta_sys_cb_ptr; +#define bta_sys_cb (*bta_sys_cb_ptr) +#endif + +/* functions used for BTA SYS HW state machine */ +void bta_sys_hw_btm_cback( tBTM_DEV_STATUS status ); +void bta_sys_hw_error(tBTA_SYS_HW_MSG *p_sys_hw_msg); +void bta_sys_hw_api_enable( tBTA_SYS_HW_MSG *p_sys_hw_msg ); +void bta_sys_hw_api_disable(tBTA_SYS_HW_MSG *p_sys_hw_msg); +void bta_sys_hw_evt_enabled(tBTA_SYS_HW_MSG *p_sys_hw_msg); +void bta_sys_hw_evt_disabled(tBTA_SYS_HW_MSG *p_sys_hw_msg); +void bta_sys_hw_evt_stack_enabled(tBTA_SYS_HW_MSG *p_sys_hw_msg); + +BOOLEAN bta_sys_sm_execute(BT_HDR *p_msg); + +#endif /* BTA_SYS_INT_H */ diff --git a/tools/sdk/include/bluedroid/btc_blufi_prf.h b/tools/sdk/include/bluedroid/btc_blufi_prf.h new file mode 100644 index 00000000..1d82d0c9 --- /dev/null +++ b/tools/sdk/include/bluedroid/btc_blufi_prf.h @@ -0,0 +1,47 @@ +// 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__ */ diff --git a/tools/sdk/include/bluedroid/btc_gap_ble.h b/tools/sdk/include/bluedroid/btc_gap_ble.h new file mode 100644 index 00000000..ea639bcd --- /dev/null +++ b/tools/sdk/include/bluedroid/btc_gap_ble.h @@ -0,0 +1,98 @@ +// 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_BLE_H__ +#define __BTC_GAP_BLE_H__ + +#include "esp_bt_defs.h" +#include "esp_gap_ble_api.h" + +#define BLE_ISVALID_PARAM(x, min, max) (((x) >= (min) && (x) <= (max)) || ((x) == ESP_BLE_CONN_PARAM_UNDEF)) + +typedef enum { + BTC_GAP_BLE_ACT_CFG_ADV_DATA = 0, + BTC_GAP_BLE_ACT_SET_SCAN_PARAM, + BTC_GAP_BLE_ACT_START_SCAN, + BTC_GAP_BLE_ACT_STOP_SCAN, + BTC_GAP_BLE_ACT_START_ADV, + BTC_GAP_BLE_ACT_STOP_ADV, + BTC_GAP_BLE_ACT_UPDATE_CONN_PARAM, + BTC_GAP_BLE_ACT_SET_PKT_DATA_LEN, + BTC_GAP_BLE_ACT_SET_RAND_ADDRESS, + BTC_GAP_BLE_ACT_CONFIG_LOCAL_PRIVACY, + BTC_GAP_BLE_ACT_SET_DEV_NAME, + BTC_GAP_BLE_ACT_CFG_ADV_DATA_RAW, + BTC_GAP_BLE_ACT_CFG_SCAN_RSP_DATA_RAW, +} btc_gap_ble_act_t; + +/* btc_ble_gap_args_t */ +typedef union { + //BTC_GAP_BLE_ACT_CFG_ADV_DATA = 0, + struct config_adv_data_args { + esp_ble_adv_data_t adv_data; + } cfg_adv_data; + //BTC_GAP_BLE_ACT_SET_SCAN_PARAM, + struct set_scan_params_args { + esp_ble_scan_params_t scan_params; + } set_scan_param; + //BTC_GAP_BLE_ACT_START_SCAN, + struct start_scan_args { + uint32_t duration; + } start_scan; + //BTC_GAP_BLE_ACT_STOP_SCAN, no args + //BTC_GAP_BLE_ACT_START_ADV, + struct start_adv_args { + esp_ble_adv_params_t adv_params; + } start_adv; + //BTC_GAP_BLE_ACT_STOP_ADV, no args + //BTC_GAP_BLE_ACT_UPDATE_CONN_PARAM, + struct conn_update_params_args { + esp_ble_conn_update_params_t conn_params; + } conn_update_params; + //BTC_GAP_BLE_ACT_SET_PKT_DATA_LEN + struct set_pkt_data_len_args { + esp_bd_addr_t remote_device; + uint16_t tx_data_length; + } set_pkt_data_len; + //BTC_GAP_BLE_ACT_SET_RAND_ADDRESS, + struct set_rand_addr_args { + esp_bd_addr_t rand_addr; + } set_rand_addr; + //BTC_GAP_BLE_ACT_CONFIG_LOCAL_PRIVACY, + struct cfg_local_privacy_args { + bool privacy_enable; + } cfg_local_privacy; + //BTC_GAP_BLE_ACT_SET_DEV_NAME, + struct set_dev_name_args { +#define ESP_GAP_DEVICE_NAME_MAX (32) + char device_name[ESP_GAP_DEVICE_NAME_MAX + 1]; + } set_dev_name; + //BTC_GAP_BLE_ACT_CFG_ADV_DATA_RAW, + struct config_adv_data_raw_args { + uint8_t *raw_adv; + uint32_t raw_adv_len; + } cfg_adv_data_raw; + //BTC_GAP_BLE_ACT_CFG_SCAN_RSP_DATA_RAW, + struct config_scan_rsp_data_raw_args { + uint8_t *raw_scan_rsp; + uint32_t raw_scan_rsp_len; + } cfg_scan_rsp_data_raw; +} btc_ble_gap_args_t; + +void btc_gap_ble_call_handler(btc_msg_t *msg); +void btc_gap_ble_cb_handler(btc_msg_t *msg); + +void btc_gap_ble_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src); + +#endif /* __BTC_GAP_BLE_H__ */ diff --git a/tools/sdk/include/bluedroid/btc_gap_bt.h b/tools/sdk/include/bluedroid/btc_gap_bt.h new file mode 100644 index 00000000..d6f2e5b5 --- /dev/null +++ b/tools/sdk/include/bluedroid/btc_gap_bt.h @@ -0,0 +1,22 @@ +// 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__ */ diff --git a/tools/sdk/include/bluedroid/btc_gatt_util.h b/tools/sdk/include/bluedroid/btc_gatt_util.h new file mode 100644 index 00000000..99083f74 --- /dev/null +++ b/tools/sdk/include/bluedroid/btc_gatt_util.h @@ -0,0 +1,40 @@ +// 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_GATT_UTIL_H__ +#define __BTC_GATT_UTIL_H__ + +#include "bt_types.h" +#include "bta_gatt_api.h" +#include "esp_bt_defs.h" +#include "esp_gatt_defs.h" +#include "esp_gattc_api.h" + +#define BTC_GATT_CREATE_CONN_ID(gatt_if, conn_id) ((uint16_t) ((((uint8_t)(conn_id)) << 8) | ((uint8_t)(gatt_if)))) +#define BTC_GATT_GET_CONN_ID(conn_id) (((uint16_t)(conn_id)) >> 8) +#define BTC_GATT_GET_GATT_IF(conn_id) ((uint8_t)(conn_id)) + +void btc128_to_bta_uuid(tBT_UUID *p_dest, uint8_t *p_src); +void btc_to_bta_uuid(tBT_UUID *p_dest, esp_bt_uuid_t *p_src); +void btc_to_bta_gatt_id(tBTA_GATT_ID *p_dest, esp_gatt_id_t *p_src); +void btc_to_bta_srvc_id(tBTA_GATT_SRVC_ID *p_dest, esp_gatt_srvc_id_t *p_src); +void btc_to_bta_response(tBTA_GATTS_RSP *rsp_struct, esp_gatt_rsp_t *p_rsp); + +void bta_to_btc_uuid(esp_bt_uuid_t *p_dest, tBT_UUID *p_src); +void bta_to_btc_gatt_id(esp_gatt_id_t *p_dest, tBTA_GATT_ID *p_src); +void bta_to_btc_srvc_id(esp_gatt_srvc_id_t *p_dest, tBTA_GATT_SRVC_ID *p_src); + +uint16_t set_read_value(uint8_t *gattc_if, esp_ble_gattc_cb_param_t *p_dest, tBTA_GATTC_READ *p_src); + +#endif /* __BTC_GATT_UTIL_H__*/ diff --git a/tools/sdk/include/bluedroid/btc_gattc.h b/tools/sdk/include/bluedroid/btc_gattc.h new file mode 100644 index 00000000..aef84189 --- /dev/null +++ b/tools/sdk/include/bluedroid/btc_gattc.h @@ -0,0 +1,183 @@ +// 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_GATTC_H__ +#define __BTC_GATTC_H__ + +#include "btc_task.h" +#include "esp_bt_defs.h" +#include "esp_gatt_defs.h" +#include "esp_gattc_api.h" + +typedef enum { + BTC_GATTC_ACT_APP_REGISTER = 0, + BTC_GATTC_ACT_APP_UNREGISTER, + BTC_GATTC_ACT_OPEN, + BTC_GATTC_ACT_CLOSE, + BTC_GATTC_ACT_CFG_MTU, + BTC_GATTC_ACT_SEARCH_SERVICE, + BTC_GATTC_ACT_GET_FIRST_CHAR, + BTC_GATTC_ACT_GET_NEXT_CHAR, + BTC_GATTC_ACT_GET_FIRST_DESCR, + BTC_GATTC_ACT_GET_NEXT_DESCR, + BTC_GATTC_ACT_GET_FIRST_INCL_SERVICE, + BTC_GATTC_ACT_GET_NEXT_INCL_SERVICE, + BTC_GATTC_ACT_READ_CHAR, + BTC_GATTC_ACT_READ_CHAR_DESCR, + BTC_GATTC_ACT_WRITE_CHAR, + BTC_GATTC_ACT_WRITE_CHAR_DESCR, + BTC_GATTC_ACT_PREPARE_WRITE, + BTC_GATTC_ACT_EXECUTE_WRITE, + BTC_GATTC_ACT_REG_FOR_NOTIFY, + BTC_GATTC_ACT_UNREG_FOR_NOTIFY +} btc_gattc_act_t; + +/* btc_ble_gattc_args_t */ +typedef union { + //BTC_GATTC_ACT_APP_REGISTER, + struct app_reg_arg { + uint16_t app_id; + } app_reg; + //BTC_GATTC_ACT_APP_UNREGISTER, + struct app_unreg_arg { + esp_gatt_if_t gattc_if; + } app_unreg; + //BTC_GATTC_ACT_OPEN, + struct open_arg { + esp_gatt_if_t gattc_if; + esp_bd_addr_t remote_bda; + bool is_direct; + } open; + //BTC_GATTC_ACT_CLOSE, + struct close_arg { + uint16_t conn_id; + } close; + //BTC_GATTC_ACT_CFG_MTU, + struct cfg_mtu_arg { + uint16_t conn_id; + uint16_t mtu; + } cfg_mtu; + //BTC_GATTC_ACT_SEARCH_SERVICE, + struct search_srvc_arg { + uint16_t conn_id; + bool filter_uuid_enable; + esp_bt_uuid_t filter_uuid; + } search_srvc; + //BTC_GATTC_ACT_GET_FIRST_CHAR, + struct get_first_char_arg { + uint16_t conn_id; + esp_gatt_srvc_id_t service_id; + } get_first_char; + //BTC_GATTC_ACT_GET_NEXT_CHAR, + struct get_next_char_arg { + uint16_t conn_id; + esp_gatt_srvc_id_t service_id; + esp_gatt_id_t char_id; + } get_next_char; + //BTC_GATTC_ACT_GET_FIRST_DESCR, + struct get_first_descr_arg { + uint16_t conn_id; + esp_gatt_srvc_id_t service_id; + esp_gatt_id_t char_id; + } get_first_descr; + //BTC_GATTC_ACT_GET_NEXT_DESCR, + struct get_next_descr_arg { + uint16_t conn_id; + esp_gatt_srvc_id_t service_id; + esp_gatt_id_t char_id; + esp_gatt_id_t descr_id; + } get_next_descr; + //BTC_GATTC_ACT_GET_FIRST_INCL_SERVICE, + struct get_first_incl_srvc_arg { + uint16_t conn_id; + esp_gatt_srvc_id_t service_id; + } get_first_incl_srvc; + //BTC_GATTC_ACT_GET_NEXT_INCL_SERVICE, + struct get_next_incl_srvc_arg { + uint16_t conn_id; + esp_gatt_srvc_id_t service_id; + esp_gatt_srvc_id_t start_service_id; + } get_next_incl_srvc; + //BTC_GATTC_ACT_READ_CHAR, + struct read_char_arg { + uint16_t conn_id; + esp_gatt_srvc_id_t service_id; + esp_gatt_id_t char_id; + esp_gatt_auth_req_t auth_req; + } read_char; + //BTC_GATTC_ACT_READ_CHAR_DESCR, + struct read_descr_arg { + uint16_t conn_id; + esp_gatt_srvc_id_t service_id; + esp_gatt_id_t char_id; + esp_gatt_id_t descr_id; + esp_gatt_auth_req_t auth_req; + } read_descr; + //BTC_GATTC_ACT_WRITE_CHAR, + struct write_char_arg { + uint16_t conn_id; + uint16_t value_len; + esp_gatt_srvc_id_t service_id; + esp_gatt_id_t char_id; + uint8_t *value; + esp_gatt_write_type_t write_type; + esp_gatt_auth_req_t auth_req; + } write_char; + //BTC_GATTC_ACT_WRITE_CHAR_DESCR, + struct write_descr_arg { + uint16_t conn_id; + uint16_t value_len; + esp_gatt_srvc_id_t service_id; + esp_gatt_id_t char_id; + esp_gatt_id_t descr_id; + uint8_t *value; + esp_gatt_write_type_t write_type; + esp_gatt_auth_req_t auth_req; + } write_descr; + //BTC_GATTC_ACT_PREPARE_WRITE, + struct prep_write_arg { + uint16_t conn_id; + esp_gatt_srvc_id_t service_id; + esp_gatt_id_t char_id; + uint16_t offset; + uint16_t value_len; + uint8_t *value; + esp_gatt_auth_req_t auth_req; + } prep_write; + //BTC_GATTC_ACT_EXECUTE_WRITE, + struct exec_write_arg { + uint16_t conn_id; + bool is_execute; + } exec_write; + //BTC_GATTC_ACT_REG_FOR_NOTIFY, + struct reg_for_notify_arg { + esp_gatt_if_t gattc_if; + esp_bd_addr_t remote_bda; + esp_gatt_srvc_id_t service_id; + esp_gatt_id_t char_id; + } reg_for_notify; + //BTC_GATTC_ACT_UNREG_FOR_NOTIFY + struct unreg_for_notify_arg { + esp_gatt_if_t gattc_if; + esp_bd_addr_t remote_bda; + esp_gatt_srvc_id_t service_id; + esp_gatt_id_t char_id; + } unreg_for_notify; +} btc_ble_gattc_args_t; + +void btc_gattc_call_handler(btc_msg_t *msg); +void btc_gattc_cb_handler(btc_msg_t *msg); +void btc_gattc_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src); + +#endif /* __BTC_GATTC_H__ */ diff --git a/tools/sdk/include/bluedroid/btc_gatts.h b/tools/sdk/include/bluedroid/btc_gatts.h new file mode 100644 index 00000000..caae44de --- /dev/null +++ b/tools/sdk/include/bluedroid/btc_gatts.h @@ -0,0 +1,152 @@ +// 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_GATTS_H__ +#define __BTC_GATTS_H__ + +#include "btc_task.h" +#include "esp_bt_defs.h" +#include "esp_gatt_defs.h" +#include "esp_gatts_api.h" + +typedef enum { + BTC_GATTS_ACT_APP_REGISTER = 0, + BTC_GATTS_ACT_APP_UNREGISTER, + BTC_GATTS_ACT_CREATE_SERVICE, + BTC_GATTS_ACT_CREATE_ATTR_TAB, + BTC_GATTS_ACT_DELETE_SERVICE, + BTC_GATTS_ACT_START_SERVICE, + BTC_GATTS_ACT_STOP_SERVICE, + BTC_GATTS_ACT_ADD_INCLUDE_SERVICE, + BTC_GATTS_ACT_ADD_CHAR, + BTC_GATTS_ACT_ADD_CHAR_DESCR, + BTC_GATTS_ACT_SEND_INDICATE, + BTC_GATTS_ACT_SEND_RESPONSE, + BTC_GATTS_ACT_SET_ATTR_VALUE, + BTC_GATTS_ACT_OPEN, + BTC_GATTS_ACT_CLOSE, +} btc_gatts_act_t; + +/* btc_ble_gatts_args_t */ +typedef union { + //BTC_GATTS_ACT_APP_REGISTER = 0, + struct app_reg_args { + uint16_t app_id; + } app_reg; + + //BTC_GATTS_ACT_APP_UNREGISTER, + struct app_unreg_args { + esp_gatt_if_t gatts_if; + } app_unreg; + + //BTC_GATTS_ACT_CREATE_SERVICE, + struct create_srvc_args { + esp_gatt_if_t gatts_if; + esp_gatt_srvc_id_t service_id; + uint16_t num_handle; + } create_srvc; + + //BTC_GATTS_ACT_CREATE_ATTR_TAB + struct create_attr_tab_args{ + esp_gatt_if_t gatts_if; + uint8_t srvc_inst_id; + uint8_t max_nb_attr; + esp_gatts_attr_db_t *gatts_attr_db; + }create_attr_tab; + + //BTC_GATTS_ACT_DELETE_SERVICE, + struct delete_srvc_args { + uint16_t service_handle; + } delete_srvc; + + //BTC_GATTS_ACT_START_SERVICE, + struct start_srvc_args { + uint16_t service_handle; + } start_srvc; + + //BTC_GATTS_ACT_STOP_SERVICE, + struct stop_srvc_args { + uint16_t service_handle; + } stop_srvc; + + //BTC_GATTS_ACT_ADD_INCLUDE_SERVICE, + struct add_incl_srvc_args { + uint16_t service_handle; + uint16_t included_service_handle; + } add_incl_srvc; + + //BTC_GATTS_ACT_ADD_CHAR, + struct add_char_args { + uint16_t service_handle; + esp_bt_uuid_t char_uuid; + esp_gatt_perm_t perm; + esp_gatt_char_prop_t property; + esp_attr_control_t attr_control; + esp_attr_value_t char_val; + } add_char; + + //BTC_GATTS_ACT_ADD_CHAR_DESCR, + struct add_descr_args { + uint16_t service_handle; + esp_bt_uuid_t descr_uuid; + esp_gatt_perm_t perm; + esp_attr_control_t attr_control; + esp_attr_value_t descr_val; + } add_descr; + + //BTC_GATTS_ACT_SEND_INDICATE, + struct send_indicate_args { + uint16_t conn_id; + uint16_t attr_handle; + bool need_confirm; + uint16_t value_len; + uint8_t *value; + } send_ind; + + //BTC_GATTS_ACT_SEND_RESPONSE, + struct send_rsp_args { + uint16_t conn_id; + uint32_t trans_id; + esp_gatt_status_t status; + esp_gatt_rsp_t *rsp; + } send_rsp; + + //BTC_GATTS_SET_ATTR_VALUE + struct set_attr_val_args{ + uint16_t length; + uint8_t *value; + } set_attr_val; + + //BTC_GATTS_ACT_OPEN, + struct open_args { + esp_gatt_if_t gatts_if; + esp_bd_addr_t remote_bda; + bool is_direct; + } open; + + //BTC_GATTS_ACT_CLOSE, + struct close_args { + uint16_t conn_id; + } close; + +} btc_ble_gatts_args_t; + + +void btc_gatts_call_handler(btc_msg_t *msg); +void btc_gatts_cb_handler(btc_msg_t *msg); +void btc_gatts_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src); +void btc_gatts_get_attr_value(uint16_t attr_handle, uint16_t *length, uint8_t **value); + + +#endif /* __BTC_GATTS_H__ */ diff --git a/tools/sdk/include/bluedroid/btc_main.h b/tools/sdk/include/bluedroid/btc_main.h new file mode 100644 index 00000000..b95ae0bb --- /dev/null +++ b/tools/sdk/include/bluedroid/btc_main.h @@ -0,0 +1,64 @@ +// 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_BT_MAIN_H__ +#define __BTC_BT_MAIN_H__ + +#include "future.h" +#include "bt_types.h" +#include "bta_api.h" +#include "btc_main.h" +#include "btc_task.h" + +typedef enum { + BTC_MAIN_ACT_INIT = 0, + BTC_MAIN_ACT_DEINIT, + BTC_MAIN_ACT_ENABLE, + BTC_MAIN_ACT_DISABLE, +} btc_main_act_t; + +typedef enum { + BTC_MAIN_INIT_FUTURE = 0, + BTC_MAIN_DEINIT_FUTURE, + BTC_MAIN_ENABLE_FUTURE, + BTC_MAIN_DISABLE_FUTURE, + BTC_MAIN_FUTURE_NUM, +} btc_main_future_type_t; + +future_t **btc_main_get_future_p(btc_main_future_type_t type); + +#if 0 +typedef union { + struct btc_main_init_args { + future_t *future; + } init; + struct btc_main_deinit_args { + future_t *future; + } deinit; + struct btc_main_init_args { + future_t *future; + } enable; + struct btc_main_init_args { + future_t *future; + } disable; +} btc_main_args_t; + +bt_status_t btc_enable_bluetooth(future_t *future); +void btc_disable_bluetooth(future_t *future); +bt_status_t btc_init_bluetooth(future_t *future); +void btc_deinit_bluetooth(future_t *future); +#endif + +void btc_main_call_handler(btc_msg_t *msg); +#endif /* __BTC_BT_MAIN_H__ */ diff --git a/tools/sdk/include/bluedroid/btc_manage.h b/tools/sdk/include/bluedroid/btc_manage.h new file mode 100644 index 00000000..8789f543 --- /dev/null +++ b/tools/sdk/include/bluedroid/btc_manage.h @@ -0,0 +1,28 @@ +// 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_MANAGE_H__ +#define __BTC_MANAGE_H__ + +#include "bta_api.h" +#include "btc_task.h" +#include "esp_bt_defs.h" + +/* reset gatt callback table */ +void esp_profile_cb_reset(void); + +int btc_profile_cb_set(btc_pid_t profile_id, void *cb); +void *btc_profile_cb_get(btc_pid_t profile_id); + +#endif /* __BTC_MANAGE_H__ */ diff --git a/tools/sdk/include/bluedroid/btc_sdp.h b/tools/sdk/include/bluedroid/btc_sdp.h new file mode 100644 index 00000000..db7984b9 --- /dev/null +++ b/tools/sdk/include/bluedroid/btc_sdp.h @@ -0,0 +1,129 @@ +// 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 __ESP_SDP_API_H__ +#define __ESP_SDP_API_H__ + +#include +#include "esp_err.h" +#include "esp_bt_common.h" +#include "bta_sdp_api.h" +#include "bt_sdp.h" + +#define BT_SDP_STAT_SUCCESS BTA_SDP_SUCCESS +#define BT_SDP_STAT_FAILURE BTA_SDP_FAILURE +#define BT_SDP_STAT_BUSY BTA_SDP_BUSY + +#define BT_SDP_ENABLE_EVT BTA_SDP_ENABLE_EVT +#define BT_SDP_SEARCH_EVT BTA_SDP_SEARCH_EVT +#define BT_SDP_SEARCH_COMP_EVT BTA_SDP_SEARCH_COMP_EVT +#define BT_SDP_CREATE_RECORD_USER_EVT BTA_SDP_CREATE_RECORD_USER_EVT +#define BT_SDP_REMOVE_RECORD_USER_EVT BTA_SDP_REMOVE_RECORD_USER_EVT +#define BT_SDP_MAX_EVT BTA_SDP_MAX_EVT + +#define BT_SDP_MAX_RECORDS BTA_SDP_MAX_RECORDS + +typedef tBTA_SDP_STATUS bt_sdp_status_t; + +typedef tBTA_SDP_EVT bt_sdp_evt_t; + +typedef bluetooth_sdp_record bt_sdp_record_t; + +/* tBTA_SEARCH_COMP, bta_sdp_api.h */ +typedef struct { + bt_sdp_status_t status; + esp_bd_addr_t remote_addr; + esp_bt_uuid_t uuid; + int record_count; + bt_sdp_record_t records[BT_SDP_MAX_RECORDS]; +} bt_sdp_search_comp_t; + +/* tBTA_SDP, bta_sdp_api.h */ +typedef union { + bt_sdp_status_t status; + bt_sdp_search_comp_t sdp_search_comp; +} bt_sdp_t; + +typedef void (bt_sdp_cb_t)(bt_sdp_evt_t event, bt_sdp_t *p_data, void *user_data); + +esp_err_t esp_bt_sdp_enable(bt_sdp_cb_t *cback); + +esp_err_t esp_bt_sdp_search(esp_bd_addr_t bd_addr, esp_bt_uuid_t *uuid); + +esp_err_t esp_bt_sdp_create_record_by_user(void *user_data); + +esp_err_t esp_bt_sdp_remove_record_by_user(void *user_data); + + +/**********************************************************************************************/ +/**********************************************************************************************/ +/* API into SDP for local service database updates + * these APIs are indended to be called in callback function in the context of stack task, + * to handle BT_SDP_CREATE_RECORD_USER_EVT and BT_SDP_REMOVE_RECORD_USER_EVT + */ + +/* This structure is used to add protocol lists and find protocol elements */ +#define ESP_BT_SDP_MAX_PROTOCOL_PARAMS SDP_MAX_PROTOCOL_PARAMS // bt_target.h +typedef struct { + uint16_t protocol_uuid; + uint16_t num_params; + uint16_t params[ESP_BT_SDP_MAX_PROTOCOL_PARAMS]; +} sdp_proto_elem_t; // tSDP_PROTOCOL_ELEM, sdp_api.h + +#define ESP_BT_SDP_MAX_LIST_ELEMS SDP_MAX_LIST_ELEMS // sdp_api.h +typedef struct { + uint16_t num_elems; + sdp_proto_elem_t list_elem[ESP_BT_SDP_MAX_LIST_ELEMS]; +} sdp_proto_list_elem_t; // tSDP_PROTO_LIST_ELEM, sdp_api.h + + +uint32_t esp_bt_sdp_create_record(void); + +bool esp_bt_sdp_delete_record(uint32_t handle); + +int32_t esp_bt_sdp_read_record(uint32_t handle, uint8_t *data, int32_t *data_len); + +bool esp_bt_sdp_add_attribute (uint32_t handle, uint16_t attr_id, + uint8_t attr_type, uint32_t attr_len, + uint8_t *p_val); + +bool esp_bt_sdp_add_sequence (uint32_t handle, uint16_t attr_id, + uint16_t num_elem, uint8_t type[], + uint8_t len[], uint8_t *p_val[]); + +bool esp_bt_sdp_add_uuid_sequence (uint32_t handle, uint16_t attr_id, + uint16_t num_uuids, uint16_t *p_uuids); + + +bool esp_bt_sdp_add_protocol_list (uint32_t handle, uint16_t num_elem, + sdp_proto_elem_t *p_elem_list); + +bool esp_bt_sdp_add_addition_protocol_lists(uint32_t handle, uint16_t num_elem, + sdp_proto_list_elem_t *p_proto_list); + +bool esp_bt_sdp_add_profile_dscp_list (uint32_t handle, + uint16_t profile_uuid, + uint16_t version); + +bool esp_bt_sdp_add_lang_base_attr_id_list(uint32_t handle, + uint16_t lang, uint16_t char_enc, + uint16_t base_id); + +bool esp_bt_sdp_add_service_class_id_list(uint32_t handle, + uint16_t num_services, + uint16_t *p_service_uuids); + +bool esp_bt_sdp_delete_attribute(uint32_t handle, uint16_t attr_id); + +#endif /* __ESP_SDP_API_H__ */ diff --git a/tools/sdk/include/bluedroid/btc_task.h b/tools/sdk/include/bluedroid/btc_task.h new file mode 100644 index 00000000..1574dae2 --- /dev/null +++ b/tools/sdk/include/bluedroid/btc_task.h @@ -0,0 +1,63 @@ +// 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_TASK_H__ +#define __BTC_TASK_H__ + +#include +#include "bt_defs.h" +#include "thread.h" + +typedef struct btc_msg { + uint8_t sig; //event signal + uint8_t aid; //application id + uint8_t pid; //profile id + uint8_t act; //profile action, defined in seprerate header files + void *arg; //param for btc function or function param +} btc_msg_t; + +typedef enum { + BTC_SIG_API_CALL = 0, // APP TO STACK + BTC_SIG_API_CB, // STACK TO APP + BTC_SIG_NUM, +} btc_sig_t; //btc message type + +typedef enum { + BTC_PID_MAIN_INIT = 0, + BTC_PID_GATTS, + BTC_PID_GATTC, + BTC_PID_GAP_BLE, + BTC_PID_GAP_BT, + BTC_PID_SDP, + BTC_PID_BLE_HID, + BTC_PID_BT_HID, + BTC_PID_SPP, + BTC_PID_SPPLIKE, + BTC_PID_BLUFI, + BTC_PID_NUM, +} btc_pid_t; //btc profile id + +typedef struct { + void (* btc_call)(btc_msg_t *msg); + void (* btc_cb)(btc_msg_t *msg); +} btc_func_t; + +typedef void (* btc_arg_deep_copy_t)(btc_msg_t *msg, void *dst, void *src); + +bt_status_t btc_transfer_context(btc_msg_t *msg, void *arg, int arg_len, btc_arg_deep_copy_t copy_func); + +int btc_init(void); +void btc_deinit(void); + +#endif /* __BTC_TASK_H__ */ diff --git a/tools/sdk/include/bluedroid/bte.h b/tools/sdk/include/bluedroid/bte.h new file mode 100644 index 00000000..6a3ffe80 --- /dev/null +++ b/tools/sdk/include/bluedroid/bte.h @@ -0,0 +1,117 @@ +/****************************************************************************** + * + * Copyright (C) 2001-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 file contains constants and definitions for the bte project + * + ******************************************************************************/ +#ifndef BTE_H +#define BTE_H + +//#include +//#include +//#include +#include "bt_target.h" + +/* by default on shutdown, baudrate is reset 115kbits. this should NOT be need for platforms + * that kill BTE driver and remove/reset BT chip + */ +#ifndef BTE_RESET_BAUD_ON_BT_DISABLE +#define BTE_RESET_BAUD_ON_BT_DISABLE TRUE +#endif + +/* Target Modes (based on jumper settings on hardware [see user manual]) */ +enum { + /* BTE BBY */ + /* J3 J4 SW3-3 SW3-2 SW3-1 */ + /* -------------------------------------------- */ + BTE_MODE_SERIAL_APP, /* OUT OUT OFF OFF OFF Sample serial port application */ + BTE_MODE_APPL, /* IN OUT OFF OFF ON Target used with Tester through RPC */ + BTE_MODE_RESERVED, /* OUT IN OFF ON OFF Reserved */ + BTE_MODE_SAMPLE_APPS, /* IN IN OFF ON ON Sample applications (ICP/HSP) */ + BTE_MODE_DONGLE, /* not yet supported ON OFF OFF Dongle mode */ + BTE_MODE_APPL_PROTOCOL_TRACE, /* this is a fake mode do allow protocol tracing in application without rpc */ + BTE_MODE_INVALID +}; + +extern volatile UINT8 bte_target_mode; /* indicates the mode that the board is running in */ + +/* Startup options */ +extern UINT32 bte_startup_options; /* Switch and jumper settings at startup */ +void bte_get_startup_options(UINT32 *p_options); /* Platform specific function for getting startup options */ + +#define BTE_OPTIONS_TARGET_MODE_MASK 0x00000007 /* bits 2-0 indicate target mode (QuickConnect: jp3 & jp4, BBY: SW3-1 & SW3-2)*/ + + +/**************************************************************************** + * Definitions to define which type of application gets built + ****************************************************************************/ +#define BUILD_HCITOOL FALSE +#define BUILD_L2PING FALSE + + +#define LINUX_FM_DRIVER_INCLUDED FALSE + + +/* hcisu userial operations. should probably go into bt_types to avoid collisions! */ +#define BT_EVT_TO_HCISU_USERIAL_OP (0x0080 | BT_EVT_HCISU) +/* operation for above hcisu event */ +#define BT_HCISU_USERIAL_OPEN (0) /* open serial port calling USERIAL_Open() */ +#define BT_HCISU_USERIAL_CLOSE (1) /* close userial port */ +/* options associated with close op */ +#define BT_HCISU_USERIAL_CL_NO_DIS_BT 0 /* do not touch bt_wake and power gpio */ +#define BT_HCISU_USERIAL_CL_DIS_BT 1 /* put power and bt_wake into defined off state to preserve + power */ +/* status codes for callback */ +/* +#define BTE_HCISU_USERIAL_FAIL 0 +#define BTE_HCISU_USERIAL_OK 1 +typedef void (tUSERIAL_MSG_CBACK) (int status); +typedef struct tHCISU_USERIAL_MSG_tag { + BT_HDR hdr; + tUSERIAL_MSG_CBACK *p_cback; + UINT8 port; // port number + UINT8 op; + UINT8 option; // option for operation. depends on operation +} tHCISU_USERIAL_MSG; + +extern void bte_hcisu_userial_oper( tUSERIAL_MSG_CBACK *p_cback, UINT8 port, UINT8 op, UINT8 option ); +*/ + +/* Pointer to function for sending HCI commands and data to the HCI tranport */ +extern int (*p_bte_hci_send)(UINT16 port, BT_HDR *p_msg); + + +/* Protocol trace mask */ +extern UINT32 bte_proto_trace_mask; + +typedef struct tBAUD_REG_tag { + UINT8 DHBR; + UINT8 DLBR; + UINT8 ExplicitBaudRate0; + UINT8 ExplicitBaudRate1; + UINT8 ExplicitBaudRate2; + UINT8 ExplicitBaudRate3; +} tBAUD_REG; + +#include "gki.h" + +extern const tBAUD_REG baud_rate_regs[]; + +#endif /* BTE_H */ diff --git a/tools/sdk/include/bluedroid/bte_appl.h b/tools/sdk/include/bluedroid/bte_appl.h new file mode 100755 index 00000000..4850250b --- /dev/null +++ b/tools/sdk/include/bluedroid/bte_appl.h @@ -0,0 +1,37 @@ +/****************************************************************************** + * + * 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 is the interface file for the bte application task + * + ******************************************************************************/ + +#pragma once + +typedef struct { +#if ((BLE_INCLUDED == TRUE) && (SMP_INCLUDED == TRUE)) + UINT8 ble_auth_req; + UINT8 ble_io_cap; + UINT8 ble_init_key; + UINT8 ble_resp_key; + UINT8 ble_max_key_size; +#endif +} tBTE_APPL_CFG; + +extern tBTE_APPL_CFG bte_appl_cfg; diff --git a/tools/sdk/include/bluedroid/btm_api.h b/tools/sdk/include/bluedroid/btm_api.h new file mode 100644 index 00000000..2d1edcb6 --- /dev/null +++ b/tools/sdk/include/bluedroid/btm_api.h @@ -0,0 +1,4029 @@ +/****************************************************************************** + * + * Copyright (C) 1999-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 file contains the Bluetooth Manager (BTM) API function external + * definitions. + * + ******************************************************************************/ +#ifndef BTM_API_H +#define BTM_API_H + +#include "bt_defs.h" +#include "bt_target.h" +#include "hcidefs.h" + +#if SDP_INCLUDED == TRUE +#include "sdp_api.h" +#endif + +#if SMP_INCLUDED == TRUE +#include "smp_api.h" +#endif +/***************************************************************************** +** DEVICE CONTROL and COMMON +*****************************************************************************/ +/***************************** +** Device Control Constants +******************************/ +/* Maximum number of bytes allowed for vendor specific command parameters */ +#define BTM_MAX_VENDOR_SPECIFIC_LEN HCI_COMMAND_SIZE + +/* BTM application return status codes */ +enum { + BTM_SUCCESS = 0, /* 0 Command succeeded */ + BTM_CMD_STARTED, /* 1 Command started OK. */ + BTM_BUSY, /* 2 Device busy with another command */ + BTM_NO_RESOURCES, /* 3 No resources to issue command */ + BTM_MODE_UNSUPPORTED, /* 4 Request for 1 or more unsupported modes */ + BTM_ILLEGAL_VALUE, /* 5 Illegal parameter value */ + BTM_WRONG_MODE, /* 6 Device in wrong mode for request */ + BTM_UNKNOWN_ADDR, /* 7 Unknown remote BD address */ + BTM_DEVICE_TIMEOUT, /* 8 Device timeout */ + BTM_BAD_VALUE_RET, /* 9 A bad value was received from HCI */ + BTM_ERR_PROCESSING, /* 10 Generic error */ + BTM_NOT_AUTHORIZED, /* 11 Authorization failed */ + BTM_DEV_RESET, /* 12 Device has been reset */ + BTM_CMD_STORED, /* 13 request is stored in control block */ + BTM_ILLEGAL_ACTION, /* 14 state machine gets illegal command */ + BTM_DELAY_CHECK, /* 15 delay the check on encryption */ + BTM_SCO_BAD_LENGTH, /* 16 Bad SCO over HCI data length */ + 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 */ +}; + +typedef uint8_t tBTM_STATUS; + +#if (defined(BTA_HOST_INTERLEAVE_SEARCH) && BTA_HOST_INTERLEAVE_SEARCH == TRUE) +typedef enum { + BTM_BR_ONE, /*0 First state or BR/EDR scan 1*/ + BTM_BLE_ONE, /*1BLE scan 1*/ + BTM_BR_TWO, /*2 BR/EDR scan 2*/ + BTM_BLE_TWO, /*3 BLE scan 2*/ + BTM_FINISH, /*4 End of Interleave Scan, or normal scan*/ + BTM_NO_INTERLEAVING /*5 No Interleaving*/ +} btm_inq_state; +#endif + + + +/************************* +** Device Control Types +**************************/ +#define BTM_DEVICE_ROLE_BR 0x01 +#define BTM_DEVICE_ROLE_DUAL 0x02 +#define BTM_MAX_DEVICE_ROLE BTM_DEVICE_ROLE_DUAL +typedef UINT8 tBTM_DEVICE_ROLE; + +/* Device name of peer (may be truncated to save space in BTM database) */ +typedef UINT8 tBTM_BD_NAME[BTM_MAX_REM_BD_NAME_LEN + 1]; + +/* Structure returned with local version information */ +typedef struct { + UINT8 hci_version; + UINT16 hci_revision; + UINT8 lmp_version; + UINT16 manufacturer; + UINT16 lmp_subversion; +} tBTM_VERSION_INFO; + +/* Structure returned with Vendor Specific Command complete callback */ +typedef struct { + UINT16 opcode; + UINT16 param_len; + UINT8 *p_param_buf; +} tBTM_VSC_CMPL; + +#define BTM_VSC_CMPL_DATA_SIZE (BTM_MAX_VENDOR_SPECIFIC_LEN + sizeof(tBTM_VSC_CMPL)) +/************************************************** +** Device Control and General Callback Functions +***************************************************/ +/* Callback function for when device status changes. Appl must poll for +** what the new state is (BTM_IsDeviceUp). The event occurs whenever the stack +** has detected that the controller status has changed. This asynchronous event +** is enabled/disabled by calling BTM_RegisterForDeviceStatusNotif(). +*/ +enum { + BTM_DEV_STATUS_UP, + BTM_DEV_STATUS_DOWN, + BTM_DEV_STATUS_CMD_TOUT +}; + +typedef UINT8 tBTM_DEV_STATUS; + + +typedef void (tBTM_DEV_STATUS_CB) (tBTM_DEV_STATUS status); + + +/* Callback function for when a vendor specific event occurs. The length and +** array of returned parameter bytes are included. This asynchronous event +** is enabled/disabled by calling BTM_RegisterForVSEvents(). +*/ +typedef void (tBTM_VS_EVT_CB) (UINT8 len, UINT8 *p); + + +/* General callback function for notifying an application that a synchronous +** BTM function is complete. The pointer contains the address of any returned data. +*/ +typedef void (tBTM_CMPL_CB) (void *p1); + +/* VSC callback function for notifying an application that a synchronous +** BTM function is complete. The pointer contains the address of any returned data. +*/ +typedef void (tBTM_VSC_CMPL_CB) (tBTM_VSC_CMPL *p1); + +/* Callback for apps to check connection and inquiry filters. +** Parameters are the BD Address of remote and the Dev Class of remote. +** If the app returns none zero, the connection or inquiry result will be dropped. +*/ +typedef UINT8 (tBTM_FILTER_CB) (BD_ADDR bd_addr, DEV_CLASS dc); + +/***************************************************************************** +** DEVICE DISCOVERY - Inquiry, Remote Name, Discovery, Class of Device +*****************************************************************************/ +/******************************* +** Device Discovery Constants +********************************/ +/* Discoverable modes */ +#define BTM_NON_DISCOVERABLE 0 +#define BTM_LIMITED_DISCOVERABLE 1 +#define BTM_GENERAL_DISCOVERABLE 2 +#define BTM_DISCOVERABLE_MASK (BTM_LIMITED_DISCOVERABLE|BTM_GENERAL_DISCOVERABLE) +#define BTM_MAX_DISCOVERABLE BTM_GENERAL_DISCOVERABLE +/* high byte for BLE Discoverable modes */ +#define BTM_BLE_NON_DISCOVERABLE 0x0000 +#define BTM_BLE_LIMITED_DISCOVERABLE 0x0100 +#define BTM_BLE_GENERAL_DISCOVERABLE 0x0200 +#define BTM_BLE_MAX_DISCOVERABLE BTM_BLE_GENERAL_DISCOVERABLE +#define BTM_BLE_DISCOVERABLE_MASK (BTM_BLE_NON_DISCOVERABLE|BTM_BLE_LIMITED_DISCOVERABLE|BTM_BLE_GENERAL_DISCOVERABLE) + +/* Connectable modes */ +#define BTM_NON_CONNECTABLE 0 +#define BTM_CONNECTABLE 1 +#define BTM_CONNECTABLE_MASK (BTM_NON_CONNECTABLE | BTM_CONNECTABLE) +/* high byte for BLE Connectable modes */ +#define BTM_BLE_NON_CONNECTABLE 0x0000 +#define BTM_BLE_CONNECTABLE 0x0100 +#define BTM_BLE_MAX_CONNECTABLE BTM_BLE_CONNECTABLE +#define BTM_BLE_CONNECTABLE_MASK (BTM_BLE_NON_CONNECTABLE | BTM_BLE_CONNECTABLE) + +/* Inquiry modes + * Note: These modes are associated with the inquiry active values (BTM_*ACTIVE) */ +#define BTM_INQUIRY_NONE 0 +#define BTM_GENERAL_INQUIRY 0x01 +#define BTM_LIMITED_INQUIRY 0x02 +#define BTM_BR_INQUIRY_MASK (BTM_GENERAL_INQUIRY | BTM_LIMITED_INQUIRY) + +/* high byte of inquiry mode for BLE inquiry mode */ +#define BTM_BLE_INQUIRY_NONE 0x00 +#define BTM_BLE_GENERAL_INQUIRY 0x10 +#define BTM_BLE_LIMITED_INQUIRY 0x20 +#define BTM_BLE_INQUIRY_MASK (BTM_BLE_GENERAL_INQUIRY|BTM_BLE_LIMITED_INQUIRY) + +/* BTM_IsInquiryActive return values (Bit Mask) + * Note: These bit masks are associated with the inquiry modes (BTM_*_INQUIRY) */ +#define BTM_INQUIRY_INACTIVE 0x0 /* no inquiry in progress */ +#define BTM_GENERAL_INQUIRY_ACTIVE BTM_GENERAL_INQUIRY /* a general inquiry is in progress */ +#define BTM_LIMITED_INQUIRY_ACTIVE BTM_LIMITED_INQUIRY /* a limited inquiry is in progress */ +#define BTM_PERIODIC_INQUIRY_ACTIVE 0x8 /* a periodic inquiry is active */ +#define BTM_SSP_INQUIRY_ACTIVE 0x4 /* SSP is active, so inquiry is disallowed (work around for FW bug) */ +#define BTM_LE_GENERAL_INQUIRY_ACTIVE BTM_BLE_GENERAL_INQUIRY /* a general inquiry is in progress */ +#define BTM_LE_LIMITED_INQUIRY_ACTIVE BTM_BLE_LIMITED_INQUIRY /* a limited inquiry is in progress */ + +/* inquiry activity mask */ +#define BTM_BR_INQ_ACTIVE_MASK (BTM_GENERAL_INQUIRY_ACTIVE|BTM_LIMITED_INQUIRY_ACTIVE|BTM_PERIODIC_INQUIRY_ACTIVE) /* BR/EDR inquiry activity mask */ +#define BTM_BLE_SCAN_ACTIVE_MASK 0xF0 /* LE scan activity mask */ +#define BTM_BLE_INQ_ACTIVE_MASK (BTM_LE_GENERAL_INQUIRY_ACTIVE|BTM_LE_LIMITED_INQUIRY_ACTIVE) /* LE inquiry activity mask*/ +#define BTM_INQUIRY_ACTIVE_MASK (BTM_BR_INQ_ACTIVE_MASK | BTM_BLE_INQ_ACTIVE_MASK) /* inquiry activity mask */ + +/* Define scan types */ +#define BTM_SCAN_TYPE_STANDARD 0 +#define BTM_SCAN_TYPE_INTERLACED 1 /* 1.2 devices only */ + +/* Define inquiry results mode */ +#define BTM_INQ_RESULT_STANDARD 0 +#define BTM_INQ_RESULT_WITH_RSSI 1 +#define BTM_INQ_RESULT_EXTENDED 2 + +#define BTM_INQ_RES_IGNORE_RSSI 0x7f /* RSSI value not supplied (ignore it) */ + +/* Inquiry Filter Condition types (see tBTM_INQ_PARMS) */ +#define BTM_CLR_INQUIRY_FILTER 0 /* Inquiry Filtering is turned off */ +#define BTM_FILTER_COND_DEVICE_CLASS HCI_FILTER_COND_DEVICE_CLASS /* Filter on device class */ +#define BTM_FILTER_COND_BD_ADDR HCI_FILTER_COND_BD_ADDR /* Filter on device addr */ + +/* State of the remote name retrieval during inquiry operations. +** Used in the tBTM_INQ_INFO structure, and returned in the +** BTM_InqDbRead, BTM_InqDbFirst, and BTM_InqDbNext functions. +** The name field is valid when the state returned is +** BTM_INQ_RMT_NAME_DONE */ +#define BTM_INQ_RMT_NAME_EMPTY 0 +#define BTM_INQ_RMT_NAME_PENDING 1 +#define BTM_INQ_RMT_NAME_DONE 2 +#define BTM_INQ_RMT_NAME_FAILED 3 + +/********************************* + *** Class of Device constants *** + *********************************/ +#define BTM_FORMAT_TYPE_1 0x00 + +/**************************** +** minor device class field +*****************************/ + +/* 0x00 is used as unclassified for all minor device classes */ +#define BTM_COD_MINOR_UNCLASSIFIED 0x00 + +/* minor device class field for Computer Major Class */ +/* #define BTM_COD_MINOR_UNCLASSIFIED 0x00 */ +#define BTM_COD_MINOR_DESKTOP_WORKSTATION 0x04 +#define BTM_COD_MINOR_SERVER_COMPUTER 0x08 +#define BTM_COD_MINOR_LAPTOP 0x0C +#define BTM_COD_MINOR_HANDHELD_PC_PDA 0x10 /* clam shell */ +#define BTM_COD_MINOR_PALM_SIZE_PC_PDA 0x14 +#define BTM_COD_MINOR_WEARABLE_COMPUTER 0x18 /* watch sized */ + +/* minor device class field for Phone Major Class */ +/* #define BTM_COD_MINOR_UNCLASSIFIED 0x00 */ +#define BTM_COD_MINOR_CELLULAR 0x04 +#define BTM_COD_MINOR_CORDLESS 0x08 +#define BTM_COD_MINOR_SMART_PHONE 0x0C +#define BTM_COD_MINOR_WIRED_MDM_V_GTWY 0x10 /* wired modem or voice gatway */ +#define BTM_COD_MINOR_ISDN_ACCESS 0x14 + +/* minor device class field for LAN Access Point Major Class */ +/* Load Factor Field bit 5-7 */ +#define BTM_COD_MINOR_FULLY_AVAILABLE 0x00 +#define BTM_COD_MINOR_1_17_UTILIZED 0x20 +#define BTM_COD_MINOR_17_33_UTILIZED 0x40 +#define BTM_COD_MINOR_33_50_UTILIZED 0x60 +#define BTM_COD_MINOR_50_67_UTILIZED 0x80 +#define BTM_COD_MINOR_67_83_UTILIZED 0xA0 +#define BTM_COD_MINOR_83_99_UTILIZED 0xC0 +#define BTM_COD_MINOR_NO_SERVICE_AVAILABLE 0xE0 +/* sub-Field bit 2-4 */ +/* #define BTM_COD_MINOR_UNCLASSIFIED 0x00 */ + +/* minor device class field for Audio/Video Major Class */ +/* #define BTM_COD_MINOR_UNCLASSIFIED 0x00 */ +#define BTM_COD_MINOR_CONFM_HEADSET 0x04 +#define BTM_COD_MINOR_CONFM_HANDSFREE 0x08 +#define BTM_COD_MINOR_MICROPHONE 0x10 +#define BTM_COD_MINOR_LOUDSPEAKER 0x14 +#define BTM_COD_MINOR_HEADPHONES 0x18 +#define BTM_COD_MINOR_PORTABLE_AUDIO 0x1C +#define BTM_COD_MINOR_CAR_AUDIO 0x20 +#define BTM_COD_MINOR_SET_TOP_BOX 0x24 +#define BTM_COD_MINOR_HIFI_AUDIO 0x28 +#define BTM_COD_MINOR_VCR 0x2C +#define BTM_COD_MINOR_VIDEO_CAMERA 0x30 +#define BTM_COD_MINOR_CAMCORDER 0x34 +#define BTM_COD_MINOR_VIDEO_MONITOR 0x38 +#define BTM_COD_MINOR_VIDDISP_LDSPKR 0x3C +#define BTM_COD_MINOR_VIDEO_CONFERENCING 0x40 +#define BTM_COD_MINOR_GAMING_TOY 0x48 + +/* minor device class field for Peripheral Major Class */ +/* Bits 6-7 independently specify mouse, keyboard, or combo mouse/keyboard */ +#define BTM_COD_MINOR_KEYBOARD 0x40 +#define BTM_COD_MINOR_POINTING 0x80 +#define BTM_COD_MINOR_COMBO 0xC0 +/* Bits 2-5 OR'd with selection from bits 6-7 */ +/* #define BTM_COD_MINOR_UNCLASSIFIED 0x00 */ +#define BTM_COD_MINOR_JOYSTICK 0x04 +#define BTM_COD_MINOR_GAMEPAD 0x08 +#define BTM_COD_MINOR_REMOTE_CONTROL 0x0C +#define BTM_COD_MINOR_SENSING_DEVICE 0x10 +#define BTM_COD_MINOR_DIGITIZING_TABLET 0x14 +#define BTM_COD_MINOR_CARD_READER 0x18 /* e.g. SIM card reader */ +#define BTM_COD_MINOR_DIGITAL_PAN 0x1C +#define BTM_COD_MINOR_HAND_SCANNER 0x20 +#define BTM_COD_MINOR_HAND_GESTURAL_INPUT 0x24 + +/* minor device class field for Imaging Major Class */ +/* Bits 5-7 independently specify display, camera, scanner, or printer */ +#define BTM_COD_MINOR_DISPLAY 0x10 +#define BTM_COD_MINOR_CAMERA 0x20 +#define BTM_COD_MINOR_SCANNER 0x40 +#define BTM_COD_MINOR_PRINTER 0x80 +/* Bits 2-3 Reserved */ +/* #define BTM_COD_MINOR_UNCLASSIFIED 0x00 */ + +/* minor device class field for Wearable Major Class */ +/* Bits 2-7 meaningful */ +#define BTM_COD_MINOR_WRIST_WATCH 0x04 +#define BTM_COD_MINOR_PAGER 0x08 +#define BTM_COD_MINOR_JACKET 0x0C +#define BTM_COD_MINOR_HELMET 0x10 +#define BTM_COD_MINOR_GLASSES 0x14 + +/* minor device class field for Toy Major Class */ +/* Bits 2-7 meaningful */ +#define BTM_COD_MINOR_ROBOT 0x04 +#define BTM_COD_MINOR_VEHICLE 0x08 +#define BTM_COD_MINOR_DOLL_ACTION_FIGURE 0x0C +#define BTM_COD_MINOR_CONTROLLER 0x10 +#define BTM_COD_MINOR_GAME 0x14 + +/* minor device class field for Health Major Class */ +/* Bits 2-7 meaningful */ +#define BTM_COD_MINOR_BLOOD_MONITOR 0x04 +#define BTM_COD_MINOR_THERMOMETER 0x08 +#define BTM_COD_MINOR_WEIGHING_SCALE 0x0C +#define BTM_COD_MINOR_GLUCOSE_METER 0x10 +#define BTM_COD_MINOR_PULSE_OXIMETER 0x14 +#define BTM_COD_MINOR_HEART_PULSE_MONITOR 0x18 +#define BTM_COD_MINOR_HEALTH_DATA_DISPLAY 0x1C +#define BTM_COD_MINOR_STEP_COUNTER 0x20 +#define BTM_COD_MINOR_BODY_COM_ANALYZER 0x24 +#define BTM_COD_MINOR_PEAK_FLOW_MONITOR 0x28 +#define BTM_COD_MINOR_MEDICATION_MONITOR 0x2C +#define BTM_COD_MINOR_KNEE_PROSTHESIS 0x30 +#define BTM_COD_MINOR_ANKLE_PROSTHESIS 0x34 + + +/*************************** +** major device class field +****************************/ +#define BTM_COD_MAJOR_MISCELLANEOUS 0x00 +#define BTM_COD_MAJOR_COMPUTER 0x01 +#define BTM_COD_MAJOR_PHONE 0x02 +#define BTM_COD_MAJOR_LAN_ACCESS_PT 0x03 +#define BTM_COD_MAJOR_AUDIO 0x04 +#define BTM_COD_MAJOR_PERIPHERAL 0x05 +#define BTM_COD_MAJOR_IMAGING 0x06 +#define BTM_COD_MAJOR_WEARABLE 0x07 +#define BTM_COD_MAJOR_TOY 0x08 +#define BTM_COD_MAJOR_HEALTH 0x09 +#define BTM_COD_MAJOR_UNCLASSIFIED 0x1F + +/*************************** +** service class fields +****************************/ +#define BTM_COD_SERVICE_LMTD_DISCOVER 0x0020 +#define BTM_COD_SERVICE_POSITIONING 0x0100 +#define BTM_COD_SERVICE_NETWORKING 0x0200 +#define BTM_COD_SERVICE_RENDERING 0x0400 +#define BTM_COD_SERVICE_CAPTURING 0x0800 +#define BTM_COD_SERVICE_OBJ_TRANSFER 0x1000 +#define BTM_COD_SERVICE_AUDIO 0x2000 +#define BTM_COD_SERVICE_TELEPHONY 0x4000 +#define BTM_COD_SERVICE_INFORMATION 0x8000 + +/* class of device field macros */ +#define BTM_COD_FORMAT_TYPE(u8, pd) {u8 = pd[2]&0x03;} +#define BTM_COD_MINOR_CLASS(u8, pd) {u8 = pd[2]&0xFC;} +#define BTM_COD_MAJOR_CLASS(u8, pd) {u8 = pd[1]&0x1F;} +#define BTM_COD_SERVICE_CLASS(u16, pd) {u16 = pd[0]; u16<<=8; u16 += pd[1]&0xE0;} + +/* to set the fields (assumes that format type is always 0) */ +#define FIELDS_TO_COD(pd, mn, mj, sv) {pd[2] = mn; pd[1] = \ + mj+ ((sv)&BTM_COD_SERVICE_CLASS_LO_B); \ + pd[0] = (sv) >> 8;} + +/* the COD masks */ +#define BTM_COD_FORMAT_TYPE_MASK 0x03 +#define BTM_COD_MINOR_CLASS_MASK 0xFC +#define BTM_COD_MAJOR_CLASS_MASK 0x1F +#define BTM_COD_SERVICE_CLASS_LO_B 0x00E0 +#define BTM_COD_SERVICE_CLASS_MASK 0xFFE0 + + +/* BTM service definitions +** Used for storing EIR data to bit mask +*/ +enum { + BTM_EIR_UUID_SERVCLASS_SERVICE_DISCOVERY_SERVER, + /* BTM_EIR_UUID_SERVCLASS_BROWSE_GROUP_DESCRIPTOR, */ + /* BTM_EIR_UUID_SERVCLASS_PUBLIC_BROWSE_GROUP, */ + BTM_EIR_UUID_SERVCLASS_SERIAL_PORT, + BTM_EIR_UUID_SERVCLASS_LAN_ACCESS_USING_PPP, + BTM_EIR_UUID_SERVCLASS_DIALUP_NETWORKING, + BTM_EIR_UUID_SERVCLASS_IRMC_SYNC, + BTM_EIR_UUID_SERVCLASS_OBEX_OBJECT_PUSH, + BTM_EIR_UUID_SERVCLASS_OBEX_FILE_TRANSFER, + BTM_EIR_UUID_SERVCLASS_IRMC_SYNC_COMMAND, + BTM_EIR_UUID_SERVCLASS_HEADSET, + BTM_EIR_UUID_SERVCLASS_CORDLESS_TELEPHONY, + BTM_EIR_UUID_SERVCLASS_AUDIO_SOURCE, + BTM_EIR_UUID_SERVCLASS_AUDIO_SINK, + BTM_EIR_UUID_SERVCLASS_AV_REM_CTRL_TARGET, + /* BTM_EIR_UUID_SERVCLASS_ADV_AUDIO_DISTRIBUTION, */ + BTM_EIR_UUID_SERVCLASS_AV_REMOTE_CONTROL, + /* BTM_EIR_UUID_SERVCLASS_VIDEO_CONFERENCING, */ + BTM_EIR_UUID_SERVCLASS_INTERCOM, + BTM_EIR_UUID_SERVCLASS_FAX, + BTM_EIR_UUID_SERVCLASS_HEADSET_AUDIO_GATEWAY, + /* BTM_EIR_UUID_SERVCLASS_WAP, */ + /* BTM_EIR_UUID_SERVCLASS_WAP_CLIENT, */ + BTM_EIR_UUID_SERVCLASS_PANU, + BTM_EIR_UUID_SERVCLASS_NAP, + BTM_EIR_UUID_SERVCLASS_GN, + BTM_EIR_UUID_SERVCLASS_DIRECT_PRINTING, + /* BTM_EIR_UUID_SERVCLASS_REFERENCE_PRINTING, */ + BTM_EIR_UUID_SERVCLASS_IMAGING, + BTM_EIR_UUID_SERVCLASS_IMAGING_RESPONDER, + BTM_EIR_UUID_SERVCLASS_IMAGING_AUTO_ARCHIVE, + BTM_EIR_UUID_SERVCLASS_IMAGING_REF_OBJECTS, + BTM_EIR_UUID_SERVCLASS_HF_HANDSFREE, + BTM_EIR_UUID_SERVCLASS_AG_HANDSFREE, + BTM_EIR_UUID_SERVCLASS_DIR_PRT_REF_OBJ_SERVICE, + /* BTM_EIR_UUID_SERVCLASS_REFLECTED_UI, */ + BTM_EIR_UUID_SERVCLASS_BASIC_PRINTING, + BTM_EIR_UUID_SERVCLASS_PRINTING_STATUS, + BTM_EIR_UUID_SERVCLASS_HUMAN_INTERFACE, + BTM_EIR_UUID_SERVCLASS_CABLE_REPLACEMENT, + BTM_EIR_UUID_SERVCLASS_HCRP_PRINT, + BTM_EIR_UUID_SERVCLASS_HCRP_SCAN, + /* BTM_EIR_UUID_SERVCLASS_COMMON_ISDN_ACCESS, */ + /* BTM_EIR_UUID_SERVCLASS_VIDEO_CONFERENCING_GW, */ + /* BTM_EIR_UUID_SERVCLASS_UDI_MT, */ + /* BTM_EIR_UUID_SERVCLASS_UDI_TA, */ + /* BTM_EIR_UUID_SERVCLASS_VCP, */ + BTM_EIR_UUID_SERVCLASS_SAP, + BTM_EIR_UUID_SERVCLASS_PBAP_PCE, + BTM_EIR_UUID_SERVCLASS_PBAP_PSE, + /* BTM_EIR_UUID_SERVCLASS_TE_PHONE_ACCESS, */ + /* BTM_EIR_UUID_SERVCLASS_ME_PHONE_ACCESS, */ + BTM_EIR_UUID_SERVCLASS_PHONE_ACCESS, + BTM_EIR_UUID_SERVCLASS_HEADSET_HS, + BTM_EIR_UUID_SERVCLASS_PNP_INFORMATION, + /* BTM_EIR_UUID_SERVCLASS_GENERIC_NETWORKING, */ + /* BTM_EIR_UUID_SERVCLASS_GENERIC_FILETRANSFER, */ + /* BTM_EIR_UUID_SERVCLASS_GENERIC_AUDIO, */ + /* BTM_EIR_UUID_SERVCLASS_GENERIC_TELEPHONY, */ + /* BTM_EIR_UUID_SERVCLASS_UPNP_SERVICE, */ + /* BTM_EIR_UUID_SERVCLASS_UPNP_IP_SERVICE, */ + /* BTM_EIR_UUID_SERVCLASS_ESDP_UPNP_IP_PAN, */ + /* BTM_EIR_UUID_SERVCLASS_ESDP_UPNP_IP_LAP, */ + /* BTM_EIR_UUID_SERVCLASS_ESDP_UPNP_IP_L2CAP, */ + BTM_EIR_UUID_SERVCLASS_VIDEO_SOURCE, + BTM_EIR_UUID_SERVCLASS_VIDEO_SINK, + /* BTM_EIR_UUID_SERVCLASS_VIDEO_DISTRIBUTION */ + /* BTM_EIR_UUID_SERVCLASS_HDP_PROFILE */ + BTM_EIR_UUID_SERVCLASS_MESSAGE_ACCESS, + BTM_EIR_UUID_SERVCLASS_MESSAGE_NOTIFICATION, + BTM_EIR_UUID_SERVCLASS_HDP_SOURCE, + BTM_EIR_UUID_SERVCLASS_HDP_SINK, + BTM_EIR_MAX_SERVICES +}; + +/* search result in EIR of inquiry database */ +#define BTM_EIR_FOUND 0 +#define BTM_EIR_NOT_FOUND 1 +#define BTM_EIR_UNKNOWN 2 + +typedef UINT8 tBTM_EIR_SEARCH_RESULT; + +#define BTM_EIR_FLAGS_TYPE HCI_EIR_FLAGS_TYPE /* 0x01 */ +#define BTM_EIR_MORE_16BITS_UUID_TYPE HCI_EIR_MORE_16BITS_UUID_TYPE /* 0x02 */ +#define BTM_EIR_COMPLETE_16BITS_UUID_TYPE HCI_EIR_COMPLETE_16BITS_UUID_TYPE /* 0x03 */ +#define BTM_EIR_MORE_32BITS_UUID_TYPE HCI_EIR_MORE_32BITS_UUID_TYPE /* 0x04 */ +#define BTM_EIR_COMPLETE_32BITS_UUID_TYPE HCI_EIR_COMPLETE_32BITS_UUID_TYPE /* 0x05 */ +#define BTM_EIR_MORE_128BITS_UUID_TYPE HCI_EIR_MORE_128BITS_UUID_TYPE /* 0x06 */ +#define BTM_EIR_COMPLETE_128BITS_UUID_TYPE HCI_EIR_COMPLETE_128BITS_UUID_TYPE /* 0x07 */ +#define BTM_EIR_SHORTENED_LOCAL_NAME_TYPE HCI_EIR_SHORTENED_LOCAL_NAME_TYPE /* 0x08 */ +#define BTM_EIR_COMPLETE_LOCAL_NAME_TYPE HCI_EIR_COMPLETE_LOCAL_NAME_TYPE /* 0x09 */ +#define BTM_EIR_TX_POWER_LEVEL_TYPE HCI_EIR_TX_POWER_LEVEL_TYPE /* 0x0A */ +#define BTM_EIR_MANUFACTURER_SPECIFIC_TYPE HCI_EIR_MANUFACTURER_SPECIFIC_TYPE /* 0xFF */ + +/* the following EIR tags are defined to OOB, not regular EIR data */ +#define BTM_EIR_OOB_BD_ADDR_TYPE HCI_EIR_OOB_BD_ADDR_TYPE /* 6 bytes */ +#define BTM_EIR_OOB_COD_TYPE HCI_EIR_OOB_COD_TYPE /* 3 bytes */ +#define BTM_EIR_OOB_SSP_HASH_C_TYPE HCI_EIR_OOB_SSP_HASH_C_TYPE /* 16 bytes */ +#define BTM_EIR_OOB_SSP_RAND_R_TYPE HCI_EIR_OOB_SSP_RAND_R_TYPE /* 16 bytes */ + +#define BTM_OOB_MANDATORY_SIZE 8 /* include 2 bytes length & 6 bytes bd_addr */ +#define BTM_OOB_DATA_LEN_SIZE 2 +#define BTM_OOB_BD_ADDR_SIZE 6 +#define BTM_OOB_COD_SIZE BT_OOB_COD_SIZE +#define BTM_OOB_HASH_C_SIZE BT_OOB_HASH_C_SIZE +#define BTM_OOB_RAND_R_SIZE BT_OOB_RAND_R_SIZE + + +#if BLE_INCLUDED == TRUE +#define BTM_BLE_SEC_NONE 0 +#define BTM_BLE_SEC_ENCRYPT 1 /* encrypt the link using current key */ +#define BTM_BLE_SEC_ENCRYPT_NO_MITM 2 +#define BTM_BLE_SEC_ENCRYPT_MITM 3 +typedef UINT8 tBTM_BLE_SEC_ACT; +#endif +/************************************************************************************************ +** BTM Services MACROS handle array of UINT32 bits for more than 32 services +*************************************************************************************************/ +/* Determine the number of UINT32's necessary for services */ +#define BTM_EIR_ARRAY_BITS 32 /* Number of bits in each array element */ +#define BTM_EIR_SERVICE_ARRAY_SIZE (((UINT32)BTM_EIR_MAX_SERVICES / BTM_EIR_ARRAY_BITS) + \ + (((UINT32)BTM_EIR_MAX_SERVICES % BTM_EIR_ARRAY_BITS) ? 1 : 0)) + +/* MACRO to set the service bit mask in a bit stream */ +#define BTM_EIR_SET_SERVICE(p, service) (((UINT32 *)(p))[(((UINT32)(service)) / BTM_EIR_ARRAY_BITS)] |= \ + ((UINT32)1 << (((UINT32)(service)) % BTM_EIR_ARRAY_BITS))) + + +/* MACRO to clear the service bit mask in a bit stream */ +#define BTM_EIR_CLR_SERVICE(p, service) (((UINT32 *)(p))[(((UINT32)(service)) / BTM_EIR_ARRAY_BITS)] &= \ + ~((UINT32)1 << (((UINT32)(service)) % BTM_EIR_ARRAY_BITS))) + +/* MACRO to check the service bit mask in a bit stream */ +#define BTM_EIR_HAS_SERVICE(p, service) ((((UINT32 *)(p))[(((UINT32)(service)) / BTM_EIR_ARRAY_BITS)] & \ + ((UINT32)1 << (((UINT32)(service)) % BTM_EIR_ARRAY_BITS))) >> (((UINT32)(service)) % BTM_EIR_ARRAY_BITS)) + +/* start of EIR in HCI buffer, 4 bytes = HCI Command(2) + Length(1) + FEC_Req(1) */ +#define BTM_HCI_EIR_OFFSET (BT_HDR_SIZE + 4) + +/*************************** +** Device Discovery Types +****************************/ +/* Definitions of the parameters passed to BTM_StartInquiry and +** BTM_SetPeriodicInquiryMode. +*/ +typedef struct { /* contains the two device class condition fields */ + DEV_CLASS dev_class; + DEV_CLASS dev_class_mask; +} tBTM_COD_COND; + + +typedef union { /* contains the inquiry filter condition */ + BD_ADDR bdaddr_cond; + tBTM_COD_COND cod_cond; +} tBTM_INQ_FILT_COND; + + +typedef struct { /* contains the parameters passed to the inquiry functions */ + UINT8 mode; /* general or limited */ + UINT8 duration; /* duration of the inquiry (1.28 sec increments) */ + UINT8 max_resps; /* maximum number of responses to return */ + BOOLEAN report_dup; /* report duplicated inquiry response with higher RSSI value */ + UINT8 filter_cond_type; /* new devices, BD ADDR, COD, or No filtering */ + tBTM_INQ_FILT_COND filter_cond; /* filter value based on filter cond type */ +#if (defined(BTA_HOST_INTERLEAVE_SEARCH) && BTA_HOST_INTERLEAVE_SEARCH == TRUE) + UINT8 intl_duration[4]; /*duration array storing the interleave scan's time portions*/ +#endif +} tBTM_INQ_PARMS; + +#define BTM_INQ_RESULT_BR 0x01 +#define BTM_INQ_RESULT_BLE 0x02 + +#if (BLE_INCLUDED == TRUE) +#define BTM_BLE_EVT_CONN_ADV 0x00 +#define BTM_BLE_EVT_CONN_DIR_ADV 0x01 +#define BTM_BLE_EVT_DISC_ADV 0x02 +#define BTM_BLE_EVT_NON_CONN_ADV 0x03 +#define BTM_BLE_EVT_SCAN_RSP 0x04 +typedef UINT8 tBTM_BLE_EVT_TYPE; +#endif + +/* These are the fields returned in each device's response to the inquiry. It +** is returned in the results callback if registered. +*/ +typedef struct { + UINT16 clock_offset; + BD_ADDR remote_bd_addr; + DEV_CLASS dev_class; + UINT8 page_scan_rep_mode; + UINT8 page_scan_per_mode; + UINT8 page_scan_mode; + INT8 rssi; /* Set to BTM_INQ_RES_IGNORE_RSSI if not valid */ + UINT32 eir_uuid[BTM_EIR_SERVICE_ARRAY_SIZE]; + BOOLEAN eir_complete_list; +#if (BLE_INCLUDED == TRUE) + tBT_DEVICE_TYPE device_type; + UINT8 inq_result_type; + UINT8 ble_addr_type; + tBTM_BLE_EVT_TYPE ble_evt_type; + UINT8 flag; +#endif +} tBTM_INQ_RESULTS; + + +/* This is the inquiry response information held in its database by BTM, and available +** to applications via BTM_InqDbRead, BTM_InqDbFirst, and BTM_InqDbNext. +*/ +typedef struct { + tBTM_INQ_RESULTS results; + + BOOLEAN appl_knows_rem_name; /* set by application if it knows the remote name of the peer device. + This is later used by application to determine if remote name request is + required to be done. Having the flag here avoid duplicate store of inquiry results */ +#if ( BLE_INCLUDED == TRUE) + UINT16 remote_name_len; + tBTM_BD_NAME remote_name; + UINT8 remote_name_state; + UINT8 remote_name_type; +#endif + +} tBTM_INQ_INFO; + + +/* Structure returned with inquiry complete callback */ +typedef struct { + tBTM_STATUS status; + UINT8 num_resp; /* Number of results from the current inquiry */ +} tBTM_INQUIRY_CMPL; + + +/* Structure returned with remote name request */ +typedef struct { + UINT16 status; + BD_ADDR bd_addr; + UINT16 length; + BD_NAME remote_bd_name; +} tBTM_REMOTE_DEV_NAME; + +typedef struct { + UINT8 pcm_intf_rate; /* PCM interface rate: 0: 128kbps, 1: 256 kbps; + 2:512 bps; 3: 1024kbps; 4: 2048kbps */ + UINT8 frame_type; /* frame type: 0: short; 1: long */ + UINT8 sync_mode; /* sync mode: 0: slave; 1: master */ + UINT8 clock_mode; /* clock mode: 0: slave; 1: master */ + +} tBTM_SCO_PCM_PARAM; + +/**************************************** +** Device Discovery Callback Functions +*****************************************/ +/* Callback function for asynchronous notifications when the BTM inquiry DB +** changes. First param is inquiry database, second is if added to or removed +** from the inquiry database. +*/ +typedef void (tBTM_INQ_DB_CHANGE_CB) (void *p1, BOOLEAN is_new); + +/* Callback function for notifications when the BTM gets inquiry response. +** First param is inquiry results database, second is pointer of EIR. +*/ +typedef void (tBTM_INQ_RESULTS_CB) (tBTM_INQ_RESULTS *p_inq_results, UINT8 *p_eir); + +/***************************************************************************** +** ACL CHANNEL MANAGEMENT +*****************************************************************************/ +/****************** +** ACL Constants +*******************/ + +/* ACL modes */ +#define BTM_ACL_MODE_NORMAL HCI_MODE_ACTIVE +#define BTM_ACL_MODE_HOLD HCI_MODE_HOLD +#define BTM_ACL_MODE_SNIFF HCI_MODE_SNIFF +#define BTM_ACL_MODE_PARK HCI_MODE_PARK + +/* Returned with structure in role switch callback (tBTM_ROLE_SWITCH_CMPL) */ +#define BTM_ROLE_MASTER HCI_ROLE_MASTER +#define BTM_ROLE_SLAVE HCI_ROLE_SLAVE +#define BTM_ROLE_UNDEFINED 0xff /* undefined value (error status) */ + +/* ACL Packet Types */ +#define BTM_ACL_PKT_TYPES_MASK_DM1 HCI_PKT_TYPES_MASK_DM1 +#define BTM_ACL_PKT_TYPES_MASK_DH1 HCI_PKT_TYPES_MASK_DH1 +#define BTM_ACL_PKT_TYPES_MASK_DM3 HCI_PKT_TYPES_MASK_DM3 +#define BTM_ACL_PKT_TYPES_MASK_DH3 HCI_PKT_TYPES_MASK_DH3 +#define BTM_ACL_PKT_TYPES_MASK_DM5 HCI_PKT_TYPES_MASK_DM5 +#define BTM_ACL_PKT_TYPES_MASK_DH5 HCI_PKT_TYPES_MASK_DH5 +#define BTM_ACL_PKT_TYPES_MASK_NO_2_DH1 HCI_PKT_TYPES_MASK_NO_2_DH1 +#define BTM_ACL_PKT_TYPES_MASK_NO_3_DH1 HCI_PKT_TYPES_MASK_NO_3_DH1 +#define BTM_ACL_PKT_TYPES_MASK_NO_2_DH3 HCI_PKT_TYPES_MASK_NO_2_DH3 +#define BTM_ACL_PKT_TYPES_MASK_NO_3_DH3 HCI_PKT_TYPES_MASK_NO_3_DH3 +#define BTM_ACL_PKT_TYPES_MASK_NO_2_DH5 HCI_PKT_TYPES_MASK_NO_2_DH5 +#define BTM_ACL_PKT_TYPES_MASK_NO_3_DH5 HCI_PKT_TYPES_MASK_NO_3_DH5 + +/*************** +** ACL Types +****************/ + +/* Structure returned with Role Switch information (in tBTM_CMPL_CB callback function) +** in response to BTM_SwitchRole call. +*/ +typedef struct { + UINT8 hci_status; /* HCI status returned with the event */ + UINT8 role; /* BTM_ROLE_MASTER or BTM_ROLE_SLAVE */ + BD_ADDR remote_bd_addr; /* Remote BD addr involved with the switch */ +} tBTM_ROLE_SWITCH_CMPL; + +/* Structure returned with QoS information (in tBTM_CMPL_CB callback function) +** in response to BTM_SetQoS call. +*/ +typedef struct { + FLOW_SPEC flow; + UINT16 handle; + UINT8 status; +} tBTM_QOS_SETUP_CMPL; + + +/* Structure returned with read RSSI event (in tBTM_CMPL_CB callback function) +** in response to BTM_ReadRSSI call. +*/ +typedef struct { + tBTM_STATUS status; + UINT8 hci_status; + INT8 rssi; + BD_ADDR rem_bda; +} tBTM_RSSI_RESULTS; + +/* Structure returned with read current TX power event (in tBTM_CMPL_CB callback function) +** in response to BTM_ReadTxPower call. +*/ +typedef struct { + tBTM_STATUS status; + UINT8 hci_status; + INT8 tx_power; + BD_ADDR rem_bda; +} tBTM_TX_POWER_RESULTS; + +/* Structure returned with read link quality event (in tBTM_CMPL_CB callback function) +** in response to BTM_ReadLinkQuality call. +*/ +typedef struct { + tBTM_STATUS status; + UINT8 hci_status; + UINT8 link_quality; + BD_ADDR rem_bda; +} tBTM_LINK_QUALITY_RESULTS; + +/* Structure returned with read inq tx power quality event (in tBTM_CMPL_CB callback function) +** in response to BTM_ReadInquiryRspTxPower call. +*/ +typedef struct { + tBTM_STATUS status; + UINT8 hci_status; + INT8 tx_power; +} tBTM_INQ_TXPWR_RESULTS; + +enum { + BTM_BL_CONN_EVT, + BTM_BL_DISCN_EVT, + BTM_BL_UPDATE_EVT, + BTM_BL_ROLE_CHG_EVT, + BTM_BL_COLLISION_EVT +}; +typedef UINT8 tBTM_BL_EVENT; +typedef UINT16 tBTM_BL_EVENT_MASK; + +#define BTM_BL_CONN_MASK 0x0001 +#define BTM_BL_DISCN_MASK 0x0002 +#define BTM_BL_UPDATE_MASK 0x0004 +#define BTM_BL_ROLE_CHG_MASK 0x0008 + +/* Device features mask definitions */ +#define BTM_FEATURE_BYTES_PER_PAGE HCI_FEATURE_BYTES_PER_PAGE +#define BTM_EXT_FEATURES_PAGE_MAX HCI_EXT_FEATURES_PAGE_MAX + +/* the data type associated with BTM_BL_CONN_EVT */ +typedef struct { + tBTM_BL_EVENT event; /* The event reported. */ + BD_ADDR_PTR p_bda; /* The address of the newly connected device */ + DEV_CLASS_PTR p_dc; /* The device class */ + BD_NAME_PTR p_bdn; /* The device name */ + UINT8 *p_features; /* pointer to the remote device's features page[0] (supported features page) */ +#if BLE_INCLUDED == TRUE + UINT16 handle; /* connection handle */ + tBT_TRANSPORT transport; /* link is LE or not */ +#endif +} tBTM_BL_CONN_DATA; + +/* the data type associated with BTM_BL_DISCN_EVT */ +typedef struct { + tBTM_BL_EVENT event; /* The event reported. */ + BD_ADDR_PTR p_bda; /* The address of the disconnected device */ +#if BLE_INCLUDED == TRUE + UINT16 handle; /* disconnected connection handle */ + tBT_TRANSPORT transport; /* link is LE link or not */ +#endif +} tBTM_BL_DISCN_DATA; + +/* Busy-Level shall have the inquiry_paging mask set when + * inquiry/paging is in progress, Else the number of ACL links */ +#define BTM_BL_INQUIRY_PAGING_MASK 0x10 +#define BTM_BL_INQUIRY_STARTED (BTM_BL_INQUIRY_PAGING_MASK | 0x1) +#define BTM_BL_INQUIRY_CANCELLED (BTM_BL_INQUIRY_PAGING_MASK | 0x2) +#define BTM_BL_INQUIRY_COMPLETE (BTM_BL_INQUIRY_PAGING_MASK | 0x3) +#define BTM_BL_PAGING_STARTED (BTM_BL_INQUIRY_PAGING_MASK | 0x4) +#define BTM_BL_PAGING_COMPLETE (BTM_BL_INQUIRY_PAGING_MASK | 0x5) +/* the data type associated with BTM_BL_UPDATE_EVT */ +typedef struct { + tBTM_BL_EVENT event; /* The event reported. */ + UINT8 busy_level;/* when paging or inquiring, level is 10. + * Otherwise, the number of ACL links. */ + UINT8 busy_level_flags; /* Notifies actual inquiry/page activities */ +} tBTM_BL_UPDATE_DATA; + +/* the data type associated with BTM_BL_ROLE_CHG_EVT */ +typedef struct { + tBTM_BL_EVENT event; /* The event reported. */ + BD_ADDR_PTR p_bda; /* The address of the peer connected device */ + UINT8 new_role; + UINT8 hci_status; /* HCI status returned with the event */ +} tBTM_BL_ROLE_CHG_DATA; + +typedef union { + tBTM_BL_EVENT event; /* The event reported. */ + tBTM_BL_CONN_DATA conn; /* The data associated with BTM_BL_CONN_EVT */ + tBTM_BL_DISCN_DATA discn; /* The data associated with BTM_BL_DISCN_EVT */ + tBTM_BL_UPDATE_DATA update; /* The data associated with BTM_BL_UPDATE_EVT */ + tBTM_BL_ROLE_CHG_DATA role_chg;/*The data associated with BTM_BL_ROLE_CHG_EVT */ +} tBTM_BL_EVENT_DATA; + +/* Callback function for notifications when the BTM busy level +** changes. +*/ +typedef void (tBTM_BL_CHANGE_CB) (tBTM_BL_EVENT_DATA *p_data); + +/*************************** +** ACL Callback Functions +****************************/ +/* Callback function for notifications when the BTM ACL connection DB +** changes. First param is BD address, second is if added or removed. +** Registered through BTM_AclRegisterForChanges call. +*/ +#if BLE_INCLUDED == TRUE +typedef void (tBTM_ACL_DB_CHANGE_CB) (BD_ADDR p_bda, DEV_CLASS p_dc, + BD_NAME p_bdn, UINT8 *features, + BOOLEAN is_new, UINT16 handle, + tBT_TRANSPORT transport); +#else +typedef void (tBTM_ACL_DB_CHANGE_CB) (BD_ADDR p_bda, DEV_CLASS p_dc, + BD_NAME p_bdn, UINT8 *features, + BOOLEAN is_new); +#endif +/***************************************************************************** +** SCO CHANNEL MANAGEMENT +*****************************************************************************/ +/****************** +** SCO Constants +*******************/ + +/* Define an invalid SCO index and an invalid HCI handle */ +#define BTM_INVALID_SCO_INDEX 0xFFFF +#define BTM_INVALID_HCI_HANDLE 0xFFFF + +/* Define an invalid SCO disconnect reason */ +#define BTM_INVALID_SCO_DISC_REASON 0xFFFF + +/* Define first active SCO index */ +#define BTM_FIRST_ACTIVE_SCO_INDEX BTM_MAX_SCO_LINKS + +/* Define SCO packet types used in APIs */ +#define BTM_SCO_PKT_TYPES_MASK_HV1 HCI_ESCO_PKT_TYPES_MASK_HV1 +#define BTM_SCO_PKT_TYPES_MASK_HV2 HCI_ESCO_PKT_TYPES_MASK_HV2 +#define BTM_SCO_PKT_TYPES_MASK_HV3 HCI_ESCO_PKT_TYPES_MASK_HV3 +#define BTM_SCO_PKT_TYPES_MASK_EV3 HCI_ESCO_PKT_TYPES_MASK_EV3 +#define BTM_SCO_PKT_TYPES_MASK_EV4 HCI_ESCO_PKT_TYPES_MASK_EV4 +#define BTM_SCO_PKT_TYPES_MASK_EV5 HCI_ESCO_PKT_TYPES_MASK_EV5 +#define BTM_SCO_PKT_TYPES_MASK_NO_2_EV3 HCI_ESCO_PKT_TYPES_MASK_NO_2_EV3 +#define BTM_SCO_PKT_TYPES_MASK_NO_3_EV3 HCI_ESCO_PKT_TYPES_MASK_NO_3_EV3 +#define BTM_SCO_PKT_TYPES_MASK_NO_2_EV5 HCI_ESCO_PKT_TYPES_MASK_NO_2_EV5 +#define BTM_SCO_PKT_TYPES_MASK_NO_3_EV5 HCI_ESCO_PKT_TYPES_MASK_NO_3_EV5 + +#define BTM_SCO_LINK_ONLY_MASK (BTM_SCO_PKT_TYPES_MASK_HV1 | \ + BTM_SCO_PKT_TYPES_MASK_HV2 | \ + BTM_SCO_PKT_TYPES_MASK_HV3) + +#define BTM_ESCO_LINK_ONLY_MASK (BTM_SCO_PKT_TYPES_MASK_EV3 | \ + BTM_SCO_PKT_TYPES_MASK_EV4 | \ + BTM_SCO_PKT_TYPES_MASK_EV5) + +#define BTM_SCO_LINK_ALL_PKT_MASK (BTM_SCO_LINK_ONLY_MASK | \ + BTM_ESCO_LINK_ONLY_MASK) + +#define BTM_VALID_SCO_ALL_PKT_TYPE HCI_VALID_SCO_ALL_PKT_TYPE + +/* Passed in BTM_CreateSco if the packet type parameter should be ignored */ +#define BTM_IGNORE_SCO_PKT_TYPE 0 + +/*************** +** SCO Types +****************/ +#define BTM_LINK_TYPE_SCO HCI_LINK_TYPE_SCO +#define BTM_LINK_TYPE_ESCO HCI_LINK_TYPE_ESCO +typedef UINT8 tBTM_SCO_TYPE; + + +/******************* +** SCO Routing Path +********************/ +#define BTM_SCO_ROUTE_PCM HCI_BRCM_SCO_ROUTE_PCM +#define BTM_SCO_ROUTE_HCI HCI_BRCM_SCO_ROUTE_HCI +typedef UINT8 tBTM_SCO_ROUTE_TYPE; + + +/******************* +** SCO Codec Types +********************/ +// TODO(google) This should use common definitions +// in hci/include/hci_audio.h +#define BTM_SCO_CODEC_NONE 0x0000 +#define BTM_SCO_CODEC_CVSD 0x0001 +#define BTM_SCO_CODEC_MSBC 0x0002 +typedef UINT16 tBTM_SCO_CODEC_TYPE; + + + +/******************* +** SCO Air Mode Types +********************/ +#define BTM_SCO_AIR_MODE_U_LAW 0 +#define BTM_SCO_AIR_MODE_A_LAW 1 +#define BTM_SCO_AIR_MODE_CVSD 2 +#define BTM_SCO_AIR_MODE_TRANSPNT 3 +typedef UINT8 tBTM_SCO_AIR_MODE_TYPE; + +/******************* +** SCO Voice Settings +********************/ +#define BTM_VOICE_SETTING_CVSD ((UINT16) (HCI_INP_CODING_LINEAR | \ + HCI_INP_DATA_FMT_2S_COMPLEMENT | \ + HCI_INP_SAMPLE_SIZE_16BIT | \ + HCI_AIR_CODING_FORMAT_CVSD)) + +#define BTM_VOICE_SETTING_TRANS ((UINT16) (HCI_INP_CODING_LINEAR | \ + HCI_INP_DATA_FMT_2S_COMPLEMENT | \ + HCI_INP_SAMPLE_SIZE_16BIT | \ + HCI_AIR_CODING_FORMAT_TRANSPNT)) + +/******************* +** SCO Data Status +********************/ +enum { + BTM_SCO_DATA_CORRECT, + BTM_SCO_DATA_PAR_ERR, + BTM_SCO_DATA_NONE, + BTM_SCO_DATA_PAR_LOST +}; +typedef UINT8 tBTM_SCO_DATA_FLAG; + +/*************************** +** SCO Callback Functions +****************************/ +typedef void (tBTM_SCO_CB) (UINT16 sco_inx); +typedef void (tBTM_SCO_DATA_CB) (UINT16 sco_inx, BT_HDR *p_data, tBTM_SCO_DATA_FLAG status); + +/****************** +** eSCO Constants +*******************/ +#define BTM_64KBITS_RATE 0x00001f40 /* 64 kbits/sec data rate */ + +/* Retransmission effort */ +#define BTM_ESCO_RETRANS_OFF 0 +#define BTM_ESCO_RETRANS_POWER 1 +#define BTM_ESCO_RETRANS_QUALITY 2 +#define BTM_ESCO_RETRANS_DONTCARE 0xff + +/* Max Latency Don't Care */ +#define BTM_ESCO_MAX_LAT_DONTCARE 0xffff + +/*************** +** eSCO Types +****************/ +/* tBTM_ESCO_CBACK event types */ +#define BTM_ESCO_CHG_EVT 1 +#define BTM_ESCO_CONN_REQ_EVT 2 +typedef UINT8 tBTM_ESCO_EVT; + +/* Passed into BTM_SetEScoMode() */ +typedef struct { + UINT32 tx_bw; + UINT32 rx_bw; + UINT16 max_latency; + UINT16 voice_contfmt; /* Voice Settings or Content Format */ + UINT16 packet_types; + UINT8 retrans_effort; +} tBTM_ESCO_PARAMS; + +typedef struct { + UINT16 max_latency; + UINT16 packet_types; + UINT8 retrans_effort; +} tBTM_CHG_ESCO_PARAMS; + +/* Returned by BTM_ReadEScoLinkParms() */ +typedef struct { + UINT16 rx_pkt_len; + UINT16 tx_pkt_len; + BD_ADDR bd_addr; + UINT8 link_type; /* BTM_LINK_TYPE_SCO or BTM_LINK_TYPE_ESCO */ + UINT8 tx_interval; + UINT8 retrans_window; + UINT8 air_mode; +} tBTM_ESCO_DATA; + +typedef struct { + UINT16 sco_inx; + UINT16 rx_pkt_len; + UINT16 tx_pkt_len; + BD_ADDR bd_addr; + UINT8 hci_status; + UINT8 tx_interval; + UINT8 retrans_window; +} tBTM_CHG_ESCO_EVT_DATA; + +typedef struct { + UINT16 sco_inx; + BD_ADDR bd_addr; + DEV_CLASS dev_class; + tBTM_SCO_TYPE link_type; +} tBTM_ESCO_CONN_REQ_EVT_DATA; + +typedef union { + tBTM_CHG_ESCO_EVT_DATA chg_evt; + tBTM_ESCO_CONN_REQ_EVT_DATA conn_evt; +} tBTM_ESCO_EVT_DATA; + +/*************************** +** eSCO Callback Functions +****************************/ +typedef void (tBTM_ESCO_CBACK) (tBTM_ESCO_EVT event, tBTM_ESCO_EVT_DATA *p_data); + + +/***************************************************************************** +** SECURITY MANAGEMENT +*****************************************************************************/ +/******************************* +** Security Manager Constants +********************************/ + +/* Security Mode (BTM_SetSecurityMode) */ +#define BTM_SEC_MODE_UNDEFINED 0 +#define BTM_SEC_MODE_NONE 1 +#define BTM_SEC_MODE_SERVICE 2 +#define BTM_SEC_MODE_LINK 3 +#define BTM_SEC_MODE_SP 4 +#define BTM_SEC_MODE_SP_DEBUG 5 +#define BTM_SEC_MODE_SC 6 + +/* Maximum Number of BTM Security Modes */ +#define BTM_SEC_MODES_MAX 7 + +/* Security Service Levels [bit mask] (BTM_SetSecurityLevel) +** Encryption should not be used without authentication +*/ +#define BTM_SEC_NONE 0x0000 /* Nothing required */ +#define BTM_SEC_IN_AUTHORIZE 0x0001 /* Inbound call requires authorization */ +#define BTM_SEC_IN_AUTHENTICATE 0x0002 /* Inbound call requires authentication */ +#define BTM_SEC_IN_ENCRYPT 0x0004 /* Inbound call requires encryption */ +#define BTM_SEC_OUT_AUTHORIZE 0x0008 /* Outbound call requires authorization */ +#define BTM_SEC_OUT_AUTHENTICATE 0x0010 /* Outbound call requires authentication */ +#define BTM_SEC_OUT_ENCRYPT 0x0020 /* Outbound call requires encryption */ +#define BTM_SEC_MODE4_LEVEL4 0x0040 /* Secure Connections Only Mode */ +#define BTM_SEC_FORCE_MASTER 0x0100 /* Need to switch connection to be master */ +#define BTM_SEC_ATTEMPT_MASTER 0x0200 /* Try to switch connection to be master */ +#define BTM_SEC_FORCE_SLAVE 0x0400 /* Need to switch connection to be master */ +#define BTM_SEC_ATTEMPT_SLAVE 0x0800 /* Try to switch connection to be slave */ +#define BTM_SEC_IN_MITM 0x1000 /* inbound Do man in the middle protection */ +#define BTM_SEC_OUT_MITM 0x2000 /* outbound Do man in the middle protection */ +#define BTM_SEC_IN_MIN_16_DIGIT_PIN 0x4000 /* enforce a minimum of 16 digit for sec mode 2 */ + +/* Security Flags [bit mask] (BTM_GetSecurityFlags) +*/ +#define BTM_SEC_FLAG_AUTHORIZED 0x01 +#define BTM_SEC_FLAG_AUTHENTICATED 0x02 +#define BTM_SEC_FLAG_ENCRYPTED 0x04 +#define BTM_SEC_FLAG_LKEY_KNOWN 0x10 +#define BTM_SEC_FLAG_LKEY_AUTHED 0x20 + +/* PIN types */ +#define BTM_PIN_TYPE_VARIABLE HCI_PIN_TYPE_VARIABLE +#define BTM_PIN_TYPE_FIXED HCI_PIN_TYPE_FIXED + +/* Link Key types used to generate the new link key. +** returned in link key notification callback function +*/ +#define BTM_LKEY_TYPE_COMBINATION HCI_LKEY_TYPE_COMBINATION +#define BTM_LKEY_TYPE_LOCAL_UNIT HCI_LKEY_TYPE_LOCAL_UNIT +#define BTM_LKEY_TYPE_REMOTE_UNIT HCI_LKEY_TYPE_REMOTE_UNIT +#define BTM_LKEY_TYPE_DEBUG_COMB HCI_LKEY_TYPE_DEBUG_COMB +#define BTM_LKEY_TYPE_UNAUTH_COMB HCI_LKEY_TYPE_UNAUTH_COMB +#define BTM_LKEY_TYPE_AUTH_COMB HCI_LKEY_TYPE_AUTH_COMB +#define BTM_LKEY_TYPE_CHANGED_COMB HCI_LKEY_TYPE_CHANGED_COMB + +#define BTM_LKEY_TYPE_UNAUTH_COMB_P_256 HCI_LKEY_TYPE_UNAUTH_COMB_P_256 +#define BTM_LKEY_TYPE_AUTH_COMB_P_256 HCI_LKEY_TYPE_AUTH_COMB_P_256 + +#define BTM_LTK_DERIVED_LKEY_OFFSET 0x20 /* "easy" requirements for LK derived from LTK */ +#define BTM_LKEY_TYPE_IGNORE 0xff /* used when event is response from + hci return link keys request */ + +typedef UINT8 tBTM_LINK_KEY_TYPE; + +/* Protocol level security (BTM_SetSecurityLevel) */ +#define BTM_SEC_PROTO_L2CAP 0 +#define BTM_SEC_PROTO_SDP 1 +#define BTM_SEC_PROTO_TCS 2 +#define BTM_SEC_PROTO_RFCOMM 3 +#define BTM_SEC_PROTO_OBEX 4 +#define BTM_SEC_PROTO_BNEP 5 +#define BTM_SEC_PROTO_HID 6 /* HID */ +#define BTM_SEC_PROTO_AVDT 7 +#define BTM_SEC_PROTO_MCA 8 + +/* Determine the number of UINT32's necessary for security services */ +#define BTM_SEC_ARRAY_BITS 32 /* Number of bits in each array element */ +#define BTM_SEC_SERVICE_ARRAY_SIZE (((UINT32)BTM_SEC_MAX_SERVICES / BTM_SEC_ARRAY_BITS) + \ + (((UINT32)BTM_SEC_MAX_SERVICES % BTM_SEC_ARRAY_BITS) ? 1 : 0)) + +/* Security service definitions (BTM_SetSecurityLevel) +** Used for Authorization APIs +*/ +#define BTM_SEC_SERVICE_SDP_SERVER 0 +#define BTM_SEC_SERVICE_SERIAL_PORT 1 +#define BTM_SEC_SERVICE_LAN_ACCESS 2 +#define BTM_SEC_SERVICE_DUN 3 +#define BTM_SEC_SERVICE_IRMC_SYNC 4 +#define BTM_SEC_SERVICE_IRMC_SYNC_CMD 5 +#define BTM_SEC_SERVICE_OBEX 6 +#define BTM_SEC_SERVICE_OBEX_FTP 7 +#define BTM_SEC_SERVICE_HEADSET 8 +#define BTM_SEC_SERVICE_CORDLESS 9 +#define BTM_SEC_SERVICE_INTERCOM 10 +#define BTM_SEC_SERVICE_FAX 11 +#define BTM_SEC_SERVICE_HEADSET_AG 12 +#define BTM_SEC_SERVICE_PNP_INFO 13 +#define BTM_SEC_SERVICE_GEN_NET 14 +#define BTM_SEC_SERVICE_GEN_FILE 15 +#define BTM_SEC_SERVICE_GEN_AUDIO 16 +#define BTM_SEC_SERVICE_GEN_TEL 17 +#define BTM_SEC_SERVICE_CTP_DATA 18 +#define BTM_SEC_SERVICE_HCRP_CTRL 19 +#define BTM_SEC_SERVICE_HCRP_DATA 20 +#define BTM_SEC_SERVICE_HCRP_NOTIF 21 +#define BTM_SEC_SERVICE_BPP_JOB 22 +#define BTM_SEC_SERVICE_BPP_STATUS 23 +#define BTM_SEC_SERVICE_BPP_REF 24 +#define BTM_SEC_SERVICE_BNEP_PANU 25 +#define BTM_SEC_SERVICE_BNEP_GN 26 +#define BTM_SEC_SERVICE_BNEP_NAP 27 +#define BTM_SEC_SERVICE_HF_HANDSFREE 28 +#define BTM_SEC_SERVICE_AG_HANDSFREE 29 +#define BTM_SEC_SERVICE_TE_PHONE_ACCESS 30 +#define BTM_SEC_SERVICE_ME_PHONE_ACCESS 31 + +#define BTM_SEC_SERVICE_HIDH_SEC_CTRL 32 +#define BTM_SEC_SERVICE_HIDH_NOSEC_CTRL 33 +#define BTM_SEC_SERVICE_HIDH_INTR 34 +#define BTM_SEC_SERVICE_BIP 35 +#define BTM_SEC_SERVICE_BIP_REF 36 +#define BTM_SEC_SERVICE_AVDTP 37 +#define BTM_SEC_SERVICE_AVDTP_NOSEC 38 +#define BTM_SEC_SERVICE_AVCTP 39 +#define BTM_SEC_SERVICE_SAP 40 +#define BTM_SEC_SERVICE_PBAP 41 +#define BTM_SEC_SERVICE_RFC_MUX 42 +#define BTM_SEC_SERVICE_AVCTP_BROWSE 43 +#define BTM_SEC_SERVICE_MAP 44 +#define BTM_SEC_SERVICE_MAP_NOTIF 45 +#define BTM_SEC_SERVICE_MCAP_CTRL 46 +#define BTM_SEC_SERVICE_MCAP_DATA 47 +#define BTM_SEC_SERVICE_HDP_SNK 48 +#define BTM_SEC_SERVICE_HDP_SRC 49 +#define BTM_SEC_SERVICE_ATT 50 + +/* Update these as services are added */ +#define BTM_SEC_SERVICE_FIRST_EMPTY 51 + +#ifndef BTM_SEC_MAX_SERVICES +#define BTM_SEC_MAX_SERVICES 65 +#endif + +/************************************************************************************************ +** Security Services MACROS handle array of UINT32 bits for more than 32 trusted services +*************************************************************************************************/ +/* MACRO to set the security service bit mask in a bit stream */ +#define BTM_SEC_SET_SERVICE(p, service) (((UINT32 *)(p))[(((UINT32)(service)) / BTM_SEC_ARRAY_BITS)] |= \ + ((UINT32)1 << (((UINT32)(service)) % BTM_SEC_ARRAY_BITS))) + + +/* MACRO to clear the security service bit mask in a bit stream */ +#define BTM_SEC_CLR_SERVICE(p, service) (((UINT32 *)(p))[(((UINT32)(service)) / BTM_SEC_ARRAY_BITS)] &= \ + ~((UINT32)1 << (((UINT32)(service)) % BTM_SEC_ARRAY_BITS))) + +/* MACRO to check the security service bit mask in a bit stream (Returns TRUE or FALSE) */ +#define BTM_SEC_IS_SERVICE_TRUSTED(p, service) (((((UINT32 *)(p))[(((UINT32)(service)) / BTM_SEC_ARRAY_BITS)]) & \ + (UINT32)(((UINT32)1 << (((UINT32)(service)) % BTM_SEC_ARRAY_BITS)))) ? TRUE : FALSE) + +/* MACRO to copy two trusted device bitmask */ +#define BTM_SEC_COPY_TRUSTED_DEVICE(p_src, p_dst) {UINT32 trst; for (trst = 0; trst < BTM_SEC_SERVICE_ARRAY_SIZE; trst++) \ + ((UINT32 *)(p_dst))[trst] = ((UINT32 *)(p_src))[trst];} + +/* MACRO to clear two trusted device bitmask */ +#define BTM_SEC_CLR_TRUSTED_DEVICE(p_dst) {UINT32 trst; for (trst = 0; trst < BTM_SEC_SERVICE_ARRAY_SIZE; trst++) \ + ((UINT32 *)(p_dst))[trst] = 0;} + +/* Following bits can be provided by host in the trusted_mask array */ +/* 0..31 bits of mask[0] (Least Significant Word) */ +#define BTM_SEC_TRUST_SDP_SERVER (1 << BTM_SEC_SERVICE_SDP_SERVER) +#define BTM_SEC_TRUST_SERIAL_PORT (1 << BTM_SEC_SERVICE_SERIAL_PORT) +#define BTM_SEC_TRUST_LAN_ACCESS (1 << BTM_SEC_SERVICE_LAN_ACCESS) +#define BTM_SEC_TRUST_DUN (1 << BTM_SEC_SERVICE_DUN) +#define BTM_SEC_TRUST_IRMC_SYNC (1 << BTM_SEC_SERVICE_IRMC_SYNC) +#define BTM_SEC_TRUST_IRMC_SYNC_CMD (1 << BTM_SEC_SERVICE_IRMC_SYNC_CMD) +#define BTM_SEC_TRUST_OBEX (1 << BTM_SEC_SERVICE_OBEX) +#define BTM_SEC_TRUST_OBEX_FTP (1 << BTM_SEC_SERVICE_OBEX_FTP) +#define BTM_SEC_TRUST_HEADSET (1 << BTM_SEC_SERVICE_HEADSET) +#define BTM_SEC_TRUST_CORDLESS (1 << BTM_SEC_SERVICE_CORDLESS) +#define BTM_SEC_TRUST_INTERCOM (1 << BTM_SEC_SERVICE_INTERCOM) +#define BTM_SEC_TRUST_FAX (1 << BTM_SEC_SERVICE_FAX) +#define BTM_SEC_TRUST_HEADSET_AG (1 << BTM_SEC_SERVICE_HEADSET_AG) +#define BTM_SEC_TRUST_PNP_INFO (1 << BTM_SEC_SERVICE_PNP_INFO) +#define BTM_SEC_TRUST_GEN_NET (1 << BTM_SEC_SERVICE_GEN_NET) +#define BTM_SEC_TRUST_GEN_FILE (1 << BTM_SEC_SERVICE_GEN_FILE) +#define BTM_SEC_TRUST_GEN_AUDIO (1 << BTM_SEC_SERVICE_GEN_AUDIO) +#define BTM_SEC_TRUST_GEN_TEL (1 << BTM_SEC_SERVICE_GEN_TEL) +#define BTM_SEC_TRUST_CTP_DATA (1 << BTM_SEC_SERVICE_CTP_DATA) +#define BTM_SEC_TRUST_HCRP_CTRL (1 << BTM_SEC_SERVICE_HCRP_CTRL) +#define BTM_SEC_TRUST_HCRP_DATA (1 << BTM_SEC_SERVICE_HCRP_DATA) +#define BTM_SEC_TRUST_HCRP_NOTIF (1 << BTM_SEC_SERVICE_HCRP_NOTIF) +#define BTM_SEC_TRUST_BPP_JOB (1 << BTM_SEC_SERVICE_JOB) +#define BTM_SEC_TRUST_BPP_STATUS (1 << BTM_SEC_SERVICE_STATUS) +#define BTM_SEC_TRUST_BPP_REF (1 << BTM_SEC_SERVICE_REF) +#define BTM_SEC_TRUST_BNEP_PANU (1 << BTM_SEC_SERVICE_BNEP_PANU) +#define BTM_SEC_TRUST_BNEP_GN (1 << BTM_SEC_SERVICE_BNEP_GN) +#define BTM_SEC_TRUST_BNEP_NAP (1 << BTM_SEC_SERVICE_BNEP_NAP) +#define BTM_SEC_TRUST_HFP_HF (1 << BTM_SEC_SERVICE_HF_HANDSFREE) +#define BTM_SEC_TRUST_HFP_AG (1 << BTM_SEC_SERVICE_AG_HANDSFREE) +#define BTM_SEC_TRUST_TE_PHONE_ACCESS (1 << BTM_SEC_SERVICE_TE_PHONE_ACCESS) +#define BTM_SEC_TRUST_ME_PHONE_ACCESS (1 << BTM_SEC_SERVICE_ME_PHONE_ACCESS) + +/* 0..31 bits of mask[1] (Most Significant Word) */ +#define BTM_SEC_TRUST_HIDH_CTRL (1 << (BTM_SEC_SERVICE_HIDH_SEC_CTRL - 32)) +#define BTM_SEC_TRUST_HIDH_NOSEC_CTRL (1 << (BTM_SEC_SERVICE_HIDH_NOSEC_CTRL - 32)) +#define BTM_SEC_TRUST_HIDH_INTR (1 << (BTM_SEC_SERVICE_HIDH_INTR - 32)) +#define BTM_SEC_TRUST_BIP (1 << (BTM_SEC_SERVICE_BIP - 32)) +#define BTM_SEC_TRUST_BIP_REF (1 << (BTM_SEC_SERVICE_BIP_REF - 32)) +#define BTM_SEC_TRUST_AVDTP (1 << (BTM_SEC_SERVICE_AVDTP - 32)) +#define BTM_SEC_TRUST_AVDTP_NOSEC (1 << (BTM_SEC_SERVICE_AVDTP_NOSEC - 32)) +#define BTM_SEC_TRUST_AVCTP (1 << (BTM_SEC_SERVICE_AVCTP - 32)) +#define BTM_SEC_TRUST_SAP (1 << (BTM_SEC_SERVICE_SAP - 32)) +#define BTM_SEC_TRUST_PBAP (1 << (BTM_SEC_SERVICE_PBAP - 32)) +#define BTM_SEC_TRUST_RFC_MUX (1 << (BTM_SEC_SERVICE_RFC_MUX - 32)) +#define BTM_SEC_TRUST_AVCTP_BROWSE (1 << (BTM_SEC_SERVICE_AVCTP_BROWSE - 32)) +#define BTM_SEC_TRUST_MAP (1 << (BTM_SEC_SERVICE_MAP - 32)) +#define BTM_SEC_TRUST_MAP_NOTIF (1 << (BTM_SEC_SERVICE_MAP_NOTIF - 32)) +#define BTM_SEC_TRUST_MCAP_CTRL (1 << (BTM_SEC_SERVICE_MCAP_CTRL - 32)) +#define BTM_SEC_TRUST_MCAP_DATA (1 << (BTM_SEC_SERVICE_MCAP_DATA - 32)) +#define BTM_SEC_TRUST_HDP_SNK (1 << (BTM_SEC_SERVICE_HDP_SNK - 32)) +#define BTM_SEC_TRUST_HDP_SRC (1 << (BTM_SEC_SERVICE_HDP_SRC - 32)) + +#define BTM_SEC_TRUST_ALL 0xFFFFFFFF /* for each array element */ + +/**************************************** +** Security Manager Callback Functions +*****************************************/ +/* Authorize device for service. Parameters are +** BD Address of remote +** Device Class of remote +** BD Name of remote +** Service name +** Service Id (NULL - unknown service or unused +** [BTM_SEC_SERVICE_NAME_LEN set to 0]) +** Is originator of the connection +** Result of the operation +*/ +typedef UINT8 (tBTM_AUTHORIZE_CALLBACK) (BD_ADDR bd_addr, DEV_CLASS dev_class, + tBTM_BD_NAME bd_name, UINT8 *service_name, + UINT8 service_id, BOOLEAN is_originator); + +/* Get PIN for the connection. Parameters are +** BD Address of remote +** Device Class of remote +** BD Name of remote +** Flag indicating the minimum pin code length to be 16 digits +*/ +typedef UINT8 (tBTM_PIN_CALLBACK) (BD_ADDR bd_addr, DEV_CLASS dev_class, + tBTM_BD_NAME bd_name, BOOLEAN min_16_digit); + +/* New Link Key for the connection. Parameters are +** BD Address of remote +** Link Key +** Key Type: Combination, Local Unit, or Remote Unit +*/ +typedef UINT8 (tBTM_LINK_KEY_CALLBACK) (BD_ADDR bd_addr, DEV_CLASS dev_class, + tBTM_BD_NAME bd_name, UINT8 *key, + UINT8 key_type); + + +/* Remote Name Resolved. Parameters are +** BD Address of remote +** BD Name of remote +*/ +typedef void (tBTM_RMT_NAME_CALLBACK) (BD_ADDR bd_addr, DEV_CLASS dc, + tBTM_BD_NAME bd_name); + + +/* Authentication complete for the connection. Parameters are +** BD Address of remote +** Device Class of remote +** BD Name of remote +** +*/ +typedef UINT8 (tBTM_AUTH_COMPLETE_CALLBACK) (BD_ADDR bd_addr, DEV_CLASS dev_class, + tBTM_BD_NAME bd_name, int result); + +enum { + BTM_SP_IO_REQ_EVT, /* received IO_CAPABILITY_REQUEST event */ + BTM_SP_IO_RSP_EVT, /* received IO_CAPABILITY_RESPONSE event */ + BTM_SP_CFM_REQ_EVT, /* received USER_CONFIRMATION_REQUEST event */ + BTM_SP_KEY_NOTIF_EVT, /* received USER_PASSKEY_NOTIFY event */ + BTM_SP_KEY_REQ_EVT, /* received USER_PASSKEY_REQUEST event */ + BTM_SP_KEYPRESS_EVT, /* received KEYPRESS_NOTIFY event */ + BTM_SP_LOC_OOB_EVT, /* received result for READ_LOCAL_OOB_DATA command */ + BTM_SP_RMT_OOB_EVT, /* received REMOTE_OOB_DATA_REQUEST event */ + BTM_SP_COMPLT_EVT, /* received SIMPLE_PAIRING_COMPLETE event */ + BTM_SP_UPGRADE_EVT /* check if the application wants to upgrade the link key */ +}; +typedef UINT8 tBTM_SP_EVT; + +#define BTM_IO_CAP_OUT 0 /* DisplayOnly */ +#define BTM_IO_CAP_IO 1 /* DisplayYesNo */ +#define BTM_IO_CAP_IN 2 /* KeyboardOnly */ +#define BTM_IO_CAP_NONE 3 /* NoInputNoOutput */ +#if BLE_INCLUDED == TRUE && SMP_INCLUDED == TRUE +#define BTM_IO_CAP_KBDISP 4 /* Keyboard display */ +#define BTM_IO_CAP_MAX 5 +#else +#define BTM_IO_CAP_MAX 4 +#endif + +typedef UINT8 tBTM_IO_CAP; + +#define BTM_MAX_PASSKEY_VAL (999999) +#define BTM_MIN_PASSKEY_VAL (0) + +#define BTM_AUTH_SP_NO 0 /* MITM Protection Not Required - Single Profile/non-bonding + Numeric comparison with automatic accept allowed */ +#define BTM_AUTH_SP_YES 1 /* MITM Protection Required - Single Profile/non-bonding + Use IO Capabilities to determine authentication procedure */ +#define BTM_AUTH_AP_NO 2 /* MITM Protection Not Required - All Profiles/dedicated bonding + Numeric comparison with automatic accept allowed */ +#define BTM_AUTH_AP_YES 3 /* MITM Protection Required - All Profiles/dedicated bonding + Use IO Capabilities to determine authentication procedure */ +#define BTM_AUTH_SPGB_NO 4 /* MITM Protection Not Required - Single Profiles/general bonding + Numeric comparison with automatic accept allowed */ +#define BTM_AUTH_SPGB_YES 5 /* MITM Protection Required - Single Profiles/general bonding + Use IO Capabilities to determine authentication procedure */ +#define BTM_AUTH_DD_BOND 2 /* this bit is ORed to the BTM_AUTH_SP_* when IO exchange for dedicated bonding */ +#define BTM_AUTH_GB_BIT 4 /* the genernal bonding bit */ +#define BTM_AUTH_BONDS 6 /* the general/dedicated bonding bits */ +#define BTM_AUTH_YN_BIT 1 /* this is the Yes or No bit */ + +#define BTM_BLE_INITIATOR_KEY_SIZE 15 +#define BTM_BLE_RESPONDER_KEY_SIZE 15 +#define BTM_BLE_MAX_KEY_SIZE 16 + +typedef UINT8 tBTM_AUTH_REQ; + +enum { + BTM_OOB_NONE, + BTM_OOB_PRESENT +#if BTM_OOB_INCLUDED == TRUE + , BTM_OOB_UNKNOWN +#endif +}; +typedef UINT8 tBTM_OOB_DATA; + +/* data type for BTM_SP_IO_REQ_EVT */ +typedef struct { + BD_ADDR bd_addr; /* peer address */ + tBTM_IO_CAP io_cap; /* local IO capabilities */ + tBTM_OOB_DATA oob_data; /* OOB data present (locally) for the peer device */ + tBTM_AUTH_REQ auth_req; /* Authentication required (for local device) */ + BOOLEAN is_orig; /* TRUE, if local device initiated the SP process */ +} tBTM_SP_IO_REQ; + +/* data type for BTM_SP_IO_RSP_EVT */ +typedef struct { + BD_ADDR bd_addr; /* peer address */ + tBTM_IO_CAP io_cap; /* peer IO capabilities */ + tBTM_OOB_DATA oob_data; /* OOB data present at peer device for the local device */ + tBTM_AUTH_REQ auth_req; /* Authentication required for peer device */ +} tBTM_SP_IO_RSP; + +/* data type for BTM_SP_CFM_REQ_EVT */ +typedef struct { + BD_ADDR bd_addr; /* peer address */ + DEV_CLASS dev_class; /* peer CoD */ + tBTM_BD_NAME bd_name; /* peer device name */ + UINT32 num_val; /* the numeric value for comparison. If just_works, do not show this number to UI */ + BOOLEAN just_works; /* TRUE, if "Just Works" association model */ + tBTM_AUTH_REQ loc_auth_req; /* Authentication required for local device */ + tBTM_AUTH_REQ rmt_auth_req; /* Authentication required for peer device */ + tBTM_IO_CAP loc_io_caps; /* IO Capabilities of the local device */ + tBTM_IO_CAP rmt_io_caps; /* IO Capabilities of the remot device */ +} tBTM_SP_CFM_REQ; + +/* data type for BTM_SP_KEY_REQ_EVT */ +typedef struct { + BD_ADDR bd_addr; /* peer address */ + DEV_CLASS dev_class; /* peer CoD */ + tBTM_BD_NAME bd_name; /* peer device name */ +} tBTM_SP_KEY_REQ; + +/* data type for BTM_SP_KEY_NOTIF_EVT */ +typedef struct { + BD_ADDR bd_addr; /* peer address */ + DEV_CLASS dev_class; /* peer CoD */ + tBTM_BD_NAME bd_name; /* peer device name */ + UINT32 passkey; /* passkey */ +} tBTM_SP_KEY_NOTIF; + +enum { + BTM_SP_KEY_STARTED, /* 0 - passkey entry started */ + BTM_SP_KEY_ENTERED, /* 1 - passkey digit entered */ + BTM_SP_KEY_ERASED, /* 2 - passkey digit erased */ + BTM_SP_KEY_CLEARED, /* 3 - passkey cleared */ + BTM_SP_KEY_COMPLT, /* 4 - passkey entry completed */ + BTM_SP_KEY_OUT_OF_RANGE /* 5 - out of range */ +}; +typedef UINT8 tBTM_SP_KEY_TYPE; + +/* data type for BTM_SP_KEYPRESS_EVT */ +typedef struct { + BD_ADDR bd_addr; /* peer address */ + tBTM_SP_KEY_TYPE notif_type; +} tBTM_SP_KEYPRESS; + +/* data type for BTM_SP_LOC_OOB_EVT */ +typedef struct { + tBTM_STATUS status; /* */ + BT_OCTET16 c; /* Simple Pairing Hash C */ + BT_OCTET16 r; /* Simple Pairing Randomnizer R */ +} tBTM_SP_LOC_OOB; + +/* data type for BTM_SP_RMT_OOB_EVT */ +typedef struct { + BD_ADDR bd_addr; /* peer address */ + DEV_CLASS dev_class; /* peer CoD */ + tBTM_BD_NAME bd_name; /* peer device name */ +} tBTM_SP_RMT_OOB; + + +/* data type for BTM_SP_COMPLT_EVT */ +typedef struct { + BD_ADDR bd_addr; /* peer address */ + DEV_CLASS dev_class; /* peer CoD */ + tBTM_BD_NAME bd_name; /* peer device name */ + tBTM_STATUS status; /* status of the simple pairing process */ +} tBTM_SP_COMPLT; + +/* data type for BTM_SP_UPGRADE_EVT */ +typedef struct { + BD_ADDR bd_addr; /* peer address */ + BOOLEAN upgrade; /* TRUE, to upgrade the link key */ +} tBTM_SP_UPGRADE; + +typedef union { + tBTM_SP_IO_REQ io_req; /* BTM_SP_IO_REQ_EVT */ + tBTM_SP_IO_RSP io_rsp; /* BTM_SP_IO_RSP_EVT */ + tBTM_SP_CFM_REQ cfm_req; /* BTM_SP_CFM_REQ_EVT */ + tBTM_SP_KEY_NOTIF key_notif; /* BTM_SP_KEY_NOTIF_EVT */ + tBTM_SP_KEY_REQ key_req; /* BTM_SP_KEY_REQ_EVT */ + tBTM_SP_KEYPRESS key_press; /* BTM_SP_KEYPRESS_EVT */ + tBTM_SP_LOC_OOB loc_oob; /* BTM_SP_LOC_OOB_EVT */ + tBTM_SP_RMT_OOB rmt_oob; /* BTM_SP_RMT_OOB_EVT */ + tBTM_SP_COMPLT complt; /* BTM_SP_COMPLT_EVT */ + tBTM_SP_UPGRADE upgrade; /* BTM_SP_UPGRADE_EVT */ +} tBTM_SP_EVT_DATA; + +/* Simple Pairing Events. Called by the stack when Simple Pairing related +** events occur. +*/ +typedef UINT8 (tBTM_SP_CALLBACK) (tBTM_SP_EVT event, tBTM_SP_EVT_DATA *p_data); + + +typedef void (tBTM_MKEY_CALLBACK) (BD_ADDR bd_addr, UINT8 status, UINT8 key_flag) ; + +/* Encryption enabled/disabled complete: Optionally passed with BTM_SetEncryption. +** Parameters are +** BD Address of remote +** optional data passed in by BTM_SetEncryption +** tBTM_STATUS - result of the operation +*/ +typedef void (tBTM_SEC_CBACK) (BD_ADDR bd_addr, tBT_TRANSPORT trasnport, + void *p_ref_data, tBTM_STATUS result); + +/* Bond Cancel complete. Parameters are +** Result of the cancel operation +** +*/ +typedef void (tBTM_BOND_CANCEL_CMPL_CALLBACK) (tBTM_STATUS result); + +/* LE related event and data structure +*/ +#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 */ +#define BTM_LE_KEY_NOTIF_EVT SMP_PASSKEY_NOTIF_EVT /* received USER_PASSKEY_NOTIFY event */ +#define BTM_LE_KEY_REQ_EVT SMP_PASSKEY_REQ_EVT /* received USER_PASSKEY_REQUEST event */ +#define BTM_LE_OOB_REQ_EVT SMP_OOB_REQ_EVT /* OOB data request event */ +#define BTM_LE_NC_REQ_EVT SMP_NC_REQ_EVT /* Numeric Comparison request event */ +#define BTM_LE_PR_KEYPR_NOT_EVT SMP_PEER_KEYPR_NOT_EVT /* Peer keypress notification recd event */ +/* SC OOB request event (both local and peer OOB data) can be expected in response */ +#define BTM_LE_SC_OOB_REQ_EVT SMP_SC_OOB_REQ_EVT +/* SC OOB local data set is created (as result of SMP_CrLocScOobData(...)) */ +#define BTM_LE_SC_LOC_OOB_EVT SMP_SC_LOC_OOB_DATA_UP_EVT +#define BTM_LE_BR_KEYS_REQ_EVT SMP_BR_KEYS_REQ_EVT /* SMP over BR keys request event */ +#define BTM_LE_COMPLT_EVT SMP_COMPLT_EVT /* SMP complete event */ +#define BTM_LE_LAST_FROM_SMP BTM_LE_BR_KEYS_REQ_EVT +#define BTM_LE_KEY_EVT BTM_LE_LAST_FROM_SMP + 1 /* KEY update event */ +typedef UINT8 tBTM_LE_EVT; + +#define BTM_LE_KEY_NONE 0 +#define BTM_LE_KEY_PENC SMP_SEC_KEY_TYPE_ENC /* encryption information of peer device */ +#define BTM_LE_KEY_PID SMP_SEC_KEY_TYPE_ID /* identity key of the peer device */ +#define BTM_LE_KEY_PCSRK SMP_SEC_KEY_TYPE_CSRK /* peer SRK */ +#define BTM_LE_KEY_PLK SMP_SEC_KEY_TYPE_LK +#define BTM_LE_KEY_LLK (SMP_SEC_KEY_TYPE_LK << 4) +#define BTM_LE_KEY_LENC (SMP_SEC_KEY_TYPE_ENC << 4) /* master role security information:div */ +#define BTM_LE_KEY_LID (SMP_SEC_KEY_TYPE_ID << 4) /* master device ID key */ +#define BTM_LE_KEY_LCSRK (SMP_SEC_KEY_TYPE_CSRK << 4) /* local CSRK has been deliver to peer */ +typedef UINT8 tBTM_LE_KEY_TYPE; + +#define BTM_LE_AUTH_REQ_NO_BOND SMP_AUTH_NO_BOND /* 0 */ +#define BTM_LE_AUTH_REQ_BOND SMP_AUTH_GEN_BOND /* 1 << 0 */ +#define BTM_LE_AUTH_REQ_MITM SMP_AUTH_YN_BIT /* 1 << 2 */ +typedef UINT8 tBTM_LE_AUTH_REQ; +#define BTM_LE_SC_SUPPORT_BIT SMP_SC_SUPPORT_BIT /* (1 << 3) */ +#define BTM_LE_KP_SUPPORT_BIT SMP_KP_SUPPORT_BIT /* (1 << 4) */ + +#define BTM_LE_AUTH_REQ_SC_ONLY SMP_AUTH_SC_ENC_ONLY /* 1 << 3 */ +#define BTM_LE_AUTH_REQ_SC_BOND SMP_AUTH_SC_GB /* 1001 */ +#define BTM_LE_AUTH_REQ_SC_MITM SMP_AUTH_SC_MITM_NB /* 1100 */ +#define BTM_LE_AUTH_REQ_SC_MITM_BOND SMP_AUTH_SC_MITM_GB /* 1101 */ +#define BTM_LE_AUTH_REQ_MASK SMP_AUTH_MASK /* 0x1D */ + +/* LE security level */ +#define BTM_LE_SEC_NONE SMP_SEC_NONE +#define BTM_LE_SEC_UNAUTHENTICATE SMP_SEC_UNAUTHENTICATE /* 1 */ +#define BTM_LE_SEC_AUTHENTICATED SMP_SEC_AUTHENTICATED /* 4 */ +typedef UINT8 tBTM_LE_SEC; + + +typedef struct { + tBTM_IO_CAP io_cap; /* local IO capabilities */ + UINT8 oob_data; /* OOB data present (locally) for the peer device */ + tBTM_LE_AUTH_REQ auth_req; /* Authentication request (for local device) contain bonding and MITM info */ + UINT8 max_key_size; /* max encryption key size */ + tBTM_LE_KEY_TYPE init_keys; /* keys to be distributed, bit mask */ + tBTM_LE_KEY_TYPE resp_keys; /* keys to be distributed, bit mask */ +} tBTM_LE_IO_REQ; + +#if BLE_INCLUDED == TRUE && SMP_INCLUDED == TRUE +/* data type for tBTM_LE_COMPLT */ +typedef struct { + UINT8 reason; + UINT8 sec_level; + BOOLEAN is_pair_cancel; + BOOLEAN smp_over_br; +} tBTM_LE_COMPLT; +#endif + +/* BLE encryption keys */ +typedef struct { + BT_OCTET16 ltk; + BT_OCTET8 rand; + UINT16 ediv; + UINT8 sec_level; + UINT8 key_size; +} tBTM_LE_PENC_KEYS; + +/* BLE CSRK keys */ +typedef struct { + UINT32 counter; + BT_OCTET16 csrk; + UINT8 sec_level; +} tBTM_LE_PCSRK_KEYS; + +/* BLE Encryption reproduction keys */ +typedef struct { + BT_OCTET16 ltk; + UINT16 div; + UINT8 key_size; + UINT8 sec_level; +} tBTM_LE_LENC_KEYS; + +/* BLE SRK keys */ +typedef struct { + UINT32 counter; + UINT16 div; + UINT8 sec_level; + BT_OCTET16 csrk; +} tBTM_LE_LCSRK_KEYS; + +typedef struct { + BT_OCTET16 irk; + tBLE_ADDR_TYPE addr_type; + BD_ADDR static_addr; +} tBTM_LE_PID_KEYS; + +typedef union { + tBTM_LE_PENC_KEYS penc_key; /* received peer encryption key */ + tBTM_LE_PCSRK_KEYS pcsrk_key; /* received peer device SRK */ + tBTM_LE_PID_KEYS pid_key; /* peer device ID key */ + tBTM_LE_LENC_KEYS lenc_key; /* local encryption reproduction keys LTK = = d1(ER,DIV,0)*/ + tBTM_LE_LCSRK_KEYS lcsrk_key; /* local device CSRK = d1(ER,DIV,1)*/ +} tBTM_LE_KEY_VALUE; + +typedef struct { + tBTM_LE_KEY_TYPE key_type; + tBTM_LE_KEY_VALUE *p_key_value; +} tBTM_LE_KEY; + +typedef union { + tBTM_LE_IO_REQ io_req; /* BTM_LE_IO_REQ_EVT */ + UINT32 key_notif; /* BTM_LE_KEY_NOTIF_EVT */ + /* BTM_LE_NC_REQ_EVT */ + /* no callback data for BTM_LE_KEY_REQ_EVT */ + /* and BTM_LE_OOB_REQ_EVT */ +#if BLE_INCLUDED == TRUE && SMP_INCLUDED == TRUE + tBTM_LE_COMPLT complt; /* BTM_LE_COMPLT_EVT */ + tSMP_OOB_DATA_TYPE req_oob_type; +#endif + tBTM_LE_KEY key; +} tBTM_LE_EVT_DATA; + +/* Simple Pairing Events. Called by the stack when Simple Pairing related +** events occur. +*/ +typedef UINT8 (tBTM_LE_CALLBACK) (tBTM_LE_EVT event, BD_ADDR bda, tBTM_LE_EVT_DATA *p_data); + +#define BTM_BLE_KEY_TYPE_ID 1 +#define BTM_BLE_KEY_TYPE_ER 2 +#define BTM_BLE_KEY_TYPE_COUNTER 3 //tobe obsolete + +typedef struct { + BT_OCTET16 ir; + BT_OCTET16 irk; + BT_OCTET16 dhk; + +} tBTM_BLE_LOCAL_ID_KEYS; + +typedef union { + tBTM_BLE_LOCAL_ID_KEYS id_keys; + BT_OCTET16 er; +} tBTM_BLE_LOCAL_KEYS; + + +/* New LE identity key for local device. +*/ +typedef void (tBTM_LE_KEY_CALLBACK) (UINT8 key_type, tBTM_BLE_LOCAL_KEYS *p_key); + + +/*************************** +** Security Manager Types +****************************/ +/* Structure that applications use to register with BTM_SecRegister */ +typedef struct { + tBTM_AUTHORIZE_CALLBACK *p_authorize_callback; + tBTM_PIN_CALLBACK *p_pin_callback; + tBTM_LINK_KEY_CALLBACK *p_link_key_callback; + tBTM_AUTH_COMPLETE_CALLBACK *p_auth_complete_callback; + tBTM_BOND_CANCEL_CMPL_CALLBACK *p_bond_cancel_cmpl_callback; + tBTM_SP_CALLBACK *p_sp_callback; +#if BLE_INCLUDED == TRUE +#if SMP_INCLUDED == TRUE + tBTM_LE_CALLBACK *p_le_callback; +#endif + tBTM_LE_KEY_CALLBACK *p_le_key_callback; +#endif +} tBTM_APPL_INFO; + +/* Callback function for when a link supervision timeout event occurs. +** This asynchronous event is enabled/disabled by calling BTM_RegForLstoEvt(). +*/ +typedef void (tBTM_LSTO_CBACK) (BD_ADDR remote_bda, UINT16 timeout); + +/***************************************************************************** +** POWER MANAGEMENT +*****************************************************************************/ +/**************************** +** Power Manager Constants +*****************************/ +/* BTM Power manager status codes */ +enum { + BTM_PM_STS_ACTIVE = HCI_MODE_ACTIVE, + BTM_PM_STS_HOLD = HCI_MODE_HOLD, + BTM_PM_STS_SNIFF = HCI_MODE_SNIFF, + BTM_PM_STS_PARK = HCI_MODE_PARK, + BTM_PM_STS_SSR, /* report the SSR parameters in HCI_SNIFF_SUB_RATE_EVT */ + BTM_PM_STS_PENDING, /* when waiting for status from controller */ + BTM_PM_STS_ERROR /* when HCI command status returns error */ +}; +typedef UINT8 tBTM_PM_STATUS; + +/* BTM Power manager modes */ +enum { + BTM_PM_MD_ACTIVE = BTM_PM_STS_ACTIVE, + BTM_PM_MD_HOLD = BTM_PM_STS_HOLD, + BTM_PM_MD_SNIFF = BTM_PM_STS_SNIFF, + BTM_PM_MD_PARK = BTM_PM_STS_PARK, + BTM_PM_MD_FORCE = 0x10 /* OR this to force ACL link to a certain mode */ +}; +typedef UINT8 tBTM_PM_MODE; + +#define BTM_PM_SET_ONLY_ID 0x80 + +/* Operation codes */ +#define BTM_PM_REG_SET 1 /* The module wants to set the desired power mode */ +#define BTM_PM_REG_NOTIF 2 /* The module wants to receive mode change event */ +#define BTM_PM_DEREG 4 /* The module does not want to involve with PM anymore */ + +/************************ +** Power Manager Types +*************************/ +typedef struct { + UINT16 max; + UINT16 min; + UINT16 attempt; + UINT16 timeout; + tBTM_PM_MODE mode; +} tBTM_PM_PWR_MD; + +/************************************* +** Power Manager Callback Functions +**************************************/ +typedef void (tBTM_PM_STATUS_CBACK) (BD_ADDR p_bda, tBTM_PM_STATUS status, + UINT16 value, UINT8 hci_status); + + +/************************ +** Stored Linkkey Types +*************************/ +#define BTM_CB_EVT_DELETE_STORED_LINK_KEYS 4 + +typedef struct { + UINT8 event; + UINT8 status; + UINT16 num_keys; + +} tBTM_DELETE_STORED_LINK_KEY_COMPLETE; + +/* MIP evnets, callbacks */ +enum { + BTM_MIP_MODE_CHG_EVT, + BTM_MIP_DISCONNECT_EVT, + BTM_MIP_PKTS_COMPL_EVT, + BTM_MIP_RXDATA_EVT +}; +typedef UINT8 tBTM_MIP_EVT; + +typedef struct { + tBTM_MIP_EVT event; + BD_ADDR bd_addr; + UINT16 mip_id; +} tBTM_MIP_MODE_CHANGE; + +typedef struct { + tBTM_MIP_EVT event; + UINT16 mip_id; + UINT8 disc_reason; +} tBTM_MIP_CONN_TIMEOUT; + +#define BTM_MIP_MAX_RX_LEN 17 + +typedef struct { + tBTM_MIP_EVT event; + UINT16 mip_id; + UINT8 rx_len; + UINT8 rx_data[BTM_MIP_MAX_RX_LEN]; +} tBTM_MIP_RXDATA; + +typedef struct { + tBTM_MIP_EVT event; + BD_ADDR bd_addr; + UINT8 data[11]; /* data[0] shows Vender-specific device type */ +} tBTM_MIP_EIR_HANDSHAKE; + +typedef struct { + tBTM_MIP_EVT event; + UINT16 num_sent; /* Number of packets completed at the controller */ +} tBTM_MIP_PKTS_COMPL; + +typedef union { + tBTM_MIP_EVT event; + tBTM_MIP_MODE_CHANGE mod_chg; + tBTM_MIP_CONN_TIMEOUT conn_tmo; + tBTM_MIP_EIR_HANDSHAKE eir; + tBTM_MIP_PKTS_COMPL completed; + tBTM_MIP_RXDATA rxdata; +} tBTM_MIP_EVENT_DATA; + +/* MIP event callback function */ +typedef void (tBTM_MIP_EVENTS_CB) (tBTM_MIP_EVT event, tBTM_MIP_EVENT_DATA data); + +/* MIP Device query callback function */ +typedef BOOLEAN (tBTM_MIP_QUERY_CB) (BD_ADDR dev_addr, UINT8 *p_mode, LINK_KEY link_key); + +#define BTM_CONTRL_ACTIVE 1 /* ACL link on, SCO link ongoing, sniff mode */ +#define BTM_CONTRL_SCAN 2 /* Scan state - paging/inquiry/trying to connect*/ +#define BTM_CONTRL_IDLE 3 /* Idle state - page scan, LE advt, inquiry scan */ + +typedef UINT8 tBTM_CONTRL_STATE; + +/***************************************************************************** +** EXTERNAL FUNCTION DECLARATIONS +*****************************************************************************/ +/* +#ifdef __cplusplus +extern "C" { +#endif +*/ +/***************************************************************************** +** DEVICE CONTROL and COMMON FUNCTIONS +*****************************************************************************/ + +/******************************************************************************* +** +** Function BTM_DeviceReset +** +** Description This function is called to reset the controller.The Callback function +** if provided is called when startup of the device has +** completed. +** +** Returns void +** +*******************************************************************************/ +//extern +void BTM_DeviceReset (tBTM_CMPL_CB *p_cb); + + +/******************************************************************************* +** +** Function BTM_IsDeviceUp +** +** Description This function is called to check if the device is up. +** +** Returns TRUE if device is up, else FALSE +** +*******************************************************************************/ +//extern +BOOLEAN BTM_IsDeviceUp (void); + + +/******************************************************************************* +** +** Function BTM_SetLocalDeviceName +** +** Description This function is called to set the local device name. +** +** Returns BTM_CMD_STARTED if successful, otherwise an error +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_SetLocalDeviceName (char *p_name); + +/******************************************************************************* +** +** Function BTM_SetDeviceClass +** +** Description This function is called to set the local device class +** +** Returns BTM_SUCCESS if successful, otherwise an error +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_SetDeviceClass (DEV_CLASS dev_class); + + +/******************************************************************************* +** +** Function BTM_ReadLocalDeviceName +** +** Description This function is called to read the local device name. +** +** Returns status of the operation +** If success, BTM_SUCCESS is returned and p_name points stored +** local device name +** If BTM doesn't store local device name, BTM_NO_RESOURCES is +** is returned and p_name is set to NULL +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_ReadLocalDeviceName (char **p_name); + +/******************************************************************************* +** +** Function BTM_ReadLocalDeviceNameFromController +** +** Description Get local device name from controller. Do not use cached +** name (used to get chip-id prior to btm reset complete). +** +** Returns BTM_CMD_STARTED if successful, otherwise an error +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_ReadLocalDeviceNameFromController (tBTM_CMPL_CB *p_rln_cmpl_cback); + +/******************************************************************************* +** +** Function BTM_ReadDeviceClass +** +** Description This function is called to read the local device class +** +** Returns pointer to the device class +** +*******************************************************************************/ +//extern +UINT8 *BTM_ReadDeviceClass (void); + + +/******************************************************************************* +** +** Function BTM_ReadLocalFeatures +** +** Description This function is called to read the local features +** +** Returns pointer to the local features string +** +*******************************************************************************/ +//extern +UINT8 *BTM_ReadLocalFeatures (void); + +/******************************************************************************* +** +** Function BTM_RegisterForDeviceStatusNotif +** +** Description This function is called to register for device status +** change notifications. +** +** Returns pointer to previous caller's callback function or NULL if first +** registration. +** +*******************************************************************************/ +//extern +tBTM_DEV_STATUS_CB *BTM_RegisterForDeviceStatusNotif (tBTM_DEV_STATUS_CB *p_cb); + + +/******************************************************************************* +** +** Function BTM_RegisterForVSEvents +** +** Description This function is called to register/deregister for vendor +** specific HCI events. +** +** If is_register=TRUE, then the function will be registered; +** if is_register=FALSE, then the function will be deregistered. +** +** Returns BTM_SUCCESS if successful, +** BTM_BUSY if maximum number of callbacks have already been +** registered. +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_RegisterForVSEvents (tBTM_VS_EVT_CB *p_cb, BOOLEAN is_register); + + +/******************************************************************************* +** +** Function BTM_VendorSpecificCommand +** +** Description Send a vendor specific HCI command to the controller. +** +** Returns +** BTM_SUCCESS Command sent. Does not expect command complete +** event. (command cmpl callback param is NULL) +** BTM_CMD_STARTED Command sent. Waiting for command cmpl event. +** BTM_BUSY Command not sent. Waiting for cmd cmpl event for +** prior command. +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_VendorSpecificCommand(UINT16 opcode, + UINT8 param_len, + UINT8 *p_param_buf, + tBTM_VSC_CMPL_CB *p_cb); + + +/******************************************************************************* +** +** Function BTM_AllocateSCN +** +** Description Look through the Server Channel Numbers for a free one to be +** used with an RFCOMM connection. +** +** Returns Allocated SCN number or 0 if none. +** +*******************************************************************************/ +//extern +UINT8 BTM_AllocateSCN(void); + +// btla-specific ++ +/******************************************************************************* +** +** Function BTM_TryAllocateSCN +** +** Description Try to allocate a fixed server channel +** +** Returns Returns TRUE if server channel was available +** +*******************************************************************************/ +//extern +BOOLEAN BTM_TryAllocateSCN(UINT8 scn); +// btla-specific -- + + +/******************************************************************************* +** +** Function BTM_FreeSCN +** +** Description Free the specified SCN. +** +** Returns TRUE if successful, FALSE if SCN is not in use or invalid +** +*******************************************************************************/ +//extern +BOOLEAN BTM_FreeSCN(UINT8 scn); + + +/******************************************************************************* +** +** Function BTM_SetTraceLevel +** +** Description This function sets the trace level for BTM. If called with +** a value of 0xFF, it simply returns the current trace level. +** +** Returns The new or current trace level +** +*******************************************************************************/ +//extern +UINT8 BTM_SetTraceLevel (UINT8 new_level); + + +/******************************************************************************* +** +** Function BTM_WritePageTimeout +** +** Description Send HCI Wite Page Timeout. +** +** Returns +** BTM_SUCCESS Command sent. +** BTM_NO_RESOURCES If out of resources to send the command. +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_WritePageTimeout(UINT16 timeout); + +/******************************************************************************* +** +** Function BTM_WriteVoiceSettings +** +** Description Send HCI Write Voice Settings command. +** See hcidefs.h for settings bitmask values. +** +** Returns +** BTM_SUCCESS Command sent. +** BTM_NO_RESOURCES If out of resources to send the command. +** +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_WriteVoiceSettings(UINT16 settings); + +/******************************************************************************* +** +** Function BTM_EnableTestMode +** +** Description Send HCI the enable device under test command. +** +** Note: Controller can only be taken out of this mode by +** resetting the controller. +** +** Returns +** BTM_SUCCESS Command sent. +** BTM_NO_RESOURCES If out of resources to send the command. +** +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_EnableTestMode(void); + + +/***************************************************************************** +** DEVICE DISCOVERY FUNCTIONS - Inquiry, Remote Name, Discovery, Class of Device +*****************************************************************************/ + +/******************************************************************************* +** +** Function BTM_SetDiscoverability +** +** Description This function is called to set the device into or out of +** discoverable mode. Discoverable mode means inquiry +** scans are enabled. If a value of '0' is entered for window or +** interval, the default values are used. +** +** Returns BTM_SUCCESS if successful +** BTM_BUSY if a setting of the filter is already in progress +** BTM_NO_RESOURCES if couldn't get a memory pool buffer +** BTM_ILLEGAL_VALUE if a bad parameter was detected +** BTM_WRONG_MODE if the device is not up. +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_SetDiscoverability (UINT16 inq_mode, UINT16 window, + UINT16 interval); + + +/******************************************************************************* +** +** Function BTM_ReadDiscoverability +** +** Description This function is called to read the current discoverability +** mode of the device. +** +** Output Params: p_window - current inquiry scan duration +** p_interval - current inquiry scan interval +** +** Returns BTM_NON_DISCOVERABLE, BTM_LIMITED_DISCOVERABLE, or +** BTM_GENERAL_DISCOVERABLE +** +*******************************************************************************/ +//extern +UINT16 BTM_ReadDiscoverability (UINT16 *p_window, + UINT16 *p_interval); + + +/******************************************************************************* +** +** Function BTM_SetPeriodicInquiryMode +** +** Description This function is called to set the device periodic inquiry mode. +** If the duration is zero, the periodic inquiry mode is cancelled. +** +** Parameters: p_inqparms - pointer to the inquiry information +** mode - GENERAL or LIMITED inquiry +** duration - length in 1.28 sec intervals (If '0', the inquiry is CANCELLED) +** max_resps - maximum amount of devices to search for before ending the inquiry +** filter_cond_type - BTM_CLR_INQUIRY_FILTER, BTM_FILTER_COND_DEVICE_CLASS, or +** BTM_FILTER_COND_BD_ADDR +** filter_cond - value for the filter (based on filter_cond_type) +** +** max_delay - maximum amount of time between successive inquiries +** min_delay - minimum amount of time between successive inquiries +** p_results_cb - callback returning pointer to results (tBTM_INQ_RESULTS) +** +** Returns BTM_CMD_STARTED if successfully started +** BTM_ILLEGAL_VALUE if a bad parameter is detected +** BTM_NO_RESOURCES if could not allocate a message buffer +** BTM_SUCCESS - if cancelling the periodic inquiry +** BTM_BUSY - if an inquiry is already active +** BTM_WRONG_MODE if the device is not up. +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_SetPeriodicInquiryMode (tBTM_INQ_PARMS *p_inqparms, + UINT16 max_delay, UINT16 min_delay, + tBTM_INQ_RESULTS_CB *p_results_cb); + + +/******************************************************************************* +** +** Function BTM_StartInquiry +** +** Description This function is called to start an inquiry. +** +** Parameters: p_inqparms - pointer to the inquiry information +** mode - GENERAL or LIMITED inquiry +** duration - length in 1.28 sec intervals (If '0', the inquiry is CANCELLED) +** max_resps - maximum amount of devices to search for before ending the inquiry +** filter_cond_type - BTM_CLR_INQUIRY_FILTER, BTM_FILTER_COND_DEVICE_CLASS, or +** BTM_FILTER_COND_BD_ADDR +** filter_cond - value for the filter (based on filter_cond_type) +** +** p_results_cb - Pointer to the callback routine which gets called +** upon receipt of an inquiry result. If this field is +** NULL, the application is not notified. +** +** p_cmpl_cb - Pointer to the callback routine which gets called +** upon completion. If this field is NULL, the +** application is not notified when completed. +** Returns tBTM_STATUS +** BTM_CMD_STARTED if successfully initiated +** BTM_BUSY if already in progress +** BTM_ILLEGAL_VALUE if parameter(s) are out of range +** BTM_NO_RESOURCES if could not allocate resources to start the command +** BTM_WRONG_MODE if the device is not up. +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_StartInquiry (tBTM_INQ_PARMS *p_inqparms, + tBTM_INQ_RESULTS_CB *p_results_cb, + tBTM_CMPL_CB *p_cmpl_cb); + + +/******************************************************************************* +** +** Function BTM_IsInquiryActive +** +** Description This function returns a bit mask of the current inquiry state +** +** Returns BTM_INQUIRY_INACTIVE if inactive (0) +** BTM_LIMITED_INQUIRY_ACTIVE if a limted inquiry is active +** BTM_GENERAL_INQUIRY_ACTIVE if a general inquiry is active +** BTM_PERIODIC_INQUIRY_ACTIVE if a periodic inquiry is active +** +*******************************************************************************/ +//extern +UINT16 BTM_IsInquiryActive (void); + + +/******************************************************************************* +** +** Function BTM_CancelInquiry +** +** Description This function cancels an inquiry if active +** +** Returns BTM_SUCCESS if successful +** BTM_NO_RESOURCES if could not allocate a message buffer +** BTM_WRONG_MODE if the device is not up. +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_CancelInquiry(void); + + +/******************************************************************************* +** +** Function BTM_CancelPeriodicInquiry +** +** Description This function cancels a periodic inquiry +** +** Returns +** BTM_NO_RESOURCES if could not allocate a message buffer +** BTM_SUCCESS - if cancelling the periodic inquiry +** BTM_WRONG_MODE if the device is not up. +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_CancelPeriodicInquiry(void); + + +/******************************************************************************* +** +** Function BTM_SetConnectability +** +** Description This function is called to set the device into or out of +** connectable mode. Discoverable mode means page scans enabled. +** +** Returns BTM_SUCCESS if successful +** BTM_ILLEGAL_VALUE if a bad parameter is detected +** BTM_NO_RESOURCES if could not allocate a message buffer +** BTM_WRONG_MODE if the device is not up. +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_SetConnectability (UINT16 page_mode, UINT16 window, + UINT16 interval); + + +/******************************************************************************* +** +** Function BTM_ReadConnectability +** +** Description This function is called to read the current discoverability +** mode of the device. +** Output Params p_window - current page scan duration +** p_interval - current time between page scans +** +** Returns BTM_NON_CONNECTABLE or BTM_CONNECTABLE +** +*******************************************************************************/ +//extern +UINT16 BTM_ReadConnectability (UINT16 *p_window, UINT16 *p_interval); + + +/******************************************************************************* +** +** Function BTM_SetInquiryMode +** +** Description This function is called to set standard, with RSSI +** mode or extended of the inquiry for local device. +** +** Input Params: BTM_INQ_RESULT_STANDARD, BTM_INQ_RESULT_WITH_RSSI or +** BTM_INQ_RESULT_EXTENDED +** +** Returns BTM_SUCCESS if successful +** BTM_NO_RESOURCES if couldn't get a memory pool buffer +** BTM_ILLEGAL_VALUE if a bad parameter was detected +** BTM_WRONG_MODE if the device is not up. +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_SetInquiryMode (UINT8 mode); + +/******************************************************************************* +** +** Function BTM_SetInquiryScanType +** +** Description This function is called to set the iquiry scan-type to +** standard or interlaced. +** +** Input Params: BTM_SCAN_TYPE_STANDARD or BTM_SCAN_TYPE_INTERLACED +** +** Returns BTM_SUCCESS if successful +** BTM_MODE_UNSUPPORTED if not a 1.2 device +** BTM_WRONG_MODE if the device is not up. +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_SetInquiryScanType (UINT16 scan_type); + +/******************************************************************************* +** +** Function BTM_SetPageScanType +** +** Description This function is called to set the page scan-type to +** standard or interlaced. +** +** Input Params: BTM_SCAN_TYPE_STANDARD or BTM_SCAN_TYPE_INTERLACED +** +** Returns BTM_SUCCESS if successful +** BTM_MODE_UNSUPPORTED if not a 1.2 device +** BTM_WRONG_MODE if the device is not up. +** +*******************************************************************************/ + +//extern +tBTM_STATUS BTM_SetPageScanType (UINT16 scan_type); + +/******************************************************************************* +** +** Function BTM_ReadRemoteDeviceName +** +** Description This function initiates a remote device HCI command to the +** controller and calls the callback when the process has completed. +** +** Input Params: remote_bda - device address of name to retrieve +** p_cb - callback function called when BTM_CMD_STARTED +** is returned. +** A pointer to tBTM_REMOTE_DEV_NAME is passed to the +** callback. +** +** Returns +** BTM_CMD_STARTED is returned if the request was successfully sent +** to HCI. +** BTM_BUSY if already in progress +** BTM_UNKNOWN_ADDR if device address is bad +** BTM_NO_RESOURCES if could not allocate resources to start the command +** BTM_WRONG_MODE if the device is not up. +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_ReadRemoteDeviceName (BD_ADDR remote_bda, + tBTM_CMPL_CB *p_cb, + tBT_TRANSPORT transport); + + +/******************************************************************************* +** +** Function BTM_CancelRemoteDeviceName +** +** Description This function initiates the cancel request for the specified +** remote device. +** +** Input Params: None +** +** Returns +** BTM_CMD_STARTED is returned if the request was successfully sent +** to HCI. +** BTM_NO_RESOURCES if could not allocate resources to start the command +** BTM_WRONG_MODE if there is not an active remote name request. +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_CancelRemoteDeviceName (void); + +/******************************************************************************* +** +** Function BTM_ReadRemoteVersion +** +** Description This function is called to read a remote device's version +** +** Returns BTM_SUCCESS if successful, otherwise an error +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_ReadRemoteVersion (BD_ADDR addr, + UINT8 *lmp_version, + UINT16 *manufacturer, + UINT16 *lmp_sub_version); + +/******************************************************************************* +** +** Function BTM_ReadRemoteFeatures +** +** Description This function is called to read a remote device's +** supported features mask (features mask located at page 0) +** +** Note: The size of device features mask page is +** BTM_FEATURE_BYTES_PER_PAGE bytes. +** +** Returns pointer to the remote supported features mask +** +*******************************************************************************/ +//extern +UINT8 *BTM_ReadRemoteFeatures (BD_ADDR addr); + +/******************************************************************************* +** +** Function BTM_ReadRemoteExtendedFeatures +** +** Description This function is called to read a specific extended features +** page of the remote device +** +** Note1: The size of device features mask page is +** BTM_FEATURE_BYTES_PER_PAGE bytes. +** Note2: The valid device features mask page number depends on +** the remote device capabilities. It is expected to be in the +** range [0 - BTM_EXT_FEATURES_PAGE_MAX]. + +** Returns pointer to the remote extended features mask +** or NULL if page_number is not valid +** +*******************************************************************************/ +//extern +UINT8 *BTM_ReadRemoteExtendedFeatures (BD_ADDR addr, UINT8 page_number); + +/******************************************************************************* +** +** Function BTM_ReadNumberRemoteFeaturesPages +** +** Description This function is called to retrieve the number of feature pages +** read from the remote device +** +** Returns number of features pages read from the remote device +** +*******************************************************************************/ +//extern +UINT8 BTM_ReadNumberRemoteFeaturesPages (BD_ADDR addr); + +/******************************************************************************* +** +** Function BTM_ReadAllRemoteFeatures +** +** Description This function is called to read all features of the remote device +** +** Returns pointer to the byte[0] of the page[0] of the remote device +** feature mask. +** +** Note: the function returns the pointer to the array of the size +** BTM_FEATURE_BYTES_PER_PAGE * (BTM_EXT_FEATURES_PAGE_MAX + 1). +** +*******************************************************************************/ +//extern +UINT8 *BTM_ReadAllRemoteFeatures (BD_ADDR addr); + +/******************************************************************************* +** +** Function BTM_InqDbRead +** +** Description This function looks through the inquiry database for a match +** based on Bluetooth Device Address. This is the application's +** interface to get the inquiry details of a specific BD address. +** +** Returns pointer to entry, or NULL if not found +** +*******************************************************************************/ +//extern +tBTM_INQ_INFO *BTM_InqDbRead (BD_ADDR p_bda); + + +/******************************************************************************* +** +** Function BTM_InqDbFirst +** +** Description This function looks through the inquiry database for the first +** used entry, and returns that. This is used in conjunction with +** BTM_InqDbNext by applications as a way to walk through the +** inquiry database. +** +** Returns pointer to first in-use entry, or NULL if DB is empty +** +*******************************************************************************/ +//extern +tBTM_INQ_INFO *BTM_InqDbFirst (void); + + +/******************************************************************************* +** +** Function BTM_InqDbNext +** +** Description This function looks through the inquiry database for the next +** used entry, and returns that. If the input parameter is NULL, +** the first entry is returned. +** +** Returns pointer to next in-use entry, or NULL if no more found. +** +*******************************************************************************/ +//extern +tBTM_INQ_INFO *BTM_InqDbNext (tBTM_INQ_INFO *p_cur); + + +/******************************************************************************* +** +** Function BTM_ClearInqDb +** +** Description This function is called to clear out a device or all devices +** from the inquiry database. +** +** Parameter p_bda - (input) BD_ADDR -> Address of device to clear +** (NULL clears all entries) +** +** Returns BTM_BUSY if an inquiry, get remote name, or event filter +** is active, otherwise BTM_SUCCESS +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_ClearInqDb (BD_ADDR p_bda); + +/******************************************************************************* +** +** Function BTM_ReadInquiryRspTxPower +** +** Description This command will read the inquiry Transmit Power level used +** to transmit the FHS and EIR data packets. +** This can be used directly in the Tx Power Level EIR data type. +** +** Returns BTM_SUCCESS if successful +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_ReadInquiryRspTxPower (tBTM_CMPL_CB *p_cb); + +#if SDP_INCLUDED == TRUE +/******************************************************************************* +** +** Function BTM_StartDiscovery +** +** Description This function is called by an application (or profile) +** when it wants to trigger an service discovery using the +** BTM's discovery database. +** +** Returns tBTM_STATUS +** BTM_CMD_STARTED if the discovery was initiated +** BTM_BUSY if one is already in progress +** BTM_UNKNOWN_ADDR if no addresses are in the INQ DB +** BTM_ERR_PROCESSING if err initiating the command +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_StartDiscovery (tBTM_CMPL_CB *p_cmpl_cb, + BD_ADDR_PTR p_rem_addr); + + +/******************************************************************************* +** +** Function BTM_FindAttribute +** +** Description This function is called by an application (or profile) +** when it wants to see if an attribute exists in the BTM +** discovery database. +** +** Returns Pointer to matching record, or NULL +** +*******************************************************************************/ +//extern +tSDP_DISC_REC *BTM_FindAttribute (UINT16 attr_id, + tSDP_DISC_REC *p_start_rec); + + +/******************************************************************************* +** +** Function BTM_FindService +** +** Description This function is called by an application (or profile) +** when it wants to see if a service exists in the BTM +** discovery database. +** +** Returns Pointer to matching record, or NULL +** +*******************************************************************************/ +//extern +tSDP_DISC_REC *BTM_FindService (UINT16 service_uuid, + tSDP_DISC_REC *p_start_rec); + + +/******************************************************************************* +** +** Function BTM_SetDiscoveryParams +** +** Description This function is called to set the BTM default discovery parameters. +** These UUID and attribute filters are used during the call to +** BTM_StartDiscovery. +** +** Returns void +** +*******************************************************************************/ +//extern +void BTM_SetDiscoveryParams (UINT16 num_uuid, tSDP_UUID *p_uuid_list, + UINT16 num_attr, UINT16 *p_attr_list); +#endif /*SDP_INCLUDED*/ + +/***************************************************************************** +** ACL CHANNEL MANAGEMENT FUNCTIONS +*****************************************************************************/ +/******************************************************************************* +** +** Function BTM_SetLinkPolicy +** +** Description Create and send HCI "Write Policy Set" command +** +** Returns BTM_CMD_STARTED if successfully initiated, otherwise error +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_SetLinkPolicy (BD_ADDR remote_bda, + UINT16 *settings); + +/******************************************************************************* +** +** Function BTM_SetDefaultLinkPolicy +** +** Description Set the default value for HCI "Write Policy Set" command +** to use when an ACL link is created. +** +** Returns void +** +*******************************************************************************/ +//extern +void BTM_SetDefaultLinkPolicy (UINT16 settings); + + +/******************************************************************************* +** +** Function BTM_SetDefaultLinkSuperTout +** +** Description Set the default value for HCI "Write Link Supervision Timeout" +** command to use when an ACL link is created. +** +** Returns void +** +*******************************************************************************/ +//extern +void BTM_SetDefaultLinkSuperTout (UINT16 timeout); + + +/******************************************************************************* +** +** Function BTM_SetLinkSuperTout +** +** Description Create and send HCI "Write Link Supervision Timeout" command +** +** Returns BTM_CMD_STARTED if successfully initiated, otherwise error +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_SetLinkSuperTout (BD_ADDR remote_bda, + UINT16 timeout); +/******************************************************************************* +** +** Function BTM_GetLinkSuperTout +** +** Description Read the link supervision timeout value of the connection +** +** Returns status of the operation +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_GetLinkSuperTout (BD_ADDR remote_bda, + UINT16 *p_timeout); + +/******************************************************************************* +** +** Function BTM_IsAclConnectionUp +** +** Description This function is called to check if an ACL connection exists +** to a specific remote BD Address. +** +** Returns TRUE if connection is up, else FALSE. +** +*******************************************************************************/ +//extern +BOOLEAN BTM_IsAclConnectionUp (BD_ADDR remote_bda, tBT_TRANSPORT transport); + + +/******************************************************************************* +** +** Function BTM_GetRole +** +** Description This function is called to get the role of the local device +** for the ACL connection with the specified remote device +** +** Returns BTM_SUCCESS if connection exists. +** BTM_UNKNOWN_ADDR if no active link with bd addr specified +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_GetRole (BD_ADDR remote_bd_addr, UINT8 *p_role); + + + +/******************************************************************************* +** +** Function BTM_SwitchRole +** +** Description This function is called to switch role between master and +** slave. If role is already set it will do nothing. If the +** command was initiated, the callback function is called upon +** completion. +** +** Returns BTM_SUCCESS if already in specified role. +** BTM_CMD_STARTED if command issued to controller. +** BTM_NO_RESOURCES if couldn't allocate memory to issue command +** BTM_UNKNOWN_ADDR if no active link with bd addr specified +** BTM_MODE_UNSUPPORTED if local device does not support role switching +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_SwitchRole (BD_ADDR remote_bd_addr, + UINT8 new_role, + tBTM_CMPL_CB *p_cb); + +/******************************************************************************* +** +** Function BTM_ReadRSSI +** +** Description This function is called to read the link policy settings. +** The address of link policy results are returned in the callback. +** (tBTM_RSSI_RESULTS) +** +** Returns BTM_CMD_STARTED if command issued to controller. +** BTM_NO_RESOURCES if couldn't allocate memory to issue command +** BTM_UNKNOWN_ADDR if no active link with bd addr specified +** BTM_BUSY if command is already in progress +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_ReadRSSI (BD_ADDR remote_bda, tBTM_CMPL_CB *p_cb); + + +/******************************************************************************* +** +** Function BTM_ReadTxPower +** +** Description This function is called to read the current connection +** TX power of the connection. The TX power level results +** are returned in the callback. +** (tBTM_RSSI_RESULTS) +** +** Returns BTM_CMD_STARTED if command issued to controller. +** BTM_NO_RESOURCES if couldn't allocate memory to issue command +** BTM_UNKNOWN_ADDR if no active link with bd addr specified +** BTM_BUSY if command is already in progress +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_ReadTxPower (BD_ADDR remote_bda, + tBT_TRANSPORT transport, tBTM_CMPL_CB *p_cb); + +/******************************************************************************* +** +** Function BTM_ReadLinkQuality +** +** Description This function is called to read the link quality. +** The value of the link quality is returned in the callback. +** (tBTM_LINK_QUALITY_RESULTS) +** +** Returns BTM_CMD_STARTED if command issued to controller. +** BTM_NO_RESOURCES if couldn't allocate memory to issue command +** BTM_UNKNOWN_ADDR if no active link with bd addr specified +** BTM_BUSY if command is already in progress +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_ReadLinkQuality (BD_ADDR remote_bda, tBTM_CMPL_CB *p_cb); + +/******************************************************************************* +** +** Function BTM_RegBusyLevelNotif +** +** Description This function is called to register a callback to receive +** busy level change events. +** +** Returns BTM_SUCCESS if successfully registered, otherwise error +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_RegBusyLevelNotif (tBTM_BL_CHANGE_CB *p_cb, UINT8 *p_level, + tBTM_BL_EVENT_MASK evt_mask); + +/******************************************************************************* +** +** Function BTM_AclRegisterForChanges +** +** Description This function is called to register a callback to receive +** ACL database change events, i.e. new connection or removed. +** +** Returns BTM_SUCCESS if successfully initiated, otherwise error +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_AclRegisterForChanges (tBTM_ACL_DB_CHANGE_CB *p_cb); + +/******************************************************************************* +** +** Function BTM_GetNumAclLinks +** +** Description This function is called to count the number of +** ACL links that are active. +** +** Returns UINT16 Number of active ACL links +** +*******************************************************************************/ +//extern +UINT16 BTM_GetNumAclLinks (void); + +/******************************************************************************* +** +** Function BTM_SetQoS +** +** Description This function is called to setup QoS +** +** Returns BTM_CMD_STARTED if successfully initiated, otherwise error +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_SetQoS(BD_ADDR bd, FLOW_SPEC *p_flow, + tBTM_CMPL_CB *p_cb); + + +/***************************************************************************** +** (e)SCO CHANNEL MANAGEMENT FUNCTIONS +*****************************************************************************/ +/******************************************************************************* +** +** Function BTM_CreateSco +** +** Description This function is called to create an SCO connection. If the +** "is_orig" flag is TRUE, the connection will be originated, +** otherwise BTM will wait for the other side to connect. +** +** Returns BTM_UNKNOWN_ADDR if the ACL connection is not up +** BTM_BUSY if another SCO being set up to +** the same BD address +** BTM_NO_RESOURCES if the max SCO limit has been reached +** BTM_CMD_STARTED if the connection establishment is started. +** In this case, "*p_sco_inx" is filled in +** with the sco index used for the connection. +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_CreateSco (BD_ADDR remote_bda, BOOLEAN is_orig, + UINT16 pkt_types, UINT16 *p_sco_inx, + tBTM_SCO_CB *p_conn_cb, + tBTM_SCO_CB *p_disc_cb); + + +/******************************************************************************* +** +** Function BTM_RemoveSco +** +** Description This function is called to remove a specific SCO connection. +** +** Returns BTM_CMD_STARTED if successfully initiated, otherwise error +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_RemoveSco (UINT16 sco_inx); + + +/******************************************************************************* +** +** Function BTM_SetScoPacketTypes +** +** Description This function is called to set the packet types used for +** a specific SCO connection, +** +** Parameters pkt_types - One or more of the following +** BTM_SCO_PKT_TYPES_MASK_HV1 +** BTM_SCO_PKT_TYPES_MASK_HV2 +** BTM_SCO_PKT_TYPES_MASK_HV3 +** BTM_SCO_PKT_TYPES_MASK_EV3 +** BTM_SCO_PKT_TYPES_MASK_EV4 +** BTM_SCO_PKT_TYPES_MASK_EV5 +** +** BTM_SCO_LINK_ALL_MASK - enables all supported types +** +** Returns BTM_CMD_STARTED if successfully initiated, otherwise error +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_SetScoPacketTypes (UINT16 sco_inx, UINT16 pkt_types); + + +/******************************************************************************* +** +** Function BTM_ReadScoPacketTypes +** +** Description This function is read the packet types used for a specific +** SCO connection. +** +** Returns One or more of the following (bitmask) +** BTM_SCO_PKT_TYPES_MASK_HV1 +** BTM_SCO_PKT_TYPES_MASK_HV2 +** BTM_SCO_PKT_TYPES_MASK_HV3 +** BTM_SCO_PKT_TYPES_MASK_EV3 +** BTM_SCO_PKT_TYPES_MASK_EV4 +** BTM_SCO_PKT_TYPES_MASK_EV5 +** +** Returns packet types supported for the connection +** +*******************************************************************************/ +//extern +UINT16 BTM_ReadScoPacketTypes (UINT16 sco_inx); + + +/******************************************************************************* +** +** Function BTM_ReadDeviceScoPacketTypes +** +** Description This function is read the SCO packet types that +** the device supports. +** +** Returns packet types supported by the device. +** +*******************************************************************************/ +//extern +UINT16 BTM_ReadDeviceScoPacketTypes (void); + + +/******************************************************************************* +** +** Function BTM_ReadScoHandle +** +** Description This function is used to read the HCI handle used for a specific +** SCO connection, +** +** Returns handle for the connection, or 0xFFFF if invalid SCO index. +** +*******************************************************************************/ +//extern +UINT16 BTM_ReadScoHandle (UINT16 sco_inx); + + +/******************************************************************************* +** +** Function BTM_ReadScoBdAddr +** +** Description This function is read the remote BD Address for a specific +** SCO connection, +** +** Returns pointer to BD address or NULL if not known +** +*******************************************************************************/ +//extern +UINT8 *BTM_ReadScoBdAddr (UINT16 sco_inx); + + +/******************************************************************************* +** +** Function BTM_ReadScoDiscReason +** +** Description This function is returns the reason why an (e)SCO connection +** has been removed. It contains the value until read, or until +** another (e)SCO connection has disconnected. +** +** Returns HCI reason or BTM_INVALID_SCO_DISC_REASON if not set. +** +*******************************************************************************/ +//extern +UINT16 BTM_ReadScoDiscReason (void); + + +/******************************************************************************* +** +** Function BTM_SetEScoMode +** +** Description This function sets up the negotiated parameters for SCO or +** eSCO, and sets as the default mode used for calls to +** BTM_CreateSco. It can be called only when there are no +** active (e)SCO links. +** +** Returns BTM_SUCCESS if the successful. +** BTM_BUSY if there are one or more active (e)SCO links. +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_SetEScoMode (tBTM_SCO_TYPE sco_mode, + tBTM_ESCO_PARAMS *p_parms); + +/******************************************************************************* +** +** Function BTM_SetWBSCodec +** +** Description This function sends command to the controller to setup +** WBS codec for the upcoming eSCO connection. +** +** Returns BTM_SUCCESS. +** +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_SetWBSCodec (tBTM_SCO_CODEC_TYPE codec_type); + +/******************************************************************************* +** +** Function BTM_RegForEScoEvts +** +** Description This function registers a SCO event callback with the +** specified instance. It should be used to received +** connection indication events and change of link parameter +** events. +** +** Returns BTM_SUCCESS if the successful. +** BTM_ILLEGAL_VALUE if there is an illegal sco_inx +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_RegForEScoEvts (UINT16 sco_inx, + tBTM_ESCO_CBACK *p_esco_cback); + +/******************************************************************************* +** +** Function BTM_ReadEScoLinkParms +** +** Description This function returns the current eSCO link parameters for +** the specified handle. This can be called anytime a connection +** is active, but is typically called after receiving the SCO +** opened callback. +** +** Note: If called over a 1.1 controller, only the packet types +** field has meaning. +** Note: If the upper layer doesn't know the current sco index, +** BTM_FIRST_ACTIVE_SCO_INDEX can be used as the first parameter to +** find the first active SCO index +** +** Returns BTM_SUCCESS if returned data is valid connection. +** BTM_ILLEGAL_VALUE if no connection for specified sco_inx. +** BTM_MODE_UNSUPPORTED if local controller does not support +** 1.2 specification. +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_ReadEScoLinkParms (UINT16 sco_inx, + tBTM_ESCO_DATA *p_parms); + +/******************************************************************************* +** +** Function BTM_ChangeEScoLinkParms +** +** Description This function requests renegotiation of the parameters on +** the current eSCO Link. If any of the changes are accepted +** by the controllers, the BTM_ESCO_CHG_EVT event is sent in +** the tBTM_ESCO_CBACK function with the current settings of +** the link. The callback is registered through the call to +** BTM_SetEScoMode. +** +** +** Returns BTM_CMD_STARTED if command is successfully initiated. +** BTM_ILLEGAL_VALUE if no connection for specified sco_inx. +** BTM_NO_RESOURCES - not enough resources to initiate command. +** BTM_MODE_UNSUPPORTED if local controller does not support +** 1.2 specification. +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_ChangeEScoLinkParms (UINT16 sco_inx, + tBTM_CHG_ESCO_PARAMS *p_parms); + +/******************************************************************************* +** +** Function BTM_EScoConnRsp +** +** Description This function is called upon receipt of an (e)SCO connection +** request event (BTM_ESCO_CONN_REQ_EVT) to accept or reject +** the request. Parameters used to negotiate eSCO links. +** If p_parms is NULL, then values set through BTM_SetEScoMode +** are used. +** If the link type of the incoming request is SCO, then only +** the tx_bw, max_latency, content format, and packet_types are +** valid. The hci_status parameter should be +** ([0x0] to accept, [0x0d..0x0f] to reject) +** +** +** Returns void +** +*******************************************************************************/ +//extern +void BTM_EScoConnRsp (UINT16 sco_inx, UINT8 hci_status, + tBTM_ESCO_PARAMS *p_parms); + +/******************************************************************************* +** +** Function BTM_GetNumScoLinks +** +** Description This function returns the number of active SCO links. +** +** Returns UINT8 +** +*******************************************************************************/ +//extern +UINT8 BTM_GetNumScoLinks (void); + +/***************************************************************************** +** SECURITY MANAGEMENT FUNCTIONS +*****************************************************************************/ +/******************************************************************************* +** +** Function BTM_SecRegister +** +** Description Application manager calls this function to register for +** security services. There can be one and only one application +** saving link keys. BTM allows only first registration. +** +** Returns TRUE if registered OK, else FALSE +** +*******************************************************************************/ +//extern +BOOLEAN BTM_SecRegister (tBTM_APPL_INFO *p_cb_info); + +/******************************************************************************* +** +** Function BTM_SecRegisterLinkKeyNotificationCallback +** +** Description Profiles can register to be notified when a new Link Key +** is generated per connection. +** +** Returns TRUE if registered OK, else FALSE +** +*******************************************************************************/ +//extern +BOOLEAN BTM_SecRegisterLinkKeyNotificationCallback( + tBTM_LINK_KEY_CALLBACK *p_callback); + +/******************************************************************************* +** +** Function BTM_SecAddRmtNameNotifyCallback +** +** Description Profiles can register to be notified when name of the +** remote device is resolved (up to BTM_SEC_MAX_RMT_NAME_CALLBACKS). +** +** Returns TRUE if registered OK, else FALSE +** +*******************************************************************************/ +//extern +BOOLEAN BTM_SecAddRmtNameNotifyCallback (tBTM_RMT_NAME_CALLBACK *p_callback); + + +/******************************************************************************* +** +** Function BTM_SecDeleteRmtNameNotifyCallback +** +** Description A profile can deregister notification when a new Link Key +** is generated per connection. +** +** Returns TRUE if OK, else FALSE +** +*******************************************************************************/ +//extern +BOOLEAN BTM_SecDeleteRmtNameNotifyCallback (tBTM_RMT_NAME_CALLBACK *p_callback); + +/******************************************************************************* +** +** Function BTM_GetSecurityFlags +** +** Description Get security flags for the device +** +** Returns BOOLEAN TRUE or FALSE is device found +** +*******************************************************************************/ +//extern +BOOLEAN BTM_GetSecurityFlags (BD_ADDR bd_addr, UINT8 *p_sec_flags); + +/******************************************************************************* +** +** Function BTM_GetSecurityFlagsByTransport +** +** Description Get security flags for the device on a particular transport +** +** Parameters bd_addr: BD address of remote device +** p_sec_flags : Out parameter to be filled with security flags for the connection +** transport : Physical transport of the connection (BR/EDR or LE) +** +** Returns BOOLEAN TRUE or FALSE is device found +** +*******************************************************************************/ +//extern +BOOLEAN BTM_GetSecurityFlagsByTransport (BD_ADDR bd_addr, + UINT8 *p_sec_flags, tBT_TRANSPORT transport); + +/******************************************************************************* +** +** Function BTM_ReadTrustedMask +** +** Description Get trusted mask for the device +** +** Returns NULL, if the device record is not found. +** otherwise, the trusted mask +** +*******************************************************************************/ +//extern +UINT32 *BTM_ReadTrustedMask (BD_ADDR bd_addr); + +/******************************************************************************* +** +** Function BTM_SetPinType +** +** Description Set PIN type for the device. +** +** Returns void +** +*******************************************************************************/ +//extern +void BTM_SetPinType (UINT8 pin_type, PIN_CODE pin_code, UINT8 pin_code_len); + + +/******************************************************************************* +** +** Function BTM_SetPairableMode +** +** Description Enable or disable pairing +** +** Parameters allow_pairing - (TRUE or FALSE) whether or not the device +** allows pairing. +** connect_only_paired - (TRUE or FALSE) whether or not to +** only allow paired devices to connect. +** +** Returns void +** +*******************************************************************************/ +//extern +void BTM_SetPairableMode (BOOLEAN allow_pairing, BOOLEAN connect_only_paired); + +/******************************************************************************* +** +** Function BTM_SetSecureConnectionsOnly +** +** Description Enable or disable default treatment for Mode 4 Level 0 services +** +** Parameter secure_connections_only_mode - (TRUE or FALSE) +** TRUE means that the device should treat Mode 4 Level 0 services as +** services of other levels. +** FALSE means that the device should provide default treatment for +** Mode 4 Level 0 services. +** +** Returns void +** +*******************************************************************************/ +//extern +void BTM_SetSecureConnectionsOnly (BOOLEAN secure_connections_only_mode); + +/******************************************************************************* +** +** Function BTM_SetSecurityLevel +** +** Description Register service security level with Security Manager. Each +** service must register its requirements regardless of the +** security level that is used. This API is called once for originators +** nad again for acceptors of connections. +** +** Returns TRUE if registered OK, else FALSE +** +*******************************************************************************/ +//extern +BOOLEAN BTM_SetSecurityLevel (BOOLEAN is_originator, char *p_name, + UINT8 service_id, UINT16 sec_level, + UINT16 psm, UINT32 mx_proto_id, + UINT32 mx_chan_id); + +/******************************************************************************* +** +** Function BTM_SetOutService +** +** Description This function is called to set the service for +** outgoing connection. +** +** Returns void +** +*******************************************************************************/ +//extern +void BTM_SetOutService(BD_ADDR bd_addr, UINT8 service_id, UINT32 mx_chan_id); + +/******************************************************************************* +** +** Function BTM_SecClrService +** +** Description Removes specified service record(s) from the security database. +** All service records with the specified name are removed. +** Typically used only by devices with limited RAM so that it can +** reuse an old security service record. +** records (except SDP). +** +** Returns Number of records that were freed. +** +*******************************************************************************/ +//extern +UINT8 BTM_SecClrService (UINT8 service_id); + +/******************************************************************************* +** +** Function BTM_SecAddDevice +** +** Description Add/modify device. This function will be normally called +** during host startup to restore all required information +** stored in the NVRAM. +** dev_class, bd_name, link_key, and features are NULL if unknown +** +** Returns TRUE if added OK, else FALSE +** +*******************************************************************************/ +//extern +BOOLEAN BTM_SecAddDevice (BD_ADDR bd_addr, DEV_CLASS dev_class, + BD_NAME bd_name, UINT8 *features, + UINT32 trusted_mask[], LINK_KEY link_key, + UINT8 key_type, tBTM_IO_CAP io_cap, UINT8 pin_length); + + +/******************************************************************************* +** +** Function BTM_SecDeleteDevice +** +** Description Free resources associated with the device. +** +** Returns TRUE if rmoved OK, FALSE if not found +** +*******************************************************************************/ +//extern +BOOLEAN BTM_SecDeleteDevice (BD_ADDR bd_addr); + + +/******************************************************************************* +** +** Function BTM_SecGetDeviceLinkKey +** +** Description This function is called to obtain link key for the device +** it returns BTM_SUCCESS if link key is available, or +** BTM_UNKNOWN_ADDR if Security Manager does not know about +** the device or device record does not contain link key info +** +** Returns BTM_SUCCESS if successful, otherwise error code +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_SecGetDeviceLinkKey (BD_ADDR bd_addr, + LINK_KEY link_key); + + +/******************************************************************************* +** +** Function BTM_SecGetDeviceLinkKeyType +** +** Description This function is called to obtain link key type for the +** device. +** it returns BTM_SUCCESS if link key is available, or +** BTM_UNKNOWN_ADDR if Security Manager does not know about +** the device or device record does not contain link key info +** +** Returns BTM_LKEY_TYPE_IGNORE if link key is unknown, link type +** otherwise. +** +*******************************************************************************/ +//extern +tBTM_LINK_KEY_TYPE BTM_SecGetDeviceLinkKeyType (BD_ADDR bd_addr); + + +/******************************************************************************* +** +** Function BTM_PINCodeReply +** +** Description This function is called after Security Manager submitted +** PIN code request to the UI. +** +** Parameters: bd_addr - Address of the device for which PIN was requested +** res - result of the operation BTM_SUCCESS if success +** pin_len - length in bytes of the PIN Code +** p_pin - pointer to array with the PIN Code +** trusted_mask - bitwise OR of trusted services (array of UINT32) +** +** Returns void +** +*******************************************************************************/ +//extern +void BTM_PINCodeReply (BD_ADDR bd_addr, UINT8 res, UINT8 pin_len, + UINT8 *p_pin, UINT32 trusted_mask[]); + + +/******************************************************************************* +** +** Function BTM_SecBond +** +** Description This function is called to perform bonding with peer device. +** +** Parameters: bd_addr - Address of the device to bond +** pin_len - length in bytes of the PIN Code +** p_pin - pointer to array with the PIN Code +** trusted_mask - bitwise OR of trusted services (array of UINT32) + +** Returns BTM_CMD_STARTED if successfully initiated, otherwise error +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_SecBond (BD_ADDR bd_addr, + UINT8 pin_len, UINT8 *p_pin, + UINT32 trusted_mask[]); + +/******************************************************************************* +** +** Function BTM_SecBondByTransport +** +** Description This function is called to perform bonding by designated transport +** +** Parameters: bd_addr - Address of the device to bond +** pin_len - length in bytes of the PIN Code +** p_pin - pointer to array with the PIN Code +** trusted_mask - bitwise OR of trusted services (array of UINT32) +** transport : Physical transport to use for bonding (BR/EDR or LE) +** +** Returns BTM_CMD_STARTED if successfully initiated, otherwise error +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_SecBondByTransport (BD_ADDR bd_addr, + tBT_TRANSPORT transport, + UINT8 pin_len, UINT8 *p_pin, + UINT32 trusted_mask[]); + +/******************************************************************************* +** +** Function BTM_SecBondCancel +** +** Description This function is called to cancel ongoing bonding process +** with peer device. +** +** Returns BTM_CMD_STARTED if successfully initiated, otherwise error +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_SecBondCancel (BD_ADDR bd_addr); + +/******************************************************************************* +** +** Function BTM_SetEncryption +** +** Description This function is called to ensure that connection is +** encrypted. Should be called only on an open connection. +** Typically only needed for connections that first want to +** bring up unencrypted links, then later encrypt them. +** +** Parameters: bd_addr - Address of the peer device +** p_callback - Pointer to callback function called if +** this function returns PENDING after required +** procedures are completed. Can be set to NULL +** if status is not desired. +** p_ref_data - pointer to any data the caller wishes to receive +** in the callback function upon completion. +* can be set to NULL if not used. +** +** Returns BTM_SUCCESS - already encrypted +** BTM_PENDING - command will be returned in the callback +** BTM_WRONG_MODE- connection not up. +** BTM_BUSY - security procedures are currently active +** BTM_MODE_UNSUPPORTED - if security manager not linked in. +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_SetEncryption (BD_ADDR bd_addr, tBT_TRANSPORT transport, + tBTM_SEC_CBACK *p_callback, void *p_ref_data); + +/******************************************************************************* +** +** Function BTM_ConfirmReqReply +** +** Description This function is called to confirm the numeric value for +** Simple Pairing in response to BTM_SP_CFM_REQ_EVT +** +** Parameters: res - result of the operation BTM_SUCCESS if success +** bd_addr - Address of the peer device +** +*******************************************************************************/ +//extern +void BTM_ConfirmReqReply(tBTM_STATUS res, BD_ADDR bd_addr); + +/******************************************************************************* +** +** Function BTM_PasskeyReqReply +** +** Description This function is called to provide the passkey for +** Simple Pairing in response to BTM_SP_KEY_REQ_EVT +** +** Parameters: res - result of the operation BTM_SUCCESS if success +** bd_addr - Address of the peer device +** passkey - numeric value in the range of 0 - 999999(0xF423F). +** +*******************************************************************************/ +//extern +void BTM_PasskeyReqReply(tBTM_STATUS res, BD_ADDR bd_addr, UINT32 passkey); + +/******************************************************************************* +** +** Function BTM_SendKeypressNotif +** +** Description This function is used during the passkey entry model +** by a device with KeyboardOnly IO capabilities +** (very likely to be a HID Device). +** It is called by a HID Device to inform the remote device when +** a key has been entered or erased. +** +** Parameters: bd_addr - Address of the peer device +** type - notification type +** +*******************************************************************************/ +//extern +void BTM_SendKeypressNotif(BD_ADDR bd_addr, tBTM_SP_KEY_TYPE type); + +/******************************************************************************* +** +** Function BTM_IoCapRsp +** +** Description This function is called in response to BTM_SP_IO_REQ_EVT +** When the event data io_req.oob_data is set to BTM_OOB_UNKNOWN +** by the tBTM_SP_CALLBACK implementation, this function is +** called to provide the actual response +** +** Parameters: bd_addr - Address of the peer device +** io_cap - The IO capability of local device. +** oob - BTM_OOB_NONE or BTM_OOB_PRESENT. +** auth_req- MITM protection required or not. +** +*******************************************************************************/ +//extern +void BTM_IoCapRsp(BD_ADDR bd_addr, tBTM_IO_CAP io_cap, + tBTM_OOB_DATA oob, tBTM_AUTH_REQ auth_req); + +/******************************************************************************* +** +** Function BTM_ReadLocalOobData +** +** Description This function is called to read the local OOB data from +** LM +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_ReadLocalOobData(void); + +/******************************************************************************* +** +** Function BTM_RemoteOobDataReply +** +** Description This function is called to provide the remote OOB data for +** Simple Pairing in response to BTM_SP_RMT_OOB_EVT +** +** Parameters: bd_addr - Address of the peer device +** c - simple pairing Hash C. +** r - simple pairing Randomizer C. +** +*******************************************************************************/ +//extern +void BTM_RemoteOobDataReply(tBTM_STATUS res, BD_ADDR bd_addr, + BT_OCTET16 c, BT_OCTET16 r); + +/******************************************************************************* +** +** Function BTM_BuildOobData +** +** Description This function is called to build the OOB data payload to +** be sent over OOB (non-Bluetooth) link +** +** Parameters: p_data - the location for OOB data +** max_len - p_data size. +** c - simple pairing Hash C. +** r - simple pairing Randomizer C. +** name_len- 0, local device name would not be included. +** otherwise, the local device name is included for +** up to this specified length +** +** Returns Number of bytes in p_data. +** +*******************************************************************************/ +//extern +UINT16 BTM_BuildOobData(UINT8 *p_data, UINT16 max_len, BT_OCTET16 c, + BT_OCTET16 r, UINT8 name_len); + +/******************************************************************************* +** +** Function BTM_BothEndsSupportSecureConnections +** +** Description This function is called to check if both the local device and the peer device +** specified by bd_addr support BR/EDR Secure Connections. +** +** Parameters: bd_addr - address of the peer +** +** Returns TRUE if BR/EDR Secure Connections are supported by both local +** and the remote device. +** else FALSE. +** +*******************************************************************************/ +//extern +BOOLEAN BTM_BothEndsSupportSecureConnections(BD_ADDR bd_addr); + +/******************************************************************************* +** +** Function BTM_PeerSupportsSecureConnections +** +** Description This function is called to check if the peer supports +** BR/EDR Secure Connections. +** +** Parameters: bd_addr - address of the peer +** +** Returns TRUE if BR/EDR Secure Connections are supported by the peer, +** else FALSE. +** +*******************************************************************************/ +//extern +BOOLEAN BTM_PeerSupportsSecureConnections(BD_ADDR bd_addr); + +/******************************************************************************* +** +** Function BTM_ReadOobData +** +** Description This function is called to parse the OOB data payload +** received over OOB (non-Bluetooth) link +** +** Parameters: p_data - the location for OOB data +** eir_tag - The associated EIR tag to read the data. +** *p_len(output) - the length of the data with the given tag. +** +** Returns the beginning of the data with the given tag. +** NULL, if the tag is not found. +** +*******************************************************************************/ +//extern +UINT8 *BTM_ReadOobData(UINT8 *p_data, UINT8 eir_tag, UINT8 *p_len); + +/******************************************************************************* +** +** Function BTM_SecReadDevName +** +** Description Looks for the device name in the security database for the +** specified BD address. +** +** Returns Pointer to the name or NULL +** +*******************************************************************************/ +//extern +char *BTM_SecReadDevName (BD_ADDR bd_addr); + + +/***************************************************************************** +** POWER MANAGEMENT FUNCTIONS +*****************************************************************************/ +/******************************************************************************* +** +** Function BTM_PmRegister +** +** Description register or deregister with power manager +** +** Returns BTM_SUCCESS if successful, +** BTM_NO_RESOURCES if no room to hold registration +** BTM_ILLEGAL_VALUE +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_PmRegister (UINT8 mask, UINT8 *p_pm_id, + tBTM_PM_STATUS_CBACK *p_cb); + + +/******************************************************************************* +** +** Function BTM_SetPowerMode +** +** Description store the mode in control block or +** alter ACL connection behavior. +** +** Returns BTM_SUCCESS if successful, +** BTM_UNKNOWN_ADDR if bd addr is not active or bad +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_SetPowerMode (UINT8 pm_id, BD_ADDR remote_bda, + tBTM_PM_PWR_MD *p_mode); + + +/******************************************************************************* +** +** Function BTM_ReadPowerMode +** +** Description This returns the current mode for a specific +** ACL connection. +** +** Input Param remote_bda - device address of desired ACL connection +** +** Output Param p_mode - address where the current mode is copied into. +** BTM_ACL_MODE_NORMAL +** BTM_ACL_MODE_HOLD +** BTM_ACL_MODE_SNIFF +** BTM_ACL_MODE_PARK +** (valid only if return code is BTM_SUCCESS) +** +** Returns BTM_SUCCESS if successful, +** BTM_UNKNOWN_ADDR if bd addr is not active or bad +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_ReadPowerMode (BD_ADDR remote_bda, + tBTM_PM_MODE *p_mode); + +/******************************************************************************* +** +** Function BTM_SetSsrParams +** +** Description This sends the given SSR parameters for the given ACL +** connection if it is in ACTIVE mode. +** +** Input Param remote_bda - device address of desired ACL connection +** max_lat - maximum latency (in 0.625ms)(0-0xFFFE) +** min_rmt_to - minimum remote timeout +** min_loc_to - minimum local timeout +** +** +** Returns BTM_SUCCESS if the HCI command is issued successful, +** BTM_UNKNOWN_ADDR if bd addr is not active or bad +** BTM_CMD_STORED if the command is stored +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_SetSsrParams (BD_ADDR remote_bda, UINT16 max_lat, + UINT16 min_rmt_to, UINT16 min_loc_to); + +/******************************************************************************* +** +** Function BTM_GetHCIConnHandle +** +** Description This function is called to get the handle for an ACL connection +** to a specific remote BD Address. +** +** Returns the handle of the connection, or 0xFFFF if none. +** +*******************************************************************************/ +//extern +UINT16 BTM_GetHCIConnHandle (BD_ADDR remote_bda, tBT_TRANSPORT transport); + +/******************************************************************************* +** +** Function BTM_DeleteStoredLinkKey +** +** Description This function is called to delete link key for the specified +** device addresses from the NVRAM storage attached to the Bluetooth +** controller. +** +** Parameters: bd_addr - Addresses of the devices +** p_cb - Call back function to be called to return +** the results +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_DeleteStoredLinkKey(BD_ADDR bd_addr, tBTM_CMPL_CB *p_cb); + +/******************************************************************************* +** +** Function BTM_WriteEIR +** +** Description This function is called to write EIR data to controller. +** +** Parameters p_buff - allocated HCI command buffer including extended +** inquriry response +** +** Returns BTM_SUCCESS - if successful +** BTM_MODE_UNSUPPORTED - if local device cannot support it +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_WriteEIR( BT_HDR *p_buff ); + +/******************************************************************************* +** +** Function BTM_CheckEirData +** +** Description This function is called to get EIR data from significant part. +** +** Parameters p_eir - pointer of EIR significant part +** type - finding EIR data type +** p_length - return the length of EIR data +** +** Returns pointer of EIR data +** +*******************************************************************************/ +//extern +UINT8 *BTM_CheckEirData( UINT8 *p_eir, UINT8 type, UINT8 *p_length ); + +/******************************************************************************* +** +** Function BTM_HasEirService +** +** Description This function is called to know if UUID in bit map of UUID. +** +** Parameters p_eir_uuid - bit map of UUID list +** uuid16 - UUID 16-bit +** +** Returns TRUE - if found +** FALSE - if not found +** +*******************************************************************************/ +//extern +BOOLEAN BTM_HasEirService( UINT32 *p_eir_uuid, UINT16 uuid16 ); + +/******************************************************************************* +** +** Function BTM_HasInquiryEirService +** +** Description This function is called to know if UUID in bit map of UUID list. +** +** Parameters p_results - inquiry results +** uuid16 - UUID 16-bit +** +** Returns BTM_EIR_FOUND - if found +** BTM_EIR_NOT_FOUND - if not found and it is complete list +** BTM_EIR_UNKNOWN - if not found and it is not complete list +** +*******************************************************************************/ +//extern +tBTM_EIR_SEARCH_RESULT BTM_HasInquiryEirService( tBTM_INQ_RESULTS *p_results, + UINT16 uuid16 ); + +/******************************************************************************* +** +** Function BTM_AddEirService +** +** Description This function is called to add a service in bit map of UUID list. +** +** Parameters p_eir_uuid - bit mask of UUID list for EIR +** uuid16 - UUID 16-bit +** +** Returns None +** +*******************************************************************************/ +//extern +void BTM_AddEirService( UINT32 *p_eir_uuid, UINT16 uuid16 ); + +/******************************************************************************* +** +** Function BTM_RemoveEirService +** +** Description This function is called to remove a service in bit map of UUID list. +** +** Parameters p_eir_uuid - bit mask of UUID list for EIR +** uuid16 - UUID 16-bit +** +** Returns None +** +*******************************************************************************/ +//extern +void BTM_RemoveEirService( UINT32 *p_eir_uuid, UINT16 uuid16 ); + +/******************************************************************************* +** +** Function BTM_GetEirSupportedServices +** +** Description This function is called to get UUID list from bit map of UUID list. +** +** Parameters p_eir_uuid - bit mask of UUID list for EIR +** p - reference of current pointer of EIR +** max_num_uuid16 - max number of UUID can be written in EIR +** num_uuid16 - number of UUID have been written in EIR +** +** Returns BTM_EIR_MORE_16BITS_UUID_TYPE, if it has more than max +** BTM_EIR_COMPLETE_16BITS_UUID_TYPE, otherwise +** +*******************************************************************************/ +//extern +UINT8 BTM_GetEirSupportedServices( UINT32 *p_eir_uuid, UINT8 **p, + UINT8 max_num_uuid16, UINT8 *p_num_uuid16); + +/******************************************************************************* +** +** Function BTM_GetEirUuidList +** +** Description This function parses EIR and returns UUID list. +** +** Parameters p_eir - EIR +** uuid_size - LEN_UUID_16, LEN_UUID_32, LEN_UUID_128 +** p_num_uuid - return number of UUID in found list +** p_uuid_list - return UUID 16-bit list +** max_num_uuid - maximum number of UUID to be returned +** +** Returns 0 - if not found +** BTM_EIR_COMPLETE_16BITS_UUID_TYPE +** BTM_EIR_MORE_16BITS_UUID_TYPE +** BTM_EIR_COMPLETE_32BITS_UUID_TYPE +** BTM_EIR_MORE_32BITS_UUID_TYPE +** BTM_EIR_COMPLETE_128BITS_UUID_TYPE +** BTM_EIR_MORE_128BITS_UUID_TYPE +** +*******************************************************************************/ +//extern +UINT8 BTM_GetEirUuidList( UINT8 *p_eir, UINT8 uuid_size, UINT8 *p_num_uuid, + UINT8 *p_uuid_list, UINT8 max_num_uuid); + +/***************************************************************************** +** SCO OVER HCI +*****************************************************************************/ +/******************************************************************************* +** +** Function BTM_ConfigScoPath +** +** Description This function enable/disable SCO over HCI and registers SCO +** data callback if SCO over HCI is enabled. +** +** Parameter path: SCO or HCI +** p_sco_data_cb: callback function or SCO data if path is set +** to transport. +** p_pcm_param: pointer to the PCM interface parameter. If a NULL +** pointer is used, PCM parameter maintained in +** the control block will be used; otherwise update +** control block value. +** err_data_rpt: Lisbon feature to enable the erronous data report +** or not. +** +** Returns BTM_SUCCESS if the successful. +** BTM_NO_RESOURCES: no rsource to start the command. +** BTM_ILLEGAL_VALUE: invalid callback function pointer. +** BTM_CMD_STARTED :Command sent. Waiting for command cmpl event. +** +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_ConfigScoPath (tBTM_SCO_ROUTE_TYPE path, + tBTM_SCO_DATA_CB *p_sco_data_cb, + tBTM_SCO_PCM_PARAM *p_pcm_param, + BOOLEAN err_data_rpt); + +/******************************************************************************* +** +** Function BTM_WriteScoData +** +** Description This function write SCO data to a specified instance. The data +** to be written p_buf needs to carry an offset of +** HCI_SCO_PREAMBLE_SIZE bytes, and the data length can not +** exceed BTM_SCO_DATA_SIZE_MAX bytes, whose default value is set +** to 60 and is configurable. Data longer than the maximum bytes +** will be truncated. +** +** Returns BTM_SUCCESS: data write is successful +** BTM_ILLEGAL_VALUE: SCO data contains illegal offset value. +** BTM_SCO_BAD_LENGTH: SCO data length exceeds the max SCO packet +** size. +** BTM_NO_RESOURCES: no resources. +** BTM_UNKNOWN_ADDR: unknown SCO connection handle, or SCO is not +** routed via HCI. +** +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_WriteScoData (UINT16 sco_inx, BT_HDR *p_buf); + +/******************************************************************************* +** +** Function BTM_SetARCMode +** +** Description Send Audio Routing Control command. +** +** Returns void +** +*******************************************************************************/ +//extern +void BTM_SetARCMode (UINT8 iface, UINT8 arc_mode, tBTM_VSC_CMPL_CB *p_arc_cb); + + +/******************************************************************************* +** +** Function BTM_PCM2Setup_Write +** +** Description Send PCM2_Setup write command. +** +** Returns void +** +*******************************************************************************/ +//extern +void BTM_PCM2Setup_Write (BOOLEAN clk_master, tBTM_VSC_CMPL_CB *p_arc_cb); + + +/******************************************************************************* +** +** Function BTM_PM_ReadControllerState +** +** Description This function is called to obtain the controller state +** +** Returns Controller state (BTM_CONTRL_ACTIVE, BTM_CONTRL_SCAN, and BTM_CONTRL_IDLE) +** +*******************************************************************************/ +//extern +tBTM_CONTRL_STATE BTM_PM_ReadControllerState(void); +/* +#ifdef __cplusplus +} +#endif +*/ + +#endif /* BTM_API_H */ diff --git a/tools/sdk/include/bluedroid/btm_ble_api.h b/tools/sdk/include/bluedroid/btm_ble_api.h new file mode 100644 index 00000000..6eb07838 --- /dev/null +++ b/tools/sdk/include/bluedroid/btm_ble_api.h @@ -0,0 +1,1958 @@ +/****************************************************************************** + * + * Copyright (C) 1999-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 file contains the Bluetooth Manager (BTM) API function external + * definitions. + * + ******************************************************************************/ +#ifndef BTM_BLE_API_H +#define BTM_BLE_API_H + +#include "bt_defs.h" +#include "btm_api.h" +#include "gki.h" +#include "bt_common_types.h" + +#define CHANNEL_MAP_LEN 5 +typedef UINT8 tBTM_BLE_CHNL_MAP[CHANNEL_MAP_LEN]; + +/* 0x00-0x04 only used for set advertising parameter command */ +#define BTM_BLE_CONNECT_EVT 0x00 /* 0x00-0x04 only used for set advertising + parameter command */ +#define BTM_BLE_CONNECT_DIR_EVT 0x01 /* Connectable directed advertising */ +#define BTM_BLE_DISCOVER_EVT 0x02 /* Scannable undirected advertising */ +#define BTM_BLE_NON_CONNECT_EVT 0x03 /* Non connectable undirected advertising */ +#define BTM_BLE_CONNECT_LO_DUTY_DIR_EVT 0x04 /* Connectable low duty + cycle directed advertising */ +/* 0x00 - 0x05 can be received on adv event type */ +#define BTM_BLE_SCAN_RSP_EVT 0x04 +#define BTM_BLE_SCAN_REQ_EVT 0x05 +#define BTM_BLE_UNKNOWN_EVT 0xff + +#define BTM_BLE_UNKNOWN_EVT 0xff + +typedef UINT8 tBTM_BLE_EVT; +typedef UINT8 tBTM_BLE_CONN_MODE; + +typedef UINT32 tBTM_BLE_REF_VALUE; + +#define BTM_BLE_SCAN_MODE_PASS 0 +#define BTM_BLE_SCAN_MODE_ACTI 1 +#define BTM_BLE_SCAN_MODE_NONE 0xff +typedef UINT8 tBLE_SCAN_MODE; + +#define BTM_BLE_BATCH_SCAN_MODE_DISABLE 0 +#define BTM_BLE_BATCH_SCAN_MODE_PASS 1 +#define BTM_BLE_BATCH_SCAN_MODE_ACTI 2 +#define BTM_BLE_BATCH_SCAN_MODE_PASS_ACTI 3 + +typedef UINT8 tBTM_BLE_BATCH_SCAN_MODE; + +/* advertising channel map */ +#define BTM_BLE_ADV_CHNL_37 (0x01 << 0) +#define BTM_BLE_ADV_CHNL_38 (0x01 << 1) +#define BTM_BLE_ADV_CHNL_39 (0x01 << 2) +typedef UINT8 tBTM_BLE_ADV_CHNL_MAP; + +/*d efault advertising channel map */ +#ifndef BTM_BLE_DEFAULT_ADV_CHNL_MAP +#define BTM_BLE_DEFAULT_ADV_CHNL_MAP (BTM_BLE_ADV_CHNL_37| BTM_BLE_ADV_CHNL_38| BTM_BLE_ADV_CHNL_39) +#endif + +/* advertising filter policy */ +#define AP_SCAN_CONN_ALL 0x00 /* default */ +#define AP_SCAN_WL_CONN_ALL 0x01 +#define AP_SCAN_ALL_CONN_WL 0x02 +#define AP_SCAN_CONN_WL 0x03 +#define AP_SCAN_CONN_POLICY_MAX 0x04 +typedef UINT8 tBTM_BLE_AFP; + +/* default advertising filter policy */ +#ifndef BTM_BLE_DEFAULT_AFP +#define BTM_BLE_DEFAULT_AFP AP_SCAN_CONN_ALL +#endif + +/* scanning filter policy */ +#define SP_ADV_ALL 0x00 /* 0: accept adv packet from all, directed adv pkt not directed */ +/* to local device is ignored */ +#define SP_ADV_WL 0x01 /* 1: accept adv packet from device in white list, directed adv */ +/* packet not directed to local device is ignored */ +#define SP_ADV_ALL_RPA_DIR_ADV 0x02 /* 2: accept adv packet from all, directed adv pkt */ +/* not directed to me is ignored except direct adv with RPA */ +#define SP_ADV_WL_RPA_DIR_ADV 0x03 /* 3: accept adv packet from device in white list, directed */ +/* adv pkt not directed to me is ignored except direct adv */ +/* with RPA */ +typedef UINT8 tBTM_BLE_SFP; + +#ifndef BTM_BLE_DEFAULT_SFP +#define BTM_BLE_DEFAULT_SFP SP_ADV_ALL +#endif + +/* adv parameter boundary values */ +#define BTM_BLE_ADV_INT_MIN 0x0020 +#define BTM_BLE_ADV_INT_MAX 0x4000 + +/* Full scan boundary values */ +#define BTM_BLE_ADV_SCAN_FULL_MIN 0x00 +#define BTM_BLE_ADV_SCAN_FULL_MAX 0x64 + +/* Partial scan boundary values */ +#define BTM_BLE_ADV_SCAN_TRUNC_MIN BTM_BLE_ADV_SCAN_FULL_MIN +#define BTM_BLE_ADV_SCAN_TRUNC_MAX BTM_BLE_ADV_SCAN_FULL_MAX + +/* Threshold values */ +#define BTM_BLE_ADV_SCAN_THR_MIN BTM_BLE_ADV_SCAN_FULL_MIN +#define BTM_BLE_ADV_SCAN_THR_MAX BTM_BLE_ADV_SCAN_FULL_MAX + +/* connection parameter boundary values */ +#define BTM_BLE_SCAN_INT_MIN 0x0004 +#define BTM_BLE_SCAN_INT_MAX 0x4000 +#define BTM_BLE_SCAN_WIN_MIN 0x0004 +#define BTM_BLE_SCAN_WIN_MAX 0x4000 +#define BTM_BLE_EXT_SCAN_INT_MAX 0x00FFFFFF +#define BTM_BLE_EXT_SCAN_WIN_MAX 0xFFFF +#define BTM_BLE_CONN_INT_MIN 0x0006 +#define BTM_BLE_CONN_INT_MAX 0x0C80 +#define BTM_BLE_CONN_LATENCY_MAX 500 +#define BTM_BLE_CONN_SUP_TOUT_MIN 0x000A +#define BTM_BLE_CONN_SUP_TOUT_MAX 0x0C80 +#define BTM_BLE_CONN_PARAM_UNDEF 0xffff /* use this value when a specific value not to be overwritten */ +#define BTM_BLE_SCAN_PARAM_UNDEF 0xffffffff + +/* default connection parameters if not configured, use GAP recommend value for auto/selective connection */ +/* default scan interval */ +#ifndef BTM_BLE_SCAN_FAST_INT +#define BTM_BLE_SCAN_FAST_INT 96 /* 30 ~ 60 ms (use 60) = 96 *0.625 */ +#endif +/* default scan window for background connection, applicable for auto connection or selective conenction */ +#ifndef BTM_BLE_SCAN_FAST_WIN +#define BTM_BLE_SCAN_FAST_WIN 48 /* 30 ms = 48 *0.625 */ +#endif + +/* default scan paramter used in reduced power cycle (background scanning) */ +#ifndef BTM_BLE_SCAN_SLOW_INT_1 +#define BTM_BLE_SCAN_SLOW_INT_1 2048 /* 1.28 s = 2048 *0.625 */ +#endif +#ifndef BTM_BLE_SCAN_SLOW_WIN_1 +#define BTM_BLE_SCAN_SLOW_WIN_1 48 /* 30 ms = 48 *0.625 */ +#endif + +/* default scan paramter used in reduced power cycle (background scanning) */ +#ifndef BTM_BLE_SCAN_SLOW_INT_2 +#define BTM_BLE_SCAN_SLOW_INT_2 4096 /* 2.56 s = 4096 *0.625 */ +#endif +#ifndef BTM_BLE_SCAN_SLOW_WIN_2 +#define BTM_BLE_SCAN_SLOW_WIN_2 36 /* 22.5 ms = 36 *0.625 */ +#endif + +/* default connection interval min */ +#ifndef BTM_BLE_CONN_INT_MIN_DEF +#define BTM_BLE_CONN_INT_MIN_DEF 24 /* recommended min: 30ms = 24 * 1.25 */ +#endif + +/* default connection interval max */ +#ifndef BTM_BLE_CONN_INT_MAX_DEF +#define BTM_BLE_CONN_INT_MAX_DEF 40 /* recommended max: 50 ms = 56 * 1.25 */ +#endif + +/* default slave latency */ +#ifndef BTM_BLE_CONN_SLAVE_LATENCY_DEF +#define BTM_BLE_CONN_SLAVE_LATENCY_DEF 0 /* 0 */ +#endif + +/* default supervision timeout */ +#ifndef BTM_BLE_CONN_TIMEOUT_DEF +#define BTM_BLE_CONN_TIMEOUT_DEF 2000 +#endif + +/* minimum acceptable connection interval */ +#ifndef BTM_BLE_CONN_INT_MIN_LIMIT +#define BTM_BLE_CONN_INT_MIN_LIMIT 0x0009 +#endif + +#define BTM_BLE_DIR_CONN_FALLBACK_UNDIR 1 +#define BTM_BLE_DIR_CONN_FALLBACK_NO_ADV 2 + +#ifndef BTM_BLE_DIR_CONN_FALLBACK +#define BTM_BLE_DIR_CONN_FALLBACK BTM_BLE_DIR_CONN_FALLBACK_UNDIR +#endif + +#define BTM_CMAC_TLEN_SIZE 8 /* 64 bits */ +#define BTM_BLE_AUTH_SIGN_LEN 12 /* BLE data signature length 8 Bytes + 4 bytes counter*/ +typedef UINT8 BLE_SIGNATURE[BTM_BLE_AUTH_SIGN_LEN]; /* Device address */ + +#ifndef BTM_BLE_HOST_SUPPORT +#define BTM_BLE_HOST_SUPPORT 0x01 +#endif + +#ifndef BTM_BLE_SIMULTANEOUS_HOST +#define BTM_BLE_SIMULTANEOUS_HOST 0x01 +#endif + +/* Appearance Values Reported with BTM_BLE_AD_TYPE_APPEARANCE */ +#define BTM_BLE_APPEARANCE_UKNOWN 0x0000 +#define BTM_BLE_APPEARANCE_GENERIC_PHONE 0x0040 +#define BTM_BLE_APPEARANCE_GENERIC_COMPUTER 0x0080 +#define BTM_BLE_APPEARANCE_GENERIC_WATCH 0x00C0 +#define BTM_BLE_APPEARANCE_SPORTS_WATCH 0x00C1 +#define BTM_BLE_APPEARANCE_GENERIC_CLOCK 0x0100 +#define BTM_BLE_APPEARANCE_GENERIC_DISPLAY 0x0140 +#define BTM_BLE_APPEARANCE_GENERIC_REMOTE 0x0180 +#define BTM_BLE_APPEARANCE_GENERIC_EYEGLASSES 0x01C0 +#define BTM_BLE_APPEARANCE_GENERIC_TAG 0x0200 +#define BTM_BLE_APPEARANCE_GENERIC_KEYRING 0x0240 +#define BTM_BLE_APPEARANCE_GENERIC_MEDIA_PLAYER 0x0280 +#define BTM_BLE_APPEARANCE_GENERIC_BARCODE_SCANNER 0x02C0 +#define BTM_BLE_APPEARANCE_GENERIC_THERMOMETER 0x0300 +#define BTM_BLE_APPEARANCE_THERMOMETER_EAR 0x0301 +#define BTM_BLE_APPEARANCE_GENERIC_HEART_RATE 0x0340 +#define BTM_BLE_APPEARANCE_HEART_RATE_BELT 0x0341 +#define BTM_BLE_APPEARANCE_GENERIC_BLOOD_PRESSURE 0x0380 +#define BTM_BLE_APPEARANCE_BLOOD_PRESSURE_ARM 0x0381 +#define BTM_BLE_APPEARANCE_BLOOD_PRESSURE_WRIST 0x0382 +#define BTM_BLE_APPEARANCE_GENERIC_HID 0x03C0 +#define BTM_BLE_APPEARANCE_HID_KEYBOARD 0x03C1 +#define BTM_BLE_APPEARANCE_HID_MOUSE 0x03C2 +#define BTM_BLE_APPEARANCE_HID_JOYSTICK 0x03C3 +#define BTM_BLE_APPEARANCE_HID_GAMEPAD 0x03C4 +#define BTM_BLE_APPEARANCE_HID_DIGITIZER_TABLET 0x03C5 +#define BTM_BLE_APPEARANCE_HID_CARD_READER 0x03C6 +#define BTM_BLE_APPEARANCE_HID_DIGITAL_PEN 0x03C7 +#define BTM_BLE_APPEARANCE_HID_BARCODE_SCANNER 0x03C8 +#define BTM_BLE_APPEARANCE_GENERIC_GLUCOSE 0x0400 +#define BTM_BLE_APPEARANCE_GENERIC_WALKING 0x0440 +#define BTM_BLE_APPEARANCE_WALKING_IN_SHOE 0x0441 +#define BTM_BLE_APPEARANCE_WALKING_ON_SHOE 0x0442 +#define BTM_BLE_APPEARANCE_WALKING_ON_HIP 0x0443 +#define BTM_BLE_APPEARANCE_GENERIC_CYCLING 0x0480 +#define BTM_BLE_APPEARANCE_CYCLING_COMPUTER 0x0481 +#define BTM_BLE_APPEARANCE_CYCLING_SPEED 0x0482 +#define BTM_BLE_APPEARANCE_CYCLING_CADENCE 0x0483 +#define BTM_BLE_APPEARANCE_CYCLING_POWER 0x0484 +#define BTM_BLE_APPEARANCE_CYCLING_SPEED_CADENCE 0x0485 +#define BTM_BLE_APPEARANCE_GENERIC_PULSE_OXIMETER 0x0C40 +#define BTM_BLE_APPEARANCE_PULSE_OXIMETER_FINGERTIP 0x0C41 +#define BTM_BLE_APPEARANCE_PULSE_OXIMETER_WRIST 0x0C42 +#define BTM_BLE_APPEARANCE_GENERIC_WEIGHT 0x0C80 +#define BTM_BLE_APPEARANCE_GENERIC_OUTDOOR_SPORTS 0x1440 +#define BTM_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION 0x1441 +#define BTM_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION_AND_NAV 0x1442 +#define BTM_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION_POD 0x1443 +#define BTM_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION_POD_AND_NAV 0x1444 + + +/* Structure returned with Rand/Encrypt complete callback */ +typedef struct { + UINT8 status; + UINT8 param_len; + UINT16 opcode; + UINT8 param_buf[BT_OCTET16_LEN]; +} tBTM_RAND_ENC; + +/* General callback function for notifying an application that a synchronous +** BTM function is complete. The pointer contains the address of any returned data. +*/ +typedef void (tBTM_RAND_ENC_CB) (tBTM_RAND_ENC *p1); + +#define BTM_BLE_FILTER_TARGET_SCANNER 0x01 +#define BTM_BLE_FILTER_TARGET_ADVR 0x00 + +#define BTM_BLE_POLICY_BLACK_ALL 0x00 /* relevant to both */ +#define BTM_BLE_POLICY_ALLOW_SCAN 0x01 /* relevant to advertiser */ +#define BTM_BLE_POLICY_ALLOW_CONN 0x02 /* relevant to advertiser */ +#define BTM_BLE_POLICY_WHITE_ALL 0x03 /* relevant to both */ + +/* ADV data flag bit definition used for BTM_BLE_AD_TYPE_FLAG */ +#define BTM_BLE_LIMIT_DISC_FLAG (0x01 << 0) +#define BTM_BLE_GEN_DISC_FLAG (0x01 << 1) +#define BTM_BLE_BREDR_NOT_SPT (0x01 << 2) +/* 4.1 spec adv flag for simultaneous BR/EDR+LE connection support */ +#define BTM_BLE_DMT_CONTROLLER_SPT (0x01 << 3) +#define BTM_BLE_DMT_HOST_SPT (0x01 << 4) +#define BTM_BLE_NON_LIMIT_DISC_FLAG (0x00 ) /* lowest bit unset */ +#define BTM_BLE_ADV_FLAG_MASK (BTM_BLE_LIMIT_DISC_FLAG | BTM_BLE_BREDR_NOT_SPT | BTM_BLE_GEN_DISC_FLAG) +#define BTM_BLE_LIMIT_DISC_MASK (BTM_BLE_LIMIT_DISC_FLAG ) + +#define BTM_BLE_AD_BIT_DEV_NAME (0x00000001 << 0) +#define BTM_BLE_AD_BIT_FLAGS (0x00000001 << 1) +#define BTM_BLE_AD_BIT_MANU (0x00000001 << 2) +#define BTM_BLE_AD_BIT_TX_PWR (0x00000001 << 3) +#define BTM_BLE_AD_BIT_INT_RANGE (0x00000001 << 5) +#define BTM_BLE_AD_BIT_SERVICE (0x00000001 << 6) +#define BTM_BLE_AD_BIT_SERVICE_SOL (0x00000001 << 7) +#define BTM_BLE_AD_BIT_SERVICE_DATA (0x00000001 << 8) +#define BTM_BLE_AD_BIT_SIGN_DATA (0x00000001 << 9) +#define BTM_BLE_AD_BIT_SERVICE_128SOL (0x00000001 << 10) +#define BTM_BLE_AD_BIT_APPEARANCE (0x00000001 << 11) +#define BTM_BLE_AD_BIT_PUBLIC_ADDR (0x00000001 << 12) +#define BTM_BLE_AD_BIT_RANDOM_ADDR (0x00000001 << 13) +#define BTM_BLE_AD_BIT_SERVICE_32 (0x00000001 << 4) +#define BTM_BLE_AD_BIT_SERVICE_32SOL (0x00000001 << 14) +#define BTM_BLE_AD_BIT_PROPRIETARY (0x00000001 << 15) +#define BTM_BLE_AD_BIT_SERVICE_128 (0x00000001 << 16) /*128-bit Service UUIDs*/ + +typedef UINT32 tBTM_BLE_AD_MASK; + +#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 */ +#define BTM_BLE_AD_TYPE_32SRV_PART HCI_EIR_MORE_32BITS_UUID_TYPE /* 0x04 */ +#define BTM_BLE_AD_TYPE_32SRV_CMPL HCI_EIR_COMPLETE_32BITS_UUID_TYPE /* 0x05 */ +#define BTM_BLE_AD_TYPE_128SRV_PART HCI_EIR_MORE_128BITS_UUID_TYPE /* 0x06 */ +#define BTM_BLE_AD_TYPE_128SRV_CMPL HCI_EIR_COMPLETE_128BITS_UUID_TYPE /* 0x07 */ +#define BTM_BLE_AD_TYPE_NAME_SHORT HCI_EIR_SHORTENED_LOCAL_NAME_TYPE /* 0x08 */ +#define BTM_BLE_AD_TYPE_NAME_CMPL HCI_EIR_COMPLETE_LOCAL_NAME_TYPE /* 0x09 */ +#define BTM_BLE_AD_TYPE_TX_PWR HCI_EIR_TX_POWER_LEVEL_TYPE /* 0x0A */ +#define BTM_BLE_AD_TYPE_DEV_CLASS 0x0D +#define BTM_BLE_AD_TYPE_SM_TK 0x10 +#define BTM_BLE_AD_TYPE_SM_OOB_FLAG 0x11 +#define BTM_BLE_AD_TYPE_INT_RANGE 0x12 +#define BTM_BLE_AD_TYPE_SOL_SRV_UUID 0x14 +#define BTM_BLE_AD_TYPE_128SOL_SRV_UUID 0x15 +#define BTM_BLE_AD_TYPE_SERVICE_DATA 0x16 +#define BTM_BLE_AD_TYPE_PUBLIC_TARGET 0x17 +#define BTM_BLE_AD_TYPE_RANDOM_TARGET 0x18 +#define BTM_BLE_AD_TYPE_APPEARANCE 0x19 +#define BTM_BLE_AD_TYPE_ADV_INT 0x1a +#define BTM_BLE_AD_TYPE_32SOL_SRV_UUID 0x1b +#define BTM_BLE_AD_TYPE_32SERVICE_DATA 0x1c +#define BTM_BLE_AD_TYPE_128SERVICE_DATA 0x1d + +#define BTM_BLE_AD_TYPE_MANU HCI_EIR_MANUFACTURER_SPECIFIC_TYPE /* 0xff */ +typedef UINT8 tBTM_BLE_AD_TYPE; + +/* Security settings used with L2CAP LE COC */ +#define BTM_SEC_LE_LINK_ENCRYPTED 0x01 +#define BTM_SEC_LE_LINK_PAIRED_WITHOUT_MITM 0x02 +#define BTM_SEC_LE_LINK_PAIRED_WITH_MITM 0x04 + +/* Min/max Preferred number of payload octets that the local Controller + should include in a single Link Layer Data Channel PDU. */ +#define BTM_BLE_DATA_SIZE_MAX 0x00fb +#define BTM_BLE_DATA_SIZE_MIN 0x001b + +/* Preferred maximum number of microseconds that the local Controller + should use to transmit a single Link Layer Data Channel PDU. */ +#define BTM_BLE_DATA_TX_TIME_MIN 0x0148 +#define BTM_BLE_DATA_TX_TIME_MAX 0x0848 + +/* adv tx power level */ +#define BTM_BLE_ADV_TX_POWER_MIN 0 /* minimum tx power */ +#define BTM_BLE_ADV_TX_POWER_LOW 1 /* low tx power */ +#define BTM_BLE_ADV_TX_POWER_MID 2 /* middle tx power */ +#define BTM_BLE_ADV_TX_POWER_UPPER 3 /* upper tx power */ +#define BTM_BLE_ADV_TX_POWER_MAX 4 /* maximum tx power */ +typedef UINT8 tBTM_BLE_ADV_TX_POWER; + +/* adv tx power in dBm */ +typedef struct { + UINT8 adv_inst_max; /* max adv instance supported in controller */ + UINT8 rpa_offloading; + UINT16 tot_scan_results_strg; + UINT8 max_irk_list_sz; + UINT8 filter_support; + UINT8 max_filter; + UINT8 energy_support; + BOOLEAN values_read; + UINT16 version_supported; + UINT16 total_trackable_advertisers; + UINT8 extended_scan_support; + UINT8 debug_logging_supported; +} tBTM_BLE_VSC_CB; + +/* slave preferred connection interval range */ +typedef struct { + UINT16 low; + UINT16 hi; + +} tBTM_BLE_INT_RANGE; + +/* Service tag supported in the device */ +typedef struct { + UINT8 num_service; + BOOLEAN list_cmpl; + UINT16 *p_uuid; +} tBTM_BLE_SERVICE; + +/* 32 bits Service supported in the device */ +typedef struct { + UINT8 num_service; + BOOLEAN list_cmpl; + UINT32 *p_uuid; +} tBTM_BLE_32SERVICE; + +/* 128 bits Service supported in the device */ +typedef struct { + BOOLEAN list_cmpl; + UINT8 uuid128[MAX_UUID_SIZE]; +} tBTM_BLE_128SERVICE; + +typedef struct { + UINT8 len; + UINT8 *p_val; +} tBTM_BLE_MANU; + + +typedef struct { + tBT_UUID service_uuid; + UINT8 len; + UINT8 *p_val; +} tBTM_BLE_SERVICE_DATA; + +typedef struct { + UINT8 adv_type; + UINT8 len; + UINT8 *p_val; /* number of len byte */ +} tBTM_BLE_PROP_ELEM; + +typedef struct { + UINT8 num_elem; + tBTM_BLE_PROP_ELEM *p_elem; +} tBTM_BLE_PROPRIETARY; + +typedef struct { + tBTM_BLE_INT_RANGE int_range; /* slave prefered conn interval range */ + tBTM_BLE_MANU *p_manu; /* manufactuer data */ + tBTM_BLE_SERVICE *p_services; /* services */ + tBTM_BLE_128SERVICE *p_services_128b; /* 128 bits service */ + tBTM_BLE_32SERVICE *p_service_32b; /* 32 bits Service UUID */ + tBTM_BLE_SERVICE *p_sol_services; /* 16 bits services Solicitation UUIDs */ + tBTM_BLE_32SERVICE *p_sol_service_32b; /* List of 32 bit Service Solicitation UUIDs */ + tBTM_BLE_128SERVICE *p_sol_service_128b; /* List of 128 bit Service Solicitation UUIDs */ + tBTM_BLE_PROPRIETARY *p_proprietary; + tBTM_BLE_SERVICE_DATA *p_service_data; /* service data */ + UINT16 appearance; + UINT8 flag; + UINT8 tx_power; +} tBTM_BLE_ADV_DATA; + +#ifndef BTM_BLE_MULTI_ADV_MAX +#define BTM_BLE_MULTI_ADV_MAX 16 /* controller returned adv_inst_max should be less + than this number */ +#endif + +#define BTM_BLE_MULTI_ADV_INVALID 0 + +#define BTM_BLE_MULTI_ADV_ENB_EVT 1 +#define BTM_BLE_MULTI_ADV_DISABLE_EVT 2 +#define BTM_BLE_MULTI_ADV_PARAM_EVT 3 +#define BTM_BLE_MULTI_ADV_DATA_EVT 4 +typedef UINT8 tBTM_BLE_MULTI_ADV_EVT; + +#define BTM_BLE_MULTI_ADV_DEFAULT_STD 0 + +typedef struct { + UINT16 adv_int_min; + UINT16 adv_int_max; + UINT8 adv_type; + tBTM_BLE_ADV_CHNL_MAP channel_map; + tBTM_BLE_AFP adv_filter_policy; + tBTM_BLE_ADV_TX_POWER tx_power; +} tBTM_BLE_ADV_PARAMS; + +typedef struct { + UINT8 *p_sub_code; /* dynamic array to store sub code */ + UINT8 *p_inst_id; /* dynamic array to store instance id */ + UINT8 pending_idx; + UINT8 next_idx; +} tBTM_BLE_MULTI_ADV_OPQ; + +typedef void (tBTM_BLE_MULTI_ADV_CBACK)(tBTM_BLE_MULTI_ADV_EVT evt, UINT8 inst_id, + void *p_ref, tBTM_STATUS status); + +typedef struct { + UINT8 inst_id; + BOOLEAN in_use; + UINT8 adv_evt; + BD_ADDR rpa; + TIMER_LIST_ENT raddr_timer_ent; + tBTM_BLE_MULTI_ADV_CBACK *p_cback; + void *p_ref; + UINT8 index; +} tBTM_BLE_MULTI_ADV_INST; + +typedef struct { + UINT8 inst_index_queue[BTM_BLE_MULTI_ADV_MAX]; + int front; + int rear; +} tBTM_BLE_MULTI_ADV_INST_IDX_Q; + +typedef struct { + tBTM_BLE_MULTI_ADV_INST *p_adv_inst; /* dynamic array to store adv instance */ + tBTM_BLE_MULTI_ADV_OPQ op_q; +} tBTM_BLE_MULTI_ADV_CB; + +typedef UINT8 tGATT_IF; + +typedef void (tBTM_BLE_SCAN_THRESHOLD_CBACK)(tBTM_BLE_REF_VALUE ref_value); +typedef void (tBTM_BLE_SCAN_REP_CBACK)(tBTM_BLE_REF_VALUE ref_value, UINT8 report_format, + UINT8 num_records, UINT16 total_len, + UINT8 *p_rep_data, UINT8 status); +typedef void (tBTM_BLE_SCAN_SETUP_CBACK)(UINT8 evt, tBTM_BLE_REF_VALUE ref_value, UINT8 status); + +#ifndef BTM_BLE_BATCH_SCAN_MAX +#define BTM_BLE_BATCH_SCAN_MAX 5 +#endif + +#ifndef BTM_BLE_BATCH_REP_MAIN_Q_SIZE +#define BTM_BLE_BATCH_REP_MAIN_Q_SIZE 2 +#endif + +typedef enum { + BTM_BLE_SCAN_INVALID_STATE = 0, + BTM_BLE_SCAN_ENABLE_CALLED = 1, + BTM_BLE_SCAN_ENABLED_STATE = 2, + BTM_BLE_SCAN_DISABLE_CALLED = 3, + BTM_BLE_SCAN_DISABLED_STATE = 4 +} tBTM_BLE_BATCH_SCAN_STATE; + +enum { + BTM_BLE_DISCARD_OLD_ITEMS, + BTM_BLE_DISCARD_LOWER_RSSI_ITEMS +}; +typedef UINT8 tBTM_BLE_DISCARD_RULE; + +typedef struct { + UINT8 sub_code[BTM_BLE_BATCH_SCAN_MAX]; + tBTM_BLE_BATCH_SCAN_STATE cur_state[BTM_BLE_BATCH_SCAN_MAX]; + tBTM_BLE_REF_VALUE ref_value[BTM_BLE_BATCH_SCAN_MAX]; + UINT8 pending_idx; + UINT8 next_idx; +} tBTM_BLE_BATCH_SCAN_OPQ; + +typedef struct { + UINT8 rep_mode[BTM_BLE_BATCH_REP_MAIN_Q_SIZE]; + tBTM_BLE_REF_VALUE ref_value[BTM_BLE_BATCH_REP_MAIN_Q_SIZE]; + UINT8 num_records[BTM_BLE_BATCH_REP_MAIN_Q_SIZE]; + UINT16 data_len[BTM_BLE_BATCH_REP_MAIN_Q_SIZE]; + UINT8 *p_data[BTM_BLE_BATCH_REP_MAIN_Q_SIZE]; + UINT8 pending_idx; + UINT8 next_idx; +} tBTM_BLE_BATCH_SCAN_REP_Q; + +typedef struct { + tBTM_BLE_BATCH_SCAN_STATE cur_state; + tBTM_BLE_BATCH_SCAN_MODE scan_mode; + UINT32 scan_interval; + UINT32 scan_window; + tBLE_ADDR_TYPE addr_type; + tBTM_BLE_DISCARD_RULE discard_rule; + tBTM_BLE_BATCH_SCAN_OPQ op_q; + tBTM_BLE_BATCH_SCAN_REP_Q main_rep_q; + tBTM_BLE_SCAN_SETUP_CBACK *p_setup_cback; + tBTM_BLE_SCAN_THRESHOLD_CBACK *p_thres_cback; + tBTM_BLE_SCAN_REP_CBACK *p_scan_rep_cback; + tBTM_BLE_REF_VALUE ref_value; +} tBTM_BLE_BATCH_SCAN_CB; + +/* filter selection bit index */ +#define BTM_BLE_PF_ADDR_FILTER 0 +#define BTM_BLE_PF_SRVC_DATA 1 +#define BTM_BLE_PF_SRVC_UUID 2 +#define BTM_BLE_PF_SRVC_SOL_UUID 3 +#define BTM_BLE_PF_LOCAL_NAME 4 +#define BTM_BLE_PF_MANU_DATA 5 +#define BTM_BLE_PF_SRVC_DATA_PATTERN 6 +#define BTM_BLE_PF_TYPE_ALL 7 /* when passed in payload filter type all, only clear action is applicable */ +#define BTM_BLE_PF_TYPE_MAX 8 + +/* max number of filter spot for different filter type */ +#ifndef BTM_BLE_MAX_UUID_FILTER +#define BTM_BLE_MAX_UUID_FILTER 8 +#endif +#ifndef BTM_BLE_MAX_ADDR_FILTER +#define BTM_BLE_MAX_ADDR_FILTER 8 +#endif +#ifndef BTM_BLE_PF_STR_COND_MAX +#define BTM_BLE_PF_STR_COND_MAX 4 /* apply to manu data , or local name */ +#endif +#ifndef BTM_BLE_PF_STR_LEN_MAX +#define BTM_BLE_PF_STR_LEN_MAX 29 /* match for first 29 bytes */ +#endif + +typedef UINT8 tBTM_BLE_PF_COND_TYPE; + +#define BTM_BLE_PF_LOGIC_OR 0 +#define BTM_BLE_PF_LOGIC_AND 1 +typedef UINT8 tBTM_BLE_PF_LOGIC_TYPE; + +#define BTM_BLE_PF_ENABLE 1 +#define BTM_BLE_PF_CONFIG 2 +typedef UINT8 tBTM_BLE_PF_ACTION; + +typedef UINT8 tBTM_BLE_PF_FILT_INDEX; + +typedef UINT8 tBTM_BLE_PF_AVBL_SPACE; + +#define BTM_BLE_PF_BRDCAST_ADDR_FILT 1 +#define BTM_BLE_PF_SERV_DATA_CHG_FILT 2 +#define BTM_BLE_PF_SERV_UUID 4 +#define BTM_BLE_PF_SERV_SOLC_UUID 8 +#define BTM_BLE_PF_LOC_NAME_CHECK 16 +#define BTM_BLE_PF_MANUF_NAME_CHECK 32 +#define BTM_BLE_PF_SERV_DATA_CHECK 64 +typedef UINT16 tBTM_BLE_PF_FEAT_SEL; + +#define BTM_BLE_PF_LIST_LOGIC_OR 1 +#define BTM_BLE_PF_LIST_LOGIC_AND 2 +typedef UINT16 tBTM_BLE_PF_LIST_LOGIC_TYPE; + +#define BTM_BLE_PF_FILT_LOGIC_OR 0 +#define BTM_BLE_PF_FILT_LOGIC_AND 1 +typedef UINT16 tBTM_BLE_PF_FILT_LOGIC_TYPE; + +typedef UINT8 tBTM_BLE_PF_RSSI_THRESHOLD; +typedef UINT8 tBTM_BLE_PF_DELIVERY_MODE; +typedef UINT16 tBTM_BLE_PF_TIMEOUT; +typedef UINT8 tBTM_BLE_PF_TIMEOUT_CNT; +typedef UINT16 tBTM_BLE_PF_ADV_TRACK_ENTRIES; + +typedef struct { + tBTM_BLE_PF_FEAT_SEL feat_seln; + tBTM_BLE_PF_LIST_LOGIC_TYPE logic_type; + tBTM_BLE_PF_FILT_LOGIC_TYPE filt_logic_type; + tBTM_BLE_PF_RSSI_THRESHOLD rssi_high_thres; + tBTM_BLE_PF_RSSI_THRESHOLD rssi_low_thres; + tBTM_BLE_PF_DELIVERY_MODE dely_mode; + tBTM_BLE_PF_TIMEOUT found_timeout; + tBTM_BLE_PF_TIMEOUT lost_timeout; + tBTM_BLE_PF_TIMEOUT_CNT found_timeout_cnt; + tBTM_BLE_PF_ADV_TRACK_ENTRIES num_of_tracking_entries; +} tBTM_BLE_PF_FILT_PARAMS; + +enum { + BTM_BLE_SCAN_COND_ADD, + BTM_BLE_SCAN_COND_DELETE, + BTM_BLE_SCAN_COND_CLEAR = 2 +}; +typedef UINT8 tBTM_BLE_SCAN_COND_OP; + +enum { + BTM_BLE_FILT_ENABLE_DISABLE = 1, + BTM_BLE_FILT_CFG = 2, + BTM_BLE_FILT_ADV_PARAM = 3 +}; + +typedef UINT8 tBTM_BLE_FILT_CB_EVT; + +/* BLE adv payload filtering config complete callback */ +typedef void (tBTM_BLE_PF_CFG_CBACK)(tBTM_BLE_PF_ACTION action, tBTM_BLE_SCAN_COND_OP cfg_op, + tBTM_BLE_PF_AVBL_SPACE avbl_space, tBTM_STATUS status, + tBTM_BLE_REF_VALUE ref_value); + +typedef void (tBTM_BLE_PF_CMPL_CBACK) (tBTM_BLE_PF_CFG_CBACK); + +/* BLE adv payload filtering status setup complete callback */ +typedef void (tBTM_BLE_PF_STATUS_CBACK) (UINT8 action, tBTM_STATUS status, + tBTM_BLE_REF_VALUE ref_value); + +/* BLE adv payload filtering param setup complete callback */ +typedef void (tBTM_BLE_PF_PARAM_CBACK) (tBTM_BLE_PF_ACTION action_type, + tBTM_BLE_PF_AVBL_SPACE avbl_space, + tBTM_BLE_REF_VALUE ref_value, tBTM_STATUS status); + +typedef union { + UINT16 uuid16_mask; + UINT32 uuid32_mask; + UINT8 uuid128_mask[LEN_UUID_128]; +} tBTM_BLE_PF_COND_MASK; + +typedef struct { + tBLE_BD_ADDR *p_target_addr; /* target address, if NULL, generic UUID filter */ + tBT_UUID uuid; /* UUID condition */ + tBTM_BLE_PF_LOGIC_TYPE cond_logic; /* AND/OR */ + tBTM_BLE_PF_COND_MASK *p_uuid_mask; /* UUID mask */ +} tBTM_BLE_PF_UUID_COND; + +typedef struct { + UINT8 data_len; /* <= 20 bytes */ + UINT8 *p_data; +} tBTM_BLE_PF_LOCAL_NAME_COND; + +typedef struct { + UINT16 company_id; /* company ID */ + UINT8 data_len; /* <= 20 bytes */ + UINT8 *p_pattern; + UINT16 company_id_mask; /* UUID value mask */ + UINT8 *p_pattern_mask; /* Manufacturer data matching mask, + same length as data pattern, + set to all 0xff, match exact data */ +} tBTM_BLE_PF_MANU_COND; + +typedef struct { + UINT16 uuid; /* service ID */ + UINT8 data_len; /* <= 20 bytes */ + UINT8 *p_pattern; + UINT8 *p_pattern_mask; /* Service data matching mask, same length as data pattern, + set to all 0xff, match exact data */ +} tBTM_BLE_PF_SRVC_PATTERN_COND; + + +typedef union { + tBLE_BD_ADDR target_addr; + tBTM_BLE_PF_LOCAL_NAME_COND local_name; /* lcoal name filtering */ + tBTM_BLE_PF_MANU_COND manu_data; /* manufactuer data filtering */ + tBTM_BLE_PF_UUID_COND srvc_uuid; /* service UUID filtering */ + tBTM_BLE_PF_UUID_COND solicitate_uuid; /* solicitated service UUID filtering */ + tBTM_BLE_PF_SRVC_PATTERN_COND srvc_data; /* service data pattern */ +} tBTM_BLE_PF_COND_PARAM; + +typedef struct { + UINT8 action_ocf[BTM_BLE_PF_TYPE_MAX]; + tBTM_BLE_REF_VALUE ref_value[BTM_BLE_PF_TYPE_MAX]; + tBTM_BLE_PF_PARAM_CBACK *p_filt_param_cback[BTM_BLE_PF_TYPE_MAX]; + tBTM_BLE_PF_CFG_CBACK *p_scan_cfg_cback[BTM_BLE_PF_TYPE_MAX]; + UINT8 cb_evt[BTM_BLE_PF_TYPE_MAX]; + UINT8 pending_idx; + UINT8 next_idx; +} tBTM_BLE_ADV_FILTER_ADV_OPQ; + +#define BTM_BLE_MAX_FILTER_COUNTER (BTM_BLE_MAX_ADDR_FILTER + 1) /* per device filter + one generic filter indexed by 0 */ + +#ifndef BTM_CS_IRK_LIST_MAX +#define BTM_CS_IRK_LIST_MAX 0x20 +#endif + +typedef struct { + BOOLEAN in_use; + BD_ADDR bd_addr; + UINT8 pf_counter[BTM_BLE_PF_TYPE_MAX]; /* number of filter indexed by tBTM_BLE_PF_COND_TYPE */ +} tBTM_BLE_PF_COUNT; + +typedef struct { + BOOLEAN enable; + UINT8 op_type; + tBTM_BLE_PF_COUNT *p_addr_filter_count; /* per BDA filter array */ + tBLE_BD_ADDR cur_filter_target; + tBTM_BLE_PF_STATUS_CBACK *p_filt_stat_cback; + tBTM_BLE_ADV_FILTER_ADV_OPQ op_q; +} tBTM_BLE_ADV_FILTER_CB; + +/* Sub codes */ +#define BTM_BLE_META_PF_ENABLE 0x00 +#define BTM_BLE_META_PF_FEAT_SEL 0x01 +#define BTM_BLE_META_PF_ADDR 0x02 +#define BTM_BLE_META_PF_UUID 0x03 +#define BTM_BLE_META_PF_SOL_UUID 0x04 +#define BTM_BLE_META_PF_LOCAL_NAME 0x05 +#define BTM_BLE_META_PF_MANU_DATA 0x06 +#define BTM_BLE_META_PF_SRVC_DATA 0x07 +#define BTM_BLE_META_PF_ALL 0x08 + +typedef UINT8 BTM_BLE_ADV_STATE; +typedef UINT8 BTM_BLE_ADV_INFO_PRESENT; +typedef UINT8 BTM_BLE_RSSI_VALUE; +typedef UINT16 BTM_BLE_ADV_INFO_TIMESTAMP; + +/* These are the fields returned in each device adv packet. It +** is returned in the results callback if registered. +*/ +typedef struct { + UINT8 conn_mode; + tBTM_BLE_AD_MASK ad_mask; /* mask of the valid adv data field */ + UINT8 flag; + UINT8 tx_power_level; + UINT8 remote_name_len; + UINT8 *p_remote_name; + tBTM_BLE_SERVICE service; +} tBTM_BLE_INQ_DATA; + +enum { + BTM_BLE_CONN_NONE, + BTM_BLE_CONN_AUTO, + BTM_BLE_CONN_SELECTIVE +}; +typedef UINT8 tBTM_BLE_CONN_TYPE; + +#define ADV_INFO_PRESENT 0x00 +#define NO_ADV_INFO_PRESENT 0x01 + +typedef btgatt_track_adv_info_t tBTM_BLE_TRACK_ADV_DATA; + +typedef void (tBTM_BLE_TRACK_ADV_CBACK)(tBTM_BLE_TRACK_ADV_DATA *p_track_adv_data); + +typedef UINT8 tBTM_BLE_TRACK_ADV_EVT; + +typedef struct { + tBTM_BLE_REF_VALUE ref_value; + tBTM_BLE_TRACK_ADV_CBACK *p_track_cback; +} tBTM_BLE_ADV_TRACK_CB; + +enum { + BTM_BLE_TRACK_ADV_ADD, + BTM_BLE_TRACK_ADV_REMOVE +}; + +typedef UINT8 tBTM_BLE_TRACK_ADV_ACTION; + +#define BTM_BLE_MULTI_ADV_INVALID 0 + +#define BTM_BLE_BATCH_SCAN_ENABLE_EVT 1 +#define BTM_BLE_BATCH_SCAN_CFG_STRG_EVT 2 +#define BTM_BLE_BATCH_SCAN_READ_REPTS_EVT 3 +#define BTM_BLE_BATCH_SCAN_THR_EVT 4 +#define BTM_BLE_BATCH_SCAN_PARAM_EVT 5 +#define BTM_BLE_BATCH_SCAN_DISABLE_EVT 6 + +typedef UINT8 tBTM_BLE_BATCH_SCAN_EVT; + +typedef UINT32 tBTM_BLE_TX_TIME_MS; +typedef UINT32 tBTM_BLE_RX_TIME_MS; +typedef UINT32 tBTM_BLE_IDLE_TIME_MS; +typedef UINT32 tBTM_BLE_ENERGY_USED; + +typedef void (tBTM_BLE_ENERGY_INFO_CBACK)(tBTM_BLE_TX_TIME_MS tx_time, tBTM_BLE_RX_TIME_MS rx_time, + tBTM_BLE_IDLE_TIME_MS idle_time, + tBTM_BLE_ENERGY_USED energy_used, + tBTM_STATUS status); + +typedef struct { + tBTM_BLE_ENERGY_INFO_CBACK *p_ener_cback; +} tBTM_BLE_ENERGY_INFO_CB; + +typedef BOOLEAN (tBTM_BLE_SEL_CBACK)(BD_ADDR random_bda, UINT8 *p_remote_name); +typedef void (tBTM_BLE_CTRL_FEATURES_CBACK)(tBTM_STATUS status); + +/* callback function for SMP signing algorithm, signed data in little endian order with tlen bits long */ +typedef void (tBTM_BLE_SIGN_CBACK)(void *p_ref_data, UINT8 *p_signing_data); +typedef void (tBTM_BLE_VERIFY_CBACK)(void *p_ref_data, BOOLEAN match); +/* random address set complete callback */ +typedef void (tBTM_BLE_RANDOM_SET_CBACK) (BD_ADDR random_bda); + +typedef void (tBTM_BLE_SCAN_REQ_CBACK)(BD_ADDR remote_bda, tBLE_ADDR_TYPE addr_type, UINT8 adv_evt); +typedef void (*tBLE_SCAN_PARAM_SETUP_CBACK)(tGATT_IF client_if, tBTM_STATUS status); + +tBTM_BLE_SCAN_SETUP_CBACK bta_ble_scan_setup_cb; + +/***************************************************************************** +** EXTERNAL FUNCTION DECLARATIONS +*****************************************************************************/ +/* +#ifdef __cplusplus +extern "C" { +#endif +*/ +/******************************************************************************* +** +** Function BTM_SecAddBleDevice +** +** Description Add/modify device. This function will be normally called +** during host startup to restore all required information +** for a LE device stored in the NVRAM. +** +** Parameters: bd_addr - BD address of the peer +** bd_name - Name of the peer device. NULL if unknown. +** dev_type - Remote device's device type. +** addr_type - LE device address type. +** +** Returns TRUE if added OK, else FALSE +** +*******************************************************************************/ +//extern +BOOLEAN BTM_SecAddBleDevice (BD_ADDR bd_addr, BD_NAME bd_name, + tBT_DEVICE_TYPE dev_type, tBLE_ADDR_TYPE addr_type); + +/******************************************************************************* +** +** Function BTM_SecAddBleKey +** +** Description Add/modify LE device information. This function will be +** normally called during host startup to restore all required +** information stored in the NVRAM. +** +** Parameters: bd_addr - BD address of the peer +** p_le_key - LE key values. +** key_type - LE SMP key type. +* +** Returns TRUE if added OK, else FALSE +** +*******************************************************************************/ +//extern +BOOLEAN BTM_SecAddBleKey (BD_ADDR bd_addr, tBTM_LE_KEY_VALUE *p_le_key, + tBTM_LE_KEY_TYPE key_type); + +/******************************************************************************* +** +** Function BTM_BleSetAdvParams +** +** Description This function is called to set advertising parameters. +** +** Parameters: None. +** +** Returns void +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_BleSetAdvParams(UINT16 adv_int_min, UINT16 adv_int_max, + tBLE_BD_ADDR *p_dir_bda, tBTM_BLE_ADV_CHNL_MAP chnl_map); + + + +/******************************************************************************* +** +** Function BTM_BleSetAdvParamsStartAdv +** +** Description This function is called to set all of the advertising parameters. +** +** Parameters: None. +** +** Returns void +** +*******************************************************************************/ +tBTM_STATUS BTM_BleSetAdvParamsStartAdv(UINT16 adv_int_min, UINT16 adv_int_max, UINT8 adv_type, + tBLE_ADDR_TYPE own_bda_type, tBLE_BD_ADDR *p_dir_bda, + tBTM_BLE_ADV_CHNL_MAP chnl_map, tBTM_BLE_AFP afp); + + +/******************************************************************************* +** +** Function BTM_BleWriteAdvData +** +** Description This function is called to write advertising data. +** +** Parameters: None. +** +** Returns void +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_BleWriteAdvData(tBTM_BLE_AD_MASK data_mask, + tBTM_BLE_ADV_DATA *p_data); + +/******************************************************************************* +** +** Function BTM_BleWriteAdvDataRaw +** +** Description This function is called to write raw advertising data. +** +** Parameters: p_raw_adv : point to raw advertising data +** raw_adv_len : raw advertising data +** +** Returns BTM_SUCCESS means success. +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_BleWriteAdvDataRaw(UINT8 *p_raw_adv, UINT32 raw_adv_len); + + +BOOLEAN BTM_BleSetRandAddress(BD_ADDR rand_addr); + + +/******************************************************************************* +** +** Function BTM_BleSetAdvParams +** +** Description This function is called to set advertising parameters. +** +** Parameters adv_int_min: minimum advertising interval +** adv_int_max: maximum advertising interval +** p_dir_bda: connectable direct initiator's LE device address +** chnl_map: advertising channel map. +** +** Returns void +** +*******************************************************************************/ +//extern +void BTM_BleReadAdvParams (UINT16 *adv_int_min, UINT16 *adv_int_max, + tBLE_BD_ADDR *p_dir_bda, tBTM_BLE_ADV_CHNL_MAP *p_chnl_map); + +/******************************************************************************* +** +** Function BTM_BleObtainVendorCapabilities +** +** Description This function is called to obatin vendor capabilties +** +** Parameters p_cmn_vsc_cb - Returns the vednor capabilities +** +** Returns void +** +*******************************************************************************/ +//extern +void BTM_BleObtainVendorCapabilities(tBTM_BLE_VSC_CB *p_cmn_vsc_cb); + +/******************************************************************************* +** +** Function BTM_BleSetScanParams +** +** Description This function is called to set Scan parameters. +** +** Parameters client_if - Client IF value +** scan_interval - Scan interval +** scan_window - Scan window +** scan_type - Scan type +** scan_setup_status_cback - Scan setup status callback +** +** Returns void +** +*******************************************************************************/ +//extern +void BTM_BleSetScanParams(tGATT_IF client_if, UINT32 scan_interval, + UINT32 scan_window, tBLE_SCAN_MODE scan_type, + tBLE_SCAN_PARAM_SETUP_CBACK scan_setup_status_cback); + + + +/******************************************************************************* +** +** Function BTM_BleSetScanFilterParams +** +** Description This function is called to set Scan Filter & parameters. +** +** Parameters client_if - Client IF value +** scan_interval - Scan interval +** scan_window - Scan window +** scan_type - Scan type +** addr_type_own - owner address type +** scan_filter_policy - scan filter policy +** scan_setup_status_cback - Scan setup status callback +** +** Returns void +** +*******************************************************************************/ +void BTM_BleSetScanFilterParams(tGATT_IF client_if, UINT32 scan_interval, UINT32 scan_window, + tBLE_SCAN_MODE scan_mode, UINT8 addr_type_own, tBTM_BLE_SFP scan_filter_policy, + tBLE_SCAN_PARAM_SETUP_CBACK scan_setup_status_cback); + + +/******************************************************************************* +** +** Function BTM_BleGetVendorCapabilities +** +** Description This function reads local LE features +** +** Parameters p_cmn_vsc_cb : Locala LE capability structure +** +** Returns void +** +*******************************************************************************/ +//extern +void BTM_BleGetVendorCapabilities(tBTM_BLE_VSC_CB *p_cmn_vsc_cb); +/******************************************************************************* +** +** Function BTM_BleSetStorageConfig +** +** Description This function is called to setup storage configuration and setup callbacks. +** +** Parameters UINT8 batch_scan_full_max -Batch scan full maximum + UINT8 batch_scan_trunc_max - Batch scan truncated value maximum + UINT8 batch_scan_notify_threshold - Threshold value + tBTM_BLE_SCAN_SETUP_CBACK *p_setup_cback - Setup callback + tBTM_BLE_SCAN_THRESHOLD_CBACK *p_thres_cback -Threshold callback + void *p_ref - Reference value +** +** Returns tBTM_STATUS +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_BleSetStorageConfig(UINT8 batch_scan_full_max, + UINT8 batch_scan_trunc_max, + UINT8 batch_scan_notify_threshold, + tBTM_BLE_SCAN_SETUP_CBACK *p_setup_cback, + tBTM_BLE_SCAN_THRESHOLD_CBACK *p_thres_cback, + tBTM_BLE_SCAN_REP_CBACK *p_cback, + tBTM_BLE_REF_VALUE ref_value); + +/******************************************************************************* +** +** Function BTM_BleEnableBatchScan +** +** Description This function is called to enable batch scan +** +** Parameters tBTM_BLE_BATCH_SCAN_MODE scan_mode - Batch scan mode + UINT32 scan_interval -Scan interval + UINT32 scan_window - Scan window value + tBLE_ADDR_TYPE addr_type - Address type + tBTM_BLE_DISCARD_RULE discard_rule - Data discard rules +** +** Returns tBTM_STATUS +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_BleEnableBatchScan(tBTM_BLE_BATCH_SCAN_MODE scan_mode, + UINT32 scan_interval, UINT32 scan_window, + tBTM_BLE_DISCARD_RULE discard_rule, + tBLE_ADDR_TYPE addr_type, + tBTM_BLE_REF_VALUE ref_value); + +/******************************************************************************* +** +** Function BTM_BleDisableBatchScan +** +** Description This function is called to disable batch scanning +** +** Parameters void +** +** Returns void +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_BleDisableBatchScan(tBTM_BLE_REF_VALUE ref_value); + +/******************************************************************************* +** +** Function BTM_BleReadScanReports +** +** Description This function is called to read batch scan reports +** +** Parameters tBLE_SCAN_MODE scan_mode - Scan mode report to be read out + tBTM_BLE_SCAN_REP_CBACK* p_cback - Reports callback +** +** Returns tBTM_STATUS +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_BleReadScanReports(tBLE_SCAN_MODE scan_mode, + tBTM_BLE_REF_VALUE ref_value); + +/******************************************************************************* +** +** Function BTM_BleTrackAdvertiser +** +** Description This function is called to read batch scan reports +** +** Parameters p_track_cback - Tracking callback +** ref_value - Reference value +** +** Returns tBTM_STATUS +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_BleTrackAdvertiser(tBTM_BLE_TRACK_ADV_CBACK *p_track_cback, + tBTM_BLE_REF_VALUE ref_value); + +/******************************************************************************* +** +** Function BTM_BleWriteScanRsp +** +** Description This function is called to write LE scan response. +** +** Parameters: p_scan_rsp: scan response. +** +** Returns status +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_BleWriteScanRsp(tBTM_BLE_AD_MASK data_mask, + tBTM_BLE_ADV_DATA *p_data); + +/******************************************************************************* +** +** Function BTM_BleWriteScanRspRaw +** +** Description This function is called to write raw scan response data +** +** Parameters: None. +** +** Returns void +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_BleWriteScanRspRaw(UINT8 *p_raw_scan_rsp, UINT32 raw_scan_rsp_len); + +/******************************************************************************* +** +** Function BTM_BleObserve +** +** Description This procedure keep the device listening for advertising +** events from a broadcast device. +** +** Parameters start: start or stop observe. +** +** Returns void +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_BleObserve(BOOLEAN start, UINT8 duration, + tBTM_INQ_RESULTS_CB *p_results_cb, tBTM_CMPL_CB *p_cmpl_cb); + + +/******************************************************************************* +** +** Function BTM_GetDeviceIDRoot +** +** Description This function is called to read the local device identity +** root. +** +** Returns void +** the local device ER is copied into er +** +*******************************************************************************/ +//extern +void BTM_GetDeviceIDRoot (BT_OCTET16 ir); + +/******************************************************************************* +** +** Function BTM_GetDeviceEncRoot +** +** Description This function is called to read the local device encryption +** root. +** +** Returns void +** the local device ER is copied into er +** +*******************************************************************************/ +//extern +void BTM_GetDeviceEncRoot (BT_OCTET16 er); + +/******************************************************************************* +** +** Function BTM_GetDeviceDHK +** +** Description This function is called to read the local device DHK. +** +** Returns void +** the local device DHK is copied into dhk +** +*******************************************************************************/ +//extern +void BTM_GetDeviceDHK (BT_OCTET16 dhk); + +/******************************************************************************* +** +** Function BTM_SecurityGrant +** +** Description This function is called to grant security process. +** +** Parameters bd_addr - peer device bd address. +** res - result of the operation BTM_SUCCESS if success. +** Otherwise, BTM_REPEATED_ATTEMPTS is too many attempts. +** +** Returns None +** +*******************************************************************************/ +//extern +void BTM_SecurityGrant(BD_ADDR bd_addr, UINT8 res); + +/******************************************************************************* +** +** Function BTM_BlePasskeyReply +** +** Description This function is called after Security Manager submitted +** passkey request to the application. +** +** Parameters: bd_addr - Address of the device for which passkey was requested +** res - result of the operation SMP_SUCCESS if success +** passkey - numeric value in the range of +** BTM_MIN_PASSKEY_VAL(0) - BTM_MAX_PASSKEY_VAL(999999(0xF423F)). +** +*******************************************************************************/ +//extern +void BTM_BlePasskeyReply (BD_ADDR bd_addr, UINT8 res, UINT32 passkey); + +/******************************************************************************* +** +** Function BTM_BleConfirmReply +** +** Description This function is called after Security Manager submitted +** numeric comparison request to the application. +** +** Parameters: bd_addr - Address of the device with which numeric +** comparison was requested +** res - comparison result BTM_SUCCESS if success +** +*******************************************************************************/ +//extern +void BTM_BleConfirmReply (BD_ADDR bd_addr, UINT8 res); + +/******************************************************************************* +** +** Function BTM_LeOobDataReply +** +** Description This function is called to provide the OOB data for +** SMP in response to BTM_LE_OOB_REQ_EVT +** +** Parameters: bd_addr - Address of the peer device +** res - result of the operation SMP_SUCCESS if success +** p_data - simple pairing Randomizer C. +** +*******************************************************************************/ +//extern +void BTM_BleOobDataReply(BD_ADDR bd_addr, UINT8 res, UINT8 len, UINT8 *p_data); + + +/******************************************************************************* +** +** Function BTM_BleDataSignature +** +** Description This function is called to sign the data using AES128 CMAC +** algorith. +** +** Parameter bd_addr: target device the data to be signed for. +** p_text: singing data +** len: length of the signing data +** signature: output parameter where data signature is going to +** be stored. +** +** Returns TRUE if signing sucessul, otherwise FALSE. +** +*******************************************************************************/ +//extern +BOOLEAN BTM_BleDataSignature (BD_ADDR bd_addr, UINT8 *p_text, UINT16 len, + BLE_SIGNATURE signature); + +/******************************************************************************* +** +** Function BTM_BleVerifySignature +** +** Description This function is called to verify the data signature +** +** Parameter bd_addr: target device the data to be signed for. +** p_orig: original data before signature. +** len: length of the signing data +** counter: counter used when doing data signing +** p_comp: signature to be compared against. + +** Returns TRUE if signature verified correctly; otherwise FALSE. +** +*******************************************************************************/ +//extern +BOOLEAN BTM_BleVerifySignature (BD_ADDR bd_addr, UINT8 *p_orig, + UINT16 len, UINT32 counter, + UINT8 *p_comp); + +/******************************************************************************* +** +** Function BTM_ReadConnectionAddr +** +** Description This function is called to set the local device random address +** . +** +** Returns void +** +*******************************************************************************/ +//extern +void BTM_ReadConnectionAddr (BD_ADDR remote_bda, BD_ADDR local_conn_addr, + tBLE_ADDR_TYPE *p_addr_type); + + + +/******************************************************************************* +** +** Function BTM_ReadRemoteConnectionAddr +** +** Description This function is read the remote device address currently used +** . +** +** Returns void +** +*******************************************************************************/ +//extern +BOOLEAN BTM_ReadRemoteConnectionAddr(BD_ADDR pseudo_addr, + BD_ADDR conn_addr, + tBLE_ADDR_TYPE *p_addr_type); + +/******************************************************************************* +** +** Function BTM_BleLoadLocalKeys +** +** Description Local local identity key, encryption root or sign counter. +** +** Parameters: key_type: type of key, can be BTM_BLE_KEY_TYPE_ID, BTM_BLE_KEY_TYPE_ER +** or BTM_BLE_KEY_TYPE_COUNTER. +** p_key: pointer to the key. +* +** Returns non2. +** +*******************************************************************************/ +//extern +void BTM_BleLoadLocalKeys(UINT8 key_type, tBTM_BLE_LOCAL_KEYS *p_key); + + +/******************************************************************************* +** +** Function BTM_BleSetBgConnType +** +** Description This function is called to set BLE background connection +** procedure type. It can be auto connection, or selective connection. +** +** Parameters conn_type: it can be auto connection, or selective connection. +** p_select_cback: callback function when selective connection procedure +** is being used. +** +** Returns void +** +*******************************************************************************/ +//extern +BOOLEAN BTM_BleSetBgConnType(tBTM_BLE_CONN_TYPE conn_type, + tBTM_BLE_SEL_CBACK *p_select_cback); + +/******************************************************************************* +** +** Function BTM_BleUpdateBgConnDev +** +** Description This function is called to add or remove a device into/from +** background connection procedure. The background connection +* procedure is decided by the background connection type, it can be +* auto connection, or selective connection. +** +** Parameters add_remove: TRUE to add; FALSE to remove. +** remote_bda: device address to add/remove. +** +** Returns void +** +*******************************************************************************/ +//extern +BOOLEAN BTM_BleUpdateBgConnDev(BOOLEAN add_remove, BD_ADDR remote_bda); + +/******************************************************************************* +** +** Function BTM_BleClearBgConnDev +** +** Description This function is called to clear the whitelist, +** end any pending whitelist connections, +* and reset the local bg device list. +** +** Parameters void +** +** Returns void +** +*******************************************************************************/ +//extern +void BTM_BleClearBgConnDev(void); + +/******************************************************** +** +** Function BTM_BleSetPrefConnParams +** +** Description Set a peripheral's preferred connection parameters. When +** any of the value does not want to be updated while others +** do, use BTM_BLE_CONN_PARAM_UNDEF for the ones want to +** leave untouched. +** +** Parameters: bd_addr - BD address of the peripheral +** min_conn_int - minimum preferred connection interval +** max_conn_int - maximum preferred connection interval +** slave_latency - preferred slave latency +** supervision_tout - preferred supervision timeout +** +** Returns void +** +*******************************************************************************/ +//extern +void BTM_BleSetPrefConnParams (BD_ADDR bd_addr, + UINT16 min_conn_int, UINT16 max_conn_int, + UINT16 slave_latency, UINT16 supervision_tout); + +/****************************************************************************** +** +** Function BTM_BleSetConnScanParams +** +** Description Set scan parameters used in BLE connection request +** +** Parameters: scan_interval - scan interval +** scan_window - scan window +** +** Returns void +** +*******************************************************************************/ +//extern +void BTM_BleSetConnScanParams (UINT32 scan_interval, UINT32 scan_window); + +/****************************************************************************** +** +** Function BTM_BleReadControllerFeatures +** +** Description Reads BLE specific controller features +** +** Parameters: tBTM_BLE_CTRL_FEATURES_CBACK : Callback to notify when features are read +** +** Returns void +** +*******************************************************************************/ +//extern +void BTM_BleReadControllerFeatures(tBTM_BLE_CTRL_FEATURES_CBACK *p_vsc_cback); + +/******************************************************************************* +** +** Function BTM_CheckAdvData +** +** Description This function is called to get ADV data for a specific type. +** +** Parameters p_adv - pointer of ADV data +** type - finding ADV data type +** p_length - return the length of ADV data not including type +** +** Returns pointer of ADV data +** +*******************************************************************************/ +//extern +UINT8 *BTM_CheckAdvData( UINT8 *p_adv, UINT8 type, UINT8 *p_length); + +/******************************************************************************* +** +** Function BTM__BLEReadDiscoverability +** +** Description This function is called to read the current LE discoverability +** mode of the device. +** +** Returns BTM_BLE_NON_DISCOVERABLE ,BTM_BLE_LIMITED_DISCOVERABLE or +** BTM_BLE_GENRAL_DISCOVERABLE +** +*******************************************************************************/ +UINT16 BTM_BleReadDiscoverability(); + +/******************************************************************************* +** +** Function BTM__BLEReadConnectability +** +** Description This function is called to read the current LE connectibility +** mode of the device. +** +** Returns BTM_BLE_NON_CONNECTABLE or BTM_BLE_CONNECTABLE +** +*******************************************************************************/ +//extern +UINT16 BTM_BleReadConnectability (); + +/******************************************************************************* +** +** Function BTM_ReadDevInfo +** +** Description This function is called to read the device/address type +** of BD address. +** +** Parameter remote_bda: remote device address +** p_dev_type: output parameter to read the device type. +** p_addr_type: output parameter to read the address type. +** +*******************************************************************************/ +//extern +void BTM_ReadDevInfo (BD_ADDR remote_bda, tBT_DEVICE_TYPE *p_dev_type, + tBLE_ADDR_TYPE *p_addr_type); + + +/******************************************************************************* +** +** Function BTM_ReadConnectedTransportAddress +** +** Description This function is called to read the paired device/address type of other device paired +** corresponding to the BD_address +** +** Parameter remote_bda: remote device address, carry out the transport address +** transport: active transport +** +** Return TRUE if an active link is identified; FALSE otherwise +** +*******************************************************************************/ +//extern +BOOLEAN BTM_ReadConnectedTransportAddress(BD_ADDR remote_bda, + tBT_TRANSPORT transport); + +/******************************************************************************* +** +** Function BTM_BleBroadcast +** +** Description This function is to start or stop broadcasting. +** +** Parameters start: start or stop broadcasting. +** +** Returns status. +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_BleBroadcast(BOOLEAN start); + +/******************************************************************************* +** +** Function BTM_BleConfigPrivacy +** +** Description This function is called to enable or disable the privacy in +** the local device. +** +** Parameters enable: TRUE to enable it; FALSE to disable it. +** +** Returns BOOLEAN privacy mode set success; otherwise failed. +** +*******************************************************************************/ +//extern +BOOLEAN BTM_BleConfigPrivacy(BOOLEAN enable); + +/******************************************************************************* +** +** Function BTM_BleLocalPrivacyEnabled +** +** Description Checks if local device supports private address +** +** Returns Return TRUE if local privacy is enabled else FALSE +** +*******************************************************************************/ +//extern +BOOLEAN BTM_BleLocalPrivacyEnabled(void); + +/******************************************************************************* +** +** Function BTM_BleEnableMixedPrivacyMode +** +** Description This function is called to enabled Mixed mode if privacy 1.2 +** is applicable in controller. +** +** Parameters mixed_on: mixed mode to be used or not. +** +** Returns void +** +*******************************************************************************/ +//extern +void BTM_BleEnableMixedPrivacyMode(BOOLEAN mixed_on); + +/******************************************************************************* +** +** Function BTM_BleMaxMultiAdvInstanceCount +** +** Description Returns max number of multi adv instances supported by controller +** +** Returns Max multi adv instance count +** +*******************************************************************************/ +//extern +UINT8 BTM_BleMaxMultiAdvInstanceCount(); + +/******************************************************************************* +** +** Function BTM_BleSetConnectableMode +** +** Description This function is called to set BLE connectable mode for a +** peripheral device. +** +** Parameters connectable_mode: directed connectable mode, or non-directed.It can +** be BTM_BLE_CONNECT_EVT, BTM_BLE_CONNECT_DIR_EVT or +** BTM_BLE_CONNECT_LO_DUTY_DIR_EVT +** +** Returns BTM_ILLEGAL_VALUE if controller does not support BLE. +** BTM_SUCCESS is status set successfully; otherwise failure. +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_BleSetConnectableMode(tBTM_BLE_CONN_MODE connectable_mode); + +/******************************************************************************* +** +** Function BTM_BleTurnOnPrivacyOnRemote +** +** Description This function is called to enable or disable the privacy on the +** remote device. +** +** Parameters bd_addr: remote device address. +** privacy_on: TRUE to enable it; FALSE to disable it. +** +** Returns void +** +*******************************************************************************/ +//extern +void BTM_BleTurnOnPrivacyOnRemote(BD_ADDR bd_addr, + BOOLEAN privacy_on); + +/******************************************************************************* +** +** Function BTM_BleUpdateAdvWhitelist +** +** Description Add or remove device from advertising white list +** +** Returns void +** +*******************************************************************************/ +//extern +BOOLEAN BTM_BleUpdateAdvWhitelist(BOOLEAN add_remove, BD_ADDR emote_bda); + +/******************************************************************************* +** +** Function BTM_BleUpdateAdvFilterPolicy +** +** Description This function update the filter policy of advertiser. +** +** Parameter adv_policy: advertising filter policy +** +** Return void +*******************************************************************************/ +//extern +void BTM_BleUpdateAdvFilterPolicy(tBTM_BLE_AFP adv_policy); + +/******************************************************************************* +** +** Function BTM_BleReceiverTest +** +** Description This function is called to start the LE Receiver test +** +** Parameter rx_freq - Frequency Range +** p_cmd_cmpl_cback - Command Complete callback +** +*******************************************************************************/ +void BTM_BleReceiverTest(UINT8 rx_freq, tBTM_CMPL_CB *p_cmd_cmpl_cback); + + +/******************************************************************************* +** +** Function BTM_BleTransmitterTest +** +** Description This function is called to start the LE Transmitter test +** +** Parameter tx_freq - Frequency Range +** test_data_len - Length in bytes of payload data in each packet +** packet_payload - Pattern to use in the payload +** p_cmd_cmpl_cback - Command Complete callback +** +*******************************************************************************/ +void BTM_BleTransmitterTest(UINT8 tx_freq, UINT8 test_data_len, + UINT8 packet_payload, tBTM_CMPL_CB *p_cmd_cmpl_cback); + +/******************************************************************************* +** +** Function BTM_BleTestEnd +** +** Description This function is called to stop the in-progress TX or RX test +** +** Parameter p_cmd_cmpl_cback - Command complete callback +** +*******************************************************************************/ +void BTM_BleTestEnd(tBTM_CMPL_CB *p_cmd_cmpl_cback); + +/******************************************************************************* +** +** Function BTM_UseLeLink +** +** Description This function is to select the underneath physical link to use. +** +** Returns TRUE to use LE, FALSE use BR/EDR. +** +*******************************************************************************/ +//extern +BOOLEAN BTM_UseLeLink (BD_ADDR bd_addr); + +/******************************************************************************* +** +** Function BTM_BleStackEnable +** +** Description Enable/Disable BLE functionality on stack regarless controller +** capability. +** +** Parameters: enable: TRUE to enable, FALSE to disable. +** +** Returns TRUE if added OK, else FALSE +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_BleStackEnable (BOOLEAN enable); + +/******************************************************************************* +** +** Function BTM_GetLeSecurityState +** +** Description This function is called to get security mode 1 flags and +** encryption key size for LE peer. +** +** Returns BOOLEAN TRUE if LE device is found, FALSE otherwise. +** +*******************************************************************************/ +//extern +BOOLEAN BTM_GetLeSecurityState (BD_ADDR bd_addr, + UINT8 *p_le_dev_sec_flags, + UINT8 *p_le_key_size); + +/******************************************************************************* +** +** Function BTM_BleSecurityProcedureIsRunning +** +** Description This function indicates if LE security procedure is +** currently running with the peer. +** +** Returns BOOLEAN TRUE if security procedure is running, FALSE otherwise. +** +*******************************************************************************/ +//extern +BOOLEAN BTM_BleSecurityProcedureIsRunning (BD_ADDR bd_addr); + +/******************************************************************************* +** +** Function BTM_BleGetSupportedKeySize +** +** Description This function gets the maximum encryption key size in bytes +** the local device can suport. +** record. +** +** Returns the key size or 0 if the size can't be retrieved. +** +*******************************************************************************/ +//extern +UINT8 BTM_BleGetSupportedKeySize (BD_ADDR bd_addr); + +/*******************************************************************************/ +/* Multi ADV API */ +/******************************************************************************* +** +** Function BTM_BleEnableAdvInstance +** +** Description This function enable a Multi-ADV instance with the specified +** adv parameters +** +** Parameters p_params: pointer to the adv parameter structure, set as default +** adv parameter when the instance is enabled. +** p_cback: callback function for the adv instance. +** p_ref: reference data attach to the adv instance to be enabled. +** +** Returns status +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_BleEnableAdvInstance (tBTM_BLE_ADV_PARAMS *p_params, + tBTM_BLE_MULTI_ADV_CBACK *p_cback, + void *p_ref); + +/******************************************************************************* +** +** Function BTM_BleUpdateAdvInstParam +** +** Description This function update a Multi-ADV instance with the specififed +** adv parameters. +** +** Parameters inst_id: adv instance ID +** p_params: pointer to the adv parameter structure. +** +** Returns status +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_BleUpdateAdvInstParam (UINT8 inst_id, tBTM_BLE_ADV_PARAMS *p_params); + +/******************************************************************************* +** +** Function BTM_BleCfgAdvInstData +** +** Description This function configure a Multi-ADV instance with the specified +** adv data or scan response data. +** +** Parameters inst_id: adv instance ID +** is_scan_rsp: is this scacn response, if no set as adv data. +** data_mask: adv data mask. +** p_data: pointer to the adv data structure. +** +** Returns status +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_BleCfgAdvInstData (UINT8 inst_id, BOOLEAN is_scan_rsp, + tBTM_BLE_AD_MASK data_mask, + tBTM_BLE_ADV_DATA *p_data); + +/******************************************************************************* +** +** Function BTM_BleDisableAdvInstance +** +** Description This function disable a Multi-ADV instance. +** +** Parameters inst_id: adv instance ID +** +** Returns status +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_BleDisableAdvInstance (UINT8 inst_id); + +/******************************************************************************* +** +** Function BTM_BleAdvFilterParamSetup +** +** Description This function is called to setup the adv data payload filter +** condition. +** +** Parameters p_target: enabble the filter condition on a target device; if NULL +** enable the generic scan condition. +** enable: enable or disable the filter condition +** +** Returns void +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_BleAdvFilterParamSetup(int action, + tBTM_BLE_PF_FILT_INDEX filt_index, + tBTM_BLE_PF_FILT_PARAMS *p_filt_params, + tBLE_BD_ADDR *p_target, tBTM_BLE_PF_PARAM_CBACK *p_cmpl_cback, + tBTM_BLE_REF_VALUE ref_value); + +/******************************************************************************* +** +** Function BTM_BleCfgFilterCondition +** +** Description This function is called to configure the adv data payload filter +** condition. +** +** Parameters action: to read/write/clear +** cond_type: filter condition type. +** p_cond: filter condition paramter +** +** Returns tBTM_STATUS +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_BleCfgFilterCondition(tBTM_BLE_SCAN_COND_OP action, + tBTM_BLE_PF_COND_TYPE cond_type, + tBTM_BLE_PF_FILT_INDEX filt_index, + tBTM_BLE_PF_COND_PARAM *p_cond, + tBTM_BLE_PF_CFG_CBACK *p_cmpl_cback, + tBTM_BLE_REF_VALUE ref_value); + +/******************************************************************************* +** +** Function BTM_BleEnableDisableFilterFeature +** +** Description This function is called to enable or disable the APCF feature +** +** Parameters enable - TRUE - enables the APCF, FALSE - disables the APCF +** ref_value - Ref value +** +** Returns tBTM_STATUS +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_BleEnableDisableFilterFeature(UINT8 enable, + tBTM_BLE_PF_STATUS_CBACK *p_stat_cback, + tBTM_BLE_REF_VALUE ref_value); + +/******************************************************************************* +** +** Function BTM_BleGetEnergyInfo +** +** Description This function obtains the energy info +** +** Parameters p_ener_cback - Callback pointer +** +** Returns status +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_BleGetEnergyInfo(tBTM_BLE_ENERGY_INFO_CBACK *p_ener_cback); + +/******************************************************************************* +** +** Function BTM_SetBleDataLength +** +** Description This function is called to set maximum BLE transmission packet size +** +** Returns BTM_SUCCESS if success; otherwise failed. +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_SetBleDataLength(BD_ADDR bd_addr, UINT16 tx_pdu_length); + +/* +#ifdef __cplusplus +} +#endif +*/ + +#endif diff --git a/tools/sdk/include/bluedroid/btm_ble_int.h b/tools/sdk/include/bluedroid/btm_ble_int.h new file mode 100644 index 00000000..8345777c --- /dev/null +++ b/tools/sdk/include/bluedroid/btm_ble_int.h @@ -0,0 +1,476 @@ +/****************************************************************************** + * + * Copyright (C) 1999-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 file contains the main Bluetooth Manager (BTM) internal + * definitions. + * + ******************************************************************************/ + +#ifndef BTM_BLE_INT_H +#define BTM_BLE_INT_H + +#include "bt_target.h" +#include "gki.h" +#include "hcidefs.h" +#include "btm_ble_api.h" +#include "btm_int.h" + +#if BLE_INCLUDED == TRUE && SMP_INCLUDED == TRUE +#include "smp_api.h" +#endif + + +/* scanning enable status */ +#define BTM_BLE_SCAN_ENABLE 0x01 +#define BTM_BLE_SCAN_DISABLE 0x00 + +/* advertising enable status */ +#define BTM_BLE_ADV_ENABLE 0x01 +#define BTM_BLE_ADV_DISABLE 0x00 + +/* use the high 4 bits unused by inquiry mode */ +#define BTM_BLE_SELECT_SCAN 0x20 +#define BTM_BLE_NAME_REQUEST 0x40 +#define BTM_BLE_OBSERVE 0x80 + +#define BTM_BLE_MAX_WL_ENTRY 1 +#define BTM_BLE_AD_DATA_LEN 31 + +#define BTM_BLE_ENC_MASK 0x03 + +#define BTM_BLE_DUPLICATE_ENABLE 1 +#define BTM_BLE_DUPLICATE_DISABLE 0 + +#define BTM_BLE_GAP_DISC_SCAN_INT 18 /* Interval(scan_int) = 11.25 ms= 0x0010 * 0.625 ms */ +#define BTM_BLE_GAP_DISC_SCAN_WIN 18 /* scan_window = 11.25 ms= 0x0010 * 0.625 ms */ +#define BTM_BLE_GAP_ADV_INT 512 /* Tgap(gen_disc) = 1.28 s= 512 * 0.625 ms */ +#define BTM_BLE_GAP_LIM_TOUT 180 /* Tgap(lim_timeout) = 180s max */ +#define BTM_BLE_LOW_LATENCY_SCAN_INT 8000 /* Interval(scan_int) = 5s= 8000 * 0.625 ms */ +#define BTM_BLE_LOW_LATENCY_SCAN_WIN 8000 /* scan_window = 5s= 8000 * 0.625 ms */ + + +#define BTM_BLE_GAP_ADV_FAST_INT_1 48 /* TGAP(adv_fast_interval1) = 30(used) ~ 60 ms = 48 *0.625 */ +#define BTM_BLE_GAP_ADV_FAST_INT_2 160 /* TGAP(adv_fast_interval2) = 100(used) ~ 150 ms = 160 * 0.625 ms */ +#define BTM_BLE_GAP_ADV_SLOW_INT 2048 /* Tgap(adv_slow_interval) = 1.28 s= 512 * 0.625 ms */ +#define BTM_BLE_GAP_ADV_DIR_MAX_INT 800 /* Tgap(dir_conn_adv_int_max) = 500 ms = 800 * 0.625 ms */ +#define BTM_BLE_GAP_ADV_DIR_MIN_INT 400 /* Tgap(dir_conn_adv_int_min) = 250 ms = 400 * 0.625 ms */ + +#define BTM_BLE_GAP_FAST_ADV_TOUT 30 + +#define BTM_BLE_SEC_REQ_ACT_NONE 0 +#define BTM_BLE_SEC_REQ_ACT_ENCRYPT 1 /* encrypt the link using current key or key refresh */ +#define BTM_BLE_SEC_REQ_ACT_PAIR 2 +#define BTM_BLE_SEC_REQ_ACT_DISCARD 3 /* discard the sec request while encryption is started but not completed */ +typedef UINT8 tBTM_BLE_SEC_REQ_ACT; + +#define BLE_STATIC_PRIVATE_MSB_MASK 0x3f +#define BLE_RESOLVE_ADDR_MSB 0x40 /* most significant bit, bit7, bit6 is 01 to be resolvable random */ +#define BLE_RESOLVE_ADDR_MASK 0xc0 /* bit 6, and bit7 */ +#define BTM_BLE_IS_RESOLVE_BDA(x) ((x[0] & BLE_RESOLVE_ADDR_MASK) == BLE_RESOLVE_ADDR_MSB) + +/* LE scan activity bit mask, continue with LE inquiry bits */ +#define BTM_LE_SELECT_CONN_ACTIVE 0x40 /* selection connection is in progress */ +#define BTM_LE_OBSERVE_ACTIVE 0x80 /* observe is in progress */ + +/* BLE scan activity mask checking */ +#define BTM_BLE_IS_SCAN_ACTIVE(x) ((x) & BTM_BLE_SCAN_ACTIVE_MASK) +#define BTM_BLE_IS_INQ_ACTIVE(x) ((x) & BTM_BLE_INQUIRY_MASK) +#define BTM_BLE_IS_OBS_ACTIVE(x) ((x) & BTM_LE_OBSERVE_ACTIVE) +#define BTM_BLE_IS_SEL_CONN_ACTIVE(x) ((x) & BTM_LE_SELECT_CONN_ACTIVE) + +/* BLE ADDR type ID bit */ +#define BLE_ADDR_TYPE_ID_BIT 0x02 + +#define BTM_VSC_CHIP_CAPABILITY_L_VERSION 55 +#define BTM_VSC_CHIP_CAPABILITY_M_VERSION 95 + +typedef struct { + UINT16 data_mask; + UINT8 *p_flags; + UINT8 ad_data[BTM_BLE_AD_DATA_LEN]; + UINT8 *p_pad; +} tBTM_BLE_LOCAL_ADV_DATA; + +typedef struct { + UINT32 inq_count; /* Used for determining if a response has already been */ + /* received for the current inquiry operation. (We do not */ + /* want to flood the caller with multiple responses from */ + /* the same device. */ + BOOLEAN scan_rsp; + tBLE_BD_ADDR le_bda; +} tINQ_LE_BDADDR; + +#define BTM_BLE_ADV_DATA_LEN_MAX 31 +#define BTM_BLE_CACHE_ADV_DATA_MAX 62 + +#define BTM_BLE_ISVALID_PARAM(x, min, max) (((x) >= (min) && (x) <= (max)) || ((x) == BTM_BLE_CONN_PARAM_UNDEF)) + +#define BTM_BLE_PRIVATE_ADDR_INT 900 /* 15 minutes minimum for random address refreshing */ + +typedef struct { + UINT16 discoverable_mode; + UINT16 connectable_mode; + UINT32 scan_window; + UINT32 scan_interval; + UINT8 scan_type; /* current scan type: active or passive */ + UINT8 scan_duplicate_filter; /* duplicate filter enabled for scan */ + UINT16 adv_interval_min; + UINT16 adv_interval_max; + tBTM_BLE_AFP afp; /* advertising filter policy */ + tBTM_BLE_SFP sfp; /* scanning filter policy */ + + tBLE_ADDR_TYPE adv_addr_type; + UINT8 evt_type; + UINT8 adv_mode; + tBLE_BD_ADDR direct_bda; + tBTM_BLE_EVT directed_conn; + BOOLEAN fast_adv_on; + TIMER_LIST_ENT fast_adv_timer; + + UINT8 adv_len; + UINT8 adv_data_cache[BTM_BLE_CACHE_ADV_DATA_MAX]; + + /* inquiry BD addr database */ + UINT8 num_bd_entries; + UINT8 max_bd_entries; + tBTM_BLE_LOCAL_ADV_DATA adv_data; + tBTM_BLE_ADV_CHNL_MAP adv_chnl_map; + + TIMER_LIST_ENT inq_timer_ent; + BOOLEAN scan_rsp; + UINT8 state; /* Current state that the inquiry process is in */ + INT8 tx_power; +} tBTM_BLE_INQ_CB; + + +/* random address resolving complete callback */ +typedef void (tBTM_BLE_RESOLVE_CBACK) (void *match_rec, void *p); + +typedef void (tBTM_BLE_ADDR_CBACK) (BD_ADDR_PTR static_random, void *p); + +/* random address management control block */ +typedef struct { + tBLE_ADDR_TYPE own_addr_type; /* local device LE address type */ + BD_ADDR private_addr; + BD_ADDR random_bda; + BOOLEAN busy; + UINT16 index; + tBTM_BLE_RESOLVE_CBACK *p_resolve_cback; + tBTM_BLE_ADDR_CBACK *p_generate_cback; + void *p; + TIMER_LIST_ENT raddr_timer_ent; +} tBTM_LE_RANDOM_CB; + +#define BTM_BLE_MAX_BG_CONN_DEV_NUM 10 + +typedef struct { + UINT16 min_conn_int; + UINT16 max_conn_int; + UINT16 slave_latency; + UINT16 supervision_tout; + +} tBTM_LE_CONN_PRAMS; + + +typedef struct { + BD_ADDR bd_addr; + UINT8 attr; + BOOLEAN is_connected; + BOOLEAN in_use; +} tBTM_LE_BG_CONN_DEV; + +/* white list using state as a bit mask */ +#define BTM_BLE_WL_IDLE 0 +#define BTM_BLE_WL_INIT 1 +#define BTM_BLE_WL_SCAN 2 +#define BTM_BLE_WL_ADV 4 +typedef UINT8 tBTM_BLE_WL_STATE; + +/* resolving list using state as a bit mask */ +#define BTM_BLE_RL_IDLE 0 +#define BTM_BLE_RL_INIT 1 +#define BTM_BLE_RL_SCAN 2 +#define BTM_BLE_RL_ADV 4 +typedef UINT8 tBTM_BLE_RL_STATE; + +/* BLE connection state */ +#define BLE_CONN_IDLE 0 +#define BLE_DIR_CONN 1 +#define BLE_BG_CONN 2 +#define BLE_CONN_CANCEL 3 +typedef UINT8 tBTM_BLE_CONN_ST; + +typedef struct { + void *p_param; +} tBTM_BLE_CONN_REQ; + +/* LE state request */ +#define BTM_BLE_STATE_INVALID 0 +#define BTM_BLE_STATE_CONN_ADV 1 +#define BTM_BLE_STATE_INIT 2 +#define BTM_BLE_STATE_MASTER 3 +#define BTM_BLE_STATE_SLAVE 4 +#define BTM_BLE_STATE_LO_DUTY_DIR_ADV 5 +#define BTM_BLE_STATE_HI_DUTY_DIR_ADV 6 +#define BTM_BLE_STATE_NON_CONN_ADV 7 +#define BTM_BLE_STATE_PASSIVE_SCAN 8 +#define BTM_BLE_STATE_ACTIVE_SCAN 9 +#define BTM_BLE_STATE_SCAN_ADV 10 +#define BTM_BLE_STATE_MAX 11 +typedef UINT8 tBTM_BLE_STATE; + +#define BTM_BLE_STATE_CONN_ADV_BIT 0x0001 +#define BTM_BLE_STATE_INIT_BIT 0x0002 +#define BTM_BLE_STATE_MASTER_BIT 0x0004 +#define BTM_BLE_STATE_SLAVE_BIT 0x0008 +#define BTM_BLE_STATE_LO_DUTY_DIR_ADV_BIT 0x0010 +#define BTM_BLE_STATE_HI_DUTY_DIR_ADV_BIT 0x0020 +#define BTM_BLE_STATE_NON_CONN_ADV_BIT 0x0040 +#define BTM_BLE_STATE_PASSIVE_SCAN_BIT 0x0080 +#define BTM_BLE_STATE_ACTIVE_SCAN_BIT 0x0100 +#define BTM_BLE_STATE_SCAN_ADV_BIT 0x0200 +typedef UINT16 tBTM_BLE_STATE_MASK; + +#define BTM_BLE_STATE_ALL_MASK 0x03ff +#define BTM_BLE_STATE_ALL_ADV_MASK (BTM_BLE_STATE_CONN_ADV_BIT|BTM_BLE_STATE_LO_DUTY_DIR_ADV_BIT|BTM_BLE_STATE_HI_DUTY_DIR_ADV_BIT|BTM_BLE_STATE_SCAN_ADV_BIT) +#define BTM_BLE_STATE_ALL_SCAN_MASK (BTM_BLE_STATE_PASSIVE_SCAN_BIT|BTM_BLE_STATE_ACTIVE_SCAN_BIT) +#define BTM_BLE_STATE_ALL_CONN_MASK (BTM_BLE_STATE_MASTER_BIT|BTM_BLE_STATE_SLAVE_BIT) + +#ifndef BTM_LE_RESOLVING_LIST_MAX +#define BTM_LE_RESOLVING_LIST_MAX 0x20 +#endif + +typedef struct { + BD_ADDR *resolve_q_random_pseudo; + UINT8 *resolve_q_action; + UINT8 q_next; + UINT8 q_pending; +} tBTM_BLE_RESOLVE_Q; + +typedef struct { + BOOLEAN in_use; + BOOLEAN to_add; + BD_ADDR bd_addr; + UINT8 attr; +} tBTM_BLE_WL_OP; + +/* BLE privacy mode */ +#define BTM_PRIVACY_NONE 0 /* BLE no privacy */ +#define BTM_PRIVACY_1_1 1 /* BLE privacy 1.1, do not support privacy 1.0 */ +#define BTM_PRIVACY_1_2 2 /* BLE privacy 1.2 */ +#define BTM_PRIVACY_MIXED 3 /* BLE privacy mixed mode, broadcom propietary mode */ +typedef UINT8 tBTM_PRIVACY_MODE; + +/* data length change event callback */ +typedef void (tBTM_DATA_LENGTH_CHANGE_CBACK) (UINT16 max_tx_length, UINT16 max_rx_length); + +/* Define BLE Device Management control structure +*/ +typedef struct { + UINT8 scan_activity; /* LE scan activity mask */ + + /***************************************************** + ** BLE Inquiry + *****************************************************/ + tBTM_BLE_INQ_CB inq_var; + + /* observer callback and timer */ + tBTM_INQ_RESULTS_CB *p_obs_results_cb; + tBTM_CMPL_CB *p_obs_cmpl_cb; + TIMER_LIST_ENT obs_timer_ent; + + /* background connection procedure cb value */ + tBTM_BLE_CONN_TYPE bg_conn_type; + UINT32 scan_int; + UINT32 scan_win; + tBTM_BLE_SEL_CBACK *p_select_cback; + + /* white list information */ + UINT8 white_list_avail_size; + tBTM_BLE_WL_STATE wl_state; + + BUFFER_Q conn_pending_q; + tBTM_BLE_CONN_ST conn_state; + + /* random address management control block */ + tBTM_LE_RANDOM_CB addr_mgnt_cb; + + BOOLEAN enabled; + +#if BLE_PRIVACY_SPT == TRUE + BOOLEAN mixed_mode; /* privacy 1.2 mixed mode is on or not */ + tBTM_PRIVACY_MODE privacy_mode; /* privacy mode */ + UINT8 resolving_list_avail_size; /* resolving list available size */ + tBTM_BLE_RESOLVE_Q resolving_list_pend_q; /* Resolving list queue */ + tBTM_BLE_RL_STATE suspended_rl_state; /* Suspended resolving list state */ + UINT8 *irk_list_mask; /* IRK list availability mask, up to max entry bits */ + tBTM_BLE_RL_STATE rl_state; /* Resolving list state */ +#endif + + tBTM_BLE_WL_OP wl_op_q[BTM_BLE_MAX_BG_CONN_DEV_NUM]; + + /* current BLE link state */ + tBTM_BLE_STATE_MASK cur_states; /* bit mask of tBTM_BLE_STATE */ + UINT8 link_count[2]; /* total link count master and slave*/ +} tBTM_BLE_CB; + +#ifdef __cplusplus +extern "C" { +#endif + +void btm_ble_timeout(TIMER_LIST_ENT *p_tle); +void btm_ble_process_adv_pkt (UINT8 *p); +void btm_ble_proc_scan_rsp_rpt (UINT8 *p); +tBTM_STATUS btm_ble_read_remote_name(BD_ADDR remote_bda, tBTM_INQ_INFO *p_cur, tBTM_CMPL_CB *p_cb); +BOOLEAN btm_ble_cancel_remote_name(BD_ADDR remote_bda); + +tBTM_STATUS btm_ble_set_discoverability(UINT16 combined_mode); +tBTM_STATUS btm_ble_set_connectability(UINT16 combined_mode); +tBTM_STATUS btm_ble_start_inquiry (UINT8 mode, UINT8 duration); +void btm_ble_stop_scan(void); +void btm_clear_all_pending_le_entry(void); + +void btm_ble_stop_scan(); +BOOLEAN btm_ble_send_extended_scan_params(UINT8 scan_type, UINT32 scan_int, + UINT32 scan_win, UINT8 addr_type_own, + UINT8 scan_filter_policy); +void btm_ble_stop_inquiry(void); +void btm_ble_init (void); +void btm_ble_connected (UINT8 *bda, UINT16 handle, UINT8 enc_mode, UINT8 role, tBLE_ADDR_TYPE addr_type, BOOLEAN addr_matched); +void btm_ble_read_remote_features_complete(UINT8 *p); +void btm_ble_write_adv_enable_complete(UINT8 *p); +void btm_ble_conn_complete(UINT8 *p, UINT16 evt_len, BOOLEAN enhanced); +void btm_read_ble_local_supported_states_complete(UINT8 *p, UINT16 evt_len); +tBTM_BLE_CONN_ST btm_ble_get_conn_st(void); +void btm_ble_set_conn_st(tBTM_BLE_CONN_ST new_st); +UINT8 *btm_ble_build_adv_data(tBTM_BLE_AD_MASK *p_data_mask, UINT8 **p_dst, + tBTM_BLE_ADV_DATA *p_data); +tBTM_STATUS btm_ble_start_adv(void); +tBTM_STATUS btm_ble_stop_adv(void); +tBTM_STATUS btm_ble_start_scan(void); +void btm_ble_create_ll_conn_complete (UINT8 status); + +/* LE security function from btm_sec.c */ +#if SMP_INCLUDED == TRUE +void btm_ble_link_sec_check(BD_ADDR bd_addr, tBTM_LE_AUTH_REQ auth_req, tBTM_BLE_SEC_REQ_ACT *p_sec_req_act); +void btm_ble_ltk_request_reply(BD_ADDR bda, BOOLEAN use_stk, BT_OCTET16 stk); +UINT8 btm_proc_smp_cback(tSMP_EVT event, BD_ADDR bd_addr, tSMP_EVT_DATA *p_data); +tBTM_STATUS btm_ble_set_encryption (BD_ADDR bd_addr, void *p_ref_data, UINT8 link_role); +void btm_ble_ltk_request(UINT16 handle, UINT8 rand[8], UINT16 ediv); +tBTM_STATUS btm_ble_start_encrypt(BD_ADDR bda, BOOLEAN use_stk, BT_OCTET16 stk); +void btm_ble_link_encrypted(BD_ADDR bd_addr, UINT8 encr_enable); +#endif + +/* LE device management functions */ +void btm_ble_reset_id( void ); + +/* security related functions */ +void btm_ble_increment_sign_ctr(BD_ADDR bd_addr, BOOLEAN is_local ); +BOOLEAN btm_get_local_div (BD_ADDR bd_addr, UINT16 *p_div); +BOOLEAN btm_ble_get_enc_key_type(BD_ADDR bd_addr, UINT8 *p_key_types); + +void btm_ble_test_command_complete(UINT8 *p); +void btm_ble_rand_enc_complete (UINT8 *p, UINT16 op_code, tBTM_RAND_ENC_CB *p_enc_cplt_cback); + +void btm_sec_save_le_key(BD_ADDR bd_addr, tBTM_LE_KEY_TYPE key_type, tBTM_LE_KEY_VALUE *p_keys, BOOLEAN pass_to_application); +void btm_ble_update_sec_key_size(BD_ADDR bd_addr, UINT8 enc_key_size); +UINT8 btm_ble_read_sec_key_size(BD_ADDR bd_addr); + +/* white list function */ +BOOLEAN btm_update_dev_to_white_list(BOOLEAN to_add, BD_ADDR bd_addr); +void btm_update_scanner_filter_policy(tBTM_BLE_SFP scan_policy); +void btm_update_adv_filter_policy(tBTM_BLE_AFP adv_policy); +void btm_ble_clear_white_list (void); +void btm_read_white_list_size_complete(UINT8 *p, UINT16 evt_len); +void btm_ble_add_2_white_list_complete(UINT8 status); +void btm_ble_remove_from_white_list_complete(UINT8 *p, UINT16 evt_len); +void btm_ble_clear_white_list_complete(UINT8 *p, UINT16 evt_len); +void btm_ble_white_list_init(UINT8 white_list_size); + +/* background connection function */ +BOOLEAN btm_ble_suspend_bg_conn(void); +BOOLEAN btm_ble_resume_bg_conn(void); +void btm_ble_initiate_select_conn(BD_ADDR bda); +BOOLEAN btm_ble_start_auto_conn(BOOLEAN start); +BOOLEAN btm_ble_start_select_conn(BOOLEAN start, tBTM_BLE_SEL_CBACK *p_select_cback); +BOOLEAN btm_ble_renew_bg_conn_params(BOOLEAN add, BD_ADDR bd_addr); +void btm_write_dir_conn_wl(BD_ADDR target_addr); +void btm_ble_update_mode_operation(UINT8 link_role, BD_ADDR bda, UINT8 status); +BOOLEAN btm_execute_wl_dev_operation(void); +void btm_ble_update_link_topology_mask(UINT8 role, BOOLEAN increase); + +/* direct connection utility */ +BOOLEAN btm_send_pending_direct_conn(void); +void btm_ble_enqueue_direct_conn_req(void *p_param); + +/* BLE address management */ +void btm_gen_resolvable_private_addr (void *p_cmd_cplt_cback); +void btm_gen_non_resolvable_private_addr (tBTM_BLE_ADDR_CBACK *p_cback, void *p); +void btm_ble_resolve_random_addr(BD_ADDR random_bda, tBTM_BLE_RESOLVE_CBACK *p_cback, void *p); +void btm_gen_resolve_paddr_low(tBTM_RAND_ENC *p); + +/* privacy function */ +#if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE) +/* BLE address mapping with CS feature */ +BOOLEAN btm_identity_addr_to_random_pseudo(BD_ADDR bd_addr, UINT8 *p_addr_type, BOOLEAN refresh); +BOOLEAN btm_random_pseudo_to_identity_addr(BD_ADDR random_pseudo, UINT8 *p_static_addr_type); +void btm_ble_refresh_peer_resolvable_private_addr(BD_ADDR pseudo_bda, BD_ADDR rra, UINT8 rra_type); +void btm_ble_refresh_local_resolvable_private_addr(BD_ADDR pseudo_addr, BD_ADDR local_rpa); +void btm_ble_read_resolving_list_entry_complete(UINT8 *p, UINT16 evt_len) ; +void btm_ble_remove_resolving_list_entry_complete(UINT8 *p, UINT16 evt_len); +void btm_ble_add_resolving_list_entry_complete(UINT8 *p, UINT16 evt_len); +void btm_ble_clear_resolving_list_complete(UINT8 *p, UINT16 evt_len); +void btm_read_ble_resolving_list_size_complete (UINT8 *p, UINT16 evt_len); +void btm_ble_enable_resolving_list(UINT8); +BOOLEAN btm_ble_disable_resolving_list(UINT8 rl_mask, BOOLEAN to_resume); +void btm_ble_enable_resolving_list_for_platform (UINT8 rl_mask); +void btm_ble_resolving_list_init(UINT8 max_irk_list_sz); +void btm_ble_resolving_list_cleanup(void); +#endif + +void btm_ble_multi_adv_configure_rpa (tBTM_BLE_MULTI_ADV_INST *p_inst); +void btm_ble_multi_adv_init(void); +void *btm_ble_multi_adv_get_ref(UINT8 inst_id); +void btm_ble_multi_adv_cleanup(void); +void btm_ble_multi_adv_reenable(UINT8 inst_id); +void btm_ble_multi_adv_enb_privacy(BOOLEAN enable); +char btm_ble_map_adv_tx_power(int tx_power_index); +void btm_ble_batchscan_init(void); +void btm_ble_batchscan_cleanup(void); +void btm_ble_adv_filter_init(void); +void btm_ble_adv_filter_cleanup(void); +BOOLEAN btm_ble_topology_check(tBTM_BLE_STATE_MASK request); +BOOLEAN btm_ble_clear_topology_mask(tBTM_BLE_STATE_MASK request_state); +BOOLEAN btm_ble_set_topology_mask(tBTM_BLE_STATE_MASK request_state); + +#if BTM_BLE_CONFORMANCE_TESTING == TRUE +void btm_ble_set_no_disc_if_pair_fail (BOOLEAN disble_disc); +void btm_ble_set_test_mac_value (BOOLEAN enable, UINT8 *p_test_mac_val); +void btm_ble_set_test_local_sign_cntr_value(BOOLEAN enable, UINT32 test_local_sign_cntr); +void btm_set_random_address(BD_ADDR random_bda); +void btm_ble_set_keep_rfu_in_auth_req(BOOLEAN keep_rfu); +#endif + +/* +#ifdef __cplusplus +} +#endif +*/ +#endif diff --git a/tools/sdk/include/bluedroid/btm_int.h b/tools/sdk/include/bluedroid/btm_int.h new file mode 100644 index 00000000..827114f0 --- /dev/null +++ b/tools/sdk/include/bluedroid/btm_int.h @@ -0,0 +1,1094 @@ +/****************************************************************************** + * + * Copyright (C) 1999-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 file contains the main Bluetooth Manager (BTM) internal + * definitions. + * + ******************************************************************************/ +#ifndef BTM_INT_H +#define BTM_INT_H + +#include "bt_defs.h" +#include "bt_target.h" +#include "gki.h" +#include "hcidefs.h" + +#include "rfcdefs.h" + +#include "btm_api.h" + +#if (BLE_INCLUDED == TRUE) +#include "btm_ble_int.h" +#if (SMP_INCLUDED == TRUE) +#include "smp_api.h" +#endif +#endif + +#if BTM_MAX_LOC_BD_NAME_LEN > 0 +typedef char tBTM_LOC_BD_NAME[BTM_MAX_LOC_BD_NAME_LEN + 1]; +#endif + +#define BTM_ACL_IS_CONNECTED(bda) (btm_bda_to_acl (bda, BT_TRANSPORT_BR_EDR) != NULL) + +/* Definitions for Server Channel Number (SCN) management +*/ +#define BTM_MAX_SCN PORT_MAX_RFC_PORTS + +/* Define masks for supported and exception 2.0 ACL packet types +*/ +#define BTM_ACL_SUPPORTED_PKTS_MASK (HCI_PKT_TYPES_MASK_DM1 | \ + HCI_PKT_TYPES_MASK_DH1 | \ + HCI_PKT_TYPES_MASK_DM3 | \ + HCI_PKT_TYPES_MASK_DH3 | \ + HCI_PKT_TYPES_MASK_DM5 | \ + HCI_PKT_TYPES_MASK_DH5) + +#define BTM_ACL_EXCEPTION_PKTS_MASK (HCI_PKT_TYPES_MASK_NO_2_DH1 | \ + HCI_PKT_TYPES_MASK_NO_3_DH1 | \ + HCI_PKT_TYPES_MASK_NO_2_DH3 | \ + HCI_PKT_TYPES_MASK_NO_3_DH3 | \ + HCI_PKT_TYPES_MASK_NO_2_DH5 | \ + HCI_PKT_TYPES_MASK_NO_3_DH5) + +#define BTM_EPR_AVAILABLE(p) ((HCI_ATOMIC_ENCRYPT_SUPPORTED((p)->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]) && \ + HCI_ATOMIC_ENCRYPT_SUPPORTED(controller_get_interface()->get_features_classic(0)->as_array)) \ + ? TRUE : FALSE) + +#define BTM_IS_BRCM_CONTROLLER() (controller_get_interface()->get_bt_version()->manufacturer == LMP_COMPID_BROADCOM) + +/* Define the ACL Management control structure +*/ +typedef struct { +UINT16 hci_handle; +UINT16 pkt_types_mask; +UINT16 clock_offset; +BD_ADDR remote_addr; +DEV_CLASS remote_dc; +BD_NAME remote_name; + +UINT16 manufacturer; +UINT16 lmp_subversion; +UINT16 link_super_tout; +BD_FEATURES peer_lmp_features[HCI_EXT_FEATURES_PAGE_MAX + 1]; /* Peer LMP Extended features mask table for the device */ +UINT8 num_read_pages; +UINT8 lmp_version; + +BOOLEAN in_use; +UINT8 link_role; +BOOLEAN link_up_issued; /* True if busy_level link up has been issued */ + +#define BTM_ACL_SWKEY_STATE_IDLE 0 +#define BTM_ACL_SWKEY_STATE_MODE_CHANGE 1 +#define BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF 2 +#define BTM_ACL_SWKEY_STATE_SWITCHING 3 +#define BTM_ACL_SWKEY_STATE_ENCRYPTION_ON 4 +#define BTM_ACL_SWKEY_STATE_IN_PROGRESS 5 +UINT8 switch_role_state; + +#define BTM_ACL_ENCRYPT_STATE_IDLE 0 +#define BTM_ACL_ENCRYPT_STATE_ENCRYPT_OFF 1 /* encryption turning off */ +#define BTM_ACL_ENCRYPT_STATE_TEMP_FUNC 2 /* temporarily off for change link key or role switch */ +#define BTM_ACL_ENCRYPT_STATE_ENCRYPT_ON 3 /* encryption turning on */ +UINT8 encrypt_state; /* overall BTM encryption state */ + +#if BLE_INCLUDED == TRUE +tBT_TRANSPORT transport; +BD_ADDR conn_addr; /* local device address used for this connection */ +UINT8 conn_addr_type; /* local device address type for this connection */ +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 */ + +#endif + +} tACL_CONN; + +/***************************************************** +** TIMER Definitions +******************************************************/ +#define TT_DEV_RESET 1 +#define TT_DEV_RLN 2 +#define TT_DEV_RLNKP 4 /* Read Link Policy Settings */ + +/* Define the Device Management control structure +*/ +typedef struct { +tBTM_DEV_STATUS_CB *p_dev_status_cb; /* Device status change callback */ +tBTM_VS_EVT_CB *p_vend_spec_cb[BTM_MAX_VSE_CALLBACKS]; /* Register for vendor specific events */ + +tBTM_CMPL_CB *p_stored_link_key_cmpl_cb; /* Read/Write/Delete stored link key */ + +TIMER_LIST_ENT reset_timer; +tBTM_CMPL_CB *p_reset_cmpl_cb; + +TIMER_LIST_ENT rln_timer; +tBTM_CMPL_CB *p_rln_cmpl_cb; /* Callback function to be called when */ +/* read local name function complete */ +TIMER_LIST_ENT rssi_timer; +tBTM_CMPL_CB *p_rssi_cmpl_cb; /* Callback function to be called when */ +/* read rssi function completes */ +TIMER_LIST_ENT lnk_quality_timer; +tBTM_CMPL_CB *p_lnk_qual_cmpl_cb;/* Callback function to be called when */ +/* read link quality function completes */ +TIMER_LIST_ENT txpwer_timer; +tBTM_CMPL_CB *p_txpwer_cmpl_cb; /* Callback function to be called when */ +/* read inq tx power function completes */ + +TIMER_LIST_ENT qossu_timer; +tBTM_CMPL_CB *p_qossu_cmpl_cb; /* Callback function to be called when */ +/* qos setup function completes */ + +tBTM_ROLE_SWITCH_CMPL switch_role_ref_data; +tBTM_CMPL_CB *p_switch_role_cb; /* Callback function to be called when */ +/* requested switch role is completed */ + +TIMER_LIST_ENT tx_power_timer; +tBTM_CMPL_CB *p_tx_power_cmpl_cb;/* Callback function to be called */ + +DEV_CLASS dev_class; /* Local device class */ + +#if BLE_INCLUDED == TRUE + +tBTM_CMPL_CB *p_le_test_cmd_cmpl_cb; /* Callback function to be called when + LE test mode command has been sent successfully */ + +BD_ADDR read_tx_pwr_addr; /* read TX power target address */ + +#define BTM_LE_SUPPORT_STATE_SIZE 8 +UINT8 le_supported_states[BTM_LE_SUPPORT_STATE_SIZE]; + +tBTM_BLE_LOCAL_ID_KEYS id_keys; /* local BLE ID keys */ +BT_OCTET16 ble_encryption_key_value; /* BLE encryption key */ + +#if BTM_BLE_CONFORMANCE_TESTING == TRUE +BOOLEAN no_disc_if_pair_fail; +BOOLEAN enable_test_mac_val; +BT_OCTET8 test_mac; +BOOLEAN enable_test_local_sign_cntr; +UINT32 test_local_sign_cntr; +#endif + +#endif /* BLE_INCLUDED */ + +tBTM_IO_CAP loc_io_caps; /* IO capability of the local device */ +tBTM_AUTH_REQ loc_auth_req; /* the auth_req flag */ +BOOLEAN secure_connections_only; /* Rejects service level 0 connections if */ +/* itself or peer device doesn't support */ +/* secure connections */ +} tBTM_DEVCB; + + +/* Define the structures and constants used for inquiry +*/ + +/* Definitions of limits for inquiries */ +#define BTM_PER_INQ_MIN_MAX_PERIOD HCI_PER_INQ_MIN_MAX_PERIOD +#define BTM_PER_INQ_MAX_MAX_PERIOD HCI_PER_INQ_MAX_MAX_PERIOD +#define BTM_PER_INQ_MIN_MIN_PERIOD HCI_PER_INQ_MIN_MIN_PERIOD +#define BTM_PER_INQ_MAX_MIN_PERIOD HCI_PER_INQ_MAX_MIN_PERIOD +#define BTM_MAX_INQUIRY_LENGTH HCI_MAX_INQUIRY_LENGTH +#define BTM_MIN_INQUIRY_LEN 0x01 + +#define BTM_MIN_INQ_TX_POWER -70 +#define BTM_MAX_INQ_TX_POWER 20 + +typedef struct { +UINT32 inq_count; /* Used for determining if a response has already been */ +/* received for the current inquiry operation. (We do not */ +/* want to flood the caller with multiple responses from */ +/* the same device. */ +BD_ADDR bd_addr; +} tINQ_BDADDR; + +typedef struct { +UINT32 time_of_resp; +UINT32 inq_count; /* "timestamps" the entry with a particular inquiry count */ +/* Used for determining if a response has already been */ +/* received for the current inquiry operation. (We do not */ +/* want to flood the caller with multiple responses from */ +/* the same device. */ +tBTM_INQ_INFO inq_info; +BOOLEAN in_use; + +#if (BLE_INCLUDED == TRUE) +BOOLEAN scan_rsp; +#endif +} tINQ_DB_ENT; + + +enum { +INQ_NONE, +INQ_LE_OBSERVE, +INQ_GENERAL +}; +typedef UINT8 tBTM_INQ_TYPE; + +typedef struct { + tBTM_CMPL_CB *p_remname_cmpl_cb; + +#define BTM_EXT_RMT_NAME_TIMEOUT 40 + + + TIMER_LIST_ENT rmt_name_timer_ent; + + UINT16 discoverable_mode; + UINT16 connectable_mode; + UINT16 page_scan_window; + UINT16 page_scan_period; + UINT16 inq_scan_window; + UINT16 inq_scan_period; + UINT16 inq_scan_type; + UINT16 page_scan_type; /* current page scan type */ + tBTM_INQ_TYPE scan_type; + + BD_ADDR remname_bda; /* Name of bd addr for active remote name request */ +#define BTM_RMT_NAME_INACTIVE 0 +#define BTM_RMT_NAME_EXT 0x1 /* Initiated through API */ +#define BTM_RMT_NAME_SEC 0x2 /* Initiated internally by security manager */ +#define BTM_RMT_NAME_INQ 0x4 /* Remote name initiated internally by inquiry */ + BOOLEAN remname_active; /* State of a remote name request by external API */ + + tBTM_CMPL_CB *p_inq_cmpl_cb; + tBTM_INQ_RESULTS_CB *p_inq_results_cb; + tBTM_CMPL_CB *p_inq_ble_cmpl_cb; /*completion callback exclusively for LE Observe*/ + tBTM_INQ_RESULTS_CB *p_inq_ble_results_cb;/*results callback exclusively for LE observe*/ + tBTM_CMPL_CB *p_inqfilter_cmpl_cb; /* Called (if not NULL) after inquiry filter completed */ + UINT32 inq_counter; /* Counter incremented each time an inquiry completes */ + /* Used for determining whether or not duplicate devices */ + /* have responded to the same inquiry */ + TIMER_LIST_ENT inq_timer_ent; + tINQ_BDADDR *p_bd_db; /* Pointer to memory that holds bdaddrs */ + UINT16 num_bd_entries; /* Number of entries in database */ + UINT16 max_bd_entries; /* Maximum number of entries that can be stored */ + tINQ_DB_ENT inq_db[BTM_INQ_DB_SIZE]; + tBTM_INQ_PARMS inqparms; /* Contains the parameters for the current inquiry */ + tBTM_INQUIRY_CMPL inq_cmpl_info; /* Status and number of responses from the last inquiry */ + + UINT16 per_min_delay; /* Current periodic minimum delay */ + UINT16 per_max_delay; /* Current periodic maximum delay */ + BOOLEAN inqfilt_active; + UINT8 pending_filt_complete_event; /* to take care of btm_event_filter_complete corresponding to */ + /* inquiry that has been cancelled*/ + UINT8 inqfilt_type; /* Contains the inquiry filter type (BD ADDR, COD, or Clear) */ + +#define BTM_INQ_INACTIVE_STATE 0 +#define BTM_INQ_CLR_FILT_STATE 1 /* Currently clearing the inquiry filter preceeding the inquiry request */ + /* (bypassed if filtering is not used) */ +#define BTM_INQ_SET_FILT_STATE 2 /* Sets the new filter (or turns off filtering) in this state */ +#define BTM_INQ_ACTIVE_STATE 3 /* Actual inquiry or periodic inquiry is in progress */ +#define BTM_INQ_REMNAME_STATE 4 /* Remote name requests are active */ + + UINT8 state; /* Current state that the inquiry process is in */ + UINT8 inq_active; /* Bit Mask indicating type of inquiry is active */ + BOOLEAN no_inc_ssp; /* TRUE, to stop inquiry on incoming SSP */ +#if (defined(BTA_HOST_INTERLEAVE_SEARCH) && BTA_HOST_INTERLEAVE_SEARCH == TRUE) + btm_inq_state next_state; /*interleaving state to determine next mode to be inquired*/ +#endif +} tBTM_INQUIRY_VAR_ST; + +/* The MSB of the clock offset field indicates that the offset is valid if TRUE */ +#define BTM_CLOCK_OFFSET_VALID 0x8000 + +/* Define the structures needed by security management +*/ + +#define BTM_SEC_INVALID_HANDLE 0xFFFF + +typedef UINT8 *BTM_BD_NAME_PTR; /* Pointer to Device name */ + +/* Security callback is called by this unit when security +** procedures are completed. Parameters are +** BD Address of remote +** Result of the operation +*/ +typedef tBTM_SEC_CBACK tBTM_SEC_CALLBACK; + +typedef void (tBTM_SCO_IND_CBACK) (UINT16 sco_inx) ; + +/* MACROs to convert from SCO packet types mask to ESCO and back */ +#define BTM_SCO_PKT_TYPE_MASK ( HCI_PKT_TYPES_MASK_HV1 \ + | HCI_PKT_TYPES_MASK_HV2 \ + | HCI_PKT_TYPES_MASK_HV3) + +/* Mask defining only the SCO types of an esco packet type */ +#define BTM_ESCO_PKT_TYPE_MASK ( HCI_ESCO_PKT_TYPES_MASK_HV1 \ + | HCI_ESCO_PKT_TYPES_MASK_HV2 \ + | HCI_ESCO_PKT_TYPES_MASK_HV3) + +#define BTM_SCO_2_ESCO(scotype) ((UINT16)(((scotype) & BTM_SCO_PKT_TYPE_MASK) >> 5)) +#define BTM_ESCO_2_SCO(escotype) ((UINT16)(((escotype) & BTM_ESCO_PKT_TYPE_MASK) << 5)) + +/* Define masks for supported and exception 2.0 SCO packet types +*/ +#define BTM_SCO_SUPPORTED_PKTS_MASK (HCI_ESCO_PKT_TYPES_MASK_HV1 | \ + HCI_ESCO_PKT_TYPES_MASK_HV2 | \ + HCI_ESCO_PKT_TYPES_MASK_HV3 | \ + HCI_ESCO_PKT_TYPES_MASK_EV3 | \ + HCI_ESCO_PKT_TYPES_MASK_EV4 | \ + HCI_ESCO_PKT_TYPES_MASK_EV5) + +#define BTM_SCO_EXCEPTION_PKTS_MASK (HCI_ESCO_PKT_TYPES_MASK_NO_2_EV3 | \ + HCI_ESCO_PKT_TYPES_MASK_NO_3_EV3 | \ + HCI_ESCO_PKT_TYPES_MASK_NO_2_EV5 | \ + HCI_ESCO_PKT_TYPES_MASK_NO_3_EV5) + + +#define BTM_SCO_ROUTE_UNKNOWN 0xff + +/* Define the structure that contains (e)SCO data */ +typedef struct { + tBTM_ESCO_CBACK *p_esco_cback; /* Callback for eSCO events */ + tBTM_ESCO_PARAMS setup; + tBTM_ESCO_DATA data; /* Connection complete information */ + UINT8 hci_status; +} tBTM_ESCO_INFO; + +/* Define the structure used for SCO Management +*/ +typedef struct { + tBTM_ESCO_INFO esco; /* Current settings */ +#if BTM_SCO_HCI_INCLUDED == TRUE + BUFFER_Q xmit_data_q; /* SCO data transmitting queue */ +#endif + tBTM_SCO_CB *p_conn_cb; /* Callback for when connected */ + tBTM_SCO_CB *p_disc_cb; /* Callback for when disconnect */ + UINT16 state; /* The state of the SCO link */ + UINT16 hci_handle; /* HCI Handle */ + BOOLEAN is_orig; /* TRUE if the originator */ + BOOLEAN rem_bd_known; /* TRUE if remote BD addr known */ + +} tSCO_CONN; + +/* SCO Management control block */ +typedef struct { + tBTM_SCO_IND_CBACK *app_sco_ind_cb; +#if BTM_SCO_HCI_INCLUDED == TRUE + tBTM_SCO_DATA_CB *p_data_cb; /* Callback for SCO data over HCI */ + UINT32 xmit_window_size; /* Total SCO window in bytes */ +#endif + tSCO_CONN sco_db[BTM_MAX_SCO_LINKS]; + tBTM_ESCO_PARAMS def_esco_parms; + BD_ADDR xfer_addr; + UINT16 sco_disc_reason; + BOOLEAN esco_supported; /* TRUE if 1.2 cntlr AND supports eSCO links */ + tBTM_SCO_TYPE desired_sco_mode; + tBTM_SCO_TYPE xfer_sco_type; + tBTM_SCO_PCM_PARAM sco_pcm_param; + tBTM_SCO_CODEC_TYPE codec_in_use; /* None, CVSD, MSBC, etc. */ +#if BTM_SCO_HCI_INCLUDED == TRUE + tBTM_SCO_ROUTE_TYPE sco_path; +#endif + +} tSCO_CB; + + +#if BTM_SCO_INCLUDED == TRUE +void btm_set_sco_ind_cback( tBTM_SCO_IND_CBACK *sco_ind_cb ); +void btm_accept_sco_link(UINT16 sco_inx, tBTM_ESCO_PARAMS *p_setup, + tBTM_SCO_CB *p_conn_cb, tBTM_SCO_CB *p_disc_cb); +void btm_reject_sco_link(UINT16 sco_inx ); +void btm_sco_chk_pend_rolechange (UINT16 hci_handle); +#else +#define btm_accept_sco_link(sco_inx, p_setup, p_conn_cb, p_disc_cb) +#define btm_reject_sco_link(sco_inx) +#define btm_set_sco_ind_cback(sco_ind_cb) +#define btm_sco_chk_pend_rolechange(hci_handle) +#endif /* BTM_SCO_INCLUDED */ + +/* +** Define structure for Security Service Record. +** A record exists for each service registered with the Security Manager +*/ +typedef struct { + UINT32 mx_proto_id; /* Service runs over this multiplexer protocol */ + UINT32 orig_mx_chan_id; /* Channel on the multiplexer protocol */ + UINT32 term_mx_chan_id; /* Channel on the multiplexer protocol */ + UINT16 psm; /* L2CAP PSM value */ + UINT16 security_flags; /* Bitmap of required security features */ + UINT8 service_id; /* Passed in authorization callback */ +#if (L2CAP_UCD_INCLUDED == TRUE) + UINT16 ucd_security_flags; /* Bitmap of required security features for UCD */ +#endif +#if BTM_SEC_SERVICE_NAME_LEN > 0 + UINT8 orig_service_name[BTM_SEC_SERVICE_NAME_LEN + 1]; + UINT8 term_service_name[BTM_SEC_SERVICE_NAME_LEN + 1]; +#endif +} tBTM_SEC_SERV_REC; + +#if BLE_INCLUDED == TRUE +/* LE Security information of device in Slave Role */ +typedef struct { + BT_OCTET16 irk; /* peer diverified identity root */ + BT_OCTET16 pltk; /* peer long term key */ + BT_OCTET16 pcsrk; /* peer SRK peer device used to secured sign local data */ + + BT_OCTET16 lltk; /* local long term key */ + BT_OCTET16 lcsrk; /* local SRK peer device used to secured sign local data */ + + BT_OCTET8 rand; /* random vector for LTK generation */ + UINT16 ediv; /* LTK diversifier of this slave device */ + UINT16 div; /* local DIV to generate local LTK=d1(ER,DIV,0) and CSRK=d1(ER,DIV,1) */ + UINT8 sec_level; /* local pairing security level */ + UINT8 key_size; /* key size of the LTK delivered to peer device */ + UINT8 srk_sec_level; /* security property of peer SRK for this device */ + UINT8 local_csrk_sec_level; /* security property of local CSRK for this device */ + + UINT32 counter; /* peer sign counter for verifying rcv signed cmd */ + UINT32 local_counter; /* local sign counter for sending signed write cmd*/ +} tBTM_SEC_BLE_KEYS; + +typedef struct { + BD_ADDR pseudo_addr; /* LE pseudo address of the device if different from device address */ + tBLE_ADDR_TYPE ble_addr_type; /* LE device type: public or random address */ + tBLE_ADDR_TYPE static_addr_type; /* static address type */ + BD_ADDR static_addr; /* static address */ + +#define BTM_WHITE_LIST_BIT 0x01 +#define BTM_RESOLVING_LIST_BIT 0x02 + UINT8 in_controller_list; /* in controller resolving list or not */ + UINT8 resolving_list_index; +#if BLE_PRIVACY_SPT == TRUE + BD_ADDR cur_rand_addr; /* current random address */ + +#define BTM_BLE_ADDR_PSEUDO 0 /* address index device record */ +#define BTM_BLE_ADDR_RRA 1 /* cur_rand_addr */ +#define BTM_BLE_ADDR_STATIC 2 /* static_addr */ + UINT8 active_addr_type; +#endif + +#if SMP_INCLUDED == TRUE + tBTM_LE_KEY_TYPE key_type; /* bit mask of valid key types in record */ + tBTM_SEC_BLE_KEYS keys; /* LE device security info in slave rode */ +#endif +} tBTM_SEC_BLE; + + +#endif /* BLE_INCLUDED */ + +/* Peering bond type */ +enum { + BOND_TYPE_UNKNOWN, + BOND_TYPE_PERSISTENT, + BOND_TYPE_TEMPORARY +}; +typedef UINT8 tBTM_BOND_TYPE; + +/* +** Define structure for Security Device Record. +** A record exists for each device authenticated with this device +*/ +typedef struct { + tBTM_SEC_SERV_REC *p_cur_service; + tBTM_SEC_CALLBACK *p_callback; + void *p_ref_data; + UINT32 timestamp; /* Timestamp of the last connection */ + UINT32 trusted_mask[BTM_SEC_SERVICE_ARRAY_SIZE]; /* Bitwise OR of trusted services */ + UINT16 hci_handle; /* Handle to connection when exists */ + UINT16 clock_offset; /* Latest known clock offset */ + BD_ADDR bd_addr; /* BD_ADDR of the device */ + DEV_CLASS dev_class; /* DEV_CLASS of the device */ + LINK_KEY link_key; /* Device link key */ + UINT8 pin_code_length; /* Length of the pin_code used for paring */ + +#define BTM_SEC_AUTHORIZED BTM_SEC_FLAG_AUTHORIZED /* 0x01 */ +#define BTM_SEC_AUTHENTICATED BTM_SEC_FLAG_AUTHENTICATED /* 0x02 */ +#define BTM_SEC_ENCRYPTED BTM_SEC_FLAG_ENCRYPTED /* 0x04 */ +#define BTM_SEC_NAME_KNOWN 0x08 +#define BTM_SEC_LINK_KEY_KNOWN BTM_SEC_FLAG_LKEY_KNOWN /* 0x10 */ +#define BTM_SEC_LINK_KEY_AUTHED BTM_SEC_FLAG_LKEY_AUTHED /* 0x20 */ +#define BTM_SEC_ROLE_SWITCHED 0x40 +#define BTM_SEC_IN_USE 0x80 + /* LE link security flag */ +#define BTM_SEC_LE_AUTHENTICATED 0x0200 /* LE link is encrypted after pairing with MITM */ +#define BTM_SEC_LE_ENCRYPTED 0x0400 /* LE link is encrypted */ +#define BTM_SEC_LE_NAME_KNOWN 0x0800 /* not used */ +#define BTM_SEC_LE_LINK_KEY_KNOWN 0x1000 /* bonded with peer (peer LTK and/or SRK is saved) */ +#define BTM_SEC_LE_LINK_KEY_AUTHED 0x2000 /* pairing is done with MITM */ +#define BTM_SEC_16_DIGIT_PIN_AUTHED 0x4000 /* pairing is done with 16 digit pin */ + + UINT16 sec_flags; /* Current device security state */ + + tBTM_BD_NAME sec_bd_name; /* User friendly name of the device. (may be truncated to save space in dev_rec table) */ + BD_FEATURES features[HCI_EXT_FEATURES_PAGE_MAX + 1]; /* Features supported by the device */ + UINT8 num_read_pages; + +#define BTM_SEC_STATE_IDLE 0 +#define BTM_SEC_STATE_AUTHENTICATING 1 +#define BTM_SEC_STATE_ENCRYPTING 2 +#define BTM_SEC_STATE_GETTING_NAME 3 +#define BTM_SEC_STATE_AUTHORIZING 4 +#define BTM_SEC_STATE_SWITCHING_ROLE 5 +#define BTM_SEC_STATE_DISCONNECTING 6 /* disconnecting BR/EDR */ +#define BTM_SEC_STATE_DELAY_FOR_ENC 7 /* delay to check for encryption to work around */ + /* controller problems */ +#define BTM_SEC_STATE_DISCONNECTING_BLE 8 /* disconnecting BLE */ +#define BTM_SEC_STATE_DISCONNECTING_BOTH 9 /* disconnecting BR/EDR and BLE */ + + UINT8 sec_state; /* Operating state */ + BOOLEAN is_originator; /* TRUE if device is originating connection */ +#if (L2CAP_UCD_INCLUDED == TRUE) + BOOLEAN is_ucd; /* TRUE if device is sending or receiving UCD */ + /* if incoming security failed, received UCD will be discarded */ +#endif + BOOLEAN role_master; /* TRUE if current mode is master */ + UINT16 security_required; /* Security required for connection */ + BOOLEAN link_key_not_sent; /* link key notification has not been sent waiting for name */ + UINT8 link_key_type; /* Type of key used in pairing */ + BOOLEAN link_key_changed; /* Changed link key during current connection */ + +#define BTM_MAX_PRE_SM4_LKEY_TYPE BTM_LKEY_TYPE_REMOTE_UNIT /* the link key type used by legacy pairing */ + +#define BTM_SM4_UNKNOWN 0x00 +#define BTM_SM4_KNOWN 0x10 +#define BTM_SM4_TRUE 0x11 +#define BTM_SM4_REQ_PEND 0x08 /* set this bit when getting remote features */ +#define BTM_SM4_UPGRADE 0x04 /* set this bit when upgrading link key */ +#define BTM_SM4_RETRY 0x02 /* set this bit to retry on HCI_ERR_KEY_MISSING or HCI_ERR_LMP_ERR_TRANS_COLLISION */ +#define BTM_SM4_DD_ACP 0x20 /* set this bit to indicate peer initiated dedicated bonding */ +#define BTM_SM4_CONN_PEND 0x40 /* set this bit to indicate accepting acl conn; to be cleared on btm_acl_created */ + UINT8 sm4; /* BTM_SM4_TRUE, if the peer supports SM4 */ + tBTM_IO_CAP rmt_io_caps; /* IO capability of the peer device */ + tBTM_AUTH_REQ rmt_auth_req; /* the auth_req flag as in the IO caps rsp evt */ + BOOLEAN remote_supports_secure_connections; + BOOLEAN remote_features_needed; /* set to true if the local device is in */ + /* "Secure Connections Only" mode and it receives */ + /* HCI_IO_CAPABILITY_REQUEST_EVT from the peer before */ + /* it knows peer's support for Secure Connections */ + + UINT16 ble_hci_handle; /* use in DUMO connection */ + UINT8 enc_key_size; /* current link encryption key size */ + tBT_DEVICE_TYPE device_type; + BOOLEAN new_encryption_key_is_p256; /* Set to TRUE when the newly generated LK + ** is generated from P-256. + ** Link encrypted with such LK can be used + ** for SM over BR/EDR. + */ + BOOLEAN no_smp_on_br; /* if set to TRUE then SMP on BR/EDR doesn't */ + /* work, i.e. link keys crosspairing */ + /* SC BR/EDR->SC LE doesn't happen */ + tBTM_BOND_TYPE bond_type; /* peering bond type */ + +#if BLE_INCLUDED == TRUE + tBTM_SEC_BLE ble; + tBTM_LE_CONN_PRAMS conn_params; +#endif + +// btla-specific ++ +#if BTM_DISC_DURING_RS == TRUE +#define BTM_SEC_RS_NOT_PENDING 0 /* Role Switch not in progress */ +#define BTM_SEC_RS_PENDING 1 /* Role Switch in progress */ +#define BTM_SEC_DISC_PENDING 2 /* Disconnect is pending */ + UINT8 rs_disc_pending; +#endif +// btla-specific -- +#define BTM_SEC_NO_LAST_SERVICE_ID 0 + UINT8 last_author_service_id; /* ID of last serviced authorized: Reset after each l2cap connection */ + +} tBTM_SEC_DEV_REC; + +#define BTM_SEC_IS_SM4(sm) ((BOOLEAN)(BTM_SM4_TRUE == ((sm)&BTM_SM4_TRUE))) +#define BTM_SEC_IS_SM4_LEGACY(sm) ((BOOLEAN)(BTM_SM4_KNOWN == ((sm)&BTM_SM4_TRUE))) +#define BTM_SEC_IS_SM4_UNKNOWN(sm) ((BOOLEAN)(BTM_SM4_UNKNOWN == ((sm)&BTM_SM4_TRUE))) + +#define BTM_SEC_LE_MASK (BTM_SEC_LE_AUTHENTICATED|BTM_SEC_LE_ENCRYPTED|BTM_SEC_LE_LINK_KEY_KNOWN|BTM_SEC_LE_LINK_KEY_AUTHED) + +/* +** Define device configuration structure +*/ +typedef struct { +#if BTM_MAX_LOC_BD_NAME_LEN > 0 + tBTM_LOC_BD_NAME bd_name; /* local Bluetooth device name */ +#endif + BOOLEAN pin_type; /* TRUE if PIN type is fixed */ + UINT8 pin_code_len; /* Bonding information */ + PIN_CODE pin_code; /* PIN CODE if pin type is fixed */ + BOOLEAN connectable; /* If TRUE page scan should be enabled */ + UINT8 def_inq_scan_mode; /* ??? limited/general/none */ +} tBTM_CFG; + +enum { + BTM_PM_ST_ACTIVE = BTM_PM_STS_ACTIVE, + BTM_PM_ST_HOLD = BTM_PM_STS_HOLD, + BTM_PM_ST_SNIFF = BTM_PM_STS_SNIFF, + BTM_PM_ST_PARK = BTM_PM_STS_PARK, + BTM_PM_ST_PENDING = BTM_PM_STS_PENDING +}; +typedef UINT8 tBTM_PM_STATE; + +enum { + BTM_PM_SET_MODE_EVT, /* Set power mode API is called. */ + BTM_PM_UPDATE_EVT, + BTM_PM_RD_MODE_EVT /* Read power mode API is called. */ +}; +typedef UINT8 tBTM_PM_EVENT; + +typedef struct { + UINT16 event; + UINT16 len; + UINT8 link_ind; +} tBTM_PM_MSG_DATA; + +typedef struct { + UINT8 hci_status; + UINT8 mode; + UINT16 interval; +} tBTM_PM_MD_CHG_DATA; + +typedef struct { + UINT8 pm_id; /* the entity that calls SetPowerMode API */ + tBTM_PM_PWR_MD *p_pmd; +} tBTM_PM_SET_MD_DATA; + +typedef struct { + void *p_data; + UINT8 link_ind; +} tBTM_PM_SM_DATA; + +typedef struct { + tBTM_PM_PWR_MD req_mode[BTM_MAX_PM_RECORDS + 1]; /* the desired mode and parameters of the connection*/ + tBTM_PM_PWR_MD set_mode; /* the mode and parameters sent down to the host controller. */ + UINT16 interval; /* the interval from last mode change event. */ +#if (BTM_SSR_INCLUDED == TRUE) + UINT16 max_lat; /* stored SSR maximum latency */ + UINT16 min_rmt_to;/* stored SSR minimum remote timeout */ + UINT16 min_loc_to;/* stored SSR minimum local timeout */ +#endif + tBTM_PM_STATE state; /* contains the current mode of the connection */ + BOOLEAN chg_ind; /* a request change indication */ +} tBTM_PM_MCB; + +#define BTM_PM_REC_NOT_USED 0 +typedef struct { + tBTM_PM_STATUS_CBACK *cback;/* to notify the registered party of mode change event */ + UINT8 mask; /* registered request mask. 0, if this entry is not used */ +} tBTM_PM_RCB; + +enum { + BTM_BLI_ACL_UP_EVT, + BTM_BLI_ACL_DOWN_EVT, + BTM_BLI_PAGE_EVT, + BTM_BLI_PAGE_DONE_EVT, + BTM_BLI_INQ_EVT, + BTM_BLI_INQ_CANCEL_EVT, + BTM_BLI_INQ_DONE_EVT +}; +typedef UINT8 tBTM_BLI_EVENT; + +/* Pairing State */ +enum { + BTM_PAIR_STATE_IDLE, /* Idle */ + BTM_PAIR_STATE_GET_REM_NAME, /* Getting the remote name (to check for SM4) */ + BTM_PAIR_STATE_WAIT_PIN_REQ, /* Started authentication, waiting for PIN req (PIN is pre-fetched) */ + BTM_PAIR_STATE_WAIT_LOCAL_PIN, /* Waiting for local PIN code */ + BTM_PAIR_STATE_WAIT_NUMERIC_CONFIRM, /* Waiting user 'yes' to numeric confirmation */ + BTM_PAIR_STATE_KEY_ENTRY, /* Key entry state (we are a keyboard) */ + BTM_PAIR_STATE_WAIT_LOCAL_OOB_RSP, /* Waiting for local response to peer OOB data */ + BTM_PAIR_STATE_WAIT_LOCAL_IOCAPS, /* Waiting for local IO capabilities and OOB data */ + BTM_PAIR_STATE_INCOMING_SSP, /* Incoming SSP (got peer IO caps when idle) */ + BTM_PAIR_STATE_WAIT_AUTH_COMPLETE, /* All done, waiting authentication cpmplete */ + BTM_PAIR_STATE_WAIT_DISCONNECT /* Waiting to disconnect the ACL */ +}; +typedef UINT8 tBTM_PAIRING_STATE; + +#define BTM_PAIR_FLAGS_WE_STARTED_DD 0x01 /* We want to do dedicated bonding */ +#define BTM_PAIR_FLAGS_PEER_STARTED_DD 0x02 /* Peer initiated dedicated bonding */ +#define BTM_PAIR_FLAGS_DISC_WHEN_DONE 0x04 /* Disconnect when done */ +#define BTM_PAIR_FLAGS_PIN_REQD 0x08 /* set this bit when pin_callback is called */ +#define BTM_PAIR_FLAGS_PRE_FETCH_PIN 0x10 /* set this bit when pre-fetch pin */ +#define BTM_PAIR_FLAGS_REJECTED_CONNECT 0x20 /* set this bit when rejected incoming connection */ +#define BTM_PAIR_FLAGS_WE_CANCEL_DD 0x40 /* set this bit when cancelling a bonding procedure */ +#define BTM_PAIR_FLAGS_LE_ACTIVE 0x80 /* use this bit when SMP pairing is active */ + + +typedef struct { + BOOLEAN is_mux; + BD_ADDR bd_addr; + UINT16 psm; + BOOLEAN is_orig; + tBTM_SEC_CALLBACK *p_callback; + void *p_ref_data; + UINT32 mx_proto_id; + UINT32 mx_chan_id; + tBT_TRANSPORT transport; +} tBTM_SEC_QUEUE_ENTRY; + +#if (L2CAP_UCD_INCLUDED == TRUE) + +#define CONN_ORIENT_TERM 0x00 /* incoming connection oriented */ +#define CONN_ORIENT_ORIG 0x01 /* outgoing connection oriented */ +#define CONNLESS_TERM 0x02 /* incoming connectionless */ +#define CONNLESS_ORIG 0x03 /* outgoing connectionless */ +#define CONNECTION_TYPE_ORIG_MASK 0x01 /* mask for direction */ +#define CONNECTION_TYPE_CONNLESS_MASK 0x02 /* mask for connectionless or not */ +typedef UINT8 CONNECTION_TYPE; + +#else + +#define CONN_ORIENT_TERM FALSE +#define CONN_ORIENT_ORIG TRUE +typedef BOOLEAN CONNECTION_TYPE; + +#endif /* (L2CAP_UCD_INCLUDED == TRUE) */ + +/* Define a structure to hold all the BTM data +*/ + +#define BTM_STATE_BUFFER_SIZE 5 /* size of state buffer */ + +typedef struct { + tBTM_CFG cfg; /* Device configuration */ + + /**************************************************** + ** ACL Management + ****************************************************/ + tACL_CONN acl_db[MAX_L2CAP_LINKS]; + UINT8 btm_scn[BTM_MAX_SCN]; /* current SCNs: TRUE if SCN is in use */ + UINT16 btm_def_link_policy; + UINT16 btm_def_link_super_tout; + + tBTM_BL_EVENT_MASK bl_evt_mask; + tBTM_BL_CHANGE_CB *p_bl_changed_cb; /* Callback for when Busy Level changed */ + + /**************************************************** + ** Power Management + ****************************************************/ + tBTM_PM_MCB pm_mode_db[MAX_L2CAP_LINKS]; /* per ACL link */ + tBTM_PM_RCB pm_reg_db[BTM_MAX_PM_RECORDS + 1]; /* per application/module */ + UINT8 pm_pend_link; /* the index of acl_db, which has a pending PM cmd */ + UINT8 pm_pend_id; /* the id pf the module, which has a pending PM cmd */ + + /***************************************************** + ** Device control + *****************************************************/ + tBTM_DEVCB devcb; + + /***************************************************** + ** BLE Device controllers + *****************************************************/ +#if (BLE_INCLUDED == TRUE) + tBTM_BLE_CB ble_ctr_cb; + + UINT16 enc_handle; + BT_OCTET8 enc_rand; /* received rand value from LTK request*/ + UINT16 ediv; /* received ediv value from LTK request */ + UINT8 key_size; + tBTM_BLE_VSC_CB cmn_ble_vsc_cb; +#endif + + /* Packet types supported by the local device */ + UINT16 btm_acl_pkt_types_supported; + UINT16 btm_sco_pkt_types_supported; + + + /***************************************************** + ** Inquiry + *****************************************************/ + tBTM_INQUIRY_VAR_ST btm_inq_vars; + + /***************************************************** + ** SCO Management + *****************************************************/ +#if BTM_SCO_INCLUDED == TRUE + tSCO_CB sco_cb; +#endif + + /***************************************************** + ** Security Management + *****************************************************/ + tBTM_APPL_INFO api; + +#define BTM_SEC_MAX_RMT_NAME_CALLBACKS 2 + tBTM_RMT_NAME_CALLBACK *p_rmt_name_callback[BTM_SEC_MAX_RMT_NAME_CALLBACKS]; + + tBTM_SEC_DEV_REC *p_collided_dev_rec; + TIMER_LIST_ENT sec_collision_tle; + UINT32 collision_start_time; + UINT32 max_collision_delay; + UINT32 dev_rec_count; /* Counter used for device record timestamp */ + UINT8 security_mode; + BOOLEAN pairing_disabled; + BOOLEAN connect_only_paired; + BOOLEAN security_mode_changed; /* mode changed during bonding */ + BOOLEAN pin_type_changed; /* pin type changed during bonding */ + BOOLEAN sec_req_pending; /* TRUE if a request is pending */ +// btla-specific ++ +#ifdef PORCHE_PAIRING_CONFLICT + UINT8 pin_code_len_saved; /* for legacy devices */ +#endif +// btla-specific -- + + UINT8 pin_code_len; /* for legacy devices */ + PIN_CODE pin_code; /* for legacy devices */ + tBTM_PAIRING_STATE pairing_state; /* The current pairing state */ + UINT8 pairing_flags; /* The current pairing flags */ + BD_ADDR pairing_bda; /* The device currently pairing */ + 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]; + tBTM_SEC_DEV_REC sec_dev_rec[BTM_SEC_MAX_DEVICE_RECORDS]; + tBTM_SEC_SERV_REC *p_out_serv; + tBTM_MKEY_CALLBACK *mkey_cback; + + BD_ADDR connecting_bda; + DEV_CLASS connecting_dc; + + UINT8 acl_disc_reason; + UINT8 trace_level; + UINT8 busy_level; /* the current busy level */ + BOOLEAN is_paging; /* TRUE, if paging is in progess */ + BOOLEAN is_inquiry; /* TRUE, if inquiry is in progess */ + BUFFER_Q page_queue; + BOOLEAN paging; + BOOLEAN discing; + BUFFER_Q sec_pending_q; /* pending sequrity requests in tBTM_SEC_QUEUE_ENTRY format */ + +#if (!defined(BT_TRACE_VERBOSE) || (BT_TRACE_VERBOSE == FALSE)) + char state_temp_buffer[BTM_STATE_BUFFER_SIZE]; +#endif +} tBTM_CB; + +/* +#ifdef __cplusplus +extern "C" +{ +#endif +*/ + +#if BTM_DYNAMIC_MEMORY == FALSE +extern tBTM_CB btm_cb; +#else +extern tBTM_CB *btm_cb_ptr; +#define btm_cb (*btm_cb_ptr) +#endif + +/* Internal functions provided by btm_main.c +******************************************** +*/ +void btm_init (void); + +/* Internal functions provided by btm_inq.c +******************************************* +*/ +tBTM_STATUS btm_initiate_rem_name (BD_ADDR remote_bda, + tBTM_INQ_INFO *p_cur, + UINT8 origin, UINT32 timeout, + tBTM_CMPL_CB *p_cb); + +void btm_process_remote_name (BD_ADDR bda, BD_NAME name, UINT16 evt_len, + UINT8 hci_status); +void btm_inq_rmt_name_failed(void); + +/* Inquiry related functions */ +void btm_clr_inq_db (BD_ADDR p_bda); +void btm_inq_db_init (void); +void btm_process_inq_results (UINT8 *p, UINT8 inq_res_mode); +void btm_process_inq_complete (UINT8 status, UINT8 mode); +void btm_process_cancel_complete(UINT8 status, UINT8 mode); +void btm_event_filter_complete (UINT8 *p); +void btm_inq_stop_on_ssp(void); +void btm_inq_clear_ssp(void); +tINQ_DB_ENT *btm_inq_db_find (BD_ADDR p_bda); +BOOLEAN btm_inq_find_bdaddr (BD_ADDR p_bda); + +BOOLEAN btm_lookup_eir(BD_ADDR_PTR p_rem_addr); + +/* Internal functions provided by btm_acl.c +******************************************** +*/ +void btm_acl_init (void); +void btm_acl_created (BD_ADDR bda, DEV_CLASS dc, BD_NAME bdn, + UINT16 hci_handle, UINT8 link_role, tBT_TRANSPORT transport); +void btm_acl_removed (BD_ADDR bda, tBT_TRANSPORT transport); +void btm_acl_device_down (void); +void btm_acl_update_busy_level (tBTM_BLI_EVENT event); + +void btm_cont_rswitch (tACL_CONN *p, + tBTM_SEC_DEV_REC *p_dev_rec, + UINT8 hci_status); + +UINT8 btm_handle_to_acl_index (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); +void btm_read_link_quality_complete (UINT8 *p); +tBTM_STATUS btm_set_packet_types (tACL_CONN *p, UINT16 pkt_types); +void btm_process_clk_off_comp_evt (UINT16 hci_handle, UINT16 clock_offset); +void btm_acl_role_changed (UINT8 hci_status, BD_ADDR bd_addr, UINT8 new_role); +void btm_acl_encrypt_change (UINT16 handle, UINT8 status, UINT8 encr_enable); +UINT16 btm_get_acl_disc_reason_code (void); +tBTM_STATUS btm_remove_acl (BD_ADDR bd_addr, tBT_TRANSPORT transport); +void btm_read_remote_features_complete (UINT8 *p); +void btm_read_remote_ext_features_complete (UINT8 *p); +void btm_read_remote_ext_features_failed (UINT8 status, UINT16 handle); +void btm_read_remote_version_complete (UINT8 *p); +void btm_establish_continue (tACL_CONN *p_acl_cb); + +// btla-specific ++ +void btm_acl_chk_peer_pkt_type_support (tACL_CONN *p, UINT16 *p_pkt_type); +// btla-specific -- +/* Read maximum data packet that can be sent over current connection */ +UINT16 btm_get_max_packet_size (BD_ADDR addr); +tACL_CONN *btm_bda_to_acl (BD_ADDR bda, tBT_TRANSPORT transport); +BOOLEAN btm_acl_notif_conn_collision (BD_ADDR bda); + +void btm_pm_reset(void); +void btm_pm_sm_alloc(UINT8 ind); +void btm_pm_proc_cmd_status(UINT8 status); +void btm_pm_proc_mode_change (UINT8 hci_status, UINT16 hci_handle, UINT8 mode, + UINT16 interval); +void btm_pm_proc_ssr_evt (UINT8 *p, UINT16 evt_len); +#if BTM_SCO_INCLUDED == TRUE +void btm_sco_chk_pend_unpark (UINT8 hci_status, UINT16 hci_handle); +#else +#define btm_sco_chk_pend_unpark(hci_status, hci_handle) +#endif /* BTM_SCO_INCLUDED */ +void btm_qos_setup_complete (UINT8 status, UINT16 handle, FLOW_SPEC *p_flow); + + +/* Internal functions provided by btm_sco.c +******************************************** +*/ +void btm_sco_init (void); +void btm_sco_connected (UINT8 hci_status, BD_ADDR bda, UINT16 hci_handle, + tBTM_ESCO_DATA *p_esco_data); +void btm_esco_proc_conn_chg (UINT8 status, UINT16 handle, UINT8 tx_interval, + UINT8 retrans_window, UINT16 rx_pkt_len, + UINT16 tx_pkt_len); +void btm_sco_conn_req (BD_ADDR bda, DEV_CLASS dev_class, UINT8 link_type); +void btm_sco_removed (UINT16 hci_handle, UINT8 reason); +void btm_sco_acl_removed (BD_ADDR bda); +void btm_route_sco_data (BT_HDR *p_msg); +BOOLEAN btm_is_sco_active (UINT16 handle); +void btm_remove_sco_links (BD_ADDR bda); +BOOLEAN btm_is_sco_active_by_bdaddr (BD_ADDR remote_bda); + +tBTM_SCO_TYPE btm_read_def_esco_mode (tBTM_ESCO_PARAMS *p_parms); +UINT16 btm_find_scb_by_handle (UINT16 handle); +void btm_sco_flush_sco_data(UINT16 sco_inx); + +/* Internal functions provided by btm_devctl.c +********************************************** +*/ +void btm_dev_init (void); +void btm_dev_timeout (TIMER_LIST_ENT *p_tle); +void btm_read_local_name_complete (UINT8 *p, UINT16 evt_len); + +#if (BLE_INCLUDED == TRUE) +void btm_ble_add_2_white_list_complete(UINT8 status); +void btm_ble_remove_from_white_list_complete(UINT8 *p, UINT16 evt_len); +void btm_ble_clear_white_list_complete(UINT8 *p, UINT16 evt_len); +BOOLEAN btm_ble_addr_resolvable(BD_ADDR rpa, tBTM_SEC_DEV_REC *p_dev_rec); +tBTM_STATUS btm_ble_read_resolving_list_entry(tBTM_SEC_DEV_REC *p_dev_rec); +BOOLEAN btm_ble_resolving_list_load_dev(tBTM_SEC_DEV_REC *p_dev_rec); +void btm_ble_resolving_list_remove_dev(tBTM_SEC_DEV_REC *p_dev_rec); +#endif /* BLE_INCLUDED */ + +/* Vendor Specific Command complete evt handler */ +void btm_vsc_complete (UINT8 *p, UINT16 cc_opcode, UINT16 evt_len, + tBTM_CMPL_CB *p_vsc_cplt_cback); +void btm_inq_db_reset (void); +void btm_vendor_specific_evt (UINT8 *p, UINT8 evt_len); +void btm_delete_stored_link_key_complete (UINT8 *p); +void btm_report_device_status (tBTM_DEV_STATUS status); + + +/* Internal functions provided by btm_dev.c +********************************************** +*/ +BOOLEAN btm_dev_support_switch (BD_ADDR bd_addr); + +tBTM_SEC_DEV_REC *btm_sec_alloc_dev (BD_ADDR bd_addr); +void btm_sec_free_dev (tBTM_SEC_DEV_REC *p_dev_rec); +tBTM_SEC_DEV_REC *btm_find_dev (BD_ADDR bd_addr); +tBTM_SEC_DEV_REC *btm_find_or_alloc_dev (BD_ADDR bd_addr); +tBTM_SEC_DEV_REC *btm_find_dev_by_handle (UINT16 handle); +tBTM_BOND_TYPE btm_get_bond_type_dev(BD_ADDR bd_addr); +BOOLEAN btm_set_bond_type_dev(BD_ADDR bd_addr, + tBTM_BOND_TYPE bond_type); + +/* Internal functions provided by btm_sec.c +********************************************** +*/ +BOOLEAN btm_dev_support_switch (BD_ADDR bd_addr); +tBTM_STATUS btm_sec_l2cap_access_req (BD_ADDR bd_addr, UINT16 psm, + UINT16 handle, CONNECTION_TYPE conn_type, + tBTM_SEC_CALLBACK *p_callback, void *p_ref_data); +tBTM_STATUS btm_sec_mx_access_request (BD_ADDR bd_addr, UINT16 psm, BOOLEAN is_originator, + UINT32 mx_proto_id, UINT32 mx_chan_id, + tBTM_SEC_CALLBACK *p_callback, void *p_ref_data); +void btm_sec_conn_req (UINT8 *bda, UINT8 *dc); +void btm_create_conn_cancel_complete (UINT8 *p); +void btm_read_linq_tx_power_complete (UINT8 *p); + +void btm_sec_init (UINT8 sec_mode); +void btm_sec_dev_reset (void); +void btm_sec_abort_access_req (BD_ADDR bd_addr); +void btm_sec_auth_complete (UINT16 handle, UINT8 status); +void btm_sec_encrypt_change (UINT16 handle, UINT8 status, UINT8 encr_enable); +void btm_sec_connected (UINT8 *bda, UINT16 handle, UINT8 status, UINT8 enc_mode); +tBTM_STATUS btm_sec_disconnect (UINT16 handle, UINT8 reason); +void btm_sec_disconnected (UINT16 handle, UINT8 reason); +void btm_sec_rmt_name_request_complete (UINT8 *bd_addr, UINT8 *bd_name, UINT8 status); +void btm_sec_rmt_host_support_feat_evt (UINT8 *p); +void btm_io_capabilities_req (UINT8 *p); +void btm_io_capabilities_rsp (UINT8 *p); +void btm_proc_sp_req_evt (tBTM_SP_EVT event, UINT8 *p); +void btm_keypress_notif_evt (UINT8 *p); +void btm_simple_pair_complete (UINT8 *p); +void btm_sec_link_key_notification (UINT8 *p_bda, UINT8 *p_link_key, UINT8 key_type); +void btm_sec_link_key_request (UINT8 *p_bda); +void btm_sec_pin_code_request (UINT8 *p_bda); +void btm_sec_update_clock_offset (UINT16 handle, UINT16 clock_offset); +void btm_sec_dev_rec_cback_event (tBTM_SEC_DEV_REC *p_dev_rec, UINT8 res, BOOLEAN is_le_trasnport); +void btm_sec_set_peer_sec_caps (tACL_CONN *p_acl_cb, tBTM_SEC_DEV_REC *p_dev_rec); + +#if BLE_INCLUDED == TRUE +void btm_sec_clear_ble_keys (tBTM_SEC_DEV_REC *p_dev_rec); +BOOLEAN btm_sec_find_bonded_dev (UINT8 start_idx, UINT8 *p_found_idx, tBTM_SEC_DEV_REC **p_rec); +BOOLEAN btm_sec_is_a_bonded_dev (BD_ADDR bda); +void btm_consolidate_dev(tBTM_SEC_DEV_REC *p_target_rec); +BOOLEAN btm_sec_is_le_capable_dev (BD_ADDR bda); +BOOLEAN btm_ble_init_pseudo_addr (tBTM_SEC_DEV_REC *p_dev_rec, BD_ADDR new_pseudo_addr); +#endif /* BLE_INCLUDED */ + +tINQ_DB_ENT *btm_inq_db_new (BD_ADDR p_bda); + +#if BTM_OOB_INCLUDED == TRUE +void btm_rem_oob_req (UINT8 *p); +void btm_read_local_oob_complete (UINT8 *p); +#else +#define btm_rem_oob_req(p) +#define btm_read_local_oob_complete(p) +#endif + +void btm_acl_resubmit_page (void); +void btm_acl_reset_paging (void); +void btm_acl_paging (BT_HDR *p, BD_ADDR dest); +UINT8 btm_sec_clr_service_by_psm (UINT16 psm); +void btm_sec_clr_temp_auth_service (BD_ADDR bda); + +/* +#ifdef __cplusplus +} +#endif +*/ + +#endif diff --git a/tools/sdk/include/bluedroid/btu.h b/tools/sdk/include/bluedroid/btu.h new file mode 100644 index 00000000..d82d96d7 --- /dev/null +++ b/tools/sdk/include/bluedroid/btu.h @@ -0,0 +1,280 @@ +/****************************************************************************** + * + * Copyright (C) 1999-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 file contains the main Bluetooth Upper Layer definitions. The Broadcom + * implementations of L2CAP RFCOMM, SDP and the BTIf run as one GKI task. The + * btu_task switches between them. + * + ******************************************************************************/ + +#ifndef BTU_H +#define BTU_H + +#include "bt_target.h" +#include "gki.h" + +// HACK(zachoverflow): temporary dark magic +#define BTU_POST_TO_TASK_NO_GOOD_HORRIBLE_HACK 0x1700 // didn't look used in bt_types...here goes nothing +typedef struct { + void (*callback)(BT_HDR *); +} post_to_task_hack_t; + +typedef struct { + void (*callback)(BT_HDR *); + BT_HDR *response; + void *context; +} command_complete_hack_t; + +typedef struct { + void (*callback)(BT_HDR *); + uint8_t status; + BT_HDR *command; + void *context; +} command_status_hack_t; + +/* callbacks +*/ +typedef void (*tBTU_TIMER_CALLBACK)(TIMER_LIST_ENT *p_tle); +typedef void (*tBTU_EVENT_CALLBACK)(BT_HDR *p_hdr); + + +/* Define the timer types maintained by BTU +*/ +#define BTU_TTYPE_BTM_DEV_CTL 1 +#define BTU_TTYPE_L2CAP_LINK 2 +#define BTU_TTYPE_L2CAP_CHNL 3 +#define BTU_TTYPE_L2CAP_HOLD 4 +#define BTU_TTYPE_SDP 5 +#define BTU_TTYPE_BTM_SCO 6 +#define BTU_TTYPE_BTM_ACL 9 +#define BTU_TTYPE_BTM_RMT_NAME 10 +#define BTU_TTYPE_RFCOMM_MFC 11 +#define BTU_TTYPE_RFCOMM_PORT 12 +#define BTU_TTYPE_TCS_L2CAP 13 +#define BTU_TTYPE_TCS_CALL 14 +#define BTU_TTYPE_TCS_WUG 15 +#define BTU_TTYPE_AUTO_SYNC 16 +#define BTU_TTYPE_CTP_RECON 17 +#define BTU_TTYPE_CTP_T100 18 +#define BTU_TTYPE_CTP_GUARD 19 +#define BTU_TTYPE_CTP_DETACH 20 + +#define BTU_TTYPE_SPP_CONN_RETRY 21 +#define BTU_TTYPE_USER_FUNC 22 + +#define BTU_TTYPE_FTP_DISC 25 +#define BTU_TTYPE_OPP_DISC 26 + +#define BTU_TTYPE_CTP_TL_DISCVY 28 +#define BTU_TTYPE_IPFRAG_TIMER 29 +#define BTU_TTYPE_HSP2_AT_CMD_TO 30 +#define BTU_TTYPE_HSP2_REPEAT_RING 31 + +#define BTU_TTYPE_CTP_GW_INIT 32 +#define BTU_TTYPE_CTP_GW_CONN 33 +#define BTU_TTYPE_CTP_GW_IDLE 35 + +#define BTU_TTYPE_ICP_L2CAP 36 +#define BTU_TTYPE_ICP_T100 37 + +#define BTU_TTYPE_HSP2_WAIT_OK 38 + +/* HCRP Timers */ +#define BTU_TTYPE_HCRP_NOTIF_REG 39 +#define BTU_TTYPE_HCRP_PROTO_RSP 40 +#define BTU_TTYPE_HCRP_CR_GRANT 41 +#define BTU_TTYPE_HCRP_CR_CHECK 42 +#define BTU_TTYPE_HCRP_W4_CLOSE 43 + +/* HCRPM Timers */ +#define BTU_TTYPE_HCRPM_NOTIF_REG 44 +#define BTU_TTYPE_HCRPM_NOTIF_KEEP 45 +#define BTU_TTYPE_HCRPM_API_RSP 46 +#define BTU_TTYPE_HCRPM_W4_OPEN 47 +#define BTU_TTYPE_HCRPM_W4_CLOSE 48 + +/* BNEP Timers */ +#define BTU_TTYPE_BNEP 50 + +#define BTU_TTYPE_HSP2_SDP_FAIL_TO 55 +#define BTU_TTYPE_HSP2_SDP_RTRY_TO 56 + +/* BTU internal */ +/* unused 60 */ + +#define BTU_TTYPE_AVDT_CCB_RET 61 +#define BTU_TTYPE_AVDT_CCB_RSP 62 +#define BTU_TTYPE_AVDT_CCB_IDLE 63 +#define BTU_TTYPE_AVDT_SCB_TC 64 + +#define BTU_TTYPE_HID_DEV_REPAGE_TO 65 +#define BTU_TTYPE_HID_HOST_REPAGE_TO 66 + +#define BTU_TTYPE_HSP2_DELAY_CKPD_RCV 67 + +#define BTU_TTYPE_SAP_TO 68 + +/* BPP Timer */ +#define BTU_TTYPE_BPP_REF_CHNL 72 + +/* LP HC idle Timer */ +#define BTU_TTYPE_LP_HC_IDLE_TO 74 + +/* Patch RAM Timer */ +#define BTU_TTYPE_PATCHRAM_TO 75 + +/* eL2CAP Info Request and other proto cmds timer */ +#define BTU_TTYPE_L2CAP_FCR_ACK 78 +#define BTU_TTYPE_L2CAP_INFO 79 + +#define BTU_TTYPE_MCA_CCB_RSP 98 + +/* BTU internal timer for BLE activity */ +#define BTU_TTYPE_BLE_INQUIRY 99 +#define BTU_TTYPE_BLE_GAP_LIM_DISC 100 +#define BTU_TTYPE_ATT_WAIT_FOR_RSP 101 +#define BTU_TTYPE_SMP_PAIRING_CMD 102 +#define BTU_TTYPE_BLE_RANDOM_ADDR 103 +#define BTU_TTYPE_ATT_WAIT_FOR_APP_RSP 104 +#define BTU_TTYPE_ATT_WAIT_FOR_IND_ACK 105 + +#define BTU_TTYPE_BLE_GAP_FAST_ADV 106 +#define BTU_TTYPE_BLE_OBSERVE 107 + + +#define BTU_TTYPE_UCD_TO 108 + +/* This is the inquiry response information held by BTU, and available +** to applications. +*/ +typedef struct { + BD_ADDR remote_bd_addr; + UINT8 page_scan_rep_mode; + UINT8 page_scan_per_mode; + UINT8 page_scan_mode; + DEV_CLASS dev_class; + UINT16 clock_offset; +} tBTU_INQ_INFO; + + + +#define BTU_MAX_REG_TIMER (2) /* max # timer callbacks which may register */ +#define BTU_MAX_REG_EVENT (6) /* max # event callbacks which may register */ +#define BTU_DEFAULT_DATA_SIZE (0x2a0) + +#if (BLE_INCLUDED == TRUE) +#define BTU_DEFAULT_BLE_DATA_SIZE (27) +#endif + +/* structure to hold registered timers */ +typedef struct { + TIMER_LIST_ENT *p_tle; /* timer entry */ + tBTU_TIMER_CALLBACK timer_cb; /* callback triggered when timer expires */ +} tBTU_TIMER_REG; + +/* structure to hold registered event callbacks */ +typedef struct { + UINT16 event_range; /* start of event range */ + tBTU_EVENT_CALLBACK event_cb; /* callback triggered when event is in range */ +} tBTU_EVENT_REG; + +#define NFC_MAX_LOCAL_CTRLS 0 + +/* the index to BTU command queue array */ +#define NFC_CONTROLLER_ID (1) +#define BTU_MAX_LOCAL_CTRLS (1 + NFC_MAX_LOCAL_CTRLS) /* only BR/EDR */ + +/* Define structure holding BTU variables +*/ +typedef struct { + tBTU_TIMER_REG timer_reg[BTU_MAX_REG_TIMER]; + tBTU_EVENT_REG event_reg[BTU_MAX_REG_EVENT]; + + BOOLEAN reset_complete; /* TRUE after first ack from device received */ + UINT8 trace_level; /* Trace level for HCI layer */ +} tBTU_CB; + +/* +#ifdef __cplusplus +extern "C" { +#endif +*/ +/* Global BTU data */ +#if BTU_DYNAMIC_MEMORY == FALSE +extern tBTU_CB btu_cb; +#else +extern tBTU_CB *btu_cb_ptr; +#define btu_cb (*btu_cb_ptr) +#endif + +extern const BD_ADDR BT_BD_ANY; + +/* Functions provided by btu_task.c +************************************ +*/ +void btu_start_timer (TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout); +void btu_stop_timer (TIMER_LIST_ENT *p_tle); +void btu_start_timer_oneshot(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout); +void btu_stop_timer_oneshot(TIMER_LIST_ENT *p_tle); + +void btu_uipc_rx_cback(BT_HDR *p_msg); + +/* +** Quick Timer +*/ +#if defined(QUICK_TIMER_TICKS_PER_SEC) && (QUICK_TIMER_TICKS_PER_SEC > 0) +void btu_start_quick_timer (TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout); +void btu_stop_quick_timer (TIMER_LIST_ENT *p_tle); +void btu_process_quick_timer_evt (void); +#endif + +#if (defined(HCILP_INCLUDED) && HCILP_INCLUDED == TRUE) +void btu_check_bt_sleep (void); +#endif + +/* Functions provided by btu_hcif.c +************************************ +*/ +void btu_hcif_process_event (UINT8 controller_id, BT_HDR *p_buf); +void btu_hcif_send_cmd (UINT8 controller_id, BT_HDR *p_msg); +void btu_hcif_send_host_rdy_for_data(void); +void btu_hcif_cmd_timeout (UINT8 controller_id); + +/* Functions provided by btu_core.c +************************************ +*/ +void btu_init_core(void); +void btu_free_core(void); + +void BTU_StartUp(void); +void BTU_ShutDown(void); + +void btu_task_start_up(void); +void btu_task_shut_down(void); + +UINT16 BTU_BleAclPktSize(void); + +/* +#ifdef __cplusplus +} +#endif +*/ + +#endif diff --git a/tools/sdk/include/bluedroid/buffer.h b/tools/sdk/include/bluedroid/buffer.h new file mode 100755 index 00000000..fd1b2fa3 --- /dev/null +++ b/tools/sdk/include/bluedroid/buffer.h @@ -0,0 +1,59 @@ +/****************************************************************************** + * + * 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 _BUFFER_H_ +#define _BUFFER_H_ + +#include +#include + +typedef struct buffer_t buffer_t; + +// Returns a new buffer of |size| bytes. Returns NULL if a buffer could not be +// allocated. |size| must be non-zero. The caller must release this buffer with +// |buffer_free|. +buffer_t *buffer_new(size_t size); + +// Creates a new reference to the buffer |buf|. A reference is indistinguishable +// from the original: writes to the original will be reflected in the reference +// and vice versa. In other words, this function creates an alias to |buf|. The +// caller must release the returned buffer with |buffer_free|. Note that releasing +// the returned buffer does not release |buf|. |buf| must not be NULL. +buffer_t *buffer_new_ref(const buffer_t *buf); + +// Creates a new reference to the last |slice_size| bytes of |buf|. See +// |buffer_new_ref| for a description of references. |slice_size| must be +// greater than 0 and may be at most |buffer_length| +// (0 < slice_size <= buffer_length). |buf| must not be NULL. +buffer_t *buffer_new_slice(const buffer_t *buf, size_t slice_size); + +// Frees a buffer object. |buf| may be NULL. +void buffer_free(buffer_t *buf); + +// Returns a pointer to a writeable memory region for |buf|. All references +// and slices that share overlapping bytes will also be written to when +// writing to the returned pointer. The caller may safely write up to +// |buffer_length| consecutive bytes starting at the address returned by +// this function. |buf| must not be NULL. +void *buffer_ptr(const buffer_t *buf); + +// Returns the length of the writeable memory region referred to by |buf|. +// |buf| must not be NULL. +size_t buffer_length(const buffer_t *buf); + +#endif /*_BUFFER_H_*/ diff --git a/tools/sdk/include/bluedroid/buffer_allocator.h b/tools/sdk/include/bluedroid/buffer_allocator.h new file mode 100755 index 00000000..9dd7ba7c --- /dev/null +++ b/tools/sdk/include/bluedroid/buffer_allocator.h @@ -0,0 +1,25 @@ +/****************************************************************************** + * + * 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 _BUFFER_ALLOCATOR_H_ + +#include "allocator.h" + +const allocator_t *buffer_allocator_get_interface(); + +#endif /*_BUFFER_ALLOCATOR_H_*/ diff --git a/tools/sdk/include/bluedroid/button_pro.h b/tools/sdk/include/bluedroid/button_pro.h new file mode 100644 index 00000000..cbc2d68d --- /dev/null +++ b/tools/sdk/include/bluedroid/button_pro.h @@ -0,0 +1,120 @@ +#include "prf_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. + + +#if (BUT_PROFILE_CFG) +#include "bt_target.h" +#include "gatt_api.h" +#include "gattdefs.h" +#include "esp_gatt_api.h" + +#define KEY_SUCCESS GATT_SUCCESS +#define KEY_ILLEGAL_PARAM GATT_ILLEGAL_PARAMETER +#define KEY_NO_RESOURCES GATT_NO_RESOURCES + +//define the key serivce uuid +#define ATT_SVC_BUTTON 0xFFFF +//define the key Char uuid +#define ATT_CHAR_BUTTON_WIT 0xFF01 +#define ATT_CHAR_BUTTON_NTF 0xFF02 + +#define BUTTON_PRESS_NTF_CFG 0x01 + +#define BUTTON_VAL_MAX_LEN (10) + +#define BUTT_MAX_APPS GATT_CL_MAX_LCB + +#define BUT_MAX_STRING_DATA 7 + +typedef void (*but_prf_cb_t)(uint8_t app_id, uint8_t event, uint16_t len, uint8_t *value); + +#ifndef BUT_MAX_INT_NUM +#define BUT_MAX_INT_NUM 4 +#endif + +enum { + RECEIVE_NET_PASSWD_EVT, + RECEIVE_NET_SSD_EVT, + RECEIVE_EVT_MAX +}; + +/// button Service Attributes Indexes +enum { + KEY_IDX_SVC, + KEY_IDX_BUTTON_WIT_CHAR, + KEY_IDX_BUTTON_WIT_VAL, + KEY_IDX_BUTTON_NTF_CHAR, + KEY_IDX_BUTTON_NTF_VAL, + KEY_IDX_BUTTON_NTF_CFG, + + KEY_IDX_NB, +}; + +typedef struct { + BD_ADDR remote_bda; + BOOLEAN need_rsp; + uint16_t clt_cfg; +} but_write_data_t; + +typedef struct { + BOOLEAN in_use; + BOOLEAN congest; + uint16_t conn_id; + BOOLEAN connected; + BD_ADDR remote_bda; + uint32_t trans_id; + uint8_t cur_srvc_id; + +} but_clcb_t; + + +typedef struct { + uint8_t app_id; + uint16_t but_wirt_hdl; + uint16_t but_ntf_hdl; + uint16_t but_cfg_hdl; + + but_prf_cb_t p_cback; + +} but_inst_t; + + +/* service engine control block */ +typedef struct { + but_clcb_t clcb; /* connection link*/ + esp_gatt_if_t gatt_if; + BOOLEAN enabled; + BOOLEAN is_primery; + but_inst_t button_inst; + uint8_t inst_id; +} button_env_cb_t; + +void Button_CreateService(void); + +but_clcb_t *button_env_clcb_alloc(uint16_t conn_id, BD_ADDR bda); + +uint16_t button_env_find_conn_id_by_bd_adddr(BD_ADDR bda); + +BOOLEAN button_env_clcb_dealloc(uint16_t conn_id); + +esp_gatt_status_t button_init(but_prf_cb_t call_back); + +void button_disable(uint16_t connid); + +void button_msg_notify(uint16_t len, uint8_t *button_msg); + +extern button_env_cb_t button_cb_env; + +#endif ///BUT_PROFILE_CFG diff --git a/tools/sdk/include/bluedroid/controller.h b/tools/sdk/include/bluedroid/controller.h new file mode 100644 index 00000000..6d6e5a8c --- /dev/null +++ b/tools/sdk/include/bluedroid/controller.h @@ -0,0 +1,85 @@ +/****************************************************************************** + * + * 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 _CONTROLLER_H_ +#define _CONTROLLER_H_ + +#include +#include + +#include "bt_target.h" +#include "bdaddr.h" +#include "device_features.h" +#include "hci_layer.h" +#include "hci_packet_factory.h" +#include "hci_packet_parser.h" + +typedef struct controller_t { + void (*start_up)(void); + void (*shut_down)(void); + bool (*get_is_ready)(void); + + const bt_bdaddr_t *(*get_address)(void); + const bt_version_t *(*get_bt_version)(void); + + const bt_device_features_t *(*get_features_classic)(int index); + + uint8_t (*get_last_features_classic_index)(void); + + const bt_device_features_t *(*get_features_ble)(void); + const uint8_t *(*get_ble_supported_states)(void); + + bool (*supports_simple_pairing)(void); + bool (*supports_secure_connections)(void); + bool (*supports_simultaneous_le_bredr)(void); + bool (*supports_reading_remote_extended_features)(void); + bool (*supports_interlaced_inquiry_scan)(void); + bool (*supports_rssi_with_inquiry_results)(void); + bool (*supports_extended_inquiry_response)(void); + bool (*supports_master_slave_role_switch)(void); + + bool (*supports_ble)(void); + bool (*supports_ble_packet_extension)(void); + bool (*supports_ble_connection_parameters_request)(void); + bool (*supports_ble_privacy)(void); + + // Get the cached acl data sizes for the controller. + uint16_t (*get_acl_data_size_classic)(void); + uint16_t (*get_acl_data_size_ble)(void); + + // Get the cached acl packet sizes for the controller. + // This is a convenience function for the respective + // acl data size + size of the acl header. + uint16_t (*get_acl_packet_size_classic)(void); + uint16_t (*get_acl_packet_size_ble)(void); + + uint16_t (*get_ble_default_data_packet_length)(void); + + // Get the number of acl packets the controller can buffer. + uint16_t (*get_acl_buffer_count_classic)(void); + uint8_t (*get_acl_buffer_count_ble)(void); + + uint8_t (*get_ble_white_list_size)(void); + + uint8_t (*get_ble_resolving_list_max_size)(void); + void (*set_ble_resolving_list_max_size)(int resolving_list_max_size); +} controller_t; + +const controller_t *controller_get_interface(); + +#endif /*_CONTROLLER_H_*/ diff --git a/tools/sdk/include/bluedroid/device_features.h b/tools/sdk/include/bluedroid/device_features.h new file mode 100644 index 00000000..360d3768 --- /dev/null +++ b/tools/sdk/include/bluedroid/device_features.h @@ -0,0 +1,29 @@ +/****************************************************************************** + * + * 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 _DEVICE_FEATURES_H_ +#define _DEVICE_FEATURES_H_ + +#include + +// Represents a page of device feature enabled/disabled bits returned +// by the local controller. See the bluetooth spec for bit indexes. +typedef struct { + uint8_t as_array[8]; +} bt_device_features_t; + +#endif /*_DEVICE_FEATURES_H_*/ diff --git a/tools/sdk/include/bluedroid/dis_api.h b/tools/sdk/include/bluedroid/dis_api.h new file mode 100644 index 00000000..5b8cfc5f --- /dev/null +++ b/tools/sdk/include/bluedroid/dis_api.h @@ -0,0 +1,338 @@ +/****************************************************************************** + * + * Copyright (C) 1999-2013 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. + * + ******************************************************************************/ + +/******************************************************************************* +** +** Header file for profile folder. +** +********************************************************************************/ + +#ifndef SRVC_DIS_API_H +#define SRVC_DIS_API_H + +#include "bt_target.h" +#include "gatt_api.h" +#include "gattdefs.h" +#include "esp_gatts_api.h" + +#define DIS_SUCCESS GATT_SUCCESS +#define DIS_ILLEGAL_PARAM GATT_ILLEGAL_PARAMETER +#define DIS_NO_RESOURCES GATT_NO_RESOURCES +typedef UINT8 tDIS_STATUS; + + +/***************************************************************************** +** Data structure for DIS +*****************************************************************************/ + +#define DIS_ATTR_SYS_ID_BIT 0x0001 +#define DIS_ATTR_MODEL_NUM_BIT 0x0002 +#define DIS_ATTR_SERIAL_NUM_BIT 0x0004 +#define DIS_ATTR_FW_NUM_BIT 0x0008 +#define DIS_ATTR_HW_NUM_BIT 0x0010 +#define DIS_ATTR_SW_NUM_BIT 0x0020 +#define DIS_ATTR_MANU_NAME_BIT 0x0040 +#define DIS_ATTR_IEEE_DATA_BIT 0x0080 +#define DIS_ATTR_PNP_ID_BIT 0x0100 +typedef UINT16 tDIS_ATTR_MASK; + +#define DIS_ATTR_ALL_MASK 0xffff + +typedef tDIS_ATTR_MASK tDIS_ATTR_BIT ; + +#define DIS_MAX_NUM_INC_SVR 0 +#define DIS_MAX_CHAR_NUM 9 +#define DIS_MAX_ATTR_NUM (DIS_MAX_CHAR_NUM * 2 + DIS_MAX_NUM_INC_SVR + 1) + +#ifndef DIS_ATTR_DB_SIZE +#define DIS_ATTR_DB_SIZE GATT_DB_MEM_SIZE(DIS_MAX_NUM_INC_SVR, DIS_MAX_CHAR_NUM, 0) +#endif + +#define DIS_SYSTEM_ID_SIZE 8 +#define DIS_PNP_ID_SIZE 7 + + +typedef struct { + UINT16 uuid; + UINT16 handle; +} tDIS_DB_ENTRY; + +typedef struct { + UINT16 len; + UINT8 *p_data; +} tDIS_STRING; + +typedef struct { + UINT16 vendor_id; + UINT16 product_id; + UINT16 product_version; + UINT8 vendor_id_src; + +} tDIS_PNP_ID; + +typedef union { + UINT64 system_id; + tDIS_PNP_ID pnp_id; + tDIS_STRING data_str; +} tDIS_ATTR; + +#define DIS_MAX_STRING_DATA 7 + +typedef struct { + UINT16 attr_mask; + UINT64 system_id; + tDIS_PNP_ID pnp_id; + UINT8 *data_string[DIS_MAX_STRING_DATA]; +} tDIS_VALUE; + +//typedef void (tDIS_READ_CBACK)(BD_ADDR addr, tDIS_VALUE *p_dis_value); + +typedef struct { + tDIS_DB_ENTRY dis_attr[DIS_MAX_CHAR_NUM]; + tDIS_VALUE dis_value; + +// tDIS_READ_CBACK *p_read_dis_cback; + + UINT16 service_handle; + UINT16 max_handle; + + bool enabled; + + // UINT8 dis_read_uuid_idx; + // tDIS_ATTR_MASK request_mask; +} tDIS_CB; + +/***************************************************************************** +** Data structure used by Battery Service +*****************************************************************************/ + +#ifndef BA_MAX_INT_NUM +#define BA_MAX_INT_NUM 4 +#endif + +#define BATTERY_LEVEL_SIZE 1 + +typedef struct { + BD_ADDR remote_bda; + BOOLEAN need_rsp; + UINT16 clt_cfg; +} tBA_WRITE_DATA; + +#define BA_READ_CLT_CFG_REQ 1 +#define BA_READ_PRE_FMT_REQ 2 +#define BA_READ_RPT_REF_REQ 3 +#define BA_READ_LEVEL_REQ 4 +#define BA_WRITE_CLT_CFG_REQ 5 + +typedef void (tBA_CBACK)(UINT32 trans_id, UINT16 conn_id, UINT8 app_id, UINT8 event, tBA_WRITE_DATA *p_data); + +#define BA_LEVEL_NOTIFY 0x01 +#define BA_LEVEL_PRE_FMT 0x02 +#define BA_LEVEL_RPT_REF 0x04 +typedef UINT8 tBA_LEVEL_DESCR; + +typedef struct { + BOOLEAN is_pri; + tBA_LEVEL_DESCR ba_level_descr; + tGATT_TRANSPORT transport; + tBA_CBACK *p_cback; + +} tBA_REG_INFO; + +typedef union { + UINT8 ba_level; + UINT16 clt_cfg; + tGATT_CHAR_RPT_REF rpt_ref; + tGATT_CHAR_PRES pres_fmt; +} tBA_RSP_DATA; + +typedef struct { + UINT8 app_id; + UINT16 ba_level_hdl; + UINT16 clt_cfg_hdl; + UINT16 rpt_ref_hdl; + UINT16 pres_fmt_hdl; + + tBA_CBACK *p_cback; + + UINT16 pending_handle; + //UINT8 pending_clcb_idx; + UINT8 pending_evt; +} tBA_INST; + +typedef struct { + tBA_INST battery_inst[BA_MAX_INT_NUM]; + UINT8 inst_id; + bool enabled; +} tBATTERY_CB; +/***************************************************************************** +** External Function Declarations +*****************************************************************************/ +#ifdef __cplusplus +extern "C" +{ +#endif +/***************************************************************************** +** Service Engine API +*****************************************************************************/ +/******************************************************************************* +** +** Function srvc_eng_init +** +** Description Initializa the GATT Service engine, register a GATT application +** as for a central service management. +** +*******************************************************************************/ +//extern tGATT_STATUS srvc_eng_init (void); + + +/***************************************************************************** +** DIS Server Function +*****************************************************************************/ + +extern bool dis_valid_handle_range(UINT16 handle); +/******************************************************************************* +** +** Function DIS_Init +** +** Description Initializa the Device Information Service Server. +** +*******************************************************************************/ +extern void DIS_Init (tBTA_GATTS_IF gatt_if, tDIS_ATTR_MASK dis_attr_mask); +/******************************************************************************* +** +** Function DIS_SrUpdate +** +** Description Update the DIS server attribute values +** +*******************************************************************************/ +extern tDIS_STATUS DIS_SrUpdate(tDIS_ATTR_BIT dis_attr_bit, tDIS_ATTR *p_info); +/******************************************************************************* +** +** Function dis_AddChar +** +** Description add characteristic for dis +** +*******************************************************************************/ +extern void dis_AddChar(UINT16 service_id); +/******************************************************************************* +** dis_s_read_attr_value +** +** Process read DIS attribute request. +*******************************************************************************/ + +extern void dis_s_read_attr_value (tGATTS_DATA *p_data, tGATT_VALUE *p_value, + UINT32 trans_id, UINT16 conn_id); +/***************************************************************************** +** DIS Client Function +*****************************************************************************/ +/******************************************************************************* +** +** Function DIS_ReadDISInfo +** +** Description Read remote device DIS information. +** +** Returns void +** +*******************************************************************************/ +//extern BOOLEAN DIS_ReadDISInfo(BD_ADDR peer_bda, tDIS_READ_CBACK *p_cback, +// tDIS_ATTR_MASK mask); + +/******************************************************************************* +** BATTERY SERVICE API +*******************************************************************************/ +/*************************************************************** +** +** Function bas_register +** +** Description register app for battery service +** +****************************************************************/ +extern void bas_register(void); +/*************************************************************** +** +** Function bas_init +** +** Description register battery service +** +****************************************************************/ +extern void bas_init(tBTA_GATTS_IF gatt_if, UINT16 app_id); + +/*************************************************************** +** +** Function bas_AddChar +** +** Description add characteristic for battery service +** +****************************************************************/ +extern void bas_AddChar(UINT16 service_id, tBT_UUID *char_uuid); +/*************************************************************** +** +** Function bas_AddCharDescr +** +** Description add descriptor for battery service if needed +** +****************************************************************/ +extern void bas_AddCharDescr(UINT16 service_id, UINT16 attr_id); +/*************************************************************** +** +** Function bas_service_cmpl +** +** Description create battery service complete +** +****************************************************************/ +extern void bas_service_cmpl(UINT16 service_id, tBTA_GATT_STATUS status); +/******************************************************************************* +** +** Function Battery_Rsp +** +** Description Respond to a battery service request +** +*******************************************************************************/ +extern void Battery_Rsp (UINT32 trans_id, UINT16 conn_id, UINT8 app_id, + tGATT_STATUS st, UINT8 event, tBA_RSP_DATA *p_rsp); +/******************************************************************************* +** +** Function Battery_Notify +** +** Description Send battery level notification +** +*******************************************************************************/ +extern void Battery_Notify (UINT16 conn_id, UINT8 app_id, BD_ADDR remote_bda, UINT8 battery_level); + +/***************************************************************************** +** Function bas_s_read_attr_value +** +** Description it will be called when client send a read request +******************************************************************************/ +extern void bas_s_read_attr_value(tGATTS_DATA *p_data, UINT32 trans_id, UINT16 conn_id); +/***************************************************************************** +** Function bas_s_write_attr_value +** +** Description it will be called when client send a write request +******************************************************************************/ +extern void bas_s_write_attr_value(tGATTS_DATA *p_data, UINT32 trans_id, + UINT16 conn_id, BD_ADDR bd_addr); + +extern void gatts_server_test(void); +#ifdef __cplusplus + +} +#endif + +#endif diff --git a/tools/sdk/include/bluedroid/dyn_mem.h b/tools/sdk/include/bluedroid/dyn_mem.h new file mode 100755 index 00000000..9a95fb95 --- /dev/null +++ b/tools/sdk/include/bluedroid/dyn_mem.h @@ -0,0 +1,155 @@ +/****************************************************************************** + * + * 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. + * + ******************************************************************************/ +#ifndef DYN_MEM_H +#define DYN_MEM_H + +/**************************************************************************** +** Define memory usage for each CORE component (if not defined in bdroid_buildcfg.h) +** The default for each component is to use static memory allocations. +*/ +#ifndef BTU_DYNAMIC_MEMORY +#define BTU_DYNAMIC_MEMORY FALSE +#endif + +#ifndef BTM_DYNAMIC_MEMORY +#define BTM_DYNAMIC_MEMORY FALSE +#endif + +#ifndef SDP_DYNAMIC_MEMORY +//#define SDP_DYNAMIC_MEMORY FALSE +#define SDP_DYNAMIC_MEMORY TRUE +#endif + +#ifndef L2C_DYNAMIC_MEMORY +#define L2C_DYNAMIC_MEMORY FALSE +#endif + +#ifndef RFC_DYNAMIC_MEMORY +#define RFC_DYNAMIC_MEMORY FALSE +#endif + +#ifndef TCS_DYNAMIC_MEMORY +#define TCS_DYNAMIC_MEMORY FALSE +#endif + +#ifndef BNEP_DYNAMIC_MEMORY +#define BNEP_DYNAMIC_MEMORY FALSE +#endif + +#ifndef AVDT_DYNAMIC_MEMORY +#define AVDT_DYNAMIC_MEMORY FALSE +#endif + +#ifndef AVCT_DYNAMIC_MEMORY +#define AVCT_DYNAMIC_MEMORY FALSE +#endif + +#ifndef MCA_DYNAMIC_MEMORY +#define MCA_DYNAMIC_MEMORY FALSE +#endif + +#ifndef GATT_DYNAMIC_MEMORY +#define GATT_DYNAMIC_MEMORY FALSE +#endif + +#ifndef SMP_DYNAMIC_MEMORY +#define SMP_DYNAMIC_MEMORY FALSE +#endif + +/**************************************************************************** +** Define memory usage for each PROFILE component (if not defined in bdroid_buildcfg.h) +** The default for each component is to use static memory allocations. +*/ +#ifndef A2D_DYNAMIC_MEMORY +#define A2D_DYNAMIC_MEMORY FALSE +#endif + +#ifndef VDP_DYNAMIC_MEMORY +#define VDP_DYNAMIC_MEMORY FALSE +#endif + +#ifndef AVRC_DYNAMIC_MEMORY +#define AVRC_DYNAMIC_MEMORY FALSE +#endif + +#ifndef BIP_DYNAMIC_MEMORY +#define BIP_DYNAMIC_MEMORY FALSE +#endif + +#ifndef BPP_DYNAMIC_MEMORY +#define BPP_DYNAMIC_MEMORY FALSE +#endif + +#ifndef CTP_DYNAMIC_MEMORY +#define CTP_DYNAMIC_MEMORY FALSE +#endif + +#ifndef FTP_DYNAMIC_MEMORY +#define FTP_DYNAMIC_MEMORY FALSE +#endif + +#ifndef HCRP_DYNAMIC_MEMORY +#define HCRP_DYNAMIC_MEMORY FALSE +#endif + +#ifndef HFP_DYNAMIC_MEMORY +#define HFP_DYNAMIC_MEMORY FALSE +#endif + +#ifndef HID_DYNAMIC_MEMORY +#define HID_DYNAMIC_MEMORY FALSE +#endif + +#ifndef HSP2_DYNAMIC_MEMORY +#define HSP2_DYNAMIC_MEMORY FALSE +#endif + +#ifndef ICP_DYNAMIC_MEMORY +#define ICP_DYNAMIC_MEMORY FALSE +#endif + +#ifndef OPP_DYNAMIC_MEMORY +#define OPP_DYNAMIC_MEMORY FALSE +#endif + +#ifndef PAN_DYNAMIC_MEMORY +#define PAN_DYNAMIC_MEMORY FALSE +#endif + +#ifndef SPP_DYNAMIC_MEMORY +#define SPP_DYNAMIC_MEMORY FALSE +#endif + +#ifndef SLIP_DYNAMIC_MEMORY +#define SLIP_DYNAMIC_MEMORY FALSE +#endif + +#ifndef LLCP_DYNAMIC_MEMORY +#define LLCP_DYNAMIC_MEMORY FALSE +#endif + +/**************************************************************************** +** Define memory usage for BTA (if not defined in bdroid_buildcfg.h) +** The default for each component is to use static memory allocations. +*/ +#ifndef BTA_DYNAMIC_MEMORY +#define BTA_DYNAMIC_MEMORY FALSE +#endif + +#endif /* #ifdef DYN_MEM_H */ + diff --git a/tools/sdk/include/bluedroid/esp_blufi_api.h b/tools/sdk/include/bluedroid/esp_blufi_api.h new file mode 100644 index 00000000..6da65121 --- /dev/null +++ b/tools/sdk/include/bluedroid/esp_blufi_api.h @@ -0,0 +1,360 @@ +// 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 __ESP_BLUFI_API_H__ +#define __ESP_BLUFI_API_H__ + +#include "esp_bt_defs.h" +#include "esp_gatt_defs.h" +#include "esp_err.h" +#include "esp_wifi_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + ESP_BLUFI_EVENT_INIT_FINISH = 0, /* +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/// 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_t; + +/// Default GATT interface id +#define ESP_DEFAULT_GATT_IF 0xff + +/// Default BLE connection param, if the value doesn't be overwritten +#define ESP_BLE_CONN_PARAM_UNDEF 0xffff /* use this value when a specific value not to be overwritten */ + +/// Check the param is valid or not +#define ESP_BLE_IS_VALID_PARAM(x, min, max) (((x) >= (min) && (x) <= (max)) || ((x) == ESP_BLE_CONN_PARAM_UNDEF)) + +/// UUID type +typedef struct { +#define ESP_UUID_LEN_16 2 +#define ESP_UUID_LEN_32 4 +#define ESP_UUID_LEN_128 16 + uint16_t len; /*!< UUID length, 16bit, 32bit or 128bit */ + union { + uint16_t uuid16; + uint32_t uuid32; + uint8_t uuid128[ESP_UUID_LEN_128]; + } uuid; /*!< UUID */ +} __attribute__((packed)) esp_bt_uuid_t; + +/// Bluetooth device type +typedef enum { + ESP_BT_DEVICE_TYPE_BREDR = 0x01, + ESP_BT_DEVICE_TYPE_BLE = 0x02, + ESP_BT_DEVICE_TYPE_DUMO = 0x03, +} esp_bt_dev_type_t; + +/// Bluetooth address length +#define ESP_BD_ADDR_LEN 6 + +/// Bluetooth device address +typedef uint8_t esp_bd_addr_t[ESP_BD_ADDR_LEN]; + +/// Own BD address source of the device +typedef enum { + /// Public Address + BD_ADDR_PUBLIC, + /// Provided random address + BD_ADDR_PROVIDED_RND, + /// Provided static random address + BD_ADDR_GEN_STATIC_RND, + /// Generated resolvable private random address + BD_ADDR_GEN_RSLV, + /// Generated non-resolvable private random address + BD_ADDR_GEN_NON_RSLV, + /// Provided Reconnection address + BD_ADDR_PROVIDED_RECON, +} esp_bd_addr_type_t; + +/// BLE device address type +typedef enum { + BLE_ADDR_TYPE_PUBLIC = 0x00, + BLE_ADDR_TYPE_RANDOM = 0x01, + BLE_ADDR_TYPE_RPA_PUBLIC = 0x02, + BLE_ADDR_TYPE_RPA_RANDOM = 0x03, +} esp_ble_addr_type_t; + +/// Minimum of the application id +#define ESP_APP_ID_MIN 0x0000 +/// Maximum of the application id +#define ESP_APP_ID_MAX 0x7fff + +#define ESP_BD_ADDR_STR "%02x:%02x:%02x:%02x:%02x:%02x" +#define ESP_BD_ADDR_HEX(addr) addr[0], addr[1], addr[2], addr[3], addr[4], addr[5] + +#ifdef __cplusplus +} +#endif + +#endif /* __ESP_BT_DEFS_H__ */ diff --git a/tools/sdk/include/bluedroid/esp_bt_device.h b/tools/sdk/include/bluedroid/esp_bt_device.h new file mode 100644 index 00000000..c84d042d --- /dev/null +++ b/tools/sdk/include/bluedroid/esp_bt_device.h @@ -0,0 +1,38 @@ +// 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 __ESP_BT_DEVICE_H__ +#define __ESP_BT_DEVICE_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * + * @brief Get bluetooth device address. Must use after "esp_bluedroid_enable". + * + * @return bluetooth device address (six bytes), or NULL if bluetooth stack is not enabled + */ +const uint8_t *esp_bt_dev_get_address(void); + +#ifdef __cplusplus +} +#endif + + +#endif /* __ESP_BT_DEVICE_H__ */ diff --git a/tools/sdk/include/bluedroid/esp_bt_main.h b/tools/sdk/include/bluedroid/esp_bt_main.h new file mode 100644 index 00000000..fad010d2 --- /dev/null +++ b/tools/sdk/include/bluedroid/esp_bt_main.h @@ -0,0 +1,81 @@ +// 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 __ESP_BT_MAIN_H__ +#define __ESP_BT_MAIN_H__ + +#include "esp_err.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Bluetooth stack status type, to indicate whether the bluetooth stack is ready + */ +typedef enum { + ESP_BLUEDROID_STATUS_UNINITIALIZED = 0, /*!< Bluetooth not initialized */ + ESP_BLUEDROID_STATUS_INITIALIZED, /*!< Bluetooth initialized but not enabled */ + ESP_BLUEDROID_STATUS_ENABLED /*!< Bluetooth initialized and enabled */ +} esp_bluedroid_status_t; + +/** + * @brief Get bluetooth stack status + * + * @return Bluetooth stack status + * + */ +esp_bluedroid_status_t esp_bluedroid_get_status(void); + +/** + * @brief Enable bluetooth, must after esp_bluedroid_init() + * + * @return + * - ESP_OK : Succeed + * - Other : Failed + */ +esp_err_t esp_bluedroid_enable(void); + +/** + * @brief Disable bluetooth, must prior to esp_bluedroid_deinit() + * + * @return + * - ESP_OK : Succeed + * - Other : Failed + */ +esp_err_t esp_bluedroid_disable(void); + +/** + * @brief Init and alloc the resource for bluetooth, must be prior to every bluetooth stuff + * + * @return + * - ESP_OK : Succeed + * - Other : Failed + */ +esp_err_t esp_bluedroid_init(void); + +/** + * @brief Deinit and free the resource for bluetooth, must be after every bluetooth stuff + * + * @return + * - ESP_OK : Succeed + * - Other : Failed + */ +esp_err_t esp_bluedroid_deinit(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __ESP_BT_MAIN_H__ */ diff --git a/tools/sdk/include/bluedroid/esp_gap_ble_api.h b/tools/sdk/include/bluedroid/esp_gap_ble_api.h new file mode 100644 index 00000000..64aff1fb --- /dev/null +++ b/tools/sdk/include/bluedroid/esp_gap_ble_api.h @@ -0,0 +1,496 @@ +// 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 __ESP_GAP_BLE_API_H__ +#define __ESP_GAP_BLE_API_H__ + +#include +#include + +#include "esp_err.h" +#include "esp_bt_defs.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/**@{ + * BLE_ADV_DATA_FLAG data flag bit definition used for advertising data flag + */ +#define ESP_BLE_ADV_FLAG_LIMIT_DISC (0x01 << 0) +#define ESP_BLE_ADV_FLAG_GEN_DISC (0x01 << 1) +#define ESP_BLE_ADV_FLAG_BREDR_NOT_SPT (0x01 << 2) +#define ESP_BLE_ADV_FLAG_DMT_CONTROLLER_SPT (0x01 << 3) +#define ESP_BLE_ADV_FLAG_DMT_HOST_SPT (0x01 << 4) +#define ESP_BLE_ADV_FLAG_NON_LIMIT_DISC (0x00 ) +/** + * @} + */ + +/// GAP BLE callback event type +typedef enum { + ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT = 0, /*!< When advertising data set complete, the event comes */ + ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT, /*!< When scan response data set complete, the event comes */ + ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT, /*!< When scan parameters set complete, the event comes */ + ESP_GAP_BLE_SCAN_RESULT_EVT, /*!< When one scan result ready, the event comes each time */ + ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT, /*!< When raw advertising data set complete, the event comes */ + ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT, /*!< When raw advertising data set complete, the event comes */ +} esp_gap_ble_cb_event_t; + +/// Advertising data maximum length +#define ESP_BLE_ADV_DATA_LEN_MAX 31 +/// Scan response data maximum length +#define ESP_BLE_SCAN_RSP_DATA_LEN_MAX 31 + +/// 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_adv_data_type; + +/// Advertising mode +typedef enum { + ADV_TYPE_IND = 0x00, + ADV_TYPE_DIRECT_IND_HIGH = 0x01, + ADV_TYPE_SCAN_IND = 0x02, + ADV_TYPE_NONCONN_IND = 0x03, + ADV_TYPE_DIRECT_IND_LOW = 0x04, +} esp_ble_adv_type_t; + +/// Advertising channel mask +typedef enum { + ADV_CHNL_37 = 0x01, + ADV_CHNL_38 = 0x02, + ADV_CHNL_39 = 0x04, + ADV_CHNL_ALL = 0x07, +} esp_ble_adv_channel_t; + +typedef enum { + ///Allow both scan and connection requests from anyone + ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY = 0x00, + ///Allow both scan req from White List devices only and connection req from anyone + ADV_FILTER_ALLOW_SCAN_WLST_CON_ANY, + ///Allow both scan req from anyone and connection req from White List devices only + ADV_FILTER_ALLOW_SCAN_ANY_CON_WLST, + ///Allow scan and connection requests from White List devices only + ADV_FILTER_ALLOW_SCAN_WLST_CON_WLST, + ///Enumeration end value for advertising filter policy value check +} esp_ble_adv_filter_t; + +/// Advertising parameters +typedef struct { + uint16_t adv_int_min; /*!< Minimum advertising interval for + undirected and low duty cycle directed advertising. + Range: 0x0020 to 0x4000 Default: N = 0x0800 (1.28 second) + Time = N * 0.625 msec Time Range: 20 ms to 10.24 sec */ + uint16_t adv_int_max; /*!< Maximum advertising interval for + undirected and low duty cycle directed advertising. + Range: 0x0020 to 0x4000 Default: N = 0x0800 (1.28 second) + Time = N * 0.625 msec Time Range: 20 ms to 10.24 sec Advertising max interval */ + esp_ble_adv_type_t adv_type; /*!< Advertising type */ + esp_ble_addr_type_t own_addr_type; /*!< Owner bluetooth device address type */ + esp_bd_addr_t peer_addr; /*!< Peer device bluetooth device address */ + esp_ble_addr_type_t peer_addr_type; /*!< Peer device bluetooth device address type */ + esp_ble_adv_channel_t channel_map; /*!< Advertising channel map */ + esp_ble_adv_filter_t adv_filter_policy; /*!< Advertising filter policy */ +} esp_ble_adv_params_t; + +/// Advertising data content, according to "Supplement to the Bluetooth Core Specification" +typedef struct { + bool set_scan_rsp; /*!< Set this advertising data as scan response or not*/ + bool include_name; /*!< Advertising data include device name or not */ + bool include_txpower; /*!< Advertising data include TX power */ + int min_interval; /*!< Advertising data show advertising min interval */ + int max_interval; /*!< Advertising data show advertising max interval */ + int appearance; /*!< External appearance of device */ + uint16_t manufacturer_len; /*!< Manufacturer data length */ + uint8_t *p_manufacturer_data; /*!< Manufacturer data point */ + uint16_t service_data_len; /*!< Service data length */ + uint8_t *p_service_data; /*!< Service data point */ + uint16_t service_uuid_len; /*!< Service uuid length */ + uint8_t *p_service_uuid; /*!< Service uuid array point */ + uint8_t flag; /*!< Advertising flag of discovery mode, see BLE_ADV_DATA_FLAG detail */ +} esp_ble_adv_data_t; + +/// Own BD address source of the device +typedef enum { + /// Public Address + ESP_PUBLIC_ADDR, + /// Provided random address + ESP_PROVIDED_RND_ADDR, + /// Provided static random address + ESP_GEN_STATIC_RND_ADDR, + /// Generated resolvable private random address + ESP_GEN_RSLV_ADDR, + /// Generated non-resolvable private random address + ESP_GEN_NON_RSLV_ADDR, + /// Provided Reconnection address + ESP_PROVIDED_RECON_ADDR, +} esp_ble_own_addr_src_t; + +/// Ble scan type +typedef enum { + BLE_SCAN_TYPE_PASSIVE = 0x0, /*!< Passive scan */ + BLE_SCAN_TYPE_ACTIVE = 0x1, /*!< Active scan */ +} esp_ble_scan_type_t; + +/// Ble scan filter type +typedef enum { + BLE_SCAN_FILTER_ALLOW_ALL = 0x0, /*!< Accept all : + 1. advertisement packets except directed advertising packets not addressed to this device (default). */ + BLE_SCAN_FILTER_ALLOW_ONLY_WLST = 0x1, /*!< Accept only : + 1. advertisement packets from devices where the advertiser’s address is in the White list. + 2. Directed advertising packets which are not addressed for this device shall be ignored. */ + BLE_SCAN_FILTER_ALLOW_UND_RPA_DIR = 0x2, /*!< Accept all : + 1. undirected advertisement packets, and + 2. directed advertising packets where the initiator address is a resolvable private address, and + 3. directed advertising packets addressed to this device. */ + BLE_SCAN_FILTER_ALLOW_WLIST_PRA_DIR = 0x3, /*!< Accept all : + 1. advertisement packets from devices where the advertiser’s address is in the White list, and + 2. directed advertising packets where the initiator address is a resolvable private address, and + 3. directed advertising packets addressed to this device.*/ +} esp_ble_scan_filter_t; + +/// Ble scan parameters +typedef struct { + esp_ble_scan_type_t scan_type; /*!< Scan type */ + esp_ble_addr_type_t own_addr_type; /*!< Owner address type */ + esp_ble_scan_filter_t scan_filter_policy; /*!< Scan filter policy */ + uint16_t scan_interval; /*!< Scan interval. This is defined as the time interval from + when the Controller started its last LE scan until it begins the subsequent LE scan. + Range: 0x0004 to 0x4000 Default: 0x0010 (10 ms) + Time = N * 0.625 msec + Time Range: 2.5 msec to 10.24 seconds*/ + uint16_t scan_window; /*!< Scan window. The duration of the LE scan. LE_Scan_Window + shall be less than or equal to LE_Scan_Interval + Range: 0x0004 to 0x4000 Default: 0x0010 (10 ms) + Time = N * 0.625 msec + Time Range: 2.5 msec to 10240 msec */ +} esp_ble_scan_params_t; + +/// Connection update parameters +typedef struct { + 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 timeout; /*!< Supervision timeout for the LE Link. Range: 0x000A to 0x0C80. + Mandatory Range: 0x000A to 0x0C80 Time = N * 10 msec + Time Range: 100 msec to 32 seconds */ +} esp_ble_conn_update_params_t; + +/// Sub Event of ESP_GAP_BLE_SCAN_RESULT_EVT +typedef enum { + ESP_GAP_SEARCH_INQ_RES_EVT = 0, /*!< Inquiry result for a peer device. */ + ESP_GAP_SEARCH_INQ_CMPL_EVT = 1, /*!< Inquiry complete. */ + ESP_GAP_SEARCH_DISC_RES_EVT = 2, /*!< Discovery result for a peer device. */ + ESP_GAP_SEARCH_DISC_BLE_RES_EVT = 3, /*!< Discovery result for BLE GATT based service on a peer device. */ + ESP_GAP_SEARCH_DISC_CMPL_EVT = 4, /*!< Discovery complete. */ + ESP_GAP_SEARCH_DI_DISC_CMPL_EVT = 5, /*!< Discovery complete. */ + ESP_GAP_SEARCH_SEARCH_CANCEL_CMPL_EVT = 6, /*!< Search cancelled */ +} esp_gap_search_evt_t; + +/** + * @brief Ble scan result event type, to indicate the + * result is scan response or advertising data or other + */ +typedef enum { + ESP_BLE_EVT_CONN_ADV = 0x00, /*!< Connectable undirected advertising (ADV_IND) */ + ESP_BLE_EVT_CONN_DIR_ADV = 0x01, /*!< Connectable directed advertising (ADV_DIRECT_IND) */ + ESP_BLE_EVT_DISC_ADV = 0x02, /*!< Scannable undirected advertising (ADV_SCAN_IND) */ + ESP_BLE_EVT_NON_CONN_ADV = 0x03, /*!< Non connectable undirected advertising (ADV_NONCONN_IND) */ + ESP_BLE_EVT_SCAN_RSP = 0x04, /*!< Scan Response (SCAN_RSP) */ +} esp_ble_evt_type_t; + +/** + * @brief Gap callback parameters union + */ +typedef union { + /** + * @brief ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT + */ + struct ble_adv_data_cmpl_evt_param { + esp_bt_status_t status; /*!< Indicate the set advertising data operation success status */ + } adv_data_cmpl; /*!< Event parameter of ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT */ + /** + * @brief ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT + */ + struct ble_scan_rsp_data_cmpl_evt_param { + esp_bt_status_t status; /*!< Indicate the set scan response data operation success status */ + } scan_rsp_data_cmpl; /*!< Event parameter of ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT */ + /** + * @brief ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT + */ + struct ble_scan_param_cmpl_evt_param { + esp_bt_status_t status; /*!< Indicate the set scan param operation success status */ + } scan_param_cmpl; /*!< Event parameter of ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT */ + /** + * @brief ESP_GAP_BLE_SCAN_RESULT_EVT + */ + struct ble_scan_result_evt_param { + esp_gap_search_evt_t search_evt; /*!< Search event type */ + esp_bd_addr_t bda; /*!< Bluetooth device address which has been searched */ + esp_bt_dev_type_t dev_type; /*!< Device type */ + esp_ble_addr_type_t ble_addr_type; /*!< Ble device address type */ + esp_ble_evt_type_t ble_evt_type; /*!< Ble scan result event type */ + int rssi; /*!< Searched device's RSSI */ + uint8_t ble_adv[ESP_BLE_ADV_DATA_LEN_MAX + ESP_BLE_SCAN_RSP_DATA_LEN_MAX]; /*!< Received EIR */ + int flag; /*!< Advertising data flag bit */ + int num_resps; /*!< Scan result number */ + } scan_rst; /*!< Event parameter of ESP_GAP_BLE_SCAN_RESULT_EVT */ + /** + * @brief ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT + */ + struct ble_adv_data_raw_cmpl_evt_param { + esp_bt_status_t status; /*!< Indicate the set raw advertising data operation success status */ + } adv_data_raw_cmpl; /*!< Event parameter of ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT */ + /** + * @brief ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT + */ + struct ble_scan_rsp_data_raw_cmpl_evt_param { + esp_bt_status_t status; /*!< Indicate the set raw advertising data operation success status */ + } scan_rsp_data_raw_cmpl; /*!< Event parameter of ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT */ +} esp_ble_gap_cb_param_t; + +/** + * @brief GAP callback function type + * @param event : Event type + * @param param : Point to callback parameter, currently is union type + */ +typedef void (* esp_gap_ble_cb_t)(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param); + +/** + * @brief This function is called to occur gap event, such as scan result + * + * @param[in] callback: callback function + * + * @return + * - ESP_OK : success + * - other : failed + * + */ +esp_err_t esp_ble_gap_register_callback(esp_gap_ble_cb_t callback); + + +/** + * @brief This function is called to override the BTA default ADV parameters. + * + * @param[in] adv_data: Pointer to User defined ADV data structure. This + * memory space can not be freed until callback of config_adv_data + * is received. + * + * @return + * - ESP_OK : success + * - other : failed + * + */ +esp_err_t esp_ble_gap_config_adv_data (esp_ble_adv_data_t *adv_data); + + + +/** + * @brief This function is called to set scan parameters + * + * @param[in] scan_params: Pointer to User defined scan_params data structure. This + * memory space can not be freed until callback of set_scan_params + * + * @return + * - ESP_OK : success + * - other : failed + * + */ +esp_err_t esp_ble_gap_set_scan_params(esp_ble_scan_params_t *scan_params); + + +/** + * @brief This procedure keep the device scanning the peer device which advertising on the air + * + * @param[in] duration: Keeping the scanning time, the unit is second. + * + * @return + * - ESP_OK : success + * - other : failed + * + */ +esp_err_t esp_ble_gap_start_scanning(uint32_t duration); + + +/** + * @brief This function call to stop the device scanning the peer device which advertising on the air + * @return + * - ESP_OK : success + * - other : failed + * + */ +esp_err_t esp_ble_gap_stop_scanning(void); + +/** + * @brief This function is called to start advertising. + * + * @param[in] adv_params: pointer to User defined adv_params data structure. + + * @return + * - ESP_OK : success + * - other : failed + * + */ +esp_err_t esp_ble_gap_start_advertising (esp_ble_adv_params_t *adv_params); + + + +/** + * @brief This function is called to stop advertising. + * + * @return + * - ESP_OK : success + * - other : failed + * + */ +esp_err_t esp_ble_gap_stop_advertising(void); + + + +/** + * @brief Update connection parameters, can only be used when connection is up. + * + * @param[in] params - connection update parameters + * + * @return + * - ESP_OK : success + * - other : failed + * + */ +esp_err_t esp_ble_gap_update_conn_params(esp_ble_conn_update_params_t *params); + + +/** + * @brief This function is to set maximum LE data packet size + * + * @return + * - ESP_OK : success + * - other : failed + * + */ +esp_err_t esp_ble_gap_set_pkt_data_len(esp_bd_addr_t remote_device, uint16_t tx_data_length); + + + +/** + * @brief This function set the random address for the application + * + * @param[in] rand_addr: the random address which should be setting + * + * @return + * - ESP_OK : success + * - other : failed + * + */ +esp_err_t esp_ble_gap_set_rand_addr(esp_bd_addr_t rand_addr); + + + +/** + * @brief Enable/disable privacy on the local device + * + * @param[in] privacy_enable - enable/disable privacy on remote device. + * + * @return + * - ESP_OK : success + * - other : failed + * + */ +esp_err_t esp_ble_gap_config_local_privacy (bool privacy_enable); + + +/** + * @brief Set device name to the local device + * + * @param[in] name - device name. + * + * @return + * - ESP_OK : success + * - other : failed + * + */ +esp_err_t esp_ble_gap_set_device_name(const char *name); + + +/** + * @brief This function is called to get ADV data for a specific type. + * + * @param[in] adv_data - pointer of ADV data which to be resolved + * @param[in] type - finding ADV data type + * @param[out] length - return the length of ADV data not including type + * + * @return - ESP_OK : success + * - other : failed + * + */ +uint8_t *esp_ble_resolve_adv_data(uint8_t *adv_data, uint8_t type, uint8_t *length); + +/** + * @brief This function is called to set raw advertising data. User need to fill + * ADV data by self. + * + * @param[in] raw_data : raw advertising data + * @param[in] raw_data_len : raw advertising data length , less than 31 bytes + * + * @return + * - ESP_OK : success + * - other : failed + * + */ +esp_err_t esp_ble_gap_config_adv_data_raw(uint8_t *raw_data, uint32_t raw_data_len); + +/** + * @brief This function is called to set raw scan response data. User need to fill + * scan response data by self. + * + * @param[in] raw_data : raw scan response data + * @param[in] raw_data_len : raw scan response data length , less than 31 bytes + * + * @return + * - ESP_OK : success + * - other : failed + */ +esp_err_t esp_ble_gap_config_scan_rsp_data_raw(uint8_t *raw_data, uint32_t raw_data_len); + +#ifdef __cplusplus +} +#endif + +#endif /* __ESP_GAP_BLE_API_H__ */ diff --git a/tools/sdk/include/bluedroid/esp_gatt_defs.h b/tools/sdk/include/bluedroid/esp_gatt_defs.h new file mode 100644 index 00000000..153a7027 --- /dev/null +++ b/tools/sdk/include/bluedroid/esp_gatt_defs.h @@ -0,0 +1,384 @@ +// 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 __ESP_GATT_DEFS_H__ +#define __ESP_GATT_DEFS_H__ + +#include "esp_bt_defs.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/// GATT INVALID UUID +#define ESP_GATT_ILLEGAL_UUID 0 +/// GATT INVALID HANDLE +#define ESP_GATT_ILLEGAL_HANDLE 0 +/// GATT attribute max handle +#define ESP_GATT_ATTR_HANDLE_MAX 100 + + +/**@{ + * All "ESP_GATT_UUID_xxx" is attribute types + */ +#define ESP_GATT_UUID_IMMEDIATE_ALERT_SVC 0x1802 /* Immediate alert Service*/ +#define ESP_GATT_UUID_LINK_LOSS_SVC 0x1803 /* Link Loss Service*/ +#define ESP_GATT_UUID_TX_POWER_SVC 0x1804 /* TX Power Service*/ +#define ESP_GATT_UUID_CURRENT_TIME_SVC 0x1805 /* Current Time Service Service*/ +#define ESP_GATT_UUID_REF_TIME_UPDATE_SVC 0x1806 /* Reference Time Update Service*/ +#define ESP_GATT_UUID_NEXT_DST_CHANGE_SVC 0x1807 /* Next DST Change Service*/ +#define ESP_GATT_UUID_GLUCOSE_SVC 0x1808 /* Glucose Service*/ +#define ESP_GATT_UUID_HEALTH_THERMOM_SVC 0x1809 /* Health Thermometer Service*/ +#define ESP_GATT_UUID_DEVICE_INFO_SVC 0x180A /* Device Information Service*/ +#define ESP_GATT_UUID_HEART_RATE_SVC 0x180D /* Heart Rate Service*/ +#define ESP_GATT_UUID_PHONE_ALERT_STATUS_SVC 0x180E /* Phone Alert Status Service*/ +#define ESP_GATT_UUID_BATTERY_SERVICE_SVC 0x180F /* Battery Service*/ +#define ESP_GATT_UUID_BLOOD_PRESSURE_SVC 0x1810 /* Blood Pressure Service*/ +#define ESP_GATT_UUID_ALERT_NTF_SVC 0x1811 /* Alert Notification Service*/ +#define ESP_GATT_UUID_HID_SVC 0x1812 /* HID Service*/ +#define ESP_GATT_UUID_SCAN_PARAMETERS_SVC 0x1813 /* Scan Parameters Service*/ +#define ESP_GATT_UUID_RUNNING_SPEED_CADENCE_SVC 0x1814 /* Running Speed and Cadence Service*/ +#define ESP_GATT_UUID_CYCLING_SPEED_CADENCE_SVC 0x1816 /* Cycling Speed and Cadence Service*/ +#define ESP_GATT_UUID_CYCLING_POWER_SVC 0x1818 /* Cycling Power Service*/ +#define ESP_GATT_UUID_LOCATION_AND_NAVIGATION_SVC 0x1819 /* Location and Navigation Service*/ +#define ESP_GATT_UUID_USER_DATA_SVC 0x181C /* User Data Service*/ +#define ESP_GATT_UUID_WEIGHT_SCALE_SVC 0x181D /* Weight Scale Service*/ + +#define ESP_GATT_UUID_PRI_SERVICE 0x2800 +#define ESP_GATT_UUID_SEC_SERVICE 0x2801 +#define ESP_GATT_UUID_INCLUDE_SERVICE 0x2802 +#define ESP_GATT_UUID_CHAR_DECLARE 0x2803 /* Characteristic Declaration*/ + +#define ESP_GATT_UUID_CHAR_EXT_PROP 0x2900 /* Characteristic Extended Properties */ +#define ESP_GATT_UUID_CHAR_DESCRIPTION 0x2901 /* Characteristic User Description*/ +#define ESP_GATT_UUID_CHAR_CLIENT_CONFIG 0x2902 /* Client Characteristic Configuration */ +#define ESP_GATT_UUID_CHAR_SRVR_CONFIG 0x2903 /* Server Characteristic Configuration */ +#define ESP_GATT_UUID_CHAR_PRESENT_FORMAT 0x2904 /* Characteristic Presentation Format*/ +#define ESP_GATT_UUID_CHAR_AGG_FORMAT 0x2905 /* Characteristic Aggregate Format*/ +#define ESP_GATT_UUID_CHAR_VALID_RANGE 0x2906 /* Characteristic Valid Range */ +#define ESP_GATT_UUID_EXT_RPT_REF_DESCR 0x2907 +#define ESP_GATT_UUID_RPT_REF_DESCR 0x2908 + +/* GAP Profile Attributes */ +#define ESP_GATT_UUID_GAP_DEVICE_NAME 0x2A00 +#define ESP_GATT_UUID_GAP_ICON 0x2A01 +#define ESP_GATT_UUID_GAP_PREF_CONN_PARAM 0x2A04 +#define ESP_GATT_UUID_GAP_CENTRAL_ADDR_RESOL 0x2AA6 + +/* Attribute Profile Attribute UUID */ +#define ESP_GATT_UUID_GATT_SRV_CHGD 0x2A05 + +/* Link ESP_Loss Service */ +#define ESP_GATT_UUID_ALERT_LEVEL 0x2A06 /* Alert Level */ +#define ESP_GATT_UUID_TX_POWER_LEVEL 0x2A07 /* TX power level */ + +/* Current Time Service */ +#define ESP_GATT_UUID_CURRENT_TIME 0x2A2B /* Current Time */ +#define ESP_GATT_UUID_LOCAL_TIME_INFO 0x2A0F /* Local time info */ +#define ESP_GATT_UUID_REF_TIME_INFO 0x2A14 /* reference time information */ + +/* Network availability Profile */ +#define ESP_GATT_UUID_NW_STATUS 0x2A18 /* network availability status */ +#define ESP_GATT_UUID_NW_TRIGGER 0x2A1A /* Network availability trigger */ + +/* Phone alert */ +#define ESP_GATT_UUID_ALERT_STATUS 0x2A3F /* alert status */ +#define ESP_GATT_UUID_RINGER_CP 0x2A40 /* ringer control point */ +#define ESP_GATT_UUID_RINGER_SETTING 0x2A41 /* ringer setting */ + +/* Glucose Service */ +#define ESP_GATT_UUID_GM_MEASUREMENT 0x2A18 +#define ESP_GATT_UUID_GM_CONTEXT 0x2A34 +#define ESP_GATT_UUID_GM_CONTROL_POINT 0x2A52 +#define ESP_GATT_UUID_GM_FEATURE 0x2A51 + +/* device information characteristic */ +#define ESP_GATT_UUID_SYSTEM_ID 0x2A23 +#define ESP_GATT_UUID_MODEL_NUMBER_STR 0x2A24 +#define ESP_GATT_UUID_SERIAL_NUMBER_STR 0x2A25 +#define ESP_GATT_UUID_FW_VERSION_STR 0x2A26 +#define ESP_GATT_UUID_HW_VERSION_STR 0x2A27 +#define ESP_GATT_UUID_SW_VERSION_STR 0x2A28 +#define ESP_GATT_UUID_MANU_NAME 0x2A29 +#define ESP_GATT_UUID_IEEE_DATA 0x2A2A +#define ESP_GATT_UUID_PNP_ID 0x2A50 + +/* HID characteristics */ +#define ESP_GATT_UUID_HID_INFORMATION 0x2A4A +#define ESP_GATT_UUID_HID_REPORT_MAP 0x2A4B +#define ESP_GATT_UUID_HID_CONTROL_POINT 0x2A4C +#define ESP_GATT_UUID_HID_REPORT 0x2A4D +#define ESP_GATT_UUID_HID_PROTO_MODE 0x2A4E +#define ESP_GATT_UUID_HID_BT_KB_INPUT 0x2A22 +#define ESP_GATT_UUID_HID_BT_KB_OUTPUT 0x2A32 +#define ESP_GATT_UUID_HID_BT_MOUSE_INPUT 0x2A33 + + /// Heart Rate Measurement +#define ESP_GATT_HEART_RATE_MEAS 0x2A37 +/// Body Sensor Location +#define ESP_GATT_BODY_SENSOR_LOCATION 0x2A38 +/// Heart Rate Control Point +#define ESP_GATT_HEART_RATE_CNTL_POINT 0x2A39 + +/* Battery Service characteristics */ +#define ESP_GATT_UUID_BATTERY_LEVEL 0x2A19 + +/* Sensor Service */ +#define ESP_GATT_UUID_SC_CONTROL_POINT 0x2A55 +#define ESP_GATT_UUID_SENSOR_LOCATION 0x2A5D + +/* Runners speed and cadence service */ +#define ESP_GATT_UUID_RSC_MEASUREMENT 0x2A53 +#define ESP_GATT_UUID_RSC_FEATURE 0x2A54 + +/* Cycling speed and cadence service */ +#define ESP_GATT_UUID_CSC_MEASUREMENT 0x2A5B +#define ESP_GATT_UUID_CSC_FEATURE 0x2A5C + +/* Scan ESP_Parameter characteristics */ +#define ESP_GATT_UUID_SCAN_INT_WINDOW 0x2A4F +#define ESP_GATT_UUID_SCAN_REFRESH 0x2A31 +/** + * @} + */ + +/// 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_type; + +/** + * @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 */ + + /* 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_status_t; + +/** + * @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_reason_t; + +/** + * @brief Gatt id, include uuid and instance id + */ +typedef struct { + esp_bt_uuid_t uuid; /*!< UUID */ + uint8_t inst_id; /*!< Instance id */ +} __attribute__((packed)) esp_gatt_id_t; + +/** + * @brief Gatt service id, include id + * (uuid and instance id) and primary flag + */ +typedef struct { + esp_gatt_id_t id; /*!< Gatt id, include uuid and instance */ + bool is_primary; /*!< This service is primary or not */ +} __attribute__((packed)) esp_gatt_srvc_id_t; + +/** + * @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_t; + +/** + * @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; + +/* 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; + +/// GATT maximum attribute length +#define ESP_GATT_MAX_ATTR_LEN 600 //as same as GATT_MAX_ATTR_LEN + + +/** + * @brief Attribute description (used to create database) + */ + typedef struct + { + uint16_t uuid_length; /*!< UUID length */ + uint8_t *uuid_p; /*!< UUID value */ + uint16_t perm; /*!< Attribute permission */ + uint16_t max_length; /*!< Maximum length of the element*/ + uint16_t length; /*!< Current length of the element*/ + uint8_t *value; /*!< Element value array*/ + } esp_attr_desc_t; + + +/** + * @brief attribute auto respose flag + */ +typedef struct +{ +#define ESP_GATT_RSP_BY_APP 0 +#define ESP_GATT_AUTO_RSP 1 + uint8_t auto_rsp; /*!< need the app response to the client if need_rsp set to 1*/ +} esp_attr_control_t; + + +/** + * @brief attribute type added to the gatt server database + */ +typedef struct +{ + esp_attr_control_t attr_control; /*!< The attribue control type*/ + esp_attr_desc_t att_desc; /*!< The attribue type*/ +} esp_gatts_attr_db_t; + + +/** + * @brief set the attribute value type + */ +typedef struct +{ + uint16_t attr_max_len; /*!< attribute max value length */ + uint16_t attr_len; /*!< attribute current value length */ + uint8_t *attr_value; /*!< the pointer to attribute value */ +} esp_attr_value_t; + + +/** + * @brief Gatt include service entry element + */ +typedef struct +{ + uint16_t start_hdl; /*!< Gatt start handle value of included service */ + uint16_t end_hdl; /*!< Gatt end handle value of included service */ + uint16_t uuid; /*!< Gatt attribute value UUID of included service */ +} esp_gatts_incl_svc_desc_t; /*!< Gatt include service entry element */ + +/** + * @brief Gatt include 128 bit service entry element + */ +typedef struct +{ + uint16_t start_hdl; /*!< Gatt start handle value of included 128 bit service */ + uint16_t end_hdl; /*!< Gatt end handle value of included 128 bit service */ +} esp_gatts_incl128_svc_desc_t; /*!< Gatt include 128 bit service entry element */ + + + + +/// Gatt attribute value +typedef struct { + uint8_t value[ESP_GATT_MAX_ATTR_LEN]; /*!< Gatt attribute value */ + uint16_t handle; /*!< Gatt attribute handle */ + uint16_t offset; /*!< Gatt attribute value offset */ + uint16_t len; /*!< Gatt attribute value length */ + uint8_t auth_req; /*!< Gatt authentication request */ +} esp_gatt_value_t; + +/// GATT remote read request response type +typedef union { + esp_gatt_value_t attr_value; /*!< Gatt attribute structure */ + uint16_t handle; /*!< Gatt attribute handle */ +} esp_gatt_rsp_t; + +/** + * @brief Gatt write type + */ +typedef enum { + ESP_GATT_WRITE_TYPE_NO_RSP = 1, /*!< Gatt write attribute need no response */ + ESP_GATT_WRITE_TYPE_RSP, /*!< Gatt write attribute need remote response */ +} esp_gatt_write_type_t; + +#define ESP_GATT_IF_NONE 0xff /*!< If callback report gattc_if/gatts_if as this macro, means this event is not correspond to any app */ + +typedef uint8_t esp_gatt_if_t; /*!< Gatt interface type, different application on GATT client use different gatt_if */ + +#ifdef __cplusplus +} +#endif + +#endif /* __ESP_GATT_DEFS_H__ */ diff --git a/tools/sdk/include/bluedroid/esp_gattc_api.h b/tools/sdk/include/bluedroid/esp_gattc_api.h new file mode 100644 index 00000000..b52dabbd --- /dev/null +++ b/tools/sdk/include/bluedroid/esp_gattc_api.h @@ -0,0 +1,607 @@ +// 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 __ESP_GATTC_API_H__ +#define __ESP_GATTC_API_H__ + +#include "esp_bt_defs.h" +#include "esp_gatt_defs.h" +#include "esp_err.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/// 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_cb_event_t; + +/// Maximum Transmission Unit used in GATT +#define ESP_GATT_DEF_BLE_MTU_SIZE 23 + +/// Maximum Transmission Unit allowed in GATT +#define ESP_GATT_MAX_MTU_SIZE 517 + +/** + * @brief Gatt client callback parameters union + */ +typedef union { + /** + * @brief ESP_GATTC_REG_EVT + */ + struct gattc_reg_evt_param { + esp_gatt_status_t status; /*!< Operation status */ + uint16_t app_id; /*!< Application id which input in register API */ + } reg; /*!< Gatt client callback param of ESP_GATTC_REG_EVT */ + + /** + * @brief ESP_GATTC_OPEN_EVT + */ + struct gattc_open_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 */ + uint16_t mtu; /*!< MTU size */ + } open; /*!< Gatt client callback param of ESP_GATTC_OPEN_EVT */ + + /** + * @brief ESP_GATTC_CLOSE_EVT + */ + struct gattc_close_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 */ + esp_gatt_conn_reason_t reason; /*!< The reason of gatt connection close */ + } close; /*!< Gatt client callback param of ESP_GATTC_CLOSE_EVT */ + + /** + * @brief ESP_GATTC_CFG_MTU_EVT + */ + struct gattc_cfg_mtu_evt_param { + esp_gatt_status_t status; /*!< Operation status */ + uint16_t conn_id; /*!< Connection id */ + uint16_t mtu; /*!< MTU size */ + } cfg_mtu; /*!< Gatt client callback param of ESP_GATTC_CFG_MTU_EVT */ + + /** + * @brief ESP_GATTC_SEARCH_CMPL_EVT + */ + struct gattc_search_cmpl_evt_param { + esp_gatt_status_t status; /*!< Operation status */ + uint16_t conn_id; /*!< Connection id */ + } search_cmpl; /*!< Gatt client callback param of ESP_GATTC_SEARCH_CMPL_EVT */ + + /** + * @brief ESP_GATTC_SEARCH_RES_EVT + */ + struct gattc_search_res_evt_param { + uint16_t conn_id; /*!< Connection id */ + esp_gatt_srvc_id_t srvc_id; /*!< Service id, include service uuid and other information */ + } search_res; /*!< Gatt client callback param of ESP_GATTC_SEARCH_RES_EVT */ + + /** + * @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 */ + + /** + * @brief ESP_GATTC_WRITE_CHAR_EVT, ESP_GATTC_PREP_WRITE_EVT, ESP_GATTC_WRITE_DESCR_EVT + */ + struct gattc_write_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 */ + } write; /*!< Gatt client callback param of ESP_GATTC_WRITE_DESCR_EVT */ + + /** + * @brief ESP_GATTC_EXEC_EVT + */ + struct gattc_exec_cmpl_evt_param { + esp_gatt_status_t status; /*!< Operation status */ + uint16_t conn_id; /*!< Connection id */ + } exec_cmpl; /*!< Gatt client callback param of ESP_GATTC_EXEC_EVT */ + + /** + * @brief ESP_GATTC_NOTIFY_EVT + */ + struct gattc_notify_evt_param { + uint16_t conn_id; /*!< Connection id */ + esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */ + 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 */ + uint16_t value_len; /*!< Notify attribute value */ + uint8_t *value; /*!< Notify attribute value */ + bool is_notify; /*!< True means notify, false means indicate */ + } notify; /*!< Gatt client callback param of ESP_GATTC_NOTIFY_EVT */ + + /** + * @brief ESP_GATTC_SRVC_CHG_EVT + */ + struct gattc_srvc_chg_evt_param { + esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */ + } srvc_chg; /*!< Gatt client callback param of ESP_GATTC_SRVC_CHG_EVT */ + + /** + * @brief ESP_GATTC_CONGEST_EVT + */ + struct gattc_congest_evt_param { + uint16_t conn_id; /*!< Connection id */ + bool congested; /*!< Congested or not */ + } congest; /*!< Gatt client callback param of ESP_GATTC_CONGEST_EVT */ + + /** + * @brief ESP_GATTC_GET_CHAR_EVT + */ + struct gattc_get_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_char_prop_t char_prop; /*!< Characteristic property */ + } get_char; /*!< Gatt client callback param of ESP_GATTC_GET_CHAR_EVT */ + + /** + * @brief ESP_GATTC_GET_DESCR_EVT + */ + struct gattc_get_descr_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 */ + } get_descr; /*!< Gatt client callback param of ESP_GATTC_GET_DESCR_EVT */ + + /** + * @brief ESP_GATTC_GET_INCL_SRVC_EVT + */ + struct gattc_get_incl_srvc_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_srvc_id_t incl_srvc_id;/*!< Included service id, include service uuid and other information */ + } get_incl_srvc; /*!< Gatt client callback param of ESP_GATTC_GET_INCL_SRVC_EVT */ + + /** + * @brief ESP_GATTC_REG_FOR_NOTIFY_EVT + */ + struct gattc_reg_for_notify_evt_param { + esp_gatt_status_t status; /*!< Operation status */ + 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 */ + } reg_for_notify; /*!< Gatt client callback param of ESP_GATTC_REG_FOR_NOTIFY_EVT */ + + /** + * @brief ESP_GATTC_UNREG_FOR_NOTIFY_EVT + */ + struct gattc_unreg_for_notify_evt_param { + esp_gatt_status_t status; /*!< Operation status */ + 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 */ + } unreg_for_notify; /*!< Gatt client callback param of ESP_GATTC_UNREG_FOR_NOTIFY_EVT */ + + +} esp_ble_gattc_cb_param_t; /*!< GATT client callback parameter union type */ + +/** + * @brief GATT Client callback function type + * @param event : Event type + * @param gatts_if : GATT client access interface, normally + * different gattc_if correspond to different profile + * @param param : Point to callback parameter, currently is union type + */ +typedef void (* esp_gattc_cb_t)(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param); + +/** + * @brief This function is called to register application callbacks + * with GATTC module. + * + * @param[in] callback : pointer to the application callback function. + * + * @return + * - ESP_OK: success + * - other: failed + * + */ +esp_err_t esp_ble_gattc_register_callback(esp_gattc_cb_t callback); + + +/** + * @brief This function is called to register application callbacks + * with GATTC module. + * + * @param[in] app_id : Application Identify (UUID), for different application + * + * @return + * - ESP_OK: success + * - other: failed + * + */ +esp_err_t esp_ble_gattc_app_register(uint16_t app_id); + + +/** + * @brief This function is called to unregister an application + * from GATTC module. + * + * @param[in] gattc_if: Gatt client access interface. + * + * @return + * - ESP_OK: success + * - other: failed + * + */ +esp_err_t esp_ble_gattc_app_unregister(esp_gatt_if_t gattc_if); + + +/** + * @brief Open a direct connection or add a background auto connection + * + * @param[in] gattc_if: Gatt client access interface. + * @param[in] remote_bda: remote device bluetooth device address. + * @param[in] is_direct: direct connection or background auto connection + * + * @return + * - ESP_OK: success + * - other: failed + * + */ +esp_err_t esp_ble_gattc_open(esp_gatt_if_t gattc_if, esp_bd_addr_t remote_bda, bool is_direct); + + +/** + * @brief Close a connection to a GATT server. + * + * @param[in] gattc_if: Gatt client access interface. + * @param[in] conn_id: connection ID to be closed. + * + * @return + * - ESP_OK: success + * - other: failed + * + */ +esp_err_t esp_ble_gattc_close (esp_gatt_if_t gattc_if, uint16_t conn_id); + + +/** + * @brief Configure the MTU size in the GATT channel. This can be done + * only once per connection. + * + * @param[in] gattc_if: Gatt client access interface. + * @param[in] conn_id: connection ID. + * @param[in] mtu: desired MTU size to use. + * + * @return + * - ESP_OK: success + * - other: failed + * + */ +esp_err_t esp_ble_gattc_config_mtu (esp_gatt_if_t gattc_if, uint16_t conn_id, uint16_t mtu); + + +/** + * @brief This function is called to request a GATT service discovery + * on a GATT server. This function report service search result + * by a callback event, and followed by a service search complete + * event. + * + * @param[in] gattc_if: Gatt client access interface. + * @param[in] conn_id: connection ID. + * @param[in] filter_uuid: a UUID of the service application is interested in. + * If Null, discover for all services. + * + * @return + * - ESP_OK: success + * - other: failed + * + */ +esp_err_t esp_ble_gattc_search_service(esp_gatt_if_t gattc_if, uint16_t conn_id, esp_bt_uuid_t *filter_uuid); + + +/** + * @brief This function is called to find the first characteristic of the + * service on the given server. + * + * @param[in] gattc_if: Gatt client access interface. + * @param[in] conn_id: connection ID which identify the server. + * @param[in] srvc_id: service ID + * @param[in] start_char_id: the start characteristic ID + * @return + * - ESP_OK: success + * - other: failed + * + */ +esp_err_t esp_ble_gattc_get_characteristic(esp_gatt_if_t gattc_if, + uint16_t conn_id, + esp_gatt_srvc_id_t *srvc_id, + esp_gatt_id_t *start_char_id); + +/** + * @brief This function is called to find the descriptor of the + * service on the given server. + * + * @param[in] gattc_if: Gatt client access interface. + * @param[in] conn_id: connection ID which identify the server. + * @param[in] srvc_id: the service ID of which the characteristic is belonged to. + * @param[in] char_id: Characteristic ID, if NULL find the first available + * characteristic. + * @param[in] start_descr_id: the start descriptor id + * + * @return + * - ESP_OK: success + * - other: failed + * + */ +esp_err_t esp_ble_gattc_get_descriptor(esp_gatt_if_t gattc_if, + uint16_t conn_id, + esp_gatt_srvc_id_t *srvc_id, + esp_gatt_id_t *char_id, + esp_gatt_id_t *start_descr_id); + + +/** + * @brief This function is called to find the first characteristic of the + * service on the given server. + * + * @param[in] gattc_if: Gatt client access interface. + * @param[in] conn_id: connection ID which identify the server. + * @param[in] srvc_id: the service ID of which the characteristic is belonged to. + * @param[in] start_incl_srvc_id: the start include service id + * + * @return + * - ESP_OK: success + * - other: failed + * + */ +esp_err_t esp_ble_gattc_get_included_service(esp_gatt_if_t gattc_if, + uint16_t conn_id, + esp_gatt_srvc_id_t *srvc_id, + esp_gatt_srvc_id_t *start_incl_srvc_id); + + +/** + * @brief This function is called to read a service's characteristics of + * the given characteristic ID + * + * @param[in] gattc_if: Gatt client access interface. + * @param[in] conn_id : connection ID. + * @param[in] srvc_id : service ID. + * @param[in] char_id : characteristic ID to read. + * @param[in] auth_req : authenticate request type + * + * @return + * - ESP_OK: success + * - other: failed + * + */ +esp_err_t esp_ble_gattc_read_char (esp_gatt_if_t gattc_if, + uint16_t conn_id, + esp_gatt_srvc_id_t *srvc_id, + esp_gatt_id_t *char_id, + esp_gatt_auth_req_t auth_req); + + +/** + * @brief This function is called to read a characteristics descriptor. + * + * @param[in] gattc_if: Gatt client access interface. + * @param[in] conn_id : connection ID. + * @param[in] srvc_id : service ID. + * @param[in] char_id : characteristic ID to read. + * @param[in] descr_id : characteristic descriptor ID to read. + * @param[in] auth_req : authenticate request type + * + * @return + * - ESP_OK: success + * - other: failed + * + */ +esp_err_t esp_ble_gattc_read_char_descr (esp_gatt_if_t gattc_if, + uint16_t conn_id, + esp_gatt_srvc_id_t *srvc_id, + esp_gatt_id_t *char_id, + esp_gatt_id_t *descr_id, + esp_gatt_auth_req_t auth_req); + + +/** + * @brief This function is called to write characteristic value. + * + * @param[in] gattc_if: Gatt client access interface. + * @param[in] conn_id : connection ID. + * @param[in] srvc_id : service ID. + * @param[in] char_id : characteristic ID to write. + * @param[in] value_len: length of the value to be written. + * @param[in] value : the value to be written. + * @param[in] write_type : the type of attribute write operation. + * @param[in] auth_req : authentication request. + * + * @return + * - ESP_OK: success + * - other: failed + * + */ +esp_err_t esp_ble_gattc_write_char( esp_gatt_if_t gattc_if, + uint16_t conn_id, + esp_gatt_srvc_id_t *srvc_id, + esp_gatt_id_t *char_id, + uint16_t value_len, + uint8_t *value, + esp_gatt_write_type_t write_type, + esp_gatt_auth_req_t auth_req); + + +/** + * @brief This function is called to write characteristic descriptor value. + * + * @param[in] gattc_if: Gatt client access interface. + * @param[in] conn_id : connection ID + * @param[in] srvc_id : service ID. + * @param[in] char_id : characteristic ID. + * @param[in] descr_id : characteristic descriptor ID to write. + * @param[in] value_len: length of the value to be written. + * @param[in] value : the value to be written. + * @param[in] write_type : the type of attribute write operation. + * @param[in] auth_req : authentication request. + * + * @return + * - ESP_OK: success + * - other: failed + * + */ +esp_err_t esp_ble_gattc_write_char_descr (esp_gatt_if_t gattc_if, + uint16_t conn_id, + esp_gatt_srvc_id_t *srvc_id, + esp_gatt_id_t *char_id, + esp_gatt_id_t *descr_id, + uint16_t value_len, + uint8_t *value, + esp_gatt_write_type_t write_type, + esp_gatt_auth_req_t auth_req); + + +/** + * @brief This function is called to prepare write a characteristic value. + * + * @param[in] gattc_if: Gatt client access interface. + * @param[in] conn_id : connection ID. + * @param[in] srvc_id : service ID. + * @param[in] char_id : GATT characteristic ID of the service. + * @param[in] offset : offset of the write value. + * @param[in] value_len: length of the value to be written. + * @param[in] value : the value to be written. + * @param[in] auth_req : authentication request. + * + * @return + * - ESP_OK: success + * - other: failed + * + */ +esp_err_t esp_ble_gattc_prepare_write(esp_gatt_if_t gattc_if, + uint16_t conn_id, + esp_gatt_srvc_id_t *srvc_id, + esp_gatt_id_t *char_id, + uint16_t offset, + uint16_t value_len, + uint8_t *value, + esp_gatt_auth_req_t auth_req); + + +/** + * @brief This function is called to execute write a prepare write sequence. + * + * @param[in] gattc_if: Gatt client access interface. + * @param[in] conn_id : connection ID. + * @param[in] is_execute : execute or cancel. + * + * @return + * - ESP_OK: success + * - other: failed + * + */ +esp_err_t esp_ble_gattc_execute_write (esp_gatt_if_t gattc_if, uint16_t conn_id, bool is_execute); + + +/** + * @brief This function is called to register for notification of a service. + * + * @param[in] gattc_if: Gatt client access interface. + * @param[in] server_bda : target GATT server. + * @param[in] srvc_id : pointer to GATT service ID. + * @param[in] char_id : pointer to GATT characteristic ID. + * + * @return + * - ESP_OK: registration succeeds + * - other: failed + * + */ +esp_gatt_status_t esp_ble_gattc_register_for_notify (esp_gatt_if_t gattc_if, + esp_bd_addr_t server_bda, + esp_gatt_srvc_id_t *srvc_id, + esp_gatt_id_t *char_id); + + +/** + * @brief This function is called to de-register for notification of a service. + * + * @param[in] gattc_if: Gatt client access interface. + * @param[in] server_bda : target GATT server. + * @param[in] srvc_id : pointer to GATT service ID. + * @param[in] char_id : pointer to GATT characteristic ID. + * + * @return + * - ESP_OK: unregister succeeds + * - other: failed + * + */ +esp_gatt_status_t esp_ble_gattc_unregister_for_notify (esp_gatt_if_t gattc_if, + esp_bd_addr_t server_bda, + esp_gatt_srvc_id_t *srvc_id, + esp_gatt_id_t *char_id); + +#ifdef __cplusplus +} +#endif + +#endif /* __ESP_GATTC_API_H__ */ diff --git a/tools/sdk/include/bluedroid/esp_gatts_api.h b/tools/sdk/include/bluedroid/esp_gatts_api.h new file mode 100644 index 00000000..777bbec3 --- /dev/null +++ b/tools/sdk/include/bluedroid/esp_gatts_api.h @@ -0,0 +1,542 @@ +// 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 __ESP_GATTS_API_H__ +#define __ESP_GATTS_API_H__ + +#include "esp_bt_defs.h" +#include "esp_gatt_defs.h" +#include "esp_err.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/// GATT Server callback function events +typedef enum { + ESP_GATTS_REG_EVT = 0, /*!< When register application id, the event comes */ + ESP_GATTS_READ_EVT = 1, /*!< When gatt client request read operation, the event comes */ + ESP_GATTS_WRITE_EVT = 2, /*!< When gatt client request write operation, the event comes */ + ESP_GATTS_EXEC_WRITE_EVT = 3, /*!< When gatt client request execute write, the event comes */ + ESP_GATTS_MTU_EVT = 4, /*!< When set mtu complete, the event comes */ + ESP_GATTS_CONF_EVT = 5, /*!< When receive confirm, the event comes */ + ESP_GATTS_UNREG_EVT = 6, /*!< When unregister application id, the event comes */ + ESP_GATTS_CREATE_EVT = 7, /*!< When create service complete, the event comes */ + ESP_GATTS_ADD_INCL_SRVC_EVT = 8, /*!< When add included service complete, the event comes */ + ESP_GATTS_ADD_CHAR_EVT = 9, /*!< When add characteristic complete, the event comes */ + ESP_GATTS_ADD_CHAR_DESCR_EVT = 10, /*!< When add descriptor complete, the event comes */ + ESP_GATTS_DELETE_EVT = 11, /*!< When delete service complete, the event comes */ + ESP_GATTS_START_EVT = 12, /*!< When start service complete, the event comes */ + ESP_GATTS_STOP_EVT = 13, /*!< When stop service complete, the event comes */ + ESP_GATTS_CONNECT_EVT = 14, /*!< When gatt client connect, the event comes */ + ESP_GATTS_DISCONNECT_EVT = 15, /*!< When gatt client disconnect, the event comes */ + ESP_GATTS_OPEN_EVT = 16, /*!< When connect to peer, the event comes */ + ESP_GATTS_CANCEL_OPEN_EVT = 17, /*!< When disconnect from peer, the event comes */ + ESP_GATTS_CLOSE_EVT = 18, /*!< When gatt server close, the event comes */ + ESP_GATTS_LISTEN_EVT = 19, /*!< When gatt listen to be connected the event comes */ + ESP_GATTS_CONGEST_EVT = 20, /*!< When congest happen, the event comes */ + /* following is extra event */ + ESP_GATTS_RESPONSE_EVT = 21, /*!< When gatt send response complete, the event comes */ + ESP_GATTS_CREAT_ATTR_TAB_EVT = 22, + ESP_GATTS_SET_ATTR_VAL_EVT = 23, +} esp_gatts_cb_event_t; + +/** + * @brief Gatt server callback parameters union + */ +typedef union { + /** + * @brief ESP_GATTS_REG_EVT + */ + struct gatts_reg_evt_param { + esp_gatt_status_t status; /*!< Operation status */ + uint16_t app_id; /*!< Application id which input in register API */ + } reg; /*!< Gatt server callback param of ESP_GATTS_REG_EVT */ + + /** + * @brief ESP_GATTS_READ_EVT + */ + struct gatts_read_evt_param { + uint16_t conn_id; /*!< Connection id */ + uint32_t trans_id; /*!< Transfer id */ + esp_bd_addr_t bda; /*!< The bluetooth device address which been read */ + uint16_t handle; /*!< The attribute handle */ + uint16_t offset; /*!< Offset of the value, if the value is too long */ + bool is_long; /*!< The value is too long or not */ + bool need_rsp; /*!< The read operation need to do response */ + } read; /*!< Gatt server callback param of ESP_GATTS_READ_EVT */ + + + /** + * @brief ESP_GATTS_WRITE_EVT + */ + struct gatts_write_evt_param { + uint16_t conn_id; /*!< Connection id */ + uint32_t trans_id; /*!< Transfer id */ + esp_bd_addr_t bda; /*!< The bluetooth device address which been written */ + uint16_t handle; /*!< The attribute handle */ + uint16_t offset; /*!< Offset of the value, if the value is too long */ + bool need_rsp; /*!< The write operation need to do response */ + bool is_prep; /*!< This write operation is prepare write */ + uint16_t len; /*!< The write attribute value length */ + uint8_t *value; /*!< The write attribute value */ + } write; /*!< Gatt server callback param of ESP_GATTS_WRITE_EVT */ + + /** + * @brief ESP_GATTS_EXEC_WRITE_EVT + */ + struct gatts_exec_write_evt_param { + uint16_t conn_id; /*!< Connection id */ + uint32_t trans_id; /*!< Transfer id */ + esp_bd_addr_t bda; /*!< The bluetooth device address which been written */ +#define ESP_GATT_PREP_WRITE_CANCEL 0x00 /*!< Prepare write flag to indicate cancel prepare write */ +#define ESP_GATT_PREP_WRITE_EXEC 0x01 /*!< Prepare write flag to indicate execute prepare write */ + uint8_t exec_write_flag; /*!< Execute write flag */ + } exec_write; /*!< Gatt server callback param of ESP_GATTS_EXEC_WRITE_EVT */ + + /** + * @brief ESP_GATTS_MTU_EVT + */ + struct gatts_mtu_evt_param { + uint16_t conn_id; /*!< Connection id */ + uint16_t mtu; /*!< MTU size */ + } mtu; /*!< Gatt server callback param of ESP_GATTS_MTU_EVT */ + + /** + * @brief ESP_GATTS_CONF_EVT + */ + struct gatts_conf_evt_param { + esp_gatt_status_t status; /*!< Operation status */ + uint16_t conn_id; /*!< Connection id */ + } conf; /*!< Gatt server callback param of ESP_GATTS_CONF_EVT (confirm) */ + + /** + * @brief ESP_GATTS_UNREG_EVT + */ + + /** + * @brief ESP_GATTS_CREATE_EVT + */ + struct gatts_create_evt_param { + esp_gatt_status_t status; /*!< Operation status */ + uint16_t service_handle; /*!< Service attribute handle */ + esp_gatt_srvc_id_t service_id; /*!< Service id, include service uuid and other information */ + } create; /*!< Gatt server callback param of ESP_GATTS_CREATE_EVT */ + + /** + * @brief ESP_GATTS_ADD_INCL_SRVC_EVT + */ + struct gatts_add_incl_srvc_evt_param { + esp_gatt_status_t status; /*!< Operation status */ + uint16_t attr_handle; /*!< Included service attribute handle */ + uint16_t service_handle; /*!< Service attribute handle */ + } add_incl_srvc; /*!< Gatt server callback param of ESP_GATTS_ADD_INCL_SRVC_EVT */ + + /** + * @brief ESP_GATTS_ADD_CHAR_EVT + */ + struct gatts_add_char_evt_param { + esp_gatt_status_t status; /*!< Operation status */ + uint16_t attr_handle; /*!< Characteristic attribute handle */ + uint16_t service_handle; /*!< Service attribute handle */ + esp_bt_uuid_t char_uuid; /*!< Characteristic uuid */ + } add_char; /*!< Gatt server callback param of ESP_GATTS_ADD_CHAR_EVT */ + + /** + * @brief ESP_GATTS_ADD_CHAR_DESCR_EVT + */ + struct gatts_add_char_descr_evt_param { + esp_gatt_status_t status; /*!< Operation status */ + uint16_t attr_handle; /*!< Descriptor attribute handle */ + uint16_t service_handle; /*!< Service attribute handle */ + esp_bt_uuid_t char_uuid; /*!< Characteristic uuid */ + } add_char_descr; /*!< Gatt server callback param of ESP_GATTS_ADD_CHAR_DESCR_EVT */ + + /** + * @brief ESP_GATTS_DELETE_EVT + */ + struct gatts_delete_evt_param { + esp_gatt_status_t status; /*!< Operation status */ + uint16_t service_handle; /*!< Service attribute handle */ + } del; /*!< Gatt server callback param of ESP_GATTS_DELETE_EVT */ + + /** + * @brief ESP_GATTS_START_EVT + */ + struct gatts_start_evt_param { + esp_gatt_status_t status; /*!< Operation status */ + uint16_t service_handle; /*!< Service attribute handle */ + } start; /*!< Gatt server callback param of ESP_GATTS_START_EVT */ + + /** + * @brief ESP_GATTS_STOP_EVT + */ + struct gatts_stop_evt_param { + esp_gatt_status_t status; /*!< Operation status */ + uint16_t service_handle; /*!< Service attribute handle */ + } stop; /*!< Gatt server callback param of ESP_GATTS_STOP_EVT */ + + /** + * @brief ESP_GATTS_CONNECT_EVT + */ + struct gatts_connect_evt_param { + uint16_t conn_id; /*!< Connection id */ + esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */ + bool is_connected; /*!< Indicate it is connected or not */ + } connect; /*!< Gatt server callback param of ESP_GATTS_CONNECT_EVT */ + + /** + * @brief ESP_GATTS_DISCONNECT_EVT + */ + struct gatts_disconnect_evt_param { + uint16_t conn_id; /*!< Connection id */ + esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */ + bool is_connected; /*!< Indicate it is connected or not */ + } disconnect; /*!< Gatt server callback param of ESP_GATTS_DISCONNECT_EVT */ + + /** + * @brief ESP_GATTS_OPEN_EVT + */ + /** + * @brief ESP_GATTS_CANCEL_OPEN_EVT + */ + /** + * @brief ESP_GATTS_CLOSE_EVT + */ + /** + * @brief ESP_GATTS_LISTEN_EVT + */ + /** + * @brief ESP_GATTS_CONGEST_EVT + */ + struct gatts_congest_evt_param { + uint16_t conn_id; /*!< Connection id */ + bool congested; /*!< Congested or not */ + } congest; /*!< Gatt server callback param of ESP_GATTS_CONGEST_EVT */ + + /** + * @brief ESP_GATTS_RESPONSE_EVT + */ + struct gatts_rsp_evt_param { + esp_gatt_status_t status; /*!< Operation status */ + uint16_t handle; /*!< Attribute handle which send response */ + } rsp; /*!< Gatt server callback param of ESP_GATTS_RESPONSE_EVT */ + + /** + * @brief ESP_GATTS_CREAT_ATTR_TAB_EVT + */ + struct gatts_add_attr_tab_evt_param{ + esp_gatt_status_t status; /*!< Operation status */ + esp_bt_uuid_t svc_uuid; /*!< Service uuid type */ + uint16_t num_handle; /*!< The number of the attribute handle to be added to the gatts database */ + uint16_t *handles; /*!< The number to the handles */ + } add_attr_tab; /*!< Gatt server callback param of ESP_GATTS_CREAT_ATTR_TAB_EVT */ + + + /** + * @brief ESP_GATTS_SET_ATTR_VAL_EVT + */ + struct gatts_set_attr_val_evt_param{ + uint16_t srvc_handle; /*!< The service handle */ + uint16_t attr_handle; /*!< The attribute handle */ + esp_gatt_status_t status; /*!< Operation status*/ + } set_attr_val; /*!< Gatt server callback param of ESP_GATTS_SET_ATTR_VAL_EVT */ + +} esp_ble_gatts_cb_param_t; + +/** + * @brief GATT Server callback function type + * @param event : Event type + * @param gatts_if : GATT server access interface, normally + * different gatts_if correspond to different profile + * @param param : Point to callback parameter, currently is union type + */ +typedef void (* esp_gatts_cb_t)(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param); + +/** + * @brief This function is called to register application callbacks + * with BTA GATTS module. + * + * @return + * - ESP_OK : success + * - other : failed + * + */ +esp_err_t esp_ble_gatts_register_callback(esp_gatts_cb_t callback); + +/** + * @brief This function is called to register application identifier + * + * @return + * - ESP_OK : success + * - other : failed + * + */ +esp_err_t esp_ble_gatts_app_register(uint16_t app_id); + + + +/** + * @brief unregister with GATT Server. + * + * @param[in] gatts_if: GATT server access interface + * @return + * - ESP_OK : success + * - other : failed + * + */ +esp_err_t esp_ble_gatts_app_unregister(esp_gatt_if_t gatts_if); + + +/** + * @brief Create a service. When service creation is done, a callback + * event BTA_GATTS_CREATE_SRVC_EVT is called to report status + * and service ID to the profile. The service ID obtained in + * the callback function needs to be used when adding included + * service and characteristics/descriptors into the service. + * + * @param[in] gatts_if: GATT server access interface + * @param[in] service_id: service ID. + * @param[in] num_handle: number of handle requested for this service. + * + * @return + * - ESP_OK : success + * - other : failed + * + */ +esp_err_t esp_ble_gatts_create_service(esp_gatt_if_t gatts_if, + esp_gatt_srvc_id_t *service_id, uint16_t num_handle); + + +/** + * @brief Create a service attribute tab. + * @param[in] gatts_attr_db: the pointer to the service attr tab + * @param[in] gatts_if: GATT server access interface + * @param[in] max_nb_attr: the number of attribute to be added to the service database. + * @param[in] srvc_inst_id: the instance id of the service + * + * @return + * - ESP_OK : success + * - other : failed + * + */ +esp_err_t esp_ble_gatts_create_attr_tab(const esp_gatts_attr_db_t *gatts_attr_db, + esp_gatt_if_t gatts_if, + uint8_t max_nb_attr, + uint8_t srvc_inst_id); +/** + * @brief This function is called to add an included service. After included + * service is included, a callback event BTA_GATTS_ADD_INCL_SRVC_EVT + * is reported the included service ID. + * + * @param[in] service_handle: service handle to which this included service is to + * be added. + * @param[in] included_service_handle: the service ID to be included. + * + * @return + * - ESP_OK : success + * - other : failed + * + */ +esp_err_t esp_ble_gatts_add_included_service(uint16_t service_handle, uint16_t included_service_handle); + + + +/** + * @brief This function is called to add a characteristic into a service. + * + * @param[in] service_handle: service handle to which this included service is to + * be added. + * @param[in] char_uuid : Characteristic UUID. + * @param[in] perm : Characteristic value declaration attribute permission. + * @param[in] property : Characteristic Properties + * @param[in] char_val : Characteristic value + * @param[in] control : attribute response control byte + * + * @return + * - ESP_OK : success + * - other : failed + * + */ +esp_err_t esp_ble_gatts_add_char(uint16_t service_handle, esp_bt_uuid_t *char_uuid, + esp_gatt_perm_t perm, esp_gatt_char_prop_t property, esp_attr_value_t *char_val, + esp_attr_control_t *control); + + +/** + * @brief This function is called to add characteristic descriptor. When + * it's done, a callback event BTA_GATTS_ADD_DESCR_EVT is called + * to report the status and an ID number for this descriptor. + * + * @param[in] service_handle: service handle to which this characteristic descriptor is to + * be added. + * @param[in] perm: descriptor access permission. + * @param[in] descr_uuid: descriptor UUID. + * @param[in] char_descr_val : Characteristic descriptor value + * @param[in] control : attribute response control byte + * @return + * - ESP_OK : success + * - other : failed + * + */ +esp_err_t esp_ble_gatts_add_char_descr (uint16_t service_handle, + esp_bt_uuid_t *descr_uuid, + esp_gatt_perm_t perm, esp_attr_value_t *char_descr_val, + esp_attr_control_t *control); + + + +/** + * @brief This function is called to delete a service. When this is done, + * a callback event BTA_GATTS_DELETE_EVT is report with the status. + * + * @param[in] service_handle: service_handle to be deleted. + * + * @return + * - ESP_OK : success + * - other : failed + * + */ +esp_err_t esp_ble_gatts_delete_service(uint16_t service_handle); + + + +/** + * @brief This function is called to start a service. + * + * @param[in] service_handle: the service handle to be started. + * + * @return + * - ESP_OK : success + * - other : failed + * + */ +esp_err_t esp_ble_gatts_start_service(uint16_t service_handle); + + + +/** + * @brief This function is called to stop a service. + * + * @param[in] service_handle - service to be topped. + * + * @return + * - ESP_OK : success + * - other : failed + * + */ +esp_err_t esp_ble_gatts_stop_service(uint16_t service_handle); + + + +/** + * @brief Send indicate or notify to GATT client. + * Set param need_confirm as false will send notification, otherwise indication. + * + * @param[in] gatts_if: GATT server access interface + * @param[in] conn_id - connection id to indicate. + * @param[in] attr_handle - attribute handle to indicate. + * @param[in] value_len - indicate value length. + * @param[in] value: value to indicate. + * @param[in] need_confirm - Whether a confirmation is required. + * false sends a GATT notification, true sends a GATT indication. + * + * @return + * - ESP_OK : success + * - other : failed + * + */ +esp_err_t esp_ble_gatts_send_indicate(esp_gatt_if_t gatts_if, uint16_t conn_id, uint16_t attr_handle, + uint16_t value_len, uint8_t *value, bool need_confirm); + + +/** + * @brief This function is called to send a response to a request. + * + * @param[in] gatts_if: GATT server access interface + * @param[in] conn_id - connection identifier. + * @param[in] trans_id - transfer id + * @param[in] status - response status + * @param[in] rsp - response data. + * + * @return + * - ESP_OK : success + * - other : failed + * + */ +esp_err_t esp_ble_gatts_send_response(esp_gatt_if_t gatts_if, uint16_t conn_id, uint32_t trans_id, + esp_gatt_status_t status, esp_gatt_rsp_t *rsp); + + +/** + * @brief This function is called to set the attribute value by the application + * + * @param[in] attr_handle: the attribute handle which to be set + * @param[in] length: the value length + * @param[in] value: the pointer to the attribute value + * + * @return + * - ESP_OK : success + * - other : failed + * + */ +esp_err_t esp_ble_gatts_set_attr_value(uint16_t attr_handle, uint16_t length, const uint8_t *value); + +/** + * @brief Retrieve attribute value + * + * @param[in] attr_handle: Attribute handle. + * @param[out] length: pointer to the attribute value length + * @param[out] value: Pointer to attribute value payload, the value cannot be modified by user + * + * @return + * - ESP_OK : success + * - other : failed + * + */ +esp_err_t esp_ble_gatts_get_attr_value(uint16_t attr_handle, uint16_t *length, const uint8_t **value); + + +/** + * @brief Open a direct open connection or add a background auto connection + * + * @param[in] gatts_if: GATT server access interface + * @param[in] remote_bda: remote device bluetooth device address. + * @param[in] is_direct: direct connection or background auto connection + * + * @return + * - ESP_OK : success + * - other : failed + * + */ +esp_err_t esp_ble_gatts_open(esp_gatt_if_t gatts_if, esp_bd_addr_t remote_bda, bool is_direct); + +/** + * @brief Close a connection a remote device. + * + * @param[in] gatts_if: GATT server access interface + * @param[in] conn_id: connection ID to be closed. + * + * @return + * - ESP_OK : success + * - other : failed + * + */ +esp_err_t esp_ble_gatts_close(esp_gatt_if_t gatts_if, uint16_t conn_id); + +#ifdef __cplusplus +} +#endif + +#endif /* __ESP_GATTS_API_H__ */ diff --git a/tools/sdk/include/bluedroid/event_mask.h b/tools/sdk/include/bluedroid/event_mask.h new file mode 100644 index 00000000..d4d036d5 --- /dev/null +++ b/tools/sdk/include/bluedroid/event_mask.h @@ -0,0 +1,30 @@ +/****************************************************************************** + * + * 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 _EVENT_MASK_H_ +#define _EVENT_MASK_H_ + +#include + +// Represents a mask which can be used to tell the controller which +// HCI events the stack wishes to be informed about. See the bluetooth +// spec for more information on what each bit means. +typedef struct { + uint8_t as_array[8]; +} bt_event_mask_t; + +#endif /*_EVENT_MASK_H_*/ diff --git a/tools/sdk/include/bluedroid/fixed_queue.h b/tools/sdk/include/bluedroid/fixed_queue.h new file mode 100755 index 00000000..9cbb846d --- /dev/null +++ b/tools/sdk/include/bluedroid/fixed_queue.h @@ -0,0 +1,102 @@ +/****************************************************************************** + * + * 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 _FIXED_QUEUE_H_ +#define _FIXED_QUEUE_H_ + +#include + +struct fixed_queue_t; +typedef struct fixed_queue_t fixed_queue_t; +//typedef struct reactor_t reactor_t; + +typedef void (*fixed_queue_free_cb)(void *data); +typedef void (*fixed_queue_cb)(fixed_queue_t *queue); + +// Creates a new fixed queue with the given |capacity|. If more elements than +// |capacity| are added to the queue, the caller is blocked until space is +// made available in the queue. Returns NULL on failure. The caller must free +// the returned queue with |fixed_queue_free|. +fixed_queue_t *fixed_queue_new(size_t capacity); + +// Freeing a queue that is currently in use (i.e. has waiters +// blocked on it) results in undefined behaviour. +void fixed_queue_free(fixed_queue_t *queue, fixed_queue_free_cb free_cb); + +// Returns a value indicating whether the given |queue| is empty. |queue| may +// not be NULL. +bool fixed_queue_is_empty(fixed_queue_t *queue); + +// Returns the maximum number of elements this queue may hold. |queue| may +// not be NULL. +size_t fixed_queue_capacity(fixed_queue_t *queue); + +// Enqueues the given |data| into the |queue|. The caller will be blocked +// if nore more space is available in the queue. Neither |queue| nor |data| +// may be NULL. +void fixed_queue_enqueue(fixed_queue_t *queue, void *data); + +// Dequeues the next element from |queue|. If the queue is currently empty, +// this function will block the caller until an item is enqueued. This +// function will never return NULL. |queue| may not be NULL. +void *fixed_queue_dequeue(fixed_queue_t *queue); + +// Tries to enqueue |data| into the |queue|. This function will never block +// the caller. If the queue capacity would be exceeded by adding one more +// element, this function returns false immediately. Otherwise, this function +// returns true. Neither |queue| nor |data| may be NULL. +bool fixed_queue_try_enqueue(fixed_queue_t *queue, void *data); + +// Tries to dequeue an element from |queue|. This function will never block +// the caller. If the queue is empty, this function returns NULL immediately. +// Otherwise, the next element in the queue is returned. |queue| may not be +// NULL. +//void *fixed_queue_try_dequeue(fixed_queue_t *queue); + +// Returns the first element from |queue|, if present, without dequeuing it. +// This function will never block the caller. Returns NULL if there are no elements +// in the queue. |queue| may not be NULL. +//void *fixed_queue_try_peek(fixed_queue_t *queue); + +// This function returns a valid file descriptor. Callers may perform one +// operation on the fd: select(2). If |select| indicates that the file +// descriptor is readable, the caller may call |fixed_queue_enqueue| without +// blocking. The caller must not close the returned file descriptor. |queue| +// may not be NULL. +//int fixed_queue_get_enqueue_fd(const fixed_queue_t *queue); + +// This function returns a valid file descriptor. Callers may perform one +// operation on the fd: select(2). If |select| indicates that the file +// descriptor is readable, the caller may call |fixed_queue_dequeue| without +// blocking. The caller must not close the returned file descriptor. |queue| +// may not be NULL. +//int fixed_queue_get_dequeue_fd(const fixed_queue_t *queue); + +// Registers |queue| with |reactor| for dequeue operations. When there is an element +// in the queue, ready_cb will be called. The |context| parameter is passed, untouched, +// to the callback routine. Neither |queue|, nor |reactor|, nor |read_cb| may be NULL. +// |context| may be NULL. +void fixed_queue_register_dequeue(fixed_queue_t *queue, fixed_queue_cb ready_cb); + +// Unregisters the dequeue ready callback for |queue| from whichever reactor +// it is registered with, if any. This function is idempotent. +void fixed_queue_unregister_dequeue(fixed_queue_t *queue); + +void fixed_queue_process(fixed_queue_t *queue); + +#endif diff --git a/tools/sdk/include/bluedroid/future.h b/tools/sdk/include/bluedroid/future.h new file mode 100644 index 00000000..d54f2378 --- /dev/null +++ b/tools/sdk/include/bluedroid/future.h @@ -0,0 +1,52 @@ +/****************************************************************************** + * + * 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 __FUTURE_H__ +#define __FUTURE_H__ +// #pragma once + +#include "osi_arch.h" + +struct future { + bool ready_can_be_called; + osi_sem_t semaphore; // NULL semaphore means immediate future + void *result; +}; +typedef struct future future_t; + +#define FUTURE_SUCCESS ((void *)1) +#define FUTURE_FAIL ((void *)0) + +// Constructs a new future_t object. Returns NULL on failure. +future_t *future_new(void); + +// Constructs a new future_t object with an immediate |value|. No waiting will +// occur in the call to |future_await| because the value is already present. +// Returns NULL on failure. +future_t *future_new_immediate(void *value); + +// Signals that the |future| is ready, passing |value| back to the context +// waiting for the result. Must only be called once for every future. +// |future| may not be NULL. +void future_ready(future_t *future, void *value); + +// Waits for the |future| to be ready. Returns the value set in |future_ready|. +// Frees the future before return. |future| may not be NULL. +void *future_await(future_t *async_result); + +#endif /* __FUTURE_H__ */ diff --git a/tools/sdk/include/bluedroid/gap_api.h b/tools/sdk/include/bluedroid/gap_api.h new file mode 100644 index 00000000..1f22db00 --- /dev/null +++ b/tools/sdk/include/bluedroid/gap_api.h @@ -0,0 +1,391 @@ +/****************************************************************************** + * + * Copyright (C) 2009-2013 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. + * + ******************************************************************************/ + +#ifndef GAP_API_H +#define GAP_API_H + +#include "sdpdefs.h" +#include "profiles_api.h" +#include "btm_api.h" +#include "l2c_api.h" + +/***************************************************************************** +** Constants +*****************************************************************************/ +/*** GAP Error and Status Codes ***/ +#define GAP_UNSUPPORTED (GAP_ERR_GRP + 0x01) /* Unsupported call */ +#define GAP_EOINQDB (GAP_ERR_GRP + 0x02) /* End of inquiry database marker */ +#define GAP_ERR_BUSY (GAP_ERR_GRP + 0x03) /* The requested function was busy */ +#define GAP_ERR_NO_CTRL_BLK (GAP_ERR_GRP + 0x04) /* No control blocks available */ +#define GAP_ERR_STARTING_CMD (GAP_ERR_GRP + 0x05) /* Error occurred while initiating the command */ +#define GAP_NO_BDADDR_REC (GAP_ERR_GRP + 0x06) /* No Inquiry DB record for BD_ADDR */ +#define GAP_ERR_ILL_MODE (GAP_ERR_GRP + 0x07) /* An illegal mode parameter was detected */ +#define GAP_ERR_ILL_INQ_TIME (GAP_ERR_GRP + 0x08) /* An illegal time parameter was detected */ +#define GAP_ERR_ILL_PARM (GAP_ERR_GRP + 0x09) /* An illegal parameter was detected */ +#define GAP_ERR_REM_NAME (GAP_ERR_GRP + 0x0a) /* Error starting the remote device name request */ +#define GAP_CMD_INITIATED (GAP_ERR_GRP + 0x0b) /* The GAP command was started (result pending) */ +#define GAP_DEVICE_NOT_UP (GAP_ERR_GRP + 0x0c) /* The device was not up; the request was not executed */ +#define GAP_BAD_BD_ADDR (GAP_ERR_GRP + 0x0d) /* The bd addr passed in was not found or invalid */ + +#define GAP_ERR_BAD_HANDLE (GAP_ERR_GRP + 0x0e) /* Bad GAP handle */ +#define GAP_ERR_BUF_OFFSET (GAP_ERR_GRP + 0x0f) /* Buffer offset invalid */ +#define GAP_ERR_BAD_STATE (GAP_ERR_GRP + 0x10) /* Connection is in invalid state */ +#define GAP_NO_DATA_AVAIL (GAP_ERR_GRP + 0x11) /* No data available */ +#define GAP_ERR_CONGESTED (GAP_ERR_GRP + 0x12) /* BT stack is congested */ +#define GAP_ERR_SECURITY (GAP_ERR_GRP + 0x13) /* Security failed */ + +#define GAP_ERR_PROCESSING (GAP_ERR_GRP + 0x14) /* General error processing BTM request */ +#define GAP_ERR_TIMEOUT (GAP_ERR_GRP + 0x15) /* Timeout occurred while processing cmd */ +#define GAP_EVT_CONN_OPENED 0x0100 +#define GAP_EVT_CONN_CLOSED 0x0101 +#define GAP_EVT_CONN_DATA_AVAIL 0x0102 +#define GAP_EVT_CONN_CONGESTED 0x0103 +#define GAP_EVT_CONN_UNCONGESTED 0x0104 +/* Values for 'chan_mode_mask' field */ +/* GAP_ConnOpen() - optional channels to negotiate */ +#define GAP_FCR_CHAN_OPT_BASIC L2CAP_FCR_CHAN_OPT_BASIC +#define GAP_FCR_CHAN_OPT_ERTM L2CAP_FCR_CHAN_OPT_ERTM +#define GAP_FCR_CHAN_OPT_STREAM L2CAP_FCR_CHAN_OPT_STREAM +/*** used in connection variables and functions ***/ +#define GAP_INVALID_HANDLE 0xFFFF + +/* This is used to change the criteria for AMP */ +#define GAP_PROTOCOL_ID (UUID_PROTOCOL_UDP) + + +#ifndef GAP_PREFER_CONN_INT_MAX +#define GAP_PREFER_CONN_INT_MAX BTM_BLE_CONN_INT_MIN +#endif + +#ifndef GAP_PREFER_CONN_INT_MIN +#define GAP_PREFER_CONN_INT_MIN BTM_BLE_CONN_INT_MIN +#endif + +#ifndef GAP_PREFER_CONN_LATENCY +#define GAP_PREFER_CONN_LATENCY 0 +#endif + +#ifndef GAP_PREFER_CONN_SP_TOUT +#define GAP_PREFER_CONN_SP_TOUT 2000 +#endif + +/***************************************************************************** +** Type Definitions +*****************************************************************************/ +/* +** Callback function for connection services +*/ +typedef void (tGAP_CONN_CALLBACK) (UINT16 gap_handle, UINT16 event); + +/* +** Define the callback function prototypes. Parameters are specific +** to each event and are described below +*/ +typedef void (tGAP_CALLBACK) (UINT16 event, void *p_data); + + +/* Definition of the GAP_FindAddrByName results structure */ +typedef struct { + UINT16 status; + BD_ADDR bd_addr; + tBTM_BD_NAME devname; +} tGAP_FINDADDR_RESULTS; + +typedef struct { + UINT16 int_min; + UINT16 int_max; + UINT16 latency; + UINT16 sp_tout; +} tGAP_BLE_PREF_PARAM; + +typedef union { + tGAP_BLE_PREF_PARAM conn_param; + BD_ADDR reconn_bda; + UINT16 icon; + UINT8 *p_dev_name; + UINT8 addr_resolution; + +} tGAP_BLE_ATTR_VALUE; + +typedef void (tGAP_BLE_CMPL_CBACK)(BOOLEAN status, BD_ADDR addr, UINT16 length, char *p_name); + + +/***************************************************************************** +** External Function Declarations +*****************************************************************************/ + +/*** Functions for L2CAP connection interface ***/ + +/******************************************************************************* +** +** Function GAP_ConnOpen +** +** Description This function is called to open a generic L2CAP connection. +** +** Returns handle of the connection if successful, else GAP_INVALID_HANDLE +** +*******************************************************************************/ +extern UINT16 GAP_ConnOpen (char *p_serv_name, UINT8 service_id, BOOLEAN is_server, + BD_ADDR p_rem_bda, UINT16 psm, tL2CAP_CFG_INFO *p_cfg, + tL2CAP_ERTM_INFO *ertm_info, + UINT16 security, UINT8 chan_mode_mask, tGAP_CONN_CALLBACK *p_cb); + +/******************************************************************************* +** +** Function GAP_ConnClose +** +** Description This function is called to close a connection. +** +** Returns BT_PASS - closed OK +** GAP_ERR_BAD_HANDLE - invalid handle +** +*******************************************************************************/ +extern UINT16 GAP_ConnClose (UINT16 gap_handle); + +/******************************************************************************* +** +** Function GAP_ConnReadData +** +** Description GKI buffer unaware application will call this function +** after receiving GAP_EVT_RXDATA event. A data copy is made +** into the receive buffer parameter. +** +** Returns BT_PASS - data read +** GAP_ERR_BAD_HANDLE - invalid handle +** GAP_NO_DATA_AVAIL - no data available +** +*******************************************************************************/ +extern UINT16 GAP_ConnReadData (UINT16 gap_handle, UINT8 *p_data, + UINT16 max_len, UINT16 *p_len); + +/******************************************************************************* +** +** Function GAP_GetRxQueueCnt +** +** Description This function return number of bytes on the rx queue. +** +** Parameters: handle - Handle returned in the GAP_ConnOpen +** p_rx_queue_count - Pointer to return queue count in. +** +** +*******************************************************************************/ +extern int GAP_GetRxQueueCnt (UINT16 handle, UINT32 *p_rx_queue_count); + +/******************************************************************************* +** +** Function GAP_ConnBTRead +** +** Description GKI buffer aware applications will call this function after +** receiving an GAP_EVT_RXDATA event to process the incoming +** data buffer. +** +** Returns BT_PASS - data read +** GAP_ERR_BAD_HANDLE - invalid handle +** GAP_NO_DATA_AVAIL - no data available +** +*******************************************************************************/ +extern UINT16 GAP_ConnBTRead (UINT16 gap_handle, BT_HDR **pp_buf); + +/******************************************************************************* +** +** Function GAP_ConnBTWrite +** +** Description GKI buffer aware applications can call this function to write data +** by passing a pointer to the GKI buffer of data. +** +** Returns BT_PASS - data read +** GAP_ERR_BAD_HANDLE - invalid handle +** GAP_ERR_BAD_STATE - connection not established +** GAP_INVALID_BUF_OFFSET - buffer offset is invalid +*******************************************************************************/ +extern UINT16 GAP_ConnBTWrite (UINT16 gap_handle, BT_HDR *p_buf); + +/******************************************************************************* +** +** Function GAP_ConnWriteData +** +** Description GKI buffer unaware application will call this function +** to send data to the connection. A data copy is made into a GKI +** buffer. +** +** Returns BT_PASS - data read +** GAP_ERR_BAD_HANDLE - invalid handle +** GAP_ERR_BAD_STATE - connection not established +** GAP_CONGESTION - system is congested +** +*******************************************************************************/ +extern UINT16 GAP_ConnWriteData (UINT16 gap_handle, UINT8 *p_data, + UINT16 max_len, UINT16 *p_len); + +/******************************************************************************* +** +** Function GAP_ConnReconfig +** +** Description Applications can call this function to reconfigure the connection. +** +** Returns BT_PASS - config process started +** GAP_ERR_BAD_HANDLE - invalid handle +** +*******************************************************************************/ +extern UINT16 GAP_ConnReconfig (UINT16 gap_handle, tL2CAP_CFG_INFO *p_cfg); + +/******************************************************************************* +** +** Function GAP_ConnSetIdleTimeout +** +** Description Higher layers call this function to set the idle timeout for +** a connection, or for all future connections. The "idle timeout" +** is the amount of time that a connection can remain up with +** no L2CAP channels on it. A timeout of zero means that the +** connection will be torn down immediately when the last channel +** is removed. A timeout of 0xFFFF means no timeout. Values are +** in seconds. +** +** Returns BT_PASS - config process started +** GAP_ERR_BAD_HANDLE - invalid handle +** +*******************************************************************************/ +extern UINT16 GAP_ConnSetIdleTimeout (UINT16 gap_handle, UINT16 timeout); + +/******************************************************************************* +** +** Function GAP_ConnGetRemoteAddr +** +** Description This function is called to get the remote BD address +** of a connection. +** +** Returns BT_PASS - closed OK +** GAP_ERR_BAD_HANDLE - invalid handle +** +*******************************************************************************/ +extern UINT8 *GAP_ConnGetRemoteAddr (UINT16 gap_handle); + +/******************************************************************************* +** +** Function GAP_ConnGetRemMtuSize +** +** Description Returns the remote device's MTU size. +** +** Returns UINT16 - maximum size buffer that can be transmitted to the peer +** +*******************************************************************************/ +extern UINT16 GAP_ConnGetRemMtuSize (UINT16 gap_handle); + +/******************************************************************************* +** +** Function GAP_ConnGetL2CAPCid +** +** Description Returns the L2CAP channel id +** +** Parameters: handle - Handle of the connection +** +** Returns UINT16 - The L2CAP channel id +** 0, if error +** +*******************************************************************************/ +extern UINT16 GAP_ConnGetL2CAPCid (UINT16 gap_handle); + +/******************************************************************************* +** +** Function GAP_SetTraceLevel +** +** Description This function sets the trace level for GAP. If called with +** a value of 0xFF, it simply returns the current trace level. +** +** Returns The new or current trace level +** +*******************************************************************************/ +extern UINT8 GAP_SetTraceLevel (UINT8 new_level); + +/******************************************************************************* +** +** Function GAP_Init +** +** Description Initializes the control blocks used by GAP. +** This routine should not be called except once per +** stack invocation. +** +** Returns Nothing +** +*******************************************************************************/ +extern void GAP_Init(void); + +#if (BLE_INCLUDED == TRUE) +/******************************************************************************* +** +** Function GAP_BleAttrDBUpdate +** +** Description update GAP local BLE attribute database. +** +** Returns Nothing +** +*******************************************************************************/ +extern void GAP_BleAttrDBUpdate(UINT16 attr_uuid, tGAP_BLE_ATTR_VALUE *p_value); + + +/******************************************************************************* +** +** Function GAP_BleReadPeerPrefConnParams +** +** Description Start a process to read a connected peripheral's preferred +** connection parameters +** +** Returns TRUE if read started, else FALSE if GAP is busy +** +*******************************************************************************/ +extern BOOLEAN GAP_BleReadPeerPrefConnParams (BD_ADDR peer_bda); + +/******************************************************************************* +** +** Function GAP_BleReadPeerDevName +** +** Description Start a process to read a connected peripheral's device name. +** +** Returns TRUE if request accepted +** +*******************************************************************************/ +extern BOOLEAN GAP_BleReadPeerDevName (BD_ADDR peer_bda, tGAP_BLE_CMPL_CBACK *p_cback); + + +/******************************************************************************* +** +** Function GAP_BleReadPeerAddressResolutionCap +** +** Description Start a process to read peer address resolution capability +** +** Returns TRUE if request accepted +** +*******************************************************************************/ +extern BOOLEAN GAP_BleReadPeerAddressResolutionCap (BD_ADDR peer_bda, + tGAP_BLE_CMPL_CBACK *p_cback); + +/******************************************************************************* +** +** Function GAP_BleCancelReadPeerDevName +** +** Description Cancel reading a peripheral's device name. +** +** Returns TRUE if request accepted +** +*******************************************************************************/ +extern BOOLEAN GAP_BleCancelReadPeerDevName (BD_ADDR peer_bda); + + +#endif + +#endif /* GAP_API_H */ diff --git a/tools/sdk/include/bluedroid/gap_int.h b/tools/sdk/include/bluedroid/gap_int.h new file mode 100644 index 00000000..fbddf67c --- /dev/null +++ b/tools/sdk/include/bluedroid/gap_int.h @@ -0,0 +1,154 @@ +/****************************************************************************** + * + * Copyright (C) 2009-2013 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. + * + ******************************************************************************/ + + +#ifndef GAP_INT_H +#define GAP_INT_H + +#include "bt_target.h" +#include "gap_api.h" +#include "gki.h" +#include "gatt_api.h" +#define GAP_MAX_BLOCKS 2 /* Concurrent GAP commands pending at a time*/ +/* Define the Generic Access Profile control structure */ +typedef struct { + void *p_data; /* Pointer to any data returned in callback */ + tGAP_CALLBACK *gap_cback; /* Pointer to users callback function */ + tGAP_CALLBACK *gap_inq_rslt_cback; /* Used for inquiry results */ + UINT16 event; /* Passed back in the callback */ + UINT8 index; /* Index of this control block and callback */ + BOOLEAN in_use; /* True when structure is allocated */ +} tGAP_INFO; + +/* Define the control block for the FindAddrByName operation (Only 1 active at a time) */ +typedef struct { + tGAP_CALLBACK *p_cback; + tBTM_INQ_INFO *p_cur_inq; /* Pointer to the current inquiry database entry */ + tGAP_FINDADDR_RESULTS results; + BOOLEAN in_use; +} tGAP_FINDADDR_CB; + +/* Define the GAP Connection Control Block. +*/ +typedef struct { +#define GAP_CCB_STATE_IDLE 0 +#define GAP_CCB_STATE_LISTENING 1 +#define GAP_CCB_STATE_CONN_SETUP 2 +#define GAP_CCB_STATE_CFG_SETUP 3 +#define GAP_CCB_STATE_WAIT_SEC 4 +#define GAP_CCB_STATE_CONNECTED 5 + UINT8 con_state; + +#define GAP_CCB_FLAGS_IS_ORIG 0x01 +#define GAP_CCB_FLAGS_HIS_CFG_DONE 0x02 +#define GAP_CCB_FLAGS_MY_CFG_DONE 0x04 +#define GAP_CCB_FLAGS_SEC_DONE 0x08 +#define GAP_CCB_FLAGS_CONN_DONE 0x0E + UINT8 con_flags; + + UINT8 service_id; /* Used by BTM */ + UINT16 gap_handle; /* GAP handle */ + UINT16 connection_id; /* L2CAP CID */ + BOOLEAN rem_addr_specified; + UINT8 chan_mode_mask; /* Supported channel modes (FCR) */ + BD_ADDR rem_dev_address; + UINT16 psm; + UINT16 rem_mtu_size; + + BOOLEAN is_congested; + BUFFER_Q tx_queue; /* Queue of buffers waiting to be sent */ + BUFFER_Q rx_queue; /* Queue of buffers waiting to be read */ + + UINT32 rx_queue_size; /* Total data count in rx_queue */ + + tGAP_CONN_CALLBACK *p_callback; /* Users callback function */ + + tL2CAP_CFG_INFO cfg; /* Configuration */ + tL2CAP_ERTM_INFO ertm_info; /* Pools and modes for ertm */ +} tGAP_CCB; + +typedef struct { +#if ((defined AMP_INCLUDED) && (AMP_INCLUDED == TRUE)) + tAMP_APPL_INFO reg_info; +#else + tL2CAP_APPL_INFO reg_info; /* L2CAP Registration info */ +#endif + tGAP_CCB ccb_pool[GAP_MAX_CONNECTIONS]; +} tGAP_CONN; + + +#if BLE_INCLUDED == TRUE +#define GAP_MAX_CHAR_NUM 4 + +typedef struct { + UINT16 handle; + UINT16 uuid; + tGAP_BLE_ATTR_VALUE attr_value; +} tGAP_ATTR; +#endif +/********************************************************************** +** M A I N C O N T R O L B L O C K +***********************************************************************/ + +#define GAP_MAX_CL GATT_CL_MAX_LCB + +typedef struct { + UINT16 uuid; + tGAP_BLE_CMPL_CBACK *p_cback; +} tGAP_BLE_REQ; + +typedef struct { + BD_ADDR bda; + tGAP_BLE_CMPL_CBACK *p_cback; + UINT16 conn_id; + UINT16 cl_op_uuid; + BOOLEAN in_use; + BOOLEAN connected; + BUFFER_Q pending_req_q; + +} tGAP_CLCB; + +typedef struct { + tGAP_INFO blk[GAP_MAX_BLOCKS]; + tBTM_CMPL_CB *btm_cback[GAP_MAX_BLOCKS]; + UINT8 trace_level; + tGAP_FINDADDR_CB findaddr_cb; /* Contains the control block for finding a device addr */ + tBTM_INQ_INFO *cur_inqptr; + +#if GAP_CONN_INCLUDED == TRUE + tGAP_CONN conn; +#endif + + /* LE GAP attribute database */ +#if BLE_INCLUDED == TRUE + tGAP_ATTR gatt_attr[GAP_MAX_CHAR_NUM]; + tGAP_CLCB clcb[GAP_MAX_CL]; /* connection link*/ + tGATT_IF gatt_if; +#endif +} tGAP_CB; + + +extern tGAP_CB gap_cb; +#if (GAP_CONN_INCLUDED == TRUE) +extern void gap_conn_init(void); +#endif +#if (BLE_INCLUDED == TRUE) +extern void gap_attr_db_init(void); +#endif + +#endif diff --git a/tools/sdk/include/bluedroid/gatt_api.h b/tools/sdk/include/bluedroid/gatt_api.h new file mode 100644 index 00000000..9360d4fb --- /dev/null +++ b/tools/sdk/include/bluedroid/gatt_api.h @@ -0,0 +1,1204 @@ +/****************************************************************************** + * + * Copyright (C) 1999-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. + * + ******************************************************************************/ +#ifndef GATT_API_H +#define GATT_API_H + +#include "bt_target.h" +#include "gattdefs.h" +#include "btm_ble_api.h" + +/***************************************************************************** +** Constants +*****************************************************************************/ +/* Success code and error codes */ +#define GATT_SUCCESS 0x00 +#define GATT_INVALID_HANDLE 0x01 +#define GATT_READ_NOT_PERMIT 0x02 +#define GATT_WRITE_NOT_PERMIT 0x03 +#define GATT_INVALID_PDU 0x04 +#define GATT_INSUF_AUTHENTICATION 0x05 +#define GATT_REQ_NOT_SUPPORTED 0x06 +#define GATT_INVALID_OFFSET 0x07 +#define GATT_INSUF_AUTHORIZATION 0x08 +#define GATT_PREPARE_Q_FULL 0x09 +#define GATT_NOT_FOUND 0x0a +#define GATT_NOT_LONG 0x0b +#define GATT_INSUF_KEY_SIZE 0x0c +#define GATT_INVALID_ATTR_LEN 0x0d +#define GATT_ERR_UNLIKELY 0x0e +#define GATT_INSUF_ENCRYPTION 0x0f +#define GATT_UNSUPPORT_GRP_TYPE 0x10 +#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 +#define GATT_DB_FULL 0x83 +#define GATT_BUSY 0x84 +#define GATT_ERROR 0x85 +#define GATT_CMD_STARTED 0x86 +#define GATT_PENDING 0x88 +#define GATT_AUTH_FAIL 0x89 +#define GATT_MORE 0x8a +#define GATT_INVALID_CFG 0x8b +#define GATT_SERVICE_STARTED 0x8c +#define GATT_ENCRYPED_MITM GATT_SUCCESS +#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 + +/* 0xE0 ~ 0xFC reserved for future use */ +#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; + + +#define GATT_RSP_ERROR 0x01 +#define GATT_REQ_MTU 0x02 +#define GATT_RSP_MTU 0x03 +#define GATT_REQ_FIND_INFO 0x04 +#define GATT_RSP_FIND_INFO 0x05 +#define GATT_REQ_FIND_TYPE_VALUE 0x06 +#define GATT_RSP_FIND_TYPE_VALUE 0x07 +#define GATT_REQ_READ_BY_TYPE 0x08 +#define GATT_RSP_READ_BY_TYPE 0x09 +#define GATT_REQ_READ 0x0A +#define GATT_RSP_READ 0x0B +#define GATT_REQ_READ_BLOB 0x0C +#define GATT_RSP_READ_BLOB 0x0D +#define GATT_REQ_READ_MULTI 0x0E +#define GATT_RSP_READ_MULTI 0x0F +#define GATT_REQ_READ_BY_GRP_TYPE 0x10 +#define GATT_RSP_READ_BY_GRP_TYPE 0x11 +#define GATT_REQ_WRITE 0x12 /* 0001-0010 (write)*/ +#define GATT_RSP_WRITE 0x13 +#define GATT_CMD_WRITE 0x52 /* changed in V4.0 01001-0010(write cmd)*/ +#define GATT_REQ_PREPARE_WRITE 0x16 +#define GATT_RSP_PREPARE_WRITE 0x17 +#define GATT_REQ_EXEC_WRITE 0x18 +#define GATT_RSP_EXEC_WRITE 0x19 +#define GATT_HANDLE_VALUE_NOTIF 0x1B +#define GATT_HANDLE_VALUE_IND 0x1D +#define GATT_HANDLE_VALUE_CONF 0x1E +#define GATT_SIGN_CMD_WRITE 0xD2 /* changed in V4.0 1101-0010 (signed write) see write cmd above*/ +#define GATT_OP_CODE_MAX GATT_HANDLE_VALUE_CONF + 1 /* 0x1E = 30 + 1 = 31*/ + + +#define GATT_HANDLE_IS_VALID(x) ((x) != 0) + +#define GATT_CONN_UNKNOWN 0 +#define GATT_CONN_L2C_FAILURE 1 /* general L2cap failure */ +#define GATT_CONN_TIMEOUT HCI_ERR_CONNECTION_TOUT /* 0x08 connection timeout */ +#define GATT_CONN_TERMINATE_PEER_USER HCI_ERR_PEER_USER /* 0x13 connection terminate by peer user */ +#define GATT_CONN_TERMINATE_LOCAL_HOST HCI_ERR_CONN_CAUSE_LOCAL_HOST /* 0x16 connectionterminated by local host */ +#define GATT_CONN_FAIL_ESTABLISH HCI_ERR_CONN_FAILED_ESTABLISHMENT/* 0x03E connection fail to establish */ +#define GATT_CONN_LMP_TIMEOUT HCI_ERR_LMP_RESPONSE_TIMEOUT /* 0x22 connection fail for LMP response tout */ +#define GATT_CONN_CANCEL L2CAP_CONN_CANCEL /* 0x0100 L2CAP connection cancelled */ +typedef UINT16 tGATT_DISCONN_REASON; + +/* MAX GATT MTU size +*/ +#ifndef GATT_MAX_MTU_SIZE +#define GATT_MAX_MTU_SIZE 517 +#endif + +/* max legth of an attribute value +*/ +#ifndef GATT_MAX_ATTR_LEN +#define GATT_MAX_ATTR_LEN 600 +#endif + +/* default GATT MTU size over LE link +*/ +#define GATT_DEF_BLE_MTU_SIZE 23 + +/* invalid connection ID +*/ +#define GATT_INVALID_CONN_ID 0xFFFF + +#ifndef GATT_CL_MAX_LCB +#define GATT_CL_MAX_LCB 12 // 22 +#endif + +#ifndef GATT_MAX_SCCB +#define GATT_MAX_SCCB 10 +#endif + + +/* GATT notification caching timer, default to be three seconds +*/ +#ifndef GATTC_NOTIF_TIMEOUT +#define GATTC_NOTIF_TIMEOUT 3 +#endif + +/***************************************************************************** +** GATT Structure Definition +*****************************************************************************/ + +/* Attribute permissions +*/ +#define GATT_PERM_READ (1 << 0) /* bit 0 */ +#define GATT_PERM_READ_ENCRYPTED (1 << 1) /* bit 1 */ +#define GATT_PERM_READ_ENC_MITM (1 << 2) /* bit 2 */ +#define GATT_PERM_WRITE (1 << 4) /* bit 4 */ +#define GATT_PERM_WRITE_ENCRYPTED (1 << 5) /* bit 5 */ +#define GATT_PERM_WRITE_ENC_MITM (1 << 6) /* bit 6 */ +#define GATT_PERM_WRITE_SIGNED (1 << 7) /* bit 7 */ +#define GATT_PERM_WRITE_SIGNED_MITM (1 << 8) /* bit 8 */ +typedef UINT16 tGATT_PERM; + +#define GATT_ENCRYPT_KEY_SIZE_MASK (0xF000) /* the MS nibble of tGATT_PERM; key size 7=0; size 16=9 */ + +#define GATT_READ_ALLOWED (GATT_PERM_READ | GATT_PERM_READ_ENCRYPTED | GATT_PERM_READ_ENC_MITM) +#define GATT_READ_AUTH_REQUIRED (GATT_PERM_READ_ENCRYPTED) +#define GATT_READ_MITM_REQUIRED (GATT_PERM_READ_ENC_MITM) +#define GATT_READ_ENCRYPTED_REQUIRED (GATT_PERM_READ_ENCRYPTED | GATT_PERM_READ_ENC_MITM) + + +#define GATT_WRITE_ALLOWED (GATT_PERM_WRITE | GATT_PERM_WRITE_ENCRYPTED | GATT_PERM_WRITE_ENC_MITM | \ + GATT_PERM_WRITE_SIGNED | GATT_PERM_WRITE_SIGNED_MITM) + +#define GATT_WRITE_AUTH_REQUIRED (GATT_PERM_WRITE_ENCRYPTED | GATT_PERM_WRITE_SIGNED) + +#define GATT_WRITE_MITM_REQUIRED (GATT_PERM_WRITE_ENC_MITM | GATT_PERM_WRITE_SIGNED_MITM) + +#define GATT_WRITE_ENCRYPTED_PERM (GATT_PERM_WRITE_ENCRYPTED | GATT_PERM_WRITE_ENC_MITM) + +#define GATT_WRITE_SIGNED_PERM (GATT_PERM_WRITE_SIGNED | GATT_PERM_WRITE_SIGNED_MITM) + + +/* Characteristic properties +*/ +#define GATT_CHAR_PROP_BIT_BROADCAST (1 << 0) +#define GATT_CHAR_PROP_BIT_READ (1 << 1) +#define GATT_CHAR_PROP_BIT_WRITE_NR (1 << 2) +#define GATT_CHAR_PROP_BIT_WRITE (1 << 3) +#define GATT_CHAR_PROP_BIT_NOTIFY (1 << 4) +#define GATT_CHAR_PROP_BIT_INDICATE (1 << 5) +#define GATT_CHAR_PROP_BIT_AUTH (1 << 6) +#define GATT_CHAR_PROP_BIT_EXT_PROP (1 << 7) +typedef UINT8 tGATT_CHAR_PROP; + + +/* Format of the value of a characteristic. enumeration type +*/ +enum { + GATT_FORMAT_RES, /* rfu */ + GATT_FORMAT_BOOL, /* 0x01 boolean */ + GATT_FORMAT_2BITS, /* 0x02 2 bit */ + GATT_FORMAT_NIBBLE, /* 0x03 nibble */ + GATT_FORMAT_UINT8, /* 0x04 uint8 */ + GATT_FORMAT_UINT12, /* 0x05 uint12 */ + GATT_FORMAT_UINT16, /* 0x06 uint16 */ + GATT_FORMAT_UINT24, /* 0x07 uint24 */ + GATT_FORMAT_UINT32, /* 0x08 uint32 */ + GATT_FORMAT_UINT48, /* 0x09 uint48 */ + GATT_FORMAT_UINT64, /* 0x0a uint64 */ + GATT_FORMAT_UINT128, /* 0x0B uint128 */ + GATT_FORMAT_SINT8, /* 0x0C signed 8 bit integer */ + GATT_FORMAT_SINT12, /* 0x0D signed 12 bit integer */ + GATT_FORMAT_SINT16, /* 0x0E signed 16 bit integer */ + GATT_FORMAT_SINT24, /* 0x0F signed 24 bit integer */ + GATT_FORMAT_SINT32, /* 0x10 signed 32 bit integer */ + GATT_FORMAT_SINT48, /* 0x11 signed 48 bit integer */ + GATT_FORMAT_SINT64, /* 0x12 signed 64 bit integer */ + GATT_FORMAT_SINT128, /* 0x13 signed 128 bit integer */ + GATT_FORMAT_FLOAT32, /* 0x14 float 32 */ + GATT_FORMAT_FLOAT64, /* 0x15 float 64*/ + GATT_FORMAT_SFLOAT, /* 0x16 IEEE-11073 16 bit SFLOAT */ + GATT_FORMAT_FLOAT, /* 0x17 IEEE-11073 32 bit SFLOAT */ + GATT_FORMAT_DUINT16, /* 0x18 IEEE-20601 format */ + GATT_FORMAT_UTF8S, /* 0x19 UTF-8 string */ + GATT_FORMAT_UTF16S, /* 0x1a UTF-16 string */ + GATT_FORMAT_STRUCT, /* 0x1b Opaque structure*/ + GATT_FORMAT_MAX /* 0x1c or above reserved */ +}; +typedef UINT8 tGATT_FORMAT; + +/* Characteristic Presentation Format Descriptor value +*/ +typedef struct { + UINT16 unit; /* as UUIUD defined by SIG */ + UINT16 descr; /* as UUID as defined by SIG */ + tGATT_FORMAT format; + INT8 exp; + UINT8 name_spc; /* The name space of the description */ +} tGATT_CHAR_PRES; + +/* Characteristic Report reference Descriptor format +*/ +typedef struct { + UINT8 rpt_id; /* report ID */ + UINT8 rpt_type; /* report type */ +} tGATT_CHAR_RPT_REF; + + +#define GATT_VALID_RANGE_MAX_SIZE 16 +typedef struct { + UINT8 format; + UINT16 len; + UINT8 lower_range[GATT_VALID_RANGE_MAX_SIZE]; /* in little endian format */ + UINT8 upper_range[GATT_VALID_RANGE_MAX_SIZE]; +} tGATT_VALID_RANGE; + +/* Characteristic Aggregate Format attribute value +*/ +#define GATT_AGGR_HANDLE_NUM_MAX 10 +typedef struct { + UINT8 num_handle; + UINT16 handle_list[GATT_AGGR_HANDLE_NUM_MAX]; +} tGATT_CHAR_AGGRE; + +/* Characteristic descriptor: Extended Properties value +*/ +#define GATT_CHAR_BIT_REL_WRITE 0x0001 /* permits reliable writes of the Characteristic Value */ +#define GATT_CHAR_BIT_WRITE_AUX 0x0002 /* permits writes to the characteristic descriptor */ + + +/* characteristic descriptor: client configuration value +*/ +#define GATT_CLT_CONFIG_NONE 0x0000 +#define GATT_CLT_CONFIG_NOTIFICATION 0x0001 +#define GATT_CLT_CONFIG_INDICATION 0x0002 +typedef UINT16 tGATT_CLT_CHAR_CONFIG; + + +/* characteristic descriptor: server configuration value +*/ +#define GATT_SVR_CONFIG_NONE 0x0000 +#define GATT_SVR_CONFIG_BROADCAST 0x0001 +typedef UINT16 tGATT_SVR_CHAR_CONFIG; + +/* Characteristic descriptor: Extended Properties value +*/ +#define GATT_CHAR_BIT_REL_WRITE 0x0001 /* permits reliable writes of the Characteristic Value */ +#define GATT_CHAR_BIT_WRITE_AUX 0x0002 /* permits writes to the characteristic descriptor */ + +/* authentication requirement +*/ +#define GATT_AUTH_REQ_NONE 0 +#define GATT_AUTH_REQ_NO_MITM 1 /* unauthenticated encryption */ +#define GATT_AUTH_REQ_MITM 2 /* authenticated encryption */ +#define GATT_AUTH_REQ_SIGNED_NO_MITM 3 +#define GATT_AUTH_REQ_SIGNED_MITM 4 +typedef UINT8 tGATT_AUTH_REQ; + +/* Attribute Value structure +*/ +typedef struct { + UINT16 conn_id; + UINT16 handle; /* attribute handle */ + UINT16 offset; /* attribute value offset, if no offfset is needed for the command, ignore it */ + UINT16 len; /* length of attribute value */ + tGATT_AUTH_REQ auth_req; /* authentication request */ + UINT8 value[GATT_MAX_ATTR_LEN]; /* the actual attribute value */ +} tGATT_VALUE; + +typedef struct{ + UINT16 attr_max_len; + UINT16 attr_len; + UINT8 *attr_val; +}tGATT_ATTR_VAL; + +typedef struct{ + uint8_t auto_rsp; +}tGATTS_ATTR_CONTROL; + +/* Union of the event data which is used in the server respond API to carry the server response information +*/ +typedef union { + /* data type member event */ + tGATT_VALUE attr_value; /* READ, HANDLE_VALUE_IND, PREPARE_WRITE */ + /* READ_BLOB, READ_BY_TYPE */ + UINT16 handle; /* WRITE, WRITE_BLOB */ + +} tGATTS_RSP; + +/* Transports for the primary service */ +#define GATT_TRANSPORT_LE BT_TRANSPORT_LE +#define GATT_TRANSPORT_BR_EDR BT_TRANSPORT_BR_EDR +#define GATT_TRANSPORT_LE_BR_EDR (BT_TRANSPORT_LE|BT_TRANSPORT_BR_EDR) +typedef UINT8 tGATT_TRANSPORT; + +#define GATT_PREP_WRITE_CANCEL 0x00 +#define GATT_PREP_WRITE_EXEC 0x01 +typedef UINT8 tGATT_EXEC_FLAG; + +/* read request always based on UUID */ +typedef struct { + UINT16 handle; + UINT16 offset; + BOOLEAN is_long; + BOOLEAN need_rsp; +} tGATT_READ_REQ; + +/* write request data */ +typedef struct { + UINT16 handle; /* attribute handle */ + UINT16 offset; /* attribute value offset, if no offfset is needed for the command, ignore it */ + UINT16 len; /* length of attribute value */ + UINT8 value[GATT_MAX_ATTR_LEN]; /* the actual attribute value */ + BOOLEAN need_rsp; /* need write response */ + BOOLEAN is_prep; /* is prepare write */ +} tGATT_WRITE_REQ; + +/* callback data for server access request from client */ +typedef union { + tGATT_READ_REQ read_req; /* read request, read by Type, read blob */ + + tGATT_WRITE_REQ write_req; /* write */ + /* prepare write */ + /* write blob */ + UINT16 handle; /* handle value confirmation */ + UINT16 mtu; /* MTU exchange request */ + tGATT_EXEC_FLAG exec_write; /* execute write */ +} tGATTS_DATA; + +typedef UINT8 tGATT_SERV_IF; /* GATT Service Interface */ + +enum { + GATTS_REQ_TYPE_READ = 1, /* Attribute read request */ + GATTS_REQ_TYPE_WRITE, /* Attribute write request */ + GATTS_REQ_TYPE_WRITE_EXEC, /* Execute write */ + GATTS_REQ_TYPE_MTU, /* MTU exchange information */ + GATTS_REQ_TYPE_CONF /* handle value confirmation */ +}; +typedef UINT8 tGATTS_REQ_TYPE; + + + +/* Client Used Data Structure +*/ +/* definition of different discovery types */ +enum { + GATT_DISC_SRVC_ALL = 1, /* discover all services */ + GATT_DISC_SRVC_BY_UUID, /* discover service of a special type */ + GATT_DISC_INC_SRVC, /* discover the included service within a service */ + GATT_DISC_CHAR, /* discover characteristics of a service with/without type requirement */ + GATT_DISC_CHAR_DSCPT, /* discover characteristic descriptors of a character */ + GATT_DISC_MAX /* maximnun discover type */ +}; +typedef UINT8 tGATT_DISC_TYPE; + +/* Discover parameters of different discovery types +*/ +typedef struct { + tBT_UUID service; + UINT16 s_handle; + UINT16 e_handle; +} tGATT_DISC_PARAM; + +/* GATT read type enumeration +*/ +enum { + GATT_READ_BY_TYPE = 1, + GATT_READ_BY_HANDLE, + GATT_READ_MULTIPLE, + GATT_READ_CHAR_VALUE, + GATT_READ_PARTIAL, + GATT_READ_MAX +}; +typedef UINT8 tGATT_READ_TYPE; + +/* Read By Type Request (GATT_READ_BY_TYPE) Data +*/ +typedef struct { + tGATT_AUTH_REQ auth_req; + UINT16 s_handle; + UINT16 e_handle; + tBT_UUID uuid; +} tGATT_READ_BY_TYPE; + +/* GATT_READ_MULTIPLE request data +*/ +#define GATT_MAX_READ_MULTI_HANDLES 10 /* Max attributes to read in one request */ +typedef struct { + tGATT_AUTH_REQ auth_req; + UINT16 num_handles; /* number of handles to read */ + UINT16 handles[GATT_MAX_READ_MULTI_HANDLES]; /* handles list to be read */ +} tGATT_READ_MULTI; + +/* Read By Handle Request (GATT_READ_BY_HANDLE) data */ +typedef struct { + tGATT_AUTH_REQ auth_req; + UINT16 handle; +} tGATT_READ_BY_HANDLE; + +/* READ_BT_HANDLE_Request data */ +typedef struct { + tGATT_AUTH_REQ auth_req; + UINT16 handle; + UINT16 offset; +} tGATT_READ_PARTIAL; + +/* Read Request Data +*/ +typedef union { + tGATT_READ_BY_TYPE service; + tGATT_READ_BY_TYPE char_type; /* characterisitc type */ + tGATT_READ_MULTI read_multiple; + tGATT_READ_BY_HANDLE by_handle; + tGATT_READ_PARTIAL partial; +} tGATT_READ_PARAM; + +/* GATT write type enumeration */ +enum { + GATT_WRITE_NO_RSP = 1, + GATT_WRITE , + GATT_WRITE_PREPARE +}; +typedef UINT8 tGATT_WRITE_TYPE; + +/* Client Operation Complete Callback Data +*/ +typedef union { + tGATT_VALUE att_value; + UINT16 mtu; + UINT16 handle; +} tGATT_CL_COMPLETE; + +/* GATT client operation type, used in client callback function +*/ +#define GATTC_OPTYPE_NONE 0 +#define GATTC_OPTYPE_DISCOVERY 1 +#define GATTC_OPTYPE_READ 2 +#define GATTC_OPTYPE_WRITE 3 +#define GATTC_OPTYPE_EXE_WRITE 4 +#define GATTC_OPTYPE_CONFIG 5 +#define GATTC_OPTYPE_NOTIFICATION 6 +#define GATTC_OPTYPE_INDICATION 7 +typedef UINT8 tGATTC_OPTYPE; + +/* characteristic declaration +*/ +typedef struct { + tGATT_CHAR_PROP char_prop; /* characterisitc properties */ + UINT16 val_handle; /* characteristic value attribute handle */ + tBT_UUID char_uuid; /* characteristic UUID type */ +} tGATT_CHAR_DCLR_VAL; + +/* primary service group data +*/ +typedef struct { + UINT16 e_handle; /* ending handle of the group */ + tBT_UUID service_type; /* group type */ +} tGATT_GROUP_VALUE; + + +/* included service attribute value +*/ +typedef struct { + tBT_UUID service_type; /* included service UUID */ + UINT16 s_handle; /* starting handle */ + UINT16 e_handle; /* ending handle */ +} tGATT_INCL_SRVC; + +typedef union { + tGATT_INCL_SRVC incl_service; /* include service value */ + tGATT_GROUP_VALUE group_value; /* Service UUID type. + This field is used with GATT_DISC_SRVC_ALL + or GATT_DISC_SRVC_BY_UUID + type of discovery result callback. */ + + UINT16 handle; /* When used with GATT_DISC_INC_SRVC type discovery result, + it is the included service starting handle.*/ + + tGATT_CHAR_DCLR_VAL dclr_value; /* Characteristic declaration value. + This field is used with GATT_DISC_CHAR type discovery.*/ +} tGATT_DISC_VALUE; + +/* discover result record +*/ +typedef struct { + tBT_UUID type; + UINT16 handle; + tGATT_DISC_VALUE value; +} tGATT_DISC_RES; + + +#define GATT_LINK_IDLE_TIMEOUT_WHEN_NO_APP 0 /* start a idle timer for this duration + when no application need to use the link */ + +#define GATT_LINK_NO_IDLE_TIMEOUT 0xFFFF + +#define GATT_INVALID_ACL_HANDLE 0xFFFF +/* discover result callback function */ +typedef void (tGATT_DISC_RES_CB) (UINT16 conn_id, tGATT_DISC_TYPE disc_type, + tGATT_DISC_RES *p_data); + +/* discover complete callback function */ +typedef void (tGATT_DISC_CMPL_CB) (UINT16 conn_id, tGATT_DISC_TYPE disc_type, tGATT_STATUS status); + +/* Define a callback function for when read/write/disc/config operation is completed. */ +typedef void (tGATT_CMPL_CBACK) (UINT16 conn_id, tGATTC_OPTYPE op, tGATT_STATUS status, + tGATT_CL_COMPLETE *p_data); + +/* Define a callback function when an initialized connection is established. */ +typedef void (tGATT_CONN_CBACK) (tGATT_IF gatt_if, BD_ADDR bda, UINT16 conn_id, BOOLEAN connected, + tGATT_DISCONN_REASON reason, tBT_TRANSPORT transport); + +/* attribute request callback for ATT server */ +typedef void (tGATT_REQ_CBACK )(UINT16 conn_id, UINT32 trans_id, tGATTS_REQ_TYPE type, + tGATTS_DATA *p_data); + +/* channel congestion/uncongestion callback */ +typedef void (tGATT_CONGESTION_CBACK )(UINT16 conn_id, BOOLEAN congested); + +/* Define a callback function when encryption is established. */ +typedef void (tGATT_ENC_CMPL_CB)(tGATT_IF gatt_if, BD_ADDR bda); + + +/* Define the structure that applications use to register with +** GATT. This structure includes callback functions. All functions +** MUST be provided. +*/ +typedef struct { + tGATT_CONN_CBACK *p_conn_cb; + tGATT_CMPL_CBACK *p_cmpl_cb; + tGATT_DISC_RES_CB *p_disc_res_cb; + tGATT_DISC_CMPL_CB *p_disc_cmpl_cb; + tGATT_REQ_CBACK *p_req_cb; + tGATT_ENC_CMPL_CB *p_enc_cmpl_cb; + tGATT_CONGESTION_CBACK *p_congestion_cb; +} tGATT_CBACK; + +/*********************** Start Handle Management Definitions ********************** +*/ + + +typedef struct { + tBT_UUID app_uuid128; + tBT_UUID svc_uuid; + UINT16 svc_inst; + UINT16 s_handle; + UINT16 e_handle; + BOOLEAN is_primary; /* primary service or secondary */ +} tGATTS_HNDL_RANGE; + + + +#define GATTS_SRV_CHG_CMD_ADD_CLIENT 1 +#define GATTS_SRV_CHG_CMD_UPDATE_CLIENT 2 +#define GATTS_SRV_CHG_CMD_REMOVE_CLIENT 3 +#define GATTS_SRV_CHG_CMD_READ_NUM_CLENTS 4 +#define GATTS_SRV_CHG_CMD_READ_CLENT 5 +typedef UINT8 tGATTS_SRV_CHG_CMD; + +typedef struct { + BD_ADDR bda; + BOOLEAN srv_changed; +} tGATTS_SRV_CHG; + + +typedef union { + tGATTS_SRV_CHG srv_chg; + UINT8 client_read_index; /* only used for sequential reading client srv chg info */ +} tGATTS_SRV_CHG_REQ; + +typedef union { + tGATTS_SRV_CHG srv_chg; + UINT8 num_clients; +} tGATTS_SRV_CHG_RSP; + + + +typedef struct { + tGATTS_HNDL_RANGE *p_new_srv_start; +} tGATTS_PENDING_NEW_SRV_START; + +/* Attibute server handle ranges NV storage callback functions +*/ +typedef void (tGATTS_NV_SAVE_CBACK)(BOOLEAN is_saved, tGATTS_HNDL_RANGE *p_hndl_range); +typedef BOOLEAN (tGATTS_NV_SRV_CHG_CBACK)(tGATTS_SRV_CHG_CMD cmd, tGATTS_SRV_CHG_REQ *p_req, + tGATTS_SRV_CHG_RSP *p_rsp); + +typedef struct { + tGATTS_NV_SAVE_CBACK *p_nv_save_callback; + tGATTS_NV_SRV_CHG_CBACK *p_srv_chg_callback; +} tGATT_APPL_INFO; + +/* +*********************** End Handle Management Definitions **********************/ + +/***************************************************************************** +** External Function Declarations +*****************************************************************************/ +#ifdef __cplusplus +extern "C" +{ +#endif + +/******************************************************************************* +** +** Function GATT_SetTraceLevel +** +** Description This function sets the trace level. If called with +** a value of 0xFF, it simply returns the current trace level. +** +** Returns The new or current trace level +** +*******************************************************************************/ +extern UINT8 GATT_SetTraceLevel (UINT8 new_level); + + +/*******************************************************************************/ +/* GATT Profile API Functions */ +/*******************************************************************************/ +/* GATT Profile Server Functions */ +/*******************************************************************************/ +/******************************************************************************* +** +** Function GATTS_AddHandleRange +** +** Description This function add the allocated handles range for the specifed +** application UUID, service UUID and service instance +** +** Parameter p_hndl_range: pointer to allocated handles information +** +** Returns TRUE if handle range is added sucessfully; otherwise FALSE. +** +*******************************************************************************/ + +extern BOOLEAN GATTS_AddHandleRange(tGATTS_HNDL_RANGE *p_hndl_range); + +/******************************************************************************* +** +** Function GATTS_NVRegister +** +** Description Application manager calls this function to register for +** NV save callback function. There can be one and only one +** NV save callback function. +** +** Parameter p_cb_info : callback informaiton +** +** Returns TRUE if registered OK, else FALSE +** +*******************************************************************************/ +extern BOOLEAN GATTS_NVRegister (tGATT_APPL_INFO *p_cb_info); + + +/******************************************************************************* +** +** Function GATTS_CreateService +** +** Description This function is called to reserve a block of handles for a service. +** +** *** It should be called only once per service instance *** +** +** Parameter gatt_if : application if +** p_svc_uuid : service UUID +** svc_inst : instance of the service inside the application +** num_handles : number of handles needed by the service. +** is_pri : is a primary service or not. +** +** Returns service handle if sucessful, otherwise 0. +** +*******************************************************************************/ +extern UINT16 GATTS_CreateService (tGATT_IF gatt_if, tBT_UUID *p_svc_uuid, + UINT16 svc_inst, UINT16 num_handles, BOOLEAN is_pri); + + +/******************************************************************************* +** +** Function GATTS_AddIncludeService +** +** Description This function is called to add an included service. +** +** Parameter service_handle : To which service this included service is added to. +** include_svc_handle : included service handle. +** +** Returns included service attribute handle. If 0, add included service +** fail. +** +*******************************************************************************/ +extern UINT16 GATTS_AddIncludeService (UINT16 service_handle, + UINT16 include_svc_handle); + + +/******************************************************************************* +** +** Function GATTS_AddCharacteristic +** +** Description This function is called to add a characteristic into a service. +** It will add a characteristic declaration and characteristic +** value declaration into the service database identified by the +** service handle. +** +** Parameter service_handle : To which service this included service is added to. +** char_uuid : Characteristic UUID. +** perm : Characteristic value declaration attribute permission. +** property : Characteristic Properties +** +** Returns Characteristic value declaration attribute handle. 0 if add +** characteristic failed. +** +*******************************************************************************/ +extern UINT16 GATTS_AddCharacteristic (UINT16 service_handle, tBT_UUID *p_char_uuid, + tGATT_PERM perm, tGATT_CHAR_PROP property, + tGATT_ATTR_VAL *attr_val, tGATTS_ATTR_CONTROL *control); + +/******************************************************************************* +** +** Function GATTS_AddCharDescriptor +** +** Description This function is called to add a characteristic descriptor +** into a service database. Add descriptor should follow add char +** to which it belongs, and next add char should be done only +** after all add descriptors for the previous char. +** +** Parameter service_handle : To which service this characteristic descriptor +** is added to. +** perm : Characteristic value declaration attribute +** permission. +** p_descr_uuid : Characteristic descriptor UUID. +** +** Returns Characteristic descriptor attribute handle. 0 if add +** characteristic descriptor failed. +** +*******************************************************************************/ +extern UINT16 GATTS_AddCharDescriptor (UINT16 service_handle, tGATT_PERM perm, + tBT_UUID *p_descr_uuid, tGATT_ATTR_VAL *attr_val, + tGATTS_ATTR_CONTROL *control); + +/******************************************************************************* +** +** Function GATTS_DeleteService +** +** Description This function is called to delete a service. +** +** Parameter gatt_if : application interface +** p_svc_uuid : service UUID +** svc_inst : instance of the service inside the application +** +** Returns TRUE if operation succeed, FALSE if handle block was not found. +** +*******************************************************************************/ +extern BOOLEAN GATTS_DeleteService (tGATT_IF gatt_if, tBT_UUID *p_svc_uuid, + UINT16 svc_inst); + +/******************************************************************************* +** +** Function GATTS_StartService +** +** Description This function is called to start a service with GATT +** +** Parameter gatt_if : service handle. +** p_cback : application service callback functions. +** sup_transport : supported transport(s) for this primary service +** +** return GATT_SUCCESS if sucessfully started; otherwise error code. +** +*******************************************************************************/ +extern tGATT_STATUS GATTS_StartService (tGATT_IF gatt_if, UINT16 service_handle, + tGATT_TRANSPORT sup_transport); + + +/******************************************************************************* +** +** Function GATTS_StopService +** +** Description This function is called to stop a service +** +** Parameter service_handle : this is the start handle of a service +** +** Returns None. +** +*******************************************************************************/ +extern void GATTS_StopService (UINT16 service_handle); + + +/******************************************************************************* +** +** Function GATTs_HandleValueIndication +** +** Description This function sends a handle value indication to a client. +** +** Parameter conn_id: connection identifier. +** attr_handle: Attribute handle of this handle value indication. +** val_len: Length of the indicated attribute value. +** p_val: Pointer to the indicated attribute value data. +** +** Returns GATT_SUCCESS if sucessfully sent or queued; otherwise error code. +** +*******************************************************************************/ +extern tGATT_STATUS GATTS_HandleValueIndication (UINT16 conn_id, + UINT16 attr_handle, + UINT16 val_len, UINT8 *p_val); + +/******************************************************************************* +** +** Function GATTS_HandleValueNotification +** +** Description This function sends a handle value notification to a client. +** +** Parameter conn_id: connection identifier. +** attr_handle: Attribute handle of this handle value indication. +** val_len: Length of the indicated attribute value. +** p_val: Pointer to the indicated attribute value data. +** +** Returns GATT_SUCCESS if sucessfully sent; otherwise error code. +** +*******************************************************************************/ +extern tGATT_STATUS GATTS_HandleValueNotification (UINT16 conn_id, UINT16 attr_handle, + UINT16 val_len, UINT8 *p_val); + + +/******************************************************************************* +** +** Function GATTS_SendRsp +** +** Description This function sends the server response to client. +** +** Parameter conn_id: connection identifier. +** trans_id: transaction id +** status: response status +** p_msg: pointer to message parameters structure. +** +** Returns GATT_SUCCESS if sucessfully sent; otherwise error code. +** +*******************************************************************************/ +extern tGATT_STATUS GATTS_SendRsp (UINT16 conn_id, UINT32 trans_id, + tGATT_STATUS status, tGATTS_RSP *p_msg); + + +/******************************************************************************* +** +** Function GATTS_SetAttributeValue +** +** Description This function sends to set the attribute value . +** +** Parameter attr_handle:the attribute handle +** length: the attribute length +** value: the value to be set to the attribute in the database +** +** Returns GATT_SUCCESS if sucessfully sent; otherwise error code. +** +*******************************************************************************/ +tGATT_STATUS GATTS_SetAttributeValue(UINT16 attr_handle, UINT16 length, UINT8 *value); + + +/******************************************************************************* +** +** Function GATTS_GetAttributeValue +** +** Description This function sends to set the attribute value . +** +** Parameter attr_handle: the attribute handle +** length:the attribute value length in the database +** value: the attribute value out put +** +** Returns GATT_SUCCESS if sucessfully sent; otherwise error code. +** +*******************************************************************************/ +tGATT_STATUS GATTS_GetAttributeValue(UINT16 attr_handle, UINT16 *length, UINT8 **value); + + + +/*******************************************************************************/ +/* GATT Profile Client Functions */ +/*******************************************************************************/ + +/******************************************************************************* +** +** Function GATTC_ConfigureMTU +** +** Description This function is called to configure the ATT MTU size for +** a connection on an LE transport. +** +** Parameters conn_id: connection identifier. +** mtu - attribute MTU size.. +** +** Returns GATT_SUCCESS if command started successfully. +** +*******************************************************************************/ +extern tGATT_STATUS GATTC_ConfigureMTU (UINT16 conn_id, UINT16 mtu); + +/******************************************************************************* +** +** Function GATTC_Discover +** +** Description This function is called to do a discovery procedure on ATT server. +** +** Parameters conn_id: connection identifier. +** disc_type:discovery type. +** p_param: parameters of discovery requirement. +** +** Returns GATT_SUCCESS if command received/sent successfully. +** +*******************************************************************************/ +extern tGATT_STATUS GATTC_Discover (UINT16 conn_id, + tGATT_DISC_TYPE disc_type, + tGATT_DISC_PARAM *p_param ); +/******************************************************************************* +** +** Function GATTC_Read +** +** Description This function is called to read the value of an attribute from +** the server. +** +** Parameters conn_id: connection identifier. +** type - attribute read type. +** p_read - read operation parameters. +** +** Returns GATT_SUCCESS if command started successfully. +** +*******************************************************************************/ +extern tGATT_STATUS GATTC_Read (UINT16 conn_id, tGATT_READ_TYPE type, + tGATT_READ_PARAM *p_read); + +/******************************************************************************* +** +** Function GATTC_Write +** +** Description This function is called to read the value of an attribute from +** the server. +** +** Parameters conn_id: connection identifier. +** type - attribute write type. +** p_write - write operation parameters. +** +** Returns GATT_SUCCESS if command started successfully. +** +*******************************************************************************/ +extern tGATT_STATUS GATTC_Write (UINT16 conn_id, tGATT_WRITE_TYPE type, + tGATT_VALUE *p_write); + + +/******************************************************************************* +** +** Function GATTC_ExecuteWrite +** +** Description This function is called to send an Execute write request to +** the server. +** +** Parameters conn_id: connection identifier. +** is_execute - to execute or cancel the prepare write requet(s) +** +** Returns GATT_SUCCESS if command started successfully. +** +*******************************************************************************/ +extern tGATT_STATUS GATTC_ExecuteWrite (UINT16 conn_id, BOOLEAN is_execute); + +/******************************************************************************* +** +** Function GATTC_SendHandleValueConfirm +** +** Description This function is called to send a handle value confirmation +** as response to a handle value notification from server. +** +** Parameters conn_id: connection identifier. +** handle: the handle of the attribute confirmation. +** +** Returns GATT_SUCCESS if command started successfully. +** +*******************************************************************************/ +extern tGATT_STATUS GATTC_SendHandleValueConfirm (UINT16 conn_id, UINT16 handle); + + +/******************************************************************************* +** +** Function GATT_SetIdleTimeout +** +** Description This function (common to both client and server) sets the idle +** timeout for a tansport connection +** +** Parameter bd_addr: target device bd address. +** idle_tout: timeout value in seconds. +** transport: trasnport option. +** +** Returns void +** +*******************************************************************************/ +extern void GATT_SetIdleTimeout (BD_ADDR bd_addr, UINT16 idle_tout, + tGATT_TRANSPORT transport); + + +/******************************************************************************* +** +** Function GATT_Register +** +** Description This function is called to register an application +** with GATT +** +** Parameter p_app_uuid128: Application UUID +** p_cb_info: callback functions. +** +** Returns 0 for error, otherwise the index of the client registered with GATT +** +*******************************************************************************/ +extern tGATT_IF GATT_Register (tBT_UUID *p_app_uuid128, tGATT_CBACK *p_cb_info); + +/******************************************************************************* +** +** Function GATT_Deregister +** +** Description This function deregistered the application from GATT. +** +** Parameters gatt_if: applicaiton interface. +** +** Returns None. +** +*******************************************************************************/ +extern void GATT_Deregister (tGATT_IF gatt_if); + +/******************************************************************************* +** +** Function GATT_StartIf +** +** Description This function is called after registration to start receiving +** callbacks for registered interface. Function may call back +** with connection status and queued notifications +** +** Parameter gatt_if: applicaiton interface. +** +** Returns None +** +*******************************************************************************/ +extern void GATT_StartIf (tGATT_IF gatt_if); + +/******************************************************************************* +** +** Function GATT_Connect +** +** Description This function initiate a connecttion to a remote device on GATT +** channel. +** +** Parameters gatt_if: applicaiton interface +** bd_addr: peer device address. +** is_direct: is a direct conenection or a background auto connection +** transport : Physical transport for GATT connection (BR/EDR or LE) +** +** Returns TRUE if connection started; FALSE if connection start failure. +** +*******************************************************************************/ +extern BOOLEAN GATT_Connect (tGATT_IF gatt_if, BD_ADDR bd_addr, + BOOLEAN is_direct, tBT_TRANSPORT transport); + + +/******************************************************************************* +** +** Function GATT_CancelConnect +** +** Description This function terminate the connection initaition to a remote +** device on GATT channel. +** +** Parameters gatt_if: client interface. If 0 used as unconditionally disconnect, +** typically used for direct connection cancellation. +** bd_addr: peer device address. +** is_direct: is a direct conenection or a background auto connection +** +** Returns TRUE if connection started; FALSE if connection start failure. +** +*******************************************************************************/ +extern BOOLEAN GATT_CancelConnect (tGATT_IF gatt_if, BD_ADDR bd_addr, + BOOLEAN is_direct); + +/******************************************************************************* +** +** Function GATT_Disconnect +** +** Description This function disconnect the GATT channel for this registered +** application. +** +** Parameters conn_id: connection identifier. +** +** Returns GATT_SUCCESS if disconnected. +** +*******************************************************************************/ +extern tGATT_STATUS GATT_Disconnect (UINT16 conn_id); + + + +/******************************************************************************* +** +** Function GATT_GetConnectionInfor +** +** Description This function use conn_id to find its associated BD address and applciation +** interface +** +** Parameters conn_id: connection id (input) +** p_gatt_if: applicaiton interface (output) +** bd_addr: peer device address. (output) +** transport : physical transport of the GATT connection (BR/EDR or LE) +** +** Returns TRUE the ligical link information is found for conn_id +** +*******************************************************************************/ +extern BOOLEAN GATT_GetConnectionInfor(UINT16 conn_id, tGATT_IF *p_gatt_if, + BD_ADDR bd_addr, tBT_TRANSPORT *p_transport); + + +/******************************************************************************* +** +** Function GATT_GetConnIdIfConnected +** +** Description This function find the conn_id if the logical link for BD address +** and applciation interface is connected +** +** Parameters gatt_if: applicaiton interface (input) +** bd_addr: peer device address. (input) +** p_conn_id: connection id (output) +** transport : physical transport of the GATT connection (BR/EDR or LE) +** +** Returns TRUE the ligical link is connected +** +*******************************************************************************/ +extern BOOLEAN GATT_GetConnIdIfConnected(tGATT_IF gatt_if, BD_ADDR bd_addr, + UINT16 *p_conn_id, tBT_TRANSPORT transport); + + +/******************************************************************************* +** +** Function GATT_Listen +** +** Description This function start or stop LE advertisement and listen for +** connection. +** +** Parameters gatt_if: applicaiton interface +** p_bd_addr: listen for specific address connection, or NULL for +** listen to all device connection. +** start: is a direct conenection or a background auto connection +** +** Returns TRUE if advertisement is started; FALSE if adv start failure. +** +*******************************************************************************/ +extern BOOLEAN GATT_Listen (tGATT_IF gatt_if, BOOLEAN start, BD_ADDR_PTR bd_addr); + +/******************************************************************************* +** +** Function GATT_ConfigServiceChangeCCC +** +** Description Configure service change indication on remote device +** +** Returns None. +** +*******************************************************************************/ +extern void GATT_ConfigServiceChangeCCC (BD_ADDR remote_bda, BOOLEAN enable, + tBT_TRANSPORT transport); + +#ifdef __cplusplus + +} +#endif + +#endif /* GATT_API_H */ diff --git a/tools/sdk/include/bluedroid/gatt_int.h b/tools/sdk/include/bluedroid/gatt_int.h new file mode 100644 index 00000000..c9622a24 --- /dev/null +++ b/tools/sdk/include/bluedroid/gatt_int.h @@ -0,0 +1,698 @@ +/****************************************************************************** + * + * Copyright (C) 1999-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. + * + ******************************************************************************/ + +#ifndef GATT_INT_H +#define GATT_INT_H + +#include "bt_target.h" + + +#include "bt_trace.h" +#include "gatt_api.h" +#include "btm_ble_api.h" +#include "btu.h" + +#include + + +#define GATT_CREATE_CONN_ID(tcb_idx, gatt_if) ((UINT16) ((((UINT8)(tcb_idx) ) << 8) | ((UINT8) (gatt_if)))) +#define GATT_GET_TCB_IDX(conn_id) ((UINT8) (((UINT16) (conn_id)) >> 8)) +#define GATT_GET_GATT_IF(conn_id) ((tGATT_IF)((UINT8) (conn_id))) + +#define GATT_GET_SR_REG_PTR(index) (&gatt_cb.sr_reg[(UINT8) (index)]); +#define GATT_TRANS_ID_MAX 0x0fffffff /* 4 MSB is reserved */ +#define GATT_RSP_BY_APP 0x00 +#define GATT_RSP_BY_STACK 0x01 +#define GATT_RSP_DEFAULT GATT_RSP_BY_APP //need to rsp by the app. + +/* security action for GATT write and read request */ +#define GATT_SEC_NONE 0 +#define GATT_SEC_OK 1 +#define GATT_SEC_SIGN_DATA 2 /* compute the signature for the write cmd */ +#define GATT_SEC_ENCRYPT 3 /* encrypt the link with current key */ +#define GATT_SEC_ENCRYPT_NO_MITM 4 /* unauthenticated encryption or better */ +#define GATT_SEC_ENCRYPT_MITM 5 /* authenticated encryption */ +#define GATT_SEC_ENC_PENDING 6 /* wait for link encryption pending */ +typedef UINT8 tGATT_SEC_ACTION; + + +#define GATT_ATTR_OP_SPT_MTU (0x00000001 << 0) +#define GATT_ATTR_OP_SPT_FIND_INFO (0x00000001 << 1) +#define GATT_ATTR_OP_SPT_FIND_BY_TYPE (0x00000001 << 2) +#define GATT_ATTR_OP_SPT_READ_BY_TYPE (0x00000001 << 3) +#define GATT_ATTR_OP_SPT_READ (0x00000001 << 4) +#define GATT_ATTR_OP_SPT_MULT_READ (0x00000001 << 5) +#define GATT_ATTR_OP_SPT_READ_BLOB (0x00000001 << 6) +#define GATT_ATTR_OP_SPT_READ_BY_GRP_TYPE (0x00000001 << 7) +#define GATT_ATTR_OP_SPT_WRITE (0x00000001 << 8) +#define GATT_ATTR_OP_SPT_WRITE_CMD (0x00000001 << 9) +#define GATT_ATTR_OP_SPT_PREP_WRITE (0x00000001 << 10) +#define GATT_ATTR_OP_SPT_EXE_WRITE (0x00000001 << 11) +#define GATT_ATTR_OP_SPT_HDL_VALUE_CONF (0x00000001 << 12) +#define GATT_ATTR_OP_SP_SIGN_WRITE (0x00000001 << 13) + +#define GATT_INDEX_INVALID 0xff + +#define GATT_PENDING_REQ_NONE 0 + + +#define GATT_WRITE_CMD_MASK 0xc0 /*0x1100-0000*/ +#define GATT_AUTH_SIGN_MASK 0x80 /*0x1000-0000*/ +#define GATT_AUTH_SIGN_LEN 12 + +#define GATT_HDR_SIZE 3 /* 1B opcode + 2B handle */ + +/* wait for ATT cmd response timeout value */ +#define GATT_WAIT_FOR_RSP_TOUT 30 +#define GATT_WAIT_FOR_DISC_RSP_TOUT 5 +#define GATT_REQ_RETRY_LIMIT 2 + +/* characteristic descriptor type */ +#define GATT_DESCR_EXT_DSCPTOR 1 /* Characteristic Extended Properties */ +#define GATT_DESCR_USER_DSCPTOR 2 /* Characteristic User Description */ +#define GATT_DESCR_CLT_CONFIG 3 /* Client Characteristic Configuration */ +#define GATT_DESCR_SVR_CONFIG 4 /* Server Characteristic Configuration */ +#define GATT_DESCR_PRES_FORMAT 5 /* Characteristic Presentation Format */ +#define GATT_DESCR_AGGR_FORMAT 6 /* Characteristic Aggregate Format */ +#define GATT_DESCR_VALID_RANGE 7 /* Characteristic Valid Range */ +#define GATT_DESCR_UNKNOWN 0xff + +#define GATT_SEC_FLAG_LKEY_UNAUTHED BTM_SEC_FLAG_LKEY_KNOWN +#define GATT_SEC_FLAG_LKEY_AUTHED BTM_SEC_FLAG_LKEY_AUTHED +#define GATT_SEC_FLAG_ENCRYPTED BTM_SEC_FLAG_ENCRYPTED +typedef UINT8 tGATT_SEC_FLAG; + +/* Find Information Response Type +*/ +#define GATT_INFO_TYPE_PAIR_16 0x01 +#define GATT_INFO_TYPE_PAIR_128 0x02 + +/* GATT client FIND_TYPE_VALUE_Request data */ +typedef struct { + tBT_UUID uuid; /* type of attribute to be found */ + UINT16 s_handle; /* starting handle */ + UINT16 e_handle; /* ending handle */ + UINT16 value_len; /* length of the attribute value */ + UINT8 value[GATT_MAX_MTU_SIZE]; /* pointer to the attribute value to be found */ +} tGATT_FIND_TYPE_VALUE; + +/* client request message to ATT protocol +*/ +typedef union { + tGATT_READ_BY_TYPE browse; /* read by type request */ + tGATT_FIND_TYPE_VALUE find_type_value;/* find by type value */ + tGATT_READ_MULTI read_multi; /* read multiple request */ + tGATT_READ_PARTIAL read_blob; /* read blob */ + tGATT_VALUE attr_value; /* write request */ + /* prepare write */ + /* write blob */ + UINT16 handle; /* read, handle value confirmation */ + UINT16 mtu; + tGATT_EXEC_FLAG exec_write; /* execute write */ +} tGATT_CL_MSG; + +/* error response strucutre */ +typedef struct { + UINT16 handle; + UINT8 cmd_code; + UINT8 reason; +} tGATT_ERROR; + +/* server response message to ATT protocol +*/ +typedef union { + /* data type member event */ + tGATT_VALUE attr_value; /* READ, HANDLE_VALUE_IND, PREPARE_WRITE */ + /* READ_BLOB, READ_BY_TYPE */ + tGATT_ERROR error; /* ERROR_RSP */ + UINT16 handle; /* WRITE, WRITE_BLOB */ + UINT16 mtu; /* exchange MTU request */ +} tGATT_SR_MSG; + +/* Characteristic declaration attribute value +*/ +typedef struct { + tGATT_CHAR_PROP property; + UINT16 char_val_handle; +} tGATT_CHAR_DECL; + +/* attribute value maintained in the server database +*/ +typedef union { + tBT_UUID uuid; /* service declaration */ + tGATT_CHAR_DECL char_decl; /* characteristic declaration */ + tGATT_INCL_SRVC incl_handle; /* included service */ + tGATT_ATTR_VAL attr_val; +} tGATT_ATTR_VALUE; + +/* Attribute UUID type +*/ +#define GATT_ATTR_UUID_TYPE_16 0 +#define GATT_ATTR_UUID_TYPE_128 1 +#define GATT_ATTR_UUID_TYPE_32 2 +typedef UINT8 tGATT_ATTR_UUID_TYPE; + +/* 16 bits UUID Attribute in server database +*/ +typedef struct { + void *p_next; /* pointer to the next attribute, either tGATT_ATTR16 or tGATT_ATTR128 */ + tGATT_ATTR_VALUE *p_value; + tGATT_ATTR_UUID_TYPE uuid_type; + tGATT_PERM permission; + tGATTS_ATTR_CONTROL control; + UINT16 handle; + UINT16 uuid; +} tGATT_ATTR16; + +/* 32 bits UUID Attribute in server database +*/ +typedef struct { + void *p_next; /* pointer to the next attribute, either tGATT_ATTR16, tGATT_ATTR32 or tGATT_ATTR128 */ + tGATT_ATTR_VALUE *p_value; + tGATT_ATTR_UUID_TYPE uuid_type; + tGATT_PERM permission; + tGATTS_ATTR_CONTROL control; + UINT16 handle; + UINT32 uuid; +} tGATT_ATTR32; + + +/* 128 bits UUID Attribute in server database +*/ +typedef struct { + void *p_next; /* pointer to the next attribute, either tGATT_ATTR16 or tGATT_ATTR128 */ + tGATT_ATTR_VALUE *p_value; + tGATT_ATTR_UUID_TYPE uuid_type; + tGATT_PERM permission; + tGATTS_ATTR_CONTROL control; + UINT16 handle; + UINT8 uuid[LEN_UUID_128]; +} tGATT_ATTR128; + +/* Service Database definition +*/ +typedef struct { + void *p_attr_list; /* pointer to the first attribute, either tGATT_ATTR16 or tGATT_ATTR128 */ + UINT8 *p_free_mem; /* Pointer to free memory */ + BUFFER_Q svc_buffer; /* buffer queue used for service database */ + UINT32 mem_free; /* Memory still available */ + UINT16 end_handle; /* Last handle number */ + UINT16 next_handle; /* Next usable handle value */ +} tGATT_SVC_DB; + +/* Data Structure used for GATT server */ +/* A GATT registration record consists of a handle, and 1 or more attributes */ +/* A service registration information record consists of beginning and ending */ +/* attribute handle, service UUID and a set of GATT server callback. */ +typedef struct { + tGATT_SVC_DB *p_db; /* pointer to the service database */ + tBT_UUID app_uuid; /* applicatino UUID */ + UINT32 sdp_handle; /* primamry service SDP handle */ + UINT16 service_instance; /* service instance number */ + UINT16 type; /* service type UUID, primary or secondary */ + UINT16 s_hdl; /* service starting handle */ + UINT16 e_hdl; /* service ending handle */ + tGATT_IF gatt_if; /* this service is belong to which application */ + BOOLEAN in_use; +} tGATT_SR_REG; + +#define GATT_LISTEN_TO_ALL 0xff +#define GATT_LISTEN_TO_NONE 0 + +/* Data Structure used for GATT server */ +/* An GATT registration record consists of a handle, and 1 or more attributes */ +/* A service registration information record consists of beginning and ending */ +/* attribute handle, service UUID and a set of GATT server callback. */ + +typedef struct { + tBT_UUID app_uuid128; + tGATT_CBACK app_cb; + tGATT_IF gatt_if; /* one based */ + BOOLEAN in_use; + UINT8 listening; /* if adv for all has been enabled */ +} tGATT_REG; + + + + +/* command queue for each connection */ +typedef struct { + BT_HDR *p_cmd; + UINT16 clcb_idx; + UINT8 op_code; + BOOLEAN to_send; +} tGATT_CMD_Q; + + +#if GATT_MAX_SR_PROFILES <= 8 +typedef UINT8 tGATT_APP_MASK; +#elif GATT_MAX_SR_PROFILES <= 16 +typedef UINT16 tGATT_APP_MASK; +#elif GATT_MAX_SR_PROFILES <= 32 +typedef UINT32 tGATT_APP_MASK; +#endif + +/* command details for each connection */ +typedef struct { + BT_HDR *p_rsp_msg; + UINT32 trans_id; + tGATT_READ_MULTI multi_req; + BUFFER_Q multi_rsp_q; + UINT16 handle; + UINT8 op_code; + UINT8 status; + UINT8 cback_cnt[GATT_MAX_APPS]; +} tGATT_SR_CMD; + +#define GATT_CH_CLOSE 0 +#define GATT_CH_CLOSING 1 +#define GATT_CH_CONN 2 +#define GATT_CH_CFG 3 +#define GATT_CH_OPEN 4 + +typedef UINT8 tGATT_CH_STATE; + +#define GATT_GATT_START_HANDLE 1 +#define GATT_GAP_START_HANDLE 20 +#define GATT_APP_START_HANDLE 40 + +typedef struct hdl_cfg { + UINT16 gatt_start_hdl; + UINT16 gap_start_hdl; + UINT16 app_start_hdl; +} tGATT_HDL_CFG; + +typedef struct hdl_list_elem { + struct hdl_list_elem *p_next; + struct hdl_list_elem *p_prev; + tGATTS_HNDL_RANGE asgn_range; /* assigned handle range */ + tGATT_SVC_DB svc_db; + BOOLEAN in_use; +} tGATT_HDL_LIST_ELEM; + +typedef struct { + tGATT_HDL_LIST_ELEM *p_first; + tGATT_HDL_LIST_ELEM *p_last; + UINT16 count; +} tGATT_HDL_LIST_INFO; + + +typedef struct srv_list_elem { + struct srv_list_elem *p_next; + struct srv_list_elem *p_prev; + UINT16 s_hdl; + UINT8 i_sreg; + BOOLEAN in_use; + BOOLEAN is_primary; +} tGATT_SRV_LIST_ELEM; + + +typedef struct { + tGATT_SRV_LIST_ELEM *p_last_primary; + tGATT_SRV_LIST_ELEM *p_first; + tGATT_SRV_LIST_ELEM *p_last; + UINT16 count; +} tGATT_SRV_LIST_INFO; + +typedef struct { + BUFFER_Q pending_enc_clcb; /* pending encryption channel q */ + tGATT_SEC_ACTION sec_act; + BD_ADDR peer_bda; + tBT_TRANSPORT transport; + UINT32 trans_id; + + UINT16 att_lcid; /* L2CAP channel ID for ATT */ + UINT16 payload_size; + + tGATT_CH_STATE ch_state; + UINT8 ch_flags; + + tGATT_IF app_hold_link[GATT_MAX_APPS]; + + /* server needs */ + /* server response data */ + tGATT_SR_CMD sr_cmd; + UINT16 indicate_handle; + BUFFER_Q pending_ind_q; + + TIMER_LIST_ENT conf_timer_ent; /* peer confirm to indication timer */ + + UINT8 prep_cnt[GATT_MAX_APPS]; + UINT8 ind_count; + + tGATT_CMD_Q cl_cmd_q[GATT_CL_MAX_LCB]; + TIMER_LIST_ENT ind_ack_timer_ent; /* local app confirm to indication timer */ + UINT8 pending_cl_req; + UINT8 next_slot_inq; /* index of next available slot in queue */ + + BOOLEAN in_use; + UINT8 tcb_idx; +} tGATT_TCB; + + +/* logic channel */ +typedef struct { + UINT16 next_disc_start_hdl; /* starting handle for the next inc srvv discovery */ + tGATT_DISC_RES result; + BOOLEAN wait_for_read_rsp; +} tGATT_READ_INC_UUID128; +typedef struct { + tGATT_TCB *p_tcb; /* associated TCB of this CLCB */ + tGATT_REG *p_reg; /* owner of this CLCB */ + UINT8 sccb_idx; + UINT8 *p_attr_buf; /* attribute buffer for read multiple, prepare write */ + tBT_UUID uuid; + UINT16 conn_id; /* connection handle */ + UINT16 clcb_idx; + UINT16 s_handle; /* starting handle of the active request */ + UINT16 e_handle; /* ending handle of the active request */ + UINT16 counter; /* used as offset, attribute length, num of prepare write */ + UINT16 start_offset; + tGATT_AUTH_REQ auth_req; /* authentication requirement */ + UINT8 operation; /* one logic channel can have one operation active */ + UINT8 op_subtype; /* operation subtype */ + UINT8 status; /* operation status */ + BOOLEAN first_read_blob_after_read; + tGATT_READ_INC_UUID128 read_uuid128; + BOOLEAN in_use; + TIMER_LIST_ENT rsp_timer_ent; /* peer response timer */ + UINT8 retry_count; + +} tGATT_CLCB; + +typedef struct { + tGATT_CLCB *p_clcb; +} tGATT_PENDING_ENC_CLCB; + + +#define GATT_SIGN_WRITE 1 +#define GATT_VERIFY_SIGN_DATA 2 + +typedef struct { + BT_HDR hdr; + tGATT_CLCB *p_clcb; +} tGATT_SIGN_WRITE_OP; + +typedef struct { + BT_HDR hdr; + tGATT_TCB *p_tcb; + BT_HDR *p_data; + +} tGATT_VERIFY_SIGN_OP; + + +typedef struct { + UINT16 clcb_idx; + BOOLEAN in_use; +} tGATT_SCCB; + +typedef struct { + UINT16 handle; + UINT16 uuid; + UINT32 service_change; +} tGATT_SVC_CHG; + +typedef struct { + tGATT_IF gatt_if[GATT_MAX_APPS]; + tGATT_IF listen_gif[GATT_MAX_APPS]; + BD_ADDR remote_bda; + BOOLEAN in_use; +} tGATT_BG_CONN_DEV; + +#define GATT_SVC_CHANGED_CONNECTING 1 /* wait for connection */ +#define GATT_SVC_CHANGED_SERVICE 2 /* GATT service discovery */ +#define GATT_SVC_CHANGED_CHARACTERISTIC 3 /* service change char discovery */ +#define GATT_SVC_CHANGED_DESCRIPTOR 4 /* service change CCC discoery */ +#define GATT_SVC_CHANGED_CONFIGURE_CCCD 5 /* config CCC */ + +typedef struct { + UINT16 conn_id; + BOOLEAN in_use; + BOOLEAN connected; + BD_ADDR bda; + tBT_TRANSPORT transport; + + /* GATT service change CCC related variables */ + UINT8 ccc_stage; + UINT8 ccc_result; + UINT16 s_handle; + UINT16 e_handle; +} tGATT_PROFILE_CLCB; + +typedef struct { + tGATT_TCB tcb[GATT_MAX_PHY_CHANNEL]; + BUFFER_Q sign_op_queue; + + tGATT_SR_REG sr_reg[GATT_MAX_SR_PROFILES]; + UINT16 next_handle; /* next available handle */ + tGATT_SVC_CHG gattp_attr; /* GATT profile attribute service change */ + tGATT_IF gatt_if; + tGATT_HDL_LIST_INFO hdl_list_info; + tGATT_HDL_LIST_ELEM hdl_list[GATT_MAX_SR_PROFILES]; + tGATT_SRV_LIST_INFO srv_list_info; + tGATT_SRV_LIST_ELEM srv_list[GATT_MAX_SR_PROFILES]; + + BUFFER_Q srv_chg_clt_q; /* service change clients queue */ + BUFFER_Q pending_new_srv_start_q; /* pending new service start queue */ + tGATT_REG cl_rcb[GATT_MAX_APPS]; + tGATT_CLCB clcb[GATT_CL_MAX_LCB]; /* connection link control block*/ + tGATT_SCCB sccb[GATT_MAX_SCCB]; /* sign complete callback function GATT_MAX_SCCB <= GATT_CL_MAX_LCB */ + UINT8 trace_level; + UINT16 def_mtu_size; + +#if GATT_CONFORMANCE_TESTING == TRUE + BOOLEAN enable_err_rsp; + UINT8 req_op_code; + UINT8 err_status; + UINT16 handle; +#endif + + tGATT_PROFILE_CLCB profile_clcb[GATT_MAX_APPS]; + UINT16 handle_of_h_r; /* Handle of the handles reused characteristic value */ + + tGATT_APPL_INFO cb_info; + + + + tGATT_HDL_CFG hdl_cfg; + tGATT_BG_CONN_DEV bgconn_dev[GATT_MAX_BG_CONN_DEV]; + +} tGATT_CB; + + +#define GATT_SIZE_OF_SRV_CHG_HNDL_RANGE 4 + +#ifdef __cplusplus +extern "C" { +#endif + +/* Global GATT data */ +#if GATT_DYNAMIC_MEMORY == FALSE +extern tGATT_CB gatt_cb; +#else +extern tGATT_CB *gatt_cb_ptr; +#define gatt_cb (*gatt_cb_ptr) +#endif + +#if GATT_CONFORMANCE_TESTING == TRUE +extern void gatt_set_err_rsp(BOOLEAN enable, UINT8 req_op_code, UINT8 err_status); +#endif + +#ifdef __cplusplus +} +#endif + +/* internal functions */ +extern void gatt_init (void); +extern void gatt_free(void); + +/* from gatt_main.c */ +extern BOOLEAN gatt_disconnect (tGATT_TCB *p_tcb); +extern BOOLEAN gatt_act_connect (tGATT_REG *p_reg, BD_ADDR bd_addr, tBT_TRANSPORT transport); +extern BOOLEAN gatt_connect (BD_ADDR rem_bda, tGATT_TCB *p_tcb, tBT_TRANSPORT transport); +extern void gatt_data_process (tGATT_TCB *p_tcb, BT_HDR *p_buf); +extern void gatt_update_app_use_link_flag ( tGATT_IF gatt_if, tGATT_TCB *p_tcb, BOOLEAN is_add, BOOLEAN check_acl_link); + +extern void gatt_profile_db_init(void); +extern void gatt_set_ch_state(tGATT_TCB *p_tcb, tGATT_CH_STATE ch_state); +extern tGATT_CH_STATE gatt_get_ch_state(tGATT_TCB *p_tcb); +extern void gatt_init_srv_chg(void); +extern void gatt_proc_srv_chg (void); +extern void gatt_send_srv_chg_ind (BD_ADDR peer_bda); +extern void gatt_chk_srv_chg(tGATTS_SRV_CHG *p_srv_chg_clt); +extern void gatt_add_a_bonded_dev_for_srv_chg (BD_ADDR bda); + +/* from gatt_attr.c */ +extern UINT16 gatt_profile_find_conn_id_by_bd_addr(BD_ADDR bda); + + +/* Functions provided by att_protocol.c */ +extern tGATT_STATUS attp_send_cl_msg (tGATT_TCB *p_tcb, UINT16 clcb_idx, UINT8 op_code, tGATT_CL_MSG *p_msg); +extern BT_HDR *attp_build_sr_msg(tGATT_TCB *p_tcb, UINT8 op_code, tGATT_SR_MSG *p_msg); +extern tGATT_STATUS attp_send_sr_msg (tGATT_TCB *p_tcb, BT_HDR *p_msg); +extern tGATT_STATUS attp_send_msg_to_l2cap(tGATT_TCB *p_tcb, BT_HDR *p_toL2CAP); + +/* utility functions */ +extern UINT8 *gatt_dbg_op_name(UINT8 op_code); +extern UINT32 gatt_add_sdp_record (tBT_UUID *p_uuid, UINT16 start_hdl, UINT16 end_hdl); +extern BOOLEAN gatt_parse_uuid_from_cmd(tBT_UUID *p_uuid, UINT16 len, UINT8 **p_data); +extern UINT8 gatt_build_uuid_to_stream(UINT8 **p_dst, tBT_UUID uuid); +extern BOOLEAN gatt_uuid_compare(tBT_UUID src, tBT_UUID tar); +extern void gatt_convert_uuid32_to_uuid128(UINT8 uuid_128[LEN_UUID_128], UINT32 uuid_32); +extern void gatt_sr_get_sec_info(BD_ADDR rem_bda, tBT_TRANSPORT transport, UINT8 *p_sec_flag, UINT8 *p_key_size); +extern void gatt_start_rsp_timer(UINT16 clcb_idx); +extern void gatt_start_conf_timer(tGATT_TCB *p_tcb); +extern void gatt_rsp_timeout(TIMER_LIST_ENT *p_tle); +extern void gatt_ind_ack_timeout(TIMER_LIST_ENT *p_tle); +extern void gatt_start_ind_ack_timer(tGATT_TCB *p_tcb); +extern tGATT_STATUS gatt_send_error_rsp(tGATT_TCB *p_tcb, UINT8 err_code, UINT8 op_code, UINT16 handle, BOOLEAN deq); +extern void gatt_dbg_display_uuid(tBT_UUID bt_uuid); +extern tGATT_PENDING_ENC_CLCB *gatt_add_pending_enc_channel_clcb(tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb ); + +extern tGATTS_PENDING_NEW_SRV_START *gatt_sr_is_new_srv_chg(tBT_UUID *p_app_uuid128, tBT_UUID *p_svc_uuid, UINT16 svc_inst); + +extern BOOLEAN gatt_is_srv_chg_ind_pending (tGATT_TCB *p_tcb); +extern tGATTS_SRV_CHG *gatt_is_bda_in_the_srv_chg_clt_list (BD_ADDR bda); + +extern BOOLEAN gatt_find_the_connected_bda(UINT8 start_idx, BD_ADDR bda, UINT8 *p_found_idx, tBT_TRANSPORT *p_transport); +extern void gatt_set_srv_chg(void); +extern void gatt_delete_dev_from_srv_chg_clt_list(BD_ADDR bd_addr); +extern tGATT_VALUE *gatt_add_pending_ind(tGATT_TCB *p_tcb, tGATT_VALUE *p_ind); +extern tGATTS_PENDING_NEW_SRV_START *gatt_add_pending_new_srv_start( tGATTS_HNDL_RANGE *p_new_srv_start); +extern void gatt_free_srvc_db_buffer_app_id(tBT_UUID *p_app_id); +extern BOOLEAN gatt_update_listen_mode(void); +extern BOOLEAN gatt_cl_send_next_cmd_inq(tGATT_TCB *p_tcb); + +/* reserved handle list */ +extern tGATT_HDL_LIST_ELEM *gatt_find_hdl_buffer_by_app_id (tBT_UUID *p_app_uuid128, tBT_UUID *p_svc_uuid, UINT16 svc_inst); +extern tGATT_HDL_LIST_ELEM *gatt_find_hdl_buffer_by_handle(UINT16 handle); +extern tGATT_HDL_LIST_ELEM *gatt_find_hdl_buffer_by_attr_handle(UINT16 attr_handle); +extern tGATT_HDL_LIST_ELEM *gatt_alloc_hdl_buffer(void); +extern void gatt_free_hdl_buffer(tGATT_HDL_LIST_ELEM *p); +extern BOOLEAN gatt_is_last_attribute(tGATT_SRV_LIST_INFO *p_list, tGATT_SRV_LIST_ELEM *p_start, tBT_UUID value); +extern void gatt_update_last_pri_srv_info(tGATT_SRV_LIST_INFO *p_list); +extern BOOLEAN gatt_add_a_srv_to_list(tGATT_SRV_LIST_INFO *p_list, tGATT_SRV_LIST_ELEM *p_new); +extern BOOLEAN gatt_remove_a_srv_from_list(tGATT_SRV_LIST_INFO *p_list, tGATT_SRV_LIST_ELEM *p_remove); +extern BOOLEAN gatt_add_an_item_to_list(tGATT_HDL_LIST_INFO *p_list, tGATT_HDL_LIST_ELEM *p_new); +extern BOOLEAN gatt_remove_an_item_from_list(tGATT_HDL_LIST_INFO *p_list, tGATT_HDL_LIST_ELEM *p_remove); +extern tGATTS_SRV_CHG *gatt_add_srv_chg_clt(tGATTS_SRV_CHG *p_srv_chg); + +/* for background connection */ +extern BOOLEAN gatt_update_auto_connect_dev (tGATT_IF gatt_if, BOOLEAN add, BD_ADDR bd_addr, BOOLEAN is_initiator); +extern BOOLEAN gatt_is_bg_dev_for_app(tGATT_BG_CONN_DEV *p_dev, tGATT_IF gatt_if); +extern BOOLEAN gatt_remove_bg_dev_for_app(tGATT_IF gatt_if, BD_ADDR bd_addr); +extern UINT8 gatt_get_num_apps_for_bg_dev(BD_ADDR bd_addr); +extern BOOLEAN gatt_find_app_for_bg_dev(BD_ADDR bd_addr, tGATT_IF *p_gatt_if); +extern tGATT_BG_CONN_DEV *gatt_find_bg_dev(BD_ADDR remote_bda); +extern void gatt_deregister_bgdev_list(tGATT_IF gatt_if); +extern void gatt_reset_bgdev_list(void); + +/* server function */ +extern UINT8 gatt_sr_find_i_rcb_by_handle(UINT16 handle); +extern UINT8 gatt_sr_find_i_rcb_by_app_id(tBT_UUID *p_app_uuid128, tBT_UUID *p_svc_uuid, UINT16 svc_inst); +extern UINT8 gatt_sr_alloc_rcb(tGATT_HDL_LIST_ELEM *p_list); +extern tGATT_STATUS gatt_sr_process_app_rsp (tGATT_TCB *p_tcb, tGATT_IF gatt_if, UINT32 trans_id, UINT8 op_code, tGATT_STATUS status, tGATTS_RSP *p_msg); +extern void gatt_server_handle_client_req (tGATT_TCB *p_tcb, UINT8 op_code, + UINT16 len, UINT8 *p_data); +extern void gatt_sr_send_req_callback(UINT16 conn_id, UINT32 trans_id, + UINT8 op_code, tGATTS_DATA *p_req_data); +extern UINT32 gatt_sr_enqueue_cmd (tGATT_TCB *p_tcb, UINT8 op_code, UINT16 handle); +extern BOOLEAN gatt_cancel_open(tGATT_IF gatt_if, BD_ADDR bda); + +/* */ + +extern tGATT_REG *gatt_get_regcb (tGATT_IF gatt_if); +extern BOOLEAN gatt_is_clcb_allocated (UINT16 conn_id); +extern tGATT_CLCB *gatt_clcb_alloc (UINT16 conn_id); +extern void gatt_clcb_dealloc (tGATT_CLCB *p_clcb); + +extern void gatt_sr_copy_prep_cnt_to_cback_cnt(tGATT_TCB *p_tcb ); +extern BOOLEAN gatt_sr_is_cback_cnt_zero(tGATT_TCB *p_tcb ); +extern BOOLEAN gatt_sr_is_prep_cnt_zero(tGATT_TCB *p_tcb ); +extern void gatt_sr_reset_cback_cnt(tGATT_TCB *p_tcb ); +extern void gatt_sr_reset_prep_cnt(tGATT_TCB *p_tcb ); +extern void gatt_sr_update_cback_cnt(tGATT_TCB *p_tcb, tGATT_IF gatt_if, BOOLEAN is_inc, BOOLEAN is_reset_first); +extern void gatt_sr_update_prep_cnt(tGATT_TCB *p_tcb, tGATT_IF gatt_if, BOOLEAN is_inc, BOOLEAN is_reset_first); + +extern BOOLEAN gatt_find_app_hold_link(tGATT_TCB *p_tcb, UINT8 start_idx, UINT8 *p_found_idx, tGATT_IF *p_gatt_if); +extern UINT8 gatt_num_apps_hold_link(tGATT_TCB *p_tcb); +extern UINT8 gatt_num_clcb_by_bd_addr(BD_ADDR bda); +extern tGATT_TCB *gatt_find_tcb_by_cid(UINT16 lcid); +extern tGATT_TCB *gatt_allocate_tcb_by_bdaddr(BD_ADDR bda, tBT_TRANSPORT transport); +extern tGATT_TCB *gatt_get_tcb_by_idx(UINT8 tcb_idx); +extern tGATT_TCB *gatt_find_tcb_by_addr(BD_ADDR bda, tBT_TRANSPORT transport); +extern BOOLEAN gatt_send_ble_burst_data (BD_ADDR remote_bda, BT_HDR *p_buf); + +/* GATT client functions */ +extern void gatt_dequeue_sr_cmd (tGATT_TCB *p_tcb); +extern UINT8 gatt_send_write_msg(tGATT_TCB *p_tcb, UINT16 clcb_idx, UINT8 op_code, UINT16 handle, + UINT16 len, UINT16 offset, UINT8 *p_data); +extern void gatt_cleanup_upon_disc(BD_ADDR bda, UINT16 reason, tBT_TRANSPORT transport); +extern void gatt_end_operation(tGATT_CLCB *p_clcb, tGATT_STATUS status, void *p_data); + +extern void gatt_act_discovery(tGATT_CLCB *p_clcb); +extern void gatt_act_read(tGATT_CLCB *p_clcb, UINT16 offset); +extern void gatt_act_write(tGATT_CLCB *p_clcb, UINT8 sec_act); +extern UINT8 gatt_act_send_browse(tGATT_TCB *p_tcb, UINT16 index, UINT8 op, UINT16 s_handle, UINT16 e_handle, + tBT_UUID uuid); +extern tGATT_CLCB *gatt_cmd_dequeue(tGATT_TCB *p_tcb, UINT8 *p_opcode); +extern BOOLEAN gatt_cmd_enq(tGATT_TCB *p_tcb, UINT16 clcb_idx, BOOLEAN to_send, UINT8 op_code, BT_HDR *p_buf); +extern void gatt_client_handle_server_rsp (tGATT_TCB *p_tcb, UINT8 op_code, + UINT16 len, UINT8 *p_data); +extern void gatt_send_queue_write_cancel (tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, tGATT_EXEC_FLAG flag); + +/* gatt_auth.c */ +extern BOOLEAN gatt_security_check_start(tGATT_CLCB *p_clcb); +extern void gatt_verify_signature(tGATT_TCB *p_tcb, BT_HDR *p_buf); +extern tGATT_SEC_ACTION gatt_determine_sec_act(tGATT_CLCB *p_clcb ); +extern tGATT_STATUS gatt_get_link_encrypt_status(tGATT_TCB *p_tcb); +extern tGATT_SEC_ACTION gatt_get_sec_act(tGATT_TCB *p_tcb); +extern void gatt_set_sec_act(tGATT_TCB *p_tcb, tGATT_SEC_ACTION sec_act); + +/* gatt_db.c */ +extern BOOLEAN gatts_init_service_db (tGATT_SVC_DB *p_db, tBT_UUID *p_service, BOOLEAN is_pri, UINT16 s_hdl, UINT16 num_handle); +extern UINT16 gatts_add_included_service (tGATT_SVC_DB *p_db, UINT16 s_handle, UINT16 e_handle, tBT_UUID service); +extern UINT16 gatts_add_characteristic (tGATT_SVC_DB *p_db, tGATT_PERM perm, + tGATT_CHAR_PROP property, + tBT_UUID *p_char_uuid, tGATT_ATTR_VAL *attr_val, + tGATTS_ATTR_CONTROL *control); +extern UINT16 gatts_add_char_descr (tGATT_SVC_DB *p_db, tGATT_PERM perm, + tBT_UUID *p_dscp_uuid, tGATT_ATTR_VAL *attr_val, + tGATTS_ATTR_CONTROL *control); + +extern tGATT_STATUS gatts_set_attribute_value(tGATT_SVC_DB *p_db, UINT16 attr_handle, + UINT16 length, UINT8 *value); + +extern tGATT_STATUS gatts_get_attribute_value(tGATT_SVC_DB *p_db, UINT16 attr_handle, + UINT16 *length, UINT8 **value); +extern BOOLEAN gatts_is_auto_response(UINT16 attr_handle); +extern tGATT_STATUS gatts_db_read_attr_value_by_type (tGATT_TCB *p_tcb, tGATT_SVC_DB *p_db, UINT8 op_code, BT_HDR *p_rsp, UINT16 s_handle, + UINT16 e_handle, tBT_UUID type, UINT16 *p_len, tGATT_SEC_FLAG sec_flag, UINT8 key_size, UINT32 trans_id, UINT16 *p_cur_handle); +extern tGATT_STATUS gatts_read_attr_value_by_handle(tGATT_TCB *p_tcb, tGATT_SVC_DB *p_db, UINT8 op_code, UINT16 handle, UINT16 offset, + UINT8 *p_value, UINT16 *p_len, UINT16 mtu, tGATT_SEC_FLAG sec_flag, UINT8 key_size, UINT32 trans_id); +extern tGATT_STATUS gatts_write_attr_value_by_handle(tGATT_SVC_DB *p_db, + UINT16 handle, UINT16 offset, + UINT8 *p_value, UINT16 len); +extern tGATT_STATUS gatts_write_attr_perm_check (tGATT_SVC_DB *p_db, UINT8 op_code, UINT16 handle, UINT16 offset, UINT8 *p_data, + UINT16 len, tGATT_SEC_FLAG sec_flag, UINT8 key_size); +extern tGATT_STATUS gatts_read_attr_perm_check(tGATT_SVC_DB *p_db, BOOLEAN is_long, UINT16 handle, tGATT_SEC_FLAG sec_flag, UINT8 key_size); +extern void gatts_update_srv_list_elem(UINT8 i_sreg, UINT16 handle, BOOLEAN is_primary); +extern tBT_UUID *gatts_get_service_uuid (tGATT_SVC_DB *p_db); + +extern void gatt_reset_bgdev_list(void); +#endif diff --git a/tools/sdk/include/bluedroid/gattdefs.h b/tools/sdk/include/bluedroid/gattdefs.h new file mode 100644 index 00000000..9380e2e9 --- /dev/null +++ b/tools/sdk/include/bluedroid/gattdefs.h @@ -0,0 +1,124 @@ +/****************************************************************************** + * + * Copyright (C) 1999-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 file contains internally used ATT definitions + * + ******************************************************************************/ + +#ifndef _GATTDEFS_H +#define _GATTDEFS_H + +#define GATT_ILLEGAL_UUID 0 + +/* GATT attribute types +*/ +#define GATT_UUID_PRI_SERVICE 0x2800 +#define GATT_UUID_SEC_SERVICE 0x2801 +#define GATT_UUID_INCLUDE_SERVICE 0x2802 +#define GATT_UUID_CHAR_DECLARE 0x2803 /* Characteristic Declaration*/ + +#define GATT_UUID_CHAR_EXT_PROP 0x2900 /* Characteristic Extended Properties */ +#define GATT_UUID_CHAR_DESCRIPTION 0x2901 /* Characteristic User Description*/ +#define GATT_UUID_CHAR_CLIENT_CONFIG 0x2902 /* Client Characteristic Configuration */ +#define GATT_UUID_CHAR_SRVR_CONFIG 0x2903 /* Server Characteristic Configuration */ +#define GATT_UUID_CHAR_PRESENT_FORMAT 0x2904 /* Characteristic Presentation Format*/ +#define GATT_UUID_CHAR_AGG_FORMAT 0x2905 /* Characteristic Aggregate Format*/ +#define GATT_UUID_CHAR_VALID_RANGE 0x2906 /* Characteristic Valid Range */ +#define GATT_UUID_EXT_RPT_REF_DESCR 0x2907 +#define GATT_UUID_RPT_REF_DESCR 0x2908 + + +/* GAP Profile Attributes +*/ +#define GATT_UUID_GAP_DEVICE_NAME 0x2A00 +#define GATT_UUID_GAP_ICON 0x2A01 +#define GATT_UUID_GAP_PREF_CONN_PARAM 0x2A04 +#define GATT_UUID_GAP_CENTRAL_ADDR_RESOL 0x2AA6 + +/* Attribute Profile Attribute UUID */ +#define GATT_UUID_GATT_SRV_CHGD 0x2A05 +/* Attribute Protocol Test */ + +/* Link Loss Service */ +#define GATT_UUID_ALERT_LEVEL 0x2A06 /* Alert Level */ +#define GATT_UUID_TX_POWER_LEVEL 0x2A07 /* TX power level */ + +/* Time Profile */ +/* Current Time Service */ +#define GATT_UUID_CURRENT_TIME 0x2A2B /* Current Time */ +#define GATT_UUID_LOCAL_TIME_INFO 0x2A0F /* Local time info */ +#define GATT_UUID_REF_TIME_INFO 0x2A14 /* reference time information */ + +/* NwA Profile */ +#define GATT_UUID_NW_STATUS 0x2A18 /* network availability status */ +#define GATT_UUID_NW_TRIGGER 0x2A1A /* Network availability trigger */ + +/* phone alert */ +#define GATT_UUID_ALERT_STATUS 0x2A3F /* alert status */ +#define GATT_UUID_RINGER_CP 0x2A40 /* ringer control point */ +#define GATT_UUID_RINGER_SETTING 0x2A41 /* ringer setting */ + +/* Glucose Service */ +#define GATT_UUID_GM_MEASUREMENT 0x2A18 +#define GATT_UUID_GM_CONTEXT 0x2A34 +#define GATT_UUID_GM_CONTROL_POINT 0x2A52 +#define GATT_UUID_GM_FEATURE 0x2A51 + +/* device infor characteristic */ +#define GATT_UUID_SYSTEM_ID 0x2A23 +#define GATT_UUID_MODEL_NUMBER_STR 0x2A24 +#define GATT_UUID_SERIAL_NUMBER_STR 0x2A25 +#define GATT_UUID_FW_VERSION_STR 0x2A26 +#define GATT_UUID_HW_VERSION_STR 0x2A27 +#define GATT_UUID_SW_VERSION_STR 0x2A28 +#define GATT_UUID_MANU_NAME 0x2A29 +#define GATT_UUID_IEEE_DATA 0x2A2A +#define GATT_UUID_PNP_ID 0x2A50 + +/* HID characteristics */ +#define GATT_UUID_HID_INFORMATION 0x2A4A +#define GATT_UUID_HID_REPORT_MAP 0x2A4B +#define GATT_UUID_HID_CONTROL_POINT 0x2A4C +#define GATT_UUID_HID_REPORT 0x2A4D +#define GATT_UUID_HID_PROTO_MODE 0x2A4E +#define GATT_UUID_HID_BT_KB_INPUT 0x2A22 +#define GATT_UUID_HID_BT_KB_OUTPUT 0x2A32 +#define GATT_UUID_HID_BT_MOUSE_INPUT 0x2A33 + +/* Battery Service char */ +#define GATT_UUID_BATTERY_LEVEL 0x2A19 + +#define GATT_UUID_SC_CONTROL_POINT 0x2A55 +#define GATT_UUID_SENSOR_LOCATION 0x2A5D + +/* RUNNERS SPEED AND CADENCE SERVICE */ +#define GATT_UUID_RSC_MEASUREMENT 0x2A53 +#define GATT_UUID_RSC_FEATURE 0x2A54 + +/* CYCLING SPEED AND CADENCE SERVICE */ +#define GATT_UUID_CSC_MEASUREMENT 0x2A5B +#define GATT_UUID_CSC_FEATURE 0x2A5C + + +/* Scan Parameter charatceristics */ +#define GATT_UUID_SCAN_INT_WINDOW 0x2A4F +#define GATT_UUID_SCAN_REFRESH 0x2A31 + +#endif diff --git a/tools/sdk/include/bluedroid/gki.h b/tools/sdk/include/bluedroid/gki.h new file mode 100644 index 00000000..4e5f3c2b --- /dev/null +++ b/tools/sdk/include/bluedroid/gki.h @@ -0,0 +1,132 @@ +/****************************************************************************** + * + * Copyright (C) 1999-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. + * + ******************************************************************************/ + +#ifndef _GKI_H_ +#define _GKI_H_ + +#include "bt_target.h" +#include "bt_types.h" +#include "gki_common.h" +#include "gki_int.h" +#include "allocator.h" + +#define ALIGN_POOL(pl_size) ( (((pl_size) + 3) / sizeof(UINT32)) * sizeof(UINT32)) +#define BUFFER_HDR_SIZE (sizeof(BUFFER_HDR_T)) /* Offset past header */ +#define BUFFER_PADDING_SIZE (sizeof(BUFFER_HDR_T) + sizeof(UINT32)) /* Header + Magic Number */ +#define MAGIC_NO 0xDDBADDBA + +#define BUF_STATUS_FREE 0 +#define BUF_STATUS_UNLINKED 1 +#define BUF_STATUS_QUEUED 2 + +/* Timer list entry callback type +*/ +typedef void (TIMER_CBACK)(void *p_tle); +#ifndef TIMER_PARAM_TYPE +#define TIMER_PARAM_TYPE UINT32 +#endif +/* Define a timer list entry +*/ +typedef struct _tle { + struct _tle *p_next; + struct _tle *p_prev; + TIMER_CBACK *p_cback; + INT32 ticks; + INT32 ticks_initial; + TIMER_PARAM_TYPE param; + TIMER_PARAM_TYPE data; + UINT16 event; + UINT8 in_use; +} TIMER_LIST_ENT; + +/*********************************************************************** +** This queue is a general purpose buffer queue, for application use. +*/ +typedef struct { + void *_p_first; + void *_p_last; + UINT16 _count; +} BUFFER_Q; + +#define GKI_PUBLIC_POOL 0 /* General pool accessible to GKI_getbuf() */ +#define GKI_RESTRICTED_POOL 1 /* Inaccessible pool to GKI_getbuf() */ + +/*********************************************************************** +** Function prototypes +*/ + +/* To get and release buffers, change owner and get size +*/ +void *GKI_getbuf_func(UINT16); +void *GKI_getpoolbuf_func(UINT8); +void GKI_freebuf(void *); +UINT16 GKI_get_buf_size (void *); +void *GKI_getpoolbuf (UINT8); +UINT16 GKI_poolcount (UINT8); +UINT16 GKI_poolfreecount (UINT8); +UINT16 GKI_poolutilization (UINT8); + +#ifdef CONFIG_BLUEDROID_MEM_DEBUG + +#define GKI_getbuf(_size) \ +({ \ + BUFFER_HDR_T *header = osi_malloc((_size) + BUFFER_HDR_SIZE); \ + header->status = BUF_STATUS_UNLINKED; \ + header->p_next = NULL; \ + header->Type = 0; \ + header->size = (_size); \ + (void *)(header + 1); \ +}) + +#define GKI_getpoolbuf(_pool_id) \ +({ \ + (void *)GKI_getbuf(gki_cb.com.pool_size[(_pool_id)]); \ +}) + +#else +#define GKI_getbuf GKI_getbuf_func +#define GKI_getpoolbuf GKI_getpoolbuf_func + +#endif /* CONFIG_BLUEDROID_MEM_DEBUG */ + +/* User buffer queue management +*/ +void *GKI_dequeue (BUFFER_Q *); +void GKI_enqueue (BUFFER_Q *, void *); +void *GKI_getfirst (BUFFER_Q *); +void *GKI_getlast (BUFFER_Q *); +void *GKI_getnext (void *); +void GKI_init_q (BUFFER_Q *); +UINT16 GKI_queue_length(BUFFER_Q *); +BOOLEAN GKI_queue_is_empty(BUFFER_Q *); +void *GKI_remove_from_queue (BUFFER_Q *, void *); +UINT16 GKI_get_pool_bufsize (UINT8); + +/* Timer management +*/ +void GKI_delay(UINT32); + +/* Disable Interrupts, Enable Interrupts +*/ +void GKI_enable(void); +void GKI_disable(void); + +/* os timer operation */ +UINT32 GKI_get_os_tick_count(void); + +#endif /*_GKI_H_*/ diff --git a/tools/sdk/include/bluedroid/gki_common.h b/tools/sdk/include/bluedroid/gki_common.h new file mode 100644 index 00000000..838896ee --- /dev/null +++ b/tools/sdk/include/bluedroid/gki_common.h @@ -0,0 +1,65 @@ +/****************************************************************************** + * + * Copyright (C) 1999-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. + * + ******************************************************************************/ + +#ifndef _GKI_COMMON_H_ +#define _GKI_COMMON_H_ + +#include "gki.h" + +typedef struct _buffer_hdr { + struct _buffer_hdr *p_next; /* next buffer in the queue */ + UINT8 q_id; /* id of the queue */ + UINT8 status; /* FREE, UNLINKED or QUEUED */ + UINT8 Type; + UINT16 size; +} BUFFER_HDR_T; + +typedef struct _free_queue { + BUFFER_HDR_T *_p_first; /* first buffer in the queue */ + BUFFER_HDR_T *_p_last; /* last buffer in the queue */ + UINT16 size; /* size of the buffers in the pool */ + UINT16 total; /* toatal number of buffers */ + UINT16 cur_cnt; /* number of buffers currently allocated */ + UINT16 max_cnt; /* maximum number of buffers allocated at any time */ +} FREE_QUEUE_T; + +/* Put all GKI variables into one control block +*/ +typedef struct { + /* Define the buffer pool management variables + */ + FREE_QUEUE_T freeq[GKI_NUM_TOTAL_BUF_POOLS]; + + UINT16 pool_buf_size[GKI_NUM_TOTAL_BUF_POOLS]; + + /* Define the buffer pool start addresses + */ + UINT8 *pool_start[GKI_NUM_TOTAL_BUF_POOLS]; /* array of pointers to the start of each buffer pool */ + UINT8 *pool_end[GKI_NUM_TOTAL_BUF_POOLS]; /* array of pointers to the end of each buffer pool */ + UINT16 pool_size[GKI_NUM_TOTAL_BUF_POOLS]; /* actual size of the buffers in a pool */ + + /* Define the buffer pool access control variables */ + UINT16 pool_access_mask; /* Bits are set if the corresponding buffer pool is a restricted pool */ +} tGKI_COM_CB; + +/* Internal GKI function prototypes +*/ +void gki_buffer_init(void); +void gki_buffer_cleanup(void); + +#endif /*_GKI_COMMON_H_*/ diff --git a/tools/sdk/include/bluedroid/gki_int.h b/tools/sdk/include/bluedroid/gki_int.h new file mode 100644 index 00000000..3307066e --- /dev/null +++ b/tools/sdk/include/bluedroid/gki_int.h @@ -0,0 +1,34 @@ +/****************************************************************************** + * + * Copyright (C) 1999-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. + * + ******************************************************************************/ + +#ifndef _GKI_INT_H_ +#define _GKI_INT_H_ + +//#include +#include "bt_defs.h" + +#include "gki_common.h" + +typedef struct { + pthread_mutex_t lock; + tGKI_COM_CB com; +} tGKI_CB; + +extern tGKI_CB gki_cb; + +#endif /*_GKI_INT_H_*/ diff --git a/tools/sdk/include/bluedroid/gki_target.h b/tools/sdk/include/bluedroid/gki_target.h new file mode 100755 index 00000000..fc844518 --- /dev/null +++ b/tools/sdk/include/bluedroid/gki_target.h @@ -0,0 +1,244 @@ +/****************************************************************************** + * + * Copyright (C) 1999-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. + * + ******************************************************************************/ + +#ifndef _GKI_TARGET_H_ +#define _GKI_TARGET_H_ + +/****************************************************************************** +** +** Buffer configuration +** +******************************************************************************/ + +/* The size of the buffers in pool 0. */ +#ifndef GKI_BUF0_SIZE +#define GKI_BUF0_SIZE 64 +#endif + +/* The number of buffers in buffer pool 0. */ +#ifndef GKI_BUF0_MAX +#define GKI_BUF0_MAX 96 +#endif + +/* The ID of buffer pool 0. */ +#ifndef GKI_POOL_ID_0 +#define GKI_POOL_ID_0 0 +#endif + +/* The size of the buffers in pool 1. */ +#ifndef GKI_BUF1_SIZE +#define GKI_BUF1_SIZE 288 +#endif + +/* The number of buffers in buffer pool 1. */ +#ifndef GKI_BUF1_MAX +#define GKI_BUF1_MAX 52 +#endif + +/* The ID of buffer pool 1. */ +#ifndef GKI_POOL_ID_1 +#define GKI_POOL_ID_1 1 +#endif + +/* The size of the buffers in pool 2. */ +#ifndef GKI_BUF2_SIZE +#define GKI_BUF2_SIZE 660 +#endif + +/* The number of buffers in buffer pool 2. */ +#ifndef GKI_BUF2_MAX +#define GKI_BUF2_MAX 90 +#endif + +/* The ID of buffer pool 2. */ +#ifndef GKI_POOL_ID_2 +#define GKI_POOL_ID_2 2 +#endif + +/* The size of the buffers in pool 3. */ +#ifndef GKI_BUF3_SIZE +#define GKI_BUF3_SIZE (4096+16) +#endif + +/* The number of buffers in buffer pool 3. */ +#ifndef GKI_BUF3_MAX +#define GKI_BUF3_MAX 400 +#endif + +/* The ID of buffer pool 3. */ +#ifndef GKI_POOL_ID_3 +#define GKI_POOL_ID_3 3 +#endif + +/* The size of the largest PUBLIC fixed buffer in system. */ +#ifndef GKI_MAX_BUF_SIZE +#define GKI_MAX_BUF_SIZE GKI_BUF3_SIZE +#endif + +/* The pool ID of the largest PUBLIC fixed buffer in system. */ +#ifndef GKI_MAX_BUF_SIZE_POOL_ID +#define GKI_MAX_BUF_SIZE_POOL_ID GKI_POOL_ID_3 +#endif + +/* Pool 4 is used for BluetoothSocket L2CAP connections */ +/* The size of the buffers in pool 4. */ +#ifndef GKI_BUF4_SIZE +#define GKI_BUF4_SIZE (8080+26) +#endif + +/* The number of buffers in buffer pool 4. */ +#ifndef GKI_BUF4_MAX +#define GKI_BUF4_MAX (OBX_NUM_SERVERS + OBX_NUM_CLIENTS) +#endif + +/* The ID of buffer pool 4. */ +#ifndef GKI_POOL_ID_4 +#define GKI_POOL_ID_4 4 +#endif + +/* The number of fixed GKI buffer pools. +eL2CAP requires Pool ID 5 +If BTM_SCO_HCI_INCLUDED is FALSE, Pool ID 6 is unnecessary, otherwise set to 7 +If BTA_HL_INCLUDED is FALSE then Pool ID 7 is uncessary and set the following to 7, otherwise set to 8 +If BLE_INCLUDED is FALSE then Pool ID 8 is uncessary and set the following to 8, otherwise set to 9 +POOL_ID 9 is a public pool meant for large buffer needs such as SDP_DB +*/ +#ifndef GKI_NUM_FIXED_BUF_POOLS +#define GKI_NUM_FIXED_BUF_POOLS 10 +#endif + +/* The buffer pool usage mask. */ +#ifndef GKI_DEF_BUFPOOL_PERM_MASK +/* Setting POOL_ID 9 as a public pool meant for large buffers such as SDP_DB */ +#define GKI_DEF_BUFPOOL_PERM_MASK 0xfdf0 +#endif + +/* The following is intended to be a reserved pool for L2CAP +Flow control and retransmissions and intentionally kept out +of order */ + +/* The number of buffers in buffer pool 5. */ +#ifndef GKI_BUF5_MAX +#define GKI_BUF5_MAX 64 +#endif + +/* The ID of buffer pool 5. */ +#ifndef GKI_POOL_ID_5 +#define GKI_POOL_ID_5 5 +#endif + +/* The size of the buffers in pool 5 +** Special pool used by L2CAP retransmissions only. This size based on segment +** that will fit into both DH5 and 2-DH3 packet types after accounting for GKI +** header. 13 bytes of max headers allows us a 339 payload max. (in btui_app.txt) +** Note: 748 used for insight scriptwrapper with CAT-2 scripts. +*/ +#ifndef GKI_BUF5_SIZE +#define GKI_BUF5_SIZE 748 +#endif + +/* The following is intended to be a reserved pool for SCO +over HCI data and intentionally kept out of order */ + +/* The ID of buffer pool 6. */ +#ifndef GKI_POOL_ID_6 +#define GKI_POOL_ID_6 6 +#endif + +/* The size of the buffers in pool 6, + BUF_SIZE = max SCO data 255 + sizeof(BT_HDR) = 8 + SCO packet header 3 + padding 2 = 268 */ +#ifndef GKI_BUF6_SIZE +#define GKI_BUF6_SIZE 268 +#endif + +/* The number of buffers in buffer pool 6. */ +#ifndef GKI_BUF6_MAX +#define GKI_BUF6_MAX 60 +#endif + + +/* The following pool is a dedicated pool for HDP + If a shared pool is more desirable then + 1. set BTA_HL_LRG_DATA_POOL_ID to the desired Gki Pool ID + 2. make sure that the shared pool size is larger than 9472 + 3. adjust GKI_NUM_FIXED_BUF_POOLS accordingly since + POOL ID 7 is not needed +*/ + +/* The ID of buffer pool 7. */ +#ifndef GKI_POOL_ID_7 +#define GKI_POOL_ID_7 7 +#endif + +/* The size of the buffers in pool 7 */ +#ifndef GKI_BUF7_SIZE +#define GKI_BUF7_SIZE (10240 + 24) +#endif + +/* The number of buffers in buffer pool 7. */ +#ifndef GKI_BUF7_MAX +#define GKI_BUF7_MAX 2 +#endif + +/* The following pool is a dedicated pool for GATT + If a shared pool is more desirable then + 1. set GATT_DB_POOL_ID to the desired Gki Pool ID + 2. make sure that the shared pool size fit a common GATT database needs + 3. adjust GKI_NUM_FIXED_BUF_POOLS accordingly since + POOL ID 8 is not needed +*/ + +/* The ID of buffer pool 8. */ +#ifndef GKI_POOL_ID_8 +#define GKI_POOL_ID_8 8 +#endif + +/* The size of the buffers in pool 8 */ +#ifndef GKI_BUF8_SIZE +#define GKI_BUF8_SIZE 128 +#endif + +/* The number of buffers in buffer pool 8. */ +#ifndef GKI_BUF8_MAX +#define GKI_BUF8_MAX 30 +#endif + +/* The following pool is meant for large allocations such as SDP_DB */ +#ifndef GKI_POOL_ID_9 +#define GKI_POOL_ID_9 9 +#endif + +#ifndef GKI_BUF9_SIZE +#define GKI_BUF9_SIZE 8192 +#endif + +#ifndef GKI_BUF9_MAX +#define GKI_BUF9_MAX 5 +#endif + +/* The number of fixed and dynamic buffer pools */ +#ifndef GKI_NUM_TOTAL_BUF_POOLS +#define GKI_NUM_TOTAL_BUF_POOLS 10 +#endif + +int gki_init(void); +void gki_clean_up(void); + +//void LogMsg (UINT32 trace_set_mask, const char *fmt_str, ...); + +#endif /*_GKI_TARGET_H_*/ diff --git a/tools/sdk/include/bluedroid/hash_functions.h b/tools/sdk/include/bluedroid/hash_functions.h new file mode 100755 index 00000000..2edbeb8b --- /dev/null +++ b/tools/sdk/include/bluedroid/hash_functions.h @@ -0,0 +1,33 @@ +/****************************************************************************** + * + * 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 _HASH_FUNCTIONS_H_ +#define _HASH_FUNCTIONS_H_ + +#include "hash_map.h" + +hash_index_t hash_function_naive(const void *key); + +hash_index_t hash_function_integer(const void *key); + +// Hashes a pointer based only on its address value +hash_index_t hash_function_pointer(const void *key); + +hash_index_t hash_function_string(const void *key); + +#endif /* _HASH_FUNCTIONS_H_ */ diff --git a/tools/sdk/include/bluedroid/hash_map.h b/tools/sdk/include/bluedroid/hash_map.h new file mode 100644 index 00000000..fea1e021 --- /dev/null +++ b/tools/sdk/include/bluedroid/hash_map.h @@ -0,0 +1,110 @@ +/****************************************************************************** + * + * 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 _HASH_MAP_H_ +#define _HASH_MAP_H_ + +#include +#include + +struct hash_map_t; +typedef struct hash_map_t hash_map_t; + +typedef struct hash_map_entry_t { + const void *key; + void *data; + const hash_map_t *hash_map; +} hash_map_entry_t; + +typedef size_t hash_index_t; + +// Takes a key structure and returns a hash value. +typedef hash_index_t (*hash_index_fn)(const void *key); +typedef bool (*hash_map_iter_cb)(hash_map_entry_t *hash_entry, void *context); + +typedef bool (*key_equality_fn)(const void *x, const void *y); + +typedef void (*key_free_fn)(void *data); +typedef void (*data_free_fn)(void *data); + +// Returns a new, empty hash_map. Returns NULL if not enough memory could be allocated +// for the hash_map structure. The returned hash_map must be freed with |hash_map_free|. +// The |num_bucket| specifies the number of hashable buckets for the map and must not +// be zero. The |hash_fn| specifies a hash function to be used and must not be NULL. +// The |key_fn| and |data_fn| are called whenever a hash_map element is removed from +// the hash_map. They can be used to release resources held by the hash_map element, +// e.g. memory or file descriptor. |key_fn| and |data_fn| may be NULL if no cleanup +// is necessary on element removal. |equality_fn| is used to check for key equality. +// If |equality_fn| is NULL, default pointer equality is used. +hash_map_t *hash_map_new( + size_t size, + hash_index_fn hash_fn, + key_free_fn key_fn, + data_free_fn data_fn, + key_equality_fn equality_fn); + +// Frees the hash_map. This function accepts NULL as an argument, in which case it +// behaves like a no-op. +void hash_map_free(hash_map_t *hash_map); + +// Returns true if the hash_map is empty (has no elements), false otherwise. +// Note that a NULL |hash_map| is not the same as an empty |hash_map|. This function +// does not accept a NULL |hash_map|. +//bool hash_map_is_empty(const hash_map_t *hash_map); + +// Returns the number of elements in the hash map. This function does not accept a +// NULL |hash_map|. +//size_t hash_map_size(const hash_map_t *hash_map); + +// Returns the number of buckets in the hash map. This function does not accept a +// NULL |hash_map|. +//size_t hash_map_num_buckets(const hash_map_t *hash_map); + +// Returns true if the hash_map has a valid entry for the presented key. +// This function does not accept a NULL |hash_map|. +bool hash_map_has_key(const hash_map_t *hash_map, const void *key); + +// Returns the element indexed by |key| in the hash_map without removing it. |hash_map| +// may not be NULL. Returns NULL if no entry indexed by |key|. +void *hash_map_get(const hash_map_t *hash_map, const void *key); + +// Sets the value |data| indexed by |key| into the |hash_map|. Neither |data| nor +// |hash_map| may be NULL. This function does not make copies of |data| nor |key| +// so the pointers must remain valid at least until the element is removed from the +// hash_map or the hash_map is freed. Returns true if |data| could be set, false +// otherwise (e.g. out of memory). +bool hash_map_set(hash_map_t *hash_map, const void *key, void *data); + +// Removes data indexed by |key| from the hash_map. |hash_map| may not be NULL. +// If |key_fn| or |data_fn| functions were specified in |hash_map_new|, they +// will be called back with |key| or |data| respectively. This function returns true +// if |key| was found in the hash_map and removed, false otherwise. +bool hash_map_erase(hash_map_t *hash_map, const void *key); + +// Removes all elements in the hash_map. Calling this function will return the hash_map +// to the same state it was in after |hash_map_new|. |hash_map| may not be NULL. +void hash_map_clear(hash_map_t *hash_map); + +// Iterates through the entire |hash_map| and calls |callback| for each data +// element and passes through the |context| argument. If the hash_map is +// empty, |callback| will never be called. It is not safe to mutate the +// hash_map inside the callback. Neither |hash_map| nor |callback| may be NULL. +// If |callback| returns false, the iteration loop will immediately exit. +void hash_map_foreach(hash_map_t *hash_map, hash_map_iter_cb callback, void *context); + +#endif /* _HASH_MAP_H_ */ diff --git a/tools/sdk/include/bluedroid/hci_hal.h b/tools/sdk/include/bluedroid/hci_hal.h new file mode 100644 index 00000000..9853211d --- /dev/null +++ b/tools/sdk/include/bluedroid/hci_hal.h @@ -0,0 +1,85 @@ +/****************************************************************************** + * + * 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 _HCI_HAL_H_ +#define _HCI_HAL_H_ + +#include +#include + +#include "bt_types.h" + +typedef enum { + DATA_TYPE_COMMAND = 1, + DATA_TYPE_ACL = 2, + DATA_TYPE_SCO = 3, + DATA_TYPE_EVENT = 4 +} serial_data_type_t; + +typedef void (*packet_ready_cb)(BT_HDR *packet); + +typedef struct { + // Called when the HAL detects inbound data. + // Data |type| may be ACL, SCO, or EVENT. + // Executes in the context of the thread supplied to |init|. + packet_ready_cb packet_ready; + + /* + // Called when the HAL detects inbound astronauts named Dave. + // HAL will deny all requests to open the pod bay doors after this. + dave_ready_cb dave_ready; + */ +} hci_hal_callbacks_t; + +typedef struct hci_hal_t { + // Initialize the HAL, with |upper_callbacks| and |upper_thread| to run in the context of. + //bool (*init)(const hci_hal_callbacks_t *upper_callbacks); + + // Connect to the underlying hardware, and let data start flowing. + bool (*open)(const hci_hal_callbacks_t *upper_callbacks); + // Disconnect from the underlying hardware, and close the HAL. + // "Daisy, Daisy..." + void (*close)(void); + + // Retrieve up to |max_size| bytes for ACL, SCO, or EVENT data packets into + // |buffer|, blocking until max_size bytes read if |block| is true. + // Only guaranteed to be correct in the context of a data_ready callback + // of the corresponding type. + //size_t (*read_data)(serial_data_type_t type, uint8_t *buffer, size_t max_size); + // The upper layer must call this to notify the HAL that it has finished + // reading a packet of the specified |type|. Underlying implementations that + // use shared channels for multiple data types depend on this to know when + // to reinterpret the data stream. + //void (*packet_finished)(serial_data_type_t type); + // Transmit COMMAND, ACL, or SCO data packets. + // |data| may not be NULL. |length| must be greater than zero. + // + // IMPORTANT NOTE: + // Depending on the underlying implementation, the byte right + // before the beginning of |data| may be borrowed during this call + // and then restored to its original value. + // This is safe in the bluetooth context, because there is always a buffer + // header that prefixes data you're sending. + uint16_t (*transmit_data)(serial_data_type_t type, uint8_t *data, uint16_t length); +} hci_hal_t; + + +// Gets the correct hal implementation, as compiled for. +const hci_hal_t *hci_hal_h4_get_interface(void); + +#endif /* _HCI_HAL_H */ diff --git a/tools/sdk/include/bluedroid/hci_internals.h b/tools/sdk/include/bluedroid/hci_internals.h new file mode 100755 index 00000000..41c792cf --- /dev/null +++ b/tools/sdk/include/bluedroid/hci_internals.h @@ -0,0 +1,31 @@ +/****************************************************************************** + * + * 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 _HCI_INTERNALS_H_ +#define _HCI_INTERNALS_H_ + +// 2 bytes for opcode, 1 byte for parameter length (Volume 2, Part E, 5.4.1) +#define HCI_COMMAND_PREAMBLE_SIZE 3 +// 2 bytes for handle, 2 bytes for data length (Volume 2, Part E, 5.4.2) +#define HCI_ACL_PREAMBLE_SIZE 4 +// 2 bytes for handle, 1 byte for data length (Volume 2, Part E, 5.4.3) +#define HCI_SCO_PREAMBLE_SIZE 3 +// 1 byte for event code, 1 byte for parameter length (Volume 2, Part E, 5.4.4) +#define HCI_EVENT_PREAMBLE_SIZE 2 + +#endif /* _HCI_INTERNALS_H_ */ diff --git a/tools/sdk/include/bluedroid/hci_layer.h b/tools/sdk/include/bluedroid/hci_layer.h new file mode 100644 index 00000000..caea29f2 --- /dev/null +++ b/tools/sdk/include/bluedroid/hci_layer.h @@ -0,0 +1,103 @@ +/****************************************************************************** + * + * 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 _HCI_LAYER_H_ +#define _HCI_LAYER_H_ + +#include "bt_types.h" +#include "allocator.h" +#include "fixed_queue.h" +#include "osi.h" +#include "future.h" +///// LEGACY DEFINITIONS ///// + +/* Message event mask across Host/Controller lib and stack */ +#define MSG_EVT_MASK 0xFF00 /* eq. BT_EVT_MASK */ +#define MSG_SUB_EVT_MASK 0x00FF /* eq. BT_SUB_EVT_MASK */ + +/* Message event ID passed from Host/Controller lib to stack */ +#define MSG_HC_TO_STACK_HCI_ERR 0x1300 /* eq. BT_EVT_TO_BTU_HCIT_ERR */ +#define MSG_HC_TO_STACK_HCI_ACL 0x1100 /* eq. BT_EVT_TO_BTU_HCI_ACL */ +#define MSG_HC_TO_STACK_HCI_SCO 0x1200 /* eq. BT_EVT_TO_BTU_HCI_SCO */ +#define MSG_HC_TO_STACK_HCI_EVT 0x1000 /* eq. BT_EVT_TO_BTU_HCI_EVT */ +#define MSG_HC_TO_STACK_L2C_SEG_XMIT 0x1900 /* eq. BT_EVT_TO_BTU_L2C_SEG_XMIT */ + +/* Message event ID passed from stack to vendor lib */ +#define MSG_STACK_TO_HC_HCI_ACL 0x2100 /* eq. BT_EVT_TO_LM_HCI_ACL */ +#define MSG_STACK_TO_HC_HCI_SCO 0x2200 /* eq. BT_EVT_TO_LM_HCI_SCO */ +#define MSG_STACK_TO_HC_HCI_CMD 0x2000 /* eq. BT_EVT_TO_LM_HCI_CMD */ + +/* Local Bluetooth Controller ID for BR/EDR */ +#define LOCAL_BR_EDR_CONTROLLER_ID 0 + +///// END LEGACY DEFINITIONS ///// + +typedef struct hci_hal_t hci_hal_t; +//typedef struct btsnoop_t btsnoop_t; +typedef struct controller_t controller_t; +//typedef struct hci_inject_t hci_inject_t; +typedef struct packet_fragmenter_t packet_fragmenter_t; +//typedef struct vendor_t vendor_t; +//typedef struct low_power_manager_t low_power_manager_t; + +//typedef unsigned char * bdaddr_t; +typedef uint16_t command_opcode_t; + +/* +typedef enum { + LPM_DISABLE, + LPM_ENABLE, + LPM_WAKE_ASSERT, + LPM_WAKE_DEASSERT +} low_power_command_t; +*/ + +typedef void (*command_complete_cb)(BT_HDR *response, void *context); +typedef void (*command_status_cb)(uint8_t status, BT_HDR *command, void *context); + +typedef struct hci_t { + // Send a low power command, if supported and the low power manager is enabled. + //void (*send_low_power_command)(low_power_command_t command); + + // Do the postload sequence (call after the rest of the BT stack initializes). + void (*do_postload)(void); + + // Set the queue to receive ACL data in + void (*set_data_queue)(fixed_queue_t *queue); + + // Send a command through the HCI layer + void (*transmit_command)( + BT_HDR *command, + command_complete_cb complete_callback, + command_status_cb status_cb, + void *context + ); + + future_t *(*transmit_command_futured)(BT_HDR *command); + + // Send some data downward through the HCI layer + void (*transmit_downward)(uint16_t type, void *data); +} hci_t; + +const hci_t *hci_layer_get_interface(); + +int hci_start_up(void); +void hci_shut_down(void); + + +#endif /* _HCI_LAYER_H_ */ diff --git a/tools/sdk/include/bluedroid/hci_packet_factory.h b/tools/sdk/include/bluedroid/hci_packet_factory.h new file mode 100644 index 00000000..879962c2 --- /dev/null +++ b/tools/sdk/include/bluedroid/hci_packet_factory.h @@ -0,0 +1,48 @@ +/****************************************************************************** + * + * 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 _HCI_PACKET_FACTORY_H_ +#define _HCI_PACKET_FACTORY_H_ + +#include "bt_types.h" +#include "event_mask.h" + +typedef struct { + BT_HDR *(*make_reset)(void); + BT_HDR *(*make_read_buffer_size)(void); + BT_HDR *(*make_host_buffer_size)(uint16_t acl_size, uint8_t sco_size, uint16_t acl_count, uint16_t sco_count); + BT_HDR *(*make_read_local_version_info)(void); + BT_HDR *(*make_read_bd_addr)(void); + BT_HDR *(*make_read_local_supported_commands)(void); + BT_HDR *(*make_read_local_extended_features)(uint8_t page_number); + BT_HDR *(*make_write_simple_pairing_mode)(uint8_t mode); + BT_HDR *(*make_write_secure_connections_host_support)(uint8_t mode); + BT_HDR *(*make_set_event_mask)(const bt_event_mask_t *event_mask); + BT_HDR *(*make_ble_write_host_support)(uint8_t supported_host, uint8_t simultaneous_host); + BT_HDR *(*make_ble_read_white_list_size)(void); + BT_HDR *(*make_ble_read_buffer_size)(void); + BT_HDR *(*make_ble_read_supported_states)(void); + BT_HDR *(*make_ble_read_local_supported_features)(void); + BT_HDR *(*make_ble_read_resolving_list_size)(void); + BT_HDR *(*make_ble_read_suggested_default_data_length)(void); + BT_HDR *(*make_ble_set_event_mask)(const bt_event_mask_t *event_mask); +} hci_packet_factory_t; + +const hci_packet_factory_t *hci_packet_factory_get_interface(); + +#endif /*_HCI_PACKET_FACTORY_H_*/ diff --git a/tools/sdk/include/bluedroid/hci_packet_parser.h b/tools/sdk/include/bluedroid/hci_packet_parser.h new file mode 100644 index 00000000..916ea313 --- /dev/null +++ b/tools/sdk/include/bluedroid/hci_packet_parser.h @@ -0,0 +1,99 @@ +/****************************************************************************** + * + * 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 _HCI_PACKET_PARSER_H_ +#define _HCI_PACKET_PARSER_H_ + +#include + +#include "allocator.h" +#include "bdaddr.h" +#include "bt_types.h" +#include "device_features.h" +//#include "features.h" +#include "version.h" + +typedef struct { + void (*parse_generic_command_complete)(BT_HDR *response); + + void (*parse_read_buffer_size_response)( + BT_HDR *response, + uint16_t *data_size_ptr, + uint16_t *acl_buffer_count_ptr + ); + + void (*parse_read_local_version_info_response)( + BT_HDR *response, + bt_version_t *bt_version_ptr + ); + + void (*parse_read_bd_addr_response)( + BT_HDR *response, + bt_bdaddr_t *address_ptr + ); + + void (*parse_read_local_supported_commands_response)( + BT_HDR *response, + uint8_t *supported_commands_ptr, + size_t supported_commands_length + ); + + void (*parse_read_local_extended_features_response)( + BT_HDR *response, + uint8_t *page_number_ptr, + uint8_t *max_page_number_ptr, + bt_device_features_t *feature_pages, + size_t feature_pages_count + ); + + void (*parse_ble_read_white_list_size_response)( + BT_HDR *response, + uint8_t *white_list_size_ptr + ); + + void (*parse_ble_read_buffer_size_response)( + BT_HDR *response, + uint16_t *data_size_ptr, + uint8_t *acl_buffer_count_ptr + ); + + void (*parse_ble_read_supported_states_response)( + BT_HDR *response, + uint8_t *supported_states, + size_t supported_states_size + ); + + void (*parse_ble_read_local_supported_features_response)( + BT_HDR *response, + bt_device_features_t *supported_features + ); + + void (*parse_ble_read_resolving_list_size_response) ( + BT_HDR *response, + uint8_t *resolving_list_size_ptr + ); + + void (*parse_ble_read_suggested_default_data_length_response)( + BT_HDR *response, + uint16_t *ble_default_packet_length_ptr + ); +} hci_packet_parser_t; + +const hci_packet_parser_t *hci_packet_parser_get_interface(); + +#endif /*_HCI_PACKET_PARSER_H_*/ diff --git a/tools/sdk/include/bluedroid/hcidefs.h b/tools/sdk/include/bluedroid/hcidefs.h new file mode 100644 index 00000000..faf04fd9 --- /dev/null +++ b/tools/sdk/include/bluedroid/hcidefs.h @@ -0,0 +1,2605 @@ +/****************************************************************************** + * + * Copyright (C) 1999-2014 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. + * + ******************************************************************************/ + +#ifndef HCIDEFS_H +#define HCIDEFS_H + +#include "bt_target.h" + +#include "bt_types.h" + +#define HCI_PROTO_VERSION 0x01 /* Version for BT spec 1.1 */ +#define HCI_PROTO_VERSION_1_2 0x02 /* Version for BT spec 1.2 */ +#define HCI_PROTO_VERSION_2_0 0x03 /* Version for BT spec 2.0 */ +#define HCI_PROTO_VERSION_2_1 0x04 /* Version for BT spec 2.1 [Lisbon] */ +#define HCI_PROTO_VERSION_3_0 0x05 /* Version for BT spec 3.0 */ +#define HCI_PROTO_VERSION_4_0 0x06 /* Version for BT spec 4.0 */ +#define HCI_PROTO_VERSION_4_1 0x07 /* Version for BT spec 4.1 */ +#define HCI_PROTO_VERSION_4_2 0x08 /* Version for BT spec 4.2 */ +#define HCI_PROTO_REVISION 0x000C /* Current implementation version */ +/* +** Definitions for HCI groups +*/ +#define HCI_GRP_LINK_CONTROL_CMDS (0x01 << 10) /* 0x0400 */ +#define HCI_GRP_LINK_POLICY_CMDS (0x02 << 10) /* 0x0800 */ +#define HCI_GRP_HOST_CONT_BASEBAND_CMDS (0x03 << 10) /* 0x0C00 */ +#define HCI_GRP_INFORMATIONAL_PARAMS (0x04 << 10) /* 0x1000 */ +#define HCI_GRP_STATUS_PARAMS (0x05 << 10) /* 0x1400 */ +#define HCI_GRP_TESTING_CMDS (0x06 << 10) /* 0x1800 */ + +#define HCI_GRP_VENDOR_SPECIFIC (0x3F << 10) /* 0xFC00 */ + +/* Group occupies high 6 bits of the HCI command rest is opcode itself */ +#define HCI_OGF(p) (UINT8)((0xFC00 & (p)) >> 10) +#define HCI_OCF(p) ( 0x3FF & (p)) + +/* +** Definitions for Link Control Commands +*/ +/* Following opcode is used only in command complete event for flow control */ +#define HCI_COMMAND_NONE 0x0000 + +/* Commands of HCI_GRP_LINK_CONTROL_CMDS group */ +#define HCI_INQUIRY (0x0001 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_INQUIRY_CANCEL (0x0002 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_PERIODIC_INQUIRY_MODE (0x0003 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_EXIT_PERIODIC_INQUIRY_MODE (0x0004 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_CREATE_CONNECTION (0x0005 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_DISCONNECT (0x0006 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_ADD_SCO_CONNECTION (0x0007 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_CREATE_CONNECTION_CANCEL (0x0008 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_ACCEPT_CONNECTION_REQUEST (0x0009 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_REJECT_CONNECTION_REQUEST (0x000A | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_LINK_KEY_REQUEST_REPLY (0x000B | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_LINK_KEY_REQUEST_NEG_REPLY (0x000C | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_PIN_CODE_REQUEST_REPLY (0x000D | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_PIN_CODE_REQUEST_NEG_REPLY (0x000E | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_CHANGE_CONN_PACKET_TYPE (0x000F | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_AUTHENTICATION_REQUESTED (0x0011 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_SET_CONN_ENCRYPTION (0x0013 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_CHANGE_CONN_LINK_KEY (0x0015 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_MASTER_LINK_KEY (0x0017 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_RMT_NAME_REQUEST (0x0019 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_RMT_NAME_REQUEST_CANCEL (0x001A | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_READ_RMT_FEATURES (0x001B | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_READ_RMT_EXT_FEATURES (0x001C | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_READ_RMT_VERSION_INFO (0x001D | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_READ_RMT_CLOCK_OFFSET (0x001F | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_READ_LMP_HANDLE (0x0020 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_SETUP_ESCO_CONNECTION (0x0028 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_ACCEPT_ESCO_CONNECTION (0x0029 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_REJECT_ESCO_CONNECTION (0x002A | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_IO_CAPABILITY_REQUEST_REPLY (0x002B | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_USER_CONF_REQUEST_REPLY (0x002C | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_USER_CONF_VALUE_NEG_REPLY (0x002D | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_USER_PASSKEY_REQ_REPLY (0x002E | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_USER_PASSKEY_REQ_NEG_REPLY (0x002F | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_REM_OOB_DATA_REQ_REPLY (0x0030 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_REM_OOB_DATA_REQ_NEG_REPLY (0x0033 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_IO_CAP_REQ_NEG_REPLY (0x0034 | HCI_GRP_LINK_CONTROL_CMDS) + +/* AMP HCI */ +#define HCI_CREATE_PHYSICAL_LINK (0x0035 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_ACCEPT_PHYSICAL_LINK (0x0036 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_DISCONNECT_PHYSICAL_LINK (0x0037 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_CREATE_LOGICAL_LINK (0x0038 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_ACCEPT_LOGICAL_LINK (0x0039 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_DISCONNECT_LOGICAL_LINK (0x003A | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_LOGICAL_LINK_CANCEL (0x003B | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_FLOW_SPEC_MODIFY (0x003C | HCI_GRP_LINK_CONTROL_CMDS) + +#define HCI_ENH_SETUP_ESCO_CONNECTION (0x003D | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_ENH_ACCEPT_ESCO_CONNECTION (0x003E | HCI_GRP_LINK_CONTROL_CMDS) + +/* ConnectionLess Broadcast */ +#define HCI_TRUNCATED_PAGE (0x003F | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_TRUNCATED_PAGE_CANCEL (0x0040 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_SET_CLB (0x0041 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_RECEIVE_CLB (0x0042 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_START_SYNC_TRAIN (0x0043 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_RECEIVE_SYNC_TRAIN (0x0044 | HCI_GRP_LINK_CONTROL_CMDS) + +#define HCI_LINK_CTRL_CMDS_FIRST HCI_INQUIRY +#define HCI_LINK_CTRL_CMDS_LAST HCI_RECEIVE_SYNC_TRAIN + +/* Commands of HCI_GRP_LINK_POLICY_CMDS */ +#define HCI_HOLD_MODE (0x0001 | HCI_GRP_LINK_POLICY_CMDS) +#define HCI_SNIFF_MODE (0x0003 | HCI_GRP_LINK_POLICY_CMDS) +#define HCI_EXIT_SNIFF_MODE (0x0004 | HCI_GRP_LINK_POLICY_CMDS) +#define HCI_PARK_MODE (0x0005 | HCI_GRP_LINK_POLICY_CMDS) +#define HCI_EXIT_PARK_MODE (0x0006 | HCI_GRP_LINK_POLICY_CMDS) +#define HCI_QOS_SETUP (0x0007 | HCI_GRP_LINK_POLICY_CMDS) +#define HCI_ROLE_DISCOVERY (0x0009 | HCI_GRP_LINK_POLICY_CMDS) +#define HCI_SWITCH_ROLE (0x000B | HCI_GRP_LINK_POLICY_CMDS) +#define HCI_READ_POLICY_SETTINGS (0x000C | HCI_GRP_LINK_POLICY_CMDS) +#define HCI_WRITE_POLICY_SETTINGS (0x000D | HCI_GRP_LINK_POLICY_CMDS) +#define HCI_READ_DEF_POLICY_SETTINGS (0x000E | HCI_GRP_LINK_POLICY_CMDS) +#define HCI_WRITE_DEF_POLICY_SETTINGS (0x000F | HCI_GRP_LINK_POLICY_CMDS) +#define HCI_FLOW_SPECIFICATION (0x0010 | HCI_GRP_LINK_POLICY_CMDS) +#define HCI_SNIFF_SUB_RATE (0x0011 | HCI_GRP_LINK_POLICY_CMDS) + +#define HCI_LINK_POLICY_CMDS_FIRST HCI_HOLD_MODE +#define HCI_LINK_POLICY_CMDS_LAST HCI_SNIFF_SUB_RATE + + +/* Commands of HCI_GRP_HOST_CONT_BASEBAND_CMDS */ +#define HCI_SET_EVENT_MASK (0x0001 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_RESET (0x0003 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_SET_EVENT_FILTER (0x0005 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_FLUSH (0x0008 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_PIN_TYPE (0x0009 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_PIN_TYPE (0x000A | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_CREATE_NEW_UNIT_KEY (0x000B | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_GET_MWS_TRANS_LAYER_CFG (0x000C | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_STORED_LINK_KEY (0x000D | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_STORED_LINK_KEY (0x0011 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_DELETE_STORED_LINK_KEY (0x0012 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_CHANGE_LOCAL_NAME (0x0013 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_LOCAL_NAME (0x0014 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_CONN_ACCEPT_TOUT (0x0015 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_CONN_ACCEPT_TOUT (0x0016 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_PAGE_TOUT (0x0017 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_PAGE_TOUT (0x0018 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_SCAN_ENABLE (0x0019 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_SCAN_ENABLE (0x001A | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_PAGESCAN_CFG (0x001B | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_PAGESCAN_CFG (0x001C | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_INQUIRYSCAN_CFG (0x001D | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_INQUIRYSCAN_CFG (0x001E | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_AUTHENTICATION_ENABLE (0x001F | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_AUTHENTICATION_ENABLE (0x0020 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_ENCRYPTION_MODE (0x0021 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_ENCRYPTION_MODE (0x0022 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_CLASS_OF_DEVICE (0x0023 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_CLASS_OF_DEVICE (0x0024 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_VOICE_SETTINGS (0x0025 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_VOICE_SETTINGS (0x0026 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_AUTO_FLUSH_TOUT (0x0027 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_AUTO_FLUSH_TOUT (0x0028 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_NUM_BCAST_REXMITS (0x0029 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_NUM_BCAST_REXMITS (0x002A | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_HOLD_MODE_ACTIVITY (0x002B | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_HOLD_MODE_ACTIVITY (0x002C | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_TRANSMIT_POWER_LEVEL (0x002D | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_SCO_FLOW_CTRL_ENABLE (0x002E | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_SCO_FLOW_CTRL_ENABLE (0x002F | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_SET_HC_TO_HOST_FLOW_CTRL (0x0031 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_HOST_BUFFER_SIZE (0x0033 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_HOST_NUM_PACKETS_DONE (0x0035 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_LINK_SUPER_TOUT (0x0036 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_LINK_SUPER_TOUT (0x0037 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_NUM_SUPPORTED_IAC (0x0038 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_CURRENT_IAC_LAP (0x0039 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_CURRENT_IAC_LAP (0x003A | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_PAGESCAN_PERIOD_MODE (0x003B | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_PAGESCAN_PERIOD_MODE (0x003C | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_PAGESCAN_MODE (0x003D | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_PAGESCAN_MODE (0x003E | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_SET_AFH_CHANNELS (0x003F | HCI_GRP_HOST_CONT_BASEBAND_CMDS) + +#define HCI_READ_INQSCAN_TYPE (0x0042 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_INQSCAN_TYPE (0x0043 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_INQUIRY_MODE (0x0044 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_INQUIRY_MODE (0x0045 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_PAGESCAN_TYPE (0x0046 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_PAGESCAN_TYPE (0x0047 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_AFH_ASSESSMENT_MODE (0x0048 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_AFH_ASSESSMENT_MODE (0x0049 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_EXT_INQ_RESPONSE (0x0051 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_EXT_INQ_RESPONSE (0x0052 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_REFRESH_ENCRYPTION_KEY (0x0053 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_SIMPLE_PAIRING_MODE (0x0055 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_SIMPLE_PAIRING_MODE (0x0056 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_LOCAL_OOB_DATA (0x0057 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_INQ_TX_POWER_LEVEL (0x0058 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_INQ_TX_POWER_LEVEL (0x0059 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_ERRONEOUS_DATA_RPT (0x005A | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_ERRONEOUS_DATA_RPT (0x005B | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_ENHANCED_FLUSH (0x005F | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_SEND_KEYPRESS_NOTIF (0x0060 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) + + +/* AMP HCI */ +#define HCI_READ_LOGICAL_LINK_ACCEPT_TIMEOUT (0x0061 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT (0x0062 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_SET_EVENT_MASK_PAGE_2 (0x0063 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_LOCATION_DATA (0x0064 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_LOCATION_DATA (0x0065 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_FLOW_CONTROL_MODE (0x0066 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_FLOW_CONTROL_MODE (0x0067 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_BE_FLUSH_TOUT (0x0069 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_BE_FLUSH_TOUT (0x006A | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_SHORT_RANGE_MODE (0x006B | HCI_GRP_HOST_CONT_BASEBAND_CMDS) /* 802.11 only */ +#define HCI_READ_LE_HOST_SUPPORT (0x006C | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_LE_HOST_SUPPORT (0x006D | HCI_GRP_HOST_CONT_BASEBAND_CMDS) + + +/* MWS coexistence */ +#define HCI_SET_MWS_CHANNEL_PARAMETERS (0x006E | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_SET_EXTERNAL_FRAME_CONFIGURATION (0x006F | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_SET_MWS_SIGNALING (0x0070 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_SET_MWS_TRANSPORT_LAYER (0x0071 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_SET_MWS_SCAN_FREQUENCY_TABLE (0x0072 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_SET_MWS_PATTERN_CONFIGURATION (0x0073 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) + +/* Connectionless Broadcast */ +#define HCI_SET_RESERVED_LT_ADDR (0x0074 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_DELETE_RESERVED_LT_ADDR (0x0075 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_CLB_DATA (0x0076 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_SYNC_TRAIN_PARAM (0x0077 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_SYNC_TRAIN_PARAM (0x0078 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) + +#define HCI_READ_SECURE_CONNS_SUPPORT (0x0079 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_SECURE_CONNS_SUPPORT (0x007A | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_CONT_BASEBAND_CMDS_FIRST HCI_SET_EVENT_MASK +#define HCI_CONT_BASEBAND_CMDS_LAST HCI_READ_SYNC_TRAIN_PARAM + + +/* Commands of HCI_GRP_INFORMATIONAL_PARAMS group */ +#define HCI_READ_LOCAL_VERSION_INFO (0x0001 | HCI_GRP_INFORMATIONAL_PARAMS) +#define HCI_READ_LOCAL_SUPPORTED_CMDS (0x0002 | HCI_GRP_INFORMATIONAL_PARAMS) +#define HCI_READ_LOCAL_FEATURES (0x0003 | HCI_GRP_INFORMATIONAL_PARAMS) +#define HCI_READ_LOCAL_EXT_FEATURES (0x0004 | HCI_GRP_INFORMATIONAL_PARAMS) +#define HCI_READ_BUFFER_SIZE (0x0005 | HCI_GRP_INFORMATIONAL_PARAMS) +#define HCI_READ_COUNTRY_CODE (0x0007 | HCI_GRP_INFORMATIONAL_PARAMS) +#define HCI_READ_BD_ADDR (0x0009 | HCI_GRP_INFORMATIONAL_PARAMS) +#define HCI_READ_DATA_BLOCK_SIZE (0x000A | HCI_GRP_INFORMATIONAL_PARAMS) +#define HCI_READ_LOCAL_SUPPORTED_CODECS (0x000B | HCI_GRP_INFORMATIONAL_PARAMS) + +#define HCI_INFORMATIONAL_CMDS_FIRST HCI_READ_LOCAL_VERSION_INFO +#define HCI_INFORMATIONAL_CMDS_LAST HCI_READ_LOCAL_SUPPORTED_CODECS + + +/* Commands of HCI_GRP_STATUS_PARAMS group */ +#define HCI_READ_FAILED_CONTACT_COUNT (0x0001 | HCI_GRP_STATUS_PARAMS) +#define HCI_RESET_FAILED_CONTACT_COUNT (0x0002 | HCI_GRP_STATUS_PARAMS) +#define HCI_GET_LINK_QUALITY (0x0003 | HCI_GRP_STATUS_PARAMS) +#define HCI_READ_RSSI (0x0005 | HCI_GRP_STATUS_PARAMS) +#define HCI_READ_AFH_CH_MAP (0x0006 | HCI_GRP_STATUS_PARAMS) +#define HCI_READ_CLOCK (0x0007 | HCI_GRP_STATUS_PARAMS) +#define HCI_READ_ENCR_KEY_SIZE (0x0008 | HCI_GRP_STATUS_PARAMS) + +/* AMP HCI */ +#define HCI_READ_LOCAL_AMP_INFO (0x0009 | HCI_GRP_STATUS_PARAMS) +#define HCI_READ_LOCAL_AMP_ASSOC (0x000A | HCI_GRP_STATUS_PARAMS) +#define HCI_WRITE_REMOTE_AMP_ASSOC (0x000B | HCI_GRP_STATUS_PARAMS) + +#define HCI_STATUS_PARAMS_CMDS_FIRST HCI_READ_FAILED_CONTACT_COUNT +#define HCI_STATUS_PARAMS_CMDS_LAST HCI_WRITE_REMOTE_AMP_ASSOC + +/* Commands of HCI_GRP_TESTING_CMDS group */ +#define HCI_READ_LOOPBACK_MODE (0x0001 | HCI_GRP_TESTING_CMDS) +#define HCI_WRITE_LOOPBACK_MODE (0x0002 | HCI_GRP_TESTING_CMDS) +#define HCI_ENABLE_DEV_UNDER_TEST_MODE (0x0003 | HCI_GRP_TESTING_CMDS) +#define HCI_WRITE_SIMP_PAIR_DEBUG_MODE (0x0004 | HCI_GRP_TESTING_CMDS) + +/* AMP HCI */ +#define HCI_ENABLE_AMP_RCVR_REPORTS (0x0007 | HCI_GRP_TESTING_CMDS) +#define HCI_AMP_TEST_END (0x0008 | HCI_GRP_TESTING_CMDS) +#define HCI_AMP_TEST (0x0009 | HCI_GRP_TESTING_CMDS) + +#define HCI_TESTING_CMDS_FIRST HCI_READ_LOOPBACK_MODE +#define HCI_TESTING_CMDS_LAST HCI_AMP_TEST + +#define HCI_VENDOR_CMDS_FIRST 0x0001 +#define HCI_VENDOR_CMDS_LAST 0xFFFF +#define HCI_VSC_MULTI_AV_HANDLE 0x0AAA +#define HCI_VSC_BURST_MODE_HANDLE 0x0BBB + +/* BLE HCI */ +#define HCI_GRP_BLE_CMDS (0x08 << 10) +/* Commands of BLE Controller setup and configuration */ +#define HCI_BLE_SET_EVENT_MASK (0x0001 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_READ_BUFFER_SIZE (0x0002 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_READ_LOCAL_SPT_FEAT (0x0003 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_WRITE_LOCAL_SPT_FEAT (0x0004 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_WRITE_RANDOM_ADDR (0x0005 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_WRITE_ADV_PARAMS (0x0006 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_READ_ADV_CHNL_TX_POWER (0x0007 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_WRITE_ADV_DATA (0x0008 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_WRITE_SCAN_RSP_DATA (0x0009 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_WRITE_ADV_ENABLE (0x000A | HCI_GRP_BLE_CMDS) +#define HCI_BLE_WRITE_SCAN_PARAMS (0x000B | HCI_GRP_BLE_CMDS) +#define HCI_BLE_WRITE_SCAN_ENABLE (0x000C | HCI_GRP_BLE_CMDS) +#define HCI_BLE_CREATE_LL_CONN (0x000D | HCI_GRP_BLE_CMDS) +#define HCI_BLE_CREATE_CONN_CANCEL (0x000E | HCI_GRP_BLE_CMDS) +#define HCI_BLE_READ_WHITE_LIST_SIZE (0x000F | HCI_GRP_BLE_CMDS) +#define HCI_BLE_CLEAR_WHITE_LIST (0x0010 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_ADD_WHITE_LIST (0x0011 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_REMOVE_WHITE_LIST (0x0012 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_UPD_LL_CONN_PARAMS (0x0013 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_SET_HOST_CHNL_CLASS (0x0014 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_READ_CHNL_MAP (0x0015 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_READ_REMOTE_FEAT (0x0016 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_ENCRYPT (0x0017 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_RAND (0x0018 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_START_ENC (0x0019 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_LTK_REQ_REPLY (0x001A | HCI_GRP_BLE_CMDS) +#define HCI_BLE_LTK_REQ_NEG_REPLY (0x001B | HCI_GRP_BLE_CMDS) +#define HCI_BLE_READ_SUPPORTED_STATES (0x001C | HCI_GRP_BLE_CMDS) +/*0x001D, 0x001E and 0x001F are reserved*/ +#define HCI_BLE_RECEIVER_TEST (0x001D | HCI_GRP_BLE_CMDS) +#define HCI_BLE_TRANSMITTER_TEST (0x001E | HCI_GRP_BLE_CMDS) +/* BLE TEST COMMANDS */ +#define HCI_BLE_TEST_END (0x001F | HCI_GRP_BLE_CMDS) +#define HCI_BLE_RC_PARAM_REQ_REPLY (0x0020 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_RC_PARAM_REQ_NEG_REPLY (0x0021 | HCI_GRP_BLE_CMDS) + +#define HCI_BLE_SET_DATA_LENGTH (0x0022 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_READ_DEFAULT_DATA_LENGTH (0x0023 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_WRITE_DEFAULT_DATA_LENGTH (0x0024 | HCI_GRP_BLE_CMDS) + +#define HCI_BLE_ADD_DEV_RESOLVING_LIST (0x0027 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_RM_DEV_RESOLVING_LIST (0x0028 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_CLEAR_RESOLVING_LIST (0x0029 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_READ_RESOLVING_LIST_SIZE (0x002A | HCI_GRP_BLE_CMDS) +#define HCI_BLE_READ_RESOLVABLE_ADDR_PEER (0x002B | HCI_GRP_BLE_CMDS) +#define HCI_BLE_READ_RESOLVABLE_ADDR_LOCAL (0x002C | HCI_GRP_BLE_CMDS) +#define HCI_BLE_SET_ADDR_RESOLUTION_ENABLE (0x002D | HCI_GRP_BLE_CMDS) +#define HCI_BLE_SET_RAND_PRIV_ADDR_TIMOUT (0x002E | HCI_GRP_BLE_CMDS) + +/* LE Get Vendor Capabilities Command OCF */ +#define HCI_BLE_VENDOR_CAP_OCF (0x0153 | HCI_GRP_VENDOR_SPECIFIC) + +/* Multi adv OCF */ +#define HCI_BLE_MULTI_ADV_OCF (0x0154 | HCI_GRP_VENDOR_SPECIFIC) + +/* Batch scan OCF */ +#define HCI_BLE_BATCH_SCAN_OCF (0x0156 | HCI_GRP_VENDOR_SPECIFIC) + +/* ADV filter OCF */ +#define HCI_BLE_ADV_FILTER_OCF (0x0157 | HCI_GRP_VENDOR_SPECIFIC) + +/* Tracking OCF */ +#define HCI_BLE_TRACK_ADV_OCF (0x0158 | HCI_GRP_VENDOR_SPECIFIC) + +/* Energy info OCF */ +#define HCI_BLE_ENERGY_INFO_OCF (0x0159 | HCI_GRP_VENDOR_SPECIFIC) + +/* Extended BLE Scan parameters OCF */ +#define HCI_BLE_EXTENDED_SCAN_PARAMS_OCF (0x0160 | HCI_GRP_VENDOR_SPECIFIC) + +/* subcode for multi adv feature */ +#define BTM_BLE_MULTI_ADV_SET_PARAM 0x01 +#define BTM_BLE_MULTI_ADV_WRITE_ADV_DATA 0x02 +#define BTM_BLE_MULTI_ADV_WRITE_SCAN_RSP_DATA 0x03 +#define BTM_BLE_MULTI_ADV_SET_RANDOM_ADDR 0x04 +#define BTM_BLE_MULTI_ADV_ENB 0x05 + +/* multi adv VSE subcode */ +#define HCI_VSE_SUBCODE_BLE_MULTI_ADV_ST_CHG 0x55 /* multi adv instance state change */ + +/* subcode for batch scan feature */ +#define BTM_BLE_BATCH_SCAN_ENB_DISAB_CUST_FEATURE 0x01 +#define BTM_BLE_BATCH_SCAN_SET_STORAGE_PARAM 0x02 +#define BTM_BLE_BATCH_SCAN_SET_PARAMS 0x03 +#define BTM_BLE_BATCH_SCAN_READ_RESULTS 0x04 + +/* batch scan VSE subcode */ +#define HCI_VSE_SUBCODE_BLE_THRESHOLD_SUB_EVT 0x54 /* Threshold event */ + +/* tracking sub event */ +#define HCI_VSE_SUBCODE_BLE_TRACKING_SUB_EVT 0x56 /* Tracking event */ + +/* LE supported states definition */ +#define HCI_LE_ADV_STATE 0x00000001 +#define HCI_LE_SCAN_STATE 0x00000002 +#define HCI_LE_INIT_STATE 0x00000004 +#define HCI_LE_CONN_SL_STATE 0x00000008 +#define HCI_LE_ADV_SCAN_STATE 0x00000010 +#define HCI_LE_ADV_INIT_STATE 0x00000020 +#define HCI_LE_ADV_MA_STATE 0x00000040 +#define HCI_LE_ADV_SL_STATE 0x00000080 +#define HCI_LE_SCAN_INIT_STATE 0x00000100 +#define HCI_LE_SCAN_MA_STATE 0x00000200 +#define HCI_LE_SCAN_SL_STATE 0x00000400 +#define HCI_LE_INIT_MA_STATE 0x00000800 + +/* LE Supported States */ +/* Non Connectable Adv state is supported. 0x0000000000000001 */ +#define HCI_SUPP_LE_STATES_NON_CONN_ADV_MASK 0x01 +#define HCI_SUPP_LE_STATES_NON_CONN_ADV_OFF 0 +#define HCI_LE_STATES_NON_CONN_ADV_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_NON_CONN_ADV_OFF] & HCI_SUPP_LE_STATES_NON_CONN_ADV_MASK) + +/*Scanneable Connectable Adv state is supported. 0x0000000000000002 */ +#define HCI_SUPP_LE_STATES_SCAN_ADV_MASK 0x02 +#define HCI_SUPP_LE_STATESSCAN_ADV_OFF 0 +#define HCI_LE_STATES_SCAN_ADV_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATESSCAN_ADV_OFF] & HCI_SUPP_LE_STATES_SCAN_ADV_MASK) + +/* Connectable Adv state is supported. 0x0000000000000004 */ +#define HCI_SUPP_LE_STATES_CONN_ADV_MASK 0x04 +#define HCI_SUPP_LE_STATES_CONN_ADV_OFF 0 +#define HCI_LE_STATES_CONN_ADV_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_CONN_ADV_OFF] & HCI_SUPP_LE_STATES_CONN_ADV_MASK) + +/* Hi duty Cycle Directed Adv state is supported. 0x0000000000000008 */ +#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_MASK 0x08 +#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_OFF 0 +#define HCI_LE_STATES_HI_DUTY_DIR_ADV_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_OFF] & HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_MASK) + +/* Passive Scan state is supported. 0x0000000000000010 */ +#define HCI_SUPP_LE_STATES_PASS_SCAN_MASK 0x10 +#define HCI_SUPP_LE_STATES_PASS_SCAN_OFF 0 +#define HCI_LE_STATES_PASS_SCAN_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_PASS_SCAN_OFF] & HCI_SUPP_LE_STATES_PASS_SCAN_MASK) + +/* Active Scan state is supported. 0x0000000000000020 */ +#define HCI_SUPP_LE_STATES_ACTIVE_SCAN_MASK 0x20 +#define HCI_SUPP_LE_STATES_ACTIVE_SCAN_OFF 0 +#define HCI_LE_STATES_ACTIVE_SCAN_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_ACTIVE_SCAN_OFF] & HCI_SUPP_LE_STATES_ACTIVE_SCAN_MASK) + +/* Initiating state is supported. 0x0000000000000040 (or connection state in master role is also supported) */ +#define HCI_SUPP_LE_STATES_INIT_MASK 0x40 +#define HCI_SUPP_LE_STATES_INIT_OFF 0 +#define HCI_LE_STATES_INIT_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_INIT_OFF] & HCI_SUPP_LE_STATES_INIT_MASK) + +/*connection state in slave role is also supported. 0x0000000000000080 */ +#define HCI_SUPP_LE_STATES_SLAVE_MASK 0x80 +#define HCI_SUPP_LE_STATES_SLAVE_OFF 0 +#define HCI_LE_STATES_SLAVE_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_SLAVE_OFF] & HCI_SUPP_LE_STATES_SLAVE_MASK) + +/* Non Connectable Adv state and Passive Scanning State combination is supported. 0x0000000000000100 */ +#define HCI_SUPP_LE_STATES_NON_CONN_ADV_PASS_SCAN_MASK 0x01 +#define HCI_SUPP_LE_STATES_NON_CONN_ADV_PASS_SCAN_OFF 1 +#define HCI_LE_STATES_NON_CONN_ADV_PASS_SCAN_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_NON_CONN_ADV_PASS_SCAN_OFF] & HCI_SUPP_LE_STATES_NON_CONN_ADV_PASS_SCAN_MASK) + +/*Scannable Adv state and Passive Scanning State combination is supported. 0x0000000000000200 */ +#define HCI_SUPP_LE_STATES_SCAN_ADV_PASS_SCAN_MASK 0x02 +#define HCI_SUPP_LE_STATES_SCAN_ADV_PASS_SCAN_OFF 1 +#define HCI_LE_STATES_SCAN_ADV_PASS_SCAN_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_SCAN_ADV_PASS_SCAN_OFF] & HCI_SUPP_LE_STATES_SCAN_ADV_PASS_SCAN_MASK) + +/*Connectable Adv state and Passive Scanning State combination is supported. 0x0000000000000400 */ +#define HCI_SUPP_LE_STATES_CONN_ADV_PASS_SCAN_MASK 0x04 +#define HCI_SUPP_LE_STATES_CONN_ADV_PASS_SCAN_OFF 1 +#define HCI_LE_STATES_CONN_ADV_PASS_SCAN_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_CONN_ADV_PASS_SCAN_OFF] & HCI_SUPP_LE_STATES_CONN_ADV_PASS_SCAN_MASK) + +/*High Duty Cycl Directed ADv and Passive Scanning State combination is supported. 0x0000000000000800 */ +#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_PASS_SCAN_MASK 0x08 +#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_PASS_SCAN_OFF 1 +#define HCI_LE_STATES_HI_DUTY_DIR_ADV_PASS_SCAN_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_PASS_SCAN_MASK] & HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_PASS_SCAN_OFF) + +/*Non Connectable Adv state and Passive Scanning State combination is supported. 0x0000000000001000 */ +#define HCI_SUPP_LE_STATES_NON_CONN_ADV_ACTIVE_SCAN_MASK 0x10 +#define HCI_SUPP_LE_STATES_NON_CONN_ADV_ACTIVE_SCAN_OFF 1 +#define HCI_LE_STATES_NON_CONN_ADV_ACTIVE_SCAN_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_NON_CONN_ADV_ACTIVE_SCAN_OFF] & HCI_SUPP_LE_STATES_NON_CONN_ADV_ACTIVE_SCAN_MASK) + +/*Scannable Adv state and Active Scanning State combination is supported. 0x0000000000002000 */ +#define HCI_SUPP_LE_STATES_SCAN_ADV_ACTIVE_SCAN_MASK 0x20 +#define HCI_SUPP_LE_STATES_SCAN_ADV_ACTIVE_SCAN_OFF 1 +#define HCI_LE_STATES_SCAN_ADV_ACTIVE_SCAN_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_SCAN_ADV_ACTIVE_SCAN_OFF] & HCI_SUPP_LE_STATES_SCAN_ADV_ACTIVE_SCAN_MASK) + +/*Connectable Adv state and Active Scanning State combination is supported. 0x0000000000004000 */ +#define HCI_SUPP_LE_STATES_CONN_ADV_ACTIVE_SCAN_MASK 0x40 +#define HCI_SUPP_LE_STATES_CONN_ADV_ACTIVE_SCAN_OFF 1 +#define HCI_LE_STATES_CONN_ADV_ACTIVE_SCAN_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_CONN_ADV_ACTIVE_SCAN_OFF] & HCI_SUPP_LE_STATES_CONN_ADV_ACTIVE_SCAN_MASK) + +/*High Duty Cycl Directed ADv and ACtive Scanning State combination is supported. 0x0000000000008000 */ +#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_ACTIVE_SCAN_MASK 0x80 +#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_ACTIVE_SCAN_OFF 1 +#define HCI_LE_STATES_HI_DUTY_DIR_ADV_ACTIVE_SCAN_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_ACTIVE_SCAN_MASK] & HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_ACTIVE_SCAN_OFF) + +/*Non-Connectable Adv state and Initiating State combination is supported. 0x0000000000010000 */ +#define HCI_SUPP_LE_STATES_NON_CONN_INIT_MASK 0x01 +#define HCI_SUPP_LE_STATES_NON_CONN_INIT_OFF 2 +#define HCI_LE_STATES_NON_CONN_INIT_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_NON_CONN_INIT_OFF] & HCI_SUPP_LE_STATES_NON_CONN_INIT_MASK) + +/* Scannable Adv state and Initiating State combination is supported. 0x0000000000020000 */ +#define HCI_SUPP_LE_STATES_SCAN_ADV_INIT_MASK 0x02 +#define HCI_SUPP_LE_STATES_SCAN_ADV_INIT_OFF 2 +#define HCI_LE_STATES_SCAN_ADV_INIT_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_SCAN_ADV_INIT_OFF] & HCI_SUPP_LE_STATES_SCAN_ADV_INIT_MASK) + +/* Non-Connectable Adv state and Master Role combination is supported. 0x0000000000040000 */ +#define HCI_SUPP_LE_STATES_NON_CONN_ADV_MASTER_MASK 0x04 +#define HCI_SUPP_LE_STATES_NON_CONN_ADV_MASTER_OFF 2 +#define HCI_LE_STATES_NON_CONN_ADV_MASTER_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_NON_CONN_ADV_MASTER_OFF] & HCI_SUPP_LE_STATES_NON_CONN_ADV_MASTER_MASK) + +/*Scannable Adv state and Master Role combination is supported. 0x0000000000040000 */ +#define HCI_SUPP_LE_STATES_SCAN_ADV_MASTER_MASK 0x08 +#define HCI_SUPP_LE_STATES_SCAN_ADV_MASTER_OFF 2 +#define HCI_LE_STATES_SCAN_ADV_MASTER_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_SCAN_ADV_MASTER_OFF] & HCI_SUPP_LE_STATES_SCAN_ADV_MASTER_MASK) + +/* Non-Connectable Adv and Slave Role combination is supported. 0x000000000100000 */ +#define HCI_SUPP_LE_STATES_NON_CONN_ADV_SLAVE_MASK 0x10 +#define HCI_SUPP_LE_STATES_NON_CONN_ADV_SLAVE_OFF 2 +#define HCI_LE_STATES_NON_CONN_ADV_SLAVE_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_NON_CONN_ADV_SLAVE_OFF] & HCI_SUPP_LE_STATES_NON_CONN_ADV_SLAVE_MASK) + +/*Scannable Adv and Slave Role combination is supported. 0x000000000200000 */ +#define HCI_SUPP_LE_STATES_SCAN_ADV_SLAVE_MASK 0x20 +#define HCI_SUPP_LE_STATES_SCAN_ADV_SLAVE_OFF 2 +#define HCI_LE_STATES_SCAN_ADV_SLAVE_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_SCAN_ADV_SLAVE_OFF] & HCI_SUPP_LE_STATES_SCAN_ADV_SLAVE_MASK) + +/*Passive Scan and Initiating State combination is supported. 0x000000000400000 */ +#define HCI_SUPP_LE_STATES_PASS_SCAN_INIT_MASK 0x40 +#define HCI_SUPP_LE_STATES_PASS_SCAN_INIT_OFF 2 +#define HCI_LE_STATES_PASS_SCAN_INIT_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_PASS_SCAN_INIT_OFF] & HCI_SUPP_LE_STATES_PASS_SCAN_INIT_MASK) + +/*Active Scan and Initiating State combination is supported. 0x000000000800000 */ +#define HCI_SUPP_LE_STATES_ACTIVE_SCAN_INIT_MASK 0x80 +#define HCI_SUPP_LE_STATES_ACTIVE_SCAN_INIT_OFF 2 +#define HCI_LE_STATES_ACTIVE_SCAN_INIT_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_ACTIVE_SCAN_INIT_OFF] & HCI_SUPP_LE_STATES_ACTIVE_SCAN_INIT_MASK) + +/*Passive Scan and Master Role combination is supported. 0x000000001000000 */ +#define HCI_SUPP_LE_STATES_PASS_SCAN_MASTER_MASK 0x01 +#define HCI_SUPP_LE_STATES_PASS_SCAN_MASTER_OFF 3 +#define HCI_LE_STATES_PASS_SCAN_MASTER_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_PASS_SCAN_MASTER_OFF] & HCI_SUPP_LE_STATES_PASS_SCAN_MASTER_MASK) + +/*Active Scan and Master Role combination is supported. 0x000000002000000 */ +#define HCI_SUPP_LE_STATES_ACTIVE_SCAN_MASTER_MASK 0x02 +#define HCI_SUPP_LE_STATES_ACTIVE_SCAN_MASTER_OFF 3 +#define HCI_LE_STATES_ACTIVE_SCAN_MASTER_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_ACTIVE_SCAN_MASTER_OFF] & HCI_SUPP_LE_STATES_ACTIVE_SCAN_MASTER_MASK) + +/*Passive Scan and Slave Role combination is supported. 0x000000004000000 */ +#define HCI_SUPP_LE_STATES_PASS_SCAN_SLAVE_MASK 0x04 +#define HCI_SUPP_LE_STATES_PASS_SCAN_SLAVE_OFF 3 +#define HCI_LE_STATES_PASS_SCAN_SLAVE_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_PASS_SCAN_SLAVE_OFF] & HCI_SUPP_LE_STATES_PASS_SCAN_SLAVE_MASK) + +/*Active Scan and Slave Role combination is supported. 0x000000008000000 */ +#define HCI_SUPP_LE_STATES_ACTIVE_SCAN_SLAVE_MASK 0x08 +#define HCI_SUPP_LE_STATES_ACTIVE_SCAN_SLAVE_OFF 3 +#define HCI_LE_STATES_ACTIVE_SCAN_SLAVE_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_ACTIVE_SCAN_SLAVE_OFF] & HCI_SUPP_LE_STATES_ACTIVE_SCAN_SLAVE_MASK) + +/*Link Layer Topology Added States Combo */ +/*Initiating State and Master Role combination supported. + Master Role and Master Role combination is also supported. 0x0000000010000000 */ +#define HCI_SUPP_LE_STATES_INIT_MASTER_MASK 0x10 +#define HCI_SUPP_LE_STATES_INIT_MASTER_OFF 3 +#define HCI_LE_STATES_INIT_MASTER_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_INIT_MASTER_OFF] & HCI_SUPP_LE_STATES_INIT_MASTER_MASK) + +/*Low Duty Cycle Directed Advertising State . 0x0000000020000000 */ +#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_MASK 0x20 +#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_OFF 3 +#define HCI_LE_STATES_LOW_DUTY_DIR_ADV_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_LOW_DUTY_DIR_ADV_OFF] & HCI_SUPP_LE_STATES_LOW_DUTY_DIR_ADV_MASK) + +/*Low Duty Cycle Directed Advertising State and Passive scan combination. 0x0000000040000000 */ +#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_PASS_SCAN_MASK 0x40 +#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_PASS_SCAN_OFF 3 +#define HCI_LE_STATES_LO_DUTY_DIR_ADV_PASS_SCAN_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_PASS_SCAN_OFF] & HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_PASS_SCAN_MASK) + +/*Low Duty Cycle Directed Advertising State and Active scan combination . 0x0000000080000000 */ +#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_ACTIVE_SCAN_MASK 0x80 +#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_ACTIVE_SCAN_OFF 3 +#define HCI_LE_STATES_LO_DUTY_DIR_ADV_ACTIVE_SCAN_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_ACTIVE_SCAN_OFF] & HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_ACTIVE_SCAN_MASK) + +/* Connectable Advertising State and Initiating State combination supported. 0x0000000100000000 */ +#define HCI_SUPP_LE_STATES_CONN_ADV_INIT_MASK 0x01 +#define HCI_SUPP_LE_STATES_CONN_ADV_INIT_OFF 4 +#define HCI_LE_STATES_CONN_ADV_INIT_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_CONN_ADV_INIT_OFF] & HCI_SUPP_LE_STATES_CONN_ADV_INIT_MASK) + +/* High Duty Cycle Directed Advertising State and Initiating State combination supported. */ +#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_INIT_MASK 0x02 +#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_INIT_OFF 4 +#define HCI_LE_STATES_HI_DUTY_DIR_ADV_INIT_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_INIT_OFF] & HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_INIT_MASK) + +/* Low Duty Cycle Directed Advertising State and Initiating State combination supported.*/ +#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_INIT_MASK 0x04 +#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_INIT_OFF 4 +#define HCI_LE_STATES_LO_DUTY_DIR_ADV_INIT_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_INIT_OFF] & HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_INIT_MASK) + +/* Connectable Advertising State and Master Role combination supported.*/ +#define HCI_SUPP_LE_STATES_CONN_ADV_MASTER_MASK 0x08 +#define HCI_SUPP_LE_STATES_CONN_ADV_MASTER_OFF 4 +#define HCI_LE_STATES_CONN_ADV_MASTER_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_CONN_ADV_MASTER_OFF] & HCI_SUPP_LE_STATES_CONN_ADV_MASTER_MASK) + +/* High Duty Cycle Directed Advertising State and Master Role combination supported.*/ +#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_MASTER_MASK 0x10 +#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_MASTER_OFF 4 +#define HCI_LE_STATES_HI_DUTY_DIR_ADV_MASTER_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_MASTER_OFF] & HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_MASTER_MASK) + +/* Low Duty Cycle Directed Advertising State and Master Role combination supported.*/ +#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_MASTER_MASK 0x20 +#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_MASTER_OFF 4 +#define HCI_LE_STATES_LO_DUTY_DIR_ADV_MASTER_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_MASTER_OFF] & HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_MASTER_MASK) + +/* Connectable Advertising State and Slave Role combination supported. */ +#define HCI_SUPP_LE_STATES_CONN_ADV_SLAVE_MASK 0x40 +#define HCI_SUPP_LE_STATES_CONN_ADV_SLAVE_OFF 4 +#define HCI_LE_STATES_CONN_ADV_SLAVE_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_CONN_ADV_SLAVE_OFF] & HCI_SUPP_LE_STATES_CONN_ADV_SLAVE_MASK) + +/* High Duty Cycle Directed Advertising State and slave Role combination supported.*/ +#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_SLAVE_MASK 0x80 +#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_SLAVE_OFF 4 +#define HCI_LE_STATES_HI_DUTY_DIR_ADV_SLAVE_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_SLAVE_OFF] & HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_SLAVE_MASK) + +/* Low Duty Cycle Directed Advertising State and slave Role combination supported.*/ +#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_SLAVE_MASK 0x01 +#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_SLAVE_OFF 5 +#define HCI_LE_STATES_LO_DUTY_DIR_ADV_SLAVE_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_SLAVE_OFF] & HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_SLAVE_MASK) + +/* Initiating State and Slave Role combination supported. + Master Role and Slave Role combination also supported. + */ +#define HCI_SUPP_LE_STATES_INIT_MASTER_SLAVE_MASK 0x02 +#define HCI_SUPP_LE_STATES_INIT_MASTER_SLAVE_OFF 5 +#define HCI_LE_STATES_INIT_MASTER_SLAVE_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_INIT_MASTER_SLAVE_OFF] & HCI_SUPP_LE_STATES_INIT_MASTER_SLAVE_MASK) + +/* +** Definitions for HCI Events +*/ +#define HCI_INQUIRY_COMP_EVT 0x01 +#define HCI_INQUIRY_RESULT_EVT 0x02 +#define HCI_CONNECTION_COMP_EVT 0x03 +#define HCI_CONNECTION_REQUEST_EVT 0x04 +#define HCI_DISCONNECTION_COMP_EVT 0x05 +#define HCI_AUTHENTICATION_COMP_EVT 0x06 +#define HCI_RMT_NAME_REQUEST_COMP_EVT 0x07 +#define HCI_ENCRYPTION_CHANGE_EVT 0x08 +#define HCI_CHANGE_CONN_LINK_KEY_EVT 0x09 +#define HCI_MASTER_LINK_KEY_COMP_EVT 0x0A +#define HCI_READ_RMT_FEATURES_COMP_EVT 0x0B +#define HCI_READ_RMT_VERSION_COMP_EVT 0x0C +#define HCI_QOS_SETUP_COMP_EVT 0x0D +#define HCI_COMMAND_COMPLETE_EVT 0x0E +#define HCI_COMMAND_STATUS_EVT 0x0F +#define HCI_HARDWARE_ERROR_EVT 0x10 +#define HCI_FLUSH_OCCURED_EVT 0x11 +#define HCI_ROLE_CHANGE_EVT 0x12 +#define HCI_NUM_COMPL_DATA_PKTS_EVT 0x13 +#define HCI_MODE_CHANGE_EVT 0x14 +#define HCI_RETURN_LINK_KEYS_EVT 0x15 +#define HCI_PIN_CODE_REQUEST_EVT 0x16 +#define HCI_LINK_KEY_REQUEST_EVT 0x17 +#define HCI_LINK_KEY_NOTIFICATION_EVT 0x18 +#define HCI_LOOPBACK_COMMAND_EVT 0x19 +#define HCI_DATA_BUF_OVERFLOW_EVT 0x1A +#define HCI_MAX_SLOTS_CHANGED_EVT 0x1B +#define HCI_READ_CLOCK_OFF_COMP_EVT 0x1C +#define HCI_CONN_PKT_TYPE_CHANGE_EVT 0x1D +#define HCI_QOS_VIOLATION_EVT 0x1E +#define HCI_PAGE_SCAN_MODE_CHANGE_EVT 0x1F +#define HCI_PAGE_SCAN_REP_MODE_CHNG_EVT 0x20 +#define HCI_FLOW_SPECIFICATION_COMP_EVT 0x21 +#define HCI_INQUIRY_RSSI_RESULT_EVT 0x22 +#define HCI_READ_RMT_EXT_FEATURES_COMP_EVT 0x23 +#define HCI_ESCO_CONNECTION_COMP_EVT 0x2C +#define HCI_ESCO_CONNECTION_CHANGED_EVT 0x2D +#define HCI_SNIFF_SUB_RATE_EVT 0x2E +#define HCI_EXTENDED_INQUIRY_RESULT_EVT 0x2F +#define HCI_ENCRYPTION_KEY_REFRESH_COMP_EVT 0x30 +#define HCI_IO_CAPABILITY_REQUEST_EVT 0x31 +#define HCI_IO_CAPABILITY_RESPONSE_EVT 0x32 +#define HCI_USER_CONFIRMATION_REQUEST_EVT 0x33 +#define HCI_USER_PASSKEY_REQUEST_EVT 0x34 +#define HCI_REMOTE_OOB_DATA_REQUEST_EVT 0x35 +#define HCI_SIMPLE_PAIRING_COMPLETE_EVT 0x36 +#define HCI_LINK_SUPER_TOUT_CHANGED_EVT 0x38 +#define HCI_ENHANCED_FLUSH_COMPLETE_EVT 0x39 +#define HCI_USER_PASSKEY_NOTIFY_EVT 0x3B +#define HCI_KEYPRESS_NOTIFY_EVT 0x3C +#define HCI_RMT_HOST_SUP_FEAT_NOTIFY_EVT 0x3D + +/*#define HCI_GENERIC_AMP_LINK_KEY_NOTIF_EVT 0x3E Removed from spec */ +#define HCI_PHYSICAL_LINK_COMP_EVT 0x40 +#define HCI_CHANNEL_SELECTED_EVT 0x41 +#define HCI_DISC_PHYSICAL_LINK_COMP_EVT 0x42 +#define HCI_PHY_LINK_LOSS_EARLY_WARNING_EVT 0x43 +#define HCI_PHY_LINK_RECOVERY_EVT 0x44 +#define HCI_LOGICAL_LINK_COMP_EVT 0x45 +#define HCI_DISC_LOGICAL_LINK_COMP_EVT 0x46 +#define HCI_FLOW_SPEC_MODIFY_COMP_EVT 0x47 +#define HCI_NUM_COMPL_DATA_BLOCKS_EVT 0x48 +#define HCI_SHORT_RANGE_MODE_COMPLETE_EVT 0x4C +#define HCI_AMP_STATUS_CHANGE_EVT 0x4D +#define HCI_SET_TRIGGERED_CLOCK_CAPTURE_EVT 0x4E + +/* ULP HCI Event */ +#define HCI_BLE_EVENT 0x3e +/* ULP Event sub code */ +#define HCI_BLE_CONN_COMPLETE_EVT 0x01 +#define HCI_BLE_ADV_PKT_RPT_EVT 0x02 +#define HCI_BLE_LL_CONN_PARAM_UPD_EVT 0x03 +#define HCI_BLE_READ_REMOTE_FEAT_CMPL_EVT 0x04 +#define HCI_BLE_LTK_REQ_EVT 0x05 +#define HCI_BLE_RC_PARAM_REQ_EVT 0x06 +#define HCI_BLE_DATA_LENGTH_CHANGE_EVT 0x07 +#define HCI_BLE_ENHANCED_CONN_COMPLETE_EVT 0x0a +#define HCI_BLE_DIRECT_ADV_EVT 0x0b + +/* Definitions for LE Channel Map */ +#define HCI_BLE_CHNL_MAP_SIZE 5 + +#define HCI_VENDOR_SPECIFIC_EVT 0xFF /* Vendor specific events */ +#define HCI_NAP_TRACE_EVT 0xFF /* was define 0xFE, 0xFD, change to 0xFF + because conflict w/ TCI_EVT and per + specification compliant */ + +/* +** Defentions for HCI Error Codes that are past in the events +*/ +#define HCI_SUCCESS 0x00 +#define HCI_PENDING 0x00 +#define HCI_ERR_ILLEGAL_COMMAND 0x01 +#define HCI_ERR_NO_CONNECTION 0x02 +#define HCI_ERR_HW_FAILURE 0x03 +#define HCI_ERR_PAGE_TIMEOUT 0x04 +#define HCI_ERR_AUTH_FAILURE 0x05 +#define HCI_ERR_KEY_MISSING 0x06 +#define HCI_ERR_MEMORY_FULL 0x07 +#define HCI_ERR_CONNECTION_TOUT 0x08 +#define HCI_ERR_MAX_NUM_OF_CONNECTIONS 0x09 +#define HCI_ERR_MAX_NUM_OF_SCOS 0x0A +#define HCI_ERR_CONNECTION_EXISTS 0x0B +#define HCI_ERR_COMMAND_DISALLOWED 0x0C +#define HCI_ERR_HOST_REJECT_RESOURCES 0x0D +#define HCI_ERR_HOST_REJECT_SECURITY 0x0E +#define HCI_ERR_HOST_REJECT_DEVICE 0x0F +#define HCI_ERR_HOST_TIMEOUT 0x10 +#define HCI_ERR_UNSUPPORTED_VALUE 0x11 +#define HCI_ERR_ILLEGAL_PARAMETER_FMT 0x12 +#define HCI_ERR_PEER_USER 0x13 +#define HCI_ERR_PEER_LOW_RESOURCES 0x14 +#define HCI_ERR_PEER_POWER_OFF 0x15 +#define HCI_ERR_CONN_CAUSE_LOCAL_HOST 0x16 +#define HCI_ERR_REPEATED_ATTEMPTS 0x17 +#define HCI_ERR_PAIRING_NOT_ALLOWED 0x18 +#define HCI_ERR_UNKNOWN_LMP_PDU 0x19 +#define HCI_ERR_UNSUPPORTED_REM_FEATURE 0x1A +#define HCI_ERR_SCO_OFFSET_REJECTED 0x1B +#define HCI_ERR_SCO_INTERVAL_REJECTED 0x1C +#define HCI_ERR_SCO_AIR_MODE 0x1D +#define HCI_ERR_INVALID_LMP_PARAM 0x1E +#define HCI_ERR_UNSPECIFIED 0x1F +#define HCI_ERR_UNSUPPORTED_LMP_FEATURE 0x20 +#define HCI_ERR_ROLE_CHANGE_NOT_ALLOWED 0x21 +#define HCI_ERR_LMP_RESPONSE_TIMEOUT 0x22 +#define HCI_ERR_LMP_ERR_TRANS_COLLISION 0x23 +#define HCI_ERR_LMP_PDU_NOT_ALLOWED 0x24 +#define HCI_ERR_ENCRY_MODE_NOT_ACCEPTABLE 0x25 +#define HCI_ERR_UNIT_KEY_USED 0x26 +#define HCI_ERR_QOS_NOT_SUPPORTED 0x27 +#define HCI_ERR_INSTANT_PASSED 0x28 +#define HCI_ERR_PAIRING_WITH_UNIT_KEY_NOT_SUPPORTED 0x29 +#define HCI_ERR_DIFF_TRANSACTION_COLLISION 0x2A +#define HCI_ERR_UNDEFINED_0x2B 0x2B +#define HCI_ERR_QOS_UNACCEPTABLE_PARAM 0x2C +#define HCI_ERR_QOS_REJECTED 0x2D +#define HCI_ERR_CHAN_CLASSIF_NOT_SUPPORTED 0x2E +#define HCI_ERR_INSUFFCIENT_SECURITY 0x2F +#define HCI_ERR_PARAM_OUT_OF_RANGE 0x30 +#define HCI_ERR_UNDEFINED_0x31 0x31 +#define HCI_ERR_ROLE_SWITCH_PENDING 0x32 +#define HCI_ERR_UNDEFINED_0x33 0x33 +#define HCI_ERR_RESERVED_SLOT_VIOLATION 0x34 +#define HCI_ERR_ROLE_SWITCH_FAILED 0x35 +#define HCI_ERR_INQ_RSP_DATA_TOO_LARGE 0x36 +#define HCI_ERR_SIMPLE_PAIRING_NOT_SUPPORTED 0x37 +#define HCI_ERR_HOST_BUSY_PAIRING 0x38 +#define HCI_ERR_REJ_NO_SUITABLE_CHANNEL 0x39 +#define HCI_ERR_CONTROLLER_BUSY 0x3A +#define HCI_ERR_UNACCEPT_CONN_INTERVAL 0x3B +#define HCI_ERR_DIRECTED_ADVERTISING_TIMEOUT 0x3C +#define HCI_ERR_CONN_TOUT_DUE_TO_MIC_FAILURE 0x3D +#define HCI_ERR_CONN_FAILED_ESTABLISHMENT 0x3E +#define HCI_ERR_MAC_CONNECTION_FAILED 0x3F + +/* ConnectionLess Broadcast errors */ +#define HCI_ERR_LT_ADDR_ALREADY_IN_USE 0x40 +#define HCI_ERR_LT_ADDR_NOT_ALLOCATED 0x41 +#define HCI_ERR_CLB_NOT_ENABLED 0x42 +#define HCI_ERR_CLB_DATA_TOO_BIG 0x43 + +#define HCI_ERR_MAX_ERR 0x43 + +#define HCI_HINT_TO_RECREATE_AMP_PHYS_LINK 0xFF + +/* +** Definitions for HCI enable event +*/ +#define HCI_INQUIRY_COMPLETE_EV(p) (*((UINT32 *)(p)) & 0x00000001) +#define HCI_INQUIRY_RESULT_EV(p) (*((UINT32 *)(p)) & 0x00000002) +#define HCI_CONNECTION_COMPLETE_EV(p) (*((UINT32 *)(p)) & 0x00000004) +#define HCI_CONNECTION_REQUEST_EV(p) (*((UINT32 *)(p)) & 0x00000008) +#define HCI_DISCONNECTION_COMPLETE_EV(p) (*((UINT32 *)(p)) & 0x00000010) +#define HCI_AUTHENTICATION_COMPLETE_EV(p) (*((UINT32 *)(p)) & 0x00000020) +#define HCI_RMT_NAME_REQUEST_COMPL_EV(p) (*((UINT32 *)(p)) & 0x00000040) +#define HCI_CHANGE_CONN_ENCRPT_ENABLE_EV(p) (*((UINT32 *)(p)) & 0x00000080) +#define HCI_CHANGE_CONN_LINK_KEY_EV(p) (*((UINT32 *)(p)) & 0x00000100) +#define HCI_MASTER_LINK_KEY_COMPLETE_EV(p) (*((UINT32 *)(p)) & 0x00000200) +#define HCI_READ_RMT_FEATURES_COMPL_EV(p) (*((UINT32 *)(p)) & 0x00000400) +#define HCI_READ_RMT_VERSION_COMPL_EV(p) (*((UINT32 *)(p)) & 0x00000800) +#define HCI_QOS_SETUP_COMPLETE_EV(p) (*((UINT32 *)(p)) & 0x00001000) +#define HCI_COMMAND_COMPLETE_EV(p) (*((UINT32 *)(p)) & 0x00002000) +#define HCI_COMMAND_STATUS_EV(p) (*((UINT32 *)(p)) & 0x00004000) +#define HCI_HARDWARE_ERROR_EV(p) (*((UINT32 *)(p)) & 0x00008000) +#define HCI_FLASH_OCCURED_EV(p) (*((UINT32 *)(p)) & 0x00010000) +#define HCI_ROLE_CHANGE_EV(p) (*((UINT32 *)(p)) & 0x00020000) +#define HCI_NUM_COMPLETED_PKTS_EV(p) (*((UINT32 *)(p)) & 0x00040000) +#define HCI_MODE_CHANGE_EV(p) (*((UINT32 *)(p)) & 0x00080000) +#define HCI_RETURN_LINK_KEYS_EV(p) (*((UINT32 *)(p)) & 0x00100000) +#define HCI_PIN_CODE_REQUEST_EV(p) (*((UINT32 *)(p)) & 0x00200000) +#define HCI_LINK_KEY_REQUEST_EV(p) (*((UINT32 *)(p)) & 0x00400000) +#define HCI_LINK_KEY_NOTIFICATION_EV(p) (*((UINT32 *)(p)) & 0x00800000) +#define HCI_LOOPBACK_COMMAND_EV(p) (*((UINT32 *)(p)) & 0x01000000) +#define HCI_DATA_BUF_OVERFLOW_EV(p) (*((UINT32 *)(p)) & 0x02000000) +#define HCI_MAX_SLOTS_CHANGE_EV(p) (*((UINT32 *)(p)) & 0x04000000) +#define HCI_READ_CLOCK_OFFSET_COMP_EV(p) (*((UINT32 *)(p)) & 0x08000000) +#define HCI_CONN_PKT_TYPE_CHANGED_EV(p) (*((UINT32 *)(p)) & 0x10000000) +#define HCI_QOS_VIOLATION_EV(p) (*((UINT32 *)(p)) & 0x20000000) +#define HCI_PAGE_SCAN_MODE_CHANGED_EV(p) (*((UINT32 *)(p)) & 0x40000000) +#define HCI_PAGE_SCAN_REP_MODE_CHNG_EV(p) (*((UINT32 *)(p)) & 0x80000000) + +/* the default event mask for 2.1+EDR (Lisbon) does not include Lisbon events */ +#define HCI_DEFAULT_EVENT_MASK_0 0xFFFFFFFF +#define HCI_DEFAULT_EVENT_MASK_1 0x00001FFF + +/* the event mask for 2.0 + EDR and later (includes Lisbon events) */ +#define HCI_LISBON_EVENT_MASK_0 0xFFFFFFFF +#define HCI_LISBON_EVENT_MASK_1 0x1DBFFFFF +#define HCI_LISBON_EVENT_MASK "\x0D\xBF\xFF\xFF\xFF\xFF\xFF\xFF" +#define HCI_LISBON_EVENT_MASK_EXT "\x1D\xBF\xFF\xFF\xFF\xFF\xFF\xFF" +#define HCI_DUMO_EVENT_MASK_EXT "\x3D\xBF\xFF\xFF\xFF\xFF\xFF\xFF" +/* 0x00001FFF FFFFFFFF Default - no Lisbon events + 0x00000800 00000000 Synchronous Connection Complete Event + 0x00001000 00000000 Synchronous Connection Changed Event + 0x00002000 00000000 Sniff Subrate Event + 0x00004000 00000000 Extended Inquiry Result Event + 0x00008000 00000000 Encryption Key Refresh Complete Event + 0x00010000 00000000 IO Capability Request Event + 0x00020000 00000000 IO Capability Response Event + 0x00040000 00000000 User Confirmation Request Event + 0x00080000 00000000 User Passkey Request Event + 0x00100000 00000000 Remote OOB Data Request Event + 0x00200000 00000000 Simple Pairing Complete Event + 0x00400000 00000000 Generic AMP Link Key Notification Event + 0x00800000 00000000 Link Supervision Timeout Changed Event + 0x01000000 00000000 Enhanced Flush Complete Event + 0x04000000 00000000 User Passkey Notification Event + 0x08000000 00000000 Keypress Notification Event + 0x10000000 00000000 Remote Host Supported Features Notification Event + 0x20000000 00000000 LE Meta Event + */ + + +/* the event mask for AMP controllers */ +#define HCI_AMP_EVENT_MASK_3_0 "\x00\x00\x00\x00\x00\x00\x3F\xFF" + +/* 0x0000000000000000 No events specified (default) + 0x0000000000000001 Physical Link Complete Event + 0x0000000000000002 Channel Selected Event + 0x0000000000000004 Disconnection Physical Link Event + 0x0000000000000008 Physical Link Loss Early Warning Event + 0x0000000000000010 Physical Link Recovery Event + 0x0000000000000020 Logical Link Complete Event + 0x0000000000000040 Disconnection Logical Link Complete Event + 0x0000000000000080 Flow Spec Modify Complete Event + 0x0000000000000100 Number of Completed Data Blocks Event + 0x0000000000000200 AMP Start Test Event + 0x0000000000000400 AMP Test End Event + 0x0000000000000800 AMP Receiver Report Event + 0x0000000000001000 Short Range Mode Change Complete Event + 0x0000000000002000 AMP Status Change Event +*/ + +/* the event mask page 2 (CLB + CSA4) for BR/EDR controller */ +#define HCI_PAGE_2_EVENT_MASK "\x00\x00\x00\x00\x00\x7F\xC0\x00" +/* 0x0000000000004000 Triggered Clock Capture Event + 0x0000000000008000 Sync Train Complete Event + 0x0000000000010000 Sync Train Received Event + 0x0000000000020000 Connectionless Broadcast Receive Event + 0x0000000000040000 Connectionless Broadcast Timeout Event + 0x0000000000080000 Truncated Page Complete Event + 0x0000000000100000 Salve Page Response Timeout Event + 0x0000000000200000 Connectionless Broadcast Channel Map Change Event + 0x0000000000400000 Inquiry Response Notification Event +*/ +#if BLE_PRIVACY_SPT == TRUE +/* BLE event mask */ +#define HCI_BLE_EVENT_MASK_DEF "\x00\x00\x00\x00\x00\x00\x07\xff" +#else +#define HCI_BLE_EVENT_MASK_DEF "\x00\x00\x00\x00\x00\x00\x00\x7f" +#endif +/* +** Definitions for packet type masks (BT1.2 and BT2.0 definitions) +*/ +#define HCI_PKT_TYPES_MASK_NO_2_DH1 0x0002 +#define HCI_PKT_TYPES_MASK_NO_3_DH1 0x0004 +#define HCI_PKT_TYPES_MASK_DM1 0x0008 +#define HCI_PKT_TYPES_MASK_DH1 0x0010 +#define HCI_PKT_TYPES_MASK_HV1 0x0020 +#define HCI_PKT_TYPES_MASK_HV2 0x0040 +#define HCI_PKT_TYPES_MASK_HV3 0x0080 +#define HCI_PKT_TYPES_MASK_NO_2_DH3 0x0100 +#define HCI_PKT_TYPES_MASK_NO_3_DH3 0x0200 +#define HCI_PKT_TYPES_MASK_DM3 0x0400 +#define HCI_PKT_TYPES_MASK_DH3 0x0800 +#define HCI_PKT_TYPES_MASK_NO_2_DH5 0x1000 +#define HCI_PKT_TYPES_MASK_NO_3_DH5 0x2000 +#define HCI_PKT_TYPES_MASK_DM5 0x4000 +#define HCI_PKT_TYPES_MASK_DH5 0x8000 + +/* Packet type should be one of valid but at least one should be specified */ +#define HCI_VALID_SCO_PKT_TYPE(t) (((((t) & ~(HCI_PKT_TYPES_MASK_HV1 \ + | HCI_PKT_TYPES_MASK_HV2 \ + | HCI_PKT_TYPES_MASK_HV3)) == 0)) \ + && ((t) != 0)) + + + + + +/* Packet type should not be invalid and at least one should be specified */ +#define HCI_VALID_ACL_PKT_TYPE(t) (((((t) & ~(HCI_PKT_TYPES_MASK_DM1 \ + | HCI_PKT_TYPES_MASK_DH1 \ + | HCI_PKT_TYPES_MASK_DM3 \ + | HCI_PKT_TYPES_MASK_DH3 \ + | HCI_PKT_TYPES_MASK_DM5 \ + | HCI_PKT_TYPES_MASK_DH5 \ + | HCI_PKT_TYPES_MASK_NO_2_DH1 \ + | HCI_PKT_TYPES_MASK_NO_3_DH1 \ + | HCI_PKT_TYPES_MASK_NO_2_DH3 \ + | HCI_PKT_TYPES_MASK_NO_3_DH3 \ + | HCI_PKT_TYPES_MASK_NO_2_DH5 \ + | HCI_PKT_TYPES_MASK_NO_3_DH5 )) == 0)) \ + && (((t) & (HCI_PKT_TYPES_MASK_DM1 \ + | HCI_PKT_TYPES_MASK_DH1 \ + | HCI_PKT_TYPES_MASK_DM3 \ + | HCI_PKT_TYPES_MASK_DH3 \ + | HCI_PKT_TYPES_MASK_DM5 \ + | HCI_PKT_TYPES_MASK_DH5)) != 0)) + +/* +** Definitions for eSCO packet type masks (BT1.2 and BT2.0 definitions) +*/ +#define HCI_ESCO_PKT_TYPES_MASK_HV1 0x0001 +#define HCI_ESCO_PKT_TYPES_MASK_HV2 0x0002 +#define HCI_ESCO_PKT_TYPES_MASK_HV3 0x0004 +#define HCI_ESCO_PKT_TYPES_MASK_EV3 0x0008 +#define HCI_ESCO_PKT_TYPES_MASK_EV4 0x0010 +#define HCI_ESCO_PKT_TYPES_MASK_EV5 0x0020 +#define HCI_ESCO_PKT_TYPES_MASK_NO_2_EV3 0x0040 +#define HCI_ESCO_PKT_TYPES_MASK_NO_3_EV3 0x0080 +#define HCI_ESCO_PKT_TYPES_MASK_NO_2_EV5 0x0100 +#define HCI_ESCO_PKT_TYPES_MASK_NO_3_EV5 0x0200 + +/* Packet type should be one of valid but at least one should be specified for 1.2 */ +#define HCI_VALID_ESCO_PKT_TYPE(t) (((((t) & ~(HCI_ESCO_PKT_TYPES_MASK_EV3 \ + | HCI_ESCO_PKT_TYPES_MASK_EV4 \ + | HCI_ESCO_PKT_TYPES_MASK_EV5)) == 0)) \ + && ((t) != 0))/* Packet type should be one of valid but at least one should be specified */ + +#define HCI_VALID_ESCO_SCOPKT_TYPE(t) (((((t) & ~(HCI_ESCO_PKT_TYPES_MASK_HV1 \ + | HCI_ESCO_PKT_TYPES_MASK_HV2 \ + | HCI_ESCO_PKT_TYPES_MASK_HV3)) == 0)) \ + && ((t) != 0)) + +#define HCI_VALID_SCO_ALL_PKT_TYPE(t) (((((t) & ~(HCI_ESCO_PKT_TYPES_MASK_HV1 \ + | HCI_ESCO_PKT_TYPES_MASK_HV2 \ + | HCI_ESCO_PKT_TYPES_MASK_HV3 \ + | HCI_ESCO_PKT_TYPES_MASK_EV3 \ + | HCI_ESCO_PKT_TYPES_MASK_EV4 \ + | HCI_ESCO_PKT_TYPES_MASK_EV5)) == 0)) \ + && ((t) != 0)) + +/* +** Define parameters to allow role switch during create connection +*/ +#define HCI_CR_CONN_NOT_ALLOW_SWITCH 0x00 +#define HCI_CR_CONN_ALLOW_SWITCH 0x01 + +/* +** Hold Mode command destination +*/ +#define HOLD_MODE_DEST_LOCAL_DEVICE 0x00 +#define HOLD_MODE_DEST_RMT_DEVICE 0x01 + +/* +** Definitions for different HCI parameters +*/ +#define HCI_PER_INQ_MIN_MAX_PERIOD 0x0003 +#define HCI_PER_INQ_MAX_MAX_PERIOD 0xFFFF +#define HCI_PER_INQ_MIN_MIN_PERIOD 0x0002 +#define HCI_PER_INQ_MAX_MIN_PERIOD 0xFFFE + +#define HCI_MAX_INQUIRY_LENGTH 0x30 + +#define HCI_MIN_INQ_LAP 0x9E8B00 +#define HCI_MAX_INQ_LAP 0x9E8B3F + +/* HCI role defenitions */ +#define HCI_ROLE_MASTER 0x00 +#define HCI_ROLE_SLAVE 0x01 +#define HCI_ROLE_UNKNOWN 0xff + +/* HCI mode defenitions */ +#define HCI_MODE_ACTIVE 0x00 +#define HCI_MODE_HOLD 0x01 +#define HCI_MODE_SNIFF 0x02 +#define HCI_MODE_PARK 0x03 + +/* HCI Flow Control Mode defenitions */ +#define HCI_PACKET_BASED_FC_MODE 0x00 +#define HCI_BLOCK_BASED_FC_MODE 0x01 + +/* Define Packet types as requested by the Host */ +#define HCI_ACL_PKT_TYPE_NONE 0x0000 +#define HCI_ACL_PKT_TYPE_DM1 0x0008 +#define HCI_ACL_PKT_TYPE_DH1 0x0010 +#define HCI_ACL_PKT_TYPE_AUX1 0x0200 +#define HCI_ACL_PKT_TYPE_DM3 0x0400 +#define HCI_ACL_PKT_TYPE_DH3 0x0800 +#define HCI_ACL_PKT_TYPE_DM5 0x4000 +#define HCI_ACL_PKT_TYPE_DH5 0x8000 + +/* Define key type in the Master Link Key command */ +#define HCI_USE_SEMI_PERMANENT_KEY 0x00 +#define HCI_USE_TEMPORARY_KEY 0x01 + +/* Page scan period modes */ +#define HCI_PAGE_SCAN_REP_MODE_R0 0x00 +#define HCI_PAGE_SCAN_REP_MODE_R1 0x01 +#define HCI_PAGE_SCAN_REP_MODE_R2 0x02 + +/* Define limits for page scan repetition modes */ +#define HCI_PAGE_SCAN_R1_LIMIT 0x0800 +#define HCI_PAGE_SCAN_R2_LIMIT 0x1000 + +/* Page scan period modes */ +#define HCI_PAGE_SCAN_PER_MODE_P0 0x00 +#define HCI_PAGE_SCAN_PER_MODE_P1 0x01 +#define HCI_PAGE_SCAN_PER_MODE_P2 0x02 + +/* Page scan modes */ +#define HCI_MANDATARY_PAGE_SCAN_MODE 0x00 +#define HCI_OPTIONAL_PAGE_SCAN_MODE1 0x01 +#define HCI_OPTIONAL_PAGE_SCAN_MODE2 0x02 +#define HCI_OPTIONAL_PAGE_SCAN_MODE3 0x03 + +/* Page and inquiry scan types */ +#define HCI_SCAN_TYPE_STANDARD 0x00 +#define HCI_SCAN_TYPE_INTERLACED 0x01 /* 1.2 devices or later */ +#define HCI_DEF_SCAN_TYPE HCI_SCAN_TYPE_STANDARD + +/* Definitions for quality of service service types */ +#define HCI_SERVICE_NO_TRAFFIC 0x00 +#define HCI_SERVICE_BEST_EFFORT 0x01 +#define HCI_SERVICE_GUARANTEED 0x02 + +#define HCI_QOS_LATENCY_DO_NOT_CARE 0xFFFFFFFF +#define HCI_QOS_DELAY_DO_NOT_CARE 0xFFFFFFFF + +/* Definitions for Flow Specification */ +#define HCI_FLOW_SPEC_LATENCY_DO_NOT_CARE 0xFFFFFFFF + +/* Definitions for AFH Channel Map */ +#define HCI_AFH_CHANNEL_MAP_LEN 10 + +/* Definitions for Extended Inquiry Response */ +#define HCI_EXT_INQ_RESPONSE_LEN 240 +#define HCI_EIR_FLAGS_TYPE BT_EIR_FLAGS_TYPE +#define HCI_EIR_MORE_16BITS_UUID_TYPE BT_EIR_MORE_16BITS_UUID_TYPE +#define HCI_EIR_COMPLETE_16BITS_UUID_TYPE BT_EIR_COMPLETE_16BITS_UUID_TYPE +#define HCI_EIR_MORE_32BITS_UUID_TYPE BT_EIR_MORE_32BITS_UUID_TYPE +#define HCI_EIR_COMPLETE_32BITS_UUID_TYPE BT_EIR_COMPLETE_32BITS_UUID_TYPE +#define HCI_EIR_MORE_128BITS_UUID_TYPE BT_EIR_MORE_128BITS_UUID_TYPE +#define HCI_EIR_COMPLETE_128BITS_UUID_TYPE BT_EIR_COMPLETE_128BITS_UUID_TYPE +#define HCI_EIR_SHORTENED_LOCAL_NAME_TYPE BT_EIR_SHORTENED_LOCAL_NAME_TYPE +#define HCI_EIR_COMPLETE_LOCAL_NAME_TYPE BT_EIR_COMPLETE_LOCAL_NAME_TYPE +#define HCI_EIR_TX_POWER_LEVEL_TYPE BT_EIR_TX_POWER_LEVEL_TYPE +#define HCI_EIR_MANUFACTURER_SPECIFIC_TYPE BT_EIR_MANUFACTURER_SPECIFIC_TYPE +#define HCI_EIR_OOB_BD_ADDR_TYPE BT_EIR_OOB_BD_ADDR_TYPE +#define HCI_EIR_OOB_COD_TYPE BT_EIR_OOB_COD_TYPE +#define HCI_EIR_OOB_SSP_HASH_C_TYPE BT_EIR_OOB_SSP_HASH_C_TYPE +#define HCI_EIR_OOB_SSP_RAND_R_TYPE BT_EIR_OOB_SSP_RAND_R_TYPE + +/* Definitions for Write Simple Pairing Mode */ +#define HCI_SP_MODE_UNDEFINED 0x00 +#define HCI_SP_MODE_ENABLED 0x01 + +/* Definitions for Write Simple Pairing Debug Mode */ +#define HCI_SPD_MODE_DISABLED 0x00 +#define HCI_SPD_MODE_ENABLED 0x01 + +/* Definitions for Write Secure Connections Host Support */ +#define HCI_SC_MODE_DISABLED 0x00 +#define HCI_SC_MODE_ENABLED 0x01 + +/* Definitions for IO Capability Response/Command */ +#define HCI_IO_CAP_DISPLAY_ONLY 0x00 +#define HCI_IO_CAP_DISPLAY_YESNO 0x01 +#define HCI_IO_CAP_KEYBOARD_ONLY 0x02 +#define HCI_IO_CAP_NO_IO 0x03 + +#define HCI_OOB_AUTH_DATA_NOT_PRESENT 0x00 +#define HCI_OOB_REM_AUTH_DATA_PRESENT 0x01 + +#define HCI_MITM_PROTECT_NOT_REQUIRED 0x00 +#define HCI_MITM_PROTECT_REQUIRED 0x01 + + +/* Policy settings status */ +#define HCI_DISABLE_ALL_LM_MODES 0x0000 +#define HCI_ENABLE_MASTER_SLAVE_SWITCH 0x0001 +#define HCI_ENABLE_HOLD_MODE 0x0002 +#define HCI_ENABLE_SNIFF_MODE 0x0004 +#define HCI_ENABLE_PARK_MODE 0x0008 + +/* By default allow switch, because host can not allow that */ +/* that until he created the connection */ +#define HCI_DEFAULT_POLICY_SETTINGS HCI_DISABLE_ALL_LM_MODES + +/* Filters that are sent in set filter command */ +#define HCI_FILTER_TYPE_CLEAR_ALL 0x00 +#define HCI_FILTER_INQUIRY_RESULT 0x01 +#define HCI_FILTER_CONNECTION_SETUP 0x02 + +#define HCI_FILTER_COND_NEW_DEVICE 0x00 +#define HCI_FILTER_COND_DEVICE_CLASS 0x01 +#define HCI_FILTER_COND_BD_ADDR 0x02 + +#define HCI_DO_NOT_AUTO_ACCEPT_CONNECT 1 +#define HCI_DO_AUTO_ACCEPT_CONNECT 2 /* role switch disabled */ +#define HCI_DO_AUTO_ACCEPT_CONNECT_RS 3 /* role switch enabled (1.1 errata 1115) */ + +/* Auto accept flags */ +#define HCI_AUTO_ACCEPT_OFF 0x00 +#define HCI_AUTO_ACCEPT_ACL_CONNECTIONS 0x01 +#define HCI_AUTO_ACCEPT_SCO_CONNECTIONS 0x02 + +/* PIN type */ +#define HCI_PIN_TYPE_VARIABLE 0 +#define HCI_PIN_TYPE_FIXED 1 + +/* Loopback Modes */ +#define HCI_LOOPBACK_MODE_DISABLED 0 +#define HCI_LOOPBACK_MODE_LOCAL 1 +#define HCI_LOOPBACK_MODE_REMOTE 2 + +#define SLOTS_PER_10MS 16 /* 0.625 ms slots in a 10 ms tick */ + +/* Maximum connection accept timeout in 0.625msec */ +#define HCI_MAX_CONN_ACCEPT_TOUT 0xB540 /* 29 sec */ +#define HCI_DEF_CONN_ACCEPT_TOUT 0x1F40 /* 5 sec */ + +/* Page timeout is used in LC only and LC is counting down slots not using OS */ +#define HCI_DEFAULT_PAGE_TOUT 0x2000 /* 5.12 sec (in slots) */ + +/* Scan enable flags */ +#define HCI_NO_SCAN_ENABLED 0x00 +#define HCI_INQUIRY_SCAN_ENABLED 0x01 +#define HCI_PAGE_SCAN_ENABLED 0x02 + +/* Pagescan timer definitions in 0.625 ms */ +#define HCI_MIN_PAGESCAN_INTERVAL 0x12 /* 11.25 ms */ +#define HCI_MAX_PAGESCAN_INTERVAL 0x1000 /* 2.56 sec */ +#define HCI_DEF_PAGESCAN_INTERVAL 0x0800 /* 1.28 sec */ + +/* Parameter for pagescan window is passed to LC and is kept in slots */ +#define HCI_MIN_PAGESCAN_WINDOW 0x11 /* 10.625 ms */ +#define HCI_MAX_PAGESCAN_WINDOW 0x1000 /* 2.56 sec */ +#define HCI_DEF_PAGESCAN_WINDOW 0x12 /* 11.25 ms */ + +/* Inquiryscan timer definitions in 0.625 ms */ +#define HCI_MIN_INQUIRYSCAN_INTERVAL 0x12 /* 11.25 ms */ +#define HCI_MAX_INQUIRYSCAN_INTERVAL 0x1000 /* 2.56 sec */ +#define HCI_DEF_INQUIRYSCAN_INTERVAL 0x1000 /* 2.56 sec */ + +/* Parameter for inquiryscan window is passed to LC and is kept in slots */ +#define HCI_MIN_INQUIRYSCAN_WINDOW 0x11 /* 10.625 ms */ +#define HCI_MAX_INQUIRYSCAN_WINDOW 0x1000 /* 2.56 sec */ +#define HCI_DEF_INQUIRYSCAN_WINDOW 0x12 /* 11.25 ms */ + +/* Encryption modes */ +#define HCI_ENCRYPT_MODE_DISABLED 0x00 +#define HCI_ENCRYPT_MODE_POINT_TO_POINT 0x01 +#define HCI_ENCRYPT_MODE_ALL 0x02 + +/* Voice settings */ +#define HCI_INP_CODING_LINEAR 0x0000 /* 0000000000 */ +#define HCI_INP_CODING_U_LAW 0x0100 /* 0100000000 */ +#define HCI_INP_CODING_A_LAW 0x0200 /* 1000000000 */ +#define HCI_INP_CODING_MASK 0x0300 /* 1100000000 */ + +#define HCI_INP_DATA_FMT_1S_COMPLEMENT 0x0000 /* 0000000000 */ +#define HCI_INP_DATA_FMT_2S_COMPLEMENT 0x0040 /* 0001000000 */ +#define HCI_INP_DATA_FMT_SIGN_MAGNITUDE 0x0080 /* 0010000000 */ +#define HCI_INP_DATA_FMT_UNSIGNED 0x00c0 /* 0011000000 */ +#define HCI_INP_DATA_FMT_MASK 0x00c0 /* 0011000000 */ + +#define HCI_INP_SAMPLE_SIZE_8BIT 0x0000 /* 0000000000 */ +#define HCI_INP_SAMPLE_SIZE_16BIT 0x0020 /* 0000100000 */ +#define HCI_INP_SAMPLE_SIZE_MASK 0x0020 /* 0000100000 */ + +#define HCI_INP_LINEAR_PCM_BIT_POS_MASK 0x001c /* 0000011100 */ +#define HCI_INP_LINEAR_PCM_BIT_POS_OFFS 2 + +#define HCI_AIR_CODING_FORMAT_CVSD 0x0000 /* 0000000000 */ +#define HCI_AIR_CODING_FORMAT_U_LAW 0x0001 /* 0000000001 */ +#define HCI_AIR_CODING_FORMAT_A_LAW 0x0002 /* 0000000010 */ +#define HCI_AIR_CODING_FORMAT_TRANSPNT 0x0003 /* 0000000011 */ +#define HCI_AIR_CODING_FORMAT_MASK 0x0003 /* 0000000011 */ + +/* default 0001100000 */ +#define HCI_DEFAULT_VOICE_SETTINGS (HCI_INP_CODING_LINEAR \ + | HCI_INP_DATA_FMT_2S_COMPLEMENT \ + | HCI_INP_SAMPLE_SIZE_16BIT \ + | HCI_AIR_CODING_FORMAT_CVSD) + +#define HCI_CVSD_SUPPORTED(x) (((x) & HCI_AIR_CODING_FORMAT_MASK) == HCI_AIR_CODING_FORMAT_CVSD) +#define HCI_U_LAW_SUPPORTED(x) (((x) & HCI_AIR_CODING_FORMAT_MASK) == HCI_AIR_CODING_FORMAT_U_LAW) +#define HCI_A_LAW_SUPPORTED(x) (((x) & HCI_AIR_CODING_FORMAT_MASK) == HCI_AIR_CODING_FORMAT_A_LAW) +#define HCI_TRANSPNT_SUPPORTED(x) (((x) & HCI_AIR_CODING_FORMAT_MASK) == HCI_AIR_CODING_FORMAT_TRANSPNT) + +/* Retransmit timer definitions in 0.625 */ +#define HCI_MAX_AUTO_FLUSH_TOUT 0x07FF +#define HCI_DEFAULT_AUTO_FLUSH_TOUT 0 /* No auto flush */ + +/* Broadcast retransmitions */ +#define HCI_DEFAULT_NUM_BCAST_RETRAN 1 + +/* Define broadcast data types as passed in the hci data packet */ +#define HCI_DATA_POINT_TO_POINT 0x00 +#define HCI_DATA_ACTIVE_BCAST 0x01 +#define HCI_DATA_PICONET_BCAST 0x02 + +/* Hold mode activity */ +#define HCI_MAINTAIN_CUR_POWER_STATE 0x00 +#define HCI_SUSPEND_PAGE_SCAN 0x01 +#define HCI_SUSPEND_INQUIRY_SCAN 0x02 +#define HCI_SUSPEND_PERIODIC_INQUIRIES 0x04 + +/* Default Link Supervision timeoout */ +#define HCI_DEFAULT_INACT_TOUT 0x7D00 /* BR/EDR (20 seconds) */ +#define HCI_DEFAULT_AMP_INACT_TOUT 0x3E80 /* AMP (10 seconds) */ + +/* Read transmit power level parameter */ +#define HCI_READ_CURRENT 0x00 +#define HCI_READ_MAXIMUM 0x01 + +/* Link types for connection complete event */ +#define HCI_LINK_TYPE_SCO 0x00 +#define HCI_LINK_TYPE_ACL 0x01 +#define HCI_LINK_TYPE_ESCO 0x02 + +/* Link Key Notification Event (Key Type) definitions */ +#define HCI_LKEY_TYPE_COMBINATION 0x00 +#define HCI_LKEY_TYPE_LOCAL_UNIT 0x01 +#define HCI_LKEY_TYPE_REMOTE_UNIT 0x02 +#define HCI_LKEY_TYPE_DEBUG_COMB 0x03 +#define HCI_LKEY_TYPE_UNAUTH_COMB 0x04 +#define HCI_LKEY_TYPE_AUTH_COMB 0x05 +#define HCI_LKEY_TYPE_CHANGED_COMB 0x06 +#define HCI_LKEY_TYPE_UNAUTH_COMB_P_256 0x07 +#define HCI_LKEY_TYPE_AUTH_COMB_P_256 0x08 + +/* Internal definitions - not used over HCI */ +#define HCI_LKEY_TYPE_AMP_WIFI 0x80 +#define HCI_LKEY_TYPE_AMP_UWB 0x81 +#define HCI_LKEY_TYPE_UNKNOWN 0xff + +/* Read Local Version HCI Version return values (Command Complete Event) */ +#define HCI_VERSION_1_0B 0x00 +#define HCI_VERSION_1_1 0x01 + +/* Define an invalid value for a handle */ +#define HCI_INVALID_HANDLE 0xFFFF + +/* Define max ammount of data in the HCI command */ +#define HCI_COMMAND_SIZE 255 + +/* Define the preamble length for all HCI Commands. +** This is 2-bytes for opcode and 1 byte for length +*/ +#define HCIC_PREAMBLE_SIZE 3 + +/* Define the preamble length for all HCI Events +** This is 1-byte for opcode and 1 byte for length +*/ +#define HCIE_PREAMBLE_SIZE 2 +#define HCI_SCO_PREAMBLE_SIZE 3 +#define HCI_DATA_PREAMBLE_SIZE 4 + +/* local Bluetooth controller id for AMP HCI */ +#define LOCAL_BR_EDR_CONTROLLER_ID 0 + +/* controller id types for AMP HCI */ +#define HCI_CONTROLLER_TYPE_BR_EDR 0 +#define HCI_CONTROLLER_TYPE_802_11 1 +#define HCI_CONTROLLER_TYPE_ECMA 2 +#define HCI_MAX_CONTROLLER_TYPES 3 + +/* ConnectionLess Broadcast */ +#define HCI_CLB_DISABLE 0x00 +#define HCI_CLB_ENABLE 0x01 + +/* ConnectionLess Broadcast Data fragment */ +#define HCI_CLB_FRAGMENT_CONT 0x00 +#define HCI_CLB_FRAGMENT_START 0x01 +#define HCI_CLB_FRAGMENT_END 0x02 +#define HCI_CLB_FRAGMENT_SINGLE 0x03 + +/* AMP Controller Status codes +*/ +#define HCI_AMP_CTRLR_PHYSICALLY_DOWN 0 +#define HCI_AMP_CTRLR_USABLE_BY_BT 1 +#define HCI_AMP_CTRLR_UNUSABLE_FOR_BT 2 +#define HCI_AMP_CTRLR_LOW_CAP_FOR_BT 3 +#define HCI_AMP_CTRLR_MED_CAP_FOR_BT 4 +#define HCI_AMP_CTRLR_HIGH_CAP_FOR_BT 5 +#define HCI_AMP_CTRLR_FULL_CAP_FOR_BT 6 + +#define HCI_MAX_AMP_STATUS_TYPES 7 + + +/* Define the extended flow specification fields used by AMP */ +typedef struct { + UINT8 id; + UINT8 stype; + UINT16 max_sdu_size; + UINT32 sdu_inter_time; + UINT32 access_latency; + UINT32 flush_timeout; +} tHCI_EXT_FLOW_SPEC; + + +/* HCI message type definitions (for H4 messages) */ +#define HCIT_TYPE_COMMAND 1 +#define HCIT_TYPE_ACL_DATA 2 +#define HCIT_TYPE_SCO_DATA 3 +#define HCIT_TYPE_EVENT 4 +#define HCIT_TYPE_LM_DIAG 7 +#define HCIT_TYPE_NFC 16 + +#define HCIT_LM_DIAG_LENGTH 63 + +/* Parameter information for HCI_BRCM_SET_ACL_PRIORITY */ +#define HCI_BRCM_ACL_PRIORITY_PARAM_SIZE 3 +#define HCI_BRCM_ACL_PRIORITY_LOW 0x00 +#define HCI_BRCM_ACL_PRIORITY_HIGH 0xFF +#define HCI_BRCM_SET_ACL_PRIORITY (0x0057 | HCI_GRP_VENDOR_SPECIFIC) + +/* Define values for LMP Test Control parameters +** Test Scenario, Hopping Mode, Power Control Mode +*/ +#define LMP_TESTCTL_TESTSC_PAUSE 0 +#define LMP_TESTCTL_TESTSC_TXTEST_0 1 +#define LMP_TESTCTL_TESTSC_TXTEST_1 2 +#define LMP_TESTCTL_TESTSC_TXTEST_1010 3 +#define LMP_TESTCTL_TESTSC_PSRND_BITSEQ 4 +#define LMP_TESTCTL_TESTSC_CLOSEDLB_ACL 5 +#define LMP_TESTCTL_TESTSC_CLOSEDLB_SCO 6 +#define LMP_TESTCTL_TESTSC_ACL_NOWHIT 7 +#define LMP_TESTCTL_TESTSC_SCO_NOWHIT 8 +#define LMP_TESTCTL_TESTSC_TXTEST_11110000 9 +#define LMP_TESTCTL_TESTSC_EXITTESTMODE 255 + +#define LMP_TESTCTL_HOPMOD_RXTX1FREQ 0 +#define LMP_TESTCTL_HOPMOD_HOP_EURUSA 1 +#define LMP_TESTCTL_HOPMOD_HOP_JAPAN 2 +#define LMP_TESTCTL_HOPMOD_HOP_FRANCE 3 +#define LMP_TESTCTL_HOPMOD_HOP_SPAIN 4 +#define LMP_TESTCTL_HOPMOD_REDUCED_HOP 5 + +#define LMP_TESTCTL_POWCTL_FIXEDTX_OP 0 +#define LMP_TESTCTL_POWCTL_ADAPTIVE 1 + +// TODO(zachoverflow): remove this once broadcom specific hacks are removed +#define LMP_COMPID_BROADCOM 15 + +/* +** Define the packet types in the packet header, and a couple extra +*/ +#define PKT_TYPE_NULL 0x00 +#define PKT_TYPE_POLL 0x01 +#define PKT_TYPE_FHS 0x02 +#define PKT_TYPE_DM1 0x03 + +#define PKT_TYPE_DH1 0x04 +#define PKT_TYPE_HV1 0x05 +#define PKT_TYPE_HV2 0x06 +#define PKT_TYPE_HV3 0x07 +#define PKT_TYPE_DV 0x08 +#define PKT_TYPE_AUX1 0x09 + +#define PKT_TYPE_DM3 0x0a +#define PKT_TYPE_DH3 0x0b + +#define PKT_TYPE_DM5 0x0e +#define PKT_TYPE_DH5 0x0f + + +#define PKT_TYPE_ID 0x10 /* Internally used packet types */ +#define PKT_TYPE_BAD 0x11 +#define PKT_TYPE_NONE 0x12 + +/* +** Define packet size +*/ +#define HCI_DM1_PACKET_SIZE 17 +#define HCI_DH1_PACKET_SIZE 27 +#define HCI_DM3_PACKET_SIZE 121 +#define HCI_DH3_PACKET_SIZE 183 +#define HCI_DM5_PACKET_SIZE 224 +#define HCI_DH5_PACKET_SIZE 339 +#define HCI_AUX1_PACKET_SIZE 29 +#define HCI_HV1_PACKET_SIZE 10 +#define HCI_HV2_PACKET_SIZE 20 +#define HCI_HV3_PACKET_SIZE 30 +#define HCI_DV_PACKET_SIZE 9 +#define HCI_EDR2_DH1_PACKET_SIZE 54 +#define HCI_EDR2_DH3_PACKET_SIZE 367 +#define HCI_EDR2_DH5_PACKET_SIZE 679 +#define HCI_EDR3_DH1_PACKET_SIZE 83 +#define HCI_EDR3_DH3_PACKET_SIZE 552 +#define HCI_EDR3_DH5_PACKET_SIZE 1021 + +/* Feature Pages */ +#define HCI_EXT_FEATURES_PAGE_0 0 /* Extended Feature Page 0 (regular features) */ +#define HCI_EXT_FEATURES_PAGE_1 1 /* Extended Feature Page 1 */ +#define HCI_EXT_FEATURES_PAGE_2 2 /* Extended Feature Page 2 */ +#define HCI_EXT_FEATURES_PAGE_MAX HCI_EXT_FEATURES_PAGE_2 + +#define HCI_FEATURE_BYTES_PER_PAGE 8 + +#define HCI_FEATURES_KNOWN(x) ((x[0] | x[1] | x[2] | x[3] | x[4] | x[5] | x[6] | x[7]) != 0) + +/* +** LMP features encoding - page 0 +*/ +#define HCI_FEATURE_3_SLOT_PACKETS_MASK 0x01 +#define HCI_FEATURE_3_SLOT_PACKETS_OFF 0 +#define HCI_3_SLOT_PACKETS_SUPPORTED(x) ((x)[HCI_FEATURE_3_SLOT_PACKETS_OFF] & HCI_FEATURE_3_SLOT_PACKETS_MASK) + +#define HCI_FEATURE_5_SLOT_PACKETS_MASK 0x02 +#define HCI_FEATURE_5_SLOT_PACKETS_OFF 0 +#define HCI_5_SLOT_PACKETS_SUPPORTED(x) ((x)[HCI_FEATURE_5_SLOT_PACKETS_OFF] & HCI_FEATURE_5_SLOT_PACKETS_MASK) + +#define HCI_FEATURE_ENCRYPTION_MASK 0x04 +#define HCI_FEATURE_ENCRYPTION_OFF 0 +#define HCI_ENCRYPTION_SUPPORTED(x) ((x)[HCI_FEATURE_ENCRYPTION_OFF] & HCI_FEATURE_ENCRYPTION_MASK) + +#define HCI_FEATURE_SLOT_OFFSET_MASK 0x08 +#define HCI_FEATURE_SLOT_OFFSET_OFF 0 +#define HCI_SLOT_OFFSET_SUPPORTED(x) ((x)[HCI_FEATURE_SLOT_OFFSET_OFF] & HCI_FEATURE_SLOT_OFFSET_MASK) + +#define HCI_FEATURE_TIMING_ACC_MASK 0x10 +#define HCI_FEATURE_TIMING_ACC_OFF 0 +#define HCI_TIMING_ACC_SUPPORTED(x) ((x)[HCI_FEATURE_TIMING_ACC_OFF] & HCI_FEATURE_TIMING_ACC_MASK) + +#define HCI_FEATURE_SWITCH_MASK 0x20 +#define HCI_FEATURE_SWITCH_OFF 0 +#define HCI_SWITCH_SUPPORTED(x) ((x)[HCI_FEATURE_SWITCH_OFF] & HCI_FEATURE_SWITCH_MASK) + +#define HCI_FEATURE_HOLD_MODE_MASK 0x40 +#define HCI_FEATURE_HOLD_MODE_OFF 0 +#define HCI_HOLD_MODE_SUPPORTED(x) ((x)[HCI_FEATURE_HOLD_MODE_OFF] & HCI_FEATURE_HOLD_MODE_MASK) + +#define HCI_FEATURE_SNIFF_MODE_MASK 0x80 +#define HCI_FEATURE_SNIFF_MODE_OFF 0 +#define HCI_SNIFF_MODE_SUPPORTED(x) ((x)[HCI_FEATURE_SNIFF_MODE_OFF] & HCI_FEATURE_SNIFF_MODE_MASK) + +#define HCI_FEATURE_PARK_MODE_MASK 0x01 +#define HCI_FEATURE_PARK_MODE_OFF 1 +#define HCI_PARK_MODE_SUPPORTED(x) ((x)[HCI_FEATURE_PARK_MODE_OFF] & HCI_FEATURE_PARK_MODE_MASK) + +#define HCI_FEATURE_RSSI_MASK 0x02 +#define HCI_FEATURE_RSSI_OFF 1 +#define HCI_RSSI_SUPPORTED(x) ((x)[HCI_FEATURE_RSSI_OFF] & HCI_FEATURE_RSSI_MASK) + +#define HCI_FEATURE_CQM_DATA_RATE_MASK 0x04 +#define HCI_FEATURE_CQM_DATA_RATE_OFF 1 +#define HCI_CQM_DATA_RATE_SUPPORTED(x) ((x)[HCI_FEATURE_CQM_DATA_RATE_OFF] & HCI_FEATURE_CQM_DATA_RATE_MASK) + +#define HCI_FEATURE_SCO_LINK_MASK 0x08 +#define HCI_FEATURE_SCO_LINK_OFF 1 +#define HCI_SCO_LINK_SUPPORTED(x) ((x)[HCI_FEATURE_SCO_LINK_OFF] & HCI_FEATURE_SCO_LINK_MASK) + +#define HCI_FEATURE_HV2_PACKETS_MASK 0x10 +#define HCI_FEATURE_HV2_PACKETS_OFF 1 +#define HCI_HV2_PACKETS_SUPPORTED(x) ((x)[HCI_FEATURE_HV2_PACKETS_OFF] & HCI_FEATURE_HV2_PACKETS_MASK) + +#define HCI_FEATURE_HV3_PACKETS_MASK 0x20 +#define HCI_FEATURE_HV3_PACKETS_OFF 1 +#define HCI_HV3_PACKETS_SUPPORTED(x) ((x)[HCI_FEATURE_HV3_PACKETS_OFF] & HCI_FEATURE_HV3_PACKETS_MASK) + +#define HCI_FEATURE_U_LAW_MASK 0x40 +#define HCI_FEATURE_U_LAW_OFF 1 +#define HCI_LMP_U_LAW_SUPPORTED(x) ((x)[HCI_FEATURE_U_LAW_OFF] & HCI_FEATURE_U_LAW_MASK) + +#define HCI_FEATURE_A_LAW_MASK 0x80 +#define HCI_FEATURE_A_LAW_OFF 1 +#define HCI_LMP_A_LAW_SUPPORTED(x) ((x)[HCI_FEATURE_A_LAW_OFF] & HCI_FEATURE_A_LAW_MASK) + +#define HCI_FEATURE_CVSD_MASK 0x01 +#define HCI_FEATURE_CVSD_OFF 2 +#define HCI_LMP_CVSD_SUPPORTED(x) ((x)[HCI_FEATURE_CVSD_OFF] & HCI_FEATURE_CVSD_MASK) + +#define HCI_FEATURE_PAGING_SCHEME_MASK 0x02 +#define HCI_FEATURE_PAGING_SCHEME_OFF 2 +#define HCI_PAGING_SCHEME_SUPPORTED(x) ((x)[HCI_FEATURE_PAGING_SCHEME_OFF] & HCI_FEATURE_PAGING_SCHEME_MASK) + +#define HCI_FEATURE_POWER_CTRL_MASK 0x04 +#define HCI_FEATURE_POWER_CTRL_OFF 2 +#define HCI_POWER_CTRL_SUPPORTED(x) ((x)[HCI_FEATURE_POWER_CTRL_OFF] & HCI_FEATURE_POWER_CTRL_MASK) + +#define HCI_FEATURE_TRANSPNT_MASK 0x08 +#define HCI_FEATURE_TRANSPNT_OFF 2 +#define HCI_LMP_TRANSPNT_SUPPORTED(x) ((x)[HCI_FEATURE_TRANSPNT_OFF] & HCI_FEATURE_TRANSPNT_MASK) + +#define HCI_FEATURE_FLOW_CTRL_LAG_MASK 0x70 +#define HCI_FEATURE_FLOW_CTRL_LAG_OFF 2 +#define HCI_FLOW_CTRL_LAG_VALUE(x) (((x)[HCI_FEATURE_FLOW_CTRL_LAG_OFF] & HCI_FEATURE_FLOW_CTRL_LAG_MASK) >> 4) + +#define HCI_FEATURE_BROADCAST_ENC_MASK 0x80 +#define HCI_FEATURE_BROADCAST_ENC_OFF 2 +#define HCI_LMP_BCAST_ENC_SUPPORTED(x) ((x)[HCI_FEATURE_BROADCAST_ENC_OFF] & HCI_FEATURE_BROADCAST_ENC_MASK) + +#define HCI_FEATURE_SCATTER_MODE_MASK 0x01 +#define HCI_FEATURE_SCATTER_MODE_OFF 3 +#define HCI_LMP_SCATTER_MODE_SUPPORTED(x) ((x)[HCI_FEATURE_SCATTER_MODE_OFF] & HCI_FEATURE_SCATTER_MODE_MASK) + +#define HCI_FEATURE_EDR_ACL_2MPS_MASK 0x02 +#define HCI_FEATURE_EDR_ACL_2MPS_OFF 3 +#define HCI_EDR_ACL_2MPS_SUPPORTED(x) ((x)[HCI_FEATURE_EDR_ACL_2MPS_OFF] & HCI_FEATURE_EDR_ACL_2MPS_MASK) + +#define HCI_FEATURE_EDR_ACL_3MPS_MASK 0x04 +#define HCI_FEATURE_EDR_ACL_3MPS_OFF 3 +#define HCI_EDR_ACL_3MPS_SUPPORTED(x) ((x)[HCI_FEATURE_EDR_ACL_3MPS_OFF] & HCI_FEATURE_EDR_ACL_3MPS_MASK) + +#define HCI_FEATURE_ENHANCED_INQ_MASK 0x08 +#define HCI_FEATURE_ENHANCED_INQ_OFF 3 +#define HCI_ENHANCED_INQ_SUPPORTED(x) ((x)[HCI_FEATURE_ENHANCED_INQ_OFF] & HCI_FEATURE_ENHANCED_INQ_MASK) + +#define HCI_FEATURE_INTERLACED_INQ_SCAN_MASK 0x10 +#define HCI_FEATURE_INTERLACED_INQ_SCAN_OFF 3 +#define HCI_LMP_INTERLACED_INQ_SCAN_SUPPORTED(x) ((x)[HCI_FEATURE_INTERLACED_INQ_SCAN_OFF] & HCI_FEATURE_INTERLACED_INQ_SCAN_MASK) + +#define HCI_FEATURE_INTERLACED_PAGE_SCAN_MASK 0x20 +#define HCI_FEATURE_INTERLACED_PAGE_SCAN_OFF 3 +#define HCI_LMP_INTERLACED_PAGE_SCAN_SUPPORTED(x) ((x)[HCI_FEATURE_INTERLACED_PAGE_SCAN_OFF] & HCI_FEATURE_INTERLACED_PAGE_SCAN_MASK) + +#define HCI_FEATURE_INQ_RSSI_MASK 0x40 +#define HCI_FEATURE_INQ_RSSI_OFF 3 +#define HCI_LMP_INQ_RSSI_SUPPORTED(x) ((x)[HCI_FEATURE_INQ_RSSI_OFF] & HCI_FEATURE_INQ_RSSI_MASK) + +#define HCI_FEATURE_ESCO_EV3_MASK 0x80 +#define HCI_FEATURE_ESCO_EV3_OFF 3 +#define HCI_ESCO_EV3_SUPPORTED(x) ((x)[HCI_FEATURE_ESCO_EV3_OFF] & HCI_FEATURE_ESCO_EV3_MASK) + +#define HCI_FEATURE_ESCO_EV4_MASK 0x01 +#define HCI_FEATURE_ESCO_EV4_OFF 4 +#define HCI_ESCO_EV4_SUPPORTED(x) ((x)[HCI_FEATURE_ESCO_EV4_OFF] & HCI_FEATURE_ESCO_EV4_MASK) + +#define HCI_FEATURE_ESCO_EV5_MASK 0x02 +#define HCI_FEATURE_ESCO_EV5_OFF 4 +#define HCI_ESCO_EV5_SUPPORTED(x) ((x)[HCI_FEATURE_ESCO_EV5_OFF] & HCI_FEATURE_ESCO_EV5_MASK) + +#define HCI_FEATURE_ABSENCE_MASKS_MASK 0x04 +#define HCI_FEATURE_ABSENCE_MASKS_OFF 4 +#define HCI_LMP_ABSENCE_MASKS_SUPPORTED(x) ((x)[HCI_FEATURE_ABSENCE_MASKS_OFF] & HCI_FEATURE_ABSENCE_MASKS_MASK) + +#define HCI_FEATURE_AFH_CAP_SLAVE_MASK 0x08 +#define HCI_FEATURE_AFH_CAP_SLAVE_OFF 4 +#define HCI_LMP_AFH_CAP_SLAVE_SUPPORTED(x) ((x)[HCI_FEATURE_AFH_CAP_SLAVE_OFF] & HCI_FEATURE_AFH_CAP_SLAVE_MASK) + +#define HCI_FEATURE_AFH_CLASS_SLAVE_MASK 0x10 +#define HCI_FEATURE_AFH_CLASS_SLAVE_OFF 4 +#define HCI_LMP_AFH_CLASS_SLAVE_SUPPORTED(x) ((x)[HCI_FEATURE_AFH_CLASS_SLAVE_OFF] & HCI_FEATURE_AFH_CLASS_SLAVE_MASK) + +#if 1 +#define HCI_FEATURE_BREDR_NOT_SPT_MASK 0x20 +#define HCI_FEATURE_BREDR_NOT_SPT_OFF 4 +#define HCI_BREDR_NOT_SPT_SUPPORTED(x) ((x)[HCI_FEATURE_BREDR_NOT_SPT_OFF] & HCI_FEATURE_BREDR_NOT_SPT_MASK) + +#define HCI_FEATURE_LE_SPT_MASK 0x40 +#define HCI_FEATURE_LE_SPT_OFF 4 +#define HCI_LE_SPT_SUPPORTED(x) ((x)[HCI_FEATURE_LE_SPT_OFF] & HCI_FEATURE_LE_SPT_MASK) +#else + +#define HCI_FEATURE_ALIAS_AUTH_MASK 0x20 +#define HCI_FEATURE_ALIAS_AUTH_OFF 4 +#define HCI_LMP_ALIAS_AUTH_SUPPORTED(x) ((x)[HCI_FEATURE_ALIAS_AUTH_OFF] & HCI_FEATURE_ALIAS_AUTH_MASK) + +#define HCI_FEATURE_ANON_MODE_MASK 0x40 +#define HCI_FEATURE_ANON_MODE_OFF 4 +#define HCI_LMP_ANON_MODE_SUPPORTED(x) ((x)[HCI_FEATURE_ANON_MODE_OFF] & HCI_FEATURE_ANON_MODE_MASK) +#endif + +#define HCI_FEATURE_3_SLOT_EDR_ACL_MASK 0x80 +#define HCI_FEATURE_3_SLOT_EDR_ACL_OFF 4 +#define HCI_3_SLOT_EDR_ACL_SUPPORTED(x) ((x)[HCI_FEATURE_3_SLOT_EDR_ACL_OFF] & HCI_FEATURE_3_SLOT_EDR_ACL_MASK) + +#define HCI_FEATURE_5_SLOT_EDR_ACL_MASK 0x01 +#define HCI_FEATURE_5_SLOT_EDR_ACL_OFF 5 +#define HCI_5_SLOT_EDR_ACL_SUPPORTED(x) ((x)[HCI_FEATURE_5_SLOT_EDR_ACL_OFF] & HCI_FEATURE_5_SLOT_EDR_ACL_MASK) + +#define HCI_FEATURE_SNIFF_SUB_RATE_MASK 0x02 +#define HCI_FEATURE_SNIFF_SUB_RATE_OFF 5 +#define HCI_SNIFF_SUB_RATE_SUPPORTED(x) ((x)[HCI_FEATURE_SNIFF_SUB_RATE_OFF] & HCI_FEATURE_SNIFF_SUB_RATE_MASK) + +#define HCI_FEATURE_ATOMIC_ENCRYPT_MASK 0x04 +#define HCI_FEATURE_ATOMIC_ENCRYPT_OFF 5 +#define HCI_ATOMIC_ENCRYPT_SUPPORTED(x) ((x)[HCI_FEATURE_ATOMIC_ENCRYPT_OFF] & HCI_FEATURE_ATOMIC_ENCRYPT_MASK) + +#define HCI_FEATURE_AFH_CAP_MASTR_MASK 0x08 +#define HCI_FEATURE_AFH_CAP_MASTR_OFF 5 +#define HCI_LMP_AFH_CAP_MASTR_SUPPORTED(x) ((x)[HCI_FEATURE_AFH_CAP_MASTR_OFF] & HCI_FEATURE_AFH_CAP_MASTR_MASK) + +#define HCI_FEATURE_AFH_CLASS_MASTR_MASK 0x10 +#define HCI_FEATURE_AFH_CLASS_MASTR_OFF 5 +#define HCI_LMP_AFH_CLASS_MASTR_SUPPORTED(x) ((x)[HCI_FEATURE_AFH_CLASS_MASTR_OFF] & HCI_FEATURE_AFH_CLASS_MASTR_MASK) + +#define HCI_FEATURE_EDR_ESCO_2MPS_MASK 0x20 +#define HCI_FEATURE_EDR_ESCO_2MPS_OFF 5 +#define HCI_EDR_ESCO_2MPS_SUPPORTED(x) ((x)[HCI_FEATURE_EDR_ESCO_2MPS_OFF] & HCI_FEATURE_EDR_ESCO_2MPS_MASK) + +#define HCI_FEATURE_EDR_ESCO_3MPS_MASK 0x40 +#define HCI_FEATURE_EDR_ESCO_3MPS_OFF 5 +#define HCI_EDR_ESCO_3MPS_SUPPORTED(x) ((x)[HCI_FEATURE_EDR_ESCO_3MPS_OFF] & HCI_FEATURE_EDR_ESCO_3MPS_MASK) + +#define HCI_FEATURE_3_SLOT_EDR_ESCO_MASK 0x80 +#define HCI_FEATURE_3_SLOT_EDR_ESCO_OFF 5 +#define HCI_3_SLOT_EDR_ESCO_SUPPORTED(x) ((x)[HCI_FEATURE_3_SLOT_EDR_ESCO_OFF] & HCI_FEATURE_3_SLOT_EDR_ESCO_MASK) + +#define HCI_FEATURE_EXT_INQ_RSP_MASK 0x01 +#define HCI_FEATURE_EXT_INQ_RSP_OFF 6 +#define HCI_EXT_INQ_RSP_SUPPORTED(x) ((x)[HCI_FEATURE_EXT_INQ_RSP_OFF] & HCI_FEATURE_EXT_INQ_RSP_MASK) + +#if 1 /* TOKYO spec definition */ +#define HCI_FEATURE_SIMUL_LE_BREDR_MASK 0x02 +#define HCI_FEATURE_SIMUL_LE_BREDR_OFF 6 +#define HCI_SIMUL_LE_BREDR_SUPPORTED(x) ((x)[HCI_FEATURE_SIMUL_LE_BREDR_OFF] & HCI_FEATURE_SIMUL_LE_BREDR_MASK) + +#else +#define HCI_FEATURE_ANUM_PIN_AWARE_MASK 0x02 +#define HCI_FEATURE_ANUM_PIN_AWARE_OFF 6 +#define HCI_ANUM_PIN_AWARE_SUPPORTED(x) ((x)[HCI_FEATURE_ANUM_PIN_AWARE_OFF] & HCI_FEATURE_ANUM_PIN_AWARE_MASK) +#endif + +#define HCI_FEATURE_ANUM_PIN_CAP_MASK 0x04 +#define HCI_FEATURE_ANUM_PIN_CAP_OFF 6 +#define HCI_ANUM_PIN_CAP_SUPPORTED(x) ((x)[HCI_FEATURE_ANUM_PIN_CAP_OFF] & HCI_FEATURE_ANUM_PIN_CAP_MASK) + +#define HCI_FEATURE_SIMPLE_PAIRING_MASK 0x08 +#define HCI_FEATURE_SIMPLE_PAIRING_OFF 6 +#define HCI_SIMPLE_PAIRING_SUPPORTED(x) ((x)[HCI_FEATURE_SIMPLE_PAIRING_OFF] & HCI_FEATURE_SIMPLE_PAIRING_MASK) + +#define HCI_FEATURE_ENCAP_PDU_MASK 0x10 +#define HCI_FEATURE_ENCAP_PDU_OFF 6 +#define HCI_ENCAP_PDU_SUPPORTED(x) ((x)[HCI_FEATURE_ENCAP_PDU_OFF] & HCI_FEATURE_ENCAP_PDU_MASK) + +#define HCI_FEATURE_ERROR_DATA_MASK 0x20 +#define HCI_FEATURE_ERROR_DATA_OFF 6 +#define HCI_ERROR_DATA_SUPPORTED(x) ((x)[HCI_FEATURE_ERROR_DATA_OFF] & HCI_FEATURE_ERROR_DATA_MASK) + +#define HCI_FEATURE_NON_FLUSHABLE_PB_MASK 0x40 +#define HCI_FEATURE_NON_FLUSHABLE_PB_OFF 6 + +/* This feature is causing frequent link drops when doing call switch with certain av/hfp headsets */ +#define HCI_NON_FLUSHABLE_PB_SUPPORTED(x) (0)//((x)[HCI_FEATURE_NON_FLUSHABLE_PB_OFF] & HCI_FEATURE_NON_FLUSHABLE_PB_MASK) + +#define HCI_FEATURE_LINK_SUP_TO_EVT_MASK 0x01 +#define HCI_FEATURE_LINK_SUP_TO_EVT_OFF 7 +#define HCI_LINK_SUP_TO_EVT_SUPPORTED(x) ((x)[HCI_FEATURE_LINK_SUP_TO_EVT_OFF] & HCI_FEATURE_LINK_SUP_TO_EVT_MASK) + +#define HCI_FEATURE_INQ_RESP_TX_MASK 0x02 +#define HCI_FEATURE_INQ_RESP_TX_OFF 7 +#define HCI_INQ_RESP_TX_SUPPORTED(x) ((x)[HCI_FEATURE_INQ_RESP_TX_OFF] & HCI_FEATURE_INQ_RESP_TX_MASK) + +#define HCI_FEATURE_EXTENDED_MASK 0x80 +#define HCI_FEATURE_EXTENDED_OFF 7 +#define HCI_LMP_EXTENDED_SUPPORTED(x) ((x)[HCI_FEATURE_EXTENDED_OFF] & HCI_FEATURE_EXTENDED_MASK) + +/* +** LMP features encoding - page 1 +*/ +#define HCI_EXT_FEATURE_SSP_HOST_MASK 0x01 +#define HCI_EXT_FEATURE_SSP_HOST_OFF 0 +#define HCI_SSP_HOST_SUPPORTED(x) ((x)[HCI_EXT_FEATURE_SSP_HOST_OFF] & HCI_EXT_FEATURE_SSP_HOST_MASK) + +#define HCI_EXT_FEATURE_LE_HOST_MASK 0x02 +#define HCI_EXT_FEATURE_LE_HOST_OFF 0 +#define HCI_LE_HOST_SUPPORTED(x) ((x)[HCI_EXT_FEATURE_LE_HOST_OFF] & HCI_EXT_FEATURE_LE_HOST_MASK) + +#define HCI_EXT_FEATURE_SIMUL_DUMO_HOST_MASK 0x04 +#define HCI_EXT_FEATURE_SIMUL_DUMO_HOST_OFF 0 +#define HCI_SIMUL_DUMO_HOST_SUPPORTED(x) ((x)[HCI_EXT_FEATURE_SIMUL_DUMO_HOST_OFF] & HCI_EXT_FEATURE_SIMUL_DUMO_HOST_MASK) + +#define HCI_EXT_FEATURE_SC_HOST_MASK 0x08 +#define HCI_EXT_FEATURE_SC_HOST_OFF 0 +#define HCI_SC_HOST_SUPPORTED(x) ((x)[HCI_EXT_FEATURE_SC_HOST_OFF] & HCI_EXT_FEATURE_SC_HOST_MASK) + +/* +** LMP features encoding - page 2 +*/ +#define HCI_EXT_FEATURE_CSB_MASTER_MASK 0x01 +#define HCI_EXT_FEATURE_CSB_MASTER_OFF 0 +#define HCI_CSB_MASTER_SUPPORTED(x) ((x)[HCI_EXT_FEATURE_CSB_MASTER_OFF] & HCI_EXT_FEATURE_CSB_MASTER_MASK) + +#define HCI_EXT_FEATURE_CSB_SLAVE_MASK 0x02 +#define HCI_EXT_FEATURE_CSB_SLAVE_OFF 0 +#define HCI_CSB_SLAVE_SUPPORTED(x) ((x)[HCI_EXT_FEATURE_CSB_SLAVE_OFF] & HCI_EXT_FEATURE_CSB_SLAVE_MASK) + +#define HCI_EXT_FEATURE_SYNC_TRAIN_MASTER_MASK 0x04 +#define HCI_EXT_FEATURE_SYNC_TRAIN_MASTER_OFF 0 +#define HCI_SYNC_TRAIN_MASTER_SUPPORTED(x) ((x)[HCI_EXT_FEATURE_SYNC_TRAIN_MASTER_OFF] & HCI_EXT_FEATURE_SYNC_TRAIN_MASTER_MASK) + +#define HCI_EXT_FEATURE_SYNC_SCAN_SLAVE_MASK 0x08 +#define HCI_EXT_FEATURE_SYNC_SCAN_SLAVE_OFF 0 +#define HCI_SYNC_SCAN_SLAVE_SUPPORTED(x) ((x)[HCI_EXT_FEATURE_SYNC_SCAN_SLAVE_OFF] & HCI_EXT_FEATURE_SYNC_SCAN_SLAVE_MASK) + +#define HCI_EXT_FEATURE_INQ_RESP_NOTIF_MASK 0x10 +#define HCI_EXT_FEATURE_INQ_RESP_NOTIF_OFF 0 +#define HCI_INQ_RESP_NOTIF_SUPPORTED(x) ((x)[HCI_EXT_FEATURE_INQ_RESP_NOTIF_OFF] & HCI_EXT_FEATURE_INQ_RESP_NOTIF_MASK) + +#define HCI_EXT_FEATURE_SC_CTRLR_MASK 0x01 +#define HCI_EXT_FEATURE_SC_CTRLR_OFF 1 +#define HCI_SC_CTRLR_SUPPORTED(x) ((x)[HCI_EXT_FEATURE_SC_CTRLR_OFF] & HCI_EXT_FEATURE_SC_CTRLR_MASK) + +#define HCI_EXT_FEATURE_PING_MASK 0x02 +#define HCI_EXT_FEATURE_PING_OFF 1 +#define HCI_PING_SUPPORTED(x) ((x)[HCI_EXT_FEATURE_PING_OFF] & HCI_EXT_FEATURE_PING_MASK) + +/* +** LE features encoding - page 0 (the only page for now) +*/ +/* LE Encryption */ +#define HCI_LE_FEATURE_LE_ENCRYPTION_MASK 0x01 +#define HCI_LE_FEATURE_LE_ENCRYPTION_OFF 0 +#define HCI_LE_ENCRYPTION_SUPPORTED(x) ((x)[HCI_LE_FEATURE_LE_ENCRYPTION_OFF] & HCI_LE_FEATURE_LE_ENCRYPTION_MASK) + +/* Connection Parameters Request Procedure */ +#define HCI_LE_FEATURE_CONN_PARAM_REQ_MASK 0x02 +#define HCI_LE_FEATURE_CONN_PARAM_REQ_OFF 0 +#define HCI_LE_CONN_PARAM_REQ_SUPPORTED(x) ((x)[HCI_LE_FEATURE_CONN_PARAM_REQ_OFF] & HCI_LE_FEATURE_CONN_PARAM_REQ_MASK) + +/* Extended Reject Indication */ +#define HCI_LE_FEATURE_EXT_REJ_IND_MASK 0x04 +#define HCI_LE_FEATURE_EXT_REJ_IND_OFF 0 +#define HCI_LE_EXT_REJ_IND_SUPPORTED(x) ((x)[HCI_LE_FEATURE_EXT_REJ_IND_OFF] & HCI_LE_FEATURE_EXT_REJ_IND_MASK) + +/* Slave-initiated Features Exchange */ +#define HCI_LE_FEATURE_SLAVE_INIT_FEAT_EXC_MASK 0x08 +#define HCI_LE_FEATURE_SLAVE_INIT_FEAT_EXC_OFF 0 +#define HCI_LE_SLAVE_INIT_FEAT_EXC_SUPPORTED(x) ((x)[HCI_LE_FEATURE_SLAVE_INIT_FEAT_EXC_OFF] & HCI_LE_FEATURE_SLAVE_INIT_FEAT_EXC_MASK) + +/* Enhanced privacy Feature: bit 6 */ +#define HCI_LE_FEATURE_ENHANCED_PRIVACY_MASK 0x40 +#define HCI_LE_FEATURE_ENHANCED_PRIVACY_OFF 0 +#define HCI_LE_ENHANCED_PRIVACY_SUPPORTED(x) ((x)[HCI_LE_FEATURE_ENHANCED_PRIVACY_OFF] & HCI_LE_FEATURE_ENHANCED_PRIVACY_MASK) + +/* Extended scanner filter policy : 7 */ +#define HCI_LE_FEATURE_EXT_SCAN_FILTER_POLICY_MASK 0x80 +#define HCI_LE_FEATURE_EXT_SCAN_FILTER_POLICY_OFF 0 +#define HCI_LE_EXT_SCAN_FILTER_POLICY_SUPPORTED(x) ((x)[HCI_LE_FEATURE_EXT_SCAN_FILTER_POLICY_OFF] & HCI_LE_FEATURE_EXT_SCAN_FILTER_POLICY_MASK) + +/* Slave-initiated Features Exchange */ +#define HCI_LE_FEATURE_DATA_LEN_EXT_MASK 0x20 +#define HCI_LE_FEATURE_DATA_LEN_EXT_OFF 0 +#define HCI_LE_DATA_LEN_EXT_SUPPORTED(x) ((x)[HCI_LE_FEATURE_DATA_LEN_EXT_OFF] & HCI_LE_FEATURE_DATA_LEN_EXT_MASK) + +/* +** Local Supported Commands encoding +*/ +#define HCI_NUM_SUPP_COMMANDS_BYTES 64 + +/* Supported Commands Byte 0 */ +#define HCI_SUPP_COMMANDS_INQUIRY_MASK 0x01 +#define HCI_SUPP_COMMANDS_INQUIRY_OFF 0 +#define HCI_INQUIRY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_INQUIRY_OFF] & HCI_SUPP_COMMANDS_INQUIRY_MASK) + +#define HCI_SUPP_COMMANDS_INQUIRY_CANCEL_MASK 0x02 +#define HCI_SUPP_COMMANDS_INQUIRY_CANCEL_OFF 0 +#define HCI_INQUIRY_CANCEL_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_INQUIRY_CANCEL_OFF] & HCI_SUPP_COMMANDS_INQUIRY_CANCEL_MASK) + +#define HCI_SUPP_COMMANDS_PERIODIC_INQUIRY_MASK 0x04 +#define HCI_SUPP_COMMANDS_PERIODIC_INQUIRY_OFF 0 +#define HCI_PERIODIC_INQUIRY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_PERIODIC_INQUIRY_OFF] & HCI_SUPP_COMMANDS_PERIODIC_INQUIRY_MASK) + +#define HCI_SUPP_COMMANDS_EXIT_PERIODIC_INQUIRY_MASK 0x08 +#define HCI_SUPP_COMMANDS_EXIT_PERIODIC_INQUIRY_OFF 0 +#define HCI_EXIT_PERIODIC_INQUIRY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_EXIT_PERIODIC_INQUIRY_OFF] & HCI_SUPP_COMMANDS_EXIT_PERIODIC_INQUIRY_MASK) + +#define HCI_SUPP_COMMANDS_CREATE_CONN_MASK 0x10 +#define HCI_SUPP_COMMANDS_CREATE_CONN_OFF 0 +#define HCI_CREATE_CONN_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_CREATE_CONN_OFF] & HCI_SUPP_COMMANDS_CREATE_CONN_MASK) + +#define HCI_SUPP_COMMANDS_DISCONNECT_MASK 0x20 +#define HCI_SUPP_COMMANDS_DISCONNECT_OFF 0 +#define HCI_DISCONNECT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_DISCONNECT_OFF] & HCI_SUPP_COMMANDS_DISCONNECT_MASK) + +#define HCI_SUPP_COMMANDS_ADD_SCO_CONN_MASK 0x40 +#define HCI_SUPP_COMMANDS_ADD_SCO_CONN_OFF 0 +#define HCI_ADD_SCO_CONN_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_ADD_SCO_CONN_OFF] & HCI_SUPP_COMMANDS_ADD_SCO_CONN_MASK) + +#define HCI_SUPP_COMMANDS_CANCEL_CREATE_CONN_MASK 0x80 +#define HCI_SUPP_COMMANDS_CANCEL_CREATE_CONN_OFF 0 +#define HCI_CANCEL_CREATE_CONN_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_CANCEL_CREATE_CONN_OFF] & HCI_SUPP_COMMANDS_CANCEL_CREATE_CONN_MASK) + +#define HCI_SUPP_COMMANDS_ACCEPT_CONN_REQUEST_MASK 0x01 +#define HCI_SUPP_COMMANDS_ACCEPT_CONN_REQUEST_OFF 1 +#define HCI_ACCEPT_CONN_REQUEST_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_ACCEPT_CONN_REQUEST_OFF] & HCI_SUPP_COMMANDS_ACCEPT_CONN_REQUEST_MASK) + +#define HCI_SUPP_COMMANDS_REJECT_CONN_REQUEST_MASK 0x02 +#define HCI_SUPP_COMMANDS_REJECT_CONN_REQUEST_OFF 1 +#define HCI_REJECT_CONN_REQUEST_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_REJECT_CONN_REQUEST_OFF] & HCI_SUPP_COMMANDS_REJECT_CONN_REQUEST_MASK) + +#define HCI_SUPP_COMMANDS_LINK_KEY_REQUEST_REPLY_MASK 0x04 +#define HCI_SUPP_COMMANDS_LINK_KEY_REQUEST_REPLY_OFF 1 +#define HCI_LINK_KEY_REQUEST_REPLY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_LINK_KEY_REQUEST_REPLY_OFF] & HCI_SUPP_COMMANDS_LINK_KEY_REQUEST_REPLY_MASK) + +#define HCI_SUPP_COMMANDS_LINK_KEY_REQUEST_NEG_REPLY_MASK 0x08 +#define HCI_SUPP_COMMANDS_LINK_KEY_REQUEST_NEG_REPLY_OFF 1 +#define HCI_LINK_KEY_REQUEST_NEG_REPLY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_LINK_KEY_REQUEST_NEG_REPLY_OFF] & HCI_SUPP_COMMANDS_LINK_KEY_REQUEST_NEG_REPLY_MASK) + +#define HCI_SUPP_COMMANDS_PIN_CODE_REQUEST_REPLY_MASK 0x10 +#define HCI_SUPP_COMMANDS_PIN_CODE_REQUEST_REPLY_OFF 1 +#define HCI_PIN_CODE_REQUEST_REPLY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_PIN_CODE_REQUEST_REPLY_OFF] & HCI_SUPP_COMMANDS_PIN_CODE_REQUEST_REPLY_MASK) + +#define HCI_SUPP_COMMANDS_PIN_CODE_REQUEST_NEG_REPLY_MASK 0x20 +#define HCI_SUPP_COMMANDS_PIN_CODE_REQUEST_NEG_REPLY_OFF 1 +#define HCI_PIN_CODE_REQUEST_NEG_REPLY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_PIN_CODE_REQUEST_NEG_REPLY_OFF] & HCI_SUPP_COMMANDS_PIN_CODE_REQUEST_NEG_REPLY_MASK) + +#define HCI_SUPP_COMMANDS_CHANGE_CONN_PKT_TYPE_MASK 0x40 +#define HCI_SUPP_COMMANDS_CHANGE_CONN_PKT_TYPE_OFF 1 +#define HCI_CHANGE_CONN_PKT_TYPE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_CHANGE_CONN_PKT_TYPE_OFF] & HCI_SUPP_COMMANDS_CHANGE_CONN_PKT_TYPE_MASK) + +#define HCI_SUPP_COMMANDS_AUTH_REQUEST_MASK 0x80 +#define HCI_SUPP_COMMANDS_AUTH_REQUEST_OFF 1 +#define HCI_AUTH_REQUEST_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_AUTH_REQUEST_OFF] & HCI_SUPP_COMMANDS_AUTH_REQUEST_MASK) + +#define HCI_SUPP_COMMANDS_SET_CONN_ENCRYPTION_MASK 0x01 +#define HCI_SUPP_COMMANDS_SET_CONN_ENCRYPTION_OFF 2 +#define HCI_SET_CONN_ENCRYPTION_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_CONN_ENCRYPTION_OFF] & HCI_SUPP_COMMANDS_SET_CONN_ENCRYPTION_MASK) + +#define HCI_SUPP_COMMANDS_CHANGE_CONN_LINK_KEY_MASK 0x02 +#define HCI_SUPP_COMMANDS_CHANGE_CONN_LINK_KEY_OFF 2 +#define HCI_CHANGE_CONN_LINK_KEY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_CHANGE_CONN_LINK_KEY_OFF] & HCI_SUPP_COMMANDS_CHANGE_CONN_LINK_KEY_MASK) + +#define HCI_SUPP_COMMANDS_MASTER_LINK_KEY_MASK 0x04 +#define HCI_SUPP_COMMANDS_MASTER_LINK_KEY_OFF 2 +#define HCI_MASTER_LINK_KEY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_MASTER_LINK_KEY_OFF] & HCI_SUPP_COMMANDS_MASTER_LINK_KEY_MASK) + +#define HCI_SUPP_COMMANDS_REMOTE_NAME_REQUEST_MASK 0x08 +#define HCI_SUPP_COMMANDS_REMOTE_NAME_REQUEST_OFF 2 +#define HCI_REMOTE_NAME_REQUEST_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_REMOTE_NAME_REQUEST_OFF] & HCI_SUPP_COMMANDS_REMOTE_NAME_REQUEST_MASK) + +#define HCI_SUPP_COMMANDS_CANCEL_REMOTE_NAME_REQUEST_MASK 0x10 +#define HCI_SUPP_COMMANDS_CANCEL_REMOTE_NAME_REQUEST_OFF 2 +#define HCI_CANCEL_REMOTE_NAME_REQUEST_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_CANCEL_REMOTE_NAME_REQUEST_OFF] & HCI_SUPP_COMMANDS_CANCEL_REMOTE_NAME_REQUEST_MASK) + +#define HCI_SUPP_COMMANDS_READ_REMOTE_SUPP_FEATURES_MASK 0x20 +#define HCI_SUPP_COMMANDS_READ_REMOTE_SUPP_FEATURES_OFF 2 +#define HCI_READ_REMOTE_SUPP_FEATURES_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_REMOTE_SUPP_FEATURES_OFF] & HCI_SUPP_COMMANDS_READ_REMOTE_SUPP_FEATURES_MASK) + +#define HCI_SUPP_COMMANDS_READ_REMOTE_EXT_FEATURES_MASK 0x40 +#define HCI_SUPP_COMMANDS_READ_REMOTE_EXT_FEATURES_OFF 2 +#define HCI_READ_REMOTE_EXT_FEATURES_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_REMOTE_EXT_FEATURES_OFF] & HCI_SUPP_COMMANDS_READ_REMOTE_EXT_FEATURES_MASK) + +#define HCI_SUPP_COMMANDS_READ_REMOTE_VER_INFO_MASK 0x80 +#define HCI_SUPP_COMMANDS_READ_REMOTE_VER_INFO_OFF 2 +#define HCI_READ_REMOTE_VER_INFO_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_REMOTE_VER_INFO_OFF] & HCI_SUPP_COMMANDS_READ_REMOTE_VER_INFO_MASK) + +#define HCI_SUPP_COMMANDS_READ_CLOCK_OFFSET_MASK 0x01 +#define HCI_SUPP_COMMANDS_READ_CLOCK_OFFSET_OFF 3 +#define HCI_READ_CLOCK_OFFSET_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_CLOCK_OFFSET_OFF] & HCI_SUPP_COMMANDS_READ_CLOCK_OFFSET_MASK) + +#define HCI_SUPP_COMMANDS_READ_LMP_HANDLE_MASK 0x02 +#define HCI_SUPP_COMMANDS_READ_LMP_HANDLE_OFF 3 +#define HCI_READ_LMP_HANDLE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LMP_HANDLE_OFF] & HCI_SUPP_COMMANDS_READ_LMP_HANDLE_MASK) + +#define HCI_SUPP_COMMANDS_HOLD_MODE_CMD_MASK 0x02 +#define HCI_SUPP_COMMANDS_HOLD_MODE_CMD_OFF 4 +#define HCI_HOLD_MODE_CMD_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_HOLD_MODE_CMD_OFF] & HCI_SUPP_COMMANDS_HOLD_MODE_CMD_MASK) + +#define HCI_SUPP_COMMANDS_SNIFF_MODE_CMD_MASK 0x04 +#define HCI_SUPP_COMMANDS_SNIFF_MODE_CMD_OFF 4 +#define HCI_SNIFF_MODE_CMD_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SNIFF_MODE_CMD_OFF] & HCI_SUPP_COMMANDS_SNIFF_MODE_CMD_MASK) + +#define HCI_SUPP_COMMANDS_EXIT_SNIFF_MODE_MASK 0x08 +#define HCI_SUPP_COMMANDS_EXIT_SNIFF_MODE_OFF 4 +#define HCI_EXIT_SNIFF_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_EXIT_SNIFF_MODE_OFF] & HCI_SUPP_COMMANDS_EXIT_SNIFF_MODE_MASK) + +#define HCI_SUPP_COMMANDS_PARK_STATE_MASK 0x10 +#define HCI_SUPP_COMMANDS_PARK_STATE_OFF 4 +#define HCI_PARK_STATE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_PARK_STATE_OFF] & HCI_SUPP_COMMANDS_PARK_STATE_MASK) + +#define HCI_SUPP_COMMANDS_EXIT_PARK_STATE_MASK 0x20 +#define HCI_SUPP_COMMANDS_EXIT_PARK_STATE_OFF 4 +#define HCI_EXIT_PARK_STATE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_EXIT_PARK_STATE_OFF] & HCI_SUPP_COMMANDS_EXIT_PARK_STATE_MASK) + +#define HCI_SUPP_COMMANDS_QOS_SETUP_MASK 0x40 +#define HCI_SUPP_COMMANDS_QOS_SETUP_OFF 4 +#define HCI_QOS_SETUP_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_QOS_SETUP_OFF] & HCI_SUPP_COMMANDS_QOS_SETUP_MASK) + +#define HCI_SUPP_COMMANDS_ROLE_DISCOVERY_MASK 0x80 +#define HCI_SUPP_COMMANDS_ROLE_DISCOVERY_OFF 4 +#define HCI_ROLE_DISCOVERY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_ROLE_DISCOVERY_OFF] & HCI_SUPP_COMMANDS_ROLE_DISCOVERY_MASK) + +#define HCI_SUPP_COMMANDS_SWITCH_ROLE_MASK 0x01 +#define HCI_SUPP_COMMANDS_SWITCH_ROLE_OFF 5 +#define HCI_SWITCH_ROLE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SWITCH_ROLE_OFF] & HCI_SUPP_COMMANDS_SWITCH_ROLE_MASK) + +#define HCI_SUPP_COMMANDS_READ_LINK_POLICY_SET_MASK 0x02 +#define HCI_SUPP_COMMANDS_READ_LINK_POLICY_SET_OFF 5 +#define HCI_READ_LINK_POLICY_SET_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LINK_POLICY_SET_OFF] & HCI_SUPP_COMMANDS_READ_LINK_POLICY_SET_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_LINK_POLICY_SET_MASK 0x04 +#define HCI_SUPP_COMMANDS_WRITE_LINK_POLICY_SET_OFF 5 +#define HCI_WRITE_LINK_POLICY_SET_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_LINK_POLICY_SET_OFF] & HCI_SUPP_COMMANDS_WRITE_LINK_POLICY_SET_MASK) + +#define HCI_SUPP_COMMANDS_READ_DEF_LINK_POLICY_SET_MASK 0x08 +#define HCI_SUPP_COMMANDS_READ_DEF_LINK_POLICY_SET_OFF 5 +#define HCI_READ_DEF_LINK_POLICY_SET_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_DEF_LINK_POLICY_SET_OFF] & HCI_SUPP_COMMANDS_READ_DEF_LINK_POLICY_SET_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_DEF_LINK_POLICY_SET_MASK 0x10 +#define HCI_SUPP_COMMANDS_WRITE_DEF_LINK_POLICY_SET_OFF 5 +#define HCI_WRITE_DEF_LINK_POLICY_SET_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_DEF_LINK_POLICY_SET_OFF] & HCI_SUPP_COMMANDS_WRITE_DEF_LINK_POLICY_SET_MASK) + +#define HCI_SUPP_COMMANDS_FLOW_SPECIFICATION_MASK 0x20 +#define HCI_SUPP_COMMANDS_FLOW_SPECIFICATION_OFF 5 +#define HCI_FLOW_SPECIFICATION_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_FLOW_SPECIFICATION_OFF] & HCI_SUPP_COMMANDS_FLOW_SPECIFICATION_MASK) + +#define HCI_SUPP_COMMANDS_SET_EVENT_MASK_MASK 0x40 +#define HCI_SUPP_COMMANDS_SET_EVENT_MASK_OFF 5 +#define HCI_SET_EVENT_MASK_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_EVENT_MASK_OFF] & HCI_SUPP_COMMANDS_SET_EVENT_MASK_MASK) + +#define HCI_SUPP_COMMANDS_RESET_MASK 0x80 +#define HCI_SUPP_COMMANDS_RESET_OFF 5 +#define HCI_RESET_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_RESET_OFF] & HCI_SUPP_COMMANDS_RESET_MASK) + +#define HCI_SUPP_COMMANDS_SET_EVENT_FILTER_MASK 0x01 +#define HCI_SUPP_COMMANDS_SET_EVENT_FILTER_OFF 6 +#define HCI_SET_EVENT_FILTER_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_EVENT_FILTER_OFF] & HCI_SUPP_COMMANDS_SET_EVENT_FILTER_MASK) + +#define HCI_SUPP_COMMANDS_FLUSH_MASK 0x02 +#define HCI_SUPP_COMMANDS_FLUSH_OFF 6 +#define HCI_FLUSH_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_FLUSH_OFF] & HCI_SUPP_COMMANDS_FLUSH_MASK) + +#define HCI_SUPP_COMMANDS_READ_PIN_TYPE_MASK 0x04 +#define HCI_SUPP_COMMANDS_READ_PIN_TYPE_OFF 6 +#define HCI_READ_PIN_TYPE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_PIN_TYPE_OFF] & HCI_SUPP_COMMANDS_READ_PIN_TYPE_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_PIN_TYPE_MASK 0x08 +#define HCI_SUPP_COMMANDS_WRITE_PIN_TYPE_OFF 6 +#define HCI_WRITE_PIN_TYPE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_PIN_TYPE_OFF] & HCI_SUPP_COMMANDS_WRITE_PIN_TYPE_MASK) + +#define HCI_SUPP_COMMANDS_CREATE_NEW_UNIT_KEY_MASK 0x10 +#define HCI_SUPP_COMMANDS_CREATE_NEW_UNIT_KEY_OFF 6 +#define HCI_CREATE_NEW_UNIT_KEY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_CREATE_NEW_UNIT_KEY_OFF] & HCI_SUPP_COMMANDS_CREATE_NEW_UNIT_KEY_MASK) + +#define HCI_SUPP_COMMANDS_READ_STORED_LINK_KEY_MASK 0x20 +#define HCI_SUPP_COMMANDS_READ_STORED_LINK_KEY_OFF 6 +#define HCI_READ_STORED_LINK_KEY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_STORED_LINK_KEY_OFF] & HCI_SUPP_COMMANDS_READ_STORED_LINK_KEY_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_STORED_LINK_KEY_MASK 0x40 +#define HCI_SUPP_COMMANDS_WRITE_STORED_LINK_KEY_OFF 6 +#define HCI_WRITE_STORED_LINK_KEY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_STORED_LINK_KEY_OFF] & HCI_SUPP_COMMANDS_WRITE_STORED_LINK_KEY_MASK) + +#define HCI_SUPP_COMMANDS_DELETE_STORED_LINK_KEY_MASK 0x80 +#define HCI_SUPP_COMMANDS_DELETE_STORED_LINK_KEY_OFF 6 +#define HCI_DELETE_STORED_LINK_KEY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_DELETE_STORED_LINK_KEY_OFF] & HCI_SUPP_COMMANDS_DELETE_STORED_LINK_KEY_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_LOCAL_NAME_MASK 0x01 +#define HCI_SUPP_COMMANDS_WRITE_LOCAL_NAME_OFF 7 +#define HCI_WRITE_LOCAL_NAME_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_LOCAL_NAME_OFF] & HCI_SUPP_COMMANDS_WRITE_LOCAL_NAME_MASK) + +#define HCI_SUPP_COMMANDS_READ_LOCAL_NAME_MASK 0x02 +#define HCI_SUPP_COMMANDS_READ_LOCAL_NAME_OFF 7 +#define HCI_READ_LOCAL_NAME_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LOCAL_NAME_OFF] & HCI_SUPP_COMMANDS_READ_LOCAL_NAME_MASK) + +#define HCI_SUPP_COMMANDS_READ_CONN_ACCEPT_TOUT_MASK 0x04 +#define HCI_SUPP_COMMANDS_READ_CONN_ACCEPT_TOUT_OFF 7 +#define HCI_READ_CONN_ACCEPT_TOUT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_CONN_ACCEPT_TOUT_OFF] & HCI_SUPP_COMMANDS_READ_CONN_ACCEPT_TOUT_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_CONN_ACCEPT_TOUT_MASK 0x08 +#define HCI_SUPP_COMMANDS_WRITE_CONN_ACCEPT_TOUT_OFF 7 +#define HCI_WRITE_CONN_ACCEPT_TOUT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_CONN_ACCEPT_TOUT_OFF] & HCI_SUPP_COMMANDS_WRITE_CONN_ACCEPT_TOUT_MASK) + +#define HCI_SUPP_COMMANDS_READ_PAGE_TOUT_MASK 0x10 +#define HCI_SUPP_COMMANDS_READ_PAGE_TOUT_OFF 7 +#define HCI_READ_PAGE_TOUT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_PAGE_TOUT_OFF] & HCI_SUPP_COMMANDS_READ_PAGE_TOUT_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_PAGE_TOUT_MASK 0x20 +#define HCI_SUPP_COMMANDS_WRITE_PAGE_TOUT_OFF 7 +#define HCI_WRITE_PAGE_TOUT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_PAGE_TOUT_OFF] & HCI_SUPP_COMMANDS_WRITE_PAGE_TOUT_MASK) + +#define HCI_SUPP_COMMANDS_READ_SCAN_ENABLE_MASK 0x40 +#define HCI_SUPP_COMMANDS_READ_SCAN_ENABLE_OFF 7 +#define HCI_READ_SCAN_ENABLE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_SCAN_ENABLE_OFF] & HCI_SUPP_COMMANDS_READ_SCAN_ENABLE_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_SCAN_ENABLE_MASK 0x80 +#define HCI_SUPP_COMMANDS_WRITE_SCAN_ENABLE_OFF 7 +#define HCI_WRITE_SCAN_ENABLE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_SCAN_ENABLE_OFF] & HCI_SUPP_COMMANDS_WRITE_SCAN_ENABLE_MASK) + +#define HCI_SUPP_COMMANDS_READ_PAGE_SCAN_ACTIVITY_MASK 0x01 +#define HCI_SUPP_COMMANDS_READ_PAGE_SCAN_ACTIVITY_OFF 8 +#define HCI_READ_PAGE_SCAN_ACTIVITY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_PAGE_SCAN_ACTIVITY_OFF] & HCI_SUPP_COMMANDS_READ_PAGE_SCAN_ACTIVITY_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_ACTIVITY_MASK 0x02 +#define HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_ACTIVITY_OFF 8 +#define HCI_WRITE_PAGE_SCAN_ACTIVITY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_ACTIVITY_OFF] & HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_ACTIVITY_MASK) + +#define HCI_SUPP_COMMANDS_READ_INQURIY_SCAN_ACTIVITY_MASK 0x04 +#define HCI_SUPP_COMMANDS_READ_INQURIY_SCAN_ACTIVITY_OFF 8 +#define HCI_READ_INQURIY_SCAN_ACTIVITY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_INQURIY_SCAN_ACTIVITY_OFF] & HCI_SUPP_COMMANDS_READ_INQURIY_SCAN_ACTIVITY_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_INQURIY_SCAN_ACTIVITY_MASK 0x08 +#define HCI_SUPP_COMMANDS_WRITE_INQURIY_SCAN_ACTIVITY_OFF 8 +#define HCI_WRITE_INQURIY_SCAN_ACTIVITY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_INQURIY_SCAN_ACTIVITY_OFF] & HCI_SUPP_COMMANDS_WRITE_INQURIY_SCAN_ACTIVITY_MASK) + +#define HCI_SUPP_COMMANDS_READ_AUTH_ENABLE_MASK 0x10 +#define HCI_SUPP_COMMANDS_READ_AUTH_ENABLE_OFF 8 +#define HCI_READ_AUTH_ENABLE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_AUTH_ENABLE_OFF] & HCI_SUPP_COMMANDS_READ_AUTH_ENABLE_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_AUTH_ENABLE_MASK 0x20 +#define HCI_SUPP_COMMANDS_WRITE_AUTH_ENABLE_OFF 8 +#define HCI_WRITE_AUTH_ENABLE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_AUTH_ENABLE_OFF] & HCI_SUPP_COMMANDS_WRITE_AUTH_ENABLE_MASK) + +#define HCI_SUPP_COMMANDS_READ_ENCRYPT_ENABLE_MASK 0x40 +#define HCI_SUPP_COMMANDS_READ_ENCRYPT_ENABLE_OFF 8 +#define HCI_READ_ENCRYPT_ENABLE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_ENCRYPT_ENABLE_OFF] & HCI_SUPP_COMMANDS_READ_ENCRYPT_ENABLE_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_ENCRYPT_ENABLE_MASK 0x80 +#define HCI_SUPP_COMMANDS_WRITE_ENCRYPT_ENABLE_OFF 8 +#define HCI_WRITE_ENCRYPT_ENABLE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_ENCRYPT_ENABLE_OFF] & HCI_SUPP_COMMANDS_WRITE_ENCRYPT_ENABLE_MASK) + +#define HCI_SUPP_COMMANDS_READ_CLASS_DEVICE_MASK 0x01 +#define HCI_SUPP_COMMANDS_READ_CLASS_DEVICE_OFF 9 +#define HCI_READ_CLASS_DEVICE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_CLASS_DEVICE_OFF] & HCI_SUPP_COMMANDS_READ_CLASS_DEVICE_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_CLASS_DEVICE_MASK 0x02 +#define HCI_SUPP_COMMANDS_WRITE_CLASS_DEVICE_OFF 9 +#define HCI_WRITE_CLASS_DEVICE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_CLASS_DEVICE_OFF] & HCI_SUPP_COMMANDS_WRITE_CLASS_DEVICE_MASK) + +#define HCI_SUPP_COMMANDS_READ_VOICE_SETTING_MASK 0x04 +#define HCI_SUPP_COMMANDS_READ_VOICE_SETTING_OFF 9 +#define HCI_READ_VOICE_SETTING_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_VOICE_SETTING_OFF] & HCI_SUPP_COMMANDS_READ_VOICE_SETTING_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_VOICE_SETTING_MASK 0x08 +#define HCI_SUPP_COMMANDS_WRITE_VOICE_SETTING_OFF 9 +#define HCI_WRITE_VOICE_SETTING_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_VOICE_SETTING_OFF] & HCI_SUPP_COMMANDS_WRITE_VOICE_SETTING_MASK) + +#define HCI_SUPP_COMMANDS_READ_AUTO_FLUSH_TOUT_MASK 0x10 +#define HCI_SUPP_COMMANDS_READ_AUTO_FLUSH_TOUT_OFF 9 +#define HCI_READ_AUTO_FLUSH_TOUT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_AUTO_FLUSH_TOUT_OFF] & HCI_SUPP_COMMANDS_READ_AUTO_FLUSH_TOUT_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_AUTO_FLUSH_TOUT_MASK 0x20 +#define HCI_SUPP_COMMANDS_WRITE_AUTO_FLUSH_TOUT_OFF 9 +#define HCI_WRITE_AUTO_FLUSH_TOUT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_AUTO_FLUSH_TOUT_OFF] & HCI_SUPP_COMMANDS_WRITE_AUTO_FLUSH_TOUT_MASK) + +#define HCI_SUPP_COMMANDS_READ_NUM_BROAD_RETRANS_MASK 0x40 +#define HCI_SUPP_COMMANDS_READ_NUM_BROAD_RETRANS_OFF 9 +#define HCI_READ_NUM_BROAD_RETRANS_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_NUM_BROAD_RETRANS_OFF] & HCI_SUPP_COMMANDS_READ_NUM_BROAD_RETRANS_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_NUM_BROAD_RETRANS_MASK 0x80 +#define HCI_SUPP_COMMANDS_WRITE_NUM_BROAD_RETRANS_OFF 9 +#define HCI_WRITE_NUM_BROAD_RETRANS_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_NUM_BROAD_RETRANS_OFF] & HCI_SUPP_COMMANDS_WRITE_NUM_BROAD_RETRANS_MASK) + +#define HCI_SUPP_COMMANDS_READ_HOLD_MODE_ACTIVITY_MASK 0x01 +#define HCI_SUPP_COMMANDS_READ_HOLD_MODE_ACTIVITY_OFF 10 +#define HCI_READ_HOLD_MODE_ACTIVITY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_HOLD_MODE_ACTIVITY_OFF] & HCI_SUPP_COMMANDS_READ_HOLD_MODE_ACTIVITY_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_HOLD_MODE_ACTIVITY_MASK 0x02 +#define HCI_SUPP_COMMANDS_WRITE_HOLD_MODE_ACTIVITY_OFF 10 +#define HCI_WRITE_HOLD_MODE_ACTIVITY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_HOLD_MODE_ACTIVITY_OFF] & HCI_SUPP_COMMANDS_WRITE_HOLD_MODE_ACTIVITY_MASK) + +#define HCI_SUPP_COMMANDS_READ_TRANS_PWR_LEVEL_MASK 0x04 +#define HCI_SUPP_COMMANDS_READ_TRANS_PWR_LEVEL_OFF 10 +#define HCI_READ_TRANS_PWR_LEVEL_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_TRANS_PWR_LEVEL_OFF] & HCI_SUPP_COMMANDS_READ_TRANS_PWR_LEVEL_MASK) + +#define HCI_SUPP_COMMANDS_READ_SYNCH_FLOW_CTRL_ENABLE_MASK 0x08 +#define HCI_SUPP_COMMANDS_READ_SYNCH_FLOW_CTRL_ENABLE_OFF 10 +#define HCI_READ_SYNCH_FLOW_CTRL_ENABLE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_SYNCH_FLOW_CTRL_ENABLE_OFF] & HCI_SUPP_COMMANDS_READ_SYNCH_FLOW_CTRL_ENABLE_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_SYNCH_FLOW_CTRL_ENABLE_MASK 0x10 +#define HCI_SUPP_COMMANDS_WRITE_SYNCH_FLOW_CTRL_ENABLE_OFF 10 +#define HCI_WRITE_SYNCH_FLOW_CTRL_ENABLE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_SYNCH_FLOW_CTRL_ENABLE_OFF] & HCI_SUPP_COMMANDS_WRITE_SYNCH_FLOW_CTRL_ENABLE_MASK) + +#define HCI_SUPP_COMMANDS_SET_HOST_CTRLR_TO_HOST_FC_MASK 0x20 +#define HCI_SUPP_COMMANDS_SET_HOST_CTRLR_TO_HOST_FC_OFF 10 +#define HCI_SET_HOST_CTRLR_TO_HOST_FC_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_HOST_CTRLR_TO_HOST_FC_OFF] & HCI_SUPP_COMMANDS_SET_HOST_CTRLR_TO_HOST_FC_MASK) + +#define HCI_SUPP_COMMANDS_HOST_BUFFER_SIZE_MASK 0x40 +#define HCI_SUPP_COMMANDS_HOST_BUFFER_SIZE_OFF 10 +#define HCI_HOST_BUFFER_SIZE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_HOST_BUFFER_SIZE_OFF] & HCI_SUPP_COMMANDS_HOST_BUFFER_SIZE_MASK) + +#define HCI_SUPP_COMMANDS_HOST_NUM_COMPLETED_PKTS_MASK 0x80 +#define HCI_SUPP_COMMANDS_HOST_NUM_COMPLETED_PKTS_OFF 10 +#define HCI_HOST_NUM_COMPLETED_PKTS_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_HOST_NUM_COMPLETED_PKTS_OFF] & HCI_SUPP_COMMANDS_HOST_NUM_COMPLETED_PKTS_MASK) + +#define HCI_SUPP_COMMANDS_READ_LINK_SUP_TOUT_MASK 0x01 +#define HCI_SUPP_COMMANDS_READ_LINK_SUP_TOUT_OFF 11 +#define HCI_READ_LINK_SUP_TOUT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LINK_SUP_TOUT_OFF] & HCI_SUPP_COMMANDS_READ_LINK_SUP_TOUT_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_LINK_SUP_TOUT_MASK 0x02 +#define HCI_SUPP_COMMANDS_WRITE_LINK_SUP_TOUT_OFF 11 +#define HCI_WRITE_LINK_SUP_TOUT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_LINK_SUP_TOUT_OFF] & HCI_SUPP_COMMANDS_WRITE_LINK_SUP_TOUT_MASK) + +#define HCI_SUPP_COMMANDS_READ_NUM_SUPP_IAC_MASK 0x04 +#define HCI_SUPP_COMMANDS_READ_NUM_SUPP_IAC_OFF 11 +#define HCI_READ_NUM_SUPP_IAC_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_NUM_SUPP_IAC_OFF] & HCI_SUPP_COMMANDS_READ_NUM_SUPP_IAC_MASK) + +#define HCI_SUPP_COMMANDS_READ_CURRENT_IAC_LAP_MASK 0x08 +#define HCI_SUPP_COMMANDS_READ_CURRENT_IAC_LAP_OFF 11 +#define HCI_READ_CURRENT_IAC_LAP_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_CURRENT_IAC_LAP_OFF] & HCI_SUPP_COMMANDS_READ_CURRENT_IAC_LAP_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_CURRENT_IAC_LAP_MASK 0x10 +#define HCI_SUPP_COMMANDS_WRITE_CURRENT_IAC_LAP_OFF 11 +#define HCI_WRITE_CURRENT_IAC_LAP_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_CURRENT_IAC_LAP_OFF] & HCI_SUPP_COMMANDS_WRITE_CURRENT_IAC_LAP_MASK) + +#define HCI_SUPP_COMMANDS_READ_PAGE_SCAN_PER_MODE_MASK 0x20 +#define HCI_SUPP_COMMANDS_READ_PAGE_SCAN_PER_MODE_OFF 11 +#define HCI_READ_PAGE_SCAN_PER_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_PAGE_SCAN_PER_MODE_OFF] & HCI_SUPP_COMMANDS_READ_PAGE_SCAN_PER_MODE_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_PER_MODE_MASK 0x40 +#define HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_PER_MODE_OFF 11 +#define HCI_WRITE_PAGE_SCAN_PER_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_PER_MODE_OFF] & HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_PER_MODE_MASK) + +#define HCI_SUPP_COMMANDS_READ_PAGE_SCAN_MODE_MASK 0x80 +#define HCI_SUPP_COMMANDS_READ_PAGE_SCAN_MODE_OFF 11 +#define HCI_READ_PAGE_SCAN_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_PAGE_SCAN_MODE_OFF] & HCI_SUPP_COMMANDS_READ_PAGE_SCAN_MODE_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_MODE_MASK 0x01 +#define HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_MODE_OFF 12 +#define HCI_WRITE_PAGE_SCAN_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_MODE_OFF] & HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_MODE_MASK) + +#define HCI_SUPP_COMMANDS_SET_AFH_CHNL_CLASS_MASK 0x02 +#define HCI_SUPP_COMMANDS_SET_AFH_CHNL_CLASS_OFF 12 +#define HCI_SET_AFH_CHNL_CLASS_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_AFH_CHNL_CLASS_OFF] & HCI_SUPP_COMMANDS_SET_AFH_CHNL_CLASS_MASK) + +#define HCI_SUPP_COMMANDS_READ_INQUIRY_SCAN_TYPE_MASK 0x10 +#define HCI_SUPP_COMMANDS_READ_INQUIRY_SCAN_TYPE_OFF 12 +#define HCI_READ_INQUIRY_SCAN_TYPE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_INQUIRY_SCAN_TYPE_OFF] & HCI_SUPP_COMMANDS_READ_INQUIRY_SCAN_TYPE_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_INQUIRY_SCAN_TYPE_MASK 0x20 +#define HCI_SUPP_COMMANDS_WRITE_INQUIRY_SCAN_TYPE_OFF 12 +#define HCI_WRITE_INQUIRY_SCAN_TYPE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_INQUIRY_SCAN_TYPE_OFF] & HCI_SUPP_COMMANDS_WRITE_INQUIRY_SCAN_TYPE_MASK) + +#define HCI_SUPP_COMMANDS_READ_INQUIRY_MODE_MASK 0x40 +#define HCI_SUPP_COMMANDS_READ_INQUIRY_MODE_OFF 12 +#define HCI_READ_INQUIRY_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_INQUIRY_MODE_OFF] & HCI_SUPP_COMMANDS_READ_INQUIRY_MODE_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_INQUIRY_MODE_MASK 0x80 +#define HCI_SUPP_COMMANDS_WRITE_INQUIRY_MODE_OFF 12 +#define HCI_WRITE_INQUIRY_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_INQUIRY_MODE_OFF] & HCI_SUPP_COMMANDS_WRITE_INQUIRY_MODE_MASK) + +#define HCI_SUPP_COMMANDS_READ_PAGE_SCAN_TYPE_MASK 0x01 +#define HCI_SUPP_COMMANDS_READ_PAGE_SCAN_TYPE_OFF 13 +#define HCI_READ_PAGE_SCAN_TYPE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_PAGE_SCAN_TYPE_OFF] & HCI_SUPP_COMMANDS_READ_PAGE_SCAN_TYPE_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_TYPE_MASK 0x02 +#define HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_TYPE_OFF 13 +#define HCI_WRITE_PAGE_SCAN_TYPE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_TYPE_OFF] & HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_TYPE_MASK) + +#define HCI_SUPP_COMMANDS_READ_AFH_CHNL_ASSESS_MODE_MASK 0x04 +#define HCI_SUPP_COMMANDS_READ_AFH_CHNL_ASSESS_MODE_OFF 13 +#define HCI_READ_AFH_CHNL_ASSESS_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_AFH_CHNL_ASSESS_MODE_OFF] & HCI_SUPP_COMMANDS_READ_AFH_CHNL_ASSESS_MODE_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_AFH_CHNL_ASSESS_MODE_MASK 0x08 +#define HCI_SUPP_COMMANDS_WRITE_AFH_CHNL_ASSESS_MODE_OFF 13 +#define HCI_WRITE_AFH_CHNL_ASSESS_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_AFH_CHNL_ASSESS_MODE_OFF] & HCI_SUPP_COMMANDS_WRITE_AFH_CHNL_ASSESS_MODE_MASK) + +#define HCI_SUPP_COMMANDS_READ_LOCAL_VER_INFO_MASK 0x08 +#define HCI_SUPP_COMMANDS_READ_LOCAL_VER_INFO_OFF 14 +#define HCI_READ_LOCAL_VER_INFO_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LOCAL_VER_INFO_OFF] & HCI_SUPP_COMMANDS_READ_LOCAL_VER_INFO_MASK) + +#define HCI_SUPP_COMMANDS_READ_LOCAL_SUP_CMDS_MASK 0x10 +#define HCI_SUPP_COMMANDS_READ_LOCAL_SUP_CMDS_OFF 14 +#define HCI_READ_LOCAL_SUP_CMDS_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LOCAL_SUP_CMDS_OFF] & HCI_SUPP_COMMANDS_READ_LOCAL_SUP_CMDS_MASK) + +#define HCI_SUPP_COMMANDS_READ_LOCAL_SUPP_FEATURES_MASK 0x20 +#define HCI_SUPP_COMMANDS_READ_LOCAL_SUPP_FEATURES_OFF 14 +#define HCI_READ_LOCAL_SUPP_FEATURES_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LOCAL_SUPP_FEATURES_OFF] & HCI_SUPP_COMMANDS_READ_LOCAL_SUPP_FEATURES_MASK) + +#define HCI_SUPP_COMMANDS_READ_LOCAL_EXT_FEATURES_MASK 0x40 +#define HCI_SUPP_COMMANDS_READ_LOCAL_EXT_FEATURES_OFF 14 +#define HCI_READ_LOCAL_EXT_FEATURES_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LOCAL_EXT_FEATURES_OFF] & HCI_SUPP_COMMANDS_READ_LOCAL_EXT_FEATURES_MASK) + +#define HCI_SUPP_COMMANDS_READ_BUFFER_SIZE_MASK 0x80 +#define HCI_SUPP_COMMANDS_READ_BUFFER_SIZE_OFF 14 +#define HCI_READ_BUFFER_SIZE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_BUFFER_SIZE_OFF] & HCI_SUPP_COMMANDS_READ_BUFFER_SIZE_MASK) + +#define HCI_SUPP_COMMANDS_READ_COUNTRY_CODE_MASK 0x01 +#define HCI_SUPP_COMMANDS_READ_COUNTRY_CODE_OFF 15 +#define HCI_READ_COUNTRY_CODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_COUNTRY_CODE_OFF] & HCI_SUPP_COMMANDS_READ_COUNTRY_CODE_MASK) + +#define HCI_SUPP_COMMANDS_READ_BD_ADDR_MASK 0x02 +#define HCI_SUPP_COMMANDS_READ_BD_ADDR_OFF 15 +#define HCI_READ_BD_ADDR_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_BD_ADDR_OFF] & HCI_SUPP_COMMANDS_READ_BD_ADDR_MASK) + +#define HCI_SUPP_COMMANDS_READ_FAIL_CONTACT_CNTR_MASK 0x04 +#define HCI_SUPP_COMMANDS_READ_FAIL_CONTACT_CNTR_OFF 15 +#define HCI_READ_FAIL_CONTACT_CNTR_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_FAIL_CONTACT_CNTR_OFF] & HCI_SUPP_COMMANDS_READ_FAIL_CONTACT_CNTR_MASK) + +#define HCI_SUPP_COMMANDS_RESET_FAIL_CONTACT_CNTR_MASK 0x08 +#define HCI_SUPP_COMMANDS_RESET_FAIL_CONTACT_CNTR_OFF 15 +#define HCI_RESET_FAIL_CONTACT_CNTR_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_RESET_FAIL_CONTACT_CNTR_OFF] & HCI_SUPP_COMMANDS_RESET_FAIL_CONTACT_CNTR_MASK) + +#define HCI_SUPP_COMMANDS_GET_LINK_QUALITY_MASK 0x10 +#define HCI_SUPP_COMMANDS_GET_LINK_QUALITY_OFF 15 +#define HCI_GET_LINK_QUALITY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_GET_LINK_QUALITY_OFF] & HCI_SUPP_COMMANDS_GET_LINK_QUALITY_MASK) + +#define HCI_SUPP_COMMANDS_READ_RSSI_MASK 0x20 +#define HCI_SUPP_COMMANDS_READ_RSSI_OFF 15 +#define HCI_READ_RSSI_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_RSSI_OFF] & HCI_SUPP_COMMANDS_READ_RSSI_MASK) + +#define HCI_SUPP_COMMANDS_READ_AFH_CH_MAP_MASK 0x40 +#define HCI_SUPP_COMMANDS_READ_AFH_CH_MAP_OFF 15 +#define HCI_READ_AFH_CH_MAP_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_AFH_CH_MAP_OFF] & HCI_SUPP_COMMANDS_READ_AFH_CH_MAP_MASK) + +#define HCI_SUPP_COMMANDS_READ_BD_CLOCK_MASK 0x80 +#define HCI_SUPP_COMMANDS_READ_BD_CLOCK_OFF 15 +#define HCI_READ_BD_CLOCK_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_BD_CLOCK_OFF] & HCI_SUPP_COMMANDS_READ_BD_CLOCK_MASK) + +#define HCI_SUPP_COMMANDS_READ_LOOPBACK_MODE_MASK 0x01 +#define HCI_SUPP_COMMANDS_READ_LOOPBACK_MODE_OFF 16 +#define HCI_READ_LOOPBACK_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LOOPBACK_MODE_OFF] & HCI_SUPP_COMMANDS_READ_LOOPBACK_MODE_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_LOOPBACK_MODE_MASK 0x02 +#define HCI_SUPP_COMMANDS_WRITE_LOOPBACK_MODE_OFF 16 +#define HCI_WRITE_LOOPBACK_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_LOOPBACK_MODE_OFF] & HCI_SUPP_COMMANDS_WRITE_LOOPBACK_MODE_MASK) + +#define HCI_SUPP_COMMANDS_ENABLE_DEV_UNDER_TEST_MASK 0x04 +#define HCI_SUPP_COMMANDS_ENABLE_DEV_UNDER_TEST_OFF 16 +#define HCI_ENABLE_DEV_UNDER_TEST_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_ENABLE_DEV_UNDER_TEST_OFF] & HCI_SUPP_COMMANDS_ENABLE_DEV_UNDER_TEST_MASK) + +#define HCI_SUPP_COMMANDS_SETUP_SYNCH_CONN_MASK 0x08 +#define HCI_SUPP_COMMANDS_SETUP_SYNCH_CONN_OFF 16 +#define HCI_SETUP_SYNCH_CONN_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SETUP_SYNCH_CONN_OFF] & HCI_SUPP_COMMANDS_SETUP_SYNCH_CONN_MASK) + +#define HCI_SUPP_COMMANDS_ACCEPT_SYNCH_CONN_MASK 0x10 +#define HCI_SUPP_COMMANDS_ACCEPT_SYNCH_CONN_OFF 16 +#define HCI_ACCEPT_SYNCH_CONN_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_ACCEPT_SYNCH_CONN_OFF] & HCI_SUPP_COMMANDS_ACCEPT_SYNCH_CONN_MASK) + +#define HCI_SUPP_COMMANDS_REJECT_SYNCH_CONN_MASK 0x20 +#define HCI_SUPP_COMMANDS_REJECT_SYNCH_CONN_OFF 16 +#define HCI_REJECT_SYNCH_CONN_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_REJECT_SYNCH_CONN_OFF] & HCI_SUPP_COMMANDS_REJECT_SYNCH_CONN_MASK) + +#define HCI_SUPP_COMMANDS_READ_EXT_INQUIRY_RESP_MASK 0x01 +#define HCI_SUPP_COMMANDS_READ_EXT_INQUIRY_RESP_OFF 17 +#define HCI_READ_EXT_INQUIRY_RESP_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_EXT_INQUIRY_RESP_OFF] & HCI_SUPP_COMMANDS_READ_EXT_INQUIRY_RESP_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_EXT_INQUIRY_RESP_MASK 0x02 +#define HCI_SUPP_COMMANDS_WRITE_EXT_INQUIRY_RESP_OFF 17 +#define HCI_WRITE_EXT_INQUIRY_RESP_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_EXT_INQUIRY_RESP_OFF] & HCI_SUPP_COMMANDS_WRITE_EXT_INQUIRY_RESP_MASK) + +#define HCI_SUPP_COMMANDS_REFRESH_ENCRYPTION_KEY_MASK 0x04 +#define HCI_SUPP_COMMANDS_REFRESH_ENCRYPTION_KEY_OFF 17 +#define HCI_REFRESH_ENCRYPTION_KEY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_REFRESH_ENCRYPTION_KEY_OFF] & HCI_SUPP_COMMANDS_REFRESH_ENCRYPTION_KEY_MASK) + +/* Octet 17, bit 3 is reserved */ + +#define HCI_SUPP_COMMANDS_SNIFF_SUB_RATE_MASK 0x10 +#define HCI_SUPP_COMMANDS_SNIFF_SUB_RATE_OFF 17 +#define HCI_SNIFF_SUB_RATE_CMD_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SNIFF_SUB_RATE_OFF] & HCI_SUPP_COMMANDS_SNIFF_SUB_RATE_MASK) + +#define HCI_SUPP_COMMANDS_READ_SIMPLE_PAIRING_MODE_MASK 0x20 +#define HCI_SUPP_COMMANDS_READ_SIMPLE_PAIRING_MODE_OFF 17 +#define HCI_READ_SIMPLE_PAIRING_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_SIMPLE_PAIRING_MODE_OFF] & HCI_SUPP_COMMANDS_READ_SIMPLE_PAIRING_MODE_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_SIMPLE_PAIRING_MODE_MASK 0x40 +#define HCI_SUPP_COMMANDS_WRITE_SIMPLE_PAIRING_MODE_OFF 17 +#define HCI_WRITE_SIMPLE_PAIRING_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_SIMPLE_PAIRING_MODE_OFF] & HCI_SUPP_COMMANDS_WRITE_SIMPLE_PAIRING_MODE_MASK) + +#define HCI_SUPP_COMMANDS_READ_LOCAL_OOB_DATA_MASK 0x80 +#define HCI_SUPP_COMMANDS_READ_LOCAL_OOB_DATA_OFF 17 +#define HCI_READ_LOCAL_OOB_DATA_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LOCAL_OOB_DATA_OFF] & HCI_SUPP_COMMANDS_READ_LOCAL_OOB_DATA_MASK) + +#define HCI_SUPP_COMMANDS_READ_INQUIRY_RESPONSE_TX_POWER_MASK 0x01 +#define HCI_SUPP_COMMANDS_READ_INQUIRY_RESPONSE_TX_POWER_OFF 18 +#define HCI_READ_INQUIRY_RESPONSE_TX_POWER_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_INQUIRY_RESPONSE_TX_POWER_OFF] & HCI_SUPP_COMMANDS_READ_INQUIRY_RESPONSE_TX_POWER_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_INQUIRY_RESPONSE_TX_POWER_MASK 0x02 +#define HCI_SUPP_COMMANDS_WRITE_INQUIRY_RESPONSE_TX_POWER_OFF 18 +#define HCI_WRITE_INQUIRY_RESPONSE_TX_POWER_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_INQUIRY_RESPONSE_TX_POWER_OFF] & HCI_SUPP_COMMANDS_WRITE_INQUIRY_RESPONSE_TX_POWER_MASK) + +#define HCI_SUPP_COMMANDS_READ_DEFAULT_ERRONEOUS_DATA_REPORTING_MASK 0x04 +#define HCI_SUPP_COMMANDS_READ_DEFAULT_ERRONEOUS_DATA_REPORTING_OFF 18 +#define HCI_READ_DEFAULT_ERRONEOUS_DATA_REPORTING_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_DEFAULT_ERRONEOUS_DATA_REPORTING_OFF] & HCI_SUPP_COMMANDS_READ_DEFAULT_ERRONEOUS_DATA_REPORTING_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_DEFAULT_ERRONEOUS_DATA_REPORTING_MASK 0x08 +#define HCI_SUPP_COMMANDS_WRITE_DEFAULT_ERRONEOUS_DATA_REPORTING_OFF 18 +#define HCI_WRITE_DEFAULT_ERRONEOUS_DATA_REPORTING_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_DEFAULT_ERRONEOUS_DATA_REPORTING_OFF] & HCI_SUPP_COMMANDS_WRITE_DEFAULT_ERRONEOUS_DATA_REPORTING_MASK) + +#define HCI_SUPP_COMMANDS_IO_CAPABILITY_REQUEST_REPLY_MASK 0x80 +#define HCI_SUPP_COMMANDS_IO_CAPABILITY_REQUEST_REPLY_OFF 18 +#define HCI_IO_CAPABILITY_REQUEST_REPLY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_IO_CAPABILITY_REQUEST_REPLY_OFF] & HCI_SUPP_COMMANDS_IO_CAPABILITY_REQUEST_REPLY_MASK) + +#define HCI_SUPP_COMMANDS_USER_CONFIRMATION_REQUEST_REPLY_MASK 0x01 +#define HCI_SUPP_COMMANDS_USER_CONFIRMATION_REQUEST_REPLY_OFF 19 +#define HCI_USER_CONFIRMATION_REQUEST_REPLY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_USER_CONFIRMATION_REQUEST_REPLY_OFF] & HCI_SUPP_COMMANDS_USER_CONFIRMATION_REQUEST_REPLY_MASK) + +#define HCI_SUPP_COMMANDS_USER_CONFIRMATION_REQUEST_NEG_REPLY_MASK 0x02 +#define HCI_SUPP_COMMANDS_USER_CONFIRMATION_REQUEST_NEG_REPLY_OFF 19 +#define HCI_USER_CONFIRMATION_REQUEST_NEG_REPLY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_USER_CONFIRMATION_REQUEST_NEG_REPLY_OFF] & HCI_SUPP_COMMANDS_USER_CONFIRMATION_REQUEST_NEG_REPLY_MASK) + +#define HCI_SUPP_COMMANDS_USER_PASSKEY_REQUEST_REPLY_MASK 0x04 +#define HCI_SUPP_COMMANDS_USER_PASSKEY_REQUEST_REPLY_OFF 19 +#define HCI_USER_PASSKEY_REQUEST_REPLY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_USER_PASSKEY_REQUEST_REPLY_OFF] & HCI_SUPP_COMMANDS_USER_PASSKEY_REQUEST_REPLY_MASK) + +#define HCI_SUPP_COMMANDS_USER_PASSKEY_REQUEST_NEG_REPLY_MASK 0x08 +#define HCI_SUPP_COMMANDS_USER_PASSKEY_REQUEST_NEG_REPLY_OFF 19 +#define HCI_USER_PASSKEY_REQUEST_NEG_REPLY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_USER_PASSKEY_REQUEST_NEG_REPLY_OFF] & HCI_SUPP_COMMANDS_USER_PASSKEY_REQUEST_NEG_REPLY_MASK) + +#define HCI_SUPP_COMMANDS_REMOTE_OOB_DATA_REQUEST_REPLY_MASK 0x10 +#define HCI_SUPP_COMMANDS_REMOTE_OOB_DATA_REQUEST_REPLY_OFF 19 +#define HCI_REMOTE_OOB_DATA_REQUEST_REPLY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_REMOTE_OOB_DATA_REQUEST_REPLY_OFF] & HCI_SUPP_COMMANDS_REMOTE_OOB_DATA_REQUEST_REPLY_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_SIMPLE_PAIRING_DBG_MODE_MASK 0x20 +#define HCI_SUPP_COMMANDS_WRITE_SIMPLE_PAIRING_DBG_MODE_OFF 19 +#define HCI_WRITE_SIMPLE_PAIRING_DBG_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_SIMPLE_PAIRING_DBG_MODE_OFF] & HCI_SUPP_COMMANDS_WRITE_SIMPLE_PAIRING_DBG_MODE_MASK) + +#define HCI_SUPP_COMMANDS_ENHANCED_FLUSH_MASK 0x40 +#define HCI_SUPP_COMMANDS_ENHANCED_FLUSH_OFF 19 +#define HCI_ENHANCED_FLUSH_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_ENHANCED_FLUSH_OFF] & HCI_SUPP_COMMANDS_ENHANCED_FLUSH_MASK) + +#define HCI_SUPP_COMMANDS_REMOTE_OOB_DATA_REQUEST_NEG_REPLY_MASK 0x80 +#define HCI_SUPP_COMMANDS_REMOTE_OOB_DATA_REQUEST_NEG_REPLY_OFF 19 +#define HCI_REMOTE_OOB_DATA_REQUEST_NEG_REPLY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_REMOTE_OOB_DATA_REQUEST_NEG_REPLY_OFF] & HCI_SUPP_COMMANDS_REMOTE_OOB_DATA_REQUEST_NEG_REPLY_MASK) + +/* Supported Commands (Byte 20) */ +#define HCI_SUPP_COMMANDS_SEND_KEYPRESS_NOTIF_MASK 0x04 +#define HCI_SUPP_COMMANDS_SEND_KEYPRESS_NOTIF_OFF 20 +#define HCI_SEND_NOTIF_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SEND_KEYPRESS_NOTIF_OFF] & HCI_SUPP_COMMANDS_SEND_KEYPRESS_NOTIF_MASK) + +#define HCI_SUPP_COMMANDS_IO_CAP_REQ_NEG_REPLY_MASK 0x08 +#define HCI_SUPP_COMMANDS_IO_CAP_REQ_NEG_REPLY_OFF 20 +#define HCI_IO_CAP_REQ_NEG_REPLY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_IO_CAP_REQ_NEG_REPLY_OFF] & HCI_SUPP_COMMANDS_IO_CAP_REQ_NEG_REPLY_MASK) + +#define HCI_SUPP_COMMANDS_READ_ENCR_KEY_SIZE_MASK 0x10 +#define HCI_SUPP_COMMANDS_READ_ENCR_KEY_SIZE_OFF 20 +#define HCI_READ_ENCR_KEY_SIZE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_ENCR_KEY_SIZE_OFF] & HCI_SUPP_COMMANDS_READ_ENCR_KEY_SIZE_MASK) + +/* Supported Commands (Byte 21) */ +#define HCI_SUPP_COMMANDS_CREATE_PHYSICAL_LINK_MASK 0x01 +#define HCI_SUPP_COMMANDS_CREATE_PHYSICAL_LINK_OFF 21 +#define HCI_CREATE_PHYSICAL_LINK_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_CREATE_PHYSICAL_LINK_OFF] & HCI_SUPP_COMMANDS_CREATE_PHYSICAL_LINK_MASK) + +#define HCI_SUPP_COMMANDS_ACCEPT_PHYSICAL_LINK_MASK 0x02 +#define HCI_SUPP_COMMANDS_ACCEPT_PHYSICAL_LINK_OFF 21 +#define HCI_ACCEPT_PHYSICAL_LINK_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_ACCEPT_PHYSICAL_LINK_OFF] & HCI_SUPP_COMMANDS_ACCEPT_PHYSICAL_LINK_MASK) + +#define HCI_SUPP_COMMANDS_DISCONNECT_PHYSICAL_LINK_MASK 0x04 +#define HCI_SUPP_COMMANDS_DISCONNECT_PHYSICAL_LINK_OFF 21 +#define HCI_DISCONNECT_PHYSICAL_LINK_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_DISCONNECT_PHYSICAL_LINK_OFF] & HCI_SUPP_COMMANDS_DISCONNECT_PHYSICAL_LINK_MASK) + +#define HCI_SUPP_COMMANDS_CREATE_LOGICAL_LINK_MASK 0x08 +#define HCI_SUPP_COMMANDS_CREATE_LOGICAL_LINK_OFF 21 +#define HCI_CREATE_LOGICAL_LINK_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_CREATE_LOGICAL_LINK_OFF] & HCI_SUPP_COMMANDS_CREATE_LOGICAL_LINK_MASK) + +#define HCI_SUPP_COMMANDS_ACCEPT_LOGICAL_LINK_MASK 0x10 +#define HCI_SUPP_COMMANDS_ACCEPT_LOGICAL_LINK_OFF 21 +#define HCI_ACCEPT_LOGICAL_LINK_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_ACCEPT_LOGICAL_LINK_OFF] & HCI_SUPP_COMMANDS_ACCEPT_LOGICAL_LINK_MASK) + +#define HCI_SUPP_COMMANDS_DISCONNECT_LOGICAL_LINK_MASK 0x20 +#define HCI_SUPP_COMMANDS_DISCONNECT_LOGICAL_LINK_OFF 21 +#define HCI_DISCONNECT_LOGICAL_LINK_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_DISCONNECT_LOGICAL_LINK_OFF] & HCI_SUPP_COMMANDS_DISCONNECT_LOGICAL_LINK_MASK) + +#define HCI_SUPP_COMMANDS_LOGICAL_LINK_CANCEL_MASK 0x40 +#define HCI_SUPP_COMMANDS_LOGICAL_LINK_CANCEL_OFF 21 +#define HCI_LOGICAL_LINK_CANCEL_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_LOGICAL_LINK_CANCEL_OFF] & HCI_SUPP_COMMANDS_LOGICAL_LINK_CANCEL_MASK) + +#define HCI_SUPP_COMMANDS_FLOW_SPEC_MODIFY_MASK 0x80 +#define HCI_SUPP_COMMANDS_FLOW_SPEC_MODIFY_OFF 21 +#define HCI_FLOW_SPEC_MODIFY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_FLOW_SPEC_MODIFY_OFF] & HCI_SUPP_COMMANDS_FLOW_SPEC_MODIFY_MASK) + +/* Supported Commands (Byte 22) */ +#define HCI_SUPP_COMMANDS_READ_LOGICAL_LINK_ACCEPT_TIMEOUT_MASK 0x01 +#define HCI_SUPP_COMMANDS_READ_LOGICAL_LINK_ACCEPT_TIMEOUT_OFF 22 +#define HCI_READ_LOGICAL_LINK_ACCEPT_TIMEOUT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LOGICAL_LINK_ACCEPT_TIMEOUT_OFF] & HCI_SUPP_COMMANDS_READ_LOGICAL_LINK_ACCEPT_TIMEOUT_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT_MASK 0x02 +#define HCI_SUPP_COMMANDS_WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT_OFF 22 +#define HCI_WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT_OFF] & HCI_SUPP_COMMANDS_WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT_MASK) + +#define HCI_SUPP_COMMANDS_SET_EVENT_MASK_PAGE_2_MASK 0x04 +#define HCI_SUPP_COMMANDS_SET_EVENT_MASK_PAGE_2_OFF 22 +#define HCI_SET_EVENT_MASK_PAGE_2_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_EVENT_MASK_PAGE_2_OFF] & HCI_SUPP_COMMANDS_SET_EVENT_MASK_PAGE_2_MASK) + +#define HCI_SUPP_COMMANDS_READ_LOCATION_DATA_MASK 0x08 +#define HCI_SUPP_COMMANDS_READ_LOCATION_DATA_OFF 22 +#define HCI_READ_LOCATION_DATA_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LOCATION_DATA_OFF] & HCI_SUPP_COMMANDS_READ_LOCATION_DATA_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_LOCATION_DATA_MASK 0x10 +#define HCI_SUPP_COMMANDS_WRITE_LOCATION_DATA_OFF 22 +#define HCI_WRITE_LOCATION_DATA_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_LOCATION_DATA_OFF] & HCI_SUPP_COMMANDS_WRITE_LOCATION_DATA_MASK) + +#define HCI_SUPP_COMMANDS_READ_LOCAL_AMP_INFO_MASK 0x20 +#define HCI_SUPP_COMMANDS_READ_LOCAL_AMP_INFO_OFF 22 +#define HCI_READ_LOCAL_AMP_INFO_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LOCAL_AMP_INFO_OFF] & HCI_SUPP_COMMANDS_READ_LOCAL_AMP_INFO_MASK) + +#define HCI_SUPP_COMMANDS_READ_LOCAL_AMP_ASSOC_MASK 0x40 +#define HCI_SUPP_COMMANDS_READ_LOCAL_AMP_ASSOC_OFF 22 +#define HCI_READ_LOCAL_AMP_ASSOC_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LOCAL_AMP_ASSOC_OFF] & HCI_SUPP_COMMANDS_READ_LOCAL_AMP_ASSOC_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_REMOTE_AMP_ASSOC_MASK 0x80 +#define HCI_SUPP_COMMANDS_WRITE_REMOTE_AMP_ASSOC_OFF 22 +#define HCI_WRITE_REMOTE_AMP_ASSOC_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_REMOTE_AMP_ASSOC_OFF] & HCI_SUPP_COMMANDS_WRITE_REMOTE_AMP_ASSOC_MASK) + +/* Supported Commands (Byte 23) */ +#define HCI_SUPP_COMMANDS_READ_FLOW_CONTROL_MODE_MASK 0x01 +#define HCI_SUPP_COMMANDS_READ_FLOW_CONTROL_MODE_OFF 23 +#define HCI_READ_FLOW_CONTROL_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_FLOW_CONTROL_MODE_OFF] & HCI_SUPP_COMMANDS_READ_FLOW_CONTROL_MODE_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_FLOW_CONTROL_MODE_MASK 0x02 +#define HCI_SUPP_COMMANDS_WRITE_FLOW_CONTROL_MODE_OFF 23 +#define HCI_WRITE_FLOW_CONTROL_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_FLOW_CONTROL_MODE_OFF] & HCI_SUPP_COMMANDS_WRITE_FLOW_CONTROL_MODE_MASK) + +#define HCI_SUPP_COMMANDS_READ_DATA_BLOCK_SIZE_MASK 0x04 +#define HCI_SUPP_COMMANDS_READ_DATA_BLOCK_SIZE_OFF 23 +#define HCI_READ_DATA_BLOCK_SIZE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_DATA_BLOCK_SIZE_OFF] & HCI_SUPP_COMMANDS_READ_DATA_BLOCK_SIZE_MASK) + +#define HCI_SUPP_COMMANDS_ENABLE_AMP_RCVR_REPORTS_MASK 0x20 +#define HCI_SUPP_COMMANDS_ENABLE_AMP_RCVR_REPORTS_OFF 23 +#define HCI_ENABLE_AMP_RCVR_REPORTS_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_ENABLE_AMP_RCVR_REPORTS_OFF] & HCI_SUPP_COMMANDS_ENABLE_AMP_RCVR_REPORTS_MASK) + +#define HCI_SUPP_COMMANDS_AMP_TEST_END_MASK 0x40 +#define HCI_SUPP_COMMANDS_AMP_TEST_END_OFF 23 +#define HCI_AMP_TEST_END_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_AMP_TEST_END_OFF] & HCI_SUPP_COMMANDS_AMP_TEST_END_MASK) + +#define HCI_SUPP_COMMANDS_AMP_TEST_MASK 0x80 +#define HCI_SUPP_COMMANDS_AMP_TEST_OFF 23 +#define HCI_AMP_TEST_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_AMP_TEST_OFF] & HCI_SUPP_COMMANDS_AMP_TEST_MASK) + +/* Supported Commands (Byte 24) */ +#define HCI_SUPP_COMMANDS_READ_TRANSMIT_POWER_LEVEL_MASK 0x01 +#define HCI_SUPP_COMMANDS_READ_TRANSMIT_POWER_LEVEL_OFF 24 +#define HCI_READ_TRANSMIT_POWER_LEVEL_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_TRANSMIT_POWER_LEVEL_OFF] & HCI_SUPP_COMMANDS_READ_TRANSMIT_POWER_LEVEL_MASK) + +#define HCI_SUPP_COMMANDS_READ_BE_FLUSH_TOUT_MASK 0x04 +#define HCI_SUPP_COMMANDS_READ_BE_FLUSH_TOUT_OFF 24 +#define HCI_READ_BE_FLUSH_TOUT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_BE_FLUSH_TOUT_OFF] & HCI_SUPP_COMMANDS_READ_BE_FLUSH_TOUT_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_BE_FLUSH_TOUT_MASK 0x08 +#define HCI_SUPP_COMMANDS_WRITE_BE_FLUSH_TOUT_OFF 24 +#define HCI_WRITE_BE_FLUSH_TOUT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_BE_FLUSH_TOUT_OFF] & HCI_SUPP_COMMANDS_WRITE_BE_FLUSH_TOUT_MASK) + +#define HCI_SUPP_COMMANDS_SHORT_RANGE_MODE_MASK 0x10 +#define HCI_SUPP_COMMANDS_SHORT_RANGE_MODE_OFF 24 +#define HCI_SHORT_RANGE_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SHORT_RANGE_MODE_OFF] & HCI_SUPP_COMMANDS_SHORT_RANGE_MODE_MASK) + +/* LE commands TBD +** Supported Commands (Byte 24 continued) +** Supported Commands (Byte 25) +** Supported Commands (Byte 26) +** Supported Commands (Byte 27) +** Supported Commands (Byte 28) +*/ + +/* Supported Commands (Byte 29) */ +#define HCI_SUPP_COMMANDS_ENH_SETUP_SYNCH_CONN_MASK 0x08 +#define HCI_SUPP_COMMANDS_ENH_SETUP_SYNCH_CONN_OFF 29 +#define HCI_READ_ENH_SETUP_SYNCH_CONN_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_ENH_SETUP_SYNCH_CONN_OFF] & HCI_SUPP_COMMANDS_ENH_SETUP_SYNCH_CONN_MASK) + +#define HCI_SUPP_COMMANDS_ENH_ACCEPT_SYNCH_CONN_MASK 0x10 +#define HCI_SUPP_COMMANDS_ENH_ACCEPT_SYNCH_CONN_OFF 29 +#define HCI_READ_ENH_ACCEPT_SYNCH_CONN_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_ENH_ACCEPT_SYNCH_CONN_OFF] & HCI_SUPP_COMMANDS_ENH_ACCEPT_SYNCH_CONN_MASK) + +#define HCI_SUPP_COMMANDS_READ_LOCAL_CODECS_MASK 0x20 +#define HCI_SUPP_COMMANDS_READ_LOCAL_CODECS_OFF 29 +#define HCI_READ_LOCAL_CODECS_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LOCAL_CODECS_OFF] & HCI_SUPP_COMMANDS_READ_LOCAL_CODECS_MASK) + +#define HCI_SUPP_COMMANDS_SET_MWS_CHANN_PARAM_MASK 0x40 +#define HCI_SUPP_COMMANDS_SET_MWS_CHANN_PARAM_OFF 29 +#define HCI_SET_MWS_CHANNEL_PARAMETERS_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_MWS_CHANN_PARAM_OFF] & HCI_SUPP_COMMANDS_SET_MWS_CHANN_PARAM_MASK) + +#define HCI_SUPP_COMMANDS_SET_EXT_FRAME_CONF_MASK 0x80 +#define HCI_SUPP_COMMANDS_SET_EXT_FRAME_CONF_OFF 29 +#define HCI_SET_EXTERNAL_FRAME_CONFIGURATION_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_EXT_FRAME_CONF_OFF] & HCI_SUPP_COMMANDS_SET_EXT_FRAME_CONF_MASK) + + +/* Supported Commands (Byte 30) */ +#define HCI_SUPP_COMMANDS_SET_MWS_SIGNALING_MASK 0x01 +#define HCI_SUPP_COMMANDS_SET_MWS_SIGNALING_OFF 30 +#define HCI_SET_MWS_SIGNALING_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_MWS_SIGNALING_OFF] & HCI_SUPP_COMMANDS_SET_MWS_SIGNALING_MASK) + +#define HCI_SUPP_COMMANDS_SET_MWS_TRANS_LAYER_MASK 0x02 +#define HCI_SUPP_COMMANDS_SET_MWS_TRANS_LAYER_OFF 30 +#define HCI_SET_MWS_TRANSPORT_LAYER_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_MWS_TRANS_LAYER_OFF] & HCI_SUPP_COMMANDS_SET_MWS_TRANS_LAYER_MASK) + +#define HCI_SUPP_COMMANDS_SET_MWS_SCAN_FREQ_TABLE_MASK 0x04 +#define HCI_SUPP_COMMANDS_SET_MWS_SCAN_FREQ_TABLE_OFF 30 +#define HCI_SET_MWS_SCAN_FREQUENCY_TABLE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_MWS_SCAN_FREQ_TABLE_OFF] & HCI_SUPP_COMMANDS_SET_MWS_SCAN_FREQ_TABLE_MASK) + +#define HCI_SUPP_COMMANDS_GET_TRANS_LAYER_CONF_MASK 0x08 +#define HCI_SUPP_COMMANDS_GET_TRANS_LAYER_CONF_OFF 30 +#define HCI_GET_MWS_TRANS_LAYER_CFG_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_GET_TRANS_LAYER_CONF_OFF] & HCI_SUPP_COMMANDS_GET_TRANS_LAYER_CONF_MASK) + +#define HCI_SUPP_COMMANDS_SET_MWS_PATTERN_CONF_MASK 0x10 +#define HCI_SUPP_COMMANDS_SET_MWS_PATTERN_CONF_OFF 30 +#define HCI_SET_MWS_PATTERN_CONFIGURATION_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_MWS_PATTERN_CONF_OFF] & HCI_SUPP_COMMANDS_SET_MWS_PATTERN_CONF_MASK) + +/* Supported Commands (Byte 30 bit 5) */ +#define HCI_SUPP_COMMANDS_SET_TRIG_CLK_CAP_MASK 0x20 +#define HCI_SUPP_COMMANDS_SET_TRIG_CLK_CAP_OFF 30 +#define HCI_SET_TRIG_CLK_CAP_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_TRIG_CLK_CAP_OFF] & HCI_SUPP_COMMANDS_SET_TRIG_CLK_CAP_MASK) + + +/* Supported Commands (Byte 30 bit 6-7) */ +#define HCI_SUPP_COMMANDS_TRUNCATED_PAGE 0x06 +#define HCI_SUPP_COMMANDS_TRUNCATED_PAGE_OFF 30 +#define HCI_TRUNCATED_PAGE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_TRUNCATED_PAGE_OFF] & HCI_SUPP_COMMANDS_TRUNCATED_PAGE) + +#define HCI_SUPP_COMMANDS_TRUNCATED_PAGE_CANCEL 0x07 +#define HCI_SUPP_COMMANDS_TRUNCATED_PAGE_CANCEL_OFF 30 +#define HCI_TRUNCATED_PAGE_CANCEL_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_TRUNCATED_PAGE_CANCEL_OFF] & HCI_SUPP_COMMANDS_TRUNCATED_PAGE_CANCEL) + +/* Supported Commands (Byte 31 bit 6-7) */ +#define HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST 0x00 +#define HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST_OFF 31 +#define HCI_SET_CONLESS_SLAVE_BRCST_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST_OFF] & HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST) + +#define HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST_RECEIVE 0x01 +#define HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST_RECEIVE_OFF 31 +#define HCI_SET_CONLESS_SLAVE_BRCST_RECEIVE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST_RECEIVE_OFF] & HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST_RECEIVE) + +#define HCI_SUPP_COMMANDS_START_SYNC_TRAIN 0x02 +#define HCI_SUPP_COMMANDS_START_SYNC_TRAIN_OFF 31 +#define HCI_START_SYNC_TRAIN_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_START_SYNC_TRAIN_OFF] & HCI_SUPP_COMMANDS_START_SYNC_TRAIN) + +#define HCI_SUPP_COMMANDS_RECEIVE_SYNC_TRAIN 0x03 +#define HCI_SUPP_COMMANDS_RECEIVE_SYNC_TRAIN_OFF 31 +#define HCI_RECEIVE_SYNC_TRAIN_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_RECEIVE_SYNC_TRAIN_OFF] & HCI_SUPP_COMMANDS_RECEIVE_SYNC_TRAIN) + +#define HCI_SUPP_COMMANDS_SET_RESERVED_LT_ADDR 0x04 +#define HCI_SUPP_COMMANDS_SET_RESERVED_LT_ADDR_OFF 31 +#define HCI_SET_RESERVED_LT_ADDR_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_RESERVED_LT_ADDR_OFF] & HCI_SUPP_COMMANDS_SET_RESERVED_LT_ADDR) + +#define HCI_SUPP_COMMANDS_DELETE_RESERVED_LT_ADDR 0x05 +#define HCI_SUPP_COMMANDS_DELETE_RESERVED_LT_ADDR_OFF 31 +#define HCI_DELETE_RESERVED_LT_ADDR_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_DELETE_RESERVED_LT_ADDR_OFF] & HCI_SUPP_COMMANDS_DELETE_RESERVED_LT_ADDR) + +#define HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST_DATA 0x06 +#define HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST_DATA_OFF 31 +#define HCI_SET_CONLESS_SLAVE_BRCST_DATA_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST_DATA_OFF] & HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST_DATA) + +#define HCI_SUPP_COMMANDS_READ_SYNC_TRAIN_PARAM 0x07 +#define HCI_SUPP_COMMANDS_READ_SYNC_TRAIN_PARAM_OFF 31 +#define HCI_READ_SYNC_TRAIN_PARAM_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_SYNC_TRAIN_PARAM_OFF] & HCI_SUPP_COMMANDS_READ_SYNC_TRAIN_PARAM) + +/* Supported Commands (Byte 32 bit 0) */ +#define HCI_SUPP_COMMANDS_WRITE_SYNC_TRAIN_PARAM 0x00 +#define HCI_SUPP_COMMANDS_WRITE_SYNC_TRAIN_PARAM_OFF 32 +#define HCI_WRITE_SYNC_TRAIN_PARAM_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_SYNC_TRAIN_PARAM_OFF] & HCI_SUPP_COMMANDS_WRITE_SYNC_TRAIN_PARAM) + +#define HCI_SUPP_COMMANDS_REMOTE_OOB_EXTENDED_DATA_REQUEST_REPLY_MASK 0x02 +#define HCI_SUPP_COMMANDS_REMOTE_OOB_EXTENDED_DATA_REQUEST_REPLY_OFF 32 +#define HCI_REMOTE_OOB_EXTENDED_DATA_REQUEST_REPLY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_REMOTE_OOB_EXTENDED_DATA_REQUEST_REPLY_OFF] & HCI_SUPP_COMMANDS_REMOTE_OOB_EXTENDED_DATA_REQUEST_REPLY_MASK) + +#define HCI_SUPP_COMMANDS_READ_SECURE_CONNS_SUPPORT_MASK 0x04 +#define HCI_SUPP_COMMANDS_READ_SECURE_CONNS_SUPPORT_OFF 32 +#define HCI_READ_SECURE_CONNS_SUPPORT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_SECURE_CONNS_SUPPORT_OFF] & HCI_SUPP_COMMANDS_READ_SECURE_CONNS_SUPPORT_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_SECURE_CONNS_SUPPORT_MASK 0x08 +#define HCI_SUPP_COMMANDS_WRITE_SECURE_CONNS_SUPPORT_OFF 32 +#define HCI_WRITE_SECURE_CONNS_SUPPORT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_SECURE_CONNS_SUPPORT_OFF] & HCI_SUPP_COMMANDS_WRITE_SECURE_CONNS_SUPPORT_MASK) + +#define HCI_SUPP_COMMANDS_READ_AUTHENT_PAYLOAD_TOUT_MASK 0x10 +#define HCI_SUPP_COMMANDS_READ_AUTHENT_PAYLOAD_TOUT_OFF 32 +#define HCI_READ_AUTHENT_PAYLOAD_TOUT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_AUTHENT_PAYLOAD_TOUT_OFF] & HCI_SUPP_COMMANDS_READ_AUTHENT_PAYLOAD_TOUT_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_AUTHENT_PAYLOAD_TOUT_MASK 0x20 +#define HCI_SUPP_COMMANDS_WRITE_AUTHENT_PAYLOAD_TOUT_OFF 32 +#define HCI_WRITE_AUTHENT_PAYLOAD_TOUT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_AUTHENT_PAYLOAD_TOUT_OFF] & HCI_SUPP_COMMANDS_WRITE_AUTHENT_PAYLOAD_TOUT_MASK) + +#define HCI_SUPP_COMMANDS_READ_LOCAL_OOB_EXTENDED_DATA_MASK 0x40 +#define HCI_SUPP_COMMANDS_READ_LOCAL_OOB_EXTENDED_DATA_OFF 32 +#define HCI_READ_LOCAL_OOB_EXTENDED_DATA_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LOCAL_OOB_EXTENDED_DATA_OFF] & HCI_SUPP_COMMANDS_READ_LOCAL_OOB_EXTENDED_DATA_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_SECURE_CONNECTIONS_TEST_MODE_MASK 0x80 +#define HCI_SUPP_COMMANDS_WRITE_SECURE_CONNECTIONS_TEST_MODE_OFF 32 +#define HCI_WRITE_SECURE_CONNECTIONS_TEST_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_SECURE_CONNECTIONS_TEST_MODE_OFF] & HCI_SUPP_COMMANDS_WRITE_SECURE_CONNECTIONS_TEST_MODE_MASK) + +/* supported LE remote control connection parameter request reply */ +#define HCI_SUPP_COMMANDS_LE_RC_CONN_PARAM_UPD_RPY_MASK 0x10 +#define HCI_SUPP_COMMANDS_LE_RC_CONN_PARAM_UPD_RPY_OFF 33 +#define HCI_LE_RC_CONN_PARAM_UPD_RPY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_LE_RC_CONN_PARAM_UPD_RPY_OFF] & HCI_SUPP_COMMANDS_LE_RC_CONN_PARAM_UPD_RPY_MASK) + +#define HCI_SUPP_COMMANDS_RLE_RC_CONN_PARAM_UPD_NEG_RPY_MASK 0x20 +#define HCI_SUPP_COMMANDS_LE_RC_CONN_PARAM_UPD_NEG_RPY_OFF 33 +#define HCI_LE_RC_CONN_PARAM_UPD_NEG_RPY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_LE_RC_CONN_PARAM_UPD_NEG_RPY_OFF] & HCI_SUPP_COMMANDS_RLE_RC_CONN_PARAM_UPD_NEG_RPY_MASK) + +#endif + diff --git a/tools/sdk/include/bluedroid/hcimsgs.h b/tools/sdk/include/bluedroid/hcimsgs.h new file mode 100644 index 00000000..d360a9a1 --- /dev/null +++ b/tools/sdk/include/bluedroid/hcimsgs.h @@ -0,0 +1,811 @@ +/****************************************************************************** + * + * Copyright (C) 1999-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. + * + ******************************************************************************/ + +#ifndef HCIMSGS_H +#define HCIMSGS_H + +#include "bt_target.h" +#include "hcidefs.h" +#include "bt_types.h" + +void bte_main_hci_send(BT_HDR *p_msg, UINT16 event); +void bte_main_lpm_allow_bt_device_sleep(void); + +/* Message by message.... */ + +BOOLEAN btsnd_hcic_inquiry(const LAP inq_lap, UINT8 duration, + UINT8 response_cnt); + +#define HCIC_PARAM_SIZE_INQUIRY 5 + + +#define HCIC_INQ_INQ_LAP_OFF 0 +#define HCIC_INQ_DUR_OFF 3 +#define HCIC_INQ_RSP_CNT_OFF 4 +/* Inquiry */ + +/* Inquiry Cancel */ +BOOLEAN btsnd_hcic_inq_cancel(void); + +#define HCIC_PARAM_SIZE_INQ_CANCEL 0 + +/* Periodic Inquiry Mode */ +BOOLEAN btsnd_hcic_per_inq_mode(UINT16 max_period, UINT16 min_period, + const LAP inq_lap, UINT8 duration, + UINT8 response_cnt); + +#define HCIC_PARAM_SIZE_PER_INQ_MODE 9 + +#define HCI_PER_INQ_MAX_INTRVL_OFF 0 +#define HCI_PER_INQ_MIN_INTRVL_OFF 2 +#define HCI_PER_INQ_INQ_LAP_OFF 4 +#define HCI_PER_INQ_DURATION_OFF 7 +#define HCI_PER_INQ_RSP_CNT_OFF 8 +/* Periodic Inquiry Mode */ + +/* Exit Periodic Inquiry Mode */ +BOOLEAN btsnd_hcic_exit_per_inq(void); + +#define HCIC_PARAM_SIZE_EXIT_PER_INQ 0 +/* Create Connection */ +BOOLEAN btsnd_hcic_create_conn(BD_ADDR dest, UINT16 packet_types, + UINT8 page_scan_rep_mode, + UINT8 page_scan_mode, + UINT16 clock_offset, + UINT8 allow_switch); + +#define HCIC_PARAM_SIZE_CREATE_CONN 13 + +#define HCIC_CR_CONN_BD_ADDR_OFF 0 +#define HCIC_CR_CONN_PKT_TYPES_OFF 6 +#define HCIC_CR_CONN_REP_MODE_OFF 8 +#define HCIC_CR_CONN_PAGE_SCAN_MODE_OFF 9 +#define HCIC_CR_CONN_CLK_OFF_OFF 10 +#define HCIC_CR_CONN_ALLOW_SWITCH_OFF 12 +/* Create Connection */ + +/* Disconnect */ +BOOLEAN btsnd_hcic_disconnect(UINT16 handle, UINT8 reason); + +#define HCIC_PARAM_SIZE_DISCONNECT 3 + +#define HCI_DISC_HANDLE_OFF 0 +#define HCI_DISC_REASON_OFF 2 +/* Disconnect */ + +#if BTM_SCO_INCLUDED == TRUE +/* Add SCO Connection */ +BOOLEAN btsnd_hcic_add_SCO_conn (UINT16 handle, UINT16 packet_types); +#endif /* BTM_SCO_INCLUDED */ + +#define HCIC_PARAM_SIZE_ADD_SCO_CONN 4 + +#define HCI_ADD_SCO_HANDLE_OFF 0 +#define HCI_ADD_SCO_PACKET_TYPES_OFF 2 +/* Add SCO Connection */ + +/* Create Connection Cancel */ +BOOLEAN btsnd_hcic_create_conn_cancel(BD_ADDR dest); + +#define HCIC_PARAM_SIZE_CREATE_CONN_CANCEL 6 + +#define HCIC_CR_CONN_CANCEL_BD_ADDR_OFF 0 +/* Create Connection Cancel */ + +/* Accept Connection Request */ +BOOLEAN btsnd_hcic_accept_conn (BD_ADDR bd_addr, UINT8 role); + +#define HCIC_PARAM_SIZE_ACCEPT_CONN 7 + +#define HCI_ACC_CONN_BD_ADDR_OFF 0 +#define HCI_ACC_CONN_ROLE_OFF 6 +/* Accept Connection Request */ + +/* Reject Connection Request */ +BOOLEAN btsnd_hcic_reject_conn (BD_ADDR bd_addr, UINT8 reason); + +#define HCIC_PARAM_SIZE_REJECT_CONN 7 + +#define HCI_REJ_CONN_BD_ADDR_OFF 0 +#define HCI_REJ_CONN_REASON_OFF 6 +/* Reject Connection Request */ + +/* Link Key Request Reply */ +BOOLEAN btsnd_hcic_link_key_req_reply (BD_ADDR bd_addr, + LINK_KEY link_key); + +#define HCIC_PARAM_SIZE_LINK_KEY_REQ_REPLY 22 + +#define HCI_LINK_KEY_REPLY_BD_ADDR_OFF 0 +#define HCI_LINK_KEY_REPLY_LINK_KEY_OFF 6 +/* Link Key Request Reply */ + +/* Link Key Request Neg Reply */ +BOOLEAN btsnd_hcic_link_key_neg_reply (BD_ADDR bd_addr); + +#define HCIC_PARAM_SIZE_LINK_KEY_NEG_REPLY 6 + +#define HCI_LINK_KEY_NEG_REP_BD_ADR_OFF 0 +/* Link Key Request Neg Reply */ + +/* PIN Code Request Reply */ +BOOLEAN btsnd_hcic_pin_code_req_reply (BD_ADDR bd_addr, + UINT8 pin_code_len, + PIN_CODE pin_code); + +#define HCIC_PARAM_SIZE_PIN_CODE_REQ_REPLY 23 + +#define HCI_PIN_CODE_REPLY_BD_ADDR_OFF 0 +#define HCI_PIN_CODE_REPLY_PIN_LEN_OFF 6 +#define HCI_PIN_CODE_REPLY_PIN_CODE_OFF 7 +/* PIN Code Request Reply */ + +/* Link Key Request Neg Reply */ +BOOLEAN btsnd_hcic_pin_code_neg_reply (BD_ADDR bd_addr); + +#define HCIC_PARAM_SIZE_PIN_CODE_NEG_REPLY 6 + +#define HCI_PIN_CODE_NEG_REP_BD_ADR_OFF 0 +/* Link Key Request Neg Reply */ + +/* Change Connection Type */ +BOOLEAN btsnd_hcic_change_conn_type (UINT16 handle, UINT16 packet_types); + +#define HCIC_PARAM_SIZE_CHANGE_CONN_TYPE 4 + +#define HCI_CHNG_PKT_TYPE_HANDLE_OFF 0 +#define HCI_CHNG_PKT_TYPE_PKT_TYPE_OFF 2 +/* Change Connection Type */ + +#define HCIC_PARAM_SIZE_CMD_HANDLE 2 + +#define HCI_CMD_HANDLE_HANDLE_OFF 0 + +BOOLEAN btsnd_hcic_auth_request (UINT16 handle); /* Authentication Request */ + +/* Set Connection Encryption */ +BOOLEAN btsnd_hcic_set_conn_encrypt (UINT16 handle, BOOLEAN enable); +#define HCIC_PARAM_SIZE_SET_CONN_ENCRYPT 3 + + +#define HCI_SET_ENCRYPT_HANDLE_OFF 0 +#define HCI_SET_ENCRYPT_ENABLE_OFF 2 +/* Set Connection Encryption */ + +/* Remote Name Request */ +BOOLEAN btsnd_hcic_rmt_name_req (BD_ADDR bd_addr, + UINT8 page_scan_rep_mode, + UINT8 page_scan_mode, + UINT16 clock_offset); + +#define HCIC_PARAM_SIZE_RMT_NAME_REQ 10 + +#define HCI_RMT_NAME_BD_ADDR_OFF 0 +#define HCI_RMT_NAME_REP_MODE_OFF 6 +#define HCI_RMT_NAME_PAGE_SCAN_MODE_OFF 7 +#define HCI_RMT_NAME_CLK_OFF_OFF 8 +/* Remote Name Request */ + +/* Remote Name Request Cancel */ +BOOLEAN btsnd_hcic_rmt_name_req_cancel(BD_ADDR bd_addr); + +#define HCIC_PARAM_SIZE_RMT_NAME_REQ_CANCEL 6 + +#define HCI_RMT_NAME_CANCEL_BD_ADDR_OFF 0 +/* Remote Name Request Cancel */ + +BOOLEAN btsnd_hcic_rmt_features_req(UINT16 handle); /* Remote Features Request */ + +/* Remote Extended Features */ +BOOLEAN btsnd_hcic_rmt_ext_features(UINT16 handle, UINT8 page_num); + +#define HCIC_PARAM_SIZE_RMT_EXT_FEATURES 3 + +#define HCI_RMT_EXT_FEATURES_HANDLE_OFF 0 +#define HCI_RMT_EXT_FEATURES_PAGE_NUM_OFF 2 +/* Remote Extended Features */ + + +BOOLEAN btsnd_hcic_rmt_ver_req(UINT16 handle); /* Remote Version Info Request */ +BOOLEAN btsnd_hcic_read_rmt_clk_offset(UINT16 handle); /* Remote Clock Offset */ +BOOLEAN btsnd_hcic_read_lmp_handle(UINT16 handle); /* Remote LMP Handle */ + +BOOLEAN btsnd_hcic_setup_esco_conn (UINT16 handle, + UINT32 tx_bw, UINT32 rx_bw, + UINT16 max_latency, UINT16 voice, + UINT8 retrans_effort, + UINT16 packet_types); +#define HCIC_PARAM_SIZE_SETUP_ESCO 17 + +#define HCI_SETUP_ESCO_HANDLE_OFF 0 +#define HCI_SETUP_ESCO_TX_BW_OFF 2 +#define HCI_SETUP_ESCO_RX_BW_OFF 6 +#define HCI_SETUP_ESCO_MAX_LAT_OFF 10 +#define HCI_SETUP_ESCO_VOICE_OFF 12 +#define HCI_SETUP_ESCO_RETRAN_EFF_OFF 14 +#define HCI_SETUP_ESCO_PKT_TYPES_OFF 15 + + +BOOLEAN btsnd_hcic_accept_esco_conn (BD_ADDR bd_addr, + UINT32 tx_bw, UINT32 rx_bw, + UINT16 max_latency, + UINT16 content_fmt, + UINT8 retrans_effort, + UINT16 packet_types); +#define HCIC_PARAM_SIZE_ACCEPT_ESCO 21 + +#define HCI_ACCEPT_ESCO_BDADDR_OFF 0 +#define HCI_ACCEPT_ESCO_TX_BW_OFF 6 +#define HCI_ACCEPT_ESCO_RX_BW_OFF 10 +#define HCI_ACCEPT_ESCO_MAX_LAT_OFF 14 +#define HCI_ACCEPT_ESCO_VOICE_OFF 16 +#define HCI_ACCEPT_ESCO_RETRAN_EFF_OFF 18 +#define HCI_ACCEPT_ESCO_PKT_TYPES_OFF 19 + + +BOOLEAN btsnd_hcic_reject_esco_conn (BD_ADDR bd_addr, UINT8 reason); +#define HCIC_PARAM_SIZE_REJECT_ESCO 7 + +#define HCI_REJECT_ESCO_BDADDR_OFF 0 +#define HCI_REJECT_ESCO_REASON_OFF 6 + +/* Hold Mode */ +BOOLEAN btsnd_hcic_hold_mode(UINT16 handle, UINT16 max_hold_period, + UINT16 min_hold_period); + +#define HCIC_PARAM_SIZE_HOLD_MODE 6 + +#define HCI_HOLD_MODE_HANDLE_OFF 0 +#define HCI_HOLD_MODE_MAX_PER_OFF 2 +#define HCI_HOLD_MODE_MIN_PER_OFF 4 +/* Hold Mode */ + +/* Sniff Mode */ +BOOLEAN btsnd_hcic_sniff_mode(UINT16 handle, + UINT16 max_sniff_period, + UINT16 min_sniff_period, + UINT16 sniff_attempt, + UINT16 sniff_timeout); + +#define HCIC_PARAM_SIZE_SNIFF_MODE 10 + + +#define HCI_SNIFF_MODE_HANDLE_OFF 0 +#define HCI_SNIFF_MODE_MAX_PER_OFF 2 +#define HCI_SNIFF_MODE_MIN_PER_OFF 4 +#define HCI_SNIFF_MODE_ATTEMPT_OFF 6 +#define HCI_SNIFF_MODE_TIMEOUT_OFF 8 +/* Sniff Mode */ + +BOOLEAN btsnd_hcic_exit_sniff_mode(UINT16 handle); /* Exit Sniff Mode */ + +/* Park Mode */ +BOOLEAN btsnd_hcic_park_mode (UINT16 handle, + UINT16 beacon_max_interval, + UINT16 beacon_min_interval); + +#define HCIC_PARAM_SIZE_PARK_MODE 6 + +#define HCI_PARK_MODE_HANDLE_OFF 0 +#define HCI_PARK_MODE_MAX_PER_OFF 2 +#define HCI_PARK_MODE_MIN_PER_OFF 4 +/* Park Mode */ + +BOOLEAN btsnd_hcic_exit_park_mode(UINT16 handle); /* Exit Park Mode */ + +/* QoS Setup */ +BOOLEAN btsnd_hcic_qos_setup (UINT16 handle, UINT8 flags, + UINT8 service_type, + UINT32 token_rate, UINT32 peak, + UINT32 latency, UINT32 delay_var); + +#define HCIC_PARAM_SIZE_QOS_SETUP 20 + +#define HCI_QOS_HANDLE_OFF 0 +#define HCI_QOS_FLAGS_OFF 2 +#define HCI_QOS_SERVICE_TYPE_OFF 3 +#define HCI_QOS_TOKEN_RATE_OFF 4 +#define HCI_QOS_PEAK_BANDWIDTH_OFF 8 +#define HCI_QOS_LATENCY_OFF 12 +#define HCI_QOS_DELAY_VAR_OFF 16 +/* QoS Setup */ + +/* Switch Role Request */ +BOOLEAN btsnd_hcic_switch_role (BD_ADDR bd_addr, UINT8 role); + +#define HCIC_PARAM_SIZE_SWITCH_ROLE 7 + +#define HCI_SWITCH_BD_ADDR_OFF 0 +#define HCI_SWITCH_ROLE_OFF 6 +/* Switch Role Request */ + +/* Write Policy Settings */ +BOOLEAN btsnd_hcic_write_policy_set(UINT16 handle, UINT16 settings); + +#define HCIC_PARAM_SIZE_WRITE_POLICY_SET 4 + +#define HCI_WRITE_POLICY_HANDLE_OFF 0 +#define HCI_WRITE_POLICY_SETTINGS_OFF 2 +/* Write Policy Settings */ + +/* Write Default Policy Settings */ +BOOLEAN btsnd_hcic_write_def_policy_set(UINT16 settings); + +#define HCIC_PARAM_SIZE_WRITE_DEF_POLICY_SET 2 + +#define HCI_WRITE_DEF_POLICY_SETTINGS_OFF 0 +/* Write Default Policy Settings */ + +/****************************************** +** Lisbon Features +*******************************************/ +#if BTM_SSR_INCLUDED == TRUE +/* Sniff Subrating */ +BOOLEAN btsnd_hcic_sniff_sub_rate(UINT16 handle, UINT16 max_lat, + UINT16 min_remote_lat, + UINT16 min_local_lat); + +#define HCIC_PARAM_SIZE_SNIFF_SUB_RATE 8 + +#define HCI_SNIFF_SUB_RATE_HANDLE_OFF 0 +#define HCI_SNIFF_SUB_RATE_MAX_LAT_OFF 2 +#define HCI_SNIFF_SUB_RATE_MIN_REM_LAT_OFF 4 +#define HCI_SNIFF_SUB_RATE_MIN_LOC_LAT_OFF 6 +/* Sniff Subrating */ + +#else /* BTM_SSR_INCLUDED == FALSE */ + +#define btsnd_hcic_sniff_sub_rate(handle, max_lat, min_remote_lat, min_local_lat) FALSE + +#endif /* BTM_SSR_INCLUDED */ + +/* Extended Inquiry Response */ +void btsnd_hcic_write_ext_inquiry_response(void *buffer, UINT8 fec_req); + +#define HCIC_PARAM_SIZE_EXT_INQ_RESP 241 + +#define HCIC_EXT_INQ_RESP_FEC_OFF 0 +#define HCIC_EXT_INQ_RESP_RESPONSE 1 +/* IO Capabilities Response */ +BOOLEAN btsnd_hcic_io_cap_req_reply (BD_ADDR bd_addr, UINT8 capability, + UINT8 oob_present, UINT8 auth_req); + +#define HCIC_PARAM_SIZE_IO_CAP_RESP 9 + +#define HCI_IO_CAP_BD_ADDR_OFF 0 +#define HCI_IO_CAPABILITY_OFF 6 +#define HCI_IO_CAP_OOB_DATA_OFF 7 +#define HCI_IO_CAP_AUTH_REQ_OFF 8 + +/* IO Capabilities Req Neg Reply */ +BOOLEAN btsnd_hcic_io_cap_req_neg_reply (BD_ADDR bd_addr, UINT8 err_code); + +#define HCIC_PARAM_SIZE_IO_CAP_NEG_REPLY 7 + +#define HCI_IO_CAP_NR_BD_ADDR_OFF 0 +#define HCI_IO_CAP_NR_ERR_CODE 6 + +/* Read Local OOB Data */ +BOOLEAN btsnd_hcic_read_local_oob_data (void); + +#define HCIC_PARAM_SIZE_R_LOCAL_OOB 0 + + +BOOLEAN btsnd_hcic_user_conf_reply (BD_ADDR bd_addr, BOOLEAN is_yes); + +#define HCIC_PARAM_SIZE_UCONF_REPLY 6 + +#define HCI_USER_CONF_BD_ADDR_OFF 0 + + +BOOLEAN btsnd_hcic_user_passkey_reply (BD_ADDR bd_addr, UINT32 value); + +#define HCIC_PARAM_SIZE_U_PKEY_REPLY 10 + +#define HCI_USER_PASSKEY_BD_ADDR_OFF 0 +#define HCI_USER_PASSKEY_VALUE_OFF 6 + + +BOOLEAN btsnd_hcic_user_passkey_neg_reply (BD_ADDR bd_addr); + +#define HCIC_PARAM_SIZE_U_PKEY_NEG_REPLY 6 + +#define HCI_USER_PASSKEY_NEG_BD_ADDR_OFF 0 + +/* Remote OOB Data Request Reply */ +BOOLEAN btsnd_hcic_rem_oob_reply (BD_ADDR bd_addr, UINT8 *p_c, + UINT8 *p_r); + +#define HCIC_PARAM_SIZE_REM_OOB_REPLY 38 + +#define HCI_REM_OOB_DATA_BD_ADDR_OFF 0 +#define HCI_REM_OOB_DATA_C_OFF 6 +#define HCI_REM_OOB_DATA_R_OFF 22 + +/* Remote OOB Data Request Negative Reply */ +BOOLEAN btsnd_hcic_rem_oob_neg_reply (BD_ADDR bd_addr); + +#define HCIC_PARAM_SIZE_REM_OOB_NEG_REPLY 6 + +#define HCI_REM_OOB_DATA_NEG_BD_ADDR_OFF 0 + +/* Read Tx Power Level */ +BOOLEAN btsnd_hcic_read_inq_tx_power (void); + +#define HCIC_PARAM_SIZE_R_TX_POWER 0 + +/* Read Default Erroneous Data Reporting */ +BOOLEAN btsnd_hcic_read_default_erroneous_data_rpt (void); + +#define HCIC_PARAM_SIZE_R_ERR_DATA_RPT 0 + +#if L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE +BOOLEAN btsnd_hcic_enhanced_flush (UINT16 handle, UINT8 packet_type); + +#define HCIC_PARAM_SIZE_ENHANCED_FLUSH 3 +#endif + + +BOOLEAN btsnd_hcic_send_keypress_notif (BD_ADDR bd_addr, UINT8 notif); + +#define HCIC_PARAM_SIZE_SEND_KEYPRESS_NOTIF 7 + +#define HCI_SEND_KEYPRESS_NOTIF_BD_ADDR_OFF 0 +#define HCI_SEND_KEYPRESS_NOTIF_NOTIF_OFF 6 + +/**** end of Simple Pairing Commands ****/ + +/* Store Current Settings */ +#define MAX_FILT_COND (sizeof (BD_ADDR) + 1) + +BOOLEAN btsnd_hcic_set_event_filter(UINT8 filt_type, + UINT8 filt_cond_type, + UINT8 *filt_cond, + UINT8 filt_cond_len); + +#define HCIC_PARAM_SIZE_SET_EVT_FILTER 9 + +#define HCI_FILT_COND_FILT_TYPE_OFF 0 +#define HCI_FILT_COND_COND_TYPE_OFF 1 +#define HCI_FILT_COND_FILT_OFF 2 +/* Set Event Filter */ + +/* Delete Stored Key */ +BOOLEAN btsnd_hcic_delete_stored_key (BD_ADDR bd_addr, BOOLEAN delete_all_flag); + +#define HCIC_PARAM_SIZE_DELETE_STORED_KEY 7 + +#define HCI_DELETE_KEY_BD_ADDR_OFF 0 +#define HCI_DELETE_KEY_ALL_FLAG_OFF 6 +/* Delete Stored Key */ + +/* Change Local Name */ +BOOLEAN btsnd_hcic_change_name(BD_NAME name); + +#define HCIC_PARAM_SIZE_CHANGE_NAME BD_NAME_LEN + +#define HCI_CHANGE_NAME_NAME_OFF 0 +/* Change Local Name */ + + +#define HCIC_PARAM_SIZE_READ_CMD 0 + +#define HCIC_PARAM_SIZE_WRITE_PARAM1 1 + +#define HCIC_WRITE_PARAM1_PARAM_OFF 0 + +#define HCIC_PARAM_SIZE_WRITE_PARAM2 2 + +#define HCIC_WRITE_PARAM2_PARAM_OFF 0 + +#define HCIC_PARAM_SIZE_WRITE_PARAM3 3 + +#define HCIC_WRITE_PARAM3_PARAM_OFF 0 + +#define HCIC_PARAM_SIZE_SET_AFH_CHANNELS 10 + +BOOLEAN btsnd_hcic_write_pin_type(UINT8 type); /* Write PIN Type */ +BOOLEAN btsnd_hcic_write_auto_accept(UINT8 flag); /* Write Auto Accept */ +BOOLEAN btsnd_hcic_read_name (void); /* Read Local Name */ +BOOLEAN btsnd_hcic_write_page_tout(UINT16 timeout); /* Write Page Timout */ +BOOLEAN btsnd_hcic_write_scan_enable(UINT8 flag); /* Write Scan Enable */ +BOOLEAN btsnd_hcic_write_pagescan_cfg(UINT16 interval, + UINT16 window); /* Write Page Scan Activity */ + +#define HCIC_PARAM_SIZE_WRITE_PAGESCAN_CFG 4 + +#define HCI_SCAN_CFG_INTERVAL_OFF 0 +#define HCI_SCAN_CFG_WINDOW_OFF 2 +/* Write Page Scan Activity */ + +/* Write Inquiry Scan Activity */ +BOOLEAN btsnd_hcic_write_inqscan_cfg(UINT16 interval, UINT16 window); + +#define HCIC_PARAM_SIZE_WRITE_INQSCAN_CFG 4 + +#define HCI_SCAN_CFG_INTERVAL_OFF 0 +#define HCI_SCAN_CFG_WINDOW_OFF 2 +/* Write Inquiry Scan Activity */ + +BOOLEAN btsnd_hcic_write_auth_enable(UINT8 flag); /* Write Authentication Enable */ +BOOLEAN btsnd_hcic_write_dev_class(DEV_CLASS dev); /* Write Class of Device */ +BOOLEAN btsnd_hcic_write_voice_settings(UINT16 flags); /* Write Voice Settings */ + +/* Host Controller to Host flow control */ +#define HCI_HOST_FLOW_CTRL_OFF 0 +#define HCI_HOST_FLOW_CTRL_ACL_ON 1 +#define HCI_HOST_FLOW_CTRL_SCO_ON 2 +#define HCI_HOST_FLOW_CTRL_BOTH_ON 3 + +BOOLEAN btsnd_hcic_write_auto_flush_tout(UINT16 handle, + UINT16 timeout); /* Write Retransmit Timout */ + +#define HCIC_PARAM_SIZE_WRITE_AUTO_FLUSH_TOUT 4 + +#define HCI_FLUSH_TOUT_HANDLE_OFF 0 +#define HCI_FLUSH_TOUT_TOUT_OFF 2 + +BOOLEAN btsnd_hcic_read_tx_power(UINT16 handle, UINT8 type); /* Read Tx Power */ + +#define HCIC_PARAM_SIZE_READ_TX_POWER 3 + +#define HCI_READ_TX_POWER_HANDLE_OFF 0 +#define HCI_READ_TX_POWER_TYPE_OFF 2 + +/* Read transmit power level parameter */ +#define HCI_READ_CURRENT 0x00 +#define HCI_READ_MAXIMUM 0x01 + +BOOLEAN btsnd_hcic_host_num_xmitted_pkts (UINT8 num_handles, + UINT16 *handle, + UINT16 *num_pkts); /* Set Host Buffer Size */ + +#define HCIC_PARAM_SIZE_NUM_PKTS_DONE_SIZE sizeof(btmsg_hcic_num_pkts_done_t) + +#define MAX_DATA_HANDLES 10 + +#define HCI_PKTS_DONE_NUM_HANDLES_OFF 0 +#define HCI_PKTS_DONE_HANDLE_OFF 1 +#define HCI_PKTS_DONE_NUM_PKTS_OFF 3 + +/* Write Link Supervision Timeout */ +BOOLEAN btsnd_hcic_write_link_super_tout(UINT8 local_controller_id, UINT16 handle, UINT16 timeout); + +#define HCIC_PARAM_SIZE_WRITE_LINK_SUPER_TOUT 4 + +#define HCI_LINK_SUPER_TOUT_HANDLE_OFF 0 +#define HCI_LINK_SUPER_TOUT_TOUT_OFF 2 +/* Write Link Supervision Timeout */ + +BOOLEAN btsnd_hcic_write_cur_iac_lap (UINT8 num_cur_iac, + LAP *const iac_lap); /* Write Current IAC LAP */ + +#define MAX_IAC_LAPS 0x40 + +#define HCI_WRITE_IAC_LAP_NUM_OFF 0 +#define HCI_WRITE_IAC_LAP_LAP_OFF 1 +/* Write Current IAC LAP */ + +BOOLEAN btsnd_hcic_get_link_quality (UINT16 handle); /* Get Link Quality */ +BOOLEAN btsnd_hcic_read_rssi (UINT16 handle); /* Read RSSI */ +BOOLEAN btsnd_hcic_enable_test_mode (void); /* Enable Device Under Test Mode */ +BOOLEAN btsnd_hcic_write_pagescan_type(UINT8 type); /* Write Page Scan Type */ +BOOLEAN btsnd_hcic_write_inqscan_type(UINT8 type); /* Write Inquiry Scan Type */ +BOOLEAN btsnd_hcic_write_inquiry_mode(UINT8 type); /* Write Inquiry Mode */ + +#define HCI_DATA_HANDLE_MASK 0x0FFF + +#define HCID_GET_HANDLE_EVENT(p) (UINT16)((*((UINT8 *)((p) + 1) + p->offset) + \ + (*((UINT8 *)((p) + 1) + p->offset + 1) << 8))) + +#define HCID_GET_HANDLE(u16) (UINT16)((u16) & HCI_DATA_HANDLE_MASK) + +#define HCI_DATA_EVENT_MASK 3 +#define HCI_DATA_EVENT_OFFSET 12 +#define HCID_GET_EVENT(u16) (UINT8)(((u16) >> HCI_DATA_EVENT_OFFSET) & HCI_DATA_EVENT_MASK) + +#define HCI_DATA_BCAST_MASK 3 +#define HCI_DATA_BCAST_OFFSET 10 +#define HCID_GET_BCAST(u16) (UINT8)(((u16) >> HCI_DATA_BCAST_OFFSET) & HCI_DATA_BCAST_MASK) + +#define HCID_GET_ACL_LEN(p) (UINT16)((*((UINT8 *)((p) + 1) + p->offset + 2) + \ + (*((UINT8 *)((p) + 1) + p->offset + 3) << 8))) + +#define HCID_HEADER_SIZE 4 + +#define HCID_GET_SCO_LEN(p) (*((UINT8 *)((p) + 1) + p->offset + 2)) + +void btsnd_hcic_vendor_spec_cmd (void *buffer, UINT16 opcode, + UINT8 len, UINT8 *p_data, + void *p_cmd_cplt_cback); + +#if (BLE_INCLUDED == TRUE) +/******************************************************************************** +** BLE Commands +** Note: "local_controller_id" is for transport, not counted in HCI message size +*********************************************************************************/ +#define HCIC_BLE_RAND_DI_SIZE 8 +#define HCIC_BLE_ENCRYT_KEY_SIZE 16 +#define HCIC_BLE_IRK_SIZE 16 + +#define HCIC_PARAM_SIZE_SET_USED_FEAT_CMD 8 +#define HCIC_PARAM_SIZE_WRITE_RANDOM_ADDR_CMD 6 +#define HCIC_PARAM_SIZE_BLE_WRITE_ADV_PARAMS 15 +#define HCIC_PARAM_SIZE_BLE_WRITE_SCAN_RSP 31 +#define HCIC_PARAM_SIZE_WRITE_ADV_ENABLE 1 +#define HCIC_PARAM_SIZE_BLE_WRITE_SCAN_PARAM 7 +#define HCIC_PARAM_SIZE_BLE_WRITE_SCAN_ENABLE 2 +#define HCIC_PARAM_SIZE_BLE_CREATE_LL_CONN 25 +#define HCIC_PARAM_SIZE_BLE_CREATE_CONN_CANCEL 0 +#define HCIC_PARAM_SIZE_CLEAR_WHITE_LIST 0 +#define HCIC_PARAM_SIZE_ADD_WHITE_LIST 7 +#define HCIC_PARAM_SIZE_REMOVE_WHITE_LIST 7 +#define HCIC_PARAM_SIZE_BLE_UPD_LL_CONN_PARAMS 14 +#define HCIC_PARAM_SIZE_SET_HOST_CHNL_CLASS 5 +#define HCIC_PARAM_SIZE_READ_CHNL_MAP 2 +#define HCIC_PARAM_SIZE_BLE_READ_REMOTE_FEAT 2 +#define HCIC_PARAM_SIZE_BLE_ENCRYPT 32 +#define HCIC_PARAM_SIZE_BLE_RAND 0 +#define HCIC_PARAM_SIZE_WRITE_LE_HOST_SUPPORTED 2 + +#define HCIC_BLE_RAND_DI_SIZE 8 +#define HCIC_BLE_ENCRYT_KEY_SIZE 16 +#define HCIC_PARAM_SIZE_BLE_START_ENC (4 + HCIC_BLE_RAND_DI_SIZE + HCIC_BLE_ENCRYT_KEY_SIZE) +#define HCIC_PARAM_SIZE_LTK_REQ_REPLY (2 + HCIC_BLE_ENCRYT_KEY_SIZE) +#define HCIC_PARAM_SIZE_LTK_REQ_NEG_REPLY 2 +#define HCIC_BLE_CHNL_MAP_SIZE 5 +#define HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA 31 + +#define HCIC_PARAM_SIZE_BLE_ADD_DEV_RESOLVING_LIST (7 + HCIC_BLE_IRK_SIZE * 2) +#define HCIC_PARAM_SIZE_BLE_RM_DEV_RESOLVING_LIST 7 +#define HCIC_PARAM_SIZE_BLE_CLEAR_RESOLVING_LIST 0 +#define HCIC_PARAM_SIZE_BLE_READ_RESOLVING_LIST_SIZE 0 +#define HCIC_PARAM_SIZE_BLE_READ_RESOLVABLE_ADDR_PEER 7 +#define HCIC_PARAM_SIZE_BLE_READ_RESOLVABLE_ADDR_LOCAL 7 +#define HCIC_PARAM_SIZE_BLE_SET_ADDR_RESOLUTION_ENABLE 1 +#define HCIC_PARAM_SIZE_BLE_SET_RAND_PRIV_ADDR_TIMOUT 2 +#define HCIC_PARAM_SIZE_BLE_SET_DATA_LENGTH 6 +#define HCIC_PARAM_SIZE_BLE_WRITE_EXTENDED_SCAN_PARAM 11 + +/* ULP HCI command */ +BOOLEAN btsnd_hcic_ble_set_evt_mask (BT_EVENT_MASK event_mask); + +BOOLEAN btsnd_hcic_ble_read_buffer_size (void); + +BOOLEAN btsnd_hcic_ble_read_local_spt_feat (void); + +BOOLEAN btsnd_hcic_ble_set_local_used_feat (UINT8 feat_set[8]); + +BOOLEAN btsnd_hcic_ble_set_random_addr (BD_ADDR random_addr); + +BOOLEAN btsnd_hcic_ble_write_adv_params (UINT16 adv_int_min, UINT16 adv_int_max, + UINT8 adv_type, UINT8 addr_type_own, + UINT8 addr_type_dir, BD_ADDR direct_bda, + UINT8 channel_map, UINT8 adv_filter_policy); + +BOOLEAN btsnd_hcic_ble_read_adv_chnl_tx_power (void); + +BOOLEAN btsnd_hcic_ble_set_adv_data (UINT8 data_len, UINT8 *p_data); + +BOOLEAN btsnd_hcic_ble_set_scan_rsp_data (UINT8 data_len, UINT8 *p_scan_rsp); + +BOOLEAN btsnd_hcic_ble_set_adv_enable (UINT8 adv_enable); + +BOOLEAN btsnd_hcic_ble_set_scan_params (UINT8 scan_type, + UINT16 scan_int, UINT16 scan_win, + UINT8 addr_type, UINT8 scan_filter_policy); + +BOOLEAN btsnd_hcic_ble_set_scan_enable (UINT8 scan_enable, UINT8 duplicate); + +BOOLEAN btsnd_hcic_ble_create_ll_conn (UINT16 scan_int, UINT16 scan_win, + UINT8 init_filter_policy, UINT8 addr_type_peer, BD_ADDR bda_peer, UINT8 addr_type_own, + UINT16 conn_int_min, UINT16 conn_int_max, UINT16 conn_latency, UINT16 conn_timeout, + UINT16 min_ce_len, UINT16 max_ce_len); + +BOOLEAN btsnd_hcic_ble_create_conn_cancel (void); + +BOOLEAN btsnd_hcic_ble_read_white_list_size (void); + +BOOLEAN btsnd_hcic_ble_clear_white_list (void); + +BOOLEAN btsnd_hcic_ble_add_white_list (UINT8 addr_type, BD_ADDR bda); + +BOOLEAN btsnd_hcic_ble_remove_from_white_list (UINT8 addr_type, BD_ADDR bda); + +BOOLEAN btsnd_hcic_ble_upd_ll_conn_params (UINT16 handle, UINT16 conn_int_min, UINT16 conn_int_max, + UINT16 conn_latency, UINT16 conn_timeout, UINT16 min_len, UINT16 max_len); + +BOOLEAN btsnd_hcic_ble_set_host_chnl_class (UINT8 chnl_map[HCIC_BLE_CHNL_MAP_SIZE]); + +BOOLEAN btsnd_hcic_ble_read_chnl_map (UINT16 handle); + +BOOLEAN btsnd_hcic_ble_read_remote_feat ( UINT16 handle); + +BOOLEAN btsnd_hcic_ble_encrypt (UINT8 *key, UINT8 key_len, UINT8 *plain_text, UINT8 pt_len, void *p_cmd_cplt_cback); + +BOOLEAN btsnd_hcic_ble_rand (void *p_cmd_cplt_cback); + +BOOLEAN btsnd_hcic_ble_start_enc ( UINT16 handle, + UINT8 rand[HCIC_BLE_RAND_DI_SIZE], + UINT16 ediv, UINT8 ltk[HCIC_BLE_ENCRYT_KEY_SIZE]); + +BOOLEAN btsnd_hcic_ble_ltk_req_reply (UINT16 handle, UINT8 ltk[HCIC_BLE_ENCRYT_KEY_SIZE]); + +BOOLEAN btsnd_hcic_ble_ltk_req_neg_reply (UINT16 handle); + +BOOLEAN btsnd_hcic_ble_read_supported_states (void); + +BOOLEAN btsnd_hcic_ble_write_host_supported (UINT8 le_host_spt, UINT8 simul_le_host_spt); + +BOOLEAN btsnd_hcic_ble_read_host_supported (void); + +BOOLEAN btsnd_hcic_ble_receiver_test(UINT8 rx_freq); + +BOOLEAN btsnd_hcic_ble_transmitter_test(UINT8 tx_freq, UINT8 test_data_len, + UINT8 payload); +BOOLEAN btsnd_hcic_ble_test_end(void); + +#if (defined BLE_LLT_INCLUDED) && (BLE_LLT_INCLUDED == TRUE) + +#define HCIC_PARAM_SIZE_BLE_RC_PARAM_REQ_REPLY 14 +BOOLEAN btsnd_hcic_ble_rc_param_req_reply(UINT16 handle, + UINT16 conn_int_min, UINT16 conn_int_max, + UINT16 conn_latency, UINT16 conn_timeout, + UINT16 min_ce_len, UINT16 max_ce_len); + +#define HCIC_PARAM_SIZE_BLE_RC_PARAM_REQ_NEG_REPLY 3 +BOOLEAN btsnd_hcic_ble_rc_param_req_neg_reply(UINT16 handle, UINT8 reason); + +#endif /* BLE_LLT_INCLUDED */ + +BOOLEAN btsnd_hcic_ble_set_data_length(UINT16 conn_handle, UINT16 tx_octets, + UINT16 tx_time); + +BOOLEAN btsnd_hcic_ble_add_device_resolving_list (UINT8 addr_type_peer, + BD_ADDR bda_peer, + UINT8 irk_peer[HCIC_BLE_IRK_SIZE], + UINT8 irk_local[HCIC_BLE_IRK_SIZE]); + +BOOLEAN btsnd_hcic_ble_rm_device_resolving_list (UINT8 addr_type_peer, + BD_ADDR bda_peer); + +BOOLEAN btsnd_hcic_ble_clear_resolving_list (void); + +BOOLEAN btsnd_hcic_ble_read_resolvable_addr_peer (UINT8 addr_type_peer, + BD_ADDR bda_peer); + +BOOLEAN btsnd_hcic_ble_read_resolvable_addr_local (UINT8 addr_type_peer, + BD_ADDR bda_peer); + +BOOLEAN btsnd_hcic_ble_set_addr_resolution_enable (UINT8 addr_resolution_enable); + +BOOLEAN btsnd_hcic_ble_set_rand_priv_addr_timeout (UINT16 rpa_timout); + +#endif /* BLE_INCLUDED */ + +BOOLEAN btsnd_hcic_read_authenticated_payload_tout(UINT16 handle); + +BOOLEAN btsnd_hcic_write_authenticated_payload_tout(UINT16 handle, + UINT16 timeout); + +#define HCIC_PARAM_SIZE_WRITE_AUTHENT_PAYLOAD_TOUT 4 + +#define HCI__WRITE_AUTHENT_PAYLOAD_TOUT_HANDLE_OFF 0 +#define HCI__WRITE_AUTHENT_PAYLOAD_TOUT_TOUT_OFF 2 + +#endif diff --git a/tools/sdk/include/bluedroid/hid_le_prf.h b/tools/sdk/include/bluedroid/hid_le_prf.h new file mode 100644 index 00000000..6436573f --- /dev/null +++ b/tools/sdk/include/bluedroid/hid_le_prf.h @@ -0,0 +1,265 @@ +// 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. + +#include "prf_defs.h" + +#if (HIDD_LE_PROFILE_CFG) +#include "bta_gatts_int.h" +#include "bt_types.h" +#include "bta_api.h" +#include "gatt_api.h" +#include "bt_app_api.h" + +/// Maximal number of HIDS that can be added in the DB +#ifndef USE_ONE_HIDS_INSTANCE +#define HIDD_LE_NB_HIDS_INST_MAX (2) +#else +#define HIDD_LE_NB_HIDS_INST_MAX (1) +#endif + +// Number of HID reports defined in the service +#define HID_NUM_REPORTS 9 + + +#define ATT_SVC_HID 0x1812 + +/// Maximal number of Report Char. that can be added in the DB for one HIDS - Up to 11 +#define HIDD_LE_NB_REPORT_INST_MAX (5) + +/// Maximal length of Report Char. Value +#define HIDD_LE_REPORT_MAX_LEN (45) +/// Maximal length of Report Map Char. Value +#define HIDD_LE_REPORT_MAP_MAX_LEN (512) + +/// Length of Boot Report Char. Value Maximal Length +#define HIDD_LE_BOOT_REPORT_MAX_LEN (8) + +/// Boot KB Input Report Notification Configuration Bit Mask +#define HIDD_LE_BOOT_KB_IN_NTF_CFG_MASK (0x40) +/// Boot KB Input Report Notification Configuration Bit Mask +#define HIDD_LE_BOOT_MOUSE_IN_NTF_CFG_MASK (0x80) +/// Boot Report Notification Configuration Bit Mask +#define HIDD_LE_REPORT_NTF_CFG_MASK (0x20) + + +/* HID information flags */ +#define HID_FLAGS_REMOTE_WAKE 0x01 // RemoteWake +#define HID_FLAGS_NORMALLY_CONNECTABLE 0x02 // NormallyConnectable + +/* Control point commands */ +#define HID_CMD_SUSPEND 0x00 // Suspend +#define HID_CMD_EXIT_SUSPEND 0x01 // Exit Suspend + +/* HID protocol mode values */ +#define HID_PROTOCOL_MODE_BOOT 0x00 // Boot Protocol Mode +#define HID_PROTOCOL_MODE_REPORT 0x01 // Report Protocol Mode + +/* Attribute value lengths */ +#define HID_PROTOCOL_MODE_LEN 1 // HID Protocol Mode +#define HID_INFORMATION_LEN 4 // HID Information +#define HID_REPORT_REF_LEN 2 // HID Report Reference Descriptor +#define HID_EXT_REPORT_REF_LEN 2 // External Report Reference Descriptor + +// HID feature flags +#define HID_KBD_FLAGS HID_FLAGS_REMOTE_WAKE + + +/// HID Service Attributes Indexes +enum { + HIDD_LE_IDX_SVC, + + // Included Service + HIDD_LE_IDX_INCL_SVC, + + // HID Information + HIDD_LE_IDX_HID_INFO_CHAR, + HIDD_LE_IDX_HID_INFO_VAL, + + // HID Control Point + HIDD_LE_IDX_HID_CTNL_PT_CHAR, + HIDD_LE_IDX_HID_CTNL_PT_VAL, + + // Report Map + HIDD_LE_IDX_REPORT_MAP_CHAR, + HIDD_LE_IDX_REPORT_MAP_VAL, + HIDD_LE_IDX_REPORT_MAP_EXT_REP_REF, + + // Protocol Mode + HIDD_LE_IDX_PROTO_MODE_CHAR, + HIDD_LE_IDX_PROTO_MODE_VAL, + + // Boot Keyboard Input Report + HIDD_LE_IDX_BOOT_KB_IN_REPORT_CHAR, + HIDD_LE_IDX_BOOT_KB_IN_REPORT_VAL, + HIDD_LE_IDX_BOOT_KB_IN_REPORT_NTF_CFG, + + // Boot Keyboard Output Report + HIDD_LE_IDX_BOOT_KB_OUT_REPORT_CHAR, + HIDD_LE_IDX_BOOT_KB_OUT_REPORT_VAL, + + // Boot Mouse Input Report + HIDD_LE_IDX_BOOT_MOUSE_IN_REPORT_CHAR, + HIDD_LE_IDX_BOOT_MOUSE_IN_REPORT_VAL, + HIDD_LE_IDX_BOOT_MOUSE_IN_REPORT_NTF_CFG, + + // Report + HIDD_LE_IDX_REPORT_CHAR, + HIDD_LE_IDX_REPORT_VAL, + HIDD_LE_IDX_REPORT_REP_REF, + HIDD_LE_IDX_REPORT_NTF_CFG, + + HIDD_LE_IDX_NB, +}; + + +/// Attribute Table Indexes +enum { + HIDD_LE_INFO_CHAR, + HIDD_LE_CTNL_PT_CHAR, + HIDD_LE_REPORT_MAP_CHAR, + HIDD_LE_REPORT_CHAR, + HIDD_LE_PROTO_MODE_CHAR, + HIDD_LE_BOOT_KB_IN_REPORT_CHAR, + HIDD_LE_BOOT_KB_OUT_REPORT_CHAR, + HIDD_LE_BOOT_MOUSE_IN_REPORT_CHAR, + HIDD_LE_CHAR_MAX //= HIDD_LE_REPORT_CHAR + HIDD_LE_NB_REPORT_INST_MAX, +}; + +///att read event table Indexs +enum { + HIDD_LE_READ_INFO_EVT, + HIDD_LE_READ_CTNL_PT_EVT, + HIDD_LE_READ_REPORT_MAP_EVT, + HIDD_LE_READ_REPORT_EVT, + HIDD_LE_READ_PROTO_MODE_EVT, + HIDD_LE_BOOT_KB_IN_REPORT_EVT, + HIDD_LE_BOOT_KB_OUT_REPORT_EVT, + HIDD_LE_BOOT_MOUSE_IN_REPORT_EVT, + + HID_LE_EVT_MAX +}; + +/// Client Characteristic Configuration Codes +enum { + HIDD_LE_DESC_MASK = 0x10, + + HIDD_LE_BOOT_KB_IN_REPORT_CFG = HIDD_LE_BOOT_KB_IN_REPORT_CHAR | HIDD_LE_DESC_MASK, + HIDD_LE_BOOT_MOUSE_IN_REPORT_CFG = HIDD_LE_BOOT_MOUSE_IN_REPORT_CHAR | HIDD_LE_DESC_MASK, + HIDD_LE_REPORT_CFG = HIDD_LE_REPORT_CHAR | HIDD_LE_DESC_MASK, +}; + +/// Features Flag Values +enum { + HIDD_LE_CFG_KEYBOARD = 0x01, + HIDD_LE_CFG_MOUSE = 0x02, + HIDD_LE_CFG_PROTO_MODE = 0x04, + HIDD_LE_CFG_MAP_EXT_REF = 0x08, + HIDD_LE_CFG_BOOT_KB_WR = 0x10, + HIDD_LE_CFG_BOOT_MOUSE_WR = 0x20, +}; + +/// Report Char. Configuration Flag Values +enum { + HIDD_LE_CFG_REPORT_IN = 0x01, + HIDD_LE_CFG_REPORT_OUT = 0x02, + //HOGPD_CFG_REPORT_FEAT can be used as a mask to check Report type + HIDD_LE_CFG_REPORT_FEAT = 0x03, + HIDD_LE_CFG_REPORT_WR = 0x10, +}; + +/// Pointer to the connection clean-up function +#define HIDD_LE_CLEANUP_FNCT (NULL) + +/* + * TYPE DEFINITIONS + **************************************************************************************** + */ + +/// HIDD Features structure +typedef struct { + /// Service Features + uint8_t svc_features; + /// Number of Report Char. instances to add in the database + uint8_t report_nb; + /// Report Char. Configuration + uint8_t report_char_cfg[HIDD_LE_NB_REPORT_INST_MAX]; +} hidd_feature_t; + + +typedef struct { + BOOLEAN in_use; + BOOLEAN congest; + uint16_t conn_id; + BOOLEAN connected; + BD_ADDR remote_bda; + uint32_t trans_id; + uint8_t cur_srvc_id; + +} hidd_clcb_t; + +// HID report mapping table +typedef struct { + uint16_t handle; // Handle of report characteristic + uint16_t cccdHandle; // Handle of CCCD for report characteristic + uint8_t id; // Report ID + uint8_t type; // Report type + uint8_t mode; // Protocol mode (report or boot) +} hidRptMap_t; + + +typedef struct { + /// hidd profile id + uint8_t app_id; + /// Notified handle + uint16_t ntf_handle; + ///Attribute handle Table + uint16_t att_tbl[HIDD_LE_CHAR_MAX]; + /// Supported Features + hidd_feature_t hidd_feature[HIDD_LE_NB_HIDS_INST_MAX]; + /// Current Protocol Mode + uint8_t proto_mode[HIDD_LE_NB_HIDS_INST_MAX]; + /// Number of HIDS added in the database + uint8_t hids_nb; + uint8_t pending_evt; + uint16_t pending_hal; +} hidd_inst_t; + + +/* service engine control block */ +typedef struct { + hidd_clcb_t hidd_clcb; /* connection link*/ + esp_gatt_if_t gatt_if; + BOOLEAN enabled; + BOOLEAN is_primery; + hidd_inst_t hidd_inst; + uint8_t inst_id; +} hidd_le_env_t; + +extern hidd_le_env_t hidd_le_env; + + +void hidd_le_create_service(BOOLEAN is_primary); + +void hidd_rsp (uint32_t trans_id, uint16_t conn_id, uint8_t app_id, + esp_gatt_status_t status, uint8_t event, tGATTS_DATA *p_rsp); + +void hidd_read_attr_value(tGATTS_DATA *p_data, uint32_t trans_id); + + +tGATT_STATUS hidd_le_init (void); + + +#endif ///HIDD_LE_PROFILE_CFG + + diff --git a/tools/sdk/include/bluedroid/hiddefs.h b/tools/sdk/include/bluedroid/hiddefs.h new file mode 100644 index 00000000..c8c3d3cb --- /dev/null +++ b/tools/sdk/include/bluedroid/hiddefs.h @@ -0,0 +1,156 @@ +/****************************************************************************** + * + * 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 file contains HID protocol definitions + * + ******************************************************************************/ + +#ifndef HIDDEFS_H +#define HIDDEFS_H + +#include "sdp_api.h" +/* +** tHID_STATUS: HID result codes, returned by HID and device and host functions. +*/ +enum { + HID_SUCCESS, + HID_ERR_NOT_REGISTERED, + HID_ERR_ALREADY_REGISTERED, + HID_ERR_NO_RESOURCES, + HID_ERR_NO_CONNECTION, + HID_ERR_INVALID_PARAM, + HID_ERR_UNSUPPORTED, + HID_ERR_UNKNOWN_COMMAND, + HID_ERR_CONGESTED, + HID_ERR_CONN_IN_PROCESS, + HID_ERR_ALREADY_CONN, + HID_ERR_DISCONNECTING, + HID_ERR_SET_CONNABLE_FAIL, + /* Device specific error codes */ + HID_ERR_HOST_UNKNOWN, + HID_ERR_L2CAP_FAILED, + HID_ERR_AUTH_FAILED, + HID_ERR_SDP_BUSY, + HID_ERR_GATT, + + HID_ERR_INVALID = 0xFF +}; + +typedef UINT8 tHID_STATUS; + +#define HID_L2CAP_CONN_FAIL (0x0100) /* Connection Attempt was made but failed */ +#define HID_L2CAP_REQ_FAIL (0x0200) /* L2CAP_ConnectReq API failed */ +#define HID_L2CAP_CFG_FAIL (0x0400) /* L2CAP Configuration was rejected by peer */ + + + +/* Define the HID transaction types +*/ +#define HID_TRANS_HANDSHAKE (0) +#define HID_TRANS_CONTROL (1) +#define HID_TRANS_GET_REPORT (4) +#define HID_TRANS_SET_REPORT (5) +#define HID_TRANS_GET_PROTOCOL (6) +#define HID_TRANS_SET_PROTOCOL (7) +#define HID_TRANS_GET_IDLE (8) +#define HID_TRANS_SET_IDLE (9) +#define HID_TRANS_DATA (10) +#define HID_TRANS_DATAC (11) + +#define HID_GET_TRANS_FROM_HDR(x) ((x >> 4) & 0x0f) +#define HID_GET_PARAM_FROM_HDR(x) (x & 0x0f) +#define HID_BUILD_HDR(t,p) (UINT8)((t << 4) | (p & 0x0f)) + + +/* Parameters for Handshake +*/ +#define HID_PAR_HANDSHAKE_RSP_SUCCESS (0) +#define HID_PAR_HANDSHAKE_RSP_NOT_READY (1) +#define HID_PAR_HANDSHAKE_RSP_ERR_INVALID_REP_ID (2) +#define HID_PAR_HANDSHAKE_RSP_ERR_UNSUPPORTED_REQ (3) +#define HID_PAR_HANDSHAKE_RSP_ERR_INVALID_PARAM (4) +#define HID_PAR_HANDSHAKE_RSP_ERR_UNKNOWN (14) +#define HID_PAR_HANDSHAKE_RSP_ERR_FATAL (15) + + +/* Parameters for Control +*/ +#define HID_PAR_CONTROL_NOP (0) +#define HID_PAR_CONTROL_HARD_RESET (1) +#define HID_PAR_CONTROL_SOFT_RESET (2) +#define HID_PAR_CONTROL_SUSPEND (3) +#define HID_PAR_CONTROL_EXIT_SUSPEND (4) +#define HID_PAR_CONTROL_VIRTUAL_CABLE_UNPLUG (5) + + +/* Different report types in get, set, data +*/ +#define HID_PAR_REP_TYPE_MASK (0x03) +#define HID_PAR_REP_TYPE_OTHER (0x00) +#define HID_PAR_REP_TYPE_INPUT (0x01) +#define HID_PAR_REP_TYPE_OUTPUT (0x02) +#define HID_PAR_REP_TYPE_FEATURE (0x03) + +/* Parameters for Get Report +*/ + +/* Buffer size in two bytes after Report ID */ +#define HID_PAR_GET_REP_BUFSIZE_FOLLOWS (0x08) + + +/* Parameters for Protocol Type +*/ +#define HID_PAR_PROTOCOL_MASK (0x01) +#define HID_PAR_PROTOCOL_REPORT (0x01) +#define HID_PAR_PROTOCOL_BOOT_MODE (0x00) + +#define HID_PAR_REP_TYPE_MASK (0x03) + +/* Descriptor types in the SDP record +*/ +#define HID_SDP_DESCRIPTOR_REPORT (0x22) +#define HID_SDP_DESCRIPTOR_PHYSICAL (0x23) + +typedef struct desc_info { + UINT16 dl_len; + UINT8 *dsc_list; +} tHID_DEV_DSCP_INFO; + +#define HID_SSR_PARAM_INVALID 0xffff + +typedef struct sdp_info { + char svc_name[HID_MAX_SVC_NAME_LEN]; /*Service Name */ + char svc_descr[HID_MAX_SVC_DESCR_LEN]; /*Service Description*/ + char prov_name[HID_MAX_PROV_NAME_LEN]; /*Provider Name.*/ + UINT16 rel_num; /*Release Number */ + UINT16 hpars_ver; /*HID Parser Version.*/ + UINT16 ssr_max_latency; /* HIDSSRHostMaxLatency value, if HID_SSR_PARAM_INVALID not used*/ + UINT16 ssr_min_tout; /* HIDSSRHostMinTimeout value, if HID_SSR_PARAM_INVALID not used* */ + UINT8 sub_class; /*Device Subclass.*/ + UINT8 ctry_code; /*Country Code.*/ + UINT16 sup_timeout;/* Supervisory Timeout */ + + tHID_DEV_DSCP_INFO dscp_info; /* Descriptor list and Report list to be set in the SDP record. + This parameter is used if HID_DEV_USE_GLB_SDP_REC is set to FALSE.*/ + tSDP_DISC_REC *p_sdp_layer_rec; +} tHID_DEV_SDP_INFO; + +#endif + diff --git a/tools/sdk/include/bluedroid/hidh_api.h b/tools/sdk/include/bluedroid/hidh_api.h new file mode 100644 index 00000000..499e6462 --- /dev/null +++ b/tools/sdk/include/bluedroid/hidh_api.h @@ -0,0 +1,235 @@ +/****************************************************************************** + * + * 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. + * + ******************************************************************************/ +#ifndef HIDH_API_H +#define HIDH_API_H + +#include "hiddefs.h" +#include "sdp_api.h" + +/***************************************************************************** +** Constants +*****************************************************************************/ + +enum { + HID_SDP_NO_SERV_UUID = (SDP_ILLEGAL_PARAMETER + 1), + HID_SDP_MANDATORY_MISSING +}; + +/* Attributes mask values to be used in HID_HostAddDev API */ +#define HID_VIRTUAL_CABLE 0x0001 +#define HID_NORMALLY_CONNECTABLE 0x0002 +#define HID_RECONN_INIT 0x0004 +#define HID_SDP_DISABLE 0x0008 +#define HID_BATTERY_POWER 0x0010 +#define HID_REMOTE_WAKE 0x0020 +#define HID_SUP_TOUT_AVLBL 0x0040 +#define HID_SSR_MAX_LATENCY 0x0080 +#define HID_SSR_MIN_TOUT 0x0100 + +#define HID_SEC_REQUIRED 0x8000 +#define HID_ATTR_MASK_IGNORE 0 + + +/***************************************************************************** +** Type Definitions +*****************************************************************************/ + +typedef void (tHID_HOST_SDP_CALLBACK) (UINT16 result, UINT16 attr_mask, + tHID_DEV_SDP_INFO *sdp_rec ); + +/* HID-HOST returns the events in the following table to the application via tHID_HOST_DEV_CALLBACK +HID_HDEV_EVT_OPEN Connected to device with Interrupt and Control Channels in OPEN state. + Data = NA +HID_HDEV_EVT_CLOSE Connection with device is closed. Data=reason code. +HID_HDEV_EVT_RETRYING Lost connection is being re-connected. + Data=Retrial number +HID_HDEV_EVT_IN_REPORT Device sent an input report Data=Report Type pdata= pointer to BT_HDR + (GKI buffer having report data.) +HID_HDEV_EVT_HANDSHAKE Device sent SET_REPORT Data=Result-code pdata=NA. +HID_HDEV_EVT_VC_UNPLUG Device sent Virtual Unplug Data=NA. pdata=NA. +*/ + +enum { + HID_HDEV_EVT_OPEN, + HID_HDEV_EVT_CLOSE, + HID_HDEV_EVT_RETRYING, + HID_HDEV_EVT_INTR_DATA, + HID_HDEV_EVT_INTR_DATC, + HID_HDEV_EVT_CTRL_DATA, + HID_HDEV_EVT_CTRL_DATC, + HID_HDEV_EVT_HANDSHAKE, + HID_HDEV_EVT_VC_UNPLUG +}; +typedef void (tHID_HOST_DEV_CALLBACK) (UINT8 dev_handle, + BD_ADDR addr, + UINT8 event, /* Event from HID-DEVICE. */ + UINT32 data, /* Integer data corresponding to the event.*/ + BT_HDR *p_buf ); /* Pointer data corresponding to the event. */ + + +/***************************************************************************** +** External Function Declarations +*****************************************************************************/ +#ifdef __cplusplus +extern "C" +{ +#endif + +/******************************************************************************* +** +** Function HID_HostGetSDPRecord +** +** Description This function reads the device SDP record. +** +** Returns tHID_STATUS +** +*******************************************************************************/ +extern tHID_STATUS HID_HostGetSDPRecord (BD_ADDR addr, + tSDP_DISCOVERY_DB *p_db, + UINT32 db_len, + tHID_HOST_SDP_CALLBACK *sdp_cback ); + +/******************************************************************************* +** +** Function HID_HostRegister +** +** Description This function registers HID-Host with lower layers. +** +** Returns tHID_STATUS +** +*******************************************************************************/ +extern tHID_STATUS HID_HostRegister (tHID_HOST_DEV_CALLBACK *dev_cback); + +/******************************************************************************* +** +** Function HID_HostDeregister +** +** Description This function is called when the host is about power down. +** +** Returns tHID_STATUS +** +*******************************************************************************/ +extern tHID_STATUS HID_HostDeregister(void); + +/******************************************************************************* +** +** Function HID_HostAddDev +** +** Description This is called so HID-host may manage this device. +** +** Returns tHID_STATUS +** +*******************************************************************************/ +extern tHID_STATUS HID_HostAddDev (BD_ADDR addr, UINT16 attr_mask, + UINT8 *handle ); + +/******************************************************************************* +** +** Function HID_HostRemoveDev +** +** Description This removes the device from list devices that host has to manage. +** +** Returns tHID_STATUS +** +*******************************************************************************/ +extern tHID_STATUS HID_HostRemoveDev (UINT8 dev_handle ); + +/******************************************************************************* +** +** Function HID_HostOpenDev +** +** Description This function is called when the user wants to initiate a +** connection attempt to a device. +** +** Returns void +** +*******************************************************************************/ +extern tHID_STATUS HID_HostOpenDev (UINT8 dev_handle ); + +/******************************************************************************* +** +** Function HID_HostWriteDev +** +** Description This function is called when the host has a report to send. +** +** Returns void +** +*******************************************************************************/ +extern tHID_STATUS HID_HostWriteDev(UINT8 dev_handle, UINT8 t_type, + UINT8 param, UINT16 data, + UINT8 report_id, BT_HDR *pbuf); + +/******************************************************************************* +** +** Function HID_HostCloseDev +** +** Description This function disconnects the device. +** +** Returns void +** +*******************************************************************************/ +extern tHID_STATUS HID_HostCloseDev(UINT8 dev_handle ); + +/******************************************************************************* +** Function HID_HostInit +** +** Description This function initializes the control block and trace variable +** +** Returns void +*******************************************************************************/ +extern void HID_HostInit(void); + +/******************************************************************************* +** Function HID_HostSetSecurityLevel +** +** Description This function sets the security level for the devices which +** are marked by application as requiring security +** +** Returns tHID_STATUS +*******************************************************************************/ +extern tHID_STATUS HID_HostSetSecurityLevel( char serv_name[], UINT8 sec_lvl ); + +/******************************************************************************* +** +** Function hid_known_hid_device +** +** Description This function checks if this device is of type HID Device +** +** Returns TRUE if device exists else FALSE +** +*******************************************************************************/ +BOOLEAN hid_known_hid_device (BD_ADDR bd_addr); + + +/******************************************************************************* +** +** Function HID_HostSetTraceLevel +** +** Description This function sets the trace level for HID Host. If called with +** a value of 0xFF, it simply reads the current trace level. +** +** Returns the new (current) trace level +** +*******************************************************************************/ +extern UINT8 HID_HostSetTraceLevel (UINT8 new_level); + +#ifdef __cplusplus +} +#endif + +#endif /* HIDH_API_H */ diff --git a/tools/sdk/include/bluedroid/interop.h b/tools/sdk/include/bluedroid/interop.h new file mode 100644 index 00000000..74394d95 --- /dev/null +++ b/tools/sdk/include/bluedroid/interop.h @@ -0,0 +1,44 @@ +/****************************************************************************** + * + * Copyright (C) 2015 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 _INTEROP_H_ +#define _INTEROP_H_ + +#include +#include "bt_defs.h" + +typedef enum { + // Disable secure connections + // This is for pre BT 4.1/2 devices that do not handle secure mode + // very well. + INTEROP_DISABLE_LE_SECURE_CONNECTIONS, + + // Some devices have proven problematic during the pairing process, often + // requiring multiple retries to complete pairing. To avoid degrading the user + // experience for those devices, automatically re-try pairing if page + // timeouts are received during pairing. + INTEROP_AUTO_RETRY_PAIRING +} interop_feature_t; + +// Check if a given |addr| matches a known interoperability workaround as identified +// by the |interop_feature_t| enum. This API is used for simple address based lookups +// where more information is not available. No look-ups or random address resolution +// is performed on |addr|. +bool interop_match(const interop_feature_t feature, const bt_bdaddr_t *addr); + +#endif /*_INTEROP_H_*/ diff --git a/tools/sdk/include/bluedroid/interop_database.h b/tools/sdk/include/bluedroid/interop_database.h new file mode 100644 index 00000000..5b9bc934 --- /dev/null +++ b/tools/sdk/include/bluedroid/interop_database.h @@ -0,0 +1,50 @@ +/****************************************************************************** + * + * Copyright (C) 2015 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 _INTEROP_DATABASE_H_ +#define _INTEROP_DATABASE_H_ + +#include "interop.h" + +typedef struct { + bt_bdaddr_t addr; + uint8_t len; + interop_feature_t feature; +} interop_entry_t; + +static const interop_entry_t interop_database[] = { + // Nexus Remote (Spike) + // Note: May affect other Asus brand devices + {{{0x08, 0x62, 0x66, 0, 0, 0}}, 3, INTEROP_DISABLE_LE_SECURE_CONNECTIONS}, + {{{0x38, 0x2c, 0x4a, 0xc9, 0, 0}}, 4, INTEROP_DISABLE_LE_SECURE_CONNECTIONS}, + {{{0x38, 0x2c, 0x4a, 0xe6, 0, 0}}, 4, INTEROP_DISABLE_LE_SECURE_CONNECTIONS}, + {{{0x54, 0xa0, 0x50, 0xd9, 0, 0}}, 4, INTEROP_DISABLE_LE_SECURE_CONNECTIONS}, + {{{0xac, 0x9e, 0x17, 0, 0, 0}}, 3, INTEROP_DISABLE_LE_SECURE_CONNECTIONS}, + {{{0xf0, 0x79, 0x59, 0, 0, 0}}, 3, INTEROP_DISABLE_LE_SECURE_CONNECTIONS}, + + // Motorola Key Link + {{{0x1c, 0x96, 0x5a, 0, 0, 0}}, 3, INTEROP_DISABLE_LE_SECURE_CONNECTIONS}, + + // Flic smart button + {{{0x80, 0xe4, 0xda, 0x70, 0, 0}}, 4, INTEROP_DISABLE_LE_SECURE_CONNECTIONS}, + + // BMW car kits (Harman/Becker) + {{{0x9c, 0xdf, 0x03, 0, 0, 0}}, 3, INTEROP_AUTO_RETRY_PAIRING} +}; + +#endif /*_INTEROP_DATABASE_H_*/ diff --git a/tools/sdk/include/bluedroid/l2c_api.h b/tools/sdk/include/bluedroid/l2c_api.h new file mode 100644 index 00000000..d79c17a1 --- /dev/null +++ b/tools/sdk/include/bluedroid/l2c_api.h @@ -0,0 +1,1137 @@ +/****************************************************************************** + * + * Copyright (C) 1999-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 file contains the L2CAP API definitions + * + ******************************************************************************/ +#ifndef L2C_API_H +#define L2C_API_H + +#include + +#include "bt_target.h" +#include "l2cdefs.h" +#include "hcidefs.h" + +/***************************************************************************** +** Constants +*****************************************************************************/ + +/* Define the minimum offset that L2CAP needs in a buffer. This is made up of +** HCI type(1), len(2), handle(2), L2CAP len(2) and CID(2) => 9 +*/ +#define L2CAP_MIN_OFFSET 13 /* plus control(2), SDU length(2) */ + +/* Minimum offset for broadcast needs another two bytes for the PSM */ +#define L2CAP_BCST_MIN_OFFSET 11 + +/* ping result codes */ +#define L2CAP_PING_RESULT_OK 0 /* Ping reply received OK */ +#define L2CAP_PING_RESULT_NO_LINK 1 /* Link could not be setup */ +#define L2CAP_PING_RESULT_NO_RESP 2 /* Remote L2CAP did not reply */ + +/* result code for L2CA_DataWrite() */ +#define L2CAP_DW_FAILED FALSE +#define L2CAP_DW_SUCCESS TRUE +#define L2CAP_DW_CONGESTED 2 + +/* Values for priority parameter to L2CA_SetAclPriority */ +#define L2CAP_PRIORITY_NORMAL 0 +#define L2CAP_PRIORITY_HIGH 1 + +/* Values for priority parameter to L2CA_SetTxPriority */ +#define L2CAP_CHNL_PRIORITY_HIGH 0 +#define L2CAP_CHNL_PRIORITY_MEDIUM 1 +#define L2CAP_CHNL_PRIORITY_LOW 2 + +typedef UINT8 tL2CAP_CHNL_PRIORITY; + +/* Values for Tx/Rx data rate parameter to L2CA_SetChnlDataRate */ +#define L2CAP_CHNL_DATA_RATE_HIGH 3 +#define L2CAP_CHNL_DATA_RATE_MEDIUM 2 +#define L2CAP_CHNL_DATA_RATE_LOW 1 +#define L2CAP_CHNL_DATA_RATE_NO_TRAFFIC 0 + +typedef UINT8 tL2CAP_CHNL_DATA_RATE; + +/* Data Packet Flags (bits 2-15 are reserved) */ +/* layer specific 14-15 bits are used for FCR SAR */ +#define L2CAP_FLUSHABLE_MASK 0x0003 +#define L2CAP_FLUSHABLE_CH_BASED 0x0000 +#define L2CAP_FLUSHABLE_PKT 0x0001 +#define L2CAP_NON_FLUSHABLE_PKT 0x0002 + + +/* L2CA_FlushChannel num_to_flush definitions */ +#define L2CAP_FLUSH_CHANS_ALL 0xffff +#define L2CAP_FLUSH_CHANS_GET 0x0000 + + +/* special CID for Multi-AV for reporting congestion */ +#define L2CAP_MULTI_AV_CID 0 + +/* length of the HCI header block */ +/* HCI header(4) + SNK count(1) + FCR bits(1) + AV data length(2) */ +#define L2CAP_MULTI_AV_HCI_HDR_LEN 8 + +/* length of padding for 4 bytes align */ +#define L2CAP_MULTI_AV_PADDING_LEN 2 + +/* length of the HCI header block with padding for FCR */ +/* HCI header(4) + SNK count(1) + FCR bits(1) + AV data length(2) + padding(2) */ +#define L2CAP_MULTI_AV_HCI_HDR_LEN_WITH_PADDING 10 + +/* length of the L2CAP header block */ +/* HCI header(4) + L2CAP header(4) + padding(4) or control word(2) + FCS(2) */ +#define L2CAP_MULTI_AV_L2C_HDR_LEN 12 + +/* definition used for L2CA_SetDesireRole */ +#define L2CAP_ROLE_SLAVE HCI_ROLE_SLAVE +#define L2CAP_ROLE_MASTER HCI_ROLE_MASTER +#define L2CAP_ROLE_ALLOW_SWITCH 0x80 /* set this bit to allow switch at create conn */ +#define L2CAP_ROLE_DISALLOW_SWITCH 0x40 /* set this bit to disallow switch at create conn */ +#define L2CAP_ROLE_CHECK_SWITCH 0xC0 + + +/* Values for 'allowed_modes' field passed in structure tL2CAP_ERTM_INFO +*/ +#define L2CAP_FCR_CHAN_OPT_BASIC (1 << L2CAP_FCR_BASIC_MODE) +#define L2CAP_FCR_CHAN_OPT_ERTM (1 << L2CAP_FCR_ERTM_MODE) +#define L2CAP_FCR_CHAN_OPT_STREAM (1 << L2CAP_FCR_STREAM_MODE) + +#define L2CAP_FCR_CHAN_OPT_ALL_MASK (L2CAP_FCR_CHAN_OPT_BASIC | L2CAP_FCR_CHAN_OPT_ERTM | L2CAP_FCR_CHAN_OPT_STREAM) + +/* Validity check for PSM. PSM values must be odd. Also, all PSM values must +** be assigned such that the least significant bit of the most sigificant +** octet equals zero. +*/ +#define L2C_INVALID_PSM(psm) (((psm) & 0x0101) != 0x0001) +#define L2C_IS_VALID_PSM(psm) (((psm) & 0x0101) == 0x0001) + +/***************************************************************************** +** Type Definitions +*****************************************************************************/ + +typedef struct { +#define L2CAP_FCR_BASIC_MODE 0x00 +#define L2CAP_FCR_ERTM_MODE 0x03 +#define L2CAP_FCR_STREAM_MODE 0x04 + + UINT8 mode; + + UINT8 tx_win_sz; + UINT8 max_transmit; + UINT16 rtrans_tout; + UINT16 mon_tout; + UINT16 mps; +} tL2CAP_FCR_OPTS; + +/* Define a structure to hold the configuration parameters. Since the +** parameters are optional, for each parameter there is a boolean to +** use to signify its presence or absence. +*/ +typedef struct { + UINT16 result; /* Only used in confirm messages */ + BOOLEAN mtu_present; + UINT16 mtu; + BOOLEAN qos_present; + FLOW_SPEC qos; + BOOLEAN flush_to_present; + UINT16 flush_to; + BOOLEAN fcr_present; + tL2CAP_FCR_OPTS fcr; + BOOLEAN fcs_present; /* Optionally bypasses FCS checks */ + UINT8 fcs; /* '0' if desire is to bypass FCS, otherwise '1' */ + BOOLEAN ext_flow_spec_present; + tHCI_EXT_FLOW_SPEC ext_flow_spec; + UINT16 flags; /* bit 0: 0-no continuation, 1-continuation */ +} tL2CAP_CFG_INFO; + +/* L2CAP channel configured field bitmap */ +#define L2CAP_CH_CFG_MASK_MTU 0x0001 +#define L2CAP_CH_CFG_MASK_QOS 0x0002 +#define L2CAP_CH_CFG_MASK_FLUSH_TO 0x0004 +#define L2CAP_CH_CFG_MASK_FCR 0x0008 +#define L2CAP_CH_CFG_MASK_FCS 0x0010 +#define L2CAP_CH_CFG_MASK_EXT_FLOW_SPEC 0x0020 + +typedef UINT16 tL2CAP_CH_CFG_BITS; + +/********************************* +** Callback Functions Prototypes +**********************************/ + +/* Connection indication callback prototype. Parameters are +** BD Address of remote +** Local CID assigned to the connection +** PSM that the remote wants to connect to +** Identifier that the remote sent +*/ +typedef void (tL2CA_CONNECT_IND_CB) (BD_ADDR, UINT16, UINT16, UINT8); + + +/* Connection confirmation callback prototype. Parameters are +** Local CID +** Result - 0 = connected, non-zero means failure reason +*/ +typedef void (tL2CA_CONNECT_CFM_CB) (UINT16, UINT16); + + +/* Connection pending callback prototype. Parameters are +** Local CID +*/ +typedef void (tL2CA_CONNECT_PND_CB) (UINT16); + + +/* Configuration indication callback prototype. Parameters are +** Local CID assigned to the connection +** Pointer to configuration info +*/ +typedef void (tL2CA_CONFIG_IND_CB) (UINT16, tL2CAP_CFG_INFO *); + + +/* Configuration confirm callback prototype. Parameters are +** Local CID assigned to the connection +** Pointer to configuration info +*/ +typedef void (tL2CA_CONFIG_CFM_CB) (UINT16, tL2CAP_CFG_INFO *); + + +/* Disconnect indication callback prototype. Parameters are +** Local CID +** Boolean whether upper layer should ack this +*/ +typedef void (tL2CA_DISCONNECT_IND_CB) (UINT16, BOOLEAN); + + +/* Disconnect confirm callback prototype. Parameters are +** Local CID +** Result +*/ +typedef void (tL2CA_DISCONNECT_CFM_CB) (UINT16, UINT16); + + +/* QOS Violation indication callback prototype. Parameters are +** BD Address of violating device +*/ +typedef void (tL2CA_QOS_VIOLATION_IND_CB) (BD_ADDR); + + +/* Data received indication callback prototype. Parameters are +** Local CID +** Address of buffer +*/ +typedef void (tL2CA_DATA_IND_CB) (UINT16, BT_HDR *); + + +/* Echo response callback prototype. Note that this is not included in the +** registration information, but is passed to L2CAP as part of the API to +** actually send an echo request. Parameters are +** Result +*/ +typedef void (tL2CA_ECHO_RSP_CB) (UINT16); + + +/* Callback function prototype to pass broadcom specific echo response */ +/* to the upper layer */ +typedef void (tL2CA_ECHO_DATA_CB) (BD_ADDR, UINT16, UINT8 *); + + +/* Congestion status callback protype. This callback is optional. If +** an application tries to send data when the transmit queue is full, +** the data will anyways be dropped. The parameter is: +** Local CID +** TRUE if congested, FALSE if uncongested +*/ +typedef void (tL2CA_CONGESTION_STATUS_CB) (UINT16, BOOLEAN); + +/* Callback prototype for number of packets completed events. +** This callback notifies the application when Number of Completed Packets +** event has been received. +** This callback is originally designed for 3DG devices. +** The parameter is: +** peer BD_ADDR +*/ +typedef void (tL2CA_NOCP_CB) (BD_ADDR); + +/* Transmit complete callback protype. This callback is optional. If +** set, L2CAP will call it when packets are sent or flushed. If the +** count is 0xFFFF, it means all packets are sent for that CID (eRTM +** mode only). The parameters are: +** Local CID +** Number of SDUs sent or dropped +*/ +typedef void (tL2CA_TX_COMPLETE_CB) (UINT16, UINT16); + +/* Define the structure that applications use to register with +** L2CAP. This structure includes callback functions. All functions +** MUST be provided, with the exception of the "connect pending" +** callback and "congestion status" callback. +*/ +typedef struct { + tL2CA_CONNECT_IND_CB *pL2CA_ConnectInd_Cb; + tL2CA_CONNECT_CFM_CB *pL2CA_ConnectCfm_Cb; + tL2CA_CONNECT_PND_CB *pL2CA_ConnectPnd_Cb; + tL2CA_CONFIG_IND_CB *pL2CA_ConfigInd_Cb; + tL2CA_CONFIG_CFM_CB *pL2CA_ConfigCfm_Cb; + tL2CA_DISCONNECT_IND_CB *pL2CA_DisconnectInd_Cb; + tL2CA_DISCONNECT_CFM_CB *pL2CA_DisconnectCfm_Cb; + tL2CA_QOS_VIOLATION_IND_CB *pL2CA_QoSViolationInd_Cb; + tL2CA_DATA_IND_CB *pL2CA_DataInd_Cb; + tL2CA_CONGESTION_STATUS_CB *pL2CA_CongestionStatus_Cb; + tL2CA_TX_COMPLETE_CB *pL2CA_TxComplete_Cb; + +} tL2CAP_APPL_INFO; + +/* Define the structure that applications use to create or accept +** connections with enhanced retransmission mode. +*/ +typedef struct { + UINT8 preferred_mode; + UINT8 allowed_modes; + UINT8 user_rx_pool_id; + UINT8 user_tx_pool_id; + UINT8 fcr_rx_pool_id; + UINT8 fcr_tx_pool_id; + +} tL2CAP_ERTM_INFO; + +#define L2CA_REGISTER(a,b,c) L2CA_Register(a,(tL2CAP_APPL_INFO *)b) +#define L2CA_DEREGISTER(a) L2CA_Deregister(a) +#define L2CA_CONNECT_REQ(a,b,c,d) L2CA_ErtmConnectReq(a,b,c) +#define L2CA_CONNECT_RSP(a,b,c,d,e,f,g) L2CA_ErtmConnectRsp(a,b,c,d,e,f) +#define L2CA_CONFIG_REQ(a,b) L2CA_ConfigReq(a,b) +#define L2CA_CONFIG_RSP(a,b) L2CA_ConfigRsp(a,b) +#define L2CA_DISCONNECT_REQ(a) L2CA_DisconnectReq(a) +#define L2CA_DISCONNECT_RSP(a) L2CA_DisconnectRsp(a) +#define L2CA_DATA_WRITE(a, b) L2CA_DataWrite(a, b) + +/***************************************************************************** +** External Function Declarations +*****************************************************************************/ +#ifdef __cplusplus +extern "C" +{ +#endif + +/******************************************************************************* +** +** Function L2CA_Register +** +** Description Other layers call this function to register for L2CAP +** services. +** +** Returns PSM to use or zero if error. Typically, the PSM returned +** is the same as was passed in, but for an outgoing-only +** connection to a dynamic PSM, a "virtual" PSM is returned +** and should be used in the calls to L2CA_ConnectReq() and +** BTM_SetSecurityLevel(). +** +*******************************************************************************/ +extern UINT16 L2CA_Register (UINT16 psm, tL2CAP_APPL_INFO *p_cb_info); + +/******************************************************************************* +** +** Function L2CA_Deregister +** +** Description Other layers call this function to deregister for L2CAP +** services. +** +** Returns void +** +*******************************************************************************/ +extern void L2CA_Deregister (UINT16 psm); + +/******************************************************************************* +** +** Function L2CA_AllocatePSM +** +** Description Other layers call this function to find an unused PSM for L2CAP +** services. +** +** Returns PSM to use. +** +*******************************************************************************/ +extern UINT16 L2CA_AllocatePSM(void); + +/******************************************************************************* +** +** Function L2CA_ConnectReq +** +** Description Higher layers call this function to create an L2CAP connection. +** Note that the connection is not established at this time, but +** connection establishment gets started. The callback function +** will be invoked when connection establishes or fails. +** +** Returns the CID of the connection, or 0 if it failed to start +** +*******************************************************************************/ +extern UINT16 L2CA_ConnectReq (UINT16 psm, BD_ADDR p_bd_addr); + +/******************************************************************************* +** +** Function L2CA_ConnectRsp +** +** Description Higher layers call this function to accept an incoming +** L2CAP connection, for which they had gotten an connect +** indication callback. +** +** Returns TRUE for success, FALSE for failure +** +*******************************************************************************/ +extern BOOLEAN L2CA_ConnectRsp (BD_ADDR p_bd_addr, UINT8 id, UINT16 lcid, + UINT16 result, UINT16 status); + +/******************************************************************************* +** +** Function L2CA_ErtmConnectReq +** +** Description Higher layers call this function to create an L2CAP connection +** that needs to use Enhanced Retransmission Mode. +** Note that the connection is not established at this time, but +** connection establishment gets started. The callback function +** will be invoked when connection establishes or fails. +** +** Returns the CID of the connection, or 0 if it failed to start +** +*******************************************************************************/ +extern UINT16 L2CA_ErtmConnectReq (UINT16 psm, BD_ADDR p_bd_addr, + tL2CAP_ERTM_INFO *p_ertm_info); + +// This function sets the callback routines for the L2CAP connection referred to by +// |local_cid|. The callback routines can only be modified for outgoing connections +// established by |L2CA_ConnectReq| or accepted incoming connections. |callbacks| +// must not be NULL. This function returns true if the callbacks could be updated, +// false if not (e.g. |local_cid| was not found). +bool L2CA_SetConnectionCallbacks(uint16_t local_cid, const tL2CAP_APPL_INFO *callbacks); + +/******************************************************************************* +** +** Function L2CA_ErtmConnectRsp +** +** Description Higher layers call this function to accept an incoming +** L2CAP connection, for which they had gotten an connect +** indication callback, and for which the higher layer wants +** to use Enhanced Retransmission Mode. +** +** Returns TRUE for success, FALSE for failure +** +*******************************************************************************/ +extern BOOLEAN L2CA_ErtmConnectRsp (BD_ADDR p_bd_addr, UINT8 id, UINT16 lcid, + UINT16 result, UINT16 status, + tL2CAP_ERTM_INFO *p_ertm_info); + +/******************************************************************************* +** +** Function L2CA_ConfigReq +** +** Description Higher layers call this function to send configuration. +** +** Returns TRUE if configuration sent, else FALSE +** +*******************************************************************************/ +extern BOOLEAN L2CA_ConfigReq (UINT16 cid, tL2CAP_CFG_INFO *p_cfg); + +/******************************************************************************* +** +** Function L2CA_ConfigRsp +** +** Description Higher layers call this function to send a configuration +** response. +** +** Returns TRUE if configuration response sent, else FALSE +** +*******************************************************************************/ +extern BOOLEAN L2CA_ConfigRsp (UINT16 cid, tL2CAP_CFG_INFO *p_cfg); + +/******************************************************************************* +** +** Function L2CA_DisconnectReq +** +** Description Higher layers call this function to disconnect a channel. +** +** Returns TRUE if disconnect sent, else FALSE +** +*******************************************************************************/ +extern BOOLEAN L2CA_DisconnectReq (UINT16 cid); + +/******************************************************************************* +** +** Function L2CA_DisconnectRsp +** +** Description Higher layers call this function to acknowledge the +** disconnection of a channel. +** +** Returns void +** +*******************************************************************************/ +extern BOOLEAN L2CA_DisconnectRsp (UINT16 cid); + +/******************************************************************************* +** +** Function L2CA_DataWrite +** +** Description Higher layers call this function to write data. +** +** Returns L2CAP_DW_SUCCESS, if data accepted, else FALSE +** L2CAP_DW_CONGESTED, if data accepted and the channel is congested +** L2CAP_DW_FAILED, if error +** +*******************************************************************************/ +extern UINT8 L2CA_DataWrite (UINT16 cid, BT_HDR *p_data); + +/******************************************************************************* +** +** Function L2CA_Ping +** +** Description Higher layers call this function to send an echo request. +** +** Returns TRUE if echo request sent, else FALSE. +** +*******************************************************************************/ +extern BOOLEAN L2CA_Ping (BD_ADDR p_bd_addr, tL2CA_ECHO_RSP_CB *p_cb); + +/******************************************************************************* +** +** Function L2CA_Echo +** +** Description Higher layers call this function to send an echo request +** with application-specific data. +** +** Returns TRUE if echo request sent, else FALSE. +** +*******************************************************************************/ +extern BOOLEAN L2CA_Echo (BD_ADDR p_bd_addr, BT_HDR *p_data, tL2CA_ECHO_DATA_CB *p_callback); + +// Given a local channel identifier, |lcid|, this function returns the bound remote +// channel identifier, |rcid|, and the ACL link handle, |handle|. If |lcid| is not +// known or is invalid, this function returns false and does not modify the values +// pointed at by |rcid| and |handle|. |rcid| and |handle| may be NULL. +bool L2CA_GetIdentifiers(uint16_t lcid, uint16_t *rcid, uint16_t *handle); + +/******************************************************************************* +** +** Function L2CA_SetIdleTimeout +** +** Description Higher layers call this function to set the idle timeout for +** a connection, or for all future connections. The "idle timeout" +** is the amount of time that a connection can remain up with +** no L2CAP channels on it. A timeout of zero means that the +** connection will be torn down immediately when the last channel +** is removed. A timeout of 0xFFFF means no timeout. Values are +** in seconds. +** +** Returns TRUE if command succeeded, FALSE if failed +** +*******************************************************************************/ +extern BOOLEAN L2CA_SetIdleTimeout (UINT16 cid, UINT16 timeout, + BOOLEAN is_global); + +/******************************************************************************* +** +** Function L2CA_SetIdleTimeoutByBdAddr +** +** Description Higher layers call this function to set the idle timeout for +** a connection. The "idle timeout" is the amount of time that +** a connection can remain up with no L2CAP channels on it. +** A timeout of zero means that the connection will be torn +** down immediately when the last channel is removed. +** A timeout of 0xFFFF means no timeout. Values are in seconds. +** A bd_addr is the remote BD address. If bd_addr = BT_BD_ANY, +** then the idle timeouts for all active l2cap links will be +** changed. +** +** Returns TRUE if command succeeded, FALSE if failed +** +** NOTE This timeout applies to all logical channels active on the +** ACL link. +*******************************************************************************/ +extern BOOLEAN L2CA_SetIdleTimeoutByBdAddr(BD_ADDR bd_addr, UINT16 timeout, + tBT_TRANSPORT transport); + +/******************************************************************************* +** +** Function L2CA_SetTraceLevel +** +** Description This function sets the trace level for L2CAP. If called with +** a value of 0xFF, it simply reads the current trace level. +** +** Returns the new (current) trace level +** +*******************************************************************************/ +extern UINT8 L2CA_SetTraceLevel (UINT8 trace_level); + +/******************************************************************************* +** +** Function L2CA_SetDesireRole +** +** Description This function sets the desire role for L2CAP. +** If the new role is L2CAP_ROLE_ALLOW_SWITCH, allow switch on +** HciCreateConnection. +** If the new role is L2CAP_ROLE_DISALLOW_SWITCH, do not allow switch on +** HciCreateConnection. +** +** If the new role is a valid role (HCI_ROLE_MASTER or HCI_ROLE_SLAVE), +** the desire role is set to the new value. Otherwise, it is not changed. +** +** Returns the new (current) role +** +*******************************************************************************/ +extern UINT8 L2CA_SetDesireRole (UINT8 new_role); + +/******************************************************************************* +** +** Function L2CA_LocalLoopbackReq +** +** Description This function sets up a CID for local loopback +** +** Returns CID of 0 if none. +** +*******************************************************************************/ +extern UINT16 L2CA_LocalLoopbackReq (UINT16 psm, UINT16 handle, BD_ADDR p_bd_addr); + +/******************************************************************************* +** +** Function L2CA_FlushChannel +** +** Description This function flushes none, some or all buffers queued up +** for xmission for a particular CID. If called with +** L2CAP_FLUSH_CHANS_GET (0), it simply returns the number +** of buffers queued for that CID L2CAP_FLUSH_CHANS_ALL (0xffff) +** flushes all buffers. All other values specifies the maximum +** buffers to flush. +** +** Returns Number of buffers left queued for that CID +** +*******************************************************************************/ +extern UINT16 L2CA_FlushChannel (UINT16 lcid, UINT16 num_to_flush); + + +/******************************************************************************* +** +** Function L2CA_SetAclPriority +** +** Description Sets the transmission priority for an ACL channel. +** (For initial implementation only two values are valid. +** L2CAP_PRIORITY_NORMAL and L2CAP_PRIORITY_HIGH). +** +** Returns TRUE if a valid channel, else FALSE +** +*******************************************************************************/ +extern BOOLEAN L2CA_SetAclPriority (BD_ADDR bd_addr, UINT8 priority); + +/******************************************************************************* +** +** Function L2CA_FlowControl +** +** Description Higher layers call this function to flow control a channel. +** +** data_enabled - TRUE data flows, FALSE data is stopped +** +** Returns TRUE if valid channel, else FALSE +** +*******************************************************************************/ +extern BOOLEAN L2CA_FlowControl (UINT16 cid, BOOLEAN data_enabled); + +/******************************************************************************* +** +** Function L2CA_SendTestSFrame +** +** Description Higher layers call this function to send a test S-frame. +** +** Returns TRUE if valid Channel, else FALSE +** +*******************************************************************************/ +extern BOOLEAN L2CA_SendTestSFrame (UINT16 cid, UINT8 sup_type, + UINT8 back_track); + +/******************************************************************************* +** +** Function L2CA_SetTxPriority +** +** Description Sets the transmission priority for a channel. (FCR Mode) +** +** Returns TRUE if a valid channel, else FALSE +** +*******************************************************************************/ +extern BOOLEAN L2CA_SetTxPriority (UINT16 cid, tL2CAP_CHNL_PRIORITY priority); + +/******************************************************************************* +** +** Function L2CA_RegForNoCPEvt +** +** Description Register callback for Number of Completed Packets event. +** +** Input Param p_cb - callback for Number of completed packets event +** p_bda - BT address of remote device +** +** Returns +** +*******************************************************************************/ +extern BOOLEAN L2CA_RegForNoCPEvt(tL2CA_NOCP_CB *p_cb, BD_ADDR p_bda); + +/******************************************************************************* +** +** Function L2CA_SetChnlDataRate +** +** Description Sets the tx/rx data rate for a channel. +** +** Returns TRUE if a valid channel, else FALSE +** +*******************************************************************************/ +extern BOOLEAN L2CA_SetChnlDataRate (UINT16 cid, tL2CAP_CHNL_DATA_RATE tx, tL2CAP_CHNL_DATA_RATE rx); + +typedef void (tL2CA_RESERVE_CMPL_CBACK) (void); + +/******************************************************************************* +** +** Function L2CA_SetFlushTimeout +** +** Description This function set the automatic flush time out in Baseband +** for ACL-U packets. +** BdAddr : the remote BD address of ACL link. If it is BT_DB_ANY +** then the flush time out will be applied to all ACL link. +** FlushTimeout: flush time out in ms +** 0x0000 : No automatic flush +** L2CAP_NO_RETRANSMISSION : No retransmission +** 0x0002 - 0xFFFE : flush time out, if (flush_tout*8)+3/5) +** <= HCI_MAX_AUTO_FLUSH_TOUT (in 625us slot). +** Otherwise, return FALSE. +** L2CAP_NO_AUTOMATIC_FLUSH : No automatic flush +** +** Returns TRUE if command succeeded, FALSE if failed +** +** NOTE This flush timeout applies to all logical channels active on the +** ACL link. +*******************************************************************************/ +extern BOOLEAN L2CA_SetFlushTimeout (BD_ADDR bd_addr, UINT16 flush_tout); + +/******************************************************************************* +** +** Function L2CA_DataWriteEx +** +** Description Higher layers call this function to write data with extended +** flags. +** flags : L2CAP_FLUSHABLE_CH_BASED +** L2CAP_FLUSHABLE_PKT +** L2CAP_NON_FLUSHABLE_PKT +** +** Returns L2CAP_DW_SUCCESS, if data accepted, else FALSE +** L2CAP_DW_CONGESTED, if data accepted and the channel is congested +** L2CAP_DW_FAILED, if error +** +*******************************************************************************/ +extern UINT8 L2CA_DataWriteEx (UINT16 cid, BT_HDR *p_data, UINT16 flags); + +/******************************************************************************* +** +** Function L2CA_SetChnlFlushability +** +** Description Higher layers call this function to set a channels +** flushability flags +** +** Returns TRUE if CID found, else FALSE +** +*******************************************************************************/ +extern BOOLEAN L2CA_SetChnlFlushability (UINT16 cid, BOOLEAN is_flushable); + +/******************************************************************************* +** +** Function L2CA_GetPeerFeatures +** +** Description Get a peers features and fixed channel map +** +** Parameters: BD address of the peer +** Pointers to features and channel mask storage area +** +** Return value: TRUE if peer is connected +** +*******************************************************************************/ +extern BOOLEAN L2CA_GetPeerFeatures (BD_ADDR bd_addr, UINT32 *p_ext_feat, UINT8 *p_chnl_mask); + +/******************************************************************************* +** +** Function L2CA_GetBDAddrbyHandle +** +** Description Get BD address for the given HCI handle +** +** Parameters: HCI handle +** BD address of the peer +** +** Return value: TRUE if found lcb for the given handle, FALSE otherwise +** +*******************************************************************************/ +extern BOOLEAN L2CA_GetBDAddrbyHandle (UINT16 handle, BD_ADDR bd_addr); + +/******************************************************************************* +** +** Function L2CA_GetChnlFcrMode +** +** Description Get the channel FCR mode +** +** Parameters: Local CID +** +** Return value: Channel mode +** +*******************************************************************************/ +extern UINT8 L2CA_GetChnlFcrMode (UINT16 lcid); + + +/******************************************************************************* +** +** UCD callback prototypes +** +*******************************************************************************/ + +/* UCD discovery. Parameters are +** BD Address of remote +** Data Type +** Data +*/ +#define L2CAP_UCD_INFO_TYPE_RECEPTION 0x01 +#define L2CAP_UCD_INFO_TYPE_MTU 0x02 + +typedef void (tL2CA_UCD_DISCOVER_CB) (BD_ADDR, UINT8, UINT32); + +/* UCD data received. Parameters are +** BD Address of remote +** Pointer to buffer with data +*/ +typedef void (tL2CA_UCD_DATA_CB) (BD_ADDR, BT_HDR *); + +/* Congestion status callback protype. This callback is optional. If +** an application tries to send data when the transmit queue is full, +** the data will anyways be dropped. The parameter is: +** remote BD_ADDR +** TRUE if congested, FALSE if uncongested +*/ +typedef void (tL2CA_UCD_CONGESTION_STATUS_CB) (BD_ADDR, BOOLEAN); + +/* UCD registration info (the callback addresses and PSM) +*/ +typedef struct { + tL2CA_UCD_DISCOVER_CB *pL2CA_UCD_Discover_Cb; + tL2CA_UCD_DATA_CB *pL2CA_UCD_Data_Cb; + tL2CA_UCD_CONGESTION_STATUS_CB *pL2CA_UCD_Congestion_Status_Cb; +} tL2CAP_UCD_CB_INFO; + +/******************************************************************************* +** +** Function L2CA_UcdRegister +** +** Description Register PSM on UCD. +** +** Parameters: tL2CAP_UCD_CB_INFO +** +** Return value: TRUE if successs +** +*******************************************************************************/ +extern BOOLEAN L2CA_UcdRegister ( UINT16 psm, tL2CAP_UCD_CB_INFO *p_cb_info ); + +/******************************************************************************* +** +** Function L2CA_UcdDeregister +** +** Description Deregister PSM on UCD. +** +** Parameters: PSM +** +** Return value: TRUE if successs +** +*******************************************************************************/ +extern BOOLEAN L2CA_UcdDeregister ( UINT16 psm ); + +/******************************************************************************* +** +** Function L2CA_UcdDiscover +** +** Description Discover UCD of remote device. +** +** Parameters: PSM +** BD_ADDR of remote device +** info_type : L2CAP_UCD_INFO_TYPE_RECEPTION +** L2CAP_UCD_INFO_TYPE_MTU +** +** +** Return value: TRUE if successs +** +*******************************************************************************/ +extern BOOLEAN L2CA_UcdDiscover ( UINT16 psm, BD_ADDR rem_bda, UINT8 info_type ); + +/******************************************************************************* +** +** Function L2CA_UcdDataWrite +** +** Description Send UCD to remote device +** +** Parameters: PSM +** BD Address of remote +** Pointer to buffer of type BT_HDR +** flags : L2CAP_FLUSHABLE_CH_BASED +** L2CAP_FLUSHABLE_PKT +** L2CAP_NON_FLUSHABLE_PKT +** +** Return value L2CAP_DW_SUCCESS, if data accepted +** L2CAP_DW_FAILED, if error +** +*******************************************************************************/ +extern UINT16 L2CA_UcdDataWrite (UINT16 psm, BD_ADDR rem_bda, BT_HDR *p_buf, UINT16 flags); + +/******************************************************************************* +** +** Function L2CA_UcdSetIdleTimeout +** +** Description Set UCD Idle timeout. +** +** Parameters: BD Addr +** Timeout in second +** +** Return value: TRUE if successs +** +*******************************************************************************/ +extern BOOLEAN L2CA_UcdSetIdleTimeout ( BD_ADDR rem_bda, UINT16 timeout ); + +/******************************************************************************* +** +** Function L2CA_UCDSetTxPriority +** +** Description Sets the transmission priority for a connectionless channel. +** +** Returns TRUE if a valid channel, else FALSE +** +*******************************************************************************/ +extern BOOLEAN L2CA_UCDSetTxPriority ( BD_ADDR rem_bda, tL2CAP_CHNL_PRIORITY priority ); + + +/******************************************************************************* +** +** Fixed Channel callback prototypes +** +*******************************************************************************/ + +/* Fixed channel connected and disconnected. Parameters are +** channel +** BD Address of remote +** TRUE if channel is connected, FALSE if disconnected +** Reason for connection failure +** transport : physical transport, BR/EDR or LE +*/ +typedef void (tL2CA_FIXED_CHNL_CB) (UINT16, BD_ADDR, BOOLEAN, UINT16, tBT_TRANSPORT); + +/* Signalling data received. Parameters are +** channel +** BD Address of remote +** Pointer to buffer with data +*/ +typedef void (tL2CA_FIXED_DATA_CB) (UINT16, BD_ADDR, BT_HDR *); + +/* Congestion status callback protype. This callback is optional. If +** an application tries to send data when the transmit queue is full, +** the data will anyways be dropped. The parameter is: +** remote BD_ADDR +** TRUE if congested, FALSE if uncongested +*/ +typedef void (tL2CA_FIXED_CONGESTION_STATUS_CB) (BD_ADDR, BOOLEAN); + +/* Fixed channel registration info (the callback addresses and channel config) +*/ +typedef struct { + tL2CA_FIXED_CHNL_CB *pL2CA_FixedConn_Cb; + tL2CA_FIXED_DATA_CB *pL2CA_FixedData_Cb; + tL2CA_FIXED_CONGESTION_STATUS_CB *pL2CA_FixedCong_Cb; + tL2CAP_FCR_OPTS fixed_chnl_opts; + + UINT16 default_idle_tout; + tL2CA_TX_COMPLETE_CB *pL2CA_FixedTxComplete_Cb; /* fixed channel tx complete callback */ +} tL2CAP_FIXED_CHNL_REG; + + +#if (L2CAP_NUM_FIXED_CHNLS > 0) +/******************************************************************************* +** +** Function L2CA_RegisterFixedChannel +** +** Description Register a fixed channel. +** +** Parameters: Fixed Channel # +** Channel Callbacks and config +** +** Return value: TRUE if registered OK +** +*******************************************************************************/ +extern BOOLEAN L2CA_RegisterFixedChannel (UINT16 fixed_cid, tL2CAP_FIXED_CHNL_REG *p_freg); + +/******************************************************************************* +** +** Function L2CA_ConnectFixedChnl +** +** Description Connect an fixed signalling channel to a remote device. +** +** Parameters: Fixed CID +** BD Address of remote +** +** Return value: TRUE if connection started +** +*******************************************************************************/ +extern BOOLEAN L2CA_ConnectFixedChnl (UINT16 fixed_cid, BD_ADDR bd_addr); + +/******************************************************************************* +** +** Function L2CA_SendFixedChnlData +** +** Description Write data on a fixed signalling channel. +** +** Parameters: Fixed CID +** BD Address of remote +** Pointer to buffer of type BT_HDR +** +** Return value L2CAP_DW_SUCCESS, if data accepted +** L2CAP_DW_FAILED, if error +** +*******************************************************************************/ +extern UINT16 L2CA_SendFixedChnlData (UINT16 fixed_cid, BD_ADDR rem_bda, BT_HDR *p_buf); + +/******************************************************************************* +** +** Function L2CA_RemoveFixedChnl +** +** Description Remove a fixed channel to a remote device. +** +** Parameters: Fixed CID +** BD Address of remote +** Idle timeout to use (or 0xFFFF if don't care) +** +** Return value: TRUE if channel removed +** +*******************************************************************************/ +extern BOOLEAN L2CA_RemoveFixedChnl (UINT16 fixed_cid, BD_ADDR rem_bda); + +/******************************************************************************* +** +** Function L2CA_SetFixedChannelTout +** +** Description Higher layers call this function to set the idle timeout for +** a fixed channel. The "idle timeout" is the amount of time that +** a connection can remain up with no L2CAP channels on it. +** A timeout of zero means that the connection will be torn +** down immediately when the last channel is removed. +** A timeout of 0xFFFF means no timeout. Values are in seconds. +** A bd_addr is the remote BD address. If bd_addr = BT_BD_ANY, +** then the idle timeouts for all active l2cap links will be +** changed. +** +** Returns TRUE if command succeeded, FALSE if failed +** +*******************************************************************************/ +extern BOOLEAN L2CA_SetFixedChannelTout (BD_ADDR rem_bda, UINT16 fixed_cid, UINT16 idle_tout); + +#endif /* (L2CAP_NUM_FIXED_CHNLS > 0) */ + +/******************************************************************************* +** +** Function L2CA_GetCurrentConfig +** +** Description This function returns configurations of L2CAP channel +** pp_our_cfg : pointer of our saved configuration options +** p_our_cfg_bits : valid config in bitmap +** pp_peer_cfg: pointer of peer's saved configuration options +** p_peer_cfg_bits : valid config in bitmap +** +** Returns TRUE if successful +** +*******************************************************************************/ +extern BOOLEAN L2CA_GetCurrentConfig (UINT16 lcid, + tL2CAP_CFG_INFO **pp_our_cfg, tL2CAP_CH_CFG_BITS *p_our_cfg_bits, + tL2CAP_CFG_INFO **pp_peer_cfg, tL2CAP_CH_CFG_BITS *p_peer_cfg_bits); + +#if (BLE_INCLUDED == TRUE) +/******************************************************************************* +** +** Function L2CA_CancelBleConnectReq +** +** Description Cancel a pending connection attempt to a BLE device. +** +** Parameters: BD Address of remote +** +** Return value: TRUE if connection was cancelled +** +*******************************************************************************/ +extern BOOLEAN L2CA_CancelBleConnectReq (BD_ADDR rem_bda); + +/******************************************************************************* +** +** Function L2CA_UpdateBleConnParams +** +** Description Update BLE connection parameters. +** +** Parameters: BD Address of remote +** +** Return value: TRUE if update started +** +*******************************************************************************/ +extern BOOLEAN L2CA_UpdateBleConnParams (BD_ADDR rem_bdRa, UINT16 min_int, + UINT16 max_int, UINT16 latency, UINT16 timeout); + +/******************************************************************************* +** +** Function L2CA_EnableUpdateBleConnParams +** +** Description Update BLE connection parameters. +** +** Parameters: BD Address of remote +** enable flag +** +** Return value: TRUE if update started +** +*******************************************************************************/ +extern BOOLEAN L2CA_EnableUpdateBleConnParams (BD_ADDR rem_bda, BOOLEAN enable); + +/******************************************************************************* +** +** Function L2CA_GetBleConnRole +** +** Description This function returns the connection role. +** +** Returns link role. +** +*******************************************************************************/ +extern UINT8 L2CA_GetBleConnRole (BD_ADDR bd_addr); + +/******************************************************************************* +** +** Function L2CA_GetDisconnectReason +** +** Description This function returns the disconnect reason code. +** +** Parameters: BD Address of remote +** Physical transport for the L2CAP connection (BR/EDR or LE) +** +** Returns disconnect reason +** +*******************************************************************************/ +extern UINT16 L2CA_GetDisconnectReason (BD_ADDR remote_bda, tBT_TRANSPORT transport); + +#endif /* (BLE_INCLUDED == TRUE) */ + +#ifdef __cplusplus +} +#endif + +#endif /* L2C_API_H */ diff --git a/tools/sdk/include/bluedroid/l2c_int.h b/tools/sdk/include/bluedroid/l2c_int.h new file mode 100644 index 00000000..56fdd0c9 --- /dev/null +++ b/tools/sdk/include/bluedroid/l2c_int.h @@ -0,0 +1,751 @@ +/****************************************************************************** + * + * Copyright (C) 1999-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 file contains L2CAP internal definitions + * + ******************************************************************************/ +#ifndef L2C_INT_H +#define L2C_INT_H + +#include + +#include "btm_api.h" +#include "gki.h" +#include "l2c_api.h" +#include "l2cdefs.h" +#include "list.h" + +#define L2CAP_MIN_MTU 48 /* Minimum acceptable MTU is 48 bytes */ + +/* Timeouts. Since L2CAP works off a 1-second list, all are in seconds. +*/ +#define L2CAP_LINK_ROLE_SWITCH_TOUT 10 /* 10 seconds */ +#define L2CAP_LINK_CONNECT_TOUT 60 /* 30 seconds */ +#define L2CAP_LINK_CONNECT_TOUT_EXT 120 /* 120 seconds */ +#define L2CAP_ECHO_RSP_TOUT 30 /* 30 seconds */ +#define L2CAP_LINK_FLOW_CONTROL_TOUT 2 /* 2 seconds */ +#define L2CAP_LINK_DISCONNECT_TOUT 30 /* 30 seconds */ + +#ifndef L2CAP_CHNL_CONNECT_TOUT /* BTIF needs to override for internal project needs */ +#define L2CAP_CHNL_CONNECT_TOUT 60 /* 60 seconds */ +#endif + +#define L2CAP_CHNL_CONNECT_TOUT_EXT 120 /* 120 seconds */ +#define L2CAP_CHNL_CFG_TIMEOUT 30 /* 30 seconds */ +#define L2CAP_CHNL_DISCONNECT_TOUT 10 /* 10 seconds */ +#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_BLE_LINK_CONNECT_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 */ +#define L2CAP_DEFAULT_MONITOR_TOUT 12000 /* 12000 milliseconds */ +#define L2CAP_FCR_ACK_TOUT 200 /* 200 milliseconds */ + +/* Define the possible L2CAP channel states. The names of +** the states may seem a bit strange, but they are taken from +** the Bluetooth specification. +*/ +typedef enum { + CST_CLOSED, /* Channel is in clodes state */ + CST_ORIG_W4_SEC_COMP, /* Originator waits security clearence */ + CST_TERM_W4_SEC_COMP, /* Acceptor waits security clearence */ + CST_W4_L2CAP_CONNECT_RSP, /* Waiting for peer conenct response */ + CST_W4_L2CA_CONNECT_RSP, /* Waiting for upper layer connect rsp */ + CST_CONFIG, /* Negotiating configuration */ + CST_OPEN, /* Data transfer state */ + CST_W4_L2CAP_DISCONNECT_RSP, /* Waiting for peer disconnect rsp */ + CST_W4_L2CA_DISCONNECT_RSP /* Waiting for upper layer disc rsp */ +} tL2C_CHNL_STATE; + +/* Define the possible L2CAP link states +*/ +typedef enum { + LST_DISCONNECTED, + LST_CONNECT_HOLDING, + LST_CONNECTING_WAIT_SWITCH, + LST_CONNECTING, + LST_CONNECTED, + LST_DISCONNECTING +} tL2C_LINK_STATE; + + + +/* Define input events to the L2CAP link and channel state machines. The names +** of the events may seem a bit strange, but they are taken from +** the Bluetooth specification. +*/ +#define L2CEVT_LP_CONNECT_CFM 0 /* Lower layer connect confirm */ +#define L2CEVT_LP_CONNECT_CFM_NEG 1 /* Lower layer connect confirm (failed) */ +#define L2CEVT_LP_CONNECT_IND 2 /* Lower layer connect indication */ +#define L2CEVT_LP_DISCONNECT_IND 3 /* Lower layer disconnect indication */ +#define L2CEVT_LP_QOS_CFM 4 /* Lower layer QOS confirmation */ +#define L2CEVT_LP_QOS_CFM_NEG 5 /* Lower layer QOS confirmation (failed)*/ +#define L2CEVT_LP_QOS_VIOLATION_IND 6 /* Lower layer QOS violation indication */ + +#define L2CEVT_SEC_COMP 7 /* Security cleared successfully */ +#define L2CEVT_SEC_COMP_NEG 8 /* Security procedure failed */ + +#define L2CEVT_L2CAP_CONNECT_REQ 10 /* Peer connection request */ +#define L2CEVT_L2CAP_CONNECT_RSP 11 /* Peer connection response */ +#define L2CEVT_L2CAP_CONNECT_RSP_PND 12 /* Peer connection response pending */ +#define L2CEVT_L2CAP_CONNECT_RSP_NEG 13 /* Peer connection response (failed) */ +#define L2CEVT_L2CAP_CONFIG_REQ 14 /* Peer configuration request */ +#define L2CEVT_L2CAP_CONFIG_RSP 15 /* Peer configuration response */ +#define L2CEVT_L2CAP_CONFIG_RSP_NEG 16 /* Peer configuration response (failed) */ +#define L2CEVT_L2CAP_DISCONNECT_REQ 17 /* Peer disconnect request */ +#define L2CEVT_L2CAP_DISCONNECT_RSP 18 /* Peer disconnect response */ +#define L2CEVT_L2CAP_INFO_RSP 19 /* Peer information response */ +#define L2CEVT_L2CAP_DATA 20 /* Peer data */ + +#define L2CEVT_L2CA_CONNECT_REQ 21 /* Upper layer connect request */ +#define L2CEVT_L2CA_CONNECT_RSP 22 /* Upper layer connect response */ +#define L2CEVT_L2CA_CONNECT_RSP_NEG 23 /* Upper layer connect response (failed)*/ +#define L2CEVT_L2CA_CONFIG_REQ 24 /* Upper layer config request */ +#define L2CEVT_L2CA_CONFIG_RSP 25 /* Upper layer config response */ +#define L2CEVT_L2CA_CONFIG_RSP_NEG 26 /* Upper layer config response (failed) */ +#define L2CEVT_L2CA_DISCONNECT_REQ 27 /* Upper layer disconnect request */ +#define L2CEVT_L2CA_DISCONNECT_RSP 28 /* Upper layer disconnect response */ +#define L2CEVT_L2CA_DATA_READ 29 /* Upper layer data read */ +#define L2CEVT_L2CA_DATA_WRITE 30 /* Upper layer data write */ +#define L2CEVT_L2CA_FLUSH_REQ 31 /* Upper layer flush */ + +#define L2CEVT_TIMEOUT 32 /* Timeout */ +#define L2CEVT_SEC_RE_SEND_CMD 33 /* btm_sec has enough info to proceed */ + +#define L2CEVT_ACK_TIMEOUT 34 /* RR delay timeout */ + + +/* Bitmask to skip over Broadcom feature reserved (ID) to avoid sending two + successive ID values, '0' id only or both */ +#define L2CAP_ADJ_BRCM_ID 0x1 +#define L2CAP_ADJ_ZERO_ID 0x2 +#define L2CAP_ADJ_ID 0x3 + +/* Return values for l2cu_process_peer_cfg_req() */ +#define L2CAP_PEER_CFG_UNACCEPTABLE 0 +#define L2CAP_PEER_CFG_OK 1 +#define L2CAP_PEER_CFG_DISCONNECT 2 + +/* eL2CAP option constants */ +#define L2CAP_MIN_RETRANS_TOUT 2000 /* Min retransmission timeout if no flush timeout or PBF */ +#define L2CAP_MIN_MONITOR_TOUT 12000 /* Min monitor timeout if no flush timeout or PBF */ + +#define L2CAP_MAX_FCR_CFG_TRIES 2 /* Config attempts before disconnecting */ + +typedef uint8_t tL2C_BLE_FIXED_CHNLS_MASK; + +typedef struct { + UINT8 next_tx_seq; /* Next sequence number to be Tx'ed */ + UINT8 last_rx_ack; /* Last sequence number ack'ed by the peer */ + UINT8 next_seq_expected; /* Next peer sequence number expected */ + UINT8 last_ack_sent; /* Last peer sequence number ack'ed */ + UINT8 num_tries; /* Number of retries to send a packet */ + UINT8 max_held_acks; /* Max acks we can hold before sending */ + + BOOLEAN remote_busy; /* TRUE if peer has flowed us off */ + BOOLEAN local_busy; /* TRUE if we have flowed off the peer */ + + BOOLEAN rej_sent; /* Reject was sent */ + BOOLEAN srej_sent; /* Selective Reject was sent */ + BOOLEAN wait_ack; /* Transmitter is waiting ack (poll sent) */ + BOOLEAN rej_after_srej; /* Send a REJ when SREJ clears */ + + BOOLEAN send_f_rsp; /* We need to send an F-bit response */ + + UINT16 rx_sdu_len; /* Length of the SDU being received */ + BT_HDR *p_rx_sdu; /* Buffer holding the SDU being received */ + BUFFER_Q waiting_for_ack_q; /* Buffers sent and waiting for peer to ack */ + BUFFER_Q srej_rcv_hold_q; /* Buffers rcvd but held pending SREJ rsp */ + BUFFER_Q retrans_q; /* Buffers being retransmitted */ + + TIMER_LIST_ENT ack_timer; /* Timer delaying RR */ + TIMER_LIST_ENT mon_retrans_timer; /* Timer Monitor or Retransmission */ + +#if (L2CAP_ERTM_STATS == TRUE) + UINT32 connect_tick_count; /* Time channel was established */ + UINT32 ertm_pkt_counts[2]; /* Packets sent and received */ + UINT32 ertm_byte_counts[2]; /* Bytes sent and received */ + UINT32 s_frames_sent[4]; /* S-frames sent (RR, REJ, RNR, SREJ) */ + UINT32 s_frames_rcvd[4]; /* S-frames rcvd (RR, REJ, RNR, SREJ) */ + UINT32 xmit_window_closed; /* # of times the xmit window was closed */ + UINT32 controller_idle; /* # of times less than 2 packets in controller */ + /* when the xmit window was closed */ + UINT32 pkts_retransmitted; /* # of packets that were retransmitted */ + UINT32 retrans_touts; /* # of retransmission timouts */ + UINT32 xmit_ack_touts; /* # of xmit ack timouts */ + +#define L2CAP_ERTM_STATS_NUM_AVG 10 +#define L2CAP_ERTM_STATS_AVG_NUM_SAMPLES 100 + UINT32 ack_delay_avg_count; + UINT32 ack_delay_avg_index; + UINT32 throughput_start; + UINT32 throughput[L2CAP_ERTM_STATS_NUM_AVG]; + UINT32 ack_delay_avg[L2CAP_ERTM_STATS_NUM_AVG]; + UINT32 ack_delay_min[L2CAP_ERTM_STATS_NUM_AVG]; + UINT32 ack_delay_max[L2CAP_ERTM_STATS_NUM_AVG]; + UINT32 ack_q_count_avg[L2CAP_ERTM_STATS_NUM_AVG]; + UINT32 ack_q_count_min[L2CAP_ERTM_STATS_NUM_AVG]; + UINT32 ack_q_count_max[L2CAP_ERTM_STATS_NUM_AVG]; +#endif +} tL2C_FCRB; + + +/* Define a registration control block. Every application (e.g. RFCOMM, SDP, +** TCS etc) that registers with L2CAP is assigned one of these. +*/ +#if (L2CAP_UCD_INCLUDED == TRUE) +#define L2C_UCD_RCB_ID 0x00 +#define L2C_UCD_STATE_UNUSED 0x00 +#define L2C_UCD_STATE_W4_DATA 0x01 +#define L2C_UCD_STATE_W4_RECEPTION 0x02 +#define L2C_UCD_STATE_W4_MTU 0x04 + +typedef struct { + UINT8 state; + tL2CAP_UCD_CB_INFO cb_info; +} tL2C_UCD_REG; +#endif + +typedef struct { + BOOLEAN in_use; + UINT16 psm; + UINT16 real_psm; /* This may be a dummy RCB for an o/b connection but */ + /* this is the real PSM that we need to connect to */ +#if (L2CAP_UCD_INCLUDED == TRUE) + tL2C_UCD_REG ucd; +#endif + + tL2CAP_APPL_INFO api; +} tL2C_RCB; + + +/* Define a channel control block (CCB). There may be many channel control blocks +** between the same two Bluetooth devices (i.e. on the same link). +** Each CCB has unique local and remote CIDs. All channel control blocks on +** the same physical link and are chained together. +*/ +typedef struct t_l2c_ccb { + BOOLEAN in_use; /* TRUE when in use, FALSE when not */ + tL2C_CHNL_STATE chnl_state; /* Channel state */ + + struct t_l2c_ccb *p_next_ccb; /* Next CCB in the chain */ + struct t_l2c_ccb *p_prev_ccb; /* Previous CCB in the chain */ + struct t_l2c_linkcb *p_lcb; /* Link this CCB is assigned to */ + + UINT16 local_cid; /* Local CID */ + UINT16 remote_cid; /* Remote CID */ + + TIMER_LIST_ENT timer_entry; /* CCB Timer List Entry */ + + tL2C_RCB *p_rcb; /* Registration CB for this Channel */ + bool should_free_rcb; /* True if RCB was allocated on the heap */ + +#define IB_CFG_DONE 0x01 +#define OB_CFG_DONE 0x02 +#define RECONFIG_FLAG 0x04 /* True after initial configuration */ +#define CFG_DONE_MASK (IB_CFG_DONE | OB_CFG_DONE) + + UINT8 config_done; /* Configuration flag word */ + UINT8 local_id; /* Transaction ID for local trans */ + UINT8 remote_id; /* Transaction ID for local */ + +#define CCB_FLAG_NO_RETRY 0x01 /* no more retry */ +#define CCB_FLAG_SENT_PENDING 0x02 /* already sent pending response */ + UINT8 flags; + + tL2CAP_CFG_INFO our_cfg; /* Our saved configuration options */ + tL2CAP_CH_CFG_BITS peer_cfg_bits; /* Store what peer wants to configure */ + tL2CAP_CFG_INFO peer_cfg; /* Peer's saved configuration options */ + + BUFFER_Q xmit_hold_q; /* Transmit data hold queue */ + BOOLEAN cong_sent; /* Set when congested status sent */ + UINT16 buff_quota; /* Buffer quota before sending congestion */ + + tL2CAP_CHNL_PRIORITY ccb_priority; /* Channel priority */ + tL2CAP_CHNL_DATA_RATE tx_data_rate; /* Channel Tx data rate */ + tL2CAP_CHNL_DATA_RATE rx_data_rate; /* Channel Rx data rate */ + + /* Fields used for eL2CAP */ + tL2CAP_ERTM_INFO ertm_info; + tL2C_FCRB fcrb; + UINT16 tx_mps; /* TX MPS adjusted based on current controller */ + UINT16 max_rx_mtu; + UINT8 fcr_cfg_tries; /* Max number of negotiation attempts */ + BOOLEAN peer_cfg_already_rejected; /* If mode rejected once, set to TRUE */ + BOOLEAN out_cfg_fcr_present; /* TRUE if cfg response shoulkd include fcr options */ + +#define L2CAP_CFG_FCS_OUR 0x01 /* Our desired config FCS option */ +#define L2CAP_CFG_FCS_PEER 0x02 /* Peer's desired config FCS option */ +#define L2CAP_BYPASS_FCS (L2CAP_CFG_FCS_OUR | L2CAP_CFG_FCS_PEER) + UINT8 bypass_fcs; + +#if (L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE) + BOOLEAN is_flushable; /* TRUE if channel is flushable */ +#endif + +#if (L2CAP_NUM_FIXED_CHNLS > 0) || (L2CAP_UCD_INCLUDED == TRUE) + UINT16 fixed_chnl_idle_tout; /* Idle timeout to use for the fixed channel */ +#endif + UINT16 tx_data_len; +} tL2C_CCB; + +/*********************************************************************** +** Define a queue of linked CCBs. +*/ +typedef struct { + tL2C_CCB *p_first_ccb; /* The first channel in this queue */ + tL2C_CCB *p_last_ccb; /* The last channel in this queue */ +} tL2C_CCB_Q; + +#if (L2CAP_ROUND_ROBIN_CHANNEL_SERVICE == TRUE) + +/* Round-Robin service for the same priority channels */ +#define L2CAP_NUM_CHNL_PRIORITY 3 /* Total number of priority group (high, medium, low)*/ +#define L2CAP_CHNL_PRIORITY_WEIGHT 5 /* weight per priority for burst transmission quota */ +#define L2CAP_GET_PRIORITY_QUOTA(pri) ((L2CAP_NUM_CHNL_PRIORITY - (pri)) * L2CAP_CHNL_PRIORITY_WEIGHT) + +/* CCBs within the same LCB are served in round robin with priority */ +/* It will make sure that low priority channel (for example, HF signaling on RFCOMM) */ +/* can be sent to headset even if higher priority channel (for example, AV media channel) */ +/* is congested. */ + +typedef struct { + tL2C_CCB *p_serve_ccb; /* current serving ccb within priority group */ + tL2C_CCB *p_first_ccb; /* first ccb of priority group */ + UINT8 num_ccb; /* number of channels in priority group */ + UINT8 quota; /* burst transmission quota */ +} tL2C_RR_SERV; + +#endif /* (L2CAP_ROUND_ROBIN_CHANNEL_SERVICE == TRUE) */ + +/* Define a link control block. There is one link control block between +** this device and any other device (i.e. BD ADDR). +*/ +typedef struct t_l2c_linkcb { + BOOLEAN in_use; /* TRUE when in use, FALSE when not */ + tL2C_LINK_STATE link_state; + + TIMER_LIST_ENT timer_entry; /* Timer list entry for timeout evt */ + UINT16 handle; /* The handle used with LM */ + + tL2C_CCB_Q ccb_queue; /* Queue of CCBs on this LCB */ + + 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 */ + BD_ADDR remote_bd_addr; /* The BD address of the remote */ + + UINT8 link_role; /* Master or slave */ + UINT8 id; + UINT8 cur_echo_id; /* Current id value for echo request */ + tL2CA_ECHO_RSP_CB *p_echo_rsp_cb; /* Echo response callback */ + UINT16 idle_timeout; /* Idle timeout */ + BOOLEAN is_bonding; /* True - link active only for bonding */ + + UINT16 link_flush_tout; /* Flush timeout used */ + + UINT16 link_xmit_quota; /* Num outstanding pkts allowed */ + UINT16 sent_not_acked; /* Num packets sent but not acked */ + + BOOLEAN partial_segment_being_sent; /* Set TRUE when a partial segment */ + /* is being sent. */ + BOOLEAN w4_info_rsp; /* TRUE when info request is active */ + UINT8 info_rx_bits; /* set 1 if received info type */ + UINT32 peer_ext_fea; /* Peer's extended features mask */ + list_t *link_xmit_data_q; /* Link transmit data buffer queue */ + + UINT8 peer_chnl_mask[L2CAP_FIXED_CHNL_ARRAY_SIZE]; +#if (L2CAP_UCD_INCLUDED == TRUE) + UINT16 ucd_mtu; /* peer MTU on UCD */ + BUFFER_Q ucd_out_sec_pending_q; /* Security pending outgoing UCD packet */ + BUFFER_Q ucd_in_sec_pending_q; /* Security pending incoming UCD packet */ +#endif + + BT_HDR *p_hcit_rcv_acl; /* Current HCIT ACL buf being rcvd */ + UINT16 idle_timeout_sv; /* Save current Idle timeout */ + UINT8 acl_priority; /* L2C_PRIORITY_NORMAL or L2C_PRIORITY_HIGH */ + tL2CA_NOCP_CB *p_nocp_cb; /* Num Cmpl pkts callback */ + +#if (L2CAP_NUM_FIXED_CHNLS > 0) + tL2C_CCB *p_fixed_ccbs[L2CAP_NUM_FIXED_CHNLS]; + UINT16 disc_reason; +#endif + + tBT_TRANSPORT transport; +#if (BLE_INCLUDED == TRUE) + tBLE_ADDR_TYPE ble_addr_type; + UINT16 tx_data_len; /* tx data length used in data length extension */ + +#define L2C_BLE_CONN_UPDATE_DISABLE 0x1 /* disable update connection parameters */ +#define L2C_BLE_NEW_CONN_PARAM 0x2 /* new connection parameter to be set */ +#define L2C_BLE_UPDATE_PENDING 0x4 /* waiting for connection update finished */ +#define L2C_BLE_NOT_DEFAULT_PARAM 0x8 /* not using default connection parameters */ + UINT8 conn_update_mask; + + UINT16 min_interval; /* parameters as requested by peripheral */ + UINT16 max_interval; + UINT16 latency; + UINT16 timeout; + +#endif + +#if (L2CAP_ROUND_ROBIN_CHANNEL_SERVICE == TRUE) + /* each priority group is limited burst transmission */ + /* round robin service for the same priority channels */ + tL2C_RR_SERV rr_serv[L2CAP_NUM_CHNL_PRIORITY]; + UINT8 rr_pri; /* current serving priority group */ +#endif + +} tL2C_LCB; + +/* Define the L2CAP control structure +*/ +typedef struct { + UINT8 l2cap_trace_level; + UINT16 controller_xmit_window; /* Total ACL window for all links */ + + UINT16 round_robin_quota; /* Round-robin link quota */ + UINT16 round_robin_unacked; /* Round-robin unacked */ + BOOLEAN check_round_robin; /* Do a round robin check */ + + BOOLEAN is_cong_cback_context; + + tL2C_LCB lcb_pool[MAX_L2CAP_LINKS]; /* Link Control Block pool */ + tL2C_CCB ccb_pool[MAX_L2CAP_CHANNELS]; /* Channel Control Block pool */ + tL2C_RCB rcb_pool[MAX_L2CAP_CLIENTS]; /* Registration info pool */ + + tL2C_CCB *p_free_ccb_first; /* Pointer to first free CCB */ + tL2C_CCB *p_free_ccb_last; /* Pointer to last free CCB */ + + UINT8 desire_role; /* desire to be master/slave when accepting a connection */ + BOOLEAN disallow_switch; /* FALSE, to allow switch at create conn */ + UINT16 num_lm_acl_bufs; /* # of ACL buffers on controller */ + UINT16 idle_timeout; /* Idle timeout */ + + list_t *rcv_pending_q; /* Recv pending queue */ + TIMER_LIST_ENT rcv_hold_tle; /* Timer list entry for rcv hold */ + + tL2C_LCB *p_cur_hcit_lcb; /* Current HCI Transport buffer */ + UINT16 num_links_active; /* Number of links active */ + +#if (L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE) + UINT16 non_flushable_pbf; /* L2CAP_PKT_START_NON_FLUSHABLE if controller supports */ + /* Otherwise, L2CAP_PKT_START */ + BOOLEAN is_flush_active; /* TRUE if an HCI_Enhanced_Flush has been sent */ +#endif + +#if L2CAP_CONFORMANCE_TESTING == TRUE + UINT32 test_info_resp; /* Conformance testing needs a dynamic response */ +#endif + +#if (L2CAP_NUM_FIXED_CHNLS > 0) + tL2CAP_FIXED_CHNL_REG fixed_reg[L2CAP_NUM_FIXED_CHNLS]; /* Reg info for fixed channels */ +#endif + +#if (BLE_INCLUDED == TRUE) + UINT16 num_ble_links_active; /* Number of LE links active */ + BOOLEAN is_ble_connecting; + BD_ADDR ble_connecting_bda; + UINT16 controller_le_xmit_window; /* Total ACL window for all links */ + tL2C_BLE_FIXED_CHNLS_MASK l2c_ble_fixed_chnls_mask; // LE fixed channels mask + UINT16 num_lm_ble_bufs; /* # of ACL buffers on controller */ + UINT16 ble_round_robin_quota; /* Round-robin link quota */ + UINT16 ble_round_robin_unacked; /* Round-robin unacked */ + BOOLEAN ble_check_round_robin; /* Do a round robin check */ +#endif + + tL2CA_ECHO_DATA_CB *p_echo_data_cb; /* Echo data callback */ + +#if (defined(L2CAP_HIGH_PRI_CHAN_QUOTA_IS_CONFIGURABLE) && (L2CAP_HIGH_PRI_CHAN_QUOTA_IS_CONFIGURABLE == TRUE)) + UINT16 high_pri_min_xmit_quota; /* Minimum number of ACL credit for high priority link */ +#endif /* (L2CAP_HIGH_PRI_CHAN_QUOTA_IS_CONFIGURABLE == TRUE) */ + + UINT16 dyn_psm; +} tL2C_CB; + + + +/* Define a structure that contains the information about a connection. +** This structure is used to pass between functions, and not all the +** fields will always be filled in. +*/ +typedef struct { + BD_ADDR bd_addr; /* Remote BD address */ + UINT8 status; /* Connection status */ + UINT16 psm; /* PSM of the connection */ + UINT16 l2cap_result; /* L2CAP result */ + UINT16 l2cap_status; /* L2CAP status */ + UINT16 remote_cid; /* Remote CID */ +} tL2C_CONN_INFO; + + +typedef void (tL2C_FCR_MGMT_EVT_HDLR) (UINT8, tL2C_CCB *); + +/* The offset in a buffer that L2CAP will use when building commands. +*/ +#define L2CAP_SEND_CMD_OFFSET 0 + + +/* Number of ACL buffers to use for high priority channel +*/ +#if (!defined(L2CAP_HIGH_PRI_CHAN_QUOTA_IS_CONFIGURABLE) || (L2CAP_HIGH_PRI_CHAN_QUOTA_IS_CONFIGURABLE == FALSE)) +#define L2CAP_HIGH_PRI_MIN_XMIT_QUOTA_A (L2CAP_HIGH_PRI_MIN_XMIT_QUOTA) +#else +#define L2CAP_HIGH_PRI_MIN_XMIT_QUOTA_A (l2cb.high_pri_min_xmit_quota) +#endif + +#ifdef __cplusplus +extern "C" { +#endif + + +/* L2CAP global data +************************************ +*/ +#if (!defined L2C_DYNAMIC_MEMORY) || (L2C_DYNAMIC_MEMORY == FALSE) +extern tL2C_CB l2cb; +#else +extern tL2C_CB *l2c_cb_ptr; +#define l2cb (*l2c_cb_ptr) +#endif + + +/* Functions provided by l2c_main.c +************************************ +*/ +void l2c_init(void); +void l2c_free(void); + +extern void l2c_process_timeout (TIMER_LIST_ENT *p_tle); +extern UINT8 l2c_data_write (UINT16 cid, BT_HDR *p_data, UINT16 flag); +extern void l2c_rcv_acl_data (BT_HDR *p_msg); +extern void l2c_process_held_packets (BOOLEAN timed_out); + +/* Functions provided by l2c_utils.c +************************************ +*/ +extern tL2C_LCB *l2cu_allocate_lcb (BD_ADDR p_bd_addr, BOOLEAN is_bonding, tBT_TRANSPORT transport); +extern BOOLEAN l2cu_start_post_bond_timer (UINT16 handle); +extern void l2cu_release_lcb (tL2C_LCB *p_lcb); +extern tL2C_LCB *l2cu_find_lcb_by_bd_addr (BD_ADDR p_bd_addr, tBT_TRANSPORT transport); +extern tL2C_LCB *l2cu_find_lcb_by_handle (UINT16 handle); +extern void l2cu_update_lcb_4_bonding (BD_ADDR p_bd_addr, BOOLEAN is_bonding); + +extern UINT8 l2cu_get_conn_role (tL2C_LCB *p_this_lcb); +extern BOOLEAN l2cu_set_acl_priority (BD_ADDR bd_addr, UINT8 priority, BOOLEAN reset_after_rs); + +extern void l2cu_enqueue_ccb (tL2C_CCB *p_ccb); +extern void l2cu_dequeue_ccb (tL2C_CCB *p_ccb); +extern void l2cu_change_pri_ccb (tL2C_CCB *p_ccb, tL2CAP_CHNL_PRIORITY priority); + +extern tL2C_CCB *l2cu_allocate_ccb (tL2C_LCB *p_lcb, UINT16 cid); +extern void l2cu_release_ccb (tL2C_CCB *p_ccb); +extern tL2C_CCB *l2cu_find_ccb_by_cid (tL2C_LCB *p_lcb, UINT16 local_cid); +extern tL2C_CCB *l2cu_find_ccb_by_remote_cid (tL2C_LCB *p_lcb, UINT16 remote_cid); +extern void l2cu_adj_id (tL2C_LCB *p_lcb, UINT8 adj_mask); +extern BOOLEAN l2c_is_cmd_rejected (UINT8 cmd_code, UINT8 id, tL2C_LCB *p_lcb); + +extern void l2cu_send_peer_cmd_reject (tL2C_LCB *p_lcb, UINT16 reason, + UINT8 rem_id, UINT16 p1, UINT16 p2); +extern void l2cu_send_peer_connect_req (tL2C_CCB *p_ccb); +extern void l2cu_send_peer_connect_rsp (tL2C_CCB *p_ccb, UINT16 result, UINT16 status); +extern void l2cu_send_peer_config_req (tL2C_CCB *p_ccb, tL2CAP_CFG_INFO *p_cfg); +extern void l2cu_send_peer_config_rsp (tL2C_CCB *p_ccb, tL2CAP_CFG_INFO *p_cfg); +extern void l2cu_send_peer_config_rej (tL2C_CCB *p_ccb, UINT8 *p_data, UINT16 data_len, UINT16 rej_len); +extern void l2cu_send_peer_disc_req (tL2C_CCB *p_ccb); +extern void l2cu_send_peer_disc_rsp (tL2C_LCB *p_lcb, UINT8 remote_id, UINT16 local_cid, UINT16 remote_cid); +extern void l2cu_send_peer_echo_req (tL2C_LCB *p_lcb, UINT8 *p_data, UINT16 data_len); +extern void l2cu_send_peer_echo_rsp (tL2C_LCB *p_lcb, UINT8 id, UINT8 *p_data, UINT16 data_len); +extern void l2cu_send_peer_info_rsp (tL2C_LCB *p_lcb, UINT8 id, UINT16 info_type); +extern void l2cu_reject_connection (tL2C_LCB *p_lcb, UINT16 remote_cid, UINT8 rem_id, UINT16 result); +extern void l2cu_send_peer_info_req (tL2C_LCB *p_lcb, UINT16 info_type); +extern void l2cu_set_acl_hci_header (BT_HDR *p_buf, tL2C_CCB *p_ccb); +extern void l2cu_check_channel_congestion (tL2C_CCB *p_ccb); +extern void l2cu_disconnect_chnl (tL2C_CCB *p_ccb); + +#if (L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE) +extern void l2cu_set_non_flushable_pbf(BOOLEAN); +#endif + +#if (BLE_INCLUDED == TRUE) +extern void l2cu_send_peer_ble_par_req (tL2C_LCB *p_lcb, UINT16 min_int, UINT16 max_int, UINT16 latency, UINT16 timeout); +extern void l2cu_send_peer_ble_par_rsp (tL2C_LCB *p_lcb, UINT16 reason, UINT8 rem_id); +#endif + +extern BOOLEAN l2cu_initialize_fixed_ccb (tL2C_LCB *p_lcb, UINT16 fixed_cid, tL2CAP_FCR_OPTS *p_fcr); +extern void l2cu_no_dynamic_ccbs (tL2C_LCB *p_lcb); +extern void l2cu_process_fixed_chnl_resp (tL2C_LCB *p_lcb); + +/* Functions provided by l2c_ucd.c +************************************ +*/ +#if (L2CAP_UCD_INCLUDED == TRUE) +void l2c_ucd_delete_sec_pending_q(tL2C_LCB *p_lcb); +void l2c_ucd_enqueue_pending_out_sec_q(tL2C_CCB *p_ccb, void *p_data); +BOOLEAN l2c_ucd_check_pending_info_req(tL2C_CCB *p_ccb); +BOOLEAN l2c_ucd_check_pending_out_sec_q(tL2C_CCB *p_ccb); +void l2c_ucd_send_pending_out_sec_q(tL2C_CCB *p_ccb); +void l2c_ucd_discard_pending_out_sec_q(tL2C_CCB *p_ccb); +BOOLEAN l2c_ucd_check_pending_in_sec_q(tL2C_CCB *p_ccb); +void l2c_ucd_send_pending_in_sec_q(tL2C_CCB *p_ccb); +void l2c_ucd_discard_pending_in_sec_q(tL2C_CCB *p_ccb); +BOOLEAN l2c_ucd_check_rx_pkts(tL2C_LCB *p_lcb, BT_HDR *p_msg); +BOOLEAN l2c_ucd_process_event(tL2C_CCB *p_ccb, UINT16 event, void *p_data); +#endif + +#if (BLE_INCLUDED == TRUE) +extern void l2cu_send_peer_ble_par_req (tL2C_LCB *p_lcb, UINT16 min_int, UINT16 max_int, UINT16 latency, UINT16 timeout); +extern void l2cu_send_peer_ble_par_rsp (tL2C_LCB *p_lcb, UINT16 reason, UINT8 rem_id); +#endif + +extern BOOLEAN l2cu_initialize_fixed_ccb (tL2C_LCB *p_lcb, UINT16 fixed_cid, tL2CAP_FCR_OPTS *p_fcr); +extern void l2cu_no_dynamic_ccbs (tL2C_LCB *p_lcb); +extern void l2cu_process_fixed_chnl_resp (tL2C_LCB *p_lcb); + + +/* Functions provided for Broadcom Aware +**************************************** +*/ +extern BOOLEAN l2cu_check_feature_req (tL2C_LCB *p_lcb, UINT8 id, UINT8 *p_data, UINT16 data_len); +extern void l2cu_check_feature_rsp (tL2C_LCB *p_lcb, UINT8 id, UINT8 *p_data, UINT16 data_len); +extern void l2cu_send_feature_req (tL2C_CCB *p_ccb); + +extern tL2C_RCB *l2cu_allocate_rcb (UINT16 psm); +extern tL2C_RCB *l2cu_find_rcb_by_psm (UINT16 psm); +extern void l2cu_release_rcb (tL2C_RCB *p_rcb); + +extern UINT8 l2cu_process_peer_cfg_req (tL2C_CCB *p_ccb, tL2CAP_CFG_INFO *p_cfg); +extern void l2cu_process_peer_cfg_rsp (tL2C_CCB *p_ccb, tL2CAP_CFG_INFO *p_cfg); +extern void l2cu_process_our_cfg_req (tL2C_CCB *p_ccb, tL2CAP_CFG_INFO *p_cfg); +extern void l2cu_process_our_cfg_rsp (tL2C_CCB *p_ccb, tL2CAP_CFG_INFO *p_cfg); + +extern void l2cu_device_reset (void); +extern tL2C_LCB *l2cu_find_lcb_by_state (tL2C_LINK_STATE state); +extern BOOLEAN l2cu_lcb_disconnecting (void); + +extern BOOLEAN l2cu_create_conn (tL2C_LCB *p_lcb, tBT_TRANSPORT transport); +extern BOOLEAN l2cu_create_conn_after_switch (tL2C_LCB *p_lcb); +extern BT_HDR *l2cu_get_next_buffer_to_send (tL2C_LCB *p_lcb); +extern void l2cu_resubmit_pending_sec_req (BD_ADDR p_bda); +extern void l2cu_initialize_amp_ccb (tL2C_LCB *p_lcb); +extern void l2cu_adjust_out_mps (tL2C_CCB *p_ccb); + +/* Functions provided by l2c_link.c +************************************ +*/ +extern BOOLEAN l2c_link_hci_conn_req (BD_ADDR bd_addr); +extern BOOLEAN l2c_link_hci_conn_comp (UINT8 status, UINT16 handle, BD_ADDR p_bda); +extern BOOLEAN l2c_link_hci_disc_comp (UINT16 handle, UINT8 reason); +extern BOOLEAN l2c_link_hci_qos_violation (UINT16 handle); +extern void l2c_link_timeout (tL2C_LCB *p_lcb); +extern void l2c_info_timeout (tL2C_LCB *p_lcb); +extern void l2c_link_check_send_pkts (tL2C_LCB *p_lcb, tL2C_CCB *p_ccb, BT_HDR *p_buf); +extern void l2c_link_adjust_allocation (void); +extern void l2c_link_process_num_completed_pkts (UINT8 *p); +extern void l2c_link_process_num_completed_blocks (UINT8 controller_id, UINT8 *p, UINT16 evt_len); +extern void l2c_link_processs_num_bufs (UINT16 num_lm_acl_bufs); +extern UINT8 l2c_link_pkts_rcvd (UINT16 *num_pkts, UINT16 *handles); +extern void l2c_link_role_changed (BD_ADDR bd_addr, UINT8 new_role, UINT8 hci_status); +extern void l2c_link_sec_comp (BD_ADDR p_bda, tBT_TRANSPORT trasnport, void *p_ref_data, UINT8 status); +extern void l2c_link_segments_xmitted (BT_HDR *p_msg); +extern void l2c_pin_code_request (BD_ADDR bd_addr); +extern void l2c_link_adjust_chnl_allocation (void); + +#if (BLE_INCLUDED == TRUE) +extern void l2c_link_processs_ble_num_bufs (UINT16 num_lm_acl_bufs); +#endif + +#if L2CAP_WAKE_PARKED_LINK == TRUE +extern BOOLEAN l2c_link_check_power_mode ( tL2C_LCB *p_lcb ); +#define L2C_LINK_CHECK_POWER_MODE(x) l2c_link_check_power_mode ((x)) +#else // L2CAP_WAKE_PARKED_LINK +#define L2C_LINK_CHECK_POWER_MODE(x) (FALSE) +#endif // L2CAP_WAKE_PARKED_LINK + +#if L2CAP_CONFORMANCE_TESTING == TRUE +/* Used only for conformance testing */ +extern void l2cu_set_info_rsp_mask (UINT32 mask); +#endif + +/* Functions provided by l2c_csm.c +************************************ +*/ +extern void l2c_csm_execute (tL2C_CCB *p_ccb, UINT16 event, void *p_data); + +extern void l2c_enqueue_peer_data (tL2C_CCB *p_ccb, BT_HDR *p_buf); + + +/* Functions provided by l2c_fcr.c +************************************ +*/ +extern void l2c_fcr_cleanup (tL2C_CCB *p_ccb); +extern void l2c_fcr_proc_pdu (tL2C_CCB *p_ccb, BT_HDR *p_buf); +extern void l2c_fcr_proc_tout (tL2C_CCB *p_ccb); +extern void l2c_fcr_proc_ack_tout (tL2C_CCB *p_ccb); +extern void l2c_fcr_send_S_frame (tL2C_CCB *p_ccb, UINT16 function_code, UINT16 pf_bit); +extern BT_HDR *l2c_fcr_clone_buf (BT_HDR *p_buf, UINT16 new_offset, UINT16 no_of_bytes, UINT8 pool); +extern BOOLEAN l2c_fcr_is_flow_controlled (tL2C_CCB *p_ccb); +extern BT_HDR *l2c_fcr_get_next_xmit_sdu_seg (tL2C_CCB *p_ccb, UINT16 max_packet_length); +extern void l2c_fcr_start_timer (tL2C_CCB *p_ccb); + +/* Configuration negotiation */ +extern UINT8 l2c_fcr_chk_chan_modes (tL2C_CCB *p_ccb); +extern BOOLEAN l2c_fcr_adj_our_req_options (tL2C_CCB *p_ccb, tL2CAP_CFG_INFO *p_cfg); +extern void l2c_fcr_adj_our_rsp_options (tL2C_CCB *p_ccb, tL2CAP_CFG_INFO *p_peer_cfg); +extern BOOLEAN l2c_fcr_renegotiate_chan(tL2C_CCB *p_ccb, tL2CAP_CFG_INFO *p_cfg); +extern UINT8 l2c_fcr_process_peer_cfg_req(tL2C_CCB *p_ccb, tL2CAP_CFG_INFO *p_cfg); +extern void l2c_fcr_adj_monitor_retran_timeout (tL2C_CCB *p_ccb); +extern void l2c_fcr_stop_timer (tL2C_CCB *p_ccb); + +/* Functions provided by l2c_ble.c +************************************ +*/ +#if (BLE_INCLUDED == TRUE) +extern BOOLEAN l2cble_create_conn (tL2C_LCB *p_lcb); +extern void l2cble_process_sig_cmd (tL2C_LCB *p_lcb, UINT8 *p, UINT16 pkt_len); +extern void l2cble_conn_comp (UINT16 handle, UINT8 role, BD_ADDR bda, tBLE_ADDR_TYPE type, + UINT16 conn_interval, UINT16 conn_latency, UINT16 conn_timeout); +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); + +#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, + UINT16 latency, UINT16 timeout); +#endif + +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 l2cble_process_data_length_change_event(UINT16 handle, UINT16 tx_data_len, + UINT16 rx_data_len); + +#endif +extern void l2cu_process_fixed_disc_cback (tL2C_LCB *p_lcb); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/tools/sdk/include/bluedroid/l2cap_client.h b/tools/sdk/include/bluedroid/l2cap_client.h new file mode 100644 index 00000000..168c8db5 --- /dev/null +++ b/tools/sdk/include/bluedroid/l2cap_client.h @@ -0,0 +1,77 @@ +/****************************************************************************** + * + * 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 _L2CAP_CLIENT_H_ +#define _L2CAP_CLIENT_H_ + +//#include +#include +#include + +typedef struct buffer_t buffer_t; +typedef struct l2cap_client_t l2cap_client_t; + +typedef struct { + void (*connected)(l2cap_client_t *client, void *context); + void (*disconnected)(l2cap_client_t *client, void *context); + void (*read_ready)(l2cap_client_t *client, buffer_t *packet, void *context); + void (*write_ready)(l2cap_client_t *client, void *context); +} l2cap_client_callbacks_t; + +// Returns a new buffer with enough space for |size| bytes of L2CAP payload. +// |size| must be greater than zero. This function returns NULL if the buffer +// could not be allocated. The returned buffer must be freed with |buffer_free| +// when it is no longer needed. +buffer_t *l2cap_buffer_new(size_t size); + +// Creates and returns a new L2CAP client object. |callbacks| must not be NULL and +// must specify a set of functions that should be called back when events occur +// on the L2CAP connection. |context| may be NULL and will be passed as the argument +// to all callbacks in |l2cap_client_callbacks_t|. The returned object must be freed +// with |l2cap_client_free|. +l2cap_client_t *l2cap_client_new(const l2cap_client_callbacks_t *callbacks, void *context); + +// Frees the L2CAP client object allocated with |l2cap_client_new|. |client| may be NULL. +void l2cap_client_free(l2cap_client_t *client); + +// Attempts to connect the |client| to a peer device specified by |remote_bdaddr| +// using the |psm| protocol specifier. This function returns true if the connect +// operation could be started and will indicate completion with either a 'connected' +// callback (success) or a 'disconnected' callback (failure). +// +// This function must not be called while a connect operation is in progress or +// while |l2cap_client_is_connected|. |client| and |remote_bdaddr| must not be NULL. +// |psm| must be greater than zero. +bool l2cap_client_connect(l2cap_client_t *client, const bt_bdaddr_t *remote_bdaddr, uint16_t psm); + +// Disconnects a connected |client|. This function is asynchronous and idempotent. It +// will indicate completion with a 'disconnected' callback. |client| must not be NULL. +void l2cap_client_disconnect(l2cap_client_t *client); + +// Returns true if |client| is connected and is ready to accept data written to it. +// |client| must not be NULL. +bool l2cap_client_is_connected(const l2cap_client_t *client); + +// Writes data contained in |packet| to a connected |client|. This function returns +// true if the packet was successfully queued for delivery, false if the client cannot +// accept more data at this time. If this function returns false, the caller must wait +// for the 'write_ready' callback to write additional data to the client. Neither +// |client| nor |packet| may be NULL. +bool l2cap_client_write(l2cap_client_t *client, buffer_t *packet); + +#endif /*_L2CAP_CLIENT_H_*/ diff --git a/tools/sdk/include/bluedroid/l2cdefs.h b/tools/sdk/include/bluedroid/l2cdefs.h new file mode 100644 index 00000000..e31ee24b --- /dev/null +++ b/tools/sdk/include/bluedroid/l2cdefs.h @@ -0,0 +1,318 @@ +/****************************************************************************** + * + * Copyright (C) 1999-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. + * + ******************************************************************************/ + +#ifndef L2CDEFS_H +#define L2CDEFS_H + +/* L2CAP command codes +*/ +#define L2CAP_CMD_REJECT 0x01 +#define L2CAP_CMD_CONN_REQ 0x02 +#define L2CAP_CMD_CONN_RSP 0x03 +#define L2CAP_CMD_CONFIG_REQ 0x04 +#define L2CAP_CMD_CONFIG_RSP 0x05 +#define L2CAP_CMD_DISC_REQ 0x06 +#define L2CAP_CMD_DISC_RSP 0x07 +#define L2CAP_CMD_ECHO_REQ 0x08 +#define L2CAP_CMD_ECHO_RSP 0x09 +#define L2CAP_CMD_INFO_REQ 0x0A +#define L2CAP_CMD_INFO_RSP 0x0B +#define L2CAP_CMD_AMP_CONN_REQ 0x0C +#define L2CAP_CMD_AMP_CONN_RSP 0x0D +#define L2CAP_CMD_AMP_MOVE_REQ 0x0E +#define L2CAP_CMD_AMP_MOVE_RSP 0x0F +#define L2CAP_CMD_AMP_MOVE_CFM 0x10 +#define L2CAP_CMD_AMP_MOVE_CFM_RSP 0x11 + +#define L2CAP_CMD_BLE_UPDATE_REQ 0x12 +#define L2CAP_CMD_BLE_UPDATE_RSP 0x13 + + +/* Define some packet and header lengths +*/ +#define L2CAP_PKT_OVERHEAD 4 /* Length and CID */ +#define L2CAP_CMD_OVERHEAD 4 /* Cmd code, Id and length */ +#define L2CAP_CMD_REJECT_LEN 2 /* Reason (data is optional) */ +#define L2CAP_CONN_REQ_LEN 4 /* PSM and source CID */ +#define L2CAP_CONN_RSP_LEN 8 /* Dest CID, source CID, reason, status */ +#define L2CAP_CONFIG_REQ_LEN 4 /* Dest CID, flags (data is optional) */ +#define L2CAP_CONFIG_RSP_LEN 6 /* Dest CID, flags, result,data optional*/ +#define L2CAP_DISC_REQ_LEN 4 /* Dest CID, source CID */ +#define L2CAP_DISC_RSP_LEN 4 /* Dest CID, source CID */ +#define L2CAP_ECHO_REQ_LEN 0 /* Data is optional */ +#define L2CAP_ECHO_RSP_LEN 0 /* Data is optional */ +#define L2CAP_INFO_REQ_LEN 2 /* Info type */ +#define L2CAP_INFO_RSP_LEN 4 /* Info type, result (data is optional) */ +#define L2CAP_BCST_OVERHEAD 2 /* Additional broadcast packet overhead */ +#define L2CAP_UCD_OVERHEAD 2 /* Additional connectionless packet overhead */ + +#define L2CAP_AMP_CONN_REQ_LEN 5 /* PSM, CID, and remote controller ID */ +#define L2CAP_AMP_MOVE_REQ_LEN 3 /* CID and remote controller ID */ +#define L2CAP_AMP_MOVE_RSP_LEN 4 /* CID and result */ +#define L2CAP_AMP_MOVE_CFM_LEN 4 /* CID and result */ +#define L2CAP_AMP_MOVE_CFM_RSP_LEN 2 /* CID */ + +#define L2CAP_CMD_BLE_UPD_REQ_LEN 8 /* Min and max interval, latency, tout */ +#define L2CAP_CMD_BLE_UPD_RSP_LEN 2 /* Result */ + + +/* Define the packet boundary flags +*/ +#if (L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE) +#define L2CAP_PKT_START_FLUSHABLE 2 +#define L2CAP_PKT_START_NON_FLUSHABLE 0 +#endif +#define L2CAP_COMPLETE_AMP_PKT 3 /* complete L2CAP packet on AMP HCI */ +#define L2CAP_PKT_START 2 +#define L2CAP_PKT_CONTINUE 1 +#define L2CAP_MASK_FLAG 0x0FFF +#define L2CAP_PKT_TYPE_SHIFT 12 +#define L2CAP_PKT_TYPE_MASK 3 + + +/* Define the L2CAP connection result codes +*/ +#define L2CAP_CONN_OK 0 +#define L2CAP_CONN_PENDING 1 +#define L2CAP_CONN_NO_PSM 2 +#define L2CAP_CONN_SECURITY_BLOCK 3 +#define L2CAP_CONN_NO_RESOURCES 4 +#define L2CAP_CONN_BAD_CTLR_ID 5 /* AMP related */ +#define L2CAP_CONN_TIMEOUT 0xEEEE +#define L2CAP_CONN_AMP_FAILED 254 +#define L2CAP_CONN_NO_LINK 255 /* Add a couple of our own for internal use */ +#define L2CAP_CONN_CANCEL 256 /* L2CAP connection cancelled */ + + +/* Define L2CAP Move Channel Response result codes +*/ +#define L2CAP_MOVE_OK 0 +#define L2CAP_MOVE_PENDING 1 +#define L2CAP_MOVE_CTRL_ID_NOT_SUPPORT 2 +#define L2CAP_MOVE_SAME_CTRLR_ID 3 +#define L2CAP_MOVE_CONFIG_NOT_SUPPORTED 4 +#define L2CAP_MOVE_CHAN_COLLISION 5 +#define L2CAP_MOVE_NOT_ALLOWED 6 + + +/* Define L2CAP Move Channel Confirmation result codes +*/ +#define L2CAP_MOVE_CFM_OK 0 +#define L2CAP_MOVE_CFM_REFUSED 1 + + +/* Define the L2CAP command reject reason codes +*/ +#define L2CAP_CMD_REJ_NOT_UNDERSTOOD 0 +#define L2CAP_CMD_REJ_MTU_EXCEEDED 1 +#define L2CAP_CMD_REJ_INVALID_CID 2 + + +/* L2CAP Predefined CIDs +*/ +#define L2CAP_SIGNALLING_CID 1 +#define L2CAP_CONNECTIONLESS_CID 2 +#define L2CAP_AMP_CID 3 +#define L2CAP_ATT_CID 4 +#define L2CAP_BLE_SIGNALLING_CID 5 +#define L2CAP_SMP_CID 6 +#define L2CAP_SMP_BR_CID 7 +#define L2CAP_AMP_TEST_CID 0x003F +#define L2CAP_BASE_APPL_CID 0x0040 +#define L2CAP_BLE_CONN_MAX_CID 0x007F + +/* Fixed Channels mask bits */ + +/* Signal channel supported (Mandatory) */ +#define L2CAP_FIXED_CHNL_SIG_BIT (1 << L2CAP_SIGNALLING_CID) + +/* Connectionless reception */ +#define L2CAP_FIXED_CHNL_CNCTLESS_BIT (1 << L2CAP_CONNECTIONLESS_CID) + +/* AMP Manager supported */ +#define L2CAP_FIXED_CHNL_AMP_BIT (1 << L2CAP_AMP_CID) + +/* Attribute protocol supported */ +#define L2CAP_FIXED_CHNL_ATT_BIT (1 << L2CAP_ATT_CID) + +/* BLE Signalling supported */ +#define L2CAP_FIXED_CHNL_BLE_SIG_BIT (1 << L2CAP_BLE_SIGNALLING_CID) + +/* BLE Security Mgr supported */ +#define L2CAP_FIXED_CHNL_SMP_BIT (1 << L2CAP_SMP_CID) + +/* Security Mgr over BR supported */ +#define L2CAP_FIXED_CHNL_SMP_BR_BIT (1 << L2CAP_SMP_BR_CID) + + + +/* Define the L2CAP configuration result codes +*/ +#define L2CAP_CFG_OK 0 +#define L2CAP_CFG_UNACCEPTABLE_PARAMS 1 +#define L2CAP_CFG_FAILED_NO_REASON 2 +#define L2CAP_CFG_UNKNOWN_OPTIONS 3 +#define L2CAP_CFG_PENDING 4 +#define L2CAP_CFG_FLOW_SPEC_REJECTED 5 + + +/* Define the L2CAP configuration option types +*/ +#define L2CAP_CFG_TYPE_MTU 0x01 +#define L2CAP_CFG_TYPE_FLUSH_TOUT 0x02 +#define L2CAP_CFG_TYPE_QOS 0x03 +#define L2CAP_CFG_TYPE_FCR 0x04 +#define L2CAP_CFG_TYPE_FCS 0x05 +#define L2CAP_CFG_TYPE_EXT_FLOW 0x06 +#define L2CAP_CFG_TYPE_EXT_WIN_SIZE 0x07 + +#define L2CAP_CFG_MTU_OPTION_LEN 2 /* MTU option length */ +#define L2CAP_CFG_FLUSH_OPTION_LEN 2 /* Flush option len */ +#define L2CAP_CFG_QOS_OPTION_LEN 22 /* QOS option length */ +#define L2CAP_CFG_FCR_OPTION_LEN 9 /* FCR option length */ +#define L2CAP_CFG_FCS_OPTION_LEN 1 /* FCR option length */ +#define L2CAP_CFG_EXT_FLOW_OPTION_LEN 16 /* Extended Flow Spec */ +#define L2CAP_CFG_EXT_WIN_SIZE_LEN 2 /* Ext window size length */ +#define L2CAP_CFG_OPTION_OVERHEAD 2 /* Type and length */ + +/* Configuration Cmd/Rsp Flags mask +*/ +#define L2CAP_CFG_FLAGS_MASK_CONT 0x0001 /* Flags mask: Continuation */ + +/* FCS Check Option values +*/ +#define L2CAP_CFG_FCS_BYPASS 0 /* Bypass the FCS in streaming or ERTM modes */ +#define L2CAP_CFG_FCS_USE 1 /* Use the FCS in streaming or ERTM modes [default] */ + +/* Default values for configuration +*/ +#define L2CAP_NO_AUTOMATIC_FLUSH 0xFFFF +#define L2CAP_NO_RETRANSMISSION 0x0001 + +#define L2CAP_DEFAULT_MTU (672) +#define L2CAP_DEFAULT_FLUSH_TO L2CAP_NO_AUTOMATIC_FLUSH +#define L2CAP_DEFAULT_SERV_TYPE 1 +#define L2CAP_DEFAULT_TOKEN_RATE 0 +#define L2CAP_DEFAULT_BUCKET_SIZE 0 +#define L2CAP_DEFAULT_PEAK_BANDWIDTH 0 +#define L2CAP_DEFAULT_LATENCY 0xFFFFFFFF +#define L2CAP_DEFAULT_DELAY 0xFFFFFFFF +#define L2CAP_DEFAULT_FCS L2CAP_CFG_FCS_USE + + +/* Define the L2CAP disconnect result codes +*/ +#define L2CAP_DISC_OK 0 +#define L2CAP_DISC_TIMEOUT 0xEEEE + +/* Define the L2CAP info resp result codes +*/ +#define L2CAP_INFO_RESP_RESULT_SUCCESS 0 +#define L2CAP_INFO_RESP_RESULT_NOT_SUPPORTED 1 + +/* Define the info-type fields of information request & response +*/ +#define L2CAP_CONNLESS_MTU_INFO_TYPE 0x0001 +#define L2CAP_EXTENDED_FEATURES_INFO_TYPE 0x0002 /* Used in Information Req/Response */ +#define L2CAP_FIXED_CHANNELS_INFO_TYPE 0x0003 /* Used in AMP */ + +#define L2CAP_CONNLESS_MTU_INFO_SIZE 2 /* Connectionless MTU size */ +#define L2CAP_EXTENDED_FEATURES_ARRAY_SIZE 4 /* Extended features array size */ +#define L2CAP_FIXED_CHNL_ARRAY_SIZE 8 /* Fixed channel array size */ + +/* Extended features mask bits +*/ +#define L2CAP_EXTFEA_RTRANS 0x00000001 /* Retransmission Mode (Not Supported) */ +#define L2CAP_EXTFEA_FC 0x00000002 /* Flow Control Mode (Not Supported) */ +#define L2CAP_EXTFEA_QOS 0x00000004 +#define L2CAP_EXTFEA_ENH_RETRANS 0x00000008 /* Enhanced retransmission mode */ +#define L2CAP_EXTFEA_STREAM_MODE 0x00000010 /* Streaming Mode */ +#define L2CAP_EXTFEA_NO_CRC 0x00000020 /* Optional FCS (if set No FCS desired) */ +#define L2CAP_EXTFEA_EXT_FLOW_SPEC 0x00000040 /* Extended flow spec */ +#define L2CAP_EXTFEA_FIXED_CHNLS 0x00000080 /* Fixed channels */ +#define L2CAP_EXTFEA_EXT_WINDOW 0x00000100 /* Extended Window Size */ +#define L2CAP_EXTFEA_UCD_RECEPTION 0x00000200 /* Unicast Connectionless Data Reception */ + +/* Mask for locally supported features used in Information Response (default to none) */ +#ifndef L2CAP_EXTFEA_SUPPORTED_MASK +#define L2CAP_EXTFEA_SUPPORTED_MASK 0 +#endif + +/* Mask for LE supported features used in Information Response (default to none) */ +#ifndef L2CAP_BLE_EXTFEA_MASK +#define L2CAP_BLE_EXTFEA_MASK 0 +#endif + +/* Define a value that tells L2CAP to use the default HCI ACL buffer pool */ +#define L2CAP_DEFAULT_ERM_POOL_ID 0xFF +/* Define a value that tells L2CAP to use the default MPS */ +#define L2CAP_DEFAULT_ERM_MPS 0x0000 + +#define L2CAP_FCR_OVERHEAD 2 /* Control word */ +#define L2CAP_FCS_LEN 2 /* FCS takes 2 bytes */ +#define L2CAP_SDU_LEN_OVERHEAD 2 /* SDU length field is 2 bytes */ +#define L2CAP_SDU_LEN_OFFSET 2 /* SDU length offset is 2 bytes */ +#define L2CAP_EXT_CONTROL_OVERHEAD 4 /* Extended Control Field */ +#define L2CAP_MAX_HEADER_FCS (L2CAP_PKT_OVERHEAD + L2CAP_EXT_CONTROL_OVERHEAD + L2CAP_SDU_LEN_OVERHEAD + L2CAP_FCS_LEN) +/* length(2), channel(2), control(4), SDU length(2) FCS(2) */ +/* To optimize this, it must be a multiplum of the L2CAP PDU length AND match the 3DH5 air + * including the l2cap headers in each packet - to match the latter - the -5 is added + */ +#define L2CAP_MAX_SDU_LENGTH (GKI_BUF4_SIZE - (L2CAP_MIN_OFFSET + L2CAP_MAX_HEADER_FCS) -5) + +/* Part of L2CAP_MIN_OFFSET that is not part of L2CAP +*/ +#define L2CAP_OFFSET_WO_L2HDR (L2CAP_MIN_OFFSET-(L2CAP_PKT_OVERHEAD+L2CAP_FCR_OVERHEAD)) + +/* SAR bits in the control word +*/ +#define L2CAP_FCR_UNSEG_SDU 0x0000 /* Control word to begin with for unsegmented PDU*/ +#define L2CAP_FCR_START_SDU 0x4000 /* ...for Starting PDU of a semented SDU */ +#define L2CAP_FCR_END_SDU 0x8000 /* ...for ending PDU of a segmented SDU */ +#define L2CAP_FCR_CONT_SDU 0xc000 /* ...for continuation PDU of a segmented SDU */ + +/* Supervisory frame types +*/ +#define L2CAP_FCR_SUP_RR 0x0000 /* Supervisory frame - RR */ +#define L2CAP_FCR_SUP_REJ 0x0001 /* Supervisory frame - REJ */ +#define L2CAP_FCR_SUP_RNR 0x0002 /* Supervisory frame - RNR */ +#define L2CAP_FCR_SUP_SREJ 0x0003 /* Supervisory frame - SREJ */ + +#define L2CAP_FCR_SAR_BITS 0xC000 /* Mask to get the SAR bits from control word */ +#define L2CAP_FCR_SAR_BITS_SHIFT 14 /* Bits to shift right to get the SAR bits from ctrl-word */ + +#define L2CAP_FCR_S_FRAME_BIT 0x0001 /* Mask to check if a PDU is S-frame */ +#define L2CAP_FCR_REQ_SEQ_BITS 0x3F00 /* Mask to get the req-seq from control word */ +#define L2CAP_FCR_REQ_SEQ_BITS_SHIFT 8 /* Bits to shift right to get the req-seq from ctrl-word */ +#define L2CAP_FCR_TX_SEQ_BITS 0x007E /* Mask on get the tx-seq from control word */ +#define L2CAP_FCR_TX_SEQ_BITS_SHIFT 1 /* Bits to shift right to get the tx-seq from ctrl-word */ + +#define L2CAP_FCR_F_BIT 0x0080 /* F-bit in the control word (Sup and I frames) */ +#define L2CAP_FCR_P_BIT 0x0010 /* P-bit in the control word (Sup frames only) */ + +#define L2CAP_FCR_F_BIT_SHIFT 7 +#define L2CAP_FCR_P_BIT_SHIFT 4 + +#define L2CAP_FCR_SEG_BITS 0xC000 /* Mask to get the segmentation bits from ctrl-word */ +#define L2CAP_FCR_SUP_SHIFT 2 /* Bits to shift right to get the S-bits from ctrl-word */ +#define L2CAP_FCR_SUP_BITS 0x000C /* Mask to get the supervisory bits from ctrl-word */ + +#define L2CAP_FCR_INIT_CRC 0 /* Initial state of the CRC register */ +#define L2CAP_FCR_SEQ_MODULO 0x3F /* Mask for sequence numbers (range 0 - 63) */ + +#endif diff --git a/tools/sdk/include/bluedroid/list.h b/tools/sdk/include/bluedroid/list.h new file mode 100755 index 00000000..77097967 --- /dev/null +++ b/tools/sdk/include/bluedroid/list.h @@ -0,0 +1,110 @@ +#ifndef _LIST_H_ +#define _LIST_H_ + +#include +#include +struct list_node_t; +typedef struct list_node_t list_node_t; + +struct list_t; +typedef struct list_t list_t; + +typedef void (*list_free_cb)(void *data); +typedef bool (*list_iter_cb)(void *data); + +// Returns a new, empty list. Returns NULL if not enough memory could be allocated +// for the list structure. The returned list must be freed with |list_free|. The +// |callback| specifies a function to be called whenever a list element is removed +// from the list. It can be used to release resources held by the list element, e.g. +// memory or file descriptor. |callback| may be NULL if no cleanup is necessary on +// element removal. +list_t *list_new(list_free_cb callback); + + +list_node_t *list_free_node(list_t *list, list_node_t *node); +//list_node_t *list_free_node(list_t *list, list_node_t *node); +// Frees the list. This function accepts NULL as an argument, in which case it +// behaves like a no-op. +void list_free(list_t *list); + +// Returns true if |list| is empty (has no elements), false otherwise. +// |list| may not be NULL. +bool list_is_empty(const list_t *list); + +// Returns true if the list contains |data|, false otherwise. +// |list| may not be NULL. +bool list_contains(const list_t *list, const void *data); + +// Returns the length of the |list|. |list| may not be NULL. +size_t list_length(const list_t *list); + +// Returns the first element in the list without removing it. |list| may not +// be NULL or empty. +void *list_front(const list_t *list); + +// Returns the last element in the list without removing it. |list| may not +// be NULL or empty. +//void *list_back(const list_t *list); + +// Inserts |data| after |prev_node| in |list|. |data|, |list|, and |prev_node| +// may not be NULL. This function does not make a copy of |data| so the pointer +// must remain valid at least until the element is removed from the list or the +// list is freed. Returns true if |data| could be inserted, false otherwise +// (e.g. out of memory). +bool list_insert_after(list_t *list, list_node_t *prev_node, void *data); + +// Inserts |data| at the beginning of |list|. Neither |data| nor |list| may be NULL. +// This function does not make a copy of |data| so the pointer must remain valid +// at least until the element is removed from the list or the list is freed. +// Returns true if |data| could be inserted, false otherwise (e.g. out of memory). +bool list_prepend(list_t *list, void *data); + +// Inserts |data| at the end of |list|. Neither |data| nor |list| may be NULL. +// This function does not make a copy of |data| so the pointer must remain valid +// at least until the element is removed from the list or the list is freed. +// Returns true if |data| could be inserted, false otherwise (e.g. out of memory). +bool list_append(list_t *list, void *data); + +// Removes |data| from the list. Neither |list| nor |data| may be NULL. If |data| +// is inserted multiple times in the list, this function will only remove the first +// instance. If a free function was specified in |list_new|, it will be called back +// with |data|. This function returns true if |data| was found in the list and removed, +// false otherwise. +//list_node_t list_remove_node(list_t *list, list_node_t *prev_node, list_node_t *node); +//list_node_t list_insert_node(list_t *list, list_node_t *prev_node, list_node_t *node); + +bool list_remove(list_t *list, void *data); + +// Removes all elements in the list. Calling this function will return the list to the +// same state it was in after |list_new|. |list| may not be NULL. +void list_clear(list_t *list); + +// Iterates through the entire |list| and calls |callback| for each data element. +// If the list is empty, |callback| will never be called. It is safe to mutate the +// list inside the callback. If an element is added before the node being visited, +// there will be no callback for the newly-inserted node. Neither |list| nor +// |callback| may be NULL. +void list_foreach(const list_t *list, list_iter_cb callback); + +// Returns an iterator to the first element in |list|. |list| may not be NULL. +// The returned iterator is valid as long as it does not equal the value returned +// by |list_end|. +list_node_t *list_begin(const list_t *list); + +// Returns an iterator that points past the end of the list. In other words, +// this function returns the value of an invalid iterator for the given list. +// When an iterator has the same value as what's returned by this function, you +// may no longer call |list_next| with the iterator. |list| may not be NULL. +list_node_t *list_end(const list_t *list); + +// Given a valid iterator |node|, this function returns the next value for the +// iterator. If the returned value equals the value returned by |list_end|, the +// iterator has reached the end of the list and may no longer be used for any +// purpose. +list_node_t *list_next(const list_node_t *node); + +// Returns the value stored at the location pointed to by the iterator |node|. +// |node| must not equal the value returned by |list_end|. +void *list_node(const list_node_t *node); + +#endif /* _LIST_H_ */ diff --git a/tools/sdk/include/bluedroid/osi.h b/tools/sdk/include/bluedroid/osi.h new file mode 100755 index 00000000..3308255b --- /dev/null +++ b/tools/sdk/include/bluedroid/osi.h @@ -0,0 +1,26 @@ + +#ifndef _OSI_H_ +#define _OSI_H_ + +#include +#include + +#define UNUSED_ATTR __attribute__((unused)) +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) +#define INVALID_FD (-1) + +#define CONCAT(a, b) a##b + +// Use during compile time to check conditional values +// NOTE: The the failures will present as a generic error +// "error: initialization makes pointer from integer without a cast" +// but the file and line number will present the condition that +// failed. +#define DUMMY_COUNTER(c) CONCAT(__osi_dummy_, c) +#define DUMMY_PTR DUMMY_COUNTER(__COUNTER__) + +#define COMPILE_ASSERT(x) char * DUMMY_PTR = !(x) + +typedef uint32_t timeout_t; + +#endif /*_OSI_H_*/ diff --git a/tools/sdk/include/bluedroid/osi_arch.h b/tools/sdk/include/bluedroid/osi_arch.h new file mode 100755 index 00000000..491d4829 --- /dev/null +++ b/tools/sdk/include/bluedroid/osi_arch.h @@ -0,0 +1,45 @@ +#ifndef __os_ARCH_H__ +#define __os_ARCH_H__ + +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "freertos/queue.h" +#include "freertos/semphr.h" + +#define OSI_ARCH_TIMEOUT 0xffffffffUL + +typedef xSemaphoreHandle osi_sem_t; +typedef xSemaphoreHandle osi_mutex_t; + +#define osi_mutex_valid( x ) ( ( ( *x ) == NULL) ? pdFALSE : pdTRUE ) +#define osi_mutex_set_invalid( x ) ( ( *x ) = NULL ) +#define osi_sem_valid( x ) ( ( ( *x ) == NULL) ? pdFALSE : pdTRUE ) +#define osi_sem_set_invalid( x ) ( ( *x ) = NULL ) + +int osi_mutex_new(osi_mutex_t *pxMutex); + +void osi_mutex_lock(osi_mutex_t *pxMutex); + +int osi_mutex_trylock(osi_mutex_t *pxMutex); + +void osi_mutex_unlock(osi_mutex_t *pxMutex); + +void osi_mutex_free(osi_mutex_t *pxMutex); + +int osi_sem_new(osi_sem_t *sem, uint32_t max_count, uint32_t init_count); + +void osi_sem_signal(osi_sem_t *sem); + +uint32_t osi_sem_wait(osi_sem_t *sem, uint32_t timeout); + +void osi_sem_free(osi_sem_t *sem); + +void osi_arch_init(void); + +uint32_t osi_now(void); + +void osi_delay_ms(uint32_t ms); + + +#endif /* __os_ARCH_H__ */ + diff --git a/tools/sdk/include/bluedroid/p_256_ecc_pp.h b/tools/sdk/include/bluedroid/p_256_ecc_pp.h new file mode 100644 index 00000000..029a79ff --- /dev/null +++ b/tools/sdk/include/bluedroid/p_256_ecc_pp.h @@ -0,0 +1,65 @@ +/****************************************************************************** + * + * Copyright (C) 2006-2015 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 file contains simple pairing algorithms using Elliptic Curve Cryptography for private public key + * + ******************************************************************************/ + +#pragma once + +#include "p_256_multprecision.h" + +typedef unsigned long DWORD; + +typedef struct { + DWORD x[KEY_LENGTH_DWORDS_P256]; + DWORD y[KEY_LENGTH_DWORDS_P256]; + DWORD z[KEY_LENGTH_DWORDS_P256]; +} Point; + +typedef struct { + // curve's coefficients + DWORD a[KEY_LENGTH_DWORDS_P256]; + DWORD b[KEY_LENGTH_DWORDS_P256]; + + //whether a is -3 + int a_minus3; + + // prime modulus + DWORD p[KEY_LENGTH_DWORDS_P256]; + + // Omega, p = 2^m -omega + DWORD omega[KEY_LENGTH_DWORDS_P256]; + + // base point, a point on E of order r + Point G; + +} elliptic_curve_t; + +extern elliptic_curve_t curve; +extern elliptic_curve_t curve_p256; + +void ECC_PointMult_Bin_NAF(Point *q, Point *p, DWORD *n, uint32_t keyLength); + +#define ECC_PointMult(q, p, n, keyLength) ECC_PointMult_Bin_NAF(q, p, n, keyLength) + +void p_256_init_curve(UINT32 keyLength); + + diff --git a/tools/sdk/include/bluedroid/p_256_multprecision.h b/tools/sdk/include/bluedroid/p_256_multprecision.h new file mode 100644 index 00000000..ac32320a --- /dev/null +++ b/tools/sdk/include/bluedroid/p_256_multprecision.h @@ -0,0 +1,62 @@ +/****************************************************************************** + * + * Copyright (C) 2006-2015 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 file contains simple pairing algorithms + * + ******************************************************************************/ +#pragma once + +#include "bt_types.h" + +/* Type definitions */ +typedef unsigned long DWORD; + +#define DWORD_BITS 32 +#define DWORD_BYTES 4 +#define DWORD_BITS_SHIFT 5 + +#define KEY_LENGTH_DWORDS_P192 6 +#define KEY_LENGTH_DWORDS_P256 8 +/* Arithmetic Operations */ + +int multiprecision_compare(DWORD *a, DWORD *b, uint32_t keyLength); +int multiprecision_iszero(DWORD *a, uint32_t keyLength); +void multiprecision_init(DWORD *c, uint32_t keyLength); +void multiprecision_copy(DWORD *c, DWORD *a, uint32_t keyLength); +UINT32 multiprecision_dword_bits (DWORD a); +UINT32 multiprecision_most_signdwords(DWORD *a, uint32_t keyLength); +UINT32 multiprecision_most_signbits(DWORD *a, uint32_t keyLength); +void multiprecision_inv_mod(DWORD *aminus, DWORD *a, uint32_t keyLength); +DWORD multiprecision_add(DWORD *c, DWORD *a, DWORD *b, uint32_t keyLength); // c=a+b +void multiprecision_add_mod(DWORD *c, DWORD *a, DWORD *b, uint32_t keyLength); +DWORD multiprecision_sub(DWORD *c, DWORD *a, DWORD *b, uint32_t keyLength); // c=a-b +void multiprecision_sub_mod(DWORD *c, DWORD *a, DWORD *b, uint32_t keyLength); +void multiprecision_rshift(DWORD *c, DWORD *a, uint32_t keyLength); // c=a>>1, return carrier +void multiprecision_lshift_mod(DWORD *c, DWORD *a, uint32_t keyLength); // c=a<> RFCOMM_SHIFT_CR; \ + dlci = *p_data++ >> RFCOMM_SHIFT_DLCI; \ + if (!ea) dlci += *p_data++ << RFCOMM_SHIFT_DLCI2; \ +} + +#define RFCOMM_FORMAT_CTRL_FIELD(p_data, ea, cr, dlci) \ + *p_data++ = ea | cr | (dlci << RFCOMM_SHIFT_DLCI) + +#define RFCOMM_PARSE_TYPE_FIELD(type, pf, p_data) \ +{ \ + type = *p_data & ~RFCOMM_PF_MASK; \ + pf = (*p_data++ & RFCOMM_PF_MASK) >> RFCOMM_PF_OFFSET;\ +} + +#define RFCOMM_FORMAT_TYPE_FIELD(p_data, type, pf) \ + *p_data++ = (type | (pf << RFCOMM_PF_OFFSET)) \ +{ \ + type = *p_data & ~RFCOMM_PF_MASK; \ + pf = (*p_data++ & RFCOMM_PF_MASK) >> RFCOMM_PF_OFFSET;\ +} + +#define RFCOMM_PARSE_LEN_FIELD(ea, length, p_data) \ +{ \ + ea = (*p_data & RFCOMM_EA); \ + length = (*p_data++ >> RFCOMM_SHIFT_LENGTH1); \ + if (!ea) length += (*p_data++ << RFCOMM_SHIFT_LENGTH2); \ +} + +#define RFCOMM_FRAME_IS_CMD(initiator, cr) \ + (( (initiator) && !(cr)) || (!(initiator) && (cr))) + +#define RFCOMM_FRAME_IS_RSP(initiator, cr) \ + (( (initiator) && (cr)) || (!(initiator) && !(cr))) + +#define RFCOMM_CR(initiator, is_command) \ + (( ( (initiator) && (is_command)) \ + || (!(initiator) && !(is_command))) << 1) + +#define RFCOMM_I_CR(is_command) ((is_command) ? 0x02 : 0x00) + +#define RFCOMM_MAX_DLCI 61 + +#define RFCOMM_VALID_DLCI(dlci) \ + (((dlci) == 0) || (((dlci) >= 2) && ((dlci) <= RFCOMM_MAX_DLCI))) + + +/* Port Negotiation (PN) */ +#define RFCOMM_PN_DLCI_MASK 0x3F + +#define RFCOMM_PN_FRAM_TYPE_UIH 0x00 +#define RFCOMM_PN_FRAME_TYPE_MASK 0x0F + +#define RFCOMM_PN_CONV_LAYER_MASK 0xF0 +#define RFCOMM_PN_CONV_LAYER_TYPE_1 0 +#define RFCOMM_PN_CONV_LAYER_CBFC_I 0xF0 +#define RFCOMM_PN_CONV_LAYER_CBFC_R 0xE0 + +#define RFCOMM_PN_PRIORITY_MASK 0x3F +#define RFCOMM_PN_PRIORITY_0 0 + +#define RFCOMM_PN_K_MASK 0x07 + +#define RFCOMM_T1_DSEC 0 /* None negotiable in RFCOMM */ +#define RFCOMM_N2 0 /* Number of retransmissions */ +#define RFCOMM_K 0 /* Window size */ +#define RFCOMM_K_MAX 7 /* Max value of K for credit based flow control */ + +#define RFCOMM_MSC_FC 0x02 /* Flow control*/ +#define RFCOMM_MSC_RTC 0x04 /* Ready to communicate*/ +#define RFCOMM_MSC_RTR 0x08 /* Ready to receive*/ +#define RFCOMM_MSC_IC 0x40 /* Incomming call indicator*/ +#define RFCOMM_MSC_DV 0x80 /* Data Valid*/ + +#define RFCOMM_MSC_SHIFT_BREAK 4 +#define RFCOMM_MSC_BREAK_MASK 0xF0 +#define RFCOMM_MSC_BREAK_PRESENT_MASK 0x02 + +#define RFCOMM_BAUD_RATE_2400 0x00 +#define RFCOMM_BAUD_RATE_4800 0x01 +#define RFCOMM_BAUD_RATE_7200 0x02 +#define RFCOMM_BAUD_RATE_9600 0x03 +#define RFCOMM_BAUD_RATE_19200 0x04 +#define RFCOMM_BAUD_RATE_38400 0x05 +#define RFCOMM_BAUD_RATE_57600 0x06 +#define RFCOMM_BAUD_RATE_115200 0x07 +#define RFCOMM_BAUD_RATE_230400 0x08 + +#define RFCOMM_5_BITS 0x00 +#define RFCOMM_6_BITS 0x01 +#define RFCOMM_7_BITS 0x02 +#define RFCOMM_8_BITS 0x03 + +#define RFCOMM_RPN_BITS_MASK 0x03 +#define RFCOMM_RPN_BITS_SHIFT 0 + +#define RFCOMM_ONESTOPBIT 0x00 +#define RFCOMM_ONE5STOPBITS 0x01 + +#define RFCOMM_RPN_STOP_BITS_MASK 0x01 +#define RFCOMM_RPN_STOP_BITS_SHIFT 2 + +#define RFCOMM_PARITY_NO 0x00 +#define RFCOMM_PARITY_YES 0x01 +#define RFCOMM_RPN_PARITY_MASK 0x01 +#define RFCOMM_RPN_PARITY_SHIFT 3 + +#define RFCOMM_ODD_PARITY 0x00 +#define RFCOMM_EVEN_PARITY 0x01 +#define RFCOMM_MARK_PARITY 0x02 +#define RFCOMM_SPACE_PARITY 0x03 + +#define RFCOMM_RPN_PARITY_TYPE_MASK 0x03 +#define RFCOMM_RPN_PARITY_TYPE_SHIFT 4 + +#define RFCOMM_FC_OFF 0x00 +#define RFCOMM_FC_XONXOFF_ON_INPUT 0x01 +#define RFCOMM_FC_XONXOFF_ON_OUTPUT 0x02 +#define RFCOMM_FC_RTR_ON_INPUT 0x04 +#define RFCOMM_FC_RTR_ON_OUTPUT 0x08 +#define RFCOMM_FC_RTC_ON_INPUT 0x10 +#define RFCOMM_FC_RTC_ON_OUTPUT 0x20 +#define RFCOMM_FC_MASK 0x3F + +#define RFCOMM_RPN_PM_BIT_RATE 0x0001 +#define RFCOMM_RPN_PM_DATA_BITS 0x0002 +#define RFCOMM_RPN_PM_STOP_BITS 0x0004 +#define RFCOMM_RPN_PM_PARITY 0x0008 +#define RFCOMM_RPN_PM_PARITY_TYPE 0x0010 +#define RFCOMM_RPN_PM_XON_CHAR 0x0020 +#define RFCOMM_RPN_PM_XOFF_CHAR 0x0040 +#define RFCOMM_RPN_PM_XONXOFF_ON_INPUT 0x0100 +#define RFCOMM_RPN_PM_XONXOFF_ON_OUTPUT 0x0200 +#define RFCOMM_RPN_PM_RTR_ON_INPUT 0x0400 +#define RFCOMM_RPN_PM_RTR_ON_OUTPUT 0x0800 +#define RFCOMM_RPN_PM_RTC_ON_INPUT 0x1000 +#define RFCOMM_RPN_PM_RTC_ON_OUTPUT 0x2000 +#define RFCOMM_RPN_PM_MASK 0x3F7F + +#define RFCOMM_RLS_ERROR 0x01 +#define RFCOMM_RLS_OVERRUN 0x02 +#define RFCOMM_RLS_PARITY 0x04 +#define RFCOMM_RLS_FRAMING 0x08 + +/* Multiplexor channel uses DLCI 0 */ +#define RFCOMM_MX_DLCI 0 + +/* +** Define RFCOMM Multiplexer message types +*/ +#define RFCOMM_MX_PN 0x80 +#define RFCOMM_MX_PN_LEN 8 + +#define RFCOMM_MX_CLD 0xC0 +#define RFCOMM_MX_CLD_LEN 0 + +#define RFCOMM_MX_TEST 0x20 + +#define RFCOMM_MX_FCON 0xA0 +#define RFCOMM_MX_FCON_LEN 0 + +#define RFCOMM_MX_FCOFF 0x60 +#define RFCOMM_MX_FCOFF_LEN 0 + +#define RFCOMM_MX_MSC 0xE0 +#define RFCOMM_MX_MSC_LEN_NO_BREAK 2 +#define RFCOMM_MX_MSC_LEN_WITH_BREAK 3 + +#define RFCOMM_MX_NSC 0x10 +#define RFCOMM_MX_NSC_LEN 1 + +#define RFCOMM_MX_RPN 0x90 +#define RFCOMM_MX_RPN_REQ_LEN 1 +#define RFCOMM_MX_RPN_LEN 8 + +#define RFCOMM_MX_RLS 0x50 +#define RFCOMM_MX_RLS_LEN 2 +#endif diff --git a/tools/sdk/include/bluedroid/sdp_api.h b/tools/sdk/include/bluedroid/sdp_api.h new file mode 100644 index 00000000..c35c1243 --- /dev/null +++ b/tools/sdk/include/bluedroid/sdp_api.h @@ -0,0 +1,724 @@ +/****************************************************************************** + * + * Copyright (C) 1999-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. + * + ******************************************************************************/ +#ifndef SDP_API_H +#define SDP_API_H + +#include "bt_target.h" +#include "sdpdefs.h" + +/***************************************************************************** +** Constants +*****************************************************************************/ + +/* Success code and error codes */ +#define SDP_SUCCESS 0x0000 +#define SDP_INVALID_VERSION 0x0001 +#define SDP_INVALID_SERV_REC_HDL 0x0002 +#define SDP_INVALID_REQ_SYNTAX 0x0003 +#define SDP_INVALID_PDU_SIZE 0x0004 +#define SDP_INVALID_CONT_STATE 0x0005 +#define SDP_NO_RESOURCES 0x0006 +#define SDP_DI_REG_FAILED 0x0007 +#define SDP_DI_DISC_FAILED 0x0008 +#define SDP_NO_DI_RECORD_FOUND 0x0009 +#define SDP_ERR_ATTR_NOT_PRESENT 0x000A +#define SDP_ILLEGAL_PARAMETER 0x000B + +#define SDP_NO_RECS_MATCH 0xFFF0 +#define SDP_CONN_FAILED 0xFFF1 +#define SDP_CFG_FAILED 0xFFF2 +#define SDP_GENERIC_ERROR 0xFFF3 +#define SDP_DB_FULL 0xFFF4 +#define SDP_INVALID_PDU 0xFFF5 +#define SDP_SECURITY_ERR 0xFFF6 +#define SDP_CONN_REJECTED 0xFFF7 +#define SDP_CANCEL 0xFFF8 + +/* Define the PSM that SDP uses */ +#define SDP_PSM 0x0001 + +/* Legacy #define to avoid code changes - SDP UUID is same as BT UUID */ +#define tSDP_UUID tBT_UUID + +/* Masks for attr_value field of tSDP_DISC_ATTR */ +#define SDP_DISC_ATTR_LEN_MASK 0x0FFF +#define SDP_DISC_ATTR_TYPE(len_type) (len_type >> 12) +#define SDP_DISC_ATTR_LEN(len_type) (len_type & SDP_DISC_ATTR_LEN_MASK) + +/* Maximum number of protocol list items (list_elem in tSDP_PROTOCOL_ELEM) */ +#define SDP_MAX_LIST_ELEMS 3 + + +/***************************************************************************** +** Type Definitions +*****************************************************************************/ + +/* Define a callback function for when discovery is complete. */ +typedef void (tSDP_DISC_CMPL_CB) (UINT16 result); +typedef void (tSDP_DISC_CMPL_CB2) (UINT16 result, void *user_data); + +typedef struct { + BD_ADDR peer_addr; + UINT16 peer_mtu; +} tSDP_DR_OPEN; + +typedef struct { + UINT8 *p_data; + UINT16 data_len; +} tSDP_DR_DATA; + +typedef union { + tSDP_DR_OPEN open; + tSDP_DR_DATA data; +} tSDP_DATA; + +/* Define a callback function for when discovery result is received. */ +typedef void (tSDP_DISC_RES_CB) (UINT16 event, tSDP_DATA *p_data); + +/* Define a structure to hold the discovered service information. */ +typedef struct { + union { + UINT8 u8; /* 8-bit integer */ + UINT16 u16; /* 16-bit integer */ + UINT32 u32; /* 32-bit integer */ + UINT8 array[4]; /* Variable length field */ + struct t_sdp_disc_attr *p_sub_attr; /* Addr of first sub-attr (list)*/ + } v; + +} tSDP_DISC_ATVAL; + +typedef struct t_sdp_disc_attr { + struct t_sdp_disc_attr *p_next_attr; /* Addr of next linked attr */ + UINT16 attr_id; /* Attribute ID */ + UINT16 attr_len_type; /* Length and type fields */ + tSDP_DISC_ATVAL attr_value; /* Variable length entry data */ +} tSDP_DISC_ATTR; + +typedef struct t_sdp_disc_rec { + tSDP_DISC_ATTR *p_first_attr; /* First attribute of record */ + struct t_sdp_disc_rec *p_next_rec; /* Addr of next linked record */ + UINT32 time_read; /* The time the record was read */ + BD_ADDR remote_bd_addr; /* Remote BD address */ +} tSDP_DISC_REC; + +typedef struct { + UINT32 mem_size; /* Memory size of the DB */ + UINT32 mem_free; /* Memory still available */ + tSDP_DISC_REC *p_first_rec; /* Addr of first record in DB */ + UINT16 num_uuid_filters; /* Number of UUIds to filter */ + tSDP_UUID uuid_filters[SDP_MAX_UUID_FILTERS]; /* UUIDs to filter */ + UINT16 num_attr_filters; /* Number of attribute filters */ + UINT16 attr_filters[SDP_MAX_ATTR_FILTERS]; /* Attributes to filter */ + UINT8 *p_free_mem; /* Pointer to free memory */ +#if (SDP_RAW_DATA_INCLUDED == TRUE) + UINT8 *raw_data; /* Received record from server. allocated/released by client */ + UINT32 raw_size; /* size of raw_data */ + UINT32 raw_used; /* length of raw_data used */ +#endif +} tSDP_DISCOVERY_DB; + +/* This structure is used to add protocol lists and find protocol elements */ +typedef struct { + UINT16 protocol_uuid; + UINT16 num_params; + UINT16 params[SDP_MAX_PROTOCOL_PARAMS]; +} tSDP_PROTOCOL_ELEM; + +typedef struct { + UINT16 num_elems; + tSDP_PROTOCOL_ELEM list_elem[SDP_MAX_LIST_ELEMS]; +} tSDP_PROTO_LIST_ELEM; + +/* Device Identification (DI) data structure +*/ +/* Used to set the DI record */ +typedef struct t_sdp_di_record { + UINT16 vendor; + UINT16 vendor_id_source; + UINT16 product; + UINT16 version; + BOOLEAN primary_record; + char client_executable_url[SDP_MAX_ATTR_LEN]; /* optional */ + char service_description[SDP_MAX_ATTR_LEN]; /* optional */ + char documentation_url[SDP_MAX_ATTR_LEN]; /* optional */ +} tSDP_DI_RECORD; + +/* Used to get the DI record */ +typedef struct t_sdp_di_get_record { + UINT16 spec_id; + tSDP_DI_RECORD rec; +} tSDP_DI_GET_RECORD; + + +/***************************************************************************** +** External Function Declarations +*****************************************************************************/ +#ifdef __cplusplus +extern "C" +{ +#endif + +/* API into the SDP layer for service discovery. */ + +/******************************************************************************* +** +** Function SDP_InitDiscoveryDb +** +** Description This function is called to initialize a discovery database. +** +** Returns TRUE if successful, FALSE if one or more parameters are bad +** +*******************************************************************************/ +extern BOOLEAN SDP_InitDiscoveryDb (tSDP_DISCOVERY_DB *p_db, UINT32 len, + UINT16 num_uuid, + tSDP_UUID *p_uuid_list, + UINT16 num_attr, + UINT16 *p_attr_list); + +/******************************************************************************* +** +** Function SDP_CancelServiceSearch +** +** Description This function cancels an active query to an SDP server. +** +** Returns TRUE if discovery cancelled, FALSE if a matching activity is not found. +** +*******************************************************************************/ +extern BOOLEAN SDP_CancelServiceSearch (tSDP_DISCOVERY_DB *p_db); + +/******************************************************************************* +** +** Function SDP_ServiceSearchRequest +** +** Description This function queries an SDP server for information. +** +** Returns TRUE if discovery started, FALSE if failed. +** +*******************************************************************************/ +extern BOOLEAN SDP_ServiceSearchRequest (UINT8 *p_bd_addr, + tSDP_DISCOVERY_DB *p_db, + tSDP_DISC_CMPL_CB *p_cb); + + +/******************************************************************************* +** +** Function SDP_ServiceSearchAttributeRequest +** +** Description This function queries an SDP server for information. +** +** The difference between this API function and the function +** SDP_ServiceSearchRequest is that this one does a +** combined ServiceSearchAttributeRequest SDP function. +** +** Returns TRUE if discovery started, FALSE if failed. +** +*******************************************************************************/ +extern BOOLEAN SDP_ServiceSearchAttributeRequest (UINT8 *p_bd_addr, + tSDP_DISCOVERY_DB *p_db, + tSDP_DISC_CMPL_CB *p_cb); + +/******************************************************************************* +** +** Function SDP_ServiceSearchAttributeRequest2 +** +** Description This function queries an SDP server for information. +** +** The difference between this API function and the function +** SDP_ServiceSearchRequest is that this one does a +** combined ServiceSearchAttributeRequest SDP function with the +** user data piggyback +** +** Returns TRUE if discovery started, FALSE if failed. +** +*******************************************************************************/ +extern BOOLEAN SDP_ServiceSearchAttributeRequest2 (UINT8 *p_bd_addr, + tSDP_DISCOVERY_DB *p_db, + tSDP_DISC_CMPL_CB2 *p_cb, void *user_data); + +/* API of utilities to find data in the local discovery database */ + +/******************************************************************************* +** +** Function SDP_FindAttributeInDb +** +** Description This function queries an SDP database for a specific attribute. +** If the p_start_rec pointer is NULL, it looks from the beginning +** of the database, else it continues from the next record after +** p_start_rec. +** +** Returns Pointer to matching record, or NULL +** +*******************************************************************************/ +extern tSDP_DISC_REC *SDP_FindAttributeInDb (tSDP_DISCOVERY_DB *p_db, + UINT16 attr_id, + tSDP_DISC_REC *p_start_rec); + + +/******************************************************************************* +** +** Function SDP_FindAttributeInRec +** +** Description This function searches an SDP discovery record for a +** specific attribute. +** +** Returns Pointer to matching attribute entry, or NULL +** +*******************************************************************************/ +extern tSDP_DISC_ATTR *SDP_FindAttributeInRec (tSDP_DISC_REC *p_rec, + UINT16 attr_id); + + +/******************************************************************************* +** +** Function SDP_FindServiceInDb +** +** Description This function queries an SDP database for a specific service. +** If the p_start_rec pointer is NULL, it looks from the beginning +** of the database, else it continues from the next record after +** p_start_rec. +** +** Returns Pointer to record containing service class, or NULL +** +*******************************************************************************/ +extern tSDP_DISC_REC *SDP_FindServiceInDb (tSDP_DISCOVERY_DB *p_db, + UINT16 service_uuid, + tSDP_DISC_REC *p_start_rec); + + +/******************************************************************************* +** +** Function SDP_FindServiceUUIDInDb +** +** Description This function queries an SDP database for a specific service. +** If the p_start_rec pointer is NULL, it looks from the beginning +** of the database, else it continues from the next record after +** p_start_rec. +** +** NOTE the only difference between this function and the previous +** function "SDP_FindServiceInDb()" is that this function takes +** a tBT_UUID input. +** +** Returns Pointer to record containing service class, or NULL +** +*******************************************************************************/ +extern tSDP_DISC_REC *SDP_FindServiceUUIDInDb (tSDP_DISCOVERY_DB *p_db, + tBT_UUID *p_uuid, + tSDP_DISC_REC *p_start_rec); + +/******************************************************************************* +** +** Function SDP_FindServiceUUIDInRec_128bit +** +** Description This function is called to read the 128-bit service UUID within a record +** if there is any. +** +** Parameters: p_rec - pointer to a SDP record. +** p_uuid - output parameter to save the UUID found. +** +** Returns TRUE if found, otherwise FALSE. +** +*******************************************************************************/ +extern BOOLEAN SDP_FindServiceUUIDInRec_128bit(tSDP_DISC_REC *p_rec, tBT_UUID *p_uuid); + +/******************************************************************************* +** +** Function SDP_FindServiceInDb_128bit +** +** Description This function queries an SDP database for a specific service. +** If the p_start_rec pointer is NULL, it looks from the beginning +** of the database, else it continues from the next record after +** p_start_rec. +** +** Returns Pointer to record containing service class, or NULL +** +*******************************************************************************/ +extern tSDP_DISC_REC *SDP_FindServiceInDb_128bit(tSDP_DISCOVERY_DB *p_db, + tSDP_DISC_REC *p_start_rec); + +/******************************************************************************* +** +** Function SDP_FindProtocolListElemInRec +** +** Description This function looks at a specific discovery record for a +** protocol list element. +** +** Returns TRUE if found, FALSE if not +** If found, the passed protocol list element is filled in. +** +*******************************************************************************/ +extern BOOLEAN SDP_FindProtocolListElemInRec (tSDP_DISC_REC *p_rec, + UINT16 layer_uuid, + tSDP_PROTOCOL_ELEM *p_elem); + + +/******************************************************************************* +** +** Function SDP_FindAddProtoListsElemInRec +** +** Description This function looks at a specific discovery record for a +** protocol list element. +** +** Returns TRUE if found, FALSE if not +** If found, the passed protocol list element is filled in. +** +*******************************************************************************/ +extern BOOLEAN SDP_FindAddProtoListsElemInRec (tSDP_DISC_REC *p_rec, + UINT16 layer_uuid, + tSDP_PROTOCOL_ELEM *p_elem); + + +/******************************************************************************* +** +** Function SDP_FindProfileVersionInRec +** +** Description This function looks at a specific discovery record for the +** Profile list descriptor, and pulls out the version number. +** The version number consists of an 8-bit major version and +** an 8-bit minor version. +** +** Returns TRUE if found, FALSE if not +** If found, the major and minor version numbers that were passed +** in are filled in. +** +*******************************************************************************/ +extern BOOLEAN SDP_FindProfileVersionInRec (tSDP_DISC_REC *p_rec, + UINT16 profile_uuid, + UINT16 *p_version); + + +/* API into SDP for local service database updates */ + +/******************************************************************************* +** +** Function SDP_CreateRecord +** +** Description This function is called to create a record in the database. +** This would be through the SDP database maintenance API. The +** record is created empty, teh application should then call +** "add_attribute" to add the record's attributes. +** +** Returns Record handle if OK, else 0. +** +*******************************************************************************/ +extern UINT32 SDP_CreateRecord (void); + + +/******************************************************************************* +** +** Function SDP_DeleteRecord +** +** Description This function is called to add a record (or all records) +** from the database. This would be through the SDP database +** maintenance API. +** +** If a record handle of 0 is passed, all records are deleted. +** +** Returns TRUE if succeeded, else FALSE +** +*******************************************************************************/ +extern BOOLEAN SDP_DeleteRecord (UINT32 handle); + + +/******************************************************************************* +** +** Function SDP_ReadRecord +** +** Description This function is called to get the raw data of the record +** with the given handle from the database. +** +** Returns -1, if the record is not found. +** Otherwise, the offset (0 or 1) to start of data in p_data. +** +** The size of data copied into p_data is in *p_data_len. +** +*******************************************************************************/ +extern INT32 SDP_ReadRecord(UINT32 handle, UINT8 *p_data, INT32 *p_data_len); + +/******************************************************************************* +** +** Function SDP_AddAttribute +** +** Description This function is called to add an attribute to a record. +** This would be through the SDP database maintenance API. +** If the attribute already exists in the record, it is replaced +** with the new value. +** +** NOTE Attribute values must be passed as a Big Endian stream. +** +** Returns TRUE if added OK, else FALSE +** +*******************************************************************************/ +extern BOOLEAN SDP_AddAttribute (UINT32 handle, UINT16 attr_id, + UINT8 attr_type, UINT32 attr_len, + UINT8 *p_val); + + +/******************************************************************************* +** +** Function SDP_AddSequence +** +** Description This function is called to add a sequence to a record. +** This would be through the SDP database maintenance API. +** If the sequence already exists in the record, it is replaced +** with the new sequence. +** +** NOTE Element values must be passed as a Big Endian stream. +** +** Returns TRUE if added OK, else FALSE +** +*******************************************************************************/ +extern BOOLEAN SDP_AddSequence (UINT32 handle, UINT16 attr_id, + UINT16 num_elem, UINT8 type[], + UINT8 len[], UINT8 *p_val[]); + + +/******************************************************************************* +** +** Function SDP_AddUuidSequence +** +** Description This function is called to add a UUID sequence to a record. +** This would be through the SDP database maintenance API. +** If the sequence already exists in the record, it is replaced +** with the new sequence. +** +** Returns TRUE if added OK, else FALSE +** +*******************************************************************************/ +extern BOOLEAN SDP_AddUuidSequence (UINT32 handle, UINT16 attr_id, + UINT16 num_uuids, UINT16 *p_uuids); + + +/******************************************************************************* +** +** Function SDP_AddProtocolList +** +** Description This function is called to add a protocol descriptor list to +** a record. This would be through the SDP database maintenance API. +** If the protocol list already exists in the record, it is replaced +** with the new list. +** +** Returns TRUE if added OK, else FALSE +** +*******************************************************************************/ +extern BOOLEAN SDP_AddProtocolList (UINT32 handle, UINT16 num_elem, + tSDP_PROTOCOL_ELEM *p_elem_list); + + +/******************************************************************************* +** +** Function SDP_AddAdditionProtoLists +** +** Description This function is called to add a protocol descriptor list to +** a record. This would be through the SDP database maintenance API. +** If the protocol list already exists in the record, it is replaced +** with the new list. +** +** Returns TRUE if added OK, else FALSE +** +*******************************************************************************/ +extern BOOLEAN SDP_AddAdditionProtoLists (UINT32 handle, UINT16 num_elem, + tSDP_PROTO_LIST_ELEM *p_proto_list); + + +/******************************************************************************* +** +** Function SDP_AddProfileDescriptorList +** +** Description This function is called to add a profile descriptor list to +** a record. This would be through the SDP database maintenance API. +** If the version already exists in the record, it is replaced +** with the new one. +** +** Returns TRUE if added OK, else FALSE +** +*******************************************************************************/ +extern BOOLEAN SDP_AddProfileDescriptorList (UINT32 handle, + UINT16 profile_uuid, + UINT16 version); + + +/******************************************************************************* +** +** Function SDP_AddLanguageBaseAttrIDList +** +** Description This function is called to add a language base attr list to +** a record. This would be through the SDP database maintenance API. +** If the version already exists in the record, it is replaced +** with the new one. +** +** Returns TRUE if added OK, else FALSE +** +*******************************************************************************/ +extern BOOLEAN SDP_AddLanguageBaseAttrIDList (UINT32 handle, + UINT16 lang, UINT16 char_enc, + UINT16 base_id); + + +/******************************************************************************* +** +** Function SDP_AddServiceClassIdList +** +** Description This function is called to add a service list to a record. +** This would be through the SDP database maintenance API. +** If the service list already exists in the record, it is replaced +** with the new list. +** +** Returns TRUE if added OK, else FALSE +** +*******************************************************************************/ +extern BOOLEAN SDP_AddServiceClassIdList (UINT32 handle, + UINT16 num_services, + UINT16 *p_service_uuids); + + +/******************************************************************************* +** +** Function SDP_DeleteAttribute +** +** Description This function is called to delete an attribute from a record. +** This would be through the SDP database maintenance API. +** +** Returns TRUE if deleted OK, else FALSE if not found +** +*******************************************************************************/ +extern BOOLEAN SDP_DeleteAttribute (UINT32 handle, UINT16 attr_id); + + +/* Device Identification APIs */ + +/******************************************************************************* +** +** Function SDP_SetLocalDiRecord +** +** Description This function adds a DI record to the local SDP database. +** +** Returns Returns SDP_SUCCESS if record added successfully, else error +** +*******************************************************************************/ +extern UINT16 SDP_SetLocalDiRecord (tSDP_DI_RECORD *device_info, + UINT32 *p_handle); + +/******************************************************************************* +** +** Function SDP_DiDiscover +** +** Description This function queries a remote device for DI information. +** +** Returns SDP_SUCCESS if query started successfully, else error +** +*******************************************************************************/ +extern UINT16 SDP_DiDiscover (BD_ADDR remote_device, + tSDP_DISCOVERY_DB *p_db, UINT32 len, + tSDP_DISC_CMPL_CB *p_cb); + + +/******************************************************************************* +** +** Function SDP_GetNumDiRecords +** +** Description Searches specified database for DI records +** +** Returns number of DI records found +** +*******************************************************************************/ +extern UINT8 SDP_GetNumDiRecords (tSDP_DISCOVERY_DB *p_db); + + +/******************************************************************************* +** +** Function SDP_GetDiRecord +** +** Description This function retrieves a remote device's DI record from +** the specified database. +** +** Returns SDP_SUCCESS if record retrieved, else error +** +*******************************************************************************/ +extern UINT16 SDP_GetDiRecord (UINT8 getRecordIndex, + tSDP_DI_GET_RECORD *device_info, + tSDP_DISCOVERY_DB *p_db); + + +/******************************************************************************* +** +** Function SDP_SetTraceLevel +** +** Description This function sets the trace level for SDP. If called with +** a value of 0xFF, it simply reads the current trace level. +** +** Returns the new (current) trace level +** +*******************************************************************************/ +extern UINT8 SDP_SetTraceLevel (UINT8 new_level); + +/******************************************************************************* +** +** Function SDP_ConnOpen +** +** Description This function creates a connection to the SDP server on the +** given device. +** +** Returns 0, if failed to initiate connection. Otherwise, the handle. +** +*******************************************************************************/ +UINT32 SDP_ConnOpen (UINT8 *p_bd_addr, tSDP_DISC_RES_CB *p_rcb, + tSDP_DISC_CMPL_CB *p_cb); + +/******************************************************************************* +** +** Function SDP_WriteData +** +** Description This function sends data to the connected SDP server. +** +** Returns TRUE if data is sent, FALSE if failed. +** +*******************************************************************************/ +BOOLEAN SDP_WriteData (UINT32 handle, BT_HDR *p_msg); + +/******************************************************************************* +** +** Function SDP_ConnClose +** +** Description This function is called to close a SDP connection. +** +** Parameters: handle - Handle of the connection returned by SDP_ConnOpen +** +** Returns TRUE if connection is closed, FALSE if failed to find the handle. +** +*******************************************************************************/ +BOOLEAN SDP_ConnClose (UINT32 handle); + +/******************************************************************************* +** +** Function SDP_FindServiceUUIDInRec +** +** Description This function is called to read the service UUID within a record +** if there is any. +** +** Parameters: p_rec - pointer to a SDP record. +** +** Returns TRUE if found, otherwise FALSE. +** +*******************************************************************************/ +BOOLEAN SDP_FindServiceUUIDInRec(tSDP_DISC_REC *p_rec, tBT_UUID *p_uuid); + +#ifdef __cplusplus +} +#endif + +#endif /* SDP_API_H */ diff --git a/tools/sdk/include/bluedroid/sdpdefs.h b/tools/sdk/include/bluedroid/sdpdefs.h new file mode 100755 index 00000000..44d87e74 --- /dev/null +++ b/tools/sdk/include/bluedroid/sdpdefs.h @@ -0,0 +1,327 @@ +/****************************************************************************** + * + * Copyright (C) 1999-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 file contains the definitions for the SDP API + * + ******************************************************************************/ + +#ifndef SDP_DEFS_H +#define SDP_DEFS_H + +/* Define the service attribute IDs. +*/ +#define ATTR_ID_SERVICE_RECORD_HDL 0x0000 +#define ATTR_ID_SERVICE_CLASS_ID_LIST 0x0001 +#define ATTR_ID_SERVICE_RECORD_STATE 0x0002 +#define ATTR_ID_SERVICE_ID 0x0003 +#define ATTR_ID_PROTOCOL_DESC_LIST 0x0004 +#define ATTR_ID_BROWSE_GROUP_LIST 0x0005 +#define ATTR_ID_LANGUAGE_BASE_ATTR_ID_LIST 0x0006 +#define ATTR_ID_SERVICE_INFO_TIME_TO_LIVE 0x0007 +#define ATTR_ID_SERVICE_AVAILABILITY 0x0008 +#define ATTR_ID_BT_PROFILE_DESC_LIST 0x0009 +#define ATTR_ID_DOCUMENTATION_URL 0x000A +#define ATTR_ID_CLIENT_EXE_URL 0x000B +#define ATTR_ID_ICON_URL 0x000C +#define ATTR_ID_ADDITION_PROTO_DESC_LISTS 0x000D + +#define LANGUAGE_BASE_ID 0x0100 +#define ATTR_ID_SERVICE_NAME LANGUAGE_BASE_ID + 0x0000 +#define ATTR_ID_SERVICE_DESCRIPTION LANGUAGE_BASE_ID + 0x0001 +#define ATTR_ID_PROVIDER_NAME LANGUAGE_BASE_ID + 0x0002 + +/* Device Identification (DI) +*/ +#define ATTR_ID_SPECIFICATION_ID 0x0200 +#define ATTR_ID_VENDOR_ID 0x0201 +#define ATTR_ID_PRODUCT_ID 0x0202 +#define ATTR_ID_PRODUCT_VERSION 0x0203 +#define ATTR_ID_PRIMARY_RECORD 0x0204 +#define ATTR_ID_VENDOR_ID_SOURCE 0x0205 + +#define BLUETOOTH_DI_SPECIFICATION 0x0103 /* 1.3 */ +#define DI_VENDOR_ID_DEFAULT 0xFFFF +#define DI_VENDOR_ID_SOURCE_BTSIG 0x0001 +#define DI_VENDOR_ID_SOURCE_USBIF 0x0002 + + +#define ATTR_ID_IP_SUBNET 0x0200 /* PAN Profile (***) */ +#define ATTR_ID_VERSION_NUMBER_LIST 0x0200 +#define ATTR_ID_GOEP_L2CAP_PSM 0x0200 +#define ATTR_ID_GROUP_ID 0x0200 +#define ATTR_ID_SERVICE_DATABASE_STATE 0x0201 +#define ATTR_ID_SERVICE_VERSION 0x0300 +#define ATTR_ID_HCRP_1284ID 0x0300 + +#define ATTR_ID_SUPPORTED_DATA_STORES 0x0301 +#define ATTR_ID_NETWORK 0x0301 +#define ATTR_ID_EXTERNAL_NETWORK 0x0301 +#define ATTR_ID_FAX_CLASS_1_SUPPORT 0x0302 +#define ATTR_ID_REMOTE_AUDIO_VOLUME_CONTROL 0x0302 +#define ATTR_ID_DEVICE_NAME 0x0302 +#define ATTR_ID_SUPPORTED_FORMATS_LIST 0x0303 +#define ATTR_ID_FAX_CLASS_2_0_SUPPORT 0x0303 +#define ATTR_ID_FAX_CLASS_2_SUPPORT 0x0304 +#define ATTR_ID_FRIENDLY_NAME 0x0304 +#define ATTR_ID_AUDIO_FEEDBACK_SUPPORT 0x0305 +#define ATTR_ID_NETWORK_ADDRESS 0x0306 +#define ATTR_ID_DEVICE_LOCATION 0x0306 +#define ATTR_ID_WAP_GATEWAY 0x0307 +#define ATTR_ID_HOME_PAGE_URL 0x0308 +#define ATTR_ID_WAP_STACK_TYPE 0x0309 +#define ATTR_ID_IMG_SUPPORTED_CAPABILITIES 0x0310 /* Imaging Profile */ +#define ATTR_ID_SUPPORTED_FEATURES 0x0311 /* HFP, BIP */ +#define ATTR_ID_IMG_SUPPORTED_FUNCTIONS 0x0312 /* Imaging Profile */ +#define ATTR_ID_IMG_TOT_DATA_CAPABILITY 0x0313 /* Imaging Profile */ +#define ATTR_ID_SUPPORTED_REPOSITORIES 0x0314 /* Phone book access Profile */ +#define ATTR_ID_MAS_INSTANCE_ID 0x0315 /* MAP profile */ +#define ATTR_ID_SUPPORTED_MSG_TYPE 0x0316 /* MAP profile */ +#define ATTR_ID_MAP_SUPPORTED_FEATURES 0x0317 /* MAP profile */ +#define ATTR_ID_PBAP_SUPPORTED_FEATURES 0x0317 /* PBAP profile */ + + +/* These values are for the BPP profile */ +#define ATTR_ID_DOCUMENT_FORMATS_SUPPORTED 0x0350 +#define ATTR_ID_CHARACTER_REPERTOIRES_SUPPORTED 0x0352 +#define ATTR_ID_XHTML_IMAGE_FORMATS_SUPPORTED 0x0354 +#define ATTR_ID_COLOR_SUPPORTED 0x0356 +#define ATTR_ID_1284ID 0x0358 +#define ATTR_ID_PRINTER_NAME 0x035A +#define ATTR_ID_PRINTER_LOCATION 0x035C +#define ATTR_ID_DUPLEX_SUPPORTED 0x035E +#define ATTR_ID_MEDIA_TYPES_SUPPORTED 0x0360 +#define ATTR_ID_MAX_MEDIA_WIDTH 0x0362 +#define ATTR_ID_MAX_MEDIA_LENGTH 0x0364 +#define ATTR_ID_ENHANCED_LAYOUT_SUPPORTED 0x0366 +#define ATTR_ID_RUI_FORMATS_SUPPORTED 0x0368 +#define ATTR_ID_RUI_REF_PRINTING_SUPPORTED 0x0370 /* Boolean */ +#define ATTR_ID_RUI_DIRECT_PRINTING_SUPPORTED 0x0372 /* Boolean */ +#define ATTR_ID_REF_PRINTING_TOP_URL 0x0374 +#define ATTR_ID_DIRECT_PRINTING_TOP_URL 0x0376 +#define ATTR_ID_PRINTER_ADMIN_RUI_TOP_URL 0x0378 +#define ATTR_ID_BPP_DEVICE_NAME 0x037A + +/* These values are for the PAN profile */ +#define ATTR_ID_SECURITY_DESCRIPTION 0x030A +#define ATTR_ID_NET_ACCESS_TYPE 0x030B +#define ATTR_ID_MAX_NET_ACCESS_RATE 0x030C +#define ATTR_ID_IPV4_SUBNET 0x030D +#define ATTR_ID_IPV6_SUBNET 0x030E +#define ATTR_ID_PAN_SECURITY 0x0400 + +/* These values are for HID profile */ +#define ATTR_ID_HID_DEVICE_RELNUM 0x0200 +#define ATTR_ID_HID_PARSER_VERSION 0x0201 +#define ATTR_ID_HID_DEVICE_SUBCLASS 0x0202 +#define ATTR_ID_HID_COUNTRY_CODE 0x0203 +#define ATTR_ID_HID_VIRTUAL_CABLE 0x0204 +#define ATTR_ID_HID_RECONNECT_INITIATE 0x0205 +#define ATTR_ID_HID_DESCRIPTOR_LIST 0x0206 +#define ATTR_ID_HID_LANGUAGE_ID_BASE 0x0207 +#define ATTR_ID_HID_SDP_DISABLE 0x0208 +#define ATTR_ID_HID_BATTERY_POWER 0x0209 +#define ATTR_ID_HID_REMOTE_WAKE 0x020A +#define ATTR_ID_HID_PROFILE_VERSION 0x020B +#define ATTR_ID_HID_LINK_SUPERVISION_TO 0x020C +#define ATTR_ID_HID_NORMALLY_CONNECTABLE 0x020D +#define ATTR_ID_HID_BOOT_DEVICE 0x020E +#define ATTR_ID_HID_SSR_HOST_MAX_LAT 0x020F +#define ATTR_ID_HID_SSR_HOST_MIN_TOUT 0x0210 + +/* These values are for the HDP profile */ +#define ATTR_ID_HDP_SUP_FEAT_LIST 0x0200 /* Supported features list */ +#define ATTR_ID_HDP_DATA_EXCH_SPEC 0x0301 /* Data exchange specification */ +#define ATTR_ID_HDP_MCAP_SUP_PROC 0x0302 /* MCAP supported procedures */ + +/* Define common 16-bit protocol UUIDs +*/ +#define UUID_PROTOCOL_SDP 0x0001 +#define UUID_PROTOCOL_UDP 0x0002 +#define UUID_PROTOCOL_RFCOMM 0x0003 +#define UUID_PROTOCOL_TCP 0x0004 +#define UUID_PROTOCOL_TCS_BIN 0x0005 +#define UUID_PROTOCOL_TCS_AT 0x0006 +#define UUID_PROTOCOL_OBEX 0x0008 +#define UUID_PROTOCOL_IP 0x0009 +#define UUID_PROTOCOL_FTP 0x000A +#define UUID_PROTOCOL_HTTP 0x000C +#define UUID_PROTOCOL_WSP 0x000E +#define UUID_PROTOCOL_BNEP 0x000F +#define UUID_PROTOCOL_UPNP 0x0010 +#define UUID_PROTOCOL_HIDP 0x0011 +#define UUID_PROTOCOL_HCRP_CTRL 0x0012 +#define UUID_PROTOCOL_HCRP_DATA 0x0014 +#define UUID_PROTOCOL_HCRP_NOTIF 0x0016 +#define UUID_PROTOCOL_AVCTP 0x0017 +#define UUID_PROTOCOL_AVDTP 0x0019 +#define UUID_PROTOCOL_CMTP 0x001B +#define UUID_PROTOCOL_UDI 0x001D +#define UUID_PROTOCOL_MCAP_CTRL 0x001E +#define UUID_PROTOCOL_MCAP_DATA 0x001F +#define UUID_PROTOCOL_L2CAP 0x0100 +#define UUID_PROTOCOL_ATT 0x0007 + +/* Define common 16-bit service class UUIDs +*/ +#define UUID_SERVCLASS_SERVICE_DISCOVERY_SERVER 0X1000 +#define UUID_SERVCLASS_BROWSE_GROUP_DESCRIPTOR 0X1001 +#define UUID_SERVCLASS_PUBLIC_BROWSE_GROUP 0X1002 +#define UUID_SERVCLASS_SERIAL_PORT 0X1101 +#define UUID_SERVCLASS_LAN_ACCESS_USING_PPP 0X1102 +#define UUID_SERVCLASS_DIALUP_NETWORKING 0X1103 +#define UUID_SERVCLASS_IRMC_SYNC 0X1104 +#define UUID_SERVCLASS_OBEX_OBJECT_PUSH 0X1105 +#define UUID_SERVCLASS_OBEX_FILE_TRANSFER 0X1106 +#define UUID_SERVCLASS_IRMC_SYNC_COMMAND 0X1107 +#define UUID_SERVCLASS_HEADSET 0X1108 +#define UUID_SERVCLASS_CORDLESS_TELEPHONY 0X1109 +#define UUID_SERVCLASS_AUDIO_SOURCE 0X110A +#define UUID_SERVCLASS_AUDIO_SINK 0X110B +#define UUID_SERVCLASS_AV_REM_CTRL_TARGET 0X110C /* Audio/Video Control profile */ +#define UUID_SERVCLASS_ADV_AUDIO_DISTRIBUTION 0X110D /* Advanced Audio Distribution profile */ +#define UUID_SERVCLASS_AV_REMOTE_CONTROL 0X110E /* Audio/Video Control profile */ +#define UUID_SERVCLASS_AV_REM_CTRL_CONTROL 0X110F /* Audio/Video Control profile */ +#define UUID_SERVCLASS_INTERCOM 0X1110 +#define UUID_SERVCLASS_FAX 0X1111 +#define UUID_SERVCLASS_HEADSET_AUDIO_GATEWAY 0X1112 +#define UUID_SERVCLASS_WAP 0X1113 +#define UUID_SERVCLASS_WAP_CLIENT 0X1114 +#define UUID_SERVCLASS_PANU 0X1115 /* PAN profile */ +#define UUID_SERVCLASS_NAP 0X1116 /* PAN profile */ +#define UUID_SERVCLASS_GN 0X1117 /* PAN profile */ +#define UUID_SERVCLASS_DIRECT_PRINTING 0X1118 /* BPP profile */ +#define UUID_SERVCLASS_REFERENCE_PRINTING 0X1119 /* BPP profile */ +#define UUID_SERVCLASS_IMAGING 0X111A /* Imaging profile */ +#define UUID_SERVCLASS_IMAGING_RESPONDER 0X111B /* Imaging profile */ +#define UUID_SERVCLASS_IMAGING_AUTO_ARCHIVE 0X111C /* Imaging profile */ +#define UUID_SERVCLASS_IMAGING_REF_OBJECTS 0X111D /* Imaging profile */ +#define UUID_SERVCLASS_HF_HANDSFREE 0X111E /* Handsfree profile */ +#define UUID_SERVCLASS_AG_HANDSFREE 0X111F /* Handsfree profile */ +#define UUID_SERVCLASS_DIR_PRT_REF_OBJ_SERVICE 0X1120 /* BPP profile */ +#define UUID_SERVCLASS_REFLECTED_UI 0X1121 /* BPP profile */ +#define UUID_SERVCLASS_BASIC_PRINTING 0X1122 /* BPP profile */ +#define UUID_SERVCLASS_PRINTING_STATUS 0X1123 /* BPP profile */ +#define UUID_SERVCLASS_HUMAN_INTERFACE 0X1124 /* HID profile */ +#define UUID_SERVCLASS_CABLE_REPLACEMENT 0X1125 /* HCRP profile */ +#define UUID_SERVCLASS_HCRP_PRINT 0X1126 /* HCRP profile */ +#define UUID_SERVCLASS_HCRP_SCAN 0X1127 /* HCRP profile */ +#define UUID_SERVCLASS_COMMON_ISDN_ACCESS 0X1128 /* CAPI Message Transport Protocol*/ +#define UUID_SERVCLASS_VIDEO_CONFERENCING_GW 0X1129 /* Video Conferencing profile */ +#define UUID_SERVCLASS_UDI_MT 0X112A /* Unrestricted Digital Information profile */ +#define UUID_SERVCLASS_UDI_TA 0X112B /* Unrestricted Digital Information profile */ +#define UUID_SERVCLASS_VCP 0X112C /* Video Conferencing profile */ +#define UUID_SERVCLASS_SAP 0X112D /* SIM Access profile */ +#define UUID_SERVCLASS_PBAP_PCE 0X112E /* Phonebook Access - PCE */ +#define UUID_SERVCLASS_PBAP_PSE 0X112F /* Phonebook Access - PSE */ +#define UUID_SERVCLASS_PHONE_ACCESS 0x1130 +#define UUID_SERVCLASS_HEADSET_HS 0x1131 /* Headset - HS, from HSP v1.2 */ +#define UUID_SERVCLASS_PNP_INFORMATION 0X1200 /* Device Identification */ +#define UUID_SERVCLASS_GENERIC_NETWORKING 0X1201 +#define UUID_SERVCLASS_GENERIC_FILETRANSFER 0X1202 +#define UUID_SERVCLASS_GENERIC_AUDIO 0X1203 +#define UUID_SERVCLASS_GENERIC_TELEPHONY 0X1204 +#define UUID_SERVCLASS_UPNP_SERVICE 0X1205 /* UPNP_Service [ESDP] */ +#define UUID_SERVCLASS_UPNP_IP_SERVICE 0X1206 /* UPNP_IP_Service [ESDP] */ +#define UUID_SERVCLASS_ESDP_UPNP_IP_PAN 0X1300 /* UPNP_IP_PAN [ESDP] */ +#define UUID_SERVCLASS_ESDP_UPNP_IP_LAP 0X1301 /* UPNP_IP_LAP [ESDP] */ +#define UUID_SERVCLASS_ESDP_UPNP_IP_L2CAP 0X1302 /* UPNP_L2CAP [ESDP] */ +#define UUID_SERVCLASS_VIDEO_SOURCE 0X1303 /* Video Distribution Profile (VDP) */ +#define UUID_SERVCLASS_VIDEO_SINK 0X1304 /* Video Distribution Profile (VDP) */ +#define UUID_SERVCLASS_VIDEO_DISTRIBUTION 0X1305 /* Video Distribution Profile (VDP) */ +#define UUID_SERVCLASS_HDP_PROFILE 0X1400 /* Health Device profile (HDP) */ +#define UUID_SERVCLASS_HDP_SOURCE 0X1401 /* Health Device profile (HDP) */ +#define UUID_SERVCLASS_HDP_SINK 0X1402 /* Health Device profile (HDP) */ +#define UUID_SERVCLASS_MAP_PROFILE 0X1134 /* MAP profile UUID */ +#define UUID_SERVCLASS_MESSAGE_ACCESS 0X1132 /* Message Access Service UUID */ +#define UUID_SERVCLASS_MESSAGE_NOTIFICATION 0X1133 /* Message Notification Service UUID */ + +#define UUID_SERVCLASS_GAP_SERVER 0x1800 +#define UUID_SERVCLASS_GATT_SERVER 0x1801 +#define UUID_SERVCLASS_IMMEDIATE_ALERT 0x1802 /* immediate alert */ +#define UUID_SERVCLASS_LINKLOSS 0x1803 /* Link Loss Alert */ +#define UUID_SERVCLASS_TX_POWER 0x1804 /* TX power */ +#define UUID_SERVCLASS_CURRENT_TIME 0x1805 /* Link Loss Alert */ +#define UUID_SERVCLASS_DST_CHG 0x1806 /* DST Time change */ +#define UUID_SERVCLASS_REF_TIME_UPD 0x1807 /* reference time update */ +#define UUID_SERVCLASS_THERMOMETER 0x1809 /* Thermometer UUID */ +#define UUID_SERVCLASS_DEVICE_INFO 0x180A /* device info service */ +#define UUID_SERVCLASS_NWA 0x180B /* Network availability */ +#define UUID_SERVCLASS_HEART_RATE 0x180D /* Heart Rate service */ +#define UUID_SERVCLASS_PHALERT 0x180E /* phone alert service */ +#define UUID_SERVCLASS_BATTERY 0x180F /* battery service */ +#define UUID_SERVCLASS_BPM 0x1810 /* blood pressure service */ +#define UUID_SERVCLASS_ALERT_NOTIFICATION 0x1811 /* alert notification service */ +#define UUID_SERVCLASS_LE_HID 0x1812 /* HID over LE */ +#define UUID_SERVCLASS_SCAN_PARAM 0x1813 /* Scan Parameter service */ +#define UUID_SERVCLASS_GLUCOSE 0x1808 /* Glucose Meter Service */ +#define UUID_SERVCLASS_RSC 0x1814 /* RUNNERS SPEED AND CADENCE SERVICE */ +#define UUID_SERVCLASS_CSC 0x1816 /* Cycling SPEED AND CADENCE SERVICE */ + +#define UUID_SERVCLASS_TEST_SERVER 0x9000 /* Test Group UUID */ + +#if (BTM_WBS_INCLUDED == TRUE ) +#define UUID_CODEC_CVSD 0x0001 /* CVSD */ +#define UUID_CODEC_MSBC 0x0002 /* mSBC */ +#endif + +/* Define all the 'Descriptor Type' values. +*/ +#define NULL_DESC_TYPE 0 +#define UINT_DESC_TYPE 1 +#define TWO_COMP_INT_DESC_TYPE 2 +#define UUID_DESC_TYPE 3 +#define TEXT_STR_DESC_TYPE 4 +#define BOOLEAN_DESC_TYPE 5 +#define DATA_ELE_SEQ_DESC_TYPE 6 +#define DATA_ELE_ALT_DESC_TYPE 7 +#define URL_DESC_TYPE 8 + +/* Define all the "Descriptor Size" values. +*/ +#define SIZE_ONE_BYTE 0 +#define SIZE_TWO_BYTES 1 +#define SIZE_FOUR_BYTES 2 +#define SIZE_EIGHT_BYTES 3 +#define SIZE_SIXTEEN_BYTES 4 +#define SIZE_IN_NEXT_BYTE 5 +#define SIZE_IN_NEXT_WORD 6 +#define SIZE_IN_NEXT_LONG 7 + +/* Language Encoding Constants */ +#define LANG_ID_CODE_ENGLISH ((UINT16) 0x656e) /* "en" */ +#define LANG_ID_CHAR_ENCODE_UTF8 ((UINT16) 0x006a) /* UTF-8 */ + +/* Constants used for display purposes only. These define ovelapping attribute values */ +#define ATTR_ID_VERS_OR_GRP_OR_DRELNUM_OR_IPSUB_OR_SPECID 0x0200 +#define ATTR_ID_VEND_ID_OR_SERVICE_DB_STATE_OR_PARSE_VER 0x0201 +#define ATTR_ID_PROD_ID_OR_HID_DEV_SUBCLASS 0x0202 +#define ATTR_ID_PROD_VER_OR_HID_COUNTRY_CODE 0x0203 +#define ATTR_ID_PRIMARY_REC_OR_HID_VIRTUAL_CABLE 0x0204 +#define ATTR_ID_DI_VENDOR_ID_SOURCE_OR_HID_INIT_RECONNECT 0x0205 +#define ATTR_ID_SERV_VERS_OR_1284ID 0x0300 +#define ATTR_ID_DATA_STORES_OR_NETWORK 0x0301 +#define ATTR_ID_FAX_1_OR_AUD_VOL_OR_DEV_NAME 0x0302 +#define ATTR_ID_FORMATS_OR_FAX_2_0 0x0303 +#define ATTR_ID_FAX_CLASS_2_OR_FRIENDLY_NAME 0x0304 +#define ATTR_ID_NETADDRESS_OR_DEVLOCATION 0x0306 + +#endif + + diff --git a/tools/sdk/include/bluedroid/sdpint.h b/tools/sdk/include/bluedroid/sdpint.h new file mode 100644 index 00000000..9e935ea5 --- /dev/null +++ b/tools/sdk/include/bluedroid/sdpint.h @@ -0,0 +1,314 @@ +/****************************************************************************** + * + * Copyright (C) 1999-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 file contains internally used SDP definitions + * + ******************************************************************************/ + +#ifndef SDP_INT_H +#define SDP_INT_H + +#include "bt_target.h" +#include "sdp_api.h" +#include "l2c_api.h" + + +/* Continuation length - we use a 2-byte offset */ +#define SDP_CONTINUATION_LEN 2 +#define SDP_MAX_CONTINUATION_LEN 16 /* As per the spec */ + +/* Timeout definitions. */ +#define SDP_INACT_TIMEOUT 30 /* Inactivity timeout */ + + +/* Define the Out-Flow default values. */ +#define SDP_OFLOW_QOS_FLAG 0 +#define SDP_OFLOW_SERV_TYPE 0 +#define SDP_OFLOW_TOKEN_RATE 0 +#define SDP_OFLOW_TOKEN_BUCKET_SIZE 0 +#define SDP_OFLOW_PEAK_BANDWIDTH 0 +#define SDP_OFLOW_LATENCY 0 +#define SDP_OFLOW_DELAY_VARIATION 0 + +/* Define the In-Flow default values. */ +#define SDP_IFLOW_QOS_FLAG 0 +#define SDP_IFLOW_SERV_TYPE 0 +#define SDP_IFLOW_TOKEN_RATE 0 +#define SDP_IFLOW_TOKEN_BUCKET_SIZE 0 +#define SDP_IFLOW_PEAK_BANDWIDTH 0 +#define SDP_IFLOW_LATENCY 0 +#define SDP_IFLOW_DELAY_VARIATION 0 + +#define SDP_LINK_TO 0 + +/* Define the type of device notification. */ +/* (Inquiry Scan and Page Scan) */ +#define SDP_DEVICE_NOTI_LEN sizeof (BT_HDR) + \ + HCIC_PREAMBLE_SIZE + \ + HCIC_PARAM_SIZE_WRITE_PARAM1 + +#define SDP_DEVICE_NOTI_FLAG 0x03 + +/* Define the Protocol Data Unit (PDU) types. +*/ +#define SDP_PDU_ERROR_RESPONSE 0x01 +#define SDP_PDU_SERVICE_SEARCH_REQ 0x02 +#define SDP_PDU_SERVICE_SEARCH_RSP 0x03 +#define SDP_PDU_SERVICE_ATTR_REQ 0x04 +#define SDP_PDU_SERVICE_ATTR_RSP 0x05 +#define SDP_PDU_SERVICE_SEARCH_ATTR_REQ 0x06 +#define SDP_PDU_SERVICE_SEARCH_ATTR_RSP 0x07 + +/* Max UUIDs and attributes we support per sequence */ +#define MAX_UUIDS_PER_SEQ 8 +#define MAX_ATTR_PER_SEQ 8 + +/* Max length we support for any attribute */ +// btla-specific ++ +#ifdef SDP_MAX_ATTR_LEN +#define MAX_ATTR_LEN SDP_MAX_ATTR_LEN +#else +#define MAX_ATTR_LEN 256 +#endif +// btla-specific -- + +/* Internal UUID sequence representation */ +typedef struct { + UINT16 len; + UINT8 value[MAX_UUID_SIZE]; +} tUID_ENT; + +typedef struct { + UINT16 num_uids; + tUID_ENT uuid_entry[MAX_UUIDS_PER_SEQ]; +} tSDP_UUID_SEQ; + + +/* Internal attribute sequence definitions */ +typedef struct { + UINT16 start; + UINT16 end; +} tATT_ENT; + +typedef struct { + UINT16 num_attr; + tATT_ENT attr_entry[MAX_ATTR_PER_SEQ]; +} tSDP_ATTR_SEQ; + + +/* Define the attribute element of the SDP database record */ +typedef struct { + UINT32 len; /* Number of bytes in the entry */ + UINT8 *value_ptr; /* Points to attr_pad */ + UINT16 id; + UINT8 type; +} tSDP_ATTRIBUTE; + +/* An SDP record consists of a handle, and 1 or more attributes */ +typedef struct { + UINT32 record_handle; + UINT32 free_pad_ptr; + UINT16 num_attributes; + tSDP_ATTRIBUTE attribute[SDP_MAX_REC_ATTR]; + UINT8 attr_pad[SDP_MAX_PAD_LEN]; +} tSDP_RECORD; + + +/* Define the SDP database */ +typedef struct { + UINT32 di_primary_handle; /* Device ID Primary record or NULL if nonexistent */ + UINT16 num_records; + tSDP_RECORD record[SDP_MAX_RECORDS]; +} tSDP_DB; + +enum { + SDP_IS_SEARCH, + SDP_IS_ATTR_SEARCH, +}; + +#if SDP_SERVER_ENABLED == TRUE +/* Continuation information for the SDP server response */ +typedef struct { + UINT16 next_attr_index; /* attr index for next continuation response */ + UINT16 next_attr_start_id; /* attr id to start with for the attr index in next cont. response */ + tSDP_RECORD *prev_sdp_rec; /* last sdp record that was completely sent in the response */ + BOOLEAN last_attr_seq_desc_sent; /* whether attr seq length has been sent previously */ + UINT16 attr_offset; /* offset within the attr to keep trak of partial attributes in the responses */ +} tSDP_CONT_INFO; +#endif /* SDP_SERVER_ENABLED == TRUE */ + +/* Define the SDP Connection Control Block */ +typedef struct { +#define SDP_STATE_IDLE 0 +#define SDP_STATE_CONN_SETUP 1 +#define SDP_STATE_CFG_SETUP 2 +#define SDP_STATE_CONNECTED 3 + UINT8 con_state; + +#define SDP_FLAGS_IS_ORIG 0x01 +#define SDP_FLAGS_HIS_CFG_DONE 0x02 +#define SDP_FLAGS_MY_CFG_DONE 0x04 + UINT8 con_flags; + + BD_ADDR device_address; + TIMER_LIST_ENT timer_entry; + UINT16 rem_mtu_size; + UINT16 connection_id; + UINT16 list_len; /* length of the response in the GKI buffer */ + UINT8 *rsp_list; /* pointer to GKI buffer holding response */ + +#if SDP_CLIENT_ENABLED == TRUE + tSDP_DISCOVERY_DB *p_db; /* Database to save info into */ + tSDP_DISC_CMPL_CB *p_cb; /* Callback for discovery done */ + tSDP_DISC_CMPL_CB2 *p_cb2; /* Callback for discovery done piggy back with the user data */ + void *user_data; /* piggy back user data */ + UINT32 handles[SDP_MAX_DISC_SERVER_RECS]; /* Discovered server record handles */ + UINT16 num_handles; /* Number of server handles */ + UINT16 cur_handle; /* Current handle being processed */ + UINT16 transaction_id; + UINT16 disconnect_reason; /* Disconnect reason */ +#if (defined(SDP_BROWSE_PLUS) && SDP_BROWSE_PLUS == TRUE) + UINT16 cur_uuid_idx; +#endif + +#define SDP_DISC_WAIT_CONN 0 +#define SDP_DISC_WAIT_HANDLES 1 +#define SDP_DISC_WAIT_ATTR 2 +#define SDP_DISC_WAIT_SEARCH_ATTR 3 +#define SDP_DISC_WAIT_CANCEL 5 + + UINT8 disc_state; + UINT8 is_attr_search; +#endif /* SDP_CLIENT_ENABLED == TRUE */ + +#if SDP_SERVER_ENABLED == TRUE + UINT16 cont_offset; /* Continuation state data in the server response */ + tSDP_CONT_INFO cont_info; /* structure to hold continuation information for the server response */ +#endif /* SDP_SERVER_ENABLED == TRUE */ + +} tCONN_CB; + + +/* The main SDP control block */ +typedef struct { + tL2CAP_CFG_INFO l2cap_my_cfg; /* My L2CAP config */ + tCONN_CB ccb[SDP_MAX_CONNECTIONS]; +#if SDP_SERVER_ENABLED == TRUE + tSDP_DB server_db; +#endif + tL2CAP_APPL_INFO reg_info; /* L2CAP Registration info */ + UINT16 max_attr_list_size; /* Max attribute list size to use */ + UINT16 max_recs_per_search; /* Max records we want per seaarch */ + UINT8 trace_level; +} tSDP_CB; + +#ifdef __cplusplus +extern "C" { +#endif +/* Global SDP data */ +#if SDP_DYNAMIC_MEMORY == FALSE +extern tSDP_CB sdp_cb; +#else +extern tSDP_CB *sdp_cb_ptr; +#define sdp_cb (*sdp_cb_ptr) +#endif + +#ifdef __cplusplus +} +#endif + +/* Functions provided by sdp_main.c */ +extern void sdp_init (void); +extern void sdp_disconnect (tCONN_CB *p_ccb, UINT16 reason); + +#if (defined(SDP_DEBUG) && SDP_DEBUG == TRUE) +extern UINT16 sdp_set_max_attr_list_size (UINT16 max_size); +#endif + +/* Functions provided by sdp_conn.c +*/ +extern void sdp_conn_rcv_l2e_conn_ind (BT_HDR *p_msg); +extern void sdp_conn_rcv_l2e_conn_cfm (BT_HDR *p_msg); +extern void sdp_conn_rcv_l2e_disc (BT_HDR *p_msg); +extern void sdp_conn_rcv_l2e_config_ind (BT_HDR *p_msg); +extern void sdp_conn_rcv_l2e_config_cfm (BT_HDR *p_msg); +extern void sdp_conn_rcv_l2e_conn_failed (BT_HDR *p_msg); +extern void sdp_conn_rcv_l2e_connected (BT_HDR *p_msg); +extern void sdp_conn_rcv_l2e_conn_failed (BT_HDR *p_msg); +extern void sdp_conn_rcv_l2e_data (BT_HDR *p_msg); +extern void sdp_conn_timeout (tCONN_CB *p_ccb); + +extern tCONN_CB *sdp_conn_originate (UINT8 *p_bd_addr); + +/* Functions provided by sdp_utils.c +*/ +extern tCONN_CB *sdpu_find_ccb_by_cid (UINT16 cid); +extern tCONN_CB *sdpu_find_ccb_by_db (tSDP_DISCOVERY_DB *p_db); +extern tCONN_CB *sdpu_allocate_ccb (void); +extern void sdpu_release_ccb (tCONN_CB *p_ccb); + +extern UINT8 *sdpu_build_attrib_seq (UINT8 *p_out, UINT16 *p_attr, UINT16 num_attrs); +extern UINT8 *sdpu_build_attrib_entry (UINT8 *p_out, tSDP_ATTRIBUTE *p_attr); +extern void sdpu_build_n_send_error (tCONN_CB *p_ccb, UINT16 trans_num, UINT16 error_code, char *p_error_text); + +extern UINT8 *sdpu_extract_attr_seq (UINT8 *p, UINT16 param_len, tSDP_ATTR_SEQ *p_seq); +extern UINT8 *sdpu_extract_uid_seq (UINT8 *p, UINT16 param_len, tSDP_UUID_SEQ *p_seq); + +extern UINT8 *sdpu_get_len_from_type (UINT8 *p, UINT8 type, UINT32 *p_len); +extern BOOLEAN sdpu_is_base_uuid (UINT8 *p_uuid); +extern BOOLEAN sdpu_compare_uuid_arrays (UINT8 *p_uuid1, UINT32 len1, UINT8 *p_uuid2, UINT16 len2); +extern BOOLEAN sdpu_compare_bt_uuids (tBT_UUID *p_uuid1, tBT_UUID *p_uuid2); +extern BOOLEAN sdpu_compare_uuid_with_attr (tBT_UUID *p_btuuid, tSDP_DISC_ATTR *p_attr); + +extern void sdpu_sort_attr_list( UINT16 num_attr, tSDP_DISCOVERY_DB *p_db ); +extern UINT16 sdpu_get_list_len( tSDP_UUID_SEQ *uid_seq, tSDP_ATTR_SEQ *attr_seq ); +extern UINT16 sdpu_get_attrib_seq_len(tSDP_RECORD *p_rec, tSDP_ATTR_SEQ *attr_seq); +extern UINT16 sdpu_get_attrib_entry_len(tSDP_ATTRIBUTE *p_attr); +extern UINT8 *sdpu_build_partial_attrib_entry (UINT8 *p_out, tSDP_ATTRIBUTE *p_attr, UINT16 len, UINT16 *offset); +extern void sdpu_uuid16_to_uuid128(UINT16 uuid16, UINT8 *p_uuid128); + +/* Functions provided by sdp_db.c +*/ +extern tSDP_RECORD *sdp_db_service_search (tSDP_RECORD *p_rec, tSDP_UUID_SEQ *p_seq); +extern tSDP_RECORD *sdp_db_find_record (UINT32 handle); +extern tSDP_ATTRIBUTE *sdp_db_find_attr_in_rec (tSDP_RECORD *p_rec, UINT16 start_attr, UINT16 end_attr); + + +/* Functions provided by sdp_server.c +*/ +#if SDP_SERVER_ENABLED == TRUE +extern void sdp_server_handle_client_req (tCONN_CB *p_ccb, BT_HDR *p_msg); +#else +#define sdp_server_handle_client_req(p_ccb, p_msg) +#endif + +/* Functions provided by sdp_discovery.c +*/ +#if SDP_CLIENT_ENABLED == TRUE +extern void sdp_disc_connected (tCONN_CB *p_ccb); +extern void sdp_disc_server_rsp (tCONN_CB *p_ccb, BT_HDR *p_msg); +#else +#define sdp_disc_connected(p_ccb) +#define sdp_disc_server_rsp(p_ccb, p_msg) +#endif + + + +#endif diff --git a/tools/sdk/include/bluedroid/smp_api.h b/tools/sdk/include/bluedroid/smp_api.h new file mode 100644 index 00000000..cb043fdf --- /dev/null +++ b/tools/sdk/include/bluedroid/smp_api.h @@ -0,0 +1,484 @@ +/****************************************************************************** + * + * Copyright (C) 1999-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 file contains the SMP API function external definitions. + * + ******************************************************************************/ +#ifndef SMP_API_H +#define SMP_API_H + +#include "bt_target.h" + +#define SMP_PIN_CODE_LEN_MAX PIN_CODE_LEN +#define SMP_PIN_CODE_LEN_MIN 6 + +#if BLE_INCLUDED == TRUE && SMP_INCLUDED == TRUE +/* SMP command code */ +#define SMP_OPCODE_PAIRING_REQ 0x01 +#define SMP_OPCODE_PAIRING_RSP 0x02 +#define SMP_OPCODE_CONFIRM 0x03 +#define SMP_OPCODE_RAND 0x04 +#define SMP_OPCODE_PAIRING_FAILED 0x05 +#define SMP_OPCODE_ENCRYPT_INFO 0x06 +#define SMP_OPCODE_MASTER_ID 0x07 +#define SMP_OPCODE_IDENTITY_INFO 0x08 +#define SMP_OPCODE_ID_ADDR 0x09 +#define SMP_OPCODE_SIGN_INFO 0x0A +#define SMP_OPCODE_SEC_REQ 0x0B +#define SMP_OPCODE_PAIR_PUBLIC_KEY 0x0C +#define SMP_OPCODE_PAIR_DHKEY_CHECK 0x0D +#define SMP_OPCODE_PAIR_KEYPR_NOTIF 0x0E +#define SMP_OPCODE_MAX SMP_OPCODE_PAIR_KEYPR_NOTIF +#define SMP_OPCODE_MIN SMP_OPCODE_PAIRING_REQ +#define SMP_OPCODE_PAIR_COMMITM 0x0F +#endif + +/* SMP event type */ +#define SMP_IO_CAP_REQ_EVT 1 /* IO capability request event */ +#define SMP_SEC_REQUEST_EVT 2 /* SMP pairing request */ +#define SMP_PASSKEY_NOTIF_EVT 3 /* passkey notification event */ +#define SMP_PASSKEY_REQ_EVT 4 /* passkey request event */ +#define SMP_OOB_REQ_EVT 5 /* OOB request event */ +#define SMP_NC_REQ_EVT 6 /* Numeric Comparison request event */ +#define SMP_COMPLT_EVT 7 /* SMP complete event */ +#define SMP_PEER_KEYPR_NOT_EVT 8 /* Peer keypress notification received event */ +#define SMP_SC_OOB_REQ_EVT 9 /* SC OOB request event (both local and peer OOB data */ +/* can be expected in response) */ +#define SMP_SC_LOC_OOB_DATA_UP_EVT 10 /* SC OOB local data set is created */ +/* (as result of SMP_CrLocScOobData(...)) */ +#define SMP_BR_KEYS_REQ_EVT 12 /* SMP over BR keys request event */ +typedef UINT8 tSMP_EVT; + + +/* pairing failure reason code */ +#define SMP_PASSKEY_ENTRY_FAIL 0x01 +#define SMP_OOB_FAIL 0x02 +#define SMP_PAIR_AUTH_FAIL 0x03 +#define SMP_CONFIRM_VALUE_ERR 0x04 +#define SMP_PAIR_NOT_SUPPORT 0x05 +#define SMP_ENC_KEY_SIZE 0x06 +#define SMP_INVALID_CMD 0x07 +#define SMP_PAIR_FAIL_UNKNOWN 0x08 +#define SMP_REPEATED_ATTEMPTS 0x09 +#define SMP_INVALID_PARAMETERS 0x0A +#define SMP_DHKEY_CHK_FAIL 0x0B +#define SMP_NUMERIC_COMPAR_FAIL 0x0C +#define SMP_BR_PARING_IN_PROGR 0x0D +#define SMP_XTRANS_DERIVE_NOT_ALLOW 0x0E +#define SMP_MAX_FAIL_RSN_PER_SPEC SMP_XTRANS_DERIVE_NOT_ALLOW + +/* self defined error code */ +#define SMP_PAIR_INTERNAL_ERR (SMP_MAX_FAIL_RSN_PER_SPEC + 0x01) /* 0x0E */ + +/* 0x0F unknown IO capability, unable to decide association model */ +#define SMP_UNKNOWN_IO_CAP (SMP_MAX_FAIL_RSN_PER_SPEC + 0x02) /* 0x0F */ + +#define SMP_INIT_FAIL (SMP_MAX_FAIL_RSN_PER_SPEC + 0x03) /* 0x10 */ +#define SMP_CONFIRM_FAIL (SMP_MAX_FAIL_RSN_PER_SPEC + 0x04) /* 0x11 */ +#define SMP_BUSY (SMP_MAX_FAIL_RSN_PER_SPEC + 0x05) /* 0x12 */ +#define SMP_ENC_FAIL (SMP_MAX_FAIL_RSN_PER_SPEC + 0x06) /* 0x13 */ +#define SMP_STARTED (SMP_MAX_FAIL_RSN_PER_SPEC + 0x07) /* 0x14 */ +#define SMP_RSP_TIMEOUT (SMP_MAX_FAIL_RSN_PER_SPEC + 0x08) /* 0x15 */ +#define SMP_DIV_NOT_AVAIL (SMP_MAX_FAIL_RSN_PER_SPEC + 0x09) /* 0x16 */ + +/* 0x17 unspecified failed reason */ +#define SMP_FAIL (SMP_MAX_FAIL_RSN_PER_SPEC + 0x0A) /* 0x17 */ + +#define SMP_CONN_TOUT (SMP_MAX_FAIL_RSN_PER_SPEC + 0x0B) +#define SMP_SUCCESS 0 + +typedef UINT8 tSMP_STATUS; + + +/* Device IO capability */ +#define SMP_IO_CAP_OUT BTM_IO_CAP_OUT /* DisplayOnly */ +#define SMP_IO_CAP_IO BTM_IO_CAP_IO /* DisplayYesNo */ +#define SMP_IO_CAP_IN BTM_IO_CAP_IN /* KeyboardOnly */ +#define SMP_IO_CAP_NONE BTM_IO_CAP_NONE /* NoInputNoOutput */ +#define SMP_IO_CAP_KBDISP BTM_IO_CAP_KBDISP /* Keyboard Display */ +#define SMP_IO_CAP_MAX BTM_IO_CAP_MAX +typedef UINT8 tSMP_IO_CAP; + +#ifndef SMP_DEFAULT_IO_CAPS +#define SMP_DEFAULT_IO_CAPS SMP_IO_CAP_KBDISP +#endif + +/* OOB data present or not */ +enum { + SMP_OOB_NONE, + SMP_OOB_PRESENT, + SMP_OOB_UNKNOWN +}; +typedef UINT8 tSMP_OOB_FLAG; + +/* type of OOB data required from application */ +enum { + SMP_OOB_INVALID_TYPE, + SMP_OOB_PEER, + SMP_OOB_LOCAL, + SMP_OOB_BOTH +}; +typedef UINT8 tSMP_OOB_DATA_TYPE; + +#define SMP_AUTH_NO_BOND 0x00 +#define SMP_AUTH_GEN_BOND 0x01 //todo sdh change GEN_BOND to BOND + +/* SMP Authentication requirement */ +#define SMP_AUTH_YN_BIT (1 << 2) +#define SMP_SC_SUPPORT_BIT (1 << 3) +#define SMP_KP_SUPPORT_BIT (1 << 4) + +#define SMP_AUTH_MASK (SMP_AUTH_GEN_BOND|SMP_AUTH_YN_BIT|SMP_SC_SUPPORT_BIT|SMP_KP_SUPPORT_BIT) + +#define SMP_AUTH_BOND SMP_AUTH_GEN_BOND + +/* no MITM, No Bonding, encryption only */ +#define SMP_AUTH_NB_ENC_ONLY 0x00 //(SMP_AUTH_MASK | BTM_AUTH_SP_NO) + +/* MITM, No Bonding, Use IO Capability to determine authentication procedure */ +#define SMP_AUTH_NB_IOCAP (SMP_AUTH_NO_BOND | SMP_AUTH_YN_BIT) + +/* No MITM, General Bonding, Encryption only */ +#define SMP_AUTH_GB_ENC_ONLY (SMP_AUTH_GEN_BOND ) + +/* MITM, General Bonding, Use IO Capability to determine authentication procedure */ +#define SMP_AUTH_GB_IOCAP (SMP_AUTH_GEN_BOND | SMP_AUTH_YN_BIT) + +/* Secure Connections, no MITM, no Bonding */ +#define SMP_AUTH_SC_ENC_ONLY (SMP_SC_SUPPORT_BIT) + +/* Secure Connections, no MITM, Bonding */ +#define SMP_AUTH_SC_GB (SMP_SC_SUPPORT_BIT | SMP_AUTH_GEN_BOND) + +/* Secure Connections, MITM, no Bonding */ +#define SMP_AUTH_SC_MITM_NB (SMP_SC_SUPPORT_BIT | SMP_AUTH_YN_BIT | SMP_AUTH_NO_BOND) + +/* Secure Connections, MITM, Bonding */ +#define SMP_AUTH_SC_MITM_GB (SMP_SC_SUPPORT_BIT | SMP_AUTH_YN_BIT | SMP_AUTH_GEN_BOND) + +/* All AuthReq RFU bits are set to 1 - NOTE: reserved bit in Bonding_Flags is not set */ +#define SMP_AUTH_ALL_RFU_SET 0xF8 + +typedef UINT8 tSMP_AUTH_REQ; + +#define SMP_SEC_NONE 0 +#define SMP_SEC_UNAUTHENTICATE (1 << 0) +#define SMP_SEC_AUTHENTICATED (1 << 2) +typedef UINT8 tSMP_SEC_LEVEL; + +/* Maximum Encryption Key Size range */ +#define SMP_ENCR_KEY_SIZE_MIN 7 +#define SMP_ENCR_KEY_SIZE_MAX 16 + +/* SMP key types */ +#define SMP_SEC_KEY_TYPE_ENC (1 << 0) /* encryption key */ +#define SMP_SEC_KEY_TYPE_ID (1 << 1) /* identity key */ +#define SMP_SEC_KEY_TYPE_CSRK (1 << 2) /* slave CSRK */ +#define SMP_SEC_KEY_TYPE_LK (1 << 3) /* BR/EDR link key */ +typedef UINT8 tSMP_KEYS; + +#define SMP_BR_SEC_DEFAULT_KEY (SMP_SEC_KEY_TYPE_ENC | SMP_SEC_KEY_TYPE_ID | \ + SMP_SEC_KEY_TYPE_CSRK) + +/* default security key distribution value */ +#define SMP_SEC_DEFAULT_KEY (SMP_SEC_KEY_TYPE_ENC | SMP_SEC_KEY_TYPE_ID | \ + SMP_SEC_KEY_TYPE_CSRK | SMP_SEC_KEY_TYPE_LK) + +#define SMP_SC_KEY_STARTED 0 /* passkey entry started */ +#define SMP_SC_KEY_ENTERED 1 /* passkey digit entered */ +#define SMP_SC_KEY_ERASED 2 /* passkey digit erased */ +#define SMP_SC_KEY_CLEARED 3 /* passkey cleared */ +#define SMP_SC_KEY_COMPLT 4 /* passkey entry completed */ +#define SMP_SC_KEY_OUT_OF_RANGE 5 /* out of range */ +typedef UINT8 tSMP_SC_KEY_TYPE; + +/* data type for BTM_SP_IO_REQ_EVT */ +typedef struct { + tSMP_IO_CAP io_cap; /* local IO capabilities */ + tSMP_OOB_FLAG oob_data; /* OOB data present (locally) for the peer device */ + tSMP_AUTH_REQ auth_req; /* Authentication required (for local device) */ + UINT8 max_key_size; /* max encryption key size */ + tSMP_KEYS init_keys; /* initiator keys to be distributed */ + tSMP_KEYS resp_keys; /* responder keys */ +} tSMP_IO_REQ; + +typedef struct { + tSMP_STATUS reason; + tSMP_SEC_LEVEL sec_level; + BOOLEAN is_pair_cancel; + BOOLEAN smp_over_br; +} tSMP_CMPL; + +typedef struct { + BT_OCTET32 x; + BT_OCTET32 y; +} tSMP_PUBLIC_KEY; + +/* the data associated with the info sent to the peer via OOB interface */ +typedef struct { + BOOLEAN present; + BT_OCTET16 randomizer; + BT_OCTET16 commitment; + + tBLE_BD_ADDR addr_sent_to; + BT_OCTET32 private_key_used; /* is used to calculate: */ + /* publ_key_used = P-256(private_key_used, curve_p256.G) - send it to the */ + /* other side */ + /* dhkey = P-256(private_key_used, publ key rcvd from the other side) */ + tSMP_PUBLIC_KEY publ_key_used; /* P-256(private_key_used, curve_p256.G) */ +} tSMP_LOC_OOB_DATA; + +/* the data associated with the info received from the peer via OOB interface */ +typedef struct { + BOOLEAN present; + BT_OCTET16 randomizer; + BT_OCTET16 commitment; + tBLE_BD_ADDR addr_rcvd_from; +} tSMP_PEER_OOB_DATA; + +typedef struct { + tSMP_LOC_OOB_DATA loc_oob_data; + tSMP_PEER_OOB_DATA peer_oob_data; +} tSMP_SC_OOB_DATA; + + +typedef union { + UINT32 passkey; + tSMP_IO_REQ io_req; /* IO request */ + tSMP_CMPL cmplt; + tSMP_OOB_DATA_TYPE req_oob_type; + tSMP_LOC_OOB_DATA loc_oob_data; +} tSMP_EVT_DATA; + + +/* AES Encryption output */ +typedef struct { + UINT8 status; + UINT8 param_len; + UINT16 opcode; + UINT8 param_buf[BT_OCTET16_LEN]; +} tSMP_ENC; + +/* Security Manager events - Called by the stack when Security Manager related events occur.*/ +typedef UINT8 (tSMP_CALLBACK) (tSMP_EVT event, BD_ADDR bd_addr, tSMP_EVT_DATA *p_data); + +/* callback function for CMAC algorithm +*/ +typedef void (tCMAC_CMPL_CBACK)(UINT8 *p_mac, UINT16 tlen, UINT32 sign_counter); + +/***************************************************************************** +** External Function Declarations +*****************************************************************************/ +#ifdef __cplusplus +extern "C" +{ +#endif +/* API of SMP */ + +/******************************************************************************* +** +** Function SMP_Init +** +** Description This function initializes the SMP unit. +** +** Returns void +** +*******************************************************************************/ +extern void SMP_Init(void); + +/******************************************************************************* +** +** Function SMP_SetTraceLevel +** +** Description This function sets the trace level for SMP. If called with +** a value of 0xFF, it simply returns the current trace level. +** +** Returns The new or current trace level +** +*******************************************************************************/ +extern UINT8 SMP_SetTraceLevel (UINT8 new_level); + +/******************************************************************************* +** +** Function SMP_Register +** +** Description This function register for the SMP service callback. +** +** Returns void +** +*******************************************************************************/ +extern BOOLEAN SMP_Register (tSMP_CALLBACK *p_cback); + +/******************************************************************************* +** +** Function SMP_Pair +** +** Description This function is called to start a SMP pairing. +** +** Returns SMP_STARTED if bond started, else otherwise exception. +** +*******************************************************************************/ +extern tSMP_STATUS SMP_Pair (BD_ADDR bd_addr); + +/******************************************************************************* +** +** Function SMP_BR_PairWith +** +** Description This function is called to start a SMP pairing over BR/EDR. +** +** Returns SMP_STARTED if pairing started, otherwise reason for failure. +** +*******************************************************************************/ +extern tSMP_STATUS SMP_BR_PairWith (BD_ADDR bd_addr); + +/******************************************************************************* +** +** Function SMP_PairCancel +** +** Description This function is called to cancel a SMP pairing. +** +** Returns TRUE - pairing cancelled +** +*******************************************************************************/ +extern BOOLEAN SMP_PairCancel (BD_ADDR bd_addr); + +/******************************************************************************* +** +** Function SMP_SecurityGrant +** +** Description This function is called to grant security process. +** +** Parameters bd_addr - peer device bd address. +** res - result of the operation SMP_SUCCESS if success. +** Otherwise, SMP_REPEATED_ATTEMPTS is too many attempts. +** +** Returns None +** +*******************************************************************************/ +extern void SMP_SecurityGrant(BD_ADDR bd_addr, UINT8 res); + +/******************************************************************************* +** +** Function SMP_PasskeyReply +** +** Description This function is called after Security Manager submitted +** Passkey request to the application. +** +** Parameters: bd_addr - Address of the device for which PIN was requested +** res - result of the operation SMP_SUCCESS if success +** passkey - numeric value in the range of +** BTM_MIN_PASSKEY_VAL(0) - BTM_MAX_PASSKEY_VAL(999999(0xF423F)). +** +*******************************************************************************/ +extern void SMP_PasskeyReply (BD_ADDR bd_addr, UINT8 res, UINT32 passkey); + +/******************************************************************************* +** +** Function SMP_ConfirmReply +** +** Description This function is called after Security Manager submitted +** numeric comparison request to the application. +** +** Parameters: bd_addr - Address of the device with which numeric +** comparison was requested +** res - comparison result SMP_SUCCESS if success +** +*******************************************************************************/ +extern void SMP_ConfirmReply (BD_ADDR bd_addr, UINT8 res); + +/******************************************************************************* +** +** Function SMP_OobDataReply +** +** Description This function is called to provide the OOB data for +** SMP in response to SMP_OOB_REQ_EVT +** +** Parameters: bd_addr - Address of the peer device +** res - result of the operation SMP_SUCCESS if success +** p_data - SM Randomizer C. +** +*******************************************************************************/ +extern void SMP_OobDataReply(BD_ADDR bd_addr, tSMP_STATUS res, UINT8 len, + UINT8 *p_data); + +/******************************************************************************* +** +** Function SMP_SecureConnectionOobDataReply +** +** Description This function is called to provide the SC OOB data for +** SMP in response to SMP_SC_OOB_REQ_EVT +** +** Parameters: p_data - pointer to the data +** +*******************************************************************************/ +extern void SMP_SecureConnectionOobDataReply(UINT8 *p_data); + +/******************************************************************************* +** +** Function SMP_Encrypt +** +** Description This function is called to encrypt the data with the specified +** key +** +** Parameters: key - Pointer to key key[0] conatins the MSB +** key_len - key length +** plain_text - Pointer to data to be encrypted +** plain_text[0] conatins the MSB +** pt_len - plain text length +** p_out - pointer to the encrypted outputs +** +** Returns Boolean - TRUE: encryption is successful +*******************************************************************************/ +extern BOOLEAN SMP_Encrypt (UINT8 *key, UINT8 key_len, + UINT8 *plain_text, UINT8 pt_len, + tSMP_ENC *p_out); + +/******************************************************************************* +** +** Function SMP_KeypressNotification +** +** Description This function is called to notify SM about Keypress Notification. +** +** Parameters: bd_addr - Address of the device to send keypress +** notification to +** value - keypress notification parameter value +** +*******************************************************************************/ +extern void SMP_KeypressNotification (BD_ADDR bd_addr, UINT8 value); + +/******************************************************************************* +** +** Function SMP_CreateLocalSecureConnectionsOobData +** +** Description This function is called to start creation of local SC OOB +** data set (tSMP_LOC_OOB_DATA). +** +** Parameters: bd_addr - Address of the device to send OOB data block +** to. +** +** Returns Boolean - TRUE: creation of local SC OOB data set started. +*******************************************************************************/ +extern BOOLEAN SMP_CreateLocalSecureConnectionsOobData ( + tBLE_BD_ADDR *addr_to_send_to); + +#ifdef __cplusplus +} +#endif +#endif /* SMP_API_H */ diff --git a/tools/sdk/include/bluedroid/smp_int.h b/tools/sdk/include/bluedroid/smp_int.h new file mode 100644 index 00000000..ad6e99ea --- /dev/null +++ b/tools/sdk/include/bluedroid/smp_int.h @@ -0,0 +1,535 @@ +/****************************************************************************** + * + * Copyright (C) 1999-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 file contains internally used SMP definitions + * + ******************************************************************************/ +#ifndef SMP_INT_H +#define SMP_INT_H + +#if BLE_INCLUDED == TRUE + +#include "btu.h" +#include "btm_ble_api.h" +#include "btm_api.h" +#include "smp_api.h" + +#define SMP_MODEL_ENCRYPTION_ONLY 0 /* Legacy mode, Just Works model */ +#define SMP_MODEL_PASSKEY 1 /* Legacy mode, Passkey Entry model, this side inputs the key */ +#define SMP_MODEL_OOB 2 /* Legacy mode, OOB model */ +#define SMP_MODEL_KEY_NOTIF 3 /* Legacy mode, Passkey Entry model, this side displays the key */ +#define SMP_MODEL_SEC_CONN_JUSTWORKS 4 /* Secure Connections mode, Just Works model */ +#define SMP_MODEL_SEC_CONN_NUM_COMP 5 /* Secure Connections mode, Numeric Comparison model */ +#define SMP_MODEL_SEC_CONN_PASSKEY_ENT 6 /* Secure Connections mode, Passkey Entry model, */ +/* this side inputs the key */ +#define SMP_MODEL_SEC_CONN_PASSKEY_DISP 7 /* Secure Connections mode, Passkey Entry model, */ +/* this side displays the key */ +#define SMP_MODEL_SEC_CONN_OOB 8 /* Secure Connections mode, OOB model */ +#define SMP_MODEL_OUT_OF_RANGE 9 +typedef UINT8 tSMP_ASSO_MODEL; + + +#ifndef SMP_MAX_CONN +#define SMP_MAX_CONN 2 +#endif + +#define SMP_WAIT_FOR_RSP_TOUT 30 + +#define SMP_OPCODE_INIT 0x04 + +/* SMP events */ +#define SMP_PAIRING_REQ_EVT SMP_OPCODE_PAIRING_REQ +#define SMP_PAIRING_RSP_EVT SMP_OPCODE_PAIRING_RSP +#define SMP_CONFIRM_EVT SMP_OPCODE_CONFIRM +#define SMP_RAND_EVT SMP_OPCODE_RAND +#define SMP_PAIRING_FAILED_EVT SMP_OPCODE_PAIRING_FAILED +#define SMP_ENCRPTION_INFO_EVT SMP_OPCODE_ENCRYPT_INFO +#define SMP_MASTER_ID_EVT SMP_OPCODE_MASTER_ID +#define SMP_ID_INFO_EVT SMP_OPCODE_IDENTITY_INFO +#define SMP_ID_ADDR_EVT SMP_OPCODE_ID_ADDR +#define SMP_SIGN_INFO_EVT SMP_OPCODE_SIGN_INFO +#define SMP_SECURITY_REQ_EVT SMP_OPCODE_SEC_REQ + +#define SMP_PAIR_PUBLIC_KEY_EVT SMP_OPCODE_PAIR_PUBLIC_KEY +#define SMP_PAIR_KEYPRESS_NOTIFICATION_EVT SMP_OPCODE_PAIR_KEYPR_NOTIF + +#define SMP_PAIR_COMMITM_EVT SMP_OPCODE_PAIR_COMMITM + +#define SMP_SELF_DEF_EVT (SMP_PAIR_COMMITM_EVT + 1) +#define SMP_KEY_READY_EVT (SMP_SELF_DEF_EVT) +#define SMP_ENCRYPTED_EVT (SMP_SELF_DEF_EVT + 1) +#define SMP_L2CAP_CONN_EVT (SMP_SELF_DEF_EVT + 2) +#define SMP_L2CAP_DISCONN_EVT (SMP_SELF_DEF_EVT + 3) +#define SMP_IO_RSP_EVT (SMP_SELF_DEF_EVT + 4) +#define SMP_API_SEC_GRANT_EVT (SMP_SELF_DEF_EVT + 5) +#define SMP_TK_REQ_EVT (SMP_SELF_DEF_EVT + 6) +#define SMP_AUTH_CMPL_EVT (SMP_SELF_DEF_EVT + 7) +#define SMP_ENC_REQ_EVT (SMP_SELF_DEF_EVT + 8) +#define SMP_BOND_REQ_EVT (SMP_SELF_DEF_EVT + 9) +#define SMP_DISCARD_SEC_REQ_EVT (SMP_SELF_DEF_EVT + 10) + +#define SMP_PAIR_DHKEY_CHCK_EVT SMP_OPCODE_PAIR_DHKEY_CHECK + +#define SMP_PUBL_KEY_EXCH_REQ_EVT (SMP_SELF_DEF_EVT + 11) /* request to start public */ +/* key exchange */ + +#define SMP_LOC_PUBL_KEY_CRTD_EVT (SMP_SELF_DEF_EVT + 12) /* local public key created */ + +#define SMP_BOTH_PUBL_KEYS_RCVD_EVT (SMP_SELF_DEF_EVT + 13) /* both local and peer public */ +/* keys are saved in cb */ + +#define SMP_SC_DHKEY_CMPLT_EVT (SMP_SELF_DEF_EVT + 14) /* DHKey computation is completed,*/ +/* time to start SC phase1 */ + +#define SMP_HAVE_LOC_NONCE_EVT (SMP_SELF_DEF_EVT + 15) /* new local nonce is generated */ +/*and saved in p_cb->rand */ + +#define SMP_SC_PHASE1_CMPLT_EVT (SMP_SELF_DEF_EVT + 16) /* time to start SC phase2 */ + +#define SMP_SC_CALC_NC_EVT (SMP_SELF_DEF_EVT + 17) /* request to calculate number */ +/* for user check. Used only in the */ +/* numeric compare protocol */ + +/* Request to display the number for user check to the user.*/ +/* Used only in the numeric compare protocol */ +#define SMP_SC_DSPL_NC_EVT (SMP_SELF_DEF_EVT + 18) + +#define SMP_SC_NC_OK_EVT (SMP_SELF_DEF_EVT + 19) /* user confirms 'OK' numeric */ +/*comparison request */ + +/* both local and peer DHKey Checks are already present - it is used on slave to prevent race condition */ +#define SMP_SC_2_DHCK_CHKS_PRES_EVT (SMP_SELF_DEF_EVT + 20) + +/* same meaning as SMP_KEY_READY_EVT to separate between SC and legacy actions */ +#define SMP_SC_KEY_READY_EVT (SMP_SELF_DEF_EVT + 21) +#define SMP_KEYPRESS_NOTIFICATION_EVENT (SMP_SELF_DEF_EVT + 22) + +#define SMP_SC_OOB_DATA_EVT (SMP_SELF_DEF_EVT + 23) /* SC OOB data from some */ +/* repository is provided */ + +#define SMP_CR_LOC_SC_OOB_DATA_EVT (SMP_SELF_DEF_EVT + 24) +#define SMP_MAX_EVT SMP_CR_LOC_SC_OOB_DATA_EVT + +typedef UINT8 tSMP_EVENT; + +/* Assumption it's only using the low 8 bits, if bigger than that, need to expand it to 16 bits */ +#define SMP_SEC_KEY_MASK 0x00ff + +/* SMP pairing state */ +enum { + SMP_STATE_IDLE, + SMP_STATE_WAIT_APP_RSP, + SMP_STATE_SEC_REQ_PENDING, + SMP_STATE_PAIR_REQ_RSP, + SMP_STATE_WAIT_CONFIRM, + SMP_STATE_CONFIRM, + SMP_STATE_RAND, + SMP_STATE_PUBLIC_KEY_EXCH, + SMP_STATE_SEC_CONN_PHS1_START, + SMP_STATE_WAIT_COMMITMENT, + SMP_STATE_WAIT_NONCE, + SMP_STATE_SEC_CONN_PHS2_START, + SMP_STATE_WAIT_DHK_CHECK, + SMP_STATE_DHK_CHECK, + SMP_STATE_ENCRYPTION_PENDING, + SMP_STATE_BOND_PENDING, + SMP_STATE_CREATE_LOCAL_SEC_CONN_OOB_DATA, + SMP_STATE_MAX +}; +typedef UINT8 tSMP_STATE; + +/* SMP over BR/EDR events */ +#define SMP_BR_PAIRING_REQ_EVT SMP_OPCODE_PAIRING_REQ +#define SMP_BR_PAIRING_RSP_EVT SMP_OPCODE_PAIRING_RSP +#define SMP_BR_CONFIRM_EVT SMP_OPCODE_CONFIRM /* not expected over BR/EDR */ +#define SMP_BR_RAND_EVT SMP_OPCODE_RAND /* not expected over BR/EDR */ +#define SMP_BR_PAIRING_FAILED_EVT SMP_OPCODE_PAIRING_FAILED +#define SMP_BR_ENCRPTION_INFO_EVT SMP_OPCODE_ENCRYPT_INFO /* not expected over BR/EDR */ +#define SMP_BR_MASTER_ID_EVT SMP_OPCODE_MASTER_ID /* not expected over BR/EDR */ +#define SMP_BR_ID_INFO_EVT SMP_OPCODE_IDENTITY_INFO +#define SMP_BR_ID_ADDR_EVT SMP_OPCODE_ID_ADDR +#define SMP_BR_SIGN_INFO_EVT SMP_OPCODE_SIGN_INFO +#define SMP_BR_SECURITY_REQ_EVT SMP_OPCODE_SEC_REQ /* not expected over BR/EDR */ +#define SMP_BR_PAIR_PUBLIC_KEY_EVT SMP_OPCODE_PAIR_PUBLIC_KEY /* not expected over BR/EDR */ +#define SMP_BR_PAIR_DHKEY_CHCK_EVT SMP_OPCODE_PAIR_DHKEY_CHECK /* not expected over BR/EDR */ +#define SMP_BR_PAIR_KEYPR_NOTIF_EVT SMP_OPCODE_PAIR_KEYPR_NOTIF /* not expected over BR/EDR */ +#define SMP_BR_SELF_DEF_EVT SMP_BR_PAIR_KEYPR_NOTIF_EVT +#define SMP_BR_KEY_READY_EVT (SMP_BR_SELF_DEF_EVT + 1) +#define SMP_BR_ENCRYPTED_EVT (SMP_BR_SELF_DEF_EVT + 2) +#define SMP_BR_L2CAP_CONN_EVT (SMP_BR_SELF_DEF_EVT + 3) +#define SMP_BR_L2CAP_DISCONN_EVT (SMP_BR_SELF_DEF_EVT + 4) +#define SMP_BR_KEYS_RSP_EVT (SMP_BR_SELF_DEF_EVT + 5) +#define SMP_BR_API_SEC_GRANT_EVT (SMP_BR_SELF_DEF_EVT + 6) +#define SMP_BR_TK_REQ_EVT (SMP_BR_SELF_DEF_EVT + 7) +#define SMP_BR_AUTH_CMPL_EVT (SMP_BR_SELF_DEF_EVT + 8) +#define SMP_BR_ENC_REQ_EVT (SMP_BR_SELF_DEF_EVT + 9) +#define SMP_BR_BOND_REQ_EVT (SMP_BR_SELF_DEF_EVT + 10) +#define SMP_BR_DISCARD_SEC_REQ_EVT (SMP_BR_SELF_DEF_EVT + 11) +#define SMP_BR_MAX_EVT (SMP_BR_SELF_DEF_EVT + 12) +typedef UINT8 tSMP_BR_EVENT; + +/* SMP over BR/EDR pairing states */ +enum { + SMP_BR_STATE_IDLE = SMP_STATE_IDLE, + SMP_BR_STATE_WAIT_APP_RSP, + SMP_BR_STATE_PAIR_REQ_RSP, + SMP_BR_STATE_BOND_PENDING, + SMP_BR_STATE_MAX +}; +typedef UINT8 tSMP_BR_STATE; + +/* random and encrption activity state */ +enum { + SMP_GEN_COMPARE = 1, + SMP_GEN_CONFIRM, + + SMP_GEN_DIV_LTK, + SMP_GEN_DIV_CSRK, + SMP_GEN_RAND_V, + SMP_GEN_TK, + SMP_GEN_SRAND_MRAND, + SMP_GEN_SRAND_MRAND_CONT, + SMP_GENERATE_PRIVATE_KEY_0_7, + SMP_GENERATE_PRIVATE_KEY_8_15, + SMP_GENERATE_PRIVATE_KEY_16_23, + SMP_GENERATE_PRIVATE_KEY_24_31, + SMP_GEN_NONCE_0_7, + SMP_GEN_NONCE_8_15 +}; + +enum { + SMP_KEY_TYPE_TK, + SMP_KEY_TYPE_CFM, + SMP_KEY_TYPE_CMP, + SMP_KEY_TYPE_PEER_DHK_CHCK, + SMP_KEY_TYPE_STK, + SMP_KEY_TYPE_LTK +}; +typedef struct { + UINT8 key_type; + UINT8 *p_data; +} tSMP_KEY; + +typedef union { + UINT8 *p_data; /* UINT8 type data pointer */ + tSMP_KEY key; + UINT16 reason; + UINT32 passkey; + tSMP_OOB_DATA_TYPE req_oob_type; +} tSMP_INT_DATA; + +/* internal status mask */ +#define SMP_PAIR_FLAGS_WE_STARTED_DD (1) +#define SMP_PAIR_FLAGS_PEER_STARTED_DD (1 << 1) +#define SMP_PAIR_FLAGS_CMD_CONFIRM (1 << SMP_OPCODE_CONFIRM) /* 1 << 3 */ +#define SMP_PAIR_FLAG_ENC_AFTER_PAIR (1 << 4) +#define SMP_PAIR_FLAG_HAVE_PEER_DHK_CHK (1 << 5) /* used on slave to resolve race condition */ +#define SMP_PAIR_FLAG_HAVE_PEER_PUBL_KEY (1 << 6) /* used on slave to resolve race condition */ +#define SMP_PAIR_FLAG_HAVE_PEER_COMM (1 << 7) /* used to resolve race condition */ +#define SMP_PAIR_FLAG_HAVE_LOCAL_PUBL_KEY (1 << 8) /* used on slave to resolve race condition */ + +/* check if authentication requirement need MITM protection */ +#define SMP_NO_MITM_REQUIRED(x) (((x) & SMP_AUTH_YN_BIT) == 0) + +#define SMP_ENCRYT_KEY_SIZE 16 +#define SMP_ENCRYT_DATA_SIZE 16 +#define SMP_ECNCRPYT_STATUS HCI_SUCCESS + +typedef struct { + BD_ADDR bd_addr; + BT_HDR *p_copy; +} tSMP_REQ_Q_ENTRY; + +/* SMP control block */ +typedef struct { + tSMP_CALLBACK *p_callback; + TIMER_LIST_ENT rsp_timer_ent; + UINT8 trace_level; + BD_ADDR pairing_bda; + tSMP_STATE state; + BOOLEAN derive_lk; + BOOLEAN id_addr_rcvd; + tBLE_ADDR_TYPE id_addr_type; + BD_ADDR id_addr; + BOOLEAN smp_over_br; + tSMP_BR_STATE br_state; /* if SMP over BR/ERD has priority over SMP */ + UINT8 failure; + UINT8 status; + UINT8 role; + UINT16 flags; + UINT8 cb_evt; + tSMP_SEC_LEVEL sec_level; + BOOLEAN connect_initialized; + BT_OCTET16 confirm; + BT_OCTET16 rconfirm; + BT_OCTET16 rrand; /* for SC this is peer nonce */ + BT_OCTET16 rand; /* for SC this is local nonce */ + BT_OCTET32 private_key; + BT_OCTET32 dhkey; + BT_OCTET16 commitment; + BT_OCTET16 remote_commitment; + BT_OCTET16 local_random; /* local randomizer - passkey or OOB randomizer */ + BT_OCTET16 peer_random; /* peer randomizer - passkey or OOB randomizer */ + BT_OCTET16 dhkey_check; + BT_OCTET16 remote_dhkey_check; + tSMP_PUBLIC_KEY loc_publ_key; + tSMP_PUBLIC_KEY peer_publ_key; + tSMP_OOB_DATA_TYPE req_oob_type; + tSMP_SC_OOB_DATA sc_oob_data; + tSMP_IO_CAP peer_io_caps; + tSMP_IO_CAP local_io_capability; + tSMP_OOB_FLAG peer_oob_flag; + tSMP_OOB_FLAG loc_oob_flag; + tSMP_AUTH_REQ peer_auth_req; + tSMP_AUTH_REQ loc_auth_req; + BOOLEAN secure_connections_only_mode_required;/* TRUE if locally SM is required to operate */ + /* either in Secure Connections mode or not at all */ + tSMP_ASSO_MODEL selected_association_model; + BOOLEAN le_secure_connections_mode_is_used; + BOOLEAN le_sc_kp_notif_is_used; + tSMP_SC_KEY_TYPE local_keypress_notification; + tSMP_SC_KEY_TYPE peer_keypress_notification; + UINT8 round; /* authentication stage 1 round for passkey association model */ + UINT32 number_to_display; + BT_OCTET16 mac_key; + UINT8 peer_enc_size; + UINT8 loc_enc_size; + UINT8 peer_i_key; + UINT8 peer_r_key; + UINT8 local_i_key; + UINT8 local_r_key; + + BT_OCTET16 tk; + BT_OCTET16 ltk; + UINT16 div; + BT_OCTET16 csrk; /* storage for local CSRK */ + UINT16 ediv; + BT_OCTET8 enc_rand; + UINT8 rand_enc_proc_state; + UINT8 addr_type; + BD_ADDR local_bda; + BOOLEAN is_pair_cancel; + BOOLEAN discard_sec_req; + UINT8 rcvd_cmd_code; + UINT8 rcvd_cmd_len; + UINT16 total_tx_unacked; + BOOLEAN wait_for_authorization_complete; +} tSMP_CB; + +/* Server Action functions are of this type */ +typedef void (*tSMP_ACT)(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); + + +#ifdef __cplusplus +extern "C" +{ +#endif + +#if SMP_DYNAMIC_MEMORY == FALSE +extern tSMP_CB smp_cb; +#else +extern tSMP_CB *smp_cb_ptr; +#define smp_cb (*smp_cb_ptr) +#endif + +#ifdef __cplusplus +} +#endif + +/* Functions provided by att_main.c */ +extern void smp_init (void); + +/* smp main */ +extern void smp_sm_event(tSMP_CB *p_cb, tSMP_EVENT event, void *p_data); + +extern void smp_proc_sec_request(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_set_fail_nc (BOOLEAN enable); +extern void smp_set_fail_conf (BOOLEAN enable); +extern void smp_set_passk_entry_fail(BOOLEAN enable); +extern void smp_set_oob_fail(BOOLEAN enable); +extern void smp_set_peer_sc_notif(BOOLEAN enable); +extern void smp_aes_cmac_rfc4493_chk (UINT8 *key, UINT8 *msg, UINT8 msg_len, + UINT8 mac_len, UINT8 *mac); +extern void smp_f4_calc_chk (UINT8 *U, UINT8 *V, UINT8 *X, UINT8 *Z, UINT8 *mac); +extern void smp_g2_calc_chk (UINT8 *U, UINT8 *V, UINT8 *X, UINT8 *Y); +extern void smp_h6_calc_chk (UINT8 *key, UINT8 *key_id, UINT8 *mac); +extern void smp_f5_key_calc_chk (UINT8 *w, UINT8 *mac); +extern void smp_f5_mackey_or_ltk_calc_chk(UINT8 *t, UINT8 *counter, + UINT8 *key_id, UINT8 *n1, + UINT8 *n2, UINT8 *a1, UINT8 *a2, + UINT8 *length, UINT8 *mac); +extern void smp_f5_calc_chk (UINT8 *w, UINT8 *n1, UINT8 *n2, UINT8 *a1, UINT8 *a2, + UINT8 *mac_key, UINT8 *ltk); +extern void smp_f6_calc_chk (UINT8 *w, UINT8 *n1, UINT8 *n2, UINT8 *r, + UINT8 *iocap, UINT8 *a1, UINT8 *a2, UINT8 *mac); +/* smp_main */ +extern void smp_sm_event(tSMP_CB *p_cb, tSMP_EVENT event, void *p_data); +extern tSMP_STATE smp_get_state(void); +extern void smp_set_state(tSMP_STATE state); + +/* smp_br_main */ +extern void smp_br_state_machine_event(tSMP_CB *p_cb, tSMP_BR_EVENT event, void *p_data); +extern tSMP_BR_STATE smp_get_br_state(void); +extern void smp_set_br_state(tSMP_BR_STATE state); + + +/* smp_act.c */ +extern void smp_send_pair_req(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_send_confirm(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_send_pair_fail(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_send_rand(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_send_pair_public_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_send_commitment(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_send_dhkey_check(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_send_keypress_notification(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_proc_pair_fail(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_proc_confirm(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_proc_rand(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_process_pairing_public_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_proc_enc_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_proc_master_id(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_proc_id_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_proc_id_addr(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_proc_sec_grant(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_proc_sec_req(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_proc_sl_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_start_enc(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_enc_cmpl(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_proc_discard(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_pairing_cmpl(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_decide_association_model(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_send_app_cback(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_proc_compare(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_check_auth_req(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_process_io_response(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_send_id_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_send_enc_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_send_csrk_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_send_ltk_reply(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_proc_pair_cmd(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_pair_terminate(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_idle_terminate(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_send_pair_rsp(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_key_distribution(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_proc_srk_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_generate_csrk(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_fast_conn_param(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_key_pick_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_both_have_public_keys(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_start_secure_connection_phase1(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_process_local_nonce(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_process_pairing_commitment(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_process_peer_nonce(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_process_dhkey_check(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_match_dhkey_checks(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_process_keypress_notification(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_move_to_secure_connections_phase2(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_phase_2_dhkey_checks_are_present(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_wait_for_both_public_keys(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_start_passkey_verification(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_process_secure_connection_oob_data(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_process_secure_connection_long_term_key(void); +extern void smp_set_local_oob_keys(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_set_local_oob_random_commitment(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_set_derive_link_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_derive_link_key_from_long_term_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_br_process_pairing_command(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_br_process_security_grant(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_br_process_slave_keys_response(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_br_send_pair_response(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_br_check_authorization_request(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_br_select_next_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_br_process_link_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_key_distribution_by_transport(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_br_pairing_complete(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); + +/* smp_l2c */ +extern void smp_l2cap_if_init (void); +extern void smp_data_ind (BD_ADDR bd_addr, BT_HDR *p_buf); + +/* smp_util.c */ +extern BOOLEAN smp_send_cmd(UINT8 cmd_code, tSMP_CB *p_cb); +extern void smp_cb_cleanup(tSMP_CB *p_cb); +extern void smp_reset_control_value(tSMP_CB *p_cb); +extern void smp_proc_pairing_cmpl(tSMP_CB *p_cb); +extern void smp_convert_string_to_tk(BT_OCTET16 tk, UINT32 passkey); +extern void smp_mask_enc_key(UINT8 loc_enc_size, UINT8 *p_data); +extern void smp_rsp_timeout(TIMER_LIST_ENT *p_tle); +extern void smp_xor_128(BT_OCTET16 a, BT_OCTET16 b); +extern BOOLEAN smp_encrypt_data (UINT8 *key, UINT8 key_len, + UINT8 *plain_text, UINT8 pt_len, + tSMP_ENC *p_out); +extern BOOLEAN smp_command_has_invalid_parameters(tSMP_CB *p_cb); +extern void smp_reject_unexpected_pairing_command(BD_ADDR bd_addr); +extern tSMP_ASSO_MODEL smp_select_association_model(tSMP_CB *p_cb); +extern void smp_reverse_array(UINT8 *arr, UINT8 len); +extern UINT8 smp_calculate_random_input(UINT8 *random, UINT8 round); +extern void smp_collect_local_io_capabilities(UINT8 *iocap, tSMP_CB *p_cb); +extern void smp_collect_peer_io_capabilities(UINT8 *iocap, tSMP_CB *p_cb); +extern void smp_collect_local_ble_address(UINT8 *le_addr, tSMP_CB *p_cb); +extern void smp_collect_peer_ble_address(UINT8 *le_addr, tSMP_CB *p_cb); +extern BOOLEAN smp_check_commitment(tSMP_CB *p_cb); +extern void smp_save_secure_connections_long_term_key(tSMP_CB *p_cb); +extern BOOLEAN smp_calculate_f5_mackey_and_long_term_key(tSMP_CB *p_cb); +extern void smp_remove_fixed_channel(tSMP_CB *p_cb); +extern BOOLEAN smp_request_oob_data(tSMP_CB *p_cb); + +/* smp_keys.c */ +extern void smp_generate_srand_mrand_confirm (tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_generate_compare (tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_generate_stk (tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_generate_ltk(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_generate_passkey (tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_generate_rand_cont(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_create_private_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_use_oob_private_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_compute_dhkey(tSMP_CB *p_cb); +extern void smp_calculate_local_commitment(tSMP_CB *p_cb); +extern void smp_calculate_peer_commitment(tSMP_CB *p_cb, BT_OCTET16 output_buf); +extern void smp_calculate_numeric_comparison_display_number(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_calculate_local_dhkey_check(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_calculate_peer_dhkey_check(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_start_nonce_generation(tSMP_CB *p_cb); +extern BOOLEAN smp_calculate_link_key_from_long_term_key(tSMP_CB *p_cb); +extern BOOLEAN smp_calculate_long_term_key_from_link_key(tSMP_CB *p_cb); +extern void smp_calculate_f4(UINT8 *u, UINT8 *v, UINT8 *x, UINT8 z, UINT8 *c); +extern UINT32 smp_calculate_g2(UINT8 *u, UINT8 *v, UINT8 *x, UINT8 *y); +extern BOOLEAN smp_calculate_f5(UINT8 *w, UINT8 *n1, UINT8 *n2, UINT8 *a1, UINT8 *a2, + UINT8 *mac_key, UINT8 *ltk); +extern BOOLEAN smp_calculate_f5_mackey_or_long_term_key(UINT8 *t, UINT8 *counter, + UINT8 *key_id, UINT8 *n1, UINT8 *n2, UINT8 *a1, + UINT8 *a2, UINT8 *length, UINT8 *mac); +extern BOOLEAN smp_calculate_f5_key(UINT8 *w, UINT8 *t); +extern BOOLEAN smp_calculate_f6(UINT8 *w, UINT8 *n1, UINT8 *n2, UINT8 *r, UINT8 *iocap, + UINT8 *a1, UINT8 *a2, UINT8 *f3); +extern BOOLEAN smp_calculate_h6(UINT8 *w, UINT8 *keyid, UINT8 *h2); +#if SMP_DEBUG == TRUE +extern void smp_debug_print_nbyte_little_endian (UINT8 *p, const UINT8 *key_name, + UINT8 len); +#endif + +/* smp_cmac.c */ +extern BOOLEAN aes_cipher_msg_auth_code(BT_OCTET16 key, UINT8 *input, UINT16 length, + UINT16 tlen, UINT8 *p_signature); +extern void print128(BT_OCTET16 x, const UINT8 *key_name); + +#endif + +#endif /* SMP_INT_H */ diff --git a/tools/sdk/include/bluedroid/srvc_api.h b/tools/sdk/include/bluedroid/srvc_api.h new file mode 100644 index 00000000..a7a46b8e --- /dev/null +++ b/tools/sdk/include/bluedroid/srvc_api.h @@ -0,0 +1,210 @@ +/****************************************************************************** + * + * Copyright (C) 1999-2013 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. + * + ******************************************************************************/ + +#ifndef SRVC_DIS_API_H +#define SRVC_DIS_API_H + +#include "bt_target.h" +#include "gatt_api.h" +#include "gattdefs.h" + +#define DIS_SUCCESS GATT_SUCCESS +#define DIS_ILLEGAL_PARAM GATT_ILLEGAL_PARAMETER +#define DIS_NO_RESOURCES GATT_NO_RESOURCES +typedef UINT8 tDIS_STATUS; + + +/***************************************************************************** +** Data structure for DIS +*****************************************************************************/ + +#define DIS_ATTR_SYS_ID_BIT 0x0001 +#define DIS_ATTR_MODEL_NUM_BIT 0x0002 +#define DIS_ATTR_SERIAL_NUM_BIT 0x0004 +#define DIS_ATTR_FW_NUM_BIT 0x0008 +#define DIS_ATTR_HW_NUM_BIT 0x0010 +#define DIS_ATTR_SW_NUM_BIT 0x0020 +#define DIS_ATTR_MANU_NAME_BIT 0x0040 +#define DIS_ATTR_IEEE_DATA_BIT 0x0080 +#define DIS_ATTR_PNP_ID_BIT 0x0100 +typedef UINT16 tDIS_ATTR_MASK; + +#define DIS_ATTR_ALL_MASK 0xffff + +typedef tDIS_ATTR_MASK tDIS_ATTR_BIT ; + +typedef struct { + UINT16 len; + UINT8 *p_data; +} tDIS_STRING; + +typedef struct { + UINT16 vendor_id; + UINT16 product_id; + UINT16 product_version; + UINT8 vendor_id_src; + +} tDIS_PNP_ID; + +typedef union { + UINT64 system_id; + tDIS_PNP_ID pnp_id; + tDIS_STRING data_str; +} tDIS_ATTR; + +#define DIS_MAX_STRING_DATA 7 + +typedef struct { + UINT16 attr_mask; + UINT64 system_id; + tDIS_PNP_ID pnp_id; + UINT8 *data_string[DIS_MAX_STRING_DATA]; +} tDIS_VALUE; + + +typedef void (tDIS_READ_CBACK)(BD_ADDR addr, tDIS_VALUE *p_dis_value); + +/***************************************************************************** +** Data structure used by Battery Service +*****************************************************************************/ +typedef struct { + BD_ADDR remote_bda; + BOOLEAN need_rsp; + UINT16 clt_cfg; +} tBA_WRITE_DATA; + +#define BA_READ_CLT_CFG_REQ 1 +#define BA_READ_PRE_FMT_REQ 2 +#define BA_READ_RPT_REF_REQ 3 +#define BA_READ_LEVEL_REQ 4 +#define BA_WRITE_CLT_CFG_REQ 5 + +typedef void (tBA_CBACK)(UINT8 app_id, UINT8 event, tBA_WRITE_DATA *p_data); + +#define BA_LEVEL_NOTIFY 0x01 +#define BA_LEVEL_PRE_FMT 0x02 +#define BA_LEVEL_RPT_REF 0x04 +typedef UINT8 tBA_LEVEL_DESCR; + +typedef struct { + BOOLEAN is_pri; + tBA_LEVEL_DESCR ba_level_descr; + tGATT_TRANSPORT transport; + tBA_CBACK *p_cback; + +} tBA_REG_INFO; + +typedef union { + UINT8 ba_level; + UINT16 clt_cfg; + tGATT_CHAR_RPT_REF rpt_ref; + tGATT_CHAR_PRES pres_fmt; +} tBA_RSP_DATA; + +/***************************************************************************** +** External Function Declarations +*****************************************************************************/ +#ifdef __cplusplus +extern "C" +{ +#endif +/***************************************************************************** +** Service Engine API +*****************************************************************************/ +/******************************************************************************* +** +** Function srvc_eng_init +** +** Description Initializa the GATT Service engine, register a GATT application +** as for a central service management. +** +*******************************************************************************/ +extern tGATT_STATUS srvc_eng_init (void); + + +/***************************************************************************** +** DIS Server Function +*****************************************************************************/ + +/******************************************************************************* +** +** Function DIS_SrInit +** +** Description Initializa the Device Information Service Server. +** +*******************************************************************************/ +extern tDIS_STATUS DIS_SrInit (tDIS_ATTR_MASK dis_attr_mask); +/******************************************************************************* +** +** Function DIS_SrUpdate +** +** Description Update the DIS server attribute values +** +*******************************************************************************/ +extern tDIS_STATUS DIS_SrUpdate(tDIS_ATTR_BIT dis_attr_bit, tDIS_ATTR *p_info); +/***************************************************************************** +** DIS Client Function +*****************************************************************************/ +/******************************************************************************* +** +** Function DIS_ReadDISInfo +** +** Description Read remote device DIS information. +** +** Returns void +** +*******************************************************************************/ +extern BOOLEAN DIS_ReadDISInfo(BD_ADDR peer_bda, tDIS_READ_CBACK *p_cback, + tDIS_ATTR_MASK mask); + +/******************************************************************************* +** BATTERY SERVICE API +*******************************************************************************/ +/******************************************************************************* +** +** Function Battery_Instantiate +** +** Description Instantiate a Battery service +** +*******************************************************************************/ +extern UINT16 Battery_Instantiate (UINT8 app_id, tBA_REG_INFO *p_reg_info); + +/******************************************************************************* +** +** Function Battery_Rsp +** +** Description Respond to a battery service request +** +*******************************************************************************/ +extern void Battery_Rsp (UINT8 app_id, tGATT_STATUS st, UINT8 event, tBA_RSP_DATA *p_rsp); +/******************************************************************************* +** +** Function Battery_Notify +** +** Description Send battery level notification +** +*******************************************************************************/ +extern void Battery_Notify (UINT8 app_id, BD_ADDR remote_bda, UINT8 battery_level); + + +#ifdef __cplusplus + +} +#endif + +#endif diff --git a/tools/sdk/include/bluedroid/thread.h b/tools/sdk/include/bluedroid/thread.h new file mode 100644 index 00000000..61e9487e --- /dev/null +++ b/tools/sdk/include/bluedroid/thread.h @@ -0,0 +1,73 @@ +// 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 __THREAD_H__ +#define __THREAD_H__ + +#include "freertos/xtensa_api.h" +#include "freertos/FreeRTOSConfig.h" +#include "freertos/FreeRTOS.h" +#include "freertos/queue.h" +#include "freertos/task.h" + +#include "bt_defs.h" + +#define portBASE_TYPE int + +struct bt_task_evt { + uint32_t sig; //task sig + void *par; //point to task param + void *cb; //point to function cb + void *arg; //point to function arg +}; +typedef struct bt_task_evt BtTaskEvt_t; + +typedef bt_status_t (* BtTaskCb_t)(void *arg); + +enum { + SIG_PRF_START_UP = 0xfc, + SIG_PRF_WORK = 0xfd, + SIG_BTU_START_UP = 0xfe, + SIG_BTU_WORK = 0xff, + SIG_BTIF_WORK = 0xff +}; + +#define HCI_HOST_TASK_STACK_SIZE 1500 +#define HCI_HOST_TASK_PRIO (configMAX_PRIORITIES - 2) +#define HCI_HOST_TASK_NAME "hciHostT" +#define HCI_HOST_QUEUE_NUM 40 + +#define HCI_H4_TASK_STACK_SIZE 1500 +#define HCI_H4_TASK_PRIO (configMAX_PRIORITIES - 3) +#define HCI_H4_TASK_NAME "hciH4T" +#define HCI_H4_QUEUE_NUM 60 + +#define BTU_TASK_STACK_SIZE 4096 +#define BTU_TASK_PRIO (configMAX_PRIORITIES - 4) +#define BTU_TASK_NAME "btuT" +#define BTU_QUEUE_NUM 50 + +#define BTC_TASK_STACK_SIZE CONFIG_BTC_TASK_STACK_SIZE //by menuconfig +#define BTC_TASK_NAME "btcT" +#define BTC_TASK_PRIO (configMAX_PRIORITIES - 5) +#define BTC_TASK_QUEUE_NUM 20 + +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); + + +#endif /* __THREAD_H__ */ diff --git a/tools/sdk/include/bluedroid/utl.h b/tools/sdk/include/bluedroid/utl.h new file mode 100644 index 00000000..39dbe297 --- /dev/null +++ b/tools/sdk/include/bluedroid/utl.h @@ -0,0 +1,169 @@ +/****************************************************************************** + * + * 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. + * + ******************************************************************************/ + +/****************************************************************************** + * + * Basic utility functions. + * + ******************************************************************************/ +#ifndef UTL_H +#define UTL_H + +#include "bt_types.h" +// #include "bt_utils.h" + +/***************************************************************************** +** Constants +*****************************************************************************/ +/*** class of device settings ***/ +#define BTA_UTL_SET_COD_MAJOR_MINOR 0x01 +#define BTA_UTL_SET_COD_SERVICE_CLASS 0x02 /* only set the bits in the input */ +#define BTA_UTL_CLR_COD_SERVICE_CLASS 0x04 +#define BTA_UTL_SET_COD_ALL 0x08 /* take service class as the input (may clear some set bits!!) */ +#define BTA_UTL_INIT_COD 0x0a + +/***************************************************************************** +** Type Definitions +*****************************************************************************/ + +/** for utl_set_device_class() **/ +typedef struct { + UINT8 minor; + UINT8 major; + UINT16 service; +} tBTA_UTL_COD; + + +#ifdef __cplusplus +extern "C" +{ +#endif + +/***************************************************************************** +** External Function Declarations +*****************************************************************************/ + +/******************************************************************************* +** +** Function utl_str2int +** +** Description This utility function converts a character string to an +** integer. Acceptable values in string are 0-9. If invalid +** string or string value too large, -1 is returned. +** +** +** Returns Integer value or -1 on error. +** +*******************************************************************************/ +extern INT16 utl_str2int(const char *p_s); + +/******************************************************************************* +** +** Function utl_strucmp +** +** Description This utility function compares two strings in uppercase. +** String p_s must be uppercase. String p_t is converted to +** uppercase if lowercase. If p_s ends first, the substring +** match is counted as a match. +** +** +** Returns 0 if strings match, nonzero otherwise. +** +*******************************************************************************/ +extern int utl_strucmp(const char *p_s, const char *p_t); + +/******************************************************************************* +** +** Function utl_itoa +** +** Description This utility function converts a UINT16 to a string. The +** string is NULL-terminated. The length of the string is +** returned. +** +** +** Returns Length of string. +** +*******************************************************************************/ +extern UINT8 utl_itoa(UINT16 i, char *p_s); + +/******************************************************************************* +** +** Function utl_freebuf +** +** Description This function calls GKI_freebuf to free the buffer passed +** in, if buffer pointer is not NULL, and also initializes +** buffer pointer to NULL. +** +** +** Returns Nothing. +** +*******************************************************************************/ +extern void utl_freebuf(void **p); + +/******************************************************************************* +** +** Function utl_set_device_class +** +** Description This function updates the local Device Class. +** +** Parameters: +** p_cod - Pointer to the device class to set to +** +** cmd - the fields of the device class to update. +** BTA_UTL_SET_COD_MAJOR_MINOR, - overwrite major, minor class +** BTA_UTL_SET_COD_SERVICE_CLASS - set the bits in the input +** BTA_UTL_CLR_COD_SERVICE_CLASS - clear the bits in the input +** BTA_UTL_SET_COD_ALL - overwrite major, minor, set the bits in service class +** BTA_UTL_INIT_COD - overwrite major, minor, and service class +** +** Returns TRUE if successful, Otherwise FALSE +** +*******************************************************************************/ +extern BOOLEAN utl_set_device_class(tBTA_UTL_COD *p_cod, UINT8 cmd); + +/******************************************************************************* +** +** Function utl_isintstr +** +** Description This utility function checks if the given string is an +** integer string or not +** +** +** Returns TRUE if successful, Otherwise FALSE +** +*******************************************************************************/ +extern BOOLEAN utl_isintstr(const char *p_s); + +/******************************************************************************* +** +** Function utl_isdialstr +** +** Description This utility function checks if the given string contains +** only dial digits or not +** +** +** Returns TRUE if successful, Otherwise FALSE +** +*******************************************************************************/ +extern BOOLEAN utl_isdialstr(const char *p_s); + +#ifdef __cplusplus +} +#endif + +#endif /* UTL_H */ diff --git a/tools/sdk/include/bluedroid/version.h b/tools/sdk/include/bluedroid/version.h new file mode 100644 index 00000000..c63b03bd --- /dev/null +++ b/tools/sdk/include/bluedroid/version.h @@ -0,0 +1,31 @@ +/****************************************************************************** + * + * 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 _VERSION_H_ +#define _VERSION_H_ + +#include + +typedef struct { + uint8_t hci_version; + uint16_t hci_revision; + uint8_t lmp_version; + uint16_t manufacturer; + uint16_t lmp_subversion; +} bt_version_t; + +#endif /*_VERSION_H_*/ diff --git a/tools/sdk/include/bluedroid/wx_airsync_prf.h b/tools/sdk/include/bluedroid/wx_airsync_prf.h new file mode 100644 index 00000000..f008ce64 --- /dev/null +++ b/tools/sdk/include/bluedroid/wx_airsync_prf.h @@ -0,0 +1,110 @@ +// 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. + +#include "prf_defs.h" + +#if (WX_AIRSYNC_CFG) + +#include "bt_target.h" +#include "gatt_api.h" +#include "gattdefs.h" +#include "bt_app_api.h" + + +/// Maximum Transmission Unit +#define ATT_DEFAULT_MTU (23) + +#define BLE_WECHAT_MAX_DATA_LEN (ATT_DEFAULT_MTU - 3) + + +//define the key serivce uuid +#define ATT_SVC_AIRSYNC 0xFEE7 +//define the airsync Char uuid +#define ATT_CHAR_AIRSYNC_WIT 0xFEC7 +#define ATT_CHAR_AIRSYBC_NTF 0xFEC8 +#define ATT_CHAR_AIRSYNC_READ 0xFEC9 + + +typedef void (tAIRSYNC_CBACK)(UINT8 app_id, UINT8 event, UINT8 len, UINT8 *data); + + +/// WX AirSync Service Attributes Indexes +enum { + WX_IDX_SVC, + WX_IDX_AIRSYNC_WIT_CHAR, + WX_IDX_AIRSYNC_WIT_VAL, + WX_IDX_AIRSYNC_NTF_CHAR, + WX_IDX_AIRSYNC_NTF_VAL, + WX_IDX_AIRSYNC_READ_CHAR, + WX_IDX_AIRSYNC_READ_VAL, + WX_IDX_AIRSYNC_NTF_CFG, + + WX_IDX_NB, +}; + +typedef struct { + BD_ADDR remote_bda; + BOOLEAN need_rsp; + UINT16 clt_cfg; +} tAirSync_WRITE_DATA; + +typedef struct { + BOOLEAN in_use; + BOOLEAN congest; + UINT16 conn_id; + BOOLEAN connected; + BD_ADDR remote_bda; + UINT32 trans_id; + UINT8 cur_srvc_id; + +} tAirSync_CLCB; + + +typedef struct { + UINT8 app_id; + UINT16 airsync_wirt_hdl; + UINT16 airsync_ntf_hdl; + UINT16 airsync_read_hdl; + UINT16 airsync_cfg_hdl; + + tAIRSYNC_CBACK *p_cback; + +} tAirSync_INST; + + +/* service engine control block */ +typedef struct { + tAirSync_CLCB clcb; /* connection link*/ + tGATT_IF gatt_if; + BOOLEAN enabled; + BOOLEAN is_primery; + tAirSync_INST airsync_inst; + UINT8 inst_id; +} tAIRSYNC_CB_ENV; + +void AirSync_CreateService(void); + +tAirSync_CLCB *airsync_env_clcb_alloc (UINT16 conn_id, BD_ADDR remote_bda); + +UINT16 AirSync_env_find_conn_id_by_bd_adddr(BD_ADDR bda); + +BOOLEAN AirSync_env_clcb_dealloc(UINT16 conn_id); + +tGATT_STATUS AirSync_Init(tAIRSYNC_CBACK *call_back); + +void AirSync_msg_notify(UINT8 len, UINT8 *button_msg); + +extern tAIRSYNC_CB_ENV airsync_cb_env; + +#endif ///WX_AIRSYNC_CFG diff --git a/tools/sdk/include/config/sdkconfig.h b/tools/sdk/include/config/sdkconfig.h index edbb9499..2619565a 100644 --- a/tools/sdk/include/config/sdkconfig.h +++ b/tools/sdk/include/config/sdkconfig.h @@ -5,14 +5,17 @@ * */ #define CONFIG_ESP32_PHY_MAX_TX_POWER 20 +#define CONFIG_PHY_ENABLED 1 #define CONFIG_TRACEMEM_RESERVE_DRAM 0x0 #define CONFIG_FREERTOS_CHECK_STACKOVERFLOW_NONE 1 #define CONFIG_ESPTOOLPY_FLASHSIZE_4MB 1 #define CONFIG_ESPTOOLPY_FLASHFREQ "80m" #define CONFIG_NEWLIB_STDOUT_ADDCR 1 +#define CONFIG_TASK_WDT_CHECK_IDLE_TASK 1 #define CONFIG_ESPTOOLPY_FLASHSIZE "4MB" #define CONFIG_ETHERNET 1 #define CONFIG_EMAC_L2_TO_L3_RX_BUF_MODE 1 +#define CONFIG_INT_WDT 1 #define CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL 1 #define CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS 1 #define CONFIG_BT_RESERVE_DRAM 0x10000 @@ -22,6 +25,7 @@ #define CONFIG_EMAC_TASK_PRIORITY 20 #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_TOOLPREFIX "xtensa-esp32-elf-" #define CONFIG_CONSOLE_UART_NUM 0 @@ -34,11 +38,15 @@ #define CONFIG_LOG_DEFAULT_LEVEL_ERROR 1 #define CONFIG_MBEDTLS_MPI_USE_INTERRUPT 1 #define CONFIG_ESP32_ENABLE_COREDUMP_TO_NONE 1 +#define CONFIG_TASK_WDT 1 #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_BTC_TASK_STACK_SIZE 2048 #define CONFIG_ESPTOOLPY_BEFORE "default_reset" #define CONFIG_LOG_DEFAULT_LEVEL 1 +#define CONFIG_ESP32_PHY_MAX_WIFI_TX_POWER 20 #define CONFIG_ULP_COPROC_ENABLED 1 #define CONFIG_DMA_RX_BUF_NUM 10 #define CONFIG_ESPTOOLPY_FLASHMODE_DIO 1 @@ -76,6 +84,7 @@ #define CONFIG_PARTITION_TABLE_CUSTOM_FILENAME "partitions.csv" #define CONFIG_MBEDTLS_HAVE_TIME 1 #define CONFIG_FREERTOS_ISR_STACKSIZE 1536 +#define CONFIG_OPENSSL_ASSERT_DO_NOTHING 1 #define CONFIG_OPTIMIZATION_LEVEL_DEBUG 1 #define CONFIG_SYSTEM_EVENT_QUEUE_SIZE 32 #define CONFIG_ESP32_WIFI_RX_BUFFER_NUM 25 diff --git a/tools/sdk/include/esp32/esp_panic.h b/tools/sdk/include/esp32/esp_panic.h index aa83c6d3..e9668fac 100644 --- a/tools/sdk/include/esp32/esp_panic.h +++ b/tools/sdk/include/esp32/esp_panic.h @@ -1,6 +1,10 @@ #ifndef PANIC_H #define PANIC_H +#ifdef __cplusplus +extern "C" +{ +#endif #define PANIC_RSN_NONE 0 #define PANIC_RSN_DEBUGEXCEPTION 1 @@ -59,4 +63,8 @@ void esp_clear_watchpoint(int no); #endif +#ifdef __cplusplus +} +#endif + #endif diff --git a/tools/sdk/include/esp32/soc/ledc_struct.h b/tools/sdk/include/esp32/soc/ledc_struct.h index d119289a..c52f6707 100644 --- a/tools/sdk/include/esp32/soc/ledc_struct.h +++ b/tools/sdk/include/esp32/soc/ledc_struct.h @@ -122,6 +122,7 @@ typedef volatile struct { uint32_t lstimer1_ovf: 1; /*The interrupt status bit for low speed channel1 counter overflow event.*/ uint32_t lstimer2_ovf: 1; /*The interrupt status bit for low speed channel2 counter overflow event.*/ uint32_t lstimer3_ovf: 1; /*The interrupt status bit for low speed channel3 counter overflow event.*/ + uint32_t duty_chng_end_hsch0: 1; /*The interrupt enable bit for high speed channel 0 duty change done event.*/ uint32_t duty_chng_end_hsch1: 1; /*The interrupt status bit for high speed channel 1 duty change done event.*/ uint32_t duty_chng_end_hsch2: 1; /*The interrupt status bit for high speed channel 2 duty change done event.*/ uint32_t duty_chng_end_hsch3: 1; /*The interrupt status bit for high speed channel 3 duty change done event.*/ diff --git a/tools/sdk/include/lwip/lwipopts.h b/tools/sdk/include/lwip/lwipopts.h index 638c1f74..dc826494 100644 --- a/tools/sdk/include/lwip/lwipopts.h +++ b/tools/sdk/include/lwip/lwipopts.h @@ -206,6 +206,11 @@ #define DHCP_MAXRTX 0 +/** + * DHCP_DOES_ARP_CHECK==1: Do an ARP check on the offered address. + */ +#define DHCP_DOES_ARP_CHECK CONFIG_LWIP_DHCP_DOES_ARP_CHECK + /* ------------------------------------ ---------- AUTOIP options ---------- diff --git a/tools/sdk/include/lwip/port/lwipopts.h b/tools/sdk/include/lwip/port/lwipopts.h index 638c1f74..dc826494 100644 --- a/tools/sdk/include/lwip/port/lwipopts.h +++ b/tools/sdk/include/lwip/port/lwipopts.h @@ -206,6 +206,11 @@ #define DHCP_MAXRTX 0 +/** + * DHCP_DOES_ARP_CHECK==1: Do an ARP check on the offered address. + */ +#define DHCP_DOES_ARP_CHECK CONFIG_LWIP_DHCP_DOES_ARP_CHECK + /* ------------------------------------ ---------- AUTOIP options ---------- diff --git a/tools/sdk/include/mbedtls/mbedtls/bignum.h b/tools/sdk/include/mbedtls/mbedtls/bignum.h index 23cd5634..46f25076 100644 --- a/tools/sdk/include/mbedtls/mbedtls/bignum.h +++ b/tools/sdk/include/mbedtls/mbedtls/bignum.h @@ -1,78 +1,722 @@ -// 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 __ESP_MBEDTLS_BIGNUM_H__ -#define __ESP_MBEDTLS_BIGNUM_H__ - -#include_next "mbedtls/bignum.h" - /** - * This is a wrapper for the main mbedtls/bignum.h. This wrapper - * provides a few additional ESP32-only functions. + * \file bignum.h * - * This is because we don't set MBEDTLS_BIGNUM_ALT in the same way we - * do for AES, SHA, etc. Because we still use most of the bignum.h - * implementation and just replace a few hardware accelerated - * functions (see MBEDTLS_MPI_EXP_MOD_ALT & MBEDTLS_MPI_MUL_MPI_ALT in - * esp_config.h). + * \brief Multi-precision integer library * - * @note Unlike the other hardware accelerator support functions in esp32/hwcrypto, there is no - * generic "hwcrypto/bignum.h" header for using these functions without mbedTLS. The reason for this - * is that all of the function implementations depend strongly upon the mbedTLS MPI implementation. + * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved + * SPDX-License-Identifier: Apache-2.0 + * + * 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 file is part of mbed TLS (https://tls.mbed.org) */ +#ifndef MBEDTLS_BIGNUM_H +#define MBEDTLS_BIGNUM_H -/** - * @brief Lock access to RSA Accelerator (MPI/bignum operations) - * - * RSA Accelerator hardware unit can only be used by one - * consumer at a time. - * - * @note This function is non-recursive (do not call it twice from the - * same task.) - * - * @note You do not need to call this if you are using the mbedTLS bignum.h - * API or esp_mpi_xxx functions. This function is only needed if you - * want to call ROM RSA functions or access the registers directly. - * - */ -void esp_mpi_acquire_hardware(void); - -/** - * @brief Unlock access to RSA Accelerator (MPI/bignum operations) - * - * Has to be called once for each call to esp_mpi_acquire_hardware(). - * - * @note You do not need to call this if you are using the mbedTLS bignum.h - * API or esp_mpi_xxx functions. This function is only needed if you - * want to call ROM RSA functions or access the registers directly. - */ -void esp_mpi_release_hardware(void); - -/* @brief MPI modular mupltiplication function - * - * Calculates Z = (X * Y) mod M using MPI hardware acceleration. - * - * This is not part of the standard mbedTLS bignum API. - * - * @note All of X, Y & Z should be less than 4096 bit long or an error is returned. - * - * @param Z Result bignum, should be pre-initialised with mbedtls_mpi_init(). - * @param X First multiplication argument. - * @param Y Second multiplication argument. - * @param M Modulus value for result. - * - * @return 0 on success, mbedTLS MPI error codes on failure. - */ -int esp_mpi_mul_mpi_mod(mbedtls_mpi *Z, const mbedtls_mpi *X, const mbedtls_mpi *Y, const mbedtls_mpi *M); - +#if !defined(MBEDTLS_CONFIG_FILE) +#include "config.h" +#else +#include MBEDTLS_CONFIG_FILE #endif + +#include +#include + +#if defined(MBEDTLS_FS_IO) +#include +#endif + +#define MBEDTLS_ERR_MPI_FILE_IO_ERROR -0x0002 /**< An error occurred while reading from or writing to a file. */ +#define MBEDTLS_ERR_MPI_BAD_INPUT_DATA -0x0004 /**< Bad input parameters to function. */ +#define MBEDTLS_ERR_MPI_INVALID_CHARACTER -0x0006 /**< There is an invalid character in the digit string. */ +#define MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL -0x0008 /**< The buffer is too small to write to. */ +#define MBEDTLS_ERR_MPI_NEGATIVE_VALUE -0x000A /**< The input arguments are negative or result in illegal output. */ +#define MBEDTLS_ERR_MPI_DIVISION_BY_ZERO -0x000C /**< The input argument for division is zero, which is not allowed. */ +#define MBEDTLS_ERR_MPI_NOT_ACCEPTABLE -0x000E /**< The input arguments are not acceptable. */ +#define MBEDTLS_ERR_MPI_ALLOC_FAILED -0x0010 /**< Memory allocation failed. */ + +#define MBEDTLS_MPI_CHK(f) do { if( ( ret = f ) != 0 ) goto cleanup; } while( 0 ) + +/* + * Maximum size MPIs are allowed to grow to in number of limbs. + */ +#define MBEDTLS_MPI_MAX_LIMBS 10000 + +#if !defined(MBEDTLS_MPI_WINDOW_SIZE) +/* + * Maximum window size used for modular exponentiation. Default: 6 + * Minimum value: 1. Maximum value: 6. + * + * Result is an array of ( 2 << MBEDTLS_MPI_WINDOW_SIZE ) MPIs used + * for the sliding window calculation. (So 64 by default) + * + * Reduction in size, reduces speed. + */ +#define MBEDTLS_MPI_WINDOW_SIZE 6 /**< Maximum windows size used. */ +#endif /* !MBEDTLS_MPI_WINDOW_SIZE */ + +#if !defined(MBEDTLS_MPI_MAX_SIZE) +/* + * Maximum size of MPIs allowed in bits and bytes for user-MPIs. + * ( Default: 512 bytes => 4096 bits, Maximum tested: 2048 bytes => 16384 bits ) + * + * Note: Calculations can results temporarily in larger MPIs. So the number + * of limbs required (MBEDTLS_MPI_MAX_LIMBS) is higher. + */ +#define MBEDTLS_MPI_MAX_SIZE 1024 /**< Maximum number of bytes for usable MPIs. */ +#endif /* !MBEDTLS_MPI_MAX_SIZE */ + +#define MBEDTLS_MPI_MAX_BITS ( 8 * MBEDTLS_MPI_MAX_SIZE ) /**< Maximum number of bits for usable MPIs. */ + +/* + * When reading from files with mbedtls_mpi_read_file() and writing to files with + * mbedtls_mpi_write_file() the buffer should have space + * for a (short) label, the MPI (in the provided radix), the newline + * characters and the '\0'. + * + * By default we assume at least a 10 char label, a minimum radix of 10 + * (decimal) and a maximum of 4096 bit numbers (1234 decimal chars). + * Autosized at compile time for at least a 10 char label, a minimum radix + * of 10 (decimal) for a number of MBEDTLS_MPI_MAX_BITS size. + * + * This used to be statically sized to 1250 for a maximum of 4096 bit + * numbers (1234 decimal chars). + * + * Calculate using the formula: + * MBEDTLS_MPI_RW_BUFFER_SIZE = ceil(MBEDTLS_MPI_MAX_BITS / ln(10) * ln(2)) + + * LabelSize + 6 + */ +#define MBEDTLS_MPI_MAX_BITS_SCALE100 ( 100 * MBEDTLS_MPI_MAX_BITS ) +#define MBEDTLS_LN_2_DIV_LN_10_SCALE100 332 +#define MBEDTLS_MPI_RW_BUFFER_SIZE ( ((MBEDTLS_MPI_MAX_BITS_SCALE100 + MBEDTLS_LN_2_DIV_LN_10_SCALE100 - 1) / MBEDTLS_LN_2_DIV_LN_10_SCALE100) + 10 + 6 ) + +#if !defined(MBEDTLS_BIGNUM_ALT) + +/* + * Define the base integer type, architecture-wise. + * + * 32-bit integers can be forced on 64-bit arches (eg. for testing purposes) + * by defining MBEDTLS_HAVE_INT32 and undefining MBEDTLS_HAVE_ASM + */ +#if ( ! defined(MBEDTLS_HAVE_INT32) && \ + defined(_MSC_VER) && defined(_M_AMD64) ) + #define MBEDTLS_HAVE_INT64 + typedef int64_t mbedtls_mpi_sint; + typedef uint64_t mbedtls_mpi_uint; +#else + #if ( ! defined(MBEDTLS_HAVE_INT32) && \ + defined(__GNUC__) && ( \ + defined(__amd64__) || defined(__x86_64__) || \ + defined(__ppc64__) || defined(__powerpc64__) || \ + defined(__ia64__) || defined(__alpha__) || \ + (defined(__sparc__) && defined(__arch64__)) || \ + defined(__s390x__) || defined(__mips64) ) ) + #define MBEDTLS_HAVE_INT64 + typedef int64_t mbedtls_mpi_sint; + typedef uint64_t mbedtls_mpi_uint; + /* mbedtls_t_udbl defined as 128-bit unsigned int */ + typedef unsigned int mbedtls_t_udbl __attribute__((mode(TI))); + #define MBEDTLS_HAVE_UDBL + #else + #define MBEDTLS_HAVE_INT32 + typedef int32_t mbedtls_mpi_sint; + typedef uint32_t mbedtls_mpi_uint; + typedef uint64_t mbedtls_t_udbl; + #define MBEDTLS_HAVE_UDBL + #endif /* !MBEDTLS_HAVE_INT32 && __GNUC__ && 64-bit platform */ +#endif /* !MBEDTLS_HAVE_INT32 && _MSC_VER && _M_AMD64 */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * \brief MPI structure + */ +typedef struct +{ + int s; /*!< integer sign */ + size_t n; /*!< total # of limbs */ + mbedtls_mpi_uint *p; /*!< pointer to limbs */ +} +mbedtls_mpi; + +/** + * \brief Initialize one MPI (make internal references valid) + * This just makes it ready to be set or freed, + * but does not define a value for the MPI. + * + * \param X One MPI to initialize. + */ +void mbedtls_mpi_init( mbedtls_mpi *X ); + +/** + * \brief Unallocate one MPI + * + * \param X One MPI to unallocate. + */ +void mbedtls_mpi_free( mbedtls_mpi *X ); + +/** + * \brief Enlarge to the specified number of limbs + * + * \param X MPI to grow + * \param nblimbs The target number of limbs + * + * \return 0 if successful, + * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed + */ +int mbedtls_mpi_grow( mbedtls_mpi *X, size_t nblimbs ); + +/** + * \brief Resize down, keeping at least the specified number of limbs + * + * \param X MPI to shrink + * \param nblimbs The minimum number of limbs to keep + * + * \return 0 if successful, + * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed + */ +int mbedtls_mpi_shrink( mbedtls_mpi *X, size_t nblimbs ); + +/** + * \brief Copy the contents of Y into X + * + * \param X Destination MPI + * \param Y Source MPI + * + * \return 0 if successful, + * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed + */ +int mbedtls_mpi_copy( mbedtls_mpi *X, const mbedtls_mpi *Y ); + +/** + * \brief Swap the contents of X and Y + * + * \param X First MPI value + * \param Y Second MPI value + */ +void mbedtls_mpi_swap( mbedtls_mpi *X, mbedtls_mpi *Y ); + +/** + * \brief Safe conditional assignement X = Y if assign is 1 + * + * \param X MPI to conditionally assign to + * \param Y Value to be assigned + * \param assign 1: perform the assignment, 0: keep X's original value + * + * \return 0 if successful, + * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed, + * + * \note This function is equivalent to + * if( assign ) mbedtls_mpi_copy( X, Y ); + * except that it avoids leaking any information about whether + * the assignment was done or not (the above code may leak + * information through branch prediction and/or memory access + * patterns analysis). + */ +int mbedtls_mpi_safe_cond_assign( mbedtls_mpi *X, const mbedtls_mpi *Y, unsigned char assign ); + +/** + * \brief Safe conditional swap X <-> Y if swap is 1 + * + * \param X First mbedtls_mpi value + * \param Y Second mbedtls_mpi value + * \param assign 1: perform the swap, 0: keep X and Y's original values + * + * \return 0 if successful, + * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed, + * + * \note This function is equivalent to + * if( assign ) mbedtls_mpi_swap( X, Y ); + * except that it avoids leaking any information about whether + * the assignment was done or not (the above code may leak + * information through branch prediction and/or memory access + * patterns analysis). + */ +int mbedtls_mpi_safe_cond_swap( mbedtls_mpi *X, mbedtls_mpi *Y, unsigned char assign ); + +/** + * \brief Set value from integer + * + * \param X MPI to set + * \param z Value to use + * + * \return 0 if successful, + * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed + */ +int mbedtls_mpi_lset( mbedtls_mpi *X, mbedtls_mpi_sint z ); + +/** + * \brief Get a specific bit from X + * + * \param X MPI to use + * \param pos Zero-based index of the bit in X + * + * \return Either a 0 or a 1 + */ +int mbedtls_mpi_get_bit( const mbedtls_mpi *X, size_t pos ); + +/** + * \brief Set a bit of X to a specific value of 0 or 1 + * + * \note Will grow X if necessary to set a bit to 1 in a not yet + * existing limb. Will not grow if bit should be set to 0 + * + * \param X MPI to use + * \param pos Zero-based index of the bit in X + * \param val The value to set the bit to (0 or 1) + * + * \return 0 if successful, + * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed, + * MBEDTLS_ERR_MPI_BAD_INPUT_DATA if val is not 0 or 1 + */ +int mbedtls_mpi_set_bit( mbedtls_mpi *X, size_t pos, unsigned char val ); + +/** + * \brief Return the number of zero-bits before the least significant + * '1' bit + * + * Note: Thus also the zero-based index of the least significant '1' bit + * + * \param X MPI to use + */ +size_t mbedtls_mpi_lsb( const mbedtls_mpi *X ); + +/** + * \brief Return the number of bits up to and including the most + * significant '1' bit' + * + * Note: Thus also the one-based index of the most significant '1' bit + * + * \param X MPI to use + */ +size_t mbedtls_mpi_bitlen( const mbedtls_mpi *X ); + +/** + * \brief Return the total size in bytes + * + * \param X MPI to use + */ +size_t mbedtls_mpi_size( const mbedtls_mpi *X ); + +/** + * \brief Import from an ASCII string + * + * \param X Destination MPI + * \param radix Input numeric base + * \param s Null-terminated string buffer + * + * \return 0 if successful, or a MBEDTLS_ERR_MPI_XXX error code + */ +int mbedtls_mpi_read_string( mbedtls_mpi *X, int radix, const char *s ); + +/** + * \brief Export into an ASCII string + * + * \param X Source MPI + * \param radix Output numeric base + * \param buf Buffer to write the string to + * \param buflen Length of buf + * \param olen Length of the string written, including final NUL byte + * + * \return 0 if successful, or a MBEDTLS_ERR_MPI_XXX error code. + * *olen is always updated to reflect the amount + * of data that has (or would have) been written. + * + * \note Call this function with buflen = 0 to obtain the + * minimum required buffer size in *olen. + */ +int mbedtls_mpi_write_string( const mbedtls_mpi *X, int radix, + char *buf, size_t buflen, size_t *olen ); + +#if defined(MBEDTLS_FS_IO) +/** + * \brief Read X from an opened file + * + * \param X Destination MPI + * \param radix Input numeric base + * \param fin Input file handle + * + * \return 0 if successful, MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if + * the file read buffer is too small or a + * MBEDTLS_ERR_MPI_XXX error code + */ +int mbedtls_mpi_read_file( mbedtls_mpi *X, int radix, FILE *fin ); + +/** + * \brief Write X into an opened file, or stdout if fout is NULL + * + * \param p Prefix, can be NULL + * \param X Source MPI + * \param radix Output numeric base + * \param fout Output file handle (can be NULL) + * + * \return 0 if successful, or a MBEDTLS_ERR_MPI_XXX error code + * + * \note Set fout == NULL to print X on the console. + */ +int mbedtls_mpi_write_file( const char *p, const mbedtls_mpi *X, int radix, FILE *fout ); +#endif /* MBEDTLS_FS_IO */ + +/** + * \brief Import X from unsigned binary data, big endian + * + * \param X Destination MPI + * \param buf Input buffer + * \param buflen Input buffer size + * + * \return 0 if successful, + * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed + */ +int mbedtls_mpi_read_binary( mbedtls_mpi *X, const unsigned char *buf, size_t buflen ); + +/** + * \brief Export X into unsigned binary data, big endian. + * Always fills the whole buffer, which will start with zeros + * if the number is smaller. + * + * \param X Source MPI + * \param buf Output buffer + * \param buflen Output buffer size + * + * \return 0 if successful, + * MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if buf isn't large enough + */ +int mbedtls_mpi_write_binary( const mbedtls_mpi *X, unsigned char *buf, size_t buflen ); + +/** + * \brief Left-shift: X <<= count + * + * \param X MPI to shift + * \param count Amount to shift + * + * \return 0 if successful, + * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed + */ +int mbedtls_mpi_shift_l( mbedtls_mpi *X, size_t count ); + +/** + * \brief Right-shift: X >>= count + * + * \param X MPI to shift + * \param count Amount to shift + * + * \return 0 if successful, + * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed + */ +int mbedtls_mpi_shift_r( mbedtls_mpi *X, size_t count ); + +/** + * \brief Compare unsigned values + * + * \param X Left-hand MPI + * \param Y Right-hand MPI + * + * \return 1 if |X| is greater than |Y|, + * -1 if |X| is lesser than |Y| or + * 0 if |X| is equal to |Y| + */ +int mbedtls_mpi_cmp_abs( const mbedtls_mpi *X, const mbedtls_mpi *Y ); + +/** + * \brief Compare signed values + * + * \param X Left-hand MPI + * \param Y Right-hand MPI + * + * \return 1 if X is greater than Y, + * -1 if X is lesser than Y or + * 0 if X is equal to Y + */ +int mbedtls_mpi_cmp_mpi( const mbedtls_mpi *X, const mbedtls_mpi *Y ); + +/** + * \brief Compare signed values + * + * \param X Left-hand MPI + * \param z The integer value to compare to + * + * \return 1 if X is greater than z, + * -1 if X is lesser than z or + * 0 if X is equal to z + */ +int mbedtls_mpi_cmp_int( const mbedtls_mpi *X, mbedtls_mpi_sint z ); + +/** + * \brief Unsigned addition: X = |A| + |B| + * + * \param X Destination MPI + * \param A Left-hand MPI + * \param B Right-hand MPI + * + * \return 0 if successful, + * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed + */ +int mbedtls_mpi_add_abs( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B ); + +/** + * \brief Unsigned subtraction: X = |A| - |B| + * + * \param X Destination MPI + * \param A Left-hand MPI + * \param B Right-hand MPI + * + * \return 0 if successful, + * MBEDTLS_ERR_MPI_NEGATIVE_VALUE if B is greater than A + */ +int mbedtls_mpi_sub_abs( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B ); + +/** + * \brief Signed addition: X = A + B + * + * \param X Destination MPI + * \param A Left-hand MPI + * \param B Right-hand MPI + * + * \return 0 if successful, + * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed + */ +int mbedtls_mpi_add_mpi( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B ); + +/** + * \brief Signed subtraction: X = A - B + * + * \param X Destination MPI + * \param A Left-hand MPI + * \param B Right-hand MPI + * + * \return 0 if successful, + * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed + */ +int mbedtls_mpi_sub_mpi( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B ); + +/** + * \brief Signed addition: X = A + b + * + * \param X Destination MPI + * \param A Left-hand MPI + * \param b The integer value to add + * + * \return 0 if successful, + * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed + */ +int mbedtls_mpi_add_int( mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_sint b ); + +/** + * \brief Signed subtraction: X = A - b + * + * \param X Destination MPI + * \param A Left-hand MPI + * \param b The integer value to subtract + * + * \return 0 if successful, + * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed + */ +int mbedtls_mpi_sub_int( mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_sint b ); + +/** + * \brief Baseline multiplication: X = A * B + * + * \param X Destination MPI + * \param A Left-hand MPI + * \param B Right-hand MPI + * + * \return 0 if successful, + * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed + */ +int mbedtls_mpi_mul_mpi( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B ); + +/** + * \brief Baseline multiplication: X = A * b + * + * \param X Destination MPI + * \param A Left-hand MPI + * \param b The unsigned integer value to multiply with + * + * \note b is unsigned + * + * \return 0 if successful, + * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed + */ +int mbedtls_mpi_mul_int( mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_uint b ); + +/** + * \brief Division by mbedtls_mpi: A = Q * B + R + * + * \param Q Destination MPI for the quotient + * \param R Destination MPI for the rest value + * \param A Left-hand MPI + * \param B Right-hand MPI + * + * \return 0 if successful, + * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed, + * MBEDTLS_ERR_MPI_DIVISION_BY_ZERO if B == 0 + * + * \note Either Q or R can be NULL. + */ +int mbedtls_mpi_div_mpi( mbedtls_mpi *Q, mbedtls_mpi *R, const mbedtls_mpi *A, const mbedtls_mpi *B ); + +/** + * \brief Division by int: A = Q * b + R + * + * \param Q Destination MPI for the quotient + * \param R Destination MPI for the rest value + * \param A Left-hand MPI + * \param b Integer to divide by + * + * \return 0 if successful, + * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed, + * MBEDTLS_ERR_MPI_DIVISION_BY_ZERO if b == 0 + * + * \note Either Q or R can be NULL. + */ +int mbedtls_mpi_div_int( mbedtls_mpi *Q, mbedtls_mpi *R, const mbedtls_mpi *A, mbedtls_mpi_sint b ); + +/** + * \brief Modulo: R = A mod B + * + * \param R Destination MPI for the rest value + * \param A Left-hand MPI + * \param B Right-hand MPI + * + * \return 0 if successful, + * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed, + * MBEDTLS_ERR_MPI_DIVISION_BY_ZERO if B == 0, + * MBEDTLS_ERR_MPI_NEGATIVE_VALUE if B < 0 + */ +int mbedtls_mpi_mod_mpi( mbedtls_mpi *R, const mbedtls_mpi *A, const mbedtls_mpi *B ); + +/** + * \brief Modulo: r = A mod b + * + * \param r Destination mbedtls_mpi_uint + * \param A Left-hand MPI + * \param b Integer to divide by + * + * \return 0 if successful, + * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed, + * MBEDTLS_ERR_MPI_DIVISION_BY_ZERO if b == 0, + * MBEDTLS_ERR_MPI_NEGATIVE_VALUE if b < 0 + */ +int mbedtls_mpi_mod_int( mbedtls_mpi_uint *r, const mbedtls_mpi *A, mbedtls_mpi_sint b ); + +/** + * \brief Sliding-window exponentiation: X = A^E mod N + * + * \param X Destination MPI + * \param A Left-hand MPI + * \param E Exponent MPI + * \param N Modular MPI + * \param _RR Speed-up MPI used for recalculations + * + * \return 0 if successful, + * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed, + * MBEDTLS_ERR_MPI_BAD_INPUT_DATA if N is negative or even or + * if E is negative + * + * \note _RR is used to avoid re-computing R*R mod N across + * multiple calls, which speeds up things a bit. It can + * be set to NULL if the extra performance is unneeded. + */ +int mbedtls_mpi_exp_mod( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *E, const mbedtls_mpi *N, mbedtls_mpi *_RR ); + +/** + * \brief Fill an MPI X with size bytes of random + * + * \param X Destination MPI + * \param size Size in bytes + * \param f_rng RNG function + * \param p_rng RNG parameter + * + * \return 0 if successful, + * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed + */ +int mbedtls_mpi_fill_random( mbedtls_mpi *X, size_t size, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng ); + +/** + * \brief Greatest common divisor: G = gcd(A, B) + * + * \param G Destination MPI + * \param A Left-hand MPI + * \param B Right-hand MPI + * + * \return 0 if successful, + * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed + */ +int mbedtls_mpi_gcd( mbedtls_mpi *G, const mbedtls_mpi *A, const mbedtls_mpi *B ); + +/** + * \brief Modular inverse: X = A^-1 mod N + * + * \param X Destination MPI + * \param A Left-hand MPI + * \param N Right-hand MPI + * + * \return 0 if successful, + * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed, + * MBEDTLS_ERR_MPI_BAD_INPUT_DATA if N is negative or nil + MBEDTLS_ERR_MPI_NOT_ACCEPTABLE if A has no inverse mod N + */ +int mbedtls_mpi_inv_mod( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *N ); + +/** + * \brief Miller-Rabin primality test + * + * \param X MPI to check + * \param f_rng RNG function + * \param p_rng RNG parameter + * + * \return 0 if successful (probably prime), + * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed, + * MBEDTLS_ERR_MPI_NOT_ACCEPTABLE if X is not prime + */ +int mbedtls_mpi_is_prime( const mbedtls_mpi *X, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng ); + +/** + * \brief Prime number generation + * + * \param X Destination MPI + * \param nbits Required size of X in bits + * ( 3 <= nbits <= MBEDTLS_MPI_MAX_BITS ) + * \param dh_flag If 1, then (X-1)/2 will be prime too + * \param f_rng RNG function + * \param p_rng RNG parameter + * + * \return 0 if successful (probably prime), + * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed, + * MBEDTLS_ERR_MPI_BAD_INPUT_DATA if nbits is < 3 + */ +int mbedtls_mpi_gen_prime( mbedtls_mpi *X, size_t nbits, int dh_flag, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng ); +#else /* MBEDTLS_BIGNUM_ALT */ +#include "bignum_alt.h" +#endif /* MBEDTLS_BIGNUM_ALT */ + +/** + * \brief Checkup routine + * + * \return 0 if successful, or 1 if the test failed + */ +int mbedtls_mpi_self_test( int verbose ); + +#ifdef __cplusplus +} +#endif + +#endif /* bignum.h */ diff --git a/tools/sdk/include/mbedtls/aes_alt.h b/tools/sdk/include/mbedtls_port/aes_alt.h similarity index 100% rename from tools/sdk/include/mbedtls/aes_alt.h rename to tools/sdk/include/mbedtls_port/aes_alt.h diff --git a/tools/sdk/include/mbedtls_port/mbedtls/bignum.h b/tools/sdk/include/mbedtls_port/mbedtls/bignum.h new file mode 100644 index 00000000..23cd5634 --- /dev/null +++ b/tools/sdk/include/mbedtls_port/mbedtls/bignum.h @@ -0,0 +1,78 @@ +// 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 __ESP_MBEDTLS_BIGNUM_H__ +#define __ESP_MBEDTLS_BIGNUM_H__ + +#include_next "mbedtls/bignum.h" + +/** + * This is a wrapper for the main mbedtls/bignum.h. This wrapper + * provides a few additional ESP32-only functions. + * + * This is because we don't set MBEDTLS_BIGNUM_ALT in the same way we + * do for AES, SHA, etc. Because we still use most of the bignum.h + * implementation and just replace a few hardware accelerated + * functions (see MBEDTLS_MPI_EXP_MOD_ALT & MBEDTLS_MPI_MUL_MPI_ALT in + * esp_config.h). + * + * @note Unlike the other hardware accelerator support functions in esp32/hwcrypto, there is no + * generic "hwcrypto/bignum.h" header for using these functions without mbedTLS. The reason for this + * is that all of the function implementations depend strongly upon the mbedTLS MPI implementation. + */ + +/** + * @brief Lock access to RSA Accelerator (MPI/bignum operations) + * + * RSA Accelerator hardware unit can only be used by one + * consumer at a time. + * + * @note This function is non-recursive (do not call it twice from the + * same task.) + * + * @note You do not need to call this if you are using the mbedTLS bignum.h + * API or esp_mpi_xxx functions. This function is only needed if you + * want to call ROM RSA functions or access the registers directly. + * + */ +void esp_mpi_acquire_hardware(void); + +/** + * @brief Unlock access to RSA Accelerator (MPI/bignum operations) + * + * Has to be called once for each call to esp_mpi_acquire_hardware(). + * + * @note You do not need to call this if you are using the mbedTLS bignum.h + * API or esp_mpi_xxx functions. This function is only needed if you + * want to call ROM RSA functions or access the registers directly. + */ +void esp_mpi_release_hardware(void); + +/* @brief MPI modular mupltiplication function + * + * Calculates Z = (X * Y) mod M using MPI hardware acceleration. + * + * This is not part of the standard mbedTLS bignum API. + * + * @note All of X, Y & Z should be less than 4096 bit long or an error is returned. + * + * @param Z Result bignum, should be pre-initialised with mbedtls_mpi_init(). + * @param X First multiplication argument. + * @param Y Second multiplication argument. + * @param M Modulus value for result. + * + * @return 0 on success, mbedTLS MPI error codes on failure. + */ +int esp_mpi_mul_mpi_mod(mbedtls_mpi *Z, const mbedtls_mpi *X, const mbedtls_mpi *Y, const mbedtls_mpi *M); + +#endif diff --git a/tools/sdk/include/mbedtls/mbedtls/esp_config.h b/tools/sdk/include/mbedtls_port/mbedtls/esp_config.h similarity index 100% rename from tools/sdk/include/mbedtls/mbedtls/esp_config.h rename to tools/sdk/include/mbedtls_port/mbedtls/esp_config.h diff --git a/tools/sdk/include/mbedtls/sha1_alt.h b/tools/sdk/include/mbedtls_port/sha1_alt.h similarity index 100% rename from tools/sdk/include/mbedtls/sha1_alt.h rename to tools/sdk/include/mbedtls_port/sha1_alt.h diff --git a/tools/sdk/include/mbedtls/sha256_alt.h b/tools/sdk/include/mbedtls_port/sha256_alt.h similarity index 100% rename from tools/sdk/include/mbedtls/sha256_alt.h rename to tools/sdk/include/mbedtls_port/sha256_alt.h diff --git a/tools/sdk/include/mbedtls/sha512_alt.h b/tools/sdk/include/mbedtls_port/sha512_alt.h similarity index 100% rename from tools/sdk/include/mbedtls/sha512_alt.h rename to tools/sdk/include/mbedtls_port/sha512_alt.h diff --git a/tools/sdk/include/openssl/internal/ssl_dbg.h b/tools/sdk/include/openssl/internal/ssl_dbg.h index b4c07546..12ba25f9 100644 --- a/tools/sdk/include/openssl/internal/ssl_dbg.h +++ b/tools/sdk/include/openssl/internal/ssl_dbg.h @@ -22,72 +22,170 @@ extern "C" { #endif -#ifndef SSL_DEBUG_ENBALE -#define SSL_DEBUG_ENBALE 0 -#endif - -#ifndef SSL_DEBUG_LEVEL -#define SSL_DEBUG_LEVEL 0 -#endif - -#ifndef SSL_ASSERT_ENABLE -#define SSL_ASSERT_ENABLE 0 -#endif - -#ifndef SSL_DEBUG_LOCATION_ENABLE -#define SSL_DEBUG_LOCATION_ENABLE 0 -#endif - -#if SSL_DEBUG_ENBALE - #if !defined(SSL_PRINT_LOG) || !defined(SSL_ERROR_LOG) || !defined(SSL_LOCAL_LOG) - #include "stdio.h" - extern int printf(const char *fmt, ...); - #ifndef SSL_PRINT_LOG - #define SSL_PRINT_LOG printf - #endif - #ifndef SSL_ERROR_LOG - #define SSL_ERROR_LOG printf - #endif - #ifndef SSL_LOCAL_LOG - #define SSL_LOCAL_LOG printf - #endif - #endif +#ifdef CONFIG_OPENSSL_DEBUG_LEVEL + #define SSL_DEBUG_LEVEL CONFIG_OPENSSL_DEBUG_LEVEL #else - #ifdef SSL_PRINT_LOG - #undef SSL_PRINT_LOG - #endif - #define SSL_PRINT_LOG(...) - - #ifdef SSL_ERROR_LOG - #undef SSL_ERROR_LOG - #endif - #define SSL_ERROR_LOG(...) - #ifdef SSL_LOCAL_LOG - #undef SSL_LOCAL_LOG - #endif - #define SSL_LOCAL_LOG(...) + #define SSL_DEBUG_LEVEL 0 #endif -#if SSL_DEBUG_LOCATION_ENABLE - #define SSL_DEBUG_LOCATION() SSL_LOCAL_LOG("%s %s line %d\n", __FILE__, __FUNCTION__, __LINE__) +#define SSL_DEBUG_ON (SSL_DEBUG_LEVEL + 1) +#define SSL_DEBUG_OFF (SSL_DEBUG_LEVEL - 1) + +#ifdef CONFIG_OPENSSL_DEBUG + #ifndef SSL_DEBUG_LOG + #error "SSL_DEBUG_LOG is not defined" + #endif + + #ifndef SSL_DEBUG_FL + #define SSL_DEBUG_FL "\n" + #endif + + #define SSL_SHOW_LOCATION() \ + SSL_DEBUG_LOG("SSL assert : %s %d\n", \ + __FILE__, __LINE__) + + #define SSL_DEBUG(level, fmt, ...) \ + { \ + if (level > SSL_DEBUG_LEVEL) { \ + SSL_DEBUG_LOG(fmt SSL_DEBUG_FL, ##__VA_ARGS__); \ + } \ + } +#else /* CONFIG_OPENSSL_DEBUG */ + #define SSL_SHOW_LOCATION() + + #define SSL_DEBUG(level, fmt, ...) +#endif /* CONFIG_OPENSSL_DEBUG */ + +/** + * OpenSSL assert function + * + * if select "CONFIG_OPENSSL_ASSERT_DEBUG", SSL_ASSERT* will show error file name and line + * if select "CONFIG_OPENSSL_ASSERT_EXIT", SSL_ASSERT* will just return error code. + * if select "CONFIG_OPENSSL_ASSERT_DEBUG_EXIT" SSL_ASSERT* will show error file name and line, + * then return error code. + * if select "CONFIG_OPENSSL_ASSERT_DEBUG_BLOCK", SSL_ASSERT* will show error file name and line, + * then block here with "while (1)" + * + * SSL_ASSERT1 may will return "-1", so function's return argument is integer. + * SSL_ASSERT2 may will return "NULL", so function's return argument is a point. + * SSL_ASSERT2 may will return nothing, so function's return argument is "void". + */ +#if defined(CONFIG_OPENSSL_ASSERT_DEBUG) + #define SSL_ASSERT1(s) \ + { \ + if (!(s)) { \ + SSL_SHOW_LOCATION(); \ + } \ + } + + #define SSL_ASSERT2(s) \ + { \ + if (!(s)) { \ + SSL_SHOW_LOCATION(); \ + } \ + } + + #define SSL_ASSERT3(s) \ + { \ + if (!(s)) { \ + SSL_SHOW_LOCATION(); \ + } \ + } +#elif defined(CONFIG_OPENSSL_ASSERT_EXIT) + #define SSL_ASSERT1(s) \ + { \ + if (!(s)) { \ + return -1; \ + } \ + } + + #define SSL_ASSERT2(s) \ + { \ + if (!(s)) { \ + return NULL; \ + } \ + } + + #define SSL_ASSERT3(s) \ + { \ + if (!(s)) { \ + return ; \ + } \ + } +#elif defined(CONFIG_OPENSSL_ASSERT_DEBUG_EXIT) + #define SSL_ASSERT1(s) \ + { \ + if (!(s)) { \ + SSL_SHOW_LOCATION(); \ + return -1; \ + } \ + } + + #define SSL_ASSERT2(s) \ + { \ + if (!(s)) { \ + SSL_SHOW_LOCATION(); \ + return NULL; \ + } \ + } + + #define SSL_ASSERT3(s) \ + { \ + if (!(s)) { \ + SSL_SHOW_LOCATION(); \ + return ; \ + } \ + } +#elif defined(CONFIG_OPENSSL_ASSERT_DEBUG_BLOCK) + #define SSL_ASSERT1(s) \ + { \ + if (!(s)) { \ + SSL_SHOW_LOCATION(); \ + while (1); \ + } \ + } + + #define SSL_ASSERT2(s) \ + { \ + if (!(s)) { \ + SSL_SHOW_LOCATION(); \ + while (1); \ + } \ + } + + #define SSL_ASSERT3(s) \ + { \ + if (!(s)) { \ + SSL_SHOW_LOCATION(); \ + while (1); \ + } \ + } #else - #define SSL_DEBUG_LOCATION() + #define SSL_ASSERT1(s) + #define SSL_ASSERT2(s) + #define SSL_ASSERT3(s) #endif -#if SSL_ASSERT_ENABLE - #define SSL_ASSERT(s) { if (!(s)) { SSL_DEBUG_LOCATION(); } } -#else - #define SSL_ASSERT(s) -#endif +#define SSL_PLATFORM_DEBUG_LEVEL SSL_DEBUG_OFF +#define SSL_PLATFORM_ERROR_LEVEL SSL_DEBUG_ON -#define SSL_ERR(err, go, fmt, ...) { SSL_DEBUG_LOCATION(); SSL_ERROR_LOG(fmt, ##__VA_ARGS__); ret = err; goto go; } +#define SSL_CERT_DEBUG_LEVEL SSL_DEBUG_OFF +#define SSL_CERT_ERROR_LEVEL SSL_DEBUG_ON -#define SSL_RET(go, fmt, ...) { SSL_DEBUG_LOCATION(); SSL_ERROR_LOG(fmt, ##__VA_ARGS__); goto go; } +#define SSL_PKEY_DEBUG_LEVEL SSL_DEBUG_OFF +#define SSL_PKEY_ERROR_LEVEL SSL_DEBUG_ON -#define SSL_DEBUG(level, fmt, ...) { if (level > SSL_DEBUG_LEVEL) {SSL_PRINT_LOG(fmt, ##__VA_ARGS__);} } +#define SSL_X509_DEBUG_LEVEL SSL_DEBUG_OFF +#define SSL_X509_ERROR_LEVEL SSL_DEBUG_ON + +#define SSL_LIB_DEBUG_LEVEL SSL_DEBUG_OFF +#define SSL_LIB_ERROR_LEVEL SSL_DEBUG_ON + +#define SSL_STACK_DEBUG_LEVEL SSL_DEBUG_OFF +#define SSL_STACK_ERROR_LEVEL SSL_DEBUG_ON #ifdef __cplusplus -} + } #endif #endif diff --git a/tools/sdk/include/openssl/platform/ssl_opt.h b/tools/sdk/include/openssl/platform/ssl_opt.h index 01d438eb..a9c55e8c 100644 --- a/tools/sdk/include/openssl/platform/ssl_opt.h +++ b/tools/sdk/include/openssl/platform/ssl_opt.h @@ -15,34 +15,6 @@ #ifndef _SSL_OPT_H_ #define _SSL_OPT_H_ -#ifdef __cplusplus - extern "C" { -#endif - -/** - * if not define "ESP32_IDF_PLATFORM", system will use esp8266 platform interface - */ -#define ESP32_IDF_PLATFORM - -/** - * openssl debug print function enable - */ -#define SSL_DEBUG_ENBALE 0 - -/** - * openssl debug print function level. function whose level is lower that "SSL_DEBUG_LEVEL" - * will not print message - */ -#define SSL_DEBUG_LEVEL 0 - -/** - * openssl assert function enable, it will check the input paramter and print the message - */ -#define SSL_ASSERT_ENABLE 0 - -/** - * openssl location function enable, it will print location of the positioning error - */ -#define SSL_DEBUG_LOCATION_ENABLE 0 +#include "sdkconfig.h" #endif diff --git a/tools/sdk/include/openssl/platform/ssl_pm.h b/tools/sdk/include/openssl/platform/ssl_pm.h index a516d574..cbbe3aa3 100644 --- a/tools/sdk/include/openssl/platform/ssl_pm.h +++ b/tools/sdk/include/openssl/platform/ssl_pm.h @@ -19,6 +19,7 @@ extern "C" { #endif +#include #include "ssl_types.h" #include "ssl_port.h" @@ -53,4 +54,8 @@ int pkey_pm_load(EVP_PKEY *pk, const unsigned char *buffer, int len); long ssl_pm_get_verify_result(const SSL *ssl); +#ifdef __cplusplus + } +#endif + #endif diff --git a/tools/sdk/include/openssl/platform/ssl_port.h b/tools/sdk/include/openssl/platform/ssl_port.h index 35c8dc18..492ea405 100644 --- a/tools/sdk/include/openssl/platform/ssl_port.h +++ b/tools/sdk/include/openssl/platform/ssl_port.h @@ -19,31 +19,27 @@ extern "C" { #endif -#include "platform/ssl_opt.h" - -#ifdef ESP32_IDF_PLATFORM - #include "esp_types.h" #include "esp_log.h" +#include "string.h" +#include "malloc.h" void *ssl_mem_zalloc(size_t size); -void *ssl_mem_malloc(size_t size); -void ssl_mem_free(void *p); -void* ssl_memcpy(void *to, const void *from, size_t size); -size_t ssl_strlen(const char *src); +#define ssl_mem_malloc malloc +#define ssl_mem_free free -void ssl_speed_up_enter(void); -void ssl_speed_up_exit(void); +#define ssl_memcpy memcpy +#define ssl_strlen strlen -#define SSL_PRINT_LOG(fmt, ...) ESP_LOGD("openssl", fmt, ##__VA_ARGS__) -#define SSL_ERROR_LOG(fmt, ...) ESP_LOGE("openssl", fmt, ##__VA_ARGS__) -#define SSL_LOCAL_LOG(fmt, ...) ESP_LOGD("openssl", fmt, ##__VA_ARGS__) +#define ssl_speed_up_enter() +#define ssl_speed_up_exit() -#elif defined(SSL_PLATFORM_USER_INCLUDE) - -SSL_PLATFORM_USER_INCLUDE +#define SSL_DEBUG_FL +#define SSL_DEBUG_LOG(fmt, ...) ESP_LOGI("openssl", fmt, ##__VA_ARGS__) +#ifdef __cplusplus + } #endif #endif diff --git a/tools/sdk/include/spi_flash/esp_partition.h b/tools/sdk/include/spi_flash/esp_partition.h index b149e102..28f8551d 100644 --- a/tools/sdk/include/spi_flash/esp_partition.h +++ b/tools/sdk/include/spi_flash/esp_partition.h @@ -191,6 +191,13 @@ esp_err_t esp_partition_read(const esp_partition_t* partition, * Before writing data to flash, corresponding region of flash needs to be erased. * This can be done using esp_partition_erase_range function. * + * Partitions marked with an encryption flag will automatically be + * written via the spi_flash_write_encrypted() function. If writing to + * an encrypted partition, all write offsets and lengths must be + * multiples of 16 bytes. See the spi_flash_write_encrypted() function + * for more details. Unencrypted partitions do not have this + * restriction. + * * @param partition Pointer to partition structure obtained using * esp_partition_find_first or esp_partition_get. * Must be non-NULL. diff --git a/tools/sdk/include/spi_flash/esp_spi_flash.h b/tools/sdk/include/spi_flash/esp_spi_flash.h index bf897e89..060d598e 100644 --- a/tools/sdk/include/spi_flash/esp_spi_flash.h +++ b/tools/sdk/include/spi_flash/esp_spi_flash.h @@ -31,6 +31,8 @@ extern "C" { #define SPI_FLASH_SEC_SIZE 4096 /**< SPI Flash sector size */ +#define SPI_FLASH_MMU_PAGE_SIZE 0x10000 /**< Flash cache MMU mapping page size */ + /** * @brief Initialize SPI flash access driver * @@ -92,14 +94,18 @@ esp_err_t spi_flash_write(size_t dest_addr, const void *src, size_t size); * * @note Flash encryption must be enabled for this function to work. * - * @note Address in flash, dest, has to be 32-byte aligned. + * @note Flash encryption must be enabled when calling this function. + * If flash encryption is disabled, the function returns + * ESP_ERR_INVALID_STATE. Use esp_flash_encryption_enabled() + * function to determine if flash encryption is enabled. * - * @note If source address is in DROM, this function will return - * ESP_ERR_INVALID_ARG. + * @note Both dest_addr and size must be multiples of 16 bytes. For + * absolute best performance, both dest_addr and size arguments should + * be multiples of 32 bytes. * - * @param dest_addr destination address in Flash. Must be a multiple of 32 bytes. + * @param dest_addr destination address in Flash. Must be a multiple of 16 bytes. * @param src pointer to the source buffer. - * @param size length of data, in bytes. Must be a multiple of 32 bytes. + * @param size length of data, in bytes. Must be a multiple of 16 bytes. * * @return esp_err_t */ @@ -116,6 +122,23 @@ esp_err_t spi_flash_write_encrypted(size_t dest_addr, const void *src, size_t si */ esp_err_t spi_flash_read(size_t src_addr, void *dest, size_t size); + +/** + * @brief Read data from Encrypted Flash. + * + * If flash encryption is enabled, this function will transparently decrypt data as it is read. + * If flash encryption is not enabled, this function behaves the same as spi_flash_read(). + * + * See esp_flash_encryption_enabled() for a function to check if flash encryption is enabled. + * + * @param src source address of the data in Flash. + * @param dest pointer to the destination buffer + * @param size length of data + * + * @return esp_err_t + */ +esp_err_t spi_flash_read_encrypted(size_t src, void *dest, size_t size); + /** * @brief Enumeration which specifies memory space requested in an mmap call */ @@ -140,7 +163,8 @@ typedef uint32_t spi_flash_mmap_handle_t; * page allocation, use spi_flash_mmap_dump function. * * @param src_addr Physical address in flash where requested region starts. - * This address *must* be aligned to 64kB boundary. + * This address *must* be aligned to 64kB boundary + * (SPI_FLASH_MMU_PAGE_SIZE). * @param size Size of region which has to be mapped. This size will be rounded * up to a 64k boundary. * @param memory Memory space where the region should be mapped @@ -181,16 +205,44 @@ typedef void (*spi_flash_guard_start_func_t)(void); * @brief SPI flash critical section exit function. */ typedef void (*spi_flash_guard_end_func_t)(void); +/** + * @brief SPI flash operation lock function. + */ +typedef void (*spi_flash_op_lock_func_t)(void); +/** + * @brief SPI flash operation unlock function. + */ +typedef void (*spi_flash_op_unlock_func_t)(void); /** - * Structure holding SPI flash access critical section management functions + * Structure holding SPI flash access critical sections management functions. + * + * Flash API uses two types of flash access management functions: + * 1) Functions which prepare/restore flash cache and interrupts before calling + * appropriate ROM functions (SPIWrite, SPIRead and SPIEraseBlock): + * - 'start' function should disables flash cache and non-IRAM interrupts and + * is invoked before the call to one of ROM function above. + * - 'end' function should restore state of flash cache and non-IRAM interrupts and + * is invoked after the call to one of ROM function above. + * 2) Functions which synchronizes access to internal data used by flash API. + * This functions are mostly intended to synchronize access to flash API internal data + * in multithreaded environment and use OS primitives: + * - 'op_lock' locks access to flash API internal data. + * - 'op_unlock' unlocks access to flash API internal data. + * Different versions of the guarding functions should be used depending on the context of + * execution (with or without functional OS). In normal conditions when flash API is called + * from task the functions use OS primitives. When there is no OS at all or when + * it is not guaranteed that OS is functional (accessing flash from exception handler) these + * functions cannot use OS primitives or even does not need them (multithreaded access is not possible). * * @note Structure and corresponding guard functions should not reside in flash. * For example structure can be placed in DRAM and functions in IRAM sections. */ typedef struct { - spi_flash_guard_start_func_t start; /**< critical section start func */ - spi_flash_guard_end_func_t end; /**< critical section end func */ + spi_flash_guard_start_func_t start; /**< critical section start func */ + spi_flash_guard_end_func_t end; /**< critical section end func */ + spi_flash_op_lock_func_t op_lock; /**< flash access API lock func */ + spi_flash_op_unlock_func_t op_unlock; /**< flash access API unlock func */ } spi_flash_guard_funcs_t; /** diff --git a/tools/sdk/ld/esp32.common.ld b/tools/sdk/ld/esp32.common.ld index 3e5d6b7d..ac04c07d 100644 --- a/tools/sdk/ld/esp32.common.ld +++ b/tools/sdk/ld/esp32.common.ld @@ -80,6 +80,7 @@ SECTIONS *(.iram1 .iram1.*) *libfreertos.a:(.literal .text .literal.* .text.*) *libesp32.a:panic.o(.literal .text .literal.* .text.*) + *libesp32.a:core_dump.o(.literal .text .literal.* .text.*) *libphy.a:(.literal .text .literal.* .text.*) *librtc.a:(.literal .text .literal.* .text.*) *libpp.a:(.literal .text .literal.* .text.*) diff --git a/tools/sdk/lib/libapp_update.a b/tools/sdk/lib/libapp_update.a index 9971677f..82c87a23 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 dc4499ad..e2d56292 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 77156433..4323b5ed 100644 Binary files a/tools/sdk/lib/libbt.a and b/tools/sdk/lib/libbt.a differ diff --git a/tools/sdk/lib/libcoap.a b/tools/sdk/lib/libcoap.a index 1166f49b..e51006a4 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 68186c0c..d0d74c0b 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 83cebdbb..ec40e5be 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 cc573488..89d579dd 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 0bd4be3c..2ac28bf5 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 bf7c0632..e8f6e002 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 c6e7dd35..a2d0aee5 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 9798384c..02166d9e 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 2643d395..5b7bd6e8 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 e8b15c19..0b2354c6 100644 Binary files a/tools/sdk/lib/libfreertos.a and b/tools/sdk/lib/libfreertos.a differ diff --git a/tools/sdk/lib/libjson.a b/tools/sdk/lib/libjson.a index b2e82576..0d36f692 100644 Binary files a/tools/sdk/lib/libjson.a and b/tools/sdk/lib/libjson.a differ diff --git a/tools/sdk/lib/liblog.a b/tools/sdk/lib/liblog.a index 0b88f6c7..e3fccaa1 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 e35a4406..b88d159e 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 b4add841..35d8a31d 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 29661128..96afe281 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 3e5840bc..fe09fe59 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 cd7b360e..a394fca5 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 ac63f0f8..aa8310e3 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 96e28b02..06be769a 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 0ab7f84c..75d03ccb 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 917628b8..eb71f118 100644 Binary files a/tools/sdk/lib/libopenssl.a and b/tools/sdk/lib/libopenssl.a differ diff --git a/tools/sdk/lib/libpp.a b/tools/sdk/lib/libpp.a index 3ae603e3..c7663a65 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 c31f1cf8..2e3be571 100644 Binary files a/tools/sdk/lib/libsdmmc.a and b/tools/sdk/lib/libsdmmc.a differ diff --git a/tools/sdk/lib/libspi_flash.a b/tools/sdk/lib/libspi_flash.a index e0cdb51a..af5dcb72 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 cc8fbe14..5305f3be 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 20b80efc..b7c48582 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 1a840ad4..24f3eb6b 100644 Binary files a/tools/sdk/lib/libvfs.a and b/tools/sdk/lib/libvfs.a differ diff --git a/tools/sdk/lib/libwpa.a b/tools/sdk/lib/libwpa.a index 9efffc78..fbfb0e4a 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 59636332..7acd7bc0 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 4bbdf693..26e45027 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 114bc8d6..cb324439 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 dfed8a4e..76c8d876 100644 Binary files a/tools/sdk/lib/libxtensa-debug-module.a and b/tools/sdk/lib/libxtensa-debug-module.a differ diff --git a/variants/esp32/pins_arduino.h b/variants/esp32/pins_arduino.h index 6485bc09..85452d36 100644 --- a/variants/esp32/pins_arduino.h +++ b/variants/esp32/pins_arduino.h @@ -15,7 +15,7 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 2; +static const uint8_t SS = 5; static const uint8_t MOSI = 23; static const uint8_t MISO = 19; static const uint8_t SCK = 18; diff --git a/variants/esp32thing/pins_arduino.h b/variants/esp32thing/pins_arduino.h new file mode 100644 index 00000000..6485bc09 --- /dev/null +++ b/variants/esp32thing/pins_arduino.h @@ -0,0 +1,54 @@ +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#define EXTERNAL_NUM_INTERRUPTS 16 +#define NUM_DIGITAL_PINS 40 +#define NUM_ANALOG_INPUTS 16 + +#define analogInputToDigitalPin(p) (((p)<20)?(esp32_adc2gpio[(p)]):-1) +#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) +#define digitalPinHasPWM(p) (p < 34) + +static const uint8_t TX = 1; +static const uint8_t RX = 3; + +static const uint8_t SDA = 21; +static const uint8_t SCL = 22; + +static const uint8_t SS = 2; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; + +static const uint8_t A0 = 36; +static const uint8_t A3 = 39; +static const uint8_t A4 = 32; +static const uint8_t A5 = 33; +static const uint8_t A6 = 34; +static const uint8_t A7 = 35; +static const uint8_t A10 = 4; +static const uint8_t A11 = 0; +static const uint8_t A12 = 2; +static const uint8_t A13 = 15; +static const uint8_t A14 = 13; +static const uint8_t A15 = 12; +static const uint8_t A16 = 14; +static const uint8_t A17 = 27; +static const uint8_t A18 = 25; +static const uint8_t A19 = 26; + +static const uint8_t T0 = 4; +static const uint8_t T1 = 0; +static const uint8_t T2 = 2; +static const uint8_t T3 = 15; +static const uint8_t T4 = 13; +static const uint8_t T5 = 12; +static const uint8_t T6 = 14; +static const uint8_t T7 = 27; +static const uint8_t T8 = 33; +static const uint8_t T9 = 32; + +static const uint8_t DAC1 = 25; +static const uint8_t DAC2 = 26; + +#endif /* Pins_Arduino_h */ diff --git a/variants/espea32/pins_arduino.h b/variants/espea32/pins_arduino.h index 1dc827f2..c87e1a23 100644 --- a/variants/espea32/pins_arduino.h +++ b/variants/espea32/pins_arduino.h @@ -17,7 +17,7 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 2; +static const uint8_t SS = 5; static const uint8_t MOSI = 23; static const uint8_t MISO = 19; static const uint8_t SCK = 18; diff --git a/variants/hornbill32dev/pins_arduino.h b/variants/hornbill32dev/pins_arduino.h index a355bafd..a76095fe 100644 --- a/variants/hornbill32dev/pins_arduino.h +++ b/variants/hornbill32dev/pins_arduino.h @@ -15,7 +15,7 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 2; +static const uint8_t SS = 5; static const uint8_t MOSI = 23; static const uint8_t MISO = 19; static const uint8_t SCK = 18; diff --git a/variants/lolin32/pins_arduino.h b/variants/lolin32/pins_arduino.h index a2f49094..cde7c0b4 100644 --- a/variants/lolin32/pins_arduino.h +++ b/variants/lolin32/pins_arduino.h @@ -18,7 +18,7 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 2; +static const uint8_t SS = 5; static const uint8_t MOSI = 23; static const uint8_t MISO = 19; static const uint8_t SCK = 18; diff --git a/variants/nano32/pins_arduino.h b/variants/nano32/pins_arduino.h index 83e1bcd0..7a1cb982 100644 --- a/variants/nano32/pins_arduino.h +++ b/variants/nano32/pins_arduino.h @@ -17,7 +17,7 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 2; +static const uint8_t SS = 5; static const uint8_t MOSI = 23; static const uint8_t MISO = 19; static const uint8_t SCK = 18; diff --git a/variants/node32s/pins_arduino.h b/variants/node32s/pins_arduino.h index 6485bc09..85452d36 100644 --- a/variants/node32s/pins_arduino.h +++ b/variants/node32s/pins_arduino.h @@ -15,7 +15,7 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 2; +static const uint8_t SS = 5; static const uint8_t MOSI = 23; static const uint8_t MISO = 19; static const uint8_t SCK = 18; diff --git a/variants/quantum/pins_arduino.h b/variants/quantum/pins_arduino.h index 6485bc09..85452d36 100644 --- a/variants/quantum/pins_arduino.h +++ b/variants/quantum/pins_arduino.h @@ -15,7 +15,7 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 2; +static const uint8_t SS = 5; static const uint8_t MOSI = 23; static const uint8_t MISO = 19; static const uint8_t SCK = 18;