Compare commits

...

409 Commits

Author SHA1 Message Date
4bbff34ac2 fix(esp-tls): Remove useless const from size paramter 2024-11-19 18:21:18 +01:00
Island
f420609c33 Merge branch 'bugfix/fix_ble_creat_conn_fail_enh' into 'master'
fix(ble/bluedroid): Fixed BLE create connection fail because of invalid own address type

Closes BLERP-639

See merge request espressif/esp-idf!34895
2024-11-19 12:06:26 +08:00
Island
5910fc8270 Merge branch 'feat/optimize_cble50y24_110' into 'master'
feat(bt/bluedroid): Added BLE 5.0 throughput examples

Closes BLERP-992

See merge request espressif/esp-idf!34316
2024-11-19 08:55:18 +08:00
Tomas Rezucha
691a0ee1fd Merge branch 'feature/usb_ctrl_hint' into 'master'
feat(hints/usb): Add a hint about too small control transfer size

See merge request espressif/esp-idf!34936
2024-11-18 21:03:30 +08:00
Tomas Rezucha
66596b7f59 feat(hints/usb): Add a hint about too small control transfer size 2024-11-18 21:03:30 +08:00
Aleksei Apaseev
9c91d08c78 Merge branch 'ci/git-diff-output-optimization' into 'master'
ci: optimize `git diff` handling to address "Argument list too long" error

See merge request espressif/esp-idf!34960
2024-11-18 19:44:10 +08:00
Kevin (Lao Kaiyao)
f3c95b632e Merge branch 'ci/fix_i2s_multi_dev_test_potential_overflow' into 'master'
ci(i2s): fix the potential overflow in multi_dev test

Closes IDFCI-2486 and IDFCI-2487

See merge request espressif/esp-idf!34681
2024-11-18 19:29:16 +08:00
laokaiyao
978896a09d docs(i2s): update i2s cap overview 2024-11-18 18:38:30 +08:00
zhanghaipeng
b65f8a98bd fix(ble/bluedroid): Fixed BLE create connection fail because of invalid own address type 2024-11-18 17:48:42 +08:00
Aleksei Apaseev
0045550de5 ci: optimize git diff handling to address "Argument list too long" error 2024-11-18 17:08:28 +08:00
Rahul Tank
393b7410a6 Merge branch 'feature/remove_min_max_def' into 'master'
fix(nimble): Removed min/max macro definition from os.h

Closes IDFGH-14017

See merge request espressif/esp-idf!34745
2024-11-18 17:05:42 +08:00
Wang Meng Yang
03b6436745 Merge branch 'bugfix/rx_invalid_cmd_err_code' into 'master'
fix(bt/bluedroid): Fixed the incorrect error code returned when receiving an invalid command

Closes BT-3899

See merge request espressif/esp-idf!34872
2024-11-18 16:43:54 +08:00
zhangbowen
6d3a82eecf feat(bt/bluedroid): Added BLE 5.0 throughput examples 2024-11-18 15:30:21 +08:00
Jiang Jiang Jian
b9253b4e66 Merge branch 'bugfix/wps_ie_reset' into 'master'
fix(wifi): Remove WPS IEs once WPS succeeds

See merge request espressif/esp-idf!34777
2024-11-18 14:08:50 +08:00
Mahavir Jain
e8800ac785 Merge branch 'feat/add_alpn_for_esp_http_client' into 'master'
feat(esp_http_client): Added alpn feature in esp_http_client

Closes IDF-10729

See merge request espressif/esp-idf!34708
2024-11-18 13:14:24 +08:00
morris
88c4086db9 Merge branch 'feat/mipi_dsi_underrun_error' into 'master'
feat(mipi_dsi): enable underrun error interrupt

See merge request espressif/esp-idf!31704
2024-11-18 11:32:23 +08:00
Shu Chen
42cbc7aada Merge branch 'feature/support_custom_ot_header_file' into 'master'
feat(openthread): support using custom header file

See merge request espressif/esp-idf!30838
2024-11-18 10:45:33 +08:00
C.S.M
9382c9a400 Merge branch 'fix/fix_tsens_retention_p4' into 'master'
fix(temperature_sensor): Fix temperature sensor sleep retention on p4

Closes IDFCI-2491, IDFCI-2483, and IDFCI-2484

See merge request espressif/esp-idf!34902
2024-11-18 10:33:25 +08:00
Armando (Dou Yiwen)
4c9154bad1 Merge branch 'doc/isp_lsc_doc' into 'master'
isp: isp lsc programming guide

See merge request espressif/esp-idf!34818
2024-11-18 10:17:38 +08:00
Anton Maklakov
16469297b4 Merge branch 'feature/update-gdb-to-15.2_20241112' into 'master'
feat(tools): update gdb version to 15.2_20241112

Closes IDF-11325

See merge request espressif/esp-idf!34859
2024-11-15 22:17:20 +08:00
Chen Ji Chang
5009857d7d Merge branch 'fix/i2c_oled_example_crash_on_esp32' into 'master'
fix(i2c_oled): fix buffer allocation

See merge request espressif/esp-idf!34968
2024-11-15 20:26:09 +08:00
Mahavir Jain
401fa7b0f3 Merge branch 'feat/updating_configs_of_esp_https_server' into 'master'
feat(esp_https_server): Updated the ESP_TLS_SERVER_CERT_SELECT_HOOK config

Closes IDF-8418

See merge request espressif/esp-idf!33966
2024-11-15 18:35:00 +08:00
laokaiyao
53d2d67226 ci(i2s): fix the potential overflow in multi_dev test 2024-11-15 18:11:39 +08:00
Island
a3922cd1a7 Merge branch 'bugfix/fix_ble_disconn_error_on_c61' into 'master'
fix(ble): fix btbb retention register size on esp32c61

Closes BLERP-1239 and PHY-206

See merge request espressif/esp-idf!34908
2024-11-15 17:33:34 +08:00
Chen Jichang
29b017b785 fix(i2c_oled): fix buffer allocation 2024-11-15 17:31:15 +08:00
hrushikesh.bhosale
5aaa47834a feat(esp_http_client): Added ALPN feature in esp_http_client
Added the alpn field in esp_http_clinet_config_t struct. So
that user can modify from the esp_http_clinet component.
2024-11-15 14:37:28 +05:30
Jiang Jiang Jian
c5ada2e82f Merge branch 'fix/fix_deadlock_in_pm_mode_switching' into 'master'
fix(esp_pm): fix deadlock in pm_mode switching

Closes PM-144

See merge request espressif/esp-idf!34723
2024-11-15 16:55:07 +08:00
Island
9f47024e78 Merge branch 'fix/ble_mesh_heartbeat_bug' into 'master'
fix(ble_mesh): fixed heartbeat issue

Closes BLERP-1241

See merge request espressif/esp-idf!34912
2024-11-15 16:23:20 +08:00
Xu Si Yu
6e05a9e65b feat(openthread): support using custom header file 2024-11-15 15:37:54 +08:00
Armando
7c384facd7 change(sdmmc): simplify cmd11 enable code 2024-11-15 15:22:02 +08:00
Armando
092bbdbc9c doc(isp): isp lsc programming guide 2024-11-15 15:22:02 +08:00
Jiang Jiang Jian
c014ced2f8 Merge branch 'bugfix/fix_classic_bt_build_fail' into 'master'
fix(bt/bluedroid): Fixed classic bt build fail when enable dynamic memory and disable BLE

Closes BT-3862

See merge request espressif/esp-idf!34921
2024-11-15 11:16:34 +08:00
C.S.M
872a3a2d71 fix(temperature_sensor): Fix temperature sensor sleep retention on p4 2024-11-15 11:04:23 +08:00
C.S.M
e84b59cf92 Merge branch 'feat/official_winbond_chip' into 'master'
feat(spi_flash): Add support for winbond flash chip

See merge request espressif/esp-idf!34039
2024-11-15 11:01:11 +08:00
Shu Chen
a1ec278291 Merge branch 'bugfix/2015_enhack' into 'master'
fix(802.15.4): handle 2015 frame enh-ack

See merge request espressif/esp-idf!34904
2024-11-15 10:14:35 +08:00
Shu Chen
9dc4a27d9c Merge branch 'fix/thread_resolve_invalid_host' into 'master'
fix(openthread): Fix invalid host resolving for Thread end devices

See merge request espressif/esp-idf!34913
2024-11-15 10:13:41 +08:00
Island
d74bf059c8 Merge branch 'feat/ble_mesh_proxy_client_server_coexists_support' into 'master'
feat(ble_mesh): Proxy Client/Server Coexists Support

Closes BLERP-1129

See merge request espressif/esp-idf!34141
2024-11-15 10:05:12 +08:00
morris
3c8a32ff0d Merge branch 'feat/vectorize_bitscrambler_register' into 'master'
bitscrambler hal driver support

See merge request espressif/esp-idf!34885
2024-11-15 09:53:54 +08:00
Radek Tandler
8255ba29a6 Merge branch 'feature/storage_nvs_bootloader' into 'master'
feat(storage/nvs): NVS bootloader support

See merge request espressif/esp-idf!31753
2024-11-15 00:12:18 +08:00
Adam Múdry
4b79cb964f Merge branch 'fix/tusb_midi_task_stack_overflow' into 'master'
fix(examples): tusb_midi task stack overflow fix

Closes IDFGH-14002

See merge request espressif/esp-idf!34914
2024-11-14 23:38:30 +08:00
Ivan Grokhotkov
4d75d2d487 Merge branch 'bugfix/protocols_examples_common_driver_dep' into 'master'
remove leftover dependencies on `driver` component

See merge request espressif/esp-idf!33548
2024-11-14 22:21:57 +08:00
zhanghaipeng
59d20e80d3 fix(bt/bluedroid): Fixed classic bt build fail when enable dynamic memory and disable BLE 2024-11-14 21:17:13 +08:00
David Čermák
890106fb23 Merge branch 'fix/lwip_tcp_pcb_recycle' into 'master'
fix(lwip): Limit active TCP PCBs and recycle them faster

Closes IDFGH-8173, IDF-8914, and IDF-10021

See merge request espressif/esp-idf!34879
2024-11-14 21:07:10 +08:00
Adam Múdry
7e9782b67e fix(examples): tusb_midi task stack overflow fix 2024-11-14 13:03:27 +01:00
WanqQixiang
1a028bdfdc fix(openthread): Fix invalid host resolving for Thread end devices 2024-11-14 19:42:26 +08:00
luoxu
167cd4762b fix(ble_mesh): fixed heartbeat issue 2024-11-14 19:38:20 +08:00
luoxu
74c847210d feat(ble_mesh): Proxy Client/Server Coexists Support 2024-11-14 19:22:59 +08:00
Abhinav Kudnar
6002db2fb9 fix(nimble): Removed min/max macro defination from os.h
Closes https://github.com/espressif/esp-idf/issues/14840
2024-11-14 19:06:14 +08:00
morris
c86a301736 feat(mipi_dsi): enable underrun error interrupt 2024-11-14 19:05:43 +08:00
cjin
ce85e113a9 fix(ble): fix btbb retention register size on esp32c61 2024-11-14 19:04:23 +08:00
radek.tandler
c445ec134b feat(nvs_flash): Implemented basic nvs_flash support for bootloader 2024-11-14 11:56:45 +01:00
C.S.M
1e11d42aa1 feat(spi_flash): Add support for winbond flash chip 2024-11-14 18:32:40 +08:00
C.S.M
38b737511c Merge branch 'feat/tsens_support_c61' into 'master'
feat(temperature_sensor): Add temperature sensor support on esp32c61

Closes IDF-9322

See merge request espressif/esp-idf!34326
2024-11-14 17:51:36 +08:00
Roland Dobai
7fcbdb9c2e Merge branch 'docs/sbom_tool' into 'master'
docs(sbom): add basic description about SBOM for ESP-IDF projects

Closes IDF-11485

See merge request espressif/esp-idf!34853
2024-11-14 17:28:11 +08:00
morris
83c9cffd2b change(soc): vectorize bitscrambler regsiter layout 2024-11-14 17:26:57 +08:00
Jeroen Domburg
ab75a94877 feat(bitscrambler): add hal driver support 2024-11-14 17:26:57 +08:00
hrushikesh.bhosale
ace6a490bc feat(esp_https_server): Updated the ESP_TLS_SERVER_CERT_SELECT_HOOK config
Update the ESP_TLS_SERVER_CERT_SELECT_HOOK config to ESP_HTTPS_SERVER_CERT_SELECT_HOOK
And made it depend on  ESP_TLS_SERVER_CERT_SELECT_HOOK
2024-11-14 14:48:50 +05:30
Roman Leonov
7ff774905a Merge branch 'fix/usb_device_msc_storage_example' into 'master'
fix(tusb_msc): Added SD power supply configuration for p4

See merge request espressif/esp-idf!33455
2024-11-14 17:18:39 +08:00
Tan Yan Quan
705e2695ee fix(802.15.4): add case for 2015 frame enh-ack 2024-11-14 15:56:21 +08:00
C.S.M
0b1170af8f Merge branch 'docs/update_i2c_slave_v2' into 'master'
feat(i2c_slave): Update I2C programming guide according to new changes

See merge request espressif/esp-idf!34806
2024-11-14 14:41:19 +08:00
Song Ruo Jing
78a690517f Merge branch 'bugfix/uart_single_wire_mode' into 'master'
fix(uart): allow same pin for tx and rx in uart_set_pin; UART_SELECT_READ_NOTIF race conditon fix

Closes IDFGH-13954, IDF-10721, IDF-11127, and IDF-9108

See merge request espressif/esp-idf!34737
2024-11-14 14:18:47 +08:00
Zhang Xiao Yan
074b74c701 Merge branch 'docs/translate_file_system_consideration' into 'master'
docs: Provide CN translation for file system considerations in IDF

Closes DOC-8963

See merge request espressif/esp-idf!33782
2024-11-14 14:02:49 +08:00
Omar Chebib
d5f244c5f7 Merge branch 'feat/psram_qemu_16_32_mb_qpi' into 'master'
feat(esp_psram): add support for QEMU 16MB and 32MB QPI PSRAM

See merge request espressif/esp-idf!34832
2024-11-14 12:04:22 +08:00
Shu Chen
1de992adef Merge branch 'fix/find_and_close_service_in_ot_ci_case' into 'master'
fix(ci): optimize an openthread ci case

Closes IDFCI-2430

See merge request espressif/esp-idf!34106
2024-11-14 11:58:23 +08:00
C.S.M
6a9e7f61e8 docs(i2c_slave): Update i2c slave programming guide for new changes 2024-11-14 11:40:44 +08:00
Gao Xu
bbcfb35d67 Merge branch 'feat/h21_introduce_step1_target' into 'master'
feat(esp32h21): introduce target esp32h21 (stage 1/8) 😐

See merge request espressif/esp-idf!34542
2024-11-14 10:46:44 +08:00
Omar Chebib
fe93c990e6 feat(esp_psram): add support for QEMU 16MB and 32MB QPI PSRAM 2024-11-14 10:24:43 +08:00
xiongweichao
4b4a9a2174 fix(bt/bluedroid): Fixed the incorrect error code returned
when receiving an invalid command
2024-11-14 10:20:53 +08:00
Zhang Shuxian
d7bc953d66 docs: Provide CN translation for file system considerations in IDF 2024-11-14 10:09:56 +08:00
Island
ea31e155e8 Merge branch 'feature/support_moving_code_to_flash' into 'master'
feat(ble): Support for putting code in flash on ESP32-C2

See merge request espressif/esp-idf!34774
2024-11-14 10:09:17 +08:00
Roman Leonov
32f60da330 fix(tusb_msc): Fixed sdmmc init on ESP32P4 2024-11-13 16:34:54 +01:00
Frantisek Hrbata
4e9362a1cb docs(sbom): add basic description about SBOM for ESP-IDF projects
Add a basic description and usage overview of the esp-idf-sbom tool. A
more detailed description is already available on the GitHub pages,
which this documentation refers to.

Signed-off-by: Frantisek Hrbata <frantisek.hrbata@espressif.com>
2024-11-13 15:45:19 +01:00
Kapil Gupta
7a305c0284 Merge branch 'bugfix/crash_deauth_fix' into 'master'
fix(esp_wifi): Fix for crash while receiving deauth in esp32c2 ECO4

Closes WIFIBUG-825 and WIFIBUG-840

See merge request espressif/esp-idf!34682
2024-11-13 21:19:01 +08:00
akshat
9ec62baa94 fix(esp_rom): Comment out unused function pointers in esp32c2 eco4 linker file 2024-11-13 20:01:26 +08:00
Aditi
862f3bd7bf fix(esp_wifi): Fix for crash while receiving deauth in esp32c2 ECO4 2024-11-13 20:01:26 +08:00
Tomas Rezucha
e613fcde6e Merge branch 'contrib/github_pr_14738' into 'master'
fix(docs): code comment spelling error  (GitHub PR)

Closes IDFGH-13896

See merge request espressif/esp-idf!34863
2024-11-13 19:23:47 +08:00
Konstantin Kondrashov
d37e1cccb6 Merge branch 'feature/adds_pthread_funcs' into 'master'
feat(pthread): Adds set/get sched param funcs

Closes IDFGH-13997 and IDFGH-6976

See merge request espressif/esp-idf!34787
2024-11-13 17:27:20 +08:00
Song Ruo Jing
582c99041c Merge branch 'bugfix/uart_8_16_bit_access' into 'master'
fix(uart): fix 8/16-bit uart register access

Closes IDF-10256

See merge request espressif/esp-idf!34846
2024-11-13 17:17:26 +08:00
Tomas Rezucha
5532fa8e26 Merge branch 'contrib/github_pr_14858' into 'master'
fix(examples/usb_host_lib): correct typo in comments (GitHub PR)

Closes IDFGH-14038

See merge request espressif/esp-idf!34861
2024-11-13 15:58:10 +08:00
David Cermak
0d99214012 fix(lwip): Limit active TCP PCBs and recycle them faster
* Update submodule: git log --oneline c816f0ee..a587d929
Detailed description of the changes:
  - test: Add tcp-pcb recycle test (espressif/esp-lwip@a587d929)
  - tcp: Apply faster PCB recycling in FIN_WAIT_1 or FIN_WAIT_2 state (espressif/esp-lwip@3bfc85d2)
  - test: Add tcp alloc limitation test (espressif/esp-lwip@0c9c39a9)
  - memp: Employ TCP-PCB allocation limit if libc malloc used (espressif/esp-lwip@9cb96ac1)

Closes https://github.com/espressif/esp-idf/issues/9670
Closes https://github.com/espressif/esp-lwip/pull/63
2024-11-13 08:53:51 +01:00
Tomas Rezucha
1e7098fe97 Merge branch 'contrib/github_pr_14859' into 'master'
fix(usb_host): return ESP_ERR_NO_MEM on failed alloc in client register (GitHub PR)

Closes IDFGH-14037

See merge request espressif/esp-idf!34862
2024-11-13 15:33:11 +08:00
Wan Lei
1a25f6887d Merge branch 'fix/adc_monitor_not_work' into 'master'
fix(esp_adc): fixed adc continue monitor don't work issue

Closes IDFGH-13931 and IDFGH-13988

See merge request espressif/esp-idf!34436
2024-11-13 15:23:28 +08:00
David Čermák
cbbb85fecd Merge branch 'fix/ws_transport_head_fragments' into 'master'
fix(ws_transport): Fix reading WS header in fragments

Closes IDFGH-13951, IDFGH-13857, and IDFGH-13859

See merge request espressif/esp-idf!34517
2024-11-13 15:07:42 +08:00
Erhan Kurubas
97b65d7350 Merge branch 'change/disable_stub_bins' into 'master'
change(esp_system): do not include openocd stub bins by default

See merge request espressif/esp-idf!34755
2024-11-13 14:30:43 +08:00
Guillaume Souchere
b6be76f53b Merge branch 'fix/typo-esp-rom' into 'master'
fix(esp_rom): Fix comment typos

Closes IDFGH-13635

See merge request espressif/esp-idf!34849
2024-11-13 13:42:03 +08:00
wuzhenghui
df52e1aa71 fix(esp_pm): fix deadlock in pm_mode switching 2024-11-13 12:12:23 +08:00
wuzhenghui
b4bd3d98bd fix(esp_pm): fix missed ccompare update when another core is already in do_switch 2024-11-13 12:11:47 +08:00
Wu Zheng Hui
908e62f5e4 Merge branch 'fix/fix_cache_error_in_sar_disable' into 'master'
fix(esp_hw_support): fix sar disable access flash in IRAM_OPT sleep

Closes IDFCI-2509

See merge request espressif/esp-idf!34833
2024-11-13 11:28:40 +08:00
Armando (Dou Yiwen)
ed8ec9de0b Merge branch 'feat/sdmmc_uhs_tuning' into 'master'
sdmmc: UHS-I support for SDR50 (100MHz, 50MB/s), DDR50 (50MHz, 50MB/s)

Closes IDF-10294, IDF-11447, and IDF-8886

See merge request espressif/esp-idf!34441
2024-11-13 11:05:10 +08:00
C.S.M
bff20b5397 feat(temperature_sensor): Add temperature sensor support on esp32c61 2024-11-13 10:52:47 +08:00
Marius Vikhammer
f8ddcee8cd Merge branch 'refactor/cache_err_panic' into 'master'
refactor(panic): refactor and unify cache panic errors

See merge request espressif/esp-idf!34382
2024-11-13 10:19:38 +08:00
Armando
5bff669f2f fix(i2s): fixed i2s example build warning 2024-11-13 09:47:45 +08:00
Armando
727825663b doc(sdmmc): aadd UHS1 support for DDR50 / SDR50 2024-11-13 09:47:45 +08:00
Armando
cb41623b2e example(sdmmc): support hs and uhs1 sdr50/ddr50 2024-11-13 09:47:45 +08:00
Armando
9e3b7e4558 feat(sdmmc): supported UHS-I SDR50 (100Mhz) and DDR50 mode 2024-11-13 09:47:45 +08:00
Adam Múdry
cf44fc6a1f Merge branch 'fix/sdmmc_test_acmd22_esp32p4_fix' into 'master'
fix(sdmmc): Fix ACMD22 DMA buffer problem for ESP32-P4

Closes IDFCI-2499

See merge request espressif/esp-idf!34826
2024-11-13 06:53:49 +08:00
Roland Dobai
30b13b132d Merge branch 'update/deprecate_python38' into 'master'
feat: Drop Python 3.8 support

Closes IDF-7579

See merge request espressif/esp-idf!34419
2024-11-13 01:40:58 +08:00
David Cermak
d8949fe50f fix(ws_transport): Unit test on reading WS data byte by byte
Closes https://github.com/espressif/esp-idf/issues/14704
Closes https://github.com/espressif/esp-protocols/issues/679
2024-11-12 17:07:15 +01:00
Roland Dobai
5bae0b92ec Merge branch 'fix/import_error_msg' into 'master'
fix(tools): re-raise ImportError without module name

Closes IDF-11648

See merge request espressif/esp-idf!34780
2024-11-13 00:07:05 +08:00
Richard Allen
7f54410256 fix(ws_transport): Fix reading WS header bytes
Correct split header bytes

When the underlying transport returns header,
length, or mask bytes early, again call the
underlying transport.

This solves the WS parser getting offset when
the server sends a burst of frames where the
last WS header is split across packet boundaries,
so fewer than the needed bytes may be available.

Merges https://github.com/espressif/esp-idf/pull/14706
2024-11-12 17:06:31 +01:00
Konstantin Kondrashov
ce72392e2f Merge branch 'feature/adds_recovery_bootloader_subtype' into 'master'
feat(partition_table): Support recovery bootloader subtype

See merge request espressif/esp-idf!34757
2024-11-12 22:54:39 +08:00
Roland Dobai
542a5d280c Merge branch 'contrib/github_pr_14733' into 'master'
fix(cmake): Prevent overwriting of component properties in output file (GitHub PR)

Closes IDFGH-13891

See merge request espressif/esp-idf!34807
2024-11-12 22:48:54 +08:00
morris
05beacad73 Merge branch 'change/esp_ldo_reserve_for_spi_flash' into 'master'
LDO calibration on ESP32-P4

Closes IDF-10754

See merge request espressif/esp-idf!32347
2024-11-12 22:44:12 +08:00
Alexey Lapshin
33149921aa fix(gdbstub): remove QThreadEvents+ from qSupported 2024-11-12 21:18:51 +07:00
Alexey Lapshin
dca5d193fc feat(tools): update gdb version to 15.2_20241112 2024-11-12 14:07:16 +00:00
Adam Múdry
b0ffe15514 fix(sdmmc): Fix ACMD22 DMA buffer problem for ESP32-P4 2024-11-12 14:55:19 +01:00
Erhan Kurubas
b4f366f56f change(esp_system): do not include openocd stub bins by default 2024-11-12 14:04:17 +01:00
Song Ruo Jing
32040c7f98 fix(uart): fix race condition with the use of UART_SELECT_READ_NOTIF
UART_SELECT_READ_NOTIF needs to be sent after received data got processed
to avoid the potential race condition
2024-11-12 20:08:38 +08:00
Song Ruo Jing
e8f0299557 fix(uart): allow same pin for tx and rx in uart_set_pin
Also add IO reserve to uart driver

Closes https://github.com/espressif/esp-idf/issues/14787
2024-11-12 20:08:38 +08:00
YAMAMOTO Takashi
de077c77b4 fix(esp-rom): Fix comment typos in cache.h
Fix typo in parameter names in cache_flash_mmu_set
amd cache_sram_mmu_set functions.
2024-11-12 12:05:03 +01:00
Shen Weilong
ccc2411191 feat(ble): Support for putting code in flash on ESP32-C2 2024-11-12 18:08:50 +08:00
Lu Wei Ke
bb9a2658a9 Merge branch 'docs/translate_partition_tables' into 'master'
docs: Provide CN translation for partition tables

Closes DOC-9274

See merge request espressif/esp-idf!34647
2024-11-12 17:23:40 +08:00
Konstantin Kondrashov
3318e0accd feat(pthread): Adds set/get sched param funcs
Closes https://github.com/espressif/esp-idf/issues/14821
Closes https://github.com/espressif/esp-idf/issues/8594
2024-11-12 17:23:03 +08:00
Konstantin Kondrashov
52f14f344d feat(partition_table): Support recovery bootloader subtype 2024-11-12 17:22:53 +08:00
Frantisek Hrbata
a4acbd2758 feat: Drop Python 3.8 support
Signed-off-by: Frantisek Hrbata <frantisek.hrbata@espressif.com>
2024-11-12 17:02:26 +08:00
Frantisek Hrbata
e8fda6f776 fix(tools): re-raise ImportError without module name
The ImportError or ModuleNotFoundError might be raised without
specifying a module name. In this not so common situation, re-raise the
exception to print all the information that could assist in identifying
the problem.

Signed-off-by: Frantisek Hrbata <frantisek.hrbata@espressif.com>
2024-11-12 17:01:46 +08:00
Song Ruo Jing
e6ef4d1791 fix(uart): fix 8/16-bit uart register access 2024-11-12 16:52:10 +08:00
morris
16eef27492 feat(ldo): load calibration parameters from efuse 2024-11-12 15:52:05 +08:00
wanckl
d0e6e825d9 fix(esp_adc): fixed adc continue monitor don't work issue
Closes https://github.com/espressif/esp-idf/issues/14769
Closes https://github.com/espressif/esp-idf/issues/14814
2024-11-12 15:42:50 +08:00
gaoxu
64bbb53b8f feat(esp32h21): introduce target esp32h21(stage 1) 2024-11-12 15:42:27 +08:00
Ivan Grokhotkov
c9bf5d9698 feat(sdmmc): support for voltage switching in protocol layer 2024-11-12 15:39:42 +08:00
Ivan Grokhotkov
c41cead036 change(sdmmc): enable UHS-1 support in test_app, swap slots on P4 EV board 2024-11-12 15:39:42 +08:00
Ivan Grokhotkov
f5f46ab74c change(sdmmc): adapt host state machine for CMD11, commit reg/struct files 2024-11-12 15:39:42 +08:00
Ivan Grokhotkov
98f1dd969a change(sdmmc): disable the logic related to D3 line, it needs to be connected for CMD11 to work 2024-11-12 15:39:41 +08:00
Ivan Grokhotkov
2b29de78bb change(sdmmc): allow speciying pins for IOMUX slots as well 2024-11-12 15:39:41 +08:00
Ivan Grokhotkov
3107f0abe7 change(sdmmc): make sdmmc_host_clock_update_command compatible with CMD11 2024-11-12 15:39:41 +08:00
Adam Múdry
1689c7e14f Merge branch 'fix/nvs_generator_test_fail_due_to_safer_write_namespace_function' into 'master'
fix(nvs): Fix the NVS generator test (write_namespace safer behavior change)

Closes IDF-11674

See merge request espressif/esp-idf!34828
2024-11-12 15:38:22 +08:00
luweike
e7ab36ebbf docs: Provide CN translation for partition tables 2024-11-12 14:29:30 +08:00
David Čermák
afb4a02fe4 Merge branch 'fix/lwip_ping_ipv6only' into 'master'
fix(lwip): Fix IP6 raw socket checksum in IPv6-only configuration

Closes IDF-9670

See merge request espressif/esp-idf!33936
2024-11-12 13:36:12 +08:00
Roland Dobai
cf087cb8e5 Merge branch 'feat/size_unify_sections' into 'master'
feat(tools): unify sections in idf.py size reports for NG version

Closes IDF-11649

See merge request espressif/esp-idf!34788
2024-11-12 13:31:10 +08:00
wuzhenghui
2899c1e39f fix(esp_hw_support): fix sar disable access flash in IRAM_OPT sleep 2024-11-12 12:01:52 +08:00
Adam Múdry
ba2bf2f512 fix(nvs): Fix the nvs generator test (write_namespace safer behavior change) 2024-11-11 22:38:47 +01:00
Samuel Obuch
3f46b378bb Merge branch 'feat/esp32p4_unicore_stop_other_core' into 'master'
feat(esp_system): stop other core for unicore esp32p4

See merge request espressif/esp-idf!34753
2024-11-11 17:58:01 +08:00
Li Bo
ea902d6ed7 Merge branch 'bugfix/esp32c3_eco7_usj_console' into 'master'
fix(esp_rom): fix esp32c3 eco7 console rom function address

See merge request espressif/esp-idf!34671
2024-11-11 17:52:48 +08:00
Roman Leonov
dccbd16750 Merge branch 'docs/usb_host_ext_port_driver' into 'master'
docs(ext_port): Maintainers Notes for the External Port Driver

Closes IDF-11106

See merge request espressif/esp-idf!33350
2024-11-11 17:34:00 +08:00
Jan Beran
06508329c8 Merge branch 'docs/edit_kconfig_docs' into 'master'
docs(kconfiglib): Make a detailed docs section about Kconfig

See merge request espressif/esp-idf!32995
2024-11-11 16:06:40 +08:00
Wang Meng Yang
7bc8b998a7 Merge branch 'bugfix/lmp_trans_collision' into 'master'
fix(bt/controller): Fixed some controller bugs on ESP32

Closes BTQABR2023-363 and BT-3577

See merge request espressif/esp-idf!34577
2024-11-11 15:19:27 +08:00
Armando (Dou Yiwen)
08ef00d82d Merge branch 'change/adc_conti_read_api_doc_update' into 'master'
adc: updated continuous mode read API doc about block timeout description

Closes IDFGH-14033

See merge request espressif/esp-idf!34796
2024-11-11 14:30:54 +08:00
Island
87e4f63c77 Merge branch 'feature/ble_mesh_50_api_minimal' into 'master'
Feature/ble mesh 50 api minimal

Closes BLERP-1211 and BLERP-1212

See merge request espressif/esp-idf!31510
2024-11-11 14:22:31 +08:00
Wu Zheng Hui
56db9a2841 Merge branch 'fix/fix_cache_stuck_in_esp_restart' into 'master'
fix(esp_system): fix P4 possible crash on esp_restart if PSRAM is used

Closes PM-291

See merge request espressif/esp-idf!34778
2024-11-11 14:00:58 +08:00
Armando
4df585e1a8 doc(adc): updated continuous mode read API block timeout description
Closes https://github.com/espressif/esp-idf/issues/14854
2024-11-11 12:09:04 +08:00
Omar Chebib
3ec05583b2 Merge branch 'contrib/github_pr_14771' into 'master'
fix(example/system/console): Add 'info' to log_level command description (GitHub PR)

Closes IDFGH-13933

See merge request espressif/esp-idf!34413
2024-11-11 10:56:56 +08:00
Jiang Jiang Jian
2414b285c0 Merge branch 'fix/move_softap_csa_and_dtim_to_nvs' into 'master'
change(wifi): move softap dtim and csa to nvs

Closes WIFIBUG-666

See merge request espressif/esp-idf!34489
2024-11-11 10:42:40 +08:00
Gao Xu
611e163024 Merge branch 'feat/esp32c61_adc_support' into 'master'
ADC: support ADC oneshot and continuous mode on ESP32C61

Closes IDF-9302 and IDF-9304

See merge request espressif/esp-idf!32907
2024-11-11 10:22:47 +08:00
Daniel Mangum
7962d54c4c fix(usb_host): return ESP_ERR_NO_MEM on failed alloc in client register
Fixes issue where ESP_ERR_NO_MEM was being silently discarded after
cleaning up after a failed malloc in usb_host_client_register.

Signed-off-by: Daniel Mangum <georgedanielmangum@gmail.com>
2024-11-10 19:55:18 -05:00
Daniel Mangum
4e3e73f353 fix(examples/usb_host_lib): correct typo in comments
Fixes a small typo in comments

Signed-off-by: Daniel Mangum <georgedanielmangum@gmail.com>
2024-11-10 19:39:53 -05:00
C.S.M
d74e99c08a Merge branch 'feat/i2c_slave_v2' into 'master'
feat(i2c_slave): Add new i2c slave driver --version two with great stretch handling. 🏂

See merge request espressif/esp-idf!33802
2024-11-09 18:43:41 +08:00
Konstantin Kondrashov
110bfc1f45 Merge branch 'feature/adds_bootloader_rollback_configs' into 'master'
feat(bootloader): Adds bootloader anti rollback configs

See merge request espressif/esp-idf!34759
2024-11-09 01:41:50 +08:00
Konstantin Kondrashov
f817b85fc3 Merge branch 'feature/ota_update_for_partitions' into 'master'
feat(ota): Supports OTA update for any partitions (bootloader, partition_table, nvs, etc.)

Closes IDFGH-13262, IDF-7781, and IDFGH-12860

See merge request espressif/esp-idf!32866
2024-11-09 00:53:45 +08:00
Fu Hanxi
d03ead4cf8 Merge branch 'ci/improve_overall_logging' into 'master'
ci: target-test job skip installing toolchain, only install python env

See merge request espressif/esp-idf!34232
2024-11-08 23:27:04 +08:00
Mahavir Jain
b3bae69c5c Merge branch 'fix/mfg_gen_csv_and_bin_prefix' into 'master'
feat(mfg_gen): Added file name serial count prefix for intermediate csv and bin...

See merge request espressif/esp-idf!34251
2024-11-08 23:22:58 +08:00
Frantisek Hrbata
798d35b2e1 feat(tools): unify sections in idf.py size reports for NG version
By default, esp-idf-size.ng displays all sections individually. This can
be confusing, especially if CONFIG_SOC_MEM_NON_CONTIGUOUS_SRAM is
enabled, resulting in sections like .dram0.data and .dram1.data being
abbreviated as two .data sections in the size report. To avoid confusion
for idf.py and cmake users, pass the --unify option to the underlying
esp_idf_size.ng by default.

Signed-off-by: Frantisek Hrbata <frantisek.hrbata@espressif.com>
2024-11-08 15:44:19 +01:00
sanika.inamdar
99f1455199 feat(mfg_gen): provision for specifying prefix counter for csv/bin files 2024-11-08 18:52:00 +05:30
Konstantin Kondrashov
816a0da0fd feat(bootloader): Adds bootloader anti rollback configs 2024-11-08 13:53:24 +02:00
Sergei Silnov
8f777699ff Merge branch 'ci/fix_macos_ccache' into 'master'
CI: Fix failing ccache and show ccache statistics for macOS tests (master)

See merge request espressif/esp-idf!33846
2024-11-08 19:44:23 +08:00
David Cermak
8b191dd7a1 fix(lwip): Fix ping_v6 receiving to accept only echo replies
This fixes a bug where we ping our own IP and the request itself
bounces back to the raw receive function and is incorrectly treated as
reply. (this bug was discovered when fixing ICMPv6 pings with incorrect
checksums, while the ping request was dropped in icmpv6.c due to wrong
checksum, but was also fed to raw layers where it was treated as
"correct" response, so the PINGv6 to ourselves still worked)
2024-11-08 12:21:35 +01:00
David Cermak
c7e2a9ea0d fix(common_connect): Fix example's stdin/out to setup UART interrupt once
Function example_configure_stdin_stdout() was used for simple UART I/O
operation in CI to enter test env configuration (wifi ssid, IPs, etc).
It could be called multiple times, but didn't handle the situation where
we install UART interrupt from multiple source (e.g. in ICMP tests,
where we first need to enter wifi credentials of test AP and then we
start ping-cmd console to handle ping commands)
2024-11-08 12:21:35 +01:00
David Cermak
f269835865 fix(lwip): Fix IP6 raw socket checksum in IPv6-only configuration 2024-11-08 12:21:35 +01:00
wuzhenghui
9a41a61dd5 fix(esp_system): writeback L1 Dcache before disable L2 if PSRAM used 2024-11-08 18:44:14 +08:00
Kapil Gupta
197128b162 fix(wifi): Remove WPS IEs once WPS succeeds 2024-11-08 15:59:58 +05:30
Fu Hanxi
2a5743c0c5 ci: target-test job skip installing toolchain, only install python env
also run with collapsed time section to better track run time
2024-11-08 11:17:57 +01:00
Fu Hanxi
83306b79ef ci: ignore test-specific 3rd-party libs while building clang projects 2024-11-08 11:15:17 +01:00
Fu Hanxi
3e2b56d114 feat: idf_tools.py export support env var "IDF_SKIP_TOOLS_CHECK" 2024-11-08 11:13:44 +01:00
Fu Hanxi
5a3f53a2b5 ci: print esp-coredump output when failed in panic tests 2024-11-08 11:13:43 +01:00
Fu Hanxi
92cd70acc9 ci: remove gcc dependency in target test 2024-11-08 11:13:43 +01:00
Fu Hanxi
f84f883ab4 ci: change logging level from debug to info for build jobs 2024-11-08 11:13:43 +01:00
Fu Hanxi
d137deed2a ci: add timeout for build jobs 2024-11-08 11:13:43 +01:00
Fu Hanxi
dcb4bf4600 ci: stop print presigned url, since the credential is masked 2024-11-08 11:13:39 +01:00
C.S.M
fc81b6878e feat(i2c_slave): Add new example for making i2c slave as a network sensor 2024-11-08 18:04:29 +08:00
C.S.M
63e74e6b68 test(i2c_slave): Add some new tests for i2c slave version 2 2024-11-08 18:04:29 +08:00
C.S.M
941d0e0779 feat(i2c_slave): refactor i2c slave api to version 2 inorder to solve some existing problem 2024-11-08 18:04:29 +08:00
Konstantin Kondrashov
f15c1b4c4f Merge branch 'feature/efuse_s3_adds_psram_cap_bit' into 'master'
feat(efuse): Adds 3 bit for PSRAM_CAP efuse field

Closes IDF-11477

See merge request espressif/esp-idf!34644
2024-11-08 17:43:29 +08:00
Xu Si Yu
8576f40ced Merge branch 'fix/fix_154_ext_coex' into 'master'
fix(coex): fix 802.15.4 external coexistence

Closes TZ-1182

See merge request espressif/esp-idf!33879
2024-11-08 17:24:05 +08:00
gaoxu
efd04b7709 feat(adc): support ADC oneshot and continuous on C61 2024-11-08 17:13:26 +08:00
Mahavir Jain
d2c74a6b1e Merge branch 'change/btl_fetch_app_desc' into 'master'
change(bootloader): Map only the necessary length when fetching the app description struct

See merge request espressif/esp-idf!34752
2024-11-08 17:03:53 +08:00
Li Bo
0bda2f8990 fix(esp_rom): fix esp32c3 eco7 console rom function address 2024-11-08 16:32:47 +08:00
Zhang Wen Xu
3730567940 Merge branch 'feat/update_openthread_submodule_and_br_lib' into 'master'
feat(openthread): update openthread submodule and border router lib

See merge request espressif/esp-idf!34547
2024-11-08 15:55:04 +08:00
Chen Ji Chang
6b54dfc636 Merge branch 'feat/mcpwm_sleep_rentention' into 'master'
feat(mcpwm): support sleep retention

Closes IDF-9752 and IDF-8473

See merge request espressif/esp-idf!33839
2024-11-08 15:39:58 +08:00
Ondrej Kosta
7f07c9de44 Merge branch 'feature/ptp' into 'master'
Feature/ptp

Closes IDFGH-12397

See merge request espressif/esp-idf!33058
2024-11-08 15:10:07 +08:00
Wan Lei
1a30fd0c39 Merge branch 'fix/c61_gpio_num_hardware_update' into 'master'
fix(esp_driver_gpio): esp32c61 gpio number update 22 -> 25

See merge request espressif/esp-idf!34747
2024-11-08 14:21:09 +08:00
luoxu
a86bb375f7 feat(ble_mesh): Support BLE 5.0 for BLE Mesh 2024-11-08 14:17:52 +08:00
Jin Cheng
cfdefd3e03 fix(bt/controller): Fixed some controller bugs on ESP32
- Fixed wrong logic in handling sniff transaction collision at slave
      side
    - Fixed the issue ACL is stopped too early before eSCO
2024-11-08 12:53:56 +08:00
Jin Cheng
c79eb0d5bf fix(bt/bluedroid): AG should send OK or other error codes to HF client
when it is driven by HF to initiate a call.
2024-11-08 12:51:00 +08:00
morris
01cd5cf4fe Merge branch 'bugfix/gpio_set_level_atomic' into 'master'
fix(gpio): improve set level performance

See merge request espressif/esp-idf!34744
2024-11-08 11:43:16 +08:00
Wang Meng Yang
f0ab551348 Merge branch 'bugfix/fix_avrc_absolute_volume_compatibility' into 'master'
bugfix/fix_avrc_absolute_volume_compatibility

Closes FCS-1619

See merge request espressif/esp-idf!34563
2024-11-08 11:07:46 +08:00
wanckl
a50c095df1 fix(esp_driver_gpio): esp32c61 gpio number update 22 -> 25 2024-11-08 10:36:20 +08:00
morris
ad476afb5c Merge branch 'feat/mipi_dsi_yuv_converter' into 'master'
feat(lcd): support YUV422 input color format

See merge request espressif/esp-idf!34530
2024-11-08 10:35:32 +08:00
Konstantin Kondrashov
bb329c4e53 feat(bootloader): Move rollback configs into a separate menu 2024-11-07 19:25:58 +02:00
David Čermák
457f65195e Merge branch 'fix/example_sta2eth_more_docs' into 'master'
fix(sta2eth): Document security consideration in sta2eth example

Closes IDFGH-13990

See merge request espressif/esp-idf!34518
2024-11-08 00:57:00 +08:00
David Cermak
cce9a80aee fix(sta2eth): Check for null netif before starting/stopping DHCP server
Fixes a potential null pointer dereference in `esp_netif` when PPP mode is enabled.
In the Ethernet event handler, `esp_netif_dhcps_start()` and `esp_netif_dhcps_stop()`
are now only called if `netif` is non-null (in provisioning mode when
the actual TCP/IP stack from IDF is used, in work mode the `netif` is
null, since the trafic is simply forwarded between wireless and wired
networks without TCP/IP stack involved)

Closes https://github.com/espressif/esp-idf/issues/14816
2024-11-07 17:48:59 +01:00
David Cermak
94536cb512 fix(sta2eth): Make some Ethernet options configurable 2024-11-07 17:48:53 +01:00
Peter Macko
4fa6e03879 fix(macos): ccache: re-enable, show stats, set CCACHE_DIR, limit CCACHE_MAXSIZE 2024-11-07 22:22:28 +08:00
Samuel Obuch
d2fe62f682 feat(esp_system): stop other core for unicore esp32p4 2024-11-07 14:00:55 +01:00
Laukik Hase
19ab0213d9 change(bootloader): Map only the necessary length when fetching the app description struct 2024-11-07 18:13:53 +05:30
Xu Si Yu
f41b43dc43 feat(openthread): update openthread submodule and border router lib 2024-11-07 20:22:48 +08:00
Ivan Grokhotkov
68e9bcbf1e fix(build): clean up dependencies on driver component 2024-11-07 13:09:23 +01:00
Konstantin Kondrashov
97d150d69a feat(app_update): OTA update bootloader, partition_table and other partitions
Passive app partition can be used as the staging partition where a new image is loaded.
Then copy it to the final partition.

Closes: https://github.com/espressif/esp-idf/issues/14195
Closes: https://github.com/espressif/esp-idf/issues/13824
2024-11-07 13:48:51 +02:00
David Cermak
ac630e4417 fix(sta2eth): Document security considerations in sta2eth example 2024-11-07 10:24:54 +01:00
morris
0ed4c19c5e feat(lcd): support color conversion for mipi dsi driver 2024-11-07 17:02:54 +08:00
morris
712e6ad927 fix(gpio): improve set level performance
by avoid "read-modify-write" operation. The registers designed to be
write only.

Related to https://github.com/espressif/esp-idf/issues/14674
2024-11-07 16:29:28 +08:00
David Čermák
5e056de1e7 Merge branch 'fix/lwip_docs_thread_safe_socks' into 'master'
fix(lwip): Document that not all sock operations are thread safe

See merge request espressif/esp-idf!34333
2024-11-07 15:41:12 +08:00
wangtao@espressif.com
db579962b6 change(wifi): change softap default dtim period to 1 2024-11-07 15:33:11 +08:00
Mahavir Jain
8aa56d805a Merge branch 'docs/add_header_files_http_server_code_example' into 'master'
docs: add a note on required header files for the esp_http_server example

See merge request espressif/esp-idf!34389
2024-11-07 15:03:57 +08:00
Ondrej Kosta
d2b1202d5a feat(esp_eth): added HW Time Stamping support for ESP32P4
Added mechanism to L2 TAP to retreive time stamp

Added PTP time synchronization example
2024-11-07 15:01:24 +08:00
C.S.M
269322191a Merge branch 'fix/i2c_bus_handle_check' into 'master'
fix(i2c): Add bus handle check so that it will not be panic when there is no free bus

Closes IDFGH-13993 and IDFGH-13963

See merge request espressif/esp-idf!34695
2024-11-07 12:21:33 +08:00
Chen Jichang
8e4ff8bcba feat(mcpwm): support sleep retention 2024-11-07 12:06:31 +08:00
Xu Si Yu
d1e7939940 fix(coex): fix 802.15.4 external coexistence 2024-11-07 11:54:51 +08:00
Marius Vikhammer
9c5dde5536 refactor(panic): refactor and unify cache panic errors 2024-11-07 11:39:40 +08:00
Chen Ji Chang
ef437b7b0d Merge branch 'feat/update_lvgl_in_parlio_tx_example' into 'master'
feat(parlio): adapt rgb_matrix example to lvgl9

See merge request espressif/esp-idf!34612
2024-11-07 11:26:28 +08:00
Zhang Yan Jiao
6fdd380812 Merge branch 'bugfix/fix_tbtt_interval_update_fail' into 'master'
fix(wifi/pm): Fixed the STA tbtt interval update error when AP's beacon interval changed

Closes IDFGH-13875

See merge request espressif/esp-idf!34672
2024-11-07 09:05:04 +08:00
Martin Vychodil
4a444c80ae Merge branch 'fix/littlefs_image_creation_windows' into 'master'
fix(littlefs): Allow LittleFS image generation on Windows + version bump

Closes IDFGH-11805

See merge request espressif/esp-idf!34686
2024-11-07 01:13:40 +08:00
Jan Beran
dbc6be3138 fix(docs): Fix links pointing to esp-idf-kconfig Documentation 2024-11-06 15:51:13 +01:00
Adam Múdry
97e669214c fix(littlefs): Allow LittleFS image generation on Windows + version bump
Closes https://github.com/espressif/esp-idf/issues/12900
2024-11-06 14:08:44 +01:00
Shu Chen
8bd4071f92 Merge branch 'fix/linker_script_check_missing_function' into 'master'
fix(802.15.4): add no inline to some static function

Closes TZ-1266

See merge request espressif/esp-idf!34702
2024-11-06 20:13:32 +08:00
C.S.M
280b3d9e62 fix(i2c): Fix some issue in programming guide,
Closes https://github.com/espressif/esp-idf/issues/14794
2024-11-06 18:48:11 +08:00
C.S.M
0a098f49d4 fix(i2c): Add bus handle check so that it will not be panic when there is no free bus,
Closes https://github.com/espressif/esp-idf/issues/14819
2024-11-06 18:48:11 +08:00
Chen Jichang
87f2080705 feat(parlio): adapt rgb_matrix example to lvgl9 2024-11-06 17:43:05 +08:00
Chen Jichang
0eeb544bd2 fix(mcpwm): fix mcpwm register offset on p4 2024-11-06 17:29:58 +08:00
Mahavir Jain
4c6cda734d Merge branch 'feature/mmu_page_size_from_app_bin' into 'master'
feat(bootloader): add support to use MMU page size from app binary

Closes IDF-8209

See merge request espressif/esp-idf!33989
2024-11-06 17:14:31 +08:00
zhangyanjiao
670d34e363 fix(wifi/pm): Fixed the tbtt interval update error when AP's beacon interval changed
Closes https://github.com/espressif/esp-idf/issues/14720
2024-11-06 16:55:06 +08:00
Shu Chen
b7aecdbbaf Merge branch 'fix/zigbee_gateway_readme_link' into 'master'
fix(zigbee_example): Fix the link in zigbee gateway readme file

See merge request espressif/esp-idf!34698
2024-11-06 16:28:39 +08:00
Aditya Patwardhan
df120ac962 Merge branch 'contrib/github_pr_14734' into 'master'
docs: fix all references to HTTPD_{GET,POST,PUT} (GitHub PR)

Closes IDFGH-13892

See merge request espressif/esp-idf!34418
2024-11-06 16:12:20 +08:00
David Cermak
e8c5992a57 fix(lwip): Document that not all sock operations are thread safe 2024-11-06 08:24:45 +01:00
Island
1f49c9a845 Merge branch 'bugfix/fixed_h2_assert_master_1031' into 'master'
Bugfix/fixed h2 assert master 1031

Closes BLERP-1172

See merge request espressif/esp-idf!34537
2024-11-06 15:06:41 +08:00
zwx
068790baa9 fix(802.15.4): add no inline to some static function 2024-11-06 14:52:46 +08:00
WanqQixiang
9d4a897d47 fix(zigbee_example): Fix the link in zigbee gateway readme file 2024-11-06 14:40:09 +08:00
Jiang Jiang Jian
c8b67235e6 Merge branch 'feature/support_to_query_phy_rf_used_time' into 'master'
feat(phy): support to query phy used time

See merge request espressif/esp-idf!29234
2024-11-06 12:11:22 +08:00
Marius Vikhammer
402fecee17 Merge branch 'feature/lp_spi_example' into 'master'
feat(lp_core): added lp-spi example for lp core

Closes IDF-10287

See merge request espressif/esp-idf!34521
2024-11-06 10:58:19 +08:00
Omar Chebib
50ac90b489 Merge branch 'fix/nmi_not_triggering_on_s3' into 'master'
fix(examples): fix NMI interrupt example to work on ESP32-S3

Closes IDFCI-2475

See merge request espressif/esp-idf!34267
2024-11-06 10:09:57 +08:00
Adam Múdry
b2e0bd9200 Merge branch 'fix/sdmmc_send_acmd22_after_multiple_write_cmd' into 'master'
fix(sdmmc): Send ACMD22 if CMD25 fails

Closes IDF-9630

See merge request espressif/esp-idf!34376
2024-11-06 04:34:06 +08:00
Mahavir Jain
765fe330ea test: add configurable mmu page size test app
Test app to ensure that bootloader and application built with
different flash MMU page size are compatible. This is for the
SoCs that support configurable flash MMU page size.
2024-11-05 20:37:31 +05:30
Mahavir Jain
afa46c06a8 feat(bootloader): add support to use MMU page size from app binary
For the SoCs that support configurable MMU page size, it is possible
that the bootloader and application are built with different MMU page
size configuration. This mismatch is not supported at the moment and
application verification fails (at bootup or during OTA update).

Configuring MMU page size helps to optimize the flash space by having
smaller alignment and padding (secure) requirements. Please note that
the MMU page size is tied with the flash size configuration at the
moment (`ESPTOOLPY_FLASHSIZE_XMB`).

This MR ensures that application verification happens using the MMU page
size configured in its binary header. Thus, bootloader and application
can now have different MMU page sizes and different combinations shall
be supported.
2024-11-05 20:37:18 +05:30
Roland Dobai
72308ca089 Merge branch 'feat/add_activate_debug_information' into 'master'
feat(tools): Imporve activate.py debug information

Closes IDF-11378

See merge request espressif/esp-idf!34534
2024-11-05 21:13:20 +08:00
Marek Fiala
26002e13fc feat(tools): Imporve activate.py debug information 2024-11-05 13:53:00 +01:00
Wan Lei
405327d22a Merge branch 'fix/c61_h2_pmu_icg_csv_update' into 'master'
fix(pmu): c61 and h2 update pmu_icg_mapping.h

See merge request espressif/esp-idf!34370
2024-11-05 20:18:04 +08:00
Shen Meng Jing
67169f8efd Merge branch 'docs/update_cn_translation' into 'master'
docs: Sync CN and EN files

Closes DOC-9182

See merge request espressif/esp-idf!34249
2024-11-05 19:18:36 +08:00
Xu Xiao
0c07ee6baf Merge branch 'feature/twt_add_parameter_to_enable_keep_alive' into 'master'
feat(twt): twt add parameter to enable keep alive

Closes WIFIBUG-927

See merge request espressif/esp-idf!34532
2024-11-05 19:04:55 +08:00
Harshal Patil
d46b23d44b Merge branch 'docs/fix_section_visibility_esp32p4' into 'master'
Fix typo to make a section visible for non-esp32 SPIRAM supported targets

See merge request espressif/esp-idf!34482
2024-11-05 18:37:35 +08:00
shenmengjing
6f86f70f0a docs: Sync CN and EN files 2024-11-05 18:03:42 +08:00
Xu Si Yu
3e4955345a fix(ci): optimize an openthread ci case 2024-11-05 17:26:03 +08:00
liuning
f0701b265d feat(phy): support to query phy used time 2024-11-05 17:18:35 +08:00
Shu Chen
7aaab5a3ff Merge branch 'fix/esp_prov_ipv6_resolve' into 'master'
fix(tools): Fix hostname resolving for IPv6-only host

See merge request espressif/esp-idf!34452
2024-11-05 17:15:16 +08:00
C.S.M
9677a4929f Merge branch 'feat/add_temperature_calib' into 'master'
feat(temperature_sensor): Add temperature sensor calibration support

Closes IDF-5236

See merge request espressif/esp-idf!34634
2024-11-05 16:28:58 +08:00
WanqQixiang
682a66d164 fix(tools/esp_prov): Fix hostname resolving for IPv6-only host 2024-11-05 15:24:23 +08:00
Song Ruo Jing
7e90a41bc9 Merge branch 'refactor/regi2c_mst_clock_enable' into 'master'
refactor(regi2c): analog i2c mst clock should be enabled/disabled per usage

Closes IDF-10492 and IDF-10693

See merge request espressif/esp-idf!32682
2024-11-05 15:15:26 +08:00
C.S.M
0546805fc5 Merge branch 'fix/bod_p4eco2_fix' into 'master'
fix(bod): Remove config for bod on p4 eco1

See merge request espressif/esp-idf!34589
2024-11-05 14:42:15 +08:00
yinqingzhao
34ba72a431 feat(twt): twt add parameter to enable keep alive 2024-11-05 14:12:02 +08:00
morris
e1a3ff1529 Merge branch 'bugfix/wrong_return_type' into 'master'
fix(i2c_lcd): wrong return type for esp_lcd_new_panel_io_i2c

See merge request espressif/esp-idf!34643
2024-11-05 13:44:39 +08:00
harshal.patil
7786cbe2c8 docs(mem_alloc): Fix typo to make a section visible for non-esp32 spiram targets 2024-11-05 10:56:20 +05:30
Harshal Patil
ae51dcc227 Merge branch 'ci/nightly_run_crt_bundle_stress_test' into 'master'
Run https x509 bundle default crt bundle stress test using QEMU

See merge request espressif/esp-idf!34508
2024-11-05 13:19:51 +08:00
Shu Chen
47c8ca5556 Merge branch 'feature/updated-zigbee-examples' into 'master'
feat(zigbee): Upgrade zigbee examples

See merge request espressif/esp-idf!33223
2024-11-05 12:11:26 +08:00
Jiang Jiang Jian
5c3cb06d18 Merge branch 'bugfix/modify_bandwidth_in_ap_records' into 'master'
fix(wifi): modify bandwidth in wifi_ap_record_t

Closes WIFIBUG-910

See merge request espressif/esp-idf!34455
2024-11-05 10:47:11 +08:00
C.S.M
75aea08703 fix(bod): Remove config for bod on p4 v0.x 2024-11-05 10:39:28 +08:00
Adam Múdry
6bf2d91c4d test(sdmmc): Add test_apps test for sdmmc component 2024-11-05 02:36:43 +01:00
Adam Múdry
9386b58e17 fix(sdmmc): Generalize waiting for card idle to a function 2024-11-05 02:36:42 +01:00
Marius Vikhammer
cfe6c45122 feat(lp_core): added lp-spi example for lp core
Added an example of using lp-spi from lp-core to read sensor data
from a BME280 sensor.
2024-11-05 08:18:09 +08:00
Zhang Hai Peng
08f1c3681a Merge branch 'bugfix/fix_ble_build_fail' into 'master'
fix(ble/bluedroid): Fixed BLE build fail when enable dynamic memory and BLE5.0

Closes BT-3862

See merge request espressif/esp-idf!34581
2024-11-05 06:15:38 +08:00
Michael (XIAO Xufeng)
676f5194d5 Merge branch 'fix/sdio_slave_add_pm_lock' into 'master'
fix(sdio_slave): fix issue that auto light sleep can happen SDIO slave enabled

Closes IDF-8476

See merge request espressif/esp-idf!33579
2024-11-05 03:19:33 +08:00
harshal.patil
5cc9931dc7 ci(examples/protocols): Run the https x509 bundle default crt bundle stress test using QEMU 2024-11-04 22:42:37 +05:30
Konstantin Kondrashov
70b652052e feat(efuse): Adds 3 bit for PSRAM_CAP efuse field 2024-11-04 17:27:53 +02:00
morris
2d8053aabf fix(i2c_lcd): wrong return type for esp_lcd_new_panel_io_i2c
when build for C++ project
2024-11-04 21:29:14 +08:00
yinqingzhao
403d44ae68 docs(wifi): add migration guide for types change in wifi 2024-11-04 21:17:37 +08:00
Xu Xiao
e6a97d2c56 Merge branch 'fix/fix_esp32c61_can_not_tx_under_ht40_above' into 'master'
fix(wifi): fix can not tx frame under ht40 above

See merge request espressif/esp-idf!34175
2024-11-04 20:48:38 +08:00
Jiang Jiang Jian
1f47975472 Merge branch 'bugfix/idf-11064' into 'master'
fix some issues on esp32c5 eco1

Closes IDF-11064 and IDF-11066

See merge request espressif/esp-idf!34350
2024-11-04 20:46:01 +08:00
yinqingzhao
93e77a4df6 fix(wifi): modify bandwidth in wifi_ap_record_t 2024-11-04 20:32:34 +08:00
Wu Zheng Hui
c0f3ac4295 Merge branch 'fix/fix_writeback_psram_after_vo2_powerdown' into 'master'
fix(esp_hw_support): fix writeback cache to psram after vo2 powerdown

Closes PM-286

See merge request espressif/esp-idf!34578
2024-11-04 20:03:06 +08:00
C.S.M
e1abef5e9b feat(temperature_sensor): Add temperature sensor calibration support 2024-11-04 18:42:00 +08:00
zhanghaipeng
94d1a4f1c0 fix(ble/bluedroid): Fixed BLE build fail when enable dynamic memory and BLE5.0 2024-11-04 17:41:34 +08:00
C.S.M
3cc9d42695 Merge branch 'fix/jpeg_com_marker' into 'master'
fix(jpeg): Fix the length of com marker

See merge request espressif/esp-idf!34549
2024-11-04 17:03:46 +08:00
Song Ruo Jing
3357fe8b95 Merge branch 'docs/update_uart_events_description' into 'master'
docs: update descriptions for UART events

See merge request espressif/esp-idf!34049
2024-11-04 16:30:20 +08:00
Laukik Hase
5504a596e2 Merge branch 'fix/fetch_image_hdr' into 'master'
fix(esp_system): Correct address used to fetch application image header

See merge request espressif/esp-idf!34375
2024-11-04 16:26:53 +08:00
nick black
6b3ae2822d docs: fix all references to HTTPD_{GET,POST,PUT} 2024-11-04 16:13:07 +08:00
liqigan
ed21c54a64 fix(bt/bluedroid): Fixed AVRCP compatibility issue on absolute volume synchronization 2024-11-04 16:10:30 +08:00
Jiang Jiang Jian
c4bde5dfae Merge branch 'bugfix/fix_crash_issue_in_mesh_tx_task' into 'master'
fix(wifi/mesh): Enlarge the mesh TX task stack

Closes WIFIBUG-906

See merge request espressif/esp-idf!34617
2024-11-04 15:55:34 +08:00
xuxiao
375156918e fix(wifi): fix esp32c61 can not tx frame under ht40 above 2024-11-04 14:23:11 +08:00
xieqinan@espressif.com
a41c2d498e feat(zigbee): Upgrade the Zigbee lib to v1.6 for Zigbee examples
- Optimize the Zigbee light, switch and gateway examples
- Remove the esp_zigbee_rcp example
2024-11-04 14:21:42 +08:00
Song Ruo Jing
2cb35a2955 refactor(regi2c): ana i2c master clock is enabled per request 2024-11-04 12:37:17 +08:00
Song Ruo Jing
92ed77933b refactor(clk): deprecate SOC_RTC_FAST_CLK_SRC_XTAL_DIV 2024-11-04 12:37:17 +08:00
Laukik Hase
5976e391ea fix(esp_system): Correct address used to fetch application image header 2024-11-04 09:58:37 +05:30
Li Shuai
45ea08b955 fix(esp_hw_support): fix the issue of wifi rx packet loss when switchng soc root clock source 2024-11-04 11:19:29 +08:00
Li Shuai
f46b9ed5a6 fix(esp_hw_support): fix the issue of mmu table content loss due to default sd signal 2024-11-04 11:11:36 +08:00
zhangyanjiao
02f6738d22 fix(wifi/mesh): Enlarge the mesh TX task stack 2024-11-04 11:08:56 +08:00
Konstantin Kondrashov
ce6085349f Merge branch 'feature/adds_efuse_adc_calib_data' into 'master'
feat(efuse): Adds efuse ADC calib data for P4 C5 C61

See merge request espressif/esp-idf!33934
2024-11-02 05:56:30 +08:00
Erhan Kurubas
c2acddda7b Merge branch 'fix/sysview_stack_overflow' into 'master'
fix(sysview): reduce isr stack usage to avoid stack guard exception

Closes IDF-11338

See merge request espressif/esp-idf!34604
2024-11-02 01:56:05 +08:00
Konstantin Kondrashov
37b600124f feat(efuse): Adds efuse ADC calib data for ESP32-C61 2024-11-01 23:08:53 +08:00
Konstantin Kondrashov
7397c159cb feat(efuse): Adds efuse ADC calib data for ESP32-C5 2024-11-01 23:08:53 +08:00
Konstantin Kondrashov
5b1891c2fa feat(efuse): Adds efuse ADC calib data for ESP32-P4 2024-11-01 23:08:53 +08:00
Jiang Jiang Jian
a71eb45ca1 Merge branch 'bugfix/set_iv_to_random_for_esptouch_v2' into 'master'
fix(wifi): Support random AES IV in esptouch_v2

Closes WIFI-6688

See merge request espressif/esp-idf!34084
2024-11-01 18:51:18 +08:00
Wang Meng Yang
5e8443a2f6 Merge branch 'bugfix/osi_replace_free' into 'master'
fix(bt/bluedroid): Replace free/malloc with osi_free/malloc

See merge request espressif/esp-idf!34507
2024-11-01 17:40:21 +08:00
Erhan Kurubas
d1e5fd08ff fix(sysview): reduce isr stack usage to avoid stack guard exception 2024-11-01 10:16:06 +01:00
Omar Chebib
569222488e Merge branch 'feature/bootloader_extra_dir' into 'master'
feat(bootloader): add the possibility to specify extra components directories

See merge request espressif/esp-idf!33433
2024-11-01 16:58:01 +08:00
Hong Shu Qing
63fdde6cd4 Merge branch 'bugfix/chip823_pll_low_temp_bug' into 'master'
[H2]Fix cpu switch fail for bbpll cali fail bug in low temp

See merge request espressif/esp-idf!31374
2024-11-01 16:45:57 +08:00
wuzhenghui
48ebf7c715 fix(esp_hw_support): only support power down flash after revison v1.0 on esp32p4 2024-11-01 16:26:12 +08:00
zhangyanjiao
8fb28dcedc fix(wifi): Support AES IV with random value in esptouch v2 2024-11-01 16:23:37 +08:00
morris
e27889a146 Merge branch 'ci/run_gdma_after_reset' into 'master'
fix(gdma): run test cases after reset

See merge request espressif/esp-idf!34572
2024-11-01 16:23:23 +08:00
Peter Dragun
90abcdebf2 Merge branch 'fix/windows_escape_seq' into 'master'
fix: recommend using Windows Terminal in case of issues with escape sequences

Closes IDFGH-13646

See merge request espressif/esp-idf!34516
2024-11-01 16:01:25 +08:00
Shen Meng Jing
d1991b5b46 Merge branch 'docs/translate_isp' into 'master'
Docs/Provide CN translation for isp.rst

Closes DOC-8335

See merge request espressif/esp-idf!32051
2024-11-01 15:36:55 +08:00
Konstantin Kondrashov
1a419e594b Merge branch 'feature/support_primary_subtypes' into 'master'
feat(partition_table): Support primary subtypes partitions

Closes IDF-11330

See merge request espressif/esp-idf!34194
2024-11-01 15:13:31 +08:00
Shu Chen
7bc9393301 Merge branch 'fix/energy_scan_api_para_mismatch' into 'master'
fix(openthread): set channel for energy scan

See merge request espressif/esp-idf!34515
2024-11-01 15:12:41 +08:00
wuzhenghui
feafc84ece fix(esp_hw_support): fix writeback cache to psram after vo2 powerdown 2024-11-01 14:11:40 +08:00
Omar Chebib
729c55b790 docs: changed bootloader extra component to a property in build-system.rst 2024-11-01 13:52:01 +08:00
renpeiying
a49454e352 docs: Update CN translation according to review 2024-11-01 13:52:01 +08:00
Omar Chebib
e33bcaa6d3 feat(bootloader): use idf property to specify extra components directories 2024-11-01 13:52:01 +08:00
renpeiying
a1df6b8185 docs: Update CN translation for api-guides/build-system.rst 2024-11-01 13:52:01 +08:00
Omar Chebib
775c65a6b7 feat(bootloader): add the possibility to specify extra components directories 2024-11-01 13:52:01 +08:00
Shu Chen
a2f3585030 Merge branch 'feat/openthread_dataset_changed_event' into 'master'
feat(openthread): Add dataset changed event and post it in state change callback

See merge request espressif/esp-idf!34543
2024-11-01 10:56:03 +08:00
Wan Lei
90e71bfa48 Merge branch 'fix/twai_io_init_glitch' into 'master'
fix(driver_twai): fixed bus-off when twai_init due to wrong gpio config

Closes IDFGH-13672, IDF-11129, and IDF-9113

See merge request espressif/esp-idf!33929
2024-11-01 10:26:43 +08:00
Jiang Jiang Jian
566721629f Merge branch 'bugfix/fix_association_failed_in_internal_reconnection' into 'master'
fix(wifi): clear pmk in internal reconnection

Closes WIFIBUG-869, WIFIBUG-894, and PM-264

See merge request espressif/esp-idf!34181
2024-11-01 10:17:34 +08:00
Omar Chebib
f6d154e761 fix(examples): fix NMI interrupt example to work on ESP32-S3 2024-11-01 10:17:09 +08:00
Marius Vikhammer
24056620ef Merge branch 'ci/fix_build_rules_system' into 'master'
ci(system): fixed build-test-rules which used ARCH config

See merge request espressif/esp-idf!34585
2024-11-01 10:16:41 +08:00
Marius Vikhammer
0e8a933488 ci(system): fixed build-test-rules which used ARCH config
These variables are not availble when evaluating the rules, resulting
in that the tests were never run.
2024-11-01 09:23:47 +08:00
Song Ruo Jing
50aeec2f97 Merge branch 'bugfix/uart_vfs_read_behavior' into 'master'
fix(uart_vfs): read() now aligned to POSIX defined behavior

Closes IDF-10424 and IDFGH-13218

See merge request espressif/esp-idf!33435
2024-10-31 23:14:07 +08:00
Shu Chen
8ac260a9d7 Merge branch 'feature/alloc_nat64_session_from_psram' into 'master'
feat(openthread): support alloc nat64 session from psram

See merge request espressif/esp-idf!33410
2024-10-31 21:39:08 +08:00
Adam Múdry
2c1bec2c70 fix(sdmmc): Send ACMD22 if CMD25 fails
Send the number of the written write blocks (ACMD22) after
write multiple blocks fails (CMD25)
2024-10-31 14:30:51 +01:00
Xiao Xufeng
ed31c19933 fix(sdio_slave): prevents peripheral power domain being powered off when SDIO slave in use 2024-10-31 21:25:40 +08:00
Xiao Xufeng
df2d09e3e0 feat(sleep_retention): allow drivers taking TOP power lock
Also add a dump function
2024-10-31 21:25:37 +08:00
Fu Hanxi
116c3d6ddb Merge branch 'ci/fix_diff_manifest_sha' into 'master'
ci: use different base commit for merge result pipelines

Closes RDT-989

See merge request espressif/esp-idf!34571
2024-10-31 20:29:56 +08:00
Peter Dragun
8318adb448 fix: recommend using Windows Terminal in case of issues with escape sequences
Closes https://github.com/espressif/esp-idf-monitor/issues/17
2024-10-31 12:56:05 +01:00
Wang Meng Yang
203e5432a9 Merge branch 'fix/set_local_device_name_during_lm_initializaiton' into 'master'
fix(bt): fixed some issues in bt controller on ESP32

Closes BT-3871 and CBI-864

See merge request espressif/esp-idf!34066
2024-10-31 19:39:05 +08:00
Fu Hanxi
a4ef854a2d ci: use different base commit for merge result pipelines 2024-10-31 12:37:01 +01:00
Konstantin Kondrashov
8c4f576f99 feat(partition_table): Support primary subtypes partitions 2024-10-31 13:16:01 +02:00
Chen Ji Chang
f9d6c4df20 Merge branch 'feat/pcnt_sleep_retention' into 'master'
feat(pcnt): add sleep retention init to avoid light sleep when pcnt is working

See merge request espressif/esp-idf!33691
2024-10-31 19:12:49 +08:00
sibeibei
7e5741953d fix(wifi): fix some wifi issues 241031
1. fix cant sleep if reconnect to connected ap
    2. clear pmk in internal reconnection
    3. update connect status for init-->auth
    4. add protection for probe request when wifi band is 5g
2024-10-31 19:03:01 +08:00
WanqQixiang
77656e2046 feat(openthread): Add dataset changed event and post it in state change callback 2024-10-31 19:00:48 +08:00
morris
8cd4091114 fix(gdma): run test cases after reset 2024-10-31 18:32:37 +08:00
Song Ruo Jing
92b4c62d06 fix(uart_vfs): read() now aligned to POSIX defined behavior
- For blocking mode, block until data available
- Return with the bytes available in the file at the time,
  it should not block until reaching the requested size

And read() should not realy return on the newline character
Closes https://github.com/espressif/esp-idf/issues/14155
2024-10-31 17:57:04 +08:00
Shu Chen
7d179ccd3e Merge branch 'pr_14676' into 'master'
feat(openthread): enable openthread coap client for mtd

See merge request espressif/esp-idf!34143
2024-10-31 17:43:12 +08:00
Wang Meng Yang
bb5a53c66c Merge branch 'bugfix/fix_memory_leak_in_sco' into 'master'
fix(bt/bluedroid): Fix memory leak in sco when bluedroid disable

Closes BT-3884

See merge request espressif/esp-idf!34523
2024-10-31 17:40:33 +08:00
Omar Chebib
66f6364bb1 Merge branch 'staging/esp32c61_bootloader_support' into 'master'
fix(bootloader_support): remove temporary notice in build test rule for ESP32-C61

Closes IDF-9260

See merge request espressif/esp-idf!33781
2024-10-31 17:38:58 +08:00
zwx
7a044c0f81 feat(openthread): support alloc nat64 session from psram 2024-10-31 17:38:34 +08:00
xiongweichao
35ef6f5140 fix(bt/bluedroid): Replace free/malloc with osi_free/malloc 2024-10-31 17:14:25 +08:00
Tomas Rezucha
00dcf1a0c0 Merge branch 'docs/usb_host_examples_readme' into 'master'
docs(usb_host): Update usb_host example READMEs for P4

Closes IDFGH-13706 and IDFGH-10950

See merge request espressif/esp-idf!34510
2024-10-31 17:08:10 +08:00
shenmengjing
7cea2a78cc docs: Update CN translation for build-system.rst and freertos.rst 2024-10-31 16:03:19 +08:00
Tomas Rezucha
f7da0175b0 docs(usb_host): Update usb_host example READMEs for P4
Closes https://github.com/espressif/esp-idf/issues/14578
Closes https://github.com/espressif/esp-idf/issues/12142
2024-10-31 09:00:59 +01:00
Wan Lei
dee6ad56c9 Merge branch 'fix/p4_spi_no_dma_polling_cache_fail' into 'master'
fix(driver_spi): fixed p4 no dma polling trans cache sync fail

Closes IDFCI-2455

See merge request espressif/esp-idf!34409
2024-10-31 15:33:59 +08:00
C.S.M
f54ec30f6a fix(jpeg): Fix the length of com marker 2024-10-31 15:16:44 +08:00
Island
92e4b80a65 Merge branch 'feat/support_controller_run_in_flash_only' into 'master'
Feat/support controller run in flash only

Closes BLERP-1164, BLERP-1165, and BLERP-1174

See merge request espressif/esp-idf!33290
2024-10-31 15:15:01 +08:00
wanckl
b64e2ebfc9 feat(twai): support gpio reserve check 2024-10-31 15:07:42 +08:00
wanckl
460233ee3b fix(driver_twai): fixed bus-off when twai_init due to wrong gpio config
Closes https://github.com/espressif/esp-idf/issues/14548
2024-10-31 15:07:42 +08:00
gongyantao
034a35a66f fix(bt): fix some issues in bt controller
1: Store local device name into NVDS when handling hci_wr_local_name_cmd.
2: Set default device name during link manager initialization.
3: Set the QoS value to the minimum value if the calculated QoS is less
   than the minumum.
2024-10-31 14:50:09 +08:00
Island
1acc70f476 Merge branch 'bugfix/fix_ble_aa_zero' into 'master'
fix(bt/ble): Update esp32 libbtdm_app.a (17db8bd)

Closes BLERP-1138

See merge request espressif/esp-idf!34511
2024-10-31 14:15:23 +08:00
wanckl
8f1fa6164a fix(pmu): c61 and h2 update pmu_icg_mapping.h 2024-10-31 13:54:20 +08:00
zwx
61a7ecd145 fix(openthread): set channel for energy scan 2024-10-31 11:57:31 +08:00
Wang Tao
358e140705 Merge branch 'fix/fix_spiram_ignore_issue' into 'master'
fix(wifi): fix spiram ignore issue

Closes IDFCI-2461

See merge request espressif/esp-idf!34496
2024-10-31 11:26:24 +08:00
zwl
dbad6a0ca5 fix(ble): fixed occasional crash issue in low memory scenarios on ESP32-H2 2024-10-31 11:16:17 +08:00
zwl
dabd66e16f fix(ble): fixed occasional crash issue in low memory scenarios on ESP32-C6 2024-10-31 11:14:13 +08:00
Chen Ji Chang
57eddeb36a Merge branch 'feat/mcpwm_dead_time_add_warning' into 'master'
fix(mcpwm): add warning about generator deadtime

Closes IDFGH-13935

See merge request espressif/esp-idf!34425
2024-10-31 10:13:00 +08:00
Omar Chebib
908e1e670a test(bootloader_support): enable analog super wdt reset for the ESP32-C61 2024-10-31 10:11:44 +08:00
Erhan Kurubas
3b36050e5e Merge branch 'fix/sysview_uart_clock_source' into 'master'
fix(sysview): fix lp uart clock source

See merge request espressif/esp-idf!33973
2024-10-30 23:31:37 +08:00
wanckl
a2be2ffe5a fix(driver_spi): fixed p4 no dma polling trans cache sync fail 2024-10-30 20:52:29 +08:00
Kevin (Lao Kaiyao)
d622011a2b Merge branch 'ci/fix_i2s_failed_case_on_c61' into 'master'
ci(i2s): fix i2s failed case on c61

Closes IDFCI-2463, IDFCI-2464, and IDFCI-2465

See merge request espressif/esp-idf!34529
2024-10-30 20:01:24 +08:00
Chen Jichang
dd8c545423 fix(mcpwm): add warning about generator deadtime
Closes https://github.com/espressif/esp-idf/issues/14773
2024-10-30 19:35:04 +08:00
Chen Jichang
ddf6fea6a2 feat(pcnt): add sleep retention init
Currently, due to the lack of sleep callback feature. We only init
sleep module but don't allocate it. Thus the power domain will be
kept during the light sleep. And temporarily disable pcnt sleep
retention support on P4 due to the lack of retention module ID.
2024-10-30 19:34:33 +08:00
Roman Leonov
4685405a3f docs(ext_port): Added maintainers notes for External Port Driver 2024-10-30 18:41:56 +08:00
Tomas Rezucha
1805efb0b2 Merge branch 'feat/dynamic_usb_hal' into 'master'
feat(hal/usb): Make USB-DWC HAL&LL configuration independent

Closes IDF-11437

See merge request espressif/esp-idf!34045
2024-10-30 18:32:32 +08:00
laokaiyao
5ee42e0239 fix(i2s): suplimemt of c61 i2s ll 2024-10-30 18:13:30 +08:00
laokaiyao
059de88f23 feat(i2s): support i2s retention on C61 2024-10-30 18:13:30 +08:00
Zhang Xiao Yan
9b270c4c7d Merge branch 'docs/add_adc_zero_crossing_detection_description_code' into 'master'
docs: Add description and code example for ADC zero-crossing detection

See merge request espressif/esp-idf!34475
2024-10-30 16:40:45 +08:00
C.S.M
65deae1404 Merge branch 'fix/suspend_ci' into 'master'
test(spi_flash): Fix some failure test cases related to spi flash

Closes IDFCI-1955, IDFCI-2023, and IDFCI-2217

See merge request espressif/esp-idf!34498
2024-10-30 16:13:44 +08:00
Shen Meng Jing
e2e4a36577 Merge branch 'docs/update_cn_lf_pt' into 'master'
docs: Update CN translation for libs-framework.rst and partition-table.rst

Closes DOC-9097 and DOC-9116

See merge request espressif/esp-idf!34091
2024-10-30 15:20:05 +08:00
Konstantin Kondrashov
1de0358249 Merge branch 'ci/fix_pytest_otatool_for_c2' into 'master'
fix(examples): Fix pytest_otatool for C2

See merge request espressif/esp-idf!34499
2024-10-30 15:13:02 +08:00
linruihao
ecefb3c7e5 fix(bt/bluedroid): Fix memory leak in sco when bluedroid disable 2024-10-30 15:08:18 +08:00
Kevin (Lao Kaiyao)
06da32f9f2 Merge branch 'ci/fix_i2s_multi_dev_failed_case' into 'master'
ci(i2s): fix i2s_multi_dev failed case

Closes IDFCI-1523 and IDFCI-2010

See merge request espressif/esp-idf!34495
2024-10-30 14:39:42 +08:00
Kevin (Lao Kaiyao)
cb4442d948 Merge branch 'feature/touch_driver_ng_on_s2_s3' into 'master'
feat(touch): touch driver-NG on S2 & S3

Closes IDF-10182

See merge request espressif/esp-idf!34051
2024-10-30 14:28:01 +08:00
Jiang Jiang Jian
ae4c4464b3 Merge branch 'fix/bypass_some_restore_process_if_sleep_rejected' into 'master'
fix(esp_hw_support): skip some wakeup steps if sleep is rejected

See merge request espressif/esp-idf!34138
2024-10-30 14:07:31 +08:00
laokaiyao
4464673ab9 ci(i2s): fix i2s_multi_dev failed case 2024-10-30 13:26:34 +08:00
Linda
29513cfe09 docs: Add description and code example for ADC zero-crossing detection 2024-10-30 11:33:47 +08:00
Marius Vikhammer
af75da0eee Merge branch 'docs/disable_jtag_usb' into 'master'
docs(size): mention disabling console output to reduce binary size

See merge request espressif/esp-idf!34240
2024-10-30 11:16:43 +08:00
wangtao@espressif.com
d74b584427 fix(wifi): fix spiram ignore issue 2024-10-30 10:58:28 +08:00
shenmengjing
a98ff3aea6 docs: Update CN translation for libs-framework.rst and partition-table.rst 2024-10-30 10:49:00 +08:00
Jiang Jiang Jian
653ce935f9 Merge branch 'chip/esp32c5_eco1_support_wifi' into 'master'
feat(wifi): add wifi support for esp32c5 eco1

See merge request espressif/esp-idf!34328
2024-10-30 10:41:47 +08:00
Xu Xiao
81f43866cd Merge branch 'disable_esp32c5_adc_ci_test' into 'master'
fix(ci): disable esp32c5 adc ci test

See merge request espressif/esp-idf!34491
2024-10-30 10:21:00 +08:00
zhiweijian
4b767d03fe feat(bt/controller): Support controller code run in flash only 2024-10-30 10:05:39 +08:00
laokaiyao
c007ec5f17 feat(touch): update doc and example for touch version 2 2024-10-30 10:02:49 +08:00
laokaiyao
1ccb534dc7 feat(touch): support s2 & s3 in touch driver-ng 2024-10-30 10:02:49 +08:00
laokaiyao
6856aec19e refactor(touch): refactor the legacy s2 & s3 touch driver 2024-10-30 10:02:49 +08:00
laokaiyao
1cd9dd5001 refactor(touch): refactor touch low-level for s2 & s3 2024-10-30 10:02:49 +08:00
Linda
10e6101061 docs: update descriptions for UART events 2024-10-30 08:26:23 +08:00
Abhik Roy
e4c92855ee Merge branch 'lwip/dns_clear_cache_fix' into 'master'
fix(lwip):  Fixed active DNS entries before clearing cache

Closes IDFGH-13375

See merge request espressif/esp-idf!33906
2024-10-29 22:36:11 +08:00
Wu Zheng Hui
cceadc4ce8 Merge branch 'fix/fix_ota_slowclock_switching' into 'master'
fix(esp_hw_support): fix rtc slow clock missing after the OTA app changes the slow clock source

Closes IDF-11424

See merge request espressif/esp-idf!34416
2024-10-29 21:49:03 +08:00
zhanghaipeng
8f7672e117 fix(bt/ble): Update esp32 libbtdm_app.a (17db8bd)
- Added a verification step for the Access Address within the CONNECT_IND PDU
2024-10-29 19:25:34 +08:00
Konstantin Kondrashov
949fc7f2c9 fix(examples): Fix pytest_otatool for C2
Test for C2 has to be run with flash_4mb
2024-10-29 11:59:52 +02:00
C.S.M
e8f01afef7 test(spi_flash): Fix some failing test related to spi flash 2024-10-29 17:47:07 +08:00
Jan Beran
1fcf006ec6 docs(kconfiglib): Add Project and Component configuration guide
* Project Configuration Guide: how to configure the project, purpose of
  sdkconfig.defaults, where is the configuration stored...
* Component configuration: how to write Kconfig files, how to ensure
  backward compatibility...

Also, general information about Kconfig and its files was added. Other parts of the
documentation (e.g. build-system) now point to these new guides in order
to provide more info.
2024-10-29 10:31:03 +01:00
Song Ruo Jing
c466082ea6 Merge branch 'feature/add_ledc_output_in_sleep_test' into 'master'
feat(ledc): added a multi device test for testing ledc output in sleep

See merge request espressif/esp-idf!34415
2024-10-29 17:29:01 +08:00
Chen Jian Hua
cd21bdeb15 Merge branch 'bugfix/fix_mem_debug_on_bluedroid' into 'master'
fix(bt/bluedroid): Fixed error when memory debug enabled

Closes BLERP-1158

See merge request espressif/esp-idf!34351
2024-10-29 15:40:33 +08:00
shenmengjing
31b665c628 docs: Provide CN translation for isp.rst 2024-10-29 14:41:35 +08:00
Marius Vikhammer
c0e1ecd310 docs(size): mention disabling console output to reduce binary size 2024-10-29 12:07:12 +08:00
xuxiao
901812c589 fix(ci): disable esp32c5 adc ci test 2024-10-29 12:00:39 +08:00
morris
fc5b392c30 Merge branch 'feat/support_lcd_on_c61' into 'master'
feat(i2c_oled): adapt to LVGL v9

Closes IDFGH-13245

See merge request espressif/esp-idf!33508
2024-10-29 11:49:54 +08:00
Ivan Grokhotkov
1d89e14433 Merge branch 'version/v5.5.0' into 'master'
Update version to v5.5-dev

See merge request espressif/esp-idf!34479
2024-10-28 23:57:02 +08:00
Chen Jichang
21b38e8b97 feat(i2c_oled): adapt i2c_oled example to LVGL v9
This commit simplified the example and removed esp_lvgl_port component.
And adapted example to LVGL v9.

Closes https://github.com/espressif/esp-idf/issues/14179
2024-10-28 19:35:40 +08:00
xuxiao
d092c1ba55 feat(wifi): add wifi support for esp32c5 eco1 2024-10-28 19:19:18 +08:00
wuzhenghui
33d3c60b26 fix(esp_hw_support): skip some wakeup steps if sleep is rejected
1. Skip esp_timer time compensation to avoid introducing errors into rtc_timer
    2. Ignore sleep_time_overhead_out measurements when sleep is rejected
2024-10-28 19:16:32 +08:00
Ivan Grokhotkov
52496491f8 change(ci): update LATEST_GIT_TAG to v5.5-dev 2024-10-28 10:34:21 +01:00
Ivan Grokhotkov
d998d76627 change(version): Update version to v5.5-dev 2024-10-28 10:17:21 +01:00
Song Ruo Jing
7df8467be5 feat(ledc): added a multi device test for testing ledc output in sleep 2024-10-28 16:40:13 +08:00
wuzhenghui
7fdfa6c227 fix(esp_hw_support): disable unused clock sources after rtc clock switching complete 2024-10-28 15:57:26 +08:00
Simon Dean
4a22f982f3 enable openthread coap client for mtd 2024-10-28 10:46:59 +08:00
Erhan Kurubas
000270a4f6 fix(sysview): fix lp uart clock source 2024-10-24 23:49:19 +02:00
Tomas Rezucha
d837cae2b0 feat(hal/usb): Make USB-DWC HAL&LL configuration independent
Previously, we included symbols from soc/usb_dwc_cfg.h and configured
the HAL and LL according to it. Now we get the configuration in runtime
from USB-DWC registers.

Added missing definition for USB FS peripheral on ESP32-P4.
2024-10-24 16:54:20 +02:00
wuzhenghui
3881d4031d fix(esp_hw_support): enable all supported slow clock at pmu_init 2024-10-24 14:22:51 +08:00
Duco Sebel
675653af89 fix(example/system/console): Add 'info' to log_level command description
Closes https://github.com/espressif/esp-idf/pull/14771
2024-10-24 02:39:48 +00:00
Linda
cd8eb11ee7 docs: add a note on required header files for the esp_http_server example 2024-10-23 14:59:05 +08:00
chenjianhua
0abdd20240 fix(bt/bluedroid): Fixed error when memory debug enabled 2024-10-22 11:49:58 +08:00
Cacti4dev
7bfee98996 Update hid_host_example.c
Distinguish was spelled incorrectly
2024-10-16 13:54:43 -07:00
viayie
bdf0821f97 fix(cmake): Prevent overwriting of component properties in output file
While 'component_properties_text'
correctly accumulated properties from all processed components, each
iteration of the loop was overwriting the entire file content.

Move the file(WRITE ...) call outside the loop to ensure all accumulated
component properties are written once, preserving information for all
components.
2024-10-16 14:11:23 +08:00
Abhik Roy
ff25e646fb fix(lwip): Fixed active DNS entries before clearing cache 2024-10-08 22:03:39 +11:00
hongshuqing
f3087c8fb0 fix: fix pll low temp bug 2024-07-08 14:40:51 +08:00
1178 changed files with 45998 additions and 14320 deletions

View File

@@ -1,4 +1,4 @@
[codespell]
skip = build,*.yuv,components/fatfs/src/*,alice.txt,*.rgb,components/wpa_supplicant/*,components/esp_wifi/*,*.pem
ignore-words-list = ser,dout,rsource,fram,inout,shs,ans,aci,unstall,unstalling,hart,wheight,wel,ot,fane,assertIn,registr,oen
ignore-words-list = ser,dout,rsource,fram,inout,shs,ans,aci,unstall,unstalling,hart,wheight,wel,ot,fane,assertIn,registr,oen,parms
write-changes = true

View File

@@ -1,7 +1,7 @@
.build_template:
stage: build
extends:
- .after_script:build:ccache:upload-when-fail
- .after_script:build:ccache-show-stats:upload-failed-job-logs
image: $ESP_ENV_IMAGE
tags:
- build
@@ -12,11 +12,11 @@
IDF_CCACHE_ENABLE: "1"
dependencies: []
.build_cmake_template:
.build_cmake_clang_template:
extends:
- .build_template
- .before_script:build
- .after_script:build:ccache
- .after_script:build:ccache-show-stats
dependencies: # set dependencies to null to avoid missing artifacts issue
needs:
- job: fast_template_app
@@ -34,29 +34,11 @@
- "**/build*/size.json"
expire_in: 1 week
when: always
script:
# CI specific options start from "--parallel-count xxx". could ignore when running locally
- run_cmd python tools/ci/ci_build_apps.py $TEST_DIR -v
-t $IDF_TARGET
--copy-sdkconfig
--parallel-count ${CI_NODE_TOTAL:-1}
--parallel-index ${CI_NODE_INDEX:-1}
--extra-preserve-dirs
examples/bluetooth/esp_ble_mesh/ble_mesh_console
examples/bluetooth/hci/controller_hci_uart_esp32
examples/wifi/iperf
--modified-components ${MR_MODIFIED_COMPONENTS}
--modified-files ${MR_MODIFIED_FILES}
# for detailed documents, please refer to .gitlab/ci/README.md#uploaddownload-artifacts-to-internal-minio-server
- python tools/ci/artifacts_handler.py upload
.build_cmake_clang_template:
extends:
- .build_cmake_template
variables:
IDF_TOOLCHAIN: clang
TEST_BUILD_OPTS_EXTRA: ""
TEST_DIR: tools/test_apps/system/clang_build_test
PYTEST_IGNORE_COLLECT_IMPORT_ERROR: "1"
script:
# CI specific options start from "--parallel-count xxx". could ignore when running locally
- run_cmd python tools/ci/ci_build_apps.py $TEST_DIR -v
@@ -126,7 +108,7 @@ gcc_static_analyzer:
ANALYZING_APP: "examples/get-started/hello_world"
script:
- echo "CONFIG_COMPILER_STATIC_ANALYZER=y" >> ${ANALYZING_APP}/sdkconfig.defaults
- python -m idf_build_apps build -vv -p ${ANALYZING_APP} -t all
- python -m idf_build_apps build -v -p ${ANALYZING_APP} -t all
########################################
# Clang Build Apps Without Tests Cases #
@@ -246,15 +228,16 @@ pytest_build_system_macos:
extends:
- .test_build_system_template
- .before_script:build:macos
- .after_script:build:macos:upload-when-fail
- .after_script:build:macos:upload-failed-job-logs:ccache-show-stats
- .rules:build:macos
tags:
- macos_shell
parallel: 3
variables:
PYENV_VERSION: "3.8"
CI_CCACHE_DISABLE: "1" # ccache: error: Read-only file system
PYENV_VERSION: "3.9"
# CCACHE_DIR: "/cache/idf_ccache". On macOS, you cannot write to this folder due to insufficient permissions.
CCACHE_DIR: "" # ccache will use "$HOME/Library/Caches/ccache".
CCACHE_MAXSIZE: "5G" # To preserve the limited Macbook storage. CCACHE automatically prunes old caches to fit the set limit.
build_docker:
extends:
- .before_script:minimal

View File

@@ -40,7 +40,7 @@ variables:
GIT_FETCH_EXTRA_FLAGS: "--no-recurse-submodules --prune --prune-tags"
# we're using .cache folder for caches
GIT_CLEAN_FLAGS: -ffdx -e .cache/
LATEST_GIT_TAG: v5.4-dev
LATEST_GIT_TAG: v5.5-dev
SUBMODULE_FETCH_TOOL: "tools/ci/ci_fetch_submodule.py"
# by default we will fetch all submodules
@@ -55,9 +55,9 @@ variables:
CHECKOUT_REF_SCRIPT: "$CI_PROJECT_DIR/tools/ci/checkout_project_ref.py"
# Docker images
ESP_ENV_IMAGE: "${CI_DOCKER_REGISTRY}/esp-env-v5.4:1"
ESP_IDF_DOC_ENV_IMAGE: "${CI_DOCKER_REGISTRY}/esp-idf-doc-env-v5.4:1-1"
TARGET_TEST_ENV_IMAGE: "${CI_DOCKER_REGISTRY}/target-test-env-v5.4:1"
ESP_ENV_IMAGE: "${CI_DOCKER_REGISTRY}/esp-env-v5.5:2"
ESP_IDF_DOC_ENV_IMAGE: "${CI_DOCKER_REGISTRY}/esp-idf-doc-env-v5.5:2-1"
TARGET_TEST_ENV_IMAGE: "${CI_DOCKER_REGISTRY}/target-test-env-v5.5:2"
SONARQUBE_SCANNER_IMAGE: "${CI_DOCKER_REGISTRY}/sonarqube-scanner:5"
PRE_COMMIT_IMAGE: "${CI_DOCKER_REGISTRY}/esp-idf-pre-commit:1"
@@ -70,7 +70,7 @@ variables:
CI_PYTHON_CONSTRAINT_BRANCH: ""
# Update the filename for a specific ESP-IDF release. It is used only with CI_PYTHON_CONSTRAINT_BRANCH.
CI_PYTHON_CONSTRAINT_FILE: "espidf.constraints.v5.4.txt"
CI_PYTHON_CONSTRAINT_FILE: "espidf.constraints.v5.5.txt"
# Set this variable to repository name of a Python tool you wish to install and test in the context of ESP-IDF CI.
# Keep the variable empty when not used.
@@ -141,40 +141,48 @@ variables:
export IDF_MIRROR_PREFIX_MAP=
fi
# install latest python packages
# target test jobs
if [[ "${CI_JOB_STAGE}" == "target_test" ]]; then
run_cmd bash install.sh --enable-ci --enable-pytest --enable-test-specific
elif [[ "${CI_JOB_STAGE}" == "build_doc" ]]; then
run_cmd bash install.sh --enable-ci --enable-docs
elif [[ "${CI_JOB_STAGE}" == "build" ]]; then
run_cmd bash install.sh --enable-ci
else
if ! echo "${CI_JOB_NAME}" | egrep ".*pytest.*"; then
if [[ "${CI_JOB_STAGE}" != "target_test" ]]; then
section_start "running_install_sh" "Running install.sh"
if [[ "${CI_JOB_STAGE}" == "build_doc" ]]; then
run_cmd bash install.sh --enable-ci --enable-docs
elif [[ "${CI_JOB_STAGE}" == "build" ]]; then
run_cmd bash install.sh --enable-ci
else
run_cmd bash install.sh --enable-ci --enable-pytest --enable-test-specific
if ! echo "${CI_JOB_NAME}" | egrep ".*pytest.*"; then
run_cmd bash install.sh --enable-ci
else
run_cmd bash install.sh --enable-ci --enable-pytest --enable-test-specific
fi
fi
section_end "running_install_sh"
else
section_start "install_python_env" "Install Python environment"
run_cmd python tools/idf_tools.py install-python-env --features ci,pytest,test-specific
section_end "install_python_env"
fi
# Install esp-clang if necessary
if [[ ! -z "$INSTALL_EXTRA_TOOLS" ]]; then
section_start "installing_optional_tools" "Install optional tools ${INSTALL_EXTRA_TOOLS}"
$IDF_PATH/tools/idf_tools.py --non-interactive install $INSTALL_EXTRA_TOOLS
section_end "installing_optional_tools"
fi
# Install esp-clang if necessary (esp-clang is separately installed)
if [[ "$IDF_TOOLCHAIN" == "clang" && -z "$CI_CLANG_DISTRO_URL" ]]; then
$IDF_PATH/tools/idf_tools.py --non-interactive install esp-clang
fi
# Install QEMU if necessary
if [[ ! -z "$INSTALL_QEMU" ]]; then
$IDF_PATH/tools/idf_tools.py --non-interactive install qemu-xtensa qemu-riscv32
if [[ "${CI_JOB_STAGE}" == "target_test" ]]; then
section_start "IDF_SKIP_TOOLS_CHECK" "Skip required tools check"
export IDF_SKIP_TOOLS_CHECK=1
section_end "IDF_SKIP_TOOLS_CHECK"
fi
# Since the version 3.21 CMake passes source files and include dirs to ninja using absolute paths.
# Needed for pytest junit reports.
$IDF_PATH/tools/idf_tools.py --non-interactive install cmake
section_start "source_export" "Source export.sh"
source ./export.sh
section_end "source_export"
# Custom clang toolchain
if [[ ! -z "$CI_CLANG_DISTRO_URL" ]]; then
if [[ "$IDF_TOOLCHAIN" == "clang" && ! -z "$CI_CLANG_DISTRO_URL" ]]; then
echo "Using custom clang from ${CI_CLANG_DISTRO_URL}"
wget $CI_CLANG_DISTRO_URL
ARCH_NAME=$(basename $CI_CLANG_DISTRO_URL)
@@ -198,6 +206,8 @@ variables:
rm -rf ${CI_PYTHON_TOOL_REPO}
fi
info "setup tools and python venv done"
.show_ccache_statistics: &show_ccache_statistics |
# Show ccache statistics if enabled globally
test "$CI_CCACHE_STATS" == 1 && test -n "$(which ccache)" && ccache --show-stats -vv || true
@@ -222,18 +232,20 @@ variables:
- export IDF_TOOLS_PATH="${HOME}/.espressif_runner_${CI_RUNNER_ID}_${CI_CONCURRENT_ID}"
# remove idf-env.json, since it may contains enabled "features"
- rm -f $IDF_TOOLS_PATH/idf-env.json
- $IDF_PATH/tools/idf_tools.py --non-interactive install cmake ninja
# This adds tools (compilers) and the version-specific Python environment to PATH
- *setup_tools_and_idf_python_venv
- fetch_submodules
variables:
INSTALL_EXTRA_TOOLS: cmake ninja
.after_script:build:macos:upload-when-fail:
.after_script:build:macos:upload-failed-job-logs:ccache-show-stats:
after_script:
# macos is running shell executor, which means it would use
# the system installed /usr/local/bin/python3 by default.
# Ensure pyenv and PYENV_VERSION installed
- eval "$(pyenv init -)"
- *upload_failed_job_log_artifacts
- *show_ccache_statistics
.before_script:build:
before_script:
@@ -244,11 +256,11 @@ variables:
- export EXTRA_CFLAGS=${PEDANTIC_CFLAGS}
- export EXTRA_CXXFLAGS=${PEDANTIC_CXXFLAGS}
.after_script:build:ccache:
.after_script:build:ccache-show-stats:
after_script:
- *show_ccache_statistics
.after_script:build:ccache:upload-when-fail:
.after_script:build:ccache-show-stats:upload-failed-job-logs:
after_script:
- *show_ccache_statistics
- *upload_failed_job_log_artifacts
@@ -307,26 +319,32 @@ variables:
- *git_init
- *git_fetch_from_mirror_url_if_exists
- |
# Store the diff output in a temporary file
TEMP_FILE=$(mktemp)
# merged results pipelines, by default
if [[ -n $CI_MERGE_REQUEST_SOURCE_BRANCH_SHA ]]; then
git fetch origin $CI_MERGE_REQUEST_DIFF_BASE_SHA --depth=1 ${GIT_FETCH_EXTRA_FLAGS}
git fetch origin $CI_MERGE_REQUEST_SOURCE_BRANCH_SHA --depth=1 ${GIT_FETCH_EXTRA_FLAGS}
export GIT_DIFF_OUTPUT=$(git diff --name-only $CI_MERGE_REQUEST_DIFF_BASE_SHA $CI_MERGE_REQUEST_SOURCE_BRANCH_SHA)
git diff --name-only $CI_MERGE_REQUEST_DIFF_BASE_SHA $CI_MERGE_REQUEST_SOURCE_BRANCH_SHA > "$TEMP_FILE"
GIT_DIFF_OUTPUT=$(cat "$TEMP_FILE")
git fetch origin $CI_COMMIT_SHA --depth=1 ${GIT_FETCH_EXTRA_FLAGS}
# merge request pipelines, when the mr got conflicts
elif [[ -n $CI_MERGE_REQUEST_DIFF_BASE_SHA ]]; then
git fetch origin $CI_MERGE_REQUEST_DIFF_BASE_SHA --depth=1 ${GIT_FETCH_EXTRA_FLAGS}
git fetch origin $CI_COMMIT_SHA --depth=1 ${GIT_FETCH_EXTRA_FLAGS}
export GIT_DIFF_OUTPUT=$(git diff --name-only $CI_MERGE_REQUEST_DIFF_BASE_SHA $CI_COMMIT_SHA)
git diff --name-only $CI_MERGE_REQUEST_DIFF_BASE_SHA $CI_COMMIT_SHA > "$TEMP_FILE"
GIT_DIFF_OUTPUT=$(cat "$TEMP_FILE")
# other pipelines, like the protected branches pipelines
elif [[ "$CI_COMMIT_BEFORE_SHA" != "0000000000000000000000000000000000000000" ]]; then
git fetch origin $CI_COMMIT_BEFORE_SHA --depth=1 ${GIT_FETCH_EXTRA_FLAGS}
git fetch origin $CI_COMMIT_SHA --depth=1 ${GIT_FETCH_EXTRA_FLAGS}
export GIT_DIFF_OUTPUT=$(git diff --name-only $CI_COMMIT_BEFORE_SHA $CI_COMMIT_SHA)
git diff --name-only $CI_COMMIT_BEFORE_SHA $CI_COMMIT_SHA > "$TEMP_FILE"
GIT_DIFF_OUTPUT=$(cat "$TEMP_FILE")
else
# pipeline source could be web, scheduler, etc.
git fetch origin $CI_COMMIT_SHA --depth=2 ${GIT_FETCH_EXTRA_FLAGS}
export GIT_DIFF_OUTPUT=$(git diff --name-only $CI_COMMIT_SHA~1 $CI_COMMIT_SHA)
git diff --name-only $CI_COMMIT_SHA~1 $CI_COMMIT_SHA > "$TEMP_FILE"
GIT_DIFF_OUTPUT=$(cat "$TEMP_FILE")
fi
- *git_checkout_ci_commit_sha
- *common-before_scripts

View File

@@ -195,7 +195,7 @@ test_tools:
junit: ${IDF_PATH}/XUNIT_*.xml
variables:
LC_ALL: C.UTF-8
INSTALL_QEMU: 1 # for test_idf_qemu.py
INSTALL_EXTRA_TOOLS: "qemu-xtensa qemu-riscv32" # for test_idf_qemu.py
script:
- stat=0
- cd ${IDF_PATH}/tools/ci/test_autocomplete
@@ -282,9 +282,10 @@ test_pytest_qemu:
junit: XUNIT_RESULT.xml
parallel:
matrix:
- IDF_TARGET: [esp32, esp32c3]
variables:
INSTALL_QEMU: 1
- IDF_TARGET: "esp32"
INSTALL_EXTRA_TOOLS: "qemu-xtensa"
- IDF_TARGET: "esp32c3"
INSTALL_EXTRA_TOOLS: "qemu-riscv32"
script:
- run_cmd python tools/ci/ci_build_apps.py . -v
--target $IDF_TARGET
@@ -346,9 +347,10 @@ test_pytest_macos:
reports:
junit: XUNIT_RESULT.xml
variables:
PYENV_VERSION: "3.9"
PYTEST_IGNORE_COLLECT_IMPORT_ERROR: "1"
script:
- run_cmd python tools/ci/ci_build_apps.py components examples tools/test_apps -vv
- run_cmd python tools/ci/ci_build_apps.py components examples tools/test_apps -v
--target linux
--pytest-apps
-m \"host_test and macos_shell\"

View File

@@ -183,12 +183,24 @@ baseline_manifest_sha:
tags: [fast_run, shiny]
script:
- |
if [ -n "$CI_MERGE_REQUEST_DIFF_BASE_SHA" ]; then
# merged results pipelines, by default
# diff between target-branch-head and merged-result-head
if [ -n "$CI_MERGE_REQUEST_TARGET_BRANCH_SHA" ]; then
git fetch origin $CI_MERGE_REQUEST_TARGET_BRANCH_SHA --depth=1
git checkout FETCH_HEAD
idf-build-apps dump-manifest-sha \
--manifest-files $(find . -name ".build-test-rules.yml" | xargs) \
--output .manifest_sha
# merge request pipelines, when the mr got conflicts
# diff between diff-base-sha and merge-request-head
elif [ -n "$CI_MERGE_REQUEST_DIFF_BASE_SHA" ]; then
git fetch origin $CI_MERGE_REQUEST_DIFF_BASE_SHA --depth=1
git checkout FETCH_HEAD
idf-build-apps dump-manifest-sha \
--manifest-files $(find . -name ".build-test-rules.yml" | xargs) \
--output .manifest_sha
# other pipelines, like the protected branches pipelines
# not triggered in this job
fi
artifacts:
paths:

View File

@@ -136,6 +136,14 @@ mainmenu "Espressif IoT Development Framework Configuration"
select FREERTOS_UNICORE
select IDF_TARGET_ARCH_RISCV
config IDF_TARGET_ESP32H21
bool
default "y" if IDF_TARGET="esp32h21"
select FREERTOS_UNICORE
select IDF_TARGET_ARCH_RISCV
select IDF_ENV_FPGA
select IDF_ENV_BRINGUP
config IDF_TARGET_LINUX
bool
default "y" if IDF_TARGET="linux"
@@ -152,6 +160,7 @@ mainmenu "Espressif IoT Development Framework Configuration"
default 0x0012 if IDF_TARGET_ESP32P4
default 0x0017 if IDF_TARGET_ESP32C5
default 0x0014 if IDF_TARGET_ESP32C61
default 0x0019 if IDF_TARGET_ESP32H21
default 0xFFFF

View File

@@ -121,16 +121,3 @@ if(CONFIG_APPTRACE_GCOV_ENABLE)
else()
target_link_libraries(${COMPONENT_LIB} INTERFACE $<TARGET_FILE:${app_trace}> c)
endif()
# This function adds a dependency on the given component if the component is included into the build.
function(maybe_add_component component_name)
idf_build_get_property(components BUILD_COMPONENTS)
if(${component_name} IN_LIST components)
idf_component_get_property(lib_name ${component_name} COMPONENT_LIB)
target_link_libraries(${COMPONENT_LIB} PUBLIC ${lib_name})
endif()
endfunction()
if(CONFIG_APPTRACE_DEST_UART0 OR CONFIG_APPTRACE_DEST_UART1 OR CONFIG_APPTRACE_DEST_UART2)
maybe_add_component(driver)
endif()

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -218,6 +218,13 @@ static esp_err_t esp_apptrace_uart_init(esp_apptrace_uart_data_t *hw_data)
hw_data->message_buff_overflow = false;
hw_data->circular_buff_overflow = false;
assert((hw_data->port_num <= SOC_UART_NUM) && "Not possible to configure UART. Please check selected UART port");
int source_clk = UART_SCLK_DEFAULT;
#if SOC_UART_LP_NUM > 0
if (hw_data->port_num >= SOC_UART_HP_NUM)
source_clk = LP_UART_SCLK_DEFAULT;
#endif
const uart_config_t uart_config = {
.baud_rate = CONFIG_APPTRACE_UART_BAUDRATE,
@@ -225,7 +232,7 @@ static esp_err_t esp_apptrace_uart_init(esp_apptrace_uart_data_t *hw_data)
.parity = UART_PARITY_DISABLE,
.stop_bits = UART_STOP_BITS_1,
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
.source_clk = UART_SCLK_DEFAULT,
.source_clk = source_clk,
};
ESP_LOGI(TAG, "UART baud rate: %i", CONFIG_APPTRACE_UART_BAUDRATE);
// We won't use a buffer for sending data.

View File

@@ -3,7 +3,7 @@
*
* SPDX-License-Identifier: BSD-1-Clause
*
* SPDX-FileContributor: 2017-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileContributor: 2017-2024 Espressif Systems (Shanghai) CO LTD
*/
/*********************************************************************
* SEGGER Microcontroller GmbH *
@@ -58,6 +58,7 @@ File : SEGGER_SYSVIEW_Config_FreeRTOS.c
Purpose : Sample setup configuration of SystemView with FreeRTOS.
Revision: $Rev: 7745 $
*/
#include <string.h>
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "SEGGER_SYSVIEW.h"
@@ -156,15 +157,16 @@ static esp_apptrace_lock_t s_sys_view_lock = {.mux = portMUX_INITIALIZER_UNLOCKE
* Sends SystemView description strings.
*/
static void _cbSendSystemDesc(void) {
char irq_str[32];
char irq_str[32] = "I#";
SEGGER_SYSVIEW_SendSysDesc("N="SYSVIEW_APP_NAME",D="SYSVIEW_DEVICE_NAME",C="SYSVIEW_CORE_NAME",O=FreeRTOS");
snprintf(irq_str, sizeof(irq_str), "I#%d=SysTick", SYSTICK_INTR_ID);
strcat(itoa(SYSTICK_INTR_ID, irq_str + 2, 10), "=SysTick");
SEGGER_SYSVIEW_SendSysDesc(irq_str);
size_t isr_count = sizeof(esp_isr_names)/sizeof(esp_isr_names[0]);
for (size_t i = 0; i < isr_count; ++i) {
if (esp_isr_names[i] == NULL || (ETS_INTERNAL_INTR_SOURCE_OFF + i) == SYSTICK_INTR_ID)
continue;
snprintf(irq_str, sizeof(irq_str), "I#%d=%s", ETS_INTERNAL_INTR_SOURCE_OFF + i, esp_isr_names[i]);
strcat(itoa(ETS_INTERNAL_INTR_SOURCE_OFF + i, irq_str + 2, 10), "=");
strncat(irq_str, esp_isr_names[i], sizeof(irq_str) - strlen(irq_str) - 1);
SEGGER_SYSVIEW_SendSysDesc(irq_str);
}
}

View File

@@ -31,13 +31,19 @@
#include "esp_attr.h"
#include "esp_bootloader_desc.h"
#include "esp_flash.h"
#include "esp_flash_internal.h"
#define SUB_TYPE_ID(i) (i & 0x0F)
#define ALIGN_UP(num, align) (((num) + ((align) - 1)) & ~((align) - 1))
/* Partial_data is word aligned so no reallocation is necessary for encrypted flash write */
typedef struct ota_ops_entry_ {
uint32_t handle;
const esp_partition_t *part;
struct {
const esp_partition_t *staging; /*!< New image will be downloaded in this staging partition. */
const esp_partition_t *final; /*!< Final destination partition which is intended to be updated. Its type/subtype shall be used for verification. */
bool finalize_with_copy; /*!< Flag to copy the image from staging partition to the final partition at the end of OTA update */
} partition;
bool need_erase;
uint32_t wrote_size;
uint8_t partial_bytes;
@@ -52,6 +58,8 @@ static uint32_t s_ota_ops_last_handle = 0;
const static char *TAG = "esp_ota_ops";
static ota_ops_entry_t *get_ota_ops_entry(esp_ota_handle_t handle);
/* Return true if this is an OTA app partition */
static bool is_ota_partition(const esp_partition_t *p)
{
@@ -114,8 +122,6 @@ static esp_ota_img_states_t set_new_state_otadata(void)
esp_err_t esp_ota_begin(const esp_partition_t *partition, size_t image_size, esp_ota_handle_t *out_handle)
{
ota_ops_entry_t *new_entry;
esp_err_t ret = ESP_OK;
if ((partition == NULL) || (out_handle == NULL)) {
return ESP_ERR_INVALID_ARG;
}
@@ -125,36 +131,26 @@ esp_err_t esp_ota_begin(const esp_partition_t *partition, size_t image_size, esp
return ESP_ERR_NOT_FOUND;
}
if (!is_ota_partition(partition)) {
return ESP_ERR_INVALID_ARG;
}
if (partition->type == ESP_PARTITION_TYPE_APP) {
// The staging partition cannot be of type Factory, but the final partition can be.
if (!is_ota_partition(partition)) {
return ESP_ERR_INVALID_ARG;
}
const esp_partition_t* running_partition = esp_ota_get_running_partition();
if (partition == running_partition) {
return ESP_ERR_OTA_PARTITION_CONFLICT;
}
const esp_partition_t* running_partition = esp_ota_get_running_partition();
if (partition == running_partition) {
return ESP_ERR_OTA_PARTITION_CONFLICT;
}
#ifdef CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE
esp_ota_img_states_t ota_state_running_part;
if (esp_ota_get_state_partition(running_partition, &ota_state_running_part) == ESP_OK) {
if (ota_state_running_part == ESP_OTA_IMG_PENDING_VERIFY) {
ESP_LOGE(TAG, "Running app has not confirmed state (ESP_OTA_IMG_PENDING_VERIFY)");
return ESP_ERR_OTA_ROLLBACK_INVALID_STATE;
esp_ota_img_states_t ota_state_running_part;
if (esp_ota_get_state_partition(running_partition, &ota_state_running_part) == ESP_OK) {
if (ota_state_running_part == ESP_OTA_IMG_PENDING_VERIFY) {
ESP_LOGE(TAG, "Running app has not confirmed state (ESP_OTA_IMG_PENDING_VERIFY)");
return ESP_ERR_OTA_ROLLBACK_INVALID_STATE;
}
}
}
#endif
if (image_size != OTA_WITH_SEQUENTIAL_WRITES) {
// If input image size is 0 or OTA_SIZE_UNKNOWN, erase entire partition
if ((image_size == 0) || (image_size == OTA_SIZE_UNKNOWN)) {
ret = esp_partition_erase_range(partition, 0, partition->size);
} else {
const int aligned_erase_size = (image_size + partition->erase_size - 1) & ~(partition->erase_size - 1);
ret = esp_partition_erase_range(partition, 0, aligned_erase_size);
}
if (ret != ESP_OK) {
return ret;
}
}
new_entry = (ota_ops_entry_t *) calloc(1, sizeof(ota_ops_entry_t));
@@ -164,10 +160,60 @@ esp_err_t esp_ota_begin(const esp_partition_t *partition, size_t image_size, esp
LIST_INSERT_HEAD(&s_ota_ops_entries_head, new_entry, entries);
new_entry->part = partition;
new_entry->partition.staging = partition;
new_entry->partition.final = partition;
new_entry->partition.finalize_with_copy = false;
new_entry->handle = ++s_ota_ops_last_handle;
new_entry->need_erase = (image_size == OTA_WITH_SEQUENTIAL_WRITES);
*out_handle = new_entry->handle;
if (partition->type == ESP_PARTITION_TYPE_BOOTLOADER) {
esp_image_bootloader_offset_set(partition->address);
}
if (partition->type == ESP_PARTITION_TYPE_BOOTLOADER || partition->type == ESP_PARTITION_TYPE_PARTITION_TABLE) {
esp_flash_set_dangerous_write_protection(esp_flash_default_chip, false);
}
if (image_size != OTA_WITH_SEQUENTIAL_WRITES) {
// If input image size is 0 or OTA_SIZE_UNKNOWN, erase entire partition
size_t erase_size;
if ((image_size == 0) || (image_size == OTA_SIZE_UNKNOWN)) {
erase_size = partition->size;
} else {
erase_size = ALIGN_UP(image_size, partition->erase_size);
}
return esp_partition_erase_range(partition, 0, erase_size);
}
return ESP_OK;
}
esp_err_t esp_ota_set_final_partition(esp_ota_handle_t handle, const esp_partition_t *final, bool finalize_with_copy)
{
ota_ops_entry_t *it = get_ota_ops_entry(handle);
if (final == NULL) {
return ESP_ERR_INVALID_ARG;
}
if (it == NULL) {
return ESP_ERR_NOT_FOUND;
}
if (it->wrote_size != 0) {
return ESP_ERR_INVALID_STATE;
}
if (it->partition.staging != final) {
const esp_partition_t* final_partition = esp_partition_verify(final);
if (final_partition == NULL) {
return ESP_ERR_NOT_FOUND;
}
ESP_LOGI(TAG,"Staging partition - <%s>. Final partition - <%s>.", it->partition.staging->label, final_partition->label);
it->partition.final = final_partition;
it->partition.finalize_with_copy = finalize_with_copy;
if (final_partition->type == ESP_PARTITION_TYPE_BOOTLOADER) {
esp_image_bootloader_offset_set(it->partition.staging->address);
}
if (final_partition->type == ESP_PARTITION_TYPE_BOOTLOADER || final_partition->type == ESP_PARTITION_TYPE_PARTITION_TABLE) {
esp_flash_set_dangerous_write_protection(esp_flash_default_chip, false);
}
}
return ESP_OK;
}
@@ -192,23 +238,33 @@ esp_err_t esp_ota_write(esp_ota_handle_t handle, const void *data, size_t size)
if (it->handle == handle) {
if (it->need_erase) {
// must erase the partition before writing to it
uint32_t first_sector = it->wrote_size / it->part->erase_size; // first affected sector
uint32_t last_sector = (it->wrote_size + size - 1) / it->part->erase_size; // last affected sector
uint32_t first_sector = it->wrote_size / it->partition.staging->erase_size; // first affected sector
uint32_t last_sector = (it->wrote_size + size - 1) / it->partition.staging->erase_size; // last affected sector
ret = ESP_OK;
if ((it->wrote_size % it->part->erase_size) == 0) {
ret = esp_partition_erase_range(it->part, it->wrote_size, ((last_sector - first_sector) + 1) * it->part->erase_size);
if ((it->wrote_size % it->partition.staging->erase_size) == 0) {
ret = esp_partition_erase_range(it->partition.staging, it->wrote_size, ((last_sector - first_sector) + 1) * it->partition.staging->erase_size);
} else if (first_sector != last_sector) {
ret = esp_partition_erase_range(it->part, (first_sector + 1) * it->part->erase_size, (last_sector - first_sector) * it->part->erase_size);
ret = esp_partition_erase_range(it->partition.staging, (first_sector + 1) * it->partition.staging->erase_size, (last_sector - first_sector) * it->partition.staging->erase_size);
}
if (ret != ESP_OK) {
return ret;
}
}
if (it->wrote_size == 0 && it->partial_bytes == 0 && size > 0 && data_bytes[0] != ESP_IMAGE_HEADER_MAGIC) {
ESP_LOGE(TAG, "OTA image has invalid magic byte (expected 0xE9, saw 0x%02x)", data_bytes[0]);
return ESP_ERR_OTA_VALIDATE_FAILED;
if (it->wrote_size == 0 && it->partial_bytes == 0 && size > 0) {
if (it->partition.final->type == ESP_PARTITION_TYPE_APP || it->partition.final->type == ESP_PARTITION_TYPE_BOOTLOADER) {
if (data_bytes[0] != ESP_IMAGE_HEADER_MAGIC) {
ESP_LOGE(TAG, "OTA image has invalid magic byte (expected 0xE9, saw 0x%02x)", data_bytes[0]);
return ESP_ERR_OTA_VALIDATE_FAILED;
}
} else if (it->partition.final->type == ESP_PARTITION_TYPE_PARTITION_TABLE) {
if (*(uint16_t*)data_bytes != (uint16_t)ESP_PARTITION_MAGIC) {
ESP_LOGE(TAG, "Partition table image has invalid magic word (expected 0x50AA, saw 0x%04x)", *(uint16_t*)data_bytes);
return ESP_ERR_OTA_VALIDATE_FAILED;
}
}
}
if (esp_flash_encryption_enabled()) {
@@ -224,7 +280,7 @@ esp_err_t esp_ota_write(esp_ota_handle_t handle, const void *data, size_t size)
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);
ret = esp_partition_write(it->partition.staging, it->wrote_size, it->partial_data, 16);
if (ret != ESP_OK) {
return ret;
}
@@ -243,7 +299,7 @@ esp_err_t esp_ota_write(esp_ota_handle_t handle, const void *data, size_t size)
}
}
ret = esp_partition_write(it->part, it->wrote_size, data_bytes, size);
ret = esp_partition_write(it->partition.staging, it->wrote_size, data_bytes, size);
if(ret == ESP_OK){
it->wrote_size += size;
}
@@ -280,7 +336,7 @@ esp_err_t esp_ota_write_with_offset(esp_ota_handle_t handle, const void *data, s
ESP_LOGE(TAG, "Size should be 16byte aligned for flash encryption case");
return ESP_ERR_INVALID_ARG;
}
ret = esp_partition_write(it->part, offset, data_bytes, size);
ret = esp_partition_write(it->partition.staging, offset, data_bytes, size);
if (ret == ESP_OK) {
it->wrote_size += size;
}
@@ -316,6 +372,34 @@ esp_err_t esp_ota_abort(esp_ota_handle_t handle)
return ESP_OK;
}
static esp_err_t ota_verify_partition(ota_ops_entry_t *ota_ops)
{
esp_err_t ret = ESP_OK;
if (ota_ops->partition.final->type == ESP_PARTITION_TYPE_APP || ota_ops->partition.final->type == ESP_PARTITION_TYPE_BOOTLOADER) {
esp_image_metadata_t data;
const esp_partition_pos_t part_pos = {
.offset = ota_ops->partition.staging->address,
.size = ota_ops->partition.staging->size,
};
if (esp_image_verify(ESP_IMAGE_VERIFY, &part_pos, &data) != ESP_OK) {
return ESP_ERR_OTA_VALIDATE_FAILED;
}
} else if (ota_ops->partition.final->type == ESP_PARTITION_TYPE_PARTITION_TABLE) {
const esp_partition_info_t *partition_table = NULL;
esp_partition_mmap_handle_t partition_table_map;
ret = esp_partition_mmap(ota_ops->partition.staging, 0, ESP_PARTITION_TABLE_MAX_LEN, ESP_PARTITION_MMAP_DATA, (const void**)&partition_table, &partition_table_map);
if (ret == ESP_OK) {
int num_partitions;
if (esp_partition_table_verify(partition_table, true, &num_partitions) != ESP_OK) {
esp_partition_munmap(partition_table_map);
return ESP_ERR_OTA_VALIDATE_FAILED;
}
esp_partition_munmap(partition_table_map);
}
}
return ret;
}
esp_err_t esp_ota_end(esp_ota_handle_t handle)
{
ota_ops_entry_t *it = get_ota_ops_entry(handle);
@@ -335,7 +419,7 @@ esp_err_t esp_ota_end(esp_ota_handle_t handle)
if (it->partial_bytes > 0) {
/* Write out last 16 bytes, if necessary */
ret = esp_partition_write(it->part, it->wrote_size, it->partial_data, 16);
ret = esp_partition_write(it->partition.staging, it->wrote_size, it->partial_data, 16);
if (ret != ESP_OK) {
ret = ESP_ERR_INVALID_STATE;
goto cleanup;
@@ -344,18 +428,21 @@ esp_err_t esp_ota_end(esp_ota_handle_t handle)
it->partial_bytes = 0;
}
esp_image_metadata_t data;
const esp_partition_pos_t part_pos = {
.offset = it->part->address,
.size = it->part->size,
};
if (esp_image_verify(ESP_IMAGE_VERIFY, &part_pos, &data) != ESP_OK) {
ret = ESP_ERR_OTA_VALIDATE_FAILED;
goto cleanup;
ret = ota_verify_partition(it);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "New image failed verification");
} else {
if (it->partition.finalize_with_copy) {
ESP_LOGI(TAG, "Copy from <%s> staging partition to <%s>...", it->partition.staging->label, it->partition.final->label);
ret = esp_partition_copy(it->partition.final, 0, it->partition.staging, 0, it->partition.final->size);
}
}
cleanup:
if (it->partition.final->type == ESP_PARTITION_TYPE_BOOTLOADER) {
// In esp_ota_begin, bootloader offset was updated, here we return it to default.
esp_image_bootloader_offset_set(ESP_PRIMARY_BOOTLOADER_OFFSET);
}
LIST_REMOVE(it, entries);
free(it);
return ret;

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -82,7 +82,11 @@ int esp_ota_get_app_elf_sha256(char* dst, size_t size) __attribute__((deprecated
* it will lead to the ESP_ERR_OTA_ROLLBACK_INVALID_STATE error. Confirm the running app before to run download a new app,
* use esp_ota_mark_app_valid_cancel_rollback() function for it (this should be done as early as possible when you first download a new application).
*
* @param partition Pointer to info for partition which will receive the OTA update. Required.
* Note: Rollback is applicable only for app type partitions.
*
* @param partition Pointer to info for partition which will receive the OTA update. Required.
* This is considered as the staging partition (where OTA is downloaded), be default this also considered as the final partition which supposed to be updated.
* The final partition can be overwritten using esp_ota_set_final_partition() after calling esp_ota_begin() to relocate contents to the final destination partition.
* @param image_size Size of new OTA app image. Partition will be erased in order to receive this size of image. If 0 or OTA_SIZE_UNKNOWN, the entire partition is erased.
* @param out_handle On success, returns a handle which should be used for subsequent esp_ota_write() and esp_ota_end() calls.
@@ -99,6 +103,31 @@ int esp_ota_get_app_elf_sha256(char* dst, size_t size) __attribute__((deprecated
*/
esp_err_t esp_ota_begin(const esp_partition_t* partition, size_t image_size, esp_ota_handle_t* out_handle);
/**
* @brief Set the final destination partition for OTA update
*
* This function configures the specified final partition as the destination for the OTA update.
* It also allows setting a flag to indicate if the image should be copied from the staging
* partition to the final partition after the OTA update completes. Otherwise, copying will need
* to be handled by custom code using esp_partition_copy().
*
* @note This can be called after esp_ota_begin() and before the OTA update has started (before esp_ota_write()).
*
* @param handle OTA update handle obtained from esp_ota_begin().
* @param final Pointer to the final destination partition where the new image will be verified and potentially finalized.
* This partition must not be NULL.
* @param finalize_with_copy Boolean flag indicating if the downloaded image should be copied
* from the staging partition to the final partition upon completion.
* Set to False if you intend to perform the final copy process manually later.
*
* @return
* - ESP_OK: final destination partition set successfully.
* - ESP_ERR_INVALID_STATE: Once the OTA update has started, changing the final destination partition is prohibited.
* - ESP_ERR_INVALID_ARG: Invalid arguments were passed (e.g., final partition is NULL).
* - ESP_ERR_NOT_FOUND: OTA handle not found or final partition verification failed.
*/
esp_err_t esp_ota_set_final_partition(esp_ota_handle_t handle, const esp_partition_t *final, bool finalize_with_copy);
/**
* @brief Write OTA update data to partition
*
@@ -113,9 +142,8 @@ esp_err_t esp_ota_begin(const esp_partition_t* partition, size_t image_size, esp
* @return
* - ESP_OK: Data was written to flash successfully, or size = 0
* - ESP_ERR_INVALID_ARG: handle is invalid.
* - ESP_ERR_OTA_VALIDATE_FAILED: First byte of image contains invalid app image magic byte.
* - ESP_ERR_OTA_VALIDATE_FAILED: First byte of image contains invalid image magic byte.
* - ESP_ERR_FLASH_OP_TIMEOUT or ESP_ERR_FLASH_OP_FAIL: Flash write failed.
* - ESP_ERR_OTA_SELECT_INFO_INVALID: OTA data partition has invalid contents
* - ESP_ERR_INVALID_SIZE: if write would go out of bounds of the partition
* - or one of error codes from lower-level flash driver.
*/
@@ -138,9 +166,7 @@ esp_err_t esp_ota_write(esp_ota_handle_t handle, const void* data, size_t size);
* @return
* - ESP_OK: Data was written to flash successfully.
* - ESP_ERR_INVALID_ARG: handle is invalid.
* - ESP_ERR_OTA_VALIDATE_FAILED: First byte of image contains invalid app image magic byte.
* - ESP_ERR_FLASH_OP_TIMEOUT or ESP_ERR_FLASH_OP_FAIL: Flash write failed.
* - ESP_ERR_OTA_SELECT_INFO_INVALID: OTA data partition has invalid contents
*/
esp_err_t esp_ota_write_with_offset(esp_ota_handle_t handle, const void *data, size_t size, uint32_t offset);
@@ -150,6 +176,11 @@ esp_err_t esp_ota_write_with_offset(esp_ota_handle_t handle, const void *data, s
* @param handle Handle obtained from esp_ota_begin().
*
* @note After calling esp_ota_end(), the handle is no longer valid and any memory associated with it is freed (regardless of result).
* @note If either the final or staging partitions were for the bootloader, then at the end of this function,
* the bootloader is reset to its default offset: esp_image_bootloader_offset_set(ESP_PRIMARY_BOOTLOADER_OFFSET)
*
* If the finalize_with_copy option is set, the staging partition will be copied to the final partition at the end of this function.
* Otherwise, copying will need to be handled by custom code using esp_partition_copy().
*
* @return
* - ESP_OK: Newly written OTA app image is valid.
@@ -258,7 +289,7 @@ esp_err_t esp_ota_get_partition_description(const esp_partition_t *partition, es
* @brief Returns the description structure of the bootloader.
*
* @param[in] bootloader_partition Pointer to bootloader partition.
* If NULL, then the current bootloader is used (the default location).
* If NULL, then the PRIMARY bootloader is used (the default location).
* offset = CONFIG_BOOTLOADER_OFFSET_IN_FLASH,
* size = CONFIG_PARTITION_TABLE_OFFSET - CONFIG_BOOTLOADER_OFFSET_IN_FLASH,
* @param[out] desc Structure of info about bootloader.

View File

@@ -2,7 +2,7 @@
components/app_update/test_apps:
enable:
- if: CONFIG_NAME == "defaults" and IDF_TARGET != "linux"
- if: CONFIG_NAME == "defaults" and IDF_TARGET in ["esp32", "esp32c2", "esp32c3", "esp32c5", "esp32c6", "esp32c61", "esp32h2", "esp32p4", "esp32s2", "esp32s3"]
- if: CONFIG_NAME == "xip_psram" and IDF_TARGET in ["esp32s2", "esp32s3", "esp32p4"]
# S2 doesn't have ROM for flash
- if: CONFIG_NAME == "xip_psram_with_rom_impl" and IDF_TARGET in ["esp32s3", "esp32p4"]

View File

@@ -0,0 +1,256 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "esp_ota_ops.h"
#include "esp_partition.h"
#include "esp_flash_partitions.h"
#include "esp_flash_internal.h"
#include "spi_flash_mmap.h"
#include "esp_image_format.h"
#include "esp_system.h"
#include "esp_log.h"
#include "unity.h"
#include "nvs_flash.h"
#include "sdkconfig.h"
static const char *TAG = "test";
static uint8_t buffer[SPI_FLASH_SEC_SIZE];
// Find the unused offset after the last partition, checking that it is of the required size
static uint32_t find_unused_space(size_t required_size)
{
esp_partition_iterator_t it = esp_partition_find(ESP_PARTITION_TYPE_ANY, ESP_PARTITION_SUBTYPE_ANY, NULL);
TEST_ASSERT_NOT_NULL(it);
const esp_partition_t* latest_partition = esp_partition_get(it);
for (; it != NULL; it = esp_partition_next(it)) {
const esp_partition_t *p = esp_partition_get(it);
if (p->address > latest_partition->address) {
latest_partition = p;
}
}
esp_partition_iterator_release(it);
TEST_ASSERT_NOT_NULL(latest_partition);
#if CONFIG_IDF_TARGET_LINUX
uint32_t flash_chip_size;
esp_flash_get_size(NULL, &flash_chip_size);
#else
uint32_t flash_chip_size = esp_flash_default_chip->size;
#endif // CONFIG_IDF_TARGET_LINUX
uint32_t unused_offset = latest_partition->address + latest_partition->size;
TEST_ASSERT_GREATER_OR_EQUAL_UINT32(required_size, flash_chip_size - unused_offset);
return unused_offset;
}
static void check_after_reboot(void)
{
ESP_LOGI(TAG, "App runs");
}
static void download_new_image_from_partition(esp_ota_handle_t update_handle, const esp_partition_t *copy_from_part)
{
uint32_t offset = 0;
ESP_LOGI(TAG, "Downloading image...");
do {
TEST_ESP_OK(esp_partition_read(copy_from_part, offset, buffer, sizeof(buffer)));
TEST_ESP_OK(esp_ota_write(update_handle, buffer, sizeof(buffer)));
offset += sizeof(buffer);
} while (offset < copy_from_part->size);
}
static void start_bootloader_ota_update_via_ota_bootloader_part(void)
{
const esp_partition_t *primary_bootloader;
TEST_ESP_OK(esp_partition_register_external(NULL, ESP_PRIMARY_BOOTLOADER_OFFSET, ESP_BOOTLOADER_SIZE, "PrimaryBTLDR", ESP_PARTITION_TYPE_BOOTLOADER, ESP_PARTITION_SUBTYPE_BOOTLOADER_PRIMARY, &primary_bootloader));
const esp_partition_t *ota_bootloader;
const uint32_t ota_bootloader_offset = find_unused_space(ESP_BOOTLOADER_SIZE);
TEST_ESP_OK(esp_partition_register_external(NULL, ota_bootloader_offset, ESP_BOOTLOADER_SIZE, "OtaBTLDR", ESP_PARTITION_TYPE_BOOTLOADER, ESP_PARTITION_SUBTYPE_BOOTLOADER_OTA, &ota_bootloader));
esp_ota_handle_t update_handle;
TEST_ESP_OK(esp_ota_begin(ota_bootloader, OTA_WITH_SEQUENTIAL_WRITES, &update_handle));
TEST_ESP_OK(esp_ota_set_final_partition(update_handle, primary_bootloader, true));
download_new_image_from_partition(update_handle, primary_bootloader);
TEST_ESP_OK(esp_ota_end(update_handle));
TEST_ESP_OK(esp_partition_deregister_external(primary_bootloader));
TEST_ESP_OK(esp_partition_deregister_external(ota_bootloader));
esp_restart();
}
TEST_CASE_MULTIPLE_STAGES("OTA update of bootloader via temp partition", "[bootloader_ota][reset=SW_CPU_RESET]", start_bootloader_ota_update_via_ota_bootloader_part, check_after_reboot);
static void start_bootloader_ota_update_via_primary_bootloader_part(void)
{
const esp_partition_t *primary_bootloader;
TEST_ESP_OK(esp_partition_register_external(NULL, ESP_PRIMARY_BOOTLOADER_OFFSET, ESP_BOOTLOADER_SIZE, "PrimaryBTLDR", ESP_PARTITION_TYPE_BOOTLOADER, ESP_PARTITION_SUBTYPE_BOOTLOADER_PRIMARY, &primary_bootloader));
esp_ota_handle_t update_handle;
TEST_ESP_OK(esp_ota_begin(primary_bootloader, OTA_WITH_SEQUENTIAL_WRITES, &update_handle));
download_new_image_from_partition(update_handle, primary_bootloader);
TEST_ESP_OK(esp_ota_end(update_handle));
TEST_ESP_OK(esp_partition_deregister_external(primary_bootloader));
esp_restart();
}
TEST_CASE_MULTIPLE_STAGES("OTA update of bootloader via primary partition", "[bootloader_ota][reset=SW_CPU_RESET]", start_bootloader_ota_update_via_primary_bootloader_part, check_after_reboot);
static void start_partition_table_ota_update_via_ota_part_table(void)
{
const esp_partition_t *primary_partition_table;
const esp_partition_t *ota_partition_table;
TEST_ESP_OK(esp_partition_register_external(NULL, ESP_PRIMARY_PARTITION_TABLE_OFFSET, ESP_PARTITION_TABLE_SIZE, "PrimaryPrtTable", ESP_PARTITION_TYPE_PARTITION_TABLE, ESP_PARTITION_SUBTYPE_PARTITION_TABLE_PRIMARY, &primary_partition_table));
uint32_t ota_partition_table_offset = find_unused_space(ESP_PARTITION_TABLE_SIZE);
TEST_ESP_OK(esp_partition_register_external(NULL, ota_partition_table_offset, ESP_PARTITION_TABLE_SIZE, "OtaPrtTable", ESP_PARTITION_TYPE_PARTITION_TABLE, ESP_PARTITION_SUBTYPE_PARTITION_TABLE_OTA, &ota_partition_table));
esp_ota_handle_t update_handle;
TEST_ESP_OK(esp_ota_begin(ota_partition_table, OTA_WITH_SEQUENTIAL_WRITES, &update_handle));
TEST_ESP_OK(esp_ota_set_final_partition(update_handle, primary_partition_table, true));
download_new_image_from_partition(update_handle, primary_partition_table);
TEST_ESP_OK(esp_ota_end(update_handle));
TEST_ESP_OK(esp_partition_deregister_external(primary_partition_table));
TEST_ESP_OK(esp_partition_deregister_external(ota_partition_table));
esp_restart();
}
TEST_CASE_MULTIPLE_STAGES("OTA update of partition_table via temp partition", "[partition_table_ota][reset=SW_CPU_RESET]", start_partition_table_ota_update_via_ota_part_table, check_after_reboot);
static void start_partition_table_ota_update_via_primary_part_table(void)
{
const esp_partition_t *primary_partition_table;
TEST_ESP_OK(esp_partition_register_external(NULL, ESP_PRIMARY_PARTITION_TABLE_OFFSET, ESP_PARTITION_TABLE_SIZE, "PrimaryPrtTable", ESP_PARTITION_TYPE_PARTITION_TABLE, ESP_PARTITION_SUBTYPE_PARTITION_TABLE_PRIMARY, &primary_partition_table));
esp_ota_handle_t update_handle;
TEST_ESP_OK(esp_ota_begin(primary_partition_table, OTA_WITH_SEQUENTIAL_WRITES, &update_handle));
download_new_image_from_partition(update_handle, primary_partition_table);
TEST_ESP_OK(esp_ota_end(update_handle));
TEST_ESP_OK(esp_partition_deregister_external(primary_partition_table));
esp_restart();
}
TEST_CASE_MULTIPLE_STAGES("OTA update of partition_table via primary partition", "[partition_table_ota][reset=SW_CPU_RESET]", start_partition_table_ota_update_via_primary_part_table, check_after_reboot);
TEST_CASE("OTA update of NVS partition", "[nvs_ota]")
{
// intilaize "nvs" partition and define a var (magic_value).
TEST_ESP_OK(nvs_flash_erase());
TEST_ESP_OK(nvs_flash_init());
nvs_handle_t my_handle;
TEST_ESP_OK(nvs_open("namespace", NVS_READWRITE, &my_handle));
uint32_t magic_value = 0x0729FEED;
TEST_ESP_OK(nvs_set_u32(my_handle, "magic_value", magic_value));
TEST_ESP_OK(nvs_commit(my_handle));
magic_value = 0;
TEST_ESP_OK(nvs_get_u32(my_handle, "magic_value", &magic_value));
TEST_ASSERT_EQUAL_HEX(0x0729FEED, magic_value);
nvs_close(my_handle);
TEST_ESP_OK(nvs_flash_deinit());
// register a new "nvs2" partition
const esp_partition_t *nvs_part = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_NVS, "nvs");
const esp_partition_t *nvs2_part;
TEST_ESP_OK(esp_partition_register_external(NULL, find_unused_space(nvs_part->size), nvs_part->size, "nvs2", ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_NVS, &nvs2_part));
ESP_LOGI(TAG, "Use %s partition (0x%08" PRIx32 ") to load a new image", nvs2_part->label, nvs2_part->address);
TEST_ESP_OK(nvs_flash_erase_partition("nvs2"));
// OTA update of the new "nvs2" partition, taking "nvs" partition as source.
esp_ota_handle_t update_handle;
TEST_ESP_OK(esp_ota_begin(nvs2_part, OTA_WITH_SEQUENTIAL_WRITES, &update_handle));
download_new_image_from_partition(update_handle, nvs_part);
TEST_ESP_OK(esp_ota_end(update_handle));
// init "nvs2" partition and check if the magic_value == 0x0729FEED
TEST_ESP_OK(nvs_flash_init_partition("nvs2"));
nvs_handle_t my_handle2;
TEST_ESP_OK(nvs_open_from_partition("nvs2", "namespace", NVS_READWRITE, &my_handle2));
magic_value = 0;
TEST_ESP_OK(nvs_get_u32(my_handle2, "magic_value", &magic_value));
TEST_ASSERT_EQUAL_HEX(0x0729FEED, magic_value);
nvs_close(my_handle2);
TEST_ESP_OK(nvs_flash_deinit_partition("nvs2"));
// deregister "nvs2"
TEST_ESP_OK(esp_partition_deregister_external(nvs2_part));
TEST_ESP_OK(nvs_flash_erase());
}
static void start_bootloader_ota_update_via_app_part(void)
{
const esp_partition_t *primary_bootloader;
TEST_ESP_OK(esp_partition_register_external(NULL, ESP_PRIMARY_BOOTLOADER_OFFSET, ESP_BOOTLOADER_SIZE, "PrimaryBTLDR", ESP_PARTITION_TYPE_BOOTLOADER, ESP_PARTITION_SUBTYPE_BOOTLOADER_PRIMARY, &primary_bootloader));
const esp_partition_t *free_app_ota_partition = esp_ota_get_next_update_partition(NULL);
esp_ota_handle_t update_handle;
TEST_ESP_OK(esp_ota_begin(free_app_ota_partition, OTA_WITH_SEQUENTIAL_WRITES, &update_handle));
TEST_ESP_OK(esp_ota_set_final_partition(update_handle, primary_bootloader, true));
download_new_image_from_partition(update_handle, primary_bootloader);
TEST_ESP_OK(esp_ota_end(update_handle));
TEST_ESP_OK(esp_partition_deregister_external(primary_bootloader));
esp_restart();
}
TEST_CASE_MULTIPLE_STAGES("OTA update of bootloader via a free ota partition", "[bootloader_ota][reset=SW_CPU_RESET]", start_bootloader_ota_update_via_app_part, check_after_reboot);
static void start_partition_table_ota_update_via_app_part(void)
{
const esp_partition_t *primary_partition_table;
TEST_ESP_OK(esp_partition_register_external(NULL, ESP_PRIMARY_PARTITION_TABLE_OFFSET, ESP_PARTITION_TABLE_SIZE, "PrimaryPrtTable", ESP_PARTITION_TYPE_PARTITION_TABLE, ESP_PARTITION_SUBTYPE_PARTITION_TABLE_PRIMARY, &primary_partition_table));
const esp_partition_t *free_app_ota_partition = esp_ota_get_next_update_partition(NULL);
esp_ota_handle_t update_handle;
TEST_ESP_OK(esp_ota_begin(free_app_ota_partition, OTA_WITH_SEQUENTIAL_WRITES, &update_handle));
TEST_ESP_OK(esp_ota_set_final_partition(update_handle, primary_partition_table, true));
download_new_image_from_partition(update_handle, primary_partition_table);
TEST_ESP_OK(esp_ota_end(update_handle));
TEST_ESP_OK(esp_partition_deregister_external(primary_partition_table));
esp_restart();
}
TEST_CASE_MULTIPLE_STAGES("OTA update of partition_table via a free ota partition", "[partition_table_ota][reset=SW_CPU_RESET]", start_partition_table_ota_update_via_app_part, check_after_reboot);
TEST_CASE("OTA update of NVS partition via a free ota partition", "[nvs_ota]")
{
// intilaize "nvs" partition and define a var (magic_value).
const esp_partition_t *nvs_part = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_NVS, "nvs");
TEST_ESP_OK(nvs_flash_erase());
TEST_ESP_OK(nvs_flash_init());
nvs_handle_t my_handle;
TEST_ESP_OK(nvs_open("namespace", NVS_READWRITE, &my_handle));
uint32_t magic_value = 0x0729FEED;
TEST_ESP_OK(nvs_set_u32(my_handle, "magic_value", magic_value));
TEST_ESP_OK(nvs_commit(my_handle));
magic_value = 0;
TEST_ESP_OK(nvs_get_u32(my_handle, "magic_value", &magic_value));
TEST_ASSERT_EQUAL_HEX(0x0729FEED, magic_value);
nvs_close(my_handle);
TEST_ESP_OK(nvs_flash_deinit());
// 1. OTA update nvs partition into free_app_ota_partition
// 2. copy free_app_ota_partition into the original nvs partition (which was erased before coping)
const esp_partition_t *free_app_ota_partition = esp_ota_get_next_update_partition(NULL);
esp_ota_handle_t update_handle;
TEST_ESP_OK(esp_ota_begin(free_app_ota_partition, OTA_WITH_SEQUENTIAL_WRITES, &update_handle));
TEST_ESP_OK(esp_ota_set_final_partition(update_handle, nvs_part, true));
download_new_image_from_partition(update_handle, nvs_part);
TEST_ESP_OK(esp_ota_end(update_handle));
// Check if the magic_value == 0x0729FEED
TEST_ESP_OK(nvs_flash_init());
TEST_ESP_OK(nvs_open("namespace", NVS_READONLY, &my_handle));
magic_value = 0;
TEST_ESP_OK(nvs_get_u32(my_handle, "magic_value", &magic_value));
TEST_ASSERT_EQUAL_HEX(0x0729FEED, magic_value);
nvs_close(my_handle);
TEST_ESP_OK(nvs_flash_deinit());
TEST_ESP_OK(nvs_flash_erase());
}

View File

@@ -43,7 +43,12 @@ static const char *TAG = "ota_test";
static void set_boot_count_in_nvs(uint8_t boot_count)
{
nvs_handle_t boot_count_handle;
TEST_ESP_OK(nvs_open(BOOT_COUNT_NAMESPACE, NVS_READWRITE, &boot_count_handle));
esp_err_t err = nvs_open(BOOT_COUNT_NAMESPACE, NVS_READWRITE, &boot_count_handle);
if (err != ESP_OK) {
TEST_ESP_OK(nvs_flash_erase());
TEST_ESP_OK(nvs_flash_init());
TEST_ESP_OK(nvs_open(BOOT_COUNT_NAMESPACE, NVS_READWRITE, &boot_count_handle));
}
TEST_ESP_OK(nvs_set_u8(boot_count_handle, "boot_count", boot_count));
TEST_ESP_OK(nvs_commit(boot_count_handle));
nvs_close(boot_count_handle);

View File

@@ -0,0 +1,68 @@
menu "Application Rollback"
config BOOTLOADER_APP_ROLLBACK_ENABLE
bool "Enable app rollback support"
default n
help
After updating the app, the bootloader runs a new app with the "ESP_OTA_IMG_PENDING_VERIFY" state set.
This state prevents the re-run of this app. After the first boot of the new app in the user code, the
function should be called to confirm the operability of the app or vice versa about its non-operability.
If the app is working, then it is marked as valid. Otherwise, it is marked as not valid and rolls back to
the previous working app. A reboot is performed, and the app is booted before the software update.
Note: If during the first boot a new app the power goes out or the WDT works, then roll back will happen.
Rollback is possible only between the apps with the same security versions.
config BOOTLOADER_APP_ANTI_ROLLBACK
bool "Enable app anti-rollback support"
depends on BOOTLOADER_APP_ROLLBACK_ENABLE
default n
help
This option prevents rollback to previous firmware/application image with lower security version.
config BOOTLOADER_APP_SECURE_VERSION
int "eFuse secure version of app"
depends on BOOTLOADER_APP_ANTI_ROLLBACK
default 0
help
The secure version is the sequence number stored in the header of each firmware.
The security version is set in the bootloader, version is recorded in the eFuse field
as the number of set ones. The allocated number of bits in the efuse field
for storing the security version is limited (see BOOTLOADER_APP_SEC_VER_SIZE_EFUSE_FIELD option).
Bootloader: When bootloader selects an app to boot, an app is selected that has
a security version greater or equal that recorded in eFuse field.
The app is booted with a higher (or equal) secure version.
The security version is worth increasing if in previous versions there is
a significant vulnerability and their use is not acceptable.
Your partition table should has a scheme with ota_0 + ota_1 (without factory).
config BOOTLOADER_APP_SEC_VER_SIZE_EFUSE_FIELD
int "Size of the efuse secure version field"
depends on BOOTLOADER_APP_ANTI_ROLLBACK
range 1 32 if IDF_TARGET_ESP32
default 32 if IDF_TARGET_ESP32
range 1 4 if IDF_TARGET_ESP32C2
default 4 if IDF_TARGET_ESP32C2
range 1 16
default 16
help
The size of the efuse secure version field.
Its length is limited to 32 bits for ESP32 and 16 bits for ESP32-S2.
This determines how many times the security version can be increased.
config BOOTLOADER_EFUSE_SECURE_VERSION_EMULATE
bool "Emulate operations with efuse secure version(only test)"
default n
depends on BOOTLOADER_APP_ANTI_ROLLBACK
select EFUSE_VIRTUAL
select EFUSE_VIRTUAL_KEEP_IN_FLASH
help
This option allows to emulate read/write operations with all eFuses and efuse secure version.
It allows to test anti-rollback implementation without permanent write eFuse bits.
There should be an entry in partition table with following details: `emul_efuse, data, efuse, , 0x2000`.
This option enables: EFUSE_VIRTUAL and EFUSE_VIRTUAL_KEEP_IN_FLASH.
endmenu

View File

@@ -0,0 +1,25 @@
menu "Bootloader Rollback"
config BOOTLOADER_ANTI_ROLLBACK_ENABLE
bool "Enable bootloader rollback support"
depends on SOC_RECOVERY_BOOTLOADER_SUPPORTED
default n
help
This option prevents rollback to previous bootloader image with lower security version.
config BOOTLOADER_SECURE_VERSION
int "Secure version of bootloader"
depends on BOOTLOADER_ANTI_ROLLBACK_ENABLE
default 0
range 0 4
help
The secure version is the sequence number stored in the header of each bootloader.
The ROM Bootloader which runs the 2nd stage bootloader (PRIMARY or RECOVERY) checks that
the security version is greater or equal that recorded in the eFuse field.
Bootloaders that have a secure version in the image < secure version in efuse will not boot.
The security version is worth increasing if in previous versions there is
a significant vulnerability and their use is not acceptable.
endmenu

View File

@@ -1,6 +1,8 @@
menu "Bootloader config"
orsource "../esp_bootloader_format/Kconfig.bootloader"
orsource "Kconfig.app_rollback"
orsource "Kconfig.bootloader_rollback"
config BOOTLOADER_OFFSET_IN_FLASH
hex
@@ -312,71 +314,6 @@ menu "Bootloader config"
- these options can increase the execution time.
Note: RTC_WDT will reset while encryption operations will be performed.
config BOOTLOADER_APP_ROLLBACK_ENABLE
bool "Enable app rollback support"
default n
help
After updating the app, the bootloader runs a new app with the "ESP_OTA_IMG_PENDING_VERIFY" state set.
This state prevents the re-run of this app. After the first boot of the new app in the user code, the
function should be called to confirm the operability of the app or vice versa about its non-operability.
If the app is working, then it is marked as valid. Otherwise, it is marked as not valid and rolls back to
the previous working app. A reboot is performed, and the app is booted before the software update.
Note: If during the first boot a new app the power goes out or the WDT works, then roll back will happen.
Rollback is possible only between the apps with the same security versions.
config BOOTLOADER_APP_ANTI_ROLLBACK
bool "Enable app anti-rollback support"
depends on BOOTLOADER_APP_ROLLBACK_ENABLE
default n
help
This option prevents rollback to previous firmware/application image with lower security version.
config BOOTLOADER_APP_SECURE_VERSION
int "eFuse secure version of app"
depends on BOOTLOADER_APP_ANTI_ROLLBACK
default 0
help
The secure version is the sequence number stored in the header of each firmware.
The security version is set in the bootloader, version is recorded in the eFuse field
as the number of set ones. The allocated number of bits in the efuse field
for storing the security version is limited (see BOOTLOADER_APP_SEC_VER_SIZE_EFUSE_FIELD option).
Bootloader: When bootloader selects an app to boot, an app is selected that has
a security version greater or equal that recorded in eFuse field.
The app is booted with a higher (or equal) secure version.
The security version is worth increasing if in previous versions there is
a significant vulnerability and their use is not acceptable.
Your partition table should has a scheme with ota_0 + ota_1 (without factory).
config BOOTLOADER_APP_SEC_VER_SIZE_EFUSE_FIELD
int "Size of the efuse secure version field"
depends on BOOTLOADER_APP_ANTI_ROLLBACK
range 1 32 if IDF_TARGET_ESP32
default 32 if IDF_TARGET_ESP32
range 1 4 if IDF_TARGET_ESP32C2
default 4 if IDF_TARGET_ESP32C2
range 1 16
default 16
help
The size of the efuse secure version field.
Its length is limited to 32 bits for ESP32 and 16 bits for ESP32-S2.
This determines how many times the security version can be increased.
config BOOTLOADER_EFUSE_SECURE_VERSION_EMULATE
bool "Emulate operations with efuse secure version(only test)"
default n
depends on BOOTLOADER_APP_ANTI_ROLLBACK
select EFUSE_VIRTUAL
select EFUSE_VIRTUAL_KEEP_IN_FLASH
help
This option allows to emulate read/write operations with all eFuses and efuse secure version.
It allows to test anti-rollback implementation without permanent write eFuse bits.
There should be an entry in partition table with following details: `emul_efuse, data, efuse, , 0x2000`.
This option enables: EFUSE_VIRTUAL and EFUSE_VIRTUAL_KEEP_IN_FLASH.
config BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP
bool "Skip image validation when exiting deep sleep"
# note: dependencies for this config item are different to other "skip image validation"

View File

@@ -116,8 +116,13 @@ idf_build_get_property(sdkconfig SDKCONFIG)
idf_build_get_property(python PYTHON)
idf_build_get_property(extra_cmake_args EXTRA_CMAKE_ARGS)
# We cannot pass lists are a parameter to the external project without modifying the ';' separator
# BOOTLOADER_EXTRA_COMPONENT_DIRS may have been set by the `main` component, do not overwrite it
idf_build_get_property(bootloader_extra_component_dirs BOOTLOADER_EXTRA_COMPONENT_DIRS)
list(APPEND bootloader_extra_component_dirs "${CMAKE_CURRENT_LIST_DIR}")
# We cannot pass lists as a parameter to the external project without modifying the ';' separator
string(REPLACE ";" "|" BOOTLOADER_IGNORE_EXTRA_COMPONENT "${BOOTLOADER_IGNORE_EXTRA_COMPONENT}")
string(REPLACE ";" "|" bootloader_extra_component_dirs "${bootloader_extra_component_dirs}")
externalproject_add(bootloader
SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/subproject"
@@ -127,7 +132,7 @@ externalproject_add(bootloader
LIST_SEPARATOR |
CMAKE_ARGS -DSDKCONFIG=${sdkconfig} -DIDF_PATH=${idf_path} -DIDF_TARGET=${idf_target}
-DPYTHON_DEPS_CHECKED=1 -DPYTHON=${python}
-DEXTRA_COMPONENT_DIRS=${CMAKE_CURRENT_LIST_DIR}
-DEXTRA_COMPONENT_DIRS=${bootloader_extra_component_dirs}
-DPROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR}
-DIGNORE_EXTRA_COMPONENT=${BOOTLOADER_IGNORE_EXTRA_COMPONENT}
${sign_key_arg} ${ver_key_arg}

View File

@@ -34,8 +34,8 @@ set(COMPONENTS
esp_system
newlib)
# Make EXTRA_COMPONENT_DIRS variable to point to the bootloader_components directory
# of the project being compiled
# EXTRA_COMPONENT_DIRS can be populated with directories containing one or several components.
# Make sure this variable contains `bootloader_components` directory of the project being compiled.
set(PROJECT_EXTRA_COMPONENTS "${PROJECT_SOURCE_DIR}/bootloader_components")
if(EXISTS ${PROJECT_EXTRA_COMPONENTS})
list(APPEND EXTRA_COMPONENT_DIRS "${PROJECT_EXTRA_COMPONENTS}")

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -13,6 +13,7 @@
#include <spi_flash_mmap.h> /* including in bootloader for error values */
#include "sdkconfig.h"
#include "bootloader_flash.h"
#include "soc/ext_mem_defs.h"
#ifdef __cplusplus
extern "C" {
@@ -20,8 +21,11 @@ extern "C" {
#define FLASH_SECTOR_SIZE 0x1000
#define FLASH_BLOCK_SIZE 0x10000
#define MMAP_ALIGNED_MASK (SPI_FLASH_MMU_PAGE_SIZE - 1)
#define MMU_FLASH_MASK (~(SPI_FLASH_MMU_PAGE_SIZE - 1))
#define MMU_FLASH_MASK_FROM_VAL(PAGE_SZ) (~((PAGE_SZ) - 1))
#define MMU_DROM_END_ENTRY_VADDR_FROM_VAL(PAGE_SZ) (SOC_DRAM_FLASH_ADDRESS_HIGH - (PAGE_SZ))
/**
* MMU mapping must always be in the unit of a SPI_FLASH_MMU_PAGE_SIZE
@@ -89,7 +93,7 @@ uint32_t bootloader_mmap_get_free_pages(void);
* @param length - Length of data to map.
*
* @return Pointer to mapped data memory (at src_addr), or NULL
* if an allocation error occured.
* if an allocation error occurred.
*/
const void *bootloader_mmap(uint32_t src_addr, uint32_t size);

View File

@@ -32,6 +32,7 @@ extern "C" {
#define PART_TYPE_BOOTLOADER 0x02
#define PART_SUBTYPE_BOOTLOADER_PRIMARY 0x00
#define PART_SUBTYPE_BOOTLOADER_OTA 0x01
#define PART_SUBTYPE_BOOTLOADER_RECOVERY 0x02
#define PART_TYPE_PARTITION_TABLE 0x03
#define PART_SUBTYPE_PARTITION_TABLE_PRIMARY 0x00

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -34,6 +34,7 @@ typedef struct {
uint32_t image_len; /* Length of image on flash, in bytes */
uint8_t image_digest[32]; /* appended SHA-256 digest */
uint32_t secure_version; /* secure version for anti-rollback, it is covered by sha256 (set if CONFIG_BOOTLOADER_APP_ANTI_ROLLBACK=y) */
uint32_t mmu_page_size; /* Flash MMU page size per binary header */
} esp_image_metadata_t;
typedef enum {
@@ -86,12 +87,12 @@ ESP_STATIC_ASSERT(sizeof(rtc_retain_mem_t) <= ESP_BOOTLOADER_RESERVE_RTC, "Reser
#endif // CONFIG_BOOTLOADER_RESERVE_RTC_MEM
/**
* @brief Verify an app image.
* @brief Verify an app/bootloader image.
*
* If encryption is enabled, data will be transparently decrypted.
*
* @param mode Mode of operation (verify, silent verify, or load).
* @param part Partition to load the app from.
* @param part Partition to load the app/bootloader from.
* @param[inout] data Pointer to the image metadata structure which is be filled in by this function.
* 'start_addr' member should be set (to the start address of the image.)
* Other fields will all be initialised by this function.
@@ -113,11 +114,11 @@ ESP_STATIC_ASSERT(sizeof(rtc_retain_mem_t) <= ESP_BOOTLOADER_RESERVE_RTC, "Reser
esp_err_t esp_image_verify(esp_image_load_mode_t mode, const esp_partition_pos_t *part, esp_image_metadata_t *data);
/**
* @brief Get metadata of app
* @brief Get metadata of app/bootloader
*
* If encryption is enabled, data will be transparently decrypted.
*
* @param part Partition to load the app from.
* @param part Partition to load the app/bootloader from.
* @param[out] metadata Pointer to the image metadata structure which is be filled in by this function.
* Fields will all be initialised by this function.
*
@@ -171,7 +172,7 @@ esp_err_t bootloader_load_image(const esp_partition_pos_t *part, esp_image_metad
esp_err_t bootloader_load_image_no_verify(const esp_partition_pos_t *part, esp_image_metadata_t *data);
/**
* @brief Verify the bootloader image.
* @brief Verify the PRIMARY bootloader image.
*
* @param[out] If result is ESP_OK and this pointer is non-NULL, it
* will be set to the length of the bootloader image.
@@ -181,7 +182,7 @@ esp_err_t bootloader_load_image_no_verify(const esp_partition_pos_t *part, esp_i
esp_err_t esp_image_verify_bootloader(uint32_t *length);
/**
* @brief Verify the bootloader image.
* @brief Verify the PRIMARY bootloader image.
*
* @param[out] Metadata for the image. Only valid if result is ESP_OK.
*
@@ -197,6 +198,25 @@ esp_err_t esp_image_verify_bootloader_data(esp_image_metadata_t *data);
*/
int esp_image_get_flash_size(esp_image_flash_size_t app_flash_size);
/**
* @brief Get the ota bootloader offset
*
* The esp_image_verify functions use the offset to distinguish between application and bootloader verifications.
* The application must set the OTA bootloader offset before running any verification functions for the OTA bootloader partition.
*
* @return ota Bootloader offset. UINT32_MAX - not set.
*/
uint32_t esp_image_bootloader_offset_get(void);
/**
* @brief Set the ota bootloader offset
*
* The esp_image_verify functions use the offset to distinguish between application and bootloader verifications.
* The application must set the OTA bootloader offset before running any verification functions for the OTA bootloader partition.
*
* @param offset ota Bootloader offset
*/
void esp_image_bootloader_offset_set(const uint32_t offset);
typedef struct {
uint32_t drom_addr;

View File

@@ -64,7 +64,7 @@ __attribute__((weak)) void bootloader_clock_configure(void)
// RTC_FAST clock source will be switched to RC_FAST at application startup
clk_cfg.fast_clk_src = rtc_clk_fast_src_get();
if (clk_cfg.fast_clk_src == SOC_RTC_FAST_CLK_SRC_INVALID) {
clk_cfg.fast_clk_src = SOC_RTC_FAST_CLK_SRC_XTAL_DIV;
clk_cfg.fast_clk_src = SOC_RTC_FAST_CLK_SRC_DEFAULT;
}
#if CONFIG_IDF_TARGET_ESP32C6

View File

@@ -140,13 +140,13 @@ bool bootloader_common_erase_part_type_data(const char *list_erase, bool ota_dat
return ret;
}
esp_err_t bootloader_common_get_sha256_of_partition (uint32_t address, uint32_t size, int type, uint8_t *out_sha_256)
esp_err_t bootloader_common_get_sha256_of_partition(uint32_t address, uint32_t size, int type, uint8_t *out_sha_256)
{
if (out_sha_256 == NULL || size == 0) {
return ESP_ERR_INVALID_ARG;
}
if (type == PART_TYPE_APP) {
if (type == PART_TYPE_APP || type == PART_TYPE_BOOTLOADER) {
const esp_partition_pos_t partition_pos = {
.offset = address,
.size = size,

View File

@@ -46,6 +46,9 @@ void bootloader_random_enable(void)
SET_PERI_REG_MASK(PMU_RF_PWC_REG, PMU_PERIF_I2C_RSTB);
SET_PERI_REG_MASK(PMU_RF_PWC_REG, PMU_XPD_PERIF_I2C);
// enable analog i2c master clock for RNG runtime
ANALOG_CLOCK_ENABLE();
// Config ADC circuit (Analog part) with I2C (HOST ID 0X69) and choose internal voltage as sampling source
REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SARADC_DTEST_RTC_ADDR, 0);
REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SARADC_ENT_PERIF_ADDR, 1);
@@ -94,6 +97,9 @@ void bootloader_random_disable(void)
REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SARADC1_EN_TOUT_ADDR, 0);
REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SARADC2_EN_TOUT_ADDR, 0);
// disable analog i2c master clock
ANALOG_CLOCK_DISABLE();
// disable ADC_CTRL_CLK (SAR ADC function clock)
REG_WRITE(PCR_SARADC_CLKM_CONF_REG, 0x00404000);

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -40,6 +40,9 @@ void bootloader_random_enable(void)
SET_PERI_REG_MASK(PMU_RF_PWC_REG, PMU_PERIF_I2C_RSTB);
SET_PERI_REG_MASK(PMU_RF_PWC_REG, PMU_XPD_PERIF_I2C);
// enable analog i2c master clock for RNG runtime
ANALOG_CLOCK_ENABLE();
// Config ADC circuit (Analog part) with I2C(HOST ID 0x69) and chose internal voltage as sampling source
REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SARADC_DTEST_RTC_ADDR , 2);
REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SARADC_ENT_RTC_ADDR , 1);
@@ -88,6 +91,9 @@ void bootloader_random_disable(void)
REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SARADC1_ENCAL_REF_ADDR, 0);
REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SARADC2_ENCAL_REF_ADDR, 0);
// disable analog i2c master clock
ANALOG_CLOCK_DISABLE();
// disable ADC_CTRL_CLK (SAR ADC function clock)
REG_WRITE(PCR_SARADC_CLKM_CONF_REG, 0x00404000);

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -45,6 +45,9 @@ void bootloader_random_enable(void)
SET_PERI_REG_MASK(PMU_RF_PWC_REG, PMU_PERIF_I2C_RSTB);
SET_PERI_REG_MASK(PMU_RF_PWC_REG, PMU_XPD_PERIF_I2C);
// enable analog i2c master clock for RNG runtime
ANALOG_CLOCK_ENABLE();
// Config ADC circuit (Analog part) with I2C(HOST ID 0x69) and chose internal voltage as sampling source
REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SARADC_DTEST_RTC_ADDR , 0);
REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SARADC_ENT_RTC_ADDR , 1);
@@ -93,6 +96,9 @@ void bootloader_random_disable(void)
REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SARADC1_ENCAL_REF_ADDR, 0);
REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SARADC2_ENCAL_REF_ADDR, 0);
// disable analog i2c master clock
ANALOG_CLOCK_DISABLE();
// disable ADC_CTRL_CLK (SAR ADC function clock)
REG_WRITE(PCR_SARADC_CLKM_CONF_REG, 0x00404000);

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -35,6 +35,9 @@ void bootloader_random_enable(void)
// some ADC sensor registers are in power group PERIF_I2C and need to be enabled via PMU
SET_PERI_REG_MASK(PMU_RF_PWC_REG, PMU_XPD_PERIF_I2C);
// enable analog i2c master clock for RNG runtime
ANALOG_CLOCK_ENABLE();
REGI2C_WRITE_MASK(I2C_SAR_ADC, I2C_SARADC_DTEST, 0);
REGI2C_WRITE_MASK(I2C_SAR_ADC, I2C_SARADC_ENT_SAR, 1);
REGI2C_WRITE_MASK(I2C_SAR_ADC, I2C_SARADC_EN_TOUT_SAR1_BUS, 1);
@@ -80,6 +83,9 @@ void bootloader_random_disable(void)
REGI2C_WRITE_MASK(I2C_SAR_ADC, I2C_SARADC_ENT_SAR, 0);
REGI2C_WRITE_MASK(I2C_SAR_ADC, I2C_SARADC_EN_TOUT_SAR1_BUS, 0);
// disable analog i2c master clock
ANALOG_CLOCK_DISABLE();
// disable ADC_CTRL_CLK (SAR ADC function clock)
REG_WRITE(PCR_SARADC_CLKM_CONF_REG, 0x00404000);

View File

@@ -62,6 +62,9 @@ void bootloader_random_enable(void)
SET_PERI_REG_MASK(ADC_CTRL_REG_REG, ADC_START_FORCE); //start force 1
// enable analog i2c master clock for RNG runtime
ANALOG_CLOCK_ENABLE();
adc1_fix_initcode_set(I2C_SAR_ADC_INIT_CODE_VAL);
// cfg pattern table
@@ -94,6 +97,9 @@ void bootloader_random_enable(void)
void bootloader_random_disable(void)
{
// disable analog i2c master clock
ANALOG_CLOCK_DISABLE();
// No-op for now TODO IDF-6497
// ADC should be set to defaults here, once ADC API is implemented
// OR just keep this empty and let application continue to use RNG initialized by the bootloader

View File

@@ -20,6 +20,7 @@
#include "esp_rom_spiflash.h"
#include "soc/soc.h"
#include "soc/soc_caps.h"
#include "soc/rtc.h"
#include "soc/efuse_periph.h"
#include "soc/rtc_periph.h"
@@ -66,7 +67,7 @@ static void set_cache_and_start_app(uint32_t drom_addr,
uint32_t irom_addr,
uint32_t irom_load_addr,
uint32_t irom_size,
uint32_t entry_addr);
const esp_image_metadata_t *data);
esp_err_t bootloader_common_read_otadata(const esp_partition_pos_t *ota_info, esp_ota_select_entry_t *two_otadata)
{
@@ -207,6 +208,9 @@ bool bootloader_utility_load_partition_table(bootloader_state_t *bs)
case PART_SUBTYPE_BOOTLOADER_OTA:
partition_usage = "ota bootloader";
break;
case PART_SUBTYPE_BOOTLOADER_RECOVERY:
partition_usage = "recovery bootloader";
break;
}
break; /* PART_TYPE_BOOTLOADER */
case PART_TYPE_PARTITION_TABLE: /* Partition table partition */
@@ -789,7 +793,7 @@ static void unpack_load_app(const esp_image_metadata_t *data)
rom_addr[1],
rom_load_addr[1],
rom_size[1],
data->image.entry_addr);
data);
}
#else //!SOC_MMU_DI_VADDR_SHARED
@@ -834,7 +838,7 @@ static void unpack_load_app(const esp_image_metadata_t *data)
irom_addr,
irom_load_addr,
irom_size,
data->image.entry_addr);
data);
}
#endif //#if SOC_MMU_DI_VADDR_SHARED
@@ -859,9 +863,11 @@ static void set_cache_and_start_app(
uint32_t irom_addr,
uint32_t irom_load_addr,
uint32_t irom_size,
uint32_t entry_addr)
const esp_image_metadata_t *data)
{
int rc __attribute__((unused));
const uint32_t entry_addr = data->image.entry_addr;
const uint32_t mmu_page_size = data->mmu_page_size;
ESP_EARLY_LOGD(TAG, "configure drom and irom and start");
//-----------------------Disable Cache to do the mapping---------
@@ -871,12 +877,18 @@ static void set_cache_and_start_app(
#else
cache_hal_disable(CACHE_LL_LEVEL_EXT_MEM, CACHE_TYPE_ALL);
#endif
#if SOC_MMU_PAGE_SIZE_CONFIGURABLE
// re-configure MMU page size
mmu_ll_set_page_size(0, mmu_page_size);
#endif //SOC_MMU_PAGE_SIZE_CONFIGURABLE
//reset MMU table first
mmu_hal_unmap_all();
//-----------------------MAP DROM--------------------------
uint32_t drom_load_addr_aligned = drom_load_addr & MMU_FLASH_MASK;
uint32_t drom_addr_aligned = drom_addr & MMU_FLASH_MASK;
uint32_t drom_load_addr_aligned = drom_load_addr & MMU_FLASH_MASK_FROM_VAL(mmu_page_size);
uint32_t drom_addr_aligned = drom_addr & MMU_FLASH_MASK_FROM_VAL(mmu_page_size);
ESP_EARLY_LOGV(TAG, "rodata starts from paddr=0x%08" PRIx32 ", vaddr=0x%08" PRIx32 ", size=0x%" PRIx32, drom_addr, drom_load_addr, drom_size);
//The addr is aligned, so we add the mask off length to the size, to make sure the corresponding buses are enabled.
drom_size = (drom_load_addr - drom_load_addr_aligned) + drom_size;
@@ -894,13 +906,13 @@ static void set_cache_and_start_app(
ESP_EARLY_LOGV(TAG, "after mapping rodata, starting from paddr=0x%08" PRIx32 " and vaddr=0x%08" PRIx32 ", 0x%" PRIx32 " bytes are mapped", drom_addr_aligned, drom_load_addr_aligned, actual_mapped_len);
}
//we use the MMU_LL_END_DROM_ENTRY_ID mmu entry as a map page for app to find the boot partition
mmu_hal_map_region(0, MMU_TARGET_FLASH0, MMU_LL_END_DROM_ENTRY_VADDR, drom_addr_aligned, CONFIG_MMU_PAGE_SIZE, &actual_mapped_len);
mmu_hal_map_region(0, MMU_TARGET_FLASH0, MMU_DROM_END_ENTRY_VADDR_FROM_VAL(mmu_page_size), drom_addr_aligned, mmu_page_size, &actual_mapped_len);
ESP_EARLY_LOGV(TAG, "mapped one page of the rodata, from paddr=0x%08" PRIx32 " and vaddr=0x%08" PRIx32 ", 0x%" PRIx32 " bytes are mapped", drom_addr_aligned, MMU_LL_END_DROM_ENTRY_VADDR, actual_mapped_len);
#endif
//-----------------------MAP IROM--------------------------
uint32_t irom_load_addr_aligned = irom_load_addr & MMU_FLASH_MASK;
uint32_t irom_addr_aligned = irom_addr & MMU_FLASH_MASK;
uint32_t irom_load_addr_aligned = irom_load_addr & MMU_FLASH_MASK_FROM_VAL(mmu_page_size);
uint32_t irom_addr_aligned = irom_addr & MMU_FLASH_MASK_FROM_VAL(mmu_page_size);
ESP_EARLY_LOGV(TAG, "text starts from paddr=0x%08" PRIx32 ", vaddr=0x%08" PRIx32 ", size=0x%" PRIx32, irom_addr, irom_load_addr, irom_size);
//The addr is aligned, so we add the mask off length to the size, to make sure the corresponding buses are enabled.
irom_size = (irom_load_addr - irom_load_addr_aligned) + irom_size;

View File

@@ -85,7 +85,7 @@ static void bootloader_super_wdt_auto_feed(void)
static inline void bootloader_hardware_init(void)
{
regi2c_ctrl_ll_master_enable_clock(true);
_regi2c_ctrl_ll_master_enable_clock(true); // keep ana i2c mst clock always enabled in bootloader
regi2c_ctrl_ll_master_force_enable_clock(true); // TODO: IDF-8667 Remove this?
regi2c_ctrl_ll_master_configure_clock();
}

View File

@@ -96,7 +96,7 @@ static inline void bootloader_hardware_init(void)
esp_rom_spiflash_fix_dummylen(1, 1);
#endif
regi2c_ctrl_ll_master_enable_clock(true);
_regi2c_ctrl_ll_master_enable_clock(true); // keep ana i2c mst clock always enabled in bootloader
regi2c_ctrl_ll_master_configure_clock();
}

View File

@@ -86,7 +86,7 @@ static void bootloader_super_wdt_auto_feed(void)
static inline void bootloader_hardware_init(void)
{
regi2c_ctrl_ll_master_enable_clock(true);
_regi2c_ctrl_ll_master_enable_clock(true); // keep ana i2c mst clock always enabled in bootloader
regi2c_ctrl_ll_master_force_enable_clock(true); // TODO: IDF-9274 Remove this?
regi2c_ctrl_ll_master_configure_clock();
}

View File

@@ -11,9 +11,9 @@
#include "hal/regi2c_ctrl.h"
#include "soc/regi2c_saradc.h"
//Not supported but common bootloader calls the function. Do nothing
void bootloader_ana_clock_glitch_reset_config(bool enable)
{
// TODO: IDF-9274
(void)enable;
}

View File

@@ -90,7 +90,7 @@ static inline void bootloader_hardware_init(void)
CLEAR_PERI_REG_MASK(PMU_RF_PWC_REG, PMU_XPD_RFPLL);
SET_PERI_REG_MASK(PMU_RF_PWC_REG, PMU_XPD_FORCE_RFPLL);
regi2c_ctrl_ll_master_enable_clock(true);
_regi2c_ctrl_ll_master_enable_clock(true); // keep ana i2c mst clock always enabled in bootloader
regi2c_ctrl_ll_master_configure_clock();
}

View File

@@ -95,8 +95,7 @@ static void bootloader_super_wdt_auto_feed(void)
static inline void bootloader_hardware_init(void)
{
int __DECLARE_RCC_RC_ATOMIC_ENV __attribute__ ((unused)); // To avoid build errors/warnings about __DECLARE_RCC_RC_ATOMIC_ENV
regi2c_ctrl_ll_master_enable_clock(true);
_regi2c_ctrl_ll_master_enable_clock(true); // keep ana i2c mst clock always enabled in bootloader
regi2c_ctrl_ll_master_configure_clock();
unsigned chip_version = efuse_hal_chip_revision();

View File

@@ -22,6 +22,7 @@
#include "bootloader_memory_utils.h"
#include "soc/soc_caps.h"
#include "hal/cache_ll.h"
#include "spi_flash_mmap.h"
#define ALIGN_UP(num, align) (((num) + ((align) - 1)) & ~((align) - 1))
@@ -77,7 +78,7 @@ static esp_err_t process_segment_data(int segment, intptr_t load_addr, uint32_t
static esp_err_t verify_image_header(uint32_t src_addr, const esp_image_header_t *image, bool silent);
/* Verify a segment header */
static esp_err_t verify_segment_header(int index, const esp_image_segment_header_t *segment, uint32_t segment_data_offs, bool silent);
static esp_err_t verify_segment_header(int index, const esp_image_segment_header_t *segment, uint32_t segment_data_offs, esp_image_metadata_t *metadata, bool silent);
/* Log-and-fail macro for use in esp_image_load */
#define FAIL_LOAD(...) do { \
@@ -102,6 +103,24 @@ static esp_err_t process_checksum(bootloader_sha256_handle_t sha_handle, uint32_
static esp_err_t __attribute__((unused)) verify_secure_boot_signature(bootloader_sha256_handle_t sha_handle, esp_image_metadata_t *data, uint8_t *image_digest, uint8_t *verified_digest);
static esp_err_t __attribute__((unused)) verify_simple_hash(bootloader_sha256_handle_t sha_handle, esp_image_metadata_t *data);
static uint32_t s_bootloader_partition_offset = ESP_PRIMARY_BOOTLOADER_OFFSET;
uint32_t esp_image_bootloader_offset_get(void)
{
return s_bootloader_partition_offset;
}
void esp_image_bootloader_offset_set(const uint32_t offset)
{
s_bootloader_partition_offset = offset;
ESP_LOGI(TAG, "Bootloader offsets for PRIMARY: 0x%x, Secondary: 0x%" PRIx32, ESP_PRIMARY_BOOTLOADER_OFFSET, s_bootloader_partition_offset);
}
static bool is_bootloader(uint32_t offset)
{
return ((offset == ESP_PRIMARY_BOOTLOADER_OFFSET) || (offset == s_bootloader_partition_offset));
}
static esp_err_t image_load(esp_image_load_mode_t mode, const esp_partition_pos_t *part, esp_image_metadata_t *data)
{
#ifdef BOOTLOADER_BUILD
@@ -135,7 +154,7 @@ static esp_err_t image_load(esp_image_load_mode_t mode, const esp_partition_pos_
// For secure boot V1 on ESP32, we don't calculate SHA or verify signature on bootloaders.
// (For non-secure boot, we don't verify any SHA-256 hash appended to the bootloader because
// esptool.py may have rewritten the header - rely on esptool.py having verified the bootloader at flashing time, instead.)
verify_sha = (part->offset != ESP_BOOTLOADER_OFFSET) && do_verify;
verify_sha = !is_bootloader(part->offset) && do_verify;
#endif
if (part->size > SIXTEEN_MB) {
@@ -199,7 +218,7 @@ static esp_err_t image_load(esp_image_load_mode_t mode, const esp_partition_pos_
#if CONFIG_SECURE_BOOT_V2_ENABLED
ESP_FAULT_ASSERT(!esp_secure_boot_enabled() || memcmp(image_digest, verified_digest, HASH_LEN) == 0);
#else // Secure Boot V1 on ESP32, only verify signatures for apps not bootloaders
ESP_FAULT_ASSERT(data->start_addr == ESP_BOOTLOADER_OFFSET || memcmp(image_digest, verified_digest, HASH_LEN) == 0);
ESP_FAULT_ASSERT(is_bootloader(data->start_addr) || memcmp(image_digest, verified_digest, HASH_LEN) == 0);
#endif
#endif // SECURE_BOOT_CHECK_SIGNATURE
@@ -332,7 +351,8 @@ static esp_err_t verify_image_header(uint32_t src_addr, const esp_image_header_t
// Checking the chip revision header *will* print a bunch of other info
// regardless of silent setting as this may be important, but don't bother checking it
// if it looks like the app partition is erased or otherwise garbage
CHECK_ERR(bootloader_common_check_chip_validity(image, ESP_IMAGE_APPLICATION));
esp_image_type image_type = is_bootloader(src_addr) ? ESP_IMAGE_BOOTLOADER : ESP_IMAGE_APPLICATION;
CHECK_ERR(bootloader_common_check_chip_validity(image, image_type));
if (image->segment_count > ESP_IMAGE_MAX_SEGMENTS) {
FAIL_LOAD("image at 0x%"PRIx32" segment count %d exceeds max %d", src_addr, image->segment_count, ESP_IMAGE_MAX_SEGMENTS);
@@ -559,7 +579,7 @@ static esp_err_t process_segment(int index, uint32_t flash_addr, esp_image_segme
ESP_LOGV(TAG, "segment data length 0x%"PRIx32" data starts 0x%"PRIx32, data_len, data_addr);
CHECK_ERR(verify_segment_header(index, header, data_addr, silent));
CHECK_ERR(verify_segment_header(index, header, data_addr, metadata, silent));
if (data_len % 4 != 0) {
FAIL_LOAD("unaligned segment length 0x%"PRIx32, data_len);
@@ -695,7 +715,7 @@ static esp_err_t process_segment_data(int segment, intptr_t load_addr, uint32_t
// Case II: Bootloader verifying bootloader
// The esp_app_desc_t structure is located in DROM and is always in segment #0.
// Anti-rollback check and efuse block version check should handle only Case I from above.
if (segment == 0 && metadata->start_addr != ESP_BOOTLOADER_OFFSET) {
if (segment == 0 && !is_bootloader(metadata->start_addr)) {
/* ESP32 doesn't have more memory and more efuse bits for block major version. */
#if !CONFIG_IDF_TARGET_ESP32
const esp_app_desc_t *app_desc = (const esp_app_desc_t *)src;
@@ -748,7 +768,7 @@ static esp_err_t process_segment_data(int segment, intptr_t load_addr, uint32_t
return ESP_OK;
}
static esp_err_t verify_segment_header(int index, const esp_image_segment_header_t *segment, uint32_t segment_data_offs, bool silent)
static esp_err_t verify_segment_header(int index, const esp_image_segment_header_t *segment, uint32_t segment_data_offs, esp_image_metadata_t *metadata, bool silent)
{
if ((segment->data_len & 3) != 0
|| segment->data_len >= SIXTEEN_MB) {
@@ -761,13 +781,39 @@ static esp_err_t verify_segment_header(int index, const esp_image_segment_header
uint32_t load_addr = segment->load_addr;
bool map_segment = should_map(load_addr);
#if SOC_MMU_PAGE_SIZE_CONFIGURABLE
/* ESP APP descriptor is present in the DROM segment #0 */
if (index == 0 && !is_bootloader(metadata->start_addr)) {
const esp_app_desc_t *app_desc = (const esp_app_desc_t *)bootloader_mmap(segment_data_offs, sizeof(esp_app_desc_t));
if (!app_desc || app_desc->magic_word != ESP_APP_DESC_MAGIC_WORD) {
ESP_LOGE(TAG, "Failed to fetch app description header!");
return ESP_FAIL;
}
// Convert from log base 2 number to actual size while handling legacy image case (value 0)
metadata->mmu_page_size = (app_desc->mmu_page_size > 0) ? (1UL << app_desc->mmu_page_size) : SPI_FLASH_MMU_PAGE_SIZE;
if (metadata->mmu_page_size != SPI_FLASH_MMU_PAGE_SIZE) {
ESP_LOGI(TAG, "MMU page size mismatch, configured: 0x%x, found: 0x%"PRIx32, SPI_FLASH_MMU_PAGE_SIZE, metadata->mmu_page_size);
}
bootloader_munmap(app_desc);
} else if (index == 0 && is_bootloader(metadata->start_addr)) {
// Bootloader always uses the default MMU page size
metadata->mmu_page_size = SPI_FLASH_MMU_PAGE_SIZE;
}
#else // SOC_MMU_PAGE_SIZE_CONFIGURABLE
metadata->mmu_page_size = SPI_FLASH_MMU_PAGE_SIZE;
#endif // !SOC_MMU_PAGE_SIZE_CONFIGURABLE
const int mmu_page_size = metadata->mmu_page_size;
ESP_LOGV(TAG, "MMU page size 0x%x", mmu_page_size);
/* Check that flash cache mapped segment aligns correctly from flash to its mapped address,
relative to the 64KB page mapping size.
relative to the MMU page mapping size.
*/
ESP_LOGV(TAG, "segment %d map_segment %d segment_data_offs 0x%"PRIx32" load_addr 0x%"PRIx32,
index, map_segment, segment_data_offs, load_addr);
if (map_segment
&& ((segment_data_offs % SPI_FLASH_MMU_PAGE_SIZE) != (load_addr % SPI_FLASH_MMU_PAGE_SIZE))) {
&& ((segment_data_offs % mmu_page_size) != (load_addr % mmu_page_size))) {
if (!silent) {
ESP_LOGE(TAG, "Segment %d load address 0x%08"PRIx32", doesn't match data 0x%08"PRIx32,
index, load_addr, segment_data_offs);
@@ -847,8 +893,8 @@ esp_err_t esp_image_verify_bootloader_data(esp_image_metadata_t *data)
return ESP_ERR_INVALID_ARG;
}
const esp_partition_pos_t bootloader_part = {
.offset = ESP_BOOTLOADER_OFFSET,
.size = ESP_PARTITION_TABLE_OFFSET - ESP_BOOTLOADER_OFFSET,
.offset = ESP_PRIMARY_BOOTLOADER_OFFSET,
.size = ESP_BOOTLOADER_SIZE,
};
return esp_image_verify(ESP_IMAGE_VERIFY,
&bootloader_part,
@@ -871,7 +917,7 @@ static esp_err_t process_appended_hash_and_sig(esp_image_metadata_t *data, uint3
#if CONFIG_SECURE_BOOT || CONFIG_SECURE_SIGNED_APPS_NO_SECURE_BOOT
// Case I: Bootloader part
if (part_offset == ESP_BOOTLOADER_OFFSET) {
if (is_bootloader(part_offset)) {
// For bootloader with secure boot v1, signature stays in an independent flash
// sector (offset 0x0) and does not get appended to the image.
#if CONFIG_SECURE_BOOT_V2_ENABLED
@@ -1005,7 +1051,7 @@ static esp_err_t verify_secure_boot_signature(bootloader_sha256_handle_t sha_han
#if CONFIG_SECURE_SIGNED_APPS_RSA_SCHEME || CONFIG_SECURE_SIGNED_APPS_ECDSA_V2_SCHEME
data->image_len = end - data->start_addr + sizeof(ets_secure_boot_signature_t);
#elif defined(CONFIG_SECURE_SIGNED_APPS_ECDSA_SCHEME)
if (data->start_addr != ESP_BOOTLOADER_OFFSET) {
if (!is_bootloader(data->start_addr)) {
data->image_len = end - data->start_addr + sizeof(esp_secure_boot_sig_block_t);
}
#endif

View File

@@ -43,7 +43,7 @@ static const char *TAG = "flash_encrypt";
/* Static functions for stages of flash encryption */
static esp_err_t encrypt_bootloader(void);
static esp_err_t encrypt_and_load_partition_table(esp_partition_info_t *partition_table, int *num_partitions);
static esp_err_t encrypt_and_load_partition_table(uint32_t offset, esp_partition_info_t *partition_table, int *num_partitions);
static esp_err_t encrypt_partition(int index, const esp_partition_info_t *partition);
static size_t get_flash_encrypt_cnt_value(void);
@@ -262,12 +262,12 @@ esp_err_t esp_flash_encrypt_contents(void)
esp_flash_encryption_enable_key_mgr();
#endif
err = encrypt_bootloader();
err = encrypt_bootloader(); // PART_SUBTYPE_BOOTLOADER_PRIMARY
if (err != ESP_OK) {
return err;
}
err = encrypt_and_load_partition_table(partition_table, &num_partitions);
err = encrypt_and_load_partition_table(ESP_PRIMARY_PARTITION_TABLE_OFFSET, partition_table, &num_partitions); // PART_SUBTYPE_PARTITION_TABLE_PRIMARY
if (err != ESP_OK) {
return err;
}
@@ -277,6 +277,14 @@ esp_err_t esp_flash_encrypt_contents(void)
/* Go through each partition and encrypt if necessary */
for (int i = 0; i < num_partitions; i++) {
if ((partition_table[i].type == PART_TYPE_BOOTLOADER && partition_table[i].subtype == PART_SUBTYPE_BOOTLOADER_PRIMARY)
|| (partition_table[i].type == PART_TYPE_PARTITION_TABLE && partition_table[i].subtype == PART_SUBTYPE_PARTITION_TABLE_PRIMARY)) {
/* Skip encryption of PRIMARY partitions for bootloader and partition table.
* PRIMARY partitions have already been encrypted above.
* We allow to encrypt partitions that are not PRIMARY.
*/
continue;
}
err = encrypt_partition(i, &partition_table[i]);
if (err != ESP_OK) {
return err;
@@ -337,13 +345,13 @@ static esp_err_t encrypt_bootloader(void)
#if CONFIG_SECURE_BOOT_V2_ENABLED
/* The image length obtained from esp_image_verify_bootloader includes the sector boundary padding and the signature block lengths */
if (ESP_BOOTLOADER_OFFSET + image_length > ESP_PARTITION_TABLE_OFFSET) {
ESP_LOGE(TAG, "Bootloader is too large to fit Secure Boot V2 signature sector and partition table (configured offset 0x%x)", ESP_PARTITION_TABLE_OFFSET);
if (image_length > ESP_BOOTLOADER_SIZE) {
ESP_LOGE(TAG, "Bootloader is too large to fit Secure Boot V2 signature sector and partition table (configured offset 0x%x)", ESP_PRIMARY_PARTITION_TABLE_OFFSET);
return ESP_ERR_INVALID_SIZE;
}
#endif // CONFIG_SECURE_BOOT_V2_ENABLED
err = esp_flash_encrypt_region(ESP_BOOTLOADER_OFFSET, image_length);
err = esp_flash_encrypt_region(ESP_PRIMARY_BOOTLOADER_OFFSET, image_length);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to encrypt bootloader in place: 0x%x", err);
return err;
@@ -368,33 +376,37 @@ static esp_err_t encrypt_bootloader(void)
return ESP_OK;
}
static esp_err_t encrypt_and_load_partition_table(esp_partition_info_t *partition_table, int *num_partitions)
static esp_err_t read_and_verify_partition_table(uint32_t offset, 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);
err = bootloader_flash_read(offset, partition_table, ESP_PARTITION_TABLE_MAX_LEN, false);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to read partition table data");
ESP_LOGE(TAG, "Failed to read partition table data at 0x%" PRIx32, offset);
return err;
}
if (esp_partition_table_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;
err = esp_partition_table_verify(partition_table, false, num_partitions);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to read partition table data - not plaintext or empty?");
}
/* Valid partition table loaded */
ESP_LOGI(TAG, "partition table encrypted and loaded successfully");
return ESP_OK;
return err;
}
static esp_err_t encrypt_and_load_partition_table(uint32_t offset, esp_partition_info_t *partition_table, int *num_partitions)
{
esp_err_t err = read_and_verify_partition_table(offset, partition_table, num_partitions);
if (err != ESP_OK) {
return err;
}
ESP_LOGD(TAG, "partition table is plaintext. Encrypting...");
err = esp_flash_encrypt_region(offset, FLASH_SECTOR_SIZE);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to encrypt partition table in place. %x", err);
return err;
}
ESP_LOGI(TAG, "partition table encrypted and loaded successfully");
return err;
}
static esp_err_t encrypt_partition(int index, const esp_partition_info_t *partition)
{
@@ -402,19 +414,26 @@ static esp_err_t encrypt_partition(int index, const esp_partition_info_t *partit
bool should_encrypt = (partition->flags & PART_FLAG_ENCRYPTED);
uint32_t size = partition->pos.size;
if (partition->type == PART_TYPE_APP) {
/* check if the partition holds a valid unencrypted app */
if (partition->type == PART_TYPE_APP || partition->type == PART_TYPE_BOOTLOADER) {
/* check if the partition holds a valid unencrypted app/bootloader */
esp_image_metadata_t image_data = {};
err = esp_image_verify(ESP_IMAGE_VERIFY,
&partition->pos,
&image_data);
if (partition->type == PART_TYPE_BOOTLOADER) {
esp_image_bootloader_offset_set(partition->pos.offset);
}
err = esp_image_verify(ESP_IMAGE_VERIFY, &partition->pos, &image_data);
should_encrypt = (err == ESP_OK);
#ifdef CONFIG_SECURE_FLASH_ENCRYPT_ONLY_IMAGE_LEN_IN_APP_PART
if (should_encrypt) {
if (partition->type == PART_TYPE_APP && should_encrypt) {
// Encrypt only the app image instead of encrypting the whole partition
size = image_data.image_len;
}
#endif
} else if (partition->type == PART_TYPE_PARTITION_TABLE) {
/* check if the partition holds a valid unencrypted partition table */
esp_partition_info_t partition_table[ESP_PARTITION_TABLE_MAX_ENTRIES];
int num_partitions;
err = read_and_verify_partition_table(partition->pos.offset, partition_table, &num_partitions);
should_encrypt = (err == ESP_OK && num_partitions != 0);
} else if ((partition->type == PART_TYPE_DATA && partition->subtype == PART_SUBTYPE_DATA_OTA)
|| (partition->type == PART_TYPE_DATA && partition->subtype == PART_SUBTYPE_DATA_NVS_KEYS)) {
/* check if we have ota data partition and the partition should be encrypted unconditionally */

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -52,10 +52,11 @@ esp_err_t esp_partition_table_verify(const esp_partition_info_t *partition_table
}
return ESP_ERR_INVALID_STATE;
}
//MD5 checksum matches and we continue with the next interation in
//MD5 checksum matches and we continue with the next iteration in
//order to detect the end of the partition table
md5_found = 1;
} else if (part->magic == 0xFFFF
} else if (num_parts != 0 // the first record cannot be empty, otherwise the whole table is empty
&& part->magic == 0xFFFF
&& part->type == PART_TYPE_END
&& part->subtype == PART_SUBTYPE_END) {
ESP_LOGD(TAG, "partition table verified, %d entries", num_parts);

View File

@@ -4,7 +4,3 @@ components/bootloader_support/test_apps/rtc_custom_section:
enable:
- if: SOC_RTC_MEM_SUPPORTED == 1
reason: this feature is supported on chips that have RTC memory
disable:
- if: IDF_TARGET == "esp32c61"
temporary: true
reason: IDF-9260

View File

@@ -85,6 +85,9 @@ if(CONFIG_BT_ENABLED)
elseif(CONFIG_IDF_TARGET_ESP32S3)
list(APPEND ldscripts "linker_rw_bt_controller.lf")
elseif(CONFIG_IDF_TARGET_ESP32C2)
if(CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY)
list(APPEND srcs "controller/esp32c2/dummy.c")
endif()
set(ldscripts "linker_esp32c2.lf")
else()
list(APPEND ldscripts "linker_esp_ble_controller.lf")
@@ -865,11 +868,19 @@ if(CONFIG_BT_ENABLED)
elseif(CONFIG_IDF_TARGET_ESP32C3)
target_link_directories(${COMPONENT_LIB} INTERFACE
"${CMAKE_CURRENT_LIST_DIR}/controller/lib_esp32c3_family/esp32c3")
target_link_libraries(${COMPONENT_LIB} PUBLIC btdm_app)
if(CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY)
target_link_libraries(${COMPONENT_LIB} PUBLIC btdm_app_flash)
else()
target_link_libraries(${COMPONENT_LIB} PUBLIC btdm_app)
endif()
elseif(CONFIG_IDF_TARGET_ESP32S3)
target_link_directories(${COMPONENT_LIB} INTERFACE
"${CMAKE_CURRENT_LIST_DIR}/controller/lib_esp32c3_family/esp32s3")
target_link_libraries(${COMPONENT_LIB} PUBLIC btdm_app)
if(CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY)
target_link_libraries(${COMPONENT_LIB} PUBLIC btdm_app_flash)
else()
target_link_libraries(${COMPONENT_LIB} PUBLIC btdm_app)
endif()
elseif(CONFIG_BT_CONTROLLER_ENABLED)
if(CONFIG_IDF_TARGET_ESP32C6)
add_prebuilt_library(libble_app
@@ -878,8 +889,13 @@ if(CONFIG_BT_ENABLED)
add_prebuilt_library(libble_app
"${CMAKE_CURRENT_LIST_DIR}/controller/lib_esp32c6/esp32c6-bt-lib/esp32c61/libble_app.a")
else()
add_prebuilt_library(libble_app
"controller/lib_${target_name}/${target_name}-bt-lib/libble_app.a")
if(CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY)
add_prebuilt_library(libble_app
"controller/lib_${target_name}/${target_name}-bt-lib/libble_app_flash.a")
else()
add_prebuilt_library(libble_app
"controller/lib_${target_name}/${target_name}-bt-lib/libble_app.a")
endif()
endif()
target_link_libraries(${COMPONENT_LIB} PRIVATE libble_app)
endif()

View File

@@ -254,9 +254,9 @@ static const btc_func_t profile_tab[BTC_PID_NUM] = {
#if CONFIG_BLE_MESH_MBT_SRV
[BTC_PID_MBT_SERVER] = {btc_ble_mesh_mbt_server_call_handler, btc_ble_mesh_mbt_server_cb_handler },
#endif /* CONFIG_BLE_MESH_MBT_SRV */
#if CONFIG_BLE_MESH_BLE_COEX_SUPPORT
#if CONFIG_BLE_MESH_BLE_COEX_SUPPORT || CONFIG_BLE_MESH_USE_BLE_50
[BTC_PID_BLE_MESH_BLE_COEX] = {btc_ble_mesh_ble_call_handler, btc_ble_mesh_ble_cb_handler },
#endif /* CONFIG_BLE_MESH_BLE_COEX_SUPPORT */
#endif /* CONFIG_BLE_MESH_BLE_COEX_SUPPORT || CONFIG_BLE_MESH_USE_BLE_50 */
#endif /* #if CONFIG_BLE_MESH */
};
@@ -382,7 +382,7 @@ static void btc_deinit_mem(void) {
btc_profile_cb_tab = NULL;
}
#if (BLE_INCLUDED == TRUE)
#if (BLE_42_FEATURE_SUPPORT == TRUE)
if (gl_bta_adv_data_ptr) {
osi_free(gl_bta_adv_data_ptr);
gl_bta_adv_data_ptr = NULL;
@@ -392,7 +392,7 @@ static void btc_deinit_mem(void) {
osi_free(gl_bta_scan_rsp_data_ptr);
gl_bta_scan_rsp_data_ptr = NULL;
}
#endif ///BLE_INCLUDED == TRUE
#endif // BLE_42_FEATURE_SUPPORT
#if GATTS_INCLUDED == TRUE && GATT_DYNAMIC_MEMORY == TRUE
if (btc_creat_tab_env_ptr) {
@@ -444,7 +444,8 @@ static bt_status_t btc_init_mem(void) {
}
memset((void *)btc_profile_cb_tab, 0, sizeof(void *) * BTC_PID_NUM);
#if (BLE_INCLUDED == TRUE)
#if BTC_DYNAMIC_MEMORY == TRUE
#if (BLE_42_FEATURE_SUPPORT == TRUE)
if ((gl_bta_adv_data_ptr = (tBTA_BLE_ADV_DATA *)osi_malloc(sizeof(tBTA_BLE_ADV_DATA))) == NULL) {
goto error_exit;
}
@@ -454,7 +455,8 @@ static bt_status_t btc_init_mem(void) {
goto error_exit;
}
memset((void *)gl_bta_scan_rsp_data_ptr, 0, sizeof(tBTA_BLE_ADV_DATA));
#endif ///BLE_INCLUDED == TRUE
#endif // (BLE_42_FEATURE_SUPPORT == TRUE)
#endif // BTC_DYNAMIC_MEMORY == TRUE
#if GATTS_INCLUDED == TRUE && GATT_DYNAMIC_MEMORY == TRUE
if ((btc_creat_tab_env_ptr = (esp_btc_creat_tab_t *)osi_malloc(sizeof(esp_btc_creat_tab_t))) == NULL) {

View File

@@ -241,5 +241,8 @@ void *osi_calloc_func(size_t size)
void osi_free_func(void *ptr)
{
#if HEAP_MEMORY_DEBUG
osi_mem_dbg_clean(ptr, __func__, __LINE__);
#endif
free(ptr);
}

View File

@@ -29,6 +29,15 @@ void *osi_malloc_func(size_t size);
void *osi_calloc_func(size_t size);
void osi_free_func(void *ptr);
// Memory alloc function without print and assertion
#if HEAP_ALLOCATION_FROM_SPIRAM_FIRST
#define osi_malloc_base(size) heap_caps_malloc_prefer(size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL)
#define osi_calloc_base(size) heap_caps_calloc_prefer(1, size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL)
#else
#define osi_malloc_base(size) malloc((size))
#define osi_calloc_base(size) calloc(1, (size))
#endif /* #if HEAP_ALLOCATION_FROM_SPIRAM_FIRST */
#if HEAP_MEMORY_DEBUG
void osi_mem_dbg_init(void);
@@ -41,13 +50,10 @@ void osi_men_dbg_set_section_start(uint8_t index);
void osi_men_dbg_set_section_end(uint8_t index);
uint32_t osi_mem_dbg_get_max_size_section(uint8_t index);
#if HEAP_ALLOCATION_FROM_SPIRAM_FIRST
#define osi_malloc(size) \
({ \
void *p; \
p = heap_caps_malloc_prefer(size, 2, \
MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, \
MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL); \
p = osi_malloc_base(size); \
osi_mem_dbg_record(p, size, __func__, __LINE__); \
(void *)p; \
})
@@ -55,34 +61,11 @@ uint32_t osi_mem_dbg_get_max_size_section(uint8_t index);
#define osi_calloc(size) \
({ \
void *p; \
p = heap_caps_calloc_prefer(1, size, 2, \
MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, \
MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL); \
p = osi_calloc_base(size); \
osi_mem_dbg_record(p, size, __func__, __LINE__); \
(void *)p; \
})
#else
#define osi_malloc(size) \
({ \
void *p; \
p = malloc((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; \
})
#endif /* #if HEAP_ALLOCATION_FROM_SPIRAM_FIRST */
#if 0
#define osi_malloc(size) \
do { \
@@ -122,15 +105,6 @@ do { \
#else
// Memory alloc function without print and assertion
#if HEAP_ALLOCATION_FROM_SPIRAM_FIRST
#define osi_malloc_base(size) heap_caps_malloc_prefer(size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL)
#define osi_calloc_base(size) heap_caps_calloc_prefer(1, size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL)
#else
#define osi_malloc_base(size) malloc((size))
#define osi_calloc_base(size) calloc(1, (size))
#endif /* #if HEAP_ALLOCATION_FROM_SPIRAM_FIRST */
// Memory alloc function with print and assertion when fails
#define osi_malloc(size) osi_malloc_func((size))
#define osi_calloc(size) osi_calloc_func((size))

View File

@@ -444,6 +444,15 @@ config BTDM_CTRL_SCAN_BACKOFF_UPPERLIMITMAX
minimize collision of scan request PDUs from nultiple scanners. If scan backoff is disabled, in active
scanning, scan request PDU will be sent every time when HW receives scannable ADV PDU.
config BTDM_CTRL_CHECK_CONNECT_IND_ACCESS_ADDRESS
bool "Enable enhanced Access Address check in CONNECT_IND"
default n
help
Enabling this option will add stricter verification of the Access Address in the CONNECT_IND PDU.
This improves security by ensuring that only connection requests with valid Access Addresses are accepted.
If disabled, only basic checks are applied, improving compatibility.
config BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP
bool "BLE adv report flow control supported"
depends on (BTDM_CTRL_MODE_BTDM || BTDM_CTRL_MODE_BLE_ONLY)

View File

@@ -109,86 +109,100 @@ menuconfig BT_LE_50_FEATURE_SUPPORT
help
Enable BLE 5 feature
config BT_LE_LL_CFG_FEAT_LE_2M_PHY
bool "Enable 2M Phy"
depends on BT_LE_50_FEATURE_SUPPORT
default y
help
Enable 2M-PHY
config BT_LE_LL_CFG_FEAT_LE_CODED_PHY
bool "Enable coded Phy"
depends on BT_LE_50_FEATURE_SUPPORT
default y
help
Enable coded-PHY
config BT_LE_EXT_ADV
bool "Enable extended advertising"
depends on BT_LE_50_FEATURE_SUPPORT
default y
help
Enable this option to do extended advertising. Extended advertising
will be supported from BLE 5.0 onwards.
if BT_LE_EXT_ADV
config BT_LE_MAX_EXT_ADV_INSTANCES
int "Maximum number of extended advertising instances."
range 0 4
default 1
depends on BT_LE_EXT_ADV
help
Change this option to set maximum number of extended advertising
instances. Minimum there is always one instance of
advertising. Enter how many more advertising instances you
want.
Each extended advertising instance will take about 0.5k DRAM.
config BT_LE_EXT_ADV_MAX_SIZE
int "Maximum length of the advertising data."
range 0 1650
default 1650
depends on BT_LE_EXT_ADV
help
Defines the length of the extended adv data. The value should not
exceed 1650.
config BT_LE_ENABLE_PERIODIC_ADV
bool "Enable periodic advertisement."
default y
depends on BT_LE_EXT_ADV
help
Enable this option to start periodic advertisement.
config BT_LE_PERIODIC_ADV_SYNC_TRANSFER
bool "Enable Transfer Sync Events"
depends on BT_LE_ENABLE_PERIODIC_ADV
if BT_LE_50_FEATURE_SUPPORT
config BT_LE_LL_CFG_FEAT_LE_2M_PHY
bool "Enable 2M Phy"
depends on BT_LE_50_FEATURE_SUPPORT
default y
help
This enables controller transfer periodic sync events to host
Enable 2M-PHY
config BT_LE_LL_CFG_FEAT_LE_CODED_PHY
bool "Enable coded Phy"
depends on BT_LE_50_FEATURE_SUPPORT
default y
help
Enable coded-PHY
config BT_LE_EXT_ADV
bool "Enable extended advertising"
depends on BT_LE_50_FEATURE_SUPPORT
default y
help
Enable this option to do extended advertising. Extended advertising
will be supported from BLE 5.0 onwards.
if BT_LE_EXT_ADV
config BT_LE_MAX_EXT_ADV_INSTANCES
int "Maximum number of extended advertising instances."
range 0 4
default 1
depends on BT_LE_EXT_ADV
help
Change this option to set maximum number of extended advertising
instances. Minimum there is always one instance of
advertising. Enter how many more advertising instances you
want.
Each extended advertising instance will take about 0.5k DRAM.
config BT_LE_EXT_ADV_MAX_SIZE
int "Maximum length of the advertising data."
range 0 1650
default 1650
depends on BT_LE_EXT_ADV
help
Defines the length of the extended adv data. The value should not
exceed 1650.
config BT_LE_ENABLE_PERIODIC_ADV
bool "Enable periodic advertisement."
default y
depends on BT_LE_EXT_ADV
help
Enable this option to start periodic advertisement.
config BT_LE_PERIODIC_ADV_SYNC_TRANSFER
bool "Enable Transfer Sync Events"
depends on BT_LE_ENABLE_PERIODIC_ADV
default y
help
This enables controller transfer periodic sync events to host
endif
config BT_LE_EXT_SCAN
bool "Enable extended scanning"
depends on BT_LE_50_FEATURE_SUPPORT && BT_LE_ROLE_OBSERVER_ENABLE
default y
help
Enable this option to do extended scanning.
config BT_LE_ENABLE_PERIODIC_SYNC
bool "Enable periodic sync"
default y
depends on BT_LE_EXT_SCAN
help
Enable this option to receive periodic advertisement.
if BT_LE_ENABLE_PERIODIC_SYNC
config BT_LE_MAX_PERIODIC_SYNCS
int "Maximum number of periodic advertising syncs"
range 0 3
default 1 if BT_LE_ENABLE_PERIODIC_ADV
default 0
help
Set this option to set the upper limit for number of periodic sync
connections. This should be less than maximum connections allowed by
controller.
config BT_LE_MAX_PERIODIC_ADVERTISER_LIST
int "Maximum number of periodic advertiser list"
range 1 5
default 5
help
Set this option to set the upper limit for number of periodic advertiser list.
endif
endif
config BT_LE_MAX_PERIODIC_SYNCS
int "Maximum number of periodic advertising syncs"
depends on BT_LE_50_FEATURE_SUPPORT && !BT_NIMBLE_ENABLED
range 0 3
default 1 if BT_LE_ENABLE_PERIODIC_ADV
default 0
help
Set this option to set the upper limit for number of periodic sync
connections. This should be less than maximum connections allowed by
controller.
config BT_LE_MAX_PERIODIC_ADVERTISER_LIST
int "Maximum number of periodic advertiser list"
depends on BT_LE_50_FEATURE_SUPPORT && !BT_NIMBLE_ENABLED
range 1 5
default 5
help
Set this option to set the upper limit for number of periodic advertiser list.
menu "Memory Settings"
depends on !BT_NIMBLE_ENABLED
@@ -523,6 +537,10 @@ config BT_LE_TX_CCA_ENABLED
help
Enable CCA feature to cancel sending the packet if the signal power is stronger than CCA threshold.
config BT_LE_DTM_ENABLED
bool "Enable Direct Test Mode (DTM) feature"
default n
config BT_LE_CCA_RSSI_THRESH
int "CCA RSSI threshold value"
depends on BT_LE_TX_CCA_ENABLED
@@ -531,6 +549,10 @@ config BT_LE_CCA_RSSI_THRESH
help
Power threshold of CCA in unit of -1 dBm.
config BT_LE_FEAT_LL_ENCRYPTION
bool "Enable controller ACL encryption"
default y
config BT_LE_ROLE_CENTROL_ENABLE
bool "Enable BLE Centrol role function"
depends on !BT_NIMBLE_ENABLED
@@ -617,3 +639,23 @@ config BT_LE_DFT_TX_POWER_LEVEL_DBM_EFF
default 18 if BT_LE_DFT_TX_POWER_LEVEL_P18
default 20 if BT_LE_DFT_TX_POWER_LEVEL_P20
default 0
config BT_CTRL_RUN_IN_FLASH_ONLY
bool "Reduce BLE IRAM usage (READ DOCS FIRST) (EXPERIMENTAL)"
default n
help
Move most IRAM into flash. This will increase the usage of flash and reduce ble performance.
Because the code is moved to the flash, the execution speed of the code is reduced.
To have a small impact on performance, you need to enable flash suspend (SPI_FLASH_AUTO_SUSPEND).
- Only one Tx-Rx can be performed in each connection interval. Therefore, reduce the connection interval
as much as possible to improve the throughput. If you want higher connection performance, you can
enable BT_LE_PLACE_CONN_RELATED_INTO_IRAM to put the connection-related code into iram.
- For HCI_LE_Extended_Create_Connection command, only 1M phy's connection parameters will be applied.
Other phys' will be ignored.
- For extended scanning, we may be unable to receive the extended adv with 300us MAFS.
config BT_LE_PLACE_CONN_RELATED_INTO_IRAM
bool "Place the connection-related code into IRAM"
depends on BT_CTRL_RUN_IN_FLASH_ONLY
default n

View File

@@ -156,6 +156,10 @@ extern int ble_get_npl_element_info(esp_bt_controller_config_t *cfg, ble_npl_cou
extern void bt_track_pll_cap(void);
extern char *ble_controller_get_compile_version(void);
extern const char *r_ble_controller_get_rom_compile_version(void);
#if CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY
extern void ble_ll_supported_features_init(void);
#endif //CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY
#if CONFIG_BT_RELEASE_IRAM
extern uint32_t _iram_bt_text_start;
extern uint32_t _bss_bt_end;
@@ -534,7 +538,12 @@ static int esp_ecc_gen_dh_key(const uint8_t *peer_pub_key_x, const uint8_t *peer
static int esp_intr_alloc_wrapper(int source, int flags, intr_handler_t handler, void *arg, void **ret_handle_in)
{
#if CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY
int rc = esp_intr_alloc(source, flags, handler, arg, (intr_handle_t *)ret_handle_in);
#else
int rc = esp_intr_alloc(source, flags | ESP_INTR_FLAG_IRAM, handler, arg, (intr_handle_t *)ret_handle_in);
#endif
return rc;
}
@@ -743,6 +752,8 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
return ret;
}
/* If we place the ble code into flash, don't need to initialize ROM. */
#if !CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY
#if DEFAULT_BT_LE_50_FEATURE_SUPPORT || DEFAULT_BT_LE_ROLE_CENTROL || DEFAULT_BT_LE_ROLE_OBSERVER
extern int esp_ble_rom_func_ptr_init_all(void);
esp_ble_rom_func_ptr_init_all();
@@ -751,6 +762,7 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
extern int esp_ble_rom_func_ptr_init_legacy_adv_and_slave(void);
esp_ble_rom_func_ptr_init_legacy_adv_and_slave();
#endif
#endif //!CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY
/* Initialize the function pointers for OS porting */
npl_freertos_funcs_init();
@@ -800,6 +812,11 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
#if CONFIG_SW_COEXIST_ENABLE
coex_init();
#endif
#if CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY
ble_ll_supported_features_init();
#endif //CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY
ret = ble_controller_init(cfg);
if (ret != ESP_OK) {
ESP_LOGW(NIMBLE_PORT_LOG_TAG, "ble_controller_init failed %d", ret);

View File

@@ -0,0 +1,320 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "esp_bt_cfg.h"
#define BLE_ERR_UNKNOWN_HCI_CMD (0x01)
/* LL Features */
#define BLE_LL_FEAT_LE_ENCRYPTION (0x0000000001)
#define BLE_LL_FEAT_CONN_PARM_REQ (0x0000000002)
#define BLE_LL_FEAT_EXTENDED_REJ (0x0000000004)
#define BLE_LL_FEAT_PERIPH_INIT (0x0000000008)
#define BLE_LL_FEAT_LE_PING (0x0000000010)
#define BLE_LL_FEAT_DATA_LEN_EXT (0x0000000020)
#define BLE_LL_FEAT_LL_PRIVACY (0x0000000040)
#define BLE_LL_FEAT_EXT_SCAN_FILT (0x0000000080)
#define BLE_LL_FEAT_LE_2M_PHY (0x0000000100)
#define BLE_LL_FEAT_STABLE_MOD_ID_TX (0x0000000200)
#define BLE_LL_FEAT_STABLE_MOD_ID_RX (0x0000000400)
#define BLE_LL_FEAT_LE_CODED_PHY (0x0000000800)
#define BLE_LL_FEAT_EXT_ADV (0x0000001000)
#define BLE_LL_FEAT_PERIODIC_ADV (0x0000002000)
#define BLE_LL_FEAT_CSA2 (0x0000004000)
#define BLE_LL_FEAT_LE_POWER_CLASS_1 (0x0000008000)
#define BLE_LL_FEAT_MIN_USED_CHAN (0x0000010000)
#define BLE_LL_FEAT_CTE_REQ (0x0000020000)
#define BLE_LL_FEAT_CTE_RSP (0x0000040000)
#define BLE_LL_FEAT_CTE_TX (0x0000080000)
#define BLE_LL_FEAT_CTE_RX (0x0000100000)
#define BLE_LL_FEAT_CTE_AOD (0x0000200000)
#define BLE_LL_FEAT_CTE_AOA (0x0000400000)
#define BLE_LL_FEAT_CTE_RECV (0x0000800000)
#define BLE_LL_FEAT_SYNC_TRANS_SEND (0x0001000000)
#define BLE_LL_FEAT_SYNC_TRANS_RECV (0x0002000000)
#define BLE_LL_FEAT_SCA_UPDATE (0x0004000000)
#define BLE_LL_FEAT_REM_PKEY (0x0008000000)
#define BLE_LL_FEAT_CIS_CENTRAL (0x0010000000)
#define BLE_LL_FEAT_CIS_PERIPH (0x0020000000)
#define BLE_LL_FEAT_ISO_BROADCASTER (0x0040000000)
#define BLE_LL_FEAT_SYNC_RECV (0x0080000000)
#define BLE_LL_FEAT_CIS_HOST (0x0100000000)
#define BLE_LL_FEAT_POWER_CTRL_REQ (0x0200000000)
#define BLE_LL_FEAT_POWER_CHANGE_IND (0x0400000000)
#define BLE_LL_FEAT_PATH_LOSS_MON (0x0800000000)
#define BLE_LL_FEAT_PERIODIC_ADV_ADI (0x1000000000)
#define BLE_LL_FEAT_CONN_SUBRATING (0x2000000000)
#define BLE_LL_FEAT_CONN_SUBRATING_HOST (0x4000000000)
#define BLE_LL_FEAT_CHANNEL_CLASS (0x8000000000)
uint64_t ble_ll_supported_features;
void
ble_ll_supported_features_init(void)
{
ble_ll_supported_features = BLE_LL_FEAT_EXTENDED_REJ;
ble_ll_supported_features |= BLE_LL_FEAT_DATA_LEN_EXT;
#if DEFAULT_BT_LE_ROLE_CENTROL || DEFAULT_BT_LE_ROLE_PERIPHERAL
ble_ll_supported_features |= BLE_LL_FEAT_PERIPH_INIT;
ble_ll_supported_features |= BLE_LL_FEAT_CONN_PARM_REQ;
#endif
#if CONFIG_BT_LE_FEAT_LL_ENCRYPTION
ble_ll_supported_features |= BLE_LL_FEAT_LE_ENCRYPTION;
#endif
ble_ll_supported_features |= (BLE_LL_FEAT_LL_PRIVACY | BLE_LL_FEAT_EXT_SCAN_FILT);
ble_ll_supported_features |= BLE_LL_FEAT_LE_PING;
#if DEFAULT_BT_LE_EXT_ADV
ble_ll_supported_features |= BLE_LL_FEAT_EXT_ADV;
#endif
#if DEFAULT_BT_LE_PERIODIC_ADV
ble_ll_supported_features |= BLE_LL_FEAT_PERIODIC_ADV;
ble_ll_supported_features |= BLE_LL_FEAT_PERIODIC_ADV_ADI;
#endif
#if DEFAULT_BT_LE_PAST
ble_ll_supported_features |= BLE_LL_FEAT_SYNC_TRANS_RECV;
ble_ll_supported_features |= BLE_LL_FEAT_SYNC_TRANS_SEND;
#endif
#if DEGAULT_BT_LE_2M_PHY
ble_ll_supported_features |= BLE_LL_FEAT_LE_2M_PHY;
#endif
#if DEGAULT_BT_LE_CODED_PHY
ble_ll_supported_features |= BLE_LL_FEAT_LE_CODED_PHY;
#endif
#if DEFAULT_BT_LE_50_FEATURE_SUPPORT
ble_ll_supported_features |= BLE_LL_FEAT_CSA2;
ble_ll_supported_features |= BLE_LL_FEAT_SCA_UPDATE;
ble_ll_supported_features |= BLE_LL_FEAT_REM_PKEY;
ble_ll_supported_features |= BLE_LL_FEAT_CHANNEL_CLASS;
#endif
}
#if !DEFAULT_BT_LE_ROLE_BROADCASTER
void r_ble_ll_adv_rpa_timeout(void) { }
void r_ble_lll_adv_halt(void) { }
void r_ble_lll_adv_event_rmvd_from_sched(void) { }
void r_ble_lll_adv_ext_event_rmvd_from_sched(void) { }
int r_ble_ll_adv_enabled(void) { return 0; }
int r_ble_ll_adv_can_chg_whitelist(void) { return 1; }
int r_ble_ll_adv_set_random_addr(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
void r_ble_ll_adv_reset(void) { }
void r_ble_ll_adv_init(void) { }
void r_ble_ll_adv_deinit(void) { }
int r_ble_ll_adv_env_init(void) { return 0; }
void r_ble_ll_adv_env_deinit(void) { }
int r_ble_lll_adv_rx_pkt_isr(void) { return -1; }
void r_ble_ll_adv_rx_pkt_in(void) { }
int r_ble_ll_adv_set_adv_params(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
int r_ble_ll_adv_read_txpwr(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
int r_ble_ll_hci_set_adv_data(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
int r_ble_ll_hci_set_scan_rsp_data(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
int r_ble_ll_hci_adv_set_enable(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
int r_ble_ll_adv_vendor_hci_legacy_adv_clear(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
int r_ble_ll_adv_set_data_related_addr_change(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
#endif // !DEFAULT_BT_LE_ROLE_BROADCASTER
#if !DEFAULT_BT_LE_EXT_ADV
bool r_ble_ll_adv_ext_check_data_itvl(void) { return true; }
void r_ble_lll_adv_coex_dpc_update_on_aux_scheduled(void) { }
void r_ble_lll_adv_coex_dpc_calc_pti_update_itvl(void) { }
void r_ble_lll_adv_sec_done(void) { }
int r_ble_lll_adv_sec_schedule_next_aux(void) { return 0; }
void r_ble_lll_adv_sec_event_done(void) { }
int r_ble_lll_adv_secondary_tx_start_cb(void) { return 0; }
void r_ble_lll_adv_aux_schedule(void) { }
void r_ble_lll_adv_update_rsp_offset(void) { }
int r_ble_ll_adv_hci_set_random_addr(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
int r_ble_ll_adv_ext_set_param(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
int r_ble_ll_adv_ext_set_adv_data(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
int r_ble_ll_adv_ext_set_scan_rsp(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
int r_ble_ll_adv_ext_set_enable(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
int r_ble_ll_adv_rd_max_adv_data_len(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
int r_ble_ll_adv_rd_sup_adv_sets(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
int r_ble_ll_adv_remove(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
int r_ble_ll_adv_clear_all(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
#endif //!DEFAULT_BT_LE_EXT_ADV
#if !DEFAULT_BT_LE_PERIODIC_ADV
void r_ble_ll_adv_sm_stop_periodic(void) { }
void r_ble_lll_adv_periodic_event_done(void) { }
int r_ble_lll_adv_sync_tx_start_cb(void) { return 0; }
void r_ble_lll_adv_sync_tx_end(void) { }
int r_ble_lll_adv_periodic_start(void) { return 0; }
void r_ble_lll_adv_periodic_rmvd_from_sched(void) { }
int r_ble_ll_adv_periodic_set_param(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
int r_ble_ll_adv_periodic_set_data(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
int r_ble_ll_adv_periodic_enable(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
#endif //!DEFAULT_BT_LE_PERIODIC_ADV
#if !DEFAULT_BT_LE_ROLE_OBSERVER
void r_ble_lll_scan_halt(void) { }
void r_ble_ll_scan_end_adv_evt(void) { }
void r_ble_ll_scan_rx_pkt_in(void) { }
int r_ble_lll_scan_rx_pkt_isr(void) { return -1; }
int r_ble_ll_scan_env_init(void) { return 0; }
void r_ble_ll_scan_env_deinit(void) { }
void r_ble_ll_scan_init(void) { }
void r_ble_ll_scan_deinit(void) { }
void r_ble_ll_scan_reset(void) { }
int r_ble_ll_scan_can_chg_whitelist(void) { return 1; }
int r_ble_ll_scan_enabled(void) { return false; }
int r_ble_lll_scan_chk_resume(void) { return -1; }
int r_ble_ll_scan_set_scan_params(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
int r_ble_ll_hci_scan_set_enable(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
int r_ble_ll_scan_hci_update_adv_report_flow_ctrl(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
int r_ble_ll_scan_hci_set_adv_report_flow_ctrl(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
#endif //!DEFAULT_BT_LE_ROLE_OBSERVER
#if !DEFAULT_BT_LE_EXT_SCAN
void r_ble_lll_scan_duration_period_timers_restart(void) { }
void r_ble_lll_scan_duration_period_timers_stop(void) { }
int r_ble_ll_hci_send_legacy_ext_adv_report(void) { return -1; }
void r_ble_lll_sched_rmv_elem_type(void) { }
void r_ble_ll_scan_send_truncated(void) { }
void r_ble_ll_scan_aux_data_unref(void) { }
void r_ble_lll_scan_sched_remove(void) { }
void r_ble_lll_scan_aux_data_free(void) { }
void r_ble_lll_aux_scan_drop(void) { }
int r_ble_lll_sched_aux_scan(void) { return -1; }
int r_ble_lll_scan_rx_isr_on_aux(void) { return -1; }
void r_ble_lll_scan_period_timer_cb(void) { }
void r_ble_lll_scan_duration_timer_cb(void) { }
void r_ble_ll_scan_rx_pkt_in_on_aux(void) { }
int r_ble_ll_set_ext_scan_params(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
int r_ble_ll_hci_ext_scan_set_enable(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
#endif //!DEFAULT_BT_LE_EXT_SCAN
#if !DEFAULT_BT_LE_ROLE_CENTROL
void r_ble_ll_init_rx_pkt_in(void) { }
int r_ble_lll_init_rx_pkt_isr(void) { return -1; }
int r_ble_ll_conn_create(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
int r_ble_ll_conn_create_cancel(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
#endif //!DEFAULT_BT_LE_ROLE_CENTROL
#if !DEFAULT_BT_LE_ROLE_CENTROL || !DEFAULT_BT_LE_EXT_SCAN
int r_ble_ll_ext_conn_create(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
#endif //!DEFAULT_BT_LE_ROLE_CENTROL || !DEFAULT_BT_LE_EXT_SCAN
#if !DEFAULT_BT_LE_ROLE_PERIPHERAL
int r_ble_ll_conn_slave_start(void) { return 0; }
#endif //!DEFAULT_BT_LE_ROLE_PERIPHERAL
#if !DEFAULT_BT_LE_ROLE_CENTROL && !DEFAULT_BT_LE_ROLE_PERIPHERAL
void r_ble_ll_conn_rx_data_pdu(void) { }
int r_ble_lll_conn_rx_pkt_isr(void) { return -1; }
int r_ble_ll_hci_disconnect(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
int r_ble_ll_conn_hci_rd_rem_ver_cmd(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
int r_ble_ll_conn_hci_update(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
int r_ble_ll_conn_hci_rd_chan_map(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
int r_ble_ll_conn_hci_read_rem_features(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
int r_ble_ll_conn_hci_param_rr(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
int r_ble_ll_conn_hci_param_nrr(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
#endif //!DEFAULT_BT_LE_ROLE_CENTROL && !DEFAULT_BT_LE_ROLE_PERIPHERAL
#if !CONFIG_BT_LE_FEAT_LL_ENCRYPTION
int r_ble_ll_conn_chk_phy_upd_start(void) { return -1; }
void r_ble_ll_hci_ev_encrypt_chg(void) { }
int r_ble_ll_ctrl_enc_allowed_pdu_rx(void) { return 1; }
int r_ble_ll_ctrl_enc_allowed_pdu_tx(void) { return 1; }
uint8_t r_ble_ll_ctrl_rx_start_enc_rsp(void) { return 0x07; }
uint8_t r_ble_ll_ctrl_rx_pause_enc_rsp(void) { return 0x07; }
int r_ble_ll_hci_le_encrypt(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
#endif //!CONFIG_BT_LE_FEAT_LL_ENCRYPTION
#if !DEFAULT_BT_LE_ROLE_PERIPHERAL || !CONFIG_BT_LE_FEAT_LL_ENCRYPTION
uint8_t r_ble_ll_ctrl_rx_pause_enc_req(void) { return 0x07; }
uint8_t r_ble_ll_ctrl_rx_enc_req(void) { return 0x07; }
int r_ble_ll_conn_hci_le_ltk_reply(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
int r_ble_ll_conn_hci_le_ltk_neg_reply(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
#endif //!DEFAULT_BT_LE_ROLE_PERIPHERAL || !CONFIG_BT_LE_FEAT_LL_ENCRYPTION
#if !DEFAULT_BT_LE_ROLE_CENTROL || !CONFIG_BT_LE_FEAT_LL_ENCRYPTION
uint8_t r_ble_ll_ctrl_rx_start_enc_req(void) { return 0x07; }
void r_ble_ll_ctrl_rx_enc_rsp(void) { }
void r_ble_ll_ctrl_enc_req_make(void) { }
int r_ble_ll_conn_hci_le_start_encrypt(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
#endif //!DEFAULT_BT_LE_ROLE_CENTROL || !CONFIG_BT_LE_FEAT_LL_ENCRYPTION
#if !DEGAULT_BT_LE_2M_PHY && !DEGAULT_BT_LE_CODED_PHY
void r_ble_ll_ctrl_phy_update_proc_complete(void) { }
void r_ble_ll_ctrl_phy_update_cancel(void) { }
uint8_t r_ble_ll_ctrl_rx_phy_update_ind(void) { return 0x07; }
uint8_t r_ble_ll_ctrl_rx_phy_rsp(void) { return 0x07; }
uint8_t r_ble_ll_ctrl_rx_phy_req(void) { return 0x07; }
void r_ble_ll_ctrl_phy_req_rsp_make(void) { }
#endif //DEGAULT_BT_LE_2M_PHY && DEGAULT_BT_LE_CODED_PHY
#if !DEFAULT_BT_LE_PERIODIC_SYNC
void r_ble_lll_sync_halt(void) { }
void r_ble_lll_sync_rmvd_from_sched(void) { }
int r_ble_ll_sync_list_search(void) { return -1; }
uint8_t r_ble_ll_ctrl_rx_periodic_sync_ind(void) { return 0x07; }
void r_ble_ll_sync_rx_pkt_in(void) { }
int r_ble_lll_sync_rx_pkt_isr(void) { return -1; }
int r_ble_ll_sync_env_init(void) { return 0; }
void r_ble_ll_sync_env_deinit(void) { }
void r_ble_ll_sync_init(void) { }
void r_ble_ll_sync_deinit(void) { }
void r_ble_ll_sync_reset(void) { }
bool r_ble_ll_sync_enabled(void) { return false; }
int r_ble_ll_sync_create(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
int r_ble_ll_sync_cancel(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
int r_ble_ll_sync_terminate(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
int r_ble_ll_sync_list_add(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
int r_ble_ll_sync_list_remove(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
int r_ble_ll_sync_list_clear(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
int r_ble_ll_sync_list_size(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
int r_ble_ll_sync_receive_enable(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
#endif //!DEFAULT_BT_LE_PERIODIC_SYNC
#if !DEFAULT_BT_LE_PAST || !DEFAULT_BT_LE_PERIODIC_ADV
int r_ble_ll_adv_periodic_set_info_transfer(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
#endif //!DEFAULT_BT_LE_PAST || !DEFAULT_BT_LE_PERIODIC_ADV
#if !DEFAULT_BT_LE_PAST || !DEFAULT_BT_LE_PERIODIC_SYNC
int r_ble_ll_sync_transfer(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
int r_ble_ll_set_sync_transfer_params(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
int r_ble_ll_set_default_sync_transfer_params(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
#endif //!DEFAULT_BT_LE_PAST || !DEFAULT_BT_LE_PERIODIC_SYNC
#if !DEFAULT_BT_LE_50_FEATURE_SUPPORT
uint8_t r_ble_ll_ctrl_rx_channel_reporting_ind(void) { return 0x07; }
uint8_t r_ble_ll_ctrl_rx_channel_status_ind(void) { return 0x07; }
uint8_t r_ble_ll_ctrl_rx_sca_req(void) { return 0x07; }
uint8_t r_ble_ll_ctrl_rx_sca_rsp(void) { return 0x07; }
void r_ble_ll_ctrl_channel_class_reporting_make(void) { }
void r_ble_ll_ctrl_channel_class_enable_make(void) { }
void r_ble_ll_ctrl_sca_req_rsp_make(void) { }
int r_ble_ll_modify_sca(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
int r_ble_ll_conn_req_peer_sca(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
#endif //!DEFAULT_BT_LE_50_FEATURE_SUPPORT
#if !DEFAULT_BT_LE_50_FEATURE_SUPPORT
int r_ble_ll_conn_hci_le_rd_phy(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
int r_ble_ll_hci_le_set_def_phy(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
int r_ble_ll_conn_hci_le_set_phy(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
#endif //!DEFAULT_BT_LE_50_FEATURE_SUPPORT
#if !CONFIG_BT_LE_DTM_ENABLED
void r_ble_lll_dtm_rx_pkt_in(void) { }
int r_ble_lll_dtm_rx_isr_end(void) { return -1; }
void r_ble_lll_dtm_reset(void) { }
void r_ble_lll_dtm_init(void) { }
void r_ble_lll_dtm_deinit(void) { }
int r_ble_lll_dtm_env_init(void) { return 0; }
void r_ble_lll_dtm_env_deinit(void) { }
int r_ble_lll_hci_dtm_tx_test(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
int r_ble_lll_hci_dtm_rx_test(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
int r_ble_lll_dtm_end_test(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
int r_ble_lll_hci_dtm_rx_test_v2(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
int r_ble_lll_hci_dtm_tx_test_v2(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
#endif //!CONFIG_BT_LE_DTM_ENABLED

View File

@@ -45,6 +45,14 @@ extern "C" {
#define DEFAULT_BT_LE_50_FEATURE_SUPPORT (0)
#endif
#define DEGAULT_BT_LE_2M_PHY (CONFIG_BT_NIMBLE_LL_CFG_FEAT_LE_2M_PHY)
#define DEGAULT_BT_LE_CODED_PHY (CONFIG_BT_NIMBLE_LL_CFG_FEAT_LE_CODED_PHY)
#define DEFAULT_BT_LE_EXT_ADV (CONFIG_BT_NIMBLE_EXT_ADV)
#define DEFAULT_BT_LE_PERIODIC_ADV (CONFIG_BT_NIMBLE_ENABLE_PERIODIC_ADV)
#define DEFAULT_BT_LE_EXT_SCAN (CONFIG_BT_NIMBLE_EXT_SCAN)
#define DEFAULT_BT_LE_PERIODIC_SYNC (CONFIG_BT_NIMBLE_ENABLE_PERIODIC_SYNC)
#define DEFAULT_BT_LE_PAST (CONFIG_BT_NIMBLE_PERIODIC_ADV_SYNC_TRANSFER)
#define DEFAULT_BT_LE_ROLE_OBSERVER MYNEWT_VAL(BLE_ROLE_OBSERVER)
#define DEFAULT_BT_LE_ROLE_CENTROL MYNEWT_VAL(BLE_ROLE_CENTRAL)
#define DEFAULT_BT_LE_ROLE_PERIPHERAL MYNEWT_VAL(BLE_ROLE_PERIPHERAL)
@@ -122,12 +130,55 @@ extern "C" {
#else
#define DEFAULT_BT_LE_HCI_EVT_LO_BUF_COUNT (8)
#endif
#if defined(CONFIG_BT_LE_50_FEATURE_SUPPORT)
#define DEFAULT_BT_LE_50_FEATURE_SUPPORT (1)
#else
#define DEFAULT_BT_LE_50_FEATURE_SUPPORT (0)
#endif
#if defined(CONFIG_BT_LE_LL_CFG_FEAT_LE_2M_PHY)
#define DEGAULT_BT_LE_2M_PHY (CONFIG_BT_LE_LL_CFG_FEAT_LE_2M_PHY)
#else
#define DEGAULT_BT_LE_2M_PHY (0)
#endif
#if defined(CONFIG_BT_LE_LL_CFG_FEAT_LE_CODED_PHY)
#define DEGAULT_BT_LE_CODED_PHY (CONFIG_BT_LE_LL_CFG_FEAT_LE_CODED_PHY)
#else
#define DEGAULT_BT_LE_CODED_PHY (0)
#endif
#if defined(CONFIG_BT_LE_EXT_ADV)
#define DEFAULT_BT_LE_EXT_ADV (CONFIG_BT_LE_EXT_ADV)
#else
#define DEFAULT_BT_LE_EXT_ADV (0)
#endif
#if defined(CONFIG_BT_LE_ENABLE_PERIODIC_ADV)
#define DEFAULT_BT_LE_PERIODIC_ADV (CONFIG_BT_LE_ENABLE_PERIODIC_ADV)
#else
#define DEFAULT_BT_LE_PERIODIC_ADV (0)
#endif
#if defined(CONFIG_BT_LE_EXT_SCAN)
#define DEFAULT_BT_LE_EXT_SCAN (CONFIG_BT_LE_EXT_SCAN)
#else
#define DEFAULT_BT_LE_EXT_SCAN (0)
#endif
#if defined(CONFIG_BT_LE_ENABLE_PERIODIC_SYNC)
#define DEFAULT_BT_LE_PERIODIC_SYNC (CONFIG_BT_LE_ENABLE_PERIODIC_SYNC)
#else
#define DEFAULT_BT_LE_PERIODIC_SYNC (0)
#endif
#if defined(BT_LE_PERIODIC_ADV_SYNC_TRANSFER)
#define DEFAULT_BT_LE_PAST (BT_LE_PERIODIC_ADV_SYNC_TRANSFER)
#else
#define DEFAULT_BT_LE_PAST (0)
#endif
#if defined(CONFIG_BT_LE_ROLE_CENTROL_ENABLE)
#define DEFAULT_BT_LE_ROLE_CENTROL (1)
#else

View File

@@ -226,6 +226,7 @@ config BT_CTRL_DFT_TX_POWER_LEVEL_EFF
config BT_CTRL_BLE_ADV_REPORT_FLOW_CTRL_SUPP
bool "BLE adv report flow control supported"
depends on (!BT_CTRL_RUN_IN_FLASH_ONLY) || (BT_CTRL_RUN_IN_FLASH_ONLY && BT_CTRL_BLE_SCAN)
default y
help
The function is mainly used to enable flow control for advertising reports. When it is enabled,
@@ -512,3 +513,38 @@ menu "BLE disconnect when instant passed"
If this option is enabled, Controller will terminate the connection
when instant passed in PHY update procedure.
endmenu
config BT_CTRL_RUN_IN_FLASH_ONLY
bool "Put all BLE Controller code in flash"
default n
help
If this option is enabled, all code for the Bluetooth controller will be moved from ROM and IRAM
to flash, saving over 20K bytes of memory. However, it will require more flash resources and the
performance of Bluetooth will decrease If this option is enabled, Bluetooth may not work properly
during erasing flash. It is recommended to turn on the auto suspend function of flash. After auto
suspend is turned on, Bluetooth interrupts can be executed normally during erasing flash, with less
impact on Bluetooth performance.
config BT_CTRL_DTM_ENABLE
depends on BT_CTRL_RUN_IN_FLASH_ONLY
bool "Enable direct test mode feature"
default n
config BT_CTRL_BLE_MASTER
depends on BT_CTRL_RUN_IN_FLASH_ONLY
bool "Enable BLE master role feature"
default y
config BT_CTRL_BLE_TEST
depends on BT_CTRL_RUN_IN_FLASH_ONLY
bool "Enable BLE QA test feature"
default n
config BT_CTRL_BLE_SCAN
depends on BT_CTRL_RUN_IN_FLASH_ONLY
bool "Enable BLE scan feature"
default y
config BT_CTRL_BLE_SECURITY_ENABLE
depends on BT_CTRL_RUN_IN_FLASH_ONLY && BT_CONTROLLER_ONLY
bool "Enable BLE security feature"
default y

View File

@@ -499,7 +499,11 @@ static int interrupt_alloc_wrapper(int cpu_id, int source, intr_handler_t handle
{
btdm_isr_alloc_t p;
p.source = source;
#if CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY
p.flags = ESP_INTR_FLAG_LEVEL3;
#else
p.flags = ESP_INTR_FLAG_LEVEL3 | ESP_INTR_FLAG_IRAM;
#endif
p.fn = handler;
p.arg = arg;
p.handle = (intr_handle_t *)ret_handle;
@@ -1426,6 +1430,10 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
ESP_LOGI(BT_LOG_TAG, "BT controller compile version [%s]", btdm_controller_get_compile_version());
#if (CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY)
ESP_LOGI(BT_LOG_TAG,"Put all controller code in flash");
#endif
if ((err = btdm_low_power_mode_init(cfg)) != ESP_OK) {
ESP_LOGE(BT_LOG_TAG, "Low power module initialization failed");
goto error;

View File

@@ -21,13 +21,25 @@ if BLE_MESH
for mesh packets. And this could help avoid collision of
advertising packets.
menuconfig BLE_MESH_USE_BLE_50
bool "Support using BLE 5.0 APIs for BLE Mesh"
depends on BLE_MESH_EXPERIMENTAL
depends on IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32S3
select BT_NIMBLE_50_FEATURE_SUPPORT if BT_NIMBLE_ENABLED
select BT_NIMBLE_EXT_ADV if BT_NIMBLE_ENABLED
select BT_BLE_50_FEATURES_SUPPORTED if BT_BLUEDROID_ENABLED
select BT_LE_50_FEATURE_SUPPORT if IDF_TARGET_ESP32C6 || IDF_TARGET_ESP32H2
default n
help
This option to enable BLE Mesh using some BLE 5.0 APIs.
config BLE_MESH_USE_DUPLICATE_SCAN
bool "Support Duplicate Scan in BLE Mesh"
select BTDM_BLE_SCAN_DUPL if IDF_TARGET_ESP32
select BTDM_BLE_MESH_SCAN_DUPL_EN if IDF_TARGET_ESP32
select BT_CTRL_BLE_SCAN_DUPL if IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32S3
select BT_CTRL_BLE_MESH_SCAN_DUPL_EN if IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32S3
select BT_LE_SCAN_DUPL if IDF_TARGET_ESP32C6 || IDF_TARGET_ESP32H2
select BT_LE_SCAN_DUPL if IDF_TARGET_ESP32C6 || IDF_TARGET_ESP32H2 || IDF_TARGET_ESP32C61 || IDF_TARGET_ESP32C5
select BT_NIMBLE_VS_SUPPORT if BT_NIMBLE_ENABLED
default y
help
@@ -415,6 +427,13 @@ if BLE_MESH
will store the solicitation src and solicitation sequence number of
the received Solicitation PDU message.
config BLE_MESH_PROXY_CLI_SRV_COEXIST
bool "Support Proxy Client and Proxy Server coexistence"
depends on BLE_MESH_EXPERIMENTAL
default n
help
Enable this option to support the coexistence of proxy client and proxy server.
config BLE_MESH_GATT_PROXY_CLIENT
bool "BLE Mesh GATT Proxy Client"
select BLE_MESH_PROXY
@@ -1646,5 +1665,7 @@ if BLE_MESH
Make BLE Mesh Experimental features visible.
Experimental features list:
- CONFIG_BLE_MESH_NOT_RELAY_REPLAY_MSG
- CONFIG_BLE_MESH_USE_BLE_50
- CONFIG_BLE_MESH_PROXY_CLI_SRV_COEXIST
endif # BLE_MESH

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -12,14 +12,14 @@
#include "btc_ble_mesh_ble.h"
#include "esp_ble_mesh_ble_api.h"
#if CONFIG_BLE_MESH_BLE_COEX_SUPPORT
#if (CONFIG_BLE_MESH_BLE_COEX_SUPPORT || CONFIG_BLE_MESH_USE_BLE_50)
esp_err_t esp_ble_mesh_register_ble_callback(esp_ble_mesh_ble_cb_t callback)
{
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
return (btc_profile_cb_set(BTC_PID_BLE_MESH_BLE_COEX, callback) == 0 ? ESP_OK : ESP_FAIL);
}
#endif /* CONFIG_BLE_MESH_BLE_COEX_SUPPORT */
#endif /* (CONFIG_BLE_MESH_BLE_COEX_SUPPORT || CONFIG_BLE_MESH_USE_BLE_50) */
#if CONFIG_BLE_MESH_SUPPORT_BLE_ADV
esp_err_t esp_ble_mesh_start_ble_advertising(const esp_ble_mesh_ble_adv_param_t *param,
@@ -100,3 +100,23 @@ esp_err_t esp_ble_mesh_stop_ble_scanning(void)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_SCAN */
esp_err_t esp_ble_mesh_scan_params_update(esp_ble_mesh_scan_param_t *scan_param)
{
btc_ble_mesh_ble_args_t arg = {0};
btc_msg_t msg = {0};
if (!scan_param) {
return ESP_FAIL;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_BLE_MESH_BLE_COEX;
msg.act = BTC_BLE_MESH_ACT_UPDATE_SCAN_PARAMS;
arg.scan_params.scan_interval = scan_param->scan_interval;
arg.scan_params.uncoded_scan_window = scan_param->uncoded_scan_window;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_ble_args_t), NULL, NULL)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -9,6 +9,10 @@
#include "esp_ble_mesh_defs.h"
#if CONFIG_BLE_MESH_USE_BLE_50 && CONFIG_BT_NIMBLE_ENABLED
#include "host/ble_gap.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
@@ -20,9 +24,38 @@ typedef enum {
ESP_BLE_MESH_START_BLE_SCANNING_COMP_EVT, /*!< Start BLE scanning completion event */
ESP_BLE_MESH_STOP_BLE_SCANNING_COMP_EVT, /*!< Stop BLE scanning completion event */
ESP_BLE_MESH_SCAN_BLE_ADVERTISING_PKT_EVT, /*!< Scanning BLE advertising packets event */
ESP_BLE_MESH_SCAN_PARAMS_UPDATE_COMP_EVT, /*!< Scan parameters update completion event */
#if CONFIG_BLE_MESH_USE_BLE_50 && CONFIG_BT_NIMBLE_ENABLED
ESP_BLE_MESH_NIMBLE_GAP_EVENT_EVT, /*!< NIMBLE GAP event */
#endif /* CONFIG_BLE_MESH_USE_BLE_50 && CONFIG_BT_NIMBLE_ENABLED */
ESP_BLE_MESH_BLE_EVT_MAX,
} esp_ble_mesh_ble_cb_event_t;
/** Context of BLE advertising report. */
typedef struct {
uint8_t addr[6]; /*!< Device address */
uint8_t addr_type; /*!< Device address type */
#if CONFIG_BLE_MESH_USE_BLE_50
uint8_t adv_type __attribute__((deprecated("`event_type` should be used to determine the advertising type"))); /*!< advertising type */
#else
uint8_t adv_type; /*!< Advertising type */
#endif
uint8_t *data; /*!< Advertising data */
uint16_t length; /*!< Advertising data length */
int8_t rssi; /*!< RSSI of the advertising packet */
#if CONFIG_BLE_MESH_USE_BLE_50
uint8_t event_type; /*!< Extended advertising event type */
uint8_t primary_phy; /*!< Extended advertising primary PHY */
uint8_t secondary_phy; /*!< Extended advertising secondary PHY */
uint8_t sid; /*!< Extended advertising set ID */
uint8_t tx_power; /*!< Extended advertising TX power */
uint8_t dir_addr_type; /*!< Direct address type */
uint8_t dir_addr[6]; /*!< Direct address */
uint8_t data_status; /*!< Data type */
uint16_t per_adv_interval; /*!< Periodic advertising interval */
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
} esp_ble_mesh_ble_adv_rpt_t;
/** BLE operation callback parameters */
typedef union {
/**
@@ -52,16 +85,24 @@ typedef union {
int err_code; /*!< Indicate the result of stopping BLE scanning */
} stop_ble_scan_comp; /*!< Event parameters of ESP_BLE_MESH_STOP_BLE_SCANNING_COMP_EVT */
/**
* @brief ESP_BLE_MESH_SCAN_BLE_ADVERTISING_PKT_EVT
* @brief Event parameters of ESP_BLE_MESH_SCAN_BLE_ADVERTISING_PKT_EVT
*/
struct {
uint8_t addr[6]; /*!< Device address */
uint8_t addr_type; /*!< Device address type */
uint8_t adv_type; /*!< Advertising data type */
uint8_t *data; /*!< Advertising data */
uint16_t length; /*!< Advertising data length */
int8_t rssi; /*!< RSSI of the advertising packet */
} scan_ble_adv_pkt; /*!< Event parameters of ESP_BLE_MESH_SCAN_BLE_ADVERTISING_PKT_EVT */
esp_ble_mesh_ble_adv_rpt_t scan_ble_adv_pkt;
/**
* @brief Event parameter of ESP_BLE_MESH_SCAN_PARAMS_UPDATE_COMP_EVT
*/
struct ble_mesh_scan_params_update_comp_param {
int err_code; /*!< Indicates the result of updating scan parameters */
} scan_params_update_comp; /*!< Event parameter of ESP_BLE_MESH_SCAN_PARAMS_UPDATE_COMP_EVT */
#if CONFIG_BLE_MESH_USE_BLE_50 && CONFIG_BT_NIMBLE_ENABLED
/**
* @brief Event parameters of ESP_BLE_MESH_NIMBLE_GAP_EVENT_EVT
*/
struct ble_mesh_nimble_gap_event_evt_param {
struct ble_gap_event event; /*!< GAP event parameters for NimBLE Host */
void *arg; /*!< User parameters */
} nimble_gap_evt; /*!< Event parameters of ESP_BLE_MESH_NIMBLE_GAP_EVENT_EVT */
#endif /* CONFIG_BLE_MESH_USE_BLE_50 && CONFIG_BT_NIMBLE_ENABLED */
} esp_ble_mesh_ble_cb_param_t;
/**
@@ -175,6 +216,33 @@ esp_err_t esp_ble_mesh_start_ble_scanning(esp_ble_mesh_ble_scan_param_t *param);
*/
esp_err_t esp_ble_mesh_stop_ble_scanning(void);
/**
* @brief Update BLE Mesh scan parameters.
*
* @note
* 1. This function shall be used after ESP BLE Mesh is initialized!
* Parameters `scan_interval` and `uncoded_scan_window` must both
* be multiples of 8.
*
* 2. If the config BLE_MESH_USE_BLE_50 is enabled, within the scan_interval:
* - If uncoded_scan_window is not zero, the scan_interval is divided into
* two parts:
* - uncoded_scan_window: Used for performing uncoded scanning.
* - (scan_interval - uncoded_scan_window): The remaining time is
* used for coded scanning (coded_scan).
* - If uncoded_scan_window is set to 0, it means the entire scan_interval
* is used for coded scanning.
* - If uncoded_scan_window is equal to scan_interval, it means the entire
* scan_interval is used for uncoded scanning.
*
* @param[in] scan_param: Scan parameters
*
* @return
* - ESP_OK: Success
* - ESP_FAIL: Invalid parameters or unable transfer this command to the stack
*/
esp_err_t esp_ble_mesh_scan_params_update(esp_ble_mesh_scan_param_t *scan_param);
#ifdef __cplusplus
}
#endif

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2017-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -415,6 +415,29 @@ typedef struct {
bool erase_flash; /*!< Indicate if erasing flash when deinit mesh stack */
} esp_ble_mesh_deinit_param_t;
/** Scan parameters */
typedef struct {
/**
* Scan interval.
*
* Range: 0x0004 to 0x4000.
*
* Time = N * 0.625 ms. Time Range: 2.5 ms to 10.24 s
*/
uint16_t scan_interval;
/**
* Uncoded Scan window.
*
* Time scanned on uncoded PHY within a scan interval.
*
* Range: 0x0004 to 0x4000.
*
* Time = N * 0.625 ms. Time Range: 2.5 ms to 10.24 s
*/
uint16_t uncoded_scan_window;
} esp_ble_mesh_scan_param_t;
/** Format of Unicast Address Range */
typedef struct {
uint16_t len_present:1, /*!< Indicate the presence or absence of the RangeLength field */

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2020-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -13,8 +13,7 @@
#include "mesh/adapter.h"
#include "esp_ble_mesh_ble_api.h"
#if CONFIG_BLE_MESH_BLE_COEX_SUPPORT
#if (CONFIG_BLE_MESH_BLE_COEX_SUPPORT || CONFIG_BLE_MESH_USE_BLE_50)
static void btc_ble_mesh_ble_copy_req_data(btc_msg_t *msg, void *p_dst, void *p_src)
{
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
@@ -29,6 +28,7 @@ static void btc_ble_mesh_ble_copy_req_data(btc_msg_t *msg, void *p_dst, void *p_
switch (msg->act) {
case ESP_BLE_MESH_SCAN_BLE_ADVERTISING_PKT_EVT:
if (p_src_data->scan_ble_adv_pkt.data && p_src_data->scan_ble_adv_pkt.length) {
memcpy(&p_dst_data->scan_ble_adv_pkt, &p_src_data->scan_ble_adv_pkt, sizeof(p_src_data->scan_ble_adv_pkt));
p_dst_data->scan_ble_adv_pkt.length = p_src_data->scan_ble_adv_pkt.length;
p_dst_data->scan_ble_adv_pkt.data = bt_mesh_calloc(p_src_data->scan_ble_adv_pkt.length);
if (p_dst_data->scan_ble_adv_pkt.data) {
@@ -86,26 +86,34 @@ static void btc_ble_mesh_ble_callback(esp_ble_mesh_ble_cb_param_t *cb_params, ui
btc_ble_mesh_ble_copy_req_data, btc_ble_mesh_ble_free_req_data);
}
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
void bt_mesh_ble_scan_cb_evt_to_btc(const bt_mesh_addr_t *addr,
uint8_t adv_type, uint8_t data[],
uint16_t length, int8_t rssi)
#if CONFIG_BT_NIMBLE_ENABLED && CONFIG_BLE_MESH_USE_BLE_50
void bt_mesh_ble_nimble_evt_to_btc(struct ble_gap_event *event, void *arg)
{
esp_ble_mesh_ble_cb_param_t param = {0};
if (addr == NULL) {
if (event == NULL) {
BT_ERR("%s, Invalid parameter", __func__);
return;
}
memcpy(param.scan_ble_adv_pkt.addr, addr->val, sizeof(addr->val));
param.scan_ble_adv_pkt.addr_type = addr->type;
if (data && length) {
param.scan_ble_adv_pkt.data = data;
param.scan_ble_adv_pkt.length = length;
memcpy(&param.nimble_gap_evt.event, event, sizeof(struct ble_gap_event));
param.nimble_gap_evt.arg = arg;
btc_ble_mesh_ble_callback(&param, ESP_BLE_MESH_NIMBLE_GAP_EVENT_EVT);
}
#endif /* CONFIG_BT_NIMBLE_ENABLED && CONFIG_BLE_MESH_USE_BLE_50 */
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
void bt_mesh_ble_scan_cb_evt_to_btc(bt_mesh_ble_adv_report_t *adv_report)
{
esp_ble_mesh_ble_cb_param_t param = {0};
if (adv_report == NULL) {
BT_ERR("%s, Invalid parameter", __func__);
return;
}
param.scan_ble_adv_pkt.adv_type = adv_type;
param.scan_ble_adv_pkt.rssi = rssi;
memcpy(&param.scan_ble_adv_pkt, adv_report, sizeof(bt_mesh_ble_adv_report_t));
btc_ble_mesh_ble_callback(&param, ESP_BLE_MESH_SCAN_BLE_ADVERTISING_PKT_EVT);
}
@@ -157,6 +165,14 @@ void btc_ble_mesh_ble_call_handler(btc_msg_t *msg)
btc_ble_mesh_ble_callback(&param, ESP_BLE_MESH_STOP_BLE_SCANNING_COMP_EVT);
break;
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_SCAN */
case BTC_BLE_MESH_ACT_UPDATE_SCAN_PARAMS:
struct bt_mesh_scan_param scan_param = {
.interval = arg->scan_params.scan_interval,
.window = arg->scan_params.uncoded_scan_window,
};
param.scan_params_update_comp.err_code = bt_mesh_scan_param_update(&scan_param);
btc_ble_mesh_ble_callback(&param, ESP_BLE_MESH_SCAN_PARAMS_UPDATE_COMP_EVT);
break;
default:
return;
}
@@ -191,5 +207,4 @@ void btc_ble_mesh_ble_cb_handler(btc_msg_t *msg)
btc_ble_mesh_ble_free_req_data(msg);
}
#endif /* CONFIG_BLE_MESH_BLE_COEX_SUPPORT */
#endif /* (CONFIG_BLE_MESH_BLE_COEX_SUPPORT || CONFIG_BLE_MESH_USE_BLE_50) */

View File

@@ -30,6 +30,7 @@
#endif /* CONFIG_BLE_MESH_V11_SUPPORT */
#include "adv.h"
#include "scan.h"
#include "mesh/kernel.h"
#include "mesh/proxy.h"
#include "mesh.h"
@@ -2948,6 +2949,7 @@ void btc_ble_mesh_model_call_handler(btc_msg_t *msg)
.ctx.send_tag = arg->model_send.ctx->send_tag,
.msg_timeout = arg->model_send.msg_timeout,
};
err = bt_mesh_client_send_msg(&param, buf, arg->model_send.need_rsp,
btc_ble_mesh_client_model_timeout_cb);
bt_mesh_free_buf(buf);

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2020-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -16,6 +16,30 @@
extern "C" {
#endif
typedef struct {
uint8_t addr[6]; /*!< Device address */
uint8_t addr_type; /*!< Device address type */
#if CONFIG_BLE_MESH_USE_BLE_50
uint8_t adv_type __attribute__((deprecated("`event_type` should be used to determine the advertising type"))); /*!< advertising type */
#else
uint8_t adv_type; /*!< Advertising type */
#endif
uint8_t *data; /*!< Advertising data */
uint16_t length; /*!< Advertising data length */
int8_t rssi; /*!< RSSI of the advertising packet */
#if CONFIG_BLE_MESH_USE_BLE_50
uint8_t event_type; /*!< Extended advertising event type */
uint8_t primary_phy; /*!< Extended advertising primary PHY */
uint8_t secondary_phy; /*!< Extended advertising secondary PHY */
uint8_t sid; /*!< Extended advertising set ID */
uint8_t tx_power; /*!< Extended advertising TX power */
uint8_t dir_addr_type; /*!< Direct address type */
uint8_t dir_addr[6]; /*!< Direct address */
uint8_t data_status; /*!< Data type */
uint16_t per_adv_interval; /*!< Periodic advertising interval */
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
} bt_mesh_ble_adv_report_t;
typedef union {
struct {
esp_ble_mesh_ble_adv_param_t param;
@@ -30,6 +54,10 @@ typedef union {
struct {
/* RFU */
} stop_ble_scan;
struct ble_mesh_scan_params {
uint16_t scan_interval;
uint16_t uncoded_scan_window;
} scan_params;
} btc_ble_mesh_ble_args_t;
typedef enum {
@@ -37,11 +65,14 @@ typedef enum {
BTC_BLE_MESH_ACT_STOP_BLE_ADV,
BTC_BLE_MESH_ACT_START_BLE_SCAN,
BTC_BLE_MESH_ACT_STOP_BLE_SCAN,
BTC_BLE_MESH_ACT_UPDATE_SCAN_PARAMS,
} btc_ble_mesh_ble_act_t;
void bt_mesh_ble_scan_cb_evt_to_btc(const bt_mesh_addr_t *addr,
uint8_t adv_type, uint8_t data[],
uint16_t length, int8_t rssi);
void bt_mesh_ble_scan_cb_evt_to_btc(bt_mesh_ble_adv_report_t *adv_report);
#if CONFIG_BT_NIMBLE_ENABLED && CONFIG_BLE_MESH_USE_BLE_50
void bt_mesh_ble_nimble_evt_to_btc(struct ble_gap_event *event, void *arg);
#endif /* CONFIG_BT_NIMBLE_ENABLED && CONFIG_BLE_MESH_USE_BLE_50 */
void btc_ble_mesh_ble_call_handler(btc_msg_t *msg);

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

View File

@@ -200,7 +200,7 @@ extern "C" {
* { MY_PWM0 , MY_PWM1 }
*
* @param LEN The length of the sequence. Must be an integer literal less
* than 255.
* than 255 (ref: utils_loops.h).
* @param F A macro function that accepts at least two arguments:
* <tt>F(i, ...)</tt>. @p F is called repeatedly in the expansion.
* Its first argument @p i is the index in the sequence, and

View File

@@ -45,6 +45,14 @@ static const uint8_t adv_type[] = {
[BLE_MESH_ADV_URI] = BLE_MESH_DATA_URI,
};
#if CONFIG_BLE_MESH_USE_BLE_50
#define ESP_BLE_MESH_INST_UNUSED_ELT_(IDX, _) [IDX] = {.id = IDX}
static struct bt_mesh_adv_inst adv_insts[BLE_MESH_ADV_INS_CNT] = {
LISTIFY(BLE_MESH_ADV_INS_CNT, ESP_BLE_MESH_INST_UNUSED_ELT_, (,)),
};
#endif
NET_BUF_POOL_DEFINE(adv_buf_pool, CONFIG_BLE_MESH_ADV_BUF_COUNT,
BLE_MESH_ADV_DATA_SIZE, BLE_MESH_ADV_USER_DATA_SIZE, NULL);
@@ -122,11 +130,51 @@ struct bt_mesh_adv_task {
static struct bt_mesh_adv_task adv_task;
#if CONFIG_BLE_MESH_USE_BLE_50
bool bt_mesh_is_adv_inst_used(uint8_t adv_inst_id)
{
uint8_t i;
for (i = 0; i < ARRAY_SIZE(adv_insts); i++) {
if (adv_insts[i].id == adv_inst_id) {
return true;
}
}
return false;
}
uint8_t bt_mesh_get_proxy_inst(void)
{
return adv_insts[0].id;
}
void bt_mesh_adv_inst_deinit(void)
{
uint8_t i;
for (i = 0; i < ARRAY_SIZE(adv_insts); i++) {
bt_le_ext_adv_stop(adv_insts[i].id);
}
return;
}
#endif
static struct bt_mesh_adv *adv_alloc(int id)
{
return &adv_pool[id];
}
int ble_mesh_adv_task_wakeup(uint16_t adv_inst_id)
{
xTaskNotify(adv_task.handle, BIT(adv_inst_id), eSetBits);
return 0;
}
static inline bool ble_mesh_adv_task_wait(uint32_t timeout, uint32_t *notify)
{
return xTaskNotifyWait(UINT32_MAX, UINT32_MAX, notify, timeout) == pdTRUE;
}
static inline void adv_send_start(uint16_t duration, int err,
const struct bt_mesh_send_cb *cb,
void *cb_data)
@@ -155,8 +203,16 @@ uint16_t bt_mesh_pdu_duration(uint8_t xmit)
return duration;
}
static inline TickType_t K_WAIT(int32_t val)
{
return (val == K_FOREVER) ? portMAX_DELAY : (val / portTICK_PERIOD_MS);
}
static inline int adv_send(struct net_buf *buf)
{
#if CONFIG_BLE_MESH_USE_BLE_50
struct bt_mesh_adv_inst *adv_ins = &adv_insts[0];
#endif
const struct bt_mesh_send_cb *cb = BLE_MESH_ADV(buf)->cb;
void *cb_data = BLE_MESH_ADV(buf)->cb_data;
struct bt_mesh_adv_param param = {0};
@@ -187,6 +243,11 @@ static inline int adv_send(struct net_buf *buf)
param.interval_min = ADV_SCAN_UNIT(adv_int);
param.interval_max = param.interval_min;
#if CONFIG_BLE_MESH_USE_BLE_50
param.adv_duration = duration;
param.adv_count = BLE_MESH_TRANSMIT_COUNT(BLE_MESH_ADV(buf)->xmit) + 1;
#endif
#if CONFIG_BLE_MESH_PROXY_SOLIC_PDU_TX
if (BLE_MESH_ADV(buf)->type == BLE_MESH_ADV_PROXY_SOLIC) {
bt_mesh_adv_buf_ref_debug(__func__, buf, 3U, BLE_MESH_BUF_REF_SMALL);
@@ -195,12 +256,24 @@ static inline int adv_send(struct net_buf *buf)
BLE_MESH_ADV_DATA_BYTES(BLE_MESH_DATA_UUID16_ALL, 0x59, 0x18),
BLE_MESH_ADV_DATA(BLE_MESH_DATA_SVC_DATA16, buf->data, buf->len),
};
err = bt_le_adv_start(&param, solic_ad, 3, NULL, 0);
#if CONFIG_BLE_MESH_USE_BLE_50
param.primary_phy = BLE_MESH_ADV_PHY_1M;
param.secondary_phy = BLE_MESH_ADV_PHY_1M;
err = bt_le_ext_adv_start(adv_ins->id, &param, &ad, 3, NULL, 0);
#else /* CONFIG_BLE_MESH_USE_BLE_50 */
err = bt_le_adv_start(&param, &ad, 3, NULL, 0);
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
} else
#endif
{
bt_mesh_adv_buf_ref_debug(__func__, buf, 4U, BLE_MESH_BUF_REF_SMALL);
#if CONFIG_BLE_MESH_USE_BLE_50
param.primary_phy = BLE_MESH_ADV_PHY_1M;
param.secondary_phy = BLE_MESH_ADV_PHY_1M;
err = bt_le_ext_adv_start(adv_ins->id, &param, &ad, 1, NULL, 0);
#else /* CONFIG_BLE_MESH_USE_BLE_50 */
err = bt_le_adv_start(&param, &ad, 1, NULL, 0);
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
}
#if CONFIG_BLE_MESH_SUPPORT_BLE_ADV
} else {
@@ -229,7 +302,11 @@ static inline int adv_send(struct net_buf *buf)
bt_mesh_adv_buf_ref_debug(__func__, buf, 3U, BLE_MESH_BUF_REF_SMALL);
#if CONFIG_BLE_MESH_USE_BLE_50
err = bt_mesh_ble_ext_adv_start(adv_ins->id, &tx->param, &data);
#else /* CONFIG_BLE_MESH_USE_BLE_50 */
err = bt_mesh_ble_adv_start(&tx->param, &data);
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
}
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_ADV */
@@ -242,9 +319,19 @@ static inline int adv_send(struct net_buf *buf)
BT_DBG("Advertising started. Sleeping %u ms", duration);
#if CONFIG_BLE_MESH_USE_BLE_50
if (!ble_mesh_adv_task_wait(K_WAIT(K_FOREVER), NULL)) {
BT_WARN("Advertising didn't finish on time");
bt_le_ext_adv_stop(adv_ins->id);
}
#else /* CONFIG_BLE_MESH_USE_BLE_50 */
k_sleep(K_MSEC(duration));
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
#if !CONFIG_BLE_MESH_USE_BLE_50
err = bt_le_adv_stop();
#endif
adv_send_end(err, cb, cb_data);
if (err) {
BT_ERR("Stop advertising failed: err %d", err);
@@ -255,11 +342,6 @@ static inline int adv_send(struct net_buf *buf)
return 0;
}
static inline TickType_t K_WAIT(int32_t val)
{
return (val == K_FOREVER) ? portMAX_DELAY : (val / portTICK_PERIOD_MS);
}
static void adv_thread(void *p)
{
#if CONFIG_BLE_MESH_RELAY_ADV_BUF
@@ -679,6 +761,10 @@ void bt_mesh_adv_deinit(void)
return;
}
#if CONFIG_BLE_MESH_USE_BLE_50
bt_mesh_adv_inst_deinit();
#endif
vTaskDelete(adv_task.handle);
adv_task.handle = NULL;
#if (CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_EXTERNAL && \

View File

@@ -2,7 +2,7 @@
/*
* SPDX-FileCopyrightText: 2017 Intel Corporation
* SPDX-FileContributor: 2018-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileContributor: 2018-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -13,6 +13,7 @@
#include "mesh/atomic.h"
#include "mesh/access.h"
#include "mesh/adapter.h"
#include "mesh/utils.h"
#ifdef __cplusplus
extern "C" {
@@ -67,6 +68,19 @@ typedef enum {
BLE_MESH_BUF_REF_MAX,
} bt_mesh_buf_ref_flag_t;
#if CONFIG_BLE_MESH_USE_BLE_50
#define BLE_MESH_ADV_INS_UNUSED 0xFF
#define BLE_MESH_ADV_INS_CNT 1
struct bt_mesh_adv_inst {
uint8_t id;
};
int ble_mesh_adv_task_wakeup(uint16_t adv_inst_id);
bool bt_mesh_is_adv_inst_used(uint8_t adv_inst_id);
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
void bt_mesh_adv_buf_ref_debug(const char *func, struct net_buf *buf,
uint8_t ref_cmp, bt_mesh_buf_ref_flag_t flag);
@@ -81,6 +95,10 @@ void bt_mesh_adv_send(struct net_buf *buf, uint8_t xmit,
const struct bt_mesh_send_cb *cb,
void *cb_data);
#if CONFIG_BLE_MESH_USE_BLE_50 && (CONFIG_BLE_MESH_GATT_PROXY_SERVER || CONFIG_BLE_MESH_PB_GATT)
uint8_t bt_mesh_get_proxy_inst(void);
#endif
struct net_buf *bt_mesh_relay_adv_create(enum bt_mesh_adv_type type, int32_t timeout);
void bt_mesh_relay_adv_send(struct net_buf *buf, uint8_t xmit,

View File

@@ -29,8 +29,10 @@
#include "mesh/adapter.h"
#include "mesh/common.h"
#include "prov_pvnr.h"
#include "scan.h"
#include "net.h"
#include "beacon.h"
#include "btc_ble_mesh_ble.h"
#if CONFIG_BLE_MESH_V11_SUPPORT
#include "mesh_v1.1/utils.h"
@@ -60,7 +62,10 @@ static uint8_t bt_mesh_private_key[32];
/* Scan related functions */
static bt_mesh_scan_cb_t *bt_mesh_scan_dev_found_cb;
#if !CONFIG_BLE_MESH_USE_BLE_50
static void bt_mesh_scan_result_callback(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data);
#endif
#if (CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PB_GATT) || \
CONFIG_BLE_MESH_GATT_PROXY_SERVER || \
@@ -104,6 +109,14 @@ static struct bt_mesh_prov_conn_cb *bt_mesh_gattc_conn_cb;
static tBTA_GATTC_IF bt_mesh_gattc_if;
#endif
#if CONFIG_BLE_MESH_USE_BLE_50 && CONFIG_BLE_MESH_SUPPORT_BLE_ADV
static inline void bt_mesh_set_ble_adv_running();
static inline void bt_mesh_unset_ble_adv_running();
static inline bool bt_mesh_is_ble_adv_running();
#endif
int bt_mesh_host_init(void)
{
return 0;
@@ -138,11 +151,18 @@ void bt_mesh_hci_init(void)
const uint8_t *p = controller_get_interface()->get_ble_supported_states();
uint64_t states_fh = 0, states_sh = 0;
STREAM_TO_UINT32(states_fh, p);
STREAM_TO_UINT32(states_sh, p);
/* macro STREAM_TO_UINT32 expansion */
states_fh = (((uint32_t)(*(p))) + ((((uint32_t)(*((p) + 1)))) << 8) + ((((uint32_t)(*((p) + 2)))) << 16) + ((((uint32_t)(*((p) + 3)))) << 24));
(p) += 4;
states_sh = (((uint32_t)(*(p))) + ((((uint32_t)(*((p) + 1)))) << 8) + ((((uint32_t)(*((p) + 2)))) << 16) + ((((uint32_t)(*((p) + 3)))) << 24));
(p) += 4;
bt_mesh_dev.le.states = (states_sh << 32) | states_fh;
}
#if !CONFIG_BLE_MESH_USE_BLE_50
static void bt_mesh_scan_results_change_2_bta(tBTM_INQ_RESULTS *p_inq, uint8_t *p_eir,
tBTA_DM_SEARCH_CBACK *p_scan_cback)
{
@@ -185,6 +205,189 @@ static void bt_mesh_scan_results_cb(tBTM_INQ_RESULTS *p_inq, uint8_t *p_eir)
{
bt_mesh_scan_results_change_2_bta(p_inq, p_eir, bt_mesh_scan_result_callback);
}
#endif
#if CONFIG_BLE_MESH_USE_BLE_50
extern void btc_ble_5_gap_callback(tBTA_DM_BLE_5_GAP_EVENT event,
tBTA_DM_BLE_5_GAP_CB_PARAMS *params);
void bt_mesh_ble_ext_adv_report(tBTM_BLE_EXT_ADV_REPORT *ext_adv_report)
{
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
bt_mesh_ble_adv_report_t adv_rpt = {0};
if (bt_mesh_ble_scan_state_get()) {
memcpy(adv_rpt.addr, ext_adv_report->addr, BLE_MESH_ADDR_LEN);
memcpy(adv_rpt.dir_addr, ext_adv_report->dir_addr, BLE_MESH_ADDR_LEN);
adv_rpt.addr_type = ext_adv_report->addr_type;
adv_rpt.data = ext_adv_report->adv_data;
adv_rpt.length = ext_adv_report->adv_data_len;
adv_rpt.rssi = ext_adv_report->rssi;
adv_rpt.event_type = ext_adv_report->event_type;
adv_rpt.primary_phy = ext_adv_report->primary_phy;
adv_rpt.secondary_phy = ext_adv_report->secondry_phy;
adv_rpt.sid = ext_adv_report->sid;
adv_rpt.tx_power = ext_adv_report->tx_power;
adv_rpt.dir_addr_type = ext_adv_report->dir_addr_type;
adv_rpt.data_status = ext_adv_report->data_status;
adv_rpt.per_adv_interval = ext_adv_report->per_adv_interval;
bt_mesh_ble_scan_cb_evt_to_btc(&adv_rpt);
}
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_SCAN */
}
static bool bt_mesh_scan_result_process(tBTM_BLE_EXT_ADV_REPORT *ext_adv_report)
{
struct bt_mesh_adv_report adv_rpt = {0};
assert(ext_adv_report);
adv_rpt.addr.type = ext_adv_report->addr_type;
memcpy(adv_rpt.addr.val, ext_adv_report->addr, BLE_MESH_ADDR_LEN);
adv_rpt.primary_phy = ext_adv_report->primary_phy;
adv_rpt.secondary_phy = ext_adv_report->secondry_phy;
adv_rpt.rssi = ext_adv_report->rssi;
if (!(ext_adv_report->event_type & BTM_BLE_ADV_LEGACY_MASK)) {
return false;
}
if (!bt_mesh_atomic_test_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCANNING)) {
return false;
}
BT_DBG("Recv adv report type %04x", ext_adv_report->event_type);
switch (ext_adv_report->event_type) {
case BLE_MESH_ADV_IND:
case BLE_MESH_ADV_DIRECT_IND:
case BLE_MESH_ADV_SCAN_IND:
case BLE_MESH_ADV_NONCONN_IND:
case BLE_MESH_ADV_SCAN_RSP:
adv_rpt.adv_type = ext_adv_report->event_type;
break;
default:
return false;
break;
}
if (bt_mesh_scan_dev_found_cb) {
net_buf_simple_init_with_data(&adv_rpt.adv_data, ext_adv_report->adv_data, ext_adv_report->adv_data_len);
bt_mesh_scan_dev_found_cb(&adv_rpt);
if (adv_rpt.adv_data.len != ext_adv_report->adv_data_len) {
/* The advertising data has been processed by Mesh Protocol */
return true;
}
}
return false;
}
void ble_mesh_5_gap_callback(tBTA_DM_BLE_5_GAP_EVENT event,
tBTA_DM_BLE_5_GAP_CB_PARAMS *params)
{
BT_DBG("recv event %d", event);
switch (event) {
case BTA_DM_BLE_5_GAP_EXT_ADV_SET_PARAMS_COMPLETE_EVT:
if (!bt_mesh_is_adv_inst_used(params->set_params.instance)) {
goto transfer_to_user;
}
if (params->set_params.status != BTM_SUCCESS) {
BT_ERR("BTA_DM_BLE_5_GAP_EXT_ADV_SET_PARAMS_COMPLETE_EVT Failed");
}
break;
case BTA_DM_BLE_5_GAP_EXT_ADV_DATA_SET_COMPLETE_EVT:
if (!bt_mesh_is_adv_inst_used(params->adv_data_set.instance)) {
goto transfer_to_user;
}
if (params->adv_data_set.status != BTM_SUCCESS) {
BT_ERR("BTA_DM_BLE_5_GAP_EXT_ADV_DATA_SET_COMPLETE_EVT Failed");
}
break;
case BTA_DM_BLE_5_GAP_EXT_SCAN_RSP_DATA_SET_COMPLETE_EVT:
if (!bt_mesh_is_adv_inst_used(params->scan_rsp_data_set.instance)) {
goto transfer_to_user;
}
if (params->scan_rsp_data_set.status != BTM_SUCCESS) {
BT_ERR("BTA_DM_BLE_5_GAP_EXT_SCAN_RSP_DATA_SET_COMPLETE_EVT Failed");
}
break;
case BTA_DM_BLE_5_GAP_EXT_ADV_START_COMPLETE_EVT:
if (!bt_mesh_is_adv_inst_used(params->adv_start.instance[0])) {
goto transfer_to_user;
}
if (params->adv_start.status != BTM_SUCCESS) {
BT_ERR("BTA_DM_BLE_5_GAP_EXT_ADV_START_COMPLETE_EVT Failed");
}
break;
case BTA_DM_BLE_5_GAP_EXT_ADV_STOP_COMPLETE_EVT:
if (!bt_mesh_is_adv_inst_used(params->adv_start.instance[0])) {
goto transfer_to_user;
}
if (params->adv_start.status != BTM_SUCCESS) {
BT_ERR("BTA_DM_BLE_5_GAP_EXT_ADV_STOP_COMPLETE_EVT Failed");
}
break;
case BTA_DM_BLE_5_GAP_ADV_TERMINATED_EVT:
if (!bt_mesh_is_adv_inst_used(params->adv_term.adv_handle)) {
goto transfer_to_user;
}
if (params->adv_term.status == 0x43 || /* Limit reached */
params->adv_term.status == 0x3C) { /* Advertising timeout */
ble_mesh_adv_task_wakeup(params->adv_term.adv_handle);
}
#if CONFIG_BLE_MESH_SUPPORT_BLE_ADV
/**
* This judgment is to distinguish between the termination
* events of BLE connectable broadcasting and proxy connectable
* adv under the same instance ID, that is, when the status is 0.
*
* Since the host task and adv task are currently operated in
* series, there is no need to consider competition issues between
* tasks.
*
* @attention: once multiple adv instances are used, the adv task
* and host will be asynchronous, and it is necessary to consider
* the issue of resource competition.
*/
if (bt_mesh_is_ble_adv_running() &&
params->adv_term.status == 0x00) {
/* The unset operation must be performed before waking up the
* adv task; performing the unset after waking up the adv task
* could lead to resource contention issues.
*/
bt_mesh_unset_ble_adv_running();
ble_mesh_adv_task_wakeup(params->adv_term.adv_handle);
}
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_ADV */
break;
case BTA_DM_BLE_5_GAP_EXT_ADV_REPORT_EVT:
if (!bt_mesh_scan_result_process(&params->ext_adv_report)) {
bt_mesh_ble_ext_adv_report(&params->ext_adv_report);
}
break;
case BTA_DM_BLE_5_GAP_EXT_SCAN_START_COMPLETE_EVT:
if (params->scan_start.status != BTM_SUCCESS) {
BT_ERR("BTA_DM_BLE_5_GAP_EXT_SCAN_START_COMPLETE_EVT Failed");
}
break;
case BTA_DM_BLE_5_GAP_EXT_SCAN_STOP_COMPLETE_EVT:
if (params->scan_stop.status != BTM_SUCCESS) {
BT_ERR("BTM_BLE_5_GAP_EXT_SCAN_START_COMPLETE_EVT Failed");
}
break;
default:
goto transfer_to_user;
}
return;
transfer_to_user:
btc_ble_5_gap_callback(event, params);
}
#endif
static bool valid_adv_param(const struct bt_mesh_adv_param *param)
{
@@ -205,7 +408,12 @@ static bool valid_adv_param(const struct bt_mesh_adv_param *param)
return true;
}
#if CONFIG_BLE_MESH_USE_BLE_50
static int set_adv_data(uint16_t hci_op, const uint8_t inst_id,
const struct bt_mesh_adv_data *ad, size_t ad_len)
#else
static int set_adv_data(uint16_t hci_op, const struct bt_mesh_adv_data *ad, size_t ad_len)
#endif
{
struct bt_mesh_hci_cp_set_adv_data param = {0};
int i;
@@ -227,16 +435,22 @@ static int set_adv_data(uint16_t hci_op, const struct bt_mesh_adv_data *ad, size
param.len += ad[i].data_len;
}
#if CONFIG_BLE_MESH_USE_BLE_50
BTA_DmBleGapConfigExtAdvDataRaw(hci_op == BLE_MESH_HCI_OP_SET_SCAN_RSP_DATA,
inst_id, param.len, param.data);
#else
/* Set adv data and scan rsp data. */
if (hci_op == BLE_MESH_HCI_OP_SET_ADV_DATA) {
BLE_MESH_BTM_CHECK_STATUS(BTM_BleWriteAdvDataRaw(param.data, param.len));
} else if (hci_op == BLE_MESH_HCI_OP_SET_SCAN_RSP_DATA) {
BLE_MESH_BTM_CHECK_STATUS(BTM_BleWriteScanRspRaw(param.data, param.len));
}
#endif
return 0;
}
#if !CONFIG_BLE_MESH_USE_BLE_50
static void start_adv_completed_cb(uint8_t status)
{
#if BLE_MESH_DEV
@@ -245,6 +459,7 @@ static void start_adv_completed_cb(uint8_t status)
}
#endif
}
#endif
static bool valid_scan_param(const struct bt_mesh_scan_param *param)
{
@@ -276,15 +491,54 @@ static bool valid_scan_param(const struct bt_mesh_scan_param *param)
static int start_le_scan(uint8_t scan_type, uint16_t interval, uint16_t window,
uint8_t filter_dup, uint8_t scan_fil_policy)
{
#if !CONFIG_BLE_MESH_USE_BLE_50
uint8_t addr_type_own = BLE_MESH_ADDR_PUBLIC; /* Currently only support Public Address */
tGATT_IF client_if = 0xFF; /* Default GATT interface id */
#endif
#if CONFIG_BLE_MESH_USE_BLE_50
tBTA_DM_BLE_EXT_SCAN_PARAMS ext_scan_params = {0};
if (interval == 0 ||
interval < window) {
BT_ERR("invalid scan param itvl %d win %d", interval, window);
return EINVAL;
}
ext_scan_params.own_addr_type = BLE_MESH_ADDR_PUBLIC;
ext_scan_params.filter_policy = scan_fil_policy;
ext_scan_params.scan_duplicate = filter_dup;
if (window == 0) {
ext_scan_params.cfg_mask = BTM_BLE_GAP_EXT_SCAN_CODE_MASK;
} else if (interval > window) {
ext_scan_params.cfg_mask = BTM_BLE_GAP_EXT_SCAN_UNCODE_MASK | BTM_BLE_GAP_EXT_SCAN_CODE_MASK;
} else {
// interval == window
ext_scan_params.cfg_mask = BTM_BLE_GAP_EXT_SCAN_UNCODE_MASK;
}
ext_scan_params.uncoded_cfg.scan_type = scan_type;
ext_scan_params.uncoded_cfg.scan_interval = interval;
ext_scan_params.uncoded_cfg.scan_window = window;
ext_scan_params.coded_cfg.scan_type = scan_type;
ext_scan_params.coded_cfg.scan_interval = interval;
ext_scan_params.coded_cfg.scan_window = interval - window;
BTA_DmBleGapSetExtScanParams(&ext_scan_params);
BTM_BleGapRegisterCallback(ble_mesh_5_gap_callback);
BTA_DmBleGapExtScan(true, 0, 0);
#else /* CONFIG_BLE_MESH_USE_BLE_50 */
BLE_MESH_BTM_CHECK_STATUS(
BTM_BleSetScanFilterParams(client_if, interval, window, scan_type, addr_type_own,
filter_dup, scan_fil_policy, NULL));
/* BLE Mesh scan permanently, so no duration of scan here */
BLE_MESH_BTM_CHECK_STATUS(BTM_BleScan(true, 0, bt_mesh_scan_results_cb, NULL, NULL));
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
#if BLE_MESH_DEV
if (scan_type == BLE_MESH_SCAN_ACTIVE) {
@@ -297,22 +551,32 @@ static int start_le_scan(uint8_t scan_type, uint16_t interval, uint16_t window,
return 0;
}
#if !CONFIG_BLE_MESH_USE_BLE_50
static void bt_mesh_scan_result_callback(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data)
{
struct net_buf_simple buf = {0};
bt_mesh_addr_t addr = {0};
struct bt_mesh_adv_report adv_rpt = {0};
BT_DBG("%s, event %d", __func__, event);
if (event == BTA_DM_INQ_RES_EVT) {
/* TODO: How to process scan response here? PS: p_data->inq_res.scan_rsp_len */
addr.type = p_data->inq_res.ble_addr_type;
memcpy(addr.val, p_data->inq_res.bd_addr, BLE_MESH_ADDR_LEN);
net_buf_simple_init_with_data(&buf, p_data->inq_res.p_eir, p_data->inq_res.adv_data_len);
adv_rpt.addr.type = p_data->inq_res.ble_addr_type;
adv_rpt.rssi = p_data->inq_res.rssi;
adv_rpt.adv_type = p_data->inq_res.ble_evt_type;
memcpy(adv_rpt.addr.val, p_data->inq_res.bd_addr, BLE_MESH_ADDR_LEN);
net_buf_simple_init_with_data(&adv_rpt.adv_data, p_data->inq_res.p_eir, p_data->inq_res.adv_data_len);
if (bt_mesh_scan_dev_found_cb) {
bt_mesh_scan_dev_found_cb(&addr, p_data->inq_res.rssi, p_data->inq_res.ble_evt_type, &buf, p_data->inq_res.scan_rsp_len);
bt_mesh_scan_dev_found_cb(&adv_rpt);
if (p_data->inq_res.scan_rsp_len) {
adv_rpt.adv_type = BLE_MESH_ADV_SCAN_RSP;
net_buf_simple_init_with_data(&adv_rpt.adv_data, p_data->inq_res.p_eir + p_data->inq_res.adv_data_len, p_data->inq_res.scan_rsp_len);
bt_mesh_scan_dev_found_cb(&adv_rpt);
}
}
} else if (event == BTA_DM_INQ_CMPL_EVT) {
BT_INFO("Scan completed, number of scan response %d", p_data->inq_cmpl.num_resps);
@@ -320,7 +584,132 @@ static void bt_mesh_scan_result_callback(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARC
BT_WARN("Unexpected scan result event %d", event);
}
}
#endif
#if CONFIG_BLE_MESH_USE_BLE_50
int bt_le_ext_adv_start(const uint8_t inst_id,
const struct bt_mesh_adv_param *param,
const struct bt_mesh_adv_data *ad, size_t ad_len,
const struct bt_mesh_adv_data *sd, size_t sd_len)
{
tBTA_DM_BLE_GAP_EXT_ADV_PARAMS ext_adv_params = {0};
tBTA_DM_BLE_EXT_ADV ext_adv = {0};
uint16_t interval = 0U;
int err = 0;
assert(param);
#if BLE_MESH_DEV
if (bt_mesh_atomic_test_bit(bt_mesh_dev.flags, BLE_MESH_DEV_ADVERTISING)) {
return -EALREADY;
}
#endif
if (!valid_adv_param(param)) {
BT_ERR("Invalid adv parameters");
return -EINVAL;
}
memset(&ext_adv_params, 0, sizeof(tBTA_DM_BLE_GAP_EXT_ADV_PARAMS));
if (param->options & BLE_MESH_ADV_OPT_CONNECTABLE) {
ext_adv_params.type = BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_LEGACY_IND;
} else if (sd != NULL) {
ext_adv_params.type = BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_LEGACY_SCAN;
} else {
if (param->primary_phy == BLE_MESH_ADV_PHY_1M &&
param->secondary_phy == BLE_MESH_ADV_PHY_1M) {
ext_adv_params.type = BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_LEGACY_NONCONN;
} else {
BT_ERR("Unsupported PHY: pri %d sec %d",param->primary_phy, param->secondary_phy);
return -EINVAL;
}
}
#if CONFIG_BLE_MESH_PRB_SRV
/* NOTE: When a Mesh Private beacon is advertised, the Mesh Private beacon shall
* use a resolvable private address or a non-resolvable private address in the
* AdvA field of the advertising PDU.
*/
if (ad->type == BLE_MESH_DATA_MESH_BEACON && ad->data[0] == BEACON_TYPE_PRIVATE) {
ext_adv_params.own_addr_type = BLE_MESH_ADDR_RANDOM;
} else {
ext_adv_params.own_addr_type = BLE_MESH_ADDR_PUBLIC;
}
#else
ext_adv_params.own_addr_type = BLE_MESH_ADDR_PUBLIC;
#endif
ext_adv_params.sid = inst_id;
ext_adv_params.max_skip = 0;
ext_adv_params.tx_power = 0x7F;
ext_adv_params.scan_req_notif = false;
ext_adv_params.primary_phy = param->primary_phy;
ext_adv_params.secondary_phy = param->secondary_phy;
ext_adv_params.filter_policy = BLE_MESH_AP_SCAN_CONN_ALL;
ext_adv_params.channel_map = BLE_MESH_ADV_CHNL_37 | BLE_MESH_ADV_CHNL_38 | BLE_MESH_ADV_CHNL_39;
interval = param->interval_min;
#if CONFIG_BLE_MESH_RANDOM_ADV_INTERVAL
/* If non-connectable mesh packets are transmitted with an adv interval
* not smaller than 10ms, then we will use a random adv interval between
* [interval / 2, interval] for them.
*/
if (adv_type == BLE_MESH_ADV_NONCONN_IND && interval >= 16) {
interval >>= 1;
interval += (bt_mesh_get_rand() % (interval + 1));
BT_INFO("%u->%u", param->interval_min, interval);
}
#endif
ext_adv_params.interval_min = interval;
ext_adv_params.interval_max = interval;
/* Check if we can start adv using BTM_BleSetAdvParamsStartAdvCheck */
BTA_DmBleGapExtAdvSetParams(inst_id, &ext_adv_params);
err = set_adv_data(BLE_MESH_HCI_OP_SET_ADV_DATA, inst_id, ad, ad_len);
if (err) {
BT_ERR("Failed to set adv data, err %d", err);
return err;
}
/*
* We need to set SCAN_RSP when enabling advertising type that allows
* for Scan Requests.
*
* If sd was not provided but we enable connectable undirected
* advertising sd needs to be cleared from values set by previous calls.
* Clearing sd is done by calling set_adv_data() with NULL data and zero len.
* So following condition check is unusual but correct.
*/
if (sd && (param->options & BLE_MESH_ADV_OPT_CONNECTABLE)) {
err = set_adv_data(BLE_MESH_HCI_OP_SET_SCAN_RSP_DATA, inst_id, sd, sd_len);
if (err) {
BT_ERR("Failed to set scan rsp data err %d", err);
return err;
}
}
ext_adv.instance = inst_id;
ext_adv.duration = param->adv_duration / 10;
ext_adv.max_events = param->adv_count;
BTA_DmBleGapExtAdvEnable(true, 1, &ext_adv);
#if BLE_MESH_DEV
bt_mesh_atomic_set_bit(bt_mesh_dev.flags, BLE_MESH_DEV_ADVERTISING);
if (!(param->options & BLE_MESH_ADV_OPT_ONE_TIME)) {
bt_mesh_atomic_set_bit(bt_mesh_dev.flags, BLE_MESH_DEV_KEEP_ADVERTISING);
}
#endif
return 0;
}
#else /* CONFIG_BLE_MESH_USE_BLE_50 */
/* APIs functions */
int bt_le_adv_start(const struct bt_mesh_adv_param *param,
const struct bt_mesh_adv_data *ad, size_t ad_len,
@@ -348,7 +737,7 @@ int bt_le_adv_start(const struct bt_mesh_adv_param *param,
err = set_adv_data(BLE_MESH_HCI_OP_SET_ADV_DATA, ad, ad_len);
if (err) {
BT_ERR("Failed to set adv data");
BT_ERR("Failed to set adv data, err %d", err);
return err;
}
@@ -364,7 +753,7 @@ int bt_le_adv_start(const struct bt_mesh_adv_param *param,
if (sd && (param->options & BLE_MESH_ADV_OPT_CONNECTABLE)) {
err = set_adv_data(BLE_MESH_HCI_OP_SET_SCAN_RSP_DATA, sd, sd_len);
if (err) {
BT_ERR("Failed to set scan rsp data");
BT_ERR("Failed to set scan rsp data, err %d", err);
return err;
}
}
@@ -427,8 +816,97 @@ int bt_le_adv_start(const struct bt_mesh_adv_param *param,
return 0;
}
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
#if CONFIG_BLE_MESH_SUPPORT_BLE_ADV
#if CONFIG_BLE_MESH_USE_BLE_50
static bool _ble_adv_running_flag;
static inline void bt_mesh_set_ble_adv_running()
{
_ble_adv_running_flag = true;
}
static inline void bt_mesh_unset_ble_adv_running()
{
_ble_adv_running_flag = false;
}
static inline bool bt_mesh_is_ble_adv_running()
{
return _ble_adv_running_flag == true;
}
int bt_mesh_ble_ext_adv_start(const uint8_t inst_id,
const struct bt_mesh_ble_adv_param *param,
const struct bt_mesh_ble_adv_data *data)
{
tBTA_DM_BLE_GAP_EXT_ADV_PARAMS ext_adv_params = {0};
tBTA_DM_BLE_EXT_ADV ext_adv = {0};
struct bt_mesh_hci_cp_set_adv_data set = {0};
if (data && param->adv_type != BLE_MESH_ADV_DIRECT_IND &&
param->adv_type != BLE_MESH_ADV_DIRECT_IND_LOW_DUTY) {
if (data->adv_data_len) {
set.len = data->adv_data_len;
memcpy(set.data, data->adv_data, data->adv_data_len);
BTA_DmBleGapConfigExtAdvDataRaw(false, inst_id, set.len, set.data);
}
if (data->scan_rsp_data_len && param->adv_type != BLE_MESH_ADV_NONCONN_IND) {
set.len = data->scan_rsp_data_len;
memcpy(set.data, data->scan_rsp_data, data->scan_rsp_data_len);
BTA_DmBleGapConfigExtAdvDataRaw(true, inst_id, set.len, set.data);
}
}
switch (param->adv_type) {
case BLE_MESH_ADV_IND:
case BLE_MESH_ADV_DIRECT_IND:
case BLE_MESH_ADV_SCAN_IND:
case BLE_MESH_ADV_NONCONN_IND:
case BLE_MESH_ADV_SCAN_RSP:
ext_adv_params.type = param->adv_type;
break;
default:
BT_ERR("Unsupported adv type %d", param->adv_type);
return -EINVAL;
}
ext_adv_params.max_skip = 0;
ext_adv_params.tx_power = 0x7F;
ext_adv_params.sid = inst_id;
ext_adv_params.scan_req_notif = false;
ext_adv_params.own_addr_type = param->own_addr_type;
ext_adv_params.interval_min = param->interval;
ext_adv_params.interval_max = param->interval;
ext_adv_params.primary_phy = BLE_MESH_ADV_PHY_1M;
ext_adv_params.secondary_phy = BLE_MESH_ADV_PHY_1M;
ext_adv_params.filter_policy = BLE_MESH_AP_SCAN_CONN_ALL;
ext_adv_params.channel_map = BLE_MESH_ADV_CHNL_37 | BLE_MESH_ADV_CHNL_38 | BLE_MESH_ADV_CHNL_39;
if (param->own_addr_type == BLE_MESH_ADDR_PUBLIC_ID ||
param->own_addr_type == BLE_MESH_ADDR_RANDOM_ID ||
param->adv_type == BLE_MESH_ADV_DIRECT_IND ||
param->adv_type == BLE_MESH_ADV_DIRECT_IND_LOW_DUTY) {
ext_adv_params.peer_addr_type = param->peer_addr_type;
memcpy(ext_adv_params.peer_addr, param->peer_addr, BLE_MESH_ADDR_LEN);
}
ext_adv.instance = inst_id;
ext_adv.duration = param->duration;
ext_adv.max_events = param->count;
/* Check if we can start adv using BTM_BleSetAdvParamsStartAdvCheck */
BTA_DmBleGapExtAdvSetParams(inst_id, &ext_adv_params);
BTA_DmBleGapExtAdvEnable(true, 1, &ext_adv);
bt_mesh_set_ble_adv_running();
return 0;
}
#else /* CONFIG_BLE_MESH_USE_BLE_50 */
int bt_mesh_ble_adv_start(const struct bt_mesh_ble_adv_param *param,
const struct bt_mesh_ble_adv_data *data)
{
@@ -470,8 +948,32 @@ int bt_mesh_ble_adv_start(const struct bt_mesh_ble_adv_param *param,
return 0;
}
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_ADV */
#if CONFIG_BLE_MESH_USE_BLE_50
int bt_le_ext_adv_stop(uint8_t inst_id)
{
tBTA_DM_BLE_EXT_ADV ext_adv = {0};
#if BLE_MESH_DEV
bt_mesh_atomic_clear_bit(bt_mesh_dev.flags, BLE_MESH_DEV_KEEP_ADVERTISING);
if (!bt_mesh_atomic_test_bit(bt_mesh_dev.flags, BLE_MESH_DEV_ADVERTISING)) {
return 0;
}
#endif
ext_adv.instance = inst_id;
BTA_DmBleGapExtAdvEnable(false, 1, &ext_adv);
#if BLE_MESH_DEV
bt_mesh_atomic_clear_bit(bt_mesh_dev.flags, BLE_MESH_DEV_ADVERTISING);
#endif
return 0;
}
#else /* CONFIG_BLE_MESH_USE_BLE_50 */
int bt_le_adv_stop(void)
{
#if BLE_MESH_DEV
@@ -489,6 +991,7 @@ int bt_le_adv_stop(void)
return 0;
}
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
int bt_le_scan_start(const struct bt_mesh_scan_param *param, bt_mesh_scan_cb_t cb)
{
@@ -530,7 +1033,11 @@ int bt_le_scan_stop(void)
return -EALREADY;
}
#if CONFIG_BLE_MESH_USE_BLE_50
BTA_DmBleGapExtScan(false, 0 ,0);
#else /* CONFIG_BLE_MESH_USE_BLE_50 */
BLE_MESH_BTM_CHECK_STATUS(BTM_BleScan(false, 0, NULL, NULL, NULL));
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
bt_mesh_atomic_clear_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCANNING);
bt_mesh_scan_dev_found_cb = NULL;
@@ -657,6 +1164,19 @@ static void bt_mesh_bta_gatts_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data)
/* When connection is created, advertising will be stopped automatically. */
bt_mesh_atomic_test_and_clear_bit(bt_mesh_dev.flags, BLE_MESH_DEV_ADVERTISING);
#endif
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
CONFIG_BLE_MESH_GATT_PROXY_CLIENT || \
(CONFIG_BLE_MESH_RPR_SRV && CONFIG_BLE_MESH_PB_GATT)
/* Check if this connection is created by Proxy client */
for (size_t i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
if (!memcmp(bt_mesh_gattc_info[i].addr.val, p_data->conn.remote_bda, BLE_MESH_ADDR_LEN)) {
BT_WARN("Already create connection with %s by proxy client",
bt_hex(p_data->conn.remote_bda, BLE_MESH_ADDR_LEN));
return;
}
}
#endif
if (bt_mesh_gatts_conn_cb != NULL && bt_mesh_gatts_conn_cb->connected != NULL) {
uint8_t index = BLE_MESH_GATT_GET_CONN_ID(p_data->conn.conn_id);
if (index < BLE_MESH_MAX_CONN) {
@@ -1198,6 +1718,9 @@ uint16_t bt_mesh_gattc_get_service_uuid(struct bt_mesh_conn *conn)
int bt_mesh_gattc_conn_create(const bt_mesh_addr_t *addr, uint16_t service_uuid)
{
#if CONFIG_BLE_MESH_USE_BLE_50
tBTA_DM_BLE_CONN_PARAMS conn_1m_param = {0};
#endif
uint8_t zero[6] = {0};
int i;
@@ -1240,21 +1763,47 @@ int bt_mesh_gattc_conn_create(const bt_mesh_addr_t *addr, uint16_t service_uuid)
}
if (bt_mesh_atomic_test_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCANNING)) {
#if CONFIG_BLE_MESH_USE_BLE_50
BTA_DmBleGapExtScan(false, 0 ,0);
#else
BLE_MESH_BTM_CHECK_STATUS(BTM_BleScan(false, 0, NULL, NULL, NULL));
#endif
bt_mesh_atomic_clear_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCANNING);
}
BT_DBG("Create conn with %s", bt_hex(addr->val, BLE_MESH_ADDR_LEN));
#if CONFIG_BLE_MESH_USE_BLE_50
/* Min_interval: 15ms 0x18, 0x18, 0x00, 0x64
* Max_interval: 15ms
* Slave_latency: 0x0
* Supervision_timeout: 1s
*/
conn_1m_param.scan_interval = 0x0020;
conn_1m_param.scan_window = 0x0020;
conn_1m_param.interval_min = 0x18;
conn_1m_param.interval_max = 0x18;
conn_1m_param.latency = 0;
conn_1m_param.supervision_timeout = 0x64;
conn_1m_param.min_ce_len = 0;
conn_1m_param.max_ce_len = 0;
BTA_DmBleGapPreferExtConnectParamsSet(bt_mesh_gattc_info[i].addr.val, 0x01, &conn_1m_param ,NULL, NULL);
BTA_GATTC_Enh_Open(bt_mesh_gattc_if, bt_mesh_gattc_info[i].addr.val,
bt_mesh_gattc_info[i].addr.type, true, BTA_GATT_TRANSPORT_LE, TRUE, BLE_ADDR_UNKNOWN_TYPE);
#else
/* Min_interval: 15ms
* Max_interval: 15ms
* Slave_latency: 0x0
* Supervision_timeout: 1s
*/
BTA_DmSetBlePrefConnParams(bt_mesh_gattc_info[i].addr.val, 0x18, 0x18, 0x00, 0x64);
BTA_GATTC_Open(bt_mesh_gattc_if, bt_mesh_gattc_info[i].addr.val,
bt_mesh_gattc_info[i].addr.type, true, BTA_GATT_TRANSPORT_LE, FALSE);
BTA_GATTC_Enh_Open(bt_mesh_gattc_if, bt_mesh_gattc_info[i].addr.val,
bt_mesh_gattc_info[i].addr.type, true, BTA_GATT_TRANSPORT_LE, FALSE, BLE_ADDR_UNKNOWN_TYPE);
#endif
return 0;
}
@@ -1655,11 +2204,15 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
* use BTM_BleScan() to re-enable scan.
*/
if (!bt_mesh_atomic_test_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCANNING)) {
#if CONFIG_BLE_MESH_USE_BLE_50
BTA_DmBleGapExtScan(true, 0 ,0);
#else
tBTM_STATUS status = BTM_BleScan(true, 0, bt_mesh_scan_results_cb, NULL, NULL);
if (status != BTM_SUCCESS && status != BTM_CMD_STARTED) {
BT_ERR("Invalid scan status %d", status);
break;
}
#endif
bt_mesh_atomic_set_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCANNING);
}
break;

View File

@@ -4,7 +4,7 @@
/*
* SPDX-FileCopyrightText: 2017 Intel Corporation
* SPDX-FileContributor: 2018-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileContributor: 2018-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

View File

@@ -1,7 +1,7 @@
/*
* SPDX-FileCopyrightText: 2017 Nordic Semiconductor ASA
* SPDX-FileCopyrightText: 2015-2017 Intel Corporation
* SPDX-FileContributor: 2018-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileContributor: 2018-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -21,18 +21,78 @@ extern "C" {
#endif
/* BLE Mesh Max Connection Count */
/**
* The maximum number of connection count is limited by
* the resources allocated by both the host and the controller
* components, so the actual number of available connections
* is the minimum of the resources from both.
*
* On the C3/S3 platform, the controller uses the macro `CONFIG_BT_CTRL_BLE_MAX_ACT`,
* but adv and scan also occupy this resource, so the actual number of available
* connections is (CONFIG_BT_CTRL_BLE_MAX_ACT - adv instance count - scan).
* However, the macro allocation on the host is entirely for connections,
* so on the C3/S3 platform, the maximum number of connectable devices should
* be determined by the configuration at the host minus the number of
* advertising instances and scan from the controller's configuration.
*/
#ifdef CONFIG_BT_BLUEDROID_ENABLED
#if CONFIG_IDF_TARGET_ESP32
#define BLE_MESH_MAX_CONN 1
#elif (CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3)
/* @todo: must ensure CONFIG_BT_CTRL_BLE_MAX_ACT is greater than 2 */
#if CONFIG_BT_ACL_CONNECTIONS > (CONFIG_BT_CTRL_BLE_MAX_ACT - 2)
/* decrease the adv,scan */
#define BLE_MESH_MAX_CONN (CONFIG_BT_CTRL_BLE_MAX_ACT - 2)
#else
#define BLE_MESH_MAX_CONN CONFIG_BT_ACL_CONNECTIONS
#endif /* CONFIG_BT_ACL_CONNECTIONS > (CONFIG_BT_CTRL_BLE_MAX_ACT - 2) */
#elif CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32C5
#if CONFIG_BT_ACL_CONNECTIONS > CONFIG_BT_LE_MAX_CONNECTIONS
#define BLE_MESH_MAX_CONN CONFIG_BT_LE_MAX_CONNECTIONS
#else
#define BLE_MESH_MAX_CONN CONFIG_BT_ACL_CONNECTIONS
#endif /* CONFIG_BT_ACL_CONNECTIONS > CONFIG_BT_LE_MAX_CONNECTIONS */
#else
/* default setting */
#define BLE_MESH_MAX_CONN 1
#endif
#endif /* CONFIG_BT_BLUEDROID_ENABLED */
#ifdef CONFIG_BT_NIMBLE_ENABLED
#if CONFIG_IDF_TARGET_ESP32
#define BLE_MESH_MAX_CONN 1
#elif (CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3)
/* @todo: must ensure CONFIG_BT_CTRL_BLE_MAX_ACT is greater than 2 */
#if CONFIG_BT_NIMBLE_MAX_CONNECTIONS > (CONFIG_BT_CTRL_BLE_MAX_ACT - 2)
/* decrease the adv,scan */
#define BLE_MESH_MAX_CONN (CONFIG_BT_CTRL_BLE_MAX_ACT - 2)
#else
#define BLE_MESH_MAX_CONN CONFIG_BT_NIMBLE_MAX_CONNECTIONS
#endif /* CONFIG_BT_NIMBLE_MAX_CONNECTIONS > (CONFIG_BT_CTRL_BLE_MAX_ACT - 2) */
#elif CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32C5
#define BLE_MESH_MAX_CONN CONFIG_BT_NIMBLE_MAX_CONNECTIONS
#else
/* default setting */
#define BLE_MESH_MAX_CONN 1
#endif
#endif /* CONFIG_BT_NIMBLE_ENABLED */
#define BLE_MESH_GAP_ADV_MAX_LEN 31
#define BLE_MESH_GATT_DEF_MTU_SIZE 23
#if CONFIG_BLE_MESH_USE_BLE_50
#define BLE_MESH_ADV_PHY_UNASSIGNED 0
#define BLE_MESH_ADV_PHY_1M 1
#define BLE_MESH_ADV_PHY_2M 2
#define BLE_MESH_ADV_PHY_CODED 3
#define BLE_MESH_ADV_PHY_OPTION_NO_PREFER 0
#define BLE_MESH_ADV_PHY_OPTION_PREFER_S2 1
#define BLE_MESH_ADV_PHY_OPTION_PREFER_S8 2
#define BLE_MESH_ADV_PHY_OPTION_REQUIRE_S2 3
#define BLE_MESH_ADV_PHY_OPTION_REQUIRE_S8 4
#endif
/* BD ADDR types */
#define BLE_MESH_ADDR_PUBLIC 0x00
#define BLE_MESH_ADDR_RANDOM 0x01
@@ -43,11 +103,22 @@ extern "C" {
#define BLE_MESH_ADDR_LEN 0x06
/* Advertising types */
#if !CONFIG_BLE_MESH_USE_BLE_50
#define BLE_MESH_ADV_IND 0x00
#define BLE_MESH_ADV_DIRECT_IND 0x01
#define BLE_MESH_ADV_SCAN_IND 0x02
#define BLE_MESH_ADV_NONCONN_IND 0x03
#define BLE_MESH_ADV_DIRECT_IND_LOW_DUTY 0x04
#define BLE_MESH_ADV_SCAN_RSP 0x04
#else
/* Bluetooth Core Spec 6.0, Vol 4, Part E, 7.7.65.13 */
#define BLE_MESH_ADV_IND (0x13)
#define BLE_MESH_ADV_DIRECT_IND (0x15)
#define BLE_MESH_ADV_SCAN_IND (0x12)
#define BLE_MESH_ADV_NONCONN_IND (0x10)
#define BLE_MESH_ADV_DIRECT_IND_LOW_DUTY (0x1b)
#define BLE_MESH_ADV_SCAN_RSP (0x1b)
#endif
/* advertising channel map */
#define BLE_MESH_ADV_CHNL_37 BIT(0)
@@ -400,8 +471,32 @@ struct bt_mesh_adv_param {
/** Maximum Advertising Interval (N * 0.625) */
uint16_t interval_max;
#if CONFIG_BLE_MESH_USE_BLE_50
/** Maximum Advertising Duration (N * 0.625) */
uint16_t adv_duration;
/** Advertising Packages Number */
uint16_t adv_count;
/** Advertising Primary PHY */
uint8_t primary_phy;
/** Advertising Secondary PHY */
uint8_t secondary_phy;
#endif
};
#if CONFIG_BLE_MESH_USE_BLE_50
enum bt_mesh_adv_inst_type {
BLE_MESH_ADV_PROXY_INS,
BLE_MESH_ADV_INS,
BLE_MESH_EXT_ADV_INS,
BLE_MESH_BLE_ADV_INS,
BLE_MESH_ADV_INS_TYPE_NUMS,
};
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
#if CONFIG_BLE_MESH_SUPPORT_BLE_ADV
enum bt_mesh_ble_adv_priority {
BLE_MESH_BLE_ADV_PRIO_LOW,
@@ -441,7 +536,7 @@ struct bt_mesh_scan_param {
/** Scan interval (N * 0.625 ms) */
uint16_t interval;
/** Scan window (N * 0.625 ms) */
/** Uncoded phy Scan window (N * 0.625 ms) */
uint16_t window;
/** BLE scan filter policy */
@@ -453,21 +548,38 @@ struct bt_mesh_conn {
bt_mesh_atomic_t ref;
};
/* BLE Mesh advertising report */
struct bt_mesh_adv_report {
/* Advertiser LE address and type. */
bt_mesh_addr_t addr;
/* Strength of advertiser signal. */
int8_t rssi;
/* Type of advertising response from advertiser. */
uint8_t adv_type;
/* Buffer containing advertiser data. */
struct net_buf_simple adv_data;
#if CONFIG_BLE_MESH_USE_BLE_50
/* Primary advertising PHY */
uint8_t primary_phy;
/* Secondary advertising PHY */
uint8_t secondary_phy;
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
};
/** @typedef bt_mesh_scan_cb_t
* @brief Callback type for reporting LE scan results.
*
* A function of this type is given to the bt_le_scan_start() function
* and will be called for any discovered LE device.
*
* @param addr Advertiser LE address and type.
* @param rssi Strength of advertiser signal.
* @param adv_type Type of advertising response from advertiser.
* @param data Buffer containing advertiser data.
* @param scan_rsp_len Scan Response data length.
* @param adv_rpt: BLE Mesh advertising report.
*/
typedef void bt_mesh_scan_cb_t(const bt_mesh_addr_t *addr, int8_t rssi,
uint8_t adv_type, struct net_buf_simple *buf,
uint8_t scan_rsp_len);
typedef void bt_mesh_scan_cb_t(struct bt_mesh_adv_report *adv_rpt);
/* @typedef bt_mesh_dh_key_cb_t
* @brief Callback type for DH Key calculation.
@@ -553,7 +665,7 @@ struct bt_mesh_gatt_attr {
* @param len Length of data to read
* @param offset Offset to start reading from
*
* @return Number fo bytes read, or in case of an error
* @return Number of bytes read, or in case of an error
* BLE_MESH_GATT_ERR() with a specific ATT error code.
*/
ssize_t (*read)(struct bt_mesh_conn *conn,
@@ -684,6 +796,21 @@ struct bt_mesh_gatt_attr {
int bt_mesh_host_init(void);
int bt_mesh_host_deinit(void);
#if CONFIG_BLE_MESH_USE_BLE_50
int bt_le_ext_adv_start(const uint8_t inst_id,
const struct bt_mesh_adv_param *param,
const struct bt_mesh_adv_data *ad, size_t ad_len,
const struct bt_mesh_adv_data *sd, size_t sd_len);
#if CONFIG_BLE_MESH_SUPPORT_BLE_ADV
int bt_mesh_ble_ext_adv_start(const uint8_t inst_id,
const struct bt_mesh_ble_adv_param *param,
const struct bt_mesh_ble_adv_data *adv_data);
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_ADV */
int bt_le_ext_adv_stop(uint8_t inst_id);
#else /* CONFIG_BLE_MESH_USE_BLE_50 */
int bt_le_adv_start(const struct bt_mesh_adv_param *param,
const struct bt_mesh_adv_data *ad, size_t ad_len,
const struct bt_mesh_adv_data *sd, size_t sd_len);
@@ -691,9 +818,10 @@ int bt_le_adv_start(const struct bt_mesh_adv_param *param,
#if CONFIG_BLE_MESH_SUPPORT_BLE_ADV
int bt_mesh_ble_adv_start(const struct bt_mesh_ble_adv_param *param,
const struct bt_mesh_ble_adv_data *data);
#endif
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_ADV */
int bt_le_adv_stop(void);
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
int bt_le_scan_start(const struct bt_mesh_scan_param *param, bt_mesh_scan_cb_t cb);

View File

@@ -13,6 +13,7 @@
#include "crypto.h"
#include "adv.h"
#include "net.h"
#include "scan.h"
#include "mesh.h"
#include "lpn.h"
@@ -836,6 +837,9 @@ int bt_mesh_net_resend(struct bt_mesh_subnet *sub, struct net_buf *buf,
uint16_t dst = 0U;
int err = 0;
/* The variable is not used when proxy server or proxy client is disabled. */
ARG_UNUSED(dst);
BT_DBG("net_idx 0x%04x new_key %u len %u", sub->net_idx, new_key,
buf->len);
@@ -913,18 +917,22 @@ int bt_mesh_net_resend(struct bt_mesh_subnet *sub, struct net_buf *buf,
return err;
}
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER) &&
bt_mesh_proxy_server_relay(&buf->b, dst) &&
BLE_MESH_ADDR_IS_UNICAST(dst)) {
/**
* TODO: Find a way to determine how the message was sent previously
* during a retransmission, to avoid ineffective advertising.
*/
#if CONFIG_BLE_MESH_GATT_PROXY_SERVER
if (bt_mesh_proxy_server_relay(&buf->b, dst) &&
BLE_MESH_ADDR_IS_UNICAST(dst) &&
bt_mesh_proxy_server_find_client_by_addr(dst)) {
send_cb_finalize(cb, cb_data);
return 0;
}
#endif
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_CLIENT) &&
bt_mesh_proxy_client_relay(&buf->b, dst)) {
send_cb_finalize(cb, cb_data);
return 0;
}
#if CONFIG_BLE_MESH_GATT_PROXY_CLIENT
bt_mesh_proxy_client_relay(&buf->b, dst);
#endif
bt_mesh_adv_send(buf, BLE_MESH_ADV(buf)->xmit, cb, cb_data);
return 0;
@@ -1051,6 +1059,7 @@ static void bt_mesh_net_adv_xmit_update(struct bt_mesh_net_tx *tx)
int bt_mesh_net_send(struct bt_mesh_net_tx *tx, struct net_buf *buf,
const struct bt_mesh_send_cb *cb, void *cb_data)
{
const struct bt_mesh_send_cb *send_cb = cb;
uint8_t bearer = BLE_MESH_ALL_BEARERS;
int err = 0;
@@ -1115,31 +1124,48 @@ int bt_mesh_net_send(struct bt_mesh_net_tx *tx, struct net_buf *buf,
* shall drop all messages secured using the friendship security
* credentials."
*/
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER) &&
(bearer & BLE_MESH_GATT_BEARER) &&
(tx->ctx->send_ttl != 1U ||
bt_mesh_tag_relay(tx->ctx->send_tag)) &&
#if CONFIG_BLE_MESH_GATT_PROXY_SERVER
if ((bearer & BLE_MESH_GATT_BEARER) &&
(tx->ctx->send_ttl != 1U || bt_mesh_tag_relay(tx->ctx->send_tag)) &&
tx->ctx->send_cred != BLE_MESH_FRIENDSHIP_CRED) {
if (bt_mesh_proxy_server_relay(&buf->b, tx->ctx->addr) &&
BLE_MESH_ADDR_IS_UNICAST(tx->ctx->addr)) {
/* Notify completion if this only went
* through the Mesh Proxy.
/* When the destination address is identified as a proxy client
* address, the message will be sent only to the proxy client.
* This action will enhance the efficiency of the proxy server
* in sending data packets.
*
* It should be noted that this approach does not significantly
* reduce the number of advertising packets in the air, as other
* proxy clients may receive the message and resend it through
* a advertising method.
*/
if ((bearer & (~BLE_MESH_GATT_BEARER)) == 0) {
send_cb_finalize(cb, cb_data);
if (bt_mesh_proxy_server_find_client_by_addr(tx->ctx->addr)) {
send_cb_finalize(send_cb, cb_data);
send_cb = NULL;
err = 0;
goto done;
}
/* Finalize transmission if this only went through GATT bearer */
if ((bearer & (~BLE_MESH_GATT_BEARER)) == 0) {
send_cb_finalize(send_cb, cb_data);
send_cb = NULL;
#if CONFIG_BLE_MESH_GATT_PROXY_CLIENT
/* This message will not be transmitted by proxy client */
if (!bt_mesh_proxy_client_get_conn_count()) {
goto done;
}
#endif /* CONFIG_BLE_MESH_GATT_PROXY_CLIENT */
}
}
}
#endif /* CONFIG_BLE_MESH_GATT_PROXY_SERVER */
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_CLIENT) &&
(bearer & BLE_MESH_GATT_BEARER) &&
(tx->ctx->send_ttl != 1U ||
bt_mesh_tag_relay(tx->ctx->send_tag)) &&
#if CONFIG_BLE_MESH_GATT_PROXY_CLIENT
if ((bearer & BLE_MESH_GATT_BEARER) &&
(tx->ctx->send_ttl != 1U || bt_mesh_tag_relay(tx->ctx->send_tag)) &&
tx->ctx->send_cred != BLE_MESH_FRIENDSHIP_CRED) {
if (bt_mesh_proxy_client_relay(&buf->b, tx->ctx->addr)) {
/* If Proxy Client succeeds to send messages with GATT bearer,
@@ -1147,45 +1173,43 @@ int bt_mesh_net_send(struct bt_mesh_net_tx *tx, struct net_buf *buf,
* connection has been created with Proxy Client, here we will
* use advertising bearer for the messages.
*/
send_cb_finalize(cb, cb_data);
if ((bearer & (~BLE_MESH_GATT_BEARER)) == 0) {
send_cb_finalize(send_cb, cb_data);
send_cb = NULL;
err = 0;
goto done;
goto done;
}
}
}
#endif /* CONFIG_BLE_MESH_GATT_PROXY_CLIENT */
/* Deliver to local network interface if necessary */
if (((IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_provisioned()) ||
(IS_ENABLED(CONFIG_BLE_MESH_PROVISIONER) && bt_mesh_is_provisioner_en())) &&
(bt_mesh_fixed_group_match(tx->ctx->addr) || bt_mesh_elem_find(tx->ctx->addr))) {
/**
* If the target address isn't a unicast address, then the callback function
* will be called by `adv task` in place of here, to avoid the callback function
* being called twice.
/* If the target address isn't a unicast address, then the callback
* function will be called by mesh adv task instead of called here
* to avoid the callback function being called twice.
* See BLEMESH24-76 for more details.
*/
if (BLE_MESH_ADDR_IS_UNICAST(tx->ctx->addr)) {
if (cb && cb->start) {
cb->start(0, 0, cb_data);
if (send_cb && send_cb->start) {
send_cb->start(0, 0, cb_data);
}
net_buf_slist_put(&bt_mesh.local_queue, net_buf_ref(buf));
if (cb && cb->end) {
cb->end(0, cb_data);
if (send_cb && send_cb->end) {
send_cb->end(0, cb_data);
}
bt_mesh_net_local();
err = 0;
goto done;
} else {
net_buf_slist_put(&bt_mesh.local_queue, net_buf_ref(buf));
bt_mesh_net_local();
}
err = 0;
net_buf_slist_put(&bt_mesh.local_queue, net_buf_ref(buf));
bt_mesh_net_local();
}
if ((bearer & BLE_MESH_ADV_BEARER) &&
@@ -1207,7 +1231,6 @@ int bt_mesh_net_send(struct bt_mesh_net_tx *tx, struct net_buf *buf,
BLE_MESH_TRANSMIT_COUNT(tx->xmit), BLE_MESH_TRANSMIT_INT(tx->xmit));
bt_mesh_adv_send(buf, tx->xmit, cb, cb_data);
err = 0;
goto done;
}
@@ -1727,8 +1750,8 @@ static void bt_mesh_net_relay(struct net_buf_simple *sbuf,
* shall drop all messages secured using the friendship security
* credentials.
*/
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER) &&
(bearer & BLE_MESH_GATT_BEARER) &&
#if CONFIG_BLE_MESH_GATT_PROXY_SERVER
if ((bearer & BLE_MESH_GATT_BEARER) &&
((bt_mesh_gatt_proxy_get() == BLE_MESH_GATT_PROXY_ENABLED &&
cred != BLE_MESH_FRIENDSHIP_CRED) ||
#if CONFIG_BLE_MESH_PRB_SRV
@@ -1738,11 +1761,14 @@ static void bt_mesh_net_relay(struct net_buf_simple *sbuf,
rx->ctx.recv_cred == BLE_MESH_FRIENDSHIP_CRED)) {
if (bt_mesh_proxy_server_relay(&buf->b, rx->ctx.recv_dst) &&
BLE_MESH_ADDR_IS_UNICAST(rx->ctx.recv_dst)) {
if ((bearer & (~BLE_MESH_GATT_BEARER)) == 0) {
if (((bearer & (~BLE_MESH_GATT_BEARER)) == 0) ||
bt_mesh_proxy_server_find_client_by_addr(rx->ctx.recv_dst)) {
goto done;
}
}
}
#endif /* CONFIG_BLE_MESH_GATT_PROXY_SERVER */
if (((bearer & BLE_MESH_ADV_BEARER) && relay_to_adv(rx->net_if)) ||
netkey_changed ||
@@ -1892,24 +1918,26 @@ static bool ignore_net_msg(uint16_t src, uint16_t dst)
return false;
}
void bt_mesh_net_recv(struct net_buf_simple *data, int8_t rssi,
enum bt_mesh_net_if net_if)
void bt_mesh_generic_net_recv(struct net_buf_simple *data,
struct bt_mesh_net_rx *rx,
enum bt_mesh_net_if net_if)
{
NET_BUF_SIMPLE_DEFINE(buf, 29);
struct bt_mesh_net_rx rx = { .ctx.recv_rssi = rssi };
struct net_buf_simple_state state = {0};
BT_DBG("rssi %d net_if %u", rssi, net_if);
assert(rx);
BT_DBG("rssi %d net_if %u", rx->ctx.recv_rssi, net_if);
if (!ready_to_recv()) {
return;
}
if (bt_mesh_net_decode(data, net_if, &rx, &buf)) {
if (bt_mesh_net_decode(data, net_if, rx, &buf)) {
return;
}
if (ignore_net_msg(rx.ctx.addr, rx.ctx.recv_dst)) {
if (ignore_net_msg(rx->ctx.addr, rx->ctx.recv_dst)) {
return;
}
@@ -1919,26 +1947,26 @@ void bt_mesh_net_recv(struct net_buf_simple *data, int8_t rssi,
BT_BQB(BLE_MESH_BQB_TEST_LOG_LEVEL_PRIMARY_ID_NODE | \
BLE_MESH_BQB_TEST_LOG_LEVEL_SUB_ID_NET,
"\nNetRecv: ctl: %d, src: %d, dst: %d, ttl: %d, data: 0x%s",
rx.ctl, rx.ctx.addr, rx.ctx.recv_dst, rx.ctx.recv_ttl,
rx->ctl, rx->ctx.addr, rx->ctx.recv_dst, rx->ctx.recv_ttl,
bt_hex(buf.data + BLE_MESH_NET_HDR_LEN, buf.len - BLE_MESH_NET_HDR_LEN));
/* If trying to handle a message with DST set to all-directed-forwarding-nodes,
* we need to make sure the directed forwarding functionality is enabled in the
* corresponding subnet.
*/
rx.local_match = (bt_mesh_fixed_group_match(rx.ctx.recv_dst) ||
bt_mesh_fixed_direct_match(rx.sub, rx.ctx.recv_dst) ||
bt_mesh_elem_find(rx.ctx.recv_dst));
rx->local_match = (bt_mesh_fixed_group_match(rx->ctx.recv_dst) ||
bt_mesh_fixed_direct_match(rx->sub, rx->ctx.recv_dst) ||
bt_mesh_elem_find(rx->ctx.recv_dst));
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER) &&
#if CONFIG_BLE_MESH_PRB_SRV
bt_mesh_private_gatt_proxy_state_get() != BLE_MESH_PRIVATE_GATT_PROXY_ENABLED &&
#endif
net_if == BLE_MESH_NET_IF_PROXY) {
bt_mesh_proxy_server_addr_add(data, rx.ctx.addr);
bt_mesh_proxy_server_addr_add(data, rx->ctx.addr);
if (bt_mesh_gatt_proxy_get() == BLE_MESH_GATT_PROXY_DISABLED &&
!rx.local_match) {
!rx->local_match) {
BT_INFO("Proxy is disabled; ignoring message");
return;
}
@@ -1951,11 +1979,11 @@ void bt_mesh_net_recv(struct net_buf_simple *data, int8_t rssi,
* tag the Network PDU with the immutable-credentials tag.
*/
#if CONFIG_BLE_MESH_DF_SRV
if (rx.sub->directed_proxy == BLE_MESH_DIRECTED_PROXY_ENABLED &&
rx.sub->use_directed == BLE_MESH_PROXY_USE_DIRECTED_ENABLED &&
!bt_mesh_addr_in_uar(&rx.sub->proxy_client_uar, rx.ctx.addr) &&
!bt_mesh_proxy_server_find_client_by_addr(rx.ctx.addr)) {
rx.ctx.recv_tag |= BLE_MESH_TAG_IMMUTABLE_CRED;
if (rx->sub->directed_proxy == BLE_MESH_DIRECTED_PROXY_ENABLED &&
rx->sub->use_directed == BLE_MESH_PROXY_USE_DIRECTED_ENABLED &&
!bt_mesh_addr_in_uar(&rx->sub->proxy_client_uar, rx->ctx.addr) &&
!bt_mesh_proxy_server_find_client_by_addr(rx->ctx.addr)) {
rx->ctx.recv_tag |= BLE_MESH_TAG_IMMUTABLE_CRED;
}
#endif /* CONFIG_BLE_MESH_DF_SRV */
}
@@ -1967,24 +1995,24 @@ void bt_mesh_net_recv(struct net_buf_simple *data, int8_t rssi,
* credentials. Remove it from the message cache so that we accept
* it again in the future.
*/
if (bt_mesh_trans_recv(&buf, &rx) == -EAGAIN) {
if (bt_mesh_trans_recv(&buf, rx) == -EAGAIN) {
BT_WARN("Removing rejected message from Network Message Cache");
msg_cache[rx.msg_cache_idx].src = BLE_MESH_ADDR_UNASSIGNED;
msg_cache[rx->msg_cache_idx].src = BLE_MESH_ADDR_UNASSIGNED;
/* Rewind the next index now that we're not using this entry */
msg_cache_next = rx.msg_cache_idx;
msg_cache_next = rx->msg_cache_idx;
}
/* Relay if this was a group/virtual address, or if the destination
* was neither a local element nor an LPN we're Friends for.
*/
if (!BLE_MESH_ADDR_IS_UNICAST(rx.ctx.recv_dst) ||
(!rx.local_match && !rx.friend_match
if (!BLE_MESH_ADDR_IS_UNICAST(rx->ctx.recv_dst) ||
(!rx->local_match && !rx->friend_match
#if CONFIG_BLE_MESH_NOT_RELAY_REPLAY_MSG
&& !rx.replay_msg
&& !rx->replay_msg
#endif
)) {
net_buf_simple_restore(&buf, &state);
bt_mesh_net_relay(&buf, &rx);
bt_mesh_net_relay(&buf, rx);
}
}

View File

@@ -2,7 +2,7 @@
/*
* SPDX-FileCopyrightText: 2017 Intel Corporation
* SPDX-FileContributor: 2018-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileContributor: 2018-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -465,8 +465,16 @@ int bt_mesh_net_resend(struct bt_mesh_subnet *sub, struct net_buf *buf,
int bt_mesh_net_decode(struct net_buf_simple *data, enum bt_mesh_net_if net_if,
struct bt_mesh_net_rx *rx, struct net_buf_simple *buf);
void bt_mesh_net_recv(struct net_buf_simple *data, int8_t rssi,
enum bt_mesh_net_if net_if);
void bt_mesh_generic_net_recv(struct net_buf_simple *data,
struct bt_mesh_net_rx *rx,
enum bt_mesh_net_if net_if);
static inline void bt_mesh_net_recv(struct net_buf_simple *data, int8_t rssi,
enum bt_mesh_net_if net_if)
{
struct bt_mesh_net_rx rx = { .ctx.recv_rssi = rssi };
bt_mesh_generic_net_recv(data, &rx, net_if);
}
bool bt_mesh_primary_subnet_exist(void);

View File

@@ -1,7 +1,7 @@
/*
* SPDX-FileCopyrightText: 2017 Nordic Semiconductor ASA
* SPDX-FileCopyrightText: 2015-2016 Intel Corporation
* SPDX-FileContributor: 2018-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileContributor: 2018-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -27,6 +27,8 @@
#include "mesh/hci.h"
#include "mesh/common.h"
#include "prov_pvnr.h"
#include "scan.h"
#include "btc_ble_mesh_ble.h"
/** @def BT_UUID_MESH_PROV
* @brief Mesh Provisioning Service
@@ -69,7 +71,6 @@ static uint8_t bt_mesh_private_key[32];
/* Scan related functions */
static bt_mesh_scan_cb_t *bt_mesh_scan_dev_found_cb;
#if CONFIG_BLE_MESH_NODE
/* the gatt database list to save the attribute table */
static sys_slist_t bt_mesh_gatts_db;
@@ -79,10 +80,57 @@ static struct bt_mesh_conn bt_mesh_gatts_conn[BLE_MESH_MAX_CONN];
static struct bt_mesh_conn_cb *bt_mesh_gatts_conn_cb;
static uint8_t bt_mesh_gatts_addr[6];
#if CONFIG_BLE_MESH_USE_BLE_50
static bool g_gatts_svcs_add = false;
#endif
#endif /* CONFIG_BLE_MESH_NODE */
#if CONFIG_BLE_MESH_USE_BLE_50 && CONFIG_BLE_MESH_SUPPORT_BLE_ADV
static inline void bt_mesh_set_ble_adv_running();
static inline void bt_mesh_unset_ble_adv_running();
static inline bool bt_mesh_is_ble_adv_running();
#endif
static bool g_host_init = false;
#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_USE_BLE_50
#define BT_MESH_GATTS_CONN_UNUSED 0xFF
static void bt_mesh_gatts_conn_init(void)
{
int i;
for (i = 0; i < BLE_MESH_MAX_CONN; i++) {
bt_mesh_gatts_conn[i].handle = BT_MESH_GATTS_CONN_UNUSED;
}
}
static int bt_mesh_find_free_conn_idx(void)
{
int i;
for (i = 0; i < BLE_MESH_MAX_CONN; i++) {
if (bt_mesh_gatts_conn[i].handle == BT_MESH_GATTS_CONN_UNUSED) {
return i;
}
}
return -ENOMEM;
}
static int bt_mesh_find_conn_idx(uint16_t conn_handle)
{
int i;
for (i = 0; i < BLE_MESH_MAX_CONN; i++) {
if (bt_mesh_gatts_conn[i].handle == conn_handle) {
return i;
}
}
return -ENODEV;
}
#endif /* CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_USE_BLE_50 */
int bt_mesh_host_init(void)
{
int rc;
@@ -145,7 +193,13 @@ void bt_mesh_hci_init(void)
#endif
}
#if CONFIG_BLE_MESH_USE_BLE_50
static struct ble_gap_ext_disc_params uncoded_disc_params;
static struct ble_gap_ext_disc_params coded_disc_params;
#else
static struct ble_gap_disc_params scan_param;
#endif
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
static struct gattc_prov_info {
@@ -350,13 +404,19 @@ static int svc_disced(uint16_t conn_handle, const struct ble_gatt_error *error,
}
uuid = &service->uuid;
uuid_length = (uint8_t) (uuid->u.type == BLE_UUID_TYPE_16 ? 2 : 16);
uuid_length = (uint8_t)(uuid->u.type == BLE_UUID_TYPE_16 ? 2 : 16);
if (uuid_length != 2) {
return 0;
}
for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
if (bt_mesh_gattc_info[i].service_uuid == (uint16_t)BLE_UUID16(uuid)->value) {
/**
* In scenarios with multiple connections, to prevent
* subsequent connections from affecting the first one,
* a check for the connection handle is needed here.
*/
if (bt_mesh_gattc_info[i].conn.handle == conn_handle &&
bt_mesh_gattc_info[i].service_uuid == (uint16_t)BLE_UUID16(uuid)->value) {
bt_mesh_gattc_info[i].start_handle = service->start_handle;
bt_mesh_gattc_info[i].end_handle = service->end_handle;
break;
@@ -398,9 +458,45 @@ static int svc_disced(uint16_t conn_handle, const struct ble_gatt_error *error,
}
#endif /* (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || CONFIG_BLE_MESH_GATT_PROXY_CLIENT */
static int disc_cb(struct ble_gap_event *event, void *arg)
#if CONFIG_BLE_MESH_USE_BLE_50
void bt_mesh_ble_ext_adv_report(struct ble_gap_ext_disc_desc *desc)
{
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
bt_mesh_ble_adv_report_t adv_rpt = {0};
if (bt_mesh_ble_scan_state_get()) {
memcpy(adv_rpt.addr, desc->addr.val, BLE_MESH_ADDR_LEN);
memcpy(adv_rpt.dir_addr, desc->direct_addr.val, BLE_MESH_ADDR_LEN);
/* Here, only a shallow copy needs to be implemented;
* deep copying behavior occurs in btc_ble_mesh_ble_copy_req_data. */
adv_rpt.data = desc->data;
adv_rpt.event_type = desc->props;
adv_rpt.addr_type = desc->addr.type;
adv_rpt.length = desc->length_data;
adv_rpt.rssi = desc->rssi;
adv_rpt.primary_phy = desc->prim_phy;
adv_rpt.secondary_phy = desc->sec_phy;
adv_rpt.sid = desc->sid;
adv_rpt.tx_power = desc->tx_power;
adv_rpt.dir_addr_type = desc->direct_addr.type;
adv_rpt.data_status = desc->data_status;
adv_rpt.per_adv_interval = desc->periodic_adv_itvl;
bt_mesh_ble_scan_cb_evt_to_btc(&adv_rpt);
}
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_SCAN */
}
#endif
int disc_cb(struct ble_gap_event *event, void *arg)
{
#if CONFIG_BLE_MESH_USE_BLE_50
struct ble_gap_ext_disc_desc *desc;
#else
struct ble_gap_disc_desc *desc;
#endif
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
int rc, i;
@@ -412,21 +508,58 @@ static int disc_cb(struct ble_gap_event *event, void *arg)
#endif
switch (event->type) {
case BLE_GAP_EVENT_DISC: {
struct net_buf_simple buf = {0};
#if CONFIG_BLE_MESH_USE_BLE_50
case BLE_GAP_EVENT_EXT_DISC: {
struct bt_mesh_adv_report adv_rpt = {0};
desc = &event->disc;
net_buf_simple_init_with_data(&buf, (void *)desc->data, desc->length_data);
desc = &event->ext_disc;
memcpy(&adv_rpt.addr, &desc->addr, sizeof(bt_mesh_addr_t));
adv_rpt.rssi = desc->rssi;
adv_rpt.adv_type = desc->props;
adv_rpt.primary_phy = desc->prim_phy;
adv_rpt.secondary_phy = desc->sec_phy;
net_buf_simple_init_with_data(&adv_rpt.adv_data, (void *)desc->data, desc->length_data);
if (bt_mesh_scan_dev_found_cb) {
/* TODO: Support Scan Response data length for NimBLE host */
bt_mesh_scan_dev_found_cb((bt_mesh_addr_t *)&desc->addr, desc->rssi, desc->event_type, &buf, 0);
if (desc->props & BLE_HCI_ADV_LEGACY_MASK) {
bt_mesh_scan_dev_found_cb(&adv_rpt);
}
}
/* Mesh didn't process that data */
if (adv_rpt.adv_data.len == desc->length_data) {
bt_mesh_ble_ext_adv_report(desc);
}
break;
}
#else /* CONFIG_BLE_MESH_USE_BLE_50 */
case BLE_GAP_EVENT_DISC: {
struct bt_mesh_adv_report adv_rpt = {0};
desc = &event->disc;
adv_rpt.rssi = desc->rssi;
adv_rpt.adv_type = desc->event_type;
memcpy(&adv_rpt.addr, &desc->addr, sizeof(bt_mesh_addr_t));
net_buf_simple_init_with_data(&adv_rpt.adv_data, (void *)desc->data, desc->length_data);
if (bt_mesh_scan_dev_found_cb) {
/* TODO: Support Scan Response data length for NimBLE host */
bt_mesh_scan_dev_found_cb(&adv_rpt);
}
break;
}
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
case BLE_GAP_EVENT_CONNECT:
/* @todo: process connect failed event */
if (event->connect.status == 0) {
/* Connection successfully established. */
MODLOG_DFLT(INFO, "Connection established ");
@@ -442,10 +575,21 @@ static int disc_cb(struct ble_gap_event *event, void *arg)
break;
}
}
if (i == ARRAY_SIZE(bt_mesh_gattc_info)) {
goto transfer_to_user;
}
} else {
goto transfer_to_user;
}
}
if (!bt_mesh_atomic_test_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCANNING)) {
#if CONFIG_BLE_MESH_USE_BLE_50
rc = ble_gap_ext_disc(BLE_OWN_ADDR_PUBLIC, 0, 0, 0, 0, 0,
uncoded_disc_params.itvl ? &uncoded_disc_params : NULL,
coded_disc_params.itvl ? &coded_disc_params : NULL, disc_cb, NULL);
#else /* CONFIG_BLE_MESH_USE_BLE_50 */
rc = ble_gap_disc(BLE_OWN_ADDR_PUBLIC, BLE_HS_FOREVER, &scan_param, disc_cb, NULL);
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
if (rc != 0) {
BT_ERR("Invalid scan status %d", rc);
break;
@@ -494,7 +638,13 @@ static int disc_cb(struct ble_gap_event *event, void *arg)
bt_mesh_gattc_info[i].wr_desc_done = false;
break;
}
if (i == ARRAY_SIZE(bt_mesh_gattc_info)) {
goto transfer_to_user;
}
}
} else {
goto transfer_to_user;
}
break;
case BLE_GAP_EVENT_MTU:
@@ -521,6 +671,8 @@ static int disc_cb(struct ble_gap_event *event, void *arg)
}
/* Search Mesh Provisioning Service or Mesh Proxy Service */
ble_gattc_disc_all_svcs(bt_mesh_gattc_info[i].conn.handle, svc_disced, NULL);
} else {
goto transfer_to_user;
}
break;
case BLE_GAP_EVENT_NOTIFY_RX:
@@ -531,8 +683,8 @@ static int disc_cb(struct ble_gap_event *event, void *arg)
}
if (i == ARRAY_SIZE(bt_mesh_gattc_info)) {
BT_ERR("Conn handle 0x%04x not found", event->notify_rx.conn_handle);
return 0;
BT_DBG("Conn handle 0x%04x not blonges to Mesh", event->notify_rx.conn_handle);
goto transfer_to_user;
}
conn = &bt_mesh_gattc_info[i].conn;
@@ -557,7 +709,7 @@ static int disc_cb(struct ble_gap_event *event, void *arg)
if (bt_mesh_gattc_info[i].service_uuid == BLE_MESH_UUID_MESH_PROV_VAL) {
if (bt_mesh_gattc_conn_cb != NULL && bt_mesh_gattc_conn_cb->prov_notify != NULL) {
len = bt_mesh_gattc_conn_cb->prov_notify(&bt_mesh_gattc_info[i].conn,
notif_data, notif_len);
notif_data, notif_len);
if (len < 0) {
BT_ERR("prov_notify failed");
bt_mesh_gattc_disconnect(conn);
@@ -568,7 +720,7 @@ static int disc_cb(struct ble_gap_event *event, void *arg)
if (bt_mesh_gattc_conn_cb != NULL && bt_mesh_gattc_conn_cb->proxy_notify != NULL &&
bt_mesh_gattc_info[i].wr_desc_done) {
len = bt_mesh_gattc_conn_cb->proxy_notify(&bt_mesh_gattc_info[i].conn,
notif_data, notif_len);
notif_data, notif_len);
if (len < 0) {
BT_ERR("proxy_notify failed");
bt_mesh_gattc_disconnect(conn);
@@ -579,14 +731,53 @@ static int disc_cb(struct ble_gap_event *event, void *arg)
break;
#endif
default:
goto transfer_to_user;
break;
}
return 0;
transfer_to_user:
#if CONFIG_BLE_MESH_USE_BLE_50
bt_mesh_ble_nimble_evt_to_btc(event, arg);
#endif
return 0;
}
#if CONFIG_BLE_MESH_USE_BLE_50
/**
* @brief Get the gap callback function used by BLE Mesh
*
* @note The user must get the mesh gap event handler function
* through the bt_mesh_nimble_gap_cb_get function and pass
* it in as a callback function when using the api:
* ble_gap_ext_connect, ble_gap_ext_disc, ble_gap_connect,
* and ble_gap_disc.
*
* @return void*
*/
void *bt_mesh_nimble_gap_cb_get(void)
{
return (void*)disc_cb;
}
#endif
static int start_le_scan(uint8_t scan_type, uint16_t interval, uint16_t window, uint8_t filter_dup)
{
#if CONFIG_BLE_MESH_USE_BLE_50
uncoded_disc_params.itvl = (window ? interval : 0);
uncoded_disc_params.window = window;
coded_disc_params.itvl = ((interval > window) ? interval : 0);
coded_disc_params.window = ((interval > window) ? interval - window : 0);
coded_disc_params.passive = (scan_type == BLE_MESH_SCAN_PASSIVE);
uncoded_disc_params.passive = (scan_type == BLE_MESH_SCAN_PASSIVE);
ble_gap_ext_disc(BLE_OWN_ADDR_PUBLIC, 0, 0, filter_dup, 0, 0,
uncoded_disc_params.itvl ? &uncoded_disc_params : NULL,
coded_disc_params.itvl ? &coded_disc_params : NULL, disc_cb, NULL);
#else /* CONFIG_BLE_MESH_USE_BLE_50 */
scan_param.filter_duplicates = filter_dup;
scan_param.itvl = interval;
scan_param.window = window;
@@ -597,6 +788,7 @@ static int start_le_scan(uint8_t scan_type, uint16_t interval, uint16_t window,
scan_param.passive = 0;
}
ble_gap_disc(BLE_OWN_ADDR_PUBLIC, BLE_HS_FOREVER, &scan_param, disc_cb, NULL);
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
#if BLE_MESH_DEV
if (scan_type == BLE_MESH_SCAN_ACTIVE) {
@@ -648,12 +840,38 @@ static int gap_event_cb(struct ble_gap_event *event, void *arg)
/* When connection is created, advertising will be stopped automatically. */
bt_mesh_atomic_test_and_clear_bit(bt_mesh_dev.flags, BLE_MESH_DEV_ADVERTISING);
#endif
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
CONFIG_BLE_MESH_GATT_PROXY_CLIENT || \
(CONFIG_BLE_MESH_RPR_SRV && CONFIG_BLE_MESH_PB_GATT)
/* Check if this connection is created by Proxy client */
for (size_t i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
if (!memcmp(bt_mesh_gattc_info[i].addr.val, desc.peer_id_addr.val, BLE_MESH_ADDR_LEN)) {
BT_WARN("Already create connection with %s by proxy client",
bt_hex(desc.peer_id_addr.val, BLE_MESH_ADDR_LEN));
return 0;
}
}
#endif
if (bt_mesh_gatts_conn_cb != NULL && bt_mesh_gatts_conn_cb->connected != NULL) {
uint8_t index = BLE_MESH_GATT_GET_CONN_ID(event->connect.conn_handle);
int index = 0;
#if CONFIG_BLE_MESH_USE_BLE_50
index = bt_mesh_find_free_conn_idx();
if (index != -ENOMEM) {
bt_mesh_gatts_conn[index].handle = BLE_MESH_GATT_GET_CONN_ID(event->connect.conn_handle);
(bt_mesh_gatts_conn_cb->connected)(&bt_mesh_gatts_conn[index], 0);
} else {
BT_ERR("No space for new connection");
ble_gap_terminate(event->connect.conn_handle, BLE_ERR_CONN_LIMIT);
}
#else /* CONFIG_BLE_MESH_USE_BLE_50 */
index = BLE_MESH_GATT_GET_CONN_ID(event->connect.conn_handle);
if (index < BLE_MESH_MAX_CONN) {
bt_mesh_gatts_conn[index].handle = BLE_MESH_GATT_GET_CONN_ID(event->connect.conn_handle);
(bt_mesh_gatts_conn_cb->connected)(&bt_mesh_gatts_conn[index], 0);
}
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
memcpy(bt_mesh_gatts_addr, desc.peer_id_addr.val, BLE_MESH_ADDR_LEN);
/* This is for EspBleMesh Android app. When it tries to connect with the
* device at the first time and it fails due to some reason. And after
@@ -673,11 +891,23 @@ static int gap_event_cb(struct ble_gap_event *event, void *arg)
bt_mesh_atomic_test_and_clear_bit(bt_mesh_dev.flags, BLE_MESH_DEV_ADVERTISING);
#endif
if (bt_mesh_gatts_conn_cb != NULL && bt_mesh_gatts_conn_cb->disconnected != NULL) {
uint8_t index = BLE_MESH_GATT_GET_CONN_ID(event->disconnect.conn.conn_handle);
int index = 0;
#if CONFIG_BLE_MESH_USE_BLE_50
index = bt_mesh_find_conn_idx(BLE_MESH_GATT_GET_CONN_ID(event->disconnect.conn.conn_handle));
if (index != -ENODEV) {
bt_mesh_gatts_conn[index].handle = BLE_MESH_GATT_GET_CONN_ID(event->disconnect.conn.conn_handle);
(bt_mesh_gatts_conn_cb->disconnected)(&bt_mesh_gatts_conn[index], event->disconnect.reason);
} else {
BT_ERR("No device");
}
#else /* CONFIG_BLE_MESH_USE_BLE_50 */
index = BLE_MESH_GATT_GET_CONN_ID(event->disconnect.conn.conn_handle);
if (index < BLE_MESH_MAX_CONN) {
bt_mesh_gatts_conn[index].handle = BLE_MESH_GATT_GET_CONN_ID(event->disconnect.conn.conn_handle);
(bt_mesh_gatts_conn_cb->disconnected)(&bt_mesh_gatts_conn[index], event->disconnect.reason);
}
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
bt_mesh_gatts_conn[index].handle = 0;
memset(bt_mesh_gatts_addr, 0x0, BLE_MESH_ADDR_LEN);
}
@@ -693,8 +923,38 @@ static int gap_event_cb(struct ble_gap_event *event, void *arg)
return 0;
case BLE_GAP_EVENT_ADV_COMPLETE:
MODLOG_DFLT(INFO, "advertise complete; reason=%d",
event->adv_complete.reason);
BT_DBG("advertise complete; reason=%d",
event->adv_complete.reason);
/* Limit Reached (0x43) and Advertising Timeout (0x3C) will cause BLE_HS_ETIMEOUT to be set. */
#if CONFIG_BLE_MESH_USE_BLE_50
if (event->adv_complete.reason == BLE_HS_ETIMEOUT) {
ble_mesh_adv_task_wakeup(event->adv_complete.instance);
}
#if CONFIG_BLE_MESH_SUPPORT_BLE_ADV
/**
* This judgment is to distinguish between the termination
* events of BLE connectable broadcasting and proxy connectable
* adv under the same instance ID, that is, when the status is 0.
*
* Since the host task and adv task are currently operated in
* series, there is no need to consider competition issues between
* tasks.
*
* @attention: once multiple adv instances are used, the adv task
* and host will be asynchronous, and it is necessary to consider
* the issue of resource competition.
*/
if (bt_mesh_is_ble_adv_running() &&
event->adv_complete.reason == 0) {
/* The unset operation must be performed before waking up the
* adv task; performing the unset after waking up the adv task
* could lead to resource contention issues.
*/
bt_mesh_unset_ble_adv_running();
ble_mesh_adv_task_wakeup(event->adv_complete.instance);
}
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_ADV */
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
return 0;
case BLE_GAP_EVENT_ENC_CHANGE:
@@ -717,10 +977,20 @@ static int gap_event_cb(struct ble_gap_event *event, void *arg)
event->subscribe.prev_indicate,
event->subscribe.cur_indicate);
struct bt_mesh_gatt_attr *attr = bt_mesh_gatts_find_attr_by_handle(event->subscribe.attr_handle + 1);
uint8_t index = BLE_MESH_GATT_GET_CONN_ID(event->subscribe.conn_handle);
int index = 0;
uint16_t len = 0;
uint16_t ccc_val = 0;
#if CONFIG_BLE_MESH_USE_BLE_50
index = bt_mesh_find_conn_idx(BLE_MESH_GATT_GET_CONN_ID(event->subscribe.conn_handle));
if (index == -ENODEV) {
BT_ERR("Couldn't find conn %d", event->subscribe.conn_handle);
return 0;
}
#else /* CONFIG_BLE_MESH_USE_BLE_50 */
index = BLE_MESH_GATT_GET_CONN_ID(event->subscribe.conn_handle);
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
if (event->subscribe.prev_notify != event->subscribe.cur_notify) {
ccc_val = event->subscribe.cur_notify;
} else if (event->subscribe.prev_indicate != event->subscribe.cur_indicate) {
@@ -773,10 +1043,231 @@ static int gap_event_cb(struct ble_gap_event *event, void *arg)
#else
static int gap_event_cb(struct ble_gap_event *event, void *arg)
{
#if CONFIG_BLE_MESH_USE_BLE_50
switch (event->type) {
case BLE_GAP_EVENT_ADV_COMPLETE:
BT_DBG("Provisioner advertise complete; reason=%d",
event->adv_complete.reason);
/* Limit Reached (0x43) and Advertising Timeout (0x3C) will cause BLE_HS_ETIMEOUT to be set. */
if (event->adv_complete.reason == BLE_HS_ETIMEOUT) {
ble_mesh_adv_task_wakeup(event->adv_complete.instance);
}
#if CONFIG_BLE_MESH_SUPPORT_BLE_ADV
/**
* This judgment is to distinguish between the termination
* events of BLE connectable broadcasting and proxy connectable
* adv under the same instance ID, that is, when the status is 0.
*
* Since the host task and adv task are currently operated in
* series, there is no need to consider competition issues between
* tasks.
*
* @attention: once multiple adv instances are used, the adv task
* and host will be asynchronous, and it is necessary to consider
* the issue of resource competition.
*/
if (bt_mesh_is_ble_adv_running() &&
event->adv_complete.reason == 0) {
/* The unset operation must be performed before waking up the
* adv task; performing the unset after waking up the adv task
* could lead to resource contention issues.
*/
bt_mesh_unset_ble_adv_running();
ble_mesh_adv_task_wakeup(event->adv_complete.instance);
}
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_ADV */
break;
}
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
return 0;
}
#endif /* CONFIG_BLE_MESH_NODE */
#if CONFIG_BLE_MESH_USE_BLE_50
int bt_le_ext_adv_start(const uint8_t inst_id,
const struct bt_mesh_adv_param *param,
const struct bt_mesh_adv_data *ad, size_t ad_len,
const struct bt_mesh_adv_data *sd, size_t sd_len)
{
struct ble_gap_ext_adv_params adv_params = {0};
struct os_mbuf *data = NULL;
struct os_mbuf *scan_rsp = NULL;
uint8_t *buf = NULL;
uint16_t interval = 0;
uint8_t buf_len = 0;
int err = 0;
err = ble_gap_ext_adv_active(inst_id);
if (err) {
BT_ERR("adv inst(%d) is running %d", inst_id, err);
return -EINVAL;
}
#if BLE_MESH_DEV
if (bt_mesh_atomic_test_bit(bt_mesh_dev.flags, BLE_MESH_DEV_ADVERTISING)) {
return -EALREADY;
}
#endif
buf = bt_mesh_calloc(ad_len * BLE_HS_ADV_MAX_SZ);
if (!buf) {
BT_ERR("ad buffer alloc failed");
return -ENOMEM;
}
err = set_ad(ad, ad_len, buf, &buf_len);
if (err) {
bt_mesh_free(buf);
BT_ERR("set_ad failed: err %d", err);
return err;
}
data = os_msys_get_pkthdr(buf_len, 0);
if (!data) {
bt_mesh_free(buf);
BT_ERR("os buf get failed");
return -ENOBUFS;
}
err = os_mbuf_append(data, buf, buf_len);
if (err) {
bt_mesh_free(buf);
BT_ERR("Append ad data to os buf failed %d", err);
return -EINVAL;
}
bt_mesh_free(buf);
if (sd && (param->options & BLE_MESH_ADV_OPT_CONNECTABLE)) {
buf_len = 0;
buf = bt_mesh_calloc(sd_len * BLE_HS_ADV_MAX_SZ);
if (!buf) {
BT_ERR("ad buffer alloc failed");
return -ENOMEM;
}
err = set_ad(sd, sd_len, buf, &buf_len);
if (err) {
bt_mesh_free(buf);
BT_ERR("set_ad failed: err %d", err);
return err;
}
scan_rsp = os_msys_get_pkthdr(buf_len, 0);
if (!data) {
bt_mesh_free(buf);
BT_ERR("os buf get failed");
return -ENOBUFS;
}
err = os_mbuf_append(scan_rsp, buf, buf_len);
if (err) {
bt_mesh_free(buf);
BT_ERR("Append ad data to os buf failed %d", err);
return -EINVAL;
}
bt_mesh_free(buf);
}
memset(&adv_params, 0, sizeof adv_params);
assert(param);
if (param->options & BLE_MESH_ADV_OPT_CONNECTABLE) {
adv_params.connectable = true;
adv_params.scannable = true;
adv_params.legacy_pdu = true;
} else if (sd != NULL) {
adv_params.connectable = false;
adv_params.scannable = true;
adv_params.legacy_pdu = true;
} else {
if (param->primary_phy == BLE_MESH_ADV_PHY_1M &&
param->secondary_phy == BLE_MESH_ADV_PHY_1M) {
adv_params.legacy_pdu = true;
}
}
adv_params.sid = inst_id;
adv_params.primary_phy = param->primary_phy;
adv_params.secondary_phy = param->secondary_phy;
adv_params.tx_power = 0x7F; // tx power will be selected by controller
adv_params.own_addr_type = BLE_OWN_ADDR_PUBLIC;
interval = param->interval_min;
#if CONFIG_BLE_MESH_RANDOM_ADV_INTERVAL
/* If non-connectable mesh packets are transmitted with an adv interval
* not smaller than 10ms, then we will use a random adv interval between
* [interval / 2, interval] for them.
*/
if (adv_params.conn_mode == BLE_GAP_CONN_MODE_NON &&
adv_params.disc_mode == BLE_GAP_DISC_MODE_NON && interval >= 16) {
interval >>= 1;
interval += (bt_mesh_get_rand() % (interval + 1));
adv_params->high_duty_directed = true;
BT_INFO("%u->%u", param->interval_min, interval);
}
#endif
adv_params.itvl_min = interval;
adv_params.itvl_max = interval;
err = ble_gap_ext_adv_configure(inst_id, &adv_params, NULL, gap_event_cb, NULL);
if (err != 0) {
BT_ERR("Advertising config failed: err %d", err);
return err;
}
err = ble_gap_ext_adv_set_data(inst_id, data);
if (err != 0) {
BT_ERR("Advertising set failed: err %d", err);
return err;
}
if (scan_rsp) {
err = ble_gap_ext_adv_rsp_set_data(inst_id, scan_rsp);
if (err != 0) {
BT_ERR("scan rsp set failed: err %d", err);
return err;
} else {
BT_INFO("scan rsp set succeed\n");
}
}
again:
if (param->adv_duration < 10 &&
param->adv_duration != 0) {
BT_WARN("adv duration shall not be less than 10ms");
}
err = ble_gap_ext_adv_start(inst_id, param->adv_duration ?
2 + param->adv_duration / 10 : 0, param->adv_count);
if (err) {
if (err == BLE_HS_EALREADY) {
ble_gap_ext_adv_stop(inst_id);
goto again;
}
BT_ERR("Advertising start failed: err %d", err);
return err;
}
#if BLE_MESH_DEV
bt_mesh_atomic_set_bit(bt_mesh_dev.flags, BLE_MESH_DEV_ADVERTISING);
if (!(param->options & BLE_MESH_ADV_OPT_ONE_TIME)) {
bt_mesh_atomic_set_bit(bt_mesh_dev.flags, BLE_MESH_DEV_KEEP_ADVERTISING);
}
#endif
return 0;
}
#else /* CONFIG_BLE_MESH_USE_BLE_50 */
/* APIs functions */
int bt_le_adv_start(const struct bt_mesh_adv_param *param,
const struct bt_mesh_adv_data *ad, size_t ad_len,
@@ -877,8 +1368,146 @@ again:
return 0;
}
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
#if CONFIG_BLE_MESH_SUPPORT_BLE_ADV
#if CONFIG_BLE_MESH_USE_BLE_50
static bool _ble_adv_running_flag;
static inline void bt_mesh_set_ble_adv_running()
{
_ble_adv_running_flag = true;
}
static inline void bt_mesh_unset_ble_adv_running()
{
_ble_adv_running_flag = false;
}
static inline bool bt_mesh_is_ble_adv_running()
{
return _ble_adv_running_flag == true;
}
int bt_mesh_ble_ext_adv_start(const uint8_t inst_id,
const struct bt_mesh_ble_adv_param *param,
const struct bt_mesh_ble_adv_data *adv_data)
{
struct ble_gap_ext_adv_params adv_params = {0};
struct os_mbuf *data = NULL;
int err = 0;
assert(param);
switch (param->adv_type) {
case BLE_MESH_ADV_IND:
adv_params.connectable = true;
adv_params.scannable = true;
adv_params.legacy_pdu = true;
break;
case BLE_MESH_ADV_DIRECT_IND:
adv_params.connectable = true;
adv_params.scannable = false;
adv_params.directed = true;
adv_params.high_duty_directed = false;
adv_params.legacy_pdu = true;
break;
case BLE_MESH_ADV_SCAN_IND:
adv_params.connectable = false;
adv_params.scannable = true;
adv_params.directed = false;
adv_params.high_duty_directed = false;
adv_params.legacy_pdu = true;
break;
case BLE_MESH_ADV_NONCONN_IND:
adv_params.connectable = false;
adv_params.scannable = false;
adv_params.directed = false;
adv_params.high_duty_directed = false;
adv_params.legacy_pdu = true;
break;
case BLE_MESH_ADV_DIRECT_IND_LOW_DUTY:
adv_params.connectable = true;
adv_params.scannable = false;
adv_params.directed = true;
adv_params.high_duty_directed = true;
adv_params.legacy_pdu = true;
break;
}
adv_params.itvl_min = param->interval;
adv_params.itvl_max = param->interval;
adv_params.channel_map = BLE_MESH_ADV_CHNL_37 | BLE_MESH_ADV_CHNL_38 | BLE_MESH_ADV_CHNL_39;
adv_params.filter_policy = BLE_MESH_AP_SCAN_CONN_ALL;
adv_params.primary_phy = BLE_MESH_ADV_PHY_1M;
adv_params.secondary_phy = BLE_MESH_ADV_PHY_1M;
if (param->own_addr_type == BLE_MESH_ADDR_PUBLIC_ID ||
param->own_addr_type == BLE_MESH_ADDR_RANDOM_ID ||
param->adv_type == BLE_MESH_ADV_DIRECT_IND ||
param->adv_type == BLE_MESH_ADV_DIRECT_IND_LOW_DUTY) {
adv_params.peer.type = param->peer_addr_type;
memcpy(adv_params.peer.val, param->peer_addr, BLE_MESH_ADDR_LEN);
}
if (ble_gap_ext_adv_configure(inst_id, &adv_params, NULL,
gap_event_cb, NULL)) {
BT_ERR("ble adv configure failed\n");
return -EINVAL;
}
if (adv_data && param->adv_type != BLE_MESH_ADV_DIRECT_IND &&
param->adv_type != BLE_MESH_ADV_DIRECT_IND_LOW_DUTY) {
if (adv_data->adv_data_len) {
data = os_msys_get_pkthdr(adv_data->adv_data_len, 0);
if (!data) {
BT_ERR("Failed to alloc buffer for ble");
return -ENOMEM;
}
if (os_mbuf_append(data, adv_data->adv_data, adv_data->adv_data_len)) {
BT_ERR("Append data failed");
return -EINVAL;
}
err = ble_gap_ext_adv_set_data(inst_id, data);
if (err) {
BT_ERR("Failed to set advertising data, err %d", err);
return err;
}
}
if (adv_data->scan_rsp_data_len && param->adv_type != BLE_MESH_ADV_NONCONN_IND) {
data = os_msys_get_pkthdr(adv_data->scan_rsp_data_len, 0);
if (!data) {
BT_ERR("Failed to alloc buffer for ble");
return -ENOMEM;
}
if (os_mbuf_append(data, adv_data->scan_rsp_data, adv_data->scan_rsp_data_len)) {
BT_ERR("Append data failed");
return -EINVAL;
}
err = ble_gap_ext_adv_rsp_set_data(inst_id, data);
if (err) {
BT_ERR("Failed to set scan rsp data, err %d", err);
return err;
}
}
}
err = ble_gap_ext_adv_start(inst_id, 2 + param->duration / 10, param->count);
if (err) {
BT_ERR("Failed to start advertising, err %d", err);
return err;
}
bt_mesh_set_ble_adv_running();
return 0;
}
#else /* CONFIG_BLE_MESH_USE_BLE_50 */
int bt_mesh_ble_adv_start(const struct bt_mesh_ble_adv_param *param,
const struct bt_mesh_ble_adv_data *data)
{
@@ -949,8 +1578,27 @@ int bt_mesh_ble_adv_start(const struct bt_mesh_ble_adv_param *param,
return 0;
}
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_ADV */
#if CONFIG_BLE_MESH_USE_BLE_50
int bt_le_ext_adv_stop(uint8_t inst_id)
{
#if BLE_MESH_DEV
bt_mesh_atomic_clear_bit(bt_mesh_dev.flags, BLE_MESH_DEV_KEEP_ADVERTISING);
if (!bt_mesh_atomic_test_bit(bt_mesh_dev.flags, BLE_MESH_DEV_ADVERTISING)) {
return 0;
}
#endif
ble_gap_ext_adv_stop(inst_id);
#if BLE_MESH_DEV
bt_mesh_atomic_clear_bit(bt_mesh_dev.flags, BLE_MESH_DEV_ADVERTISING);
#endif
return 0;
}
#else /* CONFIG_BLE_MESH_USE_BLE_50 */
int bt_le_adv_stop(void)
{
#if BLE_MESH_DEV
@@ -967,6 +1615,7 @@ int bt_le_adv_stop(void)
return 0;
}
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
int bt_le_scan_start(const struct bt_mesh_scan_param *param, bt_mesh_scan_cb_t cb)
{
@@ -987,6 +1636,7 @@ int bt_le_scan_start(const struct bt_mesh_scan_param *param, bt_mesh_scan_cb_t c
err = start_le_scan(param->type, param->interval, param->window, param->filter_dup);
if (err) {
BT_ERR("Failed to start advertising, err %d", err);
return err;
}
@@ -1554,6 +2204,7 @@ int bt_mesh_gattc_write_no_rsp(struct bt_mesh_conn *conn,
om = ble_hs_mbuf_from_flat(data, len);
if (om == NULL) {
BT_ERR("om buffer alloc failed");
return -1;
}
@@ -1622,9 +2273,19 @@ static int proxy_char_access_cb(uint16_t conn_handle, uint16_t attr_handle,
{
if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR || ctxt->op == BLE_GATT_ACCESS_OP_WRITE_DSC) {
struct bt_mesh_gatt_attr *attr = bt_mesh_gatts_find_attr_by_handle(attr_handle);
uint8_t index = BLE_MESH_GATT_GET_CONN_ID(conn_handle);
int index = 0;
uint16_t len = 0;
#if CONFIG_BLE_MESH_USE_BLE_50
index = bt_mesh_find_conn_idx(BLE_MESH_GATT_GET_CONN_ID(conn_handle));
if (index == -ENODEV) {
BT_ERR("Unknown conn handle");
return 0;
}
#else
index = BLE_MESH_GATT_GET_CONN_ID(conn_handle);
#endif
BT_DBG("write, handle %d, len %d, data %s", attr_handle,
ctxt->om->om_len,
bt_hex(ctxt->om->om_data, ctxt->om->om_len));
@@ -1713,6 +2374,58 @@ void gatt_register_cb(struct ble_gatt_register_ctxt *ctxt,
}
}
#if CONFIG_BLE_MESH_USE_BLE_50
void bt_mesh_gatts_svcs_add(void)
{
ble_hs_cfg.gatts_register_cb = gatt_register_cb;
#if CONFIG_BLE_MESH_NODE
int rc = 0;
ble_svc_gap_init();
ble_svc_gatt_init();
rc = ble_gatts_count_cfg(svc_defs);
assert(rc == 0);
rc = ble_gatts_add_svcs(svc_defs);
assert(rc == 0);
g_gatts_svcs_add = true;
#endif
}
void bt_mesh_gatt_init(void)
{
ble_att_set_preferred_mtu(BLE_MESH_GATT_DEF_MTU_SIZE);
#if CONFIG_BLE_MESH_NODE
static bool init = false;
if (init == false) {
__ASSERT(g_gatts_svcs_add, "func bt_mesh_gatts_svcs_add should be called before mesh init");
ble_gatts_svc_set_visibility(prov_svc_start_handle, 1);
ble_gatts_svc_set_visibility(proxy_svc_start_handle, 0);
#if CONFIG_BLE_MESH_USE_BLE_50
bt_mesh_gatts_conn_init();
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
init = true;
}
#endif /* CONFIG_BLE_MESH_NODE */
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
for (int i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
bt_mesh_gattc_info[i].conn.handle = 0xFFFF;
bt_mesh_gattc_info[i].mtu = BLE_ATT_MTU_DFLT;
bt_mesh_gattc_info[i].wr_desc_done = false;
}
#endif
}
#else
void bt_mesh_gatt_init(void)
{
ble_att_set_preferred_mtu(BLE_ATT_MTU_DFLT);
@@ -1751,6 +2464,7 @@ void bt_mesh_gatt_init(void)
}
#endif
}
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
#if CONFIG_BLE_MESH_DEINIT
void bt_mesh_gatt_deinit(void)
@@ -1981,12 +2695,12 @@ int bt_mesh_update_exceptional_list(uint8_t sub_code, uint32_t type, void *info)
if ((sub_code > BLE_MESH_EXCEP_LIST_SUB_CODE_CLEAN) ||
(sub_code < BLE_MESH_EXCEP_LIST_SUB_CODE_CLEAN &&
type > BLE_MESH_EXCEP_LIST_TYPE_MESH_PROXY_ADV) ||
type > BLE_MESH_EXCEP_LIST_TYPE_MAX) ||
(sub_code == BLE_MESH_EXCEP_LIST_SUB_CODE_CLEAN &&
!(type & BLE_MESH_EXCEP_LIST_CLEAN_ALL_LIST))) {
BT_ERR("%s, Invalid parameter", __func__);
return -EINVAL;
}
}
if (type == BLE_MESH_EXCEP_LIST_TYPE_MESH_LINK_ID) {
if (!info) {

View File

@@ -1471,6 +1471,9 @@ int bt_mesh_pb_gatt_close(struct bt_mesh_conn *conn, uint8_t reason)
if (bt_mesh_atomic_test_bit(prov_link.flags, PB_REMOTE)) {
prov_link.pb_remote_cbd = true;
prov_link.pb_remote_reset = true;
/* @todo: the close reason is disconnect reason, not the
* link close reason, should change it to link close reason?
*/
prov_link.pb_remote_close(&prov_link, reason);
}
#endif

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -820,6 +820,23 @@ int bt_mesh_proxy_client_disconnect(uint8_t conn_handle)
return 0;
}
uint16_t bt_mesh_proxy_client_get_conn_count(void)
{
uint16_t count = 0;
for (size_t i = 0; i < ARRAY_SIZE(servers); i++) {
struct bt_mesh_proxy_server *server = &servers[i];
if (!server->conn || server->conn_type != CLI_PROXY) {
continue;
}
count++;
}
return count;
}
bool bt_mesh_proxy_client_relay(struct net_buf_simple *buf, uint16_t dst)
{
bool send = false;

View File

@@ -104,6 +104,8 @@ int bt_mesh_proxy_client_disconnect(uint8_t conn_handle);
bool bt_mesh_proxy_client_beacon_send(struct bt_mesh_subnet *sub, bool private);
uint16_t bt_mesh_proxy_client_get_conn_count(void);
bool bt_mesh_proxy_client_relay(struct net_buf_simple *buf, uint16_t dst);
int bt_mesh_proxy_client_cfg_send(uint8_t conn_handle, uint16_t net_idx,

View File

@@ -2,7 +2,7 @@
/*
* SPDX-FileCopyrightText: 2017 Intel Corporation
* SPDX-FileContributor: 2018-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileContributor: 2018-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -29,12 +29,16 @@
#if (CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PB_GATT) || \
CONFIG_BLE_MESH_GATT_PROXY_SERVER
#if !CONFIG_BLE_MESH_BQB_TEST
#if !CONFIG_BLE_MESH_BQB_TEST && !CONFIG_BLE_MESH_PROXY_CLI_SRV_COEXIST && !CONFIG_BLE_MESH_RPR_SRV
/* Not support enabling Proxy Client and Proxy Server simultaneously */
_Static_assert(!(IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER) && IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_CLIENT)),
"Not support Proxy Server and Proxy Client simultaneously");
#endif
#if CONFIG_BLE_MESH_USE_BLE_50
static uint8_t proxy_adv_inst = BLE_MESH_ADV_INS_UNUSED;
#endif
#define ADV_OPT (BLE_MESH_ADV_OPT_CONNECTABLE | BLE_MESH_ADV_OPT_ONE_TIME)
#if CONFIG_BLE_MESH_GATT_PROXY_SERVER && \
@@ -52,12 +56,24 @@ static const struct bt_mesh_adv_param slow_adv_param = {
.options = ADV_OPT,
.interval_min = BLE_MESH_GAP_ADV_SLOW_INT_MIN,
.interval_max = BLE_MESH_GAP_ADV_SLOW_INT_MAX,
#if CONFIG_BLE_MESH_USE_BLE_50
.primary_phy = BLE_MESH_ADV_PHY_1M,
.secondary_phy = BLE_MESH_ADV_PHY_1M,
.adv_duration = 0,
.adv_count = 0,
#endif
};
static const struct bt_mesh_adv_param fast_adv_param = {
.options = ADV_OPT,
.interval_min = BLE_MESH_GAP_ADV_FAST_INT_MIN_0,
.interval_max = BLE_MESH_GAP_ADV_FAST_INT_MAX_0,
#if CONFIG_BLE_MESH_USE_BLE_50
.primary_phy = BLE_MESH_ADV_PHY_1M,
.secondary_phy = BLE_MESH_ADV_PHY_1M,
.adv_duration = 0,
.adv_count = 0,
#endif
};
static bool proxy_adv_enabled;
@@ -1465,8 +1481,13 @@ static int node_id_adv(struct bt_mesh_subnet *sub)
memcpy(proxy_svc_data + 3, tmp + 8, 8);
proxy_sd_len = gatt_proxy_adv_create(&proxy_sd);
err = bt_le_adv_start(&fast_adv_param, node_id_ad,
ARRAY_SIZE(node_id_ad), &proxy_sd, proxy_sd_len);
#if CONFIG_BLE_MESH_USE_BLE_50
err = bt_le_ext_adv_start(proxy_adv_inst, &fast_adv_param, node_id_ad,
ARRAY_SIZE(node_id_ad), &proxy_sd, proxy_sd_len);
#else
err = bt_le_adv_start(&fast_adv_param, node_id_ad,
ARRAY_SIZE(node_id_ad), &proxy_sd, proxy_sd_len);
#endif
if (err) {
BT_WARN("Failed to advertise using Node ID (err %d)", err);
return err;
@@ -1491,8 +1512,13 @@ static int net_id_adv(struct bt_mesh_subnet *sub)
memcpy(proxy_svc_data + 3, sub->keys[sub->kr_flag].net_id, 8);
proxy_sd_len = gatt_proxy_adv_create(&proxy_sd);
err = bt_le_adv_start(&slow_adv_param, net_id_ad,
ARRAY_SIZE(net_id_ad), &proxy_sd, proxy_sd_len);
#if CONFIG_BLE_MESH_USE_BLE_50
err = bt_le_ext_adv_start(proxy_adv_inst, &slow_adv_param, net_id_ad,
ARRAY_SIZE(net_id_ad), &proxy_sd, proxy_sd_len);
#else
err = bt_le_adv_start(&slow_adv_param, net_id_ad,
ARRAY_SIZE(net_id_ad), &proxy_sd, proxy_sd_len);
#endif
if (err) {
BT_WARN("Failed to advertise using Network ID (err %d)", err);
return err;
@@ -1836,13 +1862,20 @@ int32_t bt_mesh_proxy_server_adv_start(void)
return K_FOREVER;
}
#if CONFIG_BLE_MESH_USE_BLE_50
if (proxy_adv_inst == BLE_MESH_ADV_INS_UNUSED) {
BT_ERR("Proxy adv inst is not initialized!");
return K_FOREVER;
}
#endif
#if CONFIG_BLE_MESH_PB_GATT
if (prov_fast_adv) {
prov_start_time = k_uptime_get_32();
}
if (!bt_mesh_is_provisioned()) {
const struct bt_mesh_adv_param *param;
const struct bt_mesh_adv_param *param = NULL;
struct bt_mesh_adv_data prov_sd[2];
size_t prov_sd_len;
@@ -1854,8 +1887,14 @@ int32_t bt_mesh_proxy_server_adv_start(void)
prov_sd_len = gatt_prov_adv_create(prov_sd);
#if CONFIG_BLE_MESH_USE_BLE_50
if (bt_le_ext_adv_start(proxy_adv_inst, param, prov_ad, ARRAY_SIZE(prov_ad),
prov_sd, prov_sd_len) == 0) {
#else /* CONFIG_BLE_MESH_USE_BLE_50 */
if (bt_le_adv_start(param, prov_ad, ARRAY_SIZE(prov_ad),
prov_sd, prov_sd_len) == 0) {
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
proxy_adv_enabled = true;
/* Advertise 60 seconds using fast interval */
@@ -1899,7 +1938,16 @@ void bt_mesh_proxy_server_adv_stop(void)
return;
}
#if CONFIG_BLE_MESH_USE_BLE_50
if (proxy_adv_inst == BLE_MESH_ADV_INS_UNUSED) {
BT_ERR("Proxy adv inst is not initialized!");
return;
}
err = bt_le_ext_adv_stop(proxy_adv_inst);
#else
err = bt_le_adv_stop();
#endif
if (err) {
BT_ERR("Failed to stop advertising (err %d)", err);
} else {
@@ -1916,6 +1964,10 @@ int bt_mesh_proxy_server_init(void)
{
int i;
#if CONFIG_BLE_MESH_USE_BLE_50
proxy_adv_inst = bt_mesh_get_proxy_inst();
#endif
#if CONFIG_BLE_MESH_GATT_PROXY_SERVER
bt_mesh_gatts_service_register(&proxy_svc);
#endif
@@ -1954,6 +2006,10 @@ int bt_mesh_proxy_server_deinit(void)
{
int i;
#if CONFIG_BLE_MESH_USE_BLE_50
proxy_adv_inst = BLE_MESH_ADV_INS_UNUSED;
#endif
proxy_adv_enabled = false;
gatt_svc = MESH_GATT_NONE;

View File

@@ -12,6 +12,7 @@
#include "net.h"
#include "mesh/adapter.h"
#include "adv.h"
#ifdef __cplusplus
extern "C" {

View File

@@ -41,6 +41,22 @@
#define PROXY_SVC_DATA_LEN_PRIVATE_NET_ID 0x11
#define PROXY_SVC_DATA_LEN_PRIVATE_NODE_ID 0x11
static struct bt_mesh_scan_param scan_param = {
#if CONFIG_BLE_MESH_RPR_SRV_ACTIVE_SCAN
.type = BLE_MESH_SCAN_ACTIVE,
#else
.type = BLE_MESH_SCAN_PASSIVE,
#endif
#if CONFIG_BLE_MESH_USE_DUPLICATE_SCAN
.filter_dup = BLE_MESH_SCAN_FILTER_DUP_ENABLE,
#else
.filter_dup = BLE_MESH_SCAN_FILTER_DUP_DISABLE,
#endif
.interval = SCAN_INTERVAL,
.window = SCAN_WINDOW,
.scan_fil_policy = BLE_MESH_SP_ADV_ALL,
};
#if (CONFIG_BLE_MESH_PROVISIONER || CONFIG_BLE_MESH_RPR_SRV)
static const bt_mesh_addr_t *unprov_dev_addr;
static uint8_t current_adv_type;
@@ -336,13 +352,27 @@ int bt_mesh_stop_ble_scan(void)
return 0;
}
bool bt_mesh_ble_scan_state_get(void)
{
return ble_scan_en;
}
static void inline callback_ble_adv_pkt(const bt_mesh_addr_t *addr,
uint8_t adv_type, uint8_t data[],
uint16_t length, int8_t rssi)
{
#if !CONFIG_BLE_MESH_USE_BLE_50
bt_mesh_ble_adv_report_t adv_rpt = {0};
if (ble_scan_en) {
bt_mesh_ble_scan_cb_evt_to_btc(addr, adv_type, data, length, rssi);
memcpy(adv_rpt.addr, addr->val, BD_ADDR_LEN);
adv_rpt.addr_type = addr->type;
adv_rpt.adv_type = adv_type;
adv_rpt.length = length;
adv_rpt.data = data;
adv_rpt.rssi = rssi;
bt_mesh_ble_scan_cb_evt_to_btc(&adv_rpt);
}
#endif
}
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_SCAN */
@@ -364,11 +394,11 @@ static bool rpr_ext_scan_handle_adv_pkt(const bt_mesh_addr_t *addr,
}
#endif /* CONFIG_BLE_MESH_RPR_SRV */
static void bt_mesh_scan_cb(const bt_mesh_addr_t *addr,
int8_t rssi, uint8_t adv_type,
struct net_buf_simple *buf,
uint8_t scan_rsp_len)
static void bt_mesh_scan_cb(struct bt_mesh_adv_report *adv_rpt)
{
struct net_buf_simple_state buf_state = {0};
struct net_buf_simple *buf = &adv_rpt->adv_data;
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
CONFIG_BLE_MESH_GATT_PROXY_CLIENT || \
CONFIG_BLE_MESH_PROXY_SOLIC_PDU_RX
@@ -379,20 +409,44 @@ static void bt_mesh_scan_cb(const bt_mesh_addr_t *addr,
uint16_t adv_len = buf->len;
#endif
if (adv_type != BLE_MESH_ADV_NONCONN_IND && adv_type != BLE_MESH_ADV_IND) {
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
callback_ble_adv_pkt(addr, adv_type, adv_data, adv_len, rssi);
net_buf_simple_save(buf, &buf_state);
if (adv_rpt->adv_type != BLE_MESH_ADV_NONCONN_IND &&
adv_rpt->adv_type != BLE_MESH_ADV_IND
#if CONFIG_BLE_MESH_RPR_SRV && CONFIG_BLE_MESH_RPR_SRV_ACTIVE_SCAN
&& adv_rpt->adv_type != BLE_MESH_ADV_SCAN_RSP
#endif
) {
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
callback_ble_adv_pkt(&adv_rpt->addr, adv_rpt->adv_type, adv_data, adv_len, adv_rpt->rssi);
#endif
net_buf_simple_restore(buf, &buf_state);
return;
}
BT_DBG("scan, len %u: %s", buf->len, bt_hex(buf->data, buf->len));
#if (CONFIG_BLE_MESH_PROVISIONER || CONFIG_BLE_MESH_RPR_SRV)
unprov_dev_addr = addr;
current_adv_type = adv_type;
unprov_dev_addr = &adv_rpt->addr;
current_adv_type = adv_rpt->adv_type;
#endif
#if CONFIG_BLE_MESH_RPR_SRV && CONFIG_BLE_MESH_RPR_SRV_ACTIVE_SCAN
if (adv_rpt->adv_type == BLE_MESH_ADV_SCAN_RSP) {
/**
* scan response is only visible for remote provisioning extend scan.
*/
if (rpr_ext_scan_handle_adv_pkt(&adv_rpt->addr, adv_data, adv_len)) {
return;
} else {
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
callback_ble_adv_pkt(&adv_rpt->addr, adv_rpt->adv_type, adv_data, adv_len, adv_rpt->rssi);
#endif
net_buf_simple_restore(buf, &buf_state);
}
}
#endif /* CONFIG_BLE_MESH_RPR_SRV && CONFIG_BLE_MESH_RPR_SRV_ACTIVE_SCAN */
while (buf->len > 1) {
struct net_buf_simple_state state;
uint8_t len, type;
@@ -401,16 +455,18 @@ static void bt_mesh_scan_cb(const bt_mesh_addr_t *addr,
/* Check for early termination */
if (len == 0U) {
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
callback_ble_adv_pkt(addr, adv_type, adv_data, adv_len, rssi);
callback_ble_adv_pkt(&adv_rpt->addr, adv_rpt->adv_type, adv_data, adv_len, adv_rpt->rssi);
#endif
net_buf_simple_restore(buf, &buf_state);
return;
}
if (len > buf->len) {
BT_DBG("AD malformed");
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
callback_ble_adv_pkt(addr, adv_type, adv_data, adv_len, rssi);
callback_ble_adv_pkt(&adv_rpt->addr, adv_rpt->adv_type, adv_data, adv_len, adv_rpt->rssi);
#endif
net_buf_simple_restore(buf, &buf_state);
return;
}
@@ -421,14 +477,17 @@ static void bt_mesh_scan_cb(const bt_mesh_addr_t *addr,
buf->len = len - 1;
if ((type == BLE_MESH_DATA_MESH_PROV || type == BLE_MESH_DATA_MESH_MESSAGE ||
type == BLE_MESH_DATA_MESH_BEACON) && (adv_type != BLE_MESH_ADV_NONCONN_IND)) {
BT_DBG("Ignore mesh packet (type 0x%02x) with adv_type 0x%02x", type, adv_type);
type == BLE_MESH_DATA_MESH_BEACON) && (adv_rpt->adv_type != BLE_MESH_ADV_NONCONN_IND)) {
BT_DBG("Ignore mesh packet (type 0x%02x) with adv_type 0x%02x", type, adv_rpt->adv_type);
return;
}
switch (type) {
case BLE_MESH_DATA_MESH_MESSAGE:
bt_mesh_net_recv(buf, rssi, BLE_MESH_NET_IF_ADV);
struct bt_mesh_net_rx rx = {
.ctx.recv_rssi = adv_rpt->rssi,
};
bt_mesh_generic_net_recv(buf, &rx, BLE_MESH_NET_IF_ADV);
break;
#if CONFIG_BLE_MESH_PB_ADV
case BLE_MESH_DATA_MESH_PROV:
@@ -441,7 +500,7 @@ static void bt_mesh_scan_cb(const bt_mesh_addr_t *addr,
break;
#endif /* CONFIG_BLE_MESH_PB_ADV */
case BLE_MESH_DATA_MESH_BEACON:
bt_mesh_beacon_recv(buf, rssi);
bt_mesh_beacon_recv(buf, adv_rpt->rssi);
break;
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
CONFIG_BLE_MESH_GATT_PROXY_CLIENT || \
@@ -450,8 +509,9 @@ static void bt_mesh_scan_cb(const bt_mesh_addr_t *addr,
if (!adv_flags_valid(buf)) {
BT_DBG("Adv Flags mismatch, ignore this adv pkt");
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
callback_ble_adv_pkt(addr, adv_type, adv_data, adv_len, rssi);
callback_ble_adv_pkt(&adv_rpt->addr, adv_rpt->adv_type, adv_data, adv_len, adv_rpt->rssi);
#endif
net_buf_simple_restore(buf, &buf_state);
return;
}
break;
@@ -459,7 +519,7 @@ static void bt_mesh_scan_cb(const bt_mesh_addr_t *addr,
if (!adv_service_uuid_valid(buf, &uuid)) {
BT_DBG("Adv Service UUID mismatch, ignore this adv pkt");
#if CONFIG_BLE_MESH_RPR_SRV
if (rpr_ext_scan_handle_adv_pkt(addr, adv_data, adv_len)) {
if (rpr_ext_scan_handle_adv_pkt(&adv_rpt->addr, adv_data, adv_len)) {
/* If handled as extended scan report successfully, then not
* notify to the application layer as normal BLE adv packet.
*/
@@ -467,18 +527,19 @@ static void bt_mesh_scan_cb(const bt_mesh_addr_t *addr,
}
#endif
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
callback_ble_adv_pkt(addr, adv_type, adv_data, adv_len, rssi);
callback_ble_adv_pkt(&adv_rpt->addr, adv_rpt->adv_type, adv_data, adv_len, adv_rpt->rssi);
#endif
net_buf_simple_restore(buf, &buf_state);
return;
}
break;
case BLE_MESH_DATA_SVC_DATA16:
handle_adv_service_data(buf, addr, uuid, rssi);
handle_adv_service_data(buf, &adv_rpt->addr, uuid, adv_rpt->rssi);
break;
#endif
default:
#if CONFIG_BLE_MESH_RPR_SRV
if (rpr_ext_scan_handle_adv_pkt(addr, adv_data, adv_len)) {
if (rpr_ext_scan_handle_adv_pkt(&adv_rpt->addr, adv_data, adv_len)) {
/* If handled as extended scan report successfully, then not
* notify to the application layer as normal BLE adv packet.
*/
@@ -486,44 +547,21 @@ static void bt_mesh_scan_cb(const bt_mesh_addr_t *addr,
}
#endif
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
callback_ble_adv_pkt(addr, adv_type, adv_data, adv_len, rssi);
callback_ble_adv_pkt(&adv_rpt->addr, adv_rpt->adv_type, adv_data, adv_len, adv_rpt->rssi);
#endif
net_buf_simple_restore(buf, &buf_state);
return;
}
net_buf_simple_restore(buf, &state);
net_buf_simple_pull(buf, len);
}
#if CONFIG_BLE_MESH_RPR_SRV && CONFIG_BLE_MESH_RPR_SRV_ACTIVE_SCAN
if (scan_rsp_len != 0) {
/**
* scan response is only visible for remote provisioning extend scan.
*/
rpr_ext_scan_handle_adv_pkt(addr, adv_data + adv_len, scan_rsp_len);
}
#endif /* CONFIG_BLE_MESH_RPR_SRV && CONFIG_BLE_MESH_RPR_SRV_ACTIVE_SCAN */
}
int bt_mesh_scan_enable(void)
{
int err = 0;
struct bt_mesh_scan_param scan_param = {
#if CONFIG_BLE_MESH_RPR_SRV_ACTIVE_SCAN
.type = BLE_MESH_SCAN_ACTIVE,
#else
.type = BLE_MESH_SCAN_PASSIVE,
#endif
#if CONFIG_BLE_MESH_USE_DUPLICATE_SCAN
.filter_dup = BLE_MESH_SCAN_FILTER_DUP_ENABLE,
#else
.filter_dup = BLE_MESH_SCAN_FILTER_DUP_DISABLE,
#endif
.interval = SCAN_INTERVAL,
.window = SCAN_WINDOW,
.scan_fil_policy = BLE_MESH_SP_ADV_ALL,
};
err = bt_le_scan_start(&scan_param, bt_mesh_scan_cb);
if (err && err != -EALREADY) {
BT_ERR("starting scan failed (err %d)", err);
@@ -546,6 +584,49 @@ int bt_mesh_scan_disable(void)
return 0;
}
int bt_mesh_scan_param_update(struct bt_mesh_scan_param *param)
{
int err = 0;
if (param == NULL ||
param->interval == 0 ||
param->interval < param->window) {
return -EINVAL;
}
scan_param.interval = param->interval;
scan_param.window = param->window;
err = bt_le_scan_stop();
if (err) {
if (err == -EALREADY) {
BT_INFO("New scan parameters will take effect after scan starts");
return 0;
}
BT_ERR("Failed to stop scan (err %d)", err);
return err;
}
/**
* Since the user only needs to set the scan interval
* and scan window parameters, only the interval and
* window parameters in the `param` are correct.
*
* For the aforementioned reason, when updating the scan
* parameters, the other parameters also need to be set
* correctly, and these other parameters are saved in the
* `scan_param`. Therefore, `scan_param` must be used instead
* of `param` here.
*/
err = bt_le_scan_start(&scan_param, bt_mesh_scan_cb);
if (err && err != -EALREADY) {
BT_ERR("Failed to start scan (err %d)", err);
return err;
}
return 0;
}
#if CONFIG_BLE_MESH_TEST_USE_WHITE_LIST
int bt_mesh_scan_with_wl_enable(void)
{

View File

@@ -2,7 +2,7 @@
/*
* SPDX-FileCopyrightText: 2017 Intel Corporation
* SPDX-FileContributor: 2020-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileContributor: 2020-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -33,16 +33,22 @@ int bt_mesh_scan_enable(void);
int bt_mesh_scan_disable(void);
int bt_mesh_scan_param_update(struct bt_mesh_scan_param *scan_param);
int bt_mesh_scan_with_wl_enable(void);
struct bt_mesh_ble_scan_param {
uint32_t duration;
};
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
int bt_mesh_start_ble_scan(struct bt_mesh_ble_scan_param *param);
int bt_mesh_stop_ble_scan(void);
bool bt_mesh_ble_scan_state_get(void);
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_SCAN */
#ifdef __cplusplus
}
#endif

View File

@@ -1483,6 +1483,8 @@ int settings_core_commit(void)
struct bt_mesh_hb_pub *hb_pub = NULL;
struct bt_mesh_cfg_srv *cfg = NULL;
bt_mesh_atomic_set_bit(bt_mesh.flags, BLE_MESH_VALID);
hb_pub = bt_mesh_hb_pub_get();
if (hb_pub && hb_pub->dst != BLE_MESH_ADDR_UNASSIGNED &&
hb_pub->count && hb_pub->period) {
@@ -1501,7 +1503,6 @@ int settings_core_commit(void)
cfg->default_ttl = stored_cfg.cfg.default_ttl;
}
bt_mesh_atomic_set_bit(bt_mesh.flags, BLE_MESH_VALID);
bt_mesh_net_start();
}
#endif /* CONFIG_BLE_MESH_NODE */

View File

@@ -1217,19 +1217,23 @@ config BT_BLE_RPA_TIMEOUT
Default is 900 s (15 minutes). Range is 1 s to 1 hour (3600 s).
config BT_BLE_50_FEATURES_SUPPORTED
bool "Enable BLE 5.0 features"
bool "Enable BLE 5.0 features(please disable BLE 4.2 if enable BLE 5.0)"
depends on (BT_BLE_ENABLED && ((BT_CONTROLLER_ENABLED && SOC_BLE_50_SUPPORTED) || BT_CONTROLLER_DISABLED))
default y
help
Enabling this option activates BLE 5.0 features.
This option is universally supported in chips that support BLE, except for ESP32.
BLE 4.2 and BLE 5.0 cannot be used simultaneously.
config BT_BLE_42_FEATURES_SUPPORTED
bool "Enable BLE 4.2 features"
bool "Enable BLE 4.2 features(please disable BLE 5.0 if enable BLE 4.2)"
depends on (BT_BLE_ENABLED && ((BT_CONTROLLER_ENABLED && SOC_BLE_SUPPORTED) || BT_CONTROLLER_DISABLED))
default n
help
This enables BLE 4.2 features.
This option is universally supported by all ESP chips with BLE capabilities.
BLE 4.2 and BLE 5.0 cannot be used simultaneously.
config BT_BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER
bool "Enable BLE periodic advertising sync transfer feature"

View File

@@ -67,8 +67,8 @@ esp_err_t esp_ble_gattc_app_unregister(esp_gatt_if_t gattc_if)
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
#if (BLE_42_FEATURE_SUPPORT == TRUE)
esp_err_t esp_ble_gattc_open(esp_gatt_if_t gattc_if, esp_bd_addr_t remote_bda, esp_ble_addr_type_t remote_addr_type, bool is_direct)
esp_err_t esp_ble_gattc_enh_open(esp_gatt_if_t gattc_if, esp_ble_gatt_creat_conn_params_t esp_gatt_create_conn)
{
btc_msg_t msg = {0};
btc_ble_gattc_args_t arg;
@@ -79,34 +79,38 @@ esp_err_t esp_ble_gattc_open(esp_gatt_if_t gattc_if, esp_bd_addr_t remote_bda, e
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_OPEN;
arg.open.gattc_if = gattc_if;
memcpy(arg.open.remote_bda, remote_bda, ESP_BD_ADDR_LEN);
arg.open.remote_addr_type = remote_addr_type;
arg.open.is_direct = is_direct;
arg.open.is_aux = false;
memcpy(arg.open.remote_bda, esp_gatt_create_conn.remote_bda, ESP_BD_ADDR_LEN);
arg.open.remote_addr_type = esp_gatt_create_conn.remote_addr_type;
arg.open.is_direct = esp_gatt_create_conn.is_direct;
arg.open.is_aux= esp_gatt_create_conn.is_aux;
arg.open.own_addr_type = esp_gatt_create_conn.own_addr_type;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
#if (BLE_42_FEATURE_SUPPORT == TRUE)
esp_err_t esp_ble_gattc_open(esp_gatt_if_t gattc_if, esp_bd_addr_t remote_bda, esp_ble_addr_type_t remote_addr_type, bool is_direct)
{
esp_ble_gatt_creat_conn_params_t esp_gatt_create_conn;
memcpy(esp_gatt_create_conn.remote_bda, remote_bda, ESP_BD_ADDR_LEN);
esp_gatt_create_conn.remote_addr_type = remote_addr_type;
esp_gatt_create_conn.is_direct = is_direct;
esp_gatt_create_conn.is_aux = false;
esp_gatt_create_conn.own_addr_type = 0xff; //undefined, will use local value
return esp_ble_gattc_enh_open(gattc_if, esp_gatt_create_conn);
}
#endif // #if (BLE_42_FEATURE_SUPPORT == TRUE)
#if (BLE_50_FEATURE_SUPPORT == TRUE)
esp_err_t esp_ble_gattc_aux_open(esp_gatt_if_t gattc_if, esp_bd_addr_t remote_bda, esp_ble_addr_type_t remote_addr_type, bool is_direct)
{
btc_msg_t msg;
btc_ble_gattc_args_t arg;
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_AUX_OPEN;
arg.open.gattc_if = gattc_if;
memcpy(arg.open.remote_bda, remote_bda, ESP_BD_ADDR_LEN);
arg.open.remote_addr_type = remote_addr_type;
arg.open.is_direct = is_direct;
arg.open.is_aux = true;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
esp_ble_gatt_creat_conn_params_t esp_gatt_create_conn;
memcpy(esp_gatt_create_conn.remote_bda, remote_bda, ESP_BD_ADDR_LEN);
esp_gatt_create_conn.remote_addr_type = remote_addr_type;
esp_gatt_create_conn.is_direct = is_direct;
esp_gatt_create_conn.is_aux = true;
esp_gatt_create_conn.own_addr_type = 0xff; //undefined, will use local value
return esp_ble_gattc_enh_open(gattc_if, esp_gatt_create_conn);
}
#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)

View File

@@ -682,6 +682,15 @@ typedef struct {
esp_bt_uuid_t uuid; /*!< Included service UUID. */
} esp_gattc_incl_svc_elem_t;
/** @brief Represents a creat connection element. */
typedef struct {
esp_bd_addr_t remote_bda; /*!< The Bluetooth address of the remote device */
esp_ble_addr_type_t remote_addr_type; /*!< Address type of the remote device */
bool is_direct; /*!< Direct connection or background auto connection(by now, background auto connection is not supported */
bool is_aux; /*!< Set to true for BLE 5.0 or higher to enable auxiliary connections; set to false for BLE 4.2 or lower. */
esp_ble_addr_type_t own_addr_type; /*!< Specifies the address type used in the connection request. Set to 0xFF if the address type is unknown. */
} esp_ble_gatt_creat_conn_params_t;
#ifdef __cplusplus
}
#endif

View File

@@ -314,7 +314,20 @@ esp_err_t esp_ble_gattc_app_register(uint16_t app_id);
*/
esp_err_t esp_ble_gattc_app_unregister(esp_gatt_if_t gattc_if);
#if (BLE_42_FEATURE_SUPPORT == TRUE)
/**
* @brief Open a direct connection or add a background auto connection.
* Note: Do not enable both BLE_42_FEATURE_SUPPORT and BLE_50_FEATURE_SUPPORT configuration options simultaneously.
*
* @param[in] gattc_if: GATT client access interface.
* @param[in] esp_gatt_create_conn: Structure containing connection parameters.
*
* @return
* - ESP_OK: Operation successful
* - others: Operation failed
*
*/
esp_err_t esp_ble_gattc_enh_open(esp_gatt_if_t gattc_if, esp_ble_gatt_creat_conn_params_t esp_gatt_create_conn);
/**
* @brief Open a direct connection or add a background auto connection
*
@@ -328,12 +341,14 @@ esp_err_t esp_ble_gattc_app_unregister(esp_gatt_if_t gattc_if);
* - other: failed
*
*/
#if (BLE_42_FEATURE_SUPPORT == TRUE)
esp_err_t esp_ble_gattc_open(esp_gatt_if_t gattc_if, esp_bd_addr_t remote_bda, esp_ble_addr_type_t remote_addr_type, bool is_direct);
#endif // #if (BLE_42_FEATURE_SUPPORT == TRUE)
#if (BLE_50_FEATURE_SUPPORT == TRUE)
esp_err_t esp_ble_gattc_aux_open(esp_gatt_if_t gattc_if, esp_bd_addr_t remote_bda, esp_ble_addr_type_t remote_addr_type, bool is_direct);
#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
/**
* @brief Close the virtual connection to the GATT server. gattc may have multiple virtual GATT server connections when multiple app_id registered,
* this API only close one virtual GATT server connection. if there exist other virtual GATT server connections,

View File

@@ -6673,7 +6673,8 @@ void btm_dm_start_gatt_discovery (BD_ADDR bd_addr)
btm_dm_start_disc_gatt_services(bta_dm_search_cb.conn_id);
} else {
//TODO need to add addr_type in future
BTA_GATTC_Open(bta_dm_search_cb.client_if, bd_addr, BLE_ADDR_UNKNOWN_TYPE, TRUE, BTA_GATT_TRANSPORT_LE, FALSE);
BTA_GATTC_Enh_Open(bta_dm_search_cb.client_if, bd_addr, BLE_ADDR_UNKNOWN_TYPE, TRUE, BTA_GATT_TRANSPORT_LE, FALSE, BLE_ADDR_UNKNOWN_TYPE);
}
}
#endif /* #if (GATTC_INCLUDED == TRUE) */

View File

@@ -70,6 +70,7 @@ static void bta_gattc_req_cback (UINT16 conn_id, UINT32 trans_id, tGATTS_REQ_TYP
static tBTA_GATTC_FIND_SERVICE_CB bta_gattc_register_service_change_notify(UINT16 conn_id, BD_ADDR remote_bda);
extern void btc_gattc_congest_callback(tBTA_GATTC *param);
extern uint32_t BTM_BleUpdateOwnType(uint8_t *own_bda_type, tBTM_START_ADV_CMPL_CBACK *cb);
static const tGATT_CBACK bta_gattc_cl_cback = {
bta_gattc_conn_cback,
@@ -336,6 +337,10 @@ void bta_gattc_process_api_open (tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg)
UNUSED(p_cb);
if (p_clreg != NULL) {
if (p_msg->api_conn.own_addr_type <= BLE_ADDR_TYPE_MAX) {
// update own address type for creating connection
BTM_BleUpdateOwnType(&p_msg->api_conn.own_addr_type, NULL);
}
if (p_msg->api_conn.is_direct) {
if ((p_clcb = bta_gattc_find_alloc_clcb(p_msg->api_conn.client_if,
p_msg->api_conn.remote_bda,

View File

@@ -128,7 +128,7 @@ void BTA_GATTC_AppDeregister(tBTA_GATTC_IF client_if)
/*******************************************************************************
**
** Function BTA_GATTC_Open
** Function BTA_GATTC_Enh_Open
**
** Description Open a direct connection or add a background auto connection
** bd address
@@ -142,8 +142,8 @@ void BTA_GATTC_AppDeregister(tBTA_GATTC_IF client_if)
** Returns void
**
*******************************************************************************/
void BTA_GATTC_Open(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, tBTA_ADDR_TYPE remote_addr_type,
BOOLEAN is_direct, tBTA_GATT_TRANSPORT transport, BOOLEAN is_aux)
void BTA_GATTC_Enh_Open(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, tBTA_ADDR_TYPE remote_addr_type,
BOOLEAN is_direct, tBTA_GATT_TRANSPORT transport, BOOLEAN is_aux, tBTA_ADDR_TYPE own_addr_type)
{
tBTA_GATTC_API_OPEN *p_buf;
@@ -155,6 +155,7 @@ void BTA_GATTC_Open(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, tBTA_ADDR_TYPE
p_buf->transport = transport;
p_buf->is_aux = is_aux;
p_buf->remote_addr_type = remote_addr_type;
p_buf->own_addr_type = own_addr_type;
memcpy(p_buf->remote_bda, remote_bda, BD_ADDR_LEN);
@@ -472,7 +473,7 @@ void BTA_GATTC_GetGattDb(UINT16 conn_id, UINT16 start_handle, UINT16 end_handle
** Description This function is called to read a characteristics value
**
** Parameters conn_id - connection ID.
** handle - characteritic handle to read.
** handle - characteristic handle to read.
**
** Returns None
**
@@ -607,7 +608,7 @@ void BTA_GATTC_ReadMultipleVariable(UINT16 conn_id, tBTA_GATTC_MULTI *p_read_mul
**
** Parameters conn_id - connection ID.
** s_handle - start handle.
** e_handle - end hanle
** e_handle - end handle
** uuid - The attribute UUID.
**
** Returns None
@@ -687,7 +688,7 @@ void BTA_GATTC_WriteCharValue ( UINT16 conn_id,
** Description This function is called to write descriptor value.
**
** Parameters conn_id - connection ID
** handle - descriptor hadle to write.
** handle - descriptor handle to write.
** write_type - write type.
** p_value - the value to be written.
**
@@ -738,7 +739,7 @@ void BTA_GATTC_WriteCharDescr (UINT16 conn_id,
** Description This function is called to prepare write a characteristic value.
**
** Parameters conn_id - connection ID.
** p_char_id - GATT characteritic ID of the service.
** p_char_id - GATT characteristic ID of the service.
** offset - offset of the write value.
** len: length of the data to be written.
** p_value - the value to be written.
@@ -781,7 +782,7 @@ void BTA_GATTC_PrepareWrite (UINT16 conn_id, UINT16 handle,
** Description This function is called to prepare write a characteristic descriptor value.
**
** Parameters conn_id - connection ID.
** p_char_descr_id - GATT characteritic descriptor ID of the service.
** p_char_descr_id - GATT characteristic descriptor ID of the service.
** offset - offset of the write value.
** len: length of the data to be written.
** p_value - the value to be written.

View File

@@ -110,7 +110,7 @@ typedef enum {
#define BTA_GATTC_WRITE_PREPARE GATT_WRITE_PREPARE
#define BTA_GATTC_INVALID_HANDLE 0
/* internal strucutre for GATTC register API */
/* internal structure for GATTC register API */
typedef struct {
BT_HDR hdr;
tBT_UUID app_uuid;
@@ -133,6 +133,7 @@ typedef struct {
BOOLEAN is_direct;
BOOLEAN is_aux;
tBTA_TRANSPORT transport;
tBTA_ADDR_TYPE own_addr_type;
} tBTA_GATTC_API_OPEN;
typedef tBTA_GATTC_API_OPEN tBTA_GATTC_API_CANCEL_OPEN;
@@ -313,7 +314,7 @@ typedef struct {
UINT16 total_char;
UINT16 total_attr;
UINT8 srvc_hdl_chg; /* service handle change indication pending */
UINT16 attr_index; /* cahce NV saving/loading attribute index */
UINT16 attr_index; /* cache NV saving/loading attribute index */
UINT16 mtu;
bool update_incl_srvc;

View File

@@ -117,7 +117,7 @@ static void bta_hh_le_hid_report_dbg(tBTA_HH_DEV_CB *p_cb)
if (p_cb->hid_srvc[i].in_use) {
p_rpt = &p_cb->hid_srvc[i].report[0];
APPL_TRACE_DEBUG("\t HID serivce inst: %d", i);
APPL_TRACE_DEBUG("\t HID service inst: %d", i);
for (j = 0; j < BTA_HH_LE_RPT_MAX; j ++, p_rpt++) {
rpt_name = "Unknown";
@@ -334,14 +334,14 @@ void bta_hh_le_open_conn(tBTA_HH_DEV_CB *p_cb, BD_ADDR remote_bda)
bta_hh_cb.le_cb_index[BTA_HH_GET_LE_CB_IDX(p_cb->hid_handle)] = p_cb->index;
p_cb->in_use = TRUE;
BTA_GATTC_Open(bta_hh_cb.gatt_if, remote_bda, BLE_ADDR_UNKNOWN_TYPE, TRUE, BTA_GATT_TRANSPORT_LE, FALSE);
BTA_GATTC_Enh_Open(bta_hh_cb.gatt_if, remote_bda, BLE_ADDR_UNKNOWN_TYPE, TRUE, BTA_GATT_TRANSPORT_LE, FALSE, BLE_ADDR_UNKNOWN_TYPE);
}
/*******************************************************************************
**
** Function bta_hh_le_fill_16bits_gatt_id
**
** Description Utility function to fill a GATT ID strucure
** Description Utility function to fill a GATT ID structure
**
*******************************************************************************/
void bta_hh_le_fill_16bits_gatt_id(UINT8 inst_id, UINT16 uuid, tBTA_GATT_ID *p_output)
@@ -355,7 +355,7 @@ void bta_hh_le_fill_16bits_gatt_id(UINT8 inst_id, UINT16 uuid, tBTA_GATT_ID *p_
**
** Function bta_hh_le_fill_16bits_srvc_id
**
** Description Utility function to fill a service ID strucure with a 16 bits
** Description Utility function to fill a service ID structure with a 16 bits
** service UUID.
**
*******************************************************************************/
@@ -372,7 +372,7 @@ void bta_hh_le_fill_16bits_srvc_id(BOOLEAN is_pri, UINT8 inst_id, UINT16 srvc_uu
**
** Function bta_hh_le_fill_16bits_char_id
**
** Description Utility function to fill a char ID strucure with a 16 bits
** Description Utility function to fill a char ID structure with a 16 bits
** char UUID.
**
*******************************************************************************/
@@ -624,7 +624,7 @@ tBTA_HH_STATUS bta_hh_le_read_char_dscrpt(tBTA_HH_DEV_CB *p_cb, UINT16 srvc_uuid
**
** Function bta_hh_le_read_rpt_ref_descr
**
** Description read report refernece descriptors in service discovery process
** Description read report reference descriptors in service discovery process
**
*******************************************************************************/
void bta_hh_le_read_rpt_ref_descr(tBTA_HH_DEV_CB *p_dev_cb, tBTA_HH_LE_RPT *p_rpt)
@@ -841,7 +841,7 @@ void bta_hh_le_register_input_notif(tBTA_HH_DEV_CB *p_dev_cb, UINT8 srvc_inst,
}
}
/*
else unknow protocol mode */
else unknown protocol mode */
}
}
}
@@ -1486,7 +1486,7 @@ void bta_hh_le_gatt_disc_cmpl(tBTA_HH_DEV_CB *p_cb, tBTA_HH_STATUS status)
{
APPL_TRACE_DEBUG("bta_hh_le_gatt_disc_cmpl ");
/* if open sucessful or protocol mode not desired, keep the connection open but inform app */
/* if open successful or protocol mode not desired, keep the connection open but inform app */
if (status == BTA_HH_OK || status == BTA_HH_ERR_PROTO) {
/* assign a special APP ID temp, since device type unknown */
p_cb->app_id = BTA_HH_APP_ID_LE;
@@ -1504,7 +1504,7 @@ void bta_hh_le_gatt_disc_cmpl(tBTA_HH_DEV_CB *p_cb, tBTA_HH_STATUS status)
**
** Function bta_hh_le_srvc_expl_srvc
**
** Description This function discover the next avaible HID service.
** Description This function discover the next available HID service.
**
** Parameters:
**
@@ -2076,7 +2076,7 @@ void bta_hh_w4_le_read_descr_cmpl(tBTA_HH_DEV_CB *p_dev_cb, tBTA_HH_DATA *p_buf)
**
** Function bta_hh_w4_le_write_cmpl
**
** Description Write charactersitic complete event at W4_CONN st.
** Description Write characteristic complete event at W4_CONN st.
**
** Parameters:
**
@@ -2104,7 +2104,7 @@ void bta_hh_w4_le_write_cmpl(tBTA_HH_DEV_CB *p_dev_cb, tBTA_HH_DATA *p_buf)
**
** Function bta_hh_le_write_cmpl
**
** Description Write charactersitic complete event at CONN st.
** Description Write characteristic complete event at CONN st.
**
** Parameters:
**
@@ -2162,7 +2162,7 @@ void bta_hh_le_write_cmpl(tBTA_HH_DEV_CB *p_dev_cb, tBTA_HH_DATA *p_buf)
**
** Function bta_hh_le_write_char_descr_cmpl
**
** Description Write charactersitic descriptor complete event
** Description Write characteristic descriptor complete event
**
** Parameters:
**
@@ -2216,7 +2216,7 @@ void bta_hh_le_write_char_descr_cmpl(tBTA_HH_DEV_CB *p_dev_cb, tBTA_HH_DATA *p_b
**
** Function bta_hh_le_input_rpt_notify
**
** Description process the notificaton event, most likely for input report.
** Description process the notification event, most likely for input report.
**
** Parameters:
**
@@ -2357,7 +2357,7 @@ void bta_hh_gatt_close(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
**
** Function bta_hh_le_api_disc_act
**
** Description initaite a Close API to a remote HID device
** Description initiate a Close API to a remote HID device
**
** Returns void
**
@@ -2601,7 +2601,7 @@ static void bta_hh_le_add_dev_bg_conn(tBTA_HH_DEV_CB *p_cb, BOOLEAN check_bond)
if (/*p_cb->dscp_info.flag & BTA_HH_LE_NORMAL_CONN &&*/
!p_cb->in_bg_conn && to_add) {
/* add device into BG connection to accept remote initiated connection */
BTA_GATTC_Open(bta_hh_cb.gatt_if, p_cb->addr, BLE_ADDR_UNKNOWN_TYPE, FALSE, BTA_GATT_TRANSPORT_LE, FALSE);
BTA_GATTC_Enh_Open(bta_hh_cb.gatt_if, p_cb->addr, BLE_ADDR_UNKNOWN_TYPE, FALSE, BTA_GATT_TRANSPORT_LE, FALSE, BLE_ADDR_UNKNOWN_TYPE);
p_cb->in_bg_conn = TRUE;
BTA_DmBleSetBgConnType(BTA_DM_BLE_CONN_AUTO, NULL);
@@ -2682,7 +2682,7 @@ void bta_hh_le_update_scpp(tBTA_HH_DEV_CB *p_dev_cb, tBTA_HH_DATA *p_buf)
if (!p_dev_cb->is_le_device ||
p_dev_cb->mode != BTA_HH_PROTO_RPT_MODE ||
p_dev_cb->scps_supported == FALSE) {
APPL_TRACE_ERROR("Can not set ScPP scan paramter as boot host, or remote does not support ScPP ");
APPL_TRACE_ERROR("Can not set ScPP scan parameter as boot host, or remote does not support ScPP ");
cback_data.handle = p_dev_cb->hid_handle;
cback_data.status = BTA_HH_ERR;
@@ -2908,7 +2908,7 @@ static void bta_hh_le_search_scps_chars(tBTA_HH_DEV_CB *p_cb)
**
** Function bta_hh_le_register_scpp_notif
**
** Description register scan parameter refresh notitication complete
** Description register scan parameter refresh notification complete
**
**
** Parameters:
@@ -2919,7 +2919,7 @@ static void bta_hh_le_register_scpp_notif(tBTA_HH_DEV_CB *p_dev_cb, tBTA_GATT_ST
UINT8 sec_flag = 0;
tBTA_GATTC_CHAR_ID char_id;
/* if write scan parameter sucessful */
/* if write scan parameter successful */
/* if bonded and notification is not enabled, configure the client configuration */
if (status == BTA_GATT_OK &&
(p_dev_cb->scps_notify & BTA_HH_LE_SCPS_NOTIFY_SPT) != 0 &&
@@ -2949,7 +2949,7 @@ static void bta_hh_le_register_scpp_notif(tBTA_HH_DEV_CB *p_dev_cb, tBTA_GATT_ST
**
** Function bta_hh_le_register_scpp_notif_cmpl
**
** Description action function to register scan parameter refresh notitication
** Description action function to register scan parameter refresh notification
**
** Parameters:
**

View File

@@ -1512,18 +1512,18 @@ typedef UINT8 tBTA_DM_LINK_TYPE;
#define BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_INCLUDE_TX_PWR (1 << 6)
#define BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_MASK (0x7F)
#define BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_LEGACY_IND (ESP_BLE_GAP_SET_EXT_ADV_PROP_LEGACY |\
ESP_BLE_GAP_SET_EXT_ADV_PROP_CONNECTABLE |\
ESP_BLE_GAP_SET_EXT_ADV_PROP_SCANNABLE)
#define BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_LEGACY_LD_DIR (ESP_BLE_GAP_SET_EXT_ADV_PROP_LEGACY |\
ESP_BLE_GAP_SET_EXT_ADV_PROP_CONNECTABLE |\
ESP_BLE_GAP_SET_EXT_ADV_PROP_DIRECTED)
#define BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_LEGACY_HD_DIR (ESP_BLE_GAP_SET_EXT_ADV_PROP_LEGACY |\
ESP_BLE_GAP_SET_EXT_ADV_PROP_CONNECTABLE |\
ESP_BLE_GAP_SET_EXT_ADV_PROP_HD_DIRECTED)
#define BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_LEGACY_SCAN (ESP_BLE_GAP_SET_EXT_ADV_PROP_LEGACY |\
ESP_BLE_GAP_SET_EXT_ADV_PROP_SCANNABLE)
#define BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_LEGACY_NONCONN (ESP_BLE_GAP_SET_EXT_ADV_PROP_LEGACY)
#define BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_LEGACY_IND (BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_LEGACY |\
BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_CONNECTABLE |\
BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_SCANNABLE)
#define BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_LEGACY_LD_DIR (BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_LEGACY |\
BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_CONNECTABLE |\
BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_DIRECTED)
#define BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_LEGACY_HD_DIR (BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_LEGACY |\
BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_CONNECTABLE |\
BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_HD_DIRECTED)
#define BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_LEGACY_SCAN (BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_LEGACY |\
BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_SCANNABLE)
#define BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_LEGACY_NONCONN (BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_LEGACY)
typedef UINT16 tBTA_DM_BLE_EXT_ADV_TYPE_MASK;

View File

@@ -180,7 +180,7 @@ typedef UINT8 tBTA_GATT_STATUS;
#define BTA_GATTC_ADV_VSC_EVT 34 /* ADV VSC event */
#define BTA_GATTC_CONNECT_EVT 35 /* GATTC CONNECT event */
#define BTA_GATTC_DISCONNECT_EVT 36 /* GATTC DISCONNECT event */
#define BTA_GATTC_READ_MULTIPLE_EVT 37 /* GATTC Read mutiple event */
#define BTA_GATTC_READ_MULTIPLE_EVT 37 /* GATTC Read multiple event */
#define BTA_GATTC_QUEUE_FULL_EVT 38 /* GATTC queue full event */
#define BTA_GATTC_ASSOC_EVT 39 /* GATTC association address event */
#define BTA_GATTC_GET_ADDR_LIST_EVT 40 /* GATTC get address list in the cache event */
@@ -783,9 +783,10 @@ extern void BTA_GATTC_AppRegister(tBT_UUID *p_app_uuid, tBTA_GATTC_CBACK *p_clie
*******************************************************************************/
extern void BTA_GATTC_AppDeregister (tBTA_GATTC_IF client_if);
/*******************************************************************************
**
** Function BTA_GATTC_Open
** Function BTA_GATTC_Enh_Open
**
** Description Open a direct connection or add a background auto connection
** bd address
@@ -793,13 +794,14 @@ extern void BTA_GATTC_AppDeregister (tBTA_GATTC_IF client_if);
** Parameters client_if: server interface.
** remote_bda: remote device BD address.
** remote_addr_type: remote device BD address type.
** is_direct: direct connection or background auto connection
** is_direct: direct connection or background auto connection.
** own_addr_type: own address type.
**
** Returns void
**
*******************************************************************************/
extern void BTA_GATTC_Open(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, tBTA_ADDR_TYPE remote_addr_type,
BOOLEAN is_direct, tBTA_GATT_TRANSPORT transport, BOOLEAN is_aux);
extern void BTA_GATTC_Enh_Open(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, tBTA_ADDR_TYPE remote_addr_type,
BOOLEAN is_direct, tBTA_GATT_TRANSPORT transport, BOOLEAN is_aux, tBTA_ADDR_TYPE own_addr_type);
/*******************************************************************************
**
@@ -937,8 +939,8 @@ extern void BTA_GATTC_GetGattDb(UINT16 conn_id, UINT16 start_handle, UINT16 end_
**
** Description This function is called to read a characteristics value
**
** Parameters conn_id - connectino ID.
** handle - characteritic handle to read.
** Parameters conn_id - connection ID.
** handle - characteristic handle to read.
**
** Returns None
**
@@ -953,7 +955,7 @@ void BTA_GATTC_ReadCharacteristic(UINT16 conn_id, UINT16 handle, tBTA_GATT_AUTH_
**
** Parameters conn_id - connection ID.
** s_handle - start handle.
** e_handle - end hanle
** e_handle - end handle
** uuid - The attribute UUID.
**
** Returns None
@@ -1072,7 +1074,7 @@ extern tBTA_GATT_STATUS BTA_GATTC_DeregisterForNotifications (tBTA_GATTC_IF
** Description This function is called to prepare write a characteristic value.
**
** Parameters conn_id - connection ID.
** handle - GATT characteritic handle.
** handle - GATT characteristic handle.
** offset - offset of the write value.
** len - length of the data to be written.
** p_value - the value to be written.
@@ -1094,7 +1096,7 @@ extern void BTA_GATTC_PrepareWrite (UINT16 conn_id,
** Description This function is called to prepare write a characteristic descriptor value.
**
** Parameters conn_id - connection ID.
** p_char_descr_id - GATT characteritic descriptor ID of the service.
** p_char_descr_id - GATT characteristic descriptor ID of the service.
** offset - offset of the write value.
** len: length of the data to be written.
** p_value - the value to be written.
@@ -1238,7 +1240,7 @@ extern void BTA_GATTC_ConfigureMTU (UINT16 conn_id);
**
** Function BTA_GATTS_Init
**
** Description This function is called to initalize GATTS module
** Description This function is called to initialize GATTS module
**
** Parameters None
**

View File

@@ -175,8 +175,7 @@ bool btc_avrc_ct_init_p(void)
bool btc_avrc_tg_connected_p(void)
{
return (s_rc_tg_init == BTC_RC_TG_INIT_MAGIC) &&
(btc_rc_cb.rc_connected == TRUE) &&
(btc_rc_cb.rc_features & BTA_AV_FEAT_RCCT);
(btc_rc_cb.rc_connected == TRUE);
}
bool btc_avrc_ct_connected_p(void)
@@ -507,7 +506,7 @@ static void handle_rc_connect (tBTA_AV_RC_OPEN *p_rc_open)
btc_avrc_ct_cb_to_app(ESP_AVRC_CT_CONNECTION_STATE_EVT, &param);
}
if (p_rc_open->peer_features & BTA_AV_FEAT_RCCT) {
if (btc_avrc_tg_init_p()) {
esp_avrc_tg_cb_param_t param;
memset(&param, 0, sizeof(esp_avrc_tg_cb_param_t));
param.conn_stat.connected = true;
@@ -580,7 +579,7 @@ static void handle_rc_disconnect (tBTA_AV_RC_CLOSE *p_rc_close)
btc_avrc_ct_cb_to_app(ESP_AVRC_CT_CONNECTION_STATE_EVT, &param);
}
if (rc_features & BTA_AV_FEAT_RCCT) {
if (btc_avrc_tg_init_p()) {
esp_avrc_tg_cb_param_t param;
memset(&param, 0, sizeof(esp_avrc_ct_cb_param_t));
param.conn_stat.connected = false;
@@ -1006,14 +1005,10 @@ void btc_rc_handler(tBTA_AV_EVT event, tBTA_AV *p_data)
memcpy(param.conn_stat.remote_bda, btc_rc_cb.rc_addr, sizeof(esp_bd_addr_t));
btc_avrc_ct_cb_to_app(ESP_AVRC_CT_CONNECTION_STATE_EVT, &param);
}
if ((p_data->rc_feat.peer_features & BTA_AV_FEAT_RCCT) &&
!(old_feats & BTA_AV_FEAT_RCCT)) {
esp_avrc_tg_cb_param_t param;
memset(&param, 0, sizeof(esp_avrc_ct_cb_param_t));
param.conn_stat.connected = true;
memcpy(param.conn_stat.remote_bda, btc_rc_cb.rc_addr, sizeof(esp_bd_addr_t));
btc_avrc_tg_cb_to_app(ESP_AVRC_TG_CONNECTION_STATE_EVT, &param);
}
/**
* @note ESP_AVRC_TG_CONNECTION_STATE_EVT has been reported on rc connect/disconnect event,
* it doesn't rely on the SDP results.
*/
} while (0);
btc_rc_cb.rc_features = p_data->rc_feat.peer_features;
btc_rc_cb.rc_ct_features = p_data->rc_feat.peer_ct_features;

View File

@@ -958,7 +958,7 @@ static void btc_read_ble_rssi_cmpl_callback(void *p_data)
}
#if (BLE_50_FEATURE_SUPPORT == TRUE)
static void btc_ble_5_gap_callback(tBTA_DM_BLE_5_GAP_EVENT event,
void btc_ble_5_gap_callback(tBTA_DM_BLE_5_GAP_EVENT event,
tBTA_DM_BLE_5_GAP_CB_PARAMS *params)
{
esp_ble_gap_cb_param_t param;

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
@@ -212,9 +212,10 @@ static void btc_gattc_app_unregister(btc_ble_gattc_args_t *arg)
static void btc_gattc_open(btc_ble_gattc_args_t *arg)
{
tBTA_GATT_TRANSPORT transport = BTA_GATT_TRANSPORT_LE;
BTA_GATTC_Open(arg->open.gattc_if, arg->open.remote_bda,
BTA_GATTC_Enh_Open(arg->open.gattc_if, arg->open.remote_bda,
arg->open.remote_addr_type, arg->open.is_direct,
transport, arg->open.is_aux);
transport, arg->open.is_aux, arg->open.own_addr_type);
}
static void btc_gattc_close(btc_ble_gattc_args_t *arg)

View File

@@ -11,11 +11,13 @@
#include "esp_gap_ble_api.h"
#if BTC_DYNAMIC_MEMORY == TRUE
#if (BLE_42_FEATURE_SUPPORT == TRUE)
#include "bta/bta_api.h"
extern tBTA_BLE_ADV_DATA *gl_bta_adv_data_ptr;
extern tBTA_BLE_ADV_DATA *gl_bta_scan_rsp_data_ptr;
#define gl_bta_adv_data (*gl_bta_adv_data_ptr)
#define gl_bta_scan_rsp_data (*gl_bta_scan_rsp_data_ptr)
#endif // BLE_42_FEATURE_SUPPORT
#endif
#define BLE_ISVALID_PARAM(x, min, max) (((x) >= (min) && (x) <= (max)))

View File

@@ -57,6 +57,7 @@ typedef union {
esp_ble_addr_type_t remote_addr_type;
bool is_direct;
bool is_aux;
esp_ble_addr_type_t own_addr_type;
} open;
//BTC_GATTC_ACT_CLOSE,
struct close_arg {

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