Compare commits

...

252 Commits

Author SHA1 Message Date
abdf12dc9e Merge branch 'bugfix/coex_fix_some_bugs_v4.0' into 'release/v4.0'
Coexist: fix some coexist bugs(backport v4.0)

See merge request espressif/esp-idf!6088
2019-09-30 17:01:32 +08:00
10d26549fa Coexist: fix some coexist bugs
1. Fix high beacon and broadcast packets loss ratio of WiFi to
   make MDNS test pass.
2. Improve stability of WiFi performance with a little sacrifice
   of throughput.
3. Improve BLE advertising and connection performance with
   dynamic priority. It sacrifices a little WiFi throughput, but
   achieves balance between WiFi and Bluetooth.
2019-09-30 11:42:05 +08:00
26676c2b8f Merge branch 'bugfix/fix_wifi_stop_leads_to_watchdog_v4.0' into 'release/v4.0'
Fixed the bug that WiFi stop leads to task watchdog (backport v4.0)

See merge request espressif/esp-idf!6228
2019-09-30 11:00:53 +08:00
d9cfb05eb6 esp_wifi:
1. Fixed smartconfig ipc crash
2. Fix the WiFi init sequence bug
3. Fixed the bug that WiFi stop leads to task watchdog
4. Put g_promis_buf to IRAM
2019-09-29 11:38:11 +08:00
4322e89006 Merge branch 'bugfix/ble_mesh_client_invalid_addr_access_4.0' into 'release/v4.0'
ble_mesh: fix client model invalid address access (v4.0)

See merge request espressif/esp-idf!6218
2019-09-29 10:24:04 +08:00
96748f3037 Merge branch 'refactor/update_spi_ethernet_api_v4.0' into 'release/v4.0'
update spi ethernet api (v4.0)

See merge request espressif/esp-idf!6177
2019-09-27 19:43:15 +08:00
lly
5a94142481 ble_mesh: fix client model invalid address access 2019-09-27 15:28:10 +08:00
e5ff431b35 Merge branch 'fix/esp_flash_coredump_4.0' into 'release/v4.0'
esp_flash: fix coredump issues (backport v4.0)

See merge request espressif/esp-idf!6136
2019-09-26 21:26:53 +08:00
c225801b3e Merge branch 'fix/add_parentheses_to_spi_swap_data_tx_4.0' into 'release/v4.0'
spi: Put argument of macro SPI_SWAP_DATA_TX in parentheses (backport v4.0)

See merge request espressif/esp-idf!6107
2019-09-26 21:25:20 +08:00
610e3cac31 Merge branch 'bugfix/gnu_make_windows_paths_v4.0' into 'release/v4.0'
build: In GNU Make, use "cygpath -m" to avoid backslashes (v4.0)

See merge request espressif/esp-idf!6155
2019-09-26 21:24:48 +08:00
c776991233 Merge branch 'bugfix/kconfig_corrections_v4.0' into 'release/v4.0'
Fix Kconfig issues discovered by upstream Kconfiglib (v4.0)

See merge request espressif/esp-idf!6195
2019-09-25 16:26:40 +08:00
041fcceddf Merge branch 'feat/esp_flash_support_encrypt_4.0' into 'release/v4.0'
esp_flash: add support for encrypted read and write (backport v4.0)

See merge request espressif/esp-idf!6106
2019-09-25 16:17:31 +08:00
899957f521 Merge branch 'feature/cmake_check_mconf_version_v4.0' into 'release/v4.0'
cmake: check mconf-idf binary version (backport v4.0)

See merge request espressif/esp-idf!6067
2019-09-25 16:15:26 +08:00
815d7674ef Merge branch 'bugfix/openocd_instructions_v4.0' into 'release/v4.0'
docs: jtag-debugging: update for IDF Tools installation method (backport v4.0)

See merge request espressif/esp-idf!6066
2019-09-25 16:15:07 +08:00
57527ba6f9 Merge branch 'doc/build_system_requirements_v4.0' into 'release/v4.0'
docs: Explain build system REQUIRES & PRIV_REQUIRES in more detail (v4.0)

See merge request espressif/esp-idf!6054
2019-09-25 16:13:48 +08:00
a21eb04cc6 Merge branch 'bugfix/btdm_a2dp_sink_media_suspend_cmd_unack_for_v4.0' into 'release/v4.0'
bugfix/btdm_a2dp_sink_media_suspend_cmd_unack_for_v4.0(backport v4.0)

See merge request espressif/esp-idf!5940
2019-09-25 16:12:43 +08:00
116d0c8145 Merge branch 'bugfix/ble_mesh_queue_task_init_check_v4.0' into 'release/v4.0'
ble_mesh: check ble mesh queue and task init status (v4.0)

See merge request espressif/esp-idf!6193
2019-09-25 15:08:23 +08:00
dda49709fe ethernet: update spi-ethernet api 2019-09-25 06:34:39 +00:00
ebffa5f9f2 ethernet: test apps can build with ethernet disabled 2019-09-25 06:34:39 +00:00
fc738680f8 Fix Kconfig issues discovered by upstream Kconfiglib 2019-09-25 08:25:51 +02:00
1c586ebcfd Merge branch 'feature/bluedroid_min_encr_key_size_backport_v4.0' into 'release/v4.0'
BT/Bluedroid: Add support to set min encryption key size requirement (backport v4.0)

See merge request espressif/esp-idf!6180
2019-09-25 11:57:22 +08:00
499accb652 BT/Bluedroid: Add support to set min encryption key size requirement (backport)
- Backport of IDF MR!6122.
- Modifies `smp_utils.c` to add check on encryption key size received from
  peer.
- Modifies `esp_ble_gap_set_security_param` API to add minimum encryption key
  size requirement.
2019-09-25 11:57:21 +08:00
988147a451 Merge branch 'bugfix/btdm_loop_in_feature_req_ext_v4.0' into 'release/v4.0'
components/bt: Fix sending LMP_features_req_ext in a loop

See merge request espressif/esp-idf!6023
2019-09-25 11:52:10 +08:00
lly
9e6c56f9f2 ble_mesh: check ble mesh queue and task init status 2019-09-25 11:03:18 +08:00
1b6eb69f53 Merge branch 'NimBLE/mbedTLS_option_for_tinycrypty_v4.0' into 'release/v4.0'
NimBLE: Add optional mbedTLS support to NimBLE (backport)

See merge request espressif/esp-idf!6146
2019-09-23 21:37:40 +08:00
daa65b6f91 NimBLE: Add optional mbedTLS support to NimBLE (backport)
- NimBLE: Additional menuconfig option to enable mbedTLS instead of Tinycrypt from
  NimBLE, changes `component.mk` & `CMakeLists.txt` for the same.
- Addition of NimBLE stack size configuration and misc changes.
- mbedTLS: Addition of `CMAC` and `ECP_RESTARTABLE` to mbedTLS menuconfig option and
  `esp_config.h`.
- Example: Minor changes to `app_mesh.c` application.
2019-09-23 21:37:40 +08:00
7f9626d378 Merge branch 'cleanup/make_supp_headers_private_v4.0' into 'release/v4.0'
wpa_supplicant: Make internal crypto headers private (backport v4.0)

See merge request espressif/esp-idf!6061
2019-09-23 18:00:43 +08:00
6cad60f34b bugfix that call of esp_a2d_media_ctrl(ESP_A2D_MEDIA_CTRL_SUSPEND) will not get an ACK from callback on A2DP sink 2019-09-23 03:22:34 +00:00
b4c7ed999c Merge branch 'bugfix/remove_v40_deprecations_v4.0' into 'release/v4.0'
Remove features deprecated before ESP-IDF V4.0 (v4.0)

See merge request espressif/esp-idf!6150
2019-09-20 19:51:51 +08:00
8a5c08df98 Merge branch 'bugfix/fix_the_for_smartconfig_send_broadcast_to_phone_v4.0' into 'release/v4.0'
fix the bug that ESP32 sends broadcast to phone after smartconfig is done (backport v4.0)

See merge request espressif/esp-idf!6072
2019-09-20 14:02:19 +08:00
b1eac64865 build: In GNU Make, use "cygpath -m" to avoid backslashes
Fixes issues where backslashes in KCONFIG paths are later expanded as shell escape sequences.
2019-09-19 21:33:56 +10:00
4e7b559101 Delete extra '/' 2019-09-19 19:22:44 +08:00
43616f6f05 esp_wifi: Update wifi lib 2019-09-19 17:49:18 +08:00
3b9ab9caa6 idf_test: Disable tests for Wi-Fi auto reconnect
Disable one, remove IDF tag from the other
2019-09-19 18:49:37 +10:00
0dc9ddb77c Wi-Fi: remove wifi_fast_scan_threshold_t which is not suitable in name 2019-09-19 18:49:37 +10:00
9ab92331c4 dport: remove clock_en and reset bitname which is not suitable 2019-09-19 18:49:37 +10:00
08416d05ba soc: Remove deprecated LEDC struct register names (bit_num, div_num)
Deprecated since ESP-IDF V3.0
2019-09-19 18:49:37 +10:00
200c82561a soc: remove deprecated io_mux PIN_PULLxxx_yyy macros
Deprecated before ESP-IDF V1.0!
2019-09-19 18:49:37 +10:00
2e05c6020f mbedtls: Remove esp_aes_encrypt/decrypt
Deprecated in ESP-IDF V3.1

Anyone reading this should please include mbedtls/aes.h and use mbedTLS APIs,
not the ESP-specific APIs.
2019-09-19 18:49:37 +10:00
d139c851f3 heap: Remove esp_heap_alloc_caps header
Deprecated in ESP-IDF V3.1
2019-09-19 18:49:37 +10:00
365e3fd685 fatfs: Remove esp_vfs_fat_unregister()
Deprecated in ESP-IDF V2.0
2019-09-19 18:49:37 +10:00
71fad5e2c0 esp_wifi: Remove WIFI_PS_MODEM constant
Deprecated in ESP-IDF V3.1
2019-09-19 18:48:55 +10:00
94ba3a20cb esp_wifi: Remove deprecated auto connect API
Deprecated in ESP-IDF V3.1
2019-09-19 18:48:55 +10:00
5a7d3ef319 ringbuf: Remove deprecated RingbufferType_t
Deprecated in ESP-IDF V3.1
2019-09-19 18:48:55 +10:00
e4a4e6ed81 wdt: Remove deprecated esp_task_wdt_feed() function
Deprecated in ESP-IDF V3.1
2019-09-19 18:48:55 +10:00
8094e880c6 esp32/esp_common: Remove deprecated esp_efuse_read_mac() function
Deprecated since ESP-IDF V2.0
2019-09-19 18:48:30 +10:00
35b9223cf4 esp32/esp_common: Remove deprecated system_* APIs
Mostly deprecated before ESP-IDF V1.0 & V2.0
2019-09-19 18:48:30 +10:00
fe97d14e0f esp_adc_cal: Remove deprecated ADC calibration functions
Deprecated since ESP-IDF V3.1
2019-09-19 18:48:14 +10:00
2c16557ee7 esp32: Remove deprecated system_deep_sleep function
Deprecated since ESP-IDF V3.0
2019-09-19 18:48:14 +10:00
5f8e5db268 esp32/test: fix usage of deprecated fields 2019-09-19 18:48:14 +10:00
a9fe3165c4 soc/pm: Remove deprecated use of rtc_cpu_freq_t enum
Removes deprecated ways of setting/getting CPU freq, light sleep freqs.

Deprecated since ESP-IDF V3.2
2019-09-19 18:48:13 +10:00
b01036e13e driver: Remove features deprecated pre-IDF V4.0 2019-09-19 18:47:15 +10:00
10649ae23b app_update: Remove deprecated "make erase_ota" target
Deprecated in v3.2
2019-09-19 18:45:36 +10:00
c4306f7942 bootloader_support: Remove deprecated partition load/verify functions
Deprecated since v3.2
2019-09-19 18:45:36 +10:00
62be877ada bluetooth: Remove bt.h header (deprecated in v3.1-dev) 2019-09-19 18:45:36 +10:00
05d3665a14 Merge branch 'bugfix/ble_mesh_get_timer_remaining_time_v4.0' into 'release/v4.0'
ble_mesh: fix ble mesh get timer remaining time (v4.0)

See merge request espressif/esp-idf!6059
2019-09-18 16:38:31 +08:00
0bba92b2a0 esp_flash: put adapter to legacy functions into IRAM to be back-compatible 2019-09-18 15:16:00 +08:00
399477cd10 coredump: use esp_flash api in coredump
Also put esp_flash functions into noflash region, when
ESP32_PANIC_HANDLER_IRAM and coredump are enabled. The option disables
the re-enabling of the CPU-cache when it's disabled during coredump.
This requires all the coredump functions including the flash API to be
in the D/IRAM.
2019-09-18 15:14:53 +08:00
d3b54ec84a esp_flash: fix the coredump issue
During coredump, dangerous-area-checking should be disabled, and cache
disabling should be replaced by a safer version.

Dangerous-area-checking used to be in the HAL, but it seems to be more
fit to os functions. So it's moved to os functions. Interfaces are
provided to switch between os functions during coredump.
2019-09-18 14:30:23 +08:00
e4b44f3488 esp_flash: fix coredump for legacy spi flash API
When legacy mode is used, the coredump still fails during linking
because "esp_flash_init_default_chip", "esp_flash_app_init" and
"esp_flash_default_chip " are not compiled and linked.

Instead of using ``if`` macros in callers, these functions are protected
by ``if`` macros in the header, and also not compiled in the sources.
"esp_flash_default_chip" variable is compiled with safe default value.
2019-09-18 14:28:12 +08:00
ca80b0445d wpa_supplicant: Make internal crypto headers private (backport v4.0)
A lot of internally used crypto headers are publicly includeable
in user projects. This leads to bug reports when these headers
are incorrectly used or the API's are not used as intended.

Move all crypto headers into private crypto src folder, also move
crypto_ops into Supplicant to remove dependecy on crypto headers.

Closes IDF-476
2019-09-17 13:28:30 +00:00
lly
1e01accaa4 ble_mesh: fix duplicate memory free during receiving status message 2019-09-16 17:30:03 +08:00
2ca3735edd spi: Put argument of macro SPI_SWAP_DATA_TX/RX in parentheses
Close https://github.com/espressif/esp-idf/pull/3996
2019-09-16 17:17:42 +08:00
b9a2639ab4 esp_flash: add support for encrypted read and write
Using legacy implementation.
2019-09-16 17:10:08 +08:00
lly
77f186a7b9 ble_mesh: make unicast elem lookup O(1) 2019-09-16 15:06:52 +08:00
lly
89e848c820 ble_mesh: use adv report flow control for ble mesh 2019-09-16 14:44:34 +08:00
5e0cc123ee Merge branch 'bugfix/cmake_sdkconfig_path' into 'release/v4.0'
fix bug for cmake build system

See merge request espressif/esp-idf!6102
2019-09-16 14:20:38 +08:00
536c131114 fix bug for cmake build system
The path of ${SDKCONFIG_H} does not exist, should be replaced by ${sdkconfig_header}.
2019-09-16 11:18:04 +08:00
ef17d8bba1 Merge branch 'bugfix/httpd_sess_close_v4.0' into 'release/v4.0'
httpd_sess_close: Check for session validity before closing (v4.0)

See merge request espressif/esp-idf!5742
2019-09-16 08:21:37 +08:00
3194e12479 Merge branch 'bugfix/uart_select_free_v4.0' into 'release/v4.0'
VFS: Fix memory access after free() in UART select() (v4.0)

See merge request espressif/esp-idf!6085
2019-09-13 14:49:46 +08:00
bb52613bea Merge branch 'bugfix/use_local_kconfiglib_v4.0' into 'release/v4.0'
Use kconfiglib from $IDF_PATH/tools/kconfig_new (v4.0)

See merge request espressif/esp-idf!6079
2019-09-13 14:47:07 +08:00
4ee065df79 httpd_sess_close: Check for session validity before closing
If httpd_sess_trigger_close() gets called twice for the same socket,
the first httpd_sess_close() cb closes the correct socket, but the second
invocation closes the wrong socket which was just accepted and added to
the socket db. Checking for the lru counter will help identify this as the
counter is set only for requests actually served.
2019-09-12 08:41:31 +00:00
63c2834d7b VFS: Fix memory access after free() in UART select()
Closes https://github.com/espressif/esp-idf/issues/4030
2019-09-12 08:38:31 +02:00
dbf2c3d480 Merge branch 'bugfix/btdm_config_msbc_v4.0' into 'release/v4.0'
components/bt: Disable Wide Bond Speech when SCO data path is PCM

See merge request espressif/esp-idf!5979
2019-09-12 13:23:54 +08:00
582d5de497 Merge branch 'bugfix/coex_bb_reset_lock_v4.0' into 'release/v4.0'
fix some coex bugs

See merge request espressif/esp-idf!6056
2019-09-12 11:04:10 +08:00
5a351af83f Merge branch 'bugfix/flash_encryption_disable_plaintext_v4.0' into 'release/v4.0'
flash encryption: Always disable plaintext reflashes in Release mode (v4.0)

See merge request espressif/esp-idf!6070
2019-09-12 10:40:34 +08:00
a6fc9bf246 Use kconfiglib from $IDF_PATH/tools/kconfig_new 2019-09-11 14:28:39 +02:00
d52b244ae8 Merge branch 'bugfix/openocd_ulp_install_instructions_v4.0' into 'release/v4.0'
docs: ulp: update for IDF Tools installation method (backport v4.0)

See merge request espressif/esp-idf!6065
2019-09-11 16:06:52 +08:00
00e3cb672b Merge branch 'bugfix/flash_encryption_regressions_v4.0' into 'release/v4.0'
fix flash encryption regressions, add tests (backport v4.0)

See merge request espressif/esp-idf!6068
2019-09-11 12:06:02 +08:00
67eb732dbe fix the bug that ESP32 sends broadcast to phone after smartconfig is done 2019-09-11 11:37:29 +08:00
c53a5ee427 Merge branch 'bugfix/http_header_parser_resolution_v4.0' into 'release/v4.0'
(backport v4.0) esp_http_server : Bugfix in parsing of empty header values

See merge request espressif/esp-idf!6041
2019-09-11 10:20:36 +08:00
69241907a5 bootloader: Link RTC clock functions to the iram_loader section
As flash encryption & secure boot needs these functions after the app is loaded.

Fixes regression introduced in fb72a6f629
2019-09-11 10:16:43 +10:00
d4ee21bd6d docs: Small cleanup of flash encryption docs 2019-09-11 10:16:43 +10:00
5b69614e32 flash encryption: Ensure flash encryption can't be disabled if Secure Boot is on 2019-09-11 10:16:43 +10:00
3e12967535 bootloader: add definition of esp_clk_apb_freq
Commit 8cd04c80 has added a dependency of efuse component on
esp_clk_apb_freq, however there was no definition of this function in
the bootloader context.

Reported at https://esp32.com/viewtopic.php?f=13&t=12035
2019-09-11 10:16:43 +10:00
d9f1219a21 efuse: set timing configuration before writing 2019-09-11 10:16:43 +10:00
f3fc4916d2 ci: add jobs for flash encryption tests 2019-09-10 17:20:19 +02:00
b17ca9cb38 unit-test-app: add config with flash encryption enabled 2019-09-10 17:20:19 +02:00
801010dac6 spi_flash: fix mmap unit tests for flash encryption 2019-09-10 17:20:19 +02:00
f84394e550 examples/flash_encryption: refactor, add test
1. Clean up the example code
2. Add demonstration of partition read/write operations
3. Add example test
2019-09-10 17:19:44 +02:00
a0256b9e9d flash encryption: add option to require flash encryption to be enabled
In testing environment, to avoid accidentally enabling flash
encryption on a device, CONFIG_SECURE_FLASH_REQUIRE_ALREADY_ENABLED
can be set. If set, the bootloader will refuse to boot if flash
encryption is not enabled, instead of enabling it.
2019-09-10 17:19:08 +02:00
a37694741c tiny-test-fw: support testing apps with flash encryption
If CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT is set, pass
--encrypted flag to esptool.py.
2019-09-10 17:18:51 +02:00
fae124a2c1 esp32: cpu_start: read binary image header via cache
When flash encryption is enabled, reading via cache also decrypts the
data, whereas spi_flash_read does not.

Closes https://github.com/espressif/esp-idf/issues/3907
2019-09-10 17:18:51 +02:00
ad100e497a spi_flash: remove duplicate definition of spi_flash_unlock
The other (static) definition is in flash_ops.c, all references are
also in flash_ops.c.
2019-09-10 17:18:51 +02:00
da8c09c463 cmake: check mconf-idf binary version
Print a warning if an outdated version of mconf-idf is found in
the PATH.
2019-09-10 17:15:15 +02:00
6df148aa54 docs: jtag-debugging: update translation 2019-09-10 17:12:48 +02:00
3fc9b022b6 docs: jtag-debugging: update for IDF Tools installation method
- rely on OPENOCD_SCRIPTS variable in all cases, remove -s flags
- replace installation section with a reference to the Getting Started
  guides
- add Windows-specific commands in a few cases
2019-09-10 17:12:48 +02:00
28ee1c0da2 doc: update translation of ulp install instuctions 2019-09-10 17:10:17 +02:00
05b306bae1 docs: ulp: update for IDF Tools installation method
binutils-esp32ulp is installed automatically by install.sh/install.bat
or the IDF Tools Installer for Windows.
2019-09-10 17:10:17 +02:00
lly
8dbb2083ea ble_mesh: fix ble mesh get timer remaining time 2019-09-10 17:01:03 +08:00
a8590c7e8e fix some coex bugs
1. fix the bug that bb reset lock unhandled may cause assert in vPortCPUReleaseMutexIntsDisabledInternal
2. fix wifi mac reset may blocking then cause wdt timeout
3. fix bug wifi mac reset before coex init
2019-09-10 15:58:42 +08:00
8876cda09b esp_http_server : Bugfix in parsing of empty header values
This MR is intended to fix incorrect parsing of HTTP requests when empty header values are present.

The issue is was due to asymmetric behavior of `http_parser` library, which in case of:

    non-empty header values : invokes callbacks with the pointer to the start of a value
    empty header values : invokes callbacks with pointer to the start of next header or section

Since HTTP server relies on this pointer (along with length of the value) to locate the end of a value, and replace the line terminators (CRLFs) with null characters, the second case needed to be handled correctly.

Closes IDFGH-1539

Closes https://github.com/espressif/esp-idf/issues/3803
2019-09-10 05:58:49 +00:00
cec1c5f856 docs: Explain build system REQUIRES & PRIV_REQUIRES in more detail
Including an example.
2019-09-10 15:10:30 +10:00
a7107d9bbd Merge branch 'bugfix/ble_mesh_related_bugfixes_v4.0' into 'release/v4.0'
Bugfix/ble mesh related bugfixes v4.0

See merge request espressif/esp-idf!6042
2019-09-10 09:48:36 +08:00
850684438b Merge branch 'bugfix/ethernet_rx_length_check_v4.0' into 'release/v4.0'
ethernet: bugfix and optimize (v4.0)

See merge request espressif/esp-idf!6028
2019-09-10 07:58:46 +08:00
9d00f3b420 Merge branch 'deprecate/spi_common_claim_macros_v4.0' into 'release/v4.0'
spi_common: remove deprecated spi_common_periph_claim macros (backport v4.0)

See merge request espressif/esp-idf!6006
2019-09-10 06:42:32 +08:00
72264ca9b9 spi_common: remove deprecated spi_common_periph_claim macros (backport v4.0) 2019-09-10 06:42:31 +08:00
da2025a74a Merge branch 'bugfix/newlib_time_test_v4.0' into 'release/v4.0'
newlib: Fix UT - test time adjustment happens linearly (v4.0)

See merge request espressif/esp-idf!6014
2019-09-10 06:40:09 +08:00
93bad7a0de Merge branch 'bugfix/bootloader_factory_reset_with_wake_up_from_deep_sleep_v4.0' into 'release/v4.0'
bootloader: Blocking the Factory reset during wake up from deep sleep (v4.0)

See merge request espressif/esp-idf!6020
2019-09-10 06:39:19 +08:00
lly
55f687c763 ble_mesh: update ble mesh examples sdkconfig.defaults 2019-09-09 18:10:52 +08:00
lly
329388fa47 ble_mesh: fix ble mesh btc may caused memory leak 2019-09-09 18:10:47 +08:00
lly
0f36dabcaf ble_mesh: fix publication period timestamp initialization 2019-09-09 18:10:42 +08:00
lly
0299e22dd0 ble_mesh: remove useless mesh_opcode 2019-09-09 18:10:34 +08:00
lly
f072c5af4e ble_mesh: fix bt_mesh_net_resend() caused compiling error 2019-09-09 17:47:56 +08:00
lly
6982663380 ble_mesh: fix adhering to the configured Friend Queue size 2019-09-09 17:47:47 +08:00
lly
1d970ad276 ble_mesh: remove useless code bt_mesh_trans_resend() 2019-09-09 17:47:30 +08:00
lly
a73cc70af9 ble_mesh: lpn remove msg from cache on rejection 2019-09-09 17:47:24 +08:00
lly
225ee8e5d1 ble_mesh: introduce a helper for send callback function 2019-09-09 17:47:18 +08:00
lly
fa4cd56d00 ble_mesh: fix heartbeat sending on friendship established/lost 2019-09-09 17:47:07 +08:00
lly
15f8b0fccc ble_mesh: fix checking for active heartbeat publication 2019-09-09 17:46:49 +08:00
lly
97080afba2 ble_mesh: fix starting iv update when not on primary subnet 2019-09-09 17:46:43 +08:00
lly
612822d8c9 ble_mesh: fix canceling publication retransmit timer 2019-09-09 17:46:35 +08:00
lly
ff6cb921c3 ble_mesh: fix resending segments on correct bearer 2019-09-09 17:46:27 +08:00
lly
6f7b7c552d ble_mesh: fix not sending all segments through the Friend Queue 2019-09-09 17:46:19 +08:00
lly
e00186e683 ble_mesh: fix canceled buffer memory leak 2019-09-09 17:46:06 +08:00
lly
a734b3b1bc ble_mesh: remove some useless copy during ecdh calculation 2019-09-09 17:45:59 +08:00
lly
6de637811f ble_mesh: move heartbeat sending to transport layer 2019-09-09 17:45:52 +08:00
lly
6ec0c6743a ble_mesh: fix provisioning send error handling 2019-09-09 17:45:44 +08:00
lly
299c86cc84 ble_mesh: fix rejecting invalid remote public key 2019-09-09 17:45:27 +08:00
lly
d123f6c04b ble_mesh: add error checks for scan start/stop 2019-09-09 17:45:20 +08:00
lly
3c17bf1a6f ble_mesh: rename reset_link() to reset_adv_link() 2019-09-09 17:45:14 +08:00
lly
8fb20e4529 ble_mesh: fix public key mismatch error handling 2019-09-09 17:45:06 +08:00
lly
e020d1055a ble_mesh: update protocol error timeout from zephyr 2019-09-09 17:44:17 +08:00
lly
05e4b28a74 ble_mesh: fix segmented message RPL behavior 2019-09-09 17:44:11 +08:00
lly
27bc688ed8 ble_mesh: clear LPN sent_req on failure 2019-09-09 17:43:59 +08:00
lly
a214fb2821 ble_mesh: update proxy sar operation from zephyr 2019-09-09 17:43:46 +08:00
lly
6b7b9d1550 ble_mesh: fix postponing storage deadline indefinitely 2019-09-09 17:43:40 +08:00
lly
18b873b2e3 ble_mesh: fix RPL storage timeout handling 2019-09-09 17:43:29 +08:00
lly
d1755c1484 ble_mesh: fix output MIC with additional data 2019-09-09 17:43:23 +08:00
lly
152ebb104d ble_mesh: remove non-standard relay opearation 2019-09-09 17:43:13 +08:00
lly
e3b304997f ble_mesh: fix finding netkey/appkey/devkey for tx/rx msg 2019-09-09 17:43:04 +08:00
lly
1e20ed4849 ble_mesh: fix failed to set device role caused mem leak 2019-09-09 17:42:50 +08:00
lly
59b663c43d ble_mesh: ble mesh btc miscellaneous modifications 2019-09-09 17:42:43 +08:00
lly
e9e28c1265 ble_mesh: fix MESH/NODE/FRND/FN/BV-11-C related bug 2019-09-09 17:42:35 +08:00
lly
7030d612e2 ble_mesh: fix MESH/NODE/CFG/GPXY/BV-02-C & MESH/NODE/CFG/NID/BV-02-C related bug 2019-09-09 17:42:20 +08:00
lly
2c852b0d74 ble_mesh: fix MESH/NODE/CFG/HBS/BV-01-C related bug 2019-09-09 17:42:08 +08:00
lly
708bff3b17 ble_mesh: rename ble mesh client model variables and functions 2019-09-09 17:42:00 +08:00
lly
317f4c5ff5 ble_mesh: reorganize ble mesh model files 2019-09-09 17:41:54 +08:00
lly
2c025824d7 ble_mesh: sync zephyr v1.14.0 bt_hex() 2019-09-09 17:41:41 +08:00
lly
9b95064018 ble_mesh: fix provisioner prov auth bug 2019-09-09 17:41:34 +08:00
ecdffe531e Merge branch 'bugfix/reset_periph_modules_v4.0' into 'release/v4.0'
driver: Add a reset before enabling if a module is off (v4.0)

See merge request espressif/esp-idf!6015
2019-09-08 23:06:31 +08:00
31be6be147 Merge branch 'fix/esp_flash_set_get_wp_4.0' into 'release/v4.0'
esp_flash: fix the set/get write protection functions (backport v4.0)

See merge request espressif/esp-idf!5832
2019-09-08 16:34:40 +08:00
305a4a1b57 ethernet: bugfix and optimize
1. check frame length before pass to stack
2. replace semaphore with task notify
2019-09-06 15:46:18 +08:00
e659f1b15a Merge branch 'bugfix/fix_the_bug_for_WPA_WPA2_PSK_connection_fail_v4.0' into 'release/v4.0'
fix the bug for WPA_WPA2_PSK connection fail(backport v4.0)

See merge request espressif/esp-idf!6010
2019-09-06 14:52:58 +08:00
2c49592216 Merge branch 'refactor/move_smartconfig_ack_to_wifi_v4.0' into 'release/v4.0'
smartconfig: move smartconfig_ack to esp_wifi conponent (v4.0)

See merge request espressif/esp-idf!5999
2019-09-06 14:27:29 +08:00
6afb2743e7 components/bt: Fix sending LMP_features_req_ext in a loop
Remove xtensa/xtruntime.h at the same time
2019-09-06 12:04:16 +08:00
f7b458841f app_update: Fix UTs for FACTORY_RESET and APP_TEST 2019-09-06 11:59:03 +08:00
f1e9b8299f bootloader: Factory reset not for deep sleep
Closes: https://github.com/espressif/esp-idf/issues/3800

Closes: IDFGH-1536
2019-09-06 11:59:03 +08:00
9ce1b8986a rmt/driver: Add module reset before enabling 2019-09-06 11:34:53 +08:00
c5bea8dddb pcnt/driver: Add module reset before enabling 2019-09-06 11:34:53 +08:00
ba6b502cc9 sdmmc_host/driver: Add module reset before enabling 2019-09-06 11:34:53 +08:00
3b0b5f92a7 i2s/driver: Add module reset before enabling 2019-09-06 11:34:53 +08:00
d6bc1b3cbc can/driver: Add module reset before enabling 2019-09-06 11:34:53 +08:00
199c4e55f2 uart/driver: Add module reset before enabling
This commit prevents infinite restarts caused due to an interrupt flag
was left uncleared.

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

Closes: IDF-188
2019-09-06 11:34:53 +08:00
61339353e9 newlib: Fix UT - test time adjustment happens linearly
Obtaining accurate and adjustable time occurs closer to each other.
2019-09-06 11:30:01 +08:00
3b2dda5197 1. fix the bug that STA fails to connect WPA_WPA2_PSK Apple AP
2. fix the bug for softAP set authmode
2019-09-05 20:34:34 +08:00
1b8ed9abf0 Merge branch 'bugfix/btdm_crash_in_sket_ist_v4.0' into 'release/v4.0'
Fix 2 bugs in r_ld_fm_sket_isr

See merge request espressif/esp-idf!5947
2019-09-05 12:02:26 +08:00
f9453ef93d Merge branch 'bugfix/btdm_config_but_task_size_fail_v4.0' into 'release/v4.0'
Bugfix/btdm config but task size fail v4.0

See merge request espressif/esp-idf!5962
2019-09-05 11:26:56 +08:00
dcf571c1cd smartconfig: move smartconfig_ack to esp_wifi conponent 2019-09-05 10:44:00 +08:00
538c56426a Merge branch 'bugfix/err_code_collision_v4.0' into 'release/v4.0'
Fix error code collisions and re-enable CI check (v4.0)

See merge request espressif/esp-idf!5984
2019-09-04 09:10:19 +08:00
1402e78844 Fix error code collision and CI check 2019-09-03 08:07:16 +02:00
01f0c8ef16 components/bt: Rename some macros 2019-09-03 10:28:49 +08:00
a774406b91 Use CONFIG value instead of hard-coded value.
Add intermediate defines.

Use CONFIG_BTU_TASK_STACK_SIZE instead of hard-coded value in Bluedroid component
2019-09-03 10:28:12 +08:00
c9bff93080 Merge branch 'feature/enable_cfg_for_tls_asymmetric_content_length_v4.0' into 'release/v4.0'
mbedtls: keep asymmetric tls buffer length option enabled by default (v4.0)

See merge request espressif/esp-idf!5970
2019-09-02 23:25:06 +08:00
4b8e4ff248 Merge branch 'bugfix/btdm_linking_fail_with_toolchain_8.2.0_v4.0' into 'release/v4.0'
components/bt: Fix linking fail with toolchain 8.2.0

See merge request espressif/esp-idf!5967
2019-09-02 22:22:22 +08:00
9dbf979cf3 Merge branch 'bugfix/btdm_remove_unused_macro_in_menuconfig_v4.0' into 'release/v4.0'
components/bt: Remove unused macro in menuconfig

See merge request espressif/esp-idf!5951
2019-09-02 22:21:12 +08:00
ad70ab8957 components/bt: Disable Wide Bond Speech when SCO data path is PCM 2019-09-02 20:55:17 +08:00
cd5dc4d05f Merge branch 'doc/add_ble_mesh_example_description_v4.0' into 'release/v4.0'
ble_mesh: add ble mesh example description(backport v4.0)

See merge request espressif/esp-idf!5948
2019-09-02 14:29:13 +08:00
ebb9384681 Merge branch 'bugfix/various_cmake_fixes_v4.0' into 'release/v4.0'
CMake: Various backports

See merge request espressif/esp-idf!5933
2019-09-02 12:46:40 +08:00
0d3fde04ff Merge branch 'bugfix_kconfig_deps_missing_v4.0' into 'release/v4.0'
kconfig: Add -MP option so .d files include empty targets (v4.0)

See merge request espressif/esp-idf!5845
2019-09-02 12:43:28 +08:00
0552ec5791 Merge branch 'update/cjson_v1_7_12_v4.0' into 'release/v4.0'
Update cJSON to v1.7.12 (v4.0)

See merge request espressif/esp-idf!5850
2019-09-02 12:41:30 +08:00
524eef9225 Merge branch 'test/use_correct_config_for_nvs_compatible_case_v4.0' into 'release/v4.0'
test: fix nvs compatible case error (backport v4.0)

See merge request espressif/esp-idf!5891
2019-09-02 12:40:46 +08:00
955f7e2877 Merge branch 'test/fix_mesh_test_case_4.0' into 'release/v4.0'
test: fix test case MESH_EST_2403 (backport 4.0)

See merge request espressif/esp-idf!5907
2019-09-02 12:38:51 +08:00
lly
e28834aa15 ble_mesh: add ble mesh example description 2019-09-02 12:17:47 +08:00
ac03786412 Merge branch 'bugfix/wps_workaround_for_Telstra_AP_v4.0' into 'release/v4.0'
wps: Relax the check on older config methods in case of WPS2.0 (backport v4.0)

See merge request espressif/esp-idf!5952
2019-09-02 12:04:49 +08:00
a5dae2ff43 mbedtls: keep asymmetric tls buffer length option enabled by default 2019-08-31 10:24:37 +05:30
1d0142d25d components/bt: Fix linking fail with toolchain 8.2.0 2019-08-30 17:56:01 +08:00
65ef597da6 Merge branch 'bugfix/test_esp_efuse_table_on_host_v4.0' into 'release/v4.0'
CI: Fix path in the Efuse table test (v4.0)

See merge request espressif/esp-idf!5953
2019-08-30 16:27:47 +08:00
310beae373 Merge branch 'bugfix/revert_optimize_wifi_rx_v4.0' into 'release/v4.0'
esp_wifi: revert WiFi RX optimization

See merge request espressif/esp-idf!5941
2019-08-30 10:59:20 +08:00
cf0caaec11 esp_wifi: revert WiFi RX optimization
Revert following commit since it has compatibility issue:
commit 45dd6175cd
esp32: optimize wifi rx
2019-08-29 21:26:42 +08:00
4af9504a65 components/bt: Remove unused macro in menuconfig 2019-08-29 19:58:58 +08:00
64bece146c Fix path in the Efuse table test 2019-08-29 09:50:38 +02:00
6b348b94e3 wps: Relax the check on older config methods in case of WPS2.0 (backport
v4.0)

Some APs incorrectly advertize newer WPS2.0 config method bits
without setting bits for the corresponding older methods. This
results in failures during 8-way handshake. Add a workaround to
relax this check so that WPS handshake can proceed.
2019-08-29 13:05:02 +05:30
6222040888 Fix 2 bugs in r_ld_fm_sket_isr
1. When remove two elt in the 1st isr, then assert in then 2nd one.
2. When timestamp of first elt is equal to sket_clkn, then crash.
2019-08-29 11:31:57 +08:00
ea1037742d Merge branch 'bugfix/confgen_msys_path_v4.0' into 'release/v4.0'
Fix sdkconfig.rename paths for confgen.py in MSYS (v4.0)

See merge request espressif/esp-idf!5904
2019-08-29 10:15:21 +08:00
465d46e9dd Merge branch 'bugfix/cmake_src_exclude_issue_v4.0' into 'release/v4.0'
cmake: fix issue with handling of EXCLUDE_SRCS (v4.0)

See merge request espressif/esp-idf!5900
2019-08-28 14:42:20 +08:00
e71e4da388 cmake: check include directories 2019-08-28 10:28:17 +08:00
c711e969cc components: fix incorrect include dir args 2019-08-28 10:28:17 +08:00
3f1ec39a8d cmake: fix issue with checking build process args 2019-08-28 10:28:17 +08:00
f62798cb8b cmake: make default version 1 2019-08-28 10:28:17 +08:00
b6c89984a9 cmake: fix build failure when git repo is initialized but no first commit
Closes https://github.com/espressif/esp-idf/issues/3920
2019-08-28 10:28:17 +08:00
520ecb0c4d ldgen: fix build issue on make when build dir is a symlink
Fixes an issue where build fails if the build directory is a symlink.
The issue is caused by the rule target and the final executable dependency
not matching.

Closes https://github.com/espressif/esp-idf/issues/3626
2019-08-28 10:28:17 +08:00
b669495d97 Make sure ESP_PLATFORM is defined when processing CMake files. 2019-08-28 10:28:17 +08:00
8778c551eb cmake: set build dir for mconf-idf
Fixes an issue where if idf_build_process is called in a CMake
subdirectory, menuconfig looks for the mconf-idf binary in the wrong
place (in the subdirectory build dir instead of root binary dir).
2019-08-28 10:28:17 +08:00
c34d313a86 mbedtls: add source files to appropriate library 2019-08-28 10:28:17 +08:00
ebcb3a22b8 Merge branch 'bugfix/btdm_fix_ble_data_loss_and_send_same_pkt_twice_v4.0' into 'release/v4.0'
Component/bt: fix some BLE bugs (backport v4.0)

See merge request espressif/esp-idf!5909
2019-08-27 18:49:55 +08:00
6781d01e89 cmake: fix encrypted project flash arg file generation 2019-08-27 13:35:39 +08:00
4c9f30a869 cmake: set component properties 2019-08-27 13:35:21 +08:00
61ba1c3026 components/bt: backport 2 BT bugfix about controller
1.Bugfix btdm sleep twice after wakeup request
2.Set the minimum encryption key size to be 7 octects for BR/EDR link for preventing KNOB attack
    This patch is to address the CVE-2019-9506 vulnerability.
2019-08-27 10:42:40 +08:00
90bbea65c1 Component/bt: fix some BLE bugs
- fix data loss and send same pkt twice sometimes
- fix adv data error in air sometimes
- fix adv start/stop crash sometimes
2019-08-26 20:29:01 +08:00
672e9f4abc test: fix test case MESH_EST_2403 2019-08-26 20:26:46 +08:00
cb3d458050 Fix sdkconfig.rename paths for confgen.py in MSYS
Closes https://github.com/espressif/esp-idf/issues/3950
2019-08-26 11:12:44 +02:00
b72ff61899 cmake: fix issue with handling of EXCLUDE_SRCS 2019-08-26 11:49:30 +05:30
83b9727c42 test: fix nvs compatible case error:
nvs compatible test case uses new test env and app. update test config
file.
2019-08-25 20:46:56 +08:00
7bb8b5ba9e Merge branch 'Bugfix/nonblocking_udp_is_zero_for_4.0' into 'release/v4.0'
fix bug for nonblocking udp is zero for v4.0

See merge request espressif/esp-idf!5855
2019-08-23 10:50:45 +08:00
1f5f6adcb6 fix bug for nonblocking udp is zero for v4.0 2019-08-21 17:07:45 +08:00
aa0bb29404 Update cJSON to v1.7.12
Fixes potential DoS in cJSON_Minify, see https://github.com/DaveGamble/cJSON/issues/354
2019-08-21 18:40:50 +10:00
2264ea7714 kconfig: Add -MP option so .d files include empty targets
Prevents make-level errors when switching IDF versions, as headers may be removed.

Similar to some mentioned here:
https://github.com/espressif/esp-idf/issues/712
2019-08-21 18:20:47 +10:00
a626b26cf9 esp_flash: improve the comments a bit 2019-08-20 14:05:35 +08:00
1cc860216e esp_flash: fix the set/get write protection functions
Add support for get write protection support, fixed the duplicated
set_write_protection link.

All the write_protection check in the top layer are removed. The lower
levels (chip) should ensure to disable write protection before the
operation start.
2019-08-20 14:05:35 +08:00
16ee476a77 Merge branch 'bugfix/config_panic_gdbstub_build_issue_v4.0' into 'release/v4.0'
esp32_gdbstub: fix build error with esp32-2019r1 toolchain (v4.0)

See merge request espressif/esp-idf!5764
2019-08-20 13:11:24 +08:00
674ecc3b56 Merge branch 'bugfix/vfs_concurrent_select_v4.0' into 'release/v4.0'
VFS: Support concurrent VFS select calls & improve the documentation (backport v4.0)

See merge request espressif/esp-idf!5797
2019-08-20 12:49:03 +08:00
43efee5232 Merge branch 'bugfix/fix_mbedtls_net_sockets_error_handling_v4.0' into 'release/v4.0'
mbedtls: use `errno` instead of `SO_ERROR` for getting socket errors (v4.0)

See merge request espressif/esp-idf!5768
2019-08-20 12:28:56 +08:00
5dab23ea98 Merge branch 'bugfix/confserver_temporaryfile_windows_v4.0' into 'release/v4.0'
confserver: Fix NamedTemporaryFile use on Windows (v4.0)

See merge request espressif/esp-idf!5818
2019-08-20 12:28:16 +08:00
79afd2d580 confserver: Fix NamedTemporaryFile use on Windows
Can't have the file open twice, so need to close and delete after reopening.
2019-08-19 17:44:18 +10:00
a8e8919bbf tools: Support sdkconfig.rename files from outside IDF in confgen.py 2019-08-19 17:44:18 +10:00
ba0f4f17ed Merge branch 'bugfix/doc_pip_requirements_v4.0' into 'release/v4.0'
Add -r flag to pip install command from file (backport v4.0)

See merge request espressif/esp-idf!5798
2019-08-16 13:16:04 +08:00
a63b3c4fe6 Merge branch 'feature/dport_eco_revision2_v4.0' into 'release/v4.0'
make dport workaround depend on chip revision (v4.0)

See merge request espressif/esp-idf!5765
2019-08-16 13:15:18 +08:00
6b8c75d87c Merge branch 'bugfix/hwcrypt_fault_inj_v4.0' into 'release/v4.0'
AES & SHA fault injection checks (backport v4.0)

See merge request espressif/esp-idf!5748
2019-08-16 05:29:54 +08:00
68d82abe52 Added -r flag to pip install command from file
Closes https://github.com/espressif/esp-idf/pull/3874
Closes https://github.com/espressif/esp-idf/issues/3915
2019-08-15 14:23:49 +02:00
ec31f235e9 docs: Correct and extend the documentation about VFS select() 2019-08-15 14:11:51 +02:00
7e9d90b180 VFS: Support concurrent VFS select calls
Closes https://github.com/espressif/esp-idf/issues/3392
2019-08-15 14:11:37 +02:00
d4fcbe37f3 Merge branch 'bugfix/idf_tool_default_encoding_v4.0' into 'release/v4.0'
idf_tool: fix UnicodeDecodeError (v4.0)

See merge request espressif/esp-idf!5720
2019-08-15 16:35:58 +08:00
b9a5f764ba Merge branch 'bugfix/fix_flash_read_error_in_dio_mode_v4.0' into 'release/v4.0'
bugfix(flash): add spi dio address bitlen configure in psram init (backprot v4.0)

See merge request espressif/esp-idf!5790
2019-08-15 12:08:56 +08:00
764b70d7e6 bugfix(flash): add spi dio address bitlen configure in psram init 2019-08-15 10:52:56 +08:00
a1496b90e5 Merge branch 'bugfix/fix_ledc_clock_select_bug_v4.0' into 'release/v4.0'
driver(ledc): fixed ledc clock selection bug for v4.0

See merge request espressif/esp-idf!5757
2019-08-14 10:44:39 +08:00
622d6d5504 mbedtls: use errno instead of SO_ERROR for getting socket errors
As per upgrade notes of lwIP v2.1.0:
socket API: according to the standard, SO_ERROR now only returns asynchronous errors.
All other/normal/synchronous errors are (and always were) available via 'errno'.
LWIP_SOCKET_SET_ERRNO has been removed - 'errno' is always set - and required!

Refer: https://www.nongnu.org/lwip/2_1_x/upgrading.html

Fixes https://github.com/espressif/esp-azure/issues/51
2019-08-13 13:11:24 +05:30
1b903111b6 efuse: update the scheme of getting chip revision 2019-08-13 14:37:17 +08:00
69ef694178 esp32_gdbstub: fix build error with esp32-2019r1 toolchain
Fixes https://github.com/espressif/esp-idf/issues/3866
Closes https://github.com/espressif/esp-idf/issues/3834
2019-08-13 11:38:28 +05:30
81651b47a4 Merge branch 'ci/disable_nimble_tests_v4.0' into 'release/v4.0'
ci: Temporarily disable NimBLE tests in CI (v4.0)

See merge request espressif/esp-idf!5754
2019-08-13 10:42:38 +08:00
30dc86179c Merge branch 'bugfix/fix_wifi_bugs_for_authmode_and_multi_ssid_v4.0' into 'release/v4.0'
fix wifi bugs for authmode and multi ssid (backport v4.0)

See merge request espressif/esp-idf!5725
2019-08-12 23:34:43 +08:00
eff3ac05b3 driver(ledc): fixed ledc clock selection bug for release/v4.0 2019-08-12 17:16:52 +08:00
e5349d47a8 ci: Temporarily disable NimBLE tests in CI 2019-08-12 17:14:54 +10:00
4253adf42b modify WIFI_CONN_0101 case for wrong authmode of AP 2019-08-12 02:38:44 +00:00
088ed65194 wifi: fix wifi bugs for authmode and multi ssid 2019-08-12 02:38:44 +00:00
0ce94950b7 sha: Add fault injection checks reading hash digest state
Vulnerability reported by LimitedResults under Espressif Bug Bounty Program.
2019-08-11 15:58:48 +10:00
ae8b2684d7 aes: Add fault injection checks when writing key to hardware
Vulnerability reported by LimitedResults under Espressif Bug Bounty Program.
2019-08-11 15:58:48 +10:00
9c51f679a7 Merge branch 'bugfix/update_example_docs_build_instructions_to_cmake_v4.0' into 'release/v4.0'
examples: change default build instructions in docs to CMake (v4.0)

See merge request espressif/esp-idf!5704
2019-08-09 13:20:25 +08:00
5c07acad46 idf_tool: fix unicode decode error
Closes https://github.com/espressif/esp-idf/issues/3841
2019-08-07 21:27:29 +08:00
70af759dd2 examples: change default build instructions in docs to CMake 2019-08-06 17:25:25 +05:30
76191a0f55 Merge branch 'move/ble_example_v4.0' into 'release/v4.0'
examples/bluetooth: Move the demos to the appropriate locations (v4.0)

See merge request espressif/esp-idf!5687
2019-08-06 00:32:26 +08:00
f0c3114f2f examples/bluetooth: Move the demos to the appropriate locations (v4.0) 2019-08-06 00:32:25 +08:00
438 changed files with 6913 additions and 5869 deletions

View File

@ -39,7 +39,7 @@ See the Getting Started guide links above for a detailed setup guide. This is a
* Install host build dependencies mentioned in Getting Started guide.
* Add `tools/` directory to the PATH
* Run `python -m pip install requirements.txt` to install Python dependencies
* Run `python -m pip install -r requirements.txt` to install Python dependencies
## Configuring the Project

View File

@ -40,9 +40,6 @@ read_otadata: $(PARTITION_TABLE_CSV_PATH) partition_table_get_info | check_pytho
--partition-table-offset $(partition_table_offset) \
read_otadata
erase_ota: erase_otadata
@echo "WARNING: erase_ota is deprecated. Use erase_otadata instead."
all: blank_ota_data
flash: blank_ota_data
ifdef CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT

View File

@ -444,7 +444,7 @@ static void test_flow4(void)
// 2 Stage: run factory -> check it -> copy factory to OTA0 -> reboot --//--
// 3 Stage: run OTA0 -> check it -> set_pin_factory_reset -> reboot --//--
// 4 Stage: run factory -> check it -> erase OTA_DATA for next tests -> PASS
TEST_CASE_MULTIPLE_STAGES("Switching between factory, OTA0, sets pin_factory_reset, factory", "[app_update][timeout=90][reset=DEEPSLEEP_RESET, DEEPSLEEP_RESET, DEEPSLEEP_RESET]", start_test, test_flow4, test_flow4, test_flow4);
TEST_CASE_MULTIPLE_STAGES("Switching between factory, OTA0, sets pin_factory_reset, factory", "[app_update][timeout=90][ignore][reset=DEEPSLEEP_RESET, DEEPSLEEP_RESET, DEEPSLEEP_RESET]", start_test, test_flow4, test_flow4, test_flow4);
#endif
#ifdef CONFIG_BOOTLOADER_APP_TEST
@ -487,7 +487,7 @@ static void test_flow5(void)
// 2 Stage: run factory -> check it -> copy factory to Test and set pin_test_app -> reboot --//--
// 3 Stage: run test -> check it -> reset pin_test_app -> reboot --//--
// 4 Stage: run factory -> check it -> erase OTA_DATA for next tests -> PASS
TEST_CASE_MULTIPLE_STAGES("Switching between factory, test, factory", "[app_update][timeout=90][reset=DEEPSLEEP_RESET, DEEPSLEEP_RESET, DEEPSLEEP_RESET]", start_test, test_flow5, test_flow5, test_flow5);
TEST_CASE_MULTIPLE_STAGES("Switching between factory, test, factory", "[app_update][timeout=90][ignore][reset=DEEPSLEEP_RESET, DEEPSLEEP_RESET, DEEPSLEEP_RESET]", start_test, test_flow5, test_flow5, test_flow5);
#endif
static const esp_partition_t* app_update(void)

View File

@ -338,7 +338,7 @@ menu "Security features"
config SECURE_BOOT_SIGNING_KEY
string "Secure boot private signing key"
depends on SECURE_BOOT_BUILD_SIGNED_BINARIES
default secure_boot_signing_key.pem
default "secure_boot_signing_key.pem"
help
Path to the key file used to sign app images.
@ -354,7 +354,7 @@ menu "Security features"
config SECURE_BOOT_VERIFICATION_KEY
string "Secure boot public signature verification key"
depends on SECURE_SIGNED_APPS && !SECURE_BOOT_BUILD_SIGNED_BINARIES
default signature_verification_key.bin
default "signature_verification_key.bin"
help
Path to a public key file used to verify signed images. This key is compiled into the bootloader and/or
app, to verify app images.
@ -368,7 +368,7 @@ menu "Security features"
choice SECURE_BOOTLOADER_KEY_ENCODING
bool "Hardware Key Encoding"
depends on SECURE_BOOTLOADER_REFLASHABLE
default SECURE_BOOTLOADER_NO_ENCODING
default SECURE_BOOTLOADER_KEY_ENCODING_256BIT
help
In reflashable secure bootloader mode, a hardware key is derived from the signing key (with SHA-256) and
@ -515,6 +515,20 @@ menu "Security features"
Only set this option in testing environments.
config SECURE_FLASH_REQUIRE_ALREADY_ENABLED
bool "Require flash encryption to be already enabled"
depends on SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT
default N
help
If not set (default), and flash encryption is not yet enabled in eFuses, the 2nd stage bootloader
will enable flash encryption: generate the flash encryption key and program eFuses.
If this option is set, and flash encryption is not yet enabled, the bootloader will error out and
reboot.
If flash encryption is enabled in eFuses, this option does not change the bootloader behavior.
Only use this option in testing environments, to avoid accidentally enabling flash encryption on
the wrong device. The device needs to have flash encryption already enabled using espefuse.py.
endmenu # Potentially Insecure
endmenu # Security features

View File

@ -24,6 +24,7 @@
#include "bootloader_common.h"
#include "sdkconfig.h"
#include "esp_image_format.h"
#include "esp32/rom/rtc.h"
static const char* TAG = "boot";
@ -74,7 +75,8 @@ static int selected_boot_partition(const bootloader_state_t *bs)
int boot_index = bootloader_utility_get_selected_boot_partition(bs);
if (boot_index == INVALID_INDEX) {
return boot_index; // Unrecoverable failure (not due to corrupt ota data or bad partition contents)
} else {
}
if (rtc_get_reset_reason(0) != DEEPSLEEP_RESET) {
// Factory firmware.
#ifdef CONFIG_BOOTLOADER_FACTORY_RESET
if (bootloader_common_check_long_hold_gpio(CONFIG_BOOTLOADER_NUM_PIN_FACTORY_RESET, CONFIG_BOOTLOADER_HOLD_TIME_GPIO) == 1) {

View File

@ -40,6 +40,7 @@ SECTIONS
*(.iram1 .iram1.*) /* catch stray IRAM_ATTR */
*liblog.a:(.literal .text .literal.* .text.*)
*libgcc.a:(.literal .text .literal.* .text.*)
*libbootloader_support.a:bootloader_clock.*(.literal .text .literal.* .text.*)
*libbootloader_support.a:bootloader_common.*(.literal .text .literal.* .text.*)
*libbootloader_support.a:bootloader_flash.*(.literal .text .literal.* .text.*)
*libbootloader_support.a:bootloader_random.*(.literal .text .literal.* .text.*)
@ -53,6 +54,7 @@ SECTIONS
*libmicro-ecc.a:*.*(.literal .text .literal.* .text.*)
*libspi_flash.a:*.*(.literal .text .literal.* .text.*)
*libsoc.a:rtc_wdt.*(.literal .text .literal.* .text.*)
*libsoc.a:rtc_clk.*(.literal .text .literal.* .text.*)
*libefuse.a:*.*(.literal .text .literal.* .text.*)
*(.fini.literal)
*(.fini)

View File

@ -133,6 +133,21 @@ void esp_flash_write_protect_crypt_cnt();
*/
esp_flash_enc_mode_t esp_get_flash_encryption_mode();
/** @brief Check the flash encryption mode during startup
*
* @note This function is called automatically during app startup,
* it doesn't need to be called from the app.
*
* Verifies the flash encryption config during startup:
*
* - Correct any insecure flash encryption settings if hardware
* Secure Boot is enabled.
* - Log warnings if the efuse config doesn't match the project
* config in any way
*/
void esp_flash_encryption_init_checks(void);
#ifdef __cplusplus
}
#endif

View File

@ -98,12 +98,6 @@ typedef struct {
esp_err_t esp_partition_table_verify(const esp_partition_info_t *partition_table, bool log_errors, int *num_partitions);
/* This function is included for compatibility with the ESP-IDF v3.x API */
inline static __attribute__((deprecated)) esp_err_t esp_partition_table_basic_verify(const esp_partition_info_t *partition_table, bool log_errors, int *num_partitions)
{
return esp_partition_table_verify(partition_table, log_errors, num_partitions);
}
/**
* Check whether the region on the main flash is safe to write.
*

View File

@ -51,36 +51,6 @@ typedef enum {
#endif
} esp_image_load_mode_t;
/**
* @brief Verify and (optionally, in bootloader mode) load an app image.
*
* This name is deprecated and is included for compatibility with the ESP-IDF v3.x API.
* It will be removed in V4.0 version.
* Function has been renamed to esp_image_verify().
* Use function esp_image_verify() to verify a image. And use function bootloader_load_image() to load image from a bootloader space.
*
* If encryption is enabled, data will be transparently decrypted.
*
* @param mode Mode of operation (verify, silent verify, or load).
* @param part Partition to load the app from.
* @param[inout] data Pointer to the image metadata structure which is be filled in by this function. 'start_addr' member should be set (to the start address of the image.) Other fields will all be initialised by this function.
*
* Image validation checks:
* - Magic byte.
* - Partition smaller than 16MB.
* - All segments & image fit in partition.
* - 8 bit image checksum is valid.
* - SHA-256 of image is valid (if image has this appended).
* - (Signature) if signature verification is enabled.
*
* @return
* - ESP_OK if verify or load was successful
* - ESP_ERR_IMAGE_FLASH_FAIL if a SPI flash error occurs
* - ESP_ERR_IMAGE_INVALID if the image appears invalid.
* - ESP_ERR_INVALID_ARG if the partition or data pointers are invalid.
*/
esp_err_t esp_image_load(esp_image_load_mode_t mode, const esp_partition_pos_t *part, esp_image_metadata_t *data) __attribute__((deprecated));
/**
* @brief Verify an app image.
*

View File

@ -58,3 +58,12 @@ void bootloader_clock_configure()
}
#endif
}
#ifdef BOOTLOADER_BUILD
int esp_clk_apb_freq(void)
{
return rtc_clk_apb_freq_get();
}
#endif // BOOTLOADER_BUILD

View File

@ -37,7 +37,7 @@ static const char *TAG = "flash_encrypt";
/* Static functions for stages of flash encryption */
static esp_err_t initialise_flash_encryption(void);
static esp_err_t encrypt_flash_contents(uint32_t flash_crypt_cnt, bool flash_crypt_wr_dis);
static esp_err_t encrypt_flash_contents(uint32_t flash_crypt_cnt, bool flash_crypt_wr_dis) __attribute__((unused));
static esp_err_t encrypt_bootloader();
static esp_err_t encrypt_and_load_partition_table(esp_partition_info_t *partition_table, int *num_partitions);
static esp_err_t encrypt_partition(int index, const esp_partition_info_t *partition);
@ -60,8 +60,14 @@ esp_err_t esp_flash_encrypt_check_and_update(void)
return ESP_OK;
}
else {
#ifndef CONFIG_SECURE_FLASH_REQUIRE_ALREADY_ENABLED
/* Flash is not encrypted, so encrypt it! */
return encrypt_flash_contents(flash_crypt_cnt, flash_crypt_wr_dis);
#else
ESP_LOGE(TAG, "flash encryption is not enabled, and SECURE_FLASH_REQUIRE_ALREADY_ENABLED "
"is set, refusing to boot.");
return ESP_ERR_INVALID_STATE;
#endif // CONFIG_SECURE_FLASH_REQUIRE_ALREADY_ENABLED
}
}

View File

@ -268,8 +268,6 @@ esp_err_t esp_image_verify(esp_image_load_mode_t mode, const esp_partition_pos_t
return image_load(mode, part, data);
}
esp_err_t esp_image_load(esp_image_load_mode_t mode, const esp_partition_pos_t *part, esp_image_metadata_t *data) __attribute__((alias("esp_image_verify")));
static esp_err_t verify_image_header(uint32_t src_addr, const esp_image_header_t *image, bool silent)
{
esp_err_t err = ESP_OK;

View File

@ -13,9 +13,51 @@
// limitations under the License.
#include <strings.h>
#include "sdkconfig.h"
#include "esp_log.h"
#include "esp_efuse.h"
#include "esp_efuse_table.h"
#include "esp_flash_encrypt.h"
#include "esp_secure_boot.h"
#ifndef BOOTLOADER_BUILD
static const char *TAG = "flash_encrypt";
void esp_flash_encryption_init_checks()
{
esp_flash_enc_mode_t mode;
// First check is: if Release mode flash encryption & secure boot are enabled then
// FLASH_CRYPT_CNT *must* be write protected. This will have happened automatically
// if bootloader is IDF V4.0 or newer but may not have happened for previous ESP-IDF bootloaders.
#ifdef CONFIG_SECURE_FLASH_ENCRYPTION_MODE_RELEASE
#ifdef CONFIG_SECURE_BOOT_ENABLED
if (esp_secure_boot_enabled() && esp_flash_encryption_enabled()) {
uint8_t flash_crypt_cnt_wr_dis = 0;
esp_efuse_read_field_blob(ESP_EFUSE_WR_DIS_FLASH_CRYPT_CNT, &flash_crypt_cnt_wr_dis, 1);
if (!flash_crypt_cnt_wr_dis) {
ESP_EARLY_LOGE(TAG, "Flash encryption & Secure Boot together requires FLASH_CRYPT_CNT efuse to be write protected. Fixing now...");
esp_flash_write_protect_crypt_cnt();
}
}
#endif // CONFIG_SECURE_BOOT_ENABLED
#endif // CONFIG_SECURE_FLASH_ENCRYPTION_MODE_RELEASE
// Second check is to print a warning or error if the current running flash encryption mode
// doesn't match the expectation from project config (due to mismatched bootloader and app, probably)
mode = esp_get_flash_encryption_mode();
if (mode == ESP_FLASH_ENC_MODE_DEVELOPMENT) {
#ifdef CONFIG_SECURE_FLASH_ENCRYPTION_MODE_RELEASE
ESP_EARLY_LOGE(TAG, "Flash encryption settings error: app is configured for RELEASE but efuses are set for DEVELOPMENT");
ESP_EARLY_LOGE(TAG, "Mismatch found in security options in bootloader menuconfig and efuse settings. Device is not secure.");
#else
ESP_EARLY_LOGW(TAG, "Flash encryption mode is DEVELOPMENT (not secure)");
#endif
} else if (mode == ESP_FLASH_ENC_MODE_RELEASE) {
ESP_EARLY_LOGI(TAG, "Flash encryption mode is RELEASE");
}
}
#endif
void esp_flash_write_protect_crypt_cnt()
{

View File

@ -297,7 +297,8 @@ if(CONFIG_BT_ENABLED)
"esp_ble_mesh/mesh_core/include"
"esp_ble_mesh/mesh_core/settings"
"esp_ble_mesh/btc/include"
"esp_ble_mesh/mesh_models/include"
"esp_ble_mesh/mesh_models/common/include"
"esp_ble_mesh/mesh_models/client/include"
"esp_ble_mesh/api/core/include"
"esp_ble_mesh/api/models/include"
"esp_ble_mesh/api")
@ -350,12 +351,12 @@ if(CONFIG_BT_ENABLED)
"esp_ble_mesh/mesh_core/settings.c"
"esp_ble_mesh/mesh_core/test.c"
"esp_ble_mesh/mesh_core/transport.c"
"esp_ble_mesh/mesh_models/generic_client.c"
"esp_ble_mesh/mesh_models/lighting_client.c"
"esp_ble_mesh/mesh_models/mesh_common.c"
"esp_ble_mesh/mesh_models/model_common.c"
"esp_ble_mesh/mesh_models/sensor_client.c"
"esp_ble_mesh/mesh_models/time_scene_client.c")
"esp_ble_mesh/mesh_models/common/mesh_common.c"
"esp_ble_mesh/mesh_models/client/client_common.c"
"esp_ble_mesh/mesh_models/client/generic_client.c"
"esp_ble_mesh/mesh_models/client/lighting_client.c"
"esp_ble_mesh/mesh_models/client/sensor_client.c"
"esp_ble_mesh/mesh_models/client/time_scene_client.c")
endif()
if(CONFIG_BT_NIMBLE_ENABLED)
@ -376,9 +377,13 @@ if(CONFIG_BT_ENABLED)
host/nimble/nimble/nimble/host/store/ram/include
host/nimble/nimble/nimble/host/store/config/include
host/nimble/nimble/porting/npl/freertos/include
host/nimble/nimble/ext/tinycrypt/include
host/nimble/esp-hci/include)
if(NOT CONFIG_BT_NIMBLE_CRYPTO_STACK_MBEDTLS)
list(APPEND include_dirs
host/nimble/nimble/ext/tinycrypt/include)
list(APPEND srcs "host/nimble/nimble/ext/tinycrypt/src/utils.c"
"host/nimble/nimble/ext/tinycrypt/src/sha256.c"
"host/nimble/nimble/ext/tinycrypt/src/ecc.c"
@ -393,8 +398,10 @@ if(CONFIG_BT_ENABLED)
"host/nimble/nimble/ext/tinycrypt/src/hmac_prng.c"
"host/nimble/nimble/ext/tinycrypt/src/ecc_platform_specific.c"
"host/nimble/nimble/ext/tinycrypt/src/hmac.c"
"host/nimble/nimble/ext/tinycrypt/src/cbc_mode.c"
"host/nimble/nimble/nimble/host/util/src/addr.c"
"host/nimble/nimble/ext/tinycrypt/src/cbc_mode.c")
endif()
list(APPEND srcs "host/nimble/nimble/nimble/host/util/src/addr.c"
"host/nimble/nimble/nimble/host/services/gatt/src/ble_svc_gatt.c"
"host/nimble/nimble/nimble/host/services/tps/src/ble_svc_tps.c"
"host/nimble/nimble/nimble/host/services/ias/src/ble_svc_ias.c"

View File

@ -1,4 +1,4 @@
menu Bluetooth
menu "Bluetooth"
config BT_ENABLED
bool "Bluetooth"
@ -358,6 +358,21 @@ menu Bluetooth
If you set `BTDM_BLE_ADV_REPORT_DISCARD_THRSHOLD` to a small value or printf every adv lost event, it
may cause adv packets lost more.
menuconfig BTDM_COEX_BT_OPTIONS
bool "Coexistence Bluetooth Side Options"
depends on ESP32_WIFI_SW_COEXIST_ENABLE
default n
help
Options of Bluetooth Side of WiFi and bluetooth coexistence.
config BTDM_COEX_BLE_ADV_HIGH_PRIORITY
bool "Improve BLE ADV priority for WiFi & BLE coexistence"
depends on BTDM_COEX_BT_OPTIONS
default n
help
Improve BLE ADV coexistence priority to make it better performance.
For example, BLE mesh need to enable this option to improve BLE adv performance.
endmenu
choice BT_HOST

View File

@ -114,16 +114,16 @@ static const btc_func_t profile_tab[BTC_PID_NUM] = {
#endif /* #if CLASSIC_BT_INCLUDED */
#endif
#if CONFIG_BLE_MESH
[BTC_PID_PROV] = {btc_mesh_prov_call_handler, btc_mesh_prov_cb_handler},
[BTC_PID_MODEL] = {btc_mesh_model_call_handler, btc_mesh_model_cb_handler},
[BTC_PID_HEALTH_CLIENT] = {btc_mesh_health_client_call_handler, btc_mesh_health_client_cb_handler},
[BTC_PID_HEALTH_SERVER] = {btc_mesh_health_server_call_handler, btc_mesh_health_server_cb_handler},
[BTC_PID_CFG_CLIENT] = {btc_mesh_cfg_client_call_handler, btc_mesh_cfg_client_cb_handler},
[BTC_PID_CFG_SERVER] = {NULL , btc_mesh_cfg_server_cb_handler},
[BTC_PID_GENERIC_CLIENT] = {btc_mesh_generic_client_call_handler, btc_mesh_generic_client_cb_handler},
[BTC_PID_LIGHT_CLIENT] = {btc_mesh_light_client_call_handler, btc_mesh_light_client_cb_handler},
[BTC_PID_SENSOR_CLIENT] = {btc_mesh_sensor_client_call_handler, btc_mesh_sensor_client_cb_handler},
[BTC_PID_TIME_SCENE_CLIENT] = {btc_mesh_time_scene_client_call_handler, btc_mesh_time_scene_client_cb_handler},
[BTC_PID_PROV] = {btc_ble_mesh_prov_call_handler, btc_ble_mesh_prov_cb_handler },
[BTC_PID_MODEL] = {btc_ble_mesh_model_call_handler, btc_ble_mesh_model_cb_handler },
[BTC_PID_HEALTH_CLIENT] = {btc_ble_mesh_health_client_call_handler, btc_ble_mesh_health_client_cb_handler },
[BTC_PID_HEALTH_SERVER] = {btc_ble_mesh_health_server_call_handler, btc_ble_mesh_health_server_cb_handler },
[BTC_PID_CONFIG_CLIENT] = {btc_ble_mesh_config_client_call_handler, btc_ble_mesh_config_client_cb_handler },
[BTC_PID_CONFIG_SERVER] = {NULL, btc_ble_mesh_config_server_cb_handler },
[BTC_PID_GENERIC_CLIENT] = {btc_ble_mesh_generic_client_call_handler, btc_ble_mesh_generic_client_cb_handler },
[BTC_PID_LIGHTING_CLIENT] = {btc_ble_mesh_lighting_client_call_handler, btc_ble_mesh_lighting_client_cb_handler },
[BTC_PID_SENSOR_CLIENT] = {btc_ble_mesh_sensor_client_call_handler, btc_ble_mesh_sensor_client_cb_handler },
[BTC_PID_TIME_SCENE_CLIENT] = {btc_ble_mesh_time_scene_client_call_handler, btc_ble_mesh_time_scene_client_cb_handler},
#endif /* #if CONFIG_BLE_MESH */
};

View File

@ -72,10 +72,10 @@ typedef enum {
BTC_PID_MODEL,
BTC_PID_HEALTH_CLIENT,
BTC_PID_HEALTH_SERVER,
BTC_PID_CFG_CLIENT,
BTC_PID_CFG_SERVER,
BTC_PID_CONFIG_CLIENT,
BTC_PID_CONFIG_SERVER,
BTC_PID_GENERIC_CLIENT,
BTC_PID_LIGHT_CLIENT,
BTC_PID_LIGHTING_CLIENT,
BTC_PID_SENSOR_CLIENT,
BTC_PID_TIME_SCENE_CLIENT,
#endif /* CONFIG_BLE_MESH */

View File

@ -132,25 +132,28 @@ COMPONENT_SRCDIRS += common/osi \
endif
ifdef CONFIG_BLE_MESH
COMPONENT_ADD_INCLUDEDIRS += esp_ble_mesh/mesh_core \
esp_ble_mesh/mesh_core/include \
esp_ble_mesh/mesh_core/settings \
esp_ble_mesh/btc/include \
esp_ble_mesh/mesh_models/include \
esp_ble_mesh/api/core/include \
esp_ble_mesh/api/models/include \
COMPONENT_ADD_INCLUDEDIRS += esp_ble_mesh/mesh_core \
esp_ble_mesh/mesh_core/include \
esp_ble_mesh/mesh_core/settings \
esp_ble_mesh/btc/include \
esp_ble_mesh/mesh_models/common/include \
esp_ble_mesh/mesh_models/client/include \
esp_ble_mesh/api/core/include \
esp_ble_mesh/api/models/include \
esp_ble_mesh/api
COMPONENT_SRCDIRS += esp_ble_mesh/mesh_core \
esp_ble_mesh/mesh_core/settings \
esp_ble_mesh/btc \
esp_ble_mesh/mesh_models \
esp_ble_mesh/mesh_models/common \
esp_ble_mesh/mesh_models/client \
esp_ble_mesh/api/core \
esp_ble_mesh/api/models
esp_ble_mesh/api/models
endif
ifdef CONFIG_BT_NIMBLE_ENABLED
COMPONENT_ADD_INCLUDEDIRS += host/nimble/nimble/nimble/include \
host/nimble/nimble/nimble/host/include \
host/nimble/nimble/porting/nimble/include \
@ -165,14 +168,16 @@ COMPONENT_ADD_INCLUDEDIRS += host/nimble/nimble/nimble/include
host/nimble/nimble/nimble/host/util/include \
host/nimble/nimble/nimble/host/store/ram/include \
host/nimble/nimble/nimble/host/store/config/include \
host/nimble/nimble/ext/tinycrypt/include \
host/nimble/esp-hci/include \
host/nimble/port/include
ifndef CONFIG_BT_NIMBLE_CRYPTO_STACK_MBEDTLS
COMPONENT_ADD_INCLUDEDIRS += host/nimble/nimble/ext/tinycrypt/include
endif
COMPONENT_SRCDIRS += host/nimble/nimble/nimble/host/src \
host/nimble/nimble/porting/nimble/src \
host/nimble/nimble/porting/npl/freertos/src \
host/nimble/nimble/ext/tinycrypt/src \
host/nimble/nimble/nimble/host/services/ans/src \
host/nimble/nimble/nimble/host/services/bas/src \
host/nimble/nimble/nimble/host/services/gap/src \
@ -185,6 +190,10 @@ COMPONENT_SRCDIRS += host/nimble/nimble/nimble/host/src
host/nimble/nimble/nimble/host/store/config/src \
host/nimble/esp-hci/src
ifndef CONFIG_BT_NIMBLE_CRYPTO_STACK_MBEDTLS
COMPONENT_SRCDIRS += host/nimble/nimble/ext/tinycrypt/src
endif
COMPONENT_OBJEXCLUDE += host/nimble/nimble/nimble/host/store/config/src/ble_store_config_conf.o
ifdef CONFIG_BT_NIMBLE_MESH

View File

@ -203,7 +203,8 @@ extern void btdm_controller_enable_sleep(bool enable);
extern void btdm_controller_set_sleep_mode(uint8_t mode);
extern uint8_t btdm_controller_get_sleep_mode(void);
extern bool btdm_power_state_active(void);
extern void btdm_wakeup_request(void);
extern void btdm_wakeup_request(bool request_lock);
extern void btdm_wakeup_request_end(void);
/* Low Power Clock */
extern bool btdm_lpclk_select_src(uint32_t sel);
extern bool btdm_lpclk_set_div(uint32_t div);
@ -224,6 +225,7 @@ extern int coex_bt_release_wrapper(uint32_t event);
extern int coex_register_bt_cb_wrapper(coex_func_cb_t cb);
extern uint32_t coex_bb_reset_lock_wrapper(void);
extern void coex_bb_reset_unlock_wrapper(uint32_t restore);
extern void coex_ble_adv_priority_high_set(bool high);
extern char _bss_start_btdm;
extern char _bss_end_btdm;
@ -893,6 +895,8 @@ bool esp_vhci_host_check_send_available(void)
void esp_vhci_host_send_packet(uint8_t *data, uint16_t len)
{
bool do_wakeup_request = false;
if (!btdm_power_state_active()) {
#if CONFIG_PM_ENABLE
if (semphr_take_wrapper(s_pm_lock_sem, 0)) {
@ -900,9 +904,15 @@ void esp_vhci_host_send_packet(uint8_t *data, uint16_t len)
}
esp_timer_stop(s_btdm_slp_tmr);
#endif
btdm_wakeup_request();
do_wakeup_request = true;
btdm_wakeup_request(true);
}
API_vhci_host_send_packet(data, len);
if (do_wakeup_request) {
btdm_wakeup_request_end();
}
}
esp_err_t esp_vhci_host_register_callback(const esp_vhci_host_callback_t *callback)
@ -1182,6 +1192,12 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
goto error;
}
#ifdef CONFIG_BTDM_COEX_BLE_ADV_HIGH_PRIORITY
coex_ble_adv_priority_high_set(true);
#else
coex_ble_adv_priority_high_set(false);
#endif
btdm_controller_status = ESP_BT_CONTROLLER_STATUS_INITED;
return ESP_OK;
@ -1328,7 +1344,7 @@ esp_err_t esp_bt_controller_disable(void)
if (btdm_controller_get_sleep_mode() == BTDM_MODEM_SLEEP_MODE_ORIG) {
btdm_controller_enable_sleep(false);
if (!btdm_power_state_active()) {
btdm_wakeup_request();
btdm_wakeup_request(false);
}
while (!btdm_power_state_active()) {
ets_delay_us(1000);
@ -1466,7 +1482,7 @@ void esp_bt_controller_wakeup_request(void)
return;
}
btdm_wakeup_request();
btdm_wakeup_request(false);
}
esp_err_t esp_bredr_sco_datapath_set(esp_sco_data_path_t data_path)

View File

@ -157,7 +157,7 @@ esp_err_t esp_ble_mesh_client_model_init(esp_ble_mesh_model_t *model)
if (model == NULL) {
return ESP_ERR_INVALID_ARG;
}
return btc_ble_mesh_client_init(model);
return btc_ble_mesh_client_model_init(model);
}
esp_err_t esp_ble_mesh_server_model_send_msg(esp_ble_mesh_model_t *model,

View File

@ -123,7 +123,7 @@ typedef uint8_t esp_ble_mesh_octet8_t[ESP_BLE_MESH_OCTET8_LEN];
#define ESP_BLE_MESH_MODEL_ID_GEN_BATTERY_SRV BLE_MESH_MODEL_ID_GEN_BATTERY_SRV
#define ESP_BLE_MESH_MODEL_ID_GEN_BATTERY_CLI BLE_MESH_MODEL_ID_GEN_BATTERY_CLI
#define ESP_BLE_MESH_MODEL_ID_GEN_LOCATION_SRV BLE_MESH_MODEL_ID_GEN_LOCATION_SRV
#define ESP_BLE_MESH_MODEL_ID_GEN_LOCATION_SETUP_SRV BLE_MESH_MODEL_ID_GEN_LOCATION_SETUPSRV
#define ESP_BLE_MESH_MODEL_ID_GEN_LOCATION_SETUP_SRV BLE_MESH_MODEL_ID_GEN_LOCATION_SETUP_SRV
#define ESP_BLE_MESH_MODEL_ID_GEN_LOCATION_CLI BLE_MESH_MODEL_ID_GEN_LOCATION_CLI
#define ESP_BLE_MESH_MODEL_ID_GEN_ADMIN_PROP_SRV BLE_MESH_MODEL_ID_GEN_ADMIN_PROP_SRV
#define ESP_BLE_MESH_MODEL_ID_GEN_MANUFACTURER_PROP_SRV BLE_MESH_MODEL_ID_GEN_MANUFACTURER_PROP_SRV
@ -158,7 +158,7 @@ typedef uint8_t esp_ble_mesh_octet8_t[ESP_BLE_MESH_OCTET8_LEN];
#define ESP_BLE_MESH_MODEL_ID_LIGHT_XYL_SETUP_SRV BLE_MESH_MODEL_ID_LIGHT_XYL_SETUP_SRV
#define ESP_BLE_MESH_MODEL_ID_LIGHT_XYL_CLI BLE_MESH_MODEL_ID_LIGHT_XYL_CLI
#define ESP_BLE_MESH_MODEL_ID_LIGHT_LC_SRV BLE_MESH_MODEL_ID_LIGHT_LC_SRV
#define ESP_BLE_MESH_MODEL_ID_LIGHT_LC_SETUP_SRV BLE_MESH_MODEL_ID_LIGHT_LC_SETUPSRV
#define ESP_BLE_MESH_MODEL_ID_LIGHT_LC_SETUP_SRV BLE_MESH_MODEL_ID_LIGHT_LC_SETUP_SRV
#define ESP_BLE_MESH_MODEL_ID_LIGHT_LC_CLI BLE_MESH_MODEL_ID_LIGHT_LC_CLI
/*!< The following opcodes will only be used in the esp_ble_mesh_config_client_get_state function. */

View File

@ -27,20 +27,20 @@ esp_err_t esp_ble_mesh_register_config_client_callback(esp_ble_mesh_cfg_client_c
{
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
return (btc_profile_cb_set(BTC_PID_CFG_CLIENT, callback) == 0 ? ESP_OK : ESP_FAIL);
return (btc_profile_cb_set(BTC_PID_CONFIG_CLIENT, callback) == 0 ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_mesh_register_config_server_callback(esp_ble_mesh_cfg_server_cb_t callback)
{
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
return (btc_profile_cb_set(BTC_PID_CFG_SERVER, callback) == 0 ? ESP_OK : ESP_FAIL);
return (btc_profile_cb_set(BTC_PID_CONFIG_SERVER, callback) == 0 ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_mesh_config_client_get_state(esp_ble_mesh_client_common_param_t *params,
esp_ble_mesh_cfg_client_get_state_t *get_state)
{
btc_ble_mesh_cfg_client_args_t arg = {0};
btc_ble_mesh_config_client_args_t arg = {0};
btc_msg_t msg = {0};
if (!params || !params->model || !params->ctx.addr || !get_state) {
@ -50,19 +50,19 @@ esp_err_t esp_ble_mesh_config_client_get_state(esp_ble_mesh_client_common_param_
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_CFG_CLIENT;
msg.pid = BTC_PID_CONFIG_CLIENT;
msg.act = BTC_BLE_MESH_ACT_CONFIG_CLIENT_GET_STATE;
arg.cfg_client_get_state.params = params;
arg.cfg_client_get_state.get_state = get_state;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_cfg_client_args_t), btc_ble_mesh_cfg_client_arg_deep_copy)
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_config_client_args_t), btc_ble_mesh_config_client_arg_deep_copy)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_mesh_config_client_set_state(esp_ble_mesh_client_common_param_t *params,
esp_ble_mesh_cfg_client_set_state_t *set_state)
{
btc_ble_mesh_cfg_client_args_t arg = {0};
btc_ble_mesh_config_client_args_t arg = {0};
btc_msg_t msg = {0};
if (!params || !params->model || !params->ctx.addr || !set_state) {
@ -72,11 +72,11 @@ esp_err_t esp_ble_mesh_config_client_set_state(esp_ble_mesh_client_common_param_
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_CFG_CLIENT;
msg.pid = BTC_PID_CONFIG_CLIENT;
msg.act = BTC_BLE_MESH_ACT_CONFIG_CLIENT_SET_STATE;
arg.cfg_client_set_state.params = params;
arg.cfg_client_set_state.set_state = set_state;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_cfg_client_args_t), btc_ble_mesh_cfg_client_arg_deep_copy)
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_config_client_args_t), btc_ble_mesh_config_client_arg_deep_copy)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}

View File

@ -27,13 +27,13 @@ esp_err_t esp_ble_mesh_register_light_client_callback(esp_ble_mesh_light_client_
{
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
return (btc_profile_cb_set(BTC_PID_LIGHT_CLIENT, callback) == 0 ? ESP_OK : ESP_FAIL);
return (btc_profile_cb_set(BTC_PID_LIGHTING_CLIENT, callback) == 0 ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_mesh_light_client_get_state(esp_ble_mesh_client_common_param_t *params,
esp_ble_mesh_light_client_get_state_t *get_state)
{
btc_ble_mesh_light_client_args_t arg = {0};
btc_ble_mesh_lighting_client_args_t arg = {0};
btc_msg_t msg = {0};
if (!params || !params->model || !params->ctx.addr || !get_state) {
@ -43,19 +43,19 @@ esp_err_t esp_ble_mesh_light_client_get_state(esp_ble_mesh_client_common_param_t
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_LIGHT_CLIENT;
msg.act = BTC_BLE_MESH_ACT_LIGHT_CLIENT_GET_STATE;
msg.pid = BTC_PID_LIGHTING_CLIENT;
msg.act = BTC_BLE_MESH_ACT_LIGHTING_CLIENT_GET_STATE;
arg.light_client_get_state.params = params;
arg.light_client_get_state.get_state = get_state;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_light_client_args_t), btc_ble_mesh_light_client_arg_deep_copy)
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_lighting_client_args_t), btc_ble_mesh_lighting_client_arg_deep_copy)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_mesh_light_client_set_state(esp_ble_mesh_client_common_param_t *params,
esp_ble_mesh_light_client_set_state_t *set_state)
{
btc_ble_mesh_light_client_args_t arg = {0};
btc_ble_mesh_lighting_client_args_t arg = {0};
btc_msg_t msg = {0};
if (!params || !params->model || !params->ctx.addr || !set_state) {
@ -65,12 +65,12 @@ esp_err_t esp_ble_mesh_light_client_set_state(esp_ble_mesh_client_common_param_t
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_LIGHT_CLIENT;
msg.act = BTC_BLE_MESH_ACT_LIGHT_CLIENT_SET_STATE;
msg.pid = BTC_PID_LIGHTING_CLIENT;
msg.act = BTC_BLE_MESH_ACT_LIGHTING_CLIENT_SET_STATE;
arg.light_client_set_state.params = params;
arg.light_client_set_state.set_state = set_state;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_light_client_args_t), btc_ble_mesh_light_client_arg_deep_copy)
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_lighting_client_args_t), btc_ble_mesh_lighting_client_arg_deep_copy)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}

View File

@ -19,7 +19,6 @@
#ifndef _ESP_BLE_MESH_GENERIC_MODEL_API_H_
#define _ESP_BLE_MESH_GENERIC_MODEL_API_H_
#include "generic_client.h"
#include "esp_ble_mesh_defs.h"
/** @def ESP_BLE_MESH_MODEL_GEN_ONOFF_CLI

View File

@ -19,7 +19,6 @@
#ifndef _ESP_BLE_MESH_LIGHTING_MODEL_API_H_
#define _ESP_BLE_MESH_LIGHTING_MODEL_API_H_
#include "lighting_client.h"
#include "esp_ble_mesh_defs.h"
/** @def ESP_BLE_MESH_MODEL_LIGHT_LIGHTNESS_CLI
@ -108,164 +107,164 @@
/** Parameters of Light Lightness Set */
typedef struct {
bool op_en; /*!< Indicate if optional parameters are included */
u16_t lightness; /*!< Target value of light lightness actual state */
u8_t tid; /*!< Transaction ID */
u8_t trans_time; /*!< Time to complete state transition (optional) */
u8_t delay; /*!< Indicate message execution delay (C.1) */
bool op_en; /*!< Indicate if optional parameters are included */
uint16_t lightness; /*!< Target value of light lightness actual state */
uint8_t tid; /*!< Transaction ID */
uint8_t trans_time; /*!< Time to complete state transition (optional) */
uint8_t delay; /*!< Indicate message execution delay (C.1) */
} esp_ble_mesh_light_lightness_set_t;
/** Parameters of Light Lightness Linear Set */
typedef struct {
bool op_en; /*!< Indicate if optional parameters are included */
u16_t lightness; /*!< Target value of light lightness linear state */
u8_t tid; /*!< Transaction ID */
u8_t trans_time; /*!< Time to complete state transition (optional) */
u8_t delay; /*!< Indicate message execution delay (C.1) */
bool op_en; /*!< Indicate if optional parameters are included */
uint16_t lightness; /*!< Target value of light lightness linear state */
uint8_t tid; /*!< Transaction ID */
uint8_t trans_time; /*!< Time to complete state transition (optional) */
uint8_t delay; /*!< Indicate message execution delay (C.1) */
} esp_ble_mesh_light_lightness_linear_set_t;
/** Parameter of Light Lightness Default Set */
typedef struct {
u16_t lightness; /*!< The value of the Light Lightness Default state */
uint16_t lightness; /*!< The value of the Light Lightness Default state */
} esp_ble_mesh_light_lightness_default_set_t;
/** Parameters of Light Lightness Range Set */
typedef struct {
u16_t range_min; /*!< Value of range min field of light lightness range state */
u16_t range_max; /*!< Value of range max field of light lightness range state */
uint16_t range_min; /*!< Value of range min field of light lightness range state */
uint16_t range_max; /*!< Value of range max field of light lightness range state */
} esp_ble_mesh_light_lightness_range_set_t;
/** Parameters of Light CTL Set */
typedef struct {
bool op_en; /*!< Indicate if optional parameters are included */
u16_t ctl_lightness; /*!< Target value of light ctl lightness state */
u16_t ctl_temperatrue; /*!< Target value of light ctl temperature state */
s16_t ctl_delta_uv; /*!< Target value of light ctl delta UV state */
u8_t tid; /*!< Transaction ID */
u8_t trans_time; /*!< Time to complete state transition (optional) */
u8_t delay; /*!< Indicate message execution delay (C.1) */
bool op_en; /*!< Indicate if optional parameters are included */
uint16_t ctl_lightness; /*!< Target value of light ctl lightness state */
uint16_t ctl_temperatrue; /*!< Target value of light ctl temperature state */
int16_t ctl_delta_uv; /*!< Target value of light ctl delta UV state */
uint8_t tid; /*!< Transaction ID */
uint8_t trans_time; /*!< Time to complete state transition (optional) */
uint8_t delay; /*!< Indicate message execution delay (C.1) */
} esp_ble_mesh_light_ctl_set_t;
/** Parameters of Light CTL Temperature Set */
typedef struct {
bool op_en; /*!< Indicate if optional parameters are included */
u16_t ctl_temperatrue; /*!< Target value of light ctl temperature state */
s16_t ctl_delta_uv; /*!< Target value of light ctl delta UV state */
u8_t tid; /*!< Transaction ID */
u8_t trans_time; /*!< Time to complete state transition (optional) */
u8_t delay; /*!< Indicate message execution delay (C.1) */
bool op_en; /*!< Indicate if optional parameters are included */
uint16_t ctl_temperatrue; /*!< Target value of light ctl temperature state */
int16_t ctl_delta_uv; /*!< Target value of light ctl delta UV state */
uint8_t tid; /*!< Transaction ID */
uint8_t trans_time; /*!< Time to complete state transition (optional) */
uint8_t delay; /*!< Indicate message execution delay (C.1) */
} esp_ble_mesh_light_ctl_temperature_set_t;
/** Parameters of Light CTL Temperature Range Set */
typedef struct {
u16_t range_min; /*!< Value of temperature range min field of light ctl temperature range state */
u16_t range_max; /*!< Value of temperature range max field of light ctl temperature range state */
uint16_t range_min; /*!< Value of temperature range min field of light ctl temperature range state */
uint16_t range_max; /*!< Value of temperature range max field of light ctl temperature range state */
} esp_ble_mesh_light_ctl_temperature_range_set_t;
/** Parameters of Light CTL Default Set */
typedef struct {
u16_t lightness; /*!< Value of light lightness default state */
u16_t temperature; /*!< Value of light temperature default state */
s16_t delta_uv; /*!< Value of light delta UV default state */
uint16_t lightness; /*!< Value of light lightness default state */
uint16_t temperature; /*!< Value of light temperature default state */
int16_t delta_uv; /*!< Value of light delta UV default state */
} esp_ble_mesh_light_ctl_default_set_t;
/** Parameters of Light HSL Set */
typedef struct {
bool op_en; /*!< Indicate if optional parameters are included */
u16_t hsl_lightness; /*!< Target value of light hsl lightness state */
u16_t hsl_hue; /*!< Target value of light hsl hue state */
u16_t hsl_saturation; /*!< Target value of light hsl saturation state */
u8_t tid; /*!< Transaction ID */
u8_t trans_time; /*!< Time to complete state transition (optional) */
u8_t delay; /*!< Indicate message execution delay (C.1) */
bool op_en; /*!< Indicate if optional parameters are included */
uint16_t hsl_lightness; /*!< Target value of light hsl lightness state */
uint16_t hsl_hue; /*!< Target value of light hsl hue state */
uint16_t hsl_saturation; /*!< Target value of light hsl saturation state */
uint8_t tid; /*!< Transaction ID */
uint8_t trans_time; /*!< Time to complete state transition (optional) */
uint8_t delay; /*!< Indicate message execution delay (C.1) */
} esp_ble_mesh_light_hsl_set_t;
/** Parameters of Light HSL Hue Set */
typedef struct {
bool op_en; /*!< Indicate if optional parameters are included */
u16_t hue; /*!< Target value of light hsl hue state */
u8_t tid; /*!< Transaction ID */
u8_t trans_time; /*!< Time to complete state transition (optional) */
u8_t delay; /*!< Indicate message execution delay (C.1) */
bool op_en; /*!< Indicate if optional parameters are included */
uint16_t hue; /*!< Target value of light hsl hue state */
uint8_t tid; /*!< Transaction ID */
uint8_t trans_time; /*!< Time to complete state transition (optional) */
uint8_t delay; /*!< Indicate message execution delay (C.1) */
} esp_ble_mesh_light_hsl_hue_set_t;
/** Parameters of Light HSL Saturation Set */
typedef struct {
bool op_en; /*!< Indicate if optional parameters are included */
u16_t saturation; /*!< Target value of light hsl hue state */
u8_t tid; /*!< Transaction ID */
u8_t trans_time; /*!< Time to complete state transition (optional) */
u8_t delay; /*!< Indicate message execution delay (C.1) */
bool op_en; /*!< Indicate if optional parameters are included */
uint16_t saturation; /*!< Target value of light hsl hue state */
uint8_t tid; /*!< Transaction ID */
uint8_t trans_time; /*!< Time to complete state transition (optional) */
uint8_t delay; /*!< Indicate message execution delay (C.1) */
} esp_ble_mesh_light_hsl_saturation_set_t;
/** Parameters of Light HSL Default Set */
typedef struct {
u16_t lightness; /*!< Value of light lightness default state */
u16_t hue; /*!< Value of light hue default state */
u16_t saturation; /*!< Value of light saturation default state */
uint16_t lightness; /*!< Value of light lightness default state */
uint16_t hue; /*!< Value of light hue default state */
uint16_t saturation; /*!< Value of light saturation default state */
} esp_ble_mesh_light_hsl_default_set_t;
/** Parameters of Light HSL Range Set */
typedef struct {
u16_t hue_range_min; /*!< Value of hue range min field of light hsl hue range state */
u16_t hue_range_max; /*!< Value of hue range max field of light hsl hue range state */
u16_t saturation_range_min; /*!< Value of saturation range min field of light hsl saturation range state */
u16_t saturation_range_max; /*!< Value of saturation range max field of light hsl saturation range state */
uint16_t hue_range_min; /*!< Value of hue range min field of light hsl hue range state */
uint16_t hue_range_max; /*!< Value of hue range max field of light hsl hue range state */
uint16_t saturation_range_min; /*!< Value of saturation range min field of light hsl saturation range state */
uint16_t saturation_range_max; /*!< Value of saturation range max field of light hsl saturation range state */
} esp_ble_mesh_light_hsl_range_set_t;
/** Parameters of Light xyL Set */
typedef struct {
bool op_en; /*!< Indicate whether optional parameters included */
u16_t xyl_lightness; /*!< The target value of the Light xyL Lightness state */
u16_t xyl_x; /*!< The target value of the Light xyL x state */
u16_t xyl_y; /*!< The target value of the Light xyL y state */
u8_t tid; /*!< Transaction Identifier */
u8_t trans_time; /*!< Time to complete state transition (optional) */
u8_t delay; /*!< Indicate message execution delay (C.1) */
bool op_en; /*!< Indicate whether optional parameters included */
uint16_t xyl_lightness; /*!< The target value of the Light xyL Lightness state */
uint16_t xyl_x; /*!< The target value of the Light xyL x state */
uint16_t xyl_y; /*!< The target value of the Light xyL y state */
uint8_t tid; /*!< Transaction Identifier */
uint8_t trans_time; /*!< Time to complete state transition (optional) */
uint8_t delay; /*!< Indicate message execution delay (C.1) */
} esp_ble_mesh_light_xyl_set_t;
/** Parameters of Light xyL Default Set */
typedef struct {
u16_t lightness; /*!< The value of the Light Lightness Default state */
u16_t xyl_x; /*!< The value of the Light xyL x Default state */
u16_t xyl_y; /*!< The value of the Light xyL y Default state */
uint16_t lightness; /*!< The value of the Light Lightness Default state */
uint16_t xyl_x; /*!< The value of the Light xyL x Default state */
uint16_t xyl_y; /*!< The value of the Light xyL y Default state */
} esp_ble_mesh_light_xyl_default_set_t;
/** Parameters of Light xyL Range Set */
typedef struct {
u16_t xyl_x_range_min; /*!< The value of the xyL x Range Min field of the Light xyL x Range state */
u16_t xyl_x_range_max; /*!< The value of the xyL x Range Max field of the Light xyL x Range state */
u16_t xyl_y_range_min; /*!< The value of the xyL y Range Min field of the Light xyL y Range state */
u16_t xyl_y_range_max; /*!< The value of the xyL y Range Max field of the Light xyL y Range state */
uint16_t xyl_x_range_min; /*!< The value of the xyL x Range Min field of the Light xyL x Range state */
uint16_t xyl_x_range_max; /*!< The value of the xyL x Range Max field of the Light xyL x Range state */
uint16_t xyl_y_range_min; /*!< The value of the xyL y Range Min field of the Light xyL y Range state */
uint16_t xyl_y_range_max; /*!< The value of the xyL y Range Max field of the Light xyL y Range state */
} esp_ble_mesh_light_xyl_range_set_t;
/** Parameter of Light LC Mode Set */
typedef struct {
u8_t mode; /*!< The target value of the Light LC Mode state */
uint8_t mode; /*!< The target value of the Light LC Mode state */
} esp_ble_mesh_light_lc_mode_set_t;
/** Parameter of Light LC OM Set */
typedef struct {
u8_t mode; /*!< The target value of the Light LC Occupancy Mode state */
uint8_t mode; /*!< The target value of the Light LC Occupancy Mode state */
} esp_ble_mesh_light_lc_om_set_t;
/** Parameters of Light LC Light OnOff Set */
typedef struct {
bool op_en; /*!< Indicate whether optional parameters included */
u8_t light_onoff; /*!< The target value of the Light LC Light OnOff state */
u8_t tid; /*!< Transaction Identifier */
u8_t trans_time; /*!< Time to complete state transition (optional) */
u8_t delay; /*!< Indicate message execution delay (C.1) */
bool op_en; /*!< Indicate whether optional parameters included */
uint8_t light_onoff; /*!< The target value of the Light LC Light OnOff state */
uint8_t tid; /*!< Transaction Identifier */
uint8_t trans_time; /*!< Time to complete state transition (optional) */
uint8_t delay; /*!< Indicate message execution delay (C.1) */
} esp_ble_mesh_light_lc_light_onoff_set_t;
/** Parameter of Light LC Property Get */
typedef struct {
u16_t property_id; /*!< Property ID identifying a Light LC Property */
uint16_t property_id; /*!< Property ID identifying a Light LC Property */
} esp_ble_mesh_light_lc_property_get_t;
/** Parameters of Light LC Property Set */
typedef struct {
u16_t property_id; /*!< Property ID identifying a Light LC Property */
uint16_t property_id; /*!< Property ID identifying a Light LC Property */
struct net_buf_simple *property_value; /*!< Raw value for the Light LC Property */
} esp_ble_mesh_light_lc_property_set_t;
@ -308,176 +307,176 @@ typedef union {
/** Parameters of Light Lightness Status */
typedef struct {
bool op_en; /*!< Indicate if optional parameters are included */
u16_t present_lightness; /*!< Current value of light lightness actual state */
u16_t target_lightness; /*!< Target value of light lightness actual state (optional) */
u8_t remain_time; /*!< Time to complete state transition (C.1) */
bool op_en; /*!< Indicate if optional parameters are included */
uint16_t present_lightness; /*!< Current value of light lightness actual state */
uint16_t target_lightness; /*!< Target value of light lightness actual state (optional) */
uint8_t remain_time; /*!< Time to complete state transition (C.1) */
} esp_ble_mesh_light_lightness_status_cb_t;
/** Parameters of Light Lightness Linear Status */
typedef struct {
bool op_en; /*!< Indicate if optional parameters are included */
u16_t present_lightness; /*!< Current value of light lightness linear state */
u16_t target_lightness; /*!< Target value of light lightness linear state (optional) */
u8_t remain_time; /*!< Time to complete state transition (C.1) */
bool op_en; /*!< Indicate if optional parameters are included */
uint16_t present_lightness; /*!< Current value of light lightness linear state */
uint16_t target_lightness; /*!< Target value of light lightness linear state (optional) */
uint8_t remain_time; /*!< Time to complete state transition (C.1) */
} esp_ble_mesh_light_lightness_linear_status_cb_t;
/** Parameter of Light Lightness Last Status */
typedef struct {
u16_t lightness; /*!< The value of the Light Lightness Last state */
uint16_t lightness; /*!< The value of the Light Lightness Last state */
} esp_ble_mesh_light_lightness_last_status_cb_t;
/** Parameter of Light Lightness Default Status */
typedef struct {
u16_t lightness; /*!< The value of the Light Lightness default State */
uint16_t lightness; /*!< The value of the Light Lightness default State */
} esp_ble_mesh_light_lightness_default_status_cb_t;
/** Parameters of Light Lightness Range Status */
typedef struct {
u8_t status_code; /*!< Status Code for the request message */
u16_t range_min; /*!< Value of range min field of light lightness range state */
u16_t range_max; /*!< Value of range max field of light lightness range state */
uint8_t status_code; /*!< Status Code for the request message */
uint16_t range_min; /*!< Value of range min field of light lightness range state */
uint16_t range_max; /*!< Value of range max field of light lightness range state */
} esp_ble_mesh_light_lightness_range_status_cb_t;
/** Parameters of Light CTL Status */
typedef struct {
bool op_en; /*!< Indicate if optional parameters are included */
u16_t present_ctl_lightness; /*!< Current value of light ctl lightness state */
u16_t present_ctl_temperature; /*!< Current value of light ctl temperature state */
u16_t target_ctl_lightness; /*!< Target value of light ctl lightness state (optional) */
u16_t target_ctl_temperature; /*!< Target value of light ctl temperature state (C.1) */
u8_t remain_time; /*!< Time to complete state transition (C.1) */
bool op_en; /*!< Indicate if optional parameters are included */
uint16_t present_ctl_lightness; /*!< Current value of light ctl lightness state */
uint16_t present_ctl_temperature; /*!< Current value of light ctl temperature state */
uint16_t target_ctl_lightness; /*!< Target value of light ctl lightness state (optional) */
uint16_t target_ctl_temperature; /*!< Target value of light ctl temperature state (C.1) */
uint8_t remain_time; /*!< Time to complete state transition (C.1) */
} esp_ble_mesh_light_ctl_status_cb_t;
/** Parameters of Light CTL Temperature Status */
typedef struct {
bool op_en; /*!< Indicate if optional parameters are included */
u16_t present_ctl_temperature; /*!< Current value of light ctl temperature state */
u16_t present_ctl_delta_uv; /*!< Current value of light ctl delta UV state */
u16_t target_ctl_temperature; /*!< Target value of light ctl temperature state (optional) */
u16_t target_ctl_delta_uv; /*!< Target value of light ctl delta UV state (C.1) */
u8_t remain_time; /*!< Time to complete state transition (C.1) */
bool op_en; /*!< Indicate if optional parameters are included */
uint16_t present_ctl_temperature; /*!< Current value of light ctl temperature state */
uint16_t present_ctl_delta_uv; /*!< Current value of light ctl delta UV state */
uint16_t target_ctl_temperature; /*!< Target value of light ctl temperature state (optional) */
uint16_t target_ctl_delta_uv; /*!< Target value of light ctl delta UV state (C.1) */
uint8_t remain_time; /*!< Time to complete state transition (C.1) */
} esp_ble_mesh_light_ctl_temperature_status_cb_t;
/** Parameters of Light CTL Temperature Range Status */
typedef struct {
u8_t status_code; /*!< Status code for the request message */
u16_t range_min; /*!< Value of temperature range min field of light ctl temperature range state */
u16_t range_max; /*!< Value of temperature range max field of light ctl temperature range state */
uint8_t status_code; /*!< Status code for the request message */
uint16_t range_min; /*!< Value of temperature range min field of light ctl temperature range state */
uint16_t range_max; /*!< Value of temperature range max field of light ctl temperature range state */
} esp_ble_mesh_light_ctl_temperature_range_status_cb_t;
/** Parameters of Light CTL Default Status */
typedef struct {
u16_t lightness; /*!< Value of light lightness default state */
u16_t temperature; /*!< Value of light temperature default state */
s16_t delta_uv; /*!< Value of light delta UV default state */
uint16_t lightness; /*!< Value of light lightness default state */
uint16_t temperature; /*!< Value of light temperature default state */
int16_t delta_uv; /*!< Value of light delta UV default state */
} esp_ble_mesh_light_ctl_default_status_cb_t;
/** Parameters of Light HSL Status */
typedef struct {
bool op_en; /*!< Indicate if optional parameters are included */
u16_t hsl_lightness; /*!< Current value of light hsl lightness state */
u16_t hsl_hue; /*!< Current value of light hsl hue state */
u16_t hsl_saturation; /*!< Current value of light hsl saturation state */
u8_t remain_time; /*!< Time to complete state transition (optional) */
bool op_en; /*!< Indicate if optional parameters are included */
uint16_t hsl_lightness; /*!< Current value of light hsl lightness state */
uint16_t hsl_hue; /*!< Current value of light hsl hue state */
uint16_t hsl_saturation; /*!< Current value of light hsl saturation state */
uint8_t remain_time; /*!< Time to complete state transition (optional) */
} esp_ble_mesh_light_hsl_status_cb_t;
/** Parameters of Light HSL Target Status */
typedef struct {
bool op_en; /*!< Indicate if optional parameters are included */
u16_t hsl_lightness_target; /*!< Target value of light hsl lightness state */
u16_t hsl_hue_target; /*!< Target value of light hsl hue state */
u16_t hsl_saturation_target; /*!< Target value of light hsl saturation state */
u8_t remain_time; /*!< Time to complete state transition (optional) */
uint16_t hsl_lightness_target; /*!< Target value of light hsl lightness state */
uint16_t hsl_hue_target; /*!< Target value of light hsl hue state */
uint16_t hsl_saturation_target; /*!< Target value of light hsl saturation state */
uint8_t remain_time; /*!< Time to complete state transition (optional) */
} esp_ble_mesh_light_hsl_target_status_cb_t;
/** Parameters of Light HSL Hue Status */
typedef struct {
bool op_en; /*!< Indicate if optional parameters are included */
u16_t present_hue; /*!< Current value of light hsl hue state */
u16_t target_hue; /*!< Target value of light hsl hue state (optional) */
u8_t remain_time; /*!< Time to complete state transition (C.1) */
bool op_en; /*!< Indicate if optional parameters are included */
uint16_t present_hue; /*!< Current value of light hsl hue state */
uint16_t target_hue; /*!< Target value of light hsl hue state (optional) */
uint8_t remain_time; /*!< Time to complete state transition (C.1) */
} esp_ble_mesh_light_hsl_hue_status_cb_t;
/** Parameters of Light HSL Saturation Status */
typedef struct {
bool op_en; /*!< Indicate if optional parameters are included */
u16_t present_saturation; /*!< Current value of light hsl saturation state */
u16_t target_saturation; /*!< Target value of light hsl saturation state (optional) */
u8_t remain_time; /*!< Time to complete state transition (C.1) */
bool op_en; /*!< Indicate if optional parameters are included */
uint16_t present_saturation; /*!< Current value of light hsl saturation state */
uint16_t target_saturation; /*!< Target value of light hsl saturation state (optional) */
uint8_t remain_time; /*!< Time to complete state transition (C.1) */
} esp_ble_mesh_light_hsl_saturation_status_cb_t;
/** Parameters of Light HSL Default Status */
typedef struct {
u16_t lightness; /*!< Value of light lightness default state */
u16_t hue; /*!< Value of light hue default state */
u16_t saturation; /*!< Value of light saturation default state */
uint16_t lightness; /*!< Value of light lightness default state */
uint16_t hue; /*!< Value of light hue default state */
uint16_t saturation; /*!< Value of light saturation default state */
} esp_ble_mesh_light_hsl_default_status_cb_t;
/** Parameters of Light HSL Range Status */
typedef struct {
u8_t status_code; /*!< Status code for the request message */
u16_t hue_range_min; /*!< Value of hue range min field of light hsl hue range state */
u16_t hue_range_max; /*!< Value of hue range max field of light hsl hue range state */
u16_t saturation_range_min; /*!< Value of saturation range min field of light hsl saturation range state */
u16_t saturation_range_max; /*!< Value of saturation range max field of light hsl saturation range state */
uint8_t status_code; /*!< Status code for the request message */
uint16_t hue_range_min; /*!< Value of hue range min field of light hsl hue range state */
uint16_t hue_range_max; /*!< Value of hue range max field of light hsl hue range state */
uint16_t saturation_range_min; /*!< Value of saturation range min field of light hsl saturation range state */
uint16_t saturation_range_max; /*!< Value of saturation range max field of light hsl saturation range state */
} esp_ble_mesh_light_hsl_range_status_cb_t;
/** Parameters of Light xyL Status */
typedef struct {
bool op_en; /*!< Indicate whether optional parameters included */
u16_t xyl_lightness; /*!< The present value of the Light xyL Lightness state */
u16_t xyl_x; /*!< The present value of the Light xyL x state */
u16_t xyl_y; /*!< The present value of the Light xyL y state */
u8_t remain_time; /*!< Time to complete state transition (optional) */
bool op_en; /*!< Indicate whether optional parameters included */
uint16_t xyl_lightness; /*!< The present value of the Light xyL Lightness state */
uint16_t xyl_x; /*!< The present value of the Light xyL x state */
uint16_t xyl_y; /*!< The present value of the Light xyL y state */
uint8_t remain_time; /*!< Time to complete state transition (optional) */
} esp_ble_mesh_light_xyl_status_cb_t;
/** Parameters of Light xyL Target Status */
typedef struct {
bool op_en; /*!< Indicate whether optional parameters included */
u16_t target_xyl_lightness; /*!< The target value of the Light xyL Lightness state */
u16_t target_xyl_x; /*!< The target value of the Light xyL x state */
u16_t target_xyl_y; /*!< The target value of the Light xyL y state */
u8_t remain_time; /*!< Time to complete state transition (optional) */
bool op_en; /*!< Indicate whether optional parameters included */
uint16_t target_xyl_lightness; /*!< The target value of the Light xyL Lightness state */
uint16_t target_xyl_x; /*!< The target value of the Light xyL x state */
uint16_t target_xyl_y; /*!< The target value of the Light xyL y state */
uint8_t remain_time; /*!< Time to complete state transition (optional) */
} esp_ble_mesh_light_xyl_target_status_cb_t;
/** Parameters of Light xyL Default Status */
typedef struct {
u16_t lightness; /*!< The value of the Light Lightness Default state */
u16_t xyl_x; /*!< The value of the Light xyL x Default state */
u16_t xyl_y; /*!< The value of the Light xyL y Default state */
uint16_t lightness; /*!< The value of the Light Lightness Default state */
uint16_t xyl_x; /*!< The value of the Light xyL x Default state */
uint16_t xyl_y; /*!< The value of the Light xyL y Default state */
} esp_ble_mesh_light_xyl_default_status_cb_t;
/** Parameters of Light xyL Range Status */
typedef struct {
u8_t status_code; /*!< Status Code for the requesting message */
u16_t xyl_x_range_min; /*!< The value of the xyL x Range Min field of the Light xyL x Range state */
u16_t xyl_x_range_max; /*!< The value of the xyL x Range Max field of the Light xyL x Range state */
u16_t xyl_y_range_min; /*!< The value of the xyL y Range Min field of the Light xyL y Range state */
u16_t xyl_y_range_max; /*!< The value of the xyL y Range Max field of the Light xyL y Range state */
uint8_t status_code; /*!< Status Code for the requesting message */
uint16_t xyl_x_range_min; /*!< The value of the xyL x Range Min field of the Light xyL x Range state */
uint16_t xyl_x_range_max; /*!< The value of the xyL x Range Max field of the Light xyL x Range state */
uint16_t xyl_y_range_min; /*!< The value of the xyL y Range Min field of the Light xyL y Range state */
uint16_t xyl_y_range_max; /*!< The value of the xyL y Range Max field of the Light xyL y Range state */
} esp_ble_mesh_light_xyl_range_status_cb_t;
/** Parameter of Light LC Mode Status */
typedef struct {
u8_t mode; /*!< The present value of the Light LC Mode state */
uint8_t mode; /*!< The present value of the Light LC Mode state */
} esp_ble_mesh_light_lc_mode_status_cb_t;
/** Parameter of Light LC OM Status */
typedef struct {
u8_t mode; /*!< The present value of the Light LC Occupancy Mode state */
uint8_t mode; /*!< The present value of the Light LC Occupancy Mode state */
} esp_ble_mesh_light_lc_om_status_cb_t;
/** Parameters of Light LC Light OnOff Status */
typedef struct {
bool op_en; /*!< Indicate whether optional parameters included */
u8_t present_light_onoff; /*!< The present value of the Light LC Light OnOff state */
u8_t target_light_onoff; /*!< The target value of the Light LC Light OnOff state (Optional) */
u8_t remain_time; /*!< Time to complete state transition (C.1) */
bool op_en; /*!< Indicate whether optional parameters included */
uint8_t present_light_onoff; /*!< The present value of the Light LC Light OnOff state */
uint8_t target_light_onoff; /*!< The target value of the Light LC Light OnOff state (Optional) */
uint8_t remain_time; /*!< Time to complete state transition (C.1) */
} esp_ble_mesh_light_lc_light_onoff_status_cb_t;
/** Parameters of Light LC Property Status */
typedef struct {
u16_t property_id; /*!< Property ID identifying a Light LC Property */
uint16_t property_id; /*!< Property ID identifying a Light LC Property */
struct net_buf_simple *property_value; /*!< Raw value for the Light LC Property */
} esp_ble_mesh_light_lc_property_status_cb_t;
@ -571,7 +570,7 @@ esp_err_t esp_ble_mesh_light_client_get_state(esp_ble_mesh_client_common_param_t
* please refer to esp_ble_mesh_light_message_opcode_t in esp_ble_mesh_defs.h
*
* @param[in] params: Pointer to BLE Mesh common client parameters.
* @param[in] set_state: Pointer of generic set message value.
* @param[in] set_state: Pointer of light set message value.
* Shall not be set to NULL.
*
* @return ESP_OK on success or error code otherwise.

View File

@ -19,7 +19,6 @@
#ifndef _ESP_BLE_MESH_SENSOR_MODEL_API_H_
#define _ESP_BLE_MESH_SENSOR_MODEL_API_H_
#include "sensor_client.h"
#include "esp_ble_mesh_defs.h"
/** @def ESP_BLE_MESH_MODEL_SENSOR_CLI
@ -45,60 +44,60 @@
/** Parameters of Sensor Descriptor Get */
typedef struct {
bool op_en; /*!< Indicate if optional parameters are included */
u16_t property_id; /*!< Property ID of a sensor (optional) */
uint16_t property_id; /*!< Property ID of a sensor (optional) */
} esp_ble_mesh_sensor_descriptor_get_t;
/** Parameter of Sensor Cadence Get */
typedef struct {
u16_t property_id; /*!< Property ID of a sensor */
uint16_t property_id; /*!< Property ID of a sensor */
} esp_ble_mesh_sensor_cadence_get_t;
/** Parameters of Sensor Cadence Set */
typedef struct {
u16_t property_id; /*!< Property ID for the sensor */
u8_t fast_cadence_period_divisor : 7, /*!< Divisor for the publish period */
status_trigger_type : 1; /*!< The unit and format of the Status Trigger Delta fields */
uint16_t property_id; /*!< Property ID for the sensor */
uint8_t fast_cadence_period_divisor : 7, /*!< Divisor for the publish period */
status_trigger_type : 1; /*!< The unit and format of the Status Trigger Delta fields */
struct net_buf_simple *status_trigger_delta_down; /*!< Delta down value that triggers a status message */
struct net_buf_simple *status_trigger_delta_up; /*!< Delta up value that triggers a status message */
u8_t status_min_interval; /*!< Minimum interval between two consecutive Status messages */
uint8_t status_min_interval; /*!< Minimum interval between two consecutive Status messages */
struct net_buf_simple *fast_cadence_low; /*!< Low value for the fast cadence range */
struct net_buf_simple *fast_cadence_high; /*!< Fast value for the fast cadence range */
} esp_ble_mesh_sensor_cadence_set_t;
/** Parameter of Sensor Settings Get */
typedef struct {
u16_t sensor_property_id; /*!< Property ID of a sensor */
uint16_t sensor_property_id; /*!< Property ID of a sensor */
} esp_ble_mesh_sensor_settings_get_t;
/** Parameters of Sensor Setting Get */
typedef struct {
u16_t sensor_property_id; /*!< Property ID of a sensor */
u16_t sensor_setting_property_id; /*!< Setting ID identifying a setting within a sensor */
uint16_t sensor_property_id; /*!< Property ID of a sensor */
uint16_t sensor_setting_property_id; /*!< Setting ID identifying a setting within a sensor */
} esp_ble_mesh_sensor_setting_get_t;
/** Parameters of Sensor Setting Set */
typedef struct {
u16_t sensor_property_id; /*!< Property ID identifying a sensor */
u16_t sensor_setting_property_id; /*!< Setting ID identifying a setting within a sensor */
uint16_t sensor_property_id; /*!< Property ID identifying a sensor */
uint16_t sensor_setting_property_id; /*!< Setting ID identifying a setting within a sensor */
struct net_buf_simple *sensor_setting_raw; /*!< Raw value for the setting */
} esp_ble_mesh_sensor_setting_set_t;
/** Parameters of Sensor Get */
typedef struct {
bool op_en; /*!< Indicate if optional parameters are included */
u16_t property_id; /*!< Property ID for the sensor (optional) */
bool op_en; /*!< Indicate if optional parameters are included */
uint16_t property_id; /*!< Property ID for the sensor (optional) */
} esp_ble_mesh_sensor_get_t;
/** Parameters of Sensor Column Get */
typedef struct {
u16_t property_id; /*!< Property identifying a sensor */
uint16_t property_id; /*!< Property identifying a sensor */
struct net_buf_simple *raw_value_x; /*!< Raw value identifying a column */
} esp_ble_mesh_sensor_column_get_t;
/** Parameters of Sensor Series Get */
typedef struct {
bool op_en; /*!< Indicate if optional parameters are included */
u16_t property_id; /*!< Property identifying a sensor */
bool op_en; /*!< Indicate if optional parameters are included */
uint16_t property_id; /*!< Property identifying a sensor */
struct net_buf_simple *raw_value_x1; /*!< Raw value identifying a starting column (optional) */
struct net_buf_simple *raw_value_x2; /*!< Raw value identifying an ending column (C.1) */
} esp_ble_mesh_sensor_series_get_t;
@ -135,22 +134,22 @@ typedef struct {
/** Parameters of Sensor Cadence Status */
typedef struct {
u16_t property_id; /*!< Property for the sensor */
uint16_t property_id; /*!< Property for the sensor */
struct net_buf_simple *sensor_cadence_value; /*!< Value of sensor cadence state */
} esp_ble_mesh_sensor_cadence_status_cb_t;
/** Parameters of Sensor Settings Status */
typedef struct {
u16_t sensor_property_id; /*!< Property ID identifying a sensor */
uint16_t sensor_property_id; /*!< Property ID identifying a sensor */
struct net_buf_simple *sensor_setting_property_ids; /*!< A sequence of N sensor setting property IDs (optional) */
} esp_ble_mesh_sensor_settings_status_cb_t;
/** Parameters of Sensor Setting Status */
typedef struct {
bool op_en; /*!< Indicate id optional parameters are included */
u16_t sensor_property_id; /*!< Property ID identifying a sensor */
u16_t sensor_setting_property_id; /*!< Setting ID identifying a setting within a sensor */
u8_t sensor_setting_access; /*!< Read/Write access rights for the setting (optional) */
bool op_en; /*!< Indicate id optional parameters are included */
uint16_t sensor_property_id; /*!< Property ID identifying a sensor */
uint16_t sensor_setting_property_id; /*!< Setting ID identifying a setting within a sensor */
uint8_t sensor_setting_access; /*!< Read/Write access rights for the setting (optional) */
struct net_buf_simple *sensor_setting_raw; /*!< Raw value for the setting */
} esp_ble_mesh_sensor_setting_status_cb_t;
@ -161,13 +160,13 @@ typedef struct {
/** Parameters of Sensor Column Status */
typedef struct {
u16_t property_id; /*!< Property identifying a sensor and the Y axis */
uint16_t property_id; /*!< Property identifying a sensor and the Y axis */
struct net_buf_simple *sensor_column_value; /*!< Left values of sensor column status */
} esp_ble_mesh_sensor_column_status_cb_t;
/** Parameters of Sensor Series Status */
typedef struct {
u16_t property_id; /*!< Property identifying a sensor and the Y axis */
uint16_t property_id; /*!< Property identifying a sensor and the Y axis */
struct net_buf_simple *sensor_series_value; /*!< Left values of sensor series status */
} esp_ble_mesh_sensor_series_status_cb_t;

View File

@ -19,7 +19,6 @@
#ifndef _ESP_BLE_MESH_TIME_SCENE_MODEL_API_H_
#define _ESP_BLE_MESH_TIME_SCENE_MODEL_API_H_
#include "time_scene_client.h"
#include "esp_ble_mesh_defs.h"
/** @def ESP_BLE_MESH_MODEL_TIME_CLI
@ -76,69 +75,69 @@
/** Parameters of Time Set */
typedef struct {
u8_t tai_seconds[5]; /*!< The current TAI time in seconds */
u8_t sub_second; /*!< The sub-second time in units of 1/256 second */
u8_t uncertainty; /*!< The estimated uncertainty in 10-millisecond steps */
u16_t time_authority : 1; /*!< 0 = No Time Authority, 1 = Time Authority */
u16_t tai_utc_delta : 15; /*!< Current difference between TAI and UTC in seconds */
u8_t time_zone_offset; /*!< The local time zone offset in 15-minute increments */
uint8_t tai_seconds[5]; /*!< The current TAI time in seconds */
uint8_t sub_second; /*!< The sub-second time in units of 1/256 second */
uint8_t uncertainty; /*!< The estimated uncertainty in 10-millisecond steps */
uint16_t time_authority : 1; /*!< 0 = No Time Authority, 1 = Time Authority */
uint16_t tai_utc_delta : 15; /*!< Current difference between TAI and UTC in seconds */
uint8_t time_zone_offset; /*!< The local time zone offset in 15-minute increments */
} esp_ble_mesh_time_set_t;
/** Parameters of Time Zone Set */
typedef struct {
u8_t time_zone_offset_new; /*!< Upcoming local time zone offset */
u8_t tai_zone_change[5]; /*!< TAI Seconds time of the upcoming Time Zone Offset change */
uint8_t time_zone_offset_new; /*!< Upcoming local time zone offset */
uint8_t tai_zone_change[5]; /*!< TAI Seconds time of the upcoming Time Zone Offset change */
} esp_ble_mesh_time_zone_set_t;
/** Parameters of TAI-UTC Delta Set */
typedef struct {
u16_t tai_utc_delta_new : 15; /*!< Upcoming difference between TAI and UTC in seconds */
u16_t padding : 1; /*!< Always 0b0. Other values are Prohibited. */
u8_t tai_delta_change[5]; /*!< TAI Seconds time of the upcoming TAI-UTC Delta change */
uint16_t tai_utc_delta_new : 15; /*!< Upcoming difference between TAI and UTC in seconds */
uint16_t padding : 1; /*!< Always 0b0. Other values are Prohibited. */
uint8_t tai_delta_change[5]; /*!< TAI Seconds time of the upcoming TAI-UTC Delta change */
} esp_ble_mesh_tai_utc_delta_set_t;
/** Parameter of Time Role Set */
typedef struct {
u8_t time_role; /*!< The Time Role for the element */
uint8_t time_role; /*!< The Time Role for the element */
} esp_ble_mesh_time_role_set_t;
/** Parameter of Scene Store */
typedef struct {
u16_t scene_number; /*!< The number of scenes to be stored */
uint16_t scene_number; /*!< The number of scenes to be stored */
} esp_ble_mesh_scene_store_t;
/** Parameters of Scene Recall */
typedef struct {
bool op_en; /*!< Indicate if optional parameters are included */
u16_t scene_number; /*!< The number of scenes to be recalled */
u8_t tid; /*!< Transaction ID */
u8_t trans_time; /*!< Time to complete state transition (optional) */
u8_t delay; /*!< Indicate message execution delay (C.1) */
bool op_en; /*!< Indicate if optional parameters are included */
uint16_t scene_number; /*!< The number of scenes to be recalled */
uint8_t tid; /*!< Transaction ID */
uint8_t trans_time; /*!< Time to complete state transition (optional) */
uint8_t delay; /*!< Indicate message execution delay (C.1) */
} esp_ble_mesh_scene_recall_t;
/** Parameter of Scene Delete */
typedef struct {
u16_t scene_number; /*!< The number of scenes to be deleted */
uint16_t scene_number; /*!< The number of scenes to be deleted */
} esp_ble_mesh_scene_delete_t;
/** Parameter of Scheduler Action Get */
typedef struct {
u8_t index; /*!< Index of the Schedule Register entry to get */
uint8_t index; /*!< Index of the Schedule Register entry to get */
} esp_ble_mesh_scheduler_act_get_t;
/** Parameters of Scheduler Action Set */
typedef struct {
u64_t index : 4; /*!< Index of the Schedule Register entry to set */
u64_t year : 7; /*!< Scheduled year for the action */
u64_t month : 12; /*!< Scheduled month for the action */
u64_t day : 5; /*!< Scheduled day of the month for the action */
u64_t hour : 5; /*!< Scheduled hour for the action */
u64_t minute : 6; /*!< Scheduled minute for the action */
u64_t second : 6; /*!< Scheduled second for the action */
u64_t day_of_week : 7; /*!< Schedule days of the week for the action */
u64_t action : 4; /*!< Action to be performed at the scheduled time */
u64_t trans_time : 8; /*!< Transition time for this action */
u16_t scene_number; /*!< Transition time for this action */
uint64_t index : 4; /*!< Index of the Schedule Register entry to set */
uint64_t year : 7; /*!< Scheduled year for the action */
uint64_t month : 12; /*!< Scheduled month for the action */
uint64_t day : 5; /*!< Scheduled day of the month for the action */
uint64_t hour : 5; /*!< Scheduled hour for the action */
uint64_t minute : 6; /*!< Scheduled minute for the action */
uint64_t second : 6; /*!< Scheduled second for the action */
uint64_t day_of_week : 7; /*!< Schedule days of the week for the action */
uint64_t action : 4; /*!< Action to be performed at the scheduled time */
uint64_t trans_time : 8; /*!< Transition time for this action */
uint16_t scene_number; /*!< Transition time for this action */
} esp_ble_mesh_scheduler_act_set_t;
/**
@ -168,69 +167,69 @@ typedef union {
/** Parameters of Time Status */
typedef struct {
u8_t tai_seconds[5]; /*!< The current TAI time in seconds */
u8_t sub_second; /*!< The sub-second time in units of 1/256 second */
u8_t uncertainty; /*!< The estimated uncertainty in 10-millisecond steps */
u16_t time_authority : 1; /*!< 0 = No Time Authority, 1 = Time Authority */
u16_t tai_utc_delta : 15; /*!< Current difference between TAI and UTC in seconds */
u8_t time_zone_offset; /*!< The local time zone offset in 15-minute increments */
uint8_t tai_seconds[5]; /*!< The current TAI time in seconds */
uint8_t sub_second; /*!< The sub-second time in units of 1/256 second */
uint8_t uncertainty; /*!< The estimated uncertainty in 10-millisecond steps */
uint16_t time_authority : 1; /*!< 0 = No Time Authority, 1 = Time Authority */
uint16_t tai_utc_delta : 15; /*!< Current difference between TAI and UTC in seconds */
uint8_t time_zone_offset; /*!< The local time zone offset in 15-minute increments */
} esp_ble_mesh_time_status_cb_t;
/** Parameters of Time Zone Status */
typedef struct {
u8_t time_zone_offset_curr; /*!< Current local time zone offset */
u8_t time_zone_offset_new; /*!< Upcoming local time zone offset */
u8_t tai_zone_change[5]; /*!< TAI Seconds time of the upcoming Time Zone Offset change */
uint8_t time_zone_offset_curr; /*!< Current local time zone offset */
uint8_t time_zone_offset_new; /*!< Upcoming local time zone offset */
uint8_t tai_zone_change[5]; /*!< TAI Seconds time of the upcoming Time Zone Offset change */
} esp_ble_mesh_time_zone_status_cb_t;
/** Parameters of TAI-UTC Delta Status */
typedef struct {
u16_t tai_utc_delta_curr : 15; /*!< Current difference between TAI and UTC in seconds */
u16_t padding_1 : 1; /*!< Always 0b0. Other values are Prohibited. */
u16_t tai_utc_delta_new : 15; /*!< Upcoming difference between TAI and UTC in seconds */
u16_t padding_2 : 1; /*!< Always 0b0. Other values are Prohibited. */
u8_t tai_delta_change[5]; /*!< TAI Seconds time of the upcoming TAI-UTC Delta change */
uint16_t tai_utc_delta_curr : 15; /*!< Current difference between TAI and UTC in seconds */
uint16_t padding_1 : 1; /*!< Always 0b0. Other values are Prohibited. */
uint16_t tai_utc_delta_new : 15; /*!< Upcoming difference between TAI and UTC in seconds */
uint16_t padding_2 : 1; /*!< Always 0b0. Other values are Prohibited. */
uint8_t tai_delta_change[5]; /*!< TAI Seconds time of the upcoming TAI-UTC Delta change */
} esp_ble_mesh_tai_utc_delta_status_cb_t;
/** Parameter of Time Role Status */
typedef struct {
u8_t time_role; /*!< The Time Role for the element */
uint8_t time_role; /*!< The Time Role for the element */
} esp_ble_mesh_time_role_status_cb_t;
/** Parameters of Scene Status */
typedef struct {
bool op_en; /*!< Indicate if optional parameters are included */
u8_t status_code; /*!< Status code of the last operation */
u16_t current_scene; /*!< Scene Number of the current scene */
u16_t target_scene; /*!< Scene Number of the target scene (optional) */
u8_t remain_time; /*!< Time to complete state transition (C.1) */
bool op_en; /*!< Indicate if optional parameters are included */
uint8_t status_code; /*!< Status code of the last operation */
uint16_t current_scene; /*!< Scene Number of the current scene */
uint16_t target_scene; /*!< Scene Number of the target scene (optional) */
uint8_t remain_time; /*!< Time to complete state transition (C.1) */
} esp_ble_mesh_scene_status_cb_t;
/** Parameters of Scene Register Status */
typedef struct {
u8_t status_code; /*!< Status code for the previous operation */
u16_t current_scene; /*!< Scene Number of the current scene */
uint8_t status_code; /*!< Status code for the previous operation */
uint16_t current_scene; /*!< Scene Number of the current scene */
struct net_buf_simple *scenes; /*!< A list of scenes stored within an element */
} esp_ble_mesh_scene_register_status_cb_t;
/** Parameter of Scheduler Status */
typedef struct {
u16_t schedules; /*!< Bit field indicating defined Actions in the Schedule Register */
uint16_t schedules; /*!< Bit field indicating defined Actions in the Schedule Register */
} esp_ble_mesh_scheduler_status_cb_t;
/** Parameters of Scheduler Action Status */
typedef struct {
u64_t index : 4; /*!< Enumerates (selects) a Schedule Register entry */
u64_t year : 7; /*!< Scheduled year for the action */
u64_t month : 12; /*!< Scheduled month for the action */
u64_t day : 5; /*!< Scheduled day of the month for the action */
u64_t hour : 5; /*!< Scheduled hour for the action */
u64_t minute : 6; /*!< Scheduled minute for the action */
u64_t second : 6; /*!< Scheduled second for the action */
u64_t day_of_week : 7; /*!< Schedule days of the week for the action */
u64_t action : 4; /*!< Action to be performed at the scheduled time */
u64_t trans_time : 8; /*!< Transition time for this action */
u16_t scene_number; /*!< Transition time for this action */
uint64_t index : 4; /*!< Enumerates (selects) a Schedule Register entry */
uint64_t year : 7; /*!< Scheduled year for the action */
uint64_t month : 12; /*!< Scheduled month for the action */
uint64_t day : 5; /*!< Scheduled day of the month for the action */
uint64_t hour : 5; /*!< Scheduled hour for the action */
uint64_t minute : 6; /*!< Scheduled minute for the action */
uint64_t second : 6; /*!< Scheduled second for the action */
uint64_t day_of_week : 7; /*!< Schedule days of the week for the action */
uint64_t action : 4; /*!< Action to be performed at the scheduled time */
uint64_t trans_time : 8; /*!< Transition time for this action */
uint16_t scene_number; /*!< Transition time for this action */
} esp_ble_mesh_scheduler_act_status_cb_t;
/**

View File

@ -27,28 +27,22 @@
extern s32_t config_msg_timeout;
static inline void btc_ble_mesh_cfg_client_cb_to_app(esp_ble_mesh_cfg_client_cb_event_t event,
/* Configuration Client Model related functions */
static inline void btc_ble_mesh_config_client_cb_to_app(esp_ble_mesh_cfg_client_cb_event_t event,
esp_ble_mesh_cfg_client_cb_param_t *param)
{
esp_ble_mesh_cfg_client_cb_t btc_mesh_cb = (esp_ble_mesh_cfg_client_cb_t)btc_profile_cb_get(BTC_PID_CFG_CLIENT);
if (btc_mesh_cb) {
btc_mesh_cb(event, param);
esp_ble_mesh_cfg_client_cb_t btc_ble_mesh_cb =
(esp_ble_mesh_cfg_client_cb_t)btc_profile_cb_get(BTC_PID_CONFIG_CLIENT);
if (btc_ble_mesh_cb) {
btc_ble_mesh_cb(event, param);
}
}
static inline void btc_ble_mesh_cfg_server_cb_to_app(esp_ble_mesh_cfg_server_cb_event_t event,
esp_ble_mesh_cfg_server_cb_param_t *param)
void btc_ble_mesh_config_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
{
esp_ble_mesh_cfg_server_cb_t btc_mesh_cb = (esp_ble_mesh_cfg_server_cb_t)btc_profile_cb_get(BTC_PID_CFG_SERVER);
if (btc_mesh_cb) {
btc_mesh_cb(event, param);
}
}
void btc_ble_mesh_cfg_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
{
btc_ble_mesh_cfg_client_args_t *dst = (btc_ble_mesh_cfg_client_args_t *)p_dest;
btc_ble_mesh_cfg_client_args_t *src = (btc_ble_mesh_cfg_client_args_t *)p_src;
btc_ble_mesh_config_client_args_t *dst = (btc_ble_mesh_config_client_args_t *)p_dest;
btc_ble_mesh_config_client_args_t *src = (btc_ble_mesh_config_client_args_t *)p_src;
if (!msg || !dst || !src) {
LOG_ERROR("%s, Invalid parameter", __func__);
@ -88,11 +82,43 @@ void btc_ble_mesh_cfg_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p
}
}
static void btc_ble_mesh_cfg_client_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src)
static void btc_ble_mesh_config_client_arg_deep_free(btc_msg_t *msg)
{
btc_ble_mesh_config_client_args_t *arg = NULL;
if (!msg || !msg->arg) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
arg = (btc_ble_mesh_config_client_args_t *)(msg->arg);
switch (msg->act) {
case BTC_BLE_MESH_ACT_CONFIG_CLIENT_GET_STATE:
if (arg->cfg_client_get_state.params) {
osi_free(arg->cfg_client_get_state.params);
}
if (arg->cfg_client_get_state.get_state) {
osi_free(arg->cfg_client_get_state.get_state);
}
break;
case BTC_BLE_MESH_ACT_CONFIG_CLIENT_SET_STATE:
if (arg->cfg_client_set_state.params) {
osi_free(arg->cfg_client_set_state.params);
}
if (arg->cfg_client_set_state.set_state) {
osi_free(arg->cfg_client_set_state.set_state);
}
break;
default:
break;
}
}
static void btc_ble_mesh_config_client_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src)
{
esp_ble_mesh_cfg_client_cb_param_t *p_dest_data = (esp_ble_mesh_cfg_client_cb_param_t *)p_dest;
esp_ble_mesh_cfg_client_cb_param_t *p_src_data = (esp_ble_mesh_cfg_client_cb_param_t *)p_src;
u32_t opcode;
u16_t length;
if (!msg || !p_src_data || !p_dest_data) {
@ -100,13 +126,22 @@ static void btc_ble_mesh_cfg_client_copy_req_data(btc_msg_t *msg, void *p_dest,
return;
}
if (p_src_data->params) {
p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
if (!p_dest_data->params) {
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
return;
}
memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t));
}
switch (msg->act) {
case ESP_BLE_MESH_CFG_CLIENT_GET_STATE_EVT:
case ESP_BLE_MESH_CFG_CLIENT_SET_STATE_EVT:
case ESP_BLE_MESH_CFG_CLIENT_PUBLISH_EVT:
if (p_src_data->params) {
opcode = p_src_data->params->opcode;
switch (opcode) {
switch (p_src_data->params->opcode) {
case OP_DEV_COMP_DATA_GET:
case OP_DEV_COMP_DATA_STATUS:
if (p_src_data->status_cb.comp_data_status.composition_data) {
@ -186,24 +221,15 @@ static void btc_ble_mesh_cfg_client_copy_req_data(btc_msg_t *msg, void *p_dest,
}
}
case ESP_BLE_MESH_CFG_CLIENT_TIMEOUT_EVT:
if (p_src_data->params) {
p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
if (p_dest_data->params) {
memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t));
} else {
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
}
}
break;
default:
break;
}
}
static void btc_ble_mesh_cfg_client_free_req_data(btc_msg_t *msg)
static void btc_ble_mesh_config_client_free_req_data(btc_msg_t *msg)
{
esp_ble_mesh_cfg_client_cb_param_t *arg = NULL;
u32_t opcode;
if (!msg || !msg->arg) {
LOG_ERROR("%s, Invalid parameter", __func__);
@ -217,8 +243,7 @@ static void btc_ble_mesh_cfg_client_free_req_data(btc_msg_t *msg)
case ESP_BLE_MESH_CFG_CLIENT_SET_STATE_EVT:
case ESP_BLE_MESH_CFG_CLIENT_PUBLISH_EVT:
if (arg->params) {
opcode = arg->params->opcode;
switch (opcode) {
switch (arg->params->opcode) {
case OP_DEV_COMP_DATA_GET:
case OP_DEV_COMP_DATA_STATUS:
bt_mesh_free_buf(arg->status_cb.comp_data_status.composition_data);
@ -257,63 +282,28 @@ static void btc_ble_mesh_cfg_client_free_req_data(btc_msg_t *msg)
}
}
void btc_ble_mesh_cfg_client_arg_deep_free(btc_msg_t *msg)
{
btc_ble_mesh_cfg_client_args_t *arg = NULL;
if (!msg || !msg->arg) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
arg = (btc_ble_mesh_cfg_client_args_t *)(msg->arg);
switch (msg->act) {
case BTC_BLE_MESH_ACT_CONFIG_CLIENT_GET_STATE:
if (arg->cfg_client_get_state.params) {
osi_free(arg->cfg_client_get_state.params);
}
if (arg->cfg_client_get_state.get_state) {
osi_free(arg->cfg_client_get_state.get_state);
}
break;
case BTC_BLE_MESH_ACT_CONFIG_CLIENT_SET_STATE:
if (arg->cfg_client_set_state.params) {
osi_free(arg->cfg_client_set_state.params);
}
if (arg->cfg_client_set_state.set_state) {
osi_free(arg->cfg_client_set_state.set_state);
}
break;
default:
break;
}
return;
}
static void btc_mesh_cfg_client_callback(esp_ble_mesh_cfg_client_cb_param_t *cb_params, uint8_t act)
static void btc_ble_mesh_config_client_callback(esp_ble_mesh_cfg_client_cb_param_t *cb_params, uint8_t act)
{
btc_msg_t msg = {0};
LOG_DEBUG("%s", __func__);
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_CFG_CLIENT;
msg.pid = BTC_PID_CONFIG_CLIENT;
msg.act = act;
btc_transfer_context(&msg, cb_params,
sizeof(esp_ble_mesh_cfg_client_cb_param_t), btc_ble_mesh_cfg_client_copy_req_data);
sizeof(esp_ble_mesh_cfg_client_cb_param_t), btc_ble_mesh_config_client_copy_req_data);
}
void bt_mesh_callback_config_status_to_btc(u32_t opcode, u8_t evt_type,
void bt_mesh_config_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
const u8_t *val, size_t len)
{
esp_ble_mesh_cfg_client_cb_param_t cb_params = {0};
esp_ble_mesh_client_common_param_t params = {0};
size_t length;
size_t length;
uint8_t act;
if (!model || !ctx) {
@ -322,16 +312,16 @@ void bt_mesh_callback_config_status_to_btc(u32_t opcode, u8_t evt_type,
}
switch (evt_type) {
case 0x00:
case BTC_BLE_MESH_EVT_CONFIG_CLIENT_GET_STATE:
act = ESP_BLE_MESH_CFG_CLIENT_GET_STATE_EVT;
break;
case 0x01:
case BTC_BLE_MESH_EVT_CONFIG_CLIENT_SET_STATE:
act = ESP_BLE_MESH_CFG_CLIENT_SET_STATE_EVT;
break;
case 0x02:
case BTC_BLE_MESH_EVT_CONFIG_CLIENT_PUBLISH:
act = ESP_BLE_MESH_CFG_CLIENT_PUBLISH_EVT;
break;
case 0x03:
case BTC_BLE_MESH_EVT_CONFIG_CLIENT_TIMEOUT:
act = ESP_BLE_MESH_CFG_CLIENT_TIMEOUT_EVT;
break;
default:
@ -356,101 +346,32 @@ void bt_mesh_callback_config_status_to_btc(u32_t opcode, u8_t evt_type,
memcpy(&cb_params.status_cb, val, length);
}
btc_mesh_cfg_client_callback(&cb_params, act);
btc_ble_mesh_config_client_callback(&cb_params, act);
return;
}
void btc_mesh_cfg_client_publish_callback(u32_t opcode, struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf)
void btc_ble_mesh_config_client_publish_callback(u32_t opcode,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
if (!model || !ctx || !buf) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
bt_mesh_callback_config_status_to_btc(opcode, 0x02, model, ctx, buf->data, buf->len);
bt_mesh_config_client_cb_evt_to_btc(opcode,
BTC_BLE_MESH_EVT_CONFIG_CLIENT_PUBLISH, model, ctx, buf->data, buf->len);
return;
}
void btc_mesh_cfg_client_call_handler(btc_msg_t *msg)
{
esp_ble_mesh_cfg_client_cb_param_t cfg_client_cb = {0};
btc_ble_mesh_cfg_client_args_t *arg = NULL;
bt_mesh_role_param_t role_param = {0};
if (!msg || !msg->arg) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
arg = (btc_ble_mesh_cfg_client_args_t *)(msg->arg);
switch (msg->act) {
case BTC_BLE_MESH_ACT_CONFIG_CLIENT_GET_STATE: {
cfg_client_cb.params = arg->cfg_client_get_state.params;
role_param.model = (struct bt_mesh_model *)cfg_client_cb.params->model;
role_param.role = cfg_client_cb.params->msg_role;
if (bt_mesh_set_model_role(&role_param)) {
LOG_ERROR("%s, Failed to set model role", __func__);
return;
}
btc_ble_mesh_config_client_get_state(arg->cfg_client_get_state.params,
arg->cfg_client_get_state.get_state,
&cfg_client_cb);
if (cfg_client_cb.error_code) {
btc_mesh_cfg_client_callback(&cfg_client_cb, ESP_BLE_MESH_CFG_CLIENT_GET_STATE_EVT);
}
break;
}
case BTC_BLE_MESH_ACT_CONFIG_CLIENT_SET_STATE: {
cfg_client_cb.params = arg->cfg_client_set_state.params;
role_param.model = (struct bt_mesh_model *)cfg_client_cb.params->model;
role_param.role = cfg_client_cb.params->msg_role;
if (bt_mesh_set_model_role(&role_param)) {
LOG_ERROR("%s, Failed to set model role", __func__);
return;
}
btc_ble_mesh_config_client_set_state(arg->cfg_client_set_state.params,
arg->cfg_client_set_state.set_state,
&cfg_client_cb);
if (cfg_client_cb.error_code) {
btc_mesh_cfg_client_callback(&cfg_client_cb, ESP_BLE_MESH_CFG_CLIENT_SET_STATE_EVT);
}
break;
}
default:
break;
}
btc_ble_mesh_cfg_client_arg_deep_free(msg);
}
void btc_mesh_cfg_client_cb_handler(btc_msg_t *msg)
{
esp_ble_mesh_cfg_client_cb_param_t *param = NULL;
if (!msg || !msg->arg) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
param = (esp_ble_mesh_cfg_client_cb_param_t *)(msg->arg);
if (msg->act < ESP_BLE_MESH_CFG_CLIENT_EVT_MAX) {
btc_ble_mesh_cfg_client_cb_to_app(msg->act, param);
} else {
LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act);
}
btc_ble_mesh_cfg_client_free_req_data(msg);
}
int btc_ble_mesh_config_client_get_state(esp_ble_mesh_client_common_param_t *params,
esp_ble_mesh_cfg_client_get_state_t *get_state,
esp_ble_mesh_cfg_client_cb_param_t *cfg_client_cb)
static int btc_ble_mesh_config_client_get_state(esp_ble_mesh_client_common_param_t *params,
esp_ble_mesh_cfg_client_get_state_t *get,
esp_ble_mesh_cfg_client_cb_param_t *cb)
{
struct bt_mesh_msg_ctx ctx = {0};
if (!params || !cfg_client_cb) {
if (!params || !cb) {
LOG_ERROR("%s, Invalid parameter", __func__);
return -EINVAL;
}
@ -465,66 +386,68 @@ int btc_ble_mesh_config_client_get_state(esp_ble_mesh_client_common_param_t *par
switch (params->opcode) {
case ESP_BLE_MESH_MODEL_OP_BEACON_GET:
return (cfg_client_cb->error_code = bt_mesh_cfg_beacon_get(&ctx));
return (cb->error_code = bt_mesh_cfg_beacon_get(&ctx));
case ESP_BLE_MESH_MODEL_OP_DEFAULT_TTL_GET:
return (cfg_client_cb->error_code = bt_mesh_cfg_ttl_get(&ctx));
return (cb->error_code = bt_mesh_cfg_ttl_get(&ctx));
case ESP_BLE_MESH_MODEL_OP_FRIEND_GET:
return (cfg_client_cb->error_code = bt_mesh_cfg_friend_get(&ctx));
return (cb->error_code = bt_mesh_cfg_friend_get(&ctx));
case ESP_BLE_MESH_MODEL_OP_GATT_PROXY_GET:
return (cfg_client_cb->error_code = bt_mesh_cfg_gatt_proxy_get(&ctx));
return (cb->error_code = bt_mesh_cfg_gatt_proxy_get(&ctx));
case ESP_BLE_MESH_MODEL_OP_RELAY_GET:
return (cfg_client_cb->error_code = bt_mesh_cfg_relay_get(&ctx));
return (cb->error_code = bt_mesh_cfg_relay_get(&ctx));
case ESP_BLE_MESH_MODEL_OP_MODEL_PUB_GET:
return (cfg_client_cb->error_code =
bt_mesh_cfg_mod_pub_get(&ctx, get_state->model_pub_get.element_addr, get_state->model_pub_get.model_id,
get_state->model_pub_get.company_id));
return (cb->error_code =
bt_mesh_cfg_mod_pub_get(&ctx, get->model_pub_get.element_addr,
get->model_pub_get.model_id, get->model_pub_get.company_id));
case ESP_BLE_MESH_MODEL_OP_HEARTBEAT_PUB_GET:
return (cfg_client_cb->error_code = bt_mesh_cfg_hb_pub_get(&ctx));
return (cb->error_code = bt_mesh_cfg_hb_pub_get(&ctx));
case ESP_BLE_MESH_MODEL_OP_HEARTBEAT_SUB_GET:
return (cfg_client_cb->error_code = bt_mesh_cfg_hb_sub_get(&ctx));
return (cb->error_code = bt_mesh_cfg_hb_sub_get(&ctx));
case ESP_BLE_MESH_MODEL_OP_COMPOSITION_DATA_GET:
return (cfg_client_cb->error_code = bt_mesh_cfg_comp_data_get(&ctx, get_state->comp_data_get.page));
return (cb->error_code = bt_mesh_cfg_comp_data_get(&ctx, get->comp_data_get.page));
case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_SUB_GET:
return (cfg_client_cb->error_code =
bt_mesh_cfg_mod_sub_get(&ctx, get_state->sig_model_sub_get.element_addr, get_state->sig_model_sub_get.model_id));
return (cb->error_code =
bt_mesh_cfg_mod_sub_get(&ctx, get->sig_model_sub_get.element_addr,
get->sig_model_sub_get.model_id));
case ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_SUB_GET:
return (cfg_client_cb->error_code =
bt_mesh_cfg_mod_sub_get_vnd(&ctx, get_state->vnd_model_sub_get.element_addr,
get_state->vnd_model_sub_get.model_id, get_state->vnd_model_sub_get.company_id));
return (cb->error_code =
bt_mesh_cfg_mod_sub_get_vnd(&ctx, get->vnd_model_sub_get.element_addr,
get->vnd_model_sub_get.model_id, get->vnd_model_sub_get.company_id));
case ESP_BLE_MESH_MODEL_OP_NET_KEY_GET:
return (cfg_client_cb->error_code = bt_mesh_cfg_net_key_get(&ctx));
return (cb->error_code = bt_mesh_cfg_net_key_get(&ctx));
case ESP_BLE_MESH_MODEL_OP_APP_KEY_GET:
return (cfg_client_cb->error_code = bt_mesh_cfg_app_key_get(&ctx, get_state->app_key_get.net_idx));
return (cb->error_code = bt_mesh_cfg_app_key_get(&ctx, get->app_key_get.net_idx));
case ESP_BLE_MESH_MODEL_OP_NODE_IDENTITY_GET:
return (cfg_client_cb->error_code = bt_mesh_cfg_node_identity_get(&ctx, get_state->node_identity_get.net_idx));
return (cb->error_code = bt_mesh_cfg_node_identity_get(&ctx, get->node_identity_get.net_idx));
case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_APP_GET:
return (cfg_client_cb->error_code =
bt_mesh_cfg_mod_app_get(&ctx, get_state->sig_model_app_get.element_addr, get_state->sig_model_app_get.model_id));
return (cb->error_code =
bt_mesh_cfg_mod_app_get(&ctx, get->sig_model_app_get.element_addr,
get->sig_model_app_get.model_id));
case ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_APP_GET:
return (cfg_client_cb->error_code =
bt_mesh_cfg_mod_app_get_vnd(&ctx, get_state->vnd_model_app_get.element_addr,
get_state->vnd_model_app_get.model_id, get_state->vnd_model_app_get.company_id));
return (cb->error_code =
bt_mesh_cfg_mod_app_get_vnd(&ctx, get->vnd_model_app_get.element_addr,
get->vnd_model_app_get.model_id, get->vnd_model_app_get.company_id));
case ESP_BLE_MESH_MODEL_OP_KEY_REFRESH_PHASE_GET:
return (cfg_client_cb->error_code = bt_mesh_cfg_kr_phase_get(&ctx, get_state->kr_phase_get.net_idx));
return (cb->error_code = bt_mesh_cfg_kr_phase_get(&ctx, get->kr_phase_get.net_idx));
case ESP_BLE_MESH_MODEL_OP_LPN_POLLTIMEOUT_GET:
return (cfg_client_cb->error_code = bt_mesh_cfg_lpn_timeout_get(&ctx, get_state->lpn_pollto_get.lpn_addr));
return (cb->error_code = bt_mesh_cfg_lpn_timeout_get(&ctx, get->lpn_pollto_get.lpn_addr));
case ESP_BLE_MESH_MODEL_OP_NETWORK_TRANSMIT_GET:
return (cfg_client_cb->error_code = bt_mesh_cfg_net_transmit_get(&ctx));
return (cb->error_code = bt_mesh_cfg_net_transmit_get(&ctx));
default:
BT_WARN("%s, Invalid opcode 0x%x", __func__, params->opcode);
return (cfg_client_cb->error_code = -EINVAL);
LOG_ERROR("%s, Invalid opcode 0x%x", __func__, params->opcode);
return (cb->error_code = -EINVAL);
}
return 0;
}
int btc_ble_mesh_config_client_set_state(esp_ble_mesh_client_common_param_t *params,
esp_ble_mesh_cfg_client_set_state_t *set_state,
esp_ble_mesh_cfg_client_cb_param_t *cfg_client_cb)
static int btc_ble_mesh_config_client_set_state(esp_ble_mesh_client_common_param_t *params,
esp_ble_mesh_cfg_client_set_state_t *set,
esp_ble_mesh_cfg_client_cb_param_t *cb)
{
struct bt_mesh_msg_ctx ctx = {0};
if (!params || !set_state || !cfg_client_cb) {
if (!params || !set || !cb) {
LOG_ERROR("%s, Invalid parameter", __func__);
return -EINVAL;
}
@ -539,141 +462,245 @@ int btc_ble_mesh_config_client_set_state(esp_ble_mesh_client_common_param_t *par
switch (params->opcode) {
case ESP_BLE_MESH_MODEL_OP_BEACON_SET:
return (cfg_client_cb->error_code = bt_mesh_cfg_beacon_set(&ctx, set_state->beacon_set.beacon));
return (cb->error_code = bt_mesh_cfg_beacon_set(&ctx, set->beacon_set.beacon));
case ESP_BLE_MESH_MODEL_OP_DEFAULT_TTL_SET:
return (cfg_client_cb->error_code = bt_mesh_cfg_ttl_set(&ctx, set_state->default_ttl_set.ttl));
return (cb->error_code = bt_mesh_cfg_ttl_set(&ctx, set->default_ttl_set.ttl));
case ESP_BLE_MESH_MODEL_OP_FRIEND_SET:
return (cfg_client_cb->error_code = bt_mesh_cfg_friend_set(&ctx, set_state->friend_set.friend_state));
return (cb->error_code = bt_mesh_cfg_friend_set(&ctx, set->friend_set.friend_state));
case ESP_BLE_MESH_MODEL_OP_GATT_PROXY_SET:
return (cfg_client_cb->error_code = bt_mesh_cfg_gatt_proxy_set(&ctx, set_state->gatt_proxy_set.gatt_proxy));
return (cb->error_code = bt_mesh_cfg_gatt_proxy_set(&ctx, set->gatt_proxy_set.gatt_proxy));
case ESP_BLE_MESH_MODEL_OP_RELAY_SET:
return (cfg_client_cb->error_code =
bt_mesh_cfg_relay_set(&ctx, set_state->relay_set.relay, set_state->relay_set.relay_retransmit));
return (cb->error_code =
bt_mesh_cfg_relay_set(&ctx, set->relay_set.relay, set->relay_set.relay_retransmit));
case ESP_BLE_MESH_MODEL_OP_NET_KEY_ADD:
return (cfg_client_cb->error_code =
bt_mesh_cfg_net_key_add(&ctx, set_state->net_key_add.net_idx, &set_state->net_key_add.net_key[0]));
return (cb->error_code =
bt_mesh_cfg_net_key_add(&ctx, set->net_key_add.net_idx,
&set->net_key_add.net_key[0]));
case ESP_BLE_MESH_MODEL_OP_APP_KEY_ADD:
return (cfg_client_cb->error_code =
bt_mesh_cfg_app_key_add(&ctx, set_state->app_key_add.net_idx,
set_state->app_key_add.app_idx, &set_state->app_key_add.app_key[0]));
return (cb->error_code =
bt_mesh_cfg_app_key_add(&ctx, set->app_key_add.net_idx,
set->app_key_add.app_idx, &set->app_key_add.app_key[0]));
case ESP_BLE_MESH_MODEL_OP_MODEL_APP_BIND:
return (cfg_client_cb->error_code =
bt_mesh_cfg_mod_app_bind(&ctx, set_state->model_app_bind.element_addr, set_state->model_app_bind.model_app_idx,
set_state->model_app_bind.model_id, set_state->model_app_bind.company_id));
return (cb->error_code =
bt_mesh_cfg_mod_app_bind(&ctx, set->model_app_bind.element_addr,
set->model_app_bind.model_app_idx, set->model_app_bind.model_id,
set->model_app_bind.company_id));
case ESP_BLE_MESH_MODEL_OP_MODEL_PUB_SET: {
struct bt_mesh_cfg_mod_pub model_pub = {
.addr = set_state->model_pub_set.publish_addr,
.app_idx = set_state->model_pub_set.publish_app_idx,
.cred_flag = set_state->model_pub_set.cred_flag,
.ttl = set_state->model_pub_set.publish_ttl,
.period = set_state->model_pub_set.publish_period,
.transmit = set_state->model_pub_set.publish_retransmit,
.addr = set->model_pub_set.publish_addr,
.app_idx = set->model_pub_set.publish_app_idx,
.cred_flag = set->model_pub_set.cred_flag,
.ttl = set->model_pub_set.publish_ttl,
.period = set->model_pub_set.publish_period,
.transmit = set->model_pub_set.publish_retransmit,
};
return (cfg_client_cb->error_code =
bt_mesh_cfg_mod_pub_set(&ctx, set_state->model_pub_set.element_addr, set_state->model_pub_set.model_id,
set_state->model_pub_set.company_id, &model_pub));
return (cb->error_code =
bt_mesh_cfg_mod_pub_set(&ctx, set->model_pub_set.element_addr,
set->model_pub_set.model_id, set->model_pub_set.company_id, &model_pub));
}
case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_ADD:
return (cfg_client_cb->error_code =
bt_mesh_cfg_mod_sub_add(&ctx, set_state->model_sub_add.element_addr, set_state->model_sub_add.sub_addr,
set_state->model_sub_add.model_id, set_state->model_sub_add.company_id));
return (cb->error_code =
bt_mesh_cfg_mod_sub_add(&ctx, set->model_sub_add.element_addr,
set->model_sub_add.sub_addr, set->model_sub_add.model_id,
set->model_sub_add.company_id));
case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_DELETE:
return (cfg_client_cb->error_code =
bt_mesh_cfg_mod_sub_del(&ctx, set_state->model_sub_delete.element_addr, set_state->model_sub_delete.sub_addr,
set_state->model_sub_delete.model_id, set_state->model_sub_delete.company_id));
return (cb->error_code =
bt_mesh_cfg_mod_sub_del(&ctx, set->model_sub_delete.element_addr,
set->model_sub_delete.sub_addr, set->model_sub_delete.model_id,
set->model_sub_delete.company_id));
case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_OVERWRITE:
return (cfg_client_cb->error_code =
bt_mesh_cfg_mod_sub_overwrite(&ctx, set_state->model_sub_overwrite.element_addr, set_state->model_sub_overwrite.sub_addr,
set_state->model_sub_overwrite.model_id, set_state->model_sub_overwrite.company_id));
return (cb->error_code =
bt_mesh_cfg_mod_sub_overwrite(&ctx, set->model_sub_overwrite.element_addr,
set->model_sub_overwrite.sub_addr, set->model_sub_overwrite.model_id,
set->model_sub_overwrite.company_id));
case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_VIRTUAL_ADDR_ADD:
return (cfg_client_cb->error_code =
bt_mesh_cfg_mod_sub_va_add(&ctx, set_state->model_sub_va_add.element_addr, &set_state->model_sub_va_add.label_uuid[0],
set_state->model_sub_va_add.model_id, set_state->model_sub_va_add.company_id));
return (cb->error_code =
bt_mesh_cfg_mod_sub_va_add(&ctx, set->model_sub_va_add.element_addr,
&set->model_sub_va_add.label_uuid[0], set->model_sub_va_add.model_id,
set->model_sub_va_add.company_id));
case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_VIRTUAL_ADDR_OVERWRITE:
return (cfg_client_cb->error_code =
bt_mesh_cfg_mod_sub_va_overwrite(&ctx, set_state->model_sub_va_overwrite.element_addr, &set_state->model_sub_va_overwrite.label_uuid[0],
set_state->model_sub_va_overwrite.model_id, set_state->model_sub_va_overwrite.company_id));
return (cb->error_code =
bt_mesh_cfg_mod_sub_va_overwrite(&ctx, set->model_sub_va_overwrite.element_addr,
&set->model_sub_va_overwrite.label_uuid[0], set->model_sub_va_overwrite.model_id,
set->model_sub_va_overwrite.company_id));
case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_VIRTUAL_ADDR_DELETE:
return (cfg_client_cb->error_code =
bt_mesh_cfg_mod_sub_va_del(&ctx, set_state->model_sub_va_delete.element_addr, &set_state->model_sub_va_delete.label_uuid[0],
set_state->model_sub_va_delete.model_id, set_state->model_sub_va_delete.company_id));
return (cb->error_code =
bt_mesh_cfg_mod_sub_va_del(&ctx, set->model_sub_va_delete.element_addr,
&set->model_sub_va_delete.label_uuid[0], set->model_sub_va_delete.model_id,
set->model_sub_va_delete.company_id));
case ESP_BLE_MESH_MODEL_OP_HEARTBEAT_SUB_SET:
return (cfg_client_cb->error_code =
bt_mesh_cfg_hb_sub_set(&ctx, (struct bt_mesh_cfg_hb_sub *)&set_state->heartbeat_sub_set));
return (cb->error_code =
bt_mesh_cfg_hb_sub_set(&ctx,
(struct bt_mesh_cfg_hb_sub *)&set->heartbeat_sub_set));
case ESP_BLE_MESH_MODEL_OP_HEARTBEAT_PUB_SET:
return (cfg_client_cb->error_code =
bt_mesh_cfg_hb_pub_set(&ctx, (const struct bt_mesh_cfg_hb_pub *)&set_state->heartbeat_pub_set));
return (cb->error_code =
bt_mesh_cfg_hb_pub_set(&ctx,
(const struct bt_mesh_cfg_hb_pub *)&set->heartbeat_pub_set));
case ESP_BLE_MESH_MODEL_OP_NODE_RESET:
return (cfg_client_cb->error_code = bt_mesh_cfg_node_reset(&ctx));
return (cb->error_code = bt_mesh_cfg_node_reset(&ctx));
case ESP_BLE_MESH_MODEL_OP_MODEL_PUB_VIRTUAL_ADDR_SET: {
struct bt_mesh_cfg_mod_pub model_pub = {
.app_idx = set_state->model_pub_va_set.publish_app_idx,
.cred_flag = set_state->model_pub_va_set.cred_flag,
.ttl = set_state->model_pub_va_set.publish_ttl,
.period = set_state->model_pub_va_set.publish_period,
.transmit = set_state->model_pub_va_set.publish_retransmit,
.app_idx = set->model_pub_va_set.publish_app_idx,
.cred_flag = set->model_pub_va_set.cred_flag,
.ttl = set->model_pub_va_set.publish_ttl,
.period = set->model_pub_va_set.publish_period,
.transmit = set->model_pub_va_set.publish_retransmit,
};
return (cfg_client_cb->error_code =
bt_mesh_cfg_mod_pub_va_set(&ctx, set_state->model_pub_va_set.element_addr, set_state->model_pub_va_set.model_id,
set_state->model_pub_va_set.company_id, set_state->model_pub_va_set.label_uuid, &model_pub));
return (cb->error_code =
bt_mesh_cfg_mod_pub_va_set(&ctx, set->model_pub_va_set.element_addr,
set->model_pub_va_set.model_id, set->model_pub_va_set.company_id,
set->model_pub_va_set.label_uuid, &model_pub));
}
case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_DELETE_ALL:
return (cfg_client_cb->error_code =
bt_mesh_cfg_mod_sub_del_all(&ctx, set_state->model_sub_delete_all.element_addr,
set_state->model_sub_delete_all.model_id, set_state->model_sub_delete_all.company_id));
return (cb->error_code =
bt_mesh_cfg_mod_sub_del_all(&ctx, set->model_sub_delete_all.element_addr,
set->model_sub_delete_all.model_id, set->model_sub_delete_all.company_id));
case ESP_BLE_MESH_MODEL_OP_NET_KEY_UPDATE:
return (cfg_client_cb->error_code =
bt_mesh_cfg_net_key_update(&ctx, set_state->net_key_update.net_idx, set_state->net_key_update.net_key));
return (cb->error_code =
bt_mesh_cfg_net_key_update(&ctx, set->net_key_update.net_idx,
set->net_key_update.net_key));
case ESP_BLE_MESH_MODEL_OP_NET_KEY_DELETE:
return (cfg_client_cb->error_code =
bt_mesh_cfg_net_key_delete(&ctx, set_state->net_key_delete.net_idx));
return (cb->error_code =
bt_mesh_cfg_net_key_delete(&ctx, set->net_key_delete.net_idx));
case ESP_BLE_MESH_MODEL_OP_APP_KEY_UPDATE:
return (cfg_client_cb->error_code =
bt_mesh_cfg_app_key_update(&ctx, set_state->app_key_update.net_idx, set_state->app_key_update.app_idx,
set_state->app_key_update.app_key));
return (cb->error_code =
bt_mesh_cfg_app_key_update(&ctx, set->app_key_update.net_idx,
set->app_key_update.app_idx, set->app_key_update.app_key));
case ESP_BLE_MESH_MODEL_OP_APP_KEY_DELETE:
return (cfg_client_cb->error_code =
bt_mesh_cfg_app_key_delete(&ctx, set_state->app_key_delete.net_idx, set_state->app_key_delete.app_idx));
return (cb->error_code =
bt_mesh_cfg_app_key_delete(&ctx, set->app_key_delete.net_idx,
set->app_key_delete.app_idx));
case ESP_BLE_MESH_MODEL_OP_NODE_IDENTITY_SET:
return (cfg_client_cb->error_code =
bt_mesh_cfg_node_identity_set(&ctx, set_state->node_identity_set.net_idx, set_state->node_identity_set.identity));
return (cb->error_code =
bt_mesh_cfg_node_identity_set(&ctx, set->node_identity_set.net_idx,
set->node_identity_set.identity));
case ESP_BLE_MESH_MODEL_OP_MODEL_APP_UNBIND:
return (cfg_client_cb->error_code =
bt_mesh_cfg_mod_app_unbind(&ctx, set_state->model_app_unbind.element_addr, set_state->model_app_unbind.model_app_idx,
set_state->model_app_unbind.model_id, set_state->model_app_unbind.company_id));
return (cb->error_code =
bt_mesh_cfg_mod_app_unbind(&ctx, set->model_app_unbind.element_addr,
set->model_app_unbind.model_app_idx, set->model_app_unbind.model_id,
set->model_app_unbind.company_id));
case ESP_BLE_MESH_MODEL_OP_KEY_REFRESH_PHASE_SET:
return (cfg_client_cb->error_code =
bt_mesh_cfg_kr_phase_set(&ctx, set_state->kr_phase_set.net_idx, set_state->kr_phase_set.transition));
return (cb->error_code =
bt_mesh_cfg_kr_phase_set(&ctx, set->kr_phase_set.net_idx,
set->kr_phase_set.transition));
case ESP_BLE_MESH_MODEL_OP_NETWORK_TRANSMIT_SET:
return (cfg_client_cb->error_code =
bt_mesh_cfg_net_transmit_set(&ctx, set_state->net_transmit_set.net_transmit));
return (cb->error_code =
bt_mesh_cfg_net_transmit_set(&ctx, set->net_transmit_set.net_transmit));
default:
BT_WARN("%s, Invalid opcode 0x%x", __func__, params->opcode);
return (cfg_client_cb->error_code = -EINVAL);
LOG_ERROR("%s, Invalid opcode 0x%x", __func__, params->opcode);
return (cb->error_code = -EINVAL);
}
return 0;
}
static void btc_mesh_cfg_server_callback(esp_ble_mesh_cfg_server_cb_param_t *cb_params, uint8_t act)
void btc_ble_mesh_config_client_call_handler(btc_msg_t *msg)
{
btc_ble_mesh_config_client_args_t *arg = NULL;
esp_ble_mesh_cfg_client_cb_param_t cb = {0};
bt_mesh_role_param_t role_param = {0};
if (!msg || !msg->arg) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
arg = (btc_ble_mesh_config_client_args_t *)(msg->arg);
switch (msg->act) {
case BTC_BLE_MESH_ACT_CONFIG_CLIENT_GET_STATE: {
cb.params = arg->cfg_client_get_state.params;
role_param.model = (struct bt_mesh_model *)cb.params->model;
role_param.role = cb.params->msg_role;
if (bt_mesh_set_client_model_role(&role_param)) {
LOG_ERROR("%s, Failed to set model role", __func__);
break;
}
btc_ble_mesh_config_client_get_state(arg->cfg_client_get_state.params,
arg->cfg_client_get_state.get_state,
&cb);
if (cb.error_code) {
btc_ble_mesh_config_client_callback(&cb, ESP_BLE_MESH_CFG_CLIENT_GET_STATE_EVT);
}
break;
}
case BTC_BLE_MESH_ACT_CONFIG_CLIENT_SET_STATE: {
cb.params = arg->cfg_client_set_state.params;
role_param.model = (struct bt_mesh_model *)cb.params->model;
role_param.role = cb.params->msg_role;
if (bt_mesh_set_client_model_role(&role_param)) {
LOG_ERROR("%s, Failed to set model role", __func__);
break;
}
btc_ble_mesh_config_client_set_state(arg->cfg_client_set_state.params,
arg->cfg_client_set_state.set_state,
&cb);
if (cb.error_code) {
btc_ble_mesh_config_client_callback(&cb, ESP_BLE_MESH_CFG_CLIENT_SET_STATE_EVT);
}
break;
}
default:
break;
}
btc_ble_mesh_config_client_arg_deep_free(msg);
return;
}
void btc_ble_mesh_config_client_cb_handler(btc_msg_t *msg)
{
esp_ble_mesh_cfg_client_cb_param_t *param = NULL;
if (!msg || !msg->arg) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
param = (esp_ble_mesh_cfg_client_cb_param_t *)(msg->arg);
if (msg->act < ESP_BLE_MESH_CFG_CLIENT_EVT_MAX) {
btc_ble_mesh_config_client_cb_to_app(msg->act, param);
} else {
LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act);
}
btc_ble_mesh_config_client_free_req_data(msg);
return;
}
/* Configuration Server Model related functions */
static inline void btc_ble_mesh_config_server_cb_to_app(esp_ble_mesh_cfg_server_cb_event_t event,
esp_ble_mesh_cfg_server_cb_param_t *param)
{
esp_ble_mesh_cfg_server_cb_t btc_ble_mesh_cb =
(esp_ble_mesh_cfg_server_cb_t)btc_profile_cb_get(BTC_PID_CONFIG_SERVER);
if (btc_ble_mesh_cb) {
btc_ble_mesh_cb(event, param);
}
}
static void btc_ble_mesh_config_server_callback(esp_ble_mesh_cfg_server_cb_param_t *cb_params, uint8_t act)
{
btc_msg_t msg = {0};
LOG_DEBUG("%s", __func__);
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_CFG_SERVER;
msg.pid = BTC_PID_CONFIG_SERVER;
msg.act = act;
btc_transfer_context(&msg, cb_params, sizeof(esp_ble_mesh_cfg_server_cb_param_t), NULL);
}
void bt_mesh_callback_cfg_server_event_to_btc(u8_t evt_type, struct bt_mesh_model *model,
void bt_mesh_config_server_cb_evt_to_btc(u8_t evt_type,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
const u8_t *val, size_t len)
{
esp_ble_mesh_cfg_server_cb_param_t cb_params = {0};
size_t length;
size_t length;
uint8_t act;
if (!model || !ctx) {
@ -682,7 +709,7 @@ void bt_mesh_callback_cfg_server_event_to_btc(u8_t evt_type, struct bt_mesh_mode
}
switch (evt_type) {
case 0x00:
case BTC_BLE_MESH_EVT_CONFIG_SERVER_RECV_MSG:
act = ESP_BLE_MESH_CFG_SERVER_RECV_MSG_EVT;
break;
default:
@ -703,10 +730,11 @@ void bt_mesh_callback_cfg_server_event_to_btc(u8_t evt_type, struct bt_mesh_mode
memcpy(&cb_params.status_cb, val, length);
}
btc_mesh_cfg_server_callback(&cb_params, act);
btc_ble_mesh_config_server_callback(&cb_params, act);
return;
}
void btc_mesh_cfg_server_cb_handler(btc_msg_t *msg)
void btc_ble_mesh_config_server_cb_handler(btc_msg_t *msg)
{
esp_ble_mesh_cfg_server_cb_param_t *param = NULL;
@ -718,7 +746,7 @@ void btc_mesh_cfg_server_cb_handler(btc_msg_t *msg)
param = (esp_ble_mesh_cfg_server_cb_param_t *)(msg->arg);
if (msg->act < ESP_BLE_MESH_CFG_SERVER_EVT_MAX) {
btc_ble_mesh_cfg_server_cb_to_app(msg->act, param);
btc_ble_mesh_config_server_cb_to_app(msg->act, param);
} else {
LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act);
}

View File

@ -18,16 +18,19 @@
#include "btc/btc_manage.h"
#include "osi/allocator.h"
#include "cfg_cli.h"
#include "generic_client.h"
#include "btc_ble_mesh_generic_model.h"
#include "esp_ble_mesh_generic_model_api.h"
static inline void btc_ble_mesh_cb_to_app(esp_ble_mesh_generic_client_cb_event_t event,
/* Generic Client Models related functions */
static inline void btc_ble_mesh_generic_client_cb_to_app(esp_ble_mesh_generic_client_cb_event_t event,
esp_ble_mesh_generic_client_cb_param_t *param)
{
esp_ble_mesh_generic_client_cb_t btc_mesh_cb = (esp_ble_mesh_generic_client_cb_t)btc_profile_cb_get(BTC_PID_GENERIC_CLIENT);
if (btc_mesh_cb) {
btc_mesh_cb(event, param);
esp_ble_mesh_generic_client_cb_t btc_ble_mesh_cb =
(esp_ble_mesh_generic_client_cb_t)btc_profile_cb_get(BTC_PID_GENERIC_CLIENT);
if (btc_ble_mesh_cb) {
btc_ble_mesh_cb(event, param);
}
}
@ -35,7 +38,6 @@ void btc_ble_mesh_generic_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, voi
{
btc_ble_mesh_generic_client_args_t *dst = (btc_ble_mesh_generic_client_args_t *)p_dest;
btc_ble_mesh_generic_client_args_t *src = (btc_ble_mesh_generic_client_args_t *)p_src;
u32_t opcode;
u16_t length;
if (!msg || !dst || !src) {
@ -66,8 +68,7 @@ void btc_ble_mesh_generic_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, voi
memcpy(dst->generic_client_set_state.set_state, src->generic_client_set_state.set_state,
sizeof(esp_ble_mesh_generic_client_set_state_t));
opcode = src->generic_client_set_state.params->opcode;
switch (opcode) {
switch (src->generic_client_set_state.params->opcode) {
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET:
if (src->generic_client_set_state.set_state->user_property_set.property_value) {
length = src->generic_client_set_state.set_state->user_property_set.property_value->len;
@ -108,11 +109,55 @@ void btc_ble_mesh_generic_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, voi
}
}
static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src)
static void btc_ble_mesh_generic_client_arg_deep_free(btc_msg_t *msg)
{
btc_ble_mesh_generic_client_args_t *arg = NULL;
if (!msg || !msg->arg) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
arg = (btc_ble_mesh_generic_client_args_t *)(msg->arg);
switch (msg->act) {
case BTC_BLE_MESH_ACT_GENERIC_CLIENT_GET_STATE:
if (arg->generic_client_get_state.params) {
osi_free(arg->generic_client_get_state.params);
}
if (arg->generic_client_get_state.get_state) {
osi_free(arg->generic_client_get_state.get_state);
}
break;
case BTC_BLE_MESH_ACT_GENERIC_CLIENT_SET_STATE:
if (arg->generic_client_set_state.set_state) {
if (arg->generic_client_set_state.params) {
switch (arg->generic_client_set_state.params->opcode) {
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET:
bt_mesh_free_buf(arg->generic_client_set_state.set_state->user_property_set.property_value);
break;
case ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET:
bt_mesh_free_buf(arg->generic_client_set_state.set_state->admin_property_set.property_value);
break;
default:
break;
}
}
osi_free(arg->generic_client_set_state.set_state);
}
if (arg->generic_client_set_state.params) {
osi_free(arg->generic_client_set_state.params);
}
break;
default:
break;
}
}
static void btc_ble_mesh_generic_client_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src)
{
esp_ble_mesh_generic_client_cb_param_t *p_dest_data = (esp_ble_mesh_generic_client_cb_param_t *)p_dest;
esp_ble_mesh_generic_client_cb_param_t *p_src_data = (esp_ble_mesh_generic_client_cb_param_t *)p_src;
u32_t opcode;
u16_t length;
if (!msg || !p_src_data || !p_dest_data) {
@ -120,13 +165,22 @@ static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src
return;
}
if (p_src_data->params) {
p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
if (!p_dest_data->params) {
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
return;
}
memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t));
}
switch (msg->act) {
case ESP_BLE_MESH_GENERIC_CLIENT_GET_STATE_EVT:
case ESP_BLE_MESH_GENERIC_CLIENT_SET_STATE_EVT:
case ESP_BLE_MESH_GENERIC_CLIENT_PUBLISH_EVT:
if (p_src_data->params) {
opcode = p_src_data->params->opcode;
switch (opcode) {
switch (p_src_data->params->opcode) {
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_GET:
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_STATUS:
if (p_src_data->status_cb.user_properties_status.property_ids) {
@ -233,24 +287,15 @@ static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src
}
}
case ESP_BLE_MESH_GENERIC_CLIENT_TIMEOUT_EVT:
if (p_src_data->params) {
p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
if (p_dest_data->params) {
memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t));
} else {
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
}
}
break;
default:
break;
}
}
static void btc_ble_mesh_free_req_data(btc_msg_t *msg)
static void btc_ble_mesh_generic_client_free_req_data(btc_msg_t *msg)
{
esp_ble_mesh_generic_client_cb_param_t *arg = NULL;
u32_t opcode;
if (!msg || !msg->arg) {
LOG_ERROR("%s, Invalid parameter", __func__);
@ -264,8 +309,7 @@ static void btc_ble_mesh_free_req_data(btc_msg_t *msg)
case ESP_BLE_MESH_GENERIC_CLIENT_SET_STATE_EVT:
case ESP_BLE_MESH_GENERIC_CLIENT_PUBLISH_EVT:
if (arg->params) {
opcode = arg->params->opcode;
switch (opcode) {
switch (arg->params->opcode) {
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_GET:
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_STATUS:
bt_mesh_free_buf(arg->status_cb.user_properties_status.property_ids);
@ -311,56 +355,7 @@ static void btc_ble_mesh_free_req_data(btc_msg_t *msg)
}
}
void btc_ble_mesh_generic_client_arg_deep_free(btc_msg_t *msg)
{
btc_ble_mesh_generic_client_args_t *arg = NULL;
u32_t opcode = 0;
if (!msg || !msg->arg) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
arg = (btc_ble_mesh_generic_client_args_t *)(msg->arg);
switch (msg->act) {
case BTC_BLE_MESH_ACT_GENERIC_CLIENT_GET_STATE:
if (arg->generic_client_get_state.params) {
osi_free(arg->generic_client_get_state.params);
}
if (arg->generic_client_get_state.get_state) {
osi_free(arg->generic_client_get_state.get_state);
}
break;
case BTC_BLE_MESH_ACT_GENERIC_CLIENT_SET_STATE:
if (arg->generic_client_set_state.params) {
opcode = arg->generic_client_set_state.params->opcode;
osi_free(arg->generic_client_set_state.params);
}
if (arg->generic_client_set_state.set_state) {
if (opcode) {
switch (opcode) {
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET:
bt_mesh_free_buf(arg->generic_client_set_state.set_state->user_property_set.property_value);
break;
case ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET:
bt_mesh_free_buf(arg->generic_client_set_state.set_state->admin_property_set.property_value);
break;
default:
break;
}
}
osi_free(arg->generic_client_set_state.set_state);
}
break;
default:
break;
}
return;
}
static void btc_mesh_generic_client_callback(esp_ble_mesh_generic_client_cb_param_t *cb_params, uint8_t act)
static void btc_ble_mesh_generic_client_callback(esp_ble_mesh_generic_client_cb_param_t *cb_params, uint8_t act)
{
btc_msg_t msg = {0};
@ -371,10 +366,10 @@ static void btc_mesh_generic_client_callback(esp_ble_mesh_generic_client_cb_para
msg.act = act;
btc_transfer_context(&msg, cb_params,
sizeof(esp_ble_mesh_generic_client_cb_param_t), btc_ble_mesh_copy_req_data);
sizeof(esp_ble_mesh_generic_client_cb_param_t), btc_ble_mesh_generic_client_copy_req_data);
}
void bt_mesh_callback_generic_status_to_btc(u32_t opcode, u8_t evt_type,
void bt_mesh_generic_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
const u8_t *val, size_t len)
@ -390,16 +385,16 @@ void bt_mesh_callback_generic_status_to_btc(u32_t opcode, u8_t evt_type,
}
switch (evt_type) {
case 0x00:
case BTC_BLE_MESH_EVT_GENERIC_CLIENT_GET_STATE:
act = ESP_BLE_MESH_GENERIC_CLIENT_GET_STATE_EVT;
break;
case 0x01:
case BTC_BLE_MESH_EVT_GENERIC_CLIENT_SET_STATE:
act = ESP_BLE_MESH_GENERIC_CLIENT_SET_STATE_EVT;
break;
case 0x02:
case BTC_BLE_MESH_EVT_GENERIC_CLIENT_PUBLISH:
act = ESP_BLE_MESH_GENERIC_CLIENT_PUBLISH_EVT;
break;
case 0x03:
case BTC_BLE_MESH_EVT_GENERIC_CLIENT_TIMEOUT:
act = ESP_BLE_MESH_GENERIC_CLIENT_TIMEOUT_EVT;
break;
default:
@ -424,26 +419,31 @@ void bt_mesh_callback_generic_status_to_btc(u32_t opcode, u8_t evt_type,
memcpy(&cb_params.status_cb, val, length);
}
btc_mesh_generic_client_callback(&cb_params, act);
btc_ble_mesh_generic_client_callback(&cb_params, act);
return;
}
void btc_mesh_generic_client_publish_callback(u32_t opcode, struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf)
void btc_ble_mesh_generic_client_publish_callback(u32_t opcode,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
if (!model || !ctx || !buf) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
bt_mesh_callback_generic_status_to_btc(opcode, 0x02, model, ctx, buf->data, buf->len);
bt_mesh_generic_client_cb_evt_to_btc(opcode,
BTC_BLE_MESH_EVT_GENERIC_CLIENT_PUBLISH, model, ctx, buf->data, buf->len);
return;
}
void btc_mesh_generic_client_call_handler(btc_msg_t *msg)
void btc_ble_mesh_generic_client_call_handler(btc_msg_t *msg)
{
esp_ble_mesh_generic_client_cb_param_t generic_client_cb = {0};
esp_ble_mesh_client_common_param_t *params = NULL;
btc_ble_mesh_generic_client_args_t *arg = NULL;
struct bt_mesh_common_param common = {0};
esp_ble_mesh_generic_client_cb_param_t cb = {0};
bt_mesh_client_common_param_t common = {0};
bt_mesh_role_param_t role_param = {0};
if (!msg || !msg->arg) {
@ -458,9 +458,9 @@ void btc_mesh_generic_client_call_handler(btc_msg_t *msg)
params = arg->generic_client_get_state.params;
role_param.model = (struct bt_mesh_model *)params->model;
role_param.role = params->msg_role;
if (bt_mesh_set_model_role(&role_param)) {
if (bt_mesh_set_client_model_role(&role_param)) {
LOG_ERROR("%s, Failed to set model role", __func__);
return;
break;
}
common.opcode = params->opcode;
common.model = (struct bt_mesh_model *)params->model;
@ -471,15 +471,12 @@ void btc_mesh_generic_client_call_handler(btc_msg_t *msg)
common.ctx.send_ttl = params->ctx.send_ttl;
common.msg_timeout = params->msg_timeout;
generic_client_cb.params = arg->generic_client_get_state.params;
generic_client_cb.error_code =
bt_mesh_generic_client_get_state(&common,
(void *)arg->generic_client_get_state.get_state,
(void *)&generic_client_cb.status_cb);
if (generic_client_cb.error_code) {
cb.params = arg->generic_client_get_state.params;
cb.error_code = bt_mesh_generic_client_get_state(&common,
(void *)arg->generic_client_get_state.get_state, (void *)&cb.status_cb);
if (cb.error_code) {
/* If send failed, callback error_code to app layer immediately */
btc_mesh_generic_client_callback(&generic_client_cb,
ESP_BLE_MESH_GENERIC_CLIENT_GET_STATE_EVT);
btc_ble_mesh_generic_client_callback(&cb, ESP_BLE_MESH_GENERIC_CLIENT_GET_STATE_EVT);
}
break;
}
@ -487,9 +484,9 @@ void btc_mesh_generic_client_call_handler(btc_msg_t *msg)
params = arg->generic_client_set_state.params;
role_param.model = (struct bt_mesh_model *)params->model;
role_param.role = params->msg_role;
if (bt_mesh_set_model_role(&role_param)) {
if (bt_mesh_set_client_model_role(&role_param)) {
LOG_ERROR("%s, Failed to set model role", __func__);
return;
break;
}
common.opcode = params->opcode;
common.model = (struct bt_mesh_model *)params->model;
@ -500,15 +497,12 @@ void btc_mesh_generic_client_call_handler(btc_msg_t *msg)
common.ctx.send_ttl = params->ctx.send_ttl;
common.msg_timeout = params->msg_timeout;
generic_client_cb.params = arg->generic_client_set_state.params;
generic_client_cb.error_code =
bt_mesh_generic_client_set_state(&common,
(void *)arg->generic_client_set_state.set_state,
(void *)&generic_client_cb.status_cb);
if (generic_client_cb.error_code) {
cb.params = arg->generic_client_set_state.params;
cb.error_code = bt_mesh_generic_client_set_state(&common,
(void *)arg->generic_client_set_state.set_state, (void *)&cb.status_cb);
if (cb.error_code) {
/* If send failed, callback error_code to app layer immediately */
btc_mesh_generic_client_callback(&generic_client_cb,
ESP_BLE_MESH_GENERIC_CLIENT_SET_STATE_EVT);
btc_ble_mesh_generic_client_callback(&cb, ESP_BLE_MESH_GENERIC_CLIENT_SET_STATE_EVT);
}
break;
}
@ -517,9 +511,10 @@ void btc_mesh_generic_client_call_handler(btc_msg_t *msg)
}
btc_ble_mesh_generic_client_arg_deep_free(msg);
return;
}
void btc_mesh_generic_client_cb_handler(btc_msg_t *msg)
void btc_ble_mesh_generic_client_cb_handler(btc_msg_t *msg)
{
esp_ble_mesh_generic_client_cb_param_t *param = NULL;
@ -531,10 +526,11 @@ void btc_mesh_generic_client_cb_handler(btc_msg_t *msg)
param = (esp_ble_mesh_generic_client_cb_param_t *)(msg->arg);
if (msg->act < ESP_BLE_MESH_GENERIC_CLIENT_EVT_MAX) {
btc_ble_mesh_cb_to_app(msg->act, param);
btc_ble_mesh_generic_client_cb_to_app(msg->act, param);
} else {
LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act);
}
btc_ble_mesh_free_req_data(msg);
btc_ble_mesh_generic_client_free_req_data(msg);
return;
}

View File

@ -28,21 +28,15 @@
extern s32_t health_msg_timeout;
/* Health Client Model related functions */
static inline void btc_ble_mesh_health_client_cb_to_app(esp_ble_mesh_health_client_cb_event_t event,
esp_ble_mesh_health_client_cb_param_t *param)
{
esp_ble_mesh_health_client_cb_t btc_mesh_cb = (esp_ble_mesh_health_client_cb_t)btc_profile_cb_get(BTC_PID_HEALTH_CLIENT);
if (btc_mesh_cb) {
btc_mesh_cb(event, param);
}
}
static inline void btc_ble_mesh_health_server_cb_to_app(esp_ble_mesh_health_server_cb_event_t event,
esp_ble_mesh_health_server_cb_param_t *param)
{
esp_ble_mesh_health_server_cb_t btc_mesh_cb = (esp_ble_mesh_health_server_cb_t)btc_profile_cb_get(BTC_PID_HEALTH_SERVER);
if (btc_mesh_cb) {
btc_mesh_cb(event, param);
esp_ble_mesh_health_client_cb_t btc_ble_mesh_cb =
(esp_ble_mesh_health_client_cb_t)btc_profile_cb_get(BTC_PID_HEALTH_CLIENT);
if (btc_ble_mesh_cb) {
btc_ble_mesh_cb(event, param);
}
}
@ -120,45 +114,12 @@ static void btc_ble_mesh_health_client_arg_deep_free(btc_msg_t *msg)
default:
break;
}
return;
}
void btc_ble_mesh_health_server_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
{
if (!msg) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
switch (msg->act) {
case BTC_BLE_MESH_ACT_HEALTH_SERVER_FAULT_UPDATE:
break;
default:
break;
}
}
static void btc_ble_mesh_health_server_arg_deep_free(btc_msg_t *msg)
{
if (!msg) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
switch (msg->act) {
case BTC_BLE_MESH_ACT_HEALTH_SERVER_FAULT_UPDATE:
break;
default:
break;
}
}
static void btc_ble_mesh_health_client_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src)
{
esp_ble_mesh_health_client_cb_param_t *p_dest_data = (esp_ble_mesh_health_client_cb_param_t *)p_dest;
esp_ble_mesh_health_client_cb_param_t *p_src_data = (esp_ble_mesh_health_client_cb_param_t *)p_src;
u32_t opcode;
u16_t length;
if (!msg || !p_src_data || !p_dest_data) {
@ -166,13 +127,22 @@ static void btc_ble_mesh_health_client_copy_req_data(btc_msg_t *msg, void *p_des
return;
}
if (p_src_data->params) {
p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
if (!p_dest_data->params) {
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
return;
}
memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t));
}
switch (msg->act) {
case ESP_BLE_MESH_HEALTH_CLIENT_GET_STATE_EVT:
case ESP_BLE_MESH_HEALTH_CLIENT_SET_STATE_EVT:
case ESP_BLE_MESH_HEALTH_CLIENT_PUBLISH_EVT:
if (p_src_data->params) {
opcode = p_src_data->params->opcode;
switch (opcode) {
switch (p_src_data->params->opcode) {
case OP_HEALTH_CURRENT_STATUS:
if (p_src_data->status_cb.current_status.fault_array) {
length = p_src_data->status_cb.current_status.fault_array->len;
@ -207,14 +177,6 @@ static void btc_ble_mesh_health_client_copy_req_data(btc_msg_t *msg, void *p_des
}
}
case ESP_BLE_MESH_HEALTH_CLIENT_TIMEOUT_EVT:
if (p_src_data->params) {
p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
if (p_dest_data->params) {
memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t));
} else {
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
}
}
break;
default:
break;
@ -224,7 +186,6 @@ static void btc_ble_mesh_health_client_copy_req_data(btc_msg_t *msg, void *p_des
static void btc_ble_mesh_health_client_free_req_data(btc_msg_t *msg)
{
esp_ble_mesh_health_client_cb_param_t *arg = NULL;
u32_t opcode;
if (!msg || !msg->arg) {
LOG_ERROR("%s, Invalid parameter", __func__);
@ -238,8 +199,7 @@ static void btc_ble_mesh_health_client_free_req_data(btc_msg_t *msg)
case ESP_BLE_MESH_HEALTH_CLIENT_SET_STATE_EVT:
case ESP_BLE_MESH_HEALTH_CLIENT_PUBLISH_EVT:
if (arg->params) {
opcode = arg->params->opcode;
switch (opcode) {
switch (arg->params->opcode) {
case OP_HEALTH_CURRENT_STATUS:
bt_mesh_free_buf(arg->status_cb.current_status.fault_array);
break;
@ -263,6 +223,292 @@ static void btc_ble_mesh_health_client_free_req_data(btc_msg_t *msg)
}
}
static void btc_ble_mesh_health_client_callback(esp_ble_mesh_health_client_cb_param_t *cb_params, uint8_t act)
{
btc_msg_t msg = {0};
LOG_DEBUG("%s", __func__);
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_HEALTH_CLIENT;
msg.act = act;
btc_transfer_context(&msg, cb_params,
sizeof(esp_ble_mesh_health_client_cb_param_t), btc_ble_mesh_health_client_copy_req_data);
}
void bt_mesh_health_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
const u8_t *val, u16_t len)
{
esp_ble_mesh_health_client_cb_param_t cb_params = {0};
esp_ble_mesh_client_common_param_t params = {0};
size_t length;
uint8_t act;
if (!model || !ctx) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
switch (evt_type) {
case BTC_BLE_MESH_EVT_HEALTH_CLIENT_GET_STATE:
act = ESP_BLE_MESH_HEALTH_CLIENT_GET_STATE_EVT;
break;
case BTC_BLE_MESH_EVT_HEALTH_CLIENT_SET_STATE:
act = ESP_BLE_MESH_HEALTH_CLIENT_SET_STATE_EVT;
break;
case BTC_BLE_MESH_EVT_HEALTH_CLIENT_PUBLISH:
act = ESP_BLE_MESH_HEALTH_CLIENT_PUBLISH_EVT;
break;
case BTC_BLE_MESH_EVT_HEALTH_CLIENT_TIMEOUT:
act = ESP_BLE_MESH_HEALTH_CLIENT_TIMEOUT_EVT;
break;
default:
LOG_ERROR("%s, Unknown health client event type %d", __func__, evt_type);
return;
}
params.opcode = opcode;
params.model = (esp_ble_mesh_model_t *)model;
params.ctx.net_idx = ctx->net_idx;
params.ctx.app_idx = ctx->app_idx;
params.ctx.addr = ctx->addr;
params.ctx.recv_ttl = ctx->recv_ttl;
params.ctx.recv_op = ctx->recv_op;
params.ctx.recv_dst = ctx->recv_dst;
cb_params.error_code = 0;
cb_params.params = &params;
if (val && len) {
length = (len <= sizeof(cb_params.status_cb)) ? len : sizeof(cb_params.status_cb);
memcpy(&cb_params.status_cb, val, length);
}
btc_ble_mesh_health_client_callback(&cb_params, act);
return;
}
void btc_ble_mesh_health_publish_callback(u32_t opcode,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
if (!model || !ctx || !buf) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
bt_mesh_health_client_cb_evt_to_btc(opcode,
BTC_BLE_MESH_EVT_HEALTH_CLIENT_PUBLISH, model, ctx, buf->data, buf->len);
return;
}
static int btc_ble_mesh_health_client_get_state(esp_ble_mesh_client_common_param_t *params,
esp_ble_mesh_health_client_get_state_t *get,
esp_ble_mesh_health_client_cb_param_t *cb)
{
struct bt_mesh_msg_ctx ctx = {0};
if (!params || !cb) {
LOG_ERROR("%s, Invalid parameter", __func__);
return -EINVAL;
}
ctx.net_idx = params->ctx.net_idx;
ctx.app_idx = params->ctx.app_idx;
ctx.addr = params->ctx.addr;
ctx.send_rel = params->ctx.send_rel;
ctx.send_ttl = params->ctx.send_ttl;
health_msg_timeout = params->msg_timeout;
switch (params->opcode) {
case ESP_BLE_MESH_MODEL_OP_ATTENTION_GET:
return (cb->error_code = bt_mesh_health_attention_get(&ctx));
case ESP_BLE_MESH_MODEL_OP_HEALTH_PERIOD_GET:
return (cb->error_code = bt_mesh_health_period_get(&ctx));
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_GET:
return (cb->error_code = bt_mesh_health_fault_get(&ctx, get->fault_get.company_id));
default:
LOG_ERROR("%s, Invalid opcode 0x%x", __func__, params->opcode);
return (cb->error_code = -EINVAL);
}
return 0;
}
static int btc_ble_mesh_health_client_set_state(esp_ble_mesh_client_common_param_t *params,
esp_ble_mesh_health_client_set_state_t *set,
esp_ble_mesh_health_client_cb_param_t *cb)
{
struct bt_mesh_msg_ctx ctx = {0};
if (!params || !set || !cb) {
LOG_ERROR("%s, Invalid parameter", __func__);
return -EINVAL;
}
ctx.net_idx = params->ctx.net_idx;
ctx.app_idx = params->ctx.app_idx;
ctx.addr = params->ctx.addr;
ctx.send_rel = params->ctx.send_rel;
ctx.send_ttl = params->ctx.send_ttl;
health_msg_timeout = params->msg_timeout;
switch (params->opcode) {
case ESP_BLE_MESH_MODEL_OP_ATTENTION_SET:
return (cb->error_code =
bt_mesh_health_attention_set(&ctx, set->attention_set.attention, true));
case ESP_BLE_MESH_MODEL_OP_ATTENTION_SET_UNACK:
return (cb->error_code =
bt_mesh_health_attention_set(&ctx, set->attention_set.attention, false));
case ESP_BLE_MESH_MODEL_OP_HEALTH_PERIOD_SET:
return (cb->error_code =
bt_mesh_health_period_set(&ctx, set->period_set.fast_period_divisor, true));
case ESP_BLE_MESH_MODEL_OP_HEALTH_PERIOD_SET_UNACK:
return (cb->error_code =
bt_mesh_health_period_set(&ctx, set->period_set.fast_period_divisor, false));
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_TEST:
return (cb->error_code =
bt_mesh_health_fault_test(&ctx, set->fault_test.company_id, set->fault_test.test_id, true));
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_TEST_UNACK:
return (cb->error_code =
bt_mesh_health_fault_test(&ctx, set->fault_test.company_id, set->fault_test.test_id, false));
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_CLEAR:
return (cb->error_code =
bt_mesh_health_fault_clear(&ctx, set->fault_clear.company_id, true));
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_CLEAR_UNACK:
return (cb->error_code =
bt_mesh_health_fault_clear(&ctx, set->fault_clear.company_id, false));
default:
LOG_ERROR("%s, Invalid opcode 0x%x", __func__, params->opcode);
return (cb->error_code = -EINVAL);
}
return 0;
}
void btc_ble_mesh_health_client_call_handler(btc_msg_t *msg)
{
btc_ble_mesh_health_client_args_t *arg = NULL;
esp_ble_mesh_health_client_cb_param_t cb = {0};
bt_mesh_role_param_t role_param = {0};
if (!msg || !msg->arg) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
arg = (btc_ble_mesh_health_client_args_t *)(msg->arg);
switch (msg->act) {
case BTC_BLE_MESH_ACT_HEALTH_CLIENT_GET_STATE: {
cb.params = arg->health_client_get_state.params;
role_param.model = (struct bt_mesh_model *)cb.params->model;
role_param.role = cb.params->msg_role;
if (bt_mesh_set_client_model_role(&role_param)) {
LOG_ERROR("%s, Failed to set model role", __func__);
break;
}
btc_ble_mesh_health_client_get_state(arg->health_client_get_state.params,
arg->health_client_get_state.get_state, &cb);
if (cb.error_code) {
/* If send failed, callback error_code to app layer immediately */
btc_ble_mesh_health_client_callback(&cb, ESP_BLE_MESH_HEALTH_CLIENT_GET_STATE_EVT);
}
break;
}
case BTC_BLE_MESH_ACT_HEALTH_CLIENT_SET_STATE: {
cb.params = arg->health_client_set_state.params;
role_param.model = (struct bt_mesh_model *)cb.params->model;
role_param.role = cb.params->msg_role;
if (bt_mesh_set_client_model_role(&role_param)) {
LOG_ERROR("%s, Failed to set model role", __func__);
break;
}
btc_ble_mesh_health_client_set_state(arg->health_client_set_state.params,
arg->health_client_set_state.set_state, &cb);
if (cb.error_code) {
/* If send failed, callback error_code to app layer immediately */
btc_ble_mesh_health_client_callback(&cb, ESP_BLE_MESH_HEALTH_CLIENT_SET_STATE_EVT);
}
break;
}
default:
break;
}
btc_ble_mesh_health_client_arg_deep_free(msg);
return;
}
void btc_ble_mesh_health_client_cb_handler(btc_msg_t *msg)
{
esp_ble_mesh_health_client_cb_param_t *param = NULL;
if (!msg || !msg->arg) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
param = (esp_ble_mesh_health_client_cb_param_t *)(msg->arg);
if (msg->act < ESP_BLE_MESH_HEALTH_CLIENT_EVT_MAX) {
btc_ble_mesh_health_client_cb_to_app(msg->act, param);
} else {
LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act);
}
btc_ble_mesh_health_client_free_req_data(msg);
return;
}
/* Health Server Model related functions */
static inline void btc_ble_mesh_health_server_cb_to_app(esp_ble_mesh_health_server_cb_event_t event,
esp_ble_mesh_health_server_cb_param_t *param)
{
esp_ble_mesh_health_server_cb_t btc_ble_mesh_cb =
(esp_ble_mesh_health_server_cb_t)btc_profile_cb_get(BTC_PID_HEALTH_SERVER);
if (btc_ble_mesh_cb) {
btc_ble_mesh_cb(event, param);
}
}
void btc_ble_mesh_health_server_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
{
if (!msg) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
switch (msg->act) {
case BTC_BLE_MESH_ACT_HEALTH_SERVER_FAULT_UPDATE:
break;
default:
break;
}
}
static void btc_ble_mesh_health_server_arg_deep_free(btc_msg_t *msg)
{
if (!msg) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
switch (msg->act) {
case BTC_BLE_MESH_ACT_HEALTH_SERVER_FAULT_UPDATE:
break;
default:
break;
}
}
static void btc_ble_mesh_health_server_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src)
{
if (!msg) {
@ -293,21 +539,7 @@ static void btc_ble_mesh_health_server_free_req_data(btc_msg_t *msg)
}
}
static void btc_mesh_health_client_callback(esp_ble_mesh_health_client_cb_param_t *cb_params, uint8_t act)
{
btc_msg_t msg = {0};
LOG_DEBUG("%s", __func__);
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_HEALTH_CLIENT;
msg.act = act;
btc_transfer_context(&msg, cb_params,
sizeof(esp_ble_mesh_health_client_cb_param_t), btc_ble_mesh_health_client_copy_req_data);
}
static void btc_mesh_health_server_callback(esp_ble_mesh_health_server_cb_param_t *cb_params, uint8_t act)
static void btc_ble_mesh_health_server_callback(esp_ble_mesh_health_server_cb_param_t *cb_params, uint8_t act)
{
btc_msg_t msg = {0};
@ -318,236 +550,10 @@ static void btc_mesh_health_server_callback(esp_ble_mesh_health_server_cb_param_
msg.act = act;
btc_transfer_context(&msg, cb_params,
sizeof(esp_ble_mesh_health_server_cb_param_t), btc_ble_mesh_health_server_copy_req_data);
sizeof(esp_ble_mesh_health_server_cb_param_t), btc_ble_mesh_health_server_copy_req_data);
}
int btc_ble_mesh_health_client_get_state(esp_ble_mesh_client_common_param_t *params,
esp_ble_mesh_health_client_get_state_t *get_state,
esp_ble_mesh_health_client_cb_param_t *client_cb)
{
struct bt_mesh_msg_ctx ctx = {0};
if (!params || !client_cb) {
LOG_ERROR("%s, Invalid parameter", __func__);
return -EINVAL;
}
ctx.net_idx = params->ctx.net_idx;
ctx.app_idx = params->ctx.app_idx;
ctx.addr = params->ctx.addr;
ctx.send_rel = params->ctx.send_rel;
ctx.send_ttl = params->ctx.send_ttl;
health_msg_timeout = params->msg_timeout;
switch (params->opcode) {
case ESP_BLE_MESH_MODEL_OP_ATTENTION_GET:
return (client_cb->error_code = bt_mesh_health_attention_get(&ctx));
case ESP_BLE_MESH_MODEL_OP_HEALTH_PERIOD_GET:
return (client_cb->error_code = bt_mesh_health_period_get(&ctx));
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_GET:
return (client_cb->error_code = bt_mesh_health_fault_get(&ctx, get_state->fault_get.company_id));
default:
BT_WARN("%s, invalid opcode 0x%x", __func__, params->opcode);
return (client_cb->error_code = -EINVAL);
}
return 0;
}
int btc_ble_mesh_health_client_set_state(esp_ble_mesh_client_common_param_t *params,
esp_ble_mesh_health_client_set_state_t *set_state,
esp_ble_mesh_health_client_cb_param_t *client_cb)
{
struct bt_mesh_msg_ctx ctx = {0};
if (!params || !set_state || !client_cb) {
LOG_ERROR("%s, Invalid parameter", __func__);
return -EINVAL;
}
ctx.net_idx = params->ctx.net_idx;
ctx.app_idx = params->ctx.app_idx;
ctx.addr = params->ctx.addr;
ctx.send_rel = params->ctx.send_rel;
ctx.send_ttl = params->ctx.send_ttl;
health_msg_timeout = params->msg_timeout;
switch (params->opcode) {
case ESP_BLE_MESH_MODEL_OP_ATTENTION_SET:
return (client_cb->error_code =
bt_mesh_health_attention_set(&ctx, set_state->attention_set.attention, true));
case ESP_BLE_MESH_MODEL_OP_ATTENTION_SET_UNACK:
return (client_cb->error_code =
bt_mesh_health_attention_set(&ctx, set_state->attention_set.attention, false));
case ESP_BLE_MESH_MODEL_OP_HEALTH_PERIOD_SET:
return (client_cb->error_code =
bt_mesh_health_period_set(&ctx, set_state->period_set.fast_period_divisor, true));
case ESP_BLE_MESH_MODEL_OP_HEALTH_PERIOD_SET_UNACK:
return (client_cb->error_code =
bt_mesh_health_period_set(&ctx, set_state->period_set.fast_period_divisor, false));
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_TEST:
return (client_cb->error_code =
bt_mesh_health_fault_test(&ctx, set_state->fault_test.company_id, set_state->fault_test.test_id, true));
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_TEST_UNACK:
return (client_cb->error_code =
bt_mesh_health_fault_test(&ctx, set_state->fault_test.company_id, set_state->fault_test.test_id, false));
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_CLEAR:
return (client_cb->error_code =
bt_mesh_health_fault_clear(&ctx, set_state->fault_clear.company_id, true));
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_CLEAR_UNACK:
return (client_cb->error_code =
bt_mesh_health_fault_clear(&ctx, set_state->fault_clear.company_id, false));
default:
BT_WARN("%s, Invalid opcode 0x%x", __func__, params->opcode);
return (client_cb->error_code = -EINVAL);
}
return 0;
}
void bt_mesh_callback_health_status_to_btc(u32_t opcode, u8_t evt_type,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
const u8_t *val, u16_t len)
{
esp_ble_mesh_health_client_cb_param_t cb_params = {0};
esp_ble_mesh_client_common_param_t params = {0};
size_t length;
uint8_t act;
if (!model || !ctx) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
switch (evt_type) {
case 0x00:
act = ESP_BLE_MESH_HEALTH_CLIENT_GET_STATE_EVT;
break;
case 0x01:
act = ESP_BLE_MESH_HEALTH_CLIENT_SET_STATE_EVT;
break;
case 0x02:
act = ESP_BLE_MESH_HEALTH_CLIENT_PUBLISH_EVT;
break;
case 0x03:
act = ESP_BLE_MESH_HEALTH_CLIENT_TIMEOUT_EVT;
break;
default:
LOG_ERROR("%s, Unknown health client event type %d", __func__, evt_type);
return;
}
params.opcode = opcode;
params.model = (esp_ble_mesh_model_t *)model;
params.ctx.net_idx = ctx->net_idx;
params.ctx.app_idx = ctx->app_idx;
params.ctx.addr = ctx->addr;
params.ctx.recv_ttl = ctx->recv_ttl;
params.ctx.recv_op = ctx->recv_op;
params.ctx.recv_dst = ctx->recv_dst;
cb_params.error_code = 0;
cb_params.params = &params;
if (val && len) {
length = (len <= sizeof(cb_params.status_cb)) ? len : sizeof(cb_params.status_cb);
memcpy(&cb_params.status_cb, val, length);
}
btc_mesh_health_client_callback(&cb_params, act);
}
void btc_mesh_health_publish_callback(u32_t opcode, struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf)
{
if (!model || !ctx || !buf) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
bt_mesh_callback_health_status_to_btc(opcode, 0x02, model, ctx, buf->data, buf->len);
}
void btc_mesh_health_client_call_handler(btc_msg_t *msg)
{
btc_ble_mesh_health_client_args_t *arg = NULL;
esp_ble_mesh_health_client_cb_param_t health_client_cb = {0};
bt_mesh_role_param_t role_param = {0};
if (!msg || !msg->arg) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
arg = (btc_ble_mesh_health_client_args_t *)(msg->arg);
switch (msg->act) {
case BTC_BLE_MESH_ACT_HEALTH_CLIENT_GET_STATE: {
health_client_cb.params = arg->health_client_get_state.params;
role_param.model = (struct bt_mesh_model *)health_client_cb.params->model;
role_param.role = health_client_cb.params->msg_role;
if (bt_mesh_set_model_role(&role_param)) {
LOG_ERROR("%s, Failed to set model role", __func__);
return;
}
btc_ble_mesh_health_client_get_state(arg->health_client_get_state.params,
arg->health_client_get_state.get_state,
&health_client_cb);
if (health_client_cb.error_code) {
/* If send failed, callback error_code to app layer immediately */
btc_mesh_health_client_callback(&health_client_cb, ESP_BLE_MESH_HEALTH_CLIENT_GET_STATE_EVT);
}
break;
}
case BTC_BLE_MESH_ACT_HEALTH_CLIENT_SET_STATE: {
health_client_cb.params = arg->health_client_set_state.params;
role_param.model = (struct bt_mesh_model *)health_client_cb.params->model;
role_param.role = health_client_cb.params->msg_role;
if (bt_mesh_set_model_role(&role_param)) {
LOG_ERROR("%s, Failed to set model role", __func__);
return;
}
btc_ble_mesh_health_client_set_state(arg->health_client_set_state.params,
arg->health_client_set_state.set_state,
&health_client_cb);
if (health_client_cb.error_code) {
/* If send failed, callback error_code to app layer immediately */
btc_mesh_health_client_callback(&health_client_cb, ESP_BLE_MESH_HEALTH_CLIENT_SET_STATE_EVT);
}
break;
}
default:
break;
}
btc_ble_mesh_health_client_arg_deep_free(msg);
return;
}
void btc_mesh_health_client_cb_handler(btc_msg_t *msg)
{
esp_ble_mesh_health_client_cb_param_t *param = NULL;
if (!msg || !msg->arg) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
param = (esp_ble_mesh_health_client_cb_param_t *)(msg->arg);
if (msg->act < ESP_BLE_MESH_HEALTH_CLIENT_EVT_MAX) {
btc_ble_mesh_health_client_cb_to_app(msg->act, param);
} else {
LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act);
}
btc_ble_mesh_health_client_free_req_data(msg);
}
void btc_mesh_health_server_call_handler(btc_msg_t *msg)
void btc_ble_mesh_health_server_call_handler(btc_msg_t *msg)
{
esp_ble_mesh_health_server_cb_param_t health_server_cb = {0};
btc_ble_mesh_health_server_args_t *arg = NULL;
@ -560,18 +566,21 @@ void btc_mesh_health_server_call_handler(btc_msg_t *msg)
arg = (btc_ble_mesh_health_server_args_t *)(msg->arg);
switch (msg->act) {
case BTC_BLE_MESH_ACT_HEALTH_SERVER_FAULT_UPDATE: {
health_server_cb.error_code = bt_mesh_fault_update((struct bt_mesh_elem *)arg->fault_update.element);
btc_mesh_health_server_callback(&health_server_cb, ESP_BLE_MESH_HEALTH_SERVER_FAULT_UPDATE_COMPLETE_EVT);
}
case BTC_BLE_MESH_ACT_HEALTH_SERVER_FAULT_UPDATE:
health_server_cb.error_code =
bt_mesh_fault_update((struct bt_mesh_elem *)arg->fault_update.element);
btc_ble_mesh_health_server_callback(
&health_server_cb, ESP_BLE_MESH_HEALTH_SERVER_FAULT_UPDATE_COMPLETE_EVT);
break;
default:
break;
}
btc_ble_mesh_health_server_arg_deep_free(msg);
return;
}
void btc_mesh_health_server_cb_handler(btc_msg_t *msg)
void btc_ble_mesh_health_server_cb_handler(btc_msg_t *msg)
{
esp_ble_mesh_health_server_cb_param_t *param = NULL;
@ -589,4 +598,5 @@ void btc_mesh_health_server_cb_handler(btc_msg_t *msg)
}
btc_ble_mesh_health_server_free_req_data(msg);
return;
}

View File

@ -22,19 +22,22 @@
#include "btc_ble_mesh_lighting_model.h"
#include "esp_ble_mesh_lighting_model_api.h"
static inline void btc_ble_mesh_cb_to_app(esp_ble_mesh_light_client_cb_event_t event,
/* Lighting Client Models related functions */
static inline void btc_ble_mesh_lighting_client_cb_to_app(esp_ble_mesh_light_client_cb_event_t event,
esp_ble_mesh_light_client_cb_param_t *param)
{
esp_ble_mesh_light_client_cb_t btc_mesh_cb = (esp_ble_mesh_light_client_cb_t)btc_profile_cb_get(BTC_PID_LIGHT_CLIENT);
if (btc_mesh_cb) {
btc_mesh_cb(event, param);
esp_ble_mesh_light_client_cb_t btc_ble_mesh_cb =
(esp_ble_mesh_light_client_cb_t)btc_profile_cb_get(BTC_PID_LIGHTING_CLIENT);
if (btc_ble_mesh_cb) {
btc_ble_mesh_cb(event, param);
}
}
void btc_ble_mesh_light_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
void btc_ble_mesh_lighting_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
{
btc_ble_mesh_light_client_args_t *dst = (btc_ble_mesh_light_client_args_t *)p_dest;
btc_ble_mesh_light_client_args_t *src = (btc_ble_mesh_light_client_args_t *)p_src;
btc_ble_mesh_lighting_client_args_t *dst = (btc_ble_mesh_lighting_client_args_t *)p_dest;
btc_ble_mesh_lighting_client_args_t *src = (btc_ble_mesh_lighting_client_args_t *)p_src;
if (!msg || !dst || !src) {
LOG_ERROR("%s, Invalid parameter", __func__);
@ -42,7 +45,7 @@ void btc_ble_mesh_light_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void
}
switch (msg->act) {
case BTC_BLE_MESH_ACT_LIGHT_CLIENT_GET_STATE: {
case BTC_BLE_MESH_ACT_LIGHTING_CLIENT_GET_STATE: {
dst->light_client_get_state.params = (esp_ble_mesh_client_common_param_t *)osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
dst->light_client_get_state.get_state = (esp_ble_mesh_light_client_get_state_t *)osi_malloc(sizeof(esp_ble_mesh_light_client_get_state_t));
if (dst->light_client_get_state.params && dst->light_client_get_state.get_state) {
@ -55,7 +58,7 @@ void btc_ble_mesh_light_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void
}
break;
}
case BTC_BLE_MESH_ACT_LIGHT_CLIENT_SET_STATE: {
case BTC_BLE_MESH_ACT_LIGHTING_CLIENT_SET_STATE: {
dst->light_client_set_state.params = (esp_ble_mesh_client_common_param_t *)osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
dst->light_client_set_state.set_state = (esp_ble_mesh_light_client_set_state_t *)osi_malloc(sizeof(esp_ble_mesh_light_client_set_state_t));
if (dst->light_client_set_state.params && dst->light_client_set_state.set_state) {
@ -74,11 +77,43 @@ void btc_ble_mesh_light_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void
}
}
static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src)
static void btc_ble_mesh_lighting_client_arg_deep_free(btc_msg_t *msg)
{
btc_ble_mesh_lighting_client_args_t *arg = NULL;
if (!msg || !msg->arg) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
arg = (btc_ble_mesh_lighting_client_args_t *)(msg->arg);
switch (msg->act) {
case BTC_BLE_MESH_ACT_LIGHTING_CLIENT_GET_STATE:
if (arg->light_client_get_state.params) {
osi_free(arg->light_client_get_state.params);
}
if (arg->light_client_get_state.get_state) {
osi_free(arg->light_client_get_state.get_state);
}
break;
case BTC_BLE_MESH_ACT_LIGHTING_CLIENT_SET_STATE:
if (arg->light_client_set_state.params) {
osi_free(arg->light_client_set_state.params);
}
if (arg->light_client_set_state.set_state) {
osi_free(arg->light_client_set_state.set_state);
}
break;
default:
break;
}
}
static void btc_ble_mesh_lighting_client_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src)
{
esp_ble_mesh_light_client_cb_param_t *p_dest_data = (esp_ble_mesh_light_client_cb_param_t *)p_dest;
esp_ble_mesh_light_client_cb_param_t *p_src_data = (esp_ble_mesh_light_client_cb_param_t *)p_src;
u32_t opcode;
u16_t length;
if (!msg || !p_src_data || !p_dest_data) {
@ -86,13 +121,22 @@ static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src
return;
}
if (p_src_data->params) {
p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
if (!p_dest_data->params) {
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
return;
}
memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t));
}
switch (msg->act) {
case ESP_BLE_MESH_LIGHT_CLIENT_GET_STATE_EVT:
case ESP_BLE_MESH_LIGHT_CLIENT_SET_STATE_EVT:
case ESP_BLE_MESH_LIGHT_CLIENT_PUBLISH_EVT:
if (p_src_data->params) {
opcode = p_src_data->params->opcode;
switch (opcode) {
switch (p_src_data->params->opcode) {
case ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_GET:
case ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET:
case ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_STATUS:
@ -113,24 +157,15 @@ static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src
}
}
case ESP_BLE_MESH_LIGHT_CLIENT_TIMEOUT_EVT:
if (p_src_data->params) {
p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
if (p_dest_data->params) {
memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t));
} else {
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
}
}
break;
default:
break;
}
}
static void btc_ble_mesh_free_req_data(btc_msg_t *msg)
static void btc_ble_mesh_lighting_client_free_req_data(btc_msg_t *msg)
{
esp_ble_mesh_light_client_cb_param_t *arg = NULL;
u32_t opcode;
if (!msg || !msg->arg) {
LOG_ERROR("%s, Invalid parameter", __func__);
@ -144,8 +179,7 @@ static void btc_ble_mesh_free_req_data(btc_msg_t *msg)
case ESP_BLE_MESH_LIGHT_CLIENT_SET_STATE_EVT:
case ESP_BLE_MESH_LIGHT_CLIENT_PUBLISH_EVT:
if (arg->params) {
opcode = arg->params->opcode;
switch (opcode) {
switch (arg->params->opcode) {
case ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_GET:
case ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET:
case ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_STATUS:
@ -165,56 +199,21 @@ static void btc_ble_mesh_free_req_data(btc_msg_t *msg)
}
}
void btc_ble_mesh_light_client_arg_deep_free(btc_msg_t *msg)
{
btc_ble_mesh_light_client_args_t *arg = NULL;
if (!msg || !msg->arg) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
arg = (btc_ble_mesh_light_client_args_t *)(msg->arg);
switch (msg->act) {
case BTC_BLE_MESH_ACT_LIGHT_CLIENT_GET_STATE:
if (arg->light_client_get_state.params) {
osi_free(arg->light_client_get_state.params);
}
if (arg->light_client_get_state.get_state) {
osi_free(arg->light_client_get_state.get_state);
}
break;
case BTC_BLE_MESH_ACT_LIGHT_CLIENT_SET_STATE:
if (arg->light_client_set_state.params) {
osi_free(arg->light_client_set_state.params);
}
if (arg->light_client_set_state.set_state) {
osi_free(arg->light_client_set_state.set_state);
}
break;
default:
break;
}
return;
}
static void btc_mesh_light_client_callback(esp_ble_mesh_light_client_cb_param_t *cb_params, uint8_t act)
static void btc_ble_mesh_lighting_client_callback(esp_ble_mesh_light_client_cb_param_t *cb_params, uint8_t act)
{
btc_msg_t msg = {0};
LOG_DEBUG("%s", __func__);
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_LIGHT_CLIENT;
msg.pid = BTC_PID_LIGHTING_CLIENT;
msg.act = act;
btc_transfer_context(&msg, cb_params,
sizeof(esp_ble_mesh_light_client_cb_param_t), btc_ble_mesh_copy_req_data);
sizeof(esp_ble_mesh_light_client_cb_param_t), btc_ble_mesh_lighting_client_copy_req_data);
}
void bt_mesh_callback_light_status_to_btc(u32_t opcode, u8_t evt_type,
void bt_mesh_lighting_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
const u8_t *val, size_t len)
@ -230,16 +229,16 @@ void bt_mesh_callback_light_status_to_btc(u32_t opcode, u8_t evt_type,
}
switch (evt_type) {
case 0x00:
case BTC_BLE_MESH_EVT_LIGHTING_CLIENT_GET_STATE:
act = ESP_BLE_MESH_LIGHT_CLIENT_GET_STATE_EVT;
break;
case 0x01:
case BTC_BLE_MESH_EVT_LIGHTING_CLIENT_SET_STATE:
act = ESP_BLE_MESH_LIGHT_CLIENT_SET_STATE_EVT;
break;
case 0x02:
case BTC_BLE_MESH_EVT_LIGHTING_CLIENT_PUBLISH:
act = ESP_BLE_MESH_LIGHT_CLIENT_PUBLISH_EVT;
break;
case 0x03:
case BTC_BLE_MESH_EVT_LIGHTING_CLIENT_TIMEOUT:
act = ESP_BLE_MESH_LIGHT_CLIENT_TIMEOUT_EVT;
break;
default:
@ -264,26 +263,31 @@ void bt_mesh_callback_light_status_to_btc(u32_t opcode, u8_t evt_type,
memcpy(&cb_params.status_cb, val, length);
}
btc_mesh_light_client_callback(&cb_params, act);
btc_ble_mesh_lighting_client_callback(&cb_params, act);
return;
}
void btc_mesh_light_client_publish_callback(u32_t opcode, struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf)
void btc_ble_mesh_lighting_client_publish_callback(u32_t opcode,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
if (!model || !ctx || !buf) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
bt_mesh_callback_light_status_to_btc(opcode, 0x02, model, ctx, buf->data, buf->len);
bt_mesh_lighting_client_cb_evt_to_btc(opcode,
BTC_BLE_MESH_EVT_LIGHTING_CLIENT_PUBLISH, model, ctx, buf->data, buf->len);
return;
}
void btc_mesh_light_client_call_handler(btc_msg_t *msg)
void btc_ble_mesh_lighting_client_call_handler(btc_msg_t *msg)
{
esp_ble_mesh_light_client_cb_param_t light_client_cb = {0};
esp_ble_mesh_client_common_param_t *params = NULL;
btc_ble_mesh_light_client_args_t *arg = NULL;
struct bt_mesh_common_param common = {0};
btc_ble_mesh_lighting_client_args_t *arg = NULL;
esp_ble_mesh_light_client_cb_param_t cb = {0};
bt_mesh_client_common_param_t common = {0};
bt_mesh_role_param_t role_param = {0};
if (!msg || !msg->arg) {
@ -291,16 +295,16 @@ void btc_mesh_light_client_call_handler(btc_msg_t *msg)
return;
}
arg = (btc_ble_mesh_light_client_args_t *)(msg->arg);
arg = (btc_ble_mesh_lighting_client_args_t *)(msg->arg);
switch (msg->act) {
case BTC_BLE_MESH_ACT_LIGHT_CLIENT_GET_STATE: {
case BTC_BLE_MESH_ACT_LIGHTING_CLIENT_GET_STATE: {
params = arg->light_client_get_state.params;
role_param.model = (struct bt_mesh_model *)params->model;
role_param.role = params->msg_role;
if (bt_mesh_set_model_role(&role_param)) {
if (bt_mesh_set_client_model_role(&role_param)) {
LOG_ERROR("%s, Failed to set model role", __func__);
return;
break;
}
common.opcode = params->opcode;
common.model = (struct bt_mesh_model *)params->model;
@ -311,25 +315,22 @@ void btc_mesh_light_client_call_handler(btc_msg_t *msg)
common.ctx.send_ttl = params->ctx.send_ttl;
common.msg_timeout = params->msg_timeout;
light_client_cb.params = arg->light_client_get_state.params;
light_client_cb.error_code =
bt_mesh_light_client_get_state(&common,
(void *)arg->light_client_get_state.get_state,
(void *)&light_client_cb.status_cb);
if (light_client_cb.error_code) {
cb.params = arg->light_client_get_state.params;
cb.error_code = bt_mesh_light_client_get_state(&common,
(void *)arg->light_client_get_state.get_state, (void *)&cb.status_cb);
if (cb.error_code) {
/* If send failed, callback error_code to app layer immediately */
btc_mesh_light_client_callback(&light_client_cb,
ESP_BLE_MESH_LIGHT_CLIENT_GET_STATE_EVT);
btc_ble_mesh_lighting_client_callback(&cb, ESP_BLE_MESH_LIGHT_CLIENT_GET_STATE_EVT);
}
break;
}
case BTC_BLE_MESH_ACT_LIGHT_CLIENT_SET_STATE: {
case BTC_BLE_MESH_ACT_LIGHTING_CLIENT_SET_STATE: {
params = arg->light_client_set_state.params;
role_param.model = (struct bt_mesh_model *)params->model;
role_param.role = params->msg_role;
if (bt_mesh_set_model_role(&role_param)) {
if (bt_mesh_set_client_model_role(&role_param)) {
LOG_ERROR("%s, Failed to set model role", __func__);
return;
break;
}
common.opcode = params->opcode;
common.model = (struct bt_mesh_model *)params->model;
@ -340,15 +341,12 @@ void btc_mesh_light_client_call_handler(btc_msg_t *msg)
common.ctx.send_ttl = params->ctx.send_ttl;
common.msg_timeout = params->msg_timeout;
light_client_cb.params = arg->light_client_set_state.params;
light_client_cb.error_code =
bt_mesh_light_client_set_state(&common,
(void *)arg->light_client_set_state.set_state,
(void *)&light_client_cb.status_cb);
if (light_client_cb.error_code) {
cb.params = arg->light_client_set_state.params;
cb.error_code = bt_mesh_light_client_set_state(&common,
(void *)arg->light_client_set_state.set_state, (void *)&cb.status_cb);
if (cb.error_code) {
/* If send failed, callback error_code to app layer immediately */
btc_mesh_light_client_callback(&light_client_cb,
ESP_BLE_MESH_LIGHT_CLIENT_SET_STATE_EVT);
btc_ble_mesh_lighting_client_callback(&cb, ESP_BLE_MESH_LIGHT_CLIENT_SET_STATE_EVT);
}
break;
}
@ -356,10 +354,11 @@ void btc_mesh_light_client_call_handler(btc_msg_t *msg)
break;
}
btc_ble_mesh_light_client_arg_deep_free(msg);
btc_ble_mesh_lighting_client_arg_deep_free(msg);
return;
}
void btc_mesh_light_client_cb_handler(btc_msg_t *msg)
void btc_ble_mesh_lighting_client_cb_handler(btc_msg_t *msg)
{
esp_ble_mesh_light_client_cb_param_t *param = NULL;
@ -371,11 +370,12 @@ void btc_mesh_light_client_cb_handler(btc_msg_t *msg)
param = (esp_ble_mesh_light_client_cb_param_t *)(msg->arg);
if (msg->act < ESP_BLE_MESH_LIGHT_CLIENT_EVT_MAX) {
btc_ble_mesh_cb_to_app(msg->act, param);
btc_ble_mesh_lighting_client_cb_to_app(msg->act, param);
} else {
LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act);
}
btc_ble_mesh_free_req_data(msg);
btc_ble_mesh_lighting_client_free_req_data(msg);
return;
}

View File

@ -44,7 +44,7 @@
#include "lighting_client.h"
#include "sensor_client.h"
#include "time_scene_client.h"
#include "model_common.h"
#include "client_common.h"
#include "btc_ble_mesh_prov.h"
#include "btc_ble_mesh_config_model.h"
@ -59,7 +59,25 @@
#include "esp_ble_mesh_provisioning_api.h"
#include "esp_ble_mesh_networking_api.h"
#define BLE_MESH_MAX_DATA_SIZE 379
static inline void btc_ble_mesh_prov_cb_to_app(esp_ble_mesh_prov_cb_event_t event,
esp_ble_mesh_prov_cb_param_t *param)
{
esp_ble_mesh_prov_cb_t btc_ble_mesh_cb =
(esp_ble_mesh_prov_cb_t)btc_profile_cb_get(BTC_PID_PROV);
if (btc_ble_mesh_cb) {
btc_ble_mesh_cb(event, param);
}
}
static inline void btc_ble_mesh_model_cb_to_app(esp_ble_mesh_model_cb_event_t event,
esp_ble_mesh_model_cb_param_t *param)
{
esp_ble_mesh_model_cb_t btc_ble_mesh_cb =
(esp_ble_mesh_model_cb_t)btc_profile_cb_get(BTC_PID_MODEL);
if (btc_ble_mesh_cb) {
btc_ble_mesh_cb(event, param);
}
}
void btc_ble_mesh_prov_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
{
@ -97,7 +115,7 @@ void btc_ble_mesh_prov_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
}
}
void btc_ble_mesh_prov_arg_deep_free(btc_msg_t *msg)
static void btc_ble_mesh_prov_arg_deep_free(btc_msg_t *msg)
{
btc_ble_mesh_model_args_t *arg = NULL;
@ -125,7 +143,7 @@ void btc_ble_mesh_prov_arg_deep_free(btc_msg_t *msg)
return;
}
static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src)
static void btc_ble_mesh_model_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src)
{
esp_ble_mesh_model_cb_param_t *p_dest_data = (esp_ble_mesh_model_cb_param_t *)p_dest;
esp_ble_mesh_model_cb_param_t *p_src_data = (esp_ble_mesh_model_cb_param_t *)p_src;
@ -201,7 +219,7 @@ static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src
}
}
static void btc_ble_mesh_free_req_data(btc_msg_t *msg)
static void btc_ble_mesh_model_free_req_data(btc_msg_t *msg)
{
esp_ble_mesh_model_cb_param_t *arg = NULL;
@ -248,26 +266,6 @@ static void btc_ble_mesh_free_req_data(btc_msg_t *msg)
}
}
static inline void btc_ble_mesh_cb_to_app(esp_ble_mesh_prov_cb_event_t event,
esp_ble_mesh_prov_cb_param_t *param)
{
esp_ble_mesh_prov_cb_t btc_mesh_cb = (esp_ble_mesh_prov_cb_t)btc_profile_cb_get(BTC_PID_PROV);
if (btc_mesh_cb) {
btc_mesh_cb(event, param);
}
}
static inline void btc_ble_mesh_model_cb_to_app(esp_ble_mesh_model_cb_event_t event,
esp_ble_mesh_model_cb_param_t *param)
{
esp_ble_mesh_model_cb_t btc_mesh_cb = (esp_ble_mesh_model_cb_t)btc_profile_cb_get(BTC_PID_MODEL);
if (btc_mesh_cb) {
btc_mesh_cb(event, param);
}
}
extern u32_t mesh_opcode;
static void btc_ble_mesh_server_model_op_cb(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
@ -276,7 +274,7 @@ static void btc_ble_mesh_server_model_op_cb(struct bt_mesh_model *model,
btc_msg_t msg = {0};
bt_status_t ret;
mesh_param.model_operation.opcode = mesh_opcode;
mesh_param.model_operation.opcode = ctx->recv_op;
mesh_param.model_operation.model = (esp_ble_mesh_model_t *)model;
mesh_param.model_operation.ctx = (esp_ble_mesh_msg_ctx_t *)ctx;
mesh_param.model_operation.length = buf->len;
@ -286,7 +284,7 @@ static void btc_ble_mesh_server_model_op_cb(struct bt_mesh_model *model,
msg.pid = BTC_PID_MODEL;
msg.act = ESP_BLE_MESH_MODEL_OPERATION_EVT;
ret = btc_transfer_context(&msg, &mesh_param,
sizeof(esp_ble_mesh_model_cb_param_t), btc_ble_mesh_copy_req_data);
sizeof(esp_ble_mesh_model_cb_param_t), btc_ble_mesh_model_copy_req_data);
if (ret != BT_STATUS_SUCCESS) {
LOG_ERROR("%s btc_transfer_context failed", __func__);
@ -299,8 +297,6 @@ static void btc_ble_mesh_client_model_op_cb(struct bt_mesh_model *model,
struct net_buf_simple *buf)
{
esp_ble_mesh_model_cb_param_t mesh_param = {0};
bt_mesh_client_common_t *client_param = NULL;
bt_mesh_internal_data_t *data = NULL;
bt_mesh_client_node_t *node = NULL;
btc_msg_t msg = {0};
bt_status_t ret;
@ -310,38 +306,39 @@ static void btc_ble_mesh_client_model_op_cb(struct bt_mesh_model *model,
return;
}
client_param = (bt_mesh_client_common_t *)model->user_data;
data = (bt_mesh_internal_data_t *)client_param->internal_data;
if (!data) {
LOG_ERROR("%s, Client internal_data is NULL", __func__);
return;
}
bt_mesh_client_model_lock();
node = bt_mesh_is_model_message_publish(model, ctx, buf, false);
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_MODEL;
node = bt_mesh_is_client_recv_publish_msg(model, ctx, buf, false);
if (node == NULL) {
msg.act = ESP_BLE_MESH_CLIENT_MODEL_RECV_PUBLISH_MSG_EVT;
mesh_param.client_recv_publish_msg.opcode = mesh_opcode;
mesh_param.client_recv_publish_msg.opcode = ctx->recv_op;
mesh_param.client_recv_publish_msg.model = (esp_ble_mesh_model_t *)model;
mesh_param.client_recv_publish_msg.ctx = (esp_ble_mesh_msg_ctx_t *)ctx;
mesh_param.client_recv_publish_msg.length = buf->len;
mesh_param.client_recv_publish_msg.msg = buf->data;
ret = btc_transfer_context(&msg, &mesh_param,
sizeof(esp_ble_mesh_model_cb_param_t), btc_ble_mesh_model_copy_req_data);
} else {
msg.act = ESP_BLE_MESH_MODEL_OPERATION_EVT;
mesh_param.model_operation.opcode = mesh_opcode;
mesh_param.model_operation.opcode = ctx->recv_op;
mesh_param.model_operation.model = (esp_ble_mesh_model_t *)model;
mesh_param.model_operation.ctx = (esp_ble_mesh_msg_ctx_t *)ctx;
mesh_param.model_operation.length = buf->len;
mesh_param.model_operation.msg = buf->data;
if (!k_delayed_work_free(&node->timer)) {
ret = btc_transfer_context(&msg, &mesh_param,
sizeof(esp_ble_mesh_model_cb_param_t), btc_ble_mesh_model_copy_req_data);
// Don't forget to release the node at the end.
bt_mesh_client_free_node(node);
} else {
ret = BT_STATUS_SUCCESS;
}
}
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_MODEL;
if (msg.act != ESP_BLE_MESH_CLIENT_MODEL_RECV_PUBLISH_MSG_EVT) {
// Don't forget to release the node at the end.
bt_mesh_client_free_node(&data->queue, node);
}
ret = btc_transfer_context(&msg, &mesh_param,
sizeof(esp_ble_mesh_model_cb_param_t), btc_ble_mesh_copy_req_data);
bt_mesh_client_model_unlock();
if (ret != BT_STATUS_SUCCESS) {
LOG_ERROR("%s, btc_transfer_context failed", __func__);
@ -364,7 +361,7 @@ static void btc_ble_mesh_model_send_comp_cb(esp_ble_mesh_model_t *model, esp_ble
msg.pid = BTC_PID_MODEL;
msg.act = ESP_BLE_MESH_MODEL_SEND_COMP_EVT;
ret = btc_transfer_context(&msg, &mesh_param,
sizeof(esp_ble_mesh_model_cb_param_t), btc_ble_mesh_copy_req_data);
sizeof(esp_ble_mesh_model_cb_param_t), btc_ble_mesh_model_copy_req_data);
if (ret != BT_STATUS_SUCCESS) {
LOG_ERROR("%s btc_transfer_context failed", __func__);
@ -393,8 +390,8 @@ static void btc_ble_mesh_model_publish_comp_cb(esp_ble_mesh_model_t *model, int
return;
}
#if defined(CONFIG_BLE_MESH_NODE)
static void btc_oob_pub_key_cb(void)
#if CONFIG_BLE_MESH_NODE
static void btc_ble_mesh_oob_pub_key_cb(void)
{
btc_msg_t msg = {0};
@ -410,7 +407,7 @@ static void btc_oob_pub_key_cb(void)
return;
}
static int btc_output_number_cb(bt_mesh_output_action_t act, u32_t num)
static int btc_ble_mesh_output_number_cb(bt_mesh_output_action_t act, u32_t num)
{
esp_ble_mesh_prov_cb_param_t mesh_param = {0};
btc_msg_t msg = {0};
@ -434,7 +431,7 @@ static int btc_output_number_cb(bt_mesh_output_action_t act, u32_t num)
return 0;
}
static int btc_output_string_cb(const char *str)
static int btc_ble_mesh_output_string_cb(const char *str)
{
esp_ble_mesh_prov_cb_param_t mesh_param = {0};
btc_msg_t msg = {0};
@ -457,7 +454,7 @@ static int btc_output_string_cb(const char *str)
return 0;
}
static int btc_input_cb(bt_mesh_input_action_t act, u8_t size)
static int btc_ble_mesh_input_cb(bt_mesh_input_action_t act, u8_t size)
{
esp_ble_mesh_prov_cb_param_t mesh_param = {0};
btc_msg_t msg = {0};
@ -481,7 +478,7 @@ static int btc_input_cb(bt_mesh_input_action_t act, u8_t size)
return 0;
}
static void btc_link_open_cb(bt_mesh_prov_bearer_t bearer)
static void btc_ble_mesh_link_open_cb(bt_mesh_prov_bearer_t bearer)
{
esp_ble_mesh_prov_cb_param_t mesh_param = {0};
btc_msg_t msg = {0};
@ -503,7 +500,7 @@ static void btc_link_open_cb(bt_mesh_prov_bearer_t bearer)
return;
}
static void btc_link_close_cb(bt_mesh_prov_bearer_t bearer)
static void btc_ble_mesh_link_close_cb(bt_mesh_prov_bearer_t bearer)
{
esp_ble_mesh_prov_cb_param_t mesh_param = {0};
btc_msg_t msg = {0};
@ -525,7 +522,7 @@ static void btc_link_close_cb(bt_mesh_prov_bearer_t bearer)
return;
}
static void btc_complete_cb(u16_t net_idx, u16_t addr, u8_t flags, u32_t iv_index)
static void btc_ble_mesh_complete_cb(u16_t net_idx, u16_t addr, u8_t flags, u32_t iv_index)
{
esp_ble_mesh_prov_cb_param_t mesh_param = {0};
btc_msg_t msg = {0};
@ -550,7 +547,7 @@ static void btc_complete_cb(u16_t net_idx, u16_t addr, u8_t flags, u32_t iv_inde
return;
}
static void btc_reset_cb(void)
static void btc_ble_mesh_reset_cb(void)
{
btc_msg_t msg = {0};
bt_status_t ret;
@ -567,9 +564,9 @@ static void btc_reset_cb(void)
}
return;
}
#endif /* defined(CONFIG_BLE_MESH_NODE) */
#endif /* CONFIG_BLE_MESH_NODE */
static void btc_prov_register_complete_cb(int err_code)
static void btc_ble_mesh_prov_register_complete_cb(int err_code)
{
esp_ble_mesh_prov_cb_param_t mesh_param = {0};
btc_msg_t msg = {0};
@ -591,47 +588,46 @@ static void btc_prov_register_complete_cb(int err_code)
return;
}
static void btc_client_model_timeout_cb(struct k_work *work)
static void btc_ble_mesh_client_model_timeout_cb(struct k_work *work)
{
esp_ble_mesh_model_cb_param_t mesh_param = {0};
bt_mesh_client_common_t *client_param = NULL;
bt_mesh_internal_data_t *data = NULL;
struct k_delayed_work *timer = NULL;
bt_mesh_client_node_t *node = NULL;
btc_msg_t msg = {0};
bt_status_t ret;
node = CONTAINER_OF(work, bt_mesh_client_node_t, timer.work);
if (!node || !node->ctx.model || !node->ctx.model->user_data) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
bt_mesh_client_model_lock();
timer = CONTAINER_OF(work, struct k_delayed_work, work);
if (timer && !k_delayed_work_free(timer)) {
node = CONTAINER_OF(work, bt_mesh_client_node_t, timer.work);
if (node) {
mesh_param.client_send_timeout.opcode = node->opcode;
mesh_param.client_send_timeout.model = (esp_ble_mesh_model_t *)node->ctx.model;
mesh_param.client_send_timeout.ctx = (esp_ble_mesh_msg_ctx_t *)&node->ctx;
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_MODEL;
msg.act = ESP_BLE_MESH_CLIENT_MODEL_SEND_TIMEOUT_EVT;
ret = btc_transfer_context(&msg, &mesh_param,
sizeof(esp_ble_mesh_model_cb_param_t), btc_ble_mesh_model_copy_req_data);
if (ret != BT_STATUS_SUCCESS) {
LOG_ERROR("%s btc_transfer_context failed", __func__);
}
// Don't forget to release the node at the end.
bt_mesh_client_free_node(node);
}
}
client_param = (bt_mesh_client_common_t *)node->ctx.model->user_data;
data = (bt_mesh_internal_data_t *)client_param->internal_data;
if (!data) {
LOG_ERROR("%s, Client internal_data is NULL", __func__);
return;
}
bt_mesh_client_model_unlock();
mesh_param.client_send_timeout.opcode = node->opcode;
mesh_param.client_send_timeout.model = (esp_ble_mesh_model_t *)node->ctx.model;
mesh_param.client_send_timeout.ctx = (esp_ble_mesh_msg_ctx_t *)&node->ctx;
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_MODEL;
msg.act = ESP_BLE_MESH_CLIENT_MODEL_SEND_TIMEOUT_EVT;
ret = btc_transfer_context(&msg, &mesh_param,
sizeof(esp_ble_mesh_model_cb_param_t), btc_ble_mesh_copy_req_data);
if (ret != BT_STATUS_SUCCESS) {
LOG_ERROR("%s btc_transfer_context failed", __func__);
}
// Don't forget to release the node at the end.
bt_mesh_client_free_node(&data->queue, node);
return;
}
static int btc_model_publish_update(struct bt_mesh_model *mod)
static int btc_ble_mesh_model_publish_update(struct bt_mesh_model *mod)
{
esp_ble_mesh_model_cb_param_t mesh_param = {0};
btc_msg_t msg = {0};
@ -654,7 +650,7 @@ static int btc_model_publish_update(struct bt_mesh_model *mod)
return 0;
}
static void btc_prov_set_complete_cb(esp_ble_mesh_prov_cb_param_t *param, uint8_t act)
static void btc_ble_mesh_prov_set_complete_cb(esp_ble_mesh_prov_cb_param_t *param, uint8_t act)
{
btc_msg_t msg = {0};
bt_status_t ret;
@ -673,8 +669,9 @@ static void btc_prov_set_complete_cb(esp_ble_mesh_prov_cb_param_t *param, uint8_
return;
}
#if (CONFIG_BLE_MESH_PROVISIONER)
static void btc_provisioner_recv_unprov_adv_pkt_cb(const u8_t addr[6], const u8_t addr_type,
#if CONFIG_BLE_MESH_PROVISIONER
static void btc_ble_mesh_provisioner_recv_unprov_adv_pkt_cb(
const u8_t addr[6], const u8_t addr_type,
const u8_t adv_type, const u8_t dev_uuid[16],
u16_t oob_info, bt_mesh_prov_bearer_t bearer)
{
@ -709,7 +706,7 @@ static void btc_provisioner_recv_unprov_adv_pkt_cb(const u8_t addr[6], const u8_
return;
}
static int btc_provisioner_prov_read_oob_pub_key_cb(u8_t link_idx)
static int btc_ble_mesh_provisioner_prov_read_oob_pub_key_cb(u8_t link_idx)
{
esp_ble_mesh_prov_cb_param_t mesh_param = {0};
btc_msg_t msg = {0};
@ -732,7 +729,8 @@ static int btc_provisioner_prov_read_oob_pub_key_cb(u8_t link_idx)
return 0;
}
static int btc_provisioner_prov_input_cb(u8_t method, bt_mesh_output_action_t act, u8_t size, u8_t link_idx)
static int btc_ble_mesh_provisioner_prov_input_cb(u8_t method,
bt_mesh_output_action_t act, u8_t size, u8_t link_idx)
{
esp_ble_mesh_prov_cb_param_t mesh_param = {0};
btc_msg_t msg = {0};
@ -758,7 +756,8 @@ static int btc_provisioner_prov_input_cb(u8_t method, bt_mesh_output_action_t ac
return 0;
}
static int btc_provisioner_prov_output_cb(u8_t method, bt_mesh_input_action_t act, void *data, u8_t size, u8_t link_idx)
static int btc_ble_mesh_provisioner_prov_output_cb(u8_t method,
bt_mesh_input_action_t act, void *data, u8_t size, u8_t link_idx)
{
esp_ble_mesh_prov_cb_param_t mesh_param = {0};
btc_msg_t msg = {0};
@ -789,7 +788,7 @@ static int btc_provisioner_prov_output_cb(u8_t method, bt_mesh_input_action_t ac
return 0;
}
static void btc_provisioner_link_open_cb(bt_mesh_prov_bearer_t bearer)
static void btc_ble_mesh_provisioner_link_open_cb(bt_mesh_prov_bearer_t bearer)
{
esp_ble_mesh_prov_cb_param_t mesh_param = {0};
btc_msg_t msg = {0};
@ -811,7 +810,7 @@ static void btc_provisioner_link_open_cb(bt_mesh_prov_bearer_t bearer)
return;
}
static void btc_provisioner_link_close_cb(bt_mesh_prov_bearer_t bearer, u8_t reason)
static void btc_ble_mesh_provisioner_link_close_cb(bt_mesh_prov_bearer_t bearer, u8_t reason)
{
esp_ble_mesh_prov_cb_param_t mesh_param = {0};
btc_msg_t msg = {0};
@ -834,7 +833,8 @@ static void btc_provisioner_link_close_cb(bt_mesh_prov_bearer_t bearer, u8_t rea
return;
}
static void btc_provisioner_prov_complete_cb(int node_idx, const u8_t device_uuid[16],
static void btc_ble_mesh_provisioner_prov_complete_cb(
int node_idx, const u8_t device_uuid[16],
u16_t unicast_addr, u8_t element_num,
u16_t netkey_idx)
{
@ -863,7 +863,7 @@ static void btc_provisioner_prov_complete_cb(int node_idx, const u8_t device_uui
}
#endif /* CONFIG_BLE_MESH_PROVISIONER */
int btc_ble_mesh_client_init(esp_ble_mesh_model_t *model)
int btc_ble_mesh_client_model_init(esp_ble_mesh_model_t *model)
{
__ASSERT(model && model->op, "%s, Invalid parameter", __func__);
esp_ble_mesh_model_op_t *op = model->op;
@ -943,7 +943,7 @@ extern const struct bt_mesh_model_op time_cli_op[];
extern const struct bt_mesh_model_op scene_cli_op[];
extern const struct bt_mesh_model_op scheduler_cli_op[];
static void btc_mesh_model_op_add(esp_ble_mesh_model_t *model)
static void btc_ble_mesh_model_op_add(esp_ble_mesh_model_t *model)
{
esp_ble_mesh_model_op_t *op = NULL;
@ -968,7 +968,7 @@ static void btc_mesh_model_op_add(esp_ble_mesh_model_t *model)
model->op = (esp_ble_mesh_model_op_t *)bt_mesh_cfg_cli_op;
bt_mesh_config_client_t *cli = (bt_mesh_config_client_t *)model->user_data;
if (cli != NULL) {
cli->publish_status = btc_mesh_cfg_client_publish_callback;
cli->publish_status = btc_ble_mesh_config_client_publish_callback;
}
break;
}
@ -980,111 +980,111 @@ static void btc_mesh_model_op_add(esp_ble_mesh_model_t *model)
model->op = (esp_ble_mesh_model_op_t *)bt_mesh_health_cli_op;
bt_mesh_health_client_t *cli = (bt_mesh_health_client_t *)model->user_data;
if (cli != NULL) {
cli->publish_status = btc_mesh_health_publish_callback;
cli->publish_status = btc_ble_mesh_health_publish_callback;
}
break;
}
case BLE_MESH_MODEL_ID_GEN_ONOFF_CLI: {
model->op = ((esp_ble_mesh_model_op_t *)gen_onoff_cli_op);
bt_mesh_gen_onoff_cli_t *cli = (bt_mesh_gen_onoff_cli_t *)model->user_data;
bt_mesh_gen_onoff_client_t *cli = (bt_mesh_gen_onoff_client_t *)model->user_data;
if (cli != NULL) {
cli->publish_status = btc_mesh_generic_client_publish_callback;
cli->publish_status = btc_ble_mesh_generic_client_publish_callback;
}
break;
}
case BLE_MESH_MODEL_ID_GEN_LEVEL_CLI: {
model->op = ((esp_ble_mesh_model_op_t *)gen_level_cli_op);
bt_mesh_gen_level_cli_t *cli = (bt_mesh_gen_level_cli_t *)model->user_data;
bt_mesh_gen_level_client_t *cli = (bt_mesh_gen_level_client_t *)model->user_data;
if (cli != NULL) {
cli->publish_status = btc_mesh_generic_client_publish_callback;
cli->publish_status = btc_ble_mesh_generic_client_publish_callback;
}
break;
}
case BLE_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_CLI: {
model->op = ((esp_ble_mesh_model_op_t *)gen_def_trans_time_cli_op);
bt_mesh_gen_def_trans_time_cli_t *cli = (bt_mesh_gen_def_trans_time_cli_t *)model->user_data;
bt_mesh_gen_def_trans_time_client_t *cli = (bt_mesh_gen_def_trans_time_client_t *)model->user_data;
if (cli != NULL) {
cli->publish_status = btc_mesh_generic_client_publish_callback;
cli->publish_status = btc_ble_mesh_generic_client_publish_callback;
}
break;
}
case BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_CLI: {
model->op = ((esp_ble_mesh_model_op_t *)gen_power_onoff_cli_op);
bt_mesh_gen_power_onoff_cli_t *cli = (bt_mesh_gen_power_onoff_cli_t *)model->user_data;
bt_mesh_gen_power_onoff_client_t *cli = (bt_mesh_gen_power_onoff_client_t *)model->user_data;
if (cli != NULL) {
cli->publish_status = btc_mesh_generic_client_publish_callback;
cli->publish_status = btc_ble_mesh_generic_client_publish_callback;
}
break;
}
case BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_CLI: {
model->op = ((esp_ble_mesh_model_op_t *)gen_power_level_cli_op);
bt_mesh_gen_power_level_cli_t *cli = (bt_mesh_gen_power_level_cli_t *)model->user_data;
bt_mesh_gen_power_level_client_t *cli = (bt_mesh_gen_power_level_client_t *)model->user_data;
if (cli != NULL) {
cli->publish_status = btc_mesh_generic_client_publish_callback;
cli->publish_status = btc_ble_mesh_generic_client_publish_callback;
}
break;
}
case BLE_MESH_MODEL_ID_GEN_BATTERY_CLI: {
model->op = ((esp_ble_mesh_model_op_t *)gen_battery_cli_op);
bt_mesh_gen_battery_cli_t *cli = (bt_mesh_gen_battery_cli_t *)model->user_data;
bt_mesh_gen_battery_client_t *cli = (bt_mesh_gen_battery_client_t *)model->user_data;
if (cli != NULL) {
cli->publish_status = btc_mesh_generic_client_publish_callback;
cli->publish_status = btc_ble_mesh_generic_client_publish_callback;
}
break;
}
case BLE_MESH_MODEL_ID_GEN_LOCATION_CLI: {
model->op = ((esp_ble_mesh_model_op_t *)gen_location_cli_op);
bt_mesh_gen_location_cli_t *cli = (bt_mesh_gen_location_cli_t *)model->user_data;
bt_mesh_gen_location_client_t *cli = (bt_mesh_gen_location_client_t *)model->user_data;
if (cli != NULL) {
cli->publish_status = btc_mesh_generic_client_publish_callback;
cli->publish_status = btc_ble_mesh_generic_client_publish_callback;
}
break;
}
case BLE_MESH_MODEL_ID_GEN_PROP_CLI: {
model->op = ((esp_ble_mesh_model_op_t *)gen_property_cli_op);
bt_mesh_gen_property_cli_t *cli = (bt_mesh_gen_property_cli_t *)model->user_data;
bt_mesh_gen_property_client_t *cli = (bt_mesh_gen_property_client_t *)model->user_data;
if (cli != NULL) {
cli->publish_status = btc_mesh_generic_client_publish_callback;
cli->publish_status = btc_ble_mesh_generic_client_publish_callback;
}
break;
}
case BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_CLI: {
model->op = ((esp_ble_mesh_model_op_t *)light_lightness_cli_op);
bt_mesh_light_lightness_cli_t *cli = (bt_mesh_light_lightness_cli_t *)model->user_data;
bt_mesh_light_lightness_client_t *cli = (bt_mesh_light_lightness_client_t *)model->user_data;
if (cli != NULL) {
cli->publish_status = btc_mesh_light_client_publish_callback;
cli->publish_status = btc_ble_mesh_lighting_client_publish_callback;
}
break;
}
case BLE_MESH_MODEL_ID_LIGHT_CTL_CLI: {
model->op = ((esp_ble_mesh_model_op_t *)light_ctl_cli_op);
bt_mesh_light_ctl_cli_t *cli = (bt_mesh_light_ctl_cli_t *)model->user_data;
bt_mesh_light_ctl_client_t *cli = (bt_mesh_light_ctl_client_t *)model->user_data;
if (cli != NULL) {
cli->publish_status = btc_mesh_light_client_publish_callback;
cli->publish_status = btc_ble_mesh_lighting_client_publish_callback;
}
break;
}
case BLE_MESH_MODEL_ID_LIGHT_HSL_CLI: {
model->op = ((esp_ble_mesh_model_op_t *)light_hsl_cli_op);
bt_mesh_light_hsl_cli_t *cli = (bt_mesh_light_hsl_cli_t *)model->user_data;
bt_mesh_light_hsl_client_t *cli = (bt_mesh_light_hsl_client_t *)model->user_data;
if (cli != NULL) {
cli->publish_status = btc_mesh_light_client_publish_callback;
cli->publish_status = btc_ble_mesh_lighting_client_publish_callback;
}
break;
}
case BLE_MESH_MODEL_ID_LIGHT_XYL_CLI: {
model->op = ((esp_ble_mesh_model_op_t *)light_xyl_cli_op);
bt_mesh_light_xyl_cli_t *cli = (bt_mesh_light_xyl_cli_t *)model->user_data;
bt_mesh_light_xyl_client_t *cli = (bt_mesh_light_xyl_client_t *)model->user_data;
if (cli != NULL) {
cli->publish_status = btc_mesh_light_client_publish_callback;
cli->publish_status = btc_ble_mesh_lighting_client_publish_callback;
}
break;
}
case BLE_MESH_MODEL_ID_LIGHT_LC_CLI: {
model->op = ((esp_ble_mesh_model_op_t *)light_lc_cli_op);
bt_mesh_light_lc_cli_t *cli = (bt_mesh_light_lc_cli_t *)model->user_data;
bt_mesh_light_lc_client_t *cli = (bt_mesh_light_lc_client_t *)model->user_data;
if (cli != NULL) {
cli->publish_status = btc_mesh_light_client_publish_callback;
cli->publish_status = btc_ble_mesh_lighting_client_publish_callback;
}
break;
}
@ -1092,31 +1092,31 @@ static void btc_mesh_model_op_add(esp_ble_mesh_model_t *model)
model->op = ((esp_ble_mesh_model_op_t *)sensor_cli_op);
bt_mesh_sensor_client_t *cli = (bt_mesh_sensor_client_t *)model->user_data;
if (cli != NULL) {
cli->publish_status = btc_mesh_sensor_client_publish_callback;
cli->publish_status = btc_ble_mesh_sensor_client_publish_callback;
}
break;
}
case BLE_MESH_MODEL_ID_TIME_CLI: {
model->op = ((esp_ble_mesh_model_op_t *)time_cli_op);
bt_mesh_time_scene_client_t *cli = (bt_mesh_time_scene_client_t *)model->user_data;
bt_mesh_time_client_t *cli = (bt_mesh_time_client_t *)model->user_data;
if (cli != NULL) {
cli->publish_status = btc_mesh_time_scene_client_publish_callback;
cli->publish_status = btc_ble_mesh_time_scene_client_publish_callback;
}
break;
}
case BLE_MESH_MODEL_ID_SCENE_CLI: {
model->op = ((esp_ble_mesh_model_op_t *)scene_cli_op);
bt_mesh_time_scene_client_t *cli = (bt_mesh_time_scene_client_t *)model->user_data;
bt_mesh_scene_client_t *cli = (bt_mesh_scene_client_t *)model->user_data;
if (cli != NULL) {
cli->publish_status = btc_mesh_time_scene_client_publish_callback;
cli->publish_status = btc_ble_mesh_time_scene_client_publish_callback;
}
break;
}
case BLE_MESH_MODEL_ID_SCHEDULER_CLI: {
model->op = ((esp_ble_mesh_model_op_t *)scheduler_cli_op);
bt_mesh_time_scene_client_t *cli = (bt_mesh_time_scene_client_t *)model->user_data;
bt_mesh_scheduler_client_t *cli = (bt_mesh_scheduler_client_t *)model->user_data;
if (cli != NULL) {
cli->publish_status = btc_mesh_time_scene_client_publish_callback;
cli->publish_status = btc_ble_mesh_time_scene_client_publish_callback;
}
break;
}
@ -1128,7 +1128,7 @@ static void btc_mesh_model_op_add(esp_ble_mesh_model_t *model)
add_model_op:
if (model->pub) {
model->pub->update = (esp_ble_mesh_cb_t)btc_model_publish_update;
model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update;
}
op = model->op;
while (op != NULL && op->opcode != 0) {
@ -1138,7 +1138,7 @@ add_model_op:
return;
}
void btc_mesh_prov_call_handler(btc_msg_t *msg)
void btc_ble_mesh_prov_call_handler(btc_msg_t *msg)
{
esp_ble_mesh_prov_cb_param_t param = {0};
btc_ble_mesh_prov_args_t *arg = NULL;
@ -1161,10 +1161,10 @@ void btc_mesh_prov_call_handler(btc_msg_t *msg)
/* The opcode of sig model should be 1 or 2 bytes. */
if (sig_model && sig_model->op && (sig_model->op->opcode >= 0x10000)) {
err_code = -EINVAL;
btc_prov_register_complete_cb(err_code);
btc_ble_mesh_prov_register_complete_cb(err_code);
return;
}
btc_mesh_model_op_add(sig_model);
btc_ble_mesh_model_op_add(sig_model);
}
/* For vendor models */
for (int k = 0; k < elem->vnd_model_count; k++) {
@ -1172,36 +1172,36 @@ void btc_mesh_prov_call_handler(btc_msg_t *msg)
/* The opcode of vendor model should be 3 bytes. */
if (vnd_model && vnd_model->op && vnd_model->op->opcode < 0x10000) {
err_code = -EINVAL;
btc_prov_register_complete_cb(err_code);
btc_ble_mesh_prov_register_complete_cb(err_code);
return;
}
btc_mesh_model_op_add(vnd_model);
btc_ble_mesh_model_op_add(vnd_model);
}
}
#if CONFIG_BLE_MESH_NODE
arg->mesh_init.prov->oob_pub_key_cb = (esp_ble_mesh_cb_t)btc_oob_pub_key_cb;
arg->mesh_init.prov->output_num_cb = (esp_ble_mesh_cb_t)btc_output_number_cb;
arg->mesh_init.prov->output_str_cb = (esp_ble_mesh_cb_t)btc_output_string_cb;
arg->mesh_init.prov->input_cb = (esp_ble_mesh_cb_t)btc_input_cb;
arg->mesh_init.prov->link_open_cb = (esp_ble_mesh_cb_t)btc_link_open_cb;
arg->mesh_init.prov->link_close_cb = (esp_ble_mesh_cb_t)btc_link_close_cb;
arg->mesh_init.prov->complete_cb = (esp_ble_mesh_cb_t)btc_complete_cb;
arg->mesh_init.prov->reset_cb = (esp_ble_mesh_cb_t)btc_reset_cb;
arg->mesh_init.prov->oob_pub_key_cb = (esp_ble_mesh_cb_t)btc_ble_mesh_oob_pub_key_cb;
arg->mesh_init.prov->output_num_cb = (esp_ble_mesh_cb_t)btc_ble_mesh_output_number_cb;
arg->mesh_init.prov->output_str_cb = (esp_ble_mesh_cb_t)btc_ble_mesh_output_string_cb;
arg->mesh_init.prov->input_cb = (esp_ble_mesh_cb_t)btc_ble_mesh_input_cb;
arg->mesh_init.prov->link_open_cb = (esp_ble_mesh_cb_t)btc_ble_mesh_link_open_cb;
arg->mesh_init.prov->link_close_cb = (esp_ble_mesh_cb_t)btc_ble_mesh_link_close_cb;
arg->mesh_init.prov->complete_cb = (esp_ble_mesh_cb_t)btc_ble_mesh_complete_cb;
arg->mesh_init.prov->reset_cb = (esp_ble_mesh_cb_t)btc_ble_mesh_reset_cb;
#endif /* CONFIG_BLE_MESH_NODE */
#if (CONFIG_BLE_MESH_PROVISIONER)
arg->mesh_init.prov->provisioner_prov_read_oob_pub_key = (esp_ble_mesh_cb_t)btc_provisioner_prov_read_oob_pub_key_cb;
arg->mesh_init.prov->provisioner_prov_input = (esp_ble_mesh_cb_t)btc_provisioner_prov_input_cb;
arg->mesh_init.prov->provisioner_prov_output = (esp_ble_mesh_cb_t)btc_provisioner_prov_output_cb;
arg->mesh_init.prov->provisioner_link_open = (esp_ble_mesh_cb_t)btc_provisioner_link_open_cb;
arg->mesh_init.prov->provisioner_link_close = (esp_ble_mesh_cb_t)btc_provisioner_link_close_cb;
arg->mesh_init.prov->provisioner_prov_comp = (esp_ble_mesh_cb_t)btc_provisioner_prov_complete_cb;
bt_mesh_prov_adv_pkt_cb_register(btc_provisioner_recv_unprov_adv_pkt_cb);
#if CONFIG_BLE_MESH_PROVISIONER
arg->mesh_init.prov->provisioner_prov_read_oob_pub_key = (esp_ble_mesh_cb_t)btc_ble_mesh_provisioner_prov_read_oob_pub_key_cb;
arg->mesh_init.prov->provisioner_prov_input = (esp_ble_mesh_cb_t)btc_ble_mesh_provisioner_prov_input_cb;
arg->mesh_init.prov->provisioner_prov_output = (esp_ble_mesh_cb_t)btc_ble_mesh_provisioner_prov_output_cb;
arg->mesh_init.prov->provisioner_link_open = (esp_ble_mesh_cb_t)btc_ble_mesh_provisioner_link_open_cb;
arg->mesh_init.prov->provisioner_link_close = (esp_ble_mesh_cb_t)btc_ble_mesh_provisioner_link_close_cb;
arg->mesh_init.prov->provisioner_prov_comp = (esp_ble_mesh_cb_t)btc_ble_mesh_provisioner_prov_complete_cb;
bt_mesh_prov_adv_pkt_cb_register(btc_ble_mesh_provisioner_recv_unprov_adv_pkt_cb);
#endif /* CONFIG_BLE_MESH_PROVISIONER */
err_code = bt_mesh_init((struct bt_mesh_prov *)arg->mesh_init.prov,
(struct bt_mesh_comp *)arg->mesh_init.comp);
/* Give the semaphore when BLE Mesh initialization is finished. */
xSemaphoreGive(arg->mesh_init.semaphore);
btc_prov_register_complete_cb(err_code);
btc_ble_mesh_prov_register_complete_cb(err_code);
return;
}
#if CONFIG_BLE_MESH_NODE
@ -1253,7 +1253,7 @@ void btc_mesh_prov_call_handler(btc_msg_t *msg)
break;
#endif /* CONFIG_BLE_MESH_GATT_PROXY */
#endif /* CONFIG_BLE_MESH_NODE */
#if (CONFIG_BLE_MESH_PROVISIONER)
#if CONFIG_BLE_MESH_PROVISIONER
case BTC_BLE_MESH_ACT_PROVISIONER_READ_OOB_PUB_KEY:
act = ESP_BLE_MESH_PROVISIONER_PROV_READ_OOB_PUB_KEY_COMP_EVT;
param.provisioner_prov_read_oob_pub_key_comp.err_code =
@ -1382,7 +1382,7 @@ void btc_mesh_prov_call_handler(btc_msg_t *msg)
break;
}
#endif /* CONFIG_BLE_MESH_PROVISIONER */
#if (CONFIG_BLE_MESH_FAST_PROV)
#if CONFIG_BLE_MESH_FAST_PROV
case BTC_BLE_MESH_ACT_SET_FAST_PROV_INFO:
act = ESP_BLE_MESH_SET_FAST_PROV_INFO_COMP_EVT;
param.set_fast_prov_info_comp.status_unicast =
@ -1402,19 +1402,38 @@ void btc_mesh_prov_call_handler(btc_msg_t *msg)
param.set_fast_prov_action_comp.status_action =
bt_mesh_set_fast_prov_action(arg->set_fast_prov_action.action);
break;
#endif /* (CONFIG_BLE_MESH_FAST_PROV) */
#endif /* CONFIG_BLE_MESH_FAST_PROV */
default:
LOG_WARN("%s, Invalid msg->act %d", __func__, msg->act);
return;
}
btc_prov_set_complete_cb(&param, act);
btc_ble_mesh_prov_set_complete_cb(&param, act);
return;
}
void btc_mesh_model_call_handler(btc_msg_t *msg)
void btc_ble_mesh_prov_cb_handler(btc_msg_t *msg)
{
esp_ble_mesh_prov_cb_param_t *param = NULL;
if (!msg) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
param = (esp_ble_mesh_prov_cb_param_t *)(msg->arg);
if (msg->act < ESP_BLE_MESH_PROV_EVT_MAX) {
btc_ble_mesh_prov_cb_to_app(msg->act, param);
} else {
LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act);
}
}
void btc_ble_mesh_model_call_handler(btc_msg_t *msg)
{
btc_ble_mesh_model_args_t *arg = NULL;
int err;
if (!msg || !msg->arg) {
LOG_ERROR("%s, Invalid parameter", __func__);
@ -1429,12 +1448,12 @@ void btc_mesh_model_call_handler(btc_msg_t *msg)
bt_mesh_role_param_t common = {0};
common.model = (struct bt_mesh_model *)(arg->model_publish.model);
common.role = arg->model_publish.device_role;
if (bt_mesh_set_model_role(&common)) {
if (bt_mesh_set_client_model_role(&common)) {
LOG_ERROR("%s, Failed to set model role", __func__);
return;
break;
}
}
int err = bt_mesh_model_publish((struct bt_mesh_model *)arg->model_publish.model);
err = bt_mesh_model_publish((struct bt_mesh_model *)arg->model_publish.model);
btc_ble_mesh_model_publish_comp_cb(arg->model_publish.model, err);
break;
}
@ -1443,13 +1462,13 @@ void btc_mesh_model_call_handler(btc_msg_t *msg)
struct net_buf_simple *buf = bt_mesh_alloc_buf(arg->model_send.length + 8);
if (!buf) {
LOG_ERROR("%s, Failed to allocate memory", __func__);
return;
break;
}
net_buf_simple_add_mem(buf, arg->model_send.data, arg->model_send.length);
arg->model_send.ctx->srv_send = true;
int err = bt_mesh_model_send((struct bt_mesh_model *)arg->model_send.model,
(struct bt_mesh_msg_ctx *)arg->model_send.ctx,
buf, NULL, NULL);
err = bt_mesh_model_send((struct bt_mesh_model *)arg->model_send.model,
(struct bt_mesh_msg_ctx *)arg->model_send.ctx,
buf, NULL, NULL);
bt_mesh_free_buf(buf);
btc_ble_mesh_model_send_comp_cb(arg->model_send.model, arg->model_send.ctx,
arg->model_send.opcode, err);
@ -1461,21 +1480,21 @@ void btc_mesh_model_call_handler(btc_msg_t *msg)
struct net_buf_simple *buf = bt_mesh_alloc_buf(arg->model_send.length + 8);
if (!buf) {
LOG_ERROR("%s, Failed to allocate memory", __func__);
return;
break;
}
net_buf_simple_add_mem(buf, arg->model_send.data, arg->model_send.length);
arg->model_send.ctx->srv_send = false;
common.model = (struct bt_mesh_model *)(arg->model_send.model);
common.role = arg->model_send.device_role;
if (bt_mesh_set_model_role(&common)) {
if (bt_mesh_set_client_model_role(&common)) {
LOG_ERROR("%s, Failed to set model role", __func__);
return;
break;
}
int err = bt_mesh_client_send_msg((struct bt_mesh_model *)arg->model_send.model,
arg->model_send.opcode,
(struct bt_mesh_msg_ctx *)arg->model_send.ctx, buf,
btc_client_model_timeout_cb, arg->model_send.msg_timeout,
arg->model_send.need_rsp, NULL, NULL);
err = bt_mesh_client_send_msg((struct bt_mesh_model *)arg->model_send.model,
arg->model_send.opcode,
(struct bt_mesh_msg_ctx *)arg->model_send.ctx, buf,
btc_ble_mesh_client_model_timeout_cb, arg->model_send.msg_timeout,
arg->model_send.need_rsp, NULL, NULL);
bt_mesh_free_buf(buf);
btc_ble_mesh_model_send_comp_cb(arg->model_send.model, arg->model_send.ctx,
arg->model_send.opcode, err);
@ -1487,9 +1506,10 @@ void btc_mesh_model_call_handler(btc_msg_t *msg)
}
btc_ble_mesh_prov_arg_deep_free(msg);
return;
}
void btc_mesh_model_cb_handler(btc_msg_t *msg)
void btc_ble_mesh_model_cb_handler(btc_msg_t *msg)
{
esp_ble_mesh_model_cb_param_t *param = NULL;
@ -1506,23 +1526,6 @@ void btc_mesh_model_cb_handler(btc_msg_t *msg)
LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act);
}
btc_ble_mesh_free_req_data(msg);
}
void btc_mesh_prov_cb_handler(btc_msg_t *msg)
{
esp_ble_mesh_prov_cb_param_t *param = NULL;
if (!msg) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
param = (esp_ble_mesh_prov_cb_param_t *)(msg->arg);
if (msg->act < ESP_BLE_MESH_PROV_EVT_MAX) {
btc_ble_mesh_cb_to_app(msg->act, param);
} else {
LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act);
}
btc_ble_mesh_model_free_req_data(msg);
return;
}

View File

@ -22,12 +22,15 @@
#include "btc_ble_mesh_sensor_model.h"
#include "esp_ble_mesh_sensor_model_api.h"
static inline void btc_ble_mesh_cb_to_app(esp_ble_mesh_sensor_client_cb_event_t event,
/* Sensor Client Models related functions */
static inline void btc_ble_mesh_sensor_client_cb_to_app(esp_ble_mesh_sensor_client_cb_event_t event,
esp_ble_mesh_sensor_client_cb_param_t *param)
{
esp_ble_mesh_sensor_client_cb_t btc_mesh_cb = (esp_ble_mesh_sensor_client_cb_t)btc_profile_cb_get(BTC_PID_SENSOR_CLIENT);
if (btc_mesh_cb) {
btc_mesh_cb(event, param);
esp_ble_mesh_sensor_client_cb_t btc_ble_mesh_cb =
(esp_ble_mesh_sensor_client_cb_t)btc_profile_cb_get(BTC_PID_SENSOR_CLIENT);
if (btc_ble_mesh_cb) {
btc_ble_mesh_cb(event, param);
}
}
@ -35,7 +38,6 @@ void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void
{
btc_ble_mesh_sensor_client_args_t *dst = (btc_ble_mesh_sensor_client_args_t *)p_dest;
btc_ble_mesh_sensor_client_args_t *src = (btc_ble_mesh_sensor_client_args_t *)p_src;
u32_t opcode;
u16_t length;
if (!msg || !dst || !src) {
@ -53,8 +55,7 @@ void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void
memcpy(dst->sensor_client_get_state.get_state, src->sensor_client_get_state.get_state,
sizeof(esp_ble_mesh_sensor_client_get_state_t));
opcode = src->sensor_client_get_state.params->opcode;
switch (opcode) {
switch (src->sensor_client_get_state.params->opcode) {
case ESP_BLE_MESH_MODEL_OP_SENSOR_COLUMN_GET:
if (src->sensor_client_get_state.get_state->column_get.raw_value_x) {
length = src->sensor_client_get_state.get_state->column_get.raw_value_x->len;
@ -109,8 +110,7 @@ void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void
memcpy(dst->sensor_client_set_state.set_state, src->sensor_client_set_state.set_state,
sizeof(esp_ble_mesh_sensor_client_set_state_t));
opcode = src->sensor_client_set_state.params->opcode;
switch (opcode) {
switch (src->sensor_client_set_state.params->opcode) {
case ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET:
if (src->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_down) {
length = src->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_down->len;
@ -184,11 +184,71 @@ void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void
}
}
static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src)
void btc_ble_mesh_sensor_client_arg_deep_free(btc_msg_t *msg)
{
btc_ble_mesh_sensor_client_args_t *arg = NULL;
if (!msg || !msg->arg) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
arg = (btc_ble_mesh_sensor_client_args_t *)(msg->arg);
switch (msg->act) {
case BTC_BLE_MESH_ACT_SENSOR_CLIENT_GET_STATE:
if (arg->sensor_client_get_state.get_state) {
if (arg->sensor_client_get_state.params) {
switch (arg->sensor_client_get_state.params->opcode) {
case ESP_BLE_MESH_MODEL_OP_SENSOR_COLUMN_GET:
bt_mesh_free_buf(arg->sensor_client_get_state.get_state->column_get.raw_value_x);
break;
case ESP_BLE_MESH_MODEL_OP_SENSOR_SERIES_GET:
bt_mesh_free_buf(arg->sensor_client_get_state.get_state->series_get.raw_value_x1);
bt_mesh_free_buf(arg->sensor_client_get_state.get_state->series_get.raw_value_x2);
break;
default:
break;
}
}
osi_free(arg->sensor_client_get_state.get_state);
}
if (arg->sensor_client_get_state.params) {
osi_free(arg->sensor_client_get_state.params);
}
break;
case BTC_BLE_MESH_ACT_SENSOR_CLIENT_SET_STATE:
if (arg->sensor_client_set_state.set_state) {
if (arg->sensor_client_set_state.params) {
switch (arg->sensor_client_set_state.params->opcode) {
case ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET:
bt_mesh_free_buf(arg->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_down);
bt_mesh_free_buf(arg->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_up);
bt_mesh_free_buf(arg->sensor_client_set_state.set_state->cadence_set.fast_cadence_low);
bt_mesh_free_buf(arg->sensor_client_set_state.set_state->cadence_set.fast_cadence_high);
break;
case ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_SET:
bt_mesh_free_buf(arg->sensor_client_set_state.set_state->setting_set.sensor_setting_raw);
break;
default:
break;
}
}
osi_free(arg->sensor_client_set_state.set_state);
}
if (arg->sensor_client_set_state.params) {
osi_free(arg->sensor_client_set_state.params);
}
break;
default:
break;
}
}
static void btc_ble_mesh_sensor_client_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src)
{
esp_ble_mesh_sensor_client_cb_param_t *p_dest_data = (esp_ble_mesh_sensor_client_cb_param_t *)p_dest;
esp_ble_mesh_sensor_client_cb_param_t *p_src_data = (esp_ble_mesh_sensor_client_cb_param_t *)p_src;
u32_t opcode;
u16_t length;
if (!msg || !p_src_data || !p_dest_data) {
@ -196,13 +256,22 @@ static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src
return;
}
if (p_src_data->params) {
p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
if (!p_dest_data->params) {
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
return;
}
memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t));
}
switch (msg->act) {
case ESP_BLE_MESH_SENSOR_CLIENT_GET_STATE_EVT:
case ESP_BLE_MESH_SENSOR_CLIENT_SET_STATE_EVT:
case ESP_BLE_MESH_SENSOR_CLIENT_PUBLISH_EVT:
if (p_src_data->params) {
opcode = p_src_data->params->opcode;
switch (opcode) {
switch (p_src_data->params->opcode) {
case ESP_BLE_MESH_MODEL_OP_SENSOR_DESCRIPTOR_GET:
case ESP_BLE_MESH_MODEL_OP_SENSOR_DESCRIPTOR_STATUS:
if (p_src_data->status_cb.descriptor_status.descriptor) {
@ -308,24 +377,15 @@ static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src
}
}
case ESP_BLE_MESH_SENSOR_CLIENT_TIMEOUT_EVT:
if (p_src_data->params) {
p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
if (p_dest_data->params) {
memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t));
} else {
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
}
}
break;
default:
break;
}
}
static void btc_ble_mesh_free_req_data(btc_msg_t *msg)
static void btc_ble_mesh_sensor_client_free_req_data(btc_msg_t *msg)
{
esp_ble_mesh_sensor_client_cb_param_t *arg = NULL;
u32_t opcode;
if (!msg || !msg->arg) {
LOG_ERROR("%s, Invalid parameter", __func__);
@ -339,8 +399,7 @@ static void btc_ble_mesh_free_req_data(btc_msg_t *msg)
case ESP_BLE_MESH_SENSOR_CLIENT_SET_STATE_EVT:
case ESP_BLE_MESH_SENSOR_CLIENT_PUBLISH_EVT:
if (arg->params) {
opcode = arg->params->opcode;
switch (opcode) {
switch (arg->params->opcode) {
case ESP_BLE_MESH_MODEL_OP_SENSOR_DESCRIPTOR_GET:
case ESP_BLE_MESH_MODEL_OP_SENSOR_DESCRIPTOR_STATUS:
bt_mesh_free_buf(arg->status_cb.descriptor_status.descriptor);
@ -385,73 +444,7 @@ static void btc_ble_mesh_free_req_data(btc_msg_t *msg)
}
}
void btc_ble_mesh_sensor_client_arg_deep_free(btc_msg_t *msg)
{
btc_ble_mesh_sensor_client_args_t *arg = NULL;
u32_t opcode = 0;
if (!msg || !msg->arg) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
arg = (btc_ble_mesh_sensor_client_args_t *)(msg->arg);
switch (msg->act) {
case BTC_BLE_MESH_ACT_SENSOR_CLIENT_GET_STATE:
if (arg->sensor_client_get_state.params) {
opcode = arg->sensor_client_get_state.params->opcode;
osi_free(arg->sensor_client_get_state.params);
}
if (arg->sensor_client_get_state.get_state) {
if (opcode) {
switch (opcode) {
case ESP_BLE_MESH_MODEL_OP_SENSOR_COLUMN_GET:
bt_mesh_free_buf(arg->sensor_client_get_state.get_state->column_get.raw_value_x);
break;
case ESP_BLE_MESH_MODEL_OP_SENSOR_SERIES_GET:
bt_mesh_free_buf(arg->sensor_client_get_state.get_state->series_get.raw_value_x1);
bt_mesh_free_buf(arg->sensor_client_get_state.get_state->series_get.raw_value_x2);
break;
default:
break;
}
}
osi_free(arg->sensor_client_get_state.get_state);
}
break;
case BTC_BLE_MESH_ACT_SENSOR_CLIENT_SET_STATE:
if (arg->sensor_client_set_state.params) {
opcode = arg->sensor_client_set_state.params->opcode;
osi_free(arg->sensor_client_set_state.params);
}
if (arg->sensor_client_set_state.set_state) {
if (opcode) {
switch (opcode) {
case ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET:
bt_mesh_free_buf(arg->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_down);
bt_mesh_free_buf(arg->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_up);
bt_mesh_free_buf(arg->sensor_client_set_state.set_state->cadence_set.fast_cadence_low);
bt_mesh_free_buf(arg->sensor_client_set_state.set_state->cadence_set.fast_cadence_high);
break;
case ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_SET:
bt_mesh_free_buf(arg->sensor_client_set_state.set_state->setting_set.sensor_setting_raw);
break;
default:
break;
}
}
osi_free(arg->sensor_client_set_state.set_state);
}
break;
default:
break;
}
return;
}
static void btc_mesh_sensor_client_callback(esp_ble_mesh_sensor_client_cb_param_t *cb_params, uint8_t act)
static void btc_ble_mesh_sensor_client_callback(esp_ble_mesh_sensor_client_cb_param_t *cb_params, uint8_t act)
{
btc_msg_t msg = {0};
@ -462,10 +455,10 @@ static void btc_mesh_sensor_client_callback(esp_ble_mesh_sensor_client_cb_param_
msg.act = act;
btc_transfer_context(&msg, cb_params,
sizeof(esp_ble_mesh_sensor_client_cb_param_t), btc_ble_mesh_copy_req_data);
sizeof(esp_ble_mesh_sensor_client_cb_param_t), btc_ble_mesh_sensor_client_copy_req_data);
}
void bt_mesh_callback_sensor_status_to_btc(u32_t opcode, u8_t evt_type,
void bt_mesh_sensor_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
const u8_t *val, size_t len)
@ -481,16 +474,16 @@ void bt_mesh_callback_sensor_status_to_btc(u32_t opcode, u8_t evt_type,
}
switch (evt_type) {
case 0x00:
case BTC_BLE_MESH_EVT_SENSOR_CLIENT_GET_STATE:
act = ESP_BLE_MESH_SENSOR_CLIENT_GET_STATE_EVT;
break;
case 0x01:
case BTC_BLE_MESH_EVT_SENSOR_CLIENT_SET_STATE:
act = ESP_BLE_MESH_SENSOR_CLIENT_SET_STATE_EVT;
break;
case 0x02:
case BTC_BLE_MESH_EVT_SENSOR_CLIENT_PUBLISH:
act = ESP_BLE_MESH_SENSOR_CLIENT_PUBLISH_EVT;
break;
case 0x03:
case BTC_BLE_MESH_EVT_SENSOR_CLIENT_TIMEOUT:
act = ESP_BLE_MESH_SENSOR_CLIENT_TIMEOUT_EVT;
break;
default:
@ -515,26 +508,31 @@ void bt_mesh_callback_sensor_status_to_btc(u32_t opcode, u8_t evt_type,
memcpy(&cb_params.status_cb, val, length);
}
btc_mesh_sensor_client_callback(&cb_params, act);
btc_ble_mesh_sensor_client_callback(&cb_params, act);
return;
}
void btc_mesh_sensor_client_publish_callback(u32_t opcode, struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf)
void btc_ble_mesh_sensor_client_publish_callback(u32_t opcode,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
if (!model || !ctx || !buf) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
bt_mesh_callback_sensor_status_to_btc(opcode, 0x02, model, ctx, buf->data, buf->len);
bt_mesh_sensor_client_cb_evt_to_btc(opcode,
BTC_BLE_MESH_EVT_SENSOR_CLIENT_PUBLISH, model, ctx, buf->data, buf->len);
return;
}
void btc_mesh_sensor_client_call_handler(btc_msg_t *msg)
void btc_ble_mesh_sensor_client_call_handler(btc_msg_t *msg)
{
esp_ble_mesh_sensor_client_cb_param_t sensor_client_cb = {0};
esp_ble_mesh_client_common_param_t *params = NULL;
btc_ble_mesh_sensor_client_args_t *arg = NULL;
struct bt_mesh_common_param common = {0};
esp_ble_mesh_sensor_client_cb_param_t cb = {0};
bt_mesh_client_common_param_t common = {0};
bt_mesh_role_param_t role_param = {0};
if (!msg || !msg->arg) {
@ -549,9 +547,9 @@ void btc_mesh_sensor_client_call_handler(btc_msg_t *msg)
params = arg->sensor_client_get_state.params;
role_param.model = (struct bt_mesh_model *)params->model;
role_param.role = params->msg_role;
if (bt_mesh_set_model_role(&role_param)) {
if (bt_mesh_set_client_model_role(&role_param)) {
LOG_ERROR("%s, Failed to set model role", __func__);
return;
break;
}
common.opcode = params->opcode;
common.model = (struct bt_mesh_model *)params->model;
@ -562,15 +560,12 @@ void btc_mesh_sensor_client_call_handler(btc_msg_t *msg)
common.ctx.send_ttl = params->ctx.send_ttl;
common.msg_timeout = params->msg_timeout;
sensor_client_cb.params = arg->sensor_client_get_state.params;
sensor_client_cb.error_code =
bt_mesh_sensor_client_get_state(&common,
(void *)arg->sensor_client_get_state.get_state,
(void *)&sensor_client_cb.status_cb);
if (sensor_client_cb.error_code) {
cb.params = arg->sensor_client_get_state.params;
cb.error_code = bt_mesh_sensor_client_get_state(&common,
(void *)arg->sensor_client_get_state.get_state, (void *)&cb.status_cb);
if (cb.error_code) {
/* If send failed, callback error_code to app layer immediately */
btc_mesh_sensor_client_callback(&sensor_client_cb,
ESP_BLE_MESH_SENSOR_CLIENT_GET_STATE_EVT);
btc_ble_mesh_sensor_client_callback(&cb, ESP_BLE_MESH_SENSOR_CLIENT_GET_STATE_EVT);
}
break;
}
@ -578,9 +573,9 @@ void btc_mesh_sensor_client_call_handler(btc_msg_t *msg)
params = arg->sensor_client_set_state.params;
role_param.model = (struct bt_mesh_model *)params->model;
role_param.role = params->msg_role;
if (bt_mesh_set_model_role(&role_param)) {
if (bt_mesh_set_client_model_role(&role_param)) {
LOG_ERROR("%s, Failed to set model role", __func__);
return;
break;
}
common.opcode = params->opcode;
common.model = (struct bt_mesh_model *)params->model;
@ -591,15 +586,12 @@ void btc_mesh_sensor_client_call_handler(btc_msg_t *msg)
common.ctx.send_ttl = params->ctx.send_ttl;
common.msg_timeout = params->msg_timeout;
sensor_client_cb.params = arg->sensor_client_set_state.params;
sensor_client_cb.error_code =
bt_mesh_sensor_client_set_state(&common,
(void *)arg->sensor_client_set_state.set_state,
(void *)&sensor_client_cb.status_cb);
if (sensor_client_cb.error_code) {
cb.params = arg->sensor_client_set_state.params;
cb.error_code = bt_mesh_sensor_client_set_state(&common,
(void *)arg->sensor_client_set_state.set_state, (void *)&cb.status_cb);
if (cb.error_code) {
/* If send failed, callback error_code to app layer immediately */
btc_mesh_sensor_client_callback(&sensor_client_cb,
ESP_BLE_MESH_SENSOR_CLIENT_SET_STATE_EVT);
btc_ble_mesh_sensor_client_callback(&cb, ESP_BLE_MESH_SENSOR_CLIENT_SET_STATE_EVT);
}
break;
}
@ -608,9 +600,10 @@ void btc_mesh_sensor_client_call_handler(btc_msg_t *msg)
}
btc_ble_mesh_sensor_client_arg_deep_free(msg);
return;
}
void btc_mesh_sensor_client_cb_handler(btc_msg_t *msg)
void btc_ble_mesh_sensor_client_cb_handler(btc_msg_t *msg)
{
esp_ble_mesh_sensor_client_cb_param_t *param = NULL;
@ -622,11 +615,12 @@ void btc_mesh_sensor_client_cb_handler(btc_msg_t *msg)
param = (esp_ble_mesh_sensor_client_cb_param_t *)(msg->arg);
if (msg->act < ESP_BLE_MESH_SENSOR_CLIENT_EVT_MAX) {
btc_ble_mesh_cb_to_app(msg->act, param);
btc_ble_mesh_sensor_client_cb_to_app(msg->act, param);
} else {
LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act);
}
btc_ble_mesh_free_req_data(msg);
btc_ble_mesh_sensor_client_free_req_data(msg);
return;
}

View File

@ -22,12 +22,15 @@
#include "btc_ble_mesh_time_scene_model.h"
#include "esp_ble_mesh_time_scene_model_api.h"
static inline void btc_ble_mesh_cb_to_app(esp_ble_mesh_time_scene_client_cb_event_t event,
/* Time and Scenes Client Models related functions */
static inline void btc_ble_mesh_time_scene_client_cb_to_app(esp_ble_mesh_time_scene_client_cb_event_t event,
esp_ble_mesh_time_scene_client_cb_param_t *param)
{
esp_ble_mesh_time_scene_client_cb_t btc_mesh_cb = (esp_ble_mesh_time_scene_client_cb_t)btc_profile_cb_get(BTC_PID_TIME_SCENE_CLIENT);
if (btc_mesh_cb) {
btc_mesh_cb(event, param);
esp_ble_mesh_time_scene_client_cb_t btc_ble_mesh_cb =
(esp_ble_mesh_time_scene_client_cb_t)btc_profile_cb_get(BTC_PID_TIME_SCENE_CLIENT);
if (btc_ble_mesh_cb) {
btc_ble_mesh_cb(event, param);
}
}
@ -74,99 +77,6 @@ void btc_ble_mesh_time_scene_client_arg_deep_copy(btc_msg_t *msg, void *p_dest,
}
}
static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src)
{
esp_ble_mesh_time_scene_client_cb_param_t *p_dest_data = (esp_ble_mesh_time_scene_client_cb_param_t *)p_dest;
esp_ble_mesh_time_scene_client_cb_param_t *p_src_data = (esp_ble_mesh_time_scene_client_cb_param_t *)p_src;
u32_t opcode;
u16_t length;
if (!msg || !p_src_data || !p_dest_data) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
switch (msg->act) {
case ESP_BLE_MESH_TIME_SCENE_CLIENT_GET_STATE_EVT:
case ESP_BLE_MESH_TIME_SCENE_CLIENT_SET_STATE_EVT:
case ESP_BLE_MESH_TIME_SCENE_CLIENT_PUBLISH_EVT:
if (p_src_data->params) {
opcode = p_src_data->params->opcode;
switch (opcode) {
case ESP_BLE_MESH_MODEL_OP_SCENE_STORE:
case ESP_BLE_MESH_MODEL_OP_SCENE_REGISTER_GET:
case ESP_BLE_MESH_MODEL_OP_SCENE_DELETE:
case ESP_BLE_MESH_MODEL_OP_SCENE_REGISTER_STATUS:
if (p_src_data->status_cb.scene_register_status.scenes) {
length = p_src_data->status_cb.scene_register_status.scenes->len;
p_dest_data->status_cb.scene_register_status.scenes = bt_mesh_alloc_buf(length);
if (!p_dest_data->status_cb.scene_register_status.scenes) {
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
return;
}
net_buf_simple_add_mem(p_dest_data->status_cb.scene_register_status.scenes,
p_src_data->status_cb.scene_register_status.scenes->data,
p_src_data->status_cb.scene_register_status.scenes->len);
}
break;
default:
break;
}
}
case ESP_BLE_MESH_TIME_SCENE_CLIENT_TIMEOUT_EVT:
if (p_src_data->params) {
p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
if (p_dest_data->params) {
memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t));
} else {
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
}
}
break;
default:
break;
}
}
static void btc_ble_mesh_free_req_data(btc_msg_t *msg)
{
esp_ble_mesh_time_scene_client_cb_param_t *arg = NULL;
u32_t opcode;
if (!msg || !msg->arg) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
arg = (esp_ble_mesh_time_scene_client_cb_param_t *)(msg->arg);
switch (msg->act) {
case ESP_BLE_MESH_TIME_SCENE_CLIENT_GET_STATE_EVT:
case ESP_BLE_MESH_TIME_SCENE_CLIENT_SET_STATE_EVT:
case ESP_BLE_MESH_TIME_SCENE_CLIENT_PUBLISH_EVT:
if (arg->params) {
opcode = arg->params->opcode;
switch (opcode) {
case ESP_BLE_MESH_MODEL_OP_SCENE_STORE:
case ESP_BLE_MESH_MODEL_OP_SCENE_REGISTER_GET:
case ESP_BLE_MESH_MODEL_OP_SCENE_DELETE:
case ESP_BLE_MESH_MODEL_OP_SCENE_REGISTER_STATUS:
bt_mesh_free_buf(arg->status_cb.scene_register_status.scenes);
break;
default:
break;
}
}
case ESP_BLE_MESH_TIME_SCENE_CLIENT_TIMEOUT_EVT:
if (arg->params) {
osi_free(arg->params);
}
break;
default:
break;
}
}
void btc_ble_mesh_time_scene_client_arg_deep_free(btc_msg_t *msg)
{
btc_ble_mesh_time_scene_client_args_t *arg = NULL;
@ -198,11 +108,100 @@ void btc_ble_mesh_time_scene_client_arg_deep_free(btc_msg_t *msg)
default:
break;
}
return;
}
static void btc_mesh_time_scene_client_callback(esp_ble_mesh_time_scene_client_cb_param_t *cb_params, uint8_t act)
static void btc_ble_mesh_time_scene_client_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src)
{
esp_ble_mesh_time_scene_client_cb_param_t *p_dest_data = (esp_ble_mesh_time_scene_client_cb_param_t *)p_dest;
esp_ble_mesh_time_scene_client_cb_param_t *p_src_data = (esp_ble_mesh_time_scene_client_cb_param_t *)p_src;
u16_t length;
if (!msg || !p_src_data || !p_dest_data) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
if (p_src_data->params) {
p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
if (!p_dest_data->params) {
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
return;
}
memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t));
}
switch (msg->act) {
case ESP_BLE_MESH_TIME_SCENE_CLIENT_GET_STATE_EVT:
case ESP_BLE_MESH_TIME_SCENE_CLIENT_SET_STATE_EVT:
case ESP_BLE_MESH_TIME_SCENE_CLIENT_PUBLISH_EVT:
if (p_src_data->params) {
switch (p_src_data->params->opcode) {
case ESP_BLE_MESH_MODEL_OP_SCENE_STORE:
case ESP_BLE_MESH_MODEL_OP_SCENE_REGISTER_GET:
case ESP_BLE_MESH_MODEL_OP_SCENE_DELETE:
case ESP_BLE_MESH_MODEL_OP_SCENE_REGISTER_STATUS:
if (p_src_data->status_cb.scene_register_status.scenes) {
length = p_src_data->status_cb.scene_register_status.scenes->len;
p_dest_data->status_cb.scene_register_status.scenes = bt_mesh_alloc_buf(length);
if (!p_dest_data->status_cb.scene_register_status.scenes) {
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
return;
}
net_buf_simple_add_mem(p_dest_data->status_cb.scene_register_status.scenes,
p_src_data->status_cb.scene_register_status.scenes->data,
p_src_data->status_cb.scene_register_status.scenes->len);
}
break;
default:
break;
}
}
case ESP_BLE_MESH_TIME_SCENE_CLIENT_TIMEOUT_EVT:
break;
default:
break;
}
}
static void btc_ble_mesh_time_scene_client_free_req_data(btc_msg_t *msg)
{
esp_ble_mesh_time_scene_client_cb_param_t *arg = NULL;
if (!msg || !msg->arg) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
arg = (esp_ble_mesh_time_scene_client_cb_param_t *)(msg->arg);
switch (msg->act) {
case ESP_BLE_MESH_TIME_SCENE_CLIENT_GET_STATE_EVT:
case ESP_BLE_MESH_TIME_SCENE_CLIENT_SET_STATE_EVT:
case ESP_BLE_MESH_TIME_SCENE_CLIENT_PUBLISH_EVT:
if (arg->params) {
switch (arg->params->opcode) {
case ESP_BLE_MESH_MODEL_OP_SCENE_STORE:
case ESP_BLE_MESH_MODEL_OP_SCENE_REGISTER_GET:
case ESP_BLE_MESH_MODEL_OP_SCENE_DELETE:
case ESP_BLE_MESH_MODEL_OP_SCENE_REGISTER_STATUS:
bt_mesh_free_buf(arg->status_cb.scene_register_status.scenes);
break;
default:
break;
}
}
case ESP_BLE_MESH_TIME_SCENE_CLIENT_TIMEOUT_EVT:
if (arg->params) {
osi_free(arg->params);
}
break;
default:
break;
}
}
static void btc_ble_mesh_time_scene_client_callback(esp_ble_mesh_time_scene_client_cb_param_t *cb_params, uint8_t act)
{
btc_msg_t msg = {0};
@ -213,10 +212,10 @@ static void btc_mesh_time_scene_client_callback(esp_ble_mesh_time_scene_client_c
msg.act = act;
btc_transfer_context(&msg, cb_params,
sizeof(esp_ble_mesh_time_scene_client_cb_param_t), btc_ble_mesh_copy_req_data);
sizeof(esp_ble_mesh_time_scene_client_cb_param_t), btc_ble_mesh_time_scene_client_copy_req_data);
}
void bt_mesh_callback_time_scene_status_to_btc(u32_t opcode, u8_t evt_type,
void bt_mesh_time_scene_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
const u8_t *val, size_t len)
@ -232,16 +231,16 @@ void bt_mesh_callback_time_scene_status_to_btc(u32_t opcode, u8_t evt_type,
}
switch (evt_type) {
case 0x00:
case BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_GET_STATE:
act = ESP_BLE_MESH_TIME_SCENE_CLIENT_GET_STATE_EVT;
break;
case 0x01:
case BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_SET_STATE:
act = ESP_BLE_MESH_TIME_SCENE_CLIENT_SET_STATE_EVT;
break;
case 0x02:
case BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_PUBLISH:
act = ESP_BLE_MESH_TIME_SCENE_CLIENT_PUBLISH_EVT;
break;
case 0x03:
case BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_TIMEOUT:
act = ESP_BLE_MESH_TIME_SCENE_CLIENT_TIMEOUT_EVT;
break;
default:
@ -266,26 +265,31 @@ void bt_mesh_callback_time_scene_status_to_btc(u32_t opcode, u8_t evt_type,
memcpy(&cb_params.status_cb, val, length);
}
btc_mesh_time_scene_client_callback(&cb_params, act);
btc_ble_mesh_time_scene_client_callback(&cb_params, act);
return;
}
void btc_mesh_time_scene_client_publish_callback(u32_t opcode, struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf)
void btc_ble_mesh_time_scene_client_publish_callback(u32_t opcode,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
if (!model || !ctx || !buf) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
bt_mesh_callback_time_scene_status_to_btc(opcode, 0x02, model, ctx, buf->data, buf->len);
bt_mesh_time_scene_client_cb_evt_to_btc(opcode,
BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_PUBLISH, model, ctx, buf->data, buf->len);
return;
}
void btc_mesh_time_scene_client_call_handler(btc_msg_t *msg)
void btc_ble_mesh_time_scene_client_call_handler(btc_msg_t *msg)
{
esp_ble_mesh_time_scene_client_cb_param_t time_scene_client_cb = {0};
btc_ble_mesh_time_scene_client_args_t *arg = NULL;
esp_ble_mesh_client_common_param_t *params = NULL;
struct bt_mesh_common_param common = {0};
esp_ble_mesh_time_scene_client_cb_param_t cb = {0};
bt_mesh_client_common_param_t common = {0};
bt_mesh_role_param_t role_param = {0};
if (!msg || !msg->arg) {
@ -300,9 +304,9 @@ void btc_mesh_time_scene_client_call_handler(btc_msg_t *msg)
params = arg->time_scene_client_get_state.params;
role_param.model = (struct bt_mesh_model *)params->model;
role_param.role = params->msg_role;
if (bt_mesh_set_model_role(&role_param)) {
if (bt_mesh_set_client_model_role(&role_param)) {
LOG_ERROR("%s, Failed to set model role", __func__);
return;
break;
}
common.opcode = params->opcode;
common.model = (struct bt_mesh_model *)params->model;
@ -313,15 +317,12 @@ void btc_mesh_time_scene_client_call_handler(btc_msg_t *msg)
common.ctx.send_ttl = params->ctx.send_ttl;
common.msg_timeout = params->msg_timeout;
time_scene_client_cb.params = arg->time_scene_client_get_state.params;
time_scene_client_cb.error_code =
bt_mesh_time_scene_client_get_state(&common,
(void *)arg->time_scene_client_get_state.get_state,
(void *)&time_scene_client_cb.status_cb);
if (time_scene_client_cb.error_code) {
cb.params = arg->time_scene_client_get_state.params;
cb.error_code = bt_mesh_time_scene_client_get_state(&common,
(void *)arg->time_scene_client_get_state.get_state, (void *)&cb.status_cb);
if (cb.error_code) {
/* If send failed, callback error_code to app layer immediately */
btc_mesh_time_scene_client_callback(&time_scene_client_cb,
ESP_BLE_MESH_TIME_SCENE_CLIENT_GET_STATE_EVT);
btc_ble_mesh_time_scene_client_callback(&cb, ESP_BLE_MESH_TIME_SCENE_CLIENT_GET_STATE_EVT);
}
break;
}
@ -329,9 +330,9 @@ void btc_mesh_time_scene_client_call_handler(btc_msg_t *msg)
params = arg->time_scene_client_set_state.params;
role_param.model = (struct bt_mesh_model *)params->model;
role_param.role = params->msg_role;
if (bt_mesh_set_model_role(&role_param)) {
if (bt_mesh_set_client_model_role(&role_param)) {
LOG_ERROR("%s, Failed to set model role", __func__);
return;
break;
}
common.opcode = params->opcode;
common.model = (struct bt_mesh_model *)params->model;
@ -342,15 +343,12 @@ void btc_mesh_time_scene_client_call_handler(btc_msg_t *msg)
common.ctx.send_ttl = params->ctx.send_ttl;
common.msg_timeout = params->msg_timeout;
time_scene_client_cb.params = arg->time_scene_client_set_state.params;
time_scene_client_cb.error_code =
bt_mesh_time_scene_client_set_state(&common,
(void *)arg->time_scene_client_set_state.set_state,
(void *)&time_scene_client_cb.status_cb);
if (time_scene_client_cb.error_code) {
cb.params = arg->time_scene_client_set_state.params;
cb.error_code = bt_mesh_time_scene_client_set_state(&common,
(void *)arg->time_scene_client_set_state.set_state, (void *)&cb.status_cb);
if (cb.error_code) {
/* If send failed, callback error_code to app layer immediately */
btc_mesh_time_scene_client_callback(&time_scene_client_cb,
ESP_BLE_MESH_TIME_SCENE_CLIENT_SET_STATE_EVT);
btc_ble_mesh_time_scene_client_callback(&cb, ESP_BLE_MESH_TIME_SCENE_CLIENT_SET_STATE_EVT);
}
break;
}
@ -359,9 +357,10 @@ void btc_mesh_time_scene_client_call_handler(btc_msg_t *msg)
}
btc_ble_mesh_time_scene_client_arg_deep_free(msg);
return;
}
void btc_mesh_time_scene_client_cb_handler(btc_msg_t *msg)
void btc_ble_mesh_time_scene_client_cb_handler(btc_msg_t *msg)
{
esp_ble_mesh_time_scene_client_cb_param_t *param = NULL;
@ -373,11 +372,12 @@ void btc_mesh_time_scene_client_cb_handler(btc_msg_t *msg)
param = (esp_ble_mesh_time_scene_client_cb_param_t *)(msg->arg);
if (msg->act < ESP_BLE_MESH_TIME_SCENE_CLIENT_EVT_MAX) {
btc_ble_mesh_cb_to_app(msg->act, param);
btc_ble_mesh_time_scene_client_cb_to_app(msg->act, param);
} else {
LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act);
}
btc_ble_mesh_free_req_data(msg);
btc_ble_mesh_time_scene_client_free_req_data(msg);
return;
}

View File

@ -22,42 +22,53 @@
typedef enum {
BTC_BLE_MESH_ACT_CONFIG_CLIENT_GET_STATE,
BTC_BLE_MESH_ACT_CONFIG_CLIENT_SET_STATE,
} btc_ble_mesh_cfg_client_act_t;
BTC_BLE_MESH_ACT_CONFIG_CLIENT_MAX,
} btc_ble_mesh_config_client_act_t;
typedef union {
struct ble_mesh_clg_client_get_state_reg_args {
struct ble_mesh_cfg_client_get_state_reg_args {
esp_ble_mesh_client_common_param_t *params;
esp_ble_mesh_cfg_client_get_state_t *get_state;
} cfg_client_get_state;
struct ble_mesh_clg_client_set_state_reg_args {
struct ble_mesh_cfg_client_set_state_reg_args {
esp_ble_mesh_client_common_param_t *params;
esp_ble_mesh_cfg_client_set_state_t *set_state;
} cfg_client_set_state;
} btc_ble_mesh_cfg_client_args_t;
} btc_ble_mesh_config_client_args_t;
void btc_mesh_cfg_client_call_handler(btc_msg_t *msg);
typedef enum {
BTC_BLE_MESH_EVT_CONFIG_CLIENT_GET_STATE,
BTC_BLE_MESH_EVT_CONFIG_CLIENT_SET_STATE,
BTC_BLE_MESH_EVT_CONFIG_CLIENT_PUBLISH,
BTC_BLE_MESH_EVT_CONFIG_CLIENT_TIMEOUT,
BTC_BLE_MESH_EVT_CONFIG_CLIENT_MAX,
} btc_ble_mesh_config_client_evt_t;
void btc_mesh_cfg_client_cb_handler(btc_msg_t *msg);
void btc_ble_mesh_config_client_call_handler(btc_msg_t *msg);
void btc_ble_mesh_cfg_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
void btc_ble_mesh_config_client_cb_handler(btc_msg_t *msg);
int btc_ble_mesh_config_client_get_state(esp_ble_mesh_client_common_param_t *params, esp_ble_mesh_cfg_client_get_state_t *get_state,
esp_ble_mesh_cfg_client_cb_param_t *cfg_client_cb);
void btc_ble_mesh_config_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
int btc_ble_mesh_config_client_set_state(esp_ble_mesh_client_common_param_t *params, esp_ble_mesh_cfg_client_set_state_t *set_state,
esp_ble_mesh_cfg_client_cb_param_t *cfg_client_cb);
void btc_ble_mesh_config_client_publish_callback(u32_t opcode,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf);
void btc_mesh_cfg_client_publish_callback(u32_t opcode, struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf);
void bt_mesh_callback_config_status_to_btc(u32_t opcode, u8_t evt_type,
void bt_mesh_config_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
const u8_t *val, size_t len);
void btc_mesh_cfg_server_cb_handler(btc_msg_t *msg);
void btc_ble_mesh_config_server_cb_handler(btc_msg_t *msg);
void bt_mesh_callback_cfg_server_event_to_btc(u8_t evt_type, struct bt_mesh_model *model,
typedef enum {
BTC_BLE_MESH_EVT_CONFIG_SERVER_RECV_MSG,
BTC_BLE_MESH_EVT_CONFIG_SERVER_MAX,
} btc_ble_mesh_config_server_evt_t;
void bt_mesh_config_server_cb_evt_to_btc(u8_t evt_type,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
const u8_t *val, size_t len);

View File

@ -22,6 +22,7 @@
typedef enum {
BTC_BLE_MESH_ACT_GENERIC_CLIENT_GET_STATE,
BTC_BLE_MESH_ACT_GENERIC_CLIENT_SET_STATE,
BTC_BLE_MESH_ACT_GENERIC_CLIENT_MAX,
} btc_ble_mesh_generic_client_act_t;
typedef union {
@ -35,16 +36,26 @@ typedef union {
} generic_client_set_state;
} btc_ble_mesh_generic_client_args_t;
void btc_mesh_generic_client_call_handler(btc_msg_t *msg);
typedef enum {
BTC_BLE_MESH_EVT_GENERIC_CLIENT_GET_STATE,
BTC_BLE_MESH_EVT_GENERIC_CLIENT_SET_STATE,
BTC_BLE_MESH_EVT_GENERIC_CLIENT_PUBLISH,
BTC_BLE_MESH_EVT_GENERIC_CLIENT_TIMEOUT,
BTC_BLE_MESH_EVT_GENERIC_CLIENT_MAX,
} btc_ble_mesh_generic_client_evt_t;
void btc_mesh_generic_client_cb_handler(btc_msg_t *msg);
void btc_ble_mesh_generic_client_call_handler(btc_msg_t *msg);
void btc_ble_mesh_generic_client_cb_handler(btc_msg_t *msg);
void btc_ble_mesh_generic_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
void btc_mesh_generic_client_publish_callback(u32_t opcode, struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf);
void btc_ble_mesh_generic_client_publish_callback(u32_t opcode,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf);
void bt_mesh_callback_generic_status_to_btc(u32_t opcode, u8_t evt_type,
void bt_mesh_generic_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
const u8_t *val, size_t len);

View File

@ -25,11 +25,6 @@ typedef enum {
BTC_BLE_MESH_ACT_HEALTH_CLIENT_MAX,
} btc_ble_mesh_health_client_act_t;
typedef enum {
BTC_BLE_MESH_ACT_HEALTH_SERVER_FAULT_UPDATE,
BTC_BLE_MESH_ACT_HEALTH_SERVER_MAX,
} btc_ble_mesh_health_server_act_t;
typedef union {
struct ble_mesh_health_client_get_state_reg_args {
esp_ble_mesh_client_common_param_t *params;
@ -41,38 +36,45 @@ typedef union {
} health_client_set_state;
} btc_ble_mesh_health_client_args_t;
typedef enum {
BTC_BLE_MESH_EVT_HEALTH_CLIENT_GET_STATE,
BTC_BLE_MESH_EVT_HEALTH_CLIENT_SET_STATE,
BTC_BLE_MESH_EVT_HEALTH_CLIENT_PUBLISH,
BTC_BLE_MESH_EVT_HEALTH_CLIENT_TIMEOUT,
BTC_BLE_MESH_EVT_HEALTH_CLIENT_MAX,
} btc_ble_mesh_health_client_evt_t;
void btc_ble_mesh_health_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
void btc_ble_mesh_health_client_call_handler(btc_msg_t *msg);
void btc_ble_mesh_health_client_cb_handler(btc_msg_t *msg);
void btc_ble_mesh_health_publish_callback(u32_t opcode,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf);
void bt_mesh_health_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
const u8_t *val, u16_t len);
typedef enum {
BTC_BLE_MESH_ACT_HEALTH_SERVER_FAULT_UPDATE,
BTC_BLE_MESH_ACT_HEALTH_SERVER_MAX,
} btc_ble_mesh_health_server_act_t;
typedef union {
struct ble_mesh_health_server_fault_update_args {
esp_ble_mesh_elem_t *element;
} fault_update;
} btc_ble_mesh_health_server_args_t;
void btc_mesh_health_client_call_handler(btc_msg_t *msg);
void btc_ble_mesh_health_server_call_handler(btc_msg_t *msg);
void btc_mesh_health_client_cb_handler(btc_msg_t *msg);
void btc_mesh_health_server_call_handler(btc_msg_t *msg);
void btc_mesh_health_server_cb_handler(btc_msg_t *msg);
void btc_ble_mesh_health_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
void btc_ble_mesh_health_server_cb_handler(btc_msg_t *msg);
void btc_ble_mesh_health_server_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
int btc_ble_mesh_health_client_get_state(esp_ble_mesh_client_common_param_t *params,
esp_ble_mesh_health_client_get_state_t *get_state,
esp_ble_mesh_health_client_cb_param_t *client_cb);
int btc_ble_mesh_health_client_set_state(esp_ble_mesh_client_common_param_t *params,
esp_ble_mesh_health_client_set_state_t *set_state,
esp_ble_mesh_health_client_cb_param_t *client_cb);
void btc_mesh_health_publish_callback(u32_t opcode, struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf);
void bt_mesh_callback_health_status_to_btc(u32_t opcode, u8_t evt_type,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
const u8_t *val, u16_t len);
#endif /* _BTC_BLE_MESH_HEALTH_MODEL_H_ */

View File

@ -20,9 +20,10 @@
#include "esp_ble_mesh_lighting_model_api.h"
typedef enum {
BTC_BLE_MESH_ACT_LIGHT_CLIENT_GET_STATE,
BTC_BLE_MESH_ACT_LIGHT_CLIENT_SET_STATE,
} btc_ble_mesh_light_client_act_t;
BTC_BLE_MESH_ACT_LIGHTING_CLIENT_GET_STATE,
BTC_BLE_MESH_ACT_LIGHTING_CLIENT_SET_STATE,
BTC_BLE_MESH_ACT_LIGHTING_CLIENT_MAX,
} btc_ble_mesh_lighting_client_act_t;
typedef union {
struct ble_mesh_light_client_get_state_reg_args {
@ -33,18 +34,28 @@ typedef union {
esp_ble_mesh_client_common_param_t *params;
esp_ble_mesh_light_client_set_state_t *set_state;
} light_client_set_state;
} btc_ble_mesh_light_client_args_t;
} btc_ble_mesh_lighting_client_args_t;
void btc_mesh_light_client_call_handler(btc_msg_t *msg);
typedef enum {
BTC_BLE_MESH_EVT_LIGHTING_CLIENT_GET_STATE,
BTC_BLE_MESH_EVT_LIGHTING_CLIENT_SET_STATE,
BTC_BLE_MESH_EVT_LIGHTING_CLIENT_PUBLISH,
BTC_BLE_MESH_EVT_LIGHTING_CLIENT_TIMEOUT,
BTC_BLE_MESH_EVT_LIGHTING_CLIENT_MAX,
} btc_ble_mesh_lighting_client_evt_t;
void btc_mesh_light_client_cb_handler(btc_msg_t *msg);
void btc_ble_mesh_lighting_client_call_handler(btc_msg_t *msg);
void btc_ble_mesh_light_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
void btc_ble_mesh_lighting_client_cb_handler(btc_msg_t *msg);
void btc_mesh_light_client_publish_callback(u32_t opcode, struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf);
void btc_ble_mesh_lighting_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
void bt_mesh_callback_light_status_to_btc(u32_t opcode, u8_t evt_type,
void btc_ble_mesh_lighting_client_publish_callback(u32_t opcode,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf);
void bt_mesh_lighting_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
const u8_t *val, size_t len);

View File

@ -61,7 +61,7 @@ typedef enum {
typedef enum {
BTC_BLE_MESH_ACT_MODEL_PUBLISH,
BTC_BLE_MESH_ACT_SERVER_MODEL_SEND,
BTC_BLE_MESH_ACT_CLIENT_MODEL_SEND
BTC_BLE_MESH_ACT_CLIENT_MODEL_SEND,
} btc_ble_mesh_model_act_t;
typedef union {
@ -176,11 +176,9 @@ typedef union {
} model_send;
} btc_ble_mesh_model_args_t;
void btc_ble_mesh_prov_arg_deep_free(btc_msg_t *msg);
void btc_ble_mesh_prov_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
int btc_ble_mesh_client_init(esp_ble_mesh_model_t *model);
int btc_ble_mesh_client_model_init(esp_ble_mesh_model_t *model);
int32_t btc_ble_mesh_model_pub_period_get(esp_ble_mesh_model_t *mod);
@ -200,11 +198,10 @@ esp_ble_mesh_model_t *btc_ble_mesh_model_find(const esp_ble_mesh_elem_t *elem,
const esp_ble_mesh_comp_t *btc_ble_mesh_comp_get(void);
void btc_mesh_model_call_handler(btc_msg_t *msg);
void btc_mesh_model_cb_handler(btc_msg_t *msg);
void btc_ble_mesh_model_call_handler(btc_msg_t *msg);
void btc_ble_mesh_model_cb_handler(btc_msg_t *msg);
void btc_mesh_prov_call_handler(btc_msg_t *msg);
void btc_mesh_prov_cb_handler(btc_msg_t *msg);
void btc_ble_mesh_prov_call_handler(btc_msg_t *msg);
void btc_ble_mesh_prov_cb_handler(btc_msg_t *msg);
#endif /* _BTC_BLE_MESH_PROV_H_ */

View File

@ -22,6 +22,7 @@
typedef enum {
BTC_BLE_MESH_ACT_SENSOR_CLIENT_GET_STATE,
BTC_BLE_MESH_ACT_SENSOR_CLIENT_SET_STATE,
BTC_BLE_MESH_ACT_SENSOR_CLIENT_MAX,
} btc_ble_mesh_sensor_client_act_t;
typedef union {
@ -35,16 +36,26 @@ typedef union {
} sensor_client_set_state;
} btc_ble_mesh_sensor_client_args_t;
void btc_mesh_sensor_client_call_handler(btc_msg_t *msg);
typedef enum {
BTC_BLE_MESH_EVT_SENSOR_CLIENT_GET_STATE,
BTC_BLE_MESH_EVT_SENSOR_CLIENT_SET_STATE,
BTC_BLE_MESH_EVT_SENSOR_CLIENT_PUBLISH,
BTC_BLE_MESH_EVT_SENSOR_CLIENT_TIMEOUT,
BTC_BLE_MESH_EVT_SENSOR_CLIENT_MAX,
} btc_ble_mesh_sensor_client_evt_t;
void btc_mesh_sensor_client_cb_handler(btc_msg_t *msg);
void btc_ble_mesh_sensor_client_call_handler(btc_msg_t *msg);
void btc_ble_mesh_sensor_client_cb_handler(btc_msg_t *msg);
void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
void btc_mesh_sensor_client_publish_callback(u32_t opcode, struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf);
void btc_ble_mesh_sensor_client_publish_callback(u32_t opcode,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf);
void bt_mesh_callback_sensor_status_to_btc(u32_t opcode, u8_t evt_type,
void bt_mesh_sensor_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
const u8_t *val, size_t len);

View File

@ -22,6 +22,7 @@
typedef enum {
BTC_BLE_MESH_ACT_TIME_SCENE_CLIENT_GET_STATE,
BTC_BLE_MESH_ACT_TIME_SCENE_CLIENT_SET_STATE,
BTC_BLE_MESH_ACT_TIME_SCENE_CLIENT_MAX,
} btc_ble_mesh_time_scene_client_act_t;
typedef union {
@ -35,16 +36,26 @@ typedef union {
} time_scene_client_set_state;
} btc_ble_mesh_time_scene_client_args_t;
void btc_mesh_time_scene_client_call_handler(btc_msg_t *msg);
typedef enum {
BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_GET_STATE,
BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_SET_STATE,
BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_PUBLISH,
BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_TIMEOUT,
BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_MAX,
} btc_ble_mesh_time_scene_client_evt_t;
void btc_mesh_time_scene_client_cb_handler(btc_msg_t *msg);
void btc_ble_mesh_time_scene_client_call_handler(btc_msg_t *msg);
void btc_ble_mesh_time_scene_client_cb_handler(btc_msg_t *msg);
void btc_ble_mesh_time_scene_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
void btc_mesh_time_scene_client_publish_callback(u32_t opcode, struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf);
void btc_ble_mesh_time_scene_client_publish_callback(u32_t opcode,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf);
void bt_mesh_callback_time_scene_status_to_btc(u32_t opcode, u8_t evt_type,
void bt_mesh_time_scene_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
const u8_t *val, size_t len);

View File

@ -220,7 +220,24 @@ static void publish_sent(int err, void *user_data)
}
}
static void publish_start(u16_t duration, int err, void *user_data)
{
struct bt_mesh_model *mod = user_data;
struct bt_mesh_model_pub *pub = mod->pub;
if (err) {
BT_ERR("Failed to publish: err %d", err);
return;
}
/* Initialize the timestamp for the beginning of a new period */
if (pub->count == BLE_MESH_PUB_TRANSMIT_COUNT(pub->retransmit)) {
pub->period_start = k_uptime_get_32();
}
}
static const struct bt_mesh_send_cb pub_sent_cb = {
.start = publish_start,
.end = publish_sent,
};
@ -310,8 +327,6 @@ static void mod_publish(struct k_work *work)
__ASSERT_NO_MSG(pub->update != NULL);
pub->period_start = k_uptime_get_32();
/* Callback the model publish update event to the application layer.
* In the event, users can update the context of the publish message
* which will be published in the next period.
@ -326,11 +341,6 @@ static void mod_publish(struct k_work *work)
if (err) {
BT_ERR("%s, Publishing failed (err %d)", __func__, err);
}
if (pub->count) {
/* Retransmissions also control the timer */
k_delayed_work_cancel(&pub->timer);
}
}
struct bt_mesh_elem *bt_mesh_model_elem(struct bt_mesh_model *mod)
@ -495,17 +505,21 @@ static struct bt_mesh_model *bt_mesh_elem_find_group(struct bt_mesh_elem *elem,
struct bt_mesh_elem *bt_mesh_elem_find(u16_t addr)
{
int i;
u16_t index;
for (i = 0; i < dev_comp->elem_count; i++) {
struct bt_mesh_elem *elem = &dev_comp->elem[i];
if (BLE_MESH_ADDR_IS_UNICAST(addr)) {
index = (addr - dev_comp->elem[0].addr);
if (index < dev_comp->elem_count) {
return &dev_comp->elem[index];
} else {
return NULL;
}
}
if (BLE_MESH_ADDR_IS_GROUP(addr) ||
BLE_MESH_ADDR_IS_VIRTUAL(addr)) {
if (bt_mesh_elem_find_group(elem, addr)) {
return elem;
}
} else if (elem->addr == addr) {
for (index = 0; index < dev_comp->elem_count; index++) {
struct bt_mesh_elem *elem = &dev_comp->elem[index];
if (bt_mesh_elem_find_group(elem, addr)) {
return elem;
}
}
@ -616,8 +630,6 @@ bool bt_mesh_fixed_group_match(u16_t addr)
}
}
u32_t mesh_opcode;
void bt_mesh_model_recv(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf)
{
struct bt_mesh_model *models, *model;
@ -637,8 +649,6 @@ void bt_mesh_model_recv(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf)
BT_DBG("OpCode 0x%08x", opcode);
mesh_opcode = opcode;
for (i = 0; i < dev_comp->elem_count; i++) {
struct bt_mesh_elem *elem = &dev_comp->elem[i];
@ -728,67 +738,72 @@ void bt_mesh_model_msg_init(struct net_buf_simple *msg, u32_t opcode)
net_buf_simple_add_le16(msg, opcode & 0xffff);
}
static int model_send(struct bt_mesh_model *model,
struct bt_mesh_net_tx *tx, bool implicit_bind,
struct net_buf_simple *msg,
const struct bt_mesh_send_cb *cb, void *cb_data)
static bool ready_to_send(u8_t role, u16_t dst)
{
bool check = false;
u8_t role;
BT_DBG("net_idx 0x%04x app_idx 0x%04x dst 0x%04x", tx->ctx->net_idx,
tx->ctx->app_idx, tx->ctx->addr);
BT_DBG("len %u: %s", msg->len, bt_hex(msg->data, msg->len));
role = bt_mesh_get_model_role(model, tx->ctx->srv_send);
if (role == ROLE_NVAL) {
BT_ERR("%s, Failed to get model role", __func__);
return -EINVAL;
}
#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER
if (role == NODE) {
if (!bt_mesh_is_provisioned()) {
BT_ERR("%s, Local node is not yet provisioned", __func__);
return -EAGAIN;
return false;
}
if (!bt_mesh_is_provisioner_en()) {
check = true;
return true;
}
}
#endif
#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
if (role == PROVISIONER) {
if (!provisioner_check_msg_dst_addr(tx->ctx->addr)) {
BT_ERR("%s, Failed to check DST", __func__);
return -EINVAL;
if (!provisioner_check_msg_dst_addr(dst)) {
BT_ERR("%s, Failed to find DST 0x%04x", __func__, dst);
return false;
}
if (bt_mesh_is_provisioner_en()) {
check = true;
return true;
}
}
#endif
#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
if (role == PROVISIONER) {
if (!provisioner_check_msg_dst_addr(tx->ctx->addr)) {
if (!provisioner_check_msg_dst_addr(dst)) {
BT_ERR("%s, Failed to check DST", __func__);
return -EINVAL;
return false;
}
if (bt_mesh_is_provisioner_en()) {
check = true;
return true;
}
} else {
if (!bt_mesh_is_provisioned()) {
BT_ERR("%s, Local node is not yet provisioned", __func__);
return -EAGAIN;
return false;
}
check = true;
return true;
}
#endif
if (!check) {
return false;
}
static int model_send(struct bt_mesh_model *model,
struct bt_mesh_net_tx *tx, bool implicit_bind,
struct net_buf_simple *msg,
const struct bt_mesh_send_cb *cb, void *cb_data)
{
u8_t role;
role = bt_mesh_get_device_role(model, tx->ctx->srv_send);
if (role == ROLE_NVAL) {
BT_ERR("%s, Failed to get model role", __func__);
return -EINVAL;
}
BT_DBG("net_idx 0x%04x app_idx 0x%04x dst 0x%04x", tx->ctx->net_idx,
tx->ctx->app_idx, tx->ctx->addr);
BT_DBG("len %u: %s", msg->len, bt_hex(msg->data, msg->len));
if (!ready_to_send(role, tx->ctx->addr)) {
BT_ERR("%s, fail", __func__);
return -EINVAL;
}
@ -819,42 +834,13 @@ int bt_mesh_model_send(struct bt_mesh_model *model,
struct bt_mesh_subnet *sub = NULL;
u8_t role;
role = bt_mesh_get_model_role(model, ctx->srv_send);
role = bt_mesh_get_device_role(model, ctx->srv_send);
if (role == ROLE_NVAL) {
BT_ERR("%s, Failed to get model role", __func__);
return -EINVAL;
}
#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER
if (role == NODE) {
if (!bt_mesh_is_provisioner_en()) {
sub = bt_mesh_subnet_get(ctx->net_idx);
}
}
#endif
#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
if (role == PROVISIONER) {
if (bt_mesh_is_provisioner_en()) {
sub = provisioner_subnet_get(ctx->net_idx);
}
}
#endif
#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
if (role == NODE) {
sub = bt_mesh_subnet_get(ctx->net_idx);
} else if (role == PROVISIONER) {
if (bt_mesh_is_provisioner_en()) {
sub = provisioner_subnet_get(ctx->net_idx);
}
} else if (role == FAST_PROV) {
#if CONFIG_BLE_MESH_FAST_PROV
sub = get_fast_prov_subnet(ctx->net_idx);
#endif
}
#endif
sub = bt_mesh_tx_netkey_get(role, ctx->net_idx);
if (!sub) {
BT_ERR("%s, Failed to get subnet", __func__);
return -EINVAL;
@ -889,7 +875,7 @@ int bt_mesh_model_publish(struct bt_mesh_model *model)
BT_DBG("%s", __func__);
if (!pub) {
if (!pub || !pub->msg) {
BT_ERR("%s, Model has no publication support", __func__);
return -ENOTSUP;
}
@ -899,34 +885,7 @@ int bt_mesh_model_publish(struct bt_mesh_model *model)
return -EADDRNOTAVAIL;
}
#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER
if (pub->dev_role == NODE) {
if (bt_mesh_is_provisioned()) {
key = bt_mesh_app_key_find(pub->key);
}
}
#endif
#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
if (pub->dev_role == PROVISIONER) {
if (bt_mesh_is_provisioner_en()) {
key = provisioner_app_key_find(pub->key);
}
}
#endif
#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
if (pub->dev_role == NODE) {
if (bt_mesh_is_provisioned()) {
key = bt_mesh_app_key_find(pub->key);
}
} else if (pub->dev_role == PROVISIONER) {
if (bt_mesh_is_provisioner_en()) {
key = provisioner_app_key_find(pub->key);
}
}
#endif
key = bt_mesh_tx_appkey_get(pub->dev_role, pub->key, BLE_MESH_KEY_ANY);
if (!key) {
BT_ERR("%s, Failed to get AppKey", __func__);
return -EADDRNOTAVAIL;
@ -950,34 +909,7 @@ int bt_mesh_model_publish(struct bt_mesh_model *model)
tx.friend_cred = pub->cred;
#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER
if (pub->dev_role == NODE) {
if (bt_mesh_is_provisioned()) {
tx.sub = bt_mesh_subnet_get(ctx.net_idx);
}
}
#endif
#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
if (pub->dev_role == PROVISIONER) {
if (bt_mesh_is_provisioner_en()) {
tx.sub = provisioner_subnet_get(ctx.net_idx);
}
}
#endif
#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
if (pub->dev_role == NODE) {
if (bt_mesh_is_provisioned()) {
tx.sub = bt_mesh_subnet_get(ctx.net_idx);
}
} else if (pub->dev_role == PROVISIONER) {
if (bt_mesh_is_provisioner_en()) {
tx.sub = provisioner_subnet_get(ctx.net_idx);
}
}
#endif
tx.sub = bt_mesh_tx_netkey_get(pub->dev_role, ctx.net_idx);
if (!tx.sub) {
BT_ERR("%s, Failed to get subnet", __func__);
return -EADDRNOTAVAIL;
@ -1041,3 +973,281 @@ const struct bt_mesh_comp *bt_mesh_comp_get(void)
{
return dev_comp;
}
/* APIs used by messages encryption in upper transport layer & network layer */
struct bt_mesh_subnet *bt_mesh_tx_netkey_get(u8_t role, u16_t net_idx)
{
struct bt_mesh_subnet *sub = NULL;
#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER
if (role == NODE) {
if (bt_mesh_is_provisioned()) {
sub = bt_mesh_subnet_get(net_idx);
}
}
#endif
#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
if (role == PROVISIONER) {
if (bt_mesh_is_provisioner_en()) {
sub = provisioner_subnet_get(net_idx);
}
}
#endif
#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
if (role == NODE) {
if (bt_mesh_is_provisioned()) {
sub = bt_mesh_subnet_get(net_idx);
}
} else if (role == PROVISIONER) {
if (bt_mesh_is_provisioner_en()) {
sub = provisioner_subnet_get(net_idx);
}
} else if (role == FAST_PROV) {
#if CONFIG_BLE_MESH_FAST_PROV
sub = fast_prov_subnet_get(net_idx);
#endif
}
#endif
return sub;
}
const u8_t *bt_mesh_tx_devkey_get(u8_t role, u16_t dst)
{
const u8_t *key = NULL;
#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER
if (role == NODE) {
if (bt_mesh_is_provisioned()) {
key = bt_mesh.dev_key;
}
}
#endif
#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
if (role == PROVISIONER) {
if (bt_mesh_is_provisioner_en()) {
key = provisioner_dev_key_get(dst);
}
}
#endif
#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
if (role == NODE) {
if (bt_mesh_is_provisioned()) {
key = bt_mesh.dev_key;
}
} else if (role == PROVISIONER) {
if (bt_mesh_is_provisioner_en()) {
key = provisioner_dev_key_get(dst);
}
} else if (role == FAST_PROV) {
#if CONFIG_BLE_MESH_FAST_PROV
key = fast_prov_dev_key_get(dst);
#endif
}
#endif
return key;
}
struct bt_mesh_app_key *bt_mesh_tx_appkey_get(u8_t role, u16_t app_idx, u16_t net_idx)
{
struct bt_mesh_app_key *key = NULL;
#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER
if (role == NODE) {
if (bt_mesh_is_provisioned()) {
key = bt_mesh_app_key_find(app_idx);
}
}
#endif
#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
if (role == PROVISIONER) {
if (bt_mesh_is_provisioner_en()) {
key = provisioner_app_key_find(app_idx);
}
}
#endif
#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
if (role == NODE) {
if (bt_mesh_is_provisioned()) {
key = bt_mesh_app_key_find(app_idx);
}
} else if (role == PROVISIONER) {
if (bt_mesh_is_provisioner_en()) {
key = provisioner_app_key_find(app_idx);
}
} else if (role == FAST_PROV) {
#if CONFIG_BLE_MESH_FAST_PROV
key = fast_prov_app_key_find(net_idx, app_idx);
#endif
}
#endif
return key;
}
/* APIs used by messages decryption in network layer & upper transport layer */
size_t bt_mesh_rx_netkey_size(void)
{
size_t size = 0;
#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER
if (bt_mesh_is_provisioned()) {
size = ARRAY_SIZE(bt_mesh.sub);
}
#endif
#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
if (bt_mesh_is_provisioner_en()) {
size = ARRAY_SIZE(bt_mesh.p_sub);
}
#endif
#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
size = ARRAY_SIZE(bt_mesh.sub);
if (bt_mesh_is_provisioner_en()) {
size += ARRAY_SIZE(bt_mesh.p_sub);
}
#endif
return size;
}
struct bt_mesh_subnet *bt_mesh_rx_netkey_get(size_t index)
{
struct bt_mesh_subnet *sub = NULL;
#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER
if (bt_mesh_is_provisioned()) {
sub = &bt_mesh.sub[index];
}
#endif
#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
if (bt_mesh_is_provisioner_en()) {
sub = bt_mesh.p_sub[index];
}
#endif
#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
if (index < ARRAY_SIZE(bt_mesh.sub)) {
sub = &bt_mesh.sub[index];
} else {
sub = bt_mesh.p_sub[index - ARRAY_SIZE(bt_mesh.sub)];
}
#endif
return sub;
}
size_t bt_mesh_rx_devkey_size(void)
{
size_t size = 0;
#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER
if (!bt_mesh_is_provisioner_en()) {
size = 1;
}
#endif
#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
if (bt_mesh_is_provisioner_en()) {
size = 1;
}
#endif
#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
size = 1;
if (bt_mesh_is_provisioner_en()) {
size += 1;
}
#endif
return size;
}
const u8_t *bt_mesh_rx_devkey_get(size_t index, u16_t src)
{
const u8_t *key = NULL;
#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER
if (bt_mesh_is_provisioned()) {
key = bt_mesh.dev_key;
}
#endif
#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
if (bt_mesh_is_provisioner_en()) {
key = provisioner_dev_key_get(src);
}
#endif
#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
if (index < 1) {
key = bt_mesh.dev_key;
} else {
key = provisioner_dev_key_get(src);
}
#endif
return key;
}
size_t bt_mesh_rx_appkey_size(void)
{
size_t size = 0;
#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER
if (bt_mesh_is_provisioned()) {
size = ARRAY_SIZE(bt_mesh.app_keys);
}
#endif
#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
if (bt_mesh_is_provisioner_en()) {
size = ARRAY_SIZE(bt_mesh.p_app_keys);
}
#endif
#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
size = ARRAY_SIZE(bt_mesh.app_keys);
if (bt_mesh_is_provisioner_en()) {
size += ARRAY_SIZE(bt_mesh.p_app_keys);
}
#endif
return size;
}
struct bt_mesh_app_key *bt_mesh_rx_appkey_get(size_t index)
{
struct bt_mesh_app_key *key = NULL;
#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER
if (bt_mesh_is_provisioned()) {
key = &bt_mesh.app_keys[index];
}
#endif
#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
if (bt_mesh_is_provisioner_en()) {
key = bt_mesh.p_app_keys[index];
}
#endif
#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
if (index < ARRAY_SIZE(bt_mesh.app_keys)) {
key = &bt_mesh.app_keys[index];
} else {
key = bt_mesh.p_app_keys[index - ARRAY_SIZE(bt_mesh.app_keys)];
}
#endif
return key;
}

View File

@ -57,4 +57,22 @@ void bt_mesh_model_recv(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf);
int bt_mesh_comp_register(const struct bt_mesh_comp *comp);
struct bt_mesh_subnet *bt_mesh_tx_netkey_get(u8_t role, u16_t net_idx);
const u8_t *bt_mesh_tx_devkey_get(u8_t role, u16_t dst);
struct bt_mesh_app_key *bt_mesh_tx_appkey_get(u8_t role, u16_t app_idx, u16_t net_idx);
size_t bt_mesh_rx_netkey_size(void);
struct bt_mesh_subnet *bt_mesh_rx_netkey_get(size_t index);
size_t bt_mesh_rx_devkey_size(void);
const u8_t *bt_mesh_rx_devkey_get(size_t index, u16_t src);
size_t bt_mesh_rx_appkey_size(void);
struct bt_mesh_app_key *bt_mesh_rx_appkey_get(size_t index);
#endif /* _ACCESS_H_ */

View File

@ -7,6 +7,9 @@
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdint.h>
#include <errno.h>
#include "freertos/FreeRTOS.h"
#include "freertos/queue.h"
#include "freertos/task.h"
@ -186,6 +189,8 @@ static void adv_thread(void *p)
BT_ERR("%s, xQueueSendToFront failed", __func__);
}
}
} else {
net_buf_unref(*buf);
}
/* Give other threads a chance to run */
@ -381,12 +386,16 @@ static void bt_mesh_scan_cb(const bt_mesh_addr_t *addr, s8_t rssi,
void bt_mesh_adv_init(void)
{
xBleMeshQueue = xQueueCreate(150, sizeof(bt_mesh_msg_t));
xTaskCreatePinnedToCore(adv_thread, "BLE_Mesh_ADV_Task", 3072, NULL,
configASSERT(xBleMeshQueue);
int ret = xTaskCreatePinnedToCore(adv_thread, "BLE_Mesh_ADV_Task", 3072, NULL,
configMAX_PRIORITIES - 7, NULL, TASK_PINNED_TO_CORE);
configASSERT(ret == pdTRUE);
}
int bt_mesh_scan_enable(void)
{
int err;
struct bt_mesh_scan_param scan_param = {
.type = BLE_MESH_SCAN_PASSIVE,
#if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN)
@ -400,12 +409,26 @@ int bt_mesh_scan_enable(void)
BT_DBG("%s", __func__);
return bt_le_scan_start(&scan_param, bt_mesh_scan_cb);
err = bt_le_scan_start(&scan_param, bt_mesh_scan_cb);
if (err && err != -EALREADY) {
BT_ERR("starting scan failed (err %d)", err);
return err;
}
return 0;
}
int bt_mesh_scan_disable(void)
{
int err;
BT_DBG("%s", __func__);
return bt_le_scan_stop();
err = bt_le_scan_stop();
if (err && err != -EALREADY) {
BT_ERR("stopping scan failed (err %d)", err);
return err;
}
return 0;
}

View File

@ -12,6 +12,7 @@
#include <stdbool.h>
#include "osi/allocator.h"
#include "osi/mutex.h"
#include "sdkconfig.h"
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLE_MESH_DEBUG_MODEL)
@ -82,36 +83,50 @@ static const bt_mesh_client_op_pair_t cfg_op_pair[] = {
{ OP_NET_TRANSMIT_SET, OP_NET_TRANSMIT_STATUS },
};
static osi_mutex_t cfg_client_mutex;
static void bt_mesh_cfg_client_mutex_new(void)
{
static bool init;
if (!init) {
osi_mutex_new(&cfg_client_mutex);
init = true;
}
}
static void bt_mesh_cfg_client_lock(void)
{
osi_mutex_lock(&cfg_client_mutex, OSI_MUTEX_MAX_TIMEOUT);
}
static void bt_mesh_cfg_client_unlock(void)
{
osi_mutex_unlock(&cfg_client_mutex);
}
static void timeout_handler(struct k_work *work)
{
config_internal_data_t *internal = NULL;
bt_mesh_config_client_t *client = NULL;
struct k_delayed_work *timer = NULL;
bt_mesh_client_node_t *node = NULL;
BT_WARN("Receive configuration status message timeout");
node = CONTAINER_OF(work, bt_mesh_client_node_t, timer.work);
if (!node || !node->ctx.model) {
BT_ERR("%s, Invalid parameter", __func__);
return;
bt_mesh_cfg_client_lock();
timer = CONTAINER_OF(work, struct k_delayed_work, work);
if (timer && !k_delayed_work_free(timer)) {
node = CONTAINER_OF(work, bt_mesh_client_node_t, timer.work);
if (node) {
bt_mesh_config_client_cb_evt_to_btc(node->opcode,
BTC_BLE_MESH_EVT_CONFIG_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0);
// Don't forget to release the node at the end.
bt_mesh_client_free_node(node);
}
}
client = (bt_mesh_config_client_t *)node->ctx.model->user_data;
if (!client) {
BT_ERR("%s, Config Client user_data is NULL", __func__);
return;
}
internal = (config_internal_data_t *)client->internal_data;
if (!internal) {
BT_ERR("%s, Config Client internal_data is NULL", __func__);
return;
}
bt_mesh_callback_config_status_to_btc(node->opcode, 0x03, node->ctx.model,
&node->ctx, NULL, 0);
bt_mesh_client_free_node(&internal->queue, node);
bt_mesh_cfg_client_unlock();
return;
}
@ -120,7 +135,6 @@ static void cfg_client_cancel(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
void *status, size_t len)
{
config_internal_data_t *data = NULL;
bt_mesh_client_node_t *node = NULL;
struct net_buf_simple buf = {0};
u8_t evt_type = 0xFF;
@ -130,16 +144,13 @@ static void cfg_client_cancel(struct bt_mesh_model *model,
return;
}
data = (config_internal_data_t *)cli->internal_data;
if (!data) {
BT_ERR("%s, Config Client internal_data is NULL", __func__);
return;
}
/* If it is a publish message, sent to the user directly. */
buf.data = (u8_t *)status;
buf.len = (u16_t)len;
node = bt_mesh_is_model_message_publish(model, ctx, &buf, true);
bt_mesh_cfg_client_lock();
node = bt_mesh_is_client_recv_publish_msg(model, ctx, &buf, true);
if (!node) {
BT_DBG("Unexpected config status message 0x%x", ctx->recv_op);
} else {
@ -163,7 +174,7 @@ static void cfg_client_cancel(struct bt_mesh_model *model,
case OP_HEARTBEAT_SUB_GET:
case OP_LPN_TIMEOUT_GET:
case OP_NET_TRANSMIT_GET:
evt_type = 0x00;
evt_type = BTC_BLE_MESH_EVT_CONFIG_CLIENT_GET_STATE;
break;
case OP_BEACON_SET:
case OP_DEFAULT_TTL_SET:
@ -193,18 +204,22 @@ static void cfg_client_cancel(struct bt_mesh_model *model,
case OP_HEARTBEAT_PUB_SET:
case OP_HEARTBEAT_SUB_SET:
case OP_NET_TRANSMIT_SET:
evt_type = 0x01;
evt_type = BTC_BLE_MESH_EVT_CONFIG_CLIENT_SET_STATE;
break;
default:
break;
}
bt_mesh_callback_config_status_to_btc(node->opcode, evt_type, model,
ctx, (const u8_t *)status, len);
// Don't forget to release the node at the end.
bt_mesh_client_free_node(&data->queue, node);
if (!k_delayed_work_free(&node->timer)) {
bt_mesh_config_client_cb_evt_to_btc(
node->opcode, evt_type, model, ctx, (const u8_t *)status, len);
// Don't forget to release the node at the end.
bt_mesh_client_free_node(node);
}
}
bt_mesh_cfg_client_unlock();
switch (ctx->recv_op) {
case OP_DEV_COMP_DATA_STATUS: {
struct bt_mesh_cfg_comp_data_status *val;
@ -1653,5 +1668,7 @@ int bt_mesh_cfg_cli_init(struct bt_mesh_model *model, bool primary)
/* Configuration Model security is device-key based */
model->keys[0] = BLE_MESH_KEY_DEV;
bt_mesh_cfg_client_mutex_new();
return 0;
}

View File

@ -53,55 +53,6 @@ static struct label {
u8_t uuid[16];
} labels[CONFIG_BLE_MESH_LABEL_COUNT];
static void hb_send(struct bt_mesh_model *model)
{
struct bt_mesh_cfg_srv *cfg = model->user_data;
u16_t feat = 0U;
struct __packed {
u8_t init_ttl;
u16_t feat;
} hb;
struct bt_mesh_msg_ctx ctx = {
.net_idx = cfg->hb_pub.net_idx,
.app_idx = BLE_MESH_KEY_UNUSED,
.addr = cfg->hb_pub.dst,
.send_ttl = cfg->hb_pub.ttl,
};
struct bt_mesh_net_tx tx = {
.sub = bt_mesh_subnet_get(cfg->hb_pub.net_idx),
.ctx = &ctx,
.src = bt_mesh_model_elem(model)->addr,
.xmit = bt_mesh_net_transmit_get(),
};
hb.init_ttl = cfg->hb_pub.ttl;
if (bt_mesh_relay_get() == BLE_MESH_RELAY_ENABLED) {
feat |= BLE_MESH_FEAT_RELAY;
}
if (bt_mesh_gatt_proxy_get() == BLE_MESH_GATT_PROXY_ENABLED) {
feat |= BLE_MESH_FEAT_PROXY;
}
if (bt_mesh_friend_get() == BLE_MESH_FRIEND_ENABLED) {
feat |= BLE_MESH_FEAT_FRIEND;
}
#if defined(CONFIG_BLE_MESH_LOW_POWER)
if (bt_mesh.lpn.state != BLE_MESH_LPN_DISABLED) {
feat |= BLE_MESH_FEAT_LOW_POWER;
}
#endif
hb.feat = sys_cpu_to_be16(feat);
BT_DBG("InitTTL %u feat 0x%04x", cfg->hb_pub.ttl, feat);
bt_mesh_ctl_send(&tx, TRANS_CTL_OP_HEARTBEAT, &hb, sizeof(hb),
NULL, NULL, NULL);
}
static int comp_add_elem(struct net_buf_simple *buf, struct bt_mesh_elem *elem,
bool primary)
{
@ -522,8 +473,8 @@ static void app_key_add(struct bt_mesh_model *model,
}
#if defined(CONFIG_BLE_MESH_FAST_PROV)
bt_mesh_callback_cfg_server_event_to_btc(0x0, model, ctx,
(u8_t *)&key_app_idx, sizeof(u16_t));
bt_mesh_config_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_CONFIG_SERVER_RECV_MSG,
model, ctx, (u8_t *)&key_app_idx, sizeof(u16_t));
#endif
}
@ -836,7 +787,6 @@ static void gatt_proxy_set(struct bt_mesh_model *model,
struct net_buf_simple *buf)
{
struct bt_mesh_cfg_srv *cfg = model->user_data;
struct bt_mesh_subnet *sub;
BT_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x len %u: %s",
ctx->net_idx, ctx->app_idx, ctx->addr, buf->len,
@ -895,9 +845,8 @@ static void gatt_proxy_set(struct bt_mesh_model *model,
bt_mesh_adv_update();
#endif
sub = bt_mesh_subnet_get(cfg->hb_pub.net_idx);
if ((cfg->hb_pub.feat & BLE_MESH_FEAT_PROXY) && sub) {
hb_send(model);
if (cfg->hb_pub.feat & BLE_MESH_FEAT_PROXY) {
bt_mesh_heartbeat_send();
}
send_status:
@ -992,7 +941,6 @@ static void relay_set(struct bt_mesh_model *model,
if (!cfg) {
BT_WARN("No Configuration Server context available");
} else if (buf->data[0] == 0x00 || buf->data[0] == 0x01) {
struct bt_mesh_subnet *sub;
bool change;
if (cfg->relay == BLE_MESH_RELAY_NOT_SUPPORTED) {
@ -1013,9 +961,8 @@ static void relay_set(struct bt_mesh_model *model,
BLE_MESH_TRANSMIT_COUNT(cfg->relay_retransmit),
BLE_MESH_TRANSMIT_INT(cfg->relay_retransmit));
sub = bt_mesh_subnet_get(cfg->hb_pub.net_idx);
if ((cfg->hb_pub.feat & BLE_MESH_FEAT_RELAY) && sub && change) {
hb_send(model);
if ((cfg->hb_pub.feat & BLE_MESH_FEAT_RELAY) && change) {
bt_mesh_heartbeat_send();
}
} else {
BT_WARN("Invalid Relay value 0x%02x", buf->data[0]);
@ -2731,7 +2678,6 @@ static void friend_set(struct bt_mesh_model *model,
struct net_buf_simple *buf)
{
struct bt_mesh_cfg_srv *cfg = model->user_data;
struct bt_mesh_subnet *sub;
BT_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x len %u: %s",
ctx->net_idx, ctx->app_idx, ctx->addr, buf->len,
@ -2765,9 +2711,8 @@ static void friend_set(struct bt_mesh_model *model,
}
}
sub = bt_mesh_subnet_get(cfg->hb_pub.net_idx);
if ((cfg->hb_pub.feat & BLE_MESH_FEAT_FRIEND) && sub) {
hb_send(model);
if (cfg->hb_pub.feat & BLE_MESH_FEAT_FRIEND) {
bt_mesh_heartbeat_send();
}
send_status:
@ -3121,15 +3066,10 @@ static void hb_sub_send_status(struct bt_mesh_model *model,
net_buf_simple_add_u8(&msg, status);
net_buf_simple_add_le16(&msg, cfg->hb_sub.src);
net_buf_simple_add_le16(&msg, cfg->hb_sub.dst);
if (cfg->hb_sub.src == BLE_MESH_ADDR_UNASSIGNED ||
cfg->hb_sub.dst == BLE_MESH_ADDR_UNASSIGNED) {
memset(net_buf_simple_add(&msg, 4), 0, 4);
} else {
net_buf_simple_add_u8(&msg, hb_log(period));
net_buf_simple_add_u8(&msg, hb_log(cfg->hb_sub.count));
net_buf_simple_add_u8(&msg, cfg->hb_sub.min_hops);
net_buf_simple_add_u8(&msg, cfg->hb_sub.max_hops);
}
net_buf_simple_add_u8(&msg, hb_log(period));
net_buf_simple_add_u8(&msg, hb_log(cfg->hb_sub.count));
net_buf_simple_add_u8(&msg, cfg->hb_sub.min_hops);
net_buf_simple_add_u8(&msg, cfg->hb_sub.max_hops);
if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) {
BT_ERR("%s, Unable to send Config Heartbeat Subscription Status", __func__);
@ -3188,9 +3128,13 @@ static void heartbeat_sub_set(struct bt_mesh_model *model,
* trigger clearing of the values according to
* MESH/NODE/CFG/HBS/BV-02-C.
*/
if (cfg->hb_sub.src != sub_src || cfg->hb_sub.dst != sub_dst) {
if (sub_src == BLE_MESH_ADDR_UNASSIGNED ||
sub_dst == BLE_MESH_ADDR_UNASSIGNED) {
cfg->hb_sub.src = BLE_MESH_ADDR_UNASSIGNED;
cfg->hb_sub.dst = BLE_MESH_ADDR_UNASSIGNED;
cfg->hb_sub.min_hops = BLE_MESH_TTL_MAX;
cfg->hb_sub.max_hops = 0U;
cfg->hb_sub.count = 0U;
}
period_ms = 0;
@ -3280,7 +3224,6 @@ static void hb_publish(struct k_work *work)
struct bt_mesh_cfg_srv *cfg = CONTAINER_OF(work,
struct bt_mesh_cfg_srv,
hb_pub.timer.work);
struct bt_mesh_model *model = cfg->model;
struct bt_mesh_subnet *sub;
u16_t period_ms;
@ -3303,7 +3246,7 @@ static void hb_publish(struct k_work *work)
k_delayed_work_submit(&cfg->hb_pub.timer, period_ms);
}
hb_send(model);
bt_mesh_heartbeat_send();
if (cfg->hb_pub.count != 0xffff) {
cfg->hb_pub.count--;

View File

@ -261,7 +261,7 @@ static int bt_mesh_ccm_decrypt(const u8_t key[16], u8_t nonce[13],
}
}
for (i = 0; i < aad_len; i++, j++) {
for (; i < aad_len; i++, j++) {
pmsg[i] = Xn[i] ^ aad[j];
}
@ -425,7 +425,7 @@ static int bt_mesh_ccm_encrypt(const u8_t key[16], u8_t nonce[13],
}
}
for (i = 0; i < aad_len; i++, j++) {
for (; i < aad_len; i++, j++) {
pmsg[i] = Xn[i] ^ aad[j];
}

View File

@ -70,48 +70,6 @@ static struct bt_mesh_adv *adv_alloc(int id)
return &adv_pool[id].adv;
}
static void discard_buffer(void)
{
struct bt_mesh_friend *frnd = &bt_mesh.frnd[0];
struct net_buf *buf;
int i;
/* Find the Friend context with the most queued buffers */
for (i = 1; i < ARRAY_SIZE(bt_mesh.frnd); i++) {
if (bt_mesh.frnd[i].queue_size > frnd->queue_size) {
frnd = &bt_mesh.frnd[i];
}
}
buf = net_buf_slist_get(&frnd->queue);
__ASSERT_NO_MSG(buf != NULL);
BT_WARN("Discarding buffer %p for LPN 0x%04x", buf, frnd->lpn);
net_buf_unref(buf);
}
static struct net_buf *friend_buf_alloc(u16_t src)
{
struct net_buf *buf;
BT_DBG("src 0x%04x", src);
do {
buf = bt_mesh_adv_create_from_pool(&friend_buf_pool, adv_alloc,
BLE_MESH_ADV_DATA,
FRIEND_XMIT, K_NO_WAIT);
if (!buf) {
discard_buffer();
}
} while (!buf);
BLE_MESH_ADV(buf)->addr = src;
FRIEND_ADV(buf)->seq_auth = TRANS_SEQ_AUTH_NVAL;
BT_DBG("allocated buf %p", buf);
return buf;
}
static bool is_lpn_unicast(struct bt_mesh_friend *frnd, u16_t addr)
{
if (frnd->lpn == BLE_MESH_ADDR_UNASSIGNED) {
@ -151,6 +109,20 @@ struct bt_mesh_friend *bt_mesh_friend_find(u16_t net_idx, u16_t lpn_addr,
return NULL;
}
static void purge_buffers(sys_slist_t *list)
{
while (!sys_slist_is_empty(list)) {
struct net_buf *buf;
buf = (void *)sys_slist_get_not_empty(list);
buf->frags = NULL;
buf->flags &= ~NET_BUF_FRAGS;
net_buf_unref(buf);
}
}
/* Intentionally start a little bit late into the ReceiveWindow when
* it's large enough. This may improve reliability with some platforms,
* like the PTS, where the receiver might not have sufficiently compensated
@ -185,16 +157,13 @@ static void friend_clear(struct bt_mesh_friend *frnd)
frnd->last = NULL;
}
while (!sys_slist_is_empty(&frnd->queue)) {
net_buf_unref(net_buf_slist_get(&frnd->queue));
}
purge_buffers(&frnd->queue);
for (i = 0; i < ARRAY_SIZE(frnd->seg); i++) {
struct bt_mesh_friend_seg *seg = &frnd->seg[i];
while (!sys_slist_is_empty(&seg->queue)) {
net_buf_unref(net_buf_slist_get(&seg->queue));
}
purge_buffers(&seg->queue);
seg->seg_count = 0U;
}
frnd->valid = 0U;
@ -336,7 +305,15 @@ static struct net_buf *create_friend_pdu(struct bt_mesh_friend *frnd,
sub = bt_mesh_subnet_get(frnd->net_idx);
__ASSERT_NO_MSG(sub != NULL);
buf = friend_buf_alloc(info->src);
buf = bt_mesh_adv_create_from_pool(&friend_buf_pool, adv_alloc,
BLE_MESH_ADV_DATA,
FRIEND_XMIT, K_NO_WAIT);
if (!buf) {
return NULL;
}
BLE_MESH_ADV(buf)->addr = info->src;
FRIEND_ADV(buf)->seq_auth = TRANS_SEQ_AUTH_NVAL;
/* Friend Offer needs master security credentials */
if (info->ctl && TRANS_CTL_OP(sdu->data) == TRANS_CTL_OP_FRIEND_OFFER) {
@ -688,7 +665,7 @@ static void clear_procedure_start(struct bt_mesh_friend *frnd)
{
BT_DBG("LPN 0x%04x (old) Friend 0x%04x", frnd->lpn, frnd->clear.frnd);
frnd->clear.start = k_uptime_get_32() + (2 * frnd->poll_to);
frnd->clear.start = k_uptime_get_32();
frnd->clear.repeat_sec = 1U;
send_friend_clear(frnd);
@ -897,7 +874,8 @@ init_friend:
}
static struct bt_mesh_friend_seg *get_seg(struct bt_mesh_friend *frnd,
u16_t src, u64_t *seq_auth)
u16_t src, u64_t *seq_auth,
u8_t seg_count)
{
struct bt_mesh_friend_seg *unassigned = NULL;
int i;
@ -916,12 +894,16 @@ static struct bt_mesh_friend_seg *get_seg(struct bt_mesh_friend *frnd,
}
}
if (unassigned) {
unassigned->seg_count = seg_count;
}
return unassigned;
}
static void enqueue_friend_pdu(struct bt_mesh_friend *frnd,
enum bt_mesh_friend_pdu_type type,
struct net_buf *buf)
u8_t seg_count, struct net_buf *buf)
{
struct bt_mesh_friend_seg *seg;
struct friend_adv *adv;
@ -938,7 +920,7 @@ static void enqueue_friend_pdu(struct bt_mesh_friend *frnd,
}
adv = FRIEND_ADV(buf);
seg = get_seg(frnd, BLE_MESH_ADV(buf)->addr, &adv->seq_auth);
seg = get_seg(frnd, BLE_MESH_ADV(buf)->addr, &adv->seq_auth, seg_count);
if (!seg) {
BT_ERR("%s, No free friend segment RX contexts for 0x%04x",
__func__, BLE_MESH_ADV(buf)->addr);
@ -963,6 +945,10 @@ static void enqueue_friend_pdu(struct bt_mesh_friend *frnd,
}
sys_slist_merge_slist(&frnd->queue, &seg->queue);
seg->seg_count = 0U;
} else {
/* Mark the buffer as having more to come after it */
buf->flags |= NET_BUF_FRAGS;
}
}
@ -1028,13 +1014,17 @@ static void friend_timeout(struct k_work *work)
return;
}
frnd->last = net_buf_slist_get(&frnd->queue);
frnd->last = (void *)sys_slist_get(&frnd->queue);
if (!frnd->last) {
BT_WARN("%s, Friendship not established with 0x%04x", __func__, frnd->lpn);
friend_clear(frnd);
return;
}
/* Clear the flag we use for segment tracking */
frnd->last->flags &= ~NET_BUF_FRAGS;
frnd->last->frags = NULL;
BT_DBG("Sending buf %p from Friend Queue of LPN 0x%04x",
frnd->last, frnd->lpn);
frnd->queue_size--;
@ -1097,7 +1087,8 @@ static void friend_purge_old_ack(struct bt_mesh_friend *frnd, u64_t *seq_auth,
static void friend_lpn_enqueue_rx(struct bt_mesh_friend *frnd,
struct bt_mesh_net_rx *rx,
enum bt_mesh_friend_pdu_type type,
u64_t *seq_auth, struct net_buf_simple *sbuf)
u64_t *seq_auth, u8_t seg_count,
struct net_buf_simple *sbuf)
{
struct friend_pdu_info info;
struct net_buf *buf;
@ -1135,7 +1126,7 @@ static void friend_lpn_enqueue_rx(struct bt_mesh_friend *frnd,
FRIEND_ADV(buf)->seq_auth = *seq_auth;
}
enqueue_friend_pdu(frnd, type, buf);
enqueue_friend_pdu(frnd, type, seg_count, buf);
BT_DBG("Queued message for LPN 0x%04x, queue_size %u",
frnd->lpn, frnd->queue_size);
@ -1144,7 +1135,8 @@ static void friend_lpn_enqueue_rx(struct bt_mesh_friend *frnd,
static void friend_lpn_enqueue_tx(struct bt_mesh_friend *frnd,
struct bt_mesh_net_tx *tx,
enum bt_mesh_friend_pdu_type type,
u64_t *seq_auth, struct net_buf_simple *sbuf)
u64_t *seq_auth, u8_t seg_count,
struct net_buf_simple *sbuf)
{
struct friend_pdu_info info;
struct net_buf *buf;
@ -1179,7 +1171,7 @@ static void friend_lpn_enqueue_tx(struct bt_mesh_friend *frnd,
FRIEND_ADV(buf)->seq_auth = *seq_auth;
}
enqueue_friend_pdu(frnd, type, buf);
enqueue_friend_pdu(frnd, type, seg_count, buf);
BT_DBG("Queued message for LPN 0x%04x", frnd->lpn);
}
@ -1229,9 +1221,118 @@ bool bt_mesh_friend_match(u16_t net_idx, u16_t addr)
return false;
}
static bool friend_queue_has_space(struct bt_mesh_friend *frnd, u16_t addr,
u64_t *seq_auth, u8_t seg_count)
{
u32_t total = 0U;
int i;
if (seg_count > CONFIG_BLE_MESH_FRIEND_QUEUE_SIZE) {
return false;
}
for (i = 0; i < ARRAY_SIZE(frnd->seg); i++) {
struct bt_mesh_friend_seg *seg = &frnd->seg[i];
if (seq_auth) {
struct net_buf *buf;
/* If there's a segment queue for this message then the
* space verification has already happened.
*/
buf = (void *)sys_slist_peek_head(&seg->queue);
if (buf && BLE_MESH_ADV(buf)->addr == addr &&
FRIEND_ADV(buf)->seq_auth == *seq_auth) {
return true;
}
}
total += seg->seg_count;
}
/* If currently pending segments combined with this segmented message
* are more than the Friend Queue Size, then there's no space. This
* is because we don't have a mechanism of aborting already pending
* segmented messages to free up buffers.
*/
return (CONFIG_BLE_MESH_FRIEND_QUEUE_SIZE - total) > seg_count;
}
bool bt_mesh_friend_queue_has_space(u16_t net_idx, u16_t src, u16_t dst,
u64_t *seq_auth, u8_t seg_count)
{
bool someone_has_space = false, friend_match = false;
int i;
for (i = 0; i < ARRAY_SIZE(bt_mesh.frnd); i++) {
struct bt_mesh_friend *frnd = &bt_mesh.frnd[i];
if (!friend_lpn_matches(frnd, net_idx, dst)) {
continue;
}
friend_match = true;
if (friend_queue_has_space(frnd, src, seq_auth, seg_count)) {
someone_has_space = true;
}
}
/* If there were no matched LPNs treat this as success, so the
* transport layer can continue its work.
*/
if (!friend_match) {
return true;
}
/* From the transport layers perspective it's good enough that at
* least one Friend Queue has space. If there were multiple Friend
* matches then the destination must be a group address, in which
* case e.g. segment acks are not sent.
*/
return someone_has_space;
}
static bool friend_queue_prepare_space(struct bt_mesh_friend *frnd, u16_t addr,
u64_t *seq_auth, u8_t seg_count)
{
bool pending_segments;
u8_t avail_space;
if (!friend_queue_has_space(frnd, addr, seq_auth, seg_count)) {
return false;
}
avail_space = CONFIG_BLE_MESH_FRIEND_QUEUE_SIZE - frnd->queue_size;
pending_segments = false;
while (pending_segments || avail_space < seg_count) {
struct net_buf *buf = (void *)sys_slist_get(&frnd->queue);
if (!buf) {
BT_ERR("Unable to free up enough buffers");
return false;
}
frnd->queue_size--;
avail_space++;
pending_segments = (buf->flags & NET_BUF_FRAGS);
/* Make sure old slist entry state doesn't remain */
buf->frags = NULL;
buf->flags &= ~NET_BUF_FRAGS;
net_buf_unref(buf);
}
return true;
}
void bt_mesh_friend_enqueue_rx(struct bt_mesh_net_rx *rx,
enum bt_mesh_friend_pdu_type type,
u64_t *seq_auth, struct net_buf_simple *sbuf)
u64_t *seq_auth, u8_t seg_count,
struct net_buf_simple *sbuf)
{
int i;
@ -1248,16 +1349,25 @@ void bt_mesh_friend_enqueue_rx(struct bt_mesh_net_rx *rx,
for (i = 0; i < ARRAY_SIZE(bt_mesh.frnd); i++) {
struct bt_mesh_friend *frnd = &bt_mesh.frnd[i];
if (friend_lpn_matches(frnd, rx->sub->net_idx,
rx->ctx.recv_dst)) {
friend_lpn_enqueue_rx(frnd, rx, type, seq_auth, sbuf);
if (!friend_lpn_matches(frnd, rx->sub->net_idx,
rx->ctx.recv_dst)) {
continue;
}
if (!friend_queue_prepare_space(frnd, rx->ctx.addr, seq_auth,
seg_count)) {
continue;
}
friend_lpn_enqueue_rx(frnd, rx, type, seq_auth, seg_count,
sbuf);
}
}
bool bt_mesh_friend_enqueue_tx(struct bt_mesh_net_tx *tx,
enum bt_mesh_friend_pdu_type type,
u64_t *seq_auth, struct net_buf_simple *sbuf)
u64_t *seq_auth, u8_t seg_count,
struct net_buf_simple *sbuf)
{
bool matched = false;
int i;
@ -1273,10 +1383,19 @@ bool bt_mesh_friend_enqueue_tx(struct bt_mesh_net_tx *tx,
for (i = 0; i < ARRAY_SIZE(bt_mesh.frnd); i++) {
struct bt_mesh_friend *frnd = &bt_mesh.frnd[i];
if (friend_lpn_matches(frnd, tx->sub->net_idx, tx->ctx->addr)) {
friend_lpn_enqueue_tx(frnd, tx, type, seq_auth, sbuf);
matched = true;
if (!friend_lpn_matches(frnd, tx->sub->net_idx,
tx->ctx->addr)) {
continue;
}
if (!friend_queue_prepare_space(frnd, tx->src, seq_auth,
seg_count)) {
continue;
}
friend_lpn_enqueue_tx(frnd, tx, type, seq_auth, seg_count,
sbuf);
matched = true;
}
return matched;
@ -1316,9 +1435,8 @@ void bt_mesh_friend_clear_incomplete(struct bt_mesh_subnet *sub, u16_t src,
BT_WARN("%s, Clearing incomplete segments for 0x%04x", __func__, src);
while (!sys_slist_is_empty(&seg->queue)) {
net_buf_unref(net_buf_slist_get(&seg->queue));
}
purge_buffers(&seg->queue);
seg->seg_count = 0U;
}
}
}

View File

@ -20,12 +20,17 @@ bool bt_mesh_friend_match(u16_t net_idx, u16_t addr);
struct bt_mesh_friend *bt_mesh_friend_find(u16_t net_idx, u16_t lpn_addr,
bool valid, bool established);
bool bt_mesh_friend_queue_has_space(u16_t net_idx, u16_t src, u16_t dst,
u64_t *seq_auth, u8_t seg_count);
void bt_mesh_friend_enqueue_rx(struct bt_mesh_net_rx *rx,
enum bt_mesh_friend_pdu_type type,
u64_t *seq_auth, struct net_buf_simple *sbuf);
u64_t *seq_auth, u8_t seg_count,
struct net_buf_simple *sbuf);
bool bt_mesh_friend_enqueue_tx(struct bt_mesh_net_tx *tx,
enum bt_mesh_friend_pdu_type type,
u64_t *seq_auth, struct net_buf_simple *sbuf);
u64_t *seq_auth, u8_t seg_count,
struct net_buf_simple *sbuf);
void bt_mesh_friend_clear_incomplete(struct bt_mesh_subnet *sub, u16_t src,
u16_t dst, u64_t *seq_auth);

View File

@ -12,6 +12,7 @@
#include <stdbool.h>
#include "osi/allocator.h"
#include "osi/mutex.h"
#include "sdkconfig.h"
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLE_MESH_DEBUG_MODEL)
@ -38,36 +39,50 @@ static const bt_mesh_client_op_pair_t health_op_pair[] = {
{ OP_ATTENTION_SET, OP_ATTENTION_STATUS },
};
static osi_mutex_t health_client_mutex;
static void bt_mesh_health_client_mutex_new(void)
{
static bool init;
if (!init) {
osi_mutex_new(&health_client_mutex);
init = true;
}
}
static void bt_mesh_health_client_lock(void)
{
osi_mutex_lock(&health_client_mutex, OSI_MUTEX_MAX_TIMEOUT);
}
static void bt_mesh_health_client_unlock(void)
{
osi_mutex_unlock(&health_client_mutex);
}
static void timeout_handler(struct k_work *work)
{
health_internal_data_t *internal = NULL;
bt_mesh_health_client_t *client = NULL;
struct k_delayed_work *timer = NULL;
bt_mesh_client_node_t *node = NULL;
BT_WARN("Receive health status message timeout");
node = CONTAINER_OF(work, bt_mesh_client_node_t, timer.work);
if (!node || !node->ctx.model) {
BT_ERR("%s, Invalid parameter", __func__);
return;
bt_mesh_health_client_lock();
timer = CONTAINER_OF(work, struct k_delayed_work, work);
if (timer && !k_delayed_work_free(timer)) {
node = CONTAINER_OF(work, bt_mesh_client_node_t, timer.work);
if (node) {
bt_mesh_health_client_cb_evt_to_btc(node->opcode,
BTC_BLE_MESH_EVT_HEALTH_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0);
// Don't forget to release the node at the end.
bt_mesh_client_free_node(node);
}
}
client = (bt_mesh_health_client_t *)node->ctx.model->user_data;
if (!client) {
BT_ERR("%s, Health Client user_data is NULL", __func__);
return;
}
internal = (health_internal_data_t *)client->internal_data;
if (!internal) {
BT_ERR("%s, Health Client internal_data is NULL", __func__);
return;
}
bt_mesh_callback_health_status_to_btc(node->opcode, 0x03, node->ctx.model,
&node->ctx, NULL, 0);
bt_mesh_client_free_node(&internal->queue, node);
bt_mesh_health_client_unlock();
return;
}
@ -76,7 +91,6 @@ static void health_client_cancel(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
void *status, size_t len)
{
health_internal_data_t *data = NULL;
bt_mesh_client_node_t *node = NULL;
struct net_buf_simple buf = {0};
u8_t evt_type = 0xFF;
@ -86,16 +100,13 @@ static void health_client_cancel(struct bt_mesh_model *model,
return;
}
data = (health_internal_data_t *)health_cli->internal_data;
if (!data) {
BT_ERR("%s, Health Client internal_data is NULL", __func__);
return;
}
/* If it is a publish message, sent to the user directly. */
buf.data = (u8_t *)status;
buf.len = (u16_t)len;
node = bt_mesh_is_model_message_publish(model, ctx, &buf, true);
bt_mesh_health_client_lock();
node = bt_mesh_is_client_recv_publish_msg(model, ctx, &buf, true);
if (!node) {
BT_DBG("Unexpected health status message 0x%x", ctx->recv_op);
} else {
@ -103,24 +114,28 @@ static void health_client_cancel(struct bt_mesh_model *model,
case OP_HEALTH_FAULT_GET:
case OP_HEALTH_PERIOD_GET:
case OP_ATTENTION_GET:
evt_type = 0x00;
evt_type = BTC_BLE_MESH_EVT_HEALTH_CLIENT_GET_STATE;
break;
case OP_HEALTH_FAULT_CLEAR:
case OP_HEALTH_FAULT_TEST:
case OP_HEALTH_PERIOD_SET:
case OP_ATTENTION_SET:
evt_type = 0x01;
evt_type = BTC_BLE_MESH_EVT_HEALTH_CLIENT_SET_STATE;
break;
default:
break;
}
bt_mesh_callback_health_status_to_btc(node->opcode, evt_type, model,
ctx, (const u8_t *)status, len);
// Don't forget to release the node at the end.
bt_mesh_client_free_node(&data->queue, node);
if (!k_delayed_work_free(&node->timer)) {
bt_mesh_health_client_cb_evt_to_btc(
node->opcode, evt_type, model, ctx, (const u8_t *)status, len);
// Don't forget to release the node at the end.
bt_mesh_client_free_node(node);
}
}
bt_mesh_health_client_unlock();
switch (ctx->recv_op) {
case OP_HEALTH_FAULT_STATUS: {
struct bt_mesh_health_fault_status *val;
@ -169,7 +184,7 @@ static void health_current_status(struct bt_mesh_model *model,
bt_hex(buf->data, buf->len));
/* Health current status is a publish message, sent to the user directly. */
if (!(node = bt_mesh_is_model_message_publish(model, ctx, buf, true))) {
if (!(node = bt_mesh_is_client_recv_publish_msg(model, ctx, buf, true))) {
return;
}
@ -453,6 +468,8 @@ int bt_mesh_health_cli_init(struct bt_mesh_model *model, bool primary)
client->op_pair = health_op_pair;
client->internal_data = internal;
bt_mesh_health_client_mutex_new();
/* Set the default health client pointer */
if (!health_cli) {
health_cli = client;

View File

@ -13,7 +13,7 @@
#include "mesh_access.h"
#include "mesh_kernel.h"
#include "model_common.h"
#include "client_common.h"
/**
* @brief Bluetooth Mesh
@ -23,8 +23,8 @@
*/
/* Config client model common structure */
typedef bt_mesh_client_common_t bt_mesh_config_client_t;
typedef bt_mesh_internal_data_t config_internal_data_t;
typedef bt_mesh_client_user_data_t bt_mesh_config_client_t;
typedef bt_mesh_client_internal_data_t config_internal_data_t;
extern const struct bt_mesh_model_op bt_mesh_cfg_cli_op[];

View File

@ -13,7 +13,7 @@
#include "mesh_access.h"
#include "mesh_kernel.h"
#include "model_common.h"
#include "client_common.h"
/**
* @brief Bluetooth Mesh
@ -23,10 +23,8 @@
*/
/* Health client model common structure */
typedef bt_mesh_client_common_t bt_mesh_health_client_t;
typedef bt_mesh_internal_data_t health_internal_data_t;
typedef bt_mesh_internal_data_t health_client_internal_data_t;
typedef bt_mesh_client_user_data_t bt_mesh_health_client_t;
typedef bt_mesh_client_internal_data_t health_internal_data_t;
extern const struct bt_mesh_model_op bt_mesh_health_cli_op[];

View File

@ -88,7 +88,7 @@ struct bt_mesh_elem {
#define BLE_MESH_MODEL_ID_GEN_BATTERY_SRV 0x100c
#define BLE_MESH_MODEL_ID_GEN_BATTERY_CLI 0x100d
#define BLE_MESH_MODEL_ID_GEN_LOCATION_SRV 0x100e
#define BLE_MESH_MODEL_ID_GEN_LOCATION_SETUPSRV 0x100f
#define BLE_MESH_MODEL_ID_GEN_LOCATION_SETUP_SRV 0x100f
#define BLE_MESH_MODEL_ID_GEN_LOCATION_CLI 0x1010
#define BLE_MESH_MODEL_ID_GEN_ADMIN_PROP_SRV 0x1011
#define BLE_MESH_MODEL_ID_GEN_MANUFACTURER_PROP_SRV 0x1012
@ -123,7 +123,7 @@ struct bt_mesh_elem {
#define BLE_MESH_MODEL_ID_LIGHT_XYL_SETUP_SRV 0x130d
#define BLE_MESH_MODEL_ID_LIGHT_XYL_CLI 0x130e
#define BLE_MESH_MODEL_ID_LIGHT_LC_SRV 0x130f
#define BLE_MESH_MODEL_ID_LIGHT_LC_SETUPSRV 0x1310
#define BLE_MESH_MODEL_ID_LIGHT_LC_SETUP_SRV 0x1310
#define BLE_MESH_MODEL_ID_LIGHT_LC_CLI 0x1311
/** Message sending context. */

View File

@ -26,6 +26,7 @@
#include "beacon.h"
#include "foundation.h"
#include "lpn.h"
#include "cfg_srv.h"
#ifdef CONFIG_BLE_MESH_LOW_POWER
@ -201,6 +202,7 @@ static int send_friend_clear(void)
static void clear_friendship(bool force, bool disable)
{
struct bt_mesh_cfg_srv *cfg = bt_mesh_cfg_get();
struct bt_mesh_lpn *lpn = &bt_mesh.lpn;
BT_DBG("force %u disable %u", force, disable);
@ -248,6 +250,10 @@ static void clear_friendship(bool force, bool disable)
*/
lpn->groups_changed = 1U;
if (cfg->hb_pub.feat & BLE_MESH_FEAT_LOW_POWER) {
bt_mesh_heartbeat_send();
}
if (disable) {
lpn_set_state(BLE_MESH_LPN_DISABLED);
return;
@ -764,6 +770,7 @@ static void lpn_timeout(struct k_work *work)
}
lpn->counter++;
lpn_set_state(BLE_MESH_LPN_ENABLED);
lpn->sent_req = 0U;
k_delayed_work_submit(&lpn->timer, FRIEND_REQ_RETRY_TIMEOUT);
break;
case BLE_MESH_LPN_OFFER_RECV:
@ -951,6 +958,8 @@ int bt_mesh_lpn_friend_update(struct bt_mesh_net_rx *rx,
}
if (!lpn->established) {
struct bt_mesh_cfg_srv *cfg = bt_mesh_cfg_get();
/* This is normally checked on the transport layer, however
* in this state we're also still accepting master
* credentials so we need to ensure the right ones (Friend
@ -965,6 +974,10 @@ int bt_mesh_lpn_friend_update(struct bt_mesh_net_rx *rx,
BT_INFO("Friendship established with 0x%04x", lpn->frnd);
if (cfg->hb_pub.feat & BLE_MESH_FEAT_LOW_POWER) {
bt_mesh_heartbeat_send();
}
if (lpn_cb) {
lpn_cb(lpn->frnd, true);
}

View File

@ -1653,25 +1653,29 @@ void bt_mesh_set_private_key(const u8_t pri_key[32])
const u8_t *bt_mesh_pub_key_get(void)
{
Point public_key;
BT_OCTET32 pri_key;
#if 1
BT_OCTET32 private_key = {0};
Point public_key = {0};
if (bt_mesh_atomic_test_bit(bt_mesh_dev.flags, BLE_MESH_DEV_HAS_PUB_KEY)) {
return bt_mesh_public_key;
}
#else
/* BLE Mesh BQB test case MESH/NODE/PROV/UPD/BV-12-C requires
* different public key for each provisioning procedure.
* Note: if enabled, when Provisioner provision multiple devices
* at the same time, this may cause invalid confirmation value.
*
* Use the following code for generating different private key
* for each provisioning procedure.
*
* if (bt_mesh_rand(bt_mesh_private_key, BT_OCTET32_LEN)) {
* BT_ERR("%s, Unable to generate bt_mesh_private_key", __func__);
* return NULL;
* }
*/
if (bt_mesh_rand(bt_mesh_private_key, 32)) {
BT_ERR("%s, Unable to generate bt_mesh_private_key", __func__);
return NULL;
}
#endif
mem_rcopy(pri_key, bt_mesh_private_key, 32);
ECC_PointMult(&public_key, &(curve_p256.G), (DWORD *)pri_key, KEY_LENGTH_DWORDS_P256);
memcpy(private_key, bt_mesh_private_key, BT_OCTET32_LEN);
ECC_PointMult(&public_key, &(curve_p256.G), (DWORD *)private_key, KEY_LENGTH_DWORDS_P256);
memcpy(bt_mesh_public_key, public_key.x, BT_OCTET32_LEN);
memcpy(bt_mesh_public_key + BT_OCTET32_LEN, public_key.y, BT_OCTET32_LEN);
@ -1697,29 +1701,26 @@ bool bt_mesh_check_public_key(const u8_t key[64])
int bt_mesh_dh_key_gen(const u8_t remote_pk[64], bt_mesh_dh_key_cb_t cb, const u8_t idx)
{
BT_OCTET32 private_key;
Point peer_publ_key;
Point new_publ_key;
BT_OCTET32 dhkey;
BT_OCTET32 private_key = {0};
Point peer_pub_key = {0};
Point new_pub_key = {0};
BT_DBG("private key = %s", bt_hex(bt_mesh_private_key, BT_OCTET32_LEN));
mem_rcopy(private_key, bt_mesh_private_key, BT_OCTET32_LEN);
memcpy(peer_publ_key.x, remote_pk, BT_OCTET32_LEN);
memcpy(peer_publ_key.y, &remote_pk[BT_OCTET32_LEN], BT_OCTET32_LEN);
memcpy(private_key, bt_mesh_private_key, BT_OCTET32_LEN);
memcpy(peer_pub_key.x, remote_pk, BT_OCTET32_LEN);
memcpy(peer_pub_key.y, &remote_pk[BT_OCTET32_LEN], BT_OCTET32_LEN);
BT_DBG("remote public key x = %s", bt_hex(peer_publ_key.x, BT_OCTET32_LEN));
BT_DBG("remote public key y = %s", bt_hex(peer_publ_key.y, BT_OCTET32_LEN));
BT_DBG("remote public key x = %s", bt_hex(peer_pub_key.x, BT_OCTET32_LEN));
BT_DBG("remote public key y = %s", bt_hex(peer_pub_key.y, BT_OCTET32_LEN));
ECC_PointMult(&new_publ_key, &peer_publ_key, (DWORD *) private_key, KEY_LENGTH_DWORDS_P256);
ECC_PointMult(&new_pub_key, &peer_pub_key, (DWORD *)private_key, KEY_LENGTH_DWORDS_P256);
memcpy(dhkey, new_publ_key.x, BT_OCTET32_LEN);
BT_DBG("new public key x = %s", bt_hex(new_publ_key.x, 32));
BT_DBG("new public key y = %s", bt_hex(new_publ_key.y, 32));
BT_DBG("new public key x = %s", bt_hex(new_pub_key.x, 32));
BT_DBG("new public key y = %s", bt_hex(new_pub_key.y, 32));
if (cb != NULL) {
cb((const u8_t *)dhkey, idx);
cb((const u8_t *)new_pub_key.x, idx);
}
return 0;

View File

@ -38,14 +38,6 @@ typedef struct alarm_t {
int64_t deadline_us;
} osi_alarm_t;
static void bt_mesh_alarm_cb(void *data)
{
assert(data != NULL);
struct k_delayed_work *work = (struct k_delayed_work *)data;
work->work.handler(&work->work);
return;
}
unsigned int bt_mesh_irq_lock(void)
{
#if defined(CONFIG_BLE_MESH_IRQ_LOCK) && CONFIG_BLE_MESH_IRQ_LOCK
@ -111,7 +103,7 @@ void k_delayed_work_init(struct k_delayed_work *work, k_work_handler_t handler)
osi_mutex_lock(&bm_alarm_lock, OSI_MUTEX_MAX_TIMEOUT);
if (!hash_map_has_key(bm_alarm_hash_map, (void *)work)) {
alarm = osi_alarm_new("bt_mesh", bt_mesh_alarm_cb, (void *)work, 0);
alarm = osi_alarm_new("bt_mesh", (osi_alarm_callback_t)handler, (void *)&work->work, 0);
if (alarm == NULL) {
BT_ERR("%s, Unable to create alarm", __func__);
return;
@ -189,17 +181,5 @@ s32_t k_delayed_work_remaining_get(struct k_delayed_work *work)
return 0;
}
if (!alarm->deadline_us) {
return 0;
}
s32_t remain_time = 0;
int64_t now = esp_timer_get_time();
if ((alarm->deadline_us - now) < 0x1FFFFFFFFFF) {
remain_time = (alarm->deadline_us - now) / 1000;
} else {
return 0;
}
return remain_time;
return osi_alarm_get_remaining_ms(alarm);
}

View File

@ -17,19 +17,11 @@
const char *bt_hex(const void *buf, size_t len)
{
static const char hex[] = "0123456789abcdef";
static char hexbufs[4][129];
static u8_t curbuf;
static char str[129];
const u8_t *b = buf;
unsigned int mask;
char *str;
int i;
mask = bt_mesh_irq_lock();
str = hexbufs[curbuf++];
curbuf %= ARRAY_SIZE(hexbufs);
bt_mesh_irq_unlock(mask);
len = MIN(len, (sizeof(hexbufs[0]) - 1) / 2);
len = MIN(len, (sizeof(str) - 1) / 2);
for (i = 0; i < len; i++) {
str[i * 2] = hex[b[i] >> 4];

View File

@ -135,7 +135,8 @@ static bool msg_cache_match(struct bt_mesh_net_rx *rx,
}
/* Add to the cache */
msg_cache[msg_cache_next++] = hash;
rx->msg_cache_idx = msg_cache_next++;
msg_cache[rx->msg_cache_idx] = hash;
msg_cache_next %= ARRAY_SIZE(msg_cache);
return false;
@ -722,6 +723,16 @@ u32_t bt_mesh_next_seq(void)
bt_mesh_store_seq();
}
if (!bt_mesh_atomic_test_bit(bt_mesh.flags, BLE_MESH_IVU_IN_PROGRESS) &&
bt_mesh.seq > IV_UPDATE_SEQ_LIMIT &&
bt_mesh_subnet_get(BLE_MESH_KEY_PRIMARY)) {
#if CONFIG_BLE_MESH_NODE
bt_mesh_beacon_ivu_initiator(true);
#endif
bt_mesh_net_iv_update(bt_mesh.iv_index + 1, true);
bt_mesh_net_sec_update(NULL);
}
return seq;
}
@ -731,6 +742,7 @@ int bt_mesh_net_resend(struct bt_mesh_subnet *sub, struct net_buf *buf,
{
const u8_t *enc, *priv;
u32_t seq;
u16_t dst;
int err;
BT_DBG("net_idx 0x%04x new_key %u len %u", sub->net_idx, new_key,
@ -757,6 +769,9 @@ int bt_mesh_net_resend(struct bt_mesh_subnet *sub, struct net_buf *buf,
buf->data[3] = seq >> 8;
buf->data[4] = seq;
/* Get destination, in case it's a proxy client */
dst = DST(buf->data);
err = bt_mesh_net_encrypt(enc, &buf->b, BLE_MESH_NET_IVI_TX, false);
if (err) {
BT_ERR("%s, Encrypt failed (err %d)", __func__, err);
@ -769,17 +784,15 @@ int bt_mesh_net_resend(struct bt_mesh_subnet *sub, struct net_buf *buf,
return err;
}
bt_mesh_adv_send(buf, cb, cb_data);
if (!bt_mesh_atomic_test_bit(bt_mesh.flags, BLE_MESH_IVU_IN_PROGRESS) &&
bt_mesh.seq > IV_UPDATE_SEQ_LIMIT) {
#if CONFIG_BLE_MESH_NODE
bt_mesh_beacon_ivu_initiator(true);
#endif
bt_mesh_net_iv_update(bt_mesh.iv_index + 1, true);
bt_mesh_net_sec_update(NULL);
if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_provisioned()) {
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY) &&
bt_mesh_proxy_relay(&buf->b, dst)) {
send_cb_finalize(cb, cb_data);
return 0;
}
}
bt_mesh_adv_send(buf, cb, cb_data);
return 0;
}
@ -891,15 +904,7 @@ int bt_mesh_net_send(struct bt_mesh_net_tx *tx, struct net_buf *buf,
/* Notify completion if this only went
* through the Mesh Proxy.
*/
if (cb) {
if (cb->start) {
cb->start(0, 0, cb_data);
}
if (cb->end) {
cb->end(0, cb_data);
}
}
send_cb_finalize(cb, cb_data);
err = 0;
goto done;
@ -1078,56 +1083,15 @@ static bool net_find_and_decrypt(const u8_t *data, size_t data_len,
struct net_buf_simple *buf)
{
struct bt_mesh_subnet *sub = NULL;
u32_t array_size = 0;
size_t array_size = 0;
int i;
BT_DBG("%s", __func__);
#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER
if (!bt_mesh_is_provisioner_en()) {
array_size = ARRAY_SIZE(bt_mesh.sub);
}
#endif
#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
if (bt_mesh_is_provisioner_en()) {
array_size = ARRAY_SIZE(bt_mesh.p_sub);
}
#endif
#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
array_size = ARRAY_SIZE(bt_mesh.sub);
if (bt_mesh_is_provisioner_en()) {
array_size += ARRAY_SIZE(bt_mesh.p_sub);
}
#endif
if (!array_size) {
BT_ERR("%s, Unable to get subnet size", __func__);
return false;
}
array_size = bt_mesh_rx_netkey_size();
for (i = 0; i < array_size; i++) {
#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER
if (!bt_mesh_is_provisioner_en()) {
sub = &bt_mesh.sub[i];
}
#endif
#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
if (bt_mesh_is_provisioner_en()) {
sub = bt_mesh.p_sub[i];
}
#endif
#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
if (i < ARRAY_SIZE(bt_mesh.sub)) {
sub = &bt_mesh.sub[i];
} else {
sub = bt_mesh.p_sub[i - ARRAY_SIZE(bt_mesh.sub)];
}
#endif
sub = bt_mesh_rx_netkey_get(i);
if (!sub) {
BT_DBG("%s, NULL subnet", __func__);
continue;
@ -1236,15 +1200,6 @@ static void bt_mesh_net_relay(struct net_buf_simple *sbuf,
transmit = bt_mesh_relay_retransmit_get();
} else {
transmit = bt_mesh_net_transmit_get();
if (rx->net_if == BLE_MESH_NET_IF_PROXY &&
transmit < BLE_MESH_TRANSMIT(5, 20)) {
/**
* Add this in case EspBleMesh APP just send a message once, and
* the Proxy Node will send this message using advertising bearer
* with duration not less than 180ms.
*/
transmit = BLE_MESH_TRANSMIT(5, 20);
}
}
buf = bt_mesh_adv_create(BLE_MESH_ADV_DATA, transmit, K_NO_WAIT);
@ -1373,6 +1328,29 @@ int bt_mesh_net_decode(struct net_buf_simple *data, enum bt_mesh_net_if net_if,
return 0;
}
static bool ready_to_recv(void)
{
#if CONFIG_BLE_MESH_NODE
if (!bt_mesh_is_provisioner_en()) {
if (!bt_mesh_is_provisioned()) {
return false;
}
}
#endif
#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
if (!bt_mesh_is_provisioner_en()) {
BT_WARN("%s, Provisioner is disabled", __func__);
return false;
}
if (!provisioner_get_prov_node_count()) {
return false;
}
#endif
return true;
}
void bt_mesh_net_recv(struct net_buf_simple *data, s8_t rssi,
enum bt_mesh_net_if net_if)
{
@ -1382,23 +1360,9 @@ void bt_mesh_net_recv(struct net_buf_simple *data, s8_t rssi,
BT_DBG("rssi %d net_if %u", rssi, net_if);
#if CONFIG_BLE_MESH_NODE
if (!bt_mesh_is_provisioner_en()) {
if (!bt_mesh_is_provisioned()) {
return;
}
}
#endif
#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
if (!bt_mesh_is_provisioner_en()) {
BT_WARN("%s, Provisioner is disabled", __func__);
if (!ready_to_recv()) {
return;
}
if (!provisioner_get_prov_node_count()) {
return;
}
#endif
if (bt_mesh_net_decode(data, net_if, &rx, &buf)) {
return;
@ -1419,7 +1383,19 @@ void bt_mesh_net_recv(struct net_buf_simple *data, s8_t rssi,
rx.local_match = (bt_mesh_fixed_group_match(rx.ctx.recv_dst) ||
bt_mesh_elem_find(rx.ctx.recv_dst));
bt_mesh_trans_recv(&buf, &rx);
/* The transport layer has indicated that it has rejected the message,
* but would like to see it again if it is received in the future.
* This can happen if a message is received when the device is in
* Low Power mode, but the message was not encrypted with the friend
* credentials. Remove it from the message cache so that we accept
* it again in the future.
*/
if (bt_mesh_trans_recv(&buf, &rx) == -EAGAIN) {
BT_WARN("Removing rejected message from Network Message Cache");
msg_cache[rx.msg_cache_idx] = 0ULL;
/* Rewind the next index now that we're not using this entry */
msg_cache_next = rx.msg_cache_idx;
}
/* Relay if this was a group/virtual address, or if the destination
* was neither a local element nor an LPN we're Friends for.

View File

@ -115,6 +115,12 @@ struct bt_mesh_friend {
struct bt_mesh_friend_seg {
sys_slist_t queue;
/* The target number of segments, i.e. not necessarily
* the current number of segments, in the queue. This is
* used for Friend Queue free space calculations.
*/
u8_t seg_count;
} seg[FRIEND_SEG_RX];
struct net_buf *last;
@ -209,7 +215,7 @@ enum {
BLE_MESH_IVU_TEST, /* IV Update test mode */
BLE_MESH_IVU_PENDING, /* Update blocked by SDU in progress */
/* pending storage actions */
/* pending storage actions, must reside within first 32 flags */
BLE_MESH_RPL_PENDING,
BLE_MESH_KEYS_PENDING,
BLE_MESH_NET_PENDING,
@ -289,6 +295,7 @@ struct bt_mesh_net_rx {
net_if: 2, /* Network interface */
local_match: 1, /* Matched a local element */
friend_match: 1; /* Matched an LPN we're friends for */
u16_t msg_cache_idx; /* Index of entry in message cache */
s8_t rssi;
};
@ -385,4 +392,20 @@ struct friend_cred *friend_cred_create(struct bt_mesh_subnet *sub, u16_t addr,
void friend_cred_clear(struct friend_cred *cred);
int friend_cred_del(u16_t net_idx, u16_t addr);
static inline void send_cb_finalize(const struct bt_mesh_send_cb *cb,
void *cb_data)
{
if (!cb) {
return;
}
if (cb->start) {
cb->start(0, 0, cb_data);
}
if (cb->end) {
cb->end(0, cb_data);
}
}
#endif /* _NET_H_ */

View File

@ -48,6 +48,9 @@
#define INPUT_OOB_NUMBER 0x02
#define INPUT_OOB_STRING 0x03
#define PUB_KEY_NO_OOB 0x00
#define PUB_KEY_OOB 0x01
#define PROV_ERR_NONE 0x00
#define PROV_ERR_NVAL_PDU 0x01
#define PROV_ERR_NVAL_FMT 0x02
@ -105,7 +108,7 @@ enum {
SEND_CONFIRM, /* Waiting to send Confirm value */
WAIT_NUMBER, /* Waiting for number input from user */
WAIT_STRING, /* Waiting for string input from user */
TIMEOUT_START, /* Provision timeout timer has started */
LINK_INVALID, /* Error occurred during provisioning */
NUM_FLAGS,
};
@ -161,8 +164,7 @@ struct prov_link {
} tx;
#endif
/* Provision timeout timer */
struct k_delayed_work timeout;
struct k_delayed_work prot_timer;
};
struct prov_rx {
@ -176,11 +178,11 @@ struct prov_rx {
#if defined(CONFIG_BLE_MESH_FAST_PROV)
#define RETRANSMIT_TIMEOUT K_MSEC(360)
#define TRANSACTION_TIMEOUT K_SECONDS(3)
#define PROVISION_TIMEOUT K_SECONDS(6)
#define PROTOCOL_TIMEOUT K_SECONDS(6)
#else
#define RETRANSMIT_TIMEOUT K_MSEC(500)
#define TRANSACTION_TIMEOUT K_SECONDS(30)
#define PROVISION_TIMEOUT K_SECONDS(60)
#define PROTOCOL_TIMEOUT K_SECONDS(60)
#endif /* CONFIG_BLE_MESH_FAST_PROV */
#if defined(CONFIG_BLE_MESH_PB_GATT)
@ -197,10 +199,10 @@ static struct prov_link link;
static const struct bt_mesh_prov *prov;
static void close_link(u8_t err, u8_t reason);
static void reset_state(void)
{
k_delayed_work_cancel(&link.prot_timer);
/* Disable Attention Timer if it was set */
if (link.conf_inputs[0]) {
bt_mesh_attention(NULL, 0);
@ -213,7 +215,9 @@ static void reset_state(void)
#endif
#if defined(CONFIG_BLE_MESH_PB_ADV)
/* Clear everything except the retransmit delayed work config */
/* Clear everything except the retransmit and protocol timer
* delayed work objects.
*/
(void)memset(&link, 0, offsetof(struct prov_link, tx.retransmit));
link.rx.prev_id = XACT_NVAL;
@ -224,8 +228,9 @@ static void reset_state(void)
link.rx.buf = &rx_buf;
#endif /* PB_GATT */
#else
(void)memset(&link, 0, offsetof(struct prov_link, timeout));
#else /* !PB_ADV */
/* Clear everything except the protocol timer (k_delayed_work) */
(void)memset(&link, 0, offsetof(struct prov_link, prot_timer));
#endif /* PB_ADV */
}
@ -276,14 +281,10 @@ static void prov_clear_tx(void)
free_segments();
}
static void reset_link(void)
static void reset_adv_link(void)
{
prov_clear_tx();
if (bt_mesh_atomic_test_and_clear_bit(link.flags, TIMEOUT_START)) {
k_delayed_work_cancel(&link.timeout);
}
if (prov->link_close) {
prov->link_close(BLE_MESH_PROV_ADV);
}
@ -425,7 +426,7 @@ static int prov_send_adv(struct net_buf_simple *msg)
struct net_buf *start, *buf;
u8_t seg_len, seg_id;
u8_t xact_id;
s32_t timeout = PROVISION_TIMEOUT;
s32_t timeout = PROTOCOL_TIMEOUT;
BT_DBG("%s, len %u: %s", __func__, msg->len, bt_hex(msg->data, msg->len));
@ -486,17 +487,12 @@ static int prov_send_adv(struct net_buf_simple *msg)
/* Changed by Espressif, add provisioning timeout timer operations.
* When sending a provisioning PDU successfully, restart the 60s timer.
*/
if (bt_mesh_atomic_test_and_clear_bit(link.flags, TIMEOUT_START)) {
k_delayed_work_cancel(&link.timeout);
}
#if defined(CONFIG_BLE_MESH_FAST_PROV)
if (link.tx_pdu_type >= PROV_COMPLETE) {
timeout = K_SECONDS(60);
}
#endif
if (!bt_mesh_atomic_test_and_set_bit(link.flags, TIMEOUT_START)) {
k_delayed_work_submit(&link.timeout, timeout);
}
k_delayed_work_submit(&link.prot_timer, timeout);
return 0;
}
@ -521,14 +517,7 @@ static int prov_send_gatt(struct net_buf_simple *msg)
return err;
}
if (bt_mesh_atomic_test_and_clear_bit(link.flags, TIMEOUT_START)) {
k_delayed_work_cancel(&link.timeout);
}
if (msg->data[1] != PROV_COMPLETE && msg->data[1] != PROV_FAILED) {
if (!bt_mesh_atomic_test_and_set_bit(link.flags, TIMEOUT_START)) {
k_delayed_work_submit(&link.timeout, PROVISION_TIMEOUT);
}
}
k_delayed_work_submit(&link.prot_timer, PROTOCOL_TIMEOUT);
return 0;
}
@ -560,7 +549,12 @@ static void prov_send_fail_msg(u8_t err)
prov_buf_init(&buf, PROV_FAILED);
net_buf_simple_add_u8(&buf, err);
prov_send(&buf);
if (prov_send(&buf)) {
BT_ERR("Failed to send Provisioning Failed message");
}
bt_mesh_atomic_set_bit(link.flags, LINK_INVALID);
}
static void prov_invite(const u8_t *data)
@ -605,7 +599,6 @@ static void prov_invite(const u8_t *data)
if (prov_send(&buf)) {
BT_ERR("%s, Failed to send capabilities", __func__);
close_link(PROV_ERR_RESOURCES, CLOSE_REASON_FAILED);
return;
}
@ -784,8 +777,8 @@ static void prov_start(const u8_t *data)
return;
}
if (data[1] > 0x01) {
BT_ERR("%s, Invalid public key value: 0x%02x", __func__, data[1]);
if (data[1] != prov->oob_pub_key) {
BT_ERR("%s, Invalid public key type: 0x%02x", __func__, data[1]);
prov_send_fail_msg(PROV_ERR_NVAL_FMT);
return;
}
@ -821,7 +814,7 @@ static void send_confirm(void)
if (bt_mesh_prov_conf_salt(link.conf_inputs, link.conf_salt)) {
BT_ERR("%s, Unable to generate confirmation salt", __func__);
close_link(PROV_ERR_UNEXP_ERR, CLOSE_REASON_FAILED);
prov_send_fail_msg(PROV_ERR_UNEXP_ERR);
return;
}
@ -829,7 +822,7 @@ static void send_confirm(void)
if (bt_mesh_prov_conf_key(link.dhkey, link.conf_salt, link.conf_key)) {
BT_ERR("%s, Unable to generate confirmation key", __func__);
close_link(PROV_ERR_UNEXP_ERR, CLOSE_REASON_FAILED);
prov_send_fail_msg(PROV_ERR_UNEXP_ERR);
return;
}
@ -837,7 +830,7 @@ static void send_confirm(void)
if (bt_mesh_rand(link.rand, 16)) {
BT_ERR("%s, Unable to generate random number", __func__);
close_link(PROV_ERR_UNEXP_ERR, CLOSE_REASON_FAILED);
prov_send_fail_msg(PROV_ERR_UNEXP_ERR);
return;
}
@ -848,13 +841,12 @@ static void send_confirm(void)
if (bt_mesh_prov_conf(link.conf_key, link.rand, link.auth,
net_buf_simple_add(&cfm, 16))) {
BT_ERR("%s, Unable to generate confirmation value", __func__);
close_link(PROV_ERR_UNEXP_ERR, CLOSE_REASON_FAILED);
prov_send_fail_msg(PROV_ERR_UNEXP_ERR);
return;
}
if (prov_send(&cfm)) {
BT_ERR("%s, Unable to send Provisioning Confirm", __func__);
close_link(PROV_ERR_RESOURCES, CLOSE_REASON_FAILED);
return;
}
@ -866,7 +858,9 @@ static void send_input_complete(void)
PROV_BUF(buf, 1);
prov_buf_init(&buf, PROV_INPUT_COMPLETE);
prov_send(&buf);
if (prov_send(&buf)) {
BT_ERR("Failed to send Provisioning Input Complete");
}
}
int bt_mesh_input_number(u32_t num)
@ -921,7 +915,7 @@ static void prov_dh_key_cb(const u8_t key[32], const u8_t idx)
if (!key) {
BT_ERR("%s, DHKey generation failed", __func__);
close_link(PROV_ERR_UNEXP_ERR, CLOSE_REASON_FAILED);
prov_send_fail_msg(PROV_ERR_UNEXP_ERR);
return;
}
@ -946,10 +940,24 @@ static void send_pub_key(void)
PROV_BUF(buf, 65);
const u8_t *key;
/* Copy remote key in little-endian for bt_mesh_dh_key_gen().
* X and Y halves are swapped independently. Use response
* buffer as a temporary storage location. The validating of
* the remote public key is finished when it is received.
*/
sys_memcpy_swap(buf.data, &link.conf_inputs[17], 32);
sys_memcpy_swap(&buf.data[32], &link.conf_inputs[49], 32);
if (bt_mesh_dh_key_gen(buf.data, prov_dh_key_cb, 0)) {
BT_ERR("%s, Unable to generate DHKey", __func__);
prov_send_fail_msg(PROV_ERR_UNEXP_ERR);
return;
}
key = bt_mesh_pub_key_get();
if (!key) {
BT_ERR("%s, No public key available", __func__);
close_link(PROV_ERR_RESOURCES, CLOSE_REASON_FAILED);
prov_send_fail_msg(PROV_ERR_UNEXP_ERR);
return;
}
@ -963,18 +971,8 @@ static void send_pub_key(void)
memcpy(&link.conf_inputs[81], &buf.data[1], 64);
prov_send(&buf);
/* Copy remote key in little-endian for bt_mesh_dh_key_gen().
* X and Y halves are swapped independently.
*/
net_buf_simple_reset(&buf);
sys_memcpy_swap(buf.data, &link.conf_inputs[17], 32);
sys_memcpy_swap(&buf.data[32], &link.conf_inputs[49], 32);
if (bt_mesh_dh_key_gen(buf.data, prov_dh_key_cb, 0)) {
BT_ERR("%s, Unable to generate DHKey", __func__);
close_link(PROV_ERR_UNEXP_ERR, CLOSE_REASON_FAILED);
if (prov_send(&buf)) {
BT_ERR("Failed to send Public Key");
return;
}
@ -994,7 +992,7 @@ static int bt_mesh_calc_dh_key(void)
if (bt_mesh_dh_key_gen(buf.data, prov_dh_key_cb, 0)) {
BT_ERR("%s, Unable to generate DHKey", __func__);
close_link(PROV_ERR_UNEXP_ERR, CLOSE_REASON_FAILED);
prov_send_fail_msg(PROV_ERR_UNEXP_ERR);
return -EIO;
}
@ -1096,7 +1094,7 @@ static void prov_random(const u8_t *data)
if (bt_mesh_prov_conf(link.conf_key, data, link.auth, conf_verify)) {
BT_ERR("%s, Unable to calculate confirmation verification", __func__);
close_link(PROV_ERR_UNEXP_ERR, CLOSE_REASON_FAILED);
prov_send_fail_msg(PROV_ERR_UNEXP_ERR);
return;
}
@ -1104,7 +1102,7 @@ static void prov_random(const u8_t *data)
BT_ERR("%s, Invalid confirmation value", __func__);
BT_DBG("Received: %s", bt_hex(link.conf, 16));
BT_DBG("Calculated: %s", bt_hex(conf_verify, 16));
close_link(PROV_ERR_CFM_FAILED, CLOSE_REASON_FAILED);
prov_send_fail_msg(PROV_ERR_CFM_FAILED);
return;
}
@ -1113,14 +1111,13 @@ static void prov_random(const u8_t *data)
if (prov_send(&rnd)) {
BT_ERR("%s, Failed to send Provisioning Random", __func__);
close_link(PROV_ERR_RESOURCES, CLOSE_REASON_FAILED);
return;
}
if (bt_mesh_prov_salt(link.conf_salt, data, link.rand,
link.prov_salt)) {
BT_ERR("%s, Failed to generate provisioning salt", __func__);
close_link(PROV_ERR_UNEXP_ERR, CLOSE_REASON_FAILED);
prov_send_fail_msg(PROV_ERR_UNEXP_ERR);
return;
}
@ -1157,7 +1154,7 @@ static void prov_data(const u8_t *data)
err = bt_mesh_session_key(link.dhkey, link.prov_salt, session_key);
if (err) {
BT_ERR("%s, Unable to generate session key", __func__);
close_link(PROV_ERR_UNEXP_ERR, CLOSE_REASON_FAILED);
prov_send_fail_msg(PROV_ERR_UNEXP_ERR);
return;
}
@ -1166,7 +1163,7 @@ static void prov_data(const u8_t *data)
err = bt_mesh_prov_nonce(link.dhkey, link.prov_salt, nonce);
if (err) {
BT_ERR("%s, Unable to generate session nonce", __func__);
close_link(PROV_ERR_UNEXP_ERR, CLOSE_REASON_FAILED);
prov_send_fail_msg(PROV_ERR_UNEXP_ERR);
return;
}
@ -1175,14 +1172,14 @@ static void prov_data(const u8_t *data)
err = bt_mesh_prov_decrypt(session_key, nonce, data, pdu);
if (err) {
BT_ERR("%s, Unable to decrypt provisioning data", __func__);
close_link(PROV_ERR_DECRYPT, CLOSE_REASON_FAILED);
prov_send_fail_msg(PROV_ERR_DECRYPT);
return;
}
err = bt_mesh_dev_key(link.dhkey, link.prov_salt, dev_key);
if (err) {
BT_ERR("%s, Unable to generate device key", __func__);
close_link(PROV_ERR_UNEXP_ERR, CLOSE_REASON_FAILED);
prov_send_fail_msg(PROV_ERR_UNEXP_ERR);
return;
}
@ -1197,7 +1194,10 @@ static void prov_data(const u8_t *data)
net_idx, iv_index, addr);
prov_buf_init(&msg, PROV_COMPLETE);
prov_send(&msg);
if (prov_send(&msg)) {
BT_ERR("Failed to send Provisioning Complete");
return;
}
/* Ignore any further PDUs on this link */
link.expect = 0U;
@ -1249,35 +1249,6 @@ static const struct {
{ prov_failed, 1 },
};
static void close_link(u8_t err, u8_t reason)
{
#if defined(CONFIG_BLE_MESH_PB_GATT)
if (link.conn) {
bt_mesh_pb_gatt_close(link.conn);
return;
}
#endif
#if defined(CONFIG_BLE_MESH_PB_ADV)
if (err) {
prov_send_fail_msg(err);
}
link.rx.seg = 0U;
bearer_ctl_send(LINK_CLOSE, &reason, sizeof(reason));
#endif
reset_state();
}
/* Changed by Espressif, add provisioning timeout timer callback */
static void prov_timeout(struct k_work *work)
{
BT_DBG("%s", __func__);
close_link(PROV_ERR_UNEXP_ERR, CLOSE_REASON_TIMEOUT);
}
#if defined(CONFIG_BLE_MESH_PB_ADV)
static void prov_retransmit(struct k_work *work)
{
@ -1299,7 +1270,7 @@ static void prov_retransmit(struct k_work *work)
#endif
if (k_uptime_get() - link.tx.start > timeout) {
BT_WARN("Node timeout, giving up transaction");
reset_link();
reset_adv_link();
return;
}
@ -1379,7 +1350,7 @@ static void link_close(struct prov_rx *rx, struct net_buf_simple *buf)
{
BT_DBG("len %u", buf->len);
reset_link();
reset_adv_link();
}
static void gen_prov_ctl(struct prov_rx *rx, struct net_buf_simple *buf)
@ -1425,6 +1396,12 @@ static void prov_msg_recv(void)
link.rx.prev_id = link.rx.id;
link.rx.id = 0U;
if (bt_mesh_atomic_test_bit(link.flags, LINK_INVALID)) {
BT_WARN("Unexpected msg 0x%02x on invalidated link", type);
prov_send_fail_msg(PROV_ERR_UNEXP_PDU);
return;
}
if (type != PROV_FAILED && type != link.expect) {
BT_WARN("Unexpected msg 0x%02x != 0x%02x", type, link.expect);
prov_send_fail_msg(PROV_ERR_UNEXP_PDU);
@ -1433,26 +1410,21 @@ static void prov_msg_recv(void)
if (type >= ARRAY_SIZE(prov_handlers)) {
BT_ERR("%s, Unknown provisioning PDU type 0x%02x", __func__, type);
close_link(PROV_ERR_NVAL_PDU, CLOSE_REASON_FAILED);
prov_send_fail_msg(PROV_ERR_NVAL_PDU);
return;
}
if (1 + prov_handlers[type].len != link.rx.buf->len) {
BT_ERR("%s, Invalid length %u for type 0x%02x",
__func__, link.rx.buf->len, type);
close_link(PROV_ERR_NVAL_FMT, CLOSE_REASON_FAILED);
prov_send_fail_msg(PROV_ERR_NVAL_FMT);
return;
}
/* Changed by Espressif, add provisioning timeout timer operations.
* When received a provisioning PDU, restart the 60s timer.
*/
if (bt_mesh_atomic_test_and_clear_bit(link.flags, TIMEOUT_START)) {
k_delayed_work_cancel(&link.timeout);
}
if (!bt_mesh_atomic_test_and_set_bit(link.flags, TIMEOUT_START)) {
k_delayed_work_submit(&link.timeout, PROVISION_TIMEOUT);
}
k_delayed_work_submit(&link.prot_timer, PROTOCOL_TIMEOUT);
prov_handlers[type].func(&link.rx.buf->data[1]);
}
@ -1485,7 +1457,7 @@ static void gen_prov_cont(struct prov_rx *rx, struct net_buf_simple *buf)
if (seg > link.rx.last_seg) {
BT_ERR("%s, Invalid segment index %u", __func__, seg);
close_link(PROV_ERR_NVAL_FMT, CLOSE_REASON_FAILED);
prov_send_fail_msg(PROV_ERR_NVAL_FMT);
return;
} else if (seg == link.rx.last_seg) {
u8_t expect_len;
@ -1495,7 +1467,7 @@ static void gen_prov_cont(struct prov_rx *rx, struct net_buf_simple *buf)
if (expect_len != buf->len) {
BT_ERR("%s, Incorrect last seg len: %u != %u",
__func__, expect_len, buf->len);
close_link(PROV_ERR_NVAL_FMT, CLOSE_REASON_FAILED);
prov_send_fail_msg(PROV_ERR_NVAL_FMT);
return;
}
}
@ -1548,20 +1520,20 @@ static void gen_prov_start(struct prov_rx *rx, struct net_buf_simple *buf)
if (link.rx.buf->len < 1) {
BT_ERR("%s, Ignoring zero-length provisioning PDU", __func__);
close_link(PROV_ERR_NVAL_FMT, CLOSE_REASON_FAILED);
prov_send_fail_msg(PROV_ERR_NVAL_FMT);
return;
}
if (link.rx.buf->len > link.rx.buf->size) {
BT_ERR("%s, Too large provisioning PDU (%u bytes)",
__func__, link.rx.buf->len);
// close_link(PROV_ERR_NVAL_FMT, CLOSE_REASON_FAILED);
/* Zephyr uses prov_send_fail_msg() here */
return;
}
if (START_LAST_SEG(rx->gpc) > 0 && link.rx.buf->len <= 20U) {
BT_ERR("%s, Too small total length for multi-segment PDU", __func__);
close_link(PROV_ERR_NVAL_FMT, CLOSE_REASON_FAILED);
prov_send_fail_msg(PROV_ERR_NVAL_FMT);
return;
}
@ -1668,12 +1640,7 @@ int bt_mesh_pb_gatt_recv(struct bt_mesh_conn *conn, struct net_buf_simple *buf)
/* Changed by Espressif, add provisioning timeout timer operations.
* When received a provisioning PDU, restart the 60s timer.
*/
if (bt_mesh_atomic_test_and_clear_bit(link.flags, TIMEOUT_START)) {
k_delayed_work_cancel(&link.timeout);
}
if (!bt_mesh_atomic_test_and_set_bit(link.flags, TIMEOUT_START)) {
k_delayed_work_submit(&link.timeout, PROVISION_TIMEOUT);
}
k_delayed_work_submit(&link.prot_timer, PROTOCOL_TIMEOUT);
prov_handlers[type].func(buf->data);
@ -1727,6 +1694,27 @@ bool bt_prov_active(void)
return bt_mesh_atomic_test_bit(link.flags, LINK_ACTIVE);
}
static void protocol_timeout(struct k_work *work)
{
BT_DBG("Protocol timeout");
#if defined(CONFIG_BLE_MESH_PB_GATT)
if (link.conn) {
bt_mesh_pb_gatt_close(link.conn);
return;
}
#endif
#if defined(CONFIG_BLE_MESH_PB_ADV)
u8_t reason = CLOSE_REASON_TIMEOUT;
link.rx.seg = 0U;
bearer_ctl_send(LINK_CLOSE, &reason, sizeof(reason));
reset_state();
#endif
}
int bt_mesh_prov_init(const struct bt_mesh_prov *prov_info)
{
const u8_t *key = NULL;
@ -1743,15 +1731,14 @@ int bt_mesh_prov_init(const struct bt_mesh_prov *prov_info)
return -EIO;
}
k_delayed_work_init(&link.prot_timer, protocol_timeout);
prov = prov_info;
#if defined(CONFIG_BLE_MESH_PB_ADV)
k_delayed_work_init(&link.tx.retransmit, prov_retransmit);
#endif
/* Changed by Espressif, add provisioning timeout timer init */
k_delayed_work_init(&link.timeout, prov_timeout);
reset_state();
return 0;

View File

@ -330,7 +330,7 @@ bool provisioner_check_msg_dst_addr(u16_t dst_addr)
return false;
}
const u8_t *provisioner_get_device_key(u16_t dst_addr)
const u8_t *provisioner_dev_key_get(u16_t dst_addr)
{
/* Device key is only used to encrypt configuration messages.
* Configuration model shall only be supported by the primary
@ -1140,7 +1140,7 @@ int bt_mesh_provisioner_print_local_element_info(void)
#if CONFIG_BLE_MESH_FAST_PROV
const u8_t *get_fast_prov_device_key(u16_t addr)
const u8_t *fast_prov_dev_key_get(u16_t addr)
{
struct bt_mesh_node_t *node = NULL;
@ -1165,7 +1165,7 @@ const u8_t *get_fast_prov_device_key(u16_t addr)
return NULL;
}
struct bt_mesh_subnet *get_fast_prov_subnet(u16_t net_idx)
struct bt_mesh_subnet *fast_prov_subnet_get(u16_t net_idx)
{
struct bt_mesh_subnet *sub = NULL;
@ -1188,7 +1188,7 @@ struct bt_mesh_subnet *get_fast_prov_subnet(u16_t net_idx)
return NULL;
}
struct bt_mesh_app_key *get_fast_prov_app_key(u16_t net_idx, u16_t app_idx)
struct bt_mesh_app_key *fast_prov_app_key_find(u16_t net_idx, u16_t app_idx)
{
struct bt_mesh_app_key *key = NULL;
@ -1216,7 +1216,7 @@ u8_t bt_mesh_set_fast_prov_net_idx(u16_t net_idx)
struct bt_mesh_subnet *sub = NULL;
struct bt_mesh_subnet_keys *key = NULL;
sub = get_fast_prov_subnet(net_idx);
sub = fast_prov_subnet_get(net_idx);
if (sub) {
key = BLE_MESH_KEY_REFRESH(sub->kr_flag) ? &sub->keys[1] : &sub->keys[0];
return provisioner_set_fast_prov_net_idx(key->net, net_idx);
@ -1253,7 +1253,7 @@ const u8_t *bt_mesh_get_fast_prov_net_key(u16_t net_idx)
{
struct bt_mesh_subnet *sub = NULL;
sub = get_fast_prov_subnet(net_idx);
sub = fast_prov_subnet_get(net_idx);
if (!sub) {
BT_ERR("%s, Failed to get subnet", __func__);
return NULL;
@ -1266,7 +1266,7 @@ const u8_t *bt_mesh_get_fast_prov_app_key(u16_t net_idx, u16_t app_idx)
{
struct bt_mesh_app_key *key = NULL;
key = get_fast_prov_app_key(net_idx, app_idx);
key = fast_prov_app_key_find(net_idx, app_idx);
if (!key) {
BT_ERR("%s, Failed to get AppKey", __func__);
return NULL;

View File

@ -55,7 +55,7 @@ struct bt_mesh_subnet *provisioner_subnet_get(u16_t net_idx);
bool provisioner_check_msg_dst_addr(u16_t dst_addr);
const u8_t *provisioner_get_device_key(u16_t dst_addr);
const u8_t *provisioner_dev_key_get(u16_t dst_addr);
struct bt_mesh_app_key *provisioner_app_key_find(u16_t app_idx);
@ -105,11 +105,11 @@ int bt_mesh_provisioner_print_local_element_info(void);
/* The following APIs are for fast provisioning */
const u8_t *get_fast_prov_device_key(u16_t dst_addr);
const u8_t *fast_prov_dev_key_get(u16_t dst_addr);
struct bt_mesh_subnet *get_fast_prov_subnet(u16_t net_idx);
struct bt_mesh_subnet *fast_prov_subnet_get(u16_t net_idx);
struct bt_mesh_app_key *get_fast_prov_app_key(u16_t net_idx, u16_t app_idx);
struct bt_mesh_app_key *fast_prov_app_key_find(u16_t net_idx, u16_t app_idx);
u8_t bt_mesh_set_fast_prov_net_idx(u16_t net_idx);

View File

@ -575,16 +575,6 @@ static int provisioner_check_unprov_dev_info(const u8_t uuid[16])
return -EALREADY;
}
/* Check if this device is currently being provisioned.
* According to Zephyr's device code, if we connect with
* one device and start to provision it, we may still can
* receive the connectable prov adv pkt from this device.
* Here we check both PB-GATT and PB-ADV link status.
*/
if (is_unprov_dev_being_provision(uuid)) {
return -EALREADY;
}
/* Check if the device has already been provisioned */
for (i = 0U; i < ARRAY_SIZE(prov_nodes); i++) {
if (prov_nodes[i].provisioned) {
@ -1757,7 +1747,7 @@ static int prov_auth(const u8_t idx, u8_t method, u8_t action, u8_t size)
bt_mesh_rand(str, size);
/* Normalize to '0' .. '9' & 'A' .. 'Z' */
for (j = 0; j < size; j++) {
for (j = 0U; j < size; j++) {
str[j] %= 36;
if (str[j] < 10) {
str[j] += '0';
@ -1768,7 +1758,7 @@ static int prov_auth(const u8_t idx, u8_t method, u8_t action, u8_t size)
str[size] = '\0';
memcpy(link[idx].auth, str, size);
memset(link[idx].auth + size, 0, sizeof(link[idx].auth) - size);
memset(link[idx].auth + size, 0, PROV_AUTH_VAL_SIZE - size);
return prov->prov_output_num(AUTH_METHOD_INPUT, input, str, size, idx);
} else {
@ -1892,8 +1882,7 @@ int bt_mesh_prov_set_oob_input_data(const u8_t idx, const u8_t *val, bool num_fl
return 0;
}
#if 0
int bt_mesh_prov_set_oob_output_data(const u8_t idx, u8_t *num, u8_t size, bool num_flag)
int bt_mesh_prov_set_oob_output_data(const u8_t idx, const u8_t *num, u8_t size, bool num_flag)
{
/** This function should be called in the prov_output_num
* callback, after the data has been output by provisioner.
@ -1923,7 +1912,6 @@ int bt_mesh_prov_set_oob_output_data(const u8_t idx, u8_t *num, u8_t size, bool
return 0;
}
#endif
int bt_mesh_prov_read_oob_pub_key(const u8_t idx, const u8_t pub_key_x[32], const u8_t pub_key_y[32])
{

View File

@ -313,9 +313,7 @@ int bt_mesh_prov_set_oob_input_data(const u8_t idx, const u8_t *val, bool num_fl
*
* @return Zero - success, otherwise - fail
*/
#if 0
int bt_mesh_prov_set_oob_output_data(const u8_t idx, u8_t *num, u8_t size, bool num_flag);
#endif
int bt_mesh_prov_set_oob_output_data(const u8_t idx, const u8_t *num, u8_t size, bool num_flag);
/**
* @brief This function is called to read unprovisioned device's oob public key.

View File

@ -31,6 +31,12 @@
#define PDU_TYPE(data) (data[0] & BIT_MASK(6))
#define PDU_SAR(data) (data[0] >> 6)
/* Mesh Profile 1.0 Section 6.6:
* "The timeout for the SAR transfer is 20 seconds. When the timeout
* expires, the Proxy Server shall disconnect."
*/
#define PROXY_SAR_TIMEOUT K_SECONDS(20)
#define SAR_COMPLETE 0x00
#define SAR_FIRST 0x01
#define SAR_CONT 0x02
@ -71,13 +77,6 @@ static u16_t prov_ccc_val;
static bool prov_fast_adv;
#endif
enum {
SAR_TIMER_START, /* Timer for SAR transfer has been started */
NUM_FLAGS,
};
#define PROXY_SAR_TRANS_TIMEOUT K_SECONDS(20)
static struct bt_mesh_proxy_client {
struct bt_mesh_conn *conn;
u16_t filter[CONFIG_BLE_MESH_PROXY_FILTER_SIZE];
@ -91,10 +90,8 @@ static struct bt_mesh_proxy_client {
#if defined(CONFIG_BLE_MESH_GATT_PROXY)
struct k_work send_beacons;
#endif
struct k_delayed_work sar_timer;
struct net_buf_simple buf;
/* Proxy Server: 20s timeout for each segmented proxy pdu */
BLE_MESH_ATOMIC_DEFINE(flags, NUM_FLAGS);
struct k_delayed_work sar_timer;
} clients[BLE_MESH_MAX_CONN] = {
[0 ... (BLE_MESH_MAX_CONN - 1)] = {
#if defined(CONFIG_BLE_MESH_GATT_PROXY)
@ -145,6 +142,22 @@ static struct bt_mesh_proxy_client *find_client(struct bt_mesh_conn *conn)
return NULL;
}
static void proxy_sar_timeout(struct k_work *work)
{
struct bt_mesh_proxy_client *client = NULL;
BT_WARN("Proxy SAR timeout");
client = CONTAINER_OF(work, struct bt_mesh_proxy_client, sar_timer.work);
if (!client || !client->conn) {
BT_ERR("%s, Invalid proxy client parameter", __func__);
return;
}
net_buf_simple_reset(&client->buf);
bt_mesh_gatts_disconnect(client->conn, 0x13);
}
#if defined(CONFIG_BLE_MESH_GATT_PROXY)
/* Next subnet in queue to be advertised */
static int next_idx;
@ -500,10 +513,7 @@ static ssize_t proxy_recv(struct bt_mesh_conn *conn,
return -EINVAL;
}
if (!bt_mesh_atomic_test_and_set_bit(client->flags, SAR_TIMER_START)) {
k_delayed_work_submit(&client->sar_timer, PROXY_SAR_TRANS_TIMEOUT);
}
k_delayed_work_submit(&client->sar_timer, PROXY_SAR_TIMEOUT);
client->msg_type = PDU_TYPE(data);
net_buf_simple_add_mem(&client->buf, data + 1, len - 1);
break;
@ -519,6 +529,7 @@ static ssize_t proxy_recv(struct bt_mesh_conn *conn,
return -EINVAL;
}
k_delayed_work_submit(&client->sar_timer, PROXY_SAR_TIMEOUT);
net_buf_simple_add_mem(&client->buf, data + 1, len - 1);
break;
@ -533,10 +544,7 @@ static ssize_t proxy_recv(struct bt_mesh_conn *conn,
return -EINVAL;
}
if (bt_mesh_atomic_test_and_clear_bit(client->flags, SAR_TIMER_START)) {
k_delayed_work_cancel(&client->sar_timer);
}
k_delayed_work_cancel(&client->sar_timer);
net_buf_simple_add_mem(&client->buf, data + 1, len - 1);
proxy_complete_pdu(client);
break;
@ -599,10 +607,7 @@ static void proxy_disconnected(struct bt_mesh_conn *conn, u8_t reason)
bt_mesh_pb_gatt_close(conn);
}
if (bt_mesh_atomic_test_and_clear_bit(client->flags, SAR_TIMER_START)) {
k_delayed_work_cancel(&client->sar_timer);
}
k_delayed_work_cancel(&client->sar_timer);
bt_mesh_conn_unref(client->conn);
client->conn = NULL;
break;
@ -1144,14 +1149,25 @@ static bool advertise_subnet(struct bt_mesh_subnet *sub)
static struct bt_mesh_subnet *next_sub(void)
{
struct bt_mesh_subnet *sub = NULL;
int i;
for (i = 0; i < ARRAY_SIZE(bt_mesh.sub); i++) {
struct bt_mesh_subnet *sub;
sub = &bt_mesh.sub[(i + next_idx) % ARRAY_SIZE(bt_mesh.sub)];
for (i = next_idx; i < ARRAY_SIZE(bt_mesh.sub); i++) {
sub = &bt_mesh.sub[i];
if (advertise_subnet(sub)) {
next_idx = (next_idx + 1) % ARRAY_SIZE(bt_mesh.sub);
next_idx = (i + 1) % ARRAY_SIZE(bt_mesh.sub);
return sub;
}
}
/**
* If among [next_idx, ARRAY_SIZE(bt_mesh.sub)], there is no subnet
* to advertise, then try to start advertising from Primary subnet.
*/
for (i = 0; i < next_idx; i++) {
sub = &bt_mesh.sub[i];
if (advertise_subnet(sub)) {
next_idx = (i + 1) % ARRAY_SIZE(bt_mesh.sub);
return sub;
}
}
@ -1350,23 +1366,6 @@ static struct bt_mesh_conn_cb conn_callbacks = {
.disconnected = proxy_disconnected,
};
static void proxy_recv_timeout(struct k_work *work)
{
struct bt_mesh_proxy_client *client = NULL;
BT_DBG("%s", __func__);
client = CONTAINER_OF(work, struct bt_mesh_proxy_client, sar_timer.work);
if (!client || !client->conn) {
BT_ERR("%s, Invalid proxy client parameter", __func__);
return;
}
bt_mesh_atomic_clear_bit(client->flags, SAR_TIMER_START);
net_buf_simple_reset(&client->buf);
bt_mesh_gatts_disconnect(client->conn, 0x13);
}
int bt_mesh_proxy_init(void)
{
int i;
@ -1377,7 +1376,8 @@ int bt_mesh_proxy_init(void)
client->buf.size = CLIENT_BUF_SIZE;
client->buf.__buf = client_buf_data + (i * CLIENT_BUF_SIZE);
k_delayed_work_init(&client->sar_timer, proxy_recv_timeout);
k_delayed_work_init(&client->sar_timer, proxy_sar_timeout);
}
bt_mesh_gatts_conn_cb_register(&conn_callbacks);

View File

@ -59,10 +59,6 @@
#if CONFIG_BLE_MESH_SETTINGS
#define GET_ELEMENT_IDX(x) ((u8_t)((x) >> 8))
#define GET_MODEL_IDX(x) ((u8_t)(x))
#define GET_MODEL_KEY(a, b) ((u16_t)(((u16_t)((a) << 8)) | b))
/* Tracking of what storage changes are pending for App and Net Keys. We
* track this in a separate array here instead of within the respective
* bt_mesh_app_key and bt_mesh_subnet structs themselves, since once a key
@ -653,8 +649,8 @@ static int model_set(bool vnd, const char *name)
for (i = 0; i < length / SETTINGS_ITEM_SIZE; i++) {
u16_t model_key = net_buf_simple_pull_le16(buf);
elem_idx = GET_ELEMENT_IDX(model_key);
model_idx = GET_MODEL_IDX(model_key);
elem_idx = BLE_MESH_GET_ELEM_IDX(model_key);
model_idx = BLE_MESH_GET_MODEL_IDX(model_key);
model = bt_mesh_model_get(vnd, elem_idx, model_idx);
if (!model) {
@ -837,24 +833,40 @@ int settings_core_commit(void)
return 0;
}
/* Pending flags that use K_NO_WAIT as the storage timeout */
#define NO_WAIT_PENDING_BITS (BIT(BLE_MESH_NET_PENDING) | \
BIT(BLE_MESH_IV_PENDING) | \
BIT(BLE_MESH_SEQ_PENDING))
/* Pending flags that use CONFIG_BLE_MESH_STORE_TIMEOUT */
#define GENERIC_PENDING_BITS (BIT(BLE_MESH_KEYS_PENDING) | \
BIT(BLE_MESH_HB_PUB_PENDING) | \
BIT(BLE_MESH_CFG_PENDING) | \
BIT(BLE_MESH_MOD_PENDING))
static void schedule_store(int flag)
{
s32_t timeout;
s32_t timeout, remaining;
bt_mesh_atomic_set_bit(bt_mesh.flags, flag);
if (bt_mesh_atomic_test_bit(bt_mesh.flags, BLE_MESH_NET_PENDING) ||
bt_mesh_atomic_test_bit(bt_mesh.flags, BLE_MESH_IV_PENDING) ||
bt_mesh_atomic_test_bit(bt_mesh.flags, BLE_MESH_SEQ_PENDING)) {
if (bt_mesh_atomic_get(bt_mesh.flags) & NO_WAIT_PENDING_BITS) {
timeout = K_NO_WAIT;
} else if (bt_mesh_atomic_test_bit(bt_mesh.flags, BLE_MESH_RPL_PENDING) &&
(CONFIG_BLE_MESH_RPL_STORE_TIMEOUT <
CONFIG_BLE_MESH_STORE_TIMEOUT)) {
(!(bt_mesh_atomic_get(bt_mesh.flags) & GENERIC_PENDING_BITS) ||
(CONFIG_BLE_MESH_RPL_STORE_TIMEOUT <
CONFIG_BLE_MESH_STORE_TIMEOUT))) {
timeout = K_SECONDS(CONFIG_BLE_MESH_RPL_STORE_TIMEOUT);
} else {
timeout = K_SECONDS(CONFIG_BLE_MESH_STORE_TIMEOUT);
}
remaining = k_delayed_work_remaining_get(&pending_store);
if (remaining && remaining < timeout) {
BT_DBG("Not rescheduling due to existing earlier deadline");
return;
}
BT_DBG("Waiting %d seconds", timeout / MSEC_PER_SEC);
if (timeout) {
@ -1196,7 +1208,7 @@ static void store_pending_mod_bind(struct bt_mesh_model *model, bool vnd)
u16_t model_key;
int err;
model_key = GET_MODEL_KEY(model->elem_idx, model->model_idx);
model_key = BLE_MESH_GET_MODEL_KEY(model->elem_idx, model->model_idx);
sprintf(name, "mesh/%s/%04x/b", vnd ? "v" : "s", model_key);
@ -1226,7 +1238,7 @@ static void store_pending_mod_sub(struct bt_mesh_model *model, bool vnd)
u16_t model_key;
int err;
model_key = GET_MODEL_KEY(model->elem_idx, model->model_idx);
model_key = BLE_MESH_GET_MODEL_KEY(model->elem_idx, model->model_idx);
sprintf(name, "mesh/%s/%04x/s", vnd ? "v" : "s", model_key);
@ -1270,7 +1282,7 @@ static void store_pending_mod_pub(struct bt_mesh_model *model, bool vnd)
pub.period_div = model->pub->period_div;
pub.cred = model->pub->cred;
model_key = GET_MODEL_KEY(model->elem_idx, model->model_idx);
model_key = BLE_MESH_GET_MODEL_KEY(model->elem_idx, model->model_idx);
sprintf(name, "mesh/%s/%04x/p", vnd ? "v" : "s", model_key);

View File

@ -23,7 +23,11 @@
extern "C" {
#endif
#define SETTINGS_ITEM_SIZE sizeof(u16_t)
#define SETTINGS_ITEM_SIZE sizeof(u16_t)
#define BLE_MESH_GET_ELEM_IDX(x) ((u8_t)((x) >> 8))
#define BLE_MESH_GET_MODEL_IDX(x) ((u8_t)(x))
#define BLE_MESH_GET_MODEL_KEY(a, b) ((u16_t)(((u16_t)((a) << 8)) | b))
void bt_mesh_settings_foreach(void);

View File

@ -31,8 +31,8 @@
#include "settings.h"
#include "transport.h"
#include "mesh_common.h"
#include "model_common.h"
#include "provisioner_main.h"
#include "client_common.h"
#include "cfg_srv.h"
/* The transport layer needs at least three buffers for itself to avoid
* deadlocks. Ensure that there are a sufficient number of advertising
@ -141,18 +141,33 @@ static int send_unseg(struct bt_mesh_net_tx *tx, struct net_buf_simple *sdu,
if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_provisioned()) {
if (IS_ENABLED(CONFIG_BLE_MESH_FRIEND)) {
if (!bt_mesh_friend_queue_has_space(tx->sub->net_idx,
tx->src, tx->ctx->addr,
NULL, 1)) {
if (BLE_MESH_ADDR_IS_UNICAST(tx->ctx->addr)) {
BT_ERR("Not enough space in Friend Queue");
net_buf_unref(buf);
return -ENOBUFS;
} else {
BT_WARN("No space in Friend Queue");
goto send;
}
}
if (bt_mesh_friend_enqueue_tx(tx, BLE_MESH_FRIEND_PDU_SINGLE,
NULL, &buf->b) &&
NULL, 1, &buf->b) &&
BLE_MESH_ADDR_IS_UNICAST(tx->ctx->addr)) {
/* PDUs for a specific Friend should only go
* out through the Friend Queue.
*/
net_buf_unref(buf);
send_cb_finalize(cb, cb_data);
return 0;
}
}
}
send:
return bt_mesh_net_send(tx, buf, cb, cb_data);
}
@ -364,6 +379,17 @@ static int send_seg(struct bt_mesh_net_tx *net_tx, struct net_buf_simple *sdu,
BT_DBG("SeqZero 0x%04x", seq_zero);
if (IS_ENABLED(CONFIG_BLE_MESH_FRIEND) &&
!bt_mesh_friend_queue_has_space(tx->sub->net_idx, net_tx->src,
tx->dst, &tx->seq_auth,
tx->seg_n + 1) &&
BLE_MESH_ADDR_IS_UNICAST(tx->dst)) {
BT_ERR("Not enough space in Friend Queue for %u segments",
tx->seg_n + 1);
seg_tx_reset(tx);
return -ENOBUFS;
}
for (seg_o = 0U; sdu->len; seg_o++) {
struct net_buf *seg;
u16_t len;
@ -391,30 +417,31 @@ static int send_seg(struct bt_mesh_net_tx *net_tx, struct net_buf_simple *sdu,
net_buf_add_mem(seg, sdu->data, len);
net_buf_simple_pull(sdu, len);
tx->seg[seg_o] = net_buf_ref(seg);
if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_provisioned()) {
if (IS_ENABLED(CONFIG_BLE_MESH_FRIEND)) {
enum bt_mesh_friend_pdu_type type;
if (IS_ENABLED(CONFIG_BLE_MESH_FRIEND)) {
enum bt_mesh_friend_pdu_type type;
if (seg_o == tx->seg_n) {
type = BLE_MESH_FRIEND_PDU_COMPLETE;
} else {
type = BLE_MESH_FRIEND_PDU_PARTIAL;
}
if (seg_o == tx->seg_n) {
type = BLE_MESH_FRIEND_PDU_COMPLETE;
} else {
type = BLE_MESH_FRIEND_PDU_PARTIAL;
}
if (bt_mesh_friend_enqueue_tx(net_tx, type,
&tx->seq_auth,
&seg->b) &&
if (bt_mesh_friend_enqueue_tx(net_tx, type,
&tx->seq_auth,
tx->seg_n + 1,
&seg->b) &&
BLE_MESH_ADDR_IS_UNICAST(net_tx->ctx->addr)) {
/* PDUs for a specific Friend should only go
* out through the Friend Queue.
*/
net_buf_unref(seg);
return 0;
/* PDUs for a specific Friend should only go
* out through the Friend Queue.
*/
net_buf_unref(seg);
continue;
}
}
}
}
tx->seg[seg_o] = net_buf_ref(seg);
BT_DBG("Sending %u/%u", seg_o, tx->seg_n);
@ -428,6 +455,16 @@ static int send_seg(struct bt_mesh_net_tx *net_tx, struct net_buf_simple *sdu,
}
}
/* This can happen if segments only went into the Friend Queue */
if (IS_ENABLED(CONFIG_BLE_MESH_FRIEND) && !tx->seg[0]) {
seg_tx_reset(tx);
/* If there was a callback notify sending immediately since
* there's no other way to track this (at least currently)
* with the Friend Queue.
*/
send_cb_finalize(cb, cb_data);
}
if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_provisioned()) {
if (IS_ENABLED(CONFIG_BLE_MESH_LOW_POWER) &&
bt_mesh_lpn_established()) {
@ -474,43 +511,14 @@ int bt_mesh_trans_send(struct bt_mesh_net_tx *tx, struct net_buf_simple *msg,
tx->ctx->app_idx, tx->ctx->addr);
BT_DBG("len %u: %s", msg->len, bt_hex(msg->data, msg->len));
role = bt_mesh_get_model_role(tx->ctx->model, tx->ctx->srv_send);
role = bt_mesh_get_device_role(tx->ctx->model, tx->ctx->srv_send);
if (role == ROLE_NVAL) {
BT_ERR("%s, Failed to get model role", __func__);
return -EINVAL;
}
if (tx->ctx->app_idx == BLE_MESH_KEY_DEV) {
#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER
if (role == NODE) {
if (!bt_mesh_is_provisioner_en()) {
key = bt_mesh.dev_key;
}
}
#endif
#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
if (role == PROVISIONER) {
if (bt_mesh_is_provisioner_en()) {
key = provisioner_get_device_key(tx->ctx->addr);
}
}
#endif
#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
if (role == NODE) {
key = bt_mesh.dev_key;
} else if (role == PROVISIONER) {
if (bt_mesh_is_provisioner_en()) {
key = provisioner_get_device_key(tx->ctx->addr);
}
} else if (role == FAST_PROV) {
#if CONFIG_BLE_MESH_FAST_PROV
key = get_fast_prov_device_key(tx->ctx->addr);
#endif
}
#endif
key = bt_mesh_tx_devkey_get(role, tx->ctx->addr);
if (!key) {
BT_ERR("%s, Failed to get Device Key", __func__);
return -EINVAL;
@ -520,36 +528,7 @@ int bt_mesh_trans_send(struct bt_mesh_net_tx *tx, struct net_buf_simple *msg,
} else {
struct bt_mesh_app_key *app_key = NULL;
#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER
if (role == NODE) {
if (!bt_mesh_is_provisioner_en()) {
app_key = bt_mesh_app_key_find(tx->ctx->app_idx);
}
}
#endif
#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
if (role == PROVISIONER) {
if (bt_mesh_is_provisioner_en()) {
app_key = provisioner_app_key_find(tx->ctx->app_idx);
}
}
#endif
#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
if (role == NODE) {
app_key = bt_mesh_app_key_find(tx->ctx->app_idx);
} else if (role == PROVISIONER) {
if (bt_mesh_is_provisioner_en()) {
app_key = provisioner_app_key_find(tx->ctx->app_idx);
}
} else if (role == FAST_PROV) {
#if CONFIG_BLE_MESH_FAST_PROV
app_key = get_fast_prov_app_key(tx->ctx->net_idx, tx->ctx->app_idx);
#endif
}
#endif
app_key = bt_mesh_tx_appkey_get(role, tx->ctx->app_idx, tx->ctx->net_idx);
if (!app_key) {
BT_ERR("%s, Failed to get AppKey", __func__);
return -EINVAL;
@ -594,26 +573,23 @@ int bt_mesh_trans_send(struct bt_mesh_net_tx *tx, struct net_buf_simple *msg,
return err;
}
int bt_mesh_trans_resend(struct bt_mesh_net_tx *tx, struct net_buf_simple *msg,
const struct bt_mesh_send_cb *cb, void *cb_data)
static void update_rpl(struct bt_mesh_rpl *rpl, struct bt_mesh_net_rx *rx)
{
struct net_buf_simple_state state;
int err;
rpl->src = rx->ctx.addr;
rpl->seq = rx->seq;
rpl->old_iv = rx->old_iv;
net_buf_simple_save(msg, &state);
if (tx->ctx->send_rel || msg->len > 15) {
err = send_seg(tx, msg, cb, cb_data);
} else {
err = send_unseg(tx, msg, cb, cb_data);
if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) {
bt_mesh_store_rpl(rpl);
}
net_buf_simple_restore(msg, &state);
return err;
}
static bool is_replay(struct bt_mesh_net_rx *rx)
/* Check the Replay Protection List for a replay attempt. If non-NULL match
* parameter is given the RPL slot is returned but it is not immediately
* updated (needed for segmented messages), whereas if a NULL match is given
* the RPL is immediately updated (used for unsegmented messages).
*/
static bool is_replay(struct bt_mesh_net_rx *rx, struct bt_mesh_rpl **match)
{
int i;
@ -622,17 +598,20 @@ static bool is_replay(struct bt_mesh_net_rx *rx)
return false;
}
/* The RPL is used only for the local node */
if (!rx->local_match) {
return false;
}
for (i = 0; i < ARRAY_SIZE(bt_mesh.rpl); i++) {
struct bt_mesh_rpl *rpl = &bt_mesh.rpl[i];
/* Empty slot */
if (!rpl->src) {
rpl->src = rx->ctx.addr;
rpl->seq = rx->seq;
rpl->old_iv = rx->old_iv;
if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) {
bt_mesh_store_rpl(rpl);
if (match) {
*match = rpl;
} else {
update_rpl(rpl, rx);
}
return false;
@ -655,11 +634,10 @@ static bool is_replay(struct bt_mesh_net_rx *rx)
if ((!rx->old_iv && rpl->old_iv) ||
(rpl->seq < rx->seq) || (rpl->seq > rx->seq + 10)) {
#endif /* #if !CONFIG_BLE_MESH_PATCH_FOR_SLAB_APP_1_1_0 */
rpl->seq = rx->seq;
rpl->old_iv = rx->old_iv;
if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) {
bt_mesh_store_rpl(rpl);
if (match) {
*match = rpl;
} else {
update_rpl(rpl, rx);
}
return false;
@ -677,7 +655,7 @@ static int sdu_recv(struct bt_mesh_net_rx *rx, u32_t seq, u8_t hdr,
u8_t aszmic, struct net_buf_simple *buf)
{
struct net_buf_simple *sdu = NULL;
u32_t array_size = 0;
size_t array_size = 0;
u8_t *ad;
u16_t i;
int err;
@ -715,48 +693,12 @@ static int sdu_recv(struct bt_mesh_net_rx *rx, u32_t seq, u8_t hdr,
}
if (!AKF(&hdr)) {
#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER
if (!bt_mesh_is_provisioner_en()) {
array_size = 1;
}
#endif
#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
if (bt_mesh_is_provisioner_en()) {
array_size = 1;
}
#endif
#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
array_size = 1;
if (bt_mesh_is_provisioner_en()) {
array_size += 1;
}
#endif
array_size = bt_mesh_rx_devkey_size();
for (i = 0; i < array_size; i++) {
const u8_t *dev_key = NULL;
#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER
if (!bt_mesh_is_provisioner_en()) {
dev_key = bt_mesh.dev_key;
}
#endif
#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
if (bt_mesh_is_provisioner_en()) {
dev_key = provisioner_get_device_key(rx->ctx.addr);
}
#endif
#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
if (i < 1) {
dev_key = bt_mesh.dev_key;
} else {
dev_key = provisioner_get_device_key(rx->ctx.addr);
}
#endif
dev_key = bt_mesh_rx_devkey_get(i, rx->ctx.addr);
if (!dev_key) {
BT_DBG("%s, NULL Device Key", __func__);
continue;
@ -783,49 +725,13 @@ static int sdu_recv(struct bt_mesh_net_rx *rx, u32_t seq, u8_t hdr,
return -ENODEV;
}
#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER
if (!bt_mesh_is_provisioner_en()) {
array_size = ARRAY_SIZE(bt_mesh.app_keys);
}
#endif
#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
if (bt_mesh_is_provisioner_en()) {
array_size = ARRAY_SIZE(bt_mesh.p_app_keys);
}
#endif
#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
array_size = ARRAY_SIZE(bt_mesh.app_keys);
if (bt_mesh_is_provisioner_en()) {
array_size += ARRAY_SIZE(bt_mesh.p_app_keys);
}
#endif
array_size = bt_mesh_rx_appkey_size();
for (i = 0; i < array_size; i++) {
struct bt_mesh_app_key *key = NULL;
struct bt_mesh_app_keys *keys = NULL;
struct bt_mesh_app_key *key = NULL;
#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER
if (!bt_mesh_is_provisioner_en()) {
key = &bt_mesh.app_keys[i];
}
#endif
#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
if (bt_mesh_is_provisioner_en()) {
key = bt_mesh.p_app_keys[i];
}
#endif
#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
if (i < ARRAY_SIZE(bt_mesh.app_keys)) {
key = &bt_mesh.app_keys[i];
} else {
key = bt_mesh.p_app_keys[i - ARRAY_SIZE(bt_mesh.app_keys)];
}
#endif
key = bt_mesh_rx_appkey_get(i);
if (!key) {
BT_DBG("%s, NULL AppKey", __func__);
continue;
@ -1080,7 +986,7 @@ static int trans_unseg(struct net_buf_simple *buf, struct bt_mesh_net_rx *rx,
return -EINVAL;
}
if (rx->local_match && is_replay(rx)) {
if (is_replay(rx, NULL)) {
BT_WARN("Replay: src 0x%04x dst 0x%04x seq 0x%06x",
rx->ctx.addr, rx->ctx.recv_dst, rx->seq);
return -EINVAL;
@ -1149,8 +1055,8 @@ int bt_mesh_ctl_send(struct bt_mesh_net_tx *tx, u8_t ctl_op, void *data,
if (IS_ENABLED(CONFIG_BLE_MESH_FRIEND)) {
if (bt_mesh_friend_enqueue_tx(tx, BLE_MESH_FRIEND_PDU_SINGLE,
seq_auth, &buf->b) &&
BLE_MESH_ADDR_IS_UNICAST(tx->ctx->addr)) {
seq_auth, 1, &buf->b) &&
BLE_MESH_ADDR_IS_UNICAST(tx->ctx->addr)) {
/* PDUs for a specific Friend should only go
* out through the Friend Queue.
*/
@ -1357,8 +1263,10 @@ static struct seg_rx *seg_rx_alloc(struct bt_mesh_net_rx *net_rx,
}
static int trans_seg(struct net_buf_simple *buf, struct bt_mesh_net_rx *net_rx,
enum bt_mesh_friend_pdu_type *pdu_type, u64_t *seq_auth)
enum bt_mesh_friend_pdu_type *pdu_type, u64_t *seq_auth,
u8_t *seg_count)
{
struct bt_mesh_rpl *rpl = NULL;
struct seg_rx *rx;
u8_t *hdr = buf->data;
u16_t seq_zero;
@ -1371,6 +1279,12 @@ static int trans_seg(struct net_buf_simple *buf, struct bt_mesh_net_rx *net_rx,
return -EINVAL;
}
if (is_replay(net_rx, &rpl)) {
BT_WARN("Replay: src 0x%04x dst 0x%04x seq 0x%06x",
net_rx->ctx.addr, net_rx->ctx.recv_dst, net_rx->seq);
return -EINVAL;
}
BT_DBG("ASZMIC %u AKF %u AID 0x%02x", ASZMIC(hdr), AKF(hdr), AID(hdr));
net_buf_simple_pull(buf, 1);
@ -1407,6 +1321,8 @@ static int trans_seg(struct net_buf_simple *buf, struct bt_mesh_net_rx *net_rx,
((((net_rx->seq & BIT_MASK(14)) - seq_zero)) &
BIT_MASK(13))));
*seg_count = seg_n + 1;
/* Look for old RX sessions */
rx = seg_rx_find(net_rx, seq_auth);
if (rx) {
@ -1430,6 +1346,11 @@ static int trans_seg(struct net_buf_simple *buf, struct bt_mesh_net_rx *net_rx,
send_ack(net_rx->sub, net_rx->ctx.recv_dst,
net_rx->ctx.addr, net_rx->ctx.send_ttl,
seq_auth, rx->block, rx->obo);
if (rpl) {
update_rpl(rpl, net_rx);
}
return -EALREADY;
}
@ -1450,6 +1371,22 @@ static int trans_seg(struct net_buf_simple *buf, struct bt_mesh_net_rx *net_rx,
return -EMSGSIZE;
}
/* Verify early that there will be space in the Friend Queue(s) in
* case this message is destined to an LPN of ours.
*/
if (IS_ENABLED(CONFIG_BLE_MESH_FRIEND) &&
net_rx->friend_match && !net_rx->local_match &&
!bt_mesh_friend_queue_has_space(net_rx->sub->net_idx,
net_rx->ctx.addr,
net_rx->ctx.recv_dst, seq_auth,
*seg_count)) {
BT_ERR("No space in Friend Queue for %u segments", *seg_count);
send_ack(net_rx->sub, net_rx->ctx.recv_dst, net_rx->ctx.addr,
net_rx->ctx.send_ttl, seq_auth, 0,
net_rx->friend_match);
return -ENOBUFS;
}
/* Look for free slot for a new RX session */
rx = seg_rx_alloc(net_rx, hdr, seq_auth, seg_n);
if (!rx) {
@ -1517,12 +1454,8 @@ found_rx:
BT_DBG("Complete SDU");
if (net_rx->local_match && is_replay(net_rx)) {
BT_WARN("Replay: src 0x%04x dst 0x%04x seq 0x%06x",
net_rx->ctx.addr, net_rx->ctx.recv_dst, net_rx->seq);
/* Clear the segment's bit */
rx->block &= ~BIT(seg_o);
return -EINVAL;
if (rpl) {
update_rpl(rpl, net_rx);
}
*pdu_type = BLE_MESH_FRIEND_PDU_COMPLETE;
@ -1548,6 +1481,7 @@ int bt_mesh_trans_recv(struct net_buf_simple *buf, struct bt_mesh_net_rx *rx)
u64_t seq_auth = TRANS_SEQ_AUTH_NVAL;
enum bt_mesh_friend_pdu_type pdu_type = BLE_MESH_FRIEND_PDU_SINGLE;
struct net_buf_simple_state state;
u8_t seg_count = 0U;
int err;
if (IS_ENABLED(CONFIG_BLE_MESH_FRIEND)) {
@ -1591,8 +1525,9 @@ int bt_mesh_trans_recv(struct net_buf_simple *buf, struct bt_mesh_net_rx *rx)
return 0;
}
err = trans_seg(buf, rx, &pdu_type, &seq_auth);
err = trans_seg(buf, rx, &pdu_type, &seq_auth, &seg_count);
} else {
seg_count = 1U;
err = trans_unseg(buf, rx, &seq_auth);
}
@ -1608,24 +1543,26 @@ int bt_mesh_trans_recv(struct net_buf_simple *buf, struct bt_mesh_net_rx *rx)
*
*/
if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_provisioned()) {
if (IS_ENABLED(CONFIG_BLE_MESH_LOW_POWER) &&
(bt_mesh_lpn_timer() ||
(bt_mesh_lpn_established() && bt_mesh_lpn_waiting_update()))) {
bt_mesh_lpn_msg_received(rx);
}
if (IS_ENABLED(CONFIG_BLE_MESH_LOW_POWER) &&
(bt_mesh_lpn_timer() ||
(bt_mesh_lpn_established() && bt_mesh_lpn_waiting_update()))) {
bt_mesh_lpn_msg_received(rx);
}
}
net_buf_simple_restore(buf, &state);
if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_provisioned()) {
if (IS_ENABLED(CONFIG_BLE_MESH_FRIEND) && rx->friend_match && !err) {
if (seq_auth == TRANS_SEQ_AUTH_NVAL) {
bt_mesh_friend_enqueue_rx(rx, pdu_type, NULL, buf);
} else {
bt_mesh_friend_enqueue_rx(rx, pdu_type, &seq_auth, buf);
if (IS_ENABLED(CONFIG_BLE_MESH_FRIEND) && rx->friend_match && !err) {
if (seq_auth == TRANS_SEQ_AUTH_NVAL) {
bt_mesh_friend_enqueue_rx(rx, pdu_type, NULL,
seg_count, buf);
} else {
bt_mesh_friend_enqueue_rx(rx, pdu_type, &seq_auth,
seg_count, buf);
}
}
}
}
return err;
}
@ -1679,3 +1616,55 @@ void bt_mesh_rpl_clear(void)
BT_DBG("%s", __func__);
(void)memset(bt_mesh.rpl, 0, sizeof(bt_mesh.rpl));
}
void bt_mesh_heartbeat_send(void)
{
struct bt_mesh_cfg_srv *cfg = bt_mesh_cfg_get();
u16_t feat = 0U;
struct __packed {
u8_t init_ttl;
u16_t feat;
} hb;
struct bt_mesh_msg_ctx ctx = {
.net_idx = cfg->hb_pub.net_idx,
.app_idx = BLE_MESH_KEY_UNUSED,
.addr = cfg->hb_pub.dst,
.send_ttl = cfg->hb_pub.ttl,
};
struct bt_mesh_net_tx tx = {
.sub = bt_mesh_subnet_get(cfg->hb_pub.net_idx),
.ctx = &ctx,
.src = bt_mesh_model_elem(cfg->model)->addr,
.xmit = bt_mesh_net_transmit_get(),
};
/* Do nothing if heartbeat publication is not enabled */
if (cfg->hb_pub.dst == BLE_MESH_ADDR_UNASSIGNED) {
return;
}
hb.init_ttl = cfg->hb_pub.ttl;
if (bt_mesh_relay_get() == BLE_MESH_RELAY_ENABLED) {
feat |= BLE_MESH_FEAT_RELAY;
}
if (bt_mesh_gatt_proxy_get() == BLE_MESH_GATT_PROXY_ENABLED) {
feat |= BLE_MESH_FEAT_PROXY;
}
if (bt_mesh_friend_get() == BLE_MESH_FRIEND_ENABLED) {
feat |= BLE_MESH_FEAT_FRIEND;
}
if (bt_mesh_lpn_established()) {
feat |= BLE_MESH_FEAT_LOW_POWER;
}
hb.feat = sys_cpu_to_be16(feat);
BT_DBG("InitTTL %u feat 0x%04x", cfg->hb_pub.ttl, feat);
bt_mesh_ctl_send(&tx, TRANS_CTL_OP_HEARTBEAT, &hb, sizeof(hb),
NULL, NULL, NULL);
}

View File

@ -99,4 +99,6 @@ void bt_mesh_trans_init(void);
void bt_mesh_rpl_clear(void);
void bt_mesh_heartbeat_send(void);
#endif /* _TRANSPORT_H_ */

View File

@ -16,6 +16,7 @@
#include <errno.h>
#include "osi/allocator.h"
#include "osi/mutex.h"
#include "mesh_access.h"
#include "mesh_buf.h"
@ -23,15 +24,15 @@
#include "mesh_main.h"
#include "mesh.h"
#include "model_common.h"
#include "client_common.h"
bt_mesh_client_node_t *bt_mesh_is_model_message_publish(struct bt_mesh_model *model,
bt_mesh_client_node_t *bt_mesh_is_client_recv_publish_msg(
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf,
bool need_pub)
struct net_buf_simple *buf, bool need_pub)
{
bt_mesh_internal_data_t *data = NULL;
bt_mesh_client_common_t *cli = NULL;
bt_mesh_client_internal_data_t *data = NULL;
bt_mesh_client_user_data_t *cli = NULL;
bt_mesh_client_node_t *node = NULL;
u32_t rsp;
@ -40,7 +41,7 @@ bt_mesh_client_node_t *bt_mesh_is_model_message_publish(struct bt_mesh_model *mo
return NULL;
}
cli = (bt_mesh_client_common_t *)model->user_data;
cli = (bt_mesh_client_user_data_t *)model->user_data;
if (!cli) {
BT_ERR("%s, Clinet user_data is NULL", __func__);
return NULL;
@ -65,7 +66,7 @@ bt_mesh_client_node_t *bt_mesh_is_model_message_publish(struct bt_mesh_model *mo
* message, then the message is from another element and
* push it to application layer.
*/
data = (bt_mesh_internal_data_t *)cli->internal_data;
data = (bt_mesh_client_internal_data_t *)cli->internal_data;
if (!data) {
BT_ERR("%s, Client internal_data is NULL", __func__);
return NULL;
@ -172,8 +173,8 @@ int bt_mesh_client_send_msg(struct bt_mesh_model *model,
const struct bt_mesh_send_cb *cb,
void *cb_data)
{
bt_mesh_internal_data_t *internal = NULL;
bt_mesh_client_common_t *cli = NULL;
bt_mesh_client_internal_data_t *internal = NULL;
bt_mesh_client_user_data_t *cli = NULL;
bt_mesh_client_node_t *node = NULL;
int err;
@ -182,9 +183,9 @@ int bt_mesh_client_send_msg(struct bt_mesh_model *model,
return -EINVAL;
}
cli = (bt_mesh_client_common_t *)model->user_data;
cli = (bt_mesh_client_user_data_t *)model->user_data;
__ASSERT(cli, "Invalid client value when sent client msg.");
internal = (bt_mesh_internal_data_t *)cli->internal_data;
internal = (bt_mesh_client_internal_data_t *)cli->internal_data;
__ASSERT(internal, "Invalid internal value when sent client msg.");
if (!need_ack) {
@ -222,10 +223,32 @@ int bt_mesh_client_send_msg(struct bt_mesh_model *model,
return err;
}
static osi_mutex_t client_model_mutex;
static void bt_mesh_client_model_mutex_new(void)
{
static bool init;
if (!init) {
osi_mutex_new(&client_model_mutex);
init = true;
}
}
void bt_mesh_client_model_lock(void)
{
osi_mutex_lock(&client_model_mutex, OSI_MUTEX_MAX_TIMEOUT);
}
void bt_mesh_client_model_unlock(void)
{
osi_mutex_unlock(&client_model_mutex);
}
int bt_mesh_client_init(struct bt_mesh_model *model)
{
bt_mesh_internal_data_t *data = NULL;
bt_mesh_client_common_t *cli = NULL;
bt_mesh_client_internal_data_t *data = NULL;
bt_mesh_client_user_data_t *cli = NULL;
if (!model) {
BT_ERR("%s, Invalid parameter", __func__);
@ -244,7 +267,7 @@ int bt_mesh_client_init(struct bt_mesh_model *model)
}
/* TODO: call osi_free() when deinit function is invoked */
data = osi_calloc(sizeof(bt_mesh_internal_data_t));
data = osi_calloc(sizeof(bt_mesh_client_internal_data_t));
if (!data) {
BT_ERR("%s, Failed to allocate memory", __func__);
return -ENOMEM;
@ -256,35 +279,51 @@ int bt_mesh_client_init(struct bt_mesh_model *model)
cli->model = model;
cli->internal_data = data;
bt_mesh_client_model_mutex_new();
return 0;
}
int bt_mesh_client_free_node(sys_slist_t *queue, bt_mesh_client_node_t *node)
int bt_mesh_client_free_node(bt_mesh_client_node_t *node)
{
if (!queue || !node) {
bt_mesh_client_internal_data_t *internal = NULL;
bt_mesh_client_user_data_t *client = NULL;
if (!node || !node->ctx.model) {
BT_ERR("%s, Client model list item is NULL", __func__);
return -EINVAL;
}
client = (bt_mesh_client_user_data_t *)node->ctx.model->user_data;
if (!client) {
BT_ERR("%s, Client model user data is NULL", __func__);
return -EINVAL;
}
internal = (bt_mesh_client_internal_data_t *)client->internal_data;
if (!internal) {
BT_ERR("%s, Client model internal data is NULL", __func__);
return -EINVAL;
}
// Free the node timer
k_delayed_work_free(&node->timer);
// Release the client node from the queue
sys_slist_find_and_remove(queue, &node->client_node);
sys_slist_find_and_remove(&internal->queue, &node->client_node);
// Free the node
osi_free(node);
return 0;
}
int bt_mesh_set_model_role(bt_mesh_role_param_t *common)
int bt_mesh_set_client_model_role(bt_mesh_role_param_t *common)
{
bt_mesh_client_common_t *client = NULL;
bt_mesh_client_user_data_t *client = NULL;
if (!common || !common->model || !common->model->user_data) {
BT_ERR("%s, Invalid parameter", __func__);
return -EINVAL;
}
client = (bt_mesh_client_common_t *)common->model->user_data;
client = (bt_mesh_client_user_data_t *)common->model->user_data;
switch (common->role) {
#if CONFIG_BLE_MESH_NODE
@ -315,22 +354,3 @@ int bt_mesh_set_model_role(bt_mesh_role_param_t *common)
return 0;
}
u8_t bt_mesh_get_model_role(struct bt_mesh_model *model, bool srv_send)
{
bt_mesh_client_common_t *client = NULL;
if (srv_send) {
BT_DBG("%s, Message is sent by a server model", __func__);
return NODE;
}
if (!model || !model->user_data) {
BT_ERR("%s, Invalid parameter", __func__);
return ROLE_NVAL;
}
client = (bt_mesh_client_common_t *)model->user_data;
return client->msg_role;
}

View File

@ -17,6 +17,7 @@
#include <stdbool.h>
#include "osi/allocator.h"
#include "osi/mutex.h"
#include "sdkconfig.h"
#include "mesh_types.h"
@ -119,36 +120,50 @@ static const bt_mesh_client_op_pair_t gen_op_pair[] = {
{ BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_GET, BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_STATUS },
};
static osi_mutex_t generic_client_mutex;
static void bt_mesh_generic_client_mutex_new(void)
{
static bool init;
if (!init) {
osi_mutex_new(&generic_client_mutex);
init = true;
}
}
static void bt_mesh_generic_client_lock(void)
{
osi_mutex_lock(&generic_client_mutex, OSI_MUTEX_MAX_TIMEOUT);
}
static void bt_mesh_generic_client_unlock(void)
{
osi_mutex_unlock(&generic_client_mutex);
}
static void timeout_handler(struct k_work *work)
{
generic_internal_data_t *internal = NULL;
bt_mesh_generic_client_t *client = NULL;
struct k_delayed_work *timer = NULL;
bt_mesh_client_node_t *node = NULL;
BT_WARN("Receive generic status message timeout");
node = CONTAINER_OF(work, bt_mesh_client_node_t, timer.work);
if (!node || !node->ctx.model) {
BT_ERR("%s, Invalid parameter", __func__);
return;
bt_mesh_generic_client_lock();
timer = CONTAINER_OF(work, struct k_delayed_work, work);
if (timer && !k_delayed_work_free(timer)) {
node = CONTAINER_OF(work, bt_mesh_client_node_t, timer.work);
if (node) {
bt_mesh_generic_client_cb_evt_to_btc(node->opcode,
BTC_BLE_MESH_EVT_GENERIC_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0);
// Don't forget to release the node at the end.
bt_mesh_client_free_node(node);
}
}
client = (bt_mesh_generic_client_t *)node->ctx.model->user_data;
if (!client) {
BT_ERR("%s, Generic Client user_data is NULL", __func__);
return;
}
internal = (generic_internal_data_t *)client->internal_data;
if (!internal) {
BT_ERR("%s, Generic Client internal_data is NULL", __func__);
return;
}
bt_mesh_callback_generic_status_to_btc(node->opcode, 0x03, node->ctx.model,
&node->ctx, NULL, 0);
bt_mesh_client_free_node(&internal->queue, node);
bt_mesh_generic_client_unlock();
return;
}
@ -157,31 +172,14 @@ static void generic_status(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
generic_internal_data_t *internal = NULL;
bt_mesh_generic_client_t *client = NULL;
bt_mesh_client_node_t *node = NULL;
u8_t *val = NULL;
u8_t evt = 0xFF;
u32_t rsp = 0;
u8_t *val = NULL;
u8_t evt = 0xFF;
size_t len = 0;
BT_DBG("%s, len %d, bytes %s", __func__, buf->len, bt_hex(buf->data, buf->len));
client = (bt_mesh_generic_client_t *)model->user_data;
if (!client) {
BT_ERR("%s, Generic Client user_data is NULL", __func__);
return;
}
internal = (generic_internal_data_t *)client->internal_data;
if (!internal) {
BT_ERR("%s, Generic Client internal_data is NULL", __func__);
return;
}
rsp = ctx->recv_op;
switch (rsp) {
switch (ctx->recv_op) {
case BLE_MESH_MODEL_OP_GEN_ONOFF_STATUS: {
struct bt_mesh_gen_onoff_status *status = NULL;
if (buf->len != 1 && buf->len != 3) {
@ -535,9 +533,12 @@ static void generic_status(struct bt_mesh_model *model,
buf->data = val;
buf->len = len;
node = bt_mesh_is_model_message_publish(model, ctx, buf, true);
bt_mesh_generic_client_lock();
node = bt_mesh_is_client_recv_publish_msg(model, ctx, buf, true);
if (!node) {
BT_DBG("Unexpected generic status message 0x%x", rsp);
BT_DBG("Unexpected generic status message 0x%x", ctx->recv_op);
} else {
switch (node->opcode) {
case BLE_MESH_MODEL_OP_GEN_ONOFF_GET:
@ -558,7 +559,7 @@ static void generic_status(struct bt_mesh_model *model,
case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTIES_GET:
case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_GET:
case BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_GET:
evt = 0x00;
evt = BTC_BLE_MESH_EVT_GENERIC_CLIENT_GET_STATE;
break;
case BLE_MESH_MODEL_OP_GEN_ONOFF_SET:
case BLE_MESH_MODEL_OP_GEN_LEVEL_SET:
@ -574,18 +575,22 @@ static void generic_status(struct bt_mesh_model *model,
case BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET:
case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET:
case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_SET:
evt = 0x01;
evt = BTC_BLE_MESH_EVT_GENERIC_CLIENT_SET_STATE;
break;
default:
break;
}
bt_mesh_callback_generic_status_to_btc(node->opcode, evt, model, ctx, val, len);
// Don't forget to release the node at the end.
bt_mesh_client_free_node(&internal->queue, node);
if (!k_delayed_work_free(&node->timer)) {
bt_mesh_generic_client_cb_evt_to_btc(node->opcode, evt, model, ctx, val, len);
// Don't forget to release the node at the end.
bt_mesh_client_free_node(node);
}
}
switch (rsp) {
bt_mesh_generic_client_unlock();
switch (ctx->recv_op) {
case BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_STATUS: {
struct bt_mesh_gen_user_properties_status *status;
status = (struct bt_mesh_gen_user_properties_status *)val;
@ -687,7 +692,7 @@ const struct bt_mesh_model_op gen_property_cli_op[] = {
BLE_MESH_MODEL_OP_END,
};
static int gen_get_state(struct bt_mesh_common_param *common, void *value)
static int gen_get_state(bt_mesh_client_common_param_t *common, void *value)
{
NET_BUF_SIMPLE_DEFINE(msg, BLE_MESH_GEN_GET_STATE_MSG_LEN);
int err;
@ -736,7 +741,7 @@ static int gen_get_state(struct bt_mesh_common_param *common, void *value)
return err;
}
static int gen_set_state(struct bt_mesh_common_param *common,
static int gen_set_state(bt_mesh_client_common_param_t *common,
void *value, u16_t value_len, bool need_ack)
{
struct net_buf_simple *msg = NULL;
@ -781,8 +786,8 @@ static int gen_set_state(struct bt_mesh_common_param *common,
case BLE_MESH_MODEL_OP_GEN_DELTA_SET_UNACK: {
struct bt_mesh_gen_delta_set *set;
set = (struct bt_mesh_gen_delta_set *)value;
net_buf_simple_add_le32(msg, set->level);
net_buf_simple_add_u8(msg, set->tid);
net_buf_simple_add_le32(msg, set->delta_level);
net_buf_simple_add_u8(msg, set->tid);
if (set->op_en) {
net_buf_simple_add_u8(msg, set->trans_time);
net_buf_simple_add_u8(msg, set->delay);
@ -918,7 +923,7 @@ end:
return err;
}
int bt_mesh_generic_client_get_state(struct bt_mesh_common_param *common, void *get, void *status)
int bt_mesh_generic_client_get_state(bt_mesh_client_common_param_t *common, void *get, void *status)
{
bt_mesh_generic_client_t *client = NULL;
@ -981,7 +986,7 @@ int bt_mesh_generic_client_get_state(struct bt_mesh_common_param *common, void *
return gen_get_state(common, get);
}
int bt_mesh_generic_client_set_state(struct bt_mesh_common_param *common, void *set, void *status)
int bt_mesh_generic_client_set_state(bt_mesh_client_common_param_t *common, void *set, void *status)
{
bt_mesh_generic_client_t *client = NULL;
u16_t length = 0;
@ -1181,6 +1186,8 @@ static int generic_client_init(struct bt_mesh_model *model, bool primary)
client->op_pair = gen_op_pair;
client->internal_data = internal;
bt_mesh_generic_client_mutex_new();
return 0;
}

View File

@ -17,17 +17,23 @@
#include "mesh_access.h"
/** Mesh Client Model Context */
/** Client model opcode pair table */
typedef struct {
u32_t cli_op; /* The client opcode */
u32_t status_op; /* The server status opcode corresponding to the client opcode */
u32_t cli_op; /* Client message opcode */
u32_t status_op; /* Corresponding status message opcode */
} bt_mesh_client_op_pair_t;
/** Mesh Client Model Context */
/** Client model user data context */
typedef struct {
/** Pointer to the client model */
struct bt_mesh_model *model;
int op_pair_size; /* the size of op_pair */
/** Size of the opcode pair table */
int op_pair_size;
/** Pointer to the opcode pair table */
const bt_mesh_client_op_pair_t *op_pair;
/**
* @brief This function is a callback function used to push the received unsolicited
* messages to the application layer.
@ -40,26 +46,46 @@ typedef struct {
* @return None
*/
void (*publish_status)(u32_t opcode, struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf);
void *internal_data; /* Pointer of the structure of internal data */
u8_t msg_role; /* device role of the tx message */
} bt_mesh_client_common_t;
/** Pointer to the internal data of client model */
void *internal_data;
/** Role of the device to which the client model belongs */
u8_t msg_role;
} bt_mesh_client_user_data_t;
/** Client model internal data context */
typedef struct {
sys_slist_t queue;
} bt_mesh_internal_data_t;
} bt_mesh_client_internal_data_t;
/** Client model sending message related context */
typedef struct {
sys_snode_t client_node;
struct bt_mesh_msg_ctx ctx;
u32_t opcode; /* Indicate the opcode of the message sending */
u32_t op_pending; /* Indicate the status message waiting for */
struct k_delayed_work timer; /* Message send Timer. Only for stack-internal use. */
struct bt_mesh_msg_ctx ctx; /* Message context */
u32_t opcode; /* Message opcode */
u32_t op_pending; /* Expected status message opcode */
struct k_delayed_work timer; /* Time used to get response. Only for internal use. */
} bt_mesh_client_node_t;
/** Client model sending message parameters */
typedef struct {
u32_t opcode; /* Message opcode */
struct bt_mesh_model *model; /* Pointer to the client model */
struct bt_mesh_msg_ctx ctx; /* Message context */
s32_t msg_timeout; /* Time to get corresponding response */
const struct bt_mesh_send_cb *cb; /* User defined callback function */
void *cb_data; /* User defined callback value */
} bt_mesh_client_common_param_t;
void bt_mesh_client_model_lock(void);
void bt_mesh_client_model_unlock(void);
int bt_mesh_client_init(struct bt_mesh_model *model);
/**
* @brief Check the msg is a publish msg or not
* @brief Check if the msg received by client model is a publish msg or not
*
* @param model Mesh (client) Model that the message belongs to.
* @param ctx Message context, includes keys, TTL, etc.
@ -67,10 +93,10 @@ int bt_mesh_client_init(struct bt_mesh_model *model);
* @param need_pub Indicate if the msg sent to app layer as a publish msg
* @return 0 on success, or (negative) error code on failure.
*/
bt_mesh_client_node_t *bt_mesh_is_model_message_publish(struct bt_mesh_model *model,
bt_mesh_client_node_t *bt_mesh_is_client_recv_publish_msg(
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf,
bool need_pub);
struct net_buf_simple *buf, bool need_pub);
bool bt_mesh_client_find_opcode_in_list(sys_slist_t *list, u32_t opcode);
@ -86,7 +112,7 @@ int bt_mesh_client_send_msg(struct bt_mesh_model *model,
s32_t timeout, bool need_ack,
const struct bt_mesh_send_cb *cb, void *cb_data);
int bt_mesh_client_free_node(sys_slist_t *queue, bt_mesh_client_node_t *node);
int bt_mesh_client_free_node(bt_mesh_client_node_t *node);
enum {
NODE = 0,
@ -94,18 +120,9 @@ enum {
FAST_PROV,
};
#define ROLE_NVAL 0xFF
#define ROLE_NVAL 0xFF
struct bt_mesh_common_param {
u32_t opcode; /* Message opcode */
struct bt_mesh_model *model; /* Pointer to cli structure */
struct bt_mesh_msg_ctx ctx; /* Message context */
s32_t msg_timeout; /* Time to get response messages */
const struct bt_mesh_send_cb *cb; /* User defined callback function */
void *cb_data; /* Data as parameter of the cb function */
};
typedef struct bt_mesh_role_param {
typedef struct {
struct bt_mesh_model *model; /* The client model structure */
u8_t role; /* Role of the device - Node/Provisioner */
} bt_mesh_role_param_t;
@ -113,21 +130,11 @@ typedef struct bt_mesh_role_param {
/**
* @brief This function copies node_index for stack internal use.
*
* @param[in] common: Pointer to the struct bt_mesh_role_param structure
* @param[in] common: Pointer to the bt_mesh_role_param_t structure
*
* @return Zero - success, otherwise - fail
*/
int bt_mesh_set_model_role(bt_mesh_role_param_t *common);
/**
* @brief This function gets msg role for stack internal use.
*
* @param[in] model: Pointer to the model structure
* @param[in] srv_send: Indicate if the message is sent by a server model
*
* @return 0 - Node, 1 - Provisioner
*/
u8_t bt_mesh_get_model_role(struct bt_mesh_model *model, bool srv_send);
int bt_mesh_set_client_model_role(bt_mesh_role_param_t *common);
#endif /* _MODEL_COMMON_H_ */

View File

@ -22,11 +22,11 @@
#include "mesh_access.h"
#include "mesh_kernel.h"
#include "model_common.h"
#include "client_common.h"
/* Generic client model common structure */
typedef bt_mesh_client_common_t bt_mesh_generic_client_t;
typedef bt_mesh_internal_data_t generic_internal_data_t;
typedef bt_mesh_client_user_data_t bt_mesh_generic_client_t;
typedef bt_mesh_client_internal_data_t generic_internal_data_t;
/* Generic OnOff Client Model Context */
extern const struct bt_mesh_model_op gen_onoff_cli_op[];
@ -45,7 +45,7 @@ extern const struct bt_mesh_model_op gen_onoff_cli_op[];
BLE_MESH_MODEL(BLE_MESH_MODEL_ID_GEN_ONOFF_CLI, \
gen_onoff_cli_op, cli_pub, cli_data)
typedef bt_mesh_client_common_t bt_mesh_gen_onoff_cli_t;
typedef bt_mesh_client_user_data_t bt_mesh_gen_onoff_client_t;
struct bt_mesh_gen_onoff_status {
bool op_en; /* Indicate whether optional parameters included */
@ -79,7 +79,7 @@ extern const struct bt_mesh_model_op gen_level_cli_op[];
BLE_MESH_MODEL(BLE_MESH_MODEL_ID_GEN_LEVEL_CLI, \
gen_level_cli_op, cli_pub, cli_data)
typedef bt_mesh_client_common_t bt_mesh_gen_level_cli_t;
typedef bt_mesh_client_user_data_t bt_mesh_gen_level_client_t;
struct bt_mesh_gen_level_status {
bool op_en; /* Indicate whether optional parameters included */
@ -97,11 +97,11 @@ struct bt_mesh_gen_level_set {
};
struct bt_mesh_gen_delta_set {
bool op_en; /* Indicate whether optional parameters included */
s32_t level; /* Delta change of Generic Level state */
u8_t tid; /* Transaction Identifier */
u8_t trans_time; /* Time to complete state transition (optional) */
u8_t delay; /* Indicate message execution delay (C.1) */
bool op_en; /* Indicate whether optional parameters included */
s32_t delta_level; /* Delta change of Generic Level state */
u8_t tid; /* Transaction Identifier */
u8_t trans_time; /* Time to complete state transition (optional) */
u8_t delay; /* Indicate message execution delay (C.1) */
};
struct bt_mesh_gen_move_set {
@ -130,7 +130,7 @@ extern const struct bt_mesh_model_op gen_def_trans_time_cli_op[];
BLE_MESH_MODEL(BLE_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_CLI, \
gen_def_trans_time_cli_op, cli_pub, cli_data)
typedef bt_mesh_client_common_t bt_mesh_gen_def_trans_time_cli_t;
typedef bt_mesh_client_user_data_t bt_mesh_gen_def_trans_time_client_t;
struct bt_mesh_gen_def_trans_time_set {
u8_t trans_time; /* The value of the Generic Default Transition Time state */
@ -157,7 +157,7 @@ extern const struct bt_mesh_model_op gen_power_onoff_cli_op[];
BLE_MESH_MODEL(BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_CLI, \
gen_power_onoff_cli_op, cli_pub, cli_data)
typedef bt_mesh_client_common_t bt_mesh_gen_power_onoff_cli_t;
typedef bt_mesh_client_user_data_t bt_mesh_gen_power_onoff_client_t;
struct bt_mesh_gen_onpowerup_set {
u8_t onpowerup; /* The value of the Generic OnPowerUp state */
@ -184,7 +184,7 @@ extern const struct bt_mesh_model_op gen_power_level_cli_op[];
BLE_MESH_MODEL(BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_CLI, \
gen_power_level_cli_op, cli_pub, cli_data)
typedef bt_mesh_client_common_t bt_mesh_gen_power_level_cli_t;
typedef bt_mesh_client_user_data_t bt_mesh_gen_power_level_client_t;
struct bt_mesh_gen_power_level_status {
bool op_en; /* Indicate whether optional parameters included */
@ -241,7 +241,7 @@ extern const struct bt_mesh_model_op gen_battery_cli_op[];
BLE_MESH_MODEL(BLE_MESH_MODEL_ID_GEN_BATTERY_CLI, \
gen_battery_cli_op, cli_pub, cli_data)
typedef bt_mesh_client_common_t bt_mesh_gen_battery_cli_t;
typedef bt_mesh_client_user_data_t bt_mesh_gen_battery_client_t;
struct bt_mesh_gen_battery_status {
u32_t battery_level : 8; /* Value of Generic Battery Level state */
@ -267,7 +267,7 @@ extern const struct bt_mesh_model_op gen_location_cli_op[];
BLE_MESH_MODEL(BLE_MESH_MODEL_ID_GEN_LOCATION_CLI, \
gen_location_cli_op, cli_pub, cli_data)
typedef bt_mesh_client_common_t bt_mesh_gen_location_cli_t;
typedef bt_mesh_client_user_data_t bt_mesh_gen_location_client_t;
struct bt_mesh_gen_loc_global_status {
s32_t global_latitude; /* Global Coordinates (Latitude) */
@ -314,7 +314,7 @@ extern const struct bt_mesh_model_op gen_property_cli_op[];
BLE_MESH_MODEL(BLE_MESH_MODEL_ID_GEN_PROP_CLI, \
gen_property_cli_op, cli_pub, cli_data)
typedef bt_mesh_client_common_t bt_mesh_gen_property_cli_t;
typedef bt_mesh_client_user_data_t bt_mesh_gen_property_client_t;
struct bt_mesh_gen_user_properties_status {
struct net_buf_simple *user_property_ids; /* Buffer contains a sequence of N User Property IDs */
@ -475,7 +475,7 @@ int bt_mesh_gen_property_cli_init(struct bt_mesh_model *model, bool primary);
*
* @return Zero-success, other-fail
*/
int bt_mesh_generic_client_get_state(struct bt_mesh_common_param *common, void *get, void *status);
int bt_mesh_generic_client_get_state(bt_mesh_client_common_param_t *common, void *get, void *status);
/**
* @brief This function is called to set generic states.
@ -486,6 +486,6 @@ int bt_mesh_generic_client_get_state(struct bt_mesh_common_param *common, void *
*
* @return Zero-success, other-fail
*/
int bt_mesh_generic_client_set_state(struct bt_mesh_common_param *common, void *set, void *status);
int bt_mesh_generic_client_set_state(bt_mesh_client_common_param_t *common, void *set, void *status);
#endif /* _GENERIC_CLIENT_H_ */

View File

@ -22,11 +22,11 @@
#include "mesh_access.h"
#include "mesh_kernel.h"
#include "model_common.h"
#include "client_common.h"
/* Light client model common structure */
typedef bt_mesh_client_common_t bt_mesh_light_client_t;
typedef bt_mesh_internal_data_t light_internal_data_t;
typedef bt_mesh_client_user_data_t bt_mesh_light_client_t;
typedef bt_mesh_client_internal_data_t light_internal_data_t;
/* Light Lightness Client Model Context */
extern const struct bt_mesh_model_op light_lightness_cli_op[];
@ -45,7 +45,7 @@ extern const struct bt_mesh_model_op light_lightness_cli_op[];
BLE_MESH_MODEL(BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_CLI, \
light_lightness_cli_op, cli_pub, cli_data)
typedef bt_mesh_client_common_t bt_mesh_light_lightness_cli_t;
typedef bt_mesh_client_user_data_t bt_mesh_light_lightness_client_t;
struct bt_mesh_light_lightness_status {
bool op_en; /* Indicate whether optional parameters included */
@ -117,7 +117,7 @@ extern const struct bt_mesh_model_op light_ctl_cli_op[];
BLE_MESH_MODEL(BLE_MESH_MODEL_ID_LIGHT_CTL_CLI, \
light_ctl_cli_op, cli_pub, cli_data)
typedef bt_mesh_client_common_t bt_mesh_light_ctl_cli_t;
typedef bt_mesh_client_user_data_t bt_mesh_light_ctl_client_t;
struct bt_mesh_light_ctl_status {
bool op_en; /* Indicate whether optional parameters included */
@ -196,7 +196,7 @@ extern const struct bt_mesh_model_op light_hsl_cli_op[];
BLE_MESH_MODEL(BLE_MESH_MODEL_ID_LIGHT_HSL_CLI, \
light_hsl_cli_op, cli_pub, cli_data)
typedef bt_mesh_client_common_t bt_mesh_light_hsl_cli_t;
typedef bt_mesh_client_user_data_t bt_mesh_light_hsl_client_t;
struct bt_mesh_light_hsl_status {
bool op_en; /* Indicate whether optional parameters included */
@ -298,7 +298,7 @@ extern const struct bt_mesh_model_op light_xyl_cli_op[];
BLE_MESH_MODEL(BLE_MESH_MODEL_ID_LIGHT_XYL_CLI, \
light_xyl_cli_op, cli_pub, cli_data)
typedef bt_mesh_client_common_t bt_mesh_light_xyl_cli_t;
typedef bt_mesh_client_user_data_t bt_mesh_light_xyl_client_t;
struct bt_mesh_light_xyl_status {
bool op_en; /* Indicate whether optional parameters included */
@ -370,7 +370,7 @@ extern const struct bt_mesh_model_op light_lc_cli_op[];
BLE_MESH_MODEL(BLE_MESH_MODEL_ID_LIGHT_LC_CLI, \
light_lc_cli_op, cli_pub, cli_data)
typedef bt_mesh_client_common_t bt_mesh_light_lc_cli_t;
typedef bt_mesh_client_user_data_t bt_mesh_light_lc_client_t;
struct bt_mesh_light_lc_mode_status {
u8_t mode; /* The present value of the Light LC Mode state */
@ -476,7 +476,7 @@ int bt_mesh_light_lc_cli_init(struct bt_mesh_model *model, bool primary);
*
* @return Zero-success, other-fail
*/
int bt_mesh_light_client_get_state(struct bt_mesh_common_param *common, void *get, void *status);
int bt_mesh_light_client_get_state(bt_mesh_client_common_param_t *common, void *get, void *status);
/**
* @brief This function is called to set light states.
@ -487,6 +487,6 @@ int bt_mesh_light_client_get_state(struct bt_mesh_common_param *common, void *ge
*
* @return Zero-success, other-fail
*/
int bt_mesh_light_client_set_state(struct bt_mesh_common_param *common, void *set, void *status);
int bt_mesh_light_client_set_state(bt_mesh_client_common_param_t *common, void *set, void *status);
#endif /* _LIGHTING_CLIENT_H_ */

View File

@ -22,7 +22,7 @@
#include "mesh_access.h"
#include "mesh_kernel.h"
#include "model_common.h"
#include "client_common.h"
/* Sensor Client Model Context */
extern const struct bt_mesh_model_op sensor_cli_op[];
@ -41,8 +41,8 @@ extern const struct bt_mesh_model_op sensor_cli_op[];
BLE_MESH_MODEL(BLE_MESH_MODEL_ID_SENSOR_CLI, \
sensor_cli_op, cli_pub, cli_data)
typedef bt_mesh_client_common_t bt_mesh_sensor_client_t;
typedef bt_mesh_internal_data_t sensor_internal_data_t;
typedef bt_mesh_client_user_data_t bt_mesh_sensor_client_t;
typedef bt_mesh_client_internal_data_t sensor_internal_data_t;
struct bt_mesh_sensor_descriptor_status {
struct net_buf_simple *descriptor; /* Sequence of 8-octet sensor descriptors (optional) */
@ -151,7 +151,7 @@ int bt_mesh_sensor_cli_init(struct bt_mesh_model *model, bool primary);
*
* @return Zero-success, other-fail
*/
int bt_mesh_sensor_client_get_state(struct bt_mesh_common_param *common, void *get, void *status);
int bt_mesh_sensor_client_get_state(bt_mesh_client_common_param_t *common, void *get, void *status);
/**
* @brief This function is called to set sensor states.
@ -162,6 +162,6 @@ int bt_mesh_sensor_client_get_state(struct bt_mesh_common_param *common, void *g
*
* @return Zero-success, other-fail
*/
int bt_mesh_sensor_client_set_state(struct bt_mesh_common_param *common, void *set, void *status);
int bt_mesh_sensor_client_set_state(bt_mesh_client_common_param_t *common, void *set, void *status);
#endif /* _SENSOR_CLIENT_H_ */

View File

@ -22,11 +22,11 @@
#include "mesh_access.h"
#include "mesh_kernel.h"
#include "model_common.h"
#include "client_common.h"
/* Time scene client model common structure */
typedef bt_mesh_client_common_t bt_mesh_time_scene_client_t;
typedef bt_mesh_internal_data_t time_scene_internal_data_t;
typedef bt_mesh_client_user_data_t bt_mesh_time_scene_client_t;
typedef bt_mesh_client_internal_data_t time_scene_internal_data_t;
/* Time Client Model Context */
extern const struct bt_mesh_model_op time_cli_op[];
@ -45,7 +45,7 @@ extern const struct bt_mesh_model_op time_cli_op[];
BLE_MESH_MODEL(BLE_MESH_MODEL_ID_TIME_CLI, \
time_cli_op, cli_pub, cli_data)
typedef bt_mesh_client_common_t bt_mesh_time_cli_t;
typedef bt_mesh_client_user_data_t bt_mesh_time_client_t;
struct bt_mesh_time_status {
u8_t tai_seconds[5]; /* The current TAI time in seconds */
@ -115,7 +115,7 @@ extern const struct bt_mesh_model_op scene_cli_op[];
BLE_MESH_MODEL(BLE_MESH_MODEL_ID_SCENE_CLI, \
scene_cli_op, cli_pub, cli_data)
typedef bt_mesh_client_common_t bt_mesh_scene_cli_t;
typedef bt_mesh_client_user_data_t bt_mesh_scene_client_t;
struct bt_mesh_scene_status {
bool op_en; /* Indicate whether optional parameters included */
@ -164,7 +164,7 @@ extern const struct bt_mesh_model_op scheduler_cli_op[];
BLE_MESH_MODEL(BLE_MESH_MODEL_ID_SCHEDULER_CLI, \
scheduler_cli_op, cli_pub, cli_data)
typedef bt_mesh_client_common_t bt_mesh_scheduler_cli_t;
typedef bt_mesh_client_user_data_t bt_mesh_scheduler_client_t;
struct bt_mesh_scheduler_status {
u16_t schedules; /* Bit field indicating defined Actions in the Schedule Register */
@ -241,7 +241,7 @@ int bt_mesh_scheduler_cli_init(struct bt_mesh_model *model, bool primary);
*
* @return Zero-success, other-fail
*/
int bt_mesh_time_scene_client_get_state(struct bt_mesh_common_param *common, void *get, void *status);
int bt_mesh_time_scene_client_get_state(bt_mesh_client_common_param_t *common, void *get, void *status);
/**
* @brief This function is called to set scene states.
@ -252,6 +252,6 @@ int bt_mesh_time_scene_client_get_state(struct bt_mesh_common_param *common, voi
*
* @return Zero-success, other-fail
*/
int bt_mesh_time_scene_client_set_state(struct bt_mesh_common_param *common, void *set, void *status);
int bt_mesh_time_scene_client_set_state(bt_mesh_client_common_param_t *common, void *set, void *status);
#endif /* _TIME_SCENE_CLIENT_H_ */

View File

@ -17,6 +17,7 @@
#include <stdbool.h>
#include "osi/allocator.h"
#include "osi/mutex.h"
#include "sdkconfig.h"
#include "mesh_types.h"
@ -128,36 +129,50 @@ static const bt_mesh_client_op_pair_t light_op_pair[] = {
{ BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET, BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_STATUS },
};
static osi_mutex_t light_client_mutex;
static void bt_mesh_light_client_mutex_new(void)
{
static bool init;
if (!init) {
osi_mutex_new(&light_client_mutex);
init = true;
}
}
static void bt_mesh_light_client_lock(void)
{
osi_mutex_lock(&light_client_mutex, OSI_MUTEX_MAX_TIMEOUT);
}
static void bt_mesh_light_client_unlock(void)
{
osi_mutex_unlock(&light_client_mutex);
}
static void timeout_handler(struct k_work *work)
{
light_internal_data_t *internal = NULL;
bt_mesh_light_client_t *client = NULL;
struct k_delayed_work *timer = NULL;
bt_mesh_client_node_t *node = NULL;
BT_WARN("Receive light status message timeout");
node = CONTAINER_OF(work, bt_mesh_client_node_t, timer.work);
if (!node || !node->ctx.model) {
BT_ERR("%s, Invalid parameter", __func__);
return;
bt_mesh_light_client_lock();
timer = CONTAINER_OF(work, struct k_delayed_work, work);
if (timer && !k_delayed_work_free(timer)) {
node = CONTAINER_OF(work, bt_mesh_client_node_t, timer.work);
if (node) {
bt_mesh_lighting_client_cb_evt_to_btc(node->opcode,
BTC_BLE_MESH_EVT_LIGHTING_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0);
// Don't forget to release the node at the end.
bt_mesh_client_free_node(node);
}
}
client = (bt_mesh_light_client_t *)node->ctx.model->user_data;
if (!client) {
BT_ERR("%s, Lighting Client user_data is NULL", __func__);
return;
}
internal = (light_internal_data_t *)client->internal_data;
if (!internal) {
BT_ERR("%s, Lighting Client internal_data is NULL", __func__);
return;
}
bt_mesh_callback_light_status_to_btc(node->opcode, 0x03, node->ctx.model,
&node->ctx, NULL, 0);
bt_mesh_client_free_node(&internal->queue, node);
bt_mesh_light_client_unlock();
return;
}
@ -166,31 +181,14 @@ static void light_status(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
light_internal_data_t *internal = NULL;
bt_mesh_light_client_t *client = NULL;
bt_mesh_client_node_t *node = NULL;
u8_t *val = NULL;
u8_t evt = 0xFF;
u32_t rsp = 0;
u8_t *val = NULL;
u8_t evt = 0xFF;
size_t len = 0;
BT_DBG("%s, len %d, bytes %s", __func__, buf->len, bt_hex(buf->data, buf->len));
client = (bt_mesh_light_client_t *)model->user_data;
if (!client) {
BT_ERR("%s, Lighting Client user_data is NULL", __func__);
return;
}
internal = (light_internal_data_t *)client->internal_data;
if (!internal) {
BT_ERR("%s, Lighting Client internal_data is NULL", __func__);
return;
}
rsp = ctx->recv_op;
switch (rsp) {
switch (ctx->recv_op) {
case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_STATUS: {
struct bt_mesh_light_lightness_status *status = NULL;
if (buf->len != 2 && buf->len != 5) {
@ -650,9 +648,12 @@ static void light_status(struct bt_mesh_model *model,
buf->data = val;
buf->len = len;
node = bt_mesh_is_model_message_publish(model, ctx, buf, true);
bt_mesh_light_client_lock();
node = bt_mesh_is_client_recv_publish_msg(model, ctx, buf, true);
if (!node) {
BT_DBG("Unexpected light status message 0x%x", rsp);
BT_DBG("Unexpected light status message 0x%x", ctx->recv_op);
} else {
switch (node->opcode) {
case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_GET:
@ -678,7 +679,7 @@ static void light_status(struct bt_mesh_model *model,
case BLE_MESH_MODEL_OP_LIGHT_LC_OM_GET:
case BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_GET:
case BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_GET:
evt = 0x00;
evt = BTC_BLE_MESH_EVT_LIGHTING_CLIENT_GET_STATE;
break;
case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_SET:
case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_SET:
@ -700,18 +701,22 @@ static void light_status(struct bt_mesh_model *model,
case BLE_MESH_MODEL_OP_LIGHT_LC_OM_SET:
case BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_SET:
case BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET:
evt = 0x01;
evt = BTC_BLE_MESH_EVT_LIGHTING_CLIENT_SET_STATE;
break;
default:
break;
}
bt_mesh_callback_light_status_to_btc(node->opcode, evt, model, ctx, val, len);
// Don't forget to release the node at the end.
bt_mesh_client_free_node(&internal->queue, node);
if (!k_delayed_work_free(&node->timer)) {
bt_mesh_lighting_client_cb_evt_to_btc(node->opcode, evt, model, ctx, val, len);
// Don't forget to release the node at the end.
bt_mesh_client_free_node(node);
}
}
switch (rsp) {
bt_mesh_light_client_unlock();
switch (ctx->recv_op) {
case BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_STATUS: {
struct bt_mesh_light_lc_property_status *status;
status = (struct bt_mesh_light_lc_property_status *)val;
@ -770,7 +775,7 @@ const struct bt_mesh_model_op light_lc_cli_op[] = {
BLE_MESH_MODEL_OP_END,
};
static int light_get_state(struct bt_mesh_common_param *common, void *value)
static int light_get_state(bt_mesh_client_common_param_t *common, void *value)
{
NET_BUF_SIMPLE_DEFINE(msg, BLE_MESH_LIGHT_GET_STATE_MSG_LEN);
int err;
@ -801,7 +806,7 @@ static int light_get_state(struct bt_mesh_common_param *common, void *value)
return err;
}
static int light_set_state(struct bt_mesh_common_param *common,
static int light_set_state(bt_mesh_client_common_param_t *common,
void *value, u16_t value_len, bool need_ack)
{
struct net_buf_simple *msg = NULL;
@ -1042,7 +1047,7 @@ end:
return err;
}
int bt_mesh_light_client_get_state(struct bt_mesh_common_param *common, void *get, void *status)
int bt_mesh_light_client_get_state(bt_mesh_client_common_param_t *common, void *get, void *status)
{
bt_mesh_light_client_t *client = NULL;
@ -1095,7 +1100,7 @@ int bt_mesh_light_client_get_state(struct bt_mesh_common_param *common, void *ge
return light_get_state(common, get);
}
int bt_mesh_light_client_set_state(struct bt_mesh_common_param *common, void *set, void *status)
int bt_mesh_light_client_set_state(bt_mesh_client_common_param_t *common, void *set, void *status)
{
bt_mesh_light_client_t *client = NULL;
u16_t length = 0;
@ -1371,6 +1376,8 @@ static int light_client_init(struct bt_mesh_model *model, bool primary)
client->op_pair = light_op_pair;
client->internal_data = internal;
bt_mesh_light_client_mutex_new();
return 0;
}

View File

@ -17,6 +17,7 @@
#include <stdbool.h>
#include "osi/allocator.h"
#include "osi/mutex.h"
#include "sdkconfig.h"
#include "mesh_types.h"
@ -57,36 +58,50 @@ static const bt_mesh_client_op_pair_t sensor_op_pair[] = {
{ BLE_MESH_MODEL_OP_SENSOR_SERIES_GET, BLE_MESH_MODEL_OP_SENSOR_SERIES_STATUS },
};
static osi_mutex_t sensor_client_mutex;
static void bt_mesh_sensor_client_mutex_new(void)
{
static bool init;
if (!init) {
osi_mutex_new(&sensor_client_mutex);
init = true;
}
}
static void bt_mesh_sensor_client_lock(void)
{
osi_mutex_lock(&sensor_client_mutex, OSI_MUTEX_MAX_TIMEOUT);
}
static void bt_mesh_sensor_client_unlock(void)
{
osi_mutex_unlock(&sensor_client_mutex);
}
static void timeout_handler(struct k_work *work)
{
sensor_internal_data_t *internal = NULL;
bt_mesh_sensor_client_t *client = NULL;
struct k_delayed_work *timer = NULL;
bt_mesh_client_node_t *node = NULL;
BT_WARN("Receive sensor status message timeout");
node = CONTAINER_OF(work, bt_mesh_client_node_t, timer.work);
if (!node || !node->ctx.model) {
BT_ERR("%s, Invalid parameter", __func__);
return;
bt_mesh_sensor_client_lock();
timer = CONTAINER_OF(work, struct k_delayed_work, work);
if (timer && !k_delayed_work_free(timer)) {
node = CONTAINER_OF(work, bt_mesh_client_node_t, timer.work);
if (node) {
bt_mesh_sensor_client_cb_evt_to_btc(node->opcode,
BTC_BLE_MESH_EVT_SENSOR_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0);
// Don't forget to release the node at the end.
bt_mesh_client_free_node(node);
}
}
client = (bt_mesh_sensor_client_t *)node->ctx.model->user_data;
if (!client) {
BT_ERR("%s, Sensor Client user_data is NULL", __func__);
return;
}
internal = (sensor_internal_data_t *)client->internal_data;
if (!internal) {
BT_ERR("%s, Sensor Client internal_data is NULL", __func__);
return;
}
bt_mesh_callback_sensor_status_to_btc(node->opcode, 0x03, node->ctx.model,
&node->ctx, NULL, 0);
bt_mesh_client_free_node(&internal->queue, node);
bt_mesh_sensor_client_unlock();
return;
}
@ -95,30 +110,14 @@ static void sensor_status(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
sensor_internal_data_t *internal = NULL;
bt_mesh_sensor_client_t *client = NULL;
bt_mesh_client_node_t *node = NULL;
u8_t *val = NULL;
u8_t evt = 0xFF;
u32_t rsp = 0;
u8_t *val = NULL;
u8_t evt = 0xFF;
size_t len = 0;
BT_DBG("%s, len %d, bytes %s", __func__, buf->len, bt_hex(buf->data, buf->len));
client = (bt_mesh_sensor_client_t *)model->user_data;
if (!client) {
BT_ERR("%s, Sensor Client user_data is NULL", __func__);
return;
}
internal = (sensor_internal_data_t *)client->internal_data;
if (!internal) {
BT_ERR("%s, Sensor Client internal_data is NULL", __func__);
return;
}
rsp = ctx->recv_op;
switch (rsp) {
switch (ctx->recv_op) {
case BLE_MESH_MODEL_OP_SENSOR_DESCRIPTOR_STATUS: {
struct bt_mesh_sensor_descriptor_status *status = NULL;
status = osi_calloc(sizeof(struct bt_mesh_sensor_descriptor_status));
@ -262,9 +261,12 @@ static void sensor_status(struct bt_mesh_model *model,
buf->data = val;
buf->len = len;
node = bt_mesh_is_model_message_publish(model, ctx, buf, true);
bt_mesh_sensor_client_lock();
node = bt_mesh_is_client_recv_publish_msg(model, ctx, buf, true);
if (!node) {
BT_DBG("Unexpected sensor status message 0x%x", rsp);
BT_DBG("Unexpected sensor status message 0x%x", ctx->recv_op);
} else {
switch (node->opcode) {
case BLE_MESH_MODEL_OP_SENSOR_DESCRIPTOR_GET:
@ -274,22 +276,26 @@ static void sensor_status(struct bt_mesh_model *model,
case BLE_MESH_MODEL_OP_SENSOR_GET:
case BLE_MESH_MODEL_OP_SENSOR_COLUMN_GET:
case BLE_MESH_MODEL_OP_SENSOR_SERIES_GET:
evt = 0x00;
evt = BTC_BLE_MESH_EVT_SENSOR_CLIENT_GET_STATE;
break;
case BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET:
case BLE_MESH_MODEL_OP_SENSOR_SETTING_SET:
evt = 0x01;
evt = BTC_BLE_MESH_EVT_SENSOR_CLIENT_SET_STATE;
break;
default:
break;
}
bt_mesh_callback_sensor_status_to_btc(node->opcode, evt, model, ctx, val, len);
// Don't forget to release the node at the end.
bt_mesh_client_free_node(&internal->queue, node);
if (!k_delayed_work_free(&node->timer)) {
bt_mesh_sensor_client_cb_evt_to_btc(node->opcode, evt, model, ctx, val, len);
// Don't forget to release the node at the end.
bt_mesh_client_free_node(node);
}
}
switch (rsp) {
bt_mesh_sensor_client_unlock();
switch (ctx->recv_op) {
case BLE_MESH_MODEL_OP_SENSOR_DESCRIPTOR_STATUS: {
struct bt_mesh_sensor_descriptor_status *status;
status = (struct bt_mesh_sensor_descriptor_status *)val;
@ -352,7 +358,7 @@ const struct bt_mesh_model_op sensor_cli_op[] = {
BLE_MESH_MODEL_OP_END,
};
static int sensor_act_state(struct bt_mesh_common_param *common,
static int sensor_act_state(bt_mesh_client_common_param_t *common,
void *value, u16_t value_len, bool need_ack)
{
struct net_buf_simple *msg = NULL;
@ -460,7 +466,7 @@ end:
return err;
}
int bt_mesh_sensor_client_get_state(struct bt_mesh_common_param *common, void *get, void *status)
int bt_mesh_sensor_client_get_state(bt_mesh_client_common_param_t *common, void *get, void *status)
{
bt_mesh_sensor_client_t *client = NULL;
u16_t length = 0;
@ -525,7 +531,7 @@ int bt_mesh_sensor_client_get_state(struct bt_mesh_common_param *common, void *g
return sensor_act_state(common, get, length, true);
}
int bt_mesh_sensor_client_set_state(struct bt_mesh_common_param *common, void *set, void *status)
int bt_mesh_sensor_client_set_state(bt_mesh_client_common_param_t *common, void *set, void *status)
{
bt_mesh_sensor_client_t *client = NULL;
u16_t length = 0;
@ -612,5 +618,7 @@ int bt_mesh_sensor_cli_init(struct bt_mesh_model *model, bool primary)
client->op_pair = sensor_op_pair;
client->internal_data = internal;
bt_mesh_sensor_client_mutex_new();
return 0;
}

View File

@ -17,6 +17,7 @@
#include <stdbool.h>
#include "osi/allocator.h"
#include "osi/mutex.h"
#include "sdkconfig.h"
#include "mesh_types.h"
@ -73,36 +74,50 @@ static const bt_mesh_client_op_pair_t time_scene_op_pair[] = {
{ BLE_MESH_MODEL_OP_SCHEDULER_ACT_SET, BLE_MESH_MODEL_OP_SCHEDULER_ACT_STATUS },
};
static osi_mutex_t time_scene_client_mutex;
static void bt_mesh_time_scene_client_mutex_new(void)
{
static bool init;
if (!init) {
osi_mutex_new(&time_scene_client_mutex);
init = true;
}
}
static void bt_mesh_time_scene_client_lock(void)
{
osi_mutex_lock(&time_scene_client_mutex, OSI_MUTEX_MAX_TIMEOUT);
}
static void bt_mesh_time_scene_client_unlock(void)
{
osi_mutex_unlock(&time_scene_client_mutex);
}
static void timeout_handler(struct k_work *work)
{
time_scene_internal_data_t *internal = NULL;
bt_mesh_time_scene_client_t *client = NULL;
struct k_delayed_work *timer = NULL;
bt_mesh_client_node_t *node = NULL;
BT_WARN("Receive time scene status message timeout");
node = CONTAINER_OF(work, bt_mesh_client_node_t, timer.work);
if (!node || !node->ctx.model) {
BT_ERR("%s, Invalid parameter", __func__);
return;
bt_mesh_time_scene_client_lock();
timer = CONTAINER_OF(work, struct k_delayed_work, work);
if (timer && !k_delayed_work_free(timer)) {
node = CONTAINER_OF(work, bt_mesh_client_node_t, timer.work);
if (node) {
bt_mesh_time_scene_client_cb_evt_to_btc(node->opcode,
BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0);
// Don't forget to release the node at the end.
bt_mesh_client_free_node(node);
}
}
client = (bt_mesh_time_scene_client_t *)node->ctx.model->user_data;
if (!client) {
BT_ERR("%s, Time Scene Client user_data is NULL", __func__);
return;
}
internal = (time_scene_internal_data_t *)client->internal_data;
if (!internal) {
BT_ERR("%s, Time Scene Client internal_data is NULL", __func__);
return;
}
bt_mesh_callback_time_scene_status_to_btc(node->opcode, 0x03, node->ctx.model,
&node->ctx, NULL, 0);
bt_mesh_client_free_node(&internal->queue, node);
bt_mesh_time_scene_client_unlock();
return;
}
@ -111,30 +126,14 @@ static void time_scene_status(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
time_scene_internal_data_t *internal = NULL;
bt_mesh_time_scene_client_t *client = NULL;
bt_mesh_client_node_t *node = NULL;
u8_t *val = NULL;
u8_t evt = 0xFF;
u32_t rsp = 0;
u8_t *val = NULL;
u8_t evt = 0xFF;
size_t len = 0;
BT_DBG("%s, len %d, bytes %s", __func__, buf->len, bt_hex(buf->data, buf->len));
client = (bt_mesh_time_scene_client_t *)model->user_data;
if (!client) {
BT_ERR("%s, Time Scene Client user_data is NULL", __func__);
return;
}
internal = (time_scene_internal_data_t *)client->internal_data;
if (!internal) {
BT_ERR("%s, Time Scene Client internal_data is NULL", __func__);
return;
}
rsp = ctx->recv_op;
switch (rsp) {
switch (ctx->recv_op) {
case BLE_MESH_MODEL_OP_TIME_STATUS: {
struct bt_mesh_time_status *status = NULL;
if (buf->len != 5 && buf->len != 10) {
@ -299,9 +298,12 @@ static void time_scene_status(struct bt_mesh_model *model,
buf->data = val;
buf->len = len;
node = bt_mesh_is_model_message_publish(model, ctx, buf, true);
bt_mesh_time_scene_client_lock();
node = bt_mesh_is_client_recv_publish_msg(model, ctx, buf, true);
if (!node) {
BT_DBG("Unexpected time scene status message 0x%x", rsp);
BT_DBG("Unexpected time scene status message 0x%x", ctx->recv_op);
} else {
switch (node->opcode) {
case BLE_MESH_MODEL_OP_TIME_GET:
@ -312,7 +314,7 @@ static void time_scene_status(struct bt_mesh_model *model,
case BLE_MESH_MODEL_OP_SCENE_REGISTER_GET:
case BLE_MESH_MODEL_OP_SCHEDULER_GET:
case BLE_MESH_MODEL_OP_SCHEDULER_ACT_GET:
evt = 0x00;
evt = BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_GET_STATE;
break;
case BLE_MESH_MODEL_OP_TIME_SET:
case BLE_MESH_MODEL_OP_TIME_ZONE_SET:
@ -322,18 +324,22 @@ static void time_scene_status(struct bt_mesh_model *model,
case BLE_MESH_MODEL_OP_SCENE_RECALL:
case BLE_MESH_MODEL_OP_SCENE_DELETE:
case BLE_MESH_MODEL_OP_SCHEDULER_ACT_SET:
evt = 0x01;
evt = BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_SET_STATE;
break;
default:
break;
}
bt_mesh_callback_time_scene_status_to_btc(node->opcode, evt, model, ctx, val, len);
// Don't forget to release the node at the end.
bt_mesh_client_free_node(&internal->queue, node);
if (!k_delayed_work_free(&node->timer)) {
bt_mesh_time_scene_client_cb_evt_to_btc(node->opcode, evt, model, ctx, val, len);
// Don't forget to release the node at the end.
bt_mesh_client_free_node(node);
}
}
switch (rsp) {
bt_mesh_time_scene_client_unlock();
switch (ctx->recv_op) {
case BLE_MESH_MODEL_OP_SCENE_REGISTER_STATUS: {
struct bt_mesh_scene_register_status *status;
status = (struct bt_mesh_scene_register_status *)val;
@ -369,7 +375,7 @@ const struct bt_mesh_model_op scheduler_cli_op[] = {
BLE_MESH_MODEL_OP_END,
};
static int time_scene_get_state(struct bt_mesh_common_param *common, void *value)
static int time_scene_get_state(bt_mesh_client_common_param_t *common, void *value)
{
NET_BUF_SIMPLE_DEFINE(msg, BLE_MESH_SCENE_GET_STATE_MSG_LEN);
int err;
@ -400,7 +406,7 @@ static int time_scene_get_state(struct bt_mesh_common_param *common, void *value
return err;
}
static int time_scene_set_state(struct bt_mesh_common_param *common,
static int time_scene_set_state(bt_mesh_client_common_param_t *common,
void *value, u16_t value_len, bool need_ack)
{
struct net_buf_simple *msg = NULL;
@ -497,7 +503,7 @@ end:
return err;
}
int bt_mesh_time_scene_client_get_state(struct bt_mesh_common_param *common, void *get, void *status)
int bt_mesh_time_scene_client_get_state(bt_mesh_client_common_param_t *common, void *get, void *status)
{
bt_mesh_time_scene_client_t *client = NULL;
@ -535,7 +541,7 @@ int bt_mesh_time_scene_client_get_state(struct bt_mesh_common_param *common, voi
return time_scene_get_state(common, get);
}
int bt_mesh_time_scene_client_set_state(struct bt_mesh_common_param *common, void *set, void *status)
int bt_mesh_time_scene_client_set_state(bt_mesh_client_common_param_t *common, void *set, void *status)
{
bt_mesh_time_scene_client_t *client = NULL;
u16_t length = 0;
@ -675,6 +681,8 @@ static int time_scene_client_init(struct bt_mesh_model *model, bool primary)
client->op_pair = time_scene_op_pair;
client->internal_data = internal;
bt_mesh_time_scene_client_mutex_new();
return 0;
}

View File

@ -24,6 +24,7 @@
#include "mesh_types.h"
#include "mesh_buf.h"
#include "mesh_trace.h"
#include "mesh_access.h"
/**
* @brief This function allocates memory to store outgoing message.
@ -43,4 +44,18 @@ struct net_buf_simple *bt_mesh_alloc_buf(u16_t size);
*/
void bt_mesh_free_buf(struct net_buf_simple *buf);
/**
* @brief This function gets device role for stack internal use.
*
* @Note Currently Provisioner only support client models, Node supports
* client models and server models. Hence if srv_send is set to be
* TRUE, then role NODE will be returned.
*
* @param[in] model: Pointer to the model structure
* @param[in] srv_send: Indicate if the message is sent by a server model
*
* @return 0 - Node, 1 - Provisioner
*/
u8_t bt_mesh_get_device_role(struct bt_mesh_model *model, bool srv_send);
#endif /* _MESH_COMMON_H_ */

View File

@ -15,6 +15,7 @@
#include <string.h>
#include <errno.h>
#include "client_common.h"
#include "mesh_common.h"
struct net_buf_simple *bt_mesh_alloc_buf(u16_t size)
@ -44,3 +45,22 @@ void bt_mesh_free_buf(struct net_buf_simple *buf)
osi_free(buf);
}
}
u8_t bt_mesh_get_device_role(struct bt_mesh_model *model, bool srv_send)
{
bt_mesh_client_user_data_t *client = NULL;
if (srv_send) {
BT_DBG("%s, Message is sent by a server model", __func__);
return NODE;
}
if (!model || !model->user_data) {
BT_ERR("%s, Invalid parameter", __func__);
return ROLE_NVAL;
}
client = (bt_mesh_client_user_data_t *)model->user_data;
return client->msg_role;
}

View File

@ -54,16 +54,6 @@ config BT_A2DP_ENABLE
help
Advanced Audio Distrubution Profile
config BT_A2DP_SINK_TASK_STACK_SIZE
int "A2DP sink (audio stream decoding) task stack size"
depends on BT_A2DP_ENABLE
default 2048
config BT_A2DP_SOURCE_TASK_STACK_SIZE
int "A2DP source (audio stream encoding) task stack size"
depends on BT_A2DP_ENABLE
default 2048
config BT_SPP_ENABLED
bool "SPP"
depends on BT_CLASSIC_ENABLED
@ -98,6 +88,14 @@ choice BT_HFP_AUDIO_DATA_PATH
bool "HCI"
endchoice
config BT_HFP_WBS_ENABLE
bool "Wide Band Speech"
depends on BT_HFP_AUDIO_DATA_PATH_HCI
default y
help
This enables Wide Band Speech. Should disable it when SCO data path is PCM.
Otherwise there will be no data transmited via GPIOs.
config BT_SSP_ENABLED
bool "Secure Simple Pairing"
depends on BT_CLASSIC_ENABLED

View File

@ -267,14 +267,25 @@ typedef enum {
typedef enum {
ESP_BLE_SM_PASSKEY = 0,
/* Authentication requirements of local device */
ESP_BLE_SM_AUTHEN_REQ_MODE,
/* The IO capability of local device */
ESP_BLE_SM_IOCAP_MODE,
/* Initiator Key Distribution/Generation */
ESP_BLE_SM_SET_INIT_KEY,
/* Responder Key Distribution/Generation */
ESP_BLE_SM_SET_RSP_KEY,
/* Maximum Encryption key size to support */
ESP_BLE_SM_MAX_KEY_SIZE,
/* Minimum Encryption key size requirement from Peer */
ESP_BLE_SM_MIN_KEY_SIZE,
/* Set static Passkey */
ESP_BLE_SM_SET_STATIC_PASSKEY,
/* Reset static Passkey */
ESP_BLE_SM_CLEAR_STATIC_PASSKEY,
/* Accept only specified SMP Authentication requirement */
ESP_BLE_SM_ONLY_ACCEPT_SPECIFIED_SEC_AUTH,
/* Enable/Disable OOB support */
ESP_BLE_SM_OOB_SUPPORT,
ESP_BLE_SM_MAX_PARAM,
} esp_ble_sm_param_t;
@ -377,7 +388,7 @@ typedef struct {
advertising reports for each packet received */
} esp_ble_scan_params_t;
/// connection parameters information
/// connection parameters information
typedef struct {
uint16_t interval; /*!< connection interval */
uint16_t latency; /*!< Slave latency for the connection in number of connection events. Range: 0x0000 to 0x01F3 */
@ -598,7 +609,7 @@ typedef enum {
typedef enum {
ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_INFO_ADV_ADDR = 0, /*!< BLE advertising address , device info will be added into ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_ADDR_LIST */
ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_INFO_MESH_LINK_ID, /*!< BLE mesh link ID, it is for BLE mesh, device info will be added into ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_MESH_LINK_ID_LIST */
ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_INFO_MESH_BEACON_TYPE, /*!< BLE mesh beacon AD type, the format is | Len | 0x2B | Beacon Type | Beacon Data | */
ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_INFO_MESH_BEACON_TYPE, /*!< BLE mesh beacon AD type, the format is | Len | 0x2B | Beacon Type | Beacon Data | */
ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_INFO_MESH_PROV_SRV_ADV, /*!< BLE mesh provisioning service uuid, the format is | 0x02 | 0x01 | flags | 0x03 | 0x03 | 0x1827 | .... |` */
ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_INFO_MESH_PROXY_SRV_ADV, /*!< BLE mesh adv with proxy service uuid, the format is | 0x02 | 0x01 | flags | 0x03 | 0x03 | 0x1828 | .... |` */
} esp_ble_duplicate_exceptional_info_type_t;

View File

@ -326,7 +326,7 @@ typedef void (* esp_bt_gap_cb_t)(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_para
* @param[in] cod: Class of Device
* @return major service bits
*/
inline uint32_t esp_bt_gap_get_cod_srvc(uint32_t cod)
static inline uint32_t esp_bt_gap_get_cod_srvc(uint32_t cod)
{
return (cod & ESP_BT_COD_SRVC_BIT_MASK) >> ESP_BT_COD_SRVC_BIT_OFFSET;
}
@ -336,7 +336,7 @@ inline uint32_t esp_bt_gap_get_cod_srvc(uint32_t cod)
* @param[in] cod: Class of Device
* @return major device bits
*/
inline uint32_t esp_bt_gap_get_cod_major_dev(uint32_t cod)
static inline uint32_t esp_bt_gap_get_cod_major_dev(uint32_t cod)
{
return (cod & ESP_BT_COD_MAJOR_DEV_BIT_MASK) >> ESP_BT_COD_MAJOR_DEV_BIT_OFFSET;
}
@ -346,7 +346,7 @@ inline uint32_t esp_bt_gap_get_cod_major_dev(uint32_t cod)
* @param[in] cod: Class of Device
* @return minor service bits
*/
inline uint32_t esp_bt_gap_get_cod_minor_dev(uint32_t cod)
static inline uint32_t esp_bt_gap_get_cod_minor_dev(uint32_t cod)
{
return (cod & ESP_BT_COD_MINOR_DEV_BIT_MASK) >> ESP_BT_COD_MINOR_DEV_BIT_OFFSET;
}
@ -356,7 +356,7 @@ inline uint32_t esp_bt_gap_get_cod_minor_dev(uint32_t cod)
* @param[in] cod: Class of Device
* @return format type
*/
inline uint32_t esp_bt_gap_get_cod_format_type(uint32_t cod)
static inline uint32_t esp_bt_gap_get_cod_format_type(uint32_t cod)
{
return (cod & ESP_BT_COD_FORMAT_TYPE_BIT_MASK);
}
@ -368,7 +368,7 @@ inline uint32_t esp_bt_gap_get_cod_format_type(uint32_t cod)
* - true if cod is valid
* - false otherise
*/
inline bool esp_bt_gap_is_valid_cod(uint32_t cod)
static inline bool esp_bt_gap_is_valid_cod(uint32_t cod)
{
if (esp_bt_gap_get_cod_format_type(cod) == ESP_BT_COD_FORMAT_TYPE_1 &&
esp_bt_gap_get_cod_srvc(cod) != ESP_BT_COD_SRVC_NONE) {

View File

@ -48,6 +48,7 @@ tBTE_APPL_CFG bte_appl_cfg = {
BTM_BLE_INITIATOR_KEY_SIZE,
BTM_BLE_RESPONDER_KEY_SIZE,
BTM_BLE_MAX_KEY_SIZE,
BTM_BLE_MIN_KEY_SIZE,
BTM_BLE_ONLY_ACCEPT_SPECIFIED_SEC_AUTH_DISABLE,
BTM_BLE_OOB_DISABLE,
};
@ -407,7 +408,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 >= BTM_BLE_MIN_KEY_SIZE && ble_key_size <= BTM_BLE_MAX_KEY_SIZE) {
if(ble_key_size >= bte_appl_cfg.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);
@ -415,6 +416,17 @@ void bta_dm_co_ble_set_max_key_size(UINT8 ble_key_size)
#endif ///SMP_INCLUDED == TRUE
}
void bta_dm_co_ble_set_min_key_size(UINT8 ble_key_size)
{
#if (SMP_INCLUDED == TRUE)
if(ble_key_size >= BTM_BLE_MIN_KEY_SIZE && ble_key_size <= bte_appl_cfg.ble_max_key_size) {
bte_appl_cfg.ble_min_key_size = ble_key_size;
} else {
APPL_TRACE_ERROR("%s error:Invalid key size value, key_size =%d",__func__, ble_key_size);
}
#endif ///SMP_INCLUDED == TRUE
}
void bta_dm_co_ble_set_accept_auth_enable(UINT8 enable)
{
#if (SMP_INCLUDED == TRUE)

View File

@ -232,7 +232,11 @@ const tBTA_HF_CLIENT_ST_TBL bta_hf_client_st_tbl[] = {
bta_hf_client_st_closing
};
#if BTM_WBS_INCLUDED
const char *bta_hf_client_version = "1.6";
#else
const char *bta_hf_client_version = "1.5";
#endif
/* HF Client control block */
#if BTA_DYNAMIC_MEMORY == FALSE

View File

@ -206,6 +206,8 @@ extern void bta_dm_co_ble_set_rsp_key_req(UINT8 rsp_key);
extern void bta_dm_co_ble_set_max_key_size(UINT8 ble_key_size);
extern void bta_dm_co_ble_set_min_key_size(UINT8 ble_key_size);
extern void bta_dm_co_ble_set_accept_auth_enable(UINT8 enable);
extern UINT8 bta_dm_co_ble_get_accept_auth_enable(void);

View File

@ -117,7 +117,7 @@ void btc_a2dp_control_media_ctrl(esp_a2d_media_ctrl_t ctrl)
APPL_TRACE_DEBUG("BTC MEDIA (A2DP-DATA) EVENT %u", ctrl);
if (btc_aa_ctrl_cb.a2dp_cmd_pending != ESP_A2D_MEDIA_CTRL_NONE) {
APPL_TRACE_DEBUG("un-acked a2dp cmd: %u", btc_aa_ctrl_cb.a2dp_cmd_pending);
APPL_TRACE_WARNING("un-acked a2dp cmd: %u", btc_aa_ctrl_cb.a2dp_cmd_pending);
a2dp_cmd_acknowledge(ctrl, ESP_A2D_MEDIA_CTRL_ACK_BUSY);
return;
}
@ -179,6 +179,11 @@ void btc_a2dp_control_media_ctrl(esp_a2d_media_ctrl_t ctrl)
/* local suspend */
if (btc_av_stream_started_ready()) {
btc_dispatch_sm_event(BTC_AV_SUSPEND_STREAM_REQ_EVT, NULL, 0);
#if (BTC_AV_SINK_INCLUDED == TRUE)
if (btc_av_get_peer_sep() == AVDT_TSEP_SRC && btc_av_get_service_id() == BTA_A2DP_SINK_SERVICE_ID) {
btc_a2dp_control_command_ack(ESP_A2D_MEDIA_CTRL_ACK_SUCCESS);
}
#endif
} else {
/* we are not in started state; just ack back ok. This can happen if we are
remotely suspended; clear REMOTE SUSPEND Flag */

View File

@ -1196,6 +1196,12 @@ void btc_gap_ble_call_handler(btc_msg_t *msg)
bta_dm_co_ble_set_max_key_size(key_size);
break;
}
case ESP_BLE_SM_MIN_KEY_SIZE: {
uint8_t key_size = 0;
STREAM_TO_UINT8(key_size, value);
bta_dm_co_ble_set_min_key_size(key_size);
break;
}
case ESP_BLE_SM_SET_STATIC_PASSKEY: {
uint32_t passkey = 0;
for(uint8_t i = 0; i < arg->set_security_param.len; i++)

View File

@ -22,17 +22,12 @@
/**********************************************************
* Thread/Task reference
**********************************************************/
#ifdef CONFIG_BTU_TASK_STACK_SIZE
#define UC_BTU_TASK_STACK_SIZE CONFIG_BTU_TASK_STACK_SIZE
#else
#define UC_BTU_TASK_STACK_SIZE 4096
#endif
#ifdef CONFIG_A2DP_SINK_TASK_STACK_SIZE
#define UC_A2DP_SINK_TASK_STACK_SIZE CONFIG_A2DP_SINK_TASK_STACK_SIZE
#else
#define UC_A2DP_SINK_TASK_STACK_SIZE 2048
#endif
#ifdef CONFIG_A2DP_SOURCE_TASK_STACK_SIZE
#define UC_A2DP_SOURCE_TASK_STACK_SIZE CONFIG_A2DP_SOURCE_TASK_STACK_SIZE
#else
#define UC_A2DP_SOURCE_TASK_STACK_SIZE 2048
#endif
/**********************************************************
* Profile reference
@ -176,6 +171,12 @@
#define UC_BT_HFP_AUDIO_DATA_PATH_HCI FALSE
#endif
//Wide Band Speech
#ifdef CONFIG_BT_HFP_WBS_ENABLE
#define UC_BT_HFP_WBS_ENABLE CONFIG_BT_HFP_WBS_ENABLE
#else
#define UC_BT_HFP_WBS_ENABLE FALSE
#endif
/**********************************************************
* Memory reference

View File

@ -21,6 +21,7 @@
#include <stdlib.h>
#include <stdint.h>
#include <arpa/inet.h>
#include "bt_common.h"
#include "common/bt_target.h"
@ -69,62 +70,4 @@ typedef struct {
#define CPU_LITTLE_ENDIAN
#endif
inline uint16_t swap_byte_16(uint16_t x)
{
return (((x & 0x00ffU) << 8) |
((x & 0xff00U) >> 8));
}
inline uint32_t swap_byte_32(uint32_t x)
{
return (((x & 0x000000ffUL) << 24) |
((x & 0x0000ff00UL) << 8) |
((x & 0x00ff0000UL) >> 8) |
((x & 0xff000000UL) >> 24));
}
#ifndef ntohs
inline uint16_t ntohs(uint16_t x)
{
#ifdef CPU_LITTLE_ENDIAN
return swap_byte_16(x);
#else
return x;
#endif
}
#endif /* #ifndef ntohs */
#ifndef htons
inline uint16_t htons(uint16_t x)
{
#ifdef CPU_LITTLE_ENDIAN
return swap_byte_16(x);
#else
return x;
#endif
}
#endif /* #ifndef htons */
#ifndef ntohl
inline uint32_t ntohl(uint32_t x)
{
#ifdef CPU_LITTLE_ENDIAN
return swap_byte_32(x);
#else
return x;
#endif
}
#endif /* #ifndef ntohl*/
#ifndef htonl
inline uint32_t htonl(uint32_t x)
{
#ifdef CPU_LITTLE_ENDIAN
return swap_byte_32(x);
#else
return x;
#endif
}
#endif /* #ifndef htonl*/
#endif /* _BT_DEFS_H_ */

View File

@ -43,8 +43,7 @@
/* OS Configuration from User config (eg: sdkconfig) */
#define A2DP_SINK_TASK_STACK_SIZE UC_A2DP_SINK_TASK_STACK_SIZE
#define A2DP_SOURCE_TASK_STACK_SIZE UC_A2DP_SOURCE_TASK_STACK_SIZE
#define BT_BTU_TASK_STACK_SIZE UC_BTU_TASK_STACK_SIZE
/******************************************************************************
**
@ -592,7 +591,7 @@
/* Includes WBS if TRUE */
#ifndef BTM_WBS_INCLUDED
#define BTM_WBS_INCLUDED FALSE /* TRUE includes WBS code */
#define BTM_WBS_INCLUDED UC_BT_HFP_WBS_ENABLE /* TRUE includes WBS code */
#endif
/* This is used to work around a controller bug that doesn't like Disconnect

View File

@ -25,7 +25,7 @@
#include "stack/bt_types.h"
#include "bt_common.h"
inline void trc_dump_buffer(const char *prefix, uint8_t *data, uint16_t len)
static inline void trc_dump_buffer(const char *prefix, uint8_t *data, uint16_t len)
{
uint16_t i;

View File

@ -31,6 +31,7 @@ typedef struct {
UINT8 ble_init_key;
UINT8 ble_resp_key;
UINT8 ble_max_key_size;
UINT8 ble_min_key_size;
UINT8 ble_accept_auth_enable;
UINT8 oob_support;
#endif
@ -48,4 +49,4 @@ typedef struct {
#endif
} tBTE_BT_APPL_CFG;
extern tBTE_BT_APPL_CFG bte_bt_appl_cfg;
extern tBTE_BT_APPL_CFG bte_bt_appl_cfg;

View File

@ -143,11 +143,11 @@ OI_INT adjustToFitBitpool(const OI_UINT bitpool,
OI_UINT bitcount,
OI_UINT *excess);
INLINE OI_INT allocAdjustedBits(OI_UINT8 *dest,
OI_INT allocAdjustedBits(OI_UINT8 *dest,
OI_INT bits,
OI_INT excess);
INLINE OI_INT allocExcessBits(OI_UINT8 *dest,
OI_INT allocExcessBits(OI_UINT8 *dest,
OI_INT excess);
PRIVATE OI_UINT32 internal_CalculateBitrate(OI_CODEC_SBC_FRAME_INFO *frame);
@ -165,7 +165,7 @@ PRIVATE OI_STATUS internal_DecodeRaw(OI_CODEC_SBC_DECODER_CONTEXT *context,
OI_INT16 *pcmData,
OI_UINT32 *pcmBytes);
INLINE OI_STATUS internal_DecoderReset(OI_CODEC_SBC_DECODER_CONTEXT *context,
OI_STATUS internal_DecoderReset(OI_CODEC_SBC_DECODER_CONTEXT *context,
OI_UINT32 *decoderData,
OI_UINT32 decoderDataBytes,
OI_BYTE maxChannels,
@ -173,7 +173,7 @@ INLINE OI_STATUS internal_DecoderReset(OI_CODEC_SBC_DECODER_CONTEXT *context,
OI_BOOL enhanced,
OI_BOOL msbc_enable);
INLINE OI_UINT16 OI_SBC_CalculateFrameAndHeaderlen(OI_CODEC_SBC_FRAME_INFO *frame, OI_UINT *headerLen_);
OI_UINT16 OI_SBC_CalculateFrameAndHeaderlen(OI_CODEC_SBC_FRAME_INFO *frame, OI_UINT *headerLen_);
PRIVATE OI_UINT32 OI_SBC_MaxBitpool(OI_CODEC_SBC_FRAME_INFO *frame);
@ -185,13 +185,13 @@ PRIVATE void shift_buffer(SBC_BUFFER_T *dest, SBC_BUFFER_T *src, OI_UINT wordCou
PRIVATE void cosineModulateSynth4(SBC_BUFFER_T *RESTRICT out, OI_INT32 const *RESTRICT in);
PRIVATE void SynthWindow40_int32_int32_symmetry_with_sum(OI_INT16 *pcm, SBC_BUFFER_T buffer[80], OI_UINT strideShift);
INLINE void dct3_4(OI_INT32 *RESTRICT out, OI_INT32 const *RESTRICT in);
void dct3_4(OI_INT32 *RESTRICT out, OI_INT32 const *RESTRICT in);
PRIVATE void analyze4_generated(SBC_BUFFER_T analysisBuffer[RESTRICT 40],
OI_INT16 *pcm,
OI_UINT strideShift,
OI_INT32 subband[4]);
INLINE void dct3_8(OI_INT32 *RESTRICT out, OI_INT32 const *RESTRICT in);
void dct3_8(OI_INT32 *RESTRICT out, OI_INT32 const *RESTRICT in);
PRIVATE void analyze8_generated(SBC_BUFFER_T analysisBuffer[RESTRICT 80],
OI_INT16 *pcm,
@ -207,12 +207,12 @@ PRIVATE void analyze8_enhanced_generated(SBC_BUFFER_T analysisBuffer[RESTRICT 11
/* Decoder functions */
INLINE void OI_SBC_ReadHeader(OI_CODEC_SBC_COMMON_CONTEXT *common, const OI_BYTE *data);
void OI_SBC_ReadHeader(OI_CODEC_SBC_COMMON_CONTEXT *common, const OI_BYTE *data);
PRIVATE void OI_SBC_ReadScalefactors(OI_CODEC_SBC_COMMON_CONTEXT *common, const OI_BYTE *b, OI_BITSTREAM *bs);
PRIVATE void OI_SBC_ReadSamples(OI_CODEC_SBC_DECODER_CONTEXT *common, OI_BITSTREAM *ob);
PRIVATE void OI_SBC_ReadSamplesJoint(OI_CODEC_SBC_DECODER_CONTEXT *common, OI_BITSTREAM *global_bs);
PRIVATE void OI_SBC_SynthFrame(OI_CODEC_SBC_DECODER_CONTEXT *context, OI_INT16 *pcm, OI_UINT start_block, OI_UINT nrof_blocks);
INLINE OI_INT32 OI_SBC_Dequant(OI_UINT32 raw, OI_UINT scale_factor, OI_UINT bits);
OI_INT32 OI_SBC_Dequant(OI_UINT32 raw, OI_UINT scale_factor, OI_UINT bits);
PRIVATE OI_BOOL OI_SBC_ExamineCommandPacket(OI_CODEC_SBC_DECODER_CONTEXT *context, const OI_BYTE *data, OI_UINT32 len);
PRIVATE void OI_SBC_GenerateTestSignal(OI_INT16 pcmData[][2], OI_UINT32 sampleCount);

View File

@ -125,7 +125,7 @@ const OI_UINT32 dequant_long_unscaled[17];
#include <math.h>
INLINE float dequant_float(OI_UINT32 raw, OI_UINT scale_factor, OI_UINT bits)
static INLINE float dequant_float(OI_UINT32 raw, OI_UINT scale_factor, OI_UINT bits)
{
float result = (1 << (scale_factor + 1)) * ((raw * 2.0f + 1.0f) / ((1 << bits) - 1.0f) - 1.0f);

View File

@ -110,7 +110,7 @@ const OI_UINT32 dequant_long_unscaled[17] = {
#endif
#ifdef USE_WIDE_CRC
INLINE OI_CHAR crc_iterate(OI_UINT8 oldcrc, OI_UINT8 next)
static INLINE OI_CHAR crc_iterate(OI_UINT8 oldcrc, OI_UINT8 next)
{
OI_UINT crc;
OI_UINT idx;
@ -125,7 +125,7 @@ INLINE OI_CHAR crc_iterate(OI_UINT8 oldcrc, OI_UINT8 next)
return crc;
}
INLINE OI_CHAR crc_iterate_top4(OI_UINT8 oldcrc, OI_UINT8 next)
static INLINE OI_CHAR crc_iterate_top4(OI_UINT8 oldcrc, OI_UINT8 next)
{
OI_UINT crc;
OI_UINT idx;
@ -142,13 +142,13 @@ INLINE OI_CHAR crc_iterate_top4(OI_UINT8 oldcrc, OI_UINT8 next)
#else // USE_WIDE_CRC
INLINE OI_UINT8 crc_iterate_top4(OI_UINT8 oldcrc, OI_UINT8 next)
static INLINE OI_UINT8 crc_iterate_top4(OI_UINT8 oldcrc, OI_UINT8 next)
{
return (oldcrc << 4) ^ crc8_narrow[(oldcrc ^ next) >> 4];
}
#ifdef USE_NIBBLEWISE_CRC
INLINE OI_UINT8 crc_iterate(OI_UINT8 crc, OI_UINT8 next)
static INLINE OI_UINT8 crc_iterate(OI_UINT8 crc, OI_UINT8 next)
{
crc = (crc << 4) ^ crc8_narrow[(crc ^ next) >> 4];
crc = (crc << 4) ^ crc8_narrow[((crc >> 4)^next) & 0xf];
@ -157,7 +157,7 @@ INLINE OI_UINT8 crc_iterate(OI_UINT8 crc, OI_UINT8 next)
}
#else // USE_NIBBLEWISE_CRC
INLINE OI_UINT8 crc_iterate(OI_UINT8 crc, OI_UINT8 next)
static INLINE OI_UINT8 crc_iterate(OI_UINT8 crc, OI_UINT8 next)
{
return crc8_narrow[crc ^ next];
}

View File

@ -62,7 +62,7 @@
* @return A signed 32-bit value corresponding to the 32 most significant bits
* of the 64-bit product of u and v.
*/
INLINE OI_INT32 default_mul_32s_32s_hi(OI_INT32 u, OI_INT32 v)
static INLINE OI_INT32 default_mul_32s_32s_hi(OI_INT32 u, OI_INT32 v)
{
OI_UINT32 u0, v0;
OI_INT32 u1, v1, w1, w2, t;

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