Compare commits

...

131 Commits

Author SHA1 Message Date
c70a613127 Merge branch 'bugfix/tw20575_fix_potential_phy_calibration_bug_v2.1' into 'release/v2.1'
esp32: fix potential PHY calibration bug

See merge request idf/esp-idf!2357
2018-05-09 21:22:45 +08:00
c5498468d8 Merge branch 'bugfix/tw17012_wifi_interface_stop' into 'release/v2.1'
Bugfix/tw17012 wifi interface stop

See merge request idf/esp-idf!2363
2018-05-09 10:06:15 +08:00
7c74ed8638 spi_flash: Expose an accessor the current SPI flash guard functions
Change places which uses g_flash_guard_default_ops to use this. Probably exact same data, but a bit
cleaner.
2018-05-08 10:46:05 +08:00
6e9b9c95df freertos: Also test (& handle) the case where scheduler is disabled on other CPU...
ie CPU A has scheduler disabled and task blocked on Q. CPU B sends to Q (or gives mutex, etc.) Task on CPU A should be woken on scheduler resume.
2018-05-08 10:39:24 +08:00
2fa801dec4 Make sure cache is disabled/enabled when *both* CPUs are running inside the iram guard code 2018-05-08 10:19:16 +08:00
df3ef3184a esp32: fix potential PHY calibration bug
1. Add error log if failed to store calibration version/mac/data
2. Change the NVS calibration version/mac/data store sequence
3. Pass the init_data instead of NULL to esp_phy_rf_init() in esp_phy_load_cal_and_init()
2018-05-07 10:03:51 +08:00
ca9993eca3 Merge branch 'bugfix/btdm_lib_ld_pscan_235_for_v2.1' into 'release/v2.1'
component/bt: fix the bug in controller(ld_pscan.c +235) caused by interrupt react slowly

See merge request !1821
2018-01-23 11:58:49 +08:00
ef7ce1069f component/bt: fix the bug in controller(ld_pscan.c +235) caused by interrupt react slowly 2018-01-22 19:54:49 +08:00
3baa4e39b3 Merge branch 'bugfix/btdm_send_data_len_req_after_read_feats' into 'release/v2.1'
Component/bt: send data length request by host after read feature complete for v2.1

See merge request !1815
2018-01-22 19:43:40 +08:00
137d407e66 Component/bt: send data length request by host after read feature complete 2018-01-17 19:40:22 +08:00
2b089968fe Merge branch 'bugfix/fix_ble_rx_performance_for_2_1' into 'release/v2.1'
component/bt : optimze ble rx performance

See merge request !1668
2018-01-17 19:28:10 +08:00
e5066ed5cb component/bt : optimze ble rx performance 2018-01-16 08:53:51 +00:00
dcf1db17f7 Merge branch 'cherry-pick-1c718330' into 'release/v2.1'
cherry-pick 'bugfix/remove_at_build_from_ci' into 'release/v2.1'

See merge request !1817
2018-01-16 16:45:27 +08:00
43a04ebcf1 Merge branch 'bugfix/remove_at_build_from_ci' into 'master'
CI: remove build at

See merge request !1171
2018-01-16 15:10:16 +08:00
8bca703467 Merge branch 'bugfix/lwip_send_timeout_v2.1' into 'release/v2.1'
match sys tick with lwip_send_timeout

See merge request !1546
2017-11-16 17:40:48 +08:00
0f9925cfc8 match sys tick with lwip_send_timeout 2017-11-16 11:58:16 +08:00
c092079587 Merge branch 'bugfix/btdm_smp_compile_err' into 'release/v2.1'
component/bt: Fix ble compile error when close the SMP module.

See merge request !1541
2017-11-16 11:31:07 +08:00
bb309f0acf Merge branch 'bugfix/fix_airkiss_macro_error_v2.1' into 'release/v2.1'
fix an airkiss typo error

See merge request !1533
2017-11-15 21:31:25 +08:00
ebc8877b75 component/bt: Fix ble compile error when close the SMP module. 2017-11-15 21:13:12 +08:00
11613ba7a7 fix an airkiss typo error 2017-11-15 14:10:04 +08:00
5af843f61b Merge branch 'bugfix/v2.1_rtc_bias_and_restart' into 'release/v2.1'
Cherry-pick: increase core voltage for 80M flash, esp_restart fix

See merge request !1512
2017-11-09 21:09:40 +08:00
a237327eff Merge branch 'feature/tw16227_add_fix_rate_api_2.1' into 'release/v2.1'
esp32: add fix rate api

See merge request !1509
2017-11-09 18:47:09 +08:00
4f603017bd soc/rtc: raise core voltage when 80MHz flash frequency is used
To achieve reliable operation with GD flash at 80MHz, need to raise
core voltage.
This causes the following current consumption increase:

At 80MHz: from 29mA to 33mA
At 160MHz: from 41mA to 47mA

Test conditions: 2 cores running code from IRAM, remaining peripherals
clock gated.
2017-11-09 16:11:59 +08:00
e324707cc8 esp_restart: fix possible race while stalling other CPU, enable WDT early
Previously esp_restart would stall the other CPU before enabling RTC_WDT.
If the other CPU was executing an s32c1i instruction, the lock signal
from CPU to the arbiter would still be held after CPU was stalled. If
the CPU running esp_restart would then try to access the same locked
memory pool, it would be stuck, because lock signal would never be
released.

With this change, esp_restart resets the other CPU before stalling it.
Ideally, we would want to reset the CPU and keep it in reset, but the
hardware doesn't have such feature for PRO_CPU (it is possible to hold
APP_CPU in reset using DPORT register). Given that ROM code will not use
s32c1i in the first few hundred cycles, doing reset and then stall seems
to be safe.

In addition to than, RTC_WDT initialization is moved to the beginning of
the function, to prevent possible lock-up if CPU stalling still has any
issue.
2017-11-09 16:05:35 +08:00
07543dfec4 soc/rtc: wait for SLOW_CLK cycle when switching CPU clock
Previous implementation waited for 20us after setting
RTC_CNTL_SOC_CLK_SEL_XTL register, using ets_delay_us, assuming that
the CPU was running at XTAL frequency. In reality, clock switch happened
on the next RTC_SLOW_CLK cycle, and CPU could be running at the previous
frequency (for example, 240 MHz) until then.
ets_delay_us would wait for 20 us * 40 cycles per us = 800 CPU cycles
(assuming 40 MHz XTAL; even less with a 26 MHz XTAL).
But if CPU was running at 240 MHz, 800 cycles would pass in just 3.3us,
while SLOW_CLK cycle could happen as much as 1/150kHz = 6.7us after
RTC_CNTL_SOC_CLK_SEL_XTL was set. So the software would not actually wait
long enough for the clock switch to happen, and would disable the PLL
while CPU was still clocked from PLL, leading to a halt.

This implementation uses rtc_clk_wait_for_slow_cycle() function to wait
until the clock switch, removing the need to wait for a fixed number of
CPU cycles.
2017-11-09 15:51:14 +08:00
d262fe4bc9 soc/rtc: add a function to wait for slow clock cycle
Some RTC features are synchronized to RTC_SLOW_CLK, so sometimes
software needs to wait for the next slow clock cycle.
This function implements waiting using Timer Group clock calibration
feature.
2017-11-09 15:48:25 +08:00
fd20a89e20 Merge branch 'bugfix/v2.1_bootloader' into 'release/v2.1'
bugfix(80m flash): cherry pick from idf3.0, add gpio config and vddsdio config

See merge request !1503
2017-11-09 14:59:09 +08:00
d6b8602892 Merge branch 'bugfix/btdm_fix_merge_missing' into 'release/v2.1'
component/bt : fix merge missing of scan fail bugfix

See merge request !1507
2017-11-09 14:17:41 +08:00
dfb1c41a28 esp32: add fix rate api
Add hidden fix rate api
2017-11-09 10:06:19 +08:00
378f3463fe soc/rtc: power down VDDSDIO in deep sleep
If VDDSDIO is controlled by RTC (which is the case when using 1.8V flash
and CONFIG_BOOTLOADER_VDDSDIO_BOOST is enabled), need to allow VDDSDIO
to be controlled by the state machine before going into deep sleep.
2017-11-08 21:45:10 +08:00
0c67282bc5 component/bt : fix merge missing of scan fail bugfix 2017-11-08 18:22:05 +08:00
305e2695d6 bugfix(80m flash): cherry pick from idf3.0, add gpio config and vddsdio config
1. raise vddsdio for 1.8v flash
2. gpio matrix config for flash
3. fix esp_restart function

todo:
to decide whether to raise core voltage
to test deep-sleep current
2017-11-08 12:50:08 +08:00
f108f5394f Merge branch 'cherry-pick-97dffbfc' into 'release/v2.1'
component/bt: disable the use of ROLE_SWITCH feature for classic BT as workaround

See merge request !1498
2017-11-07 20:02:05 +08:00
3aad5a09f4 Merge branch 'bugfix/btdm_disable_role_switch' into 'master'
component/bt: disable the use of ROLE_SWITCH feature for classic BT as workaround

See merge request !1446
2017-11-07 15:44:50 +08:00
6d16de8999 Merge branch 'bugfix/fix_800mA_bug_v2.1' into 'release/v2.1'
Fix a problem which initialize current can reach 800mA.

See merge request !1482
2017-11-03 17:34:02 +08:00
4aa6551fe0 Fix a problem which initialize current can reach 800mA. 2017-11-02 11:02:38 +08:00
e2e46f4243 Merge branch 'bugfix/scan_problem_of_bonded_device_v2.1' into 'release/v2.1'
component/bt: Fix scan problem of bonded device using public address

See merge request !1450
2017-10-25 18:12:40 +08:00
c8525c21b9 component/bt: Fix scan problem of bonded device using public address 2017-10-25 15:48:33 +08:00
0e290863db Merge branch 'bugfix/fail_to_reconnect_to_some_aps_v2.1' into 'release/v2.1'
Bugfix/fail to reconnect to some aps v2.1

See merge request !1430
2017-10-24 10:39:30 +08:00
e5b75b4a17 fix the bug that fail to reconnect to some APs 2017-10-20 11:52:53 +08:00
207524f3da Merge branch 'feature/update_phy362_rtc230_for_2_1' into 'release/v2.1'
component/esp32 : update rtc phy lib

See merge request !1400
2017-10-17 14:14:46 +08:00
e5d5727969 Merge branch 'bugfix/sdmmc_tests_v2.1' into 'release/v2.1'
sdmmc tests: Don't run under CI in v2.1

See merge request !1408
2017-10-17 14:13:03 +08:00
3a9781ff45 component/esp32 : remove phy init data description 2017-10-17 11:28:35 +08:00
edbd744991 component/esp32 : update rtc phy lib
RTC V230
add BT AGC saturation protection, replace RTC V229.

PHY V362
Power up print: "phy_version: 362.0, 61e8d92, Sep 8 2017, 18:48:13"
1. esp_init_data_v3.bin
modify TX target power
modify WIFI & BT RX gain table
2. modify phy_close_rf()
3. add phy_set_most_tpw()
4. 26M crystal work OK
5. noise_check_loop ok
2017-10-16 18:00:56 +08:00
817d75a4e1 sdmmc tests: Don't run under CI in v2.1 2017-10-16 17:19:00 +08:00
a73c78a85b Merge branch 'bugfix/backport_to_2.1' into 'release/v2.1'
Backport several bug fixes to 2.1 branch

See merge request !1318
2017-10-11 16:56:22 +08:00
84413f641d Merge branch 'bugfix/btdm_ea_overload_for_rel_v2.1' into 'release/v2.1'
component/bt: update bluetooth library to increase programming delay in EA

See merge request !1344
2017-10-11 16:52:18 +08:00
b6c91ce088 Merge branch 'bugfix/fix_a_wpa_wpa2_bug_v2.1' into 'release/v2.1'
Fix a wpa and wpa2 bug

See merge request !1343
2017-10-11 16:50:53 +08:00
0c75b6e6e6 component/bt: update bluetooth library to increase programming delay in EA 2017-09-30 18:40:49 +08:00
90aafbd25b Merge branch 'feature/ip_route_base_on_source_ip_v2.1' into 'release/v2.1'
Broadcast IP route based on source IP address.

See merge request !1218
2017-09-30 16:04:03 +08:00
b95a6b01ba Merge branch 'bugfix/btdm_update_lib_for_2_1_1' into 'release/v2.1'
component/bt : update libbtdm_app.a

See merge request !1283
2017-09-30 15:53:34 +08:00
151c6d9016 Merge branch 'bugfix/btdm_fixbugs_for_ble_v2.1' into 'release/v2.1'
component/bt: fix ble bugs for v2.1

See merge request !1261
2017-09-30 15:53:00 +08:00
62c2c37606 Fix a wpa and wpa2 bug 2017-09-30 15:51:33 +08:00
3eeaae0573 Merge branch 'bugfix/bt_sdp_server_continuation_2.1' into 'release/v2.1'
bluedroid: Add continuation offset check to SDP server (backport to v2.1)

See merge request !1324
2017-09-27 11:14:26 +08:00
43b25e2a2f bluedroid: Add continuation offset check to SDP server
Fix for CVE-2017-0785
https://android.googlesource.com/platform/system/bt/+/818cf6f%5E%21/#F0
2017-09-27 10:02:31 +10:00
74879c66e0 docs/wifi: remove note about the latest version 2017-09-26 00:11:15 +08:00
5db3b86871 fix(spi_master): fix the bug that VSPI no respond when host changed
from HSPI to VSPI, and vice versa.

fix the SPI control bits written wrong in the headers.

TW#12123, Github#477
2017-09-26 00:04:04 +08:00
65734a8344 Fix an assert that erroneously triggered when popping a zero-byte payload from the end of the ringbuffer 2017-09-26 00:02:52 +08:00
fdb390aeac Place uart_tx_wait_idle in IRAM 2017-09-26 00:02:20 +08:00
f285d8f678 windows: Add workaround for "git submodule" stray output bug
TW10271
2017-09-26 00:01:27 +08:00
6f7d6dbde4 nghttp2: Add submodule to COMPONENT_SUBMODULES, update to release v1.24
Removes need for -DNDEBUG hack in component.mk (fixed upstream).
2017-09-25 23:54:43 +08:00
348825a438 freertos: make sure xPortGetCoreID is placed into IRAM
In some cases, xPortGetCoreID was not inlined, and ended up in flash.
Since this function is used in many situations when cache is disabled,
that caused exceptions. Adding IRAM attribute to fix that.
2017-09-25 23:53:19 +08:00
23d7dd8b8e freertos: place uxTopUsedPriority into DRAM
When debugging crashes caused by flash cache access errors, OpenOCD may
request the value of uxTopUsedPriority when cache is disabled. Placing
it into IRAM to avoid an error in such case.
2017-09-25 23:52:30 +08:00
301fcad36b docs: wifi: use list instead of nested table
Latex backend does not support nested tables, which caused documentation
build to fail on readthedocs.
2017-09-25 23:51:55 +08:00
7655f3e92c nghttp: build port directory
Fixes https://github.com/espressif/esp-idf/issues/843
2017-09-25 23:51:22 +08:00
a61ef26be1 nvs: check CRC of items on full pages
Previously NVS did check CRC values of key-value pairs on the active
page, but the check for full pages was missing. This adds the necessary
check and a test for it.
2017-09-25 23:49:27 +08:00
0f238dcdec sdmmc: fix reads/writes to/from unaligned buffers
SDMMC hardware treats all buffers as aligned, and ignores 2 LSBs of
addresses written into DMA descriptors. Previously SDMMC host driver
assumed that data buffers passed from SDDMC command layer would be
aligned. However alignment checks were never implemented in the command
layer, as were the checks that the buffer coming from the application
would be in DMA capable memory. Most of the time this was indeed true.
However in some cases FATFS library can pass buffers offset by 2 bytes
from word boundary. “DMA capable” restriction may be broken if pSRAM
support is used.

This change adds buffer checks to the SDMMC host driver (alignment and
DMA capability), so that the host layer will error out for incompatible
buffers. In SDMMC command layer, a check is added to read and write
functions. If an incompatible buffer is passed from the application, new
buffer (512 bytes size) is allocated, and the transfer is performed
using {READ,WRITE}_SINGLE_BLOCK commands.
2017-09-25 23:45:40 +08:00
70f3dccaf5 driver/rtc: fix copy-paste error in HOLD_FORCE field name for GPIO26
This error prevented EXT1 wakeup using GPIO26 from working.
2017-09-25 23:33:35 +08:00
8e3de3fbde component/bt : update libbtdm_app.a
1. fix 0x3ffc0000 overwite bug
2. no cswitch jump table
3. fix hci controller to host flow control bug
4. fix SMP negtive LTK replay bug
5. btdm .data init bug
6. fix scan fail after long time bug
7. change pll track interrupt bits
2017-09-25 18:33:24 +08:00
691c8693e6 Component/bt: add random address check for set_rand_addr() 2017-09-22 20:19:02 +08:00
25b0a4f514 Component/bt: abnormal behavior for update conn param command 2017-09-22 20:19:02 +08:00
fbdec19c23 component/bt : fix btc security storage bug
1. Remove the bond_device global variable.
2. Fix bond_device add cause memory exception
3. Modify the code location.
4. modify thread security
5. remove esp_ble_clear_bond_device_list() API
6. modify esp_ble_get_gond_device_list() to return list immediately, rather than wait event.
7. modify the gatt_security_server demo to show how to remove all the bonded devices.
8. fix some code bugs may cause something error.
9. modify gatt_security_server demo
2017-09-22 20:19:02 +08:00
4fd437d466 component/bt : support remove bonded device
1. add feature of remove bonded devices.
2. fix SMP key size bug
3. fix privacy bug
4. fix gatt set value bug
5. add gatt security client demo
6. change gatt server/gatt client demo
2017-09-22 20:19:02 +08:00
00b5f82c41 Merge branch 'bugfix/fix_set_locked_channel_typo_of_smartconfig' into 'release/v2.1'
fix set locked channel typo of smartconfig

See merge request !1156
2017-09-19 14:06:33 +08:00
3062790128 gitlab-ci: use specific version of build container 2017-09-18 18:26:27 +08:00
024f853964 Broadcast IP route based on source IP address.
If destination IP address of the packet is broadcast address, firstly compare
    source IP address with the that of each network interface. If it matches,
    packet is forwarded from the interface.
2017-09-05 17:51:15 +08:00
cf185846f5 fix set locked channel typo of smartconfig 2017-08-25 16:25:03 +08:00
7138fb0290 Merge branch 'bugfix/xtal_freq_40_2.1' into 'release/v2.1'
esp32: by default, set 40MHz crystal frequency

See merge request !1143
2017-08-24 20:40:11 +08:00
b7f7a92c5d esp32: by default, set 40MHz crystal frequency 2017-08-23 16:39:22 +08:00
27574a31e7 Merge branch 'feature/tw12244_add_more_comments_for_wifi_api_v2.1' into 'release/v2.1'
docs: add wifi doc

See merge request !1046
2017-07-24 19:42:36 +08:00
8134140acd docs: add wifi doc
Add more comments about WiFi API usage
2017-07-24 14:52:00 +08:00
efdbc63b5f Merge branch 'cherry-pick-292c2abd' into 'release/v2.1'
Merge branch 'bugfix/init_nvs_in_bluetooth' into 'master'

See merge request !1031
2017-07-23 14:35:33 +08:00
1891382db6 examples: add missing nvs_flash.h include 2017-07-20 17:53:39 +08:00
16cd517410 Merge branch 'bugfix/tw14046_scan_assert_in_non_sleep_mode' into 'release/v2.1'
Fix the bug that scan assert in non sleep mode.

See merge request !1023
2017-07-20 14:57:04 +08:00
8fc78a958a Merge branch 'bugfix/init_nvs_in_bluetooth' into 'master'
bt: call nvs_flash_init in examples, show error if NVS is not initialized

See merge request !1003
2017-07-20 14:26:14 +08:00
3cbaf98d29 Merge branch 'bugfix/btdm_rx_losing' into 'release/v2.1'
component/bt : update libbtadm_app.a (easing syncerr to fix RX packet losing bug)

See merge request !1029
2017-07-20 14:19:49 +08:00
b2d41a3506 component/bt : update libbtadm_app.a (easing syncerr to fix RX packet losing bug) 2017-07-20 11:51:28 +08:00
5d1ec0da02 Fix the bug that scan assert in non sleep mode. 2017-07-19 14:12:14 +08:00
6a9e9759ea Merge branch 'bugfix/l2cap_disc_tmo' into 'release/v2.1'
component/bt: fix a bug for L2CAP state machine to access lcb after it is released

See merge request !1015
2017-07-18 19:49:05 +08:00
0de622e4f6 component/bt: fix a bug for L2CAP state machine to access lcb after it is released
cherry-pick commit 6da84eff
2017-07-17 21:30:40 +08:00
fc67a8b1b9 Merge branch 'cherry-pick-5d736f7eca' into 'release/v2.1'
mbedtls: Fix memory leak in initial ECDH exchange if OOM/failure occurs

See merge request !995
2017-07-17 21:18:32 +08:00
41f43164e2 Merge branch 'cherry-pick-0c28b3bc' into 'release/v2.1'
Merge branch 'bugfix/btdm_update_connect_params_for_gattc' into 'master'

See merge request !996
2017-07-17 21:10:54 +08:00
2236ab7bd4 Merge branch 'cherry-pick-5ac0503c' into 'release/v2.1'
Merge branch 'bugfix/btdm_modify_BTA_GATTC_KNOWN_SR_MAX_for_Multi-connection' into 'master'

See merge request !999
2017-07-17 21:10:30 +08:00
a281359db0 Merge branch 'cherry-pick-4ec2abbf' into 'release/v2.1'
Merge branch 'feature/some_refactor_for_tcpip_adapter' into 'master'

See merge request !1000
2017-07-17 21:10:04 +08:00
1fb777cc49 Merge branch 'feature/some_refactor_for_tcpip_adapter' into 'master'
tcpip_adapter: not remove netif when tcpip adapter is stopped

See merge request !943
2017-07-13 22:16:58 +08:00
92facb6884 Merge branch 'bugfix/btdm_modify_BTA_GATTC_KNOWN_SR_MAX_for_Multi-connection' into 'master'
component/bt: modify BTA_GATTC_KNOWN_SR_MAX for Multi-connection bug

See merge request !992
2017-07-13 21:55:36 +08:00
eb38883217 Merge branch 'bugfix/btdm_update_connect_params_for_gattc' into 'master'
component/bt: bugfix update connect params for gattc

See merge request !991
2017-07-13 16:08:02 +08:00
5d736f7eca mbedtls: Fix memory leak in initial ECDH exchange if OOM/failure occurs
In ecp_mul_comb(), if (!p_eq_g && grp->T == NULL) and ecp_precompute_comb() fails (which can happen due to OOM), then the new array of points T was leaked.
2017-07-13 15:55:57 +08:00
bdc499aea7 Merge branch 'cherry-pick-94877972' into 'release/v2.1'
freertos: Bump idle stack size to 1KB, min stack to 768 bytes, make configurable

See merge request !981
2017-07-12 22:39:12 +08:00
99dbfb3539 Merge branch 'bugfix/minimal_stack_size' into 'master'
freertos: Bump idle stack size to 1KB, min stack to 768 bytes, make configurable

See merge request !979
2017-07-12 04:24:18 +08:00
8d3e1a2a79 Merge branch 'bugfix/btdm_blufi_aes_cfb128_for_v2.1' into 'release/v2.1'
component/bt : comment out set_key_dec for res cfb128(software crypt)

See merge request !972
2017-07-09 11:52:23 +08:00
f33b0fd4c9 Merge branch 'bugfix/btdm_update_lib_for_v2.1' into 'release/v2.1'
component/bt : update lib for fix register reg(follow V2.1 RC)

See merge request !973
2017-07-08 23:29:37 +08:00
b99551b48f component/bt : update lib for fix register reg(follow V2.1 RC) 2017-07-08 22:48:26 +08:00
6c04e3ee6a component/bt : comment out set_key_dec for res cfb128(software crypt) 2017-07-08 22:46:02 +08:00
6878c4e329 Merge branch 'cherry-pick-7a79d31d' into 'release/v2.1'
fix reg operation missing

See merge request !966
2017-07-08 15:46:58 +08:00
f54a656932 Merge branch 'bugfix/make_low_rate_work' into 'release/v2.1'
esp32: udpate wifi lib to make low rate work

See merge request !967
2017-07-08 01:11:26 +08:00
305564cd59 esp32: udpate wifi lib to make low rate work
Make low rate feature work
2017-07-07 22:47:39 +08:00
6bceb41bf7 fix reg operation missing 2017-07-07 22:44:05 +08:00
2e9db99921 Merge branch 'cherry-pick-6d03d42d' into 'release/v2.1'
Merge branch 'bugfix/btdm_error_length_unit' into 'master'

See merge request !960
2017-07-07 11:14:03 +08:00
fa7d3f38fc Merge branch 'cherry_pick_to_release_v2.1' into 'release/v2.1'
Update release/v2.1 with some bug fixes

See merge request !952
2017-07-07 11:13:43 +08:00
602e223c9c mbedtls unit tests: Allow for longer timeout using software SHA
Hardware SHA runs SHA operations faster than software...
2017-07-06 18:09:59 +08:00
baa743c7b9 Merge branch 'bugfix/btdm_error_length_unit' into 'master'
Component/bt: fix bug for  error length unit

See merge request !950
2017-07-06 14:49:09 +08:00
6db29f0766 soc: fix typo in register name 2017-07-06 14:29:37 +08:00
abec2392c7 esp_chip_info: populate ‘model’ field 2017-07-06 14:29:30 +08:00
8a54ebe02e docs: update general notes section on IRAM/ISRs
- Remove outdated note that all ISRs should be in IRAM
- Replace “ISR handler” with “ISR” or “interrupt handler”
2017-07-06 14:29:23 +08:00
0a1c68d7b6 docs: fix flash encryption key storage block, use same names as in TRM 2017-07-06 14:29:15 +08:00
494641c481 phy_init: fix log level for "PHY data partition validated" message 2017-07-06 14:29:08 +08:00
3ab2436b11 mbedtls: Temporarily disable hardware acceleration in dual-core mode
Temporary fix, until DPORT bugs in crypto accelerators are completely fixed.
2017-07-06 14:28:43 +08:00
ee86c15ab8 Merge branch 'cherry-pick-55b3ea9c' into 'release/v2.1'
Merge branch 'bugfix/btdm_cherry-pick_ble_smp_bonding_issues' into 'master'

See merge request !949
2017-07-04 17:28:30 +08:00
9deaa6ab60 Merge branch 'cherry-pick-3c082b47' into 'release/v2.1'
Merge branch 'bugfix/bt_avdt_state_machine' into 'master'

See merge request !948
2017-07-04 17:28:17 +08:00
8a5c1e9209 Merge branch 'cherry-pick-176107f8' into 'release/v2.1'
update expiration date of wpa2 enterprise certificates to 2027/06/05.

See merge request !945
2017-07-04 17:28:00 +08:00
3d3994632b ESP_ERR_NVS_VALUE_TOO_LONG had conflicting value.
`ESP_ERR_NVS_VALUE_TOO_LONG` had conflicting value, its original value was `0x0c`, which is the same as `ESP_ERR_NVS_INVALID_LENGTH`
2017-07-04 15:31:33 +08:00
17dd3e9ca0 nvs: add test for ESP_ERR_NVS_INVALID_LENGTH 2017-07-04 15:31:10 +08:00
c40bbc5c42 ipc task: Allow configuration of IPC task stack size
Fixes regression in 3fe0022ef
2017-07-04 15:30:04 +08:00
1b3120615b stack sizes: Revert stack size increases added in 8d43859
Set min stack size to 2048 if AppTrace support is enabled, 512 bytes otherwise.
2017-07-04 15:29:33 +08:00
3365b9322b dport_access: Fix spurious warning in unicore mode, refactor 2017-07-04 15:27:31 +08:00
852e94d73a bugfix(uart): fix bugs reported from github
1. uart_set_line_inverse API issue, https://github.com/espressif/esp-idf/issues/673
2. tx buffer length issue, https://github.com/espressif/esp-idf/issues/710
2017-07-04 15:24:02 +08:00
09bb7a7650 newlib locks: Fix _lock_init() & _lock_init_recursive() failing to initialise a lock
If scheduler was running, and lock was an automatic variable (ie stack-allocated) to be initialised by _lock_init*,
initialisation could be skipped if the lock variable was non-zero (and lock would be left invalid).

In other cases the lock is statically initialised to zero by __LOCK_INIT*
2017-07-04 15:23:10 +08:00
4f4fb7b453 Merge branch 'bugfix/btdm_cherry-pick_ble_smp_bonding_issues' into 'master'
component/bt: Fixed the bug crash of disconnet BLE when close the SMP module in the menuconfig.

See merge request !941
2017-07-03 19:49:30 +08:00
663129abce Merge branch 'bugfix/bt_avdt_state_machine' into 'master'
component/bt: bugfix for AVDTP state machine function on disconnection to handle NULL pointer condition

See merge request !946
2017-07-03 19:48:40 +08:00
9cf81f754b update expiration date of wpa2 enterprise certificates to 2027/06/05. 2017-07-03 15:41:11 +08:00
166 changed files with 6063 additions and 2125 deletions

View File

@ -41,7 +41,7 @@ before_script:
build_template_app:
stage: build
image: $CI_DOCKER_REGISTRY/esp32-ci-env
image: $CI_DOCKER_REGISTRY/esp32-ci-env:v2.1
tags:
- build
variables:
@ -69,7 +69,7 @@ build_template_app:
.build_template: &build_template
stage: build
image: $CI_DOCKER_REGISTRY/esp32-ci-env
image: $CI_DOCKER_REGISTRY/esp32-ci-env:v2.1
tags:
- build
variables:
@ -89,15 +89,6 @@ build_ssc:
- git checkout ${CI_COMMIT_REF_NAME} || echo "Using SSC default branch..."
- MAKEFLAGS= ./gen_misc_ng.sh
build_at:
<<: *build_template
script:
- git clone $GITLAB_SSH_SERVER/application/esp-at.git
- cd esp-at
- git checkout ${CI_COMMIT_REF_NAME} || echo "Using esp-at default branch..."
- make defconfig
- make
build_esp_idf_tests:
<<: *build_template
artifacts:
@ -154,7 +145,7 @@ build_examples_04:
build_docs:
stage: build
image: $CI_DOCKER_REGISTRY/esp32-ci-env
image: $CI_DOCKER_REGISTRY/esp32-ci-env:v2.1
tags:
- build_docs
artifacts:
@ -171,7 +162,7 @@ build_docs:
test_nvs_on_host:
stage: test
image: $CI_DOCKER_REGISTRY/esp32-ci-env
image: $CI_DOCKER_REGISTRY/esp32-ci-env:v2.1
tags:
- nvs_host_test
dependencies: []
@ -181,7 +172,7 @@ test_nvs_on_host:
test_partition_table_on_host:
stage: test
image: $CI_DOCKER_REGISTRY/esp32-ci-env
image: $CI_DOCKER_REGISTRY/esp32-ci-env:v2.1
tags:
- build
dependencies: []
@ -191,7 +182,7 @@ test_partition_table_on_host:
test_wl_on_host:
stage: test
image: $CI_DOCKER_REGISTRY/esp32-ci-env
image: $CI_DOCKER_REGISTRY/esp32-ci-env:v2.1
tags:
- wl_host_test
artifacts:
@ -204,7 +195,7 @@ test_wl_on_host:
test_build_system:
stage: test
image: $CI_DOCKER_REGISTRY/esp32-ci-env
image: $CI_DOCKER_REGISTRY/esp32-ci-env:v2.1
tags:
- build_test
dependencies: []
@ -214,7 +205,7 @@ test_build_system:
test_report:
stage: test_report
image: $CI_DOCKER_REGISTRY/esp32-ci-env
image: $CI_DOCKER_REGISTRY/esp32-ci-env:v2.1
tags:
- report
only:
@ -269,7 +260,7 @@ push_master_to_github:
before_script:
- echo "Not setting up GitLab key, not fetching submodules"
stage: deploy
image: $CI_DOCKER_REGISTRY/esp32-ci-env
image: $CI_DOCKER_REGISTRY/esp32-ci-env:v2.1
tags:
- deploy
only:
@ -300,7 +291,7 @@ deploy_docs:
before_script:
- echo "Not setting up GitLab key, not fetching submodules"
stage: deploy
image: $CI_DOCKER_REGISTRY/esp32-ci-env
image: $CI_DOCKER_REGISTRY/esp32-ci-env:v2.1
tags:
- deploy
only:
@ -326,7 +317,7 @@ deploy_docs:
check_doc_links:
stage: test
image: $CI_DOCKER_REGISTRY/esp32-ci-env
image: $CI_DOCKER_REGISTRY/esp32-ci-env:v2.1
tags:
- check_doc_links
only:
@ -346,7 +337,7 @@ check_doc_links:
check_commit_msg:
stage: deploy
image: $CI_DOCKER_REGISTRY/esp32-ci-env
image: $CI_DOCKER_REGISTRY/esp32-ci-env:v2.1
tags:
- build
except:
@ -363,7 +354,7 @@ check_commit_msg:
check_submodule_sync:
stage: deploy
image: $CI_DOCKER_REGISTRY/esp32-ci-env
image: $CI_DOCKER_REGISTRY/esp32-ci-env:v2.1
tags:
- build
except:

View File

@ -28,8 +28,17 @@ config LOG_BOOTLOADER_LEVEL
default 4 if LOG_BOOTLOADER_LEVEL_DEBUG
default 5 if LOG_BOOTLOADER_LEVEL_VERBOSE
endmenu
config BOOTLOADER_VDDSDIO_BOOST
bool "Increase VDDSDIO LDO voltage to 1.9V"
default y
help
If this option is enabled, and VDDSDIO LDO is set to 1.8V (using EFUSE
or MTDI bootstrapping pin), bootloader will change LDO settings to
output 1.9V instead. This helps prevent flash chip from browning out
during flash programming operations.
For 3.3V flash, this option has no effect.
endmenu # Bootloader
menu "Security features"

View File

@ -72,6 +72,8 @@ static void set_cache_and_start_app(uint32_t drom_addr,
uint32_t irom_size,
uint32_t entry_addr);
static void update_flash_config(const esp_image_header_t* pfhdr);
static void vddsdio_configure();
static void flash_gpio_configure();
static void clock_configure(void);
static void uart_console_configure(void);
static void wdt_reset_check(void);
@ -237,6 +239,8 @@ static bool ota_select_valid(const esp_ota_select_entry_t *s)
void bootloader_main()
{
vddsdio_configure();
flash_gpio_configure();
clock_configure();
uart_console_configure();
wdt_reset_check();
@ -697,6 +701,104 @@ void print_flash_info(const esp_image_header_t* phdr)
#endif
}
static void vddsdio_configure()
{
#if CONFIG_BOOTLOADER_VDDSDIO_BOOST
rtc_vddsdio_config_t cfg = rtc_vddsdio_get_config();
if (cfg.tieh == 0) { // 1.8V is used
cfg.drefh = 3;
cfg.drefm = 3;
cfg.drefl = 3;
cfg.force = 1;
cfg.enable = 1;
rtc_vddsdio_set_config(cfg);
ets_delay_us(10); // wait for regulator to become stable
}
#endif // CONFIG_BOOTLOADER_VDDSDIO_BOOST
}
#define FLASH_CLK_IO 6
#define FLASH_CS_IO 11
#define FLASH_SPIQ_IO 7
#define FLASH_SPID_IO 8
#define FLASH_SPIWP_IO 10
#define FLASH_SPIHD_IO 9
#define FLASH_IO_MATRIX_DUMMY_40M 1
#define FLASH_IO_MATRIX_DUMMY_80M 2
static void IRAM_ATTR flash_gpio_configure()
{
int spi_cache_dummy = 0;
int drv = 2;
#if CONFIG_FLASHMODE_QIO
spi_cache_dummy = SPI0_R_QIO_DUMMY_CYCLELEN; //qio 3
#elif CONFIG_FLASHMODE_QOUT
spi_cache_dummy = SPI0_R_FAST_DUMMY_CYCLELEN; //qout 7
#elif CONFIG_FLASHMODE_DIO
spi_cache_dummy = SPI0_R_DIO_DUMMY_CYCLELEN; //dio 3
#elif CONFIG_FLASHMODE_DOUT
spi_cache_dummy = SPI0_R_FAST_DUMMY_CYCLELEN; //dout 7
#endif
/* dummy_len_plus values defined in ROM for SPI flash configuration */
extern uint8_t g_rom_spiflash_dummy_len_plus[];
#if CONFIG_ESPTOOLPY_FLASHFREQ_40M
g_rom_spiflash_dummy_len_plus[0] = FLASH_IO_MATRIX_DUMMY_40M;
g_rom_spiflash_dummy_len_plus[1] = FLASH_IO_MATRIX_DUMMY_40M;
SET_PERI_REG_BITS(SPI_USER1_REG(0), SPI_USR_DUMMY_CYCLELEN_V, spi_cache_dummy + FLASH_IO_MATRIX_DUMMY_40M, SPI_USR_DUMMY_CYCLELEN_S); //DUMMY
#elif CONFIG_ESPTOOLPY_FLASHFREQ_80M
g_rom_spiflash_dummy_len_plus[0] = FLASH_IO_MATRIX_DUMMY_80M;
g_rom_spiflash_dummy_len_plus[1] = FLASH_IO_MATRIX_DUMMY_80M;
SET_PERI_REG_BITS(SPI_USER1_REG(0), SPI_USR_DUMMY_CYCLELEN_V, spi_cache_dummy + FLASH_IO_MATRIX_DUMMY_80M, SPI_USR_DUMMY_CYCLELEN_S); //DUMMY
drv = 3;
#endif
uint32_t chip_ver = REG_GET_FIELD(EFUSE_BLK0_RDATA3_REG, EFUSE_RD_CHIP_VER_PKG);
uint32_t pkg_ver = chip_ver & 0x7;
if (pkg_ver == EFUSE_RD_CHIP_VER_PKG_ESP32D2WDQ5) {
// For ESP32D2WD the SPI pins are already configured
ESP_LOGI(TAG, "Detected ESP32D2WD");
//flash clock signal should come from IO MUX.
PIN_FUNC_SELECT(PERIPHS_IO_MUX_SD_CLK_U, FUNC_SD_CLK_SPICLK);
SET_PERI_REG_BITS(PERIPHS_IO_MUX_SD_CLK_U, FUN_DRV, drv, FUN_DRV_S);
} else if (pkg_ver == EFUSE_RD_CHIP_VER_PKG_ESP32PICOD2) {
// For ESP32PICOD2 the SPI pins are already configured
ESP_LOGI(TAG, "Detected ESP32PICOD2");
//flash clock signal should come from IO MUX.
PIN_FUNC_SELECT(PERIPHS_IO_MUX_SD_CLK_U, FUNC_SD_CLK_SPICLK);
SET_PERI_REG_BITS(PERIPHS_IO_MUX_SD_CLK_U, FUN_DRV, drv, FUN_DRV_S);
} else if (pkg_ver == EFUSE_RD_CHIP_VER_PKG_ESP32PICOD4) {
// For ESP32PICOD4 the SPI pins are already configured
ESP_LOGI(TAG, "Detected ESP32PICOD4");
//flash clock signal should come from IO MUX.
PIN_FUNC_SELECT(PERIPHS_IO_MUX_SD_CLK_U, FUNC_SD_CLK_SPICLK);
SET_PERI_REG_BITS(PERIPHS_IO_MUX_SD_CLK_U, FUN_DRV, drv, FUN_DRV_S);
} else {
ESP_LOGI(TAG, "Detected ESP32");
const uint32_t spiconfig = ets_efuse_get_spiconfig();
if (spiconfig == EFUSE_SPICONFIG_SPI_DEFAULTS) {
gpio_matrix_out(FLASH_CS_IO, SPICS0_OUT_IDX, 0, 0);
gpio_matrix_out(FLASH_SPIQ_IO, SPIQ_OUT_IDX, 0, 0);
gpio_matrix_in(FLASH_SPIQ_IO, SPIQ_IN_IDX, 0);
gpio_matrix_out(FLASH_SPID_IO, SPID_OUT_IDX, 0, 0);
gpio_matrix_in(FLASH_SPID_IO, SPID_IN_IDX, 0);
gpio_matrix_out(FLASH_SPIWP_IO, SPIWP_OUT_IDX, 0, 0);
gpio_matrix_in(FLASH_SPIWP_IO, SPIWP_IN_IDX, 0);
gpio_matrix_out(FLASH_SPIHD_IO, SPIHD_OUT_IDX, 0, 0);
gpio_matrix_in(FLASH_SPIHD_IO, SPIHD_IN_IDX, 0);
//select pin function gpio
PIN_FUNC_SELECT(PERIPHS_IO_MUX_SD_DATA0_U, PIN_FUNC_GPIO);
PIN_FUNC_SELECT(PERIPHS_IO_MUX_SD_DATA1_U, PIN_FUNC_GPIO);
PIN_FUNC_SELECT(PERIPHS_IO_MUX_SD_DATA2_U, PIN_FUNC_GPIO);
PIN_FUNC_SELECT(PERIPHS_IO_MUX_SD_DATA3_U, PIN_FUNC_GPIO);
PIN_FUNC_SELECT(PERIPHS_IO_MUX_SD_CMD_U, PIN_FUNC_GPIO);
// flash clock signal should come from IO MUX.
// set drive ability for clock
PIN_FUNC_SELECT(PERIPHS_IO_MUX_SD_CLK_U, FUNC_SD_CLK_SPICLK);
SET_PERI_REG_BITS(PERIPHS_IO_MUX_SD_CLK_U, FUN_DRV, drv, FUN_DRV_S);
}
}
}
static void clock_configure(void)
{

View File

@ -163,7 +163,7 @@ static void enable_qio_mode(read_status_fn_t read_status_fn,
// spiconfig specifies a custom efuse pin configuration. This config defines all pins -except- WP.
//
// For now, in this situation we only support Quad I/O mode for ESP32-D2WD where WP pin is known.
uint32_t chip_ver = REG_GET_FIELD(EFUSE_BLK0_RDATA3_REG, EFUSE_RD_CHIP_VER_RESERVE);
uint32_t chip_ver = REG_GET_FIELD(EFUSE_BLK0_RDATA3_REG, EFUSE_RD_CHIP_VER_PKG);
uint32_t pkg_ver = chip_ver & 0x7;
const uint32_t PKG_VER_ESP32_D2WD = 2; // TODO: use chip detection API once available
if (pkg_ver != PKG_VER_ESP32_D2WD) {

View File

@ -20,13 +20,13 @@
#include "bt_trace.h"
#include "btc_manage.h"
#include "btc_gap_ble.h"
#include "btc_ble_storage.h"
esp_err_t esp_ble_gap_register_callback(esp_gap_ble_cb_t callback)
{
if (esp_bluedroid_get_status() == ESP_BLUEDROID_STATUS_UNINITIALIZED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
return (btc_profile_cb_set(BTC_PID_GAP_BLE, callback) == 0 ? ESP_OK : ESP_FAIL);
}
@ -36,10 +36,8 @@ esp_err_t esp_ble_gap_config_adv_data(esp_ble_adv_data_t *adv_data)
btc_msg_t msg;
btc_ble_gap_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
if (adv_data == NULL) {
return ESP_ERR_INVALID_ARG;
}
@ -63,10 +61,8 @@ esp_err_t esp_ble_gap_set_scan_params(esp_ble_scan_params_t *scan_params)
btc_msg_t msg;
btc_ble_gap_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
if (scan_params == NULL) {
return ESP_ERR_INVALID_ARG;
}
@ -84,9 +80,7 @@ esp_err_t esp_ble_gap_start_scanning(uint32_t duration)
btc_msg_t msg;
btc_ble_gap_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BLE;
@ -101,10 +95,8 @@ esp_err_t esp_ble_gap_stop_scanning(void)
{
btc_msg_t msg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BLE;
msg.act = BTC_GAP_BLE_ACT_STOP_SCAN;
@ -116,10 +108,8 @@ esp_err_t esp_ble_gap_start_advertising(esp_ble_adv_params_t *adv_params)
btc_msg_t msg;
btc_ble_gap_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BLE;
msg.act = BTC_GAP_BLE_ACT_START_ADV;
@ -132,10 +122,8 @@ esp_err_t esp_ble_gap_stop_advertising(void)
{
btc_msg_t msg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BLE;
msg.act = BTC_GAP_BLE_ACT_STOP_ADV;
@ -149,10 +137,8 @@ esp_err_t esp_ble_gap_update_conn_params(esp_ble_conn_update_params_t *params)
btc_msg_t msg;
btc_ble_gap_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BLE;
msg.act = BTC_GAP_BLE_ACT_UPDATE_CONN_PARAM;
@ -166,10 +152,8 @@ esp_err_t esp_ble_gap_set_pkt_data_len(esp_bd_addr_t remote_device, uint16_t tx_
btc_msg_t msg;
btc_ble_gap_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BLE;
msg.act = BTC_GAP_BLE_ACT_SET_PKT_DATA_LEN;
@ -185,10 +169,8 @@ esp_err_t esp_ble_gap_set_rand_addr(esp_bd_addr_t rand_addr)
btc_msg_t msg;
btc_ble_gap_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BLE;
msg.act = BTC_GAP_BLE_ACT_SET_RAND_ADDRESS;
@ -203,10 +185,8 @@ esp_err_t esp_ble_gap_config_local_privacy (bool privacy_enable)
btc_msg_t msg;
btc_ble_gap_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BLE;
msg.act = BTC_GAP_BLE_ACT_CONFIG_LOCAL_PRIVACY;
@ -217,6 +197,8 @@ esp_err_t esp_ble_gap_config_local_privacy (bool privacy_enable)
esp_err_t esp_ble_gap_set_device_name(const char *name)
{
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
return esp_bt_dev_set_device_name(name);
}
@ -241,9 +223,7 @@ esp_err_t esp_ble_gap_config_adv_data_raw(uint8_t *raw_data, uint32_t raw_data_l
btc_msg_t msg;
btc_ble_gap_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
if (raw_data == NULL
|| (raw_data_len <= 0 || raw_data_len > ESP_BLE_ADV_DATA_LEN_MAX)) {
@ -265,9 +245,7 @@ esp_err_t esp_ble_gap_config_scan_rsp_data_raw(uint8_t *raw_data, uint32_t raw_d
btc_msg_t msg;
btc_ble_gap_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
if (raw_data == NULL
|| (raw_data_len <= 0 || raw_data_len > ESP_BLE_SCAN_RSP_DATA_LEN_MAX)) {
@ -284,13 +262,15 @@ esp_err_t esp_ble_gap_config_scan_rsp_data_raw(uint8_t *raw_data, uint32_t raw_d
}
#if (SMP_INCLUDED)
esp_err_t esp_ble_gap_set_security_param(esp_ble_sm_param_t param_type,
void *value, uint8_t len)
{
btc_msg_t msg;
btc_ble_gap_args_t arg;
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BLE;
msg.act = BTC_GAP_BLE_SET_SECURITY_PARAM_EVT;
@ -307,6 +287,8 @@ esp_err_t esp_ble_set_encryption(esp_bd_addr_t bd_addr, esp_ble_sec_act_t sec_ac
btc_msg_t msg;
btc_ble_gap_args_t arg;
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BLE;
msg.act = BTC_GAP_BLE_SET_ENCRYPTION_EVT;
@ -321,6 +303,9 @@ esp_err_t esp_ble_gap_security_rsp(esp_bd_addr_t bd_addr, bool accept)
{
btc_msg_t msg;
btc_ble_gap_args_t arg;
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BLE;
msg.act = BTC_GAP_BLE_SECURITY_RSP_EVT;
@ -337,6 +322,8 @@ esp_err_t esp_ble_passkey_reply(esp_bd_addr_t bd_addr, bool accept, uint32_t pas
btc_msg_t msg;
btc_ble_gap_args_t arg;
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BLE;
msg.act = BTC_GAP_BLE_PASSKEY_REPLY_EVT;
@ -353,6 +340,8 @@ esp_err_t esp_ble_confirm_reply(esp_bd_addr_t bd_addr, bool accept)
btc_msg_t msg;
btc_ble_gap_args_t arg;
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BLE;
msg.act = BTC_GAP_BLE_CONFIRM_REPLY_EVT;
@ -363,14 +352,54 @@ esp_err_t esp_ble_confirm_reply(esp_bd_addr_t bd_addr, bool accept)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_remove_bond_device(esp_bd_addr_t bd_addr)
{
btc_msg_t msg;
btc_ble_gap_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BLE;
msg.act = BTC_GAP_BLE_REMOVE_BOND_DEV_EVT;
memcpy(arg.remove_bond_device.bd_addr, bd_addr, ESP_BD_ADDR_LEN);
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
int esp_ble_get_bond_device_num(void)
{
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
return btc_storage_get_num_ble_bond_devices();
}
esp_err_t esp_ble_get_bond_device_list(int *dev_num, esp_ble_bond_dev_t *dev_list)
{
int ret;
int dev_num_total;
if (dev_num == NULL || dev_list == NULL) {
return ESP_ERR_INVALID_ARG;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
dev_num_total = btc_storage_get_num_ble_bond_devices();
if (*dev_num > dev_num_total) {
*dev_num = dev_num_total;
}
ret = btc_storage_get_bonded_ble_devices_list(dev_list, *dev_num);
return (ret == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
#endif /* #if (SMP_INCLUDED) */
esp_err_t esp_ble_gap_disconnect(esp_bd_addr_t remote_device)
{
btc_msg_t msg;
btc_ble_gap_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BLE;

View File

@ -23,9 +23,7 @@
#if (GATTC_INCLUDED == TRUE)
esp_err_t esp_ble_gattc_register_callback(esp_gattc_cb_t callback)
{
if (esp_bluedroid_get_status() == ESP_BLUEDROID_STATUS_UNINITIALIZED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
if (callback == NULL) {
return ESP_FAIL;
@ -40,9 +38,7 @@ esp_err_t esp_ble_gattc_app_register(uint16_t app_id)
btc_msg_t msg;
btc_ble_gattc_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
if (app_id > ESP_APP_ID_MAX) {
return ESP_ERR_INVALID_ARG;
@ -61,9 +57,7 @@ esp_err_t esp_ble_gattc_app_unregister(esp_gatt_if_t gattc_if)
btc_msg_t msg;
btc_ble_gattc_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
@ -78,9 +72,7 @@ esp_err_t esp_ble_gattc_open(esp_gatt_if_t gattc_if, esp_bd_addr_t remote_bda, b
btc_msg_t msg;
btc_ble_gattc_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
@ -97,9 +89,7 @@ esp_err_t esp_ble_gattc_close (esp_gatt_if_t gattc_if, uint16_t conn_id)
btc_msg_t msg;
btc_ble_gattc_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
@ -114,9 +104,7 @@ esp_err_t esp_ble_gattc_config_mtu (esp_gatt_if_t gattc_if, uint16_t conn_id, ui
btc_msg_t msg;
btc_ble_gattc_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
if ((mtu < ESP_GATT_DEF_BLE_MTU_SIZE) || (mtu > ESP_GATT_MAX_MTU_SIZE)) {
return ESP_GATT_ILLEGAL_PARAMETER;
@ -136,9 +124,7 @@ esp_err_t esp_ble_gattc_search_service(esp_gatt_if_t gattc_if, uint16_t conn_id,
btc_msg_t msg;
btc_ble_gattc_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
@ -163,9 +149,7 @@ esp_err_t esp_ble_gattc_get_characteristic(esp_gatt_if_t gattc_if,
btc_msg_t msg;
btc_ble_gattc_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
@ -192,9 +176,7 @@ esp_err_t esp_ble_gattc_get_descriptor(esp_gatt_if_t gattc_if,
btc_msg_t msg;
btc_ble_gattc_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
@ -223,9 +205,7 @@ esp_err_t esp_ble_gattc_get_included_service(esp_gatt_if_t gattc_if,
btc_msg_t msg;
btc_ble_gattc_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
@ -253,9 +233,7 @@ esp_err_t esp_ble_gattc_read_char (esp_gatt_if_t gattc_if,
btc_msg_t msg;
btc_ble_gattc_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
@ -278,9 +256,7 @@ esp_err_t esp_ble_gattc_read_char_descr (esp_gatt_if_t gattc_if,
btc_msg_t msg;
btc_ble_gattc_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
@ -306,9 +282,7 @@ esp_err_t esp_ble_gattc_write_char( esp_gatt_if_t gattc_if,
btc_msg_t msg;
btc_ble_gattc_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
@ -337,9 +311,7 @@ esp_err_t esp_ble_gattc_write_char_descr (esp_gatt_if_t gattc_if,
btc_msg_t msg;
btc_ble_gattc_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
@ -368,9 +340,7 @@ esp_err_t esp_ble_gattc_prepare_write(esp_gatt_if_t gattc_if,
btc_msg_t msg;
btc_ble_gattc_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
@ -399,9 +369,7 @@ esp_err_t esp_ble_gattc_prepare_write_char_descr(esp_gatt_if_t gattc_if,
btc_msg_t msg;
btc_ble_gattc_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
@ -423,9 +391,7 @@ esp_err_t esp_ble_gattc_execute_write (esp_gatt_if_t gattc_if, uint16_t conn_id,
btc_msg_t msg;
btc_ble_gattc_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
@ -436,7 +402,7 @@ esp_err_t esp_ble_gattc_execute_write (esp_gatt_if_t gattc_if, uint16_t conn_id,
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_gatt_status_t esp_ble_gattc_register_for_notify (esp_gatt_if_t gattc_if,
esp_err_t esp_ble_gattc_register_for_notify (esp_gatt_if_t gattc_if,
esp_bd_addr_t server_bda,
esp_gatt_srvc_id_t *srvc_id,
esp_gatt_id_t *char_id)
@ -444,9 +410,7 @@ esp_gatt_status_t esp_ble_gattc_register_for_notify (esp_gatt_if_t gattc_if,
btc_msg_t msg;
btc_ble_gattc_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
@ -459,7 +423,7 @@ esp_gatt_status_t esp_ble_gattc_register_for_notify (esp_gatt_if_t gattc_if,
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_gatt_status_t esp_ble_gattc_unregister_for_notify (esp_gatt_if_t gattc_if,
esp_err_t esp_ble_gattc_unregister_for_notify (esp_gatt_if_t gattc_if,
esp_bd_addr_t server_bda,
esp_gatt_srvc_id_t *srvc_id,
esp_gatt_id_t *char_id)
@ -467,9 +431,7 @@ esp_gatt_status_t esp_ble_gattc_unregister_for_notify (esp_gatt_if_t gattc_if,
btc_msg_t msg;
btc_ble_gattc_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
@ -487,9 +449,7 @@ esp_err_t esp_ble_gattc_cache_refresh(esp_bd_addr_t remote_bda)
btc_msg_t msg;
btc_ble_gattc_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;

View File

@ -28,9 +28,8 @@ static esp_err_t esp_ble_gatts_add_char_desc_param_check(esp_attr_value_t *char_
esp_err_t esp_ble_gatts_register_callback(esp_gatts_cb_t callback)
{
if (esp_bluedroid_get_status() == ESP_BLUEDROID_STATUS_UNINITIALIZED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
return (btc_profile_cb_set(BTC_PID_GATTS, callback) == 0 ? ESP_OK : ESP_FAIL);
}
@ -39,9 +38,7 @@ esp_err_t esp_ble_gatts_app_register(uint16_t app_id)
btc_msg_t msg;
btc_ble_gatts_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
//if (app_id < ESP_APP_ID_MIN || app_id > ESP_APP_ID_MAX) {
if (app_id > ESP_APP_ID_MAX) {
@ -62,9 +59,7 @@ esp_err_t esp_ble_gatts_app_unregister(esp_gatt_if_t gatts_if)
btc_msg_t msg;
btc_ble_gatts_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
@ -80,9 +75,7 @@ esp_err_t esp_ble_gatts_create_service(esp_gatt_if_t gatts_if,
btc_msg_t msg;
btc_ble_gatts_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
@ -102,6 +95,8 @@ esp_err_t esp_ble_gatts_create_attr_tab(const esp_gatts_attr_db_t *gatts_attr_db
btc_msg_t msg;
btc_ble_gatts_args_t arg;
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
msg.act = BTC_GATTS_ACT_CREATE_ATTR_TAB;
@ -120,9 +115,7 @@ esp_err_t esp_ble_gatts_add_included_service(uint16_t service_handle, uint16_t i
btc_msg_t msg;
btc_ble_gatts_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
@ -142,9 +135,7 @@ esp_err_t esp_ble_gatts_add_char(uint16_t service_handle, esp_bt_uuid_t *char_
btc_ble_gatts_args_t arg;
esp_err_t status;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
/* parameter validation check */
status = esp_ble_gatts_add_char_desc_param_check(char_val, control);
@ -183,9 +174,7 @@ esp_err_t esp_ble_gatts_add_char_descr (uint16_t service_handle,
btc_ble_gatts_args_t arg;
esp_err_t status;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
/* parameter validation check */
status = esp_ble_gatts_add_char_desc_param_check(char_descr_val, control);
@ -219,9 +208,7 @@ esp_err_t esp_ble_gatts_delete_service(uint16_t service_handle)
btc_msg_t msg;
btc_ble_gatts_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
@ -236,9 +223,7 @@ esp_err_t esp_ble_gatts_start_service(uint16_t service_handle)
btc_msg_t msg;
btc_ble_gatts_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
@ -253,9 +238,7 @@ esp_err_t esp_ble_gatts_stop_service(uint16_t service_handle)
btc_msg_t msg;
btc_ble_gatts_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
@ -272,9 +255,7 @@ esp_err_t esp_ble_gatts_send_indicate(esp_gatt_if_t gatts_if, uint16_t conn_id,
btc_msg_t msg;
btc_ble_gatts_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
@ -295,9 +276,7 @@ esp_err_t esp_ble_gatts_send_response(esp_gatt_if_t gatts_if, uint16_t conn_id,
btc_msg_t msg;
btc_ble_gatts_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
@ -316,6 +295,8 @@ esp_err_t esp_ble_gatts_set_attr_value(uint16_t attr_handle, uint16_t length, co
btc_msg_t msg;
btc_ble_gatts_args_t arg;
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
msg.act = BTC_GATTS_ACT_SET_ATTR_VALUE;
@ -327,13 +308,15 @@ esp_err_t esp_ble_gatts_set_attr_value(uint16_t attr_handle, uint16_t length, co
btc_gatts_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gatts_get_attr_value(uint16_t attr_handle, uint16_t *length, const uint8_t **value)
esp_gatt_status_t esp_ble_gatts_get_attr_value(uint16_t attr_handle, uint16_t *length, const uint8_t **value)
{
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
if (attr_handle == ESP_GATT_ILLEGAL_HANDLE) {
return ESP_FAIL;
return ESP_GATT_INVALID_HANDLE;
}
btc_gatts_get_attr_value(attr_handle, length, (uint8_t **)value);
return ESP_OK;
return btc_gatts_get_attr_value(attr_handle, length, (uint8_t **)value);
}
esp_err_t esp_ble_gatts_open(esp_gatt_if_t gatts_if, esp_bd_addr_t remote_bda, bool is_direct)
@ -341,9 +324,7 @@ esp_err_t esp_ble_gatts_open(esp_gatt_if_t gatts_if, esp_bd_addr_t remote_bda, b
btc_msg_t msg;
btc_ble_gatts_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
@ -361,9 +342,7 @@ esp_err_t esp_ble_gatts_close(esp_gatt_if_t gatts_if, uint16_t conn_id)
btc_msg_t msg;
btc_ble_gatts_args_t arg;
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;

View File

@ -22,6 +22,12 @@
extern "C" {
#endif
#define ESP_BLUEDROID_STATUS_CHECK(status) \
if (esp_bluedroid_get_status() != (status)) { \
return ESP_ERR_INVALID_STATE; \
}
/* relate to BT_STATUS_xxx in bt_def.h */
/// Status Return Value
typedef enum {
@ -44,6 +50,7 @@ typedef enum {
ESP_BT_STATUS_TIMEOUT, /* relate to BT_STATUS_TIMEOUT in bt_def.h */
ESP_BT_STATUS_PEER_LE_DATA_LEN_UNSUPPORTED, /* relate to BTM_PEER_LE_DATA_LEN_UNSUPPORTED in btm_api.h */
ESP_BT_STATUS_CONTROL_LE_DATA_LEN_UNSUPPORTED,/* relate to BTM_CONTROL_LE_DATA_LEN_UNSUPPORTED in btm_api.h */
ESP_BT_STATUS_ERR_ILLEGAL_PARAMETER_FMT, /* relate to HCI_ERR_ILLEGAL_PARAMETER_FMT in hcidefs.h */
} esp_bt_status_t;
@ -107,6 +114,7 @@ typedef enum {
#define ESP_BLE_CSR_KEY_MASK (1 << 2) /* relate to BTM_BLE_CSR_KEY_MASK in btm_api.h */
/// Used to exchange the link key(this key just used in the BLE & BR/EDR coexist mode) in the init key & response key
#define ESP_BLE_LINK_KEY_MASK (1 << 3) /* relate to BTM_BLE_LINK_KEY_MASK in btm_api.h */
typedef uint8_t esp_ble_key_mask_t; /* the key mask type */
/// Minimum of the application id
#define ESP_APP_ID_MIN 0x0000

View File

@ -93,6 +93,9 @@ typedef enum {
ESP_GAP_BLE_SET_STATIC_RAND_ADDR_EVT, /*!< When set the static rand address complete, the event comes */
ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT, /*!< When update connection parameters complete, the event comes */
ESP_GAP_BLE_SET_PKT_LENGTH_COMPLETE_EVT, /*!< When set pkt lenght complete, the event comes */
ESP_GAP_BLE_SET_LOCAL_PRIVACY_COMPLETE_EVT, /*!< When Enable/disable privacy on the local device complete, the event comes */
ESP_GAP_BLE_REMOVE_BOND_DEV_COMPLETE_EVT, /*!< When remove the bond device complete, the event comes */
ESP_GAP_BLE_EVT_MAX,
} esp_gap_ble_cb_event_t;
/// Advertising data maximum length
@ -293,7 +296,7 @@ typedef struct
uint16_t ediv; /*!< The ediv value*/
uint8_t sec_level; /*!< The security level of the security link*/
uint8_t key_size; /*!< The key size(7~16) of the security link*/
}esp_ble_penc_keys_t; /*!< The key type*/
} esp_ble_penc_keys_t; /*!< The key type*/
/**
* @brief BLE CSRK keys
@ -303,7 +306,7 @@ typedef struct
uint32_t counter; /*!< The counter */
esp_bt_octet16_t csrk; /*!< The csrk key */
uint8_t sec_level; /*!< The security level */
}esp_ble_pcsrk_keys_t; /*!< The pcsrk key type */
} esp_ble_pcsrk_keys_t; /*!< The pcsrk key type */
/**
* @brief BLE pid keys
@ -313,7 +316,7 @@ typedef struct
esp_bt_octet16_t irk; /*!< The irk value */
esp_ble_addr_type_t addr_type; /*!< The address type */
esp_bd_addr_t static_addr; /*!< The static address */
}esp_ble_pid_keys_t; /*!< The pid key type */
} esp_ble_pid_keys_t; /*!< The pid key type */
/**
* @brief BLE Encryption reproduction keys
@ -324,7 +327,7 @@ typedef struct
uint16_t div; /*!< The div value */
uint8_t key_size; /*!< The key size of the security link */
uint8_t sec_level; /*!< The security level of the security link */
}esp_ble_lenc_keys_t; /*!< The key type */
} esp_ble_lenc_keys_t; /*!< The key type */
/**
* @brief BLE SRK keys
@ -334,8 +337,8 @@ typedef struct
uint32_t counter; /*!< The counter value */
uint16_t div; /*!< The div value */
uint8_t sec_level; /*!< The security level of the security link */
esp_bt_octet16_t csrk; /*!< The csrk key value */
}esp_ble_lcsrk_keys; /*!< The csrk key type */
esp_bt_octet16_t csrk; /*!< The csrk key value */
} esp_ble_lcsrk_keys; /*!< The csrk key type */
/**
* @brief Structure associated with ESP_KEY_NOTIF_EVT
@ -352,7 +355,7 @@ typedef struct
typedef struct
{
esp_bd_addr_t bd_addr; /*!< peer address */
}esp_ble_sec_req_t; /*!< BLE security request type*/
} esp_ble_sec_req_t; /*!< BLE security request type*/
/**
* @brief union type of the security key value
@ -364,7 +367,27 @@ typedef union
esp_ble_pid_keys_t pid_key; /*!< peer device ID key */
esp_ble_lenc_keys_t lenc_key; /*!< local encryption reproduction keys LTK = = d1(ER,DIV,0)*/
esp_ble_lcsrk_keys lcsrk_key; /*!< local device CSRK = d1(ER,DIV,1)*/
}esp_ble_key_value_t; /*!< ble key value type*/
} esp_ble_key_value_t; /*!< ble key value type*/
/**
* @brief struct type of the bond key informatuon value
*/
typedef struct
{
esp_ble_key_mask_t key_mask; /*!< the key mask to indicate witch key is present */
esp_ble_penc_keys_t penc_key; /*!< received peer encryption key */
esp_ble_pcsrk_keys_t pcsrk_key; /*!< received peer device SRK */
esp_ble_pid_keys_t pid_key; /*!< peer device ID key */
} esp_ble_bond_key_info_t; /*!< ble bond key information value type */
/**
* @brief struct type of the bond device value
*/
typedef struct
{
esp_bd_addr_t bd_addr; /*!< peer address */
esp_ble_bond_key_info_t bond_key; /*!< the bond key information */
} esp_ble_bond_dev_t; /*!< the ble bond device type */
/**
@ -375,7 +398,7 @@ typedef struct
esp_bd_addr_t bd_addr; /*!< peer address */
esp_ble_key_type_t key_type; /*!< key type of the security link */
esp_ble_key_value_t p_key_value; /*!< the pointer to the key value */
}esp_ble_key_t; /*!< the union to the ble key value type*/
} esp_ble_key_t; /*!< the union to the ble key value type*/
/**
* @brief structure type of the ble local id keys value
@ -384,7 +407,7 @@ typedef struct {
esp_bt_octet16_t ir; /*!< the 16 bits of the ir value */
esp_bt_octet16_t irk; /*!< the 16 bits of the ir key value */
esp_bt_octet16_t dhk; /*!< the 16 bits of the dh key value */
}esp_ble_local_id_keys_t; /*!< the structure of the ble local id keys value type*/
} esp_ble_local_id_keys_t; /*!< the structure of the ble local id keys value type*/
/**
@ -400,7 +423,7 @@ typedef struct
uint8_t fail_reason; /*!< The HCI reason/error code for when success=FALSE */
esp_ble_addr_type_t addr_type; /*!< Peer device address type */
esp_bt_dev_type_t dev_type; /*!< Device type */
}esp_ble_auth_cmpl_t; /*!< The ble authentication complite cb type */
} esp_ble_auth_cmpl_t; /*!< The ble authentication complite cb type */
/**
* @brief union associated with ble security
@ -412,7 +435,7 @@ typedef union
esp_ble_key_t ble_key; /*!< BLE SMP keys used when pairing */
esp_ble_local_id_keys_t ble_id_keys; /*!< BLE IR event */
esp_ble_auth_cmpl_t auth_cmpl; /*!< Authentication complete indication. */
}esp_ble_sec_t; /*!< Ble secutity type */
} esp_ble_sec_t; /*!< Ble secutity type */
/// Sub Event of ESP_GAP_BLE_SCAN_RESULT_EVT
typedef enum {
@ -539,6 +562,19 @@ typedef union {
esp_bt_status_t status; /*!< Indicate the set pkt data length operation success status */
esp_ble_pkt_data_length_params_t params; /*!< pkt data length value */
} pkt_data_lenth_cmpl; /*!< Event parameter of ESP_GAP_BLE_SET_PKT_LENGTH_COMPLETE_EVT */
/**
* @brief ESP_GAP_BLE_SET_LOCAL_PRIVACY_COMPLETE_EVT
*/
struct ble_local_privacy_cmpl_evt_param {
esp_bt_status_t status; /*!< Indicate the set local privacy operation success status */
} local_privacy_cmpl; /*!< Event parameter of ESP_GAP_BLE_SET_LOCAL_PRIVACY_COMPLETE_EVT */
/**
* @brief ESP_GAP_BLE_REMOVE_BOND_DEV_COMPLETE_EVT
*/
struct ble_remove_bond_dev_cmpl_evt_param {
esp_bt_status_t status; /*!< Indicate the remove bond device operation success status */
esp_bd_addr_t bd_addr; /*!< The device address which has been remove from the bond list */
}remove_bond_dev_cmpl; /*!< Event parameter of ESP_GAP_BLE_REMOVE_BOND_DEV_COMPLETE_EVT */
} esp_ble_gap_cb_param_t;
/**
@ -814,6 +850,44 @@ esp_err_t esp_ble_passkey_reply(esp_bd_addr_t bd_addr, bool accept, uint32_t pas
*/
esp_err_t esp_ble_confirm_reply(esp_bd_addr_t bd_addr, bool accept);
/**
* @brief Removes a device from the security database list of
* peer device. It manages unpairing event while connected.
*
* @param[in] bd_addr : BD address of the peer device
*
* @return - ESP_OK : success
* - other : failed
*
*/
esp_err_t esp_ble_remove_bond_device(esp_bd_addr_t bd_addr);
/**
* @brief Get the device number from the security database list of peer device.
* It will return the device bonded number immediately.
*
* @return - >= 0 : bonded devices number.
* - < 0 : failed
*
*/
int esp_ble_get_bond_device_num(void);
/**
* @brief Get the device from the security database list of peer device.
* It will return the device bonded information immediately.
* @param[inout] dev_num: Indicate the dev_list array(buffer) size as input.
* If dev_num is large enough, it means the actual number as output.
* Suggest that dev_num value equal to esp_ble_get_bond_device_num().
*
* @param[out] dev_list: an array(buffer) of `esp_ble_bond_dev_t` type. Use for storing the bonded devices address.
* The dev_list should be allocated by who call this API.
* @return - ESP_OK : success
* - other : failed
*
*/
esp_err_t esp_ble_get_bond_device_list(int *dev_num, esp_ble_bond_dev_t *dev_list);
/**
* @brief This function is to disconnect the physical connection of the peer device
*

View File

@ -634,7 +634,7 @@ esp_err_t esp_ble_gattc_execute_write (esp_gatt_if_t gattc_if, uint16_t conn_id,
* - other: failed
*
*/
esp_gatt_status_t esp_ble_gattc_register_for_notify (esp_gatt_if_t gattc_if,
esp_err_t esp_ble_gattc_register_for_notify (esp_gatt_if_t gattc_if,
esp_bd_addr_t server_bda,
esp_gatt_srvc_id_t *srvc_id,
esp_gatt_id_t *char_id);
@ -653,7 +653,7 @@ esp_gatt_status_t esp_ble_gattc_register_for_notify (esp_gatt_if_t gattc_if,
* - other: failed
*
*/
esp_gatt_status_t esp_ble_gattc_unregister_for_notify (esp_gatt_if_t gattc_if,
esp_err_t esp_ble_gattc_unregister_for_notify (esp_gatt_if_t gattc_if,
esp_bd_addr_t server_bda,
esp_gatt_srvc_id_t *srvc_id,
esp_gatt_id_t *char_id);

View File

@ -514,11 +514,11 @@ esp_err_t esp_ble_gatts_set_attr_value(uint16_t attr_handle, uint16_t length, co
* @param[out] value: Pointer to attribute value payload, the value cannot be modified by user
*
* @return
* - ESP_OK : success
* - ESP_GATT_OK : success
* - other : failed
*
*/
esp_err_t esp_ble_gatts_get_attr_value(uint16_t attr_handle, uint16_t *length, const uint8_t **value);
esp_gatt_status_t esp_ble_gatts_get_attr_value(uint16_t attr_handle, uint16_t *length, const uint8_t **value);
/**

View File

@ -4517,13 +4517,6 @@ void bta_dm_ble_set_conn_scan_params (tBTA_DM_MSG *p_data)
*******************************************************************************/
void bta_dm_ble_update_conn_params (tBTA_DM_MSG *p_data)
{
tACL_CONN *p_acl_cb = btm_bda_to_acl(p_data->ble_update_conn_params.bd_addr, BT_TRANSPORT_LE);
if (p_acl_cb == NULL) {
APPL_TRACE_ERROR("%s error: Invalid connection bd_addr.", __func__);
return;
} else {
p_acl_cb->update_conn_param_cb = p_data->ble_update_conn_params.update_conn_param_cb;
}
if (!L2CA_UpdateBleConnParams(p_data->ble_update_conn_params.bd_addr,
p_data->ble_update_conn_params.min_int,
p_data->ble_update_conn_params.max_int,
@ -4601,7 +4594,7 @@ void bta_dm_ble_stop_advertising(tBTA_DM_MSG *p_data)
*******************************************************************************/
void bta_dm_ble_config_local_privacy (tBTA_DM_MSG *p_data)
{
BTM_BleConfigPrivacy (p_data->ble_local_privacy.privacy_enable);
BTM_BleConfigPrivacy (p_data->ble_local_privacy.privacy_enable, p_data->ble_local_privacy.set_local_privacy_cback);
}
#endif

View File

@ -1575,7 +1575,7 @@ void BTA_DmBleUpdateConnectionParam(BD_ADDR bd_addr, UINT16 min_int,
** Returns void
**
*******************************************************************************/
void BTA_DmBleConfigLocalPrivacy(BOOLEAN privacy_enable)
void BTA_DmBleConfigLocalPrivacy(BOOLEAN privacy_enable, tBTA_SET_LOCAL_PRIVACY_CBACK *set_local_privacy_cback)
{
///This function used the irk to generate the resolve address
#if BLE_INCLUDED == TRUE && BLE_PRIVACY_SPT == TRUE
@ -1586,7 +1586,7 @@ void BTA_DmBleConfigLocalPrivacy(BOOLEAN privacy_enable)
p_msg->hdr.event = BTA_DM_API_LOCAL_PRIVACY_EVT;
p_msg->privacy_enable = privacy_enable;
p_msg->set_local_privacy_cback = set_local_privacy_cback;
bta_sys_sendmsg(p_msg);
}
#else
@ -1991,7 +1991,7 @@ void BTA_DmEnableScanFilter(UINT8 action, tBTA_DM_BLE_PF_STATUS_CBACK *p_cmpl_cb
**
*******************************************************************************/
void BTA_DmBleUpdateConnectionParams(BD_ADDR bd_addr, UINT16 min_int, UINT16 max_int,
UINT16 latency, UINT16 timeout, tBTA_UPDATE_CONN_PARAM_CBACK *update_conn_param_cb)
UINT16 latency, UINT16 timeout)
{
tBTA_DM_API_UPDATE_CONN_PARAM *p_msg;
@ -2004,7 +2004,6 @@ void BTA_DmBleUpdateConnectionParams(BD_ADDR bd_addr, UINT16 min_int, UINT16 max
p_msg->max_int = max_int;
p_msg->latency = latency;
p_msg->timeout = timeout;
p_msg->update_conn_param_cb = update_conn_param_cb;
bta_sys_sendmsg(p_msg);
}
}

View File

@ -444,6 +444,7 @@ typedef struct {
typedef struct {
BT_HDR hdr;
BOOLEAN privacy_enable;
tBTA_SET_LOCAL_PRIVACY_CBACK *set_local_privacy_cback;
} tBTA_DM_API_LOCAL_PRIVACY;
/* set scan parameter for BLE connections */
@ -644,7 +645,6 @@ typedef struct {
UINT16 max_int;
UINT16 latency;
UINT16 timeout;
tBTA_UPDATE_CONN_PARAM_CBACK *update_conn_param_cb;
} tBTA_DM_API_UPDATE_CONN_PARAM;
#if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE

View File

@ -33,6 +33,7 @@
#include "bta_gattc_int.h"
#include "l2c_api.h"
#include "l2c_int.h"
#include "gatt_int.h"
#if (defined BTA_HH_LE_INCLUDED && BTA_HH_LE_INCLUDED == TRUE)
#include "bta_hh_int.h"
@ -860,9 +861,6 @@ void bta_gattc_set_discover_st(tBTA_GATTC_SERV *p_srcb)
tBTA_GATTC_CB *p_cb = &bta_gattc_cb;
UINT8 i;
#if BLE_INCLUDED == TRUE
L2CA_EnableUpdateBleConnParams(p_srcb->server_bda, FALSE);
#endif
for (i = 0; i < BTA_GATTC_CLCB_MAX; i ++) {
if (p_cb->clcb[i].p_srcb == p_srcb) {
p_cb->clcb[i].status = BTA_GATT_OK;
@ -992,11 +990,6 @@ void bta_gattc_disc_cmpl(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
APPL_TRACE_DEBUG("bta_gattc_disc_cmpl conn_id=%d", p_clcb->bta_conn_id);
#if BLE_INCLUDED == TRUE
if (p_clcb->transport == BTA_TRANSPORT_LE) {
L2CA_EnableUpdateBleConnParams(p_clcb->p_srcb->server_bda, TRUE);
}
#endif
p_clcb->p_srcb->state = BTA_GATTC_SERV_IDLE;
p_clcb->disc_active = FALSE;
@ -2410,7 +2403,12 @@ tBTA_GATTC_FIND_SERVICE_CB bta_gattc_register_service_change_notify(UINT16 conn_
ccc_value.len = 2;
ccc_value.value[0] = GATT_CLT_CONFIG_INDICATION;
ccc_value.auth_req = GATT_AUTH_REQ_NONE;
write_status = GATTC_Write (conn_id, GATT_WRITE, &ccc_value);
if (gatt_is_clcb_allocated(conn_id)) {
APPL_TRACE_DEBUG("%s, GATTC_Write GATT_BUSY conn_id = %d", __func__, conn_id);
write_status = GATT_BUSY;
} else {
write_status = GATTC_Write (conn_id, GATT_WRITE, &ccc_value);
}
if (write_status != GATT_SUCCESS) {
start_find_ccc_timer = TRUE;
result = SERVICE_CHANGE_WRITE_CCC_FAILED;

View File

@ -36,6 +36,7 @@
#include "bta_gattc_int.h"
#include "btm_api.h"
#include "btm_ble_api.h"
#include "l2c_api.h"
#define LOG_TAG "bt_bta_gattc"
// #include "osi/include/log.h"
@ -588,6 +589,13 @@ static void bta_gattc_explore_srvc(UINT16 conn_id, tBTA_GATTC_SERV *p_srvc_cb)
#if (defined BTA_GATT_DEBUG && BTA_GATT_DEBUG == TRUE)
bta_gattc_display_cache_server(p_srvc_cb->p_srvc_cache);
#endif
//server discover end, update connection parameters
#if BLE_INCLUDED == TRUE
if (p_clcb->transport == BTA_TRANSPORT_LE) {
L2CA_EnableUpdateBleConnParams(p_clcb->p_srcb->server_bda, TRUE);
}
#endif
/* save cache to NV */
p_clcb->p_srcb->state = BTA_GATTC_SERV_SAVE;
bta_gattc_co_cache_open(p_srvc_cb->server_bda, BTA_GATTC_CI_CACHE_OPEN_EVT,

View File

@ -506,7 +506,7 @@ void bta_gatts_set_attr_value(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_
UINT16 service_id = p_srvc_cb->service_id;
tBTA_GATTS cb_data;
tBTA_GATT_STATUS gatts_status;
gatts_status = GATTS_SetAttributeValue(p_msg->api_add_char_descr.hdr.layer_specific,
gatts_status = GATTS_SetAttributeValue(p_msg->api_set_val.hdr.layer_specific,
p_msg->api_set_val.length,
p_msg->api_set_val.value);
@ -515,14 +515,19 @@ void bta_gatts_set_attr_value(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_
cb_data.attr_val.attr_id = p_msg->api_set_val.hdr.layer_specific;
cb_data.attr_val.status = gatts_status;
if (p_msg->api_set_val.value != NULL){
GKI_freebuf(p_msg->api_set_val.value);
}
if (p_rcb->p_cback) {
(*p_rcb->p_cback)(BTA_GATTS_SET_ATTR_VAL_EVT, &cb_data);
}
}
void bta_gatts_get_attr_value(UINT16 attr_handle, UINT16 *length, UINT8 **value)
tGATT_STATUS bta_gatts_get_attr_value(UINT16 attr_handle, UINT16 *length, UINT8 **value)
{
GATTS_GetAttributeValue(attr_handle, length, value);
return GATTS_GetAttributeValue(attr_handle, length, value);
}
/*******************************************************************************

View File

@ -490,9 +490,9 @@ void BTA_SetAttributeValue(UINT16 attr_handle, UINT16 length, UINT8 *value)
}
void BTA_GetAttributeValue(UINT16 attr_handle, UINT16 *length, UINT8 **value)
tBTA_GATT_STATUS BTA_GetAttributeValue(UINT16 attr_handle, UINT16 *length, UINT8 **value)
{
bta_gatts_get_attr_value(attr_handle, length, value);
return bta_gatts_get_attr_value(attr_handle, length, value);
}
/*******************************************************************************

View File

@ -404,6 +404,8 @@ typedef void (tBTA_START_ADV_CMPL_CBACK) (tBTA_STATUS status);
typedef tBTM_SET_PKT_DATA_LENGTH_CBACK tBTA_SET_PKT_DATA_LENGTH_CBACK;
typedef tBTM_SET_LOCAL_PRIVACY_CBACK tBTA_SET_LOCAL_PRIVACY_CBACK;
/* advertising channel map */
#define BTA_BLE_ADV_CHNL_37 BTM_BLE_ADV_CHNL_37
#define BTA_BLE_ADV_CHNL_38 BTM_BLE_ADV_CHNL_38
@ -2035,11 +2037,11 @@ extern void BTA_DmSetRandAddress(BD_ADDR rand_addr);
** Description Enable/disable privacy on the local device
**
** Parameters: privacy_enable - enable/disabe privacy on remote device.
**
** set_local_privacy_cback -callback to be called with result
** Returns void
**
*******************************************************************************/
extern void BTA_DmBleConfigLocalPrivacy(BOOLEAN privacy_enable);
extern void BTA_DmBleConfigLocalPrivacy(BOOLEAN privacy_enable, tBTA_SET_LOCAL_PRIVACY_CBACK *set_local_privacy_cback);
/*******************************************************************************
**
@ -2208,7 +2210,7 @@ extern void BTA_BleDisableAdvInstance(UINT8 inst_id);
**
*******************************************************************************/
extern void BTA_DmBleUpdateConnectionParams(BD_ADDR bd_addr, UINT16 min_int,
UINT16 max_int, UINT16 latency, UINT16 timeout, tBTA_UPDATE_CONN_PARAM_CBACK *update_conn_param_cb);
UINT16 max_int, UINT16 latency, UINT16 timeout);
/*******************************************************************************
**

View File

@ -1409,10 +1409,10 @@ extern void BTA_SetAttributeValue(UINT16 attr_handle, UINT16 length, UINT8 *valu
** length - the value length which has been set to the attribute.
** value - the pointer to the value
**
** Returns None
** Returns tBTA_GATT_STATUS
**
*******************************************************************************/
extern void BTA_GetAttributeValue(UINT16 attr_handle, UINT16 *length, UINT8 **value);
extern tBTA_GATT_STATUS BTA_GetAttributeValue(UINT16 attr_handle, UINT16 *length, UINT8 **value);
/*******************************************************************************
**

View File

@ -81,7 +81,11 @@ typedef UINT16 tBTA_GATTC_INT_EVT;
/* max known devices GATTC can support */
#ifndef BTA_GATTC_KNOWN_SR_MAX
#define BTA_GATTC_KNOWN_SR_MAX 3 // 10
#if (GATT_MAX_PHY_CHANNEL > 3)
#define BTA_GATTC_KNOWN_SR_MAX GATT_MAX_PHY_CHANNEL
#else
#define BTA_GATTC_KNOWN_SR_MAX 3 // The origin value is 10
#endif
#endif
#define BTA_GATTC_CONN_MAX GATT_MAX_PHY_CHANNEL

View File

@ -230,7 +230,7 @@ extern void bta_gatts_add_include_srvc(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS
extern void bta_gatts_add_char(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_msg);
extern void bta_gatts_add_char_descr(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_msg);
extern void bta_gatts_set_attr_value(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_msg);
extern void bta_gatts_get_attr_value(UINT16 attr_handle, UINT16 *length, UINT8 **value);
extern tGATT_STATUS bta_gatts_get_attr_value(UINT16 attr_handle, UINT16 *length, UINT8 **value);
extern void bta_gatts_delete_service(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_msg);
extern void bta_gatts_start_service(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_msg);
extern void bta_gatts_stop_service(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_msg);

File diff suppressed because it is too large Load Diff

View File

@ -31,53 +31,39 @@
static const char *CONFIG_FILE_PATH = "bt_config.conf";
static const period_ms_t CONFIG_SETTLE_PERIOD_MS = 3000;
static void timer_config_save(void *data);
// TODO(zachoverflow): Move these two functions out, because they are too specific for this file
// {grumpy-cat/no, monty-python/you-make-me-sad}
bool btc_get_device_type(const BD_ADDR bd_addr, int *p_device_type)
{
if (p_device_type == NULL) {
return FALSE;
}
bt_bdaddr_t bda;
bdcpy(bda.address, bd_addr);
bdstr_t bd_addr_str;
bdaddr_to_string(&bda, bd_addr_str, sizeof(bd_addr_str));
if (!btc_config_get_int(bd_addr_str, "DevType", p_device_type)) {
return FALSE;
}
LOG_DEBUG("%s: Device [%s] type %d\n", __FUNCTION__, bd_addr_str, *p_device_type);
return TRUE;
}
bool btc_get_address_type(const BD_ADDR bd_addr, int *p_addr_type)
{
if (p_addr_type == NULL) {
return FALSE;
}
bt_bdaddr_t bda;
bdcpy(bda.address, bd_addr);
bdstr_t bd_addr_str;
bdaddr_to_string(&bda, bd_addr_str, sizeof(bd_addr_str));
if (!btc_config_get_int(bd_addr_str, "AddrType", p_addr_type)) {
return FALSE;
}
LOG_DEBUG("%s: Device [%s] address type %d\n", __FUNCTION__, bd_addr_str, *p_addr_type);
return TRUE;
}
static void btc_key_value_to_string(uint8_t *key_vaule, char *value_str, int key_length);
static pthread_mutex_t lock; // protects operations on |config|.
static config_t *config;
static osi_alarm_t *alarm_timer;
bool btc_compare_address_key_value(const char *section, char *key_type, void *key_value, int key_length)
{
assert(key_value != NULL);
bool status = false;
char value_str[100] = {0};
if(key_length > sizeof(value_str)/2) {
return false;
}
btc_key_value_to_string((uint8_t *)key_value, value_str, key_length);
if ((status = config_has_key_in_section(config, key_type, value_str)) == true) {
config_remove_section(config, section);
}
return status;
}
static void btc_key_value_to_string(uint8_t *key_vaule, char *value_str, int key_length)
{
const char *lookup = "0123456789abcdef";
assert(key_vaule != NULL);
assert(value_str != NULL);
for (size_t i = 0; i < key_length; ++i) {
value_str[(i * 2) + 0] = lookup[(key_vaule[i] >> 4) & 0x0F];
value_str[(i * 2) + 1] = lookup[key_vaule[i] & 0x0F];
}
return;
}
// Module lifecycle functions
@ -93,27 +79,15 @@ bool btc_config_init(void)
goto error;
}
}
if (config_save(config, CONFIG_FILE_PATH)) {
// unlink(LEGACY_CONFIG_FILE_PATH);
}
// TODO(sharvil): use a non-wake alarm for this once we have
// API support for it. There's no need to wake the system to
// write back to disk.
alarm_timer = osi_alarm_new("btc_config", timer_config_save, NULL, CONFIG_SETTLE_PERIOD_MS);
if (!alarm_timer) {
LOG_ERROR("%s unable to create alarm.\n", __func__);
goto error;
}
return true;
error:;
osi_alarm_free(alarm_timer);
config_free(config);
pthread_mutex_destroy(&lock);
alarm_timer = NULL;
config = NULL;
LOG_ERROR("%s failed\n", __func__);
return false;
@ -129,10 +103,8 @@ bool btc_config_clean_up(void)
{
btc_config_flush();
osi_alarm_free(alarm_timer);
config_free(config);
pthread_mutex_destroy(&lock);
alarm_timer = NULL;
config = NULL;
return true;
}
@ -142,11 +114,7 @@ bool btc_config_has_section(const char *section)
assert(config != NULL);
assert(section != NULL);
pthread_mutex_lock(&lock);
bool ret = config_has_section(config, section);
pthread_mutex_unlock(&lock);
return ret;
return config_has_section(config, section);
}
bool btc_config_exist(const char *section, const char *key)
@ -155,11 +123,7 @@ bool btc_config_exist(const char *section, const char *key)
assert(section != NULL);
assert(key != NULL);
pthread_mutex_lock(&lock);
bool ret = config_has_key(config, section, key);
pthread_mutex_unlock(&lock);
return ret;
return config_has_key(config, section, key);
}
bool btc_config_get_int(const char *section, const char *key, int *value)
@ -169,12 +133,10 @@ bool btc_config_get_int(const char *section, const char *key, int *value)
assert(key != NULL);
assert(value != NULL);
pthread_mutex_lock(&lock);
bool ret = config_has_key(config, section, key);
if (ret) {
*value = config_get_int(config, section, key, *value);
}
pthread_mutex_unlock(&lock);
return ret;
}
@ -185,9 +147,7 @@ bool btc_config_set_int(const char *section, const char *key, int value)
assert(section != NULL);
assert(key != NULL);
pthread_mutex_lock(&lock);
config_set_int(config, section, key, value);
pthread_mutex_unlock(&lock);
return true;
}
@ -200,9 +160,7 @@ bool btc_config_get_str(const char *section, const char *key, char *value, int *
assert(value != NULL);
assert(size_bytes != NULL);
pthread_mutex_lock(&lock);
const char *stored_value = config_get_string(config, section, key, NULL);
pthread_mutex_unlock(&lock);
if (!stored_value) {
return false;
@ -221,9 +179,7 @@ bool btc_config_set_str(const char *section, const char *key, const char *value)
assert(key != NULL);
assert(value != NULL);
pthread_mutex_lock(&lock);
config_set_string(config, section, key, value, false);
pthread_mutex_unlock(&lock);
return true;
}
@ -236,9 +192,7 @@ bool btc_config_get_bin(const char *section, const char *key, uint8_t *value, si
assert(value != NULL);
assert(length != NULL);
pthread_mutex_lock(&lock);
const char *value_str = config_get_string(config, section, key, NULL);
pthread_mutex_unlock(&lock);
if (!value_str) {
return false;
@ -269,9 +223,7 @@ size_t btc_config_get_bin_length(const char *section, const char *key)
assert(section != NULL);
assert(key != NULL);
pthread_mutex_lock(&lock);
const char *value_str = config_get_string(config, section, key, NULL);
pthread_mutex_unlock(&lock);
if (!value_str) {
return 0;
@ -303,9 +255,7 @@ bool btc_config_set_bin(const char *section, const char *key, const uint8_t *val
str[(i * 2) + 1] = lookup[value[i] & 0x0F];
}
pthread_mutex_lock(&lock);
config_set_string(config, section, key, str, false);
pthread_mutex_unlock(&lock);
osi_free(str);
return true;
@ -337,103 +287,54 @@ const char *btc_config_section_name(const btc_config_section_iter_t *section)
return config_section_name((const config_section_node_t *)section);
}
bool btc_config_remove(const char *section, const char *key)
{
assert(config != NULL);
assert(section != NULL);
assert(key != NULL);
pthread_mutex_lock(&lock);
bool ret = config_remove_key(config, section, key);
pthread_mutex_unlock(&lock);
return ret;
return config_remove_key(config, section, key);
}
void btc_config_save(void)
bool btc_config_remove_section(const char *section)
{
assert(alarm_timer != NULL);
assert(config != NULL);
assert(section != NULL);
osi_alarm_set(alarm_timer, CONFIG_SETTLE_PERIOD_MS);
return config_remove_section(config, section);
}
void btc_config_flush(void)
{
assert(config != NULL);
assert(alarm_timer != NULL);
osi_alarm_cancel(alarm_timer);
pthread_mutex_lock(&lock);
config_save(config, CONFIG_FILE_PATH);
pthread_mutex_unlock(&lock);
}
int btc_config_clear(void)
{
assert(config != NULL);
assert(alarm_timer != NULL);
osi_alarm_cancel(alarm_timer);
pthread_mutex_lock(&lock);
config_free(config);
config = config_new_empty();
if (config == NULL) {
pthread_mutex_unlock(&lock);
return false;
}
int ret = config_save(config, CONFIG_FILE_PATH);
pthread_mutex_unlock(&lock);
return ret;
}
static void timer_config_save(UNUSED_ATTR void *data)
void btc_config_lock(void)
{
assert(config != NULL);
assert(alarm_timer != NULL);
// Garbage collection process: the config file accumulates
// cached information about remote devices during regular
// inquiry scans. We remove some of these junk entries
// so the file doesn't grow indefinitely. We have to take care
// to make sure we don't remove information about bonded
// devices (hence the check for link keys).
static const size_t CACHE_MAX = 256;
const char *keys[CACHE_MAX];
size_t num_keys = 0;
size_t total_candidates = 0;
pthread_mutex_lock(&lock);
for (const config_section_node_t *snode = config_section_begin(config); snode != config_section_end(config); snode = config_section_next(snode)) {
const char *section = config_section_name(snode);
if (!string_is_bdaddr(section)) {
continue;
}
}
if (config_has_key(config, section, "LinkKey") ||
config_has_key(config, section, "LE_KEY_PENC") ||
config_has_key(config, section, "LE_KEY_PID") ||
config_has_key(config, section, "LE_KEY_PCSRK") ||
config_has_key(config, section, "LE_KEY_LENC") ||
config_has_key(config, section, "LE_KEY_LCSRK")) {
continue;
}
if (num_keys < CACHE_MAX) {
keys[num_keys++] = section;
}
++total_candidates;
}
if (total_candidates > CACHE_MAX * 2)
while (num_keys > 0) {
config_remove_section(config, keys[--num_keys]);
}
config_save(config, CONFIG_FILE_PATH);
void btc_config_unlock(void)
{
pthread_mutex_unlock(&lock);
}

View File

@ -23,6 +23,7 @@
#include "btc_storage.h"
#include "btc_ble_storage.h"
#include "esp_gap_ble_api.h"
#include "btm_int.h"
#include "bta_api.h"
#include "bta_gatt_api.h"
@ -36,6 +37,11 @@
** Static variables
******************************************************************************/
static tBTA_SERVICE_MASK btc_enabled_services = 0;
#if (SMP_INCLUDED == TRUE)
static btc_dm_pairing_cb_t pairing_cb;
static btc_dm_local_key_cb_t ble_local_key_cb;
#endif
/******************************************************************************
** Static functions
******************************************************************************/
@ -115,21 +121,138 @@ static void btc_disable_bluetooth_evt(void)
}
#if (SMP_INCLUDED == TRUE)
void btc_dm_load_ble_local_keys(void)
{
memset(&ble_local_key_cb, 0, sizeof(btc_dm_local_key_cb_t));
if (btc_storage_get_ble_local_key(BTC_LE_LOCAL_KEY_ER,(char*)&ble_local_key_cb.er[0],
BT_OCTET16_LEN)== BT_STATUS_SUCCESS) {
ble_local_key_cb.is_er_rcvd = TRUE;
LOG_DEBUG("%s BLE ER key loaded",__func__ );
}
if ((btc_storage_get_ble_local_key(BTC_LE_LOCAL_KEY_IR,(char*)&ble_local_key_cb.id_keys.ir[0],
BT_OCTET16_LEN)== BT_STATUS_SUCCESS )&&
(btc_storage_get_ble_local_key(BTC_LE_LOCAL_KEY_IRK, (char*)&ble_local_key_cb.id_keys.irk[0],
BT_OCTET16_LEN)== BT_STATUS_SUCCESS)&&
(btc_storage_get_ble_local_key(BTC_LE_LOCAL_KEY_DHK,(char*)&ble_local_key_cb.id_keys.dhk[0],
BT_OCTET16_LEN)== BT_STATUS_SUCCESS)) {
ble_local_key_cb.is_id_keys_rcvd = TRUE;
LOG_DEBUG("%s BLE ID keys loaded", __func__);
}
}
void btc_dm_get_ble_local_keys(tBTA_DM_BLE_LOCAL_KEY_MASK *p_key_mask, BT_OCTET16 er,
tBTA_BLE_LOCAL_ID_KEYS *p_id_keys)
{
if (ble_local_key_cb.is_er_rcvd ) {
memcpy(&er[0], &ble_local_key_cb.er[0], sizeof(BT_OCTET16));
*p_key_mask |= BTA_BLE_LOCAL_KEY_TYPE_ER;
}
if (ble_local_key_cb.is_id_keys_rcvd) {
memcpy(&p_id_keys->ir[0], &ble_local_key_cb.id_keys.ir[0], sizeof(BT_OCTET16));
memcpy(&p_id_keys->irk[0], &ble_local_key_cb.id_keys.irk[0], sizeof(BT_OCTET16));
memcpy(&p_id_keys->dhk[0], &ble_local_key_cb.id_keys.dhk[0], sizeof(BT_OCTET16));
*p_key_mask |= BTA_BLE_LOCAL_KEY_TYPE_ID;
}
LOG_DEBUG("%s *p_key_mask=0x%02x",__func__, *p_key_mask);
}
static void btc_dm_remove_ble_bonding_keys(void)
{
bt_bdaddr_t bd_addr;
LOG_DEBUG("%s\n",__func__);
bdcpy(bd_addr.address, pairing_cb.bd_addr);
btc_storage_remove_remote_addr_type(&bd_addr, false);
btc_storage_remove_ble_dev_type(&bd_addr, false);
btc_storage_remove_ble_bonding_keys(&bd_addr);
}
static void btc_dm_save_ble_bonding_keys(void)
{
bt_bdaddr_t bd_addr;
bdcpy(bd_addr.address, pairing_cb.bd_addr);
btc_storage_set_ble_dev_type(&bd_addr, false);
LOG_DEBUG("%s, penc = %d, pid = %d", __func__, pairing_cb.ble.is_penc_key_rcvd, pairing_cb.ble.is_pid_key_rcvd);
if (pairing_cb.ble.is_penc_key_rcvd) {
btc_storage_add_ble_bonding_key(&bd_addr,
(char *) &pairing_cb.ble.penc_key,
BTM_LE_KEY_PENC,
sizeof(tBTM_LE_PENC_KEYS));
}
if (pairing_cb.ble.is_pid_key_rcvd) {
btc_storage_add_ble_bonding_key(&bd_addr,
(char *) &pairing_cb.ble.pid_key,
BTM_LE_KEY_PID,
sizeof(tBTM_LE_PID_KEYS));
}
if (pairing_cb.ble.is_pcsrk_key_rcvd) {
btc_storage_add_ble_bonding_key(&bd_addr,
(char *) &pairing_cb.ble.pcsrk_key,
BTM_LE_KEY_PCSRK,
sizeof(tBTM_LE_PCSRK_KEYS));
}
if (pairing_cb.ble.is_lenc_key_rcvd) {
btc_storage_add_ble_bonding_key(&bd_addr,
(char *) &pairing_cb.ble.lenc_key,
BTM_LE_KEY_LENC,
sizeof(tBTM_LE_LENC_KEYS));
}
if (pairing_cb.ble.is_lcsrk_key_rcvd) {
btc_storage_add_ble_bonding_key(&bd_addr,
(char *) &pairing_cb.ble.lcsrk_key,
BTM_LE_KEY_LCSRK,
sizeof(tBTM_LE_LCSRK_KEYS));
}
if (pairing_cb.ble.is_lidk_key_rcvd) {
btc_storage_add_ble_bonding_key(&bd_addr,
NULL,
BTM_LE_KEY_LID,
0);
}
}
static void btc_dm_ble_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl)
{
/* Save link key, if not temporary */
LOG_DEBUG("%s, status = %d", __func__, p_auth_cmpl->success);
bt_status_t status = BT_STATUS_FAIL;
int addr_type;
bt_bdaddr_t bdaddr;
bdcpy(bdaddr.address, p_auth_cmpl->bd_addr);
bdcpy(pairing_cb.bd_addr, p_auth_cmpl->bd_addr);
if (p_auth_cmpl->success) {
status = BT_STATUS_SUCCESS;
int addr_type;
bt_bdaddr_t bdaddr;
bdcpy(bdaddr.address, p_auth_cmpl->bd_addr);
bdcpy(pairing_cb.bd_addr, p_auth_cmpl->bd_addr);
LOG_DEBUG ("%s, - p_auth_cmpl->bd_addr: %08x%04x", __func__,
(p_auth_cmpl->bd_addr[0] << 24) + (p_auth_cmpl->bd_addr[1] << 16) + (p_auth_cmpl->bd_addr[2] << 8) + p_auth_cmpl->bd_addr[3],
(p_auth_cmpl->bd_addr[4] << 8) + p_auth_cmpl->bd_addr[5]);
LOG_DEBUG ("%s, - pairing_cb.bd_addr: %08x%04x", __func__,
(pairing_cb.bd_addr[0] << 24) + (pairing_cb.bd_addr[1] << 16) + (pairing_cb.bd_addr[2] << 8) + pairing_cb.bd_addr[3],
(pairing_cb.bd_addr[4] << 8) + pairing_cb.bd_addr[5]);
if (btc_storage_get_remote_addr_type(&bdaddr, &addr_type) != BT_STATUS_SUCCESS) {
btc_storage_set_remote_addr_type(&bdaddr, p_auth_cmpl->addr_type);
btc_storage_set_remote_addr_type(&bdaddr, p_auth_cmpl->addr_type, true);
}
btc_save_ble_bonding_keys();
/* check the irk has been save in the flash or not, if the irk has already save, means that the peer device has bonding
before. */
if(pairing_cb.ble.is_pid_key_rcvd) {
btc_storage_compare_address_key_value(&bdaddr, BTM_LE_KEY_PID,
(void *)&pairing_cb.ble.pid_key, sizeof(tBTM_LE_PID_KEYS));
}
btc_dm_save_ble_bonding_keys();
} else {
/*Map the HCI fail reason to bt status */
switch (p_auth_cmpl->fail_reason) {
@ -310,8 +433,8 @@ void btc_dm_sec_cb_handler(btc_msg_t *msg)
btc_clear_services_mask();
btc_storage_load_bonded_devices();
#if (SMP_INCLUDED == TRUE)
//load the ble local key whitch has been store in the flash
btc_dm_load_ble_local_keys();
//load the bonding device to the btm layer
btc_storage_load_bonded_ble_devices();
#endif ///SMP_INCLUDED == TRUE
btc_enable_bluetooth_evt(p_data->enable.status);
break;
@ -335,8 +458,24 @@ void btc_dm_sec_cb_handler(btc_msg_t *msg)
case BTA_DM_BOND_CANCEL_CMPL_EVT:
case BTA_DM_SP_CFM_REQ_EVT:
case BTA_DM_SP_KEY_NOTIF_EVT:
case BTA_DM_DEV_UNPAIRED_EVT:
break;
case BTA_DM_DEV_UNPAIRED_EVT: {
#if (SMP_INCLUDED)
bt_bdaddr_t bd_addr;
rsp_app = true;
LOG_ERROR("BTA_DM_DEV_UNPAIRED_EVT");
memcpy(bd_addr.address, p_data->link_down.bd_addr, sizeof(BD_ADDR));
btm_set_bond_type_dev(p_data->link_down.bd_addr, BOND_TYPE_UNKNOWN);
//remove the bonded key in the config and nvs flash.
btc_storage_remove_ble_dev_type(&bd_addr, false);
btc_storage_remove_remote_addr_type(&bd_addr, false);
btc_storage_remove_ble_bonding_keys(&bd_addr);
ble_msg.act = ESP_GAP_BLE_REMOVE_BOND_DEV_COMPLETE_EVT;
param.remove_bond_dev_cmpl.status = (p_data->link_down.status == HCI_SUCCESS) ? ESP_BT_STATUS_SUCCESS : ESP_BT_STATUS_FAIL;
memcpy(param.remove_bond_dev_cmpl.bd_addr, p_data->link_down.bd_addr, sizeof(BD_ADDR));
#endif /* #if (SMP_INCLUDED) */
break;
}
case BTA_DM_BUSY_LEVEL_EVT:
case BTA_DM_LINK_UP_EVT:
case BTA_DM_LINK_DOWN_EVT:

View File

@ -19,6 +19,7 @@
#include "esp_err.h"
#include "btc_config.h"
#include "alarm.h"
#include "btc_ble_storage.h"
static future_t *main_future[BTC_MAIN_FUTURE_NUM];
@ -54,8 +55,12 @@ static void btc_init_bluetooth(void)
{
osi_alarm_create_mux();
osi_alarm_init();
btc_config_init();
bte_main_boot_entry(btc_init_callback);
btc_config_init();
#if (SMP_INCLUDED)
//load the ble local key whitch has been store in the flash
btc_dm_load_ble_local_keys();
#endif /* #if (SMP_INCLUDED) */
}

View File

@ -43,11 +43,14 @@ bt_status_t btc_storage_add_bonded_device(bt_bdaddr_t *remote_bd_addr,
bdaddr_to_string(remote_bd_addr, bdstr, sizeof(bdstr));
LOG_DEBUG("add to storage: Remote device:%s\n", bdstr);
int ret = btc_config_set_int(bdstr, "LinkKeyType", (int)key_type);
ret &= btc_config_set_int(bdstr, "PinLength", (int)pin_length);
ret &= btc_config_set_bin(bdstr, "LinkKey", link_key, sizeof(LINK_KEY));
btc_config_lock();
int ret = btc_config_set_int(bdstr, BTC_STORAGE_LINK_KEY_TYPE_STR, (int)key_type);
ret &= btc_config_set_int(bdstr, BTC_STORAGE_PIN_LENGTH_STR, (int)pin_length);
ret &= btc_config_set_bin(bdstr, BTC_STORAGE_LINK_KEY_STR, link_key, sizeof(LINK_KEY));
/* write bonded info immediately */
btc_config_flush();
btc_config_unlock();
LOG_DEBUG("Storage add rslt %d\n", ret);
return ret ? BT_STATUS_SUCCESS : BT_STATUS_FAIL;
}
@ -66,6 +69,7 @@ static bt_status_t btc_in_fetch_bonded_devices(int add)
{
BOOLEAN bt_linkkey_file_found = FALSE;
btc_config_lock();
for (const btc_config_section_iter_t *iter = btc_config_section_begin(); iter != btc_config_section_end(); iter = btc_config_section_next(iter)) {
const char *name = btc_config_section_name(iter);
if (!string_is_bdaddr(name)) {
@ -75,21 +79,19 @@ static bt_status_t btc_in_fetch_bonded_devices(int add)
LOG_DEBUG("Remote device:%s\n", name);
LINK_KEY link_key;
size_t size = sizeof(link_key);
if (btc_config_get_bin(name, "LinkKey", link_key, &size)) {
if (btc_config_get_bin(name, BTC_STORAGE_LINK_KEY_STR, link_key, &size)) {
int linkkey_type;
if (btc_config_get_int(name, "LinkKeyType", &linkkey_type)) {
//int pin_len;
//btc_config_get_int(name, "PinLength", &pin_len))
if (btc_config_get_int(name, BTC_STORAGE_LINK_KEY_TYPE_STR, &linkkey_type)) {
bt_bdaddr_t bd_addr;
string_to_bdaddr(name, &bd_addr);
if (add) {
DEV_CLASS dev_class = {0, 0, 0};
int cod;
int pin_length = 0;
if (btc_config_get_int(name, "DevClass", &cod)) {
if (btc_config_get_int(name, BTC_STORAGE_DEV_CLASS_STR, &cod)) {
uint2devclass((UINT32)cod, dev_class);
}
btc_config_get_int(name, "PinLength", &pin_length);
btc_config_get_int(name, BTC_STORAGE_PIN_LENGTH_STR, &pin_length);
#if (SMP_INCLUDED == TRUE)
BTA_DmAddDevice(bd_addr.address, dev_class, link_key, 0, 0,
(UINT8)linkkey_type, 0, pin_length);
@ -104,6 +106,8 @@ static bt_status_t btc_in_fetch_bonded_devices(int add)
LOG_DEBUG("Remote device:%s, no link key\n", name);
}
}
btc_config_unlock();
return BT_STATUS_SUCCESS;
}
@ -142,19 +146,22 @@ bt_status_t btc_storage_remove_bonded_device(bt_bdaddr_t *remote_bd_addr)
{
bdstr_t bdstr;
bdaddr_to_string(remote_bd_addr, bdstr, sizeof(bdstr));
int ret = 1;
LOG_DEBUG("Add to storage: Remote device:%s\n", bdstr);
int ret = 1;
if (btc_config_exist(bdstr, "LinkKeyType")) {
ret &= btc_config_remove(bdstr, "LinkKeyType");
btc_config_lock();
if (btc_config_exist(bdstr, BTC_STORAGE_LINK_KEY_TYPE_STR)) {
ret &= btc_config_remove(bdstr, BTC_STORAGE_LINK_KEY_TYPE_STR);
}
if (btc_config_exist(bdstr, "PinLength")) {
ret &= btc_config_remove(bdstr, "PinLength");
if (btc_config_exist(bdstr, BTC_STORAGE_PIN_LENGTH_STR)) {
ret &= btc_config_remove(bdstr, BTC_STORAGE_PIN_LENGTH_STR);
}
if (btc_config_exist(bdstr, "LinkKey")) {
ret &= btc_config_remove(bdstr, "LinkKey");
if (btc_config_exist(bdstr, BTC_STORAGE_LINK_KEY_STR)) {
ret &= btc_config_remove(bdstr, BTC_STORAGE_LINK_KEY_STR);
}
/* write bonded info immediately */
btc_config_flush();
btc_config_unlock();
return ret ? BT_STATUS_SUCCESS : BT_STATUS_FAIL;
}

View File

@ -141,7 +141,7 @@ int btc_init(void)
{
xBtcQueue = xQueueCreate(BTC_TASK_QUEUE_NUM, sizeof(btc_msg_t));
xTaskCreatePinnedToCore(btc_task, "Btc_task", BTC_TASK_STACK_SIZE, NULL, BTC_TASK_PRIO, &xBtcTaskHandle, 0);
btc_gap_callback_init();
/* TODO: initial the profile_tab */
return BT_STATUS_SUCCESS;

View File

@ -11,9 +11,11 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef __BTC_BLE_STORAGE_H__
#define __BTC_BLE_STORAGE_H__
#include "bt_types.h"
#include "bt_target.h"
#include "esp_gap_ble_api.h"
#if (SMP_INCLUDED == TRUE)
#define BTC_LE_LOCAL_KEY_IR (1<<0)
@ -21,52 +23,25 @@
#define BTC_LE_LOCAL_KEY_DHK (1<<2)
#define BTC_LE_LOCAL_KEY_ER (1<<3)
#define BTC_BLE_STORAGE_DEV_TYPE_STR "DevType"
#define BTC_BLE_STORAGE_ADDR_TYPE_STR "AddrType"
#define BTC_BLE_STORAGE_LINK_KEY_STR "LinkKey"
#define BTC_BLE_STORAGE_LE_KEY_PENC_STR "LE_KEY_PENC"
#define BTC_BLE_STORAGE_LE_KEY_PID_STR "LE_KEY_PID"
#define BTC_BLE_STORAGE_LE_KEY_PCSRK_STR "LE_KEY_PCSRK"
#define BTC_BLE_STORAGE_LE_KEY_LENC_STR "LE_KEY_LENC"
#define BTC_BLE_STORAGE_LE_KEY_LID_STR "LE_KEY_LID"
#define BTC_BLE_STORAGE_LE_KEY_LCSRK_STR "LE_KEY_LCSRK"
#define BTC_BLE_STORAGE_LOCAL_ADAPTER_STR "Adapter"
#define BTC_BLE_STORAGE_LE_LOCAL_KEY_IR_STR "LE_LOCAL_KEY_IR"
#define BTC_BLE_STORAGE_LE_LOCAL_KEY_IRK_STR "LE_LOCAL_KEY_IRK"
#define BTC_BLE_STORAGE_LE_LOCAL_KEY_DHK_STR "LE_LOCAL_KEY_DHK"
#define BTC_BLE_STORAGE_LE_LOCAL_KEY_ER_STR "LE_LOCAL_KEY_ER"
/************************************************************************************
** Local type definitions
************************************************************************************/
typedef struct
{
uint32_t num_devices;
bt_bdaddr_t devices[BTM_SEC_MAX_DEVICE_RECORDS];
} btc_bonded_devices_t;
typedef struct
{
bool is_penc_key_rcvd;
tBTM_LE_PENC_KEYS penc_key; /* received peer encryption key */
bool is_pcsrk_key_rcvd;
tBTM_LE_PCSRK_KEYS pcsrk_key; /* received peer device SRK */
bool is_pid_key_rcvd;
tBTM_LE_PID_KEYS pid_key; /* peer device ID key */
bool is_lenc_key_rcvd;
tBTM_LE_LENC_KEYS lenc_key; /* local encryption reproduction keys LTK = = d1(ER,DIV,0)*/
bool is_lcsrk_key_rcvd;
tBTM_LE_LCSRK_KEYS lcsrk_key; /* local device CSRK = d1(ER,DIV,1)*/
bool is_lidk_key_rcvd; /* local identity key received */
} btc_dm_ble_cb_t;
typedef struct
{
bt_bdaddr_t static_bdaddr;
BD_ADDR bd_addr;
btc_dm_ble_cb_t ble;
} btc_dm_pairing_cb_t;
typedef struct
{
uint8_t ir[BT_OCTET16_LEN];
uint8_t irk[BT_OCTET16_LEN];
uint8_t dhk[BT_OCTET16_LEN];
}btc_dm_local_key_id_t;
typedef struct
{
bool is_er_rcvd;
uint8_t er[BT_OCTET16_LEN];
bool is_id_keys_rcvd;
btc_dm_local_key_id_t id_keys; /* ID kyes */
}btc_dm_local_key_cb_t;
typedef struct
{
BT_OCTET16 sp_c;
@ -75,50 +50,37 @@ typedef struct
} btc_dm_oob_cb_t;
extern btc_dm_pairing_cb_t pairing_cb;
extern btc_dm_local_key_cb_t ble_local_key_cb;
void btc_storage_save(void);
bt_status_t btc_storage_load_bonded_ble_devices(void);
bt_status_t btc_storage_add_ble_bonding_key( bt_bdaddr_t *remote_bd_addr, char *key, uint8_t key_type, uint8_t key_length);
bt_status_t btc_in_fetch_bonded_ble_devices(int add);
void btc_dm_remove_ble_bonding_keys(void);
bt_status_t btc_storage_add_ble_bonding_key( bt_bdaddr_t *remote_bd_addr,
char *key,
uint8_t key_type,
uint8_t key_length);
void btc_save_ble_bonding_keys(void);
bt_status_t btc_in_fetch_bonded_ble_device(const char *remote_bd_addr, int add,
btc_bonded_devices_t *p_bonded_devices);
bt_status_t btc_storage_get_ble_bonding_key(bt_bdaddr_t *remote_bd_addr,
uint8_t key_type,
char *key_value,
int key_length);
bt_status_t btc_storage_add_ble_local_key(char *key,
uint8_t key_type,
uint8_t key_length);
bt_status_t btc_storage_get_ble_bonding_key(bt_bdaddr_t *remote_bd_addr, uint8_t key_type, char *key_value, int key_length);
bt_status_t btc_storage_remove_ble_bonding_keys(bt_bdaddr_t *remote_bd_addr);
bool btc_storage_compare_address_key_value(bt_bdaddr_t *remote_bd_addr, uint8_t key_type, void *key_value, int key_length);
bt_status_t btc_storage_add_ble_local_key(char *key, uint8_t key_type, uint8_t key_length);
bt_status_t btc_storage_remove_ble_local_keys(void);
bt_status_t btc_storage_get_ble_local_key(uint8_t key_type,
char *key_value,
int key_len);
bt_status_t btc_storage_get_ble_local_key(uint8_t key_type, char *key_value, int key_len);
bt_status_t btc_storage_get_remote_addr_type(bt_bdaddr_t *remote_bd_addr,
int *addr_type);
bt_status_t btc_storage_get_remote_addr_type(bt_bdaddr_t *remote_bd_addr, int *addr_type);
bt_status_t btc_storage_set_remote_addr_type(bt_bdaddr_t *remote_bd_addr,
uint8_t addr_type);
bt_status_t btc_storage_set_remote_addr_type(bt_bdaddr_t *remote_bd_addr, uint8_t addr_type, bool flush);
void btc_dm_load_ble_local_keys(void);
bt_status_t btc_storage_remove_remote_addr_type(bt_bdaddr_t *remote_bd_addr, bool flush);
void btc_dm_get_ble_local_keys(tBTA_DM_BLE_LOCAL_KEY_MASK *p_key_mask, BT_OCTET16 er,
tBTA_BLE_LOCAL_ID_KEYS *p_id_keys);
#endif ///SMP_INCLUDED == TRUE
bt_status_t btc_storage_set_ble_dev_type(bt_bdaddr_t *bd_addr, bool flush);
bt_status_t btc_storage_remove_ble_dev_type(bt_bdaddr_t *remote_bd_addr, bool flush);
bt_status_t btc_storage_load_bonded_ble_devices(void);
bt_status_t btc_storage_get_bonded_ble_devices_list(esp_ble_bond_dev_t *bond_dev, int dev_num);
int btc_storage_get_num_ble_bond_devices(void);
#endif ///SMP_INCLUDED == TRUE
#endif ///__BTC_BLE_STORAGE_H__

View File

@ -35,6 +35,7 @@ bool btc_config_set_str(const char *section, const char *key, const char *value)
bool btc_config_get_bin(const char *section, const char *key, uint8_t *value, size_t *length);
bool btc_config_set_bin(const char *section, const char *key, const uint8_t *value, size_t length);
bool btc_config_remove(const char *section, const char *key);
bool btc_config_remove_section(const char *section);
size_t btc_config_get_bin_length(const char *section, const char *key);
@ -43,12 +44,15 @@ const btc_config_section_iter_t *btc_config_section_end(void);
const btc_config_section_iter_t *btc_config_section_next(const btc_config_section_iter_t *section);
const char *btc_config_section_name(const btc_config_section_iter_t *section);
void btc_config_save(void);
void btc_config_flush(void);
int btc_config_clear(void);
// TODO(zachoverflow): Eww...we need to move these out. These are peer specific, not config general.
bool btc_get_address_type(const BD_ADDR bd_addr, int *p_addr_type);
bool btc_compare_address_key_value(const char *section, char *key_type, void *key_value, int key_length);
bool btc_get_device_type(const BD_ADDR bd_addr, int *p_device_type);
void btc_config_lock(void);
void btc_config_unlock(void);
#endif

View File

@ -29,6 +29,45 @@ typedef union {
tBTA_DM_SEC sec;
} btc_dm_sec_args_t;
typedef struct
{
bool is_penc_key_rcvd;
tBTM_LE_PENC_KEYS penc_key; /* received peer encryption key */
bool is_pcsrk_key_rcvd;
tBTM_LE_PCSRK_KEYS pcsrk_key; /* received peer device SRK */
bool is_pid_key_rcvd;
tBTM_LE_PID_KEYS pid_key; /* peer device ID key */
bool is_lenc_key_rcvd;
tBTM_LE_LENC_KEYS lenc_key; /* local encryption reproduction keys LTK = = d1(ER,DIV,0)*/
bool is_lcsrk_key_rcvd;
tBTM_LE_LCSRK_KEYS lcsrk_key; /* local device CSRK = d1(ER,DIV,1)*/
bool is_lidk_key_rcvd; /* local identity key received */
} btc_dm_ble_cb_t;
typedef struct
{
bt_bdaddr_t static_bdaddr;
BD_ADDR bd_addr;
btc_dm_ble_cb_t ble;
} btc_dm_pairing_cb_t;
typedef struct
{
uint8_t ir[BT_OCTET16_LEN];
uint8_t irk[BT_OCTET16_LEN];
uint8_t dhk[BT_OCTET16_LEN];
} btc_dm_local_key_id_t;
typedef struct
{
bool is_er_rcvd;
uint8_t er[BT_OCTET16_LEN];
bool is_id_keys_rcvd;
btc_dm_local_key_id_t id_keys; /* ID kyes */
} btc_dm_local_key_cb_t;
// void btc_dm_call_handler(btc_msg_t *msg);
void btc_dm_sec_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC *data);
void btc_dm_sec_cb_handler(btc_msg_t *msg);
@ -37,4 +76,11 @@ void btc_dm_sec_arg_deep_copy(btc_msg_t *msg, void *dst, void *src);
bt_status_t btc_dm_enable_service(tBTA_SERVICE_ID service_id);
bt_status_t btc_dm_disable_service(tBTA_SERVICE_ID service_id);
#if (SMP_INCLUDED == TRUE)
void btc_dm_load_ble_local_keys(void);
void btc_dm_get_ble_local_keys(tBTA_DM_BLE_LOCAL_KEY_MASK *p_key_mask, BT_OCTET16 er,
tBTA_BLE_LOCAL_ID_KEYS *p_id_keys);
#endif
#endif /* __BTC_DM_H__ */

View File

@ -19,6 +19,12 @@
#include "bt_defs.h"
#include "bt_types.h"
#define BTC_STORAGE_DEV_CLASS_STR "DevClass"
#define BTC_STORAGE_LINK_KEY_STR "LinkKey" /* same as the ble */
#define BTC_STORAGE_LINK_KEY_TYPE_STR "LinkKeyType"
#define BTC_STORAGE_PIN_LENGTH_STR "PinLength"
/*******************************************************************************
**
** Function btc_storage_add_bonded_device

View File

@ -24,6 +24,8 @@
#include "btc_gatt_util.h"
#include "esp_bt_defs.h"
#include "esp_gap_ble_api.h"
#include "btc_ble_storage.h"
#include "btc_dm.h"
static tBTA_BLE_ADV_DATA gl_bta_adv_data;
static tBTA_BLE_ADV_DATA gl_bta_scan_rsp_data;
@ -124,6 +126,9 @@ static esp_bt_status_t btc_hci_to_esp_status(uint8_t hci_status)
case HCI_ERR_PARAM_OUT_OF_RANGE:
esp_status = ESP_BT_STATUS_PARAM_OUT_OF_RANGE;
break;
case HCI_ERR_ILLEGAL_PARAMETER_FMT:
esp_status = ESP_BT_STATUS_ERR_ILLEGAL_PARAMETER_FMT;
break;
default:
esp_status = ESP_BT_STATUS_FAIL;
break;
@ -145,6 +150,12 @@ static esp_bt_status_t btc_btm_status_to_esp_status (uint8_t btm_status)
case BTM_CONTROL_LE_DATA_LEN_UNSUPPORTED:
esp_status = ESP_BT_STATUS_CONTROL_LE_DATA_LEN_UNSUPPORTED;
break;
case BTM_SET_PRIVACY_SUCCESS:
esp_status = ESP_BT_STATUS_SUCCESS;
break;
case BTM_SET_PRIVACY_FAIL:
esp_status = ESP_BT_STATUS_FAIL;
break;
default:
esp_status = ESP_BT_STATUS_FAIL;
break;
@ -618,7 +629,7 @@ static void btc_stop_scan_callback(tBTA_STATUS status)
}
}
void btc_update_conn_param_callback (UINT8 status, BD_ADDR bd_addr,
void btc_update_conn_param_callback (UINT8 status, BD_ADDR bd_addr,
tBTM_LE_UPDATE_CONN_PRAMS *update_conn_params)
{
esp_ble_gap_cb_param_t param;
@ -661,6 +672,23 @@ static void btc_set_pkt_length_callback(UINT8 status, tBTM_LE_SET_PKT_DATA_LENGT
}
}
static void btc_set_local_privacy_callback(UINT8 status)
{
esp_ble_gap_cb_param_t param;
bt_status_t ret;
btc_msg_t msg;
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_GAP_BLE;
msg.act = ESP_GAP_BLE_SET_LOCAL_PRIVACY_COMPLETE_EVT;
param.local_privacy_cmpl.status = btc_btm_status_to_esp_status(status);
ret = btc_transfer_context(&msg, &param,
sizeof(esp_ble_gap_cb_param_t), NULL);
if (ret != BT_STATUS_SUCCESS) {
LOG_ERROR("%s btc_transfer_context failed\n", __func__);
}
}
#if (SMP_INCLUDED == TRUE)
static void btc_set_encryption_callback(BD_ADDR bd_addr, tBTA_TRANSPORT transport, tBTA_STATUS enc_status)
@ -699,8 +727,7 @@ static void btc_ble_stop_advertising(tBTA_START_STOP_ADV_CMPL_CBACK *stop_adv_cb
}
static void btc_ble_update_conn_params(BD_ADDR bd_addr, uint16_t min_int,
uint16_t max_int, uint16_t latency, uint16_t timeout,
tBTA_UPDATE_CONN_PARAM_CBACK *update_conn_param_cb)
uint16_t max_int, uint16_t latency, uint16_t timeout)
{
if (min_int > max_int) {
min_int = max_int;
@ -711,7 +738,7 @@ static void btc_ble_update_conn_params(BD_ADDR bd_addr, uint16_t min_int,
}
BTA_DmBleUpdateConnectionParams(bd_addr, min_int, max_int,
latency, timeout, update_conn_param_cb);
latency, timeout);
}
static void btc_ble_set_pkt_data_len(BD_ADDR remote_device, uint16_t tx_data_length, tBTA_SET_PKT_DATA_LENGTH_CBACK *p_set_pkt_data_cback)
@ -733,16 +760,27 @@ static void btc_ble_set_rand_addr (BD_ADDR rand_addr)
param.set_rand_addr_cmpl.status = ESP_BT_STATUS_SUCCESS;
if (rand_addr != NULL) {
if((rand_addr[BD_ADDR_LEN - 1] & BT_STATIC_RAND_ADDR_MASK)
== BT_STATIC_RAND_ADDR_MASK) {
/*
A static address is a 48-bit randomly generated address and shall meet the following requirements:
• The two most significant bits of the address shall be equal to 1
• All bits of the random part of the address shall not be equal to 1
• All bits of the random part of the address shall not be equal to 0
*/
BD_ADDR invalid_rand_addr_a, invalid_rand_addr_b;
memset(invalid_rand_addr_a, 0xff, sizeof(BD_ADDR));
memset(invalid_rand_addr_b, 0x00, sizeof(BD_ADDR));
invalid_rand_addr_b[BD_ADDR_LEN - 1] = invalid_rand_addr_b[BD_ADDR_LEN - 1] | BT_STATIC_RAND_ADDR_MASK;
if((rand_addr[BD_ADDR_LEN - 1] & BT_STATIC_RAND_ADDR_MASK) == BT_STATIC_RAND_ADDR_MASK
&& memcmp(invalid_rand_addr_a, rand_addr, BD_ADDR_LEN) != 0
&& memcmp(invalid_rand_addr_b, rand_addr, BD_ADDR_LEN) != 0){
BTA_DmSetRandAddress(rand_addr);
} else {
param.set_rand_addr_cmpl.status = ESP_BT_STATUS_INVALID_STATIC_RAND_ADDR;
LOG_ERROR("Invalid randrom address, the high bit should be 0x11xx");
LOG_ERROR("Invalid random address, the high bit should be 0b11, the random part shall not be to 1 or 0");
}
} else {
param.set_rand_addr_cmpl.status = ESP_BT_STATUS_INVALID_STATIC_RAND_ADDR;
LOG_ERROR("Invalid randrom addressm, the address value is NULL");
LOG_ERROR("Invalid random addressm, the address value is NULL");
}
msg.sig = BTC_SIG_API_CB;
@ -756,9 +794,9 @@ static void btc_ble_set_rand_addr (BD_ADDR rand_addr)
}
}
static void btc_ble_config_local_privacy(bool privacy_enable)
static void btc_ble_config_local_privacy(bool privacy_enable, tBTA_SET_LOCAL_PRIVACY_CBACK *set_local_privacy_cback)
{
BTA_DmBleConfigLocalPrivacy(privacy_enable);
BTA_DmBleConfigLocalPrivacy(privacy_enable, set_local_privacy_cback);
}
static void btc_ble_disconnect(BD_ADDR bd_addr)
@ -770,78 +808,14 @@ void btc_gap_ble_cb_handler(btc_msg_t *msg)
{
esp_ble_gap_cb_param_t *param = (esp_ble_gap_cb_param_t *)msg->arg;
switch (msg->act) {
case ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT:
btc_gap_ble_cb_to_app(ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT, param);
break;
case ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT :
btc_gap_ble_cb_to_app(ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT, param);
break;
case ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT:
btc_gap_ble_cb_to_app(ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT, param);
break;
case ESP_GAP_BLE_SCAN_RESULT_EVT:
btc_gap_ble_cb_to_app(ESP_GAP_BLE_SCAN_RESULT_EVT, param);
break;
case ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT:
btc_gap_ble_cb_to_app(ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT, param);
break;
case ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT:
btc_gap_ble_cb_to_app(ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT, param);
break;
case ESP_GAP_BLE_ADV_START_COMPLETE_EVT:
btc_gap_ble_cb_to_app(ESP_GAP_BLE_ADV_START_COMPLETE_EVT, param);
break;
case ESP_GAP_BLE_SCAN_START_COMPLETE_EVT:
btc_gap_ble_cb_to_app(ESP_GAP_BLE_SCAN_START_COMPLETE_EVT, param);
break;
case ESP_GAP_BLE_AUTH_CMPL_EVT:
btc_gap_ble_cb_to_app(ESP_GAP_BLE_AUTH_CMPL_EVT, param);
break;
case ESP_GAP_BLE_KEY_EVT:
btc_gap_ble_cb_to_app(ESP_GAP_BLE_KEY_EVT, param);
break;
btc_gap_ble_cb_to_app(ESP_GAP_BLE_KEY_EVT, param);
case ESP_GAP_BLE_SEC_REQ_EVT:
btc_gap_ble_cb_to_app(ESP_GAP_BLE_SEC_REQ_EVT, param);
break;
case ESP_GAP_BLE_PASSKEY_NOTIF_EVT:
btc_gap_ble_cb_to_app(ESP_GAP_BLE_PASSKEY_NOTIF_EVT, param);
break;
case ESP_GAP_BLE_PASSKEY_REQ_EVT:
btc_gap_ble_cb_to_app(ESP_GAP_BLE_PASSKEY_REQ_EVT, param);
break;
case ESP_GAP_BLE_OOB_REQ_EVT:
btc_gap_ble_cb_to_app(ESP_GAP_BLE_OOB_REQ_EVT, param);
break;
case ESP_GAP_BLE_LOCAL_IR_EVT:
btc_gap_ble_cb_to_app(ESP_GAP_BLE_LOCAL_IR_EVT, param);
break;
case ESP_GAP_BLE_LOCAL_ER_EVT:
btc_gap_ble_cb_to_app(ESP_GAP_BLE_LOCAL_ER_EVT, param);
break;
case ESP_GAP_BLE_NC_REQ_EVT:
btc_gap_ble_cb_to_app(ESP_GAP_BLE_NC_REQ_EVT, param);
case ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT:
btc_gap_ble_cb_to_app(ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT, param);
break;
case ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT:
btc_gap_ble_cb_to_app(ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT, param);
break;
case ESP_GAP_BLE_SET_STATIC_RAND_ADDR_EVT:
btc_gap_ble_cb_to_app(ESP_GAP_BLE_SET_STATIC_RAND_ADDR_EVT, param);
break;
case ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT:
btc_gap_ble_cb_to_app(ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT, param);
break;
case ESP_GAP_BLE_SET_PKT_LENGTH_COMPLETE_EVT:
btc_gap_ble_cb_to_app(ESP_GAP_BLE_SET_PKT_LENGTH_COMPLETE_EVT, param);
break;
default:
break;
if (msg->act < ESP_GAP_BLE_EVT_MAX) {
btc_gap_ble_cb_to_app(msg->act, param);
} else {
LOG_ERROR("%s, unknow msg->act = %d", __func__, msg->act);
}
btc_gap_ble_cb_deep_free(msg);
}
void btc_gap_ble_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
@ -913,7 +887,16 @@ void btc_gap_ble_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
}
}
static void btc_gap_ble_arg_deep_free(btc_msg_t *msg)
void btc_gap_ble_cb_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
{
switch (msg->act) {
default:
LOG_ERROR("%s, Unhandled deep copy %d\n", __func__, msg->act);
break;
}
}
void btc_gap_ble_arg_deep_free(btc_msg_t *msg)
{
LOG_DEBUG("%s \n", __func__);
switch (msg->act) {
@ -952,6 +935,16 @@ static void btc_gap_ble_arg_deep_free(btc_msg_t *msg)
}
}
void btc_gap_ble_cb_deep_free(btc_msg_t *msg)
{
LOG_DEBUG("%s", __func__);
switch (msg->act) {
default:
LOG_DEBUG("Unhandled deep free %d", msg->act);
break;
}
}
void btc_gap_ble_call_handler(btc_msg_t *msg)
{
btc_ble_gap_args_t *arg = (btc_ble_gap_args_t *)msg->arg;
@ -987,8 +980,7 @@ void btc_gap_ble_call_handler(btc_msg_t *msg)
arg->conn_update_params.conn_params.min_int,
arg->conn_update_params.conn_params.max_int,
arg->conn_update_params.conn_params.latency,
arg->conn_update_params.conn_params.timeout,
btc_update_conn_param_callback);
arg->conn_update_params.conn_params.timeout);
break;
case BTC_GAP_BLE_ACT_SET_PKT_DATA_LEN:
btc_ble_set_pkt_data_len(arg->set_pkt_data_len.remote_device, arg->set_pkt_data_len.tx_data_length, btc_set_pkt_length_callback);
@ -1000,7 +992,7 @@ void btc_gap_ble_call_handler(btc_msg_t *msg)
break;
}
case BTC_GAP_BLE_ACT_CONFIG_LOCAL_PRIVACY:
btc_ble_config_local_privacy(arg->cfg_local_privacy.privacy_enable);
btc_ble_config_local_privacy(arg->cfg_local_privacy.privacy_enable, btc_set_local_privacy_callback);
break;
case BTC_GAP_BLE_ACT_CFG_ADV_DATA_RAW:
btc_ble_set_adv_data_raw(arg->cfg_adv_data_raw.raw_adv,
@ -1078,6 +1070,12 @@ void btc_gap_ble_call_handler(btc_msg_t *msg)
BTA_DmBleConfirmReply(bd_addr, arg->enc_comfirm_replay.accept);
break;
}
case BTC_GAP_BLE_REMOVE_BOND_DEV_EVT: {
BD_ADDR bd_addr;
memcpy(bd_addr, arg->remove_bond_device.bd_addr, sizeof(BD_ADDR));
BTA_DmRemoveDevice(bd_addr);
break;
}
#endif ///SMP_INCLUDED == TRUE
case BTC_GAP_BLE_DISCONNECT_EVT:
btc_ble_disconnect(arg->disconnect.remote_device);
@ -1088,3 +1086,10 @@ void btc_gap_ble_call_handler(btc_msg_t *msg)
btc_gap_ble_arg_deep_free(msg);
}
//register connection parameter update callback
void btc_gap_callback_init(void)
{
BTM_BleRegiseterConnParamCallback(btc_update_conn_param_callback);
}

View File

@ -138,7 +138,7 @@ void btc_gatts_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
break;
}
case BTC_GATTS_ACT_SET_ATTR_VALUE:{
uint8_t len = src->set_attr_val.length;
uint16_t len = src->set_attr_val.length;
if(src->set_attr_val.value){
dst->set_attr_val.value = (uint8_t *)GKI_getbuf(len);
if(dst->set_attr_val.value != NULL){
@ -474,10 +474,10 @@ static esp_gatt_status_t btc_gatts_check_valid_attr_tab(esp_gatts_attr_db_t *gat
return ESP_GATT_OK;
}
void btc_gatts_get_attr_value(uint16_t attr_handle, uint16_t *length, uint8_t **value)
esp_gatt_status_t btc_gatts_get_attr_value(uint16_t attr_handle, uint16_t *length, uint8_t **value)
{
BTA_GetAttributeValue(attr_handle, length, value);
return BTA_GetAttributeValue(attr_handle, length, value);
}

View File

@ -40,6 +40,7 @@ typedef enum {
BTC_GAP_BLE_PASSKEY_REPLY_EVT,
BTC_GAP_BLE_CONFIRM_REPLY_EVT,
BTC_GAP_BLE_DISCONNECT_EVT,
BTC_GAP_BLE_REMOVE_BOND_DEV_EVT,
} btc_gap_ble_act_t;
/* btc_ble_gap_args_t */
@ -89,44 +90,50 @@ typedef union {
uint8_t *raw_scan_rsp;
uint32_t raw_scan_rsp_len;
} cfg_scan_rsp_data_raw;
//BTC_GAP_BLE_SET_ENCRYPTION_EVT
struct set_encryption_args {
esp_bd_addr_t bd_addr;
esp_ble_sec_act_t sec_act;
} set_encryption;
//BTC_GAP_BLE_SET_SECURITY_PARAM_EVT
struct set_security_param_args {
esp_ble_sm_param_t param_type;
uint8_t len;
uint8_t *value;
} set_security_param;
//BTC_GAP_BLE_SECURITY_RSP_EVT
struct enc_rsp_args {
esp_bd_addr_t bd_addr;
bool accept;
} sec_rsp;
//BTC_GAP_BLE_PASSKEY_REPLY_EVT
struct enc_passkey_reply_args {
esp_bd_addr_t bd_addr;
bool accept;
uint32_t passkey;
} enc_passkey_replay;
//BTC_GAP_BLE_CONFIRM_REPLY_EVT
struct enc_comfirm_reply_args {
esp_bd_addr_t bd_addr;
bool accept;
} enc_comfirm_replay;
//BTC_GAP_BLE_DISCONNECT_EVT
struct disconnect_args {
esp_bd_addr_t remote_device;
} disconnect;
//BTC_GAP_BLE_REMOVE_BOND_DEV_EVT
struct remove_bond_device_args {
esp_bd_addr_t bd_addr;
} remove_bond_device;
} btc_ble_gap_args_t;
void btc_gap_callback_init(void);
void btc_gap_ble_call_handler(btc_msg_t *msg);
void btc_gap_ble_cb_handler(btc_msg_t *msg);
void btc_gap_ble_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
void btc_gap_ble_arg_deep_free(btc_msg_t *msg);
void btc_gap_ble_cb_deep_free(btc_msg_t *msg);
void btc_gap_ble_cb_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
#endif /* __BTC_GAP_BLE_H__ */

View File

@ -147,7 +147,7 @@ typedef union {
void btc_gatts_call_handler(btc_msg_t *msg);
void btc_gatts_cb_handler(btc_msg_t *msg);
void btc_gatts_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
void btc_gatts_get_attr_value(uint16_t attr_handle, uint16_t *length, uint8_t **value);
esp_gatt_status_t btc_gatts_get_attr_value(uint16_t attr_handle, uint16_t *length, uint8_t **value);
#endif /* __BTC_GATTS_H__ */

View File

@ -22,7 +22,7 @@
#include "bta_sys.h"
#include "bta_dm_co.h"
#include "bta_dm_ci.h"
#include "btc_ble_storage.h"
#include "btc_dm.h"
#if (defined(BTIF_INCLUDED) && BTIF_INCLUDED == TRUE)
#include "bt_utils.h"
#if (BTM_OOB_INCLUDED == TRUE)
@ -502,7 +502,7 @@ void bta_dm_co_ble_set_rsp_key_req(UINT8 rsp_key)
void bta_dm_co_ble_set_max_key_size(UINT8 ble_key_size)
{
#if (SMP_INCLUDED == TRUE)
if(ble_key_size > 7 && ble_key_size >= 16) {
if(ble_key_size >= BTM_BLE_MIN_KEY_SIZE && ble_key_size <= BTM_BLE_MAX_KEY_SIZE) {
bte_appl_cfg.ble_max_key_size = ble_key_size;
} else {
APPL_TRACE_ERROR("%s error:Invalid key size value, key_size =%d",__func__, ble_key_size);

View File

@ -66,6 +66,7 @@ static uint8_t ble_resolving_list_max_size;
static uint8_t ble_supported_states[BLE_SUPPORTED_STATES_SIZE];
static bt_device_features_t features_ble;
static uint16_t ble_suggested_default_data_length;
static uint16_t ble_suggested_default_data_txtime;
static bool readable;
static bool ble_supported;
@ -228,7 +229,8 @@ static void start_up(void)
response = AWAIT_COMMAND(packet_factory->make_ble_read_suggested_default_data_length());
packet_parser->parse_ble_read_suggested_default_data_length_response(
response,
&ble_suggested_default_data_length);
&ble_suggested_default_data_length,
&ble_suggested_default_data_txtime);
}
// Set the ble event mask next
@ -404,6 +406,13 @@ static uint16_t get_ble_suggested_default_data_length(void)
return ble_suggested_default_data_length;
}
static uint16_t get_ble_suggested_default_data_txtime(void)
{
assert(readable);
assert(ble_supported);
return ble_suggested_default_data_txtime;
}
static uint16_t get_acl_buffer_count_classic(void)
{
assert(readable);
@ -472,6 +481,7 @@ static const controller_t interface = {
get_acl_packet_size_classic,
get_acl_packet_size_ble,
get_ble_suggested_default_data_length,
get_ble_suggested_default_data_txtime,
get_acl_buffer_count_classic,
get_acl_buffer_count_ble,

View File

@ -69,6 +69,7 @@ typedef struct controller_t {
uint16_t (*get_acl_packet_size_ble)(void);
uint16_t (*get_ble_default_data_packet_length)(void);
uint16_t (*get_ble_default_data_packet_txtime)(void);
// Get the number of acl packets the controller can buffer.
uint16_t (*get_acl_buffer_count_classic)(void);

View File

@ -183,11 +183,13 @@ static void parse_ble_read_resolving_list_size_response(
static void parse_ble_read_suggested_default_data_length_response(
BT_HDR *response,
uint16_t *ble_default_packet_length_ptr)
uint16_t *ble_default_packet_length_ptr,
uint16_t *ble_default_packet_txtime_ptr)
{
uint8_t *stream = read_command_complete_header(response, HCI_BLE_READ_DEFAULT_DATA_LENGTH, 2 /* bytes after */);
STREAM_TO_UINT8(*ble_default_packet_length_ptr, stream);
STREAM_TO_UINT16(*ble_default_packet_length_ptr, stream);
STREAM_TO_UINT16(*ble_default_packet_txtime_ptr, stream);
buffer_allocator->free(response);
}

View File

@ -90,7 +90,8 @@ typedef struct {
void (*parse_ble_read_suggested_default_data_length_response)(
BT_HDR *response,
uint16_t *ble_default_packet_length_ptr
uint16_t *ble_default_packet_length_ptr,
uint16_t *ble_default_packet_txtime_ptr
);
} hci_packet_parser_t;

View File

@ -577,7 +577,11 @@
/* The number of security records for peer devices. 100 AS Default*/
#ifndef BTM_SEC_MAX_DEVICE_RECORDS
#define BTM_SEC_MAX_DEVICE_RECORDS 8 // 100
#if SMP_INCLUDED == TRUE
#define BTM_SEC_MAX_DEVICE_RECORDS 15 // 100
#else
#define BTM_SEC_MAX_DEVICE_RECORDS 8
#endif /* SMP_INCLUDED == TRUE */
#endif
/* The number of security records for services. 32 AS Default*/

View File

@ -28,7 +28,7 @@
#include "list.h"
#include "bt_trace.h"
#define CONFIG_FILE_MAX_SIZE (1024)
#define CONFIG_FILE_MAX_SIZE (2048)
#define CONFIG_KEY "bt_cfg_key"
typedef struct {
char *key;
@ -91,7 +91,12 @@ config_t *config_new(const char *filename)
nvs_handle fp;
err = nvs_open(filename, NVS_READWRITE, &fp);
if (err != ESP_OK) {
LOG_ERROR("%s unable to open file '%s'\n", __func__, filename);
if (err == ESP_ERR_NVS_NOT_INITIALIZED) {
LOG_ERROR("%s: NVS not initialized. "
"Call nvs_flash_init before initializing bluetooth.", __func__);
} else {
LOG_ERROR("%s unable to open NVS namespace '%s'\n", __func__, filename);
}
config_free(config);
return NULL;
}
@ -128,6 +133,25 @@ bool config_has_key(const config_t *config, const char *section, const char *key
return (entry_find(config, section, key) != NULL);
}
bool config_has_key_in_section(config_t *config, char *key, char *key_value)
{
LOG_DEBUG("key = %s, value = %s", key, key_value);
for (const list_node_t *node = list_begin(config->sections); node != list_end(config->sections); node = list_next(node)) {
const section_t *section = (const section_t *)list_node(node);
for (const list_node_t *node = list_begin(section->entries); node != list_end(section->entries); node = list_next(node)) {
entry_t *entry = list_node(node);
LOG_DEBUG("entry->key = %s, entry->value = %s", entry->key, entry->value);
if (!strcmp(entry->key, key) && !strcmp(entry->value, key_value)) {
LOG_DEBUG("%s, the irk aready in the flash.", __func__);
return true;
}
}
}
return false;
}
int config_get_int(const config_t *config, const char *section, const char *key, int def_value)
{
assert(config != NULL);
@ -296,6 +320,10 @@ bool config_save(const config_t *config, const char *filename)
err = nvs_open(filename, NVS_READWRITE, &fp);
if (err != ESP_OK) {
if (err == ESP_ERR_NVS_NOT_INITIALIZED) {
LOG_ERROR("%s: NVS not initialized. "
"Call nvs_flash_init before initializing bluetooth.", __func__);
}
err_code |= 0x02;
goto error;
}
@ -303,8 +331,8 @@ bool config_save(const config_t *config, const char *filename)
int w_cnt, w_cnt_total = 0;
for (const list_node_t *node = list_begin(config->sections); node != list_end(config->sections); node = list_next(node)) {
const section_t *section = (const section_t *)list_node(node);
LOG_DEBUG("section name: %s\n", section->name);
w_cnt = snprintf(line, 1024, "[%s]\n", section->name);
LOG_DEBUG("section name: %s, w_cnt + w_cnt_total = %d\n", section->name, w_cnt + w_cnt_total);
if (w_cnt + w_cnt_total < CONFIG_FILE_MAX_SIZE) {
memcpy(buf + w_cnt_total, line, w_cnt);
w_cnt_total += w_cnt;
@ -316,6 +344,7 @@ bool config_save(const config_t *config, const char *filename)
const entry_t *entry = (const entry_t *)list_node(enode);
LOG_DEBUG("(key, val): (%s, %s)\n", entry->key, entry->value);
w_cnt = snprintf(line, 1024, "%s = %s\n", entry->key, entry->value);
LOG_DEBUG("%s, w_cnt + w_cnt_total = %d", __func__, w_cnt + w_cnt_total);
if (w_cnt + w_cnt_total < CONFIG_FILE_MAX_SIZE) {
memcpy(buf + w_cnt_total, line, w_cnt);
w_cnt_total += w_cnt;

View File

@ -66,6 +66,10 @@ bool config_has_section(const config_t *config, const char *section);
// Returns false otherwise. |config|, |section|, and |key| must not be NULL.
bool config_has_key(const config_t *config, const char *section, const char *key);
// Returns true if the config file has a key named |key| and the key_value.
// Returns false otherwise. |config|, |key|, and |key_value| must not be NULL.
bool config_has_key_in_section(config_t *config, char *key, char *key_value);
// Returns the integral value for a given |key| in |section|. If |section|
// or |key| do not exist, or the value cannot be fully converted to an integer,
// this function returns |def_value|. |config|, |section|, and |key| must not

View File

@ -956,7 +956,11 @@ void avdt_scb_hdl_tc_close(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
/* set up hdr */
avdt_ctrl.hdr.err_code = p_scb->close_code;
avdt_ctrl.hdr.err_param = p_data->close.disc_rsn;
if (p_data) {
avdt_ctrl.hdr.err_param = p_data->close.disc_rsn;
} else {
avdt_ctrl.hdr.err_param = AVDT_DISC_RSN_NORMAL;
}
/* clear sep variables */
avdt_scb_clr_vars(p_scb, p_data);

View File

@ -907,6 +907,11 @@ void btm_read_remote_version_complete (UINT8 *p)
}
#if BLE_INCLUDED == TRUE
if (p_acl_cb->transport == BT_TRANSPORT_LE) {
if (HCI_LE_DATA_LEN_EXT_SUPPORTED(p_acl_cb->peer_le_features)) {
uint16_t data_length = controller_get_interface()->get_ble_default_data_packet_length();
uint16_t data_txtime = controller_get_interface()->get_ble_default_data_packet_txtime();
btsnd_hcic_ble_set_data_length(p_acl_cb->hci_handle, data_length, data_txtime);
}
l2cble_notify_le_connection (p_acl_cb->remote_addr);
}
#endif

View File

@ -180,7 +180,11 @@ BOOLEAN BTM_SecAddBleKey (BD_ADDR bd_addr, tBTM_LE_KEY_VALUE *p_le_key, tBTM_LE_
#if (BLE_PRIVACY_SPT == TRUE)
if (key_type == BTM_LE_KEY_PID || key_type == BTM_LE_KEY_LID) {
btm_ble_resolving_list_load_dev (p_dev_rec);
/* It will cause that scanner doesn't send scan request to advertiser
* which has sent IRK to us and we have stored the IRK in controller.
* It is a design problem of hardware. The temporal solution is not to
* send the key to the controller and then resolve the random address in host. */
//btm_ble_resolving_list_load_dev (p_dev_rec);
}
#endif
@ -808,7 +812,7 @@ tBTM_STATUS BTM_SetBleDataLength(BD_ADDR bd_addr, UINT16 tx_pdu_length)
}
if (!HCI_LE_DATA_LEN_EXT_SUPPORTED(p_acl->peer_le_features)) {
BTM_TRACE_DEBUG("%s failed, peer does not support request", __FUNCTION__);
BTM_TRACE_ERROR("%s failed, peer does not support request", __FUNCTION__);
return BTM_PEER_LE_DATA_LEN_UNSUPPORTED;
}
@ -1898,7 +1902,11 @@ UINT8 btm_proc_smp_cback(tSMP_EVT event, BD_ADDR bd_addr, tSMP_EVT_DATA *p_data)
p_dev_rec->sec_state = BTM_SEC_STATE_IDLE;
#if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE)
/* add all bonded device into resolving list if IRK is available*/
btm_ble_resolving_list_load_dev(p_dev_rec);
/* It will cause that scanner doesn't send scan request to advertiser
* which has sent IRK to us and we have stored the IRK in controller.
* It is a design problem of hardware. The temporal solution is not to
* send the key to the controller and then resolve the random address in host. */
//btm_ble_resolving_list_load_dev(p_dev_rec);
#endif
}

View File

@ -60,6 +60,10 @@ static void btm_gen_resolve_paddr_cmpl(tSMP_ENC *p)
btsnd_hcic_ble_set_random_addr(p_cb->private_addr);
p_cb->own_addr_type = BLE_ADDR_RANDOM;
if (p_cb->set_local_privacy_cback){
(*p_cb->set_local_privacy_cback)(BTM_SET_PRIVACY_SUCCESS);
p_cb->set_local_privacy_cback = NULL;
}
/* start a periodical timer to refresh random addr */
btu_stop_timer_oneshot(&p_cb->raddr_timer_ent);
@ -73,6 +77,10 @@ static void btm_gen_resolve_paddr_cmpl(tSMP_ENC *p)
} else {
/* random address set failure */
BTM_TRACE_DEBUG("set random address failed");
if (p_cb->set_local_privacy_cback){
(*p_cb->set_local_privacy_cback)(BTM_SET_PRIVACY_FAIL);
p_cb->set_local_privacy_cback = NULL;
}
}
}
/*******************************************************************************

View File

@ -61,6 +61,7 @@ static tBTM_BLE_VSC_CB cmn_ble_vsc_cb;
static tBTM_BLE_CTRL_FEATURES_CBACK *p_ctrl_le_feature_rd_cmpl_cback = NULL;
#endif
tBTM_CallbackFunc conn_param_update_cb;
/*******************************************************************************
** Local functions
*******************************************************************************/
@ -220,6 +221,19 @@ const UINT8 btm_le_state_combo_tbl[BTM_BLE_STATE_MAX][BTM_BLE_STATE_MAX][2] = {
/* check LE combo state supported */
#define BTM_LE_STATES_SUPPORTED(x, y, z) ((x)[(z)] & (y))
/*******************************************************************************
**
** Function BTM_BleRegiseterConnParamCallback
**
** Description register connection parameters update callback func
**
** Returns void
**
*******************************************************************************/
void BTM_BleRegiseterConnParamCallback(tBTM_UPDATE_CONN_PARAM_CBACK *update_conn_param_cb)
{
conn_param_update_cb.update_conn_param_cb = update_conn_param_cb;
}
/*******************************************************************************
**
@ -640,10 +654,16 @@ void BTM_BleEnableMixedPrivacyMode(BOOLEAN mixed_on)
** Returns BOOLEAN privacy mode set success; otherwise failed.
**
*******************************************************************************/
BOOLEAN BTM_BleConfigPrivacy(BOOLEAN privacy_mode)
BOOLEAN BTM_BleConfigPrivacy(BOOLEAN privacy_mode, tBTM_SET_LOCAL_PRIVACY_CBACK *set_local_privacy_cback)
{
#if BLE_PRIVACY_SPT == TRUE
tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
tBTM_LE_RANDOM_CB *random_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb;
if (random_cb){
random_cb->set_local_privacy_cback = set_local_privacy_cback;
}else{
BTM_TRACE_ERROR("%s,random_cb = NULL", __func__);
}
BTM_TRACE_EVENT ("%s\n", __func__);
@ -657,6 +677,10 @@ BOOLEAN BTM_BleConfigPrivacy(BOOLEAN privacy_mode)
if (!privacy_mode) { /* if privacy disabled, always use public address */
p_cb->addr_mgnt_cb.own_addr_type = BLE_ADDR_PUBLIC;
p_cb->privacy_mode = BTM_PRIVACY_NONE;
if (random_cb && random_cb->set_local_privacy_cback){
(*random_cb->set_local_privacy_cback)(BTM_SET_PRIVACY_SUCCESS);
random_cb->set_local_privacy_cback = NULL;
}
} else { /* privacy is turned on*/
/* always set host random address, used when privacy 1.1 or priavcy 1.2 is disabled */
p_cb->addr_mgnt_cb.own_addr_type = BLE_ADDR_RANDOM;
@ -3326,6 +3350,11 @@ void btm_ble_read_remote_features_complete(UINT8 *p)
else{
if (p_acl_cb->transport == BT_TRANSPORT_LE) {
if (HCI_LE_DATA_LEN_EXT_SUPPORTED(p_acl_cb->peer_le_features)) {
uint16_t data_length = controller_get_interface()->get_ble_default_data_packet_length();
uint16_t data_txtime = controller_get_interface()->get_ble_default_data_packet_txtime();
btsnd_hcic_ble_set_data_length(p_acl_cb->hci_handle, data_length, data_txtime);
}
l2cble_notify_le_connection (p_acl_cb->remote_addr);
}
}

View File

@ -126,6 +126,7 @@ static void btu_ble_ll_conn_complete_evt (UINT8 *p, UINT16 evt_len);
static void btu_ble_process_adv_pkt (UINT8 *p);
static void btu_ble_read_remote_feat_evt (UINT8 *p);
static void btu_ble_ll_conn_param_upd_evt (UINT8 *p, UINT16 evt_len);
static void btu_ble_ll_get_conn_param_format_err_from_contoller (UINT8 status, UINT16 handle);
#if (SMP_INCLUDED == TRUE)
static void btu_ble_proc_ltk_req (UINT8 *p);
static void btu_hcif_encryption_key_refresh_cmpl_evt (UINT8 *p);
@ -1130,6 +1131,14 @@ static void btu_hcif_hdl_command_status (UINT16 opcode, UINT8 status, UINT8 *p_c
case HCI_BLE_CREATE_LL_CONN:
btm_ble_create_ll_conn_complete(status);
break;
case HCI_BLE_UPD_LL_CONN_PARAMS:
if (p_cmd != NULL){
p_cmd++;
STREAM_TO_UINT16 (handle, p_cmd);
btu_ble_ll_get_conn_param_format_err_from_contoller(status, handle);
}
break;
#endif
#if BTM_SCO_INCLUDED == TRUE
@ -1758,6 +1767,14 @@ static void btu_ble_ll_conn_param_upd_evt (UINT8 *p, UINT16 evt_len)
conn_latency, conn_timeout);
}
static void btu_ble_ll_get_conn_param_format_err_from_contoller (UINT8 status, UINT16 handle)
{
/* host send illegal connection parameters format, controller would send
back HCI_ERR_ILLEGAL_PARAMETER_FMT */
l2cble_get_conn_param_format_err_from_contoller(status, handle);
}
static void btu_ble_read_remote_feat_evt (UINT8 *p)
{
btm_ble_read_remote_features_complete(p);

View File

@ -989,8 +989,10 @@ void gatt_process_mtu_rsp(tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, UINT16 len, UINT
p_tcb->payload_size = mtu;
}
}
l2cble_set_fixed_channel_tx_data_length(p_tcb->peer_bda, L2CAP_ATT_CID, p_tcb->payload_size);
/* host will set packet data length to 251 automatically if remote device support set packet data length,
so l2cble_set_fixed_channel_tx_data_length() is not necessary.
l2cble_set_fixed_channel_tx_data_length(p_tcb->peer_bda, L2CAP_ATT_CID, p_tcb->payload_size);
*/
gatt_end_operation(p_clcb, status, NULL);
}
/*******************************************************************************

View File

@ -752,6 +752,14 @@ tGATT_STATUS gatts_get_attribute_value(tGATT_SVC_DB *p_db, UINT16 attr_handle,
GATT_TRACE_ERROR("gatts_get_attribute_value Fail:p_db->p_attr_list is NULL.\n");
return GATT_INVALID_PDU;
}
if (length == NULL){
GATT_TRACE_ERROR("gatts_get_attribute_value Fail:length is NULL.\n");
return GATT_INVALID_PDU;
}
if (value == NULL){
GATT_TRACE_ERROR("gatts_get_attribute_value Fail:value is NULL.\n");
return GATT_INVALID_PDU;
}
p_cur = (tGATT_ATTR16 *) p_db->p_attr_list;

View File

@ -929,9 +929,10 @@ static void gatts_process_mtu_req (tGATT_TCB *p_tcb, UINT16 len, UINT8 *p_data)
p_tcb->payload_size = mtu;
}
GATT_TRACE_ERROR("MTU request PDU with MTU size %d\n", p_tcb->payload_size);
l2cble_set_fixed_channel_tx_data_length(p_tcb->peer_bda, L2CAP_ATT_CID, p_tcb->payload_size);
/* host will set packet data length to 251 automatically if remote device support set packet data length,
so l2cble_set_fixed_channel_tx_data_length() is not necessary.
l2cble_set_fixed_channel_tx_data_length(p_tcb->peer_bda, L2CAP_ATT_CID, p_tcb->payload_size);
*/
if ((p_buf = attp_build_sr_msg(p_tcb, GATT_RSP_MTU, (tGATT_SR_MSG *) &p_tcb->payload_size)) != NULL) {
attp_send_sr_msg (p_tcb, p_buf);

View File

@ -69,7 +69,9 @@ enum {
BTM_REPEATED_ATTEMPTS, /* 19 repeated attempts for LE security requests */
BTM_MODE4_LEVEL4_NOT_SUPPORTED, /* 20 Secure Connections Only Mode can't be supported */
BTM_PEER_LE_DATA_LEN_UNSUPPORTED, /* 21 peer setting data length is unsupported*/
BTM_CONTROL_LE_DATA_LEN_UNSUPPORTED /* 22 controller setting data length is unsupported*/
BTM_CONTROL_LE_DATA_LEN_UNSUPPORTED,/* 22 controller setting data length is unsupported*/
BTM_SET_PRIVACY_SUCCESS, /* 23 enable/disable local privacy success */
BTM_SET_PRIVACY_FAIL, /* 24 enable/disable local privacy failed*/
};
typedef uint8_t tBTM_STATUS;
@ -175,6 +177,8 @@ typedef void (tBTM_UPDATE_CONN_PARAM_CBACK) (UINT8 status, BD_ADDR bd_addr, tBTM
typedef void (tBTM_SET_PKT_DATA_LENGTH_CBACK) (UINT8 status, tBTM_LE_SET_PKT_DATA_LENGTH_PARAMS *data_length_params);
typedef void (tBTM_SET_LOCAL_PRIVACY_CBACK) (UINT8 status);
/*****************************************************************************
** DEVICE DISCOVERY - Inquiry, Remote Name, Discovery, Class of Device
@ -1412,6 +1416,7 @@ typedef UINT8 tBTM_IO_CAP;
#define BTM_BLE_INITIATOR_KEY_SIZE 15
#define BTM_BLE_RESPONDER_KEY_SIZE 15
#define BTM_BLE_MAX_KEY_SIZE 16
#define BTM_BLE_MIN_KEY_SIZE 7
typedef UINT8 tBTM_AUTH_REQ;

View File

@ -164,12 +164,12 @@ typedef UINT8 tBTM_BLE_SFP;
/* default connection interval min */
#ifndef BTM_BLE_CONN_INT_MIN_DEF
#define BTM_BLE_CONN_INT_MIN_DEF 24 /* recommended min: 30ms = 24 * 1.25 */
#define BTM_BLE_CONN_INT_MIN_DEF 10 /* recommended min: 12.5ms = 10 * 1.25 */
#endif
/* default connection interval max */
#ifndef BTM_BLE_CONN_INT_MAX_DEF
#define BTM_BLE_CONN_INT_MAX_DEF 40 /* recommended max: 50 ms = 56 * 1.25 */
#define BTM_BLE_CONN_INT_MAX_DEF 12 /* recommended max: 15 ms = 12 * 1.25 */
#endif
/* default slave latency */
@ -861,6 +861,20 @@ tBTM_BLE_SCAN_SETUP_CBACK bta_ble_scan_setup_cb;
extern "C" {
#endif
*/
/*******************************************************************************
**
** Function BTM_BleRegiseterConnParamCallback
**
** Description register connection parameters update callback func
**
** Parameters: update_conn_param_cb
**
** Returns void
**
*******************************************************************************/
void BTM_BleRegiseterConnParamCallback(tBTM_UPDATE_CONN_PARAM_CBACK *update_conn_param_cb);
/*******************************************************************************
**
** Function BTM_SecAddBleDevice
@ -1596,7 +1610,7 @@ tBTM_STATUS BTM_BleBroadcast(BOOLEAN start);
**
*******************************************************************************/
//extern
BOOLEAN BTM_BleConfigPrivacy(BOOLEAN enable);
BOOLEAN BTM_BleConfigPrivacy(BOOLEAN enable, tBTM_SET_LOCAL_PRIVACY_CBACK *set_local_privacy_cabck);
/*******************************************************************************
**

View File

@ -185,6 +185,7 @@ typedef struct {
tBTM_BLE_ADDR_CBACK *p_generate_cback;
void *p;
TIMER_LIST_ENT raddr_timer_ent;
tBTM_SET_LOCAL_PRIVACY_CBACK *set_local_privacy_cback;
} tBTM_LE_RANDOM_CB;
#define BTM_BLE_MAX_BG_CONN_DEV_NUM 10

View File

@ -115,7 +115,6 @@ UINT8 conn_addr_type; /* local device address type for this co
BD_ADDR active_remote_addr; /* remote address used on this connection */
UINT8 active_remote_addr_type; /* local device address type for this connection */
BD_FEATURES peer_le_features; /* Peer LE Used features mask for the device */
tBTM_UPDATE_CONN_PARAM_CBACK *update_conn_param_cb;
tBTM_SET_PKT_DATA_LENGTH_CBACK *p_set_pkt_data_cback;
tBTM_LE_SET_PKT_DATA_LENGTH_PARAMS data_length_params;
#endif
@ -874,6 +873,12 @@ typedef struct {
#endif
} tBTM_CB;
typedef struct{
//connection parameters update callback
tBTM_UPDATE_CONN_PARAM_CBACK *update_conn_param_cb;
}tBTM_CallbackFunc;
extern tBTM_CallbackFunc conn_param_update_cb;
/*
#ifdef __cplusplus
extern "C"

View File

@ -1469,7 +1469,8 @@ typedef struct {
#define HCI_FEATURE_SWITCH_MASK 0x20
#define HCI_FEATURE_SWITCH_OFF 0
#define HCI_SWITCH_SUPPORTED(x) ((x)[HCI_FEATURE_SWITCH_OFF] & HCI_FEATURE_SWITCH_MASK)
// temporarily disable ROLE_SWITCH since there is an issue to be fixed
#define HCI_SWITCH_SUPPORTED(x) (0 & ((x)[HCI_FEATURE_SWITCH_OFF] & HCI_FEATURE_SWITCH_MASK))
#define HCI_FEATURE_HOLD_MODE_MASK 0x40
#define HCI_FEATURE_HOLD_MODE_OFF 0

View File

@ -402,14 +402,24 @@ typedef struct t_l2c_linkcb {
#define L2C_BLE_NEW_CONN_PARAM 0x2 /* new connection parameter to be set */
#define L2C_BLE_UPDATE_PENDING 0x4 /* waiting for connection update finished */
#define L2C_BLE_NOT_DEFAULT_PARAM 0x8 /* not using default connection parameters */
#define L2C_BLE_UPDATE_PARAM_FULL 0x10 /* update connection parameters full, can not update */
UINT8 conn_update_mask;
UINT16 min_interval; /* parameters as requested by peripheral */
UINT16 max_interval;
UINT16 conn_int;
UINT16 latency;
UINT16 timeout;
/* cache connection parameters that wait to update */
UINT16 waiting_update_conn_min_interval;
UINT16 waiting_update_conn_max_interval;
UINT16 waiting_update_conn_latency;
UINT16 waiting_update_conn_timeout;
/* cache parameters that is being updated */
UINT16 updating_conn_min_interval;
UINT16 updating_conn_max_interval;
bool updating_param_flag;
/* current connection parameters that current connection is using */
UINT16 current_used_conn_interval;
UINT16 current_used_conn_latency;
UINT16 current_used_conn_timeout;
/* connection parameters update order:
waiting_update_conn_xx -> updating_conn_xx -> current_used_conn_xx
*/
#endif
#if (L2CAP_ROUND_ROBIN_CHANNEL_SERVICE == TRUE)
@ -733,6 +743,7 @@ extern void l2cble_notify_le_connection (BD_ADDR bda);
extern void l2c_ble_link_adjust_allocation (void);
extern void l2cble_process_conn_update_evt (UINT16 handle, UINT8 status, UINT16 conn_interval,
UINT16 conn_latency, UINT16 conn_timeout);
extern void l2cble_get_conn_param_format_err_from_contoller(UINT8 status, UINT16 handle);
#if (defined BLE_LLT_INCLUDED) && (BLE_LLT_INCLUDED == TRUE)
extern void l2cble_process_rc_param_request_evt(UINT16 handle, UINT16 int_min, UINT16 int_max,
@ -745,6 +756,7 @@ extern void l2cble_set_fixed_channel_tx_data_length(BD_ADDR remote_bda, UINT16 f
extern void l2c_send_update_conn_params_cb(tL2C_LCB *p_lcb, UINT8 status);
extern void l2cble_process_data_length_change_event(UINT16 handle, UINT16 tx_data_len,
UINT16 rx_data_len);
extern UINT32 CalConnectParamTimeout(tL2C_LCB *p_lcb);
#endif
extern void l2cu_process_fixed_disc_cback (tL2C_LCB *p_lcb);

View File

@ -117,14 +117,31 @@ BOOLEAN L2CA_UpdateBleConnParams (BD_ADDR rem_bda, UINT16 min_int, UINT16 max_in
return (FALSE);
}
p_lcb->min_interval = min_int;
p_lcb->max_interval = max_int;
p_lcb->latency = latency;
p_lcb->timeout = timeout;
if (p_lcb->conn_update_mask & L2C_BLE_UPDATE_PARAM_FULL){
UINT8 status = HCI_ERR_ILLEGAL_COMMAND;
L2CAP_TRACE_ERROR("There are two connection parameter requests that are being updated, please try later ");
if (conn_param_update_cb.update_conn_param_cb != NULL) {
tBTM_LE_UPDATE_CONN_PRAMS update_param;
update_param.max_conn_int = max_int;
update_param.min_conn_int = min_int;
update_param.conn_int = p_lcb->current_used_conn_interval;
update_param.slave_latency = p_lcb->current_used_conn_latency;
update_param.supervision_tout = p_lcb->current_used_conn_timeout;
(conn_param_update_cb.update_conn_param_cb)(status, p_lcb->remote_bd_addr, &update_param);
}
return (FALSE);
}
p_lcb->waiting_update_conn_min_interval = min_int;
p_lcb->waiting_update_conn_max_interval = max_int;
p_lcb->waiting_update_conn_latency = latency;
p_lcb->waiting_update_conn_timeout = timeout;
p_lcb->conn_update_mask |= L2C_BLE_NEW_CONN_PARAM;
if(l2cble_start_conn_update(p_lcb) == TRUE) {
btu_start_timer(&p_lcb->upda_con_timer, BTU_TTYPE_L2CAP_UPDA_CONN_PARAMS, L2CAP_UPDATE_CONN_PARAM_TOUT);
UINT32 time = CalConnectParamTimeout(p_lcb);
btu_start_timer(&p_lcb->upda_con_timer, BTU_TTYPE_L2CAP_UPDA_CONN_PARAMS, time);
}
return (TRUE);
@ -167,6 +184,10 @@ BOOLEAN L2CA_EnableUpdateBleConnParams (BD_ADDR rem_bda, BOOLEAN enable)
return (FALSE);
}
if (p_lcb->current_used_conn_interval <= BTM_BLE_CONN_INT_MAX_DEF && (p_lcb->conn_update_mask & L2C_BLE_CONN_UPDATE_DISABLE) == 0){
return (FALSE);
}
if (enable) {
p_lcb->conn_update_mask &= ~L2C_BLE_CONN_UPDATE_DISABLE;
} else {
@ -174,7 +195,9 @@ BOOLEAN L2CA_EnableUpdateBleConnParams (BD_ADDR rem_bda, BOOLEAN enable)
}
if (l2cble_start_conn_update(p_lcb) == TRUE) {
btu_start_timer(&p_lcb->upda_con_timer, BTU_TTYPE_L2CAP_UPDA_CONN_PARAMS, L2CAP_UPDATE_CONN_PARAM_TOUT);
UINT32 time = CalConnectParamTimeout(p_lcb);
btu_start_timer(&p_lcb->upda_con_timer, BTU_TTYPE_L2CAP_UPDA_CONN_PARAMS, time);
}
return (TRUE);
@ -304,10 +327,11 @@ void l2cble_scanner_conn_comp (UINT16 handle, BD_ADDR bda, tBLE_ADDR_TYPE type,
p_lcb->transport = BT_TRANSPORT_LE;
/* update link parameter, set slave link as non-spec default upon link up */
p_lcb->min_interval = p_lcb->max_interval = conn_interval;
p_lcb->timeout = conn_timeout;
p_lcb->latency = conn_latency;
p_lcb->waiting_update_conn_min_interval = p_lcb->waiting_update_conn_max_interval = p_lcb->current_used_conn_interval = conn_interval;
p_lcb->waiting_update_conn_timeout = p_lcb->current_used_conn_timeout = conn_timeout;
p_lcb->waiting_update_conn_latency = p_lcb->current_used_conn_latency = conn_latency;
p_lcb->conn_update_mask = L2C_BLE_NOT_DEFAULT_PARAM;
p_lcb->updating_param_flag = false;
/* If there are any preferred connection parameters, set them now */
if ( (p_dev_rec->conn_params.min_conn_int >= BTM_BLE_CONN_INT_MIN ) &&
@ -326,10 +350,11 @@ void l2cble_scanner_conn_comp (UINT16 handle, BD_ADDR bda, tBLE_ADDR_TYPE type,
handle, p_dev_rec->conn_params.min_conn_int, p_dev_rec->conn_params.max_conn_int,
p_dev_rec->conn_params.slave_latency, p_dev_rec->conn_params.supervision_tout);
p_lcb->min_interval = p_dev_rec->conn_params.min_conn_int;
p_lcb->max_interval = p_dev_rec->conn_params.max_conn_int;
p_lcb->timeout = p_dev_rec->conn_params.supervision_tout;
p_lcb->latency = p_dev_rec->conn_params.slave_latency;
p_lcb->waiting_update_conn_min_interval = p_dev_rec->conn_params.min_conn_int;
p_lcb->waiting_update_conn_max_interval = p_dev_rec->conn_params.max_conn_int;
p_lcb->waiting_update_conn_timeout = p_dev_rec->conn_params.supervision_tout;
p_lcb->waiting_update_conn_latency = p_dev_rec->conn_params.slave_latency;
btsnd_hcic_ble_upd_ll_conn_params (handle,
p_dev_rec->conn_params.min_conn_int,
@ -403,10 +428,11 @@ void l2cble_advertiser_conn_comp (UINT16 handle, BD_ADDR bda, tBLE_ADDR_TYPE typ
p_lcb->transport = BT_TRANSPORT_LE;
/* update link parameter, set slave link as non-spec default upon link up */
p_lcb->min_interval = p_lcb->max_interval = conn_interval;
p_lcb->timeout = conn_timeout;
p_lcb->latency = conn_latency;
p_lcb->waiting_update_conn_min_interval = p_lcb->waiting_update_conn_max_interval = p_lcb->current_used_conn_interval = conn_interval;
p_lcb->waiting_update_conn_timeout = p_lcb->current_used_conn_timeout = conn_timeout;
p_lcb->waiting_update_conn_latency = p_lcb->current_used_conn_latency = conn_latency;
p_lcb->conn_update_mask = L2C_BLE_NOT_DEFAULT_PARAM;
p_lcb->updating_param_flag = false;
/* Tell BTM Acl management about the link */
p_dev_rec = btm_find_or_alloc_dev (bda);
@ -469,10 +495,10 @@ static BOOLEAN l2cble_start_conn_update (tL2C_LCB *p_lcb)
#if (defined BLE_LLT_INCLUDED) && (BLE_LLT_INCLUDED == TRUE) && (BLE_SLAVE_UPD_CONN_PARAMS == TRUE)
tACL_CONN *p_acl_cb = btm_bda_to_acl(p_lcb->remote_bd_addr, BT_TRANSPORT_LE);
#endif /* defined BLE_LLT_INCLUDED) && (BLE_LLT_INCLUDED == TRUE) && (BLE_SLAVE_UPD_CONN_PARAMS == TRUE */
UINT8 status;
if (p_lcb->conn_update_mask & L2C_BLE_UPDATE_PENDING) {
L2CAP_TRACE_ERROR("%s, the last connection update command still pending.", __func__);
L2CAP_TRACE_WARNING("%s, the last connection update command still pending.", __func__);
p_lcb->conn_update_mask |= L2C_BLE_UPDATE_PARAM_FULL;
return FALSE;
}
@ -482,7 +508,7 @@ static BOOLEAN l2cble_start_conn_update (tL2C_LCB *p_lcb)
up to what has been requested during connection establishement */
if (p_lcb->conn_update_mask & L2C_BLE_NOT_DEFAULT_PARAM &&
/* current connection interval is greater than default min */
p_lcb->min_interval > BTM_BLE_CONN_INT_MIN) {
p_lcb->waiting_update_conn_min_interval > BTM_BLE_CONN_INT_MIN) {
/* use 7.5 ms as fast connection parameter, 0 slave latency */
min_conn_int = max_conn_int = BTM_BLE_CONN_INT_MIN;
slave_latency = BTM_BLE_CONN_SLAVE_LATENCY_DEF;
@ -500,15 +526,16 @@ static BOOLEAN l2cble_start_conn_update (tL2C_LCB *p_lcb)
} else {
l2cu_send_peer_ble_par_req (p_lcb, min_conn_int, max_conn_int, slave_latency, supervision_tout);
}
//cache save
p_lcb->updating_conn_min_interval = min_conn_int;
p_lcb->updating_conn_max_interval = max_conn_int;
p_lcb->updating_param_flag = true;
p_lcb->conn_update_mask |= L2C_BLE_UPDATE_PENDING;
p_lcb->conn_update_mask &= ~L2C_BLE_NOT_DEFAULT_PARAM;
p_lcb->conn_update_mask |= L2C_BLE_NEW_CONN_PARAM;
return TRUE;
} else {
status = HCI_ERR_ILLEGAL_COMMAND;
L2CAP_TRACE_ERROR("%s, staus = %x, line = %d", __func__, status, __LINE__);
btu_stop_timer(&p_lcb->upda_con_timer);
l2c_send_update_conn_params_cb(p_lcb, status);
return FALSE;
}
} else {
@ -521,18 +548,22 @@ static BOOLEAN l2cble_start_conn_update (tL2C_LCB *p_lcb)
HCI_LE_CONN_PARAM_REQ_SUPPORTED(p_acl_cb->peer_le_features))
#endif
) {
btsnd_hcic_ble_upd_ll_conn_params(p_lcb->handle, p_lcb->min_interval,
p_lcb->max_interval, p_lcb->latency, p_lcb->timeout, 0, 0);
btsnd_hcic_ble_upd_ll_conn_params(p_lcb->handle, p_lcb->waiting_update_conn_min_interval,
p_lcb->waiting_update_conn_max_interval, p_lcb->waiting_update_conn_latency, p_lcb->waiting_update_conn_timeout, 0, 0);
} else {
l2cu_send_peer_ble_par_req (p_lcb, p_lcb->min_interval, p_lcb->max_interval,
p_lcb->latency, p_lcb->timeout);
l2cu_send_peer_ble_par_req (p_lcb, p_lcb->waiting_update_conn_min_interval, p_lcb->waiting_update_conn_max_interval,
p_lcb->waiting_update_conn_latency, p_lcb->waiting_update_conn_timeout);
}
//cache save
p_lcb->updating_conn_min_interval = p_lcb->waiting_update_conn_min_interval;
p_lcb->updating_conn_max_interval = p_lcb->waiting_update_conn_max_interval;
p_lcb->updating_param_flag = true;
p_lcb->conn_update_mask |= L2C_BLE_UPDATE_PENDING;
p_lcb->conn_update_mask &= ~L2C_BLE_NEW_CONN_PARAM;
p_lcb->conn_update_mask |= L2C_BLE_NOT_DEFAULT_PARAM;
return TRUE;
} else {
btu_stop_timer(&p_lcb->upda_con_timer);
return FALSE;
}
}
@ -553,37 +584,77 @@ void l2cble_process_conn_update_evt (UINT16 handle, UINT8 status, UINT16 conn_in
{
tL2C_LCB *p_lcb;
L2CAP_TRACE_DEBUG("l2cble_process_conn_update_evt");
L2CAP_TRACE_WARNING("l2cble_process_conn_update_evt: status: %d", status);
/* See if we have a link control block for the remote device */
p_lcb = l2cu_find_lcb_by_handle(handle);
if (!p_lcb) {
L2CAP_TRACE_WARNING("l2cble_process_conn_update_evt: Invalid handle: %d", handle);
return;
}
p_lcb->conn_int = conn_interval;
p_lcb->latency = conn_latency;
p_lcb->timeout = conn_timeout;
tACL_CONN *p_acl_cb = btm_bda_to_acl(p_lcb->remote_bd_addr, BT_TRANSPORT_LE);
p_lcb->conn_update_mask &= ~L2C_BLE_UPDATE_PENDING;
if (status != HCI_SUCCESS) {
if (status == HCI_SUCCESS){
p_lcb->current_used_conn_interval = conn_interval;
p_lcb->current_used_conn_latency = conn_latency;
p_lcb->current_used_conn_timeout = conn_timeout;
}else{
L2CAP_TRACE_WARNING("l2cble_process_conn_update_evt: Error status: %d", status);
}
if (l2cble_start_conn_update(p_lcb) == TRUE) {
btu_start_timer(&p_lcb->upda_con_timer, BTU_TTYPE_L2CAP_UPDA_CONN_PARAMS, L2CAP_UPDATE_CONN_PARAM_TOUT);
}
p_lcb->conn_update_mask &= ~L2C_BLE_UPDATE_PENDING;
p_lcb->conn_update_mask &= ~L2C_BLE_UPDATE_PARAM_FULL;
btu_stop_timer (&p_lcb->timer_entry);
if (p_acl_cb->update_conn_param_cb != NULL) {
btu_stop_timer(&p_lcb->upda_con_timer);
if (conn_param_update_cb.update_conn_param_cb != NULL) {
l2c_send_update_conn_params_cb(p_lcb, status);
}
if (l2cble_start_conn_update(p_lcb) == TRUE) {
UINT32 time = CalConnectParamTimeout(p_lcb);
btu_start_timer(&p_lcb->upda_con_timer, BTU_TTYPE_L2CAP_UPDA_CONN_PARAMS, time);
}
btu_stop_timer (&p_lcb->timer_entry);
L2CAP_TRACE_DEBUG("l2cble_process_conn_update_evt: conn_update_mask=%d", p_lcb->conn_update_mask);
}
/*******************************************************************************
**
** Function l2cble_get_conn_param_format_err_from_contoller
**
** Description This function is called when host get illegal connection paramrters
** format status from controller
**
** Returns void
**
*******************************************************************************/
void l2cble_get_conn_param_format_err_from_contoller (UINT8 status, UINT16 handle)
{
tL2C_LCB *p_lcb;
/* See if we have a link control block for the remote device */
p_lcb = l2cu_find_lcb_by_handle(handle);
if (!p_lcb) {
L2CAP_TRACE_ERROR("%s: Invalid handle: %d", __FUNCTION__, handle);
return;
}
p_lcb->conn_update_mask &= ~L2C_BLE_UPDATE_PENDING;
btu_stop_timer (&p_lcb->upda_con_timer);
if (conn_param_update_cb.update_conn_param_cb != NULL) {
l2c_send_update_conn_params_cb(p_lcb, status);
}
if ((p_lcb->conn_update_mask & L2C_BLE_UPDATE_PARAM_FULL) != 0){
p_lcb->conn_update_mask &= ~L2C_BLE_UPDATE_PARAM_FULL;
if (l2cble_start_conn_update(p_lcb) == TRUE) {
UINT32 time = CalConnectParamTimeout(p_lcb);
btu_start_timer(&p_lcb->upda_con_timer, BTU_TTYPE_L2CAP_UPDA_CONN_PARAMS, time);
}
}
}
/*******************************************************************************
**
** Function l2cble_process_sig_cmd
@ -631,32 +702,33 @@ void l2cble_process_sig_cmd (tL2C_LCB *p_lcb, UINT8 *p, UINT16 pkt_len)
STREAM_TO_UINT16 (timeout, p); /* 0x000A - 0x0C80 */
/* If we are a master, the slave wants to update the parameters */
if (p_lcb->link_role == HCI_ROLE_MASTER) {
if (min_interval < BTM_BLE_CONN_INT_MIN_LIMIT) {
min_interval = BTM_BLE_CONN_INT_MIN_LIMIT;
}
if (min_interval < BTM_BLE_CONN_INT_MIN || min_interval > BTM_BLE_CONN_INT_MAX ||
max_interval < BTM_BLE_CONN_INT_MIN || max_interval > BTM_BLE_CONN_INT_MAX ||
latency > BTM_BLE_CONN_LATENCY_MAX ||
/*(timeout >= max_interval && latency > (timeout * 10/(max_interval * 1.25) - 1)) ||*/
timeout < BTM_BLE_CONN_SUP_TOUT_MIN || timeout > BTM_BLE_CONN_SUP_TOUT_MAX ||
timeout <= ((1 + latency)*BTM_BLE_CONN_INT_MAX*2) ||
/* The supervision_timeout parameter defines the link supervision timeout for the connection.
The supervision_timeout in milliseconds shall be large than (1 + latency) * max_interval * 2,
where max_interval is given in milliseconds. (See [Vol 6] Part B, Section 4.5.2).
supervision_timeout (mult of 10ms); conn_interval (mult of 1.25ms)
(max_interval * 1.25 * 2) replaced by ((max_interval * 5) >> 1).
*/
((timeout * 10) < ((1 + latency) *((max_interval * 5) >> 1))) ||
max_interval < min_interval) {
l2cu_send_peer_ble_par_rsp (p_lcb, L2CAP_CFG_UNACCEPTABLE_PARAMS, id);
UINT8 status = HCI_ERR_PARAM_OUT_OF_RANGE;
l2c_send_update_conn_params_cb(p_lcb, status);
L2CAP_TRACE_ERROR("slave connection parameters update failed, the parameters are out of range");
} else {
l2cu_send_peer_ble_par_rsp (p_lcb, L2CAP_CFG_OK, id);
p_lcb->min_interval = min_interval;
p_lcb->max_interval = max_interval;
p_lcb->latency = latency;
p_lcb->timeout = timeout;
p_lcb->waiting_update_conn_min_interval = min_interval;
p_lcb->waiting_update_conn_max_interval = max_interval;
p_lcb->waiting_update_conn_latency = latency;
p_lcb->waiting_update_conn_timeout = timeout;
p_lcb->conn_update_mask |= L2C_BLE_NEW_CONN_PARAM;
if (l2cble_start_conn_update(p_lcb) == TRUE) {
btu_start_timer(&p_lcb->upda_con_timer, BTU_TTYPE_L2CAP_UPDA_CONN_PARAMS, L2CAP_UPDATE_CONN_PARAM_TOUT);
UINT32 time = CalConnectParamTimeout(p_lcb);
btu_start_timer(&p_lcb->upda_con_timer, BTU_TTYPE_L2CAP_UPDA_CONN_PARAMS, time);
}
}
} else {
@ -670,6 +742,8 @@ void l2cble_process_sig_cmd (tL2C_LCB *p_lcb, UINT8 *p, UINT16 pkt_len)
UINT8 status = (result == 0) ? HCI_SUCCESS : HCI_ERR_PARAM_OUT_OF_RANGE;
if (status != HCI_SUCCESS) {
btu_stop_timer(&p_lcb->upda_con_timer);
p_lcb->conn_update_mask &= ~L2C_BLE_UPDATE_PENDING;
p_lcb->conn_update_mask &= ~L2C_BLE_UPDATE_PARAM_FULL;
l2c_send_update_conn_params_cb(p_lcb, status);
}
break;
@ -946,10 +1020,7 @@ void l2cble_process_rc_param_request_evt(UINT16 handle, UINT16 int_min, UINT16 i
tL2C_LCB *p_lcb = l2cu_find_lcb_by_handle (handle);
if (p_lcb != NULL) {
p_lcb->min_interval = int_min;
p_lcb->max_interval = int_max;
p_lcb->latency = latency;
p_lcb->timeout = timeout;
/* if update is enabled, always accept connection parameter update */
if ((p_lcb->conn_update_mask & L2C_BLE_CONN_UPDATE_DISABLE) == 0) {
p_lcb->conn_update_mask |= L2C_BLE_UPDATE_PENDING;
@ -1088,16 +1159,48 @@ void l2cble_set_fixed_channel_tx_data_length(BD_ADDR remote_bda, UINT16 fix_cid,
*******************************************************************************/
void l2c_send_update_conn_params_cb(tL2C_LCB *p_lcb, UINT8 status)
{
tACL_CONN *p_acl_cb = btm_bda_to_acl(p_lcb->remote_bd_addr, BT_TRANSPORT_LE);
if (p_acl_cb != NULL && p_acl_cb->update_conn_param_cb != NULL) {
if (conn_param_update_cb.update_conn_param_cb != NULL) {
tBTM_LE_UPDATE_CONN_PRAMS update_param;
update_param.max_conn_int = p_lcb->max_interval;
update_param.min_conn_int = p_lcb->min_interval;
update_param.conn_int = p_lcb->conn_int;
update_param.slave_latency = p_lcb->latency;
update_param.supervision_tout = p_lcb->timeout;
(p_acl_cb->update_conn_param_cb)(status, p_acl_cb->active_remote_addr, &update_param);
//if myself update the connection parameters
if (p_lcb->updating_param_flag){
update_param.max_conn_int = p_lcb->updating_conn_max_interval;
update_param.min_conn_int = p_lcb->updating_conn_min_interval;
p_lcb->updating_param_flag = false;
}else{
// remote device update the connection parameters
update_param.max_conn_int = update_param.min_conn_int = 0;
}
// current connection parameters
update_param.conn_int = p_lcb->current_used_conn_interval;
update_param.slave_latency = p_lcb->current_used_conn_latency;
update_param.supervision_tout = p_lcb->current_used_conn_timeout;
(conn_param_update_cb.update_conn_param_cb)(status, p_lcb->remote_bd_addr, &update_param);
}
}
/*******************************************************************************
**
** Function CalConnectParamTimeout
**
** Description This function is called to calculate the connection parameter timeout.
**
** Returns timeout
**
*******************************************************************************/
UINT32 CalConnectParamTimeout(tL2C_LCB *p_lcb)
{
UINT32 timeout = 6;
if (p_lcb != NULL){
//1.25 * conn_int *(1+ latency) *32
timeout = (40 * ( 1 + p_lcb->current_used_conn_latency) * p_lcb->current_used_conn_interval + 500) / 1000;
if (timeout < 1){
timeout = 1;
}else if (timeout > 120){
timeout = 120;
}
}
return timeout;
}
#endif /* (BLE_INCLUDED == TRUE) */

View File

@ -896,7 +896,12 @@ void l2c_process_timeout (TIMER_LIST_ENT *p_tle)
break;
case BTU_TTYPE_L2CAP_UPDA_CONN_PARAMS: {
UINT8 status = HCI_ERR_HOST_TIMEOUT;
l2c_send_update_conn_params_cb((tL2C_LCB *)p_tle->param, status);
tL2C_LCB *p_lcb = (tL2C_LCB *)p_tle->param;
if (p_lcb){
p_lcb->conn_update_mask &= ~L2C_BLE_UPDATE_PENDING;
p_lcb->conn_update_mask &= ~L2C_BLE_UPDATE_PARAM_FULL;
}
l2c_send_update_conn_params_cb(p_lcb, status);
break;
}
}

View File

@ -926,6 +926,11 @@ void l2cu_send_peer_disc_rsp (tL2C_LCB *p_lcb, UINT8 remote_id, UINT16 local_cid
BT_HDR *p_buf;
UINT8 *p;
if (!p_lcb) {
L2CAP_TRACE_WARNING("lcb already released\n");
return;
}
if ((p_buf = l2cu_build_header(p_lcb, L2CAP_DISC_RSP_LEN, L2CAP_CMD_DISC_RSP, remote_id)) == NULL) {
L2CAP_TRACE_WARNING ("L2CAP - no buffer for disc_rsp");
return;
@ -1606,7 +1611,9 @@ void l2cu_release_ccb (tL2C_CCB *p_ccb)
p_ccb->should_free_rcb = false;
}
btm_sec_clr_temp_auth_service (p_lcb->remote_bd_addr);
if (p_lcb) {
btm_sec_clr_temp_auth_service (p_lcb->remote_bd_addr);
}
/* Stop the timer */
btu_stop_timer (&p_ccb->timer_entry);
@ -2635,7 +2642,16 @@ void l2cu_no_dynamic_ccbs (tL2C_LCB *p_lcb)
/* probably no buffer to send disconnect */
timeout = BT_1SEC_TIMEOUT;
}
#else
if (btsnd_hcic_disconnect (p_lcb->handle, HCI_ERR_PEER_USER)) {
l2cu_process_fixed_disc_cback(p_lcb);
p_lcb->link_state = LST_DISCONNECTING;
timeout = L2CAP_LINK_DISCONNECT_TOUT;
} else {
timeout = BT_1SEC_TIMEOUT;
}
#endif ///SMP_INCLUDED == TRUE
}
if (timeout != 0xFFFF) {

View File

@ -223,7 +223,7 @@ static void process_service_search (tCONN_CB *p_ccb, UINT16 trans_num,
}
BE_STREAM_TO_UINT16 (cont_offset, p_req);
if (cont_offset != p_ccb->cont_offset) {
if (cont_offset != p_ccb->cont_offset || num_rsp_handles < cont_offset) {
sdpu_build_n_send_error (p_ccb, trans_num, SDP_INVALID_CONT_STATE,
SDP_TEXT_BAD_CONT_INX);
return;

View File

@ -142,6 +142,8 @@ esp_err_t sdmmc_host_set_card_clk(int slot, uint32_t freq_khz);
* can call sdmmc_host_do_transaction as long as other sdmmc_host_*
* functions are not called.
*
* @attention Data buffer passed in cmdinfo->data must be in DMA capable memory
*
* @param slot slot number (SDMMC_HOST_SLOT_0 or SDMMC_HOST_SLOT_1)
* @param cmdinfo pointer to structure describing command and data to transfer
* @return
@ -149,6 +151,8 @@ esp_err_t sdmmc_host_set_card_clk(int slot, uint32_t freq_khz);
* - ESP_ERR_TIMEOUT if response or data transfer has timed out
* - ESP_ERR_INVALID_CRC if response or data transfer CRC check has failed
* - ESP_ERR_INVALID_RESPONSE if the card has sent an invalid response
* - ESP_ERR_INVALID_SIZE if the size of data transfer is not valid in SD protocol
* - ESP_ERR_INVALID_ARG if the data buffer is not in DMA capable memory
*/
esp_err_t sdmmc_host_do_transaction(int slot, sdmmc_command_t* cmdinfo);

View File

@ -474,6 +474,8 @@ esp_err_t uart_intr_config(uart_port_t uart_num, const uart_intr_config_t *intr_
* @param rx_buffer_size UART RX ring buffer size, rx_buffer_size should be greater than UART_FIFO_LEN.
* @param tx_buffer_size UART TX ring buffer size.
* If set to zero, driver will not use TX buffer, TX function will block task until all data have been sent out..
* @note tx_buffer_size should be greater than UART_FIFO_LEN.
*
* @param queue_size UART event queue size/depth.
* @param uart_queue UART event queue handle (out param). On success, a new queue handle is written here to provide
* access to UART events. If set to NULL, driver will not use an event queue.

View File

@ -70,7 +70,7 @@ const rtc_gpio_desc_t rtc_gpio_desc[GPIO_PIN_COUNT] = {
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //23
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //24
{RTC_IO_PAD_DAC1_REG, RTC_IO_PDAC1_MUX_SEL_M, RTC_IO_PDAC1_FUN_SEL_S, RTC_IO_PDAC1_FUN_IE_M, RTC_IO_PDAC1_RUE_M, RTC_IO_PDAC1_RDE_M, RTC_IO_PDAC1_SLP_SEL_M, RTC_IO_PDAC1_SLP_IE_M, RTC_IO_PDAC1_HOLD_M, RTC_CNTL_PDAC1_HOLD_FORCE_M, 6}, //25
{RTC_IO_PAD_DAC2_REG, RTC_IO_PDAC2_MUX_SEL_M, RTC_IO_PDAC2_FUN_SEL_S, RTC_IO_PDAC2_FUN_IE_M, RTC_IO_PDAC2_RUE_M, RTC_IO_PDAC2_RDE_M, RTC_IO_PDAC2_SLP_SEL_M, RTC_IO_PDAC2_SLP_IE_M, RTC_IO_PDAC2_HOLD_M, RTC_CNTL_PDAC1_HOLD_FORCE_M, 7}, //26
{RTC_IO_PAD_DAC2_REG, RTC_IO_PDAC2_MUX_SEL_M, RTC_IO_PDAC2_FUN_SEL_S, RTC_IO_PDAC2_FUN_IE_M, RTC_IO_PDAC2_RUE_M, RTC_IO_PDAC2_RDE_M, RTC_IO_PDAC2_SLP_SEL_M, RTC_IO_PDAC2_SLP_IE_M, RTC_IO_PDAC2_HOLD_M, RTC_CNTL_PDAC2_HOLD_FORCE_M, 7}, //26
{RTC_IO_TOUCH_PAD7_REG, RTC_IO_TOUCH_PAD7_MUX_SEL_M, RTC_IO_TOUCH_PAD7_FUN_SEL_S, RTC_IO_TOUCH_PAD7_FUN_IE_M, RTC_IO_TOUCH_PAD7_RUE_M, RTC_IO_TOUCH_PAD7_RDE_M, RTC_IO_TOUCH_PAD7_SLP_SEL_M, RTC_IO_TOUCH_PAD7_SLP_IE_M, RTC_IO_TOUCH_PAD7_HOLD_M, RTC_CNTL_TOUCH_PAD7_HOLD_FORCE_M, 17}, //27
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //28
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //29

View File

@ -20,6 +20,7 @@
#include "freertos/semphr.h"
#include "soc/sdmmc_reg.h"
#include "soc/sdmmc_struct.h"
#include "esp_heap_alloc_caps.h"
#include "driver/sdmmc_types.h"
#include "driver/sdmmc_defs.h"
#include "driver/sdmmc_host.h"
@ -105,9 +106,16 @@ esp_err_t sdmmc_host_do_transaction(int slot, sdmmc_command_t* cmdinfo)
// convert cmdinfo to hardware register value
sdmmc_hw_cmd_t hw_cmd = make_hw_cmd(cmdinfo);
if (cmdinfo->data) {
// these constraints should be handled by upper layer
assert(cmdinfo->datalen >= 4);
assert(cmdinfo->blklen % 4 == 0);
if (cmdinfo->datalen < 4 || cmdinfo->blklen % 4 != 0) {
ESP_LOGD(TAG, "%s: invalid size: total=%d block=%d",
__func__, cmdinfo->datalen, cmdinfo->blklen);
return ESP_ERR_INVALID_SIZE;
}
if ((intptr_t) cmdinfo->data % 4 != 0 ||
!esp_ptr_dma_capable(cmdinfo->data)) {
ESP_LOGD(TAG, "%s: buffer %p can not be used for DMA", __func__, cmdinfo->data);
return ESP_ERR_INVALID_ARG;
}
// this clears "owned by IDMAC" bits
memset(s_dma_desc, 0, sizeof(s_dma_desc));
// initialize first descriptor

View File

@ -259,3 +259,64 @@ TEST_CASE("SPI Master test, interaction of multiple devs", "[spi][ignore]") {
destroy_spi_bus(handle1);
}
TEST_CASE("SPI Master no response when switch from host1 (HSPI) to host2 (VSPI)", "[spi]")
{
//spi config
spi_bus_config_t bus_config;
spi_device_interface_config_t device_config;
spi_device_handle_t spi;
spi_host_device_t host;
int dma = 1;
memset(&bus_config, 0, sizeof(spi_bus_config_t));
memset(&device_config, 0, sizeof(spi_device_interface_config_t));
bus_config.miso_io_num = -1;
bus_config.mosi_io_num = 26;
bus_config.sclk_io_num = 25;
bus_config.quadwp_io_num = -1;
bus_config.quadhd_io_num = -1;
device_config.clock_speed_hz = 50000;
device_config.mode = 0;
device_config.spics_io_num = -1;
device_config.queue_size = 1;
device_config.flags = SPI_DEVICE_TXBIT_LSBFIRST | SPI_DEVICE_RXBIT_LSBFIRST;
struct spi_transaction_t transaction = {
.flags = SPI_TRANS_USE_TXDATA | SPI_TRANS_USE_RXDATA,
.length = 16,
.tx_buffer = NULL,
.rx_buffer = NULL,
.tx_data = {0x04, 0x00}
};
//initialize for first host
host = 1;
assert(spi_bus_initialize(host, &bus_config, dma) == ESP_OK);
assert(spi_bus_add_device(host, &device_config, &spi) == ESP_OK);
printf("before first xmit\n");
assert(spi_device_transmit(spi, &transaction) == ESP_OK);
printf("after first xmit\n");
assert(spi_bus_remove_device(spi) == ESP_OK);
assert(spi_bus_free(host) == ESP_OK);
//for second host and failed before
host = 2;
assert(spi_bus_initialize(host, &bus_config, dma) == ESP_OK);
assert(spi_bus_add_device(host, &device_config, &spi) == ESP_OK);
printf("before second xmit\n");
// the original version (bit mis-written) stucks here.
assert(spi_device_transmit(spi, &transaction) == ESP_OK);
// test case success when see this.
printf("after second xmit\n");
}

View File

@ -191,7 +191,7 @@ esp_err_t uart_get_baudrate(uart_port_t uart_num, uint32_t* baudrate)
esp_err_t uart_set_line_inverse(uart_port_t uart_num, uint32_t inverse_mask)
{
UART_CHECK((uart_num < UART_NUM_MAX), "uart_num error", ESP_FAIL);
UART_CHECK((((inverse_mask & ~UART_LINE_INV_MASK) == 0) && (inverse_mask != 0)), "inverse_mask error", ESP_FAIL);
UART_CHECK((((inverse_mask & ~UART_LINE_INV_MASK) == 0) || (inverse_mask == 0)), "inverse_mask error", ESP_FAIL);
UART_ENTER_CRITICAL(&uart_spinlock[uart_num]);
CLEAR_PERI_REG_MASK(UART_CONF0_REG(uart_num), UART_LINE_INV_MASK);
SET_PERI_REG_MASK(UART_CONF0_REG(uart_num), inverse_mask);
@ -970,6 +970,7 @@ esp_err_t uart_driver_install(uart_port_t uart_num, int rx_buffer_size, int tx_b
{
UART_CHECK((uart_num < UART_NUM_MAX), "uart_num error", ESP_FAIL);
UART_CHECK((rx_buffer_size > UART_FIFO_LEN), "uart rx buffer length error(>128)", ESP_FAIL);
UART_CHECK((tx_buffer_size > UART_FIFO_LEN) || (tx_buffer_size == 0), "uart tx buffer length error(>128 or 0)", ESP_FAIL);
if(p_uart_obj[uart_num] == NULL) {
p_uart_obj[uart_num] = (uart_obj_t*) malloc(sizeof(uart_obj_t));
if(p_uart_obj[uart_num] == NULL) {

View File

@ -199,8 +199,24 @@ config MAIN_TASK_STACK_SIZE
int "Main task stack size"
default 4096
help
Config system event task stack size in different application.
Configure the "main task" stack size. This is the stack of the task
which calls app_main(). If app_main() returns then this task is deleted
and its stack memory is freed.
config IPC_TASK_STACK_SIZE
int "Inter-Processor Call (IPC) task stack size"
default 1024
range 512 65536 if !ESP32_APPTRACE_ENABLE
range 2048 65536 if ESP32_APPTRACE_ENABLE
help
Configure the IPC tasks stack size. One IPC task runs on each core
(in dual core mode), and allows for cross-core function calls.
See IPC documentation for more details.
The default stack size should be enough for most common use cases.
It can be shrunk if you are sure that you do not use any custom
IPC functionality.
config NEWLIB_STDOUT_ADDCR
bool "Standard-out output adds carriage return before newline"
@ -566,7 +582,7 @@ config ESP32_DEEP_SLEEP_WAKEUP_DELAY
choice ESP32_XTAL_FREQ_SEL
prompt "Main XTAL frequency"
default ESP32_XTAL_FREQ_AUTO
default ESP32_XTAL_FREQ_40
help
ESP32 currently supports the following XTAL frequencies:
- 26 MHz

View File

@ -22,6 +22,7 @@
#include <stdint.h>
#include <string.h>
#include <sdkconfig.h>
#include "esp_attr.h"
#include "esp_err.h"
#include "esp_intr.h"
@ -145,16 +146,20 @@ void IRAM_ATTR esp_dport_access_stall_other_cpu_end_wrap(void)
DPORT_STALL_OTHER_CPU_END();
}
static void dport_access_init_core0(void *arg)
static void dport_access_init_core(void *arg)
{
int core_id = xPortGetCoreID();
int core_id = 0;
uint32_t intr_source = ETS_FROM_CPU_INTR2_SOURCE;
assert(core_id == 0);
vPortCPUInitializeMutex(&g_dport_mux);
#ifndef CONFIG_FREERTOS_UNICORE
core_id = xPortGetCoreID();
if (core_id == 1) {
intr_source = ETS_FROM_CPU_INTR3_SOURCE;
}
#endif
ESP_INTR_DISABLE(ETS_DPORT_INUM);
intr_matrix_set(core_id, ETS_FROM_CPU_INTR2_SOURCE, ETS_DPORT_INUM);
intr_matrix_set(core_id, intr_source, ETS_DPORT_INUM);
ESP_INTR_ENABLE(ETS_DPORT_INUM);
dport_access_ref[core_id] = 0;
@ -165,33 +170,10 @@ static void dport_access_init_core0(void *arg)
vTaskDelete(NULL);
}
static void dport_access_init_core1(void *arg)
{
int core_id = xPortGetCoreID();
assert(core_id == 1);
ESP_INTR_DISABLE(ETS_DPORT_INUM);
intr_matrix_set(core_id, ETS_FROM_CPU_INTR3_SOURCE, ETS_DPORT_INUM);
ESP_INTR_ENABLE(ETS_DPORT_INUM);
dport_access_ref[core_id] = 0;
dport_access_start[core_id] = 0;
dport_access_end[core_id] = 0;
dport_core_state[core_id] = DPORT_CORE_STATE_RUNNING;
vTaskDelete(NULL);
}
/* This initialise should be really effective after vTaskStartScheduler */
/* Defer initialisation until after scheduler is running */
void esp_dport_access_int_init(void)
{
if (xPortGetCoreID() == 0) {
xTaskCreatePinnedToCore(&dport_access_init_core0, "dport0", 512, NULL, 5, NULL, 0);
} else {
xTaskCreatePinnedToCore(&dport_access_init_core1, "dport1", 512, NULL, 5, NULL, 1);
}
xTaskCreatePinnedToCore(&dport_access_init_core, "dport", configMINIMAL_STACK_SIZE, NULL, 5, NULL, xPortGetCoreID());
}
void esp_dport_access_int_deinit(void)
@ -203,3 +185,12 @@ void esp_dport_access_int_deinit(void)
#endif
portEXIT_CRITICAL_ISR(&g_dport_mux);
}
void esp_dport_access_int_abort(void)
{
dport_core_state[0] = DPORT_CORE_STATE_IDLE;
#ifndef CONFIG_FREERTOS_UNICORE
dport_core_state[1] = DPORT_CORE_STATE_IDLE;
#endif
}

View File

@ -23,6 +23,7 @@ void esp_dport_access_stall_other_cpu_start(void);
void esp_dport_access_stall_other_cpu_end(void);
void esp_dport_access_int_init(void);
void esp_dport_access_int_deinit(void);
void esp_dport_access_int_abort(void);
#if defined(BOOTLOADER_BUILD) || defined(CONFIG_FREERTOS_UNICORE) || !defined(ESP_PLATFORM)
#define DPORT_STALL_OTHER_CPU_START()

View File

@ -57,6 +57,10 @@ void esp_ipc_init();
*
* In single-core mode, returns ESP_ERR_INVALID_ARG for cpu_id 1.
*
* For complex functions, you may need to increase the stack size of the "IPC task"
* which runs the function must be sufficient. See the "Inter-Processor Call (IPC)
* task stack size" setting in menuconfig.
*
* @param cpu_id CPU where function should be executed (0 or 1)
* @param func pointer to a function which should be executed
* @param arg arbitrary argument to be passed into function

View File

@ -30,112 +30,7 @@ extern "C" {
* @brief Structure holding PHY init parameters
*/
typedef struct {
uint8_t param_ver_id; /*!< init_data structure version */
uint8_t crystal_select; /*!< 0: 40MHz, 1: 26 MHz, 2: 24 MHz, 3: auto */
uint8_t wifi_rx_gain_swp_step_1; /*!< do not change */
uint8_t wifi_rx_gain_swp_step_2; /*!< do not change */
uint8_t wifi_rx_gain_swp_step_3; /*!< do not change */
uint8_t wifi_rx_gain_swp_step_4; /*!< do not change */
uint8_t wifi_rx_gain_swp_step_5; /*!< do not change */
uint8_t wifi_rx_gain_swp_step_6; /*!< do not change */
uint8_t wifi_rx_gain_swp_step_7; /*!< do not change */
uint8_t wifi_rx_gain_swp_step_8; /*!< do not change */
uint8_t wifi_rx_gain_swp_step_9; /*!< do not change */
uint8_t wifi_rx_gain_swp_step_10; /*!< do not change */
uint8_t wifi_rx_gain_swp_step_11; /*!< do not change */
uint8_t wifi_rx_gain_swp_step_12; /*!< do not change */
uint8_t wifi_rx_gain_swp_step_13; /*!< do not change */
uint8_t wifi_rx_gain_swp_step_14; /*!< do not change */
uint8_t wifi_rx_gain_swp_step_15; /*!< do not change */
uint8_t bt_rx_gain_swp_step_1; /*!< do not change */
uint8_t bt_rx_gain_swp_step_2; /*!< do not change */
uint8_t bt_rx_gain_swp_step_3; /*!< do not change */
uint8_t bt_rx_gain_swp_step_4; /*!< do not change */
uint8_t bt_rx_gain_swp_step_5; /*!< do not change */
uint8_t bt_rx_gain_swp_step_6; /*!< do not change */
uint8_t bt_rx_gain_swp_step_7; /*!< do not change */
uint8_t bt_rx_gain_swp_step_8; /*!< do not change */
uint8_t bt_rx_gain_swp_step_9; /*!< do not change */
uint8_t bt_rx_gain_swp_step_10; /*!< do not change */
uint8_t bt_rx_gain_swp_step_11; /*!< do not change */
uint8_t bt_rx_gain_swp_step_12; /*!< do not change */
uint8_t bt_rx_gain_swp_step_13; /*!< do not change */
uint8_t bt_rx_gain_swp_step_14; /*!< do not change */
uint8_t bt_rx_gain_swp_step_15; /*!< do not change */
uint8_t gain_cmp_1; /*!< do not change */
uint8_t gain_cmp_6; /*!< do not change */
uint8_t gain_cmp_11; /*!< do not change */
uint8_t gain_cmp_ext2_1; /*!< do not change */
uint8_t gain_cmp_ext2_6; /*!< do not change */
uint8_t gain_cmp_ext2_11; /*!< do not change */
uint8_t gain_cmp_ext3_1; /*!< do not change */
uint8_t gain_cmp_ext3_6; /*!< do not change */
uint8_t gain_cmp_ext3_11; /*!< do not change */
uint8_t gain_cmp_bt_ofs_1; /*!< do not change */
uint8_t gain_cmp_bt_ofs_6; /*!< do not change */
uint8_t gain_cmp_bt_ofs_11; /*!< do not change */
uint8_t target_power_qdb_0; /*!< 78 means target power is 78/4=19.5dbm */
uint8_t target_power_qdb_1; /*!< 76 means target power is 76/4=19dbm */
uint8_t target_power_qdb_2; /*!< 74 means target power is 74/4=18.5dbm */
uint8_t target_power_qdb_3; /*!< 68 means target power is 68/4=17dbm */
uint8_t target_power_qdb_4; /*!< 64 means target power is 64/4=16dbm */
uint8_t target_power_qdb_5; /*!< 52 means target power is 52/4=13dbm */
uint8_t target_power_index_mcs0; /*!< target power index is 0, means target power is target_power_qdb_0 19.5dbm; (1m,2m,5.5m,11m,6m,9m) */
uint8_t target_power_index_mcs1; /*!< target power index is 0, means target power is target_power_qdb_0 19.5dbm; (12m) */
uint8_t target_power_index_mcs2; /*!< target power index is 1, means target power is target_power_qdb_1 19dbm; (18m) */
uint8_t target_power_index_mcs3; /*!< target power index is 1, means target power is target_power_qdb_1 19dbm; (24m) */
uint8_t target_power_index_mcs4; /*!< target power index is 2, means target power is target_power_qdb_2 18.5dbm; (36m) */
uint8_t target_power_index_mcs5; /*!< target power index is 3, means target power is target_power_qdb_3 17dbm; (48m) */
uint8_t target_power_index_mcs6; /*!< target power index is 4, means target power is target_power_qdb_4 16dbm; (54m) */
uint8_t target_power_index_mcs7; /*!< target power index is 5, means target power is target_power_qdb_5 13dbm */
uint8_t pwr_ind_11b_en; /*!< 0: 11b power is same as mcs0 and 6m, 1: 11b power different with OFDM */
uint8_t pwr_ind_11b_0; /*!< 1m, 2m power index [0~5] */
uint8_t pwr_ind_11b_1; /*!< 5.5m, 11m power index [0~5] */
uint8_t chan_backoff_en; /*!< 0: channel backoff disable, 1:channel backoff enable */
uint8_t chan1_power_backoff_qdb; /*!< 4 means backoff is 1db */
uint8_t chan2_power_backoff_qdb; /*!< see chan1_power_backoff_qdb */
uint8_t chan3_power_backoff_qdb; /*!< chan1_power_backoff_qdb */
uint8_t chan4_power_backoff_qdb; /*!< chan1_power_backoff_qdb */
uint8_t chan5_power_backoff_qdb; /*!< chan1_power_backoff_qdb */
uint8_t chan6_power_backoff_qdb; /*!< chan1_power_backoff_qdb */
uint8_t chan7_power_backoff_qdb; /*!< chan1_power_backoff_qdb */
uint8_t chan8_power_backoff_qdb; /*!< chan1_power_backoff_qdb */
uint8_t chan9_power_backoff_qdb; /*!< chan1_power_backoff_qdb */
uint8_t chan10_power_backoff_qdb; /*!< chan1_power_backoff_qdb */
uint8_t chan11_power_backoff_qdb; /*!< chan1_power_backoff_qdb */
uint8_t chan12_power_backoff_qdb; /*!< chan1_power_backoff_qdb */
uint8_t chan13_power_backoff_qdb; /*!< chan1_power_backoff_qdb */
uint8_t chan14_power_backoff_qdb; /*!< chan1_power_backoff_qdb */
uint8_t chan1_rate_backoff_index; /*!< if bit i is set, backoff data rate is target_power_qdb_i */
uint8_t chan2_rate_backoff_index; /*!< see chan1_rate_backoff_index */
uint8_t chan3_rate_backoff_index; /*!< see chan1_rate_backoff_index */
uint8_t chan4_rate_backoff_index; /*!< see chan1_rate_backoff_index */
uint8_t chan5_rate_backoff_index; /*!< see chan1_rate_backoff_index */
uint8_t chan6_rate_backoff_index; /*!< see chan1_rate_backoff_index */
uint8_t chan7_rate_backoff_index; /*!< see chan1_rate_backoff_index */
uint8_t chan8_rate_backoff_index; /*!< see chan1_rate_backoff_index */
uint8_t chan9_rate_backoff_index; /*!< see chan1_rate_backoff_index */
uint8_t chan10_rate_backoff_index; /*!< see chan1_rate_backoff_index */
uint8_t chan11_rate_backoff_index; /*!< see chan1_rate_backoff_index */
uint8_t chan12_rate_backoff_index; /*!< see chan1_rate_backoff_index */
uint8_t chan13_rate_backoff_index; /*!< see chan1_rate_backoff_index */
uint8_t chan14_rate_backoff_index; /*!< see chan1_rate_backoff_index */
uint8_t spur_freq_cfg_msb_1; /*!< first spur: */
uint8_t spur_freq_cfg_1; /*!< spur_freq_cfg = (spur_freq_cfg_msb_1 <<8) | spur_freq_cfg_1 */
uint8_t spur_freq_cfg_div_1; /*!< spur_freq=spur_freq_cfg/spur_freq_cfg_div_1 */
uint8_t spur_freq_en_h_1; /*!< the seventh bit for total enable */
uint8_t spur_freq_en_l_1; /*!< each bit for 1 channel, and use [spur_freq_en_h, spur_freq_en_l] to select the spur's channel priority */
uint8_t spur_freq_cfg_msb_2; /*!< second spur: */
uint8_t spur_freq_cfg_2; /*!< spur_freq_cfg = (spur_freq_cfg_msb_2 <<8) | spur_freq_cfg_2 */
uint8_t spur_freq_cfg_div_2; /*!< spur_freq=spur_freq_cfg/spur_freq_cfg_div_2 */
uint8_t spur_freq_en_h_2; /*!< the seventh bit for total enable */
uint8_t spur_freq_en_l_2; /*!< each bit for 1 channel, and use [spur_freq_en_h, spur_freq_en_l] to select the spur's channel priority */
uint8_t spur_freq_cfg_msb_3; /*!< third spur: */
uint8_t spur_freq_cfg_3; /*!< spur_freq_cfg = (spur_freq_cfg_msb_3 <<8) | spur_freq_cfg_3 */
uint8_t spur_freq_cfg_div_3; /*!< spur_freq=spur_freq_cfg/spur_freq_cfg_div_3 */
uint8_t spur_freq_en_h_3; /*!< the seventh bit for total enable */
uint8_t spur_freq_en_l_3; /*!< each bit for 1 channel, and use [spur_freq_en_h, spur_freq_en_l] to select the spur's channel priority, */
uint8_t reserved[23]; /*!< reserved for future expansion */
uint8_t params[128]; /*!< opaque PHY initialization parameters */
} esp_phy_init_data_t;
/**

View File

@ -267,7 +267,7 @@ void uart_tx_flush(uint8_t uart_no);
* The function defined in ROM code has a bug, so we define the correct version
* here for compatibility.
*/
static inline void uart_tx_wait_idle(uint8_t uart_no) {
static inline void IRAM_ATTR uart_tx_wait_idle(uint8_t uart_no) {
while(REG_GET_FIELD(UART_STATUS_REG(uart_no), UART_ST_UTX_OUT)) {
;
}

View File

@ -80,7 +80,7 @@ void esp_ipc_init()
const char* task_names[2] = {"ipc0", "ipc1"};
for (int i = 0; i < portNUM_PROCESSORS; ++i) {
s_ipc_sem[i] = xSemaphoreCreateBinary();
xTaskCreatePinnedToCore(ipc_task, task_names[i], XT_STACK_MIN_SIZE, (void*) i,
xTaskCreatePinnedToCore(ipc_task, task_names[i], CONFIG_IPC_TASK_STACK_SIZE, (void*) i,
configMAX_PRIORITIES - 1, &s_ipc_tasks[i], i);
}
}

View File

@ -432,6 +432,8 @@ PROVIDE ( r_ea_interval_delete = 0x400155a8 );
PROVIDE ( r_ea_interval_duration_req = 0x4001597c );
PROVIDE ( r_ea_interval_insert = 0x4001557c );
PROVIDE ( r_ea_interval_remove = 0x40015590 );
PROVIDE ( ea_conflict_check = 0x40014e9c );
PROVIDE ( ea_prog_timer = 0x40014f88 );
PROVIDE ( realloc = 0x4000becc );
PROVIDE ( _realloc_r = 0x4000bbe0 );
PROVIDE ( r_ea_offset_req = 0x40015748 );
@ -1855,6 +1857,7 @@ PROVIDE ( ets_update_cpu_frequency_rom = 0x40008550 ); /* Updates g_ticks_per_u
/* Following are static data, but can be used, not generated by script <<<<< btdm data */
PROVIDE ( hci_tl_env = 0x3ffb8154 );
PROVIDE ( ld_acl_env = 0x3ffb8258 );
PROVIDE ( ea_env = 0x3ffb80ec );
PROVIDE ( ld_active_ch_map = 0x3ffb8334 );
PROVIDE ( ld_bcst_acl_env = 0x3ffb8274 );
PROVIDE ( ld_csb_rx_env = 0x3ffb8278 );

View File

@ -119,7 +119,7 @@ const esp_phy_init_data_t* esp_phy_get_init_data()
ESP_LOGE(TAG, "failed to validate PHY data partition");
return NULL;
}
ESP_LOGE(TAG, "PHY data partition validated");
ESP_LOGD(TAG, "PHY data partition validated");
return (const esp_phy_init_data_t*) (init_data_store + sizeof(phy_init_magic_pre));
}
@ -159,22 +159,18 @@ static esp_err_t store_cal_data_to_nvs_handle(nvs_handle handle,
esp_err_t esp_phy_load_cal_data_from_nvs(esp_phy_calibration_data_t* out_cal_data)
{
esp_err_t err = nvs_flash_init();
if (err != ESP_OK) {
ESP_LOGW(TAG, "%s: failed to initialize NVS (0x%x)", __func__, err);
return err;
}
nvs_handle handle;
err = nvs_open(PHY_NAMESPACE, NVS_READONLY, &handle);
if (err != ESP_OK) {
esp_err_t err = nvs_open(PHY_NAMESPACE, NVS_READONLY, &handle);
if (err == ESP_ERR_NVS_NOT_INITIALIZED) {
ESP_LOGE(TAG, "%s: NVS has not been initialized. "
"Call nvs_flash_init before starting WiFi/BT.", __func__);
} else if (err != ESP_OK) {
ESP_LOGD(TAG, "%s: failed to open NVS namespace (0x%x)", __func__, err);
return err;
}
else {
err = load_cal_data_from_nvs_handle(handle, out_cal_data);
nvs_close(handle);
return err;
}
err = load_cal_data_from_nvs_handle(handle, out_cal_data);
nvs_close(handle);
return err;
}
esp_err_t esp_phy_store_cal_data_to_nvs(const esp_phy_calibration_data_t* cal_data)
@ -245,19 +241,34 @@ static esp_err_t store_cal_data_to_nvs_handle(nvs_handle handle,
const esp_phy_calibration_data_t* cal_data)
{
esp_err_t err;
uint32_t cal_format_version = phy_get_rf_cal_version() & (~BIT(16));
ESP_LOGV(TAG, "phy_get_rf_cal_version: %d\n", cal_format_version);
err = nvs_set_u32(handle, PHY_CAL_VERSION_KEY, cal_format_version);
err = nvs_set_blob(handle, PHY_CAL_DATA_KEY, cal_data, sizeof(*cal_data));
if (err != ESP_OK) {
ESP_LOGE(TAG, "%s: store calibration data failed(0x%x)\n", __func__, err);
return err;
}
uint8_t sta_mac[6];
esp_efuse_mac_get_default(sta_mac);
err = nvs_set_blob(handle, PHY_CAL_MAC_KEY, sta_mac, sizeof(sta_mac));
if (err != ESP_OK) {
ESP_LOGE(TAG, "%s: store calibration mac failed(0x%x)\n", __func__, err);
return err;
}
err = nvs_set_blob(handle, PHY_CAL_DATA_KEY, cal_data, sizeof(*cal_data));
uint32_t cal_format_version = phy_get_rf_cal_version() & (~BIT(16));
ESP_LOGV(TAG, "phy_get_rf_cal_version: %d\n", cal_format_version);
err = nvs_set_u32(handle, PHY_CAL_VERSION_KEY, cal_format_version);
if (err != ESP_OK) {
ESP_LOGE(TAG, "%s: store calibration version failed(0x%x)\n", __func__, err);
return err;
}
err = nvs_commit(handle);
if (err != ESP_OK) {
ESP_LOGE(TAG, "%s: store calibration nvs commit failed(0x%x)\n", __func__, err);
}
return err;
}
@ -270,17 +281,18 @@ void esp_phy_load_cal_and_init(void)
abort();
}
#ifdef CONFIG_ESP32_PHY_CALIBRATION_AND_DATA_STORAGE
esp_phy_calibration_mode_t calibration_mode = PHY_RF_CAL_PARTIAL;
if (rtc_get_reset_reason(0) == DEEPSLEEP_RESET) {
calibration_mode = PHY_RF_CAL_NONE;
}
const esp_phy_init_data_t* init_data = esp_phy_get_init_data();
if (init_data == NULL) {
ESP_LOGE(TAG, "failed to obtain PHY init data");
abort();
}
#ifdef CONFIG_ESP32_PHY_CALIBRATION_AND_DATA_STORAGE
esp_phy_calibration_mode_t calibration_mode = PHY_RF_CAL_PARTIAL;
if (rtc_get_reset_reason(0) == DEEPSLEEP_RESET) {
calibration_mode = PHY_RF_CAL_NONE;
}
esp_err_t err = esp_phy_load_cal_data_from_nvs(cal_data);
if (err != ESP_OK) {
ESP_LOGW(TAG, "failed to load RF calibration data (0x%x), falling back to full calibration", err);
@ -296,7 +308,7 @@ void esp_phy_load_cal_and_init(void)
}
esp_phy_release_init_data(init_data);
#else
esp_phy_rf_init(NULL, PHY_RF_CAL_FULL, cal_data);
esp_phy_rf_init(init_data, PHY_RF_CAL_FULL, cal_data);
#endif
free(cal_data); // PHY maintains a copy of calibration data, so we can free this

View File

@ -26,114 +26,115 @@ static const char phy_init_magic_pre[] = PHY_INIT_MAGIC;
/**
* @brief Structure containing default recommended PHY initialization parameters.
*/
static const esp_phy_init_data_t phy_init_data= {
.param_ver_id = 1,
.crystal_select = 3,
.wifi_rx_gain_swp_step_1 = 0x05,
.wifi_rx_gain_swp_step_2 = 0x04,
.wifi_rx_gain_swp_step_3 = 0x06,
.wifi_rx_gain_swp_step_4 = 0x05,
.wifi_rx_gain_swp_step_5 = 0x01,
.wifi_rx_gain_swp_step_6 = 0x06,
.wifi_rx_gain_swp_step_7 = 0x05,
.wifi_rx_gain_swp_step_8 = 0x04,
.wifi_rx_gain_swp_step_9 = 0x06,
.wifi_rx_gain_swp_step_10 = 0x04,
.wifi_rx_gain_swp_step_11 = 0x05,
.wifi_rx_gain_swp_step_12 = 0x00,
.wifi_rx_gain_swp_step_13 = 0x00,
.wifi_rx_gain_swp_step_14 = 0x00,
.wifi_rx_gain_swp_step_15 = 0x00,
.bt_rx_gain_swp_step_1 = 0x05,
.bt_rx_gain_swp_step_2 = 0x04,
.bt_rx_gain_swp_step_3 = 0x06,
.bt_rx_gain_swp_step_4 = 0x05,
.bt_rx_gain_swp_step_5 = 0x01,
.bt_rx_gain_swp_step_6 = 0x06,
.bt_rx_gain_swp_step_7 = 0x05,
.bt_rx_gain_swp_step_8 = 0x00,
.bt_rx_gain_swp_step_9 = 0x00,
.bt_rx_gain_swp_step_10 = 0x00,
.bt_rx_gain_swp_step_11 = 0x00,
.bt_rx_gain_swp_step_12 = 0x00,
.bt_rx_gain_swp_step_13 = 0x00,
.bt_rx_gain_swp_step_14 = 0x00,
.bt_rx_gain_swp_step_15 = 0x00,
.gain_cmp_1 = 0x0a,
.gain_cmp_6 = 0x0a,
.gain_cmp_11 = 0x0c,
.gain_cmp_ext2_1 = 0xf0,
.gain_cmp_ext2_6 = 0xf0,
.gain_cmp_ext2_11 = 0xf0,
.gain_cmp_ext3_1 = 0xe0,
.gain_cmp_ext3_6 = 0xe0,
.gain_cmp_ext3_11 = 0xe0,
.gain_cmp_bt_ofs_1 = 0x18,
.gain_cmp_bt_ofs_6 = 0x18,
.gain_cmp_bt_ofs_11 = 0x18,
.target_power_qdb_0 = LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 78),
.target_power_qdb_1 = LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 76),
.target_power_qdb_2 = LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 74),
.target_power_qdb_3 = LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 68),
.target_power_qdb_4 = LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 60),
.target_power_qdb_5 = LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 52),
.target_power_index_mcs0 = 0,
.target_power_index_mcs1 = 0,
.target_power_index_mcs2 = 1,
.target_power_index_mcs3 = 1,
.target_power_index_mcs4 = 2,
.target_power_index_mcs5 = 3,
.target_power_index_mcs6 = 4,
.target_power_index_mcs7 = 5,
.pwr_ind_11b_en = 0,
.pwr_ind_11b_0 = 0,
.pwr_ind_11b_1 = 0,
.chan_backoff_en = 0,
.chan1_power_backoff_qdb = 0,
.chan2_power_backoff_qdb = 0,
.chan3_power_backoff_qdb = 0,
.chan4_power_backoff_qdb = 0,
.chan5_power_backoff_qdb = 0,
.chan6_power_backoff_qdb = 0,
.chan7_power_backoff_qdb = 0,
.chan8_power_backoff_qdb = 0,
.chan9_power_backoff_qdb = 0,
.chan10_power_backoff_qdb = 0,
.chan11_power_backoff_qdb = 0,
.chan12_power_backoff_qdb = 0,
.chan13_power_backoff_qdb = 0,
.chan14_power_backoff_qdb = 0,
.chan1_rate_backoff_index = 0,
.chan2_rate_backoff_index = 0,
.chan3_rate_backoff_index = 0,
.chan4_rate_backoff_index = 0,
.chan5_rate_backoff_index = 0,
.chan6_rate_backoff_index = 0,
.chan7_rate_backoff_index = 0,
.chan8_rate_backoff_index = 0,
.chan9_rate_backoff_index = 0,
.chan10_rate_backoff_index = 0,
.chan11_rate_backoff_index = 0,
.chan12_rate_backoff_index = 0,
.chan13_rate_backoff_index = 0,
.chan14_rate_backoff_index = 0,
.spur_freq_cfg_msb_1 = 0,
.spur_freq_cfg_1 = 0,
.spur_freq_cfg_div_1 = 0,
.spur_freq_en_h_1 = 0,
.spur_freq_en_l_1 = 0,
.spur_freq_cfg_msb_2 = 0,
.spur_freq_cfg_2 = 0,
.spur_freq_cfg_div_2 = 0,
.spur_freq_en_h_2 = 0,
.spur_freq_en_l_2 = 0,
.spur_freq_cfg_msb_3 = 0,
.spur_freq_cfg_3 = 0,
.spur_freq_cfg_div_3 = 0,
.spur_freq_en_h_3 = 0,
.spur_freq_en_l_3 = 0,
.reserved = {0}
};
static const esp_phy_init_data_t phy_init_data= { {
3,
3,
0x05,
0x09,
0x06,
0x05,
0x03,
0x06,
0x05,
0x04,
0x06,
0x04,
0x05,
0x00,
0x00,
0x00,
0x00,
0x05,
0x09,
0x06,
0x05,
0x03,
0x06,
0x05,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0xfc,
0xfc,
0xfe,
0xf0,
0xf0,
0xf0,
0xe0,
0xe0,
0xe0,
0x18,
0x18,
0x18,
LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 78),
LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 72),
LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 66),
LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 60),
LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 56),
LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 52),
0,
1,
1,
2,
2,
3,
4,
5,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
} };
static const char phy_init_magic_post[] = PHY_INIT_MAGIC;

View File

@ -256,22 +256,31 @@ void IRAM_ATTR esp_restart(void)
*/
void IRAM_ATTR esp_restart_noos()
{
const uint32_t core_id = xPortGetCoreID();
const uint32_t other_core_id = core_id == 0 ? 1 : 0;
esp_cpu_stall(other_core_id);
// Disable interrupts
xt_ints_off(0xFFFFFFFF);
// other core is now stalled, can access DPORT registers directly
esp_dport_access_int_deinit();
// We need to disable TG0/TG1 watchdogs
// First enable RTC watchdog to be on the safe side
// Enable RTC watchdog for 1 second
REG_WRITE(RTC_CNTL_WDTWPROTECT_REG, RTC_CNTL_WDT_WKEY_VALUE);
REG_WRITE(RTC_CNTL_WDTCONFIG0_REG,
RTC_CNTL_WDT_FLASHBOOT_MOD_EN_M |
(RTC_WDT_STG_SEL_RESET_SYSTEM << RTC_CNTL_WDT_STG0_S) |
(RTC_WDT_STG_SEL_RESET_RTC << RTC_CNTL_WDT_STG1_S) |
(1 << RTC_CNTL_WDT_SYS_RESET_LENGTH_S) |
(1 << RTC_CNTL_WDT_CPU_RESET_LENGTH_S) );
REG_WRITE(RTC_CNTL_WDTCONFIG1_REG, 128000);
// Reset and stall the other CPU.
// CPU must be reset before stalling, in case it was running a s32c1i
// instruction. This would cause memory pool to be locked by arbiter
// to the stalled CPU, preventing current CPU from accessing this pool.
const uint32_t core_id = xPortGetCoreID();
const uint32_t other_core_id = (core_id == 0) ? 1 : 0;
esp_cpu_reset(other_core_id);
esp_cpu_stall(other_core_id);
// Other core is now stalled, can access DPORT registers directly
esp_dport_access_int_abort();
// Disable TG0/TG1 watchdogs
TIMERG0.wdt_wprotect=TIMG_WDT_WKEY_VALUE;
TIMERG0.wdt_config0.en = 0;
@ -280,8 +289,6 @@ void IRAM_ATTR esp_restart_noos()
TIMERG1.wdt_config0.en = 0;
TIMERG1.wdt_wprotect=0;
// Disable all interrupts
xt_ints_off(0xFFFFFFFF);
// Disable cache
Cache_Read_Disable(0);
@ -291,6 +298,14 @@ void IRAM_ATTR esp_restart_noos()
uart_tx_wait_idle(0);
uart_tx_wait_idle(1);
uart_tx_wait_idle(2);
// 2nd stage bootloader reconfigures SPI flash signals.
// Reset them to the defaults expected by ROM.
WRITE_PERI_REG(GPIO_FUNC0_IN_SEL_CFG_REG, 0x30);
WRITE_PERI_REG(GPIO_FUNC1_IN_SEL_CFG_REG, 0x30);
WRITE_PERI_REG(GPIO_FUNC2_IN_SEL_CFG_REG, 0x30);
WRITE_PERI_REG(GPIO_FUNC3_IN_SEL_CFG_REG, 0x30);
WRITE_PERI_REG(GPIO_FUNC4_IN_SEL_CFG_REG, 0x30);
WRITE_PERI_REG(GPIO_FUNC5_IN_SEL_CFG_REG, 0x30);
// Reset wifi/bluetooth/ethernet/sdio (bb/mac)
DPORT_SET_PERI_REG_MASK(DPORT_CORE_RST_EN_REG,
@ -314,14 +329,14 @@ void IRAM_ATTR esp_restart_noos()
// Reset CPUs
if (core_id == 0) {
// Running on PRO CPU: APP CPU is stalled. Can reset both CPUs.
SET_PERI_REG_MASK(RTC_CNTL_OPTIONS0_REG,
RTC_CNTL_SW_PROCPU_RST_M | RTC_CNTL_SW_APPCPU_RST_M);
esp_cpu_reset(1);
esp_cpu_reset(0);
} else {
// Running on APP CPU: need to reset PRO CPU and unstall it,
// then reset APP CPU
SET_PERI_REG_MASK(RTC_CNTL_OPTIONS0_REG, RTC_CNTL_SW_PROCPU_RST_M);
esp_cpu_reset(0);
esp_cpu_unstall(0);
SET_PERI_REG_MASK(RTC_CNTL_OPTIONS0_REG, RTC_CNTL_SW_APPCPU_RST_M);
esp_cpu_reset(1);
}
while(true) {
;
@ -349,6 +364,7 @@ const char* esp_get_idf_version(void)
static void get_chip_info_esp32(esp_chip_info_t* out_info)
{
out_info->model = CHIP_ESP32;
uint32_t reg = REG_READ(EFUSE_BLK0_RDATA3_REG);
memset(out_info, 0, sizeof(*out_info));
if ((reg & EFUSE_RD_CHIP_VER_REV1_M) != 0) {
@ -363,8 +379,10 @@ static void get_chip_info_esp32(esp_chip_info_t* out_info)
if ((reg & EFUSE_RD_CHIP_VER_DIS_BT_M) == 0) {
out_info->features |= CHIP_FEATURE_BT | CHIP_FEATURE_BLE;
}
if (((reg & EFUSE_RD_CHIP_VER_PKG_M) >> EFUSE_RD_CHIP_VER_PKG_S) ==
EFUSE_RD_CHIP_VER_PKG_ESP32D2WDQ5) {
int package = (reg & EFUSE_RD_CHIP_VER_PKG_M) >> EFUSE_RD_CHIP_VER_PKG_S;
if (package == EFUSE_RD_CHIP_VER_PKG_ESP32D2WDQ5 ||
package == EFUSE_RD_CHIP_VER_PKG_ESP32PICOD2 ||
package == EFUSE_RD_CHIP_VER_PKG_ESP32PICOD4) {
out_info->features |= CHIP_FEATURE_EMB_FLASH;
}
}

View File

@ -10,6 +10,7 @@
*/
#include "FreeRTOS.h"
#include "esp_attr.h"
#include "sdkconfig.h"
#ifdef __GNUC__
@ -19,5 +20,5 @@
#endif
#ifdef CONFIG_ESP32_DEBUG_OCDAWARE
const int USED uxTopUsedPriority = configMAX_PRIORITIES - 1;
#endif
const int USED DRAM_ATTR uxTopUsedPriority = configMAX_PRIORITIES - 1;
#endif

View File

@ -149,6 +149,15 @@ menuconfig ENABLE_MEMORY_DEBUG
help
Enable this option to show malloc heap block and memory crash detect
config FREERTOS_IDLE_TASK_STACKSIZE
int "Idle Task stack size"
range 768 32768
default 1024
help
The idle task has its own stack, sized in bytes. The default size is enough for most uses. Size can be reduced
to 768 bytes if no (or simple) FreeRTOS idle hooks are used. The stack size may need to be increased above the
default if the app installs idle hooks that use a lot of stack memory.
config FREERTOS_ISR_STACKSIZE
int "ISR stack size"
range 1536 32768

View File

@ -163,14 +163,16 @@
#define configMAX_PRIORITIES ( 25 )
#endif
/* Minimal stack size. This may need to be increased for your application */
/* NOTE: The FreeRTOS demos may not work reliably with stack size < 4KB. */
/* The Xtensa-specific examples should be fine with XT_STACK_MIN_SIZE. */
#if !(defined XT_STACK_MIN_SIZE)
#error XT_STACK_MIN_SIZE not defined, did you include xtensa_config.h ?
#ifndef CONFIG_ESP32_APPTRACE_ENABLE
#define configMINIMAL_STACK_SIZE 768
#else
/* apptrace module requires at least 2KB of stack per task */
#define configMINIMAL_STACK_SIZE 2048
#endif
#define configMINIMAL_STACK_SIZE (XT_STACK_MIN_SIZE > 1024 ? XT_STACK_MIN_SIZE : 1024)
#ifndef configIDLE_TASK_STACK_SIZE
#define configIDLE_TASK_STACK_SIZE CONFIG_FREERTOS_IDLE_TASK_STACKSIZE
#endif
/* The Xtensa port uses a separate interrupt stack. Adjust the stack size */
/* to suit the needs of your specific application. */

View File

@ -214,7 +214,7 @@ BaseType_t xPortInIsrContext();
#endif
/* Multi-core: get current core ID */
static inline uint32_t xPortGetCoreID() {
static inline uint32_t IRAM_ATTR xPortGetCoreID() {
int id;
asm volatile(
"rsr.prid %0\n"

View File

@ -121,6 +121,7 @@ typedef unsigned portBASE_TYPE UBaseType_t;
#include "portbenchmark.h"
#include "sdkconfig.h"
#include "esp_attr.h"
#define portFIRST_TASK_HOOK CONFIG_FREERTOS_BREAK_ON_SCHEDULER_START_JTAG

View File

@ -337,7 +337,7 @@ static void returnItemToRingbufDefault(ringbuf_t *rb, void *item) {
uint8_t *data=(uint8_t*)item;
configASSERT(((int)rb->free_ptr&3)==0);
configASSERT(data >= rb->data);
configASSERT(data < rb->data+rb->size);
configASSERT(data <= rb->data+rb->size);
//Grab the buffer entry that preceeds the buffer
buf_entry_hdr_t *hdr=(buf_entry_hdr_t*)(data-sizeof(buf_entry_hdr_t));
configASSERT(hdr->len < rb->size);

View File

@ -112,9 +112,9 @@ functions but without including stdio.h here. */
#endif /* configUSE_TICKLESS_IDLE */
/*
* Defines the size, in words, of the stack allocated to the idle task.
* Defines the size, in bytes, of the stack allocated to the idle task.
*/
#define tskIDLE_STACK_SIZE configMINIMAL_STACK_SIZE
#define tskIDLE_STACK_SIZE configIDLE_TASK_STACK_SIZE
#if( configUSE_PREEMPTION == 0 )
/* If the cooperative scheduler is being used then a yield should not be
@ -2163,7 +2163,6 @@ BaseType_t xAlreadyYielded = pdFALSE;
{
/* We can schedule the awoken task on this CPU. */
xYieldPending[xPortGetCoreID()] = pdTRUE;
break;
}
else
{
@ -3023,6 +3022,8 @@ BaseType_t xTaskRemoveFromEventList( const List_t * const pxEventList )
{
TCB_t *pxUnblockedTCB;
BaseType_t xReturn;
BaseType_t xTaskCanBeReady;
UBaseType_t i, uxTargetCPU;
/* THIS FUNCTION MUST BE CALLED FROM A CRITICAL SECTION. It can also be
called from a critical section within an ISR. */
@ -3046,7 +3047,24 @@ BaseType_t xReturn;
return pdFALSE;
}
if( uxSchedulerSuspended[ xPortGetCoreID() ] == ( UBaseType_t ) pdFALSE )
/* Determine if the task can possibly be run on either CPU now, either because the scheduler
the task is pinned to is running or because a scheduler is running on any CPU. */
xTaskCanBeReady = pdFALSE;
if ( pxUnblockedTCB->xCoreID == tskNO_AFFINITY ) {
uxTargetCPU = xPortGetCoreID();
for (i = 0; i < portNUM_PROCESSORS; i++) {
if ( uxSchedulerSuspended[ i ] == ( UBaseType_t ) pdFALSE ) {
xTaskCanBeReady = pdTRUE;
break;
}
}
} else {
uxTargetCPU = pxUnblockedTCB->xCoreID;
xTaskCanBeReady = uxSchedulerSuspended[ uxTargetCPU ] == ( UBaseType_t ) pdFALSE;
}
if( xTaskCanBeReady )
{
( void ) uxListRemove( &( pxUnblockedTCB->xGenericListItem ) );
prvAddTaskToReadyList( pxUnblockedTCB );
@ -3054,8 +3072,8 @@ BaseType_t xReturn;
else
{
/* The delayed and ready lists cannot be accessed, so hold this task
pending until the scheduler is resumed. */
vListInsertEnd( &( xPendingReadyList[ xPortGetCoreID() ] ), &( pxUnblockedTCB->xEventListItem ) );
pending until the scheduler is resumed on this CPU. */
vListInsertEnd( &( xPendingReadyList[ uxTargetCPU ] ), &( pxUnblockedTCB->xEventListItem ) );
}
if ( tskCAN_RUN_HERE(pxUnblockedTCB->xCoreID) && pxUnblockedTCB->uxPriority >= pxCurrentTCB[ xPortGetCoreID() ]->uxPriority )

View File

@ -195,3 +195,26 @@ TEST_CASE("FreeRTOS ringbuffer test, w/ splitting items", "[freertos][ignore]")
testRingbuffer(1);
}
TEST_CASE("FreeRTOS ringbuffer test, check if zero-length items are handled correctly", "[freertos]")
{
rb = xRingbufferCreate(32, 0);
int r;
void *v;
size_t sz;
for (int x=0; x<128; x++) {
if (x!=127) {
//Send an item
r = xRingbufferSend(rb, NULL, 0, 10000 / portTICK_PERIOD_MS);
assert(r==pdTRUE);
}
if (x!=0) {
//Receive an item
v=xRingbufferReceive(rb, &sz, 10000 / portTICK_PERIOD_MS);
assert(sz==0);
vRingbufferReturnItem(rb, v); //actually not needed for NULL data...
}
}
vRingbufferDelete(rb);
}

View File

@ -12,7 +12,7 @@
#include "driver/timer.h"
static SemaphoreHandle_t isr_semaphore;
static volatile unsigned isr_count, task_count;
static volatile unsigned isr_count;
/* Timer ISR increments an ISR counter, and signals a
mutex semaphore to wake up another counter task */
@ -29,33 +29,42 @@ static void timer_group0_isr(void *vp_arg)
}
}
static void counter_task_fn(void *ignore)
typedef struct {
SemaphoreHandle_t trigger_sem;
volatile unsigned counter;
} counter_config_t;
static void counter_task_fn(void *vp_config)
{
counter_config_t *config = (counter_config_t *)vp_config;
printf("counter_task running...\n");
while(1) {
xSemaphoreTake(isr_semaphore, portMAX_DELAY);
task_count++;
xSemaphoreTake(config->trigger_sem, portMAX_DELAY);
config->counter++;
}
}
/* This test verifies that an interrupt can wake up a task while the scheduler is disabled.
In the FreeRTOS implementation, this exercises the xPendingReadyList for that core.
*/
TEST_CASE("Handle pending context switch while scheduler disabled", "[freertos]")
TEST_CASE("Scheduler disabled can handle a pending context switch on resume", "[freertos]")
{
task_count = 0;
isr_count = 0;
isr_semaphore = xSemaphoreCreateMutex();
TaskHandle_t counter_task;
counter_config_t count_config = {
.trigger_sem = isr_semaphore,
.counter = 0,
};
xTaskCreatePinnedToCore(counter_task_fn, "counter", 2048,
NULL, UNITY_FREERTOS_PRIORITY + 1,
&count_config, UNITY_FREERTOS_PRIORITY + 1,
&counter_task, UNITY_FREERTOS_CPU);
/* Configure timer ISR */
const timer_config_t config = {
const timer_config_t timer_config = {
.alarm_en = 1,
.auto_reload = 1,
.counter_dir = TIMER_COUNT_UP,
@ -64,7 +73,7 @@ TEST_CASE("Handle pending context switch while scheduler disabled", "[freertos]"
.counter_en = TIMER_PAUSE,
};
/* Configure timer */
timer_init(TIMER_GROUP_0, TIMER_0, &config);
timer_init(TIMER_GROUP_0, TIMER_0, &timer_config);
timer_pause(TIMER_GROUP_0, TIMER_0);
timer_set_counter_value(TIMER_GROUP_0, TIMER_0, 0);
timer_set_alarm_value(TIMER_GROUP_0, TIMER_0, 1000);
@ -75,20 +84,20 @@ TEST_CASE("Handle pending context switch while scheduler disabled", "[freertos]"
vTaskDelay(5);
// Check some counts have been triggered via the ISR
TEST_ASSERT(task_count > 10);
TEST_ASSERT(count_config.counter > 10);
TEST_ASSERT(isr_count > 10);
for (int i = 0; i < 20; i++) {
vTaskSuspendAll();
esp_intr_noniram_disable();
unsigned no_sched_task = task_count;
unsigned no_sched_task = count_config.counter;
// scheduler off on this CPU...
ets_delay_us(20 * 1000);
//TEST_ASSERT_NOT_EQUAL(no_sched_isr, isr_count);
TEST_ASSERT_EQUAL(task_count, no_sched_task);
TEST_ASSERT_EQUAL(count_config.counter, no_sched_task);
// disable timer interrupts
timer_disable_intr(TIMER_GROUP_0, TIMER_0);
@ -98,9 +107,139 @@ TEST_CASE("Handle pending context switch while scheduler disabled", "[freertos]"
esp_intr_noniram_enable();
xTaskResumeAll();
TEST_ASSERT_NOT_EQUAL(task_count, no_sched_task);
TEST_ASSERT_NOT_EQUAL(count_config.counter, no_sched_task);
}
vTaskDelete(counter_task);
vSemaphoreDelete(isr_semaphore);
}
/* Multiple tasks on different cores can be added to the pending ready list
while scheduler is suspended, and should be started once the scheduler
resumes.
*/
TEST_CASE("Scheduler disabled can wake multiple tasks on resume", "[freertos]")
{
#define TASKS_PER_PROC 4
TaskHandle_t tasks[portNUM_PROCESSORS][TASKS_PER_PROC] = { 0 };
counter_config_t counters[portNUM_PROCESSORS][TASKS_PER_PROC] = { 0 };
/* Start all the tasks, they will block on isr_semaphore */
for (int p = 0; p < portNUM_PROCESSORS; p++) {
for (int t = 0; t < TASKS_PER_PROC; t++) {
counters[p][t].trigger_sem = xSemaphoreCreateMutex();
TEST_ASSERT_NOT_NULL( counters[p][t].trigger_sem );
TEST_ASSERT( xSemaphoreTake(counters[p][t].trigger_sem, 0) );
xTaskCreatePinnedToCore(counter_task_fn, "counter", 2048,
&counters[p][t], UNITY_FREERTOS_PRIORITY + 1,
&tasks[p][t], p);
TEST_ASSERT_NOT_NULL( tasks[p][t] );
}
}
/* takes a while to initialize tasks on both cores, sometimes... */
vTaskDelay(TASKS_PER_PROC * portNUM_PROCESSORS * 3);
/* Check nothing is counting, each counter should be blocked on its trigger_sem */
for (int p = 0; p < portNUM_PROCESSORS; p++) {
for (int t = 0; t < TASKS_PER_PROC; t++) {
TEST_ASSERT_EQUAL(0, counters[p][t].counter);
}
}
/* Suspend scheduler on this CPU */
vTaskSuspendAll();
/* Give all the semaphores once. This will wake tasks immediately on the other
CPU, but they are deferred here until the scheduler resumes.
*/
for (int p = 0; p < portNUM_PROCESSORS; p++) {
for (int t = 0; t < TASKS_PER_PROC; t++) {
xSemaphoreGive(counters[p][t].trigger_sem);
}
}
ets_delay_us(200); /* Let the other CPU do some things */
for (int p = 0; p < portNUM_PROCESSORS; p++) {
for (int t = 0; t < TASKS_PER_PROC; t++) {
int expected = (p == UNITY_FREERTOS_CPU) ? 0 : 1; // Has run if it was on the other CPU
ets_printf("Checking CPU %d task %d (expected %d actual %d)\n", p, t, expected, counters[p][t].counter);
TEST_ASSERT_EQUAL(expected, counters[p][t].counter);
}
}
/* Resume scheduler */
xTaskResumeAll();
/* Now the tasks on both CPUs should have been woken once and counted once. */
for (int p = 0; p < portNUM_PROCESSORS; p++) {
for (int t = 0; t < TASKS_PER_PROC; t++) {
ets_printf("Checking CPU %d task %d (expected 1 actual %d)\n", p, t, counters[p][t].counter);
TEST_ASSERT_EQUAL(1, counters[p][t].counter);
}
}
/* Clean up */
for (int p = 0; p < portNUM_PROCESSORS; p++) {
for (int t = 0; t < TASKS_PER_PROC; t++) {
vTaskDelete(tasks[p][t]);
vSemaphoreDelete(counters[p][t].trigger_sem);
}
}
}
static volatile bool sched_suspended;
static void suspend_scheduler_5ms_task_fn(void *ignore)
{
vTaskSuspendAll();
sched_suspended = true;
for (int i = 0; i <5; i++) {
ets_delay_us(1000);
}
xTaskResumeAll();
sched_suspended = false;
vTaskDelete(NULL);
}
#ifndef CONFIG_FREERTOS_UNICORE
/* If the scheduler is disabled on one CPU (A) with a task blocked on something, and a task
on B (where scheduler is running) wakes it, then the task on A should be woken on resume.
*/
TEST_CASE("Scheduler disabled on CPU B, tasks on A can wake", "[freertos]")
{
TaskHandle_t counter_task;
SemaphoreHandle_t wake_sem = xSemaphoreCreateMutex();
xSemaphoreTake(wake_sem, 0);
counter_config_t count_config = {
.trigger_sem = wake_sem,
.counter = 0,
};
xTaskCreatePinnedToCore(counter_task_fn, "counter", 2048,
&count_config, UNITY_FREERTOS_PRIORITY + 1,
&counter_task, !UNITY_FREERTOS_CPU);
xTaskCreatePinnedToCore(suspend_scheduler_5ms_task_fn, "suspender", 2048,
NULL, UNITY_FREERTOS_PRIORITY - 1,
NULL, !UNITY_FREERTOS_CPU);
/* counter task is now blocked on other CPU, waiting for wake_sem, and we expect
that this CPU's scheduler will be suspended for 5ms shortly... */
while(!sched_suspended) { }
xSemaphoreGive(wake_sem);
ets_delay_us(1000);
// Bit of a race here if the other CPU resumes its scheduler, but 5ms is a long time... */
TEST_ASSERT(sched_suspended);
TEST_ASSERT_EQUAL(0, count_config.counter); // the other task hasn't woken yet, because scheduler is off
TEST_ASSERT(sched_suspended);
/* wait for the rest of the 5ms... */
while(sched_suspended) { }
ets_delay_us(100);
TEST_ASSERT_EQUAL(1, count_config.counter); // when scheduler resumes, counter task should immediately count
vTaskDelete(counter_task);
}
#endif

View File

@ -115,9 +115,36 @@ ip4_set_default_multicast_netif(struct netif* default_multicast_netif)
#endif /* LWIP_MULTICAST_TX_OPTIONS */
#ifdef LWIP_HOOK_IP4_ROUTE_SRC
/**
* Source based IPv4 routing hook function. This function works only
* when destination IP is broadcast IP.
*/
struct netif *
ip4_route_src_hook(const ip4_addr_t *dest, const ip4_addr_t *src)
{
struct netif *netif = NULL;
/* destination IP is broadcast IP? */
if ((src != NULL) && (dest->addr == IPADDR_BROADCAST)) {
/* iterate through netifs */
for (netif = netif_list; netif != NULL; netif = netif->next) {
/* is the netif up, does it have a link and a valid address? */
if (netif_is_up(netif) && netif_is_link_up(netif) && !ip4_addr_isany_val(*netif_ip4_addr(netif))) {
/* source IP matches? */
if (ip4_addr_cmp(src, netif_ip4_addr(netif))) {
/* return netif on which to forward IP packet */
return netif;
}
}
}
}
return netif;
}
/**
* Source based IPv4 routing must be fully implemented in
* LWIP_HOOK_IP4_ROUTE_SRC(). This function only provides he parameters.
* LWIP_HOOK_IP4_ROUTE_SRC(). This function only provides the parameters.
*/
struct netif *
ip4_route_src(const ip4_addr_t *dest, const ip4_addr_t *src)

View File

@ -385,7 +385,7 @@ void netif_set_gw(struct netif *netif, const ip4_addr_t *gw);
void netif_set_up(struct netif *netif);
void netif_set_down(struct netif *netif);
/** Ask if an interface is up */
#define netif_is_up(netif) (((netif)->flags & NETIF_FLAG_UP) ? (u8_t)1 : (u8_t)0)
#define netif_is_up(netif) ( ((netif) && ((netif)->flags & NETIF_FLAG_UP)) ? (u8_t)1 : (u8_t)0)
#if LWIP_NETIF_STATUS_CALLBACK
void netif_set_status_callback(struct netif *netif, netif_status_callback_fn status_callback);

View File

@ -574,6 +574,7 @@
---------- Hook options ---------------
---------------------------------------
*/
#define LWIP_HOOK_IP4_ROUTE_SRC ip4_route_src_hook
/*
---------------------------------------

View File

@ -446,7 +446,7 @@ sys_jiffies(void)
u32_t
sys_now(void)
{
return xTaskGetTickCount();
return (xTaskGetTickCount() * portTICK_PERIOD_MS);
}
/*

View File

@ -153,11 +153,17 @@ ethernetif_input(struct netif *netif, void *buffer, uint16_t len)
{
struct pbuf *p;
if(buffer== NULL || netif == NULL)
goto _exit;
if(buffer== NULL || !netif_is_up(netif)) {
if (buffer) {
esp_eth_free_rx_buf(buffer);
}
return;
}
#ifdef CONFIG_EMAC_L2_TO_L3_RX_BUF_MODE
p = pbuf_alloc(PBUF_RAW, len, PBUF_RAM);
if (p == NULL) {
esp_eth_free_rx_buf(buffer);
return;
}
p->l2_owner = NULL;
@ -172,6 +178,7 @@ if (netif->input(p, netif) != ERR_OK) {
#else
p = pbuf_alloc(PBUF_RAW, len, PBUF_REF);
if (p == NULL){
esp_eth_free_rx_buf(buffer);
return;
}
p->payload = buffer;
@ -185,8 +192,6 @@ if (netif->input(p, netif) != ERR_OK) {
pbuf_free(p);
}
#endif
_exit:
;
}
/**

View File

@ -144,8 +144,12 @@ wlanif_input(struct netif *netif, void *buffer, u16_t len, void* eb)
{
struct pbuf *p;
if(!buffer || !netif)
goto _exit;
if(!buffer || !netif_is_up(netif)) {
if (eb) {
esp_wifi_internal_free_rx_buffer(eb);
}
return;
}
#if (ESP_L2_TO_L3_COPY == 1)
p = pbuf_alloc(PBUF_RAW, len, PBUF_RAM);
@ -161,6 +165,7 @@ wlanif_input(struct netif *netif, void *buffer, u16_t len, void* eb)
p = pbuf_alloc(PBUF_RAW, len, PBUF_REF);
if (p == NULL){
ESP_STATS_DROP_INC(esp.wlanif_input_pbuf_fail);
esp_wifi_internal_free_rx_buffer(eb);
return;
}
p->payload = buffer;
@ -174,8 +179,6 @@ wlanif_input(struct netif *netif, void *buffer, u16_t len, void* eb)
pbuf_free(p);
}
_exit:
;
}
/**

View File

@ -31,14 +31,25 @@ config MBEDTLS_DEBUG
at runtime in order to enable mbedTLS debug output via the ESP
log mechanism.
config MBEDTLS_UNSAFE_ACCELERATION
bool "Allow buggy hardware acceleration features"
depends on !FREERTOS_UNICORE
default n
help
A bug currently prevents dual cores & crypto hardware acceleration from being used together.
Enable this option to allow hardware acceleration anyhow (note that invalid results or crashes may occur.)
config MBEDTLS_HARDWARE_AES
bool "Enable hardware AES acceleration"
depends on MBEDTLS_UNSAFE_ACCELERATION || FREERTOS_UNICORE
default y
help
Enable hardware accelerated AES encryption & decryption.
config MBEDTLS_HARDWARE_MPI
bool "Enable hardware MPI (bignum) acceleration"
depends on MBEDTLS_UNSAFE_ACCELERATION || FREERTOS_UNICORE
default y
help
Enable hardware accelerated multiple precision integer operations.
@ -60,6 +71,7 @@ config MBEDTLS_MPI_USE_INTERRUPT
config MBEDTLS_HARDWARE_SHA
bool "Enable hardware SHA acceleration"
depends on MBEDTLS_UNSAFE_ACCELERATION || FREERTOS_UNICORE
default y
help
Enable hardware accelerated SHA1, SHA256, SHA384 & SHA512 in mbedTLS.

View File

@ -1406,7 +1406,7 @@ static int ecp_mul_comb( mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
cleanup:
if( T != NULL && ! p_eq_g )
if( T != NULL && T != grp->T )
{
for( i = 0; i < pre_len; i++ )
mbedtls_ecp_point_free( &T[i] );

View File

@ -165,8 +165,14 @@ TEST_CASE("mbedtls SHA self-tests multithreaded", "[mbedtls]")
xTaskCreate(tskRunSHASelftests, "SHASelftests1", 8192, NULL, 3, NULL);
xTaskCreate(tskRunSHASelftests, "SHASelftests2", 8192, NULL, 3, NULL);
#ifdef CONFIG_MBEDTLS_HARDWARE_SHA
const int TIMEOUT_MS = 12000;
#else
const int TIMEOUT_MS = 20000; // Soft-only SHA may need a little longer
#endif
for(int i = 0; i < 2; i++) {
if(!xSemaphoreTake(done_sem, 12000/portTICK_PERIOD_MS)) {
if(!xSemaphoreTake(done_sem, TIMEOUT_MS/portTICK_PERIOD_MS)) {
TEST_FAIL_MESSAGE("done_sem not released by test task");
}
}

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