Compare commits

...

713 Commits

Author SHA1 Message Date
Ivan Grokhotkov
bef9896305 Merge branch 'bugfix/xtal_freq_40_2.0' into 'release/v2.0'
esp32: by default, set 40MHz crystal frequency

See merge request !1144
2017-08-24 15:48:06 +08:00
He Yin Ling
18dbdd46f4 CI: checkout relative branch of test_script
test script interface could change. we need to use the correct version
of test script to run test on old release versions of IDF.
2017-08-24 11:38:52 +08:00
Ivan Grokhotkov
4184968469 esp32: by default, set 40MHz crystal frequency 2017-08-23 16:41:51 +08:00
Ivan Grokhotkov
024ef51d1a Merge branch 'bugfix/bt_increase_btc_task_queue_size' into 'release/v2.0'
bt component: increase BTC task queue size



See merge request !637
2017-04-06 10:57:00 +08:00
island
4d9778e208 bt component: increase BTC task queue number 2017-04-05 21:42:12 +08:00
Ivan Grokhotkov
6181af2a0b Merge branch 'test/reboot_between_unit_test_cases' into 'release/v2.0'
CI: add reset between running each unit test cases

Unit test is designed to detect bug **within** each test case. Therefore we'll reset between each case to provide a clean context. We will later add stress cases to run unit test cases together to detect potential bugs.

See merge request !636
2017-04-05 20:52:13 +08:00
He Yin Ling
abf0cd8421 CI: add reset between running each unit test cases 2017-04-05 18:41:56 +08:00
Ivan Grokhotkov
7a83c87c44 Merge branch 'bugfix/cpu1_isr_stack_location' into 'master'
Fix finding location of ISR stack space for CPU1

Up to now, the CPU1 interrupts erroneously used the area *after* the ISR stack region, leading to bugs in BT Classic. This fixes that.

See merge request !618
2017-04-01 16:56:21 +08:00
island
6ad86f0d67 bt component: fix gatt delete service memory leak problem 2017-04-01 15:34:38 +08:00
Liu Zhi Fu
fddebe4bcc Merge branch 'bugfix/merge_esptouch_fix' into 'release/v2.0'
esp32: update wifi lib for esptouch issue

Disconnect station before enabling esptouch

See merge request !617
2017-03-28 19:16:06 +08:00
Liu Zhi Fu
2102acf266 esp32: update wifi lib for esptouch issue
Disconnect station before enabling esptouch
2017-03-28 15:45:19 +08:00
Liu Zhi Fu
a4ac9bf80b Merge branch 'bugfix/merge_some_wifi_bugs_into_release2.0' into 'release/v2.0'
esp32: update wifi lib for some fixes

1. Fix AMSDU flags issue
2. Fix smartconfig cause serial no response issue
3. Fix restore cause exception issue
4. smartconfig cause crash

See merge request !611
2017-03-27 15:01:21 +08:00
Liu Zhi Fu
6e2601f389 esp32: update wifi lib for some bugfix
1. Fix AMSDU flags issue
2. Fix smartconfig cause serial no response issue
3. Fix restore cause exception issue
4. Fix smartconfig cause crash
2017-03-27 11:29:08 +08:00
Ivan Grokhotkov
ea48f43f87 Merge branch 'bugfix/timer_stack_size' into 'release/v2.0'
freertos: increase timer task stack size to 2048 bytes

Current timer task stack size is insufficient for logging calls which
use non-nano vprintf.

See merge request !607
2017-03-24 15:54:57 +08:00
Ivan Grokhotkov
1b0b34247a Merge branch 'bugfix/btdm_isr_alloc' into 'release/v2.0'
component/bt : fix rx packet assert bug and malloc in ISR bug in bluetooth

1. fix alloc in ISR context bug
2. fix rx bluetooth packets cause assert bug

See merge request !609
2017-03-24 15:54:09 +08:00
Tian Hao
4aaa453b31 component/bt : fix rx packet assert bug and malloc in ISR bug in bluetooth 2017-03-24 14:57:07 +08:00
Ivan Grokhotkov
fe69377782 freertos: increase timer task stack size to 2048 bytes
Current timer task stack size is insufficient for logging calls which
use non-nano vprintf.
2017-03-24 08:40:05 +08:00
island
1c9d8744ab bt component: Fix HCI task stack overflow bug 2017-03-23 17:27:15 +08:00
Ivan Grokhotkov
7db3370e20 Merge branch 'bugfix/vhci_callback' into 'release/v2.0'
component/bt: let "vhci_notify_host_send_available" be called in task context

Previously the callback function "vhci_notify_host_send_available" can be called in both interrupt context or BT controller task context, which is one of the cause that Bluedroid tasks cannot work on dual CPUs. 

See merge request !603
2017-03-22 22:42:58 +08:00
Angus Gratton
eece22d075 ci: Swap github/gitlab submodules for release branches & tags also 2017-03-22 21:21:00 +08:00
Angus Gratton
2cc668bbb1 ci: Also run deployment steps for tags of form vX.Y (with optional -suffix) 2017-03-22 21:21:00 +08:00
wangmengyang
ad4a1b600a component/bt: let vhci callback "vhci_notify_host_send_available" be called in the context of BT controller task. 2017-03-22 19:38:47 +08:00
Tian Hao
877b407c8c component/bt : fix blufi bug of sec_mode reset 2017-03-22 16:17:20 +08:00
me-no-dev
5850f423d5 address security issues with mDNS 2017-03-22 16:16:44 +08:00
island
ea74033d1e bt component: fix bluetooth gatt packets process bugs
1. Add process of prepare write request packets
2. Add process of execute write request packets
3. Add process of reliable write request packets
4. Fix bug of processing read blob request packets
5. Fix bug of processing write request packets
6. Optimize error check and process in stack
2017-03-21 14:32:25 +08:00
Angus Gratton
7cd1e0ef4b ci: Fix master branch being pushed to master
Previous change in 8b6993f7 doesn't work if branch exists locally.
2017-03-17 18:17:41 +08:00
Angus Gratton
f72888544e build/CI: Push all allocated release branches to github
Previously CI deployment only pushed to master.
2017-03-17 18:17:11 +08:00
Tian Hao
a513ac4dec add extra check before bluedroid init and disable 2017-03-17 18:15:11 +08:00
Angus Gratton
b337b20270 docs/eclipse: Add considerations for PATH, PYTHONPATH
Thanks to @motla who mentioned these on github:
https://github.com/espressif/esp-idf/pull/157#issuecomment-271109920
2017-03-17 18:14:17 +08:00
Angus Gratton
8ab96b13af esp_err: Use separate code path for ESP_ERROR_CHECK assertion
* Minimum code size overhead
* Makes function safe to use when flash cache is disabled

Builds on #339 https://github.com/espressif/esp-idf/pull/339
2017-03-17 18:14:17 +08:00
Angus Gratton
50f414f54c spi_flash: Add spi_flash_cache_enabled() test function 2017-03-17 18:13:46 +08:00
Angus Gratton
0dfef8c16c sdmmc: Use slot width as default slot_config width parameter, instead of 4
Ref #361 https://github.com/espressif/esp-idf/pull/361
2017-03-17 18:12:41 +08:00
Derek Gregory
6bb1367fe5 component/bt: fix bug where uuid was not reset in btc_gatts_act_create_attr_tab.
Merges #307 https://github.com/espressif/esp-idf/pull/307
2017-03-17 18:12:41 +08:00
lucashutchinson
a286846095 ble: Fix ble_adv data truncation
Fixed issue with ble_adv data being truncated after the 31st octet due to an incorrect length passed in a memcpy.

Merges #389 https://github.com/espressif/esp-idf/pull/389
2017-03-17 18:12:41 +08:00
Angus Gratton
2b2dd845ae docs/*-setup: Use --enable-local instead of --prefix=$PWD for ct-ng 2017-03-17 18:12:41 +08:00
Daniel Bovensiepen
b9f9e681ba docs/linux-setup: Install dependencies for Ubuntu 16.04
Not sure which Ubuntu is used in the installation guide but for the latest LTS release 16.04 we need libtool-bin for
compiling crosstool-NG proper

Merges #46 https://github.com/espressif/esp-idf/pull/46
2017-03-17 18:12:41 +08:00
Angus Gratton
3429241e1a esp_err: add NDEBUG guard, comment about flash cache
Follow-up to 316b040
2017-03-17 18:12:41 +08:00
Neil Kolban
455a7784a9 Update to ESP_ERROR_CHECK
See request from ESP_Angus here:
https://esp32.com/viewtopic.php?f=18&t=1179

Merges #339 https://github.com/espressif/esp-idf/pull/339
2017-03-17 18:12:41 +08:00
Anne Jan Brouwer
7d9a20e714 Added missing platform.h to mbedtls ssl.h
There was a missing definition of mbedtls_time_t

See for example:
https://travis-ci.org/SHA2017-badge/Firmware/jobs/202459377

Merges #348 https://github.com/espressif/esp-idf/pull/348
2017-03-17 18:12:41 +08:00
Angus Gratton
a6980fce4c lwip: Use strlcpy() instead of memcpy() to copy hostname to static buffer 2017-03-17 18:12:41 +08:00
alarruskain
4bd41d4082 lwip: Fix hostname set in tcpip_adapter_lwip
Hostname for each interface is not correctly stored in "hostinfo" variable.

Merges #350 https://github.com/espressif/esp-idf/pull/350
2017-03-17 18:12:41 +08:00
gbcwbz
3302a38432 docs: Fix typo in build-system.rst
Merges #355 https://github.com/espressif/esp-idf/pull/355
2017-03-17 18:12:41 +08:00
Daniel Campora
82ef2b9485 sdmmc: Add width field to the slot config.
Therefore if the width is set to 1, you can choose to only
configure the CLK, DAT0 and CMD pins.

Merges #361 https://github.com/espressif/esp-idf/pull/361
2017-03-17 18:12:41 +08:00
rudi ;-)
de461671aa examples/ethernet: Same sense of meaning SW_STRAP
Merges #366 #367
https://github.com/espressif/esp-idf/pull/366
https://github.com/espressif/esp-idf/pull/367
2017-03-17 18:12:41 +08:00
rudi ;-)
aa2f5e4ae5 examples/ethernet: typo, better named
Merges #382 https://github.com/espressif/esp-idf/pull/382
2017-03-17 18:12:41 +08:00
Ivan Grokhotkov
c01dff8263 Merge branch 'feature/run_test_on_release_branches' into 'master'
CI: support running CI test on release branches

Patches will be cherry-picked to release branches after it's released. Therefore we need to run test jobs with the same strategy as master.

See merge request !551
2017-03-04 15:06:37 +08:00
Wu Jian Gang
06274ff5a5 Merge branch 'bugfix/fix_mpdu_len_error' into 'master'
esp32: update wifi lib to fix mpdu len error

Fix mpdu len error which impact espressif smartconfig

See merge request !552
2017-03-04 15:03:46 +08:00
Jiang Jiang Jian
c62ae777c2 Merge branch 'feature/tw10306_menuconfig_adds_some_wifi_options' into 'master'
menuconfig adds some WiFi options

menuconfig adds some WiFi options
 1. Add options to enable/disable AMPDU
  2. Add options to configure WiFi task stack size
  3. Add options to configure WiFi RX/TX buffer number


See merge request !519
2017-03-02 19:46:29 +08:00
Liu Zhi Fu
abdd8feebb esp32: menuconfig adds some WiFi options
1. Add options to enable/disable AMPDU
2. Add options to enable/disable WIFI NVS
3. Add options to configure WiFi RX/TX buffer number
2017-03-02 18:13:49 +08:00
Jiang Jiang Jian
3b8c9a407f Merge branch 'feature/add_user_set_mac' into 'master'
Feature/add user set mac

1. Add menuconfig for user to set mac address of wifi, bt and ethernet.
2. Add the number of MAC address generated from efuse for user to choose.
3. Add MAC address derive method.

See merge request !542
2017-03-02 17:34:14 +08:00
Jiang Jiang Jian
6451c57e52 Merge branch 'bugfix/tw10169_dhcp_release_cause_tcp_abort' into 'master'
Bugfix/tw10169 dhcp release cause tcp abort

Modify the DHCP timer granularity from 1 minutes to 1 second.

See merge request !539
2017-03-02 17:28:11 +08:00
Jeroen Domburg
432b25f755 Merge branch 'feature/in_isr_context' into 'master'
Add xPortInIsrContext function + unit test

As title states.

See merge request !533
2017-03-02 17:17:23 +08:00
Jeroen Domburg
6739d5b99f Add xPortInIsrContext function + unit test. This function returns true when the current CPU runs in an interrupt handler context. 2017-03-02 17:00:32 +08:00
XiaXiaotian
d3eede2110 mac address: add the number of MAC address generated from efuse for user to choose
1. Add the number of MAC address generated from efuse for user to choose.

2. Add MAC address derive method.
2017-03-02 15:54:35 +08:00
Ivan Grokhotkov
ecbe5a66f2 Merge branch 'bugfix/rng_disabled_wifi_stop_2' into 'master'
esp32: Fix hardware rng after esp_wifi_stop (second implementation)

Ensures hardware RNG remains enabled at all times.

Reworked  version of !534

See merge request !536
2017-03-02 10:51:30 +08:00
Jiang Jiang Jian
4e5e154603 Merge branch 'bugfix/fix_some_default_lwip_bool_options' into 'master'
Bugfix/fix some default lwip bool options

menuconfig options with bool type should use 'y/n' to set the default value, instead of '1/0'


See merge request !538
2017-03-01 22:03:57 +08:00
wangmengyang
6d061ec903 component/bt: modify the bluetooth read_efuse_mac interface 2017-03-01 21:04:12 +08:00
XiaXiaotian
fabe0493c2 mac address: add user set mac address
add menuconfig for user to set mac address of wifi, bt and ethernet.
2017-03-01 20:51:49 +08:00
Liu Zhi Fu
66199b1efe Check DHCP rebind timer before checking dhcp release timer in cause they have the same value.
lwip: modify dhcp timer granularity from 60s to 1s

Current DHCP granularity is 60 seconds, it's not accurate, it can cause DHCP release/rebind/renew timer
timeout at the same time, also it may renew/rebind/release at wrong time, thus cause problem.
2017-03-01 20:50:58 +08:00
XiaXiaotian
23f933a78d mac address: add user set mac address
add menuconfig for user to set mac address of wifi, bt and ethernet.
2017-03-01 20:42:46 +08:00
Liu Zhi Fu
3b3c3210a6 lwip: fix bool options default value wrong issue
menuconfig options with bool type should use 'y/n' to use the default value,
instead of '1/0'
2017-03-01 13:37:36 +08:00
Liu Zhi Fu
ae09a46cb8 Merge branch 'master' of ssh://gitlab.espressif.cn:27227/idf/esp-idf 2017-03-01 13:32:04 +08:00
Angus Gratton
4d67a2ba8b esp32 phy_init: Move DPORT Wifi clock masks to macro values
Amended fix for c642079 !534
2017-03-01 12:11:57 +11:00
Angus Gratton
98f8594151 esp32 dport_reg.h: Fix typo in register bit names 2017-03-01 12:01:07 +11:00
Ivan Grokhotkov
c025dfbfa7 Merge branch 'bugfix/mmap_instr' into 'master'
spi_flash: fix mmap not working for SPI_FLASH_MMAP_INST

Fixes https://github.com/espressif/esp-idf/issues/378

See merge request !528
2017-02-28 17:14:38 +08:00
Ivan Grokhotkov
f3687f7177 spi_flash: fix memory leak when spi_flash_mmap arguments are invalid
Check src_addr and size first, then allocate new_entry.
2017-02-28 15:11:54 +08:00
Wu Jian Gang
8f43567a68 Merge branch 'bugfix/esp_get_random_return_zero' into 'master'
Do not disable clock for generating random number.

1. Do not disable clock for generating random number.
2. And fix the bug that system crashes if call esp_wifi_stop() twice.

See merge request !534
2017-02-28 14:35:22 +08:00
XiaXiaotian
f36c909528 update phy and rtc lib
1. RTC V214: modify APLL function for the chip of ECO version.

2. Add API phy_close_rf() and use it in esp_phy_deinit() instead of pm_close_rf().

3. RTC V213: fix BT will not work when BT-init is called more than once.
2017-02-27 19:54:22 +08:00
Liu Zhi Fu
cd83bfb31c Merge branch 'master' of ssh://gitlab.espressif.cn:27227/idf/esp-idf 2017-02-27 17:22:47 +08:00
XiaXiaotian
c6420792f2 1. Do not disable clock for generating random number.
2. And fix the bug that system crashes if call esp_wifi_stop() twice.
2017-02-27 16:48:04 +08:00
Ivan Grokhotkov
290c40a4ab Merge branch 'bugfix/sdmmc_fail_no_card' into 'master'
vfs_fat_sdmmc: if card init fails, fail cleanly

This fixes the issue with sdmmc_host not returned to clean state after a failed attempt to mount the card, with no SD card in the slot.

See merge request !527
2017-02-27 10:00:55 +08:00
Jiang Jiang Jian
13dfb5568d Merge branch 'bugfix/set_channel_fail_before_enable_sniffer' into 'master'
wifi: fix issue in setting channel API

Update wifi libs to fix issue in setting channel API.

See merge request !529
2017-02-24 22:23:06 +08:00
qiyueixa
d9c649d26e wifi: fix issue in setting channel API 2017-02-24 22:08:54 +08:00
Ivan Grokhotkov
75115e1d83 spi_flash: fix mmap not working for SPI_FLASH_MMAP_INST 2017-02-24 21:50:05 +08:00
Ivan Grokhotkov
c17e05040a vfs_fat_sdmmc: if card init fails, fail cleanly
This fixes the issue with sdmmc_host not returned to clean state after
a failed attempt to mount the card, with no SD card in the slot.
2017-02-24 21:04:22 +08:00
Jiang Jiang Jian
63e0140ae6 Merge branch 'bugfix/btdm_adv_scan_enable_report' into 'master'
component/bt : add adv/scan start complete event

1. indicate adv/scan start complete success or failed
2. controller do limit of adv/scan concurrence, so add some codes to report adv/scan start failed or not.

See merge request !524
2017-02-24 16:24:22 +08:00
Ivan Grokhotkov
1671879b7a Merge branch 'bugfix/set_channel_fail_before_enable_sniffer' into 'master'
wifi: fix issue in setting channel before sniffer is enabled



See merge request !526
2017-02-24 16:15:39 +08:00
qiyueixa
ff81e17504 wifi: fix issue in setting channel before sniffer is enabled 2017-02-24 15:19:31 +08:00
Ivan Grokhotkov
708539c559 Merge branch 'bugfix/btdm_gatts_write_desc_error' into 'master'
component/bt:fixed the write ccc crash bug error

fix the gatt server write ccc lead to the system crash if not initialize the ccc value.

See merge request !515
2017-02-24 15:11:18 +08:00
Ivan Grokhotkov
36b3963efb Merge branch 'feature/btdm_ram_config' into 'master'
Optimize or release memory in bluetooth

1. add option to release about 30K from BT if BLE only
2. later BT/BLE will be separated by BT/BLE macro, but this option should use when user make sure that in BLE only mode.

See merge request !520
2017-02-23 18:21:16 +08:00
Tian Hao
b582697889 component/bt : add adv/scan start complete event
1. indicate adv/scan start complete success or failed
2. controller do limit of adv/scan concurrence, so add some codes to report adv/scan start failed or not.
2017-02-23 17:54:22 +08:00
Jeroen Domburg
7dfb1c2e97 Merge branch 'bugfix/app_tasks_start_on_wrong_cpu' into 'master'
Fix a scheduling bug

Fixes:
- Trivial bug where in some special cases a task could be started on the wrong core (and would run there for max 1 tick)
- More major bug causing a yield to be done with a mux held.

See merge request !523
2017-02-23 11:19:37 +08:00
Jeroen Domburg
c057f067c7 Merge branch 'bugfix/spi_master_length' into 'master'
Fix SPI master transmit length

Tx/Rx length fix from https://github.com/espressif/esp-idf/pull/336

I also added an extra commit in to make use of a define instead of a literal, plus fix a (harmless) off-by-one condition.

See merge request !521
2017-02-22 17:11:00 +08:00
Jeroen Domburg
ce7d0a7015 Fixed a small bug where a task could initially be scheduled on a wrong CPU, and a much bigger bug where a yield was performed with a held mux. 2017-02-22 17:04:51 +08:00
Ivan Grokhotkov
d772e1489b Merge branch 'bugfix/bootloader_disable_sar_test_mux' into 'master'
Deep sleep fixes

This change fixes extra 24 uA current consumption in deep sleep mode (https://esp32.com/viewtopic.php?f=2&t=1133).

Recent update to libphy/librtc caused another problem that WiFi related parts of RTC are no longer disabled by RTC sleep functions. This means that if WiFi is not disabled by the application before entering deep sleep, extra ~200uA of current would be consumed. This is fixed, and documentation for esp_deep_sleep and SNTP example are updated to mention that applications should take care of disabling WiFi and BT before going into the deep sleep mode.

See merge request !516
2017-02-22 14:32:32 +08:00
Ivan Grokhotkov
dca0377e19 Merge branch 'bugfix/flash_write_single_core' into 'master'
spi_flash: fix protection issues

This MR fixes the two spi_flash related issues:

- esp_intr_noniram_{disable,enable} not being protected by spi_flash_op_{lock,unlock} in single core mode. This caused a safety assert to be triggered in esp_intr_noniram_disable.

- spi_flash_unlock not being protected by spi_flash_guard_{start,end}. This caused a conflict between SPI0 and SPI1 controllers when accessing SPI flash, manifesting in cache data corruption and IllegalInstruction exceptions, for some flash chips.


See merge request !522
2017-02-22 14:17:40 +08:00
Ivan Grokhotkov
cbb71baca9 spi_flash: protect spi_flash_unlock
spi_flash_unlock was missing spi_flash_guard_start, which caused cache
to be enabled during unlock operation, causing hard-to-trace crashes
and cache data corruption.
2017-02-22 12:51:16 +08:00
Angus Gratton
045307ea0f Merge branch 'bugfix/make_config_problems' into 'master'
build system: Fix several make & configuration problems

Collection of quasi-related build system fixes:
* Fix issues with "make menuconfig" running twice when no existing sdkconfig
* Fix issues with menuconfig getting into a bad state if "make -jN" and no existing sdkconfig
* Hopefully fix intermittent issue with build system sometimes not picking up all config, leading to missing BT/WiFi libs at compile/link time.
* Fix issues with path resolution on Windows (including in Eclipse)
* Add new BATCH_BUILD variable for IDEs and automated build environments.

See merge request !485
2017-02-22 10:10:34 +08:00
Angus Gratton
f29768c404 Build system: Add new BATCH_BUILD flag to disable interactive parts of the build
Mostly useful for Eclipse (where accidentally running interactive
config hangs the build), but also good for CI and other automated
build systems.
2017-02-22 11:59:37 +11:00
Angus Gratton
c0f155f6ff kconfig: Ignore Windows host-compiled executables 2017-02-22 11:59:37 +11:00
Angus Gratton
8dede8f8a4 Eclipse: Process Windows paths correctly using cygpath
Includes splitting the Windows Eclipse setup doc into a separate page,
as it has so many additional steps.

Addresses github #17 and #166
https://github.com/espressif/esp-idf/issues/17
https://github.com/espressif/esp-idf/issues/166
2017-02-22 11:59:37 +11:00
Angus Gratton
d28ee9a25e build system: Account for Windows behaviour of make wildcard for some dirs
See github #166
2017-02-22 11:59:37 +11:00
Angus Gratton
c3544dc090 Build system: Fix error if librtc submodule not available to bootloader
Closes #220 https://github.com/espressif/esp-idf/issues/220
2017-02-22 11:59:37 +11:00
Angus Gratton
3c90032369 build system: Fix parallel & double menuconfig issues when sdkconfig missing
Fixes misbehaviour of default menuconfig when sdkconfig is missing.

(Either appearing twice, or breaking if make -jN is used.)
2017-02-22 11:58:49 +11:00
Angus Gratton
e91d436e45 build system: Probable fix for errors due to bad config bypassing components
See github #311 https://github.com/espressif/esp-idf/issues/311

Should fix weird compiler/linker bugs where config says something is
enabled, but build system says it is disabled.
Particularly noticeable when WiFi/BT libraries fail to
compile/link despite being enabled.

Underlying cause is configuration file regenerating, but component
Makefiles not reevaluating.

Entirely removes the idea that we don't need to generate config for some
targets (like 'clean'). We need valid config for these targets,
otherwise they don't know which files to clean (etc).
2017-02-22 11:58:49 +11:00
Angus Gratton
de28d3a655 Merge branch 'feature/partition_table_envvars' into 'master'
partition tables: Expand environment variables in gen_esp32part

Allows parametrizing partition table with (exported) make variables.

Merges PR #301 https://github.com/espressif/esp-idf/pull/301

See merge request !505
2017-02-22 07:22:04 +08:00
Ivan Grokhotkov
e76c187efb spi_flash: protect esp_intr_noniram_{disable,enable} in 1-core config
MR !441 (7c155ab) has fixed issue with esp_intr_noniram_{disable,enable}
calls not being properly protected by spi_flash_op_{lock,unlock}.
Unit test was added, but the unit test environment tests only dual-core
config. Similar issue was present in the code path for the single-core
config, where esp_intr_noniram_{disable,enable} calls were unprotected.

This change fixes the protection issue and updates the unit test to
run properly in single core config as well.

The issue with running unit tests for single core config will be
addressed in a separate MR.
2017-02-21 21:57:53 +08:00
Jeroen Domburg
e35ebbf813 Use THRESH_DMA_TRANS define everywhere, make code match "smaller or equal" description 2017-02-21 18:27:56 +08:00
Lourens Naudé
04f7d96623 Fix SPI read edges in spi_intr
Signed-off-by: Jeroen Domburg <jeroen@espressif.com>
2017-02-21 18:26:03 +08:00
Tian Hao
55693b1168 component/bt : add option to release about 30K from BT if BLE only
1. later BT/BLE will be separated by BT/BLE macro, but this option should use when user make sure that in BLE only mode.
2017-02-21 17:46:59 +08:00
Ivan Grokhotkov
26dec992eb deep sleep: add note about disabling WiFi and BT
This change adds a note to esp_deep_sleep that applications should disable WiFi and BT before going into deep sleep.
SNTP example is also updated.
2017-02-21 17:07:16 +08:00
Ivan Grokhotkov
d3fde5188e deep sleep: bring some registers into known state
In case WiFi/BT stack has been enabled but wasn’t disabled, some RTC
bits may be left enabled, causing increased current consumption.
This change returns some of the bits back to their default values.
2017-02-21 17:07:15 +08:00
Ivan Grokhotkov
3b583c150f bootloader: disconnect VRTC from SAR input in bootloader_random_disable
Bootloader enables SAR ADC in test mode to get some entropy for the RNG.
The bits which control the ADC test mux were not disabled, which caused
extra ~24uA current to be drawn from VRTC, increasing deep sleep current
consumption. This change disables relevant test mode bits in
bootloader_random_disable.
2017-02-21 17:07:15 +08:00
Ivan Grokhotkov
1405fd1fef Merge branch 'bugfix/exception_after_merge_phy_disable' into 'master'
bugfix: it causes exception that wifi interrupt happens when read/write flash, i…

…f pp_post() is on icache.

See merge request !518
2017-02-21 16:16:41 +08:00
Liu Zhi Fu
adfb289e81 Merge branch 'master' of ssh://gitlab.espressif.cn:27227/idf/esp-idf 2017-02-21 15:03:34 +08:00
XiaXiaotian
a51f378ecc bugfix: it causes exception that wifi interrupt happens when read/write flash, if pp_post() is on icache. 2017-02-21 14:25:34 +08:00
Jiang Jiang Jian
b5d1eb42b4 Merge branch 'feature/disable_phy_rf_when_disable_wifi_bt' into 'master'
disable PHY and RF when stop WiFi and disable BT

1. Add disable PHY and RF when WiFi and BT are both disabled(including call sniffer disable API).

2. Do not init PHY and RF when cpu start. Init PHY and RF when call Wifi or BT start APIs(including sniffer enable API).

3. Add a temporary lib: librtc_clk.a and will delete it when CPU frequency switching function is done.

4. Add an function to get OS tick rate.

5. Do not put the whole pp.a in iram0, only put lmac.o, ieee80211_misc.o, ets_time.o and wdev.o in iram0.

See merge request !510
2017-02-21 01:40:49 +08:00
XiaXiaotian
678ec0bd04 Merge branch 'master' of ssh://gitlab.espressif.cn:27227/idf/esp-idf into feature/disable_phy_rf_when_disable_wifi_bt 2017-02-21 01:20:48 +08:00
Tian Hao
12a7293b31 component/bt : add bluetooth status check
1. add bluetooth controller/host initialize status check
2. separate bluetooth controller task schedule loop from controller init
2017-02-21 01:05:37 +08:00
XiaXiaotian
bb0298bc71 coexist: enable coexist when wifi&bt are enabled, disable coexist when one of wifi&bt is disabled. 2017-02-20 23:53:25 +08:00
Yulong
abf87b000d component/bt:fixed the write ccc crash bug error 2017-02-20 08:50:02 -05:00
Ivan Grokhotkov
7eaf1c76dc Merge branch 'bugfix/vfat_open_append' into 'master'
Fix fopen() in “a” (append) mode

fopen() does not work when file is opened in “a” (append) mode

* Merges github PR #302 https://github.com/espressif/esp-idf/pull/302
* Closes #328 https://github.com/espressif/esp-idf/issues/328

See merge request !503
2017-02-20 13:32:32 +08:00
XiaXiaotian
770c2ade05 phy init: modify some comments 2017-02-20 10:44:40 +08:00
Angus Gratton
95b62ef980 Merge branch 'feature/doc_drivers' into 'master'
docs: Add missing peripheral driver docs (ADC, DAC, RTC I/O, I2S)

Plus some general driver doc related cleanup.

touch_pad docs to follow in a subsequent MR.

See merge request !508
2017-02-20 10:28:52 +08:00
Angus Gratton
4db4e28b6e uart driver docs: Remove references to setting interrupt number
Closes #185 https://github.com/espressif/esp-idf/issues/185
2017-02-20 10:39:29 +11:00
Angus Gratton
bfdfcbfaef docs: Add missing peripheral driver docs (ADC, DAC, RTC I/O, I2S) 2017-02-20 10:39:29 +11:00
Angus Gratton
21964a42fb rtc_gpio: Replace RTC_GPIO_IS_VALID_GPIO macro with inline function 2017-02-20 10:39:29 +11:00
Tian Hao
4bd5b0c91a component/bt : add bt enable/disable for power save
1. add new APIs bt controller enable/disab/deinit
2. make bt controller work need to call two APIs of esp_bt_controller_init and enable
3. modify phy init to make mac reset once
2017-02-17 19:24:58 +08:00
XiaXiaotian
8f3d1d3184 fix compile error that if enable CONFIG_ESP32_PHY_INIT_DATA_IN_PARTITION compile fail 2017-02-17 15:29:11 +08:00
Jiang Jiang Jian
4494e15ecf Merge branch 'feature/btdm_pll_track' into 'master'
component/bt : wide range work temperature for bluetooth RF

1. add PLL track for bluetooth RF for wide range temperature
2. move some initialized codes to cache

See merge request !511
2017-02-17 13:48:26 +08:00
Tian Hao
ad890aa5ea component/bt : wide range work temperature for bluetooth RF
1. add PLL track for bluetooth RF for wide range temperature
2. move some initialized codes to cache
2017-02-17 12:26:28 +08:00
XiaXiaotian
cd13c9e95d disable phy and rf
1. add a macro in menuconfig for users to choose whether store phy calibration data into NVS or not.

2. rename some disable phy and rf APIs so that existing code which calls old APIS will fail to compile.
2017-02-17 10:24:55 +08:00
XiaXiaotian
eb14284c92 disable PHY and RF when stop WiFi and disable BT
1. Add disable PHY and RF when WiFi and BT are both disabled(including call sniffer disable API).

2. Do not init PHY and RF when cpu start. Init PHY and RF when call Wifi or BT start APIs(including sniffer enable API).

3. Add a temporary lib: librtc_clk.a and will delete it when CPU frequency switching function is done.

4. Add an function to get OS tick rate.

5. Do not put the whole pp.a in iram0, only put lmac.o, ieee80211_misc.o, ets_time.o and wdev.o in iram0.
2017-02-17 10:24:54 +08:00
Jiang Jiang Jian
61c7bd3c3a Merge branch 'bugfix/btdm_gatt' into 'master'
component/bt : fix gatt write memory leak

fix bug of GATT write cause memory leak 

See merge request !506
2017-02-16 15:13:05 +08:00
Jiang Jiang Jian
6c139c8ffb Merge branch 'feature/ethernet_phy_power' into 'master'
ethernet: add a gpio to enable/disable phy power

ethernet board v2 use gpio 17 .

See merge request !495
2017-02-16 15:12:09 +08:00
Jiang Jiang Jian
997fbf9e18 Merge branch 'bugfix/btdm_iphone10_0_2' into 'master'
Bugfix/btdm iphone10 0 2

This connection error caused by iPhone, it think that TX data length must large than 27 when slave support EXTEND_DATA_LENGTH. But this should be allow. Besides,  the problem cannot be found on higher version of Iphone7, apple seemed to have fixed it.
Actually maybe other BLE device have the same problem.

See merge request !509
2017-02-16 15:10:50 +08:00
shangke
2fc4413dae ethernet: add pin macro 2017-02-16 14:36:46 +08:00
Tian Hao
6648ff427c component/bt : fix connection bug of Iphone7 10.0.2
This connection error caused by iPhone, it think that TX data length must large than 27 when slave support EXTEND_DATA_LENGTH. But this should be allow. Besides,  the problem cannot be found on higher version of Iphone7, apple seemed to have fixed it.
Actually maybe other BLE device have the same problem.
2017-02-16 14:15:46 +08:00
Tian Hao
5023e30a33 component/bt : fix gatt write memory leak 2017-02-15 20:08:39 +08:00
Angus Gratton
9cea5ea075 fatfs: Add unit test for overwrite/append fix 2017-02-15 18:04:28 +11:00
Ivan Grokhotkov
34d0b0086e Merge branch 'bugfix/openssl_server_example' into 'master'
Example 10_openssl_server should use TLSv1.2 instead of SSLv3; fixed corrupted HTTP Header

* Merges github PR #214 https://github.com/espressif/esp-idf/pull/214
* Closes #333 https://github.com/espressif/esp-idf/issues/333

See merge request !501
2017-02-15 14:34:08 +08:00
Angus Gratton
39c546d63f openssl_server example: Roll back to TLS_server_method() for compatibility
Add a comment recommending TLS v1.2.
2017-02-15 17:19:09 +11:00
Ivan Grokhotkov
413f05ce09 Merge branch 'docs/flash_encryption_disable' into 'master'
Docs: Document flash encryption disable steps, clean up flash encryption & secure boot docs

Generate clean up of flash encryption & secure boot docs

Including steps for disabling flash encryption (for people who accidentally enable it).

See merge request !500
2017-02-15 13:31:08 +08:00
Ivan Grokhotkov
578e93803a Merge branch 'bugfix/gperf_v3_1' into 'master'
kconfig: Remove gperf 3.1+ incompatible kconf_conf_id forward declaration

Forward declaration was unused. gperf 3.1+ changed parameter type from
'unsigned int' to 'size_t'.

Ref github #200 https://github.com/espressif/esp-idf/issues/200#issuecomment-279377753
Fixes #315 https://github.com/espressif/esp-idf/issues/315
Fixes #251 https://github.com/espressif/esp-idf/issues/251

See merge request !498
2017-02-15 13:29:18 +08:00
Ivan Grokhotkov
fe44bc9e79 Merge branch 'bugfix/add_espcoredump_to_add_paths_script' into 'master'
Add espcoredump to the add_path shell helper

Merges PR #335 https://github.com/espressif/esp-idf/pull/335


See merge request !504
2017-02-15 13:27:18 +08:00
Ivan Grokhotkov
174c313d3d Merge branch 'bugfix/send_crosscore_iram' into 'master'
esp32: Move esp_crosscore_int_send_yield() to IRAM

Merges PR #257 https://github.com/espressif/esp-idf/pull/257

See merge request !502
2017-02-15 13:26:56 +08:00
Ivan Grokhotkov
dd5401749d Merge branch 'bugfix/phy_init_write_nvs_once' into 'master'
phy_init: don’t rewrite valid calibration data

In the default PHY init routine, calibration data is loaded from NVS.
Most of the time the incremental changes to calibration will be fairly
small, so we don’t need to rewrite the existing calibration data stored
in the NVS.

Possible enhancement to be done in the future: expose a function in PHY
library to tell how big was the change in calibration data. If the
change was significant, then calibration data stored in NVS should be
updated.

See merge request !487
2017-02-15 13:26:22 +08:00
Ivan Grokhotkov
01c4a980ee Merge branch 'bugfix/fix_protection_of_queue_list' into 'master'
freertos: fix protection issue in freertos queue event list

When functions in queue.c calls listLIST_IS_EMPTY() to check queue event list, the queue list is
protected by queue mutex, on the other hand, when xTaskIncrementTick() modify the queue list, the
 queue list is protected by xTaskQueueMutex, this may cause xTaskRemoveFromEventList operate on
the empty queue list and cause problem.
This change works around the problem by reducing the window where the race condition can happen.

See merge request !465
2017-02-15 13:25:51 +08:00
Ivan Grokhotkov
25f05bef71 Merge branch 'bugfix/OTA_and_flash_encryption_incompatible' into 'master'
bootloader_support: fix bug OTA & flash encryption incompatible

github issue:https://github.com/espressif/esp-idf/issues/253

See merge request !464
2017-02-15 13:24:10 +08:00
Angus Gratton
24cfe78962 partition table: Fix comment at top of gen_esp32part.py 2017-02-15 10:28:45 +11:00
Angus Gratton
4c9fdb7c52 Docs: Mark PDF links as such in the documentation index
Nothing worse than clicking what you think is an internal page link
and finding a PDF downloading!
2017-02-15 09:42:46 +11:00
Angus Gratton
0eb5c06ad4 README: Add some tips on using menuconfig 2017-02-15 09:42:46 +11:00
Angus Gratton
7c7edab328 flash encryption/secure boot: Restructure documentation
Also add steps to disable flash encryption, as some people seem to
accidentally enable it.

Explicitly mark the flash encryption and secure boot as "READ DOCS
FIRST" in menuconfig.
2017-02-15 09:42:46 +11:00
Deomid Ryabkov
22c3877183 Expand environment variables in gen_esp32part
Allows parametrizing partition table with (exported) make variables.
2017-02-14 13:53:17 +08:00
nineisk
57af0d70d3 Fix fopen() in “a” (append) mode
fopen() does not work when file is opened in “a” (append) mode
2017-02-14 16:15:08 +11:00
Marcin Galczynski
10c2e984dc esp32: Move esp_crosscore_int_send_yield() to IRAM 2017-02-14 15:55:16 +11:00
Malte Janduda
dcd5c5bb73 Example 10_openssl_server should use TLSv1.2 instead of SSLv3; fixed corrupted HTTP Header 2017-02-14 15:38:37 +11:00
Angus Gratton
473f2cff51 kconfig: Remove gperf 3.1+ incompatible kconf_conf_id forward declaration
Forward declaration was unused. gperf 3.1+ changed parameter type from
'unsigned int' to 'size_t'.
2017-02-14 10:01:44 +11:00
Jiang Jiang Jian
a65944a8cb Merge branch 'bugfix/update_wifi_lib_to_include_some_fix_and_optimization' into 'master'
esp32: update wifi lib for some fixes and optimizations

1. Reduce the default static rx buffer size from 25 to 10
2. Adjust ampdu interrupt size to 3, namely, raise 1 interrupt per 3-mpdu
3. Make a copy for all received packets, including AMSDU/AMPDU/MPDU
4. Fix softap mis-forward issue
5. Fix pp q full issue
6. Fix sniffer copy wrong content issue

See merge request !491
2017-02-13 21:22:43 +08:00
Liu Zhi Fu
97eef61184 Merge branch 'master' of ssh://gitlab.espressif.cn:27227/idf/esp-idf 2017-02-13 17:39:53 +08:00
Jiang Jiang Jian
2664291ba5 Merge branch 'bugfix/btdm_blufi' into 'master'
fix BLUFI bug

fix BLUFI bug with small MTU size

See merge request !493
2017-02-13 14:52:46 +08:00
Jiang Jiang Jian
483411fd1a Merge branch 'bugfix/btdm_gatt_memleak' into 'master'
component/bt : fix GATT disconnect memory leak bug

fix a bug of memory leak of GATT disconnection

See merge request !496
2017-02-13 14:30:09 +08:00
Jiang Jiang Jian
554237bf5e Merge branch 'bugfix/btdm_demo_adv_raw_data' into 'master'
component/bt : use real adv data to set raw adv data

Use real advertising data to set raw advertising data in GATT-SERVER demo.

See merge request !492
2017-02-13 14:27:21 +08:00
Tian Hao
5fd7bd14db component/bt : fix GATT disconnect memory leak bug 2017-02-13 14:00:26 +08:00
Lourens Naudé
3aa2b571ae Add espcoredump to the add_path shell helper 2017-02-12 22:48:41 +00:00
shangke
e8b7670db3 ethernet: add doc 2017-02-11 16:42:16 +08:00
shangke
9893b71096 ethernet: add a gpio to enable/disable phy power 2017-02-11 15:19:53 +08:00
Tian Hao
cf917567e9 component/bt : use real adv data to set raw adv data 2017-02-10 16:40:40 +08:00
Tian Hao
2c334b46e0 component/bt : fix BLUFI bug with small MTU size 2017-02-10 11:20:34 +08:00
Liu Zhi Fu
0017e75bda freertos: fix protection issue in freertos queue event list
When functions in queue.c calls listLIST_IS_EMPTY() to check queue event list, the queue list is
protected by queue mutex, on the other hand, when xTaskIncrementTick() modify the queue list, the
 queue list is protected by xTaskQueueMutex, this may cause xTaskRemoveFromEventList operate on
the empty queue list and cause problem. This commit is to fix this bug.

may cause
2017-02-10 10:30:17 +08:00
Liu Zhi Fu
7093c59a74 esp32: update wifi lib for some fixes and optimizations
1. Reduce the default static rx buffer size from 25 to 10
2. Adjust ampdu interrupt size to 3, namely, raise 1 interrupt per 3-mpdu
3. Make a copy for all received packets, including AMSDU/AMPDU/MPDU
4. Fix softap mis-forward issue
5. Fix pp q full issue
6. Fix sniffer copy wrong content issue
2017-02-10 10:28:03 +08:00
Ivan Grokhotkov
02460ff864 Merge branch 'test/get_test_env_config_from_gitlab' into 'master'
CI: get test env config from gitlab

Previous design was put test env config on local runners. It's not easy to manage as test runners count growing. 

Now we'll put config files for test runners to a Gitlab repository. Test runners will get its config from Gitlab every time before running.

See merge request !480
2017-02-08 16:56:38 +08:00
Jeroen Domburg
c61fdff729 Merge branch 'bugfix/yield_other_core_prio_check_fix' into 'master'
Fix interrupting task on other CPU that has lower prio than current task on current CPU

Fix for a very subtle bug introduced somewhere in december. This bug would cause a cross-core interrupt to only be sent if the activated task has a higher priority than the task currently running on *this* cpu, instead of on the other CPU.

See merge request !475
2017-02-08 12:19:34 +08:00
Ivan Grokhotkov
777816cb99 phy_init: don’t rewrite valid calibration data
In the default PHY init routine, calibration data is loaded from NVS.
Most of the time the incremental changes to calibration will be fairly
small, so we don’t need to rewrite the existing calibration data stored
in the NVS.

Possible enhancement to be done in the future: expose a function in PHY
library to tell how big was the change in calibration data. If the
change was significant, then calibration data stored in NVS should be
updated.
2017-02-07 15:14:45 +08:00
Jiang Jiang Jian
89fea85a45 Merge branch 'bugfix/fix_several_wifi_misc_issues' into 'master'
esp32: fix several misc wifi issue

1. Fix ssid_str not free issue
2. Fix sniffer not work issue
3. Fix null parameter cause esp_wifi_init crash issue
4. Enable ap ampdu rx interface

See merge request !484
2017-02-07 11:15:58 +08:00
Liu Zhi Fu
b748a63a43 esp32: fix several misc wifi issue
1. Fix ssid_str not free issue
2. Fix sniffer not work issue
3. Fix null parameter cause esp_wifi_init crash issue
4. Enable ap ampdu rx interface
2017-02-06 17:56:42 +08:00
Jeroen Domburg
d07a149e2c Fix interrupting task on other CPU that has lower prio than current task on current CPU 2017-02-06 17:53:07 +08:00
Ivan Grokhotkov
c78aa138b0 Merge branch 'bugfix/esp32_core_dump_wd_uart' into 'master'
esp32: Fixes watchdog problem when printing core dump to uart

1) Fixes watchdog problem when printing core dump to uart
2) Also fixes generation of core dumps when flash cache is disabled


See merge request !472
2017-02-06 17:44:08 +08:00
Wu Jian Gang
e8adb5ab57 Merge branch 'bugfix/ethernet_flow_ctrl' into 'master'
ethernet:disable flow control when select l2_to_l3_copy_mode

Disable flow control when select l2_to_l3_copy_mode ,because this mode can not touch flow control watermark  .

See merge request !482
2017-02-06 13:42:18 +08:00
shangke
627bc23b1c ethernet:disable flow control when select l2_to_l3_copy_mode 2017-02-06 11:19:16 +08:00
Liu Zhi Fu
96e6839745 Merge branch 'master' of ssh://gitlab.espressif.cn:27227/idf/esp-idf 2017-02-05 15:34:36 +08:00
Angus Gratton
2d5162dc3c OTA: Always clean up OTA handle regardless of esp_ota_end() result
As reported on forum: http://esp32.com/viewtopic.php?f=14&t=1093
2017-02-03 10:07:30 +11:00
He Yin Ling
732a5fd0b2 CI: get test env config from gitlab
Previous design was put test env config on local runners. It's not easy
to manage as test runners count growing. Now we'll put config files for
test runners to a Gitlab repository. Test runners will get its config
from Gitlab every time before running.
2017-02-02 21:59:00 +08:00
Alexey Gerenkov
04acc88023 esp32: Fixes watchdog problem when printing core dump to uart
Also fixes generation of core dumps when flash cache is disabled
2017-02-01 18:39:28 +03:00
Ivan Grokhotkov
b8e2edc99f Merge branch 'bugfix/esp32_core_dump_esptool_search_path' into 'master'
esp32: Fixed search path for esptool

@igrokhotkov @angus Could you review the fix?

See merge request !474
2017-02-01 13:59:40 +08:00
Ivan Grokhotkov
f21275b910 Merge branch 'bugfix/esp32_core_dump_doc' into 'master'
esp32: Fixed and updated core dump docs



See merge request !473
2017-02-01 13:59:15 +08:00
Angus Gratton
0a678ebe8c Merge branch 'feature/openssl_option' into 'master'
components/openssl: refactor openssl debugging and assert function

1. add openssl option at menuconfig
2. remove SSL_ERR to reduce complexity
3. add more functions about debugging and assert

According these, our coders and customers may use and debug the OpenSSL code easily.


See merge request !400
2017-01-27 08:37:02 +08:00
Angus Gratton
21c7fc624a Merge branch 'bugfix/encrypted_partition_flag' into 'master'
Use PART_FLAG_ENCRYPTED value in gen_esp32part.py

Currently paritions marked as encrypted by gen_esp32part.py are not
recognized as such and encrypted writes don't work.

This is part of espressif/esp-idf#253

Merges Pull Request #293 https://github.com/espressif/esp-idf/pull/293

See merge request !470
2017-01-27 08:34:08 +08:00
Angus Gratton
aaa891ada9 Merge branch 'feature/custom_partition_table_csv_path' into 'master'
Allow providing custom PARTITION_TABLE_CSV_PATH

Provide direct absolute path to CSV, without project_path

Github pull request #296: https://github.com/espressif/esp-idf/pull/296

See merge request !469
2017-01-27 08:33:41 +08:00
Angus Gratton
a4c76671c2 Merge branch 'bugfix/spi_multiple_cs_fix' into 'master'
Add missing variable initialisation to make SPI work for multiple CS

Ref https://github.com/espressif/esp-idf/pull/277
From PR: "I am not especially familiar with this platform or with esp-idf -- so review with care.

The spi-master driver would not work for me when the number of devices on a bus exceeded 1 (caused device hang). I believe this is because cur_cs is not properly set (anywhere), and yet is used. This is likely just not noticed because 0 is presumably the correct value when there's only 1 device (and I'm guessing multi-device setup is not tested as thoroughly).

Simply setting cur_cs to the correct slot value resolves the problem and multiple devices on a single bus behave correctly in my test environment."

Looks like a small oversight on my side.

See merge request !468
2017-01-27 08:33:16 +08:00
Alexey Gerenkov
f512923791 esp32: Fixed search path for esptool 2017-01-26 19:28:13 +03:00
Alexey Gerenkov
e6f8837152 esp32: Fixed and updated core dump docs 2017-01-26 18:47:10 +03:00
Jiang Jiang Jian
5e3b30da3a Merge branch 'bugfix/fix_two_wifi_datapath_issues' into 'master'
esp32: udpate wifi lib to fix two datapath issues

1. fix ampdu<->mpdu<->ampdu switch may cause rx slow issue by put mpdu into ampdu reorder queue
2. fix each ac first sending always fail issue by adding retry

See merge request !471
2017-01-26 21:52:28 +08:00
Angus Gratton
b6a2329f0f FreeRTOS: esp_crosscore_int_send_yield() should be in IRAM
Possible for xQueueGenericSendFromISR -> xTaskRemoveFromEventQueueList
-> taskYIELD_OTHER_CORE code path to occur while cache is off.
2017-01-26 18:53:02 +11:00
Angus Gratton
eea2788f5a OTA: Fix issues with encrypted OTA
- OTA source can write non-16-byte multiples of data
- Assumption that empty ota_data is 0xFFFFFFFF untrue when encrypted
2017-01-26 18:52:35 +11:00
Liu Zhi Fu
385c61e183 esp32: udpate wifi lib to fix two datapath issues
1. fix ampdu<->mpdu<->ampdu switch may cause rx slow issue by put mpdu into ampdu reorder queue
2. fix each ac first sending always fail issue by adding retry
2017-01-26 15:35:04 +08:00
Liu Zhi Fu
39fe51924e esp32: update wifi lib to fix two datapath issues
1. fix ampdu<->mpdu<->ampdu switch may cause rx slow issue by put mpdu into ampdu reorder queue
2. fix each ac first sending always fail issue by adding retry
2017-01-26 15:33:23 +08:00
Angus Gratton
d8aae55eeb Flash encryption: Temporary fix for issue with stale cache reads
Seems doing certain kinds of short reads while flash encryption is
enabled will return stale data. This fixes it, but is probably a
little heavy-handed performance wise.
2017-01-26 18:29:18 +11:00
Angus Gratton
67336672bd OTA: Improve verification of OTA image before writing, incl. secure boot
Verify 0xE9 magic byte on first write, verify entire image before
switching.

Enable verification for secure boot signature (was using invalid ifdef
guard)
2017-01-26 16:20:06 +11:00
Angus Gratton
813395adcb OTA: Fall back to factory partition if ota data partition is invalid 2017-01-26 16:20:06 +11:00
Tian Zhong Xing
2173ad3b45 bootloader_support: fix bug OTA & flash encryption incompatible
ota data partition should be encrypted unconditionally when flash encrypt enable
2017-01-26 16:20:06 +11:00
Ivan Grokhotkov
4dd81fddd8 Merge branch 'feature/add_build_at_job_in_ci' into 'master'
CI: add job to check build esp-at in esp-idf

Add a job to check if latest IDF breaks `esp-at` build.

As `esp-at` is an application and has its own CI, we don't save binary as artifacts.

See merge request !462
2017-01-26 10:46:45 +08:00
Dong Heng
93395a3370 components/openssl: Add more debugging information at platform level 2017-01-26 10:12:58 +08:00
Deomid Ryabkov
4f7e4dd0f5 Use PART_FLAG_ENCRYPTED value in gen_esp32part.py
Currently paritions marked as encrypted by gen_esp32part.py are not
recognized as such and encrypted writes don't work.

This is part of espressif/esp-idf#253
2017-01-26 12:27:00 +11:00
Dermot Duffy
33500f2561 Add missing variable initialisation.
Signed-off-by: Jeroen Domburg <jeroen@espressif.com>
2017-01-25 21:41:45 +08:00
Jiang Jiang Jian
32ad1e676d Merge branch 'lwip/optimize_dhcpc_taken_time' into 'master'
lwip: optimize the dhcp client

1. modify the discover retry backoff time from (2,4,8,16,32,60,60)s to (500m,1,2,4,8,15,15)s.
2. add DHCP_DOES_ARP_CHECK to menuconfig for users to specify if do a ARP check on the offered address.
   If enable, one more second will be taken.

See merge request !459
2017-01-25 21:39:17 +08:00
Ivan Grokhotkov
8e467801bc Merge branch 'bugfix/btdm_debug_gatt_attr_table' into 'master'
component/bt: Fix Gatt table read_req bug and advertising channel 39 not available bug

1. Fix Gatt table read request bug
2. Fix advertising channel 39 not available bug

See merge request !463
2017-01-25 11:48:09 +08:00
Island
c6bb239f0c component/bt: Fix Gatt table read_req bug and advertising channel 39 not available bug 2017-01-25 11:18:26 +08:00
Deomid Ryabkov
74f78540ae Allow providing custom PARTITION_TABLE_CSV_PATH
Provide direct absolute path to CSV, without project_path
2017-01-25 00:30:29 +00:00
Dong Heng
1d0c909daf components/openssl: fixes for github issues 219
"SSL_write" doesn't send large buffers correctly
2017-01-24 17:36:32 +08:00
He Yin Ling
d193424ae8 CI: add job to check build esp-at in esp-idf 2017-01-24 15:52:07 +08:00
qiyueixa
03e3b137bf lwip: optimize the dhcp client
1. modify the discover retry backoff time from (2,4,8,16,32,60,60)s to (500m,1,2,4,8,15,15)s.
2. add DHCP_DOES_ARP_CHECK to menuconfig for users to specify if do a ARP check on the offered address.
   If enable, one more second will be taken in obtaining IP address.
3. update wifi libs
2017-01-23 13:44:34 +08:00
Ivan Grokhotkov
6bc9cd39e9 Merge branch 'feature/spi_flash_write_16bytes' into 'master'
SPI Flash: Allow 16 byte aligned encrypted writes

Also includes some improved documentation

See merge request !456
2017-01-20 20:09:48 +08:00
Angus Gratton
d4462664b7 spi_flash: Move FLASH_PAGE_SIZE constant into esp_spi_flash.h 2017-01-20 19:50:01 +08:00
Angus Gratton
14aa1d1b3e docs: spi_flash: Add flash encryption ops, remove boilerplate 2017-01-20 19:50:01 +08:00
Angus Gratton
adc590ff69 spi_flash_write_encrypted: Allow 16-byte aligned block writes
As each 32 byte write has two identical 16 byte AES blocks, it's
possible to write them separately.
2017-01-20 19:48:46 +08:00
Angus Gratton
36ccdee6ec spi_flash: Flush flash cache if flash_mmap()ing a written-to page
Without this, it's possible for stale information to be read from
cache via mmap, even if the MMU table entry had been invalidated
prior to writing flash (if  the same MMU table entry was re-used after
writing flash.)
2017-01-20 19:48:46 +08:00
Angus Gratton
95c150fe2c spiflash: Add spi_flash_read_encrypted() function 2017-01-20 19:48:46 +08:00
Ivan Grokhotkov
fbe89a0833 Merge branch 'feature/deploy_tags' into 'master'
ci: deploy code and docs for tags

Currently deploy happens only for the master branch.
This change is needed to support tags in release branches.

See merge request !458
2017-01-20 19:38:02 +08:00
Ivan Grokhotkov
b4a29f5240 ci: deploy code and docs for release branches
Currently deploy happens only for the master branch.
This change is needed to support release branches.
2017-01-20 18:45:21 +08:00
Ivan Grokhotkov
374d03093c Merge branch 'bugfix/misc_fixes' into 'master'
Misc fixes (including Github PRs)

Collection of single commit fixes, including several from Github.

See merge request !457
2017-01-20 17:53:12 +08:00
Ivan Grokhotkov
632bd0bb4f Merge branch 'feature/docs_gh_link_roles' into 'master'
docs: use custom roles to generate GitHub links

This change replaces direct links to GitHub master branch with
auto-generated links using docutils custom roles.
These auto-generated links point to the tree or blob for the git commit
ID (or tag) of the repository. This is needed to ensure that links don’t
become broken when files in master branch are moved around or deleted.

The following roles are introduced:

```
- :idf:`path` - points to directory inside ESP-IDF
- :idf_blob:`path` - points to file inside ESP-IDF
- :idf_raw:`path` - points to raw view of the file inside ESP-IDF
- :component:`path` - points to directory inside ESP-IDF components dir
- :component_blob:`path` - points to file inside ESP-IDF components dir
- :component_raw:`path` - points to raw view of the file inside ESP-IDF
  components dir
- :example:`path` - points to directory inside ESP-IDF examples dir
- :example_blob:`path` - points to file inside ESP-IDF examples dir
- :example_raw:`path` - points to raw view of the file inside ESP-IDF
  examples dir
```

A check is added to the CI build script, which searches RST files for
presence of hard-coded links (identified by tree/master, blob/master,
or raw/master part of the URL).
This check can be run manually: cd docs && make gh-linkcheck

Additionally, Sphinx linkcheck build type is used to create new CI test,
which check for broken links. This test has to be triggered explicitly,
because including it in normal build process (when the commit is not yet
deployed to Github) will not work. It can be triggered in a regular
fashion using a combination of cron and Curl, similar to stress tests.

See merge request !455
2017-01-20 17:47:34 +08:00
Ivan Grokhotkov
15072028c4 docs: use custom roles to generate GitHub links
This change replaces direct links to GitHub master branch with
auto-generated links using docutils custom roles.
These auto-generated links point to the tree or blob for the git commit
ID (or tag) of the repository. This is needed to ensure that links don’t
become broken when files in master branch are moved around or deleted.

The following roles are introduced:

- :idf:`path` - points to directory inside ESP-IDF
- :idf_blob:`path` - points to file inside ESP-IDF
- :idf_raw:`path` - points to raw view of the file inside ESP-IDF
- :component:`path` - points to directory inside ESP-IDF components dir
- :component_blob:`path` - points to file inside ESP-IDF components dir
- :component_raw:`path` - points to raw view of the file inside ESP-IDF
  components dir
- :example:`path` - points to directory inside ESP-IDF examples dir
- :example_blob:`path` - points to file inside ESP-IDF examples dir
- :example_raw:`path` - points to raw view of the file inside ESP-IDF
  examples dir

A check is added to the CI build script, which searches RST files for
presence of hard-coded links (identified by tree/master, blob/master,
or raw/master part of the URL).
This check can be run manually: cd docs && make gh-linkcheck

Additionally, Sphinx linkcheck build type is used to create new CI test,
which check for broken links. This test has to be triggered explicitly,
because including it in normal build process (when the commit is not yet
deployed to Github) will not work. It can be triggered in a regular
fashion using a combination of cron and Curl, similar to stress tests.
2017-01-20 17:22:47 +08:00
Angus Gratton
fab35cb307 Merge branch 'feature/esptool_v20_beta' into 'master'
Update esptool.py to v2.0-beta1

* Minor bug fixes, no major functionality changes from the esp-idf perspective.
* Now tracks master branch of esptool repo (finally!)
* Supports Python 3, although our other esp-idf Python tools don't yet support Python 3.

See merge request !396
2017-01-20 15:45:03 +08:00
Mike Ryan
74aff89918 gatts_demo: re-enter advertising after client disconnects
In the existing tree, after a connected client disconnects the device
will never re-enter the advertising state. Additional clients will not
be able to discover or connect to the device. This patch forces the
device back into the advertising state upon disconnection.

Resolves Pull Request #217 https://github.com/espressif/esp-idf/pull/217
2017-01-20 14:57:41 +11:00
Dermot Duffy
6f3f3bb30c Add missing bit from LEDC interrupt state struct.
Resolves #191 https://github.com/espressif/esp-idf/pull/191
2017-01-20 14:57:24 +11:00
Jan Schmidt
a14f22f65b netconn_gethostbyname: Fix race reporting success
If the DNS request is dispatched and performed very quickly,
then it can complete before tcpip_callback() actually returns,
in which case we'll destroy the actual err_t error value passed
in the message. Use a local variable for the tcpip_callback
error code so that can't happen.

Resolves #269 https://github.com/espressif/esp-idf/pull/269
2017-01-20 14:57:00 +11:00
Jan Schmidt
ac412feb69 gpio: Attach gpio intr to the isr_server on the right core.
Make sure GPIO interrupts get attached to the core that
the ISR service routine is running on, otherwise they
don't arrive.
2017-01-20 14:56:59 +11:00
Angus Gratton
b022232e84 esp_panic.h: Add C++ include guards 2017-01-20 14:56:59 +11:00
Angus Gratton
0b257cfcef bt: esp_ble_gatts_send_indicate: Fix description 2017-01-20 14:56:54 +11:00
Ivan Grokhotkov
92b9ed8342 Merge branch 'bugfix/ci_test_result_always_fail' into 'master'
CI: fix bug that test result always fail

CI test report jobs always fails because of 2 bugs:

1. merge/rebase error: the variable used to log test result is modified during merge/rebase
2. path of unit test module definition file is not correct

See merge request !454
2017-01-20 11:13:41 +08:00
He Yin Ling
5305842763 CI: fix merge error on test report job
the variable used to save report result is changed by merge error
2017-01-19 23:37:12 +08:00
Jiang Jiang Jian
0fca7769e8 Merge branch 'bugfix/ethernet_flow_control' into 'master'
ethernet: limit rx buf num when flow ctrl enable.



See merge request !452
2017-01-19 22:16:40 +08:00
He Yin Ling
3c28283377 CI: fix bug that test result always fail
the path of module definition file from unit test is not correct
2017-01-19 18:59:50 +08:00
Jiang Jiang Jian
aea18f6e74 Merge branch 'feature/btdm_raw_adv' into 'master'
Feature/btdm raw adv

Add APIs to set raw advertising data and scan response data by user self.

See merge request !451
2017-01-19 18:57:39 +08:00
Wu Jian Gang
1916610b83 Merge branch 'bugfix/fix_ap_not_reply_ba_issue' into 'master'
esp32: update wifi lib to fix ap not respond BA bug

Currently softap doesn't replay BA when receiving AMPDU, this fix is to fix this bug

See merge request !453
2017-01-19 18:27:48 +08:00
Liu Zhi Fu
12b1c99962 esp32: update wifi lib to fix ap not respond BA bug
Currently softap doesn't respond BA when receiving AMPDU, this fix is to fix this bug
2017-01-19 18:01:32 +08:00
Tian Hao
0073ff3acd component/bt : add api to set raw adv_data/scan_rsp_data
1. add api to set raw scan response data
2. add api to set raw scan response data
3. update doxygen
4. add menuconfig to config gatt server demo
2017-01-19 17:36:40 +08:00
shangke
2ea4d7fd02 ethernet: limit rx buf num when flow ctrl enable. 2017-01-19 16:45:30 +08:00
Ivan Grokhotkov
7eb570b039 Merge branch 'bugfix/phy_auto_init' into 'master'
Move PHY options out of WiFi config, improve descriptions

- move PHY-related settings into new menu, make it dependent on WIFI_ENABLED || BT_ENABLED

- improve descriptions of Ethernet Kconfig options


See merge request !443
2017-01-19 13:27:17 +08:00
Ivan Grokhotkov
b1df4c47f9 kconfig: define ESP32_PHY_MAX_TX_POWER if PHY_ENABLED
ESP32_PHY_MAX_TX_POWER option is only meaningful for WiFi, so previous
change made it depend on WIFI_ENABLED. However if WiFi is not enabled,
but BT is, this option becomes undefined which breaks phy_init_data
generation.

This change turns ESP32_PHY_MAX_TX_POWER into a hidden parameter, which
depends on PHY_ENABLED. New user-visible parameter,
ESP32_PHY_MAX_WIFI_TX_POWER is introduced which depends on WIFI_ENABLED
and is used as default value for ESP32_PHY_MAX_TX_POWER if WIFI_ENABLED
is set. Otherwise ESP32_PHY_MAX_WIFI_TX_POWER is set to 20.
2017-01-19 10:58:09 +08:00
Ivan Grokhotkov
0865819cf9 Merge branch 'feature/category_readme' into 'master'
Readme and links to example category folders

- Added README.md to example category folders, for BT ref. https://github.com/espressif/esp-idf/issues/262
- Added links from api category TOC to example category folders

See merge request !450
2017-01-19 10:19:06 +08:00
Ivan Grokhotkov
12e3992ae2 Merge branch 'bugfix/console_uart_none' into 'master'
Fix compilation if CONSOLE_UART is set to NONE

CONFIG_CONSOLE_UART_BAUDRATE is not defined

See merge request !445
2017-01-19 10:18:33 +08:00
Ivan Grokhotkov
1ebf907658 Merge branch 'bugfix/lwip_tcpip_printf' into 'master'
TCPIP: Do not printf if debug level is not correct



See merge request !448
2017-01-19 10:18:12 +08:00
Ivan Grokhotkov
9ae3ecc72c Merge branch 'bugfix/dhcp_debug_printf' into 'master'
DHCP: Do not printf if debug is not enabled



See merge request !447
2017-01-19 10:17:53 +08:00
Ivan Grokhotkov
a6b163c954 Merge branch 'bugfix/frc1_timer_clear' into 'master'
newlib: fix register used for DPORT/RTC bug workaround

While there was no register at DR_REG_FRC_TIMER_BASE + 0x60, due to
peripheral address space wraparound this write actually affected one of
FRC2 registers, which is used by WiFi stack to implement legacy
ets_timer APIs.
This change uses FRC_TIMER_LOAD_REG(0) instead, which can be set to
known value safely.

See merge request !449
2017-01-19 10:17:36 +08:00
Ivan Grokhotkov
7c155ab647 Merge branch 'bugfix/flash_op_unpinned_task' into 'master'
fixes for issues observed when using spi_flash

This MR fixes three unrelated issues:

- Race condition in spi_flash_enable_interrupts_caches_and_other_cpu
  when operations on unpinned tasks are performed.
  The issue is reported in https://github.com/espressif/esp-idf/pull/258

- esp_intr_noniram_disable doesn’t disable interrupts when compiled in
  release mode. This issue manifested itself with an illegal instruction
  exception when task WDT ISR was called at the time when flash was
  disabled.
  Fixes https://github.com/espressif/esp-idf/issues/263.

- Tick hooks on CPU1 were not called if CPU0 scheduler was disabled for
  significant amount of time (which could happen when doing flash erase).
  The issue manifested itself as “INT WDT timeout on core 1” error.
  Fixes https://github.com/espressif/esp-idf/issues/219.

See merge request !441
2017-01-19 10:14:34 +08:00
Angus Gratton
9a8a82e857 phyinit: Use PHY config to enable, don't need phy_get_romfunc_addr to init 2017-01-19 11:18:44 +11:00
krzychb
16b23a407c Added links from api category TOC to example category folders
Typo fix in bluetooth README.md
2017-01-18 21:21:02 +01:00
krzychb
0b6598c492 Added README.md to example category folders 2017-01-18 21:03:15 +01:00
Ivan Grokhotkov
90c43ea95e newlib: fix register used for DPORT/RTC bug workaround
While there was no register at DR_REG_FRC_TIMER_BASE + 0x60, due to
peripheral address space wraparound this write actually affected one of
FRC2 registers, which is used by WiFi stack to implement legacy
ets_timer APIs.
This change uses FRC_TIMER_LOAD_REG(0) instead, which can be set to
known value safely.
2017-01-19 00:36:30 +08:00
Ivan Grokhotkov
30c2fca25a Merge branch 'bugfix/docs_cleanup' into 'master'
Organize examples and API documentation - supplement to !430

This supplement to !430, both intended to replace bulky  !421.

1. Fixed broken links
2. Added links to available examples in API documentation, where missing
3. Updated links to point directly to example folder (to show README.md with example description)
4. Added README.md in docs folder info to point reader to ReadTheDocs instead of doc sources, ref. https://github.com/espressif/esp-idf/issues/243
5. Fixed some typo errors / Sphinx warnings
6. Fixed memory leak in example, ref. https://github.com/espressif/esp-idf/issues/209


See merge request !440
2017-01-19 00:33:31 +08:00
Ivan Grokhotkov
efbd2805e2 ethernet: improve kconfig option descriptions
Also limit suggested EMAC task priority range to 22, as the top priority
should be used only by IPC tasks.
2017-01-19 00:32:10 +08:00
Tian Hao
97e3c0fec4 kconfig: move PHY-related settings into new menu
- PHY options must be shown when either WIFI or BT is enabled.

- Add clarification that TX power option applies to WiFi only.
2017-01-19 00:30:20 +08:00
Ivan Grokhotkov
31ec0a7c44 freertos: call tick hooks on CPU1 even if CPU0 scheduler is suspended
The block which dispatches ticks on CPU1 was a copy of the code block
for the normal path (CPU0). It used to check uxPendedTicks, with the
logic that uxPendedTicks can be 0 iff the scheduler is not suspended.

On CPU1 however, uxPendedTicks is not related to the state of the
scheduler (as uxPendedTicks is updated on CPU0). Due to this, if CPU0
scheduler was suspended, and uxPendedTicks happened to be nonzero,
tick hooks on CPU1 didn’t run, even though CPU1 scheduler was working.

This change removes the check for uxPendedTicks in CPU1 code path,
so that the tick hooks on CPU1 always get called (as for the CPU0 code
path).
2017-01-18 23:19:05 +08:00
me-no-dev
d3a2d6aedc Do not printf if debug level is not correct 2017-01-18 16:13:09 +02:00
me-no-dev
26015f5d88 Do not printf if debug is not enabled 2017-01-18 16:06:54 +02:00
me-no-dev
865b21d5a1 Fix compilation if CONSOLE_UART is set to NONE
CONFIG_CONSOLE_UART_BAUDRATE is not defined
2017-01-18 15:36:10 +02:00
Jiang Jiang Jian
3c2d54ead0 Merge branch 'bug/tw7809_sta_no_rewiring_softap' into 'master'
tw7809: fix station no rewiring softap probability



See merge request !444
2017-01-18 20:45:08 +08:00
XiaXiaotian
0564263e5b tw7809: fix station no rewiring softap probability 2017-01-18 20:17:03 +08:00
Ivan Grokhotkov
3128f2b004 Merge branch 'bugfix/partition_write_encrypted' into 'master'
Allow writes to encrypted partitions

There is a size alignment requirement but it is checked by
spi_flash_write_encrypted. However, this check flat-out bans encrypted
writes.

Original PR on Github: https://github.com/espressif/esp-idf/pull/249

See merge request !432
2017-01-18 18:32:03 +08:00
Ivan Grokhotkov
f7e2e456e4 intr_alloc: mark inline asm operand as earlyclobber
When compiling in release mode, compiler was choosing same register for
oldint and intmask variables, so INTENABLE was never modified.
This effectively broke disabling of non-IRAM interrupts during flash
operations, observed in the existing tests if task watchdog is enabled.
This change adds an extra constraint tells the compiler that output
operand should not be placed into the same register as an input one.
2017-01-18 18:31:06 +08:00
Jiang Jiang Jian
680a0d1306 Merge branch 'bugfix/btdm_isr_cache' into 'master'
component/bt : move some codes of controller to iram

1. mv codes which called by isr into iram
2. mv libcoexist.a into iram

See merge request !442
2017-01-18 17:38:55 +08:00
Ivan Grokhotkov
0b3646f26e Merge branch 'feature/parse_unit_test_cases_from_test_files' into 'master'
Parse unit test cases from test files

As of now, we need to sync three different places when adding new unit test cases. The plan is to add a python script in tools/unit-test-app. This script would parse unit test cases from the C files with tests and generate the needed YAML files in components/idf_test/unit_test. CI would run this script in build stage to create the files and unit-test stage would use the generated files to run tests.

To get the needed test metadata, we need to add some more tags in the test case functions. For example:

```
TEST_CASE("SYS_LIB_0102 test time functions", "[stdlib][fails][env=UT_T1_APC]") 
{
    //...
}
```

Reason for this kind of implementation is that we need the YAML files for generating documents.

See merge request !275
2017-01-18 17:23:04 +08:00
antti
0501507d6b CI: add script for parsing unit test cases for CI from test files
Add python script that parses list of unit test cases for CI from component test folder

Modify .gitlab-ci.yml to run this script as part of build unit tests stage
2017-01-18 17:08:20 +08:00
antti
f8b5c29346 esp32: add [ignore] tag to some unit test cases for CI
Add ignore tag on unit test cases that are not supported in CI yet
2017-01-18 17:08:20 +08:00
antti
57f911033d esp32: add unit testing doc 2017-01-18 17:08:20 +08:00
Tian Hao
2bb67985dc component/bt : move some codes of controller to iram
1. mv codes which called by sir into iram
2. mv libcoexist.a into iram
2017-01-18 16:38:06 +08:00
Jiang Jiang Jian
6e2e456d62 Merge branch 'bugfix/btdm_minor_misc' into 'master'
component/bt : fix gatt server table bugs

1. fix gatt server table bugs
2. fix blufi a minor bugs
3. fix example minor mistakes

See merge request !438
2017-01-18 16:14:50 +08:00
Ivan Grokhotkov
4676d159ad spi_flash: fix race condition when doing operations in unpinned tasks
spi_flash_enable_interrupts_caches_and_other_cpu function used to enable
non-IRAM interrupts after giving up flash operation lock, which would
cause problems if another task was waiting on the lock to start a flash
operation. In fact, non-IRAM interrupts should be re-enabled before the
task scheduler is resumed. Otherwise non-pinned task can be moved to the
other CPU due to preemption, causing esp_intr_noniram_enable to be
called on the other CPU, causing an abort to be triggered.

Fixes the issue reported in
https://github.com/espressif/esp-idf/pull/258
2017-01-18 15:07:27 +08:00
Ivan Grokhotkov
0b2962f41e Merge branch 'feature/update_gitignore' into 'master'
Update gitignore for examples

Also ignore .settings since some of us use eclipse.

See merge request !437
2017-01-18 10:32:14 +08:00
Ivan Grokhotkov
557dafda07 Merge branch 'bugfix/high_timer_int' into 'master'
Delete option to select core timer 2 as a FreeRTOS tick source

Core timer 2 is unusable for FreeRTOS ticks because it triggers a high-level interrupt. This MR deletes the option to select it.

Ref https://github.com/espressif/esp-idf/issues/234

See merge request !418
2017-01-18 10:31:03 +08:00
Wu Jian Gang
0bbc60618b Merge branch 'feature/add_get_idf_version_api' into 'master'
Add get idf version API

This is same as IDF_VER.

See merge request !435
2017-01-18 09:44:53 +08:00
Wu Jian Gang
e62b255813 Merge branch 'feature/add_some_configurable_lwip_options' into 'master'
Allow config TCP_MAXRTX & TCP_SYNMAXRTX in menuconfig



See merge request !436
2017-01-18 09:44:23 +08:00
krzychb
8aa5082baa Fixed memory leak in example, ref. https://github.com/espressif/esp-idf/issues/209 2017-01-17 21:20:24 +01:00
krzychb
66647bb5bd Typo corrections 2017-01-17 21:12:54 +01:00
krzychb
46d8ece20e Docs folder info, ref. https://github.com/espressif/esp-idf/issues/243; Doc title fix 2017-01-17 20:37:27 +01:00
krzychb
03c14809f9 Updated links to point directly to example folder, fixed names 2017-01-17 20:03:26 +01:00
krzychb
5ae9647667 Added links to examples in API documentation 2017-01-17 19:12:48 +01:00
krzychb
fb7b218091 Fixed broken links 2017-01-17 18:53:29 +01:00
Tian Hao
5508826509 component/bt : fix gatts demo mistakes & unpeg notify bug 2017-01-17 20:13:25 +08:00
Tian Hao
799be9fa3a component/bt : fix gatt server table bugs
1. fix gatt server table bugs
2. fix blufi a minor bug
2017-01-17 18:42:11 +08:00
Wu Jian Gang
963c3aa16a gitignore: Update gitignore for examples 2017-01-17 17:55:29 +08:00
Wu Jian Gang
3c8235d40d lwip: Allow config TCP_MAXRTX & TCP_SYNMAXRTX in menuconfig 2017-01-17 17:44:25 +08:00
Wu Jian Gang
f4d5d151aa esp32: add get idf version api 2017-01-17 16:52:42 +08:00
Ivan Grokhotkov
a14bef8f8a Merge branch 'feature/categorize_examples_doc_new' into 'master'
Organize examples and API documentation

Organize / categorize growing number of code examples and API documentation,  ref. https://gitlab.espressif.cn:6688/idf/esp-idf/issues/10

This merge request is intended to replace most of https://gitlab.espressif.cn:6688/idf/esp-idf/merge_requests/421. The rest of changes submitted in https://gitlab.espressif.cn:6688/idf/esp-idf/merge_requests/421 will follow.

1. Moved examples to category folders, removed numbers from example names
2. Modified `buid_examples.sh` script to handle new locations of examples
3. Moved api-name.rst files to category folders
4. Updated documentation TOC (`docs/index.rst`)
5. Updated links to examples in API documentation


See merge request !430
2017-01-17 15:14:00 +08:00
Ivan Grokhotkov
5e6714dd51 Merge branch 'bugfix/docs' into 'master'
Minor documentation fixes

Two trivial fixes:
- fix link formatted as RST in an MD document
- fix DRAM size typo

See merge request !429
2017-01-17 15:13:04 +08:00
Ivan Grokhotkov
df2dc908f0 Merge branch 'bugfix/btdm_flash_operation' into 'master'
component/bt : update bt lib to fix flash operation bug

update bt lib to fix flash write bug when bt interrupt happened.

See merge request !434
2017-01-17 15:12:23 +08:00
Ivan Grokhotkov
ce8ec337eb Merge branch 'bugfix/release_build' into 'master'
Release build related fixes

- Fix (non-)inlining issue with `spi_flash_guards_` functions in release mode
- Fix assert-related warnings generated in release mode by changing assert definition

Fixes https://github.com/espressif/esp-idf/issues/233

See merge request !428
2017-01-17 14:24:14 +08:00
Ivan Grokhotkov
4d8ca3beaa Merge branch 'bugfix/time_syscalls' into 'master'
Fix issues with time syscalls

- fix compilation error when no time source is selected (https://github.com/espressif/esp-idf/issues/238)
- work around a bug that time speeds up when RTC registers are read on the APP CPU (https://github.com/espressif/arduino-esp32/issues/120)


See merge request !427
2017-01-17 14:04:11 +08:00
Tian Hao
f9ac7657e3 component/bt : update bt lib to fix flash operation bug 2017-01-17 13:51:44 +08:00
Deomid Ryabkov
71ab455c87 Allow writes to encrypted partitions
There is a size alignment requirement but it is checked by
spi_flash_write_encrypted. However, this check flat-out bans encrypted
writes.
2017-01-17 12:32:01 +08:00
Ivan Grokhotkov
7776d3e065 time: only define {get,set}_boot_time if FRC1 or RTC is used as time source
Fixes https://github.com/espressif/esp-idf/issues/238
2017-01-17 12:29:09 +08:00
Ivan Grokhotkov
8c25a0fd9d time: workaround for FRC_TIMER_INT_REG write issue
In some cases (when RTC register reads are performed from the APP CPU), a write to FRC_TIMER_INT_REG may be lost on the bus.
Writing to another DPORT register immediately before or after that works around the issue.
We write one dummy value to an address which doesn’t have any register associated with it.

Fixes https://github.com/espressif/arduino-esp32/issues/120
2017-01-17 12:29:09 +08:00
Dong Heng
905180667c components/openssl: refactor openssl debugging and assert function
1. add openssl option at menuconfig
2. remove SSL_ERR to reduce complexity
3. add more functions about debugging and assert

According these, our coders and customers may use and debug the OpenSSL code easily.
2017-01-17 10:15:26 +08:00
Krzysztof Budzynski
ad25997349 Updated links to examples in new folders / categories in api documentation 2017-01-16 23:08:36 +01:00
Krzysztof Budzynski
47a0b88f6e Updated relative paths to included documents 2017-01-16 23:08:35 +01:00
Krzysztof Budzynski
469d390d46 Moved api documentation to new folders / categories 2017-01-16 23:08:35 +01:00
Krzysztof Budzynski
f7a9a2f50b Modified buid_examples.sh to handle new locations of examples 2017-01-16 23:08:35 +01:00
Krzysztof Budzynski
382999b378 Moved examples to new folders / categories. Removed example numbers from example names 2017-01-16 23:08:35 +01:00
Ivan Grokhotkov
1989917f71 docs: fix data RAM size
Fixes https://github.com/espressif/esp-idf/issues/184
2017-01-17 01:18:23 +08:00
Ivan Grokhotkov
1896381501 readme: fix link formatting 2017-01-17 01:17:20 +08:00
Ivan Grokhotkov
c47cc63489 newlib: change definition of assert for release builds
One common pattern of using assert function looks as follows:
    int ret = do_foo();
    assert(ret == 0);   // which reads as: “do_foo should never fail here, by design”
The problem with such code is that if ‘assert’ is removed by the preprocessor in release build,
variable ret is no longer used, and the compiler issues a warning about this.
Changing assert definition in the way done here make the variable used, from language syntax perspective.
Semantically, the variable is still unused at run time (as sizeof can be evaluated at compile time), so the compiler
can optimize things away if possible.
2017-01-17 00:49:38 +08:00
Ivan Grokhotkov
075446318d spi_flash: define spi_flash_guard_{start,stop} with IRAM_ATTR
These functions are marked as inline and are called from functions which are in IRAM.
In release (-Os) builds, the compiler may decide not to inline these functions.
Placing these functions into IRAM explicitly works around this.
2017-01-17 00:42:55 +08:00
Ivan Grokhotkov
48ae7ab500 Merge branch 'bugfix/osx_toolchain_detection' into 'master'
build: Use greedy match for toolchain version detection (fixes macOS)



See merge request !423
2017-01-16 23:09:53 +08:00
Wu Jian Gang
dd8681d8fc Merge branch 'bug/fix_some_wifi_lib_bugs' into 'master'
update wifi lib: fix some wifi lib bugs

1. net80211: fix get ap info error(a4614877)

2. tw9358: sta mac same with softap(ea38d32c)

3. tw9221: scan channel error when connected(183d469c)

See merge request !425
2017-01-16 18:57:02 +08:00
Wu Jian Gang
81777a9ffe Merge branch 'bugfix/event_stack_overflow' into 'master'
esp_event: event stack overflow



See merge request !424
2017-01-16 18:56:46 +08:00
XiaXiaotian
3684e6ddfd update wifi lib: fix some wifi lib bugs
1. net80211: fix get ap info error(a4614877)

2. tw9358: sta mac same with softap(ea38d32c)

3. tw9221: scan channel error when connected(183d469c)
2017-01-16 17:20:05 +08:00
shangke
53b0b03e63 esp_event: event stack overflow 2017-01-16 17:06:12 +08:00
Angus Gratton
cdf8836ceb build: Use greedy match for toolchain version detection (fixes macOS) 2017-01-16 15:09:20 +11:00
Ivan Grokhotkov
455bb4271e Merge branch 'feature/vfs_uart_read' into 'master'
vfs: implement reading from UART

This change adds support for reading from the UART FIFO via the `stdin`.

Useful for simple cases when handling lots of data is not a requirement (e.g. command prompts operated by humans).

`\r\n` -> `\n` conversion is guided by the existing `CONFIG_NEWLIB_STDOUT_ADDCR` configuration option.

See merge request !393
2017-01-16 12:08:22 +08:00
Ivan Grokhotkov
0d00a1ba01 vfs: implement reading from UART 2017-01-16 11:33:32 +08:00
Ivan Grokhotkov
7f751fd0fe Merge branch 'bugfix/i2s_bootloader_random_disable' into 'master'
bootloader_random_disable: Restore all SARADC/I2S registers to defaults

Fix for issue with I2S0 not being usable after bootloader_random_enable()

See merge request !415
2017-01-16 10:40:58 +08:00
Ivan Grokhotkov
6538252552 Merge branch 'bugfix/panic_reset_hangs' into 'master'
Panic handler: Use same reset path as esp_restart(), disabling hardware

Closes #223 https://github.com/espressif/esp-idf/issues/223

See merge request !417
2017-01-16 10:40:47 +08:00
Ivan Grokhotkov
72da7aa53b Merge branch 'bugfix/fixes_from_github' into 'master'
fixes for github issues

This MR includes commits from several Github PRs, as well some fixes for issues reported on Github and on the forum.

- compile PHY-related code only when WiFi is enabled
- fix macOS setup instructions
- fix some of the Sphinx warnings
- update docs index, improve structure of the readme-
- wifi: fix typos, rename ESP_ERR_WIFI_NOT_START to ESP_ERR_WIFI_NOT_STARTED
- sdmmc: fix explanation of flash voltage regulator configuration efuses
- sdmmc: change idx num of example
- fix i2c_get_period name
- fix esp_log_level_set function name in docs

See merge request !420
2017-01-16 10:26:58 +08:00
Angus Gratton
ea19838d3a Build: Handle WiFi & BT enabled/disabled combos gracefully as possible
If using WIFI_INIT_CONFIG_DEFAULT, error message will point out lack
of WiFi. Otherwise linker errors on WiFi symbols should help give a
clue as to what is broken.

Piggy-backs on changes in !420, ref github #230 #237
2017-01-16 13:03:17 +11:00
Ivan Grokhotkov
27711b7c22 Merge branch 'bugfix/compact_panic' into 'master'
Fix panic register dump format

Fix misplaced a printf somewhere causing an enter to be printed after every register in the panic regdump instead of every 4th register.

Fixes https://github.com/espressif/esp-idf/issues/236

See merge request !419
2017-01-16 09:28:40 +08:00
Angus Gratton
ed20560cc4 Merge branch 'bugfix/toolchain_detection_windows' into 'master'
Toolchain detection: Allow for Windows executable name and not-yet-configured toolchain path

Windows executable name based on fix suggested by @krzysztof

See merge request !416
2017-01-16 07:45:47 +08:00
Ivan Grokhotkov
f20135af54 esp32: compile PHY-related code only when WiFi is enabled
Fixes https://github.com/espressif/esp-idf/issues/230, https://github.com/espressif/esp-idf/issues/237
2017-01-16 02:38:32 +08:00
Ivan Grokhotkov
786573fb2d docs: fix macOS setup instructions
Most of the packages mentioned are only needed for building the toolchain using crosstool-NG, not for the normal ESP-IDF environment.
Mention that pyserial needs to be installed (fixes https://github.com/espressif/esp-idf/issues/229).
2017-01-16 02:38:31 +08:00
Ivan Grokhotkov
4c0f90bfae docs: fix some of the Sphinx warnings 2017-01-16 02:38:31 +08:00
Ivan Grokhotkov
4b71d9cb35 docs: update index, improve structure of the readme 2017-01-16 02:38:31 +08:00
Neil Kolban
3efbbab2cf wifi: fix typos, rename ESP_ERR_WIFI_NOT_START to ESP_ERR_WIFI_NOT_STARTED 2017-01-16 02:38:31 +08:00
Ivan Grokhotkov
a2ace698ed sdmmc: fix explanation of flash voltage regulator configuration efuses
- low level on GPIO12 corresponds to 3.3V output, not 1.8V
- add espefuse.py commands to burn efuses
- add XPD_SDIO_REG to the list of efuses which must be set

Reported on the forum: http://esp32.com/viewtopic.php?f=2&t=849&start=10#p4170
2017-01-16 02:38:31 +08:00
rudi ;-)
e5feeb195f sdmmc: change idx num of example 2017-01-16 02:38:31 +08:00
devsaurus
d8fb30c930 i2c: fix i2c_get_period name
rename i2s_get_period to i2c_get_period
2017-01-16 02:37:10 +08:00
Lourens Naudé
a8b75ed974 log: fix esp_log_level_set function name in docs
Fix documentation and comments to reflect the new esp_log_level_set API (and not deprecated esp_log_set_level)
2017-01-16 02:37:10 +08:00
Ivan Grokhotkov
5bd7e655b9 Merge branch 'feature/new-mdns' into 'master'
Feature/new mdns

This is a written from scratch mDNS implementation that supports compression, service and host lookups and service advertisement.

See merge request !365
2017-01-16 00:15:59 +08:00
Jeroen Domburg
08f11e4c53 Fix panic register dump format 2017-01-15 16:49:18 +08:00
Jeroen Domburg
3168ad10e7 Core timer 2 is unusable for FreeRTOS ticks because it triggers a high-level interrupt. This commit deletes the option to select it. 2017-01-15 11:11:58 +08:00
me-no-dev
dd3f18d2d8 Initial mDNS component and example 2017-01-13 12:12:43 +02:00
Ivan Grokhotkov
ca9f62ad77 Merge branch 'feature/esp32_core_dump' into 'master'
esp32 core dump to flash

1.  menuconfig option to select where to store core dump: flash, uart or disable
2. Saving of core dump to flash
3. Partition table definitions files with core dump partition
4. Python scripts to support core dump generation from GDB command line

See merge request !341
2017-01-13 11:51:40 +08:00
Angus Gratton
e53d307814 Panic handler: Use same reset path as esp_restart(), disabling hardware
Closes #223 https://github.com/espressif/esp-idf/issues/223
2017-01-13 14:37:36 +11:00
Angus Gratton
5c9c08eabb Toolchain detection: Fix issue when run in a clean project
If the makefile config entry hasn't been generated yet, don't test the toolchain.

Closes #226 https://github.com/espressif/esp-idf/issues/226
2017-01-13 14:09:01 +11:00
Angus Gratton
233fde166b Toolchain detection: Allow for Windows executable name and not-yet-configured toolchain path
Windows executable name based on fix suggested by @krzysztof
2017-01-13 13:55:26 +11:00
Angus Gratton
7d40f17d1d bootloader_random: Restore all SARADC/I2S registers to reset values
Fix for issue with I2S0 not being usable after bootloader_random_enable()
2017-01-13 12:19:13 +11:00
Alexey Gerenkov
ad66fbe5ad esp32: Fixes issues discussed during code review of MR!341
The following issues mentioned during MR!341 review were fixed:
1) Core dump test application description
2) Usage of CONFIG_ESP32_ENABLE_COREDUMP_TO_FLASH and CONFIG_ESP32_ENABLE_COREDUMP_TO_UART
3) FLASH_GUARD_START macro usage is fixed in flash API
4) Core dump module logging facility
5) cache util functions doc updated
6) interactive delay before print core dump to uart
7) core dump partion support in build system
2017-01-12 19:38:19 +03:00
Jiang Jiang Jian
ee9fb10e29 Merge branch 'bug/ets_timer_crash' into 'master'
tw9503: fix ets timer crash bug

1. tw9503: call ets_timer_disarm before calling ets_timer_setfn

2. change CHECK_AP_CONN to CHECK_STA_CONN

See merge request !414
2017-01-12 21:33:28 +08:00
XiaXiaotian
6eedbfa9be tw9503: fix ets timer crash bug
1. tw9503: call ets_timer_disarm before calling ets_timer_setfn

2. change CHECK_AP_CONN to CHECK_STA_CONN
2017-01-12 20:43:59 +08:00
Wu Jian Gang
9052c6e9ee Merge branch 'bugfix/btdm_adv_stop' into 'master'
component/bt : fix adv stop bug

fix advertising cannot stop bug.

See merge request !412
2017-01-12 17:32:09 +08:00
Wu Jian Gang
ad1790fe3e Merge branch 'feature/btdm_attr_table' into 'master'
component bt:Added the create attribute table method to the new API

GATT Server service table APIs.
Have already modify the style and other things as @jeroen  suggestion in other MR(the MR have been closed)

See merge request !399
2017-01-12 17:31:39 +08:00
Tian Hao
1895460406 component/bt : fix adv stop bug 2017-01-12 16:29:07 +08:00
Tian Hao
fec2f534d5 component/bt : gatt server table fix uuid discovery bug 2017-01-12 16:25:09 +08:00
Ivan Grokhotkov
b018a3ce8e Merge branch 'bugfix/deep_sleep' into 'master'
deep sleep related fixes

A few fixes for deep sleep behavior:

- Fix a regression that deep sleep stub crashed if `ESP32_DEEP_SLEEP_WAKEUP_DELAY` option was enabled — the stub called `ets_update_cpu_frequency`, which was recently redefined to be an IRAM function, rather than a ROM one. Fixed by restoring the ROM definition as `ets_update_cpu_frequency_rom`, and using that in the deep sleep stub.

- By default, don't power down RTC_SLOW_MEM if there is any data in .rtc.data or .rtc.bss sections. This provides better out-of-the box experience, as variables attributed to .rtc.data are actually preserved during deep sleep.

- Store boot time in RTC_STORE registers instead of using a variable with RTC_DATA_ATTR. This allows RTC_SLOW_MEM to be powered down in deep sleep if no variables with RTC_DATA_ATTR are present in the program.

Fixes https://github.com/espressif/esp-idf/issues/182


See merge request !409
2017-01-12 15:53:09 +08:00
Tian Hao
142756615b component/bt : mv demo name
1. mv demo name
2. fix a docs
2017-01-12 14:44:26 +08:00
Ivan Grokhotkov
b24ac487cb newlib: use RTC_STORE registers to keep boot time instead of RTC_SLOW_MEM
This allows RTC_SLOW_MEM to be powered down in deep sleep if no other variables are placed into RTC_SLOW_MEM.
2017-01-12 14:43:34 +08:00
Ivan Grokhotkov
9aa0e29079 deep sleep: keep RTC_SLOW_MEM powered on if data is placed into RTC slow memory 2017-01-12 14:15:30 +08:00
Ivan Grokhotkov
e4811216ff deep sleep: fix regression due to moving ets_update_cpu_frequency into IRAM
Deep sleep stub may call ets_update_cpu_frequency, which has been moved from ROM to IRAM.
Restore the ROM version in the linker script, call it ets_update_cpu_frequency_rom, use it in the deep sleep stub.
2017-01-12 14:15:25 +08:00
Jiang Jiang Jian
d3a0580bef Merge branch 'bugfix/btdm_dualcore_tmp_solution' into 'master'
component/bt : modify bluedroid task to core0

use tmp solution to resolve the dual core bug.

Run bluedroid all task on core0.

See merge request !408
2017-01-12 11:50:18 +08:00
Jiang Jiang Jian
2126f6c8b7 Merge branch 'feature/wpa2_example' into 'master'
wpa2 enterprise: add example for wpa2 enterprise



See merge request !410
2017-01-12 11:49:52 +08:00
Island
9f151d745e component/bt : Optimize Gatt attr table and fix some bugs
1. Optimize GATT attribute table structure
2. fix read/write bugs
3. add docs
2017-01-12 11:49:15 +08:00
Ivan Grokhotkov
aece3d6fc6 Merge branch 'bugfix/mbedtls_tests' into 'master'
fix mbedtls unit tests, fix IDF_VER when building a project outside ESP-IDF tree

- mbedTLS test needs about 5% more time to run (in debug mode) when building with 5.2.0, compared to 4.8.5. Increase the timeout to let the test pass.
- when doing `git describe` in IDF_VER definition, `-C $(IDF_PATH)` is needed to get the version of ESP-IDF, and not the project being built (which may not even be in git)

See merge request !411
2017-01-12 09:47:15 +08:00
Alexey Gerenkov
50b3ce616f esp32: Adds documentation and comments to core dump feature files 2017-01-11 20:51:28 +03:00
Alexey Gerenkov
39ddc7b836 esp32: Fixes several issues in core dump feature
1) PS is fixed up to allow GDB backtrace to work properly
2) MR!341 discussion: in core dump module: esp_panicPutXXX was replaced by ets_printf.
3) MR!341 discussion: core dump flash magic number was changed.
4) MR!341 discussion: SPI flash access API was redesigned to allow flexible critical section management.
5) test app for core dump feature was added
6) fixed base64 file reading issues on Windows platform
7) now raw bin core file is deleted upon core loader failure by epscoredump.py
2017-01-11 20:51:28 +03:00
Alexey Gerenkov
23f836659d esp32: Add core dump printing to UART feature 2017-01-11 20:51:28 +03:00
Alexey Gerenkov
4a3e160888 esp32: Add core dump saving to flash feature
Complimentary changes:
1) Partition table definitions files with core dump partition
2) Special sub-type for core dump partition
3) Special version of spi_flash_xxx
4) espcoredump.py is script to get core dump from flash and print useful info
5) FreeRTOS API was extended to get tasks snapshots
2017-01-11 20:51:28 +03:00
Ivan Grokhotkov
dd73a40556 build system: fix IDF_VER for projects outside of ESP-IDF tree 2017-01-11 22:47:44 +08:00
XiaXiaotian
ff4a5a1406 wpa2 enterprise: add example for wpa2 enterprise 2017-01-11 21:56:17 +08:00
Ivan Grokhotkov
d6842e537c mbedtls: give SHA test slightly more time to run 2017-01-11 21:30:23 +08:00
Ivan Grokhotkov
5fbea86a9e Merge branch 'feature/config_wifi_bt' into 'master'
Clean up WiFi & Bluetooth config options

* Splits "WiFi" configuration out from ESP32 configuration submenu to its own menu.
* Renames "BT" to "Bluetooth", enabling Bluetooth is now in this option not the ESP32 submenu.

* Also disables compiling/linking of BT stack if Bluetooth is disabled, saves some build time.

See merge request !397
2017-01-11 18:38:30 +08:00
Ivan Grokhotkov
8eb9f947e8 Merge branch 'feature/toolchain_update' into 'master'
update toolchain version, rebuild newlib

- This MR updates the toolchain version used in the ESP-IDF
- Compiler version check and warning is added to project.mk
- Newlib is rebuilt to include wcsftime function
- libstdc++ build uses correct newlib headers (so we won't get undefined reference to `__impure_ptr` anymore)

See merge request !387
2017-01-11 18:37:45 +08:00
Wu Jian Gang
61da8595ca Merge branch 'bugfix/fix_remove_wifi_auto_reconnect' into 'master'
esp32: fixs about auto-reconnect and ap ssid configuration

1. Remove auto-reconnect
2. Use strnlen instead strlen to calculate ssid len in wifi lib

See merge request !407
2017-01-11 18:10:44 +08:00
XiaXiaotian
2d8a8bc141 esp32: fixs about auto-reconnect and ap ssid configuration
1. Remove auto-reconnect
2. Use strnlen instead strlen to calculate ssid len in wifi lib
2017-01-11 17:21:10 +08:00
Tian Hao
1eed54c7cd component/bt : modify bluedroid task to core0 2017-01-11 17:19:25 +08:00
Jeroen Domburg
8a2ff5a16d Merge branch 'bugfix/spi_inconsistencies' into 'master'
SPI: Some fixes to docs and flag naming

Kolban noticed the flags for a transaction are not named like the documentation states. The flags as mentioned in the docs are more consistent, so this MR renames them to that. Also some additions to the docs wrt the SPI signals

Ref http://www.esp32.com/viewtopic.php?f=13&t=919&p=3976#p3976 and http://www.esp32.com/viewtopic.php?f=13&t=921&p=3975#p3975

See merge request !398
2017-01-11 17:11:45 +08:00
Yulong
d512d6100c component bt:Added the create attribute table method to the new API 2017-01-11 16:57:19 +08:00
Jeroen Domburg
356e01545c Add test for spi clock, fix corner cases) 2017-01-11 16:13:33 +08:00
Jiang Jiang Jian
0c01ef68f1 Merge branch 'bugfix/id9562_unregistered_callback' into 'master'
component/bt: check for registration status of callback function before using it

Add checking of NULL function pointers when calling bluetooth callbacks, especially before the callback functions are registered

See merge request !406
2017-01-11 15:57:03 +08:00
Jiang Jiang Jian
478591b842 Merge branch 'feature/add_wpa2_set_id_api' into 'master'
add wpa2 set id api and modify null data tx description

1. wpa2: add wpa2 set id api

2. low rate: modify null data tx description

See merge request !402
2017-01-11 15:13:47 +08:00
Ivan Grokhotkov
8d2199e36c docs: update toolchain version 2017-01-11 15:03:14 +08:00
Ivan Grokhotkov
f04e62e6cc cxx: add iostreams test
Checks that libstdc++ can use newlib IO functions
2017-01-11 15:03:14 +08:00
Ivan Grokhotkov
23448e7121 newlib: build with wcsftime function 2017-01-11 15:03:12 +08:00
Jiang Jiang Jian
63091a2358 Merge branch 'feature/ethernet_support_flow_control' into 'master'
ethernet: support flow control

(1) Only fullduplex mode support flow ctrl .

(2) Fix reboot exception which caused by not-reset EMAC hardware (such as DMA) when reset CPU.

See merge request !392
2017-01-11 14:51:43 +08:00
Jiang Jiang Jian
ae48cbd8c4 Merge branch 'bugfix/id9561_bt_status_check' into 'master'
component/bt: bug fix of lack of checking bluetooth stack status inside API functions

Add an API function for checking bluetooth stack status: whether it is uninitialized, initialized or enabled.
The function is intended to be used by users to check the bluetooth stack status, also, it is used inside bluetooth API functions to ensure the stack is in valid state.

See merge request !405
2017-01-11 14:38:43 +08:00
Jeroen Domburg
daa2b7cbc9 n, h and l actually are 6-bit; they go from 1 to 64. 2017-01-11 14:13:37 +08:00
wangmengyang
babeed4170 component/bt: change MACRO to inline function when invoking callbacks 2017-01-11 14:08:16 +08:00
wangmengyang
c592714679 component/bt: fix typos in "if" condition espressions 2017-01-11 13:36:48 +08:00
Jeroen Domburg
a98d07d650 Fix clock divider calculation 2017-01-11 13:01:48 +08:00
XiaXiaotian
b455b0246c add wpa2 set id api and modify null data tx description
1. wpa2: add wpa2 set id api

2. low rate: modify null data tx description
2017-01-11 12:13:11 +08:00
Ivan Grokhotkov
919bb747f8 Merge branch 'bugfix/crosscore_int_iram' into 'master'
Place cross-core interrupt into IRAM, sanity check handler address passed into esp_intr_alloc

Cross-core interrupt handler was not marked with IRAM_ATTR.

The reason why this caused an exception is probably due to some tasks running at highest priority (these are not blocked by spi_flash_disable_caches_interrupts_and_other_cpu mechanism).

This change puts the interrupt handler into IRAM and adds a sanity check into `esp_intr_alloc`.

Reported on Github: https://github.com/espressif/esp-idf/issues/211


See merge request !404
2017-01-11 12:07:43 +08:00
Jeroen Domburg
69a7cfa976 Also update documentation to new conventions 2017-01-11 11:55:23 +08:00
Ivan Grokhotkov
a2e0c2432e esp32: sanity check ISR handler address passed into esp_intr_alloc
Return ESP_ERR_INVALID_ARG if the handler is not in IRAM (or RTC fast memory)
2017-01-11 11:38:17 +08:00
Ivan Grokhotkov
8c26dd8d38 Merge branch 'feature/idf_version' into 'master'
build system: add IDF_VER environment variable and preprocessor define

This adds an `IDF_VER` preprocessor define which is obtained from `git describe`.

Looks like `v1.0-275-g0efaa4f` for non-release version or `v2.0` for a tagged (release) version.

See merge request !403
2017-01-11 11:34:28 +08:00
wangmengyang
0c31bdf643 component/bt: check for registration status of callback function before using it 2017-01-11 11:31:35 +08:00
Jeroen Domburg
ee59fa75f4 Rename SPI Master IO pins to more common terminology, add better explanation to queue_length initialization value 2017-01-11 11:25:56 +08:00
Wu Jian Gang
758281dfed Merge branch 'feature/ping_function' into 'master'
Add ping function

Add ping function, It's need enable LWIP_RAW.

See merge request !285
2017-01-11 11:25:32 +08:00
wangmengyang
59540eeae1 component/bt: bug fix of lack of checking bluetooth stack status inside API functions 2017-01-11 11:04:41 +08:00
Liu Han
6c86586e97 components/lwip: Set the ping target info
Add API for set the ping target info and get the ping result
2017-01-11 10:58:34 +08:00
Ivan Grokhotkov
833102cbf3 esp32: place cross-core interrupt handler into IRAM
esp_intr_alloc is called with ESP_INTR_FLAG_IRAM, so the ISR should be in IRAM.
2017-01-11 00:52:45 +08:00
Ivan Grokhotkov
89e0ecc272 build system: add IDF_VER environment variable and preprocessor define 2017-01-11 00:24:50 +08:00
shangke
2e06c6ba38 dhcp: fix dhcp err when wifi and ethernet coexist 2017-01-10 21:54:53 +08:00
shangke
0e701e1cac ethernet: support flow control 2017-01-10 15:19:18 +08:00
Jeroen Domburg
5eb8eb3855 SPI master: rename transaction flags from SPI_* to SPI_TRANS_*, like the documentation says. Also add some explanation about the SPI signals in the documentation 2017-01-10 14:41:12 +08:00
Jeroen Domburg
a3f6728797 Merge branch 'feature/watchpoint_on_stack_canary' into 'master'
Add option to automatically set a watchpoint at the end of the swapped-in task

This should make stack overflows easier to debug because it triggers a debug exception as soon as the stack is overwritten, not later when a context switch happens. Marked as a FreeRTOS debug feature because it doesn't give a nice error message and uses up a watchpoint.

See merge request !389
2017-01-10 14:01:07 +08:00
Wu Jian Gang
2927688eba Merge branch 'bugfix/tcpip_adapter_set_hostname' into 'master'
Fix tcpip_adapter_set_hostname issue

The default hostname for each interface is "espressif", users can call this API to change each interface's hostname.

See merge request !284
2017-01-10 13:59:22 +08:00
Angus Gratton
26d1a23308 config: Move WiFi & BT toggles to Components menu, same as Ethernet 2017-01-10 16:39:43 +11:00
Jeroen Domburg
881157e1ed Add documentation to panic handler functions, move watchpoint stuff from tasks.c to port.c, account for non-32-bytes-aligned stacks when setting watchpoint, add debug reason explanation to panic handler 2017-01-10 13:05:19 +08:00
Angus Gratton
2e78b397bc config: Simplify WiFi & Bluetooth config options
Removes redundant menu options, splits WiFi configuration out from
generic ESP32 configuration.
2017-01-10 16:04:04 +11:00
Ivan Grokhotkov
e9f8e03309 Merge branch 'feature/JSON_Float' into 'master'
Add float format process

Add float format process

See merge request !390
2017-01-10 13:01:43 +08:00
Liu Han
315b3f979f components/tcpip_adapter: Allow to set different hostname for each interface 2017-01-10 12:42:14 +08:00
Wu Jian Gang
fb70126bc8 Merge branch 'feature/openssl' into 'master'
examples/10_openssl_server: fixup SSL server with method of specific version

1. add method of any version supporting at OpenSSL and add API in header file
2. change OpenSSL server context method to be method of any version

Fixes http://esp32.com/viewtopic.php?f=14&t=696.

See merge request !369
2017-01-10 12:01:40 +08:00
Angus Gratton
c4b3f6bbbc Update esptool.py to v2.0-beta1
Minor bug fixes, no major functionality changes.
2017-01-10 14:04:54 +11:00
Angus Gratton
a54791846b coap: Initialise/update the libcoap submodule 2017-01-10 11:12:02 +11:00
Angus Gratton
b877216fef stdatomic.h: Include stdint.h, required for some limit types 2017-01-10 11:11:27 +11:00
Angus Gratton
433ff1474e WiFi software coexistence: Clarify KConfig description
Ref http://esp32.com/viewtopic.php?f=13&t=844&p=3576
2017-01-10 11:11:27 +11:00
Jiang Jiang Jian
f89de9c5af Merge branch 'feature/low_rate_change_ie' into 'master'
esp32:update wifi libs

1. low_rate: change low rate ie
2. modem sleep

See merge request !391
2017-01-09 21:14:40 +08:00
Wu Jian Gang
8615dbd486 Merge branch 'bugfix/autoip_enable_issue' into 'master'
lwip: fix compile issue when autoip option enabled



See merge request !383
2017-01-09 18:57:03 +08:00
qiyueixa
d5464074dd update wifi libs 2017-01-09 18:44:27 +08:00
Liu Han
5c1c6d2c32 cJSON:Add float format process 2017-01-09 17:51:48 +08:00
Jeroen Domburg
ca57a86f20 Add option to automatically set a watchpoint at the end of the swapped-in task 2017-01-09 16:42:45 +08:00
Jiang Jiang Jian
633cd49f88 Merge branch 'bugfix/detect_ocd_when_panic' into 'master'
Fix OpenOCD detection code

In the current master, detection of an attached OCD is broken. This fixes it.

I also snuck in two unrelated checks in intr_alloc which return from a function that is asserted earlier in the code. This makes the code behave better when they are called erroneously in a production build.

See merge request !377
2017-01-09 13:25:45 +08:00
Angus Gratton
1820069943 Merge branch 'bugfix/sdkconfig_defaults' into 'master'
build system: Fix sdkconfig.defaults file preventing menuconfig changes

'make defconfig' now behaves similarly whether sdkconfig.defaults
is present or not, and 'make menuconfig' doesn't trigger a defconfig.

See merge request !385
2017-01-09 12:51:20 +08:00
Angus Gratton
6421479dab build system: Fix sdkconfig.defaults file preventing menuconfig changes
'make defconfig' now behaves similarly whether sdkconfig.defaults
is present or not, and 'make menuconfig' doesn't trigger a defconfig.
2017-01-09 15:19:23 +11:00
Jeroen Domburg
11a994d5d8 Calling esp_intr_noniram_[en|dis]able twice is an error, so abort instead of doing an assert which disappears in non-debug mode 2017-01-09 12:04:21 +08:00
Jiang Jiang Jian
0106feeeda Merge branch 'feature/btdm_common_api' into 'master'
component/bt : add bt device api

1. add get bd_addr function

later, will add other functions reference with bluetooth device.

See merge request !380
2017-01-09 11:33:57 +08:00
Wu Jian Gang
37fbe9efb3 Merge branch 'bugfix/tw9515_fix_wifi_timer_thread_safe_issue' into 'master'
esp32: fix wifi timer thread-safe issue

Update wifi lib to fix a wifi timer thread-safe issue

See merge request !388
2017-01-09 10:54:00 +08:00
Wu Jian Gang
9dd5f2a952 lwip: fix compile issue when autoip option enabled 2017-01-09 10:22:36 +08:00
Liu Zhi Fu
084c14f1e4 esp32: fix wifi timer thread-safe issue
Update wifi lib to fix a wifi timer thread-safe issue
2017-01-09 10:21:29 +08:00
Ivan Grokhotkov
3fba6f4392 Merge branch 'bugfix/bootloader_ets_cpu_update_freq' into 'master'
bootloader: export ets_update_cpu_frequency

MR !363 added linking librtc into bootloader. At the same time, MR !373 removed ets_update_cpu_frequency from ROM exports ld script, and replaced it with a dual CPU aware version. Combining these two MRs caused linker error in bootloader due to the unresolved `ets_update_cpu_frequency`.

One option to fix this is to move the definition of ets_update_cpu_frequency into bootloader_support component. This does however look a bit odd because this function is not something that is specifically needed for bootloader support.

Another option is to export the ROM version of ets_update_cpu_frequency for the bootloader only. This means that when bootloader changes CPU frequency, it only updates the tick period variable for PRO CPU. This isn't an issue though, because app startup code still calls the dual CPU aware version of ets_update_cpu_frequency early on, before any non-trivial code can run on the APP cpu.

This MR uses the second approach. Looking forward, we may move this definition of ets_update_cpu_frequency into the rtc_clk component, which will be used both by the bootloader and the app, and placing ets_update_cpu_frequency there would be logical.

See merge request !384
2017-01-09 10:14:00 +08:00
Ivan Grokhotkov
5b5a4355e7 Merge branch 'feature/sd_driver_new' into 'master'
SDMMC peripheral driver, SD protocol driver, FATFS library, VFS integration

This MR contains:
- SDMMC host peripheral driver
- SD protocol driver in sdmmc component (can be extended to support MMC/eMMC and SPI based hosts)
- ChaN's FATFS library v0.12b
- VFS integration
- FAT access via VFS is thread-safe (unless same file is read/written/unlinked/renamed from different tasks)
- Support for POSIX directory-related functions in VFS (and in vfs_fatfs.c)
- unit test for the above
- Example
- API documentation

Will be done in other MRs:
- Support for spi_flash IO driver for FatFs
- SPI host driver and support for SPI mode commands in sdmmc component
- MMC/eMMC support in sdmmc component
- Support for slightly higher 53/26.6MHz clocks (currently I'm using 20MHz for DS and 40MHz for HS, instead of 25MHz/50MHz per standard), and arbitrary low clocks (e.g. 4MHz).

See merge request !353
2017-01-09 06:48:25 +08:00
Ivan Grokhotkov
47f4a09704 docs: add sdmmc and fatfs docs 2017-01-09 05:54:12 +08:00
Ivan Grokhotkov
44ce833d76 fatfs: add vfs support 2017-01-09 05:54:04 +08:00
Ivan Grokhotkov
d418776982 fatfs: rename DIR to FF_DIR to avoid conflict with dirent.h 2017-01-09 04:51:24 +08:00
Ivan Grokhotkov
9398d1b1cc fatfs: add pluggable diskio layer, sdmmc implementation 2017-01-09 04:51:24 +08:00
Ivan Grokhotkov
1440c866fc fatfs: import version 0.12b 2017-01-09 04:51:24 +08:00
Ivan Grokhotkov
6fb430f45e vfs: add directory APIs 2017-01-09 04:51:24 +08:00
Ivan Grokhotkov
3f889de5ab vfs: implement vfs_unregister 2017-01-09 04:51:24 +08:00
Ivan Grokhotkov
edd924f273 sdmmc: add peripheral driver and protocol layer 2017-01-09 04:51:24 +08:00
Ivan Grokhotkov
c1b06bf0a2 bootloader: export ets_update_cpu_frequency 2017-01-09 03:08:24 +08:00
Wu Jian Gang
ecf720d3b3 Merge branch 'bugfix/fix_wifi_auth_fail_issue' into 'master'
esp32: fix wifi auth issue

Fix wifi auth failed issue by default phy mode to 11N

See merge request !382
2017-01-07 21:12:45 +08:00
Ivan Grokhotkov
b1c754bbb5 Merge branch 'feature/cplusplus' into 'master'
C++ support

This change adds necessary support for compiling C++ programs:
- linking against libstdc++
- implementation of static initialization guards using FreeRTOS primitives: since we don't have condition variables at our disposal, and we don't want to allocate a synchronization primitive for every guard variable generated by the compiler, we imitate condition variables using a combination of a mutex, counting semaphore, and a counter (based on [Microsoft Research paper](https://www.microsoft.com/en-us/research/wp-content/uploads/2004/12/ImplementingCVs.pdf), albeit because we don't need *arbitrary* code to use these CVs, implementation gets simpler).

Note that libstdc++ also contains an implementation of `__cxa_guard_{acquire,release,abort}` functions. These implementations come from an `#ifndef GXX_THREADS` branch, i.e. are not aware of multthreading. There are three ways of replacing these libstdc++ functions with our implementation:

1. Move our code into gcc. Pros: cleanest solution. Cons: Such changes are unlikely to be merged by any upstream, so we end up maintaining our own forks of {gcc,crosstool-ng}.
2. Use library as it is built by crosstool, use `ar` to delete one object file (`guards.o`), add this library to ESP-IDF. Pros: easy to implement. Cons: libstdc++ is a 15MB binary 😯 
3. Keep using libstdc++ from crosstool, force our implementation to be linked using a `-u` linker flag. Pros: no impact on repo size, easy to implement. Cons: somewhat less clean than 1 (and about as hacky as 2).

For the reasons mentioned, option (3) looks like the best tradeoff.

Ref. TW6702

See merge request !364
2017-01-07 18:50:12 +08:00
Ivan Grokhotkov
5c4f707a33 Merge branch 'test/update_known_issues' into 'master'
CI: update know issue list for idf



See merge request !360
2017-01-07 18:47:17 +08:00
Ivan Grokhotkov
339267ffc9 Merge branch 'feature/bootloader_rng' into 'master'
Enable bootloader entropy source for RNG

Enables an entropy source when bootloader starts up, which both seeds the RNG for use before WiFi/BT stack is enabled and provides an adequate RNG for secure boot & flash encryption key generation.

A prerequisite was enabling 80MHz operation, so the CPU is now set to 80MHz as soon as second stage bootloader starts running.

See merge request !363
2017-01-07 18:46:10 +08:00
Ivan Grokhotkov
0efaa4f4b8 Merge branch 'feature/lwip-rcvbuf-option' into 'master'
add menuconfig option to enable SO_RCVBUF

This option is required by Arduino and enables netconn connection to be queried for amount of data available in the rx buffer.

See merge request !372
2017-01-07 18:45:37 +08:00
Ivan Grokhotkov
4f909b8ecc Merge branch 'bugfix/ets_delay_on_app_cpu' into 'master'
esp32: ets_update_cpu_frequency should set tick scale for both CPUs

ets_update_cpu_frequency ROM function updates g_ticks_per_us, which is has two copies, one for each CPU.
The APP CPU copy of g_ticks_per_us never got updated, resulting in shorter delays produced by ets_delay_us on the APP CPU.

This MR replaces ROM ets_update_cpu_frequency with a copy in IRAM which updates scaling factors on both of the CPUs.

So now we get expected delays (in microseconds):
```
ets_delay_us core=0 expected=50000 actual=50014
ets_delay_us core=1 expected=50000 actual=50015
vTaskDelay core=0 expected=50000 actual=49428
vTaskDelay core=1 expected=50000 actual=50000
```

Reported on the forum: http://esp32.com/viewtopic.php?f=2&t=713#p3722

See merge request !373
2017-01-07 18:45:14 +08:00
Jeroen Domburg
0bfe08578b Add sdkconfig include to cpu_util.h so CONFIG_ESP32_DEBUG_OCDAWARE actually resolves 2017-01-07 18:44:20 +08:00
Ivan Grokhotkov
3708e15ea9 Merge branch 'bugfix/fix_a_crash_issue' into 'master'
esp32: modify ld file to fix a crash issue

This MR is to fix a crash issue in latest idf

See merge request !379
2017-01-07 18:26:20 +08:00
Liu Zhi Fu
0e7f7a2112 esp32: fix wifi auth issue
Fix wifi auth failed issue by default phy mode to 11N
2017-01-07 16:32:03 +08:00
Liu Zhi Fu
a575b9e893 esp32: modify ld file to fix a crash issue 2017-01-07 16:12:07 +08:00
Wu Jian Gang
2250fee01a Merge branch 'bugfix/fix_ci_error' into 'master'
Fix CI error of some examples

Include coap_client/coap_server/ota.

See merge request !381
2017-01-07 15:59:29 +08:00
Wu Jian Gang
1b9f477b15 example: Reindex ota demo 2017-01-07 15:39:22 +08:00
Wu Jian Gang
ed01eb2df1 example: fix CI error of ota demo 2017-01-07 15:39:22 +08:00
Wu Jian Gang
4491dd0e2a example: fix CI error of coap server demo 2017-01-07 15:39:18 +08:00
Wu Jian Gang
6ca2934843 example: fix CI error of coap client demo 2017-01-07 15:39:12 +08:00
Tian Hao
9c630b759f component/bt : add bt device api
1. add get bd_addr function
2017-01-06 21:19:58 +08:00
Jiang Jiang Jian
f5b221b9fb Merge branch 'feature/btdm_blufi_version' into 'master'
component/bt : blufi add version

blufi add version and the android APK add version check, too.

See merge request !378
2017-01-06 18:55:05 +08:00
Tian Hao
e4b9563dac component/bt : blufi add version 2017-01-06 17:40:46 +08:00
Jeroen Domburg
718969f6ed Merge branch 'driver/spi' into 'master'
SPI master driver

This merge requests adds an SPI Master driver. This driver is (of course) multithread capable, has device abstraction, has command queueing, DMA support and all other sorts of nice things you'd expect from a SPI driver.


See merge request !332
2017-01-06 16:28:52 +08:00
Wu Jian Gang
a4c3f876ab Merge branch 'bugfix/ethernet_init' into 'master'
ethernet : fix sometimes ethernet init fail bug



See merge request !376
2017-01-06 16:26:40 +08:00
Wu Jian Gang
e387a16e51 Merge branch 'feature/Add_OTA_Demo' into 'master'
esp32 examples: Add OTA Demo

this demo would show you an OTA workflow and how to make it run.

See merge request !324
2017-01-06 16:15:14 +08:00
Ivan Grokhotkov
079138201d cxx: implement static initialization guards 2017-01-06 16:07:33 +08:00
Ivan Grokhotkov
a69a798878 Merge branch 'bugfix/tw9540_workaround_appdata_overwrite_bootdata' into 'master'
modify bootloader dram start address, swap app bss and data segments

Modify bootloader dram_seg from address 0x3ffc0000 to 0x3fff0000, len from 0x20000 to 0x10000.
Also put app .data before .bss, to reduce the chance .data collides with ROM bootloader stack.

See merge request !375
2017-01-06 15:59:22 +08:00
Wu Jian Gang
c943fabcda Merge branch 'feature/CoAP' into 'master'
Add CoAP feature

Add CoAP protocol, support client and server test demo.

See merge request !303
2017-01-06 15:37:09 +08:00
Ivan Grokhotkov
1cbc2fa046 esp32: ets_update_cpu_frequency should set tick scale for both CPUs 2017-01-06 15:00:17 +08:00
Ivan Grokhotkov
5b2888e113 unity: fix testcase initializer for compiling with C++ 2017-01-06 14:56:02 +08:00
Ivan Grokhotkov
845cd09570 cxx: link against libstdc++, remove abi.cpp 2017-01-06 14:56:02 +08:00
Jeroen Domburg
23455de4c2 Add SPI Master driver, example, test and docs 2017-01-06 14:20:32 +08:00
shangke
6e1150473e ethernet: update docs 2017-01-06 14:16:34 +08:00
shangke
489701eb2d ethernet : fix sometimes ethernet init fail bug 2017-01-06 13:49:42 +08:00
Ivan Grokhotkov
0b264f4f7b bootloader: update ld script comment 2017-01-06 13:47:53 +08:00
Ivan Grokhotkov
61c6ce86d2 esp32: put .data before .bss
This change reduces chances that a large .bss segment will push .data all the way into
0x3ffe1320 — 0x3ffe5320 range where the bootloader stack is, creating a problem when
bootloader will be loading application into memory.
With this change, .data would need to be at least 200k big to cause problems.
2017-01-06 13:46:06 +08:00
Liu Zhi Fu
1b38494df4 bootloader: modify bootloader dram start address to 0x3fff0000
Modify bootloader dram_seg from address 0x3ffc0000 to 0x3fff0000, len from
0x20000 to 0x10000. Please be notified that this is just a workaround for
fixing app data overwrite bootloader data issue!
2017-01-06 13:44:09 +08:00
Wu Jian Gang
e2d05d8592 Merge branch 'feature/wifi_deinit' into 'master'
wifi: add wifi rx buffer number config in menuconfig



See merge request !370
2017-01-06 13:32:25 +08:00
Jiang Jiang Jian
8e4a8e1703 Merge branch 'bugfix/btdm_blufi' into 'master'
component/bt : blufi fix security init bug

fix a memset bug.

See merge request !374
2017-01-06 13:18:08 +08:00
Tian Hao
99d6984800 component/bt : blufi fix security init bug 2017-01-06 12:24:37 +08:00
XiaXiaotian
7853893731 wifi: add wifi rx buffer number config in menuconfig 2017-01-06 10:12:27 +08:00
Ivan Grokhotkov
ded13ac8e6 Merge branch 'feature/btdm_blufi' into 'master'
Feature/btdm blufi

This is new BLUFI for config wifi connection through bluetooth.


See merge request !359
2017-01-05 21:54:45 +08:00
Tian Hao
9017c408ac component/bt : use new lib, optimize BT power 2017-01-05 20:41:15 +08:00
Wu Jian Gang
c9ef32a0f2 Merge branch 'feature/low_rate' into 'master'
add WiFi low rate feature



See merge request !358
2017-01-05 20:34:50 +08:00
Tian Hao
24af07fd13 component/bt : new blufi
1. new blufi protocol
2. new blufi demo
3. support security
4. support sta/ap/sta_ap
5. support wpa-enterprise
2017-01-05 20:22:35 +08:00
Wang Jia Lin
ad1d4500f9 Merge branch 'feature/ledc' into 'master'
driver: ledc update

1. add fading functions.
2. clear up ledc.h
3. update api doc.
4. add ledc example

See merge request !347
2017-01-05 20:05:13 +08:00
wangmengyang
2e7748d625 component/bt: modify bluetooth API
1. VHCI api and doxygen
2. Controller api and doxygen
3. bluedroid init/enable api and doxygen
4. cleanup demo codes
2017-01-05 20:02:06 +08:00
me-no-dev
0feb3633fc add menuconfig option to enable SO_RCVBUF 2017-01-05 13:17:52 +02:00
qiyueixa
7778273314 esp32: update wifi libs
1. add wifi low rate feature
2017-01-05 18:43:09 +08:00
qiyueixa
5677149833 esp32: add wifi low rate feature
1. add low_rate_enable flag to scan results to identify if AP low rate is enabled.
2. add WIFI_PROTOCOL_LR for users to enable low rate feature.
2017-01-05 18:22:07 +08:00
Wangjialin
6b5e734901 driver: ledc - update fading functions, add example and doc
1. add fading functions.
2. clear up ledc.c and ledc.h
3. update api doc.
4. add ledc example
5. edit ledc.rst and add readme for example code.
6. add s_ prefix for static global values.
7. add mutex for fade functions
8. minor changes according to the comments.
2017-01-05 17:57:52 +08:00
Tian Hao
d6fcec73b2 component/bt : add macro for adv_data_flag
1. add macro for adv data flag
2. add docs for doxygen
2017-01-05 17:53:33 +08:00
Tian Hao
daf58e3852 component/bt : fix advertising bug
1. adv data flag
2. default adv data not BR/EDR in demo
2017-01-05 17:53:33 +08:00
Ivan Grokhotkov
f867e0671e Merge branch 'feature/btdm_gatt_api' into 'master'
Feature/btdm gatt api

GATT upstream api changed. 
Actually, feature/btdm_blufi based on this branch.

See merge request !366
2017-01-05 16:43:01 +08:00
Dong Heng
8c7dfef317 examples/10_openssl_server: fixup SSL server with method of specific version
1. add method of any version supporting at OpenSSL and add API in header file
2. change OpenSSL server context method to be method of any version

Fixes http://esp32.com/viewtopic.php?f=14&t=696.
2017-01-05 15:57:25 +08:00
Liu Han
56514d5ab2 examples: Add CoAP client demo
Test CoAP protocol client
2017-01-05 15:49:21 +08:00
Liu Han
899f61f4a2 examples: Add CoAP server demo
Test CoAP protocol server
2017-01-05 15:49:14 +08:00
Tian Hao
ee318d42ae Merge branch 'master' into feature/btdm_gatt_api 2017-01-05 15:25:03 +08:00
Tian Hao
790a3d9ab3 component/bt : update bluetooth api doxygen ref 2017-01-05 14:56:16 +08:00
Wu Jian Gang
c2a356f23c Merge branch 'feature/throughput_optimization_phrase_1' into 'master'
lwip/freertos/esp32: add throughput optimization related code

1. Update wifi lib which contains ampdu and other optimizations
2. Add throughput code debug code
3. Add code to support sending multiple packet per socket call for udp
4. Other misc modification about throughput optimization

See merge request !361
2017-01-05 14:09:23 +08:00
Liu Zhi Fu
d98b99f4f0 lwip: rework according review comments 2017-01-05 12:22:49 +08:00
Liu Zhi Fu
be994740b4 Merge branch 'master' of ssh://gitlab.espressif.cn:27227/idf/esp-idf into feature/throughput_optimization_phrase_1 2017-01-05 11:37:56 +08:00
Liu Zhi Fu
0fb2ab9f5c lwip/freertos/esp32: add throughput optimization related code
1. Update wifi lib which contains ampdu and other optimizations
2. Add throughput code debug code
3. Other misc modification about throughput optimization
2017-01-05 11:37:08 +08:00
Chen Wu
b1cac83f61 examples: Rename 18_ota to 26_ota
example numbers should accord with our internal definition.
2017-01-05 09:57:45 +08:00
Ivan Grokhotkov
6f578796d3 Merge branch 'bugfix/ci_build_example_failures' into 'master'
Fix CI build example not failing on errors



See merge request !357
2017-01-05 00:48:27 +08:00
Yinling
6c41080fd9 CI: update known issues 2017-01-04 19:27:58 +08:00
Angus Gratton
63e9806d85 esp_random: XOR the RNG register value several times before returning it
Probably unnecessary, but avoids returning internal RNG state as-is.
2017-01-04 17:07:12 +11:00
Angus Gratton
3922ce47b2 bootloader: Enable early boot RNG entropy source
This reverts commit ceb8566970.
2017-01-04 17:07:12 +11:00
Angus Gratton
83442526e0 bootloader: Allow custom baud rate on UART 0 2017-01-04 16:24:12 +11:00
Angus Gratton
2e3ca1c2f7 bootloader: Boost bootloader CPU to 80MHz
Partially needed to use RNG, also useful to improve boot performance.
2017-01-04 16:07:19 +11:00
Wang Jia Lin
bf3093feca Merge branch 'driver_merge_tmp/merge_i2c' into 'master'
driver: i2c code

1. add i2c master code
2. add i2c slave code
3. add i2c example code

See merge request !318
2017-01-03 16:44:08 +08:00
Yinling
16de41941e CI: fix bug that test report job failed 2017-01-03 14:07:00 +08:00
Yinling
b9a6d276a2 CI: update known issues 2017-01-03 14:06:50 +08:00
Yinling
c47bc43afd CI: fix bug that restore initial condition fail:
in STA+AP mode, when STA is reconnecting to external AP, its AP
interface is not connectable. do disconnect on STA interface first
2017-01-03 14:06:50 +08:00
Angus Gratton
2407faf6c6 Merge branch 'feature/print_halt_abort' into 'master'
panic handlers: Print the PC address where abort() was called, don't dump registers



See merge request !338
2017-01-03 13:44:34 +08:00
Angus Gratton
19fa6e254d Merge branch 'feature/make_monitor' into 'master'
Add 'make monitor' target as used in arduino-esp32



See merge request !355
2017-01-03 08:43:49 +08:00
Angus Gratton
189543f317 Merge branch 'bugfix/remove_keep_ram_sections' into 'master'
linker script: Remove KEEP from RAM-resident sections

Reduce RAM usage when not all data/bss sections in source files were used.

See merge request !354
2017-01-03 08:38:56 +08:00
Angus Gratton
5e96070c27 linker script: Remove KEEP from RAM-resident sections
Reduce RAM usage when not all data/bss sections in source files were used.
2017-01-03 11:02:12 +11:00
Angus Gratton
4f7314a760 README: Add a note about parallel builds 2017-01-03 10:59:11 +11:00
Angus Gratton
03551ec2da build system: Add 'make monitor' target from arduino-esp32
Originally added to arduino-esp32 by @me-no-dev. It's so useful, we
want it in esp-idf as well! :)
2017-01-03 10:59:10 +11:00
Angus Gratton
7883a5bae5 Merge branch 'feature/esptool_reset_options' into 'master'
esptool: Add new options to reset before/after, detect flash size

Also fixes bugs with reading MAC, chip id.

See merge request !331
2017-01-03 07:48:10 +08:00
Wangjialin
9c7cc86793 1. modify i2c_set_pin function
2. update example comments and other minor changes
3. rename API:  i2c_cmd_link_create/i2c_cmd_link_delete (+4 squashed commits)

Squashed commits:
[2e0ac3e] 1. coding style: add one space after condition key words.
2. modify i2c.h, use gpio_num_t instead of int, improve comments of return values
3. add i2c index in index.rst
4. add readme for i2c example
[4991d92] update i2c.doc
[88b672e] driver: i2c

1. add mux and spin lock to run in a thread-safe way.
2. modify example code
[4eb15fe] driver: i2c code

1. add i2c master code
2. add i2c slave code
3. add i2c example code
4. add DRAM_ATTR for I2C array
2017-01-03 00:57:19 +08:00
liuhan
d0b10ba2dd components/coap: Add libcoap port for ESP32 platform 2016-12-30 15:05:26 +08:00
liuhan
2b41c1b8b2 components/coap: Add libcoap library as submodule 2016-12-30 15:05:26 +08:00
Angus Gratton
6b87419d42 CI build_examples: Don't stop on first failed example, print failure summary 2016-12-30 17:21:16 +11:00
Angus Gratton
eb8324e2c2 examples: Fix build errors that weren't being caught by CI 2016-12-30 16:53:01 +11:00
Angus Gratton
79d6d9f701 CI build_examples: Correctly detect example build failures
"pipefail" regression when fail-on-warnings was added...
2016-12-30 16:52:58 +11:00
Ivan Grokhotkov
370cf5493f Merge branch 'driver/i2s' into 'master'
Add i2s driver

Lasted version of I2S driver 

See merge request !351
2016-12-30 11:39:49 +08:00
Angus Gratton
3783e28f0e bootloader: Check all partitions fit inside configured flash size 2016-12-30 14:19:46 +11:00
Angus Gratton
76e61ded30 bootloader: Call esp_partition_table_basic_verify() as part of standard boot
Was previously only verified during flash encryption.
2016-12-30 14:19:46 +11:00
Angus Gratton
d245f016ea esptool: Add new options to reset before/after, detect flash size 2016-12-30 14:19:46 +11:00
Angus Gratton
2350288a33 examples: Move sdkconfig.defaults support into build system
Is used fairly widely, and a little bit buggy in the form
where it was in each Makefile (didn't always get copied in place).
2016-12-29 17:37:30 +08:00
Chen Wu
d0fccbce15 examples: Add OTA demo 2016-12-29 17:37:17 +08:00
Tuan PM
5462d98e5a Add i2s driver 2016-12-29 17:29:14 +08:00
Wang Jia Lin
8bcd341fca Merge branch 'buffix/uart_frm_err_parity_err_mismatch' into 'master'
bugfix: uart event mismatch

Fix bug of uart frame error and parity error interrupt mismatch in driver code, which will cause the corresponding interrupt can not be cleared correctly, and will finally cause a interrupt watch dog.

See merge request !335
2016-12-29 13:15:48 +08:00
Ivan Grokhotkov
c1370c5561 Merge branch 'feature/osx_brew_reqs' into 'master'
docs: provide list of packages for homebrew

Github PR #20: https://github.com/espressif/esp-idf/pull/20

See merge request !340
2016-12-29 12:36:30 +08:00
Ivan Grokhotkov
48c4a10827 Merge branch 'feature/gpio_intr_function' into 'master'
GPIO driver: add per-pin interrupt handlers

1. add ISR handler apis so that users of different layers can hook their own isr handler on different GPIO.
    Audio project has different software layers, they need different gpio isr handler for layer instead of processing all GPIO interrupts in one handler.
    If this kind of calling a handler from isr is not proper, please kindly point out.
2. add gpio example code.
3. update gpio doc.

See merge request !345
2016-12-29 12:36:04 +08:00
Ivan Grokhotkov
156845f754 Merge branch 'bugfix/doc_template' into 'master'
Clarification on documenting examples

Improve documentation of examples with two basic actions:
- include README.md in each example project
- add a link with synopsis in API documentation

This was not clear reading original API documentation template.


See merge request !349
2016-12-29 12:33:51 +08:00
Wu Jian Gang
0b79a108b8 Merge branch 'feature/add_ip_frag_option' into 'master'
lwip: add ip frag and reassembly option in menuconfig

add ip frag and reassembly option in menuconfig

See merge request !348
2016-12-29 11:26:06 +08:00
Wangjialin
ade7ee2092 gpio_driver: add per-pin interrupt handlers
1. add ISR handler apis so that users of different layers can hook their own isr handler on different GPIO.
    Audio project has different software layers, they need different gpio isr handler for layer instead of processing all GPIO interrupts in one handler.
    If this kind of calling a handler from isr is not proper, please kindly point out.
2. add gpio example code.
3. improve gpio.rst
4. add readme for gpio example

Squashed commits:
[278e50f] update: GPIO
1. coding style, add a space between conditional or loop keyword and an opening paren.
2. modify some return value and doc
3. use printf in example code
Squashed commits:
[efb23bb] minor change of comment
2016-12-29 11:16:32 +08:00
Angus Gratton
1c08cf2f79 Merge branch 'bugfix/uart_intr_config' into 'master'
uart_intr_config should return ESP_OK on success

Github PR #170 https://github.com/espressif/esp-idf/pull/170

See merge request !339
2016-12-29 05:36:26 +08:00
Angus Gratton
3cfe738fcf Merge branch 'bugfix/minor_issues' into 'master'
Bugfixes from Github

Many small fixes for open github issues.

See merge request !334
2016-12-28 13:18:34 +08:00
Angus Gratton
2d7681249a Merge branch 'bugfix/freertos_tick_period' into 'master'
Replace backwards-compatible portTICK_RATE_MS with FreeRTOS v8+ portTICK_PERIOD_MS

Closes github #51 https://github.com/espressif/esp-idf/issues/51

See merge request !336
2016-12-28 08:28:04 +08:00
Angus Gratton
06e03ff52e Replace backwards-compatible portTICK_RATE_MS with FreeRTOS v8+ portTICK_PERIOD_MS
Closes github #51 https://github.com/espressif/esp-idf/issues/51
2016-12-28 10:23:13 +11:00
Angus Gratton
e6b09dc258 FreeRTOS: Default to canary byte stack overflow checking
Was mistakenly "none" due to name change not being propagated.

Closes github issue #181: https://github.com/espressif/esp-idf/issues/181
2016-12-28 10:17:56 +11:00
Angus Gratton
665dcc5712 linux docs: Add note about precompiled gdb on Arch
Closes github #150: https://github.com/espressif/esp-idf/issues/150
2016-12-28 10:17:56 +11:00
Angus Gratton
9496fda662 RMT driver: Rename rmt_set_evt_intr_en to rmt_set_tx_thr_intr_en
Closes github #115: https://github.com/espressif/esp-idf/issues/115
2016-12-28 10:17:56 +11:00
Angus Gratton
948a2ba23a uart driver: Remove invalid UART_BITRATE_115200 enum from example
Closes github #92 https://github.com/espressif/esp-idf/issues/92
2016-12-28 10:17:56 +11:00
Angus Gratton
6395081503 uart driver: Set type of uart_driver_install queue param
Closes github #91 https://github.com/espressif/esp-idf/issues/91
2016-12-28 10:17:56 +11:00
Angus Gratton
45571b3c38 LEDC driver: Use ledc_channel_t for all channel arguments
Closes github #54: https://github.com/espressif/esp-idf/issues/54
2016-12-28 10:17:56 +11:00
Angus Gratton
41eca2c67b RMT: Don't require carrier_freq_hz to be non-zero if carrier_en unset
Closes github #123 https://github.com/espressif/esp-idf/issues/123
2016-12-28 10:17:56 +11:00
Angus Gratton
ff1fa8a323 gpio driver: Fix gpio_set_level validation of gpio_num argument
Closes #125 https://github.com/espressif/esp-idf/issues/125
2016-12-28 10:17:56 +11:00
Angus Gratton
1e44f72e98 esp_wifi_init: Update comment about init event_q
Closes github #28 https://github.com/espressif/esp-idf/issues/28
2016-12-28 10:17:56 +11:00
Angus Gratton
c1a6d55116 WiFi interface: SSID and password fields should be uint8_t in all cases
Closes github #40 https://github.com/espressif/esp-idf/issues/40
2016-12-28 10:17:56 +11:00
Angus Gratton
da977149f6 panic handlers: Print the PC address where abort() was called, don't dump registers 2016-12-28 10:09:40 +11:00
Jiang Jiang Jian
6d0fd80af4 Merge branch 'bugfix/tw9313_dual_core_issue' into 'master'
freertos: fix dual core issue

This commit try to fix dual issue tw9313 raised by QA
1. Put per-core data into critical session or interrupt disabled/enabled session
2. Idle task may have problem when it terminate the task in both core

See merge request !333
2016-12-27 22:06:55 +08:00
Krzysztof
6a39bc6996 Clarification on documenting examples 2016-12-27 12:32:40 +01:00
Ivan Grokhotkov
835fa31d56 Merge branch 'feature/save_and_commit_CI_test_result' into 'master'
Feature/save and commit ci test result



See merge request !255
2016-12-27 12:23:38 +08:00
Liu Zhi Fu
d049fd3929 freertos: rework code based on review 2016-12-27 12:11:07 +08:00
Liu Zhi Fu
d2e58193d2 add more protection for per-core data 2016-12-26 19:04:41 +08:00
Wu Jian Gang
3ad6dbbaa1 Merge branch 'feature/ethernet_driver' into 'master'
feature/ethernet_driver: update ethernet driver



See merge request !319
2016-12-26 15:50:21 +08:00
XiaXiaotian
15651b5923 lwip: add ip frag and reassembly option in menuconfig 2016-12-26 15:47:20 +08:00
shangke
5ddf6daa98 feature/ethernet_driver: update ethernet driver
1. The transmitting mode of the packets from LWIP to MAC is changed from synchronous to asynchronous.
2. The receive buf mode : support pointer mode and copy mode.
3. Add get phy status func used to config mac register.
2016-12-26 14:50:49 +08:00
Ivan Grokhotkov
05fcdcfedb Merge branch 'bugfix/make_erase_flash' into 'master'
build system: Fix bug where erase_flash was always invoked for flash

Order-only prerequisites do not work for phony targets!

See merge request !337
2016-12-25 09:13:58 +08:00
Ivan Grokhotkov
28aa7ba658 Merge branch 'bugfix/ci_use_gitlab_for_bt_lib_on_non_master_branch' into 'master'
CI: use gitlab repo for bt lib on non master barnch

same as wifi lib, some bt lib might not be pushed to github yet for developping branches

See merge request !342
2016-12-24 02:32:11 +08:00
Yinling
a1915f7f87 use gitlab repo for bt lib on non master barnch
same as wifi lib, some bt lib might not be pushed to github yet for
developping branches

replace gitlab server address with variable
2016-12-23 20:48:34 +08:00
Malte Janduda
e8b194d5e5 provide list of packages for homebrew 2016-12-22 17:09:05 +11:00
Wangjialin
794f7dd294 bugfix: uart event mismatch
1. Fix bug of uart frame error and parity error interrupt mismatch in driver code, which will cause the corresponding interrupt can not be cleared correctly, and will finally cause a interrupt watch dog.
2. Add gpio pull-up for rx pin and cts pin.
2016-12-22 14:08:48 +08:00
Angus Gratton
abb7668af7 build system: Fix bug where erase_flash was always invoked for flash
Order-only prerequisites do not work for phony targets!
2016-12-22 16:37:28 +11:00
Liu Zhi Fu
99f4c697ee freertos: enable dual core by default 2016-12-22 13:37:07 +08:00
Angus Gratton
4cfbe80b0f Merge branch 'bugfix/bootloader_stack' into 'master'
bootloader: Check if DRAM segments are going to collide with stack



See merge request !330
2016-12-22 12:15:18 +08:00
Angus Gratton
578b627d9b Merge branch 'bugfix/build_system_tilde' into 'master'
Build system: Allow IDF_PATH to contain ~ or C:/

See github issues
* https://github.com/espressif/esp-idf/issues/118
* https://github.com/espressif/esp-idf/issues/166

(This is easier to work around in the build system than to document.)

See merge request !315
2016-12-22 12:14:16 +08:00
Angus Gratton
ab5915ff8b spi_flash: Standardise argument types & names used for flash offsets
Closes github #88: https://github.com/espressif/esp-idf/issues/88
2016-12-22 15:07:02 +11:00
Angus Gratton
2f9772860a Examples: Add READMEs for examples which did not have them
Closes github #128 https://github.com/espressif/esp-idf/issues/128
2016-12-22 15:07:02 +11:00
Liu Zhi Fu
3a2fbda35c freertos: minor change according to review comments 2016-12-22 10:51:40 +08:00
Yinling
57817f7c53 generate test result and commit to CI-test-result:
1. config git user name before commit
2. continue committing test result for failed jobs
3. update test result repository path
4. change escape key word in branch name, use '___' to escape key word '/' in report file name
2016-12-22 10:36:13 +08:00
Liu Zhi Fu
2cffaf9cc8 freertos: fix dual core issue
This commit fixes:
1. xTaskGetCurrentTaskHandle may return wrong TCB when current task switch to a different core
2. Idle task may have problem when it terminate the task in both core
2016-12-22 10:17:39 +08:00
Ivan Grokhotkov
a760eb3980 Merge branch 'feature/erase_flash' into 'master'
Build system: Add `make erase_flash` target



See merge request !328
2016-12-22 09:53:25 +08:00
Angus Gratton
de8ecdd3c1 build system: Fix Windows case when IDF_PATH contains colons (ie C:/)
Closes github #166 https://github.com/espressif/esp-idf/issues/166
2016-12-22 10:36:25 +11:00
Wang Jia Lin
168190d7e4 Merge branch 'feature/uart' into 'master'
driver: uart

1. add uart rx buffer data length API
2. add uart pattern detect event
3. add uart example code
4. modify uart_isr_register API
5. modify uart.rst
6. fix parity err event and frame err event.

See merge request !321
2016-12-21 14:10:37 +08:00
Wangjialin
9dbdab5c9a driver: uart
1. add uart rx buffer data length API
2. add uart pattern detect event
3. add uart example code
4. modify uart_isr_register
5. modify uart.rst
6. fix parity err event and frame err event.
2016-12-21 11:55:53 +08:00
Angus Gratton
4f3ff1cf7e Merge branch 'bugfix/ringbuffer_receive_upto_api' into 'master'
bugfix: ring buffer

Fix API xRingbufferReceiveUpToFromISR

See merge request !327
2016-12-21 10:01:13 +08:00
Angus Gratton
bae0149920 Merge branch 'bugfix/minor_fixes' into 'master'
Minor fixes from various sources

- Fix memory debugging code. Noticed by Tuan.
- intr_enable/disable should be in IRAM. Noticed by rojer
- Still old timer code in examples in doxygen comments. Noticed on the forum by jumjum123
- Timer example was broken. Noticed on the forum by jumjum123

See merge request !325
2016-12-21 06:54:33 +08:00
Angus Gratton
51cd654658 Merge branch 'bugfix/ota_select_info_point_fix' into 'master'
bootloader: fix error pointer to ota select info

bbs issue: http://www.esp32.com/viewtopic.php?f=14&t=615,
ota select info should be in different sector

See merge request !316
2016-12-21 06:54:21 +08:00
Angus Gratton
198889ad26 bootloader: Check if DRAM segments are going to collide with stack 2016-12-20 16:14:07 +11:00
Wu Jian Gang
cca883490e Merge branch 'bugfix/tcpip_adapter_set_ip_info' into 'master'
Fix set static IP address issue

Set static IP address, clear current DNS servers default.

See merge request !310
2016-12-20 11:18:17 +08:00
Ivan Grokhotkov
ba08d1ae25 Merge branch 'feature/phy_init_data_update' into 'master'
phy init data update

This changes 54M target power from 16 dBm to 15 dBm, and bumps init_data version from 0 to 1.

See merge request !322
2016-12-20 10:26:16 +08:00
Ivan Grokhotkov
41ce99db32 Merge branch 'feature/ulp' into 'master'
ULP: add new instructions, fix bugs, add tests

This adds peripheral register read and write instructions, an instruction to wake the SoC from deep sleep, and some tests.

Also fixes two bugs: ANDI instruction definition, and running the ULP when in deep sleep mode.

See merge request !317
2016-12-20 10:25:55 +08:00
Jeroen Domburg
4c86aba160 Merge branch 'bugfix/exception_handling' into 'master'
Fix exception handler to jump to correct vector instead of crashing to the double exception vector.

One-character fix... basically, this caused the exception handler to crash into the double-exception handler instead of nicy panic'ing.

See merge request !323
2016-12-20 09:22:41 +08:00
Angus Gratton
7ba6be782e Merge branch 'feature/secure_boot_remote_sign' into 'master'
Secure boot: Option for app & partition table signing to happen outside build system

Allows for a remote signing server, private signing key does not need to be on the build system.

See merge request !320
2016-12-20 07:04:31 +08:00
Angus Gratton
59e0f63d37 Build system: Add make erase_flash target 2016-12-20 10:00:04 +11:00
Angus Gratton
d031530196 Merge branch 'feature/dhcpserver_null_gw' into 'master'
Allow gw to be null

Github Pull Request 163: https://github.com/espressif/esp-idf/pull/163

Allow interfaces to be configured without a default gateway, for
local-only communication.

In case of the AP interface, if gw is not set, do not offer it.

See merge request !312
2016-12-20 06:14:44 +08:00
Wangjialin
6a8a9a0272 bugfix: ring buffer, fix api xRingbufferReceiveUpToFromISR 2016-12-20 01:13:03 +08:00
Deomid Ryabkov
1597f7a035 Add IRAM_ATTR to esp_intr_{enable,disable}
So it's safe to invoke from ISR

Signed-off-by: Jeroen Domburg <jeroen@espressif.com>
2016-12-19 18:49:28 +08:00
Jeroen Domburg
99849ca2cc Fix timer example; it had too little stack resulting in a stack overflow 2016-12-19 18:48:08 +08:00
Jeroen Domburg
93e72649dc Fix memory debugging code 2016-12-19 18:48:08 +08:00
Jeroen Domburg
4854dcf0eb Get rid of old interrupt example code 2016-12-19 18:48:08 +08:00
Tian Hao
65fe6ab320 component/bt : modify demo for new api
1. modify GATT Client demo
2. modify GATT Server demo
3. fix a register notify bug
2016-12-19 17:15:41 +08:00
Tian Hao
c01dedcb06 component/bt : change api for V2.0
1. change all gatt cb function to 3 args and function type. add gattc_if/gatts_if as second argument
2. delete gatt_if of "gatt cb param"
3. separate conn_id and gatt_if from conn_id
4. change the demo code as the gatt changed
2016-12-19 17:15:41 +08:00
Jeroen Domburg
bb584c4333 Fix exception handler to jump to correct vector instead of crashing to the double exception vector. 2016-12-19 16:01:21 +08:00
Ivan Grokhotkov
4853df9c83 phy init data update
This changes 54M target power from 16 dBm to 15 dBm, and bumps init_data version from 0 to 1.
2016-12-19 14:23:39 +08:00
Wang Jia Lin
1ed584f896 Merge branch 'driver_merge_tmp/merge_sigmadelta' into 'master'
driver: sigma-delta

1. add sigma-delta code and example.
2. add gpio output signal in io matrix.

See merge request !241
2016-12-19 12:29:32 +08:00
Angus Gratton
d6fafd00db Secure boot: Option for app & partition table signing to happen outside build system 2016-12-19 13:12:05 +11:00
Wangjialin
b00b75db7e driver: sigma-delta
1. add sigma-delta code and example.
2. add gpio output signal in io matrix.

Squashed commits:
[a25e7d4] minor changes for doc
[6a03a1e] minor changes on comments and doc.
[97dd9e4] Add doc.
update index.rst
change example index
2016-12-18 17:20:17 +08:00
Deomid Ryabkov
2c165aba36 uart_intr_config should return ESP_OK on success 2016-12-16 22:27:45 +00:00
Ivan Grokhotkov
b62f8b42d4 ulp: document peripherals accessible using RD_REG and WR_REG 2016-12-16 20:32:34 +08:00
Ivan Grokhotkov
7a527896dc ulp: use timer to start ULP, fix I_ANDI bug, add tests
Starting the ULP using SENS_SAR_START_FORCE_REG doesn’t disable clock gating of RTC fast clock.
When SoC goes into deep sleep mode, RTC fast clock gets gated, so ULP can no longer run.
Instead, it has to be started using the timer (RTC_CNTL_ULP_CP_SLP_TIMER_EN bit).
When ULP is enabled by the timer, clock also gets enabled.
2016-12-16 20:25:38 +08:00
Ivan Grokhotkov
7b02eae9e6 ulp: add RD_REG, WR_REG, END instruction 2016-12-16 20:01:15 +08:00
Tian Zhong Xing
461aab3e75 bootloader: fix error pointer to ota select info 2016-12-16 18:47:25 +08:00
Ivan Grokhotkov
576052e5c2 Merge branch 'feature/extend_deep_sleep_apis' into 'master'
extend deep sleep APIs

This adds the following APIs to enable various wakeup sources:
- esp_deep_sleep_enable_timer_wakeup
- esp_deep_sleep_enable_ulp_wakeup
- esp_deep_sleep_enable_ext0_wakeup
- esp_deep_sleep_enable_ext1_wakeup

And an API to start deep sleep:
- esp_deep_sleep_start

Add an API to control which peripherals are kept enabled in deep sleep mode:
- esp_err_t esp_deep_sleep_pd_config

Also rolled an update of rtc_io header comments into this MR, as I had to add `slpie`, `slpsel`, and `hold` fields into `rtc_gpio_desc_t` struct.

Deep sleep unit tests don’t do anything useful in CI context because we don’t have a way to check reset behavior (time till reset, reason for reset) in CI environment, yet. Also for external wakeup we would need to control some ESP32 pins from the test environment.

Currently there is one known issue:
- RTC Fast memory may be isolated from the bus after deep sleep reset. We work around this by setting FORCE_NONISO flag in RTC power control register. This is non-optimal and we will keep looking for the reason why isolation gets enabled.

See merge request !297
2016-12-16 16:17:37 +08:00
Ivan Grokhotkov
126d164283 docs: fix some warnings 2016-12-16 14:31:29 +08:00
Ivan Grokhotkov
628bad1dbf deep sleep: add documentation 2016-12-16 14:31:29 +08:00
Ivan Grokhotkov
370f4b8556 deep sleep: set pin configuration right before entering deep sleep
This change allows setting pin configuration for EXT1 wakeup depending on the state of RTC_PERIPH power domain:
- if peripherals are enabled (due to another wakeup mode, or due to esp_deep_sleep_pd_config call), we can keep internal pullups/pulldowns enabled
- if peripherals are disabled, pullups and pulldowns need to be disabled as well

Also add comments about the purpose of registers being configured.
2016-12-16 14:30:27 +08:00
Ivan Grokhotkov
609d852834 deep sleep: power down RTC peripherals in EXT1 sleep 2016-12-16 14:30:27 +08:00
Ivan Grokhotkov
616d1d32f1 ulp: add missing component.mk for tests 2016-12-16 14:30:27 +08:00
Ivan Grokhotkov
83184bd52b deep sleep: RTC fast memory may be disconnected after deep sleep wakeup
This adds a workaround for a bug that following deep sleep wakeup, ISO (bus isolation) signal may be set for RTC fast memory.
We set FORCE_NOISO bit in RTC_CNTL_PWC_REG until we find out what is causing ISO signal to be set.
2016-12-16 14:30:27 +08:00
Ivan Grokhotkov
35115885c5 deep sleep: add API to control power down 2016-12-16 14:30:27 +08:00
Ivan Grokhotkov
88ddf5aefa deep sleep: rename header file 2016-12-16 14:30:27 +08:00
Ivan Grokhotkov
eac80b0651 deep sleep: add option to delay CPU startup
When ESP32 wakes up from deep sleep, flash is accessed an approximately 900us after power on.
Some flash chips need more time to become ready. This change adds a menuconfig option to add
some delay to the default deep sleep wake stub.

Fixes https://github.com/espressif/esp-idf/issues/117
2016-12-16 14:30:27 +08:00
Ivan Grokhotkov
3b854fe46a deep sleep: implement wake up using ULP, EXT0, EXT1 sources
This adds the following APIs to enable various wakeup sources:
- esp_deep_sleep_enable_timer_wakeup
- esp_deep_sleep_enable_ulp_wakeup
- esp_deep_sleep_enable_ext0_wakeup
- esp_deep_sleep_enable_ext1_wakeup

And an API to start deep sleep:
- esp_deep_sleep_start
2016-12-16 14:30:27 +08:00
Ivan Grokhotkov
71daf49e39 driver/rtc_io: improve header comments
Fix descriptions of return values, fix typos, use upper case for abbreviations.
2016-12-16 14:30:27 +08:00
Angus Gratton
d246836cfc Merge branch 'feature/spiflash_unaligned_readwrite' into 'master'
Remove alignment reqs from spi_flash_{read,write}

Github pull request https://github.com/espressif/esp-idf/pull/155

See merge request !311
2016-12-16 13:28:12 +08:00
Angus Gratton
9d8e110202 Build system: Deal with the case where IDF_PATH contains ~
See github issue https://github.com/espressif/esp-idf/issues/118

(This is easier to work around in the build system than to document.)
2016-12-16 11:30:37 +11:00
Wu Jian Gang
87d0eb0fdb Merge branch 'feature/tw8657_refractor_to_sniffer' into 'master'
refactor to sniffer

1. WiFi send the whole packet to smartconfig
2. Fixed some modem sleep bugs


See merge request !306
2016-12-15 19:03:44 +08:00
Liu Zhi Fu
3984d96acb esp32: refactor to sniffer
1. TW8657, WIFI send the whole packet to smartconfig;
2. modify API annotation of smartconfig and sniffer;
3. export smartconfig APIs to programming guide;
2016-12-15 18:20:00 +08:00
Wu Jian Gang
847092e483 Merge branch 'bugfix/tw9240_fix_lwip_dual_core_issue' into 'master'
lwip: fix lwip dual core issue

Call xSemaphoreGiveFromISR instead xSemaphoreGive when the calling context is in critical section.

See merge request !314
2016-12-15 17:33:28 +08:00
Xia Xiaotian
eec743d04c esp32: update wifi lib, fix some modem sleep bugs
1. tw7426: fix the bug that config ap crashes(7bb90c19)
2. tw9149: fix memory leak in modem sleep(1f450cb8)
3. tw9157: fix dtim change log in modem sleep(1f450cb8)
4. update smartconfig.a
2016-12-15 17:18:40 +08:00
Ivan Grokhotkov
9d5f4e877e Merge branch 'bugfix/heap_alloc_no_iram' into 'master'
Restore ability to alloc IRAM, and more.

- Fix mem regions so allocating IRAM works again
- Optimize allocator slightly, uses 4 less bytes per malloc now
- Allow querying free heap memory space per memory type


See merge request !301
2016-12-15 16:28:29 +08:00
Jiang Jiang Jian
70d39aa105 Merge branch 'bugfix/btdm_bluedroid' into 'master'
Bugfix/btdm bluedroid

Cleanup all the warnings。
Fix GATT CLIENT cannot receive notfiy/indicate from GATT SERVER bug.

Originally, bluetooth have its own master branch(feature/btdm_bluedroid), all the bluetooth sub branch will merge to feature/btdm_bluedroid firstly. If feature/btdm_bluedroid is ready, it will request merge to master. But as Ivan/JG/Jack's requires, all the bluetooth bugfix or feature will request merge to master ASAP.
This MR contains "cleanup warning " and "some bug fix", after, every merge request only contain one thing.

See merge request !286
2016-12-15 16:10:21 +08:00
Jeroen Domburg
dc9646bc53 Merge branch 'bugfix/uart_examples_intr' into 'master'
Update uart examples in uart.h to new interrupt allocation scheme

Some of the examples in the UART header haven't been adjusted to the new interrupt scheme; this fixes that. Also runs dos2unix on the drivers tree; a fair few drivers used DOS-style line ends.

See merge request !313
2016-12-15 15:15:32 +08:00
Liu Zhi Fu
55726385a4 add more comments and call portYIELD when necessary 2016-12-15 15:06:00 +08:00
Jeroen Domburg
712f53176d Make internal function static 2016-12-15 15:03:22 +08:00
Jeroen Domburg
6f0a494cae Add testcase, fix executable memory allocated in shared dram/iram region 2016-12-15 15:03:22 +08:00
Jeroen Domburg
1e117dc3d3 Fix small things noticed in MR, add documentation 2016-12-15 15:03:22 +08:00
Jeroen Domburg
293ad4cd36 Add xPortGetFreeHeapSizeCaps and xPortGetMinimumEverFreeHeapSizeCaps plus everything it entails. Allows querying the available memory for various capabilities. Also: xPortGetFreeHeapSize and xPortGetMinimumEverFreeHeapSize now return the expected value. Bonus: the linked list used in the allocator is now 4 bytes smaller, which should save some memory. 2016-12-15 15:03:22 +08:00
Jeroen Domburg
3f3cf397f7 Tabs -> spaces 2016-12-15 15:03:22 +08:00
Jeroen Domburg
1cb2081d99 Do not disable entire IRAM pool; instead disable only the bit that is used. This gives us 50K of iram at the moment. 2016-12-15 15:03:22 +08:00
Jeroen Domburg
25e7f3a303 Add name to tag type 2016-12-15 15:03:22 +08:00
Tian Hao
5a2033c4e3 Merge branch 'master' into bugfix/btdm_bluedroid 2016-12-15 14:40:29 +08:00
Liu Zhi Fu
5e2ae7ac19 lwip: fix lwip dual core issue
Call xSemaphoreGiveFromISR instead xSemaphoreGive when the calling context is in critical section.
2016-12-15 14:37:21 +08:00
Tian Hao
d242251295 component/bt : fix advertising bug
1. low duty can not be set bug
2. adv type can not be effective bug
2016-12-15 14:33:09 +08:00
Tian Hao
f3450abf3d component/bt : add some macro , so redo the doxygen 2016-12-15 14:02:48 +08:00
Tian Hao
d045187c0f component/bt : change the resolving list cleanup position
1. enable will malloc, but disable don't free resolving list, so fix it
2. In disable procedure, it will alloc alarm to hash_map, and all the alarm  hash_map will be free in deinit. So this need not be fixed currently.
2016-12-15 13:35:30 +08:00
Jeroen Domburg
1037a50abe Convert DOS line ends to Unix line ends in drivers 2016-12-15 09:45:40 +08:00
Jeroen Domburg
3ed16758c0 Update examples in uart.h 2016-12-15 09:44:21 +08:00
Deomid Ryabkov
d288a3d053 Remove alignment reqs from spi_flash_{read,write} 2016-12-15 10:07:31 +11:00
Angus Gratton
f1390fa7c9 Merge branch 'bugfix/conf_across_mountpoints' into 'master'
Create temp config in the same dir as target

Fixes case where SDK and app are on different mounts

(In our usage of kconfig, dirname is the empty string & basename is the full path to sdkconfig)

Github pull request https://github.com/espressif/esp-idf/pull/151


See merge request !309
2016-12-15 07:07:27 +08:00
Angus Gratton
953b12b4c0 Merge branch 'bugfix/build_deps_assembler' into 'master'
build system: Generate dependency make rules for assembler source

Was previously only C, C++.

See merge request !304
2016-12-15 06:48:15 +08:00
Angus Gratton
4f637034e8 build system tests: Add test case for sdkconfig-triggered recompilation 2016-12-15 08:45:32 +11:00
Angus Gratton
49be64a716 build system: Generate dependency make rules for assembler source
Was previously only C, C++.
2016-12-15 08:44:48 +11:00
Angus Gratton
487548e7dd Merge branch 'bugfix/build_system_linker_script_deps' into 'master'
build system: Linker scripts or binary libraries should trigger a re-link

Add binary libraries and linker scripts to the list of dependencies for the ELF file.

Fixes TW7816.


See merge request !307
2016-12-15 05:38:54 +08:00
Deomid Ryabkov
cbff82cc44 Allow gw to be null
Allow interfaces to be configured without a default gateway, for
local-only communication.

In case of the AP interface, if gw is not set, do not offer it.
2016-12-14 19:34:04 +00:00
Tian Hao
aba262b18b component/bt : fix bluetooth disable memory leak 2016-12-15 01:36:27 +08:00
Tian Hao
69ee1de9fa component/bt : fix enable bug
1. enable will cause exception with list->head memory modify
2. gatt complete, timeout with HCI cmd timeout will cause exception
2016-12-14 22:10:21 +08:00
Tian Hao
5e87cdec7e component/bt : increase the task stack size
1. increase HCI task stack size
2. increase BTC task stack size for default
2016-12-14 22:10:21 +08:00
Tian Hao
fd11beebcd component/bt : fix the init/deinit memory leak
1. modify the memory debug
2. fix init/deinit memory leak
2016-12-14 22:10:21 +08:00
Tian Hao
7ae7a56457 component/bt : fix the bug of deinit/disable
1. fix the exception of deinit/disable
2. debug mem leak of deinit, fix some memleak, but still something wrong.
3. debug men leak of disable.
4. add bluedroid memory debug
2016-12-14 22:10:21 +08:00
Ivan Grokhotkov
2e9c06b584 Merge branch 'bugfix/rom_int_functions' into 'master'
Fix broken WiFi due to intr allocation code.

TL;DR: The dynamic interrupt allocation code fixed something up to the point it broke. This code breaks off the broken code, fixing everything.

The dynamic allocated interrupt patch also fixed a bug in FreeRTOSs interrupt handling for two cores, which caused the two cores to (most of the time) have exactly the same interrupts enabled. This made WiFi fail: it would wait on a semaphore but never figure out the other core had set the semaphore, so it would keep waiting in the idle task for ever. This was caused by both the cross-core interrupt as well as the tick interrupt being disabled.

The culplrit for this appeared to be the WiFi driver, which enabled a FRC2 interrupt. The code enabling this, through a respectable amount of defines, called a rom function which called a HAL function... which was configured in such a way that it worked okay if both CPUs happened to have the same interrupts set, but broke as soon as that was not the case, possibly setting only the interrupt that was enabled and clearing all others.

The fix for this is to not use the ROM functions, but provide our own instead. Fortunately, this can be done without changes in the WiFi libs.

This MR also addresses a potentially dangerous ESP_LOG as well as some, according to the ISA document, needed rsyncs in the interrupt enable/disable code. It also marks int 9 and 10 as reserved, the WiFi code seems to use this.

See merge request !308
2016-12-13 14:16:57 +08:00
Jeroen Domburg
d5c57d1d10 Put ets_isr_* functions into IRAM. Original fns were in ROM so people may expect them to work when flash cache is out. 2016-12-13 13:24:01 +08:00
Ivan Grokhotkov
8f3c74353a newlib: fix unit test name in test config 2016-12-13 13:24:01 +08:00
Ivan Grokhotkov
071615b059 freertos: fix TLS delete callback test
“Full” printf uses more stack space than “nano” printf, and more space than available in the idle task.
This caused stack overflow in TLS delete test. Replacing printf with ets_printf.
2016-12-13 13:24:01 +08:00
Jeroen Domburg
78161a1fe3 Replace non-multicore-aware rom funcs with multicore-aware funcs, ESP_LOG->ESP_EARLY_LOG fix, reserve ints used in wireless libs. Fixes WiFi crashing 2016-12-13 13:24:01 +08:00
Liu Han
d60ff9b6f6 components/tcpip_adapter: Fix set static IP address issue
Set static IP address, clear current DNS servers.
2016-12-13 09:52:29 +08:00
Angus Gratton
311b7040d5 Merge branch 'feature/make_size' into 'master'
Add the size target to project Makefile

Github pull request https://github.com/espressif/esp-idf/pull/154

See merge request !305
2016-12-13 07:25:35 +08:00
Jonathan Dumaresq
2a22dc082b Add the size target to project Makefile 2016-12-13 10:03:51 +11:00
Deomid Ryabkov
6380245d3d Create temp config in the same dir as target
Fixes case where SDK and app are on different mounts
2016-12-12 16:16:14 +00:00
Ivan Grokhotkov
2a4b150017 Merge branch 'test/integrate_stress_test_to_CI' into 'master'
add supported stress test to CI

add supported stress test to CI:

stress test requires long time to execute. They will only be executed when variable NIGHT_BUILD=YES. Therefore we'll use gitlab-API trigger to execute stress test cases.

See merge request !220
2016-12-12 16:20:13 +08:00
Angus Gratton
bbe1bceda8 build system: Project ELF should depend on linker scripts, binary libraries
TW#7816
2016-12-12 15:58:53 +11:00
Angus Gratton
9a378bca0e build system: Be specific about esp-idf submodule update warnings 2016-12-12 15:58:50 +11:00
Ivan Grokhotkov
1c60a0450e Merge branch 'bugfix/driver_cleanup_log' into 'master'
drivers: remove file paths from log statements

Function name and error string are usually sufficient to find the place which has triggered an error. 

`__FILE__` macro generates a string which has absolute file name (with our build system), which add many long strings to the program binary.

Also change log tags to lower case to match style used elsewhere.

Fixes https://github.com/espressif/esp-idf/issues/126

See merge request !282
2016-12-12 10:15:25 +08:00
Yinling
bf2a568924 remove not used code as rm -rf always return 0 2016-12-12 09:31:06 +08:00
Angus Gratton
bab1d49f1f Merge branch 'feature/esptool_flash_encryption' into 'master'
Flash encryption support

Flash encryption support in build system, tooling

To come in future MR:
* On-device key generation on first boot (for production devices), need to finalise testing of bootloader entropy seeding.
* spi_flash_encrypted_write to support non-32-byte block writes (at least optionally.)
* I think a lot of the bootloader_support component can possibly be rolled into "spiflash" and other components, to use a common API.

See merge request !240
2016-12-12 06:50:46 +08:00
Ivan Grokhotkov
f0efb41b57 Merge branch 'bugfix/warnings' into 'master'
bootloader, driver/rtc: fix warnings about unused functions

This fixes master builds which are failing due to warnings.

See merge request !300
2016-12-09 19:29:19 +08:00
Ivan Grokhotkov
f504e23d0f bootloader, driver/rtc: fix warnings about unused functions 2016-12-09 15:47:32 +08:00
Tian Hao
1be09039e3 component/bt : cleanup the un-necessary include in api.h
1. cleanup the un-necessary include in api.h for "extern c"
2. add UUID define
2016-12-09 14:38:21 +08:00
Tian Hao
4c6ccf1c23 component/bt : add cpp extern c
1. add cpp extern c
2. retab tab to 4 space
2016-12-09 14:38:21 +08:00
Tian Hao
e0e6966be0 component/bt : fix the authentication req type 2016-12-09 14:38:21 +08:00
Tian Hao
8185b0f806 component/bt : fix bug of bdaddr point to resolve gattc recv notify 2016-12-09 14:38:21 +08:00
Jeroen Domburg
bf57594ebe Merge branch 'feature/intr_alloc' into 'master'
Add dynamic interrupt allocation mechanism

This adds:
- Dynamic allocation of interrupts. Pass it the features of the interrupt you want, it'll set you up with an int.
- Shared interrupts. Enables multiple peripheral drivers to use the same interrupt. 
- Marking what interrupts are fully executable from IRAM; if an int isn't marked like that it will get disabled once flash cache gets disabled.

Also:
- Modifies driver to be in line with these changes

See merge request !254
2016-12-09 14:00:39 +08:00
Angus Gratton
f68e1c22ab Merge branch 'bugfix/ci_fail_warnings' into 'master'
Fail CI build on warnings

This allows developers to add CFLAGS for -Wno-error=XXX while developing, but before code passes the CI build then it must be warning-free.

See merge request !279
2016-12-09 13:25:51 +08:00
Angus Gratton
9fd7908bbe Merge branch 'bugfix/spiflash_erase_block' into 'master'
SPI flash: Block erase size 64KB not 32KB

Reverts changes made in 9f9d92b2df

See merge request !298
2016-12-09 13:19:09 +08:00
Ivan Grokhotkov
cf311d81ee Merge branch 'feature/newlib_full_format' into 'master'
newlib: add "full" formatting support

This change adds support for 64-bit formats and C99 features to newlib printf/scanf functions. This support is enabled by default in menuconfig, but can be switched off to reduce code size.

Also adds missing functions such as fmod and fmodf.

- Fixes https://github.com/espressif/esp-idf/issues/52
- Fixes https://github.com/espressif/esp-idf/issues/83


See merge request !274
2016-12-09 12:04:29 +08:00
Angus Gratton
8ba75a1e9f SPI flash: Block erase size 64KB not 32KB
Reverts changes made in 9f9d92b2df
2016-12-09 14:18:58 +11:00
Yinling
a283042258 switch socket recv print for stress test 2016-12-09 10:45:10 +08:00
Ivan Grokhotkov
bf7fbdf3cf Merge branch 'feature/mbedtls/add_menuconfig_component' into 'master'
components/mbedtls: add time and time data configuration at menuconfig



See merge request !268
2016-12-08 22:25:26 +08:00
Liu Han
d6ec6d1ae5 example/09_openssl_client: change default port to be 443 2016-12-08 20:28:45 +08:00
Yinling
5e1cdd3422 fix bug in test case TCPIP_TCP_5101
test time is not set in test case and not used to control test time
2016-12-08 16:15:49 +08:00
Liu Han
19a2ee3740 example/https_request: add header file declare platform.h of mbedtls 2016-12-08 15:03:38 +08:00
Tian Hao
8ca6e37c12 component/bt : delete the un-used lines 2016-12-08 15:00:19 +08:00
Jeroen Domburg
baa6a477c5 Fix example code, add chapter to docs about interrupts and multicore issues 2016-12-08 14:42:00 +08:00
Liu Han
c1802eaa98 components/mbedtls: add time and time data configuration at menuconfig 2016-12-08 13:33:47 +08:00
Angus Gratton
f807d16310 Merge branch 'feature/backtrace_dumps' into 'master'
Feature/backtrace dumps

Github pull request https://github.com/espressif/esp-idf/pull/149

(Plus reformatting of panic.c, as it hadn't been formatted to our code style yet.)

See merge request !290
2016-12-08 13:27:33 +08:00
Jeroen Domburg
cb9ef19d3b Also add intr_alloc magic to rtc code 2016-12-08 12:57:57 +08:00
Jeroen Domburg
2c34ab3374 Mark some interrupts that are now allocated dynamically as free, add int handle param documentation, add local ints test 2016-12-08 12:39:33 +08:00
Jeroen Domburg
9dc908d105 Add test for local interrupts, fix int disable code 2016-12-08 12:39:33 +08:00
Jeroen Domburg
ae8c37e0b6 Add disabling/enabling of shared interrupt, add testcase for interrupts 2016-12-08 12:39:33 +08:00
Jeroen Domburg
32fa94935d Changes according to merge request 2016-12-08 12:39:33 +08:00
Jeroen Domburg
655fd2986a Add interrupt allocation scheme / interrupt sharing. Also modifies drivers and examples. Also allows interrupts
to be marked specifically as having a handler that's all in IRAM.
2016-12-08 12:39:33 +08:00
Ivan Grokhotkov
221dc13535 newlib: add "full" formatting support, add missing functions
- add two versions of libc: libc.a and libc_nano.a. First one has full C99 formatting support, second one uses “nano” formatting functions available in ROM.
- fix linker error for fmod, fmodf, atof, atoff
- update tests
2016-12-08 11:04:54 +08:00
Ivan Grokhotkov
505282bab1 Merge branch 'feature/select_default_uart' into 'master'
UART console selection

This change adds a set of menuconfig options to set custom UART#, baud rate, and pins, for console output.
Ref. TW8146

Also includes the following changes:
- `uart_tx_wait_idle`: fix issue with last character not transmitted. ROM function `uart_tx_wait_idle` may have a bug which causes the function to return before the final character is fully transmitted. This replaces `uart_tx_wait_idle` declaration with a static inline definition which fixes the issue. Also replaces the use of `uart_tx_flush` with `uart_tx_wait_idle` in `esp_restart`, to remove garbage in console output on restart.
- `rtc_printf` is temporary replaced with a no-op, pending a new release of librtc.a. Current release assumes that UART0 is used for output,
and switches UART0 baud rate while doing frequency changes and printing some log output. This doesn’t work if a different UART is used for output.
- disable boot watchdog only after starting the main task. Boot watchdogs were disabled very early in startup code. It was possible to introduce an infinite loop anywhere in the many functions called from startup code, and this would not be detected by interrupt watchdog and task watchdog. This change postpones disabling of boot watchdogs to the point when the scheduler is running. Also replaces register expressed using integer address with a name. This change is not directly related to the previous ones, but was found while debugging UART selection features.

See merge request !288
2016-12-08 10:58:44 +08:00
Ivan Grokhotkov
a1542421c0 Merge branch 'bugfix/pcnt_driver' into 'master'
Fixing some syntax errors in pcnt



See merge request !278
2016-12-08 10:48:05 +08:00
Ivan Grokhotkov
e3eff5deb9 cpu_start: tabs->spaces 2016-12-08 10:20:12 +08:00
Angus Gratton
81e721ebcb Merge branch 'bugfix/rmt_debug_newline' into 'master'
Removal of spurious newline character in debug statement

There was a debug statement in the code that included an additional newline character that wasn't needed.

From github PR: https://github.com/espressif/esp-idf/pull/124

See merge request !291
2016-12-08 10:05:11 +08:00
Ivan Grokhotkov
a00762f1f9 Merge branch 'bugfix/netif_zero_init' into 'master'
Zero-fill netif on alloc

LwIP's `struct netif` was not zero-initialized after allocation, so `ipv6_addr_cb ` function pointer contained garbage. This caused a crash if the device was on an IPv6 capable network.

Fixes https://github.com/espressif/esp-idf/issues/133, https://github.com/espressif/esp-idf/issues/147, https://github.com/espressif/esp-idf/issues/142.

Source: https://github.com/espressif/esp-idf/pull/148

See merge request !289
2016-12-08 10:02:15 +08:00
Angus Gratton
cbc7d1814c pcnt example: Remove unused debugging tag 2016-12-07 14:16:05 -08:00
Neil Kolban
dbc5edac7e Removal of spurious newline character in debug statement
There was a debug statement in the code that included an additional newline character that wasn't needed.
2016-12-07 13:57:09 -08:00
tzx
25e4e21226 app_update: clean up warning log when compile any project 2016-12-07 13:49:53 -08:00
Tian Hao
c277735e6e component/bt : cleanup demo warnings 2016-12-07 13:49:53 -08:00
Tian Hao
5933ebc6b6 component/bt : cleanup all the "-W-no-xx" and all the warnings
1. cleanup the warnings.
2. fix the some function called in gap
3. fix some code in btc_main
2016-12-07 13:49:53 -08:00
Angus Gratton
94d2f77643 build system: Remove FLAGS_XXX variable option, replace with per-target overrides
Use for targeted disabling of warnings in LWIP.
2016-12-07 13:49:09 -08:00
Angus Gratton
b98405f9d9 esp32: ReformatReformat panic.c (remove tabs, etc) 2016-12-07 13:25:56 -08:00
Deomid Ryabkov
20fd57f147 Add backtrace to exception output.
On Xtensa windowed ABI backtrace is easy to do, and it's immensely
useful for debugging, so - do it by default.
We try to be careful and not deref bogus pointers while walking the
frames.

Example output (from debugging espressif/esp-idf#133):

Backtrace: 0x1:0x3ffc51e0 0x400e9dfa:0x3ffc5210 0x400e9ebc:0x3ffc5230 0x400ec487:0x3ffc5260

With just addr2line utility from binutils, this already pinpoints the
location of the crash.
2016-12-07 19:58:06 +00:00
Ivan Grokhotkov
13d802262a cpu_start: disable boot watchdog only after starting the main task
Boot watchdogs were disabled very early in startup code. It was possible to introduce an infinite loop anywhere in the many functions called from startup code, and this would not be detected by interrupt watchdog and task watchdog. This change postpones disabling of boot watchdogs to the point when the scheduler is running. Also replaces register expressed using integer address with a name.
2016-12-08 01:42:37 +08:00
Ivan Grokhotkov
b57aecdfe9 uart_tx_wait_idle: fix issue with last character not transmitted
- ROM function uart_tx_wait_idle may have a bug which causes the function to return before the final character is fully transmitted.
  This replaces uart_tx_wait_idle declaration with a static inline definition which fixes the issue.
- Also replaces the use of uart_tx_flush with uart_tx_wait_idle in esp_restart, to remove garbage in console output on restart.
- rtc_printf is temporary replaced with a no-op, pending a new release of librtc.a. Current release assumes that UART0 is used for output,
  and switches UART0 baud rate while doing frequency changes and printing some log output. This doesn’t work if a different UART is used for output.
2016-12-08 01:42:37 +08:00
Ivan Grokhotkov
b3f6cd08db support for console redirection to other UART
This change adds a set of menuconfig options to set custom UART#, baud rate, and pins, for console output.
Setting happens in bootloader startup code for PRO CPU, and in application startup code for APP CPU.
Ref. TW8146
2016-12-08 01:42:37 +08:00
Deomid Ryabkov
ce8b52617e Zero-fill netif on alloc
Fixes espressif/esp-idf#133
2016-12-07 14:32:29 +00:00
Ivan Grokhotkov
6dc77bc55c Merge branch 'driver_merge_tmp/merge_rtc_module' into 'master'
Driver: add rtc module

1. add rtc io control API (pull,output and input)
2. add touch pad API (touch pad read and interrupt)
3. add adc1 API (the max width is 12 Bits and support attenuation)
4. add hall sensor API (support hall sensor read )
5. add dac API (the width is 8 Bits)

See merge request !243
2016-12-07 17:03:33 +08:00
Chu Shu Chen
b1db2721dc driver: add rtc module and bugfix gpio32 gpio33
feature(rtc_module):add rtc module

1. add rtc io control API (pull,output and input)
2. add touch pad API (touch pad read and interrupt)
3. add adc1 API (the max width is 12 Bits and support attenuation)
4. add hall sensor API (support hall sensor read )
5. add dac API (the width is 8 Bits)

bugfix(gpio):gpio32 and gpio33 can not output and input

the gpio32 and gpio33 is initialize by librtc.a,and gpio_config not initialize the gpio as
digital gpio.they can not output and input,when users use gpio32 or gpio33.And there are some problems
about others driver ,when they use gpio32 or gpio33 as  matrix.
2016-12-07 15:56:13 +08:00
Ivan Grokhotkov
0dff9ed79d drivers: remove file paths from log statements
Function name and error string are usually sufficient to find the place which has triggered an error. __FILE__ macro generates a string which has absolute file name (with our build system), so there is a lot of long strings present in the program because of that.

Fixes https://github.com/espressif/esp-idf/issues/126
2016-12-07 12:01:54 +08:00
Ivan Grokhotkov
60d7440781 Merge branch 'feature/debugging_fixes' into 'master'
Small debugging fixes

Invoke panic handler when a stack overflow has been detected; unhandled interrupt handler now prints interrupt/cpu number for easier pinning down of source.

See merge request !277
2016-12-07 10:30:17 +08:00
Ivan Grokhotkov
a35e4f5923 Merge branch 'feature/unit_test_app_tweaks' into 'master'
unit-test-app: Don't auto-display menu after test run finishes

Previous code would sometimes display menu multiple times, depending on UART activity.

See merge request !253
2016-12-07 10:28:19 +08:00
Angus Gratton
69df54a28c unit-test-app: Don't auto-display menu after test run finishes
Previous code sometimes menu multiple times, depending on UART activity.
2016-12-06 11:25:31 -08:00
Angus Gratton
9a774848d4 Merge branch 'bugfix/gdbstub_no_sync_gdb' into 'master'
Gdbstub: Fix bug, small cleanup

Tianzhongxing found a small bug preventing gdbstub to work in certain cases. This fixes it, as well as including some minor cleanups.

See merge request !260
2016-12-07 03:20:07 +08:00
Angus Gratton
1613c180e0 CI build_examples.sh: Fail on warnings, even with -Wno-error 2016-12-06 10:39:56 -08:00
Yinling
a241197067 handle the case that artifacts do not exist 2016-12-06 19:01:20 +08:00
Yinling
ec40053720 add supported stress test cases to CI 2016-12-06 15:41:02 +08:00
me-no-dev
3cd9cb8911 Fix comment in the header 2016-12-06 02:10:35 +02:00
me-no-dev
2dbae95a7e Fix wrong assignment of channel and unit in pcnt_unit_config 2016-12-06 01:11:32 +02:00
Jeroen Domburg
c852e9958b Invoke panic handler when a stack overflow has been detected; unhandled interrupt now prints interrupt/cpu number. 2016-12-05 20:37:59 +08:00
Ivan Grokhotkov
c8685c2002 Merge branch 'feature/ulp' into 'master'
Initial support for generation of ULP coprocessor code

This adds basic support for writing ULP coprocessor programs using an assembly-like syntax, with integer labels and branches to labels.

See merge request !261
2016-12-02 22:45:47 +08:00
Jeroen Domburg
004aadfe70 Fix small bug in gdbstub where it sometimes would not return a valid stop reason, timing out gdb. Also clean up the code a bit. 2016-12-02 17:42:11 +08:00
Angus Gratton
ceb8566970 Flash encryption / secure boot: Temporarily disable on-device key generation
Will be enabled after seeding of HWRNG in bootloader is fully tested/qualified.
2016-12-01 23:49:13 -08:00
Angus Gratton
f62b83fb77 secure boot docs: Add some examples of using espsecure.py standalone 2016-12-01 23:49:12 -08:00
Angus Gratton
822ed84225 docs: Correct partition table offset 2016-12-01 23:49:12 -08:00
Angus Gratton
a9d5e26748 Secure boot: Correctly re-sign if signing key changes, better error if missing 2016-12-01 23:49:12 -08:00
Angus Gratton
506c8cd964 secure boot & flash encryption: Rework configuration options
Add UART bootloader disable options for flash encryption
2016-12-01 23:49:12 -08:00
Angus Gratton
9eb135fd73 Flash encryption: Support enabling flash encryption in bootloader, app support
* App access functions are all flash encryption-aware
* Documentation for flash encryption
* Partition read/write is flash aware
* New encrypted write function
2016-12-01 23:49:12 -08:00
Ivan Grokhotkov
ab3677d64c initial support for generation of ULP coprocessor code 2016-12-01 20:26:47 -08:00
746 changed files with 61574 additions and 13791 deletions

10
.gitignore vendored
View File

@@ -15,15 +15,19 @@ GPATH
.#*
\#*#
# eclipse setting
.settings
# Example project files
examples/*/sdkconfig
examples/*/sdkconfig.old
examples/*/build
examples/*/*/sdkconfig
examples/*/*/sdkconfig.old
examples/*/*/build
#Doc build artifacts
docs/_build/
docs/doxygen-warning-log.txt
docs/xml/
docs/man/
# Unit test app files
tools/unit-test-app/sdkconfig

View File

@@ -14,9 +14,11 @@ before_script:
- chmod 600 ~/.ssh/id_rsa
- echo -e "Host gitlab.espressif.cn\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
# if testing master branch, use github wifi libs.
# if testing other branches, use gitlab wifi libs (as maybe changes aren't merged to master yet)
- test "${CI_BUILD_REF_NAME}" = "master" || sed -i "s%https://github.com/espressif/esp32-wifi-lib%ssh://git@gitlab.espressif.cn:27227/idf/esp32-wifi-lib%" .gitmodules
# Set IS_PRIVATE or IS_PUBLIC depending on if our branch is public or not
#
# (the same regular expressions are used to set these are used in 'only:' sections below
- source make/configure_ci_environment.sh
# fetch all submodules
- git submodule update --init --recursive
@@ -30,6 +32,7 @@ build_template_app:
SDK_PATH: "$CI_PROJECT_DIR"
IDF_PATH: "$CI_PROJECT_DIR"
GIT_STRATEGY: clone
BATCH_BUILD: "1"
script:
- git clone https://github.com/espressif/esp-idf-template.git
@@ -38,13 +41,11 @@ build_template_app:
# using on esp-idf. If it doesn't exist then just stick to the default
# branch
- git checkout ${CI_BUILD_REF_NAME} || echo "Using esp-idf-template default branch..."
- make defconfig
# Test debug build (default)
- make all V=1
# Now test release build
- make clean
- sed -i.bak -e's/CONFIG_OPTIMIZATION_LEVEL_DEBUG\=y/CONFIG_OPTIMIZATION_LEVEL_RELEASE=y/' sdkconfig
- make defconfig
- make all V=1
# Check if there are any stray printf/ets_printf references in WiFi libs
- cd ../components/esp32/lib
@@ -62,6 +63,8 @@ build_template_app:
SDK_PATH: "$CI_PROJECT_DIR"
IDF_PATH: "$CI_PROJECT_DIR"
GIT_STRATEGY: clone
BATCH_BUILD: "1"
build_ssc:
<<: *build_template
@@ -78,6 +81,15 @@ build_ssc:
- chmod +x gen_misc_ng.sh
- ./gen_misc_ng.sh
build_at:
<<: *build_template
script:
- git clone $GITLAB_SSH_SERVER/application/esp-at.git
- cd esp-at
- git checkout ${CI_BUILD_REF_NAME} || echo "Using esp-at default branch..."
- make defconfig
- make
build_esp_idf_tests:
<<: *build_template
artifacts:
@@ -86,13 +98,15 @@ build_esp_idf_tests:
- ./tools/unit-test-app/build/*.elf
- ./tools/unit-test-app/build/*.map
- ./tools/unit-test-app/build/bootloader/*.bin
- ./components/idf_test/unit_test/TestCaseAll.yml
- ./components/idf_test/unit_test/CIConfigs/*.yml
expire_in: 6 mos
script:
- cd tools/unit-test-app
- git checkout ${CI_BUILD_REF_NAME} || echo "Using default branch..."
- make defconfig
- make TESTS_ALL=1
- python UnitTestParser.py
build_examples:
<<: *build_template
@@ -120,7 +134,8 @@ build_docs:
- cd docs
- doxygen
# If not building master branch, and there are Doxygen warnings, print them and bail out
- test "${CI_BUILD_REF_NAME}" = "master" || test $(cat doxygen-warning-log.txt | wc -l) -eq 0 || ( echo "Doxygen pass had some warnings:" && cat doxygen-warning-log.txt && false )
- test -n $IS_PRIVATE && test $(cat doxygen-warning-log.txt | wc -l) -eq 0 || ( echo "Doxygen pass had some warnings:" && cat doxygen-warning-log.txt && false )
- make gh-linkcheck
- make html
artifacts:
paths:
@@ -145,19 +160,24 @@ test_build_system:
variables:
IDF_PATH: "$CI_PROJECT_DIR"
script:
- ./make/test_configure_ci_environment.sh
- ./make/test_build_system.sh
test_report:
stage: test_report
image: espressif/esp32-ci-env
only:
- master
- triggers
- /^release\/v/
- /^v\d+\.\d+(\.\d+)?($|-)/
tags:
- test_report
- report
variables:
LOG_PATH: "$CI_PROJECT_DIR/$CI_BUILD_REF"
TEST_CASE_FILE_PATH: "$CI_PROJECT_DIR/components/idf_test"
REPORT_PATH: "$CI_PROJECT_DIR/CI_Test_Report"
MODULE_UPDATE_FILE: "$CI_PROJECT_DIR/tools/unit-test-app/ModuleDefinition.yml"
artifacts:
when: always
paths:
@@ -165,12 +185,34 @@ test_report:
- $LOG_PATH
expire_in: 12 mos
script:
# calc log path
- VER_NUM=`git rev-list HEAD | wc -l | awk '{print $1}'`
- SHA_ID=`echo $CI_BUILD_REF | cut -c 1-7`
- REVISION="${VER_NUM}_${SHA_ID}"
# replace / to _ in branch name
- ESCAPED_BRANCH_NAME=`echo $CI_BUILD_REF_NAME | sed 's/\//___/g'`
# result path and artifacts path
- RESULT_PATH="$CI_PROJECT_NAME/$ESCAPED_BRANCH_NAME/$REVISION"
- ARTIFACTS_PATH="$GITLAB_HTTP_SERVER/idf/esp-idf/builds/$CI_BUILD_ID/artifacts/browse/$CI_BUILD_REF"
# clone test bench
- git clone $GITLAB_SSH_SERVER/yinling/auto_test_script.git
- cd auto_test_script
# generate report
- python CITestReport.py -l $LOG_PATH -t $TEST_CASE_FILE_PATH -p $REPORT_PATH
- TEST_RESULT=Pass
- python CITestReport.py -l $LOG_PATH -t $TEST_CASE_FILE_PATH -p $REPORT_PATH -r $RESULT_PATH -a $ARTIFACTS_PATH -m $MODULE_UPDATE_FILE || TEST_RESULT=Fail
# commit to CI-test-result project
- git clone $GITLAB_SSH_SERVER/qa/CI-test-result.git
- rm -rf CI-test-result/RawData/$RESULT_PATH
- cp -R $CI_PROJECT_NAME CI-test-result/RawData
- cd CI-test-result
# config git user
- git config --global user.email "ci-test-result@espressif.com"
- git config --global user.name "ci-test-result"
# commit test result
- git add .
- git commit . -m "update test result for $CI_PROJECT_NAME/$CI_BUILD_REF_NAME/$CI_BUILD_REF, pipeline ID $CI_PIPELINE_ID" || exit 0
- git push origin master
- test "${TEST_RESULT}" = "Pass" || exit 1
push_master_to_github:
before_script:
@@ -178,12 +220,15 @@ push_master_to_github:
stage: deploy
only:
- master
- /^release\/v/
- /^v\d+\.\d+(\.\d+)?($|-)/
tags:
- deploy
when: on_success
image: espressif/esp32-ci-env
variables:
GIT_STRATEGY: clone
GITHUB_PUSH_REFS: refs/remotes/origin/release refs/remotes/origin/master
script:
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
@@ -192,7 +237,14 @@ push_master_to_github:
- chmod 600 ~/.ssh/id_rsa
- echo -e "Host github.com\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
- git remote add github git@github.com:espressif/esp-idf.git
- git push --follow-tags github HEAD:master
# What the next line of script does: goes through the list of refs for all branches we push to github,
# generates a snippet of shell which is evaluated. The snippet checks CI_BUILD_REF against the SHA
# (aka objectname) at tip of each branch, and if any SHAs match then it checks out the local branch
# and then pushes that ref to a corresponding github branch
#
# NB: In gitlab 9.x, CI_BUILD_REF was deprecated. New name is CI_COMMIT_REF. If below command suddenly
# generates bash syntax errors, this is probably why.
- eval $(git for-each-ref --shell bash --format 'if [ $CI_BUILD_REF == %(objectname) ]; then git checkout -B %(refname:strip=3); git push --follow-tags github %(refname:strip=3); fi;' $GITHUB_PUSH_REFS)
deploy_docs:
@@ -201,6 +253,8 @@ deploy_docs:
stage: deploy
only:
- master
- /^release\/v/
- /^v\d+\.\d+(\.\d+)?($|-)/
- triggers
tags:
- deploy
@@ -219,6 +273,26 @@ deploy_docs:
- scp $GIT_VER.tar.gz $DOCS_SERVER:$DOCS_PATH
- ssh $DOCS_SERVER -x "cd $DOCS_PATH && tar xzvf $GIT_VER.tar.gz && rm -f latest && ln -s $GIT_VER latest"
check_doc_links:
stage: test
image: espressif/esp32-ci-env
tags:
- check_doc_links
only:
# can only be triggered
- triggers
script:
# must be triggered with CHECK_LINKS=Yes, otherwise exit without test
- test $CHECK_LINKS = "Yes" || exit 0
# can only run on master branch (otherwise the commit is not on Github yet)
- test "${CI_BUILD_REF_NAME}" = "master" || exit 0
- cd docs
- make linkcheck
artifacts:
paths:
- docs/_build/linkcheck
expire_in: 1 mos
# AUTO GENERATED PART START, DO NOT MODIFY CONTENT BELOW
# template for test jobs
@@ -227,18 +301,20 @@ deploy_docs:
when: on_success
only:
- master
- /^release\/v/
- /^v\d+\.\d+(\.\d+)?($|-)/
- triggers
allow_failure: true
variables:
# LOCAL_ENV_CONFIG_PATH: define in template and jobs can overwrite if required
LOCAL_ENV_CONFIG_PATH: /home/gitlab-runner/LocalConfig/ESP32_IDF
LOCAL_ENV_CONFIG_PATH: $CI_PROJECT_DIR/ci-test-runner-configs/$CI_RUNNER_DESCRIPTION/ESP32_IDF
BIN_PATH: "$CI_PROJECT_DIR/SSC/ssc_bin/SSC"
APP_NAME: "ssc"
LOG_PATH: "$CI_PROJECT_DIR/$CI_BUILD_REF"
# append test level folder to TEST_CASE_FILE_PATH in before_script of test job
TEST_CASE_FILE_PATH: "$CI_PROJECT_DIR/components/idf_test/integration_test"
# jobs MUST set CONFIG_FILE in before_script, and overwrite the variables above if necessary
MODULE_UPDATE_FILE: "$CI_PROJECT_DIR/components/idf_test/unit_test/ModuleDefinition.yml"
artifacts:
when: always
@@ -247,6 +323,8 @@ deploy_docs:
expire_in: 6 mos
script:
# remove artifacts from last stage (UT logs)
- rm -rf $LOG_PATH
# add gitlab ssh key
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
@@ -254,11 +332,14 @@ deploy_docs:
- base64 --decode --ignore-garbage ~/.ssh/id_rsa_base64 > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
- echo -e "Host gitlab.espressif.cn\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
# clone local test env configs
- git clone $GITLAB_SSH_SERVER/qa/ci-test-runner-configs.git
# clone test bench
- git clone $GITLAB_SSH_SERVER/yinling/auto_test_script.git
- cd auto_test_script
- git checkout ${CI_COMMIT_REF_NAME} || echo "Using default branch..."
# run test
- python CIRunner.py -l $LOG_PATH -c $CONFIG_FILE -e $LOCAL_ENV_CONFIG_PATH -t $TEST_CASE_FILE_PATH bin_path $APP_NAME $BIN_PATH
- python CIRunner.py -l $LOG_PATH -c $CONFIG_FILE -e $LOCAL_ENV_CONFIG_PATH -t $TEST_CASE_FILE_PATH -m $MODULE_UPDATE_FILE bin_path $APP_NAME $BIN_PATH
# template for overnight test jobs
@@ -268,6 +349,8 @@ deploy_docs:
# can only be triggered
- triggers
script:
# remove artifacts from last stage (UT logs)
- rm -rf $LOG_PATH
# must be night build triggers, otherwise exit without test
- test $NIGHT_BUILD = "Yes" || exit 0
# add gitlab ssh key
@@ -277,11 +360,14 @@ deploy_docs:
- base64 --decode --ignore-garbage ~/.ssh/id_rsa_base64 > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
- echo -e "Host gitlab.espressif.cn\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
# clone local test env configs
- git clone $GITLAB_SSH_SERVER/qa/ci-test-runner-configs.git
# clone test bench
- git clone $GITLAB_SSH_SERVER/yinling/auto_test_script.git
- cd auto_test_script
- git checkout ${CI_COMMIT_REF_NAME} || echo "Using default branch..."
# run test
- python CIRunner.py -l $LOG_PATH -c $CONFIG_FILE -e $LOCAL_ENV_CONFIG_PATH -t $TEST_CASE_FILE_PATH bin_path $APP_NAME $BIN_PATH
- python CIRunner.py -l $LOG_PATH -c $CONFIG_FILE -e $LOCAL_ENV_CONFIG_PATH -t $TEST_CASE_FILE_PATH -m $MODULE_UPDATE_FILE bin_path $APP_NAME $BIN_PATH
# template for unit test jobs
.unit_test_template: &unit_test_template
@@ -290,12 +376,15 @@ deploy_docs:
stage: unit_test
variables:
# jobs MUST set CONFIG_FILE in before_script, and overwrite the variables above if necessary
LOCAL_ENV_CONFIG_PATH: /home/gitlab-runner/LocalConfig/ESP32_IDF
LOCAL_ENV_CONFIG_PATH: $CI_PROJECT_DIR/ci-test-runner-configs/$CI_RUNNER_DESCRIPTION/ESP32_IDF
BIN_PATH: "$CI_PROJECT_DIR/tools/unit-test-app/build/"
LOG_PATH: "$CI_PROJECT_DIR/$CI_BUILD_REF"
APP_NAME: "ut"
TEST_CASE_FILE_PATH: "$CI_PROJECT_DIR/components/idf_test/unit_test"
MODULE_UPDATE_FILE: "$CI_PROJECT_DIR/tools/unit-test-app/ModuleDefinition.yml"
dependencies:
- build_esp_idf_tests
UT_Function_SYS_01:
<<: *unit_test_template
@@ -305,6 +394,14 @@ UT_Function_SYS_01:
before_script:
- CONFIG_FILE=$TEST_CASE_FILE_PATH/CIConfigs/UT_Function_SYS_01.yml
UT_Function_SYS_02:
<<: *unit_test_template
tags:
- ESP32_IDF
- UT_T1_1
before_script:
- CONFIG_FILE=$TEST_CASE_FILE_PATH/CIConfigs/UT_Function_SYS_02.yml
IT_Function_SYS_01:
<<: *test_template
tags:
@@ -345,7 +442,6 @@ IT_Function_TCPIP_02:
tags:
- ESP32_IDF
- SSC_T1_1
- SSC_T2_1
before_script:
- CONFIG_FILE=$TEST_CASE_FILE_PATH/CIConfigs/IT_Function_TCPIP_02.yml
@@ -372,10 +468,73 @@ IT_Function_TCPIP_05:
tags:
- ESP32_IDF
- SSC_T1_1
- SSC_T2_1
before_script:
- CONFIG_FILE=$TEST_CASE_FILE_PATH/CIConfigs/IT_Function_TCPIP_05.yml
IT_Stress_WIFI_01:
<<: *test_template_night
tags:
- ESP32_IDF
- SSC_T5_1
before_script:
- CONFIG_FILE=$TEST_CASE_FILE_PATH/CIConfigs/IT_Stress_WIFI_01.yml
IT_Stress_TCPIP_01:
<<: *test_template_night
tags:
- ESP32_IDF
- SSC_T1_1
before_script:
- CONFIG_FILE=$TEST_CASE_FILE_PATH/CIConfigs/IT_Stress_TCPIP_01.yml
IT_Stress_TCPIP_02:
<<: *test_template_night
tags:
- ESP32_IDF
- SSC_T2_1
before_script:
- CONFIG_FILE=$TEST_CASE_FILE_PATH/CIConfigs/IT_Stress_TCPIP_02.yml
IT_Stress_TCPIP_03:
<<: *test_template_night
tags:
- ESP32_IDF
- SSC_T1_1
before_script:
- CONFIG_FILE=$TEST_CASE_FILE_PATH/CIConfigs/IT_Stress_TCPIP_03.yml
IT_Stress_TCPIP_04:
<<: *test_template_night
tags:
- ESP32_IDF
- SSC_T2_1
before_script:
- CONFIG_FILE=$TEST_CASE_FILE_PATH/CIConfigs/IT_Stress_TCPIP_04.yml
IT_Stable_TCPIP_01:
<<: *test_template_night
tags:
- ESP32_IDF
- SSC_T5_1
before_script:
- CONFIG_FILE=$TEST_CASE_FILE_PATH/CIConfigs/IT_Stable_TCPIP_01.yml
IT_Stable_TCPIP_02:
<<: *test_template_night
tags:
- ESP32_IDF
- SSC_T1_1
before_script:
- CONFIG_FILE=$TEST_CASE_FILE_PATH/CIConfigs/IT_Stable_TCPIP_02.yml
IT_Stable_TCPIP_03:
<<: *test_template_night
tags:
- ESP32_IDF
- SSC_T5_1
before_script:
- CONFIG_FILE=$TEST_CASE_FILE_PATH/CIConfigs/IT_Stable_TCPIP_03.yml
IT_Function_TCPIP_06:
<<: *test_template_night
tags:
@@ -388,7 +547,7 @@ IT_Function_WIFI_03:
<<: *test_template
tags:
- ESP32_IDF
- SSC_T3_PhyMode
- SSC_T1_APC
before_script:
- CONFIG_FILE=$TEST_CASE_FILE_PATH/CIConfigs/IT_Function_WIFI_03.yml
@@ -396,7 +555,7 @@ IT_Function_WIFI_04:
<<: *test_template
tags:
- ESP32_IDF
- SSC_T1_APC
- SSC_T3_PhyMode
before_script:
- CONFIG_FILE=$TEST_CASE_FILE_PATH/CIConfigs/IT_Function_WIFI_04.yml
@@ -422,7 +581,6 @@ IT_Function_TCPIP_07:
- ESP32_IDF
- SSC_T1_1
- SSC_T1_2
- SSC_T2_1
before_script:
- CONFIG_FILE=$TEST_CASE_FILE_PATH/CIConfigs/IT_Function_TCPIP_07.yml
@@ -431,6 +589,7 @@ IT_Function_TCPIP_08:
tags:
- ESP32_IDF
- SSC_T1_1
- SSC_T2_1
before_script:
- CONFIG_FILE=$TEST_CASE_FILE_PATH/CIConfigs/IT_Function_TCPIP_08.yml
@@ -439,6 +598,7 @@ IT_Function_TCPIP_09:
tags:
- ESP32_IDF
- SSC_T1_1
- SSC_T1_2
before_script:
- CONFIG_FILE=$TEST_CASE_FILE_PATH/CIConfigs/IT_Function_TCPIP_09.yml
@@ -448,7 +608,6 @@ IT_Function_TCPIP_10:
- ESP32_IDF
- SSC_T1_1
- SSC_T1_2
- SSC_T2_1
before_script:
- CONFIG_FILE=$TEST_CASE_FILE_PATH/CIConfigs/IT_Function_TCPIP_10.yml
@@ -457,7 +616,6 @@ IT_Function_TCPIP_11:
tags:
- ESP32_IDF
- SSC_T1_1
- SSC_T1_2
before_script:
- CONFIG_FILE=$TEST_CASE_FILE_PATH/CIConfigs/IT_Function_TCPIP_11.yml
@@ -468,3 +626,4 @@ IT_Function_TCPIP_12:
- SSC_T1_1
before_script:
- CONFIG_FILE=$TEST_CASE_FILE_PATH/CIConfigs/IT_Function_TCPIP_12.yml

5
.gitmodules vendored
View File

@@ -3,10 +3,13 @@
url = https://github.com/espressif/esp32-wifi-lib.git
[submodule "components/esptool_py/esptool"]
path = components/esptool_py/esptool
url = https://github.com/themadinventor/esptool.git
url = https://github.com/espressif/esptool.git
[submodule "components/bt/lib"]
path = components/bt/lib
url = https://github.com/espressif/esp32-bt-lib.git
[submodule "components/micro-ecc/micro-ecc"]
path = components/micro-ecc/micro-ecc
url = https://github.com/kmackay/micro-ecc.git
[submodule "components/coap/libcoap"]
path = components/coap/libcoap
url = https://github.com/obgm/libcoap.git

View File

@@ -21,7 +21,7 @@ Before sending us a Pull Request, please consider this list of points:
* Is the code adequately commented for people to understand how it is structured?
* Is there documentation or examples that go with code contributions? `There are additional suggestions for writing good examples in the examples README <https://github.com/espressif/esp-idf/tree/master/examples>`_.
* Is there documentation or examples that go with code contributions? There are additional suggestions for writing good examples in :idf:`examples` readme.
* Are comments and documentation written in clear English, with no spelling or grammar errors?

View File

@@ -1,32 +1,46 @@
# Using Espressif IoT Development Framework with the ESP32
# Espressif IoT Development Framework
[![alt text](https://readthedocs.org/projects/docs/badge/?version=latest "Documentation Status")](http://esp-idf.readthedocs.io/en/latest/?badge=latest)
# Setting Up ESP-IDF
ESP-IDF is the official development framework for the [ESP32](https://espressif.com/en/products/hardware/esp32/overview>) chip.
In the [docs](docs) directory you will find per-platform setup guides:
# Developing With the ESP-IDF
* [Windows Setup Guide](docs/windows-setup.rst)
* [Mac OS Setup Guide](docs/macos-setup.rst)
* [Linux Setup Guide](docs/linux-setup.rst)
## Setting Up ESP-IDF
# Finding A Project
See setup guides for detailed instructions to set up the ESP-IDF:
As well as the [esp-idf-template](https://github.com/espressif/esp-idf-template) project mentioned in the setup guide, esp-idf comes with some example projects in the [examples](examples) directory.
* [Windows Setup Guide](http://esp-idf.readthedocs.io/en/latest/windows-setup.html)
* [Mac OS Setup Guide](http://esp-idf.readthedocs.io/en/latest/macos-setup.html)
* [Linux Setup Guide](http://esp-idf.readthedocs.io/en/latest/linux-setup.html)
Once you've found the project you want to work with, change to its directory and you can configure and build it:
## Finding a Project
# Configuring your project
As well as the [esp-idf-template](https://github.com/espressif/esp-idf-template) project mentioned in the setup guide, ESP-IDF comes with some example projects in the [examples](examples) directory.
Once you've found the project you want to work with, change to its directory and you can configure and build it.
## Configuring the Project
`make menuconfig`
# Compiling your project
* Opens a text-based configuration menu for the project.
* Use up & down arrow keys to navigate the menu.
* Use Enter key to go into a submenu, Escape key to go out or to exit.
* Type `?` to see a help screen. Enter key exits the help screen.
* Use Space key, or `Y` and `N` keys to enable (Yes) and disable (No) configuration items with checkboxes "`[*]`"
* Pressing `?` while highlighting a configuration item displays help about that item.
* Type `/` to search the configuration items.
Once done configuring, press Escape multiple times to exit and say "Yes" to save the new configuration when prompted.
## Compiling the Project
`make all`
... will compile app, bootloader and generate a partition table based on the config.
# Flashing your project
## Flashing the Project
When `make all` finishes, it will print a command line to use esptool.py to flash the chip. However you can also do this from make by running:
@@ -36,7 +50,17 @@ This will flash the entire project (app, bootloader and partition table) to a ne
You don't need to run `make all` before running `make flash`, `make flash` will automatically rebuild anything which needs it.
# Compiling & Flashing Just the App
## Viewing Serial Output
The `make monitor` target will use the already-installed [miniterm](http://pyserial.readthedocs.io/en/latest/tools.html#module-serial.tools.miniterm) (a part of pyserial) to display serial output from the ESP32 on the terminal console.
Exit miniterm by typing Ctrl-].
To flash and monitor output in one pass, you can run:
`make flash monitor`
## Compiling & Flashing Just the App
After the initial flash, you may just want to build and flash just your app, not the bootloader and partition table:
@@ -45,9 +69,19 @@ After the initial flash, you may just want to build and flash just your app, not
`make app-flash` will automatically rebuild the app if it needs it.
(There's no downside to reflashing the bootloader and partition table each time, if they haven't changed.)
(In normal development there's no downside to reflashing the bootloader and partition table each time, if they haven't changed.)
# The Partition Table
## Parallel Builds
ESP-IDF supports compiling multiple files in parallel, so all of the above commands can be run as `make -jN` where `N` is the number of parallel make processes to run (generally N should be equal to or one more than the number of CPU cores in your system.)
Multiple make functions can be combined into one. For example: to build the app & bootloader using 5 jobs in parallel, then flash everything, and then display serial output from the ESP32 run:
```
make -j5 flash monitor
```
## The Partition Table
Once you've compiled your project, the "build" directory will contain a binary file with a name like "my_app.bin". This is an ESP32 image binary that can be loaded by the bootloader.
@@ -64,13 +98,19 @@ In both cases the factory app is flashed at offset 0x10000. If you `make partiti
For more details about partition tables and how to create custom variations, view the `docs/partition-tables.rst` file.
## Erasing Flash
The `make flash` target does not erase the entire flash contents. However it is sometimes useful to set the device back to a totally erased state, particularly when making partition table changes or OTA app updates. To erase the entire flash, run `make erase_flash`.
This can be combined with other targets, ie `make erase_flash flash` will erase everything and then re-flash the new app, bootloader and partition table.
# Resources
* The [docs directory of the esp-idf repository](docs) contains source of [esp-idf](http://esp-idf.readthedocs.io/) documentation.
* Documentation for the latest version: http://esp-idf.readthedocs.io/. This documentation is built from the [docs directory](docs) of this repository.
* The [esp32.com forum](http://esp32.com/) is a place to ask questions and find community resources.
* [Check the Issues section on github](https://github.com/espressif/esp-idf/issues) if you find a bug or have a feature request. Please check existing Issues before opening a new one.
* If you're interested in contributing to esp-idf, please check the [Contributions Guide](http://esp-idf.readthedocs.io/en/latest/contributing.html>).
* If you're interested in contributing to ESP-IDF, please check the [Contributions Guide](http://esp-idf.readthedocs.io/en/latest/contributing.html>).

View File

@@ -9,7 +9,7 @@
if [ -z ${IDF_PATH} ]; then
echo "IDF_PATH must be set before including this script."
else
IDF_ADD_PATHS_EXTRAS="${IDF_PATH}/components/esptool_py/esptool:${IDF_PATH}/components/partition_table/"
IDF_ADD_PATHS_EXTRAS="${IDF_PATH}/components/esptool_py/esptool:${IDF_PATH}/components/espcoredump:${IDF_PATH}/components/partition_table/"
export PATH="${PATH}:${IDF_ADD_PATHS_EXTRAS}"
echo "Added to PATH: ${IDF_ADD_PATHS_EXTRAS}"
fi

View File

@@ -27,6 +27,7 @@
#include "esp_spi_flash.h"
#include "esp_image_format.h"
#include "esp_secure_boot.h"
#include "esp_flash_encrypt.h"
#include "sdkconfig.h"
#include "esp_ota_ops.h"
@@ -44,6 +45,10 @@ typedef struct ota_ops_entry_ {
esp_partition_t part;
uint32_t erased_size;
uint32_t wrote_size;
#ifdef CONFIG_FLASH_ENCRYPTION_ENABLED
uint8_t partial_bytes;
uint8_t partial_data[16];
#endif
LIST_ENTRY(ota_ops_entry_) entries;
} ota_ops_entry_t;
@@ -106,6 +111,7 @@ esp_err_t esp_ota_begin(const esp_partition_t *partition, size_t image_size, esp
esp_err_t esp_ota_write(esp_ota_handle_t handle, const void *data, size_t size)
{
const uint8_t *data_bytes = (const uint8_t *)data;
esp_err_t ret;
ota_ops_entry_t *it;
@@ -119,7 +125,47 @@ esp_err_t esp_ota_write(esp_ota_handle_t handle, const void *data, size_t size)
if (it->handle == handle) {
// must erase the partition before writing to it
assert(it->erased_size > 0 && "must erase the partition before writing to it");
ret = esp_partition_write(&it->part, it->wrote_size, data, size);
if(it->wrote_size == 0 && size > 0 && data_bytes[0] != 0xE9) {
ESP_LOGE(TAG, "OTA image has invalid magic byte (expected 0xE9, saw 0x%02x", data_bytes[0]);
return ESP_ERR_OTA_VALIDATE_FAILED;
}
#ifdef CONFIG_FLASH_ENCRYPTION_ENABLED
if (esp_flash_encryption_enabled()) {
/* Can only write 16 byte blocks to flash, so need to cache anything else */
size_t copy_len;
/* check if we have partially written data from earlier */
if (it->partial_bytes != 0) {
copy_len = OTA_MIN(16 - it->partial_bytes, size);
memcpy(it->partial_data + it->partial_bytes, data_bytes, copy_len);
it->partial_bytes += copy_len;
if (it->partial_bytes != 16) {
return ESP_OK; /* nothing to write yet, just filling buffer */
}
/* write 16 byte to partition */
ret = esp_partition_write(&it->part, it->wrote_size, it->partial_data, 16);
if (ret != ESP_OK) {
return ret;
}
it->partial_bytes = 0;
memset(it->partial_data, 0xFF, 16);
it->wrote_size += 16;
data_bytes += copy_len;
size -= copy_len;
}
/* check if we need to save trailing data that we're about to write */
it->partial_bytes = size % 16;
if (it->partial_bytes != 0) {
size -= it->partial_bytes;
memcpy(it->partial_data, data_bytes + size, it->partial_bytes);
}
}
#endif
ret = esp_partition_write(&it->part, it->wrote_size, data_bytes, size);
if(ret == ESP_OK){
it->wrote_size += size;
}
@@ -134,27 +180,12 @@ esp_err_t esp_ota_write(esp_ota_handle_t handle, const void *data, size_t size)
esp_err_t esp_ota_end(esp_ota_handle_t handle)
{
esp_err_t ret;
ota_ops_entry_t *it;
size_t image_size;
esp_err_t ret = ESP_OK;
for (it = LIST_FIRST(&s_ota_ops_entries_head); it != NULL; it = LIST_NEXT(it, entries)) {
if (it->handle == handle) {
// an ota handle need to be ended after erased and wrote data in it
if ((it->erased_size == 0) || (it->wrote_size == 0)) {
return ESP_ERR_INVALID_ARG;
}
#ifdef CONFIG_SECUREBOOTLOADER
if (esp_image_basic_verify(it->part.address, &image_size) != ESP_OK) {
return ESP_ERR_OTA_VALIDATE_FAILED;
}
ret = esp_secure_boot_verify_signature(it->part.address, image_size);
if (ret != ESP_OK) {
return ESP_ERR_OTA_VALIDATE_FAILED;
}
#endif
LIST_REMOVE(it, entries);
break;
}
}
@@ -163,8 +194,44 @@ esp_err_t esp_ota_end(esp_ota_handle_t handle)
return ESP_ERR_NOT_FOUND;
}
/* 'it' holds the ota_ops_entry_t for 'handle' */
// esp_ota_end() is only valid if some data was written to this handle
if ((it->erased_size == 0) || (it->wrote_size == 0)) {
ret = ESP_ERR_INVALID_ARG;
goto cleanup;
}
#ifdef CONFIG_FLASH_ENCRYPTION_ENABLED
if (it->partial_bytes > 0 && esp_flash_encryption_enabled()) {
/* Write out last 16 bytes, if necessary */
ret = esp_partition_write(&it->part, it->wrote_size, it->partial_data, 16);
if (ret != ESP_OK) {
ret = ESP_ERR_INVALID_STATE;
goto cleanup;
}
it->wrote_size += 16;
it->partial_bytes = 0;
}
#endif
if (esp_image_basic_verify(it->part.address, true, &image_size) != ESP_OK) {
ret = ESP_ERR_OTA_VALIDATE_FAILED;
goto cleanup;
}
#ifdef CONFIG_SECURE_BOOT_ENABLED
ret = esp_secure_boot_verify_signature(it->part.address, image_size);
if (ret != ESP_OK) {
ret = ESP_ERR_OTA_VALIDATE_FAILED;
goto cleanup;
}
#endif
cleanup:
LIST_REMOVE(it, entries);
free(it);
return ESP_OK;
return ret;
}
static uint32_t ota_select_crc(const ota_select *s)
@@ -271,11 +338,9 @@ static esp_err_t esp_rewrite_ota_data(esp_partition_subtype_t subtype)
}
return rewrite_ota_seq((SUB_TYPE_ID(subtype) + 1) % ota_app_count + i * ota_app_count, 0, find_partition);
} else if (s_ota_select[0].ota_seq == 0xFFFFFFFF && s_ota_select[1].ota_seq == 0xFFFFFFFF) {
return rewrite_ota_seq(SUB_TYPE_ID(subtype) + 1, 0, find_partition);
} else {
return ESP_ERR_OTA_SELECT_INFO_INVALID;
/* Both OTA slots are invalid, probably because unformatted... */
return rewrite_ota_seq(SUB_TYPE_ID(subtype) + 1, 0, find_partition);
}
} else {
@@ -285,17 +350,18 @@ static esp_err_t esp_rewrite_ota_data(esp_partition_subtype_t subtype)
esp_err_t esp_ota_set_boot_partition(const esp_partition_t *partition)
{
const esp_partition_t *find_partition = NULL;
size_t image_size;
const esp_partition_t *find_partition = NULL;
if (partition == NULL) {
return ESP_ERR_INVALID_ARG;
}
#ifdef CONFIG_SECUREBOOTLOADER
if (esp_image_basic_verify(partition->address, &image_size) != ESP_OK) {
if (esp_image_basic_verify(partition->address, true, &image_size) != ESP_OK) {
return ESP_ERR_OTA_VALIDATE_FAILED;
}
ret = esp_secure_boot_verify_signature(partition->address, image_size);
#ifdef CONFIG_SECURE_BOOT_ENABLED
esp_err_t ret = esp_secure_boot_verify_signature(partition->address, image_size);
if (ret != ESP_OK) {
return ESP_ERR_OTA_VALIDATE_FAILED;
}
@@ -349,33 +415,34 @@ const esp_partition_t *esp_ota_get_boot_partition(void)
}
ota_app_count = get_ota_partition_count();
ESP_LOGD(TAG, "found ota bin max = %d", ota_app_count);
ESP_LOGD(TAG, "found ota app max = %d", ota_app_count);
if (s_ota_select[0].ota_seq == 0xFFFFFFFF && s_ota_select[1].ota_seq == 0xFFFFFFFF) {
ESP_LOGD(TAG, "finding factory bin......");
ESP_LOGD(TAG, "finding factory app......");
return esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_FACTORY, NULL);
} else if (ota_select_valid(&s_ota_select[0]) && ota_select_valid(&s_ota_select[1])) {
ESP_LOGD(TAG, "finding ota_%d bin......", \
ESP_LOGD(TAG, "finding ota_%d app......", \
ESP_PARTITION_SUBTYPE_APP_OTA_MIN + ((OTA_MAX(s_ota_select[0].ota_seq, s_ota_select[1].ota_seq) - 1) % ota_app_count));
return esp_partition_find_first(ESP_PARTITION_TYPE_APP, \
ESP_PARTITION_SUBTYPE_APP_OTA_MIN + ((OTA_MAX(s_ota_select[0].ota_seq, s_ota_select[1].ota_seq) - 1) % ota_app_count), NULL);
} else if (ota_select_valid(&s_ota_select[0])) {
ESP_LOGD(TAG, "finding ota_%d bin......", \
ESP_LOGD(TAG, "finding ota_%d app......", \
ESP_PARTITION_SUBTYPE_APP_OTA_MIN + (s_ota_select[0].ota_seq - 1) % ota_app_count);
return esp_partition_find_first(ESP_PARTITION_TYPE_APP, \
ESP_PARTITION_SUBTYPE_APP_OTA_MIN + (s_ota_select[0].ota_seq - 1) % ota_app_count, NULL);
} else if (ota_select_valid(&s_ota_select[1])) {
ESP_LOGD(TAG, "finding ota_%d bin......", \
ESP_LOGD(TAG, "finding ota_%d app......", \
ESP_PARTITION_SUBTYPE_APP_OTA_MIN + (s_ota_select[1].ota_seq - 1) % ota_app_count);
return esp_partition_find_first(ESP_PARTITION_TYPE_APP, \
ESP_PARTITION_SUBTYPE_APP_OTA_MIN + (s_ota_select[1].ota_seq - 1) % ota_app_count, NULL);
} else {
ESP_LOGE(TAG, "not found current bin");
return NULL;
ESP_LOGE(TAG, "ota data invalid, no current app. Assuming factory");
return esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_FACTORY, NULL);
}
}
}

View File

@@ -73,11 +73,16 @@ esp_err_t esp_ota_write(esp_ota_handle_t handle, const void* data, size_t size);
/**
* @brief Finish the update and validate written data
*
* @param handle Handle obtained from esp_ota_begin
* @param handle Handle obtained from esp_ota_begin.
*
* @return:
* - ESP_OK: if validate ota image pass
* - ESP_ERR_OTA_VALIDATE_FAILED: validate the ota image is invalid
* @note After calling esp_ota_end(), the handle is no longer valid and any memory associated with it is freed (regardless of result).
*
* @return:
* - ESP_OK: Newly written OTA app image is valid.
* - ESP_ERR_NOT_FOUND: OTA handle was not found.
* - ESP_ERR_INVALID_ARG: Handle was never written to.
* - ESP_ERR_OTA_VALIDATE_FAILED: OTA image is invalid (either not a valid app image, or - if secure boot is enabled - signature failed to verify.)
* - ESP_ERR_INVALID_STATE: If flash encryption is enabled, this result indicates an internal error writing the final encrypted bytes to flash.
*/
esp_err_t esp_ota_end(esp_ota_handle_t handle);

View File

@@ -1,7 +1,7 @@
menu "Bootloader config"
choice LOG_BOOTLOADER_LEVEL
bool "Bootloader log verbosity"
default LOG_BOOTLOADER_LEVEL_WARN
default LOG_BOOTLOADER_LEVEL_INFO
help
Specify how much output to see in bootloader logs.
@@ -32,23 +32,24 @@ endmenu
menu "Secure boot configuration"
menu "Security features"
choice SECURE_BOOTLOADER
bool "Secure bootloader"
default SECURE_BOOTLOADER_DISABLED
config SECURE_BOOT_ENABLED
bool "Enable secure boot in bootloader (READ DOCS FIRST)"
default N
help
Build a bootloader with the secure boot flag enabled.
Build a bootloader which enables secure boot on first boot.
Secure bootloader can be one-time-flash (chip will only ever
boot that particular bootloader), or a digest key can be used
to allow the secure bootloader to be re-flashed with
modifications. Secure boot also permanently disables JTAG.
Once enabled, secure boot will not boot a modified bootloader. The bootloader will only load a partition table or boot an app if the data has a verified digital signature. There are implications for reflashing updated apps once secure boot is enabled.
See docs/security/secure-boot.rst for details.
When enabling secure boot, JTAG and ROM BASIC Interpreter are permanently disabled by default.
config SECURE_BOOTLOADER_DISABLED
bool "Disabled"
Refer to http://esp-idf.readthedocs.io/en/latest/security/secure-boot.html before enabling.
choice SECURE_BOOTLOADER_MODE
bool "Secure bootloader mode"
depends on SECURE_BOOT_ENABLED
default SECURE_BOOTLOADER_ONE_TIME_FLASH
config SECURE_BOOTLOADER_ONE_TIME_FLASH
bool "One-time flash"
@@ -62,18 +63,29 @@ config SECURE_BOOTLOADER_REFLASHABLE
help
Generate a reusable secure bootloader key, derived (via SHA-256) from the secure boot signing key.
This allows the secure bootloader to be re-flashed by anyone with access to the secure boot signing key.
This allows the secure bootloader to be re-flashed by anyone with access to the secure boot signing key.
This option is less secure than one-time flash, because a leak of the digest key from one device allows reflashing of any device that uses it.
endchoice
config SECURE_BOOT_SIGNING_KEY
string "Secure boot signing key"
depends on SECURE_BOOTLOADER_ENABLED
default secure_boot_signing_key.pem
config SECURE_BOOT_BUILD_SIGNED_BINARIES
bool "Sign binaries during build"
depends on SECURE_BOOT_ENABLED
default y
help
Path to the key file used to sign partition tables and app images for secure boot.
Once secure boot is enabled, bootloader will only boot if partition table and app image are signed.
If enabled, these binary files are signed as part of the build process. The file named in "Secure boot private signing key" will be used to sign the image.
If disabled, unsigned app/partition data will be built. They must be signed manually using espsecure.py (for example, on a remote signing server.)
config SECURE_BOOT_SIGNING_KEY
string "Secure boot private signing key"
depends on SECURE_BOOT_BUILD_SIGNED_BINARIES
default secure_boot_signing_key.pem
help
Path to the key file used to sign partition tables and app images for secure boot. Once secure boot is enabled, bootloader will only boot if partition table and app image are signed.
Key file is an ECDSA private key (NIST256p curve) in PEM format.
@@ -84,35 +96,122 @@ config SECURE_BOOT_SIGNING_KEY
See docs/security/secure-boot.rst for details.
config SECURE_BOOT_DISABLE_JTAG
bool "First boot: Permanently disable JTAG"
depends on SECURE_BOOTLOADER_ENABLED
default Y
config SECURE_BOOT_VERIFICATION_KEY
string "Secure boot public signature verification key"
depends on SECURE_BOOT_ENABLED && !SECURE_BOOT_BUILD_SIGNED_BINARIES
default signature_verification_key.bin
help
Path to a public key file used to verify signed images. This key is compiled into the bootloader,
and may also be used to verify signatures on OTA images after download.
Key file is in raw binary format, and can be extracted from a
PEM formatted private key using the espsecure.py
extract_public_key command.
Refer to http://esp-idf.readthedocs.io/en/latest/security/secure-boot.html before enabling.
config SECURE_BOOT_INSECURE
bool "Allow potentially insecure options"
depends on SECURE_BOOT_ENABLED
default N
help
You can disable some of the default protections offered by secure boot, in order to enable testing or a custom combination of security features.
Only enable these options if you are very sure.
Refer to http://esp-idf.readthedocs.io/en/latest/security/secure-boot.html before enabling.
config FLASH_ENCRYPTION_ENABLED
bool "Enable flash encryption on boot (READ DOCS FIRST)"
default N
help
If this option is set, flash contents will be encrypted by the bootloader on first boot.
Note: After first boot, the system will be permanently encrypted. Re-flashing an encrypted
system is complicated and not always possible.
Read http://esp-idf.readthedocs.io/en/latest/security/flash-encryption.html before enabling.
config FLASH_ENCRYPTION_INSECURE
bool "Allow potentially insecure options"
depends on FLASH_ENCRYPTION_ENABLED
default N
help
You can disable some of the default protections offered by flash encryption, in order to enable testing or a custom combination of security features.
Only enable these options if you are very sure.
Refer to docs/security/secure-boot.rst and docs/security/flash-encryption.rst for details.
menu "Potentially insecure options"
visible if FLASH_ENCRYPTION_INSECURE || SECURE_BOOT_INSECURE
# NOTE: Options in this menu NEED to have SECURE_BOOT_INSECURE
# and/or FLASH_ENCRYPTION_INSECURE in "depends on", as the menu
# itself doesn't enable/disable its children (if it's not set,
# it's possible for the insecure menu to be disabled but the insecure option
# to remain on which is very bad.)
config SECURE_BOOT_ALLOW_ROM_BASIC
bool "Leave ROM BASIC Interpreter available on reset"
depends on SECURE_BOOT_INSECURE
default N
help
Bootloader permanently disable JTAG (across entire chip) when enabling secure boot. This happens on first boot of the bootloader.
If not set (default), bootloader permanently disables ROM BASIC (on UART console) as a fallback if the bootloader image becomes invalid. This happens on first boot.
It is recommended this option remains set for production environments.
Only set this option in testing environments.
config SECURE_BOOT_DISABLE_ROM_BASIC
bool "First boot: Permanently disable ROM BASIC fallback"
depends on SECURE_BOOTLOADER_ENABLED
default Y
config SECURE_BOOT_ALLOW_JTAG
bool "Allow JTAG Debugging"
depends on SECURE_BOOT_INSECURE || FLASH_ENCRYPTION_INSECURE
default N
help
Bootloader permanently disables ROM BASIC (on UART console) as a fallback if the bootloader image becomes invalid. This happens on first boot.
If not set (default), the bootloader will permanently disable JTAG (across entire chip) on first boot when either secure boot or flash encryption is enabled.
It is recommended this option remains set in production environments.
Setting this option leaves JTAG on for debugging, which negates all protections of flash encryption and some of the protections of secure boot.
Only set this option in testing environments.
config FLASH_ENCRYPTION_UART_BOOTLOADER_ALLOW_ENCRYPT
bool "Leave UART bootloader encryption enabled"
depends on FLASH_ENCRYPTION_INSECURE
default N
help
If not set (default), the bootloader will permanently disable UART bootloader encryption access on first boot. If set, the UART bootloader will still be able to access hardware encryption.
It is recommended to only set this option in testing environments.
config FLASH_ENCRYPTION_UART_BOOTLOADER_ALLOW_DECRYPT
bool "Leave UART bootloader decryption enabled"
depends on FLASH_ENCRYPTION_INSECURE
default N
help
If not set (default), the bootloader will permanently disable UART bootloader decryption access on first boot. If set, the UART bootloader will still be able to access hardware decryption.
Only set this option in testing environments. Setting this option allows complete bypass of flash encryption.
config FLASH_ENCRYPTION_UART_BOOTLOADER_ALLOW_CACHE
bool "Leave UART bootloader flash cache enabled"
depends on FLASH_ENCRYPTION_INSECURE
default N
help
If not set (default), the bootloader will permanently disable UART bootloader flash cache access on first boot. If set, the UART bootloader will still be able to access the flash cache.
Only set this option in testing environments.
config SECURE_BOOT_TEST_MODE
bool "Test mode: don't actually enable secure boot"
depends on SECURE_BOOTLOADER_ENABLED
bool "Secure boot test mode: don't permanently set any efuses"
depends on SECURE_BOOT_INSECURE
default N
help
If this option is set, all permanent secure boot changes (via Efuse) are disabled.
This option is for testing purposes only - it effectively completely disables secure boot protection.
Log output will state changes which would be applied, but they will not be.
config SECURE_BOOTLOADER_ENABLED
bool
default SECURE_BOOTLOADER_ONE_TIME_FLASH || SECURE_BOOTLOADER_REFLASHABLE
This option is for testing purposes only - it completely disables secure boot protection.
endmenu # potentially insecure
endmenu

View File

@@ -18,6 +18,9 @@ BOOTLOADER_BIN=$(BOOTLOADER_BUILD_DIR)/bootloader.bin
SECURE_BOOT_SIGNING_KEY=$(abspath $(call dequote,$(CONFIG_SECURE_BOOT_SIGNING_KEY)))
export SECURE_BOOT_SIGNING_KEY # used by bootloader_support component
# Has a matching value in bootloader_support esp_flash_partitions.h
BOOTLOADER_OFFSET := 0x1000
# Custom recursive make for bootloader sub-project
BOOTLOADER_MAKE=+$(MAKE) -C $(BOOTLOADER_COMPONENT_PATH)/src \
V=$(V) BUILD_DIR_BASE=$(BOOTLOADER_BUILD_DIR) TEST_COMPONENTS=
@@ -29,66 +32,59 @@ $(BOOTLOADER_BIN): $(SDKCONFIG_MAKEFILE)
clean: bootloader-clean
ifdef CONFIG_SECURE_BOOTLOADER_DISABLED
ifndef CONFIG_SECURE_BOOT_ENABLED
# If secure boot disabled, bootloader flashing is integrated
# with 'make flash' and no warnings are printed.
bootloader: $(BOOTLOADER_BIN)
@echo $(SEPARATOR)
@echo "Bootloader built. Default flash command is:"
@echo "$(ESPTOOLPY_WRITE_FLASH) 0x1000 $^"
@echo "$(ESPTOOLPY_WRITE_FLASH) $(BOOTLOADER_OFFSET) $^"
ESPTOOL_ALL_FLASH_ARGS += 0x1000 $(BOOTLOADER_BIN)
ESPTOOL_ALL_FLASH_ARGS += $(BOOTLOADER_OFFSET) $(BOOTLOADER_BIN)
bootloader-flash: $(BOOTLOADER_BIN)
bootloader-flash: $(BOOTLOADER_BIN) $(call prereq_if_explicit,erase_flash)
$(ESPTOOLPY_WRITE_FLASH) 0x1000 $^
else ifdef CONFIG_SECURE_BOOTLOADER_ONE_TIME_FLASH
#### TEMPORARILY DISABLE THIS OPTION
ifneq ("$(IDF_INSECURE_SECURE_BOOT)","1")
bootloader:
@echo "Secure boot features are not yet mature, so the current secure bootloader will not properly secure the device"
@echo "If you flash this bootloader, you will be left with an non-updateable bootloader that is missing features."
@echo "If you really want to do this, set the environment variable IDF_INSECURE_SECURE_BOOT=1 and rerun make."
exit 1
else
# One time flashing requires user to run esptool.py command themselves,
# and warning is printed about inability to reflash.
#
# The flashing command is deliberately printed without an auto-reset
# step, so the device doesn't immediately reset to flash itself.
bootloader: $(BOOTLOADER_BIN)
@echo $(SEPARATOR)
@echo "Bootloader built. One-time flash command is:"
@echo "$(ESPTOOLPY_WRITE_FLASH) 0x1000 $(BOOTLOADER_BIN)"
@echo "$(subst hard_reset,no_reset,$(ESPTOOLPY_WRITE_FLASH)) $(BOOTLOADER_OFFSET) $(BOOTLOADER_BIN)"
@echo $(SEPARATOR)
@echo "* IMPORTANT: After first boot, BOOTLOADER CANNOT BE RE-FLASHED on same device"
endif # IDF_INSECURE_SECURE_BOOT
else ifdef CONFIG_SECURE_BOOTLOADER_REFLASHABLE
# Reflashable secure bootloader
# generates a digest binary (bootloader + digest)
#### TEMPORARILY DISABLE THIS OPTION
ifneq ("$(IDF_INSECURE_SECURE_BOOT)","1")
bootloader:
@echo "Secure boot features are not yet mature, so the current secure bootloader will not properly secure the device."
@echo "If using this feature, expect to reflash the bootloader at least one more time."
@echo "If you really want to do this, set the environment variable IDF_INSECURE_SECURE_BOOT=1 and rerun make."
exit 1
else
BOOTLOADER_DIGEST_BIN := $(BOOTLOADER_BUILD_DIR)/bootloader-reflash-digest.bin
SECURE_BOOTLOADER_KEY := $(BOOTLOADER_BUILD_DIR)/secure-bootloader-key.bin
ifdef CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES
$(SECURE_BOOTLOADER_KEY): $(SECURE_BOOT_SIGNING_KEY)
$(Q) $(ESPSECUREPY) digest_private_key -k $< $@
$(ESPSECUREPY) digest_private_key -k $< $@
else
$(SECURE_BOOTLOADER_KEY):
@echo "No pre-generated key for a reflashable secure bootloader is available, due to signing configuration."
@echo "To generate one, you can use this command:"
@echo "espsecure.py generate_flash_encryption_key $@"
@echo "then re-run make."
exit 1
endif
bootloader: $(BOOTLOADER_DIGEST_BIN)
@echo $(SEPARATOR)
@echo "Bootloader built and secure digest generated. First time flash command is:"
@echo "$(ESPEFUSEPY) burn_key secure_boot $(SECURE_BOOTLOADER_KEY)"
@echo "$(ESPTOOLPY_WRITE_FLASH) 0x1000 $(BOOTLOADER_BIN)"
@echo "$(ESPTOOLPY_WRITE_FLASH) $(BOOTLOADER_OFFSET) $(BOOTLOADER_BIN)"
@echo $(SEPARATOR)
@echo "To reflash the bootloader after initial flash:"
@echo "$(ESPTOOLPY_WRITE_FLASH) 0x0 $(BOOTLOADER_DIGEST_BIN)"
@@ -100,14 +96,16 @@ $(BOOTLOADER_DIGEST_BIN): $(BOOTLOADER_BIN) $(SECURE_BOOTLOADER_KEY)
@echo "DIGEST $(notdir $@)"
$(Q) $(ESPSECUREPY) digest_secure_bootloader -k $(SECURE_BOOTLOADER_KEY) -o $@ $<
endif # IDF_INSECURE_SECURE_BOOT
else
bootloader:
@echo "Invalid bootloader target: bad sdkconfig?"
@exit 1
endif
ifndef CONFIG_SECURE_BOOT_ENABLED
# don't build bootloader by default is secure boot is enabled
all_binaries: $(BOOTLOADER_BIN)
endif
bootloader-clean:
$(BOOTLOADER_MAKE) app-clean

View File

@@ -0,0 +1,4 @@
# Submodules normally added in component.mk, but fully qualified
# paths can be added at this level (we need binary librtc to be
# available to link bootloader).
COMPONENT_SUBMODULES += $(IDF_PATH)/components/esp32/lib

View File

@@ -23,7 +23,6 @@ extern "C"
#include "esp_flash_data_types.h"
#define BOOT_VERSION "V0.1"
#define SPI_SEC_SIZE 0x1000
#define IROM_LOW 0x400D0000
#define IROM_HIGH 0x40400000
@@ -34,20 +33,6 @@ extern "C"
#define RTC_DATA_LOW 0x50000000
#define RTC_DATA_HIGH 0x50002000
#define PART_TYPE_APP 0x00
#define PART_SUBTYPE_FACTORY 0x00
#define PART_SUBTYPE_OTA_FLAG 0x10
#define PART_SUBTYPE_OTA_MASK 0x0f
#define PART_SUBTYPE_TEST 0x20
#define PART_TYPE_DATA 0x01
#define PART_SUBTYPE_DATA_OTA 0x00
#define PART_SUBTYPE_DATA_RF 0x01
#define PART_SUBTYPE_DATA_WIFI 0x02
#define PART_TYPE_END 0xff
#define PART_SUBTYPE_END 0xff
#define SPI_ERROR_LOG "spi flash error"
typedef struct {

View File

@@ -23,6 +23,9 @@
#include "rom/spi_flash.h"
#include "rom/crc.h"
#include "rom/rtc.h"
#include "rom/uart.h"
#include "rom/gpio.h"
#include "rom/secure_boot.h"
#include "soc/soc.h"
#include "soc/cpu.h"
@@ -31,13 +34,18 @@
#include "soc/efuse_reg.h"
#include "soc/rtc_cntl_reg.h"
#include "soc/timer_group_reg.h"
#include "soc/gpio_reg.h"
#include "soc/gpio_sig_map.h"
#include "sdkconfig.h"
#include "esp_image_format.h"
#include "esp_secure_boot.h"
#include "esp_flash_encrypt.h"
#include "esp_flash_partitions.h"
#include "bootloader_flash.h"
#include "bootloader_random.h"
#include "bootloader_config.h"
#include "rtc.h"
extern int _bss_start;
extern int _bss_end;
@@ -54,7 +62,7 @@ extern void Cache_Flush(int);
void bootloader_main();
static void unpack_load_app(const esp_partition_pos_t *app_node);
void print_flash_info(const esp_image_header_t* pfhdr);
void set_cache_and_start_app(uint32_t drom_addr,
static void set_cache_and_start_app(uint32_t drom_addr,
uint32_t drom_load_addr,
uint32_t drom_size,
uint32_t irom_addr,
@@ -62,7 +70,7 @@ void set_cache_and_start_app(uint32_t drom_addr,
uint32_t irom_size,
uint32_t entry_addr);
static void update_flash_config(const esp_image_header_t* pfhdr);
static void uart_console_configure(void);
void IRAM_ATTR call_start_cpu0()
{
@@ -111,16 +119,14 @@ bool load_partition_table(bootloader_state_t* bs)
{
const esp_partition_info_t *partitions;
const int ESP_PARTITION_TABLE_DATA_LEN = 0xC00; /* length of actual data (signature is appended to this) */
const int MAX_PARTITIONS = ESP_PARTITION_TABLE_DATA_LEN / sizeof(esp_partition_info_t);
char *partition_usage;
esp_err_t err;
int num_partitions;
ESP_LOGI(TAG, "Partition Table:");
ESP_LOGI(TAG, "## Label Usage Type ST Offset Length");
#ifdef CONFIG_SECURE_BOOTLOADER_ENABLED
#ifdef CONFIG_SECURE_BOOT_ENABLED
if(esp_secure_boot_enabled()) {
ESP_LOGI(TAG, "Verifying partition table signature...");
esp_err_t err = esp_secure_boot_verify_signature(ESP_PARTITION_TABLE_ADDR, ESP_PARTITION_TABLE_DATA_LEN);
err = esp_secure_boot_verify_signature(ESP_PARTITION_TABLE_ADDR, ESP_PARTITION_TABLE_DATA_LEN);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to verify partition table signature.");
return false;
@@ -136,17 +142,21 @@ bool load_partition_table(bootloader_state_t* bs)
}
ESP_LOGD(TAG, "mapped partition table 0x%x at 0x%x", ESP_PARTITION_TABLE_ADDR, (intptr_t)partitions);
for(int i = 0; i < MAX_PARTITIONS; i++) {
err = esp_partition_table_basic_verify(partitions, true, &num_partitions);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to verify partition table");
return false;
}
ESP_LOGI(TAG, "Partition Table:");
ESP_LOGI(TAG, "## Label Usage Type ST Offset Length");
for(int i = 0; i < num_partitions; i++) {
const esp_partition_info_t *partition = &partitions[i];
ESP_LOGD(TAG, "load partition table entry 0x%x", (intptr_t)partition);
ESP_LOGD(TAG, "type=%x subtype=%x", partition->type, partition->subtype);
partition_usage = "unknown";
if (partition->magic != ESP_PARTITION_MAGIC) {
/* invalid partition definition indicates end-of-table */
break;
}
/* valid partition table */
switch(partition->type) {
case PART_TYPE_APP: /* app partition */
@@ -224,8 +234,18 @@ static bool ota_select_valid(const esp_ota_select_entry_t *s)
void bootloader_main()
{
ESP_LOGI(TAG, "Espressif ESP32 2nd stage bootloader v. %s", BOOT_VERSION);
/* Set CPU to 80MHz.
Start by ensuring it is set to XTAL, as PLL must be off first
(may still be on due to soft reset.)
*/
rtc_set_cpu_freq(CPU_XTAL);
rtc_set_cpu_freq(CPU_80M);
uart_console_configure();
ESP_LOGI(TAG, "ESP-IDF %s 2nd stage bootloader", IDF_VER);
#if defined(CONFIG_SECURE_BOOT_ENABLED) || defined(CONFIG_FLASH_ENCRYPTION_ENABLED)
esp_err_t err;
#endif
esp_image_header_t fhdr;
bootloader_state_t bs;
SpiFlashOpResult spiRet1,spiRet2;
@@ -240,7 +260,10 @@ void bootloader_main()
REG_CLR_BIT( TIMG_WDTCONFIG0_REG(0), TIMG_WDT_FLASHBOOT_MOD_EN );
SPIUnlock();
if(esp_image_load_header(0x1000, &fhdr) != ESP_OK) {
ESP_LOGI(TAG, "Enabling RNG early entropy source...");
bootloader_random_enable();
if(esp_image_load_header(0x1000, true, &fhdr) != ESP_OK) {
ESP_LOGE(TAG, "failed to load bootloader header!");
return;
}
@@ -258,7 +281,7 @@ void bootloader_main()
if (bs.ota_info.offset != 0) { // check if partition table has OTA info partition
//ESP_LOGE("OTA info sector handling is not implemented");
if (bs.ota_info.size < 2 * sizeof(esp_ota_select_entry_t)) {
if (bs.ota_info.size < 2 * SPI_SEC_SIZE) {
ESP_LOGE(TAG, "ERROR: ota_info partition size %d is too small (minimum %d bytes)", bs.ota_info.size, sizeof(esp_ota_select_entry_t));
return;
}
@@ -267,10 +290,9 @@ void bootloader_main()
ESP_LOGE(TAG, "bootloader_mmap(0x%x, 0x%x) failed", bs.ota_info.offset, bs.ota_info.size);
return;
}
sa = ota_select_map[0];
sb = ota_select_map[1];
memcpy(&sa, ota_select_map, sizeof(esp_ota_select_entry_t));
memcpy(&sb, (uint8_t *)ota_select_map + SPI_SEC_SIZE, sizeof(esp_ota_select_entry_t));
bootloader_munmap(ota_select_map);
if(sa.ota_seq == 0xFFFFFFFF && sb.ota_seq == 0xFFFFFFFF) {
// init status flash
if (bs.factory.offset != 0) { // if have factory bin,boot factory bin
@@ -301,12 +323,15 @@ void bootloader_main()
} else {
if(ota_select_valid(&sa) && ota_select_valid(&sb)) {
load_part_pos = bs.ota[(((sa.ota_seq > sb.ota_seq)?sa.ota_seq:sb.ota_seq) - 1)%bs.app_count];
}else if(ota_select_valid(&sa)) {
} else if(ota_select_valid(&sa)) {
load_part_pos = bs.ota[(sa.ota_seq - 1) % bs.app_count];
}else if(ota_select_valid(&sb)) {
} else if(ota_select_valid(&sb)) {
load_part_pos = bs.ota[(sb.ota_seq - 1) % bs.app_count];
}else {
ESP_LOGE(TAG, "ota data partition info error");
} else if (bs.factory.offset != 0) {
ESP_LOGE(TAG, "ota data partition invalid, falling back to factory");
load_part_pos = bs.factory;
} else {
ESP_LOGE(TAG, "ota data partition invalid and no factory, can't boot");
return;
}
}
@@ -319,12 +344,11 @@ void bootloader_main()
return;
}
ESP_LOGI(TAG, "Loading app partition at offset %08x", load_part_pos);
#ifdef CONFIG_SECURE_BOOTLOADER_ENABLED
#ifdef CONFIG_SECURE_BOOT_ENABLED
/* Generate secure digest from this bootloader to protect future
modifications */
esp_err_t err = esp_secure_boot_permanently_enable();
ESP_LOGI(TAG, "Checking secure boot...");
err = esp_secure_boot_permanently_enable();
if (err != ESP_OK) {
ESP_LOGE(TAG, "Bootloader digest generation failed (%d). SECURE BOOT IS NOT ENABLED.", err);
/* Allow booting to continue, as the failure is probably
@@ -333,19 +357,34 @@ void bootloader_main()
}
#endif
if(fhdr.encrypt_flag == 0x01) {
/* encrypt flash */
if (false == flash_encrypt(&bs)) {
ESP_LOGE(TAG, "flash encrypt failed");
return;
}
#ifdef CONFIG_FLASH_ENCRYPTION_ENABLED
/* encrypt flash */
ESP_LOGI(TAG, "Checking flash encryption...");
bool flash_encryption_enabled = esp_flash_encryption_enabled();
err = esp_flash_encrypt_check_and_update();
if (err != ESP_OK) {
ESP_LOGE(TAG, "Flash encryption check failed (%d).", err);
return;
}
if (!flash_encryption_enabled && esp_flash_encryption_enabled()) {
/* Flash encryption was just enabled for the first time,
so issue a system reset to ensure flash encryption
cache resets properly */
ESP_LOGI(TAG, "Resetting with flash encryption enabled...");
REG_WRITE(RTC_CNTL_OPTIONS0_REG, RTC_CNTL_SW_SYS_RST);
return;
}
#endif
ESP_LOGI(TAG, "Disabling RNG early entropy source...");
bootloader_random_disable();
// copy loaded segments to RAM, set up caches for mapped segments, and start application
ESP_LOGI(TAG, "Loading app partition at offset %08x", load_part_pos);
unpack_load_app(&load_part_pos);
}
static void unpack_load_app(const esp_partition_pos_t* partition)
{
esp_err_t err;
@@ -353,13 +392,13 @@ static void unpack_load_app(const esp_partition_pos_t* partition)
uint32_t image_length;
/* TODO: verify the app image as part of OTA boot decision, so can have fallbacks */
err = esp_image_basic_verify(partition->offset, &image_length);
err = esp_image_basic_verify(partition->offset, true, &image_length);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to verify app image @ 0x%x (%d)", partition->offset, err);
return;
}
#ifdef CONFIG_SECURE_BOOTLOADER_ENABLED
#ifdef CONFIG_SECURE_BOOT_ENABLED
if (esp_secure_boot_enabled()) {
ESP_LOGI(TAG, "Verifying app signature @ 0x%x (length 0x%x)", partition->offset, image_length);
err = esp_secure_boot_verify_signature(partition->offset, image_length);
@@ -371,7 +410,7 @@ static void unpack_load_app(const esp_partition_pos_t* partition)
}
#endif
if (esp_image_load_header(partition->offset, &image_header) != ESP_OK) {
if (esp_image_load_header(partition->offset, true, &image_header) != ESP_OK) {
ESP_LOGE(TAG, "Failed to load app image header @ 0x%x", partition->offset);
return;
}
@@ -393,12 +432,15 @@ static void unpack_load_app(const esp_partition_pos_t* partition)
image_header.spi_size,
(unsigned)image_header.entry_addr);
/* Important: From here on this function cannot access any global data (bss/data segments),
as loading the app image may overwrite these.
*/
for (int segment = 0; segment < image_header.segment_count; segment++) {
esp_image_segment_header_t segment_header;
uint32_t data_offs;
if(esp_image_load_segment_header(segment, partition->offset,
&image_header, &segment_header,
&data_offs) != ESP_OK) {
&image_header, true,
&segment_header, &data_offs) != ESP_OK) {
ESP_LOGE(TAG, "failed to load segment header #%d", segment);
return;
}
@@ -448,6 +490,31 @@ static void unpack_load_app(const esp_partition_pos_t* partition)
segment_header.load_addr, segment_header.data_len, segment_header.data_len, (load)?"load":(map)?"map":"");
if (load) {
intptr_t sp, start_addr, end_addr;
ESP_LOGV(TAG, "bootloader_mmap data_offs=%08x data_len=%08x", data_offs, segment_header.data_len);
start_addr = segment_header.load_addr;
end_addr = start_addr + segment_header.data_len;
/* Before loading segment, check it doesn't clobber
bootloader RAM... */
if (end_addr < 0x40000000) {
sp = (intptr_t)get_sp();
if (end_addr > sp) {
ESP_LOGE(TAG, "Segment %d end address %08x overlaps bootloader stack %08x - can't load",
segment, end_addr, sp);
return;
}
if (end_addr > sp - 256) {
/* We don't know for sure this is the stack high water mark, so warn if
it seems like we may overflow.
*/
ESP_LOGW(TAG, "Segment %d end address %08x close to stack pointer %08x",
segment, end_addr, sp);
}
}
const void *data = bootloader_mmap(data_offs, segment_header.data_len);
if(!data) {
ESP_LOGE(TAG, "bootloader_mmap(0x%xc, 0x%x) failed",
@@ -468,7 +535,7 @@ static void unpack_load_app(const esp_partition_pos_t* partition)
image_header.entry_addr);
}
void set_cache_and_start_app(
static void set_cache_and_start_app(
uint32_t drom_addr,
uint32_t drom_load_addr,
uint32_t drom_size,
@@ -616,3 +683,58 @@ void print_flash_info(const esp_image_header_t* phdr)
ESP_LOGI(TAG, "SPI Flash Size : %s", str );
#endif
}
static void uart_console_configure(void)
{
#if CONFIG_CONSOLE_UART_NONE
ets_install_putc1(NULL);
ets_install_putc2(NULL);
#else // CONFIG_CONSOLE_UART_NONE
const int uart_num = CONFIG_CONSOLE_UART_NUM;
uartAttach();
ets_install_uart_printf();
// ROM bootloader may have put a lot of text into UART0 FIFO.
// Wait for it to be printed.
uart_tx_wait_idle(0);
#if CONFIG_CONSOLE_UART_CUSTOM
// Some constants to make the following code less upper-case
const int uart_tx_gpio = CONFIG_CONSOLE_UART_TX_GPIO;
const int uart_rx_gpio = CONFIG_CONSOLE_UART_RX_GPIO;
// Switch to the new UART (this just changes UART number used for
// ets_printf in ROM code).
uart_tx_switch(uart_num);
// If console is attached to UART1 or if non-default pins are used,
// need to reconfigure pins using GPIO matrix
if (uart_num != 0 || uart_tx_gpio != 1 || uart_rx_gpio != 3) {
// Change pin mode for GPIO1/3 from UART to GPIO
PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0RXD_U, FUNC_U0RXD_GPIO3);
PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_U0TXD_GPIO1);
// Route GPIO signals to/from pins
// (arrays should be optimized away by the compiler)
const uint32_t tx_idx_list[3] = { U0TXD_OUT_IDX, U1TXD_OUT_IDX, U2TXD_OUT_IDX };
const uint32_t rx_idx_list[3] = { U0RXD_IN_IDX, U1RXD_IN_IDX, U2RXD_IN_IDX };
const uint32_t tx_idx = tx_idx_list[uart_num];
const uint32_t rx_idx = rx_idx_list[uart_num];
gpio_matrix_out(uart_tx_gpio, tx_idx, 0, 0);
gpio_matrix_in(uart_rx_gpio, rx_idx, 0);
}
#endif // CONFIG_CONSOLE_UART_CUSTOM
// Set configured UART console baud rate
const int uart_baud = CONFIG_CONSOLE_UART_BAUDRATE;
uart_div_modify(uart_num, (APB_CLK_FREQ << 4) / uart_baud);
#endif // CONFIG_CONSOLE_UART_NONE
}
/* empty rtc_printf implementation, to work with librtc
linking. Can be removed once -lrtc is removed from bootloader's
main component.mk.
*/
int rtc_printf(void)
{
return 0;
}

View File

@@ -5,5 +5,19 @@
# we pull in bootloader-specific linker arguments.
#
COMPONENT_ADD_LDFLAGS := -L $(COMPONENT_PATH) -lmain -T esp32.bootloader.ld -T $(IDF_PATH)/components/esp32/ld/esp32.rom.ld
LINKER_SCRIPTS := \
esp32.bootloader.ld \
$(IDF_PATH)/components/esp32/ld/esp32.rom.ld \
esp32.bootloader.rom.ld
COMPONENT_ADD_LDFLAGS := -L $(COMPONENT_PATH) -lmain $(addprefix -T ,$(LINKER_SCRIPTS))
COMPONENT_ADD_LINKER_DEPS := $(LINKER_SCRIPTS)
# following lines are a workaround to link librtc into the
# bootloader, until clock setting code is in a source-based esp-idf
# component. See also rtc_printf() in bootloader_start.c
#
# See also matching COMPONENT_SUBMODULES line in Makefile.projbuild
COMPONENT_ADD_LDFLAGS += -L $(IDF_PATH)/components/esp32/lib/ -lrtc_clk -lrtc
COMPONENT_EXTRA_INCLUDES += $(IDF_PATH)/components/esp32/

View File

@@ -17,7 +17,7 @@ MEMORY
dport0_seg (RW) : org = 0x3FF00000, len = 0x10 /* IO */
iram_seg (RWX) : org = 0x40080000, len = 0x400 /* 1k of IRAM used by bootloader functions which need to flush/enable APP CPU cache */
iram_pool_1_seg (RWX) : org = 0x40078000, len = 0x8000 /* IRAM POOL1, used for APP CPU cache. We can abuse it in bootloader because APP CPU is still held in reset, until we enable APP CPU cache */
dram_seg (RW) : org = 0x3FFC0000, len = 0x20000 /* Shared RAM, minus rom bss/data/stack.*/
dram_seg (RW) : org = 0x3FFF0000, len = 0x10000 /* 64k at the end of DRAM, after ROM bootloader stack */
}
/* Default entry point: */

View File

@@ -0,0 +1 @@
PROVIDE ( ets_update_cpu_frequency = 0x40008550 ); /* Updates g_ticks_per_us on the current CPU only; not on the other core */

View File

@@ -1,188 +0,0 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <string.h>
#include "esp_types.h"
#include "esp_attr.h"
#include "esp_log.h"
#include "esp_err.h"
#include "rom/cache.h"
#include "rom/ets_sys.h"
#include "rom/spi_flash.h"
#include "soc/dport_reg.h"
#include "soc/io_mux_reg.h"
#include "soc/efuse_reg.h"
#include "soc/rtc_cntl_reg.h"
#include "sdkconfig.h"
#include "bootloader_config.h"
#include "esp_image_format.h"
static const char* TAG = "flash_encrypt";
/**
* @function : bitcount
* @description: calculate bit 1 in flash_crypt_cnt
* if it's even number, need encrypt flash data, and burn efuse
*
* @inputs: n flash_crypt_cnt
* @return: number of 1 in flash_crypt_cnt
*
*/
int bitcount(int n){
int count = 0;
while (n > 0) {
count += n & 1;
n >>= 1;
}
return count;
}
/**
* @function : flash_encrypt_write
* @description: write encrypted data in flash
*
* @inputs: pos address in flash
* len size of data need encrypt
* @return: return true, if the write flash success
*
*/
bool flash_encrypt_write(uint32_t pos, uint32_t len)
{
SpiFlashOpResult spiRet;
uint32_t buf[1024];
int i = 0;
Cache_Read_Disable(0);
for (i = 0;i<((len-1)/0x1000 + 1);i++) {
spiRet = SPIRead(pos, buf, SPI_SEC_SIZE);
if (spiRet != SPI_FLASH_RESULT_OK) {
Cache_Read_Enable(0);
ESP_LOGE(TAG, SPI_ERROR_LOG);
return false;
}
spiRet = SPIEraseSector(pos/SPI_SEC_SIZE);
if (spiRet != SPI_FLASH_RESULT_OK) {
Cache_Read_Enable(0);
ESP_LOGE(TAG, SPI_ERROR_LOG);
return false;
}
spiRet = SPI_Encrypt_Write(pos, buf, SPI_SEC_SIZE);
if (spiRet != SPI_FLASH_RESULT_OK) {
Cache_Read_Enable(0);
ESP_LOGE(TAG, SPI_ERROR_LOG);
return false;
}
pos += SPI_SEC_SIZE;
}
Cache_Read_Enable(0);
return true;
}
/**
* @function : flash_encrypt
* @description: encrypt 2nd boot ,partition table ,factory bin <20><>test bin (if use)<29><>ota bin
* <20><>OTA info sector.
*
* @inputs: bs bootloader state structure used to save the data
*
* @return: return true, if the encrypt flash success
*
*/
bool flash_encrypt(bootloader_state_t *bs)
{
esp_err_t err;
uint32_t image_len = 0;
uint32_t flash_crypt_cnt = REG_GET_FIELD(EFUSE_BLK0_RDATA0_REG, EFUSE_FLASH_CRYPT_CNT);
uint8_t count = bitcount(flash_crypt_cnt);
ESP_LOGD(TAG, "flash encrypt cnt %x, bitcount %d", flash_crypt_cnt, count);
if ((count % 2) == 0) {
/* encrypt iv and abstract */
if (false == flash_encrypt_write(0, SPI_SEC_SIZE)) {
ESP_LOGE(TAG, "encrypt iv and abstract error");
return false;
}
/* encrypt bootloader image */
err = esp_image_basic_verify(0x1000, &image_len);
if(err == ESP_OK && image_len != 0) {
if (false == flash_encrypt_write(0x1000, image_len)) {
ESP_LOGE(TAG, "encrypt 2nd boot error");
return false;
}
} else {
ESP_LOGE(TAG, "2nd boot len error");
return false;
}
/* encrypt partition table */
if (false == flash_encrypt_write(ESP_PARTITION_TABLE_ADDR, SPI_SEC_SIZE)) {
ESP_LOGE(TAG, "encrypt partition table error");
return false;
}
/* encrypt write factory bin */
if(bs->factory.offset != 0 && bs->factory.size != 0) {
ESP_LOGD(TAG, "have factory bin");
if (false == flash_encrypt_write(bs->factory.offset, bs->factory.size)) {
ESP_LOGE(TAG, "encrypt factory bin error");
return false;
}
}
/* encrypt write test bin */
if(bs->test.offset != 0 && bs->test.size != 0) {
ESP_LOGD(TAG, "have test bin");
if (false == flash_encrypt_write(bs->test.offset, bs->test.size)) {
ESP_LOGE(TAG, "encrypt test bin error");
return false;
}
}
/* encrypt write ota bin */
for (int i = 0; i < 16; i++) {
if(bs->ota[i].offset != 0 && bs->ota[i].size != 0) {
ESP_LOGD(TAG, "have ota[%d] bin",i);
if (false == flash_encrypt_write(bs->ota[i].offset, bs->ota[i].size)) {
ESP_LOGE(TAG, "encrypt ota bin error");
return false;
}
}
}
/* encrypt write ota info bin */
if (false == flash_encrypt_write(bs->ota_info.offset, 2*SPI_SEC_SIZE)) {
ESP_LOGE(TAG, "encrypt ota info error");
return false;
}
REG_SET_FIELD(EFUSE_BLK0_WDATA0_REG, EFUSE_FLASH_CRYPT_CNT, 0x04);
REG_WRITE(EFUSE_CONF_REG, 0x5A5A); /* efuse_pgm_op_ena, force no rd/wr disable */
REG_WRITE(EFUSE_CMD_REG, 0x02); /* efuse_pgm_cmd */
while (REG_READ(EFUSE_CMD_REG)); /* wait for efuse_pagm_cmd=0 */
ESP_LOGW(TAG, "burn flash_crypt_cnt");
REG_WRITE(EFUSE_CONF_REG, 0x5AA5); /* efuse_read_op_ena, release force */
REG_WRITE(EFUSE_CMD_REG, 0x01); /* efuse_read_cmd */
while (REG_READ(EFUSE_CMD_REG)); /* wait for efuse_read_cmd=0 */
return true;
} else {
ESP_LOGI(TAG, "flash already encrypted.");
return true;
}
}

View File

@@ -0,0 +1,7 @@
$(SECURE_BOOT_SIGNING_KEY):
@echo "Need to generate secure boot signing key."
@echo "One way is to run this command:"
@echo "$(ESPSECUREPY) generate_signing_key $@"
@echo "Keep key file safe after generating."
@echo "(See secure boot documentation for risks & alternatives.)"
@exit 1

View File

@@ -12,21 +12,31 @@ COMPONENT_SRCDIRS := src
#
# Secure boot signing key support
#
ifdef CONFIG_SECURE_BOOTLOADER_ENABLED
ifdef CONFIG_SECURE_BOOT_ENABLED
# this path is created relative to the component build directory
SECURE_BOOT_VERIFICATION_KEY := $(abspath signature_verification_key.bin)
$(SECURE_BOOT_SIGNING_KEY):
@echo "Need to generate secure boot signing key."
@echo "One way is to run this command:"
@echo "$(ESPSECUREPY) generate_signing_key $@"
@echo "Keep key file safe after generating."
@echo "(See secure boot documentation for risks & alternatives.)"
@exit 1
$(SECURE_BOOT_VERIFICATION_KEY): $(SECURE_BOOT_SIGNING_KEY)
ifdef CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES
# verification key derived from signing key.
$(SECURE_BOOT_VERIFICATION_KEY): $(SECURE_BOOT_SIGNING_KEY) $(SDKCONFIG_MAKEFILE)
$(ESPSECUREPY) extract_public_key --keyfile $< $@
else
# find the configured public key file
ORIG_SECURE_BOOT_VERIFICATION_KEY := $(call resolvepath,$(call dequote,$(CONFIG_SECURE_BOOT_VERIFICATION_KEY)),$(PROJECT_PATH))
$(ORIG_SECURE_BOOT_VERIFICATION_KEY):
@echo "Secure boot verification public key '$@' missing."
@echo "This can be extracted from the private signing key, see"
@echo "docs/security/secure-boot.rst for details."
exit 1
# copy it into the build dir, so the secure boot verification key has
# a predictable file name
$(SECURE_BOOT_VERIFICATION_KEY): $(ORIG_SECURE_BOOT_VERIFICATION_KEY) $(SDKCONFIG_MAKEFILE)
$(summary) CP $< $@
cp $< $@
endif
COMPONENT_EXTRA_CLEAN += $(SECURE_BOOT_VERIFICATION_KEY)

View File

@@ -0,0 +1,56 @@
// 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_EFUSE_H
#define _ESP_EFUSE_H
#include "soc/efuse_reg.h"
#ifdef __cplusplus
extern "C" {
#endif
/* @brief Permanently update values written to the efuse write registers
*
* After updating EFUSE_BLKx_WDATAx_REG registers with new values to
* write, call this function to permanently write them to efuse.
*
* @note Setting bits in efuse is permanent, they cannot be unset.
*
* @note Due to this restriction you don't need to copy values to
* Efuse write registers from the matching read registers, bits which
* are set in the read register but unset in the matching write
* register will be unchanged when new values are burned.
*
* @note This function is not threadsafe, if calling code updates
* efuse values from multiple tasks then this is caller's
* responsibility to serialise.
*
* After burning new efuses, the read registers are updated to match
* the new efuse values.
*/
void esp_efuse_burn_new_values(void);
/* @brief Reset efuse write registers
*
* Efuse write registers are written to zero, to negate
* any changes that have been staged here.
*/
void esp_efuse_reset(void);
#ifdef __cplusplus
}
#endif
#endif /* __ESP_EFUSE_H */

View File

@@ -0,0 +1,102 @@
// 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 __ESP32_FLASH_ENCRYPT_H
#define __ESP32_FLASH_ENCRYPT_H
#include <stdbool.h>
#include "esp_attr.h"
#include "esp_err.h"
#include "esp_spi_flash.h"
#include "soc/efuse_reg.h"
/**
* @file esp_partition.h
* @brief Support functions for flash encryption features
*
* Can be compiled as part of app or bootloader code.
*/
/** @brief Is flash encryption currently enabled in hardware?
*
* Flash encryption is enabled if the FLASH_CRYPT_CNT efuse has an odd number of bits set.
*
* @return true if flash encryption is enabled.
*/
static inline IRAM_ATTR bool esp_flash_encryption_enabled(void) {
uint32_t flash_crypt_cnt = REG_GET_FIELD(EFUSE_BLK0_RDATA0_REG, EFUSE_RD_FLASH_CRYPT_CNT);
/* __builtin_parity is in flash, so we calculate parity inline */
bool enabled = false;
while(flash_crypt_cnt) {
if (flash_crypt_cnt & 1) {
enabled = !enabled;
}
flash_crypt_cnt >>= 1;
}
return enabled;
}
/* @brief Update on-device flash encryption
*
* Intended to be called as part of the bootloader process if flash
* encryption is enabled in device menuconfig.
*
* If FLASH_CRYPT_CNT efuse parity is 1 (ie odd number of bits set),
* then return ESP_OK immediately (indicating flash encryption is enabled
* and functional).
*
* If FLASH_CRYPT_CNT efuse parity is 0 (ie even number of bits set),
* assume the flash has just been written with plaintext that needs encrypting.
*
* The following regions of flash are encrypted in place:
*
* - The bootloader image, if a valid plaintext image is found.[*]
* - The partition table, if a valid plaintext table is found.
* - Any app partition that contains a valid plaintext app image.
* - Any other partitions with the "encrypt" flag set. [**]
*
* After the re-encryption process completes, a '1' bit is added to the
* FLASH_CRYPT_CNT value (setting the parity to 1) and the EFUSE is re-burned.
*
* [*] If reflashing bootloader with secure boot enabled, pre-encrypt
* the bootloader before writing it to flash or secure boot will fail.
*
* [**] For this reason, if serial re-flashing a previous flashed
* device with secure boot enabled and using FLASH_CRYPT_CNT to
* trigger re-encryption, you must simultaneously re-flash plaintext
* content to all partitions with the "encrypt" flag set or this
* data will be corrupted (encrypted twice).
*
* @note The post-condition of this function is that all
* partitions that should be encrypted are encrypted.
*
* @note Take care not to power off the device while this function
* is running, or the partition currently being encrypted will be lost.
*
* @return ESP_OK if all operations succeeded, ESP_ERR_INVALID_STATE
* if a fatal error occured during encryption of all partitions.
*/
esp_err_t esp_flash_encrypt_check_and_update(void);
/** @brief Encrypt-in-place a block of flash sectors
*
* @param src_addr Source offset in flash. Should be multiple of 4096 bytes.
* @param data_length Length of data to encrypt in bytes. Will be rounded up to next multiple of 4096 bytes.
*
* @return ESP_OK if all operations succeeded, ESP_ERR_FLASH_OP_FAIL
* if SPI flash fails, ESP_ERR_FLASH_OP_TIMEOUT if flash times out.
*/
esp_err_t esp_flash_encrypt_region(uint32_t src_addr, size_t data_length);
#endif

View File

@@ -0,0 +1,39 @@
// 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_FLASH_PARTITIONS_H
#define __ESP_FLASH_PARTITIONS_H
#include "esp_err.h"
#include "esp_flash_data_types.h"
#include <stdbool.h>
/* Pre-partition table fixed flash offsets */
#define ESP_BOOTLOADER_DIGEST_OFFSET 0x0
#define ESP_BOOTLOADER_OFFSET 0x1000 /* Offset of bootloader image. Has matching value in bootloader KConfig.projbuild file. */
#define ESP_PARTITION_TABLE_OFFSET 0x8000 /* Offset of partition table. Has matching value in partition_table Kconfig.projbuild file. */
#define ESP_PARTITION_TABLE_MAX_LEN 0xC00 /* Maximum length of partition table data */
#define ESP_PARTITION_TABLE_MAX_ENTRIES (ESP_PARTITION_TABLE_MAX_LEN / sizeof(esp_partition_info_t)) /* Maximum length of partition table data, including terminating entry */
/* @brief Verify the partition table (does not include verifying secure boot cryptographic signature)
*
* @param partition_table Pointer to at least ESP_PARTITION_TABLE_MAX_ENTRIES of potential partition table data. (ESP_PARTITION_TABLE_MAX_LEN bytes.)
* @param log_errors Log errors if the partition table is invalid.
* @param num_partitions If result is ESP_OK, num_partitions is updated with total number of partitions (not including terminating entry).
*
* @return ESP_OK on success, ESP_ERR_INVALID_STATE if partition table is not valid.
*/
esp_err_t esp_partition_table_basic_verify(const esp_partition_info_t *partition_table, bool log_errors, int *num_partitions);
#endif

View File

@@ -77,33 +77,40 @@ typedef struct {
/**
* @brief Read an ESP image header from flash.
*
* If encryption is enabled, data will be transparently decrypted.
*
* @param src_addr Address in flash to load image header. Must be 4 byte aligned.
* @param log_errors Log error output if image header appears invalid.
* @param[out] image_header Pointer to an esp_image_header_t struture to be filled with data. If the function fails, contents are undefined.
*
* @return ESP_OK if image header was loaded, ESP_ERR_IMAGE_FLASH_FAIL
* if a SPI flash error occurs, ESP_ERR_IMAGE_INVALID if the image header
* appears invalid.
*/
esp_err_t esp_image_load_header(uint32_t src_addr, esp_image_header_t *image_header);
esp_err_t esp_image_load_header(uint32_t src_addr, bool log_errors, esp_image_header_t *image_header);
/**
* @brief Read the segment header and data offset of a segment in the image.
*
* If encryption is enabled, data will be transparently decrypted.
*
* @param index Index of the segment to load information for.
* @param src_addr Base address in flash of the image.
* @param[in] image_header Pointer to the flash image header, already loaded by @ref esp_image_load_header().
* @param log_errors Log errors reading the segment header.
* @param[out] segment_header Pointer to a segment header structure to be filled with data. If the function fails, contents are undefined.
* @param[out] segment_data_offset Pointer to the data offset of the segment.
*
* @return ESP_OK if segment_header & segment_data_offset were loaded successfully, ESP_ERR_IMAGE_FLASH_FAIL if a SPI flash error occurs, ESP_ERR_IMAGE_INVALID if the image header appears invalid, ESP_ERR_INVALID_ARG if the index is invalid.
*/
esp_err_t esp_image_load_segment_header(uint8_t index, uint32_t src_addr, const esp_image_header_t *image_header, esp_image_segment_header_t *segment_header, uint32_t *segment_data_offset);
esp_err_t esp_image_load_segment_header(uint8_t index, uint32_t src_addr, const esp_image_header_t *image_header, bool log_errors, esp_image_segment_header_t *segment_header, uint32_t *segment_data_offset);
/**
* @brief Return length of an image in flash. Non-cryptographically validates image integrity in the process.
* @brief Non-cryptographically validate app image integrity. On success, length of image is provided to caller.
*
* If the image has a secure boot signature appended, the signature is not checked and this length is not included in the result.
* If the image has a secure boot signature appended, the signature is not checked and this length is not included in the
* output value.
*
* Image validation checks:
* - Magic byte
@@ -111,13 +118,17 @@ esp_err_t esp_image_load_segment_header(uint8_t index, uint32_t src_addr, const
* - Total image no longer than 16MB
* - 8 bit image checksum is valid
*
* If flash encryption is enabled, the image will be tranpsarently decrypted.
*
* @param src_addr Offset of the start of the image in flash. Must be 4 byte aligned.
* @param allow_decrypt If true and flash encryption is enabled, the image will be transparently decrypted.
* @param log_errors Log errors verifying the image.
* @param[out] length Length of the image, set to a value if the image is valid. Can be null.
*
* @return ESP_OK if image is valid, ESP_FAIL or ESP_ERR_IMAGE_INVALID on errors.
*
*/
esp_err_t esp_image_basic_verify(uint32_t src_addr, uint32_t *length);
esp_err_t esp_image_basic_verify(uint32_t src_addr, bool log_errors, uint32_t *length);
typedef struct {

View File

@@ -67,9 +67,25 @@ esp_err_t esp_secure_boot_permanently_enable(void);
* @param src_addr Starting offset of the data in flash.
* @param length Length of data in bytes. Signature is appended -after- length bytes.
*
* If flash encryption is enabled, the image will be transparently decrypted while being verified.
*
* @return ESP_OK if signature is valid, ESP_ERR_INVALID_STATE if
* signature fails, ESP_FAIL for other failures (ie can't read flash).
*/
esp_err_t esp_secure_boot_verify_signature(uint32_t src_addr, uint32_t length);
/** @brief Secure boot verification block, on-flash data format. */
typedef struct {
uint32_t version;
uint8_t signature[64];
} esp_secure_boot_sig_block_t;
#define FLASH_OFFS_SECURE_BOOT_IV_DIGEST 0
/** @brief Secure boot IV+digest header */
typedef struct {
uint8_t iv[128];
uint8_t digest[64];
} esp_secure_boot_iv_digest_t;
#endif

View File

@@ -18,6 +18,9 @@
#include <stdbool.h>
#include <stdint.h>
#include <esp_err.h>
#include "esp_spi_flash.h"
#define FLASH_SECTOR_SIZE 0x1000
/* Provide a Flash API for bootloader_support code,
that can be used from bootloader or app code.
@@ -56,14 +59,45 @@ void bootloader_munmap(const void *mapping);
/**
* @brief Read data from Flash.
*
* @note Both src and dest have to be 4-byte aligned.
*
* @note All of src, dest and size have to be 4-byte aligned.
*
* @param src source address of the data in Flash.
* @param dest pointer to the destination buffer
* @param size length of data
* @param allow_decrypt If true and flash encryption is enabled, data on flash
* will be decrypted transparently as part of the read.
*
* @return ESP_OK on success, ESP_ERR_FLASH_OP_FAIL on SPI failure,
* ESP_ERR_FLASH_OP_TIMEOUT on SPI timeout.
*/
esp_err_t bootloader_flash_read(size_t src_addr, void *dest, size_t size, bool allow_decrypt);
/**
* @brief Write data to Flash.
*
* @note All of dest_addr, src and size have to be 4-byte aligned. If write_encrypted is set, dest_addr and size must be 32-byte aligned.
*
* Note: In bootloader, when write_encrypted == true, the src buffer is encrypted in place.
*
* @param dest_addr Destination address to write in Flash.
* @param src Pointer to the data to write to flash
* @param size Length of data in bytes.
* @param write_encrypted If true, data will be written encrypted on flash.
*
* @return ESP_OK on success, ESP_ERR_FLASH_OP_FAIL on SPI failure,
* ESP_ERR_FLASH_OP_TIMEOUT on SPI timeout.
*/
esp_err_t bootloader_flash_write(size_t dest_addr, void *src, size_t size, bool write_encrypted);
/**
* @brief Erase the Flash sector.
*
* @param sector Sector number, the count starts at sector 0, 4KB per sector.
*
* @return esp_err_t
*/
esp_err_t bootloader_flash_read(size_t src_addr, void *dest, size_t size);
esp_err_t bootloader_flash_erase_sector(size_t sector);
#endif

View File

@@ -0,0 +1,49 @@
// Copyright 2010-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.
#pragma once
#include <stddef.h>
/**
* @brief Enable early entropy source for RNG
*
* Uses the SAR ADC to feed entropy into the HWRNG. The ADC is put
* into a test mode that reads the 1.1V internal reference source and
* feeds the LSB of data into the HWRNG.
*
* Can also be used from app code early during operation, if entropy
* is required before WiFi stack is initialised. Call this function
* from app code only if WiFi/BT are not yet enabled and I2S and SAR
* ADC are not in use.
*
* Call bootloader_random_disable() when done.
*/
void bootloader_random_enable(void);
/**
* @brief Disable early entropy source for RNG
*
* Disables SAR ADC source and resets the I2S hardware.
*
*/
void bootloader_random_disable(void);
/**
* @brief Fill buffer with 'length' random bytes
*
* @param buffer Pointer to buffer
* @param length This many bytes of random data will be copied to buffer
*/
void bootloader_fill_random(void *buffer, size_t length);

View File

@@ -16,6 +16,7 @@
#include <bootloader_flash.h>
#include <esp_log.h>
#include <esp_spi_flash.h> /* including in bootloader for error values */
#include <esp_flash_encrypt.h>
#ifndef BOOTLOADER_BUILD
/* Normal app version maps to esp_spi_flash.h operations...
@@ -46,38 +47,72 @@ void bootloader_munmap(const void *mapping)
map = 0;
}
esp_err_t bootloader_flash_read(size_t src, void *dest, size_t size)
esp_err_t bootloader_flash_read(size_t src, void *dest, size_t size, bool allow_decrypt)
{
return spi_flash_read(src, dest, size);
if (allow_decrypt && esp_flash_encryption_enabled()) {
return spi_flash_read_encrypted(src, dest, size);
} else {
return spi_flash_read(src, dest, size);
}
}
esp_err_t bootloader_flash_write(size_t dest_addr, void *src, size_t size, bool write_encrypted)
{
if (write_encrypted) {
return spi_flash_write_encrypted(dest_addr, src, size);
} else {
return spi_flash_write(dest_addr, src, size);
}
}
esp_err_t bootloader_flash_erase_sector(size_t sector)
{
return spi_flash_erase_sector(sector);
}
#else
/* Bootloader version, uses ROM functions only */
#include <soc/dport_reg.h>
#include <rom/spi_flash.h>
#include <rom/cache.h>
static const char *TAG = "bootloader_flash";
/* Use first 50 blocks in MMU for bootloader_mmap,
50th block for bootloader_flash_read
*/
#define MMU_BLOCK0_VADDR 0x3f400000
#define MMU_BLOCK50_VADDR 0x3f720000
#define MMU_FLASH_MASK 0xffff0000
#define MMU_BLOCK_SIZE 0x00010000
static bool mapped;
static uint32_t current_read_mapping = UINT32_MAX;
const void *bootloader_mmap(uint32_t src_addr, uint32_t size)
{
if (mapped) {
ESP_LOGE(TAG, "tried to bootloader_mmap twice");
return NULL; /* can't map twice */
}
if (size > 0x320000) {
/* Allow mapping up to 50 of the 51 available MMU blocks (last one used for reads) */
ESP_LOGE(TAG, "bootloader_mmap excess size %x", size);
return NULL;
}
uint32_t src_addr_aligned = src_addr & 0xffff0000;
uint32_t count = (size + (src_addr - src_addr_aligned) + 0xffff) / 0x10000;
uint32_t src_addr_aligned = src_addr & MMU_FLASH_MASK;
uint32_t count = (size + (src_addr - src_addr_aligned) + 0xffff) / MMU_BLOCK_SIZE;
Cache_Read_Disable(0);
Cache_Flush(0);
ESP_LOGD(TAG, "mmu set paddr=%08x count=%d", src_addr_aligned, count );
cache_flash_mmu_set( 0, 0, 0x3f400000, src_addr_aligned, 64, count );
cache_flash_mmu_set( 0, 0, MMU_BLOCK0_VADDR, src_addr_aligned, 64, count );
Cache_Read_Enable( 0 );
mapped = true;
return (void *)(0x3f400000 + (src_addr - src_addr_aligned));
return (void *)(MMU_BLOCK0_VADDR + (src_addr - src_addr_aligned));
}
void bootloader_munmap(const void *mapping)
@@ -88,25 +123,12 @@ void bootloader_munmap(const void *mapping)
Cache_Flush(0);
mmu_init(0);
mapped = false;
current_read_mapping = UINT32_MAX;
}
}
esp_err_t bootloader_flash_read(size_t src_addr, void *dest, size_t size)
static esp_err_t spi_to_esp_err(SpiFlashOpResult r)
{
if(src_addr & 3) {
ESP_LOGE(TAG, "bootloader_flash_read src_addr 0x%x not 4-byte aligned", src_addr);
return ESP_FAIL;
}
if((intptr_t)dest & 3) {
ESP_LOGE(TAG, "bootloader_flash_read dest 0x%x not 4-byte aligned", (intptr_t)dest);
return ESP_FAIL;
}
Cache_Read_Disable(0);
Cache_Flush(0);
SpiFlashOpResult r = SPIRead(src_addr, dest, size);
Cache_Read_Enable(0);
switch(r) {
case SPI_FLASH_RESULT_OK:
return ESP_OK;
@@ -119,4 +141,101 @@ esp_err_t bootloader_flash_read(size_t src_addr, void *dest, size_t size)
}
}
static esp_err_t bootloader_flash_read_no_decrypt(size_t src_addr, void *dest, size_t size)
{
Cache_Read_Disable(0);
Cache_Flush(0);
SpiFlashOpResult r = SPIRead(src_addr, dest, size);
Cache_Read_Enable(0);
return spi_to_esp_err(r);
}
static esp_err_t bootloader_flash_read_allow_decrypt(size_t src_addr, void *dest, size_t size)
{
uint32_t *dest_words = (uint32_t *)dest;
/* Use the 51st MMU mapping to read from flash in 64KB blocks.
(MMU will transparently decrypt if encryption is enabled.)
*/
for (int word = 0; word < size / 4; word++) {
uint32_t word_src = src_addr + word * 4; /* Read this offset from flash */
uint32_t map_at = word_src & MMU_FLASH_MASK; /* Map this 64KB block from flash */
uint32_t *map_ptr;
if (map_at != current_read_mapping) {
/* Move the 64KB mmu mapping window to fit map_at */
Cache_Read_Disable(0);
Cache_Flush(0);
ESP_LOGD(TAG, "mmu set block paddr=0x%08x (was 0x%08x)", map_at, current_read_mapping);
int e = cache_flash_mmu_set(0, 0, MMU_BLOCK50_VADDR, map_at, 64, 1);
if (e != 0) {
ESP_LOGE(TAG, "cache_flash_mmu_set failed: %d\n", e);
Cache_Read_Enable(0);
return ESP_FAIL;
}
current_read_mapping = map_at;
Cache_Read_Enable(0);
}
map_ptr = (uint32_t *)(MMU_BLOCK50_VADDR + (word_src - map_at));
dest_words[word] = *map_ptr;
}
return ESP_OK;
}
esp_err_t bootloader_flash_read(size_t src_addr, void *dest, size_t size, bool allow_decrypt)
{
if (src_addr & 3) {
ESP_LOGE(TAG, "bootloader_flash_read src_addr 0x%x not 4-byte aligned", src_addr);
return ESP_FAIL;
}
if (size & 3) {
ESP_LOGE(TAG, "bootloader_flash_read size 0x%x not 4-byte aligned", size);
return ESP_FAIL;
}
if ((intptr_t)dest & 3) {
ESP_LOGE(TAG, "bootloader_flash_read dest 0x%x not 4-byte aligned", (intptr_t)dest);
return ESP_FAIL;
}
if (allow_decrypt) {
return bootloader_flash_read_allow_decrypt(src_addr, dest, size);
} else {
return bootloader_flash_read_no_decrypt(src_addr, dest, size);
}
}
esp_err_t bootloader_flash_write(size_t dest_addr, void *src, size_t size, bool write_encrypted)
{
esp_err_t err;
size_t alignment = write_encrypted ? 32 : 4;
if ((dest_addr % alignment) != 0) {
ESP_LOGE(TAG, "bootloader_flash_write dest_addr 0x%x not %d-byte aligned", dest_addr, alignment);
return ESP_FAIL;
}
if ((size % alignment) != 0) {
ESP_LOGE(TAG, "bootloader_flash_write size 0x%x not %d-byte aligned", size, alignment);
return ESP_FAIL;
}
if (((intptr_t)src % 4) != 0) {
ESP_LOGE(TAG, "bootloader_flash_write src 0x%x not 4 byte aligned", (intptr_t)src);
return ESP_FAIL;
}
err = spi_to_esp_err(SPIUnlock());
if (err != ESP_OK) {
return err;
}
if (write_encrypted) {
return spi_to_esp_err(SPI_Encrypt_Write(dest_addr, src, size));
} else {
return spi_to_esp_err(SPIWrite(dest_addr, src, size));
}
}
esp_err_t bootloader_flash_erase_sector(size_t sector)
{
return spi_to_esp_err(SPIEraseSector(sector));
}
#endif

View File

@@ -0,0 +1,147 @@
// Copyright 2010-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 "bootloader_random.h"
#include "soc/cpu.h"
#include "soc/wdev_reg.h"
#include "soc/rtc_cntl_reg.h"
#include "soc/sens_reg.h"
#include "soc/syscon_reg.h"
#include "soc/dport_reg.h"
#include "soc/i2s_reg.h"
#include "esp_log.h"
#ifndef BOOTLOADER_BUILD
#include "esp_system.h"
#endif
const char *TAG = "boot_rng";
void bootloader_fill_random(void *buffer, size_t length)
{
uint8_t *buffer_bytes = (uint8_t *)buffer;
uint32_t random;
#ifdef BOOTLOADER_BUILD
uint32_t start, now;
#endif
for (int i = 0; i < length; i++) {
if (i == 0 || i % 4 == 0) { /* redundant check is for a compiler warning */
#ifdef BOOTLOADER_BUILD
/* in bootloader with ADC feeding HWRNG, we accumulate 1
bit of entropy per 40 APB cycles (==80 CPU cycles.)
To avoid reading the entire RNG hardware state out
as-is, we repeatedly read the RNG register and XOR all
values.
*/
random = REG_READ(WDEV_RND_REG);
RSR(CCOUNT, start);
do {
random ^= REG_READ(WDEV_RND_REG);
RSR(CCOUNT, now);
} while(now - start < 80*32*2); /* extra factor of 2 is precautionary */
#else
random = esp_random();
#endif
}
buffer_bytes[i] = random >> ((i % 4) * 8);
}
}
void bootloader_random_enable(void)
{
/* Ensure the hardware RNG is enabled following a soft reset. This should always be the case already (this clock is
never disabled while the CPU is running), this is a "belts and braces" type check.
*/
SET_PERI_REG_MASK(DPORT_WIFI_CLK_EN_REG, DPORT_WIFI_CLK_RNG_EN);
/* Enable SAR ADC in test mode to feed ADC readings of the 1.1V
reference via I2S into the RNG entropy input.
Note: I2S requires the PLL to be running, so the call to rtc_set_cpu_freq(CPU_80M)
in early bootloader startup must have been made.
*/
SET_PERI_REG_BITS(RTC_CNTL_TEST_MUX_REG, RTC_CNTL_DTEST_RTC, 2, RTC_CNTL_DTEST_RTC_S);
SET_PERI_REG_MASK(RTC_CNTL_TEST_MUX_REG, RTC_CNTL_ENT_RTC);
SET_PERI_REG_MASK(SENS_SAR_START_FORCE_REG, SENS_SAR2_EN_TEST);
SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_I2S0_CLK_EN);
CLEAR_PERI_REG_MASK(SENS_SAR_START_FORCE_REG, SENS_ULP_CP_FORCE_START_TOP);
CLEAR_PERI_REG_MASK(SENS_SAR_START_FORCE_REG, SENS_ULP_CP_START_TOP);
// Test pattern configuration byte 0xAD:
//--[7:4] channel_sel: 10-->en_test
//--[3:2] bit_width : 3-->12bit
//--[1:0] atten : 1-->3dB attenuation
WRITE_PERI_REG(SYSCON_SARADC_SAR2_PATT_TAB1_REG, 0xADADADAD);
WRITE_PERI_REG(SYSCON_SARADC_SAR2_PATT_TAB2_REG, 0xADADADAD);
WRITE_PERI_REG(SYSCON_SARADC_SAR2_PATT_TAB3_REG, 0xADADADAD);
WRITE_PERI_REG(SYSCON_SARADC_SAR2_PATT_TAB4_REG, 0xADADADAD);
SET_PERI_REG_BITS(SENS_SAR_MEAS_WAIT2_REG, SENS_FORCE_XPD_SAR, 3, SENS_FORCE_XPD_SAR_S);
SET_PERI_REG_MASK(SENS_SAR_READ_CTRL_REG, SENS_SAR1_DIG_FORCE);
SET_PERI_REG_MASK(SENS_SAR_READ_CTRL2_REG, SENS_SAR2_DIG_FORCE);
SET_PERI_REG_MASK(SYSCON_SARADC_CTRL_REG, SYSCON_SARADC_SAR2_MUX);
SET_PERI_REG_BITS(SYSCON_SARADC_CTRL_REG, SYSCON_SARADC_SAR_CLK_DIV, 4, SYSCON_SARADC_SAR_CLK_DIV_S);
SET_PERI_REG_BITS(SYSCON_SARADC_FSM_REG, SYSCON_SARADC_RSTB_WAIT, 8, SYSCON_SARADC_RSTB_WAIT_S); /* was 1 */
SET_PERI_REG_BITS(SYSCON_SARADC_FSM_REG, SYSCON_SARADC_START_WAIT, 10, SYSCON_SARADC_START_WAIT_S);
SET_PERI_REG_BITS(SYSCON_SARADC_CTRL_REG, SYSCON_SARADC_WORK_MODE, 0, SYSCON_SARADC_WORK_MODE_S);
SET_PERI_REG_MASK(SYSCON_SARADC_CTRL_REG, SYSCON_SARADC_SAR_SEL);
CLEAR_PERI_REG_MASK(SYSCON_SARADC_CTRL_REG, SYSCON_SARADC_DATA_SAR_SEL);
SET_PERI_REG_BITS(I2S_SAMPLE_RATE_CONF_REG(0), I2S_RX_BCK_DIV_NUM, 20, I2S_RX_BCK_DIV_NUM_S);
SET_PERI_REG_MASK(SYSCON_SARADC_CTRL_REG,SYSCON_SARADC_DATA_TO_I2S);
CLEAR_PERI_REG_MASK(I2S_CONF2_REG(0), I2S_CAMERA_EN);
SET_PERI_REG_MASK(I2S_CONF2_REG(0), I2S_LCD_EN);
SET_PERI_REG_MASK(I2S_CONF2_REG(0), I2S_DATA_ENABLE);
SET_PERI_REG_MASK(I2S_CONF2_REG(0), I2S_DATA_ENABLE_TEST_EN);
SET_PERI_REG_MASK(I2S_CONF_REG(0), I2S_RX_START);
}
void bootloader_random_disable(void)
{
/* Disable i2s clock */
CLEAR_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_I2S0_CLK_EN);
/* Reset some i2s configuration (possibly redundant as we reset entire
I2S peripheral further down). */
CLEAR_PERI_REG_MASK(I2S_CONF2_REG(0), I2S_CAMERA_EN);
CLEAR_PERI_REG_MASK(I2S_CONF2_REG(0), I2S_LCD_EN);
CLEAR_PERI_REG_MASK(I2S_CONF2_REG(0), I2S_DATA_ENABLE_TEST_EN);
CLEAR_PERI_REG_MASK(I2S_CONF2_REG(0), I2S_DATA_ENABLE);
CLEAR_PERI_REG_MASK(I2S_CONF_REG(0), I2S_RX_START);
/* Restore SYSCON mode registers */
CLEAR_PERI_REG_MASK(SENS_SAR_READ_CTRL_REG, SENS_SAR1_DIG_FORCE);
CLEAR_PERI_REG_MASK(SENS_SAR_READ_CTRL2_REG, SENS_SAR2_DIG_FORCE);
/* Restore SAR ADC mode */
CLEAR_PERI_REG_MASK(SENS_SAR_START_FORCE_REG, SENS_SAR2_EN_TEST);
CLEAR_PERI_REG_MASK(SYSCON_SARADC_CTRL_REG, SYSCON_SARADC_SAR2_MUX
| SYSCON_SARADC_SAR_SEL | SYSCON_SARADC_DATA_TO_I2S);
SET_PERI_REG_BITS(SENS_SAR_MEAS_WAIT2_REG, SENS_FORCE_XPD_SAR, 0, SENS_FORCE_XPD_SAR_S);
SET_PERI_REG_BITS(SYSCON_SARADC_FSM_REG, SYSCON_SARADC_START_WAIT, 8, SYSCON_SARADC_START_WAIT_S);
/* Reset i2s peripheral */
SET_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_I2S0_RST);
CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_I2S0_RST);
/* Disable pull supply voltage to SAR ADC */
CLEAR_PERI_REG_MASK(RTC_CNTL_TEST_MUX_REG, RTC_CNTL_ENT_RTC);
SET_PERI_REG_BITS(RTC_CNTL_TEST_MUX_REG, RTC_CNTL_DTEST_RTC, 0, RTC_CNTL_DTEST_RTC_S);
}

View File

@@ -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.
#include "esp_efuse.h"
#define EFUSE_CONF_WRITE 0x5A5A /* efuse_pgm_op_ena, force no rd/wr disable */
#define EFUSE_CONF_READ 0x5AA5 /* efuse_read_op_ena, release force */
#define EFUSE_CMD_PGM 0x02
#define EFUSE_CMD_READ 0x01
void esp_efuse_burn_new_values(void)
{
REG_WRITE(EFUSE_CONF_REG, EFUSE_CONF_WRITE);
REG_WRITE(EFUSE_CMD_REG, EFUSE_CMD_PGM);
while (REG_READ(EFUSE_CMD_REG) != 0) {
}
REG_WRITE(EFUSE_CONF_REG, EFUSE_CONF_READ);
REG_WRITE(EFUSE_CMD_REG, EFUSE_CMD_READ);
while (REG_READ(EFUSE_CMD_REG) != 0) {
}
esp_efuse_reset();
}
void esp_efuse_reset(void)
{
REG_WRITE(EFUSE_CONF_REG, EFUSE_CONF_READ);
const uint32_t block_start[4] = { EFUSE_BLK0_WDATA0_REG, EFUSE_BLK1_WDATA0_REG,
EFUSE_BLK2_WDATA0_REG, EFUSE_BLK3_WDATA0_REG };
const uint32_t block_end[4] = { EFUSE_BLK0_WDATA6_REG, EFUSE_BLK1_WDATA7_REG,
EFUSE_BLK2_WDATA7_REG, EFUSE_BLK3_WDATA7_REG };
for (int i = 0; i < 4; i++) {
for (uint32_t r = block_start[i]; r <= block_end[i]; r+= 4) {
REG_WRITE(r, 0);
}
}
}

View File

@@ -22,26 +22,30 @@ static const char *TAG = "esp_image";
#define SIXTEEN_MB 0x1000000
#define ESP_ROM_CHECKSUM_INITIAL 0xEF
esp_err_t esp_image_load_header(uint32_t src_addr, esp_image_header_t *image_header)
esp_err_t esp_image_load_header(uint32_t src_addr, bool log_errors, esp_image_header_t *image_header)
{
esp_err_t err;
ESP_LOGD(TAG, "reading image header @ 0x%x", src_addr);
err = bootloader_flash_read(src_addr, image_header, sizeof(esp_image_header_t));
err = bootloader_flash_read(src_addr, image_header, sizeof(esp_image_header_t), true);
if (err == ESP_OK) {
if (image_header->magic != ESP_IMAGE_HEADER_MAGIC) {
ESP_LOGE(TAG, "image at 0x%x has invalid magic byte", src_addr);
if (log_errors) {
ESP_LOGE(TAG, "image at 0x%x has invalid magic byte", src_addr);
}
err = ESP_ERR_IMAGE_INVALID;
}
if (image_header->spi_mode > ESP_IMAGE_SPI_MODE_SLOW_READ) {
ESP_LOGW(TAG, "image at 0x%x has invalid SPI mode %d", src_addr, image_header->spi_mode);
}
if (image_header->spi_speed > ESP_IMAGE_SPI_SPEED_80M) {
ESP_LOGW(TAG, "image at 0x%x has invalid SPI speed %d", src_addr, image_header->spi_speed);
}
if (image_header->spi_size > ESP_IMAGE_FLASH_SIZE_MAX) {
ESP_LOGW(TAG, "image at 0x%x has invalid SPI size %d", src_addr, image_header->spi_size);
if (log_errors) {
if (image_header->spi_mode > ESP_IMAGE_SPI_MODE_SLOW_READ) {
ESP_LOGW(TAG, "image at 0x%x has invalid SPI mode %d", src_addr, image_header->spi_mode);
}
if (image_header->spi_speed > ESP_IMAGE_SPI_SPEED_80M) {
ESP_LOGW(TAG, "image at 0x%x has invalid SPI speed %d", src_addr, image_header->spi_speed);
}
if (image_header->spi_size > ESP_IMAGE_FLASH_SIZE_MAX) {
ESP_LOGW(TAG, "image at 0x%x has invalid SPI size %d", src_addr, image_header->spi_size);
}
}
}
@@ -51,23 +55,27 @@ esp_err_t esp_image_load_header(uint32_t src_addr, esp_image_header_t *image_hea
return err;
}
esp_err_t esp_image_load_segment_header(uint8_t index, uint32_t src_addr, const esp_image_header_t *image_header, esp_image_segment_header_t *segment_header, uint32_t *segment_data_offset)
esp_err_t esp_image_load_segment_header(uint8_t index, uint32_t src_addr, const esp_image_header_t *image_header, bool log_errors, esp_image_segment_header_t *segment_header, uint32_t *segment_data_offset)
{
esp_err_t err = ESP_OK;
uint32_t next_addr = src_addr + sizeof(esp_image_header_t);
if(index >= image_header->segment_count) {
ESP_LOGE(TAG, "index %d higher than segment count %d", index, image_header->segment_count);
if (log_errors) {
ESP_LOGE(TAG, "index %d higher than segment count %d", index, image_header->segment_count);
}
return ESP_ERR_INVALID_ARG;
}
for(int i = 0; i <= index && err == ESP_OK; i++) {
ESP_LOGV(TAG, "loading segment header %d at offset 0x%x", i, next_addr);
err = bootloader_flash_read(next_addr, segment_header, sizeof(esp_image_segment_header_t));
err = bootloader_flash_read(next_addr, segment_header, sizeof(esp_image_segment_header_t), true);
if (err == ESP_OK) {
if ((segment_header->data_len & 3) != 0
|| segment_header->data_len >= SIXTEEN_MB) {
ESP_LOGE(TAG, "invalid segment length 0x%x", segment_header->data_len);
if (log_errors) {
ESP_LOGE(TAG, "invalid segment length 0x%x", segment_header->data_len);
}
err = ESP_ERR_IMAGE_INVALID;
}
next_addr += sizeof(esp_image_segment_header_t);
@@ -85,15 +93,14 @@ esp_err_t esp_image_load_segment_header(uint8_t index, uint32_t src_addr, const
return err;
}
esp_err_t esp_image_basic_verify(uint32_t src_addr, uint32_t *p_length)
esp_err_t esp_image_basic_verify(uint32_t src_addr, bool log_errors, uint32_t *p_length)
{
esp_err_t err;
uint8_t buf[16];
uint8_t buf[128];
uint8_t checksum = ESP_ROM_CHECKSUM_INITIAL;
esp_image_header_t image_header;
esp_image_segment_header_t segment_header = { 0 };
uint32_t segment_data_offs = 0;
const uint8_t *segment_data;
uint32_t end_addr;
uint32_t length;
@@ -101,7 +108,7 @@ esp_err_t esp_image_basic_verify(uint32_t src_addr, uint32_t *p_length)
*p_length = 0;
}
err = esp_image_load_header(src_addr, &image_header);
err = esp_image_load_header(src_addr, log_errors, &image_header);
if (err != ESP_OK) {
return err;
}
@@ -110,34 +117,38 @@ esp_err_t esp_image_basic_verify(uint32_t src_addr, uint32_t *p_length)
/* Checksum each segment's data */
for (int i = 0; i < image_header.segment_count; i++) {
err = esp_image_load_segment_header(i, src_addr, &image_header,
err = esp_image_load_segment_header(i, src_addr, &image_header, log_errors,
&segment_header, &segment_data_offs);
if (err != ESP_OK) {
return err;
}
segment_data = bootloader_mmap(segment_data_offs, segment_header.data_len);
if (segment_data == NULL) {
ESP_LOGE(TAG, "bootloader_mmap(0x%x, 0x%x) failed", segment_data_offs, segment_header.data_len);
return ESP_FAIL;
for (int i = 0; i < segment_header.data_len; i += sizeof(buf)) {
err = bootloader_flash_read(segment_data_offs + i, buf, sizeof(buf), true);
if (err != ESP_OK) {
return err;
}
for (int j = 0; j < sizeof(buf) && i + j < segment_header.data_len; j++) {
checksum ^= buf[j];
}
}
for(int i = 0; i < segment_header.data_len; i++) {
checksum ^= segment_data[i];
}
bootloader_munmap(segment_data);
}
/* End of image, verify checksum */
end_addr = segment_data_offs + segment_header.data_len;
if (end_addr < src_addr) {
ESP_LOGE(TAG, "image offset has wrapped");
if (log_errors) {
ESP_LOGE(TAG, "image offset has wrapped");
}
return ESP_ERR_IMAGE_INVALID;
}
length = end_addr - src_addr;
if (length >= SIXTEEN_MB) {
ESP_LOGE(TAG, "invalid total length 0x%x", length);
if (log_errors) {
ESP_LOGE(TAG, "invalid total length 0x%x", length);
}
return ESP_ERR_IMAGE_INVALID;
}
@@ -147,10 +158,12 @@ esp_err_t esp_image_basic_verify(uint32_t src_addr, uint32_t *p_length)
length = length - (length % 16);
ESP_LOGV(TAG, "padded image length 0x%x", length);
ESP_LOGD(TAG, "reading checksum block at 0x%x", src_addr + length - 16);
bootloader_flash_read(src_addr + length - 16, buf, 16);
bootloader_flash_read(src_addr + length - 16, buf, 16, true);
if (checksum != buf[15]) {
ESP_LOGE(TAG, "checksum failed. Calculated 0x%x read 0x%x",
checksum, buf[15]);
if (log_errors) {
ESP_LOGE(TAG, "checksum failed. Calculated 0x%x read 0x%x",
checksum, buf[15]);
}
return ESP_ERR_IMAGE_INVALID;
}

View File

@@ -0,0 +1,339 @@
// 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 <strings.h>
#include "bootloader_flash.h"
#include "bootloader_random.h"
#include "esp_image_format.h"
#include "esp_flash_encrypt.h"
#include "esp_flash_partitions.h"
#include "esp_flash_data_types.h"
#include "esp_secure_boot.h"
#include "esp_efuse.h"
#include "esp_log.h"
#include "rom/secure_boot.h"
#include "rom/cache.h"
#include "rom/spi_flash.h" /* TODO: Remove this */
static const char *TAG = "flash_encrypt";
/* Static functions for stages of flash encryption */
static esp_err_t initialise_flash_encryption(void);
static esp_err_t encrypt_flash_contents(uint32_t flash_crypt_cnt, bool flash_crypt_wr_dis);
static esp_err_t encrypt_bootloader();
static esp_err_t encrypt_and_load_partition_table(esp_partition_info_t *partition_table, int *num_partitions);
static esp_err_t encrypt_partition(int index, const esp_partition_info_t *partition);
esp_err_t esp_flash_encrypt_check_and_update(void)
{
uint32_t efuse_blk0 = REG_READ(EFUSE_BLK0_RDATA0_REG);
ESP_LOGV(TAG, "efuse_blk0 raw value %08x", efuse_blk0);
uint32_t flash_crypt_cnt = (efuse_blk0 & EFUSE_RD_FLASH_CRYPT_CNT_M) >> EFUSE_RD_FLASH_CRYPT_CNT_S;
bool flash_crypt_wr_dis = efuse_blk0 & EFUSE_WR_DIS_FLASH_CRYPT_CNT;
ESP_LOGV(TAG, "efuse FLASH_CRYPT_CNT 0x%x WR_DIS_FLASH_CRYPT_CNT 0x%x", flash_crypt_cnt, flash_crypt_wr_dis);
if (__builtin_parity(flash_crypt_cnt) == 1) {
/* Flash is already encrypted */
int left = (7 - __builtin_popcount(flash_crypt_cnt)) / 2;
if (flash_crypt_wr_dis) {
left = 0; /* can't update FLASH_CRYPT_CNT, no more flashes */
}
ESP_LOGI(TAG, "flash encryption is enabled (%d plaintext flashes left)", left);
return ESP_OK;
}
else {
/* Flash is not encrypted, so encrypt it! */
return encrypt_flash_contents(flash_crypt_cnt, flash_crypt_wr_dis);
}
}
static esp_err_t initialise_flash_encryption(void)
{
/* Before first flash encryption pass, need to initialise key & crypto config */
/* Generate key */
uint32_t dis_reg = REG_READ(EFUSE_BLK0_RDATA0_REG);
bool efuse_key_read_protected = dis_reg & EFUSE_RD_DIS_BLK1;
bool efuse_key_write_protected = dis_reg & EFUSE_WR_DIS_BLK1;
if (efuse_key_read_protected == false
&& efuse_key_write_protected == false
&& REG_READ(EFUSE_BLK1_RDATA0_REG) == 0
&& REG_READ(EFUSE_BLK1_RDATA1_REG) == 0
&& REG_READ(EFUSE_BLK1_RDATA2_REG) == 0
&& REG_READ(EFUSE_BLK1_RDATA3_REG) == 0
&& REG_READ(EFUSE_BLK1_RDATA4_REG) == 0
&& REG_READ(EFUSE_BLK1_RDATA5_REG) == 0
&& REG_READ(EFUSE_BLK1_RDATA6_REG) == 0
&& REG_READ(EFUSE_BLK1_RDATA7_REG) == 0) {
ESP_LOGI(TAG, "Generating new flash encryption key...");
uint32_t buf[8];
bootloader_fill_random(buf, sizeof(buf));
for (int i = 0; i < 8; i++) {
ESP_LOGV(TAG, "EFUSE_BLK1_WDATA%d_REG = 0x%08x", i, buf[i]);
REG_WRITE(EFUSE_BLK1_WDATA0_REG + 4*i, buf[i]);
}
bzero(buf, sizeof(buf));
esp_efuse_burn_new_values();
ESP_LOGI(TAG, "Read & write protecting new key...");
REG_WRITE(EFUSE_BLK0_WDATA0_REG, EFUSE_WR_DIS_BLK1 | EFUSE_RD_DIS_BLK1);
esp_efuse_burn_new_values();
} else {
if(!(efuse_key_read_protected && efuse_key_write_protected)) {
ESP_LOGE(TAG, "Flash encryption key has to be either unset or both read and write protected");
return ESP_ERR_INVALID_STATE;
}
ESP_LOGW(TAG, "Using pre-loaded flash encryption key in EFUSE block 1");
}
/* CRYPT_CONFIG determines which bits of the AES block key are XORed
with bits from the flash address, to provide the key tweak.
CRYPT_CONFIG == 0 is effectively AES ECB mode (NOT SUPPORTED)
For now this is hardcoded to XOR all 256 bits of the key.
If you need to override it, you can pre-burn this efuse to the
desired value and then write-protect it, in which case this
operation does nothing. Please note this is not recommended!
*/
ESP_LOGI(TAG, "Setting CRYPT_CONFIG efuse to 0xF");
REG_WRITE(EFUSE_BLK0_WDATA5_REG, EFUSE_FLASH_CRYPT_CONFIG_M);
esp_efuse_burn_new_values();
uint32_t new_wdata6 = 0;
#ifndef CONFIG_FLASH_ENCRYPTION_UART_BOOTLOADER_ALLOW_ENCRYPT
ESP_LOGI(TAG, "Disable UART bootloader encryption...");
new_wdata6 |= EFUSE_DISABLE_DL_ENCRYPT;
#else
ESP_LOGW(TAG, "Not disabling UART bootloader encryption");
#endif
#ifndef CONFIG_FLASH_ENCRYPTION_UART_BOOTLOADER_ALLOW_DECRYPT
ESP_LOGI(TAG, "Disable UART bootloader decryption...");
new_wdata6 |= EFUSE_DISABLE_DL_DECRYPT;
#else
ESP_LOGW(TAG, "Not disabling UART bootloader decryption - SECURITY COMPROMISED");
#endif
#ifndef CONFIG_FLASH_ENCRYPTION_UART_BOOTLOADER_ALLOW_CACHE
ESP_LOGI(TAG, "Disable UART bootloader MMU cache...");
new_wdata6 |= EFUSE_DISABLE_DL_CACHE;
#else
ESP_LOGW(TAG, "Not disabling UART bootloader MMU cache - SECURITY COMPROMISED");
#endif
#ifndef CONFIG_SECURE_BOOT_ALLOW_JTAG
ESP_LOGI(TAG, "Disable JTAG...");
new_wdata6 |= EFUSE_RD_DISABLE_JTAG;
#else
ESP_LOGW(TAG, "Not disabling JTAG - SECURITY COMPROMISED");
#endif
if (new_wdata6 != 0) {
REG_WRITE(EFUSE_BLK0_WDATA6_REG, new_wdata6);
esp_efuse_burn_new_values();
}
return ESP_OK;
}
/* Encrypt all flash data that should be encrypted */
static esp_err_t encrypt_flash_contents(uint32_t flash_crypt_cnt, bool flash_crypt_wr_dis)
{
esp_err_t err;
esp_partition_info_t partition_table[ESP_PARTITION_TABLE_MAX_ENTRIES];
int num_partitions;
/* If the last flash_crypt_cnt bit is burned or write-disabled, the
device can't re-encrypt itself. */
if (flash_crypt_wr_dis || flash_crypt_cnt == 0xFF) {
ESP_LOGE(TAG, "Cannot re-encrypt data (FLASH_CRYPT_CNT 0x%02x write disabled %d", flash_crypt_cnt, flash_crypt_wr_dis);
return ESP_FAIL;
}
if (flash_crypt_cnt == 0) {
/* Very first flash of encrypted data: generate keys, etc. */
err = initialise_flash_encryption();
if (err != ESP_OK) {
return err;
}
}
err = encrypt_bootloader();
if (err != ESP_OK) {
return err;
}
err = encrypt_and_load_partition_table(partition_table, &num_partitions);
if (err != ESP_OK) {
return err;
}
/* Now iterate the just-loaded partition table, looking for entries to encrypt
*/
/* Go through each partition and encrypt if necessary */
for (int i = 0; i < num_partitions; i++) {
err = encrypt_partition(i, &partition_table[i]);
if (err != ESP_OK) {
return err;
}
}
ESP_LOGD(TAG, "All flash regions checked for encryption pass");
/* Set least significant 0-bit in flash_crypt_cnt */
int ffs_inv = __builtin_ffs((~flash_crypt_cnt) & 0xFF);
/* ffs_inv shouldn't be zero, as zero implies flash_crypt_cnt == 0xFF */
uint32_t new_flash_crypt_cnt = flash_crypt_cnt + (1 << (ffs_inv - 1));
ESP_LOGD(TAG, "FLASH_CRYPT_CNT 0x%x -> 0x%x", flash_crypt_cnt, new_flash_crypt_cnt);
REG_SET_FIELD(EFUSE_BLK0_WDATA0_REG, EFUSE_FLASH_CRYPT_CNT, new_flash_crypt_cnt);
esp_efuse_burn_new_values();
ESP_LOGI(TAG, "Flash encryption completed");
return ESP_OK;
}
static esp_err_t encrypt_bootloader()
{
esp_err_t err;
uint32_t image_length;
/* Check for plaintext bootloader */
if (esp_image_basic_verify(ESP_BOOTLOADER_OFFSET, false, &image_length) == ESP_OK) {
ESP_LOGD(TAG, "bootloader is plaintext. Encrypting...");
err = esp_flash_encrypt_region(ESP_BOOTLOADER_OFFSET, image_length);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to encrypt bootloader in place: 0x%x", err);
return err;
}
if (esp_secure_boot_enabled()) {
/* If secure boot is enabled and bootloader was plaintext, also
need to encrypt secure boot IV+digest.
*/
ESP_LOGD(TAG, "Encrypting secure bootloader IV & digest...");
err = esp_flash_encrypt_region(FLASH_OFFS_SECURE_BOOT_IV_DIGEST,
FLASH_SECTOR_SIZE);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to encrypt bootloader IV & digest in place: 0x%x", err);
return err;
}
}
}
else {
ESP_LOGW(TAG, "no valid bootloader was found");
}
return ESP_OK;
}
static esp_err_t encrypt_and_load_partition_table(esp_partition_info_t *partition_table, int *num_partitions)
{
esp_err_t err;
/* Check for plaintext partition table */
err = bootloader_flash_read(ESP_PARTITION_TABLE_OFFSET, partition_table, ESP_PARTITION_TABLE_MAX_LEN, false);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to read partition table data");
return err;
}
if (esp_partition_table_basic_verify(partition_table, false, num_partitions) == ESP_OK) {
ESP_LOGD(TAG, "partition table is plaintext. Encrypting...");
esp_err_t err = esp_flash_encrypt_region(ESP_PARTITION_TABLE_OFFSET,
FLASH_SECTOR_SIZE);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to encrypt partition table in place. %x", err);
return err;
}
}
else {
ESP_LOGE(TAG, "Failed to read partition table data - not plaintext?");
return ESP_ERR_INVALID_STATE;
}
/* Valid partition table loded */
return ESP_OK;
}
static esp_err_t encrypt_partition(int index, const esp_partition_info_t *partition)
{
esp_err_t err;
uint32_t image_len = partition->pos.size;
bool should_encrypt = (partition->flags & PART_FLAG_ENCRYPTED);
if (partition->type == PART_TYPE_APP) {
/* check if the partition holds an unencrypted app */
if (esp_image_basic_verify(partition->pos.offset, false, &image_len) == ESP_OK) {
if(image_len > partition->pos.size) {
ESP_LOGE(TAG, "partition entry %d has image longer than partition (%d vs %d)", index, image_len, partition->pos.size);
should_encrypt = false;
} else {
should_encrypt = true;
}
} else {
should_encrypt = false;
}
} else if (partition->type == PART_TYPE_DATA && partition->subtype == PART_SUBTYPE_DATA_OTA) {
/* check if we have ota data partition and the partition should be encrypted unconditionally */
should_encrypt = true;
}
if (!should_encrypt) {
return ESP_OK;
}
else {
/* should_encrypt */
ESP_LOGI(TAG, "Encrypting partition %d at offset 0x%x...", index, partition->pos.offset);
err = esp_flash_encrypt_region(partition->pos.offset, partition->pos.size);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to encrypt partition %d", index);
}
return err;
}
}
esp_err_t esp_flash_encrypt_region(uint32_t src_addr, size_t data_length)
{
esp_err_t err;
uint32_t buf[FLASH_SECTOR_SIZE / sizeof(uint32_t)];
if (src_addr % FLASH_SECTOR_SIZE != 0) {
ESP_LOGE(TAG, "esp_flash_encrypt_region bad src_addr 0x%x",src_addr);
return ESP_FAIL;
}
for (size_t i = 0; i < data_length; i += FLASH_SECTOR_SIZE) {
uint32_t sec_start = i + src_addr;
err = bootloader_flash_read(sec_start, buf, FLASH_SECTOR_SIZE, false);
if (err != ESP_OK) {
goto flash_failed;
}
err = bootloader_flash_erase_sector(sec_start / FLASH_SECTOR_SIZE);
if (err != ESP_OK) {
goto flash_failed;
}
err = bootloader_flash_write(sec_start, buf, FLASH_SECTOR_SIZE, true);
if (err != ESP_OK) {
goto flash_failed;
}
}
return ESP_OK;
flash_failed:
ESP_LOGE(TAG, "flash operation failed: 0x%x", err);
return err;
}

View File

@@ -0,0 +1,60 @@
// 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 "esp_flash_partitions.h"
#include "esp_log.h"
#include "rom/spi_flash.h"
static const char *TAG = "flash_parts";
esp_err_t esp_partition_table_basic_verify(const esp_partition_info_t *partition_table, bool log_errors, int *num_partitions)
{
int num_parts;
uint32_t chip_size = g_rom_flashchip.chip_size;
*num_partitions = 0;
for(num_parts = 0; num_parts < ESP_PARTITION_TABLE_MAX_ENTRIES; num_parts++) {
const esp_partition_info_t *part = &partition_table[num_parts];
if (part->magic == 0xFFFF
&& part->type == PART_TYPE_END
&& part->subtype == PART_SUBTYPE_END) {
/* TODO: check md5 */
ESP_LOGD(TAG, "partition table verified, %d entries", num_parts);
*num_partitions = num_parts;
return ESP_OK;
}
if (part->magic != ESP_PARTITION_MAGIC) {
if (log_errors) {
ESP_LOGE(TAG, "partition %d invalid magic number 0x%x", num_parts, part->magic);
}
return ESP_ERR_INVALID_STATE;
}
const esp_partition_pos_t *pos = &part->pos;
if (pos->offset > chip_size || pos->offset + pos->size > chip_size) {
if (log_errors) {
ESP_LOGE(TAG, "partition %d invalid - offset 0x%x size 0x%x exceeds flash chip size 0x%x",
num_parts, pos->offset, pos->size, chip_size);
}
return ESP_ERR_INVALID_SIZE;
}
}
if (log_errors) {
ESP_LOGE(TAG, "partition table has no terminating entry, not valid");
}
return ESP_ERR_INVALID_STATE;
}

View File

@@ -20,7 +20,6 @@
#include "rom/cache.h"
#include "rom/ets_sys.h"
#include "rom/spi_flash.h"
#include "rom/secure_boot.h"
#include "soc/dport_reg.h"
@@ -31,15 +30,14 @@
#include "sdkconfig.h"
#include "bootloader_flash.h"
#include "bootloader_random.h"
#include "esp_image_format.h"
#include "esp_secure_boot.h"
#include "esp_flash_encrypt.h"
#include "esp_efuse.h"
static const char* TAG = "secure_boot";
#define HASH_BLOCK_SIZE 128
#define IV_LEN HASH_BLOCK_SIZE
#define DIGEST_LEN 64
/**
* @function : secure_boot_generate
* @description: generate boot digest (aka "abstract") & iv
@@ -47,39 +45,26 @@ static const char* TAG = "secure_boot";
* @inputs: image_len - length of image to calculate digest for
*/
static bool secure_boot_generate(uint32_t image_len){
SpiFlashOpResult spiRet;
/* buffer is uint32_t not uint8_t to meet ROM SPI API signature */
uint32_t buf[IV_LEN / sizeof(uint32_t)];
const void *image;
esp_err_t err;
esp_secure_boot_iv_digest_t digest;
const uint32_t *image;
/* hardware secure boot engine only takes full blocks, so round up the
image length. The additional data should all be 0xFF.
*/
if (image_len % HASH_BLOCK_SIZE != 0) {
image_len = (image_len / HASH_BLOCK_SIZE + 1) * HASH_BLOCK_SIZE;
if (image_len % sizeof(digest.iv) != 0) {
image_len = (image_len / sizeof(digest.iv) + 1) * sizeof(digest.iv);
}
ets_secure_boot_start();
ets_secure_boot_rd_iv(buf);
ets_secure_boot_rd_iv((uint32_t *)digest.iv);
ets_secure_boot_hash(NULL);
Cache_Read_Disable(0);
/* iv stored in sec 0 */
spiRet = SPIEraseSector(0);
if (spiRet != SPI_FLASH_RESULT_OK)
err = bootloader_flash_erase_sector(0);
if (err != ESP_OK)
{
ESP_LOGE(TAG, "SPI erase failed %d", spiRet);
ESP_LOGE(TAG, "SPI erase failed: 0x%x", err);
return false;
}
Cache_Read_Enable(0);
/* write iv to flash, 0x0000, 128 bytes (1024 bits) */
ESP_LOGD(TAG, "write iv to flash.");
spiRet = SPIWrite(0, buf, IV_LEN);
if (spiRet != SPI_FLASH_RESULT_OK)
{
ESP_LOGE(TAG, "SPI write failed %d", spiRet);
return false;
}
bzero(buf, sizeof(buf));
/* generate digest from image contents */
image = bootloader_mmap(0x1000, image_len);
@@ -87,22 +72,22 @@ static bool secure_boot_generate(uint32_t image_len){
ESP_LOGE(TAG, "bootloader_mmap(0x1000, 0x%x) failed", image_len);
return false;
}
for (int i = 0; i < image_len; i+= HASH_BLOCK_SIZE) {
ets_secure_boot_hash(image + i/sizeof(void *));
for (int i = 0; i < image_len; i+= sizeof(digest.iv)) {
ets_secure_boot_hash(&image[i/sizeof(uint32_t)]);
}
bootloader_munmap(image);
ets_secure_boot_obtain();
ets_secure_boot_rd_abstract(buf);
ets_secure_boot_rd_abstract((uint32_t *)digest.digest);
ets_secure_boot_finish();
ESP_LOGD(TAG, "write digest to flash.");
spiRet = SPIWrite(0x80, buf, DIGEST_LEN);
if (spiRet != SPI_FLASH_RESULT_OK) {
ESP_LOGE(TAG, "SPI write failed %d", spiRet);
ESP_LOGD(TAG, "write iv+digest to flash");
err = bootloader_flash_write(FLASH_OFFS_SECURE_BOOT_IV_DIGEST, &digest,
sizeof(digest), esp_flash_encryption_enabled());
if (err != ESP_OK) {
ESP_LOGE(TAG, "SPI write failed: 0x%x", err);
return false;
}
ESP_LOGD(TAG, "write digest to flash.");
Cache_Read_Enable(0);
return true;
}
@@ -111,14 +96,9 @@ static bool secure_boot_generate(uint32_t image_len){
static inline void burn_efuses()
{
#ifdef CONFIG_SECURE_BOOT_TEST_MODE
ESP_LOGE(TAG, "SECURE BOOT TEST MODE. Not really burning any efuses!");
ESP_LOGE(TAG, "SECURE BOOT TEST MODE. Not really burning any efuses! NOT SECURE");
#else
REG_WRITE(EFUSE_CONF_REG, 0x5A5A); /* efuse_pgm_op_ena, force no rd/wr disable */
REG_WRITE(EFUSE_CMD_REG, 0x02); /* efuse_pgm_cmd */
while (REG_READ(EFUSE_CMD_REG)); /* wait for efuse_pagm_cmd=0 */
REG_WRITE(EFUSE_CONF_REG, 0x5AA5); /* efuse_read_op_ena, release force */
REG_WRITE(EFUSE_CMD_REG, 0x01); /* efuse_read_cmd */
while (REG_READ(EFUSE_CMD_REG)); /* wait for efuse_read_cmd=0 */
esp_efuse_burn_new_values();
#endif
}
@@ -131,7 +111,7 @@ esp_err_t esp_secure_boot_permanently_enable(void) {
return ESP_OK;
}
err = esp_image_basic_verify(0x1000, &image_len);
err = esp_image_basic_verify(0x1000, true, &image_len);
if (err != ESP_OK) {
ESP_LOGE(TAG, "bootloader image appears invalid! error %d", err);
return err;
@@ -151,12 +131,8 @@ esp_err_t esp_secure_boot_permanently_enable(void) {
&& REG_READ(EFUSE_BLK2_RDATA6_REG) == 0
&& REG_READ(EFUSE_BLK2_RDATA7_REG) == 0) {
ESP_LOGI(TAG, "Generating new secure boot key...");
/* reuse the secure boot IV generation function to generate
the key, as this generator uses the hardware RNG. */
uint32_t buf[32];
ets_secure_boot_start();
ets_secure_boot_rd_iv(buf);
ets_secure_boot_finish();
uint32_t buf[8];
bootloader_fill_random(buf, sizeof(buf));
for (int i = 0; i < 8; i++) {
ESP_LOGV(TAG, "EFUSE_BLK2_WDATA%d_REG = 0x%08x", i, buf[i]);
REG_WRITE(EFUSE_BLK2_WDATA0_REG + 4*i, buf[i]);
@@ -180,6 +156,7 @@ esp_err_t esp_secure_boot_permanently_enable(void) {
}
ESP_LOGI(TAG, "Digest generation complete.");
#ifndef CONFIG_SECURE_BOOT_TEST_MODE
if (!efuse_key_read_protected) {
ESP_LOGE(TAG, "Pre-loaded key is not read protected. Refusing to blow secure boot efuse.");
return ESP_ERR_INVALID_STATE;
@@ -188,21 +165,26 @@ esp_err_t esp_secure_boot_permanently_enable(void) {
ESP_LOGE(TAG, "Pre-loaded key is not write protected. Refusing to blow secure boot efuse.");
return ESP_ERR_INVALID_STATE;
}
#endif
ESP_LOGI(TAG, "blowing secure boot efuse...");
ESP_LOGD(TAG, "before updating, EFUSE_BLK0_RDATA6 %x", REG_READ(EFUSE_BLK0_RDATA6_REG));
uint32_t new_wdata6 = EFUSE_RD_ABS_DONE_0;
#ifdef CONFIG_SECURE_BOOT_DISABLE_JTAG
ESP_LOGI(TAG, "disabling JTAG...");
#ifndef CONFIG_SECURE_BOOT_ALLOW_JTAG
ESP_LOGI(TAG, "Disable JTAG...");
new_wdata6 |= EFUSE_RD_DISABLE_JTAG;
#endif
#else
ESP_LOGW(TAG, "Not disabling JTAG - SECURITY COMPROMISED");
#endif
#ifdef CONFIG_SECURE_BOOT_DISABLE_UART_BOOTLOADER
ESP_LOGI(TAG, "disabling UART bootloader...");
new_wdata6 |= EFUSE_RD_CONSOLE_DEBUG_DISABLE_S;
#endif
#ifndef CONFIG_SECURE_BOOT_ALLOW_ROM_BASIC
ESP_LOGI(TAG, "Disable ROM BASIC interpreter fallback...");
new_wdata6 |= EFUSE_RD_CONSOLE_DEBUG_DISABLE;
#else
ESP_LOGW(TAG, "Not disabling ROM BASIC fallback - SECURITY COMPROMISED");
#endif
REG_WRITE(EFUSE_BLK0_WDATA6_REG, new_wdata6);
burn_efuses();

View File

@@ -27,11 +27,6 @@ typedef SHA_CTX sha_context;
#include "hwcrypto/sha.h"
#endif
typedef struct {
uint32_t version;
uint8_t signature[64];
} signature_block_t;
static const char* TAG = "secure_boot";
extern const uint8_t signature_verification_key_start[] asm("_binary_signature_verification_key_bin_start");
@@ -47,7 +42,7 @@ esp_err_t esp_secure_boot_verify_signature(uint32_t src_addr, uint32_t length)
uint8_t digest[32];
ptrdiff_t keylen;
const uint8_t *data;
const signature_block_t *sigblock;
const esp_secure_boot_sig_block_t *sigblock;
bool is_valid;
#ifdef BOOTLOADER_BUILD
const uint8_t *digest_data;
@@ -56,13 +51,13 @@ esp_err_t esp_secure_boot_verify_signature(uint32_t src_addr, uint32_t length)
ESP_LOGD(TAG, "verifying signature src_addr 0x%x length 0x%x", src_addr, length);
data = bootloader_mmap(src_addr, length + sizeof(signature_block_t));
data = bootloader_mmap(src_addr, length + sizeof(esp_secure_boot_sig_block_t));
if(data == NULL) {
ESP_LOGE(TAG, "bootloader_mmap(0x%x, 0x%x) failed", src_addr, length+sizeof(signature_block_t));
ESP_LOGE(TAG, "bootloader_mmap(0x%x, 0x%x) failed", src_addr, length+sizeof(esp_secure_boot_sig_block_t));
return ESP_FAIL;
}
sigblock = (const signature_block_t *)(data + length);
sigblock = (const esp_secure_boot_sig_block_t *)(data + length);
if (sigblock->version != 0) {
ESP_LOGE(TAG, "src 0x%x has invalid signature version field 0x%08x", src_addr, sigblock->version);

View File

@@ -1,35 +1,33 @@
menu "BT config"
visible if MEMMAP_BT
config BT_ENABLED
bool
depends on ESP32_ENABLE_STACK_BT
menuconfig BT_ENABLED
bool "Bluetooth"
help
This compiles in the low-level BT stack.
Select this option to enable Bluetooth stack and show the submenu with Bluetooth configuration choices.
config BTC_TASK_STACK_SIZE
int "BT event (callback to application) task stack size"
default 2048
int "Bluetooth event (callback to application) task stack size"
depends on BT_ENABLED
default 3072
help
This select btc task stack size
#config BT_BTLE
# bool "Enable BTLE"
# depends on BT_ENABLED
# help
# This compiles BTLE support
#
#config BT_BT
# bool "Enable classic BT"
# depends on BT_ENABLED
# help
# This enables classic BT support
config BLUEDROID_MEM_DEBUG
bool "Bluedroid memory debug"
depends on BT_ENABLED
default n
help
Bluedroid memory debug
endmenu
config BT_DRAM_RELEASE
bool "Release DRAM from Classic BT controller"
depends on BT_ENABLED
default n
help
This option should only be used when BLE only.
Open this option will release about 30K DRAM from Classic BT.
The released DRAM will be used as system heap memory.
# Memory reserved at start of DRAM for Bluetooth stack
config BT_RESERVE_DRAM
hex
default 0x10000 if MEMMAP_BT
default 0x10000 if BT_ENABLED
default 0

View File

@@ -22,22 +22,38 @@
#include "btc_main.h"
#include "future.h"
esp_err_t esp_blufi_register_callback(esp_profile_cb_t callback)
esp_err_t esp_blufi_register_callbacks(esp_blufi_callbacks_t *callbacks)
{
return (btc_profile_cb_set(BTC_PID_BLUFI, callback) == 0 ? ESP_OK : ESP_FAIL);
if (esp_bluedroid_get_status() == ESP_BLUEDROID_STATUS_UNINITIALIZED) {
return ESP_ERR_INVALID_STATE;
}
if (callbacks == NULL) {
return ESP_FAIL;
}
btc_blufi_set_callbacks(callbacks);
return (btc_profile_cb_set(BTC_PID_BLUFI, callbacks->event_cb) == 0 ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_blufi_send_config_state(esp_blufi_config_state_t state)
esp_err_t esp_blufi_send_wifi_conn_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)
{
btc_msg_t msg;
btc_blufi_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_BLUFI;
msg.act = BTC_BLUFI_ACT_SEND_CFG_STATE;
arg.cfg_state.state = state;
msg.act = BTC_BLUFI_ACT_SEND_CFG_REPORT;
arg.wifi_conn_report.opmode = opmode;
arg.wifi_conn_report.sta_conn_state = sta_conn_state;
arg.wifi_conn_report.softap_conn_num = softap_conn_num;
arg.wifi_conn_report.extra_info = extra_info;
return (btc_transfer_context(&msg, &arg, sizeof(btc_blufi_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
return (btc_transfer_context(&msg, &arg, sizeof(btc_blufi_args_t), btc_blufi_call_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
@@ -45,6 +61,10 @@ esp_err_t esp_blufi_profile_init(void)
{
btc_msg_t msg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_BLUFI;
msg.act = BTC_BLUFI_ACT_INIT;
@@ -56,6 +76,10 @@ esp_err_t esp_blufi_profile_deinit(void)
{
btc_msg_t msg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_BLUFI;
msg.act = BTC_BLUFI_ACT_DEINIT;
@@ -63,4 +87,8 @@ esp_err_t esp_blufi_profile_deinit(void)
return (btc_transfer_context(&msg, NULL, 0, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
uint16_t esp_blufi_get_version(void)
{
return btc_blufi_get_version();
}

View File

@@ -0,0 +1,26 @@
// 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 "esp_bt_device.h"
#include "esp_bt_main.h"
#include "controller.h"
const uint8_t *esp_bt_dev_get_address(void)
{
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return NULL;
}
return controller_get_interface()->get_address()->address;
}

View File

@@ -16,25 +16,44 @@
#include "esp_bt_main.h"
#include "btc_task.h"
#include "btc_main.h"
#include "bt.h"
#include "future.h"
static bool esp_already_enable = false;
static bool esp_already_init = false;
static bool bd_already_enable = false;
static bool bd_already_init = false;
esp_err_t esp_enable_bluetooth(void)
esp_bluedroid_status_t esp_bluedroid_get_status(void)
{
if (bd_already_init) {
if (bd_already_enable) {
return ESP_BLUEDROID_STATUS_ENABLED;
} else {
return ESP_BLUEDROID_STATUS_INITIALIZED;
}
} else {
return ESP_BLUEDROID_STATUS_UNINITIALIZED;
}
}
esp_err_t esp_bluedroid_enable(void)
{
btc_msg_t msg;
future_t **future_p;
if (esp_already_enable) {
LOG_ERROR("%s already enable\n", __func__);
if (!bd_already_init) {
LOG_ERROR("Bludroid not initialised\n");
return ESP_ERR_INVALID_STATE;
}
if (bd_already_enable) {
LOG_ERROR("Bluedroid already enabled\n");
return ESP_ERR_INVALID_STATE;
}
future_p = btc_main_get_future_p(BTC_MAIN_ENABLE_FUTURE);
*future_p = future_new();
if (*future_p == NULL) {
LOG_ERROR("%s failed\n", __func__);
LOG_ERROR("Bluedroid enable failed\n");
return ESP_ERR_NO_MEM;
}
@@ -44,29 +63,29 @@ esp_err_t esp_enable_bluetooth(void)
btc_transfer_context(&msg, NULL, 0, NULL);
if (future_await(*future_p) == FUTURE_FAIL) {
LOG_ERROR("%s failed\n", __func__);
LOG_ERROR("Bluedroid enable failed\n");
return ESP_FAIL;
}
esp_already_enable = true;
bd_already_enable = true;
return ESP_OK;
}
esp_err_t esp_disable_bluetooth(void)
esp_err_t esp_bluedroid_disable(void)
{
btc_msg_t msg;
future_t **future_p;
if (!esp_already_enable) {
LOG_ERROR("%s already disable\n", __func__);
if (!bd_already_enable) {
LOG_ERROR("Bluedroid already disabled\n");
return ESP_ERR_INVALID_STATE;
}
future_p = btc_main_get_future_p(BTC_MAIN_DISABLE_FUTURE);
*future_p = future_new();
if (*future_p == NULL) {
LOG_ERROR("%s failed\n", __func__);
LOG_ERROR("Bluedroid disable failed\n");
return ESP_ERR_NO_MEM;
}
@@ -76,29 +95,34 @@ esp_err_t esp_disable_bluetooth(void)
btc_transfer_context(&msg, NULL, 0, NULL);
if (future_await(*future_p) == FUTURE_FAIL) {
LOG_ERROR("%s failed\n", __func__);
LOG_ERROR("Bluedroid disable failed\n");
return ESP_FAIL;
}
esp_already_enable = false;
bd_already_enable = false;
return ESP_OK;
}
esp_err_t esp_init_bluetooth(void)
esp_err_t esp_bluedroid_init(void)
{
btc_msg_t msg;
future_t **future_p;
if (esp_already_init) {
LOG_ERROR("%s already init\n", __func__);
if (esp_bt_controller_get_status() != ESP_BT_CONTROLLER_STATUS_ENABLED) {
LOG_ERROR("Conroller not initialised\n");
return ESP_ERR_INVALID_STATE;
}
if (bd_already_init) {
LOG_ERROR("Bluedroid already initialised\n");
return ESP_ERR_INVALID_STATE;
}
future_p = btc_main_get_future_p(BTC_MAIN_INIT_FUTURE);
*future_p = future_new();
if (*future_p == NULL) {
LOG_ERROR("%s failed\n", __func__);
LOG_ERROR("Bluedroid initialise failed\n");
return ESP_ERR_NO_MEM;
}
@@ -110,30 +134,35 @@ esp_err_t esp_init_bluetooth(void)
btc_transfer_context(&msg, NULL, 0, NULL);
if (future_await(*future_p) == FUTURE_FAIL) {
LOG_ERROR("%s failed\n", __func__);
LOG_ERROR("Bluedroid initialise failed\n");
return ESP_FAIL;
}
esp_already_init = true;;
bd_already_init = true;
return ESP_OK;
}
esp_err_t esp_deinit_bluetooth(void)
esp_err_t esp_bluedroid_deinit(void)
{
btc_msg_t msg;
future_t **future_p;
if (!esp_already_init) {
LOG_ERROR("%s already deinit\n", __func__);
if (!bd_already_init) {
LOG_ERROR("Bluedroid already de-initialised\n");
return ESP_ERR_INVALID_STATE;
}
if (bd_already_enable) {
LOG_ERROR("Bludroid already enabled, do disable first\n");
return ESP_ERR_INVALID_STATE;
}
future_p = btc_main_get_future_p(BTC_MAIN_DEINIT_FUTURE);
*future_p = future_new();
if (*future_p == NULL) {
LOG_ERROR("%s failed\n", __func__);
LOG_ERROR("Bluedroid de-initialise failed\n");
return ESP_ERR_NO_MEM;
}
@@ -143,15 +172,14 @@ esp_err_t esp_deinit_bluetooth(void)
btc_transfer_context(&msg, NULL, 0, NULL);
if (future_await(*future_p) == FUTURE_FAIL) {
LOG_ERROR("%s failed\n", __func__);
LOG_ERROR("Bluedroid de-initialise failed\n");
return ESP_FAIL;
}
btc_deinit();
esp_already_init = false;
bd_already_init = false;
return ESP_OK;
}

View File

@@ -14,6 +14,7 @@
#include <string.h>
#include "esp_bt_main.h"
#include "esp_gap_ble_api.h"
#include "bta_api.h"
#include "bt_trace.h"
@@ -21,8 +22,11 @@
#include "btc_gap_ble.h"
esp_err_t esp_ble_gap_register_callback(esp_profile_cb_t callback)
esp_err_t esp_ble_gap_register_callback(esp_gap_ble_cb_t callback)
{
if (esp_bluedroid_get_status() == ESP_BLUEDROID_STATUS_UNINITIALIZED) {
return ESP_ERR_INVALID_STATE;
}
return (btc_profile_cb_set(BTC_PID_GAP_BLE, callback) == 0 ? ESP_OK : ESP_FAIL);
}
@@ -31,7 +35,11 @@ esp_err_t esp_ble_gap_config_adv_data(esp_ble_adv_data_t *adv_data)
{
btc_msg_t msg;
btc_ble_gap_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
if (adv_data == NULL) {
return ESP_ERR_INVALID_ARG;
}
@@ -54,7 +62,11 @@ esp_err_t esp_ble_gap_set_scan_params(esp_ble_scan_params_t *scan_params)
{
btc_msg_t msg;
btc_ble_gap_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
if (scan_params == NULL) {
return ESP_ERR_INVALID_ARG;
}
@@ -72,6 +84,10 @@ esp_err_t esp_ble_gap_start_scanning(uint32_t duration)
btc_msg_t msg;
btc_ble_gap_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BLE;
msg.act = BTC_GAP_BLE_ACT_START_SCAN;
@@ -84,8 +100,11 @@ esp_err_t esp_ble_gap_start_scanning(uint32_t duration)
esp_err_t esp_ble_gap_stop_scanning(void)
{
btc_msg_t msg;
btc_ble_gap_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BLE;
msg.act = BTC_GAP_BLE_ACT_STOP_SCAN;
@@ -97,6 +116,10 @@ esp_err_t esp_ble_gap_start_advertising(esp_ble_adv_params_t *adv_params)
btc_msg_t msg;
btc_ble_gap_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BLE;
msg.act = BTC_GAP_BLE_ACT_START_ADV;
@@ -109,6 +132,10 @@ esp_err_t esp_ble_gap_stop_advertising(void)
{
btc_msg_t msg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BLE;
msg.act = BTC_GAP_BLE_ACT_STOP_ADV;
@@ -122,6 +149,10 @@ esp_err_t esp_ble_gap_update_conn_params(esp_ble_conn_update_params_t *params)
btc_msg_t msg;
btc_ble_gap_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BLE;
msg.act = BTC_GAP_BLE_ACT_UPDATE_CONN_PARAM;
@@ -135,6 +166,10 @@ esp_err_t esp_ble_gap_set_pkt_data_len(esp_bd_addr_t remote_device, uint16_t tx_
btc_msg_t msg;
btc_ble_gap_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BLE;
msg.act = BTC_GAP_BLE_ACT_SET_PKT_DATA_LEN;
@@ -150,6 +185,10 @@ esp_err_t esp_ble_gap_set_rand_addr(esp_bd_addr_t rand_addr)
btc_msg_t msg;
btc_ble_gap_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BLE;
msg.act = BTC_GAP_BLE_ACT_SET_RAND_ADDRESS;
@@ -164,6 +203,10 @@ esp_err_t esp_ble_gap_config_local_privacy (bool privacy_enable)
btc_msg_t msg;
btc_ble_gap_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BLE;
msg.act = BTC_GAP_BLE_ACT_CONFIG_LOCAL_PRIVACY;
@@ -177,6 +220,10 @@ esp_err_t esp_ble_gap_set_device_name(const char *name)
btc_msg_t msg;
btc_ble_gap_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
if (strlen(name) > ESP_GAP_DEVICE_NAME_MAX) {
return ESP_ERR_INVALID_ARG;
}
@@ -205,3 +252,50 @@ uint8_t *esp_ble_resolve_adv_data( uint8_t *adv_data, uint8_t type, uint8_t *len
return (BTM_CheckAdvData( adv_data, type, length));
}
esp_err_t esp_ble_gap_config_adv_data_raw(uint8_t *raw_data, uint32_t raw_data_len)
{
btc_msg_t msg;
btc_ble_gap_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
if (raw_data == NULL
|| (raw_data_len <= 0 || raw_data_len > ESP_BLE_ADV_DATA_LEN_MAX)) {
return ESP_ERR_INVALID_ARG;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BLE;
msg.act = BTC_GAP_BLE_ACT_CFG_ADV_DATA_RAW;
arg.cfg_adv_data_raw.raw_adv = raw_data;
arg.cfg_adv_data_raw.raw_adv_len = raw_data_len;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), btc_gap_ble_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gap_config_scan_rsp_data_raw(uint8_t *raw_data, uint32_t raw_data_len)
{
btc_msg_t msg;
btc_ble_gap_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
if (raw_data == NULL
|| (raw_data_len <= 0 || raw_data_len > ESP_BLE_SCAN_RSP_DATA_LEN_MAX)) {
return ESP_ERR_INVALID_ARG;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BLE;
msg.act = BTC_GAP_BLE_ACT_CFG_SCAN_RSP_DATA_RAW;
arg.cfg_scan_rsp_data_raw.raw_scan_rsp = raw_data;
arg.cfg_scan_rsp_data_raw.raw_scan_rsp_len = raw_data_len;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), btc_gap_ble_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}

View File

@@ -15,11 +15,17 @@
#include <string.h>
#include "esp_gattc_api.h"
#include "esp_bt_main.h"
#include "btc_manage.h"
#include "btc_gattc.h"
#include "btc_gatt_util.h"
esp_err_t esp_ble_gattc_register_callback(esp_profile_cb_t callback)
esp_err_t esp_ble_gattc_register_callback(esp_gattc_cb_t callback)
{
if (esp_bluedroid_get_status() == ESP_BLUEDROID_STATUS_UNINITIALIZED) {
return ESP_ERR_INVALID_STATE;
}
if (callback == NULL) {
return ESP_FAIL;
}
@@ -33,7 +39,10 @@ esp_err_t esp_ble_gattc_app_register(uint16_t app_id)
btc_msg_t msg;
btc_ble_gattc_args_t arg;
//if (app_id < ESP_APP_ID_MIN || app_id > ESP_APP_ID_MAX) {
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
if (app_id > ESP_APP_ID_MAX) {
return ESP_ERR_INVALID_ARG;
}
@@ -46,52 +55,68 @@ esp_err_t esp_ble_gattc_app_register(uint16_t app_id)
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gattc_app_unregister(esp_gatt_if_t gatt_if)
esp_err_t esp_ble_gattc_app_unregister(esp_gatt_if_t gattc_if)
{
btc_msg_t msg;
btc_ble_gattc_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_APP_UNREGISTER;
arg.app_unreg.gatt_if = gatt_if;
arg.app_unreg.gattc_if = gattc_if;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gattc_open(esp_gatt_if_t gatt_if, esp_bd_addr_t remote_bda, bool is_direct)
esp_err_t esp_ble_gattc_open(esp_gatt_if_t gattc_if, esp_bd_addr_t remote_bda, bool is_direct)
{
btc_msg_t msg;
btc_ble_gattc_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_OPEN;
arg.open.gatt_if = gatt_if;
arg.open.gattc_if = gattc_if;
memcpy(arg.open.remote_bda, remote_bda, ESP_BD_ADDR_LEN);
arg.open.is_direct = is_direct;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gattc_close (uint16_t conn_id)
esp_err_t esp_ble_gattc_close (esp_gatt_if_t gattc_if, uint16_t conn_id)
{
btc_msg_t msg;
btc_ble_gattc_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_CLOSE;
arg.close.conn_id = conn_id;
arg.close.conn_id = BTC_GATT_CREATE_CONN_ID(gattc_if, conn_id);
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gattc_config_mtu (uint16_t conn_id, uint16_t mtu)
esp_err_t esp_ble_gattc_config_mtu (esp_gatt_if_t gattc_if, uint16_t conn_id, uint16_t mtu)
{
btc_msg_t msg;
btc_ble_gattc_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
if ((mtu < ESP_GATT_DEF_BLE_MTU_SIZE) || (mtu > ESP_GATT_MAX_MTU_SIZE)) {
return ESP_GATT_ILLEGAL_PARAMETER;
}
@@ -99,21 +124,26 @@ esp_err_t esp_ble_gattc_config_mtu (uint16_t conn_id, uint16_t mtu)
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_CFG_MTU;
arg.cfg_mtu.conn_id = conn_id;
arg.cfg_mtu.conn_id = BTC_GATT_CREATE_CONN_ID(gattc_if, conn_id);
arg.cfg_mtu.mtu = mtu;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gattc_search_service(uint16_t conn_id, esp_bt_uuid_t *filter_uuid)
esp_err_t esp_ble_gattc_search_service(esp_gatt_if_t gattc_if, uint16_t conn_id, esp_bt_uuid_t *filter_uuid)
{
btc_msg_t msg;
btc_ble_gattc_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_SEARCH_SERVICE;
arg.search_srvc.conn_id = conn_id;
arg.search_srvc.conn_id = BTC_GATT_CREATE_CONN_ID(gattc_if, conn_id);
if (filter_uuid) {
arg.search_srvc.filter_uuid_enable = true;
memcpy(&arg.search_srvc.filter_uuid, filter_uuid, sizeof(esp_bt_uuid_t));
@@ -124,22 +154,27 @@ esp_err_t esp_ble_gattc_search_service(uint16_t conn_id, esp_bt_uuid_t *filter_u
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gattc_get_characteristic(uint16_t conn_id,
esp_gatt_srvc_id_t *srvc_id,
esp_gatt_id_t *start_char_id)
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)
{
btc_msg_t msg;
btc_ble_gattc_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
if (start_char_id) {
arg.get_next_char.conn_id = conn_id;
arg.get_next_char.conn_id = BTC_GATT_CREATE_CONN_ID(gattc_if, conn_id);
memcpy(&arg.get_next_char.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&arg.get_next_char.char_id, start_char_id, sizeof(esp_gatt_id_t));
msg.act = BTC_GATTC_ACT_GET_NEXT_CHAR;
} else {
arg.get_first_char.conn_id = conn_id;
arg.get_first_char.conn_id = BTC_GATT_CREATE_CONN_ID(gattc_if, conn_id);
memcpy(&arg.get_first_char.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
msg.act = BTC_GATTC_ACT_GET_FIRST_CHAR;
}
@@ -147,7 +182,8 @@ esp_err_t esp_ble_gattc_get_characteristic(uint16_t conn_id,
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gattc_get_descriptor(uint16_t conn_id,
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)
@@ -155,17 +191,21 @@ esp_err_t esp_ble_gattc_get_descriptor(uint16_t conn_id,
btc_msg_t msg;
btc_ble_gattc_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
if (start_descr_id) {
arg.get_next_descr.conn_id = conn_id;
arg.get_next_descr.conn_id = BTC_GATT_CREATE_CONN_ID(gattc_if, conn_id);
memcpy(&arg.get_next_descr.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&arg.get_next_descr.char_id, char_id, sizeof(esp_gatt_id_t));
memcpy(&arg.get_next_descr.descr_id, start_descr_id, sizeof(esp_gatt_id_t));
msg.act = BTC_GATTC_ACT_GET_NEXT_DESCR;
} else {
arg.get_first_descr.conn_id = conn_id;
arg.get_first_descr.conn_id = BTC_GATT_CREATE_CONN_ID(gattc_if, conn_id);
memcpy(&arg.get_first_descr.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&arg.get_first_descr.char_id, char_id, sizeof(esp_gatt_id_t));
msg.act = BTC_GATTC_ACT_GET_FIRST_DESCR;
@@ -174,23 +214,28 @@ esp_err_t esp_ble_gattc_get_descriptor(uint16_t conn_id,
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gattc_get_included_service(uint16_t conn_id,
esp_gatt_srvc_id_t *srvc_id,
esp_gatt_srvc_id_t *start_incl_srvc_id)
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)
{
btc_msg_t msg;
btc_ble_gattc_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
if (start_incl_srvc_id) {
arg.get_next_incl_srvc.conn_id = conn_id;
arg.get_next_incl_srvc.conn_id = BTC_GATT_CREATE_CONN_ID(gattc_if, conn_id);
memcpy(&arg.get_next_incl_srvc.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&arg.get_next_incl_srvc.start_service_id, start_incl_srvc_id, sizeof(esp_gatt_srvc_id_t));
msg.act = BTC_GATTC_ACT_GET_NEXT_INCL_SERVICE;
} else {
arg.get_first_incl_srvc.conn_id = conn_id;
arg.get_first_incl_srvc.conn_id = BTC_GATT_CREATE_CONN_ID(gattc_if, conn_id);
memcpy(&arg.get_first_incl_srvc.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
msg.act = BTC_GATTC_ACT_GET_FIRST_INCL_SERVICE;
}
@@ -198,16 +243,23 @@ esp_err_t esp_ble_gattc_get_included_service(uint16_t conn_id,
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gattc_read_char (uint16_t conn_id, esp_gatt_srvc_id_t *srvc_id,
esp_gatt_id_t *char_id, esp_gatt_auth_req_t auth_req)
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)
{
btc_msg_t msg;
btc_ble_gattc_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_READ_CHAR;
arg.read_char.conn_id = conn_id;
arg.read_char.conn_id = BTC_GATT_CREATE_CONN_ID(gattc_if, conn_id);
memcpy(&arg.read_char.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&arg.read_char.char_id, char_id, sizeof(esp_gatt_id_t));
arg.read_char.auth_req = auth_req;
@@ -215,19 +267,24 @@ esp_err_t esp_ble_gattc_read_char (uint16_t conn_id, esp_gatt_srvc_id_t *srvc_id
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gattc_read_char_descr (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)
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)
{
btc_msg_t msg;
btc_ble_gattc_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_READ_CHAR_DESCR;
arg.read_descr.conn_id = conn_id;
arg.read_descr.conn_id = BTC_GATT_CREATE_CONN_ID(gattc_if, conn_id);
memcpy(&arg.read_descr.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&arg.read_descr.char_id, char_id, sizeof(esp_gatt_id_t));
memcpy(&arg.read_descr.descr_id, descr_id, sizeof(esp_gatt_id_t));
@@ -236,21 +293,26 @@ esp_err_t esp_ble_gattc_read_char_descr (uint16_t conn_id,
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gattc_write_char( uint16_t conn_id,
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_write_type_t write_type,
esp_gatt_auth_req_t auth_req)
{
btc_msg_t msg;
btc_ble_gattc_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_WRITE_CHAR;
arg.write_char.conn_id = (uint16_t) conn_id;
arg.write_char.conn_id = BTC_GATT_CREATE_CONN_ID(gattc_if, conn_id);
memcpy(&arg.write_char.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&arg.write_char.char_id, char_id, sizeof(esp_gatt_id_t));
arg.write_char.value_len = value_len > ESP_GATT_MAX_ATTR_LEN ? ESP_GATT_MAX_ATTR_LEN : value_len;
@@ -261,22 +323,27 @@ esp_err_t esp_ble_gattc_write_char( uint16_t conn_id,
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), btc_gattc_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gattc_write_char_descr (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)
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)
{
btc_msg_t msg;
btc_ble_gattc_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_WRITE_CHAR_DESCR;
arg.write_descr.conn_id = (uint16_t) conn_id;
arg.write_descr.conn_id = BTC_GATT_CREATE_CONN_ID(gattc_if, conn_id);
memcpy(&arg.write_descr.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&arg.write_descr.char_id, char_id, sizeof(esp_gatt_id_t));
memcpy(&arg.write_descr.descr_id, descr_id, sizeof(esp_gatt_id_t));
@@ -288,7 +355,8 @@ esp_err_t esp_ble_gattc_write_char_descr (uint16_t conn_id,
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), btc_gattc_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gattc_prepare_write(uint16_t conn_id,
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,
@@ -300,10 +368,14 @@ esp_err_t esp_ble_gattc_prepare_write(uint16_t conn_id,
btc_msg_t msg;
btc_ble_gattc_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_PREPARE_WRITE;
arg.prep_write.conn_id = conn_id;
arg.prep_write.conn_id = BTC_GATT_CREATE_CONN_ID(gattc_if, conn_id);
memcpy(&arg.prep_write.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&arg.prep_write.char_id, char_id, sizeof(esp_gatt_id_t));
arg.prep_write.offset = offset;
@@ -314,21 +386,25 @@ esp_err_t esp_ble_gattc_prepare_write(uint16_t conn_id,
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), btc_gattc_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gattc_execute_write (uint16_t conn_id, bool is_execute)
esp_err_t esp_ble_gattc_execute_write (esp_gatt_if_t gattc_if, uint16_t conn_id, bool is_execute)
{
btc_msg_t msg;
btc_ble_gattc_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_EXECUTE_WRITE;
arg.exec_write.conn_id = conn_id;
arg.exec_write.conn_id = BTC_GATT_CREATE_CONN_ID(gattc_if, conn_id);
arg.exec_write.is_execute = is_execute;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_gatt_status_t esp_ble_gattc_register_for_notify (esp_gatt_if_t gatt_if,
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)
@@ -336,18 +412,22 @@ esp_gatt_status_t esp_ble_gattc_register_for_notify (esp_gatt_if_t gatt_if,
btc_msg_t msg;
btc_ble_gattc_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_REG_FOR_NOTIFY;
arg.reg_for_notify.gatt_if = gatt_if;
memcpy(&arg.reg_for_notify.remote_bda, &server_bda, sizeof(esp_bd_addr_t));
arg.reg_for_notify.gattc_if = gattc_if;
memcpy(arg.reg_for_notify.remote_bda, server_bda, sizeof(esp_bd_addr_t));
memcpy(&arg.reg_for_notify.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&arg.reg_for_notify.char_id, char_id, sizeof(esp_gatt_id_t));
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_gatt_status_t esp_ble_gattc_unregister_for_notify (esp_gatt_if_t gatt_if,
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)
@@ -355,11 +435,15 @@ esp_gatt_status_t esp_ble_gattc_unregister_for_notify (esp_gatt_if_t gatt_if,
btc_msg_t msg;
btc_ble_gattc_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_UNREG_FOR_NOTIFY;
arg.unreg_for_notify.gatt_if = gatt_if;
memcpy(&arg.unreg_for_notify.remote_bda, &server_bda, sizeof(esp_bd_addr_t));
arg.unreg_for_notify.gattc_if = gattc_if;
memcpy(arg.unreg_for_notify.remote_bda, server_bda, sizeof(esp_bd_addr_t));
memcpy(&arg.unreg_for_notify.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&arg.unreg_for_notify.char_id, char_id, sizeof(esp_gatt_id_t));

View File

@@ -15,13 +15,19 @@
#include "string.h"
#include "esp_gatt_defs.h"
#include "esp_gatts_api.h"
#include "esp_bt_main.h"
#include "btc_manage.h"
#include "btc_gatts.h"
#include "btc_gatt_util.h"
#define COPY_TO_GATTS_ARGS(_gatt_args, _arg, _arg_type) memcpy(_gatt_args, _arg, sizeof(_arg_type))
esp_err_t esp_ble_gatts_register_callback(esp_profile_cb_t callback)
esp_err_t esp_ble_gatts_register_callback(esp_gatts_cb_t callback)
{
if (esp_bluedroid_get_status() == ESP_BLUEDROID_STATUS_UNINITIALIZED) {
return ESP_ERR_INVALID_STATE;
}
return (btc_profile_cb_set(BTC_PID_GATTS, callback) == 0 ? ESP_OK : ESP_FAIL);
}
@@ -30,6 +36,10 @@ esp_err_t esp_ble_gatts_app_register(uint16_t app_id)
btc_msg_t msg;
btc_ble_gatts_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
//if (app_id < ESP_APP_ID_MIN || app_id > ESP_APP_ID_MAX) {
if (app_id > ESP_APP_ID_MAX) {
return ESP_ERR_INVALID_ARG;
@@ -44,41 +54,73 @@ esp_err_t esp_ble_gatts_app_register(uint16_t app_id)
}
esp_err_t esp_ble_gatts_app_unregister(esp_gatt_if_t gatt_if)
esp_err_t esp_ble_gatts_app_unregister(esp_gatt_if_t gatts_if)
{
btc_msg_t msg;
btc_ble_gatts_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
msg.act = BTC_GATTS_ACT_APP_UNREGISTER;
arg.app_unreg.gatt_if = gatt_if;
arg.app_unreg.gatts_if = gatts_if;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gatts_create_service(esp_gatt_if_t gatt_if,
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)
{
btc_msg_t msg;
btc_ble_gatts_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
msg.act = BTC_GATTS_ACT_CREATE_SERVICE;
arg.create_srvc.gatt_if = gatt_if;
arg.create_srvc.gatts_if = gatts_if;
arg.create_srvc.num_handle = num_handle;
memcpy(&arg.create_srvc.service_id, service_id, sizeof(esp_gatt_srvc_id_t));
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
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)
{
btc_msg_t msg;
btc_ble_gatts_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
msg.act = BTC_GATTS_ACT_CREATE_ATTR_TAB;
arg.create_attr_tab.gatts_if = gatts_if;
arg.create_attr_tab.max_nb_attr = max_nb_attr;
arg.create_attr_tab.srvc_inst_id = srvc_inst_id;
arg.create_attr_tab.gatts_attr_db = (esp_gatts_attr_db_t *)gatts_attr_db;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), btc_gatts_arg_deep_copy)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gatts_add_included_service(uint16_t service_handle, uint16_t included_service_handle)
{
btc_msg_t msg;
btc_ble_gatts_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
msg.act = BTC_GATTS_ACT_ADD_INCLUDE_SERVICE;
@@ -90,38 +132,113 @@ esp_err_t esp_ble_gatts_add_included_service(uint16_t service_handle, uint16_t i
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_gatt_perm_t perm, esp_gatt_char_prop_t property, esp_attr_value_t *char_val,
esp_attr_control_t *control)
{
btc_msg_t msg;
btc_ble_gatts_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
/* parameter validation check */
if ((control != NULL) && (control->auto_rsp == GATT_STACK_RSP)){
if (char_val == NULL){
LOG_ERROR("Error in %s, line=%d, for stack respond attribute, char_val should not be NULL here\n",\
__func__, __LINE__);
return ESP_ERR_INVALID_ARG;
} else if (char_val->attr_max_len == 0){
LOG_ERROR("Error in %s, line=%d, for stack respond attribute, attribute max length should not be 0\n",\
__func__, __LINE__);
return ESP_ERR_INVALID_ARG;
}
}
if (char_val != NULL){
if (char_val->attr_len > char_val->attr_max_len){
LOG_ERROR("Error in %s, line=%d,attribute actual length (%d) should not be larger than max length (%d)\n",\
__func__, __LINE__, char_val->attr_len, char_val->attr_max_len);
return ESP_ERR_INVALID_ARG;
}
}
memset(&arg, 0, sizeof(btc_ble_gatts_args_t));
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
msg.act = BTC_GATTS_ACT_ADD_CHAR;
arg.add_char.service_handle = service_handle;
arg.add_char.perm = perm;
arg.add_char.property = property;
if (char_val != NULL) {
arg.add_char.char_val.attr_max_len = char_val->attr_max_len;
arg.add_char.char_val.attr_len = char_val->attr_len;
arg.add_char.char_val.attr_value = char_val->attr_value;
}
if (control != NULL) {
arg.add_char.attr_control.auto_rsp = control->auto_rsp;
}
memcpy(&arg.add_char.char_uuid, char_uuid, sizeof(esp_bt_uuid_t));
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), btc_gatts_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
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_gatt_perm_t perm, esp_attr_value_t *char_descr_val,
esp_attr_control_t *control)
{
btc_msg_t msg;
btc_ble_gatts_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
/* parameter validation check */
if ((control != NULL) && (control->auto_rsp == GATT_STACK_RSP)){
if (char_descr_val == NULL){
LOG_ERROR("Error in %s, line=%d, for stack respond attribute, char_descr_val should not be NULL here\n",\
__func__, __LINE__);
return ESP_ERR_INVALID_ARG;
}
else if (char_descr_val->attr_max_len == 0){
LOG_ERROR("Error in %s, line=%d, for stack respond attribute, attribute max length should not be 0\n",\
__func__, __LINE__);
return ESP_ERR_INVALID_ARG;
}
}
if (char_descr_val != NULL){
if (char_descr_val->attr_len > char_descr_val->attr_max_len){
LOG_ERROR("Error in %s, line=%d,attribute actual length (%d) should not be larger than max length (%d)\n",\
__func__, __LINE__, char_descr_val->attr_len, char_descr_val->attr_max_len);
return ESP_ERR_INVALID_ARG;
}
}
memset(&arg, 0, sizeof(btc_ble_gatts_args_t));
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
msg.act = BTC_GATTS_ACT_ADD_CHAR_DESCR;
arg.add_descr.service_handle = service_handle;
arg.add_descr.perm = perm;
if (char_descr_val != NULL) {
arg.add_descr.descr_val.attr_max_len = char_descr_val->attr_max_len;
arg.add_descr.descr_val.attr_len = char_descr_val->attr_len;
arg.add_descr.descr_val.attr_value = char_descr_val->attr_value;
}
if (control != NULL) {
arg.add_descr.attr_control.auto_rsp = control->auto_rsp;
}
memcpy(&arg.add_descr.descr_uuid, descr_uuid, sizeof(esp_bt_uuid_t));
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), btc_gatts_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gatts_delete_service(uint16_t service_handle)
@@ -129,6 +246,10 @@ esp_err_t esp_ble_gatts_delete_service(uint16_t service_handle)
btc_msg_t msg;
btc_ble_gatts_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
msg.act = BTC_GATTS_ACT_DELETE_SERVICE;
@@ -142,6 +263,10 @@ esp_err_t esp_ble_gatts_start_service(uint16_t service_handle)
btc_msg_t msg;
btc_ble_gatts_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
msg.act = BTC_GATTS_ACT_START_SERVICE;
@@ -155,6 +280,10 @@ esp_err_t esp_ble_gatts_stop_service(uint16_t service_handle)
btc_msg_t msg;
btc_ble_gatts_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
msg.act = BTC_GATTS_ACT_STOP_SERVICE;
@@ -164,65 +293,109 @@ esp_err_t esp_ble_gatts_stop_service(uint16_t service_handle)
}
esp_err_t esp_ble_gatts_send_indicate(uint16_t conn_id, uint16_t attr_handle,
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)
{
btc_msg_t msg;
btc_ble_gatts_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
msg.act = BTC_GATTS_ACT_SEND_INDICATE;
arg.send_ind.conn_id = conn_id;
arg.send_ind.conn_id = BTC_GATT_CREATE_CONN_ID(gatts_if, conn_id);
arg.send_ind.attr_handle = attr_handle;
arg.send_ind.need_confirm = need_confirm;
arg.send_ind.value_len = value_len;
arg.send_ind.value = value;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), btc_gatts_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t),
btc_gatts_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gatts_send_response(uint16_t conn_id, uint32_t trans_id,
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)
{
btc_msg_t msg;
btc_ble_gatts_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
msg.act = BTC_GATTS_ACT_SEND_RESPONSE;
arg.send_rsp.conn_id = conn_id;
arg.send_rsp.conn_id = BTC_GATT_CREATE_CONN_ID(gatts_if, conn_id);
arg.send_rsp.trans_id = trans_id;
arg.send_rsp.status = status;
arg.send_rsp.rsp = rsp;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), btc_gatts_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t),
btc_gatts_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gatts_open(esp_gatt_if_t gatt_if, esp_bd_addr_t remote_bda, bool is_direct)
esp_err_t esp_ble_gatts_set_attr_value(uint16_t attr_handle, uint16_t length, const uint8_t *value)
{
btc_msg_t msg;
btc_ble_gatts_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
msg.act = BTC_GATTS_ACT_SET_ATTR_VALUE;
arg.set_attr_val.length = length;
arg.set_attr_val.value = (uint8_t *)value;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t),
btc_gatts_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gatts_get_attr_value(uint16_t attr_handle, uint16_t *length, const uint8_t **value)
{
if (attr_handle == ESP_GATT_ILLEGAL_HANDLE) {
return ESP_FAIL;
}
btc_gatts_get_attr_value(attr_handle, length, (uint8_t **)value);
return ESP_OK;
}
esp_err_t esp_ble_gatts_open(esp_gatt_if_t gatts_if, esp_bd_addr_t remote_bda, bool is_direct)
{
btc_msg_t msg;
btc_ble_gatts_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
msg.act = BTC_GATTS_ACT_OPEN;
arg.open.gatt_if = gatt_if;
arg.open.gatts_if = gatts_if;
arg.open.is_direct = is_direct;
memcpy(&arg.open.remote_bda, remote_bda, sizeof(esp_bd_addr_t));
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gatts_close(uint16_t conn_id)
esp_err_t esp_ble_gatts_close(esp_gatt_if_t gatts_if, uint16_t conn_id)
{
btc_msg_t msg;
btc_ble_gatts_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
msg.act = BTC_GATTS_ACT_CLOSE;
arg.close.conn_id = conn_id;
arg.close.conn_id = BTC_GATT_CREATE_CONN_ID(gatts_if, conn_id);
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}

View File

@@ -15,23 +15,47 @@
#ifndef __ESP_BLUFI_API_H__
#define __ESP_BLUFI_API_H__
#include "bt_types.h"
#include "esp_bt_defs.h"
#include "esp_gatt_defs.h"
#include "bta_gatt_api.h"
#include "esp_err.h"
#include "esp_wifi_types.h"
#define ESP_BLUFI_RECV_DATA_LEN_MAX (64+1)
#ifdef __cplusplus
extern "C" {
#endif
#define ESP_BLUFI_EVENT_INIT_FINISH 0
#define ESP_BLUFI_EVENT_DEINIT_FINISH 1
#define ESP_BLUFI_EVENT_RECV_DATA 2
typedef enum {
ESP_BLUFI_EVENT_INIT_FINISH = 0, /*<! When BLUFI init complete, this event happen */
ESP_BLUFI_EVENT_DEINIT_FINISH, /*<! When BLUFI deinit complete, this event happen */
ESP_BLUFI_EVENT_SET_WIFI_OPMODE, /*<! When Phone set ESP32 wifi operation mode(AP/STA/AP_STA), this event happen */
ESP_BLUFI_EVENT_BLE_CONNECT, /*<! When Phone connect to ESP32 with BLE, this event happen */
ESP_BLUFI_EVENT_BLE_DISCONNECT, /*<! When Phone disconnect with BLE, this event happen */
ESP_BLUFI_EVENT_REQ_CONNECT_TO_AP, /*<! When Phone request ESP32's STA connect to AP, this event happen */
ESP_BLUFI_EVENT_REQ_DISCONNECT_FROM_AP, /*<! When Phone request ESP32's STA disconnect from AP, this event happen */
ESP_BLUFI_EVENT_GET_WIFI_STATUS, /*<! When Phone get ESP32 wifi status, this event happen */
ESP_BLUFI_EVENT_DEAUTHENTICATE_STA, /*<! When Phone deauthenticate sta from SOFTAP, this event happen */
/* recv data */
ESP_BLUFI_EVENT_RECV_STA_BSSID, /*<! When Phone send STA BSSID to ESP32 to connect, this event happen */
ESP_BLUFI_EVENT_RECV_STA_SSID, /*<! When Phone send STA SSID to ESP32 to connect, this event happen */
ESP_BLUFI_EVENT_RECV_STA_PASSWD, /*<! When Phone send STA PASSWORD to ESP32 to connect, this event happen */
ESP_BLUFI_EVENT_RECV_SOFTAP_SSID, /*<! When Phone send SOFTAP SSID to ESP32 to start SOFTAP, this event happen */
ESP_BLUFI_EVENT_RECV_SOFTAP_PASSWD, /*<! When Phone send SOFTAP PASSWORD to ESP32 to start SOFTAP, this event happen */
ESP_BLUFI_EVENT_RECV_SOFTAP_MAX_CONN_NUM, /*<! When Phone send SOFTAP max connection number to ESP32 to start SOFTAP, this event happen */
ESP_BLUFI_EVENT_RECV_SOFTAP_AUTH_MODE, /*<! When Phone send SOFTAP authentication mode to ESP32 to start SOFTAP, this event happen */
ESP_BLUFI_EVENT_RECV_SOFTAP_CHANNEL, /*<! When Phone send SOFTAP channel to ESP32 to start SOFTAP, this event happen */
ESP_BLUFI_EVENT_RECV_USERNAME, /*<! When Phone send username to ESP32, this event happen */
ESP_BLUFI_EVENT_RECV_CA_CERT, /*<! When Phone send CA certificate to ESP32, this event happen */
ESP_BLUFI_EVENT_RECV_CLIENT_CERT, /*<! When Phone send Client certificate to ESP32, this event happen */
ESP_BLUFI_EVENT_RECV_SERVER_CERT, /*<! When Phone send Server certificate to ESP32, this event happen */
ESP_BLUFI_EVENT_RECV_CLIENT_PRIV_KEY, /*<! When Phone send Client Private key to ESP32, this event happen */
ESP_BLUFI_EVENT_RECV_SERVER_PRIV_KEY, /*<! When Phone send Server Private key to ESP32, this event happen */
} esp_blufi_cb_event_t;
/// BLUFI config status
typedef enum {
ESP_BLUFI_CONFIG_OK = 0,
ESP_BLUFI_CONFIG_FAILED,
} esp_blufi_config_state_t;
ESP_BLUFI_STA_CONN_SUCCESS = 0x00,
ESP_BLUFI_STA_CONN_FAIL = 0x01,
} esp_blufi_sta_conn_state_t;
/// BLUFI init status
typedef enum {
@@ -45,6 +69,29 @@ typedef enum {
ESP_BLUFI_DEINIT_FAILED = 0,
} esp_blufi_deinit_state_t;
/**
* @brief BLUFI extra information structure
*/
typedef struct {
//station
uint8_t sta_bssid[6]; /*!< BSSID of station interface */
bool sta_bssid_set; /*!< is BSSID of station interface set */
uint8_t *sta_ssid; /*!< SSID of station interface */
int sta_ssid_len; /*!< length of SSID of station interface */
uint8_t *sta_passwd; /*!< password of station interface */
int sta_passwd_len; /*!< length of password of station interface */
uint8_t *softap_ssid; /*!< SSID of softap interface */
int softap_ssid_len; /*!< length of SSID of softap interface */
uint8_t *softap_passwd; /*!< password of station interface */
int softap_passwd_len; /*!< length of password of station interface */
uint8_t softap_authmode; /*!< authentication mode of softap interface */
bool softap_authmode_set; /*!< is authentication mode of softap interface set */
uint8_t softap_max_conn_num; /*!< max connection number of softap interface */
bool softap_max_conn_num_set; /*!< is max connection number of softap interface set */
uint8_t softap_channel; /*!< channel of softap interface */
bool softap_channel_set; /*!< is channel of softap interface set */
} esp_blufi_extra_info_t;
/**
* @brief BLUFI callback parameters union
*/
@@ -64,35 +111,207 @@ typedef union {
} deinit_finish; /*!< Blufi callback param of ESP_BLUFI_EVENT_DEINIT_FINISH */
/**
* @brief ESP_BLUFI_EVENT_RECV_DATA
* @brief ESP_BLUFI_EVENT_SET_WIFI_MODE
*/
struct blufi_set_wifi_mode_evt_param {
wifi_mode_t op_mode; /*!< Wifi operation mode */
} wifi_mode; /*!< Blufi callback param of ESP_BLUFI_EVENT_INIT_FINISH */
/**
* @brief ESP_BLUFI_EVENT_CONNECT
*/
struct blufi_recv_evt_param {
uint8_t data[ESP_BLUFI_RECV_DATA_LEN_MAX]; /*!< Blufi receive data */
uint8_t data_len; /*!< Blufi receive data length */
} recv_data; /*!< Blufi callback param of ESP_BLUFI_EVENT_RECV_DATA */
struct blufi_connect_evt_param {
esp_bd_addr_t remote_bda; /*!< Blufi Remote bluetooth device address */
} connect; /*!< Blufi callback param of ESP_BLUFI_EVENT_CONNECT */
/**
* @brief ESP_BLUFI_EVENT_DISCONNECT
*/
struct blufi_disconnect_evt_param {
esp_bd_addr_t remote_bda; /*!< Blufi Remote bluetooth device address */
} disconnect; /*!< Blufi callback param of ESP_BLUFI_EVENT_DISCONNECT */
/* ESP_BLUFI_EVENT_REQ_WIFI_CONNECT */ /* No callback param */
/* ESP_BLUFI_EVENT_REQ_WIFI_DISCONNECT */ /* No callback param */
/**
* @brief ESP_BLUFI_EVENT_RECV_STA_BSSID
*/
struct blufi_recv_sta_bssid_evt_param {
uint8_t bssid[6]; /*!< BSSID */
} sta_bssid; /*!< Blufi callback param of ESP_BLUFI_EVENT_RECV_STA_BSSID */
/**
* @brief ESP_BLUFI_EVENT_RECV_STA_SSID
*/
struct blufi_recv_sta_ssid_evt_param {
uint8_t *ssid; /*!< SSID */
int ssid_len; /*!< SSID length */
} sta_ssid; /*!< Blufi callback param of ESP_BLUFI_EVENT_RECV_STA_SSID */
/**
* @brief
* ESP_BLUFI_EVENT_RECV_STA_PASSWD
*/
struct blufi_recv_sta_passwd_evt_param {
uint8_t *passwd; /*!< Password */
int passwd_len; /*!< Password Length */
} sta_passwd; /*!< Blufi callback param of ESP_BLUFI_EVENT_RECV_STA_PASSWD */
/**
* @brief ESP_BLUFI_EVENT_RECV_SOFTAP_SSID
*/
struct blufi_recv_softap_ssid_evt_param {
uint8_t *ssid; /*!< SSID */
int ssid_len; /*!< SSID length */
} softap_ssid; /*!< Blufi callback param of ESP_BLUFI_EVENT_RECV_SOFTAP_SSID */
/**
* @brief
* ESP_BLUFI_EVENT_RECV_SOFTAP_PASSWD
*/
struct blufi_recv_softap_passwd_evt_param {
uint8_t *passwd; /*!< Password */
int passwd_len; /*!< Password Length */
} softap_passwd; /*!< Blufi callback param of ESP_BLUFI_EVENT_RECV_SOFTAP_PASSWD */
/**
* @brief ESP_BLUFI_EVENT_RECV_SOFTAP_MAX_CONN_NUM
*/
struct blufi_recv_softap_max_conn_num_evt_param {
int max_conn_num; /*!< SSID */
} softap_max_conn_num; /*!< Blufi callback param of ESP_BLUFI_EVENT_RECV_SOFTAP_MAX_CONN_NUM */
/**
* @brief
* ESP_BLUFI_EVENT_RECV_SOFTAP_AUTH_MODE
*/
struct blufi_recv_softap_auth_mode_evt_param {
wifi_auth_mode_t auth_mode; /*!< Authentication mode */
} softap_auth_mode; /*!< Blufi callback param of ESP_BLUFI_EVENT_RECV_SOFTAP_AUTH_MODE */
/**
* @brief
* ESP_BLUFI_EVENT_RECV_SOFTAP_CHANNEL
*/
struct blufi_recv_softap_channel_evt_param {
uint8_t channel; /*!< Authentication mode */
} softap_channel; /*!< Blufi callback param of ESP_BLUFI_EVENT_RECV_SOFTAP_CHANNEL */
/**
* @brief ESP_BLUFI_EVENT_RECV_USERNAME
*/
struct blufi_recv_username_evt_param {
uint8_t *name; /*!< Username point */
int name_len; /*!< Username length */
} username; /*!< Blufi callback param of ESP_BLUFI_EVENT_RECV_USERNAME*/
/**
* @brief ESP_BLUFI_EVENT_RECV_CA_CERT
*/
struct blufi_recv_ca_evt_param {
uint8_t *cert; /*!< CA certificate point */
int cert_len; /*!< CA certificate length */
} ca; /*!< Blufi callback param of ESP_BLUFI_EVENT_RECV_CA_CERT */
/**
* ESP_BLUFI_EVENT_RECV_CLIENT_CERT
*/
struct blufi_recv_client_cert_evt_param {
uint8_t *cert; /*!< Client certificate point */
int cert_len; /*!< Client certificate length */
} client_cert; /*!< Blufi callback param of ESP_BLUFI_EVENT_RECV_CLIENT_CERT */
/**
* ESP_BLUFI_EVENT_RECV_SERVER_CERT
*/
struct blufi_recv_server_cert_evt_param {
uint8_t *cert; /*!< Client certificate point */
int cert_len; /*!< Client certificate length */
} server_cert; /*!< Blufi callback param of ESP_BLUFI_EVENT_RECV_SERVER_CERT */
/**
* ESP_BLUFI_EVENT_RECV_CLIENT_PRIV_KEY
*/
struct blufi_recv_client_pkey_evt_param {
uint8_t *pkey; /*!< Client Private Key point, if Client certificate not contain Key */
int pkey_len; /*!< Client Private key length */
} client_pkey; /*!< Blufi callback param of ESP_BLUFI_EVENT_RECV_CLIENT_PRIV_KEY */
/**
* ESP_BLUFI_EVENT_RECV_SERVER_PRIV_KEY
*/
struct blufi_recv_server_pkey_evt_param {
uint8_t *pkey; /*!< Client Private Key point, if Client certificate not contain Key */
int pkey_len; /*!< Client Private key length */
} server_pkey; /*!< Blufi callback param of ESP_BLUFI_EVENT_RECV_SERVER_PRIV_KEY */
} esp_blufi_cb_param_t;
/**
* @brief BLUFI event callback function type
* @param event : Event type
* @param param : Point to callback parameter, currently is union type
*/
typedef void (* esp_blufi_event_cb_t)(esp_blufi_cb_event_t event, esp_blufi_cb_param_t *param);
/* security function declare */
/**
* @brief BLUFI negotiate data handler
* @param data : data from phone
* @param len : length of data from phone
* @param output_data : data want to send to phone
* @param output_len : length of data want to send to phone
*/
typedef void (*esp_blufi_negotiate_data_handler_t)(uint8_t *data, int len, uint8_t **output_data, int *output_len, bool *need_free);
/**
* @brief BLUFI encrypt the data after negotiate a share key
* @param iv8 : initial vector(8bit), normally, blufi core will input packet sequence number
* @param crypt_data : plain text and encrypted data, the encrypt function must support autochthonous encrypt
* @param crypt_len : length of plain text
* @return Nonnegative number is encrypted length, if error, return negative number;
*/
typedef int (* esp_blufi_encrypt_func_t)(uint8_t iv8, uint8_t *crypt_data, int cyprt_len);
/**
* @brief BLUFI decrypt the data after negotiate a share key
* @param iv8 : initial vector(8bit), normally, blufi core will input packet sequence number
* @param crypt_data : encrypted data and plain text, the encrypt function must support autochthonous decrypt
* @param crypt_len : length of encrypted text
* @return Nonnegative number is decrypted length, if error, return negative number;
*/
typedef int (* esp_blufi_decrypt_func_t)(uint8_t iv8, uint8_t *crypt_data, int crypt_len);
/**
* @brief BLUFI checksum
* @param iv8 : initial vector(8bit), normally, blufi core will input packet sequence number
* @param data : data need to checksum
* @param len : length of data
*/
typedef uint16_t (*esp_blufi_checksum_func_t)(uint8_t iv8, uint8_t *data, int len);
/**
* @brief BLUFI callback functions type
*/
typedef struct {
esp_blufi_event_cb_t event_cb; /*!< BLUFI event callback */
esp_blufi_negotiate_data_handler_t negotiate_data_handler; /*!< BLUFI negotiate data function for negotiate share key */
esp_blufi_encrypt_func_t encrypt_func; /*!< BLUFI encrypt data function with share key generated by negotiate_data_handler */
esp_blufi_decrypt_func_t decrypt_func; /*!< BLUFI decrypt data function with share key generated by negotiate_data_handler */
esp_blufi_checksum_func_t checksum_func; /*!< BLUFI check sum function (FCS) */
} esp_blufi_callbacks_t;
/**
*
* @brief This function is called to receive blufi callback event
*
* @param[in] callback: callback function
* @param[in] callbacks: callback functions
*
* @return ESP_OK - success, other - failed
*
*/
esp_err_t esp_blufi_register_callback(esp_profile_cb_t callback);
/**
*
* @brief This function is called to send config state to phone
*
* @param[in] state: blufi config OK or not
*
* @return ESP_OK - success, other - failed
*
*/
esp_err_t esp_blufi_send_config_state(esp_blufi_config_state_t state);
esp_err_t esp_blufi_register_callbacks(esp_blufi_callbacks_t *callbacks);
/**
*
@@ -112,6 +331,30 @@ esp_err_t esp_blufi_profile_init(void);
*/
esp_err_t esp_blufi_profile_deinit(void);
/**
*
* @brief This function is called to send wifi connection report
* @param opmode : wifi opmode
* @param sta_conn_state : station is already in connection or not
* @param softap_conn_num : softap connection number
* @param extra_info : extra information, such as sta_ssid, softap_ssid and etc.
*
* @return ESP_OK - success, other - failed
*
*/
esp_err_t esp_blufi_send_wifi_conn_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);
/**
*
* @brief Get BLUFI profile version
*
* @return Most 8bit significant is Great version, Least 8bit is Sub version
*
*/
uint16_t esp_blufi_get_version(void);
#ifdef __cplusplus
}
#endif
#endif /* _ESP_BLUFI_API_ */

View File

@@ -18,6 +18,10 @@
#include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
/// Status Return Value
typedef enum {
ESP_BT_STATUS_SUCCESS = 0, /* Successful operation. */
@@ -92,11 +96,11 @@ typedef enum {
/// Maximum of the application id
#define ESP_APP_ID_MAX 0x7fff
/**
* @brief Each profile callback function type
* @param event : Event type
* @param param : Point to callback parameter, currently is union type
*/
typedef void (* esp_profile_cb_t)(uint32_t event, void *param);
#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]
#endif ///__ESP_BT_DEFS_H__
#ifdef __cplusplus
}
#endif
#endif /* __ESP_BT_DEFS_H__ */

View File

@@ -12,28 +12,27 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef __BT_APP_COMMON_H__
#define __BT_APP_COMMON_H__
#ifndef __ESP_BT_DEVICE_H__
#define __ESP_BT_DEVICE_H__
#include <stdint.h>
#include "osi.h"
#include "bt_common_types.h"
#include "esp_err.h"
#include <stdbool.h>
enum BLUFI_SIG {
BLUFI_SIG_SWITCH_CONTEXT = 0,
BLUFI_SIG_ENABLE,
BLUFI_SIG_DISABLE,
};
#ifdef __cplusplus
extern "C" {
#endif
typedef esp_err_t (*blufi_task_cb_t)(void *arg);
/**
*
* @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);
void blufi_init(void);
void blufi_deinit(void);
#ifdef __cplusplus
}
#endif
esp_err_t blufi_enable(void *arg);
esp_err_t blufi_disable(void *arg);
esp_err_t blufi_transfer_context(blufi_task_cb_t cb, void *arg);
#endif /* __BT_APP_COMMON_H__ */
#endif /* __ESP_BT_DEVICE_H__ */

View File

@@ -15,26 +15,46 @@
#ifndef __ESP_BT_MAIN_H__
#define __ESP_BT_MAIN_H__
#include "btc_main.h"
#include "esp_err.h"
/**
* @brief Enable bluetooth, must after esp_init_bluetooth()
*
* @return
* - ESP_OK : Succeed
* - Other : Failed
*/
esp_err_t esp_enable_bluetooth(void);
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Disable bluetooth, must prior to esp_deinit_bluetooth()
* @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_disable_bluetooth(void);
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
@@ -43,7 +63,7 @@ esp_err_t esp_disable_bluetooth(void);
* - ESP_OK : Succeed
* - Other : Failed
*/
esp_err_t esp_init_bluetooth(void);
esp_err_t esp_bluedroid_init(void);
/**
* @brief Deinit and free the resource for bluetooth, must be after every bluetooth stuff
@@ -52,7 +72,10 @@ esp_err_t esp_init_bluetooth(void);
* - ESP_OK : Succeed
* - Other : Failed
*/
esp_err_t esp_deinit_bluetooth(void);
esp_err_t esp_bluedroid_deinit(void);
#ifdef __cplusplus
}
#endif
#endif /* __ESP_BT_MAIN_H__ */

View File

@@ -21,44 +21,67 @@
#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_cb_event_t;
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_ADV_START_COMPLETE_EVT, /*!< When start advertising complete, the event comes */
ESP_GAP_BLE_SCAN_START_COMPLETE_EVT, /*!< When start scan complete, the event comes */
} esp_gap_ble_cb_event_t;
/// Advertising data maximum length
#define ESP_BLE_ADV_DATA_LEN_MAX 31
#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_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
@@ -74,7 +97,7 @@ typedef enum {
typedef enum {
ADV_CHNL_37 = 0x01,
ADV_CHNL_38 = 0x02,
ADV_CHNL_39 = 0x03,
ADV_CHNL_39 = 0x04,
ADV_CHNL_ALL = 0x07,
} esp_ble_adv_channel_t;
@@ -92,37 +115,37 @@ typedef enum {
/// 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 */
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 */
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
@@ -143,53 +166,53 @@ typedef enum {
/// Ble scan type
typedef enum {
BLE_SCAN_TYPE_PASSIVE = 0x0, /*!< Passive scan */
BLE_SCAN_TYPE_ACTIVE = 0x1, /*!< Active scan */
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_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 advertisers address is in the White list.
2. Directed advertising packets which are not addressed for this device shall be ignored. */
1. advertisement packets from devices where the advertisers 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. */
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 advertisers 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.*/
1. advertisement packets from devices where the advertisers 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_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_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
@@ -208,11 +231,11 @@ typedef enum {
* 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_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;
/**
@@ -223,36 +246,67 @@ 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 */
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 */
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 */
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]; /*!< 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 */
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 */
/**
* @brief ESP_GAP_BLE_ADV_START_COMPLETE_EVT
*/
struct ble_adv_start_cmpl_evt_param {
esp_bt_status_t status; /*!< Indicate advertising start operation success status */
} adv_start_cmpl; /*!< Event parameter of ESP_GAP_BLE_ADV_START_COMPLETE_EVT */
/**
* @brief ESP_GAP_BLE_SCAN_START_COMPLETE_EVT
*/
struct ble_scan_start_cmpl_evt_param {
esp_bt_status_t status; /*!< Indicate scan start operation success status */
} scan_start_cmpl; /*!< Event parameter of ESP_GAP_BLE_SCAN_START_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
*
@@ -263,7 +317,7 @@ typedef union {
* - other : failed
*
*/
esp_err_t esp_ble_gap_register_callback(esp_profile_cb_t callback);
esp_err_t esp_ble_gap_register_callback(esp_gap_ble_cb_t callback);
/**
@@ -416,9 +470,41 @@ esp_err_t esp_ble_gap_set_device_name(const char *name);
* @param[in] type - finding ADV data type
* @param[out] length - return the length of ADV data not including type
*
* @return pointer of ADV data
* @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__ */

View File

@@ -17,10 +17,146 @@
#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_CANCEL = 0x00, /*!< Prepare write cancel */
ESP_GATT_PREP_WRITE_EXEC = 0x01, /*!< Prepare write execute */
} esp_gatt_prep_write_type;
/**
@@ -77,23 +213,23 @@ typedef enum {
* @brief Gatt Connection reason enum
*/
typedef enum {
ESP_GATT_CONN_UNKNOWN = 0, /*!< Gatt connection unknown */
ESP_GATT_CONN_L2C_FAILURE = 1, /*!< General L2cap failure */
ESP_GATT_CONN_TIMEOUT = 0x08, /*!< Connection timeout */
ESP_GATT_CONN_TERMINATE_PEER_USER = 0x13, /*!< Connection terminate by peer user */
ESP_GATT_CONN_TERMINATE_LOCAL_HOST = 0x16, /*!< Connectionterminated by local host */
ESP_GATT_CONN_FAIL_ESTABLISH = 0x3e, /*!< Connection fail to establish */
ESP_GATT_CONN_LMP_TIMEOUT = 0x22, /*!< Connection fail for LMP response tout */
ESP_GATT_CONN_CONN_CANCEL = 0x0100, /*!< L2CAP connection cancelled */
ESP_GATT_CONN_NONE = 0x0101 /*!< No connection to cancel */
ESP_GATT_CONN_UNKNOWN = 0, /*!< Gatt connection unknown */
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 */
esp_bt_uuid_t uuid; /*!< UUID */
uint8_t inst_id; /*!< Instance id */
} __attribute__((packed)) esp_gatt_id_t;
/**
@@ -101,23 +237,19 @@ typedef struct {
* (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 */
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 {
AUTH_REQ_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 */
AUTH_REQ_PARTIAL_SCATTERNET, /* Device supports partial scatternet. It can have
simulateous connection in Master and Slave roles
for short period of time */
AUTH_REQ_FULL_SCATTERNET /* Device can have simultaneous connection in master
and slave roles */
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;
/**
@@ -149,29 +281,104 @@ typedef enum {
/// 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 */
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_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_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;
typedef uint32_t esp_gatt_if_t; /*!< Gatt interface type, different application on GATT client use different gatt_if */
#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__ */

137
components/bt/bluedroid/api/include/esp_gattc_api.h Executable file → Normal file
View File

@@ -15,11 +15,14 @@
#ifndef __ESP_GATTC_API_H__
#define __ESP_GATTC_API_H__
#include "bt_types.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 */
@@ -78,7 +81,6 @@ typedef union {
*/
struct gattc_reg_evt_param {
esp_gatt_status_t status; /*!< Operation status */
esp_gatt_if_t gatt_if; /*!< Gatt interface id, different application on gatt client different gatt_if */
uint16_t app_id; /*!< Application id which input in register API */
} reg; /*!< Gatt client callback param of ESP_GATTC_REG_EVT */
@@ -88,7 +90,6 @@ typedef union {
struct gattc_open_evt_param {
esp_gatt_status_t status; /*!< Operation status */
uint16_t conn_id; /*!< Connection id */
esp_gatt_if_t gatt_if; /*!< Gatt interface id, different application on gatt client different gatt_if */
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 */
@@ -99,7 +100,6 @@ typedef union {
struct gattc_close_evt_param {
esp_gatt_status_t status; /*!< Operation status */
uint16_t conn_id; /*!< Connection id */
esp_gatt_if_t gatt_if; /*!< Gatt interface id, different application on gatt client different gatt_if */
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 */
@@ -244,6 +244,14 @@ typedef union {
} 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
@@ -256,7 +264,7 @@ typedef union {
* - other: failed
*
*/
esp_err_t esp_ble_gattc_register_callback(esp_profile_cb_t callback);
esp_err_t esp_ble_gattc_register_callback(esp_gattc_cb_t callback);
/**
@@ -277,20 +285,20 @@ 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] gatt_if : app identifier.
* @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 gatt_if);
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] gatt_if: application identity.
* @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
*
@@ -299,12 +307,13 @@ esp_err_t esp_ble_gattc_app_unregister(esp_gatt_if_t gatt_if);
* - other: failed
*
*/
esp_err_t esp_ble_gattc_open(esp_gatt_if_t gatt_if, esp_bd_addr_t remote_bda, bool is_direct);
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
@@ -312,13 +321,14 @@ esp_err_t esp_ble_gattc_open(esp_gatt_if_t gatt_if, esp_bd_addr_t remote_bda, bo
* - other: failed
*
*/
esp_err_t esp_ble_gattc_close(uint16_t conn_id);
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.
*
@@ -327,7 +337,7 @@ esp_err_t esp_ble_gattc_close(uint16_t conn_id);
* - other: failed
*
*/
esp_err_t esp_ble_gattc_config_mtu(uint16_t conn_id, uint16_t mtu);
esp_err_t esp_ble_gattc_config_mtu (esp_gatt_if_t gattc_if, uint16_t conn_id, uint16_t mtu);
/**
@@ -336,6 +346,7 @@ esp_err_t esp_ble_gattc_config_mtu(uint16_t conn_id, uint16_t mtu);
* 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.
@@ -345,32 +356,32 @@ esp_err_t esp_ble_gattc_config_mtu(uint16_t conn_id, uint16_t mtu);
* - other: failed
*
*/
esp_err_t esp_ble_gattc_search_service(uint16_t conn_id, esp_bt_uuid_t *filter_uuid);
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(uint16_t conn_id,
esp_gatt_srvc_id_t *srvc_id, esp_gatt_id_t *start_char_id);
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
@@ -382,8 +393,10 @@ esp_err_t esp_ble_gattc_get_characteristic(uint16_t conn_id,
* - other: failed
*
*/
esp_err_t esp_ble_gattc_get_descriptor(uint16_t conn_id,
esp_gatt_srvc_id_t *srvc_id, esp_gatt_id_t *char_id,
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);
@@ -391,6 +404,7 @@ esp_err_t esp_ble_gattc_get_descriptor(uint16_t conn_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
@@ -400,14 +414,17 @@ esp_err_t esp_ble_gattc_get_descriptor(uint16_t conn_id,
* - other: failed
*
*/
esp_err_t esp_ble_gattc_get_included_service(uint16_t conn_id,
esp_gatt_srvc_id_t *srvc_id, esp_gatt_srvc_id_t *start_incl_srvc_id);
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 characteriistic ID
* 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.
@@ -418,15 +435,17 @@ esp_err_t esp_ble_gattc_get_included_service(uint16_t conn_id,
* - other: failed
*
*/
esp_err_t esp_ble_gattc_read_char (uint16_t conn_id,
esp_gatt_srvc_id_t *srvc_id,
esp_gatt_id_t *char_id,
esp_gatt_auth_req_t auth_req);
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.
@@ -438,16 +457,18 @@ esp_err_t esp_ble_gattc_read_char (uint16_t conn_id,
* - other: failed
*
*/
esp_err_t esp_ble_gattc_read_char_descr (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);
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.
@@ -461,7 +482,8 @@ esp_err_t esp_ble_gattc_read_char_descr (uint16_t conn_id,
* - other: failed
*
*/
esp_err_t esp_ble_gattc_write_char( uint16_t conn_id,
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,
@@ -473,6 +495,7 @@ esp_err_t esp_ble_gattc_write_char( uint16_t conn_id,
/**
* @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.
@@ -487,19 +510,21 @@ esp_err_t esp_ble_gattc_write_char( uint16_t conn_id,
* - other: failed
*
*/
esp_err_t esp_ble_gattc_write_char_descr (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);
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.
@@ -513,7 +538,8 @@ esp_err_t esp_ble_gattc_write_char_descr (uint16_t conn_id,
* - other: failed
*
*/
esp_err_t esp_ble_gattc_prepare_write(uint16_t conn_id,
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,
@@ -521,9 +547,11 @@ esp_err_t esp_ble_gattc_prepare_write(uint16_t conn_id,
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.
*
@@ -532,13 +560,13 @@ esp_err_t esp_ble_gattc_prepare_write(uint16_t conn_id,
* - other: failed
*
*/
esp_err_t esp_ble_gattc_execute_write (uint16_t conn_id, bool is_execute);
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] gatt_if : gatt interface id.
* @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.
@@ -548,16 +576,16 @@ esp_err_t esp_ble_gattc_execute_write (uint16_t conn_id, bool is_execute);
* - other: failed
*
*/
esp_gatt_status_t esp_ble_gattc_register_for_notify (esp_gatt_if_t gatt_if,
esp_bd_addr_t server_bda,
esp_gatt_srvc_id_t *srvc_id,
esp_gatt_id_t *char_id);
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] gatt_if : gatt interface id.
* @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.
@@ -567,10 +595,13 @@ esp_gatt_status_t esp_ble_gattc_register_for_notify (esp_gatt_if_t gatt_if,
* - other: failed
*
*/
esp_gatt_status_t esp_ble_gattc_unregister_for_notify (esp_gatt_if_t gatt_if,
esp_bd_addr_t server_bda,
esp_gatt_srvc_id_t *srvc_id,
esp_gatt_id_t *char_id);
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__ */

View File

@@ -15,37 +15,41 @@
#ifndef __ESP_GATTS_API_H__
#define __ESP_GATTS_API_H__
#include "bt_types.h"
#include "esp_bt_defs.h"
#include "esp_gatt_defs.h"
#include "bta_gatt_api.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_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;
/**
@@ -56,65 +60,66 @@ typedef union {
* @brief ESP_GATTS_REG_EVT
*/
struct gatts_reg_evt_param {
esp_gatt_status_t status; /*!< Operation status */
uint16_t gatt_if; /*!< Gatt interface id, different application on gatt client different gatt_if */
uint16_t app_id; /*!< Application id which input in register API */
} reg; /*!< Gatt server callback param of ESP_GATTS_REG_EVT */
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 */
} read; /*!< Gatt server callback param of ESP_GATTS_READ_EVT */
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 */
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
#define ESP_GATT_PREP_WRITE_EXEC 0x01
uint8_t exec_write_flag; /*!< Execute write flag */
} exec_write; /*!< Gatt server callback param of ESP_GATTS_EXEC_WRITE_EVT */
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 */
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) */
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
@@ -124,90 +129,81 @@ typedef union {
* @brief ESP_GATTS_CREATE_EVT
*/
struct gatts_create_evt_param {
esp_gatt_status_t status; /*!< Operation status */
uint16_t gatt_if; /*!< Gatt interface id, different application on gatt client different gatt_if */
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 */
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 gatt_if; /*!< Gatt interface id, different application on gatt client different gatt_if */
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 */
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 gatt_if; /*!< Gatt interface id, different application on gatt client different gatt_if */
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 */
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 gatt_if; /*!< Gatt interface id, different application on gatt client different gatt_if */
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 */
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 gatt_if; /*!< Gatt interface id, different application on gatt client different gatt_if */
uint16_t service_handle; /*!< Service attribute handle */
} del; /*!< Gatt server callback param of ESP_GATTS_DELETE_EVT */
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 gatt_if; /*!< Gatt interface id, different application on gatt client different gatt_if */
uint16_t service_handle; /*!< Service attribute handle */
} start; /*!< Gatt server callback param of ESP_GATTS_START_EVT */
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 gatt_if; /*!< Gatt interface id, different application on gatt client different gatt_if */
uint16_t service_handle; /*!< Service attribute handle */
} stop; /*!< Gatt server callback param of ESP_GATTS_STOP_EVT */
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 */
uint16_t gatt_if; /*!< Gatt interface id, different application on gatt client different gatt_if */
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 */
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 */
uint16_t gatt_if; /*!< Gatt interface id, different application on gatt client different gatt_if */
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 */
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
@@ -225,19 +221,49 @@ typedef union {
* @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 */
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 */
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.
@@ -247,9 +273,7 @@ typedef union {
* - other : failed
*
*/
esp_err_t esp_ble_gatts_register_callback(esp_profile_cb_t callback);
esp_err_t esp_ble_gatts_register_callback(esp_gatts_cb_t callback);
/**
* @brief This function is called to register application identifier
@@ -266,14 +290,13 @@ esp_err_t esp_ble_gatts_app_register(uint16_t app_id);
/**
* @brief unregister with GATT Server.
*
* @param[in] gatt_if: gatt interface id.
*
* @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 gatt_if);
esp_err_t esp_ble_gatts_app_unregister(esp_gatt_if_t gatts_if);
/**
@@ -283,7 +306,7 @@ esp_err_t esp_ble_gatts_app_unregister(esp_gatt_if_t gatt_if);
* the callback function needs to be used when adding included
* service and characteristics/descriptors into the service.
*
* @param[in] gatt_if: gatt interface ID
* @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.
*
@@ -292,11 +315,26 @@ esp_err_t esp_ble_gatts_app_unregister(esp_gatt_if_t gatt_if);
* - other : failed
*
*/
esp_err_t esp_ble_gatts_create_service(esp_gatt_if_t gatt_if,
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
@@ -323,6 +361,8 @@ esp_err_t esp_ble_gatts_add_included_service(uint16_t service_handle, uint16_t i
* @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
@@ -330,7 +370,8 @@ esp_err_t esp_ble_gatts_add_included_service(uint16_t service_handle, uint16_t i
*
*/
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_gatt_perm_t perm, esp_gatt_char_prop_t property, esp_attr_value_t *char_val,
esp_attr_control_t *control);
/**
@@ -342,15 +383,17 @@ esp_err_t esp_ble_gatts_add_char(uint16_t service_handle, esp_bt_uuid_t *char_
* 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_bt_uuid_t *descr_uuid,
esp_gatt_perm_t perm, esp_attr_value_t *char_descr_val,
esp_attr_control_t *control);
@@ -398,26 +441,30 @@ esp_err_t esp_ble_gatts_stop_service(uint16_t service_handle);
/**
* @brief This function is called to read a characteristics descriptor.
* @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 - if this indication expects a confirmation or not.
* @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(uint16_t conn_id, uint16_t attr_handle,
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
@@ -428,14 +475,43 @@ esp_err_t esp_ble_gatts_send_indicate(uint16_t conn_id, uint16_t attr_handle,
* - other : failed
*
*/
esp_err_t esp_ble_gatts_send_response(uint16_t conn_id, uint32_t trans_id,
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] gatt_if: application ID.
* @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
*
@@ -444,11 +520,12 @@ esp_err_t esp_ble_gatts_send_response(uint16_t conn_id, uint32_t trans_id,
* - other : failed
*
*/
esp_err_t esp_ble_gatts_open(esp_gatt_if_t gatt_if, esp_bd_addr_t remote_bda, bool is_direct);
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
@@ -456,7 +533,10 @@ esp_err_t esp_ble_gatts_open(esp_gatt_if_t gatt_if, esp_bd_addr_t remote_bda, bo
* - other : failed
*
*/
esp_err_t esp_ble_gatts_close(uint16_t conn_id);
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__ */

View File

@@ -62,18 +62,6 @@ static BOOLEAN bta_dm_check_av(UINT16 event);
static void bta_dm_bl_change_cback (tBTM_BL_EVENT_DATA *p_data);
#if BLE_INCLUDED == TRUE
static void bta_dm_acl_change_cback(BD_ADDR p_bda, DEV_CLASS p_dc,
BD_NAME p_bdn, UINT8 *features,
BOOLEAN is_new, UINT16 handle,
tBT_TRANSPORT transport);
#else
static void bta_dm_acl_change_cback(BD_ADDR p_bda, DEV_CLASS p_dc,
BD_NAME p_bdn, UINT8 *features,
BOOLEAN is_new);
#endif
static void bta_dm_policy_cback(tBTA_SYS_CONN_STATUS status, UINT8 id, UINT8 app_id, BD_ADDR peer_addr);
/* Extended Inquiry Response */
@@ -443,6 +431,10 @@ void bta_dm_disable (tBTA_DM_MSG *p_data)
bta_sys_start_timer(&bta_dm_cb.disable_timer, 0, 5000);
}
#if BLE_PRIVACY_SPT == TRUE
btm_ble_resolving_list_cleanup (); //by TH, because cmn_ble_vsc_cb.max_filter has something mistake as btm_ble_adv_filter_cleanup
#endif
}
/*******************************************************************************
@@ -1647,7 +1639,7 @@ void bta_dm_sdp_result (tBTA_DM_MSG *p_data)
if ( bta_dm_search_cb.p_sdp_db != NULL && bta_dm_search_cb.p_sdp_db->raw_used != 0 &&
bta_dm_search_cb.p_sdp_db->raw_data != NULL) {
APPL_TRACE_DEBUG(
"%s raw_data used = 0x%x raw_data_ptr = 0x%x", __func__,
"%s raw_data used = 0x%x raw_data_ptr = %p", __func__,
bta_dm_search_cb.p_sdp_db->raw_used,
bta_dm_search_cb.p_sdp_db->raw_data);
@@ -1991,7 +1983,6 @@ static void bta_dm_find_services ( BD_ADDR bd_addr)
{
tSDP_UUID uuid;
UINT16 num_attrs = 1;
tBTA_DM_MSG *p_msg;
memset (&uuid, 0, sizeof(tSDP_UUID));
@@ -2169,7 +2160,7 @@ static void bta_dm_discover_device(BD_ADDR remote_bd_addr)
bdcpy(bta_dm_search_cb.peer_bdaddr, remote_bd_addr);
APPL_TRACE_DEBUG("%s name_discover_done = %d p_btm_inq_info 0x%x state = %d, transport=%d",
APPL_TRACE_DEBUG("%s name_discover_done = %d p_btm_inq_info %p state = %d, transport=%d",
__func__,
bta_dm_search_cb.name_discover_done,
bta_dm_search_cb.p_btm_inq_info,
@@ -2231,7 +2222,7 @@ static void bta_dm_discover_device(BD_ADDR remote_bd_addr)
#if (BLE_INCLUDED == TRUE && (defined BTA_GATT_INCLUDED) && (BTA_GATT_INCLUDED == TRUE))
if ( bta_dm_search_cb.p_btm_inq_info ) {
APPL_TRACE_DEBUG("%s p_btm_inq_info 0x%x results.device_type 0x%x services_to_search 0x%x",
APPL_TRACE_DEBUG("%s p_btm_inq_info %p results.device_type 0x%x services_to_search 0x%x",
__func__,
bta_dm_search_cb.p_btm_inq_info,
bta_dm_search_cb.p_btm_inq_info->results.device_type,
@@ -2956,48 +2947,6 @@ static void bta_dm_bl_change_cback (tBTM_BL_EVENT_DATA *p_data)
}
/*******************************************************************************
**
** Function bta_dm_acl_change_cback
**
** Description Callback from btm when acl connection goes up or down
**
**
** Returns void
**
*******************************************************************************/
#if BLE_INCLUDED == TRUE
static void bta_dm_acl_change_cback(BD_ADDR p_bda, DEV_CLASS p_dc, BD_NAME p_bdn,
UINT8 *features, BOOLEAN is_new, UINT16 handle,
tBT_TRANSPORT transport)
#else
static void bta_dm_acl_change_cback(BD_ADDR p_bda, DEV_CLASS p_dc, BD_NAME p_bdn,
UINT8 *features, BOOLEAN is_new)
#endif
{
tBTA_DM_ACL_CHANGE *p_msg = (tBTA_DM_ACL_CHANGE *) GKI_getbuf(sizeof(tBTA_DM_ACL_CHANGE));
if (p_msg != NULL) {
memset(p_msg, 0, sizeof(tBTA_DM_ACL_CHANGE));
bdcpy(p_msg->bd_addr, p_bda);
p_msg->is_new = is_new;
#if BLE_INCLUDED == TRUE
p_msg->handle = handle;
p_msg->transport = transport;
#endif
/* This is collision case */
if (features != NULL) {
if ((features[0] == 0xFF) && !is_new) {
p_msg->event = BTM_BL_COLLISION_EVT;
}
}
p_msg->hdr.event = BTA_DM_ACL_CHANGE_EVT;
bta_sys_sendmsg(p_msg);
}
}
/*******************************************************************************
**
** Function bta_dm_rs_cback
@@ -4018,7 +3967,7 @@ void bta_dm_encrypt_cback(BD_ADDR bd_addr, tBT_TRANSPORT transport, void *p_ref_
break;
}
APPL_TRACE_DEBUG("bta_dm_encrypt_cback status =%d p_callback=0x%x", bta_status, p_callback);
APPL_TRACE_DEBUG("bta_dm_encrypt_cback status =%d p_callback=%p", bta_status, p_callback);
if (p_callback) {
(*p_callback)(bd_addr, transport, bta_status);
@@ -4150,8 +4099,6 @@ static UINT8 bta_dm_ble_smp_cback (tBTM_LE_EVT event, BD_ADDR bda, tBTM_LE_EVT_D
tBTM_STATUS status = BTM_SUCCESS;
tBTA_DM_SEC sec_event;
char *p_name = NULL;
UINT8 i;
tBT_DEVICE_TYPE dev_type;
if (!bta_dm_cb.p_sec_cback) {
return BTM_NOT_AUTHORIZED;
@@ -4587,12 +4534,11 @@ void bta_dm_ble_observe (tBTA_DM_MSG *p_data)
bta_dm_search_cb.p_scan_cback = p_data->ble_observe.p_cback;
if ((status = BTM_BleObserve(TRUE, p_data->ble_observe.duration,
bta_dm_observe_results_cb, bta_dm_observe_cmpl_cb)) != BTM_CMD_STARTED) {
tBTA_DM_SEARCH data;
APPL_TRACE_WARNING(" %s BTM_BleObserve failed. status %d\n", __FUNCTION__, status);
data.inq_cmpl.num_resps = 0;
if (bta_dm_search_cb.p_scan_cback) {
bta_dm_search_cb.p_scan_cback(BTA_DM_INQ_CMPL_EVT, &data);
}
}
if (p_data->ble_observe.p_start_scan_cback) {
status = (status == BTM_CMD_STARTED ? BTA_SUCCESS : BTA_FAILURE);
p_data->ble_observe.p_start_scan_cback(status);
}
} else {
bta_dm_search_cb.p_scan_cback = NULL;
@@ -4629,13 +4575,21 @@ void bta_dm_ble_set_adv_params (tBTA_DM_MSG *p_data)
*******************************************************************************/
void bta_dm_ble_set_adv_params_all (tBTA_DM_MSG *p_data)
{
BTM_BleSetAdvParamsStartAdv(p_data->ble_set_adv_params_all.adv_int_min,
tBTA_STATUS status = BTA_FAILURE;
if (BTM_BleSetAdvParamsStartAdv(p_data->ble_set_adv_params_all.adv_int_min,
p_data->ble_set_adv_params_all.adv_int_max,
p_data->ble_set_adv_params_all.adv_type,
p_data->ble_set_adv_params_all.addr_type_own,
p_data->ble_set_adv_params_all.p_dir_bda,
p_data->ble_set_adv_params_all.channel_map,
p_data->ble_set_adv_params_all.adv_filter_policy);
p_data->ble_set_adv_params_all.adv_filter_policy) == BTM_SUCCESS) {
status = BTA_SUCCESS;
}
if (p_data->ble_set_adv_params_all.p_start_adv_cback) {
(*p_data->ble_set_adv_params_all.p_start_adv_cback)(status);
}
}
/*******************************************************************************
@@ -4661,6 +4615,30 @@ void bta_dm_ble_set_adv_config (tBTA_DM_MSG *p_data)
}
}
/*******************************************************************************
**
** Function bta_dm_ble_set_adv_config_raw
**
** Description This function set the customized ADV data configuration
**
** Parameters:
**
*******************************************************************************/
void bta_dm_ble_set_adv_config_raw (tBTA_DM_MSG *p_data)
{
tBTA_STATUS status = BTA_FAILURE;
if (BTM_BleWriteAdvDataRaw(p_data->ble_set_adv_data_raw.p_raw_adv,
p_data->ble_set_adv_data_raw.raw_adv_len) == BTM_SUCCESS) {
status = BTA_SUCCESS;
}
if (p_data->ble_set_adv_data_raw.p_adv_data_cback) {
(*p_data->ble_set_adv_data_raw.p_adv_data_cback)(status);
}
}
/*******************************************************************************
**
** Function bta_dm_ble_set_scan_rsp
@@ -4684,6 +4662,29 @@ void bta_dm_ble_set_scan_rsp (tBTA_DM_MSG *p_data)
}
}
/*******************************************************************************
**
** Function bta_dm_ble_set_scan_rsp_raw
**
** Description This function set the raw scan response data
**
** Parameters:
**
*******************************************************************************/
void bta_dm_ble_set_scan_rsp_raw (tBTA_DM_MSG *p_data)
{
tBTA_STATUS status = BTA_FAILURE;
if (BTM_BleWriteScanRspRaw(p_data->ble_set_adv_data_raw.p_raw_adv,
p_data->ble_set_adv_data_raw.raw_adv_len) == BTM_SUCCESS) {
status = BTA_SUCCESS;
}
if (p_data->ble_set_adv_data_raw.p_adv_data_cback) {
(*p_data->ble_set_adv_data_raw.p_adv_data_cback)(status);
}
}
/*******************************************************************************
**
** Function bta_dm_ble_set_data_length
@@ -5255,7 +5256,7 @@ static void bta_dm_gatt_disc_result(tBTA_GATT_ID service_id)
if ( bta_dm_search_cb.ble_raw_used + sizeof(tBTA_GATT_ID) < bta_dm_search_cb.ble_raw_size ) {
APPL_TRACE_DEBUG("ADDING BLE SERVICE uuid=0x%x, ble_ptr = 0x%x, ble_raw_used = 0x%x",
APPL_TRACE_DEBUG("ADDING BLE SERVICE uuid=0x%x, ble_ptr = %p, ble_raw_used = 0x%x",
service_id.uuid.uu.uuid16, bta_dm_search_cb.p_ble_rawdata, bta_dm_search_cb.ble_raw_used);
if (bta_dm_search_cb.p_ble_rawdata) {

View File

@@ -1009,13 +1009,13 @@ void BTA_DmSetBleAdvParams (UINT16 adv_int_min, UINT16 adv_int_max,
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)
tBLE_BD_ADDR *p_dir_bda, tBTA_START_ADV_CMPL_CBACK p_start_adv_cb)
{
#if BLE_INCLUDED == TRUE
tBTA_DM_API_BLE_ADV_PARAMS_ALL *p_msg;
APPL_TRACE_ERROR ("BTA_DmSetBleAdvParamsAll: %d, %d\n", adv_int_min, adv_int_max);
APPL_TRACE_ERROR ("adv_type = %d, addr_type_own = %d, chnl_map = %d, adv_fil_pol = %d\n",
APPL_TRACE_API ("BTA_DmSetBleAdvParamsAll: %d, %d\n", adv_int_min, adv_int_max);
APPL_TRACE_API ("adv_type = %d, addr_type_own = %d, chnl_map = %d, adv_fil_pol = %d\n",
adv_type, addr_type_own, chnl_map, adv_fil_pol);
if ((p_msg = (tBTA_DM_API_BLE_ADV_PARAMS_ALL *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_ADV_PARAMS_ALL)
+ sizeof(tBLE_BD_ADDR))) != NULL) {
@@ -1029,6 +1029,7 @@ void BTA_DmSetBleAdvParamsAll (UINT16 adv_int_min, UINT16 adv_int_max,
p_msg->addr_type_own = addr_type_own;
p_msg->channel_map = chnl_map;
p_msg->adv_filter_policy = adv_fil_pol;
p_msg->p_start_adv_cback = p_start_adv_cb;
if (p_dir_bda != NULL) {
p_msg->p_dir_bda = (tBLE_BD_ADDR *)(p_msg + 1);
memcpy(p_msg->p_dir_bda, p_dir_bda, sizeof(tBLE_BD_ADDR));
@@ -1077,6 +1078,35 @@ void BTA_DmBleSetAdvConfig (tBTA_BLE_AD_MASK data_mask, tBTA_BLE_ADV_DATA *p_adv
}
}
/*******************************************************************************
**
** 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
**
*******************************************************************************/
void BTA_DmBleSetAdvConfigRaw (UINT8 *p_raw_adv, UINT32 raw_adv_len,
tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback)
{
tBTA_DM_API_SET_ADV_CONFIG_RAW *p_msg;
if ((p_msg = (tBTA_DM_API_SET_ADV_CONFIG_RAW *)
GKI_getbuf(sizeof(tBTA_DM_API_SET_ADV_CONFIG_RAW))) != NULL) {
p_msg->hdr.event = BTA_DM_API_BLE_SET_ADV_CONFIG_RAW_EVT;
p_msg->p_adv_data_cback = p_adv_data_cback;
p_msg->p_raw_adv = p_raw_adv;
p_msg->raw_adv_len = raw_adv_len;
bta_sys_sendmsg(p_msg);
}
}
/*******************************************************************************
**
** Function BTA_DmBleSetScanRsp
@@ -1104,6 +1134,35 @@ extern void BTA_DmBleSetScanRsp (tBTA_BLE_AD_MASK data_mask, tBTA_BLE_ADV_DATA *
}
}
/*******************************************************************************
**
** 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
**
*******************************************************************************/
void BTA_DmBleSetScanRspRaw (UINT8 *p_raw_scan_rsp, UINT32 raw_scan_rsp_len,
tBTA_SET_ADV_DATA_CMPL_CBACK *p_scan_rsp_data_cback)
{
tBTA_DM_API_SET_ADV_CONFIG_RAW *p_msg;
if ((p_msg = (tBTA_DM_API_SET_ADV_CONFIG_RAW *)
GKI_getbuf(sizeof(tBTA_DM_API_SET_ADV_CONFIG_RAW))) != NULL) {
p_msg->hdr.event = BTA_DM_API_BLE_SET_SCAN_RSP_RAW_EVT;
p_msg->p_adv_data_cback = p_scan_rsp_data_cback;
p_msg->p_raw_adv = p_raw_scan_rsp;
p_msg->raw_adv_len = raw_scan_rsp_len;
bta_sys_sendmsg(p_msg);
}
}
/*******************************************************************************
**
** Function BTA_DmBleSetStorageParams
@@ -2069,7 +2128,8 @@ void BTA_DmCloseACL(BD_ADDR bd_addr, BOOLEAN remove_dev, tBTA_TRANSPORT transpor
**
*******************************************************************************/
extern void BTA_DmBleObserve(BOOLEAN start, UINT8 duration,
tBTA_DM_SEARCH_CBACK *p_results_cb)
tBTA_DM_SEARCH_CBACK *p_results_cb,
tBTA_START_SCAN_CMPL_CBACK *p_start_scan_cb)
{
tBTA_DM_API_BLE_OBSERVE *p_msg;
@@ -2082,6 +2142,7 @@ extern void BTA_DmBleObserve(BOOLEAN start, UINT8 duration,
p_msg->start = start;
p_msg->duration = duration;
p_msg->p_cback = p_results_cb;
p_msg->p_start_scan_cback = p_start_scan_cb;
bta_sys_sendmsg(p_msg);
}
@@ -2168,12 +2229,16 @@ void BTA_VendorCleanup (void)
BTM_BleGetVendorCapabilities(&cmn_ble_vsc_cb);
#if (BLE_INCLUDED == TRUE && BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE)
btm_ble_adv_filter_cleanup(); // when BLE_VND_INCLUDED is false, this function will be ignore, so move it out of "if"
#if 0 //by TH, comment out temporarily
if (cmn_ble_vsc_cb.max_filter > 0) {
btm_ble_adv_filter_cleanup();
#if BLE_PRIVACY_SPT == TRUE
btm_ble_resolving_list_cleanup ();
#endif
}
#endif
if (cmn_ble_vsc_cb.tot_scan_results_strg > 0) {
btm_ble_batchscan_cleanup();

View File

@@ -109,7 +109,11 @@ enum {
support setting the ble advertising param by the APP******/
BTA_DM_API_BLE_ADV_PARAM_All_EVT,
BTA_DM_API_BLE_SET_ADV_CONFIG_EVT,
/* Add for set raw advertising data */
BTA_DM_API_BLE_SET_ADV_CONFIG_RAW_EVT,
BTA_DM_API_BLE_SET_SCAN_RSP_EVT,
/* Add for set raw scan response data */
BTA_DM_API_BLE_SET_SCAN_RSP_RAW_EVT,
BTA_DM_API_BLE_BROADCAST_EVT,
BTA_DM_API_SET_DATA_LENGTH_EVT,
@@ -467,7 +471,8 @@ typedef struct {
BT_HDR hdr;
BOOLEAN start;
UINT16 duration;
tBTA_DM_SEARCH_CBACK *p_cback;
tBTA_DM_SEARCH_CBACK *p_cback;
tBTA_START_SCAN_CMPL_CBACK *p_start_scan_cback;
} tBTA_DM_API_BLE_OBSERVE;
typedef struct {
@@ -502,6 +507,7 @@ typedef struct {
tBTM_BLE_ADV_CHNL_MAP channel_map;
tBTM_BLE_AFP adv_filter_policy;
tBLE_BD_ADDR *p_dir_bda;
tBTA_START_ADV_CMPL_CBACK *p_start_adv_cback;
} tBTA_DM_API_BLE_ADV_PARAMS_ALL;
@@ -545,6 +551,15 @@ typedef struct {
tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback;
} tBTA_DM_API_SET_ADV_CONFIG;
/* raw scan response and raw advertising data use
the same structure */
typedef struct {
BT_HDR hdr;
UINT8 *p_raw_adv;
UINT32 raw_adv_len;
tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback;
} tBTA_DM_API_SET_ADV_CONFIG_RAW;
typedef struct {
BT_HDR hdr;
UINT8 batch_scan_full_max;
@@ -708,6 +723,7 @@ typedef union {
tBTA_DM_API_BLE_ADV_PARAMS ble_set_adv_params;
tBTA_DM_API_BLE_ADV_PARAMS_ALL ble_set_adv_params_all;
tBTA_DM_API_SET_ADV_CONFIG ble_set_adv_data;
tBTA_DM_API_SET_ADV_CONFIG_RAW ble_set_adv_data_raw;
#if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE
tBTA_DM_API_SCAN_FILTER_PARAM_SETUP ble_scan_filt_param_setup;
tBTA_DM_API_CFG_FILTER_COND ble_cfg_filter_cond;
@@ -1093,9 +1109,11 @@ extern void bta_dm_ble_set_rand_address(tBTA_DM_MSG *p_data);
extern void bta_dm_ble_stop_advertising(tBTA_DM_MSG *p_data);
extern void bta_dm_ble_config_local_privacy (tBTA_DM_MSG *p_data);
extern void bta_dm_ble_set_adv_params (tBTA_DM_MSG *p_data);
extern void bta_dm_ble_set_adv_params_all (tBTA_DM_MSG *p_data);
extern void bta_dm_ble_set_adv_params_all(tBTA_DM_MSG *p_data);
extern void bta_dm_ble_set_adv_config (tBTA_DM_MSG *p_data);
extern void bta_dm_ble_set_adv_config_raw (tBTA_DM_MSG *p_data);
extern void bta_dm_ble_set_scan_rsp (tBTA_DM_MSG *p_data);
extern void bta_dm_ble_set_scan_rsp_raw (tBTA_DM_MSG *p_data);
extern void bta_dm_ble_broadcast (tBTA_DM_MSG *p_data);
extern void bta_dm_ble_set_data_length(tBTA_DM_MSG *p_data);

View File

@@ -47,86 +47,95 @@ typedef void (*tBTA_DM_ACTION)(tBTA_DM_MSG *p_data);
const tBTA_DM_ACTION bta_dm_action[BTA_DM_MAX_EVT] = {
/* device manager local device API events */
bta_dm_enable, /* 0 BTA_DM_API_ENABLE_EVT */
bta_dm_disable, /* 1 BTA_DM_API_DISABLE_EVT */
bta_dm_set_dev_name, /* 2 BTA_DM_API_SET_NAME_EVT */
bta_dm_set_visibility, /* 3 BTA_DM_API_SET_VISIBILITY_EVT */
bta_dm_acl_change, /* 8 BTA_DM_ACL_CHANGE_EVT */
bta_dm_add_device, /* 9 BTA_DM_API_ADD_DEVICE_EVT */
bta_dm_close_acl, /* 10 BTA_DM_API_ADD_DEVICE_EVT */
bta_dm_enable, /* 0 BTA_DM_API_ENABLE_EVT */
bta_dm_disable, /* 1 BTA_DM_API_DISABLE_EVT */
bta_dm_set_dev_name, /* 2 BTA_DM_API_SET_NAME_EVT */
bta_dm_set_visibility, /* 3 BTA_DM_API_SET_VISIBILITY_EVT */
bta_dm_acl_change, /* 8 BTA_DM_ACL_CHANGE_EVT */
bta_dm_add_device, /* 9 BTA_DM_API_ADD_DEVICE_EVT */
bta_dm_close_acl, /* 10 BTA_DM_API_ADD_DEVICE_EVT */
/* security API events */
bta_dm_bond, /* 11 BTA_DM_API_BOND_EVT */
bta_dm_bond_cancel, /* 12 BTA_DM_API_BOND_CANCEL_EVT */
bta_dm_pin_reply, /* 13 BTA_DM_API_PIN_REPLY_EVT */
bta_dm_bond, /* 11 BTA_DM_API_BOND_EVT */
bta_dm_bond_cancel, /* 12 BTA_DM_API_BOND_CANCEL_EVT */
bta_dm_pin_reply, /* 13 BTA_DM_API_PIN_REPLY_EVT */
/* power manger events */
bta_dm_pm_btm_status, /* 16 BTA_DM_PM_BTM_STATUS_EVT */
bta_dm_pm_timer, /* 17 BTA_DM_PM_TIMER_EVT*/
bta_dm_pm_btm_status, /* 16 BTA_DM_PM_BTM_STATUS_EVT */
bta_dm_pm_timer, /* 17 BTA_DM_PM_TIMER_EVT*/
/* simple pairing events */
bta_dm_confirm, /* 18 BTA_DM_API_CONFIRM_EVT */
bta_dm_confirm, /* 18 BTA_DM_API_CONFIRM_EVT */
bta_dm_set_encryption, /* BTA_DM_API_SET_ENCRYPTION_EVT */
bta_dm_set_encryption, /* BTA_DM_API_SET_ENCRYPTION_EVT */
#if (BTM_OOB_INCLUDED == TRUE)
bta_dm_loc_oob, /* 20 BTA_DM_API_LOC_OOB_EVT */
bta_dm_ci_io_req_act, /* 21 BTA_DM_CI_IO_REQ_EVT */
bta_dm_ci_rmt_oob_act, /* 22 BTA_DM_CI_RMT_OOB_EVT */
bta_dm_loc_oob, /* 20 BTA_DM_API_LOC_OOB_EVT */
bta_dm_ci_io_req_act, /* 21 BTA_DM_CI_IO_REQ_EVT */
bta_dm_ci_rmt_oob_act, /* 22 BTA_DM_CI_RMT_OOB_EVT */
#endif /* BTM_OOB_INCLUDED */
#if BLE_INCLUDED == TRUE
bta_dm_add_blekey, /* BTA_DM_API_ADD_BLEKEY_EVT */
bta_dm_add_ble_device, /* BTA_DM_API_ADD_BLEDEVICE_EVT */
bta_dm_ble_passkey_reply, /* BTA_DM_API_BLE_PASSKEY_REPLY_EVT */
bta_dm_ble_confirm_reply, /* BTA_DM_API_BLE_CONFIRM_REPLY_EVT */
bta_dm_add_blekey, /* BTA_DM_API_ADD_BLEKEY_EVT */
bta_dm_add_ble_device, /* BTA_DM_API_ADD_BLEDEVICE_EVT */
bta_dm_ble_passkey_reply, /* BTA_DM_API_BLE_PASSKEY_REPLY_EVT */
bta_dm_ble_confirm_reply, /* BTA_DM_API_BLE_CONFIRM_REPLY_EVT */
bta_dm_security_grant,
bta_dm_ble_set_bg_conn_type,
bta_dm_ble_set_conn_params, /* BTA_DM_API_BLE_CONN_PARAM_EVT */
bta_dm_ble_set_conn_scan_params, /* BTA_DM_API_BLE_CONN_SCAN_PARAM_EVT */
bta_dm_ble_set_scan_params, /* BTA_DM_API_BLE_SCAN_PARAM_EVT */
bta_dm_ble_set_scan_fil_params, /* BTA_DM_API_BLE_SCAN_FIL_PARAM_EVT */
bta_dm_ble_observe, /* BTA_DM_API_BLE_OBSERVE_EVT*/
bta_dm_ble_update_conn_params, /* BTA_DM_API_UPDATE_CONN_PARAM_EVT */
/*******This handler function added by Yulong at 2016/9/9 to
support the random address setting for the APP******/
bta_dm_ble_set_rand_address, /*BTA_DM_API_SET_RAND_ADDR_EVT*/
/*******This handler function added by Yulong at 2016/10/19 to
support stop the ble advertising setting by the APP******/
bta_dm_ble_stop_advertising, /*BTA_DM_API_BLE_STOP_ADV_EVT*/
bta_dm_ble_set_conn_params, /* BTA_DM_API_BLE_CONN_PARAM_EVT */
bta_dm_ble_set_conn_scan_params, /* BTA_DM_API_BLE_CONN_SCAN_PARAM_EVT */
bta_dm_ble_set_scan_params, /* BTA_DM_API_BLE_SCAN_PARAM_EVT */
bta_dm_ble_set_scan_fil_params, /* BTA_DM_API_BLE_SCAN_FIL_PARAM_EVT */
bta_dm_ble_observe, /* BTA_DM_API_BLE_OBSERVE_EVT*/
bta_dm_ble_update_conn_params, /* BTA_DM_API_UPDATE_CONN_PARAM_EVT */
/* This handler function added by
Yulong at 2016/9/9 to support the
random address setting for the APP */
bta_dm_ble_set_rand_address, /* BTA_DM_API_SET_RAND_ADDR_EVT*/
/* This handler function added by
Yulong at 2016/10/19 to support
stop the ble advertising setting
by the APP */
bta_dm_ble_stop_advertising, /* BTA_DM_API_BLE_STOP_ADV_EVT*/
#if BLE_PRIVACY_SPT == TRUE
bta_dm_ble_config_local_privacy, /* BTA_DM_API_LOCAL_PRIVACY_EVT */
bta_dm_ble_config_local_privacy, /* BTA_DM_API_LOCAL_PRIVACY_EVT */
#endif
bta_dm_ble_set_adv_params, /* BTA_DM_API_BLE_ADV_PARAM_EVT */
bta_dm_ble_set_adv_params_all, /* BTA_DM_API_BLE_ADV_PARAM_All_EVT */
bta_dm_ble_set_adv_config, /* BTA_DM_API_BLE_SET_ADV_CONFIG_EVT */
bta_dm_ble_set_scan_rsp, /* BTA_DM_API_BLE_SET_SCAN_RSPT */
bta_dm_ble_broadcast, /* BTA_DM_API_BLE_BROADCAST_EVT */
bta_dm_ble_set_data_length, /* BTA_DM_API_SET_DATA_LENGTH_EVT */
bta_dm_ble_set_adv_params, /* BTA_DM_API_BLE_ADV_PARAM_EVT */
bta_dm_ble_set_adv_params_all, /* BTA_DM_API_BLE_ADV_PARAM_All_EVT */
bta_dm_ble_set_adv_config, /* BTA_DM_API_BLE_SET_ADV_CONFIG_EVT */
/* New function to allow set raw adv
data to HCI */
bta_dm_ble_set_adv_config_raw, /* BTA_DM_API_BLE_SET_ADV_CONFIG_RAW_EVT */
bta_dm_ble_set_scan_rsp, /* BTA_DM_API_BLE_SET_SCAN_RSP_EVT */
/* New function to allow set raw scan
response data to HCI */
bta_dm_ble_set_scan_rsp_raw, /* BTA_DM_API_BLE_SET_SCAN_RSP_RAW_EVT */
bta_dm_ble_broadcast, /* BTA_DM_API_BLE_BROADCAST_EVT */
bta_dm_ble_set_data_length, /* BTA_DM_API_SET_DATA_LENGTH_EVT */
#if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE
bta_dm_cfg_filter_cond, /* BTA_DM_API_CFG_FILTER_COND_EVT */
bta_dm_scan_filter_param_setup, /* BTA_DM_API_SCAN_FILTER_SETUP_EVT */
bta_dm_enable_scan_filter, /* BTA_DM_API_SCAN_FILTER_ENABLE_EVT */
bta_dm_cfg_filter_cond, /* BTA_DM_API_CFG_FILTER_COND_EVT */
bta_dm_scan_filter_param_setup, /* BTA_DM_API_SCAN_FILTER_SETUP_EVT */
bta_dm_enable_scan_filter, /* BTA_DM_API_SCAN_FILTER_ENABLE_EVT */
#endif
bta_dm_ble_multi_adv_enb, /* BTA_DM_API_BLE_MULTI_ADV_ENB_EVT*/
bta_dm_ble_multi_adv_upd_param, /* BTA_DM_API_BLE_MULTI_ADV_PARAM_UPD_EVT */
bta_dm_ble_multi_adv_data, /* BTA_DM_API_BLE_MULTI_ADV_DATA_EVT */
btm_dm_ble_multi_adv_disable, /* BTA_DM_API_BLE_MULTI_ADV_DISABLE_EVT */
bta_dm_ble_setup_storage, /* BTA_DM_API_BLE_SETUP_STORAGE_EVT */
bta_dm_ble_enable_batch_scan, /* BTA_DM_API_BLE_ENABLE_BATCH_SCAN_EVT */
bta_dm_ble_disable_batch_scan, /* BTA_DM_API_BLE_DISABLE_BATCH_SCAN_EVT */
bta_dm_ble_read_scan_reports, /* BTA_DM_API_BLE_READ_SCAN_REPORTS_EVT */
bta_dm_ble_track_advertiser, /* BTA_DM_API_BLE_TRACK_ADVERTISER_EVT */
bta_dm_ble_get_energy_info, /* BTA_DM_API_BLE_ENERGY_INFO_EVT */
bta_dm_ble_multi_adv_enb, /* BTA_DM_API_BLE_MULTI_ADV_ENB_EVT*/
bta_dm_ble_multi_adv_upd_param, /* BTA_DM_API_BLE_MULTI_ADV_PARAM_UPD_EVT */
bta_dm_ble_multi_adv_data, /* BTA_DM_API_BLE_MULTI_ADV_DATA_EVT */
btm_dm_ble_multi_adv_disable, /* BTA_DM_API_BLE_MULTI_ADV_DISABLE_EVT */
bta_dm_ble_setup_storage, /* BTA_DM_API_BLE_SETUP_STORAGE_EVT */
bta_dm_ble_enable_batch_scan, /* BTA_DM_API_BLE_ENABLE_BATCH_SCAN_EVT */
bta_dm_ble_disable_batch_scan, /* BTA_DM_API_BLE_DISABLE_BATCH_SCAN_EVT */
bta_dm_ble_read_scan_reports, /* BTA_DM_API_BLE_READ_SCAN_REPORTS_EVT */
bta_dm_ble_track_advertiser, /* BTA_DM_API_BLE_TRACK_ADVERTISER_EVT */
bta_dm_ble_get_energy_info, /* BTA_DM_API_BLE_ENERGY_INFO_EVT */
#endif
bta_dm_enable_test_mode, /* BTA_DM_API_ENABLE_TEST_MODE_EVT */
bta_dm_disable_test_mode, /* BTA_DM_API_DISABLE_TEST_MODE_EVT */
bta_dm_execute_callback, /* BTA_DM_API_EXECUTE_CBACK_EVT */
bta_dm_enable_test_mode, /* BTA_DM_API_ENABLE_TEST_MODE_EVT */
bta_dm_disable_test_mode, /* BTA_DM_API_DISABLE_TEST_MODE_EVT */
bta_dm_execute_callback, /* BTA_DM_API_EXECUTE_CBACK_EVT */
bta_dm_remove_all_acl, /* BTA_DM_API_REMOVE_ALL_ACL_EVT */
bta_dm_remove_device, /* BTA_DM_API_REMOVE_DEVICE_EVT */
bta_dm_remove_all_acl, /* BTA_DM_API_REMOVE_ALL_ACL_EVT */
bta_dm_remove_device, /* BTA_DM_API_REMOVE_DEVICE_EVT */
};
@@ -161,24 +170,24 @@ enum {
/* action function list */
const tBTA_DM_ACTION bta_dm_search_action[] = {
bta_dm_search_start, /* 0 BTA_DM_API_SEARCH */
bta_dm_search_cancel, /* 1 BTA_DM_API_SEARCH_CANCEL */
bta_dm_discover, /* 2 BTA_DM_API_DISCOVER */
bta_dm_inq_cmpl, /* 3 BTA_DM_INQUIRY_CMPL */
bta_dm_rmt_name, /* 4 BTA_DM_REMT_NAME */
bta_dm_sdp_result, /* 5 BTA_DM_SDP_RESULT */
bta_dm_search_cmpl, /* 6 BTA_DM_SEARCH_CMPL */
bta_dm_free_sdp_db, /* 7 BTA_DM_FREE_SDP_DB */
bta_dm_disc_result, /* 8 BTA_DM_DISC_RESULT */
bta_dm_search_result, /* 9 BTA_DM_SEARCH_RESULT */
bta_dm_queue_search, /* 10 BTA_DM_QUEUE_SEARCH */
bta_dm_queue_disc, /* 11 BTA_DM_QUEUE_DISC */
bta_dm_search_clear_queue, /* 12 BTA_DM_SEARCH_CLEAR_QUEUE */
bta_dm_search_cancel_cmpl, /* 13 BTA_DM_SEARCH_CANCEL_CMPL */
bta_dm_search_cancel_notify, /* 14 BTA_DM_SEARCH_CANCEL_NOTIFY */
bta_dm_search_cancel_transac_cmpl, /* 15 BTA_DM_SEARCH_CANCEL_TRANSAC_CMPL */
bta_dm_disc_rmt_name, /* 16 BTA_DM_DISC_RMT_NAME */
bta_dm_di_disc /* 17 BTA_DM_API_DI_DISCOVER */
bta_dm_search_start, /* 0 BTA_DM_API_SEARCH */
bta_dm_search_cancel, /* 1 BTA_DM_API_SEARCH_CANCEL */
bta_dm_discover, /* 2 BTA_DM_API_DISCOVER */
bta_dm_inq_cmpl, /* 3 BTA_DM_INQUIRY_CMPL */
bta_dm_rmt_name, /* 4 BTA_DM_REMT_NAME */
bta_dm_sdp_result, /* 5 BTA_DM_SDP_RESULT */
bta_dm_search_cmpl, /* 6 BTA_DM_SEARCH_CMPL */
bta_dm_free_sdp_db, /* 7 BTA_DM_FREE_SDP_DB */
bta_dm_disc_result, /* 8 BTA_DM_DISC_RESULT */
bta_dm_search_result, /* 9 BTA_DM_SEARCH_RESULT */
bta_dm_queue_search, /* 10 BTA_DM_QUEUE_SEARCH */
bta_dm_queue_disc, /* 11 BTA_DM_QUEUE_DISC */
bta_dm_search_clear_queue, /* 12 BTA_DM_SEARCH_CLEAR_QUEUE */
bta_dm_search_cancel_cmpl, /* 13 BTA_DM_SEARCH_CANCEL_CMPL */
bta_dm_search_cancel_notify, /* 14 BTA_DM_SEARCH_CANCEL_NOTIFY */
bta_dm_search_cancel_transac_cmpl, /* 15 BTA_DM_SEARCH_CANCEL_TRANSAC_CMPL */
bta_dm_disc_rmt_name, /* 16 BTA_DM_DISC_RMT_NAME */
bta_dm_di_disc /* 17 BTA_DM_API_DI_DISCOVER */
#if BLE_INCLUDED == TRUE
, bta_dm_close_gatt_conn
#endif

View File

@@ -337,7 +337,6 @@ static void bta_dm_pm_cback(tBTA_SYS_CONN_STATUS status, UINT8 id, UINT8 app_id,
{
UINT8 i, j;
UINT16 policy_setting;
UINT8 *p = NULL;
tBTA_DM_PEER_DEVICE *p_dev;

View File

@@ -34,7 +34,6 @@
#include "bta_gatts_int.h"
#include "bta_gatts_co.h"
#include "btm_ble_api.h"
// #include "btif/include/btif_debug_conn.h"
#include <string.h>
static void bta_gatts_nv_save_cback(BOOLEAN is_saved, tGATTS_HNDL_RANGE *p_hndl_range);
@@ -233,8 +232,6 @@ void bta_gatts_register(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg)
if (p_msg->api_reg.p_cback) {
(*p_msg->api_reg.p_cback)(BTA_GATTS_REG_EVT, &cb_data);
}
LOG_ERROR("status=%x\n", status);
}
@@ -406,10 +403,22 @@ void bta_gatts_add_char(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_msg)
UINT16 attr_id = 0;
tBTA_GATTS cb_data;
tGATT_ATTR_VAL *p_attr_val = NULL;
tGATTS_ATTR_CONTROL *p_control = NULL;
if(p_msg->api_add_char.attr_val.attr_max_len != 0){
p_attr_val = &p_msg->api_add_char.attr_val;
}
if(p_msg->api_add_char.control.auto_rsp != 0){
p_control = &p_msg->api_add_char.control;
}
attr_id = GATTS_AddCharacteristic(p_msg->api_add_char.hdr.layer_specific,
&p_msg->api_add_char.char_uuid,
p_msg->api_add_char.perm,
p_msg->api_add_char.property);
p_msg->api_add_char.property, p_attr_val, p_control);
cb_data.add_result.server_if = p_rcb->gatt_if;
cb_data.add_result.service_id = p_msg->api_add_incl_srvc.hdr.layer_specific;
cb_data.add_result.attr_id = attr_id;
@@ -422,11 +431,15 @@ void bta_gatts_add_char(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_msg)
} else {
cb_data.add_result.status = BTA_GATT_ERROR;
}
if((p_attr_val != NULL) && (p_attr_val->attr_val != NULL)){
GKI_freebuf(p_attr_val->attr_val);
}
if (p_rcb->p_cback) {
(*p_rcb->p_cback)(BTA_GATTS_ADD_CHAR_EVT, &cb_data);
}
}
/*******************************************************************************
**
** Function bta_gatts_add_char_descr
@@ -441,10 +454,20 @@ void bta_gatts_add_char_descr(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_
tBTA_GATTS_RCB *p_rcb = &bta_gatts_cb.rcb[p_srvc_cb->rcb_idx];
UINT16 attr_id = 0;
tBTA_GATTS cb_data;
tGATT_ATTR_VAL *p_attr_val = NULL;
tGATTS_ATTR_CONTROL *p_control = NULL;
if (p_msg->api_add_char_descr.attr_val.attr_max_len != 0) {
p_attr_val = &p_msg->api_add_char_descr.attr_val;
}
if (p_msg->api_add_char_descr.control.auto_rsp != 0) {
p_control = &p_msg->api_add_char_descr.control;
}
attr_id = GATTS_AddCharDescriptor(p_msg->api_add_char_descr.hdr.layer_specific,
p_msg->api_add_char_descr.perm,
&p_msg->api_add_char_descr.descr_uuid);
&p_msg->api_add_char_descr.descr_uuid, p_attr_val,
p_control);
cb_data.add_result.server_if = p_rcb->gatt_if;
cb_data.add_result.service_id = p_msg->api_add_incl_srvc.hdr.layer_specific;
@@ -458,12 +481,50 @@ void bta_gatts_add_char_descr(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_
} else {
cb_data.add_result.status = BTA_GATT_ERROR;
}
if((p_attr_val != NULL) && (p_attr_val->attr_val != NULL)){
GKI_freebuf(p_attr_val->attr_val);
}
if (p_rcb->p_cback) {
(*p_rcb->p_cback)(BTA_GATTS_ADD_CHAR_DESCR_EVT, &cb_data);
}
}
/*******************************************************************************
**
** Function bta_gatts_add_char_descr
**
** Description action function to add characteristic descriptor.
**
** Returns none.
**
*******************************************************************************/
void bta_gatts_set_attr_value(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_msg)
{
tBTA_GATTS_RCB *p_rcb = &bta_gatts_cb.rcb[p_srvc_cb->rcb_idx];
UINT16 attr_id = 0;
tBTA_GATTS cb_data;
tBTA_GATT_STATUS gatts_status;
gatts_status = GATTS_SetAttributeValue(p_msg->api_add_char_descr.hdr.layer_specific,
p_msg->api_set_val.length,
p_msg->api_set_val.value);
cb_data.attr_val.server_if = p_rcb->gatt_if;
cb_data.attr_val.service_id = p_msg->api_set_val.hdr.layer_specific;
cb_data.attr_val.attr_id = attr_id;
cb_data.attr_val.status = gatts_status;
if (p_rcb->p_cback) {
(*p_rcb->p_cback)(BTA_GATTS_SET_ATTR_VAL_EVT, &cb_data);
}
}
void bta_gatts_get_attr_value(UINT16 attr_handle, UINT16 *length, UINT8 **value)
{
GATTS_GetAttributeValue(attr_handle, length, value);
}
/*******************************************************************************
**
** Function bta_gatts_delete_service

View File

@@ -215,10 +215,14 @@ void BTA_GATTS_AddIncludeService(UINT16 service_id, UINT16 included_service_id)
**
*******************************************************************************/
void BTA_GATTS_AddCharacteristic (UINT16 service_id, tBT_UUID *p_char_uuid,
tBTA_GATT_PERM perm, tBTA_GATT_CHAR_PROP property)
tBTA_GATT_PERM perm, tBTA_GATT_CHAR_PROP property, tGATT_ATTR_VAL *attr_val,
tBTA_GATTS_ATTR_CONTROL *control)
{
tBTA_GATTS_API_ADD_CHAR *p_buf;
UINT16 len = 0;
if(attr_val != NULL){
len = attr_val->attr_len;
}
if ((p_buf = (tBTA_GATTS_API_ADD_CHAR *) GKI_getbuf(sizeof(tBTA_GATTS_API_ADD_CHAR))) != NULL) {
memset(p_buf, 0, sizeof(tBTA_GATTS_API_ADD_CHAR));
@@ -226,6 +230,19 @@ void BTA_GATTS_AddCharacteristic (UINT16 service_id, tBT_UUID *p_char_uuid,
p_buf->hdr.layer_specific = service_id;
p_buf->perm = perm;
p_buf->property = property;
if(control !=NULL){
p_buf->control.auto_rsp = control->auto_rsp;
}
if(attr_val != NULL){
APPL_TRACE_DEBUG("!!!!!!attr_val->attr_len = %x\n",attr_val->attr_len);
APPL_TRACE_DEBUG("!!!!!!!attr_val->attr_max_len = %x\n",attr_val->attr_max_len);
p_buf->attr_val.attr_len = attr_val->attr_len;
p_buf->attr_val.attr_max_len = attr_val->attr_max_len;
p_buf->attr_val.attr_val = (uint8_t *)GKI_getbuf(len);
if(p_buf->attr_val.attr_val != NULL){
memcpy(p_buf->attr_val.attr_val, attr_val->attr_val, attr_val->attr_len);
}
}
if (p_char_uuid) {
memcpy(&p_buf->char_uuid, p_char_uuid, sizeof(tBT_UUID));
@@ -253,22 +270,43 @@ void BTA_GATTS_AddCharacteristic (UINT16 service_id, tBT_UUID *p_char_uuid,
*******************************************************************************/
void BTA_GATTS_AddCharDescriptor (UINT16 service_id,
tBTA_GATT_PERM perm,
tBT_UUID *p_descr_uuid)
tBT_UUID *p_descr_uuid, tBTA_GATT_ATTR_VAL *attr_val,
tBTA_GATTS_ATTR_CONTROL *control)
{
tBTA_GATTS_API_ADD_DESCR *p_buf;
UINT16 len = sizeof(tBTA_GATTS_API_ADD_DESCR);
UINT16 value_len = 0;
if ((p_buf = (tBTA_GATTS_API_ADD_DESCR *) GKI_getbuf(len)) != NULL) {
memset(p_buf, 0, len);
if ((p_buf = (tBTA_GATTS_API_ADD_DESCR *) GKI_getbuf(sizeof(tBTA_GATTS_API_ADD_DESCR))) != NULL) {
memset(p_buf, 0, sizeof(tBTA_GATTS_API_ADD_DESCR));
p_buf->hdr.event = BTA_GATTS_API_ADD_DESCR_EVT;
p_buf->hdr.layer_specific = service_id;
p_buf->perm = perm;
if(control != NULL){
p_buf->control.auto_rsp = control->auto_rsp;
}
if (p_descr_uuid) {
memcpy(&p_buf->descr_uuid, p_descr_uuid, sizeof(tBT_UUID));
}
if(attr_val != NULL){
p_buf->attr_val.attr_len = attr_val->attr_len;
p_buf->attr_val.attr_max_len = attr_val->attr_max_len;
value_len = attr_val->attr_len;
if (value_len != 0){
p_buf->attr_val.attr_val = (uint8_t*)GKI_getbuf(value_len);
if(p_buf->attr_val.attr_val != NULL){
memcpy(p_buf->attr_val.attr_val, attr_val->attr_val, value_len);
}
else{
APPL_TRACE_ERROR("Allocate fail for %s\n", __func__);
}
}
}
bta_sys_sendmsg(p_buf);
}
return;
@@ -276,14 +314,14 @@ void BTA_GATTS_AddCharDescriptor (UINT16 service_id,
}
/*******************************************************************************
**
** 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.
**
**
** 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.
**
*******************************************************************************/
@@ -433,6 +471,29 @@ void BTA_GATTS_SendRsp (UINT16 conn_id, UINT32 trans_id,
}
void BTA_SetAttributeValue(UINT16 attr_handle, UINT16 length, UINT8 *value)
{
tBTA_GATTS_API_SET_ATTR_VAL *p_buf;
if((p_buf = (tBTA_GATTS_API_SET_ATTR_VAL *)GKI_getbuf(
sizeof(tBTA_GATTS_API_SET_ATTR_VAL))) != NULL){
p_buf->hdr.event = BTA_GATTS_API_SET_ATTR_VAL_EVT;
p_buf->hdr.layer_specific = attr_handle;
p_buf->length = length;
if(value != NULL){
if((p_buf->value = (UINT8 *)GKI_getbuf(length)) != NULL){
memcpy(p_buf->value, value, length);
}
}
bta_sys_sendmsg(p_buf);
}
}
void BTA_GetAttributeValue(UINT16 attr_handle, UINT16 *length, UINT8 **value)
{
bta_gatts_get_attr_value(attr_handle, length, value);
}
/*******************************************************************************
**

View File

@@ -104,29 +104,30 @@ BOOLEAN bta_gatts_hdl_event(BT_HDR *p_msg)
case BTA_GATTS_API_RSP_EVT:
bta_gatts_send_rsp(p_cb, (tBTA_GATTS_DATA *) p_msg);
break;
case BTA_GATTS_API_SET_ATTR_VAL_EVT:{
UINT16 attr_id = ((tBTA_GATTS_DATA *) p_msg)->api_set_val.hdr.layer_specific;
p_srvc_cb = bta_gatts_find_srvc_cb_by_attr_id(p_cb, attr_id);
bta_gatts_set_attr_value(p_srvc_cb, (tBTA_GATTS_DATA *) p_msg);
break;
}
case BTA_GATTS_API_LISTEN_EVT:
bta_gatts_listen(p_cb, (tBTA_GATTS_DATA *) p_msg);
break;
case BTA_GATTS_API_ADD_INCL_SRVC_EVT:
case BTA_GATTS_API_ADD_CHAR_EVT:
case BTA_GATTS_API_ADD_DESCR_EVT:
case BTA_GATTS_API_DEL_SRVC_EVT:
case BTA_GATTS_API_START_SRVC_EVT:
case BTA_GATTS_API_STOP_SRVC_EVT:
p_srvc_cb = bta_gatts_find_srvc_cb_by_srvc_id(p_cb,
((tBTA_GATTS_DATA *)p_msg)->api_add_incl_srvc.hdr.layer_specific);
if (p_srvc_cb != NULL) {
bta_gatts_srvc_build_act[p_msg->event - BTA_GATTS_API_ADD_INCL_SRVC_EVT](p_srvc_cb, (tBTA_GATTS_DATA *) p_msg);
} else {
APPL_TRACE_ERROR("service not created");
APPL_TRACE_ERROR("service not created\n");
}
break;
default:
break;
}

View File

@@ -400,6 +400,8 @@ typedef struct {
typedef void (tBTA_SET_ADV_DATA_CMPL_CBACK) (tBTA_STATUS status);
typedef void (tBTA_START_ADV_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
@@ -1095,6 +1097,8 @@ 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_START_SCAN_CMPL_CBACK) (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);
@@ -1891,7 +1895,7 @@ extern void BTA_DmSetBleAdvParams (UINT16 adv_int_min, UINT16 adv_int_max,
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);
tBLE_BD_ADDR *p_dir_bda, tBTA_START_ADV_CMPL_CBACK p_start_adv_cb);
/*******************************************************************************
@@ -1997,7 +2001,8 @@ extern void BTA_DmSetEncryption(BD_ADDR bd_addr, tBTA_TRANSPORT transport,
**
*******************************************************************************/
extern void BTA_DmBleObserve(BOOLEAN start, UINT8 duration,
tBTA_DM_SEARCH_CBACK *p_results_cb);
tBTA_DM_SEARCH_CBACK *p_results_cb,
tBTA_START_SCAN_CMPL_CBACK *p_start_scan_cb);
extern void BTA_DmBleStopAdvertising(void);
@@ -2050,6 +2055,22 @@ 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
@@ -2065,6 +2086,22 @@ 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

View File

@@ -109,41 +109,41 @@ typedef UINT8 tBTA_GATT_STATUS;
/* 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 */
#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;
@@ -151,7 +151,7 @@ typedef tGATT_IF tBTA_GATTC_IF;
typedef struct {
UINT16 unit; /* as UUIUD defined by SIG */
UINT16 descr; /* as UUID as 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 */
@@ -165,7 +165,7 @@ 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 */
#define BTA_GATT_SVR_CONFIG_BROADCAST GATT_SVR_CONFIG_BROADCAST /* 0x0001 */
typedef UINT16 tBTA_GATT_SVR_CHAR_CONFIG;
/* Characteristic Aggregate Format attribute value
@@ -367,8 +367,8 @@ typedef struct {
// btla-specific --
typedef struct {
tBTA_GATTC_IF client_if;
BD_ADDR remote_bda;
tBTA_GATTC_IF client_if;
BD_ADDR remote_bda;
} tBTA_GATTC_ENC_CMPL_CB;
typedef union {
@@ -395,7 +395,6 @@ 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
@@ -419,6 +418,7 @@ typedef void (tBTA_GATTC_CBACK)(tBTA_GATTC_EVT event, tBTA_GATTC *p_data);
#define BTA_GATTS_CLOSE_EVT 18
#define BTA_GATTS_LISTEN_EVT 19
#define BTA_GATTS_CONGEST_EVT 20
#define BTA_GATTS_SET_ATTR_VAL_EVT 21
typedef UINT8 tBTA_GATTS_EVT;
typedef tGATT_IF tBTA_GATTS_IF;
@@ -434,20 +434,22 @@ typedef tGATT_IF tBTA_GATTS_IF;
#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 */
#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
@@ -476,8 +478,8 @@ 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 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;
@@ -539,6 +541,13 @@ typedef struct {
// 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;
@@ -566,17 +575,18 @@ typedef struct {
/* 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 */
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_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 */
@@ -1193,8 +1203,9 @@ extern void BTA_GATTS_AddIncludeService(UINT16 service_id, UINT16 included_servi
** Returns None
**
*******************************************************************************/
extern void BTA_GATTS_AddCharacteristic (UINT16 service_id, tBT_UUID *p_char_uuid,
tBTA_GATT_PERM perm, tBTA_GATT_CHAR_PROP property);
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);
/*******************************************************************************
**
@@ -1214,8 +1225,9 @@ extern void BTA_GATTS_AddCharacteristic (UINT16 service_id, tBT_UUID *p_char_
**
*******************************************************************************/
extern void BTA_GATTS_AddCharDescriptor (UINT16 service_id,
tBTA_GATT_PERM perm,
tBT_UUID *p_descr_uuid);
tBTA_GATT_PERM perm,
tBT_UUID *p_descr_uuid, tBTA_GATT_ATTR_VAL *attr_val,
tBTA_GATTS_ATTR_CONTROL *control);
/*******************************************************************************
**
@@ -1296,6 +1308,38 @@ 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

View File

@@ -48,6 +48,7 @@ enum {
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,
@@ -91,19 +92,21 @@ typedef struct {
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;
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 {
@@ -121,6 +124,12 @@ typedef struct {
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;
@@ -156,6 +165,7 @@ typedef union {
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;
@@ -169,7 +179,7 @@ typedef struct {
BOOLEAN in_use;
tBT_UUID app_uuid;
tBTA_GATTS_CBACK *p_cback;
tBTA_GATTS_IF gatt_if;
tBTA_GATTS_IF gatt_if;
} tBTA_GATTS_RCB;
/* service registration control block */
@@ -219,6 +229,8 @@ 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);

View File

@@ -298,7 +298,6 @@ static void bta_create_ops_sdp_record(bluetooth_sdp_record *record, tSDP_DISC_RE
static void bta_create_sap_sdp_record(bluetooth_sdp_record *record, tSDP_DISC_REC *p_rec)
{
tSDP_DISCOVERY_DB *db = p_bta_sdp_cfg->p_sdp_db;
tSDP_DISC_ATTR *p_attr;
tSDP_PROTOCOL_ELEM pe;
UINT16 pversion = -1;

View File

@@ -598,6 +598,8 @@ void bta_alarm_cb(void *data)
TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)data;
fixed_queue_enqueue(btu_bta_alarm_queue, p_tle);
btu_task_post(SIG_BTU_WORK);
}
void bta_sys_start_timer(TIMER_LIST_ENT *p_tle, UINT16 type, INT32 timeout_ms)

View File

@@ -39,14 +39,18 @@ static void btc_sec_callback(tBTA_DM_SEC_EVT event, tBTA_DM_SEC *p_data)
}
}
static bt_status_t btc_enable_bluetooth(void)
static void btc_enable_bluetooth(void)
{
BTA_EnableBluetooth(btc_sec_callback);
if (BTA_EnableBluetooth(btc_sec_callback) != BTA_SUCCESS) {
future_ready(*btc_main_get_future_p(BTC_MAIN_ENABLE_FUTURE), FUTURE_FAIL);
}
}
static bt_status_t btc_disable_bluetooth(void)
static void btc_disable_bluetooth(void)
{
BTA_DisableBluetooth();
if (BTA_DisableBluetooth() != BTA_SUCCESS) {
future_ready(*btc_main_get_future_p(BTC_MAIN_DISABLE_FUTURE), FUTURE_FAIL);
}
}
void btc_init_callback(void)
@@ -54,7 +58,7 @@ void btc_init_callback(void)
future_ready(*btc_main_get_future_p(BTC_MAIN_INIT_FUTURE), FUTURE_SUCCESS);
}
static bt_status_t btc_init_bluetooth(void)
static void btc_init_bluetooth(void)
{
bte_main_boot_entry(btc_init_callback);
}

View File

@@ -20,7 +20,7 @@
#include "esp_bt_defs.h"
#include "esp_gatt_defs.h"
static esp_profile_cb_t btc_profile_cb_tab[BTC_PID_NUM] = {};
static void *btc_profile_cb_tab[BTC_PID_NUM] = {};
void esp_profile_cb_reset(void)
{
@@ -31,7 +31,7 @@ void esp_profile_cb_reset(void)
}
}
int btc_profile_cb_set(btc_pid_t profile_id, esp_profile_cb_t cb)
int btc_profile_cb_set(btc_pid_t profile_id, void *cb)
{
if (profile_id < 0 || profile_id >= BTC_PID_NUM) {
return -1;
@@ -42,7 +42,7 @@ int btc_profile_cb_set(btc_pid_t profile_id, esp_profile_cb_t cb)
return 0;
}
esp_profile_cb_t btc_profile_cb_get(btc_pid_t profile_id)
void *btc_profile_cb_get(btc_pid_t profile_id)
{
if (profile_id < 0 || profile_id >= BTC_PID_NUM) {
return NULL;

View File

@@ -56,7 +56,7 @@ static void btc_task(void *arg)
for (;;) {
if (pdTRUE == xQueueReceive(xBtcQueue, &msg, (portTickType)portMAX_DELAY)) {
LOG_DEBUG("%s msg %u %u %u %08x\n", __func__, msg.sig, msg.pid, msg.act, msg.arg);
LOG_DEBUG("%s msg %u %u %u %p\n", __func__, msg.sig, msg.pid, msg.act, msg.arg);
switch (msg.sig) {
case BTC_SIG_API_CALL:
profile_tab[msg.pid].btc_call(&msg);
@@ -80,7 +80,7 @@ static bt_status_t btc_task_post(btc_msg_t *msg)
return BT_STATUS_PARM_INVALID;
}
if (xQueueSend(xBtcQueue, msg, 10 / portTICK_RATE_MS) != pdTRUE) {
if (xQueueSend(xBtcQueue, msg, 10 / portTICK_PERIOD_MS) != pdTRUE) {
LOG_ERROR("Btc Post failed\n");
return BT_STATUS_BUSY;
}
@@ -120,7 +120,7 @@ bt_status_t btc_transfer_context(btc_msg_t *msg, void *arg, int arg_len, btc_arg
int btc_init(void)
{
xBtcQueue = xQueueCreate(BTC_TASK_QUEUE_NUM, sizeof(btc_msg_t));
xTaskCreate(btc_task, "Btc_task", BTC_TASK_STACK_SIZE, NULL, BTC_TASK_PRIO, &xBtcTaskHandle);
xTaskCreatePinnedToCore(btc_task, "Btc_task", BTC_TASK_STACK_SIZE, NULL, BTC_TASK_PRIO, &xBtcTaskHandle, 0);
/* TODO: initial the profile_tab */

View File

@@ -22,7 +22,7 @@
/* reset gatt callback table */
void esp_profile_cb_reset(void);
int btc_profile_cb_set(btc_pid_t profile_id, esp_profile_cb_t cb);
esp_profile_cb_t btc_profile_cb_get(btc_pid_t profile_id);
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__ */

View File

@@ -1,164 +0,0 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "blufi_adv.h"
/*******************************************************************************
**
** Function BlufiConfigadvData
**
** Description This function is called to override the BTA default ADV parameters.
**
** adv_data: Pointer to User defined ADV data structure. This
** memory space can not be freed until p_adv_data_cback
** is received.
** p_adv_data_cback: set adv data complete callback.
**
** Returns None
**
*******************************************************************************/
void BlufiBleConfigadvData(tBLUFI_BLE_ADV_DATA *adv_data,
tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback)
{
tBTA_BLE_AD_MASK data_mask = 0;
if (adv_data->adv_name != NULL) {
data_mask |= BTM_BLE_AD_BIT_DEV_NAME;
BTA_DmSetDeviceName(adv_data->adv_name);
}
if (adv_data->ble_adv_data.int_range.low != 0 ||
adv_data->ble_adv_data.int_range.hi != 0) {
data_mask |= BTM_BLE_AD_BIT_INT_RANGE;
}
if (adv_data->ble_adv_data.p_manu != NULL) {
data_mask |= BTM_BLE_AD_BIT_MANU;
}
if (adv_data->ble_adv_data.p_services != NULL) {
data_mask |= BTM_BLE_AD_BIT_SERVICE;
}
if (adv_data->ble_adv_data.p_service_32b != NULL) {
data_mask |= BTM_BLE_AD_BIT_SERVICE_32;
}
if (adv_data->ble_adv_data.p_services_128b != NULL) {
data_mask |= BTM_BLE_AD_BIT_SERVICE_128;
}
if (adv_data->ble_adv_data.p_sol_services != NULL) {
data_mask |= BTM_BLE_AD_BIT_SERVICE_SOL;
}
if (adv_data->ble_adv_data.p_sol_service_32b != NULL) {
data_mask |= BTM_BLE_AD_BIT_SERVICE_32SOL;
}
if (adv_data->ble_adv_data.p_sol_service_128b != NULL) {
data_mask |= BTM_BLE_AD_BIT_SERVICE_128SOL;
}
if (adv_data->ble_adv_data.p_service_data != NULL) {
data_mask |= BTM_BLE_AD_BIT_SERVICE_DATA;
}
if (adv_data->ble_adv_data.appearance != 0) {
data_mask |= BTM_BLE_AD_BIT_APPEARANCE;
}
if (adv_data->ble_adv_data.p_proprietary != NULL) {
data_mask |= BTM_BLE_AD_BIT_PROPRIETARY;
}
if (adv_data->ble_adv_data.tx_power != 0) {
data_mask |= BTM_BLE_AD_BIT_TX_PWR;
}
BTA_DmBleSetAdvConfig(data_mask, &(adv_data->ble_adv_data), p_adv_data_cback);
}
/*******************************************************************************
**
** Function BLUFI_BleSetScanRsp
**
** Description This function is called to override the app scan response.
**
** Parameters Pointer to User defined ADV data structure
**
** Returns None
**
*******************************************************************************/
void BlufiBleSetScanRsp(tBLUFI_BLE_ADV_DATA *scan_rsp_data,
tBTA_SET_ADV_DATA_CMPL_CBACK *p_scan_rsp_data_cback)
{
tBTA_BLE_AD_MASK data_mask = 0;
if (scan_rsp_data->adv_name != NULL) {
data_mask |= BTM_BLE_AD_BIT_DEV_NAME;
BTA_DmSetDeviceName(scan_rsp_data->adv_name);
}
if (scan_rsp_data->ble_adv_data.int_range.low != 0 ||
scan_rsp_data->ble_adv_data.int_range.hi != 0) {
data_mask |= BTM_BLE_AD_BIT_INT_RANGE;
}
if (scan_rsp_data->ble_adv_data.p_manu != NULL) {
data_mask |= BTM_BLE_AD_BIT_MANU;
}
if (scan_rsp_data->ble_adv_data.p_services != NULL) {
data_mask |= BTM_BLE_AD_BIT_SERVICE;
}
if (scan_rsp_data->ble_adv_data.p_service_32b != NULL) {
data_mask |= BTM_BLE_AD_BIT_SERVICE_32;
}
if (scan_rsp_data->ble_adv_data.p_services_128b != NULL) {
data_mask |= BTM_BLE_AD_BIT_SERVICE_128;
}
if (scan_rsp_data->ble_adv_data.p_sol_services != NULL) {
data_mask |= BTM_BLE_AD_BIT_SERVICE_SOL;
}
if (scan_rsp_data->ble_adv_data.p_sol_service_32b != NULL) {
data_mask |= BTM_BLE_AD_BIT_SERVICE_32SOL;
}
if (scan_rsp_data->ble_adv_data.p_sol_service_128b != NULL) {
data_mask |= BTM_BLE_AD_BIT_SERVICE_128SOL;
}
if (scan_rsp_data->ble_adv_data.p_service_data != NULL) {
data_mask |= BTM_BLE_AD_BIT_SERVICE_DATA;
}
if (scan_rsp_data->ble_adv_data.appearance != 0) {
data_mask |= BTM_BLE_AD_BIT_APPEARANCE;
}
if (scan_rsp_data->ble_adv_data.p_proprietary != NULL) {
data_mask |= BTM_BLE_AD_BIT_PROPRIETARY;
}
if (scan_rsp_data->ble_adv_data.tx_power != 0) {
data_mask |= BTM_BLE_AD_BIT_TX_PWR;
}
BTA_DmBleSetScanRsp(data_mask, &(scan_rsp_data->ble_adv_data), p_scan_rsp_data_cback);
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,249 @@
// 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 <stdint.h>
#include <string.h>
#include <stdbool.h>
#include <stdio.h>
#include "bt_target.h"
#include "bt_trace.h"
#include "bt_types.h"
#include "gatt_api.h"
#include "bta_api.h"
#include "bta_gatt_api.h"
#include "bta_gatts_int.h"
#include "btc_blufi_prf.h"
#include "btc_task.h"
#include "btc_manage.h"
#include "blufi_int.h"
#include "esp_wifi.h"
extern tBLUFI_ENV blufi_env;
void btc_blufi_protocol_handler(uint8_t type, uint8_t *data, int len)
{
btc_msg_t msg;
esp_blufi_cb_param_t param;
uint8_t *output_data = NULL;
int output_len = 0;
bool need_free = false;
switch (BLUFI_GET_TYPE(type)) {
case BLUFI_TYPE_CTRL:
switch (BLUFI_GET_SUBTYPE(type)) {
case BLUFI_TYPE_CTRL_SUBTYPE_ACK:
/* TODO: check sequence */
break;
case BLUFI_TYPE_CTRL_SUBTYPE_SET_SEC_MODE:
blufi_env.sec_mode = data[0];
break;
case BLUFI_TYPE_CTRL_SUBTYPE_SET_WIFI_OPMODE:
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_BLUFI;
msg.act = ESP_BLUFI_EVENT_SET_WIFI_OPMODE;
param.wifi_mode.op_mode = data[0];
btc_transfer_context(&msg, &param, sizeof(esp_blufi_cb_param_t), NULL);
break;
case BLUFI_TYPE_CTRL_SUBTYPE_CONN_TO_AP:
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_BLUFI;
msg.act = ESP_BLUFI_EVENT_REQ_CONNECT_TO_AP;
btc_transfer_context(&msg, NULL, 0, NULL);
break;
case BLUFI_TYPE_CTRL_SUBTYPE_DISCONN_FROM_AP:
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_BLUFI;
msg.act = ESP_BLUFI_EVENT_REQ_DISCONNECT_FROM_AP;
btc_transfer_context(&msg, NULL, 0, NULL);
break;
case BLUFI_TYPE_CTRL_SUBTYPE_GET_WIFI_STATUS:
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_BLUFI;
msg.act = ESP_BLUFI_EVENT_GET_WIFI_STATUS;
btc_transfer_context(&msg, NULL, 0, NULL);
break;
case BLUFI_TYPE_CTRL_SUBTYPE_DEAUTHENTICATE_STA:
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_BLUFI;
msg.act = ESP_BLUFI_EVENT_DEAUTHENTICATE_STA;
btc_transfer_context(&msg, NULL, 0, NULL);
break;
case BLUFI_TYPE_CTRL_SUBTYPE_GET_VERSION: {
uint8_t type = BLUFI_BUILD_TYPE(BLUFI_TYPE_DATA, BLUFI_TYPE_DATA_SUBTYPE_REPLY_VERSION);
uint8_t data[2];
data[0] = BTC_BLUFI_GREAT_VER;
data[1] = BTC_BLUFI_SUB_VER;
btc_blufi_send_encap(type, &data[0], sizeof(data));
break;
}
default:
LOG_ERROR("%s Unkown Ctrl pkt %02x\n", __func__, type);
break;
}
break;
case BLUFI_TYPE_DATA:
switch (BLUFI_GET_SUBTYPE(type)) {
case BLUFI_TYPE_DATA_SUBTYPE_NEG:
if (blufi_env.cbs && blufi_env.cbs->negotiate_data_handler) {
blufi_env.cbs->negotiate_data_handler(data, len, &output_data, &output_len, &need_free);
}
if (output_data && output_len > 0) {
btc_blufi_send_encap(BLUFI_BUILD_TYPE(BLUFI_TYPE_DATA, BLUFI_TYPE_DATA_SUBTYPE_NEG),
output_data, output_len);
}
break;
case BLUFI_TYPE_DATA_SUBTYPE_STA_BSSID:
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_BLUFI;
msg.act = ESP_BLUFI_EVENT_RECV_STA_BSSID;
memcpy(param.sta_bssid.bssid, &data[0], 6);
btc_transfer_context(&msg, &param, sizeof(esp_blufi_cb_param_t), NULL);
break;
case BLUFI_TYPE_DATA_SUBTYPE_STA_SSID:
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_BLUFI;
msg.act = ESP_BLUFI_EVENT_RECV_STA_SSID;
param.sta_ssid.ssid = &data[0];
param.sta_ssid.ssid_len = len;
btc_transfer_context(&msg, &param, sizeof(esp_blufi_cb_param_t), btc_blufi_cb_deep_copy);
break;
case BLUFI_TYPE_DATA_SUBTYPE_STA_PASSWD:
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_BLUFI;
msg.act = ESP_BLUFI_EVENT_RECV_STA_PASSWD;
param.sta_passwd.passwd = &data[0];
param.sta_passwd.passwd_len = len;
btc_transfer_context(&msg, &param, sizeof(esp_blufi_cb_param_t), btc_blufi_cb_deep_copy);
break;
case BLUFI_TYPE_DATA_SUBTYPE_SOFTAP_SSID:
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_BLUFI;
msg.act = ESP_BLUFI_EVENT_RECV_SOFTAP_SSID;
param.softap_ssid.ssid = &data[0];
param.softap_ssid.ssid_len = len;
btc_transfer_context(&msg, &param, sizeof(esp_blufi_cb_param_t), btc_blufi_cb_deep_copy);
break;
case BLUFI_TYPE_DATA_SUBTYPE_SOFTAP_PASSWD:
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_BLUFI;
msg.act = ESP_BLUFI_EVENT_RECV_SOFTAP_PASSWD;
param.softap_passwd.passwd = &data[0];
param.softap_passwd.passwd_len = len;
btc_transfer_context(&msg, &param, sizeof(esp_blufi_cb_param_t), btc_blufi_cb_deep_copy);
break;
case BLUFI_TYPE_DATA_SUBTYPE_SOFTAP_MAX_CONN_NUM:
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_BLUFI;
msg.act = ESP_BLUFI_EVENT_RECV_SOFTAP_MAX_CONN_NUM;
param.softap_max_conn_num.max_conn_num = data[0];
btc_transfer_context(&msg, &param, sizeof(esp_blufi_cb_param_t), NULL);
break;
case BLUFI_TYPE_DATA_SUBTYPE_SOFTAP_AUTH_MODE:
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_BLUFI;
msg.act = ESP_BLUFI_EVENT_RECV_SOFTAP_AUTH_MODE;
param.softap_auth_mode.auth_mode = data[0];
btc_transfer_context(&msg, &param, sizeof(esp_blufi_cb_param_t), NULL);
break;
case BLUFI_TYPE_DATA_SUBTYPE_SOFTAP_CHANNEL:
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_BLUFI;
msg.act = ESP_BLUFI_EVENT_RECV_SOFTAP_CHANNEL;
param.softap_channel.channel = data[0];
btc_transfer_context(&msg, &param, sizeof(esp_blufi_cb_param_t), NULL);
break;
case BLUFI_TYPE_DATA_SUBTYPE_USERNAME:
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_BLUFI;
msg.act = ESP_BLUFI_EVENT_RECV_USERNAME;
param.username.name = &data[0];
param.username.name_len = len;
btc_transfer_context(&msg, &param, sizeof(esp_blufi_cb_param_t), btc_blufi_cb_deep_copy);
break;
case BLUFI_TYPE_DATA_SUBTYPE_CA:
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_BLUFI;
msg.act = ESP_BLUFI_EVENT_RECV_CA_CERT;
param.ca.cert = &data[0];
param.ca.cert_len = len;
btc_transfer_context(&msg, &param, sizeof(esp_blufi_cb_param_t), btc_blufi_cb_deep_copy);
break;
case BLUFI_TYPE_DATA_SUBTYPE_CLIENT_CERT:
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_BLUFI;
msg.act = ESP_BLUFI_EVENT_RECV_CLIENT_CERT;
param.client_cert.cert = &data[0];
param.client_cert.cert_len = len;
btc_transfer_context(&msg, &param, sizeof(esp_blufi_cb_param_t), btc_blufi_cb_deep_copy);
break;
case BLUFI_TYPE_DATA_SUBTYPE_SERVER_CERT:
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_BLUFI;
msg.act = ESP_BLUFI_EVENT_RECV_SERVER_CERT;
param.client_cert.cert = &data[0];
param.client_cert.cert_len = len;
btc_transfer_context(&msg, &param, sizeof(esp_blufi_cb_param_t), btc_blufi_cb_deep_copy);
break;
case BLUFI_TYPE_DATA_SUBTYPE_CLIENT_PRIV_KEY:
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_BLUFI;
msg.act = ESP_BLUFI_EVENT_RECV_CLIENT_PRIV_KEY;
param.client_pkey.pkey = &data[0];
param.client_pkey.pkey_len = len;
btc_transfer_context(&msg, &param, sizeof(esp_blufi_cb_param_t), btc_blufi_cb_deep_copy);
break;
case BLUFI_TYPE_DATA_SUBTYPE_SERVER_PRIV_KEY:
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_BLUFI;
msg.act = ESP_BLUFI_EVENT_RECV_SERVER_PRIV_KEY;
param.client_pkey.pkey = &data[0];
param.client_pkey.pkey_len = len;
btc_transfer_context(&msg, &param, sizeof(esp_blufi_cb_param_t), btc_blufi_cb_deep_copy);
break;
default:
LOG_ERROR("%s Unkown Ctrl pkt %02x\n", __func__, type);
break;
}
break;
default:
break;
}
}

View File

@@ -1,39 +0,0 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef __BLUFI_ADV_H__
#define __BLUFI_ADV_H__
#include "bta_api.h"
#include "btm_ble_api.h"
#include "esp_bt_defs.h"
typedef enum {
BLE_ADV_DATA_IDX = 0,
BLE_SCAN_RSP_DATA_IDX = 1,
ADV_SCAN_IDX_MAX,
} ADV_SCAN_IDX_t;
typedef struct {
char *adv_name; //set the device name to be sent on the advertising
tBTA_BLE_ADV_DATA ble_adv_data;
} tBLUFI_BLE_ADV_DATA;
extern void BlufiBleConfigadvData(tBLUFI_BLE_ADV_DATA *adv_data,
tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback);
extern void BlufiBleSetScanRsp(tBLUFI_BLE_ADV_DATA *scan_rsp_data,
tBTA_SET_ADV_DATA_CMPL_CBACK *p_scan_rsp_data_cback);
#endif /* __BLUFI_ADV_H__ */

View File

@@ -15,38 +15,165 @@
#ifndef __BLUFI_INT_H__
#define __BLUFI_INT_H__
//define the blufi serivce uuid
#define SVC_BLUFI_UUID 0xFFFF
//define the blufi Char uuid
#define CHAR_BLUFI_UUID 0xFF01
#define BLUFI_HDL_NUM 4
#define BLUFI_VAL_MAX_LEN (128)
#define BLUFI_MAX_STRING_DATA 128
typedef struct {
UINT8 app_id;
UINT16 blufi_hdl;
} tBLUFI_INST;
#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 {
BOOLEAN enabled;
BOOLEAN is_primery;
UINT8 inst_id;
/* Protocol reference */
tGATT_IF gatt_if;
tBLUFI_INST blufi_inst;
BOOLEAN in_use;
BOOLEAN congest;
UINT8 srvc_inst;
UINT16 handle_srvc;
UINT16 handle_char_p2e;
UINT16 handle_char_e2p;
UINT16 handle_descr_e2p;
UINT16 conn_id;
BOOLEAN connected;
BOOLEAN is_connected;
BD_ADDR remote_bda;
UINT32 trans_id;
UINT8 cur_srvc_id;
} tBLUFI_CB_ENV;
UINT8 congest;
UINT16 frag_size;
#define BLUFI_PREPAIR_BUF_MAX_SIZE 1024
uint8_t *prepare_buf;
int prepare_len;
/* Control reference */
esp_blufi_callbacks_t *cbs;
BOOLEAN enabled;
uint8_t send_seq;
uint8_t recv_seq;
uint8_t sec_mode;
uint8_t *aggr_buf;
uint16_t total_len;
uint16_t offset;
} tBLUFI_ENV;
/* BLUFI protocol */
struct blufi_hdr{
uint8_t type;
uint8_t fc;
uint8_t seq;
uint8_t data_len;
uint8_t data[0];
};
typedef struct blufi_hdr blufi_hd_t;
struct blufi_frag_hdr {
uint8_t type;
uint8_t fc;
uint8_t seq;
uint8_t data_len;
uint16_t total_len;
uint8_t content[0];
};
typedef struct blufi_frag_hdr blufi_frag_hdr_t;
#define BLUFI_DATA_SEC_MODE_CHECK_MASK 0x01
#define BLUFI_DATA_SEC_MODE_ENC_MASK 0x02
#define BLUFI_CTRL_SEC_MODE_CHECK_MASK 0x10
#define BLUFI_CTRL_SEC_MODE_ENC_MASK 0x20
// packet type
#define BLUFI_TYPE_MASK 0x03
#define BLUFI_TYPE_SHIFT 0
#define BLUFI_SUBTYPE_MASK 0xFC
#define BLUFI_SUBTYPE_SHIFT 2
#define BLUFI_GET_TYPE(type) ((type) & BLUFI_TYPE_MASK)
#define BLUFI_GET_SUBTYPE(type) (((type) & BLUFI_SUBTYPE_MASK) >>BLUFI_SUBTYPE_SHIFT)
#define BLUFI_BUILD_TYPE(type, subtype) (((type) & BLUFI_TYPE_MASK) | ((subtype)<<BLUFI_SUBTYPE_SHIFT))
#define BLUFI_TYPE_CTRL 0x0
#define BLUFI_TYPE_CTRL_SUBTYPE_ACK 0x00
#define BLUFI_TYPE_CTRL_SUBTYPE_SET_SEC_MODE 0x01
#define BLUFI_TYPE_CTRL_SUBTYPE_SET_WIFI_OPMODE 0x02
#define BLUFI_TYPE_CTRL_SUBTYPE_CONN_TO_AP 0x03
#define BLUFI_TYPE_CTRL_SUBTYPE_DISCONN_FROM_AP 0x04
#define BLUFI_TYPE_CTRL_SUBTYPE_GET_WIFI_STATUS 0x05
#define BLUFI_TYPE_CTRL_SUBTYPE_DEAUTHENTICATE_STA 0x06
#define BLUFI_TYPE_CTRL_SUBTYPE_GET_VERSION 0x07
#define BLUFI_TYPE_DATA 0x1
#define BLUFI_TYPE_DATA_SUBTYPE_NEG 0x00
#define BLUFI_TYPE_DATA_SUBTYPE_STA_BSSID 0x01
#define BLUFI_TYPE_DATA_SUBTYPE_STA_SSID 0x02
#define BLUFI_TYPE_DATA_SUBTYPE_STA_PASSWD 0x03
#define BLUFI_TYPE_DATA_SUBTYPE_SOFTAP_SSID 0x04
#define BLUFI_TYPE_DATA_SUBTYPE_SOFTAP_PASSWD 0x05
#define BLUFI_TYPE_DATA_SUBTYPE_SOFTAP_MAX_CONN_NUM 0x06
#define BLUFI_TYPE_DATA_SUBTYPE_SOFTAP_AUTH_MODE 0x07
#define BLUFI_TYPE_DATA_SUBTYPE_SOFTAP_CHANNEL 0x08
#define BLUFI_TYPE_DATA_SUBTYPE_USERNAME 0x09
#define BLUFI_TYPE_DATA_SUBTYPE_CA 0x0a
#define BLUFI_TYPE_DATA_SUBTYPE_CLIENT_CERT 0x0b
#define BLUFI_TYPE_DATA_SUBTYPE_SERVER_CERT 0x0c
#define BLUFI_TYPE_DATA_SUBTYPE_CLIENT_PRIV_KEY 0x0d
#define BLUFI_TYPE_DATA_SUBTYPE_SERVER_PRIV_KEY 0x0e
#define BLUFI_TYPE_DATA_SUBTYPE_WIFI_REP 0x0f
#define BLUFI_TYPE_DATA_SUBTYPE_REPLY_VERSION 0x10
#define BLUFI_TYPE_IS_CTRL(type) (BLUFI_GET_TYPE((type)) == BLUFI_TYPE_CTRL)
#define BLUFI_TYPE_IS_DATA(type) (BLUFI_GET_TYPE((type)) == BLUFI_TYPE_DATA)
#define BLUFI_TYPE_IS_CTRL_ACK(type) (BLUFI_TYPE_IS_CTRL((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_CTRL_SUBTYPE_ACK)
#define BLUFI_TYPE_IS_CTRL_START_NEG(type) (BLUFI_TYPE_IS_CTRL((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_CTRL_SUBTYPE_START_NEG)
#define BLUFI_TYPE_IS_CTRL_STOP_NEG(type) (BLUFI_TYPE_IS_CTRL((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_CTRL_SUBTYPE_STOP_NEG)
#define BLUFI_TYPE_IS_CTRL_SET_WIFI_OPMODE(type) (BLUFI_TYPE_IS_CTRL((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_CTRL_SUBTYPE_SET_WIFI_OPMODE)
#define BLUFI_TYPE_IS_CTRL_CONN_WIFI(type) (BLUFI_TYPE_IS_CTRL((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_CTRL_SUBTYPE_CONN_TO_AP)
#define BLUFI_TYPE_IS_CTRL_DISCONN_WIFI(type) (BLUFI_TYPE_IS_CTRL((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_CTRL_SUBTYPE_DISCONN_FROM_AP)
#define BLUFI_TYPE_IS_CTRL_GET_WIFI_STATUS(type) (BLUFI_TYPE_IS_CTRL((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_CTRL_SUBTYPE_GET_WIFI_STATUS)
#define BLUFI_TYPE_IS_CTRL_DEAUTHENTICATE_STA(type) (BLUFI_TYPE_IS_CTRL((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_CTRL_SUBTYPE_DEAUTHENTICATE_STA)
#define BLUFI_TYPE_IS_CTRL_GET_VERSION(type) (BLUFI_TYPE_IS_CTRL((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_CTRL_SUBTYPE_GET_VERSION)
#define BLUFI_TYPE_IS_DATA_NEG(type) (BLUFI_TYPE_IS_DATA((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_DATA_SUBTYPE_NEG)
#define BLUFI_TYPE_IS_DATA_STA_BSSID(type) (BLUFI_TYPE_IS_DATA((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_DATA_SUBTYPE_STA_BSSID)
#define BLUFI_TYPE_IS_DATA_STA_SSID(type) (BLUFI_TYPE_IS_DATA((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_DATA_SUBTYPE_STA_SSID)
#define BLUFI_TYPE_IS_DATA_STA_PASSWD(type) (BLUFI_TYPE_IS_DATA((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_DATA_SUBTYPE_STA_PASSWD)
#define BLUFI_TYPE_IS_DATA_SOFTAP_SSID(type) (BLUFI_TYPE_IS_DATA((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_DATA_SUBTYPE_SOFTAP_SSID)
#define BLUFI_TYPE_IS_DATA_SOFTAP_PASSWD(type) (BLUFI_TYPE_IS_DATA((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_DATA_SUBTYPE_SOFTAP_PASSWD)
#define BLUFI_TYPE_IS_DATA_SOFTAP_MAX_CONN_NUM(type) (BLUFI_TYPE_IS_DATA((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_DATA_SUBTYPE_SOFTAP_MAX_CONN_NUM)
#define BLUFI_TYPE_IS_DATA_SOFTAP_AUTH_MODE(type) (BLUFI_TYPE_IS_DATA((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_DATA_SUBTYPE_SOFTAP_AUTH_MODE)
#define BLUFI_TYPE_IS_DATA_SOFTAP_CHANNEL(type) (BLUFI_TYPE_IS_DATA((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_DATA_SUBTYPE_SOFTAP_CHANNEL)
#define BLUFI_TYPE_IS_DATA_USERNAME(type) (BLUFI_TYPE_IS_DATA((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_DATA_SUBTYPE_USERNAME)
#define BLUFI_TYPE_IS_DATA_CA(type) (BLUFI_TYPE_IS_DATA((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_DATA_SUBTYPE_CA)
#define BLUFI_TYPE_IS_DATA_CLEINT_CERT(type) (BLUFI_TYPE_IS_DATA((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_DATA_SUBTYPE_CLIENT_CERT)
#define BLUFI_TYPE_IS_DATA_SERVER_CERT(type) (BLUFI_TYPE_IS_DATA((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_DATA_SUBTYPE_SERVER_CERT)
#define BLUFI_TYPE_IS_DATA_CLIENT_PRIV_KEY(type) (BLUFI_TYPE_IS_DATA((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_DATA_SUBTYPE_CLIENT_PRIV_KEY)
#define BLUFI_TYPE_IS_DATA_SERVER_PRIV_KEY(type) (BLUFI_TYPE_IS_DATA((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_DATA_SUBTYPE_SERVER_PRIV_KEY)
// packet frame control
#define BLUFI_FC_ENC_MASK 0x01
#define BLUFI_FC_CHECK_MASK 0x02
#define BLUFI_FC_DIR_MASK 0x04
#define BLUFI_FC_REQ_ACK_MASK 0x08
#define BLUFI_FC_FRAG_MASK 0x10
#define BLUFI_FC_ENC 0x01
#define BLUFI_FC_CHECK 0x02
#define BLUFI_FC_DIR_P2E 0x00
#define BLUFI_FC_DIR_E2P 0x04
#define BLUFI_FC_REQ_ACK 0x08
#define BLUFI_FC_FRAG 0x10
#define BLUFI_FC_IS_ENC(fc) ((fc) & BLUFI_FC_ENC_MASK)
#define BLUFI_FC_IS_CHECK(fc) ((fc) & BLUFI_FC_CHECK_MASK)
#define BLUFI_FC_IS_DIR_P2E(fc) ((fc) & BLUFI_FC_DIR_P2E_MASK)
#define BLUFI_FC_IS_DIR_E2P(fc) (!((fc) & BLUFI_DIR_P2E_MASK))
#define BLUFI_FC_IS_REQ_ACK(fc) ((fc) & BLUFI_FC_REQ_ACK_MASK)
#define BLUFI_FC_IS_FRAG(fc) ((fc) & BLUFI_FC_FRAG_MASK)
/* BLUFI HEADER + TOTAL(REMAIN) LENGTH + CRC + L2CAP RESERVED */
#define BLUFI_MTU_RESERVED_SIZE (sizeof(struct blufi_hdr) + 2 + 2 + 3)
#define BLUFI_FRAG_DATA_DEFAULT_LEN (GATT_DEF_BLE_MTU_SIZE - BLUFI_MTU_RESERVED_SIZE)
//function declare
void btc_blufi_protocol_handler(uint8_t type, uint8_t *data, int len);
void btc_blufi_send_encap(uint8_t type, uint8_t *data, int data_len);
void btc_blufi_set_callbacks(esp_blufi_callbacks_t *callbacks);
void btc_blufi_cb_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
void btc_blufi_cb_deep_free(btc_msg_t *msg);
#endif /* __BLUFI_INT_H__ */

View File

@@ -22,31 +22,26 @@
typedef enum {
BTC_BLUFI_ACT_INIT = 0,
BTC_BLUFI_ACT_DEINIT,
BTC_BLUFI_ACT_SEND_CFG_STATE,
BTC_BLUFI_ACT_SEND_CFG_REPORT,
} btc_blufi_act_t;
typedef enum {
BTC_BLUFI_CB_ACT_INIT_FINISH = 0,
BTC_BLUFI_CB_ACT_DEINIT_FINISH,
BTC_BLUFI_CB_ACT_RECV_DATA,
} btc_blufi_cb_act_t;
typedef union {
#if 0
//BTC_BLUFI_ACT_INIT = 0,
struct blufi_init_param {
} init;
//BTC_BLUFI_ACT_DEINIT,
struct blufi_deinit_param {
} deinit;
#endif
//BTC_BLUFI_ACT_SEND_CFG_STATE,
struct blufi_send_cfg_state_pram {
esp_blufi_config_state_t state;
} cfg_state;
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__ */

View File

@@ -26,8 +26,13 @@
static tBTA_BLE_ADV_DATA gl_bta_adv_data;
static tBTA_BLE_ADV_DATA gl_bta_scan_rsp_data;
#define BTC_GAP_BLE_CB_TO_APP(_event, _param) ((esp_profile_cb_t )btc_profile_cb_get(BTC_PID_GAP_BLE))(_event, _param)
static inline void btc_gap_ble_cb_to_app(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param)
{
esp_gap_ble_cb_t btc_gap_ble_cb = (esp_gap_ble_cb_t)btc_profile_cb_get(BTC_PID_GAP_BLE);
if (btc_gap_ble_cb) {
btc_gap_ble_cb(event, param);
}
}
static void btc_gap_adv_point_cleanup(void **buf)
{
@@ -109,6 +114,7 @@ static void btc_to_bta_adv_data(esp_ble_adv_data_t *p_adv_data, tBTA_BLE_ADV_DAT
if (p_adv_data->flag != 0) {
mask = BTM_BLE_AD_BIT_FLAGS;
bta_adv_data->flag = p_adv_data->flag;
}
if (p_adv_data->include_name) {
@@ -200,7 +206,7 @@ static void btc_to_bta_adv_data(esp_ble_adv_data_t *p_adv_data, tBTA_BLE_ADV_DAT
}
if (NULL != bta_adv_data->p_services->p_uuid) {
LOG_ERROR("%s - In 16-UUID_data", __FUNCTION__);
LOG_DEBUG("%s - In 16-UUID_data", __FUNCTION__);
mask |= BTM_BLE_AD_BIT_SERVICE;
++bta_adv_data->p_services->num_service;
*p_uuid_out16++ = bt_uuid.uu.uuid16;
@@ -220,7 +226,7 @@ static void btc_to_bta_adv_data(esp_ble_adv_data_t *p_adv_data, tBTA_BLE_ADV_DAT
}
if (NULL != bta_adv_data->p_service_32b->p_uuid) {
LOG_ERROR("%s - In 32-UUID_data", __FUNCTION__);
LOG_DEBUG("%s - In 32-UUID_data", __FUNCTION__);
mask |= BTM_BLE_AD_BIT_SERVICE_32;
++bta_adv_data->p_service_32b->num_service;
*p_uuid_out32++ = bt_uuid.uu.uuid32;
@@ -287,7 +293,7 @@ static void btc_scan_rsp_data_callback(tBTA_STATUS status)
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_GAP_BLE;
msg.act = ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT;
param.adv_data_cmpl.status = status;
param.scan_rsp_data_cmpl.status = status;
ret = btc_transfer_context(&msg, &param,
sizeof(esp_ble_gap_cb_param_t), NULL);
@@ -297,7 +303,7 @@ static void btc_scan_rsp_data_callback(tBTA_STATUS status)
}
}
static void btc_set_scan_param_callback(tGATT_IF client_if, tBTA_STATUS status )
static void btc_adv_data_raw_callback(tBTA_STATUS status)
{
esp_ble_gap_cb_param_t param;
bt_status_t ret;
@@ -305,8 +311,8 @@ static void btc_set_scan_param_callback(tGATT_IF client_if, tBTA_STATUS status )
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_GAP_BLE;
msg.act = ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT;
param.adv_data_cmpl.status = status;
msg.act = ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT;
param.adv_data_raw_cmpl.status = status;
ret = btc_transfer_context(&msg, &param,
sizeof(esp_ble_gap_cb_param_t), NULL);
@@ -316,57 +322,74 @@ static void btc_set_scan_param_callback(tGATT_IF client_if, tBTA_STATUS status )
}
}
static void btc_scan_rsp_data_raw_callback(tBTA_STATUS status)
{
esp_ble_gap_cb_param_t param;
bt_status_t ret;
btc_msg_t msg;
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_GAP_BLE;
msg.act = ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT;
param.scan_rsp_data_raw_cmpl.status = status;
ret = btc_transfer_context(&msg, &param,
sizeof(esp_ble_gap_cb_param_t), NULL);
if (ret != BT_STATUS_SUCCESS) {
LOG_ERROR("%s btc_transfer_context failed\n", __func__);
}
}
static void btc_ble_set_adv_data(esp_ble_adv_data_t *adv_data,
tBTA_SET_ADV_DATA_CMPL_CBACK p_adv_data_cback)
{
tBTA_BLE_AD_MASK data_mask = 0;
btc_to_bta_adv_data(adv_data, &gl_bta_adv_data, &data_mask);
if (!adv_data->set_scan_rsp) {
btc_to_bta_adv_data(adv_data, &gl_bta_adv_data, &data_mask);
BTA_DmBleSetAdvConfig(data_mask, &gl_bta_adv_data, p_adv_data_cback);
} else {
BTA_DmBleSetScanRsp(data_mask, &gl_bta_adv_data, p_adv_data_cback);
btc_to_bta_adv_data(adv_data, &gl_bta_scan_rsp_data, &data_mask);
BTA_DmBleSetScanRsp(data_mask, &gl_bta_scan_rsp_data, p_adv_data_cback);
}
}
static void btc_ble_set_scan_param(esp_ble_scan_params_t *ble_scan_params,
tBLE_SCAN_PARAM_SETUP_CBACK scan_param_setup_cback)
static void btc_ble_set_adv_data_raw(uint8_t *raw_adv, uint32_t raw_adv_len,
tBTA_SET_ADV_DATA_CMPL_CBACK p_adv_data_cback)
{
//tBTA_BLE_AD_MASK data_mask = 0;
BTA_DmSetBleScanParams (ESP_DEFAULT_GATT_IF,
ble_scan_params->scan_interval,
ble_scan_params->scan_window,
ble_scan_params->scan_type,
scan_param_setup_cback);
//btc_to_bta_adv_data(scan_rsp_data, &gl_bta_scan_rsp_data, &data_mask);
//BTA_DmBleSetScanRsp(data_mask, &gl_bta_scan_rsp_data, p_scan_rsp_data_cback);
BTA_DmBleSetAdvConfigRaw(raw_adv, raw_adv_len, p_adv_data_cback);
}
void btc_ble_start_advertising (esp_ble_adv_params_t *ble_adv_params)
static void btc_ble_set_scan_rsp_data_raw(uint8_t *raw_scan_rsp, uint32_t raw_scan_rsp_len,
tBTA_SET_ADV_DATA_CMPL_CBACK p_scan_rsp_data_cback)
{
BTA_DmBleSetScanRspRaw(raw_scan_rsp, raw_scan_rsp_len, p_scan_rsp_data_cback);
}
static void btc_start_adv_callback(tBTA_STATUS status)
{
esp_ble_gap_cb_param_t param;
bt_status_t ret;
btc_msg_t msg;
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_GAP_BLE;
msg.act = ESP_GAP_BLE_ADV_START_COMPLETE_EVT;
param.adv_start_cmpl.status = status;
ret = btc_transfer_context(&msg, &param,
sizeof(esp_ble_gap_cb_param_t), NULL);
if (ret != BT_STATUS_SUCCESS) {
LOG_ERROR("%s btc_transfer_context failed\n", __func__);
}
}
static void btc_ble_start_advertising (esp_ble_adv_params_t *ble_adv_params, tBTA_START_ADV_CMPL_CBACK start_adv_cback)
{
tBTA_DM_DISC disc_mode = 0;
tBTA_DM_CONN conn_mode = 0;
tBLE_BD_ADDR peer_addr;
if (ble_adv_params->adv_type == ADV_TYPE_NONCONN_IND) {
conn_mode = BTA_DM_BLE_NON_CONNECTABLE;
} else {
conn_mode = BTA_DM_BLE_CONNECTABLE;
}
if (ble_adv_params->adv_filter_policy == ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY) {
disc_mode = BTA_DM_BLE_GENERAL_DISCOVERABLE;
} else if (ble_adv_params->adv_filter_policy == ADV_FILTER_ALLOW_SCAN_WLST_CON_ANY
|| ble_adv_params->adv_filter_policy == ADV_FILTER_ALLOW_SCAN_ANY_CON_WLST) {
disc_mode = BTA_DM_BLE_LIMITED_DISCOVERABLE;
} else if (ble_adv_params->adv_filter_policy == ADV_FILTER_ALLOW_SCAN_WLST_CON_WLST) {
disc_mode = BTA_DM_BLE_NON_DISCOVERABLE;
}
if (!BLE_ISVALID_PARAM(ble_adv_params->adv_int_min, BTM_BLE_ADV_INT_MIN, BTM_BLE_ADV_INT_MAX) ||
!BLE_ISVALID_PARAM(ble_adv_params->adv_int_max, BTM_BLE_ADV_INT_MIN, BTM_BLE_ADV_INT_MAX)) {
LOG_ERROR("Invalid advertisting interval parameters.\n");
@@ -386,7 +409,6 @@ void btc_ble_start_advertising (esp_ble_adv_params_t *ble_adv_params)
}
LOG_DEBUG("API_Ble_AppStartAdvertising\n");
///
memcpy(peer_addr.bda, ble_adv_params->peer_addr, ESP_BD_ADDR_LEN);
peer_addr.type = ble_adv_params->peer_addr_type;
BTA_DmSetBleAdvParamsAll(ble_adv_params->adv_int_min,
@@ -395,10 +417,8 @@ void btc_ble_start_advertising (esp_ble_adv_params_t *ble_adv_params)
ble_adv_params->own_addr_type,
ble_adv_params->channel_map,
ble_adv_params->adv_filter_policy,
&peer_addr);
/*set connectable,discoverable, pairable and paired only modes of local device*/
BTA_DmSetVisibility(disc_mode, conn_mode, (UINT8)BTA_DM_NON_PAIRABLE, (UINT8)BTA_DM_CONN_ALL);
&peer_addr,
start_adv_cback);
}
@@ -421,20 +441,21 @@ static void btc_scan_params_callback(tGATT_IF gatt_if, tBTM_STATUS status)
}
}
static void btc_ble_set_scan_params(esp_ble_scan_params_t *scan_params,
tBLE_SCAN_PARAM_SETUP_CBACK scan_param_setup_cback)
static void btc_ble_set_scan_params(esp_ble_scan_params_t *scan_params, tBLE_SCAN_PARAM_SETUP_CBACK scan_param_setup_cback)
{
if (BLE_ISVALID_PARAM(scan_params->scan_interval, BTM_BLE_SCAN_INT_MIN, BTM_BLE_SCAN_INT_MAX) &&
BLE_ISVALID_PARAM(scan_params->scan_window, BTM_BLE_SCAN_WIN_MIN, BTM_BLE_SCAN_WIN_MAX) &&
(scan_params->scan_type == BTM_BLE_SCAN_MODE_ACTI || scan_params->scan_type == BTM_BLE_SCAN_MODE_PASS)) {
BTA_DmSetBleScanFilterParams(0 /*client_if*/,
BTA_DmSetBleScanFilterParams(ESP_DEFAULT_GATT_IF, /*client_if*/
scan_params->scan_interval,
scan_params->scan_window,
scan_params->scan_type,
scan_params->own_addr_type,
scan_params->scan_filter_policy,
scan_param_setup_cback);
}
} else {
btc_scan_params_callback(ESP_DEFAULT_GATT_IF, BTM_ILLEGAL_VALUE);
}
}
static void btc_search_callback(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data)
@@ -455,8 +476,7 @@ static void btc_search_callback(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data
param.scan_rst.ble_addr_type = p_data->inq_res.ble_addr_type;
param.scan_rst.ble_evt_type = p_data->inq_res.ble_evt_type;
param.scan_rst.flag = p_data->inq_res.flag;
memcpy(param.scan_rst.ble_adv, p_data->inq_res.p_eir,
ESP_BLE_ADV_DATA_LEN_MAX);
memcpy(param.scan_rst.ble_adv, p_data->inq_res.p_eir, sizeof(param.scan_rst.ble_adv));
break;
}
case BTA_DM_INQ_CMPL_EVT: {
@@ -486,12 +506,33 @@ static void btc_search_callback(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data
btc_transfer_context(&msg, &param, sizeof(esp_ble_gap_cb_param_t), NULL);
}
static void btc_ble_start_scanning(uint8_t duration, tBTA_DM_SEARCH_CBACK *results_cb)
static void btc_start_scan_callback(tBTA_STATUS status)
{
if ((duration != 0) && (results_cb != NULL)) {
esp_ble_gap_cb_param_t param;
bt_status_t ret;
btc_msg_t msg;
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_GAP_BLE;
msg.act = ESP_GAP_BLE_SCAN_START_COMPLETE_EVT;
param.scan_start_cmpl.status = status;
ret = btc_transfer_context(&msg, &param,
sizeof(esp_ble_gap_cb_param_t), NULL);
if (ret != BT_STATUS_SUCCESS) {
LOG_ERROR("%s btc_transfer_context failed\n", __func__);
}
}
static void btc_ble_start_scanning(uint8_t duration,
tBTA_DM_SEARCH_CBACK *results_cb,
tBTA_START_SCAN_CMPL_CBACK *start_scan_cb)
{
if ((duration != 0) && (results_cb != NULL) && (start_scan_cb != NULL)) {
///Start scan the device
BTA_DmBleObserve(true, duration, results_cb);
BTA_DmBleObserve(true, duration, results_cb, start_scan_cb);
} else {
LOG_ERROR("The scan duration or p_results_cb invalid\n");
}
@@ -500,7 +541,7 @@ static void btc_ble_start_scanning(uint8_t duration, tBTA_DM_SEARCH_CBACK *resul
static void btc_ble_stop_scanning(void)
{
uint8_t duration = 0;
BTA_DmBleObserve(false, duration, NULL);
BTA_DmBleObserve(false, duration, NULL, NULL);
}
@@ -558,16 +599,28 @@ void btc_gap_ble_cb_handler(btc_msg_t *msg)
switch (msg->act) {
case ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT:
BTC_GAP_BLE_CB_TO_APP(ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT, param);
btc_gap_ble_cb_to_app(ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT, param);
break;
case ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT :
BTC_GAP_BLE_CB_TO_APP(ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT, param);
btc_gap_ble_cb_to_app(ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT, param);
break;
case ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT:
BTC_GAP_BLE_CB_TO_APP(ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT, param);
btc_gap_ble_cb_to_app(ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT, param);
break;
case ESP_GAP_BLE_SCAN_RESULT_EVT:
BTC_GAP_BLE_CB_TO_APP(ESP_GAP_BLE_SCAN_RESULT_EVT, param);
btc_gap_ble_cb_to_app(ESP_GAP_BLE_SCAN_RESULT_EVT, param);
break;
case ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT:
btc_gap_ble_cb_to_app(ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT, param);
break;
case ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT:
btc_gap_ble_cb_to_app(ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT, param);
break;
case ESP_GAP_BLE_ADV_START_COMPLETE_EVT:
btc_gap_ble_cb_to_app(ESP_GAP_BLE_ADV_START_COMPLETE_EVT, param);
break;
case ESP_GAP_BLE_SCAN_START_COMPLETE_EVT:
btc_gap_ble_cb_to_app(ESP_GAP_BLE_SCAN_START_COMPLETE_EVT, param);
break;
default:
break;
@@ -600,6 +653,30 @@ void btc_gap_ble_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
}
break;
}
case BTC_GAP_BLE_ACT_CFG_ADV_DATA_RAW: {
btc_ble_gap_args_t *src = (btc_ble_gap_args_t *)p_src;
btc_ble_gap_args_t *dst = (btc_ble_gap_args_t *) p_dest;
if (src && src->cfg_adv_data_raw.raw_adv && src->cfg_adv_data_raw.raw_adv_len > 0) {
dst->cfg_adv_data_raw.raw_adv = GKI_getbuf(src->cfg_adv_data_raw.raw_adv_len);
if (dst->cfg_adv_data_raw.raw_adv) {
memcpy(dst->cfg_adv_data_raw.raw_adv, src->cfg_adv_data_raw.raw_adv, src->cfg_adv_data_raw.raw_adv_len);
}
}
break;
}
case BTC_GAP_BLE_ACT_CFG_SCAN_RSP_DATA_RAW: {
btc_ble_gap_args_t *src = (btc_ble_gap_args_t *)p_src;
btc_ble_gap_args_t *dst = (btc_ble_gap_args_t *) p_dest;
if (src && src->cfg_scan_rsp_data_raw.raw_scan_rsp && src->cfg_scan_rsp_data_raw.raw_scan_rsp_len > 0) {
dst->cfg_scan_rsp_data_raw.raw_scan_rsp = GKI_getbuf(src->cfg_scan_rsp_data_raw.raw_scan_rsp_len);
if (dst->cfg_scan_rsp_data_raw.raw_scan_rsp) {
memcpy(dst->cfg_scan_rsp_data_raw.raw_scan_rsp, src->cfg_scan_rsp_data_raw.raw_scan_rsp, src->cfg_scan_rsp_data_raw.raw_scan_rsp_len);
}
}
break;
}
default:
LOG_ERROR("Unhandled deep copy %d\n", msg->act);
break;
@@ -625,6 +702,20 @@ static void btc_gap_ble_arg_deep_free(btc_msg_t *msg)
}
break;
}
case BTC_GAP_BLE_ACT_CFG_ADV_DATA_RAW: {
uint8_t *raw_adv = ((btc_ble_gap_args_t *)msg->arg)->cfg_adv_data_raw.raw_adv;
if (raw_adv) {
GKI_freebuf(raw_adv);
}
break;
}
case BTC_GAP_BLE_ACT_CFG_SCAN_RSP_DATA_RAW: {
uint8_t *raw_scan_rsp = ((btc_ble_gap_args_t *)msg->arg)->cfg_scan_rsp_data_raw.raw_scan_rsp;
if (raw_scan_rsp) {
GKI_freebuf(raw_scan_rsp);
}
break;
}
default:
LOG_DEBUG("Unhandled deep free %d\n", msg->act);
break;
@@ -647,16 +738,16 @@ void btc_gap_ble_call_handler(btc_msg_t *msg)
break;
}
case BTC_GAP_BLE_ACT_SET_SCAN_PARAM:
btc_ble_set_scan_param(&arg->set_scan_param.scan_params, btc_set_scan_param_callback);
btc_ble_set_scan_params(&arg->set_scan_param.scan_params, btc_scan_params_callback);
break;
case BTC_GAP_BLE_ACT_START_SCAN:
btc_ble_start_scanning(arg->start_scan.duration, btc_search_callback);
btc_ble_start_scanning(arg->start_scan.duration, btc_search_callback, btc_start_scan_callback);
break;
case BTC_GAP_BLE_ACT_STOP_SCAN:
btc_ble_stop_scanning();
break;
case BTC_GAP_BLE_ACT_START_ADV:
btc_ble_start_advertising(&arg->start_adv.adv_params);
btc_ble_start_advertising(&arg->start_adv.adv_params, btc_start_adv_callback);
break;
case BTC_GAP_BLE_ACT_STOP_ADV:
btc_ble_stop_advertising();
@@ -680,6 +771,16 @@ void btc_gap_ble_call_handler(btc_msg_t *msg)
case BTC_GAP_BLE_ACT_SET_DEV_NAME:
BTA_DmSetDeviceName(arg->set_dev_name.device_name);
break;
case BTC_GAP_BLE_ACT_CFG_ADV_DATA_RAW:
btc_ble_set_adv_data_raw(arg->cfg_adv_data_raw.raw_adv,
arg->cfg_adv_data_raw.raw_adv_len,
btc_adv_data_raw_callback);
break;
case BTC_GAP_BLE_ACT_CFG_SCAN_RSP_DATA_RAW:
btc_ble_set_scan_rsp_data_raw(arg->cfg_scan_rsp_data_raw.raw_scan_rsp,
arg->cfg_scan_rsp_data_raw.raw_scan_rsp_len,
btc_scan_rsp_data_raw_callback);
break;
default:
break;
}

View File

@@ -59,7 +59,7 @@ int uuidType(unsigned char *p_uuid)
return LEN_UUID_128;
}
int btc128_to_bta_uuid(tBT_UUID *p_dest, uint8_t *p_src)
void btc128_to_bta_uuid(tBT_UUID *p_dest, uint8_t *p_src)
{
int i = 0;
@@ -169,13 +169,14 @@ uint16_t get_uuid16(tBT_UUID *p_uuid)
return (UINT16) p_uuid->uu.uuid32;
}
}
uint16_t set_read_value(esp_ble_gattc_cb_param_t *p_dest, tBTA_GATTC_READ *p_src)
uint16_t set_read_value(uint8_t *gattc_if, esp_ble_gattc_cb_param_t *p_dest, tBTA_GATTC_READ *p_src)
{
uint16_t descr_type = 0;
uint16_t len = 0;
p_dest->read.status = p_src->status;
p_dest->read.conn_id = p_src->conn_id;
p_dest->read.conn_id = BTC_GATT_GET_CONN_ID(p_src->conn_id);
*gattc_if = BTC_GATT_GET_GATT_IF(p_src->conn_id);
bta_to_btc_srvc_id(&p_dest->read.srvc_id, &p_src->srvc_id);
bta_to_btc_gatt_id(&p_dest->read.char_id, &p_src->char_id);
bta_to_btc_gatt_id(&p_dest->read.descr_id, &p_src->descr_type);

View File

@@ -22,7 +22,13 @@
#include "bt_trace.h"
#include "esp_gattc_api.h"
#define BTC_GATTC_CB_TO_APP(_event, _param) ((esp_profile_cb_t )btc_profile_cb_get(BTC_PID_GATTC))(_event, _param)
static inline void btc_gattc_cb_to_app(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param)
{
esp_gattc_cb_t btc_gattc_cb = (esp_gattc_cb_t )btc_profile_cb_get(BTC_PID_GATTC);
if (btc_gattc_cb) {
btc_gattc_cb(event, gattc_if, param);
}
}
void btc_gattc_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
{
@@ -141,13 +147,13 @@ static void btc_gattc_app_register(btc_ble_gattc_args_t *arg)
static void btc_gattc_app_unregister(btc_ble_gattc_args_t *arg)
{
BTA_GATTC_AppDeregister(arg->app_unreg.gatt_if);
BTA_GATTC_AppDeregister(arg->app_unreg.gattc_if);
}
static void btc_gattc_open(btc_ble_gattc_args_t *arg)
{
tBTA_GATT_TRANSPORT transport = BTA_GATT_TRANSPORT_LE;
BTA_GATTC_Open(arg->open.gatt_if, arg->open.remote_bda, arg->open.is_direct, transport);
BTA_GATTC_Open(arg->open.gattc_if, arg->open.remote_bda, arg->open.is_direct, transport);
}
static void btc_gattc_close(btc_ble_gattc_args_t *arg)
@@ -181,6 +187,7 @@ static void btc_gattc_get_first_char(btc_ble_gattc_args_t *arg)
tBTA_GATT_CHAR_PROP out_char_prop;
tBTA_GATT_SRVC_ID srvc_id;
esp_ble_gattc_cb_param_t param;
esp_gatt_if_t gattc_if;
btc_to_bta_srvc_id(&srvc_id, &arg->get_first_char.service_id);
status = BTA_GATTC_GetFirstChar(arg->get_first_char.conn_id, &srvc_id, NULL,
@@ -189,13 +196,14 @@ static void btc_gattc_get_first_char(btc_ble_gattc_args_t *arg)
bta_to_btc_gatt_id(&char_id, &out_char_id.char_id);
}
gattc_if = BTC_GATT_GET_GATT_IF(arg->get_first_char.conn_id);
memset(&param, 0, sizeof(esp_ble_gattc_cb_param_t));
param.get_char.conn_id = arg->get_first_char.conn_id;
param.get_char.conn_id = BTC_GATT_GET_CONN_ID(arg->get_first_char.conn_id);
param.get_char.status = status;
memcpy(&param.get_char.srvc_id, &arg->get_first_char.service_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&param.get_char.char_id, &char_id, sizeof(esp_gatt_id_t));
param.get_char.char_prop = out_char_prop;
BTC_GATTC_CB_TO_APP(ESP_GATTC_GET_CHAR_EVT, &param);
btc_gattc_cb_to_app(ESP_GATTC_GET_CHAR_EVT, gattc_if, &param);
}
static void btc_gattc_get_next_char(btc_ble_gattc_args_t *arg)
@@ -206,6 +214,8 @@ static void btc_gattc_get_next_char(btc_ble_gattc_args_t *arg)
tBTA_GATTC_CHAR_ID out_char_id;
tBTA_GATT_CHAR_PROP out_char_prop;
esp_ble_gattc_cb_param_t param;
esp_gatt_if_t gattc_if;
btc_to_bta_srvc_id(&in_char_id.srvc_id, &arg->get_next_char.service_id);
btc_to_bta_gatt_id(&in_char_id.char_id, &arg->get_next_char.char_id);
@@ -216,13 +226,14 @@ static void btc_gattc_get_next_char(btc_ble_gattc_args_t *arg)
bta_to_btc_gatt_id(&char_id, &out_char_id.char_id);
}
gattc_if = BTC_GATT_GET_GATT_IF(arg->get_next_char.conn_id);
memset(&param, 0, sizeof(esp_ble_gattc_cb_param_t));
param.get_char.conn_id = arg->get_next_char.conn_id;
param.get_char.conn_id = BTC_GATT_GET_CONN_ID(arg->get_next_char.conn_id);
param.get_char.status = status;
memcpy(&param.get_char.srvc_id, &arg->get_next_char.service_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&param.get_char.char_id, &char_id, sizeof(esp_gatt_id_t));
param.get_char.char_prop = out_char_prop;
BTC_GATTC_CB_TO_APP(ESP_GATTC_GET_CHAR_EVT, &param);
btc_gattc_cb_to_app(ESP_GATTC_GET_CHAR_EVT, gattc_if, &param);
}
static void btc_gattc_get_first_descr(btc_ble_gattc_args_t *arg)
@@ -232,6 +243,7 @@ static void btc_gattc_get_first_descr(btc_ble_gattc_args_t *arg)
tBTA_GATTC_CHAR_ID in_char_id;
tBTA_GATTC_CHAR_DESCR_ID out_char_descr_id;
esp_ble_gattc_cb_param_t param;
esp_gatt_if_t gattc_if;
btc_to_bta_srvc_id(&in_char_id.srvc_id, &arg->get_first_descr.service_id);
btc_to_bta_gatt_id(&in_char_id.char_id, &arg->get_first_descr.char_id);
@@ -243,13 +255,14 @@ static void btc_gattc_get_first_descr(btc_ble_gattc_args_t *arg)
bta_to_btc_gatt_id(&descr_id, &out_char_descr_id.descr_id);
}
gattc_if = BTC_GATT_GET_GATT_IF(arg->get_first_descr.conn_id);
memset(&param, 0, sizeof(esp_ble_gattc_cb_param_t));
param.get_descr.conn_id = arg->get_first_descr.conn_id;
param.get_descr.conn_id = BTC_GATT_GET_CONN_ID(arg->get_first_descr.conn_id);
param.get_descr.status = status;
memcpy(&param.get_descr.srvc_id, &arg->get_first_descr.service_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&param.get_descr.char_id, &arg->get_first_descr.char_id, sizeof(esp_gatt_id_t));
memcpy(&param.get_descr.descr_id, &descr_id, sizeof(esp_gatt_id_t));
BTC_GATTC_CB_TO_APP(ESP_GATTC_GET_DESCR_EVT, &param);
btc_gattc_cb_to_app(ESP_GATTC_GET_DESCR_EVT, gattc_if, &param);
}
static void btc_gattc_get_next_descr(btc_ble_gattc_args_t *arg)
@@ -259,6 +272,7 @@ static void btc_gattc_get_next_descr(btc_ble_gattc_args_t *arg)
tBTA_GATTC_CHAR_DESCR_ID in_char_descr_id;
tBTA_GATTC_CHAR_DESCR_ID out_char_descr_id;
esp_ble_gattc_cb_param_t param;
esp_gatt_if_t gattc_if;
btc_to_bta_srvc_id(&in_char_descr_id.char_id.srvc_id, &arg->get_next_descr.service_id);
btc_to_bta_gatt_id(&in_char_descr_id.char_id.char_id, &arg->get_next_descr.char_id);
@@ -270,13 +284,14 @@ static void btc_gattc_get_next_descr(btc_ble_gattc_args_t *arg)
bta_to_btc_gatt_id(&descr_id, &out_char_descr_id.descr_id);
}
gattc_if = BTC_GATT_GET_GATT_IF(arg->get_next_descr.conn_id);
memset(&param, 0, sizeof(esp_ble_gattc_cb_param_t));
param.get_descr.conn_id = arg->get_next_descr.conn_id;
param.get_descr.conn_id = BTC_GATT_GET_CONN_ID(arg->get_next_descr.conn_id);
param.get_descr.status = status;
memcpy(&param.get_descr.srvc_id, &arg->get_next_descr.service_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&param.get_descr.char_id, &arg->get_next_descr.char_id, sizeof(esp_gatt_id_t));
memcpy(&param.get_descr.descr_id, &descr_id, sizeof(esp_gatt_id_t));
BTC_GATTC_CB_TO_APP(ESP_GATTC_GET_DESCR_EVT, &param);
btc_gattc_cb_to_app(ESP_GATTC_GET_DESCR_EVT, gattc_if, &param);
}
static void btc_gattc_get_first_incl_service(btc_ble_gattc_args_t *arg)
@@ -286,6 +301,7 @@ static void btc_gattc_get_first_incl_service(btc_ble_gattc_args_t *arg)
tBTA_GATT_SRVC_ID srvc_id;
tBTA_GATTC_INCL_SVC_ID out_incl_svc_id;
esp_ble_gattc_cb_param_t param;
esp_gatt_if_t gattc_if;
btc_to_bta_srvc_id(&srvc_id, &arg->get_first_incl_srvc.service_id);
@@ -294,12 +310,13 @@ static void btc_gattc_get_first_incl_service(btc_ble_gattc_args_t *arg)
bta_to_btc_srvc_id(&incl_srvc_id, &out_incl_svc_id.incl_svc_id);
gattc_if = BTC_GATT_GET_GATT_IF(arg->get_first_incl_srvc.conn_id);
memset(&param, 0, sizeof(esp_ble_gattc_cb_param_t));
param.get_incl_srvc.conn_id = arg->get_first_incl_srvc.conn_id;
param.get_incl_srvc.conn_id = BTC_GATT_GET_CONN_ID(arg->get_first_incl_srvc.conn_id);
param.get_incl_srvc.status = status;
memcpy(&param.get_incl_srvc.srvc_id, &arg->get_first_incl_srvc.service_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&param.get_incl_srvc.incl_srvc_id, &incl_srvc_id, sizeof(esp_gatt_srvc_id_t));
BTC_GATTC_CB_TO_APP(ESP_GATTC_GET_INCL_SRVC_EVT, &param);
btc_gattc_cb_to_app(ESP_GATTC_GET_INCL_SRVC_EVT, gattc_if, &param);
}
static void btc_gattc_get_next_incl_service(btc_ble_gattc_args_t *arg)
@@ -309,6 +326,7 @@ static void btc_gattc_get_next_incl_service(btc_ble_gattc_args_t *arg)
tBTA_GATTC_INCL_SVC_ID in_incl_svc_id;
tBTA_GATTC_INCL_SVC_ID out_incl_svc_id;
esp_ble_gattc_cb_param_t param;
esp_gatt_if_t gattc_if;
btc_to_bta_srvc_id(&in_incl_svc_id.srvc_id, &arg->get_next_incl_srvc.service_id);
btc_to_bta_srvc_id(&in_incl_svc_id.incl_svc_id, &arg->get_next_incl_srvc.start_service_id);
@@ -318,12 +336,13 @@ static void btc_gattc_get_next_incl_service(btc_ble_gattc_args_t *arg)
bta_to_btc_srvc_id(&incl_srvc_id, &out_incl_svc_id.incl_svc_id);
gattc_if = BTC_GATT_GET_GATT_IF(arg->get_next_incl_srvc.conn_id);
memset(&param, 0, sizeof(esp_ble_gattc_cb_param_t));
param.get_incl_srvc.conn_id = arg->get_next_incl_srvc.conn_id;
param.get_incl_srvc.conn_id = BTC_GATT_GET_CONN_ID(arg->get_next_incl_srvc.conn_id);
param.get_incl_srvc.status = status;
memcpy(&param.get_incl_srvc.srvc_id, &arg->get_next_incl_srvc.service_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&param.get_incl_srvc.incl_srvc_id, &incl_srvc_id, sizeof(esp_gatt_srvc_id_t));
BTC_GATTC_CB_TO_APP(ESP_GATTC_GET_INCL_SRVC_EVT, &param);
btc_gattc_cb_to_app(ESP_GATTC_GET_INCL_SRVC_EVT, gattc_if, &param);
}
static void btc_gattc_read_char(btc_ble_gattc_args_t *arg)
@@ -402,15 +421,15 @@ static void btc_gattc_reg_for_notify(btc_ble_gattc_args_t *arg)
btc_to_bta_srvc_id(&in_char_id.srvc_id, &arg->reg_for_notify.service_id);
btc_to_bta_gatt_id(&in_char_id.char_id, &arg->reg_for_notify.char_id);
status = BTA_GATTC_RegisterForNotifications(arg->reg_for_notify.gatt_if,
status = BTA_GATTC_RegisterForNotifications(arg->reg_for_notify.gattc_if,
arg->reg_for_notify.remote_bda,
&in_char_id);
memset(&param, 0, sizeof(esp_ble_gattc_cb_param_t));
param.reg_for_notify.status = status;
memcpy(&param.reg_for_notify.srvc_id, &arg->reg_for_notify.service_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&param.reg_for_notify.char_id, &arg->reg_for_notify.service_id, sizeof(esp_gatt_id_t));
BTC_GATTC_CB_TO_APP(ESP_GATTC_REG_FOR_NOTIFY_EVT, &param);
memcpy(&param.reg_for_notify.char_id, &arg->reg_for_notify.char_id, sizeof(esp_gatt_id_t));
btc_gattc_cb_to_app(ESP_GATTC_REG_FOR_NOTIFY_EVT, arg->reg_for_notify.gattc_if, &param);
}
static void btc_gattc_unreg_for_notify(btc_ble_gattc_args_t *arg)
@@ -422,15 +441,15 @@ static void btc_gattc_unreg_for_notify(btc_ble_gattc_args_t *arg)
btc_to_bta_srvc_id(&in_char_id.srvc_id, &arg->unreg_for_notify.service_id);
btc_to_bta_gatt_id(&in_char_id.char_id, &arg->unreg_for_notify.char_id);
status = BTA_GATTC_DeregisterForNotifications(arg->unreg_for_notify.gatt_if,
status = BTA_GATTC_DeregisterForNotifications(arg->unreg_for_notify.gattc_if,
arg->unreg_for_notify.remote_bda,
&in_char_id);
memset(&param, 0, sizeof(esp_ble_gattc_cb_param_t));
param.unreg_for_notify.status = status;
memcpy(&param.unreg_for_notify.srvc_id, &arg->unreg_for_notify.service_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&param.unreg_for_notify.char_id, &arg->unreg_for_notify.service_id, sizeof(esp_gatt_id_t));
BTC_GATTC_CB_TO_APP(ESP_GATTC_UNREG_FOR_NOTIFY_EVT, &param);
memcpy(&param.unreg_for_notify.char_id, &arg->unreg_for_notify.char_id, sizeof(esp_gatt_id_t));
btc_gattc_cb_to_app(ESP_GATTC_UNREG_FOR_NOTIFY_EVT, arg->unreg_for_notify.gattc_if, &param);
}
void btc_gattc_call_handler(btc_msg_t *msg)
@@ -508,6 +527,7 @@ void btc_gattc_call_handler(btc_msg_t *msg)
void btc_gattc_cb_handler(btc_msg_t *msg)
{
tBTA_GATTC *arg = (tBTA_GATTC *)(msg->arg);
esp_gatt_if_t gattc_if;
esp_ble_gattc_cb_param_t param;
memset(&param, 0, sizeof(esp_ble_gattc_cb_param_t));
@@ -515,76 +535,91 @@ void btc_gattc_cb_handler(btc_msg_t *msg)
switch (msg->act) {
case BTA_GATTC_REG_EVT: {
tBTA_GATTC_REG *reg_oper = &arg->reg_oper;
gattc_if = reg_oper->client_if;
param.reg.status = reg_oper->status;
param.reg.gatt_if = reg_oper->client_if;
param.reg.app_id = reg_oper->app_uuid.uu.uuid16;
BTC_GATTC_CB_TO_APP(ESP_GATTC_REG_EVT, &param);
btc_gattc_cb_to_app(ESP_GATTC_REG_EVT, gattc_if, &param);
break;
}
case BTA_GATTC_DEREG_EVT: {
BTC_GATTC_CB_TO_APP(ESP_GATTC_UNREG_EVT, NULL);
tBTA_GATTC_REG *reg_oper = &arg->reg_oper;
gattc_if = reg_oper->client_if;
btc_gattc_cb_to_app(ESP_GATTC_UNREG_EVT, gattc_if, NULL);
break;
}
case BTA_GATTC_READ_CHAR_EVT: {
set_read_value(&param, &arg->read);
BTC_GATTC_CB_TO_APP(ESP_GATTC_READ_CHAR_EVT, &param);
set_read_value(&gattc_if, &param, &arg->read);
btc_gattc_cb_to_app(ESP_GATTC_READ_CHAR_EVT, gattc_if, &param);
break;
}
case BTA_GATTC_WRITE_CHAR_EVT:
case BTA_GATTC_PREP_WRITE_EVT: {
tBTA_GATTC_WRITE *write = &arg->write;
uint32_t ret_evt = (msg->act == BTA_GATTC_WRITE_CHAR_EVT) ?
ESP_GATTC_WRITE_CHAR_EVT : ESP_GATTC_PREP_WRITE_EVT;
param.write.conn_id = write->conn_id;
gattc_if = BTC_GATT_GET_GATT_IF(write->conn_id);
param.write.conn_id = BTC_GATT_GET_CONN_ID(write->conn_id);
param.write.status = write->status;
bta_to_btc_srvc_id(&param.write.srvc_id, &write->srvc_id);
bta_to_btc_gatt_id(&param.write.char_id, &write->char_id);
BTC_GATTC_CB_TO_APP(ret_evt, &param);
btc_gattc_cb_to_app(ret_evt, gattc_if, &param);
break;
}
case BTA_GATTC_EXEC_EVT: {
tBTA_GATTC_EXEC_CMPL *exec_cmpl = &arg->exec_cmpl;
param.exec_cmpl.conn_id = exec_cmpl->conn_id;
gattc_if = BTC_GATT_GET_GATT_IF(exec_cmpl->conn_id);
param.exec_cmpl.conn_id = BTC_GATT_GET_CONN_ID(exec_cmpl->conn_id);
param.exec_cmpl.status = exec_cmpl->status;
BTC_GATTC_CB_TO_APP(ESP_GATTC_EXEC_EVT, &param);
btc_gattc_cb_to_app(ESP_GATTC_EXEC_EVT, gattc_if, &param);
break;
}
case BTA_GATTC_SEARCH_CMPL_EVT: {
tBTA_GATTC_SEARCH_CMPL *search_cmpl = &arg->search_cmpl;
param.search_cmpl.conn_id = search_cmpl->conn_id;
gattc_if = BTC_GATT_GET_GATT_IF(search_cmpl->conn_id);
param.search_cmpl.conn_id = BTC_GATT_GET_CONN_ID(search_cmpl->conn_id);
param.search_cmpl.status = search_cmpl->status;
BTC_GATTC_CB_TO_APP(ESP_GATTC_SEARCH_CMPL_EVT, &param);
btc_gattc_cb_to_app(ESP_GATTC_SEARCH_CMPL_EVT, gattc_if, &param);
break;
}
case BTA_GATTC_SEARCH_RES_EVT: {
tBTA_GATTC_SRVC_RES *srvc_res = &arg->srvc_res;
param.search_res.conn_id = srvc_res->conn_id;
gattc_if = BTC_GATT_GET_GATT_IF(srvc_res->conn_id);
param.search_res.conn_id = BTC_GATT_GET_CONN_ID(srvc_res->conn_id);
bta_to_btc_srvc_id(&param.search_res.srvc_id, &srvc_res->service_uuid);
BTC_GATTC_CB_TO_APP(ESP_GATTC_SEARCH_RES_EVT, &param);
btc_gattc_cb_to_app(ESP_GATTC_SEARCH_RES_EVT, gattc_if, &param);
break;
}
case BTA_GATTC_READ_DESCR_EVT: {
set_read_value(&param, &arg->read);
BTC_GATTC_CB_TO_APP(ESP_GATTC_READ_DESCR_EVT, &param);
set_read_value(&gattc_if, &param, &arg->read);
btc_gattc_cb_to_app(ESP_GATTC_READ_DESCR_EVT, gattc_if, &param);
break;
}
case BTA_GATTC_WRITE_DESCR_EVT: {
tBTA_GATTC_WRITE *write = &arg->write;
param.write.conn_id = write->conn_id;
gattc_if = BTC_GATT_GET_GATT_IF(write->conn_id);
param.write.conn_id = BTC_GATT_GET_CONN_ID(write->conn_id);
param.write.status = write->status;
bta_to_btc_srvc_id(&param.write.srvc_id, &write->srvc_id);
bta_to_btc_gatt_id(&param.write.char_id, &write->char_id);
bta_to_btc_gatt_id(&param.write.descr_id, &write->descr_type);
BTC_GATTC_CB_TO_APP(ESP_GATTC_WRITE_DESCR_EVT, &param);
btc_gattc_cb_to_app(ESP_GATTC_WRITE_DESCR_EVT, gattc_if, &param);
break;
}
case BTA_GATTC_NOTIF_EVT: {
tBTA_GATTC_NOTIFY *notify = &arg->notify;
param.notify.conn_id = notify->conn_id;
memcpy(&param.notify.remote_bda, &notify->bda, sizeof(esp_bd_addr_t));
gattc_if = BTC_GATT_GET_GATT_IF(notify->conn_id);
param.notify.conn_id = BTC_GATT_GET_CONN_ID(notify->conn_id);
memcpy(param.notify.remote_bda, notify->bda, sizeof(esp_bd_addr_t));
bta_to_btc_srvc_id(&param.notify.srvc_id, &notify->char_id.srvc_id);
bta_to_btc_gatt_id(&param.notify.char_id, &notify->char_id.char_id);
bta_to_btc_gatt_id(&param.notify.descr_id, &notify->descr_type);
@@ -597,57 +632,63 @@ void btc_gattc_cb_handler(btc_msg_t *msg)
BTA_GATTC_SendIndConfirm(notify->conn_id, &notify->char_id);
}
BTC_GATTC_CB_TO_APP(ESP_GATTC_NOTIFY_EVT, &param);
btc_gattc_cb_to_app(ESP_GATTC_NOTIFY_EVT, gattc_if, &param);
break;
}
case BTA_GATTC_OPEN_EVT: {
tBTA_GATTC_OPEN *open = &arg->open;
gattc_if = open->client_if;
param.open.status = open->status;
param.open.conn_id = open->conn_id;
param.open.gatt_if = open->client_if;
memcpy(&param.open.remote_bda, &open->remote_bda, sizeof(esp_bd_addr_t));
param.open.conn_id = BTC_GATT_GET_CONN_ID(open->conn_id);
memcpy(param.open.remote_bda, open->remote_bda, sizeof(esp_bd_addr_t));
param.open.mtu = open->mtu;
BTC_GATTC_CB_TO_APP(ESP_GATTC_OPEN_EVT, &param);
btc_gattc_cb_to_app(ESP_GATTC_OPEN_EVT, gattc_if, &param);
break;
}
case BTA_GATTC_CLOSE_EVT: {
tBTA_GATTC_CLOSE *close = &arg->close;
gattc_if = close->client_if;
param.close.status = close->status;
param.close.conn_id = close->conn_id;
param.close.gatt_if = close->client_if;
memcpy(&param.close.remote_bda, &close->remote_bda, sizeof(esp_bd_addr_t));
param.close.conn_id = BTC_GATT_GET_CONN_ID(close->conn_id);
memcpy(param.close.remote_bda, close->remote_bda, sizeof(esp_bd_addr_t));
param.close.reason = close->reason;
BTC_GATTC_CB_TO_APP(ESP_GATTC_CLOSE_EVT, &param);
btc_gattc_cb_to_app(ESP_GATTC_CLOSE_EVT, gattc_if, &param);
break;
}
case BTA_GATTC_CFG_MTU_EVT: {
tBTA_GATTC_CFG_MTU *cfg_mtu = &arg->cfg_mtu;
param.cfg_mtu.conn_id = cfg_mtu->conn_id;
gattc_if = BTC_GATT_GET_GATT_IF(cfg_mtu->conn_id);
param.cfg_mtu.conn_id = BTC_GATT_GET_CONN_ID(cfg_mtu->conn_id);
param.cfg_mtu.status = cfg_mtu->status;
param.cfg_mtu.mtu = cfg_mtu->mtu;
BTC_GATTC_CB_TO_APP(ESP_GATTC_CFG_MTU_EVT, &param);
btc_gattc_cb_to_app(ESP_GATTC_CFG_MTU_EVT, gattc_if, &param);
break;
}
case BTA_GATTC_ACL_EVT: {
BTC_GATTC_CB_TO_APP(ESP_GATTC_ACL_EVT, NULL);
/* Currently, this event will never happen */
break;
}
case BTA_GATTC_CANCEL_OPEN_EVT: {
BTC_GATTC_CB_TO_APP(ESP_GATTC_CANCEL_OPEN_EVT, NULL);
/* Currently, this event will never happen */
break;
}
case BTA_GATTC_CONGEST_EVT: {
tBTA_GATTC_CONGEST *congest = &arg->congest;
param.congest.conn_id = congest->conn_id;
gattc_if = BTC_GATT_GET_GATT_IF(congest->conn_id);
param.congest.conn_id = BTC_GATT_GET_CONN_ID(congest->conn_id);
param.congest.congested = (congest->congested == TRUE) ? true : false;
BTC_GATTC_CB_TO_APP(ESP_GATTC_CONGEST_EVT, &param);
btc_gattc_cb_to_app(ESP_GATTC_CONGEST_EVT, gattc_if, &param);
break;
}
case BTA_GATTC_SRVC_CHG_EVT: {
memcpy(&param.srvc_chg.remote_bda, &arg->remote_bda, sizeof(esp_bd_addr_t));
BTC_GATTC_CB_TO_APP(ESP_GATTC_SRVC_CHG_EVT, &param);
memcpy(param.srvc_chg.remote_bda, arg->remote_bda, sizeof(esp_bd_addr_t));
btc_gattc_cb_to_app(ESP_GATTC_SRVC_CHG_EVT, ESP_GATT_IF_NONE, &param);
break;
}
default:

View File

@@ -20,14 +20,52 @@
#include "btc_manage.h"
#include "btc_gatts.h"
#include "btc_gatt_util.h"
#include "future.h"
#include "btc_main.h"
#include "esp_gatts_api.h"
#define BTC_GATTS_CB_TO_APP(_event, _param) ((esp_profile_cb_t)btc_profile_cb_get(BTC_PID_GATTS))(_event, _param)
#define A2C_GATTS_EVT(_bta_event) (_bta_event) //BTA TO BTC EVT
#define C2A_GATTS_EVT(_btc_event) (_btc_event) //BTC TO BTA EVT
typedef struct {
future_t *complete_future;
uint16_t svc_start_hdl;
esp_bt_uuid_t svc_uuid;
bool is_tab_creat_svc;
uint8_t num_handle;
uint8_t handle_idx;
uint16_t handles[ESP_GATT_ATTR_HANDLE_MAX];
} esp_btc_creat_tab_t;
static esp_btc_creat_tab_t btc_creat_tab_env;
static inline void btc_gatts_cb_to_app(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param)
{
esp_gatts_cb_t btc_gatts_cb = (esp_gatts_cb_t)btc_profile_cb_get(BTC_PID_GATTS);
if (btc_gatts_cb) {
btc_gatts_cb(event, gatts_if, param);
}
}
static inline void btc_gatts_uuid_format_convert(esp_bt_uuid_t* dest_uuid, uint16_t src_uuid_len, uint8_t* src_uuid_p)
{
dest_uuid->len = src_uuid_len;
if(src_uuid_len == ESP_UUID_LEN_16){
dest_uuid->uuid.uuid16 = src_uuid_p[0] + (src_uuid_p[1]<<8);
}
else if(src_uuid_len == ESP_UUID_LEN_32){
dest_uuid->uuid.uuid32 = src_uuid_p[0] + (src_uuid_p[1]<<8) + (src_uuid_p[2]<<16) + (src_uuid_p[3]<<24);
}
else if(src_uuid_len == ESP_UUID_LEN_128){
memcpy(dest_uuid->uuid.uuid128, src_uuid_p, src_uuid_len);
}
else{
LOG_ERROR("%s wrong uuid length %d\n", __func__, src_uuid_len);
}
}
void btc_gatts_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
{
btc_ble_gatts_args_t *dst = (btc_ble_gatts_args_t *) p_dest;
@@ -53,6 +91,56 @@ void btc_gatts_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
}
}
break;
}
case BTC_GATTS_ACT_ADD_CHAR:{
if (src->add_char.char_val.attr_value != NULL){
dst->add_char.char_val.attr_value = (uint8_t *)GKI_getbuf(src->add_char.char_val.attr_len);
if(dst->add_char.char_val.attr_value != NULL){
memcpy(dst->add_char.char_val.attr_value, src->add_char.char_val.attr_value,
src->add_char.char_val.attr_len);
}else{
LOG_ERROR("%s %d no mem\n", __func__, msg->act);
}
}
break;
}
case BTC_GATTS_ACT_ADD_CHAR_DESCR:{
if(src->add_descr.descr_val.attr_value != NULL){
dst->add_descr.descr_val.attr_value = (uint8_t *)GKI_getbuf(src->add_descr.descr_val.attr_len);
if(dst->add_descr.descr_val.attr_value != NULL){
memcpy(dst->add_descr.descr_val.attr_value, src->add_descr.descr_val.attr_value,
src->add_descr.descr_val.attr_len);
}else{
LOG_ERROR("%s %d no mem\n", __func__, msg->act);
}
}
break;
}
case BTC_GATTS_ACT_CREATE_ATTR_TAB:{
uint8_t num_attr = src->create_attr_tab.max_nb_attr;
if(src->create_attr_tab.gatts_attr_db != NULL){
dst->create_attr_tab.gatts_attr_db = (esp_gatts_attr_db_t *)GKI_getbuf(sizeof(esp_gatts_attr_db_t)*num_attr);
if(dst->create_attr_tab.gatts_attr_db != NULL){
memcpy(dst->create_attr_tab.gatts_attr_db, src->create_attr_tab.gatts_attr_db,
sizeof(esp_gatts_attr_db_t)*num_attr);
}else{
LOG_ERROR("%s %d no mem\n",__func__, msg->act);
}
}
break;
}
case BTC_GATTS_ACT_SET_ATTR_VALUE:{
uint8_t len = src->set_attr_val.length;
if(src->set_attr_val.value){
dst->set_attr_val.value = (uint8_t *)GKI_getbuf(len);
if(dst->set_attr_val.value != NULL){
memcpy(dst->set_attr_val.value, src->set_attr_val.value, len);
}else{
LOG_ERROR("%s %d no mem\n",__func__, msg->act);
}
}
break;
}
default:
LOG_DEBUG("%s Unhandled deep copy %d\n", __func__, msg->act);
@@ -78,6 +166,30 @@ void btc_gatts_arg_deep_free(btc_msg_t *msg)
}
break;
}
case BTC_GATTS_ACT_ADD_CHAR:{
if (arg->add_char.char_val.attr_value != NULL) {
GKI_freebuf(arg->add_char.char_val.attr_value);
}
break;
}
case BTC_GATTS_ACT_ADD_CHAR_DESCR:{
if (arg->add_descr.descr_val.attr_value != NULL){
GKI_freebuf(arg->add_descr.descr_val.attr_value);
}
break;
}
case BTC_GATTS_ACT_CREATE_ATTR_TAB:{
if (arg->create_attr_tab.gatts_attr_db != NULL){
GKI_freebuf(arg->create_attr_tab.gatts_attr_db);
}
break;
}
case BTC_GATTS_ACT_SET_ATTR_VALUE:{
if (arg->set_attr_val.value != NULL){
GKI_freebuf(arg->set_attr_val.value);
}
}
default:
LOG_DEBUG("%s Unhandled deep free %d\n", __func__, msg->act);
break;
@@ -85,6 +197,178 @@ void btc_gatts_arg_deep_free(btc_msg_t *msg)
}
static void btc_gatts_act_create_attr_tab(esp_gatts_attr_db_t *gatts_attr_db,
esp_gatt_if_t gatts_if,
uint8_t max_nb_attr,
uint8_t srvc_inst_id)
{
uint16_t uuid = 0;
future_t *future_p;
esp_ble_gatts_cb_param_t param;
//set the attribute table create service flag to true
btc_creat_tab_env.is_tab_creat_svc = true;
btc_creat_tab_env.num_handle = max_nb_attr;
for(int i = 0; i < max_nb_attr; i++){
if(gatts_attr_db[i].att_desc.uuid_length== ESP_UUID_LEN_16){
uuid = (gatts_attr_db[i].att_desc.uuid_p[1] << 8) + (gatts_attr_db[i].att_desc.uuid_p[0]);
}
else{
continue;
}
future_p = future_new();
if (future_p == NULL) {
LOG_ERROR("%s failed:no mem\n", __func__);
return ;
}
btc_creat_tab_env.complete_future = future_p;
btc_creat_tab_env.handle_idx = i;
switch(uuid)
{
case ESP_GATT_UUID_PRI_SERVICE:{
tBTA_GATT_SRVC_ID srvc_id;
esp_gatt_srvc_id_t esp_srvc_id;
esp_srvc_id.id.inst_id = srvc_inst_id;
btc_gatts_uuid_format_convert(&esp_srvc_id.id.uuid,gatts_attr_db[i].att_desc.length,
gatts_attr_db[i].att_desc.value);
btc_to_bta_srvc_id(&srvc_id, &esp_srvc_id);
BTA_GATTS_CreateService(gatts_if, &srvc_id.id.uuid,
srvc_inst_id, max_nb_attr, true);
if (future_await(future_p) == FUTURE_FAIL) {
LOG_ERROR("%s failed\n", __func__);
return;
}
break;
}
case ESP_GATT_UUID_SEC_SERVICE:{
tBTA_GATT_SRVC_ID srvc_id;
esp_gatt_srvc_id_t esp_srvc_id;
esp_srvc_id.id.inst_id = srvc_inst_id;
btc_gatts_uuid_format_convert(&esp_srvc_id.id.uuid,gatts_attr_db[i].att_desc.uuid_length,
gatts_attr_db[i].att_desc.uuid_p);
btc_to_bta_srvc_id(&srvc_id, &esp_srvc_id);
BTA_GATTS_CreateService(gatts_if, &srvc_id.id.uuid,
srvc_inst_id, max_nb_attr, false);
if (future_await(future_p) == FUTURE_FAIL) {
LOG_ERROR("%s failed\n", __func__);
return;
}
break;
}
case ESP_GATT_UUID_INCLUDE_SERVICE:{
esp_gatts_incl_svc_desc_t *incl_svc_desc = (esp_gatts_incl_svc_desc_t *)gatts_attr_db[i].att_desc.value;
if(incl_svc_desc!= NULL){
if(btc_creat_tab_env.svc_start_hdl != 0){
BTA_GATTS_AddIncludeService(btc_creat_tab_env.svc_start_hdl,
incl_svc_desc->start_hdl);
if (future_await(future_p) == FUTURE_FAIL) {
LOG_ERROR("%s failed\n", __func__);
return;
}
}
}
break;
}
case ESP_GATT_UUID_CHAR_DECLARE:{
uint16_t svc_hal = 0;
tBT_UUID bta_char_uuid;
tGATT_ATTR_VAL attr_val;
esp_bt_uuid_t uuid_temp;
tBTA_GATT_PERM perm;
tBTA_GATTS_ATTR_CONTROL control;
uint8_t char_property;
if(btc_creat_tab_env.svc_start_hdl != 0){
svc_hal = btc_creat_tab_env.svc_start_hdl;
if((gatts_attr_db[i].att_desc.value) == NULL){
LOG_ERROR("%s Characteristic declaration should not be NULL\n", __func__);
}
else{
char_property = (uint8_t)(*(uint8_t*)(gatts_attr_db[i].att_desc.value));
perm = gatts_attr_db[i+1].att_desc.perm;
attr_val.attr_len = gatts_attr_db[i+1].att_desc.length;
attr_val.attr_max_len = gatts_attr_db[i+1].att_desc.max_length;
btc_gatts_uuid_format_convert(&uuid_temp, gatts_attr_db[i+1].att_desc.uuid_length,gatts_attr_db[i+1].att_desc.uuid_p);
btc_to_bta_uuid(&bta_char_uuid, &uuid_temp);
attr_val.attr_val = gatts_attr_db[i+1].att_desc.value;
control.auto_rsp = gatts_attr_db[i+1].attr_control.auto_rsp;
BTA_GATTS_AddCharacteristic (svc_hal, &bta_char_uuid,
perm, char_property, &attr_val, &control);
if (future_await(future_p) == FUTURE_FAIL) {
LOG_ERROR("%s failed\n", __func__);
return;
}
}
}
break;
}
case ESP_GATT_UUID_CHAR_EXT_PROP:
case ESP_GATT_UUID_CHAR_DESCRIPTION:
case ESP_GATT_UUID_CHAR_CLIENT_CONFIG:
case ESP_GATT_UUID_CHAR_SRVR_CONFIG:
case ESP_GATT_UUID_CHAR_PRESENT_FORMAT:
case ESP_GATT_UUID_CHAR_AGG_FORMAT:
case ESP_GATT_UUID_CHAR_VALID_RANGE:
case ESP_GATT_UUID_EXT_RPT_REF_DESCR:
case ESP_GATT_UUID_RPT_REF_DESCR:{
uint16_t svc_hal = btc_creat_tab_env.svc_start_hdl;
tBT_UUID bta_char_uuid;
esp_bt_uuid_t uuid_temp;
tGATT_ATTR_VAL attr_val;
tBTA_GATT_PERM perm = gatts_attr_db[i].att_desc.perm;
tBTA_GATTS_ATTR_CONTROL control;
if(svc_hal != 0){
attr_val.attr_len = gatts_attr_db[i].att_desc.length;
attr_val.attr_max_len = gatts_attr_db[i].att_desc.max_length;
attr_val.attr_val = gatts_attr_db[i].att_desc.value;
btc_gatts_uuid_format_convert(&uuid_temp, gatts_attr_db[i].att_desc.uuid_length,
gatts_attr_db[i].att_desc.uuid_p);
btc_to_bta_uuid(&bta_char_uuid, &uuid_temp);
control.auto_rsp = gatts_attr_db[i].attr_control.auto_rsp;
BTA_GATTS_AddCharDescriptor(svc_hal, perm, &bta_char_uuid, &attr_val, &control);
if (future_await(future_p) == FUTURE_FAIL) {
LOG_ERROR("%s failed\n", __func__);
return;
}
}
break;
}
default:
break;
}
}
param.add_attr_tab.status = ESP_GATT_OK;
param.add_attr_tab.num_handle = max_nb_attr;
param.add_attr_tab.handles = btc_creat_tab_env.handles;
memcpy(&param.add_attr_tab.svc_uuid, &btc_creat_tab_env.svc_uuid, sizeof(esp_bt_uuid_t));
btc_gatts_cb_to_app(ESP_GATTS_CREAT_ATTR_TAB_EVT, gatts_if, &param);
//reset the env after sent the data to app
memset(&btc_creat_tab_env, 0, sizeof(esp_btc_creat_tab_t));
//release the flag vaule to false after finish the service created.
btc_creat_tab_env.is_tab_creat_svc = false;
}
void btc_gatts_get_attr_value(uint16_t attr_handle, uint16_t *length, uint8_t **value)
{
BTA_GetAttributeValue(attr_handle, length, value);
}
static void btc_gatts_cb_param_copy_req(btc_msg_t *msg, void *p_dest, void *p_src)
{
@@ -131,7 +415,6 @@ static void btc_gatts_cb_param_copy_free(btc_msg_t *msg, tBTA_GATTS *p_data)
GKI_freebuf(p_data->req_data.p_data);
}
break;
default:
break;
}
@@ -142,11 +425,43 @@ static void btc_gatts_inter_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data)
{
bt_status_t status;
btc_msg_t msg;
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_GATTS;
msg.act = event;
if(btc_creat_tab_env.is_tab_creat_svc && btc_creat_tab_env.complete_future){
switch(event){
case BTA_GATTS_CREATE_EVT:{
//save the service handle to the btc module after used
//the attribute table method to creat a service
bta_to_btc_uuid(&btc_creat_tab_env.svc_uuid, &p_data->create.uuid);
uint8_t index = btc_creat_tab_env.handle_idx;
btc_creat_tab_env.svc_start_hdl = p_data->create.service_id;
btc_creat_tab_env.handles[index] = p_data->create.service_id;
break;
}
case BTA_GATTS_ADD_INCL_SRVC_EVT:{
uint8_t index = btc_creat_tab_env.handle_idx;
btc_creat_tab_env.handles[index] = p_data->add_result.attr_id;
break;
}
case BTA_GATTS_ADD_CHAR_EVT:{
uint8_t index = btc_creat_tab_env.handle_idx;
btc_creat_tab_env.handles[index] = p_data->add_result.attr_id - 1;
btc_creat_tab_env.handles[index+1] = p_data->add_result.attr_id;
break;
}
case BTA_GATTS_ADD_CHAR_DESCR_EVT:{
uint8_t index = btc_creat_tab_env.handle_idx;
btc_creat_tab_env.handles[index] = p_data->add_result.attr_id;
break;
}
default:
break;
}
future_ready(btc_creat_tab_env.complete_future, FUTURE_SUCCESS);
}
status = btc_transfer_context(&msg, p_data,
sizeof(tBTA_GATTS), btc_gatts_cb_param_copy_req);
@@ -171,16 +486,22 @@ void btc_gatts_call_handler(btc_msg_t *msg)
break;
}
case BTC_GATTS_ACT_APP_UNREGISTER:
BTA_GATTS_AppDeregister(arg->app_unreg.gatt_if);
BTA_GATTS_AppDeregister(arg->app_unreg.gatts_if);
break;
case BTC_GATTS_ACT_CREATE_SERVICE: {
tBTA_GATT_SRVC_ID srvc_id;
btc_to_bta_srvc_id(&srvc_id, &arg->create_srvc.service_id);
BTA_GATTS_CreateService(arg->create_srvc.gatt_if, &srvc_id.id.uuid,
BTA_GATTS_CreateService(arg->create_srvc.gatts_if, &srvc_id.id.uuid,
srvc_id.id.inst_id, arg->create_srvc.num_handle,
srvc_id.is_primary);
break;
}
case BTC_GATTS_ACT_CREATE_ATTR_TAB:
btc_gatts_act_create_attr_tab(arg->create_attr_tab.gatts_attr_db,
arg->create_attr_tab.gatts_if,
arg->create_attr_tab.max_nb_attr,
arg->create_attr_tab.srvc_inst_id);
break;
case BTC_GATTS_ACT_DELETE_SERVICE:
BTA_GATTS_DeleteService(arg->delete_srvc.service_handle);
break;
@@ -198,13 +519,17 @@ void btc_gatts_call_handler(btc_msg_t *msg)
btc_to_bta_uuid(&uuid, &arg->add_char.char_uuid);
BTA_GATTS_AddCharacteristic(arg->add_char.service_handle, &uuid,
arg->add_char.perm, arg->add_char.property);
arg->add_char.perm, arg->add_char.property,
(tGATT_ATTR_VAL *)&arg->add_char.char_val,
(tBTA_GATTS_ATTR_CONTROL *)&arg->add_char.attr_control);
break;
}
case BTC_GATTS_ACT_ADD_CHAR_DESCR: {
tBT_UUID uuid;
btc_to_bta_uuid(&uuid, &arg->add_descr.descr_uuid);
BTA_GATTS_AddCharDescriptor(arg->add_descr.service_handle, arg->add_descr.perm, &uuid);
BTA_GATTS_AddCharDescriptor(arg->add_descr.service_handle, arg->add_descr.perm, &uuid,
(tBTA_GATT_ATTR_VAL *)&arg->add_descr.descr_val,
(tBTA_GATTS_ATTR_CONTROL *)&arg->add_descr.attr_control);
break;
}
case BTC_GATTS_ACT_SEND_INDICATE:
@@ -227,13 +552,14 @@ void btc_gatts_call_handler(btc_msg_t *msg)
}
param.rsp.status = 0;
BTC_GATTS_CB_TO_APP(ESP_GATTS_RESPONSE_EVT, &param);
btc_gatts_cb_to_app(ESP_GATTS_RESPONSE_EVT, BTC_GATT_GET_GATT_IF(arg->send_rsp.conn_id), &param);
break;
}
case BTC_GATTS_ACT_SET_ATTR_VALUE:
break;
case BTC_GATTS_ACT_OPEN: {
// Ensure device is in inquiry database
int addr_type = 0;
int device_type = 0;
tBTA_GATT_TRANSPORT transport = BTA_GATT_TRANSPORT_LE;
//TODO : implement address type and device type
@@ -254,7 +580,7 @@ void btc_gatts_call_handler(btc_msg_t *msg)
transport = BTA_GATT_TRANSPORT_LE;
// Connect!
BTA_GATTS_Open(arg->open.gatt_if, arg->open.remote_bda,
BTA_GATTS_Open(arg->open.gatts_if, arg->open.remote_bda,
arg->open.is_direct, transport);
break;
}
@@ -279,34 +605,39 @@ void btc_gatts_call_handler(btc_msg_t *msg)
void btc_gatts_cb_handler(btc_msg_t *msg)
{
esp_ble_gatts_cb_param_t param;
tBTA_GATTS *p_data = (tBTA_GATTS *)msg->arg;
esp_gatt_if_t gatts_if;
switch (msg->act) {
case BTA_GATTS_REG_EVT: {
gatts_if = p_data->reg_oper.server_if;
param.reg.status = p_data->reg_oper.status;
param.reg.gatt_if = p_data->reg_oper.server_if;
param.reg.app_id = p_data->reg_oper.uuid.uu.uuid16;
BTC_GATTS_CB_TO_APP(ESP_GATTS_REG_EVT, &param);
btc_gatts_cb_to_app(ESP_GATTS_REG_EVT, gatts_if, &param);
break;
}
case BTA_GATTS_DEREG_EVT:
// do nothing
case BTA_GATTS_DEREG_EVT: {
gatts_if = p_data->reg_oper.server_if;
btc_gatts_cb_to_app(ESP_GATTS_UNREG_EVT, gatts_if, NULL);
break;
}
case BTA_GATTS_READ_EVT: {
param.read.conn_id = p_data->req_data.conn_id;
gatts_if = BTC_GATT_GET_GATT_IF(p_data->req_data.conn_id);
param.read.conn_id = BTC_GATT_GET_CONN_ID(p_data->req_data.conn_id);
param.read.trans_id = p_data->req_data.trans_id;
memcpy(param.read.bda, p_data->req_data.remote_bda, ESP_BD_ADDR_LEN);
param.read.handle = p_data->req_data.p_data->read_req.handle,
param.read.offset = p_data->req_data.p_data->read_req.offset,
param.read.is_long = p_data->req_data.p_data->read_req.is_long,
param.read.handle = p_data->req_data.p_data->read_req.handle;
param.read.offset = p_data->req_data.p_data->read_req.offset;
param.read.is_long = p_data->req_data.p_data->read_req.is_long;
BTC_GATTS_CB_TO_APP(ESP_GATTS_READ_EVT, &param);
param.read.need_rsp = p_data->req_data.p_data->read_req.need_rsp;
btc_gatts_cb_to_app(ESP_GATTS_READ_EVT, gatts_if, &param);
break;
}
case BTA_GATTS_WRITE_EVT: {
param.write.conn_id = p_data->req_data.conn_id;
gatts_if = BTC_GATT_GET_GATT_IF(p_data->req_data.conn_id);
param.write.conn_id = BTC_GATT_GET_CONN_ID(p_data->req_data.conn_id);
param.write.trans_id = p_data->req_data.trans_id;
memcpy(param.write.bda, p_data->req_data.remote_bda, ESP_BD_ADDR_LEN);
param.write.handle = p_data->req_data.p_data->write_req.handle;
@@ -316,116 +647,128 @@ void btc_gatts_cb_handler(btc_msg_t *msg)
param.write.len = p_data->req_data.p_data->write_req.len;
param.write.value = p_data->req_data.p_data->write_req.value;
BTC_GATTS_CB_TO_APP(ESP_GATTS_WRITE_EVT, &param);
btc_gatts_cb_to_app(ESP_GATTS_WRITE_EVT, gatts_if, &param);
break;
}
case BTA_GATTS_EXEC_WRITE_EVT: {
param.exec_write.conn_id = p_data->req_data.conn_id;
gatts_if = BTC_GATT_GET_GATT_IF(p_data->req_data.conn_id);
param.exec_write.conn_id = BTC_GATT_GET_CONN_ID(p_data->req_data.conn_id);
param.exec_write.trans_id = p_data->req_data.trans_id;
memcpy(param.exec_write.bda, p_data->req_data.remote_bda, ESP_BD_ADDR_LEN);
param.exec_write.exec_write_flag = p_data->req_data.p_data->exec_write;
BTC_GATTS_CB_TO_APP(ESP_GATTS_EXEC_WRITE_EVT, &param);
btc_gatts_cb_to_app(ESP_GATTS_EXEC_WRITE_EVT, gatts_if, &param);
break;
}
case BTA_GATTS_MTU_EVT:
param.mtu.conn_id = p_data->req_data.conn_id;
gatts_if = BTC_GATT_GET_GATT_IF(p_data->req_data.conn_id);
param.mtu.conn_id = BTC_GATT_GET_CONN_ID(p_data->req_data.conn_id);
param.mtu.mtu = p_data->req_data.p_data->mtu;
BTC_GATTS_CB_TO_APP(ESP_GATTS_MTU_EVT, &param);
btc_gatts_cb_to_app(ESP_GATTS_MTU_EVT, gatts_if, &param);
break;
case BTA_GATTS_CONF_EVT:
param.conf.conn_id = p_data->req_data.conn_id;
gatts_if = BTC_GATT_GET_GATT_IF(p_data->req_data.conn_id);
param.conf.conn_id = BTC_GATT_GET_CONN_ID(p_data->req_data.conn_id);
param.conf.status = p_data->req_data.status;
BTC_GATTS_CB_TO_APP(ESP_GATTS_CONF_EVT, &param);
btc_gatts_cb_to_app(ESP_GATTS_CONF_EVT, gatts_if, &param);
break;
case BTA_GATTS_CREATE_EVT:
gatts_if = p_data->create.server_if;
param.create.status = p_data->create.status;
param.create.gatt_if = p_data->create.server_if;
param.create.service_handle = p_data->create.service_id;
param.create.service_id.is_primary = p_data->create.is_primary;
param.create.service_id.id.inst_id = p_data->create.svc_instance;
bta_to_btc_uuid(&param.create.service_id.id.uuid, &p_data->create.uuid);
BTC_GATTS_CB_TO_APP(ESP_GATTS_CREATE_EVT, &param);
btc_gatts_cb_to_app(ESP_GATTS_CREATE_EVT, gatts_if, &param);
break;
case BTA_GATTS_ADD_INCL_SRVC_EVT:
gatts_if = p_data->add_result.server_if;
param.add_incl_srvc.status = p_data->add_result.status;
param.add_incl_srvc.gatt_if = p_data->add_result.server_if;
param.add_incl_srvc.attr_handle = p_data->add_result.attr_id;
param.add_incl_srvc.service_handle = p_data->add_result.service_id;
BTC_GATTS_CB_TO_APP(ESP_GATTS_ADD_INCL_SRVC_EVT, &param);
btc_gatts_cb_to_app(ESP_GATTS_ADD_INCL_SRVC_EVT, gatts_if, &param);
break;
case BTA_GATTS_ADD_CHAR_EVT:
gatts_if = p_data->add_result.server_if;
param.add_char.status = p_data->add_result.status;
param.add_char.gatt_if = p_data->add_result.server_if;
param.add_char.attr_handle = p_data->add_result.attr_id;
param.add_char.service_handle = p_data->add_result.service_id;
bta_to_btc_uuid(&param.add_char.char_uuid, &p_data->add_result.char_uuid);
BTC_GATTS_CB_TO_APP(ESP_GATTS_ADD_CHAR_EVT, &param);
btc_gatts_cb_to_app(ESP_GATTS_ADD_CHAR_EVT, gatts_if, &param);
break;
case BTA_GATTS_ADD_CHAR_DESCR_EVT:
gatts_if = p_data->add_result.server_if;
param.add_char_descr.status = p_data->add_result.status;
param.add_char_descr.gatt_if = p_data->add_result.server_if;
param.add_char_descr.attr_handle = p_data->add_result.attr_id;
param.add_char_descr.service_handle = p_data->add_result.service_id;
bta_to_btc_uuid(&param.add_char_descr.char_uuid, &p_data->add_result.char_uuid);
BTC_GATTS_CB_TO_APP(ESP_GATTS_ADD_CHAR_DESCR_EVT, &param);
btc_gatts_cb_to_app(ESP_GATTS_ADD_CHAR_DESCR_EVT, gatts_if, &param);
break;
case BTA_GATTS_DELELTE_EVT:
gatts_if = p_data->srvc_oper.server_if;
param.del.status = p_data->srvc_oper.status;
param.del.gatt_if = p_data->srvc_oper.server_if;
param.del.service_handle = p_data->srvc_oper.service_id;
BTC_GATTS_CB_TO_APP(ESP_GATTS_DELETE_EVT, &param);
btc_gatts_cb_to_app(ESP_GATTS_DELETE_EVT, gatts_if, &param);
break;
case BTA_GATTS_START_EVT:
gatts_if = p_data->srvc_oper.server_if;
param.start.status = p_data->srvc_oper.status;
param.start.gatt_if = p_data->srvc_oper.server_if;
param.start.service_handle = p_data->srvc_oper.service_id;
BTC_GATTS_CB_TO_APP(ESP_GATTS_START_EVT, &param);
btc_gatts_cb_to_app(ESP_GATTS_START_EVT, gatts_if, &param);
break;
case BTA_GATTS_STOP_EVT:
gatts_if = p_data->srvc_oper.server_if;
param.stop.status = p_data->srvc_oper.status;
param.stop.gatt_if = p_data->srvc_oper.server_if;
param.stop.service_handle = p_data->srvc_oper.service_id;
BTC_GATTS_CB_TO_APP(ESP_GATTS_STOP_EVT, &param);
btc_gatts_cb_to_app(ESP_GATTS_STOP_EVT, gatts_if, &param);
break;
case BTA_GATTS_CONNECT_EVT:
param.connect.conn_id = p_data->conn.conn_id;
param.connect.gatt_if = p_data->conn.server_if;
gatts_if = p_data->conn.server_if;
param.connect.conn_id = BTC_GATT_GET_CONN_ID(p_data->conn.conn_id);
param.connect.is_connected = true;
memcpy(param.connect.remote_bda, p_data->conn.remote_bda, ESP_BD_ADDR_LEN);
BTC_GATTS_CB_TO_APP(ESP_GATTS_CONNECT_EVT, &param);
btc_gatts_cb_to_app(ESP_GATTS_CONNECT_EVT, gatts_if, &param);
break;
case BTA_GATTS_DISCONNECT_EVT:
param.connect.conn_id = p_data->conn.conn_id;
param.connect.gatt_if = p_data->conn.server_if;
param.connect.is_connected = false;
memcpy(param.connect.remote_bda, p_data->conn.remote_bda, ESP_BD_ADDR_LEN);
gatts_if = p_data->conn.server_if;
param.disconnect.conn_id = BTC_GATT_GET_CONN_ID(p_data->conn.conn_id);
param.disconnect.is_connected = false;
memcpy(param.disconnect.remote_bda, p_data->conn.remote_bda, ESP_BD_ADDR_LEN);
BTC_GATTS_CB_TO_APP(ESP_GATTS_DISCONNECT_EVT, &param);
btc_gatts_cb_to_app(ESP_GATTS_DISCONNECT_EVT, gatts_if, &param);
break;
case BTA_GATTS_OPEN_EVT:
// do nothing
// do nothing
case BTA_GATTS_CANCEL_OPEN_EVT:
// do nothing
// do nothing
case BTA_GATTS_CLOSE_EVT:
// do nothing
// do nothing
case BTA_GATTS_LISTEN_EVT:
// do nothing
break;
case BTA_GATTS_CONGEST_EVT:
param.congest.conn_id = p_data->congest.conn_id;
gatts_if = BTC_GATT_GET_GATT_IF(p_data->congest.conn_id);
param.congest.conn_id = BTC_GATT_GET_CONN_ID(p_data->congest.conn_id);
param.congest.congested = p_data->congest.congested;
btc_gatts_cb_to_app(ESP_GATTS_CONGEST_EVT, gatts_if, &param);
break;
case BTA_GATTS_SET_ATTR_VAL_EVT:
gatts_if = p_data->attr_val.server_if;
param.set_attr_val.srvc_handle = p_data->attr_val.service_id;
param.set_attr_val.attr_handle = p_data->attr_val.attr_id;
param.set_attr_val.status = p_data->attr_val.status;
btc_gatts_cb_to_app(ESP_GATTS_SET_ATTR_VAL_EVT, gatts_if, &param);
break;
default:
// do nothing

View File

@@ -32,6 +32,8 @@ typedef enum {
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 */
@@ -76,6 +78,16 @@ typedef union {
#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);

View File

@@ -21,7 +21,11 @@
#include "esp_gatt_defs.h"
#include "esp_gattc_api.h"
int btc128_to_bta_uuid(tBT_UUID *p_dest, uint8_t *p_src);
#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);
@@ -31,6 +35,6 @@ 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(esp_ble_gattc_cb_param_t *p_dest, tBTA_GATTC_READ *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__*/

View File

@@ -51,11 +51,11 @@ typedef union {
} app_reg;
//BTC_GATTC_ACT_APP_UNREGISTER,
struct app_unreg_arg {
esp_gatt_if_t gatt_if;
esp_gatt_if_t gattc_if;
} app_unreg;
//BTC_GATTC_ACT_OPEN,
struct open_arg {
esp_gatt_if_t gatt_if;
esp_gatt_if_t gattc_if;
esp_bd_addr_t remote_bda;
bool is_direct;
} open;
@@ -162,14 +162,14 @@ typedef union {
} exec_write;
//BTC_GATTC_ACT_REG_FOR_NOTIFY,
struct reg_for_notify_arg {
esp_gatt_if_t gatt_if;
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 gatt_if;
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;

View File

@@ -24,6 +24,7 @@ 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,
@@ -32,6 +33,7 @@ typedef enum {
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;
@@ -42,46 +44,67 @@ typedef union {
struct app_reg_args {
uint16_t app_id;
} app_reg;
//BTC_GATTS_ACT_APP_UNREGISTER,
struct app_unreg_args {
esp_gatt_if_t gatt_if;
esp_gatt_if_t gatts_if;
} app_unreg;
//BTC_GATTS_ACT_CREATE_SERVICE,
struct create_srvc_args {
esp_gatt_if_t gatt_if;
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;
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;
@@ -90,6 +113,7 @@ typedef union {
uint16_t value_len;
uint8_t *value;
} send_ind;
//BTC_GATTS_ACT_SEND_RESPONSE,
struct send_rsp_args {
uint16_t conn_id;
@@ -97,21 +121,32 @@ typedef union {
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 gatt_if;
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__ */

View File

@@ -221,6 +221,10 @@ static void start_up(void)
}
if (HCI_LE_DATA_LEN_EXT_SUPPORTED(features_ble.as_array)) {
/* set default tx data length to MAX 251 */
response = AWAIT_COMMAND(packet_factory->make_ble_write_suggested_default_data_length(BTM_BLE_DATA_SIZE_MAX, BTM_BLE_DATA_TX_TIME_MAX));
packet_parser->parse_generic_command_complete(response);
response = AWAIT_COMMAND(packet_factory->make_ble_read_suggested_default_data_length());
packet_parser->parse_ble_read_suggested_default_data_length_response(
response,

View File

@@ -30,21 +30,21 @@ typedef struct {
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},
{{{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},
{{{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},
{{{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}
{{{0x9c, 0xdf, 0x03, 0, 0, 0}}, 3, INTEROP_AUTO_RETRY_PAIRING}
};
#endif /*_INTEROP_DATABASE_H_*/

View File

@@ -20,15 +20,6 @@
#include "allocator.h"
#include "gki_int.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
/*******************************************************************************
**
** Function gki_init_free_queue
@@ -173,7 +164,7 @@ void GKI_init_q (BUFFER_Q *p_q)
/*******************************************************************************
**
** Function GKI_getbuf
** Function GKI_getbuf_func
**
** Description Called by an application to get a free buffer which
** is of size greater or equal to the requested size.
@@ -187,7 +178,7 @@ void GKI_init_q (BUFFER_Q *p_q)
** Returns A pointer to the buffer, or NULL if none available
**
*******************************************************************************/
void *GKI_getbuf (UINT16 size)
void *GKI_getbuf_func(UINT16 size)
{
BUFFER_HDR_T *header = osi_malloc(size + BUFFER_HDR_SIZE);
header->status = BUF_STATUS_UNLINKED;
@@ -198,10 +189,9 @@ void *GKI_getbuf (UINT16 size)
return header + 1;
}
/*******************************************************************************
**
** Function GKI_getpoolbuf
** Function GKI_getpoolbuf_func
**
** Description Called by an application to get a free buffer from
** a specific buffer pool.
@@ -214,9 +204,9 @@ void *GKI_getbuf (UINT16 size)
** Returns A pointer to the buffer, or NULL if none available
**
*******************************************************************************/
void *GKI_getpoolbuf (UINT8 pool_id)
void *GKI_getpoolbuf_func(UINT8 pool_id)
{
return GKI_getbuf(gki_cb.com.pool_size[pool_id]);
return GKI_getbuf_func(gki_cb.com.pool_size[pool_id]);
}
/*******************************************************************************
@@ -235,7 +225,6 @@ void GKI_freebuf (void *p_buf)
osi_free((BUFFER_HDR_T *)p_buf - 1);
}
/*******************************************************************************
**
** Function GKI_get_buf_size

View File

@@ -21,8 +21,18 @@
#include "bt_target.h"
#include "bt_types.h"
#include "gki_common.h"
#include "gki_int.h"
#include "allocator.h"
//static const char GKI_MODULE[] = "gki_module";
#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
*/
@@ -62,14 +72,37 @@ typedef struct {
/* To get and release buffers, change owner and get size
*/
void GKI_freebuf (void *);
void *GKI_getbuf (UINT16);
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
*/

View File

@@ -57,7 +57,7 @@ typedef struct {
static hci_hal_env_t hci_hal_env;
static const hci_hal_t interface;
static const hci_hal_callbacks_t *callbacks;
static const vhci_host_callback_t vhci_host_cb;
static const esp_vhci_host_callback_t vhci_host_cb;
static xTaskHandle xHciH4TaskHandle;
static xQueueHandle xHciH4Queue;
@@ -102,10 +102,10 @@ static bool hal_open(const hci_hal_callbacks_t *upper_callbacks)
hci_hal_env_init(HCI_HAL_SERIAL_BUFFER_SIZE, SIZE_MAX);
xHciH4Queue = xQueueCreate(HCI_H4_QUEUE_NUM, sizeof(BtTaskEvt_t));
xTaskCreate(hci_hal_h4_rx_handler, HCI_H4_TASK_NAME, HCI_H4_TASK_STACK_SIZE, NULL, HCI_H4_TASK_PRIO, &xHciH4TaskHandle);
xTaskCreatePinnedToCore(hci_hal_h4_rx_handler, HCI_H4_TASK_NAME, HCI_H4_TASK_STACK_SIZE, NULL, HCI_H4_TASK_PRIO, &xHciH4TaskHandle, 0);
//register vhci host cb
API_vhci_host_register_callback(&vhci_host_cb);
esp_vhci_host_register_callback(&vhci_host_cb);
return true;
@@ -148,7 +148,7 @@ static uint16_t transmit_data(serial_data_type_t type,
BTTRC_DUMP_BUFFER("Transmit Pkt", data, length);
// TX Data to target
API_vhci_host_send_packet(data, length);
esp_vhci_host_send_packet(data, length);
// Be nice and restore the old value of that byte
*(data) = previous_byte;
@@ -177,7 +177,7 @@ void hci_hal_h4_task_post(void)
evt.sig = 0xff;
evt.par = 0;
if (xQueueSend(xHciH4Queue, &evt, 10 / portTICK_RATE_MS) != pdTRUE) {
if (xQueueSend(xHciH4Queue, &evt, 10 / portTICK_PERIOD_MS) != pdTRUE) {
LOG_ERROR("xHciH4Queue failed\n");
}
}
@@ -278,7 +278,7 @@ static int host_recv_pkt_cb(uint8_t *data, uint16_t len)
return 0;
}
static const vhci_host_callback_t vhci_host_cb = {
static const esp_vhci_host_callback_t vhci_host_cb = {
.notify_host_send_available = host_send_pkt_available_cb,
.notify_host_recv = host_recv_pkt_cb,
};

View File

@@ -89,11 +89,6 @@ static const packet_fragmenter_callbacks_t packet_fragmenter_callbacks;
static int hci_layer_init_env(void);
static void hci_layer_deinit_env(void);
static void hci_host_thread_handler(void *arg);
static int hci_send_async_command(bt_vendor_opcode_t opcode, void *param);
static void event_finish_startup(void *context);
static void firmware_config_callback(bool success);
static void event_postload(void);
static void sco_config_callback(bool success);
static void event_command_ready(fixed_queue_t *queue);
static void event_packet_ready(fixed_queue_t *queue);
static void restart_comamnd_waiting_response_timer(
@@ -114,7 +109,7 @@ int hci_start_up(void)
}
xHciHostQueue = xQueueCreate(HCI_HOST_QUEUE_NUM, sizeof(BtTaskEvt_t));
xTaskCreate(hci_host_thread_handler, HCI_HOST_TASK_NAME, HCI_HOST_TASK_STACK_SIZE, NULL, HCI_HOST_TASK_PRIO, &xHciHostTaskHandle);
xTaskCreatePinnedToCore(hci_host_thread_handler, HCI_HOST_TASK_NAME, HCI_HOST_TASK_STACK_SIZE, NULL, HCI_HOST_TASK_PRIO, &xHciHostTaskHandle, 0);
packet_fragmenter->init(&packet_fragmenter_callbacks);
hal->open(&hal_callbacks);
@@ -151,7 +146,7 @@ void hci_host_task_post(void)
evt.sig = 0xff;
evt.par = 0;
if (xQueueSend(xHciHostQueue, &evt, 10 / portTICK_RATE_MS) != pdTRUE) {
if (xQueueSend(xHciHostQueue, &evt, 10 / portTICK_PERIOD_MS) != pdTRUE) {
LOG_ERROR("xHciHostQueue failed\n");
}
}
@@ -203,7 +198,7 @@ static void hci_layer_deinit_env(void)
command_waiting_response_t *cmd_wait_q;
if (hci_host_env.command_queue) {
fixed_queue_free(hci_host_env.command_queue, osi_free);
fixed_queue_free(hci_host_env.command_queue, allocator_calloc.free);
}
if (hci_host_env.packet_queue) {
fixed_queue_free(hci_host_env.packet_queue, buffer_allocator->free);
@@ -233,7 +228,7 @@ static void hci_host_thread_handler(void *arg)
if (pdTRUE == xQueueReceive(xHciHostQueue, &e, (portTickType)portMAX_DELAY)) {
if (e.sig == 0xff) {
if (API_vhci_host_check_send_available()) {
if (esp_vhci_host_check_send_available()) {
/*Now Target only allowed one packet per TX*/
BT_HDR *pkt = packet_fragmenter->fragment_current_packet();
if (pkt != NULL) {
@@ -320,24 +315,8 @@ static void transmit_downward(uint16_t type, void *data)
hci_host_task_post();
}
// Postload functions
static void event_postload(void)
{
if (hci_send_async_command(BT_VND_OP_SCO_CFG, NULL) == -1) {
// If couldn't configure sco, we won't get the sco configuration callback
// so go pretend to do it now
sco_config_callback(false);
}
}
static void sco_config_callback(UNUSED_ATTR bool success)
{
LOG_INFO("%s postload finished.", __func__);
}
// Command/packet transmitting functions
static void event_command_ready(fixed_queue_t *queue)
{
waiting_command_t *wait_entry = NULL;
@@ -426,8 +405,8 @@ static void restart_comamnd_waiting_response_timer(
timeout = osi_alarm_time_diff(COMMAND_PENDING_TIMEOUT, timeout);
timeout = (timeout <= COMMAND_PENDING_TIMEOUT) ? timeout : COMMAND_PENDING_TIMEOUT;
osi_alarm_set(cmd_wait_q->command_response_timer, timeout);
cmd_wait_q->timer_is_set = true;
osi_alarm_set(cmd_wait_q->command_response_timer, timeout);
}
static void command_timed_out(void *context)
@@ -509,6 +488,8 @@ static bool filter_incoming_event(BT_HDR *packet)
return false;
intercepted:
restart_comamnd_waiting_response_timer(&hci_host_env.cmd_waiting_q, false);
/*Tell HCI Host Task to continue TX Pending commands*/
if (hci_host_env.command_credits &&
!fixed_queue_is_empty(hci_host_env.command_queue)) {
@@ -516,8 +497,6 @@ intercepted:
}
//ke_event_set(KE_EVENT_HCI_HOST_THREAD);
restart_comamnd_waiting_response_timer(&hci_host_env.cmd_waiting_q, false);
if (wait_entry) {
// If it has a callback, it's responsible for freeing the packet
if (event_code == HCI_COMMAND_STATUS_EVT ||
@@ -594,10 +573,6 @@ static waiting_command_t *get_waiting_command(command_opcode_t opcode)
return NULL;
}
static int hci_send_async_command(bt_vendor_opcode_t opcode, void *param)
{
}
static void init_layer_interface()
{
if (!interface_created) {

View File

@@ -154,6 +154,17 @@ static BT_HDR *make_ble_read_suggested_default_data_length(void)
return make_command_no_params(HCI_BLE_READ_DEFAULT_DATA_LENGTH);
}
static BT_HDR *make_ble_write_suggested_default_data_length(uint16_t SuggestedMaxTxOctets, uint16_t SuggestedMaxTxTime)
{
uint8_t *stream;
uint8_t parameter_size = sizeof(uint16_t) + sizeof(uint16_t);
BT_HDR *packet = make_command(HCI_BLE_WRITE_DEFAULT_DATA_LENGTH, parameter_size, &stream);
UINT16_TO_STREAM(stream, SuggestedMaxTxOctets);
UINT16_TO_STREAM(stream, SuggestedMaxTxTime);
return packet;
}
static BT_HDR *make_ble_set_event_mask(const bt_event_mask_t *event_mask)
{
uint8_t *stream;
@@ -215,6 +226,7 @@ static const hci_packet_factory_t interface = {
make_ble_read_local_supported_features,
make_ble_read_resolving_list_size,
make_ble_read_suggested_default_data_length,
make_ble_write_suggested_default_data_length,
make_ble_set_event_mask
};

View File

@@ -40,6 +40,7 @@ typedef struct {
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_write_suggested_default_data_length)(uint16_t SuggestedMaxTxOctets, uint16_t SuggestedMaxTxTime);
BT_HDR *(*make_ble_set_event_mask)(const bt_event_mask_t *event_mask);
} hci_packet_factory_t;

View File

@@ -147,16 +147,13 @@ static void reassemble_and_dispatch(BT_HDR *packet)
if (boundary_flag == START_PACKET_BOUNDARY) {
if (partial_packet) {
LOG_ERROR("%s found unfinished packet for handle with start packet. Dropping old.\n", __func__);
LOG_ERROR("partial_packet->len = %x, offset = %x\n", partial_packet->len, partial_packet->len);
LOG_DEBUG("%s found unfinished packet for handle with start packet. Dropping old.\n", __func__);
LOG_DEBUG("partial_packet->len = %x, offset = %x\n", partial_packet->len, partial_packet->len);
for (int i = 0; i < partial_packet->len; i++) {
LOG_ERROR("%x", partial_packet->data[i]);
}
LOG_ERROR("\n");
hash_map_erase(partial_packets, (void *)(uintptr_t)handle);
//buffer_allocator->free(partial_packet);
LOG_ERROR("+++++++++++++++++++\n");
}
uint16_t full_length = l2cap_length + L2CAP_HEADER_SIZE + HCI_ACL_PREAMBLE_SIZE;
@@ -214,7 +211,7 @@ static void reassemble_and_dispatch(BT_HDR *packet)
STREAM_TO_UINT16(handle, stream);
STREAM_TO_UINT16(acl_length, stream);
STREAM_TO_UINT16(l2cap_length, stream);
LOG_ERROR("partial_packet->offset = %x\n", partial_packet->offset);
LOG_DEBUG("partial_packet->offset = %x\n", partial_packet->offset);
hash_map_erase(partial_packets, (void *)(uintptr_t)handle);
partial_packet->offset = 0;

View File

@@ -32,7 +32,7 @@
#define assert(x) do { if (!(x)) BT_PRINTF("bt host error %s %u\n", __FILE__, __LINE__); } while (0)
#endif
inline void trc_dump_buffer(uint8_t *prefix, uint8_t *data, uint16_t len)
inline void trc_dump_buffer(const char *prefix, uint8_t *data, uint16_t len)
{
uint16_t i;
@@ -41,14 +41,13 @@ inline void trc_dump_buffer(uint8_t *prefix, uint8_t *data, uint16_t len)
}
if (prefix) {
BT_PRINTF("%s:\t", prefix);
BT_PRINTF("%s: len %d\n", prefix, len);
}
for (i = 0; i < len; i++) {
BT_PRINTF(" %02x", *(data + i));
if (!((i + 1) & 0xf)) {
BT_PRINTF("\n");
}
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");
}

View File

@@ -37,6 +37,7 @@
#include "hash_functions.h"
#include "controller.h"
#include "hci_layer.h"
#include "bta_api.h"
//#include "bluedroid_test.h"
/*
@@ -104,6 +105,7 @@ fixed_queue_t *btu_hci_msg_queue;
bluedroid_init_done_cb_t bluedroid_init_done_cb;
extern void osi_mem_dbg_init(void);
/******************************************************************************
**
** Function bte_main_boot_entry
@@ -115,6 +117,10 @@ bluedroid_init_done_cb_t bluedroid_init_done_cb;
******************************************************************************/
int bte_main_boot_entry(bluedroid_init_done_cb_t cb)
{
#ifdef CONFIG_BLUEDROID_MEM_DEBUG
osi_mem_dbg_init();
#endif
if (gki_init()) {
LOG_ERROR("%s: Init GKI Module Failure.\n", __func__);
return -1;
@@ -163,6 +169,7 @@ void bte_main_shutdown(void)
{
//data_dispatcher_register_default(hci_layer_get_interface()->event_dispatcher, NULL);
hci->set_data_queue(NULL);
fixed_queue_unregister_dequeue(btu_hci_msg_queue);
fixed_queue_free(btu_hci_msg_queue, NULL);
btu_hci_msg_queue = NULL;
@@ -174,9 +181,11 @@ void bte_main_shutdown(void)
module_clean_up(get_module(GKI_MODULE));
*/
gki_clean_up();
#if (BLE_INCLUDED == TRUE)
BTA_VendorCleanup();
#endif
bte_main_disable();
gki_clean_up();
}
/******************************************************************************

View File

@@ -28,7 +28,7 @@
#include "freertos/xtensa_api.h"
#include "rom/ets_sys.h"
#define RTC_TIMER_TICKS_TO_MS(ticks) ((ticks/625)<<1 + (ticks-(ticks/625)*625)/312)
#define RTC_TIMER_TICKS_TO_MS(ticks) (((ticks/625)<<1) + (ticks-(ticks/625)*625)/312)
#define BT_ALARM_START_WAIT_TICKS 100
@@ -49,7 +49,7 @@ static struct alarm_t *alarm_cbs_lookfor_available(void)
for (i = 0; i < ALARM_CBS_NUM; i++) {
if (alarm_cbs[i].alarm_hdl == NULL) { //available
LOG_DEBUG(">>>> %d %08x<<<<\n", i, &alarm_cbs[i]);
LOG_DEBUG("%s %d %p\n", __func__, i, &alarm_cbs[i]);
return &alarm_cbs[i];
}
}
@@ -62,12 +62,12 @@ static void alarm_cb_handler(TimerHandle_t xTimer)
struct alarm_t *alarm;
if (!xTimer) {
LOG_DEBUG("TimerName: NULL\n");
LOG_ERROR("TimerName: NULL\n");
return;
}
alarm = pvTimerGetTimerID(xTimer);
LOG_DEBUG("TimerID %08x, Name %s\n", alarm, pcTimerGetTimerName(xTimer));
LOG_DEBUG("TimerID %p, Name %s\n", alarm, pcTimerGetTimerName(xTimer));
if (alarm->cb) {
alarm->cb(alarm->cb_data);
}

View File

@@ -24,6 +24,97 @@
extern void *pvPortZalloc(size_t size);
extern void vPortFree(void *pv);
#ifdef CONFIG_BLUEDROID_MEM_DEBUG
#define OSI_MEM_DBG_INFO_MAX 1024
typedef struct {
void *p;
int size;
const char *func;
int line;
} osi_mem_dbg_info_t;
static uint32_t mem_dbg_count = 0;
static uint32_t mem_dbg_count2 = 0;
static osi_mem_dbg_info_t mem_dbg_info[OSI_MEM_DBG_INFO_MAX];
void osi_mem_dbg_init(void)
{
int i;
for (i = 0; i < OSI_MEM_DBG_INFO_MAX; i++) {
mem_dbg_info[i].p = NULL;
mem_dbg_info[i].size = 0;
mem_dbg_info[i].func = NULL;
mem_dbg_info[i].line = 0;
}
mem_dbg_count = 0;
mem_dbg_count2 = 0;
}
void osi_mem_dbg_record(void *p, int size, const char *func, int line)
{
int i;
if (!p || size == 0) {
LOG_ERROR("%s invalid !!\n", __func__);
return;
}
for (i = 0; i < OSI_MEM_DBG_INFO_MAX; i++) {
if (mem_dbg_info[i].p == NULL) {
mem_dbg_info[i].p = p;
mem_dbg_info[i].size = size;
mem_dbg_info[i].func = func;
mem_dbg_info[i].line = line;
mem_dbg_count++;
break;
}
}
if (i >= OSI_MEM_DBG_INFO_MAX) {
LOG_ERROR("%s full %s %d !!\n", __func__, func, line);
}
}
void osi_mem_dbg_clean(void *p, const char *func, int line)
{
int i;
if (!p) {
LOG_ERROR("%s invalid\n", __func__);
return;
}
for (i = 0; i < OSI_MEM_DBG_INFO_MAX; i++) {
if (mem_dbg_info[i].p == p) {
mem_dbg_info[i].p = NULL;
mem_dbg_info[i].size = 0;
mem_dbg_info[i].func = NULL;
mem_dbg_info[i].line = 0;
mem_dbg_count--;
break;
}
}
if (i >= OSI_MEM_DBG_INFO_MAX) {
LOG_ERROR("%s full %s %d !!\n", __func__, func, line);
}
}
void osi_mem_dbg_show(void)
{
int i;
for (i = 0; i < OSI_MEM_DBG_INFO_MAX; i++) {
if (mem_dbg_info[i].p || mem_dbg_info[i].size != 0 ) {
LOG_ERROR("--> p %p, s %d, f %s, l %d\n", mem_dbg_info[i].p, mem_dbg_info[i].size, mem_dbg_info[i].func, mem_dbg_info[i].line);
}
}
LOG_ERROR("--> count %d\n", mem_dbg_count);
}
#endif
char *osi_strdup(const char *str)
{
size_t size = strlen(str) + 1; // + 1 for the null terminator
@@ -37,27 +128,46 @@ char *osi_strdup(const char *str)
return new_string;
}
void *osi_malloc(size_t size)
void *osi_malloc_func(size_t size)
{
#ifdef CONFIG_BLUEDROID_MEM_DEBUG
void *p;
p = calloc(1, size);
osi_mem_dbg_record(p, size, __func__, __LINE__);
return p;
#else
return calloc(1, size);
#endif
}
void *osi_calloc(size_t size)
void *osi_calloc_func(size_t size)
{
#ifdef CONFIG_BLUEDROID_MEM_DEBUG
void *p;
p = calloc(1, size);
osi_mem_dbg_record(p, size, __func__, __LINE__);
return p;
#else
return calloc(1, size);
#endif
}
void osi_free(void *ptr)
void osi_free_func(void *ptr)
{
#ifdef CONFIG_BLUEDROID_MEM_DEBUG
osi_mem_dbg_clean(ptr, __func__, __LINE__);
#endif
free(ptr);
}
const allocator_t allocator_malloc = {
osi_malloc,
osi_free
osi_malloc_func,
osi_free_func
};
const allocator_t allocator_calloc = {
osi_calloc,
osi_free
osi_calloc_func,
osi_free_func
};

View File

@@ -16,22 +16,13 @@
*
******************************************************************************/
// #define LOG_TAG "bt_osi_future"
// #include <assert.h>
#include "bt_trace.h"
#include "allocator.h"
#include "future.h"
#include "osi.h"
//#include "osi/include/log.h"
#include "osi_arch.h"
struct future_t {
bool ready_can_be_called;
osi_sem_t semaphore; // NULL semaphore means immediate future
void *result;
};
static void future_free(future_t *future);
future_t *future_new(void)
@@ -100,7 +91,7 @@ static void future_free(future_t *future)
return;
}
if (!future->semaphore) {
if (future->semaphore) {
osi_sem_free(&future->semaphore);
}

View File

@@ -36,8 +36,47 @@ extern const allocator_t allocator_calloc;
char *osi_strdup(const char *str);
void *osi_malloc(size_t size);
void *osi_calloc(size_t size);
void osi_free(void *ptr);
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_ */

View File

@@ -20,7 +20,14 @@
#define __FUTURE_H__
// #pragma once
typedef struct future_t future_t;
#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)

View File

@@ -43,25 +43,27 @@ enum {
SIG_BTIF_WORK = 0xff
};
#define HCI_HOST_TASK_STACK_SIZE 1024
#define HCI_HOST_TASK_PRIO (configMAX_PRIORITIES - 3)
#define HCI_HOST_TASK_NAME "hciHostT"
#define HCI_HOST_QUEUE_NUM 30
#define HCI_H4_TASK_STACK_SIZE 1024
#define HCI_H4_TASK_PRIO (configMAX_PRIORITIES - 3)
#define HCI_H4_TASK_NAME "hciH4T"
#define HCI_H4_QUEUE_NUM 30
#define BT_TASK_EXTRA_STACK_SIZE 512
#define HCI_HOST_TASK_STACK_SIZE (2048 + BT_TASK_EXTRA_STACK_SIZE)
#define HCI_HOST_TASK_PRIO (configMAX_PRIORITIES - 2)
#define HCI_HOST_TASK_NAME "hciHostT"
#define HCI_HOST_QUEUE_NUM 40
#define BTU_TASK_STACK_SIZE 4096
#define BTU_TASK_PRIO (configMAX_PRIORITIES - 1)
#define BTU_TASK_NAME "btuT"
#define BTU_QUEUE_NUM 50
#define HCI_H4_TASK_STACK_SIZE (2048 + BT_TASK_EXTRA_STACK_SIZE)
#define HCI_H4_TASK_PRIO (configMAX_PRIORITIES - 3)
#define HCI_H4_TASK_NAME "hciH4T"
#define HCI_H4_QUEUE_NUM 60
#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
#define BTU_TASK_STACK_SIZE (3584 + BT_TASK_EXTRA_STACK_SIZE)
#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 + BT_TASK_EXTRA_STACK_SIZE) //by menuconfig
#define BTC_TASK_NAME "btcT"
#define BTC_TASK_PRIO (configMAX_PRIORITIES - 5)
#define BTC_TASK_QUEUE_NUM 60
void btu_task_post(uint32_t sig);
void hci_host_task_post(void);

View File

@@ -137,9 +137,9 @@ osi_sem_wait(osi_sem_t *sem, uint32_t timeout)
StartTime = xTaskGetTickCount();
if (timeout != 0) {
if (xSemaphoreTake(*sem, timeout / portTICK_RATE_MS) == pdTRUE) {
if (xSemaphoreTake(*sem, timeout / portTICK_PERIOD_MS) == pdTRUE) {
EndTime = xTaskGetTickCount();
Elapsed = (EndTime - StartTime) * portTICK_RATE_MS;
Elapsed = (EndTime - StartTime) * portTICK_PERIOD_MS;
if (Elapsed == 0) {
Elapsed = 1;
@@ -153,7 +153,7 @@ osi_sem_wait(osi_sem_t *sem, uint32_t timeout)
while (xSemaphoreTake(*sem, portMAX_DELAY) != pdTRUE);
EndTime = xTaskGetTickCount();
Elapsed = (EndTime - StartTime) * portTICK_RATE_MS;
Elapsed = (EndTime - StartTime) * portTICK_PERIOD_MS;
if (Elapsed == 0) {
Elapsed = 1;
@@ -190,7 +190,7 @@ osi_now(void)
void osi_delay_ms(uint32_t ms)
{
vTaskDelay(ms / portTICK_RATE_MS);
vTaskDelay(ms / portTICK_PERIOD_MS);
}

View File

@@ -651,7 +651,6 @@ void BTM_ReadDevInfo (BD_ADDR remote_bda, tBT_DEVICE_TYPE *p_dev_type, tBLE_ADDR
BOOLEAN BTM_ReadConnectedTransportAddress(BD_ADDR remote_bda, tBT_TRANSPORT transport)
{
tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev(remote_bda);
tACL_CONN *p = btm_bda_to_acl(remote_bda, transport);
/* if no device can be located, return */
if (p_dev_rec == NULL) {
@@ -1392,58 +1391,6 @@ void btm_ble_link_encrypted(BD_ADDR bd_addr, UINT8 encr_enable)
gatt_notify_enc_cmpl(p_dev_rec->ble.pseudo_addr);
}
/*******************************************************************************
** Function btm_enc_proc_ltk
** Description send LTK reply when it's ready.
*******************************************************************************/
static void btm_enc_proc_ltk(tSMP_ENC *p)
{
UINT8 i;
BTM_TRACE_DEBUG ("btm_enc_proc_ltk");
if (p && p->param_len == BT_OCTET16_LEN) {
for (i = 0; i < (BT_OCTET16_LEN - btm_cb.key_size); i ++) {
p->param_buf[BT_OCTET16_LEN - i - 1] = 0;
}
btsnd_hcic_ble_ltk_req_reply(btm_cb.enc_handle, p->param_buf);
}
}
/*******************************************************************************
** Function btm_enc_proc_slave_y
** Description calculate LTK when Y is ready
*******************************************************************************/
static void btm_enc_proc_slave_y(tSMP_ENC *p)
{
UINT16 div, y;
UINT8 *pp = p->param_buf;
tBTM_CB *p_cb = &btm_cb;
tSMP_ENC output;
tBTM_SEC_DEV_REC *p_dev_rec;
BTM_TRACE_DEBUG ("btm_enc_proc_slave_y");
if (p != NULL) {
STREAM_TO_UINT16(y, pp);
div = p_cb->ediv ^ y;
p_dev_rec = btm_find_dev_by_handle (p_cb->enc_handle);
if ( p_dev_rec &&
p_dev_rec->ble.keys.div == div ) {
BTM_TRACE_DEBUG ("LTK request OK");
/* calculating LTK , LTK = E er(div) */
SMP_Encrypt(p_cb->devcb.ble_encryption_key_value, BT_OCTET16_LEN, (UINT8 *)&div, 2, &output);
btm_enc_proc_ltk(&output);
} else {
BTM_TRACE_DEBUG ("LTK request failed - send negative reply");
btsnd_hcic_ble_ltk_req_neg_reply(p_cb->enc_handle);
if (p_dev_rec) {
btm_ble_link_encrypted(p_dev_rec->bd_addr, 0);
}
}
}
}
/*******************************************************************************
**
** Function btm_ble_ltk_request_reply
@@ -1458,7 +1405,6 @@ void btm_ble_ltk_request_reply(BD_ADDR bda, BOOLEAN use_stk, BT_OCTET16 stk)
{
tBTM_SEC_DEV_REC *p_rec = btm_find_dev (bda);
tBTM_CB *p_cb = &btm_cb;
tSMP_ENC output;
if (p_rec == NULL) {
BTM_TRACE_ERROR("btm_ble_ltk_request_reply received for unknown device");
@@ -1855,7 +1801,7 @@ UINT8 btm_proc_smp_cback(tSMP_EVT event, BD_ADDR bd_addr, tSMP_EVT_DATA *p_data)
case SMP_COMPLT_EVT:
if (btm_cb.api.p_le_callback) {
/* the callback function implementation may change the IO capability... */
BTM_TRACE_DEBUG ("btm_cb.api.p_le_callback=0x%x", btm_cb.api.p_le_callback );
BTM_TRACE_DEBUG ("btm_cb.api.p_le_callback=%p", btm_cb.api.p_le_callback );
(*btm_cb.api.p_le_callback) (event, bd_addr, (tBTM_LE_EVT_DATA *)p_data);
}
@@ -1975,7 +1921,7 @@ BOOLEAN BTM_BleDataSignature (BD_ADDR bd_addr, UINT8 *p_text, UINT16 len,
btm_ble_increment_sign_ctr(bd_addr, TRUE);
}
BTM_TRACE_DEBUG("%s p_mac = %d", __func__, p_mac);
BTM_TRACE_DEBUG("%s p_mac = %p", __func__, p_mac);
BTM_TRACE_DEBUG("p_mac[0] = 0x%02x p_mac[1] = 0x%02x p_mac[2] = 0x%02x p_mac[3] = 0x%02x",
*p_mac, *(p_mac + 1), *(p_mac + 2), *(p_mac + 3));
BTM_TRACE_DEBUG("p_mac[4] = 0x%02x p_mac[5] = 0x%02x p_mac[6] = 0x%02x p_mac[7] = 0x%02x",

View File

@@ -118,7 +118,7 @@ void btm_ble_advfilt_enq_op_q(UINT8 action, UINT8 ocf, tBTM_BLE_FILT_CB_EVT cb_e
btm_ble_adv_filt_cb.op_q.p_scan_cfg_cback[btm_ble_adv_filt_cb.op_q.next_idx] = p_cmpl_cback;
btm_ble_adv_filt_cb.op_q.p_filt_param_cback[btm_ble_adv_filt_cb.op_q.next_idx]
= p_filt_param_cback;
BTM_TRACE_DEBUG("btm_ble_advfilt_enq_op_q: act_ocf:%d, action:%d, ocf:%d,cb_evt;%d, cback:%x",
BTM_TRACE_DEBUG("btm_ble_advfilt_enq_op_q: act_ocf:%d, action:%d, ocf:%d,cb_evt;%d, cback:%p",
btm_ble_adv_filt_cb.op_q.action_ocf[btm_ble_adv_filt_cb.op_q.next_idx], action,
ocf, cb_evt, p_cmpl_cback);
btm_ble_adv_filt_cb.op_q.next_idx = (btm_ble_adv_filt_cb.op_q.next_idx + 1)

Some files were not shown because too many files have changed in this diff Show More