Merge branch 'master' into feature/esp32s2beta_merge

This commit is contained in:
Angus Gratton 2019-09-16 10:56:48 +10:00 committed by Angus Gratton
commit 438d513a95
361 changed files with 10271 additions and 7062 deletions

4
.gitmodules vendored
View File

@ -79,3 +79,7 @@
path = components/bt/host/nimble/nimble
url = ../../espressif/esp-nimble.git
[submodule "components/cbor/tinycbor"]
path = components/cbor/tinycbor
url = ../../intel/tinycbor.git

View File

@ -29,8 +29,11 @@ if(NOT BOOTLOADER_BUILD)
idf_build_get_property(idf_path IDF_PATH)
idf_build_get_property(python PYTHON)
idf_component_get_property(partition_table_dir partition_table COMPONENT_DIR)
add_custom_command(OUTPUT ${blank_otadata_file}
COMMAND ${python} ${idf_path}/components/partition_table/gen_empty_partition.py
COMMAND ${python} ${partition_table_dir}/gen_empty_partition.py
${otadata_size} ${blank_otadata_file})
add_custom_target(blank_ota_data ALL DEPENDS ${blank_otadata_file})

View File

@ -448,7 +448,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
@ -491,7 +491,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

@ -219,6 +219,53 @@ menu "Bootloader config"
It allow to test anti-rollback implemention without permanent write eFuse bits.
In partition table should be exist this partition `emul_efuse, data, 5, , 0x2000`.
config BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP
bool "Skip image validation when exiting deep sleep"
depends on (SECURE_BOOT_ENABLED && SECURE_BOOT_INSECURE) || !SECURE_BOOT_ENABLED
default n
help
This option disables the normal validation of an image coming out of
deep sleep (checksums, SHA256, and signature). This is a trade-off
between wakeup performance from deep sleep, and image integrity checks.
Only enable this if you know what you are doing. It should not be used
in conjunction with using deep_sleep() entry and changing the active OTA
partition as this would skip the validation upon first load of the new
OTA partition.
config BOOTLOADER_RESERVE_RTC_SIZE
hex
default 0x10 if BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP || BOOTLOADER_CUSTOM_RESERVE_RTC
default 0
help
Reserve RTC FAST memory for Skip image validation. This option in bytes.
This option reserves an area in the RTC FAST memory (access only PRO_CPU).
Used to save the addresses of the selected application.
When a wakeup occurs (from Deep sleep), the bootloader retrieves it and
loads the application without validation.
config BOOTLOADER_CUSTOM_RESERVE_RTC
bool "Reserve RTC FAST memory for custom purposes"
default n
help
This option allows the customer to place data in the RTC FAST memory,
this area remains valid when rebooted, except for power loss.
This memory is located at a fixed address and is available
for both the bootloader and the application.
(The application and bootoloader must be compiled with the same option).
The RTC FAST memory has access only through PRO_CPU.
config BOOTLOADER_CUSTOM_RESERVE_RTC_SIZE
hex "Size in bytes for custom purposes"
range 0 0x10
default 0
depends on BOOTLOADER_CUSTOM_RESERVE_RTC
help
This option reserves in RTC FAST memory the area for custom purposes.
If you want to create your own bootloader and save more information
in this area of memory, you can increase it. It must be a multiple of 4 bytes.
This area (rtc_retain_mem_t) is reserved and has access from the bootloader and an application.
endmenu # Bootloader
@ -234,12 +281,15 @@ menu "Security features"
config SECURE_SIGNED_ON_UPDATE
bool
default y
select MBEDTLS_ECP_DP_SECP256R1_ENABLED
depends on SECURE_BOOT_ENABLED || SECURE_SIGNED_ON_UPDATE_NO_SECURE_BOOT
config SECURE_SIGNED_APPS
bool
default y
select MBEDTLS_ECP_DP_SECP256R1_ENABLED
select MBEDTLS_ECP_C
select MBEDTLS_ECDH_C
select MBEDTLS_ECDSA_C
depends on SECURE_SIGNED_ON_BOOT || SECURE_SIGNED_ON_UPDATE
@ -535,6 +585,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

@ -96,12 +96,13 @@ endif()
idf_build_get_property(idf_path IDF_PATH)
idf_build_get_property(idf_target IDF_TARGET)
idf_build_get_property(sdkconfig SDKCONFIG)
idf_build_get_property(python PYTHON)
externalproject_add(bootloader
SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/subproject"
BINARY_DIR "${BOOTLOADER_BUILD_DIR}"
CMAKE_ARGS -DSDKCONFIG=${sdkconfig} -DIDF_PATH=${idf_path} -DIDF_TARGET=${idf_target}
-DPYTHON_DEPS_CHECKED=1
-DPYTHON_DEPS_CHECKED=1 -DPYTHON=${python}
-DEXTRA_COMPONENT_DIRS=${CMAKE_CURRENT_LIST_DIR}
${sign_key_arg} ${ver_key_arg}
# LEGACY_INCLUDE_COMMON_HEADERS has to be passed in via cache variable since

View File

@ -23,9 +23,11 @@
#include "esp_image_format.h"
#if CONFIG_IDF_TARGET_ESP32
#include "esp32/rom/gpio.h"
#include "esp32/rom/rtc.h"
#include "esp32/rom/spi_flash.h"
#elif CONFIG_IDF_TARGET_ESP32S2BETA
#include "esp32s2beta/rom/gpio.h"
#include "esp32s2beta/rom/rtc.h"
#include "esp32s2beta/rom/spi_flash.h"
#endif
@ -45,6 +47,14 @@ void __attribute__((noreturn)) call_start_cpu0(void)
bootloader_reset();
}
#ifdef CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP
// If this boot is a wake up from the deep sleep then go to the short way,
// try to load the application which worked before deep sleep.
// It skips a lot of checks due to it was done before (while first boot).
bootloader_utility_load_boot_image_from_deep_sleep();
// If it is not successful try to load an application as usual.
#endif
// 2. Select the number of boot partition
bootloader_state_t bs = { 0 };
int boot_index = select_partition_number(&bs);
@ -78,7 +88,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

@ -153,6 +153,68 @@ esp_err_t bootloader_common_get_partition_description(const esp_partition_pos_t
*/
void bootloader_common_vddsdio_configure(void);
#if defined( CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP ) || defined( CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC )
/**
* @brief Returns partition from rtc_retain_mem
*
* Uses to get the partition of application which was worked before to go to the deep sleep.
* This partition was stored in rtc_retain_mem.
* Note: This function operates the RTC FAST memory which available only for PRO_CPU.
* Make sure that this function is used only PRO_CPU.
*
* @return partition: If rtc_retain_mem is valid.
* - NULL: If it is not valid.
*/
esp_partition_pos_t* bootloader_common_get_rtc_retain_mem_partition(void);
/**
* @brief Update the partition and reboot_counter in rtc_retain_mem.
*
* This function saves the partition of application for fast booting from the deep sleep.
* An algorithm uses this partition to avoid reading the otadata and does not validate an image.
* Note: This function operates the RTC FAST memory which available only for PRO_CPU.
* Make sure that this function is used only PRO_CPU.
*
* @param[in] partition App partition description. Can be NULL, in this case rtc_retain_mem.partition is not updated.
* @param[in] reboot_counter If true then update reboot_counter.
*
*/
void bootloader_common_update_rtc_retain_mem(esp_partition_pos_t* partition, bool reboot_counter);
/**
* @brief Reset entire rtc_retain_mem.
*
* Note: This function operates the RTC FAST memory which available only for PRO_CPU.
* Make sure that this function is used only PRO_CPU.
*/
void bootloader_common_reset_rtc_retain_mem(void);
/**
* @brief Returns reboot_counter from rtc_retain_mem
*
* The reboot_counter counts the number of reboots. Reset only when power is off.
* The very first launch of the application will be from 1.
* Overflow is not possible, it will stop at the value UINT16_MAX.
* Note: This function operates the RTC FAST memory which available only for PRO_CPU.
* Make sure that this function is used only PRO_CPU.
*
* @return reboot_counter: 1..65535
* - 0: If rtc_retain_mem is not valid.
*/
uint16_t bootloader_common_get_rtc_retain_mem_reboot_counter(void);
/**
* @brief Returns rtc_retain_mem
*
* Note: This function operates the RTC FAST memory which available only for PRO_CPU.
* Make sure that this function is used only PRO_CPU.
*
* @return rtc_retain_mem
*/
rtc_retain_mem_t* bootloader_common_get_rtc_retain_mem(void);
#endif
#ifdef __cplusplus
}
#endif

View File

@ -140,6 +140,21 @@ void esp_flash_write_protect_crypt_cnt(void);
*/
esp_flash_enc_mode_t esp_get_flash_encryption_mode(void);
/** @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

@ -42,15 +42,43 @@ typedef struct {
uint8_t image_digest[32]; /* appended SHA-256 digest */
} esp_image_metadata_t;
/* Mode selection for esp_image_load() */
typedef enum {
ESP_IMAGE_VERIFY, /* Verify image contents, load metadata. Print errors. */
ESP_IMAGE_VERIFY_SILENT, /* Verify image contents, load metadata. Don't print errors. */
ESP_IMAGE_VERIFY, /* Verify image contents, not load to memory, load metadata. Print errors. */
ESP_IMAGE_VERIFY_SILENT, /* Verify image contents, not load to memory, load metadata. Don't print errors. */
#ifdef BOOTLOADER_BUILD
ESP_IMAGE_LOAD, /* Verify image contents, load to memory. Print errors. */
ESP_IMAGE_LOAD, /* Verify image contents, load to memory, load metadata. Print errors. */
ESP_IMAGE_LOAD_NO_VALIDATE, /* Not verify image contents, load to memory, load metadata. Print errors. */
#endif
} esp_image_load_mode_t;
typedef struct {
esp_partition_pos_t partition; /*!< Partition of application which worked before goes to the deep sleep. */
uint16_t reboot_counter; /*!< Reboot counter. Reset only when power is off. */
uint16_t reserve; /*!< Reserve */
#ifdef CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC
uint8_t custom[CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC_SIZE]; /*!< Reserve for custom propose */
#endif
uint32_t crc; /*!< Check sum crc32 */
} rtc_retain_mem_t;
#ifdef CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC
_Static_assert(CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC_SIZE % 4 == 0, "CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC_SIZE must be a multiple of 4 bytes");
#endif
#if defined(CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP) || defined(CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC)
_Static_assert(CONFIG_BOOTLOADER_RESERVE_RTC_SIZE % 4 == 0, "CONFIG_BOOTLOADER_RESERVE_RTC_SIZE must be a multiple of 4 bytes");
#endif
#ifdef CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC
#define ESP_BOOTLOADER_RESERVE_RTC (CONFIG_BOOTLOADER_RESERVE_RTC_SIZE + CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC_SIZE)
#elif defined(CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP)
#define ESP_BOOTLOADER_RESERVE_RTC (CONFIG_BOOTLOADER_RESERVE_RTC_SIZE)
#endif
#if defined(CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP) || defined(CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC)
_Static_assert(sizeof(rtc_retain_mem_t) <= ESP_BOOTLOADER_RESERVE_RTC, "Reserved RTC area must exceed size of rtc_retain_mem_t");
#endif
/**
* @brief Verify and (optionally, in bootloader mode) load an app image.
*
@ -134,6 +162,24 @@ esp_err_t esp_image_verify(esp_image_load_mode_t mode, const esp_partition_pos_t
*/
esp_err_t bootloader_load_image(const esp_partition_pos_t *part, esp_image_metadata_t *data);
/**
* @brief Load an app image without verification (available only in space of bootloader).
*
* If encryption is enabled, data will be transparently decrypted.
*
* @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.
*
* @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 bootloader_load_image_no_verify(const esp_partition_pos_t *part, esp_image_metadata_t *data);
/**
* @brief Verify the bootloader image.
*

View File

@ -55,6 +55,16 @@ int bootloader_utility_get_selected_boot_partition(const bootloader_state_t *bs)
*/
__attribute__((noreturn)) void bootloader_utility_load_boot_image(const bootloader_state_t *bs, int start_index);
#ifdef CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP
/**
* @brief Load that application which was worked before we go to the deep sleep.
*
* Checks the reboot reason if it is the deep sleep and has a valid partition in the RTC memory
* then try to load the application which was worked before we go to the deep sleep.
*
*/
void bootloader_utility_load_boot_image_from_deep_sleep(void);
#endif
/**
* @brief Software reset the ESP32

View File

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

View File

@ -277,3 +277,66 @@ void bootloader_common_vddsdio_configure(void)
}
#endif // CONFIG_BOOTLOADER_VDDSDIO_BOOST
}
#if defined( CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP ) || defined( CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC )
rtc_retain_mem_t *const rtc_retain_mem = (rtc_retain_mem_t *)(SOC_RTC_DRAM_HIGH - sizeof(rtc_retain_mem_t));
static bool check_rtc_retain_mem(void)
{
return crc32_le(UINT32_MAX, (uint8_t*)rtc_retain_mem, sizeof(rtc_retain_mem_t) - sizeof(rtc_retain_mem->crc)) == rtc_retain_mem->crc && rtc_retain_mem->crc != UINT32_MAX;
}
static void update_rtc_retain_mem_crc(void)
{
rtc_retain_mem->crc = crc32_le(UINT32_MAX, (uint8_t*)rtc_retain_mem, sizeof(rtc_retain_mem_t) - sizeof(rtc_retain_mem->crc));
}
void bootloader_common_reset_rtc_retain_mem(void)
{
memset(rtc_retain_mem, 0, sizeof(rtc_retain_mem_t));
}
uint16_t bootloader_common_get_rtc_retain_mem_reboot_counter(void)
{
if (check_rtc_retain_mem()) {
return rtc_retain_mem->reboot_counter;
}
return 0;
}
esp_partition_pos_t* bootloader_common_get_rtc_retain_mem_partition(void)
{
if (check_rtc_retain_mem()) {
return &rtc_retain_mem->partition;
}
return NULL;
}
void bootloader_common_update_rtc_retain_mem(esp_partition_pos_t* partition, bool reboot_counter)
{
if (reboot_counter) {
if (!check_rtc_retain_mem()) {
bootloader_common_reset_rtc_retain_mem();
}
if (++rtc_retain_mem->reboot_counter == 0) {
// do not allow to overflow. Stop it.
--rtc_retain_mem->reboot_counter;
}
}
if (partition != NULL) {
rtc_retain_mem->partition.offset = partition->offset;
rtc_retain_mem->partition.size = partition->size;
}
update_rtc_retain_mem_crc();
}
rtc_retain_mem_t* bootloader_common_get_rtc_retain_mem(void)
{
return rtc_retain_mem;
}
#endif

View File

@ -432,8 +432,31 @@ static void set_actual_ota_seq(const bootloader_state_t *bs, int index)
update_anti_rollback(&bs->ota[index]);
#endif
}
#if defined( CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP ) || defined( CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC )
esp_partition_pos_t partition = index_to_partition(bs, index);
bootloader_common_update_rtc_retain_mem(&partition, true);
#endif
}
#ifdef CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP
void bootloader_utility_load_boot_image_from_deep_sleep(void)
{
if (rtc_get_reset_reason(0) == DEEPSLEEP_RESET) {
esp_partition_pos_t* partition = bootloader_common_get_rtc_retain_mem_partition();
if (partition != NULL) {
esp_image_metadata_t image_data;
if (bootloader_load_image_no_verify(partition, &image_data) == ESP_OK) {
ESP_LOGI(TAG, "Fast booting app from partition at offset 0x%x", partition->offset);
bootloader_common_update_rtc_retain_mem(NULL, true);
load_image(&image_data);
}
}
ESP_LOGE(TAG, "Fast booting is not successful");
ESP_LOGI(TAG, "Try to load an app as usual with all validations");
}
}
#endif
#define TRY_LOG_FORMAT "Trying partition index %d offs 0x%x size 0x%x"
void bootloader_utility_load_boot_image(const bootloader_state_t *bs, int start_index)

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(void);
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

@ -103,14 +103,17 @@ static esp_err_t __attribute__((unused)) verify_simple_hash(bootloader_sha256_ha
static esp_err_t image_load(esp_image_load_mode_t mode, const esp_partition_pos_t *part, esp_image_metadata_t *data)
{
#ifdef BOOTLOADER_BUILD
bool do_load = (mode == ESP_IMAGE_LOAD);
bool do_load = (mode == ESP_IMAGE_LOAD) || (mode == ESP_IMAGE_LOAD_NO_VALIDATE);
bool do_verify = (mode == ESP_IMAGE_LOAD) || (mode == ESP_IMAGE_VERIFY) || (mode == ESP_IMAGE_VERIFY_SILENT);
#else
bool do_load = false; // Can't load the image in app mode
bool do_verify = true; // In app mode is avalible only verify mode
#endif
bool silent = (mode == ESP_IMAGE_VERIFY_SILENT);
esp_err_t err = ESP_OK;
// checksum the image a word at a time. This shaves 30-40ms per MB of image size
uint32_t checksum_word = ESP_ROM_CHECKSUM_INITIAL;
uint32_t *checksum = NULL;
bootloader_sha256_handle_t sha_handle = NULL;
if (data == NULL || part == NULL) {
@ -131,6 +134,9 @@ static esp_err_t image_load(esp_image_load_mode_t mode, const esp_partition_pos_
goto err;
}
if (do_verify) {
checksum = &checksum_word;
// Calculate SHA-256 of image if secure boot is on, or if image has a hash appended
#ifdef SECURE_BOOT_CHECK_SIGNATURE
if (1) {
@ -160,12 +166,13 @@ static esp_err_t image_load(esp_image_load_mode_t mode, const esp_partition_pos_
FAIL_LOAD("image at 0x%x segment count %d exceeds max %d",
data->start_addr, data->image.segment_count, ESP_IMAGE_MAX_SEGMENTS);
}
} // if (do_verify)
uint32_t next_addr = data->start_addr + sizeof(esp_image_header_t);
for (int i = 0; i < data->image.segment_count; i++) {
esp_image_segment_header_t *header = &data->segments[i];
ESP_LOGV(TAG, "loading segment header %d at offset 0x%x", i, next_addr);
err = process_segment(i, next_addr, header, silent, do_load, sha_handle, &checksum_word);
err = process_segment(i, next_addr, header, silent, do_load, sha_handle, checksum);
if (err != ESP_OK) {
goto err;
}
@ -174,6 +181,7 @@ static esp_err_t image_load(esp_image_load_mode_t mode, const esp_partition_pos_
next_addr += header->data_len;
}
if (do_verify) {
// Segments all loaded, verify length
uint32_t end_addr = next_addr;
if (end_addr < data->start_addr) {
@ -182,29 +190,31 @@ static esp_err_t image_load(esp_image_load_mode_t mode, const esp_partition_pos_
data->image_len = end_addr - data->start_addr;
ESP_LOGV(TAG, "image start 0x%08x end of last section 0x%08x", data->start_addr, end_addr);
if (!esp_cpu_in_ocd_debug_mode()) {
if (NULL != checksum && !esp_cpu_in_ocd_debug_mode()) {
err = verify_checksum(sha_handle, checksum_word, data);
if (err != ESP_OK) {
goto err;
}
}
/* For secure boot on ESP32, we don't calculate SHA or verify signautre on bootloaders.
For ESP32S2, we do verify signature on botoloaders which includes the SHA calculation.
(For non-secure boot, we don't verify any SHA-256 hash appended to the bootloader because
esptool.py may have rewritten the header - rely on esptool.py having verified the bootloader at flashing time, instead.)
*/
bool verify_sha;
#if defined(CONFIG_SECURE_BOOT_ENABLED) && defined(CONFIG_IDF_TARGET_ESP32S2BETA)
verify_sha = true;
#else // ESP32, or ESP32S2 without secure boot enabled
verify_sha = (data->start_addr != ESP_BOOTLOADER_OFFSET);
#endif
if (verify_sha) {
if (data->image_len > part->size) {
FAIL_LOAD("Image length %d doesn't fit in partition length %d", data->image_len, part->size);
}
/* For secure boot, we don't verify signature on bootloaders.
For non-secure boot, we don't verify any SHA-256 hash appended to the bootloader because esptool.py may have
rewritten the header - rely on esptool.py having verified the bootloader at flashing time, instead.
*/
bool should_verify;
#if defined(CONFIG_SECURE_BOOT_ENABLED) && defined(CONFIG_IDF_TARGET_ESP32S2BETA)
should_verify = true;
#else // ESP32, or ESP32S2 without secure boot enabled
should_verify = (data->start_addr != ESP_BOOTLOADER_OFFSET);
#endif
if (should_verify) {
#ifdef SECURE_BOOT_CHECK_SIGNATURE
// secure boot images have a signature appended
err = verify_secure_boot_signature(sha_handle, data);
@ -214,12 +224,11 @@ static esp_err_t image_load(esp_image_load_mode_t mode, const esp_partition_pos_
err = verify_simple_hash(sha_handle, data);
}
#endif // SECURE_BOOT_CHECK_SIGNATURE
} else {
} else { // verify_sha
// bootloader may still have a sha256 digest handle open
if (sha_handle != NULL) {
bootloader_sha256_finish(sha_handle, NULL);
}
}
if (data->image.hash_appended) {
const void *hash = bootloader_mmap(data->start_addr + data->image_len - HASH_LEN, HASH_LEN);
@ -230,14 +239,16 @@ static esp_err_t image_load(esp_image_load_mode_t mode, const esp_partition_pos_
memcpy(data->image_digest, hash, HASH_LEN);
bootloader_munmap(hash);
}
sha_handle = NULL;
} // verify_sha
} // do_verify
if (err != ESP_OK) {
goto err;
}
#ifdef BOOTLOADER_BUILD
if (do_load) { // Need to deobfuscate RAM
if (do_load && ram_obfs_value[0] != 0 && ram_obfs_value[1] != 0) { // Need to deobfuscate RAM
for (int i = 0; i < data->image.segment_count; i++) {
uint32_t load_addr = data->segments[i].load_addr;
if (should_load(load_addr)) {
@ -264,7 +275,7 @@ err:
// Prevent invalid/incomplete data leaking out
bzero(data, sizeof(esp_image_metadata_t));
return err;
}
}
esp_err_t bootloader_load_image(const esp_partition_pos_t *part, esp_image_metadata_t *data)
{
@ -275,6 +286,15 @@ esp_err_t bootloader_load_image(const esp_partition_pos_t *part, esp_image_metad
#endif
}
esp_err_t bootloader_load_image_no_verify(const esp_partition_pos_t *part, esp_image_metadata_t *data)
{
#ifdef BOOTLOADER_BUILD
return image_load(ESP_IMAGE_LOAD_NO_VALIDATE, part, data);
#else
return ESP_FAIL;
#endif
}
esp_err_t esp_image_verify(esp_image_load_mode_t mode, const esp_partition_pos_t *part, esp_image_metadata_t *data)
{
return image_load(mode, part, data);
@ -408,6 +428,13 @@ err:
static esp_err_t process_segment_data(intptr_t load_addr, uint32_t data_addr, uint32_t data_len, bool do_load, bootloader_sha256_handle_t sha_handle, uint32_t *checksum)
{
// If we are not loading, and the checksum is empty, skip processing this
// segment for data
if(!do_load && checksum == NULL) {
ESP_LOGD(TAG, "skipping checksum for segment");
return ESP_OK;
}
const uint32_t *data = (const uint32_t *)bootloader_mmap(data_addr, data_len);
if (!data) {
ESP_LOGE(TAG, "bootloader_mmap(0x%x, 0x%x) failed",
@ -415,6 +442,12 @@ static esp_err_t process_segment_data(intptr_t load_addr, uint32_t data_addr, ui
return ESP_FAIL;
}
if (checksum == NULL && sha_handle == NULL) {
memcpy((void *)load_addr, data, data_len);
bootloader_munmap(data);
return ESP_OK;
}
#ifdef BOOTLOADER_BUILD
// Set up the obfuscation value to use for loading
while (ram_obfs_value[0] == 0 || ram_obfs_value[1] == 0) {
@ -428,7 +461,9 @@ static esp_err_t process_segment_data(intptr_t load_addr, uint32_t data_addr, ui
for (int i = 0; i < data_len; i += 4) {
int w_i = i / 4; // Word index
uint32_t w = src[w_i];
if (checksum != NULL) {
*checksum ^= w;
}
#ifdef BOOTLOADER_BUILD
if (do_load) {
dest[w_i] = w ^ ((w_i & 1) ? ram_obfs_value[0] : ram_obfs_value[1]);
@ -506,15 +541,15 @@ static bool should_load(uint32_t load_addr)
if (!load_rtc_memory) {
if (load_addr >= SOC_RTC_IRAM_LOW && load_addr < SOC_RTC_IRAM_HIGH) {
ESP_LOGD(TAG, "Skipping RTC fast memory segment at 0x%08x\n", load_addr);
ESP_LOGD(TAG, "Skipping RTC fast memory segment at 0x%08x", load_addr);
return false;
}
if (load_addr >= SOC_RTC_DRAM_LOW && load_addr < SOC_RTC_DRAM_HIGH) {
ESP_LOGD(TAG, "Skipping RTC fast memory segment at 0x%08x\n", load_addr);
ESP_LOGD(TAG, "Skipping RTC fast memory segment at 0x%08x", load_addr);
return false;
}
if (load_addr >= SOC_RTC_DATA_LOW && load_addr < SOC_RTC_DATA_HIGH) {
ESP_LOGD(TAG, "Skipping RTC slow memory segment at 0x%08x\n", load_addr);
ESP_LOGD(TAG, "Skipping RTC slow memory segment at 0x%08x", load_addr);
return false;
}
}

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(void)
{

View File

@ -56,6 +56,10 @@ esp_err_t esp_secure_boot_verify_signature(uint32_t src_addr, uint32_t length)
esp_err_t esp_secure_boot_verify_signature_block(const esp_secure_boot_sig_block_t *sig_block, const uint8_t *image_digest)
{
#if !(defined(CONFIG_MBEDTLS_ECDSA_C) && defined(CONFIG_MBEDTLS_ECP_DP_SECP256R1_ENABLED))
ESP_LOGE(TAG, "Signature verification requires ECDSA & SECP256R1 curve enabled");
return ESP_ERR_NOT_SUPPORTED;
#else
ptrdiff_t keylen;
keylen = signature_verification_key_end - signature_verification_key_start;
@ -117,4 +121,5 @@ cleanup:
mbedtls_mpi_free(&s);
mbedtls_ecdsa_free(&ecdsa_context);
return ret == 0 ? ESP_OK : ESP_ERR_IMAGE_INVALID;
#endif // CONFIG_MBEDTLS_ECDSA_C && CONFIG_MBEDTLS_ECP_DP_SECP256R1_ENABLED
}

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)

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

@ -136,7 +136,8 @@ ifdef CONFIG_BLE_MESH
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
@ -144,7 +145,8 @@ ifdef CONFIG_BLE_MESH
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
endif

View File

@ -37,13 +37,14 @@
#include "esp_err.h"
#include "esp_log.h"
#include "esp_pm.h"
#include "esp_ipc.h"
#include "driver/periph_ctrl.h"
#include "soc/rtc.h"
#include "soc/soc_memory_layout.h"
#include "esp32/clk.h"
#include "esp_coexist_internal.h"
#if !CONFIG_FREERTOS_UNICORE
#include "esp_ipc.h"
#endif
#if CONFIG_BT_ENABLED
@ -755,12 +756,15 @@ static int IRAM_ATTR cause_sw_intr_to_core_wrapper(int core_id, int intr_no)
{
esp_err_t err = ESP_OK;
#if CONFIG_FREERTOS_UNICORE
cause_sw_intr((void *)intr_no);
#else /* CONFIG_FREERTOS_UNICORE */
if (xPortGetCoreID() == core_id) {
cause_sw_intr((void *)intr_no);
} else {
err = esp_ipc_call(core_id, cause_sw_intr, (void *)intr_no);
}
#endif /* !CONFIG_FREERTOS_UNICORE */
return err;
}

@ -1 +1 @@
Subproject commit 717f0c6ec71a016a0b292acffeacf239d007b8ff
Subproject commit d122b080242fdf045bd5a8ba8b5879f2f9c7885e

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
@ -109,163 +108,163 @@
/** 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) */
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) */
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) */
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) */
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) */
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) */
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) */
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) */
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) */
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;
@ -309,175 +308,175 @@ 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) */
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) */
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) */
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) */
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) */
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) */
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) */
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) */
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) */
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) */
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 */
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) */
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 */
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) */
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) */
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) */
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,56 +282,21 @@ 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)
@ -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,136 +462,240 @@ 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)
{
@ -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};
@ -321,233 +553,7 @@ static void btc_mesh_health_server_callback(esp_ble_mesh_health_server_cb_param_
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,8 @@ 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_user_data_t *client_param = NULL;
bt_mesh_client_internal_data_t *data = NULL;
bt_mesh_client_node_t *node = NULL;
btc_msg_t msg = {0};
bt_status_t ret;
@ -310,24 +308,24 @@ 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;
client_param = (bt_mesh_client_user_data_t *)model->user_data;
data = (bt_mesh_client_internal_data_t *)client_param->internal_data;
if (!data) {
LOG_ERROR("%s, Client internal_data is NULL", __func__);
return;
}
node = bt_mesh_is_model_message_publish(model, ctx, buf, false);
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;
} 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;
@ -341,7 +339,7 @@ static void btc_ble_mesh_client_model_op_cb(struct bt_mesh_model *model,
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);
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__);
@ -364,7 +362,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 +391,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 +408,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 +432,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 +455,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 +479,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 +501,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 +523,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 +548,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 +565,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,11 +589,11 @@ 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;
bt_mesh_client_user_data_t *client_param = NULL;
bt_mesh_client_internal_data_t *data = NULL;
bt_mesh_client_node_t *node = NULL;
btc_msg_t msg = {0};
bt_status_t ret;
@ -606,8 +604,8 @@ static void btc_client_model_timeout_cb(struct k_work *work)
return;
}
client_param = (bt_mesh_client_common_t *)node->ctx.model->user_data;
data = (bt_mesh_internal_data_t *)client_param->internal_data;
client_param = (bt_mesh_client_user_data_t *)node->ctx.model->user_data;
data = (bt_mesh_client_internal_data_t *)client_param->internal_data;
if (!data) {
LOG_ERROR("%s, Client internal_data is NULL", __func__);
return;
@ -621,7 +619,7 @@ static void btc_client_model_timeout_cb(struct k_work *work)
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);
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__);
@ -631,7 +629,7 @@ static void btc_client_model_timeout_cb(struct k_work *work)
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 +652,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 +671,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 +708,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 +731,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 +758,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 +790,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 +812,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 +835,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 +865,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 +945,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 +970,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 +982,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 +1094,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 +1130,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 +1140,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 +1163,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 +1174,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 +1255,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 +1384,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 +1404,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 +1450,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,11 +1464,11 @@ 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,
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);
@ -1461,20 +1482,20 @@ 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,
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,
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,
@ -1487,9 +1508,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 +1528,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__);
btc_ble_mesh_model_free_req_data(msg);
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);
}
}

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)
@ -616,8 +626,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 +645,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 +734,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 +830,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 +871,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 +881,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 +905,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 +969,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 */
@ -387,6 +392,8 @@ void bt_mesh_adv_init(void)
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 +407,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

@ -108,8 +108,8 @@ static void timeout_handler(struct k_work *work)
return;
}
bt_mesh_callback_config_status_to_btc(node->opcode, 0x03, node->ctx.model,
&node->ctx, NULL, 0);
bt_mesh_config_client_cb_evt_to_btc(node->opcode,
BTC_BLE_MESH_EVT_CONFIG_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0);
bt_mesh_client_free_node(&internal->queue, node);
@ -139,7 +139,7 @@ static void cfg_client_cancel(struct bt_mesh_model *model,
/* 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);
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 +163,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,14 +193,14 @@ 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);
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(&data->queue, node);
}

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);
}
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,
if (!friend_lpn_matches(frnd, rx->sub->net_idx,
rx->ctx.recv_dst)) {
friend_lpn_enqueue_rx(frnd, rx, type, seq_auth, sbuf);
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

@ -64,8 +64,8 @@ static void timeout_handler(struct k_work *work)
return;
}
bt_mesh_callback_health_status_to_btc(node->opcode, 0x03, node->ctx.model,
&node->ctx, NULL, 0);
bt_mesh_health_client_cb_evt_to_btc(node->opcode,
BTC_BLE_MESH_EVT_HEALTH_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0);
bt_mesh_client_free_node(&internal->queue, node);
@ -95,7 +95,7 @@ static void health_client_cancel(struct bt_mesh_model *model,
/* 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);
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,20 +103,20 @@ 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);
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(&data->queue, node);
}
@ -169,7 +169,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;
}

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

@ -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()) {
if (!ready_to_recv()) {
return;
}
}
#endif
#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
if (!bt_mesh_is_provisioner_en()) {
BT_WARN("%s, Provisioner is disabled", __func__);
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 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;
struct net_buf_simple buf;
} 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);
}
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);
}
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) &&
(!(bt_mesh_atomic_get(bt_mesh.flags) & GENERIC_PENDING_BITS) ||
(CONFIG_BLE_MESH_RPL_STORE_TIMEOUT <
CONFIG_BLE_MESH_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

@ -25,6 +25,10 @@ extern "C" {
#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);
int bt_mesh_save_core_settings(const char *key, const u8_t *val, size_t len);

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,8 +417,6 @@ 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;
@ -405,17 +429,20 @@ static int send_seg(struct bt_mesh_net_tx *net_tx, struct net_buf_simple *sdu,
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;
continue;
}
}
}
tx->seg[seg_o] = net_buf_ref(seg);
BT_DBG("Sending %u/%u", seg_o, tx->seg_n);
err = bt_mesh_net_send(net_tx, seg,
@ -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,7 +1055,7 @@ 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) &&
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);
}
@ -1620,9 +1555,11 @@ 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_FRIEND) && rx->friend_match && !err) {
if (seq_auth == TRANS_SEQ_AUTH_NVAL) {
bt_mesh_friend_enqueue_rx(rx, pdu_type, NULL, buf);
bt_mesh_friend_enqueue_rx(rx, pdu_type, NULL,
seg_count, buf);
} else {
bt_mesh_friend_enqueue_rx(rx, pdu_type, &seq_auth, buf);
bt_mesh_friend_enqueue_rx(rx, pdu_type, &seq_auth,
seg_count, buf);
}
}
}
@ -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

@ -23,15 +23,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 +40,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 +65,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 +172,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 +182,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) {
@ -224,8 +224,8 @@ int bt_mesh_client_send_msg(struct bt_mesh_model *model,
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 +244,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;
@ -275,16 +275,16 @@ int bt_mesh_client_free_node(sys_slist_t *queue, bt_mesh_client_node_t *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 +315,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

@ -145,8 +145,8 @@ static void timeout_handler(struct k_work *work)
return;
}
bt_mesh_callback_generic_status_to_btc(node->opcode, 0x03, node->ctx.model,
&node->ctx, NULL, 0);
bt_mesh_generic_client_cb_evt_to_btc(node->opcode,
BTC_BLE_MESH_EVT_GENERIC_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0);
bt_mesh_client_free_node(&internal->queue, node);
@ -535,7 +535,7 @@ 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);
node = bt_mesh_is_client_recv_publish_msg(model, ctx, buf, true);
if (!node) {
BT_DBG("Unexpected generic status message 0x%x", rsp);
} else {
@ -558,7 +558,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,13 +574,13 @@ 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);
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(&internal->queue, node);
}
@ -687,7 +687,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 +736,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,7 +781,7 @@ 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_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);
@ -918,7 +918,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 +981,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;

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,42 @@ 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;
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 +89,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);
@ -96,16 +118,7 @@ enum {
#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 +126,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 */
@ -98,7 +98,7 @@ 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 */
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) */
@ -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

@ -154,8 +154,8 @@ static void timeout_handler(struct k_work *work)
return;
}
bt_mesh_callback_light_status_to_btc(node->opcode, 0x03, node->ctx.model,
&node->ctx, NULL, 0);
bt_mesh_lighting_client_cb_evt_to_btc(node->opcode,
BTC_BLE_MESH_EVT_LIGHTING_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0);
bt_mesh_client_free_node(&internal->queue, node);
@ -650,7 +650,7 @@ 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);
node = bt_mesh_is_client_recv_publish_msg(model, ctx, buf, true);
if (!node) {
BT_DBG("Unexpected light status message 0x%x", rsp);
} else {
@ -678,7 +678,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,13 +700,13 @@ 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);
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(&internal->queue, node);
}
@ -770,7 +770,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 +801,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 +1042,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 +1095,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;

View File

@ -83,8 +83,8 @@ static void timeout_handler(struct k_work *work)
return;
}
bt_mesh_callback_sensor_status_to_btc(node->opcode, 0x03, node->ctx.model,
&node->ctx, NULL, 0);
bt_mesh_sensor_client_cb_evt_to_btc(node->opcode,
BTC_BLE_MESH_EVT_SENSOR_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0);
bt_mesh_client_free_node(&internal->queue, node);
@ -262,7 +262,7 @@ 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);
node = bt_mesh_is_client_recv_publish_msg(model, ctx, buf, true);
if (!node) {
BT_DBG("Unexpected sensor status message 0x%x", rsp);
} else {
@ -274,17 +274,17 @@ 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);
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(&internal->queue, node);
}
@ -352,7 +352,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 +460,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 +525,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;

View File

@ -99,8 +99,8 @@ static void timeout_handler(struct k_work *work)
return;
}
bt_mesh_callback_time_scene_status_to_btc(node->opcode, 0x03, node->ctx.model,
&node->ctx, NULL, 0);
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);
bt_mesh_client_free_node(&internal->queue, node);
@ -299,7 +299,7 @@ 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);
node = bt_mesh_is_client_recv_publish_msg(model, ctx, buf, true);
if (!node) {
BT_DBG("Unexpected time scene status message 0x%x", rsp);
} else {
@ -312,7 +312,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,13 +322,13 @@ 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);
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(&internal->queue, node);
}
@ -369,7 +369,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 +400,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 +497,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 +535,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;

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

@ -432,6 +432,22 @@ esp_err_t esp_hf_client_request_last_voice_tag_number(void)
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
}
esp_err_t esp_hf_client_send_nrec(void)
{
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
btc_msg_t msg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_HF_CLIENT;
msg.act = BTC_HF_CLIENT_SEND_NREC_EVT;
/* Switch to BTC context */
bt_status_t stat = btc_transfer_context(&msg, NULL, 0, NULL);
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
}
esp_err_t esp_hf_client_register_data_callback(esp_hf_client_incoming_data_cb_t recv,
esp_hf_client_outgoing_data_cb_t send)
{

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

@ -578,6 +578,20 @@ esp_err_t esp_hf_client_send_dtmf(char code);
*/
esp_err_t esp_hf_client_request_last_voice_tag_number(void);
/**
*
* @brief Disable echo cancellation and noise reduction in the AG (use AT+NREC=0 command)
* As a precondition to use this API, Service Level Connection shall exist with AG
*
* @return
* - ESP_OK: NREC=0 request is sent to lower layer
* - ESP_INVALID_STATE: if bluetooth stack is not yet enabled
* - ESP_FAIL: others
*
*/
esp_err_t esp_hf_client_send_nrec(void);
/**
* @brief Register HFP client data output function; the callback is only used in
* the case that Voice Over HCI is enabled.

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

@ -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

@ -630,6 +630,27 @@ static bt_status_t btc_hf_client_request_last_voice_tag_number(void)
return BT_STATUS_UNSUPPORTED;
}
/*******************************************************************************
**
** Function btc_hf_client_send_nrec
**
** Description Request AG to disable echo cancellation & noise reduction
**
** Returns bt_status_t
**
*******************************************************************************/
static bt_status_t btc_hf_client_send_nrec(void)
{
CHECK_HF_CLIENT_SLC_CONNECTED();
if (hf_client_local_param.btc_hf_client_cb.peer_feat & BTA_HF_CLIENT_PEER_FEAT_ECNR)
{
BTA_HfClientSendAT(hf_client_local_param.btc_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_NREC, 0, 0, NULL);
return BT_STATUS_SUCCESS;
}
return BT_STATUS_UNSUPPORTED;
}
/*******************************************************************************
**
** Function bte_hf_client_evt
@ -1073,6 +1094,9 @@ void btc_hf_client_call_handler(btc_msg_t *msg)
case BTC_HF_CLIENT_REGISTER_DATA_CALLBACK_EVT:
btc_hf_client_reg_data_cb(arg->reg_data_cb.recv, arg->reg_data_cb.send);
break;
case BTC_HF_CLIENT_SEND_NREC_EVT:
btc_hf_client_send_nrec();
break;
default:
BTC_TRACE_WARNING("%s : unhandled event: %d\n", __FUNCTION__, msg->act);
}

View File

@ -57,6 +57,7 @@ typedef enum {
BTC_HF_CLIENT_SEND_DTMF_EVT,
BTC_HF_CLIENT_REQUEST_LAST_VOICE_TAG_NUMBER_EVT,
BTC_HF_CLIENT_REGISTER_DATA_CALLBACK_EVT,
BTC_HF_CLIENT_SEND_NREC_EVT,
} btc_hf_client_act_t;
/* btc_hf_client_args_t */

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

@ -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);

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